Skip to content

Commit

Permalink
fixed wrong filte function
Browse files Browse the repository at this point in the history
  • Loading branch information
easylogic committed May 6, 2020
1 parent 679f62b commit 9fe4458
Show file tree
Hide file tree
Showing 27 changed files with 91 additions and 219 deletions.
198 changes: 33 additions & 165 deletions dist/colorpicker.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/colorpicker.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@easylogic/colorpicker",
"version": "1.9.68",
"version": "1.9.69",
"description": "simple colorpicker used anywhere",
"main": "./dist/colorpicker.js",
"scripts": {
Expand Down
16 changes: 10 additions & 6 deletions src/util/filter/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,13 +374,17 @@ export function makeUserFilterFunctionList (arr) {
return [newKeys[key], JSON.stringify(it.context[key])].join(' = ')
})

let preCallbackString = it.callback.toString().split("{");
let preCallbackString = it.callback;

preCallbackString.shift()
preCallbackString = preCallbackString.join("{")
preCallbackString = preCallbackString.split("}")
preCallbackString.pop()
preCallbackString = preCallbackString.join("}")
if (typeof it.callback === 'function') {
preCallbackString = it.callback.toString().split("{");

preCallbackString.shift()
preCallbackString = preCallbackString.join("{")
preCallbackString = preCallbackString.split("}")
preCallbackString.pop()
preCallbackString = preCallbackString.join("}")
}

