konva 9.3.16 → 9.3.18

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.
@@ -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
- let srcPixels = src.data, dstPixels = dst.data, xSize = src.width, ySize = src.height, xMid = opt.polarCenterX || xSize / 2, yMid = opt.polarCenterY || ySize / 2, i, x, y, r = 0, g = 0, b = 0, a = 0;
10
- let rad, rMax = Math.sqrt(xMid * xMid + yMid * yMid);
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
- let rSize = ySize, tSize = xSize, radius, theta;
16
- let conversion = ((360 / tSize) * Math.PI) / 180, sin, cos;
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
- let srcPixels = src.data, dstPixels = dst.data, xSize = src.width, ySize = src.height, xMid = opt.polarCenterX || xSize / 2, yMid = opt.polarCenterY || ySize / 2, i, x, y, dx, dy, r = 0, g = 0, b = 0, a = 0;
38
- let rad, rMax = Math.sqrt(xMid * xMid + yMid * yMid);
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
- let rSize = ySize, tSize = xSize, radius, theta, phaseShift = opt.polarRotation || 0;
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;
@@ -131,7 +131,8 @@ function smoothEdgeMask(mask, sw, sh) {
131
131
  return maskResult;
132
132
  }
133
133
  const Mask = function (imageData) {
134
- let threshold = this.threshold(), mask = backgroundMask(imageData, threshold);
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);
@@ -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
- let levels = Math.round(this.levels() * 254) + 1, data = imageData.data, len = data.length, scale = 255 / levels, i;
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
  };
@@ -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
- let data = imageData.data, nPixels = data.length, red = this.red(), green = this.green(), blue = this.blue(), i, brightness;
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;
@@ -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
- let data = imageData.data, nPixels = data.length, i, r, g, b;
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);
@@ -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 - offset,
90
+ x: lineRect.x,
91
91
  y: lineRect.y - offset,
92
- width: lineRect.width + offset * 2,
92
+ width: lineRect.width,
93
93
  height: lineRect.height + offset * 2,
94
94
  };
95
95
  }
