konva 10.6.0 → 10.7.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 +12 -8
- package/konva.js +533 -230
- package/konva.min.js +4 -4
- package/lib/Canvas.d.ts +9 -2
- package/lib/Canvas.js +83 -5
- package/lib/Container.d.ts +3 -2
- package/lib/Container.js +23 -12
- package/lib/Context.d.ts +5 -2
- package/lib/Context.js +22 -1
- package/lib/Global.d.ts +2 -1
- package/lib/Global.js +8 -3
- package/lib/Group.d.ts +7 -1
- package/lib/Group.js +61 -0
- package/lib/Layer.d.ts +1 -1
- package/lib/Layer.js +4 -2
- package/lib/Node.d.ts +4 -7
- package/lib/Node.js +19 -43
- package/lib/Shape.d.ts +9 -15
- package/lib/Shape.js +145 -85
- package/lib/Stage.d.ts +0 -2
- package/lib/Stage.js +2 -13
- package/lib/Util.d.ts +1 -0
- package/lib/Util.js +25 -0
- package/lib/shapes/Arc.js +3 -3
- package/lib/shapes/Arrow.d.ts +1 -0
- package/lib/shapes/Arrow.js +7 -1
- package/lib/shapes/Circle.d.ts +1 -0
- package/lib/shapes/Circle.js +4 -1
- package/lib/shapes/Ellipse.d.ts +1 -0
- package/lib/shapes/Ellipse.js +4 -1
- package/lib/shapes/Image.d.ts +2 -1
- package/lib/shapes/Image.js +6 -3
- package/lib/shapes/Label.js +18 -20
- package/lib/shapes/Line.d.ts +1 -0
- package/lib/shapes/Line.js +4 -1
- package/lib/shapes/Path.js +1 -1
- package/lib/shapes/Rect.d.ts +1 -0
- package/lib/shapes/Rect.js +4 -1
- package/lib/shapes/RegularPolygon.js +1 -1
- package/lib/shapes/Ring.d.ts +7 -0
- package/lib/shapes/Ring.js +8 -1
- package/lib/shapes/Sprite.d.ts +2 -1
- package/lib/shapes/Sprite.js +6 -3
- package/lib/shapes/Star.d.ts +6 -0
- package/lib/shapes/Star.js +5 -1
- package/lib/shapes/Text.d.ts +5 -2
- package/lib/shapes/Text.js +49 -22
- package/lib/shapes/TextPath.d.ts +7 -0
- package/lib/shapes/TextPath.js +16 -1
- package/lib/shapes/Transformer.js +7 -5
- package/lib/shapes/Wedge.js +1 -1
- package/package.json +2 -18
package/konva.js
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
})(this, (function () { 'use strict';
|
|
6
6
|
|
|
7
7
|
/*
|
|
8
|
-
* Konva JavaScript Framework v10.
|
|
8
|
+
* Konva JavaScript Framework v10.7.0
|
|
9
9
|
* http://konvajs.org/
|
|
10
10
|
* Licensed under the MIT
|
|
11
|
-
* Date:
|
|
11
|
+
* Date: Wed Sep 23 2026
|
|
12
12
|
*
|
|
13
13
|
* Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
|
|
14
14
|
* Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva)
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
: {};
|
|
36
36
|
const Konva$2 = {
|
|
37
37
|
_global: glob,
|
|
38
|
-
version: '10.
|
|
38
|
+
version: '10.7.0',
|
|
39
39
|
isBrowser: detectBrowser(),
|
|
40
40
|
isUnminified: /param/.test(function (param) { }.toString()),
|
|
41
41
|
dblClickWindow: 400,
|
|
@@ -189,8 +189,13 @@
|
|
|
189
189
|
glob.Konva = Konva;
|
|
190
190
|
},
|
|
191
191
|
};
|
|
192
|
-
|
|
192
|
+
// Konva's own shapes whose bounds cover everything they paint. Plugins can
|
|
193
|
+
// import _registerNode, so they opt in explicitly.
|
|
194
|
+
const _boundedShapes = new Set();
|
|
195
|
+
const _registerNode = (NodeClass, boundsCoverPaint = false) => {
|
|
193
196
|
Konva$2[NodeClass.prototype.getClassName()] = NodeClass;
|
|
197
|
+
if (boundsCoverPaint)
|
|
198
|
+
_boundedShapes.add(NodeClass);
|
|
194
199
|
};
|
|
195
200
|
Konva$2._injectGlobal(Konva$2);
|
|
196
201
|
|
|
@@ -282,6 +287,31 @@ js: import "konva/skia-backend";
|
|
|
282
287
|
y: m[1] * point.x + m[3] * point.y + m[5],
|
|
283
288
|
};
|
|
284
289
|
}
|
|
290
|
+
// Axis-aligned bounds of a rectangle after this transform.
|
|
291
|
+
_getTransformedRect(rect) {
|
|
292
|
+
const [a, b, c, d, e, f] = this.m;
|
|
293
|
+
const x1 = rect.x, y1 = rect.y, x2 = rect.x + rect.width, y2 = rect.y + rect.height;
|
|
294
|
+
const xs = [
|
|
295
|
+
a * x1 + c * y1 + e,
|
|
296
|
+
a * x2 + c * y1 + e,
|
|
297
|
+
a * x2 + c * y2 + e,
|
|
298
|
+
a * x1 + c * y2 + e,
|
|
299
|
+
];
|
|
300
|
+
const ys = [
|
|
301
|
+
b * x1 + d * y1 + f,
|
|
302
|
+
b * x2 + d * y1 + f,
|
|
303
|
+
b * x2 + d * y2 + f,
|
|
304
|
+
b * x1 + d * y2 + f,
|
|
305
|
+
];
|
|
306
|
+
const minX = Math.min(xs[0], xs[1], xs[2], xs[3]);
|
|
307
|
+
const minY = Math.min(ys[0], ys[1], ys[2], ys[3]);
|
|
308
|
+
return {
|
|
309
|
+
x: minX,
|
|
310
|
+
y: minY,
|
|
311
|
+
width: Math.max(xs[0], xs[1], xs[2], xs[3]) - minX,
|
|
312
|
+
height: Math.max(ys[0], ys[1], ys[2], ys[3]) - minY,
|
|
313
|
+
};
|
|
314
|
+
}
|
|
285
315
|
/**
|
|
286
316
|
* Apply translation
|
|
287
317
|
* @method
|
|
@@ -1459,6 +1489,7 @@ js: import "konva/skia-backend";
|
|
|
1459
1489
|
'globalAlpha',
|
|
1460
1490
|
'globalCompositeOperation',
|
|
1461
1491
|
'imageSmoothingEnabled',
|
|
1492
|
+
'imageSmoothingQuality',
|
|
1462
1493
|
'filter',
|
|
1463
1494
|
];
|
|
1464
1495
|
const traceArrMax = 100;
|
|
@@ -1631,14 +1662,34 @@ js: import "konva/skia-backend";
|
|
|
1631
1662
|
this.clearRect(0, 0, canvas.getWidth() / canvas.pixelRatio, canvas.getHeight() / canvas.pixelRatio);
|
|
1632
1663
|
}
|
|
1633
1664
|
}
|
|
1665
|
+
// Copy a buffer already rasterized in destination pixels. The caller owns
|
|
1666
|
+
// save/restore, opacity, compositing and the destination clip.
|
|
1667
|
+
_drawDeviceBuffer(canvas) {
|
|
1668
|
+
const { x, y, width, height } = canvas._isolationRect;
|
|
1669
|
+
this.setTransform(1, 0, 0, 1, 0, 0);
|
|
1670
|
+
this.imageSmoothingEnabled = false;
|
|
1671
|
+
this.drawImage(canvas._canvas, 0, 0, width, height, x, y, width, height);
|
|
1672
|
+
}
|
|
1634
1673
|
_applyLineCap(shape) {
|
|
1635
1674
|
const lineCap = shape.attrs.lineCap;
|
|
1636
1675
|
if (lineCap) {
|
|
1637
1676
|
this.setAttr('lineCap', lineCap);
|
|
1638
1677
|
}
|
|
1639
1678
|
}
|
|
1679
|
+
_getOpacity(shape) {
|
|
1680
|
+
if (!this._opacityRoot) {
|
|
1681
|
+
return shape.getAbsoluteOpacity();
|
|
1682
|
+
}
|
|
1683
|
+
let opacity = shape.opacity();
|
|
1684
|
+
let parent = shape.parent;
|
|
1685
|
+
while (parent && parent !== this._opacityRoot) {
|
|
1686
|
+
opacity *= parent.opacity();
|
|
1687
|
+
parent = parent.parent;
|
|
1688
|
+
}
|
|
1689
|
+
return opacity;
|
|
1690
|
+
}
|
|
1640
1691
|
_applyOpacity(shape) {
|
|
1641
|
-
const absOpacity =
|
|
1692
|
+
const absOpacity = this._getOpacity(shape);
|
|
1642
1693
|
if (absOpacity !== 1) {
|
|
1643
1694
|
this.setAttr('globalAlpha', absOpacity);
|
|
1644
1695
|
}
|
|
@@ -2217,10 +2268,6 @@ js: import "konva/skia-backend";
|
|
|
2217
2268
|
this._logicalWidth = 0;
|
|
2218
2269
|
this._logicalHeight = 0;
|
|
2219
2270
|
this.isCache = false;
|
|
2220
|
-
// origin of a buffer canvas in the coordinate space of the canvas it is
|
|
2221
|
-
// drawn back into, see Shape.drawScene
|
|
2222
|
-
this.x = 0;
|
|
2223
|
-
this.y = 0;
|
|
2224
2271
|
const conf = config || {};
|
|
2225
2272
|
// a Konva.pixelRatio reset to undefined or 0 means the device ratio
|
|
2226
2273
|
const pixelRatio = conf.pixelRatio ||
|
|
@@ -2351,8 +2398,90 @@ js: import "konva/skia-backend";
|
|
|
2351
2398
|
}
|
|
2352
2399
|
}
|
|
2353
2400
|
class SceneCanvas extends Canvas {
|
|
2401
|
+
// A cleared surface over `rect` (in the current drawing space), or over the
|
|
2402
|
+
// whole canvas, in this canvas's device pixels. Siblings reuse it; nested
|
|
2403
|
+
// groups borrow from the surface itself, so they cannot clear a parent's
|
|
2404
|
+
// unfinished image.
|
|
2405
|
+
_prepareIsolationCanvas(rect) {
|
|
2406
|
+
const { a, b, c, d, e, f } = this.getContext()._context.getTransform();
|
|
2407
|
+
const view = this._isolationRect || this;
|
|
2408
|
+
let x = 0, y = 0, width = view.width, height = view.height;
|
|
2409
|
+
if (rect) {
|
|
2410
|
+
const box = new Transform([a, b, c, d, e, f])._getTransformedRect(rect);
|
|
2411
|
+
// Round outwards, with a pixel for antialiasing.
|
|
2412
|
+
x = Math.max(0, Math.floor(box.x) - 1);
|
|
2413
|
+
y = Math.max(0, Math.floor(box.y) - 1);
|
|
2414
|
+
width = Math.min(width, Math.ceil(box.x + box.width) + 1) - x;
|
|
2415
|
+
height = Math.min(height, Math.ceil(box.y + box.height) + 1) - y;
|
|
2416
|
+
}
|
|
2417
|
+
if (!(width > 0 && height > 0)) {
|
|
2418
|
+
// An empty source must still composite for copy/destination-in/etc.
|
|
2419
|
+
x = y = 0;
|
|
2420
|
+
width = height = 1;
|
|
2421
|
+
}
|
|
2422
|
+
const surface = (this._isolationCanvas || (this._isolationCanvas = new SceneCanvas({
|
|
2423
|
+
width: 0,
|
|
2424
|
+
height: 0,
|
|
2425
|
+
pixelRatio: this.pixelRatio,
|
|
2426
|
+
})));
|
|
2427
|
+
if (surface.width < width || surface.height < height) {
|
|
2428
|
+
// Headroom on a short side, so a growing group does not reallocate
|
|
2429
|
+
// every frame.
|
|
2430
|
+
const ratio = this.pixelRatio;
|
|
2431
|
+
const grow = (need, have, max) => Math.min(max, Math.ceil((have < need ? Math.max(need, have * 1.5) : have) / ratio));
|
|
2432
|
+
surface.setSize(grow(width, surface.width, this._logicalWidth), grow(height, surface.height, this._logicalHeight));
|
|
2433
|
+
}
|
|
2434
|
+
surface._isolationRect = { x, y, width, height };
|
|
2435
|
+
const peak = surface._isolationPeak;
|
|
2436
|
+
peak.width = Math.max(peak.width, width);
|
|
2437
|
+
peak.height = Math.max(peak.height, height);
|
|
2438
|
+
const context = surface.getContext();
|
|
2439
|
+
context.setTransform(1, 0, 0, 1, 0, 0);
|
|
2440
|
+
context.clearRect(0, 0, width, height);
|
|
2441
|
+
context.setTransform(a, b, c, d, e - x, f - y);
|
|
2442
|
+
const parent = this.getContext();
|
|
2443
|
+
context.imageSmoothingEnabled = parent.imageSmoothingEnabled;
|
|
2444
|
+
context.imageSmoothingQuality = parent.imageSmoothingQuality;
|
|
2445
|
+
context.direction = parent.direction;
|
|
2446
|
+
return surface;
|
|
2447
|
+
}
|
|
2448
|
+
// After a frame, free surfaces that ten frames in a row did not use or used
|
|
2449
|
+
// a small part of. Content that changes size keeps its surface.
|
|
2450
|
+
_trimIsolationCanvas() {
|
|
2451
|
+
const surface = this._isolationCanvas;
|
|
2452
|
+
if (!surface)
|
|
2453
|
+
return;
|
|
2454
|
+
const peak = surface._isolationPeak;
|
|
2455
|
+
const low = surface.width * surface.height > 4 * peak.width * peak.height;
|
|
2456
|
+
surface._isolationLowFrames = low ? surface._isolationLowFrames + 1 : 0;
|
|
2457
|
+
if (surface._isolationLowFrames >= 10) {
|
|
2458
|
+
this._releaseIsolationCanvas();
|
|
2459
|
+
}
|
|
2460
|
+
else {
|
|
2461
|
+
peak.width = peak.height = 0;
|
|
2462
|
+
surface._trimIsolationCanvas();
|
|
2463
|
+
}
|
|
2464
|
+
}
|
|
2465
|
+
_releaseIsolationCanvas() {
|
|
2466
|
+
const surface = this._isolationCanvas;
|
|
2467
|
+
if (surface) {
|
|
2468
|
+
surface._releaseIsolationCanvas();
|
|
2469
|
+
Util.releaseCanvas(surface._canvas);
|
|
2470
|
+
this._isolationCanvas = undefined;
|
|
2471
|
+
}
|
|
2472
|
+
}
|
|
2473
|
+
setSize(width, height) {
|
|
2474
|
+
// A bitmap reset also resets its origin-clean state. A surface from the
|
|
2475
|
+
// previous lifetime may be tainted even after clearing its pixels.
|
|
2476
|
+
this._releaseIsolationCanvas();
|
|
2477
|
+
super.setSize(width, height);
|
|
2478
|
+
}
|
|
2354
2479
|
constructor(config = { width: 0, height: 0, willReadFrequently: false }) {
|
|
2355
2480
|
super(config);
|
|
2481
|
+
// The largest width and height requested since the last trim.
|
|
2482
|
+
this._isolationPeak = { width: 0, height: 0 };
|
|
2483
|
+
// Consecutive frames that used less than a quarter of the surface.
|
|
2484
|
+
this._isolationLowFrames = 0;
|
|
2356
2485
|
this.context = new SceneContext(this, {
|
|
2357
2486
|
willReadFrequently: config.willReadFrequently,
|
|
2358
2487
|
});
|
|
@@ -3002,20 +3131,6 @@ js: import "konva/skia-backend";
|
|
|
3002
3131
|
'transformsEnabledChange.konva',
|
|
3003
3132
|
].join(SPACE$1);
|
|
3004
3133
|
let idCounter$1 = 1;
|
|
3005
|
-
// "perfect drawing" buffer for cache() and toCanvas(): it mirrors the target
|
|
3006
|
-
// canvas and is drawn back at (x, y) in the target's coordinate space.
|
|
3007
|
-
// It starts empty and Shape.drawScene sizes it on first use, so nodes
|
|
3008
|
-
// without buffered shapes never allocate it.
|
|
3009
|
-
function createBufferCanvas(target, x, y) {
|
|
3010
|
-
const bufferCanvas = new SceneCanvas({
|
|
3011
|
-
width: 0,
|
|
3012
|
-
height: 0,
|
|
3013
|
-
pixelRatio: target.pixelRatio,
|
|
3014
|
-
});
|
|
3015
|
-
bufferCanvas.x = x;
|
|
3016
|
-
bufferCanvas.y = y;
|
|
3017
|
-
return bufferCanvas;
|
|
3018
|
-
}
|
|
3019
3134
|
/**
|
|
3020
3135
|
* Node constructor. Nodes are entities that can be transformed, layered,
|
|
3021
3136
|
* and have bound events. The stage, layers, groups, and shapes all extend Node.
|
|
@@ -3228,7 +3343,6 @@ js: import "konva/skia-backend";
|
|
|
3228
3343
|
height: 0,
|
|
3229
3344
|
willReadFrequently: true,
|
|
3230
3345
|
}), sceneContext = cachedSceneCanvas.getContext();
|
|
3231
|
-
const bufferCanvas = createBufferCanvas(cachedSceneCanvas, x, y);
|
|
3232
3346
|
cachedSceneCanvas.isCache = true;
|
|
3233
3347
|
this._releaseCanvasCache();
|
|
3234
3348
|
this._filterUpToDate = false;
|
|
@@ -3242,7 +3356,7 @@ js: import "konva/skia-backend";
|
|
|
3242
3356
|
this._isUnderCache = true;
|
|
3243
3357
|
this._clearSelfAndDescendantCache(ABSOLUTE_OPACITY);
|
|
3244
3358
|
try {
|
|
3245
|
-
this.drawScene(cachedSceneCanvas, this
|
|
3359
|
+
this.drawScene(cachedSceneCanvas, this);
|
|
3246
3360
|
}
|
|
3247
3361
|
catch (e) {
|
|
3248
3362
|
Util.releaseCanvas(cachedSceneCanvas._canvas);
|
|
@@ -3253,8 +3367,7 @@ js: import "konva/skia-backend";
|
|
|
3253
3367
|
// descendants cached their opacity relative to this node while drawing
|
|
3254
3368
|
this._clearSelfAndDescendantCache(ABSOLUTE_OPACITY);
|
|
3255
3369
|
sceneContext.restore();
|
|
3256
|
-
|
|
3257
|
-
Util.releaseCanvas(bufferCanvas._canvas);
|
|
3370
|
+
cachedSceneCanvas._releaseIsolationCanvas();
|
|
3258
3371
|
}
|
|
3259
3372
|
// this will draw a red border around the cached box for
|
|
3260
3373
|
// debugging purposes
|
|
@@ -3365,28 +3478,22 @@ js: import "konva/skia-backend";
|
|
|
3365
3478
|
// redefine in Container and Shape
|
|
3366
3479
|
throw new Error('abstract "getClientRect" method call');
|
|
3367
3480
|
}
|
|
3368
|
-
|
|
3369
|
-
const
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
points.forEach(function (point) {
|
|
3378
|
-
const transformed = trans.point(point);
|
|
3379
|
-
minX = Math.min(minX, transformed.x);
|
|
3380
|
-
minY = Math.min(minY, transformed.y);
|
|
3381
|
-
maxX = Math.max(maxX, transformed.x);
|
|
3382
|
-
maxY = Math.max(maxY, transformed.y);
|
|
3383
|
-
});
|
|
3384
|
-
return {
|
|
3385
|
-
x: minX,
|
|
3386
|
-
y: minY,
|
|
3387
|
-
width: maxX - minX,
|
|
3388
|
-
height: maxY - minY,
|
|
3481
|
+
_getCachedSceneRect(config) {
|
|
3482
|
+
const cache = config._forDrawing && !this._isUnderCache && this._getCanvasCache();
|
|
3483
|
+
if (!cache)
|
|
3484
|
+
return;
|
|
3485
|
+
const rect = {
|
|
3486
|
+
x: cache.x,
|
|
3487
|
+
y: cache.y,
|
|
3488
|
+
width: cache.scene.width / cache.scene.pixelRatio,
|
|
3489
|
+
height: cache.scene.height / cache.scene.pixelRatio,
|
|
3389
3490
|
};
|
|
3491
|
+
return config.skipTransform
|
|
3492
|
+
? rect
|
|
3493
|
+
: this._transformedRect(rect, config.relativeTo);
|
|
3494
|
+
}
|
|
3495
|
+
_transformedRect(rect, top) {
|
|
3496
|
+
return this.getAbsoluteTransform(top)._getTransformedRect(rect);
|
|
3390
3497
|
}
|
|
3391
3498
|
_drawCachedSceneCanvas(context) {
|
|
3392
3499
|
context.save();
|
|
@@ -4645,7 +4752,6 @@ js: import "konva/skia-backend";
|
|
|
4645
4752
|
(stage ? stage.height() : 0),
|
|
4646
4753
|
pixelRatio: pixelRatio,
|
|
4647
4754
|
}), context = canvas.getContext();
|
|
4648
|
-
const bufferCanvas = createBufferCanvas(canvas, x, y);
|
|
4649
4755
|
if (config.imageSmoothingEnabled === false) {
|
|
4650
4756
|
context._context.imageSmoothingEnabled = false;
|
|
4651
4757
|
}
|
|
@@ -4653,10 +4759,9 @@ js: import "konva/skia-backend";
|
|
|
4653
4759
|
if (x || y) {
|
|
4654
4760
|
context.translate(-1 * x, -1 * y);
|
|
4655
4761
|
}
|
|
4656
|
-
this.drawScene(canvas
|
|
4762
|
+
this.drawScene(canvas);
|
|
4657
4763
|
context.restore();
|
|
4658
|
-
|
|
4659
|
-
Util.releaseCanvas(bufferCanvas._canvas);
|
|
4764
|
+
canvas._releaseIsolationCanvas();
|
|
4660
4765
|
return canvas;
|
|
4661
4766
|
}
|
|
4662
4767
|
/**
|
|
@@ -6226,7 +6331,7 @@ js: import "konva/skia-backend";
|
|
|
6226
6331
|
});
|
|
6227
6332
|
this._requestDraw();
|
|
6228
6333
|
}
|
|
6229
|
-
drawScene(can, top
|
|
6334
|
+
drawScene(can, top) {
|
|
6230
6335
|
const layer = this.getLayer(), canvas = can || (layer && layer.getCanvas()), context = canvas && canvas.getContext(), cachedCanvas = this._getCanvasCache(), cachedSceneCanvas = cachedCanvas && cachedCanvas.scene;
|
|
6231
6336
|
const caching = top === this;
|
|
6232
6337
|
if (!(top ? this._isVisible(top) : this.isVisible()) && !caching) {
|
|
@@ -6240,7 +6345,7 @@ js: import "konva/skia-backend";
|
|
|
6240
6345
|
context.restore();
|
|
6241
6346
|
}
|
|
6242
6347
|
else {
|
|
6243
|
-
this._drawChildren('drawScene', canvas, top
|
|
6348
|
+
this._drawChildren('drawScene', canvas, top);
|
|
6244
6349
|
}
|
|
6245
6350
|
return this;
|
|
6246
6351
|
}
|
|
@@ -6261,8 +6366,7 @@ js: import "konva/skia-backend";
|
|
|
6261
6366
|
}
|
|
6262
6367
|
return this;
|
|
6263
6368
|
}
|
|
6264
|
-
_drawChildren(drawMethod, canvas, top
|
|
6265
|
-
var _a;
|
|
6369
|
+
_drawChildren(drawMethod, canvas, top) {
|
|
6266
6370
|
const context = canvas && canvas.getContext(), clipWidth = this.clipWidth(), clipHeight = this.clipHeight(), clipFunc = this.clipFunc(), hasClip = (typeof clipWidth === 'number' && typeof clipHeight === 'number') ||
|
|
6267
6371
|
clipFunc;
|
|
6268
6372
|
const selfCache = top === this;
|
|
@@ -6292,23 +6396,34 @@ js: import "konva/skia-backend";
|
|
|
6292
6396
|
context.save();
|
|
6293
6397
|
context._applyGlobalCompositeOperation(this);
|
|
6294
6398
|
}
|
|
6295
|
-
|
|
6296
|
-
|
|
6297
|
-
});
|
|
6298
|
-
if (hasComposition) {
|
|
6299
|
-
context.restore();
|
|
6399
|
+
try {
|
|
6400
|
+
this._drawChildNodes(drawMethod, canvas, top);
|
|
6300
6401
|
}
|
|
6301
|
-
|
|
6302
|
-
|
|
6402
|
+
finally {
|
|
6403
|
+
if (hasComposition) {
|
|
6404
|
+
context.restore();
|
|
6405
|
+
}
|
|
6406
|
+
if (hasClip) {
|
|
6407
|
+
context.restore();
|
|
6408
|
+
}
|
|
6303
6409
|
}
|
|
6304
6410
|
}
|
|
6411
|
+
_drawChildNodes(drawMethod, canvas, top) {
|
|
6412
|
+
var _a;
|
|
6413
|
+
(_a = this.children) === null || _a === void 0 ? void 0 : _a.forEach(function (child) {
|
|
6414
|
+
child[drawMethod](canvas, top);
|
|
6415
|
+
});
|
|
6416
|
+
}
|
|
6305
6417
|
getClientRect(config = {}) {
|
|
6306
6418
|
var _a;
|
|
6419
|
+
const cachedRect = this._getCachedSceneRect(config);
|
|
6420
|
+
if (cachedRect)
|
|
6421
|
+
return cachedRect;
|
|
6307
6422
|
const skipTransform = config.skipTransform;
|
|
6308
6423
|
const relativeTo = config.relativeTo;
|
|
6309
6424
|
const [a, b, c, d] = this.getAbsoluteTransform().getMatrix();
|
|
6310
6425
|
// A zero scale cannot project local padding for a non-scaling stroke.
|
|
6311
|
-
const measureTransformed = !skipTransform && a * d - b * c === 0;
|
|
6426
|
+
const measureTransformed = !skipTransform && (config._forDrawing || a * d - b * c === 0);
|
|
6312
6427
|
let minX, minY, maxX, maxY;
|
|
6313
6428
|
let selfRect = {
|
|
6314
6429
|
x: Infinity,
|
|
@@ -6324,6 +6439,7 @@ js: import "konva/skia-backend";
|
|
|
6324
6439
|
}
|
|
6325
6440
|
const rect = child.getClientRect({
|
|
6326
6441
|
relativeTo: measureTransformed ? relativeTo : that,
|
|
6442
|
+
_forDrawing: config._forDrawing,
|
|
6327
6443
|
skipShadow: config.skipShadow,
|
|
6328
6444
|
skipStroke: config.skipStroke,
|
|
6329
6445
|
});
|
|
@@ -6723,7 +6839,7 @@ js: import "konva/skia-backend";
|
|
|
6723
6839
|
if (index > -1) {
|
|
6724
6840
|
stages.splice(index, 1);
|
|
6725
6841
|
}
|
|
6726
|
-
Util.releaseCanvas(this.
|
|
6842
|
+
Util.releaseCanvas(this.bufferHitCanvas._canvas);
|
|
6727
6843
|
return this;
|
|
6728
6844
|
}
|
|
6729
6845
|
/**
|
|
@@ -6828,13 +6944,6 @@ js: import "konva/skia-backend";
|
|
|
6828
6944
|
layer.draw();
|
|
6829
6945
|
});
|
|
6830
6946
|
}
|
|
6831
|
-
// "perfect drawing" uses bufferCanvas, shape.intersects() uses
|
|
6832
|
-
// bufferHitCanvas; both are lazy - created at 0x0 and sized to the stage
|
|
6833
|
-
// on first use
|
|
6834
|
-
_syncBufferSize(canvas) {
|
|
6835
|
-
canvas.setSizeIfChanged(this.width(), this.height());
|
|
6836
|
-
return canvas;
|
|
6837
|
-
}
|
|
6838
6947
|
add(layer, ...rest) {
|
|
6839
6948
|
if (arguments.length > 1) {
|
|
6840
6949
|
for (let i = 0; i < arguments.length; i++) {
|
|
@@ -7410,12 +7519,8 @@ js: import "konva/skia-backend";
|
|
|
7410
7519
|
};
|
|
7411
7520
|
}
|
|
7412
7521
|
_buildDOM() {
|
|
7413
|
-
// lazy buffer
|
|
7522
|
+
// lazy buffer canvas, sized by Shape.intersects() on first use
|
|
7414
7523
|
// https://github.com/konvajs/konva/issues/2009
|
|
7415
|
-
this.bufferCanvas = new SceneCanvas({
|
|
7416
|
-
width: 0,
|
|
7417
|
-
height: 0,
|
|
7418
|
-
});
|
|
7419
7524
|
this.bufferHitCanvas = new HitCanvas({
|
|
7420
7525
|
pixelRatio: 1,
|
|
7421
7526
|
width: 0,
|
|
@@ -7851,7 +7956,9 @@ js: import "konva/skia-backend";
|
|
|
7851
7956
|
if (!stage) {
|
|
7852
7957
|
return false;
|
|
7853
7958
|
}
|
|
7854
|
-
const bufferHitCanvas = stage.
|
|
7959
|
+
const bufferHitCanvas = stage.bufferHitCanvas;
|
|
7960
|
+
// lazy: allocated at stage size on first use
|
|
7961
|
+
bufferHitCanvas.setSizeIfChanged(stage.width(), stage.height());
|
|
7855
7962
|
bufferHitCanvas.getContext().clear();
|
|
7856
7963
|
this.drawHit(bufferHitCanvas);
|
|
7857
7964
|
const p = bufferHitCanvas.context.getImageData(Math.floor(point.x), Math.floor(point.y), 1, 1).data;
|
|
@@ -7866,7 +7973,7 @@ js: import "konva/skia-backend";
|
|
|
7866
7973
|
// why do we need buffer canvas?
|
|
7867
7974
|
// it give better result when a shape has
|
|
7868
7975
|
// stroke with fill and with some opacity
|
|
7869
|
-
_useBufferCanvas(forceFill) {
|
|
7976
|
+
_useBufferCanvas(forceFill, opacity = this.getAbsoluteOpacity()) {
|
|
7870
7977
|
// image and sprite still has "fill" as image
|
|
7871
7978
|
// so they use that method with forced fill
|
|
7872
7979
|
// it probably will be simpler, then copy/paste the code
|
|
@@ -7878,7 +7985,7 @@ js: import "konva/skia-backend";
|
|
|
7878
7985
|
}
|
|
7879
7986
|
const hasFill = forceFill || this.hasFill();
|
|
7880
7987
|
const hasStroke = this.hasStroke();
|
|
7881
|
-
const isTransparent = !this._isUnderCache &&
|
|
7988
|
+
const isTransparent = !this._isUnderCache && opacity !== 1;
|
|
7882
7989
|
if (hasFill && hasStroke && isTransparent) {
|
|
7883
7990
|
return true;
|
|
7884
7991
|
}
|
|
@@ -7919,6 +8026,9 @@ js: import "konva/skia-backend";
|
|
|
7919
8026
|
*
|
|
7920
8027
|
*/
|
|
7921
8028
|
getSelfRect() {
|
|
8029
|
+
const selfRectFunc = this.attrs.selfRectFunc;
|
|
8030
|
+
if (selfRectFunc)
|
|
8031
|
+
return { ...selfRectFunc.call(this, this) };
|
|
7922
8032
|
const size = this.size();
|
|
7923
8033
|
return {
|
|
7924
8034
|
x: this._centroid ? -size.width / 2 : 0,
|
|
@@ -7927,16 +8037,34 @@ js: import "konva/skia-backend";
|
|
|
7927
8037
|
height: size.height,
|
|
7928
8038
|
};
|
|
7929
8039
|
}
|
|
8040
|
+
_getSelfRectForDrawing() {
|
|
8041
|
+
return this.getSelfRect();
|
|
8042
|
+
}
|
|
7930
8043
|
getClientRect(config = {}) {
|
|
8044
|
+
const cachedRect = this._getCachedSceneRect(config);
|
|
8045
|
+
if (cachedRect)
|
|
8046
|
+
return cachedRect;
|
|
7931
8047
|
const skipTransform = config.skipTransform;
|
|
7932
8048
|
const relativeTo = config.relativeTo;
|
|
7933
|
-
const
|
|
8049
|
+
const forDrawing = config._forDrawing;
|
|
8050
|
+
// Painted bounds are measured in the canvas that draws the shape
|
|
8051
|
+
// (relativeTo): non-scaling strokes and shadows use that canvas's axes.
|
|
8052
|
+
// The identity transform normalizes negative sizes.
|
|
8053
|
+
const fillRect = !forDrawing
|
|
8054
|
+
? this.getSelfRect()
|
|
8055
|
+
: this.strokeScaleEnabled()
|
|
8056
|
+
? new Transform()._getTransformedRect(this._getSelfRectForDrawing())
|
|
8057
|
+
: this._transformedRect(this._getSelfRectForDrawing(), relativeTo);
|
|
7934
8058
|
const applyStroke = !config.skipStroke && this.hasStroke();
|
|
7935
|
-
const strokeWidth =
|
|
8059
|
+
const strokeWidth = applyStroke
|
|
8060
|
+
? forDrawing
|
|
8061
|
+
? this._getStrokePadding() * 2
|
|
8062
|
+
: this.strokeWidth()
|
|
8063
|
+
: 0;
|
|
7936
8064
|
let strokeWidthX = strokeWidth;
|
|
7937
8065
|
let strokeWidthY = strokeWidth;
|
|
7938
8066
|
let collapsedStroke;
|
|
7939
|
-
if (strokeWidth && !this.strokeScaleEnabled()) {
|
|
8067
|
+
if (!forDrawing && strokeWidth && !this.strokeScaleEnabled()) {
|
|
7940
8068
|
// Strokes are constant in the canvas they are drawn into. A cached
|
|
7941
8069
|
// ancestor supplies that coordinate space until its bitmap is rebuilt.
|
|
7942
8070
|
let top = this;
|
|
@@ -7967,26 +8095,29 @@ js: import "konva/skia-backend";
|
|
|
7967
8095
|
}
|
|
7968
8096
|
}
|
|
7969
8097
|
}
|
|
7970
|
-
|
|
7971
|
-
|
|
7972
|
-
|
|
7973
|
-
|
|
7974
|
-
|
|
7975
|
-
const preWidth = fillAndStrokeWidth + Math.abs(shadowOffsetX);
|
|
7976
|
-
const preHeight = fillAndStrokeHeight + Math.abs(shadowOffsetY);
|
|
7977
|
-
const blurRadius = (applyShadow && this.shadowBlur()) || 0;
|
|
7978
|
-
const width = preWidth + blurRadius * 2;
|
|
7979
|
-
const height = preHeight + blurRadius * 2;
|
|
7980
|
-
const rect = {
|
|
7981
|
-
width: width,
|
|
7982
|
-
height: height,
|
|
7983
|
-
x: -(strokeWidthX / 2 + blurRadius) +
|
|
7984
|
-
Math.min(shadowOffsetX, 0) +
|
|
7985
|
-
fillRect.x,
|
|
7986
|
-
y: -(strokeWidthY / 2 + blurRadius) +
|
|
7987
|
-
Math.min(shadowOffsetY, 0) +
|
|
7988
|
-
fillRect.y,
|
|
8098
|
+
let rect = {
|
|
8099
|
+
x: fillRect.x - strokeWidthX / 2,
|
|
8100
|
+
y: fillRect.y - strokeWidthY / 2,
|
|
8101
|
+
width: fillRect.width + strokeWidthX,
|
|
8102
|
+
height: fillRect.height + strokeWidthY,
|
|
7989
8103
|
};
|
|
8104
|
+
if (forDrawing && this.strokeScaleEnabled()) {
|
|
8105
|
+
rect = this._transformedRect(rect, relativeTo);
|
|
8106
|
+
}
|
|
8107
|
+
if (!config.skipShadow && this.hasShadow()) {
|
|
8108
|
+
const scale = forDrawing ? this.getAbsoluteScale() : { x: 1, y: 1 };
|
|
8109
|
+
const dx = this.shadowOffsetX() * scale.x;
|
|
8110
|
+
const dy = this.shadowOffsetY() * scale.y;
|
|
8111
|
+
const blur = this.shadowBlur() *
|
|
8112
|
+
(forDrawing ? 2 * Math.min(Math.abs(scale.x), Math.abs(scale.y)) : 1);
|
|
8113
|
+
rect.x += Math.min(0, dx) - blur;
|
|
8114
|
+
rect.y += Math.min(0, dy) - blur;
|
|
8115
|
+
rect.width += Math.abs(dx) + blur * 2;
|
|
8116
|
+
rect.height += Math.abs(dy) + blur * 2;
|
|
8117
|
+
}
|
|
8118
|
+
if (forDrawing) {
|
|
8119
|
+
return rect;
|
|
8120
|
+
}
|
|
7990
8121
|
if (!skipTransform) {
|
|
7991
8122
|
const transformed = this._transformedRect(rect, relativeTo);
|
|
7992
8123
|
if (collapsedStroke) {
|
|
@@ -8002,14 +8133,20 @@ js: import "konva/skia-backend";
|
|
|
8002
8133
|
}
|
|
8003
8134
|
return rect;
|
|
8004
8135
|
}
|
|
8005
|
-
|
|
8136
|
+
_getStrokePadding(miterLimit = this.miterLimit() || 10) {
|
|
8137
|
+
// Custom paths can have sharper joins than the built-in geometry.
|
|
8138
|
+
if (this.attrs.sceneFunc)
|
|
8139
|
+
miterLimit = this.miterLimit() || 10;
|
|
8140
|
+
return ((Math.abs(this.strokeWidth()) / 2) *
|
|
8141
|
+
Math.max(this.lineCap() === 'square' ? Math.SQRT2 : 1, (this.lineJoin() || 'miter') === 'miter' ? miterLimit : 1));
|
|
8142
|
+
}
|
|
8143
|
+
drawScene(can, top) {
|
|
8006
8144
|
// basically there are 3 drawing modes
|
|
8007
8145
|
// 1 - simple drawing when nothing is cached.
|
|
8008
8146
|
// 2 - when we are caching current
|
|
8009
8147
|
// 3 - when node is cached and we need to draw it into layer
|
|
8010
8148
|
const layer = this.getLayer();
|
|
8011
8149
|
const canvas = can || layer.getCanvas(), context = canvas.getContext(), cachedCanvas = this._getCanvasCache(), drawFunc = this.getSceneFunc(), hasShadow = this.hasShadow();
|
|
8012
|
-
let stage;
|
|
8013
8150
|
const cachingSelf = top === this;
|
|
8014
8151
|
if (!(top ? this._isVisible(top) : this.isVisible()) && !cachingSelf) {
|
|
8015
8152
|
return this;
|
|
@@ -8027,66 +8164,72 @@ js: import "konva/skia-backend";
|
|
|
8027
8164
|
return this;
|
|
8028
8165
|
}
|
|
8029
8166
|
context.save();
|
|
8030
|
-
|
|
8031
|
-
|
|
8032
|
-
|
|
8033
|
-
|
|
8034
|
-
|
|
8035
|
-
|
|
8036
|
-
|
|
8037
|
-
|
|
8038
|
-
|
|
8039
|
-
//
|
|
8040
|
-
|
|
8041
|
-
|
|
8042
|
-
|
|
8043
|
-
|
|
8044
|
-
|
|
8045
|
-
|
|
8167
|
+
try {
|
|
8168
|
+
// if buffer canvas is needed; an empty canvas has nothing to draw into
|
|
8169
|
+
if (canvas.width &&
|
|
8170
|
+
canvas.height &&
|
|
8171
|
+
this._useBufferCanvas(undefined, context._getOpacity(this))) {
|
|
8172
|
+
// Built-in shapes, custom shapes with a selfRectFunc and isolated
|
|
8173
|
+
// groups use a buffer the size of the painted bounds. Other custom
|
|
8174
|
+
// drawing (sceneFunc, charRenderFunc, own classes) gets the whole
|
|
8175
|
+
// canvas, since it can paint outside its bounds. The shadow is
|
|
8176
|
+
// applied when the buffer is drawn, not inside it.
|
|
8177
|
+
const bounded = !!context._opacityRoot ||
|
|
8178
|
+
(!!this.attrs.selfRectFunc &&
|
|
8179
|
+
this.getSelfRect === Shape.prototype.getSelfRect) ||
|
|
8180
|
+
(!this.attrs.sceneFunc &&
|
|
8181
|
+
!this.attrs.charRenderFunc &&
|
|
8182
|
+
_boundedShapes.has(this.constructor));
|
|
8183
|
+
const bc = canvas._prepareIsolationCanvas(bounded
|
|
8184
|
+
? this.getClientRect({
|
|
8185
|
+
_forDrawing: true,
|
|
8186
|
+
relativeTo: top,
|
|
8187
|
+
skipShadow: true,
|
|
8188
|
+
})
|
|
8189
|
+
: undefined);
|
|
8190
|
+
const bufferContext = bc.getContext();
|
|
8046
8191
|
bufferContext.save();
|
|
8047
|
-
bufferContext.
|
|
8048
|
-
bufferContext.
|
|
8192
|
+
bufferContext._applyLineJoin(this);
|
|
8193
|
+
bufferContext._applyMiterLimit(this);
|
|
8194
|
+
// layer might be undefined if we are using cache before adding to layer
|
|
8195
|
+
const o = this.getAbsoluteTransform(top).getMatrix();
|
|
8196
|
+
bufferContext.transform(o[0], o[1], o[2], o[3], o[4], o[5]);
|
|
8197
|
+
drawFunc.call(this, bufferContext, this);
|
|
8049
8198
|
bufferContext.restore();
|
|
8199
|
+
if (hasShadow) {
|
|
8200
|
+
context._applyShadow(this);
|
|
8201
|
+
}
|
|
8202
|
+
// if we are caching self, we don't need to apply opacity and global composite operation
|
|
8203
|
+
// because it will be applied in the cache
|
|
8204
|
+
if (!cachingSelf) {
|
|
8205
|
+
context._applyOpacity(this);
|
|
8206
|
+
context._applyGlobalCompositeOperation(this);
|
|
8207
|
+
}
|
|
8208
|
+
context._drawDeviceBuffer(bc);
|
|
8050
8209
|
}
|
|
8051
|
-
|
|
8052
|
-
|
|
8053
|
-
|
|
8054
|
-
|
|
8055
|
-
|
|
8056
|
-
|
|
8057
|
-
|
|
8058
|
-
|
|
8059
|
-
|
|
8060
|
-
|
|
8061
|
-
|
|
8062
|
-
|
|
8063
|
-
|
|
8064
|
-
if (hasShadow) {
|
|
8065
|
-
context._applyShadow(this);
|
|
8066
|
-
}
|
|
8067
|
-
// if we are caching self, we don't need to apply opacity and global composite operation
|
|
8068
|
-
// because it will be applied in the cache
|
|
8069
|
-
if (!cachingSelf) {
|
|
8070
|
-
context._applyOpacity(this);
|
|
8071
|
-
context._applyGlobalCompositeOperation(this);
|
|
8210
|
+
else {
|
|
8211
|
+
context._applyLineJoin(this);
|
|
8212
|
+
context._applyMiterLimit(this);
|
|
8213
|
+
if (!cachingSelf) {
|
|
8214
|
+
const o = this.getAbsoluteTransform(top).getMatrix();
|
|
8215
|
+
context.transform(o[0], o[1], o[2], o[3], o[4], o[5]);
|
|
8216
|
+
context._applyOpacity(this);
|
|
8217
|
+
context._applyGlobalCompositeOperation(this);
|
|
8218
|
+
}
|
|
8219
|
+
if (hasShadow) {
|
|
8220
|
+
context._applyShadow(this);
|
|
8221
|
+
}
|
|
8222
|
+
drawFunc.call(this, context, this);
|
|
8072
8223
|
}
|
|
8073
|
-
context.drawImage(bc._canvas, bc.x, bc.y, bc.width / ratio, bc.height / ratio);
|
|
8074
8224
|
}
|
|
8075
|
-
|
|
8076
|
-
|
|
8077
|
-
|
|
8078
|
-
|
|
8079
|
-
|
|
8080
|
-
|
|
8081
|
-
|
|
8082
|
-
context._applyGlobalCompositeOperation(this);
|
|
8083
|
-
}
|
|
8084
|
-
if (hasShadow) {
|
|
8085
|
-
context._applyShadow(this);
|
|
8086
|
-
}
|
|
8087
|
-
drawFunc.call(this, context, this);
|
|
8225
|
+
catch (error) {
|
|
8226
|
+
// A throwing sceneFunc can leave a clip on the shared buffer.
|
|
8227
|
+
canvas._releaseIsolationCanvas();
|
|
8228
|
+
throw error;
|
|
8229
|
+
}
|
|
8230
|
+
finally {
|
|
8231
|
+
context.restore();
|
|
8088
8232
|
}
|
|
8089
|
-
context.restore();
|
|
8090
8233
|
return this;
|
|
8091
8234
|
}
|
|
8092
8235
|
drawHit(can, top) {
|
|
@@ -8116,8 +8259,12 @@ js: import "konva/skia-backend";
|
|
|
8116
8259
|
const o = this.getAbsoluteTransform(top).getMatrix();
|
|
8117
8260
|
context.transform(o[0], o[1], o[2], o[3], o[4], o[5]);
|
|
8118
8261
|
}
|
|
8119
|
-
|
|
8120
|
-
|
|
8262
|
+
try {
|
|
8263
|
+
drawFunc.call(this, context, this);
|
|
8264
|
+
}
|
|
8265
|
+
finally {
|
|
8266
|
+
context.restore();
|
|
8267
|
+
}
|
|
8121
8268
|
return this;
|
|
8122
8269
|
}
|
|
8123
8270
|
/**
|
|
@@ -8394,6 +8541,24 @@ js: import "konva/skia-backend";
|
|
|
8394
8541
|
* context.fillStrokeShape(shape);
|
|
8395
8542
|
* });
|
|
8396
8543
|
*/
|
|
8544
|
+
Factory.addGetterSetter(Shape, 'selfRectFunc');
|
|
8545
|
+
/**
|
|
8546
|
+
* get/set the function that returns the self rectangle of a custom shape: the
|
|
8547
|
+
* local, untransformed area its sceneFunc paints, before the stroke and shadow
|
|
8548
|
+
* Konva adds. Use it when drawing goes outside the width and height box, so
|
|
8549
|
+
* bounds, cache(), isolated groups and perfect drawing include that paint.
|
|
8550
|
+
* Paint outside the returned rectangle can be clipped. Meant for custom
|
|
8551
|
+
* shapes, and for Text drawn with charRenderFunc; built-in shapes that compute
|
|
8552
|
+
* their own bounds may ignore it.
|
|
8553
|
+
* @name Konva.Shape#selfRectFunc
|
|
8554
|
+
* @method
|
|
8555
|
+
* @param {Function} selfRectFunc function returning {x, y, width, height}
|
|
8556
|
+
* @returns {Function}
|
|
8557
|
+
* @example
|
|
8558
|
+
* shape.selfRectFunc(() => ({ x: -10, y: -10, width: 120, height: 120 }));
|
|
8559
|
+
* // back to the automatic width and height box
|
|
8560
|
+
* shape.selfRectFunc(undefined);
|
|
8561
|
+
*/
|
|
8397
8562
|
Factory.addGetterSetter(Shape, 'dash');
|
|
8398
8563
|
/**
|
|
8399
8564
|
* get/set dash array for stroke.
|
|
@@ -8749,7 +8914,7 @@ js: import "konva/skia-backend";
|
|
|
8749
8914
|
*/
|
|
8750
8915
|
Factory.addGetterSetter(Shape, 'strokeScaleEnabled', true);
|
|
8751
8916
|
/**
|
|
8752
|
-
* get/set strokeScale enabled flag
|
|
8917
|
+
* get/set strokeScale enabled flag. Text and TextPath always scale their stroke.
|
|
8753
8918
|
* @name Konva.Shape#strokeScaleEnabled
|
|
8754
8919
|
* @method
|
|
8755
8920
|
* @param {Boolean} enabled
|
|
@@ -9604,7 +9769,7 @@ js: import "konva/skia-backend";
|
|
|
9604
9769
|
}
|
|
9605
9770
|
return {};
|
|
9606
9771
|
}
|
|
9607
|
-
drawScene(can, top
|
|
9772
|
+
drawScene(can, top) {
|
|
9608
9773
|
const layer = this.getLayer(), canvas = can || (layer && layer.getCanvas());
|
|
9609
9774
|
this._fire(BEFORE_DRAW, {
|
|
9610
9775
|
node: this,
|
|
@@ -9612,7 +9777,8 @@ js: import "konva/skia-backend";
|
|
|
9612
9777
|
if (this.clearBeforeDraw()) {
|
|
9613
9778
|
canvas.getContext().clear();
|
|
9614
9779
|
}
|
|
9615
|
-
Container.prototype.drawScene.call(this, canvas, top
|
|
9780
|
+
Container.prototype.drawScene.call(this, canvas, top);
|
|
9781
|
+
canvas._trimIsolationCanvas();
|
|
9616
9782
|
this._fire(DRAW, {
|
|
9617
9783
|
node: this,
|
|
9618
9784
|
});
|
|
@@ -9699,6 +9865,7 @@ js: import "konva/skia-backend";
|
|
|
9699
9865
|
}
|
|
9700
9866
|
}
|
|
9701
9867
|
destroy() {
|
|
9868
|
+
this.getCanvas()._releaseIsolationCanvas();
|
|
9702
9869
|
Util.releaseCanvas(this.getNativeCanvasElement(), this.getHitCanvas()._canvas);
|
|
9703
9870
|
return super.destroy();
|
|
9704
9871
|
}
|
|
@@ -9796,6 +9963,7 @@ js: import "konva/skia-backend";
|
|
|
9796
9963
|
* @memberof Konva
|
|
9797
9964
|
* @augments Konva.Container
|
|
9798
9965
|
* @param {Object} config
|
|
9966
|
+
* @param {Boolean} [config.isolated=false] composite children as one live image
|
|
9799
9967
|
* @param {Number} [config.x]
|
|
9800
9968
|
* @param {Number} [config.y]
|
|
9801
9969
|
* @param {Number} [config.width]
|
|
@@ -9833,7 +10001,65 @@ js: import "konva/skia-backend";
|
|
|
9833
10001
|
Util.throw('You may only add groups and shapes to groups.');
|
|
9834
10002
|
}
|
|
9835
10003
|
}
|
|
10004
|
+
_drawChildNodes(drawMethod, canvas, top) {
|
|
10005
|
+
// cache() already provides an isolated surface and owns its snapshot.
|
|
10006
|
+
if (drawMethod !== 'drawScene' || !this.isolated() || top === this) {
|
|
10007
|
+
return super._drawChildNodes(drawMethod, canvas, top);
|
|
10008
|
+
}
|
|
10009
|
+
if (!canvas.width || !canvas.height) {
|
|
10010
|
+
return;
|
|
10011
|
+
}
|
|
10012
|
+
const context = canvas.getContext();
|
|
10013
|
+
const surface = canvas._prepareIsolationCanvas(this.getClientRect({ _forDrawing: true, relativeTo: top }));
|
|
10014
|
+
const surfaceContext = surface.getContext();
|
|
10015
|
+
surfaceContext._opacityRoot = this;
|
|
10016
|
+
context.save();
|
|
10017
|
+
try {
|
|
10018
|
+
super._drawChildNodes(drawMethod, surface, top);
|
|
10019
|
+
context._applyOpacity(this);
|
|
10020
|
+
context._drawDeviceBuffer(surface);
|
|
10021
|
+
}
|
|
10022
|
+
catch (error) {
|
|
10023
|
+
// A throwing sceneFunc can leave unbalanced saves or a clip on the
|
|
10024
|
+
// scratch context. Discard it rather than contaminate the next draw.
|
|
10025
|
+
canvas._releaseIsolationCanvas();
|
|
10026
|
+
throw error;
|
|
10027
|
+
}
|
|
10028
|
+
finally {
|
|
10029
|
+
context.restore();
|
|
10030
|
+
surfaceContext._opacityRoot = undefined;
|
|
10031
|
+
}
|
|
10032
|
+
}
|
|
9836
10033
|
}
|
|
10034
|
+
/**
|
|
10035
|
+
* Get or set group isolation. Default is false.
|
|
10036
|
+
* An isolated group draws its children into a transparent canvas on each scene draw.
|
|
10037
|
+
* The group opacity and globalCompositeOperation apply once to the completed image.
|
|
10038
|
+
* Child blend modes and erasing affect only the content inside that canvas.
|
|
10039
|
+
*
|
|
10040
|
+
* Explicit cache() calls keep their snapshot behavior. clearCache() resumes live drawing.
|
|
10041
|
+
* Hit testing keeps its normal behavior, including hits on erased content.
|
|
10042
|
+
* For video or canvas sources, schedule draws when the source changes.
|
|
10043
|
+
*
|
|
10044
|
+
* Buffers use conservative content bounds at the destination pixel ratio.
|
|
10045
|
+
* Moving the buffer origin changes native edge coverage. A few edge pixels
|
|
10046
|
+
* can differ substantially; isolation does not promise pixel-identical antialiasing.
|
|
10047
|
+
* Like cache(), isolation requires custom drawing (sceneFunc, charRenderFunc) to provide accurate
|
|
10048
|
+
* bounds, including any pixels it paints outside its size: selfRectFunc or a
|
|
10049
|
+
* getSelfRect() override.
|
|
10050
|
+
* Text is bounded by its lines plus one font size, so a glyph with many stacked
|
|
10051
|
+
* marks can be clipped. node-canvas shadows can change with bitmap origin.
|
|
10052
|
+
* Siblings reuse a buffer; unused or oversized buffers are freed after each layer draw.
|
|
10053
|
+
* @name Konva.Group#isolated
|
|
10054
|
+
* @method
|
|
10055
|
+
* @param {Boolean} isolated
|
|
10056
|
+
* @returns {Boolean}
|
|
10057
|
+
* @example
|
|
10058
|
+
* const group = new Konva.Group({ isolated: true, opacity: 0.5 });
|
|
10059
|
+
* group.add(shape1, shape2);
|
|
10060
|
+
* group.isolated(false);
|
|
10061
|
+
*/
|
|
10062
|
+
Factory.addGetterSetter(Group, 'isolated', false, getBooleanValidator());
|
|
9837
10063
|
Group.prototype.nodeType = 'Group';
|
|
9838
10064
|
_registerNode(Group);
|
|
9839
10065
|
|
|
@@ -10884,8 +11110,8 @@ js: import "konva/skia-backend";
|
|
|
10884
11110
|
this.outerRadius(height / 2);
|
|
10885
11111
|
}
|
|
10886
11112
|
getSelfRect() {
|
|
10887
|
-
const
|
|
10888
|
-
const
|
|
11113
|
+
const r1 = Math.abs(this.innerRadius()), r2 = Math.abs(this.outerRadius());
|
|
11114
|
+
const innerRadius = Math.min(r1, r2), outerRadius = Math.max(r1, r2);
|
|
10889
11115
|
const clockwise = this.clockwise();
|
|
10890
11116
|
// canvas draws a full circle for any non-zero full-turn end angle regardless
|
|
10891
11117
|
// of direction, and nothing for angle 0. Keep exact turns distinct from
|
|
@@ -10928,7 +11154,7 @@ js: import "konva/skia-backend";
|
|
|
10928
11154
|
'angle',
|
|
10929
11155
|
'clockwise',
|
|
10930
11156
|
];
|
|
10931
|
-
_registerNode(Arc);
|
|
11157
|
+
_registerNode(Arc, true);
|
|
10932
11158
|
// add getters setters
|
|
10933
11159
|
Factory.addGetterSetter(Arc, 'innerRadius', 0, getNumberValidator());
|
|
10934
11160
|
/**
|
|
@@ -11342,6 +11568,9 @@ js: import "konva/skia-backend";
|
|
|
11342
11568
|
onQuadratic(x0, y0, tp[len - 2], tp[len - 1], points[length - 2], points[length - 1]);
|
|
11343
11569
|
}
|
|
11344
11570
|
}
|
|
11571
|
+
_getStrokePadding(miterLimit = this.points().length === 4 && !this.closed() ? 1 : undefined) {
|
|
11572
|
+
return super._getStrokePadding(miterLimit);
|
|
11573
|
+
}
|
|
11345
11574
|
_sceneFunc(context) {
|
|
11346
11575
|
const points = this.points(), length = points.length, closed = this.closed(), bezier = this.bezier();
|
|
11347
11576
|
if (!length) {
|
|
@@ -11441,7 +11670,7 @@ js: import "konva/skia-backend";
|
|
|
11441
11670
|
}
|
|
11442
11671
|
Line.prototype.className = 'Line';
|
|
11443
11672
|
Line.prototype._attrsAffectingSize = ['points', 'bezier', 'tension', 'closed'];
|
|
11444
|
-
_registerNode(Line);
|
|
11673
|
+
_registerNode(Line, true);
|
|
11445
11674
|
// add getters setters
|
|
11446
11675
|
Factory.addGetterSetter(Line, 'closed', false);
|
|
11447
11676
|
/**
|
|
@@ -12278,7 +12507,7 @@ js: import "konva/skia-backend";
|
|
|
12278
12507
|
}
|
|
12279
12508
|
Path.prototype.className = 'Path';
|
|
12280
12509
|
Path.prototype._attrsAffectingSize = ['data'];
|
|
12281
|
-
_registerNode(Path);
|
|
12510
|
+
_registerNode(Path, true);
|
|
12282
12511
|
/**
|
|
12283
12512
|
* get/set SVG path data string. This method
|
|
12284
12513
|
* also automatically parses the data string
|
|
@@ -12410,6 +12639,12 @@ js: import "konva/skia-backend";
|
|
|
12410
12639
|
* });
|
|
12411
12640
|
*/
|
|
12412
12641
|
class Arrow extends Line {
|
|
12642
|
+
_getStrokePadding() {
|
|
12643
|
+
// Arrowheads have joins even when the shaft is a single straight line.
|
|
12644
|
+
return super._getStrokePadding(this.pointerAtBeginning() || this.pointerAtEnding()
|
|
12645
|
+
? this.miterLimit() || 10
|
|
12646
|
+
: undefined);
|
|
12647
|
+
}
|
|
12413
12648
|
_sceneFunc(ctx) {
|
|
12414
12649
|
super._sceneFunc(ctx);
|
|
12415
12650
|
const points = this.points();
|
|
@@ -12526,7 +12761,7 @@ js: import "konva/skia-backend";
|
|
|
12526
12761
|
'pointerAtBeginning',
|
|
12527
12762
|
'pointerAtEnding',
|
|
12528
12763
|
];
|
|
12529
|
-
_registerNode(Arrow);
|
|
12764
|
+
_registerNode(Arrow, true);
|
|
12530
12765
|
/**
|
|
12531
12766
|
* get/set pointerLength
|
|
12532
12767
|
* @name Konva.Arrow#pointerLength
|
|
@@ -12676,6 +12911,9 @@ js: import "konva/skia-backend";
|
|
|
12676
12911
|
* });
|
|
12677
12912
|
*/
|
|
12678
12913
|
class Circle extends Shape {
|
|
12914
|
+
_getStrokePadding() {
|
|
12915
|
+
return super._getStrokePadding(1);
|
|
12916
|
+
}
|
|
12679
12917
|
_sceneFunc(context) {
|
|
12680
12918
|
context.beginPath();
|
|
12681
12919
|
context.arc(0, 0, Math.abs(this.attrs.radius || 0), 0, Math.PI * 2, false);
|
|
@@ -12698,7 +12936,7 @@ js: import "konva/skia-backend";
|
|
|
12698
12936
|
Circle.prototype._centroid = true;
|
|
12699
12937
|
Circle.prototype.className = 'Circle';
|
|
12700
12938
|
Circle.prototype._attrsAffectingSize = ['radius'];
|
|
12701
|
-
_registerNode(Circle);
|
|
12939
|
+
_registerNode(Circle, true);
|
|
12702
12940
|
/**
|
|
12703
12941
|
* get/set radius
|
|
12704
12942
|
* @name Konva.Circle#radius
|
|
@@ -12805,6 +13043,9 @@ js: import "konva/skia-backend";
|
|
|
12805
13043
|
* });
|
|
12806
13044
|
*/
|
|
12807
13045
|
class Ellipse extends Shape {
|
|
13046
|
+
_getStrokePadding() {
|
|
13047
|
+
return super._getStrokePadding(1);
|
|
13048
|
+
}
|
|
12808
13049
|
_sceneFunc(context) {
|
|
12809
13050
|
const rx = Math.abs(this.radiusX()), ry = Math.abs(this.radiusY());
|
|
12810
13051
|
context.beginPath();
|
|
@@ -12828,7 +13069,7 @@ js: import "konva/skia-backend";
|
|
|
12828
13069
|
Ellipse.prototype.className = 'Ellipse';
|
|
12829
13070
|
Ellipse.prototype._centroid = true;
|
|
12830
13071
|
Ellipse.prototype._attrsAffectingSize = ['radiusX', 'radiusY'];
|
|
12831
|
-
_registerNode(Ellipse);
|
|
13072
|
+
_registerNode(Ellipse, true);
|
|
12832
13073
|
// add getters setters
|
|
12833
13074
|
Factory.addComponentsGetterSetter(Ellipse, 'radius', ['x', 'y']);
|
|
12834
13075
|
/**
|
|
@@ -13004,7 +13245,7 @@ js: import "konva/skia-backend";
|
|
|
13004
13245
|
super.destroy();
|
|
13005
13246
|
return this;
|
|
13006
13247
|
}
|
|
13007
|
-
_useBufferCanvas() {
|
|
13248
|
+
_useBufferCanvas(forceFill, opacity = this.getAbsoluteOpacity()) {
|
|
13008
13249
|
if (this.attrs.perfectDrawEnabled === false)
|
|
13009
13250
|
return false;
|
|
13010
13251
|
const hasCornerRadius = !!this.cornerRadius();
|
|
@@ -13012,7 +13253,10 @@ js: import "konva/skia-backend";
|
|
|
13012
13253
|
if (hasCornerRadius && hasShadow) {
|
|
13013
13254
|
return true;
|
|
13014
13255
|
}
|
|
13015
|
-
return super._useBufferCanvas(true);
|
|
13256
|
+
return super._useBufferCanvas(true, opacity);
|
|
13257
|
+
}
|
|
13258
|
+
_getStrokePadding() {
|
|
13259
|
+
return super._getStrokePadding(this.strokeScaleEnabled() ? 1 : undefined);
|
|
13016
13260
|
}
|
|
13017
13261
|
_sceneFunc(context) {
|
|
13018
13262
|
const width = this.getWidth();
|
|
@@ -13090,7 +13334,7 @@ js: import "konva/skia-backend";
|
|
|
13090
13334
|
}
|
|
13091
13335
|
Image.prototype.className = 'Image';
|
|
13092
13336
|
Image.prototype._attrsAffectingSize = ['image'];
|
|
13093
|
-
_registerNode(Image);
|
|
13337
|
+
_registerNode(Image, true);
|
|
13094
13338
|
/**
|
|
13095
13339
|
* get/set corner radius
|
|
13096
13340
|
* @method
|
|
@@ -13449,7 +13693,7 @@ js: import "konva/skia-backend";
|
|
|
13449
13693
|
if (!this.text()) {
|
|
13450
13694
|
return;
|
|
13451
13695
|
}
|
|
13452
|
-
let padding = this.padding(), fontSize = this.fontSize(), lineHeightPx = this.lineHeight() * fontSize,
|
|
13696
|
+
let padding = this.padding(), fontSize = this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, direction = this.direction(), align = this.align(), totalWidth = this.getWidth(), letterSpacing = this.letterSpacing(), charRenderFunc = this.charRenderFunc(), textDecoration = this.textDecoration(), shouldUnderline = textDecoration.indexOf('underline') !== -1, shouldLineThrough = textDecoration.indexOf('line-through') !== -1, n;
|
|
13453
13697
|
let translateY = lineHeightPx / 2;
|
|
13454
13698
|
let baseline = MIDDLE;
|
|
13455
13699
|
if (!Konva$2.legacyTextRendering) {
|
|
@@ -13470,14 +13714,7 @@ js: import "konva/skia-backend";
|
|
|
13470
13714
|
context.setAttr('font', this._getContextFont());
|
|
13471
13715
|
context.setAttr('textBaseline', baseline);
|
|
13472
13716
|
context.setAttr('textAlign', LEFT$1);
|
|
13473
|
-
|
|
13474
|
-
if (verticalAlign === MIDDLE) {
|
|
13475
|
-
alignY = (this.getHeight() - textArrLen * lineHeightPx - padding * 2) / 2;
|
|
13476
|
-
}
|
|
13477
|
-
else if (verticalAlign === BOTTOM) {
|
|
13478
|
-
alignY = this.getHeight() - textArrLen * lineHeightPx - padding * 2;
|
|
13479
|
-
}
|
|
13480
|
-
context.translate(padding, alignY + padding);
|
|
13717
|
+
context.translate(padding, this._getTextTop());
|
|
13481
13718
|
// Start the callback with the same fill that normal drawing would use.
|
|
13482
13719
|
// Assigning that color again then needs no override, including black.
|
|
13483
13720
|
if (charRenderFunc) {
|
|
@@ -13606,6 +13843,16 @@ js: import "konva/skia-backend";
|
|
|
13606
13843
|
}
|
|
13607
13844
|
}
|
|
13608
13845
|
}
|
|
13846
|
+
_getTextTop() {
|
|
13847
|
+
const padding = this.padding(), free = this.getHeight() -
|
|
13848
|
+
this.textArr.length * this.lineHeight() * this.fontSize() -
|
|
13849
|
+
padding * 2, verticalAlign = this.verticalAlign();
|
|
13850
|
+
if (verticalAlign === MIDDLE)
|
|
13851
|
+
return padding + free / 2;
|
|
13852
|
+
if (verticalAlign === BOTTOM)
|
|
13853
|
+
return padding + free;
|
|
13854
|
+
return padding;
|
|
13855
|
+
}
|
|
13609
13856
|
_getUnderlineOffset() {
|
|
13610
13857
|
var _a;
|
|
13611
13858
|
return ((_a = this.underlineOffset()) !== null && _a !== void 0 ? _a : Math.round(this.fontSize() / (!Konva$2.legacyTextRendering ? 4 : 2)));
|
|
@@ -13617,21 +13864,41 @@ js: import "konva/skia-backend";
|
|
|
13617
13864
|
return rect;
|
|
13618
13865
|
}
|
|
13619
13866
|
// the underline of the last line is drawn below the text block
|
|
13620
|
-
const fontSize = this.fontSize(), lineHeightPx = this.lineHeight() * fontSize
|
|
13621
|
-
let bottom = lines * lineHeightPx - lineHeightPx / 2
|
|
13867
|
+
const fontSize = this.fontSize(), lineHeightPx = this.lineHeight() * fontSize;
|
|
13868
|
+
let bottom = this._getTextTop() + lines * lineHeightPx - lineHeightPx / 2;
|
|
13622
13869
|
if (!Konva$2.legacyTextRendering) {
|
|
13623
13870
|
bottom += this._baselineShift;
|
|
13624
13871
|
}
|
|
13625
|
-
if (verticalAlign === MIDDLE) {
|
|
13626
|
-
bottom += (rect.height - blockHeight) / 2;
|
|
13627
|
-
}
|
|
13628
|
-
else if (verticalAlign === BOTTOM) {
|
|
13629
|
-
bottom += rect.height - blockHeight;
|
|
13630
|
-
}
|
|
13631
13872
|
bottom += this._getUnderlineOffset() + getDecorationLineWidth(fontSize) / 2;
|
|
13632
|
-
rect.height = Math.max(rect.height, bottom);
|
|
13873
|
+
rect.height = Math.max(rect.y + rect.height, bottom) - rect.y;
|
|
13633
13874
|
return rect;
|
|
13634
13875
|
}
|
|
13876
|
+
_getSelfRectForDrawing() {
|
|
13877
|
+
// Lines can be wider than the box, negative spacing moves the pen back,
|
|
13878
|
+
// and glyph ink passes the advance box (italics, accents): up to 0.6em
|
|
13879
|
+
// in common fonts, so pad by 1em.
|
|
13880
|
+
const rect = this.getSelfRect(), fontSize = this.fontSize(), padding = this.padding(), lineHeightPx = this.lineHeight() * fontSize, available = this.getWidth() - padding * 2, align = this.align(), blockHeight = this.textArr.length * lineHeightPx, top = this._getTextTop();
|
|
13881
|
+
let left = rect.x, right = rect.x + rect.width;
|
|
13882
|
+
for (const { text, width } of this.textArr) {
|
|
13883
|
+
const x = padding +
|
|
13884
|
+
(align === RIGHT$1
|
|
13885
|
+
? available - width
|
|
13886
|
+
: align === CENTER
|
|
13887
|
+
? (available - width) / 2
|
|
13888
|
+
: 0);
|
|
13889
|
+
const back = Math.min(0, this.letterSpacing()) * text.length;
|
|
13890
|
+
left = Math.min(left, x + back);
|
|
13891
|
+
right = Math.max(right, x + width - back);
|
|
13892
|
+
}
|
|
13893
|
+
const underline = this.textDecoration().includes('underline');
|
|
13894
|
+
const y = Math.min(rect.y, top + (underline ? Math.min(0, this._getUnderlineOffset()) : 0));
|
|
13895
|
+
return {
|
|
13896
|
+
x: left - fontSize,
|
|
13897
|
+
y: y - fontSize,
|
|
13898
|
+
width: right - left + fontSize * 2,
|
|
13899
|
+
height: Math.max(rect.y + rect.height, top + blockHeight) - y + fontSize * 2,
|
|
13900
|
+
};
|
|
13901
|
+
}
|
|
13635
13902
|
_hitFunc(context) {
|
|
13636
13903
|
const width = this.getWidth(), height = this.getHeight();
|
|
13637
13904
|
context.beginPath();
|
|
@@ -13912,7 +14179,11 @@ js: import "konva/skia-backend";
|
|
|
13912
14179
|
getStrokeScaleEnabled() {
|
|
13913
14180
|
return true;
|
|
13914
14181
|
}
|
|
13915
|
-
|
|
14182
|
+
_getStrokePadding() {
|
|
14183
|
+
// _strokeFunc uses a miter limit of two for glyph outlines.
|
|
14184
|
+
return super._getStrokePadding(2);
|
|
14185
|
+
}
|
|
14186
|
+
_useBufferCanvas(forceFill, opacity = this.getAbsoluteOpacity()) {
|
|
13916
14187
|
if (this.attrs.perfectDrawEnabled === false)
|
|
13917
14188
|
return false;
|
|
13918
14189
|
const hasLine = this.textDecoration().indexOf('underline') !== -1 ||
|
|
@@ -13921,10 +14192,10 @@ js: import "konva/skia-backend";
|
|
|
13921
14192
|
if (hasLine && hasShadow) {
|
|
13922
14193
|
return true;
|
|
13923
14194
|
}
|
|
13924
|
-
if (hasShadow &&
|
|
14195
|
+
if (hasShadow && opacity !== 1 && hasShadowOpacityBug()) {
|
|
13925
14196
|
return true;
|
|
13926
14197
|
}
|
|
13927
|
-
return super._useBufferCanvas();
|
|
14198
|
+
return super._useBufferCanvas(forceFill, opacity);
|
|
13928
14199
|
}
|
|
13929
14200
|
}
|
|
13930
14201
|
Text.prototype._fillFunc = _fillFunc$1;
|
|
@@ -13933,7 +14204,7 @@ js: import "konva/skia-backend";
|
|
|
13933
14204
|
// the decoration attrs are not in ATTR_CHANGE_LIST: they change the bounds
|
|
13934
14205
|
// through getSelfRect, but need no relayout
|
|
13935
14206
|
Text.prototype._attrsAffectingSize = ATTR_CHANGE_LIST$2.filter((attr) => attr !== 'width' && attr !== 'height').concat(['textDecoration', 'underlineOffset']);
|
|
13936
|
-
_registerNode(Text);
|
|
14207
|
+
_registerNode(Text, true);
|
|
13937
14208
|
// update text data for certain attr changes
|
|
13938
14209
|
Text.prototype.on(ATTR_CHANGE_LIST$2.map((attr) => attr + CHANGE_KONVA).join(' '), function () {
|
|
13939
14210
|
this._setTextData();
|
|
@@ -14406,31 +14677,29 @@ js: import "konva/skia-backend";
|
|
|
14406
14677
|
context.fillStrokeShape(this);
|
|
14407
14678
|
}
|
|
14408
14679
|
getSelfRect() {
|
|
14409
|
-
|
|
14410
|
-
|
|
14411
|
-
|
|
14412
|
-
|
|
14413
|
-
|
|
14414
|
-
|
|
14415
|
-
|
|
14416
|
-
|
|
14417
|
-
|
|
14418
|
-
x -= pointerWidth;
|
|
14419
|
-
width += pointerWidth;
|
|
14680
|
+
const pointerWidth = this.pointerWidth(), pointerHeight = this.pointerHeight(), direction = this.pointerDirection(), width = this.width(), height = this.height();
|
|
14681
|
+
// The pointer base is centred on its side and can be longer than it.
|
|
14682
|
+
if (direction === UP || direction === DOWN) {
|
|
14683
|
+
return {
|
|
14684
|
+
x: Math.min(0, (width - pointerWidth) / 2),
|
|
14685
|
+
y: direction === UP ? -pointerHeight : 0,
|
|
14686
|
+
width: Math.max(width, pointerWidth),
|
|
14687
|
+
height: height + pointerHeight,
|
|
14688
|
+
};
|
|
14420
14689
|
}
|
|
14421
|
-
|
|
14422
|
-
|
|
14690
|
+
if (direction === LEFT || direction === RIGHT) {
|
|
14691
|
+
return {
|
|
14692
|
+
x: direction === LEFT ? -pointerWidth : 0,
|
|
14693
|
+
y: Math.min(0, (height - pointerHeight) / 2),
|
|
14694
|
+
width: width + pointerWidth,
|
|
14695
|
+
height: Math.max(height, pointerHeight),
|
|
14696
|
+
};
|
|
14423
14697
|
}
|
|
14424
|
-
return {
|
|
14425
|
-
x: x,
|
|
14426
|
-
y: y,
|
|
14427
|
-
width: width,
|
|
14428
|
-
height: height,
|
|
14429
|
-
};
|
|
14698
|
+
return { x: 0, y: 0, width, height };
|
|
14430
14699
|
}
|
|
14431
14700
|
}
|
|
14432
14701
|
Tag.prototype.className = 'Tag';
|
|
14433
|
-
_registerNode(Tag);
|
|
14702
|
+
_registerNode(Tag, true);
|
|
14434
14703
|
/**
|
|
14435
14704
|
* get/set pointer direction
|
|
14436
14705
|
* @name Konva.Tag#pointerDirection
|
|
@@ -14567,6 +14836,9 @@ js: import "konva/skia-backend";
|
|
|
14567
14836
|
* });
|
|
14568
14837
|
*/
|
|
14569
14838
|
class Rect extends Shape {
|
|
14839
|
+
_getStrokePadding() {
|
|
14840
|
+
return super._getStrokePadding(this.strokeScaleEnabled() ? 1 : undefined);
|
|
14841
|
+
}
|
|
14570
14842
|
_sceneFunc(context) {
|
|
14571
14843
|
const cornerRadius = this.cornerRadius(), width = this.width(), height = this.height();
|
|
14572
14844
|
context.beginPath();
|
|
@@ -14582,7 +14854,7 @@ js: import "konva/skia-backend";
|
|
|
14582
14854
|
}
|
|
14583
14855
|
}
|
|
14584
14856
|
Rect.prototype.className = 'Rect';
|
|
14585
|
-
_registerNode(Rect);
|
|
14857
|
+
_registerNode(Rect, true);
|
|
14586
14858
|
/**
|
|
14587
14859
|
* get/set corner radius
|
|
14588
14860
|
* @method
|
|
@@ -14765,7 +15037,7 @@ js: import "konva/skia-backend";
|
|
|
14765
15037
|
RegularPolygon.prototype.className = 'RegularPolygon';
|
|
14766
15038
|
RegularPolygon.prototype._centroid = true;
|
|
14767
15039
|
RegularPolygon.prototype._attrsAffectingSize = ['radius', 'sides'];
|
|
14768
|
-
_registerNode(RegularPolygon);
|
|
15040
|
+
_registerNode(RegularPolygon, true);
|
|
14769
15041
|
/**
|
|
14770
15042
|
* get/set radius
|
|
14771
15043
|
* @method
|
|
@@ -14905,6 +15177,9 @@ js: import "konva/skia-backend";
|
|
|
14905
15177
|
* });
|
|
14906
15178
|
*/
|
|
14907
15179
|
class Ring extends Shape {
|
|
15180
|
+
_getStrokePadding() {
|
|
15181
|
+
return super._getStrokePadding(1);
|
|
15182
|
+
}
|
|
14908
15183
|
_sceneFunc(context) {
|
|
14909
15184
|
const innerRadius = Math.abs(this.innerRadius()), outerRadius = Math.abs(this.outerRadius());
|
|
14910
15185
|
context.beginPath();
|
|
@@ -14914,6 +15189,10 @@ js: import "konva/skia-backend";
|
|
|
14914
15189
|
context.closePath();
|
|
14915
15190
|
context.fillStrokeShape(this);
|
|
14916
15191
|
}
|
|
15192
|
+
getSelfRect() {
|
|
15193
|
+
const radius = Math.max(Math.abs(this.innerRadius()), Math.abs(this.outerRadius()));
|
|
15194
|
+
return { x: -radius, y: -radius, width: radius * 2, height: radius * 2 };
|
|
15195
|
+
}
|
|
14917
15196
|
getWidth() {
|
|
14918
15197
|
return Math.abs(this.outerRadius()) * 2;
|
|
14919
15198
|
}
|
|
@@ -14930,7 +15209,7 @@ js: import "konva/skia-backend";
|
|
|
14930
15209
|
Ring.prototype.className = 'Ring';
|
|
14931
15210
|
Ring.prototype._centroid = true;
|
|
14932
15211
|
Ring.prototype._attrsAffectingSize = ['innerRadius', 'outerRadius'];
|
|
14933
|
-
_registerNode(Ring);
|
|
15212
|
+
_registerNode(Ring, true);
|
|
14934
15213
|
/**
|
|
14935
15214
|
* get/set innerRadius
|
|
14936
15215
|
* @method
|
|
@@ -15124,6 +15403,9 @@ js: import "konva/skia-backend";
|
|
|
15124
15403
|
offsetY: offset[index * 2 + 1] || 0,
|
|
15125
15404
|
};
|
|
15126
15405
|
}
|
|
15406
|
+
_getStrokePadding() {
|
|
15407
|
+
return super._getStrokePadding(this.strokeScaleEnabled() ? 1 : undefined);
|
|
15408
|
+
}
|
|
15127
15409
|
_sceneFunc(context) {
|
|
15128
15410
|
const frame = this._getFrame();
|
|
15129
15411
|
if (!frame) {
|
|
@@ -15159,8 +15441,8 @@ js: import "konva/skia-backend";
|
|
|
15159
15441
|
}
|
|
15160
15442
|
: { x: 0, y: 0, width: 0, height: 0 };
|
|
15161
15443
|
}
|
|
15162
|
-
_useBufferCanvas() {
|
|
15163
|
-
return super._useBufferCanvas(true);
|
|
15444
|
+
_useBufferCanvas(forceFill, opacity = this.getAbsoluteOpacity()) {
|
|
15445
|
+
return super._useBufferCanvas(true, opacity);
|
|
15164
15446
|
}
|
|
15165
15447
|
_setInterval() {
|
|
15166
15448
|
const that = this;
|
|
@@ -15213,7 +15495,7 @@ js: import "konva/skia-backend";
|
|
|
15213
15495
|
}
|
|
15214
15496
|
}
|
|
15215
15497
|
Sprite.prototype.className = 'Sprite';
|
|
15216
|
-
_registerNode(Sprite);
|
|
15498
|
+
_registerNode(Sprite, true);
|
|
15217
15499
|
// add getters setters
|
|
15218
15500
|
Factory.addGetterSetter(Sprite, 'animation');
|
|
15219
15501
|
/**
|
|
@@ -15454,6 +15736,10 @@ js: import "konva/skia-backend";
|
|
|
15454
15736
|
context.closePath();
|
|
15455
15737
|
context.fillStrokeShape(this);
|
|
15456
15738
|
}
|
|
15739
|
+
getSelfRect() {
|
|
15740
|
+
const radius = Math.max(Math.abs(this.innerRadius()), Math.abs(this.outerRadius()));
|
|
15741
|
+
return { x: -radius, y: -radius, width: radius * 2, height: radius * 2 };
|
|
15742
|
+
}
|
|
15457
15743
|
getWidth() {
|
|
15458
15744
|
return this.outerRadius() * 2;
|
|
15459
15745
|
}
|
|
@@ -15470,7 +15756,7 @@ js: import "konva/skia-backend";
|
|
|
15470
15756
|
Star.prototype.className = 'Star';
|
|
15471
15757
|
Star.prototype._centroid = true;
|
|
15472
15758
|
Star.prototype._attrsAffectingSize = ['innerRadius', 'outerRadius'];
|
|
15473
|
-
_registerNode(Star);
|
|
15759
|
+
_registerNode(Star, true);
|
|
15474
15760
|
/**
|
|
15475
15761
|
* get/set number of points
|
|
15476
15762
|
* @name Konva.Star#numPoints
|
|
@@ -15894,6 +16180,21 @@ js: import "konva/skia-backend";
|
|
|
15894
16180
|
height: rect.height + fontSize,
|
|
15895
16181
|
};
|
|
15896
16182
|
}
|
|
16183
|
+
// Like Text: a glyph stroke is drawn with the text, so it always scales.
|
|
16184
|
+
getStrokeScaleEnabled() {
|
|
16185
|
+
return true;
|
|
16186
|
+
}
|
|
16187
|
+
_getSelfRectForDrawing() {
|
|
16188
|
+
// getSelfRect() pads glyph anchors by half the font size; ascenders,
|
|
16189
|
+
// accents and other baselines reach further from the path.
|
|
16190
|
+
const rect = this.getSelfRect(), pad = this.fontSize();
|
|
16191
|
+
return {
|
|
16192
|
+
x: rect.x - pad,
|
|
16193
|
+
y: rect.y - pad,
|
|
16194
|
+
width: rect.width + pad * 2,
|
|
16195
|
+
height: rect.height + pad * 2,
|
|
16196
|
+
};
|
|
16197
|
+
}
|
|
15897
16198
|
}
|
|
15898
16199
|
TextPath.prototype._fillFunc = _fillFunc;
|
|
15899
16200
|
TextPath.prototype._strokeFunc = _strokeFunc;
|
|
@@ -15912,7 +16213,7 @@ js: import "konva/skia-backend";
|
|
|
15912
16213
|
'fontVariant',
|
|
15913
16214
|
'direction',
|
|
15914
16215
|
];
|
|
15915
|
-
_registerNode(TextPath);
|
|
16216
|
+
_registerNode(TextPath, true);
|
|
15916
16217
|
TextPath.prototype.on('dataChange.konva', function () {
|
|
15917
16218
|
this._readDataAttribute();
|
|
15918
16219
|
this._setTextData();
|
|
@@ -16152,6 +16453,7 @@ js: import "konva/skia-backend";
|
|
|
16152
16453
|
'transformsEnabledChange',
|
|
16153
16454
|
'strokeWidthChange',
|
|
16154
16455
|
'strokeChange',
|
|
16456
|
+
'selfRectFuncChange',
|
|
16155
16457
|
'strokeLinearGradientColorStopsChange',
|
|
16156
16458
|
'strokeScaleEnabledChange',
|
|
16157
16459
|
'strokeEnabledChange',
|
|
@@ -16594,13 +16896,14 @@ js: import "konva/skia-backend";
|
|
|
16594
16896
|
// Bounds may only be reused when they are a pure function of the node's
|
|
16595
16897
|
// own size: then every change reaches us either through _setAttr or
|
|
16596
16898
|
// through the size probe below. A shape with its own getSelfRect - Line
|
|
16597
|
-
// mutates its points array in place, and a user subclass
|
|
16598
|
-
// anything at all - may change with no signal, so it is
|
|
16599
|
-
// time. Groups depend on their descendants, and a cached
|
|
16600
|
-
// suppresses descendant transform-change notifications, so
|
|
16601
|
-
// measured too.
|
|
16899
|
+
// mutates its points array in place, and a user subclass or selfRectFunc
|
|
16900
|
+
// can measure anything at all - may change with no signal, so it is
|
|
16901
|
+
// measured every time. Groups depend on their descendants, and a cached
|
|
16902
|
+
// ancestor suppresses descendant transform-change notifications, so
|
|
16903
|
+
// both are measured too.
|
|
16602
16904
|
const cacheable = node instanceof Shape &&
|
|
16603
16905
|
node.getSelfRect === Shape.prototype.getSelfRect &&
|
|
16906
|
+
!node.attrs.selfRectFunc &&
|
|
16604
16907
|
!node._hasCachedAncestor();
|
|
16605
16908
|
// width() and height() are the only inputs of the default getSelfRect and
|
|
16606
16909
|
// they can come from outside the attrs (an Image source that loads or
|
|
@@ -18059,7 +18362,7 @@ js: import "konva/skia-backend";
|
|
|
18059
18362
|
Wedge.prototype.className = 'Wedge';
|
|
18060
18363
|
Wedge.prototype._centroid = true;
|
|
18061
18364
|
Wedge.prototype._attrsAffectingSize = ['radius'];
|
|
18062
|
-
_registerNode(Wedge);
|
|
18365
|
+
_registerNode(Wedge, true);
|
|
18063
18366
|
/**
|
|
18064
18367
|
* get/set radius
|
|
18065
18368
|
* @name Konva.Wedge#radius
|