konva 8.3.2 → 8.3.5

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/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.2',
16
+ version: '8.3.5',
17
17
  isBrowser: detectBrowser(),
18
18
  isUnminified: /param/.test(function (param) { }.toString()),
19
19
  dblClickWindow: 400,
package/lib/Node.js CHANGED
@@ -99,13 +99,13 @@ export class Node {
99
99
  relativeTo: this.getParent(),
100
100
  });
101
101
  }
102
- var width = Math.ceil(conf.width || rect.width), height = Math.ceil(conf.height || rect.height), pixelRatio = conf.pixelRatio, x = conf.x === undefined ? rect.x : conf.x, y = conf.y === undefined ? rect.y : conf.y, offset = conf.offset || 0, drawBorder = conf.drawBorder || false, hitCanvasPixelRatio = conf.hitCanvasPixelRatio || 1;
102
+ var width = Math.ceil(conf.width || rect.width), height = Math.ceil(conf.height || rect.height), pixelRatio = conf.pixelRatio, x = conf.x === undefined ? Math.floor(rect.x) : conf.x, y = conf.y === undefined ? Math.floor(rect.y) : conf.y, offset = conf.offset || 0, drawBorder = conf.drawBorder || false, hitCanvasPixelRatio = conf.hitCanvasPixelRatio || 1;
103
103
  if (!width || !height) {
104
104
  Util.error('Can not cache the node. Width or height of the node equals 0. Caching is skipped.');
105
105
  return;
106
106
  }
107
- width += offset * 2;
108
- height += offset * 2;
107
+ width += offset * 2 + 1;
108
+ height += offset * 2 + 1;
109
109
  x -= offset;
110
110
  y -= offset;
