@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/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stable public entry point for the `schemd` server-side compiler.
|
|
3
|
+
*
|
|
4
|
+
* All runtime exports are dependency-free. The Marked integration imports
|
|
5
|
+
* Marked contracts as types only, so applications pay for no Markdown runtime
|
|
6
|
+
* unless they already provide one at the host boundary.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
export { parseSchematic, parseSchematicColor, parseSchematicFence } from './parser.js';
|
|
11
|
+
export { renderSchematic } from './renderer.js';
|
|
12
|
+
export { schematicMarkedExtension } from './marked-extension.js';
|
|
13
|
+
export { mathLabelGlyphLength, mathLabelText, parseMathLabel, renderMathLabelTspans, type MathLabelSegment, type MathLabelSegmentKind } from './math-label.js';
|
|
14
|
+
export { MAX_SCHEMATIC_COMPONENTS, MAX_SCHEMATIC_CONNECTIONS, MAX_SCHEMATIC_SOURCE_CHARACTERS, MAX_SCHEMATIC_SVG_OUTPUT_BYTES, SCHEMATIC_LIMITS } from './limits.js';
|
|
15
|
+
export { classicalGateHeight, componentObstacleRectangle, componentRectangle, componentTextAnchors, distributedCoordinate, enumerateComponentPorts, positionIcPin, PORT_HOTSPOT_RADIUS, resolvePortPoint, routeConnections, routeConnection, SCHEMATIC_BRIDGE_RADIUS, SCHEMATIC_OBSTACLE_CLEARANCE, validateDocumentGeometry, type RoutedConnection, type ComponentTextAnchors, type ComponentPort, type IcPinSide, type SchematicRectangle } from './layout.js';
|
|
16
|
+
export { ANALOG_KINDS, COMPONENT_KINDS, CLASSICAL_GATE_KINDS, DIODE_TYPES, GROUND_STYLES, PASSIVE_KINDS, QUANTUM_GATE_KINDS, SCHEMATIC_SIGNAL_MARKERS, SEMANTIC_COLORS, TRANSISTOR_TYPES, SCHEMD_OUTPUT_MODES, SchematicSyntaxError, type AnalogKind, type CompileSchematicOptions, type ClassicalGateComponent, type ClassicalGateKind, type ComponentKind, type DiodeComponent, type DiodeType, type GroundComponent, type GroundStyle, type IcComponent, type IntegratedCircuitComponent, type IntegratedCircuitPins, type PassiveComponent, type PassiveKind, type PortComponent, type SemanticColor, type SchematicBounds, type SchematicComponent, type SchematicConnection, type SchematicColor, type SchematicDocument, type SchematicEndpoint, type SchematicFence, type SchematicSignalMarker, type SchematicMarkedOptions, type SchematicPoint, type SchemdOutputMode, type TransistorComponent, type TransistorType, type QuantumGateComponent, type QuantumGateKind } from './types.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { parseSchematic, parseSchematicColor, parseSchematicFence } from './parser.js';
|
|
2
|
+
export { renderSchematic } from './renderer.js';
|
|
3
|
+
export { schematicMarkedExtension } from './marked-extension.js';
|
|
4
|
+
export { mathLabelGlyphLength, mathLabelText, parseMathLabel, renderMathLabelTspans } from './math-label.js';
|
|
5
|
+
export { MAX_SCHEMATIC_COMPONENTS, MAX_SCHEMATIC_CONNECTIONS, MAX_SCHEMATIC_SOURCE_CHARACTERS, MAX_SCHEMATIC_SVG_OUTPUT_BYTES, SCHEMATIC_LIMITS } from './limits.js';
|
|
6
|
+
export { classicalGateHeight, componentObstacleRectangle, componentRectangle, componentTextAnchors, distributedCoordinate, enumerateComponentPorts, positionIcPin, PORT_HOTSPOT_RADIUS, resolvePortPoint, routeConnections, routeConnection, SCHEMATIC_BRIDGE_RADIUS, SCHEMATIC_OBSTACLE_CLEARANCE, validateDocumentGeometry } from './layout.js';
|
|
7
|
+
export { ANALOG_KINDS, COMPONENT_KINDS, CLASSICAL_GATE_KINDS, DIODE_TYPES, GROUND_STYLES, PASSIVE_KINDS, QUANTUM_GATE_KINDS, SCHEMATIC_SIGNAL_MARKERS, SEMANTIC_COLORS, TRANSISTOR_TYPES, SCHEMD_OUTPUT_MODES, SchematicSyntaxError } from './types.js';
|
package/dist/layout.d.ts
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deterministic component geometry, terminal resolution, and wire routing.
|
|
3
|
+
*
|
|
4
|
+
* The layout pass performs bounded arithmetic directly in SVG viewBox units;
|
|
5
|
+
* it has no graph-layout dependency, mutable global state, DOM measurement, or
|
|
6
|
+
* asynchronous work. Orthogonal traces avoid expanded component AABBs and later
|
|
7
|
+
* crossings receive compact engineering bridge arcs in source order.
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
11
|
+
import { type ClassicalGateComponent, type IntegratedCircuitComponent, type SchematicComponent, type SchematicConnection, type SchematicDocument, type SchematicFence, type SchematicPoint } from './types.js';
|
|
12
|
+
/** Axis-aligned rectangle expressed in absolute schematic coordinates. */
|
|
13
|
+
export interface SchematicRectangle {
|
|
14
|
+
/** Inclusive left extent. */
|
|
15
|
+
minX: number;
|
|
16
|
+
/** Inclusive top extent. */
|
|
17
|
+
minY: number;
|
|
18
|
+
/** Inclusive right extent. */
|
|
19
|
+
maxX: number;
|
|
20
|
+
/** Inclusive bottom extent. */
|
|
21
|
+
maxY: number;
|
|
22
|
+
}
|
|
23
|
+
/** Render-ready connection path and the points used for bounds validation. */
|
|
24
|
+
export interface RoutedConnection {
|
|
25
|
+
/** Compact SVG path-data string. */
|
|
26
|
+
d: string;
|
|
27
|
+
/** At least two absolute points spanning endpoints, controls, corners, and bridge extrema. */
|
|
28
|
+
points: readonly [SchematicPoint, SchematicPoint, ...SchematicPoint[]];
|
|
29
|
+
}
|
|
30
|
+
/** External text-row baselines and fitted widths relative to a component origin. */
|
|
31
|
+
export interface ComponentTextAnchors {
|
|
32
|
+
/** Vertical designator baseline offset. */
|
|
33
|
+
designatorY: number;
|
|
34
|
+
/** Vertical human-readable label baseline offset. */
|
|
35
|
+
labelY: number;
|
|
36
|
+
/** Estimated designator width in viewBox units. */
|
|
37
|
+
designatorWidth: number;
|
|
38
|
+
/** Estimated label width after micro-math translation. */
|
|
39
|
+
labelWidth: number;
|
|
40
|
+
}
|
|
41
|
+
/** A canonical, physically rendered component terminal and its absolute SVG coordinate. */
|
|
42
|
+
export interface ComponentPort {
|
|
43
|
+
/** Canonical terminal name emitted by full-mode interaction hooks. */
|
|
44
|
+
readonly id: string;
|
|
45
|
+
/** Absolute center of the physical terminal. */
|
|
46
|
+
readonly point: SchematicPoint;
|
|
47
|
+
}
|
|
48
|
+
/** One edge of a polymorphic integrated-circuit body. */
|
|
49
|
+
export type IcPinSide = 'left' | 'right' | 'top' | 'bottom';
|
|
50
|
+
/** An eight-pixel target satisfies the minimum pointer hotspot without changing vector geometry. */
|
|
51
|
+
export declare const PORT_HOTSPOT_RADIUS = 4;
|
|
52
|
+
/** Physical clearance between an orthogonal trace and a component body. */
|
|
53
|
+
export declare const SCHEMATIC_OBSTACLE_CLEARANCE = 12;
|
|
54
|
+
/** Radius of the engineering crossover arc inserted at non-junction wire crossings. */
|
|
55
|
+
export declare const SCHEMATIC_BRIDGE_RADIUS = 5;
|
|
56
|
+
/**
|
|
57
|
+
* Evenly distribute a terminal within a centered span while preserving edge clearance.
|
|
58
|
+
*
|
|
59
|
+
* @param index - Zero-based item index.
|
|
60
|
+
* @param count - Positive number of items in the distribution.
|
|
61
|
+
* @param span - Total centered span in viewBox units.
|
|
62
|
+
* @returns Relative coordinate between negative and positive half-span.
|
|
63
|
+
*/
|
|
64
|
+
export declare function distributedCoordinate(index: number, count: number, span: number): number;
|
|
65
|
+
/**
|
|
66
|
+
* Compute a classical gate height that scales with its busiest terminal side.
|
|
67
|
+
*
|
|
68
|
+
* @param component - Validated classical gate.
|
|
69
|
+
* @returns Height in viewBox units, never smaller than 48.
|
|
70
|
+
*/
|
|
71
|
+
export declare function classicalGateHeight(component: ClassicalGateComponent): number;
|
|
72
|
+
/**
|
|
73
|
+
* Position an already-indexed IC pin in O(1), without scanning any side list.
|
|
74
|
+
*
|
|
75
|
+
* @param component - Integrated circuit owning the side list.
|
|
76
|
+
* @param side - Physical edge on which the pin is declared.
|
|
77
|
+
* @param index - Zero-based index within that edge's pin array.
|
|
78
|
+
* @returns Absolute terminal point 16 units beyond the IC body.
|
|
79
|
+
* @throws {RangeError} When `index` is non-integral or outside the selected side.
|
|
80
|
+
*/
|
|
81
|
+
export declare function positionIcPin(component: IntegratedCircuitComponent, side: IcPinSide, index: number): SchematicPoint;
|
|
82
|
+
/**
|
|
83
|
+
* Resolve a validated, named component port into absolute schematic coordinates.
|
|
84
|
+
*
|
|
85
|
+
* @param component - Component owning the previously validated terminal.
|
|
86
|
+
* @param port - Canonical name or supported alias.
|
|
87
|
+
* @returns Absolute terminal coordinate used by routing and interaction hotspots.
|
|
88
|
+
* @throws {Error} When called with an endpoint the semantic parser did not validate.
|
|
89
|
+
*/
|
|
90
|
+
export declare function resolvePortPoint(component: SchematicComponent, port: string): SchematicPoint;
|
|
91
|
+
/**
|
|
92
|
+
* Enumerate each physical terminal exactly once. Alias spellings deliberately resolve through
|
|
93
|
+
* `resolvePortPoint` but do not create duplicate interactive targets.
|
|
94
|
+
*
|
|
95
|
+
* @param component - Component whose canonical terminals should be exposed.
|
|
96
|
+
* @returns Port descriptors in stable physical/source order.
|
|
97
|
+
*/
|
|
98
|
+
export declare function enumerateComponentPorts(component: SchematicComponent): readonly ComponentPort[];
|
|
99
|
+
/**
|
|
100
|
+
* Return the AABB used by orthogonal routing, including engineering clearance.
|
|
101
|
+
*
|
|
102
|
+
* @param component - Component treated as a routing obstacle.
|
|
103
|
+
* @param clearance - Optional non-negative margin; defaults to 12 units.
|
|
104
|
+
* @returns Expanded physical-body rectangle.
|
|
105
|
+
* @throws {RangeError} For negative or non-finite clearance values.
|
|
106
|
+
*/
|
|
107
|
+
export declare function componentObstacleRectangle(component: SchematicComponent, clearance?: number): SchematicRectangle;
|
|
108
|
+
/**
|
|
109
|
+
* Calculate a deterministic line, cubic Bézier, or orthogonal trace.
|
|
110
|
+
*
|
|
111
|
+
* @param connection - Validated directed connection.
|
|
112
|
+
* @param components - Complete component map used for endpoint and obstacle lookup.
|
|
113
|
+
* @returns SVG path data plus control/corner points for later bounds checks.
|
|
114
|
+
*/
|
|
115
|
+
export declare function routeConnection(connection: SchematicConnection, components: ReadonlyMap<string, SchematicComponent>): RoutedConnection;
|
|
116
|
+
/**
|
|
117
|
+
* Route connections in source order and bridge only the later trace at a true crossing.
|
|
118
|
+
*
|
|
119
|
+
* A fixed spatial bucket bounds comparisons in typical sparse diagrams. Parallel
|
|
120
|
+
* overlaps, endpoint contacts, Bézier paths, and straight diagonal traces are not bridged.
|
|
121
|
+
*
|
|
122
|
+
* @param connections - Validated connections in deterministic source order.
|
|
123
|
+
* @param components - Complete component map.
|
|
124
|
+
* @returns Routes in the same order, with crossings applied to later orthogonal traces.
|
|
125
|
+
*/
|
|
126
|
+
export declare function routeConnections(connections: readonly SchematicConnection[], components: ReadonlyMap<string, SchematicComponent>): readonly RoutedConnection[];
|
|
127
|
+
/**
|
|
128
|
+
* Calculate external designator and label fitting metrics.
|
|
129
|
+
*
|
|
130
|
+
* @param component - Component supplying identity, label, and physical height.
|
|
131
|
+
* @returns Relative baselines and conservative width estimates.
|
|
132
|
+
*/
|
|
133
|
+
export declare function componentTextAnchors(component: SchematicComponent): ComponentTextAnchors;
|
|
134
|
+
/**
|
|
135
|
+
* Calculate complete component bounds, including text and interactive port radii.
|
|
136
|
+
*
|
|
137
|
+
* @param component - Component to measure.
|
|
138
|
+
* @returns Absolute AABB encompassing vectors, label rows, and port hotspots.
|
|
139
|
+
*/
|
|
140
|
+
export declare function componentRectangle(component: SchematicComponent): SchematicRectangle;
|
|
141
|
+
/**
|
|
142
|
+
* Validate final generated geometry after terminal distribution and wire routing.
|
|
143
|
+
*
|
|
144
|
+
* This complements lexical origin checks and prevents component stubs, dynamic
|
|
145
|
+
* IC pins, labels, bridge extrema, and routed control points from escaping the viewBox.
|
|
146
|
+
*
|
|
147
|
+
* @param document - Parsed immutable schematic document.
|
|
148
|
+
* @param fence - Intrinsic canvas contract.
|
|
149
|
+
* @throws {SchematicSyntaxError} At the originating component or connection line.
|
|
150
|
+
*/
|
|
151
|
+
export declare function validateDocumentGeometry(document: SchematicDocument, fence: SchematicFence): void;
|