schematic-symbols 0.0.35 → 0.0.37
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 +11 -1
- package/dist/index.js +409 -196
- package/dist/index.js.map +1 -1
- package/drawing/typeguards.ts +155 -0
- package/package.json +3 -3
- package/symbols/ac_voltmeter_horz.ts +31 -0
- package/symbols/ac_voltmeter_vert.ts +26 -0
@@ -0,0 +1,155 @@
|
|
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/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "schematic-symbols",
|
3
3
|
"main": "./dist/index.js",
|
4
|
-
"version": "0.0.
|
4
|
+
"version": "0.0.37",
|
5
5
|
"type": "module",
|
6
6
|
"files": [
|
7
7
|
"dist",
|
@@ -17,10 +17,10 @@
|
|
17
17
|
"generate:all": "bun run scripts/generate-symbols-from-asset-svgs.ts && bun run format",
|
18
18
|
"format:check": "bunx biome format",
|
19
19
|
"format": "bunx biome format . --write",
|
20
|
-
"vercel-build": "bun run ./scripts/build.ts"
|
20
|
+
"vercel-build": "bun run build && bun run ./scripts/build.ts"
|
21
21
|
},
|
22
22
|
"devDependencies": {
|
23
|
-
"@biomejs/biome": "^1.9.
|
23
|
+
"@biomejs/biome": "^1.9.3",
|
24
24
|
"@types/bun": "latest",
|
25
25
|
"@types/prompts": "^2.4.9",
|
26
26
|
"@types/svg-path-parser": "^1.1.6",
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import { defineSymbol } from "drawing/defineSymbol"
|
2
|
+
import svgJson from "assets/generated/ac_voltmeter.json"
|
3
|
+
|
4
|
+
const { paths, bounds, refblocks, circles } = svgJson
|
5
|
+
|
6
|
+
export default defineSymbol({
|
7
|
+
primitives: [
|
8
|
+
...Object.values(paths),
|
9
|
+
...Object.values(circles),
|
10
|
+
{
|
11
|
+
type: "text",
|
12
|
+
text: "{REF}",
|
13
|
+
x: 0,
|
14
|
+
y: -0.3594553499999995,
|
15
|
+
anchor: "middle_bottom",
|
16
|
+
},
|
17
|
+
{
|
18
|
+
type: "text",
|
19
|
+
text: "{VAL}",
|
20
|
+
x: 0,
|
21
|
+
y: 0.35,
|
22
|
+
anchor: "middle_top",
|
23
|
+
},
|
24
|
+
] as any,
|
25
|
+
ports: [
|
26
|
+
{ ...refblocks.left1, labels: ["1"] }, // TODO add more "standard" labels
|
27
|
+
{ ...refblocks.right1, labels: ["2"] }, // TODO add more "standard" labels
|
28
|
+
],
|
29
|
+
size: { width: bounds.width, height: bounds.height },
|
30
|
+
center: { x: bounds.centerX, y: bounds.centerY },
|
31
|
+
})
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { rotateSymbol } from "drawing/rotateSymbol"
|
2
|
+
import dc_voltmeter_horz from "./ac_voltmeter_horz"
|
3
|
+
import { Primitive } from "drawing/types"
|
4
|
+
|
5
|
+
const {
|
6
|
+
2: letter,
|
7
|
+
3: path1,
|
8
|
+
4: path2,
|
9
|
+
5: path3,
|
10
|
+
6: path4,
|
11
|
+
...rest
|
12
|
+
} = dc_voltmeter_horz.primitives
|
13
|
+
|
14
|
+
function isPrimitive(value: any): value is Primitive {
|
15
|
+
return typeof value === "object"
|
16
|
+
}
|
17
|
+
|
18
|
+
const rotatedSymbol = rotateSymbol({
|
19
|
+
...dc_voltmeter_horz,
|
20
|
+
primitives: Object.values(rest).filter(isPrimitive),
|
21
|
+
})
|
22
|
+
|
23
|
+
export default {
|
24
|
+
...rotatedSymbol,
|
25
|
+
primitives: [...rotatedSymbol.primitives, letter, path1, path2, path3, path4],
|
26
|
+
}
|