konva 8.4.3 → 9.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 (190) hide show
  1. package/README.md +1 -9
  2. package/konva.js +17669 -16989
  3. package/konva.min.js +3 -3
  4. package/lib/Animation.js +11 -7
  5. package/lib/BezierFunctions.d.ts +6 -0
  6. package/lib/BezierFunctions.js +791 -0
  7. package/lib/Canvas.d.ts +1 -0
  8. package/lib/Canvas.js +26 -18
  9. package/lib/Container.js +16 -12
  10. package/lib/Context.d.ts +3 -1
  11. package/lib/Context.js +18 -10
  12. package/lib/Core.js +7 -3
  13. package/lib/DragAndDrop.js +25 -22
  14. package/lib/Factory.js +27 -24
  15. package/lib/FastLayer.js +10 -6
  16. package/lib/Global.js +16 -12
  17. package/lib/Group.js +10 -6
  18. package/lib/Layer.js +37 -33
  19. package/lib/Node.js +95 -90
  20. package/lib/PointerEvents.js +15 -7
  21. package/lib/Shape.js +90 -86
  22. package/lib/Stage.js +51 -47
  23. package/lib/Tween.js +26 -22
  24. package/lib/Util.js +29 -25
  25. package/lib/Validators.js +58 -44
  26. package/lib/_CoreInternals.js +36 -33
  27. package/lib/_FullInternals.js +78 -75
  28. package/lib/filters/Blur.js +9 -5
  29. package/lib/filters/Brighten.js +9 -5
  30. package/lib/filters/Contrast.js +9 -5
  31. package/lib/filters/Emboss.js +14 -10
  32. package/lib/filters/Enhance.js +9 -5
  33. package/lib/filters/Grayscale.js +5 -1
  34. package/lib/filters/HSL.js +11 -7
  35. package/lib/filters/HSV.js +11 -7
  36. package/lib/filters/Invert.js +5 -1
  37. package/lib/filters/Kaleidoscope.js +13 -9
  38. package/lib/filters/Mask.js +9 -5
  39. package/lib/filters/Noise.js +9 -5
  40. package/lib/filters/Pixelate.js +11 -7
  41. package/lib/filters/Posterize.js +9 -5
  42. package/lib/filters/RGB.js +11 -7
  43. package/lib/filters/RGBA.js +12 -8
  44. package/lib/filters/Sepia.js +5 -1
  45. package/lib/filters/Solarize.js +5 -1
  46. package/lib/filters/Threshold.js +9 -5
  47. package/lib/index-node.js +7 -5
  48. package/lib/index.js +4 -2
  49. package/lib/shapes/Arc.js +17 -13
  50. package/lib/shapes/Arrow.js +17 -13
  51. package/lib/shapes/Circle.js +11 -7
  52. package/lib/shapes/Ellipse.js +13 -9
  53. package/lib/shapes/Image.js +21 -17
  54. package/lib/shapes/Label.js +18 -13
  55. package/lib/shapes/Line.js +14 -10
  56. package/lib/shapes/Path.d.ts +5 -2
  57. package/lib/shapes/Path.js +44 -43
  58. package/lib/shapes/Rect.js +13 -9
  59. package/lib/shapes/RegularPolygon.js +12 -8
  60. package/lib/shapes/Ring.js +12 -8
  61. package/lib/shapes/Sprite.js +19 -15
  62. package/lib/shapes/Star.js +13 -9
  63. package/lib/shapes/Text.js +31 -26
  64. package/lib/shapes/TextPath.d.ts +5 -1
  65. package/lib/shapes/TextPath.js +82 -188
  66. package/lib/shapes/Transformer.js +85 -81
  67. package/lib/shapes/Wedge.js +16 -12
  68. package/lib/types.d.ts +6 -0
  69. package/lib/types.js +5 -2
  70. package/package.json +13 -42
  71. package/cmj/Animation.d.ts +0 -24
  72. package/cmj/Animation.js +0 -145
  73. package/cmj/Canvas.d.ts +0 -32
  74. package/cmj/Canvas.js +0 -114
  75. package/cmj/Container.d.ts +0 -47
  76. package/cmj/Container.js +0 -325
  77. package/cmj/Context.d.ts +0 -85
  78. package/cmj/Context.js +0 -538
  79. package/cmj/Core.d.ts +0 -3
  80. package/cmj/Core.js +0 -7
  81. package/cmj/DragAndDrop.d.ts +0 -17
  82. package/cmj/DragAndDrop.js +0 -111
  83. package/cmj/Factory.d.ts +0 -11
  84. package/cmj/Factory.js +0 -125
  85. package/cmj/FastLayer.d.ts +0 -4
  86. package/cmj/FastLayer.js +0 -16
  87. package/cmj/Global.d.ts +0 -34
  88. package/cmj/Global.js +0 -61
  89. package/cmj/Group.d.ts +0 -8
  90. package/cmj/Group.js +0 -17
  91. package/cmj/Layer.d.ts +0 -61
  92. package/cmj/Layer.js +0 -309
  93. package/cmj/Node.d.ts +0 -328
  94. package/cmj/Node.js +0 -1420
  95. package/cmj/PointerEvents.d.ts +0 -11
  96. package/cmj/PointerEvents.js +0 -45
  97. package/cmj/Shape.d.ts +0 -186
  98. package/cmj/Shape.js +0 -521
  99. package/cmj/Stage.d.ts +0 -85
  100. package/cmj/Stage.js +0 -692
  101. package/cmj/Tween.d.ts +0 -86
  102. package/cmj/Tween.js +0 -520
  103. package/cmj/Util.d.ts +0 -91
  104. package/cmj/Util.js +0 -801
  105. package/cmj/Validators.d.ts +0 -11
  106. package/cmj/Validators.js +0 -192
  107. package/cmj/_CoreInternals.d.ts +0 -152
  108. package/cmj/_CoreInternals.js +0 -37
  109. package/cmj/_FullInternals.d.ts +0 -196
  110. package/cmj/_FullInternals.js +0 -81
  111. package/cmj/filters/Blur.d.ts +0 -2
  112. package/cmj/filters/Blur.js +0 -701
  113. package/cmj/filters/Brighten.d.ts +0 -2
  114. package/cmj/filters/Brighten.js +0 -16
  115. package/cmj/filters/Contrast.d.ts +0 -2
  116. package/cmj/filters/Contrast.js +0 -38
  117. package/cmj/filters/Emboss.d.ts +0 -2
  118. package/cmj/filters/Emboss.js +0 -106
  119. package/cmj/filters/Enhance.d.ts +0 -2
  120. package/cmj/filters/Enhance.js +0 -87
  121. package/cmj/filters/Grayscale.d.ts +0 -2
  122. package/cmj/filters/Grayscale.js +0 -13
  123. package/cmj/filters/HSL.d.ts +0 -2
  124. package/cmj/filters/HSL.js +0 -28
  125. package/cmj/filters/HSV.d.ts +0 -2
  126. package/cmj/filters/HSV.js +0 -28
  127. package/cmj/filters/Invert.d.ts +0 -2
  128. package/cmj/filters/Invert.js +0 -12
  129. package/cmj/filters/Kaleidoscope.d.ts +0 -2
  130. package/cmj/filters/Kaleidoscope.js +0 -137
  131. package/cmj/filters/Mask.d.ts +0 -2
  132. package/cmj/filters/Mask.js +0 -144
  133. package/cmj/filters/Noise.d.ts +0 -2
  134. package/cmj/filters/Noise.js +0 -16
  135. package/cmj/filters/Pixelate.d.ts +0 -2
  136. package/cmj/filters/Pixelate.js +0 -64
  137. package/cmj/filters/Posterize.d.ts +0 -2
  138. package/cmj/filters/Posterize.js +0 -14
  139. package/cmj/filters/RGB.d.ts +0 -2
  140. package/cmj/filters/RGB.js +0 -43
  141. package/cmj/filters/RGBA.d.ts +0 -2
  142. package/cmj/filters/RGBA.js +0 -53
  143. package/cmj/filters/Sepia.d.ts +0 -2
  144. package/cmj/filters/Sepia.js +0 -15
  145. package/cmj/filters/Solarize.d.ts +0 -2
  146. package/cmj/filters/Solarize.js +0 -29
  147. package/cmj/filters/Threshold.d.ts +0 -2
  148. package/cmj/filters/Threshold.js +0 -14
  149. package/cmj/index-node.d.ts +0 -2
  150. package/cmj/index-node.js +0 -21
  151. package/cmj/index-types.d.ts +0 -181
  152. package/cmj/index.d.ts +0 -2
  153. package/cmj/index.js +0 -4
  154. package/cmj/package.json +0 -6
  155. package/cmj/shapes/Arc.d.ts +0 -26
  156. package/cmj/shapes/Arc.js +0 -59
  157. package/cmj/shapes/Arrow.d.ts +0 -26
  158. package/cmj/shapes/Arrow.js +0 -103
  159. package/cmj/shapes/Circle.d.ts +0 -14
  160. package/cmj/shapes/Circle.js +0 -37
  161. package/cmj/shapes/Ellipse.d.ts +0 -17
  162. package/cmj/shapes/Ellipse.js +0 -41
  163. package/cmj/shapes/Image.d.ts +0 -25
  164. package/cmj/shapes/Image.js +0 -117
  165. package/cmj/shapes/Label.d.ts +0 -36
  166. package/cmj/shapes/Label.js +0 -178
  167. package/cmj/shapes/Line.d.ts +0 -28
  168. package/cmj/shapes/Line.js +0 -159
  169. package/cmj/shapes/Path.d.ts +0 -37
  170. package/cmj/shapes/Path.js +0 -631
  171. package/cmj/shapes/Rect.d.ts +0 -10
  172. package/cmj/shapes/Rect.js +0 -26
  173. package/cmj/shapes/RegularPolygon.d.ts +0 -23
  174. package/cmj/shapes/RegularPolygon.js +0 -69
  175. package/cmj/shapes/Ring.d.ts +0 -16
  176. package/cmj/shapes/Ring.js +0 -37
  177. package/cmj/shapes/Sprite.d.ts +0 -31
  178. package/cmj/shapes/Sprite.js +0 -112
  179. package/cmj/shapes/Star.d.ts +0 -18
  180. package/cmj/shapes/Star.js +0 -42
  181. package/cmj/shapes/Text.d.ts +0 -63
  182. package/cmj/shapes/Text.js +0 -373
  183. package/cmj/shapes/TextPath.d.ts +0 -56
  184. package/cmj/shapes/TextPath.js +0 -351
  185. package/cmj/shapes/Transformer.d.ts +0 -116
  186. package/cmj/shapes/Transformer.js +0 -971
  187. package/cmj/shapes/Wedge.d.ts +0 -18
  188. package/cmj/shapes/Wedge.js +0 -42
  189. package/cmj/types.d.ts +0 -50
  190. package/cmj/types.js +0 -25
