schematic-symbols 0.0.41 → 0.0.43

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.
@@ -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
- currentX = args[0]
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
- currentX = args[0]
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
- currentX = args[0]
32
- points.push({ x: currentX, y: currentY })
32
+ addPoint(args[0], currentY)
33
33
  break
34
34
  case "V":
35
- currentY = args[0]
36
- points.push({ x: currentX, y: currentY })
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, Q, T, A) if needed
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
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "schematic-symbols",
3
3
  "main": "./dist/index.js",
4
- "version": "0.0.41",
4
+ "version": "0.0.43",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist",
@@ -0,0 +1,42 @@
1
+ import { defineSymbol } from "drawing/defineSymbol"
2
+ import svgJson from "assets/generated/power_factor_meter.json"
3
+ import { ninePointAnchorToSvgAnchor } from "drawing/ninePointAnchorToSvgAnchor"
4
+
5
+ const { paths, texts, bounds, refblocks, circles } = svgJson
6
+
7
+ export default defineSymbol({
8
+ primitives: [
9
+ ...Object.values(paths),
10
+ ...Object.values(circles),
11
+ // { ...texts.top1, anchor: "middle_left" },
12
+ {
13
+ type: "text",
14
+ text: "{REF}",
15
+ x: -0.15,
16
+ y: -0.42330070000000064,
17
+ anchor: "middle_left",
18
+ },
19
+ // { ...texts.bottom1, anchor: "middle_left" },
20
+ {
21
+ type: "text",
22
+ text: "{VAL}",
23
+ x: -0.15,
24
+ y: 0.42330070000000064,
25
+ anchor: "middle_left",
26
+ },
27
+ // { ...texts.left1, anchor: "middle_left" },
28
+ {
29
+ type: "text",
30
+ text: "COS φ",
31
+ x: -0.14,
32
+ y: 0.014279000000000375,
33
+ anchor: "middle-left",
34
+ },
35
+ ] as any,
36
+ ports: [
37
+ { ...refblocks.left1, labels: ["1"] }, // TODO add more "standard" labels
38
+ { ...refblocks.right1, labels: ["2"] }, // TODO add more "standard" labels
39
+ ],
40
+ size: { width: bounds.width, height: bounds.height },
41
+ center: { x: bounds.centerX, y: bounds.centerY },
42
+ })
@@ -0,0 +1,16 @@
1
+ import { rotateSymbol } from "drawing/rotateSymbol"
2
+ import power_factor_meter_horz from "./power_factor_meter_horz"
3
+ import { text } from "drawing/text"
4
+
5
+ const rotatedSymbol = rotateSymbol(power_factor_meter_horz)
6
+ const texts = rotatedSymbol.primitives.filter((p) => p.type === "text")
7
+ const ref = texts.find((t) => t.text === "{REF}")!
8
+ const val = texts.find((t) => t.text === "{VAL}")!
9
+ const text_cos = texts.find((t) => t.text === "COS φ")!
10
+ ref.x = 0.35
11
+ ref.y = 0
12
+ val.x = -0.6
13
+ val.y = 0
14
+ text_cos.x = -0.1
15
+ text_cos.y = 0
16
+ export default rotatedSymbol