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.
Files changed (129) hide show
  1. package/README.md +1 -1
  2. package/konva.js +664 -226
  3. package/konva.min.js +46 -4
  4. package/lib/Animation.d.ts +2 -2
  5. package/lib/Animation.js +7 -11
  6. package/lib/BezierFunctions.js +9 -15
  7. package/lib/Canvas.d.ts +1 -1
  8. package/lib/Canvas.js +14 -20
  9. package/lib/Container.d.ts +7 -6
  10. package/lib/Container.js +12 -16
  11. package/lib/Context.d.ts +7 -5
  12. package/lib/Context.js +34 -14
  13. package/lib/Core.d.ts +2 -2
  14. package/lib/Core.js +3 -7
  15. package/lib/DragAndDrop.d.ts +3 -3
  16. package/lib/DragAndDrop.js +24 -27
  17. package/lib/Factory.d.ts +2 -2
  18. package/lib/Factory.js +24 -27
  19. package/lib/FastLayer.d.ts +1 -1
  20. package/lib/FastLayer.js +6 -10
  21. package/lib/Global.d.ts +4 -3
  22. package/lib/Global.js +19 -19
  23. package/lib/Group.d.ts +4 -3
  24. package/lib/Group.js +6 -10
  25. package/lib/Layer.d.ts +10 -9
  26. package/lib/Layer.js +33 -37
  27. package/lib/Node.d.ts +16 -13
  28. package/lib/Node.js +207 -123
  29. package/lib/PointerEvents.d.ts +4 -4
  30. package/lib/PointerEvents.js +7 -14
  31. package/lib/Shape.d.ts +7 -4
  32. package/lib/Shape.js +91 -91
  33. package/lib/Stage.d.ts +8 -7
  34. package/lib/Stage.js +66 -56
  35. package/lib/Tween.d.ts +3 -2
  36. package/lib/Tween.js +29 -31
  37. package/lib/Util.d.ts +3 -2
  38. package/lib/Util.js +98 -38
  39. package/lib/Validators.js +44 -57
  40. package/lib/_CoreInternals.d.ts +49 -23
  41. package/lib/_CoreInternals.js +33 -36
  42. package/lib/_FullInternals.d.ts +126 -62
  43. package/lib/_FullInternals.js +77 -78
  44. package/lib/canvas-backend.d.ts +2 -0
  45. package/lib/canvas-backend.js +27 -0
  46. package/lib/filters/Blur.d.ts +1 -1
  47. package/lib/filters/Blur.js +5 -9
  48. package/lib/filters/Brighten.d.ts +1 -1
  49. package/lib/filters/Brighten.js +5 -9
  50. package/lib/filters/Brightness.d.ts +2 -0
  51. package/lib/filters/Brightness.js +8 -0
  52. package/lib/filters/Contrast.d.ts +1 -1
  53. package/lib/filters/Contrast.js +5 -9
  54. package/lib/filters/Emboss.d.ts +1 -1
  55. package/lib/filters/Emboss.js +95 -101
  56. package/lib/filters/Enhance.d.ts +1 -1
  57. package/lib/filters/Enhance.js +5 -9
  58. package/lib/filters/Grayscale.d.ts +1 -1
  59. package/lib/filters/Grayscale.js +1 -5
  60. package/lib/filters/HSL.d.ts +1 -1
  61. package/lib/filters/HSL.js +7 -11
  62. package/lib/filters/HSV.d.ts +1 -1
  63. package/lib/filters/HSV.js +7 -11
  64. package/lib/filters/Invert.d.ts +1 -1
  65. package/lib/filters/Invert.js +1 -5
  66. package/lib/filters/Kaleidoscope.d.ts +1 -1
  67. package/lib/filters/Kaleidoscope.js +9 -13
  68. package/lib/filters/Mask.d.ts +1 -1
  69. package/lib/filters/Mask.js +16 -10
  70. package/lib/filters/Noise.d.ts +1 -1
  71. package/lib/filters/Noise.js +5 -9
  72. package/lib/filters/Pixelate.d.ts +1 -1
  73. package/lib/filters/Pixelate.js +7 -11
  74. package/lib/filters/Posterize.d.ts +1 -1
  75. package/lib/filters/Posterize.js +5 -9
  76. package/lib/filters/RGB.d.ts +1 -1
  77. package/lib/filters/RGB.js +7 -11
  78. package/lib/filters/RGBA.d.ts +1 -1
  79. package/lib/filters/RGBA.js +8 -12
  80. package/lib/filters/Sepia.d.ts +1 -1
  81. package/lib/filters/Sepia.js +1 -5
  82. package/lib/filters/Solarize.d.ts +1 -1
  83. package/lib/filters/Solarize.js +13 -29
  84. package/lib/filters/Threshold.d.ts +1 -1
  85. package/lib/filters/Threshold.js +5 -9
  86. package/lib/index.d.ts +1 -1
  87. package/lib/index.js +2 -4
  88. package/lib/shapes/Arc.d.ts +4 -3
  89. package/lib/shapes/Arc.js +13 -17
  90. package/lib/shapes/Arrow.d.ts +4 -3
  91. package/lib/shapes/Arrow.js +13 -17
  92. package/lib/shapes/Circle.d.ts +4 -3
  93. package/lib/shapes/Circle.js +7 -11
  94. package/lib/shapes/Ellipse.d.ts +4 -3
  95. package/lib/shapes/Ellipse.js +9 -13
  96. package/lib/shapes/Image.d.ts +4 -3
  97. package/lib/shapes/Image.js +17 -21
  98. package/lib/shapes/Label.d.ts +7 -6
  99. package/lib/shapes/Label.js +13 -18
  100. package/lib/shapes/Line.d.ts +4 -3
  101. package/lib/shapes/Line.js +10 -14
  102. package/lib/shapes/Path.d.ts +3 -2
  103. package/lib/shapes/Path.js +83 -23
  104. package/lib/shapes/Rect.d.ts +4 -3
  105. package/lib/shapes/Rect.js +9 -13
  106. package/lib/shapes/RegularPolygon.d.ts +6 -3
  107. package/lib/shapes/RegularPolygon.js +19 -16
  108. package/lib/shapes/Ring.d.ts +4 -3
  109. package/lib/shapes/Ring.js +8 -12
  110. package/lib/shapes/Sprite.d.ts +5 -4
  111. package/lib/shapes/Sprite.js +15 -19
  112. package/lib/shapes/Star.d.ts +4 -3
  113. package/lib/shapes/Star.js +9 -13
  114. package/lib/shapes/Text.d.ts +16 -3
  115. package/lib/shapes/Text.js +73 -53
  116. package/lib/shapes/TextPath.d.ts +5 -4
  117. package/lib/shapes/TextPath.js +48 -41
  118. package/lib/shapes/Transformer.d.ts +8 -8
  119. package/lib/shapes/Transformer.js +90 -90
  120. package/lib/shapes/Wedge.d.ts +4 -3
  121. package/lib/shapes/Wedge.js +12 -16
  122. package/lib/skia-backend.d.ts +2 -0
  123. package/lib/skia-backend.js +24 -0
  124. package/lib/types.d.ts +22 -22
  125. package/lib/types.js +21 -25
  126. package/package.json +53 -25
  127. package/lib/index-node.d.ts +0 -2
  128. package/lib/index-node.js +0 -21
  129. package/lib/index-types.d.ts +0 -181
