schematic-symbols 0.0.92 → 0.0.94
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.ts +5 -3
- package/dist/index.js +155 -130
- package/dist/index.js.map +1 -1
- package/drawing/rotateSymbol.ts +70 -11
- package/package.json +1 -1
- package/symbols/diode_down.ts +4 -0
- package/symbols/diode_left.ts +4 -0
- package/symbols/{diode_horz.ts → diode_right.ts} +5 -3
- package/symbols/diode_up.ts +4 -0
- package/symbols/varistor_vert.ts +1 -1
- package/symbols/diode_vert.ts +0 -4
package/drawing/rotateSymbol.ts
CHANGED
@@ -7,21 +7,72 @@ import type {
|
|
7
7
|
NinePointAnchor,
|
8
8
|
} from "./types"
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
// Update rotateAnchor to handle all anchor rotations based on orientation
|
11
|
+
const rotateAnchor = (
|
12
|
+
anchor: NinePointAnchor,
|
13
|
+
orientation: "up" | "down" | "left" | "right" = "right",
|
14
|
+
): NinePointAnchor => {
|
15
|
+
switch (orientation) {
|
16
|
+
case "up":
|
17
|
+
switch (anchor) {
|
18
|
+
case "middle_top":
|
19
|
+
return "middle_left"
|
20
|
+
case "middle_bottom":
|
21
|
+
return "middle_right"
|
22
|
+
case "middle_left":
|
23
|
+
return "middle_bottom"
|
24
|
+
case "middle_right":
|
25
|
+
return "middle_top"
|
26
|
+
}
|
27
|
+
break
|
28
|
+
case "down":
|
29
|
+
switch (anchor) {
|
30
|
+
case "middle_top":
|
31
|
+
return "middle_right"
|
32
|
+
case "middle_bottom":
|
33
|
+
return "middle_left"
|
34
|
+
case "middle_left":
|
35
|
+
return "middle_top"
|
36
|
+
case "middle_right":
|
37
|
+
return "middle_bottom"
|
38
|
+
}
|
39
|
+
break
|
40
|
+
case "left":
|
41
|
+
switch (anchor) {
|
42
|
+
case "middle_top":
|
43
|
+
return "middle_left"
|
44
|
+
case "middle_bottom":
|
45
|
+
return "middle_right"
|
46
|
+
case "middle_left":
|
47
|
+
return "middle_bottom"
|
48
|
+
case "middle_right":
|
49
|
+
return "middle_top"
|
50
|
+
}
|
51
|
+
break
|
52
|
+
case "right":
|
53
|
+
return anchor // No change if orientation is "right"
|
16
54
|
}
|
17
55
|
return anchor
|
18
56
|
}
|
19
57
|
|
20
58
|
export const rotateSymbol = (
|
21
59
|
symbol: SchSymbol,
|
60
|
+
orientation?: "up" | "down" | "left" | "right",
|
22
61
|
overrides?: Partial<SchSymbol>,
|
23
62
|
): SchSymbol => {
|
24
|
-
|
63
|
+
// Assuming the default orientation is "right"
|
64
|
+
const angleMap = {
|
65
|
+
up: -Math.PI / 2,
|
66
|
+
right: 0,
|
67
|
+
down: Math.PI / 2,
|
68
|
+
left: -Math.PI,
|
69
|
+
}
|
70
|
+
|
71
|
+
const transform = rotate(
|
72
|
+
orientation ? angleMap[orientation] : Math.PI / 2,
|
73
|
+
symbol.center.x,
|
74
|
+
symbol.center.y,
|
75
|
+
)
|
25
76
|
|
26
77
|
const { primitives, center, size, ports } = symbol
|
27
78
|
|
@@ -41,7 +92,10 @@ export const rotateSymbol = (
|
|
41
92
|
y: primitive.y,
|
42
93
|
}) as Point
|
43
94
|
|
44
|
-
primitive.anchor = rotateAnchor(
|
95
|
+
primitive.anchor = rotateAnchor(
|
96
|
+
primitive.anchor,
|
97
|
+
orientation ?? "right",
|
98
|
+
)
|
45
99
|
|
46
100
|
return {
|
47
101
|
...primitive,
|
@@ -84,10 +138,15 @@ export const rotateSymbol = (
|
|
84
138
|
primitives: rotatedPrimitives,
|
85
139
|
center,
|
86
140
|
ports: rotatedPorts,
|
87
|
-
// TODO recompute size using overrides
|
88
141
|
size: {
|
89
|
-
width:
|
90
|
-
|
142
|
+
width:
|
143
|
+
orientation === "up" || orientation === "down"
|
144
|
+
? size.width
|
145
|
+
: size.height,
|
146
|
+
height:
|
147
|
+
orientation === "up" || orientation === "down"
|
148
|
+
? size.height
|
149
|
+
: size.width,
|
91
150
|
},
|
92
151
|
...overrides,
|
93
152
|
}
|
package/package.json
CHANGED
@@ -1,14 +1,16 @@
|
|
1
|
-
import svgJson from "assets/generated/diode.json"
|
2
1
|
import { defineSymbol } from "drawing/defineSymbol"
|
2
|
+
import svgJson from "assets/generated/diode.json"
|
3
|
+
import { Primitive } from "drawing/types"
|
3
4
|
|
4
|
-
const { paths, texts, bounds, refblocks } = svgJson
|
5
|
+
const { paths, texts, bounds, refblocks, circles } = svgJson
|
5
6
|
|
6
7
|
export default defineSymbol({
|
7
8
|
primitives: [
|
8
9
|
...Object.values(paths),
|
10
|
+
...Object.values(circles),
|
9
11
|
{ ...texts.top1, anchor: "middle_bottom" },
|
10
12
|
{ ...texts.bottom1, anchor: "middle_top" },
|
11
|
-
] as
|
13
|
+
] as Primitive[],
|
12
14
|
ports: [
|
13
15
|
{ ...refblocks.left1, labels: ["1"] }, // TODO add more "standard" labels
|
14
16
|
{ ...refblocks.right1, labels: ["2"] }, // TODO add more "standard" labels
|
package/symbols/varistor_vert.ts
CHANGED
package/symbols/diode_vert.ts
DELETED