konva 10.8.0 → 10.9.1
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/konva.js +387 -248
- package/konva.min.js +4 -4
- package/lib/Animation.js +13 -10
- package/lib/Container.d.ts +1 -0
- package/lib/Container.js +22 -32
- package/lib/Context.d.ts +1 -0
- package/lib/Context.js +15 -1
- package/lib/Global.js +2 -2
- package/lib/Node.d.ts +8 -3
- package/lib/Node.js +97 -70
- package/lib/Shape.d.ts +5 -1
- package/lib/Shape.js +41 -28
- package/lib/Util.js +2 -0
- package/lib/_CoreInternals.d.ts +26 -0
- package/lib/_CoreInternals.js +26 -0
- package/lib/_FullInternals.d.ts +1 -0
- package/lib/filters/Blur.js +25 -1
- package/lib/filters/Brightness.js +8 -2
- package/lib/filters/Contrast.js +7 -3
- package/lib/filters/Emboss.js +11 -4
- package/lib/shapes/Text.js +4 -4
- package/lib/shapes/TextPath.d.ts +3 -2
- package/lib/shapes/TextPath.js +65 -40
- package/lib/shapes/Transformer.d.ts +5 -3
- package/lib/shapes/Transformer.js +49 -47
- package/package.json +1 -1
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.9.1
|
|
9
9
|
* http://konvajs.org/
|
|
10
10
|
* Licensed under the MIT
|
|
11
|
-
* Date:
|
|
11
|
+
* Date: Sat Oct 31 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.9.1',
|
|
39
39
|
isBrowser: detectBrowser(),
|
|
40
40
|
isUnminified: /param/.test(function (param) { }.toString()),
|
|
41
41
|
dblClickWindow: 400,
|
|
@@ -1392,6 +1392,8 @@ js: import "konva/skia-backend";
|
|
|
1392
1392
|
else {
|
|
1393
1393
|
currCornerRadius = i < cornerRadius.length ? cornerRadius[i] : 0;
|
|
1394
1394
|
}
|
|
1395
|
+
// a negative corner radius would throw in context.arcTo()
|
|
1396
|
+
currCornerRadius = Math.max(currCornerRadius, 0);
|
|
1395
1397
|
const maxCornerRadius = radius * Math.cos(Math.PI / sides);
|
|
1396
1398
|
// cornerRadius creates perfect circle at 1/2 radius
|
|
1397
1399
|
currCornerRadius =
|
|
@@ -2127,7 +2129,7 @@ js: import "konva/skia-backend";
|
|
|
2127
2129
|
}
|
|
2128
2130
|
}
|
|
2129
2131
|
_strokeLinearGradient(shape) {
|
|
2130
|
-
let start = shape.getStrokeLinearGradientStartPoint(), end = shape.getStrokeLinearGradientEndPoint();
|
|
2132
|
+
let start = shape._toStyleSpace(shape.getStrokeLinearGradientStartPoint()), end = shape._toStyleSpace(shape.getStrokeLinearGradientEndPoint());
|
|
2131
2133
|
if (!shape.getStrokeScaleEnabled()) {
|
|
2132
2134
|
const { a, b, c, d, e, f } = this._context.getTransform();
|
|
2133
2135
|
const transform = new Transform([a, b, c, d, e, f]);
|
|
@@ -2164,6 +2166,20 @@ js: import "konva/skia-backend";
|
|
|
2164
2166
|
this.setAttr('strokeStyle', shape.stroke());
|
|
2165
2167
|
}
|
|
2166
2168
|
}
|
|
2169
|
+
// Text decorations are drawn like the glyphs: with the fill, or with the
|
|
2170
|
+
// stroke when the text is only outlined. False when the glyphs paint nothing.
|
|
2171
|
+
_applyDecorationStyle(shape) {
|
|
2172
|
+
if (shape.hasFill()) {
|
|
2173
|
+
this.strokeStyle = this._getFillStyle(shape);
|
|
2174
|
+
}
|
|
2175
|
+
else if (shape.hasStroke()) {
|
|
2176
|
+
this._applyStrokeStyle(shape);
|
|
2177
|
+
}
|
|
2178
|
+
else {
|
|
2179
|
+
return false;
|
|
2180
|
+
}
|
|
2181
|
+
return true;
|
|
2182
|
+
}
|
|
2167
2183
|
_stroke(shape) {
|
|
2168
2184
|
const dash = shape.dash(),
|
|
2169
2185
|
// ignore strokeScaleEnabled for Text
|
|
@@ -3047,14 +3063,8 @@ js: import "konva/skia-backend";
|
|
|
3047
3063
|
let match;
|
|
3048
3064
|
while ((match = filterRegex.exec(cssFilter)) !== null) {
|
|
3049
3065
|
const [, name, argument] = match;
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
'brightness',
|
|
3053
|
-
'contrast',
|
|
3054
|
-
'grayscale',
|
|
3055
|
-
'sepia',
|
|
3056
|
-
'invert',
|
|
3057
|
-
].includes(name)) {
|
|
3066
|
+
const fallback = cssFilterFallbacks[name];
|
|
3067
|
+
if (!fallback) {
|
|
3058
3068
|
Util.warn(`CSS filter "${name}" is not supported in fallback mode. Consider using function filters for better compatibility.`);
|
|
3059
3069
|
continue;
|
|
3060
3070
|
}
|
|
@@ -3063,53 +3073,47 @@ js: import "konva/skia-backend";
|
|
|
3063
3073
|
? 0
|
|
3064
3074
|
: 1
|
|
3065
3075
|
: parseFloat(argument) / (argument.includes('%') ? 100 : 1);
|
|
3066
|
-
steps.push({
|
|
3076
|
+
steps.push({ fallback, value });
|
|
3067
3077
|
}
|
|
3068
3078
|
return function (imageData, pixelRatio = 1) {
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
if (['grayscale', 'sepia', 'invert'].includes(name)) {
|
|
3072
|
-
const amount = Math.min(1, Math.max(0, value));
|
|
3073
|
-
const data = imageData.data;
|
|
3074
|
-
for (let i = 0; i < data.length; i += 4) {
|
|
3075
|
-
const r = data[i], g = data[i + 1], b = data[i + 2];
|
|
3076
|
-
let red, green, blue;
|
|
3077
|
-
if (name === 'grayscale') {
|
|
3078
|
-
red = green = blue = 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
3079
|
-
}
|
|
3080
|
-
else if (name === 'sepia') {
|
|
3081
|
-
red = 0.393 * r + 0.769 * g + 0.189 * b;
|
|
3082
|
-
green = 0.349 * r + 0.686 * g + 0.168 * b;
|
|
3083
|
-
blue = 0.272 * r + 0.534 * g + 0.131 * b;
|
|
3084
|
-
}
|
|
3085
|
-
else {
|
|
3086
|
-
red = 255 - r;
|
|
3087
|
-
green = 255 - g;
|
|
3088
|
-
blue = 255 - b;
|
|
3089
|
-
}
|
|
3090
|
-
// CSS interpolates the color matrix before clamping the result.
|
|
3091
|
-
data[i] = r + (red - r) * amount;
|
|
3092
|
-
data[i + 1] = g + (green - g) * amount;
|
|
3093
|
-
data[i + 2] = b + (blue - b) * amount;
|
|
3094
|
-
}
|
|
3095
|
-
continue;
|
|
3096
|
-
}
|
|
3097
|
-
const filter = (_a = Konva$2.Filters) === null || _a === void 0 ? void 0 : _a[Util._capitalize(name)];
|
|
3098
|
-
if (!filter)
|
|
3099
|
-
continue;
|
|
3100
|
-
// Supply filter parameters without setters or changes to the node.
|
|
3101
|
-
const context = Object.create(this);
|
|
3102
|
-
context.attrs = { ...this.attrs };
|
|
3103
|
-
if (name === 'blur')
|
|
3104
|
-
context.attrs.blurRadius = value * 0.5;
|
|
3105
|
-
if (name === 'brightness')
|
|
3106
|
-
context.attrs.brightness = value;
|
|
3107
|
-
if (name === 'contrast')
|
|
3108
|
-
context.attrs.contrast = 100 * (Math.sqrt(value) - 1);
|
|
3109
|
-
filter.call(context, imageData, pixelRatio);
|
|
3079
|
+
for (const { fallback, value } of steps) {
|
|
3080
|
+
fallback(imageData, value, pixelRatio);
|
|
3110
3081
|
}
|
|
3111
3082
|
};
|
|
3112
3083
|
}
|
|
3084
|
+
// Fallbacks for CSS filter functions. Filter modules register theirs on
|
|
3085
|
+
// import, so the core build carries none of their code.
|
|
3086
|
+
const cssFilterFallbacks = {};
|
|
3087
|
+
function _registerCSSFilterFallback(name, fallback) {
|
|
3088
|
+
cssFilterFallbacks[name] = fallback;
|
|
3089
|
+
}
|
|
3090
|
+
for (const name of ['grayscale', 'sepia', 'invert']) {
|
|
3091
|
+
_registerCSSFilterFallback(name, (imageData, value) => {
|
|
3092
|
+
const amount = Math.min(1, Math.max(0, value));
|
|
3093
|
+
const data = imageData.data;
|
|
3094
|
+
for (let i = 0; i < data.length; i += 4) {
|
|
3095
|
+
const r = data[i], g = data[i + 1], b = data[i + 2];
|
|
3096
|
+
let red, green, blue;
|
|
3097
|
+
if (name === 'grayscale') {
|
|
3098
|
+
red = green = blue = 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
3099
|
+
}
|
|
3100
|
+
else if (name === 'sepia') {
|
|
3101
|
+
red = 0.393 * r + 0.769 * g + 0.189 * b;
|
|
3102
|
+
green = 0.349 * r + 0.686 * g + 0.168 * b;
|
|
3103
|
+
blue = 0.272 * r + 0.534 * g + 0.131 * b;
|
|
3104
|
+
}
|
|
3105
|
+
else {
|
|
3106
|
+
red = 255 - r;
|
|
3107
|
+
green = 255 - g;
|
|
3108
|
+
blue = 255 - b;
|
|
3109
|
+
}
|
|
3110
|
+
// CSS interpolates the color matrix before clamping the result.
|
|
3111
|
+
data[i] = r + (red - r) * amount;
|
|
3112
|
+
data[i + 1] = g + (green - g) * amount;
|
|
3113
|
+
data[i + 2] = b + (blue - b) * amount;
|
|
3114
|
+
}
|
|
3115
|
+
});
|
|
3116
|
+
}
|
|
3113
3117
|
// CONSTANTS
|
|
3114
3118
|
const ABSOLUTE_OPACITY = 'absoluteOpacity', ABSOLUTE_TRANSFORM = 'absoluteTransform', CHANGE = 'Change', CHILDREN = 'children', KONVA = 'konva', LISTENING = 'listening', MOUSEENTER$1 = 'mouseenter', MOUSELEAVE$1 = 'mouseleave', POINTERENTER$1 = 'pointerenter', POINTERLEAVE$1 = 'pointerleave', TOUCHENTER = 'touchenter', TOUCHLEAVE = 'touchleave', NON_BUBBLING_EVENTS = [
|
|
3115
3119
|
MOUSEENTER$1,
|
|
@@ -3239,14 +3243,44 @@ js: import "konva/skia-backend";
|
|
|
3239
3243
|
this.fire('absoluteTransformChange');
|
|
3240
3244
|
}
|
|
3241
3245
|
}
|
|
3242
|
-
static
|
|
3243
|
-
if (Node.
|
|
3244
|
-
Node.
|
|
3246
|
+
static _runAfterUpdateBatch(cb) {
|
|
3247
|
+
if (Node._updateBatchDepth > 0) {
|
|
3248
|
+
Node._pendingUpdates.add(cb);
|
|
3245
3249
|
}
|
|
3246
3250
|
else {
|
|
3247
3251
|
cb();
|
|
3248
3252
|
}
|
|
3249
3253
|
}
|
|
3254
|
+
static _flushUpdateBatch() {
|
|
3255
|
+
if (Node._updateBatchDepth > 0)
|
|
3256
|
+
return;
|
|
3257
|
+
const callbacks = Node._pendingUpdates;
|
|
3258
|
+
if (!callbacks.size)
|
|
3259
|
+
return;
|
|
3260
|
+
Node._pendingUpdates = new Set();
|
|
3261
|
+
callbacks.forEach((callback) => callback());
|
|
3262
|
+
}
|
|
3263
|
+
static _updateBatch(fn) {
|
|
3264
|
+
Node._updateBatchDepth++;
|
|
3265
|
+
try {
|
|
3266
|
+
return fn();
|
|
3267
|
+
}
|
|
3268
|
+
finally {
|
|
3269
|
+
Node._updateBatchDepth--;
|
|
3270
|
+
Node._flushUpdateBatch();
|
|
3271
|
+
}
|
|
3272
|
+
}
|
|
3273
|
+
static _beginUpdateBatch() {
|
|
3274
|
+
Node._updateBatchDepth++;
|
|
3275
|
+
let finished = false;
|
|
3276
|
+
return () => {
|
|
3277
|
+
if (finished)
|
|
3278
|
+
return;
|
|
3279
|
+
finished = true;
|
|
3280
|
+
Node._updateBatchDepth--;
|
|
3281
|
+
Node._flushUpdateBatch();
|
|
3282
|
+
};
|
|
3283
|
+
}
|
|
3250
3284
|
/**
|
|
3251
3285
|
* clear cached canvas
|
|
3252
3286
|
* @method
|
|
@@ -3739,12 +3773,17 @@ js: import "konva/skia-backend";
|
|
|
3739
3773
|
_delegate(event, selector, handler) {
|
|
3740
3774
|
const stopNode = this;
|
|
3741
3775
|
this.on(event, function (evt) {
|
|
3776
|
+
const original = evt;
|
|
3742
3777
|
const targets = evt.target.findAncestors(selector, true, stopNode);
|
|
3743
3778
|
for (let i = 0; i < targets.length; i++) {
|
|
3744
3779
|
evt = Util.cloneObject(evt);
|
|
3745
3780
|
evt.currentTarget = targets[i];
|
|
3746
3781
|
handler.call(targets[i], evt);
|
|
3747
3782
|
}
|
|
3783
|
+
// handlers get copies, so pass a cancelled bubble back
|
|
3784
|
+
if (evt.cancelBubble) {
|
|
3785
|
+
original.cancelBubble = true;
|
|
3786
|
+
}
|
|
3748
3787
|
});
|
|
3749
3788
|
return this;
|
|
3750
3789
|
}
|
|
@@ -4037,18 +4076,20 @@ js: import "konva/skia-backend";
|
|
|
4037
4076
|
func();
|
|
4038
4077
|
return;
|
|
4039
4078
|
}
|
|
4040
|
-
|
|
4041
|
-
|
|
4042
|
-
|
|
4043
|
-
|
|
4044
|
-
|
|
4045
|
-
|
|
4046
|
-
|
|
4047
|
-
this._needClearTransformCache
|
|
4048
|
-
|
|
4049
|
-
|
|
4079
|
+
Node._updateBatch(() => {
|
|
4080
|
+
this._batchingTransformChange = true;
|
|
4081
|
+
try {
|
|
4082
|
+
func();
|
|
4083
|
+
}
|
|
4084
|
+
finally {
|
|
4085
|
+
this._batchingTransformChange = false;
|
|
4086
|
+
if (this._needClearTransformCache) {
|
|
4087
|
+
this._needClearTransformCache = false;
|
|
4088
|
+
this._clearCache(TRANSFORM);
|
|
4089
|
+
this._clearSelfAndDescendantCache(ABSOLUTE_TRANSFORM);
|
|
4090
|
+
}
|
|
4050
4091
|
}
|
|
4051
|
-
}
|
|
4092
|
+
});
|
|
4052
4093
|
}
|
|
4053
4094
|
setPosition(pos) {
|
|
4054
4095
|
this._batchTransformChanges(() => {
|
|
@@ -5465,12 +5506,13 @@ js: import "konva/skia-backend";
|
|
|
5465
5506
|
}
|
|
5466
5507
|
// Number of registered observers. The ancestor walk is skipped while it is 0.
|
|
5467
5508
|
Node._subtreeObserverCount = 0;
|
|
5468
|
-
// Perf:
|
|
5469
|
-
// .Transformer
|
|
5470
|
-
//
|
|
5471
|
-
//
|
|
5472
|
-
Node.
|
|
5473
|
-
|
|
5509
|
+
// Perf: while a batch is open, work that depends on many nodes (a Konva
|
|
5510
|
+
// .Transformer refresh) is queued and runs once when the outermost scope
|
|
5511
|
+
// ends, instead of once per node change. Scopes are the callers of
|
|
5512
|
+
// _updateBatch() and _beginUpdateBatch().
|
|
5513
|
+
Node._updateBatchDepth = 0;
|
|
5514
|
+
// a Set, so a callback queued once per change runs once per batch
|
|
5515
|
+
Node._pendingUpdates = new Set();
|
|
5474
5516
|
// keyed by prototype: subclasses that share a nodeType (every shape class)
|
|
5475
5517
|
// have their own listeners
|
|
5476
5518
|
Node.protoListenerMap = new WeakMap();
|
|
@@ -5894,6 +5936,7 @@ js: import "konva/skia-backend";
|
|
|
5894
5936
|
* get/set filters. Supports function filters, CSS filter strings, or mixed arrays.
|
|
5895
5937
|
* CSS filters are applied using native browser performance when possible, function filters use ImageData manipulation.
|
|
5896
5938
|
* CSS filters automatically fall back to function filters in unsupported browsers.
|
|
5939
|
+
* The fallback covers blur, brightness, contrast, grayscale, sepia and invert. A core build needs the Blur, Brightness and Contrast filters imported for the first three.
|
|
5897
5940
|
* Blur radii, pixelation sizes and CSS lengths use node coordinates, independent of cache pixelRatio.
|
|
5898
5941
|
* Custom filters receive (imageData, pixelRatio). ImageData contains full-resolution backing pixels.
|
|
5899
5942
|
* @name Konva.Node#filters
|
|
@@ -6099,17 +6142,7 @@ js: import "konva/skia-backend";
|
|
|
6099
6142
|
* @name Konva.Container#removeChildren
|
|
6100
6143
|
*/
|
|
6101
6144
|
removeChildren() {
|
|
6102
|
-
this.
|
|
6103
|
-
// reset parent to prevent many _setChildrenIndices calls
|
|
6104
|
-
child.parent = null;
|
|
6105
|
-
child.index = 0;
|
|
6106
|
-
child.remove();
|
|
6107
|
-
});
|
|
6108
|
-
this.children = [];
|
|
6109
|
-
// because all children were detached from parent, request draw via container
|
|
6110
|
-
this._notifySubtreeChange();
|
|
6111
|
-
this._requestDraw();
|
|
6112
|
-
return this;
|
|
6145
|
+
return this._clearChildren('remove');
|
|
6113
6146
|
}
|
|
6114
6147
|
/**
|
|
6115
6148
|
* destroy all children nodes.
|
|
@@ -6117,17 +6150,22 @@ js: import "konva/skia-backend";
|
|
|
6117
6150
|
* @name Konva.Container#destroyChildren
|
|
6118
6151
|
*/
|
|
6119
6152
|
destroyChildren() {
|
|
6120
|
-
this.
|
|
6121
|
-
|
|
6122
|
-
|
|
6123
|
-
|
|
6124
|
-
|
|
6153
|
+
return this._clearChildren('destroy');
|
|
6154
|
+
}
|
|
6155
|
+
_clearChildren(dispose) {
|
|
6156
|
+
return Node._updateBatch(() => {
|
|
6157
|
+
this.children.forEach((child) => {
|
|
6158
|
+
// reset parent to prevent many _setChildrenIndices calls
|
|
6159
|
+
child.parent = null;
|
|
6160
|
+
child.index = 0;
|
|
6161
|
+
child[dispose]();
|
|
6162
|
+
});
|
|
6163
|
+
this.children = [];
|
|
6164
|
+
// because all children were detached from parent, request draw via container
|
|
6165
|
+
this._notifySubtreeChange();
|
|
6166
|
+
this._requestDraw();
|
|
6167
|
+
return this;
|
|
6125
6168
|
});
|
|
6126
|
-
this.children = [];
|
|
6127
|
-
// because all children were detached from parent, request draw via container
|
|
6128
|
-
this._notifySubtreeChange();
|
|
6129
|
-
this._requestDraw();
|
|
6130
|
-
return this;
|
|
6131
6169
|
}
|
|
6132
6170
|
/**
|
|
6133
6171
|
* add a child and children into container
|
|
@@ -6332,12 +6370,12 @@ js: import "konva/skia-backend";
|
|
|
6332
6370
|
}
|
|
6333
6371
|
_clearSelfAndDescendantCache(attr) {
|
|
6334
6372
|
var _a;
|
|
6335
|
-
// Perf:
|
|
6336
|
-
//
|
|
6337
|
-
//
|
|
6373
|
+
// Perf: an absoluteTransform cascade is an update batch, so a listener on
|
|
6374
|
+
// one of N descendants defers its work until the outermost walk returns.
|
|
6375
|
+
// try/finally so depth/flush survive listener exceptions.
|
|
6338
6376
|
const isAbsTransform = attr === undefined || attr === 'absoluteTransform';
|
|
6339
6377
|
if (isAbsTransform)
|
|
6340
|
-
Node.
|
|
6378
|
+
Node._updateBatchDepth++;
|
|
6341
6379
|
try {
|
|
6342
6380
|
super._clearSelfAndDescendantCache(attr);
|
|
6343
6381
|
// a cached container is drawn from its bitmap, so its descendants keep
|
|
@@ -6350,13 +6388,8 @@ js: import "konva/skia-backend";
|
|
|
6350
6388
|
});
|
|
6351
6389
|
}
|
|
6352
6390
|
finally {
|
|
6353
|
-
if (isAbsTransform && --Node.
|
|
6354
|
-
|
|
6355
|
-
if (callbacks.length) {
|
|
6356
|
-
Node._pendingAfterCascade = [];
|
|
6357
|
-
for (let i = 0; i < callbacks.length; i++)
|
|
6358
|
-
callbacks[i]();
|
|
6359
|
-
}
|
|
6391
|
+
if (isAbsTransform && --Node._updateBatchDepth === 0) {
|
|
6392
|
+
Node._flushUpdateBatch();
|
|
6360
6393
|
}
|
|
6361
6394
|
}
|
|
6362
6395
|
}
|
|
@@ -7852,44 +7885,54 @@ js: import "konva/skia-backend";
|
|
|
7852
7885
|
this.shadowOffsetX() ||
|
|
7853
7886
|
this.shadowOffsetY()));
|
|
7854
7887
|
}
|
|
7888
|
+
_toStyleSpace(point) {
|
|
7889
|
+
return this._styleTransform ? this._styleTransform.point(point) : point;
|
|
7890
|
+
}
|
|
7891
|
+
// Unlike a gradient, a pattern can be moved after it is created, so one
|
|
7892
|
+
// pattern serves every space it is drawn in (see _styleTransform).
|
|
7855
7893
|
_getFillPattern() {
|
|
7856
|
-
|
|
7894
|
+
const pattern = this._getCache(patternImage, this._createFillPattern);
|
|
7895
|
+
return pattern && this._setFillPatternTransform(pattern);
|
|
7857
7896
|
}
|
|
7858
|
-
|
|
7897
|
+
_createFillPattern() {
|
|
7859
7898
|
if (this.fillPatternImage()) {
|
|
7860
|
-
|
|
7861
|
-
|
|
7862
|
-
|
|
7863
|
-
|
|
7864
|
-
|
|
7865
|
-
|
|
7866
|
-
|
|
7867
|
-
|
|
7868
|
-
|
|
7869
|
-
|
|
7870
|
-
|
|
7871
|
-
|
|
7872
|
-
|
|
7873
|
-
|
|
7874
|
-
|
|
7875
|
-
|
|
7876
|
-
|
|
7877
|
-
|
|
7878
|
-
:
|
|
7879
|
-
|
|
7880
|
-
|
|
7881
|
-
|
|
7899
|
+
return getDummyContext$1().createPattern(this.fillPatternImage(), this.fillPatternRepeat() || 'repeat');
|
|
7900
|
+
}
|
|
7901
|
+
}
|
|
7902
|
+
_setFillPatternTransform(pattern) {
|
|
7903
|
+
var _a;
|
|
7904
|
+
if (pattern.setTransform) {
|
|
7905
|
+
const tr = ((_a = this._styleTransform) === null || _a === void 0 ? void 0 : _a.copy()) || new Transform();
|
|
7906
|
+
tr.translate(this.fillPatternX(), this.fillPatternY());
|
|
7907
|
+
tr.rotate(Konva$2.getAngle(this.fillPatternRotation()));
|
|
7908
|
+
tr.scale(this.fillPatternScaleX(), this.fillPatternScaleY());
|
|
7909
|
+
tr.translate(-1 * this.fillPatternOffsetX(), -1 * this.fillPatternOffsetY());
|
|
7910
|
+
const m = tr.getMatrix();
|
|
7911
|
+
const matrix = typeof DOMMatrix === 'undefined'
|
|
7912
|
+
? {
|
|
7913
|
+
a: m[0], // Horizontal scaling. A value of 1 results in no scaling.
|
|
7914
|
+
b: m[1], // Vertical skewing.
|
|
7915
|
+
c: m[2], // Horizontal skewing.
|
|
7916
|
+
d: m[3],
|
|
7917
|
+
e: m[4], // Horizontal translation (moving).
|
|
7918
|
+
f: m[5], // Vertical translation (moving).
|
|
7919
|
+
}
|
|
7920
|
+
: new DOMMatrix(m);
|
|
7921
|
+
pattern.setTransform(matrix);
|
|
7882
7922
|
}
|
|
7923
|
+
return pattern;
|
|
7883
7924
|
}
|
|
7884
7925
|
_getLinearGradient() {
|
|
7926
|
+
if (this._styleTransform)
|
|
7927
|
+
return this.__getLinearGradient();
|
|
7885
7928
|
return this._getCache(linearGradient, this.__getLinearGradient);
|
|
7886
7929
|
}
|
|
7887
7930
|
__getLinearGradient() {
|
|
7888
7931
|
const colorStops = this.fillLinearGradientColorStops();
|
|
7889
7932
|
if (colorStops) {
|
|
7890
7933
|
const ctx = getDummyContext$1();
|
|
7891
|
-
const start = this.fillLinearGradientStartPoint();
|
|
7892
|
-
const end = this.fillLinearGradientEndPoint();
|
|
7934
|
+
const start = this._toStyleSpace(this.fillLinearGradientStartPoint());
|
|
7935
|
+
const end = this._toStyleSpace(this.fillLinearGradientEndPoint());
|
|
7893
7936
|
const grd = ctx.createLinearGradient(start.x, start.y, end.x, end.y);
|
|
7894
7937
|
// build color stops
|
|
7895
7938
|
for (let n = 0; n < colorStops.length; n += 2) {
|
|
@@ -7899,14 +7942,17 @@ js: import "konva/skia-backend";
|
|
|
7899
7942
|
}
|
|
7900
7943
|
}
|
|
7901
7944
|
_getRadialGradient() {
|
|
7945
|
+
if (this._styleTransform)
|
|
7946
|
+
return this.__getRadialGradient();
|
|
7902
7947
|
return this._getCache(radialGradient, this.__getRadialGradient);
|
|
7903
7948
|
}
|
|
7904
7949
|
__getRadialGradient() {
|
|
7905
7950
|
const colorStops = this.fillRadialGradientColorStops();
|
|
7906
7951
|
if (colorStops) {
|
|
7907
7952
|
const ctx = getDummyContext$1();
|
|
7908
|
-
|
|
7909
|
-
const
|
|
7953
|
+
// a rigid transform keeps the radii
|
|
7954
|
+
const start = this._toStyleSpace(this.fillRadialGradientStartPoint());
|
|
7955
|
+
const end = this._toStyleSpace(this.fillRadialGradientEndPoint());
|
|
7910
7956
|
const grd = ctx.createRadialGradient(start.x, start.y, this.fillRadialGradientStartRadius(), end.x, end.y, this.fillRadialGradientEndRadius());
|
|
7911
7957
|
// build color stops
|
|
7912
7958
|
for (let n = 0; n < colorStops.length; n += 2) {
|
|
@@ -10232,16 +10278,18 @@ js: import "konva/skia-backend";
|
|
|
10232
10278
|
const layersToDraw = new Set();
|
|
10233
10279
|
// an animation may stop or restart itself, or another one, inside its
|
|
10234
10280
|
// function: each one runs at most once per frame, a stopped one not at all
|
|
10235
|
-
|
|
10236
|
-
|
|
10237
|
-
|
|
10238
|
-
|
|
10239
|
-
|
|
10240
|
-
|
|
10241
|
-
|
|
10242
|
-
|
|
10243
|
-
|
|
10244
|
-
|
|
10281
|
+
Node._updateBatch(() => {
|
|
10282
|
+
Array.from(this.animations).forEach((anim) => {
|
|
10283
|
+
if (!this.animations.has(anim)) {
|
|
10284
|
+
return;
|
|
10285
|
+
}
|
|
10286
|
+
anim._updateFrameObject(now());
|
|
10287
|
+
// the function returns false to skip the redraw
|
|
10288
|
+
if (anim.func && anim.func.call(anim, anim.frame) === false) {
|
|
10289
|
+
return;
|
|
10290
|
+
}
|
|
10291
|
+
anim.layers.forEach((layer) => layer && layersToDraw.add(layer));
|
|
10292
|
+
});
|
|
10245
10293
|
});
|
|
10246
10294
|
layersToDraw.forEach((layer) => layer.batchDraw());
|
|
10247
10295
|
}
|
|
@@ -11014,6 +11062,32 @@ js: import "konva/skia-backend";
|
|
|
11014
11062
|
|
|
11015
11063
|
// what is core parts of Konva?
|
|
11016
11064
|
const Konva$1 = Util._assign(Konva$2, {
|
|
11065
|
+
/**
|
|
11066
|
+
* Defer automatic Konva.Transformer updates across many synchronous node changes
|
|
11067
|
+
* and run them once when the returned function is called.
|
|
11068
|
+
* A Transformer normally updates after every change of an attached node, so a loop
|
|
11069
|
+
* over N selected nodes costs N updates, each measuring all N nodes. In a batch it costs one.
|
|
11070
|
+
* A single setAttrs(), position(), destroyChildren(), removeChildren() call or animation frame is
|
|
11071
|
+
* already batched; use this for anything else, for example a React commit or an undo.
|
|
11072
|
+
* Attributes and change events stay synchronous. Inside the batch, the Transformer's own
|
|
11073
|
+
* x(), y(), width(), height() and getClientRect() are computed on read; its anchors are laid out
|
|
11074
|
+
* when the batch finishes, or earlier if something draws or measures them.
|
|
11075
|
+
* Change events fire inside the batch, so a listener sees the new attributes and the
|
|
11076
|
+
* Transformer's box, but not its anchors; call transformer.update() there if it needs them.
|
|
11077
|
+
* Batches nest. Call the returned function in a finally block, and do not keep a batch
|
|
11078
|
+
* open across an await or an animation frame.
|
|
11079
|
+
* @method
|
|
11080
|
+
* @name Konva.beginUpdateBatch
|
|
11081
|
+
* @returns {Function} finishes the batch and runs the pending updates
|
|
11082
|
+
* @example
|
|
11083
|
+
* const finish = Konva.beginUpdateBatch();
|
|
11084
|
+
* try {
|
|
11085
|
+
* selectedNodes.forEach((node) => node.width(100));
|
|
11086
|
+
* } finally {
|
|
11087
|
+
* finish();
|
|
11088
|
+
* }
|
|
11089
|
+
*/
|
|
11090
|
+
beginUpdateBatch: Node._beginUpdateBatch,
|
|
11017
11091
|
Util,
|
|
11018
11092
|
Transform,
|
|
11019
11093
|
Node,
|
|
@@ -13509,7 +13583,7 @@ js: import "konva/skia-backend";
|
|
|
13509
13583
|
// constants
|
|
13510
13584
|
const AUTO = 'auto',
|
|
13511
13585
|
//CANVAS = 'canvas',
|
|
13512
|
-
CENTER = 'center', INHERIT = 'inherit', JUSTIFY = 'justify', CHANGE_KONVA = 'Change.konva', CONTEXT_2D = '2d', DASH = '-', LEFT$1 = 'left', TEXT = 'text', TEXT_UPPER = 'Text', TOP = 'top', BOTTOM = 'bottom', MIDDLE = 'middle', NORMAL$1 = 'normal', PX_SPACE = 'px ', SPACE = ' ', RIGHT$1 = 'right', RTL = 'rtl', WORD = 'word', CHAR = 'char', NONE$1 = 'none', ELLIPSIS = '…', ATTR_CHANGE_LIST$
|
|
13586
|
+
CENTER = 'center', INHERIT = 'inherit', JUSTIFY = 'justify', CHANGE_KONVA = 'Change.konva', CONTEXT_2D = '2d', DASH = '-', LEFT$1 = 'left', TEXT = 'text', TEXT_UPPER = 'Text', TOP = 'top', BOTTOM = 'bottom', MIDDLE = 'middle', NORMAL$1 = 'normal', PX_SPACE = 'px ', SPACE = ' ', RIGHT$1 = 'right', RTL = 'rtl', WORD = 'word', CHAR = 'char', NONE$1 = 'none', ELLIPSIS = '…', ATTR_CHANGE_LIST$3 = [
|
|
13513
13587
|
'direction',
|
|
13514
13588
|
'fontFamily',
|
|
13515
13589
|
'fontSize',
|
|
@@ -13795,8 +13869,8 @@ js: import "konva/skia-backend";
|
|
|
13795
13869
|
const lineWidth = align === JUSTIFY && !lastLine ? totalWidth - padding * 2 : width;
|
|
13796
13870
|
context.lineTo(x + Math.round(lineWidth), y);
|
|
13797
13871
|
context.lineWidth = getDecorationLineWidth(fontSize);
|
|
13798
|
-
|
|
13799
|
-
|
|
13872
|
+
if (context._applyDecorationStyle(this))
|
|
13873
|
+
context.stroke();
|
|
13800
13874
|
context.restore();
|
|
13801
13875
|
}
|
|
13802
13876
|
// store the starting x position for line-through which is drawn after text
|
|
@@ -13874,8 +13948,8 @@ js: import "konva/skia-backend";
|
|
|
13874
13948
|
const lineWidth = align === JUSTIFY && !lastLine ? totalWidth - padding * 2 : width;
|
|
13875
13949
|
context.lineTo(x + Math.round(lineWidth), translateY + lineTranslateY + yOffset);
|
|
13876
13950
|
context.lineWidth = getDecorationLineWidth(fontSize);
|
|
13877
|
-
|
|
13878
|
-
|
|
13951
|
+
if (context._applyDecorationStyle(this))
|
|
13952
|
+
context.stroke();
|
|
13879
13953
|
context.restore();
|
|
13880
13954
|
}
|
|
13881
13955
|
context.restore();
|
|
@@ -14244,10 +14318,10 @@ js: import "konva/skia-backend";
|
|
|
14244
14318
|
Text.prototype.className = TEXT_UPPER;
|
|
14245
14319
|
// the decoration attrs are not in ATTR_CHANGE_LIST: they change the bounds
|
|
14246
14320
|
// through getSelfRect, but need no relayout
|
|
14247
|
-
Text.prototype._attrsAffectingSize = ATTR_CHANGE_LIST$
|
|
14321
|
+
Text.prototype._attrsAffectingSize = ATTR_CHANGE_LIST$3.filter((attr) => attr !== 'width' && attr !== 'height').concat(['textDecoration', 'underlineOffset']);
|
|
14248
14322
|
_registerNode(Text, true);
|
|
14249
14323
|
// update text data for certain attr changes
|
|
14250
|
-
Text.prototype.on(ATTR_CHANGE_LIST$
|
|
14324
|
+
Text.prototype.on(ATTR_CHANGE_LIST$3.map((attr) => attr + CHANGE_KONVA).join(' '), function () {
|
|
14251
14325
|
this._setTextData();
|
|
14252
14326
|
});
|
|
14253
14327
|
/**
|
|
@@ -14524,14 +14598,14 @@ js: import "konva/skia-backend";
|
|
|
14524
14598
|
Factory.addGetterSetter(Text, 'charRenderFunc', undefined);
|
|
14525
14599
|
|
|
14526
14600
|
// constants
|
|
14527
|
-
const ATTR_CHANGE_LIST$
|
|
14601
|
+
const ATTR_CHANGE_LIST$2 = [
|
|
14528
14602
|
...Text.prototype._attrsAffectingSize,
|
|
14529
14603
|
'width',
|
|
14530
14604
|
'height',
|
|
14531
14605
|
'pointerDirection',
|
|
14532
14606
|
'pointerWidth',
|
|
14533
14607
|
'pointerHeight',
|
|
14534
|
-
], CHANGE_EVENTS = ATTR_CHANGE_LIST$
|
|
14608
|
+
], CHANGE_EVENTS = ATTR_CHANGE_LIST$2.map((attr) => attr + 'Change.konva').join(' '), NONE = 'none', UP = 'up', RIGHT = 'right', DOWN = 'down', LEFT = 'left';
|
|
14535
14609
|
/**
|
|
14536
14610
|
* Label constructor. Labels are groups that contain a Text and Tag shape
|
|
14537
14611
|
* @constructor
|
|
@@ -15996,40 +16070,49 @@ js: import "konva/skia-backend";
|
|
|
15996
16070
|
context.setAttr('textAlign', 'left');
|
|
15997
16071
|
context.save();
|
|
15998
16072
|
const textDecoration = this.textDecoration();
|
|
15999
|
-
const fill = this.fill();
|
|
16000
16073
|
const fontSize = this.fontSize();
|
|
16074
|
+
const underlineOffset = this._getUnderlineOffset();
|
|
16001
16075
|
const glyphInfo = this.glyphInfo;
|
|
16002
16076
|
const hasUnderline = textDecoration.indexOf('underline') !== -1;
|
|
16003
16077
|
const hasLineThrough = textDecoration.indexOf('line-through') !== -1;
|
|
16004
16078
|
if (hasUnderline) {
|
|
16005
16079
|
context.beginPath();
|
|
16006
16080
|
}
|
|
16007
|
-
|
|
16008
|
-
|
|
16009
|
-
|
|
16010
|
-
|
|
16011
|
-
|
|
16012
|
-
|
|
16013
|
-
|
|
16014
|
-
|
|
16015
|
-
|
|
16016
|
-
|
|
16081
|
+
try {
|
|
16082
|
+
for (let i = 0; i < glyphInfo.length; i++) {
|
|
16083
|
+
context.save();
|
|
16084
|
+
const p0 = glyphInfo[i].p0;
|
|
16085
|
+
const rotation = glyphInfo[i].rotation;
|
|
16086
|
+
context.translate(p0.x, p0.y);
|
|
16087
|
+
context.rotate(rotation);
|
|
16088
|
+
this.partialText = glyphInfo[i].text;
|
|
16089
|
+
// keep gradients and patterns in the shape's space, not the glyph's
|
|
16090
|
+
this._styleTransform = new Transform()
|
|
16091
|
+
.rotate(-rotation)
|
|
16092
|
+
.translate(-p0.x, -p0.y);
|
|
16093
|
+
context.fillStrokeShape(this);
|
|
16094
|
+
if (hasUnderline) {
|
|
16095
|
+
if (i === 0) {
|
|
16096
|
+
context.moveTo(0, underlineOffset);
|
|
16097
|
+
}
|
|
16098
|
+
context.lineTo(glyphInfo[i].width, underlineOffset);
|
|
16017
16099
|
}
|
|
16018
|
-
context.
|
|
16100
|
+
context.restore();
|
|
16101
|
+
//// To assist with debugging visually, uncomment following
|
|
16102
|
+
//
|
|
16103
|
+
// if (i % 2) context.strokeStyle = 'cyan';
|
|
16104
|
+
// else context.strokeStyle = 'green';
|
|
16105
|
+
// var p1 = glyphInfo[i].p1;
|
|
16106
|
+
// context.moveTo(p0.x, p0.y);
|
|
16107
|
+
// context.lineTo(p1.x, p1.y);
|
|
16108
|
+
// context.stroke();
|
|
16019
16109
|
}
|
|
16020
|
-
context.restore();
|
|
16021
|
-
//// To assist with debugging visually, uncomment following
|
|
16022
|
-
//
|
|
16023
|
-
// if (i % 2) context.strokeStyle = 'cyan';
|
|
16024
|
-
// else context.strokeStyle = 'green';
|
|
16025
|
-
// var p1 = glyphInfo[i].p1;
|
|
16026
|
-
// context.moveTo(p0.x, p0.y);
|
|
16027
|
-
// context.lineTo(p1.x, p1.y);
|
|
16028
|
-
// context.stroke();
|
|
16029
16110
|
}
|
|
16030
|
-
|
|
16031
|
-
|
|
16032
|
-
|
|
16111
|
+
finally {
|
|
16112
|
+
this._styleTransform = undefined;
|
|
16113
|
+
}
|
|
16114
|
+
context.lineWidth = getDecorationLineWidth(fontSize);
|
|
16115
|
+
if (hasUnderline && context._applyDecorationStyle(this)) {
|
|
16033
16116
|
context.stroke();
|
|
16034
16117
|
}
|
|
16035
16118
|
if (hasLineThrough) {
|
|
@@ -16045,9 +16128,8 @@ js: import "konva/skia-backend";
|
|
|
16045
16128
|
context.lineTo(glyphInfo[i].width, 0);
|
|
16046
16129
|
context.restore();
|
|
16047
16130
|
}
|
|
16048
|
-
context.
|
|
16049
|
-
|
|
16050
|
-
context.stroke();
|
|
16131
|
+
if (context._applyDecorationStyle(this))
|
|
16132
|
+
context.stroke();
|
|
16051
16133
|
}
|
|
16052
16134
|
context.restore();
|
|
16053
16135
|
}
|
|
@@ -16214,12 +16296,30 @@ js: import "konva/skia-backend";
|
|
|
16214
16296
|
});
|
|
16215
16297
|
const rect = Util._getPointsRect(points);
|
|
16216
16298
|
const fontSize = this.fontSize();
|
|
16217
|
-
|
|
16218
|
-
|
|
16219
|
-
|
|
16220
|
-
|
|
16221
|
-
|
|
16222
|
-
|
|
16299
|
+
let x = rect.x - fontSize / 2, y = rect.y - fontSize / 2, right = rect.x + rect.width + fontSize / 2, bottom = rect.y + rect.height + fontSize / 2;
|
|
16300
|
+
if (this.textDecoration().indexOf('underline') !== -1) {
|
|
16301
|
+
// the underline is drawn below the glyphs, past the padding
|
|
16302
|
+
const lineWidth = getDecorationLineWidth(fontSize), lineY = this._getUnderlineOffset() - lineWidth / 2;
|
|
16303
|
+
this.glyphInfo.forEach(function (info) {
|
|
16304
|
+
const line = new Transform()
|
|
16305
|
+
.translate(info.p0.x, info.p0.y)
|
|
16306
|
+
.rotate(info.rotation)
|
|
16307
|
+
._getTransformedRect({
|
|
16308
|
+
x: 0,
|
|
16309
|
+
y: lineY,
|
|
16310
|
+
width: info.width,
|
|
16311
|
+
height: lineWidth,
|
|
16312
|
+
});
|
|
16313
|
+
x = Math.min(x, line.x);
|
|
16314
|
+
y = Math.min(y, line.y);
|
|
16315
|
+
right = Math.max(right, line.x + line.width);
|
|
16316
|
+
bottom = Math.max(bottom, line.y + line.height);
|
|
16317
|
+
});
|
|
16318
|
+
}
|
|
16319
|
+
return { x, y, width: right - x, height: bottom - y };
|
|
16320
|
+
}
|
|
16321
|
+
_getUnderlineOffset() {
|
|
16322
|
+
return this.fontSize() / 2 + 1;
|
|
16223
16323
|
}
|
|
16224
16324
|
// Like Text: a glyph stroke is drawn with the text, so it always scales.
|
|
16225
16325
|
getStrokeScaleEnabled() {
|
|
@@ -16242,10 +16342,9 @@ js: import "konva/skia-backend";
|
|
|
16242
16342
|
TextPath.prototype._fillFuncHit = _fillFunc;
|
|
16243
16343
|
TextPath.prototype._strokeFuncHit = _strokeFunc;
|
|
16244
16344
|
TextPath.prototype.className = 'TextPath';
|
|
16245
|
-
|
|
16345
|
+
const ATTR_CHANGE_LIST$1 = [
|
|
16246
16346
|
'text',
|
|
16247
16347
|
'fontSize',
|
|
16248
|
-
'data',
|
|
16249
16348
|
'align',
|
|
16250
16349
|
'letterSpacing',
|
|
16251
16350
|
'kerningFunc',
|
|
@@ -16254,16 +16353,16 @@ js: import "konva/skia-backend";
|
|
|
16254
16353
|
'fontVariant',
|
|
16255
16354
|
'direction',
|
|
16256
16355
|
];
|
|
16356
|
+
// data relayouts in its own listener; textDecoration changes the bounds
|
|
16357
|
+
// through getSelfRect, but needs no relayout
|
|
16358
|
+
TextPath.prototype._attrsAffectingSize = ATTR_CHANGE_LIST$1.concat('data', 'textDecoration');
|
|
16257
16359
|
_registerNode(TextPath, true);
|
|
16258
16360
|
TextPath.prototype.on('dataChange.konva', function () {
|
|
16259
16361
|
this._readDataAttribute();
|
|
16260
16362
|
this._setTextData();
|
|
16261
16363
|
});
|
|
16262
16364
|
// update text data for certain attr changes
|
|
16263
|
-
TextPath.prototype.on(
|
|
16264
|
-
.filter((attr) => attr !== 'data')
|
|
16265
|
-
.map((attr) => attr + 'Change.konva')
|
|
16266
|
-
.join(' '), function () {
|
|
16365
|
+
TextPath.prototype.on(ATTR_CHANGE_LIST$1.map((attr) => attr + 'Change.konva').join(' '), function () {
|
|
16267
16366
|
this._setTextData();
|
|
16268
16367
|
});
|
|
16269
16368
|
/**
|
|
@@ -16737,14 +16836,14 @@ js: import "konva/skia-backend";
|
|
|
16737
16836
|
// rendered in another window than the one Konva was imported into
|
|
16738
16837
|
this._transformWindow = null;
|
|
16739
16838
|
this._elementsCreated = false;
|
|
16740
|
-
|
|
16741
|
-
|
|
16742
|
-
this._subtreeChanged = false;
|
|
16839
|
+
// the layout is stale; the next sync point runs _update() (see _syncUpdate)
|
|
16840
|
+
this._updatePending = false;
|
|
16743
16841
|
this._createElements();
|
|
16744
16842
|
// bindings
|
|
16745
16843
|
this._handleMouseMove = this._handleMouseMove.bind(this);
|
|
16746
16844
|
this._handleMouseUp = this._handleMouseUp.bind(this);
|
|
16747
16845
|
this.update = this.update.bind(this);
|
|
16846
|
+
this._syncUpdate = this._syncUpdate.bind(this);
|
|
16748
16847
|
// update transformer data for certain attr changes
|
|
16749
16848
|
this.on(ATTR_CHANGE_LIST, (event) => {
|
|
16750
16849
|
if (event.type === 'ignoreStrokeChange')
|
|
@@ -16800,12 +16899,7 @@ js: import "konva/skia-backend";
|
|
|
16800
16899
|
return true;
|
|
16801
16900
|
});
|
|
16802
16901
|
this._nodes = nodes = filteredNodes;
|
|
16803
|
-
|
|
16804
|
-
this.rotation(nodes[0].getAbsoluteRotation());
|
|
16805
|
-
}
|
|
16806
|
-
else {
|
|
16807
|
-
this.rotation(0);
|
|
16808
|
-
}
|
|
16902
|
+
this._resetRotation();
|
|
16809
16903
|
this._nodes.forEach((node) => {
|
|
16810
16904
|
const onChange = () => {
|
|
16811
16905
|
var _a;
|
|
@@ -16817,6 +16911,7 @@ js: import "konva/skia-backend";
|
|
|
16817
16911
|
(_a = this._nodeRectCache) === null || _a === void 0 ? void 0 : _a.delete(node);
|
|
16818
16912
|
return;
|
|
16819
16913
|
}
|
|
16914
|
+
// unlike _resetRotation, a multi-node box keeps its rotation here
|
|
16820
16915
|
if (this.nodes().length === 1 && this.useSingleNodeRotation()) {
|
|
16821
16916
|
this.rotation(this.nodes()[0].getAbsoluteRotation());
|
|
16822
16917
|
}
|
|
@@ -16841,8 +16936,7 @@ js: import "konva/skia-backend";
|
|
|
16841
16936
|
if (node instanceof Container)
|
|
16842
16937
|
node._addSubtreeObserver(this);
|
|
16843
16938
|
node.on(`destroy.${this._getEventNamespace()}`, () => {
|
|
16844
|
-
|
|
16845
|
-
this.setNodes(this._nodes.filter((n) => n !== node));
|
|
16939
|
+
this._removeNode(node);
|
|
16846
16940
|
});
|
|
16847
16941
|
this._proxyDrag(node);
|
|
16848
16942
|
});
|
|
@@ -16888,6 +16982,23 @@ js: import "konva/skia-backend";
|
|
|
16888
16982
|
lastPos = null;
|
|
16889
16983
|
});
|
|
16890
16984
|
}
|
|
16985
|
+
_detachNode(node) {
|
|
16986
|
+
node.off('.' + this._getEventNamespace());
|
|
16987
|
+
node._removeSubtreeObserver(this);
|
|
16988
|
+
}
|
|
16989
|
+
_resetRotation() {
|
|
16990
|
+
const single = this._nodes.length === 1 && this.useSingleNodeRotation();
|
|
16991
|
+
this.rotation(single ? this._nodes[0].getAbsoluteRotation() : 0);
|
|
16992
|
+
}
|
|
16993
|
+
// Drops one destroyed node. Re-attaching the survivors instead costs
|
|
16994
|
+
// O(N) listener rebinds per destroyed node, O(N^2) for a deleted selection.
|
|
16995
|
+
_removeNode(node) {
|
|
16996
|
+
this._detachNode(node);
|
|
16997
|
+
this._nodes = this._nodes.filter((n) => n !== node);
|
|
16998
|
+
this._resetRotation();
|
|
16999
|
+
this._resetTransformCache(node);
|
|
17000
|
+
this._scheduleUpdate();
|
|
17001
|
+
}
|
|
16891
17002
|
getNodes() {
|
|
16892
17003
|
return this._nodes || [];
|
|
16893
17004
|
}
|
|
@@ -16911,17 +17022,12 @@ js: import "konva/skia-backend";
|
|
|
16911
17022
|
* transformer.detach();
|
|
16912
17023
|
*/
|
|
16913
17024
|
detach() {
|
|
16914
|
-
var _a;
|
|
16915
|
-
|
|
16916
|
-
if (this._nodes) {
|
|
16917
|
-
this._nodes.forEach((node) => {
|
|
16918
|
-
node.off('.' + this._getEventNamespace());
|
|
16919
|
-
node._removeSubtreeObserver(this);
|
|
16920
|
-
});
|
|
16921
|
-
}
|
|
17025
|
+
var _a, _b;
|
|
17026
|
+
(_a = this._nodes) === null || _a === void 0 ? void 0 : _a.forEach((node) => this._detachNode(node));
|
|
16922
17027
|
this._nodes = [];
|
|
17028
|
+
this._updatePending = false;
|
|
16923
17029
|
this._resetTransformCache();
|
|
16924
|
-
(
|
|
17030
|
+
(_b = this.getLayer()) === null || _b === void 0 ? void 0 : _b.batchDraw();
|
|
16925
17031
|
}
|
|
16926
17032
|
/**
|
|
16927
17033
|
* bind events to the Transformer. You can use events: `transform`, `transformstart`, `transformend`, `dragstart`, `dragmove`, `dragend`
|
|
@@ -16949,37 +17055,42 @@ js: import "konva/skia-backend";
|
|
|
16949
17055
|
// Called for every change below an attached container. A burst of child
|
|
16950
17056
|
// changes only drops cached values here. The new bounds are measured once,
|
|
16951
17057
|
// before the next frame, or earlier if a draw or transform step comes first
|
|
16952
|
-
// (
|
|
17058
|
+
// (_syncUpdate).
|
|
16953
17059
|
_onSubtreeChange(node) {
|
|
16954
17060
|
var _a, _b;
|
|
16955
17061
|
if (this._fitting)
|
|
16956
17062
|
return;
|
|
16957
17063
|
// nothing was measured since the last change, so nothing cached is stale
|
|
16958
|
-
|
|
17064
|
+
const measured = !this._updatePending || !!this._cache[NODES_RECT];
|
|
17065
|
+
if (measured)
|
|
17066
|
+
this._resetTransformCache(node);
|
|
17067
|
+
if (Node._updateBatchDepth > 0) {
|
|
17068
|
+
// the batch flush lays the new bounds out, no frame needed
|
|
17069
|
+
this._scheduleUpdate();
|
|
16959
17070
|
return;
|
|
16960
|
-
|
|
16961
|
-
if (!this.
|
|
16962
|
-
this.
|
|
17071
|
+
}
|
|
17072
|
+
if (!this._updatePending) {
|
|
17073
|
+
this._updatePending = true;
|
|
16963
17074
|
// queued ahead of the draw the change requests, so that draw shows the
|
|
16964
17075
|
// new layout. Updating inside the draw would request one more frame.
|
|
16965
|
-
Util.requestAnimFrame(
|
|
17076
|
+
Util.requestAnimFrame(this._syncUpdate, (_a = this.getStage()) === null || _a === void 0 ? void 0 : _a._getOwnerWindow());
|
|
16966
17077
|
// the transformer can be on another layer than the changed node
|
|
16967
17078
|
(_b = this.getLayer()) === null || _b === void 0 ? void 0 : _b.batchDraw();
|
|
16968
17079
|
}
|
|
16969
17080
|
}
|
|
16970
|
-
|
|
16971
|
-
|
|
17081
|
+
// Runs a deferred update before anything draws or measures the anchors.
|
|
17082
|
+
_syncUpdate() {
|
|
16972
17083
|
// while dragging, the dragmove handler updates the layout
|
|
16973
|
-
if (this.
|
|
17084
|
+
if (this._updatePending && !this._fitting && !this.isDragging()) {
|
|
16974
17085
|
this._update();
|
|
16975
17086
|
}
|
|
16976
17087
|
}
|
|
16977
17088
|
drawScene(can, top) {
|
|
16978
|
-
this.
|
|
17089
|
+
this._syncUpdate();
|
|
16979
17090
|
return super.drawScene(can, top);
|
|
16980
17091
|
}
|
|
16981
17092
|
drawHit(can, top) {
|
|
16982
|
-
this.
|
|
17093
|
+
this._syncUpdate();
|
|
16983
17094
|
return super.drawHit(can, top);
|
|
16984
17095
|
}
|
|
16985
17096
|
_getNodeRect() {
|
|
@@ -17266,7 +17377,7 @@ js: import "konva/skia-backend";
|
|
|
17266
17377
|
}
|
|
17267
17378
|
_moveTransform(e) {
|
|
17268
17379
|
// anchors must show the current bounds before they are measured against
|
|
17269
|
-
this.
|
|
17380
|
+
this._syncUpdate();
|
|
17270
17381
|
let x, y, newHypotenuse;
|
|
17271
17382
|
const anchorNode = this._anchors[this._movingAnchorName];
|
|
17272
17383
|
const stage = anchorNode.getStage();
|
|
@@ -17700,21 +17811,10 @@ js: import "konva/skia-backend";
|
|
|
17700
17811
|
layersToDraw.add(this.getLayer());
|
|
17701
17812
|
layersToDraw.forEach((layer) => layer && layer.batchDraw());
|
|
17702
17813
|
}
|
|
17703
|
-
//
|
|
17704
|
-
// the cascade ends; outside a cascade, run synchronously so reads of
|
|
17705
|
-
// transformer state stay consistent.
|
|
17814
|
+
// deferred to the batch flush when one is open, else synchronous
|
|
17706
17815
|
_scheduleUpdate() {
|
|
17707
|
-
|
|
17708
|
-
|
|
17709
|
-
this._updateScheduled = true;
|
|
17710
|
-
Node._runAfterAbsTransformCascade(() => {
|
|
17711
|
-
var _a;
|
|
17712
|
-
this._updateScheduled = false;
|
|
17713
|
-
if (!((_a = this._nodes) === null || _a === void 0 ? void 0 : _a.length) || this._fitting || this.isDragging()) {
|
|
17714
|
-
return;
|
|
17715
|
-
}
|
|
17716
|
-
this._update();
|
|
17717
|
-
});
|
|
17816
|
+
this._updatePending = true;
|
|
17817
|
+
Node._runAfterUpdateBatch(this._syncUpdate);
|
|
17718
17818
|
}
|
|
17719
17819
|
/**
|
|
17720
17820
|
* force update of Konva.Transformer.
|
|
@@ -17736,7 +17836,7 @@ js: import "konva/skia-backend";
|
|
|
17736
17836
|
}
|
|
17737
17837
|
_update() {
|
|
17738
17838
|
var _a;
|
|
17739
|
-
this.
|
|
17839
|
+
this._updatePending = false;
|
|
17740
17840
|
const attrs = this._getNodeRect();
|
|
17741
17841
|
this._updateElements(attrs);
|
|
17742
17842
|
const draggable = this.nodes().some((node) => node.draggable());
|
|
@@ -17916,6 +18016,7 @@ js: import "konva/skia-backend";
|
|
|
17916
18016
|
return node;
|
|
17917
18017
|
}
|
|
17918
18018
|
getClientRect(config) {
|
|
18019
|
+
this._syncUpdate();
|
|
17919
18020
|
if (this.nodes().length > 0) {
|
|
17920
18021
|
return super.getClientRect(config);
|
|
17921
18022
|
}
|
|
@@ -18898,6 +18999,30 @@ js: import "konva/skia-backend";
|
|
|
18898
18999
|
filterGaussBlurRGBA(imageData, radius);
|
|
18899
19000
|
}
|
|
18900
19001
|
};
|
|
19002
|
+
// CSS blur(σ) where the 2D context has no `filter`. A stack blur of radius 2σ
|
|
19003
|
+
// stays within about 10/255 alpha of the native Gaussian in Chromium, Firefox
|
|
19004
|
+
// and WebKit. Like the native filter, it has no radius limit and reads the
|
|
19005
|
+
// area beyond the image as transparent: a 1px transparent border is what the
|
|
19006
|
+
// blur repeats past the edges.
|
|
19007
|
+
_registerCSSFilterFallback('blur', (imageData, sigma, pixelRatio) => {
|
|
19008
|
+
const radius = Math.round(2 * sigma * pixelRatio);
|
|
19009
|
+
if (radius <= 0) {
|
|
19010
|
+
return;
|
|
19011
|
+
}
|
|
19012
|
+
const { width, height, data } = imageData, row = width * 4, framedRow = row + 8, framed = {
|
|
19013
|
+
width: width + 2,
|
|
19014
|
+
height: height + 2,
|
|
19015
|
+
data: new Uint8ClampedArray(framedRow * (height + 2)),
|
|
19016
|
+
};
|
|
19017
|
+
for (let y = 0; y < height; y++) {
|
|
19018
|
+
framed.data.set(data.subarray(y * row, y * row + row), (y + 1) * framedRow + 4);
|
|
19019
|
+
}
|
|
19020
|
+
filterGaussBlurRGBA(framed, radius);
|
|
19021
|
+
for (let y = 0; y < height; y++) {
|
|
19022
|
+
const start = (y + 1) * framedRow + 4;
|
|
19023
|
+
data.set(framed.data.subarray(start, start + row), y * row);
|
|
19024
|
+
}
|
|
19025
|
+
});
|
|
18901
19026
|
Factory.addGetterSetter(Node, 'blurRadius', 0, getNumberValidator(), Factory.afterSetFilter);
|
|
18902
19027
|
/**
|
|
18903
19028
|
* get/set blur radius. Use with {@link Konva.Filters.Blur} filter
|
|
@@ -18942,7 +19067,6 @@ js: import "konva/skia-backend";
|
|
|
18942
19067
|
* @returns {Number}
|
|
18943
19068
|
*/
|
|
18944
19069
|
|
|
18945
|
-
// The shared brightness accessor is registered by Brighten.
|
|
18946
19070
|
/**
|
|
18947
19071
|
* Brightness Filter.
|
|
18948
19072
|
* CSS-compatible brightness multiplier. An unset brightness leaves pixels unchanged.
|
|
@@ -18955,7 +19079,12 @@ js: import "konva/skia-backend";
|
|
|
18955
19079
|
* node.brightness(1.5); // 50% brighter (CSS-compatible)
|
|
18956
19080
|
*/
|
|
18957
19081
|
const Brightness = function (imageData) {
|
|
18958
|
-
|
|
19082
|
+
brighten(imageData, this.attrs.brightness === undefined ? 1 : this.brightness());
|
|
19083
|
+
};
|
|
19084
|
+
// CSS brightness(v) is the same multiplier.
|
|
19085
|
+
_registerCSSFilterFallback('brightness', brighten);
|
|
19086
|
+
function brighten(imageData, brightness) {
|
|
19087
|
+
const data = imageData.data, len = data.length;
|
|
18959
19088
|
for (let i = 0; i < len; i += 4) {
|
|
18960
19089
|
// red
|
|
18961
19090
|
data[i] = Math.min(255, data[i] * brightness);
|
|
@@ -18964,7 +19093,7 @@ js: import "konva/skia-backend";
|
|
|
18964
19093
|
// blue
|
|
18965
19094
|
data[i + 2] = Math.min(255, data[i + 2] * brightness);
|
|
18966
19095
|
}
|
|
18967
|
-
}
|
|
19096
|
+
}
|
|
18968
19097
|
|
|
18969
19098
|
/**
|
|
18970
19099
|
* Contrast Filter.
|
|
@@ -18977,7 +19106,11 @@ js: import "konva/skia-backend";
|
|
|
18977
19106
|
* node.contrast(10);
|
|
18978
19107
|
*/
|
|
18979
19108
|
const Contrast = function (imageData) {
|
|
18980
|
-
|
|
19109
|
+
applyContrast(imageData, Math.pow((this.contrast() + 100) / 100, 2));
|
|
19110
|
+
};
|
|
19111
|
+
// CSS contrast(v) scales the distance from mid-grey by v.
|
|
19112
|
+
_registerCSSFilterFallback('contrast', applyContrast);
|
|
19113
|
+
function applyContrast(imageData, adjust) {
|
|
18981
19114
|
const data = imageData.data, nPixels = data.length;
|
|
18982
19115
|
let red = 150, green = 150, blue = 150;
|
|
18983
19116
|
for (let i = 0; i < nPixels; i += 4) {
|
|
@@ -19009,7 +19142,7 @@ js: import "konva/skia-backend";
|
|
|
19009
19142
|
data[i + 1] = green;
|
|
19010
19143
|
data[i + 2] = blue;
|
|
19011
19144
|
}
|
|
19012
|
-
}
|
|
19145
|
+
}
|
|
19013
19146
|
/**
|
|
19014
19147
|
* get/set filter contrast. The contrast is a number between -100 and 100.
|
|
19015
19148
|
* Use with {@link Konva.Filters.Contrast} filter.
|
|
@@ -19034,7 +19167,7 @@ js: import "konva/skia-backend";
|
|
|
19034
19167
|
* node.embossBlend(true);
|
|
19035
19168
|
*/
|
|
19036
19169
|
const Emboss = function (imageData) {
|
|
19037
|
-
var _a, _b, _c, _d, _e, _f, _g, _h
|
|
19170
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
19038
19171
|
const data = imageData.data;
|
|
19039
19172
|
const w = imageData.width;
|
|
19040
19173
|
const h = imageData.height;
|
|
@@ -19052,8 +19185,13 @@ js: import "konva/skia-backend";
|
|
|
19052
19185
|
'bottom-left': 45,
|
|
19053
19186
|
left: 0,
|
|
19054
19187
|
};
|
|
19055
|
-
const
|
|
19056
|
-
|
|
19188
|
+
const direction = (_f = (_e = this.embossDirection) === null || _e === void 0 ? void 0 : _e.call(this)) !== null && _f !== void 0 ? _f : 'top-left';
|
|
19189
|
+
let directionDeg = directionMap[direction]; // degrees
|
|
19190
|
+
if (directionDeg === undefined) {
|
|
19191
|
+
Util.warn('Unknown emboss direction: "' + direction + '". Using "top-left".');
|
|
19192
|
+
directionDeg = directionMap['top-left'];
|
|
19193
|
+
}
|
|
19194
|
+
const blend = !!((_h = (_g = this.embossBlend) === null || _g === void 0 ? void 0 : _g.call(this)) !== null && _h !== void 0 ? _h : false);
|
|
19057
19195
|
// Internal mapping:
|
|
19058
19196
|
// - "strength" was 0..10; we honor your 0..1 API and scale accordingly.
|
|
19059
19197
|
// - Sobel directional response is roughly in [-1020..1020] for 8-bit luminance; scale to ~±128.
|
|
@@ -19061,7 +19199,8 @@ js: import "konva/skia-backend";
|
|
|
19061
19199
|
const bias = whiteLevel01 * 255;
|
|
19062
19200
|
const dirRad = (directionDeg * Math.PI) / 180;
|
|
19063
19201
|
const cx = Math.cos(dirRad);
|
|
19064
|
-
|
|
19202
|
+
// the angles above are measured with y up, but image rows go down
|
|
19203
|
+
const cy = -Math.sin(dirRad);
|
|
19065
19204
|
const SCALE = (128 / 1020) * strength; // ≈0.1255 * strength
|
|
19066
19205
|
// Precompute luminance (Rec.709)
|
|
19067
19206
|
const lum = new Float32Array(w * h);
|