path2d-polyfill 1.2.3 → 2.0.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,25 @@
1
+ ## [2.0.0](https://github.com/nilzona/path2d-polyfill/compare/v1.2.3...v2.0.0) (2023-01-22)
2
+
3
+ ### ⚠ BREAKING CHANGES
4
+
5
+ - target build now has the name `dist/path2d-polyfill.min.js`
6
+
7
+ - chore: null Path2D in example index.html
8
+
9
+ - Update tsconfig.json
10
+
11
+ Co-authored-by: Linus Unnebäck <linus@folkdatorn.se>
12
+
13
+ - chore: build for node and browsers
14
+
15
+ - docs: update doc example
16
+
17
+ Co-authored-by: Linus Unnebäck <linus@folkdatorn.se>
18
+
19
+ ### Features
20
+
21
+ - node support with roundRect polyfill ([#43](https://github.com/nilzona/path2d-polyfill/issues/43)) ([2fffe15](https://github.com/nilzona/path2d-polyfill/commit/2fffe15a76e7adac50beacc0f9587d5b3cc71485))
22
+
1
23
  ## [1.2.3](https://github.com/nilzona/path2d-polyfill/compare/v1.2.2...v1.2.3) (2022-10-11)
2
24
 
3
25
  ## [1.2.2](https://github.com/nilzona/path2d-polyfill/compare/v1.2.1...v1.2.2) (2022-07-23)
package/README.md CHANGED
@@ -2,9 +2,7 @@
2
2
 
3
3
  [![validate](https://github.com/nilzona/path2d-polyfill/actions/workflows/validate.yaml/badge.svg)](https://github.com/nilzona/path2d-polyfill/actions/workflows/validate.yaml)
4
4
 
5
- Polyfills Path2D api for rendering SVG paths in canvas
6
-
7
- Use this to enable Path2D features in e.g. Internet Explorer.
5
+ Polyfills `Path2D` api and `roundRect` for CanvasRenderingContext2D
8
6
 
9
7
  ## Usage
10
8
 
@@ -23,15 +21,60 @@ npm install --save path2d-polyfill
23
21
  and import with module bundler e.g. webpack _before_ using the feature
24
22
 
25
23
  ```javascript
26
- require("path2d-polyfill");
24
+ import "path2d-polyfill";
27
25
  ```
28
26
 
29
- or with es2015+ modules
27
+ This will polyfill the browser's window object with Path2D features and it will also polyfill roundRect if they are missing in both CanvasRenderingContexst and Path2D.
28
+
29
+ Example of usage
30
30
 
31
31
  ```javascript
32
- import "path2d-polyfill";
32
+ ctx.fill(new Path2D("M 80 80 A 45 45 0 0 0 125 125 L 125 80 Z"));
33
+ ctx.stroke(new Path2D("M 80 80 A 45 45 0 0 0 125 125 L 125 80 Z"));
34
+ ```
35
+
36
+ ## Usage in a node environment
37
+
38
+ It is possible to use this library in a node environment as well. The package exports a few functions that can be used:
39
+
40
+ - `Path2D` - class to create Path2D objects used by the polyfill methods
41
+ - `polyfillPath2D` - function that adds Path2D to a "window like" object and polyfills CanvasRenderingContext2D to use Path2D
42
+ - `polyfillRoundRect` - polyfills roundRect function on Path2D and CanvasRenderingContext2D (missing in firefox)
43
+ - `parsePath` - function for parsing an SVG path string into canvas commands
44
+
45
+ use any of these functions like:
46
+
47
+ ```js
48
+ const { polyfillRoundRect } = require "path2d-polyfill";
49
+
50
+ const windowlike = { CanvasRenderingContext2D, Path2D };
51
+
52
+ polyfillRoundRect(windowLike);
53
+ // roundRect functions has now been added if they were missing
33
54
  ```
34
55
 
56
+ ### usage with node-canvas
57
+
58
+ To get Path2D features with the [node-canvas library](https://github.com/Automattic/node-canvas) use the following pattern:
59
+
60
+ ```js
61
+ const { createCanvas, CanvasRenderingContext2D } = require("canvas");
62
+ const { polyfillPath2D } = require("path2d-polyfill/path2d");
63
+
64
+ global.CanvasRenderingContext2D = CanvasRenderingContext2D;
65
+ polyfillPath2D(global);
66
+ // Path2D has now been added to global object
67
+
68
+ const canvas = createCanvas(200, 200);
69
+ const ctx = canvas.getContext("2d");
70
+
71
+ const p = new Path2D("M10 10 l 20 0 l 0 20 Z");
72
+ ctx.fillStyle = "green";
73
+ ctx.fill(p);
74
+ ```
75
+
76
+ A working example of a node express server that serves an image drawn with canvas can be seen [here](https://gist.github.com/nilzona/e611c99336d8ea1f645bd391a459c24f)
77
+
35
78
  ## Support table
36
79
 
37
80
  | Method | Supported |
@@ -46,13 +89,7 @@ import "path2d-polyfill";
46
89
  | arc() | Yes |
47
90
  | ellipse() | Yes |
48
91
  | rect() | Yes |
49
-
50
- Example of usage
51
-
52
- ```javascript
53
- ctx.fill(new Path2D("M 80 80 A 45 45 0 0 0 125 125 L 125 80 Z"));
54
- ctx.stroke(new Path2D("M 80 80 A 45 45 0 0 0 125 125 L 125 80 Z"));
55
- ```
92
+ | roundRect() | Yes |
56
93
 
57
94
  ## See it in action
58
95