konva 9.3.0 → 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.
@@ -25,15 +25,19 @@ export declare abstract class Container<ChildType extends Node = Node> extends N
25
25
  findOne<ChildNode extends Node = Node>(selector: string | Function): ChildNode | undefined;
26
26
  _generalFind<ChildNode extends Node>(selector: string | Function, findOne: boolean): ChildNode[];
27
27
  private _descendants;
28
- toObject(): any;
28
+ toObject(): {
29
+ attrs: any;
30
+ className: string;
31
+ children?: any[] | undefined;
32
+ };
29
33
  isAncestorOf(node: Node): boolean;
30
34
  clone(obj?: any): this;
31
35
  getAllIntersections(pos: any): Shape<import("./Shape.js").ShapeConfig>[];
32
36
  _clearSelfAndDescendantCache(attr?: string): void;
33
37
  _setChildrenIndices(): void;
34
- drawScene(can?: SceneCanvas, top?: Node): this;
38
+ drawScene(can?: SceneCanvas, top?: Node, bufferCanvas?: SceneCanvas): this;
35
39
  drawHit(can?: HitCanvas, top?: Node): this;
36
- _drawChildren(drawMethod: any, canvas: any, top: any): void;
40
+ _drawChildren(drawMethod: any, canvas: any, top: any, bufferCanvas?: any): void;
37
41
  getClientRect(config?: {
38
42
  skipTransform?: boolean;
39
43
  skipShadow?: boolean;
package/lib/Container.js CHANGED
@@ -168,7 +168,7 @@ class Container extends Node_1.Node {
168
168
  });
169
169
  this._requestDraw();
170
170
  }
