@schemd/core 0.1.0
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/README.md +726 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +7 -0
- package/dist/layout.d.ts +151 -0
- package/dist/layout.js +592 -0
- package/dist/limits.d.ts +31 -0
- package/dist/limits.js +25 -0
- package/dist/marked-extension.d.ts +23 -0
- package/dist/marked-extension.js +75 -0
- package/dist/math-label.d.ts +50 -0
- package/dist/math-label.js +151 -0
- package/dist/parser.d.ts +56 -0
- package/dist/parser.js +598 -0
- package/dist/renderer.d.ts +44 -0
- package/dist/renderer.js +485 -0
- package/dist/types.d.ts +248 -0
- package/dist/types.js +25 -0
- package/package.json +56 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public abstract-syntax-tree and compiler option contracts for `schemd`.
|
|
3
|
+
*
|
|
4
|
+
* The declarations in this module are deliberately data-only. They can be
|
|
5
|
+
* imported with `import type` by hosts without initializing a renderer,
|
|
6
|
+
* Markdown parser, browser API, or DOM implementation.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
/** Passive two-terminal component keywords accepted by the DSL. */
|
|
11
|
+
export declare const PASSIVE_KINDS: readonly ["resistor", "capacitor", "inductor"];
|
|
12
|
+
/** A supported passive two-terminal component keyword. */
|
|
13
|
+
export type PassiveKind = (typeof PASSIVE_KINDS)[number];
|
|
14
|
+
/** Discrete analog and boundary component keywords accepted by the DSL. */
|
|
15
|
+
export declare const ANALOG_KINDS: readonly ["diode", "transistor", "port", "ground"];
|
|
16
|
+
/** A supported discrete analog or boundary component keyword. */
|
|
17
|
+
export type AnalogKind = (typeof ANALOG_KINDS)[number];
|
|
18
|
+
/** Valid diode construction variants. */
|
|
19
|
+
export declare const DIODE_TYPES: readonly ["standard", "schottky", "zener", "led"];
|
|
20
|
+
/** A diode construction variant selected by the `type` attribute. */
|
|
21
|
+
export type DiodeType = (typeof DIODE_TYPES)[number];
|
|
22
|
+
/** Valid bipolar and field-effect transistor variants. */
|
|
23
|
+
export declare const TRANSISTOR_TYPES: readonly ["npn", "pnp", "nmos", "pmos"];
|
|
24
|
+
/** A transistor variant selected by the `type` attribute. */
|
|
25
|
+
export type TransistorType = (typeof TRANSISTOR_TYPES)[number];
|
|
26
|
+
/** Valid electrical ground symbol styles. */
|
|
27
|
+
export declare const GROUND_STYLES: readonly ["chassis", "earth", "signal"];
|
|
28
|
+
/** A ground symbol style selected by the `style` attribute. */
|
|
29
|
+
export type GroundStyle = (typeof GROUND_STYLES)[number];
|
|
30
|
+
/** Classical logic gate keywords supported by the vector renderer. */
|
|
31
|
+
export declare const CLASSICAL_GATE_KINDS: readonly ["nand", "nor", "xor", "and", "or", "not"];
|
|
32
|
+
/** A supported classical logic gate keyword. */
|
|
33
|
+
export type ClassicalGateKind = (typeof CLASSICAL_GATE_KINDS)[number];
|
|
34
|
+
/** Native and polymorphic quantum operator keywords. */
|
|
35
|
+
export declare const QUANTUM_GATE_KINDS: readonly ["hadamard", "cnot", "qgate"];
|
|
36
|
+
/** A supported native or polymorphic quantum gate keyword. */
|
|
37
|
+
export type QuantumGateKind = (typeof QUANTUM_GATE_KINDS)[number];
|
|
38
|
+
/** Complete, collision-free component keyword registry. */
|
|
39
|
+
export declare const COMPONENT_KINDS: readonly ["resistor", "capacitor", "inductor", "diode", "transistor", "port", "ground", "nand", "nor", "xor", "and", "or", "not", "hadamard", "cnot", "qgate", "ic"];
|
|
40
|
+
/** Any component keyword that can begin a declaration. */
|
|
41
|
+
export type ComponentKind = (typeof COMPONENT_KINDS)[number];
|
|
42
|
+
/** Built-in semantic color tokens that hosts can theme through CSS. */
|
|
43
|
+
export declare const SEMANTIC_COLORS: readonly ["amber", "blue", "cyan", "purple", "slate", "emerald"];
|
|
44
|
+
/** A built-in semantic color token. */
|
|
45
|
+
export type SemanticColor = (typeof SEMANTIC_COLORS)[number];
|
|
46
|
+
/**
|
|
47
|
+
* Sanitized color representation produced by the lexer.
|
|
48
|
+
*
|
|
49
|
+
* `token` values become stable theme classes, `css` values are validated CSS
|
|
50
|
+
* color literals, and `alias` values resolve through a host-provided custom
|
|
51
|
+
* property rather than being emitted as arbitrary markup.
|
|
52
|
+
*/
|
|
53
|
+
export type SchematicColor = {
|
|
54
|
+
kind: 'token';
|
|
55
|
+
value: SemanticColor;
|
|
56
|
+
} | {
|
|
57
|
+
kind: 'css';
|
|
58
|
+
value: string;
|
|
59
|
+
} | {
|
|
60
|
+
kind: 'alias';
|
|
61
|
+
value: string;
|
|
62
|
+
};
|
|
63
|
+
/** Intrinsic SVG canvas dimensions declared by a `schemd` fence. */
|
|
64
|
+
export interface SchematicBounds {
|
|
65
|
+
/** Horizontal viewBox extent in coordinate units. */
|
|
66
|
+
width: number;
|
|
67
|
+
/** Vertical viewBox extent in coordinate units. */
|
|
68
|
+
height: number;
|
|
69
|
+
}
|
|
70
|
+
/** Validated metadata parsed from a fenced `schemd` declaration. */
|
|
71
|
+
export interface SchematicFence {
|
|
72
|
+
/** Static dimensions used to reserve layout space before browser paint. */
|
|
73
|
+
bounds: SchematicBounds;
|
|
74
|
+
/** Accessible diagram title, supplied explicitly or by the host default. */
|
|
75
|
+
title: string;
|
|
76
|
+
}
|
|
77
|
+
/** Absolute point in the declared schematic coordinate system. */
|
|
78
|
+
export interface SchematicPoint {
|
|
79
|
+
/** Horizontal coordinate. */
|
|
80
|
+
x: number;
|
|
81
|
+
/** Vertical coordinate. */
|
|
82
|
+
y: number;
|
|
83
|
+
}
|
|
84
|
+
/** Shared immutable source metadata for every parsed component. */
|
|
85
|
+
interface ComponentBase extends SchematicPoint {
|
|
86
|
+
/** Document-unique component identifier used by connection endpoints. */
|
|
87
|
+
id: string;
|
|
88
|
+
/** Human-readable label, optionally containing schemd micro-math syntax. */
|
|
89
|
+
label: string;
|
|
90
|
+
/** Sanitized semantic or custom vector color. */
|
|
91
|
+
color: SchematicColor;
|
|
92
|
+
/** One-based source line used for deterministic diagnostics. */
|
|
93
|
+
line: number;
|
|
94
|
+
}
|
|
95
|
+
/** Parsed resistor, capacitor, or inductor component. */
|
|
96
|
+
export interface PassiveComponent extends ComponentBase {
|
|
97
|
+
/** Specific two-terminal passive kind. */
|
|
98
|
+
kind: PassiveKind;
|
|
99
|
+
}
|
|
100
|
+
/** Parsed diode with its selected physical symbol variant. */
|
|
101
|
+
export interface DiodeComponent extends ComponentBase {
|
|
102
|
+
/** Discriminant for diode components. */
|
|
103
|
+
kind: 'diode';
|
|
104
|
+
/** Standard, Schottky, Zener, or LED vector treatment. */
|
|
105
|
+
diodeType: DiodeType;
|
|
106
|
+
}
|
|
107
|
+
/** Parsed bipolar or field-effect transistor. */
|
|
108
|
+
export interface TransistorComponent extends ComponentBase {
|
|
109
|
+
/** Discriminant for transistor components. */
|
|
110
|
+
kind: 'transistor';
|
|
111
|
+
/** Electrical device family and polarity. */
|
|
112
|
+
transistorType: TransistorType;
|
|
113
|
+
}
|
|
114
|
+
/** Parsed system-boundary input/output terminal. */
|
|
115
|
+
export interface PortComponent extends ComponentBase {
|
|
116
|
+
/** Discriminant for boundary ports. */
|
|
117
|
+
kind: 'port';
|
|
118
|
+
}
|
|
119
|
+
/** Parsed zero-volt reference symbol. */
|
|
120
|
+
export interface GroundComponent extends ComponentBase {
|
|
121
|
+
/** Discriminant for ground references. */
|
|
122
|
+
kind: 'ground';
|
|
123
|
+
/** Chassis, earth, or signal-ground visual form. */
|
|
124
|
+
groundStyle: GroundStyle;
|
|
125
|
+
}
|
|
126
|
+
/** Parsed IEEE- or IEC-style classical logic gate. */
|
|
127
|
+
export interface ClassicalGateComponent extends ComponentBase {
|
|
128
|
+
/** Logic operation represented by the gate. */
|
|
129
|
+
kind: ClassicalGateKind;
|
|
130
|
+
/** Validated number of addressable input pins, from 1 through 32. */
|
|
131
|
+
inputs: number;
|
|
132
|
+
/** Validated number of addressable output pins, from 1 through 32. */
|
|
133
|
+
outputs: number;
|
|
134
|
+
/** Symbol convention used when generating the gate contour. */
|
|
135
|
+
standard: 'ieee' | 'iec';
|
|
136
|
+
}
|
|
137
|
+
/** Parsed native or user-labelled quantum operator. */
|
|
138
|
+
export interface QuantumGateComponent extends ComponentBase {
|
|
139
|
+
/** Quantum operator family. */
|
|
140
|
+
kind: QuantumGateKind;
|
|
141
|
+
/** Optional operator parameter rendered through the micro-math pipeline. */
|
|
142
|
+
parameter?: string;
|
|
143
|
+
/** Optional compact matrix description. */
|
|
144
|
+
matrix?: string;
|
|
145
|
+
/** Optional phase expression. */
|
|
146
|
+
phase?: string;
|
|
147
|
+
}
|
|
148
|
+
/** Pin names registered on each side of a polymorphic integrated circuit. */
|
|
149
|
+
export interface IntegratedCircuitPins {
|
|
150
|
+
/** Pins distributed from top to bottom on the left edge. */
|
|
151
|
+
left: readonly string[];
|
|
152
|
+
/** Pins distributed from top to bottom on the right edge. */
|
|
153
|
+
right: readonly string[];
|
|
154
|
+
/** Pins distributed from left to right on the top edge. */
|
|
155
|
+
top: readonly string[];
|
|
156
|
+
/** Pins distributed from left to right on the bottom edge. */
|
|
157
|
+
bottom: readonly string[];
|
|
158
|
+
}
|
|
159
|
+
/** Parsed custom multi-terminal integrated-circuit block. */
|
|
160
|
+
export interface IcComponent extends ComponentBase {
|
|
161
|
+
/** Discriminant for custom integrated circuits and architecture blocks. */
|
|
162
|
+
kind: 'ic';
|
|
163
|
+
/** Addressable, side-aware pin registry. */
|
|
164
|
+
pins: IntegratedCircuitPins;
|
|
165
|
+
/** Computed body width that preserves label and pin clearances. */
|
|
166
|
+
bodyWidth: number;
|
|
167
|
+
/** Computed body height derived from the longest pin list. */
|
|
168
|
+
bodyHeight: number;
|
|
169
|
+
}
|
|
170
|
+
/** Descriptive alias for a parsed integrated-circuit block. */
|
|
171
|
+
export type IntegratedCircuitComponent = IcComponent;
|
|
172
|
+
/** Discriminated union of every component node accepted by the renderer. */
|
|
173
|
+
export type SchematicComponent = PassiveComponent | DiodeComponent | TransistorComponent | PortComponent | GroundComponent | ClassicalGateComponent | QuantumGateComponent | IcComponent;
|
|
174
|
+
/** Address of one component terminal in a connection declaration. */
|
|
175
|
+
export interface SchematicEndpoint {
|
|
176
|
+
/** Document-local component identifier. */
|
|
177
|
+
componentId: string;
|
|
178
|
+
/** Canonicalized port name, including stable aliases such as `in` and `out`. */
|
|
179
|
+
port: string;
|
|
180
|
+
}
|
|
181
|
+
/** Validated directed signal connection between two component terminals. */
|
|
182
|
+
export interface SchematicConnection {
|
|
183
|
+
/** Signal origin. */
|
|
184
|
+
from: SchematicEndpoint;
|
|
185
|
+
/** Signal destination. */
|
|
186
|
+
to: SchematicEndpoint;
|
|
187
|
+
/** Sanitized trace color. */
|
|
188
|
+
color: SchematicColor;
|
|
189
|
+
/** Straight, cubic Bézier, or obstacle-aware orthogonal routing strategy. */
|
|
190
|
+
curve: 'line' | 'bezier' | 'ortho';
|
|
191
|
+
/** Optional marker drawn at the source terminal. */
|
|
192
|
+
markerStart: SchematicSignalMarker;
|
|
193
|
+
/** Optional marker drawn at the destination terminal. */
|
|
194
|
+
markerEnd: SchematicSignalMarker;
|
|
195
|
+
/** One-based source line used for routing diagnostics. */
|
|
196
|
+
line: number;
|
|
197
|
+
}
|
|
198
|
+
/** Frozen parser result consumed by layout and rendering passes. */
|
|
199
|
+
export interface SchematicDocument {
|
|
200
|
+
/** Components in deterministic source order. */
|
|
201
|
+
readonly components: readonly SchematicComponent[];
|
|
202
|
+
/** Connections in deterministic source order. */
|
|
203
|
+
readonly connections: readonly SchematicConnection[];
|
|
204
|
+
}
|
|
205
|
+
/** Supported SVG output budgets, ordered from smallest to most interactive. */
|
|
206
|
+
export declare const SCHEMD_OUTPUT_MODES: readonly ["default", "embedded-css", "full"];
|
|
207
|
+
/** Static, CSS-enhanced, or fully attributed SVG output mode. */
|
|
208
|
+
export type SchemdOutputMode = (typeof SCHEMD_OUTPUT_MODES)[number];
|
|
209
|
+
/** Marker primitives that can terminate or originate a signal trace. */
|
|
210
|
+
export declare const SCHEMATIC_SIGNAL_MARKERS: readonly ["none", "arrow", "dot"];
|
|
211
|
+
/** A validated connection marker selection. */
|
|
212
|
+
export type SchematicSignalMarker = (typeof SCHEMATIC_SIGNAL_MARKERS)[number];
|
|
213
|
+
/** Per-render options extending the fence's intrinsic layout contract. */
|
|
214
|
+
export interface CompileSchematicOptions extends SchematicFence {
|
|
215
|
+
/** Caller-controlled, sanitized prefix preventing duplicate SVG definition IDs. */
|
|
216
|
+
idPrefix?: string;
|
|
217
|
+
/** Markup and interaction budget for the generated SVG. */
|
|
218
|
+
mode?: SchemdOutputMode;
|
|
219
|
+
}
|
|
220
|
+
/** Configuration accepted by the type-only Marked extension factory. */
|
|
221
|
+
export interface SchematicMarkedOptions {
|
|
222
|
+
/** Accessible title used when the fence omits one. */
|
|
223
|
+
defaultTitle?: string;
|
|
224
|
+
/** Fixed output mode for every schemd fence in a Markdown pass. */
|
|
225
|
+
mode?: SchemdOutputMode;
|
|
226
|
+
/** Synchronous mode resolver for hosts with request-scoped rendering state. */
|
|
227
|
+
resolveMode?: () => SchemdOutputMode;
|
|
228
|
+
/** Optional safe fallback renderer for bounded syntax failures. */
|
|
229
|
+
onError?: (error: SchematicSyntaxError, source: string) => string;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Deterministic syntax or geometry failure with optional source location.
|
|
233
|
+
*
|
|
234
|
+
* The constructor prefixes located messages with `Line N:` exactly once so
|
|
235
|
+
* hosts can present the same diagnostic in SSR, remote previews, and tests.
|
|
236
|
+
*/
|
|
237
|
+
export declare class SchematicSyntaxError extends Error {
|
|
238
|
+
/** One-based source line when the failure maps to a DSL declaration. */
|
|
239
|
+
readonly line: number | undefined;
|
|
240
|
+
/**
|
|
241
|
+
* Create a compiler diagnostic.
|
|
242
|
+
*
|
|
243
|
+
* @param message - Human-readable failure without a line prefix.
|
|
244
|
+
* @param line - Optional one-based source line.
|
|
245
|
+
*/
|
|
246
|
+
constructor(message: string, line?: number);
|
|
247
|
+
}
|
|
248
|
+
export {};
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export const PASSIVE_KINDS = ['resistor', 'capacitor', 'inductor'];
|
|
2
|
+
export const ANALOG_KINDS = ['diode', 'transistor', 'port', 'ground'];
|
|
3
|
+
export const DIODE_TYPES = ['standard', 'schottky', 'zener', 'led'];
|
|
4
|
+
export const TRANSISTOR_TYPES = ['npn', 'pnp', 'nmos', 'pmos'];
|
|
5
|
+
export const GROUND_STYLES = ['chassis', 'earth', 'signal'];
|
|
6
|
+
export const CLASSICAL_GATE_KINDS = ['nand', 'nor', 'xor', 'and', 'or', 'not'];
|
|
7
|
+
export const QUANTUM_GATE_KINDS = ['hadamard', 'cnot', 'qgate'];
|
|
8
|
+
export const COMPONENT_KINDS = [
|
|
9
|
+
...PASSIVE_KINDS,
|
|
10
|
+
...ANALOG_KINDS,
|
|
11
|
+
...CLASSICAL_GATE_KINDS,
|
|
12
|
+
...QUANTUM_GATE_KINDS,
|
|
13
|
+
'ic'
|
|
14
|
+
];
|
|
15
|
+
export const SEMANTIC_COLORS = ['amber', 'blue', 'cyan', 'purple', 'slate', 'emerald'];
|
|
16
|
+
export const SCHEMD_OUTPUT_MODES = ['default', 'embedded-css', 'full'];
|
|
17
|
+
export const SCHEMATIC_SIGNAL_MARKERS = ['none', 'arrow', 'dot'];
|
|
18
|
+
export class SchematicSyntaxError extends Error {
|
|
19
|
+
line;
|
|
20
|
+
constructor(message, line) {
|
|
21
|
+
super(line === undefined ? message : `Line ${line}: ${message}`);
|
|
22
|
+
this.name = 'SchematicSyntaxError';
|
|
23
|
+
this.line = line;
|
|
24
|
+
}
|
|
25
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@schemd/core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Strict, bounded, server-side engineering schematic DSL compiler for Marked.",
|
|
5
|
+
"homepage": "https://johnowolabiidogun.dev/tools/schemd/docs/overview",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/Sirneij/schemd/issues"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/Sirneij/schemd.git"
|
|
12
|
+
},
|
|
13
|
+
"type": "module",
|
|
14
|
+
"sideEffects": false,
|
|
15
|
+
"browser": false,
|
|
16
|
+
"main": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"README.md"
|
|
21
|
+
],
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"import": "./dist/index.js"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "node -e \"require('node:fs').rmSync('dist',{ recursive: true, force: true })\" && tsc -p tsconfig.build.json && tsc -p tsconfig.types.json",
|
|
30
|
+
"check": "tsc -p tsconfig.json --noEmit",
|
|
31
|
+
"prepack": "npm run build",
|
|
32
|
+
"test": "vitest run",
|
|
33
|
+
"test:coverage": "vitest run --coverage"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"marked": ">=17 <19"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@vitest/coverage-v8": "^4.1.10",
|
|
40
|
+
"marked": "^18.0.6",
|
|
41
|
+
"typescript": "^6.0.3",
|
|
42
|
+
"vitest": "^4.1.10"
|
|
43
|
+
},
|
|
44
|
+
"engines": {
|
|
45
|
+
"node": ">=24"
|
|
46
|
+
},
|
|
47
|
+
"keywords": [
|
|
48
|
+
"schemd",
|
|
49
|
+
"marked",
|
|
50
|
+
"schematic",
|
|
51
|
+
"svg",
|
|
52
|
+
"compiler",
|
|
53
|
+
"engineering"
|
|
54
|
+
],
|
|
55
|
+
"license": "MIT"
|
|
56
|
+
}
|