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/cmj/Node.js CHANGED
@@ -102,13 +102,13 @@ class Node {
102
102
  relativeTo: this.getParent(),
103
103
  });
104
104
  }
105
- 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;
105
+ 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;
106
106
  if (!width || !height) {
107
107
  Util_1.Util.error('Can not cache the node. Width or height of the node equals 0. Caching is skipped.');
108
108
  return;
109
109
  }
110
- width += offset * 2;
111
- height += offset * 2;
110
+ width += offset * 2 + 1;
111
+ height += offset * 2 + 1;
112
112
  x -= offset;
113
113
  y -= offset;
114
114
  var cachedSceneCanvas = new Canvas_1.SceneCanvas({
@@ -936,11 +936,16 @@ class Node {
936
936
  _toKonvaCanvas(config) {
937
937
  config = config || {};
938
938
  var box = this.getClientRect();
939
- 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 Canvas_1.SceneCanvas({
940
- width: config.width || box.width || (stage ? stage.width() : 0),
941
- height: config.height || box.height || (stage ? stage.height() : 0),
939
+ 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 Canvas_1.SceneCanvas({
940
+ width: config.width || Math.ceil(box.width) || (stage ? stage.width() : 0),
941
+ height: config.height ||
942
+ Math.ceil(box.height) ||
943
+ (stage ? stage.height() : 0),
942
944
  pixelRatio: pixelRatio,
943
945
  }), context = canvas.getContext();
946
+ if (config.imageSmoothingEnabled === false) {
947
+ context._context.imageSmoothingEnabled = false;
948
+ }
944
949
  context.save();
945
950
  if (x || y) {
946
951
  context.translate(-1 * x, -1 * y);
package/cmj/Shape.js CHANGED
@@ -101,14 +101,17 @@ class Shape extends Node_1.Node {
101
101
  tr.scale(this.fillPatternScaleX(), this.fillPatternScaleY());
102
102
  tr.translate(-1 * this.fillPatternOffsetX(), -1 * this.fillPatternOffsetY());
103
103
  const m = tr.getMatrix();
104
- pattern.setTransform({
105
- a: m[0],
106
- b: m[1],
107
- c: m[2],
108
- d: m[3],
109
- e: m[4],
110
- f: m[5],
111
- });
104
+ const matrix = typeof DOMMatrix === 'undefined'
105
+ ? {
106
+ a: m[0],
107
+ b: m[1],
108
+ c: m[2],
109
+ d: m[3],
110
+ e: m[4],
111
+ f: m[5],
112
+ }
113
+ : new DOMMatrix(m);
114
+ pattern.setTransform(matrix);
112
115
  }
113
116
  return pattern;
114
117
  }
@@ -273,17 +276,13 @@ class Shape extends Node_1.Node {
273
276
  const blurRadius = (applyShadow && this.shadowBlur()) || 0;
274
277
  const width = preWidth + blurRadius * 2;
275
278
  const height = preHeight + blurRadius * 2;
276
- let roundingOffset = 0;
277
- if (Math.round(strokeWidth / 2) !== strokeWidth / 2) {
278
- roundingOffset = 1;
279
- }
280
279
  const rect = {
281
- width: width + roundingOffset,
282
- height: height + roundingOffset,
283
- x: -Math.round(strokeWidth / 2 + blurRadius) +
280
+ width: width,
281
+ height: height,
282
+ x: -(strokeWidth / 2 + blurRadius) +
284
283
  Math.min(shadowOffsetX, 0) +
285
284
  fillRect.x,
286
- y: -Math.round(strokeWidth / 2 + blurRadius) +
285
+ y: -(strokeWidth / 2 + blurRadius) +
287
286
  Math.min(shadowOffsetY, 0) +
288
287
  fillRect.y,
289
288
  };
package/cmj/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/cmj/Util.js CHANGED
@@ -109,10 +109,6 @@ class Transform {
109
109
  getMatrix() {
110
110
  return this.m;
111
111
  }
112
- setAbsolutePosition(x, y) {
113
- 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;
114
- return this.translate(xt, yt);
115
- }
116
112
  decompose() {
117
113
  var a = this.m[0];
118
114
  var b = this.m[1];
package/cmj/index-node.js CHANGED
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const _FullInternals_1 = require("./_FullInternals");
4
4
  const Canvas = require("canvas");
5
5
  const canvas = Canvas['default'] || Canvas;
6
+ global.DOMMatrix = canvas.DOMMatrix;
6
7
  const isNode = typeof global.document === 'undefined';
7
8
  if (isNode) {
8
9
  _FullInternals_1.Konva.Util['createCanvasElement'] = () => {
package/cmj/shapes/Arc.js CHANGED
@@ -34,17 +34,17 @@ class Arc extends Shape_1.Shape {
34
34
  const angle = Global_1.Konva.getAngle(clockwise ? 360 - this.angle() : this.angle());
35
35
  const boundLeftRatio = Math.cos(Math.min(angle, Math.PI));
36
36
  const boundRightRatio = 1;
37
- const boundTopRatio = Math.sin(Math.min(Math.max(Math.PI, angle), 3 * Math.PI / 2));
37
+ const boundTopRatio = Math.sin(Math.min(Math.max(Math.PI, angle), (3 * Math.PI) / 2));
38
38
  const boundBottomRatio = Math.sin(Math.min(angle, Math.PI / 2));
39
39
  const boundLeft = boundLeftRatio * (boundLeftRatio > 0 ? innerRadius : outerRadius);
40
40
  const boundRight = boundRightRatio * (boundRightRatio > 0 ? outerRadius : innerRadius);
41
41
  const boundTop = boundTopRatio * (boundTopRatio > 0 ? innerRadius : outerRadius);
42
42
  const boundBottom = boundBottomRatio * (boundBottomRatio > 0 ? outerRadius : innerRadius);
43
43
  return {
44
- x: Math.round(boundLeft),
45
- y: Math.round(clockwise ? -1 * boundBottom : boundTop),
46
- width: Math.round(boundRight - boundLeft),
47
- height: Math.round(boundBottom - boundTop)
44
+ x: boundLeft,
45
+ y: clockwise ? -1 * boundBottom : boundTop,
46
+ width: boundRight - boundLeft,
47
+ height: boundBottom - boundTop,
48
48
  };
49
49
  }
50
50
  }
@@ -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
  };
@@ -120,10 +120,10 @@ class Path extends Shape_1.Shape {
120
120
  }
121
121
  }
122
122
  return {
123
- x: Math.round(minX),
124
- y: Math.round(minY),
125
- width: Math.round(maxX - minX),
126
- height: Math.round(maxY - minY),
123
+ x: minX,
124
+ y: minY,
125
+ width: maxX - minX,
126
+ height: maxY - minY,
127
127
  };
128
128
  }
129
129
  getLength() {
@@ -25,7 +25,7 @@ class TextPath extends Shape_1.Shape {
25
25
  this.dataArray = Path_1.Path.parsePathData(this.attrs.data);
26
26
  this._setTextData();
27
27
  });
28
- this.on('textChange.konva alignChange.konva letterSpacingChange.konva kerningFuncChange.konva fontSizeChange.konva', this._setTextData);
28
+ this.on('textChange.konva alignChange.konva letterSpacingChange.konva kerningFuncChange.konva fontSizeChange.konva fontFamilyChange.konva', this._setTextData);
29
29
  this._setTextData();
30
30
  }
31
31
  _sceneFunc(context) {
@@ -449,9 +449,9 @@ class Transformer extends Group_1.Group {
449
449
  x: pos.x - ap.x,
450
450
  y: pos.y - ap.y,
451
451
  };
452
- this._fire('transformstart', { evt: e, target: this.getNode() });
452
+ this._fire('transformstart', { evt: e.evt, target: this.getNode() });
453
453
  this._nodes.forEach((target) => {
454
- target._fire('transformstart', { evt: e, target });
454
+ target._fire('transformstart', { evt: e.evt, target });
455
455
  });
456
456
  }
457
457
  _handleMouseMove(e) {
package/konva.js CHANGED
@@ -5,10 +5,10 @@
5
5
  })(this, (function () { 'use strict';
6
6
 
7
7
  /*
8
- * Konva JavaScript Framework v8.3.3
8
+ * Konva JavaScript Framework v8.3.6
9
9
  * http://konvajs.org/
10
10
  * Licensed under the MIT
11
- * Date: Wed Feb 23 2022
11
+ * Date: Wed Apr 27 2022
12
12
  *
13
13
  * Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
14
14
  * Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva)
@@ -35,7 +35,7 @@
35
35
  : {};
36
36
  const Konva$2 = {
37
37
  _global: glob,
38
- version: '8.3.3',
38
+ version: '8.3.6',
39
39
  isBrowser: detectBrowser(),
40
40
  isUnminified: /param/.test(function (param) { }.toString()),
41
41
  dblClickWindow: 400,
@@ -370,17 +370,6 @@
370
370
  getMatrix() {
371
371
  return this.m;
372
372
  }
373
- /**
374
- * set to absolute position via translation
375
- * @method
376
- * @name Konva.Transform#setAbsolutePosition
377
- * @returns {Konva.Transform}
378
- * @author ericdrowell
379
- */
380
- setAbsolutePosition(x, y) {
381
- 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;
382
- return this.translate(xt, yt);
383
- }
384
373
  /**
385
374
  * convert transformation matrix back into node's attributes
386
375
  * @method
@@ -2599,15 +2588,26 @@
2599
2588
  relativeTo: this.getParent(),
2600
2589
  });
2601
2590
  }
2602
- 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;
2591
+ 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;
2603
2592
  if (!width || !height) {
2604
2593
  Util.error('Can not cache the node. Width or height of the node equals 0. Caching is skipped.');
2605
2594
  return;
2606
2595
  }
2607
- width += offset * 2;
2608
- height += offset * 2;
2596
+ // let's just add 1 pixel extra,
2597
+ // because using Math.floor on x, y position may shift drawing
2598
+ width += offset * 2 + 1;
2599
+ height += offset * 2 + 1;
2609
2600
  x -= offset;
2610
2601
  y -= offset;
2602
+ // if (Math.floor(x) < x) {
2603
+ // x = Math.floor(x);
2604
+ // // width += 1;
2605
+ // }
2606
+ // if (Math.floor(y) < y) {
2607
+ // y = Math.floor(y);
2608
+ // // height += 1;
2609
+ // }
2610
+ // console.log({ x, y, width, height }, rect);
2611
2611
  var cachedSceneCanvas = new SceneCanvas({
2612
2612
  pixelRatio: pixelRatio,
2613
2613
  width: width,
@@ -3964,11 +3964,16 @@
3964
3964
  _toKonvaCanvas(config) {
3965
3965
  config = config || {};
3966
3966
  var box = this.getClientRect();
3967
- 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({
3968
- width: config.width || box.width || (stage ? stage.width() : 0),
3969
- height: config.height || box.height || (stage ? stage.height() : 0),
3967
+ 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({
3968
+ width: config.width || Math.ceil(box.width) || (stage ? stage.width() : 0),
3969
+ height: config.height ||
3970
+ Math.ceil(box.height) ||
3971
+ (stage ? stage.height() : 0),
3970
3972
  pixelRatio: pixelRatio,
3971
3973
  }), context = canvas.getContext();
3974
+ if (config.imageSmoothingEnabled === false) {
3975
+ context._context.imageSmoothingEnabled = false;
3976
+ }
3972
3977
  context.save();
3973
3978
  if (x || y) {
3974
3979
  context.translate(-1 * x, -1 * y);
@@ -3991,6 +3996,7 @@
3991
3996
  * You can use that property to increase quality of the image, for example for super hight quality exports
3992
3997
  * or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
3993
3998
  * If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.
3999
+ * @param {Boolean} [config.imageSmoothingEnabled] set this to false if you want to disable imageSmoothing
3994
4000
  * @example
3995
4001
  * var canvas = node.toCanvas();
3996
4002
  */
@@ -4017,6 +4023,7 @@
4017
4023
  * You can use that property to increase quality of the image, for example for super hight quality exports
4018
4024
  * or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
4019
4025
  * If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.
4026
+ * @param {Boolean} [config.imageSmoothingEnabled] set this to false if you want to disable imageSmoothing
4020
4027
  * @returns {String}
4021
4028
  */
4022
4029
  toDataURL(config) {
@@ -4049,6 +4056,7 @@
4049
4056
  * You can use that property to increase quality of the image, for example for super hight quality exports
4050
4057
  * or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
4051
4058
  * If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.
4059
+ * @param {Boolean} [config.imageSmoothingEnabled] set this to false if you want to disable imageSmoothing
4052
4060
  * @example
4053
4061
  * var image = node.toImage({
4054
4062
  * callback(img) {
@@ -6704,14 +6712,17 @@
6704
6712
  tr.scale(this.fillPatternScaleX(), this.fillPatternScaleY());
6705
6713
  tr.translate(-1 * this.fillPatternOffsetX(), -1 * this.fillPatternOffsetY());
6706
6714
  const m = tr.getMatrix();
6707
- pattern.setTransform({
6708
- a: m[0],
6709
- b: m[1],
6710
- c: m[2],
6711
- d: m[3],
6712
- e: m[4],
6713
- f: m[5], // Vertical translation (moving).
6714
- });
6715
+ const matrix = typeof DOMMatrix === 'undefined'
6716
+ ? {
6717
+ a: m[0],
6718
+ b: m[1],
6719
+ c: m[2],
6720
+ d: m[3],
6721
+ e: m[4],
6722
+ f: m[5], // Vertical translation (moving).
6723
+ }
6724
+ : new DOMMatrix(m);
6725
+ pattern.setTransform(matrix);
6715
6726
  }
6716
6727
  return pattern;
6717
6728
  }
@@ -6933,20 +6944,13 @@
6933
6944
  const blurRadius = (applyShadow && this.shadowBlur()) || 0;
6934
6945
  const width = preWidth + blurRadius * 2;
6935
6946
  const height = preHeight + blurRadius * 2;
6936
- // if stroke, for example = 3
6937
- // we need to set x to 1.5, but after Math.round it will be 2
6938
- // as we have additional offset we need to increase width and height by 1 pixel
6939
- let roundingOffset = 0;
6940
- if (Math.round(strokeWidth / 2) !== strokeWidth / 2) {
6941
- roundingOffset = 1;
6942
- }
6943
6947
  const rect = {
6944
- width: width + roundingOffset,
6945
- height: height + roundingOffset,
6946
- x: -Math.round(strokeWidth / 2 + blurRadius) +
6948
+ width: width,
6949
+ height: height,
6950
+ x: -(strokeWidth / 2 + blurRadius) +
6947
6951
  Math.min(shadowOffsetX, 0) +
6948
6952
  fillRect.x,
6949
- y: -Math.round(strokeWidth / 2 + blurRadius) +
6953
+ y: -(strokeWidth / 2 + blurRadius) +
6950
6954
  Math.min(shadowOffsetY, 0) +
6951
6955
  fillRect.y,
6952
6956
  };
@@ -9732,17 +9736,17 @@
9732
9736
  const angle = Konva$2.getAngle(clockwise ? 360 - this.angle() : this.angle());
9733
9737
  const boundLeftRatio = Math.cos(Math.min(angle, Math.PI));
9734
9738
  const boundRightRatio = 1;
9735
- const boundTopRatio = Math.sin(Math.min(Math.max(Math.PI, angle), 3 * Math.PI / 2));
9739
+ const boundTopRatio = Math.sin(Math.min(Math.max(Math.PI, angle), (3 * Math.PI) / 2));
9736
9740
  const boundBottomRatio = Math.sin(Math.min(angle, Math.PI / 2));
9737
9741
  const boundLeft = boundLeftRatio * (boundLeftRatio > 0 ? innerRadius : outerRadius);
9738
9742
  const boundRight = boundRightRatio * (outerRadius );
9739
9743
  const boundTop = boundTopRatio * (boundTopRatio > 0 ? innerRadius : outerRadius);
9740
9744
  const boundBottom = boundBottomRatio * (boundBottomRatio > 0 ? outerRadius : innerRadius);
9741
9745
  return {
9742
- x: Math.round(boundLeft),
9743
- y: Math.round(clockwise ? -1 * boundBottom : boundTop),
9744
- width: Math.round(boundRight - boundLeft),
9745
- height: Math.round(boundBottom - boundTop)
9746
+ x: boundLeft,
9747
+ y: clockwise ? -1 * boundBottom : boundTop,
9748
+ width: boundRight - boundLeft,
9749
+ height: boundBottom - boundTop,
9746
9750
  };
9747
9751
  }
9748
9752
  }
@@ -10341,10 +10345,10 @@
10341
10345
  }
10342
10346
  }
10343
10347
  return {
10344
- x: Math.round(minX),
10345
- y: Math.round(minY),
10346
- width: Math.round(maxX - minX),
10347
- height: Math.round(maxY - minY),
10348
+ x: minX,
10349
+ y: minY,
10350
+ width: maxX - minX,
10351
+ height: maxY - minY,
10348
10352
  };
10349
10353
  }
10350
10354
  /**
@@ -13964,7 +13968,7 @@
13964
13968
  this._setTextData();
13965
13969
  });
13966
13970
  // update text data for certain attr changes
13967
- this.on('textChange.konva alignChange.konva letterSpacingChange.konva kerningFuncChange.konva fontSizeChange.konva', this._setTextData);
13971
+ this.on('textChange.konva alignChange.konva letterSpacingChange.konva kerningFuncChange.konva fontSizeChange.konva fontFamilyChange.konva', this._setTextData);
13968
13972
  this._setTextData();
13969
13973
  }
13970
13974
  _sceneFunc(context) {
@@ -14386,10 +14390,10 @@
14386
14390
  * @param {Number} letterSpacing
14387
14391
  * @returns {Number}
14388
14392
  * @example
14389
- * // get line height
14393
+ * // get letter spacing value
14390
14394
  * var letterSpacing = shape.letterSpacing();
14391
14395
  *
14392
- * // set the line height
14396
+ * // set the letter spacing value
14393
14397
  * shape.letterSpacing(2);
14394
14398
  */
14395
14399
  Factory.addGetterSetter(TextPath, 'letterSpacing', 0, getNumberValidator());
@@ -14400,10 +14404,10 @@
14400
14404
  * @param {String} textBaseline
14401
14405
  * @returns {String}
14402
14406
  * @example
14403
- * // get line height
14407
+ * // get current text baseline
14404
14408
  * var textBaseline = shape.textBaseline();
14405
14409
  *
14406
- * // set the line height
14410
+ * // set new text baseline
14407
14411
  * shape.textBaseline('top');
14408
14412
  */
14409
14413
  Factory.addGetterSetter(TextPath, 'textBaseline', 'middle');
@@ -15001,9 +15005,9 @@
15001
15005
  x: pos.x - ap.x,
15002
15006
  y: pos.y - ap.y,
15003
15007
  };
15004
- this._fire('transformstart', { evt: e, target: this.getNode() });
15008
+ this._fire('transformstart', { evt: e.evt, target: this.getNode() });
15005
15009
  this._nodes.forEach((target) => {
15006
- target._fire('transformstart', { evt: e, target });
15010
+ target._fire('transformstart', { evt: e.evt, target });
15007
15011
  });
15008
15012
  }
15009
15013
  _handleMouseMove(e) {