schematic-symbols 0.0.11 → 0.0.13
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/LICENSE +21 -0
- package/dist/index.cjs +2129 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -1
- package/drawing/getSvg.ts +16 -10
- package/index.ts +3 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
@@ -67,6 +67,22 @@ interface SchSymbol {
|
|
67
67
|
}
|
68
68
|
type NinePointAnchor = "top_left" | "top_right" | "bottom_left" | "bottom_right" | "center" | "middle_top" | "middle_bottom" | "middle_left" | "middle_right";
|
69
69
|
|
70
|
+
declare function getInnerSvg(symbol: SchSymbol, options?: {
|
71
|
+
width?: number;
|
72
|
+
height?: number;
|
73
|
+
debug?: boolean;
|
74
|
+
}): string;
|
75
|
+
declare function getSvg(symbol: SchSymbol, options?: {
|
76
|
+
width?: number;
|
77
|
+
height?: number;
|
78
|
+
debug?: boolean;
|
79
|
+
}): string;
|
80
|
+
|
81
|
+
declare function resizeSymbol(symbol: SchSymbol, newSize: {
|
82
|
+
width?: number;
|
83
|
+
height?: number;
|
84
|
+
}): SchSymbol;
|
85
|
+
|
70
86
|
type BaseSymbolName = keyof typeof _default extends `${infer T}_${infer U}` ? `${T}` : never;
|
71
87
|
/**
|
72
88
|
* Utility for easier autocomplete:
|
@@ -76,4 +92,4 @@ type BaseSymbolName = keyof typeof _default extends `${infer T}_${infer U}` ? `$
|
|
76
92
|
*/
|
77
93
|
declare const BASE_SYMBOLS: Record<BaseSymbolName, BaseSymbolName>;
|
78
94
|
|
79
|
-
export { BASE_SYMBOLS, type BaseSymbolName, type BoxPrimitive, type CirclePrimitive, type PathPrimitive, type SchSymbol, type TextPrimitive, _default as symbols };
|
95
|
+
export { BASE_SYMBOLS, type BaseSymbolName, type BoxPrimitive, type CirclePrimitive, type PathPrimitive, type SchSymbol, type TextPrimitive, getInnerSvg, getSvg, resizeSymbol, _default as symbols };
|
package/drawing/getSvg.ts
CHANGED
@@ -79,7 +79,7 @@ function createPortElement(port: Port): string {
|
|
79
79
|
`
|
80
80
|
}
|
81
81
|
|
82
|
-
export function
|
82
|
+
export function getInnerSvg(
|
83
83
|
symbol: SchSymbol,
|
84
84
|
options: { width?: number; height?: number; debug?: boolean } = {},
|
85
85
|
): string {
|
@@ -101,6 +101,20 @@ export function getSvg(
|
|
101
101
|
}
|
102
102
|
})
|
103
103
|
|
104
|
+
const portElements = ports.map(createPortElement).join("\n ")
|
105
|
+
|
106
|
+
const centerDiamond = createDiamondElement(symbol.center)
|
107
|
+
|
108
|
+
return [svgElements.join("\n "), portElements, centerDiamond].join("\n")
|
109
|
+
}
|
110
|
+
|
111
|
+
export function getSvg(
|
112
|
+
symbol: SchSymbol,
|
113
|
+
options: { width?: number; height?: number; debug?: boolean } = {},
|
114
|
+
): string {
|
115
|
+
const { size } = symbol
|
116
|
+
const innerSvg = getInnerSvg(symbol, options)
|
117
|
+
|
104
118
|
// Use the center and the size to calculate the viewBox
|
105
119
|
const bufferMultiple = 1.1
|
106
120
|
const w = size.width * bufferMultiple
|
@@ -121,13 +135,5 @@ export function getSvg(
|
|
121
135
|
options.height = viewBox.height
|
122
136
|
}
|
123
137
|
|
124
|
-
|
125
|
-
|
126
|
-
const centerDiamond = createDiamondElement(symbol.center)
|
127
|
-
|
128
|
-
return `<svg width="${options.width}" height="${options.height}" viewBox="${viewBox.x} ${viewBox.y} ${viewBox.width} ${viewBox.height}" xmlns="http://www.w3.org/2000/svg">
|
129
|
-
${svgElements.join("\n ")}
|
130
|
-
${portElements}
|
131
|
-
${centerDiamond}
|
132
|
-
</svg>`
|
138
|
+
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>`
|
133
139
|
}
|
package/index.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import symbols from "./symbols"
|
2
|
+
|
2
3
|
export type {
|
3
4
|
SchSymbol,
|
4
5
|
BoxPrimitive,
|
@@ -6,6 +7,7 @@ export type {
|
|
6
7
|
PathPrimitive,
|
7
8
|
TextPrimitive,
|
8
9
|
} from "./drawing/types"
|
10
|
+
import { getSvg, getInnerSvg, resizeSymbol } from "./drawing"
|
9
11
|
|
10
12
|
export type BaseSymbolName =
|
11
13
|
keyof typeof symbols extends `${infer T}_${infer U}` ? `${T}` : never
|
@@ -19,4 +21,4 @@ export type BaseSymbolName =
|
|
19
21
|
export const BASE_SYMBOLS: Record<BaseSymbolName, BaseSymbolName> =
|
20
22
|
Object.fromEntries(Object.keys(symbols).map((k) => [k, k])) as any
|
21
23
|
|
22
|
-
export { symbols }
|
24
|
+
export { symbols, getSvg, getInnerSvg, resizeSymbol }
|