package/cmj/Shape.js DELETED
@@ -1,521 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Shape = exports.shapes = void 0;
4
- const Global_1 = require("./Global");
5
- const Util_1 = require("./Util");
6
- const Factory_1 = require("./Factory");
7
- const Node_1 = require("./Node");
8
- const Validators_1 = require("./Validators");
9
- const Global_2 = require("./Global");
10
- const PointerEvents = require("./PointerEvents");
11
- var HAS_SHADOW = 'hasShadow';
12
- var SHADOW_RGBA = 'shadowRGBA';
13
- var patternImage = 'patternImage';
14
- var linearGradient = 'linearGradient';
15
- var radialGradient = 'radialGradient';
16
- let dummyContext;
17
- function getDummyContext() {
18
- if (dummyContext) {
19
- return dummyContext;
20
- }
21
- dummyContext = Util_1.Util.createCanvasElement().getContext('2d');
22
- return dummyContext;
23
- }
24
- exports.shapes = {};
25
- function _fillFunc(context) {
26
- context.fill();
27
- }
28
- function _strokeFunc(context) {
29
- context.stroke();
30
- }
31
- function _fillFuncHit(context) {
32
- context.fill();
33
- }
34
- function _strokeFuncHit(context) {
35
- context.stroke();
36
- }
37
- function _clearHasShadowCache() {
38
- this._clearCache(HAS_SHADOW);
39
- }
40
- function _clearGetShadowRGBACache() {
41
- this._clearCache(SHADOW_RGBA);
42
- }
43
- function _clearFillPatternCache() {
44
- this._clearCache(patternImage);
45
- }
46
- function _clearLinearGradientCache() {
47
- this._clearCache(linearGradient);
48
- }
49
- function _clearRadialGradientCache() {
50
- this._clearCache(radialGradient);
51
- }
52
- class Shape extends Node_1.Node {
53
- constructor(config) {
54
- super(config);
55
- let key;
56
- while (true) {
57
- key = Util_1.Util.getRandomColor();
58
- if (key && !(key in exports.shapes)) {
59
- break;
60
- }
61
- }
62
- this.colorKey = key;
63
- exports.shapes[key] = this;
64
- }
65
- getContext() {
66
- Util_1.Util.warn('shape.getContext() method is deprecated. Please do not use it.');
67
- return this.getLayer().getContext();
68
- }
69
- getCanvas() {
70
- Util_1.Util.warn('shape.getCanvas() method is deprecated. Please do not use it.');
71
- return this.getLayer().getCanvas();
72
- }
73
- getSceneFunc() {
74
- return this.attrs.sceneFunc || this['_sceneFunc'];
75
- }
76
- getHitFunc() {
77
- return this.attrs.hitFunc || this['_hitFunc'];
78
- }
79
- hasShadow() {
80
- return this._getCache(HAS_SHADOW, this._hasShadow);
81
- }
82
- _hasShadow() {
83
- return (this.shadowEnabled() &&
84
- this.shadowOpacity() !== 0 &&
85
- !!(this.shadowColor() ||
86
- this.shadowBlur() ||
87
- this.shadowOffsetX() ||
88
- this.shadowOffsetY()));
89
- }
90
- _getFillPattern() {
91
- return this._getCache(patternImage, this.__getFillPattern);
92
- }
93
- __getFillPattern() {
94
- if (this.fillPatternImage()) {
95
- var ctx = getDummyContext();
96
- const pattern = ctx.createPattern(this.fillPatternImage(), this.fillPatternRepeat() || 'repeat');
97
- if (pattern && pattern.setTransform) {
98
- const tr = new Util_1.Transform();
99
- tr.translate(this.fillPatternX(), this.fillPatternY());
100
- tr.rotate(Global_1.Konva.getAngle(this.fillPatternRotation()));
101
- tr.scale(this.fillPatternScaleX(), this.fillPatternScaleY());
102
- tr.translate(-1 * this.fillPatternOffsetX(), -1 * this.fillPatternOffsetY());
103
- const m = tr.getMatrix();
104
- const matrix = typeof DOMMatrix === 'undefined'
105
- ? {
106
- a: m[0],
107
- b: m[1],
108
- c: m[2],
109
- d: m[3],
110
- e: m[4],
111
- f: m[5],
112
- }
113
- : new DOMMatrix(m);
114
- pattern.setTransform(matrix);
115
- }
116
- return pattern;
117
- }
118
- }
119
- _getLinearGradient() {
120
- return this._getCache(linearGradient, this.__getLinearGradient);
121
- }
122
- __getLinearGradient() {
123
- var colorStops = this.fillLinearGradientColorStops();
124
- if (colorStops) {
125
- var ctx = getDummyContext();
126
- var start = this.fillLinearGradientStartPoint();
127
- var end = this.fillLinearGradientEndPoint();
128
- var grd = ctx.createLinearGradient(start.x, start.y, end.x, end.y);
129
- for (var n = 0; n < colorStops.length; n += 2) {
130
- grd.addColorStop(colorStops[n], colorStops[n + 1]);
131
- }
132
- return grd;
133
- }
134
- }
135
- _getRadialGradient() {
136
- return this._getCache(radialGradient, this.__getRadialGradient);
137
- }
138
- __getRadialGradient() {
139
- var colorStops = this.fillRadialGradientColorStops();
140
- if (colorStops) {
141
- var ctx = getDummyContext();
142
- var start = this.fillRadialGradientStartPoint();
143
- var end = this.fillRadialGradientEndPoint();
144
- var grd = ctx.createRadialGradient(start.x, start.y, this.fillRadialGradientStartRadius(), end.x, end.y, this.fillRadialGradientEndRadius());
145
- for (var n = 0; n < colorStops.length; n += 2) {
146
- grd.addColorStop(colorStops[n], colorStops[n + 1]);
147
- }
148
- return grd;
149
- }
150
- }
151
- getShadowRGBA() {
152
- return this._getCache(SHADOW_RGBA, this._getShadowRGBA);
153
- }
154
- _getShadowRGBA() {
155
- if (!this.hasShadow()) {
156
- return;
157
- }
158
- var rgba = Util_1.Util.colorToRGBA(this.shadowColor());
159
- if (rgba) {
160
- return ('rgba(' +
161
- rgba.r +
162
- ',' +
163
- rgba.g +
164
- ',' +
165
- rgba.b +
166
- ',' +
167
- rgba.a * (this.shadowOpacity() || 1) +
168
- ')');
169
- }
170
- }
171
- hasFill() {
172
- return this._calculate('hasFill', [
173
- 'fillEnabled',
174
- 'fill',
175
- 'fillPatternImage',
176
- 'fillLinearGradientColorStops',
177
- 'fillRadialGradientColorStops',
178
- ], () => {
179
- return (this.fillEnabled() &&
180
- !!(this.fill() ||
181
- this.fillPatternImage() ||
182
- this.fillLinearGradientColorStops() ||
183
- this.fillRadialGradientColorStops()));
184
- });
185
- }
186
- hasStroke() {
187
- return this._calculate('hasStroke', [
188
- 'strokeEnabled',
189
- 'strokeWidth',
190
- 'stroke',
191
- 'strokeLinearGradientColorStops',
192
- ], () => {
193
- return (this.strokeEnabled() &&
194
- this.strokeWidth() &&
195
- !!(this.stroke() || this.strokeLinearGradientColorStops()));
196
- });
197
- }
198
- hasHitStroke() {
199
- const width = this.hitStrokeWidth();
200
- if (width === 'auto') {
201
- return this.hasStroke();
202
- }
203
- return this.strokeEnabled() && !!width;
204
- }
205
- intersects(point) {
206
- var stage = this.getStage(), bufferHitCanvas = stage.bufferHitCanvas, p;
207
- bufferHitCanvas.getContext().clear();
208
- this.drawHit(bufferHitCanvas, null, true);
209
- p = bufferHitCanvas.context.getImageData(Math.round(point.x), Math.round(point.y), 1, 1).data;
210
- return p[3] > 0;
211
- }
212
- destroy() {
213
- Node_1.Node.prototype.destroy.call(this);
214
- delete exports.shapes[this.colorKey];
215
- delete this.colorKey;
216
- return this;
217
- }
218
- _useBufferCanvas(forceFill) {
219
- var _a;
220
- if (!this.getStage()) {
221
- return false;
222
- }
223
- const perfectDrawEnabled = (_a = this.attrs.perfectDrawEnabled) !== null && _a !== void 0 ? _a : true;
224
- if (!perfectDrawEnabled) {
225
- return false;
226
- }
227
- const hasFill = forceFill || this.hasFill();
228
- const hasStroke = this.hasStroke();
229
- const isTransparent = this.getAbsoluteOpacity() !== 1;
230
- if (hasFill && hasStroke && isTransparent) {
231
- return true;
232
- }
233
- const hasShadow = this.hasShadow();
234
- const strokeForShadow = this.shadowForStrokeEnabled();
235
- if (hasFill && hasStroke && hasShadow && strokeForShadow) {
236
- return true;
237
- }
238
- return false;
239
- }
240
- setStrokeHitEnabled(val) {
241
- Util_1.Util.warn('strokeHitEnabled property is deprecated. Please use hitStrokeWidth instead.');
242
- if (val) {
243
- this.hitStrokeWidth('auto');
244
- }
245
- else {
246
- this.hitStrokeWidth(0);
247
- }
248
- }
249
- getStrokeHitEnabled() {
250
- if (this.hitStrokeWidth() === 0) {
251
- return false;
252
- }
253
- else {
254
- return true;
255
- }
256
- }
257
- getSelfRect() {
258
- var size = this.size();
259
- return {
260
- x: this._centroid ? -size.width / 2 : 0,
261
- y: this._centroid ? -size.height / 2 : 0,
262
- width: size.width,
263
- height: size.height,
264
- };
265
- }
266
- getClientRect(config = {}) {
267
- const skipTransform = config.skipTransform;
268
- const relativeTo = config.relativeTo;
269
- const fillRect = this.getSelfRect();
270
- const applyStroke = !config.skipStroke && this.hasStroke();
271
- const strokeWidth = (applyStroke && this.strokeWidth()) || 0;
272
- const fillAndStrokeWidth = fillRect.width + strokeWidth;
273
- const fillAndStrokeHeight = fillRect.height + strokeWidth;
274
- const applyShadow = !config.skipShadow && this.hasShadow();
275
- const shadowOffsetX = applyShadow ? this.shadowOffsetX() : 0;
276
- const shadowOffsetY = applyShadow ? this.shadowOffsetY() : 0;
277
- const preWidth = fillAndStrokeWidth + Math.abs(shadowOffsetX);
278
- const preHeight = fillAndStrokeHeight + Math.abs(shadowOffsetY);
279
- const blurRadius = (applyShadow && this.shadowBlur()) || 0;
280
- const width = preWidth + blurRadius * 2;
281
- const height = preHeight + blurRadius * 2;
282
- const rect = {
283
- width: width,
284
- height: height,
285
- x: -(strokeWidth / 2 + blurRadius) +
286
- Math.min(shadowOffsetX, 0) +
287
- fillRect.x,
288
- y: -(strokeWidth / 2 + blurRadius) +
289
- Math.min(shadowOffsetY, 0) +
290
- fillRect.y,
291
- };
292
- if (!skipTransform) {
293
- return this._transformedRect(rect, relativeTo);
294
- }
295
- return rect;
296
- }
297
- drawScene(can, top) {
298
- var layer = this.getLayer(), canvas = can || layer.getCanvas(), context = canvas.getContext(), cachedCanvas = this._getCanvasCache(), drawFunc = this.getSceneFunc(), hasShadow = this.hasShadow(), stage, bufferCanvas, bufferContext;
299
- var skipBuffer = canvas.isCache;
300
- var cachingSelf = top === this;
301
- if (!this.isVisible() && !cachingSelf) {
302
- return this;
303
- }
304
- if (cachedCanvas) {
305
- context.save();
306
- var m = this.getAbsoluteTransform(top).getMatrix();
307
- context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
308
- this._drawCachedSceneCanvas(context);
309
- context.restore();
310
- return this;
311
- }
312
- if (!drawFunc) {
313
- return this;
314
- }
315
- context.save();
316
- if (this._useBufferCanvas() && !skipBuffer) {
317
- stage = this.getStage();
318
- bufferCanvas = stage.bufferCanvas;
319
- bufferContext = bufferCanvas.getContext();
320
- bufferContext.clear();
321
- bufferContext.save();
322
- bufferContext._applyLineJoin(this);
323
- var o = this.getAbsoluteTransform(top).getMatrix();
324
- bufferContext.transform(o[0], o[1], o[2], o[3], o[4], o[5]);
325
- drawFunc.call(this, bufferContext, this);
326
- bufferContext.restore();
327
- var ratio = bufferCanvas.pixelRatio;
328
- if (hasShadow) {
329
- context._applyShadow(this);
330
- }
331
- context._applyOpacity(this);
332
- context._applyGlobalCompositeOperation(this);
333
- context.drawImage(bufferCanvas._canvas, 0, 0, bufferCanvas.width / ratio, bufferCanvas.height / ratio);
334
- }
335
- else {
336
- context._applyLineJoin(this);
337
- if (!cachingSelf) {
338
- var o = this.getAbsoluteTransform(top).getMatrix();
339
- context.transform(o[0], o[1], o[2], o[3], o[4], o[5]);
340
- context._applyOpacity(this);
341
- context._applyGlobalCompositeOperation(this);
342
- }
343
- if (hasShadow) {
344
- context._applyShadow(this);
345
- }
346
- drawFunc.call(this, context, this);
347
- }
348
- context.restore();
349
- return this;
350
- }
351
- drawHit(can, top, skipDragCheck = false) {
352
- if (!this.shouldDrawHit(top, skipDragCheck)) {
353
- return this;
354
- }
355
- var layer = this.getLayer(), canvas = can || layer.hitCanvas, context = canvas && canvas.getContext(), drawFunc = this.hitFunc() || this.sceneFunc(), cachedCanvas = this._getCanvasCache(), cachedHitCanvas = cachedCanvas && cachedCanvas.hit;
356
- if (!this.colorKey) {
357
- Util_1.Util.warn('Looks like your canvas has a destroyed shape in it. Do not reuse shape after you destroyed it. If you want to reuse shape you should call remove() instead of destroy()');
358
- }
359
- if (cachedHitCanvas) {
360
- context.save();
361
- var m = this.getAbsoluteTransform(top).getMatrix();
362
- context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
363
- this._drawCachedHitCanvas(context);
364
- context.restore();
365
- return this;
366
- }
367
- if (!drawFunc) {
368
- return this;
369
- }
370
- context.save();
371
- context._applyLineJoin(this);
372
- const selfCache = this === top;
373
- if (!selfCache) {
374
- var o = this.getAbsoluteTransform(top).getMatrix();
375
- context.transform(o[0], o[1], o[2], o[3], o[4], o[5]);
376
- }
377
- drawFunc.call(this, context, this);
378
- context.restore();
379
- return this;
380
- }
381
- drawHitFromCache(alphaThreshold = 0) {
382
- var cachedCanvas = this._getCanvasCache(), sceneCanvas = this._getCachedSceneCanvas(), hitCanvas = cachedCanvas.hit, hitContext = hitCanvas.getContext(), hitWidth = hitCanvas.getWidth(), hitHeight = hitCanvas.getHeight(), hitImageData, hitData, len, rgbColorKey, i, alpha;
383
- hitContext.clear();
384
- hitContext.drawImage(sceneCanvas._canvas, 0, 0, hitWidth, hitHeight);
385
- try {
386
- hitImageData = hitContext.getImageData(0, 0, hitWidth, hitHeight);
387
- hitData = hitImageData.data;
388
- len = hitData.length;
389
- rgbColorKey = Util_1.Util._hexToRgb(this.colorKey);
390
- for (i = 0; i < len; i += 4) {
391
- alpha = hitData[i + 3];
392
- if (alpha > alphaThreshold) {
393
- hitData[i] = rgbColorKey.r;
394
- hitData[i + 1] = rgbColorKey.g;
395
- hitData[i + 2] = rgbColorKey.b;
396
- hitData[i + 3] = 255;
397
- }
398
- else {
399
- hitData[i + 3] = 0;
400
- }
401
- }
402
- hitContext.putImageData(hitImageData, 0, 0);
403
- }
404
- catch (e) {
405
- Util_1.Util.error('Unable to draw hit graph from cached scene canvas. ' + e.message);
406
- }
407
- return this;
408
- }
409
- hasPointerCapture(pointerId) {
410
- return PointerEvents.hasPointerCapture(pointerId, this);
411
- }
412
- setPointerCapture(pointerId) {
413
- PointerEvents.setPointerCapture(pointerId, this);
414
- }
415
- releaseCapture(pointerId) {
416
- PointerEvents.releaseCapture(pointerId, this);
417
- }
418
- }
419
- exports.Shape = Shape;
420
- Shape.prototype._fillFunc = _fillFunc;
421
- Shape.prototype._strokeFunc = _strokeFunc;
422
- Shape.prototype._fillFuncHit = _fillFuncHit;
423
- Shape.prototype._strokeFuncHit = _strokeFuncHit;
424
- Shape.prototype._centroid = false;
425
- Shape.prototype.nodeType = 'Shape';
426
- (0, Global_2._registerNode)(Shape);
427
- Shape.prototype.eventListeners = {};
428
- Shape.prototype.on.call(Shape.prototype, 'shadowColorChange.konva shadowBlurChange.konva shadowOffsetChange.konva shadowOpacityChange.konva shadowEnabledChange.konva', _clearHasShadowCache);
429
- Shape.prototype.on.call(Shape.prototype, 'shadowColorChange.konva shadowOpacityChange.konva shadowEnabledChange.konva', _clearGetShadowRGBACache);
430
- Shape.prototype.on.call(Shape.prototype, 'fillPriorityChange.konva fillPatternImageChange.konva fillPatternRepeatChange.konva fillPatternScaleXChange.konva fillPatternScaleYChange.konva fillPatternOffsetXChange.konva fillPatternOffsetYChange.konva fillPatternXChange.konva fillPatternYChange.konva fillPatternRotationChange.konva', _clearFillPatternCache);
431
- Shape.prototype.on.call(Shape.prototype, 'fillPriorityChange.konva fillLinearGradientColorStopsChange.konva fillLinearGradientStartPointXChange.konva fillLinearGradientStartPointYChange.konva fillLinearGradientEndPointXChange.konva fillLinearGradientEndPointYChange.konva', _clearLinearGradientCache);
432
- Shape.prototype.on.call(Shape.prototype, 'fillPriorityChange.konva fillRadialGradientColorStopsChange.konva fillRadialGradientStartPointXChange.konva fillRadialGradientStartPointYChange.konva fillRadialGradientEndPointXChange.konva fillRadialGradientEndPointYChange.konva fillRadialGradientStartRadiusChange.konva fillRadialGradientEndRadiusChange.konva', _clearRadialGradientCache);
433
- Factory_1.Factory.addGetterSetter(Shape, 'stroke', undefined, (0, Validators_1.getStringOrGradientValidator)());
434
- Factory_1.Factory.addGetterSetter(Shape, 'strokeWidth', 2, (0, Validators_1.getNumberValidator)());
435
- Factory_1.Factory.addGetterSetter(Shape, 'fillAfterStrokeEnabled', false);
436
- Factory_1.Factory.addGetterSetter(Shape, 'hitStrokeWidth', 'auto', (0, Validators_1.getNumberOrAutoValidator)());
437
- Factory_1.Factory.addGetterSetter(Shape, 'strokeHitEnabled', true, (0, Validators_1.getBooleanValidator)());
438
- Factory_1.Factory.addGetterSetter(Shape, 'perfectDrawEnabled', true, (0, Validators_1.getBooleanValidator)());
439
- Factory_1.Factory.addGetterSetter(Shape, 'shadowForStrokeEnabled', true, (0, Validators_1.getBooleanValidator)());
440
- Factory_1.Factory.addGetterSetter(Shape, 'lineJoin');
441
- Factory_1.Factory.addGetterSetter(Shape, 'lineCap');
442
- Factory_1.Factory.addGetterSetter(Shape, 'sceneFunc');
443
- Factory_1.Factory.addGetterSetter(Shape, 'hitFunc');
444
- Factory_1.Factory.addGetterSetter(Shape, 'dash');
445
- Factory_1.Factory.addGetterSetter(Shape, 'dashOffset', 0, (0, Validators_1.getNumberValidator)());
446
- Factory_1.Factory.addGetterSetter(Shape, 'shadowColor', undefined, (0, Validators_1.getStringValidator)());
447
- Factory_1.Factory.addGetterSetter(Shape, 'shadowBlur', 0, (0, Validators_1.getNumberValidator)());
448
- Factory_1.Factory.addGetterSetter(Shape, 'shadowOpacity', 1, (0, Validators_1.getNumberValidator)());
449
- Factory_1.Factory.addComponentsGetterSetter(Shape, 'shadowOffset', ['x', 'y']);
450
- Factory_1.Factory.addGetterSetter(Shape, 'shadowOffsetX', 0, (0, Validators_1.getNumberValidator)());
451
- Factory_1.Factory.addGetterSetter(Shape, 'shadowOffsetY', 0, (0, Validators_1.getNumberValidator)());
452
- Factory_1.Factory.addGetterSetter(Shape, 'fillPatternImage');
453
- Factory_1.Factory.addGetterSetter(Shape, 'fill', undefined, (0, Validators_1.getStringOrGradientValidator)());
454
- Factory_1.Factory.addGetterSetter(Shape, 'fillPatternX', 0, (0, Validators_1.getNumberValidator)());
455
- Factory_1.Factory.addGetterSetter(Shape, 'fillPatternY', 0, (0, Validators_1.getNumberValidator)());
456
- Factory_1.Factory.addGetterSetter(Shape, 'fillLinearGradientColorStops');
457
- Factory_1.Factory.addGetterSetter(Shape, 'strokeLinearGradientColorStops');
458
- Factory_1.Factory.addGetterSetter(Shape, 'fillRadialGradientStartRadius', 0);
459
- Factory_1.Factory.addGetterSetter(Shape, 'fillRadialGradientEndRadius', 0);
460
- Factory_1.Factory.addGetterSetter(Shape, 'fillRadialGradientColorStops');
461
- Factory_1.Factory.addGetterSetter(Shape, 'fillPatternRepeat', 'repeat');
462
- Factory_1.Factory.addGetterSetter(Shape, 'fillEnabled', true);
463
- Factory_1.Factory.addGetterSetter(Shape, 'strokeEnabled', true);
464
- Factory_1.Factory.addGetterSetter(Shape, 'shadowEnabled', true);
465
- Factory_1.Factory.addGetterSetter(Shape, 'dashEnabled', true);
466
- Factory_1.Factory.addGetterSetter(Shape, 'strokeScaleEnabled', true);
467
- Factory_1.Factory.addGetterSetter(Shape, 'fillPriority', 'color');
468
- Factory_1.Factory.addComponentsGetterSetter(Shape, 'fillPatternOffset', ['x', 'y']);
469
- Factory_1.Factory.addGetterSetter(Shape, 'fillPatternOffsetX', 0, (0, Validators_1.getNumberValidator)());
470
- Factory_1.Factory.addGetterSetter(Shape, 'fillPatternOffsetY', 0, (0, Validators_1.getNumberValidator)());
471
- Factory_1.Factory.addComponentsGetterSetter(Shape, 'fillPatternScale', ['x', 'y']);
472
- Factory_1.Factory.addGetterSetter(Shape, 'fillPatternScaleX', 1, (0, Validators_1.getNumberValidator)());
473
- Factory_1.Factory.addGetterSetter(Shape, 'fillPatternScaleY', 1, (0, Validators_1.getNumberValidator)());
474
- Factory_1.Factory.addComponentsGetterSetter(Shape, 'fillLinearGradientStartPoint', [
475
- 'x',
476
- 'y',
477
- ]);
478
- Factory_1.Factory.addComponentsGetterSetter(Shape, 'strokeLinearGradientStartPoint', [
479
- 'x',
480
- 'y',
481
- ]);
482
- Factory_1.Factory.addGetterSetter(Shape, 'fillLinearGradientStartPointX', 0);
483
- Factory_1.Factory.addGetterSetter(Shape, 'strokeLinearGradientStartPointX', 0);
484
- Factory_1.Factory.addGetterSetter(Shape, 'fillLinearGradientStartPointY', 0);
485
- Factory_1.Factory.addGetterSetter(Shape, 'strokeLinearGradientStartPointY', 0);
486
- Factory_1.Factory.addComponentsGetterSetter(Shape, 'fillLinearGradientEndPoint', [
487
- 'x',
488
- 'y',
489
- ]);
490
- Factory_1.Factory.addComponentsGetterSetter(Shape, 'strokeLinearGradientEndPoint', [
491
- 'x',
492
- 'y',
493
- ]);
494
- Factory_1.Factory.addGetterSetter(Shape, 'fillLinearGradientEndPointX', 0);
495
- Factory_1.Factory.addGetterSetter(Shape, 'strokeLinearGradientEndPointX', 0);
496
- Factory_1.Factory.addGetterSetter(Shape, 'fillLinearGradientEndPointY', 0);
497
- Factory_1.Factory.addGetterSetter(Shape, 'strokeLinearGradientEndPointY', 0);
498
- Factory_1.Factory.addComponentsGetterSetter(Shape, 'fillRadialGradientStartPoint', [
499
- 'x',
500
- 'y',
501
- ]);
502
- Factory_1.Factory.addGetterSetter(Shape, 'fillRadialGradientStartPointX', 0);
503
- Factory_1.Factory.addGetterSetter(Shape, 'fillRadialGradientStartPointY', 0);
504
- Factory_1.Factory.addComponentsGetterSetter(Shape, 'fillRadialGradientEndPoint', [
505
- 'x',
506
- 'y',
507
- ]);
508
- Factory_1.Factory.addGetterSetter(Shape, 'fillRadialGradientEndPointX', 0);
509
- Factory_1.Factory.addGetterSetter(Shape, 'fillRadialGradientEndPointY', 0);
510
- Factory_1.Factory.addGetterSetter(Shape, 'fillPatternRotation', 0);
511
- Factory_1.Factory.backCompat(Shape, {
512
- dashArray: 'dash',
513
- getDashArray: 'getDash',
514
- setDashArray: 'getDash',
515
- drawFunc: 'sceneFunc',
516
- getDrawFunc: 'getSceneFunc',
517
- setDrawFunc: 'setSceneFunc',
518
- drawHitFunc: 'hitFunc',
519
- getDrawHitFunc: 'getHitFunc',
520
- setDrawHitFunc: 'setHitFunc',
521
- });
package/cmj/Stage.d.ts DELETED
@@ -1,85 +0,0 @@
1
- import { Container, ContainerConfig } from './Container';
2
- import { SceneCanvas, HitCanvas } from './Canvas';
3
- import { GetSet, Vector2d } from './types';
4
- import { Shape } from './Shape';
5
- import { Layer } from './Layer';
6
- export interface StageConfig extends ContainerConfig {
7
- container: HTMLDivElement | string;
8
- }
9
- export declare const stages: Stage[];
10
- export declare class Stage extends Container<Layer> {
11
- content: HTMLDivElement;
12
- pointerPos: Vector2d | null;
13
- _pointerPositions: (Vector2d & {
14
- id?: number;
15
- })[];
16
- _changedPointerPositions: (Vector2d & {
17
- id: number;
18
- })[];
19
- bufferCanvas: SceneCanvas;
20
- bufferHitCanvas: HitCanvas;
21
- _mouseTargetShape: Shape;
22
- _touchTargetShape: Shape;
23
- _pointerTargetShape: Shape;
24
- _mouseClickStartShape: Shape;
25
- _touchClickStartShape: Shape;
26
- _pointerClickStartShape: Shape;
27
- _mouseClickEndShape: Shape;
28
- _touchClickEndShape: Shape;
29
- _pointerClickEndShape: Shape;
30
- _mouseDblTimeout: any;
31
- _touchDblTimeout: any;
32
- _pointerDblTimeout: any;
33
- constructor(config: StageConfig);
34
- _validateAdd(child: any): void;
35
- _checkVisibility(): void;
36
- setContainer(container: any): this;
37
- shouldDrawHit(): boolean;
38
- clear(): this;
39
- clone(obj?: any): any;
40
- destroy(): this;
41
- getPointerPosition(): Vector2d | null;
42
- _getPointerById(id?: number): Vector2d & {
43
- id?: number;
44
- };
45
- getPointersPositions(): (Vector2d & {
46
- id?: number;
47
- })[];
48
- getStage(): this;
49
- getContent(): HTMLDivElement;
50
- _toKonvaCanvas(config: any): SceneCanvas;
51
- getIntersection(pos: Vector2d): Shape<import("./Shape").ShapeConfig>;
52
- _resizeDOM(): void;
53
- add(layer: Layer, ...rest: any[]): this;
54
- getParent(): any;
55
- getLayer(): any;
56
- hasPointerCapture(pointerId: number): boolean;
57
- setPointerCapture(pointerId: number): void;
58
- releaseCapture(pointerId: number): void;
59
- getLayers(): Layer[];
60
- _bindContentEvents(): void;
61
- _pointerenter(evt: any): void;
62
- _pointerover(evt: any): void;
63
- _getTargetShape(evenType: any): Shape<import("./Shape").ShapeConfig>;
64
- _pointerleave(evt: any): void;
65
- _pointerdown(evt: TouchEvent | MouseEvent | PointerEvent): void;
66
- _pointermove(evt: TouchEvent | MouseEvent | PointerEvent): void;
67
- _pointerup(evt: any): void;
68
- _contextmenu(evt: any): void;
69
- _wheel(evt: any): void;
70
- _pointercancel(evt: PointerEvent): void;
71
- _lostpointercapture(evt: PointerEvent): void;
72
- setPointersPositions(evt: any): void;
73
- _setPointerPosition(evt: any): void;
74
- _getContentPosition(): {
75
- top: number;
76
- left: number;
77
- scaleX: number;
78
- scaleY: number;
79
- };
80
- _buildDOM(): void;
81
- cache(): this;
82
- clearCache(): this;
83
- batchDraw(): this;
84
- container: GetSet<HTMLDivElement, this>;
85
- }