modern-path2d 0.0.5 → 0.1.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/README.md CHANGED
@@ -18,6 +18,18 @@
18
18
  </a>
19
19
  </p>
20
20
 
21
+ ## Features
22
+
23
+ - Compatible Web Path2D
24
+
25
+ - Path animation
26
+
27
+ - Path transform
28
+
29
+ - Parse svg to Path2D array
30
+
31
+ - TypeScript
32
+
21
33
  ## 📦 Install
22
34
 
23
35
  ```sh
@@ -27,9 +39,11 @@ npm i modern-path2d
27
39
  ## 🦄 Usage
28
40
 
29
41
  ```ts
30
- import { Path2D } from 'modern-path2d'
42
+ import { parseSvg, Path2D } from 'modern-path2d'
31
43
 
32
44
  const path = new Path2D()
45
+
46
+ // base methods
33
47
  path.arc(75, 75, 50, 0, Math.PI * 2, true)
34
48
  path.moveTo(110, 75)
35
49
  path.arc(75, 75, 35, 0, Math.PI, false)
@@ -38,5 +52,29 @@ path.arc(60, 65, 5, 0, Math.PI * 2, true)
38
52
  path.moveTo(95, 65)
39
53
  path.arc(90, 65, 5, 0, Math.PI * 2, true)
40
54
 
55
+ // add path data
56
+ path.addData('M10,30 A20,20 0,0,1 50,30 A20,20 0,0,1 90,30 Q90,60 50,90 Q10,60 10,30 z M5,5 L90,90')
57
+
58
+ // add path commands
59
+ path.addCommands([
60
+ { type: 'M', x: 118, y: 39 },
61
+ { type: 'L', x: 218, y: 39 }
62
+ ])
63
+
64
+ // add svg
65
+ const parsedPaths = parseSvg(`<svg xmlns="http://www.w3.org/2000/svg" width="72" height="72" viewBox="0 0 72 72" fill="none">
66
+ <path d="M51.3646 45.8642C49.7808 46.2782 47.906 46.705 45.8588 47.0857M45.8588 47.0857C34.1649 49.2607 16.8486 49.9343 16.0277 38.1484C15.22 26.5533 32.264 22.3636 45.6135 24.5626C53.601 25.8783 57.4507 29.6208 57.9285 34.237C58.2811 37.6435 55.778 43.3702 45.8588 47.0857ZM45.8588 47.0857C42.3367 48.4051 37.8795 49.4708 32.283 50.0891" stroke="#FFC300" stroke-width="2.5" stroke-linecap="round"/>
67
+ </svg>`)
68
+ parsedPaths.forEach((parsedPath) => {
69
+ path.addPath(parsedPath)
70
+ })
71
+
72
+ // export to ctx
41
73
  path.strokeTo(document.getElementById('canvas').getContext('2d'))
74
+
75
+ // export path data
76
+ console.log(path.getData())
77
+
78
+ // export path commands
79
+ console.log(path.getCommands())
42
80
  ```