schematic-symbols 0.0.100 → 0.0.101
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.
@@ -0,0 +1,91 @@
|
|
1
|
+
import { NinePointAnchor, SchSymbol } from "drawing/types"
|
2
|
+
import { rotateRightFacingSymbol } from "drawing/rotateSymbol"
|
3
|
+
|
4
|
+
interface ModifySymbolBuilder {
|
5
|
+
changeTextAnchor(
|
6
|
+
text: "{REF}" | "{VAL}" | string,
|
7
|
+
newAnchor: NinePointAnchor,
|
8
|
+
): ModifySymbolBuilder
|
9
|
+
rotateRightFacingSymbol(
|
10
|
+
newOrientation: "up" | "down" | "left" | "right",
|
11
|
+
): ModifySymbolBuilder
|
12
|
+
labelPort(currentLabel: string, newLabels: string[]): ModifySymbolBuilder
|
13
|
+
build(): SchSymbol
|
14
|
+
}
|
15
|
+
|
16
|
+
class SymbolModifier implements ModifySymbolBuilder {
|
17
|
+
private symbol: SchSymbol
|
18
|
+
|
19
|
+
constructor(symbol: SchSymbol) {
|
20
|
+
this.symbol = JSON.parse(JSON.stringify(symbol))
|
21
|
+
}
|
22
|
+
|
23
|
+
changeTextAnchor(
|
24
|
+
text: "{REF}" | "{VAL}" | string,
|
25
|
+
newAnchor: NinePointAnchor,
|
26
|
+
): ModifySymbolBuilder {
|
27
|
+
this.symbol = {
|
28
|
+
...this.symbol,
|
29
|
+
primitives: this.symbol.primitives.map((primitive) => {
|
30
|
+
if (primitive.type === "text" && primitive.text === text) {
|
31
|
+
return {
|
32
|
+
...primitive,
|
33
|
+
anchor: newAnchor,
|
34
|
+
}
|
35
|
+
}
|
36
|
+
return primitive
|
37
|
+
}),
|
38
|
+
}
|
39
|
+
return this
|
40
|
+
}
|
41
|
+
|
42
|
+
labelPort(currentLabel: string, newLabels: string[]): ModifySymbolBuilder {
|
43
|
+
this.symbol = {
|
44
|
+
...this.symbol,
|
45
|
+
ports: this.symbol.ports.map((port) => {
|
46
|
+
return port.labels.includes(currentLabel)
|
47
|
+
? { ...port, labels: newLabels }
|
48
|
+
: port
|
49
|
+
}),
|
50
|
+
}
|
51
|
+
return this
|
52
|
+
}
|
53
|
+
|
54
|
+
rotateRightFacingSymbol(
|
55
|
+
newOrientation: "up" | "down" | "left" | "right",
|
56
|
+
): ModifySymbolBuilder {
|
57
|
+
this.symbol = rotateRightFacingSymbol(this.symbol, {
|
58
|
+
newOrientation,
|
59
|
+
})
|
60
|
+
return this
|
61
|
+
}
|
62
|
+
|
63
|
+
build(): SchSymbol {
|
64
|
+
return this.symbol
|
65
|
+
}
|
66
|
+
}
|
67
|
+
|
68
|
+
export const modifySymbol = (symbol: any): ModifySymbolBuilder => {
|
69
|
+
return new SymbolModifier({
|
70
|
+
...symbol,
|
71
|
+
primitives: symbol.primitives ?? [
|
72
|
+
...Object.values(symbol.paths ?? {}),
|
73
|
+
...Object.values(symbol.texts ?? {}),
|
74
|
+
...Object.values(symbol.circles ?? {}),
|
75
|
+
...Object.values(symbol.rects ?? {}),
|
76
|
+
],
|
77
|
+
ports:
|
78
|
+
symbol.ports ??
|
79
|
+
Object.entries(symbol.refblocks).flatMap(([key, refblock]) => {
|
80
|
+
return [{ ...(refblock as object), labels: [key] }]
|
81
|
+
}),
|
82
|
+
center: symbol.center ?? {
|
83
|
+
x: symbol.bounds.centerX,
|
84
|
+
y: symbol.bounds.centerY,
|
85
|
+
},
|
86
|
+
size: symbol.size ?? {
|
87
|
+
width: symbol.bounds.width,
|
88
|
+
height: symbol.bounds.height,
|
89
|
+
},
|
90
|
+
})
|
91
|
+
}
|
package/package.json
CHANGED
package/symbols/diode_right.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { defineSymbol } from "drawing/defineSymbol"
|
2
2
|
import svgJson from "assets/generated/diode.json"
|
3
|
-
import { modifySymbol } from "
|
3
|
+
import { modifySymbol } from "drawing/modify-symbol/modify-symbol"
|
4
4
|
|
5
5
|
export default modifySymbol(svgJson)
|
6
6
|
.labelPort("left1", ["1", "pos"])
|
package/symbols/ground_vert.ts
CHANGED
@@ -2,6 +2,6 @@ import { defineSymbol } from "drawing/defineSymbol"
|
|
2
2
|
import svgJson from "assets/generated/ground.json"
|
3
3
|
import { Primitive } from "drawing/types"
|
4
4
|
import groundHorz from "./ground_horz"
|
5
|
-
import { modifySymbol } from "
|
5
|
+
import { modifySymbol } from "drawing/modify-symbol/modify-symbol"
|
6
6
|
|
7
7
|
export default modifySymbol(groundHorz).rotateRightFacingSymbol("down").build()
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { defineSymbol } from "drawing/defineSymbol"
|
2
2
|
import svgJson from "assets/generated/schottky_diode.json"
|
3
|
-
import { modifySymbol } from "
|
3
|
+
import { modifySymbol } from "drawing/modify-symbol/modify-symbol"
|
4
4
|
|
5
5
|
export default modifySymbol(svgJson)
|
6
6
|
.labelPort("left1", ["1", "pos"])
|