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/lib/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/lib/Context.js CHANGED
@@ -70,7 +70,6 @@ const traceArrMax = 100;
70
70
  export class Context {
71
71
  constructor(canvas) {
72
72
  this.canvas = canvas;
73
- this._context = canvas._canvas.getContext('2d');
74
73
  if (Konva.enableTrace) {
75
74
  this.traceArr = [];
76
75
  this._enableTrace();
@@ -378,6 +377,10 @@ CONTEXT_PROPERTIES.forEach(function (prop) {
378
377
  });
379
378
  });
380
379
  export class SceneContext extends Context {
380
+ constructor(canvas) {
381
+ super(canvas);
382
+ this._context = canvas._canvas.getContext('2d');
383
+ }
381
384
  _fillColor(shape) {
382
385
  var fill = shape.fill();
383
386
  this.setAttr('fillStyle', fill);
@@ -487,6 +490,12 @@ export class SceneContext extends Context {
487
490
  }
488
491
  }
489
492
  export class HitContext extends Context {
493
+ constructor(canvas) {
494
+ super(canvas);
495
+ this._context = canvas._canvas.getContext('2d', {
496
+ willReadFrequently: true,
497
+ });
498
+ }
490
499
  _fill(shape) {
491
500
  this.save();
492
501
  this.setAttr('fillStyle', shape.colorKey);
package/lib/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/lib/Factory.js CHANGED
@@ -60,6 +60,11 @@ export const Factory = {
60
60
  }
61
61
  this._setAttr(attr + capitalize(key), val[key]);
62
62
  }
63
+ if (!val) {
64
+ components.forEach((component) => {
65
+ this._setAttr(attr + capitalize(component), undefined);
66
+ });
67
+ }
63
68
  this._fireChangeEvent(attr, oldVal, val);
64
69
  if (after) {
65
70
  after.call(this);
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.11',
16
+ version: '8.3.13',
17
17
  isBrowser: detectBrowser(),
18
18
  isUnminified: /param/.test(function (param) { }.toString()),
19
19
  dblClickWindow: 400,
package/lib/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/lib/Node.js CHANGED
@@ -985,7 +985,7 @@ export class Node {
985
985
  const callback = config === null || config === void 0 ? void 0 : config.callback;
986
986
  if (callback)
987
987
  delete config.callback;
988
- this.toCanvas(config).toBlob(blob => {
988
+ this.toCanvas(config).toBlob((blob) => {
989
989
  resolve(blob);
990
990
  callback === null || callback === void 0 ? void 0 : callback(blob);
991
991
  });
package/lib/Shape.js CHANGED
@@ -149,8 +149,11 @@ export class Shape extends Node {
149
149
  return this._getCache(SHADOW_RGBA, this._getShadowRGBA);
150
150
  }
151
151
  _getShadowRGBA() {
152
- if (this.hasShadow()) {
153
- var rgba = Util.colorToRGBA(this.shadowColor());
152
+ if (!this.hasShadow()) {
153
+ return;
154
+ }
155
+ var rgba = Util.colorToRGBA(this.shadowColor());
156
+ if (rgba) {
154
157
  return ('rgba(' +
155
158
  rgba.r +
156
159
  ',' +
package/lib/Stage.js CHANGED
@@ -302,7 +302,7 @@ export class Stage extends Container {
302
302
  EVENTS.forEach(([event, methodName]) => {
303
303
  this.content.addEventListener(event, (evt) => {
304
304
  this[methodName](evt);
305
- });
305
+ }, { passive: false });
306
306
  });
307
307
  }
308
308
  _pointerenter(evt) {
package/lib/Validators.js CHANGED
@@ -120,6 +120,10 @@ export function getFunctionValidator() {
120
120
  export function getNumberArrayValidator() {
121
121
  if (Konva.isUnminified) {
122
122
  return function (val, attr) {
123
+ const TypedArray = Int8Array ? Object.getPrototypeOf(Int8Array) : null;
124
+ if (TypedArray && val instanceof TypedArray) {
125
+ return val;
126
+ }
123
127
  if (!Util._isArray(val)) {
124
128
  Util.warn(_formatValue(val) +
125
129
  ' is a not valid value for "' +
@@ -158,6 +162,9 @@ export function getBooleanValidator() {
158
162
  export function getComponentValidator(components) {
159
163
  if (Konva.isUnminified) {
160
164
  return function (val, attr) {
165
+ if (val === undefined || val === null) {
166
+ return val;
167
+ }
161
168
  if (!Util.isObject(val)) {
162
169
  Util.warn(_formatValue(val) +
163
170
  ' 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;
@@ -300,7 +300,7 @@ export class Text extends Shape {
300
300
  this._addTextLine(line);
301
301
  currentHeightPx += lineHeightPx;
302
302
  textWidth = Math.max(textWidth, lineWidth);
303
- if (this._shouldHandleEllipsis(currentHeightPx)) {
303
+ if (this._shouldHandleEllipsis(currentHeightPx) && i < max - 1) {
304
304
  this._tryToAddEllipsisToLastLine();
305
305
  }
306
306
  }
@@ -164,7 +164,7 @@ export class TextPath extends Shape {
164
164
  pathCmd = undefined;
165
165
  }
166
166
  }
167
- if (pathCmd === {} || p0 === undefined) {
167
+ if (Object.keys(pathCmd).length === 0 || p0 === undefined) {
168
168
  return undefined;
169
169
  }
170
170
  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>;
@@ -897,7 +897,12 @@ export class Transformer extends Group {
897
897
  return Node.prototype.toObject.call(this);
898
898
  }
899
899
  getClientRect() {
900
- return { x: 0, y: 0, width: 0, height: 0 };
900
+ if (this.nodes().length > 0) {
901
+ return super.getClientRect();
902
+ }
903
+ else {
904
+ return { x: 0, y: 0, width: 0, height: 0 };
905
+ }
901
906
  }
902
907
  }
903
908
  function validateAnchors(val) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "konva",
3
- "version": "8.3.11",
3
+ "version": "8.3.13",
4
4
  "author": "Anton Lavrenov",
5
5
  "files": [
6
6
  "README.md",
@@ -49,7 +49,7 @@
49
49
  "test": "npm run test:browser && npm run test:node",
50
50
  "test:build": "parcel build ./test/unit-tests.html --dist-dir ./test-build --target none --public-url ./ --no-source-maps",
51
51
  "test:browser": "npm run test:build && mocha-headless-chrome -f ./test-build/unit-tests.html -a disable-web-security",
52
- "test:node": "env TS_NODE_PROJECT=\"./test/tsconfig.json\" mocha -r ts-node/register test/unit/**/*.ts --exit && npm run test:import",
52
+ "test:node": "ts-mocha -p ./test/tsconfig.json test/unit/**/*.ts --exit && npm run test:import",
53
53
  "test:watch": "rm -rf ./parcel-cache && parcel serve ./test/unit-tests.html ./test/manual-tests.html ./test/sandbox.html",
54
54
  "tsc": "tsc --removeComments && tsc --build ./tsconfig-cmj.json",
55
55
  "rollup": "rollup -c",
@@ -88,10 +88,10 @@
88
88
  }
89
89
  ],
90
90
  "devDependencies": {
91
- "@parcel/transformer-image": "2.6.0",
92
- "@size-limit/preset-big-lib": "^7.0.8",
91
+ "@parcel/transformer-image": "2.7.0",
92
+ "@size-limit/preset-big-lib": "^8.0.0",
93
93
  "@types/mocha": "^9.1.1",
94
- "canvas": "^2.9.1",
94
+ "canvas": "^2.9.3",
95
95
  "chai": "4.3.6",
96
96
  "filehound": "^1.17.6",
97
97
  "gulp": "^4.0.2",
@@ -105,19 +105,19 @@
105
105
  "gulp-uglify": "^3.0.2",
106
106
  "gulp-uglify-es": "^3.0.0",
107
107
  "gulp-util": "^3.0.8",
108
- "mocha": "9.2.2",
108
+ "mocha": "10.0.0",
109
109
  "mocha-headless-chrome": "^4.0.0",
110
- "parcel": "2.6.0",
110
+ "parcel": "2.7.0",
111
111
  "process": "^0.11.10",
112
- "rollup": "^2.75.0",
112
+ "rollup": "^2.77.2",
113
113
  "rollup-plugin-commonjs": "^10.1.0",
114
114
  "rollup-plugin-node-resolve": "^5.2.0",
115
115
  "rollup-plugin-sourcemaps": "^0.6.3",
116
- "rollup-plugin-typescript2": "^0.31.2",
117
- "size-limit": "^7.0.8",
118
- "ts-mocha": "^9.0.2",
119
- "ts-node": "^9.1.1",
120
- "typescript": "^4.6.3"
116
+ "rollup-plugin-typescript2": "^0.32.1",
117
+ "size-limit": "^8.0.0",
118
+ "ts-mocha": "^10.0.0",
119
+ "ts-node": "^10.9.1",
120
+ "typescript": "^4.7.4"
121
121
  },
122
122
  "keywords": [
123
123
  "canvas",