konva 8.4.2 → 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 (242) hide show
  1. package/README.md +1 -9
  2. package/konva.js +17669 -16968
  3. package/konva.min.js +3 -3
  4. package/lib/Animation.d.ts +2 -2
  5. package/lib/Animation.js +11 -7
  6. package/lib/BezierFunctions.d.ts +6 -0
  7. package/lib/BezierFunctions.js +791 -0
  8. package/lib/Canvas.d.ts +2 -1
  9. package/lib/Canvas.js +26 -18
  10. package/lib/Container.d.ts +4 -4
  11. package/lib/Container.js +16 -12
  12. package/lib/Context.d.ts +16 -13
  13. package/lib/Context.js +27 -19
  14. package/lib/Core.d.ts +2 -2
  15. package/lib/Core.js +7 -3
  16. package/lib/DragAndDrop.d.ts +3 -3
  17. package/lib/DragAndDrop.js +25 -22
  18. package/lib/Factory.js +27 -24
  19. package/lib/FastLayer.d.ts +1 -1
  20. package/lib/FastLayer.js +10 -6
  21. package/lib/Global.js +16 -12
  22. package/lib/Group.d.ts +3 -3
  23. package/lib/Group.js +10 -6
  24. package/lib/Layer.d.ts +9 -9
  25. package/lib/Layer.js +37 -33
  26. package/lib/Node.d.ts +8 -8
  27. package/lib/Node.js +95 -90
  28. package/lib/PointerEvents.d.ts +4 -4
  29. package/lib/PointerEvents.js +15 -7
  30. package/lib/Shape.d.ts +6 -4
  31. package/lib/Shape.js +90 -86
  32. package/lib/Stage.d.ts +7 -7
  33. package/lib/Stage.js +51 -47
  34. package/lib/Tween.d.ts +2 -2
  35. package/lib/Tween.js +26 -22
  36. package/lib/Util.d.ts +2 -2
  37. package/lib/Util.js +29 -25
  38. package/lib/Validators.js +58 -44
  39. package/lib/_CoreInternals.d.ts +29 -29
  40. package/lib/_CoreInternals.js +36 -33
  41. package/lib/_FullInternals.d.ts +67 -67
  42. package/lib/_FullInternals.js +78 -75
  43. package/lib/filters/Blur.d.ts +1 -1
  44. package/lib/filters/Blur.js +9 -5
  45. package/lib/filters/Brighten.d.ts +1 -1
  46. package/lib/filters/Brighten.js +9 -5
  47. package/lib/filters/Contrast.d.ts +1 -1
  48. package/lib/filters/Contrast.js +9 -5
  49. package/lib/filters/Emboss.d.ts +1 -1
  50. package/lib/filters/Emboss.js +14 -10
  51. package/lib/filters/Enhance.d.ts +1 -1
  52. package/lib/filters/Enhance.js +9 -5
  53. package/lib/filters/Grayscale.d.ts +1 -1
  54. package/lib/filters/Grayscale.js +5 -1
  55. package/lib/filters/HSL.d.ts +1 -1
  56. package/lib/filters/HSL.js +11 -7
  57. package/lib/filters/HSV.d.ts +1 -1
  58. package/lib/filters/HSV.js +11 -7
  59. package/lib/filters/Invert.d.ts +1 -1
  60. package/lib/filters/Invert.js +5 -1
  61. package/lib/filters/Kaleidoscope.d.ts +1 -1
  62. package/lib/filters/Kaleidoscope.js +13 -9
  63. package/lib/filters/Mask.d.ts +1 -1
  64. package/lib/filters/Mask.js +9 -5
  65. package/lib/filters/Noise.d.ts +1 -1
  66. package/lib/filters/Noise.js +9 -5
  67. package/lib/filters/Pixelate.d.ts +1 -1
  68. package/lib/filters/Pixelate.js +11 -7
  69. package/lib/filters/Posterize.d.ts +1 -1
  70. package/lib/filters/Posterize.js +9 -5
  71. package/lib/filters/RGB.d.ts +1 -1
  72. package/lib/filters/RGB.js +11 -7
  73. package/lib/filters/RGBA.d.ts +1 -1
  74. package/lib/filters/RGBA.js +12 -8
  75. package/lib/filters/Sepia.d.ts +1 -1
  76. package/lib/filters/Sepia.js +5 -1
  77. package/lib/filters/Solarize.d.ts +1 -1
  78. package/lib/filters/Solarize.js +5 -1
  79. package/lib/filters/Threshold.d.ts +1 -1
  80. package/lib/filters/Threshold.js +9 -5
  81. package/lib/index-node.d.ts +1 -1
  82. package/lib/index-node.js +7 -5
  83. package/lib/index-types.d.ts +124 -124
  84. package/lib/index.d.ts +1 -1
  85. package/lib/index.js +4 -2
  86. package/lib/shapes/Arc.d.ts +6 -5
  87. package/lib/shapes/Arc.js +17 -13
  88. package/lib/shapes/Arrow.d.ts +5 -4
  89. package/lib/shapes/Arrow.js +17 -13
  90. package/lib/shapes/Circle.d.ts +6 -5
  91. package/lib/shapes/Circle.js +11 -7
  92. package/lib/shapes/Ellipse.d.ts +6 -5
  93. package/lib/shapes/Ellipse.js +13 -9
  94. package/lib/shapes/Image.d.ts +5 -5
  95. package/lib/shapes/Image.js +21 -17
  96. package/lib/shapes/Label.d.ts +8 -7
  97. package/lib/shapes/Label.js +18 -13
  98. package/lib/shapes/Line.d.ts +3 -3
  99. package/lib/shapes/Line.js +14 -10
  100. package/lib/shapes/Path.d.ts +6 -3
  101. package/lib/shapes/Path.js +44 -43
  102. package/lib/shapes/Rect.d.ts +3 -3
  103. package/lib/shapes/Rect.js +13 -9
  104. package/lib/shapes/RegularPolygon.d.ts +6 -5
  105. package/lib/shapes/RegularPolygon.js +12 -8
  106. package/lib/shapes/Ring.d.ts +6 -5
  107. package/lib/shapes/Ring.js +12 -8
  108. package/lib/shapes/Sprite.d.ts +7 -6
  109. package/lib/shapes/Sprite.js +19 -15
  110. package/lib/shapes/Star.d.ts +6 -5
  111. package/lib/shapes/Star.js +13 -9
  112. package/lib/shapes/Text.d.ts +8 -7
  113. package/lib/shapes/Text.js +31 -26
  114. package/lib/shapes/TextPath.d.ts +12 -7
  115. package/lib/shapes/TextPath.js +82 -188
  116. package/lib/shapes/Transformer.d.ts +10 -10
  117. package/lib/shapes/Transformer.js +92 -81
  118. package/lib/shapes/Wedge.d.ts +6 -5
  119. package/lib/shapes/Wedge.js +16 -12
  120. package/lib/types.d.ts +6 -0
  121. package/lib/types.js +5 -2
  122. package/package.json +13 -42
  123. package/cmj/Animation.d.ts +0 -24
  124. package/cmj/Animation.js +0 -145
  125. package/cmj/Canvas.d.ts +0 -32
  126. package/cmj/Canvas.js +0 -114
  127. package/cmj/Container.d.ts +0 -47
  128. package/cmj/Container.js +0 -325
  129. package/cmj/Context.d.ts +0 -84
  130. package/cmj/Context.js +0 -538
  131. package/cmj/Core.d.ts +0 -3
  132. package/cmj/Core.js +0 -7
  133. package/cmj/DragAndDrop.d.ts +0 -17
  134. package/cmj/DragAndDrop.js +0 -111
  135. package/cmj/Factory.d.ts +0 -11
  136. package/cmj/Factory.js +0 -125
  137. package/cmj/FastLayer.d.ts +0 -4
  138. package/cmj/FastLayer.js +0 -16
  139. package/cmj/Global.d.ts +0 -34
  140. package/cmj/Global.js +0 -61
  141. package/cmj/Group.d.ts +0 -8
  142. package/cmj/Group.js +0 -17
  143. package/cmj/Layer.d.ts +0 -61
  144. package/cmj/Layer.js +0 -309
  145. package/cmj/Node.d.ts +0 -328
  146. package/cmj/Node.js +0 -1420
  147. package/cmj/PointerEvents.d.ts +0 -11
  148. package/cmj/PointerEvents.js +0 -45
  149. package/cmj/Shape.d.ts +0 -184
  150. package/cmj/Shape.js +0 -521
  151. package/cmj/Stage.d.ts +0 -85
  152. package/cmj/Stage.js +0 -692
  153. package/cmj/Tween.d.ts +0 -86
  154. package/cmj/Tween.js +0 -520
  155. package/cmj/Util.d.ts +0 -91
  156. package/cmj/Util.js +0 -801
  157. package/cmj/Validators.d.ts +0 -11
  158. package/cmj/Validators.js +0 -192
  159. package/cmj/_CoreInternals.d.ts +0 -152
  160. package/cmj/_CoreInternals.js +0 -37
  161. package/cmj/_FullInternals.d.ts +0 -196
  162. package/cmj/_FullInternals.js +0 -81
  163. package/cmj/filters/Blur.d.ts +0 -2
  164. package/cmj/filters/Blur.js +0 -701
  165. package/cmj/filters/Brighten.d.ts +0 -2
  166. package/cmj/filters/Brighten.js +0 -16
  167. package/cmj/filters/Contrast.d.ts +0 -2
  168. package/cmj/filters/Contrast.js +0 -38
  169. package/cmj/filters/Emboss.d.ts +0 -2
  170. package/cmj/filters/Emboss.js +0 -106
  171. package/cmj/filters/Enhance.d.ts +0 -2
  172. package/cmj/filters/Enhance.js +0 -87
  173. package/cmj/filters/Grayscale.d.ts +0 -2
  174. package/cmj/filters/Grayscale.js +0 -13
  175. package/cmj/filters/HSL.d.ts +0 -2
  176. package/cmj/filters/HSL.js +0 -28
  177. package/cmj/filters/HSV.d.ts +0 -2
  178. package/cmj/filters/HSV.js +0 -28
  179. package/cmj/filters/Invert.d.ts +0 -2
  180. package/cmj/filters/Invert.js +0 -12
  181. package/cmj/filters/Kaleidoscope.d.ts +0 -2
  182. package/cmj/filters/Kaleidoscope.js +0 -137
  183. package/cmj/filters/Mask.d.ts +0 -2
  184. package/cmj/filters/Mask.js +0 -144
  185. package/cmj/filters/Noise.d.ts +0 -2
  186. package/cmj/filters/Noise.js +0 -16
  187. package/cmj/filters/Pixelate.d.ts +0 -2
  188. package/cmj/filters/Pixelate.js +0 -64
  189. package/cmj/filters/Posterize.d.ts +0 -2
  190. package/cmj/filters/Posterize.js +0 -14
  191. package/cmj/filters/RGB.d.ts +0 -2
  192. package/cmj/filters/RGB.js +0 -43
  193. package/cmj/filters/RGBA.d.ts +0 -2
  194. package/cmj/filters/RGBA.js +0 -53
  195. package/cmj/filters/Sepia.d.ts +0 -2
  196. package/cmj/filters/Sepia.js +0 -15
  197. package/cmj/filters/Solarize.d.ts +0 -2
  198. package/cmj/filters/Solarize.js +0 -29
  199. package/cmj/filters/Threshold.d.ts +0 -2
  200. package/cmj/filters/Threshold.js +0 -14
  201. package/cmj/index-node.d.ts +0 -2
  202. package/cmj/index-node.js +0 -21
  203. package/cmj/index-types.d.ts +0 -181
  204. package/cmj/index.d.ts +0 -2
  205. package/cmj/index.js +0 -4
  206. package/cmj/package.json +0 -6
  207. package/cmj/shapes/Arc.d.ts +0 -25
  208. package/cmj/shapes/Arc.js +0 -59
  209. package/cmj/shapes/Arrow.d.ts +0 -25
  210. package/cmj/shapes/Arrow.js +0 -103
  211. package/cmj/shapes/Circle.d.ts +0 -13
  212. package/cmj/shapes/Circle.js +0 -37
  213. package/cmj/shapes/Ellipse.d.ts +0 -16
  214. package/cmj/shapes/Ellipse.js +0 -41
  215. package/cmj/shapes/Image.d.ts +0 -25
  216. package/cmj/shapes/Image.js +0 -117
  217. package/cmj/shapes/Label.d.ts +0 -35
  218. package/cmj/shapes/Label.js +0 -178
  219. package/cmj/shapes/Line.d.ts +0 -28
  220. package/cmj/shapes/Line.js +0 -159
  221. package/cmj/shapes/Path.d.ts +0 -37
  222. package/cmj/shapes/Path.js +0 -631
  223. package/cmj/shapes/Rect.d.ts +0 -10
  224. package/cmj/shapes/Rect.js +0 -26
  225. package/cmj/shapes/RegularPolygon.d.ts +0 -22
  226. package/cmj/shapes/RegularPolygon.js +0 -69
  227. package/cmj/shapes/Ring.d.ts +0 -15
  228. package/cmj/shapes/Ring.js +0 -37
  229. package/cmj/shapes/Sprite.d.ts +0 -30
  230. package/cmj/shapes/Sprite.js +0 -112
  231. package/cmj/shapes/Star.d.ts +0 -17
  232. package/cmj/shapes/Star.js +0 -42
  233. package/cmj/shapes/Text.d.ts +0 -62
  234. package/cmj/shapes/Text.js +0 -373
  235. package/cmj/shapes/TextPath.d.ts +0 -55
  236. package/cmj/shapes/TextPath.js +0 -351
  237. package/cmj/shapes/Transformer.d.ts +0 -116
  238. package/cmj/shapes/Transformer.js +0 -964
  239. package/cmj/shapes/Wedge.d.ts +0 -17
  240. package/cmj/shapes/Wedge.js +0 -42
  241. package/cmj/types.d.ts +0 -50
  242. package/cmj/types.js +0 -25
