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.
- package/.github/CODEOWNERS +1 -0
- package/.github/workflows/bun-pver-release.yml +25 -0
- package/README.md +88 -0
- package/assets/symbols-svg-json/boxresistor.json +90 -0
- package/assets/symbols-svg-json/capacitor.json +76 -0
- package/assets/symbols-svg-json/capacitor_polarized.json +83 -0
- package/assets/symbols-svg-json/diode.json +91 -0
- package/assets/symbols-svg-json/diode_bipolar_zener.json +166 -0
- package/assets/symbols-svg-json/diode_schottky.json +76 -0
- package/assets/symbols-svg-json/diode_zener.json +31 -0
- package/assets/symbols-svg-json/fuse.json +84 -0
- package/assets/symbols-svg-json/led.json +205 -0
- package/assets/symbols-svg-json/mosfet_depletion_normally_on.json +267 -0
- package/assets/symbols-svg-json/potentiometer.json +137 -0
- package/assets/symbols-svg-json/potentiometer2.json +160 -0
- package/assets/symbols-svg-json/testshape.json +35 -0
- package/assets/symbols-svg-json/varistor.json +129 -0
- package/assets/symbols.svg +965 -0
- package/biome.json +44 -0
- package/bun.lockb +0 -0
- package/dev-server.ts +22 -0
- package/drawing/arrow.ts +41 -0
- package/drawing/box.ts +5 -0
- package/drawing/circle.ts +7 -0
- package/drawing/defineSymbol.ts +5 -0
- package/drawing/getBoundsOfSvgJson.ts +44 -0
- package/drawing/getSvg.ts +133 -0
- package/drawing/index.ts +11 -0
- package/drawing/mapColor.ts +10 -0
- package/drawing/ninePointAnchorToSvgAnchor.ts +11 -0
- package/drawing/path.ts +5 -0
- package/drawing/pathToSvgD.ts +9 -0
- package/drawing/resizeSymbol.ts +66 -0
- package/drawing/rotateSymbol.ts +94 -0
- package/drawing/svgPathToPoints.ts +50 -0
- package/drawing/text.ts +8 -0
- package/drawing/types.ts +90 -0
- package/index.ts +1 -0
- package/package.json +25 -0
- package/scripts/build.ts +18 -0
- package/scripts/convertToObjectWithOrderedPositionIds.ts +52 -0
- package/scripts/generate-symbols-from-asset-svgs.ts +145 -0
- package/scripts/lib/applyGroupTransformsToChildren.ts +118 -0
- package/scripts/lib/findInnerText.ts +11 -0
- package/scripts/lib/generate-web-page.ts +60 -0
- package/scripts/lib/getTsFileContentForSvgGroup.ts +33 -0
- package/scripts/lib/serializeSvgPathCommands.ts +47 -0
- package/symbols/boxresistor_horz.ts +35 -0
- package/symbols/boxresistor_vert.ts +4 -0
- package/symbols/fuse_horz.ts +24 -0
- package/symbols/fuse_vert.ts +4 -0
- package/symbols/index.ts +31 -0
- package/symbols/led_horz.ts +18 -0
- package/symbols/led_vert.ts +4 -0
- package/symbols/mosfet_depletion_normally_on_horz.ts +19 -0
- package/symbols/mosfet_depletion_normally_on_vert.ts +21 -0
- package/symbols/potentiometer2_horz.ts +14 -0
- package/symbols/potentiometer2_vert.ts +4 -0
- package/symbols/potentiometer_horz.ts +18 -0
- package/symbols/potentiometer_vert.ts +6 -0
- package/symbols/varistor_horz.ts +24 -0
- package/symbols/varistor_vert.ts +4 -0
- package/tests/assets/boxresistor-untransformed.json +187 -0
- package/tests/assets/testshape-untransformed.json +25 -0
- package/tests/normalize-svg.test.ts +29 -0
- package/tsconfig.json +28 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
import { rotateSymbol } from "drawing/rotateSymbol"
|
2
|
+
import mosfet_depletion_normally_on_horz from "./mosfet_depletion_normally_on_horz"
|
3
|
+
import type { TextPrimitive } from "drawing"
|
4
|
+
|
5
|
+
const rotated = rotateSymbol(mosfet_depletion_normally_on_horz)
|
6
|
+
|
7
|
+
const ref = rotated.primitives.find(
|
8
|
+
(p) => p.type === "text" && p.text === "{REF}",
|
9
|
+
)! as TextPrimitive
|
10
|
+
const val = rotated.primitives.find(
|
11
|
+
(p) => p.type === "text" && p.text === "{VAL}",
|
12
|
+
)! as TextPrimitive
|
13
|
+
|
14
|
+
ref.anchor = "middle_top"
|
15
|
+
val.anchor = "middle_top"
|
16
|
+
|
17
|
+
ref.x = val.x
|
18
|
+
|
19
|
+
val.y += 0.15
|
20
|
+
|
21
|
+
export default rotated
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import { defineSymbol } from "drawing/defineSymbol"
|
2
|
+
import svgJson from "assets/symbols-svg-json/potentiometer2.json"
|
3
|
+
|
4
|
+
const { paths, texts, bounds, refblocks } = svgJson
|
5
|
+
|
6
|
+
export default defineSymbol({
|
7
|
+
primitives: [...Object.values(paths), ...Object.values(texts)] as any,
|
8
|
+
ports: [
|
9
|
+
{ ...refblocks.left1, labels: ["1"] }, // TODO add more "standard" labels
|
10
|
+
{ ...refblocks.right1, labels: ["2"] }, // TODO add more "standard" labels
|
11
|
+
],
|
12
|
+
size: { width: bounds.width, height: bounds.height },
|
13
|
+
center: { x: bounds.centerX, y: bounds.centerY },
|
14
|
+
})
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { defineSymbol } from "drawing/defineSymbol"
|
2
|
+
import svgJson from "assets/symbols-svg-json/potentiometer.json"
|
3
|
+
|
4
|
+
const { paths, texts, bounds, refblocks } = svgJson
|
5
|
+
|
6
|
+
export default defineSymbol({
|
7
|
+
primitives: [
|
8
|
+
...Object.values(paths),
|
9
|
+
{ ...texts.bottom1, y: 0.35, anchor: "middle_top" },
|
10
|
+
{ ...texts.right1, anchor: "middle_left" },
|
11
|
+
] as any,
|
12
|
+
ports: [
|
13
|
+
{ ...refblocks.left1, labels: ["1"] }, // TODO add more "standard" labels
|
14
|
+
{ ...refblocks.right1, labels: ["2"] }, // TODO add more "standard" labels
|
15
|
+
],
|
16
|
+
size: { width: bounds.width + 0.05, height: bounds.height },
|
17
|
+
center: { x: bounds.centerX, y: bounds.centerY },
|
18
|
+
})
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import { defineSymbol } from "drawing/defineSymbol"
|
2
|
+
import svgJson from "assets/symbols-svg-json/varistor.json"
|
3
|
+
|
4
|
+
const { paths, texts, bounds, refblocks } = svgJson
|
5
|
+
|
6
|
+
export default defineSymbol({
|
7
|
+
primitives: [
|
8
|
+
...Object.values(paths),
|
9
|
+
{ ...texts.top1, anchor: "middle_left" },
|
10
|
+
{ ...texts.bottom1, anchor: "middle_right" },
|
11
|
+
] as any,
|
12
|
+
ports: [
|
13
|
+
{
|
14
|
+
...refblocks.left1,
|
15
|
+
labels: ["1", "-"],
|
16
|
+
},
|
17
|
+
{
|
18
|
+
...refblocks.right1,
|
19
|
+
labels: ["2", "+"],
|
20
|
+
},
|
21
|
+
],
|
22
|
+
size: { width: bounds.width, height: bounds.height }, //{ width: 1, height: 0.24 },
|
23
|
+
center: { x: bounds.centerX, y: bounds.centerY },
|
24
|
+
})
|
@@ -0,0 +1,187 @@
|
|
1
|
+
{
|
2
|
+
"name": "g",
|
3
|
+
"type": "element",
|
4
|
+
"value": "",
|
5
|
+
"parent": null,
|
6
|
+
"attributes": {
|
7
|
+
"id": "boxresistor",
|
8
|
+
"transform": "rotate(90,-72.654678,2.0374476)",
|
9
|
+
"inkscape:label": "boxresistor"
|
10
|
+
},
|
11
|
+
"children": [
|
12
|
+
{
|
13
|
+
"name": "title",
|
14
|
+
"type": "element",
|
15
|
+
"value": "",
|
16
|
+
"parent": null,
|
17
|
+
"attributes": {
|
18
|
+
"id": "title1"
|
19
|
+
},
|
20
|
+
"children": [
|
21
|
+
{
|
22
|
+
"name": "",
|
23
|
+
"type": "text",
|
24
|
+
"value": "Resistor",
|
25
|
+
"parent": null,
|
26
|
+
"attributes": {},
|
27
|
+
"children": []
|
28
|
+
}
|
29
|
+
]
|
30
|
+
},
|
31
|
+
{
|
32
|
+
"name": "path",
|
33
|
+
"type": "element",
|
34
|
+
"value": "",
|
35
|
+
"parent": null,
|
36
|
+
"attributes": {
|
37
|
+
"style": "fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:round;stroke-linejoin:miter;stroke-opacity:1",
|
38
|
+
"d": "M 30.427082,-90.614597 V -93.26043",
|
39
|
+
"id": "path1",
|
40
|
+
"inkscape:connector-curvature": "0"
|
41
|
+
},
|
42
|
+
"children": []
|
43
|
+
},
|
44
|
+
{
|
45
|
+
"name": "path",
|
46
|
+
"type": "element",
|
47
|
+
"value": "",
|
48
|
+
"parent": null,
|
49
|
+
"attributes": {
|
50
|
+
"style": "fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:round;stroke-linejoin:miter;stroke-opacity:1",
|
51
|
+
"d": "m 30.427082,-98.552096 v -2.645834",
|
52
|
+
"id": "path2",
|
53
|
+
"inkscape:connector-curvature": "0"
|
54
|
+
},
|
55
|
+
"children": []
|
56
|
+
},
|
57
|
+
{
|
58
|
+
"name": "path",
|
59
|
+
"type": "element",
|
60
|
+
"value": "",
|
61
|
+
"parent": null,
|
62
|
+
"attributes": {
|
63
|
+
"style": "fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1",
|
64
|
+
"d": "m 29.104165,-95.906262 v -2.645833 h 2.645834 v 5.291667 h -2.645834 v -2.645834",
|
65
|
+
"id": "path3",
|
66
|
+
"inkscape:connector-curvature": "0"
|
67
|
+
},
|
68
|
+
"children": []
|
69
|
+
},
|
70
|
+
{
|
71
|
+
"name": "text",
|
72
|
+
"type": "element",
|
73
|
+
"value": "",
|
74
|
+
"parent": null,
|
75
|
+
"attributes": {
|
76
|
+
"xml:space": "preserve",
|
77
|
+
"style": "font-size:1.41111px;text-align:center;text-anchor:middle;fill:#000000;stroke-width:0.264583",
|
78
|
+
"x": "95.718857",
|
79
|
+
"y": "28.388716",
|
80
|
+
"id": "text14-0-6",
|
81
|
+
"transform": "rotate(-90)"
|
82
|
+
},
|
83
|
+
"children": [
|
84
|
+
{
|
85
|
+
"name": "tspan",
|
86
|
+
"type": "element",
|
87
|
+
"value": "",
|
88
|
+
"parent": null,
|
89
|
+
"attributes": {
|
90
|
+
"sodipodi:role": "line",
|
91
|
+
"id": "tspan14-0-1",
|
92
|
+
"style": "font-size:1.41111px;text-align:center;text-anchor:middle;stroke-width:0.264583",
|
93
|
+
"x": "95.718857",
|
94
|
+
"y": "28.388716"
|
95
|
+
},
|
96
|
+
"children": [
|
97
|
+
{
|
98
|
+
"name": "",
|
99
|
+
"type": "text",
|
100
|
+
"value": "{REF}",
|
101
|
+
"parent": null,
|
102
|
+
"attributes": {},
|
103
|
+
"children": []
|
104
|
+
}
|
105
|
+
]
|
106
|
+
}
|
107
|
+
]
|
108
|
+
},
|
109
|
+
{
|
110
|
+
"name": "text",
|
111
|
+
"type": "element",
|
112
|
+
"value": "",
|
113
|
+
"parent": null,
|
114
|
+
"attributes": {
|
115
|
+
"xml:space": "preserve",
|
116
|
+
"style": "font-size:1.41111px;text-align:center;text-anchor:middle;fill:#000000;stroke-width:0.264583",
|
117
|
+
"x": "95.728477",
|
118
|
+
"y": "33.388676",
|
119
|
+
"id": "text14-0-4-4",
|
120
|
+
"transform": "rotate(-90)"
|
121
|
+
},
|
122
|
+
"children": [
|
123
|
+
{
|
124
|
+
"name": "tspan",
|
125
|
+
"type": "element",
|
126
|
+
"value": "",
|
127
|
+
"parent": null,
|
128
|
+
"attributes": {
|
129
|
+
"sodipodi:role": "line",
|
130
|
+
"id": "tspan14-0-9-0",
|
131
|
+
"style": "font-size:1.41111px;text-align:center;text-anchor:middle;stroke-width:0.264583",
|
132
|
+
"x": "95.728477",
|
133
|
+
"y": "33.388676"
|
134
|
+
},
|
135
|
+
"children": [
|
136
|
+
{
|
137
|
+
"name": "",
|
138
|
+
"type": "text",
|
139
|
+
"value": "{VAL}",
|
140
|
+
"parent": null,
|
141
|
+
"attributes": {},
|
142
|
+
"children": []
|
143
|
+
}
|
144
|
+
]
|
145
|
+
}
|
146
|
+
]
|
147
|
+
},
|
148
|
+
{
|
149
|
+
"name": "title",
|
150
|
+
"type": "element",
|
151
|
+
"value": "",
|
152
|
+
"parent": null,
|
153
|
+
"attributes": {
|
154
|
+
"id": "title3"
|
155
|
+
},
|
156
|
+
"children": [
|
157
|
+
{
|
158
|
+
"name": "",
|
159
|
+
"type": "text",
|
160
|
+
"value": "Resistor",
|
161
|
+
"parent": null,
|
162
|
+
"attributes": {},
|
163
|
+
"children": []
|
164
|
+
}
|
165
|
+
]
|
166
|
+
},
|
167
|
+
{
|
168
|
+
"name": "title",
|
169
|
+
"type": "element",
|
170
|
+
"value": "",
|
171
|
+
"parent": null,
|
172
|
+
"attributes": {
|
173
|
+
"id": "title4"
|
174
|
+
},
|
175
|
+
"children": [
|
176
|
+
{
|
177
|
+
"name": "",
|
178
|
+
"type": "text",
|
179
|
+
"value": "Resistor",
|
180
|
+
"parent": null,
|
181
|
+
"attributes": {},
|
182
|
+
"children": []
|
183
|
+
}
|
184
|
+
]
|
185
|
+
}
|
186
|
+
]
|
187
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
{
|
2
|
+
"name": "g",
|
3
|
+
"type": "element",
|
4
|
+
"value": "",
|
5
|
+
"parent": null,
|
6
|
+
"attributes": {
|
7
|
+
"id": "testshape",
|
8
|
+
"style": "fill:none;stroke:#000000;stroke-opacity:1",
|
9
|
+
"transform": "translate(0.45366488,0.38885561)"
|
10
|
+
},
|
11
|
+
"children": [
|
12
|
+
{
|
13
|
+
"name": "path",
|
14
|
+
"type": "element",
|
15
|
+
"value": "",
|
16
|
+
"parent": null,
|
17
|
+
"attributes": {
|
18
|
+
"style": "opacity:1;fill:none;stroke:#000000;stroke-width:0.264583;stroke-opacity:1",
|
19
|
+
"d": "m 21.331058,95.261238 1.282194,-3.817442 4.953934,0.582816",
|
20
|
+
"id": "path207"
|
21
|
+
},
|
22
|
+
"children": []
|
23
|
+
}
|
24
|
+
]
|
25
|
+
}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import { expect, it } from "bun:test"
|
2
|
+
import { svgPathToPoints } from "drawing/svgPathToPoints"
|
3
|
+
import { getBoundsOfSvgJson } from "drawing/getBoundsOfSvgJson"
|
4
|
+
import testShapeSvgJson from "./assets/testshape-untransformed.json"
|
5
|
+
import boxResistorSvgJson from "./assets/boxresistor-untransformed.json"
|
6
|
+
import {
|
7
|
+
applyGroupTransformsToChildren,
|
8
|
+
transformPath,
|
9
|
+
} from "../scripts/lib/applyGroupTransformsToChildren"
|
10
|
+
import { identity, translate } from "transformation-matrix"
|
11
|
+
|
12
|
+
it("applies group transforms to children", () => {
|
13
|
+
const bounds1 = getBoundsOfSvgJson(testShapeSvgJson as any)
|
14
|
+
const result = applyGroupTransformsToChildren(testShapeSvgJson)
|
15
|
+
const bounds2 = getBoundsOfSvgJson(result as any)
|
16
|
+
expect(bounds2.centerX).not.toEqual(bounds1.centerX)
|
17
|
+
})
|
18
|
+
|
19
|
+
it("should transform V properly", () => {
|
20
|
+
const transformed = transformPath("M1,2 V3", translate(1, 2))
|
21
|
+
expect(transformed).toEqual("M2,4 L2,5")
|
22
|
+
})
|
23
|
+
|
24
|
+
it("should load V path directives properly", () => {
|
25
|
+
const result = applyGroupTransformsToChildren(boxResistorSvgJson as any)
|
26
|
+
expect(result.children[1].attributes.d).toEqual(
|
27
|
+
"M19.997366600000007,105.11920759999998 L22.643199600000003,105.11920759999998",
|
28
|
+
)
|
29
|
+
})
|
package/tsconfig.json
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
{
|
2
|
+
"compilerOptions": {
|
3
|
+
// Enable latest features
|
4
|
+
"lib": ["ESNext", "DOM"],
|
5
|
+
"target": "ESNext",
|
6
|
+
"module": "ESNext",
|
7
|
+
"moduleDetection": "force",
|
8
|
+
"jsx": "react-jsx",
|
9
|
+
"allowJs": true,
|
10
|
+
"baseUrl": ".",
|
11
|
+
|
12
|
+
// Bundler mode
|
13
|
+
"moduleResolution": "bundler",
|
14
|
+
"allowImportingTsExtensions": true,
|
15
|
+
"verbatimModuleSyntax": false,
|
16
|
+
"noEmit": true,
|
17
|
+
|
18
|
+
// Best practices
|
19
|
+
"strict": true,
|
20
|
+
"skipLibCheck": true,
|
21
|
+
"noFallthroughCasesInSwitch": true,
|
22
|
+
|
23
|
+
// Some stricter flags (disabled by default)
|
24
|
+
"noUnusedLocals": false,
|
25
|
+
"noUnusedParameters": false,
|
26
|
+
"noPropertyAccessFromIndexSignature": false
|
27
|
+
}
|
28
|
+
}
|