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/Context.d.ts DELETED
@@ -1,85 +0,0 @@
1
- import { Canvas } from './Canvas';
2
- import { Shape } from './Shape';
3
- import { IRect } from './types';
4
- import type { Node } from './Node';
5
- declare var CONTEXT_PROPERTIES: readonly ["fillStyle", "strokeStyle", "shadowColor", "shadowBlur", "shadowOffsetX", "shadowOffsetY", "lineCap", "lineDashOffset", "lineJoin", "lineWidth", "miterLimit", "font", "textAlign", "textBaseline", "globalAlpha", "globalCompositeOperation", "imageSmoothingEnabled"];
6
- export declare class Context {
7
- canvas: Canvas;
8
- _context: CanvasRenderingContext2D;
9
- traceArr: Array<String>;
10
- constructor(canvas: Canvas);
11
- fillShape(shape: Shape): void;
12
- _fill(shape: Shape): void;
13
- strokeShape(shape: Shape): void;
14
- _stroke(shape: Shape): void;
15
- fillStrokeShape(shape: Shape): void;
16
- getTrace(relaxed?: boolean, rounded?: boolean): string;
17
- clearTrace(): void;
18
- _trace(str: any): void;
19
- reset(): void;
20
- getCanvas(): Canvas;
21
- clear(bounds?: IRect): void;
22
- _applyLineCap(shape: Shape): void;
23
- _applyOpacity(shape: Node): void;
24
- _applyLineJoin(shape: Shape): void;
25
- setAttr(attr: string, val: any): void;
26
- arc(a0: number, a1: number, a2: number, a3: number, a4: number, a5?: boolean): void;
27
- arcTo(a0: number, a1: number, a2: number, a3: number, a4: number): void;
28
- beginPath(): void;
29
- bezierCurveTo(a0: number, a1: number, a2: number, a3: number, a4: number, a5: number): void;
30
- clearRect(a0: number, a1: number, a2: number, a3: number): void;
31
- clip(): void;
32
- closePath(): void;
33
- createImageData(a0: any, a1: any): ImageData;
34
- createLinearGradient(a0: number, a1: number, a2: number, a3: number): CanvasGradient;
35
- createPattern(a0: CanvasImageSource, a1: string | null): CanvasPattern;
36
- createRadialGradient(a0: number, a1: number, a2: number, a3: number, a4: number, a5: number): CanvasGradient;
37
- drawImage(a0: CanvasImageSource, a1: number, a2: number, a3?: number, a4?: number, a5?: number, a6?: number, a7?: number, a8?: number): void;
38
- ellipse(a0: number, a1: number, a2: number, a3: number, a4: number, a5: number, a6: number, a7?: boolean): void;
39
- isPointInPath(x: number, y: number, path?: Path2D, fillRule?: CanvasFillRule): boolean;
40
- fill(path2d?: Path2D): void;
41
- fillRect(x: number, y: number, width: number, height: number): void;
42
- strokeRect(x: number, y: number, width: number, height: number): void;
43
- fillText(text: string, x: number, y: number, maxWidth?: number): void;
44
- measureText(text: string): TextMetrics;
45
- getImageData(a0: number, a1: number, a2: number, a3: number): ImageData;
46
- lineTo(a0: number, a1: number): void;
47
- moveTo(a0: number, a1: number): void;
48
- rect(a0: number, a1: number, a2: number, a3: number): void;
49
- putImageData(a0: ImageData, a1: number, a2: number): void;
50
- quadraticCurveTo(a0: number, a1: number, a2: number, a3: number): void;
51
- restore(): void;
52
- rotate(a0: number): void;
53
- save(): void;
54
- scale(a0: number, a1: number): void;
55
- setLineDash(a0: number[]): void;
56
- getLineDash(): number[];
57
- setTransform(a0: number, a1: number, a2: number, a3: number, a4: number, a5: number): void;
58
- stroke(path2d?: Path2D): void;
59
- strokeText(a0: string, a1: number, a2: number, a3?: number): void;
60
- transform(a0: number, a1: number, a2: number, a3: number, a4: number, a5: number): void;
61
- translate(a0: number, a1: number): void;
62
- _enableTrace(): void;
63
- _applyGlobalCompositeOperation(node: any): void;
64
- }
65
- type CanvasContextProps = Pick<CanvasRenderingContext2D, typeof CONTEXT_PROPERTIES[number]>;
66
- export interface Context extends CanvasContextProps {
67
- }
68
- export declare class SceneContext extends Context {
69
- constructor(canvas: Canvas);
70
- _fillColor(shape: Shape): void;
71
- _fillPattern(shape: Shape): void;
72
- _fillLinearGradient(shape: Shape): void;
73
- _fillRadialGradient(shape: Shape): void;
74
- _fill(shape: any): void;
75
- _strokeLinearGradient(shape: any): void;
76
- _stroke(shape: any): void;
77
- _applyShadow(shape: any): void;
78
- }
79
- export declare class HitContext extends Context {
80
- constructor(canvas: Canvas);
81
- _fill(shape: Shape): void;
82
- strokeShape(shape: Shape): void;
83
- _stroke(shape: any): void;
84
- }
85
- export {};
package/cmj/Context.js DELETED
@@ -1,538 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HitContext = exports.SceneContext = exports.Context = void 0;
4
- const Util_1 = require("./Util");
5
- const Global_1 = require("./Global");
6
- function simplifyArray(arr) {
7
- var retArr = [], len = arr.length, util = Util_1.Util, n, val;
8
- for (n = 0; n < len; n++) {
9
- val = arr[n];
10
- if (util._isNumber(val)) {
11
- val = Math.round(val * 1000) / 1000;
12
- }
13
- else if (!util._isString(val)) {
14
- val = val + '';
15
- }
16
- retArr.push(val);
17
- }
18
- return retArr;
19
- }
20
- var COMMA = ',', OPEN_PAREN = '(', CLOSE_PAREN = ')', OPEN_PAREN_BRACKET = '([', CLOSE_BRACKET_PAREN = '])', SEMICOLON = ';', DOUBLE_PAREN = '()', EQUALS = '=', CONTEXT_METHODS = [
21
- 'arc',
22
- 'arcTo',
23
- 'beginPath',
24
- 'bezierCurveTo',
25
- 'clearRect',
26
- 'clip',
27
- 'closePath',
28
- 'createLinearGradient',
29
- 'createPattern',
30
- 'createRadialGradient',
31
- 'drawImage',
32
- 'ellipse',
33
- 'fill',
34
- 'fillText',
35
- 'getImageData',
36
- 'createImageData',
37
- 'lineTo',
38
- 'moveTo',
39
- 'putImageData',
40
- 'quadraticCurveTo',
41
- 'rect',
42
- 'restore',
43
- 'rotate',
44
- 'save',
45
- 'scale',
46
- 'setLineDash',
47
- 'setTransform',
48
- 'stroke',
49
- 'strokeText',
50
- 'transform',
51
- 'translate',
52
- ];
53
- var CONTEXT_PROPERTIES = [
54
- 'fillStyle',
55
- 'strokeStyle',
56
- 'shadowColor',
57
- 'shadowBlur',
58
- 'shadowOffsetX',
59
- 'shadowOffsetY',
60
- 'lineCap',
61
- 'lineDashOffset',
62
- 'lineJoin',
63
- 'lineWidth',
64
- 'miterLimit',
65
- 'font',
66
- 'textAlign',
67
- 'textBaseline',
68
- 'globalAlpha',
69
- 'globalCompositeOperation',
70
- 'imageSmoothingEnabled',
71
- ];
72
- const traceArrMax = 100;
73
- class Context {
74
- constructor(canvas) {
75
- this.canvas = canvas;
76
- if (Global_1.Konva.enableTrace) {
77
- this.traceArr = [];
78
- this._enableTrace();
79
- }
80
- }
81
- fillShape(shape) {
82
- if (shape.fillEnabled()) {
83
- this._fill(shape);
84
- }
85
- }
86
- _fill(shape) {
87
- }
88
- strokeShape(shape) {
89
- if (shape.hasStroke()) {
90
- this._stroke(shape);
91
- }
92
- }
93
- _stroke(shape) {
94
- }
95
- fillStrokeShape(shape) {
96
- if (shape.attrs.fillAfterStrokeEnabled) {
97
- this.strokeShape(shape);
98
- this.fillShape(shape);
99
- }
100
- else {
101
- this.fillShape(shape);
102
- this.strokeShape(shape);
103
- }
104
- }
105
- getTrace(relaxed, rounded) {
106
- var traceArr = this.traceArr, len = traceArr.length, str = '', n, trace, method, args;
107
- for (n = 0; n < len; n++) {
108
- trace = traceArr[n];
109
- method = trace.method;
110
- if (method) {
111
- args = trace.args;
112
- str += method;
113
- if (relaxed) {
114
- str += DOUBLE_PAREN;
115
- }
116
- else {
117
- if (Util_1.Util._isArray(args[0])) {
118
- str += OPEN_PAREN_BRACKET + args.join(COMMA) + CLOSE_BRACKET_PAREN;
119
- }
120
- else {
121
- if (rounded) {
122
- args = args.map((a) => typeof a === 'number' ? Math.floor(a) : a);
123
- }
124
- str += OPEN_PAREN + args.join(COMMA) + CLOSE_PAREN;
125
- }
126
- }
127
- }
128
- else {
129
- str += trace.property;
130
- if (!relaxed) {
131
- str += EQUALS + trace.val;
132
- }
133
- }
134
- str += SEMICOLON;
135
- }
136
- return str;
137
- }
138
- clearTrace() {
139
- this.traceArr = [];
140
- }
141
- _trace(str) {
142
- var traceArr = this.traceArr, len;
143
- traceArr.push(str);
144
- len = traceArr.length;
145
- if (len >= traceArrMax) {
146
- traceArr.shift();
147
- }
148
- }
149
- reset() {
150
- var pixelRatio = this.getCanvas().getPixelRatio();
151
- this.setTransform(1 * pixelRatio, 0, 0, 1 * pixelRatio, 0, 0);
152
- }
153
- getCanvas() {
154
- return this.canvas;
155
- }
156
- clear(bounds) {
157
- var canvas = this.getCanvas();
158
- if (bounds) {
159
- this.clearRect(bounds.x || 0, bounds.y || 0, bounds.width || 0, bounds.height || 0);
160
- }
161
- else {
162
- this.clearRect(0, 0, canvas.getWidth() / canvas.pixelRatio, canvas.getHeight() / canvas.pixelRatio);
163
- }
164
- }
165
- _applyLineCap(shape) {
166
- const lineCap = shape.attrs.lineCap;
167
- if (lineCap) {
168
- this.setAttr('lineCap', lineCap);
169
- }
170
- }
171
- _applyOpacity(shape) {
172
- var absOpacity = shape.getAbsoluteOpacity();
173
- if (absOpacity !== 1) {
174
- this.setAttr('globalAlpha', absOpacity);
175
- }
176
- }
177
- _applyLineJoin(shape) {
178
- const lineJoin = shape.attrs.lineJoin;
179
- if (lineJoin) {
180
- this.setAttr('lineJoin', lineJoin);
181
- }
182
- }
183
- setAttr(attr, val) {
184
- this._context[attr] = val;
185
- }
186
- arc(a0, a1, a2, a3, a4, a5) {
187
- this._context.arc(a0, a1, a2, a3, a4, a5);
188
- }
189
- arcTo(a0, a1, a2, a3, a4) {
190
- this._context.arcTo(a0, a1, a2, a3, a4);
191
- }
192
- beginPath() {
193
- this._context.beginPath();
194
- }
195
- bezierCurveTo(a0, a1, a2, a3, a4, a5) {
196
- this._context.bezierCurveTo(a0, a1, a2, a3, a4, a5);
197
- }
198
- clearRect(a0, a1, a2, a3) {
199
- this._context.clearRect(a0, a1, a2, a3);
200
- }
201
- clip() {
202
- this._context.clip();
203
- }
204
- closePath() {
205
- this._context.closePath();
206
- }
207
- createImageData(a0, a1) {
208
- var a = arguments;
209
- if (a.length === 2) {
210
- return this._context.createImageData(a0, a1);
211
- }
212
- else if (a.length === 1) {
213
- return this._context.createImageData(a0);
214
- }
215
- }
216
- createLinearGradient(a0, a1, a2, a3) {
217
- return this._context.createLinearGradient(a0, a1, a2, a3);
218
- }
219
- createPattern(a0, a1) {
220
- return this._context.createPattern(a0, a1);
221
- }
222
- createRadialGradient(a0, a1, a2, a3, a4, a5) {
223
- return this._context.createRadialGradient(a0, a1, a2, a3, a4, a5);
224
- }
225
- drawImage(a0, a1, a2, a3, a4, a5, a6, a7, a8) {
226
- var a = arguments, _context = this._context;
227
- if (a.length === 3) {
228
- _context.drawImage(a0, a1, a2);
229
- }
230
- else if (a.length === 5) {
231
- _context.drawImage(a0, a1, a2, a3, a4);
232
- }
233
- else if (a.length === 9) {
234
- _context.drawImage(a0, a1, a2, a3, a4, a5, a6, a7, a8);
235
- }
236
- }
237
- ellipse(a0, a1, a2, a3, a4, a5, a6, a7) {
238
- this._context.ellipse(a0, a1, a2, a3, a4, a5, a6, a7);
239
- }
240
- isPointInPath(x, y, path, fillRule) {
241
- if (path) {
242
- return this._context.isPointInPath(path, x, y, fillRule);
243
- }
244
- return this._context.isPointInPath(x, y, fillRule);
245
- }
246
- fill(path2d) {
247
- if (path2d) {
248
- this._context.fill(path2d);
249
- }
250
- else {
251
- this._context.fill();
252
- }
253
- }
254
- fillRect(x, y, width, height) {
255
- this._context.fillRect(x, y, width, height);
256
- }
257
- strokeRect(x, y, width, height) {
258
- this._context.strokeRect(x, y, width, height);
259
- }
260
- fillText(text, x, y, maxWidth) {
261
- if (maxWidth) {
262
- this._context.fillText(text, x, y, maxWidth);
263
- }
264
- else {
265
- this._context.fillText(text, x, y);
266
- }
267
- }
268
- measureText(text) {
269
- return this._context.measureText(text);
270
- }
271
- getImageData(a0, a1, a2, a3) {
272
- return this._context.getImageData(a0, a1, a2, a3);
273
- }
274
- lineTo(a0, a1) {
275
- this._context.lineTo(a0, a1);
276
- }
277
- moveTo(a0, a1) {
278
- this._context.moveTo(a0, a1);
279
- }
280
- rect(a0, a1, a2, a3) {
281
- this._context.rect(a0, a1, a2, a3);
282
- }
283
- putImageData(a0, a1, a2) {
284
- this._context.putImageData(a0, a1, a2);
285
- }
286
- quadraticCurveTo(a0, a1, a2, a3) {
287
- this._context.quadraticCurveTo(a0, a1, a2, a3);
288
- }
289
- restore() {
290
- this._context.restore();
291
- }
292
- rotate(a0) {
293
- this._context.rotate(a0);
294
- }
295
- save() {
296
- this._context.save();
297
- }
298
- scale(a0, a1) {
299
- this._context.scale(a0, a1);
300
- }
301
- setLineDash(a0) {
302
- if (this._context.setLineDash) {
303
- this._context.setLineDash(a0);
304
- }
305
- else if ('mozDash' in this._context) {
306
- this._context['mozDash'] = a0;
307
- }
308
- else if ('webkitLineDash' in this._context) {
309
- this._context['webkitLineDash'] = a0;
310
- }
311
- }
312
- getLineDash() {
313
- return this._context.getLineDash();
314
- }
315
- setTransform(a0, a1, a2, a3, a4, a5) {
316
- this._context.setTransform(a0, a1, a2, a3, a4, a5);
317
- }
318
- stroke(path2d) {
319
- if (path2d) {
320
- this._context.stroke(path2d);
321
- }
322
- else {
323
- this._context.stroke();
324
- }
325
- }
326
- strokeText(a0, a1, a2, a3) {
327
- this._context.strokeText(a0, a1, a2, a3);
328
- }
329
- transform(a0, a1, a2, a3, a4, a5) {
330
- this._context.transform(a0, a1, a2, a3, a4, a5);
331
- }
332
- translate(a0, a1) {
333
- this._context.translate(a0, a1);
334
- }
335
- _enableTrace() {
336
- var that = this, len = CONTEXT_METHODS.length, origSetter = this.setAttr, n, args;
337
- var func = function (methodName) {
338
- var origMethod = that[methodName], ret;
339
- that[methodName] = function () {
340
- args = simplifyArray(Array.prototype.slice.call(arguments, 0));
341
- ret = origMethod.apply(that, arguments);
342
- that._trace({
343
- method: methodName,
344
- args: args,
345
- });
346
- return ret;
347
- };
348
- };
349
- for (n = 0; n < len; n++) {
350
- func(CONTEXT_METHODS[n]);
351
- }
352
- that.setAttr = function () {
353
- origSetter.apply(that, arguments);
354
- var prop = arguments[0];
355
- var val = arguments[1];
356
- if (prop === 'shadowOffsetX' ||
357
- prop === 'shadowOffsetY' ||
358
- prop === 'shadowBlur') {
359
- val = val / this.canvas.getPixelRatio();
360
- }
361
- that._trace({
362
- property: prop,
363
- val: val,
364
- });
365
- };
366
- }
367
- _applyGlobalCompositeOperation(node) {
368
- const op = node.attrs.globalCompositeOperation;
369
- var def = !op || op === 'source-over';
370
- if (!def) {
371
- this.setAttr('globalCompositeOperation', op);
372
- }
373
- }
374
- }
375
- exports.Context = Context;
376
- CONTEXT_PROPERTIES.forEach(function (prop) {
377
- Object.defineProperty(Context.prototype, prop, {
378
- get() {
379
- return this._context[prop];
380
- },
381
- set(val) {
382
- this._context[prop] = val;
383
- },
384
- });
385
- });
386
- class SceneContext extends Context {
387
- constructor(canvas) {
388
- super(canvas);
389
- this._context = canvas._canvas.getContext('2d');
390
- }
391
- _fillColor(shape) {
392
- var fill = shape.fill();
393
- this.setAttr('fillStyle', fill);
394
- shape._fillFunc(this);
395
- }
396
- _fillPattern(shape) {
397
- this.setAttr('fillStyle', shape._getFillPattern());
398
- shape._fillFunc(this);
399
- }
400
- _fillLinearGradient(shape) {
401
- var grd = shape._getLinearGradient();
402
- if (grd) {
403
- this.setAttr('fillStyle', grd);
404
- shape._fillFunc(this);
405
- }
406
- }
407
- _fillRadialGradient(shape) {
408
- const grd = shape._getRadialGradient();
409
- if (grd) {
410
- this.setAttr('fillStyle', grd);
411
- shape._fillFunc(this);
412
- }
413
- }
414
- _fill(shape) {
415
- const hasColor = shape.fill(), fillPriority = shape.getFillPriority();
416
- if (hasColor && fillPriority === 'color') {
417
- this._fillColor(shape);
418
- return;
419
- }
420
- const hasPattern = shape.getFillPatternImage();
421
- if (hasPattern && fillPriority === 'pattern') {
422
- this._fillPattern(shape);
423
- return;
424
- }
425
- const hasLinearGradient = shape.getFillLinearGradientColorStops();
426
- if (hasLinearGradient && fillPriority === 'linear-gradient') {
427
- this._fillLinearGradient(shape);
428
- return;
429
- }
430
- const hasRadialGradient = shape.getFillRadialGradientColorStops();
431
- if (hasRadialGradient && fillPriority === 'radial-gradient') {
432
- this._fillRadialGradient(shape);
433
- return;
434
- }
435
- if (hasColor) {
436
- this._fillColor(shape);
437
- }
438
- else if (hasPattern) {
439
- this._fillPattern(shape);
440
- }
441
- else if (hasLinearGradient) {
442
- this._fillLinearGradient(shape);
443
- }
444
- else if (hasRadialGradient) {
445
- this._fillRadialGradient(shape);
446
- }
447
- }
448
- _strokeLinearGradient(shape) {
449
- const start = shape.getStrokeLinearGradientStartPoint(), end = shape.getStrokeLinearGradientEndPoint(), colorStops = shape.getStrokeLinearGradientColorStops(), grd = this.createLinearGradient(start.x, start.y, end.x, end.y);
450
- if (colorStops) {
451
- for (var n = 0; n < colorStops.length; n += 2) {
452
- grd.addColorStop(colorStops[n], colorStops[n + 1]);
453
- }
454
- this.setAttr('strokeStyle', grd);
455
- }
456
- }
457
- _stroke(shape) {
458
- var dash = shape.dash(), strokeScaleEnabled = shape.getStrokeScaleEnabled();
459
- if (shape.hasStroke()) {
460
- if (!strokeScaleEnabled) {
461
- this.save();
462
- var pixelRatio = this.getCanvas().getPixelRatio();
463
- this.setTransform(pixelRatio, 0, 0, pixelRatio, 0, 0);
464
- }
465
- this._applyLineCap(shape);
466
- if (dash && shape.dashEnabled()) {
467
- this.setLineDash(dash);
468
- this.setAttr('lineDashOffset', shape.dashOffset());
469
- }
470
- this.setAttr('lineWidth', shape.strokeWidth());
471
- if (!shape.getShadowForStrokeEnabled()) {
472
- this.setAttr('shadowColor', 'rgba(0,0,0,0)');
473
- }
474
- var hasLinearGradient = shape.getStrokeLinearGradientColorStops();
475
- if (hasLinearGradient) {
476
- this._strokeLinearGradient(shape);
477
- }
478
- else {
479
- this.setAttr('strokeStyle', shape.stroke());
480
- }
481
- shape._strokeFunc(this);
482
- if (!strokeScaleEnabled) {
483
- this.restore();
484
- }
485
- }
486
- }
487
- _applyShadow(shape) {
488
- var _a, _b, _c;
489
- var color = (_a = shape.getShadowRGBA()) !== null && _a !== void 0 ? _a : 'black', blur = (_b = shape.getShadowBlur()) !== null && _b !== void 0 ? _b : 5, offset = (_c = shape.getShadowOffset()) !== null && _c !== void 0 ? _c : {
490
- x: 0,
491
- y: 0,
492
- }, scale = shape.getAbsoluteScale(), ratio = this.canvas.getPixelRatio(), scaleX = scale.x * ratio, scaleY = scale.y * ratio;
493
- this.setAttr('shadowColor', color);
494
- this.setAttr('shadowBlur', blur * Math.min(Math.abs(scaleX), Math.abs(scaleY)));
495
- this.setAttr('shadowOffsetX', offset.x * scaleX);
496
- this.setAttr('shadowOffsetY', offset.y * scaleY);
497
- }
498
- }
499
- exports.SceneContext = SceneContext;
500
- class HitContext extends Context {
501
- constructor(canvas) {
502
- super(canvas);
503
- this._context = canvas._canvas.getContext('2d', {
504
- willReadFrequently: true,
505
- });
506
- }
507
- _fill(shape) {
508
- this.save();
509
- this.setAttr('fillStyle', shape.colorKey);
510
- shape._fillFuncHit(this);
511
- this.restore();
512
- }
513
- strokeShape(shape) {
514
- if (shape.hasHitStroke()) {
515
- this._stroke(shape);
516
- }
517
- }
518
- _stroke(shape) {
519
- if (shape.hasHitStroke()) {
520
- const strokeScaleEnabled = shape.getStrokeScaleEnabled();
521
- if (!strokeScaleEnabled) {
522
- this.save();
523
- var pixelRatio = this.getCanvas().getPixelRatio();
524
- this.setTransform(pixelRatio, 0, 0, pixelRatio, 0, 0);
525
- }
526
- this._applyLineCap(shape);
527
- var hitStrokeWidth = shape.hitStrokeWidth();
528
- var strokeWidth = hitStrokeWidth === 'auto' ? shape.strokeWidth() : hitStrokeWidth;
529
- this.setAttr('lineWidth', strokeWidth);
530
- this.setAttr('strokeStyle', shape.colorKey);
531
- shape._strokeFuncHit(this);
532
- if (!strokeScaleEnabled) {
533
- this.restore();
534
- }
535
- }
536
- }
537
- }
538
- exports.HitContext = HitContext;
package/cmj/Core.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export { Konva } from './_CoreInternals';
2
- import { Konva } from './_CoreInternals';
3
- export default Konva;
package/cmj/Core.js DELETED
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Konva = void 0;
4
- var _CoreInternals_1 = require("./_CoreInternals");
5
- Object.defineProperty(exports, "Konva", { enumerable: true, get: function () { return _CoreInternals_1.Konva; } });
6
- const _CoreInternals_2 = require("./_CoreInternals");
7
- exports.default = _CoreInternals_2.Konva;
@@ -1,17 +0,0 @@
1
- import { Node } from './Node';
2
- import { Vector2d } from './types';
3
- export declare const DD: {
4
- readonly isDragging: boolean;
5
- justDragged: boolean;
6
- readonly node: Node<import("./Node").NodeConfig>;
7
- _dragElements: Map<number, {
8
- node: Node;
9
- startPointerPos: Vector2d;
10
- offset: Vector2d;
11
- pointerId?: number;
12
- dragStatus: 'ready' | 'dragging' | 'stopped';
13
- }>;
14
- _drag(evt: any): void;
15
- _endDragBefore(evt?: any): void;
16
- _endDragAfter(evt: any): void;
17
- };