schematic-symbols 0.0.96 → 0.0.97
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/dist/index.d.ts +9 -1
- package/dist/index.js +94 -9
- package/dist/index.js.map +1 -1
- package/drawing/rotateSymbol.ts +159 -1
- package/package.json +1 -1
- package/symbols/led_left.ts +2 -2
- package/symbols/led_up.ts +24 -1
package/drawing/rotateSymbol.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { rotate, applyToPoint } from "transformation-matrix"
|
1
|
+
import { rotate, applyToPoint, transform, scale } from "transformation-matrix"
|
2
2
|
import type {
|
3
3
|
SchSymbol,
|
4
4
|
Primitive,
|
@@ -55,6 +55,164 @@ const rotateAnchor = (
|
|
55
55
|
return anchor
|
56
56
|
}
|
57
57
|
|
58
|
+
export const flipSymbolOverXAxis = (
|
59
|
+
symbol: SchSymbol,
|
60
|
+
overrides?: Partial<SchSymbol>,
|
61
|
+
): SchSymbol => {
|
62
|
+
const { primitives, center, ports, size } = symbol
|
63
|
+
const transformMatrix = transform({
|
64
|
+
a: 1,
|
65
|
+
b: 0,
|
66
|
+
c: 0,
|
67
|
+
d: -1,
|
68
|
+
e: 0,
|
69
|
+
f: 2 * center.y,
|
70
|
+
})
|
71
|
+
|
72
|
+
const flippedPrimitives = primitives.map((primitive): Primitive => {
|
73
|
+
primitive = { ...primitive }
|
74
|
+
switch (primitive.type) {
|
75
|
+
case "path":
|
76
|
+
return {
|
77
|
+
...primitive,
|
78
|
+
points: primitive.points.map(
|
79
|
+
(point) => applyToPoint(transformMatrix, point) as Point,
|
80
|
+
),
|
81
|
+
}
|
82
|
+
case "text":
|
83
|
+
const flippedPoint = applyToPoint(transformMatrix, {
|
84
|
+
x: primitive.x,
|
85
|
+
y: primitive.y,
|
86
|
+
}) as Point
|
87
|
+
|
88
|
+
// Flip text anchors vertically
|
89
|
+
const anchorMap: Record<NinePointAnchor, NinePointAnchor> = {
|
90
|
+
top_left: "bottom_left",
|
91
|
+
top_right: "bottom_right",
|
92
|
+
bottom_left: "top_left",
|
93
|
+
bottom_right: "top_right",
|
94
|
+
center: "center",
|
95
|
+
middle_top: "middle_bottom",
|
96
|
+
middle_bottom: "middle_top",
|
97
|
+
middle_left: "middle_left",
|
98
|
+
middle_right: "middle_right",
|
99
|
+
}
|
100
|
+
|
101
|
+
return {
|
102
|
+
...primitive,
|
103
|
+
x: flippedPoint.x,
|
104
|
+
y: flippedPoint.y,
|
105
|
+
anchor: anchorMap[primitive.anchor],
|
106
|
+
}
|
107
|
+
case "circle":
|
108
|
+
case "box":
|
109
|
+
const flippedCenter = applyToPoint(transformMatrix, {
|
110
|
+
x: primitive.x,
|
111
|
+
y: primitive.y,
|
112
|
+
}) as Point
|
113
|
+
return {
|
114
|
+
...primitive,
|
115
|
+
x: flippedCenter.x,
|
116
|
+
y: flippedCenter.y,
|
117
|
+
}
|
118
|
+
}
|
119
|
+
})
|
120
|
+
|
121
|
+
const flippedPorts = ports.map(
|
122
|
+
(port): Port => ({
|
123
|
+
...port,
|
124
|
+
...(applyToPoint(transformMatrix, port) as Point),
|
125
|
+
}),
|
126
|
+
)
|
127
|
+
|
128
|
+
return {
|
129
|
+
primitives: flippedPrimitives,
|
130
|
+
center,
|
131
|
+
ports: flippedPorts,
|
132
|
+
size,
|
133
|
+
...overrides,
|
134
|
+
}
|
135
|
+
}
|
136
|
+
|
137
|
+
export const flipSymbolOverYAxis = (
|
138
|
+
symbol: SchSymbol,
|
139
|
+
overrides?: Partial<SchSymbol>,
|
140
|
+
): SchSymbol => {
|
141
|
+
const { primitives, center, ports, size } = symbol
|
142
|
+
const transformMatrix = transform({
|
143
|
+
a: -1,
|
144
|
+
b: 0,
|
145
|
+
c: 0,
|
146
|
+
d: 1,
|
147
|
+
e: 0,
|
148
|
+
f: 2 * center.x,
|
149
|
+
})
|
150
|
+
|
151
|
+
const flippedPrimitives = primitives.map((primitive): Primitive => {
|
152
|
+
primitive = { ...primitive }
|
153
|
+
switch (primitive.type) {
|
154
|
+
case "path":
|
155
|
+
return {
|
156
|
+
...primitive,
|
157
|
+
points: primitive.points.map(
|
158
|
+
(point) => applyToPoint(transformMatrix, point) as Point,
|
159
|
+
),
|
160
|
+
}
|
161
|
+
case "text":
|
162
|
+
const flippedPoint = applyToPoint(transformMatrix, {
|
163
|
+
x: primitive.x,
|
164
|
+
y: primitive.y,
|
165
|
+
}) as Point
|
166
|
+
|
167
|
+
// Flip text anchors horizontally
|
168
|
+
const anchorMap: Record<NinePointAnchor, NinePointAnchor> = {
|
169
|
+
top_left: "top_right",
|
170
|
+
top_right: "top_left",
|
171
|
+
bottom_left: "bottom_right",
|
172
|
+
bottom_right: "bottom_left",
|
173
|
+
center: "center",
|
174
|
+
middle_top: "middle_top",
|
175
|
+
middle_bottom: "middle_bottom",
|
176
|
+
middle_left: "middle_right",
|
177
|
+
middle_right: "middle_left",
|
178
|
+
}
|
179
|
+
|
180
|
+
return {
|
181
|
+
...primitive,
|
182
|
+
x: flippedPoint.x,
|
183
|
+
y: flippedPoint.y,
|
184
|
+
anchor: anchorMap[primitive.anchor],
|
185
|
+
}
|
186
|
+
case "circle":
|
187
|
+
case "box":
|
188
|
+
const flippedCenter = applyToPoint(transformMatrix, {
|
189
|
+
x: primitive.x,
|
190
|
+
y: primitive.y,
|
191
|
+
}) as Point
|
192
|
+
return {
|
193
|
+
...primitive,
|
194
|
+
x: flippedCenter.x,
|
195
|
+
y: flippedCenter.y,
|
196
|
+
}
|
197
|
+
}
|
198
|
+
})
|
199
|
+
|
200
|
+
const flippedPorts = ports.map(
|
201
|
+
(port): Port => ({
|
202
|
+
...port,
|
203
|
+
...(applyToPoint(transformMatrix, port) as Point),
|
204
|
+
}),
|
205
|
+
)
|
206
|
+
|
207
|
+
return {
|
208
|
+
primitives: flippedPrimitives,
|
209
|
+
center,
|
210
|
+
ports: flippedPorts,
|
211
|
+
size,
|
212
|
+
...overrides,
|
213
|
+
}
|
214
|
+
}
|
215
|
+
|
58
216
|
export const rotateSymbol = (
|
59
217
|
symbol: SchSymbol,
|
60
218
|
orientation?: "up" | "down" | "left" | "right",
|
package/package.json
CHANGED
package/symbols/led_left.ts
CHANGED
package/symbols/led_up.ts
CHANGED
@@ -1,4 +1,27 @@
|
|
1
1
|
import { rotateSymbol } from "drawing/rotateSymbol"
|
2
2
|
import led_right from "./led_right"
|
3
3
|
|
4
|
-
|
4
|
+
const baseSymbol = rotateSymbol(led_right, "up")
|
5
|
+
|
6
|
+
// Flip path25-0 and path78 over X axis
|
7
|
+
const modifiedSymbol = {
|
8
|
+
...baseSymbol,
|
9
|
+
primitives: baseSymbol.primitives.map((primitive) => {
|
10
|
+
if (
|
11
|
+
primitive.type === "path" &&
|
12
|
+
(primitive.points.length === 3 || primitive.points.length === 4)
|
13
|
+
) {
|
14
|
+
// This matches both the triangle shape (path25-0) and path78
|
15
|
+
return {
|
16
|
+
...primitive,
|
17
|
+
points: primitive.points.map((point) => ({
|
18
|
+
x: point.x,
|
19
|
+
y: -point.y + 2 * baseSymbol.center.y,
|
20
|
+
})),
|
21
|
+
}
|
22
|
+
}
|
23
|
+
return primitive
|
24
|
+
}),
|
25
|
+
}
|
26
|
+
|
27
|
+
export default modifiedSymbol
|