konva 8.3.14 → 8.4.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.
package/lib/Container.js CHANGED
@@ -43,13 +43,16 @@ export class Container extends Node {
43
43
  return this;
44
44
  }
45
45
  add(...children) {
46
- if (arguments.length > 1) {
47
- for (var i = 0; i < arguments.length; i++) {
48
- this.add(arguments[i]);
46
+ if (children.length === 0) {
47
+ return this;
48
+ }
49
+ if (children.length > 1) {
50
+ for (var i = 0; i < children.length; i++) {
51
+ this.add(children[i]);
49
52
  }
50
53
  return this;
51
54
  }
52
- var child = children[0];
55
+ const child = children[0];
53
56
  if (child.getParent()) {
54
57
  child.moveTo(this);
55
58
  return this;
package/lib/Context.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { Canvas } from './Canvas';
2
2
  import { Shape } from './Shape';
3
+ import { IRect } from './types';
3
4
  declare var CONTEXT_PROPERTIES: readonly ["fillStyle", "strokeStyle", "shadowColor", "shadowBlur", "shadowOffsetX", "shadowOffsetY", "lineCap", "lineDashOffset", "lineJoin", "lineWidth", "miterLimit", "font", "textAlign", "textBaseline", "globalAlpha", "globalCompositeOperation", "imageSmoothingEnabled"];
4
5
  export declare class Context {
5
6
  canvas: Canvas;
@@ -7,7 +8,7 @@ export declare class Context {
7
8
  traceArr: Array<String>;
8
9
  constructor(canvas: Canvas);
9
10
  fillShape(shape: Shape): void;
10
- _fill(shape: any): void;
11
+ _fill(shape: Shape): void;
11
12
  strokeShape(shape: Shape): void;
12
13
  _stroke(shape: any): void;
13
14
  fillStrokeShape(shape: Shape): void;
@@ -16,51 +17,51 @@ export declare class Context {
16
17
  _trace(str: any): void;
17
18
  reset(): void;
18
19
  getCanvas(): Canvas;
19
- clear(bounds?: any): void;
20
+ clear(bounds?: IRect): void;
20
21
  _applyLineCap(shape: any): void;
21
22
  _applyOpacity(shape: any): void;
22
23
  _applyLineJoin(shape: Shape): void;
23
- setAttr(attr: any, val: any): void;
24
- arc(a0: any, a1: any, a2: any, a3: any, a4: any, a5: any): void;
25
- 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;
26
27
  beginPath(): void;
27
- bezierCurveTo(a0: any, a1: any, a2: any, a3: any, a4: any, a5: any): void;
28
- 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;
29
30
  clip(): void;
30
31
  closePath(): void;
31
32
  createImageData(a0: any, a1: any): ImageData;
32
- createLinearGradient(a0: any, a1: any, a2: any, a3: any): CanvasGradient;
33
- createPattern(a0: any, a1: any): CanvasPattern;
34
- 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;
35
36
  drawImage(a0: CanvasImageSource, a1: number, a2: number, a3?: number, a4?: number, a5?: number, a6?: number, a7?: number, a8?: number): void;
36
37
  ellipse(a0: number, a1: number, a2: number, a3: number, a4: number, a5: number, a6: number, a7?: boolean): void;
37
- isPointInPath(x: any, y: any): boolean;
38
+ isPointInPath(x: number, y: number, path?: Path2D, fillRule?: CanvasFillRule): boolean;
38
39
  fill(path2d?: Path2D): void;
39
- fillRect(x: any, y: any, width: any, height: any): void;
40
- 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;
41
42
  fillText(text: string, x: number, y: number, maxWidth?: number): void;
42
- measureText(text: any): TextMetrics;
43
- getImageData(a0: any, a1: any, a2: any, a3: any): ImageData;
44
- lineTo(a0: any, a1: any): void;
45
- moveTo(a0: any, a1: any): void;
46
- rect(a0: any, a1: any, a2: any, a3: any): void;
47
- putImageData(a0: any, a1: any, a2: any): void;
48
- 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;
49
50
  restore(): void;
50
- rotate(a0: any): void;
51
+ rotate(a0: number): void;
51
52
  save(): void;
52
- scale(a0: any, a1: any): void;
53
- setLineDash(a0: any): void;
53
+ scale(a0: number, a1: number): void;
54
+ setLineDash(a0: number[]): void;
54
55
  getLineDash(): number[];
55
- 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;
56
57
  stroke(path2d?: Path2D): void;
57
- strokeText(a0: any, a1: any, a2: any, a3: any): void;
58
- transform(a0: any, a1: any, a2: any, a3: any, a4: any, a5: any): void;
59
- 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;
60
61
  _enableTrace(): void;
61
62
  _applyGlobalCompositeOperation(node: any): void;
62
63
  }
63
- declare type CanvasContextProps = Pick<CanvasRenderingContext2D, typeof CONTEXT_PROPERTIES[number]>;
64
+ type CanvasContextProps = Pick<CanvasRenderingContext2D, typeof CONTEXT_PROPERTIES[number]>;
64
65
  export interface Context extends CanvasContextProps {
65
66
  }
66
67
  export declare class SceneContext extends Context {
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,7 +369,6 @@ export class Context {
366
369
  }
367
370
  }
368
371
  }
369
- ;
370
372
  CONTEXT_PROPERTIES.forEach(function (prop) {
371
373
  Object.defineProperty(Context.prototype, prop, {
372
374
  get() {
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.14',
16
+ version: '8.4.1',
17
17
  isBrowser: detectBrowser(),
18
18
  isUnminified: /param/.test(function (param) { }.toString()),
19
19
  dblClickWindow: 400,
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;
@@ -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/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;
@@ -84,4 +87,5 @@ export declare const Util: {
84
87
  _assign<T, U>(target: T, source: U): T & U;
85
88
  _getFirstPointerId(evt: any): any;
86
89
  releaseCanvas(...canvases: HTMLCanvasElement[]): void;
90
+ drawRoundedRectPath(context: Context, width: number, height: number, cornerRadius: number | number[]): void;
87
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 {
@@ -747,5 +769,29 @@ export const Util = {
747
769
  c.width = 0;
748
770
  c.height = 0;
749
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);
750
796
  }
751
797
  };
@@ -71,7 +71,9 @@ export declare const Konva: {
71
71
  };
72
72
  _rgbColorToRGBA(str: string): import("./types").RGBA;
73
73
  _rgbaColorToRGBA(str: string): import("./types").RGBA;
74
+ _hex8ColorToRGBA(str: string): import("./types").RGBA;
74
75
  _hex6ColorToRGBA(str: string): import("./types").RGBA;
76
+ _hex4ColorToRGBA(str: string): import("./types").RGBA;
75
77
  _hex3ColorToRGBA(str: string): import("./types").RGBA;
76
78
  _hslColorToRGBA(str: string): import("./types").RGBA;
77
79
  haveIntersection(r1: import("./types").IRect, r2: import("./types").IRect): boolean;
@@ -95,6 +97,7 @@ export declare const Konva: {
95
97
  _assign<T, U>(target: T, source: U): T & U;
96
98
  _getFirstPointerId(evt: any): any;
97
99
  releaseCanvas(...canvases: HTMLCanvasElement[]): void;
100
+ drawRoundedRectPath(context: Context, width: number, height: number, cornerRadius: number | number[]): void;
98
101
  };
99
102
  Transform: typeof Transform;
100
103
  Node: typeof Node;
@@ -76,7 +76,9 @@ export declare const Konva: {
76
76
  };
77
77
  _rgbColorToRGBA(str: string): import("./types").RGBA;
78
78
  _rgbaColorToRGBA(str: string): import("./types").RGBA;
79
+ _hex8ColorToRGBA(str: string): import("./types").RGBA;
79
80
  _hex6ColorToRGBA(str: string): import("./types").RGBA;
81
+ _hex4ColorToRGBA(str: string): import("./types").RGBA;
80
82
  _hex3ColorToRGBA(str: string): import("./types").RGBA;
81
83
  _hslColorToRGBA(str: string): import("./types").RGBA;
82
84
  haveIntersection(r1: import("./types").IRect, r2: import("./types").IRect): boolean;
@@ -100,6 +102,7 @@ export declare const Konva: {
100
102
  _assign<T, U>(target: T, source: U): T & U;
101
103
  _getFirstPointerId(evt: any): any;
102
104
  releaseCanvas(...canvases: HTMLCanvasElement[]): void;
105
+ drawRoundedRectPath(context: import("./Context").Context, width: number, height: number, cornerRadius: number | number[]): void;
103
106
  };
104
107
  Transform: typeof import("./Util").Transform;
105
108
  Node: typeof import("./Node").Node;
@@ -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);
@@ -107,12 +107,11 @@ export class Text extends Shape {
107
107
  spacesNumber = text.split(' ').length - 1;
108
108
  oneWord = spacesNumber === 0;
109
109
  lineWidth =
110
- align === JUSTIFY && lastLine && !oneWord
111
- ? totalWidth - padding * 2
112
- : width;
110
+ align === JUSTIFY && !lastLine ? totalWidth - padding * 2 : width;
113
111
  context.lineTo(lineTranslateX + Math.round(lineWidth), translateY + lineTranslateY + Math.round(fontSize / 2));
114
112
  context.lineWidth = fontSize / 15;
115
- context.strokeStyle = fill;
113
+ const gradient = this._getLinearGradient();
114
+ context.strokeStyle = gradient || fill;
116
115
  context.stroke();
117
116
  context.restore();
118
117
  }
@@ -128,7 +127,8 @@ export class Text extends Shape {
128
127
  : width;
129
128
  context.lineTo(lineTranslateX + Math.round(lineWidth), translateY + lineTranslateY);
130
129
  context.lineWidth = fontSize / 15;
131
- context.strokeStyle = fill;
130
+ const gradient = this._getLinearGradient();
131
+ context.strokeStyle = gradient || fill;
132
132
  context.stroke();
133
133
  context.restore();
134
134
  }
@@ -213,7 +213,8 @@ export class Text extends Shape {
213
213
  normalizeFontFamily(this.fontFamily()));
214
214
  }
215
215
  _addTextLine(line) {
216
- if (this.align() === JUSTIFY) {
216
+ const align = this.align();
217
+ if (align === JUSTIFY) {
217
218
  line = line.trim();
218
219
  }
219
220
  var width = this._getTextWidth(line);
@@ -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",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "konva",
3
- "version": "8.3.14",
3
+ "version": "8.4.1",
4
4
  "author": "Anton Lavrenov",
5
5
  "files": [
6
6
  "README.md",
@@ -52,7 +52,7 @@
52
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
- "rollup": "rollup -c",
55
+ "rollup": "rollup -c --bundleConfigAsCjs",
56
56
  "clean": "rm -rf ./lib && rm -rf ./types && rm -rf ./cmj && rm -rf ./test-build",
57
57
  "watch": "rollup -c -w",
58
58
  "size": "size-limit"
@@ -88,11 +88,11 @@
88
88
  }
89
89
  ],
90
90
  "devDependencies": {
91
- "@parcel/transformer-image": "2.7.0",
92
- "@size-limit/preset-big-lib": "^8.0.0",
93
- "@types/mocha": "^9.1.1",
94
- "canvas": "^2.9.3",
95
- "chai": "4.3.6",
91
+ "@parcel/transformer-image": "2.8.2",
92
+ "@size-limit/preset-big-lib": "^8.1.0",
93
+ "@types/mocha": "^10.0.1",
94
+ "canvas": "^2.10.2",
95
+ "chai": "4.3.7",
96
96
  "filehound": "^1.17.6",
97
97
  "gulp": "^4.0.2",
98
98
  "gulp-concat": "^2.6.1",
@@ -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": "10.0.0",
108
+ "mocha": "10.2.0",
109
109
  "mocha-headless-chrome": "^4.0.0",
110
- "parcel": "2.7.0",
110
+ "parcel": "2.8.2",
111
111
  "process": "^0.11.10",
112
- "rollup": "^2.77.2",
112
+ "rollup": "^3.7.5",
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.32.1",
117
- "size-limit": "^8.0.0",
116
+ "rollup-plugin-typescript2": "^0.34.1",
117
+ "size-limit": "^8.1.0",
118
118
  "ts-mocha": "^10.0.0",
119
119
  "ts-node": "^10.9.1",
120
- "typescript": "^4.7.4"
120
+ "typescript": "^4.9.4"
121
121
  },
122
122
  "keywords": [
123
123
  "canvas",