konva 8.3.8 → 8.3.11

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.
@@ -55,6 +55,7 @@ export const DD = {
55
55
  });
56
56
  },
57
57
  _endDragBefore(evt) {
58
+ const drawNodes = [];
58
59
  DD._dragElements.forEach((elem) => {
59
60
  const { node } = elem;
60
61
  const stage = node.getStage();
@@ -74,10 +75,13 @@ export const DD = {
74
75
  }
75
76
  const drawNode = elem.node.getLayer() ||
76
77
  (elem.node instanceof Konva['Stage'] && elem.node);
77
- if (drawNode) {
78
- drawNode.batchDraw();
78
+ if (drawNode && drawNodes.indexOf(drawNode) === -1) {
79
+ drawNodes.push(drawNode);
79
80
  }
80
81
  });
82
+ drawNodes.forEach((drawNode) => {
83
+ drawNode.draw();
84
+ });
81
85
  },
82
86
  _endDragAfter(evt) {
83
87
  DD._dragElements.forEach((elem, key) => {
package/lib/Global.js CHANGED
@@ -13,7 +13,7 @@ export const glob = typeof global !== 'undefined'
13
13
  : {};
14
14
  export const Konva = {
15
15
  _global: glob,
16
- version: '8.3.8',
16
+ version: '8.3.11',
17
17
  isBrowser: detectBrowser(),
18
18
  isUnminified: /param/.test(function (param) { }.toString()),
19
19
  dblClickWindow: 400,
package/lib/Group.d.ts CHANGED
@@ -1,6 +1,8 @@
1
- import { Container } from './Container';
1
+ import { Container, ContainerConfig } from './Container';
2
2
  import { Node } from './Node';
3
3
  import { Shape } from './Shape';
4
+ export interface GroupConfig extends ContainerConfig {
5
+ }
4
6
  export declare class Group extends Container<Group | Shape> {
5
7
  _validateAdd(child: Node): void;
6
8
  }
package/lib/Node.d.ts CHANGED
@@ -216,7 +216,17 @@ export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
216
216
  mimeType?: string;
217
217
  quality?: number;
218
218
  callback?: (img: HTMLImageElement) => void;
219
- }): void;
219
+ }): Promise<unknown>;
220
+ toBlob(config?: {
221
+ x?: number;
222
+ y?: number;
223
+ width?: number;
224
+ height?: number;
225
+ pixelRatio?: number;
226
+ mimeType?: string;
227
+ quality?: number;
228
+ callback?: (blob: Blob) => void;
229
+ }): Promise<unknown>;
220
230
  setSize(size: any): this;
221
231
  getSize(): {
222
232
  width: number;
package/lib/Node.js CHANGED
@@ -964,13 +964,35 @@ export class Node {
964
964
  return url;
965
965
  }
966
966
  toImage(config) {
967
- if (!config || !config.callback) {
968
- throw 'callback required for toImage method config argument';
969
- }
970
- var callback = config.callback;
971
- delete config.callback;
972
- Util._urlToImage(this.toDataURL(config), function (img) {
973
- callback(img);
967
+ return new Promise((resolve, reject) => {
968
+ try {
969
+ const callback = config === null || config === void 0 ? void 0 : config.callback;
970
+ if (callback)
971
+ delete config.callback;
972
+ Util._urlToImage(this.toDataURL(config), function (img) {
973
+ resolve(img);
974
+ callback === null || callback === void 0 ? void 0 : callback(img);
975
+ });
976
+ }
977
+ catch (err) {
978
+ reject(err);
979
+ }
980
+ });
981
+ }
982
+ toBlob(config) {
983
+ return new Promise((resolve, reject) => {
984
+ try {
985
+ const callback = config === null || config === void 0 ? void 0 : config.callback;
986
+ if (callback)
987
+ delete config.callback;
988
+ this.toCanvas(config).toBlob(blob => {
989
+ resolve(blob);
990
+ callback === null || callback === void 0 ? void 0 : callback(blob);
991
+ });
992
+ }
993
+ catch (err) {
994
+ reject(err);
995
+ }
974
996
  });
975
997
  }
976
998
  setSize(size) {
package/lib/Stage.js CHANGED
@@ -543,7 +543,7 @@ export class Stage extends Container {
543
543
  });
544
544
  }
545
545
  Konva['_' + eventType + 'ListenClick'] = false;
546
- if (evt.cancelable) {
546
+ if (evt.cancelable && eventType !== 'touch') {
547
547
  evt.preventDefault();
548
548
  }
549
549
  }
@@ -83,6 +83,7 @@ declare namespace Konva {
83
83
 
84
84
  export const Group: typeof import('./Group').Group;
85
85
  export type Group = import('./Group').Group;
86
+ export type GroupConfig = import('./Group').GroupConfig;
86
87
 
87
88
  export const DD: typeof import('./DragAndDrop').DD;
88
89
 
@@ -12,6 +12,9 @@ var ATTR_CHANGE_LIST = [
12
12
  'text',
13
13
  'width',
14
14
  'height',
15
+ 'pointerDirection',
16
+ 'pointerWidth',
17
+ 'pointerHeight',
15
18
  ], CHANGE_KONVA = 'Change.konva', NONE = 'none', UP = 'up', RIGHT = 'right', DOWN = 'down', LEFT = 'left', attrChangeListLen = ATTR_CHANGE_LIST.length;
16
19
  export class Label extends Group {
17
20
  constructor(config) {
@@ -93,7 +96,11 @@ export class Tag extends Shape {
93
96
  let bottomLeft = 0;
94
97
  let bottomRight = 0;
95
98
  if (typeof cornerRadius === 'number') {
96
- topLeft = topRight = bottomLeft = bottomRight = Math.min(cornerRadius, width / 2, height / 2);
99
+ topLeft =
100
+ topRight =
101
+ bottomLeft =
102
+ bottomRight =
103
+ Math.min(cornerRadius, width / 2, height / 2);
97
104
  }
98
105
  else {
99
106
  topLeft = Math.min(cornerRadius[0] || 0, width / 2, height / 2);
@@ -43,6 +43,8 @@ export declare class Text extends Shape<TextConfig> {
43
43
  _addTextLine(line: any): number;
44
44
  _getTextWidth(text: any): any;
45
45
  _setTextData(): void;
46
+ _shouldHandleEllipsis(currentHeightPx: number): boolean;
47
+ _tryToAddEllipsisToLastLine(): void;
46
48
  getStrokeScaleEnabled(): boolean;
47
49
  fontFamily: GetSet<string, this>;
48
50
  fontSize: GetSet<number, this>;
@@ -274,19 +274,9 @@ export class Text extends Shape {
274
274
  this._addTextLine(match);
275
275
  textWidth = Math.max(textWidth, matchWidth);
276
276
  currentHeightPx += lineHeightPx;
277
- if (!shouldWrap ||
278
- (fixedHeight && currentHeightPx + lineHeightPx > maxHeightPx)) {
279
- var lastLine = this.textArr[this.textArr.length - 1];
280
- if (lastLine) {
281
- if (shouldAddEllipsis) {
282
- var haveSpace = this._getTextWidth(lastLine.text + ELLIPSIS) < maxWidth;
283
- if (!haveSpace) {
284
- lastLine.text = lastLine.text.slice(0, lastLine.text.length - 3);
285
- }
286
- this.textArr.splice(this.textArr.length - 1, 1);
287
- this._addTextLine(lastLine.text + ELLIPSIS);
288
- }
289
- }
277
+ var shouldHandleEllipsis = this._shouldHandleEllipsis(currentHeightPx);
278
+ if (shouldHandleEllipsis) {
279
+ this._tryToAddEllipsisToLastLine();
290
280
  break;
291
281
  }
292
282
  line = line.slice(low);
@@ -310,6 +300,9 @@ export class Text extends Shape {
310
300
  this._addTextLine(line);
311
301
  currentHeightPx += lineHeightPx;
312
302
  textWidth = Math.max(textWidth, lineWidth);
303
+ if (this._shouldHandleEllipsis(currentHeightPx)) {
304
+ this._tryToAddEllipsisToLastLine();
305
+ }
313
306
  }
314
307
  if (fixedHeight && currentHeightPx + lineHeightPx > maxHeightPx) {
315
308
  break;
@@ -321,6 +314,26 @@ export class Text extends Shape {
321
314
  this.textHeight = fontSize;
322
315
  this.textWidth = textWidth;
323
316
  }
317
+ _shouldHandleEllipsis(currentHeightPx) {
318
+ var fontSize = +this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, height = this.attrs.height, fixedHeight = height !== AUTO && height !== undefined, padding = this.padding(), maxHeightPx = height - padding * 2, wrap = this.wrap(), shouldWrap = wrap !== NONE;
319
+ return (!shouldWrap ||
320
+ (fixedHeight && currentHeightPx + lineHeightPx > maxHeightPx));
321
+ }
322
+ _tryToAddEllipsisToLastLine() {
323
+ var width = this.attrs.width, fixedWidth = width !== AUTO && width !== undefined, padding = this.padding(), maxWidth = width - padding * 2, shouldAddEllipsis = this.ellipsis();
324
+ var lastLine = this.textArr[this.textArr.length - 1];
325
+ if (!lastLine || !shouldAddEllipsis) {
326
+ return;
327
+ }
328
+ if (fixedWidth) {
329
+ var haveSpace = this._getTextWidth(lastLine.text + ELLIPSIS) < maxWidth;
330
+ if (!haveSpace) {
331
+ lastLine.text = lastLine.text.slice(0, lastLine.text.length - 3);
332
+ }
333
+ }
334
+ this.textArr.splice(this.textArr.length - 1, 1);
335
+ this._addTextLine(lastLine.text + ELLIPSIS);
336
+ }
324
337
  getStrokeScaleEnabled() {
325
338
  return true;
326
339
  }
@@ -86,6 +86,12 @@ export declare class Transformer extends Group {
86
86
  stopTransform(): void;
87
87
  destroy(): this;
88
88
  toObject(): any;
89
+ getClientRect(): {
90
+ x: number;
91
+ y: number;
92
+ width: number;
93
+ height: number;
94
+ };
89
95
  nodes: GetSet<Node[], this>;
90
96
  enabledAnchors: GetSet<string[], this>;
91
97
  rotationSnaps: GetSet<number[], this>;
@@ -896,6 +896,9 @@ export class Transformer extends Group {
896
896
  toObject() {
897
897
  return Node.prototype.toObject.call(this);
898
898
  }
899
+ getClientRect() {
900
+ return { x: 0, y: 0, width: 0, height: 0 };
901
+ }
899
902
  }
900
903
  function validateAnchors(val) {
901
904
  if (!(val instanceof Array)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "konva",
3
- "version": "8.3.8",
3
+ "version": "8.3.11",
4
4
  "author": "Anton Lavrenov",
5
5
  "files": [
6
6
  "README.md",
@@ -47,7 +47,7 @@
47
47
  "build": "npm run compile && cp ./src/index-types.d.ts ./lib && gulp build && node ./rename-imports.mjs",
48
48
  "test:import": "npm run build && node ./test/import-test.cjs &&node ./test/import-test.mjs",
49
49
  "test": "npm run test:browser && npm run test:node",
50
- "test:build": "parcel build ./test/unit-tests.html --dist-dir test-build --target none --public-url ./ --no-source-maps",
50
+ "test:build": "parcel build ./test/unit-tests.html --dist-dir ./test-build --target none --public-url ./ --no-source-maps",
51
51
  "test:browser": "npm run test:build && mocha-headless-chrome -f ./test-build/unit-tests.html -a disable-web-security",
52
52
  "test:node": "env TS_NODE_PROJECT=\"./test/tsconfig.json\" mocha -r ts-node/register test/unit/**/*.ts --exit && npm run test:import",
53
53
  "test:watch": "rm -rf ./parcel-cache && parcel serve ./test/unit-tests.html ./test/manual-tests.html ./test/sandbox.html",
@@ -88,7 +88,7 @@
88
88
  }
89
89
  ],
90
90
  "devDependencies": {
91
- "@parcel/transformer-image": "2.5.0",
91
+ "@parcel/transformer-image": "2.6.0",
92
92
  "@size-limit/preset-big-lib": "^7.0.8",
93
93
  "@types/mocha": "^9.1.1",
94
94
  "canvas": "^2.9.1",
@@ -107,9 +107,9 @@
107
107
  "gulp-util": "^3.0.8",
108
108
  "mocha": "9.2.2",
109
109
  "mocha-headless-chrome": "^4.0.0",
110
- "parcel": "2.5.0",
110
+ "parcel": "2.6.0",
111
111
  "process": "^0.11.10",
112
- "rollup": "^2.70.2",
112
+ "rollup": "^2.75.0",
113
113
  "rollup-plugin-commonjs": "^10.1.0",
114
114
  "rollup-plugin-node-resolve": "^5.2.0",
115
115
  "rollup-plugin-sourcemaps": "^0.6.3",
@@ -117,7 +117,7 @@
117
117
  "size-limit": "^7.0.8",
118
118
  "ts-mocha": "^9.0.2",
119
119
  "ts-node": "^9.1.1",
120
- "typescript": "4.6.3"
120
+ "typescript": "^4.6.3"
121
121
  },
122
122
  "keywords": [
123
123
  "canvas",