schematic-symbols 0.0.121 → 0.0.123

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.
Files changed (197) hide show
  1. package/dist/index.js +2 -2
  2. package/dist/index.js.map +1 -1
  3. package/package.json +2 -5
  4. package/drawing/arc.ts +0 -31
  5. package/drawing/arrow.ts +0 -41
  6. package/drawing/box.ts +0 -5
  7. package/drawing/circle.ts +0 -7
  8. package/drawing/cubicBezierCurveArc.ts +0 -28
  9. package/drawing/defineSymbol.ts +0 -16
  10. package/drawing/getSvg.ts +0 -199
  11. package/drawing/index.ts +0 -10
  12. package/drawing/mapColor.ts +0 -10
  13. package/drawing/modify-symbol/modify-symbol.ts +0 -97
  14. package/drawing/ninePointAnchorToSvgAnchor.ts +0 -11
  15. package/drawing/path.ts +0 -5
  16. package/drawing/pathToSvgD.ts +0 -22
  17. package/drawing/resizeSymbol.ts +0 -67
  18. package/drawing/rotateSymbol.ts +0 -324
  19. package/drawing/svgPathToPoints.ts +0 -109
  20. package/drawing/text.ts +0 -8
  21. package/drawing/typeguards.ts +0 -155
  22. package/drawing/types.ts +0 -93
  23. package/drawing/utils/getBoundsOfPrimitives.ts +0 -51
  24. package/drawing/utils/makeYUpPositive.ts +0 -46
  25. package/index.ts +0 -24
  26. package/symbols/SPDT_switch_horz.ts +0 -22
  27. package/symbols/SPDT_switch_vert.ts +0 -20
  28. package/symbols/SPST_switch_horz.ts +0 -12
  29. package/symbols/SPST_switch_vert.ts +0 -20
  30. package/symbols/ac_voltmeter_horz.ts +0 -31
  31. package/symbols/ac_voltmeter_vert.ts +0 -8
  32. package/symbols/avalanche_diode_horz.ts +0 -19
  33. package/symbols/avalanche_diode_vert.ts +0 -10
  34. package/symbols/battery_horz.ts +0 -20
  35. package/symbols/battery_vert.ts +0 -6
  36. package/symbols/boxresistor_down.ts +0 -33
  37. package/symbols/boxresistor_left.ts +0 -33
  38. package/symbols/boxresistor_right.ts +0 -33
  39. package/symbols/boxresistor_up.ts +0 -33
  40. package/symbols/capacitor_down.ts +0 -34
  41. package/symbols/capacitor_left.ts +0 -11
  42. package/symbols/capacitor_polarized_down.ts +0 -34
  43. package/symbols/capacitor_polarized_left.ts +0 -10
  44. package/symbols/capacitor_polarized_right.ts +0 -10
  45. package/symbols/capacitor_polarized_up.ts +0 -34
  46. package/symbols/capacitor_right.ts +0 -10
  47. package/symbols/capacitor_up.ts +0 -34
  48. package/symbols/constant_current_diode_horz.ts +0 -9
  49. package/symbols/constant_current_diode_vert.ts +0 -11
  50. package/symbols/crystal_4pin_horz.ts +0 -11
  51. package/symbols/crystal_4pin_vert.ts +0 -10
  52. package/symbols/crystal_horz.ts +0 -9
  53. package/symbols/crystal_vert.ts +0 -10
  54. package/symbols/darlington_pair_transistor_horz.ts +0 -10
  55. package/symbols/darlington_pair_transistor_vert.ts +0 -12
  56. package/symbols/dc_ammeter_horz.ts +0 -32
  57. package/symbols/dc_ammeter_vert.ts +0 -51
  58. package/symbols/dc_voltmeter_horz.ts +0 -31
  59. package/symbols/dc_voltmeter_vert.ts +0 -19
  60. package/symbols/diac_horz.ts +0 -9
  61. package/symbols/diac_vert.ts +0 -16
  62. package/symbols/diode_down.ts +0 -4
  63. package/symbols/diode_left.ts +0 -4
  64. package/symbols/diode_right.ts +0 -9
  65. package/symbols/diode_up.ts +0 -4
  66. package/symbols/dpdt_normally_closed_switch_down.ts +0 -22
  67. package/symbols/dpdt_normally_closed_switch_left.ts +0 -23
  68. package/symbols/dpdt_normally_closed_switch_right.ts +0 -13
  69. package/symbols/dpdt_normally_closed_switch_up.ts +0 -22
  70. package/symbols/dpdt_switch_down.ts +0 -22
  71. package/symbols/dpdt_switch_left.ts +0 -23
  72. package/symbols/dpdt_switch_right.ts +0 -13
  73. package/symbols/dpdt_switch_up.ts +0 -22
  74. package/symbols/dpst_normally_closed_switch_down.ts +0 -22
  75. package/symbols/dpst_normally_closed_switch_left.ts +0 -23
  76. package/symbols/dpst_normally_closed_switch_right.ts +0 -11
  77. package/symbols/dpst_normally_closed_switch_up.ts +0 -22
  78. package/symbols/dpst_switch_down.ts +0 -21
  79. package/symbols/dpst_switch_left.ts +0 -23
  80. package/symbols/dpst_switch_right.ts +0 -11
  81. package/symbols/dpst_switch_up.ts +0 -22
  82. package/symbols/filled_diode_horz.ts +0 -9
  83. package/symbols/filled_diode_vert.ts +0 -4
  84. package/symbols/frequency_meter_horz.ts +0 -32
  85. package/symbols/frequency_meter_vert.ts +0 -19
  86. package/symbols/fuse_horz.ts +0 -24
  87. package/symbols/fuse_vert.ts +0 -4
  88. package/symbols/ground_horz.ts +0 -37
  89. package/symbols/ground_vert.ts +0 -4
  90. package/symbols/gunn_diode_horz.ts +0 -11
  91. package/symbols/gunn_diode_vert.ts +0 -11
  92. package/symbols/icled_down.ts +0 -4
  93. package/symbols/icled_left.ts +0 -4
  94. package/symbols/icled_right.ts +0 -11
  95. package/symbols/icled_up.ts +0 -27
  96. package/symbols/igbt_transistor_horz.ts +0 -10
  97. package/symbols/igbt_transistor_vert.ts +0 -21
  98. package/symbols/illuminated_push_button_normally_open_horz.ts +0 -9
  99. package/symbols/illuminated_push_button_normally_open_vert.ts +0 -20
  100. package/symbols/inductor_down.ts +0 -4
  101. package/symbols/inductor_left.ts +0 -4
  102. package/symbols/inductor_right.ts +0 -20
  103. package/symbols/inductor_up.ts +0 -4
  104. package/symbols/laser_diode_horz.ts +0 -10
  105. package/symbols/laser_diode_vert.ts +0 -13
  106. package/symbols/led_down.ts +0 -4
  107. package/symbols/led_left.ts +0 -4
  108. package/symbols/led_right.ts +0 -20
  109. package/symbols/led_up.ts +0 -27
  110. package/symbols/light_dependent_resistor_horz.ts +0 -20
  111. package/symbols/light_dependent_resistor_vert.ts +0 -20
  112. package/symbols/mosfet_depletion_normally_on_horz.ts +0 -19
  113. package/symbols/mosfet_depletion_normally_on_vert.ts +0 -21
  114. package/symbols/mushroom_head_normally_open_momentary_horz.ts +0 -20
  115. package/symbols/mushroom_head_normally_open_momentary_vert.ts +0 -23
  116. package/symbols/n_channel_d_mosfet_transistor_horz.ts +0 -20
  117. package/symbols/n_channel_d_mosfet_transistor_vert.ts +0 -20
  118. package/symbols/n_channel_e_mosfet_transistor_horz.ts +0 -21
  119. package/symbols/n_channel_e_mosfet_transistor_vert.ts +0 -20
  120. package/symbols/njfet_transistor_horz.ts +0 -20
  121. package/symbols/njfet_transistor_vert.ts +0 -20
  122. package/symbols/npn_bipolar_transistor_horz.ts +0 -11
  123. package/symbols/npn_bipolar_transistor_vert.ts +0 -21
  124. package/symbols/opamp_no_power_down.ts +0 -4
  125. package/symbols/opamp_no_power_left.ts +0 -4
  126. package/symbols/opamp_no_power_right.ts +0 -10
  127. package/symbols/opamp_no_power_up.ts +0 -4
  128. package/symbols/opamp_with_power_down.ts +0 -4
  129. package/symbols/opamp_with_power_left.ts +0 -4
  130. package/symbols/opamp_with_power_right.ts +0 -12
  131. package/symbols/opamp_with_power_up.ts +0 -4
  132. package/symbols/p_channel_d_mosfet_transistor_horz.ts +0 -20
  133. package/symbols/p_channel_d_mosfet_transistor_vert.ts +0 -20
  134. package/symbols/p_channel_e_mosfet_transistor_horz.ts +0 -20
  135. package/symbols/p_channel_e_mosfet_transistor_vert.ts +0 -20
  136. package/symbols/photodiode_horz.ts +0 -9
  137. package/symbols/photodiode_vert.ts +0 -13
  138. package/symbols/pjfet_transistor_horz.ts +0 -20
  139. package/symbols/pjfet_transistor_vert.ts +0 -20
  140. package/symbols/pnp_bipolar_transistor_horz.ts +0 -10
  141. package/symbols/pnp_bipolar_transistor_vert.ts +0 -20
  142. package/symbols/potentiometer2_horz.ts +0 -18
  143. package/symbols/potentiometer2_vert.ts +0 -14
  144. package/symbols/potentiometer3_down.ts +0 -4
  145. package/symbols/potentiometer3_left.ts +0 -4
  146. package/symbols/potentiometer3_right.ts +0 -10
  147. package/symbols/potentiometer3_up.ts +0 -4
  148. package/symbols/potentiometer_horz.ts +0 -18
  149. package/symbols/potentiometer_vert.ts +0 -6
  150. package/symbols/power_factor_meter_horz.ts +0 -42
  151. package/symbols/power_factor_meter_vert.ts +0 -19
  152. package/symbols/push_button_normally_closed_momentary_horz.ts +0 -20
  153. package/symbols/push_button_normally_closed_momentary_vert.ts +0 -4
  154. package/symbols/push_button_normally_open_momentary_horz.ts +0 -20
  155. package/symbols/push_button_normally_open_momentary_vert.ts +0 -4
  156. package/symbols/rectifier_diode_horz.ts +0 -21
  157. package/symbols/rectifier_diode_vert.ts +0 -17
  158. package/symbols/resonator_horz.ts +0 -34
  159. package/symbols/resonator_vert.ts +0 -4
  160. package/symbols/schottky_diode_horz.ts +0 -10
  161. package/symbols/schottky_diode_vert.ts +0 -18
  162. package/symbols/silicon_controlled_rectifier_horz.ts +0 -13
  163. package/symbols/silicon_controlled_rectifier_vert.ts +0 -15
  164. package/symbols/spdt_normally_closed_switch_down.ts +0 -22
  165. package/symbols/spdt_normally_closed_switch_left.ts +0 -22
  166. package/symbols/spdt_normally_closed_switch_right.ts +0 -10
  167. package/symbols/spdt_normally_closed_switch_up.ts +0 -22
  168. package/symbols/spst_normally_closed_switch_down.ts +0 -22
  169. package/symbols/spst_normally_closed_switch_left.ts +0 -22
  170. package/symbols/spst_normally_closed_switch_right.ts +0 -12
  171. package/symbols/spst_normally_closed_switch_up.ts +0 -22
  172. package/symbols/step_recovery_diode_horz.ts +0 -11
  173. package/symbols/step_recovery_diode_vert.ts +0 -4
  174. package/symbols/tachometer_horz.ts +0 -32
  175. package/symbols/tachometer_vert.ts +0 -19
  176. package/symbols/triac_horz.ts +0 -13
  177. package/symbols/triac_vert.ts +0 -16
  178. package/symbols/tunnel_diode_horz.ts +0 -19
  179. package/symbols/tunnel_diode_vert.ts +0 -18
  180. package/symbols/unijunction_transistor_horz.ts +0 -20
  181. package/symbols/unijunction_transistor_vert.ts +0 -19
  182. package/symbols/var_meter_horz.ts +0 -30
  183. package/symbols/var_meter_vert.ts +0 -4
  184. package/symbols/varactor_diode_horz.ts +0 -19
  185. package/symbols/varactor_diode_vert.ts +0 -18
  186. package/symbols/varistor_horz.ts +0 -24
  187. package/symbols/varistor_vert.ts +0 -4
  188. package/symbols/varmeter_horz.ts +0 -32
  189. package/symbols/varmeter_vert.ts +0 -19
  190. package/symbols/volt_meter_horz.ts +0 -10
  191. package/symbols/volt_meter_vert.ts +0 -4
  192. package/symbols/watt_hour_meter_horz.ts +0 -32
  193. package/symbols/watt_hour_meter_vert.ts +0 -19
  194. package/symbols/wattmeter_horz.ts +0 -32
  195. package/symbols/wattmeter_vert.ts +0 -19
  196. package/symbols/zener_diode_horz.ts +0 -19
  197. package/symbols/zener_diode_vert.ts +0 -17
