konva 9.3.0 → 9.3.2

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.3.0
8
+ * Konva JavaScript Framework v9.3.2
9
9
  * http://konvajs.org/
10
10
  * Licensed under the MIT
11
- * Date: Wed Dec 20 2023
11
+ * Date: Fri Jan 26 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.3.0',
38
+ version: '9.3.2',
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,13 @@
4076
4090
  (stage ? stage.height() : 0),
4077
4091
  pixelRatio: pixelRatio,
4078
4092
  }), context = canvas.getContext();
4093
+ const bufferCanvas = new SceneCanvas({
4094
+ // width and height already multiplied by pixelRatio
4095
+ // so we need to revert that
4096
+ width: canvas.width / canvas.pixelRatio,
4097
+ height: canvas.height / canvas.pixelRatio,
4098
+ pixelRatio: canvas.pixelRatio,
4099
+ });
4079
4100
  if (config.imageSmoothingEnabled === false) {
4080
4101
  context._context.imageSmoothingEnabled = false;
4081
4102
  }
@@ -4083,7 +4104,7 @@
4083
4104
  if (x || y) {
4084
4105
  context.translate(-1 * x, -1 * y);
4085
4106
  }
4086
- this.drawScene(canvas);
4107
+ this.drawScene(canvas, undefined, bufferCanvas);
4087
4108
  context.restore();
4088
4109
  return canvas;
4089
4110
  }
@@ -5570,7 +5591,7 @@
5570
5591
  });
5571
5592
  this._requestDraw();
5572
5593
  }
5573
- drawScene(can, top) {
5594
+ drawScene(can, top, bufferCanvas) {
5574
5595
  var layer = this.getLayer(), canvas = can || (layer && layer.getCanvas()), context = canvas && canvas.getContext(), cachedCanvas = this._getCanvasCache(), cachedSceneCanvas = cachedCanvas && cachedCanvas.scene;
5575
5596
  var caching = canvas && canvas.isCache;
5576
5597
  if (!this.isVisible() && !caching) {
@@ -5584,7 +5605,7 @@
5584
5605
  context.restore();
5585
5606
  }
5586
5607
  else {
5587
- this._drawChildren('drawScene', canvas, top);
5608
+ this._drawChildren('drawScene', canvas, top, bufferCanvas);
5588
5609
  }
5589
5610
  return this;
5590
5611
  }
@@ -5605,7 +5626,7 @@
5605
5626
  }
5606
5627
  return this;
5607
5628
  }
5608
- _drawChildren(drawMethod, canvas, top) {
5629
+ _drawChildren(drawMethod, canvas, top, bufferCanvas) {
5609
5630
  var _a;
5610
5631
  var context = canvas && canvas.getContext(), clipWidth = this.clipWidth(), clipHeight = this.clipHeight(), clipFunc = this.clipFunc(), hasClip = (clipWidth && clipHeight) || clipFunc;
5611
5632
  const selfCache = top === this;
@@ -5636,7 +5657,7 @@
5636
5657
  context._applyGlobalCompositeOperation(this);
5637
5658
  }
5638
5659
  (_a = this.children) === null || _a === void 0 ? void 0 : _a.forEach(function (child) {
5639
- child[drawMethod](canvas, top);
5660
+ child[drawMethod](canvas, top, bufferCanvas);
5640
5661
  });
5641
5662
  if (hasComposition) {
5642
5663
  context.restore();
@@ -7048,10 +7069,6 @@
7048
7069
  // so they use that method with forced fill
7049
7070
  // it probably will be simpler, then copy/paste the code
7050
7071
  var _a;
7051
- // buffer canvas is available only inside the stage
7052
- if (!this.getStage()) {
7053
- return false;
7054
- }
7055
7072
  // force skip buffer canvas
7056
7073
  const perfectDrawEnabled = (_a = this.attrs.perfectDrawEnabled) !== null && _a !== void 0 ? _a : true;
7057
7074
  if (!perfectDrawEnabled) {
@@ -7139,13 +7156,13 @@
7139
7156
  }
7140
7157
  return rect;
7141
7158
  }
7142
- drawScene(can, top) {
7159
+ drawScene(can, top, bufferCanvas) {
7143
7160
  // basically there are 3 drawing modes
7144
7161
  // 1 - simple drawing when nothing is cached.
7145
7162
  // 2 - when we are caching current
7146
7163
  // 3 - when node is cached and we need to draw it into layer
7147
7164
  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;
7165
+ var canvas = can || layer.getCanvas(), context = canvas.getContext(), cachedCanvas = this._getCanvasCache(), drawFunc = this.getSceneFunc(), hasShadow = this.hasShadow(), stage, bufferContext;
7149
7166
  var skipBuffer = canvas.isCache;
7150
7167
  var cachingSelf = top === this;
7151
7168
  if (!this.isVisible() && !cachingSelf) {
@@ -7167,8 +7184,8 @@
7167
7184
  // if buffer canvas is needed
7168
7185
  if (this._useBufferCanvas() && !skipBuffer) {
7169
7186
  stage = this.getStage();
7170
- bufferCanvas = stage.bufferCanvas;
7171
- bufferContext = bufferCanvas.getContext();
7187
+ const bc = bufferCanvas || stage.bufferCanvas;
7188
+ bufferContext = bc.getContext();
7172
7189
  bufferContext.clear();
7173
7190
  bufferContext.save();
7174
7191
  bufferContext._applyLineJoin(this);
@@ -7177,13 +7194,13 @@
7177
7194
  bufferContext.transform(o[0], o[1], o[2], o[3], o[4], o[5]);
7178
7195
  drawFunc.call(this, bufferContext, this);
7179
7196
  bufferContext.restore();
7180
- var ratio = bufferCanvas.pixelRatio;
7197
+ var ratio = bc.pixelRatio;
7181
7198
  if (hasShadow) {
7182
7199
  context._applyShadow(this);
7183
7200
  }
7184
7201
  context._applyOpacity(this);
7185
7202
  context._applyGlobalCompositeOperation(this);
7186
- context.drawImage(bufferCanvas._canvas, 0, 0, bufferCanvas.width / ratio, bufferCanvas.height / ratio);
7203
+ context.drawImage(bc._canvas, 0, 0, bc.width / ratio, bc.height / ratio);
7187
7204
  }
7188
7205
  else {
7189
7206
  context._applyLineJoin(this);