schematic-symbols 0.0.1

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 (66) hide show
  1. package/.github/CODEOWNERS +1 -0
  2. package/.github/workflows/bun-pver-release.yml +25 -0
  3. package/README.md +88 -0
  4. package/assets/symbols-svg-json/boxresistor.json +90 -0
  5. package/assets/symbols-svg-json/capacitor.json +76 -0
  6. package/assets/symbols-svg-json/capacitor_polarized.json +83 -0
  7. package/assets/symbols-svg-json/diode.json +91 -0
  8. package/assets/symbols-svg-json/diode_bipolar_zener.json +166 -0
  9. package/assets/symbols-svg-json/diode_schottky.json +76 -0
  10. package/assets/symbols-svg-json/diode_zener.json +31 -0
  11. package/assets/symbols-svg-json/fuse.json +84 -0
  12. package/assets/symbols-svg-json/led.json +205 -0
  13. package/assets/symbols-svg-json/mosfet_depletion_normally_on.json +267 -0
  14. package/assets/symbols-svg-json/potentiometer.json +137 -0
  15. package/assets/symbols-svg-json/potentiometer2.json +160 -0
  16. package/assets/symbols-svg-json/testshape.json +35 -0
  17. package/assets/symbols-svg-json/varistor.json +129 -0
  18. package/assets/symbols.svg +965 -0
  19. package/biome.json +44 -0
  20. package/bun.lockb +0 -0
  21. package/dev-server.ts +22 -0
  22. package/drawing/arrow.ts +41 -0
  23. package/drawing/box.ts +5 -0
  24. package/drawing/circle.ts +7 -0
  25. package/drawing/defineSymbol.ts +5 -0
  26. package/drawing/getBoundsOfSvgJson.ts +44 -0
  27. package/drawing/getSvg.ts +133 -0
  28. package/drawing/index.ts +11 -0
  29. package/drawing/mapColor.ts +10 -0
  30. package/drawing/ninePointAnchorToSvgAnchor.ts +11 -0
  31. package/drawing/path.ts +5 -0
  32. package/drawing/pathToSvgD.ts +9 -0
  33. package/drawing/resizeSymbol.ts +66 -0
  34. package/drawing/rotateSymbol.ts +94 -0
  35. package/drawing/svgPathToPoints.ts +50 -0
  36. package/drawing/text.ts +8 -0
  37. package/drawing/types.ts +90 -0
  38. package/index.ts +1 -0
  39. package/package.json +25 -0
  40. package/scripts/build.ts +18 -0
  41. package/scripts/convertToObjectWithOrderedPositionIds.ts +52 -0
  42. package/scripts/generate-symbols-from-asset-svgs.ts +145 -0
  43. package/scripts/lib/applyGroupTransformsToChildren.ts +118 -0
  44. package/scripts/lib/findInnerText.ts +11 -0
  45. package/scripts/lib/generate-web-page.ts +60 -0
  46. package/scripts/lib/getTsFileContentForSvgGroup.ts +33 -0
  47. package/scripts/lib/serializeSvgPathCommands.ts +47 -0
  48. package/symbols/boxresistor_horz.ts +35 -0
  49. package/symbols/boxresistor_vert.ts +4 -0
  50. package/symbols/fuse_horz.ts +24 -0
  51. package/symbols/fuse_vert.ts +4 -0
  52. package/symbols/index.ts +31 -0
  53. package/symbols/led_horz.ts +18 -0
  54. package/symbols/led_vert.ts +4 -0
  55. package/symbols/mosfet_depletion_normally_on_horz.ts +19 -0
  56. package/symbols/mosfet_depletion_normally_on_vert.ts +21 -0
  57. package/symbols/potentiometer2_horz.ts +14 -0
  58. package/symbols/potentiometer2_vert.ts +4 -0
  59. package/symbols/potentiometer_horz.ts +18 -0
  60. package/symbols/potentiometer_vert.ts +6 -0
  61. package/symbols/varistor_horz.ts +24 -0
  62. package/symbols/varistor_vert.ts +4 -0
  63. package/tests/assets/boxresistor-untransformed.json +187 -0
  64. package/tests/assets/testshape-untransformed.json +25 -0
  65. package/tests/normalize-svg.test.ts +29 -0
  66. package/tsconfig.json +28 -0
