konva 9.3.17 → 9.3.19

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/lib/Canvas.js CHANGED
@@ -4,8 +4,6 @@ exports.HitCanvas = exports.SceneCanvas = exports.Canvas = void 0;
4
4
  const Util_1 = require("./Util");
5
5
  const Context_1 = require("./Context");
6
6
  const Global_1 = require("./Global");
7
- const Factory_1 = require("./Factory");
8
- const Validators_1 = require("./Validators");
9
7
  let _pixelRatio;
10
8
  function getDevicePixelRatio() {
11
9
  if (_pixelRatio) {
@@ -94,7 +92,6 @@ class Canvas {
94
92
  }
95
93
  }
96
94
  exports.Canvas = Canvas;
97
- Factory_1.Factory.addGetterSetter(Canvas, 'pixelRatio', undefined, (0, Validators_1.getNumberValidator)());
98
95
  class SceneCanvas extends Canvas {
99
96
  constructor(config = { width: 0, height: 0, willReadFrequently: false }) {
100
97
  super(config);
package/lib/Global.js CHANGED
@@ -16,7 +16,7 @@ exports.glob = typeof global !== 'undefined'
16
16
  : {};
17
17
  exports.Konva = {
18
18
  _global: exports.glob,
19
- version: '9.3.17',
19
+ version: '9.3.19',
20
20
  isBrowser: detectBrowser(),
21
21
  isUnminified: /param/.test(function (param) { }.toString()),
22
22
  dblClickWindow: 400,
package/lib/shapes/Arc.js CHANGED
@@ -51,7 +51,12 @@ class Arc extends Shape_1.Shape {
51
51
  exports.Arc = Arc;
52
52
  Arc.prototype._centroid = true;
53
53
  Arc.prototype.className = 'Arc';
54
- Arc.prototype._attrsAffectingSize = ['innerRadius', 'outerRadius'];
54
+ Arc.prototype._attrsAffectingSize = [
55
+ 'innerRadius',
56
+ 'outerRadius',
57
+ 'angle',
58
+ 'clockwise',
59
+ ];
55
60
  (0, Global_2._registerNode)(Arc);
56
61
  Factory_1.Factory.addGetterSetter(Arc, 'innerRadius', 0, (0, Validators_1.getNumberValidator)());
57
62
  Factory_1.Factory.addGetterSetter(Arc, 'outerRadius', 0, (0, Validators_1.getNumberValidator)());
@@ -7,8 +7,11 @@ export interface ImageConfig extends ShapeConfig {
7
7
  cornerRadius?: number | number[];
8
8
  }
9
9
  export declare class Image extends Shape<ImageConfig> {
10
+ private _loadListener;
10
11
  constructor(attrs: ImageConfig);
11
12
  _setImageLoad(): void;
13
+ _removeImageLoad(image: any): void;
14
+ destroy(): this;
12
15
  _useBufferCanvas(): boolean;
13
16
  _sceneFunc(context: Context): void;
14
17
  _hitFunc(context: Context): void;
@@ -9,7 +9,11 @@ const Validators_1 = require("../Validators");
9
9
  class Image extends Shape_1.Shape {
10
10
  constructor(attrs) {
11
11
  super(attrs);
12
- this.on('imageChange.konva', () => {
12
+ this._loadListener = () => {
13
+ this._requestDraw();
14
+ };
15
+ this.on('imageChange.konva', (props) => {
16
+ this._removeImageLoad(props.oldVal);
13
17
  this._setImageLoad();
14
18
  });
15
19
  this._setImageLoad();
@@ -23,11 +27,19 @@ class Image extends Shape_1.Shape {
23
27
  return;
24
28
  }
25
29
  if (image && image['addEventListener']) {
26
- image['addEventListener']('load', () => {
27
- this._requestDraw();
28
- });
30
+ image['addEventListener']('load', this._loadListener);
29
31
  }
30
32
  }
33
+ _removeImageLoad(image) {
34
+ if (image && image['removeEventListener']) {
35
+ image['removeEventListener']('load', this._loadListener);
36
+ }
37
+ }
38
+ destroy() {
39
+ this._removeImageLoad(this.image());
40
+ super.destroy();
41
+ return this;
42
+ }
31
43
  _useBufferCanvas() {
32
44
  const hasCornerRadius = !!this.cornerRadius();
33
45
  const hasShadow = this.hasShadow();
@@ -11,8 +11,10 @@ const Global_2 = require("../Global");
11
11
  function stringToArray(string) {
12
12
  return [...string].reduce((acc, char, index, array) => {
13
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;
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] = '';
16
18
  }
17
19
  else {
18
20
  acc.push(char);
@@ -24,7 +26,7 @@ function stringToArray(string) {
24
26
  else if (index > 0 && /\p{Mn}|\p{Me}|\p{Mc}/u.test(char)) {
25
27
  acc[acc.length - 1] += char;
26
28
  }
27
- else {
29
+ else if (char) {
28
30
  acc.push(char);
29
31
  }
30
32
  return acc;
@@ -298,9 +300,9 @@ class Text extends Shape_1.Shape {
298
300
  let lineWidth = this._getTextWidth(line);
299
301
  if (fixedWidth && lineWidth > maxWidth) {
300
302
  while (line.length > 0) {
301
- let low = 0, high = line.length, match = '', matchWidth = 0;
303
+ let low = 0, high = stringToArray(line).length, match = '', matchWidth = 0;
302
304
  while (low < high) {
303
- 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;
304
306
  if (substrWidth <= maxWidth) {
305
307
  low = mid + 1;
306
308
  match = substr;
@@ -312,20 +314,22 @@ class Text extends Shape_1.Shape {
312
314
  }
313
315
  if (match) {
314
316
  if (wrapAtWord) {
315
- var wrapIndex;
316
- const nextChar = line[match.length];
317
+ const lineArray = stringToArray(line);
318
+ const matchArray = stringToArray(match);
319
+ const nextChar = lineArray[matchArray.length];
317
320
  const nextIsSpaceOrDash = nextChar === SPACE || nextChar === DASH;
321
+ let wrapIndex;
318
322
  if (nextIsSpaceOrDash && matchWidth <= maxWidth) {
319
- wrapIndex = match.length;
323
+ wrapIndex = matchArray.length;
320
324
  }
321
325
  else {
322
- wrapIndex =
323
- Math.max(match.lastIndexOf(SPACE), match.lastIndexOf(DASH)) +
324
- 1;
326
+ const lastSpaceIndex = matchArray.lastIndexOf(SPACE);
327
+ const lastDashIndex = matchArray.lastIndexOf(DASH);
328
+ wrapIndex = Math.max(lastSpaceIndex, lastDashIndex) + 1;
325
329
  }
326
330
  if (wrapIndex > 0) {
327
331
  low = wrapIndex;
328
- match = match.slice(0, low);
332
+ match = lineArray.slice(0, low).join('');
329
333
  matchWidth = this._getTextWidth(match);
330
334
  }
331
335
  }
@@ -338,8 +342,8 @@ class Text extends Shape_1.Shape {
338
342
  this._tryToAddEllipsisToLastLine();
339
343
  break;
340
344
  }
341
- line = line.slice(low);
342
- line = line.trimLeft();
345
+ const lineArray = stringToArray(line);
346
+ line = lineArray.slice(low).join('').trimLeft();
343
347
  if (line.length > 0) {
344
348
  lineWidth = this._getTextWidth(line);
345
349
  if (lineWidth <= maxWidth) {
@@ -198,10 +198,12 @@ class Transformer extends Group_1.Group {
198
198
  this.update();
199
199
  }
200
200
  };
201
- const additionalEvents = node._attrsAffectingSize
202
- .map((prop) => prop + 'Change.' + this._getEventNamespace())
203
- .join(' ');
204
- node.on(additionalEvents, onChange);
201
+ if (node._attrsAffectingSize.length) {
202
+ const additionalEvents = node._attrsAffectingSize
203
+ .map((prop) => prop + 'Change.' + this._getEventNamespace())
204
+ .join(' ');
205
+ node.on(additionalEvents, onChange);
206
+ }
205
207
  node.on(TRANSFORM_CHANGE_STR.map((e) => e + `.${this._getEventNamespace()}`).join(' '), onChange);
206
208
  node.on(`absoluteTransformChange.${this._getEventNamespace()}`, onChange);
207
209
  this._proxyDrag(node);
package/lib/types.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export interface GetSet<Type, This> {
2
2
  (): Type;
3
- (v: Type): This;
3
+ (v: Type | null | undefined): This;
4
4
  }
5
5
  export interface Vector2d {
6
6
  x: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "konva",
3
- "version": "9.3.17",
3
+ "version": "9.3.19",
4
4
  "description": "HTML5 2d canvas library.",
5
5
  "author": "Anton Lavrenov",
6
6
  "files": [
@@ -19,8 +19,8 @@
19
19
  "build": "npm run compile && cp ./src/index-types.d.ts ./lib && gulp build && node ./rename-imports.mjs",
20
20
  "test:import": "npm run build && node ./test/import-test.cjs && node ./test/import-test.mjs",
21
21
  "test": "npm run test:browser && npm run test:node",
22
- "test:build": "parcel build ./test/unit-tests.html --dist-dir ./test-build --target none --public-url ./ --no-source-maps",
23
- "test:browser": "npm run test:build && mocha-headless-chrome -f ./test-build/unit-tests.html -a disable-web-security -a no-sandbox",
22
+ "test:build": "PARCEL_WORKER_BACKEND=process parcel build ./test/unit-tests.html --dist-dir ./test-build --target none --public-url ./ --no-source-maps",
23
+ "test:browser": "npm run test:build && mocha-headless-chrome -f ./test-build/unit-tests.html -a disable-web-security -a no-sandbox -a disable-setuid-sandbox",
24
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",
25
25
  "test:node": "ts-mocha -r ./test/node-global-setup.mjs -p ./test/tsconfig.json test/unit/**/*.ts --exit && npm run test:import",
26
26
  "tsc": "tsc --removeComments",
@@ -63,7 +63,7 @@
63
63
  "@parcel/transformer-image": "2.13.2",
64
64
  "@size-limit/preset-big-lib": "^11.1.6",
65
65
  "@types/mocha": "^10.0.10",
66
- "canvas": "^3.0.0-rc3",
66
+ "canvas": "^3.1.0",
67
67
  "chai": "5.1.2",
68
68
  "filehound": "^1.17.6",
69
69
  "gulp": "^5.0.0",
@@ -79,14 +79,14 @@
79
79
  "gulp-util": "^3.0.8",
80
80
  "mocha": "10.2.0",
81
81
  "mocha-headless-chrome": "^4.0.0",
82
- "parcel": "2.13.2",
82
+ "parcel": "2.13.3",
83
83
  "process": "^0.11.10",
84
- "rollup": "^4.28.1",
84
+ "rollup": "^4.31.0",
85
85
  "rollup-plugin-typescript2": "^0.36.0",
86
86
  "size-limit": "^11.1.6",
87
87
  "ts-mocha": "^10.0.0",
88
88
  "ts-node": "^10.9.2",
89
- "typescript": "^5.7.2"
89
+ "typescript": "^5.7.3"
90
90
  },
91
91
  "keywords": [
92
92
  "canvas",