konva 8.3.3 → 8.3.6

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.3',
16
+ version: '8.3.6',
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,11 +933,16 @@ 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();
943
+ if (config.imageSmoothingEnabled === false) {
944
+ context._context.imageSmoothingEnabled = false;
945
+ }
941
946
  context.save();
942
947
  if (x || y) {
943
948
  context.translate(-1 * x, -1 * y);
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/Util.d.ts CHANGED
@@ -21,7 +21,6 @@ export declare class Transform {
21
21
  multiply(matrix: Transform): this;
22
22
  invert(): this;
23
23
  getMatrix(): number[];
24
- setAbsolutePosition(x: number, y: number): this;
25
24
  decompose(): {
26
25
  x: number;
27
26
  y: number;
package/lib/Util.js CHANGED
@@ -106,10 +106,6 @@ export class Transform {
106
106
  getMatrix() {
107
107
  return this.m;
108
108
  }
109
- setAbsolutePosition(x, y) {
110
- var m0 = this.m[0], m1 = this.m[1], m2 = this.m[2], m3 = this.m[3], m4 = this.m[4], m5 = this.m[5], yt = (m0 * (y - m5) - m1 * (x - m4)) / (m0 * m3 - m1 * m2), xt = (x - m4 - m2 * yt) / m0;
111
- return this.translate(xt, yt);
112
- }
113
109
  decompose() {
114
110
  var a = this.m[0];
115
111
  var b = this.m[1];
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() {
@@ -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.3",
3
+ "version": "8.3.6",
4
4
  "author": "Anton Lavrenov",
5
5
  "files": [
6
6
  "README.md",
@@ -9,10 +9,38 @@
9
9
  "lib",
10
10
  "cmj"
11
11
  ],
12
- "main": "./lib/index-node.js",
12
+ "main": "./cmj/index-node.js",
13
13
  "browser": "./lib/index.js",
14
14
  "typings": "./lib/index-types.d.ts",
15
15
  "type": "module",
16
+ "exports": {
17
+ ".": {
18
+ "node": {
19
+ "require": "./cmj/index-node.js",
20
+ "import": "./lib/index-node.js",
21
+ "default": "./lib/index-node.js"
22
+ },
23
+ "require": "./cmj/index.js",
24
+ "import": "./lib/index.js",
25
+ "default": "./lib/index.js"
26
+ },
27
+ "./cmj": {
28
+ "import": "./lib/index.js",
29
+ "require": "./cmj/index-node.js",
30
+ "node": "./cmj/index-node.js",
31
+ "default": "./cmj/index.js"
32
+ },
33
+ "./cmj/*": {
34
+ "import": "./lib/*.js",
35
+ "require": "./cmj/*.js",
36
+ "default": "./cmj/*.js"
37
+ },
38
+ "./lib/*": {
39
+ "import": "./lib/*.js",
40
+ "require": "./cmj/*.js",
41
+ "default": "./lib/*.js"
42
+ }
43
+ },
16
44
  "scripts": {
17
45
  "start": "npm run test:watch",
18
46
  "compile": "npm run clean && npm run tsc && cp ./src/index-types.d.ts ./lib/index-types.d.ts && npm run rollup && cp ./package-cmj.json ./cmj/package.json && cp ./src/index-types.d.ts ./cmj/index-types.d.ts",
@@ -60,12 +88,12 @@
60
88
  }
61
89
  ],
62
90
  "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",
68
- "filehound": "^1.17.5",
91
+ "@parcel/transformer-image": "2.5.0",
92
+ "@size-limit/preset-big-lib": "^7.0.8",
93
+ "@types/mocha": "^9.1.1",
94
+ "canvas": "^2.9.1",
95
+ "chai": "4.3.6",
96
+ "filehound": "^1.17.6",
69
97
  "gulp": "^4.0.2",
70
98
  "gulp-concat": "^2.6.1",
71
99
  "gulp-connect": "^5.7.0",
@@ -77,18 +105,19 @@
77
105
  "gulp-uglify": "^3.0.2",
78
106
  "gulp-uglify-es": "^3.0.0",
79
107
  "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",
108
+ "mocha": "9.2.2",
109
+ "mocha-headless-chrome": "^4.0.0",
110
+ "parcel": "2.5.0",
111
+ "process": "^0.11.10",
112
+ "rollup": "^2.70.2",
84
113
  "rollup-plugin-commonjs": "^10.1.0",
85
114
  "rollup-plugin-node-resolve": "^5.2.0",
86
115
  "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",
116
+ "rollup-plugin-typescript2": "^0.31.2",
117
+ "size-limit": "^7.0.8",
118
+ "ts-mocha": "^9.0.2",
90
119
  "ts-node": "^9.1.1",
91
- "typescript": "^4.4.3"
120
+ "typescript": "4.6.3"
92
121
  },
93
122
  "keywords": [
94
123
  "canvas",