@@ -0,0 +1 @@
1
+ * @seveibar @tscircuit/core
@@ -0,0 +1,25 @@
1
+ # Created using @tscircuit/plop (npm install -g @tscircuit/plop)
2
+ name: Publish to npm
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ jobs:
8
+ publish:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v3
12
+ - name: Setup bun
13
+ uses: oven-sh/setup-bun@v1
14
+ with:
15
+ bun-version: latest
16
+ - uses: actions/setup-node@v3
17
+ with:
18
+ node-version: 20
19
+ registry-url: https://registry.npmjs.org/
20
+ - run: npm install -g pver
21
+ - run: bun install --frozen-lockfile
22
+ - run: bun run build
23
+ - run: pver release
24
+ env:
25
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
package/README.md ADDED
@@ -0,0 +1,88 @@
1
+ # schematic-symbols
2
+
3
+ > [!WARNING]
4
+ > This is a work-in-progress that contains all the schematic symbols for tscircuit.
5
+
6
+ Schematic symbols for tscircuit
7
+
8
+ ## Usage
9
+
10
+ ```ts
11
+ import { getSvg, resize, symbols } from "@tscircuit/schematic-symbols"
12
+
13
+ console.log(symbols.resistor.primitives)
14
+ // [{ type: "path", d: "M0 0L1 0...", color: "primary" }, {type: "text", text: "{REF}", ... }]
15
+ console.log(symbols.resistor.size)
16
+ // { width: 1, height: 0.6 }
17
+
18
+ getSvg(resistor)
19
+ // <svg><path d="M0 0L1 0... ...</svg>
20
+
21
+ // You can easily resize symbols
22
+ console.log(resize(symbols.resistor, { width: 100 }).size)
23
+ // { width: 100, height: 60 }
24
+ ```
25
+
26
+ ## Adding New Symbols
27
+
28
+ Go into the `./symbols` directory to add new shapes. After adding a shape file, it will
29
+ automatically appear in the dev environment (`npm run dev`). Here's an example of a shape
30
+ file:
31
+
32
+ ```ts
33
+ // boxresistor.ts
34
+ import { path, text, defineSymbol } from "drawing"
35
+
36
+ export const boxresistor = defineSymbol({
37
+ primitives: [
38
+ path({ points: [[0, 0] /* ... */, , [1, 0]], color: "primary" }),
39
+ text("{REF}", { x: 0.5, y: 0.3, anchor: "middle_top" }),
40
+ ],
41
+ ports: [
42
+ { x: 0, y: 0, labels: ["1", "-"] },
43
+ { x: 1, y: 0, labels: ["2", "+"] },
44
+ ],
45
+ center: { x: 0.5, y: 0 },
46
+ size: { width: 1, height: 0.6 },
47
+ })
48
+ ```
49
+
50
+ ### Primitives
51
+
52
+ Various primitive JSON elements are defined to represent components, each primitive has
53
+ a function you can use to quickly define it inside new symbol definitions.
54
+
55
+ | Primitive | Description |
56
+ | --------- | ----------------------------------------------------------- |
57
+ | `path` | A set of lines `{ points: Array<[number, number]>, color }` |
58
+ | `text` | Text `{ text, x, y, anchor }` |
59
+ | `circle` | Circle `{ x, y, radius }` |
60
+ | `box` | Box `{ x, y, width, height, anchor }` |
61
+
62
+ ### Colors
63
+
64
+ You can use the following color aliases to color your symbol:
65
+
66
+ - `primary`
67
+ - `secondary`
68
+ - `background`
69
+
70
+ ### Guidelines
71
+
72
+ The symbols should all look correct next to eachother, since they're all used together
73
+ in the same schematic.
74
+
75
+ - The width of most standard passives is `1`
76
+ - The height of most standard passives is `0.6`
77
+
78
+ ### Development
79
+
80
+ Software needed to edit this project:
81
+ - VS Code
82
+ - Inkscape
83
+
84
+ ## References
85
+
86
+ - [MIT Schematic Symbols](https://github.com/sjgallagher2/SchematicSymbolsSVG)
87
+ - [affinity-circuit-symbols-asset](https://github.com/keikawa/affinity-circuit-symbols-asset/tree/main)
88
+ - [Inkscape Symbols](https://github.com/upb-lea/Inkscape_electric_Symbols?tab=readme-ov-file)
@@ -0,0 +1,90 @@
1
+ {
2
+ "paths": {
3
+ "path1": {
4
+ "type": "path",
5
+ "points": [
6
+ {
7
+ "x": -0.5291666499999996,
8
+ "y": 0
9
+ },
10
+ {
11
+ "x": -0.2645833500000001,
12
+ "y": 0
13
+ }
14
+ ],
15
+ "color": "primary",
16
+ "fill": false
17
+ },
18
+ "path2": {
19
+ "type": "path",
20
+ "points": [
21
+ {
22
+ "x": 0.2645832500000007,
23
+ "y": 0
24
+ },
25
+ {
26
+ "x": 0.5291666500000001,
27
+ "y": 0
28
+ }
29
+ ],
30
+ "color": "primary",
31
+ "fill": false
32
+ },
33
+ "path3": {
34
+ "type": "path",
35
+ "points": [
36
+ {
37
+ "x": -1.4999999997655777e-7,
38
+ "y": -0.13229169999999968
39
+ },
40
+ {
41
+ "x": 0.26458314999999955,
42
+ "y": -0.13229169999999968
43
+ },
44
+ {
45
+ "x": 0.26458314999999955,
46
+ "y": 0.13229169999999968
47
+ },
48
+ {
49
+ "x": -0.2645835500000011,
50
+ "y": 0.13229169999999968
51
+ },
52
+ {
53
+ "x": -0.2645835500000011,
54
+ "y": -0.13229169999999968
55
+ },
56
+ {
57
+ "x": -1.5000000175291461e-7,
58
+ "y": -0.13229169999999968
59
+ }
60
+ ],
61
+ "color": "primary",
62
+ "fill": false
63
+ }
64
+ },
65
+ "texts": {
66
+ "top1": {
67
+ "type": "text",
68
+ "text": "{REF}",
69
+ "x": -0.018740649999999803,
70
+ "y": -0.20383659999999892
71
+ },
72
+ "bottom1": {
73
+ "type": "text",
74
+ "text": "{VAL}",
75
+ "x": -0.01777865000000034,
76
+ "y": 0.2961594000000023
77
+ }
78
+ },
79
+ "refblocks": {},
80
+ "bounds": {
81
+ "minX": -0.5291666499999996,
82
+ "maxX": 0.5291666500000001,
83
+ "minY": -0.13229169999999968,
84
+ "maxY": 0.13229169999999968,
85
+ "width": 1.0583332999999997,
86
+ "height": 0.26458339999999936,
87
+ "centerX": 2.220446049250313e-16,
88
+ "centerY": 0
89
+ }
90
+ }
@@ -0,0 +1,76 @@
1
+ {
2
+ "paths": {
3
+ "path27": {
4
+ "type": "path",
5
+ "points": [
6
+ {
7
+ "x": 0.5291666500000001,
8
+ "y": 0
9
+ },
10
+ {
11
+ "x": 0.07937504999999989,
12
+ "y": 0
13
+ }
14
+ ],
15
+ "color": "primary",
16
+ "fill": false
17
+ },
18
+ "path28": {
19
+ "type": "path",
20
+ "points": [
21
+ {
22
+ "x": -0.07937494999999961,
23
+ "y": 0
24
+ },
25
+ {
26
+ "x": -0.5291666500000001,
27
+ "y": 0
28
+ }
29
+ ],
30
+ "color": "primary",
31
+ "fill": false
32
+ },
33
+ "path29": {
34
+ "type": "path",
35
+ "points": [
36
+ {
37
+ "x": 0.07937504999999989,
38
+ "y": -0.26458330000000174
39
+ },
40
+ {
41
+ "x": 0.07937504999999989,
42
+ "y": 0.2645832999999982
43
+ }
44
+ ],
45
+ "color": "primary",
46
+ "fill": false
47
+ },
48
+ "path30": {
49
+ "type": "path",
50
+ "points": [
51
+ {
52
+ "x": -0.07937495000000006,
53
+ "y": -0.26458330000000174
54
+ },
55
+ {
56
+ "x": -0.07937494999999961,
57
+ "y": 0.2645832999999982
58
+ }
59
+ ],
60
+ "color": "primary",
61
+ "fill": false
62
+ }
63
+ },
64
+ "texts": {},
65
+ "refblocks": {},
66
+ "bounds": {
67
+ "minX": -0.5291666500000001,
68
+ "maxX": 0.5291666500000001,
69
+ "minY": -0.26458330000000174,
70
+ "maxY": 0.2645832999999982,
71
+ "width": 1.0583333000000001,
72
+ "height": 0.5291665999999999,
73
+ "centerX": 0,
74
+ "centerY": -1.7763568394002505e-15
75
+ }
76
+ }
@@ -0,0 +1,83 @@
1
+ {
2
+ "paths": {
3
+ "path31": {
4
+ "type": "path",
5
+ "points": [
6
+ {
7
+ "x": 0.5291666499999996,
8
+ "y": 0
9
+ },
10
+ {
11
+ "x": 0.07937484999999933,
12
+ "y": 0
13
+ }
14
+ ],
15
+ "color": "primary",
16
+ "fill": false
17
+ },
18
+ "path32": {
19
+ "type": "path",
20
+ "points": [
21
+ {
22
+ "x": -0.07937515000000017,
23
+ "y": 0
24
+ },
25
+ {
26
+ "x": -0.5291666500000001,
27
+ "y": 0
28
+ }
29
+ ],
30
+ "color": "primary",
31
+ "fill": false
32
+ },
33
+ "path33": {
34
+ "type": "path",
35
+ "points": [
36
+ {
37
+ "x": 0.07937504999999989,
38
+ "y": -0.2645832999999982
39
+ },
40
+ {
41
+ "x": 0.07937504999999989,
42
+ "y": 0.26458329999999997
43
+ }
44
+ ],
45
+ "color": "primary",
46
+ "fill": false
47
+ },
48
+ "path34": {
49
+ "type": "path",
50
+ "points": [
51
+ {
52
+ "x": -0.07937495000000006,
53
+ "y": -0.2645832999999982
54
+ },
55
+ {
56
+ "x": -0.07937495000000006,
57
+ "y": 0.26458329999999997
58
+ }
59
+ ],
60
+ "color": "primary",
61
+ "fill": false
62
+ }
63
+ },
64
+ "texts": {
65
+ "top1": {
66
+ "type": "text",
67
+ "text": "+",
68
+ "x": 0.13859564999999963,
69
+ "y": -0.3182225999999986
70
+ }
71
+ },
72
+ "refblocks": {},
73
+ "bounds": {
74
+ "minX": -0.5291666500000001,
75
+ "maxX": 0.5291666499999996,
76
+ "minY": -0.2645832999999982,
77
+ "maxY": 0.26458329999999997,
78
+ "width": 1.0583332999999997,
79
+ "height": 0.5291665999999982,
80
+ "centerX": -2.220446049250313e-16,
81
+ "centerY": 8.881784197001252e-16
82
+ }
83
+ }
@@ -0,0 +1,91 @@
1
+ {
2
+ "paths": {
3
+ "path40": {
4
+ "type": "path",
5
+ "points": [
6
+ {
7
+ "x": 0.13229164999999998,
8
+ "y": 0
9
+ },
10
+ {
11
+ "x": -0.13229164999999954,
12
+ "y": 0.13229169999999968
13
+ }
14
+ ],
15
+ "color": "primary",
16
+ "fill": false
17
+ },
18
+ "path41": {
19
+ "type": "path",
20
+ "points": [
21
+ {
22
+ "x": -0.13229164999999954,
23
+ "y": -0.13229170000000323
24
+ },
25
+ {
26
+ "x": 0.13229164999999998,
27
+ "y": 0
28
+ }
29
+ ],
30
+ "color": "primary",
31
+ "fill": false
32
+ },
33
+ "path42": {
34
+ "type": "path",
35
+ "points": [
36
+ {
37
+ "x": -0.13229164999999954,
38
+ "y": 0.13229169999999613
39
+ },
40
+ {
41
+ "x": -0.13229164999999954,
42
+ "y": -0.13229170000000323
43
+ }
44
+ ],
45
+ "color": "primary",
46
+ "fill": false
47
+ },
48
+ "path43": {
49
+ "type": "path",
50
+ "points": [
51
+ {
52
+ "x": 0.13229164999999998,
53
+ "y": -0.13229170000000323
54
+ },
55
+ {
56
+ "x": 0.13229164999999998,
57
+ "y": 0.13229169999999613
58
+ }
59
+ ],
60
+ "color": "primary",
61
+ "fill": false
62
+ },
63
+ "path44": {
64
+ "type": "path",
65
+ "points": [
66
+ {
67
+ "x": 0.5291666500000001,
68
+ "y": 0
69
+ },
70
+ {
71
+ "x": -0.5291666499999996,
72
+ "y": 0
73
+ }
74
+ ],
75
+ "color": "primary",
76
+ "fill": false
77
+ }
78
+ },
79
+ "texts": {},
80
+ "refblocks": {},
81
+ "bounds": {
82
+ "minX": -0.5291666499999996,
83
+ "maxX": 0.5291666500000001,
84
+ "minY": -0.13229170000000323,
85
+ "maxY": 0.13229169999999968,
86
+ "width": 1.0583332999999997,
87
+ "height": 0.2645834000000029,
88
+ "centerX": 2.220446049250313e-16,
89
+ "centerY": -1.7763568394002505e-15
90
+ }
91
+ }
@@ -0,0 +1,166 @@
1
+ {
2
+ "paths": {
3
+ "path67": {
4
+ "type": "path",
5
+ "points": [
6
+ {
7
+ "x": 5.000000058430487e-8,
8
+ "y": 3.552713678800501e-15
9
+ },
10
+ {
11
+ "x": -0.2645832499999994,
12
+ "y": 0.13229200000000318
13
+ }
14
+ ],
15
+ "color": "primary",
16
+ "fill": false
17
+ },
18
+ "path68": {
19
+ "type": "path",
20
+ "points": [
21
+ {
22
+ "x": -0.2645832499999994,
23
+ "y": -0.13229199999999608
24
+ },
25
+ {
26
+ "x": 5.000000058430487e-8,
27
+ "y": 0
28
+ }
29
+ ],
30
+ "color": "primary",
31
+ "fill": false
32
+ },
33
+ "path69": {
34
+ "type": "path",
35
+ "points": [
36
+ {
37
+ "x": -0.2645832499999994,
38
+ "y": 0.13229200000000318
39
+ },
40
+ {
41
+ "x": -0.2645832499999994,
42
+ "y": -0.13229199999999608
43
+ }
44
+ ],
45
+ "color": "primary",
46
+ "fill": false
47
+ },
48
+ "path70": {
49
+ "type": "path",
50
+ "points": [
51
+ {
52
+ "x": 5.000000058430487e-8,
53
+ "y": -0.13229199999999608
54
+ },
55
+ {
56
+ "x": 5.000000058430487e-8,
57
+ "y": 0.13229200000000318
58
+ }
59
+ ],
60
+ "color": "primary",
61
+ "fill": false
62
+ },
63
+ "path71": {
64
+ "type": "path",
65
+ "points": [
66
+ {
67
+ "x": 0.5291666499999996,
68
+ "y": -9.999999974752427e-7
69
+ },
70
+ {
71
+ "x": -0.5291666500000001,
72
+ "y": -9.999999974752427e-7
73
+ }
74
+ ],
75
+ "color": "primary",
76
+ "fill": false
77
+ },
78
+ "path72": {
79
+ "type": "path",
80
+ "points": [
81
+ {
82
+ "x": 4.499999994855841e-7,
83
+ "y": 0.13229200000000318
84
+ },
85
+ {
86
+ "x": -0.07937455000000071,
87
+ "y": 0.13229200000000318
88
+ }
89
+ ],
90
+ "color": "primary",
91
+ "fill": false
92
+ },
93
+ "path73": {
94
+ "type": "path",
95
+ "points": [
96
+ {
97
+ "x": 4.499999994855841e-7,
98
+ "y": -0.1322909999999986
99
+ },
100
+ {
101
+ "x": 0.07937544999999968,
102
+ "y": -0.1322909999999986
103
+ }
104
+ ],
105
+ "color": "primary",
106
+ "fill": false
107
+ },
108
+ "path74": {
109
+ "type": "path",
110
+ "points": [
111
+ {
112
+ "x": 3.49999999649242e-7,
113
+ "y": 3.552713678800501e-15
114
+ },
115
+ {
116
+ "x": 0.2645833500000001,
117
+ "y": -0.13229199999999608
118
+ }
119
+ ],
120
+ "color": "primary",
121
+ "fill": false
122
+ },
123
+ "path75": {
124
+ "type": "path",
125
+ "points": [
126
+ {
127
+ "x": 0.2645833500000001,
128
+ "y": 0.13229200000000318
129
+ },
130
+ {
131
+ "x": 3.49999999649242e-7,
132
+ "y": 3.552713678800501e-15
133
+ }
134
+ ],
135
+ "color": "primary",
136
+ "fill": false
137
+ },
138
+ "path76": {
139
+ "type": "path",
140
+ "points": [
141
+ {
142
+ "x": 0.2645833500000001,
143
+ "y": -0.13229199999999608
144
+ },
145
+ {
146
+ "x": 0.2645833500000001,
147
+ "y": 0.13229200000000318
148
+ }
149
+ ],
150
+ "color": "primary",
151
+ "fill": false
152
+ }
153
+ },
154
+ "texts": {},
155
+ "refblocks": {},
156
+ "bounds": {
157
+ "minX": -0.5291666500000001,
158
+ "maxX": 0.5291666499999996,
159
+ "minY": -0.13229199999999608,
160
+ "maxY": 0.13229200000000318,
161
+ "width": 1.0583332999999997,
162
+ "height": 0.26458399999999926,
163
+ "centerX": -2.220446049250313e-16,
164
+ "centerY": 3.552713678800501e-15
165
+ }
166
+ }
@@ -0,0 +1,76 @@
1
+ {
2
+ "paths": {
3
+ "path63": {
4
+ "type": "path",
5
+ "points": [
6
+ {
7
+ "x": -5.000000014021566e-8,
8
+ "y": -0.13229199999999963
9
+ },
10
+ {
11
+ "x": 0.05291665000000023,
12
+ "y": -0.13229199999999963
13
+ }
14
+ ],
15
+ "color": "primary",
16
+ "fill": false
17
+ },
18
+ "path64": {
19
+ "type": "path",
20
+ "points": [
21
+ {
22
+ "x": 0.05291665000000023,
23
+ "y": -0.07937499999999886
24
+ },
25
+ {
26
+ "x": 0.05291665000000023,
27
+ "y": -0.13229199999999963
28
+ }
29
+ ],
30
+ "color": "primary",
31
+ "fill": false
32
+ },
33
+ "path65": {
34
+ "type": "path",
35
+ "points": [
36
+ {
37
+ "x": -5.000000014021566e-8,
38
+ "y": 0.13229199999999963
39
+ },
40
+ {
41
+ "x": -0.05291665000000023,
42
+ "y": 0.13229199999999963
43
+ }
44
+ ],
45
+ "color": "primary",
46
+ "fill": false
47
+ },
48
+ "path66": {
49
+ "type": "path",
50
+ "points": [
51
+ {
52
+ "x": -0.05291665000000023,
53
+ "y": 0.07937499999999886
54
+ },
55
+ {
56
+ "x": -0.05291665000000023,
57
+ "y": 0.13229199999999963
58
+ }
59
+ ],
60
+ "color": "primary",
61
+ "fill": false
62
+ }
63
+ },
64
+ "texts": {},
65
+ "refblocks": {},
66
+ "bounds": {
67
+ "minX": -0.05291665000000023,
68
+ "maxX": 0.05291665000000023,
69
+ "minY": -0.13229199999999963,
70
+ "maxY": 0.13229199999999963,
71
+ "width": 0.10583330000000046,
72
+ "height": 0.26458399999999926,
73
+ "centerX": 0,
74
+ "centerY": 0
75
+ }
76
+ }