@@ -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' | 'top' | 'right' | 'bottom' | 'up' | 'down', this>;
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 {};
@@ -10,8 +10,15 @@ 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{Emoji_Modifier_Base}\p{Emoji_Modifier}?(?:\u200D\p{Emoji_Presentation})+/u.test(char)) {
14
- acc.push(char);
13
+ if (/\p{Emoji}/u.test(char)) {
14
+ const nextChar = array[index + 1];
15
+ if (nextChar && /\p{Emoji_Modifier}|\u200D/u.test(nextChar)) {
16
+ acc.push(char + nextChar);
17
+ array[index + 1] = '';
18
+ }
19
+ else {
20
+ acc.push(char);
21
+ }
15
22
  }
16
23
  else if (/\p{Regional_Indicator}{2}/u.test(char + (array[index + 1] || ''))) {
17
24
  acc.push(char + array[index + 1]);
@@ -19,7 +26,7 @@ function stringToArray(string) {
19
26
  else if (index > 0 && /\p{Mn}|\p{Me}|\p{Mc}/u.test(char)) {
20
27
  acc[acc.length - 1] += char;
21
28
  }
22
- else {
29
+ else if (char) {
23
30
  acc.push(char);
24
31
  }
25
32
  return acc;
@@ -160,9 +167,7 @@ class Text extends Shape_1.Shape {
160
167
  spacesNumber = text.split(' ').length - 1;
161
168
  oneWord = spacesNumber === 0;
162
169
  lineWidth =
163
- align === JUSTIFY && lastLine && !oneWord
164
- ? totalWidth - padding * 2
165
- : width;
170
+ align === JUSTIFY && !lastLine ? totalWidth - padding * 2 : width;
166
171
  context.lineTo(lineTranslateX + Math.round(lineWidth), translateY + lineTranslateY + yOffset);
167
172
  context.lineWidth = fontSize / 15;
168
173
  const gradient = this._getLinearGradient();
@@ -281,22 +286,23 @@ class Text extends Shape_1.Shape {
281
286
  _getTextWidth(text) {
282
287
  const letterSpacing = this.letterSpacing();
283
288
  const length = text.length;
284
- return (getDummyContext().measureText(text).width +
285
- (length ? letterSpacing * (length - 1) : 0));
289
+ return getDummyContext().measureText(text).width + letterSpacing * length;
286
290
  }
287
291
  _setTextData() {
288
292
  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
293
  this.textArr = [];
290
294
  getDummyContext().font = this._getContextFont();
291
- const additionalWidth = shouldAddEllipsis ? this._getTextWidth(ELLIPSIS) : 0;
295
+ const additionalWidth = shouldAddEllipsis
296
+ ? this._getTextWidth(ELLIPSIS)
297
+ : 0;
292
298
  for (let i = 0, max = lines.length; i < max; ++i) {
293
299
  let line = lines[i];
294
300
  let lineWidth = this._getTextWidth(line);
295
301
  if (fixedWidth && lineWidth > maxWidth) {
296
302
  while (line.length > 0) {
297
- let low = 0, high = line.length, match = '', matchWidth = 0;
303
+ let low = 0, high = stringToArray(line).length, match = '', matchWidth = 0;
298
304
  while (low < high) {
299
- const mid = (low + high) >>> 1, substr = line.slice(0, mid + 1), substrWidth = this._getTextWidth(substr) + additionalWidth;
305
+ const mid = (low + high) >>> 1, lineArray = stringToArray(line), substr = lineArray.slice(0, mid + 1).join(''), substrWidth = this._getTextWidth(substr) + additionalWidth;
300
306
  if (substrWidth <= maxWidth) {
301
307
  low = mid + 1;
302
308
  match = substr;
@@ -308,20 +314,22 @@ class Text extends Shape_1.Shape {
308
314
  }
309
315
  if (match) {
310
316
  if (wrapAtWord) {
311
- var wrapIndex;
312
- const nextChar = line[match.length];
317
+ const lineArray = stringToArray(line);
318
+ const matchArray = stringToArray(match);
319
+ const nextChar = lineArray[matchArray.length];
313
320
  const nextIsSpaceOrDash = nextChar === SPACE || nextChar === DASH;
321
+ let wrapIndex;
314
322
  if (nextIsSpaceOrDash && matchWidth <= maxWidth) {
315
- wrapIndex = match.length;
323
+ wrapIndex = matchArray.length;
316
324
  }
317
325
  else {
318
- wrapIndex =
319
- Math.max(match.lastIndexOf(SPACE), match.lastIndexOf(DASH)) +
320
- 1;
326
+ const lastSpaceIndex = matchArray.lastIndexOf(SPACE);
327
+ const lastDashIndex = matchArray.lastIndexOf(DASH);
328
+ wrapIndex = Math.max(lastSpaceIndex, lastDashIndex) + 1;
321
329
  }
322
330
  if (wrapIndex > 0) {
323
331
  low = wrapIndex;
324
- match = match.slice(0, low);
332
+ match = lineArray.slice(0, low).join('');
325
333
  matchWidth = this._getTextWidth(match);
326
334
  }
327
335
  }
@@ -334,8 +342,8 @@ class Text extends Shape_1.Shape {
334
342
  this._tryToAddEllipsisToLastLine();
335
343
  break;
336
344
  }
337
- line = line.slice(low);
338
- line = line.trimLeft();
345
+ const lineArray = stringToArray(line);
346
+ line = lineArray.slice(low).join('').trimLeft();
339
347
  if (line.length > 0) {
340
348
  lineWidth = this._getTextWidth(line);
341
349
  if (lineWidth <= maxWidth) {
@@ -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', null);
241
- Factory_1.Factory.addGetterSetter(TextPath, 'kerningFunc', null);
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.16",
3
+ "version": "9.3.18",
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.10.1",
63
- "@size-limit/preset-big-lib": "^11.0.1",
64
- "@types/mocha": "^10.0.6",
65
- "canvas": "^2.11.2",
66
- "chai": "4.3.10",
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": "^4.0.2",
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.10.1",
82
+ "parcel": "2.13.2",
82
83
  "process": "^0.11.10",
83
- "rollup": "^4.9.1",
84
+ "rollup": "^4.28.1",
84
85
  "rollup-plugin-typescript2": "^0.36.0",
85
- "size-limit": "^11.0.1",
86
+ "size-limit": "^11.1.6",
86
87
  "ts-mocha": "^10.0.0",
87
88
  "ts-node": "^10.9.2",
88
- "typescript": "^5.3.3"
89
+ "typescript": "^5.7.2"
89
90
  },
90
91
  "keywords": [
91
92
  "canvas",