konva 10.3.3 → 10.5.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 (123) hide show
  1. package/README.md +1 -1
  2. package/konva.js +1576 -1636
  3. package/konva.min.js +4 -4
  4. package/lib/Animation.d.ts +63 -3
  5. package/lib/Animation.js +86 -65
  6. package/lib/BezierFunctions.d.ts +10 -0
  7. package/lib/BezierFunctions.js +32 -0
  8. package/lib/Canvas.d.ts +53 -0
  9. package/lib/Canvas.js +93 -34
  10. package/lib/Container.d.ts +156 -9
  11. package/lib/Container.js +260 -25
  12. package/lib/Context.d.ts +247 -0
  13. package/lib/Context.js +312 -74
  14. package/lib/Core.js +1 -0
  15. package/lib/DragAndDrop.d.ts +2 -0
  16. package/lib/DragAndDrop.js +92 -21
  17. package/lib/Factory.d.ts +24 -1
  18. package/lib/Factory.js +14 -20
  19. package/lib/FastLayer.d.ts +14 -1
  20. package/lib/FastLayer.js +14 -1
  21. package/lib/Global.d.ts +114 -3
  22. package/lib/Global.js +134 -5
  23. package/lib/Group.d.ts +11 -0
  24. package/lib/Group.js +11 -0
  25. package/lib/Layer.d.ts +128 -3
  26. package/lib/Layer.js +260 -49
  27. package/lib/Node.d.ts +703 -32
  28. package/lib/Node.js +1545 -202
  29. package/lib/PointerEvents.d.ts +2 -1
  30. package/lib/PointerEvents.js +19 -1
  31. package/lib/Shape.d.ts +99 -14
  32. package/lib/Shape.js +1101 -67
  33. package/lib/Stage.d.ts +85 -2
  34. package/lib/Stage.js +205 -14
  35. package/lib/Tween.d.ts +159 -4
  36. package/lib/Tween.js +243 -24
  37. package/lib/Util.d.ts +148 -4
  38. package/lib/Util.js +354 -82
  39. package/lib/Validators.d.ts +0 -2
  40. package/lib/Validators.js +3 -25
  41. package/lib/_CoreInternals.d.ts +12 -6
  42. package/lib/_CoreInternals.js +1 -0
  43. package/lib/_FullInternals.d.ts +17 -6
  44. package/lib/_FullInternals.js +7 -0
  45. package/lib/canvas-backend.js +6 -0
  46. package/lib/filters/Blur.d.ts +18 -0
  47. package/lib/filters/Blur.js +97 -24
  48. package/lib/filters/Brighten.d.ts +21 -0
  49. package/lib/filters/Brighten.js +24 -0
  50. package/lib/filters/Brightness.d.ts +11 -0
  51. package/lib/filters/Brightness.js +16 -0
  52. package/lib/filters/Contrast.d.ts +10 -0
  53. package/lib/filters/Contrast.js +21 -0
  54. package/lib/filters/Emboss.d.ts +20 -0
  55. package/lib/filters/Emboss.js +68 -8
  56. package/lib/filters/Enhance.d.ts +14 -0
  57. package/lib/filters/Enhance.js +34 -0
  58. package/lib/filters/Grayscale.d.ts +9 -0
  59. package/lib/filters/Grayscale.js +12 -0
  60. package/lib/filters/HSL.d.ts +17 -0
  61. package/lib/filters/HSL.js +48 -5
  62. package/lib/filters/HSV.d.ts +18 -0
  63. package/lib/filters/HSV.js +49 -5
  64. package/lib/filters/Invert.d.ts +9 -0
  65. package/lib/filters/Invert.js +12 -0
  66. package/lib/filters/Kaleidoscope.d.ts +12 -0
  67. package/lib/filters/Kaleidoscope.js +83 -0
  68. package/lib/filters/Mask.d.ts +11 -0
  69. package/lib/filters/Mask.js +18 -0
  70. package/lib/filters/Noise.d.ts +19 -0
  71. package/lib/filters/Noise.js +19 -0
  72. package/lib/filters/Pixelate.d.ts +20 -0
  73. package/lib/filters/Pixelate.js +28 -1
  74. package/lib/filters/Posterize.d.ts +21 -0
  75. package/lib/filters/Posterize.js +22 -0
  76. package/lib/filters/RGB.d.ts +21 -0
  77. package/lib/filters/RGB.js +43 -28
  78. package/lib/filters/RGBA.d.ts +23 -0
  79. package/lib/filters/RGBA.js +28 -41
  80. package/lib/filters/Sepia.d.ts +9 -0
  81. package/lib/filters/Sepia.js +10 -0
  82. package/lib/filters/Solarize.d.ts +10 -0
  83. package/lib/filters/Solarize.js +11 -0
  84. package/lib/filters/Threshold.d.ts +22 -0
  85. package/lib/filters/Threshold.js +22 -0
  86. package/lib/shapes/Arc.d.ts +40 -0
  87. package/lib/shapes/Arc.js +89 -6
  88. package/lib/shapes/Arrow.d.ts +24 -1
  89. package/lib/shapes/Arrow.js +83 -0
  90. package/lib/shapes/Circle.d.ts +18 -0
  91. package/lib/shapes/Circle.js +36 -9
  92. package/lib/shapes/Ellipse.d.ts +34 -2
  93. package/lib/shapes/Ellipse.js +67 -9
  94. package/lib/shapes/Image.d.ts +49 -0
  95. package/lib/shapes/Image.js +151 -22
  96. package/lib/shapes/Label.d.ts +65 -1
  97. package/lib/shapes/Label.js +113 -20
  98. package/lib/shapes/Line.d.ts +50 -8
  99. package/lib/shapes/Line.js +116 -20
  100. package/lib/shapes/Path.d.ts +56 -6
  101. package/lib/shapes/Path.js +203 -128
  102. package/lib/shapes/Rect.d.ts +18 -0
  103. package/lib/shapes/Rect.js +36 -0
  104. package/lib/shapes/RegularPolygon.d.ts +22 -0
  105. package/lib/shapes/RegularPolygon.js +70 -0
  106. package/lib/shapes/Ring.d.ts +19 -0
  107. package/lib/shapes/Ring.js +51 -5
  108. package/lib/shapes/Sprite.d.ts +78 -0
  109. package/lib/shapes/Sprite.js +238 -25
  110. package/lib/shapes/Star.d.ts +23 -0
  111. package/lib/shapes/Star.js +62 -0
  112. package/lib/shapes/Text.d.ts +59 -1
  113. package/lib/shapes/Text.js +481 -97
  114. package/lib/shapes/TextPath.d.ts +49 -3
  115. package/lib/shapes/TextPath.js +278 -34
  116. package/lib/shapes/Transformer.d.ts +124 -12
  117. package/lib/shapes/Transformer.js +864 -140
  118. package/lib/shapes/Wedge.d.ts +22 -0
  119. package/lib/shapes/Wedge.js +67 -3
  120. package/lib/skia-backend.js +9 -0
  121. package/lib/types.d.ts +2 -23
  122. package/lib/types.js +1 -21
  123. package/package.json +12 -16
