konva 10.5.0 → 10.7.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 (79) hide show
  1. package/README.md +16 -12
  2. package/konva.js +3623 -3819
  3. package/konva.min.js +4 -4
  4. package/lib/Animation.d.ts +2 -2
  5. package/lib/Animation.js +2 -2
  6. package/lib/BezierFunctions.d.ts +1 -1
  7. package/lib/BezierFunctions.js +76 -116
  8. package/lib/Canvas.d.ts +10 -3
  9. package/lib/Canvas.js +91 -10
  10. package/lib/Container.d.ts +3 -2
  11. package/lib/Container.js +31 -17
  12. package/lib/Context.d.ts +9 -7
  13. package/lib/Context.js +99 -73
  14. package/lib/DragAndDrop.d.ts +4 -3
  15. package/lib/DragAndDrop.js +39 -25
  16. package/lib/Factory.d.ts +3 -2
  17. package/lib/Factory.js +10 -9
  18. package/lib/Global.d.ts +2 -7
  19. package/lib/Global.js +8 -9
  20. package/lib/Group.d.ts +7 -1
  21. package/lib/Group.js +61 -0
  22. package/lib/Layer.d.ts +1 -1
  23. package/lib/Layer.js +13 -8
  24. package/lib/Node.d.ts +25 -19
  25. package/lib/Node.js +178 -169
  26. package/lib/PointerEvents.d.ts +1 -2
  27. package/lib/PointerEvents.js +20 -18
  28. package/lib/Shape.d.ts +9 -15
  29. package/lib/Shape.js +190 -86
  30. package/lib/Stage.d.ts +19 -15
  31. package/lib/Stage.js +184 -99
  32. package/lib/Tween.js +59 -66
  33. package/lib/Util.d.ts +3 -2
  34. package/lib/Util.js +46 -16
  35. package/lib/_CoreInternals.d.ts +23 -11
  36. package/lib/_FullInternals.d.ts +23 -11
  37. package/lib/filters/Blur.js +16 -12
  38. package/lib/filters/Brighten.d.ts +1 -0
  39. package/lib/filters/Brighten.js +1 -0
  40. package/lib/filters/Brightness.d.ts +2 -1
  41. package/lib/filters/Brightness.js +4 -4
  42. package/lib/filters/Emboss.js +16 -58
  43. package/lib/filters/Kaleidoscope.js +8 -15
  44. package/lib/filters/Mask.js +8 -8
  45. package/lib/filters/Pixelate.js +16 -29
  46. package/lib/filters/Threshold.d.ts +1 -1
  47. package/lib/filters/Threshold.js +1 -1
  48. package/lib/shapes/Arc.js +8 -6
  49. package/lib/shapes/Arrow.d.ts +3 -6
  50. package/lib/shapes/Arrow.js +75 -47
  51. package/lib/shapes/Circle.d.ts +1 -0
  52. package/lib/shapes/Circle.js +4 -1
  53. package/lib/shapes/Ellipse.d.ts +1 -0
  54. package/lib/shapes/Ellipse.js +4 -1
  55. package/lib/shapes/Image.d.ts +2 -1
  56. package/lib/shapes/Image.js +22 -22
  57. package/lib/shapes/Label.d.ts +2 -3
  58. package/lib/shapes/Label.js +25 -41
  59. package/lib/shapes/Line.d.ts +2 -1
  60. package/lib/shapes/Line.js +5 -2
  61. package/lib/shapes/Path.d.ts +11 -2
  62. package/lib/shapes/Path.js +133 -143
  63. package/lib/shapes/Rect.d.ts +1 -0
  64. package/lib/shapes/Rect.js +4 -1
  65. package/lib/shapes/RegularPolygon.js +2 -2
  66. package/lib/shapes/Ring.d.ts +7 -0
  67. package/lib/shapes/Ring.js +8 -1
  68. package/lib/shapes/Sprite.d.ts +2 -1
  69. package/lib/shapes/Sprite.js +8 -9
  70. package/lib/shapes/Star.d.ts +6 -0
  71. package/lib/shapes/Star.js +5 -1
  72. package/lib/shapes/Text.d.ts +16 -5
  73. package/lib/shapes/Text.js +134 -65
  74. package/lib/shapes/TextPath.d.ts +11 -3
  75. package/lib/shapes/TextPath.js +56 -27
  76. package/lib/shapes/Transformer.js +95 -96
  77. package/lib/shapes/Wedge.js +1 -1
  78. package/lib/types.d.ts +2 -2
  79. package/package.json +5 -20
package/lib/Layer.js CHANGED
@@ -177,11 +177,14 @@ export class Layer extends Container {
177
177
  return this;
178
178
  }
