konva 9.3.21 → 10.0.0-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/konva.js +664 -226
- package/konva.min.js +46 -4
- package/lib/Animation.d.ts +2 -2
- package/lib/Animation.js +7 -11
- package/lib/BezierFunctions.js +9 -15
- package/lib/Canvas.d.ts +1 -1
- package/lib/Canvas.js +14 -20
- package/lib/Container.d.ts +7 -6
- package/lib/Container.js +12 -16
- package/lib/Context.d.ts +7 -5
- package/lib/Context.js +34 -14
- package/lib/Core.d.ts +2 -2
- package/lib/Core.js +3 -7
- package/lib/DragAndDrop.d.ts +3 -3
- package/lib/DragAndDrop.js +24 -27
- package/lib/Factory.d.ts +2 -2
- package/lib/Factory.js +24 -27
- package/lib/FastLayer.d.ts +1 -1
- package/lib/FastLayer.js +6 -10
- package/lib/Global.d.ts +4 -3
- package/lib/Global.js +19 -19
- package/lib/Group.d.ts +4 -3
- package/lib/Group.js +6 -10
- package/lib/Layer.d.ts +10 -9
- package/lib/Layer.js +33 -37
- package/lib/Node.d.ts +16 -13
- package/lib/Node.js +207 -123
- package/lib/PointerEvents.d.ts +4 -4
- package/lib/PointerEvents.js +7 -14
- package/lib/Shape.d.ts +7 -4
- package/lib/Shape.js +91 -91
- package/lib/Stage.d.ts +8 -7
- package/lib/Stage.js +66 -56
- package/lib/Tween.d.ts +3 -2
- package/lib/Tween.js +29 -31
- package/lib/Util.d.ts +3 -2
- package/lib/Util.js +98 -38
- package/lib/Validators.js +44 -57
- package/lib/_CoreInternals.d.ts +49 -23
- package/lib/_CoreInternals.js +33 -36
- package/lib/_FullInternals.d.ts +126 -62
- package/lib/_FullInternals.js +77 -78
- package/lib/canvas-backend.d.ts +2 -0
- package/lib/canvas-backend.js +27 -0
- package/lib/filters/Blur.d.ts +1 -1
- package/lib/filters/Blur.js +5 -9
- package/lib/filters/Brighten.d.ts +1 -1
- package/lib/filters/Brighten.js +5 -9
- package/lib/filters/Brightness.d.ts +2 -0
- package/lib/filters/Brightness.js +8 -0
- package/lib/filters/Contrast.d.ts +1 -1
- package/lib/filters/Contrast.js +5 -9
- package/lib/filters/Emboss.d.ts +1 -1
- package/lib/filters/Emboss.js +95 -101
- package/lib/filters/Enhance.d.ts +1 -1
- package/lib/filters/Enhance.js +5 -9
- package/lib/filters/Grayscale.d.ts +1 -1
- package/lib/filters/Grayscale.js +1 -5
- package/lib/filters/HSL.d.ts +1 -1
- package/lib/filters/HSL.js +7 -11
- package/lib/filters/HSV.d.ts +1 -1
- package/lib/filters/HSV.js +7 -11
- package/lib/filters/Invert.d.ts +1 -1
- package/lib/filters/Invert.js +1 -5
- package/lib/filters/Kaleidoscope.d.ts +1 -1
- package/lib/filters/Kaleidoscope.js +9 -13
- package/lib/filters/Mask.d.ts +1 -1
- package/lib/filters/Mask.js +16 -10
- package/lib/filters/Noise.d.ts +1 -1
- package/lib/filters/Noise.js +5 -9
- package/lib/filters/Pixelate.d.ts +1 -1
- package/lib/filters/Pixelate.js +7 -11
- package/lib/filters/Posterize.d.ts +1 -1
- package/lib/filters/Posterize.js +5 -9
- package/lib/filters/RGB.d.ts +1 -1
- package/lib/filters/RGB.js +7 -11
- package/lib/filters/RGBA.d.ts +1 -1
- package/lib/filters/RGBA.js +8 -12
- package/lib/filters/Sepia.d.ts +1 -1
- package/lib/filters/Sepia.js +1 -5
- package/lib/filters/Solarize.d.ts +1 -1
- package/lib/filters/Solarize.js +13 -29
- package/lib/filters/Threshold.d.ts +1 -1
- package/lib/filters/Threshold.js +5 -9
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -4
- package/lib/shapes/Arc.d.ts +4 -3
- package/lib/shapes/Arc.js +13 -17
- package/lib/shapes/Arrow.d.ts +4 -3
- package/lib/shapes/Arrow.js +13 -17
- package/lib/shapes/Circle.d.ts +4 -3
- package/lib/shapes/Circle.js +7 -11
- package/lib/shapes/Ellipse.d.ts +4 -3
- package/lib/shapes/Ellipse.js +9 -13
- package/lib/shapes/Image.d.ts +4 -3
- package/lib/shapes/Image.js +17 -21
- package/lib/shapes/Label.d.ts +7 -6
- package/lib/shapes/Label.js +13 -18
- package/lib/shapes/Line.d.ts +4 -3
- package/lib/shapes/Line.js +10 -14
- package/lib/shapes/Path.d.ts +3 -2
- package/lib/shapes/Path.js +83 -23
- package/lib/shapes/Rect.d.ts +4 -3
- package/lib/shapes/Rect.js +9 -13
- package/lib/shapes/RegularPolygon.d.ts +6 -3
- package/lib/shapes/RegularPolygon.js +19 -16
- package/lib/shapes/Ring.d.ts +4 -3
- package/lib/shapes/Ring.js +8 -12
- package/lib/shapes/Sprite.d.ts +5 -4
- package/lib/shapes/Sprite.js +15 -19
- package/lib/shapes/Star.d.ts +4 -3
- package/lib/shapes/Star.js +9 -13
- package/lib/shapes/Text.d.ts +16 -3
- package/lib/shapes/Text.js +73 -53
- package/lib/shapes/TextPath.d.ts +5 -4
- package/lib/shapes/TextPath.js +48 -41
- package/lib/shapes/Transformer.d.ts +8 -8
- package/lib/shapes/Transformer.js +90 -90
- package/lib/shapes/Wedge.d.ts +4 -3
- package/lib/shapes/Wedge.js +12 -16
- package/lib/skia-backend.d.ts +2 -0
- package/lib/skia-backend.js +24 -0
- package/lib/types.d.ts +22 -22
- package/lib/types.js +21 -25
- package/package.json +53 -25
- package/lib/index-node.d.ts +0 -2
- package/lib/index-node.js +0 -21
- package/lib/index-types.d.ts +0 -181
package/lib/filters/Emboss.js
CHANGED
|
@@ -1,107 +1,101 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
dirY = 1;
|
|
34
|
-
dirX = 0;
|
|
35
|
-
break;
|
|
36
|
-
case 'bottom-left':
|
|
37
|
-
dirY = 1;
|
|
38
|
-
dirX = -1;
|
|
39
|
-
break;
|
|
40
|
-
case 'left':
|
|
41
|
-
dirY = 0;
|
|
42
|
-
dirX = -1;
|
|
43
|
-
break;
|
|
44
|
-
default:
|
|
45
|
-
Util_1.Util.error('Unknown emboss direction: ' + direction);
|
|
1
|
+
import { Factory } from "../Factory.js";
|
|
2
|
+
import { Node } from "../Node.js";
|
|
3
|
+
import { getNumberValidator } from "../Validators.js";
|
|
4
|
+
export const Emboss = function (imageData) {
|
|
5
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
6
|
+
const data = imageData.data;
|
|
7
|
+
const w = imageData.width;
|
|
8
|
+
const h = imageData.height;
|
|
9
|
+
const strength01 = Math.min(1, Math.max(0, (_b = (_a = this.embossStrength) === null || _a === void 0 ? void 0 : _a.call(this)) !== null && _b !== void 0 ? _b : 0.5));
|
|
10
|
+
const whiteLevel01 = Math.min(1, Math.max(0, (_d = (_c = this.embossWhiteLevel) === null || _c === void 0 ? void 0 : _c.call(this)) !== null && _d !== void 0 ? _d : 0.5));
|
|
11
|
+
const directionMap = {
|
|
12
|
+
'top-left': 315,
|
|
13
|
+
top: 270,
|
|
14
|
+
'top-right': 225,
|
|
15
|
+
right: 180,
|
|
16
|
+
'bottom-right': 135,
|
|
17
|
+
bottom: 90,
|
|
18
|
+
'bottom-left': 45,
|
|
19
|
+
left: 0,
|
|
20
|
+
};
|
|
21
|
+
const directionDeg = (_g = directionMap[(_f = (_e = this.embossDirection) === null || _e === void 0 ? void 0 : _e.call(this)) !== null && _f !== void 0 ? _f : 'top-left']) !== null && _g !== void 0 ? _g : 315;
|
|
22
|
+
const blend = !!((_j = (_h = this.embossBlend) === null || _h === void 0 ? void 0 : _h.call(this)) !== null && _j !== void 0 ? _j : false);
|
|
23
|
+
const strength = strength01 * 10;
|
|
24
|
+
const bias = whiteLevel01 * 255;
|
|
25
|
+
const dirRad = (directionDeg * Math.PI) / 180;
|
|
26
|
+
const cx = Math.cos(dirRad);
|
|
27
|
+
const cy = Math.sin(dirRad);
|
|
28
|
+
const SCALE = (128 / 1020) * strength;
|
|
29
|
+
const src = new Uint8ClampedArray(data);
|
|
30
|
+
const lum = new Float32Array(w * h);
|
|
31
|
+
for (let p = 0, i = 0; i < data.length; i += 4, p++) {
|
|
32
|
+
lum[p] = 0.2126 * src[i] + 0.7152 * src[i + 1] + 0.0722 * src[i + 2];
|
|
46
33
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
const
|
|
74
|
-
const absB = dB > 0 ? dB : -dB;
|
|
75
|
-
if (absG > absDif) {
|
|
76
|
-
dif = dG;
|
|
77
|
-
}
|
|
78
|
-
if (absB > absDif) {
|
|
79
|
-
dif = dB;
|
|
80
|
-
}
|
|
81
|
-
dif *= strength;
|
|
34
|
+
const Gx = [-1, 0, 1, -2, 0, 2, -1, 0, 1];
|
|
35
|
+
const Gy = [-1, -2, -1, 0, 0, 0, 1, 2, 1];
|
|
36
|
+
const OFF = [-w - 1, -w, -w + 1, -1, 0, 1, w - 1, w, w + 1];
|
|
37
|
+
const clamp8 = (v) => (v < 0 ? 0 : v > 255 ? 255 : v);
|
|
38
|
+
for (let y = 1; y < h - 1; y++) {
|
|
39
|
+
for (let x = 1; x < w - 1; x++) {
|
|
40
|
+
const p = y * w + x;
|
|
41
|
+
let sx = 0, sy = 0;
|
|
42
|
+
sx += lum[p + OFF[0]] * Gx[0];
|
|
43
|
+
sy += lum[p + OFF[0]] * Gy[0];
|
|
44
|
+
sx += lum[p + OFF[1]] * Gx[1];
|
|
45
|
+
sy += lum[p + OFF[1]] * Gy[1];
|
|
46
|
+
sx += lum[p + OFF[2]] * Gx[2];
|
|
47
|
+
sy += lum[p + OFF[2]] * Gy[2];
|
|
48
|
+
sx += lum[p + OFF[3]] * Gx[3];
|
|
49
|
+
sy += lum[p + OFF[3]] * Gy[3];
|
|
50
|
+
sx += lum[p + OFF[5]] * Gx[5];
|
|
51
|
+
sy += lum[p + OFF[5]] * Gy[5];
|
|
52
|
+
sx += lum[p + OFF[6]] * Gx[6];
|
|
53
|
+
sy += lum[p + OFF[6]] * Gy[6];
|
|
54
|
+
sx += lum[p + OFF[7]] * Gx[7];
|
|
55
|
+
sy += lum[p + OFF[7]] * Gy[7];
|
|
56
|
+
sx += lum[p + OFF[8]] * Gx[8];
|
|
57
|
+
sy += lum[p + OFF[8]] * Gy[8];
|
|
58
|
+
const r = cx * sx + cy * sy;
|
|
59
|
+
const outGray = clamp8(bias + r * SCALE);
|
|
60
|
+
const o = p * 4;
|
|
82
61
|
if (blend) {
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
data[
|
|
87
|
-
data[
|
|
88
|
-
data[offset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
|
|
62
|
+
const delta = outGray - bias;
|
|
63
|
+
data[o] = clamp8(src[o] + delta);
|
|
64
|
+
data[o + 1] = clamp8(src[o + 1] + delta);
|
|
65
|
+
data[o + 2] = clamp8(src[o + 2] + delta);
|
|
66
|
+
data[o + 3] = src[o + 3];
|
|
89
67
|
}
|
|
90
68
|
else {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
grey = 0;
|
|
94
|
-
}
|
|
95
|
-
else if (grey > 255) {
|
|
96
|
-
grey = 255;
|
|
97
|
-
}
|
|
98
|
-
data[offset] = data[offset + 1] = data[offset + 2] = grey;
|
|
69
|
+
data[o] = data[o + 1] = data[o + 2] = outGray;
|
|
70
|
+
data[o + 3] = src[o + 3];
|
|
99
71
|
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
for (let x = 0; x < w; x++) {
|
|
75
|
+
let oTop = x * 4, oBot = ((h - 1) * w + x) * 4;
|
|
76
|
+
data[oTop] = src[oTop];
|
|
77
|
+
data[oTop + 1] = src[oTop + 1];
|
|
78
|
+
data[oTop + 2] = src[oTop + 2];
|
|
79
|
+
data[oTop + 3] = src[oTop + 3];
|
|
80
|
+
data[oBot] = src[oBot];
|
|
81
|
+
data[oBot + 1] = src[oBot + 1];
|
|
82
|
+
data[oBot + 2] = src[oBot + 2];
|
|
83
|
+
data[oBot + 3] = src[oBot + 3];
|
|
84
|
+
}
|
|
85
|
+
for (let y = 1; y < h - 1; y++) {
|
|
86
|
+
let oL = y * w * 4, oR = (y * w + (w - 1)) * 4;
|
|
87
|
+
data[oL] = src[oL];
|
|
88
|
+
data[oL + 1] = src[oL + 1];
|
|
89
|
+
data[oL + 2] = src[oL + 2];
|
|
90
|
+
data[oL + 3] = src[oL + 3];
|
|
91
|
+
data[oR] = src[oR];
|
|
92
|
+
data[oR + 1] = src[oR + 1];
|
|
93
|
+
data[oR + 2] = src[oR + 2];
|
|
94
|
+
data[oR + 3] = src[oR + 3];
|
|
95
|
+
}
|
|
96
|
+
return imageData;
|
|
102
97
|
};
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
Factory_1.Factory.addGetterSetter(Node_1.Node, 'embossBlend', false, undefined, Factory_1.Factory.afterSetFilter);
|
|
98
|
+
Factory.addGetterSetter(Node, 'embossStrength', 0.5, getNumberValidator(), Factory.afterSetFilter);
|
|
99
|
+
Factory.addGetterSetter(Node, 'embossWhiteLevel', 0.5, getNumberValidator(), Factory.afterSetFilter);
|
|
100
|
+
Factory.addGetterSetter(Node, 'embossDirection', 'top-left', undefined, Factory.afterSetFilter);
|
|
101
|
+
Factory.addGetterSetter(Node, 'embossBlend', false, undefined, Factory.afterSetFilter);
|
package/lib/filters/Enhance.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Filter } from '../Node.
|
|
1
|
+
import type { Filter } from '../Node.ts';
|
|
2
2
|
export declare const Enhance: Filter;
|
package/lib/filters/Enhance.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const Factory_1 = require("../Factory");
|
|
5
|
-
const Node_1 = require("../Node");
|
|
6
|
-
const Validators_1 = require("../Validators");
|
|
1
|
+
import { Factory } from "../Factory.js";
|
|
2
|
+
import { Node } from "../Node.js";
|
|
3
|
+
import { getNumberValidator } from "../Validators.js";
|
|
7
4
|
function remap(fromValue, fromMin, fromMax, toMin, toMax) {
|
|
8
5
|
const fromRange = fromMax - fromMin, toRange = toMax - toMin;
|
|
9
6
|
if (fromRange === 0) {
|
|
@@ -16,7 +13,7 @@ function remap(fromValue, fromMin, fromMax, toMin, toMax) {
|
|
|
16
13
|
toValue = toRange * toValue + toMin;
|
|
17
14
|
return toValue;
|
|
18
15
|
}
|
|
19
|
-
const Enhance = function (imageData) {
|
|
16
|
+
export const Enhance = function (imageData) {
|
|
20
17
|
const data = imageData.data, nSubPixels = data.length;
|
|
21
18
|
let rMin = data[0], rMax = rMin, r, gMin = data[1], gMax = gMin, g, bMin = data[2], bMax = bMin, b;
|
|
22
19
|
const enhanceAmount = this.enhance();
|
|
@@ -84,5 +81,4 @@ const Enhance = function (imageData) {
|
|
|
84
81
|
data[i + 2] = remap(data[i + 2], bMin, bMax, bGoalMin, bGoalMax);
|
|
85
82
|
}
|
|
86
83
|
};
|
|
87
|
-
|
|
88
|
-
Factory_1.Factory.addGetterSetter(Node_1.Node, 'enhance', 0, (0, Validators_1.getNumberValidator)(), Factory_1.Factory.afterSetFilter);
|
|
84
|
+
Factory.addGetterSetter(Node, 'enhance', 0, getNumberValidator(), Factory.afterSetFilter);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Filter } from '../Node.
|
|
1
|
+
import type { Filter } from '../Node.ts';
|
|
2
2
|
export declare const Grayscale: Filter;
|
package/lib/filters/Grayscale.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Grayscale = void 0;
|
|
4
|
-
const Grayscale = function (imageData) {
|
|
1
|
+
export const Grayscale = function (imageData) {
|
|
5
2
|
const data = imageData.data, len = data.length;
|
|
6
3
|
for (let i = 0; i < len; i += 4) {
|
|
7
4
|
const brightness = 0.34 * data[i] + 0.5 * data[i + 1] + 0.16 * data[i + 2];
|
|
@@ -10,4 +7,3 @@ const Grayscale = function (imageData) {
|
|
|
10
7
|
data[i + 2] = brightness;
|
|
11
8
|
}
|
|
12
9
|
};
|
|
13
|
-
exports.Grayscale = Grayscale;
|
package/lib/filters/HSL.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Filter } from '../Node.
|
|
1
|
+
import type { Filter } from '../Node.ts';
|
|
2
2
|
export declare const HSL: Filter;
|
package/lib/filters/HSL.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Factory_1.Factory.addGetterSetter(Node_1.Node, 'saturation', 0, (0, Validators_1.getNumberValidator)(), Factory_1.Factory.afterSetFilter);
|
|
9
|
-
Factory_1.Factory.addGetterSetter(Node_1.Node, 'luminance', 0, (0, Validators_1.getNumberValidator)(), Factory_1.Factory.afterSetFilter);
|
|
10
|
-
const HSL = function (imageData) {
|
|
1
|
+
import { Factory } from "../Factory.js";
|
|
2
|
+
import { Node } from "../Node.js";
|
|
3
|
+
import { getNumberValidator } from "../Validators.js";
|
|
4
|
+
Factory.addGetterSetter(Node, 'hue', 0, getNumberValidator(), Factory.afterSetFilter);
|
|
5
|
+
Factory.addGetterSetter(Node, 'saturation', 0, getNumberValidator(), Factory.afterSetFilter);
|
|
6
|
+
Factory.addGetterSetter(Node, 'luminance', 0, getNumberValidator(), Factory.afterSetFilter);
|
|
7
|
+
export const HSL = function (imageData) {
|
|
11
8
|
const data = imageData.data, nPixels = data.length, v = 1, s = Math.pow(2, this.saturation()), h = Math.abs(this.hue() + 360) % 360, l = this.luminance() * 127;
|
|
12
9
|
const vsu = v * s * Math.cos((h * Math.PI) / 180), vsw = v * s * Math.sin((h * Math.PI) / 180);
|
|
13
10
|
const rr = 0.299 * v + 0.701 * vsu + 0.167 * vsw, rg = 0.587 * v - 0.587 * vsu + 0.33 * vsw, rb = 0.114 * v - 0.114 * vsu - 0.497 * vsw;
|
|
@@ -25,4 +22,3 @@ const HSL = function (imageData) {
|
|
|
25
22
|
data[i + 3] = a;
|
|
26
23
|
}
|
|
27
24
|
};
|
|
28
|
-
exports.HSL = HSL;
|
package/lib/filters/HSV.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Filter } from '../Node.
|
|
1
|
+
import type { Filter } from '../Node.ts';
|
|
2
2
|
export declare const HSV: Filter;
|
package/lib/filters/HSV.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const Node_1 = require("../Node");
|
|
6
|
-
const Validators_1 = require("../Validators");
|
|
7
|
-
const HSV = function (imageData) {
|
|
1
|
+
import { Factory } from "../Factory.js";
|
|
2
|
+
import { Node } from "../Node.js";
|
|
3
|
+
import { getNumberValidator } from "../Validators.js";
|
|
4
|
+
export const HSV = function (imageData) {
|
|
8
5
|
const data = imageData.data, nPixels = data.length, v = Math.pow(2, this.value()), s = Math.pow(2, this.saturation()), h = Math.abs(this.hue() + 360) % 360;
|
|
9
6
|
const vsu = v * s * Math.cos((h * Math.PI) / 180), vsw = v * s * Math.sin((h * Math.PI) / 180);
|
|
10
7
|
const rr = 0.299 * v + 0.701 * vsu + 0.167 * vsw, rg = 0.587 * v - 0.587 * vsu + 0.33 * vsw, rb = 0.114 * v - 0.114 * vsu - 0.497 * vsw;
|
|
@@ -21,7 +18,6 @@ const HSV = function (imageData) {
|
|
|
21
18
|
data[i + 3] = a;
|
|
22
19
|
}
|
|
23
20
|
};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
Factory_1.Factory.addGetterSetter(Node_1.Node, 'value', 0, (0, Validators_1.getNumberValidator)(), Factory_1.Factory.afterSetFilter);
|
|
21
|
+
Factory.addGetterSetter(Node, 'hue', 0, getNumberValidator(), Factory.afterSetFilter);
|
|
22
|
+
Factory.addGetterSetter(Node, 'saturation', 0, getNumberValidator(), Factory.afterSetFilter);
|
|
23
|
+
Factory.addGetterSetter(Node, 'value', 0, getNumberValidator(), Factory.afterSetFilter);
|
package/lib/filters/Invert.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Filter } from '../Node.
|
|
1
|
+
import type { Filter } from '../Node.ts';
|
|
2
2
|
export declare const Invert: Filter;
|
package/lib/filters/Invert.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Invert = void 0;
|
|
4
|
-
const Invert = function (imageData) {
|
|
1
|
+
export const Invert = function (imageData) {
|
|
5
2
|
const data = imageData.data, len = data.length;
|
|
6
3
|
for (let i = 0; i < len; i += 4) {
|
|
7
4
|
data[i] = 255 - data[i];
|
|
@@ -9,4 +6,3 @@ const Invert = function (imageData) {
|
|
|
9
6
|
data[i + 2] = 255 - data[i + 2];
|
|
10
7
|
}
|
|
11
8
|
};
|
|
12
|
-
exports.Invert = Invert;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Filter } from '../Node.
|
|
1
|
+
import type { Filter } from '../Node.ts';
|
|
2
2
|
export declare const Kaleidoscope: Filter;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const Node_1 = require("../Node");
|
|
6
|
-
const Util_1 = require("../Util");
|
|
7
|
-
const Validators_1 = require("../Validators");
|
|
1
|
+
import { Factory } from "../Factory.js";
|
|
2
|
+
import { Node } from "../Node.js";
|
|
3
|
+
import { Util } from "../Util.js";
|
|
4
|
+
import { getNumberValidator } from "../Validators.js";
|
|
8
5
|
const ToPolar = function (src, dst, opt) {
|
|
9
6
|
const srcPixels = src.data, dstPixels = dst.data, xSize = src.width, ySize = src.height, xMid = opt.polarCenterX || xSize / 2, yMid = opt.polarCenterY || ySize / 2;
|
|
10
7
|
let rMax = Math.sqrt(xMid * xMid + yMid * yMid);
|
|
@@ -64,7 +61,7 @@ const FromPolar = function (src, dst, opt) {
|
|
|
64
61
|
}
|
|
65
62
|
}
|
|
66
63
|
};
|
|
67
|
-
const Kaleidoscope = function (imageData) {
|
|
64
|
+
export const Kaleidoscope = function (imageData) {
|
|
68
65
|
const xSize = imageData.width, ySize = imageData.height;
|
|
69
66
|
let x, y, xoff, i, r, g, b, a, srcPos, dstPos;
|
|
70
67
|
let power = Math.round(this.kaleidoscopePower());
|
|
@@ -73,13 +70,13 @@ const Kaleidoscope = function (imageData) {
|
|
|
73
70
|
if (power < 1) {
|
|
74
71
|
return;
|
|
75
72
|
}
|
|
76
|
-
const tempCanvas =
|
|
73
|
+
const tempCanvas = Util.createCanvasElement();
|
|
77
74
|
tempCanvas.width = xSize;
|
|
78
75
|
tempCanvas.height = ySize;
|
|
79
76
|
const scratchData = tempCanvas
|
|
80
77
|
.getContext('2d')
|
|
81
78
|
.getImageData(0, 0, xSize, ySize);
|
|
82
|
-
|
|
79
|
+
Util.releaseCanvas(tempCanvas);
|
|
83
80
|
ToPolar(imageData, scratchData, {
|
|
84
81
|
polarCenterX: xSize / 2,
|
|
85
82
|
polarCenterY: ySize / 2,
|
|
@@ -132,6 +129,5 @@ const Kaleidoscope = function (imageData) {
|
|
|
132
129
|
}
|
|
133
130
|
FromPolar(scratchData, imageData, { polarRotation: 0 });
|
|
134
131
|
};
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
Factory_1.Factory.addGetterSetter(Node_1.Node, 'kaleidoscopeAngle', 0, (0, Validators_1.getNumberValidator)(), Factory_1.Factory.afterSetFilter);
|
|
132
|
+
Factory.addGetterSetter(Node, 'kaleidoscopePower', 2, getNumberValidator(), Factory.afterSetFilter);
|
|
133
|
+
Factory.addGetterSetter(Node, 'kaleidoscopeAngle', 0, getNumberValidator(), Factory.afterSetFilter);
|
package/lib/filters/Mask.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Filter } from '../Node.
|
|
1
|
+
import type { Filter } from '../Node.ts';
|
|
2
2
|
export declare const Mask: Filter;
|
package/lib/filters/Mask.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const Factory_1 = require("../Factory");
|
|
5
|
-
const Node_1 = require("../Node");
|
|
6
|
-
const Validators_1 = require("../Validators");
|
|
1
|
+
import { Factory } from "../Factory.js";
|
|
2
|
+
import { Node } from "../Node.js";
|
|
3
|
+
import { getNumberValidator } from "../Validators.js";
|
|
7
4
|
function pixelAt(idata, x, y) {
|
|
8
5
|
let idx = (y * idata.width + x) * 4;
|
|
9
6
|
const d = [];
|
|
@@ -106,7 +103,17 @@ function dilateMask(mask, sw, sh) {
|
|
|
106
103
|
return maskResult;
|
|
107
104
|
}
|
|
108
105
|
function smoothEdgeMask(mask, sw, sh) {
|
|
109
|
-
const weights = [
|
|
106
|
+
const weights = [
|
|
107
|
+
1 / 9,
|
|
108
|
+
1 / 9,
|
|
109
|
+
1 / 9,
|
|
110
|
+
1 / 9,
|
|
111
|
+
1 / 9,
|
|
112
|
+
1 / 9,
|
|
113
|
+
1 / 9,
|
|
114
|
+
1 / 9,
|
|
115
|
+
1 / 9,
|
|
116
|
+
];
|
|
110
117
|
const side = Math.round(Math.sqrt(weights.length));
|
|
111
118
|
const halfSide = Math.floor(side / 2);
|
|
112
119
|
const maskResult = [];
|
|
@@ -130,7 +137,7 @@ function smoothEdgeMask(mask, sw, sh) {
|
|
|
130
137
|
}
|
|
131
138
|
return maskResult;
|
|
132
139
|
}
|
|
133
|
-
const Mask = function (imageData) {
|
|
140
|
+
export const Mask = function (imageData) {
|
|
134
141
|
const threshold = this.threshold();
|
|
135
142
|
let mask = backgroundMask(imageData, threshold);
|
|
136
143
|
if (mask) {
|
|
@@ -141,5 +148,4 @@ const Mask = function (imageData) {
|
|
|
141
148
|
}
|
|
142
149
|
return imageData;
|
|
143
150
|
};
|
|
144
|
-
|
|
145
|
-
Factory_1.Factory.addGetterSetter(Node_1.Node, 'threshold', 0, (0, Validators_1.getNumberValidator)(), Factory_1.Factory.afterSetFilter);
|
|
151
|
+
Factory.addGetterSetter(Node, 'threshold', 0, getNumberValidator(), Factory.afterSetFilter);
|
package/lib/filters/Noise.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Filter } from '../Node.
|
|
1
|
+
import type { Filter } from '../Node.ts';
|
|
2
2
|
export declare const Noise: Filter;
|
package/lib/filters/Noise.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const Node_1 = require("../Node");
|
|
6
|
-
const Validators_1 = require("../Validators");
|
|
7
|
-
const Noise = function (imageData) {
|
|
1
|
+
import { Factory } from "../Factory.js";
|
|
2
|
+
import { Node } from "../Node.js";
|
|
3
|
+
import { getNumberValidator } from "../Validators.js";
|
|
4
|
+
export const Noise = function (imageData) {
|
|
8
5
|
const amount = this.noise() * 255, data = imageData.data, nPixels = data.length, half = amount / 2;
|
|
9
6
|
for (let i = 0; i < nPixels; i += 4) {
|
|
10
7
|
data[i + 0] += half - 2 * half * Math.random();
|
|
@@ -12,5 +9,4 @@ const Noise = function (imageData) {
|
|
|
12
9
|
data[i + 2] += half - 2 * half * Math.random();
|
|
13
10
|
}
|
|
14
11
|
};
|
|
15
|
-
|
|
16
|
-
Factory_1.Factory.addGetterSetter(Node_1.Node, 'noise', 0.2, (0, Validators_1.getNumberValidator)(), Factory_1.Factory.afterSetFilter);
|
|
12
|
+
Factory.addGetterSetter(Node, 'noise', 0.2, getNumberValidator(), Factory.afterSetFilter);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Filter } from '../Node.
|
|
1
|
+
import type { Filter } from '../Node.ts';
|
|
2
2
|
export declare const Pixelate: Filter;
|
package/lib/filters/Pixelate.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const Node_1 = require("../Node");
|
|
7
|
-
const Validators_1 = require("../Validators");
|
|
8
|
-
const Pixelate = function (imageData) {
|
|
1
|
+
import { Factory } from "../Factory.js";
|
|
2
|
+
import { Util } from "../Util.js";
|
|
3
|
+
import { Node } from "../Node.js";
|
|
4
|
+
import { getNumberValidator } from "../Validators.js";
|
|
5
|
+
export const Pixelate = function (imageData) {
|
|
9
6
|
let pixelSize = Math.ceil(this.pixelSize()), width = imageData.width, height = imageData.height, nBinsX = Math.ceil(width / pixelSize), nBinsY = Math.ceil(height / pixelSize), data = imageData.data;
|
|
10
7
|
if (pixelSize <= 0) {
|
|
11
|
-
|
|
8
|
+
Util.error('pixelSize value can not be <= 0');
|
|
12
9
|
return;
|
|
13
10
|
}
|
|
14
11
|
for (let xBin = 0; xBin < nBinsX; xBin += 1) {
|
|
@@ -60,5 +57,4 @@ const Pixelate = function (imageData) {
|
|
|
60
57
|
}
|
|
61
58
|
}
|
|
62
59
|
};
|
|
63
|
-
|
|
64
|
-
Factory_1.Factory.addGetterSetter(Node_1.Node, 'pixelSize', 8, (0, Validators_1.getNumberValidator)(), Factory_1.Factory.afterSetFilter);
|
|
60
|
+
Factory.addGetterSetter(Node, 'pixelSize', 8, getNumberValidator(), Factory.afterSetFilter);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Filter } from '../Node.
|
|
1
|
+
import type { Filter } from '../Node.ts';
|
|
2
2
|
export declare const Posterize: Filter;
|
package/lib/filters/Posterize.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const Node_1 = require("../Node");
|
|
6
|
-
const Validators_1 = require("../Validators");
|
|
7
|
-
const Posterize = function (imageData) {
|
|
1
|
+
import { Factory } from "../Factory.js";
|
|
2
|
+
import { Node } from "../Node.js";
|
|
3
|
+
import { getNumberValidator } from "../Validators.js";
|
|
4
|
+
export const Posterize = function (imageData) {
|
|
8
5
|
const levels = Math.round(this.levels() * 254) + 1, data = imageData.data, len = data.length, scale = 255 / levels;
|
|
9
6
|
for (let i = 0; i < len; i += 1) {
|
|
10
7
|
data[i] = Math.floor(data[i] / scale) * scale;
|
|
11
8
|
}
|
|
12
9
|
};
|
|
13
|
-
|
|
14
|
-
Factory_1.Factory.addGetterSetter(Node_1.Node, 'levels', 0.5, (0, Validators_1.getNumberValidator)(), Factory_1.Factory.afterSetFilter);
|
|
10
|
+
Factory.addGetterSetter(Node, 'levels', 0.5, getNumberValidator(), Factory.afterSetFilter);
|
package/lib/filters/RGB.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Filter } from '../Node.
|
|
1
|
+
import type { Filter } from '../Node.ts';
|
|
2
2
|
export declare const RGB: Filter;
|
package/lib/filters/RGB.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const Node_1 = require("../Node");
|
|
6
|
-
const Validators_1 = require("../Validators");
|
|
7
|
-
const RGB = function (imageData) {
|
|
1
|
+
import { Factory } from "../Factory.js";
|
|
2
|
+
import { Node } from "../Node.js";
|
|
3
|
+
import { RGBComponent } from "../Validators.js";
|
|
4
|
+
export const RGB = function (imageData) {
|
|
8
5
|
const data = imageData.data, nPixels = data.length, red = this.red(), green = this.green(), blue = this.blue();
|
|
9
6
|
for (let i = 0; i < nPixels; i += 4) {
|
|
10
7
|
const brightness = (0.34 * data[i] + 0.5 * data[i + 1] + 0.16 * data[i + 2]) / 255;
|
|
@@ -14,8 +11,7 @@ const RGB = function (imageData) {
|
|
|
14
11
|
data[i + 3] = data[i + 3];
|
|
15
12
|
}
|
|
16
13
|
};
|
|
17
|
-
|
|
18
|
-
Factory_1.Factory.addGetterSetter(Node_1.Node, 'red', 0, function (val) {
|
|
14
|
+
Factory.addGetterSetter(Node, 'red', 0, function (val) {
|
|
19
15
|
this._filterUpToDate = false;
|
|
20
16
|
if (val > 255) {
|
|
21
17
|
return 255;
|
|
@@ -27,7 +23,7 @@ Factory_1.Factory.addGetterSetter(Node_1.Node, 'red', 0, function (val) {
|
|
|
27
23
|
return Math.round(val);
|
|
28
24
|
}
|
|
29
25
|
});
|
|
30
|
-
|
|
26
|
+
Factory.addGetterSetter(Node, 'green', 0, function (val) {
|
|
31
27
|
this._filterUpToDate = false;
|
|
32
28
|
if (val > 255) {
|
|
33
29
|
return 255;
|
|
@@ -39,4 +35,4 @@ Factory_1.Factory.addGetterSetter(Node_1.Node, 'green', 0, function (val) {
|
|
|
39
35
|
return Math.round(val);
|
|
40
36
|
}
|
|
41
37
|
});
|
|
42
|
-
|
|
38
|
+
Factory.addGetterSetter(Node, 'blue', 0, RGBComponent, Factory.afterSetFilter);
|
package/lib/filters/RGBA.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Filter } from '../Node.
|
|
1
|
+
import type { Filter } from '../Node.ts';
|
|
2
2
|
export declare const RGBA: Filter;
|