konva 8.3.13 → 8.4.0

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.
Files changed (55) hide show
  1. package/cmj/Canvas.js +1 -0
  2. package/cmj/Context.d.ts +33 -27
  3. package/cmj/Context.js +6 -2
  4. package/cmj/Global.d.ts +1 -0
  5. package/cmj/Global.js +2 -1
  6. package/cmj/Layer.d.ts +1 -0
  7. package/cmj/Layer.js +4 -0
  8. package/cmj/Node.d.ts +5 -5
  9. package/cmj/Node.js +6 -1
  10. package/cmj/PointerEvents.d.ts +1 -1
  11. package/cmj/Shape.d.ts +3 -3
  12. package/cmj/Stage.js +1 -0
  13. package/cmj/Util.d.ts +5 -0
  14. package/cmj/Util.js +54 -0
  15. package/cmj/_CoreInternals.d.ts +5 -0
  16. package/cmj/_FullInternals.d.ts +5 -0
  17. package/cmj/filters/Kaleidoscope.js +1 -0
  18. package/cmj/shapes/Image.d.ts +2 -0
  19. package/cmj/shapes/Image.js +17 -5
  20. package/cmj/shapes/Rect.d.ts +2 -1
  21. package/cmj/shapes/Rect.js +2 -22
  22. package/cmj/shapes/TextPath.d.ts +1 -0
  23. package/cmj/shapes/TextPath.js +4 -0
  24. package/cmj/shapes/Transformer.d.ts +1 -0
  25. package/cmj/shapes/Transformer.js +4 -0
  26. package/cmj/types.d.ts +1 -1
  27. package/konva.js +147 -47
  28. package/konva.min.js +3 -3
  29. package/lib/Canvas.js +1 -0
  30. package/lib/Context.d.ts +33 -27
  31. package/lib/Context.js +6 -2
  32. package/lib/Global.d.ts +1 -0
  33. package/lib/Global.js +2 -1
  34. package/lib/Layer.d.ts +1 -0
  35. package/lib/Layer.js +4 -0
  36. package/lib/Node.d.ts +5 -5
  37. package/lib/Node.js +6 -1
  38. package/lib/PointerEvents.d.ts +1 -1
  39. package/lib/Shape.d.ts +3 -3
  40. package/lib/Stage.js +1 -0
  41. package/lib/Util.d.ts +5 -0
  42. package/lib/Util.js +54 -0
  43. package/lib/_CoreInternals.d.ts +5 -0
  44. package/lib/_FullInternals.d.ts +5 -0
  45. package/lib/filters/Kaleidoscope.js +1 -0
  46. package/lib/shapes/Image.d.ts +2 -0
  47. package/lib/shapes/Image.js +17 -5
  48. package/lib/shapes/Rect.d.ts +2 -1
  49. package/lib/shapes/Rect.js +2 -22
  50. package/lib/shapes/TextPath.d.ts +1 -0
  51. package/lib/shapes/TextPath.js +4 -0
  52. package/lib/shapes/Transformer.d.ts +1 -0
  53. package/lib/shapes/Transformer.js +4 -0
  54. package/lib/types.d.ts +1 -1
  55. package/package.json +13 -13
package/lib/Canvas.js CHANGED
@@ -19,6 +19,7 @@ function getDevicePixelRatio() {
19
19
  1;
20
20
  return devicePixelRatio / backingStoreRatio;
21
21
  })();
22
+ Util.releaseCanvas(canvas);
22
23
  return _pixelRatio;
23
24
  }