@@ -1,107 +1,101 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Emboss = void 0;
4
- const Factory_1 = require("../Factory");
5
- const Node_1 = require("../Node");
6
- const Util_1 = require("../Util");
7
- const Validators_1 = require("../Validators");
8
- const Emboss = function (imageData) {
9
- const strength = this.embossStrength() * 10, greyLevel = this.embossWhiteLevel() * 255, direction = this.embossDirection(), blend = this.embossBlend(), data = imageData.data, w = imageData.width, h = imageData.height, w4 = w * 4;
10
- let dirY = 0, dirX = 0, y = h;
11
- switch (direction) {
12
- case 'top-left':
13
- dirY = -1;
14
- dirX = -1;
15
- break;
16
- case 'top':
17
- dirY = -1;
18
- dirX = 0;
19
- break;
20
- case 'top-right':
21
- dirY = -1;
22
- dirX = 1;
23
- break;
24
- case 'right':
25
- dirY = 0;
26
- dirX = 1;
27
- break;
28
- case 'bottom-right':
29
- dirY = 1;
30
- dirX = 1;
31
- break;
32
- case 'bottom':
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
- do {
48
- const offsetY = (y - 1) * w4;
49
- let otherY = dirY;
50
- if (y + otherY < 1) {
51
- otherY = 0;
52
- }
53
- if (y + otherY > h) {
54
- otherY = 0;
55
- }
56
- const offsetYOther = (y - 1 + otherY) * w * 4;
57
- let x = w;
58
- do {
59
- const offset = offsetY + (x - 1) * 4;
60
- let otherX = dirX;
61
- if (x + otherX < 1) {
62
- otherX = 0;
63
- }
64
- if (x + otherX > w) {
65
- otherX = 0;
66
- }
67
- const offsetOther = offsetYOther + (x - 1 + otherX) * 4;
68
- const dR = data[offset] - data[offsetOther];
69
- const dG = data[offset + 1] - data[offsetOther + 1];
70
- const dB = data[offset + 2] - data[offsetOther + 2];
71
- let dif = dR;
72
- const absDif = dif > 0 ? dif : -dif;
73
- const absG = dG > 0 ? dG : -dG;
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 r = data[offset] + dif;
84
- const g = data[offset + 1] + dif;
85
- const b = data[offset + 2] + dif;
86
- data[offset] = r > 255 ? 255 : r < 0 ? 0 : r;
87
- data[offset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
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
- let grey = greyLevel - dif;
92
- if (grey < 0) {
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
- } while (--x);
101
- } while (--y);
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
- exports.Emboss = Emboss;
104
- Factory_1.Factory.addGetterSetter(Node_1.Node, 'embossStrength', 0.5, (0, Validators_1.getNumberValidator)(), Factory_1.Factory.afterSetFilter);
105
- Factory_1.Factory.addGetterSetter(Node_1.Node, 'embossWhiteLevel', 0.5, (0, Validators_1.getNumberValidator)(), Factory_1.Factory.afterSetFilter);
106
- Factory_1.Factory.addGetterSetter(Node_1.Node, 'embossDirection', 'top-left', undefined, Factory_1.Factory.afterSetFilter);
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);
@@ -1,2 +1,2 @@
1
- import { Filter } from '../Node.js';
1
+ import type { Filter } from '../Node.ts';
2
2
  export declare const Enhance: Filter;
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Enhance = void 0;
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
- exports.Enhance = Enhance;
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.js';
1
+ import type { Filter } from '../Node.ts';
2
2
  export declare const Grayscale: Filter;
@@ -1,7 +1,4 @@
1
- "use strict";
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;
@@ -1,2 +1,2 @@
1
- import { Filter } from '../Node.js';
1
+ import type { Filter } from '../Node.ts';
2
2
  export declare const HSL: Filter;
@@ -1,13 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HSL = void 0;
4
- const Factory_1 = require("../Factory");
5
- const Node_1 = require("../Node");
6
- const Validators_1 = require("../Validators");
7
- Factory_1.Factory.addGetterSetter(Node_1.Node, 'hue', 0, (0, Validators_1.getNumberValidator)(), Factory_1.Factory.afterSetFilter);
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;
@@ -1,2 +1,2 @@
1
- import { Filter } from '../Node.js';
1
+ import type { Filter } from '../Node.ts';
2
2
  export declare const HSV: Filter;
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HSV = void 0;
4
- const Factory_1 = require("../Factory");
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
- exports.HSV = HSV;
25
- Factory_1.Factory.addGetterSetter(Node_1.Node, 'hue', 0, (0, Validators_1.getNumberValidator)(), Factory_1.Factory.afterSetFilter);
26
- Factory_1.Factory.addGetterSetter(Node_1.Node, 'saturation', 0, (0, Validators_1.getNumberValidator)(), Factory_1.Factory.afterSetFilter);
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);
@@ -1,2 +1,2 @@
1
- import { Filter } from '../Node.js';
1
+ import type { Filter } from '../Node.ts';
2
2
  export declare const Invert: Filter;
@@ -1,7 +1,4 @@
1
- "use strict";
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.js';
1
+ import type { Filter } from '../Node.ts';
2
2
  export declare const Kaleidoscope: Filter;
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Kaleidoscope = void 0;
4
- const Factory_1 = require("../Factory");
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 = Util_1.Util.createCanvasElement();
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
- Util_1.Util.releaseCanvas(tempCanvas);
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
- exports.Kaleidoscope = Kaleidoscope;
136
- Factory_1.Factory.addGetterSetter(Node_1.Node, 'kaleidoscopePower', 2, (0, Validators_1.getNumberValidator)(), Factory_1.Factory.afterSetFilter);
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);
@@ -1,2 +1,2 @@
1
- import { Filter } from '../Node.js';
1
+ import type { Filter } from '../Node.ts';
2
2
  export declare const Mask: Filter;
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Mask = void 0;
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 = [1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9];
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
- exports.Mask = Mask;
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);
@@ -1,2 +1,2 @@
1
- import { Filter } from '../Node.js';
1
+ import type { Filter } from '../Node.ts';
2
2
  export declare const Noise: Filter;
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Noise = void 0;
4
- const Factory_1 = require("../Factory");
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
- exports.Noise = Noise;
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.js';
1
+ import type { Filter } from '../Node.ts';
2
2
  export declare const Pixelate: Filter;
