konva 10.3.3 → 10.5.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.
- package/README.md +1 -1
- package/konva.js +1576 -1636
- package/konva.min.js +4 -4
- package/lib/Animation.d.ts +63 -3
- package/lib/Animation.js +86 -65
- package/lib/BezierFunctions.d.ts +10 -0
- package/lib/BezierFunctions.js +32 -0
- package/lib/Canvas.d.ts +53 -0
- package/lib/Canvas.js +93 -34
- package/lib/Container.d.ts +156 -9
- package/lib/Container.js +260 -25
- package/lib/Context.d.ts +247 -0
- package/lib/Context.js +312 -74
- package/lib/Core.js +1 -0
- package/lib/DragAndDrop.d.ts +2 -0
- package/lib/DragAndDrop.js +92 -21
- package/lib/Factory.d.ts +24 -1
- package/lib/Factory.js +14 -20
- package/lib/FastLayer.d.ts +14 -1
- package/lib/FastLayer.js +14 -1
- package/lib/Global.d.ts +114 -3
- package/lib/Global.js +134 -5
- package/lib/Group.d.ts +11 -0
- package/lib/Group.js +11 -0
- package/lib/Layer.d.ts +128 -3
- package/lib/Layer.js +260 -49
- package/lib/Node.d.ts +703 -32
- package/lib/Node.js +1545 -202
- package/lib/PointerEvents.d.ts +2 -1
- package/lib/PointerEvents.js +19 -1
- package/lib/Shape.d.ts +99 -14
- package/lib/Shape.js +1101 -67
- package/lib/Stage.d.ts +85 -2
- package/lib/Stage.js +205 -14
- package/lib/Tween.d.ts +159 -4
- package/lib/Tween.js +243 -24
- package/lib/Util.d.ts +148 -4
- package/lib/Util.js +354 -82
- package/lib/Validators.d.ts +0 -2
- package/lib/Validators.js +3 -25
- package/lib/_CoreInternals.d.ts +12 -6
- package/lib/_CoreInternals.js +1 -0
- package/lib/_FullInternals.d.ts +17 -6
- package/lib/_FullInternals.js +7 -0
- package/lib/canvas-backend.js +6 -0
- package/lib/filters/Blur.d.ts +18 -0
- package/lib/filters/Blur.js +97 -24
- package/lib/filters/Brighten.d.ts +21 -0
- package/lib/filters/Brighten.js +24 -0
- package/lib/filters/Brightness.d.ts +11 -0
- package/lib/filters/Brightness.js +16 -0
- package/lib/filters/Contrast.d.ts +10 -0
- package/lib/filters/Contrast.js +21 -0
- package/lib/filters/Emboss.d.ts +20 -0
- package/lib/filters/Emboss.js +68 -8
- package/lib/filters/Enhance.d.ts +14 -0
- package/lib/filters/Enhance.js +34 -0
- package/lib/filters/Grayscale.d.ts +9 -0
- package/lib/filters/Grayscale.js +12 -0
- package/lib/filters/HSL.d.ts +17 -0
- package/lib/filters/HSL.js +48 -5
- package/lib/filters/HSV.d.ts +18 -0
- package/lib/filters/HSV.js +49 -5
- package/lib/filters/Invert.d.ts +9 -0
- package/lib/filters/Invert.js +12 -0
- package/lib/filters/Kaleidoscope.d.ts +12 -0
- package/lib/filters/Kaleidoscope.js +83 -0
- package/lib/filters/Mask.d.ts +11 -0
- package/lib/filters/Mask.js +18 -0
- package/lib/filters/Noise.d.ts +19 -0
- package/lib/filters/Noise.js +19 -0
- package/lib/filters/Pixelate.d.ts +20 -0
- package/lib/filters/Pixelate.js +28 -1
- package/lib/filters/Posterize.d.ts +21 -0
- package/lib/filters/Posterize.js +22 -0
- package/lib/filters/RGB.d.ts +21 -0
- package/lib/filters/RGB.js +43 -28
- package/lib/filters/RGBA.d.ts +23 -0
- package/lib/filters/RGBA.js +28 -41
- package/lib/filters/Sepia.d.ts +9 -0
- package/lib/filters/Sepia.js +10 -0
- package/lib/filters/Solarize.d.ts +10 -0
- package/lib/filters/Solarize.js +11 -0
- package/lib/filters/Threshold.d.ts +22 -0
- package/lib/filters/Threshold.js +22 -0
- package/lib/shapes/Arc.d.ts +40 -0
- package/lib/shapes/Arc.js +89 -6
- package/lib/shapes/Arrow.d.ts +24 -1
- package/lib/shapes/Arrow.js +83 -0
- package/lib/shapes/Circle.d.ts +18 -0
- package/lib/shapes/Circle.js +36 -9
- package/lib/shapes/Ellipse.d.ts +34 -2
- package/lib/shapes/Ellipse.js +67 -9
- package/lib/shapes/Image.d.ts +49 -0
- package/lib/shapes/Image.js +151 -22
- package/lib/shapes/Label.d.ts +65 -1
- package/lib/shapes/Label.js +113 -20
- package/lib/shapes/Line.d.ts +50 -8
- package/lib/shapes/Line.js +116 -20
- package/lib/shapes/Path.d.ts +56 -6
- package/lib/shapes/Path.js +203 -128
- package/lib/shapes/Rect.d.ts +18 -0
- package/lib/shapes/Rect.js +36 -0
- package/lib/shapes/RegularPolygon.d.ts +22 -0
- package/lib/shapes/RegularPolygon.js +70 -0
- package/lib/shapes/Ring.d.ts +19 -0
- package/lib/shapes/Ring.js +51 -5
- package/lib/shapes/Sprite.d.ts +78 -0
- package/lib/shapes/Sprite.js +238 -25
- package/lib/shapes/Star.d.ts +23 -0
- package/lib/shapes/Star.js +62 -0
- package/lib/shapes/Text.d.ts +59 -1
- package/lib/shapes/Text.js +481 -97
- package/lib/shapes/TextPath.d.ts +49 -3
- package/lib/shapes/TextPath.js +278 -34
- package/lib/shapes/Transformer.d.ts +124 -12
- package/lib/shapes/Transformer.js +864 -140
- package/lib/shapes/Wedge.d.ts +22 -0
- package/lib/shapes/Wedge.js +67 -3
- package/lib/skia-backend.js +9 -0
- package/lib/types.d.ts +2 -23
- package/lib/types.js +1 -21
- package/package.json +12 -16
package/lib/Context.js
CHANGED
|
@@ -14,7 +14,11 @@ function simplifyArray(arr) {
|
|
|
14
14
|
}
|
|
15
15
|
return retArr;
|
|
16
16
|
}
|
|
17
|
-
const COMMA = ',', OPEN_PAREN = '(', CLOSE_PAREN = ')',
|
|
17
|
+
const COMMA = ',', OPEN_PAREN = '(', CLOSE_PAREN = ')', SEMICOLON = ';', DOUBLE_PAREN = '()',
|
|
18
|
+
// EMPTY_STRING = '',
|
|
19
|
+
EQUALS = '=',
|
|
20
|
+
// SET = 'set',
|
|
21
|
+
CONTEXT_METHODS = [
|
|
18
22
|
'arc',
|
|
19
23
|
'arcTo',
|
|
20
24
|
'beginPath',
|
|
@@ -71,6 +75,7 @@ const CONTEXT_PROPERTIES = [
|
|
|
71
75
|
'filter',
|
|
72
76
|
];
|
|
73
77
|
const traceArrMax = 100;
|
|
78
|
+
// Check if CSS filters are supported in the current browser
|
|
74
79
|
let _cssFiltersSupported = null;
|
|
75
80
|
export function isCSSFiltersSupported() {
|
|
76
81
|
if (_cssFiltersSupported !== null) {
|
|
@@ -79,17 +84,36 @@ export function isCSSFiltersSupported() {
|
|
|
79
84
|
try {
|
|
80
85
|
const canvas = Util.createCanvasElement();
|
|
81
86
|
const ctx = canvas.getContext('2d');
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
return !!ctx && 'filter' in ctx;
|
|
87
|
+
_cssFiltersSupported = !!ctx && 'filter' in ctx;
|
|
88
|
+
Util.releaseCanvas(canvas);
|
|
87
89
|
}
|
|
88
90
|
catch (e) {
|
|
89
91
|
_cssFiltersSupported = false;
|
|
90
|
-
return false;
|
|
91
92
|
}
|
|
93
|
+
return _cssFiltersSupported;
|
|
92
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Konva wrapper around native 2d canvas context. It has almost the same API of 2d context with some additional functions.
|
|
97
|
+
* With core Konva shapes you don't need to use this object. But you will use it if you want to create
|
|
98
|
+
* a [custom shape](/docs/react/Custom_Shape.html) or a [custom hit regions](/docs/events/Custom_Hit_Region.html).
|
|
99
|
+
* For full information about each 2d context API use [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D)
|
|
100
|
+
* @constructor
|
|
101
|
+
* @memberof Konva
|
|
102
|
+
* @example
|
|
103
|
+
* const rect = new Konva.Shape({
|
|
104
|
+
* fill: 'red',
|
|
105
|
+
* width: 100,
|
|
106
|
+
* height: 100,
|
|
107
|
+
* sceneFunc: (ctx, shape) => {
|
|
108
|
+
* // ctx - is context wrapper
|
|
109
|
+
* // shape - is instance of Konva.Shape, so it equals to "rect" variable
|
|
110
|
+
* ctx.rect(0, 0, shape.getAttr('width'), shape.getAttr('height'));
|
|
111
|
+
*
|
|
112
|
+
* // automatically fill shape from props and draw hit region
|
|
113
|
+
* ctx.fillStrokeShape(shape);
|
|
114
|
+
* }
|
|
115
|
+
* })
|
|
116
|
+
*/
|
|
93
117
|
export class Context {
|
|
94
118
|
constructor(canvas) {
|
|
95
119
|
this.canvas = canvas;
|
|
@@ -98,20 +122,40 @@ export class Context {
|
|
|
98
122
|
this._enableTrace();
|
|
99
123
|
}
|
|
100
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* fill shape
|
|
127
|
+
* @method
|
|
128
|
+
* @name Konva.Context#fillShape
|
|
129
|
+
* @param {Konva.Shape} shape
|
|
130
|
+
*/
|
|
101
131
|
fillShape(shape) {
|
|
102
132
|
if (shape.fillEnabled()) {
|
|
103
133
|
this._fill(shape);
|
|
104
134
|
}
|
|
105
135
|
}
|
|
106
136
|
_fill(shape) {
|
|
107
|
-
|
|
137
|
+
// abstract
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* stroke shape
|
|
141
|
+
* @method
|
|
142
|
+
* @name Konva.Context#strokeShape
|
|
143
|
+
* @param {Konva.Shape} shape
|
|
144
|
+
*/
|
|
108
145
|
strokeShape(shape) {
|
|
109
146
|
if (shape.hasStroke()) {
|
|
110
147
|
this._stroke(shape);
|
|
111
148
|
}
|
|
112
149
|
}
|
|
113
150
|
_stroke(shape) {
|
|
114
|
-
|
|
151
|
+
// abstract
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* fill then stroke
|
|
155
|
+
* @method
|
|
156
|
+
* @name Konva.Context#fillStrokeShape
|
|
157
|
+
* @param {Konva.Shape} shape
|
|
158
|
+
*/
|
|
115
159
|
fillStrokeShape(shape) {
|
|
116
160
|
if (shape.attrs.fillAfterStrokeEnabled) {
|
|
117
161
|
this.strokeShape(shape);
|
|
@@ -127,6 +171,7 @@ export class Context {
|
|
|
127
171
|
for (n = 0; n < len; n++) {
|
|
128
172
|
trace = traceArr[n];
|
|
129
173
|
method = trace.method;
|
|
174
|
+
// methods
|
|
130
175
|
if (method) {
|
|
131
176
|
args = trace.args;
|
|
132
177
|
str += method;
|
|
@@ -134,18 +179,14 @@ export class Context {
|
|
|
134
179
|
str += DOUBLE_PAREN;
|
|
135
180
|
}
|
|
136
181
|
else {
|
|
137
|
-
if (
|
|
138
|
-
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
if (rounded) {
|
|
142
|
-
args = args.map((a) => typeof a === 'number' ? Math.floor(a) : a);
|
|
143
|
-
}
|
|
144
|
-
str += OPEN_PAREN + args.join(COMMA) + CLOSE_PAREN;
|
|
182
|
+
if (rounded) {
|
|
183
|
+
args = args.map((a) => (typeof a === 'number' ? Math.floor(a) : a));
|
|
145
184
|
}
|
|
185
|
+
str += OPEN_PAREN + args.join(COMMA) + CLOSE_PAREN;
|
|
146
186
|
}
|
|
147
187
|
}
|
|
148
188
|
else {
|
|
189
|
+
// properties
|
|
149
190
|
str += trace.property;
|
|
150
191
|
if (!relaxed) {
|
|
151
192
|
str += EQUALS + trace.val;
|
|
@@ -166,13 +207,34 @@ export class Context {
|
|
|
166
207
|
traceArr.shift();
|
|
167
208
|
}
|
|
168
209
|
}
|
|
210
|
+
/**
|
|
211
|
+
* reset canvas context transform
|
|
212
|
+
* @method
|
|
213
|
+
* @name Konva.Context#reset
|
|
214
|
+
*/
|
|
169
215
|
reset() {
|
|
170
216
|
const pixelRatio = this.getCanvas().getPixelRatio();
|
|
171
217
|
this.setTransform(1 * pixelRatio, 0, 0, 1 * pixelRatio, 0, 0);
|
|
172
218
|
}
|
|
219
|
+
/**
|
|
220
|
+
* get canvas wrapper
|
|
221
|
+
* @method
|
|
222
|
+
* @name Konva.Context#getCanvas
|
|
223
|
+
* @returns {Konva.Canvas}
|
|
224
|
+
*/
|
|
173
225
|
getCanvas() {
|
|
174
226
|
return this.canvas;
|
|
175
227
|
}
|
|
228
|
+
/**
|
|
229
|
+
* clear canvas
|
|
230
|
+
* @method
|
|
231
|
+
* @name Konva.Context#clear
|
|
232
|
+
* @param {Object} [bounds]
|
|
233
|
+
* @param {Number} [bounds.x]
|
|
234
|
+
* @param {Number} [bounds.y]
|
|
235
|
+
* @param {Number} [bounds.width]
|
|
236
|
+
* @param {Number} [bounds.height]
|
|
237
|
+
*/
|
|
176
238
|
clear(bounds) {
|
|
177
239
|
const canvas = this.getCanvas();
|
|
178
240
|
if (bounds) {
|
|
@@ -209,27 +271,63 @@ export class Context {
|
|
|
209
271
|
setAttr(attr, val) {
|
|
210
272
|
this._context[attr] = val;
|
|
211
273
|
}
|
|
274
|
+
/**
|
|
275
|
+
* arc function.
|
|
276
|
+
* @method
|
|
277
|
+
* @name Konva.Context#arc
|
|
278
|
+
*/
|
|
212
279
|
arc(x, y, radius, startAngle, endAngle, counterClockwise) {
|
|
213
280
|
this._context.arc(x, y, radius, startAngle, endAngle, counterClockwise);
|
|
214
281
|
}
|
|
282
|
+
/**
|
|
283
|
+
* arcTo function.
|
|
284
|
+
* @method
|
|
285
|
+
* @name Konva.Context#arcTo
|
|
286
|
+
*
|
|
287
|
+
*/
|
|
215
288
|
arcTo(x1, y1, x2, y2, radius) {
|
|
216
289
|
this._context.arcTo(x1, y1, x2, y2, radius);
|
|
217
290
|
}
|
|
291
|
+
/**
|
|
292
|
+
* beginPath function.
|
|
293
|
+
* @method
|
|
294
|
+
* @name Konva.Context#beginPath
|
|
295
|
+
*/
|
|
218
296
|
beginPath() {
|
|
219
297
|
this._context.beginPath();
|
|
220
298
|
}
|
|
299
|
+
/**
|
|
300
|
+
* bezierCurveTo function.
|
|
301
|
+
* @method
|
|
302
|
+
* @name Konva.Context#bezierCurveTo
|
|
303
|
+
*/
|
|
221
304
|
bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) {
|
|
222
305
|
this._context.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
|
|
223
306
|
}
|
|
307
|
+
/**
|
|
308
|
+
* clearRect function.
|
|
309
|
+
* @method
|
|
310
|
+
* @name Konva.Context#clearRect
|
|
311
|
+
*/
|
|
224
312
|
clearRect(x, y, width, height) {
|
|
225
313
|
this._context.clearRect(x, y, width, height);
|
|
226
314
|
}
|
|
227
315
|
clip(...args) {
|
|
228
316
|
this._context.clip.apply(this._context, args);
|
|
229
317
|
}
|
|
318
|
+
/**
|
|
319
|
+
* closePath function.
|
|
320
|
+
* @method
|
|
321
|
+
* @name Konva.Context#closePath
|
|
322
|
+
*/
|
|
230
323
|
closePath() {
|
|
231
324
|
this._context.closePath();
|
|
232
325
|
}
|
|
326
|
+
/**
|
|
327
|
+
* createImageData function.
|
|
328
|
+
* @method
|
|
329
|
+
* @name Konva.Context#createImageData
|
|
330
|
+
*/
|
|
233
331
|
createImageData(width, height) {
|
|
234
332
|
const a = arguments;
|
|
235
333
|
if (a.length === 2) {
|
|
@@ -239,16 +337,37 @@ export class Context {
|
|
|
239
337
|
return this._context.createImageData(width);
|
|
240
338
|
}
|
|
241
339
|
}
|
|
340
|
+
/**
|
|
341
|
+
* createLinearGradient function.
|
|
342
|
+
* @method
|
|
343
|
+
* @name Konva.Context#createLinearGradient
|
|
344
|
+
*/
|
|
242
345
|
createLinearGradient(x0, y0, x1, y1) {
|
|
243
346
|
return this._context.createLinearGradient(x0, y0, x1, y1);
|
|
244
347
|
}
|
|
348
|
+
/**
|
|
349
|
+
* createPattern function.
|
|
350
|
+
* @method
|
|
351
|
+
* @name Konva.Context#createPattern
|
|
352
|
+
*/
|
|
245
353
|
createPattern(image, repetition) {
|
|
246
354
|
return this._context.createPattern(image, repetition);
|
|
247
355
|
}
|
|
356
|
+
/**
|
|
357
|
+
* createRadialGradient function.
|
|
358
|
+
* @method
|
|
359
|
+
* @name Konva.Context#createRadialGradient
|
|
360
|
+
*/
|
|
248
361
|
createRadialGradient(x0, y0, r0, x1, y1, r1) {
|
|
249
362
|
return this._context.createRadialGradient(x0, y0, r0, x1, y1, r1);
|
|
250
363
|
}
|
|
364
|
+
/**
|
|
365
|
+
* drawImage function.
|
|
366
|
+
* @method
|
|
367
|
+
* @name Konva.Context#drawImage
|
|
368
|
+
*/
|
|
251
369
|
drawImage(image, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight) {
|
|
370
|
+
// this._context.drawImage(...arguments);
|
|
252
371
|
const a = arguments, _context = this._context;
|
|
253
372
|
if (a.length === 3) {
|
|
254
373
|
_context.drawImage(image, sx, sy);
|
|
@@ -260,9 +379,19 @@ export class Context {
|
|
|
260
379
|
_context.drawImage(image, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight);
|
|
261
380
|
}
|
|
262
381
|
}
|
|
382
|
+
/**
|
|
383
|
+
* ellipse function.
|
|
384
|
+
* @method
|
|
385
|
+
* @name Konva.Context#ellipse
|
|
386
|
+
*/
|
|
263
387
|
ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, counterclockwise) {
|
|
264
388
|
this._context.ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, counterclockwise);
|
|
265
389
|
}
|
|
390
|
+
/**
|
|
391
|
+
* isPointInPath function.
|
|
392
|
+
* @method
|
|
393
|
+
* @name Konva.Context#isPointInPath
|
|
394
|
+
*/
|
|
266
395
|
isPointInPath(x, y, path, fillRule) {
|
|
267
396
|
if (path) {
|
|
268
397
|
return this._context.isPointInPath(path, x, y, fillRule);
|
|
@@ -270,14 +399,30 @@ export class Context {
|
|
|
270
399
|
return this._context.isPointInPath(x, y, fillRule);
|
|
271
400
|
}
|
|
272
401
|
fill(...args) {
|
|
402
|
+
// this._context.fill();
|
|
273
403
|
this._context.fill.apply(this._context, args);
|
|
274
404
|
}
|
|
405
|
+
/**
|
|
406
|
+
* fillRect function.
|
|
407
|
+
* @method
|
|
408
|
+
* @name Konva.Context#fillRect
|
|
409
|
+
*/
|
|
275
410
|
fillRect(x, y, width, height) {
|
|
276
411
|
this._context.fillRect(x, y, width, height);
|
|
277
412
|
}
|
|
413
|
+
/**
|
|
414
|
+
* strokeRect function.
|
|
415
|
+
* @method
|
|
416
|
+
* @name Konva.Context#strokeRect
|
|
417
|
+
*/
|
|
278
418
|
strokeRect(x, y, width, height) {
|
|
279
419
|
this._context.strokeRect(x, y, width, height);
|
|
280
420
|
}
|
|
421
|
+
/**
|
|
422
|
+
* fillText function.
|
|
423
|
+
* @method
|
|
424
|
+
* @name Konva.Context#fillText
|
|
425
|
+
*/
|
|
281
426
|
fillText(text, x, y, maxWidth) {
|
|
282
427
|
if (maxWidth) {
|
|
283
428
|
this._context.fillText(text, x, y, maxWidth);
|
|
@@ -286,59 +431,131 @@ export class Context {
|
|
|
286
431
|
this._context.fillText(text, x, y);
|
|
287
432
|
}
|
|
288
433
|
}
|
|
434
|
+
/**
|
|
435
|
+
* measureText function.
|
|
436
|
+
* @method
|
|
437
|
+
* @name Konva.Context#measureText
|
|
438
|
+
*/
|
|
289
439
|
measureText(text) {
|
|
290
440
|
return this._context.measureText(text);
|
|
291
441
|
}
|
|
442
|
+
/**
|
|
443
|
+
* getImageData function.
|
|
444
|
+
* @method
|
|
445
|
+
* @name Konva.Context#getImageData
|
|
446
|
+
*/
|
|
292
447
|
getImageData(sx, sy, sw, sh) {
|
|
293
448
|
return this._context.getImageData(sx, sy, sw, sh);
|
|
294
449
|
}
|
|
450
|
+
/**
|
|
451
|
+
* lineTo function.
|
|
452
|
+
* @method
|
|
453
|
+
* @name Konva.Context#lineTo
|
|
454
|
+
*/
|
|
295
455
|
lineTo(x, y) {
|
|
296
456
|
this._context.lineTo(x, y);
|
|
297
457
|
}
|
|
458
|
+
/**
|
|
459
|
+
* moveTo function.
|
|
460
|
+
* @method
|
|
461
|
+
* @name Konva.Context#moveTo
|
|
462
|
+
*/
|
|
298
463
|
moveTo(x, y) {
|
|
299
464
|
this._context.moveTo(x, y);
|
|
300
465
|
}
|
|
466
|
+
/**
|
|
467
|
+
* rect function.
|
|
468
|
+
* @method
|
|
469
|
+
* @name Konva.Context#rect
|
|
470
|
+
*/
|
|
301
471
|
rect(x, y, width, height) {
|
|
302
472
|
this._context.rect(x, y, width, height);
|
|
303
473
|
}
|
|
474
|
+
/**
|
|
475
|
+
* roundRect function.
|
|
476
|
+
* @method
|
|
477
|
+
* @name Konva.Context#roundRect
|
|
478
|
+
*/
|
|
304
479
|
roundRect(x, y, width, height, radii) {
|
|
305
480
|
this._context.roundRect(x, y, width, height, radii);
|
|
306
481
|
}
|
|
482
|
+
/**
|
|
483
|
+
* putImageData function.
|
|
484
|
+
* @method
|
|
485
|
+
* @name Konva.Context#putImageData
|
|
486
|
+
*/
|
|
307
487
|
putImageData(imageData, dx, dy) {
|
|
308
488
|
this._context.putImageData(imageData, dx, dy);
|
|
309
489
|
}
|
|
490
|
+
/**
|
|
491
|
+
* quadraticCurveTo function.
|
|
492
|
+
* @method
|
|
493
|
+
* @name Konva.Context#quadraticCurveTo
|
|
494
|
+
*/
|
|
310
495
|
quadraticCurveTo(cpx, cpy, x, y) {
|
|
311
496
|
this._context.quadraticCurveTo(cpx, cpy, x, y);
|
|
312
497
|
}
|
|
498
|
+
/**
|
|
499
|
+
* restore function.
|
|
500
|
+
* @method
|
|
501
|
+
* @name Konva.Context#restore
|
|
502
|
+
*/
|
|
313
503
|
restore() {
|
|
314
504
|
this._context.restore();
|
|
315
505
|
}
|
|
506
|
+
/**
|
|
507
|
+
* rotate function.
|
|
508
|
+
* @method
|
|
509
|
+
* @name Konva.Context#rotate
|
|
510
|
+
*/
|
|
316
511
|
rotate(angle) {
|
|
317
512
|
this._context.rotate(angle);
|
|
318
513
|
}
|
|
514
|
+
/**
|
|
515
|
+
* save function.
|
|
516
|
+
* @method
|
|
517
|
+
* @name Konva.Context#save
|
|
518
|
+
*/
|
|
319
519
|
save() {
|
|
320
520
|
this._context.save();
|
|
321
521
|
}
|
|
522
|
+
/**
|
|
523
|
+
* scale function.
|
|
524
|
+
* @method
|
|
525
|
+
* @name Konva.Context#scale
|
|
526
|
+
*/
|
|
322
527
|
scale(x, y) {
|
|
323
528
|
this._context.scale(x, y);
|
|
324
529
|
}
|
|
530
|
+
/**
|
|
531
|
+
* setLineDash function.
|
|
532
|
+
* @method
|
|
533
|
+
* @name Konva.Context#setLineDash
|
|
534
|
+
*/
|
|
325
535
|
setLineDash(segments) {
|
|
326
|
-
|
|
327
|
-
this._context.setLineDash(segments);
|
|
328
|
-
}
|
|
329
|
-
else if ('mozDash' in this._context) {
|
|
330
|
-
this._context['mozDash'] = segments;
|
|
331
|
-
}
|
|
332
|
-
else if ('webkitLineDash' in this._context) {
|
|
333
|
-
this._context['webkitLineDash'] = segments;
|
|
334
|
-
}
|
|
536
|
+
this._context.setLineDash(segments);
|
|
335
537
|
}
|
|
538
|
+
/**
|
|
539
|
+
* getLineDash function.
|
|
540
|
+
* @method
|
|
541
|
+
* @name Konva.Context#getLineDash
|
|
542
|
+
*/
|
|
336
543
|
getLineDash() {
|
|
337
544
|
return this._context.getLineDash();
|
|
338
545
|
}
|
|
546
|
+
/**
|
|
547
|
+
* setTransform function.
|
|
548
|
+
* @method
|
|
549
|
+
* @name Konva.Context#setTransform
|
|
550
|
+
*/
|
|
339
551
|
setTransform(a, b, c, d, e, f) {
|
|
340
552
|
this._context.setTransform(a, b, c, d, e, f);
|
|
341
553
|
}
|
|
554
|
+
/**
|
|
555
|
+
* stroke function.
|
|
556
|
+
* @method
|
|
557
|
+
* @name Konva.Context#stroke
|
|
558
|
+
*/
|
|
342
559
|
stroke(path2d) {
|
|
343
560
|
if (path2d) {
|
|
344
561
|
this._context.stroke(path2d);
|
|
@@ -347,17 +564,33 @@ export class Context {
|
|
|
347
564
|
this._context.stroke();
|
|
348
565
|
}
|
|
349
566
|
}
|
|
567
|
+
/**
|
|
568
|
+
* strokeText function.
|
|
569
|
+
* @method
|
|
570
|
+
* @name Konva.Context#strokeText
|
|
571
|
+
*/
|
|
350
572
|
strokeText(text, x, y, maxWidth) {
|
|
351
573
|
this._context.strokeText(text, x, y, maxWidth);
|
|
352
574
|
}
|
|
575
|
+
/**
|
|
576
|
+
* transform function.
|
|
577
|
+
* @method
|
|
578
|
+
* @name Konva.Context#transform
|
|
579
|
+
*/
|
|
353
580
|
transform(a, b, c, d, e, f) {
|
|
354
581
|
this._context.transform(a, b, c, d, e, f);
|
|
355
582
|
}
|
|
583
|
+
/**
|
|
584
|
+
* translate function.
|
|
585
|
+
* @method
|
|
586
|
+
* @name Konva.Context#translate
|
|
587
|
+
*/
|
|
356
588
|
translate(x, y) {
|
|
357
589
|
this._context.translate(x, y);
|
|
358
590
|
}
|
|
359
591
|
_enableTrace() {
|
|
360
592
|
let that = this, len = CONTEXT_METHODS.length, origSetter = this.setAttr, n, args;
|
|
593
|
+
// to prevent creating scope function at each loop
|
|
361
594
|
const func = function (methodName) {
|
|
362
595
|
let origMethod = that[methodName], ret;
|
|
363
596
|
that[methodName] = function () {
|
|
@@ -370,9 +603,11 @@ export class Context {
|
|
|
370
603
|
return ret;
|
|
371
604
|
};
|
|
372
605
|
};
|
|
606
|
+
// methods
|
|
373
607
|
for (n = 0; n < len; n++) {
|
|
374
608
|
func(CONTEXT_METHODS[n]);
|
|
375
609
|
}
|
|
610
|
+
// attrs
|
|
376
611
|
that.setAttr = function () {
|
|
377
612
|
origSetter.apply(that, arguments);
|
|
378
613
|
const prop = arguments[0];
|
|
@@ -419,6 +654,10 @@ export class SceneContext extends Context {
|
|
|
419
654
|
shape._fillFunc(this);
|
|
420
655
|
}
|
|
421
656
|
_fillPattern(shape) {
|
|
657
|
+
// `imageSmoothingEnabled` (set on the layer/context) controls pattern
|
|
658
|
+
// smoothing in the browser. node-canvas ignores it for pattern fills and
|
|
659
|
+
// instead exposes a non-standard `patternQuality` property, so mirror the
|
|
660
|
+
// current smoothing setting onto it to keep both backends consistent.
|
|
422
661
|
const context = this._context;
|
|
423
662
|
if ('patternQuality' in context) {
|
|
424
663
|
context.patternQuality = context.imageSmoothingEnabled
|
|
@@ -444,6 +683,7 @@ export class SceneContext extends Context {
|
|
|
444
683
|
}
|
|
445
684
|
_fill(shape) {
|
|
446
685
|
const hasColor = shape.fill(), fillPriority = shape.getFillPriority();
|
|
686
|
+
// priority fills
|
|
447
687
|
if (hasColor && fillPriority === 'color') {
|
|
448
688
|
this._fillColor(shape);
|
|
449
689
|
return;
|
|
@@ -463,6 +703,7 @@ export class SceneContext extends Context {
|
|
|
463
703
|
this._fillRadialGradient(shape);
|
|
464
704
|
return;
|
|
465
705
|
}
|
|
706
|
+
// now just try and fill with whatever is available
|
|
466
707
|
if (hasColor) {
|
|
467
708
|
this._fillColor(shape);
|
|
468
709
|
}
|
|
@@ -479,6 +720,7 @@ export class SceneContext extends Context {
|
|
|
479
720
|
_strokeLinearGradient(shape) {
|
|
480
721
|
const start = shape.getStrokeLinearGradientStartPoint(), end = shape.getStrokeLinearGradientEndPoint(), colorStops = shape.getStrokeLinearGradientColorStops(), grd = this.createLinearGradient(start.x, start.y, end.x, end.y);
|
|
481
722
|
if (colorStops) {
|
|
723
|
+
// build color stops
|
|
482
724
|
for (let n = 0; n < colorStops.length; n += 2) {
|
|
483
725
|
grd.addColorStop(colorStops[n], colorStops[n + 1]);
|
|
484
726
|
}
|
|
@@ -486,41 +728,38 @@ export class SceneContext extends Context {
|
|
|
486
728
|
}
|
|
487
729
|
}
|
|
488
730
|
_stroke(shape) {
|
|
489
|
-
const dash = shape.dash(),
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
731
|
+
const dash = shape.dash(),
|
|
732
|
+
// ignore strokeScaleEnabled for Text
|
|
733
|
+
strokeScaleEnabled = shape.getStrokeScaleEnabled();
|
|
734
|
+
if (!strokeScaleEnabled) {
|
|
735
|
+
this.save();
|
|
736
|
+
const pixelRatio = this.getCanvas().getPixelRatio();
|
|
737
|
+
this.setTransform(pixelRatio, 0, 0, pixelRatio, 0, 0);
|
|
738
|
+
}
|
|
739
|
+
this._applyLineCap(shape);
|
|
740
|
+
if (dash && shape.dashEnabled()) {
|
|
741
|
+
this.setLineDash(dash);
|
|
742
|
+
this.setAttr('lineDashOffset', shape.dashOffset());
|
|
743
|
+
}
|
|
744
|
+
this.setAttr('lineWidth', shape.strokeWidth());
|
|
745
|
+
if (!shape.getShadowForStrokeEnabled()) {
|
|
746
|
+
this.setAttr('shadowColor', 'rgba(0,0,0,0)');
|
|
747
|
+
}
|
|
748
|
+
const hasLinearGradient = shape.getStrokeLinearGradientColorStops();
|
|
749
|
+
if (hasLinearGradient) {
|
|
750
|
+
this._strokeLinearGradient(shape);
|
|
751
|
+
}
|
|
752
|
+
else {
|
|
753
|
+
this.setAttr('strokeStyle', shape.stroke());
|
|
754
|
+
}
|
|
755
|
+
shape._strokeFunc(this);
|
|
756
|
+
if (!strokeScaleEnabled) {
|
|
757
|
+
this.restore();
|
|
516
758
|
}
|
|
517
759
|
}
|
|
518
760
|
_applyShadow(shape) {
|
|
519
|
-
var _a
|
|
520
|
-
const color = (_a = shape.getShadowRGBA()) !== null && _a !== void 0 ? _a : 'black', blur = (
|
|
521
|
-
x: 0,
|
|
522
|
-
y: 0,
|
|
523
|
-
}, scale = shape.getAbsoluteScale(), ratio = this.canvas.getPixelRatio(), scaleX = scale.x * ratio, scaleY = scale.y * ratio;
|
|
761
|
+
var _a;
|
|
762
|
+
const color = (_a = shape.getShadowRGBA()) !== null && _a !== void 0 ? _a : 'black', blur = shape.getShadowBlur(), offset = shape.getShadowOffset(), scale = shape.getAbsoluteScale(), ratio = this.canvas.getPixelRatio(), scaleX = scale.x * ratio, scaleY = scale.y * ratio;
|
|
524
763
|
this.setAttr('shadowColor', color);
|
|
525
764
|
this.setAttr('shadowBlur', blur * Math.min(Math.abs(scaleX), Math.abs(scaleY)));
|
|
526
765
|
this.setAttr('shadowOffsetX', offset.x * scaleX);
|
|
@@ -546,22 +785,21 @@ export class HitContext extends Context {
|
|
|
546
785
|
}
|
|
547
786
|
}
|
|
548
787
|
_stroke(shape) {
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
}
|
|
788
|
+
// ignore strokeScaleEnabled for Text
|
|
789
|
+
const strokeScaleEnabled = shape.getStrokeScaleEnabled();
|
|
790
|
+
if (!strokeScaleEnabled) {
|
|
791
|
+
this.save();
|
|
792
|
+
const pixelRatio = this.getCanvas().getPixelRatio();
|
|
793
|
+
this.setTransform(pixelRatio, 0, 0, pixelRatio, 0, 0);
|
|
794
|
+
}
|
|
795
|
+
this._applyLineCap(shape);
|
|
796
|
+
const hitStrokeWidth = shape.hitStrokeWidth();
|
|
797
|
+
const strokeWidth = hitStrokeWidth === 'auto' ? shape.strokeWidth() : hitStrokeWidth;
|
|
798
|
+
this.setAttr('lineWidth', strokeWidth);
|
|
799
|
+
this.setAttr('strokeStyle', shape.colorKey);
|
|
800
|
+
shape._strokeFuncHit(this);
|
|
801
|
+
if (!strokeScaleEnabled) {
|
|
802
|
+
this.restore();
|
|
565
803
|
}
|
|
566
804
|
}
|
|
567
805
|
}
|
package/lib/Core.js
CHANGED
package/lib/DragAndDrop.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ type DragElement = {
|
|
|
5
5
|
startPointerPos: Vector2d;
|
|
6
6
|
offset: Vector2d;
|
|
7
7
|
pointerId?: number;
|
|
8
|
+
lastPos?: Vector2d;
|
|
8
9
|
startEvent?: any;
|
|
9
10
|
dragStatus: 'ready' | 'dragging' | 'stopped';
|
|
10
11
|
};
|
|
@@ -14,6 +15,7 @@ export declare const DD: {
|
|
|
14
15
|
readonly node: Node<import("./Node.ts").NodeConfig> | undefined;
|
|
15
16
|
_dragElements: Map<number, DragElement>;
|
|
16
17
|
_listenToWindow(win: Window): void;
|
|
18
|
+
_batchEvents(callback: () => void, win?: Window): void;
|
|
17
19
|
_drag(evt: any, win?: Window): void;
|
|
18
20
|
_endDragBefore(evt?: any, win?: Window): void;
|
|
19
21
|
_endDragAfter(evt: any): void;
|