konva 10.3.2 → 10.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 (123) hide show
  1. package/README.md +5 -1
  2. package/konva.js +1327 -1572
  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 +1 -0
  16. package/lib/DragAndDrop.js +66 -17
  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 +692 -30
  28. package/lib/Node.js +1534 -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 +81 -1
  34. package/lib/Stage.js +166 -7
  35. package/lib/Tween.d.ts +159 -4
  36. package/lib/Tween.js +243 -24
  37. package/lib/Util.d.ts +147 -4
  38. package/lib/Util.js +332 -82
  39. package/lib/Validators.d.ts +0 -2
  40. package/lib/Validators.js +3 -25
  41. package/lib/_CoreInternals.d.ts +10 -6
  42. package/lib/_CoreInternals.js +1 -0
  43. package/lib/_FullInternals.d.ts +15 -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 +40 -6
  101. package/lib/shapes/Path.js +187 -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 +108 -11
  117. package/lib/shapes/Transformer.js +744 -102
  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 +24 -21
@@ -1,4 +1,4 @@
1
- import type { KonvaEventObject } from './Node.ts';
1
+ import type { KonvaEventObject, Node } from './Node.ts';
2
2
  import type { Shape } from './Shape.ts';
3
3
  import type { Stage } from './Stage.ts';
