konva 10.3.0 → 10.3.2
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 +33 -43
- package/konva.js +1158 -681
- package/konva.min.js +4 -4
- package/lib/BezierFunctions.d.ts +2 -0
- package/lib/BezierFunctions.js +46 -0
- package/lib/Canvas.d.ts +1 -0
- package/lib/Canvas.js +6 -0
- package/lib/Container.js +22 -8
- package/lib/Context.js +6 -0
- package/lib/DragAndDrop.d.ts +13 -10
- package/lib/DragAndDrop.js +18 -13
- package/lib/Factory.d.ts +1 -1
- package/lib/Global.js +1 -1
- package/lib/Layer.d.ts +1 -0
- package/lib/Layer.js +15 -4
- package/lib/Node.d.ts +6 -2
- package/lib/Node.js +51 -18
- package/lib/PointerEvents.js +12 -2
- package/lib/Shape.js +6 -5
- package/lib/Stage.d.ts +2 -0
- package/lib/Stage.js +34 -19
- package/lib/Tween.js +10 -4
- package/lib/Util.d.ts +1 -7
- package/lib/Util.js +135 -135
- package/lib/_CoreInternals.d.ts +4 -9
- package/lib/_FullInternals.d.ts +4 -9
- package/lib/shapes/Arc.js +11 -0
- package/lib/shapes/Line.d.ts +2 -0
- package/lib/shapes/Line.js +39 -59
- package/lib/shapes/Path.js +10 -6
- package/lib/shapes/Text.d.ts +2 -0
- package/lib/shapes/Text.js +21 -4
- package/lib/shapes/Transformer.d.ts +5 -1
- package/lib/shapes/Transformer.js +80 -37
- package/package.json +13 -1
package/lib/Stage.js
CHANGED
|
@@ -93,6 +93,19 @@ function checkNoClip(attrs = {}) {
|
|
|
93
93
|
}
|
|
94
94
|
const NO_POINTERS_MESSAGE = `Pointer position is missing and not registered by the stage. Looks like it is outside of the stage container. You can set it manually from event: stage.setPointersPositions(event);`;
|
|
95
95
|
export const stages = [];
|
|
96
|
+
const listeningWindows = new WeakSet();
|
|
97
|
+
const listenToWindow = (win) => {
|
|
98
|
+
if (!win || listeningWindows.has(win)) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
listeningWindows.add(win);
|
|
102
|
+
DD._listenToWindow(win);
|
|
103
|
+
win.document.addEventListener('visibilitychange', () => {
|
|
104
|
+
stages.forEach((stage) => {
|
|
105
|
+
stage.batchDraw();
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
};
|
|
96
109
|
export class Stage extends Container {
|
|
97
110
|
constructor(config) {
|
|
98
111
|
super(checkNoClip(config));
|
|
@@ -123,6 +136,11 @@ export class Stage extends Container {
|
|
|
123
136
|
const style = this.visible() ? '' : 'none';
|
|
124
137
|
this.content.style.display = style;
|
|
125
138
|
}
|
|
139
|
+
_getOwnerWindow() {
|
|
140
|
+
var _a;
|
|
141
|
+
const element = this.content || this.container();
|
|
142
|
+
return (((_a = element === null || element === void 0 ? void 0 : element.ownerDocument) === null || _a === void 0 ? void 0 : _a.defaultView) || (Konva.isBrowser ? window : null));
|
|
143
|
+
}
|
|
126
144
|
setContainer(container) {
|
|
127
145
|
if (typeof container === STRING) {
|
|
128
146
|
let id;
|
|
@@ -149,6 +167,7 @@ export class Stage extends Container {
|
|
|
149
167
|
this.content.parentElement.removeChild(this.content);
|
|
150
168
|
}
|
|
151
169
|
container.appendChild(this.content);
|
|
170
|
+
listenToWindow(this._getOwnerWindow());
|
|
152
171
|
}
|
|
153
172
|
return this;
|
|
154
173
|
}
|
|
@@ -251,13 +270,15 @@ export class Stage extends Container {
|
|
|
251
270
|
this.content.style.width = width + PX;
|
|
252
271
|
this.content.style.height = height + PX;
|
|
253
272
|
}
|
|
254
|
-
this.bufferCanvas.setSize(width, height);
|
|
255
|
-
this.bufferHitCanvas.setSize(width, height);
|
|
256
273
|
this.children.forEach((layer) => {
|
|
257
274
|
layer.setSize({ width, height });
|
|
258
275
|
layer.draw();
|
|
259
276
|
});
|
|
260
277
|
}
|
|
278
|
+
_syncBufferSize(canvas) {
|
|
279
|
+
canvas.setSizeIfChanged(this.width(), this.height());
|
|
280
|
+
return canvas;
|
|
281
|
+
}
|
|
261
282
|
add(layer, ...rest) {
|
|
262
283
|
if (arguments.length > 1) {
|
|
263
284
|
for (let i = 0; i < arguments.length; i++) {
|
|
@@ -484,6 +505,8 @@ export class Stage extends Container {
|
|
|
484
505
|
return;
|
|
485
506
|
}
|
|
486
507
|
this.setPointersPositions(evt);
|
|
508
|
+
const wasDragged = DD.justDragged || (eventType === 'pointer' && Konva.isDragging());
|
|
509
|
+
const listenClick = Konva['_' + eventType + 'ListenClick'] && !wasDragged;
|
|
487
510
|
const clickStartShape = this[eventType + 'ClickStartShape'];
|
|
488
511
|
const clickEndShape = this[eventType + 'ClickEndShape'];
|
|
489
512
|
const processedShapesIds = {};
|
|
@@ -505,7 +528,7 @@ export class Stage extends Container {
|
|
|
505
528
|
fireDblClick = true;
|
|
506
529
|
clearTimeout(this[eventType + 'DblTimeout']);
|
|
507
530
|
}
|
|
508
|
-
else if (!
|
|
531
|
+
else if (!wasDragged) {
|
|
509
532
|
Konva['_' + eventType + 'InDblClickWindow'] = true;
|
|
510
533
|
clearTimeout(this[eventType + 'DblTimeout']);
|
|
511
534
|
}
|
|
@@ -516,9 +539,7 @@ export class Stage extends Container {
|
|
|
516
539
|
skipPointerUpTrigger = true;
|
|
517
540
|
this[eventType + 'ClickEndShape'] = shape;
|
|
518
541
|
shape._fireAndBubble(events.pointerup, { ...event });
|
|
519
|
-
if (
|
|
520
|
-
clickStartShape &&
|
|
521
|
-
clickStartShape === shape) {
|
|
542
|
+
if (listenClick && clickStartShape === shape) {
|
|
522
543
|
shape._fireAndBubble(events.pointerclick, { ...event });
|
|
523
544
|
if (fireDblClick && clickEndShape && clickEndShape === shape) {
|
|
524
545
|
shape._fireAndBubble(events.pointerdblclick, { ...event });
|
|
@@ -536,7 +557,7 @@ export class Stage extends Container {
|
|
|
536
557
|
});
|
|
537
558
|
skipPointerUpTrigger = true;
|
|
538
559
|
}
|
|
539
|
-
if (
|
|
560
|
+
if (listenClick) {
|
|
540
561
|
this._fire(events.pointerclick, {
|
|
541
562
|
evt: evt,
|
|
542
563
|
target: this,
|
|
@@ -665,13 +686,13 @@ export class Stage extends Container {
|
|
|
665
686
|
}
|
|
666
687
|
_buildDOM() {
|
|
667
688
|
this.bufferCanvas = new SceneCanvas({
|
|
668
|
-
width:
|
|
669
|
-
height:
|
|
689
|
+
width: 0,
|
|
690
|
+
height: 0,
|
|
670
691
|
});
|
|
671
692
|
this.bufferHitCanvas = new HitCanvas({
|
|
672
693
|
pixelRatio: 1,
|
|
673
|
-
width:
|
|
674
|
-
height:
|
|
694
|
+
width: 0,
|
|
695
|
+
height: 0,
|
|
675
696
|
});
|
|
676
697
|
if (!Konva.isBrowser) {
|
|
677
698
|
return;
|
|
@@ -681,12 +702,13 @@ export class Stage extends Container {
|
|
|
681
702
|
throw 'Stage has no container. A container is required.';
|
|
682
703
|
}
|
|
683
704
|
container.innerHTML = '';
|
|
684
|
-
this.content =
|
|
705
|
+
this.content = container.ownerDocument.createElement('div');
|
|
685
706
|
this.content.style.position = 'relative';
|
|
686
707
|
this.content.style.userSelect = 'none';
|
|
687
708
|
this.content.className = 'konvajs-content';
|
|
688
709
|
this.content.setAttribute('role', 'presentation');
|
|
689
710
|
container.appendChild(this.content);
|
|
711
|
+
listenToWindow(this._getOwnerWindow());
|
|
690
712
|
this._resizeDOM();
|
|
691
713
|
}
|
|
692
714
|
cache() {
|
|
@@ -706,10 +728,3 @@ export class Stage extends Container {
|
|
|
706
728
|
Stage.prototype.nodeType = STAGE;
|
|
707
729
|
_registerNode(Stage);
|
|
708
730
|
Factory.addGetterSetter(Stage, 'container');
|
|
709
|
-
if (Konva.isBrowser) {
|
|
710
|
-
document.addEventListener('visibilitychange', () => {
|
|
711
|
-
stages.forEach((stage) => {
|
|
712
|
-
stage.batchDraw();
|
|
713
|
-
});
|
|
714
|
-
});
|
|
715
|
-
}
|
package/lib/Tween.js
CHANGED
|
@@ -10,6 +10,12 @@ const blacklist = {
|
|
|
10
10
|
yoyo: 1,
|
|
11
11
|
}, PAUSED = 1, PLAYING = 2, REVERSING = 3, colorAttrs = ['fill', 'stroke', 'shadowColor'];
|
|
12
12
|
let idCounter = 0;
|
|
13
|
+
function colorToRGBA(color) {
|
|
14
|
+
return (Util.colorToRGBA(color) ||
|
|
15
|
+
Util.throw('can not tween the color "' +
|
|
16
|
+
color +
|
|
17
|
+
'", because it is not a valid color.'));
|
|
18
|
+
}
|
|
13
19
|
class TweenEngine {
|
|
14
20
|
constructor(prop, propFunc, func, begin, finish, duration, yoyo) {
|
|
15
21
|
this.prop = prop;
|
|
@@ -197,8 +203,8 @@ export class Tween {
|
|
|
197
203
|
diff.push(end[n] - start[n]);
|
|
198
204
|
}
|
|
199
205
|
else {
|
|
200
|
-
const startRGBA =
|
|
201
|
-
endRGBA =
|
|
206
|
+
const startRGBA = colorToRGBA(start[n]);
|
|
207
|
+
endRGBA = colorToRGBA(end[n]);
|
|
202
208
|
start[n] = startRGBA;
|
|
203
209
|
diff.push({
|
|
204
210
|
r: endRGBA.r - startRGBA.r,
|
|
@@ -216,8 +222,8 @@ export class Tween {
|
|
|
216
222
|
}
|
|
217
223
|
}
|
|
218
224
|
else if (colorAttrs.indexOf(key) !== -1) {
|
|
219
|
-
start =
|
|
220
|
-
endRGBA =
|
|
225
|
+
start = colorToRGBA(start);
|
|
226
|
+
endRGBA = colorToRGBA(end);
|
|
221
227
|
diff = {
|
|
222
228
|
r: endRGBA.r - start.r,
|
|
223
229
|
g: endRGBA.g - start.g,
|
package/lib/Util.d.ts
CHANGED
|
@@ -43,7 +43,7 @@ export declare const Util: {
|
|
|
43
43
|
isObject(val: any): val is object;
|
|
44
44
|
isValidSelector(selector: any): boolean;
|
|
45
45
|
_sign(number: number): 1 | -1;
|
|
46
|
-
requestAnimFrame(callback: Function): void;
|
|
46
|
+
requestAnimFrame(callback: Function, win?: Window | null): void;
|
|
47
47
|
createCanvasElement(): HTMLCanvasElement;
|
|
48
48
|
createImageElement(): HTMLImageElement;
|
|
49
49
|
_isInDocument(el: any): boolean;
|
|
@@ -74,12 +74,6 @@ export declare const Util: {
|
|
|
74
74
|
b: number;
|
|
75
75
|
a: number;
|
|
76
76
|
} | undefined;
|
|
77
|
-
_rgbaColorToRGBA(str: string): {
|
|
78
|
-
r: number;
|
|
79
|
-
g: number;
|
|
80
|
-
b: number;
|
|
81
|
-
a: number;
|
|
82
|
-
} | undefined;
|
|
83
77
|
_hex8ColorToRGBA(str: string): {
|
|
84
78
|
r: number;
|
|
85
79
|
g: number;
|
package/lib/Util.js
CHANGED
|
@@ -165,7 +165,7 @@ export class Transform {
|
|
|
165
165
|
return result;
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
|
-
const OBJECT_ARRAY = '[object Array]', OBJECT_NUMBER = '[object Number]', OBJECT_STRING = '[object String]', OBJECT_BOOLEAN = '[object Boolean]', PI_OVER_DEG180 = Math.PI / 180, DEG180_OVER_PI = 180 / Math.PI, HASH = '#', EMPTY_STRING = '', ZERO = '0', KONVA_WARNING = 'Konva warning: ', KONVA_ERROR = 'Konva error: ',
|
|
168
|
+
const OBJECT_ARRAY = '[object Array]', OBJECT_NUMBER = '[object Number]', OBJECT_STRING = '[object String]', OBJECT_BOOLEAN = '[object Boolean]', PI_OVER_DEG180 = Math.PI / 180, DEG180_OVER_PI = 180 / Math.PI, HASH = '#', EMPTY_STRING = '', ZERO = '0', KONVA_WARNING = 'Konva warning: ', KONVA_ERROR = 'Konva error: ', COLORS = {
|
|
169
169
|
aliceblue: [240, 248, 255],
|
|
170
170
|
antiquewhite: [250, 235, 215],
|
|
171
171
|
aqua: [0, 255, 255],
|
|
@@ -189,7 +189,7 @@ const OBJECT_ARRAY = '[object Array]', OBJECT_NUMBER = '[object Number]', OBJECT
|
|
|
189
189
|
cyan: [0, 255, 255],
|
|
190
190
|
darkblue: [0, 0, 139],
|
|
191
191
|
darkcyan: [0, 139, 139],
|
|
192
|
-
darkgoldenrod: [184,
|
|
192
|
+
darkgoldenrod: [184, 134, 11],
|
|
193
193
|
darkgray: [169, 169, 169],
|
|
194
194
|
darkgreen: [0, 100, 0],
|
|
195
195
|
darkgrey: [169, 169, 169],
|
|
@@ -212,7 +212,7 @@ const OBJECT_ARRAY = '[object Array]', OBJECT_NUMBER = '[object Number]', OBJECT
|
|
|
212
212
|
dimgrey: [105, 105, 105],
|
|
213
213
|
dodgerblue: [30, 144, 255],
|
|
214
214
|
firebrick: [178, 34, 34],
|
|
215
|
-
floralwhite: [255,
|
|
215
|
+
floralwhite: [255, 250, 240],
|
|
216
216
|
forestgreen: [34, 139, 34],
|
|
217
217
|
fuchsia: [255, 0, 255],
|
|
218
218
|
gainsboro: [220, 220, 220],
|
|
@@ -282,7 +282,7 @@ const OBJECT_ARRAY = '[object Array]', OBJECT_NUMBER = '[object Number]', OBJECT
|
|
|
282
282
|
peachpuff: [255, 218, 185],
|
|
283
283
|
peru: [205, 133, 63],
|
|
284
284
|
pink: [255, 192, 203],
|
|
285
|
-
plum: [221, 160,
|
|
285
|
+
plum: [221, 160, 221],
|
|
286
286
|
powderblue: [176, 224, 230],
|
|
287
287
|
purple: [128, 0, 128],
|
|
288
288
|
rebeccapurple: [102, 51, 153],
|
|
@@ -298,9 +298,9 @@ const OBJECT_ARRAY = '[object Array]', OBJECT_NUMBER = '[object Number]', OBJECT
|
|
|
298
298
|
silver: [192, 192, 192],
|
|
299
299
|
skyblue: [135, 206, 235],
|
|
300
300
|
slateblue: [106, 90, 205],
|
|
301
|
-
slategray: [
|
|
302
|
-
slategrey: [
|
|
303
|
-
snow: [255,
|
|
301
|
+
slategray: [112, 128, 144],
|
|
302
|
+
slategrey: [112, 128, 144],
|
|
303
|
+
snow: [255, 250, 250],
|
|
304
304
|
springgreen: [0, 255, 127],
|
|
305
305
|
steelblue: [70, 130, 180],
|
|
306
306
|
tan: [210, 180, 140],
|
|
@@ -314,14 +314,47 @@ const OBJECT_ARRAY = '[object Array]', OBJECT_NUMBER = '[object Number]', OBJECT
|
|
|
314
314
|
white: [255, 255, 255],
|
|
315
315
|
whitesmoke: [245, 245, 245],
|
|
316
316
|
yellow: [255, 255, 0],
|
|
317
|
-
yellowgreen: [154, 205,
|
|
318
|
-
}
|
|
319
|
-
let animQueue = [];
|
|
317
|
+
yellowgreen: [154, 205, 50],
|
|
318
|
+
};
|
|
320
319
|
let _isCanvasFarblingActive = null;
|
|
321
|
-
const
|
|
322
|
-
|
|
320
|
+
const defaultWindow = typeof window !== 'undefined' ? window : {};
|
|
321
|
+
const animQueues = new WeakMap();
|
|
322
|
+
const requestFrame = (win, f) => {
|
|
323
|
+
if (typeof win.requestAnimationFrame === 'function') {
|
|
324
|
+
win.requestAnimationFrame(f);
|
|
325
|
+
}
|
|
326
|
+
else if (typeof requestAnimationFrame !== 'undefined') {
|
|
327
|
+
requestAnimationFrame(f);
|
|
328
|
+
}
|
|
329
|
+
else {
|
|
323
330
|
setTimeout(f, 16);
|
|
324
|
-
}
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
const capitalizeCache = new Map();
|
|
334
|
+
const splitColorComponents = (str) => {
|
|
335
|
+
const components = str.trim();
|
|
336
|
+
return components.indexOf(',') === -1
|
|
337
|
+
? components.split(/\s*\/\s*|\s+/)
|
|
338
|
+
: components.split(/\s*,\s*/);
|
|
339
|
+
};
|
|
340
|
+
const NUMBER_SOURCE = '[+-]?(?:\\d+\\.?\\d*|\\.\\d+)(?:e[+-]?\\d+)?';
|
|
341
|
+
const COLOR_COMPONENT_REGEX = new RegExp(`^(${NUMBER_SOURCE})(%?)$`, 'i');
|
|
342
|
+
const parseColorComponent = (value, max) => {
|
|
343
|
+
const match = COLOR_COMPONENT_REGEX.exec(value);
|
|
344
|
+
if (!match) {
|
|
345
|
+
return NaN;
|
|
346
|
+
}
|
|
347
|
+
return match[2] ? (Number(match[1]) / 100) * max : Number(match[1]);
|
|
348
|
+
};
|
|
349
|
+
const HEX_COLOR_REGEX = /^#[0-9a-f]+$/i;
|
|
350
|
+
const clamp01 = (value) => Math.min(Math.max(value, 0), 1);
|
|
351
|
+
const HUE_REGEX = new RegExp(`^(${NUMBER_SOURCE})(deg|grad|rad|turn)?$`, 'i');
|
|
352
|
+
const HUE_UNITS = {
|
|
353
|
+
deg: 1,
|
|
354
|
+
grad: 0.9,
|
|
355
|
+
rad: DEG180_OVER_PI,
|
|
356
|
+
turn: 360,
|
|
357
|
+
};
|
|
325
358
|
export const Util = {
|
|
326
359
|
_isElement(obj) {
|
|
327
360
|
return !!(obj && obj.nodeType == 1);
|
|
@@ -369,17 +402,20 @@ export const Util = {
|
|
|
369
402
|
return -1;
|
|
370
403
|
}
|
|
371
404
|
},
|
|
372
|
-
requestAnimFrame(callback) {
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
405
|
+
requestAnimFrame(callback, win) {
|
|
406
|
+
const target = (win && !win.closed && win) || defaultWindow;
|
|
407
|
+
let queue = animQueues.get(target);
|
|
408
|
+
if (!queue) {
|
|
409
|
+
queue = [];
|
|
410
|
+
animQueues.set(target, queue);
|
|
411
|
+
requestFrame(target, function () {
|
|
412
|
+
animQueues.delete(target);
|
|
378
413
|
queue.forEach(function (cb) {
|
|
379
414
|
cb();
|
|
380
415
|
});
|
|
381
416
|
});
|
|
382
417
|
}
|
|
418
|
+
queue.push(callback);
|
|
383
419
|
},
|
|
384
420
|
createCanvasElement() {
|
|
385
421
|
ensureBrowser();
|
|
@@ -395,12 +431,7 @@ export const Util = {
|
|
|
395
431
|
return document.createElement('img');
|
|
396
432
|
},
|
|
397
433
|
_isInDocument(el) {
|
|
398
|
-
|
|
399
|
-
if (el == document) {
|
|
400
|
-
return true;
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
return false;
|
|
434
|
+
return !!el.isConnected;
|
|
404
435
|
},
|
|
405
436
|
_urlToImage(url, callback) {
|
|
406
437
|
const imageObj = Util.createImageElement();
|
|
@@ -480,44 +511,22 @@ export const Util = {
|
|
|
480
511
|
this._rgbToHex(Math.round(rgb.r / 5) * 5, Math.round(rgb.g / 5) * 5, Math.round(rgb.b / 5) * 5));
|
|
481
512
|
},
|
|
482
513
|
getRGB(color) {
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
return {
|
|
487
|
-
r: rgb[0],
|
|
488
|
-
g: rgb[1],
|
|
489
|
-
b: rgb[2],
|
|
490
|
-
};
|
|
491
|
-
}
|
|
492
|
-
else if (color[0] === HASH) {
|
|
493
|
-
return this._hexToRgb(color.substring(1));
|
|
494
|
-
}
|
|
495
|
-
else if (color.substr(0, 4) === RGB_PAREN) {
|
|
496
|
-
rgb = RGB_REGEX.exec(color.replace(/ /g, ''));
|
|
497
|
-
return {
|
|
498
|
-
r: parseInt(rgb[1], 10),
|
|
499
|
-
g: parseInt(rgb[2], 10),
|
|
500
|
-
b: parseInt(rgb[3], 10),
|
|
501
|
-
};
|
|
502
|
-
}
|
|
503
|
-
else {
|
|
504
|
-
return {
|
|
505
|
-
r: 0,
|
|
506
|
-
g: 0,
|
|
507
|
-
b: 0,
|
|
508
|
-
};
|
|
509
|
-
}
|
|
514
|
+
var _a;
|
|
515
|
+
const { r = 0, g = 0, b = 0 } = (_a = Util.colorToRGBA(color)) !== null && _a !== void 0 ? _a : {};
|
|
516
|
+
return { r, g, b };
|
|
510
517
|
},
|
|
511
518
|
colorToRGBA(str) {
|
|
512
|
-
str = str || 'black';
|
|
513
|
-
|
|
519
|
+
str = (str || '').trim() || 'black';
|
|
520
|
+
const color = Util._namedColorToRBA(str) ||
|
|
514
521
|
Util._hex3ColorToRGBA(str) ||
|
|
515
522
|
Util._hex4ColorToRGBA(str) ||
|
|
516
523
|
Util._hex6ColorToRGBA(str) ||
|
|
517
524
|
Util._hex8ColorToRGBA(str) ||
|
|
518
525
|
Util._rgbColorToRGBA(str) ||
|
|
519
|
-
Util.
|
|
520
|
-
|
|
526
|
+
Util._hslColorToRGBA(str);
|
|
527
|
+
if (color && [color.r, color.g, color.b, color.a].every(Util._isNumber)) {
|
|
528
|
+
return color;
|
|
529
|
+
}
|
|
521
530
|
},
|
|
522
531
|
_namedColorToRBA(str) {
|
|
523
532
|
const c = COLORS[str.toLowerCase()];
|
|
@@ -528,40 +537,27 @@ export const Util = {
|
|
|
528
537
|
r: c[0],
|
|
529
538
|
g: c[1],
|
|
530
539
|
b: c[2],
|
|
531
|
-
a: 1,
|
|
540
|
+
a: c.length > 3 ? c[3] : 1,
|
|
532
541
|
};
|
|
533
542
|
},
|
|
534
543
|
_rgbColorToRGBA(str) {
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
return {
|
|
539
|
-
r: parts[0],
|
|
540
|
-
g: parts[1],
|
|
541
|
-
b: parts[2],
|
|
542
|
-
a: 1,
|
|
543
|
-
};
|
|
544
|
+
const match = /^rgba?\(([^)]*)\)$/i.exec(str);
|
|
545
|
+
if (!match) {
|
|
546
|
+
return;
|
|
544
547
|
}
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
str = str.match(/rgba\(([^)]+)\)/)[1];
|
|
549
|
-
const parts = str.split(/ *, */).map((n, index) => {
|
|
550
|
-
if (n.slice(-1) === '%') {
|
|
551
|
-
return index === 3 ? parseInt(n) / 100 : (parseInt(n) / 100) * 255;
|
|
552
|
-
}
|
|
553
|
-
return Number(n);
|
|
554
|
-
});
|
|
555
|
-
return {
|
|
556
|
-
r: parts[0],
|
|
557
|
-
g: parts[1],
|
|
558
|
-
b: parts[2],
|
|
559
|
-
a: parts[3],
|
|
560
|
-
};
|
|
548
|
+
const parts = splitColorComponents(match[1]);
|
|
549
|
+
if (parts.length < 3 || parts.length > 4) {
|
|
550
|
+
return;
|
|
561
551
|
}
|
|
552
|
+
return {
|
|
553
|
+
r: parseColorComponent(parts[0], 255),
|
|
554
|
+
g: parseColorComponent(parts[1], 255),
|
|
555
|
+
b: parseColorComponent(parts[2], 255),
|
|
556
|
+
a: parts.length > 3 ? parseColorComponent(parts[3], 1) : 1,
|
|
557
|
+
};
|
|
562
558
|
},
|
|
563
559
|
_hex8ColorToRGBA(str) {
|
|
564
|
-
if (str
|
|
560
|
+
if (str.length === 9 && HEX_COLOR_REGEX.test(str)) {
|
|
565
561
|
return {
|
|
566
562
|
r: parseInt(str.slice(1, 3), 16),
|
|
567
563
|
g: parseInt(str.slice(3, 5), 16),
|
|
@@ -571,7 +567,7 @@ export const Util = {
|
|
|
571
567
|
}
|
|
572
568
|
},
|
|
573
569
|
_hex6ColorToRGBA(str) {
|
|
574
|
-
if (str
|
|
570
|
+
if (str.length === 7 && HEX_COLOR_REGEX.test(str)) {
|
|
575
571
|
return {
|
|
576
572
|
r: parseInt(str.slice(1, 3), 16),
|
|
577
573
|
g: parseInt(str.slice(3, 5), 16),
|
|
@@ -581,7 +577,7 @@ export const Util = {
|
|
|
581
577
|
}
|
|
582
578
|
},
|
|
583
579
|
_hex4ColorToRGBA(str) {
|
|
584
|
-
if (str
|
|
580
|
+
if (str.length === 5 && HEX_COLOR_REGEX.test(str)) {
|
|
585
581
|
return {
|
|
586
582
|
r: parseInt(str[1] + str[1], 16),
|
|
587
583
|
g: parseInt(str[2] + str[2], 16),
|
|
@@ -591,7 +587,7 @@ export const Util = {
|
|
|
591
587
|
}
|
|
592
588
|
},
|
|
593
589
|
_hex3ColorToRGBA(str) {
|
|
594
|
-
if (str
|
|
590
|
+
if (str.length === 4 && HEX_COLOR_REGEX.test(str)) {
|
|
595
591
|
return {
|
|
596
592
|
r: parseInt(str[1] + str[1], 16),
|
|
597
593
|
g: parseInt(str[2] + str[2], 16),
|
|
@@ -601,60 +597,59 @@ export const Util = {
|
|
|
601
597
|
}
|
|
602
598
|
},
|
|
603
599
|
_hslColorToRGBA(str) {
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
600
|
+
const match = /^hsla?\(([^)]*)\)$/i.exec(str);
|
|
601
|
+
if (!match) {
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
604
|
+
const parts = splitColorComponents(match[1]);
|
|
605
|
+
if (parts.length < 3 || parts.length > 4) {
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
const hue = HUE_REGEX.exec(parts[0]);
|
|
609
|
+
if (!hue) {
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
const unit = hue[2];
|
|
613
|
+
const degrees = Number(hue[1]) * (unit ? HUE_UNITS[unit.toLowerCase()] : 1);
|
|
614
|
+
if (!isFinite(degrees)) {
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
617
|
+
const h = (((degrees % 360) + 360) % 360) / 360;
|
|
618
|
+
const s = clamp01(parseColorComponent(parts[1], 100) / 100);
|
|
619
|
+
const l = clamp01(parseColorComponent(parts[2], 100) / 100);
|
|
620
|
+
const a = parts.length > 3 ? parseColorComponent(parts[3], 1) : 1;
|
|
621
|
+
const t2 = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
|
622
|
+
const t1 = 2 * l - t2;
|
|
623
|
+
const rgb = [0, 0, 0];
|
|
624
|
+
for (let i = 0; i < 3; i++) {
|
|
625
|
+
let t3 = h + (1 / 3) * -(i - 1);
|
|
626
|
+
if (t3 < 0) {
|
|
627
|
+
t3++;
|
|
628
|
+
}
|
|
629
|
+
if (t3 > 1) {
|
|
630
|
+
t3--;
|
|
631
|
+
}
|
|
611
632
|
let val;
|
|
612
|
-
if (
|
|
613
|
-
val =
|
|
614
|
-
return {
|
|
615
|
-
r: Math.round(val),
|
|
616
|
-
g: Math.round(val),
|
|
617
|
-
b: Math.round(val),
|
|
618
|
-
a: 1,
|
|
619
|
-
};
|
|
633
|
+
if (6 * t3 < 1) {
|
|
634
|
+
val = t1 + (t2 - t1) * 6 * t3;
|
|
620
635
|
}
|
|
621
|
-
if (
|
|
622
|
-
|
|
636
|
+
else if (2 * t3 < 1) {
|
|
637
|
+
val = t2;
|
|
623
638
|
}
|
|
624
|
-
else {
|
|
625
|
-
|
|
639
|
+
else if (3 * t3 < 2) {
|
|
640
|
+
val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
|
|
626
641
|
}
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
for (let i = 0; i < 3; i++) {
|
|
630
|
-
t3 = h + (1 / 3) * -(i - 1);
|
|
631
|
-
if (t3 < 0) {
|
|
632
|
-
t3++;
|
|
633
|
-
}
|
|
634
|
-
if (t3 > 1) {
|
|
635
|
-
t3--;
|
|
636
|
-
}
|
|
637
|
-
if (6 * t3 < 1) {
|
|
638
|
-
val = t1 + (t2 - t1) * 6 * t3;
|
|
639
|
-
}
|
|
640
|
-
else if (2 * t3 < 1) {
|
|
641
|
-
val = t2;
|
|
642
|
-
}
|
|
643
|
-
else if (3 * t3 < 2) {
|
|
644
|
-
val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
|
|
645
|
-
}
|
|
646
|
-
else {
|
|
647
|
-
val = t1;
|
|
648
|
-
}
|
|
649
|
-
rgb[i] = val * 255;
|
|
642
|
+
else {
|
|
643
|
+
val = t1;
|
|
650
644
|
}
|
|
651
|
-
|
|
652
|
-
r: Math.round(rgb[0]),
|
|
653
|
-
g: Math.round(rgb[1]),
|
|
654
|
-
b: Math.round(rgb[2]),
|
|
655
|
-
a: 1,
|
|
656
|
-
};
|
|
645
|
+
rgb[i] = val * 255;
|
|
657
646
|
}
|
|
647
|
+
return {
|
|
648
|
+
r: Math.round(rgb[0]),
|
|
649
|
+
g: Math.round(rgb[1]),
|
|
650
|
+
b: Math.round(rgb[2]),
|
|
651
|
+
a,
|
|
652
|
+
};
|
|
658
653
|
},
|
|
659
654
|
haveIntersection(r1, r2) {
|
|
660
655
|
return !(r2.x > r1.x + r1.width ||
|
|
@@ -698,7 +693,12 @@ export const Util = {
|
|
|
698
693
|
return Konva.angleDeg ? Util.radToDeg(radians) : radians;
|
|
699
694
|
},
|
|
700
695
|
_capitalize(str) {
|
|
701
|
-
|
|
696
|
+
const cached = capitalizeCache.get(str);
|
|
697
|
+
if (cached !== undefined)
|
|
698
|
+
return cached;
|
|
699
|
+
const out = str.charAt(0).toUpperCase() + str.slice(1);
|
|
700
|
+
capitalizeCache.set(str, out);
|
|
701
|
+
return out;
|
|
702
702
|
},
|
|
703
703
|
throw(str) {
|
|
704
704
|
throw new Error(KONVA_ERROR + str);
|
package/lib/_CoreInternals.d.ts
CHANGED
|
@@ -56,7 +56,7 @@ export declare const Konva: {
|
|
|
56
56
|
isObject(val: any): val is object;
|
|
57
57
|
isValidSelector(selector: any): boolean;
|
|
58
58
|
_sign(number: number): 1 | -1;
|
|
59
|
-
requestAnimFrame(callback: Function): void;
|
|
59
|
+
requestAnimFrame(callback: Function, win?: Window | null): void;
|
|
60
60
|
createCanvasElement(): HTMLCanvasElement;
|
|
61
61
|
createImageElement(): HTMLImageElement;
|
|
62
62
|
_isInDocument(el: any): boolean;
|
|
@@ -87,12 +87,6 @@ export declare const Konva: {
|
|
|
87
87
|
b: number;
|
|
88
88
|
a: number;
|
|
89
89
|
} | undefined;
|
|
90
|
-
_rgbaColorToRGBA(str: string): {
|
|
91
|
-
r: number;
|
|
92
|
-
g: number;
|
|
93
|
-
b: number;
|
|
94
|
-
a: number;
|
|
95
|
-
} | undefined;
|
|
96
90
|
_hex8ColorToRGBA(str: string): {
|
|
97
91
|
r: number;
|
|
98
92
|
g: number;
|
|
@@ -167,8 +161,9 @@ export declare const Konva: {
|
|
|
167
161
|
startEvent?: any;
|
|
168
162
|
dragStatus: "ready" | "dragging" | "stopped";
|
|
169
163
|
}>;
|
|
170
|
-
|
|
171
|
-
|
|
164
|
+
_listenToWindow(win: Window): void;
|
|
165
|
+
_drag(evt: any, win?: Window): void;
|
|
166
|
+
_endDragBefore(evt?: any, win?: Window): void;
|
|
172
167
|
_endDragAfter(evt: any): void;
|
|
173
168
|
};
|
|
174
169
|
Shape: typeof Shape;
|
package/lib/_FullInternals.d.ts
CHANGED
|
@@ -62,7 +62,7 @@ export declare const Konva: {
|
|
|
62
62
|
isObject(val: any): val is object;
|
|
63
63
|
isValidSelector(selector: any): boolean;
|
|
64
64
|
_sign(number: number): 1 | -1;
|
|
65
|
-
requestAnimFrame(callback: Function): void;
|
|
65
|
+
requestAnimFrame(callback: Function, win?: Window | null): void;
|
|
66
66
|
createCanvasElement(): HTMLCanvasElement;
|
|
67
67
|
createImageElement(): HTMLImageElement;
|
|
68
68
|
_isInDocument(el: any): boolean;
|
|
@@ -93,12 +93,6 @@ export declare const Konva: {
|
|
|
93
93
|
b: number;
|
|
94
94
|
a: number;
|
|
95
95
|
} | undefined;
|
|
96
|
-
_rgbaColorToRGBA(str: string): {
|
|
97
|
-
r: number;
|
|
98
|
-
g: number;
|
|
99
|
-
b: number;
|
|
100
|
-
a: number;
|
|
101
|
-
} | undefined;
|
|
102
96
|
_hex8ColorToRGBA(str: string): {
|
|
103
97
|
r: number;
|
|
104
98
|
g: number;
|
|
@@ -173,8 +167,9 @@ export declare const Konva: {
|
|
|
173
167
|
startEvent?: any;
|
|
174
168
|
dragStatus: "ready" | "dragging" | "stopped";
|
|
175
169
|
}>;
|
|
176
|
-
|
|
177
|
-
|
|
170
|
+
_listenToWindow(win: Window): void;
|
|
171
|
+
_drag(evt: any, win?: Window): void;
|
|
172
|
+
_endDragBefore(evt?: any, win?: Window): void;
|
|
178
173
|
_endDragAfter(evt: any): void;
|
|
179
174
|
};
|
|
180
175
|
Shape: typeof import("./Shape.ts").Shape;
|
package/lib/shapes/Arc.js
CHANGED
|
@@ -28,6 +28,17 @@ export class Arc extends Shape {
|
|
|
28
28
|
const innerRadius = this.innerRadius();
|
|
29
29
|
const outerRadius = this.outerRadius();
|
|
30
30
|
const clockwise = this.clockwise();
|
|
31
|
+
const rawAngle = Konva.getAngle(this.angle());
|
|
32
|
+
if (rawAngle % (Math.PI * 2) === 0) {
|
|
33
|
+
return rawAngle !== 0
|
|
34
|
+
? {
|
|
35
|
+
x: -outerRadius,
|
|
36
|
+
y: -outerRadius,
|
|
37
|
+
width: outerRadius * 2,
|
|
38
|
+
height: outerRadius * 2,
|
|
39
|
+
}
|
|
40
|
+
: { x: innerRadius, y: 0, width: outerRadius - innerRadius, height: 0 };
|
|
41
|
+
}
|
|
31
42
|
const angle = Konva.getAngle(clockwise ? 360 - this.angle() : this.angle());
|
|
32
43
|
const boundLeftRatio = Math.cos(Math.min(angle, Math.PI));
|
|
33
44
|
const boundRightRatio = 1;
|