@@ -1,324 +0,0 @@
1
- import { rotate, applyToPoint, transform, scale } from "transformation-matrix"
2
- import type {
3
- SchSymbol,
4
- Primitive,
5
- Point,
6
- Port,
7
- NinePointAnchor,
8
- } from "./types"
9
- import { getBoundsOfPrimitives } from "./utils/getBoundsOfPrimitives"
10
-
11
- // Update rotateAnchor to handle all anchor rotations based on orientation
12
- const rotateRightFacingAnchor = (
13
- anchor: NinePointAnchor,
14
- newOrientation: "up" | "down" | "left" | "right" = "right",
15
- ): NinePointAnchor => {
16
- switch (newOrientation) {
17
- case "down":
18
- switch (anchor) {
19
- case "middle_top":
20
- return "middle_right"
21
- case "middle_bottom":
22
- return "middle_left"
23
- case "middle_left":
24
- return "middle_bottom"
25
- case "middle_right":
26
- return "middle_top"
27
- }
28
- break
29
- case "up":
30
- switch (anchor) {
31
- case "middle_top":
32
- return "middle_left"
33
- case "middle_bottom":
34
- return "middle_right"
35
- case "middle_left":
36
- return "middle_top"
37
- case "middle_right":
38
- return "middle_bottom"
39
- }
40
- break
41
- case "left":
42
- switch (anchor) {
43
- case "middle_top":
44
- return "middle_bottom"
45
- case "middle_bottom":
46
- return "middle_top"
47
- case "middle_left":
48
- return "middle_right"
49
- case "middle_right":
50
- return "middle_left"
51
- }
52
- break
53
- case "right":
54
- return anchor // No change if orientation is "right"
55
- }
56
- return anchor
57
- }
58
-
59
- export const flipSymbolOverXAxis = (
60
- symbol: SchSymbol,
61
- overrides?: Partial<SchSymbol>,
62
- ): SchSymbol => {
63
- const { primitives, center, ports, size } = symbol
64
- const transformMatrix = transform({
65
- a: 1,
66
- b: 0,
67
- c: 0,
68
- d: -1,
69
- e: 0,
70
- f: 2 * center.y,
71
- })
72
-
73
- const flippedPrimitives = primitives.map((primitive): Primitive => {
74
- primitive = { ...primitive }
75
- switch (primitive.type) {
76
- case "path":
77
- return {
78
- ...primitive,
79
- points: primitive.points.map(
80
- (point) => applyToPoint(transformMatrix, point) as Point,
81
- ),
82
- }
83
- case "text":
84
- const flippedPoint = applyToPoint(transformMatrix, {
85
- x: primitive.x,
86
- y: primitive.y,
87
- }) as Point
88
-
89
- // Flip text anchors vertically
90
- const anchorMap: Record<NinePointAnchor, NinePointAnchor> = {
91
- top_left: "bottom_left",
92
- top_right: "bottom_right",
93
- bottom_left: "top_left",
94
- bottom_right: "top_right",
95
- center: "center",
96
- middle_top: "middle_bottom",
97
- middle_bottom: "middle_top",
98
- middle_left: "middle_left",
99
- middle_right: "middle_right",
100
- }
101
-
102
- return {
103
- ...primitive,
104
- x: flippedPoint.x,
105
- y: flippedPoint.y,
106
- anchor: anchorMap[primitive.anchor],
107
- }
108
- case "circle":
109
- case "box":
110
- const flippedCenter = applyToPoint(transformMatrix, {
111
- x: primitive.x,
112
- y: primitive.y,
113
- }) as Point
114
- return {
115
- ...primitive,
116
- x: flippedCenter.x,
117
- y: flippedCenter.y,
118
- }
119
- }
120
- })
121
-
122
- const flippedPorts = ports.map(
123
- (port): Port => ({
124
- ...port,
125
- ...(applyToPoint(transformMatrix, port) as Point),
126
- }),
127
- )
128
-
129
- return {
130
- primitives: flippedPrimitives,
131
- center,
132
- ports: flippedPorts,
133
- size,
134
- ...overrides,
135
- }
136
- }
137
-
138
- export const flipSymbolOverYAxis = (
139
- symbol: SchSymbol,
140
- overrides?: Partial<SchSymbol>,
141
- ): SchSymbol => {
142
- const { primitives, center, ports, size } = symbol
143
- const transformMatrix = transform({
144
- a: -1,
145
- b: 0,
146
- c: 0,
147
- d: 1,
148
- e: 0,
149
- f: 2 * center.x,
150
- })
151
-
152
- const flippedPrimitives = primitives.map((primitive): Primitive => {
153
- primitive = { ...primitive }
154
- switch (primitive.type) {
155
- case "path":
156
- return {
157
- ...primitive,
158
- points: primitive.points.map(
159
- (point) => applyToPoint(transformMatrix, point) as Point,
160
- ),
161
- }
162
- case "text":
163
- const flippedPoint = applyToPoint(transformMatrix, {
164
- x: primitive.x,
165
- y: primitive.y,
166
- }) as Point
167
-
168
- // Flip text anchors horizontally
169
- const anchorMap: Record<NinePointAnchor, NinePointAnchor> = {
170
- top_left: "top_right",
171
- top_right: "top_left",
172
- bottom_left: "bottom_right",
173
- bottom_right: "bottom_left",
174
- center: "center",
175
- middle_top: "middle_top",
176
- middle_bottom: "middle_bottom",
177
- middle_left: "middle_right",
178
- middle_right: "middle_left",
179
- }
180
-
181
- return {
182
- ...primitive,
183
- x: flippedPoint.x,
184
- y: flippedPoint.y,
185
- anchor: anchorMap[primitive.anchor],
186
- }
187
- case "circle":
188
- case "box":
189
- const flippedCenter = applyToPoint(transformMatrix, {
190
- x: primitive.x,
191
- y: primitive.y,
192
- }) as Point
193
- return {
194
- ...primitive,
195
- x: flippedCenter.x,
196
- y: flippedCenter.y,
197
- }
198
- }
199
- })
200
-
201
- const flippedPorts = ports.map(
202
- (port): Port => ({
203
- ...port,
204
- ...(applyToPoint(transformMatrix, port) as Point),
205
- }),
206
- )
207
-
208
- return {
209
- primitives: flippedPrimitives,
210
- center,
211
- ports: flippedPorts,
212
- size,
213
- ...overrides,
214
- }
215
- }
216
-
217
- export const rotateRightFacingSymbol = (
218
- symbol: SchSymbol,
219
- opts: {
220
- newOrientation?: "up" | "down" | "left" | "right"
221
- overrides?: Partial<SchSymbol>
222
- },
223
- ): SchSymbol => {
224
- const { newOrientation, overrides } = opts
225
- // Assuming the default orientation is "right"
226
- const angleMap = {
227
- up: Math.PI / 2,
228
- right: 0,
229
- down: -Math.PI / 2,
230
- left: -Math.PI,
231
- }
232
-
233
- const transform = rotate(
234
- newOrientation ? angleMap[newOrientation] : Math.PI / 2,
235
- symbol.center.x,
236
- symbol.center.y,
237
- )
238
-
239
- const { primitives, center, size, ports } = symbol
240
-
241
- const rotatedPrimitives = primitives.map((primitive): Primitive => {
242
- primitive = { ...primitive }
243
- switch (primitive.type) {
244
- case "path":
245
- return {
246
- ...primitive,
247
- points: primitive.points.map(
248
- (point) => applyToPoint(transform, point) as Point,
249
- ),
250
- }
251
- case "text":
252
- const rotatedPoint = applyToPoint(transform, {
253
- x: primitive.x,
254
- y: primitive.y,
255
- }) as Point
256
-
257
- primitive.anchor = rotateRightFacingAnchor(
258
- primitive.anchor,
259
- newOrientation ?? "right",
260
- )
261
-
262
- return {
263
- ...primitive,
264
- x: rotatedPoint.x,
265
- y: rotatedPoint.y,
266
- }
267
- case "circle":
268
- const rotatedCenter = applyToPoint(transform, {
269
- x: primitive.x,
270
- y: primitive.y,
271
- }) as Point
272
- return {
273
- ...primitive,
274
- x: rotatedCenter.x,
275
- y: rotatedCenter.y,
276
- }
277
- case "box":
278
- const rotatedCorner = applyToPoint(transform, {
279
- x: primitive.x,
280
- y: primitive.y,
281
- }) as Point
282
- return {
283
- ...primitive,
284
- x: rotatedCorner.x,
285
- y: rotatedCorner.y,
286
- width: primitive.height,
287
- height: primitive.width,
288
- }
289
- }
290
- })
291
-
292
- const rotatedPorts = ports.map(
293
- (port): Port => ({
294
- ...port,
295
- ...(applyToPoint(transform, port) as Point),
296
- }),
297
- )
298
-
299
- const bounds = getBoundsOfPrimitives(rotatedPrimitives)
300
-
301
- return {
302
- primitives: rotatedPrimitives,
303
- center,
304
- ports: rotatedPorts,
305
- size: {
306
- width: bounds.maxX - bounds.minX,
307
- height: bounds.maxY - bounds.minY,
308
- },
309
- ...overrides,
310
- }
311
- }
312
-
313
- /**
314
- * @deprecated use rotateRightFacingSymbol instead
315
- */
316
- export const rotateSymbol = (
317
- symbol: SchSymbol,
318
- orientation: "up" | "down" | "left" | "right" = "down",
319
- overrides: Partial<SchSymbol> = {},
320
- ): SchSymbol =>
321
- rotateRightFacingSymbol(symbol, {
322
- newOrientation: orientation,
323
- overrides,
324
- })
@@ -1,109 +0,0 @@
1
- import type { Point } from "./types"
2
- import { approximateArc } from "./arc"
3
- import { approximateBezier } from "./cubicBezierCurveArc"
4
-
5
- export function svgPathToPoints(pathString: string): Point[] {
6
- const points: Point[] = []
7
- const commands =
8
- pathString.match(/[MmLlHhVvCcSsQqTtAaZz][^MmLlHhVvCcSsQqTtAaZz]*/g) || []
9
- let currentX = 0
10
- let currentY = 0
11
-
12
- function addPoint(x: number, y: number) {
13
- points.push({ x, y })
14
- currentX = x
15
- currentY = y
16
- }
17
-
18
- for (const command of commands) {
19
- const type = command[0]
20
- const args = command
21
- .slice(1)
22
- .trim()
23
- .split(/[\s,]+/)
24
- .map(Number.parseFloat)
25
-
26
- switch (type.toUpperCase()) {
27
- case "M":
28
- addPoint(args[0], args[1])
29
- break
30
- case "L":
31
- addPoint(args[0], args[1])
32
- break
33
- case "H":
34
- addPoint(args[0], currentY)
35
- break
36
- case "V":
37
- addPoint(currentX, args[0])
38
- break
39
- case "C": {
40
- const [x1, y1, x2, y2, x, y] = args
41
-
42
- // Approximate the cubic Bézier curve
43
- const bezierPoints = approximateBezier(
44
- { x: currentX, y: currentY }, // Start point
45
- { x: x1, y: y1 }, // Control point 1
46
- { x: x2, y: y2 }, // Control point 2
47
- { x, y }, // End point
48
- )
49
-
50
- points.push(...bezierPoints)
51
- addPoint(x, y) // Update the current position
52
- break
53
- }
54
- case "Q":
55
- // For Q command, we add both the control point and the end point
56
- points.push({ x: args[0], y: args[1] }) // Control point
57
- addPoint(args[2], args[3]) // End point
58
- break
59
- case "Z":
60
- // Close path - no new point
61
- break
62
- case "A":
63
- // For A command, we add the end point and intermediate points to approximate the arc
64
- const [rx, ry, xAxisRotation, largeArcFlag, sweepFlag, x, y] = args
65
- const arcPoints = approximateArc(
66
- currentX,
67
- currentY,
68
- rx,
69
- ry,
70
- largeArcFlag,
71
- sweepFlag,
72
- x,
73
- y,
74
- )
75
- arcPoints.forEach((point) => points.push(point))
76
- addPoint(x, y)
77
- break
78
- // Add cases for other commands (S, T) if needed
79
- default:
80
- console.warn(`Unsupported SVG command: ${type}`)
81
- }
82
-
83
- // Handle relative commands
84
- if (type === type.toLowerCase() && type !== "z" && type !== "a") {
85
- if (type === "c") {
86
- // For relative c, adjust both control points and end point
87
- points[points.length - 3].x += currentX
88
- points[points.length - 3].y += currentY
89
- points[points.length - 2].x += currentX
90
- points[points.length - 2].y += currentY
91
- points[points.length - 1].x += currentX
92
- points[points.length - 1].y += currentY
93
- } else if (type === "q") {
94
- // For relative q, adjust both control point and end point
95
- points[points.length - 2].x += currentX
96
- points[points.length - 2].y += currentY
97
- points[points.length - 1].x += currentX
98
- points[points.length - 1].y += currentY
99
- } else {
100
- points[points.length - 1].x += currentX
101
- points[points.length - 1].y += currentY
102
- }
103
- currentX = points[points.length - 1].x
104
- currentY = points[points.length - 1].y
105
- }
106
- }
107
-
108
- return points
109
- }
package/drawing/text.ts DELETED
@@ -1,8 +0,0 @@
1
- import type { TextPrimitive } from "drawing"
2
-
3
- export function text(
4
- text: string,
5
- options: Omit<TextPrimitive, "type" | "text">,
6
- ): TextPrimitive {
7
- return { type: "text", text, ...options }
8
- }
@@ -1,155 +0,0 @@
1
- import {
2
- PathPrimitive,
3
- TextPrimitive,
4
- CirclePrimitive,
5
- BoxPrimitive,
6
- Primitive,
7
- NinePointAnchor,
8
- Point,
9
- SchSymbol,
10
- Port,
11
- SvgData,
12
- Bounds,
13
- } from "./types"
14
-
15
- // Basic types
16
- function isPoint(value: any): value is Point {
17
- return (
18
- typeof value === "object" &&
19
- value !== null &&
20
- typeof value.x === "number" &&
21
- typeof value.y === "number"
22
- )
23
- }
24
-
25
- export function isNinePointAnchor(value: any): value is NinePointAnchor {
26
- return [
27
- "top_left",
28
- "top_right",
29
- "bottom_left",
30
- "bottom_right",
31
- "center",
32
- "middle_top",
33
- "middle_bottom",
34
- "middle_left",
35
- "middle_right",
36
- ].includes(value)
37
- }
38
-
39
- // Primitive types
40
- export function isPathPrimitive(value: any): value is PathPrimitive {
41
- return (
42
- typeof value === "object" &&
43
- value !== null &&
44
- value.type === "path" &&
45
- Array.isArray(value.points) &&
46
- value.points.every(isPoint) &&
47
- typeof value.color === "string"
48
- )
49
- }
50
-
51
- export function isTextPrimitive(value: any): value is TextPrimitive {
52
- return (
53
- typeof value === "object" &&
54
- value !== null &&
55
- value.type === "text" &&
56
- typeof value.text === "string" &&
57
- typeof value.x === "number" &&
58
- typeof value.y === "number" &&
59
- isNinePointAnchor(value.anchor)
60
- )
61
- }
62
-
63
- export function isCirclePrimitive(value: any): value is CirclePrimitive {
64
- return (
65
- typeof value === "object" &&
66
- value !== null &&
67
- value.type === "circle" &&
68
- typeof value.x === "number" &&
69
- typeof value.y === "number" &&
70
- typeof value.radius === "number" &&
71
- typeof value.fill === "boolean" &&
72
- typeof value.color === "string"
73
- )
74
- }
75
-
76
- export function isBoxPrimitive(value: any): value is BoxPrimitive {
77
- return (
78
- typeof value === "object" &&
79
- value !== null &&
80
- value.type === "box" &&
81
- typeof value.x === "number" &&
82
- typeof value.y === "number" &&
83
- typeof value.width === "number" &&
84
- typeof value.height === "number" &&
85
- isNinePointAnchor(value.anchor)
86
- )
87
- }
88
-
89
- export function isPrimitive(value: any): value is Primitive {
90
- return (
91
- isPathPrimitive(value) ||
92
- isTextPrimitive(value) ||
93
- isCirclePrimitive(value) ||
94
- isBoxPrimitive(value)
95
- )
96
- }
97
-
98
- // Complex types
99
- export function isPort(value: any): value is Port {
100
- return (
101
- typeof value === "object" &&
102
- value !== null &&
103
- typeof value.x === "number" &&
104
- typeof value.y === "number" &&
105
- Array.isArray(value.labels) &&
106
- value.labels.every((label: any) => typeof label === "string")
107
- )
108
- }
109
-
110
- export function isSchSymbol(value: any): value is SchSymbol {
111
- return (
112
- typeof value === "object" &&
113
- value !== null &&
114
- Array.isArray(value.primitives) &&
115
- value.primitives.every(isPrimitive) &&
116
- isPoint(value.center) &&
117
- Array.isArray(value.ports) &&
118
- value.ports.every(isPort) &&
119
- typeof value.size === "object" &&
120
- value.size !== null &&
121
- typeof value.size.width === "number" &&
122
- typeof value.size.height === "number"
123
- )
124
- }
125
-
126
- export function isBounds(value: any): value is Bounds {
127
- return (
128
- typeof value === "object" &&
129
- value !== null &&
130
- typeof value.minX === "number" &&
131
- typeof value.maxX === "number" &&
132
- typeof value.minY === "number" &&
133
- typeof value.maxY === "number" &&
134
- typeof value.width === "number" &&
135
- typeof value.height === "number" &&
136
- typeof value.centerX === "number" &&
137
- typeof value.centerY === "number"
138
- )
139
- }
140
-
141
- export function isSvgData(value: any): value is SvgData {
142
- return (
143
- typeof value === "object" &&
144
- value !== null &&
145
- typeof value.paths === "object" &&
146
- Object.values(value.paths).every(isPathPrimitive) &&
147
- typeof value.texts === "object" &&
148
- Object.values(value.texts).every(isTextPrimitive) &&
149
- typeof value.refblocks === "object" &&
150
- Object.values(value.refblocks).every(isPoint) &&
151
- isBounds(value.bounds) &&
152
- typeof value.circles === "object" &&
153
- Object.values(value.circles).every(isCirclePrimitive)
154
- )
155
- }
package/drawing/types.ts DELETED
@@ -1,93 +0,0 @@
1
- export interface Point {
2
- x: number
3
- y: number
4
- }
5
-
6
- export interface Port {
7
- x: number
8
- y: number
9
- labels: string[]
10
- }
11
-
12
- export interface PathPrimitive {
13
- type: "path"
14
- fill?: boolean
15
- points: Point[]
16
- color: string
17
- closed?: boolean
18
- }
19
-
20
- export interface TextPrimitive {
21
- type: "text"
22
- text: string
23
- fontSize?: number
24
- x: number
25
- y: number
26
- anchor: NinePointAnchor
27
- }
28
-
29
- export interface CirclePrimitive {
30
- type: "circle"
31
- x: number
32
- y: number
33
- radius: number
34
- fill: boolean
35
- color: string
36
- }
37
-
38
- export interface BoxPrimitive {
39
- type: "box"
40
- x: number
41
- y: number
42
- width: number
43
- height: number
44
- anchor: string
45
- }
46
-
47
- export type Primitive =
48
- | PathPrimitive
49
- | TextPrimitive
50
- | CirclePrimitive
51
- | BoxPrimitive
52
-
53
- export interface SchSymbol {
54
- primitives: Primitive[]
55
- center: Point
56
- ports: Port[]
57
- size: {
58
- width: number
59
- height: number
60
- }
61
- }
62
-
63
- export type Bounds = {
64
- minX: number
65
- maxX: number
66
- minY: number
67
- maxY: number
68
- width: number
69
- height: number
70
- centerX: number
71
- centerY: number
72
- }
73
-
74
- export interface SvgData {
75
- paths: Record<string, PathPrimitive>
76
- texts: Record<string, TextPrimitive>
77
- refblocks: Record<string, Point>
78
- bounds: Bounds
79
- circles: Record<string, CirclePrimitive>
80
- }
81
-
82
- export type SvgAnchor = "start" | "middle" | "end"
83
-
84
- export type NinePointAnchor =
85
- | "top_left"
86
- | "top_right"
87
- | "bottom_left"
88
- | "bottom_right"
89
- | "center"
90
- | "middle_top"
91
- | "middle_bottom"
92
- | "middle_left"
93
- | "middle_right"