konva 9.3.16 → 9.3.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/konva.js +152 -134
- package/konva.min.js +3 -3
- package/lib/Context.js +3 -3
- package/lib/Factory.d.ts +18 -8
- package/lib/Factory.js +12 -11
- package/lib/Global.js +1 -1
- package/lib/Node.d.ts +1 -1
- package/lib/Node.js +2 -2
- package/lib/Shape.d.ts +5 -0
- package/lib/Shape.js +7 -7
- package/lib/Stage.js +7 -6
- package/lib/Tween.js +15 -11
- package/lib/Util.js +6 -5
- package/lib/Validators.d.ts +9 -9
- package/lib/Validators.js +6 -6
- package/lib/filters/Blur.js +2 -1
- package/lib/filters/Brighten.js +2 -2
- package/lib/filters/Contrast.js +3 -2
- package/lib/filters/Emboss.js +4 -3
- package/lib/filters/Enhance.js +6 -5
- package/lib/filters/Grayscale.js +3 -3
- package/lib/filters/HSL.js +2 -2
- package/lib/filters/Invert.js +2 -2
- package/lib/filters/Kaleidoscope.js +31 -31
- package/lib/filters/Mask.js +2 -1
- package/lib/filters/Posterize.js +2 -2
- package/lib/filters/RGB.js +3 -4
- package/lib/filters/Sepia.js +5 -5
- package/lib/shapes/Arrow.js +2 -2
- package/lib/shapes/Label.d.ts +3 -1
- package/lib/shapes/Text.js +12 -8
- package/lib/shapes/TextPath.js +2 -2
- package/lib/shapes/Transformer.js +1 -1
- package/package.json +14 -13
|
@@ -6,25 +6,25 @@ const Node_1 = require("../Node");
|
|
|
6
6
|
const Util_1 = require("../Util");
|
|
7
7
|
const Validators_1 = require("../Validators");
|
|
8
8
|
const ToPolar = function (src, dst, opt) {
|
|
9
|
-
|
|
10
|
-
let
|
|
11
|
-
x = xSize - xMid;
|
|
12
|
-
y = ySize - yMid;
|
|
13
|
-
rad = Math.sqrt(x * x + y * y);
|
|
9
|
+
const srcPixels = src.data, dstPixels = dst.data, xSize = src.width, ySize = src.height, xMid = opt.polarCenterX || xSize / 2, yMid = opt.polarCenterY || ySize / 2;
|
|
10
|
+
let rMax = Math.sqrt(xMid * xMid + yMid * yMid);
|
|
11
|
+
let x = xSize - xMid;
|
|
12
|
+
let y = ySize - yMid;
|
|
13
|
+
const rad = Math.sqrt(x * x + y * y);
|
|
14
14
|
rMax = rad > rMax ? rad : rMax;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
for (theta = 0; theta < tSize; theta += 1) {
|
|
18
|
-
sin = Math.sin(theta * conversion);
|
|
19
|
-
cos = Math.cos(theta * conversion);
|
|
20
|
-
for (radius = 0; radius < rSize; radius += 1) {
|
|
15
|
+
const rSize = ySize, tSize = xSize;
|
|
16
|
+
const conversion = ((360 / tSize) * Math.PI) / 180;
|
|
17
|
+
for (let theta = 0; theta < tSize; theta += 1) {
|
|
18
|
+
const sin = Math.sin(theta * conversion);
|
|
19
|
+
const cos = Math.cos(theta * conversion);
|
|
20
|
+
for (let radius = 0; radius < rSize; radius += 1) {
|
|
21
21
|
x = Math.floor(xMid + ((rMax * radius) / rSize) * cos);
|
|
22
22
|
y = Math.floor(yMid + ((rMax * radius) / rSize) * sin);
|
|
23
|
-
i = (y * xSize + x) * 4;
|
|
24
|
-
r = srcPixels[i + 0];
|
|
25
|
-
g = srcPixels[i + 1];
|
|
26
|
-
b = srcPixels[i + 2];
|
|
27
|
-
a = srcPixels[i + 3];
|
|
23
|
+
let i = (y * xSize + x) * 4;
|
|
24
|
+
const r = srcPixels[i + 0];
|
|
25
|
+
const g = srcPixels[i + 1];
|
|
26
|
+
const b = srcPixels[i + 2];
|
|
27
|
+
const a = srcPixels[i + 3];
|
|
28
28
|
i = (theta + radius * xSize) * 4;
|
|
29
29
|
dstPixels[i + 0] = r;
|
|
30
30
|
dstPixels[i + 1] = g;
|
|
@@ -34,28 +34,28 @@ const ToPolar = function (src, dst, opt) {
|
|
|
34
34
|
}
|
|
35
35
|
};
|
|
36
36
|
const FromPolar = function (src, dst, opt) {
|
|
37
|
-
|
|
38
|
-
let
|
|
39
|
-
x = xSize - xMid;
|
|
40
|
-
y = ySize - yMid;
|
|
41
|
-
rad = Math.sqrt(x * x + y * y);
|
|
37
|
+
const srcPixels = src.data, dstPixels = dst.data, xSize = src.width, ySize = src.height, xMid = opt.polarCenterX || xSize / 2, yMid = opt.polarCenterY || ySize / 2;
|
|
38
|
+
let rMax = Math.sqrt(xMid * xMid + yMid * yMid);
|
|
39
|
+
let x = xSize - xMid;
|
|
40
|
+
let y = ySize - yMid;
|
|
41
|
+
const rad = Math.sqrt(x * x + y * y);
|
|
42
42
|
rMax = rad > rMax ? rad : rMax;
|
|
43
|
-
|
|
43
|
+
const rSize = ySize, tSize = xSize, phaseShift = opt.polarRotation || 0;
|
|
44
44
|
let x1, y1;
|
|
45
45
|
for (x = 0; x < xSize; x += 1) {
|
|
46
46
|
for (y = 0; y < ySize; y += 1) {
|
|
47
|
-
dx = x - xMid;
|
|
48
|
-
dy = y - yMid;
|
|
49
|
-
radius = (Math.sqrt(dx * dx + dy * dy) * rSize) / rMax;
|
|
50
|
-
theta = ((Math.atan2(dy, dx) * 180) / Math.PI + 360 + phaseShift) % 360;
|
|
47
|
+
const dx = x - xMid;
|
|
48
|
+
const dy = y - yMid;
|
|
49
|
+
const radius = (Math.sqrt(dx * dx + dy * dy) * rSize) / rMax;
|
|
50
|
+
let theta = ((Math.atan2(dy, dx) * 180) / Math.PI + 360 + phaseShift) % 360;
|
|
51
51
|
theta = (theta * tSize) / 360;
|
|
52
52
|
x1 = Math.floor(theta);
|
|
53
53
|
y1 = Math.floor(radius);
|
|
54
|
-
i = (y1 * xSize + x1) * 4;
|
|
55
|
-
r = srcPixels[i + 0];
|
|
56
|
-
g = srcPixels[i + 1];
|
|
57
|
-
b = srcPixels[i + 2];
|
|
58
|
-
a = srcPixels[i + 3];
|
|
54
|
+
let i = (y1 * xSize + x1) * 4;
|
|
55
|
+
const r = srcPixels[i + 0];
|
|
56
|
+
const g = srcPixels[i + 1];
|
|
57
|
+
const b = srcPixels[i + 2];
|
|
58
|
+
const a = srcPixels[i + 3];
|
|
59
59
|
i = (y * xSize + x) * 4;
|
|
60
60
|
dstPixels[i + 0] = r;
|
|
61
61
|
dstPixels[i + 1] = g;
|
package/lib/filters/Mask.js
CHANGED
|
@@ -131,7 +131,8 @@ function smoothEdgeMask(mask, sw, sh) {
|
|
|
131
131
|
return maskResult;
|
|
132
132
|
}
|
|
133
133
|
const Mask = function (imageData) {
|
|
134
|
-
|
|
134
|
+
const threshold = this.threshold();
|
|
135
|
+
let mask = backgroundMask(imageData, threshold);
|
|
135
136
|
if (mask) {
|
|
136
137
|
mask = erodeMask(mask, imageData.width, imageData.height);
|
|
137
138
|
mask = dilateMask(mask, imageData.width, imageData.height);
|
package/lib/filters/Posterize.js
CHANGED
|
@@ -5,8 +5,8 @@ const Factory_1 = require("../Factory");
|
|
|
5
5
|
const Node_1 = require("../Node");
|
|
6
6
|
const Validators_1 = require("../Validators");
|
|
7
7
|
const Posterize = function (imageData) {
|
|
8
|
-
|
|
9
|
-
for (i = 0; i < len; i += 1) {
|
|
8
|
+
const levels = Math.round(this.levels() * 254) + 1, data = imageData.data, len = data.length, scale = 255 / levels;
|
|
9
|
+
for (let i = 0; i < len; i += 1) {
|
|
10
10
|
data[i] = Math.floor(data[i] / scale) * scale;
|
|
11
11
|
}
|
|
12
12
|
};
|
package/lib/filters/RGB.js
CHANGED
|
@@ -5,10 +5,9 @@ const Factory_1 = require("../Factory");
|
|
|
5
5
|
const Node_1 = require("../Node");
|
|
6
6
|
const Validators_1 = require("../Validators");
|
|
7
7
|
const RGB = function (imageData) {
|
|
8
|
-
|
|
9
|
-
for (i = 0; i < nPixels; i += 4) {
|
|
10
|
-
brightness =
|
|
11
|
-
(0.34 * data[i] + 0.5 * data[i + 1] + 0.16 * data[i + 2]) / 255;
|
|
8
|
+
const data = imageData.data, nPixels = data.length, red = this.red(), green = this.green(), blue = this.blue();
|
|
9
|
+
for (let i = 0; i < nPixels; i += 4) {
|
|
10
|
+
const brightness = (0.34 * data[i] + 0.5 * data[i + 1] + 0.16 * data[i + 2]) / 255;
|
|
12
11
|
data[i] = brightness * red;
|
|
13
12
|
data[i + 1] = brightness * green;
|
|
14
13
|
data[i + 2] = brightness * blue;
|
package/lib/filters/Sepia.js
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Sepia = void 0;
|
|
4
4
|
const Sepia = function (imageData) {
|
|
5
|
-
|
|
6
|
-
for (i = 0; i < nPixels; i += 4) {
|
|
7
|
-
r = data[i + 0];
|
|
8
|
-
g = data[i + 1];
|
|
9
|
-
b = data[i + 2];
|
|
5
|
+
const data = imageData.data, nPixels = data.length;
|
|
6
|
+
for (let i = 0; i < nPixels; i += 4) {
|
|
7
|
+
const r = data[i + 0];
|
|
8
|
+
const g = data[i + 1];
|
|
9
|
+
const b = data[i + 2];
|
|
10
10
|
data[i + 0] = Math.min(255, r * 0.393 + g * 0.769 + b * 0.189);
|
|
11
11
|
data[i + 1] = Math.min(255, r * 0.349 + g * 0.686 + b * 0.168);
|
|
12
12
|
data[i + 2] = Math.min(255, r * 0.272 + g * 0.534 + b * 0.131);
|
package/lib/shapes/Arrow.js
CHANGED
|
@@ -87,9 +87,9 @@ class Arrow extends Line_1.Line {
|
|
|
87
87
|
const lineRect = super.getSelfRect();
|
|
88
88
|
const offset = this.pointerWidth() / 2;
|
|
89
89
|
return {
|
|
90
|
-
x: lineRect.x
|
|
90
|
+
x: lineRect.x,
|
|
91
91
|
y: lineRect.y - offset,
|
|
92
|
-
width: lineRect.width
|
|
92
|
+
width: lineRect.width,
|
|
93
93
|
height: lineRect.height + offset * 2,
|
|
94
94
|
};
|
|
95
95
|
}
|
package/lib/shapes/Label.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { GetSet } from '../types.js';
|
|
|
6
6
|
import { Text } from './Text.js';
|
|
7
7
|
export interface LabelConfig extends ContainerConfig {
|
|
8
8
|
}
|
|
9
|
+
declare const NONE = "none";
|
|
9
10
|
export declare class Label extends Group {
|
|
10
11
|
constructor(config?: LabelConfig);
|
|
11
12
|
getText(): Text;
|
|
@@ -29,8 +30,9 @@ export declare class Tag extends Shape<TagConfig> {
|
|
|
29
30
|
width: number;
|
|
30
31
|
height: number;
|
|
31
32
|
};
|
|
32
|
-
pointerDirection: GetSet<'left' | '
|
|
33
|
+
pointerDirection: GetSet<'left' | 'up' | 'right' | 'down' | typeof NONE, this>;
|
|
33
34
|
pointerWidth: GetSet<number, this>;
|
|
34
35
|
pointerHeight: GetSet<number, this>;
|
|
35
36
|
cornerRadius: GetSet<number, this>;
|
|
36
37
|
}
|
|
38
|
+
export {};
|
package/lib/shapes/Text.js
CHANGED
|
@@ -10,8 +10,13 @@ const Validators_1 = require("../Validators");
|
|
|
10
10
|
const Global_2 = require("../Global");
|
|
11
11
|
function stringToArray(string) {
|
|
12
12
|
return [...string].reduce((acc, char, index, array) => {
|
|
13
|
-
if (/\p{
|
|
14
|
-
acc.
|
|
13
|
+
if (/\p{Emoji}/u.test(char)) {
|
|
14
|
+
if (acc.length > 0 && /\p{Emoji}/u.test(acc[acc.length - 1])) {
|
|
15
|
+
acc[acc.length - 1] += char;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
acc.push(char);
|
|
19
|
+
}
|
|
15
20
|
}
|
|
16
21
|
else if (/\p{Regional_Indicator}{2}/u.test(char + (array[index + 1] || ''))) {
|
|
17
22
|
acc.push(char + array[index + 1]);
|
|
@@ -160,9 +165,7 @@ class Text extends Shape_1.Shape {
|
|
|
160
165
|
spacesNumber = text.split(' ').length - 1;
|
|
161
166
|
oneWord = spacesNumber === 0;
|
|
162
167
|
lineWidth =
|
|
163
|
-
align === JUSTIFY && lastLine
|
|
164
|
-
? totalWidth - padding * 2
|
|
165
|
-
: width;
|
|
168
|
+
align === JUSTIFY && !lastLine ? totalWidth - padding * 2 : width;
|
|
166
169
|
context.lineTo(lineTranslateX + Math.round(lineWidth), translateY + lineTranslateY + yOffset);
|
|
167
170
|
context.lineWidth = fontSize / 15;
|
|
168
171
|
const gradient = this._getLinearGradient();
|
|
@@ -281,14 +284,15 @@ class Text extends Shape_1.Shape {
|
|
|
281
284
|
_getTextWidth(text) {
|
|
282
285
|
const letterSpacing = this.letterSpacing();
|
|
283
286
|
const length = text.length;
|
|
284
|
-
return
|
|
285
|
-
(length ? letterSpacing * (length - 1) : 0));
|
|
287
|
+
return getDummyContext().measureText(text).width + letterSpacing * length;
|
|
286
288
|
}
|
|
287
289
|
_setTextData() {
|
|
288
290
|
let lines = this.text().split('\n'), fontSize = +this.fontSize(), textWidth = 0, lineHeightPx = this.lineHeight() * fontSize, width = this.attrs.width, height = this.attrs.height, fixedWidth = width !== AUTO && width !== undefined, fixedHeight = height !== AUTO && height !== undefined, padding = this.padding(), maxWidth = width - padding * 2, maxHeightPx = height - padding * 2, currentHeightPx = 0, wrap = this.wrap(), shouldWrap = wrap !== NONE, wrapAtWord = wrap !== CHAR && shouldWrap, shouldAddEllipsis = this.ellipsis();
|
|
289
291
|
this.textArr = [];
|
|
290
292
|
getDummyContext().font = this._getContextFont();
|
|
291
|
-
const additionalWidth = shouldAddEllipsis
|
|
293
|
+
const additionalWidth = shouldAddEllipsis
|
|
294
|
+
? this._getTextWidth(ELLIPSIS)
|
|
295
|
+
: 0;
|
|
292
296
|
for (let i = 0, max = lines.length; i < max; ++i) {
|
|
293
297
|
let line = lines[i];
|
|
294
298
|
let lineWidth = this._getTextWidth(line);
|
package/lib/shapes/TextPath.js
CHANGED
|
@@ -237,5 +237,5 @@ Factory_1.Factory.addGetterSetter(TextPath, 'letterSpacing', 0, (0, Validators_1
|
|
|
237
237
|
Factory_1.Factory.addGetterSetter(TextPath, 'textBaseline', 'middle');
|
|
238
238
|
Factory_1.Factory.addGetterSetter(TextPath, 'fontVariant', NORMAL);
|
|
239
239
|
Factory_1.Factory.addGetterSetter(TextPath, 'text', EMPTY_STRING);
|
|
240
|
-
Factory_1.Factory.addGetterSetter(TextPath, 'textDecoration',
|
|
241
|
-
Factory_1.Factory.addGetterSetter(TextPath, 'kerningFunc',
|
|
240
|
+
Factory_1.Factory.addGetterSetter(TextPath, 'textDecoration', '');
|
|
241
|
+
Factory_1.Factory.addGetterSetter(TextPath, 'kerningFunc', undefined);
|
|
@@ -993,8 +993,8 @@ Factory_1.Factory.addGetterSetter(Transformer, 'shiftBehavior', 'default');
|
|
|
993
993
|
Factory_1.Factory.addGetterSetter(Transformer, 'centeredScaling', false);
|
|
994
994
|
Factory_1.Factory.addGetterSetter(Transformer, 'ignoreStroke', false);
|
|
995
995
|
Factory_1.Factory.addGetterSetter(Transformer, 'padding', 0, (0, Validators_1.getNumberValidator)());
|
|
996
|
-
Factory_1.Factory.addGetterSetter(Transformer, 'node');
|
|
997
996
|
Factory_1.Factory.addGetterSetter(Transformer, 'nodes');
|
|
997
|
+
Factory_1.Factory.addGetterSetter(Transformer, 'node');
|
|
998
998
|
Factory_1.Factory.addGetterSetter(Transformer, 'boundBoxFunc');
|
|
999
999
|
Factory_1.Factory.addGetterSetter(Transformer, 'anchorDragBoundFunc');
|
|
1000
1000
|
Factory_1.Factory.addGetterSetter(Transformer, 'anchorStyleFunc');
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "konva",
|
|
3
|
-
"version": "9.3.
|
|
3
|
+
"version": "9.3.17",
|
|
4
|
+
"description": "HTML5 2d canvas library.",
|
|
4
5
|
"author": "Anton Lavrenov",
|
|
5
6
|
"files": [
|
|
6
7
|
"README.md",
|
|
@@ -16,10 +17,10 @@
|
|
|
16
17
|
"start": "npm run test:watch",
|
|
17
18
|
"compile": "npm run clean && npm run tsc && cp ./src/index-types.d.ts ./lib/index-types.d.ts && npm run rollup",
|
|
18
19
|
"build": "npm run compile && cp ./src/index-types.d.ts ./lib && gulp build && node ./rename-imports.mjs",
|
|
19
|
-
"test:import": "npm run build && node ./test/import-test.cjs &&node ./test/import-test.mjs",
|
|
20
|
+
"test:import": "npm run build && node ./test/import-test.cjs && node ./test/import-test.mjs",
|
|
20
21
|
"test": "npm run test:browser && npm run test:node",
|
|
21
22
|
"test:build": "parcel build ./test/unit-tests.html --dist-dir ./test-build --target none --public-url ./ --no-source-maps",
|
|
22
|
-
"test:browser": "npm run test:build && mocha-headless-chrome -f ./test-build/unit-tests.html -a disable-web-security",
|
|
23
|
+
"test:browser": "npm run test:build && mocha-headless-chrome -f ./test-build/unit-tests.html -a disable-web-security -a no-sandbox",
|
|
23
24
|
"test:watch": "rm -rf ./.parcel-cache && PARCEL_WORKERS=0 parcel serve ./test/unit-tests.html ./test/manual-tests.html ./test/sandbox.html ./test/text-paths.html ./test/bunnies.html",
|
|
24
25
|
"test:node": "ts-mocha -r ./test/node-global-setup.mjs -p ./test/tsconfig.json test/unit/**/*.ts --exit && npm run test:import",
|
|
25
26
|
"tsc": "tsc --removeComments",
|
|
@@ -59,13 +60,13 @@
|
|
|
59
60
|
}
|
|
60
61
|
],
|
|
61
62
|
"devDependencies": {
|
|
62
|
-
"@parcel/transformer-image": "2.
|
|
63
|
-
"@size-limit/preset-big-lib": "^11.
|
|
64
|
-
"@types/mocha": "^10.0.
|
|
65
|
-
"canvas": "^
|
|
66
|
-
"chai": "
|
|
63
|
+
"@parcel/transformer-image": "2.13.2",
|
|
64
|
+
"@size-limit/preset-big-lib": "^11.1.6",
|
|
65
|
+
"@types/mocha": "^10.0.10",
|
|
66
|
+
"canvas": "^3.0.0-rc3",
|
|
67
|
+
"chai": "5.1.2",
|
|
67
68
|
"filehound": "^1.17.6",
|
|
68
|
-
"gulp": "^
|
|
69
|
+
"gulp": "^5.0.0",
|
|
69
70
|
"gulp-concat": "^2.6.1",
|
|
70
71
|
"gulp-connect": "^5.7.0",
|
|
71
72
|
"gulp-exec": "^5.0.0",
|
|
@@ -78,14 +79,14 @@
|
|
|
78
79
|
"gulp-util": "^3.0.8",
|
|
79
80
|
"mocha": "10.2.0",
|
|
80
81
|
"mocha-headless-chrome": "^4.0.0",
|
|
81
|
-
"parcel": "2.
|
|
82
|
+
"parcel": "2.13.2",
|
|
82
83
|
"process": "^0.11.10",
|
|
83
|
-
"rollup": "^4.
|
|
84
|
+
"rollup": "^4.28.1",
|
|
84
85
|
"rollup-plugin-typescript2": "^0.36.0",
|
|
85
|
-
"size-limit": "^11.
|
|
86
|
+
"size-limit": "^11.1.6",
|
|
86
87
|
"ts-mocha": "^10.0.0",
|
|
87
88
|
"ts-node": "^10.9.2",
|
|
88
|
-
"typescript": "^5.
|
|
89
|
+
"typescript": "^5.7.2"
|
|
89
90
|
},
|
|
90
91
|
"keywords": [
|
|
91
92
|
"canvas",
|