111
111
  var cachedSceneCanvas = new SceneCanvas({
@@ -933,9 +933,11 @@ export class Node {
933
933
  _toKonvaCanvas(config) {
934
934
  config = config || {};
935
935
  var box = this.getClientRect();
936
- var stage = this.getStage(), x = config.x !== undefined ? config.x : box.x, y = config.y !== undefined ? config.y : box.y, pixelRatio = config.pixelRatio || 1, canvas = new SceneCanvas({
937
- width: config.width || box.width || (stage ? stage.width() : 0),
938
- height: config.height || box.height || (stage ? stage.height() : 0),
936
+ var stage = this.getStage(), x = config.x !== undefined ? config.x : Math.floor(box.x), y = config.y !== undefined ? config.y : Math.floor(box.y), pixelRatio = config.pixelRatio || 1, canvas = new SceneCanvas({
937
+ width: config.width || Math.ceil(box.width) || (stage ? stage.width() : 0),
938
+ height: config.height ||
939
+ Math.ceil(box.height) ||
940
+ (stage ? stage.height() : 0),
939
941
  pixelRatio: pixelRatio,
940
942
  }), context = canvas.getContext();
941
943
  context.save();
@@ -1290,8 +1292,8 @@ export class Node {
1290
1292
  const screenRect = {
1291
1293
  x: -margin.x,
1292
1294
  y: -margin.y,
1293
- width: stage.width() + margin.x,
1294
- height: stage.height() + margin.y,
1295
+ width: stage.width() + 2 * margin.x,
1296
+ height: stage.height() + 2 * margin.y,
1295
1297
  };
1296
1298
  return Util.haveIntersection(screenRect, this.getClientRect());
1297
1299
  }
package/lib/Shape.js CHANGED
@@ -98,14 +98,17 @@ export class Shape extends Node {
98
98
  tr.scale(this.fillPatternScaleX(), this.fillPatternScaleY());
99
99
  tr.translate(-1 * this.fillPatternOffsetX(), -1 * this.fillPatternOffsetY());
100
100
  const m = tr.getMatrix();
101
- pattern.setTransform({
102
- a: m[0],
103
- b: m[1],
104
- c: m[2],
105
- d: m[3],
106
- e: m[4],
107
- f: m[5],
108
- });
101
+ const matrix = typeof DOMMatrix === 'undefined'
102
+ ? {
103
+ a: m[0],
104
+ b: m[1],
105
+ c: m[2],
106
+ d: m[3],
107
+ e: m[4],
108
+ f: m[5],
109
+ }
110
+ : new DOMMatrix(m);
111
+ pattern.setTransform(matrix);
109
112
  }
110
113
  return pattern;
111
114
  }
@@ -270,17 +273,13 @@ export class Shape extends Node {
270
273
  const blurRadius = (applyShadow && this.shadowBlur()) || 0;
271
274
  const width = preWidth + blurRadius * 2;
272
275
  const height = preHeight + blurRadius * 2;
273
- let roundingOffset = 0;
274
- if (Math.round(strokeWidth / 2) !== strokeWidth / 2) {
275
- roundingOffset = 1;
276
- }
277
276
  const rect = {
278
- width: width + roundingOffset,
279
- height: height + roundingOffset,
280
- x: -Math.round(strokeWidth / 2 + blurRadius) +
277
+ width: width,
278
+ height: height,
279
+ x: -(strokeWidth / 2 + blurRadius) +
281
280
  Math.min(shadowOffsetX, 0) +
282
281
  fillRect.x,
283
- y: -Math.round(strokeWidth / 2 + blurRadius) +
282
+ y: -(strokeWidth / 2 + blurRadius) +
284
283
  Math.min(shadowOffsetY, 0) +
285
284
  fillRect.y,
286
285
  };
package/lib/index-node.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Konva } from './_FullInternals.js';
2
2
  import * as Canvas from 'canvas';
3
3
  const canvas = Canvas['default'] || Canvas;
4
+ global.DOMMatrix = canvas.DOMMatrix;
4
5
  const isNode = typeof global.document === 'undefined';
5
6
  if (isNode) {
6
7
  Konva.Util['createCanvasElement'] = () => {
package/lib/shapes/Arc.js CHANGED
@@ -31,17 +31,17 @@ export class Arc extends Shape {
31
31
  const angle = Konva.getAngle(clockwise ? 360 - this.angle() : this.angle());
32
32
  const boundLeftRatio = Math.cos(Math.min(angle, Math.PI));
33
33
  const boundRightRatio = 1;
34
- const boundTopRatio = Math.sin(Math.min(Math.max(Math.PI, angle), 3 * Math.PI / 2));
34
+ const boundTopRatio = Math.sin(Math.min(Math.max(Math.PI, angle), (3 * Math.PI) / 2));
35
35
  const boundBottomRatio = Math.sin(Math.min(angle, Math.PI / 2));
36
36
  const boundLeft = boundLeftRatio * (boundLeftRatio > 0 ? innerRadius : outerRadius);
37
37
  const boundRight = boundRightRatio * (boundRightRatio > 0 ? outerRadius : innerRadius);
38
38
  const boundTop = boundTopRatio * (boundTopRatio > 0 ? innerRadius : outerRadius);
39
39
  const boundBottom = boundBottomRatio * (boundBottomRatio > 0 ? outerRadius : innerRadius);
40
40
  return {
41
- x: Math.round(boundLeft),
42
- y: Math.round(clockwise ? -1 * boundBottom : boundTop),
43
- width: Math.round(boundRight - boundLeft),
44
- height: Math.round(boundBottom - boundTop)
41
+ x: boundLeft,
42
+ y: clockwise ? -1 * boundBottom : boundTop,
43
+ width: boundRight - boundLeft,
44
+ height: boundBottom - boundTop,
45
45
  };
46
46
  }
47
47
  }
@@ -9,8 +9,8 @@ export declare class Path extends Shape<PathConfig> {
9
9
  constructor(config?: PathConfig);
10
10
  _sceneFunc(context: any): void;
11
11
  getSelfRect(): {
12
- x: number;
13
- y: number;
12
+ x: any;
13
+ y: any;
14
14
  width: number;
15
15
  height: number;
16
16
  };
@@ -117,10 +117,10 @@ export class Path extends Shape {
117
117
  }
118
118
  }
119
119
  return {
120
- x: Math.round(minX),
121
- y: Math.round(minY),
122
- width: Math.round(maxX - minX),
123
- height: Math.round(maxY - minY),
120
+ x: minX,
121
+ y: minY,
122
+ width: maxX - minX,
123
+ height: maxY - minY,
124
124
  };
125
125
  }
126
126
  getLength() {
@@ -20,6 +20,7 @@ export declare class Text extends Shape<TextConfig> {
20
20
  textArr: Array<{
21
21
  text: string;
22
22
  width: number;
23
+ lastInParagraph: boolean;
23
24
  }>;
24
25
  _partialText: string;
25
26
  _partialTextX: number;
@@ -92,7 +92,7 @@ export class Text extends Shape {
92
92
  for (n = 0; n < textArrLen; n++) {
93
93
  var lineTranslateX = 0;
94
94
  var lineTranslateY = 0;
95
- var obj = textArr[n], text = obj.text, width = obj.width, lastLine = n !== textArrLen - 1, spacesNumber, oneWord, lineWidth;
95
+ var obj = textArr[n], text = obj.text, width = obj.width, lastLine = obj.lastInParagraph, spacesNumber, oneWord, lineWidth;
96
96
  context.save();
97
97
  if (align === RIGHT) {
98
98
  lineTranslateX += totalWidth - width - padding * 2;
@@ -137,7 +137,7 @@ export class Text extends Shape {
137
137
  var array = stringToArray(text);
138
138
  for (var li = 0; li < array.length; li++) {
139
139
  var letter = array[li];
140
- if (letter === ' ' && n !== textArrLen - 1 && align === JUSTIFY) {
140
+ if (letter === ' ' && !lastLine && align === JUSTIFY) {
141
141
  lineTranslateX += (totalWidth - padding * 2 - width) / spacesNumber;
142
142
  }
143
143
  this._partialTextX = lineTranslateX;
@@ -217,7 +217,11 @@ export class Text extends Shape {
217
217
  line = line.trim();
218
218
  }
219
219
  var width = this._getTextWidth(line);
220
- return this.textArr.push({ text: line, width: width });
220
+ return this.textArr.push({
221
+ text: line,
222
+ width: width,
223
+ lastInParagraph: false,
224
+ });
221
225
  }
222
226
  _getTextWidth(text) {
223
227
  var letterSpacing = this.letterSpacing();
@@ -310,6 +314,9 @@ export class Text extends Shape {
310
314
  if (fixedHeight && currentHeightPx + lineHeightPx > maxHeightPx) {
311
315
  break;
312
316
  }
317
+ if (this.textArr[this.textArr.length - 1]) {
318
+ this.textArr[this.textArr.length - 1].lastInParagraph = true;
319
+ }
313
320
  }
314
321
  this.textHeight = fontSize;
315
322
  this.textWidth = textWidth;
@@ -22,7 +22,7 @@ export class TextPath extends Shape {
22
22
  this.dataArray = Path.parsePathData(this.attrs.data);
23
23
  this._setTextData();
24
24
  });
25
- this.on('textChange.konva alignChange.konva letterSpacingChange.konva kerningFuncChange.konva fontSizeChange.konva', this._setTextData);
25
+ this.on('textChange.konva alignChange.konva letterSpacingChange.konva kerningFuncChange.konva fontSizeChange.konva fontFamilyChange.konva', this._setTextData);
26
26
  this._setTextData();
27
27
  }
28
28
  _sceneFunc(context) {
@@ -446,9 +446,9 @@ export class Transformer extends Group {
446
446
  x: pos.x - ap.x,
447
447
  y: pos.y - ap.y,
448
448
  };
449
- this._fire('transformstart', { evt: e, target: this.getNode() });
449
+ this._fire('transformstart', { evt: e.evt, target: this.getNode() });
450
450
  this._nodes.forEach((target) => {
451
- target._fire('transformstart', { evt: e, target });
451
+ target._fire('transformstart', { evt: e.evt, target });
452
452
  });
453
453
  }
454
454
  _handleMouseMove(e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "konva",
3
- "version": "8.3.2",
3
+ "version": "8.3.5",
4
4
  "author": "Anton Lavrenov",
5
5
  "files": [
6
6
  "README.md",
@@ -60,11 +60,11 @@
60
60
  }
61
61
  ],
62
62
  "devDependencies": {
63
- "@parcel/transformer-image": "2.0.0-beta.2",
64
- "@size-limit/preset-big-lib": "^5.0.4",
65
- "@types/mocha": "^9.0.0",
66
- "canvas": "^2.8.0",
67
- "chai": "4.3.4",
63
+ "@parcel/transformer-image": "2.3.2",
64
+ "@size-limit/preset-big-lib": "^7.0.8",
65
+ "@types/mocha": "^9.1.0",
66
+ "canvas": "^2.9.0",
67
+ "chai": "4.3.6",
68
68
  "filehound": "^1.17.5",
69
69
  "gulp": "^4.0.2",
70
70
  "gulp-concat": "^2.6.1",
@@ -77,18 +77,19 @@
77
77
  "gulp-uglify": "^3.0.2",
78
78
  "gulp-uglify-es": "^3.0.0",
79
79
  "gulp-util": "^3.0.8",
80
- "mocha": "8.4.0",
81
- "mocha-headless-chrome": "^3.1.0",
82
- "parcel": "2.0.0-beta.2",
83
- "rollup": "^2.57.0",
80
+ "mocha": "9.2.2",
81
+ "mocha-headless-chrome": "^4.0.0",
82
+ "parcel": "2.3.2",
83
+ "process": "^0.11.10",
84
+ "rollup": "^2.70.0",
84
85
  "rollup-plugin-commonjs": "^10.1.0",
85
86
  "rollup-plugin-node-resolve": "^5.2.0",
86
87
  "rollup-plugin-sourcemaps": "^0.6.3",
87
- "rollup-plugin-typescript2": "^0.30.0",
88
- "size-limit": "^5.0.4",
89
- "ts-mocha": "^8.0.0",
88
+ "rollup-plugin-typescript2": "^0.31.2",
89
+ "size-limit": "^7.0.8",
90
+ "ts-mocha": "^9.0.2",
90
91
  "ts-node": "^9.1.1",
91
- "typescript": "^4.4.3"
92
+ "typescript": "4.5.5"
92
93
  },
93
94
  "keywords": [
94
95
  "canvas",