konva 8.3.11 → 8.3.13

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/Context.d.ts CHANGED
@@ -60,6 +60,7 @@ export declare class Context {
60
60
  _applyGlobalCompositeOperation(node: any): void;
61
61
  }
62
62
  export declare class SceneContext extends Context {
63
+ constructor(canvas: Canvas);
63
64
  _fillColor(shape: Shape): void;
64
65
  _fillPattern(shape: any): void;
65
66
  _fillLinearGradient(shape: any): void;
@@ -70,6 +71,7 @@ export declare class SceneContext extends Context {
70
71
  _applyShadow(shape: any): void;
71
72
  }
72
73
  export declare class HitContext extends Context {
74
+ constructor(canvas: Canvas);
73
75
  _fill(shape: any): void;
74
76
  strokeShape(shape: Shape): void;
75
77
  _stroke(shape: any): void;
package/cmj/Context.js CHANGED
@@ -73,7 +73,6 @@ const traceArrMax = 100;
73
73
  class Context {
74
74
  constructor(canvas) {
75
75
  this.canvas = canvas;
76
- this._context = canvas._canvas.getContext('2d');
77
76
  if (Global_1.Konva.enableTrace) {
78
77
  this.traceArr = [];
79
78
  this._enableTrace();
@@ -382,6 +381,10 @@ CONTEXT_PROPERTIES.forEach(function (prop) {
382
381
  });
383
382
  });
384
383
  class SceneContext extends Context {
384
+ constructor(canvas) {
385
+ super(canvas);
386
+ this._context = canvas._canvas.getContext('2d');
387
+ }
385
388
  _fillColor(shape) {
386
389
  var fill = shape.fill();
387
390
  this.setAttr('fillStyle', fill);
@@ -492,6 +495,12 @@ class SceneContext extends Context {
492
495
  }
493
496
  exports.SceneContext = SceneContext;
494
497
  class HitContext extends Context {
498
+ constructor(canvas) {
499
+ super(canvas);
500
+ this._context = canvas._canvas.getContext('2d', {
501
+ willReadFrequently: true,
502
+ });
503
+ }
495
504
  _fill(shape) {
496
505
  this.save();
497
506
  this.setAttr('fillStyle', shape.colorKey);
package/cmj/Factory.d.ts CHANGED
@@ -3,7 +3,7 @@ export declare const Factory: {
3
3
  addGetter(constructor: any, attr: any, def?: any): void;
4
4
  addSetter(constructor: any, attr: any, validator?: any, after?: any): void;
5
5
  overWriteSetter(constructor: any, attr: any, validator?: any, after?: any): void;
6
- addComponentsGetterSetter(constructor: any, attr: any, components: any, validator?: any, after?: any): void;
6
+ addComponentsGetterSetter(constructor: any, attr: string, components: Array<string>, validator?: Function, after?: Function): void;
7
7
  addOverloadedGetterSetter(constructor: any, attr: any): void;
8
8
  addDeprecatedGetterSetter(constructor: any, attr: any, def: any, validator: any): void;
9
9
  backCompat(constructor: any, methods: any): void;
package/cmj/Factory.js CHANGED
@@ -63,6 +63,11 @@ exports.Factory = {
63
63
  }
64
64
  this._setAttr(attr + capitalize(key), val[key]);
65
65
  }
66
+ if (!val) {
67
+ components.forEach((component) => {
68
+ this._setAttr(attr + capitalize(component), undefined);
69
+ });
70
+ }
66
71
  this._fireChangeEvent(attr, oldVal, val);
67
72
  if (after) {
68
73
  after.call(this);
package/cmj/Global.js CHANGED
@@ -16,7 +16,7 @@ exports.glob = typeof global !== 'undefined'
16
16
  : {};
17
17
  exports.Konva = {
18
18
  _global: exports.glob,
19
- version: '8.3.11',
19
+ version: '8.3.13',
20
20
  isBrowser: detectBrowser(),
21
21
  isUnminified: /param/.test(function (param) { }.toString()),
22
22
  dblClickWindow: 400,
package/cmj/Node.d.ts CHANGED
@@ -18,7 +18,7 @@ export interface NodeConfig {
18
18
  listening?: boolean;
19
19
  id?: string;
20
20
  name?: string;
21
- opacity?: Number;
21
+ opacity?: number;
22
22
  scale?: Vector2d;
23
23
  scaleX?: number;
24
24
  scaleY?: number;
@@ -179,7 +179,7 @@ export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
179
179
  getParent(): Container<Node<NodeConfig>>;
180
180
  findAncestors(selector: string, includeSelf?: boolean, stopNode?: Node): Node<NodeConfig>[];
181
181
  isAncestorOf(node: Node): boolean;
182
- findAncestor(selector?: string, includeSelf?: boolean, stopNode?: Container): any;
182
+ findAncestor(selector?: string, includeSelf?: boolean, stopNode?: Container): Node<NodeConfig>;
183
183
  _isMatch(selector: string | Function): any;
184
184
  getLayer(): Layer | null;
185
185
  getStage(): Stage | null;
@@ -303,7 +303,7 @@ export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
303
303
  opacity: GetSet<number, this>;
304
304
  rotation: GetSet<number, this>;
305
305
  zIndex: GetSet<number, this>;
306
- scale: GetSet<Vector2d, this>;
306
+ scale: GetSet<Vector2d | undefined, this>;
307
307
  scaleX: GetSet<number, this>;
308
308
  scaleY: GetSet<number, this>;
309
309
  skew: GetSet<Vector2d, this>;
package/cmj/Node.js CHANGED
@@ -988,7 +988,7 @@ class Node {
988
988
  const callback = config === null || config === void 0 ? void 0 : config.callback;
989
989
  if (callback)
990
990
  delete config.callback;
991
- this.toCanvas(config).toBlob(blob => {
991
+ this.toCanvas(config).toBlob((blob) => {
992
992
  resolve(blob);
993
993
  callback === null || callback === void 0 ? void 0 : callback(blob);
994
994
  });
package/cmj/Shape.js CHANGED
@@ -152,8 +152,11 @@ class Shape extends Node_1.Node {
152
152
  return this._getCache(SHADOW_RGBA, this._getShadowRGBA);
153
153
  }
154
154
  _getShadowRGBA() {
155
- if (this.hasShadow()) {
156
- var rgba = Util_1.Util.colorToRGBA(this.shadowColor());
155
+ if (!this.hasShadow()) {
156
+ return;
157
+ }
158
+ var rgba = Util_1.Util.colorToRGBA(this.shadowColor());
159
+ if (rgba) {
157
160
  return ('rgba(' +
158
161
  rgba.r +
159
162
  ',' +
package/cmj/Stage.js CHANGED
@@ -305,7 +305,7 @@ class Stage extends Container_1.Container {
305
305
  EVENTS.forEach(([event, methodName]) => {
306
306
  this.content.addEventListener(event, (evt) => {
307
307
  this[methodName](evt);
308
- });
308
+ }, { passive: false });
309
309
  });
310
310
  }
311
311
  _pointerenter(evt) {
package/cmj/Validators.js CHANGED
@@ -131,6 +131,10 @@ exports.getFunctionValidator = getFunctionValidator;
131
131
  function getNumberArrayValidator() {
132
132
  if (Global_1.Konva.isUnminified) {
133
133
  return function (val, attr) {
134
+ const TypedArray = Int8Array ? Object.getPrototypeOf(Int8Array) : null;
135
+ if (TypedArray && val instanceof TypedArray) {
136
+ return val;
137
+ }
134
138
  if (!Util_1.Util._isArray(val)) {
135
139
  Util_1.Util.warn(_formatValue(val) +
136
140
  ' is a not valid value for "' +
@@ -171,6 +175,9 @@ exports.getBooleanValidator = getBooleanValidator;
171
175
  function getComponentValidator(components) {
172
176
  if (Global_1.Konva.isUnminified) {
173
177
  return function (val, attr) {
178
+ if (val === undefined || val === null) {
179
+ return val;
180
+ }
174
181
  if (!Util_1.Util.isObject(val)) {
175
182
  Util_1.Util.warn(_formatValue(val) +
176
183
  ' is a not valid value for "' +
@@ -2,7 +2,7 @@ import { Shape, ShapeConfig } from '../Shape';
2
2
  import { GetSet } from '../types';
3
3
  import { Context } from '../Context';
4
4
  export interface LineConfig extends ShapeConfig {
5
- points?: number[];
5
+ points?: number[] | Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array;
6
6
  tension?: number;
7
7
  closed?: boolean;
8
8
  bezier?: boolean;
@@ -3,7 +3,6 @@ import { GetSet } from '../types';
3
3
  export interface RingConfig extends ShapeConfig {
4
4
  innerRadius: number;
5
5
  outerRadius: number;
6
- clockwise?: boolean;
7
6
  }
8
7
  export declare class Ring extends Shape<RingConfig> {
9
8
  _sceneFunc(context: any): void;
@@ -304,7 +304,7 @@ class Text extends Shape_1.Shape {
304
304
  this._addTextLine(line);
305
305
  currentHeightPx += lineHeightPx;
306
306
  textWidth = Math.max(textWidth, lineWidth);
307
- if (this._shouldHandleEllipsis(currentHeightPx)) {
307
+ if (this._shouldHandleEllipsis(currentHeightPx) && i < max - 1) {
308
308
  this._tryToAddEllipsisToLastLine();
309
309
  }
310
310
  }
@@ -167,7 +167,7 @@ class TextPath extends Shape_1.Shape {
167
167
  pathCmd = undefined;
168
168
  }
169
169
  }
170
- if (pathCmd === {} || p0 === undefined) {
170
+ if (Object.keys(pathCmd).length === 0 || p0 === undefined) {
171
171
  return undefined;
172
172
  }
173
173
  var needNewSegment = false;
@@ -86,12 +86,7 @@ export declare class Transformer extends Group {
86
86
  stopTransform(): void;
87
87
  destroy(): this;
88
88
  toObject(): any;
89
- getClientRect(): {
90
- x: number;
91
- y: number;
92
- width: number;
93
- height: number;
94
- };
89
+ getClientRect(): IRect;
95
90
  nodes: GetSet<Node[], this>;
96
91
  enabledAnchors: GetSet<string[], this>;
97
92
  rotationSnaps: GetSet<number[], this>;
@@ -900,7 +900,12 @@ class Transformer extends Group_1.Group {
900
900
  return Node_1.Node.prototype.toObject.call(this);
901
901
  }
902
902
  getClientRect() {
903
- return { x: 0, y: 0, width: 0, height: 0 };
903
+ if (this.nodes().length > 0) {
904
+ return super.getClientRect();
905
+ }
906
+ else {
907
+ return { x: 0, y: 0, width: 0, height: 0 };
908
+ }
904
909
  }
905
910
  }
906
911
  exports.Transformer = Transformer;
package/konva.js CHANGED
@@ -5,10 +5,10 @@
5
5
  })(this, (function () { 'use strict';
6
6
 
7
7
  /*
8
- * Konva JavaScript Framework v8.3.11
8
+ * Konva JavaScript Framework v8.3.13
9
9
  * http://konvajs.org/
10
10
  * Licensed under the MIT
11
- * Date: Fri Aug 05 2022
11
+ * Date: Mon Oct 03 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.11',
38
+ version: '8.3.13',
39
39
  isBrowser: detectBrowser(),
40
40
  isUnminified: /param/.test(function (param) { }.toString()),
41
41
  dblClickWindow: 400,
@@ -1171,6 +1171,12 @@
1171
1171
  function getNumberArrayValidator() {
1172
1172
  if (Konva$2.isUnminified) {
1173
1173
  return function (val, attr) {
1174
+ // Retrieve TypedArray constructor as found in MDN (if TypedArray is available)
1175
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray#description
1176
+ const TypedArray = Int8Array ? Object.getPrototypeOf(Int8Array) : null;
1177
+ if (TypedArray && val instanceof TypedArray) {
1178
+ return val;
1179
+ }
1174
1180
  if (!Util._isArray(val)) {
1175
1181
  Util.warn(_formatValue(val) +
1176
1182
  ' is a not valid value for "' +
@@ -1209,6 +1215,10 @@
1209
1215
  function getComponentValidator(components) {
1210
1216
  if (Konva$2.isUnminified) {
1211
1217
  return function (val, attr) {
1218
+ // ignore validation on undefined value, because it will reset to defalt
1219
+ if (val === undefined || val === null) {
1220
+ return val;
1221
+ }
1212
1222
  if (!Util.isObject(val)) {
1213
1223
  Util.warn(_formatValue(val) +
1214
1224
  ' is a not valid value for "' +
@@ -1283,6 +1293,11 @@
1283
1293
  }
1284
1294
  this._setAttr(attr + capitalize(key), val[key]);
1285
1295
  }
1296
+ if (!val) {
1297
+ components.forEach((component) => {
1298
+ this._setAttr(attr + capitalize(component), undefined);
1299
+ });
1300
+ }
1286
1301
  this._fireChangeEvent(attr, oldVal, val);
1287
1302
  if (after) {
1288
1303
  after.call(this);
@@ -1437,7 +1452,6 @@
1437
1452
  class Context {
1438
1453
  constructor(canvas) {
1439
1454
  this.canvas = canvas;
1440
- this._context = canvas._canvas.getContext('2d');
1441
1455
  if (Konva$2.enableTrace) {
1442
1456
  this.traceArr = [];
1443
1457
  this._enableTrace();
@@ -1976,6 +1990,10 @@
1976
1990
  });
1977
1991
  });
1978
1992
  class SceneContext extends Context {
1993
+ constructor(canvas) {
1994
+ super(canvas);
1995
+ this._context = canvas._canvas.getContext('2d');
1996
+ }
1979
1997
  _fillColor(shape) {
1980
1998
  var fill = shape.fill();
1981
1999
  this.setAttr('fillStyle', fill);
@@ -2090,6 +2108,12 @@
2090
2108
  }
2091
2109
  }
2092
2110
  class HitContext extends Context {
2111
+ constructor(canvas) {
2112
+ super(canvas);
2113
+ this._context = canvas._canvas.getContext('2d', {
2114
+ willReadFrequently: true,
2115
+ });
2116
+ }
2093
2117
  _fill(shape) {
2094
2118
  this.save();
2095
2119
  this.setAttr('fillStyle', shape.colorKey);
@@ -4090,33 +4114,33 @@
4090
4114
  });
4091
4115
  }
4092
4116
  /**
4093
- * Converts node into a blob. Since the toBlob method is asynchronous,
4094
- * the resulting blob can only be retrieved from the config callback
4095
- * or the returned Promise.
4096
- * @method
4097
- * @name Konva.Node#toBlob
4098
- * @param {Object} config
4099
- * @param {Function} [config.callback] function executed when the composite has completed
4100
- * @param {Number} [config.x] x position of canvas section
4101
- * @param {Number} [config.y] y position of canvas section
4102
- * @param {Number} [config.width] width of canvas section
4103
- * @param {Number} [config.height] height of canvas section
4104
- * @param {Number} [config.pixelRatio] pixelRatio of output canvas. Default is 1.
4105
- * You can use that property to increase quality of the image, for example for super hight quality exports
4106
- * or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
4107
- * If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.
4108
- * @param {Boolean} [config.imageSmoothingEnabled] set this to false if you want to disable imageSmoothing
4109
- * @example
4110
- * var blob = await node.toBlob({});
4111
- * @returns {Promise<Blob>}
4112
- */
4117
+ * Converts node into a blob. Since the toBlob method is asynchronous,
4118
+ * the resulting blob can only be retrieved from the config callback
4119
+ * or the returned Promise.
4120
+ * @method
4121
+ * @name Konva.Node#toBlob
4122
+ * @param {Object} config
4123
+ * @param {Function} [config.callback] function executed when the composite has completed
4124
+ * @param {Number} [config.x] x position of canvas section
4125
+ * @param {Number} [config.y] y position of canvas section
4126
+ * @param {Number} [config.width] width of canvas section
4127
+ * @param {Number} [config.height] height of canvas section
4128
+ * @param {Number} [config.pixelRatio] pixelRatio of output canvas. Default is 1.
4129
+ * You can use that property to increase quality of the image, for example for super hight quality exports
4130
+ * or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
4131
+ * If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.
4132
+ * @param {Boolean} [config.imageSmoothingEnabled] set this to false if you want to disable imageSmoothing
4133
+ * @example
4134
+ * var blob = await node.toBlob({});
4135
+ * @returns {Promise<Blob>}
4136
+ */
4113
4137
  toBlob(config) {
4114
4138
  return new Promise((resolve, reject) => {
4115
4139
  try {
4116
4140
  const callback = config === null || config === void 0 ? void 0 : config.callback;
4117
4141
  if (callback)
4118
4142
  delete config.callback;
4119
- this.toCanvas(config).toBlob(blob => {
4143
+ this.toCanvas(config).toBlob((blob) => {
4120
4144
  resolve(blob);
4121
4145
  callback === null || callback === void 0 ? void 0 : callback(blob);
4122
4146
  });
@@ -6125,7 +6149,7 @@
6125
6149
  EVENTS.forEach(([event, methodName]) => {
6126
6150
  this.content.addEventListener(event, (evt) => {
6127
6151
  this[methodName](evt);
6128
- });
6152
+ }, { passive: false });
6129
6153
  });
6130
6154
  }
6131
6155
  _pointerenter(evt) {
@@ -6820,8 +6844,11 @@
6820
6844
  return this._getCache(SHADOW_RGBA, this._getShadowRGBA);
6821
6845
  }
6822
6846
  _getShadowRGBA() {
6823
- if (this.hasShadow()) {
6824
- var rgba = Util.colorToRGBA(this.shadowColor());
6847
+ if (!this.hasShadow()) {
6848
+ return;
6849
+ }
6850
+ var rgba = Util.colorToRGBA(this.shadowColor());
6851
+ if (rgba) {
6825
6852
  return ('rgba(' +
6826
6853
  rgba.r +
6827
6854
  ',' +
@@ -12487,7 +12514,6 @@
12487
12514
  * @param {Object} config
12488
12515
  * @param {Number} config.innerRadius
12489
12516
  * @param {Number} config.outerRadius
12490
- * @param {Boolean} [config.clockwise]
12491
12517
  * @param {String} [config.fill] fill color
12492
12518
  * @param {Image} [config.fillPatternImage] fill pattern image
12493
12519
  * @param {Number} [config.fillPatternX]
@@ -13626,7 +13652,7 @@
13626
13652
  this._addTextLine(line);
13627
13653
  currentHeightPx += lineHeightPx;
13628
13654
  textWidth = Math.max(textWidth, lineWidth);
13629
- if (this._shouldHandleEllipsis(currentHeightPx)) {
13655
+ if (this._shouldHandleEllipsis(currentHeightPx) && i < max - 1) {
13630
13656
  this._tryToAddEllipsisToLastLine();
13631
13657
  }
13632
13658
  }
@@ -14213,7 +14239,7 @@
14213
14239
  pathCmd = undefined;
14214
14240
  }
14215
14241
  }
14216
- if (pathCmd === {} || p0 === undefined) {
14242
+ if (Object.keys(pathCmd).length === 0 || p0 === undefined) {
14217
14243
  return undefined;
14218
14244
  }
14219
14245
  var needNewSegment = false;
@@ -15577,9 +15603,14 @@
15577
15603
  return Node.prototype.toObject.call(this);
15578
15604
  }
15579
15605
  getClientRect() {
15580
- // return zero size
15581
- // so it will be skipped in calculations
15582
- return { x: 0, y: 0, width: 0, height: 0 };
15606
+ if (this.nodes().length > 0) {
15607
+ return super.getClientRect();
15608
+ }
15609
+ else {
15610
+ // if we are detached return zero size
15611
+ // so it will be skipped in calculations
15612
+ return { x: 0, y: 0, width: 0, height: 0 };
15613
+ }
15583
15614
  }
15584
15615
  }
15585
15616
  function validateAnchors(val) {