171
- drawScene(can, top) {
171
+ drawScene(can, top, bufferCanvas) {
172
172
  var layer = this.getLayer(), canvas = can || (layer && layer.getCanvas()), context = canvas && canvas.getContext(), cachedCanvas = this._getCanvasCache(), cachedSceneCanvas = cachedCanvas && cachedCanvas.scene;
173
173
  var caching = canvas && canvas.isCache;
174
174
  if (!this.isVisible() && !caching) {
@@ -182,7 +182,7 @@ class Container extends Node_1.Node {
182
182
  context.restore();
183
183
  }
184
184
  else {
185
- this._drawChildren('drawScene', canvas, top);
185
+ this._drawChildren('drawScene', canvas, top, bufferCanvas);
186
186
  }
187
187
  return this;
188
188
  }
@@ -203,7 +203,7 @@ class Container extends Node_1.Node {
203
203
  }
204
204
  return this;
205
205
  }
206
- _drawChildren(drawMethod, canvas, top) {
206
+ _drawChildren(drawMethod, canvas, top, bufferCanvas) {
207
207
  var _a;
208
208
  var context = canvas && canvas.getContext(), clipWidth = this.clipWidth(), clipHeight = this.clipHeight(), clipFunc = this.clipFunc(), hasClip = (clipWidth && clipHeight) || clipFunc;
209
209
  const selfCache = top === this;
@@ -234,7 +234,7 @@ class Container extends Node_1.Node {
234
234
  context._applyGlobalCompositeOperation(this);
235
235
  }
236
236
  (_a = this.children) === null || _a === void 0 ? void 0 : _a.forEach(function (child) {
237
- child[drawMethod](canvas, top);
237
+ child[drawMethod](canvas, top, bufferCanvas);
238
238
  });
239
239
  if (hasComposition) {
240
240
  context.restore();
package/lib/Context.d.ts CHANGED
@@ -51,6 +51,7 @@ export declare class Context {
51
51
  lineTo(x: number, y: number): void;
52
52
  moveTo(x: number, y: number): void;
53
53
  rect(x: number, y: number, width: number, height: number): void;
54
+ roundRect(x: number, y: number, width: number, height: number, radii: number | DOMPointInit | (number | DOMPointInit)[]): void;
54
55
  putImageData(imageData: ImageData, dx: number, dy: number): void;
55
56
  quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): void;
56
57
  restore(): void;
package/lib/Context.js CHANGED
@@ -39,6 +39,7 @@ var COMMA = ',', OPEN_PAREN = '(', CLOSE_PAREN = ')', OPEN_PAREN_BRACKET = '([',
39
39
  'putImageData',
40
40
  'quadraticCurveTo',
41
41
  'rect',
42
+ 'roundRect',
42
43
  'restore',
43
44
  'rotate',
44
45
  'save',
@@ -277,6 +278,9 @@ class Context {
277
278
  rect(x, y, width, height) {
278
279
  this._context.rect(x, y, width, height);
279
280
  }
281
+ roundRect(x, y, width, height, radii) {
282
+ this._context.roundRect(x, y, width, height, radii);
283
+ }
280
284
  putImageData(imageData, dx, dy) {
281
285
  this._context.putImageData(imageData, dx, dy);
282
286
  }
package/lib/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: '9.3.0',
19
+ version: '9.3.1',
20
20
  isBrowser: detectBrowser(),
21
21
  isUnminified: /param/.test(function (param) { }.toString()),
22
22
  dblClickWindow: 400,
package/lib/Node.d.ts CHANGED
@@ -21,6 +21,8 @@ export interface NodeConfig {
21
21
  opacity?: number;
22
22
  scale?: Vector2d;
23
23
  scaleX?: number;
24
+ skewX?: number;
25
+ skewY?: number;
24
26
  scaleY?: number;
25
27
  rotation?: number;
26
28
  rotationDeg?: number;
@@ -91,7 +93,7 @@ export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
91
93
  hitCanvasPixelRatio?: number;
92
94
  }): this | undefined;
93
95
  isCached(): boolean;
94
- abstract drawScene(canvas?: Canvas, top?: Node): void;
96
+ abstract drawScene(canvas?: Canvas, top?: Node, bufferCanvas?: Canvas): void;
95
97
  abstract drawHit(canvas?: Canvas, top?: Node): void;
96
98
  getClientRect(config?: {
97
99
  skipTransform?: boolean;
@@ -125,7 +127,7 @@ export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
125
127
  destroy(): this;
126
128
  getAttr(attr: string): any;
127
129
  getAncestors(): Node<NodeConfig>[];
128
- getAttrs(): any;
130
+ getAttrs(): Config & Record<string, any>;
129
131
  setAttrs(config: any): this;
130
132
  isListening(): any;
131
133
  _isListening(relativeTo?: Node): boolean;
@@ -175,7 +177,11 @@ export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
175
177
  getAbsoluteOpacity(): any;
176
178
  _getAbsoluteOpacity(): number;
177
179
  moveTo(newContainer: any): this;
178
- toObject(): any;
180
+ toObject(): {
181
+ attrs: Config & Record<string, any>;
182
+ className: string;
183
+ children?: any[] | undefined;
184
+ };
179
185
  toJSON(): string;
180
186
  getParent(): Container<Node<NodeConfig>> | null;
181
187
  findAncestors(selector: string | Function, includeSelf?: boolean, stopNode?: Node): Node<NodeConfig>[];
package/lib/Node.js CHANGED
@@ -111,8 +111,10 @@ class Node {
111
111
  Util_1.Util.error('Can not cache the node. Width or height of the node equals 0. Caching is skipped.');
112
112
  return;
113
113
  }
114
- width += offset * 2 + 1;
115
- height += offset * 2 + 1;
114
+ const extraPaddingX = Math.abs(Math.round(rect.x) - x) > 0.5 ? 1 : 0;
115
+ const extraPaddingY = Math.abs(Math.round(rect.y) - y) > 0.5 ? 1 : 0;
116
+ width += offset * 2 + extraPaddingX;
117
+ height += offset * 2 + extraPaddingY;
116
118
  x -= offset;
117
119
  y -= offset;
118
120
  var cachedSceneCanvas = new Canvas_1.SceneCanvas({
@@ -377,7 +379,7 @@ class Node {
377
379
  return ancestors;
378
380
  }
379
381
  getAttrs() {
380
- return this.attrs || {};
382
+ return (this.attrs || {});
381
383
  }
382
384
  setAttrs(config) {
383
385
  this._batchTransformChanges(() => {
@@ -720,8 +722,11 @@ class Node {
720
722
  return this;
721
723
  }
722
724
  toObject() {
723
- var obj = {}, attrs = this.getAttrs(), key, val, getter, defaultValue, nonPlainObject;
724
- obj.attrs = {};
725
+ var attrs = this.getAttrs(), key, val, getter, defaultValue, nonPlainObject;
726
+ const obj = {
727
+ attrs: {},
728
+ className: this.getClassName(),
729
+ };
725
730
  for (key in attrs) {
726
731
  val = attrs[key];
727
732
  nonPlainObject =
@@ -737,7 +742,6 @@ class Node {
737
742
  obj.attrs[key] = val;
738
743
  }
739
744
  }
740
- obj.className = this.getClassName();
741
745
  return Util_1.Util._prepareToStringify(obj);
742
746
  }
743
747
  toJSON() {
@@ -949,6 +953,11 @@ class Node {
949
953
  (stage ? stage.height() : 0),
950
954
  pixelRatio: pixelRatio,
951
955
  }), context = canvas.getContext();
956
+ const bufferCanvas = new Canvas_1.SceneCanvas({
957
+ width: canvas.width,
958
+ height: canvas.height,
959
+ pixelRatio: canvas.pixelRatio,
960
+ });
952
961
  if (config.imageSmoothingEnabled === false) {
953
962
  context._context.imageSmoothingEnabled = false;
954
963
  }
@@ -956,7 +965,7 @@ class Node {
956
965
  if (x || y) {
957
966
  context.translate(-1 * x, -1 * y);
958
967
  }
959
- this.drawScene(canvas);
968
+ this.drawScene(canvas, undefined, bufferCanvas);
960
969
  context.restore();
961
970
  return canvas;
962
971
  }
package/lib/Shape.d.ts CHANGED
@@ -115,7 +115,7 @@ export declare class Shape<Config extends ShapeConfig = ShapeConfig> extends Nod
115
115
  x: number;
116
116
  y: number;
117
117
  };
118
- drawScene(can?: SceneCanvas, top?: Node): this;
118
+ drawScene(can?: SceneCanvas, top?: Node, bufferCanvas?: SceneCanvas): this;
119
119
  drawHit(can?: HitCanvas, top?: Node, skipDragCheck?: boolean): this;
120
120
  drawHitFromCache(alphaThreshold?: number): this;
121
121
  hasPointerCapture(pointerId: number): boolean;
package/lib/Shape.js CHANGED
@@ -227,9 +227,6 @@ class Shape extends Node_1.Node {
227
227
  }
228
228
  _useBufferCanvas(forceFill) {
229
229
  var _a;
230
- if (!this.getStage()) {
231
- return false;
232
- }
233
230
  const perfectDrawEnabled = (_a = this.attrs.perfectDrawEnabled) !== null && _a !== void 0 ? _a : true;
234
231
  if (!perfectDrawEnabled) {
235
232
  return false;
@@ -304,9 +301,9 @@ class Shape extends Node_1.Node {
304
301
  }
305
302
  return rect;
306
303
  }
307
- drawScene(can, top) {
304
+ drawScene(can, top, bufferCanvas) {
308
305
  var layer = this.getLayer();
309
- var canvas = can || layer.getCanvas(), context = canvas.getContext(), cachedCanvas = this._getCanvasCache(), drawFunc = this.getSceneFunc(), hasShadow = this.hasShadow(), stage, bufferCanvas, bufferContext;
306
+ var canvas = can || layer.getCanvas(), context = canvas.getContext(), cachedCanvas = this._getCanvasCache(), drawFunc = this.getSceneFunc(), hasShadow = this.hasShadow(), stage, bufferContext;
310
307
  var skipBuffer = canvas.isCache;
311
308
  var cachingSelf = top === this;
312
309
  if (!this.isVisible() && !cachingSelf) {
@@ -326,8 +323,8 @@ class Shape extends Node_1.Node {
326
323
  context.save();
327
324
  if (this._useBufferCanvas() && !skipBuffer) {
328
325
  stage = this.getStage();
329
- bufferCanvas = stage.bufferCanvas;
330
- bufferContext = bufferCanvas.getContext();
326
+ const bc = bufferCanvas || stage.bufferCanvas;
327
+ bufferContext = bc.getContext();
331
328
  bufferContext.clear();
332
329
  bufferContext.save();
333
330
  bufferContext._applyLineJoin(this);
@@ -335,13 +332,13 @@ class Shape extends Node_1.Node {
335
332
  bufferContext.transform(o[0], o[1], o[2], o[3], o[4], o[5]);
336
333
  drawFunc.call(this, bufferContext, this);
337
334
  bufferContext.restore();
338
- var ratio = bufferCanvas.pixelRatio;
335
+ var ratio = bc.pixelRatio;
339
336
  if (hasShadow) {
340
337
  context._applyShadow(this);
341
338
  }
342
339
  context._applyOpacity(this);
343
340
  context._applyGlobalCompositeOperation(this);
344
- context.drawImage(bufferCanvas._canvas, 0, 0, bufferCanvas.width / ratio, bufferCanvas.height / ratio);
341
+ context.drawImage(bc._canvas, 0, 0, bc.width / ratio, bc.height / ratio);
345
342
  }
346
343
  else {
347
344
  context._applyLineJoin(this);
package/lib/Util.d.ts CHANGED
@@ -123,8 +123,8 @@ export declare const Util: {
123
123
  _getProjectionToSegment(x1: any, y1: any, x2: any, y2: any, x3: any, y3: any): any[];
124
124
  _getProjectionToLine(pt: Vector2d, line: Array<Vector2d>, isClosed: boolean): Vector2d;
125
125
  _prepareArrayForTween(startArray: any, endArray: any, isClosed: any): number[];
126
- _prepareToStringify(obj: any): any;
127
- _assign<T, U>(target: T, source: U): T & U;
126
+ _prepareToStringify<T>(obj: any): T | null;
127
+ _assign<T_1, U>(target: T_1, source: U): T_1 & U;
128
128
  _getFirstPointerId(evt: any): any;
129
129
  releaseCanvas(...canvases: HTMLCanvasElement[]): void;
130
130
  drawRoundedRectPath(context: Context, width: number, height: number, cornerRadius: number | number[]): void;
@@ -133,8 +133,8 @@ export declare const Konva: {
133
133
  _getProjectionToSegment(x1: any, y1: any, x2: any, y2: any, x3: any, y3: any): any[];
134
134
  _getProjectionToLine(pt: import("./types").Vector2d, line: import("./types").Vector2d[], isClosed: boolean): import("./types.js").Vector2d;
135
135
  _prepareArrayForTween(startArray: any, endArray: any, isClosed: any): number[];
136
- _prepareToStringify(obj: any): any;
137
- _assign<T, U>(target: T, source: U): T & U;
136
+ _prepareToStringify<T>(obj: any): T | null;
137
+ _assign<T_1, U>(target: T_1, source: U): T_1 & U;
138
138
  _getFirstPointerId(evt: any): any;
139
139
  releaseCanvas(...canvases: HTMLCanvasElement[]): void;
140
140
  drawRoundedRectPath(context: Context, width: number, height: number, cornerRadius: number | number[]): void;
@@ -138,8 +138,8 @@ export declare const Konva: {
138
138
  _getProjectionToSegment(x1: any, y1: any, x2: any, y2: any, x3: any, y3: any): any[];
139
139
  _getProjectionToLine(pt: import("./types").Vector2d, line: import("./types").Vector2d[], isClosed: boolean): import("./types.js").Vector2d;
140
140
  _prepareArrayForTween(startArray: any, endArray: any, isClosed: any): number[];
141
- _prepareToStringify(obj: any): any;
142
- _assign<T, U>(target: T, source: U): T & U;
141
+ _prepareToStringify<T>(obj: any): T | null;
142
+ _assign<T_1, U>(target: T_1, source: U): T_1 & U;
143
143
  _getFirstPointerId(evt: any): any;
144
144
  releaseCanvas(...canvases: HTMLCanvasElement[]): void;
145
145
  drawRoundedRectPath(context: import("./Context.js").Context, width: number, height: number, cornerRadius: number | number[]): void;
@@ -1,5 +1,6 @@
1
1
  import { Transform } from '../Util.js';
2
2
  import { Node } from '../Node.js';
3
+ import { Shape } from '../Shape.js';
3
4
  import { Rect } from './Rect.js';
4
5
  import { Group } from '../Group.js';
5
6
  import { ContainerConfig } from '../Container.js';
@@ -34,6 +35,8 @@ export interface TransformerConfig extends ContainerConfig {
34
35
  boundBoxFunc?: (oldBox: Box, newBox: Box) => Box;
35
36
  useSingleNodeRotation?: boolean;
36
37
  shouldOverdrawWholeArea?: boolean;
38
+ anchorDragBoundFunc?: (oldPos: Vector2d, newPos: Vector2d, evt: any) => Vector2d;
39
+ anchorStyleFunc?: (anchor: Shape) => void;
37
40
  }
38
41
  export declare class Transformer extends Group {
39
42
  _nodes: Array<Node>;
@@ -88,7 +91,11 @@ export declare class Transformer extends Group {
88
91
  isTransforming(): boolean;
89
92
  stopTransform(): void;
90
93
  destroy(): this;
91
- toObject(): any;
94
+ toObject(): {
95
+ attrs: any;
96
+ className: string;
97
+ children?: any[] | undefined;
98
+ };
92
99
  clone(obj?: any): this;
93
100
  getClientRect(): IRect;
94
101
  nodes: GetSet<Node[], this>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "konva",
3
- "version": "9.3.0",
3
+ "version": "9.3.1",
4
4
  "author": "Anton Lavrenov",
5
5
  "files": [
6
6
  "README.md",