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
package/package.json CHANGED
@@ -1,13 +1,10 @@
1
1
  {
2
2
  "name": "schematic-symbols",
3
3
  "main": "./dist/index.js",
4
- "version": "0.0.121",
4
+ "version": "0.0.123",
5
5
  "type": "module",
6
6
  "files": [
7
- "dist",
8
- "index.ts",
9
- "drawing",
10
- "symbols"
7
+ "dist"
11
8
  ],
12
9
  "scripts": {
13
10
  "start": "bun run build && bun --hot run dev-server.ts",
package/drawing/arc.ts DELETED
@@ -1,31 +0,0 @@
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
- sweepFlag: number,
10
- x2: number,
11
- y2: number,
12
- ): Point[] {
13
- // This is a simplified approximation. For a more accurate representation,
14
- // you might want to use a dedicated SVG path library.
15
- const steps = 40
16
- const points: Point[] = []
17
- for (let i = 1; i < steps; i++) {
18
- const t = i / steps
19
- const x = (1 - t) * x1 + t * x2
20
- const y = (1 - t) * y1 + t * y2
21
- // Apply a simple curve to make it non-linear, with reduced height and no center drop
22
- const curveY =
23
- 0.03 *
24
- Math.abs(Math.sin(t * Math.PI)) *
25
- Math.min(rx, ry) *
26
- (largeArcFlag ? 1 : -1) *
27
- (sweepFlag ? -1 : 1)
28
- points.push({ x, y: y + curveY })
29
- }
30
- return points
31
- }
package/drawing/arrow.ts DELETED
@@ -1,41 +0,0 @@
1
- import { Point, Primitive } from "drawing"
2
- import { path } from "./path"
3
-
4
- export const arrow = (
5
- start: Point,
6
- end: Point,
7
- color: string = "black",
8
- headSize: number = 10,
9
- ): Primitive[] => {
10
- // Calculate the angle and length of the arrow
11
- const dx = end.x - start.x
12
- const dy = end.y - start.y
13
- const angle = Math.atan2(dy, dx)
14
- const length = Math.sqrt(dx * dx + dy * dy)
15
-
16
- // Calculate the points for the arrow head
17
- const headAngle = Math.PI / 6 // 30 degrees
18
- const headPoint1 = {
19
- x: end.x - headSize * Math.cos(angle - headAngle),
20
- y: end.y - headSize * Math.sin(angle - headAngle),
21
- }
22
- const headPoint2 = {
23
- x: end.x - headSize * Math.cos(angle + headAngle),
24
- y: end.y - headSize * Math.sin(angle + headAngle),
25
- }
26
-
27
- return [
28
- // Arrow body
29
- path({
30
- points: [start, end],
31
- color: color,
32
- fill: false,
33
- }),
34
- // Arrow head
35
- path({
36
- points: [headPoint1, end, headPoint2],
37
- color: color,
38
- fill: true,
39
- }),
40
- ]
41
- }
package/drawing/box.ts DELETED
@@ -1,5 +0,0 @@
1
- import type { BoxPrimitive } from "drawing"
2
-
3
- export function box(options: Omit<BoxPrimitive, "type">): BoxPrimitive {
4
- return { type: "box", ...options }
5
- }
package/drawing/circle.ts DELETED
@@ -1,7 +0,0 @@
1
- import type { CirclePrimitive } from "drawing"
2
-
3
- export function circle(
4
- options: Omit<CirclePrimitive, "type">,
5
- ): CirclePrimitive {
6
- return { type: "circle", ...options }
7
- }
@@ -1,28 +0,0 @@
1
- import type { Point } from "./types"
2
-
3
- export function approximateBezier(
4
- p0: Point,
5
- p1: Point,
6
- p2: Point,
7
- p3: Point,
8
- ): Point[] {
9
- const points: Point[] = []
10
- const steps = 30
11
- for (let t = 0; t <= 1; t += 1 / steps) {
12
- const x =
13
- Math.pow(1 - t, 3) * p0.x +
14
- 3 * Math.pow(1 - t, 2) * t * p1.x +
15
- 3 * (1 - t) * Math.pow(t, 2) * p2.x +
16
- Math.pow(t, 3) * p3.x
17
-
18
- const y =
19
- Math.pow(1 - t, 3) * p0.y +
20
- 3 * Math.pow(1 - t, 2) * t * p1.y +
21
- 3 * (1 - t) * Math.pow(t, 2) * p2.y +
22
- Math.pow(t, 3) * p3.y
23
-
24
- points.push({ x, y })
25
- }
26
-
27
- return points
28
- }
@@ -1,16 +0,0 @@
1
- import type { SchSymbol } from "./types"
2
- import { getBoundsOfPrimitives } from "./utils/getBoundsOfPrimitives"
3
-
4
- export function defineSymbol(
5
- symbol: Omit<SchSymbol, "size"> & Partial<Pick<SchSymbol, "size">>,
6
- ): SchSymbol {
7
- let size = symbol.size
8
- if (!size) {
9
- const bounds = getBoundsOfPrimitives(symbol.primitives)
10
- size = {
11
- width: bounds.maxX - bounds.minX,
12
- height: bounds.maxY - bounds.minY,
13
- }
14
- }
15
- return { ...symbol, size }
16
- }
package/drawing/getSvg.ts DELETED
@@ -1,199 +0,0 @@
1
- import { makeAnchorYUpPositive, makeYUpPositive } from "./utils/makeYUpPositive"
2
- import { mapColor } from "./mapColor"
3
- import { pathToSvgD } from "./pathToSvgD"
4
- import type { Point, Port, SchSymbol, TextPrimitive } from "./types"
5
-
6
- function createDiamondElement(
7
- center: Point,
8
- size = 0.05,
9
- yUpPositive: boolean = true,
10
- ): string {
11
- const { x, y } = center
12
- const halfSize = size / 2
13
- return `<path d="M ${x} ${makeYUpPositive(y, yUpPositive) - halfSize} L ${x + halfSize} ${makeYUpPositive(y, yUpPositive)} L ${x} ${
14
- makeYUpPositive(y, yUpPositive) + halfSize
15
- } L ${x - halfSize} ${makeYUpPositive(y, yUpPositive)} Z" fill="green" />`
16
- }
17
-
18
- function createTextElement(
19
- primitive: TextPrimitive,
20
- { yUpPositive }: { yUpPositive?: boolean },
21
- ): {
22
- text: string
23
- anchor: string
24
- } {
25
- const { x, y, text, fontSize = 0.1, anchor } = primitive
26
- let textAnchor: string
27
- const dx = 0
28
- let dy = 0
29
-
30
- const capHeight = fontSize * 0.75
31
-
32
- switch (anchor) {
33
- case "top_left":
34
- textAnchor = "start"
35
- dy = fontSize
36
- break
37
- case "top_right":
38
- textAnchor = "end"
39
- dy = fontSize
40
- break
41
- case "bottom_left":
42
- textAnchor = "start"
43
- break
44
- case "bottom_right":
45
- textAnchor = "end"
46
- break
47
- case "center":
48
- textAnchor = "middle"
49
- dy = fontSize / 2
50
- break
51
- case "middle_top":
52
- textAnchor = "middle"
53
- dy = capHeight
54
- break
55
- case "middle_bottom":
56
- textAnchor = "middle"
57
- break
58
- case "middle_left":
59
- textAnchor = "start"
60
- dy = capHeight / 2
61
- break
62
- case "middle_right":
63
- textAnchor = "end"
64
- dy = capHeight / 2
65
- break
66
- }
67
-
68
- return {
69
- text: `<text x="${x}" y="${makeYUpPositive(y, yUpPositive)}" dx="${dx}" dy="${dy}" text-anchor="${textAnchor}" style="font: ${
70
- fontSize ?? 0.1
71
- }px monospace; fill: ${mapColor("primary")}">${text}</text>`,
72
- anchor: `<rect x="${x - 0.025 / 2}" y="${
73
- makeYUpPositive(y, yUpPositive) - 0.025 / 2
74
- }" width="0.025" height="0.025" fill="blue" />`,
75
- }
76
- }
77
-
78
- function createPortElement(
79
- port: Port,
80
- { yUpPositive }: { yUpPositive?: boolean },
81
- ): string {
82
- const { x, y, labels } = port
83
- const rectSize = 0.05
84
- const labelFontSize = 0.08
85
- const label = labels[0] || ""
86
-
87
- return `
88
- <rect x="${x - rectSize / 2}" y="${
89
- makeYUpPositive(y, yUpPositive) - rectSize / 2
90
- }" width="${rectSize}" height="${rectSize}" fill="red" />
91
- <text x="${x - labelFontSize / 2}" y="${
92
- makeYUpPositive(y, yUpPositive) + rectSize + labelFontSize / 2
93
- }" text-anchor="middle" style="font: ${labelFontSize}px monospace; fill: #833;">${label}</text>
94
- `
95
- }
96
-
97
- export function getInnerSvg(
98
- symbol: SchSymbol,
99
- options: { width?: number; height?: number; debug?: boolean } = {},
100
- ): string {
101
- const { debug = false } = options
102
- const { primitives, size, ports } = symbol
103
- const svgElements = primitives.map((primitive) => {
104
- switch (primitive.type) {
105
- case "path":
106
- return `<path d="${pathToSvgD(primitive.points, {
107
- closed: primitive.closed,
108
- yUpPositive: true,
109
- })}" fill="${
110
- primitive.fill ? mapColor(primitive.color) : "none"
111
- }" stroke="${mapColor(
112
- primitive.color,
113
- )}" stroke-width="0.02" stroke-linecap="round" stroke-linejoin="round" />`
114
- case "text":
115
- const textElements = createTextElement(primitive, { yUpPositive: true })
116
- return textElements.text + (debug ? textElements.anchor : "")
117
- case "circle":
118
- return `<circle cx="${primitive.x}" cy="${makeYUpPositive(primitive.y, true)}" r="${
119
- primitive.radius
120
- }" fill="${primitive.fill ? mapColor(primitive.color) : "none"}" ${
121
- !primitive.fill
122
- ? `stroke="${mapColor(primitive.color)}" stroke-width="0.02"`
123
- : ""
124
- } />`
125
- case "box":
126
- return `<rect x="${primitive.x}" y="${makeYUpPositive(primitive.y)}" width="${
127
- primitive.width
128
- }" height="${primitive.height}" fill="${mapColor("primary")}" />`
129
- default:
130
- return ""
131
- }
132
- })
133
-
134
- const portElements = ports
135
- .map((p) => createPortElement(p, { yUpPositive: true }))
136
- .join("\n ")
137
-
138
- const centerDiamond = createDiamondElement(symbol.center)
139
-
140
- const debugElements = []
141
- if (debug) {
142
- const topLeft = {
143
- x: symbol.center.x - size.width / 2,
144
- y: symbol.center.y - size.height / 2,
145
- }
146
- debugElements.push(
147
- `<text x="${topLeft.x}" y="${topLeft.y}" style="font: 0.05px monospace; fill: #833;">${size.width.toFixed(2)} x ${size.height.toFixed(2)}</text>`,
148
- )
149
-
150
- // Show all available port labels
151
- ports.forEach((port, i) => {
152
- if (port.labels.length > 1) {
153
- const alternateLabels = port.labels.slice(1).join(", ")
154
- debugElements.push(
155
- `<text x="${topLeft.x}" y="${topLeft.y - (i + 1) * 0.05}" dy="-0.15" style="font: 0.05px monospace; fill: #833;">${port.labels[0]} [${alternateLabels}]</text>`,
156
- )
157
- }
158
- })
159
-
160
- debugElements.push(...debugElements)
161
- }
162
-
163
- return [
164
- svgElements.join("\n "),
165
- portElements,
166
- centerDiamond,
167
- ...debugElements,
168
- ].join("\n")
169
- }
170
-
171
- export function getSvg(
172
- symbol: SchSymbol,
173
- options: { width?: number; height?: number; debug?: boolean } = {},
174
- ): string {
175
- const { size } = symbol
176
- const innerSvg = getInnerSvg(symbol, options)
177
-
178
- // Use the center and the size to calculate the viewBox
179
- const bufferMultiple = 1.2
180
- const w = size.width * bufferMultiple
181
- const h = size.height * bufferMultiple
182
- const viewBox = {
183
- x: symbol.center.x - w / 2,
184
- y: makeYUpPositive(symbol.center.y, true) - h / 2,
185
- width: w,
186
- height: h,
187
- }
188
-
189
- if (options.width && !options.height) {
190
- options.height = options.width! * (viewBox.height / viewBox.width)
191
- } else if (!options.width && options.height) {
192
- options.width = options.height! * (viewBox.width / viewBox.height)
193
- } else if (!options.width && !options.height) {
194
- options.width = viewBox.width
195
- options.height = viewBox.height
196
- }
197
-
198
- return `<svg width="${options.width}" height="${options.height}" viewBox="${viewBox.x} ${viewBox.y} ${viewBox.width} ${viewBox.height}" xmlns="http://www.w3.org/2000/svg">${innerSvg}</svg>`
199
- }
package/drawing/index.ts DELETED
@@ -1,10 +0,0 @@
1
- export * from "./types"
2
- export * from "./box"
3
- export * from "./arrow"
4
- export * from "./circle"
5
- export * from "./getSvg"
6
- export * from "./mapColor"
7
- export * from "./resizeSymbol"
8
- export * from "./pathToSvgD"
9
- export * from "./text"
10
- export * from "./svgPathToPoints"
@@ -1,10 +0,0 @@
1
- export const mapColor = (color: string) => {
2
- switch (color) {
3
- case "primary":
4
- return "black"
5
- case "secondary":
6
- return "gray"
7
- default:
8
- return color
9
- }
10
- }
@@ -1,97 +0,0 @@
1
- import { NinePointAnchor, SchSymbol } from "drawing/types"
2
- import { rotateRightFacingSymbol } from "drawing/rotateSymbol"
3
- import { getBoundsOfPrimitives } from "drawing/utils/getBoundsOfPrimitives"
4
-
5
- interface ModifySymbolBuilder {
6
- changeTextAnchor(
7
- text: "{REF}" | "{VAL}" | string,
8
- newAnchor: NinePointAnchor,
9
- ): ModifySymbolBuilder
10
- rotateRightFacingSymbol(
11
- newOrientation: "up" | "down" | "left" | "right",
12
- ): ModifySymbolBuilder
13
- labelPort(currentLabel: string, newLabels: string[]): ModifySymbolBuilder
14
- build(): SchSymbol
15
- }
16
-
17
- class SymbolModifier implements ModifySymbolBuilder {
18
- private symbol: SchSymbol
19
-
20
- constructor(symbol: SchSymbol) {
21
- this.symbol = JSON.parse(JSON.stringify(symbol))
22
- this.symbol.size = this.computeSize()
23
- }
24
-
25
- changeTextAnchor(
26
- text: "{REF}" | "{VAL}" | string,
27
- newAnchor: NinePointAnchor,
28
- ): ModifySymbolBuilder {
29
- this.symbol = {
30
- ...this.symbol,
31
- primitives: this.symbol.primitives.map((primitive) => {
32
- if (primitive.type === "text" && primitive.text === text) {
33
- return {
34
- ...primitive,
35
- anchor: newAnchor,
36
- }
37
- }
38
- return primitive
39
- }),
40
- }
41
- return this
42
- }
43
-
44
- labelPort(currentLabel: string, newLabels: string[]): ModifySymbolBuilder {
45
- this.symbol = {
46
- ...this.symbol,
47
- ports: this.symbol.ports.map((port) => {
48
- return port.labels.includes(currentLabel)
49
- ? { ...port, labels: newLabels }
50
- : port
51
- }),
52
- }
53
- return this
54
- }
55
-
56
- rotateRightFacingSymbol(
57
- newOrientation: "up" | "down" | "left" | "right",
58
- ): ModifySymbolBuilder {
59
- this.symbol = rotateRightFacingSymbol(this.symbol, {
60
- newOrientation,
61
- })
62
- return this
63
- }
64
-
65
- computeSize(): { width: number; height: number } {
66
- const bounds = getBoundsOfPrimitives(this.symbol.primitives)
67
- return {
68
- width: bounds.maxX - bounds.minX,
69
- height: bounds.maxY - bounds.minY,
70
- }
71
- }
72
-
73
- build(): SchSymbol {
74
- return { ...this.symbol, size: this.computeSize() }
75
- }
76
- }
77
-
78
- export const modifySymbol = (symbol: any): ModifySymbolBuilder => {
79
- return new SymbolModifier({
80
- ...symbol,
81
- primitives: symbol.primitives ?? [
82
- ...Object.values(symbol.paths ?? {}),
83
- ...Object.values(symbol.texts ?? {}),
84
- ...Object.values(symbol.circles ?? {}),
85
- ...Object.values(symbol.rects ?? {}),
86
- ],
87
- ports:
88
- symbol.ports ??
89
- Object.entries(symbol.refblocks).flatMap(([key, refblock]) => {
90
- return [{ ...(refblock as object), labels: [key] }]
91
- }),
92
- center: symbol.center ?? {
93
- x: symbol.bounds.centerX,
94
- y: symbol.bounds.centerY,
95
- },
96
- })
97
- }
@@ -1,11 +0,0 @@
1
- export const ninePointAnchorToSvgAnchor = {
2
- top_left: "start",
3
- top_right: "end",
4
- bottom_left: "start",
5
- bottom_right: "end",
6
- center: "middle",
7
- middle_top: "middle",
8
- middle_bottom: "middle",
9
- middle_left: "start",
10
- middle_right: "end",
11
- }
package/drawing/path.ts DELETED
@@ -1,5 +0,0 @@
1
- import type { PathPrimitive } from "drawing"
2
-
3
- export function path(options: Omit<PathPrimitive, "type">): PathPrimitive {
4
- return { type: "path", ...options }
5
- }
@@ -1,22 +0,0 @@
1
- import type { Point } from "drawing"
2
- import { makeYUpPositive } from "./utils/makeYUpPositive"
3
-
4
- export function pathToSvgD(
5
- points: Point[],
6
- {
7
- closed = false,
8
- yUpPositive = true,
9
- }: {
10
- closed?: boolean
11
- yUpPositive?: boolean
12
- },
13
- ): string {
14
- const pathCommands = points
15
- .map(
16
- (point, index) =>
17
- `${index === 0 ? "M" : "L"}${point.x},${makeYUpPositive(point.y, yUpPositive)}`,
18
- )
19
- .join(" ")
20
-
21
- return closed ? `${pathCommands} Z` : pathCommands
22
- }
@@ -1,67 +0,0 @@
1
- import type { SchSymbol } from "./types"
2
-
3
- export function resizeSymbol(
4
- symbol: SchSymbol,
5
- newSize: { width?: number; height?: number },
6
- ): SchSymbol {
7
- const { width: oldWidth, height: oldHeight } = symbol.size
8
- let scaleX = 1,
9
- scaleY = 1
10
-
11
- if (newSize.width && newSize.height) {
12
- scaleX = newSize.width / oldWidth
13
- scaleY = newSize.height / oldHeight
14
- } else if (newSize.width) {
15
- scaleX = scaleY = newSize.width / oldWidth
16
- } else if (newSize.height) {
17
- scaleX = scaleY = newSize.height / oldHeight
18
- }
19
-
20
- const resizedPrimitives = symbol.primitives.map((primitive) => {
21
- switch (primitive.type) {
22
- case "path":
23
- return {
24
- ...primitive,
25
- points: primitive.points.map((p) => ({
26
- x: p.x * scaleX,
27
- y: p.y * scaleY,
28
- })),
29
- }
30
- case "text":
31
- case "circle":
32
- return {
33
- ...primitive,
34
- x: primitive.x * scaleX,
35
- y: primitive.y * scaleY,
36
- }
37
- case "box":
38
- return {
39
- ...primitive,
40
- x: primitive.x * scaleX,
41
- y: primitive.y * scaleY,
42
- width: primitive.width * scaleX,
43
- height: primitive.height * scaleY,
44
- }
45
- default:
46
- return primitive
47
- }
48
- })
49
-
50
- return {
51
- ...symbol,
52
- primitives: resizedPrimitives,
53
- center: {
54
- x: symbol.center.x * scaleX,
55
- y: symbol.center.y * scaleY,
56
- },
57
- ports: symbol.ports.map((port) => ({
58
- ...port,
59
- x: port.x * scaleX,
60
- y: port.y * scaleY,
61
- })),
62
- size: {
63
- width: oldWidth * scaleX,
64
- height: oldHeight * scaleY,
65
- },
66
- }
67
- }