konva 9.3.22 → 10.0.0-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/README.md +1 -1
- package/konva.js +690 -221
- 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 +44 -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 +22 -26
- 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-1
|
|
9
9
|
* http://konvajs.org/
|
|
10
10
|
* Licensed under the MIT
|
|
11
|
-
* Date: Tue
|
|
11
|
+
* Date: Tue Sep 02 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-1',
|
|
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
|
}
|
|
@@ -2094,12 +2200,45 @@
|
|
|
2094
2200
|
this.setSize(config.width, config.height);
|
|
2095
2201
|
}
|
|
2096
2202
|
}
|
|
2203
|
+
// function checks if canvas farbling is active
|
|
2204
|
+
// canvas farbling is a Browser security feature, it break konva internals
|
|
2205
|
+
function isCanvasFarblingActive() {
|
|
2206
|
+
const c = Util.createCanvasElement();
|
|
2207
|
+
c.width = 1;
|
|
2208
|
+
c.height = 1;
|
|
2209
|
+
const ctx = c.getContext('2d', {
|
|
2210
|
+
willReadFrequently: true,
|
|
2211
|
+
});
|
|
2212
|
+
ctx.clearRect(0, 0, 1, 1);
|
|
2213
|
+
ctx.fillStyle = 'rgba(255,0,255,1)'; // clear #FF00FF, no alpha
|
|
2214
|
+
ctx.fillRect(0, 0, 1, 1);
|
|
2215
|
+
const d = ctx.getImageData(0, 0, 1, 1).data;
|
|
2216
|
+
const exact = d[0] === 255 && d[1] === 0 && d[2] === 255 && d[3] === 255;
|
|
2217
|
+
return !exact;
|
|
2218
|
+
}
|
|
2219
|
+
function isBraveBrowser() {
|
|
2220
|
+
var _a, _b;
|
|
2221
|
+
if (typeof navigator === 'undefined') {
|
|
2222
|
+
return false;
|
|
2223
|
+
}
|
|
2224
|
+
// @ts-ignore
|
|
2225
|
+
return (_b = (_a = navigator.brave) === null || _a === void 0 ? void 0 : _a.isBrave()) !== null && _b !== void 0 ? _b : false;
|
|
2226
|
+
}
|
|
2227
|
+
let warned = false;
|
|
2228
|
+
function checkHitCanvasSupport() {
|
|
2229
|
+
if (isBraveBrowser() && isCanvasFarblingActive() && !warned) {
|
|
2230
|
+
warned = true;
|
|
2231
|
+
Util.error('Looks like you have "Brave shield" enabled in your browser. It breaks KonvaJS internals. Please disable it. You may need to ask your users to do the same.');
|
|
2232
|
+
}
|
|
2233
|
+
return isBraveBrowser() && isCanvasFarblingActive();
|
|
2234
|
+
}
|
|
2097
2235
|
class HitCanvas extends Canvas {
|
|
2098
2236
|
constructor(config = { width: 0, height: 0 }) {
|
|
2099
2237
|
super(config);
|
|
2100
2238
|
this.hitCanvas = true;
|
|
2101
2239
|
this.context = new HitContext(this);
|
|
2102
2240
|
this.setSize(config.width, config.height);
|
|
2241
|
+
checkHitCanvasSupport();
|
|
2103
2242
|
}
|
|
2104
2243
|
}
|
|
2105
2244
|
|
|
@@ -2513,6 +2652,83 @@
|
|
|
2513
2652
|
},
|
|
2514
2653
|
};
|
|
2515
2654
|
|
|
2655
|
+
// CSS filter parser for fallback to function filters
|
|
2656
|
+
function parseCSSFilters(cssFilter) {
|
|
2657
|
+
// Parse common CSS filter functions and map to Konva filters
|
|
2658
|
+
const filterRegex = /(\w+)\(([^)]+)\)/g;
|
|
2659
|
+
let match;
|
|
2660
|
+
while ((match = filterRegex.exec(cssFilter)) !== null) {
|
|
2661
|
+
const [, filterName, filterValue] = match;
|
|
2662
|
+
switch (filterName) {
|
|
2663
|
+
case 'blur': {
|
|
2664
|
+
const blurRadius = parseFloat(filterValue.replace('px', ''));
|
|
2665
|
+
return function (imageData) {
|
|
2666
|
+
// CSS blur uses standard deviation, Stack Blur uses radius
|
|
2667
|
+
// Empirical testing shows CSS blur needs ~0.5 scaling for visual match
|
|
2668
|
+
this.blurRadius(blurRadius * 0.5);
|
|
2669
|
+
// Access filters through dynamic import to avoid circular dependency
|
|
2670
|
+
const KonvaFilters = Konva$2.Filters;
|
|
2671
|
+
if (KonvaFilters && KonvaFilters.Blur) {
|
|
2672
|
+
KonvaFilters.Blur.call(this, imageData);
|
|
2673
|
+
}
|
|
2674
|
+
};
|
|
2675
|
+
}
|
|
2676
|
+
case 'brightness': {
|
|
2677
|
+
const brightness = filterValue.includes('%')
|
|
2678
|
+
? parseFloat(filterValue) / 100
|
|
2679
|
+
: parseFloat(filterValue);
|
|
2680
|
+
return function (imageData) {
|
|
2681
|
+
this.brightness(brightness); // CSS uses multiplier
|
|
2682
|
+
const KonvaFilters = Konva$2.Filters;
|
|
2683
|
+
if (KonvaFilters && KonvaFilters.Brightness) {
|
|
2684
|
+
KonvaFilters.Brightness.call(this, imageData);
|
|
2685
|
+
}
|
|
2686
|
+
};
|
|
2687
|
+
}
|
|
2688
|
+
case 'contrast': {
|
|
2689
|
+
const contrast = parseFloat(filterValue);
|
|
2690
|
+
return function (imageData) {
|
|
2691
|
+
// Convert CSS contrast to Konva parameter using square root conversion
|
|
2692
|
+
// to account for Konva's quadratic scaling: Math.pow((param + 100) / 100, 2)
|
|
2693
|
+
const konvaContrast = 100 * (Math.sqrt(contrast) - 1);
|
|
2694
|
+
this.contrast(konvaContrast);
|
|
2695
|
+
const KonvaFilters = Konva$2.Filters;
|
|
2696
|
+
if (KonvaFilters && KonvaFilters.Contrast) {
|
|
2697
|
+
KonvaFilters.Contrast.call(this, imageData);
|
|
2698
|
+
}
|
|
2699
|
+
};
|
|
2700
|
+
}
|
|
2701
|
+
case 'grayscale': {
|
|
2702
|
+
return function (imageData) {
|
|
2703
|
+
const KonvaFilters = Konva$2.Filters;
|
|
2704
|
+
if (KonvaFilters && KonvaFilters.Grayscale) {
|
|
2705
|
+
KonvaFilters.Grayscale.call(this, imageData);
|
|
2706
|
+
}
|
|
2707
|
+
};
|
|
2708
|
+
}
|
|
2709
|
+
case 'sepia': {
|
|
2710
|
+
return function (imageData) {
|
|
2711
|
+
const KonvaFilters = Konva$2.Filters;
|
|
2712
|
+
if (KonvaFilters && KonvaFilters.Sepia) {
|
|
2713
|
+
KonvaFilters.Sepia.call(this, imageData);
|
|
2714
|
+
}
|
|
2715
|
+
};
|
|
2716
|
+
}
|
|
2717
|
+
case 'invert': {
|
|
2718
|
+
return function (imageData) {
|
|
2719
|
+
const KonvaFilters = Konva$2.Filters;
|
|
2720
|
+
if (KonvaFilters && KonvaFilters.Invert) {
|
|
2721
|
+
KonvaFilters.Invert.call(this, imageData);
|
|
2722
|
+
}
|
|
2723
|
+
};
|
|
2724
|
+
}
|
|
2725
|
+
default:
|
|
2726
|
+
Util.warn(`CSS filter "${filterName}" is not supported in fallback mode. Consider using function filters for better compatibility.`);
|
|
2727
|
+
break;
|
|
2728
|
+
}
|
|
2729
|
+
}
|
|
2730
|
+
return () => { };
|
|
2731
|
+
}
|
|
2516
2732
|
// CONSTANTS
|
|
2517
2733
|
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
2734
|
'xChange.konva',
|
|
@@ -2905,39 +3121,54 @@
|
|
|
2905
3121
|
}
|
|
2906
3122
|
_getCachedSceneCanvas() {
|
|
2907
3123
|
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;
|
|
3124
|
+
if (!filters || filters.length === 0) {
|
|
3125
|
+
return sceneCanvas;
|
|
3126
|
+
}
|
|
3127
|
+
if (this._filterUpToDate) {
|
|
3128
|
+
return filterCanvas;
|
|
3129
|
+
}
|
|
3130
|
+
let useNativeOnly = true;
|
|
3131
|
+
for (let i = 0; i < filters.length; i++) {
|
|
3132
|
+
typeof filters[i] === 'string' && !isCSSFiltersSupported();
|
|
3133
|
+
if (typeof filters[i] !== 'string' || !isCSSFiltersSupported()) {
|
|
3134
|
+
useNativeOnly = false;
|
|
3135
|
+
break;
|
|
2937
3136
|
}
|
|
3137
|
+
}
|
|
3138
|
+
const ratio = sceneCanvas.pixelRatio;
|
|
3139
|
+
filterCanvas.setSize(sceneCanvas.width / sceneCanvas.pixelRatio, sceneCanvas.height / sceneCanvas.pixelRatio);
|
|
3140
|
+
if (useNativeOnly) {
|
|
3141
|
+
const finalFilter = filters.join(' ');
|
|
3142
|
+
filterContext.save();
|
|
3143
|
+
filterContext.setAttr('filter', finalFilter);
|
|
3144
|
+
filterContext.drawImage(sceneCanvas._canvas, 0, 0, sceneCanvas.getWidth() / ratio, sceneCanvas.getHeight() / ratio);
|
|
3145
|
+
filterContext.restore();
|
|
3146
|
+
this._filterUpToDate = true;
|
|
2938
3147
|
return filterCanvas;
|
|
2939
3148
|
}
|
|
2940
|
-
|
|
3149
|
+
try {
|
|
3150
|
+
len = filters.length;
|
|
3151
|
+
filterContext.clear();
|
|
3152
|
+
// copy cached canvas onto filter context
|
|
3153
|
+
filterContext.drawImage(sceneCanvas._canvas, 0, 0, sceneCanvas.getWidth() / ratio, sceneCanvas.getHeight() / ratio);
|
|
3154
|
+
imageData = filterContext.getImageData(0, 0, filterCanvas.getWidth(), filterCanvas.getHeight());
|
|
3155
|
+
// apply filters to filter context
|
|
3156
|
+
for (n = 0; n < len; n++) {
|
|
3157
|
+
filter = filters[n];
|
|
3158
|
+
if (typeof filter === 'string') {
|
|
3159
|
+
filter = parseCSSFilters(filter);
|
|
3160
|
+
}
|
|
3161
|
+
filter.call(this, imageData);
|
|
3162
|
+
filterContext.putImageData(imageData, 0, 0);
|
|
3163
|
+
}
|
|
3164
|
+
}
|
|
3165
|
+
catch (e) {
|
|
3166
|
+
Util.error('Unable to apply filter. ' +
|
|
3167
|
+
e.message +
|
|
3168
|
+
' This post my help you https://konvajs.org/docs/posts/Tainted_Canvas.html.');
|
|
3169
|
+
}
|
|
3170
|
+
this._filterUpToDate = true;
|
|
3171
|
+
return filterCanvas;
|
|
2941
3172
|
}
|
|
2942
3173
|
/**
|
|
2943
3174
|
* bind events to the node. KonvaJS supports mouseover, mousemove,
|
|
@@ -3181,7 +3412,7 @@
|
|
|
3181
3412
|
* @returns {Array}
|
|
3182
3413
|
* @example
|
|
3183
3414
|
* shape.getAncestors().forEach(function(node) {
|
|
3184
|
-
* console.log(node.
|
|
3415
|
+
* console.log(node.id());
|
|
3185
3416
|
* })
|
|
3186
3417
|
*/
|
|
3187
3418
|
getAncestors() {
|
|
@@ -5176,25 +5407,30 @@
|
|
|
5176
5407
|
return val;
|
|
5177
5408
|
});
|
|
5178
5409
|
/**
|
|
5179
|
-
* get/set filters.
|
|
5410
|
+
* get/set filters. Supports function filters, CSS filter strings, or mixed arrays.
|
|
5411
|
+
* CSS filters are applied using native browser performance when possible, function filters use ImageData manipulation.
|
|
5412
|
+
* CSS filters automatically fall back to function filters in unsupported browsers.
|
|
5180
5413
|
* @name Konva.Node#filters
|
|
5181
5414
|
* @method
|
|
5182
|
-
* @param {Array} filters array of
|
|
5415
|
+
* @param {Array} filters array of filter functions and/or CSS filter strings
|
|
5183
5416
|
* @returns {Array}
|
|
5184
5417
|
* @example
|
|
5185
5418
|
* // get filters
|
|
5186
5419
|
* var filters = node.filters();
|
|
5187
5420
|
*
|
|
5188
|
-
* // set
|
|
5421
|
+
* // set CSS filters only (no caching required, uses native performance)
|
|
5422
|
+
* node.filters(['blur(5px)', 'brightness(1.2)', 'contrast(1.5)']);
|
|
5423
|
+
*
|
|
5424
|
+
* // set function filters only (caching required)
|
|
5189
5425
|
* node.cache();
|
|
5190
|
-
* node.filters([Konva.Filters.Blur]);
|
|
5426
|
+
* node.filters([Konva.Filters.Blur, Konva.Filters.Sepia, Konva.Filters.Invert]);
|
|
5191
5427
|
*
|
|
5192
|
-
* //
|
|
5428
|
+
* // mix CSS and function filters (caching required, uses fallback strategy)
|
|
5193
5429
|
* node.cache();
|
|
5194
5430
|
* node.filters([
|
|
5195
|
-
*
|
|
5196
|
-
* Konva.Filters.
|
|
5197
|
-
*
|
|
5431
|
+
* 'blur(3px)', // CSS filter
|
|
5432
|
+
* Konva.Filters.Invert, // function filter
|
|
5433
|
+
* 'brightness(1.5)' // CSS filter
|
|
5198
5434
|
* ]);
|
|
5199
5435
|
*/
|
|
5200
5436
|
addGetterSetter(Node, 'visible', true, getBooleanValidator());
|
|
@@ -6408,7 +6644,14 @@
|
|
|
6408
6644
|
if (!events) {
|
|
6409
6645
|
return;
|
|
6410
6646
|
}
|
|
6411
|
-
|
|
6647
|
+
// prevent default only for touch-based interactions to avoid blocking
|
|
6648
|
+
// native mouse wheel scrolling during drag on desktop
|
|
6649
|
+
const isTouchPointer = evt.type.indexOf('touch') >= 0 ||
|
|
6650
|
+
evt.pointerType === 'touch';
|
|
6651
|
+
if (Konva$2.isDragging() &&
|
|
6652
|
+
DD.node.preventDefault() &&
|
|
6653
|
+
evt.cancelable &&
|
|
6654
|
+
isTouchPointer) {
|
|
6412
6655
|
evt.preventDefault();
|
|
6413
6656
|
}
|
|
6414
6657
|
this.setPointersPositions(evt);
|
|
@@ -6475,7 +6718,7 @@
|
|
|
6475
6718
|
const clickStartShape = this[eventType + 'ClickStartShape'];
|
|
6476
6719
|
const clickEndShape = this[eventType + 'ClickEndShape'];
|
|
6477
6720
|
const processedShapesIds = {};
|
|
6478
|
-
let
|
|
6721
|
+
let skipPointerUpTrigger = false;
|
|
6479
6722
|
this._changedPointerPositions.forEach((pos) => {
|
|
6480
6723
|
const shape = (getCapturedShape(pos.id) ||
|
|
6481
6724
|
this.getIntersection(pos));
|
|
@@ -6502,7 +6745,7 @@
|
|
|
6502
6745
|
Konva$2['_' + eventType + 'InDblClickWindow'] = false;
|
|
6503
6746
|
}, Konva$2.dblClickWindow);
|
|
6504
6747
|
if (shape && shape.isListening()) {
|
|
6505
|
-
|
|
6748
|
+
skipPointerUpTrigger = true;
|
|
6506
6749
|
this[eventType + 'ClickEndShape'] = shape;
|
|
6507
6750
|
shape._fireAndBubble(events.pointerup, { ...event });
|
|
6508
6751
|
// detect if click or double click occurred
|
|
@@ -6517,6 +6760,15 @@
|
|
|
6517
6760
|
}
|
|
6518
6761
|
else {
|
|
6519
6762
|
this[eventType + 'ClickEndShape'] = null;
|
|
6763
|
+
if (!skipPointerUpTrigger) {
|
|
6764
|
+
this._fire(events.pointerup, {
|
|
6765
|
+
evt: evt,
|
|
6766
|
+
target: this,
|
|
6767
|
+
currentTarget: this,
|
|
6768
|
+
pointerId: this._changedPointerPositions[0].id,
|
|
6769
|
+
});
|
|
6770
|
+
skipPointerUpTrigger = true;
|
|
6771
|
+
}
|
|
6520
6772
|
if (Konva$2['_' + eventType + 'ListenClick']) {
|
|
6521
6773
|
this._fire(events.pointerclick, {
|
|
6522
6774
|
evt: evt,
|
|
@@ -6535,7 +6787,7 @@
|
|
|
6535
6787
|
}
|
|
6536
6788
|
}
|
|
6537
6789
|
});
|
|
6538
|
-
if (!
|
|
6790
|
+
if (!skipPointerUpTrigger) {
|
|
6539
6791
|
this._fire(events.pointerup, {
|
|
6540
6792
|
evt: evt,
|
|
6541
6793
|
target: this,
|
|
@@ -7262,9 +7514,15 @@
|
|
|
7262
7514
|
bufferContext.clear();
|
|
7263
7515
|
bufferContext.save();
|
|
7264
7516
|
bufferContext._applyLineJoin(this);
|
|
7517
|
+
bufferContext._applyMiterLimit(this);
|
|
7265
7518
|
// layer might be undefined if we are using cache before adding to layer
|
|
7266
7519
|
const o = this.getAbsoluteTransform(top).getMatrix();
|
|
7267
7520
|
bufferContext.transform(o[0], o[1], o[2], o[3], o[4], o[5]);
|
|
7521
|
+
// Apply CSS filters to buffer context if not cached
|
|
7522
|
+
// we skip filters in non cache use cases for now
|
|
7523
|
+
// if (!cachingSelf && filters?.length > 0) {
|
|
7524
|
+
// bufferContext._applyCSSFilters(this);
|
|
7525
|
+
// }
|
|
7268
7526
|
drawFunc.call(this, bufferContext, this);
|
|
7269
7527
|
bufferContext.restore();
|
|
7270
7528
|
const ratio = bc.pixelRatio;
|
|
@@ -7277,11 +7535,16 @@
|
|
|
7277
7535
|
}
|
|
7278
7536
|
else {
|
|
7279
7537
|
context._applyLineJoin(this);
|
|
7538
|
+
context._applyMiterLimit(this);
|
|
7280
7539
|
if (!cachingSelf) {
|
|
7281
7540
|
const o = this.getAbsoluteTransform(top).getMatrix();
|
|
7282
7541
|
context.transform(o[0], o[1], o[2], o[3], o[4], o[5]);
|
|
7283
7542
|
context._applyOpacity(this);
|
|
7284
7543
|
context._applyGlobalCompositeOperation(this);
|
|
7544
|
+
// Apply CSS filters to main context if not cached
|
|
7545
|
+
// if (filters?.length) {
|
|
7546
|
+
// context._applyCSSFilters(this);
|
|
7547
|
+
// }
|
|
7285
7548
|
}
|
|
7286
7549
|
if (hasShadow) {
|
|
7287
7550
|
context._applyShadow(this);
|
|
@@ -7312,6 +7575,7 @@
|
|
|
7312
7575
|
}
|
|
7313
7576
|
context.save();
|
|
7314
7577
|
context._applyLineJoin(this);
|
|
7578
|
+
context._applyMiterLimit(this);
|
|
7315
7579
|
const selfCache = this === top;
|
|
7316
7580
|
if (!selfCache) {
|
|
7317
7581
|
const o = this.getAbsoluteTransform(top).getMatrix();
|
|
@@ -7536,6 +7800,20 @@
|
|
|
7536
7800
|
* // set line cap
|
|
7537
7801
|
* shape.lineCap('round');
|
|
7538
7802
|
*/
|
|
7803
|
+
Factory.addGetterSetter(Shape, 'miterLimit');
|
|
7804
|
+
/**
|
|
7805
|
+
* get/set miterLimit.
|
|
7806
|
+
* @name Konva.Shape#miterLimit
|
|
7807
|
+
* @method
|
|
7808
|
+
* @param {Number} miterLimit
|
|
7809
|
+
* @returns {Number}
|
|
7810
|
+
* @example
|
|
7811
|
+
* // get miter limit
|
|
7812
|
+
* var miterLimit = shape.miterLimit();
|
|
7813
|
+
*
|
|
7814
|
+
* // set miter limit
|
|
7815
|
+
* shape.miterLimit(10);
|
|
7816
|
+
*/
|
|
7539
7817
|
Factory.addGetterSetter(Shape, 'sceneFunc');
|
|
7540
7818
|
/**
|
|
7541
7819
|
* get/set scene draw function. That function is used to draw the shape on a canvas.
|
|
@@ -11695,19 +11973,87 @@
|
|
|
11695
11973
|
// while ((match = re.exec(str))) {
|
|
11696
11974
|
// coords.push(match[0]);
|
|
11697
11975
|
// }
|
|
11698
|
-
|
|
11976
|
+
let p = [];
|
|
11977
|
+
// Track param position for A/a commands: 0..6 => rx, ry, psi, fa, fs, x, y
|
|
11978
|
+
let arcParamIndex = c === 'A' || c === 'a' ? 0 : -1;
|
|
11699
11979
|
for (let j = 0, jlen = coords.length; j < jlen; j++) {
|
|
11980
|
+
const token = coords[j];
|
|
11700
11981
|
// extra case for merged flags
|
|
11701
|
-
if (
|
|
11982
|
+
if (token === '00') {
|
|
11702
11983
|
p.push(0, 0);
|
|
11984
|
+
if (arcParamIndex >= 0) {
|
|
11985
|
+
arcParamIndex += 2;
|
|
11986
|
+
if (arcParamIndex >= 7)
|
|
11987
|
+
arcParamIndex -= 7;
|
|
11988
|
+
}
|
|
11703
11989
|
continue;
|
|
11704
11990
|
}
|
|
11705
|
-
|
|
11706
|
-
|
|
11707
|
-
|
|
11991
|
+
if (arcParamIndex >= 0) {
|
|
11992
|
+
// index-aware minimal handling for merged flags
|
|
11993
|
+
if (arcParamIndex === 3) {
|
|
11994
|
+
// expecting large-arc-flag; token may contain fa+fs(+x)
|
|
11995
|
+
if (/^[01]{2}\d+(?:\.\d+)?$/.test(token)) {
|
|
11996
|
+
p.push(parseInt(token[0], 10));
|
|
11997
|
+
p.push(parseInt(token[1], 10));
|
|
11998
|
+
p.push(parseFloat(token.slice(2)));
|
|
11999
|
+
arcParamIndex += 3;
|
|
12000
|
+
if (arcParamIndex >= 7)
|
|
12001
|
+
arcParamIndex -= 7;
|
|
12002
|
+
continue;
|
|
12003
|
+
}
|
|
12004
|
+
if (token === '11' || token === '10' || token === '01') {
|
|
12005
|
+
p.push(parseInt(token[0], 10));
|
|
12006
|
+
p.push(parseInt(token[1], 10));
|
|
12007
|
+
arcParamIndex += 2;
|
|
12008
|
+
if (arcParamIndex >= 7)
|
|
12009
|
+
arcParamIndex -= 7;
|
|
12010
|
+
continue;
|
|
12011
|
+
}
|
|
12012
|
+
if (token === '0' || token === '1') {
|
|
12013
|
+
p.push(parseInt(token, 10));
|
|
12014
|
+
arcParamIndex += 1;
|
|
12015
|
+
if (arcParamIndex >= 7)
|
|
12016
|
+
arcParamIndex -= 7;
|
|
12017
|
+
continue;
|
|
12018
|
+
}
|
|
12019
|
+
}
|
|
12020
|
+
else if (arcParamIndex === 4) {
|
|
12021
|
+
// expecting sweep-flag; token may contain fs(+x)
|
|
12022
|
+
if (/^[01]\d+(?:\.\d+)?$/.test(token)) {
|
|
12023
|
+
p.push(parseInt(token[0], 10));
|
|
12024
|
+
p.push(parseFloat(token.slice(1)));
|
|
12025
|
+
arcParamIndex += 2;
|
|
12026
|
+
if (arcParamIndex >= 7)
|
|
12027
|
+
arcParamIndex -= 7;
|
|
12028
|
+
continue;
|
|
12029
|
+
}
|
|
12030
|
+
if (token === '0' || token === '1') {
|
|
12031
|
+
p.push(parseInt(token, 10));
|
|
12032
|
+
arcParamIndex += 1;
|
|
12033
|
+
if (arcParamIndex >= 7)
|
|
12034
|
+
arcParamIndex -= 7;
|
|
12035
|
+
continue;
|
|
12036
|
+
}
|
|
12037
|
+
}
|
|
12038
|
+
const parsedArc = parseFloat(token);
|
|
12039
|
+
if (!isNaN(parsedArc)) {
|
|
12040
|
+
p.push(parsedArc);
|
|
12041
|
+
}
|
|
12042
|
+
else {
|
|
12043
|
+
p.push(0);
|
|
12044
|
+
}
|
|
12045
|
+
arcParamIndex += 1;
|
|
12046
|
+
if (arcParamIndex >= 7)
|
|
12047
|
+
arcParamIndex -= 7;
|
|
11708
12048
|
}
|
|
11709
12049
|
else {
|
|
11710
|
-
|
|
12050
|
+
const parsed = parseFloat(token);
|
|
12051
|
+
if (!isNaN(parsed)) {
|
|
12052
|
+
p.push(parsed);
|
|
12053
|
+
}
|
|
12054
|
+
else {
|
|
12055
|
+
p.push(0);
|
|
12056
|
+
}
|
|
11711
12057
|
}
|
|
11712
12058
|
}
|
|
11713
12059
|
while (p.length > 0) {
|
|
@@ -13354,6 +13700,7 @@
|
|
|
13354
13700
|
* @memberof Konva
|
|
13355
13701
|
* @augments Konva.Shape
|
|
13356
13702
|
* @param {Object} config
|
|
13703
|
+
* @param {Number} [config.cornerRadius]
|
|
13357
13704
|
* @param {Number} config.sides
|
|
13358
13705
|
* @param {Number} config.radius
|
|
13359
13706
|
* @param {String} [config.fill] fill color
|
|
@@ -13443,11 +13790,16 @@
|
|
|
13443
13790
|
*/
|
|
13444
13791
|
class RegularPolygon extends Shape {
|
|
13445
13792
|
_sceneFunc(context) {
|
|
13446
|
-
const points = this._getPoints();
|
|
13793
|
+
const points = this._getPoints(), radius = this.radius(), sides = this.sides(), cornerRadius = this.cornerRadius();
|
|
13447
13794
|
context.beginPath();
|
|
13448
|
-
|
|
13449
|
-
|
|
13450
|
-
|
|
13795
|
+
if (!cornerRadius) {
|
|
13796
|
+
context.moveTo(points[0].x, points[0].y);
|
|
13797
|
+
for (let n = 1; n < points.length; n++) {
|
|
13798
|
+
context.lineTo(points[n].x, points[n].y);
|
|
13799
|
+
}
|
|
13800
|
+
}
|
|
13801
|
+
else {
|
|
13802
|
+
Util.drawRoundedPolygonPath(context, points, sides, radius, cornerRadius);
|
|
13451
13803
|
}
|
|
13452
13804
|
context.closePath();
|
|
13453
13805
|
context.fillStrokeShape(this);
|
|
@@ -13528,6 +13880,23 @@
|
|
|
13528
13880
|
* shape.sides(10);
|
|
13529
13881
|
*/
|
|
13530
13882
|
Factory.addGetterSetter(RegularPolygon, 'sides', 0, getNumberValidator());
|
|
13883
|
+
/**
|
|
13884
|
+
* get/set corner radius
|
|
13885
|
+
* @method
|
|
13886
|
+
* @name Konva.RegularPolygon#cornerRadius
|
|
13887
|
+
* @param {Number} cornerRadius
|
|
13888
|
+
* @returns {Number}
|
|
13889
|
+
* @example
|
|
13890
|
+
* // get corner radius
|
|
13891
|
+
* var cornerRadius = poly.cornerRadius();
|
|
13892
|
+
*
|
|
13893
|
+
* // set corner radius
|
|
13894
|
+
* poly.cornerRadius(10);
|
|
13895
|
+
*
|
|
13896
|
+
* // set different corner radius values (pentagon)
|
|
13897
|
+
* poly.cornerRadius([0, 10, 20, 30, 40]);
|
|
13898
|
+
*/
|
|
13899
|
+
Factory.addGetterSetter(RegularPolygon, 'cornerRadius', 0, getNumberOrArrayOfNumbersValidator(4));
|
|
13531
13900
|
|
|
13532
13901
|
const PIx2 = Math.PI * 2;
|
|
13533
13902
|
/**
|
|
@@ -14422,20 +14791,21 @@
|
|
|
14422
14791
|
this._setTextData();
|
|
14423
14792
|
}
|
|
14424
14793
|
_sceneFunc(context) {
|
|
14794
|
+
var _a, _b;
|
|
14425
14795
|
const textArr = this.textArr, textArrLen = textArr.length;
|
|
14426
14796
|
if (!this.text()) {
|
|
14427
14797
|
return;
|
|
14428
14798
|
}
|
|
14429
|
-
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;
|
|
14799
|
+
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;
|
|
14430
14800
|
direction = direction === INHERIT ? context.direction : direction;
|
|
14431
14801
|
let translateY = lineHeightPx / 2;
|
|
14432
14802
|
let baseline = MIDDLE;
|
|
14433
|
-
if (Konva$2.
|
|
14803
|
+
if (!Konva$2.legacyTextRendering) {
|
|
14434
14804
|
const metrics = this.measureSize('M'); // Use a sample character to get the ascent
|
|
14435
14805
|
baseline = 'alphabetic';
|
|
14436
|
-
|
|
14437
|
-
|
|
14438
|
-
|
|
14806
|
+
const ascent = (_a = metrics.fontBoundingBoxAscent) !== null && _a !== void 0 ? _a : metrics.actualBoundingBoxAscent;
|
|
14807
|
+
const descent = (_b = metrics.fontBoundingBoxDescent) !== null && _b !== void 0 ? _b : metrics.actualBoundingBoxDescent;
|
|
14808
|
+
translateY = (ascent - descent) / 2 + lineHeightPx / 2;
|
|
14439
14809
|
}
|
|
14440
14810
|
if (direction === RTL) {
|
|
14441
14811
|
context.setAttr('direction', direction);
|
|
@@ -14467,7 +14837,7 @@
|
|
|
14467
14837
|
if (shouldUnderline) {
|
|
14468
14838
|
context.save();
|
|
14469
14839
|
context.beginPath();
|
|
14470
|
-
const yOffset = Konva$2.
|
|
14840
|
+
const yOffset = !Konva$2.legacyTextRendering
|
|
14471
14841
|
? Math.round(fontSize / 4)
|
|
14472
14842
|
: Math.round(fontSize / 2);
|
|
14473
14843
|
const x = lineTranslateX;
|
|
@@ -14483,23 +14853,12 @@
|
|
|
14483
14853
|
context.stroke();
|
|
14484
14854
|
context.restore();
|
|
14485
14855
|
}
|
|
14486
|
-
|
|
14487
|
-
context.save();
|
|
14488
|
-
context.beginPath();
|
|
14489
|
-
const yOffset = Konva$2._fixTextRendering ? -Math.round(fontSize / 4) : 0;
|
|
14490
|
-
context.moveTo(lineTranslateX, translateY + lineTranslateY + yOffset);
|
|
14491
|
-
const lineWidth = align === JUSTIFY && !lastLine ? totalWidth - padding * 2 : width;
|
|
14492
|
-
context.lineTo(lineTranslateX + Math.round(lineWidth), translateY + lineTranslateY + yOffset);
|
|
14493
|
-
context.lineWidth = fontSize / 15;
|
|
14494
|
-
const gradient = this._getLinearGradient();
|
|
14495
|
-
context.strokeStyle = gradient || fill;
|
|
14496
|
-
context.stroke();
|
|
14497
|
-
context.restore();
|
|
14498
|
-
}
|
|
14856
|
+
// draw line-through above the text content
|
|
14499
14857
|
// As `letterSpacing` isn't supported on Safari, we use this polyfill.
|
|
14500
14858
|
// The exception is for RTL text, which we rely on native as it cannot
|
|
14501
14859
|
// be supported otherwise.
|
|
14502
|
-
if (direction !== RTL &&
|
|
14860
|
+
if (direction !== RTL &&
|
|
14861
|
+
(letterSpacing !== 0 || align === JUSTIFY || charRenderFunc)) {
|
|
14503
14862
|
// var words = text.split(' ');
|
|
14504
14863
|
const spacesNumber = text.split(' ').length - 1;
|
|
14505
14864
|
const array = stringToArray(text);
|
|
@@ -14516,7 +14875,27 @@
|
|
|
14516
14875
|
this._partialTextX = lineTranslateX;
|
|
14517
14876
|
this._partialTextY = translateY + lineTranslateY;
|
|
14518
14877
|
this._partialText = letter;
|
|
14878
|
+
if (charRenderFunc) {
|
|
14879
|
+
context.save();
|
|
14880
|
+
const previousLines = textArr.slice(0, n);
|
|
14881
|
+
const previousGraphemes = previousLines.reduce((acc, line) => acc + stringToArray(line.text).length, 0);
|
|
14882
|
+
const charIndex = li + previousGraphemes;
|
|
14883
|
+
charRenderFunc({
|
|
14884
|
+
char: letter,
|
|
14885
|
+
index: charIndex,
|
|
14886
|
+
x: lineTranslateX,
|
|
14887
|
+
y: translateY + lineTranslateY,
|
|
14888
|
+
lineIndex: n,
|
|
14889
|
+
column: li,
|
|
14890
|
+
isLastInLine: lastLine,
|
|
14891
|
+
width: this.measureSize(letter).width,
|
|
14892
|
+
context,
|
|
14893
|
+
});
|
|
14894
|
+
}
|
|
14519
14895
|
context.fillStrokeShape(this);
|
|
14896
|
+
if (charRenderFunc) {
|
|
14897
|
+
context.restore();
|
|
14898
|
+
}
|
|
14520
14899
|
lineTranslateX += this.measureSize(letter).width + letterSpacing;
|
|
14521
14900
|
}
|
|
14522
14901
|
}
|
|
@@ -14529,6 +14908,22 @@
|
|
|
14529
14908
|
this._partialText = text;
|
|
14530
14909
|
context.fillStrokeShape(this);
|
|
14531
14910
|
}
|
|
14911
|
+
// draw line-through above the text content
|
|
14912
|
+
if (shouldLineThrough) {
|
|
14913
|
+
context.save();
|
|
14914
|
+
context.beginPath();
|
|
14915
|
+
const yOffset = !Konva$2.legacyTextRendering
|
|
14916
|
+
? -Math.round(fontSize / 4)
|
|
14917
|
+
: 0;
|
|
14918
|
+
context.moveTo(0, translateY + lineTranslateY + yOffset);
|
|
14919
|
+
const lineWidth = align === JUSTIFY && !lastLine ? totalWidth - padding * 2 : width;
|
|
14920
|
+
context.lineTo(Math.round(lineWidth), translateY + lineTranslateY + yOffset);
|
|
14921
|
+
context.lineWidth = fontSize / 15;
|
|
14922
|
+
const gradient = this._getLinearGradient();
|
|
14923
|
+
context.strokeStyle = gradient || fill;
|
|
14924
|
+
context.stroke();
|
|
14925
|
+
context.restore();
|
|
14926
|
+
}
|
|
14532
14927
|
context.restore();
|
|
14533
14928
|
if (textArrLen > 1) {
|
|
14534
14929
|
translateY += lineHeightPx;
|
|
@@ -15063,6 +15458,23 @@
|
|
|
15063
15458
|
* text.textDecoration('underline line-through');
|
|
15064
15459
|
*/
|
|
15065
15460
|
Factory.addGetterSetter(Text, 'textDecoration', '');
|
|
15461
|
+
/**
|
|
15462
|
+
* get/set per-character render hook. The callback is invoked for each grapheme before drawing.
|
|
15463
|
+
* It can mutate the provided context (e.g. translate, rotate, change styles) and should return void.
|
|
15464
|
+
* Note: per-character rendering may disable native kerning/ligatures.
|
|
15465
|
+
* @name Konva.Text#charRenderFunc
|
|
15466
|
+
* @method
|
|
15467
|
+
* @param {Function} charRenderFunc
|
|
15468
|
+
* @returns {Function}
|
|
15469
|
+
* @example
|
|
15470
|
+
* // apply small x-translation to every second character
|
|
15471
|
+
* text.charRenderFunc(function(props) {
|
|
15472
|
+
* if (props.index % 2 === 1) {
|
|
15473
|
+
* props.context.translate(2, 0);
|
|
15474
|
+
* }
|
|
15475
|
+
* });
|
|
15476
|
+
*/
|
|
15477
|
+
Factory.addGetterSetter(Text, 'charRenderFunc', undefined);
|
|
15066
15478
|
|
|
15067
15479
|
const EMPTY_STRING = '', NORMAL = 'normal';
|
|
15068
15480
|
function _fillFunc(context) {
|
|
@@ -15309,7 +15721,17 @@
|
|
|
15309
15721
|
};
|
|
15310
15722
|
}
|
|
15311
15723
|
_setTextData() {
|
|
15312
|
-
const
|
|
15724
|
+
const charArr = stringToArray(this.text());
|
|
15725
|
+
const chars = [];
|
|
15726
|
+
let width = 0;
|
|
15727
|
+
for (let i = 0; i < charArr.length; i++) {
|
|
15728
|
+
chars.push({
|
|
15729
|
+
char: charArr[i],
|
|
15730
|
+
width: this._getTextSize(charArr[i]).width,
|
|
15731
|
+
});
|
|
15732
|
+
width += chars[i].width;
|
|
15733
|
+
}
|
|
15734
|
+
const { height } = this._getTextSize(this.attrs.text);
|
|
15313
15735
|
this.textWidth = width;
|
|
15314
15736
|
this.textHeight = height;
|
|
15315
15737
|
this.glyphInfo = [];
|
|
@@ -15328,31 +15750,32 @@
|
|
|
15328
15750
|
if (align === 'right') {
|
|
15329
15751
|
offset = Math.max(0, this.pathLength - textWidth);
|
|
15330
15752
|
}
|
|
15331
|
-
const charArr = stringToArray(this.text());
|
|
15332
15753
|
// Algorithm for calculating glyph positions:
|
|
15333
15754
|
// 1. Get the begging point of the glyph on the path using the offsetToGlyph,
|
|
15334
15755
|
// 2. Get the ending point of the glyph on the path using the offsetToGlyph plus glyph width,
|
|
15335
15756
|
// 3. Calculate the rotation, width, and midpoint of the glyph using the start and end points,
|
|
15336
15757
|
// 4. Add glyph width to the offsetToGlyph and repeat
|
|
15337
15758
|
let offsetToGlyph = offset;
|
|
15338
|
-
for (let i = 0; i <
|
|
15759
|
+
for (let i = 0; i < chars.length; i++) {
|
|
15339
15760
|
const charStartPoint = this._getPointAtLength(offsetToGlyph);
|
|
15340
15761
|
if (!charStartPoint)
|
|
15341
15762
|
return;
|
|
15342
|
-
|
|
15343
|
-
|
|
15763
|
+
const char = chars[i].char;
|
|
15764
|
+
let glyphWidth = chars[i].width + letterSpacing;
|
|
15765
|
+
if (char === ' ' && align === 'justify') {
|
|
15344
15766
|
const numberOfSpaces = this.text().split(' ').length - 1;
|
|
15345
15767
|
glyphWidth += (this.pathLength - textWidth) / numberOfSpaces;
|
|
15346
15768
|
}
|
|
15347
15769
|
const charEndPoint = this._getPointAtLength(offsetToGlyph + glyphWidth);
|
|
15348
|
-
if (!charEndPoint)
|
|
15770
|
+
if (!charEndPoint) {
|
|
15349
15771
|
return;
|
|
15772
|
+
}
|
|
15350
15773
|
const width = Path.getLineLength(charStartPoint.x, charStartPoint.y, charEndPoint.x, charEndPoint.y);
|
|
15351
15774
|
let kern = 0;
|
|
15352
15775
|
if (kerningFunc) {
|
|
15353
15776
|
try {
|
|
15354
15777
|
// getKerning is a user provided getter. Make sure it never breaks our logic
|
|
15355
|
-
kern = kerningFunc(
|
|
15778
|
+
kern = kerningFunc(chars[i - 1].char, char) * this.fontSize();
|
|
15356
15779
|
}
|
|
15357
15780
|
catch (e) {
|
|
15358
15781
|
kern = 0;
|
|
@@ -15619,6 +16042,7 @@
|
|
|
15619
16042
|
'offsetYChange',
|
|
15620
16043
|
'transformsEnabledChange',
|
|
15621
16044
|
'strokeWidthChange',
|
|
16045
|
+
'draggableChange',
|
|
15622
16046
|
];
|
|
15623
16047
|
const ANGLES = {
|
|
15624
16048
|
'top-left': -45,
|
|
@@ -16092,7 +16516,6 @@
|
|
|
16092
16516
|
name: 'back',
|
|
16093
16517
|
width: 0,
|
|
16094
16518
|
height: 0,
|
|
16095
|
-
draggable: true,
|
|
16096
16519
|
sceneFunc(ctx, shape) {
|
|
16097
16520
|
const tr = shape.getParent();
|
|
16098
16521
|
const padding = tr.padding();
|
|
@@ -16490,6 +16913,16 @@
|
|
|
16490
16913
|
const delta = newTr.multiply(oldTr.invert());
|
|
16491
16914
|
this._nodes.forEach((node) => {
|
|
16492
16915
|
var _a;
|
|
16916
|
+
// check to close this issue: https://github.com/konvajs/konva/issues/1957
|
|
16917
|
+
// a node can be destroyed during the transformation
|
|
16918
|
+
// probably a developer must remove it from transformer
|
|
16919
|
+
if (!node.getStage()) {
|
|
16920
|
+
// do we need a helping message?
|
|
16921
|
+
// Util.error(
|
|
16922
|
+
// '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.'
|
|
16923
|
+
// );
|
|
16924
|
+
return;
|
|
16925
|
+
}
|
|
16493
16926
|
// for each node we have the same [delta transform]
|
|
16494
16927
|
// the equations is
|
|
16495
16928
|
// [delta transform] * [parent transform] * [old local transform] = [parent transform] * [new local transform]
|
|
@@ -16620,6 +17053,7 @@
|
|
|
16620
17053
|
stroke: this.borderStroke(),
|
|
16621
17054
|
strokeWidth: this.borderStrokeWidth(),
|
|
16622
17055
|
dash: this.borderDash(),
|
|
17056
|
+
draggable: this.nodes().some((node) => node.draggable()),
|
|
16623
17057
|
x: 0,
|
|
16624
17058
|
y: 0,
|
|
16625
17059
|
});
|
|
@@ -17363,6 +17797,7 @@
|
|
|
17363
17797
|
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
17364
17798
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
17365
17799
|
OTHER DEALINGS IN THE SOFTWARE.
|
|
17800
|
+
* @license MIT
|
|
17366
17801
|
*/
|
|
17367
17802
|
function BlurStack() {
|
|
17368
17803
|
this.r = 0;
|
|
@@ -17617,6 +18052,8 @@
|
|
|
17617
18052
|
|
|
17618
18053
|
/**
|
|
17619
18054
|
* Brighten Filter.
|
|
18055
|
+
* @deprecated Use {@link Konva.Filters.Brightness} instead for CSS-compatible behavior.
|
|
18056
|
+
* This filter uses additive brightness adjustment (adds a constant value to RGB channels).
|
|
17620
18057
|
* @function
|
|
17621
18058
|
* @memberof Konva.Filters
|
|
17622
18059
|
* @param {Object} imageData
|
|
@@ -17647,6 +18084,31 @@
|
|
|
17647
18084
|
* @returns {Number}
|
|
17648
18085
|
*/
|
|
17649
18086
|
|
|
18087
|
+
/**
|
|
18088
|
+
* Brightness Filter.
|
|
18089
|
+
* CSS-compatible brightness filter that uses multiplicative approach.
|
|
18090
|
+
* @function
|
|
18091
|
+
* @memberof Konva.Filters
|
|
18092
|
+
* @param {Object} imageData
|
|
18093
|
+
* @example
|
|
18094
|
+
* node.cache();
|
|
18095
|
+
* node.filters([Konva.Filters.Brightness]);
|
|
18096
|
+
* node.brightness(1.5); // 50% brighter (CSS-compatible)
|
|
18097
|
+
*/
|
|
18098
|
+
const Brightness = function (imageData) {
|
|
18099
|
+
const brightness = this.brightness(), data = imageData.data, len = data.length;
|
|
18100
|
+
for (let i = 0; i < len; i += 4) {
|
|
18101
|
+
// red
|
|
18102
|
+
data[i] = Math.min(255, data[i] * brightness);
|
|
18103
|
+
// green
|
|
18104
|
+
data[i + 1] = Math.min(255, data[i + 1] * brightness);
|
|
18105
|
+
// blue
|
|
18106
|
+
data[i + 2] = Math.min(255, data[i + 2] * brightness);
|
|
18107
|
+
}
|
|
18108
|
+
};
|
|
18109
|
+
// Note: brightness property is already defined in Brighten.ts
|
|
18110
|
+
// This filter reuses the existing brightness property but with CSS-compatible behavior
|
|
18111
|
+
|
|
17650
18112
|
/**
|
|
17651
18113
|
* Contrast Filter.
|
|
17652
18114
|
* @function
|
|
@@ -17703,9 +18165,6 @@
|
|
|
17703
18165
|
|
|
17704
18166
|
/**
|
|
17705
18167
|
* Emboss Filter.
|
|
17706
|
-
* Pixastic Lib - Emboss filter - v0.1.0
|
|
17707
|
-
* Copyright (c) 2008 Jacob Seidelin, jseidelin@nihilogic.dk, http://blog.nihilogic.dk/
|
|
17708
|
-
* License: [http://www.pixastic.com/lib/license.txt]
|
|
17709
18168
|
* @function
|
|
17710
18169
|
* @memberof Konva.Filters
|
|
17711
18170
|
* @param {Object} imageData
|
|
@@ -17718,103 +18177,116 @@
|
|
|
17718
18177
|
* node.embossBlend(true);
|
|
17719
18178
|
*/
|
|
17720
18179
|
const Emboss = function (imageData) {
|
|
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
|
-
|
|
17764
|
-
|
|
17765
|
-
let
|
|
17766
|
-
|
|
17767
|
-
|
|
17768
|
-
|
|
17769
|
-
|
|
17770
|
-
|
|
17771
|
-
|
|
17772
|
-
|
|
17773
|
-
|
|
17774
|
-
|
|
17775
|
-
|
|
17776
|
-
|
|
17777
|
-
|
|
17778
|
-
|
|
17779
|
-
|
|
17780
|
-
|
|
17781
|
-
|
|
17782
|
-
|
|
17783
|
-
|
|
17784
|
-
|
|
17785
|
-
|
|
17786
|
-
|
|
17787
|
-
|
|
17788
|
-
const
|
|
17789
|
-
const
|
|
17790
|
-
const absB = dB > 0 ? dB : -dB;
|
|
17791
|
-
if (absG > absDif) {
|
|
17792
|
-
dif = dG;
|
|
17793
|
-
}
|
|
17794
|
-
if (absB > absDif) {
|
|
17795
|
-
dif = dB;
|
|
17796
|
-
}
|
|
17797
|
-
dif *= strength;
|
|
18180
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
18181
|
+
const data = imageData.data;
|
|
18182
|
+
const w = imageData.width;
|
|
18183
|
+
const h = imageData.height;
|
|
18184
|
+
// Inputs from Konva node
|
|
18185
|
+
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]
|
|
18186
|
+
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]
|
|
18187
|
+
// Convert string direction to degrees
|
|
18188
|
+
const directionMap = {
|
|
18189
|
+
'top-left': 315,
|
|
18190
|
+
top: 270,
|
|
18191
|
+
'top-right': 225,
|
|
18192
|
+
right: 180,
|
|
18193
|
+
'bottom-right': 135,
|
|
18194
|
+
bottom: 90,
|
|
18195
|
+
'bottom-left': 45,
|
|
18196
|
+
left: 0,
|
|
18197
|
+
};
|
|
18198
|
+
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
|
|
18199
|
+
const blend = !!((_j = (_h = this.embossBlend) === null || _h === void 0 ? void 0 : _h.call(this)) !== null && _j !== void 0 ? _j : false);
|
|
18200
|
+
// Internal mapping:
|
|
18201
|
+
// - "strength" was 0..10; we honor your 0..1 API and scale accordingly.
|
|
18202
|
+
// - Sobel directional response is roughly in [-1020..1020] for 8-bit luminance; scale to ~±128.
|
|
18203
|
+
const strength = strength01 * 10;
|
|
18204
|
+
const bias = whiteLevel01 * 255;
|
|
18205
|
+
const dirRad = (directionDeg * Math.PI) / 180;
|
|
18206
|
+
const cx = Math.cos(dirRad);
|
|
18207
|
+
const cy = Math.sin(dirRad);
|
|
18208
|
+
const SCALE = (128 / 1020) * strength; // ≈0.1255 * strength
|
|
18209
|
+
// Precompute luminance (Rec.709)
|
|
18210
|
+
const src = new Uint8ClampedArray(data); // snapshot
|
|
18211
|
+
const lum = new Float32Array(w * h);
|
|
18212
|
+
for (let p = 0, i = 0; i < data.length; i += 4, p++) {
|
|
18213
|
+
lum[p] = 0.2126 * src[i] + 0.7152 * src[i + 1] + 0.0722 * src[i + 2];
|
|
18214
|
+
}
|
|
18215
|
+
// Sobel kernels (flattened)
|
|
18216
|
+
const Gx = [-1, 0, 1, -2, 0, 2, -1, 0, 1];
|
|
18217
|
+
const Gy = [-1, -2, -1, 0, 0, 0, 1, 2, 1];
|
|
18218
|
+
// neighbor offsets around center pixel in lum space
|
|
18219
|
+
const OFF = [-w - 1, -w, -w + 1, -1, 0, 1, w - 1, w, w + 1];
|
|
18220
|
+
// Helpers
|
|
18221
|
+
const clamp8 = (v) => (v < 0 ? 0 : v > 255 ? 255 : v);
|
|
18222
|
+
// Process: leave a 1px border unchanged (faster/cleaner)
|
|
18223
|
+
for (let y = 1; y < h - 1; y++) {
|
|
18224
|
+
for (let x = 1; x < w - 1; x++) {
|
|
18225
|
+
const p = y * w + x;
|
|
18226
|
+
// Directional derivative = (cosθ * Gx + sinθ * Gy) • neighborhood(lum)
|
|
18227
|
+
let sx = 0, sy = 0;
|
|
18228
|
+
// unroll loop for speed
|
|
18229
|
+
sx += lum[p + OFF[0]] * Gx[0];
|
|
18230
|
+
sy += lum[p + OFF[0]] * Gy[0];
|
|
18231
|
+
sx += lum[p + OFF[1]] * Gx[1];
|
|
18232
|
+
sy += lum[p + OFF[1]] * Gy[1];
|
|
18233
|
+
sx += lum[p + OFF[2]] * Gx[2];
|
|
18234
|
+
sy += lum[p + OFF[2]] * Gy[2];
|
|
18235
|
+
sx += lum[p + OFF[3]] * Gx[3];
|
|
18236
|
+
sy += lum[p + OFF[3]] * Gy[3];
|
|
18237
|
+
// center has 0 weights in both Sobel masks; can skip if desired
|
|
18238
|
+
sx += lum[p + OFF[5]] * Gx[5];
|
|
18239
|
+
sy += lum[p + OFF[5]] * Gy[5];
|
|
18240
|
+
sx += lum[p + OFF[6]] * Gx[6];
|
|
18241
|
+
sy += lum[p + OFF[6]] * Gy[6];
|
|
18242
|
+
sx += lum[p + OFF[7]] * Gx[7];
|
|
18243
|
+
sy += lum[p + OFF[7]] * Gy[7];
|
|
18244
|
+
sx += lum[p + OFF[8]] * Gx[8];
|
|
18245
|
+
sy += lum[p + OFF[8]] * Gy[8];
|
|
18246
|
+
const r = cx * sx + cy * sy; // directional response
|
|
18247
|
+
const outGray = clamp8(bias + r * SCALE); // biased, scaled, clamped
|
|
18248
|
+
const o = p * 4;
|
|
17798
18249
|
if (blend) {
|
|
17799
|
-
|
|
17800
|
-
const
|
|
17801
|
-
|
|
17802
|
-
data[
|
|
17803
|
-
data[
|
|
17804
|
-
data[
|
|
18250
|
+
// Add the emboss "relief" around chosen bias to original RGB
|
|
18251
|
+
const delta = outGray - bias; // symmetric around whiteLevel
|
|
18252
|
+
data[o] = clamp8(src[o] + delta);
|
|
18253
|
+
data[o + 1] = clamp8(src[o + 1] + delta);
|
|
18254
|
+
data[o + 2] = clamp8(src[o + 2] + delta);
|
|
18255
|
+
data[o + 3] = src[o + 3];
|
|
17805
18256
|
}
|
|
17806
18257
|
else {
|
|
17807
|
-
|
|
17808
|
-
|
|
17809
|
-
|
|
17810
|
-
|
|
17811
|
-
|
|
17812
|
-
|
|
17813
|
-
|
|
17814
|
-
|
|
17815
|
-
|
|
17816
|
-
|
|
17817
|
-
|
|
18258
|
+
// Grayscale embossed output
|
|
18259
|
+
data[o] = data[o + 1] = data[o + 2] = outGray;
|
|
18260
|
+
data[o + 3] = src[o + 3];
|
|
18261
|
+
}
|
|
18262
|
+
}
|
|
18263
|
+
}
|
|
18264
|
+
// Copy border (untouched) to keep edges clean
|
|
18265
|
+
// top & bottom rows
|
|
18266
|
+
for (let x = 0; x < w; x++) {
|
|
18267
|
+
let oTop = x * 4, oBot = ((h - 1) * w + x) * 4;
|
|
18268
|
+
data[oTop] = src[oTop];
|
|
18269
|
+
data[oTop + 1] = src[oTop + 1];
|
|
18270
|
+
data[oTop + 2] = src[oTop + 2];
|
|
18271
|
+
data[oTop + 3] = src[oTop + 3];
|
|
18272
|
+
data[oBot] = src[oBot];
|
|
18273
|
+
data[oBot + 1] = src[oBot + 1];
|
|
18274
|
+
data[oBot + 2] = src[oBot + 2];
|
|
18275
|
+
data[oBot + 3] = src[oBot + 3];
|
|
18276
|
+
}
|
|
18277
|
+
// left & right columns
|
|
18278
|
+
for (let y = 1; y < h - 1; y++) {
|
|
18279
|
+
let oL = y * w * 4, oR = (y * w + (w - 1)) * 4;
|
|
18280
|
+
data[oL] = src[oL];
|
|
18281
|
+
data[oL + 1] = src[oL + 1];
|
|
18282
|
+
data[oL + 2] = src[oL + 2];
|
|
18283
|
+
data[oL + 3] = src[oL + 3];
|
|
18284
|
+
data[oR] = src[oR];
|
|
18285
|
+
data[oR + 1] = src[oR + 1];
|
|
18286
|
+
data[oR + 2] = src[oR + 2];
|
|
18287
|
+
data[oR + 3] = src[oR + 3];
|
|
18288
|
+
}
|
|
18289
|
+
return imageData;
|
|
17818
18290
|
};
|
|
17819
18291
|
Factory.addGetterSetter(Node, 'embossStrength', 0.5, getNumberValidator(), Factory.afterSetFilter);
|
|
17820
18292
|
/**
|
|
@@ -18456,7 +18928,17 @@
|
|
|
18456
18928
|
return maskResult;
|
|
18457
18929
|
}
|
|
18458
18930
|
function smoothEdgeMask(mask, sw, sh) {
|
|
18459
|
-
const weights = [
|
|
18931
|
+
const weights = [
|
|
18932
|
+
1 / 9,
|
|
18933
|
+
1 / 9,
|
|
18934
|
+
1 / 9,
|
|
18935
|
+
1 / 9,
|
|
18936
|
+
1 / 9,
|
|
18937
|
+
1 / 9,
|
|
18938
|
+
1 / 9,
|
|
18939
|
+
1 / 9,
|
|
18940
|
+
1 / 9,
|
|
18941
|
+
];
|
|
18460
18942
|
const side = Math.round(Math.sqrt(weights.length));
|
|
18461
18943
|
const halfSide = Math.floor(side / 2);
|
|
18462
18944
|
const maskResult = [];
|
|
@@ -18842,9 +19324,6 @@
|
|
|
18842
19324
|
|
|
18843
19325
|
/**
|
|
18844
19326
|
* Solarize Filter
|
|
18845
|
-
* Pixastic Lib - Solarize filter - v0.1.0
|
|
18846
|
-
* Copyright (c) 2008 Jacob Seidelin, jseidelin@nihilogic.dk, http://blog.nihilogic.dk/
|
|
18847
|
-
* License: [http://www.pixastic.com/lib/license.txt]
|
|
18848
19327
|
* @function
|
|
18849
19328
|
* @name Solarize
|
|
18850
19329
|
* @memberof Konva.Filters
|
|
@@ -18854,30 +19333,19 @@
|
|
|
18854
19333
|
* node.filters([Konva.Filters.Solarize]);
|
|
18855
19334
|
*/
|
|
18856
19335
|
const Solarize = function (imageData) {
|
|
18857
|
-
const
|
|
18858
|
-
|
|
18859
|
-
|
|
18860
|
-
const
|
|
18861
|
-
|
|
18862
|
-
|
|
18863
|
-
|
|
18864
|
-
|
|
18865
|
-
|
|
18866
|
-
|
|
18867
|
-
|
|
18868
|
-
|
|
18869
|
-
|
|
18870
|
-
if (g > 127) {
|
|
18871
|
-
g = 255 - g;
|
|
18872
|
-
}
|
|
18873
|
-
if (b > 127) {
|
|
18874
|
-
b = 255 - b;
|
|
18875
|
-
}
|
|
18876
|
-
data[offset] = r;
|
|
18877
|
-
data[offset + 1] = g;
|
|
18878
|
-
data[offset + 2] = b;
|
|
18879
|
-
} while (--x);
|
|
18880
|
-
} while (--y);
|
|
19336
|
+
const threshold = 128;
|
|
19337
|
+
const d = imageData.data;
|
|
19338
|
+
for (let i = 0; i < d.length; i += 4) {
|
|
19339
|
+
const r = d[i], g = d[i + 1], b = d[i + 2];
|
|
19340
|
+
// sRGB luma
|
|
19341
|
+
const L = 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
19342
|
+
if (L >= threshold) {
|
|
19343
|
+
d[i] = 255 - r;
|
|
19344
|
+
d[i + 1] = 255 - g;
|
|
19345
|
+
d[i + 2] = 255 - b;
|
|
19346
|
+
}
|
|
19347
|
+
}
|
|
19348
|
+
return imageData;
|
|
18881
19349
|
};
|
|
18882
19350
|
|
|
18883
19351
|
/**
|
|
@@ -18936,6 +19404,7 @@
|
|
|
18936
19404
|
*/
|
|
18937
19405
|
Filters: {
|
|
18938
19406
|
Blur,
|
|
19407
|
+
Brightness,
|
|
18939
19408
|
Brighten,
|
|
18940
19409
|
Contrast,
|
|
18941
19410
|
Emboss,
|