konva 9.2.3 → 9.3.1

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/konva.js CHANGED
@@ -5,10 +5,10 @@
5
5
  })(this, (function () { 'use strict';
6
6
 
7
7
  /*
8
- * Konva JavaScript Framework v9.2.3
8
+ * Konva JavaScript Framework v9.3.1
9
9
  * http://konvajs.org/
10
10
  * Licensed under the MIT
11
- * Date: Tue Oct 31 2023
11
+ * Date: Wed Jan 17 2024
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: '9.2.3',
38
+ version: '9.3.1',
39
39
  isBrowser: detectBrowser(),
40
40
  isUnminified: /param/.test(function (param) { }.toString()),
41
41
  dblClickWindow: 400,
@@ -1467,6 +1467,7 @@
1467
1467
  'putImageData',
1468
1468
  'quadraticCurveTo',
1469
1469
  'rect',
1470
+ 'roundRect',
1470
1471
  'restore',
1471
1472
  'rotate',
1472
1473
  'save',
@@ -1878,6 +1879,14 @@
1878
1879
  rect(x, y, width, height) {
1879
1880
  this._context.rect(x, y, width, height);
1880
1881
  }
1882
+ /**
1883
+ * roundRect function.
1884
+ * @method
1885
+ * @name Konva.Context#roundRect
1886
+ */
1887
+ roundRect(x, y, width, height, radii) {
1888
+ this._context.roundRect(x, y, width, height, radii);
1889
+ }
1881
1890
  /**
1882
1891
  * putImageData function.
1883
1892
  * @method
@@ -2696,10 +2705,13 @@
2696
2705
  Util.error('Can not cache the node. Width or height of the node equals 0. Caching is skipped.');
2697
2706
  return;
2698
2707
  }
2699
- // let's just add 1 pixel extra,
2700
2708
  // because using Math.floor on x, y position may shift drawing
2701
- width += offset * 2 + 1;
2702
- height += offset * 2 + 1;
2709
+ // to avoid shift we need to increase size
2710
+ // but we better to avoid it, for better filters flows
2711
+ const extraPaddingX = Math.abs(Math.round(rect.x) - x) > 0.5 ? 1 : 0;
2712
+ const extraPaddingY = Math.abs(Math.round(rect.y) - y) > 0.5 ? 1 : 0;
2713
+ width += offset * 2 + extraPaddingX;
2714
+ height += offset * 2 + extraPaddingY;
2703
2715
  x -= offset;
2704
2716
  y -= offset;
2705
2717
  // if (Math.floor(x) < x) {
@@ -3160,7 +3172,7 @@
3160
3172
  * @returns {Object}
3161
3173
  */
3162
3174
  getAttrs() {
3163
- return this.attrs || {};
3175
+ return (this.attrs || {});
3164
3176
  }
3165
3177
  /**
3166
3178
  * set multiple attrs at once using an object literal
@@ -3688,8 +3700,11 @@
3688
3700
  * @returns {Object}
3689
3701
  */
3690
3702
  toObject() {
3691
- var obj = {}, attrs = this.getAttrs(), key, val, getter, defaultValue, nonPlainObject;
3692
- obj.attrs = {};
3703
+ var attrs = this.getAttrs(), key, val, getter, defaultValue, nonPlainObject;
3704
+ const obj = {
3705
+ attrs: {},
3706
+ className: this.getClassName(),
3707
+ };
3693
3708
  for (key in attrs) {
3694
3709
  val = attrs[key];
3695
3710
  // if value is object and object is not plain
@@ -3709,7 +3724,6 @@
3709
3724
  obj.attrs[key] = val;
3710
3725
  }
3711
3726
  }
3712
- obj.className = this.getClassName();
3713
3727
  return Util._prepareToStringify(obj);
3714
3728
  }
3715
3729
  /**
@@ -4076,6 +4090,11 @@
4076
4090
  (stage ? stage.height() : 0),
4077
4091
  pixelRatio: pixelRatio,
4078
4092
  }), context = canvas.getContext();
4093
+ const bufferCanvas = new SceneCanvas({
4094
+ width: canvas.width,
4095
+ height: canvas.height,
4096
+ pixelRatio: canvas.pixelRatio,
4097
+ });
4079
4098
  if (config.imageSmoothingEnabled === false) {
4080
4099
  context._context.imageSmoothingEnabled = false;
4081
4100
  }
@@ -4083,7 +4102,7 @@
4083
4102
  if (x || y) {
4084
4103
  context.translate(-1 * x, -1 * y);
4085
4104
  }
4086
- this.drawScene(canvas);
4105
+ this.drawScene(canvas, undefined, bufferCanvas);
4087
4106
  context.restore();
4088
4107
  return canvas;
4089
4108
  }
@@ -4217,7 +4236,7 @@
4217
4236
  this.toCanvas(config).toBlob((blob) => {
4218
4237
  resolve(blob);
4219
4238
  callback === null || callback === void 0 ? void 0 : callback(blob);
4220
- });
4239
+ }, config === null || config === void 0 ? void 0 : config.mimeType, config === null || config === void 0 ? void 0 : config.quality);
4221
4240
  }
4222
4241
  catch (err) {
4223
4242
  reject(err);
@@ -5570,7 +5589,7 @@
5570
5589
  });
5571
5590
  this._requestDraw();
5572
5591
  }
5573
- drawScene(can, top) {
5592
+ drawScene(can, top, bufferCanvas) {
5574
5593
  var layer = this.getLayer(), canvas = can || (layer && layer.getCanvas()), context = canvas && canvas.getContext(), cachedCanvas = this._getCanvasCache(), cachedSceneCanvas = cachedCanvas && cachedCanvas.scene;
5575
5594
  var caching = canvas && canvas.isCache;
5576
5595
  if (!this.isVisible() && !caching) {
@@ -5584,7 +5603,7 @@
5584
5603
  context.restore();
5585
5604
  }
5586
5605
  else {
5587
- this._drawChildren('drawScene', canvas, top);
5606
+ this._drawChildren('drawScene', canvas, top, bufferCanvas);
5588
5607
  }
5589
5608
  return this;
5590
5609
  }
@@ -5605,7 +5624,7 @@
5605
5624
  }
5606
5625
  return this;
5607
5626
  }
5608
- _drawChildren(drawMethod, canvas, top) {
5627
+ _drawChildren(drawMethod, canvas, top, bufferCanvas) {
5609
5628
  var _a;
5610
5629
  var context = canvas && canvas.getContext(), clipWidth = this.clipWidth(), clipHeight = this.clipHeight(), clipFunc = this.clipFunc(), hasClip = (clipWidth && clipHeight) || clipFunc;
5611
5630
  const selfCache = top === this;
@@ -5636,7 +5655,7 @@
5636
5655
  context._applyGlobalCompositeOperation(this);
5637
5656
  }
5638
5657
  (_a = this.children) === null || _a === void 0 ? void 0 : _a.forEach(function (child) {
5639
- child[drawMethod](canvas, top);
5658
+ child[drawMethod](canvas, top, bufferCanvas);
5640
5659
  });
5641
5660
  if (hasComposition) {
5642
5661
  context.restore();
@@ -6887,11 +6906,11 @@
6887
6906
  const m = tr.getMatrix();
6888
6907
  const matrix = typeof DOMMatrix === 'undefined'
6889
6908
  ? {
6890
- a: m[0],
6891
- b: m[1],
6892
- c: m[2],
6909
+ a: m[0], // Horizontal scaling. A value of 1 results in no scaling.
6910
+ b: m[1], // Vertical skewing.
6911
+ c: m[2], // Horizontal skewing.
6893
6912
  d: m[3],
6894
- e: m[4],
6913
+ e: m[4], // Horizontal translation (moving).
6895
6914
  f: m[5], // Vertical translation (moving).
6896
6915
  }
6897
6916
  : new DOMMatrix(m);
@@ -7048,10 +7067,6 @@
7048
7067
  // so they use that method with forced fill
7049
7068
  // it probably will be simpler, then copy/paste the code
7050
7069
  var _a;
7051
- // buffer canvas is available only inside the stage
7052
- if (!this.getStage()) {
7053
- return false;
7054
- }
7055
7070
  // force skip buffer canvas
7056
7071
  const perfectDrawEnabled = (_a = this.attrs.perfectDrawEnabled) !== null && _a !== void 0 ? _a : true;
7057
7072
  if (!perfectDrawEnabled) {
@@ -7139,13 +7154,13 @@
7139
7154
  }
7140
7155
  return rect;
7141
7156
  }
7142
- drawScene(can, top) {
7157
+ drawScene(can, top, bufferCanvas) {
7143
7158
  // basically there are 3 drawing modes
7144
7159
  // 1 - simple drawing when nothing is cached.
7145
7160
  // 2 - when we are caching current
7146
7161
  // 3 - when node is cached and we need to draw it into layer
7147
7162
  var layer = this.getLayer();
7148
- var canvas = can || layer.getCanvas(), context = canvas.getContext(), cachedCanvas = this._getCanvasCache(), drawFunc = this.getSceneFunc(), hasShadow = this.hasShadow(), stage, bufferCanvas, bufferContext;
7163
+ var canvas = can || layer.getCanvas(), context = canvas.getContext(), cachedCanvas = this._getCanvasCache(), drawFunc = this.getSceneFunc(), hasShadow = this.hasShadow(), stage, bufferContext;
7149
7164
  var skipBuffer = canvas.isCache;
7150
7165
  var cachingSelf = top === this;
7151
7166
  if (!this.isVisible() && !cachingSelf) {
@@ -7167,8 +7182,8 @@
7167
7182
  // if buffer canvas is needed
7168
7183
  if (this._useBufferCanvas() && !skipBuffer) {
7169
7184
  stage = this.getStage();
7170
- bufferCanvas = stage.bufferCanvas;
7171
- bufferContext = bufferCanvas.getContext();
7185
+ const bc = bufferCanvas || stage.bufferCanvas;
7186
+ bufferContext = bc.getContext();
7172
7187
  bufferContext.clear();
7173
7188
  bufferContext.save();
7174
7189
  bufferContext._applyLineJoin(this);
@@ -7177,13 +7192,13 @@
7177
7192
  bufferContext.transform(o[0], o[1], o[2], o[3], o[4], o[5]);
7178
7193
  drawFunc.call(this, bufferContext, this);
7179
7194
  bufferContext.restore();
7180
- var ratio = bufferCanvas.pixelRatio;
7195
+ var ratio = bc.pixelRatio;
7181
7196
  if (hasShadow) {
7182
7197
  context._applyShadow(this);
7183
7198
  }
7184
7199
  context._applyOpacity(this);
7185
7200
  context._applyGlobalCompositeOperation(this);
7186
- context.drawImage(bufferCanvas._canvas, 0, 0, bufferCanvas.width / ratio, bufferCanvas.height / ratio);
7201
+ context.drawImage(bc._canvas, 0, 0, bc.width / ratio, bc.height / ratio);
7187
7202
  }
7188
7203
  else {
7189
7204
  context._applyLineJoin(this);
@@ -8317,10 +8332,10 @@
8317
8332
  * 8 - 7 - 6
8318
8333
  */
8319
8334
  INTERSECTION_OFFSETS = [
8320
- { x: 0, y: 0 },
8321
- { x: -1, y: -1 },
8322
- { x: 1, y: -1 },
8323
- { x: 1, y: 1 },
8335
+ { x: 0, y: 0 }, // 0
8336
+ { x: -1, y: -1 }, // 2
8337
+ { x: 1, y: -1 }, // 4
8338
+ { x: 1, y: 1 }, // 6
8324
8339
  { x: -1, y: 1 }, // 8
8325
8340
  ], INTERSECTION_OFFSETS_LEN = INTERSECTION_OFFSETS.length;
8326
8341
  /**
@@ -15566,6 +15581,7 @@
15566
15581
  * @param {Object} config
15567
15582
  * @param {Boolean} [config.resizeEnabled] Default is true
15568
15583
  * @param {Boolean} [config.rotateEnabled] Default is true
15584
+ * @param {Boolean} [config.rotateLineVisible] Default is true
15569
15585
  * @param {Array} [config.rotationSnaps] Array of angles for rotation snaps. Default is []
15570
15586
  * @param {Number} [config.rotationSnapTolerance] Snapping tolerance. If closer than this it will snap. Default is 5
15571
15587
  * @param {Number} [config.rotateAnchorOffset] Default is 50
@@ -15927,7 +15943,7 @@
15927
15943
  ctx.beginPath();
15928
15944
  ctx.rect(-padding, -padding, shape.width() + padding * 2, shape.height() + padding * 2);
15929
15945
  ctx.moveTo(shape.width() / 2, -padding);
15930
- if (tr.rotateEnabled()) {
15946
+ if (tr.rotateEnabled() && tr.rotateLineVisible()) {
15931
15947
  ctx.lineTo(shape.width() / 2, -tr.rotateAnchorOffset() * Util._sign(shape.height()) - padding);
15932
15948
  }
15933
15949
  ctx.fillStrokeShape(shape);
@@ -16585,6 +16601,20 @@
16585
16601
  * transformer.rotateEnabled(false);
16586
16602
  */
16587
16603
  Factory.addGetterSetter(Transformer, 'rotateEnabled', true);
16604
+ /**
16605
+ * get/set visibility of a little line that connects transformer and rotate anchor.
16606
+ * @name Konva.Transformer#rotateLineVisible
16607
+ * @method
16608
+ * @param {Boolean} enabled
16609
+ * @returns {Boolean}
16610
+ * @example
16611
+ * // get
16612
+ * var rotateLineVisible = transformer.rotateLineVisible();
16613
+ *
16614
+ * // set
16615
+ * transformer.rotateLineVisible(false);
16616
+ */
16617
+ Factory.addGetterSetter(Transformer, 'rotateLineVisible', true);
16588
16618
  /**
16589
16619
  * get/set rotation snaps angles.
16590
16620
  * @name Konva.Transformer#rotationSnaps