schematic-symbols 0.0.42 → 0.0.44
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/drawing/svgPathToPoints.ts +26 -12
- package/package.json +1 -1
@@ -4,10 +4,15 @@ export function svgPathToPoints(pathString: string): Point[] {
|
|
4
4
|
const points: Point[] = []
|
5
5
|
const commands =
|
6
6
|
pathString.match(/[MmLlHhVvCcSsQqTtAaZz][^MmLlHhVvCcSsQqTtAaZz]*/g) || []
|
7
|
-
|
8
7
|
let currentX = 0
|
9
8
|
let currentY = 0
|
10
9
|
|
10
|
+
function addPoint(x: number, y: number) {
|
11
|
+
points.push({ x, y })
|
12
|
+
currentX = x
|
13
|
+
currentY = y
|
14
|
+
}
|
15
|
+
|
11
16
|
for (const command of commands) {
|
12
17
|
const type = command[0]
|
13
18
|
const args = command
|
@@ -18,33 +23,42 @@ export function svgPathToPoints(pathString: string): Point[] {
|
|
18
23
|
|
19
24
|
switch (type.toUpperCase()) {
|
20
25
|
case "M":
|
21
|
-
|
22
|
-
currentY = args[1]
|
23
|
-
points.push({ x: currentX, y: currentY })
|
26
|
+
addPoint(args[0], args[1])
|
24
27
|
break
|
25
28
|
case "L":
|
26
|
-
|
27
|
-
currentY = args[1]
|
28
|
-
points.push({ x: currentX, y: currentY })
|
29
|
+
addPoint(args[0], args[1])
|
29
30
|
break
|
30
31
|
case "H":
|
31
|
-
|
32
|
-
points.push({ x: currentX, y: currentY })
|
32
|
+
addPoint(args[0], currentY)
|
33
33
|
break
|
34
34
|
case "V":
|
35
|
-
|
36
|
-
|
35
|
+
addPoint(currentX, args[0])
|
36
|
+
break
|
37
|
+
case "Q":
|
38
|
+
// For Q command, we add both the control point and the end point
|
39
|
+
points.push({ x: args[0], y: args[1] }) // Control point
|
40
|
+
addPoint(args[2], args[3]) // End point
|
37
41
|
break
|
38
42
|
case "Z":
|
39
43
|
// Close path - no new point
|
40
44
|
break
|
41
|
-
// Add cases for other commands (C, S,
|
45
|
+
// Add cases for other commands (C, S, T, A) if needed
|
42
46
|
default:
|
43
47
|
console.warn(`Unsupported SVG command: ${type}`)
|
44
48
|
}
|
45
49
|
|
46
50
|
// Handle relative commands
|
47
51
|
if (type === type.toLowerCase() && type !== "z") {
|
52
|
+
if (type === "q") {
|
53
|
+
// For relative q, adjust both control point and end point
|
54
|
+
points[points.length - 2].x += currentX
|
55
|
+
points[points.length - 2].y += currentY
|
56
|
+
points[points.length - 1].x += currentX
|
57
|
+
points[points.length - 1].y += currentY
|
58
|
+
} else {
|
59
|
+
points[points.length - 1].x += currentX
|
60
|
+
points[points.length - 1].y += currentY
|
61
|
+
}
|
48
62
|
currentX = points[points.length - 1].x
|
49
63
|
currentY = points[points.length - 1].y
|
50
64
|
}
|