konva 10.9.1 → 10.11.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 (71) hide show
  1. package/README.md +22 -10
  2. package/konva.js +19184 -18924
  3. package/konva.min.js +50 -50
  4. package/lib/Animation.js +3 -3
  5. package/lib/Canvas.js +11 -3
  6. package/lib/Container.js +5 -4
  7. package/lib/Context.d.ts +1 -2
  8. package/lib/Context.js +12 -39
  9. package/lib/Core.js +2 -2
  10. package/lib/DragAndDrop.js +1 -1
  11. package/lib/Factory.js +2 -2
  12. package/lib/FastLayer.js +3 -3
  13. package/lib/Global.d.ts +0 -1
  14. package/lib/Global.js +13 -7
  15. package/lib/Group.js +5 -5
  16. package/lib/Layer.d.ts +1 -1
  17. package/lib/Layer.js +8 -8
  18. package/lib/Node.d.ts +3 -1
  19. package/lib/Node.js +105 -66
  20. package/lib/PointerEvents.js +1 -1
  21. package/lib/Shape.d.ts +8 -1
  22. package/lib/Shape.js +129 -32
  23. package/lib/Stage.js +8 -8
  24. package/lib/Tween.js +4 -4
  25. package/lib/Util.d.ts +67 -3
  26. package/lib/Util.js +123 -42
  27. package/lib/Validators.js +2 -2
  28. package/lib/_CoreInternals.d.ts +15 -11
  29. package/lib/_CoreInternals.js +16 -14
  30. package/lib/_FullInternals.d.ts +14 -10
  31. package/lib/_FullInternals.js +38 -38
  32. package/lib/canvas-backend.js +6 -15
  33. package/lib/filters/Blur.js +3 -3
  34. package/lib/filters/Brighten.js +3 -3
  35. package/lib/filters/Brightness.js +2 -2
  36. package/lib/filters/Contrast.js +3 -3
  37. package/lib/filters/Emboss.js +10 -9
  38. package/lib/filters/Enhance.js +3 -3
  39. package/lib/filters/HSL.js +3 -3
  40. package/lib/filters/HSV.js +3 -3
  41. package/lib/filters/Kaleidoscope.js +3 -3
  42. package/lib/filters/Mask.js +3 -3
  43. package/lib/filters/Noise.js +3 -3
  44. package/lib/filters/Pixelate.js +4 -4
  45. package/lib/filters/Posterize.js +3 -3
  46. package/lib/filters/RGB.js +3 -3
  47. package/lib/filters/RGBA.js +3 -3
  48. package/lib/filters/Threshold.js +3 -3
  49. package/lib/index.js +1 -1
  50. package/lib/napi-backend.d.ts +2 -0
  51. package/lib/napi-backend.js +15 -0
  52. package/lib/shapes/Arc.js +5 -5
  53. package/lib/shapes/Arrow.js +5 -5
  54. package/lib/shapes/Circle.js +4 -4
  55. package/lib/shapes/Ellipse.js +4 -4
  56. package/lib/shapes/Image.js +5 -5
  57. package/lib/shapes/Label.js +7 -7
  58. package/lib/shapes/Line.js +6 -6
  59. package/lib/shapes/Path.js +5 -5
  60. package/lib/shapes/Rect.js +5 -5
  61. package/lib/shapes/RegularPolygon.js +5 -5
  62. package/lib/shapes/Ring.js +4 -4
  63. package/lib/shapes/Sprite.js +5 -5
  64. package/lib/shapes/Star.js +4 -4
  65. package/lib/shapes/Text.d.ts +0 -1
  66. package/lib/shapes/Text.js +32 -30
  67. package/lib/shapes/TextPath.js +7 -7
  68. package/lib/shapes/Transformer.js +12 -11
  69. package/lib/shapes/Wedge.js +5 -5
  70. package/lib/skia-backend.js +17 -25
  71. package/package.json +31 -34
package/README.md CHANGED
@@ -128,20 +128,17 @@ import { Blur } from 'konva/lib/filters/Blur';
128
128
 
129
129
  ### 4 NodeJS env
130
130
 
131
- In order to run `konva` in nodejs environment you also need to install `canvas` or `skia-canvas` package manually for rendering backend.
131
+ In order to run `konva` in nodejs environment you also need to install `canvas`, `skia-canvas` or `@napi-rs/canvas` package manually for rendering backend.
132
132
 
133
133
  ```bash
134
- # node-canvas backend
135
- npm install konva canvas
136
- # skia-canvas backend
137
- npm install konva skia-canvas
134
+ npm install konva canvas # or skia-canvas, or @napi-rs/canvas
138
135
  ```
139
136
 
140
137
  Use the same scene graph API for server-side rendering and omit the stage's `container` attribute. DOM events require a browser, and canvas feature support depends on the selected backend.
141
138
 
142
139
  ```js
143
140
  import Konva from 'konva';
144
- import 'konva/canvas-backend'; // or import 'konva/skia-backend';
141
+ import 'konva/canvas-backend'; // or 'konva/skia-backend', or 'konva/napi-backend'
145
142
 
146
143
  const stage = new Konva.Stage({
147
144
  width: 500,
@@ -150,6 +147,25 @@ const stage = new Konva.Stage({
150
147
  // Add shapes and export the stage with the usual Konva drawing API.
151
148
  ```
152
149
 
150
+ A backend module also sets the global `DOMMatrix` and `Path2D`. To leave globals alone, or to use another canvas library, pass it to `Konva.setCanvasBackend()`. `Konva.getCanvasBackend()` returns the name of the active one, or `null` before one is set:
151
+
152
+ ```js
153
+ import { Canvas, Image, Path2D } from '@napi-rs/canvas';
154
+
155
+ Konva.setCanvasBackend({
156
+ name: 'my-canvas',
157
+ createCanvas: () => new Canvas(300, 150),
158
+ createImage: () => new Image(), // optional, to load images
159
+ createPath2D: (path) => new Path2D(path), // optional, for Konva.Util.createPath2D()
160
+ });
161
+ ```
162
+
163
+ Create stages and nodes again after the call: ones created before keep the canvases, gradients and patterns of the old library.
164
+
165
+ ### 5 Web Worker
166
+
167
+ Konva draws on `OffscreenCanvas` in a Web Worker without setup. Export with `toBlob()`, since `toDataURL()` is not available there, and pass images as `ImageBitmap`. DOM events do not reach a worker; forward them from the page.
168
+
153
169
  # Backers
154
170
 
155
171
  Konva is maintained by the team behind [Polotno](https://polotno.com/?utm_source=konvajs&utm_medium=readme&utm_content=konva-backers), a commercial design editor SDK built on Konva, which sponsors ongoing development.
@@ -178,10 +194,6 @@ Konva uses Mocha for testing.
178
194
  Konva is covered with hundreds of tests and well over a thousand assertions.
179
195
  For each feature or bug fix, write a failing test first, implement the behavior, then verify that the test passes (test-driven development).
180
196
 
181
- ## Generate documentation
182
-
183
- Run `npm run build`, then `npx gulp api` to generate documentation from the current bundle in the `api` folder.
184
-
185
197
  # Pull Requests
186
198
 
187
199
  I'd be happy to review any pull requests that may better the Konva project,