4
4
  export interface KonvaPointerEvent extends KonvaEventObject<PointerEvent> {
@@ -8,4 +8,5 @@ export declare function getCapturedShape(pointerId: number): Shape<import("./Sha
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;
11
+ export declare function releaseCapturesOf(node: Node): void;
11
12
  export declare function releaseCapture(pointerId: number, target?: Shape | Stage): void;
@@ -1,5 +1,7 @@
1
1
  import { Konva } from "./Global.js";
2
2
  const Captures = new Map();
3
+ // we may use this module for capturing touch events too
4
+ // so make sure we don't do something super specific to pointer
3
5
  const SUPPORT_POINTER_EVENTS = Konva._global['PointerEvent'] !== undefined;
4
6
  export function getCapturedShape(pointerId) {
5
7
  return Captures.get(pointerId);
@@ -21,18 +23,33 @@ export function setPointerCapture(pointerId, shape) {
21
23
  return;
22
24
  Captures.set(pointerId, shape);
23
25
  if (SUPPORT_POINTER_EVENTS) {
26
+ // capture on the DOM level too, so the stage keeps receiving the events
27
+ // of that pointer even when it moves outside of the stage container
28
+ // https://github.com/konvajs/konva/issues/1992
24
29
  try {
25
30
  (_a = stage.content) === null || _a === void 0 ? void 0 : _a.setPointerCapture(pointerId);
26
31
  }
27
32
  catch (e) {
33
+ // capture is possible only for an active pointer;
34
+ // ids of mouse and touch events (999 and touch identifiers) and
35
+ // programmatic calls outside of a pointer event land here
28
36
  }
29
37
  shape._fire('gotpointercapture', createEvent(new PointerEvent('gotpointercapture')));
30
38
  }
31
39
  }
40
+ // a destroyed node must not keep receiving the events of its pointer
41
+ export function releaseCapturesOf(node) {
42
+ Captures.forEach((shape, pointerId) => {
43
+ if (shape === node) {
44
+ releaseCapture(pointerId);
45
+ }
46
+ });
47
+ }
32
48
  export function releaseCapture(pointerId, target) {
33
49
  var _a;
34
50
  const shape = Captures.get(pointerId);
35
- if (!shape)
51
+ // a node can only release its own capture
52
+ if (!shape || (target && shape !== target))
36
53
  return;
37
54
  const stage = shape.getStage();
38
55
  Captures.delete(pointerId);
@@ -41,6 +58,7 @@ export function releaseCapture(pointerId, target) {
41
58
  (_a = stage === null || stage === void 0 ? void 0 : stage.content) === null || _a === void 0 ? void 0 : _a.releasePointerCapture(pointerId);
42
59
  }
43
60
  catch (e) {
61
+ // same as in setPointerCapture: the pointer may not be active
44
62
  }
45
63
  shape._fire('lostpointercapture', createEvent(new PointerEvent('lostpointercapture')));
46
64
  }
package/lib/Shape.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { NodeConfig } from './Node.ts';
1
+ import type { GetClientRectConfig, NodeConfig } from './Node.ts';
2
2
  import { Node } from './Node.ts';
3
3
  import type { Context } from './Context.ts';
4
4
  import type { GetSet, Vector2d } from './types.ts';
@@ -28,6 +28,13 @@ export type ShapeConfig = NodeConfig & {
28
28
  fillLinearGradientEndPointX?: number;
29
29
  fillLinearGradientEndPointY?: number;
30
30
  fillLinearGradientColorStops?: Array<number | string>;
31
+ strokeLinearGradientStartPoint?: Vector2d;
32
+ strokeLinearGradientStartPointX?: number;
33
+ strokeLinearGradientStartPointY?: number;
34
+ strokeLinearGradientEndPoint?: Vector2d;
35
+ strokeLinearGradientEndPointX?: number;
36
+ strokeLinearGradientEndPointY?: number;
37
+ strokeLinearGradientColorStops?: Array<number | string>;
31
38
  fillRadialGradientStartPoint?: Vector2d;
32
39
  fillRadialGradientStartPointX?: number;
33
40
  fillRadialGradientStartPointY?: number;
@@ -65,16 +72,37 @@ export type ShapeConfig = NodeConfig & {
65
72
  dashEnabled?: boolean;
66
73
  perfectDrawEnabled?: boolean;
67
74
  };
68
- export interface ShapeGetClientRectConfig {
69
- skipTransform?: boolean;
70
- skipShadow?: boolean;
71
- skipStroke?: boolean;
72
- relativeTo?: Node;
73
- }
75
+ export type ShapeGetClientRectConfig = GetClientRectConfig;
74
76
  export type FillFuncOutput = void | [Path2D | CanvasFillRule] | [Path2D, CanvasFillRule];
75
77
  export declare const shapes: {
76
78
  [key: string]: Shape;
77
79
  };
80
+ /**
81
+ * Shape constructor. Shapes are primitive objects such as rectangles,
82
+ * circles, text, lines, etc.
83
+ * @constructor
84
+ * @memberof Konva
85
+ * @augments Konva.Node
86
+ * @param {Object} config
87
+ * @@shapeParams
88
+ * @@nodeParams
89
+ * @example
90
+ * var customShape = new Konva.Shape({
91
+ * x: 5,
92
+ * y: 10,
93
+ * fill: 'red',
94
+ * // a Konva.Canvas renderer is passed into the sceneFunc function
95
+ * sceneFunc (context, shape) {
96
+ * context.beginPath();
97
+ * context.moveTo(200, 50);
98
+ * context.lineTo(420, 80);
99
+ * context.quadraticCurveTo(300, 100, 260, 170);
100
+ * context.closePath();
101
+ * // Konva specific method
102
+ * context.fillStrokeShape(shape);
103
+ * }
104
+ *});
105
+ */
78
106
  export declare class Shape<Config extends ShapeConfig = ShapeConfig> extends Node<Config> {
79
107
  _centroid: boolean;
80
108
  colorKey: string;
@@ -83,10 +111,22 @@ export declare class Shape<Config extends ShapeConfig = ShapeConfig> extends Nod
83
111
  _fillFuncHit: (ctx: Context) => void;
84
112
  _strokeFuncHit: (ctx: Context) => void;
85
113
  constructor(config?: Config);
114
+ /**
115
+ * @deprecated
116
+ */
86
117
  getContext(): Context;
118
+ /**
119
+ * @deprecated
120
+ */
87
121
  getCanvas(): SceneCanvas;
88
122
  getSceneFunc(): any;
89
123
  getHitFunc(): any;
124
+ /**
125
+ * returns whether or not a shadow will be rendered
126
+ * @method
127
+ * @name Konva.Shape#hasShadow
128
+ * @returns {Boolean}
129
+ */
90
130
  hasShadow(): any;
91
131
  _hasShadow(): boolean;
92
132
  _getFillPattern(): any;
@@ -97,14 +137,53 @@ export declare class Shape<Config extends ShapeConfig = ShapeConfig> extends Nod
97
137
  __getRadialGradient(): CanvasGradient | undefined;
98
138
  getShadowRGBA(): any;
99
139
  _getShadowRGBA(): string | undefined;
140
+ /**
141
+ * returns whether or not the shape will be filled
142
+ * @method
143
+ * @name Konva.Shape#hasFill
144
+ * @returns {Boolean}
145
+ */
100
146
  hasFill(): any;
147
+ _hasFill(): boolean;
148
+ /**
149
+ * returns whether or not the shape will be stroked
150
+ * @method
151
+ * @name Konva.Shape#hasStroke
152
+ * @returns {Boolean}
153
+ */
101
154
  hasStroke(): any;
155
+ _hasStroke(): boolean;
102
156
  hasHitStroke(): any;
157
+ /**
158
+ * determines if point is in the shape, regardless if other shapes are on top of it. Note: because
159
+ * this method clears a temporary canvas and then redraws the shape, it performs very poorly if executed many times
160
+ * consecutively. Please use the {@link Konva.Stage#getIntersection} method if at all possible
161
+ * because it performs much better. A shape that is invisible, not listening or not on a stage
162
+ * never intersects
163
+ * @method
164
+ * @name Konva.Shape#intersects
165
+ * @param {Object} point
166
+ * @param {Number} point.x
167
+ * @param {Number} point.y
168
+ * @returns {Boolean}
169
+ */
103
170
  intersects(point: Vector2d): boolean;
104
171
  destroy(): this;
105
172
  _useBufferCanvas(forceFill?: boolean): boolean;
106
173
  setStrokeHitEnabled(val: number): void;
107
174
  getStrokeHitEnabled(): boolean;
175
+ /**
176
+ * return self rectangle (x, y, width, height) of shape.
177
+ * This method are not taken into account transformation and styles.
178
+ * @method
179
+ * @name Konva.Shape#getSelfRect
180
+ * @returns {Object} rect with {x, y, width, height} properties
181
+ * @example
182
+ *
183
+ * rect.getSelfRect(); // return {x:0, y:0, width:rect.width(), height:rect.height()}
184
+ * circle.getSelfRect(); // return {x: - circle.width() / 2, y: - circle.height() / 2, width:circle.width(), height:circle.height()}
185
+ *
186
+ */
108
187
  getSelfRect(): {
109
188
  x: number;
110
189
  y: number;
@@ -118,7 +197,19 @@ export declare class Shape<Config extends ShapeConfig = ShapeConfig> extends Nod
118
197
  y: number;
119
198
  };
120
199
  drawScene(can?: SceneCanvas, top?: Node, bufferCanvas?: SceneCanvas): this;
121
- drawHit(can?: HitCanvas, top?: Node, skipDragCheck?: boolean): this;
200
+ drawHit(can?: HitCanvas, top?: Node): this;
201
+ /**
202
+ * draw hit graph using the cached scene canvas
203
+ * @method
204
+ * @name Konva.Shape#drawHitFromCache
205
+ * @param {Integer} alphaThreshold alpha channel threshold that determines whether or not
206
+ * a pixel should be drawn onto the hit graph. Must be a value between 0 and 255.
207
+ * The default is 0
208
+ * @returns {Konva.Shape}
209
+ * @example
210
+ * shape.cache();
211
+ * shape.drawHitFromCache();
212
+ */
122
213
  drawHitFromCache(alphaThreshold?: number): this;
123
214
  hasPointerCapture(pointerId: number): boolean;
124
215
  setPointerCapture(pointerId: number): void;
@@ -137,12 +228,6 @@ export declare class Shape<Config extends ShapeConfig = ShapeConfig> extends Nod
137
228
  fillLinearGradientEndPoint: GetSet<Vector2d, this>;
138
229
  fillLinearGradientEndPointX: GetSet<number, this>;
139
230
  fillLinearGradientEndPointY: GetSet<number, this>;
140
- fillLinearRadialStartPoint: GetSet<Vector2d, this>;
141
- fillLinearRadialStartPointX: GetSet<number, this>;
142
- fillLinearRadialStartPointY: GetSet<number, this>;
143
- fillLinearRadialEndPoint: GetSet<Vector2d, this>;
144
- fillLinearRadialEndPointX: GetSet<number, this>;
145
- fillLinearRadialEndPointY: GetSet<number, this>;
146
231
  fillPatternImage: GetSet<HTMLImageElement | HTMLCanvasElement, this>;
147
232
  fillRadialGradientStartRadius: GetSet<number, this>;
148
233
  fillRadialGradientEndRadius: GetSet<number, this>;