schematic-symbols 0.0.89 → 0.0.90

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/arc.ts ADDED
@@ -0,0 +1,29 @@
1
+ import type { Point } from "./types"
2
+
3
+ export function approximateArc(
4
+ x1: number,
5
+ y1: number,
6
+ rx: number,
7
+ ry: number,
8
+ largeArcFlag: number,
9
+ x2: number,
10
+ y2: number,
11
+ ): Point[] {
12
+ // This is a simplified approximation. For a more accurate representation,
13
+ // you might want to use a dedicated SVG path library.
14
+ const steps = 30
15
+ const points: Point[] = []
16
+ for (let i = 1; i < steps; i++) {
17
+ const t = i / steps
18
+ const x = (1 - t) * x1 + t * x2
19
+ const y = (1 - t) * y1 + t * y2
20
+ // Apply a simple curve to make it non-linear, with reduced height and no center drop
21
+ const curveY =
22
+ 0.03 *
23
+ Math.abs(Math.sin(t * Math.PI)) *
24
+ Math.min(rx, ry) *
25
+ (largeArcFlag ? 1 : -1)
26
+ points.push({ x, y: y + curveY })
27
+ }
28
+ return points
29
+ }
@@ -1,4 +1,5 @@
1
1
  import type { Point } from "./types"
2
+ import { approximateArc } from "./arc"
2
3
 
3
4
  export function svgPathToPoints(pathString: string): Point[] {
4
5
  const points: Point[] = []
@@ -48,13 +49,28 @@ export function svgPathToPoints(pathString: string): Point[] {
48
49
  case "Z":
49
50
  // Close path - no new point
50
51
  break
51
- // Add cases for other commands (S, T, A) if needed
52
+ case "A":
53
+ // For A command, we add the end point and intermediate points to approximate the arc
54
+ const [rx, ry, xAxisRotation, largeArcFlag, sweepFlag, x, y] = args
55
+ const arcPoints = approximateArc(
56
+ currentX,
57
+ currentY,
58
+ rx,
59
+ ry,
60
+ largeArcFlag,
61
+ x,
62
+ y,
63
+ )
64
+ arcPoints.forEach((point) => points.push(point))
65
+ addPoint(x, y)
66
+ break
67
+ // Add cases for other commands (S, T) if needed
52
68
  default:
53
69
  console.warn(`Unsupported SVG command: ${type}`)
54
70
  }
55
71
 
56
72
  // Handle relative commands
57
- if (type === type.toLowerCase() && type !== "z") {
73
+ if (type === type.toLowerCase() && type !== "z" && type !== "a") {
58
74
  if (type === "c") {
59
75
  // For relative c, adjust both control points and end point
60
76
  points[points.length - 3].x += currentX
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.89",
4
+ "version": "0.0.90",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist",
@@ -0,0 +1,20 @@
1
+ import { defineSymbol } from "drawing/defineSymbol"
2
+ import svgJson from "assets/generated/inductor.json"
3
+ import { Primitive } from "drawing/types"
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_bottom" },
12
+ { ...texts.bottom1, anchor: "middle_top" },
13
+ ] as Primitive[],
14
+ ports: [
15
+ { ...refblocks.left1, labels: ["1"] }, // TODO add more "standard" labels
16
+ { ...refblocks.right1, labels: ["2"] }, // TODO add more "standard" labels
17
+ ],
18
+ size: { width: bounds.width, height: bounds.height },
19
+ center: { x: bounds.centerX, y: bounds.centerY },
20
+ })
@@ -0,0 +1,4 @@
1
+ import { rotateSymbol } from "drawing/rotateSymbol"
2
+ import inductor_horz from "./inductor_horz"
3
+
4
+ export default rotateSymbol(inductor_horz)