konva 10.3.3 → 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 +1 -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 +12 -16
@@ -7,6 +7,28 @@ export interface WedgeConfig extends ShapeConfig {
7
7
  radius: number;
8
8
  clockwise?: boolean;
9
9
  }
10
+ /**
11
+ * Wedge constructor
12
+ * @constructor
13
+ * @memberof Konva
14
+ * @augments Konva.Shape
15
+ * @param {Object} config
16
+ * @param {Number} config.angle in degrees
17
+ * @param {Number} config.radius
18
+ * @param {Boolean} [config.clockwise]
19
+ * @@shapeParams
20
+ * @@nodeParams
21
+ * @example
22
+ * // draw a wedge that's pointing downwards
23
+ * var wedge = new Konva.Wedge({
24
+ * radius: 40,
25
+ * fill: 'red',
26
+ * stroke: 'black',
27
+ * strokeWidth: 5,
28
+ * angle: 60,
29
+ * rotation: -120
30
+ * });
31
+ */
10
32
  export declare class Wedge extends Shape<WedgeConfig> {
11
33
  _sceneFunc(context: Context): void;
12
34
  getWidth(): number;
@@ -3,19 +3,41 @@ import { Shape } from "../Shape.js";
3
3
  import { Konva } from "../Global.js";
4
4
  import { getNumberValidator } from "../Validators.js";
5
5
  import { _registerNode } from "../Global.js";
6
+ /**
7
+ * Wedge constructor
8
+ * @constructor
9
+ * @memberof Konva
10
+ * @augments Konva.Shape
11
+ * @param {Object} config
12
+ * @param {Number} config.angle in degrees
13
+ * @param {Number} config.radius
14
+ * @param {Boolean} [config.clockwise]
15
+ * @@shapeParams
16
+ * @@nodeParams
17
+ * @example
18
+ * // draw a wedge that's pointing downwards
19
+ * var wedge = new Konva.Wedge({
20
+ * radius: 40,
21
+ * fill: 'red',
22
+ * stroke: 'black',
23
+ * strokeWidth: 5,
24
+ * angle: 60,
25
+ * rotation: -120
26
+ * });
27
+ */
6
28
  export class Wedge extends Shape {
7
29
  _sceneFunc(context) {
8
30
  context.beginPath();
9
- context.arc(0, 0, this.radius(), 0, Konva.getAngle(this.angle()), this.clockwise());
31
+ context.arc(0, 0, Math.abs(this.radius()), 0, Konva.getAngle(this.angle()), this.clockwise());
10
32
  context.lineTo(0, 0);
11
33
  context.closePath();
12
34
  context.fillStrokeShape(this);
13
35
  }
14
36
  getWidth() {
15
- return this.radius() * 2;
37
+ return Math.abs(this.radius()) * 2;
16
38
  }
17
39
  getHeight() {
18
- return this.radius() * 2;
40
+ return Math.abs(this.radius()) * 2;
19
41
  }
20
42
  setWidth(width) {
21
43
  this.radius(width / 2);
@@ -28,8 +50,50 @@ Wedge.prototype.className = 'Wedge';
28
50
  Wedge.prototype._centroid = true;
29
51
  Wedge.prototype._attrsAffectingSize = ['radius'];
30
52
  _registerNode(Wedge);
53
+ /**
54
+ * get/set radius
55
+ * @name Konva.Wedge#radius
56
+ * @method
57
+ * @param {Number} radius
58
+ * @returns {Number}
59
+ * @example
60
+ * // get radius
61
+ * var radius = wedge.radius();
62
+ *
63
+ * // set radius
64
+ * wedge.radius(10);
65
+ */
31
66
  Factory.addGetterSetter(Wedge, 'radius', 0, getNumberValidator());
67
+ /**
68
+ * get/set angle in degrees
69
+ * @name Konva.Wedge#angle
70
+ * @method
71
+ * @param {Number} angle
72
+ * @returns {Number}
73
+ * @example
74
+ * // get angle
75
+ * var angle = wedge.angle();
76
+ *
77
+ * // set angle
78
+ * wedge.angle(20);
79
+ */
32
80
  Factory.addGetterSetter(Wedge, 'angle', 0, getNumberValidator());
81
+ /**
82
+ * get/set clockwise flag
83
+ * @name Konva.Wedge#clockwise
84
+ * @method
85
+ * @param {Boolean} clockwise
86
+ * @returns {Boolean}
87
+ * @example
88
+ * // get clockwise flag
89
+ * var clockwise = wedge.clockwise();
90
+ *
91
+ * // draw wedge counter-clockwise
92
+ * wedge.clockwise(false);
93
+ *
94
+ * // draw wedge clockwise
95
+ * wedge.clockwise(true);
96
+ */
33
97
  Factory.addGetterSetter(Wedge, 'clockwise', false);
34
98
  Factory.backCompat(Wedge, {
35
99
  angleDeg: 'angle',
@@ -1,6 +1,9 @@
1
1
  import { Konva } from "./_CoreInternals.js";
2
+ // @ts-ignore
2
3
  import { Canvas, DOMMatrix, Image, Path2D } from 'skia-canvas';
4
+ // @ts-ignore
3
5
  global.DOMMatrix = DOMMatrix;
6
+ // @ts-ignore
4
7
  global.Path2D = Path2D;
5
8
  Path2D.prototype.toString = () => '[object Path2D]';
6
9
  Konva.Util['createCanvasElement'] = () => {
@@ -10,15 +13,21 @@ Konva.Util['createCanvasElement'] = () => {
10
13
  }
11
14
  node.toString = () => '[object HTMLCanvasElement]';
12
15
  const ctx = node.getContext('2d');
16
+ // Override the getter to return the canvas node directly
17
+ // because in skia-canvas canvas is using weak ref to the canvas node
18
+ // and somehow on many tests it fails to get the canvas node
13
19
  Object.defineProperty(ctx, 'canvas', {
14
20
  get: () => node,
15
21
  });
16
22
  return node;
17
23
  };
24
+ // create image in Node env
18
25
  Konva.Util.createImageElement = () => {
19
26
  const node = new Image();
20
27
  node.toString = () => '[object HTMLImageElement]';
21
28
  return node;
22
29
  };
23
30
  Konva._renderBackend = 'skia-canvas';
31
+ // the core Konva object, without shapes and filters. `import 'konva'` extends
32
+ // this same object with them
24
33
  export default Konva;
package/lib/types.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export interface GetSet<Type, This> {
1
+ export interface GetSet<Type, This, SetType = Type> {
2
2
  (): Type;
3
- (v: Type | null | undefined): This;
3
+ (v: SetType | null | undefined): This;
4
4
  }
5
5
  export interface Vector2d {
6
6
  x: number;
@@ -25,27 +25,6 @@ export interface IFrame {
25
25
  frameRate: number;
26
26
  }
27
27
  export type AnimationFn = (frame: IFrame) => boolean | void;
28
- export declare const KonvaNodeEvent: {
29
- readonly mouseover: "mouseover";
30
- readonly mouseout: "mouseout";
31
- readonly mousemove: "mousemove";
32
- readonly mouseleave: "mouseleave";
33
- readonly mouseenter: "mouseenter";
34
- readonly mousedown: "mousedown";
35
- readonly mouseup: "mouseup";
36
- readonly wheel: "wheel";
37
- readonly contextmenu: "contextmenu";
38
- readonly click: "click";
39
- readonly dblclick: "dblclick";
40
- readonly touchstart: "touchstart";
41
- readonly touchmove: "touchmove";
42
- readonly touchend: "touchend";
43
- readonly tap: "tap";
44
- readonly dbltap: "dbltap";
45
- readonly dragstart: "dragstart";
46
- readonly dragmove: "dragmove";
47
- readonly dragend: "dragend";
48
- };
49
28
  export interface RGB {
50
29
  r: number;
51
30
  g: number;
package/lib/types.js CHANGED
@@ -1,21 +1 @@
1
- export const KonvaNodeEvent = {
2
- mouseover: 'mouseover',
3
- mouseout: 'mouseout',
4
- mousemove: 'mousemove',
5
- mouseleave: 'mouseleave',
6
- mouseenter: 'mouseenter',
7
- mousedown: 'mousedown',
8
- mouseup: 'mouseup',
9
- wheel: 'wheel',
10
- contextmenu: 'contextmenu',
11
- click: 'click',
12
- dblclick: 'dblclick',
13
- touchstart: 'touchstart',
14
- touchmove: 'touchmove',
15
- touchend: 'touchend',
16
- tap: 'tap',
17
- dbltap: 'dbltap',
18
- dragstart: 'dragstart',
19
- dragmove: 'dragmove',
20
- dragend: 'dragend',
21
- };
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "konva",
3
- "version": "10.3.3",
3
+ "version": "10.4.0",
4
4
  "description": "HTML5 2d canvas library for interactive graphics, design editors, whiteboards, and diagrams.",
5
5
  "author": "Anton Lavrenov",
6
6
  "type": "module",
@@ -30,27 +30,30 @@
30
30
  "./skia-backend": {
31
31
  "types": "./lib/skia-backend.d.ts",
32
32
  "default": "./lib/skia-backend.js"
33
- }
33
+ },
34
+ "./package.json": "./package.json"
34
35
  },
35
36
  "main": "./lib/index.js",
36
37
  "types": "./lib/index.d.ts",
37
38
  "scripts": {
38
39
  "start": "npm run test:watch",
39
40
  "compile": "npm run clean && npm run tsc && npm run rollup",
41
+ "prepublishOnly": "npm run build",
40
42
  "build": "npm run compile && gulp build",
41
43
  "fmt": "prettier --write .",
42
44
  "fmt:check": "prettier --check .",
43
45
  "test:import": "npm run build && node ./test/import-test.cjs && node ./test/import-test.mjs",
44
- "test": "npm run test:browser && npm run test:node && npm run test:import",
45
- "test:build": "PARCEL_WORKER_BACKEND=process parcel build ./test/unit-tests.html --dist-dir ./test-build --target none --public-url ./ --no-source-maps",
46
+ "test": "npm run test:types && npm run test:browser && npm run test:node && npm run test:import",
47
+ "test:types": "tsc -p test/types/tsconfig.json",
48
+ "test:build": "rimraf ./.parcel-cache && PARCEL_WORKER_BACKEND=process parcel build ./test/unit-tests.html --dist-dir ./test-build --target none --public-url ./ --no-source-maps",
46
49
  "test:browser": "npm run test:build && mocha-headless-chrome -f ./test-build/unit-tests.html -a disable-web-security -a no-sandbox -a disable-setuid-sandbox",
47
50
  "test:watch": "rimraf ./.parcel-cache && PARCEL_WORKERS=0 parcel serve ./test/unit-tests.html ./test/manual-tests.html ./test/sandbox.html ./test/text-paths.html ./test/bunnies.html",
48
- "test:node:canvas": "mocha -r tsx -r ./test/node-canvas-global-setup.mjs --extension ts --recursive './test/unit/' --exit",
49
- "test:node:skia": "mocha -r tsx -r ./test/node-skia-global-setup.mjs --extension ts --recursive './test/unit/' --exit",
51
+ "test:node:canvas": "mocha -r tsx -r ./test/node-canvas-global-setup.mjs --extension ts --recursive './test/unit/'",
52
+ "test:node:skia": "mocha -r tsx -r ./test/node-skia-global-setup.mjs --extension ts --recursive './test/unit/'",
50
53
  "test:node": "npm run test:node:canvas && npm run test:node:skia",
51
- "tsc": "tsc --removeComments",
54
+ "tsc": "tsc",
52
55
  "rollup": "rollup -c",
53
- "clean": "rimraf ./lib && rimraf ./types && rimraf ./cmj && rimraf ./test-build",
56
+ "clean": "rimraf ./lib ./test-build",
54
57
  "watch": "rollup -c -w",
55
58
  "size": "size-limit"
56
59
  },
@@ -73,7 +76,7 @@
73
76
  ],
74
77
  "size-limit": [
75
78
  {
76
- "limit": "45 KB",
79
+ "limit": "48 KB",
77
80
  "path": "./lib/index.js"
78
81
  },
79
82
  {
@@ -90,16 +93,11 @@
90
93
  "@types/mocha": "^10.0.10",
91
94
  "canvas": "^3.2.1",
92
95
  "chai": "6.2.2",
93
- "filehound": "^1.17.6",
94
96
  "gulp": "^5.0.1",
95
- "gulp-concat": "^2.6.1",
96
97
  "gulp-connect": "^5.7.0",
97
- "gulp-exec": "^5.0.0",
98
98
  "gulp-jsdoc3": "^3.0.0",
99
99
  "gulp-rename": "^2.1.0",
100
100
  "gulp-replace": "^1.1.4",
101
- "gulp-typescript": "^5.0.1",
102
- "gulp-uglify": "^3.0.2",
103
101
  "gulp-uglify-es": "^3.0.0",
104
102
  "gulp-util": "^3.0.8",
105
103
  "mocha": "^10",
@@ -112,8 +110,6 @@
112
110
  "rollup-plugin-typescript2": "^0.37.0",
113
111
  "size-limit": "^11.2.0",
114
112
  "skia-canvas": "^3.0.4",
115
- "ts-mocha": "^11.1.0",
116
- "ts-node": "^10.9.2",
117
113
  "tsx": "^4.21.0",
118
114
  "typescript": "^5.9.3"
119
115
  },