Object.keys(newKeys).forEach(key => {
var newKey = newKeys[key]
Expand Down
4 changes: 2 additions & 2 deletions src/util/filter/pixel/bitonal.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ export default function bitonal(darkColor, lightColor, threshold = 100) {
let $lightColor = Color.parse(lightColor);
let $threshold = threshold

return pixel(() => {
return pixel(`
const thresholdColor = ( $r + $g + $b ) <= $threshold ? $darkColor : $lightColor
$r = thresholdColor.r;
$g = thresholdColor.g;
$b = thresholdColor.b;
}, {
`, {
$threshold
}, {
$darkColor,
Expand Down
4 changes: 2 additions & 2 deletions src/util/filter/pixel/brightness.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ export default function brightness (amount = 1) {
amount = parseParamNumber(amount)
const $C = Math.floor(255 * (amount / 100));

return pixel(() => {
return pixel(`
$r += $C;
$g += $C;
$b += $C;
},{ $C })
`,{ $C })
}
4 changes: 2 additions & 2 deletions src/util/filter/pixel/brownie.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export default function brownie () {
0,0,0,1
]

return pixel(() => {
return pixel(`
$r = $matrix[0] * $r + $matrix[1] * $g + $matrix[2] * $b + $matrix[3] * $a;
$g = $matrix[4] * $r + $matrix[5] * $g + $matrix[6] * $b + $matrix[7] * $a;
$b = $matrix[8] * $r + $matrix[9] * $g + $matrix[10] * $b + $matrix[11] * $a;
$a = $matrix[12] * $r + $matrix[13] * $g + $matrix[14] * $b + $matrix[15] * $a;
}, {
`, {
$matrix
})
}
4 changes: 2 additions & 2 deletions src/util/filter/pixel/clip.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ export default function clip (amount = 0) {
amount = parseParamNumber(amount)
const $C = Math.abs(amount) * 2.55

return pixel(() => {
return pixel(`
$r = ($r > 255 - $C) ? 255 : 0;
$g = ($g > 255 - $C) ? 255 : 0;
$b = ($b > 255 - $C) ? 255 : 0;
}, { $C })
`, { $C })
}
4 changes: 2 additions & 2 deletions src/util/filter/pixel/contrast.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ export default function contrast(amount = 0) {
amount = parseParamNumber(amount)
const $C = Math.max((128 + amount) / 128, 0);

return pixel(() => {
return pixel(`
$r *= $C;
$g *= $C;
$b *= $C;
}, { $C })
`, { $C })
}
4 changes: 2 additions & 2 deletions src/util/filter/pixel/gamma.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import {

export default function gamma (amount = 1) {
const $C = parseParamNumber(amount)
return pixel(() => {
return pixel(`
$r = Math.pow($r / 255, $C) * 255;
$g = Math.pow($g / 255, $C) * 255;
$b = Math.pow($b / 255, $C) * 255;
}, { $C })
`, { $C })
}
4 changes: 2 additions & 2 deletions src/util/filter/pixel/gradient.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default function gradient () {
return {r, g, b, a}
})

return pixel(() => {
return pixel(`
const colorIndex = clamp(Math.ceil($r * 0.2126 + $g * 0.7152 + $b * 0.0722));
const newColorIndex = clamp(Math.floor(colorIndex * ($scale / 256)));
const color = $colors[newColorIndex];
Expand All @@ -48,5 +48,5 @@ export default function gradient () {
$g = color.g;
$b = color.b;
$a = clamp(Math.floor(color.a * 256));
}, { }, { $colors, $scale })
`, { }, { $colors, $scale })
}
4 changes: 2 additions & 2 deletions src/util/filter/pixel/grayscale.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ export default function grayscale (amount) {
0, 0, 0, 1
]

return pixel(() => {
return pixel(`
$r = $matrix[0] * $r + $matrix[1] * $g + $matrix[2] * $b + $matrix[3] * $a;
$g = $matrix[4] * $r + $matrix[5] * $g + $matrix[6] * $b + $matrix[7] * $a;
$b = $matrix[8] * $r + $matrix[9] * $g + $matrix[10] * $b + $matrix[11] * $a;
$a = $matrix[12] * $r + $matrix[13] * $g + $matrix[14] * $b + $matrix[15] * $a;
}, {
`, {
$matrix
});
}
4 changes: 2 additions & 2 deletions src/util/filter/pixel/hue.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
*/
export default function hue (amount = 360) {
const $C = parseParamNumber(amount)
return pixel(() => {
return pixel(`
var hsv = Color.RGBtoHSV($r, $g, $b);
// 0 ~ 360
Expand All @@ -22,7 +22,7 @@ export default function hue (amount = 360) {
$r = rgb.r;
$g = rgb.g;
$b = rgb.b;
}, {
`, {
$C
})
}
4 changes: 2 additions & 2 deletions src/util/filter/pixel/invert.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ export default function invert (amount = 100) {
amount = parseParamNumber(amount)
const $C = amount / 100;

return pixel(() => {
return pixel(`
$r = (255 - $r) * $C;
$g = (255 - $g) * $C;
$b = (255 - $b) * $C;
}, {
`, {
$C
})
}
4 changes: 2 additions & 2 deletions src/util/filter/pixel/kodachrome.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export default function kodachrome () {
0,0,0,1
]

return pixel(() => {
return pixel(`
$r = $matrix[0] * $r + $matrix[1] * $g + $matrix[2] * $b + $matrix[3] * $a;
$g = $matrix[4] * $r + $matrix[5] * $g + $matrix[6] * $b + $matrix[7] * $a;
$b = $matrix[8] * $r + $matrix[9] * $g + $matrix[10] * $b + $matrix[11] * $a;
$a = $matrix[12] * $r + $matrix[13] * $g + $matrix[14] * $b + $matrix[15] * $a;
}, {
`, {
$matrix
})
}
4 changes: 2 additions & 2 deletions src/util/filter/pixel/matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ export default function matrix (
$m, $n, $o, $p
]

return pixel(() => {
return pixel(`
$r = $matrix[0] * $r + $matrix[1] * $g + $matrix[2] * $b + $matrix[3] * $a;
$g = $matrix[4] * $r + $matrix[5] * $g + $matrix[6] * $b + $matrix[7] * $a;
$b = $matrix[8] * $r + $matrix[9] * $g + $matrix[10] * $b + $matrix[11] * $a;
$a = $matrix[12] * $r + $matrix[13] * $g + $matrix[14] * $b + $matrix[15] * $a;
}, {
`, {
$matrix
})
}
4 changes: 2 additions & 2 deletions src/util/filter/pixel/noise.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
*/
export default function noise (amount = 1) {
const $C = parseParamNumber(amount)
return pixel(() => {
return pixel(`
const C = Math.abs($C) * 5;
const min = -C;
const max = C;
Expand All @@ -18,7 +18,7 @@ export default function noise (amount = 1) {
$r += noiseValue;
$g += noiseValue;
$b += noiseValue;
}, {
`, {
$C
})
}
4 changes: 2 additions & 2 deletions src/util/filter/pixel/opacity.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default function opacity (amount = 100) {
amount = parseParamNumber(amount)
const $C = amount / 100;

return pixel(() => {
return pixel(`
$a *= $C;
}, { $C })
`, { $C })
}
4 changes: 2 additions & 2 deletions src/util/filter/pixel/polaroid.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export default function polaroid () {
0,0,0,1
]

return pixel(() => {
return pixel(`
$r = $matrix[0] * $r + $matrix[1] * $g + $matrix[2] * $b + $matrix[3] * $a;
$g = $matrix[4] * $r + $matrix[5] * $g + $matrix[6] * $b + $matrix[7] * $a;
$b = $matrix[8] * $r + $matrix[9] * $g + $matrix[10] * $b + $matrix[11] * $a;
$a = $matrix[12] * $r + $matrix[13] * $g + $matrix[14] * $b + $matrix[15] * $a;
}, {
`, {
$matrix
})
}
4 changes: 2 additions & 2 deletions src/util/filter/pixel/saturation.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ export default function saturation (amount = 100) {
0, 0, 0, L
]

return pixel(() => {
return pixel(`
$r = $matrix[0] * $r + $matrix[1] * $g + $matrix[2] * $b + $matrix[3] * $a;
$g = $matrix[4] * $r + $matrix[5] * $g + $matrix[6] * $b + $matrix[7] * $a;
$b = $matrix[8] * $r + $matrix[9] * $g + $matrix[10] * $b + $matrix[11] * $a;
$a = $matrix[12] * $r + $matrix[13] * $g + $matrix[14] * $b + $matrix[15] * $a;
}, {
`, {
$matrix
})

Expand Down
4 changes: 2 additions & 2 deletions src/util/filter/pixel/sepia.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ export default function sepia (amount = 1) {
0, 0, 0, 1
]

return pixel(() => {
return pixel(`
$r = $matrix[0] * $r + $matrix[1] * $g + $matrix[2] * $b + $matrix[3] * $a;
$g = $matrix[4] * $r + $matrix[5] * $g + $matrix[6] * $b + $matrix[7] * $a;
$b = $matrix[8] * $r + $matrix[9] * $g + $matrix[10] * $b + $matrix[11] * $a;
$a = $matrix[12] * $r + $matrix[13] * $g + $matrix[14] * $b + $matrix[15] * $a;
}, {
`, {
$matrix
})
}
4 changes: 2 additions & 2 deletions src/util/filter/pixel/shade.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ export default function shade(redValue = 1, greenValue = 1, blueValue = 1) {
const $greenValue = parseParamNumber(greenValue)
const $blueValue = parseParamNumber(blueValue)

return pixel(() => {
return pixel(`
$r *= $redValue;
$g *= $greenValue;
$b *= $blueValue;
}, {
`, {
$redValue,
$greenValue,
$blueValue
Expand Down
4 changes: 2 additions & 2 deletions src/util/filter/pixel/shift.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export default function shift () {
0,0,0,1
]

return pixel(() => {
return pixel(`
$r = $matrix[0] * $r + $matrix[1] * $g + $matrix[2] * $b + $matrix[3] * $a;
$g = $matrix[4] * $r + $matrix[5] * $g + $matrix[6] * $b + $matrix[7] * $a;
$b = $matrix[8] * $r + $matrix[9] * $g + $matrix[10] * $b + $matrix[11] * $a;
$a = $matrix[12] * $r + $matrix[13] * $g + $matrix[14] * $b + $matrix[15] * $a;
}, {
`, {
$matrix
})
}
4 changes: 2 additions & 2 deletions src/util/filter/pixel/solarize.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ export default function solarize (redValue, greenValue, blueValue) {
const $redValue = parseParamNumber(redValue)
const $greenValue = parseParamNumber(greenValue)
const $blueValue = parseParamNumber(blueValue)
return pixel(() => {
return pixel(`
$r = ($r < $redValue) ? 255 - $r: $r;
$g = ($g < $greenValue) ? 255 - $g: $g;
$b = ($b < $blueValue) ? 255 - $b: $b;
}, {
`, {
$redValue, $greenValue, $blueValue
})

Expand Down
4 changes: 2 additions & 2 deletions src/util/filter/pixel/technicolor.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export default function technicolor () {
0,0,0,1
]

return pixel(() => {
return pixel(`
$r = $matrix[0] * $r + $matrix[1] * $g + $matrix[2] * $b + $matrix[3] * $a;
$g = $matrix[4] * $r + $matrix[5] * $g + $matrix[6] * $b + $matrix[7] * $a;
$b = $matrix[8] * $r + $matrix[9] * $g + $matrix[10] * $b + $matrix[11] * $a;
$a = $matrix[12] * $r + $matrix[13] * $g + $matrix[14] * $b + $matrix[15] * $a;
}, {
`, {
$matrix
})
}
4 changes: 2 additions & 2 deletions src/util/filter/pixel/threshold-color.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default function thresholdColor (scale = 200, amount = 100, hasColor = tr
const $C = amount / 100;
const $hasColor = hasColor

return pixel(() => {
return pixel(`
// refer to Color.brightness
const v = ($C * Math.ceil($r * 0.2126 + $g * 0.7152 + $b * 0.0722) ) >= $scale ? 255 : 0;
Expand All @@ -29,7 +29,7 @@ export default function thresholdColor (scale = 200, amount = 100, hasColor = tr
$b = value;
}
}, {
`, {
$C, $scale, $hasColor
})
}
4 changes: 2 additions & 2 deletions src/util/filter/pixel/tint.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ export default function (redTint = 1, greenTint = 1, blueTint = 1) {
const $redTint = parseParamNumber(redTint)
const $greenTint = parseParamNumber(greenTint)
const $blueTint = parseParamNumber(blueTint)
return pixel(() => {
return pixel(`
$r += (255 - $r) * $redTint;
$g += (255 - $g) * $greenTint;
$b += (255 - $b) * $blueTint;
}, {
`, {
$redTint,
$greenTint,
$blueTint
Expand Down

0 comments on commit 9fe4458

Please sign in to comment.