konva 10.3.3 → 10.4.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 (123) hide show
  1. package/README.md +1 -1
  2. package/konva.js +1327 -1572
  3. package/konva.min.js +4 -4
  4. package/lib/Animation.d.ts +63 -3
  5. package/lib/Animation.js +86 -65
  6. package/lib/BezierFunctions.d.ts +10 -0
  7. package/lib/BezierFunctions.js +32 -0
  8. package/lib/Canvas.d.ts +53 -0
  9. package/lib/Canvas.js +93 -34
  10. package/lib/Container.d.ts +156 -9
  11. package/lib/Container.js +260 -25
  12. package/lib/Context.d.ts +247 -0
  13. package/lib/Context.js +312 -74
  14. package/lib/Core.js +1 -0
  15. package/lib/DragAndDrop.d.ts +1 -0
  16. package/lib/DragAndDrop.js +66 -17
  17. package/lib/Factory.d.ts +24 -1
  18. package/lib/Factory.js +14 -20
  19. package/lib/FastLayer.d.ts +14 -1
  20. package/lib/FastLayer.js +14 -1
  21. package/lib/Global.d.ts +114 -3
  22. package/lib/Global.js +134 -5
  23. package/lib/Group.d.ts +11 -0
  24. package/lib/Group.js +11 -0
  25. package/lib/Layer.d.ts +128 -3
  26. package/lib/Layer.js +260 -49
  27. package/lib/Node.d.ts +692 -30
  28. package/lib/Node.js +1534 -202
  29. package/lib/PointerEvents.d.ts +2 -1
  30. package/lib/PointerEvents.js +19 -1
  31. package/lib/Shape.d.ts +99 -14
  32. package/lib/Shape.js +1101 -67
  33. package/lib/Stage.d.ts +81 -1
  34. package/lib/Stage.js +166 -7
  35. package/lib/Tween.d.ts +159 -4
  36. package/lib/Tween.js +243 -24
  37. package/lib/Util.d.ts +147 -4
  38. package/lib/Util.js +332 -82
  39. package/lib/Validators.d.ts +0 -2
  40. package/lib/Validators.js +3 -25
  41. package/lib/_CoreInternals.d.ts +10 -6
  42. package/lib/_CoreInternals.js +1 -0
  43. package/lib/_FullInternals.d.ts +15 -6
  44. package/lib/_FullInternals.js +7 -0
  45. package/lib/canvas-backend.js +6 -0
  46. package/lib/filters/Blur.d.ts +18 -0
  47. package/lib/filters/Blur.js +97 -24
  48. package/lib/filters/Brighten.d.ts +21 -0
  49. package/lib/filters/Brighten.js +24 -0
  50. package/lib/filters/Brightness.d.ts +11 -0
  51. package/lib/filters/Brightness.js +16 -0
  52. package/lib/filters/Contrast.d.ts +10 -0
  53. package/lib/filters/Contrast.js +21 -0
  54. package/lib/filters/Emboss.d.ts +20 -0
  55. package/lib/filters/Emboss.js +68 -8
  56. package/lib/filters/Enhance.d.ts +14 -0
  57. package/lib/filters/Enhance.js +34 -0
  58. package/lib/filters/Grayscale.d.ts +9 -0
  59. package/lib/filters/Grayscale.js +12 -0
  60. package/lib/filters/HSL.d.ts +17 -0
  61. package/lib/filters/HSL.js +48 -5
  62. package/lib/filters/HSV.d.ts +18 -0
  63. package/lib/filters/HSV.js +49 -5
  64. package/lib/filters/Invert.d.ts +9 -0
  65. package/lib/filters/Invert.js +12 -0
  66. package/lib/filters/Kaleidoscope.d.ts +12 -0
  67. package/lib/filters/Kaleidoscope.js +83 -0
  68. package/lib/filters/Mask.d.ts +11 -0
  69. package/lib/filters/Mask.js +18 -0
  70. package/lib/filters/Noise.d.ts +19 -0
  71. package/lib/filters/Noise.js +19 -0
  72. package/lib/filters/Pixelate.d.ts +20 -0
  73. package/lib/filters/Pixelate.js +28 -1
  74. package/lib/filters/Posterize.d.ts +21 -0
  75. package/lib/filters/Posterize.js +22 -0
  76. package/lib/filters/RGB.d.ts +21 -0
  77. package/lib/filters/RGB.js +43 -28
  78. package/lib/filters/RGBA.d.ts +23 -0
  79. package/lib/filters/RGBA.js +28 -41
  80. package/lib/filters/Sepia.d.ts +9 -0
  81. package/lib/filters/Sepia.js +10 -0
  82. package/lib/filters/Solarize.d.ts +10 -0
  83. package/lib/filters/Solarize.js +11 -0
  84. package/lib/filters/Threshold.d.ts +22 -0
  85. package/lib/filters/Threshold.js +22 -0
  86. package/lib/shapes/Arc.d.ts +40 -0
  87. package/lib/shapes/Arc.js +89 -6
  88. package/lib/shapes/Arrow.d.ts +24 -1
  89. package/lib/shapes/Arrow.js +83 -0
  90. package/lib/shapes/Circle.d.ts +18 -0
  91. package/lib/shapes/Circle.js +36 -9
  92. package/lib/shapes/Ellipse.d.ts +34 -2
  93. package/lib/shapes/Ellipse.js +67 -9
  94. package/lib/shapes/Image.d.ts +49 -0
  95. package/lib/shapes/Image.js +151 -22
  96. package/lib/shapes/Label.d.ts +65 -1
  97. package/lib/shapes/Label.js +113 -20
  98. package/lib/shapes/Line.d.ts +50 -8
  99. package/lib/shapes/Line.js +116 -20
  100. package/lib/shapes/Path.d.ts +40 -6
  101. package/lib/shapes/Path.js +187 -128
  102. package/lib/shapes/Rect.d.ts +18 -0
  103. package/lib/shapes/Rect.js +36 -0
  104. package/lib/shapes/RegularPolygon.d.ts +22 -0
  105. package/lib/shapes/RegularPolygon.js +70 -0
  106. package/lib/shapes/Ring.d.ts +19 -0
  107. package/lib/shapes/Ring.js +51 -5
  108. package/lib/shapes/Sprite.d.ts +78 -0
  109. package/lib/shapes/Sprite.js +238 -25
  110. package/lib/shapes/Star.d.ts +23 -0
  111. package/lib/shapes/Star.js +62 -0
  112. package/lib/shapes/Text.d.ts +59 -1
  113. package/lib/shapes/Text.js +481 -97
  114. package/lib/shapes/TextPath.d.ts +49 -3
  115. package/lib/shapes/TextPath.js +278 -34
  116. package/lib/shapes/Transformer.d.ts +108 -11
  117. package/lib/shapes/Transformer.js +744 -102
  118. package/lib/shapes/Wedge.d.ts +22 -0
  119. package/lib/shapes/Wedge.js +67 -3
  120. package/lib/skia-backend.js +9 -0
  121. package/lib/types.d.ts +2 -23
  122. package/lib/types.js +1 -21
  123. package/package.json +12 -16
