schematic-symbols 0.0.89 → 0.0.91
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.ts +5 -1
- package/dist/index.js +1809 -537
- package/dist/index.js.map +1 -1
- package/drawing/arc.ts +29 -0
- package/drawing/svgPathToPoints.ts +18 -2
- package/package.json +1 -1
- package/symbols/ground_horz.ts +37 -0
- package/symbols/ground_vert.ts +34 -0
- package/symbols/inductor_horz.ts +20 -0
- package/symbols/inductor_vert.ts +4 -0
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
|
-
|
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
@@ -0,0 +1,37 @@
|
|
1
|
+
import { defineSymbol } from "drawing/defineSymbol"
|
2
|
+
import svgJson from "assets/generated/ground.json"
|
3
|
+
import { Primitive } from "drawing/types"
|
4
|
+
import { rotateSymbol } from "drawing/rotateSymbol"
|
5
|
+
|
6
|
+
// Extract paths, bounds, etc.
|
7
|
+
const { paths, circles, bounds, refblocks } = svgJson
|
8
|
+
|
9
|
+
// Horizontal orientation symbol
|
10
|
+
export const horizontalSymbol = defineSymbol({
|
11
|
+
primitives: [
|
12
|
+
...Object.values(paths),
|
13
|
+
...Object.values(circles),
|
14
|
+
{
|
15
|
+
type: "text",
|
16
|
+
text: "{REF}", // REF label for horizontal
|
17
|
+
x: -0.1, // Adjust this for the horizontal positioning of REF
|
18
|
+
y: -0.8, // Adjust this for the vertical positioning of REF
|
19
|
+
anchor: "middle_bottom", // Horizontal anchor for REF
|
20
|
+
},
|
21
|
+
{
|
22
|
+
type: "text",
|
23
|
+
text: "{VAL}", // VAL label for horizontal
|
24
|
+
x: -0.1, // Adjust for horizontal positioning of VAL
|
25
|
+
y: -0.1, // Adjust for vertical positioning of VAL
|
26
|
+
anchor: "middle_top", // Horizontal anchor for VAL
|
27
|
+
},
|
28
|
+
] as Primitive[],
|
29
|
+
ports: [{ ...refblocks.top1, labels: ["1"] }],
|
30
|
+
size: { width: bounds.width, height: bounds.height },
|
31
|
+
center: { x: bounds.centerX - 0.09, y: bounds.centerY - 0.45 },
|
32
|
+
})
|
33
|
+
|
34
|
+
// Vertical orientation symbol
|
35
|
+
|
36
|
+
// Export vertical symbol (rotated 90 degrees from original)
|
37
|
+
export default horizontalSymbol
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import { defineSymbol } from "drawing/defineSymbol"
|
2
|
+
import svgJson from "assets/generated/ground.json"
|
3
|
+
import { Primitive } from "drawing/types"
|
4
|
+
import { rotateSymbol } from "drawing/rotateSymbol"
|
5
|
+
|
6
|
+
// Extract paths, bounds, etc.
|
7
|
+
const { paths, circles, bounds, refblocks } = svgJson
|
8
|
+
|
9
|
+
export const verticalSymbol = defineSymbol({
|
10
|
+
primitives: [
|
11
|
+
...Object.values(paths),
|
12
|
+
...Object.values(circles),
|
13
|
+
{
|
14
|
+
type: "text",
|
15
|
+
text: "{REF}", // REF label for vertical
|
16
|
+
x: -0.015, // Adjust this for the horizontal positioning of REF
|
17
|
+
y: -0.75, // Adjust this for the vertical positioning of REF
|
18
|
+
anchor: "middle_bottom", // Vertical anchor for REF
|
19
|
+
},
|
20
|
+
{
|
21
|
+
type: "text",
|
22
|
+
text: "{VAL}", // VAL label for vertical
|
23
|
+
x: -0.015, // Adjust for horizontal positioning of VAL
|
24
|
+
y: -0.12, // Adjust for vertical positioning of VAL
|
25
|
+
anchor: "middle_top", // Vertical anchor for VAL
|
26
|
+
},
|
27
|
+
] as Primitive[],
|
28
|
+
ports: [{ ...refblocks.top1, labels: ["1"] }],
|
29
|
+
size: { width: bounds.width, height: bounds.height },
|
30
|
+
center: { x: bounds.centerX, y: bounds.centerY - 0.45 },
|
31
|
+
})
|
32
|
+
|
33
|
+
// Export vertical symbol (rotated 90 degrees from original)
|
34
|
+
export default rotateSymbol(verticalSymbol)
|
@@ -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
|
+
})
|