@@ -1,5 +1,6 @@
1
1
  import { Transform } from '../Util.ts';
2
2
  import { Node } from '../Node.ts';
3
+ import { Shape } from '../Shape.ts';
3
4
  import { Rect } from './Rect.ts';
4
5
  import { Group } from '../Group.ts';
5
6
  import type { ContainerConfig } from '../Container.ts';
@@ -38,10 +39,69 @@ export interface TransformerConfig extends ContainerConfig {
38
39
  anchorDragBoundFunc?: (oldPos: Vector2d, newPos: Vector2d, evt: any) => Vector2d;
39
40
  anchorStyleFunc?: (anchor: Rect) => void;
40
41
  }
42
+ /**
43
+ * Transformer constructor. Transformer is a special type of group that allow you transform Konva
44
+ * primitives and shapes. Transforming tool is not changing `width` and `height` properties of nodes
45
+ * when you resize them. Instead it changes `scaleX` and `scaleY` properties.
46
+ * @constructor
47
+ * @memberof Konva
48
+ * @param {Object} config
49
+ * @param {Boolean} [config.resizeEnabled] Default is true
50
+ * @param {Boolean} [config.rotateEnabled] Default is true
51
+ * @param {Boolean} [config.rotateLineVisible] Default is true
52
+ * @param {Array} [config.rotationSnaps] Array of angles for rotation snaps. Default is []
53
+ * @param {Number} [config.rotationSnapTolerance] Snapping tolerance. If closer than this it will snap. Default is 5
54
+ * @param {Number} [config.rotateAnchorOffset] Default is 50
55
+ * @param {Number} [config.rotateAnchorAngle] Angle of the rotate anchor around the box, in degrees. Default is 0 (top)
56
+ * @param {String} [config.rotateAnchorCursor] Default is crosshair
57
+ * @param {Number} [config.padding] Default is 0
58
+ * @param {Boolean} [config.borderEnabled] Should we draw border? Default is true
59
+ * @param {String} [config.borderStroke] Border stroke color
60
+ * @param {Number} [config.borderStrokeWidth] Border stroke size
61
+ * @param {Array} [config.borderDash] Array for border dash.
62
+ * @param {String} [config.anchorFill] Anchor fill color
63
+ * @param {String} [config.anchorStroke] Anchor stroke color
64
+ * @param {Number} [config.anchorCornerRadius] Anchor corner radius
65
+ * @param {Number} [config.anchorStrokeWidth] Anchor stroke size
66
+ * @param {Number} [config.anchorSize] Default is 10
67
+ * @param {Boolean} [config.keepRatio] Should we keep ratio when we are moving edges? Default is true
68
+ * @param {String} [config.shiftBehavior] How does transformer react on shift key press when we are moving edges? Default is 'default'
69
+ * @param {Boolean} [config.centeredScaling] Should we resize relative to node's center? Default is false
70
+ * @param {Array} [config.enabledAnchors] Array of names of enabled handles
71
+ * @param {Boolean} [config.flipEnabled] Can we flip/mirror shape on transform?. True by default
72
+ * @param {Function} [config.boundBoxFunc] Bounding box function, see {@link Konva.Transformer#boundBoxFunc}
73
+ * @param {Function} [config.anchorDragBoundFunc] Function bounding the position of a dragged anchor, see {@link Konva.Transformer#anchorDragBoundFunc}
74
+ * @param {Function} [config.anchorStyleFunc] Function styling every anchor, see {@link Konva.Transformer#anchorStyleFunc}
75
+ * @param {Boolean} [config.ignoreStroke] Should we ignore stroke size? Default is false
76
+ * @param {Boolean} [config.useSingleNodeRotation] When just one node attached, should we use its rotation for transformer?
77
+ * @param {Boolean} [config.shouldOverdrawWholeArea] Should we fill whole transformer area with fake transparent shape to enable dragging from empty spaces?
78
+ * @example
79
+ * var transformer = new Konva.Transformer({
80
+ * nodes: [rectangle],
81
+ * rotateAnchorOffset: 60,
82
+ * enabledAnchors: ['top-left', 'top-right', 'bottom-left', 'bottom-right']
83
+ * });
84
+ * layer.add(transformer);
85
+ */
41
86
  export declare class Transformer extends Group {
42
87
  _nodes: Array<Node>;
88
+ _nodeRectCache?: Map<Node, {
89
+ rotation: number;
90
+ ignoreStroke: boolean;
91
+ version: number;
92
+ width: number;
93
+ height: number;
94
+ minX: number;
95
+ minY: number;
96
+ maxX: number;
97
+ maxY: number;
98
+ }>;
43
99
  _movingAnchorName: string | null;
100
+ _pointerId?: number;
101
+ _anchors: Record<string, Rect>;
102
+ _back: Shape;
44
103
  _transforming: boolean;
104
+ _fitting: boolean;
45
105
  _transformWindow: Window | null;
46
106
  _anchorDragOffset: Vector2d;
47
107
  sin: number;
@@ -49,8 +109,18 @@ export declare class Transformer extends Group {
49
109
  _cursorChange: boolean;
50
110
  _elementsCreated: boolean;
51
111
  _updateScheduled: boolean;
112
+ _lastNodeRect?: Readonly<Box>;
52
113
  static isTransforming: () => boolean;
114
+ static _isLayerTransforming(layer: Node): boolean;
53
115
  constructor(config?: TransformerConfig);
116
+ /**
117
+ * alias to `tr.nodes([shape])`/ This method is deprecated and will be removed soon.
118
+ * @method
119
+ * @name Konva.Transformer#attachTo
120
+ * @returns {Konva.Transformer}
121
+ * @example
122
+ * transformer.attachTo(shape);
123
+ */
54
124
  attachTo(node: Node): this;
55
125
  setNode(node: Node): this;
56
126
  getNode(): Node<import("../Node.ts").NodeConfig>;
@@ -58,17 +128,39 @@ export declare class Transformer extends Group {
58
128
  setNodes(nodes?: Array<Node>): this;
59
129
  _proxyDrag(node: Node): void;
60
130
  getNodes(): Node<import("../Node.ts").NodeConfig>[];
131
+ /**
132
+ * return the name of current active anchor
133
+ * @method
134
+ * @name Konva.Transformer#getActiveAnchor
135
+ * @returns {String | Null}
136
+ * @example
137
+ * transformer.getActiveAnchor();
138
+ */
61
139
  getActiveAnchor(): string | null;
140
+ /**
141
+ * detach transformer from an attached node
142
+ * @method
143
+ * @name Konva.Transformer#detach
144
+ * @returns {Konva.Transformer}
145
+ * @example
146
+ * transformer.detach();
147
+ */
62
148
  detach(): void;
63
- _resetTransformCache(): void;
149
+ /**
150
+ * bind events to the Transformer. You can use events: `transform`, `transformstart`, `transformend`, `dragstart`, `dragmove`, `dragend`
151
+ * @method
152
+ * @name Konva.Transformer#on
153
+ * @param {String} evtStr e.g. 'transform'
154
+ * @param {Function} handler The handler function. The first argument of that function is event object. Event object has `target` as main target of the event, `currentTarget` as current node listener and `evt` as native browser event.
155
+ * @returns {Konva.Transformer}
156
+ * @example
157
+ * // add click listener
158
+ * tr.on('transformstart', function() {
159
+ * console.log('transform started');
160
+ * });
161
+ */
162
+ _resetTransformCache(changedNode?: Node): void;
64
163
  _getNodeRect(): any;
65
- __getNodeShape(node: Node, rot?: number, relative?: Node): {
66
- rotation: number;
67
- x: number;
68
- y: number;
69
- width: number;
70
- height: number;
71
- };
72
164
  __getNodeRect(): {
73
165
  x: number;
74
166
  y: number;
@@ -85,16 +177,36 @@ export declare class Transformer extends Group {
85
177
  _createBack(): void;
86
178
  _handleMouseDown(e: any): void;
87
179
  _handleMouseMove(e: any): void;
180
+ _moveTransform(e: any): void;
88
181
  _handleMouseUp(e: any): void;
89
- getAbsoluteTransform(): Transform;
182
+ getAbsoluteTransform(top?: Node | null): Transform;
90
183
  _removeEvents(e?: any): void;
91
184
  _fitNodesInto(newAttrs: any, evt?: any, anchorProjected?: boolean): void;
92
185
  _doFitNodesInto(newAttrs: any, evt?: any, anchorProjected?: boolean): void;
93
186
  _scheduleUpdate(): void;
187
+ /**
188
+ * force update of Konva.Transformer.
189
+ * Use it when you updated attached Konva.Group and now you need to reset transformer size
190
+ * @method
191
+ * @name Konva.Transformer#forceUpdate
192
+ */
94
193
  forceUpdate(): void;
95
- _batchChangeChild(selector: string, attrs: any): void;
96
194
  update(): void;
195
+ _update(): void;
196
+ _updateElements(attrs: Box): void;
197
+ /**
198
+ * determine if transformer is in active transform
199
+ * @method
200
+ * @name Konva.Transformer#isTransforming
201
+ * @returns {Boolean}
202
+ */
97
203
  isTransforming(): boolean;
204
+ /**
205
+ * Stop active transform action
206
+ * @method
207
+ * @name Konva.Transformer#stopTransform
208
+ * @returns {Boolean}
209
+ */
98
210
  stopTransform(): void;
99
211
  destroy(): this;
100
212
  add(...children: any[]): this;
@@ -104,7 +216,7 @@ export declare class Transformer extends Group {
104
216
  children?: Array<any>;
105
217
  };
106
218
  clone(obj?: any): this;
107
- getClientRect(): IRect;
219
+ getClientRect(config?: Parameters<Group['getClientRect']>[0]): IRect;
108
220
  nodes: GetSet<Node[], this>;
109
221
  enabledAnchors: GetSet<string[], this>;
110
222
  rotationSnaps: GetSet<number[], this>;
@@ -131,7 +243,7 @@ export declare class Transformer extends Group {
131
243
  flipEnabled: GetSet<boolean, this>;
132
244
  ignoreStroke: GetSet<boolean, this>;
133
245
  boundBoxFunc: GetSet<(oldBox: Box, newBox: Box) => Box, this>;
134
- anchorDragBoundFunc: GetSet<(oldPos: Vector2d, newPos: Vector2d, e: MouseEvent) => Vector2d, this>;
246
+ anchorDragBoundFunc: GetSet<(oldPos: Vector2d, newPos: Vector2d, evt: any) => Vector2d, this>;
135
247
  anchorStyleFunc: GetSet<null | ((Node: Rect) => void), this>;
136
248
  shouldOverdrawWholeArea: GetSet<boolean, this>;
137
249
  useSingleNodeRotation: GetSet<boolean, this>;