package/cmj/Animation.js DELETED
@@ -1,145 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Animation = void 0;
4
- const Global_1 = require("./Global");
5
- const Util_1 = require("./Util");
6
- var now = (function () {
7
- if (Global_1.glob.performance && Global_1.glob.performance.now) {
8
- return function () {
9
- return Global_1.glob.performance.now();
10
- };
11
- }
12
- return function () {
13
- return new Date().getTime();
14
- };
15
- })();
16
- class Animation {
17
- constructor(func, layers) {
18
- this.id = Animation.animIdCounter++;
19
- this.frame = {
20
- time: 0,
21
- timeDiff: 0,
22
- lastTime: now(),
23
- frameRate: 0,
24
- };
25
- this.func = func;
26
- this.setLayers(layers);
27
- }
28
- setLayers(layers) {
29
- var lays = [];
30
- if (!layers) {
31
- lays = [];
32
- }
33
- else if (layers.length > 0) {
34
- lays = layers;
35
- }
36
- else {
37
- lays = [layers];
38
- }
39
- this.layers = lays;
40
- return this;
41
- }
42
- getLayers() {
43
- return this.layers;
44
- }
45
- addLayer(layer) {
46
- var layers = this.layers, len = layers.length, n;
47
- for (n = 0; n < len; n++) {
48
- if (layers[n]._id === layer._id) {
49
- return false;
50
- }
51
- }
52
- this.layers.push(layer);
53
- return true;
54
- }
55
- isRunning() {
56
- var a = Animation, animations = a.animations, len = animations.length, n;
57
- for (n = 0; n < len; n++) {
58
- if (animations[n].id === this.id) {
59
- return true;
60
- }
61
- }
62
- return false;
63
- }
64
- start() {
65
- this.stop();
66
- this.frame.timeDiff = 0;
67
- this.frame.lastTime = now();
68
- Animation._addAnimation(this);
69
- return this;
70
- }
71
- stop() {
72
- Animation._removeAnimation(this);
73
- return this;
74
- }
75
- _updateFrameObject(time) {
76
- this.frame.timeDiff = time - this.frame.lastTime;
77
- this.frame.lastTime = time;
78
- this.frame.time += this.frame.timeDiff;
79
- this.frame.frameRate = 1000 / this.frame.timeDiff;
80
- }
81
- static _addAnimation(anim) {
82
- this.animations.push(anim);
83
- this._handleAnimation();
84
- }
85
- static _removeAnimation(anim) {
86
- var id = anim.id, animations = this.animations, len = animations.length, n;
87
- for (n = 0; n < len; n++) {
88
- if (animations[n].id === id) {
89
- this.animations.splice(n, 1);
90
- break;
91
- }
92
- }
93
- }
94
- static _runFrames() {
95
- var layerHash = {}, animations = this.animations, anim, layers, func, n, i, layersLen, layer, key, needRedraw;
96
- for (n = 0; n < animations.length; n++) {
97
- anim = animations[n];
98
- layers = anim.layers;
99
- func = anim.func;
100
- anim._updateFrameObject(now());
101
- layersLen = layers.length;
102
- if (func) {
103
- needRedraw = func.call(anim, anim.frame) !== false;
104
- }
105
- else {
106
- needRedraw = true;
107
- }
108
- if (!needRedraw) {
109
- continue;
110
- }
111
- for (i = 0; i < layersLen; i++) {
112
- layer = layers[i];
113
- if (layer._id !== undefined) {
114
- layerHash[layer._id] = layer;
115
- }
116
- }
117
- }
118
- for (key in layerHash) {
119
- if (!layerHash.hasOwnProperty(key)) {
120
- continue;
121
- }
122
- layerHash[key].batchDraw();
123
- }
124
- }
125
- static _animationLoop() {
126
- var Anim = Animation;
127
- if (Anim.animations.length) {
128
- Anim._runFrames();
129
- Util_1.Util.requestAnimFrame(Anim._animationLoop);
130
- }
131
- else {
132
- Anim.animRunning = false;
133
- }
134
- }
135
- static _handleAnimation() {
136
- if (!this.animRunning) {
137
- this.animRunning = true;
138
- Util_1.Util.requestAnimFrame(this._animationLoop);
139
- }
140
- }
141
- }
142
- exports.Animation = Animation;
143
- Animation.animations = [];
144
- Animation.animIdCounter = 0;
145
- Animation.animRunning = false;
package/cmj/Canvas.d.ts DELETED
@@ -1,32 +0,0 @@
1
- import { Context } from './Context';
2
- interface ICanvasConfig {
3
- width?: number;
4
- height?: number;
5
- pixelRatio?: number;
6
- }
7
- export declare class Canvas {
8
- pixelRatio: number;
9
- _canvas: HTMLCanvasElement;
10
- context: Context;
11
- width: number;
12
- height: number;
13
- isCache: boolean;
14
- constructor(config: ICanvasConfig);
15
- getContext(): Context;
16
- getPixelRatio(): number;
17
- setPixelRatio(pixelRatio: any): void;
18
- setWidth(width: any): void;
19
- setHeight(height: any): void;
20
- getWidth(): number;
21
- getHeight(): number;
22
- setSize(width: any, height: any): void;
23
- toDataURL(mimeType: any, quality: any): string;
24
- }
25
- export declare class SceneCanvas extends Canvas {
26
- constructor(config?: ICanvasConfig);
27
- }
28
- export declare class HitCanvas extends Canvas {
29
- hitCanvas: boolean;
30
- constructor(config?: ICanvasConfig);
31
- }
32
- export {};
package/cmj/Canvas.js DELETED
@@ -1,114 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HitCanvas = exports.SceneCanvas = exports.Canvas = void 0;
4
- const Util_1 = require("./Util");
5
- const Context_1 = require("./Context");
6
- const Global_1 = require("./Global");
7
- const Factory_1 = require("./Factory");
8
- const Validators_1 = require("./Validators");
9
- var _pixelRatio;
10
- function getDevicePixelRatio() {
11
- if (_pixelRatio) {
12
- return _pixelRatio;
13
- }
14
- var canvas = Util_1.Util.createCanvasElement();
15
- var context = canvas.getContext('2d');
16
- _pixelRatio = (function () {
17
- var devicePixelRatio = Global_1.Konva._global.devicePixelRatio || 1, backingStoreRatio = context.webkitBackingStorePixelRatio ||
18
- context.mozBackingStorePixelRatio ||
19
- context.msBackingStorePixelRatio ||
20
- context.oBackingStorePixelRatio ||
21
- context.backingStorePixelRatio ||
22
- 1;
23
- return devicePixelRatio / backingStoreRatio;
24
- })();
25
- Util_1.Util.releaseCanvas(canvas);
26
- return _pixelRatio;
27
- }
28
- class Canvas {
29
- constructor(config) {
30
- this.pixelRatio = 1;
31
- this.width = 0;
32
- this.height = 0;
33
- this.isCache = false;
34
- var conf = config || {};
35
- var pixelRatio = conf.pixelRatio || Global_1.Konva.pixelRatio || getDevicePixelRatio();
36
- this.pixelRatio = pixelRatio;
37
- this._canvas = Util_1.Util.createCanvasElement();
38
- this._canvas.style.padding = '0';
39
- this._canvas.style.margin = '0';
40
- this._canvas.style.border = '0';
41
- this._canvas.style.background = 'transparent';
42
- this._canvas.style.position = 'absolute';
43
- this._canvas.style.top = '0';
44
- this._canvas.style.left = '0';
45
- }
46
- getContext() {
47
- return this.context;
48
- }
49
- getPixelRatio() {
50
- return this.pixelRatio;
51
- }
52
- setPixelRatio(pixelRatio) {
53
- var previousRatio = this.pixelRatio;
54
- this.pixelRatio = pixelRatio;
55
- this.setSize(this.getWidth() / previousRatio, this.getHeight() / previousRatio);
56
- }
57
- setWidth(width) {
58
- this.width = this._canvas.width = width * this.pixelRatio;
59
- this._canvas.style.width = width + 'px';
60
- var pixelRatio = this.pixelRatio, _context = this.getContext()._context;
61
- _context.scale(pixelRatio, pixelRatio);
62
- }
63
- setHeight(height) {
64
- this.height = this._canvas.height = height * this.pixelRatio;
65
- this._canvas.style.height = height + 'px';
66
- var pixelRatio = this.pixelRatio, _context = this.getContext()._context;
67
- _context.scale(pixelRatio, pixelRatio);
68
- }
69
- getWidth() {
70
- return this.width;
71
- }
72
- getHeight() {
73
- return this.height;
74
- }
75
- setSize(width, height) {
76
- this.setWidth(width || 0);
77
- this.setHeight(height || 0);
78
- }
79
- toDataURL(mimeType, quality) {
80
- try {
81
- return this._canvas.toDataURL(mimeType, quality);
82
- }
83
- catch (e) {
84
- try {
85
- return this._canvas.toDataURL();
86
- }
87
- catch (err) {
88
- Util_1.Util.error('Unable to get data URL. ' +
89
- err.message +
90
- ' For more info read https://konvajs.org/docs/posts/Tainted_Canvas.html.');
91
- return '';
92
- }
93
- }
94
- }
95
- }
96
- exports.Canvas = Canvas;
97
- Factory_1.Factory.addGetterSetter(Canvas, 'pixelRatio', undefined, (0, Validators_1.getNumberValidator)());
98
- class SceneCanvas extends Canvas {
99
- constructor(config = { width: 0, height: 0 }) {
100
- super(config);
101
- this.context = new Context_1.SceneContext(this);
102
- this.setSize(config.width, config.height);
103
- }
104
- }
105
- exports.SceneCanvas = SceneCanvas;
106
- class HitCanvas extends Canvas {
107
- constructor(config = { width: 0, height: 0 }) {
108
- super(config);
109
- this.hitCanvas = true;
110
- this.context = new Context_1.HitContext(this);
111
- this.setSize(config.width, config.height);
112
- }
113
- }
114
- exports.HitCanvas = HitCanvas;
@@ -1,47 +0,0 @@
1
- import { Node, NodeConfig } from './Node';
2
- import { GetSet, IRect } from './types';
3
- import { HitCanvas, SceneCanvas } from './Canvas';
4
- import { SceneContext } from './Context';
5
- export interface ContainerConfig extends NodeConfig {
6
- clearBeforeDraw?: boolean;
7
- clipFunc?: (ctx: SceneContext) => void;
8
- clipX?: number;
9
- clipY?: number;
10
- clipWidth?: number;
11
- clipHeight?: number;
12
- }
13
- export declare abstract class Container<ChildType extends Node = Node> extends Node<ContainerConfig> {
14
- children: Array<ChildType> | undefined;
15
- getChildren(filterFunc?: (item: Node) => boolean): ChildType[];
16
- hasChildren(): boolean;
17
- removeChildren(): this;
18
- destroyChildren(): this;
19
- abstract _validateAdd(node: Node): void;
20
- add(...children: ChildType[]): this;
21
- destroy(): this;
22
- find<ChildNode extends Node = Node>(selector: any): Array<ChildNode>;
23
- findOne<ChildNode extends Node = Node>(selector: string | Function): ChildNode;
24
- _generalFind<ChildNode extends Node = Node>(selector: string | Function, findOne: boolean): ChildNode[];
25
- private _descendants;
26
- toObject(): any;
27
- isAncestorOf(node: Node): boolean;
28
- clone(obj?: any): this;
29
- getAllIntersections(pos: any): any[];
30
- _clearSelfAndDescendantCache(attr?: string): void;
31
- _setChildrenIndices(): void;
32
- drawScene(can?: SceneCanvas, top?: Node): this;
33
- drawHit(can?: HitCanvas, top?: Node): this;
34
- _drawChildren(drawMethod: any, canvas: any, top: any): void;
35
- getClientRect(config?: {
36
- skipTransform?: boolean;
37
- skipShadow?: boolean;
38
- skipStroke?: boolean;
39
- relativeTo?: Container<Node>;
40
- }): IRect;
41
- clip: GetSet<IRect, this>;
42
- clipX: GetSet<number, this>;
43
- clipY: GetSet<number, this>;
44
- clipWidth: GetSet<number, this>;
45
- clipHeight: GetSet<number, this>;
46
- clipFunc: GetSet<(ctx: CanvasRenderingContext2D, shape: Container<ChildType>) => void, this>;
47
- }
package/cmj/Container.js DELETED
@@ -1,325 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Container = void 0;
4
- const Factory_1 = require("./Factory");
5
- const Node_1 = require("./Node");
6
- const Validators_1 = require("./Validators");
7
- class Container extends Node_1.Node {
8
- constructor() {
9
- super(...arguments);
10
- this.children = [];
11
- }
12
- getChildren(filterFunc) {
13
- if (!filterFunc) {
14
- return this.children || [];
15
- }
16
- const children = this.children || [];
17
- var results = [];
18
- children.forEach(function (child) {
19
- if (filterFunc(child)) {
20
- results.push(child);
21
- }
22
- });
23
- return results;
24
- }
25
- hasChildren() {
26
- return this.getChildren().length > 0;
27
- }
28
- removeChildren() {
29
- this.getChildren().forEach((child) => {
30
- child.parent = null;
31
- child.index = 0;
32
- child.remove();
33
- });
34
- this.children = [];
35
- this._requestDraw();
36
- return this;
37
- }
38
- destroyChildren() {
39
- this.getChildren().forEach((child) => {
40
- child.parent = null;
41
- child.index = 0;
42
- child.destroy();
43
- });
44
- this.children = [];
45
- this._requestDraw();
46
- return this;
47
- }
48
- add(...children) {
49
- if (children.length === 0) {
50
- return this;
51
- }
52
- if (children.length > 1) {
53
- for (var i = 0; i < children.length; i++) {
54
- this.add(children[i]);
55
- }
56
- return this;
57
- }
58
- const child = children[0];
59
- if (child.getParent()) {
60
- child.moveTo(this);
61
- return this;
62
- }
63
- this._validateAdd(child);
64
- child.index = this.getChildren().length;
65
- child.parent = this;
66
- child._clearCaches();
67
- this.getChildren().push(child);
68
- this._fire('add', {
69
- child: child,
70
- });
71
- this._requestDraw();
72
- return this;
73
- }
74
- destroy() {
75
- if (this.hasChildren()) {
76
- this.destroyChildren();
77
- }
78
- super.destroy();
79
- return this;
80
- }
81
- find(selector) {
82
- return this._generalFind(selector, false);
83
- }
84
- findOne(selector) {
85
- var result = this._generalFind(selector, true);
86
- return result.length > 0 ? result[0] : undefined;
87
- }
88
- _generalFind(selector, findOne) {
89
- var retArr = [];
90
- this._descendants((node) => {
91
- const valid = node._isMatch(selector);
92
- if (valid) {
93
- retArr.push(node);
94
- }
95
- if (valid && findOne) {
96
- return true;
97
- }
98
- return false;
99
- });
100
- return retArr;
101
- }
102
- _descendants(fn) {
103
- let shouldStop = false;
104
- const children = this.getChildren();
105
- for (const child of children) {
106
- shouldStop = fn(child);
107
- if (shouldStop) {
108
- return true;
109
- }
110
- if (!child.hasChildren()) {
111
- continue;
112
- }
113
- shouldStop = child._descendants(fn);
114
- if (shouldStop) {
115
- return true;
116
- }
117
- }
118
- return false;
119
- }
120
- toObject() {
121
- var obj = Node_1.Node.prototype.toObject.call(this);
122
- obj.children = [];
123
- this.getChildren().forEach((child) => {
124
- obj.children.push(child.toObject());
125
- });
126
- return obj;
127
- }
128
- isAncestorOf(node) {
129
- var parent = node.getParent();
130
- while (parent) {
131
- if (parent._id === this._id) {
132
- return true;
133
- }
134
- parent = parent.getParent();
135
- }
136
- return false;
137
- }
138
- clone(obj) {
139
- var node = Node_1.Node.prototype.clone.call(this, obj);
140
- this.getChildren().forEach(function (no) {
141
- node.add(no.clone());
142
- });
143
- return node;
144
- }
145
- getAllIntersections(pos) {
146
- var arr = [];
147
- this.find('Shape').forEach(function (shape) {
148
- if (shape.isVisible() && shape.intersects(pos)) {
149
- arr.push(shape);
150
- }
151
- });
152
- return arr;
153
- }
154
- _clearSelfAndDescendantCache(attr) {
155
- var _a;
156
- super._clearSelfAndDescendantCache(attr);
157
- if (this.isCached()) {
158
- return;
159
- }
160
- (_a = this.children) === null || _a === void 0 ? void 0 : _a.forEach(function (node) {
161
- node._clearSelfAndDescendantCache(attr);
162
- });
163
- }
164
- _setChildrenIndices() {
165
- var _a;
166
- (_a = this.children) === null || _a === void 0 ? void 0 : _a.forEach(function (child, n) {
167
- child.index = n;
168
- });
169
- this._requestDraw();
170
- }
171
- drawScene(can, top) {
172
- var layer = this.getLayer(), canvas = can || (layer && layer.getCanvas()), context = canvas && canvas.getContext(), cachedCanvas = this._getCanvasCache(), cachedSceneCanvas = cachedCanvas && cachedCanvas.scene;
173
- var caching = canvas && canvas.isCache;
174
- if (!this.isVisible() && !caching) {
175
- return this;
176
- }
177
- if (cachedSceneCanvas) {
178
- context.save();
179
- var m = this.getAbsoluteTransform(top).getMatrix();
180
- context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
181
- this._drawCachedSceneCanvas(context);
182
- context.restore();
183
- }
184
- else {
185
- this._drawChildren('drawScene', canvas, top);
186
- }
187
- return this;
188
- }
189
- drawHit(can, top) {
190
- if (!this.shouldDrawHit(top)) {
191
- return this;
192
- }
193
- var layer = this.getLayer(), canvas = can || (layer && layer.hitCanvas), context = canvas && canvas.getContext(), cachedCanvas = this._getCanvasCache(), cachedHitCanvas = cachedCanvas && cachedCanvas.hit;
194
- if (cachedHitCanvas) {
195
- context.save();
196
- var m = this.getAbsoluteTransform(top).getMatrix();
197
- context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
198
- this._drawCachedHitCanvas(context);
199
- context.restore();
200
- }
201
- else {
202
- this._drawChildren('drawHit', canvas, top);
203
- }
204
- return this;
205
- }
206
- _drawChildren(drawMethod, canvas, top) {
207
- var _a;
208
- var context = canvas && canvas.getContext(), clipWidth = this.clipWidth(), clipHeight = this.clipHeight(), clipFunc = this.clipFunc(), hasClip = (clipWidth && clipHeight) || clipFunc;
209
- const selfCache = top === this;
210
- if (hasClip) {
211
- context.save();
212
- var transform = this.getAbsoluteTransform(top);
213
- var m = transform.getMatrix();
214
- context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
215
- context.beginPath();
216
- if (clipFunc) {
217
- clipFunc.call(this, context, this);
218
- }
219
- else {
220
- var clipX = this.clipX();
221
- var clipY = this.clipY();
222
- context.rect(clipX, clipY, clipWidth, clipHeight);
223
- }
224
- context.clip();
225
- m = transform.copy().invert().getMatrix();
226
- context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
227
- }
228
- var hasComposition = !selfCache &&
229
- this.globalCompositeOperation() !== 'source-over' &&
230
- drawMethod === 'drawScene';
231
- if (hasComposition) {
232
- context.save();
233
- context._applyGlobalCompositeOperation(this);
234
- }
235
- (_a = this.children) === null || _a === void 0 ? void 0 : _a.forEach(function (child) {
236
- child[drawMethod](canvas, top);
237
- });
238
- if (hasComposition) {
239
- context.restore();
240
- }
241
- if (hasClip) {
242
- context.restore();
243
- }
244
- }
245
- getClientRect(config) {
246
- var _a;
247
- config = config || {};
248
- var skipTransform = config.skipTransform;
249
- var relativeTo = config.relativeTo;
250
- var minX, minY, maxX, maxY;
251
- var selfRect = {
252
- x: Infinity,
253
- y: Infinity,
254
- width: 0,
255
- height: 0,
256
- };
257
- var that = this;
258
- (_a = this.children) === null || _a === void 0 ? void 0 : _a.forEach(function (child) {
259
- if (!child.visible()) {
260
- return;
261
- }
262
- var rect = child.getClientRect({
263
- relativeTo: that,
264
- skipShadow: config.skipShadow,
265
- skipStroke: config.skipStroke,
266
- });
267
- if (rect.width === 0 && rect.height === 0) {
268
- return;
269
- }
270
- if (minX === undefined) {
271
- minX = rect.x;
272
- minY = rect.y;
273
- maxX = rect.x + rect.width;
274
- maxY = rect.y + rect.height;
275
- }
276
- else {
277
- minX = Math.min(minX, rect.x);
278
- minY = Math.min(minY, rect.y);
279
- maxX = Math.max(maxX, rect.x + rect.width);
280
- maxY = Math.max(maxY, rect.y + rect.height);
281
- }
282
- });
283
- var shapes = this.find('Shape');
284
- var hasVisible = false;
285
- for (var i = 0; i < shapes.length; i++) {
286
- var shape = shapes[i];
287
- if (shape._isVisible(this)) {
288
- hasVisible = true;
289
- break;
290
- }
291
- }
292
- if (hasVisible && minX !== undefined) {
293
- selfRect = {
294
- x: minX,
295
- y: minY,
296
- width: maxX - minX,
297
- height: maxY - minY,
298
- };
299
- }
300
- else {
301
- selfRect = {
302
- x: 0,
303
- y: 0,
304
- width: 0,
305
- height: 0,
306
- };
307
- }
308
- if (!skipTransform) {
309
- return this._transformedRect(selfRect, relativeTo);
310
- }
311
- return selfRect;
312
- }
313
- }
314
- exports.Container = Container;
315
- Factory_1.Factory.addComponentsGetterSetter(Container, 'clip', [
316
- 'x',
317
- 'y',
318
- 'width',
319
- 'height',
320
- ]);
321
- Factory_1.Factory.addGetterSetter(Container, 'clipX', undefined, (0, Validators_1.getNumberValidator)());
322
- Factory_1.Factory.addGetterSetter(Container, 'clipY', undefined, (0, Validators_1.getNumberValidator)());
323
- Factory_1.Factory.addGetterSetter(Container, 'clipWidth', undefined, (0, Validators_1.getNumberValidator)());
324
- Factory_1.Factory.addGetterSetter(Container, 'clipHeight', undefined, (0, Validators_1.getNumberValidator)());
325
- Factory_1.Factory.addGetterSetter(Container, 'clipFunc');