179
179
  remove() {
180
- const _canvas = this.getNativeCanvasElement();
181
- Node.prototype.remove.call(this);
182
- if (_canvas && _canvas.parentNode && Util._isInDocument(_canvas)) {
183
- _canvas.parentNode.removeChild(_canvas);
184
- }
180
+ var _a, _b;
181
+ super.remove();
182
+ // both canvases live in stage.content: the scene one always, the hit one
183
+ // while toggleHitCanvas() shows it
184
+ const scene = this.getNativeCanvasElement();
185
+ const hit = this.getHitCanvas()._canvas;
186
+ (_a = scene.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(scene);
187
+ (_b = hit.parentNode) === null || _b === void 0 ? void 0 : _b.removeChild(hit);
185
188
  return this;
186
189
  }
187
190
  getStage() {
@@ -369,7 +372,7 @@ export class Layer extends Container {
369
372
  }
370
373
  return {};
371
374
  }
372
- drawScene(can, top, bufferCanvas) {
375
+ drawScene(can, top) {
373
376
  const layer = this.getLayer(), canvas = can || (layer && layer.getCanvas());
374
377
  this._fire(BEFORE_DRAW, {
375
378
  node: this,
@@ -377,7 +380,8 @@ export class Layer extends Container {
377
380
  if (this.clearBeforeDraw()) {
378
381
  canvas.getContext().clear();
379
382
  }
380
- Container.prototype.drawScene.call(this, canvas, top, bufferCanvas);
383
+ Container.prototype.drawScene.call(this, canvas, top);
384
+ canvas._trimIsolationCanvas();
381
385
  this._fire(DRAW, {
382
386
  node: this,
383
387
  });
@@ -398,7 +402,7 @@ export class Layer extends Container {
398
402
  let underDrag = false;
399
403
  DD._dragElements.forEach((elem) => {
400
404
  if (elem.dragStatus === 'dragging' &&
401
- (elem.node.nodeType === 'Stage' || elem.node.getLayer() === this)) {
405
+ (elem.node === this.getStage() || elem.node.getLayer() === this)) {
402
406
  underDrag = true;
403
407
  }
404
408
  });
@@ -464,6 +468,7 @@ export class Layer extends Container {
464
468
  }
465
469
  }
466
470
  destroy() {
471
+ this.getCanvas()._releaseIsolationCanvas();
467
472
  Util.releaseCanvas(this.getNativeCanvasElement(), this.getHitCanvas()._canvas);
468
473
  return super.destroy();
469
474
  }
package/lib/Node.d.ts CHANGED
@@ -8,7 +8,7 @@ import type { Stage } from './Stage.ts';
8
8
  import type { Tween, TweenConfig } from './Tween.ts';
9
9
  import type { GetSet, IRect, Vector2d } from './types.ts';
10
10
  import { Transform, type AnyString } from './Util.ts';
11
- export type FilterFunction = (this: Node, imageData: ImageData) => void;
11
+ export type FilterFunction = (this: Node, imageData: ImageData, pixelRatio?: number) => void;
12
12
  export type Filter = FilterFunction | string;
13
13
  type Filters = Array<FilterFunction | string>;
14
14
  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';
@@ -55,6 +55,7 @@ export interface KonvaEventObject<EventType, This = Node> {
55
55
  newVal?: any;
56
56
  }
57
57
  export interface GetClientRectConfig {
58
+ _forDrawing?: boolean;
58
59
  skipTransform?: boolean;
59
60
  skipShadow?: boolean;
60
61
  skipStroke?: boolean;
@@ -202,11 +203,13 @@ export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
202
203
  * @returns {Boolean}
203
204
  */
204
205
  isCached(): boolean;
205
- abstract drawScene(canvas?: Canvas, top?: Node, bufferCanvas?: Canvas): void;
206
+ abstract drawScene(canvas?: Canvas, top?: Node): void;
206
207
  abstract drawHit(canvas?: Canvas, top?: Node): void;
207
208
  /**
208
209
  * Return client rectangle {x, y, width, height} of node. This rectangle also include all styling (strokes, shadows, etc).
209
210
  * The purpose of the method is similar to getBoundingClientRect API of the DOM.
211
+ * Non-scaling stroke padding is converted from its drawing canvas to the requested coordinates.
212
+ * Cached strokes use the cache's coordinates; their pixels scale with the cached bitmap.
210
213
  * @method
211
214
  * @name Konva.Node#getClientRect
212
215
  * @param {Object} config
@@ -241,12 +244,8 @@ export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
241
244
  * // returns Object {x: -2, y: 46, width: 104, height: 208}
242
245
  */
243
246
  getClientRect(config?: GetClientRectConfig): IRect;
244
- _transformedRect(rect: IRect, top?: Node | null): {
245
- x: number;
246
- y: number;
247
- width: number;
248
- height: number;
249
- };
247
+ _getCachedSceneRect(config: GetClientRectConfig): IRect | undefined;
248
+ _transformedRect(rect: IRect, top?: Node | null): IRect;
250
249
  _drawCachedSceneCanvas(context: Context): void;
251
250
  _drawCachedHitCanvas(context: Context, hitCanvas: HitCanvas): void;
252
251
  _getCachedSceneCanvas(): Canvas;
@@ -705,8 +704,9 @@ export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
705
704
  * @param {Number} [config.width] width of canvas section
706
705
  * @param {Number} [config.height] height of canvas section
707
706
  * @param {Number} [config.pixelRatio] pixelRatio of output canvas. Default is 1.
708
- * You can use that property to increase quality of the image, for example for super hight quality exports
709
- * or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
707
+ * Higher pixel ratios increase export resolution. Cached nodes keep their cache resolution.
708
+ * Rebuild caches at the export pixel ratio to preserve detail.
709
+ * The pixel ratio multiplies the dimensions of the exported image.
710
710
  * If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.
711
711
  * @param {Boolean} [config.imageSmoothingEnabled] set this to false if you want to disable imageSmoothing
712
712
  * @example
@@ -730,8 +730,9 @@ export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
730
730
  * you can specify the quality from 0 to 1, where 0 is very poor quality and 1
731
731
  * is very high quality
732
732
  * @param {Number} [config.pixelRatio] pixelRatio of output image url. Default is 1.
733
- * You can use that property to increase quality of the image, for example for super hight quality exports
734
- * or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
733
+ * Higher pixel ratios increase export resolution. Cached nodes keep their cache resolution.
734
+ * Rebuild caches at the export pixel ratio to preserve detail.
735
+ * The pixel ratio multiplies the dimensions of the exported image.
735
736
  * If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.
736
737
  * @param {Boolean} [config.imageSmoothingEnabled] set this to false if you want to disable imageSmoothing
737
738
  * @returns {String}
@@ -758,8 +759,9 @@ export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
758
759
  * you can specify the quality from 0 to 1, where 0 is very poor quality and 1
759
760
  * is very high quality
760
761
  * @param {Number} [config.pixelRatio] pixelRatio of output image. Default is 1.
761
- * You can use that property to increase quality of the image, for example for super hight quality exports
762
- * or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
762
+ * Higher pixel ratios increase export resolution. Cached nodes keep their cache resolution.
763
+ * Rebuild caches at the export pixel ratio to preserve detail.
764
+ * The pixel ratio multiplies the dimensions of the exported image.
763
765
  * If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.
764
766
  * @param {Boolean} [config.imageSmoothingEnabled] set this to false if you want to disable imageSmoothing
765
767
  * @return {Promise<Image>}
@@ -786,8 +788,9 @@ export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
786
788
  * @param {Number} [config.width] width of canvas section
787
789
  * @param {Number} [config.height] height of canvas section
788
790
  * @param {Number} [config.pixelRatio] pixelRatio of output canvas. Default is 1.
789
- * You can use that property to increase quality of the image, for example for super hight quality exports
790
- * or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
791
+ * Higher pixel ratios increase export resolution. Cached nodes keep their cache resolution.
792
+ * Rebuild caches at the export pixel ratio to preserve detail.
793
+ * The pixel ratio multiplies the dimensions of the exported image.
791
794
  * If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.
792
795
  * @param {Boolean} [config.imageSmoothingEnabled] set this to false if you want to disable imageSmoothing
793
796
  * @example
@@ -951,12 +954,15 @@ export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
951
954
  embossWhiteLevel: GetSet<number, this>;
952
955
  enhance: GetSet<number, this>;
953
956
  filters: GetSet<Filters, this>;
954
- position: GetSet<Vector2d, this>;
955
- absolutePosition: GetSet<Vector2d, this>;
957
+ position: GetSet<Vector2d, this, Vector2d>;
958
+ absolutePosition: GetSet<Vector2d, this, Vector2d>;
956
959
  size: GetSet<{
957
960
  width: number;
958
961
  height: number;
959
- }, this>;
962
+ }, this, {
963
+ width: number;
964
+ height: number;
965
+ }>;
960
966
  id: GetSet<string, this>;
961
967
  listening: GetSet<boolean, this>;
962
968
  name: GetSet<string, this>;