24
25
  export class Canvas {
package/lib/Context.d.ts CHANGED
@@ -1,12 +1,14 @@
1
1
  import { Canvas } from './Canvas';
2
2
  import { Shape } from './Shape';
3
+ import { IRect } from './types';
4
+ declare var CONTEXT_PROPERTIES: readonly ["fillStyle", "strokeStyle", "shadowColor", "shadowBlur", "shadowOffsetX", "shadowOffsetY", "lineCap", "lineDashOffset", "lineJoin", "lineWidth", "miterLimit", "font", "textAlign", "textBaseline", "globalAlpha", "globalCompositeOperation", "imageSmoothingEnabled"];
3
5
  export declare class Context {
4
6
  canvas: Canvas;
5
7
  _context: CanvasRenderingContext2D;
6
8
  traceArr: Array<String>;
7
9
  constructor(canvas: Canvas);
8
10
  fillShape(shape: Shape): void;
9
- _fill(shape: any): void;
11
+ _fill(shape: Shape): void;
10
12
  strokeShape(shape: Shape): void;
11
13
  _stroke(shape: any): void;
12
14
  fillStrokeShape(shape: Shape): void;
@@ -15,50 +17,53 @@ export declare class Context {
15
17
  _trace(str: any): void;
16
18
  reset(): void;
17
19
  getCanvas(): Canvas;
18
- clear(bounds?: any): void;
20
+ clear(bounds?: IRect): void;
19
21
  _applyLineCap(shape: any): void;
20
22
  _applyOpacity(shape: any): void;
21
23
  _applyLineJoin(shape: Shape): void;
22
- setAttr(attr: any, val: any): void;
23
- arc(a0: any, a1: any, a2: any, a3: any, a4: any, a5: any): void;
24
- arcTo(a0: any, a1: any, a2: any, a3: any, a4: any): void;
24
+ setAttr(attr: string, val: any): void;
25
+ arc(a0: number, a1: number, a2: number, a3: number, a4: number, a5?: boolean): void;
26
+ arcTo(a0: number, a1: number, a2: number, a3: number, a4: number): void;
25
27
  beginPath(): void;
26
- bezierCurveTo(a0: any, a1: any, a2: any, a3: any, a4: any, a5: any): void;
27
- clearRect(a0: any, a1: any, a2: any, a3: any): void;
28
+ bezierCurveTo(a0: number, a1: number, a2: number, a3: number, a4: number, a5: number): void;
29
+ clearRect(a0: number, a1: number, a2: number, a3: number): void;
28
30
  clip(): void;
29
31
  closePath(): void;
30
32
  createImageData(a0: any, a1: any): ImageData;
31
- createLinearGradient(a0: any, a1: any, a2: any, a3: any): CanvasGradient;
32
- createPattern(a0: any, a1: any): CanvasPattern;
33
- createRadialGradient(a0: any, a1: any, a2: any, a3: any, a4: any, a5: any): CanvasGradient;
33
+ createLinearGradient(a0: number, a1: number, a2: number, a3: number): CanvasGradient;
34
+ createPattern(a0: CanvasImageSource, a1: string | null): CanvasPattern;
35
+ createRadialGradient(a0: number, a1: number, a2: number, a3: number, a4: number, a5: number): CanvasGradient;
34
36
  drawImage(a0: CanvasImageSource, a1: number, a2: number, a3?: number, a4?: number, a5?: number, a6?: number, a7?: number, a8?: number): void;
35
37
  ellipse(a0: number, a1: number, a2: number, a3: number, a4: number, a5: number, a6: number, a7?: boolean): void;
36
- isPointInPath(x: any, y: any): boolean;
38
+ isPointInPath(x: number, y: number, path?: Path2D, fillRule?: CanvasFillRule): boolean;
37
39
  fill(path2d?: Path2D): void;
38
- fillRect(x: any, y: any, width: any, height: any): void;
39
- strokeRect(x: any, y: any, width: any, height: any): void;
40
+ fillRect(x: number, y: number, width: number, height: number): void;
41
+ strokeRect(x: number, y: number, width: number, height: number): void;
40
42
  fillText(text: string, x: number, y: number, maxWidth?: number): void;
41
- measureText(text: any): TextMetrics;
42
- getImageData(a0: any, a1: any, a2: any, a3: any): ImageData;
43
- lineTo(a0: any, a1: any): void;
44
- moveTo(a0: any, a1: any): void;
45
- rect(a0: any, a1: any, a2: any, a3: any): void;
46
- putImageData(a0: any, a1: any, a2: any): void;
47
- quadraticCurveTo(a0: any, a1: any, a2: any, a3: any): void;
43
+ measureText(text: string): TextMetrics;
44
+ getImageData(a0: number, a1: number, a2: number, a3: number): ImageData;
45
+ lineTo(a0: number, a1: number): void;
46
+ moveTo(a0: number, a1: number): void;
47
+ rect(a0: number, a1: number, a2: number, a3: number): void;
48
+ putImageData(a0: ImageData, a1: number, a2: number): void;
49
+ quadraticCurveTo(a0: number, a1: number, a2: number, a3: number): void;
48
50
  restore(): void;
49
- rotate(a0: any): void;
51
+ rotate(a0: number): void;
50
52
  save(): void;
51
- scale(a0: any, a1: any): void;
52
- setLineDash(a0: any): void;
53
+ scale(a0: number, a1: number): void;
54
+ setLineDash(a0: number[]): void;
53
55
  getLineDash(): number[];
54
- setTransform(a0: any, a1: any, a2: any, a3: any, a4: any, a5: any): void;
56
+ setTransform(a0: number, a1: number, a2: number, a3: number, a4: number, a5: number): void;
55
57
  stroke(path2d?: Path2D): void;
56
- strokeText(a0: any, a1: any, a2: any, a3: any): void;
57
- transform(a0: any, a1: any, a2: any, a3: any, a4: any, a5: any): void;
58
- translate(a0: any, a1: any): void;
58
+ strokeText(a0: string, a1: number, a2: number, a3: number): void;
59
+ transform(a0: number, a1: number, a2: number, a3: number, a4: number, a5: number): void;
60
+ translate(a0: number, a1: number): void;
59
61
  _enableTrace(): void;
60
62
  _applyGlobalCompositeOperation(node: any): void;
61
63
  }
64
+ type CanvasContextProps = Pick<CanvasRenderingContext2D, typeof CONTEXT_PROPERTIES[number]>;
65
+ export interface Context extends CanvasContextProps {
66
+ }
62
67
  export declare class SceneContext extends Context {
63
68
  constructor(canvas: Canvas);
64
69
  _fillColor(shape: Shape): void;
@@ -76,3 +81,4 @@ export declare class HitContext extends Context {
76
81
  strokeShape(shape: Shape): void;
77
82
  _stroke(shape: any): void;
78
83
  }
84
+ export {};
package/lib/Context.js CHANGED
@@ -234,8 +234,11 @@ export class Context {
234
234
  ellipse(a0, a1, a2, a3, a4, a5, a6, a7) {
235
235
  this._context.ellipse(a0, a1, a2, a3, a4, a5, a6, a7);
236
236
  }
237
- isPointInPath(x, y) {
238
- return this._context.isPointInPath(x, y);
237
+ isPointInPath(x, y, path, fillRule) {
238
+ if (path) {
239
+ return this._context.isPointInPath(path, x, y, fillRule);
240
+ }
241
+ return this._context.isPointInPath(x, y, fillRule);
239
242
  }
240
243
  fill(path2d) {
241
244
  if (path2d) {
@@ -366,6 +369,7 @@ export class Context {
366
369
  }
367
370
  }
368
371
  }
372
+ ;
369
373
  CONTEXT_PROPERTIES.forEach(function (prop) {
370
374
  Object.defineProperty(Context.prototype, prop, {
371
375
  get() {
package/lib/Global.d.ts CHANGED
@@ -27,6 +27,7 @@ export declare const Konva: {
27
27
  dragButtons: number[];
28
28
  isDragging(): any;
29
29
  isDragReady(): boolean;
30
+ releaseCanvasOnDestroy: boolean;
30
31
  document: any;
31
32
  _injectGlobal(Konva: any): void;
32
33
  };
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.13',
16
+ version: '8.4.0',
17
17
  isBrowser: detectBrowser(),
18
18
  isUnminified: /param/.test(function (param) { }.toString()),
19
19
  dblClickWindow: 400,
@@ -45,6 +45,7 @@ export const Konva = {
45
45
  isDragReady() {
46
46
  return !!Konva['DD'].node;
47
47
  },
48
+ releaseCanvasOnDestroy: true,
48
49
  document: glob.document,
49
50
  _injectGlobal(Konva) {
50
51
  glob.Konva = Konva;
package/lib/Layer.d.ts CHANGED
@@ -54,6 +54,7 @@ export declare class Layer extends Container<Group | Shape> {
54
54
  setHitGraphEnabled(val: any): void;
55
55
  getHitGraphEnabled(val: any): boolean;
56
56
  toggleHitCanvas(): void;
57
+ destroy(): this;
57
58
  hitGraphEnabled: GetSet<boolean, this>;
58
59
  clearBeforeDraw: GetSet<boolean, this>;
59
60
  imageSmoothingEnabled: GetSet<boolean, this>;
package/lib/Layer.js CHANGED
@@ -293,6 +293,10 @@ export class Layer extends Container {
293
293
  parent.content.appendChild(this.hitCanvas._canvas);
294
294
  }
295
295
  }
296
+ destroy() {
297
+ Util.releaseCanvas(this.getNativeCanvasElement(), this.getHitCanvas()._canvas);
298
+ return super.destroy();
299
+ }
296
300
  }
297
301
  Layer.prototype.nodeType = 'Layer';
298
302
  _registerNode(Layer);
package/lib/Node.d.ts CHANGED
@@ -6,8 +6,8 @@ import { Stage } from './Stage';
6
6
  import { Context } from './Context';
7
7
  import { Shape } from './Shape';
8
8
  import { Layer } from './Layer';
9
- export declare type Filter = (this: Node, imageData: ImageData) => void;
10
- declare type globalCompositeOperationType = '' | 'source-over' | 'source-in' | 'source-out' | 'source-atop' | 'destination-over' | 'destination-in' | 'destination-out' | 'destination-atop' | 'lighter' | 'copy' | 'xor' | 'multiply' | 'screen' | 'overlay' | 'darken' | 'lighten' | 'color-dodge' | 'color-burn' | 'hard-light' | 'soft-light' | 'difference' | 'exclusion' | 'hue' | 'saturation' | 'color' | 'luminosity';
9
+ export type Filter = (this: Node, imageData: ImageData) => void;
10
+ type globalCompositeOperationType = '' | 'source-over' | 'source-in' | 'source-out' | 'source-atop' | 'destination-over' | 'destination-in' | 'destination-out' | 'destination-atop' | 'lighter' | 'copy' | 'xor' | 'multiply' | 'screen' | 'overlay' | 'darken' | 'lighten' | 'color-dodge' | 'color-burn' | 'hard-light' | 'soft-light' | 'difference' | 'exclusion' | 'hue' | 'saturation' | 'color' | 'luminosity';
11
11
  export interface NodeConfig {
12
12
  [index: string]: any;
13
13
  x?: number;
@@ -34,7 +34,7 @@ export interface NodeConfig {
34
34
  globalCompositeOperation?: globalCompositeOperationType;
35
35
  filters?: Array<Filter>;
36
36
  }
37
- declare type NodeEventMap = GlobalEventHandlersEventMap & {
37
+ type NodeEventMap = GlobalEventHandlersEventMap & {
38
38
  [index: string]: any;
39
39
  };
40
40
  export interface KonvaEventObject<EventType> {
@@ -45,7 +45,7 @@ export interface KonvaEventObject<EventType> {
45
45
  cancelBubble: boolean;
46
46
  child?: Node;
47
47
  }
48
- export declare type KonvaEventListener<This, EventType> = (this: This, ev: KonvaEventObject<EventType>) => void;
48
+ export type KonvaEventListener<This, EventType> = (this: This, ev: KonvaEventObject<EventType>) => void;
49
49
  export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
50
50
  _id: number;
51
51
  eventListeners: {
@@ -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): Node<NodeConfig>;
182
+ findAncestor(selector?: string, includeSelf?: boolean, stopNode?: Container): any;
183
183
  _isMatch(selector: string | Function): any;
184
184
  getLayer(): Layer | null;
185
185
  getStage(): Stage | null;
package/lib/Node.js CHANGED
@@ -82,7 +82,11 @@ export class Node {
82
82
  }
83
83
  }
84
84
  clearCache() {
85
- this._cache.delete(CANVAS);
85
+ if (this._cache.has(CANVAS)) {
86
+ const { scene, filter, hit } = this._cache.get(CANVAS);
87
+ Util.releaseCanvas(scene, filter, hit);
88
+ this._cache.delete(CANVAS);
89
+ }
86
90
  this._clearSelfAndDescendantCache();
87
91
  this._requestDraw();
88
92
  return this;
@@ -350,6 +354,7 @@ export class Node {
350
354
  }
351
355
  destroy() {
352
356
  this.remove();
357
+ this.clearCache();
353
358
  return this;
354
359
  }
355
360
  getAttr(attr) {
@@ -4,7 +4,7 @@ import { Stage } from './Stage';
4
4
  export interface KonvaPointerEvent extends KonvaEventObject<PointerEvent> {
5
5
  pointerId: number;
6
6
  }
7
- export declare function getCapturedShape(pointerId: number): Stage | Shape<import("./Shape").ShapeConfig>;
7
+ export declare function getCapturedShape(pointerId: number): Shape<import("./Shape").ShapeConfig> | Stage;
8
8
  export declare function createEvent(evt: PointerEvent): KonvaPointerEvent;
9
9
  export declare function hasPointerCapture(pointerId: number, shape: Shape | Stage): boolean;
10
10
  export declare function setPointerCapture(pointerId: number, shape: Shape | Stage): void;
package/lib/Shape.d.ts CHANGED
@@ -2,11 +2,11 @@ import { Node, NodeConfig } from './Node';
2
2
  import { Context } from './Context';
3
3
  import { GetSet, Vector2d } from './types';
4
4
  import { HitCanvas, SceneCanvas } from './Canvas';
5
- export declare type ShapeConfigHandler<TTarget> = {
5
+ export type ShapeConfigHandler<TTarget> = {
6
6
  bivarianceHack(ctx: Context, shape: TTarget): void;
7
7
  }['bivarianceHack'];
8
- export declare type LineJoin = 'round' | 'bevel' | 'miter';
9
- export declare type LineCap = 'butt' | 'round' | 'square';
8
+ export type LineJoin = 'round' | 'bevel' | 'miter';
9
+ export type LineCap = 'butt' | 'round' | 'square';
10
10
  export interface ShapeConfig extends NodeConfig {
11
11
  fill?: string;
12
12
  fillPatternImage?: HTMLImageElement;
package/lib/Stage.js CHANGED
@@ -179,6 +179,7 @@ export class Stage extends Container {
179
179
  if (index > -1) {
180
180
  stages.splice(index, 1);
181
181
  }
182
+ Util.releaseCanvas(this.bufferCanvas._canvas, this.bufferHitCanvas._canvas);
182
183
  return this;
183
184
  }
184
185
  getPointerPosition() {
package/lib/Util.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { Context } from './Context';
1
2
  import { IRect, RGB, RGBA, Vector2d } from './types';
2
3
  export declare class Transform {
3
4
  m: Array<number>;
@@ -60,7 +61,9 @@ export declare const Util: {
60
61
  };
61
62
  _rgbColorToRGBA(str: string): RGBA;
62
63
  _rgbaColorToRGBA(str: string): RGBA;
64
+ _hex8ColorToRGBA(str: string): RGBA;
63
65
  _hex6ColorToRGBA(str: string): RGBA;
66
+ _hex4ColorToRGBA(str: string): RGBA;
64
67
  _hex3ColorToRGBA(str: string): RGBA;
65
68
  _hslColorToRGBA(str: string): RGBA;
66
69
  haveIntersection(r1: IRect, r2: IRect): boolean;
@@ -83,4 +86,6 @@ export declare const Util: {
83
86
  _prepareToStringify(obj: any): any;
84
87
  _assign<T, U>(target: T, source: U): T & U;
85
88
  _getFirstPointerId(evt: any): any;
89
+ releaseCanvas(...canvases: HTMLCanvasElement[]): void;
90
+ drawRoundedRectPath(context: Context, width: number, height: number, cornerRadius: number | number[]): void;
86
91
  };
package/lib/Util.js CHANGED
@@ -438,7 +438,9 @@ export const Util = {
438
438
  str = str || 'black';
439
439
  return (Util._namedColorToRBA(str) ||
440
440
  Util._hex3ColorToRGBA(str) ||
441
+ Util._hex4ColorToRGBA(str) ||
441
442
  Util._hex6ColorToRGBA(str) ||
443
+ Util._hex8ColorToRGBA(str) ||
442
444
  Util._rgbColorToRGBA(str) ||
443
445
  Util._rgbaColorToRGBA(str) ||
444
446
  Util._hslColorToRGBA(str));
@@ -484,6 +486,16 @@ export const Util = {
484
486
  };
485
487
  }
486
488
  },
489
+ _hex8ColorToRGBA(str) {
490
+ if (str[0] === '#' && str.length === 9) {
491
+ return {
492
+ r: parseInt(str.slice(1, 3), 16),
493
+ g: parseInt(str.slice(3, 5), 16),
494
+ b: parseInt(str.slice(5, 7), 16),
495
+ a: parseInt(str.slice(7, 9), 16) / 0xff,
496
+ };
497
+ }
498
+ },
487
499
  _hex6ColorToRGBA(str) {
488
500
  if (str[0] === '#' && str.length === 7) {
489
501
  return {
@@ -494,6 +506,16 @@ export const Util = {
494
506
  };
495
507
  }
496
508
  },
509
+ _hex4ColorToRGBA(str) {
510
+ if (str[0] === '#' && str.length === 5) {
511
+ return {
512
+ r: parseInt(str[1] + str[1], 16),
513
+ g: parseInt(str[2] + str[2], 16),
514
+ b: parseInt(str[3] + str[3], 16),
515
+ a: parseInt(str[4] + str[4], 16) / 0xff,
516
+ };
517
+ }
518
+ },
497
519
  _hex3ColorToRGBA(str) {
498
520
  if (str[0] === '#' && str.length === 4) {
499
521
  return {
@@ -740,4 +762,36 @@ export const Util = {
740
762
  return evt.changedTouches[0].identifier;
741
763
  }
742
764
  },
765
+ releaseCanvas(...canvases) {
766
+ if (!Konva.releaseCanvasOnDestroy)
767
+ return;
768
+ canvases.forEach(c => {
769
+ c.width = 0;
770
+ c.height = 0;
771
+ });
772
+ },
773
+ drawRoundedRectPath(context, width, height, cornerRadius) {
774
+ let topLeft = 0;
775
+ let topRight = 0;
776
+ let bottomLeft = 0;
777
+ let bottomRight = 0;
778
+ if (typeof cornerRadius === 'number') {
779
+ topLeft = topRight = bottomLeft = bottomRight = Math.min(cornerRadius, width / 2, height / 2);
780
+ }
781
+ else {
782
+ topLeft = Math.min(cornerRadius[0] || 0, width / 2, height / 2);
783
+ topRight = Math.min(cornerRadius[1] || 0, width / 2, height / 2);
784
+ bottomRight = Math.min(cornerRadius[2] || 0, width / 2, height / 2);
785
+ bottomLeft = Math.min(cornerRadius[3] || 0, width / 2, height / 2);
786
+ }
787
+ context.moveTo(topLeft, 0);
788
+ context.lineTo(width - topRight, 0);
789
+ context.arc(width - topRight, topRight, topRight, (Math.PI * 3) / 2, 0, false);
790
+ context.lineTo(width, height - bottomRight);
791
+ context.arc(width - bottomRight, height - bottomRight, bottomRight, 0, Math.PI / 2, false);
792
+ context.lineTo(bottomLeft, height);
793
+ context.arc(bottomLeft, height - bottomLeft, bottomLeft, Math.PI / 2, Math.PI, false);
794
+ context.lineTo(0, topLeft);
795
+ context.arc(topLeft, topLeft, topLeft, Math.PI, (Math.PI * 3) / 2, false);
796
+ }
743
797
  };
@@ -38,6 +38,7 @@ export declare const Konva: {
38
38
  dragButtons: number[];
39
39
  isDragging(): any;
40
40
  isDragReady(): boolean;
41
+ releaseCanvasOnDestroy: boolean;
41
42
  document: any;
42
43
  _injectGlobal(Konva: any): void;
43
44
  } & {
@@ -70,7 +71,9 @@ export declare const Konva: {
70
71
  };
71
72
  _rgbColorToRGBA(str: string): import("./types").RGBA;
72
73
  _rgbaColorToRGBA(str: string): import("./types").RGBA;
74
+ _hex8ColorToRGBA(str: string): import("./types").RGBA;
73
75
  _hex6ColorToRGBA(str: string): import("./types").RGBA;
76
+ _hex4ColorToRGBA(str: string): import("./types").RGBA;
74
77
  _hex3ColorToRGBA(str: string): import("./types").RGBA;
75
78
  _hslColorToRGBA(str: string): import("./types").RGBA;
76
79
  haveIntersection(r1: import("./types").IRect, r2: import("./types").IRect): boolean;
@@ -93,6 +96,8 @@ export declare const Konva: {
93
96
  _prepareToStringify(obj: any): any;
94
97
  _assign<T, U>(target: T, source: U): T & U;
95
98
  _getFirstPointerId(evt: any): any;
99
+ releaseCanvas(...canvases: HTMLCanvasElement[]): void;
100
+ drawRoundedRectPath(context: Context, width: number, height: number, cornerRadius: number | number[]): void;
96
101
  };
97
102
  Transform: typeof Transform;
98
103
  Node: typeof Node;
@@ -43,6 +43,7 @@ export declare const Konva: {
43
43
  dragButtons: number[];
44
44
  isDragging(): any;
45
45
  isDragReady(): boolean;
46
+ releaseCanvasOnDestroy: boolean;
46
47
  document: any;
47
48
  _injectGlobal(Konva: any): void;
48
49
  } & {
@@ -75,7 +76,9 @@ export declare const Konva: {
75
76
  };
76
77
  _rgbColorToRGBA(str: string): import("./types").RGBA;
77
78
  _rgbaColorToRGBA(str: string): import("./types").RGBA;
79
+ _hex8ColorToRGBA(str: string): import("./types").RGBA;
78
80
  _hex6ColorToRGBA(str: string): import("./types").RGBA;
81
+ _hex4ColorToRGBA(str: string): import("./types").RGBA;
79
82
  _hex3ColorToRGBA(str: string): import("./types").RGBA;
80
83
  _hslColorToRGBA(str: string): import("./types").RGBA;
81
84
  haveIntersection(r1: import("./types").IRect, r2: import("./types").IRect): boolean;
@@ -98,6 +101,8 @@ export declare const Konva: {
98
101
  _prepareToStringify(obj: any): any;
99
102
  _assign<T, U>(target: T, source: U): T & U;
100
103
  _getFirstPointerId(evt: any): any;
104
+ releaseCanvas(...canvases: HTMLCanvasElement[]): void;
105
+ drawRoundedRectPath(context: import("./Context").Context, width: number, height: number, cornerRadius: number | number[]): void;
101
106
  };
102
107
  Transform: typeof import("./Util").Transform;
103
108
  Node: typeof import("./Node").Node;
@@ -76,6 +76,7 @@ export const Kaleidoscope = function (imageData) {
76
76
  var scratchData = tempCanvas
77
77
  .getContext('2d')
78
78
  .getImageData(0, 0, xSize, ySize);
79
+ Util.releaseCanvas(tempCanvas);
79
80
  ToPolar(imageData, scratchData, {
80
81
  polarCenterX: xSize / 2,
81
82
  polarCenterY: ySize / 2,
@@ -4,6 +4,7 @@ import { Context } from '../Context';
4
4
  export interface ImageConfig extends ShapeConfig {
5
5
  image: CanvasImageSource | undefined;
6
6
  crop?: IRect;
7
+ cornerRadius?: number | number[];
7
8
  }
8
9
  export declare class Image extends Shape<ImageConfig> {
9
10
  constructor(attrs: ImageConfig);
@@ -20,4 +21,5 @@ export declare class Image extends Shape<ImageConfig> {
20
21
  cropY: GetSet<number, this>;
21
22
  cropWidth: GetSet<number, this>;
22
23
  cropHeight: GetSet<number, this>;
24
+ cornerRadius: GetSet<number | number[], this>;
23
25
  }
@@ -1,8 +1,8 @@
1
1
  import { Util } from '../Util.js';
2
2
  import { Factory } from '../Factory.js';
3
3
  import { Shape } from '../Shape.js';
4
- import { getNumberValidator } from '../Validators.js';
5
4
  import { _registerNode } from '../Global.js';
5
+ import { getNumberOrArrayOfNumbersValidator, getNumberValidator, } from '../Validators.js';
6
6
  export class Image extends Shape {
7
7
  constructor(attrs) {
8
8
  super(attrs);
@@ -31,6 +31,7 @@ export class Image extends Shape {
31
31
  _sceneFunc(context) {
32
32
  const width = this.getWidth();
33
33
  const height = this.getHeight();
34
+ const cornerRadius = this.cornerRadius();
34
35
  const image = this.attrs.image;
35
36
  let params;
36
37
  if (image) {
@@ -53,20 +54,30 @@ export class Image extends Shape {
53
54
  params = [image, 0, 0, width, height];
54
55
  }
55
56
  }
56
- if (this.hasFill() || this.hasStroke()) {
57
+ if (this.hasFill() || this.hasStroke() || cornerRadius) {
57
58
  context.beginPath();
58
- context.rect(0, 0, width, height);
59
+ cornerRadius
60
+ ? Util.drawRoundedRectPath(context, width, height, cornerRadius)
61
+ : context.rect(0, 0, width, height);
59
62
  context.closePath();
60
63
  context.fillStrokeShape(this);
61
64
  }
62
65
  if (image) {
66
+ if (cornerRadius) {
67
+ context.clip();
68
+ }
63
69
  context.drawImage.apply(context, params);
64
70
  }
65
71
  }
66
72
  _hitFunc(context) {
67
- var width = this.width(), height = this.height();
73
+ var width = this.width(), height = this.height(), cornerRadius = this.cornerRadius();
68
74
  context.beginPath();
69
- context.rect(0, 0, width, height);
75
+ if (!cornerRadius) {
76
+ context.rect(0, 0, width, height);
77
+ }
78
+ else {
79
+ Util.drawRoundedRectPath(context, width, height, cornerRadius);
80
+ }
70
81
  context.closePath();
71
82
  context.fillStrokeShape(this);
72
83
  }
@@ -93,6 +104,7 @@ export class Image extends Shape {
93
104
  }
94
105
  Image.prototype.className = 'Image';
95
106
  _registerNode(Image);
107
+ Factory.addGetterSetter(Image, 'cornerRadius', 0, getNumberOrArrayOfNumbersValidator(4));
96
108
  Factory.addGetterSetter(Image, 'image');
97
109
  Factory.addComponentsGetterSetter(Image, 'crop', ['x', 'y', 'width', 'height']);
98
110
  Factory.addGetterSetter(Image, 'cropX', 0, getNumberValidator());
@@ -1,9 +1,10 @@
1
1
  import { Shape, ShapeConfig } from '../Shape';
2
2
  import { GetSet } from '../types';
3
+ import { Context } from '../Context';
3
4
  export interface RectConfig extends ShapeConfig {
4
5
  cornerRadius?: number | number[];
5
6
  }
6
7
  export declare class Rect extends Shape<RectConfig> {
7
- _sceneFunc(context: any): void;
8
+ _sceneFunc(context: Context): void;
8
9
  cornerRadius: GetSet<number | number[], this>;
9
10
  }
@@ -1,6 +1,7 @@
1
1
  import { Factory } from '../Factory.js';
2
2
  import { Shape } from '../Shape.js';
3
3
  import { _registerNode } from '../Global.js';
4
+ import { Util } from '../Util.js';
4
5
  import { getNumberOrArrayOfNumbersValidator } from '../Validators.js';
5
6
  export class Rect extends Shape {
6
7
  _sceneFunc(context) {
@@ -10,28 +11,7 @@ export class Rect extends Shape {
10
11
  context.rect(0, 0, width, height);
11
12
  }
12
13
  else {
13
- let topLeft = 0;
14
- let topRight = 0;
15
- let bottomLeft = 0;
16
- let bottomRight = 0;
17
- if (typeof cornerRadius === 'number') {
18
- topLeft = topRight = bottomLeft = bottomRight = Math.min(cornerRadius, width / 2, height / 2);
19
- }
20
- else {
21
- topLeft = Math.min(cornerRadius[0] || 0, width / 2, height / 2);
22
- topRight = Math.min(cornerRadius[1] || 0, width / 2, height / 2);
23
- bottomRight = Math.min(cornerRadius[2] || 0, width / 2, height / 2);
24
- bottomLeft = Math.min(cornerRadius[3] || 0, width / 2, height / 2);
25
- }
26
- context.moveTo(topLeft, 0);
27
- context.lineTo(width - topRight, 0);
28
- context.arc(width - topRight, topRight, topRight, (Math.PI * 3) / 2, 0, false);
29
- context.lineTo(width, height - bottomRight);
30
- context.arc(width - bottomRight, height - bottomRight, bottomRight, 0, Math.PI / 2, false);
31
- context.lineTo(bottomLeft, height);
32
- context.arc(bottomLeft, height - bottomLeft, bottomLeft, Math.PI / 2, Math.PI, false);
33
- context.lineTo(0, topLeft);
34
- context.arc(topLeft, topLeft, topLeft, Math.PI, (Math.PI * 3) / 2, false);
14
+ Util.drawRoundedRectPath(context, width, height, cornerRadius);
35
15
  }
36
16
  context.closePath();
37
17
  context.fillStrokeShape(this);
@@ -40,6 +40,7 @@ export declare class TextPath extends Shape<TextPathConfig> {
40
40
  width: number;
41
41
  height: number;
42
42
  };
43
+ destroy(): this;
43
44
  fontFamily: GetSet<string, this>;
44
45
  fontSize: GetSet<number, this>;
45
46
  fontStyle: GetSet<string, this>;
@@ -322,6 +322,10 @@ export class TextPath extends Shape {
322
322
  height: maxY - minY + fontSize,
323
323
  };
324
324
  }
325
+ destroy() {
326
+ Util.releaseCanvas(this.dummyCanvas);
327
+ return super.destroy();
328
+ }
325
329
  }
326
330
  TextPath.prototype._fillFunc = _fillFunc;
327
331
  TextPath.prototype._strokeFunc = _strokeFunc;
@@ -86,6 +86,7 @@ export declare class Transformer extends Group {
86
86
  stopTransform(): void;
87
87
  destroy(): this;
88
88
  toObject(): any;
89
+ clone(obj?: any): this;
89
90
  getClientRect(): IRect;
90
91
  nodes: GetSet<Node[], this>;
91
92
  enabledAnchors: GetSet<string[], this>;
@@ -896,6 +896,10 @@ export class Transformer extends Group {
896
896
  toObject() {
897
897
  return Node.prototype.toObject.call(this);
898
898
  }
899
+ clone(obj) {
900
+ var node = Node.prototype.clone.call(this, obj);
901
+ return node;
902
+ }
899
903
  getClientRect() {
900
904
  if (this.nodes().length > 0) {
901
905
  return super.getClientRect();
package/lib/types.d.ts CHANGED
@@ -18,7 +18,7 @@ export interface IFrame {
18
18
  lastTime: number;
19
19
  frameRate: number;
20
20
  }
21
- export declare type AnimationFn = (frame?: IFrame) => boolean | void;
21
+ export type AnimationFn = (frame?: IFrame) => boolean | void;
22
22
  export declare enum KonvaNodeEvent {
23
23
  mouseover = "mouseover",
24
24
  mouseout = "mouseout",