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/cmj/Canvas.js CHANGED
@@ -22,6 +22,7 @@ function getDevicePixelRatio() {
22
22
  1;
23
23
  return devicePixelRatio / backingStoreRatio;
24
24
  })();
25
+ Util_1.Util.releaseCanvas(canvas);
25
26
  return _pixelRatio;
26
27
  }
27
28
  class Canvas {
package/cmj/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/cmj/Context.js CHANGED
@@ -237,8 +237,11 @@ class Context {
237
237
  ellipse(a0, a1, a2, a3, a4, a5, a6, a7) {
238
238
  this._context.ellipse(a0, a1, a2, a3, a4, a5, a6, a7);
239
239
  }
240
- isPointInPath(x, y) {
241
- return this._context.isPointInPath(x, y);
240
+ isPointInPath(x, y, path, fillRule) {
241
+ if (path) {
242
+ return this._context.isPointInPath(path, x, y, fillRule);
243
+ }
244
+ return this._context.isPointInPath(x, y, fillRule);
242
245
  }
243
246
  fill(path2d) {
244
247
  if (path2d) {
@@ -370,6 +373,7 @@ class Context {
370
373
  }
371
374
  }
372
375
  exports.Context = Context;
376
+ ;
373
377
  CONTEXT_PROPERTIES.forEach(function (prop) {
374
378
  Object.defineProperty(Context.prototype, prop, {
375
379
  get() {
package/cmj/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/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.13',
19
+ version: '8.4.0',
20
20
  isBrowser: detectBrowser(),
21
21
  isUnminified: /param/.test(function (param) { }.toString()),
22
22
  dblClickWindow: 400,
@@ -48,6 +48,7 @@ exports.Konva = {
48
48
  isDragReady() {
49
49
  return !!exports.Konva['DD'].node;
50
50
  },
51
+ releaseCanvasOnDestroy: true,
51
52
  document: exports.glob.document,
52
53
  _injectGlobal(Konva) {
53
54
  exports.glob.Konva = Konva;
package/cmj/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/cmj/Layer.js CHANGED
@@ -296,6 +296,10 @@ class Layer extends Container_1.Container {
296
296
  parent.content.appendChild(this.hitCanvas._canvas);
297
297
  }
298
298
  }
299
+ destroy() {
300
+ Util_1.Util.releaseCanvas(this.getNativeCanvasElement(), this.getHitCanvas()._canvas);
301
+ return super.destroy();
302
+ }
299
303
  }
300
304
  exports.Layer = Layer;
301
305
  Layer.prototype.nodeType = 'Layer';
package/cmj/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/cmj/Node.js CHANGED
@@ -85,7 +85,11 @@ class Node {
85
85
  }
86
86
  }
87
87
  clearCache() {
88
- this._cache.delete(CANVAS);
88
+ if (this._cache.has(CANVAS)) {
89
+ const { scene, filter, hit } = this._cache.get(CANVAS);
90
+ Util_1.Util.releaseCanvas(scene, filter, hit);
91
+ this._cache.delete(CANVAS);
92
+ }
89
93
  this._clearSelfAndDescendantCache();
90
94
  this._requestDraw();
91
95
  return this;
@@ -353,6 +357,7 @@ class Node {
353
357
  }
354
358
  destroy() {
355
359
  this.remove();
360
+ this.clearCache();
356
361
  return this;
357
362
  }
358
363
  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/cmj/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/cmj/Stage.js CHANGED
@@ -182,6 +182,7 @@ class Stage extends Container_1.Container {
182
182
  if (index > -1) {
183
183
  exports.stages.splice(index, 1);
184
184
  }
185
+ Util_1.Util.releaseCanvas(this.bufferCanvas._canvas, this.bufferHitCanvas._canvas);
185
186
  return this;
186
187
  }
187
188
  getPointerPosition() {
package/cmj/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/cmj/Util.js CHANGED
@@ -442,7 +442,9 @@ exports.Util = {
442
442
  str = str || 'black';
443
443
  return (exports.Util._namedColorToRBA(str) ||
444
444
  exports.Util._hex3ColorToRGBA(str) ||
445
+ exports.Util._hex4ColorToRGBA(str) ||
445
446
  exports.Util._hex6ColorToRGBA(str) ||
447
+ exports.Util._hex8ColorToRGBA(str) ||
446
448
  exports.Util._rgbColorToRGBA(str) ||
447
449
  exports.Util._rgbaColorToRGBA(str) ||
448
450
  exports.Util._hslColorToRGBA(str));
@@ -488,6 +490,16 @@ exports.Util = {
488
490
  };
489
491
  }
490
492
  },
493
+ _hex8ColorToRGBA(str) {
494
+ if (str[0] === '#' && str.length === 9) {
495
+ return {
496
+ r: parseInt(str.slice(1, 3), 16),
497
+ g: parseInt(str.slice(3, 5), 16),
498
+ b: parseInt(str.slice(5, 7), 16),
499
+ a: parseInt(str.slice(7, 9), 16) / 0xff,
500
+ };
501
+ }
502
+ },
491
503
  _hex6ColorToRGBA(str) {
492
504
  if (str[0] === '#' && str.length === 7) {
493
505
  return {
@@ -498,6 +510,16 @@ exports.Util = {
498
510
  };
499
511
  }
500
512
  },
513
+ _hex4ColorToRGBA(str) {
514
+ if (str[0] === '#' && str.length === 5) {
515
+ return {
516
+ r: parseInt(str[1] + str[1], 16),
517
+ g: parseInt(str[2] + str[2], 16),
518
+ b: parseInt(str[3] + str[3], 16),
519
+ a: parseInt(str[4] + str[4], 16) / 0xff,
520
+ };
521
+ }
522
+ },
501
523
  _hex3ColorToRGBA(str) {
502
524
  if (str[0] === '#' && str.length === 4) {
503
525
  return {
@@ -744,4 +766,36 @@ exports.Util = {
744
766
  return evt.changedTouches[0].identifier;
745
767
  }
746
768
  },
769
+ releaseCanvas(...canvases) {
770
+ if (!Global_1.Konva.releaseCanvasOnDestroy)
771
+ return;
772
+ canvases.forEach(c => {
773
+ c.width = 0;
774
+ c.height = 0;
775
+ });
776
+ },
777
+ drawRoundedRectPath(context, width, height, cornerRadius) {
778
+ let topLeft = 0;
779
+ let topRight = 0;
780
+ let bottomLeft = 0;
781
+ let bottomRight = 0;
782
+ if (typeof cornerRadius === 'number') {
783
+ topLeft = topRight = bottomLeft = bottomRight = Math.min(cornerRadius, width / 2, height / 2);
784
+ }
785
+ else {
786
+ topLeft = Math.min(cornerRadius[0] || 0, width / 2, height / 2);
787
+ topRight = Math.min(cornerRadius[1] || 0, width / 2, height / 2);
788
+ bottomRight = Math.min(cornerRadius[2] || 0, width / 2, height / 2);
789
+ bottomLeft = Math.min(cornerRadius[3] || 0, width / 2, height / 2);
790
+ }
791
+ context.moveTo(topLeft, 0);
792
+ context.lineTo(width - topRight, 0);
793
+ context.arc(width - topRight, topRight, topRight, (Math.PI * 3) / 2, 0, false);
794
+ context.lineTo(width, height - bottomRight);
795
+ context.arc(width - bottomRight, height - bottomRight, bottomRight, 0, Math.PI / 2, false);
796
+ context.lineTo(bottomLeft, height);
797
+ context.arc(bottomLeft, height - bottomLeft, bottomLeft, Math.PI / 2, Math.PI, false);
798
+ context.lineTo(0, topLeft);
799
+ context.arc(topLeft, topLeft, topLeft, Math.PI, (Math.PI * 3) / 2, false);
800
+ }
747
801
  };
@@ -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;
@@ -79,6 +79,7 @@ const Kaleidoscope = function (imageData) {
79
79
  var scratchData = tempCanvas
80
80
  .getContext('2d')
81
81
  .getImageData(0, 0, xSize, ySize);
82
+ Util_1.Util.releaseCanvas(tempCanvas);
82
83
  ToPolar(imageData, scratchData, {
83
84
  polarCenterX: xSize / 2,
84
85
  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
  }
@@ -4,8 +4,8 @@ exports.Image = void 0;
4
4
  const Util_1 = require("../Util");
5
5
  const Factory_1 = require("../Factory");
6
6
  const Shape_1 = require("../Shape");
7
- const Validators_1 = require("../Validators");
8
7
  const Global_1 = require("../Global");
8
+ const Validators_1 = require("../Validators");
9
9
  class Image extends Shape_1.Shape {
10
10
  constructor(attrs) {
11
11
  super(attrs);
@@ -34,6 +34,7 @@ class Image extends Shape_1.Shape {
34
34
  _sceneFunc(context) {
35
35
  const width = this.getWidth();
36
36
  const height = this.getHeight();
37
+ const cornerRadius = this.cornerRadius();
37
38
  const image = this.attrs.image;
38
39
  let params;
39
40
  if (image) {
@@ -56,20 +57,30 @@ class Image extends Shape_1.Shape {
56
57
  params = [image, 0, 0, width, height];
57
58
  }
58
59
  }
59
- if (this.hasFill() || this.hasStroke()) {
60
+ if (this.hasFill() || this.hasStroke() || cornerRadius) {
60
61
  context.beginPath();
61
- context.rect(0, 0, width, height);
62
+ cornerRadius
63
+ ? Util_1.Util.drawRoundedRectPath(context, width, height, cornerRadius)
64
+ : context.rect(0, 0, width, height);
62
65
  context.closePath();
63
66
  context.fillStrokeShape(this);
64
67
  }
65
68
  if (image) {
69
+ if (cornerRadius) {
70
+ context.clip();
71
+ }
66
72
  context.drawImage.apply(context, params);
67
73
  }
68
74
  }
69
75
  _hitFunc(context) {
70
- var width = this.width(), height = this.height();
76
+ var width = this.width(), height = this.height(), cornerRadius = this.cornerRadius();
71
77
  context.beginPath();
72
- context.rect(0, 0, width, height);
78
+ if (!cornerRadius) {
79
+ context.rect(0, 0, width, height);
80
+ }
81
+ else {
82
+ Util_1.Util.drawRoundedRectPath(context, width, height, cornerRadius);
83
+ }
73
84
  context.closePath();
74
85
  context.fillStrokeShape(this);
75
86
  }
@@ -97,6 +108,7 @@ class Image extends Shape_1.Shape {
97
108
  exports.Image = Image;
98
109
  Image.prototype.className = 'Image';
99
110
  (0, Global_1._registerNode)(Image);
111
+ Factory_1.Factory.addGetterSetter(Image, 'cornerRadius', 0, (0, Validators_1.getNumberOrArrayOfNumbersValidator)(4));
100
112
  Factory_1.Factory.addGetterSetter(Image, 'image');
101
113
  Factory_1.Factory.addComponentsGetterSetter(Image, 'crop', ['x', 'y', 'width', 'height']);
102
114
  Factory_1.Factory.addGetterSetter(Image, 'cropX', 0, (0, Validators_1.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
  }
@@ -4,6 +4,7 @@ exports.Rect = void 0;
4
4
  const Factory_1 = require("../Factory");
5
5
  const Shape_1 = require("../Shape");
6
6
  const Global_1 = require("../Global");
7
+ const Util_1 = require("../Util");
7
8
  const Validators_1 = require("../Validators");
8
9
  class Rect extends Shape_1.Shape {
9
10
  _sceneFunc(context) {
@@ -13,28 +14,7 @@ class Rect extends Shape_1.Shape {
13
14
  context.rect(0, 0, width, height);
14
15
  }
15
16
  else {
16
- let topLeft = 0;
17
- let topRight = 0;
18
- let bottomLeft = 0;
19
- let bottomRight = 0;
20
- if (typeof cornerRadius === 'number') {
21
- topLeft = topRight = bottomLeft = bottomRight = Math.min(cornerRadius, width / 2, height / 2);
22
- }
23
- else {
24
- topLeft = Math.min(cornerRadius[0] || 0, width / 2, height / 2);
25
- topRight = Math.min(cornerRadius[1] || 0, width / 2, height / 2);
26
- bottomRight = Math.min(cornerRadius[2] || 0, width / 2, height / 2);
27
- bottomLeft = Math.min(cornerRadius[3] || 0, width / 2, height / 2);
28
- }
29
- context.moveTo(topLeft, 0);
30
- context.lineTo(width - topRight, 0);
31
- context.arc(width - topRight, topRight, topRight, (Math.PI * 3) / 2, 0, false);
32
- context.lineTo(width, height - bottomRight);
33
- context.arc(width - bottomRight, height - bottomRight, bottomRight, 0, Math.PI / 2, false);
34
- context.lineTo(bottomLeft, height);
35
- context.arc(bottomLeft, height - bottomLeft, bottomLeft, Math.PI / 2, Math.PI, false);
36
- context.lineTo(0, topLeft);
37
- context.arc(topLeft, topLeft, topLeft, Math.PI, (Math.PI * 3) / 2, false);
17
+ Util_1.Util.drawRoundedRectPath(context, width, height, cornerRadius);
38
18
  }
39
19
  context.closePath();
40
20
  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>;
@@ -325,6 +325,10 @@ class TextPath extends Shape_1.Shape {
325
325
  height: maxY - minY + fontSize,
326
326
  };
327
327
  }
328
+ destroy() {
329
+ Util_1.Util.releaseCanvas(this.dummyCanvas);
330
+ return super.destroy();
331
+ }
328
332
  }
329
333
  exports.TextPath = TextPath;
330
334
  TextPath.prototype._fillFunc = _fillFunc;
@@ -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>;
@@ -899,6 +899,10 @@ class Transformer extends Group_1.Group {
899
899
  toObject() {
900
900
  return Node_1.Node.prototype.toObject.call(this);
901
901
  }
902
+ clone(obj) {
903
+ var node = Node_1.Node.prototype.clone.call(this, obj);
904
+ return node;
905
+ }
902
906
  getClientRect() {
903
907
  if (this.nodes().length > 0) {
904
908
  return super.getClientRect();
package/cmj/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",