konva 10.9.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 +225 -139
- package/konva.min.js +4 -4
- package/lib/Context.d.ts +1 -0
- package/lib/Context.js +15 -1
- package/lib/Global.js +2 -2
- package/lib/Node.d.ts +2 -0
- package/lib/Node.js +44 -50
- package/lib/Shape.d.ts +5 -1
- package/lib/Shape.js +41 -28
- package/lib/Util.js +2 -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/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.9.
|
|
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.9.
|
|
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,
|
|
@@ -3769,12 +3773,17 @@ js: import "konva/skia-backend";
|
|
|
3769
3773
|
_delegate(event, selector, handler) {
|
|
3770
3774
|
const stopNode = this;
|
|
3771
3775
|
this.on(event, function (evt) {
|
|
3776
|
+
const original = evt;
|
|
3772
3777
|
const targets = evt.target.findAncestors(selector, true, stopNode);
|
|
3773
3778
|
for (let i = 0; i < targets.length; i++) {
|
|
3774
3779
|
evt = Util.cloneObject(evt);
|
|
3775
3780
|
evt.currentTarget = targets[i];
|
|
3776
3781
|
handler.call(targets[i], evt);
|
|
3777
3782
|
}
|
|
3783
|
+
// handlers get copies, so pass a cancelled bubble back
|
|
3784
|
+
if (evt.cancelBubble) {
|
|
3785
|
+
original.cancelBubble = true;
|
|
3786
|
+
}
|
|
3778
3787
|
});
|
|
3779
3788
|
return this;
|
|
3780
3789
|
}
|
|
@@ -5927,6 +5936,7 @@ js: import "konva/skia-backend";
|
|
|
5927
5936
|
* get/set filters. Supports function filters, CSS filter strings, or mixed arrays.
|
|
5928
5937
|
* CSS filters are applied using native browser performance when possible, function filters use ImageData manipulation.
|
|
5929
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.
|
|
5930
5940
|
* Blur radii, pixelation sizes and CSS lengths use node coordinates, independent of cache pixelRatio.
|
|
5931
5941
|
* Custom filters receive (imageData, pixelRatio). ImageData contains full-resolution backing pixels.
|
|
5932
5942
|
* @name Konva.Node#filters
|
|
@@ -7875,44 +7885,54 @@ js: import "konva/skia-backend";
|
|
|
7875
7885
|
this.shadowOffsetX() ||
|
|
7876
7886
|
this.shadowOffsetY()));
|
|
7877
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).
|
|
7878
7893
|
_getFillPattern() {
|
|
7879
|
-
|
|
7894
|
+
const pattern = this._getCache(patternImage, this._createFillPattern);
|
|
7895
|
+
return pattern && this._setFillPatternTransform(pattern);
|
|
7880
7896
|
}
|
|
7881
|
-
|
|
7897
|
+
_createFillPattern() {
|
|
7882
7898
|
if (this.fillPatternImage()) {
|
|
7883
|
-
|
|
7884
|
-
|
|
7885
|
-
|
|
7886
|
-
|
|
7887
|
-
|
|
7888
|
-
|
|
7889
|
-
|
|
7890
|
-
|
|
7891
|
-
|
|
7892
|
-
|
|
7893
|
-
|
|
7894
|
-
|
|
7895
|
-
|
|
7896
|
-
|
|
7897
|
-
|
|
7898
|
-
|
|
7899
|
-
|
|
7900
|
-
|
|
7901
|
-
:
|
|
7902
|
-
|
|
7903
|
-
|
|
7904
|
-
|
|
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);
|
|
7905
7922
|
}
|
|
7923
|
+
return pattern;
|
|
7906
7924
|
}
|
|
7907
7925
|
_getLinearGradient() {
|
|
7926
|
+
if (this._styleTransform)
|
|
7927
|
+
return this.__getLinearGradient();
|
|
7908
7928
|
return this._getCache(linearGradient, this.__getLinearGradient);
|
|
7909
7929
|
}
|
|
7910
7930
|
__getLinearGradient() {
|
|
7911
7931
|
const colorStops = this.fillLinearGradientColorStops();
|
|
7912
7932
|
if (colorStops) {
|
|
7913
7933
|
const ctx = getDummyContext$1();
|
|
7914
|
-
const start = this.fillLinearGradientStartPoint();
|
|
7915
|
-
const end = this.fillLinearGradientEndPoint();
|
|
7934
|
+
const start = this._toStyleSpace(this.fillLinearGradientStartPoint());
|
|
7935
|
+
const end = this._toStyleSpace(this.fillLinearGradientEndPoint());
|
|
7916
7936
|
const grd = ctx.createLinearGradient(start.x, start.y, end.x, end.y);
|
|
7917
7937
|
// build color stops
|
|
7918
7938
|
for (let n = 0; n < colorStops.length; n += 2) {
|
|
@@ -7922,14 +7942,17 @@ js: import "konva/skia-backend";
|
|
|
7922
7942
|
}
|
|
7923
7943
|
}
|
|
7924
7944
|
_getRadialGradient() {
|
|
7945
|
+
if (this._styleTransform)
|
|
7946
|
+
return this.__getRadialGradient();
|
|
7925
7947
|
return this._getCache(radialGradient, this.__getRadialGradient);
|
|
7926
7948
|
}
|
|
7927
7949
|
__getRadialGradient() {
|
|
7928
7950
|
const colorStops = this.fillRadialGradientColorStops();
|
|
7929
7951
|
if (colorStops) {
|
|
7930
7952
|
const ctx = getDummyContext$1();
|
|
7931
|
-
|
|
7932
|
-
const
|
|
7953
|
+
// a rigid transform keeps the radii
|
|
7954
|
+
const start = this._toStyleSpace(this.fillRadialGradientStartPoint());
|
|
7955
|
+
const end = this._toStyleSpace(this.fillRadialGradientEndPoint());
|
|
7933
7956
|
const grd = ctx.createRadialGradient(start.x, start.y, this.fillRadialGradientStartRadius(), end.x, end.y, this.fillRadialGradientEndRadius());
|
|
7934
7957
|
// build color stops
|
|
7935
7958
|
for (let n = 0; n < colorStops.length; n += 2) {
|
|
@@ -13560,7 +13583,7 @@ js: import "konva/skia-backend";
|
|
|
13560
13583
|
// constants
|
|
13561
13584
|
const AUTO = 'auto',
|
|
13562
13585
|
//CANVAS = 'canvas',
|
|
13563
|
-
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 = [
|
|
13564
13587
|
'direction',
|
|
13565
13588
|
'fontFamily',
|
|
13566
13589
|
'fontSize',
|
|
@@ -13846,8 +13869,8 @@ js: import "konva/skia-backend";
|
|
|
13846
13869
|
const lineWidth = align === JUSTIFY && !lastLine ? totalWidth - padding * 2 : width;
|
|
13847
13870
|
context.lineTo(x + Math.round(lineWidth), y);
|
|
13848
13871
|
context.lineWidth = getDecorationLineWidth(fontSize);
|
|
13849
|
-
|
|
13850
|
-
|
|
13872
|
+
if (context._applyDecorationStyle(this))
|
|
13873
|
+
context.stroke();
|
|
13851
13874
|
context.restore();
|
|
13852
13875
|
}
|
|
13853
13876
|
// store the starting x position for line-through which is drawn after text
|
|
@@ -13925,8 +13948,8 @@ js: import "konva/skia-backend";
|
|
|
13925
13948
|
const lineWidth = align === JUSTIFY && !lastLine ? totalWidth - padding * 2 : width;
|
|
13926
13949
|
context.lineTo(x + Math.round(lineWidth), translateY + lineTranslateY + yOffset);
|
|
13927
13950
|
context.lineWidth = getDecorationLineWidth(fontSize);
|
|
13928
|
-
|
|
13929
|
-
|
|
13951
|
+
if (context._applyDecorationStyle(this))
|
|
13952
|
+
context.stroke();
|
|
13930
13953
|
context.restore();
|
|
13931
13954
|
}
|
|
13932
13955
|
context.restore();
|
|
@@ -14295,10 +14318,10 @@ js: import "konva/skia-backend";
|
|
|
14295
14318
|
Text.prototype.className = TEXT_UPPER;
|
|
14296
14319
|
// the decoration attrs are not in ATTR_CHANGE_LIST: they change the bounds
|
|
14297
14320
|
// through getSelfRect, but need no relayout
|
|
14298
|
-
Text.prototype._attrsAffectingSize = ATTR_CHANGE_LIST$
|
|
14321
|
+
Text.prototype._attrsAffectingSize = ATTR_CHANGE_LIST$3.filter((attr) => attr !== 'width' && attr !== 'height').concat(['textDecoration', 'underlineOffset']);
|
|
14299
14322
|
_registerNode(Text, true);
|
|
14300
14323
|
// update text data for certain attr changes
|
|
14301
|
-
Text.prototype.on(ATTR_CHANGE_LIST$
|
|
14324
|
+
Text.prototype.on(ATTR_CHANGE_LIST$3.map((attr) => attr + CHANGE_KONVA).join(' '), function () {
|
|
14302
14325
|
this._setTextData();
|
|
14303
14326
|
});
|
|
14304
14327
|
/**
|
|
@@ -14575,14 +14598,14 @@ js: import "konva/skia-backend";
|
|
|
14575
14598
|
Factory.addGetterSetter(Text, 'charRenderFunc', undefined);
|
|
14576
14599
|
|
|
14577
14600
|
// constants
|
|
14578
|
-
const ATTR_CHANGE_LIST$
|
|
14601
|
+
const ATTR_CHANGE_LIST$2 = [
|
|
14579
14602
|
...Text.prototype._attrsAffectingSize,
|
|
14580
14603
|
'width',
|
|
14581
14604
|
'height',
|
|
14582
14605
|
'pointerDirection',
|
|
14583
14606
|
'pointerWidth',
|
|
14584
14607
|
'pointerHeight',
|
|
14585
|
-
], 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';
|
|
14586
14609
|
/**
|
|
14587
14610
|
* Label constructor. Labels are groups that contain a Text and Tag shape
|
|
14588
14611
|
* @constructor
|
|
@@ -16047,40 +16070,49 @@ js: import "konva/skia-backend";
|
|
|
16047
16070
|
context.setAttr('textAlign', 'left');
|
|
16048
16071
|
context.save();
|
|
16049
16072
|
const textDecoration = this.textDecoration();
|
|
16050
|
-
const fill = this.fill();
|
|
16051
16073
|
const fontSize = this.fontSize();
|
|
16074
|
+
const underlineOffset = this._getUnderlineOffset();
|
|
16052
16075
|
const glyphInfo = this.glyphInfo;
|
|
16053
16076
|
const hasUnderline = textDecoration.indexOf('underline') !== -1;
|
|
16054
16077
|
const hasLineThrough = textDecoration.indexOf('line-through') !== -1;
|
|
16055
16078
|
if (hasUnderline) {
|
|
16056
16079
|
context.beginPath();
|
|
16057
16080
|
}
|
|
16058
|
-
|
|
16059
|
-
|
|
16060
|
-
|
|
16061
|
-
|
|
16062
|
-
|
|
16063
|
-
|
|
16064
|
-
|
|
16065
|
-
|
|
16066
|
-
|
|
16067
|
-
|
|
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);
|
|
16068
16099
|
}
|
|
16069
|
-
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();
|
|
16070
16109
|
}
|
|
16071
|
-
context.restore();
|
|
16072
|
-
//// To assist with debugging visually, uncomment following
|
|
16073
|
-
//
|
|
16074
|
-
// if (i % 2) context.strokeStyle = 'cyan';
|
|
16075
|
-
// else context.strokeStyle = 'green';
|
|
16076
|
-
// var p1 = glyphInfo[i].p1;
|
|
16077
|
-
// context.moveTo(p0.x, p0.y);
|
|
16078
|
-
// context.lineTo(p1.x, p1.y);
|
|
16079
|
-
// context.stroke();
|
|
16080
16110
|
}
|
|
16081
|
-
|
|
16082
|
-
|
|
16083
|
-
|
|
16111
|
+
finally {
|
|
16112
|
+
this._styleTransform = undefined;
|
|
16113
|
+
}
|
|
16114
|
+
context.lineWidth = getDecorationLineWidth(fontSize);
|
|
16115
|
+
if (hasUnderline && context._applyDecorationStyle(this)) {
|
|
16084
16116
|
context.stroke();
|
|
16085
16117
|
}
|
|
16086
16118
|
if (hasLineThrough) {
|
|
@@ -16096,9 +16128,8 @@ js: import "konva/skia-backend";
|
|
|
16096
16128
|
context.lineTo(glyphInfo[i].width, 0);
|
|
16097
16129
|
context.restore();
|
|
16098
16130
|
}
|
|
16099
|
-
context.
|
|
16100
|
-
|
|
16101
|
-
context.stroke();
|
|
16131
|
+
if (context._applyDecorationStyle(this))
|
|
16132
|
+
context.stroke();
|
|
16102
16133
|
}
|
|
16103
16134
|
context.restore();
|
|
16104
16135
|
}
|
|
@@ -16265,12 +16296,30 @@ js: import "konva/skia-backend";
|
|
|
16265
16296
|
});
|
|
16266
16297
|
const rect = Util._getPointsRect(points);
|
|
16267
16298
|
const fontSize = this.fontSize();
|
|
16268
|
-
|
|
16269
|
-
|
|
16270
|
-
|
|
16271
|
-
|
|
16272
|
-
|
|
16273
|
-
|
|
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;
|
|
16274
16323
|
}
|
|
16275
16324
|
// Like Text: a glyph stroke is drawn with the text, so it always scales.
|
|
16276
16325
|
getStrokeScaleEnabled() {
|
|
@@ -16293,10 +16342,9 @@ js: import "konva/skia-backend";
|
|
|
16293
16342
|
TextPath.prototype._fillFuncHit = _fillFunc;
|
|
16294
16343
|
TextPath.prototype._strokeFuncHit = _strokeFunc;
|
|
16295
16344
|
TextPath.prototype.className = 'TextPath';
|
|
16296
|
-
|
|
16345
|
+
const ATTR_CHANGE_LIST$1 = [
|
|
16297
16346
|
'text',
|
|
16298
16347
|
'fontSize',
|
|
16299
|
-
'data',
|
|
16300
16348
|
'align',
|
|
16301
16349
|
'letterSpacing',
|
|
16302
16350
|
'kerningFunc',
|
|
@@ -16305,16 +16353,16 @@ js: import "konva/skia-backend";
|
|
|
16305
16353
|
'fontVariant',
|
|
16306
16354
|
'direction',
|
|
16307
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');
|
|
16308
16359
|
_registerNode(TextPath, true);
|
|
16309
16360
|
TextPath.prototype.on('dataChange.konva', function () {
|
|
16310
16361
|
this._readDataAttribute();
|
|
16311
16362
|
this._setTextData();
|
|
16312
16363
|
});
|
|
16313
16364
|
// update text data for certain attr changes
|
|
16314
|
-
TextPath.prototype.on(
|
|
16315
|
-
.filter((attr) => attr !== 'data')
|
|
16316
|
-
.map((attr) => attr + 'Change.konva')
|
|
16317
|
-
.join(' '), function () {
|
|
16365
|
+
TextPath.prototype.on(ATTR_CHANGE_LIST$1.map((attr) => attr + 'Change.konva').join(' '), function () {
|
|
16318
16366
|
this._setTextData();
|
|
16319
16367
|
});
|
|
16320
16368
|
/**
|
|
@@ -18951,6 +18999,30 @@ js: import "konva/skia-backend";
|
|
|
18951
18999
|
filterGaussBlurRGBA(imageData, radius);
|
|
18952
19000
|
}
|
|
18953
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
|
+
});
|
|
18954
19026
|
Factory.addGetterSetter(Node, 'blurRadius', 0, getNumberValidator(), Factory.afterSetFilter);
|
|
18955
19027
|
/**
|
|
18956
19028
|
* get/set blur radius. Use with {@link Konva.Filters.Blur} filter
|
|
@@ -18995,7 +19067,6 @@ js: import "konva/skia-backend";
|
|
|
18995
19067
|
* @returns {Number}
|
|
18996
19068
|
*/
|
|
18997
19069
|
|
|
18998
|
-
// The shared brightness accessor is registered by Brighten.
|
|
18999
19070
|
/**
|
|
19000
19071
|
* Brightness Filter.
|
|
19001
19072
|
* CSS-compatible brightness multiplier. An unset brightness leaves pixels unchanged.
|
|
@@ -19008,7 +19079,12 @@ js: import "konva/skia-backend";
|
|
|
19008
19079
|
* node.brightness(1.5); // 50% brighter (CSS-compatible)
|
|
19009
19080
|
*/
|
|
19010
19081
|
const Brightness = function (imageData) {
|
|
19011
|
-
|
|
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;
|
|
19012
19088
|
for (let i = 0; i < len; i += 4) {
|
|
19013
19089
|
// red
|
|
19014
19090
|
data[i] = Math.min(255, data[i] * brightness);
|
|
@@ -19017,7 +19093,7 @@ js: import "konva/skia-backend";
|
|
|
19017
19093
|
// blue
|
|
19018
19094
|
data[i + 2] = Math.min(255, data[i + 2] * brightness);
|
|
19019
19095
|
}
|
|
19020
|
-
}
|
|
19096
|
+
}
|
|
19021
19097
|
|
|
19022
19098
|
/**
|
|
19023
19099
|
* Contrast Filter.
|
|
@@ -19030,7 +19106,11 @@ js: import "konva/skia-backend";
|
|
|
19030
19106
|
* node.contrast(10);
|
|
19031
19107
|
*/
|
|
19032
19108
|
const Contrast = function (imageData) {
|
|
19033
|
-
|
|
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) {
|
|
19034
19114
|
const data = imageData.data, nPixels = data.length;
|
|
19035
19115
|
let red = 150, green = 150, blue = 150;
|
|
19036
19116
|
for (let i = 0; i < nPixels; i += 4) {
|
|
@@ -19062,7 +19142,7 @@ js: import "konva/skia-backend";
|
|
|
19062
19142
|
data[i + 1] = green;
|
|
19063
19143
|
data[i + 2] = blue;
|
|
19064
19144
|
}
|
|
19065
|
-
}
|
|
19145
|
+
}
|
|
19066
19146
|
/**
|
|
19067
19147
|
* get/set filter contrast. The contrast is a number between -100 and 100.
|
|
19068
19148
|
* Use with {@link Konva.Filters.Contrast} filter.
|
|
@@ -19087,7 +19167,7 @@ js: import "konva/skia-backend";
|
|
|
19087
19167
|
* node.embossBlend(true);
|
|
19088
19168
|
*/
|
|
19089
19169
|
const Emboss = function (imageData) {
|
|
19090
|
-
var _a, _b, _c, _d, _e, _f, _g, _h
|
|
19170
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
19091
19171
|
const data = imageData.data;
|
|
19092
19172
|
const w = imageData.width;
|
|
19093
19173
|
const h = imageData.height;
|
|
@@ -19105,8 +19185,13 @@ js: import "konva/skia-backend";
|
|
|
19105
19185
|
'bottom-left': 45,
|
|
19106
19186
|
left: 0,
|
|
19107
19187
|
};
|
|
19108
|
-
const
|
|
19109
|
-
|
|
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);
|
|
19110
19195
|
// Internal mapping:
|
|
19111
19196
|
// - "strength" was 0..10; we honor your 0..1 API and scale accordingly.
|
|
19112
19197
|
// - Sobel directional response is roughly in [-1020..1020] for 8-bit luminance; scale to ~±128.
|
|
@@ -19114,7 +19199,8 @@ js: import "konva/skia-backend";
|
|
|
19114
19199
|
const bias = whiteLevel01 * 255;
|
|
19115
19200
|
const dirRad = (directionDeg * Math.PI) / 180;
|
|
19116
19201
|
const cx = Math.cos(dirRad);
|
|
19117
|
-
|
|
19202
|
+
// the angles above are measured with y up, but image rows go down
|
|
19203
|
+
const cy = -Math.sin(dirRad);
|
|
19118
19204
|
const SCALE = (128 / 1020) * strength; // ≈0.1255 * strength
|
|
19119
19205
|
// Precompute luminance (Rec.709)
|
|
19120
19206
|
const lum = new Float32Array(w * h);
|