@@ -1,13 +1,28 @@
1
1
  import { Factory } from "../Factory.js";
2
2
  import { Node } from "../Node.js";
3
3
  import { getNumberValidator } from "../Validators.js";
4
+ /**
5
+ * Emboss Filter.
6
+ * @function
7
+ * @memberof Konva.Filters
8
+ * @param {Object} imageData
9
+ * @example
10
+ * node.cache();
11
+ * node.filters([Konva.Filters.Emboss]);
12
+ * node.embossStrength(0.8);
13
+ * node.embossWhiteLevel(0.3);
14
+ * node.embossDirection('right');
15
+ * node.embossBlend(true);
16
+ */
4
17
  export const Emboss = function (imageData) {
5
18
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
6
19
  const data = imageData.data;
7
20
  const w = imageData.width;
8
21
  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));
22
+ // Inputs from Konva node
23
+ 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)); // [0..1]
24
+ 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)); // [0..1]
25
+ // Convert string direction to degrees
11
26
  const directionMap = {
12
27
  'top-left': 315,
13
28
  top: 270,
@@ -18,27 +33,37 @@ export const Emboss = function (imageData) {
18
33
  'bottom-left': 45,
19
34
  left: 0,
20
35
  };
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;
36
+ 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; // degrees
22
37
  const blend = !!((_j = (_h = this.embossBlend) === null || _h === void 0 ? void 0 : _h.call(this)) !== null && _j !== void 0 ? _j : false);
38
+ // Internal mapping:
39
+ // - "strength" was 0..10; we honor your 0..1 API and scale accordingly.
40
+ // - Sobel directional response is roughly in [-1020..1020] for 8-bit luminance; scale to ~±128.
23
41
  const strength = strength01 * 10;
24
42
  const bias = whiteLevel01 * 255;
25
43
  const dirRad = (directionDeg * Math.PI) / 180;
26
44
  const cx = Math.cos(dirRad);
27
45
  const cy = Math.sin(dirRad);
28
- const SCALE = (128 / 1020) * strength;
29
- const src = new Uint8ClampedArray(data);
46
+ const SCALE = (128 / 1020) * strength; // ≈0.1255 * strength
47
+ // Precompute luminance (Rec.709)
48
+ const src = new Uint8ClampedArray(data); // snapshot
30
49
  const lum = new Float32Array(w * h);
31
50
  for (let p = 0, i = 0; i < data.length; i += 4, p++) {
32
51
  lum[p] = 0.2126 * src[i] + 0.7152 * src[i + 1] + 0.0722 * src[i + 2];
33
52
  }
53
+ // Sobel kernels (flattened)
34
54
  const Gx = [-1, 0, 1, -2, 0, 2, -1, 0, 1];
35
55
  const Gy = [-1, -2, -1, 0, 0, 0, 1, 2, 1];
56
+ // neighbor offsets around center pixel in lum space
36
57
  const OFF = [-w - 1, -w, -w + 1, -1, 0, 1, w - 1, w, w + 1];
58
+ // Helpers
37
59
  const clamp8 = (v) => (v < 0 ? 0 : v > 255 ? 255 : v);
60
+ // Process: leave a 1px border unchanged (faster/cleaner)
38
61
  for (let y = 1; y < h - 1; y++) {
39
62
  for (let x = 1; x < w - 1; x++) {
40
63
  const p = y * w + x;
64
+ // Directional derivative = (cosθ * Gx + sinθ * Gy) • neighborhood(lum)
41
65
  let sx = 0, sy = 0;
66
+ // unroll loop for speed
42
67
  sx += lum[p + OFF[0]] * Gx[0];
43
68
  sy += lum[p + OFF[0]] * Gy[0];
44
69
  sx += lum[p + OFF[1]] * Gx[1];
@@ -47,6 +72,7 @@ export const Emboss = function (imageData) {
47
72
  sy += lum[p + OFF[2]] * Gy[2];
48
73
  sx += lum[p + OFF[3]] * Gx[3];
49
74
  sy += lum[p + OFF[3]] * Gy[3];
75
+ // center has 0 weights in both Sobel masks; can skip if desired
50
76
  sx += lum[p + OFF[5]] * Gx[5];
51
77
  sy += lum[p + OFF[5]] * Gy[5];
52
78
  sx += lum[p + OFF[6]] * Gx[6];
@@ -55,22 +81,26 @@ export const Emboss = function (imageData) {
55
81
  sy += lum[p + OFF[7]] * Gy[7];
56
82
  sx += lum[p + OFF[8]] * Gx[8];
57
83
  sy += lum[p + OFF[8]] * Gy[8];
58
- const r = cx * sx + cy * sy;
59
- const outGray = clamp8(bias + r * SCALE);
84
+ const r = cx * sx + cy * sy; // directional response
85
+ const outGray = clamp8(bias + r * SCALE); // biased, scaled, clamped
60
86
  const o = p * 4;
61
87
  if (blend) {
62
- const delta = outGray - bias;
88
+ // Add the emboss "relief" around chosen bias to original RGB
89
+ const delta = outGray - bias; // symmetric around whiteLevel
63
90
  data[o] = clamp8(src[o] + delta);
64
91
  data[o + 1] = clamp8(src[o + 1] + delta);
65
92
  data[o + 2] = clamp8(src[o + 2] + delta);
66
93
  data[o + 3] = src[o + 3];
67
94
  }
68
95
  else {
96
+ // Grayscale embossed output
69
97
  data[o] = data[o + 1] = data[o + 2] = outGray;
70
98
  data[o + 3] = src[o + 3];
71
99
  }
72
100
  }
73
101
  }
102
+ // Copy border (untouched) to keep edges clean
103
+ // top & bottom rows
74
104
  for (let x = 0; x < w; x++) {
75
105
  let oTop = x * 4, oBot = ((h - 1) * w + x) * 4;
76
106
  data[oTop] = src[oTop];
@@ -82,6 +112,7 @@ export const Emboss = function (imageData) {
82
112
  data[oBot + 2] = src[oBot + 2];
83
113
  data[oBot + 3] = src[oBot + 3];
84
114
  }
115
+ // left & right columns
85
116
  for (let y = 1; y < h - 1; y++) {
86
117
  let oL = y * w * 4, oR = (y * w + (w - 1)) * 4;
87
118
  data[oL] = src[oL];
@@ -96,6 +127,35 @@ export const Emboss = function (imageData) {
96
127
  return imageData;
97
128
  };
98
129
  Factory.addGetterSetter(Node, 'embossStrength', 0.5, getNumberValidator(), Factory.afterSetFilter);
130
+ /**
131
+ * get/set emboss strength. Use with {@link Konva.Filters.Emboss} filter.
132
+ * @name Konva.Node#embossStrength
133
+ * @method
134
+ * @param {Number} level between 0 and 1. Default is 0.5
135
+ * @returns {Number}
136
+ */
99
137
  Factory.addGetterSetter(Node, 'embossWhiteLevel', 0.5, getNumberValidator(), Factory.afterSetFilter);
138
+ /**
139
+ * get/set emboss white level. Use with {@link Konva.Filters.Emboss} filter.
140
+ * @name Konva.Node#embossWhiteLevel
141
+ * @method
142
+ * @param {Number} embossWhiteLevel between 0 and 1. Default is 0.5
143
+ * @returns {Number}
144
+ */
100
145
  Factory.addGetterSetter(Node, 'embossDirection', 'top-left', undefined, Factory.afterSetFilter);
146
+ /**
147
+ * get/set emboss direction. Use with {@link Konva.Filters.Emboss} filter.
148
+ * @name Konva.Node#embossDirection
149
+ * @method
150
+ * @param {String} embossDirection can be top-left, top, top-right, right, bottom-right, bottom, bottom-left or left
151
+ * The default is top-left
152
+ * @returns {String}
153
+ */
101
154
  Factory.addGetterSetter(Node, 'embossBlend', false, undefined, Factory.afterSetFilter);
155
+ /**
156
+ * get/set emboss blend. Use with {@link Konva.Filters.Emboss} filter.
157
+ * @name Konva.Node#embossBlend
158
+ * @method
159
+ * @param {Boolean} embossBlend
160
+ * @returns {Boolean}
161
+ */
@@ -1,2 +1,16 @@
1
1
  import type { Filter } from '../Node.ts';
2
+ /**
3
+ * Enhance Filter. Adjusts the colors so that they span the widest
4
+ * possible range (ie 0-255). Performs w*h pixel reads and w*h pixel
5
+ * writes.
6
+ * @function
7
+ * @name Enhance
8
+ * @memberof Konva.Filters
9
+ * @param {Object} imageData
10
+ * @author ippo615
11
+ * @example
12
+ * node.cache();
13
+ * node.filters([Konva.Filters.Enhance]);
14
+ * node.enhance(0.4);
15
+ */
2
16
  export declare const Enhance: Filter;
@@ -2,24 +2,43 @@ import { Factory } from "../Factory.js";
2
2
  import { Node } from "../Node.js";
3
3
  import { getNumberValidator } from "../Validators.js";
4
4
  function remap(fromValue, fromMin, fromMax, toMin, toMax) {
5
+ // Compute the range of the data
5
6
  const fromRange = fromMax - fromMin, toRange = toMax - toMin;
7
+ // If either range is 0, then the value can only be mapped to 1 value
6
8
  if (fromRange === 0) {
7
9
  return toMin + toRange / 2;
8
10
  }
9
11
  if (toRange === 0) {
10
12
  return toMin;
11
13
  }
14
+ // (1) untranslate, (2) unscale, (3) rescale, (4) retranslate
12
15
  let toValue = (fromValue - fromMin) / fromRange;
13
16
  toValue = toRange * toValue + toMin;
14
17
  return toValue;
15
18
  }
19
+ /**
20
+ * Enhance Filter. Adjusts the colors so that they span the widest
21
+ * possible range (ie 0-255). Performs w*h pixel reads and w*h pixel
22
+ * writes.
23
+ * @function
24
+ * @name Enhance
25
+ * @memberof Konva.Filters
26
+ * @param {Object} imageData
27
+ * @author ippo615
28
+ * @example
29
+ * node.cache();
30
+ * node.filters([Konva.Filters.Enhance]);
31
+ * node.enhance(0.4);
32
+ */
16
33
  export const Enhance = function (imageData) {
17
34
  const data = imageData.data, nSubPixels = data.length;
18
35
  let rMin = data[0], rMax = rMin, r, gMin = data[1], gMax = gMin, g, bMin = data[2], bMax = bMin, b;
36
+ // If we are not enhancing anything - don't do any computation
19
37
  const enhanceAmount = this.enhance();
20
38
  if (enhanceAmount === 0) {
21
39
  return;
22
40
  }
41
+ // 1st Pass - find the min and max for each channel:
23
42
  for (let i = 0; i < nSubPixels; i += 4) {
24
43
  r = data[i + 0];
25
44
  if (r < rMin) {
@@ -42,7 +61,11 @@ export const Enhance = function (imageData) {
42
61
  else if (b > bMax) {
43
62
  bMax = b;
44
63
  }
64
+ //a = data[i + 3];
65
+ //if (a < aMin) { aMin = a; } else
66
+ //if (a > aMax) { aMax = a; }
45
67
  }
68
+ // If there is only 1 level - don't remap
46
69
  if (rMax === rMin) {
47
70
  rMax = 255;
48
71
  rMin = 0;
@@ -56,6 +79,7 @@ export const Enhance = function (imageData) {
56
79
  bMin = 0;
57
80
  }
58
81
  let rGoalMax, rGoalMin, gGoalMax, gGoalMin, bGoalMax, bGoalMin;
82
+ // If the enhancement is positive - stretch the histogram
59
83
  if (enhanceAmount > 0) {
60
84
  rGoalMax = rMax + enhanceAmount * (255 - rMax);
61
85
  rGoalMin = rMin - enhanceAmount * (rMin - 0);
@@ -63,6 +87,7 @@ export const Enhance = function (imageData) {
63
87
  gGoalMin = gMin - enhanceAmount * (gMin - 0);
64
88
  bGoalMax = bMax + enhanceAmount * (255 - bMax);
65
89
  bGoalMin = bMin - enhanceAmount * (bMin - 0);
90
+ // If the enhancement is negative - compress the histogram
66
91
  }
67
92
  else {
68
93
  const rMid = (rMax + rMin) * 0.5;
@@ -75,10 +100,19 @@ export const Enhance = function (imageData) {
75
100
  bGoalMax = bMax + enhanceAmount * (bMax - bMid);
76
101
  bGoalMin = bMin + enhanceAmount * (bMin - bMid);
77
102
  }
103
+ // Pass 2 - remap everything, except the alpha
78
104
  for (let i = 0; i < nSubPixels; i += 4) {
79
105
  data[i + 0] = remap(data[i + 0], rMin, rMax, rGoalMin, rGoalMax);
80
106
  data[i + 1] = remap(data[i + 1], gMin, gMax, gGoalMin, gGoalMax);
81
107
  data[i + 2] = remap(data[i + 2], bMin, bMax, bGoalMin, bGoalMax);
108
+ //data[i + 3] = remap(data[i + 3], aMin, aMax, aGoalMin, aGoalMax);
82
109
  }
83
110
  };
111
+ /**
112
+ * get/set enhance. Use with {@link Konva.Filters.Enhance} filter. -1 to 1 values
113
+ * @name Konva.Node#enhance
114
+ * @method
115
+ * @param {Float} amount
116
+ * @returns {Float}
117
+ */
84
118
  Factory.addGetterSetter(Node, 'enhance', 0, getNumberValidator(), Factory.afterSetFilter);
@@ -1,2 +1,11 @@
1
1
  import type { Filter } from '../Node.ts';
2
+ /**
3
+ * Grayscale Filter
4
+ * @function
5
+ * @memberof Konva.Filters
6
+ * @param {Object} imageData
7
+ * @example
8
+ * node.cache();
9
+ * node.filters([Konva.Filters.Grayscale]);
10
+ */
2
11
  export declare const Grayscale: Filter;
@@ -1,9 +1,21 @@
1
+ /**
2
+ * Grayscale Filter
3
+ * @function
4
+ * @memberof Konva.Filters
5
+ * @param {Object} imageData
6
+ * @example
7
+ * node.cache();
8
+ * node.filters([Konva.Filters.Grayscale]);
9
+ */
1
10
  export const Grayscale = function (imageData) {
2
11
  const data = imageData.data, len = data.length;
3
12
  for (let i = 0; i < len; i += 4) {
4
13
  const brightness = 0.34 * data[i] + 0.5 * data[i + 1] + 0.16 * data[i + 2];
14
+ // red
5
15
  data[i] = brightness;
16
+ // green
6
17
  data[i + 1] = brightness;
18
+ // blue
7
19
  data[i + 2] = brightness;
8
20
  }
9
21
  };
@@ -1,2 +1,19 @@
1
1
  import type { Filter } from '../Node.ts';
2
+ /**
3
+ * get/set hsl luminance. Use with {@link Konva.Filters.HSL} filter.
4
+ * @name Konva.Node#luminance
5
+ * @method
6
+ * @param {Number} value from -1 to 1
7
+ * @returns {Number}
8
+ */
9
+ /**
10
+ * HSL Filter. Adjusts the hue, saturation and luminance (or lightness)
11
+ * @function
12
+ * @memberof Konva.Filters
13
+ * @param {Object} imageData
14
+ * @author ippo615
15
+ * @example
16
+ * image.filters([Konva.Filters.HSL]);
17
+ * image.luminance(0.2);
18
+ */
2
19
  export declare const HSL: Filter;
@@ -2,14 +2,57 @@ import { Factory } from "../Factory.js";
2
2
  import { Node } from "../Node.js";
3
3
  import { getNumberValidator } from "../Validators.js";
4
4
  Factory.addGetterSetter(Node, 'hue', 0, getNumberValidator(), Factory.afterSetFilter);
5
+ /**
6
+ * get/set hsv hue in degrees. Use with {@link Konva.Filters.HSV} or {@link Konva.Filters.HSL} filter.
7
+ * @name Konva.Node#hue
8
+ * @method
9
+ * @param {Number} hue value between 0 and 359
10
+ * @returns {Number}
11
+ */
5
12
  Factory.addGetterSetter(Node, 'saturation', 0, getNumberValidator(), Factory.afterSetFilter);
13
+ /**
14
+ * get/set hsv saturation. Use with {@link Konva.Filters.HSV} or {@link Konva.Filters.HSL} filter.
15
+ * @name Konva.Node#saturation
16
+ * @method
17
+ * @param {Number} saturation 0 is no change, -1.0 halves the saturation, 1.0 doubles, etc..
18
+ * @returns {Number}
19
+ */
6
20
  Factory.addGetterSetter(Node, 'luminance', 0, getNumberValidator(), Factory.afterSetFilter);
21
+ /**
22
+ * get/set hsl luminance. Use with {@link Konva.Filters.HSL} filter.
23
+ * @name Konva.Node#luminance
24
+ * @method
25
+ * @param {Number} value from -1 to 1
26
+ * @returns {Number}
27
+ */
28
+ /**
29
+ * HSL Filter. Adjusts the hue, saturation and luminance (or lightness)
30
+ * @function
31
+ * @memberof Konva.Filters
32
+ * @param {Object} imageData
33
+ * @author ippo615
34
+ * @example
35
+ * image.filters([Konva.Filters.HSL]);
36
+ * image.luminance(0.2);
37
+ */
7
38
  export const HSL = function (imageData) {
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;
39
+ const data = imageData.data, nPixels = data.length, v = 1, s = Math.pow(2, this.saturation()), h = ((this.hue() % 360) + 360) % 360, l = this.luminance() * 127;
40
+ // Basis for the technique used:
41
+ // http://beesbuzz.biz/code/hsv_color_transforms.php
42
+ // V is the value multiplier (1 for none, 2 for double, 0.5 for half)
43
+ // S is the saturation multiplier (1 for none, 2 for double, 0.5 for half)
44
+ // H is the hue shift in degrees (0 to 360)
45
+ // vsu = V*S*cos(H*PI/180);
46
+ // vsw = V*S*sin(H*PI/180);
47
+ //[ .299V+.701vsu+.168vsw .587V-.587vsu+.330vsw .114V-.114vsu-.497vsw ] [R]
48
+ //[ .299V-.299vsu-.328vsw .587V+.413vsu+.035vsw .114V-.114vsu+.292vsw ]*[G]
49
+ //[ .299V-.300vsu+1.25vsw .587V-.588vsu-1.05vsw .114V+.886vsu-.203vsw ] [B]
50
+ // Precompute the values in the matrix:
9
51
  const vsu = v * s * Math.cos((h * Math.PI) / 180), vsw = v * s * Math.sin((h * Math.PI) / 180);
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;
11
- const gr = 0.299 * v - 0.299 * vsu - 0.328 * vsw, gg = 0.587 * v + 0.413 * vsu + 0.035 * vsw, gb = 0.114 * v - 0.114 * vsu + 0.293 * vsw;
12
- const br = 0.299 * v - 0.3 * vsu + 1.25 * vsw, bg = 0.587 * v - 0.586 * vsu - 1.05 * vsw, bb = 0.114 * v + 0.886 * vsu - 0.2 * vsw;
52
+ // (result spot)(source spot)
53
+ const rr = 0.299 * v + 0.701 * vsu + 0.168 * vsw, rg = 0.587 * v - 0.587 * vsu + 0.33 * vsw, rb = 0.114 * v - 0.114 * vsu - 0.497 * vsw;
54
+ const gr = 0.299 * v - 0.299 * vsu - 0.328 * vsw, gg = 0.587 * v + 0.413 * vsu + 0.035 * vsw, gb = 0.114 * v - 0.114 * vsu + 0.292 * vsw;
55
+ const br = 0.299 * v - 0.3 * vsu + 1.25 * vsw, bg = 0.587 * v - 0.588 * vsu - 1.05 * vsw, bb = 0.114 * v + 0.886 * vsu - 0.203 * vsw;
13
56
  let r, g, b, a;
14
57
  for (let i = 0; i < nPixels; i += 4) {
15
58
  r = data[i + 0];
@@ -19,6 +62,6 @@ export const HSL = function (imageData) {
19
62
  data[i + 0] = rr * r + rg * g + rb * b + l;
20
63
  data[i + 1] = gr * r + gg * g + gb * b + l;
21
64
  data[i + 2] = br * r + bg * g + bb * b + l;
22
- data[i + 3] = a;
65
+ data[i + 3] = a; // alpha
23
66
  }
24
67
  };
@@ -1,2 +1,20 @@
1
1
  import type { Filter } from '../Node.ts';
2
+ /**
3
+ * HSV Filter. Adjusts the hue, saturation and value
4
+ * @function
5
+ * @name HSV
6
+ * @memberof Konva.Filters
7
+ * @param {Object} imageData
8
+ * @author ippo615
9
+ * @example
10
+ * image.filters([Konva.Filters.HSV]);
11
+ * image.value(1); // twice as bright
12
+ */
2
13
  export declare const HSV: Filter;
14
+ /**
15
+ * get/set hsv value. Use with {@link Konva.Filters.HSV} filter.
16
+ * @name Konva.Node#value
17
+ * @method
18
+ * @param {Number} value 0 is no change, -1.0 halves the value, 1.0 doubles, etc..
19
+ * @returns {Number}
20
+ */
@@ -1,12 +1,35 @@
1
1
  import { Factory } from "../Factory.js";
2
2
  import { Node } from "../Node.js";
3
3
  import { getNumberValidator } from "../Validators.js";
4
+ /**
5
+ * HSV Filter. Adjusts the hue, saturation and value
6
+ * @function
7
+ * @name HSV
8
+ * @memberof Konva.Filters
9
+ * @param {Object} imageData
10
+ * @author ippo615
11
+ * @example
12
+ * image.filters([Konva.Filters.HSV]);
13
+ * image.value(1); // twice as bright
14
+ */
4
15
  export const HSV = function (imageData) {
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;
16
+ const data = imageData.data, nPixels = data.length, v = Math.pow(2, this.value()), s = Math.pow(2, this.saturation()), h = ((this.hue() % 360) + 360) % 360;
17
+ // Basis for the technique used:
18
+ // http://beesbuzz.biz/code/hsv_color_transforms.php
19
+ // V is the value multiplier (1 for none, 2 for double, 0.5 for half)
20
+ // S is the saturation multiplier (1 for none, 2 for double, 0.5 for half)
21
+ // H is the hue shift in degrees (0 to 360)
22
+ // vsu = V*S*cos(H*PI/180);
23
+ // vsw = V*S*sin(H*PI/180);
24
+ //[ .299V+.701vsu+.168vsw .587V-.587vsu+.330vsw .114V-.114vsu-.497vsw ] [R]
25
+ //[ .299V-.299vsu-.328vsw .587V+.413vsu+.035vsw .114V-.114vsu+.292vsw ]*[G]
26
+ //[ .299V-.300vsu+1.25vsw .587V-.588vsu-1.05vsw .114V+.886vsu-.203vsw ] [B]
27
+ // Precompute the values in the matrix:
6
28
  const vsu = v * s * Math.cos((h * Math.PI) / 180), vsw = v * s * Math.sin((h * Math.PI) / 180);
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;
8
- const gr = 0.299 * v - 0.299 * vsu - 0.328 * vsw, gg = 0.587 * v + 0.413 * vsu + 0.035 * vsw, gb = 0.114 * v - 0.114 * vsu + 0.293 * vsw;
9
- const br = 0.299 * v - 0.3 * vsu + 1.25 * vsw, bg = 0.587 * v - 0.586 * vsu - 1.05 * vsw, bb = 0.114 * v + 0.886 * vsu - 0.2 * vsw;
29
+ // (result spot)(source spot)
30
+ const rr = 0.299 * v + 0.701 * vsu + 0.168 * vsw, rg = 0.587 * v - 0.587 * vsu + 0.33 * vsw, rb = 0.114 * v - 0.114 * vsu - 0.497 * vsw;
31
+ const gr = 0.299 * v - 0.299 * vsu - 0.328 * vsw, gg = 0.587 * v + 0.413 * vsu + 0.035 * vsw, gb = 0.114 * v - 0.114 * vsu + 0.292 * vsw;
32
+ const br = 0.299 * v - 0.3 * vsu + 1.25 * vsw, bg = 0.587 * v - 0.588 * vsu - 1.05 * vsw, bb = 0.114 * v + 0.886 * vsu - 0.203 * vsw;
10
33
  for (let i = 0; i < nPixels; i += 4) {
11
34
  const r = data[i + 0];
12
35
  const g = data[i + 1];
@@ -15,9 +38,30 @@ export const HSV = function (imageData) {
15
38
  data[i + 0] = rr * r + rg * g + rb * b;
16
39
  data[i + 1] = gr * r + gg * g + gb * b;
17
40
  data[i + 2] = br * r + bg * g + bb * b;
18
- data[i + 3] = a;
41
+ data[i + 3] = a; // alpha
19
42
  }
20
43
  };
21
44
  Factory.addGetterSetter(Node, 'hue', 0, getNumberValidator(), Factory.afterSetFilter);
45
+ /**
46
+ * get/set hsv hue in degrees. Use with {@link Konva.Filters.HSV} or {@link Konva.Filters.HSL} filter.
47
+ * @name Konva.Node#hue
48
+ * @method
49
+ * @param {Number} hue value between 0 and 359
50
+ * @returns {Number}
51
+ */
22
52
  Factory.addGetterSetter(Node, 'saturation', 0, getNumberValidator(), Factory.afterSetFilter);
53
+ /**
54
+ * get/set hsv saturation. Use with {@link Konva.Filters.HSV} or {@link Konva.Filters.HSL} filter.
55
+ * @name Konva.Node#saturation
56
+ * @method
57
+ * @param {Number} saturation 0 is no change, -1.0 halves the saturation, 1.0 doubles, etc..
58
+ * @returns {Number}
59
+ */
23
60
  Factory.addGetterSetter(Node, 'value', 0, getNumberValidator(), Factory.afterSetFilter);
61
+ /**
62
+ * get/set hsv value. Use with {@link Konva.Filters.HSV} filter.
63
+ * @name Konva.Node#value
64
+ * @method
65
+ * @param {Number} value 0 is no change, -1.0 halves the value, 1.0 doubles, etc..
66
+ * @returns {Number}
67
+ */
@@ -1,2 +1,11 @@
1
1
  import type { Filter } from '../Node.ts';
2
+ /**
3
+ * Invert Filter
4
+ * @function
5
+ * @memberof Konva.Filters
6
+ * @param {Object} imageData
7
+ * @example
8
+ * node.cache();
9
+ * node.filters([Konva.Filters.Invert]);
10
+ */
2
11
  export declare const Invert: Filter;
@@ -1,8 +1,20 @@
1
+ /**
2
+ * Invert Filter
3
+ * @function
4
+ * @memberof Konva.Filters
5
+ * @param {Object} imageData
6
+ * @example
7
+ * node.cache();
8
+ * node.filters([Konva.Filters.Invert]);
9
+ */
1
10
  export const Invert = function (imageData) {
2
11
  const data = imageData.data, len = data.length;
3
12
  for (let i = 0; i < len; i += 4) {
13
+ // red
4
14
  data[i] = 255 - data[i];
15
+ // green
5
16
  data[i + 1] = 255 - data[i + 1];
17
+ // blue
6
18
  data[i + 2] = 255 - data[i + 2];
7
19
  }
8
20
  };
@@ -1,2 +1,14 @@
1
1
  import type { Filter } from '../Node.ts';
2
+ /**
3
+ * Kaleidoscope Filter.
4
+ * @function
5
+ * @name Kaleidoscope
6
+ * @author ippo615
7
+ * @memberof Konva.Filters
8
+ * @example
9
+ * node.cache();
10
+ * node.filters([Konva.Filters.Kaleidoscope]);
11
+ * node.kaleidoscopePower(3);
12
+ * node.kaleidoscopeAngle(45);
13
+ */
2
14
  export declare const Kaleidoscope: Filter;