@@ -1,14 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Pixelate = void 0;
4
- const Factory_1 = require("../Factory");
5
- const Util_1 = require("../Util");
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
- Util_1.Util.error('pixelSize value can not be <= 0');
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
- exports.Pixelate = Pixelate;
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.js';
1
+ import type { Filter } from '../Node.ts';
2
2
  export declare const Posterize: Filter;
@@ -1,14 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Posterize = void 0;
4
- const Factory_1 = require("../Factory");
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
- exports.Posterize = Posterize;
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);
@@ -1,2 +1,2 @@
1
- import { Filter } from '../Node.js';
1
+ import type { Filter } from '../Node.ts';
2
2
  export declare const RGB: Filter;
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RGB = void 0;
4
- const Factory_1 = require("../Factory");
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
- exports.RGB = RGB;
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
- Factory_1.Factory.addGetterSetter(Node_1.Node, 'green', 0, function (val) {
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
- Factory_1.Factory.addGetterSetter(Node_1.Node, 'blue', 0, Validators_1.RGBComponent, Factory_1.Factory.afterSetFilter);
38
+ Factory.addGetterSetter(Node, 'blue', 0, RGBComponent, Factory.afterSetFilter);
@@ -1,2 +1,2 @@
1
- import { Filter } from '../Node.js';
1
+ import type { Filter } from '../Node.ts';
2
2
  export declare const RGBA: Filter;