konva 9.3.21 → 10.0.0-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/konva.js +664 -226
- package/konva.min.js +46 -4
- package/lib/Animation.d.ts +2 -2
- package/lib/Animation.js +7 -11
- package/lib/BezierFunctions.js +9 -15
- package/lib/Canvas.d.ts +1 -1
- package/lib/Canvas.js +14 -20
- package/lib/Container.d.ts +7 -6
- package/lib/Container.js +12 -16
- package/lib/Context.d.ts +7 -5
- package/lib/Context.js +34 -14
- package/lib/Core.d.ts +2 -2
- package/lib/Core.js +3 -7
- package/lib/DragAndDrop.d.ts +3 -3
- package/lib/DragAndDrop.js +24 -27
- package/lib/Factory.d.ts +2 -2
- package/lib/Factory.js +24 -27
- package/lib/FastLayer.d.ts +1 -1
- package/lib/FastLayer.js +6 -10
- package/lib/Global.d.ts +4 -3
- package/lib/Global.js +19 -19
- package/lib/Group.d.ts +4 -3
- package/lib/Group.js +6 -10
- package/lib/Layer.d.ts +10 -9
- package/lib/Layer.js +33 -37
- package/lib/Node.d.ts +16 -13
- package/lib/Node.js +207 -123
- package/lib/PointerEvents.d.ts +4 -4
- package/lib/PointerEvents.js +7 -14
- package/lib/Shape.d.ts +7 -4
- package/lib/Shape.js +91 -91
- package/lib/Stage.d.ts +8 -7
- package/lib/Stage.js +66 -56
- package/lib/Tween.d.ts +3 -2
- package/lib/Tween.js +29 -31
- package/lib/Util.d.ts +3 -2
- package/lib/Util.js +98 -38
- package/lib/Validators.js +44 -57
- package/lib/_CoreInternals.d.ts +49 -23
- package/lib/_CoreInternals.js +33 -36
- package/lib/_FullInternals.d.ts +126 -62
- package/lib/_FullInternals.js +77 -78
- package/lib/canvas-backend.d.ts +2 -0
- package/lib/canvas-backend.js +27 -0
- package/lib/filters/Blur.d.ts +1 -1
- package/lib/filters/Blur.js +5 -9
- package/lib/filters/Brighten.d.ts +1 -1
- package/lib/filters/Brighten.js +5 -9
- package/lib/filters/Brightness.d.ts +2 -0
- package/lib/filters/Brightness.js +8 -0
- package/lib/filters/Contrast.d.ts +1 -1
- package/lib/filters/Contrast.js +5 -9
- package/lib/filters/Emboss.d.ts +1 -1
- package/lib/filters/Emboss.js +95 -101
- package/lib/filters/Enhance.d.ts +1 -1
- package/lib/filters/Enhance.js +5 -9
- package/lib/filters/Grayscale.d.ts +1 -1
- package/lib/filters/Grayscale.js +1 -5
- package/lib/filters/HSL.d.ts +1 -1
- package/lib/filters/HSL.js +7 -11
- package/lib/filters/HSV.d.ts +1 -1
- package/lib/filters/HSV.js +7 -11
- package/lib/filters/Invert.d.ts +1 -1
- package/lib/filters/Invert.js +1 -5
- package/lib/filters/Kaleidoscope.d.ts +1 -1
- package/lib/filters/Kaleidoscope.js +9 -13
- package/lib/filters/Mask.d.ts +1 -1
- package/lib/filters/Mask.js +16 -10
- package/lib/filters/Noise.d.ts +1 -1
- package/lib/filters/Noise.js +5 -9
- package/lib/filters/Pixelate.d.ts +1 -1
- package/lib/filters/Pixelate.js +7 -11
- package/lib/filters/Posterize.d.ts +1 -1
- package/lib/filters/Posterize.js +5 -9
- package/lib/filters/RGB.d.ts +1 -1
- package/lib/filters/RGB.js +7 -11
- package/lib/filters/RGBA.d.ts +1 -1
- package/lib/filters/RGBA.js +8 -12
- package/lib/filters/Sepia.d.ts +1 -1
- package/lib/filters/Sepia.js +1 -5
- package/lib/filters/Solarize.d.ts +1 -1
- package/lib/filters/Solarize.js +13 -29
- package/lib/filters/Threshold.d.ts +1 -1
- package/lib/filters/Threshold.js +5 -9
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -4
- package/lib/shapes/Arc.d.ts +4 -3
- package/lib/shapes/Arc.js +13 -17
- package/lib/shapes/Arrow.d.ts +4 -3
- package/lib/shapes/Arrow.js +13 -17
- package/lib/shapes/Circle.d.ts +4 -3
- package/lib/shapes/Circle.js +7 -11
- package/lib/shapes/Ellipse.d.ts +4 -3
- package/lib/shapes/Ellipse.js +9 -13
- package/lib/shapes/Image.d.ts +4 -3
- package/lib/shapes/Image.js +17 -21
- package/lib/shapes/Label.d.ts +7 -6
- package/lib/shapes/Label.js +13 -18
- package/lib/shapes/Line.d.ts +4 -3
- package/lib/shapes/Line.js +10 -14
- package/lib/shapes/Path.d.ts +3 -2
- package/lib/shapes/Path.js +83 -23
- package/lib/shapes/Rect.d.ts +4 -3
- package/lib/shapes/Rect.js +9 -13
- package/lib/shapes/RegularPolygon.d.ts +6 -3
- package/lib/shapes/RegularPolygon.js +19 -16
- package/lib/shapes/Ring.d.ts +4 -3
- package/lib/shapes/Ring.js +8 -12
- package/lib/shapes/Sprite.d.ts +5 -4
- package/lib/shapes/Sprite.js +15 -19
- package/lib/shapes/Star.d.ts +4 -3
- package/lib/shapes/Star.js +9 -13
- package/lib/shapes/Text.d.ts +16 -3
- package/lib/shapes/Text.js +73 -53
- package/lib/shapes/TextPath.d.ts +5 -4
- package/lib/shapes/TextPath.js +48 -41
- package/lib/shapes/Transformer.d.ts +8 -8
- package/lib/shapes/Transformer.js +90 -90
- package/lib/shapes/Wedge.d.ts +4 -3
- package/lib/shapes/Wedge.js +12 -16
- package/lib/skia-backend.d.ts +2 -0
- package/lib/skia-backend.js +24 -0
- package/lib/types.d.ts +22 -22
- package/lib/types.js +21 -25
- package/package.json +53 -25
- package/lib/index-node.d.ts +0 -2
- package/lib/index-node.js +0 -21
- package/lib/index-types.d.ts +0 -181
package/konva.js
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
})(this, (function () { 'use strict';
|
|
6
6
|
|
|
7
7
|
/*
|
|
8
|
-
* Konva JavaScript Framework
|
|
8
|
+
* Konva JavaScript Framework v10.0.0-0
|
|
9
9
|
* http://konvajs.org/
|
|
10
10
|
* Licensed under the MIT
|
|
11
|
-
* Date:
|
|
11
|
+
* Date: Sun Aug 24 2025
|
|
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: '
|
|
38
|
+
version: '10.0.0-0',
|
|
39
39
|
isBrowser: detectBrowser(),
|
|
40
40
|
isUnminified: /param/.test(function (param) { }.toString()),
|
|
41
41
|
dblClickWindow: 400,
|
|
@@ -87,7 +87,17 @@
|
|
|
87
87
|
_mouseDblClickPointerId: null,
|
|
88
88
|
_touchDblClickPointerId: null,
|
|
89
89
|
_pointerDblClickPointerId: null,
|
|
90
|
-
|
|
90
|
+
_renderBackend: 'web', // web, node-canvas, skia-canvas
|
|
91
|
+
/**
|
|
92
|
+
* Use legacy text rendering. with "middle" baseline by default.
|
|
93
|
+
* @property legacyTextRendering
|
|
94
|
+
* @default false
|
|
95
|
+
* @name legacyTextRendering
|
|
96
|
+
* @memberof Konva
|
|
97
|
+
* @example
|
|
98
|
+
* Konva.legacyTextRendering = true;
|
|
99
|
+
*/
|
|
100
|
+
legacyTextRendering: false,
|
|
91
101
|
/**
|
|
92
102
|
* Global pixel ratio configuration. KonvaJS automatically detect pixel ratio of current device.
|
|
93
103
|
* But you may override such property, if you want to use your value. Set this value before any components initializations.
|
|
@@ -150,8 +160,8 @@
|
|
|
150
160
|
return Konva$2['DD'].isDragging;
|
|
151
161
|
},
|
|
152
162
|
isTransforming() {
|
|
153
|
-
var _a;
|
|
154
|
-
return (_a = Konva$2['Transformer']) === null || _a === void 0 ? void 0 : _a.isTransforming();
|
|
163
|
+
var _a, _b;
|
|
164
|
+
return (_b = (_a = Konva$2['Transformer']) === null || _a === void 0 ? void 0 : _a.isTransforming()) !== null && _b !== void 0 ? _b : false;
|
|
155
165
|
},
|
|
156
166
|
/**
|
|
157
167
|
* returns whether or not a drag and drop operation is ready, but may
|
|
@@ -178,6 +188,9 @@
|
|
|
178
188
|
// insert Konva into global namespace (window)
|
|
179
189
|
// it is required for npm packages
|
|
180
190
|
_injectGlobal(Konva) {
|
|
191
|
+
if (typeof glob.Konva !== 'undefined') {
|
|
192
|
+
console.error('Severa Konva instances detected. It is not recommended to use multiple Konva instances in the same environment.');
|
|
193
|
+
}
|
|
181
194
|
glob.Konva = Konva;
|
|
182
195
|
},
|
|
183
196
|
};
|
|
@@ -186,6 +199,25 @@
|
|
|
186
199
|
};
|
|
187
200
|
Konva$2._injectGlobal(Konva$2);
|
|
188
201
|
|
|
202
|
+
const NODE_ERROR = `Konva.js unsupported environment.
|
|
203
|
+
|
|
204
|
+
Looks like you are trying to use Konva.js in Node.js environment. because "document" object is undefined.
|
|
205
|
+
|
|
206
|
+
To use Konva.js in Node.js environment, you need to use the "canvas-backend" or "skia-backend" module.
|
|
207
|
+
|
|
208
|
+
bash: npm install canvas
|
|
209
|
+
js: import "konva/canvas-backend";
|
|
210
|
+
|
|
211
|
+
or
|
|
212
|
+
|
|
213
|
+
bash: npm install skia-canvas
|
|
214
|
+
js: import "konva/skia-backend";
|
|
215
|
+
`;
|
|
216
|
+
const ensureBrowser = () => {
|
|
217
|
+
if (typeof document === 'undefined') {
|
|
218
|
+
throw new Error(NODE_ERROR);
|
|
219
|
+
}
|
|
220
|
+
};
|
|
189
221
|
/*
|
|
190
222
|
* Last updated November 2011
|
|
191
223
|
* By Simon Sarris
|
|
@@ -659,6 +691,7 @@
|
|
|
659
691
|
}
|
|
660
692
|
},
|
|
661
693
|
createCanvasElement() {
|
|
694
|
+
ensureBrowser();
|
|
662
695
|
const canvas = document.createElement('canvas');
|
|
663
696
|
// on some environments canvas.style is readonly
|
|
664
697
|
try {
|
|
@@ -668,6 +701,7 @@
|
|
|
668
701
|
return canvas;
|
|
669
702
|
},
|
|
670
703
|
createImageElement() {
|
|
704
|
+
ensureBrowser();
|
|
671
705
|
return document.createElement('img');
|
|
672
706
|
},
|
|
673
707
|
_isInDocument(el) {
|
|
@@ -1121,6 +1155,11 @@
|
|
|
1121
1155
|
});
|
|
1122
1156
|
},
|
|
1123
1157
|
drawRoundedRectPath(context, width, height, cornerRadius) {
|
|
1158
|
+
// if negative dimensions, abs width/height and move rectangle
|
|
1159
|
+
let xOrigin = width < 0 ? width : 0;
|
|
1160
|
+
let yOrigin = height < 0 ? height : 0;
|
|
1161
|
+
width = Math.abs(width);
|
|
1162
|
+
height = Math.abs(height);
|
|
1124
1163
|
let topLeft = 0;
|
|
1125
1164
|
let topRight = 0;
|
|
1126
1165
|
let bottomLeft = 0;
|
|
@@ -1138,15 +1177,55 @@
|
|
|
1138
1177
|
bottomRight = Math.min(cornerRadius[2] || 0, width / 2, height / 2);
|
|
1139
1178
|
bottomLeft = Math.min(cornerRadius[3] || 0, width / 2, height / 2);
|
|
1140
1179
|
}
|
|
1141
|
-
context.moveTo(topLeft,
|
|
1142
|
-
context.lineTo(width - topRight,
|
|
1143
|
-
context.arc(width - topRight, topRight, topRight, (Math.PI * 3) / 2, 0, false);
|
|
1144
|
-
context.lineTo(width, height - bottomRight);
|
|
1145
|
-
context.arc(width - bottomRight, height - bottomRight, bottomRight, 0, Math.PI / 2, false);
|
|
1146
|
-
context.lineTo(bottomLeft, height);
|
|
1147
|
-
context.arc(bottomLeft, height - bottomLeft, bottomLeft, Math.PI / 2, Math.PI, false);
|
|
1148
|
-
context.lineTo(
|
|
1149
|
-
context.arc(topLeft, topLeft, topLeft, Math.PI, (Math.PI * 3) / 2, false);
|
|
1180
|
+
context.moveTo(xOrigin + topLeft, yOrigin);
|
|
1181
|
+
context.lineTo(xOrigin + width - topRight, yOrigin);
|
|
1182
|
+
context.arc(xOrigin + width - topRight, yOrigin + topRight, topRight, (Math.PI * 3) / 2, 0, false);
|
|
1183
|
+
context.lineTo(xOrigin + width, yOrigin + height - bottomRight);
|
|
1184
|
+
context.arc(xOrigin + width - bottomRight, yOrigin + height - bottomRight, bottomRight, 0, Math.PI / 2, false);
|
|
1185
|
+
context.lineTo(xOrigin + bottomLeft, yOrigin + height);
|
|
1186
|
+
context.arc(xOrigin + bottomLeft, yOrigin + height - bottomLeft, bottomLeft, Math.PI / 2, Math.PI, false);
|
|
1187
|
+
context.lineTo(xOrigin, yOrigin + topLeft);
|
|
1188
|
+
context.arc(xOrigin + topLeft, yOrigin + topLeft, topLeft, Math.PI, (Math.PI * 3) / 2, false);
|
|
1189
|
+
},
|
|
1190
|
+
drawRoundedPolygonPath(context, points, sides, radius, cornerRadius) {
|
|
1191
|
+
radius = Math.abs(radius);
|
|
1192
|
+
for (let i = 0; i < sides; i++) {
|
|
1193
|
+
const prev = points[(i - 1 + sides) % sides];
|
|
1194
|
+
const curr = points[i];
|
|
1195
|
+
const next = points[(i + 1) % sides];
|
|
1196
|
+
const vec1 = { x: curr.x - prev.x, y: curr.y - prev.y };
|
|
1197
|
+
const vec2 = { x: next.x - curr.x, y: next.y - curr.y };
|
|
1198
|
+
const len1 = Math.hypot(vec1.x, vec1.y);
|
|
1199
|
+
const len2 = Math.hypot(vec2.x, vec2.y);
|
|
1200
|
+
let currCornerRadius;
|
|
1201
|
+
if (typeof cornerRadius === 'number') {
|
|
1202
|
+
currCornerRadius = cornerRadius;
|
|
1203
|
+
}
|
|
1204
|
+
else {
|
|
1205
|
+
currCornerRadius = i < cornerRadius.length ? cornerRadius[i] : 0;
|
|
1206
|
+
}
|
|
1207
|
+
const maxCornerRadius = radius * Math.cos(Math.PI / sides);
|
|
1208
|
+
// cornerRadius creates perfect circle at 1/2 radius
|
|
1209
|
+
currCornerRadius =
|
|
1210
|
+
maxCornerRadius * Math.min(1, (currCornerRadius / radius) * 2);
|
|
1211
|
+
const normalVec1 = { x: vec1.x / len1, y: vec1.y / len1 };
|
|
1212
|
+
const normalVec2 = { x: vec2.x / len2, y: vec2.y / len2 };
|
|
1213
|
+
const p1 = {
|
|
1214
|
+
x: curr.x - normalVec1.x * currCornerRadius,
|
|
1215
|
+
y: curr.y - normalVec1.y * currCornerRadius,
|
|
1216
|
+
};
|
|
1217
|
+
const p2 = {
|
|
1218
|
+
x: curr.x + normalVec2.x * currCornerRadius,
|
|
1219
|
+
y: curr.y + normalVec2.y * currCornerRadius,
|
|
1220
|
+
};
|
|
1221
|
+
if (i === 0) {
|
|
1222
|
+
context.moveTo(p1.x, p1.y);
|
|
1223
|
+
}
|
|
1224
|
+
else {
|
|
1225
|
+
context.lineTo(p1.x, p1.y);
|
|
1226
|
+
}
|
|
1227
|
+
context.arcTo(curr.x, curr.y, p2.x, p2.y, currCornerRadius);
|
|
1228
|
+
}
|
|
1150
1229
|
},
|
|
1151
1230
|
};
|
|
1152
1231
|
|
|
@@ -1222,8 +1301,29 @@
|
|
|
1222
1301
|
'globalAlpha',
|
|
1223
1302
|
'globalCompositeOperation',
|
|
1224
1303
|
'imageSmoothingEnabled',
|
|
1304
|
+
'filter',
|
|
1225
1305
|
];
|
|
1226
1306
|
const traceArrMax = 100;
|
|
1307
|
+
// Check if CSS filters are supported in the current browser
|
|
1308
|
+
let _cssFiltersSupported = null;
|
|
1309
|
+
function isCSSFiltersSupported() {
|
|
1310
|
+
if (_cssFiltersSupported !== null) {
|
|
1311
|
+
return _cssFiltersSupported;
|
|
1312
|
+
}
|
|
1313
|
+
try {
|
|
1314
|
+
const canvas = Util.createCanvasElement();
|
|
1315
|
+
const ctx = canvas.getContext('2d');
|
|
1316
|
+
if (!ctx) {
|
|
1317
|
+
_cssFiltersSupported = false;
|
|
1318
|
+
return false;
|
|
1319
|
+
}
|
|
1320
|
+
return !!ctx && 'filter' in ctx;
|
|
1321
|
+
}
|
|
1322
|
+
catch (e) {
|
|
1323
|
+
_cssFiltersSupported = false;
|
|
1324
|
+
return false;
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1227
1327
|
/**
|
|
1228
1328
|
* Konva wrapper around native 2d canvas context. It has almost the same API of 2d context with some additional functions.
|
|
1229
1329
|
* With core Konva shapes you don't need to use this object. But you will use it if you want to create
|
|
@@ -1399,6 +1499,12 @@
|
|
|
1399
1499
|
this.setAttr('lineJoin', lineJoin);
|
|
1400
1500
|
}
|
|
1401
1501
|
}
|
|
1502
|
+
_applyMiterLimit(shape) {
|
|
1503
|
+
const miterLimit = shape.attrs.miterLimit;
|
|
1504
|
+
if (miterLimit != null) {
|
|
1505
|
+
this.setAttr('miterLimit', miterLimit);
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1402
1508
|
setAttr(attr, val) {
|
|
1403
1509
|
this._context[attr] = val;
|
|
1404
1510
|
}
|
|
@@ -2513,6 +2619,83 @@
|
|
|
2513
2619
|
},
|
|
2514
2620
|
};
|
|
2515
2621
|
|
|
2622
|
+
// CSS filter parser for fallback to function filters
|
|
2623
|
+
function parseCSSFilters(cssFilter) {
|
|
2624
|
+
// Parse common CSS filter functions and map to Konva filters
|
|
2625
|
+
const filterRegex = /(\w+)\(([^)]+)\)/g;
|
|
2626
|
+
let match;
|
|
2627
|
+
while ((match = filterRegex.exec(cssFilter)) !== null) {
|
|
2628
|
+
const [, filterName, filterValue] = match;
|
|
2629
|
+
switch (filterName) {
|
|
2630
|
+
case 'blur': {
|
|
2631
|
+
const blurRadius = parseFloat(filterValue.replace('px', ''));
|
|
2632
|
+
return function (imageData) {
|
|
2633
|
+
// CSS blur uses standard deviation, Stack Blur uses radius
|
|
2634
|
+
// Empirical testing shows CSS blur needs ~0.5 scaling for visual match
|
|
2635
|
+
this.blurRadius(blurRadius * 0.5);
|
|
2636
|
+
// Access filters through dynamic import to avoid circular dependency
|
|
2637
|
+
const KonvaFilters = Konva$2.Filters;
|
|
2638
|
+
if (KonvaFilters && KonvaFilters.Blur) {
|
|
2639
|
+
KonvaFilters.Blur.call(this, imageData);
|
|
2640
|
+
}
|
|
2641
|
+
};
|
|
2642
|
+
}
|
|
2643
|
+
case 'brightness': {
|
|
2644
|
+
const brightness = filterValue.includes('%')
|
|
2645
|
+
? parseFloat(filterValue) / 100
|
|
2646
|
+
: parseFloat(filterValue);
|
|
2647
|
+
return function (imageData) {
|
|
2648
|
+
this.brightness(brightness); // CSS uses multiplier
|
|
2649
|
+
const KonvaFilters = Konva$2.Filters;
|
|
2650
|
+
if (KonvaFilters && KonvaFilters.Brightness) {
|
|
2651
|
+
KonvaFilters.Brightness.call(this, imageData);
|
|
2652
|
+
}
|
|
2653
|
+
};
|
|
2654
|
+
}
|
|
2655
|
+
case 'contrast': {
|
|
2656
|
+
const contrast = parseFloat(filterValue);
|
|
2657
|
+
return function (imageData) {
|
|
2658
|
+
// Convert CSS contrast to Konva parameter using square root conversion
|
|
2659
|
+
// to account for Konva's quadratic scaling: Math.pow((param + 100) / 100, 2)
|
|
2660
|
+
const konvaContrast = 100 * (Math.sqrt(contrast) - 1);
|
|
2661
|
+
this.contrast(konvaContrast);
|
|
2662
|
+
const KonvaFilters = Konva$2.Filters;
|
|
2663
|
+
if (KonvaFilters && KonvaFilters.Contrast) {
|
|
2664
|
+
KonvaFilters.Contrast.call(this, imageData);
|
|
2665
|
+
}
|
|
2666
|
+
};
|
|
2667
|
+
}
|
|
2668
|
+
case 'grayscale': {
|
|
2669
|
+
return function (imageData) {
|
|
2670
|
+
const KonvaFilters = Konva$2.Filters;
|
|
2671
|
+
if (KonvaFilters && KonvaFilters.Grayscale) {
|
|
2672
|
+
KonvaFilters.Grayscale.call(this, imageData);
|
|
2673
|
+
}
|
|
2674
|
+
};
|
|
2675
|
+
}
|
|
2676
|
+
case 'sepia': {
|
|
2677
|
+
return function (imageData) {
|
|
2678
|
+
const KonvaFilters = Konva$2.Filters;
|
|
2679
|
+
if (KonvaFilters && KonvaFilters.Sepia) {
|
|
2680
|
+
KonvaFilters.Sepia.call(this, imageData);
|
|
2681
|
+
}
|
|
2682
|
+
};
|
|
2683
|
+
}
|
|
2684
|
+
case 'invert': {
|
|
2685
|
+
return function (imageData) {
|
|
2686
|
+
const KonvaFilters = Konva$2.Filters;
|
|
2687
|
+
if (KonvaFilters && KonvaFilters.Invert) {
|
|
2688
|
+
KonvaFilters.Invert.call(this, imageData);
|
|
2689
|
+
}
|
|
2690
|
+
};
|
|
2691
|
+
}
|
|
2692
|
+
default:
|
|
2693
|
+
Util.warn(`CSS filter "${filterName}" is not supported in fallback mode. Consider using function filters for better compatibility.`);
|
|
2694
|
+
break;
|
|
2695
|
+
}
|
|
2696
|
+
}
|
|
2697
|
+
return () => { };
|
|
2698
|
+
}
|
|
2516
2699
|
// CONSTANTS
|
|
2517
2700
|
const ABSOLUTE_OPACITY = 'absoluteOpacity', ALL_LISTENERS = 'allEventListeners', ABSOLUTE_TRANSFORM = 'absoluteTransform', ABSOLUTE_SCALE = 'absoluteScale', CANVAS = 'canvas', CHANGE = 'Change', CHILDREN = 'children', KONVA = 'konva', LISTENING = 'listening', MOUSEENTER$1 = 'mouseenter', MOUSELEAVE$1 = 'mouseleave', POINTERENTER$1 = 'pointerenter', POINTERLEAVE$1 = 'pointerleave', TOUCHENTER = 'touchenter', TOUCHLEAVE = 'touchleave', SET = 'set', SHAPE = 'Shape', SPACE$1 = ' ', STAGE$1 = 'stage', TRANSFORM = 'transform', UPPER_STAGE = 'Stage', VISIBLE = 'visible', TRANSFORM_CHANGE_STR$1 = [
|
|
2518
2701
|
'xChange.konva',
|
|
@@ -2905,39 +3088,54 @@
|
|
|
2905
3088
|
}
|
|
2906
3089
|
_getCachedSceneCanvas() {
|
|
2907
3090
|
let filters = this.filters(), cachedCanvas = this._getCanvasCache(), sceneCanvas = cachedCanvas.scene, filterCanvas = cachedCanvas.filter, filterContext = filterCanvas.getContext(), len, imageData, n, filter;
|
|
2908
|
-
if (filters) {
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
filter = filters[n];
|
|
2921
|
-
if (typeof filter !== 'function') {
|
|
2922
|
-
Util.error('Filter should be type of function, but got ' +
|
|
2923
|
-
typeof filter +
|
|
2924
|
-
' instead. Please check correct filters');
|
|
2925
|
-
continue;
|
|
2926
|
-
}
|
|
2927
|
-
filter.call(this, imageData);
|
|
2928
|
-
filterContext.putImageData(imageData, 0, 0);
|
|
2929
|
-
}
|
|
2930
|
-
}
|
|
2931
|
-
catch (e) {
|
|
2932
|
-
Util.error('Unable to apply filter. ' +
|
|
2933
|
-
e.message +
|
|
2934
|
-
' This post my help you https://konvajs.org/docs/posts/Tainted_Canvas.html.');
|
|
2935
|
-
}
|
|
2936
|
-
this._filterUpToDate = true;
|
|
3091
|
+
if (!filters || filters.length === 0) {
|
|
3092
|
+
return sceneCanvas;
|
|
3093
|
+
}
|
|
3094
|
+
if (this._filterUpToDate) {
|
|
3095
|
+
return filterCanvas;
|
|
3096
|
+
}
|
|
3097
|
+
let useNativeOnly = true;
|
|
3098
|
+
for (let i = 0; i < filters.length; i++) {
|
|
3099
|
+
typeof filters[i] === 'string' && !isCSSFiltersSupported();
|
|
3100
|
+
if (typeof filters[i] !== 'string' || !isCSSFiltersSupported()) {
|
|
3101
|
+
useNativeOnly = false;
|
|
3102
|
+
break;
|
|
2937
3103
|
}
|
|
3104
|
+
}
|
|
3105
|
+
const ratio = sceneCanvas.pixelRatio;
|
|
3106
|
+
filterCanvas.setSize(sceneCanvas.width / sceneCanvas.pixelRatio, sceneCanvas.height / sceneCanvas.pixelRatio);
|
|
3107
|
+
if (useNativeOnly) {
|
|
3108
|
+
const finalFilter = filters.join(' ');
|
|
3109
|
+
filterContext.save();
|
|
3110
|
+
filterContext.setAttr('filter', finalFilter);
|
|
3111
|
+
filterContext.drawImage(sceneCanvas._canvas, 0, 0, sceneCanvas.getWidth() / ratio, sceneCanvas.getHeight() / ratio);
|
|
3112
|
+
filterContext.restore();
|
|
3113
|
+
this._filterUpToDate = true;
|
|
2938
3114
|
return filterCanvas;
|
|
2939
3115
|
}
|
|
2940
|
-
|
|
3116
|
+
try {
|
|
3117
|
+
len = filters.length;
|
|
3118
|
+
filterContext.clear();
|
|
3119
|
+
// copy cached canvas onto filter context
|
|
3120
|
+
filterContext.drawImage(sceneCanvas._canvas, 0, 0, sceneCanvas.getWidth() / ratio, sceneCanvas.getHeight() / ratio);
|
|
3121
|
+
imageData = filterContext.getImageData(0, 0, filterCanvas.getWidth(), filterCanvas.getHeight());
|
|
3122
|
+
// apply filters to filter context
|
|
3123
|
+
for (n = 0; n < len; n++) {
|
|
3124
|
+
filter = filters[n];
|
|
3125
|
+
if (typeof filter === 'string') {
|
|
3126
|
+
filter = parseCSSFilters(filter);
|
|
3127
|
+
}
|
|
3128
|
+
filter.call(this, imageData);
|
|
3129
|
+
filterContext.putImageData(imageData, 0, 0);
|
|
3130
|
+
}
|
|
3131
|
+
}
|
|
3132
|
+
catch (e) {
|
|
3133
|
+
Util.error('Unable to apply filter. ' +
|
|
3134
|
+
e.message +
|
|
3135
|
+
' This post my help you https://konvajs.org/docs/posts/Tainted_Canvas.html.');
|
|
3136
|
+
}
|
|
3137
|
+
this._filterUpToDate = true;
|
|
3138
|
+
return filterCanvas;
|
|
2941
3139
|
}
|
|
2942
3140
|
/**
|
|
2943
3141
|
* bind events to the node. KonvaJS supports mouseover, mousemove,
|
|
@@ -3181,7 +3379,7 @@
|
|
|
3181
3379
|
* @returns {Array}
|
|
3182
3380
|
* @example
|
|
3183
3381
|
* shape.getAncestors().forEach(function(node) {
|
|
3184
|
-
* console.log(node.
|
|
3382
|
+
* console.log(node.id());
|
|
3185
3383
|
* })
|
|
3186
3384
|
*/
|
|
3187
3385
|
getAncestors() {
|
|
@@ -5176,25 +5374,30 @@
|
|
|
5176
5374
|
return val;
|
|
5177
5375
|
});
|
|
5178
5376
|
/**
|
|
5179
|
-
* get/set filters.
|
|
5377
|
+
* get/set filters. Supports function filters, CSS filter strings, or mixed arrays.
|
|
5378
|
+
* CSS filters are applied using native browser performance when possible, function filters use ImageData manipulation.
|
|
5379
|
+
* CSS filters automatically fall back to function filters in unsupported browsers.
|
|
5180
5380
|
* @name Konva.Node#filters
|
|
5181
5381
|
* @method
|
|
5182
|
-
* @param {Array} filters array of
|
|
5382
|
+
* @param {Array} filters array of filter functions and/or CSS filter strings
|
|
5183
5383
|
* @returns {Array}
|
|
5184
5384
|
* @example
|
|
5185
5385
|
* // get filters
|
|
5186
5386
|
* var filters = node.filters();
|
|
5187
5387
|
*
|
|
5188
|
-
* // set
|
|
5388
|
+
* // set CSS filters only (no caching required, uses native performance)
|
|
5389
|
+
* node.filters(['blur(5px)', 'brightness(1.2)', 'contrast(1.5)']);
|
|
5390
|
+
*
|
|
5391
|
+
* // set function filters only (caching required)
|
|
5189
5392
|
* node.cache();
|
|
5190
|
-
* node.filters([Konva.Filters.Blur]);
|
|
5393
|
+
* node.filters([Konva.Filters.Blur, Konva.Filters.Sepia, Konva.Filters.Invert]);
|
|
5191
5394
|
*
|
|
5192
|
-
* //
|
|
5395
|
+
* // mix CSS and function filters (caching required, uses fallback strategy)
|
|
5193
5396
|
* node.cache();
|
|
5194
5397
|
* node.filters([
|
|
5195
|
-
*
|
|
5196
|
-
* Konva.Filters.
|
|
5197
|
-
*
|
|
5398
|
+
* 'blur(3px)', // CSS filter
|
|
5399
|
+
* Konva.Filters.Invert, // function filter
|
|
5400
|
+
* 'brightness(1.5)' // CSS filter
|
|
5198
5401
|
* ]);
|
|
5199
5402
|
*/
|
|
5200
5403
|
addGetterSetter(Node, 'visible', true, getBooleanValidator());
|
|
@@ -6408,7 +6611,14 @@
|
|
|
6408
6611
|
if (!events) {
|
|
6409
6612
|
return;
|
|
6410
6613
|
}
|
|
6411
|
-
|
|
6614
|
+
// prevent default only for touch-based interactions to avoid blocking
|
|
6615
|
+
// native mouse wheel scrolling during drag on desktop
|
|
6616
|
+
const isTouchPointer = evt.type.indexOf('touch') >= 0 ||
|
|
6617
|
+
evt.pointerType === 'touch';
|
|
6618
|
+
if (Konva$2.isDragging() &&
|
|
6619
|
+
DD.node.preventDefault() &&
|
|
6620
|
+
evt.cancelable &&
|
|
6621
|
+
isTouchPointer) {
|
|
6412
6622
|
evt.preventDefault();
|
|
6413
6623
|
}
|
|
6414
6624
|
this.setPointersPositions(evt);
|
|
@@ -6475,7 +6685,7 @@
|
|
|
6475
6685
|
const clickStartShape = this[eventType + 'ClickStartShape'];
|
|
6476
6686
|
const clickEndShape = this[eventType + 'ClickEndShape'];
|
|
6477
6687
|
const processedShapesIds = {};
|
|
6478
|
-
let
|
|
6688
|
+
let skipPointerUpTrigger = false;
|
|
6479
6689
|
this._changedPointerPositions.forEach((pos) => {
|
|
6480
6690
|
const shape = (getCapturedShape(pos.id) ||
|
|
6481
6691
|
this.getIntersection(pos));
|
|
@@ -6502,7 +6712,7 @@
|
|
|
6502
6712
|
Konva$2['_' + eventType + 'InDblClickWindow'] = false;
|
|
6503
6713
|
}, Konva$2.dblClickWindow);
|
|
6504
6714
|
if (shape && shape.isListening()) {
|
|
6505
|
-
|
|
6715
|
+
skipPointerUpTrigger = true;
|
|
6506
6716
|
this[eventType + 'ClickEndShape'] = shape;
|
|
6507
6717
|
shape._fireAndBubble(events.pointerup, { ...event });
|
|
6508
6718
|
// detect if click or double click occurred
|
|
@@ -6517,6 +6727,15 @@
|
|
|
6517
6727
|
}
|
|
6518
6728
|
else {
|
|
6519
6729
|
this[eventType + 'ClickEndShape'] = null;
|
|
6730
|
+
if (!skipPointerUpTrigger) {
|
|
6731
|
+
this._fire(events.pointerup, {
|
|
6732
|
+
evt: evt,
|
|
6733
|
+
target: this,
|
|
6734
|
+
currentTarget: this,
|
|
6735
|
+
pointerId: this._changedPointerPositions[0].id,
|
|
6736
|
+
});
|
|
6737
|
+
skipPointerUpTrigger = true;
|
|
6738
|
+
}
|
|
6520
6739
|
if (Konva$2['_' + eventType + 'ListenClick']) {
|
|
6521
6740
|
this._fire(events.pointerclick, {
|
|
6522
6741
|
evt: evt,
|
|
@@ -6535,7 +6754,7 @@
|
|
|
6535
6754
|
}
|
|
6536
6755
|
}
|
|
6537
6756
|
});
|
|
6538
|
-
if (!
|
|
6757
|
+
if (!skipPointerUpTrigger) {
|
|
6539
6758
|
this._fire(events.pointerup, {
|
|
6540
6759
|
evt: evt,
|
|
6541
6760
|
target: this,
|
|
@@ -7262,9 +7481,15 @@
|
|
|
7262
7481
|
bufferContext.clear();
|
|
7263
7482
|
bufferContext.save();
|
|
7264
7483
|
bufferContext._applyLineJoin(this);
|
|
7484
|
+
bufferContext._applyMiterLimit(this);
|
|
7265
7485
|
// layer might be undefined if we are using cache before adding to layer
|
|
7266
7486
|
const o = this.getAbsoluteTransform(top).getMatrix();
|
|
7267
7487
|
bufferContext.transform(o[0], o[1], o[2], o[3], o[4], o[5]);
|
|
7488
|
+
// Apply CSS filters to buffer context if not cached
|
|
7489
|
+
// we skip filters in non cache use cases for now
|
|
7490
|
+
// if (!cachingSelf && filters?.length > 0) {
|
|
7491
|
+
// bufferContext._applyCSSFilters(this);
|
|
7492
|
+
// }
|
|
7268
7493
|
drawFunc.call(this, bufferContext, this);
|
|
7269
7494
|
bufferContext.restore();
|
|
7270
7495
|
const ratio = bc.pixelRatio;
|
|
@@ -7277,11 +7502,16 @@
|
|
|
7277
7502
|
}
|
|
7278
7503
|
else {
|
|
7279
7504
|
context._applyLineJoin(this);
|
|
7505
|
+
context._applyMiterLimit(this);
|
|
7280
7506
|
if (!cachingSelf) {
|
|
7281
7507
|
const o = this.getAbsoluteTransform(top).getMatrix();
|
|
7282
7508
|
context.transform(o[0], o[1], o[2], o[3], o[4], o[5]);
|
|
7283
7509
|
context._applyOpacity(this);
|
|
7284
7510
|
context._applyGlobalCompositeOperation(this);
|
|
7511
|
+
// Apply CSS filters to main context if not cached
|
|
7512
|
+
// if (filters?.length) {
|
|
7513
|
+
// context._applyCSSFilters(this);
|
|
7514
|
+
// }
|
|
7285
7515
|
}
|
|
7286
7516
|
if (hasShadow) {
|
|
7287
7517
|
context._applyShadow(this);
|
|
@@ -7312,6 +7542,7 @@
|
|
|
7312
7542
|
}
|
|
7313
7543
|
context.save();
|
|
7314
7544
|
context._applyLineJoin(this);
|
|
7545
|
+
context._applyMiterLimit(this);
|
|
7315
7546
|
const selfCache = this === top;
|
|
7316
7547
|
if (!selfCache) {
|
|
7317
7548
|
const o = this.getAbsoluteTransform(top).getMatrix();
|
|
@@ -7536,6 +7767,20 @@
|
|
|
7536
7767
|
* // set line cap
|
|
7537
7768
|
* shape.lineCap('round');
|
|
7538
7769
|
*/
|
|
7770
|
+
Factory.addGetterSetter(Shape, 'miterLimit');
|
|
7771
|
+
/**
|
|
7772
|
+
* get/set miterLimit.
|
|
7773
|
+
* @name Konva.Shape#miterLimit
|
|
7774
|
+
* @method
|
|
7775
|
+
* @param {Number} miterLimit
|
|
7776
|
+
* @returns {Number}
|
|
7777
|
+
* @example
|
|
7778
|
+
* // get miter limit
|
|
7779
|
+
* var miterLimit = shape.miterLimit();
|
|
7780
|
+
*
|
|
7781
|
+
* // set miter limit
|
|
7782
|
+
* shape.miterLimit(10);
|
|
7783
|
+
*/
|
|
7539
7784
|
Factory.addGetterSetter(Shape, 'sceneFunc');
|
|
7540
7785
|
/**
|
|
7541
7786
|
* get/set scene draw function. That function is used to draw the shape on a canvas.
|
|
@@ -9622,11 +9867,13 @@
|
|
|
9622
9867
|
// Clean up attrs entry
|
|
9623
9868
|
delete Tween.attrs[nodeId][thisId];
|
|
9624
9869
|
// Clean up parent objects if empty
|
|
9625
|
-
if (
|
|
9626
|
-
|
|
9627
|
-
|
|
9628
|
-
|
|
9629
|
-
|
|
9870
|
+
if (Tween.tweens[nodeId]) {
|
|
9871
|
+
if (Object.keys(Tween.tweens[nodeId]).length === 0) {
|
|
9872
|
+
delete Tween.tweens[nodeId];
|
|
9873
|
+
}
|
|
9874
|
+
if (Object.keys(Tween.attrs[nodeId]).length === 0) {
|
|
9875
|
+
delete Tween.attrs[nodeId];
|
|
9876
|
+
}
|
|
9630
9877
|
}
|
|
9631
9878
|
}
|
|
9632
9879
|
}
|
|
@@ -11693,19 +11940,87 @@
|
|
|
11693
11940
|
// while ((match = re.exec(str))) {
|
|
11694
11941
|
// coords.push(match[0]);
|
|
11695
11942
|
// }
|
|
11696
|
-
|
|
11943
|
+
let p = [];
|
|
11944
|
+
// Track param position for A/a commands: 0..6 => rx, ry, psi, fa, fs, x, y
|
|
11945
|
+
let arcParamIndex = c === 'A' || c === 'a' ? 0 : -1;
|
|
11697
11946
|
for (let j = 0, jlen = coords.length; j < jlen; j++) {
|
|
11947
|
+
const token = coords[j];
|
|
11698
11948
|
// extra case for merged flags
|
|
11699
|
-
if (
|
|
11949
|
+
if (token === '00') {
|
|
11700
11950
|
p.push(0, 0);
|
|
11951
|
+
if (arcParamIndex >= 0) {
|
|
11952
|
+
arcParamIndex += 2;
|
|
11953
|
+
if (arcParamIndex >= 7)
|
|
11954
|
+
arcParamIndex -= 7;
|
|
11955
|
+
}
|
|
11701
11956
|
continue;
|
|
11702
11957
|
}
|
|
11703
|
-
|
|
11704
|
-
|
|
11705
|
-
|
|
11958
|
+
if (arcParamIndex >= 0) {
|
|
11959
|
+
// index-aware minimal handling for merged flags
|
|
11960
|
+
if (arcParamIndex === 3) {
|
|
11961
|
+
// expecting large-arc-flag; token may contain fa+fs(+x)
|
|
11962
|
+
if (/^[01]{2}\d+(?:\.\d+)?$/.test(token)) {
|
|
11963
|
+
p.push(parseInt(token[0], 10));
|
|
11964
|
+
p.push(parseInt(token[1], 10));
|
|
11965
|
+
p.push(parseFloat(token.slice(2)));
|
|
11966
|
+
arcParamIndex += 3;
|
|
11967
|
+
if (arcParamIndex >= 7)
|
|
11968
|
+
arcParamIndex -= 7;
|
|
11969
|
+
continue;
|
|
11970
|
+
}
|
|
11971
|
+
if (token === '11' || token === '10' || token === '01') {
|
|
11972
|
+
p.push(parseInt(token[0], 10));
|
|
11973
|
+
p.push(parseInt(token[1], 10));
|
|
11974
|
+
arcParamIndex += 2;
|
|
11975
|
+
if (arcParamIndex >= 7)
|
|
11976
|
+
arcParamIndex -= 7;
|
|
11977
|
+
continue;
|
|
11978
|
+
}
|
|
11979
|
+
if (token === '0' || token === '1') {
|
|
11980
|
+
p.push(parseInt(token, 10));
|
|
11981
|
+
arcParamIndex += 1;
|
|
11982
|
+
if (arcParamIndex >= 7)
|
|
11983
|
+
arcParamIndex -= 7;
|
|
11984
|
+
continue;
|
|
11985
|
+
}
|
|
11986
|
+
}
|
|
11987
|
+
else if (arcParamIndex === 4) {
|
|
11988
|
+
// expecting sweep-flag; token may contain fs(+x)
|
|
11989
|
+
if (/^[01]\d+(?:\.\d+)?$/.test(token)) {
|
|
11990
|
+
p.push(parseInt(token[0], 10));
|
|
11991
|
+
p.push(parseFloat(token.slice(1)));
|
|
11992
|
+
arcParamIndex += 2;
|
|
11993
|
+
if (arcParamIndex >= 7)
|
|
11994
|
+
arcParamIndex -= 7;
|
|
11995
|
+
continue;
|
|
11996
|
+
}
|
|
11997
|
+
if (token === '0' || token === '1') {
|
|
11998
|
+
p.push(parseInt(token, 10));
|
|
11999
|
+
arcParamIndex += 1;
|
|
12000
|
+
if (arcParamIndex >= 7)
|
|
12001
|
+
arcParamIndex -= 7;
|
|
12002
|
+
continue;
|
|
12003
|
+
}
|
|
12004
|
+
}
|
|
12005
|
+
const parsedArc = parseFloat(token);
|
|
12006
|
+
if (!isNaN(parsedArc)) {
|
|
12007
|
+
p.push(parsedArc);
|
|
12008
|
+
}
|
|
12009
|
+
else {
|
|
12010
|
+
p.push(0);
|
|
12011
|
+
}
|
|
12012
|
+
arcParamIndex += 1;
|
|
12013
|
+
if (arcParamIndex >= 7)
|
|
12014
|
+
arcParamIndex -= 7;
|
|
11706
12015
|
}
|
|
11707
12016
|
else {
|
|
11708
|
-
|
|
12017
|
+
const parsed = parseFloat(token);
|
|
12018
|
+
if (!isNaN(parsed)) {
|
|
12019
|
+
p.push(parsed);
|
|
12020
|
+
}
|
|
12021
|
+
else {
|
|
12022
|
+
p.push(0);
|
|
12023
|
+
}
|
|
11709
12024
|
}
|
|
11710
12025
|
}
|
|
11711
12026
|
while (p.length > 0) {
|
|
@@ -13352,6 +13667,7 @@
|
|
|
13352
13667
|
* @memberof Konva
|
|
13353
13668
|
* @augments Konva.Shape
|
|
13354
13669
|
* @param {Object} config
|
|
13670
|
+
* @param {Number} [config.cornerRadius]
|
|
13355
13671
|
* @param {Number} config.sides
|
|
13356
13672
|
* @param {Number} config.radius
|
|
13357
13673
|
* @param {String} [config.fill] fill color
|
|
@@ -13441,11 +13757,16 @@
|
|
|
13441
13757
|
*/
|
|
13442
13758
|
class RegularPolygon extends Shape {
|
|
13443
13759
|
_sceneFunc(context) {
|
|
13444
|
-
const points = this._getPoints();
|
|
13760
|
+
const points = this._getPoints(), radius = this.radius(), sides = this.sides(), cornerRadius = this.cornerRadius();
|
|
13445
13761
|
context.beginPath();
|
|
13446
|
-
|
|
13447
|
-
|
|
13448
|
-
|
|
13762
|
+
if (!cornerRadius) {
|
|
13763
|
+
context.moveTo(points[0].x, points[0].y);
|
|
13764
|
+
for (let n = 1; n < points.length; n++) {
|
|
13765
|
+
context.lineTo(points[n].x, points[n].y);
|
|
13766
|
+
}
|
|
13767
|
+
}
|
|
13768
|
+
else {
|
|
13769
|
+
Util.drawRoundedPolygonPath(context, points, sides, radius, cornerRadius);
|
|
13449
13770
|
}
|
|
13450
13771
|
context.closePath();
|
|
13451
13772
|
context.fillStrokeShape(this);
|
|
@@ -13526,6 +13847,23 @@
|
|
|
13526
13847
|
* shape.sides(10);
|
|
13527
13848
|
*/
|
|
13528
13849
|
Factory.addGetterSetter(RegularPolygon, 'sides', 0, getNumberValidator());
|
|
13850
|
+
/**
|
|
13851
|
+
* get/set corner radius
|
|
13852
|
+
* @method
|
|
13853
|
+
* @name Konva.RegularPolygon#cornerRadius
|
|
13854
|
+
* @param {Number} cornerRadius
|
|
13855
|
+
* @returns {Number}
|
|
13856
|
+
* @example
|
|
13857
|
+
* // get corner radius
|
|
13858
|
+
* var cornerRadius = poly.cornerRadius();
|
|
13859
|
+
*
|
|
13860
|
+
* // set corner radius
|
|
13861
|
+
* poly.cornerRadius(10);
|
|
13862
|
+
*
|
|
13863
|
+
* // set different corner radius values (pentagon)
|
|
13864
|
+
* poly.cornerRadius([0, 10, 20, 30, 40]);
|
|
13865
|
+
*/
|
|
13866
|
+
Factory.addGetterSetter(RegularPolygon, 'cornerRadius', 0, getNumberOrArrayOfNumbersValidator(4));
|
|
13529
13867
|
|
|
13530
13868
|
const PIx2 = Math.PI * 2;
|
|
13531
13869
|
/**
|
|
@@ -14420,20 +14758,21 @@
|
|
|
14420
14758
|
this._setTextData();
|
|
14421
14759
|
}
|
|
14422
14760
|
_sceneFunc(context) {
|
|
14761
|
+
var _a, _b;
|
|
14423
14762
|
const textArr = this.textArr, textArrLen = textArr.length;
|
|
14424
14763
|
if (!this.text()) {
|
|
14425
14764
|
return;
|
|
14426
14765
|
}
|
|
14427
|
-
let padding = this.padding(), fontSize = this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, verticalAlign = this.verticalAlign(), direction = this.direction(), alignY = 0, align = this.align(), totalWidth = this.getWidth(), letterSpacing = this.letterSpacing(), fill = this.fill(), textDecoration = this.textDecoration(), shouldUnderline = textDecoration.indexOf('underline') !== -1, shouldLineThrough = textDecoration.indexOf('line-through') !== -1, n;
|
|
14766
|
+
let padding = this.padding(), fontSize = this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, verticalAlign = this.verticalAlign(), direction = this.direction(), alignY = 0, align = this.align(), totalWidth = this.getWidth(), letterSpacing = this.letterSpacing(), charRenderFunc = this.charRenderFunc(), fill = this.fill(), textDecoration = this.textDecoration(), shouldUnderline = textDecoration.indexOf('underline') !== -1, shouldLineThrough = textDecoration.indexOf('line-through') !== -1, n;
|
|
14428
14767
|
direction = direction === INHERIT ? context.direction : direction;
|
|
14429
14768
|
let translateY = lineHeightPx / 2;
|
|
14430
14769
|
let baseline = MIDDLE;
|
|
14431
|
-
if (Konva$2.
|
|
14770
|
+
if (!Konva$2.legacyTextRendering) {
|
|
14432
14771
|
const metrics = this.measureSize('M'); // Use a sample character to get the ascent
|
|
14433
14772
|
baseline = 'alphabetic';
|
|
14434
|
-
|
|
14435
|
-
|
|
14436
|
-
|
|
14773
|
+
const ascent = (_a = metrics.fontBoundingBoxAscent) !== null && _a !== void 0 ? _a : metrics.actualBoundingBoxAscent;
|
|
14774
|
+
const descent = (_b = metrics.fontBoundingBoxDescent) !== null && _b !== void 0 ? _b : metrics.actualBoundingBoxDescent;
|
|
14775
|
+
translateY = (ascent - descent) / 2 + lineHeightPx / 2;
|
|
14437
14776
|
}
|
|
14438
14777
|
if (direction === RTL) {
|
|
14439
14778
|
context.setAttr('direction', direction);
|
|
@@ -14465,7 +14804,7 @@
|
|
|
14465
14804
|
if (shouldUnderline) {
|
|
14466
14805
|
context.save();
|
|
14467
14806
|
context.beginPath();
|
|
14468
|
-
const yOffset = Konva$2.
|
|
14807
|
+
const yOffset = !Konva$2.legacyTextRendering
|
|
14469
14808
|
? Math.round(fontSize / 4)
|
|
14470
14809
|
: Math.round(fontSize / 2);
|
|
14471
14810
|
const x = lineTranslateX;
|
|
@@ -14481,23 +14820,12 @@
|
|
|
14481
14820
|
context.stroke();
|
|
14482
14821
|
context.restore();
|
|
14483
14822
|
}
|
|
14484
|
-
|
|
14485
|
-
context.save();
|
|
14486
|
-
context.beginPath();
|
|
14487
|
-
const yOffset = Konva$2._fixTextRendering ? -Math.round(fontSize / 4) : 0;
|
|
14488
|
-
context.moveTo(lineTranslateX, translateY + lineTranslateY + yOffset);
|
|
14489
|
-
const lineWidth = align === JUSTIFY && !lastLine ? totalWidth - padding * 2 : width;
|
|
14490
|
-
context.lineTo(lineTranslateX + Math.round(lineWidth), translateY + lineTranslateY + yOffset);
|
|
14491
|
-
context.lineWidth = fontSize / 15;
|
|
14492
|
-
const gradient = this._getLinearGradient();
|
|
14493
|
-
context.strokeStyle = gradient || fill;
|
|
14494
|
-
context.stroke();
|
|
14495
|
-
context.restore();
|
|
14496
|
-
}
|
|
14823
|
+
// draw line-through above the text content
|
|
14497
14824
|
// As `letterSpacing` isn't supported on Safari, we use this polyfill.
|
|
14498
14825
|
// The exception is for RTL text, which we rely on native as it cannot
|
|
14499
14826
|
// be supported otherwise.
|
|
14500
|
-
if (direction !== RTL &&
|
|
14827
|
+
if (direction !== RTL &&
|
|
14828
|
+
(letterSpacing !== 0 || align === JUSTIFY || charRenderFunc)) {
|
|
14501
14829
|
// var words = text.split(' ');
|
|
14502
14830
|
const spacesNumber = text.split(' ').length - 1;
|
|
14503
14831
|
const array = stringToArray(text);
|
|
@@ -14514,7 +14842,27 @@
|
|
|
14514
14842
|
this._partialTextX = lineTranslateX;
|
|
14515
14843
|
this._partialTextY = translateY + lineTranslateY;
|
|
14516
14844
|
this._partialText = letter;
|
|
14845
|
+
if (charRenderFunc) {
|
|
14846
|
+
context.save();
|
|
14847
|
+
const previousLines = textArr.slice(0, n);
|
|
14848
|
+
const previousGraphemes = previousLines.reduce((acc, line) => acc + stringToArray(line.text).length, 0);
|
|
14849
|
+
const charIndex = li + previousGraphemes;
|
|
14850
|
+
charRenderFunc({
|
|
14851
|
+
char: letter,
|
|
14852
|
+
index: charIndex,
|
|
14853
|
+
x: lineTranslateX,
|
|
14854
|
+
y: translateY + lineTranslateY,
|
|
14855
|
+
lineIndex: n,
|
|
14856
|
+
column: li,
|
|
14857
|
+
isLastInLine: lastLine,
|
|
14858
|
+
width: this.measureSize(letter).width,
|
|
14859
|
+
context,
|
|
14860
|
+
});
|
|
14861
|
+
}
|
|
14517
14862
|
context.fillStrokeShape(this);
|
|
14863
|
+
if (charRenderFunc) {
|
|
14864
|
+
context.restore();
|
|
14865
|
+
}
|
|
14518
14866
|
lineTranslateX += this.measureSize(letter).width + letterSpacing;
|
|
14519
14867
|
}
|
|
14520
14868
|
}
|
|
@@ -14527,6 +14875,22 @@
|
|
|
14527
14875
|
this._partialText = text;
|
|
14528
14876
|
context.fillStrokeShape(this);
|
|
14529
14877
|
}
|
|
14878
|
+
// draw line-through above the text content
|
|
14879
|
+
if (shouldLineThrough) {
|
|
14880
|
+
context.save();
|
|
14881
|
+
context.beginPath();
|
|
14882
|
+
const yOffset = !Konva$2.legacyTextRendering
|
|
14883
|
+
? -Math.round(fontSize / 4)
|
|
14884
|
+
: 0;
|
|
14885
|
+
context.moveTo(0, translateY + lineTranslateY + yOffset);
|
|
14886
|
+
const lineWidth = align === JUSTIFY && !lastLine ? totalWidth - padding * 2 : width;
|
|
14887
|
+
context.lineTo(Math.round(lineWidth), translateY + lineTranslateY + yOffset);
|
|
14888
|
+
context.lineWidth = fontSize / 15;
|
|
14889
|
+
const gradient = this._getLinearGradient();
|
|
14890
|
+
context.strokeStyle = gradient || fill;
|
|
14891
|
+
context.stroke();
|
|
14892
|
+
context.restore();
|
|
14893
|
+
}
|
|
14530
14894
|
context.restore();
|
|
14531
14895
|
if (textArrLen > 1) {
|
|
14532
14896
|
translateY += lineHeightPx;
|
|
@@ -15061,6 +15425,23 @@
|
|
|
15061
15425
|
* text.textDecoration('underline line-through');
|
|
15062
15426
|
*/
|
|
15063
15427
|
Factory.addGetterSetter(Text, 'textDecoration', '');
|
|
15428
|
+
/**
|
|
15429
|
+
* get/set per-character render hook. The callback is invoked for each grapheme before drawing.
|
|
15430
|
+
* It can mutate the provided context (e.g. translate, rotate, change styles) and should return void.
|
|
15431
|
+
* Note: per-character rendering may disable native kerning/ligatures.
|
|
15432
|
+
* @name Konva.Text#charRenderFunc
|
|
15433
|
+
* @method
|
|
15434
|
+
* @param {(props: {char: string, index: number, x: number, y: number, lineIndex: number, column: number, isLastInLine: boolean, width: number, context: Konva.Context}) => void} charRenderFunc
|
|
15435
|
+
* @returns {(props: CharRenderProps) => void}
|
|
15436
|
+
* @example
|
|
15437
|
+
* // apply small x-translation to every second character
|
|
15438
|
+
* text.charRenderFunc(function(props) {
|
|
15439
|
+
* if (props.index % 2 === 1) {
|
|
15440
|
+
* props.context.translate(2, 0);
|
|
15441
|
+
* }
|
|
15442
|
+
* });
|
|
15443
|
+
*/
|
|
15444
|
+
Factory.addGetterSetter(Text, 'charRenderFunc', undefined);
|
|
15064
15445
|
|
|
15065
15446
|
const EMPTY_STRING = '', NORMAL = 'normal';
|
|
15066
15447
|
function _fillFunc(context) {
|
|
@@ -15307,7 +15688,17 @@
|
|
|
15307
15688
|
};
|
|
15308
15689
|
}
|
|
15309
15690
|
_setTextData() {
|
|
15310
|
-
const
|
|
15691
|
+
const charArr = stringToArray(this.text());
|
|
15692
|
+
const chars = [];
|
|
15693
|
+
let width = 0;
|
|
15694
|
+
for (let i = 0; i < charArr.length; i++) {
|
|
15695
|
+
chars.push({
|
|
15696
|
+
char: charArr[i],
|
|
15697
|
+
width: this._getTextSize(charArr[i]).width,
|
|
15698
|
+
});
|
|
15699
|
+
width += chars[i].width;
|
|
15700
|
+
}
|
|
15701
|
+
const { height } = this._getTextSize(this.attrs.text);
|
|
15311
15702
|
this.textWidth = width;
|
|
15312
15703
|
this.textHeight = height;
|
|
15313
15704
|
this.glyphInfo = [];
|
|
@@ -15326,31 +15717,32 @@
|
|
|
15326
15717
|
if (align === 'right') {
|
|
15327
15718
|
offset = Math.max(0, this.pathLength - textWidth);
|
|
15328
15719
|
}
|
|
15329
|
-
const charArr = stringToArray(this.text());
|
|
15330
15720
|
// Algorithm for calculating glyph positions:
|
|
15331
15721
|
// 1. Get the begging point of the glyph on the path using the offsetToGlyph,
|
|
15332
15722
|
// 2. Get the ending point of the glyph on the path using the offsetToGlyph plus glyph width,
|
|
15333
15723
|
// 3. Calculate the rotation, width, and midpoint of the glyph using the start and end points,
|
|
15334
15724
|
// 4. Add glyph width to the offsetToGlyph and repeat
|
|
15335
15725
|
let offsetToGlyph = offset;
|
|
15336
|
-
for (let i = 0; i <
|
|
15726
|
+
for (let i = 0; i < chars.length; i++) {
|
|
15337
15727
|
const charStartPoint = this._getPointAtLength(offsetToGlyph);
|
|
15338
15728
|
if (!charStartPoint)
|
|
15339
15729
|
return;
|
|
15340
|
-
|
|
15341
|
-
|
|
15730
|
+
const char = chars[i].char;
|
|
15731
|
+
let glyphWidth = chars[i].width + letterSpacing;
|
|
15732
|
+
if (char === ' ' && align === 'justify') {
|
|
15342
15733
|
const numberOfSpaces = this.text().split(' ').length - 1;
|
|
15343
15734
|
glyphWidth += (this.pathLength - textWidth) / numberOfSpaces;
|
|
15344
15735
|
}
|
|
15345
15736
|
const charEndPoint = this._getPointAtLength(offsetToGlyph + glyphWidth);
|
|
15346
|
-
if (!charEndPoint)
|
|
15737
|
+
if (!charEndPoint) {
|
|
15347
15738
|
return;
|
|
15739
|
+
}
|
|
15348
15740
|
const width = Path.getLineLength(charStartPoint.x, charStartPoint.y, charEndPoint.x, charEndPoint.y);
|
|
15349
15741
|
let kern = 0;
|
|
15350
15742
|
if (kerningFunc) {
|
|
15351
15743
|
try {
|
|
15352
15744
|
// getKerning is a user provided getter. Make sure it never breaks our logic
|
|
15353
|
-
kern = kerningFunc(
|
|
15745
|
+
kern = kerningFunc(chars[i - 1].char, char) * this.fontSize();
|
|
15354
15746
|
}
|
|
15355
15747
|
catch (e) {
|
|
15356
15748
|
kern = 0;
|
|
@@ -15617,6 +16009,7 @@
|
|
|
15617
16009
|
'offsetYChange',
|
|
15618
16010
|
'transformsEnabledChange',
|
|
15619
16011
|
'strokeWidthChange',
|
|
16012
|
+
'draggableChange',
|
|
15620
16013
|
];
|
|
15621
16014
|
const ANGLES = {
|
|
15622
16015
|
'top-left': -45,
|
|
@@ -16090,7 +16483,6 @@
|
|
|
16090
16483
|
name: 'back',
|
|
16091
16484
|
width: 0,
|
|
16092
16485
|
height: 0,
|
|
16093
|
-
draggable: true,
|
|
16094
16486
|
sceneFunc(ctx, shape) {
|
|
16095
16487
|
const tr = shape.getParent();
|
|
16096
16488
|
const padding = tr.padding();
|
|
@@ -16488,6 +16880,16 @@
|
|
|
16488
16880
|
const delta = newTr.multiply(oldTr.invert());
|
|
16489
16881
|
this._nodes.forEach((node) => {
|
|
16490
16882
|
var _a;
|
|
16883
|
+
// check to close this issue: https://github.com/konvajs/konva/issues/1957
|
|
16884
|
+
// a node can be destroyed during the transformation
|
|
16885
|
+
// probably a developer must remove it from transformer
|
|
16886
|
+
if (!node.getStage()) {
|
|
16887
|
+
// do we need a helping message?
|
|
16888
|
+
// Util.error(
|
|
16889
|
+
// 'Node is not attached to the stage. This is not allowed. Please attach the node to the stage before transforming. If node was destroyed, make sure to remove it from transformer.'
|
|
16890
|
+
// );
|
|
16891
|
+
return;
|
|
16892
|
+
}
|
|
16491
16893
|
// for each node we have the same [delta transform]
|
|
16492
16894
|
// the equations is
|
|
16493
16895
|
// [delta transform] * [parent transform] * [old local transform] = [parent transform] * [new local transform]
|
|
@@ -16618,6 +17020,7 @@
|
|
|
16618
17020
|
stroke: this.borderStroke(),
|
|
16619
17021
|
strokeWidth: this.borderStrokeWidth(),
|
|
16620
17022
|
dash: this.borderDash(),
|
|
17023
|
+
draggable: this.nodes().some((node) => node.draggable()),
|
|
16621
17024
|
x: 0,
|
|
16622
17025
|
y: 0,
|
|
16623
17026
|
});
|
|
@@ -17361,6 +17764,7 @@
|
|
|
17361
17764
|
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
17362
17765
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
17363
17766
|
OTHER DEALINGS IN THE SOFTWARE.
|
|
17767
|
+
* @license MIT
|
|
17364
17768
|
*/
|
|
17365
17769
|
function BlurStack() {
|
|
17366
17770
|
this.r = 0;
|
|
@@ -17615,6 +18019,8 @@
|
|
|
17615
18019
|
|
|
17616
18020
|
/**
|
|
17617
18021
|
* Brighten Filter.
|
|
18022
|
+
* @deprecated Use {@link Konva.Filters.Brightness} instead for CSS-compatible behavior.
|
|
18023
|
+
* This filter uses additive brightness adjustment (adds a constant value to RGB channels).
|
|
17618
18024
|
* @function
|
|
17619
18025
|
* @memberof Konva.Filters
|
|
17620
18026
|
* @param {Object} imageData
|
|
@@ -17645,6 +18051,31 @@
|
|
|
17645
18051
|
* @returns {Number}
|
|
17646
18052
|
*/
|
|
17647
18053
|
|
|
18054
|
+
/**
|
|
18055
|
+
* Brightness Filter.
|
|
18056
|
+
* CSS-compatible brightness filter that uses multiplicative approach.
|
|
18057
|
+
* @function
|
|
18058
|
+
* @memberof Konva.Filters
|
|
18059
|
+
* @param {Object} imageData
|
|
18060
|
+
* @example
|
|
18061
|
+
* node.cache();
|
|
18062
|
+
* node.filters([Konva.Filters.Brightness]);
|
|
18063
|
+
* node.brightness(1.5); // 50% brighter (CSS-compatible)
|
|
18064
|
+
*/
|
|
18065
|
+
const Brightness = function (imageData) {
|
|
18066
|
+
const brightness = this.brightness(), data = imageData.data, len = data.length;
|
|
18067
|
+
for (let i = 0; i < len; i += 4) {
|
|
18068
|
+
// red
|
|
18069
|
+
data[i] = Math.min(255, data[i] * brightness);
|
|
18070
|
+
// green
|
|
18071
|
+
data[i + 1] = Math.min(255, data[i + 1] * brightness);
|
|
18072
|
+
// blue
|
|
18073
|
+
data[i + 2] = Math.min(255, data[i + 2] * brightness);
|
|
18074
|
+
}
|
|
18075
|
+
};
|
|
18076
|
+
// Note: brightness property is already defined in Brighten.ts
|
|
18077
|
+
// This filter reuses the existing brightness property but with CSS-compatible behavior
|
|
18078
|
+
|
|
17648
18079
|
/**
|
|
17649
18080
|
* Contrast Filter.
|
|
17650
18081
|
* @function
|
|
@@ -17701,9 +18132,6 @@
|
|
|
17701
18132
|
|
|
17702
18133
|
/**
|
|
17703
18134
|
* Emboss Filter.
|
|
17704
|
-
* Pixastic Lib - Emboss filter - v0.1.0
|
|
17705
|
-
* Copyright (c) 2008 Jacob Seidelin, jseidelin@nihilogic.dk, http://blog.nihilogic.dk/
|
|
17706
|
-
* License: [http://www.pixastic.com/lib/license.txt]
|
|
17707
18135
|
* @function
|
|
17708
18136
|
* @memberof Konva.Filters
|
|
17709
18137
|
* @param {Object} imageData
|
|
@@ -17716,103 +18144,116 @@
|
|
|
17716
18144
|
* node.embossBlend(true);
|
|
17717
18145
|
*/
|
|
17718
18146
|
const Emboss = function (imageData) {
|
|
17719
|
-
|
|
17720
|
-
|
|
17721
|
-
|
|
17722
|
-
|
|
17723
|
-
|
|
17724
|
-
|
|
17725
|
-
|
|
17726
|
-
|
|
17727
|
-
|
|
17728
|
-
|
|
17729
|
-
|
|
17730
|
-
|
|
17731
|
-
|
|
17732
|
-
|
|
17733
|
-
|
|
17734
|
-
|
|
17735
|
-
|
|
17736
|
-
|
|
17737
|
-
|
|
17738
|
-
|
|
17739
|
-
|
|
17740
|
-
|
|
17741
|
-
|
|
17742
|
-
|
|
17743
|
-
|
|
17744
|
-
|
|
17745
|
-
|
|
17746
|
-
|
|
17747
|
-
|
|
17748
|
-
|
|
17749
|
-
|
|
17750
|
-
|
|
17751
|
-
|
|
17752
|
-
|
|
17753
|
-
|
|
17754
|
-
|
|
17755
|
-
|
|
17756
|
-
|
|
17757
|
-
|
|
17758
|
-
|
|
17759
|
-
|
|
17760
|
-
|
|
17761
|
-
|
|
17762
|
-
|
|
17763
|
-
let
|
|
17764
|
-
|
|
17765
|
-
|
|
17766
|
-
|
|
17767
|
-
|
|
17768
|
-
|
|
17769
|
-
|
|
17770
|
-
|
|
17771
|
-
|
|
17772
|
-
|
|
17773
|
-
|
|
17774
|
-
|
|
17775
|
-
|
|
17776
|
-
|
|
17777
|
-
|
|
17778
|
-
|
|
17779
|
-
|
|
17780
|
-
|
|
17781
|
-
|
|
17782
|
-
|
|
17783
|
-
|
|
17784
|
-
|
|
17785
|
-
|
|
17786
|
-
const
|
|
17787
|
-
const
|
|
17788
|
-
const absB = dB > 0 ? dB : -dB;
|
|
17789
|
-
if (absG > absDif) {
|
|
17790
|
-
dif = dG;
|
|
17791
|
-
}
|
|
17792
|
-
if (absB > absDif) {
|
|
17793
|
-
dif = dB;
|
|
17794
|
-
}
|
|
17795
|
-
dif *= strength;
|
|
18147
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
18148
|
+
const data = imageData.data;
|
|
18149
|
+
const w = imageData.width;
|
|
18150
|
+
const h = imageData.height;
|
|
18151
|
+
// Inputs from Konva node
|
|
18152
|
+
const strength01 = Math.min(1, Math.max(0, (_b = (_a = this.embossStrength) === null || _a === void 0 ? void 0 : _a.call(this)) !== null && _b !== void 0 ? _b : 0.5)); // [0..1]
|
|
18153
|
+
const whiteLevel01 = Math.min(1, Math.max(0, (_d = (_c = this.embossWhiteLevel) === null || _c === void 0 ? void 0 : _c.call(this)) !== null && _d !== void 0 ? _d : 0.5)); // [0..1]
|
|
18154
|
+
// Convert string direction to degrees
|
|
18155
|
+
const directionMap = {
|
|
18156
|
+
'top-left': 315,
|
|
18157
|
+
top: 270,
|
|
18158
|
+
'top-right': 225,
|
|
18159
|
+
right: 180,
|
|
18160
|
+
'bottom-right': 135,
|
|
18161
|
+
bottom: 90,
|
|
18162
|
+
'bottom-left': 45,
|
|
18163
|
+
left: 0,
|
|
18164
|
+
};
|
|
18165
|
+
const directionDeg = (_g = directionMap[(_f = (_e = this.embossDirection) === null || _e === void 0 ? void 0 : _e.call(this)) !== null && _f !== void 0 ? _f : 'top-left']) !== null && _g !== void 0 ? _g : 315; // degrees
|
|
18166
|
+
const blend = !!((_j = (_h = this.embossBlend) === null || _h === void 0 ? void 0 : _h.call(this)) !== null && _j !== void 0 ? _j : false);
|
|
18167
|
+
// Internal mapping:
|
|
18168
|
+
// - "strength" was 0..10; we honor your 0..1 API and scale accordingly.
|
|
18169
|
+
// - Sobel directional response is roughly in [-1020..1020] for 8-bit luminance; scale to ~±128.
|
|
18170
|
+
const strength = strength01 * 10;
|
|
18171
|
+
const bias = whiteLevel01 * 255;
|
|
18172
|
+
const dirRad = (directionDeg * Math.PI) / 180;
|
|
18173
|
+
const cx = Math.cos(dirRad);
|
|
18174
|
+
const cy = Math.sin(dirRad);
|
|
18175
|
+
const SCALE = (128 / 1020) * strength; // ≈0.1255 * strength
|
|
18176
|
+
// Precompute luminance (Rec.709)
|
|
18177
|
+
const src = new Uint8ClampedArray(data); // snapshot
|
|
18178
|
+
const lum = new Float32Array(w * h);
|
|
18179
|
+
for (let p = 0, i = 0; i < data.length; i += 4, p++) {
|
|
18180
|
+
lum[p] = 0.2126 * src[i] + 0.7152 * src[i + 1] + 0.0722 * src[i + 2];
|
|
18181
|
+
}
|
|
18182
|
+
// Sobel kernels (flattened)
|
|
18183
|
+
const Gx = [-1, 0, 1, -2, 0, 2, -1, 0, 1];
|
|
18184
|
+
const Gy = [-1, -2, -1, 0, 0, 0, 1, 2, 1];
|
|
18185
|
+
// neighbor offsets around center pixel in lum space
|
|
18186
|
+
const OFF = [-w - 1, -w, -w + 1, -1, 0, 1, w - 1, w, w + 1];
|
|
18187
|
+
// Helpers
|
|
18188
|
+
const clamp8 = (v) => (v < 0 ? 0 : v > 255 ? 255 : v);
|
|
18189
|
+
// Process: leave a 1px border unchanged (faster/cleaner)
|
|
18190
|
+
for (let y = 1; y < h - 1; y++) {
|
|
18191
|
+
for (let x = 1; x < w - 1; x++) {
|
|
18192
|
+
const p = y * w + x;
|
|
18193
|
+
// Directional derivative = (cosθ * Gx + sinθ * Gy) • neighborhood(lum)
|
|
18194
|
+
let sx = 0, sy = 0;
|
|
18195
|
+
// unroll loop for speed
|
|
18196
|
+
sx += lum[p + OFF[0]] * Gx[0];
|
|
18197
|
+
sy += lum[p + OFF[0]] * Gy[0];
|
|
18198
|
+
sx += lum[p + OFF[1]] * Gx[1];
|
|
18199
|
+
sy += lum[p + OFF[1]] * Gy[1];
|
|
18200
|
+
sx += lum[p + OFF[2]] * Gx[2];
|
|
18201
|
+
sy += lum[p + OFF[2]] * Gy[2];
|
|
18202
|
+
sx += lum[p + OFF[3]] * Gx[3];
|
|
18203
|
+
sy += lum[p + OFF[3]] * Gy[3];
|
|
18204
|
+
// center has 0 weights in both Sobel masks; can skip if desired
|
|
18205
|
+
sx += lum[p + OFF[5]] * Gx[5];
|
|
18206
|
+
sy += lum[p + OFF[5]] * Gy[5];
|
|
18207
|
+
sx += lum[p + OFF[6]] * Gx[6];
|
|
18208
|
+
sy += lum[p + OFF[6]] * Gy[6];
|
|
18209
|
+
sx += lum[p + OFF[7]] * Gx[7];
|
|
18210
|
+
sy += lum[p + OFF[7]] * Gy[7];
|
|
18211
|
+
sx += lum[p + OFF[8]] * Gx[8];
|
|
18212
|
+
sy += lum[p + OFF[8]] * Gy[8];
|
|
18213
|
+
const r = cx * sx + cy * sy; // directional response
|
|
18214
|
+
const outGray = clamp8(bias + r * SCALE); // biased, scaled, clamped
|
|
18215
|
+
const o = p * 4;
|
|
17796
18216
|
if (blend) {
|
|
17797
|
-
|
|
17798
|
-
const
|
|
17799
|
-
|
|
17800
|
-
data[
|
|
17801
|
-
data[
|
|
17802
|
-
data[
|
|
18217
|
+
// Add the emboss "relief" around chosen bias to original RGB
|
|
18218
|
+
const delta = outGray - bias; // symmetric around whiteLevel
|
|
18219
|
+
data[o] = clamp8(src[o] + delta);
|
|
18220
|
+
data[o + 1] = clamp8(src[o + 1] + delta);
|
|
18221
|
+
data[o + 2] = clamp8(src[o + 2] + delta);
|
|
18222
|
+
data[o + 3] = src[o + 3];
|
|
17803
18223
|
}
|
|
17804
18224
|
else {
|
|
17805
|
-
|
|
17806
|
-
|
|
17807
|
-
|
|
17808
|
-
|
|
17809
|
-
|
|
17810
|
-
|
|
17811
|
-
|
|
17812
|
-
|
|
17813
|
-
|
|
17814
|
-
|
|
17815
|
-
|
|
18225
|
+
// Grayscale embossed output
|
|
18226
|
+
data[o] = data[o + 1] = data[o + 2] = outGray;
|
|
18227
|
+
data[o + 3] = src[o + 3];
|
|
18228
|
+
}
|
|
18229
|
+
}
|
|
18230
|
+
}
|
|
18231
|
+
// Copy border (untouched) to keep edges clean
|
|
18232
|
+
// top & bottom rows
|
|
18233
|
+
for (let x = 0; x < w; x++) {
|
|
18234
|
+
let oTop = x * 4, oBot = ((h - 1) * w + x) * 4;
|
|
18235
|
+
data[oTop] = src[oTop];
|
|
18236
|
+
data[oTop + 1] = src[oTop + 1];
|
|
18237
|
+
data[oTop + 2] = src[oTop + 2];
|
|
18238
|
+
data[oTop + 3] = src[oTop + 3];
|
|
18239
|
+
data[oBot] = src[oBot];
|
|
18240
|
+
data[oBot + 1] = src[oBot + 1];
|
|
18241
|
+
data[oBot + 2] = src[oBot + 2];
|
|
18242
|
+
data[oBot + 3] = src[oBot + 3];
|
|
18243
|
+
}
|
|
18244
|
+
// left & right columns
|
|
18245
|
+
for (let y = 1; y < h - 1; y++) {
|
|
18246
|
+
let oL = y * w * 4, oR = (y * w + (w - 1)) * 4;
|
|
18247
|
+
data[oL] = src[oL];
|
|
18248
|
+
data[oL + 1] = src[oL + 1];
|
|
18249
|
+
data[oL + 2] = src[oL + 2];
|
|
18250
|
+
data[oL + 3] = src[oL + 3];
|
|
18251
|
+
data[oR] = src[oR];
|
|
18252
|
+
data[oR + 1] = src[oR + 1];
|
|
18253
|
+
data[oR + 2] = src[oR + 2];
|
|
18254
|
+
data[oR + 3] = src[oR + 3];
|
|
18255
|
+
}
|
|
18256
|
+
return imageData;
|
|
17816
18257
|
};
|
|
17817
18258
|
Factory.addGetterSetter(Node, 'embossStrength', 0.5, getNumberValidator(), Factory.afterSetFilter);
|
|
17818
18259
|
/**
|
|
@@ -18454,7 +18895,17 @@
|
|
|
18454
18895
|
return maskResult;
|
|
18455
18896
|
}
|
|
18456
18897
|
function smoothEdgeMask(mask, sw, sh) {
|
|
18457
|
-
const weights = [
|
|
18898
|
+
const weights = [
|
|
18899
|
+
1 / 9,
|
|
18900
|
+
1 / 9,
|
|
18901
|
+
1 / 9,
|
|
18902
|
+
1 / 9,
|
|
18903
|
+
1 / 9,
|
|
18904
|
+
1 / 9,
|
|
18905
|
+
1 / 9,
|
|
18906
|
+
1 / 9,
|
|
18907
|
+
1 / 9,
|
|
18908
|
+
];
|
|
18458
18909
|
const side = Math.round(Math.sqrt(weights.length));
|
|
18459
18910
|
const halfSide = Math.floor(side / 2);
|
|
18460
18911
|
const maskResult = [];
|
|
@@ -18840,9 +19291,6 @@
|
|
|
18840
19291
|
|
|
18841
19292
|
/**
|
|
18842
19293
|
* Solarize Filter
|
|
18843
|
-
* Pixastic Lib - Solarize filter - v0.1.0
|
|
18844
|
-
* Copyright (c) 2008 Jacob Seidelin, jseidelin@nihilogic.dk, http://blog.nihilogic.dk/
|
|
18845
|
-
* License: [http://www.pixastic.com/lib/license.txt]
|
|
18846
19294
|
* @function
|
|
18847
19295
|
* @name Solarize
|
|
18848
19296
|
* @memberof Konva.Filters
|
|
@@ -18852,30 +19300,19 @@
|
|
|
18852
19300
|
* node.filters([Konva.Filters.Solarize]);
|
|
18853
19301
|
*/
|
|
18854
19302
|
const Solarize = function (imageData) {
|
|
18855
|
-
const
|
|
18856
|
-
|
|
18857
|
-
|
|
18858
|
-
const
|
|
18859
|
-
|
|
18860
|
-
|
|
18861
|
-
|
|
18862
|
-
|
|
18863
|
-
|
|
18864
|
-
|
|
18865
|
-
|
|
18866
|
-
|
|
18867
|
-
|
|
18868
|
-
if (g > 127) {
|
|
18869
|
-
g = 255 - g;
|
|
18870
|
-
}
|
|
18871
|
-
if (b > 127) {
|
|
18872
|
-
b = 255 - b;
|
|
18873
|
-
}
|
|
18874
|
-
data[offset] = r;
|
|
18875
|
-
data[offset + 1] = g;
|
|
18876
|
-
data[offset + 2] = b;
|
|
18877
|
-
} while (--x);
|
|
18878
|
-
} while (--y);
|
|
19303
|
+
const threshold = 128;
|
|
19304
|
+
const d = imageData.data;
|
|
19305
|
+
for (let i = 0; i < d.length; i += 4) {
|
|
19306
|
+
const r = d[i], g = d[i + 1], b = d[i + 2];
|
|
19307
|
+
// sRGB luma
|
|
19308
|
+
const L = 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
19309
|
+
if (L >= threshold) {
|
|
19310
|
+
d[i] = 255 - r;
|
|
19311
|
+
d[i + 1] = 255 - g;
|
|
19312
|
+
d[i + 2] = 255 - b;
|
|
19313
|
+
}
|
|
19314
|
+
}
|
|
19315
|
+
return imageData;
|
|
18879
19316
|
};
|
|
18880
19317
|
|
|
18881
19318
|
/**
|
|
@@ -18934,6 +19371,7 @@
|
|
|
18934
19371
|
*/
|
|
18935
19372
|
Filters: {
|
|
18936
19373
|
Blur,
|
|
19374
|
+
Brightness,
|
|
18937
19375
|
Brighten,
|
|
18938
19376
|
Contrast,
|
|
18939
19377
|
Emboss,
|