@mica-js/document 0.0.0-stage → 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 +12 -2
- package/dist/canvas/index.d.ts +223 -0
- package/dist/canvas/index.js +570 -0
- package/dist/canvas/index.js.map +1 -0
- package/dist/errors-7cnIjhnV.js +69 -0
- package/dist/errors-7cnIjhnV.js.map +1 -0
- package/dist/index.d.ts +182 -0
- package/dist/index.js +3 -0
- package/dist/schematic/index.d.ts +931 -0
- package/dist/schematic/index.js +2845 -0
- package/dist/schematic/index.js.map +1 -0
- package/dist/type-name-B6Vkwj77.js +154 -0
- package/dist/type-name-B6Vkwj77.js.map +1 -0
- package/dist/validate-Cz-ZbbEr.js +232 -0
- package/dist/validate-Cz-ZbbEr.js.map +1 -0
- package/package.json +45 -3
|
@@ -0,0 +1,931 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Applies an edit command to a copy of `document`.
|
|
3
|
+
*
|
|
4
|
+
* @throws {SchematicError} when the command is invalid; the input document is never mutated.
|
|
5
|
+
*/
|
|
6
|
+
export declare function applySchematicCommand(document: SchematicDocument, command: SchematicCommand, options?: SchematicEditOptions): SchematicDocument;
|
|
7
|
+
|
|
8
|
+
/** Where an image / binary property value lives (#7). */
|
|
9
|
+
export declare const ASSET_MODES: readonly ["file", "inline", "store"];
|
|
10
|
+
|
|
11
|
+
/** Where an image / binary property value lives (#7). */
|
|
12
|
+
export declare type AssetMode = 'file' | 'inline' | 'store';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* `file` mode payload rules (#7): a project-root relative POSIX path that never escapes the
|
|
16
|
+
* project root and never turns into a URL.
|
|
17
|
+
*/
|
|
18
|
+
export declare function assetPathError(src: string): string | undefined;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Reference to a project asset instead of inline bytes (#7): `file` is a project-root relative
|
|
22
|
+
* POSIX path, `inline` is base64 text and `store` is a host resource identifier.
|
|
23
|
+
*/
|
|
24
|
+
export declare interface AssetReference {
|
|
25
|
+
readonly src: string;
|
|
26
|
+
readonly mode: AssetMode;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** `inline` mode payload: base64 text, so hosts decode without guessing the encoding. */
|
|
30
|
+
export declare function base64Error(src: string): string | undefined;
|
|
31
|
+
|
|
32
|
+
/** Builtin symbols recognised by the loader instead of the device registry. */
|
|
33
|
+
export declare type BuiltinSymbolKind = 'label' | 'power' | 'ground';
|
|
34
|
+
|
|
35
|
+
/** Returns the builtin kind for `builtin:label` / `builtin:power` / `builtin:ground`. */
|
|
36
|
+
export declare function builtinSymbolKind(raw: string): BuiltinSymbolKind | undefined;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Designator policy derived from the device descriptions: `<device prefix><n>`, falling back to
|
|
40
|
+
* `U` for devices that declare none.
|
|
41
|
+
*/
|
|
42
|
+
export declare function createDesignatorFactory(devices: DeviceSymbolProvider | undefined): DesignatorFactory;
|
|
43
|
+
|
|
44
|
+
export declare function createDeviceRegistry(packages?: readonly DevicePackageRegistration[]): DeviceRegistry;
|
|
45
|
+
|
|
46
|
+
export declare interface DanglingWireEnd {
|
|
47
|
+
readonly wireId: string;
|
|
48
|
+
readonly end: 'start' | 'end';
|
|
49
|
+
readonly point: Point;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Prefix used when neither the host nor the device description provides one. */
|
|
53
|
+
export declare const DEFAULT_DESIGNATOR_PREFIX = "U";
|
|
54
|
+
|
|
55
|
+
export declare const DEFAULT_GROUND_LABEL = "GND";
|
|
56
|
+
|
|
57
|
+
export declare const DEFAULT_POWER_LABEL = "VCC";
|
|
58
|
+
|
|
59
|
+
export declare const DEFAULT_TEXT_CONTENT = "\u6587\u672C";
|
|
60
|
+
|
|
61
|
+
/** Default comparison tolerance, in page units. */
|
|
62
|
+
export declare const DEFAULT_TOLERANCE = 0;
|
|
63
|
+
|
|
64
|
+
/** Default policy for providers without device data: `U1`, `U2`, … */
|
|
65
|
+
export declare const defaultDesignatorFactory: DesignatorFactory;
|
|
66
|
+
|
|
67
|
+
/** Fresh UUID v4 that no element of `kind` uses yet. */
|
|
68
|
+
export declare const defaultElementIdFactory: ElementIdFactory;
|
|
69
|
+
|
|
70
|
+
/** Net name a freshly placed symbol of `role` gets when none is given. */
|
|
71
|
+
export declare function defaultNetName(role: SymbolRole): string | undefined;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Derives nets from wires, explicit junctions and symbol connection points (#6).
|
|
75
|
+
*
|
|
76
|
+
* @throws {SchematicError} when a device cannot be resolved or a net has conflicting labels.
|
|
77
|
+
*/
|
|
78
|
+
export declare function deriveSchematicTopology(document: SchematicDocument, options?: SchematicTopologyOptions): SchematicTopology;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Picks the reference designator of a newly placed component. Hosts replace this when their
|
|
82
|
+
* naming rules go beyond the device's own prefix.
|
|
83
|
+
*/
|
|
84
|
+
export declare type DesignatorFactory = (device: string, document: SchematicDocument) => string;
|
|
85
|
+
|
|
86
|
+
/** Reference designator of a component; `undefined` for symbols that have none. */
|
|
87
|
+
export declare function designatorOf(symbol: {
|
|
88
|
+
readonly id: string;
|
|
89
|
+
readonly device: string;
|
|
90
|
+
readonly designator?: string;
|
|
91
|
+
}): string | undefined;
|
|
92
|
+
|
|
93
|
+
/** Prefix the device declares, else {@link DEFAULT_DESIGNATOR_PREFIX}. */
|
|
94
|
+
export declare function designatorPrefixOf(devices: DeviceSymbolProvider | undefined, device: string): string;
|
|
95
|
+
|
|
96
|
+
export declare type DeviceCoordinate = readonly [number, number];
|
|
97
|
+
|
|
98
|
+
export declare type DeviceGraphic = DeviceGraphicStyle & ({
|
|
99
|
+
readonly type: 'line';
|
|
100
|
+
readonly from: DeviceCoordinate;
|
|
101
|
+
readonly to: DeviceCoordinate;
|
|
102
|
+
} | {
|
|
103
|
+
readonly type: 'polyline';
|
|
104
|
+
readonly points: readonly DeviceCoordinate[];
|
|
105
|
+
readonly closed?: boolean;
|
|
106
|
+
} | {
|
|
107
|
+
readonly type: 'rect';
|
|
108
|
+
readonly x: number;
|
|
109
|
+
readonly y: number;
|
|
110
|
+
readonly width: number;
|
|
111
|
+
readonly height: number;
|
|
112
|
+
} | {
|
|
113
|
+
readonly type: 'circle';
|
|
114
|
+
readonly center: DeviceCoordinate;
|
|
115
|
+
readonly radius: number;
|
|
116
|
+
} | {
|
|
117
|
+
readonly type: 'arc';
|
|
118
|
+
readonly center: DeviceCoordinate;
|
|
119
|
+
readonly radius: number;
|
|
120
|
+
readonly startAngle: number;
|
|
121
|
+
readonly sweepAngle: number;
|
|
122
|
+
} | {
|
|
123
|
+
readonly type: 'text';
|
|
124
|
+
readonly position: DeviceCoordinate;
|
|
125
|
+
readonly text: string;
|
|
126
|
+
readonly align?: DeviceTextAlign;
|
|
127
|
+
readonly fontSize?: number;
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
export declare interface DeviceGraphicStyle {
|
|
131
|
+
readonly fill?: 'none' | 'foreground' | 'background';
|
|
132
|
+
readonly strokeWidth?: number;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export declare interface DeviceMetadata {
|
|
136
|
+
readonly kind: 'device';
|
|
137
|
+
readonly id: string;
|
|
138
|
+
readonly version: string;
|
|
139
|
+
readonly displayName: string;
|
|
140
|
+
readonly description?: string;
|
|
141
|
+
readonly license?: string;
|
|
142
|
+
readonly tags?: readonly string[];
|
|
143
|
+
readonly designatorPrefix?: string;
|
|
144
|
+
readonly properties?: Readonly<Record<string, DevicePropertyMetadata>>;
|
|
145
|
+
readonly pins?: Readonly<Record<string, DevicePinMetadata>>;
|
|
146
|
+
readonly ports?: Readonly<Record<string, DevicePortMetadata>>;
|
|
147
|
+
readonly symbol?: {
|
|
148
|
+
readonly bounds: Rect;
|
|
149
|
+
readonly graphics: readonly DeviceGraphic[];
|
|
150
|
+
readonly pins: Readonly<Record<string, {
|
|
151
|
+
readonly position: DeviceCoordinate;
|
|
152
|
+
readonly direction: 'left' | 'right' | 'up' | 'down';
|
|
153
|
+
readonly label?: DevicePinLabel;
|
|
154
|
+
}>>;
|
|
155
|
+
readonly annotations?: DeviceSymbolAnnotations;
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export declare function deviceMetadataPropertyDescriptors(metadata: DeviceMetadata): ReadonlyMap<string, PropertyDescriptor_2>;
|
|
160
|
+
|
|
161
|
+
export declare function deviceMetadataSymbol(metadata: DeviceMetadata): DeviceSymbolDefinition;
|
|
162
|
+
|
|
163
|
+
/** Package data prepared by the host from the #11 `devices` index and device descriptions. */
|
|
164
|
+
export declare interface DevicePackageRegistration {
|
|
165
|
+
readonly packageId: string;
|
|
166
|
+
readonly devices: readonly DeviceRegistrationEntry[];
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** Pin declaration subset used for symbol synthesis (see #11 / #12). */
|
|
170
|
+
export declare interface DevicePinDeclaration {
|
|
171
|
+
/** Display side; pins without a side are drawn on the left. */
|
|
172
|
+
readonly side?: PinSide;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export declare interface DevicePinLabel {
|
|
176
|
+
readonly visible: boolean;
|
|
177
|
+
readonly position?: DeviceCoordinate;
|
|
178
|
+
readonly align?: DeviceTextAlign;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export declare interface DevicePinMetadata {
|
|
182
|
+
readonly label?: string;
|
|
183
|
+
readonly description?: string;
|
|
184
|
+
readonly group?: string;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export declare interface DevicePortMetadata {
|
|
188
|
+
readonly direction: 'input' | 'output';
|
|
189
|
+
readonly type: 'boolean' | 'number' | 'string' | 'vec2d' | 'vec3d' | 'bytes' | 'bytes<rgb565>' | 'bytes<segments>';
|
|
190
|
+
readonly title?: string;
|
|
191
|
+
readonly description?: string;
|
|
192
|
+
readonly delivery?: 'level' | 'message';
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export declare type DevicePropertyEditor = {
|
|
196
|
+
readonly kind: 'number';
|
|
197
|
+
readonly min?: number;
|
|
198
|
+
readonly max?: number;
|
|
199
|
+
readonly step?: number;
|
|
200
|
+
} | {
|
|
201
|
+
readonly kind: 'text' | 'textarea' | 'checkbox' | 'file';
|
|
202
|
+
} | {
|
|
203
|
+
readonly kind: 'select';
|
|
204
|
+
readonly labels?: Readonly<Record<string, string>>;
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
export declare interface DevicePropertyMetadata {
|
|
208
|
+
readonly type: 'number' | 'boolean' | 'string' | 'enum' | 'bytes';
|
|
209
|
+
readonly required: boolean;
|
|
210
|
+
readonly nullable?: boolean;
|
|
211
|
+
readonly default?: unknown;
|
|
212
|
+
readonly enumName?: string;
|
|
213
|
+
readonly values?: readonly string[];
|
|
214
|
+
readonly title?: string;
|
|
215
|
+
readonly description?: string;
|
|
216
|
+
readonly unit?: string;
|
|
217
|
+
readonly group?: string;
|
|
218
|
+
readonly order?: number;
|
|
219
|
+
readonly editor?: DevicePropertyEditor;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export declare interface DeviceReference {
|
|
223
|
+
readonly raw: string;
|
|
224
|
+
readonly packageId: string;
|
|
225
|
+
readonly deviceId: string;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export declare interface DeviceRegisterOptions {
|
|
229
|
+
readonly replace?: boolean;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export declare interface DeviceRegistrationEntry {
|
|
233
|
+
/** Device id, unique within the package. */
|
|
234
|
+
readonly id: string;
|
|
235
|
+
/** Display name; defaults to the device id. */
|
|
236
|
+
readonly displayName?: string;
|
|
237
|
+
readonly description?: string;
|
|
238
|
+
/**
|
|
239
|
+
* Reference-designator prefix used when the device is placed (`U1`, `R3`, `DS2`, …).
|
|
240
|
+
* Falls back to `raw.designatorPrefix`, then to the global default `U`.
|
|
241
|
+
*/
|
|
242
|
+
readonly designatorPrefix?: string;
|
|
243
|
+
/** Schematic symbol; omitted when the device has no geometry yet. */
|
|
244
|
+
readonly symbol?: DeviceSymbolGeometry;
|
|
245
|
+
/** Remaining device description fields (#5 pins, #7 properties, #10 ports, ...), kept as-is. */
|
|
246
|
+
readonly raw?: Readonly<Record<string, unknown>>;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export declare interface DeviceRegistry extends DeviceSymbolProvider {
|
|
250
|
+
/** @throws {SchematicError} when the package data is invalid; nothing is registered then. */
|
|
251
|
+
registerPackage(registration: DevicePackageRegistration, options?: DeviceRegisterOptions): void;
|
|
252
|
+
resolve(reference: DeviceReference | string): ResolvedDevice | undefined;
|
|
253
|
+
listDevices(packageId?: string): readonly ResolvedDevice[];
|
|
254
|
+
/** Non-fatal diagnostics collected while registering packages (currently `device/no-symbol`). */
|
|
255
|
+
readonly diagnostics: readonly Diagnostic[];
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export declare interface DeviceSymbolAnnotations {
|
|
259
|
+
readonly designator?: {
|
|
260
|
+
readonly position: DeviceCoordinate;
|
|
261
|
+
readonly align?: DeviceTextAlign;
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
export declare interface DeviceSymbolDefinition {
|
|
266
|
+
/** Name rendered at the centre of the symbol. */
|
|
267
|
+
readonly name: string;
|
|
268
|
+
/** Pin id to pre-placement anchor coordinate in symbol space. */
|
|
269
|
+
readonly pins: Readonly<Record<string, PinAnchor>>;
|
|
270
|
+
/** Optional outline used by the editor to draw the symbol body. */
|
|
271
|
+
readonly bounds?: Rect;
|
|
272
|
+
readonly graphics?: readonly DeviceGraphic[];
|
|
273
|
+
readonly annotations?: DeviceSymbolAnnotations;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export declare interface DeviceSymbolGeometry {
|
|
277
|
+
/** Placement-independent geometry, as provided by the device description. */
|
|
278
|
+
readonly name?: string;
|
|
279
|
+
readonly pins: Readonly<Record<string, PinAnchor>>;
|
|
280
|
+
readonly bounds?: Rect;
|
|
281
|
+
readonly graphics?: readonly DeviceGraphic[];
|
|
282
|
+
readonly annotations?: DeviceSymbolAnnotations;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export declare interface DeviceSymbolProvider {
|
|
286
|
+
/** Symbol geometry; `undefined` when the device is unknown or has no geometry. */
|
|
287
|
+
getDeviceSymbol(reference: DeviceReference): DeviceSymbolDefinition | undefined;
|
|
288
|
+
/** Name rendered on the symbol: the symbol name, else the display name. `undefined` when unknown. */
|
|
289
|
+
getDeviceName(reference: DeviceReference): string | undefined;
|
|
290
|
+
/**
|
|
291
|
+
* Reference-designator prefix the device declares (`U`, `R`, `DS`, …); `undefined` when the
|
|
292
|
+
* provider does not describe one, in which case placement falls back to the global default.
|
|
293
|
+
*/
|
|
294
|
+
getDeviceDesignatorPrefix?(reference: DeviceReference): string | undefined;
|
|
295
|
+
/**
|
|
296
|
+
* Property descriptors the device declares (#7); `undefined` when the provider does not describe
|
|
297
|
+
* them, in which case property editing is restricted to structural validation only.
|
|
298
|
+
*/
|
|
299
|
+
getDevicePropertyDescriptors?(reference: DeviceReference): ReadonlyMap<string, PropertyDescriptor_2> | undefined;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
export declare type DeviceTextAlign = 'left' | 'center' | 'right';
|
|
303
|
+
|
|
304
|
+
export declare interface Diagnostic {
|
|
305
|
+
readonly severity: DiagnosticSeverity;
|
|
306
|
+
readonly code: DiagnosticCode;
|
|
307
|
+
/** Human readable English message; the `code` is the stable contract. */
|
|
308
|
+
readonly message: string;
|
|
309
|
+
/** JSON Pointer to the offending member, e.g. `/sheet/symbols/0/id`. */
|
|
310
|
+
readonly pointer?: string;
|
|
311
|
+
readonly entity?: DiagnosticEntity;
|
|
312
|
+
readonly related?: readonly DiagnosticRelated[];
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
export declare type DiagnosticCode = 'json/invalid' | 'json/not-object' | 'schema/unsupported-version' | 'schema/missing-field' | 'schema/invalid-type' | 'schema/invalid-value' | 'schema/unknown-field' | 'id/duplicate' | 'device/invalid-reference' | 'device/unresolved' | 'device/invalid-package' | 'device/duplicate-package' | 'device/reserved-namespace' | 'device/duplicate-device' | 'device/invalid-description' | 'device/unknown-pin' | 'device/no-symbol' | 'wire/invalid-points' | 'wire/not-orthogonal' | 'junction/unknown-wire' | 'junction/duplicate-wire' | 'junction/off-wire' | 'symbol/missing-net' | 'symbol/unsupported-field' | 'symbol/designator-duplicate' | 'net/naming-conflict' | 'canvas/unknown-symbol' | 'canvas/unknown-widget' | 'canvas/unknown-property' | 'canvas/unknown-port' | 'canvas/unknown-schematic' | 'canvas/unknown-target-port' | 'topic/type-mismatch' | 'type/unknown' | 'edit/unknown-entity' | 'edit/invalid-command';
|
|
316
|
+
|
|
317
|
+
export declare interface DiagnosticEntity {
|
|
318
|
+
readonly kind: 'symbol' | 'wire' | 'junction';
|
|
319
|
+
readonly id: string;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
export declare interface DiagnosticRelated {
|
|
323
|
+
readonly pointer?: string;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
export declare type DiagnosticSeverity = 'error' | 'warning';
|
|
327
|
+
|
|
328
|
+
export declare function distanceToSegment(point: Point, a: Point, b: Point): number;
|
|
329
|
+
|
|
330
|
+
export declare interface EditEffect {
|
|
331
|
+
readonly kind: 'junction-removed';
|
|
332
|
+
readonly id: string;
|
|
333
|
+
readonly reason: 'wire-removed' | 'junction-detached';
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
export declare type ElementIdFactory = (kind: ElementKind, document: SchematicDocument) => string;
|
|
337
|
+
|
|
338
|
+
export declare type ElementKind = 'symbol' | 'wire' | 'junction';
|
|
339
|
+
|
|
340
|
+
export declare function formatDeviceReference(packageId: string, deviceId: string): string;
|
|
341
|
+
|
|
342
|
+
export declare const GROUND_DEVICE = "builtin:ground";
|
|
343
|
+
|
|
344
|
+
/** Only components are annotated with a reference designator. */
|
|
345
|
+
export declare function hasDesignator(role: SymbolRole): boolean;
|
|
346
|
+
|
|
347
|
+
export declare function isAssetMode(value: unknown): value is AssetMode;
|
|
348
|
+
|
|
349
|
+
export declare function isAssetReference(value: unknown): value is AssetReference;
|
|
350
|
+
|
|
351
|
+
export declare function isBuiltinDevice(raw: string): boolean;
|
|
352
|
+
|
|
353
|
+
export declare function isLabelDevice(raw: string): boolean;
|
|
354
|
+
|
|
355
|
+
export declare function isPropertyType(value: unknown): value is PropertyType;
|
|
356
|
+
|
|
357
|
+
/** `builtin` is reserved for loader-provided symbols such as `builtin:label`. */
|
|
358
|
+
export declare function isReservedPackageId(packageId: string): boolean;
|
|
359
|
+
|
|
360
|
+
/** True for the free-standing text annotation (`builtin:text`). */
|
|
361
|
+
export declare function isTextDevice(raw: string): boolean;
|
|
362
|
+
|
|
363
|
+
export declare function isValidPackageId(packageId: string): boolean;
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* The junction sitting exactly at `point`, extended with `wireId`, so a wire that ends on an
|
|
367
|
+
* existing junction actually joins it. `undefined` when there is nothing to join.
|
|
368
|
+
*/
|
|
369
|
+
export declare function joinJunctionAt(document: SchematicDocument, wireId: string, point: Point): JunctionJoin | undefined;
|
|
370
|
+
|
|
371
|
+
export declare interface JunctionJoin {
|
|
372
|
+
readonly id: string;
|
|
373
|
+
readonly wires: readonly string[];
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
export declare interface JunctionRelease {
|
|
377
|
+
readonly id: string;
|
|
378
|
+
/** Remaining participating wires; `undefined` means the junction has to be removed. */
|
|
379
|
+
readonly wires: readonly string[] | undefined;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
export declare interface JunctionReleaseOptions {
|
|
383
|
+
readonly tolerance?: number;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
export declare const LABEL_DEVICE = "builtin:label";
|
|
387
|
+
|
|
388
|
+
export declare interface LoadedSchematic {
|
|
389
|
+
readonly document: SchematicDocument;
|
|
390
|
+
readonly topology: SchematicTopology;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/** Parses a schematic and derives its topology. @throws {SchematicError} on any contract violation. */
|
|
394
|
+
export declare function loadSchematic(source: string | SchematicDocument, options?: LoadSchematicOptions): LoadedSchematic;
|
|
395
|
+
|
|
396
|
+
export declare type LoadSchematicOptions = SchematicTopologyOptions;
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Merges the two collinear wires meeting at `junctionId` into one wire and removes the junction.
|
|
400
|
+
* Returns `undefined` when the junction does not describe such a splice.
|
|
401
|
+
*
|
|
402
|
+
* @throws {SchematicError} when the junction is unknown.
|
|
403
|
+
*/
|
|
404
|
+
export declare function mergeWiresAtJunction(document: SchematicDocument, junctionId: string, options?: WireEditOptions): MergeWiresResult | undefined;
|
|
405
|
+
|
|
406
|
+
export declare interface MergeWiresResult {
|
|
407
|
+
readonly document: SchematicDocument;
|
|
408
|
+
/** Wire that kept its id and absorbed the other one. */
|
|
409
|
+
readonly wireId: string;
|
|
410
|
+
readonly removedWireId: string;
|
|
411
|
+
readonly removedJunctionId: string;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/** Net labels, power and ground ports name the net they attach to. */
|
|
415
|
+
export declare function namesNet(role: SymbolRole): boolean;
|
|
416
|
+
|
|
417
|
+
/** Closest point on a polyline, with the segment it belongs to; `undefined` when empty. */
|
|
418
|
+
export declare function nearestPointOnPolyline(points: readonly Point[], point: Point): SegmentProjection | undefined;
|
|
419
|
+
|
|
420
|
+
/** Net name of a label / power / ground symbol; `undefined` when the symbol names no net. */
|
|
421
|
+
export declare function netNameOf(symbol: {
|
|
422
|
+
readonly device: string;
|
|
423
|
+
readonly net?: string;
|
|
424
|
+
}): string | undefined;
|
|
425
|
+
|
|
426
|
+
/** Smallest unused `<prefix><n>` designator. */
|
|
427
|
+
export declare function nextDesignator(document: SchematicDocument, prefix?: string): string;
|
|
428
|
+
|
|
429
|
+
/** Uppercases a `#RRGGBB` / `#RRGGBBAA` color; `undefined` when the text is not a color. */
|
|
430
|
+
export declare function normalizeColor(value: string): string | undefined;
|
|
431
|
+
|
|
432
|
+
/** Canonical stored value: colors are uppercased, everything else is stored as given. */
|
|
433
|
+
export declare function normalizePropertyValue(descriptor: PropertyDescriptor_2, value: PropertyValue): PropertyValue;
|
|
434
|
+
|
|
435
|
+
/** Validates JSON text or an object, throwing the existing diagnostic-bearing format error. */
|
|
436
|
+
export declare function parseDeviceMetadata(input: unknown): DeviceMetadata;
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Splits `<packageId>:<deviceId>`. Package ids follow npm conventions and may be scoped
|
|
440
|
+
* (`@scope/name`); device ids accept metadata identifiers plus the legacy identifier charset.
|
|
441
|
+
*/
|
|
442
|
+
export declare function parseDeviceReference(raw: string): DeviceReference | undefined;
|
|
443
|
+
|
|
444
|
+
/** Parses one declared property; `undefined` when the type is unknown or the descriptor unusable. */
|
|
445
|
+
export declare function parsePropertyDescriptor(key: string, raw: unknown): PropertyDescriptor_2 | undefined;
|
|
446
|
+
|
|
447
|
+
/** @throws {SchematicError} when the input does not match the `.sch` contract. */
|
|
448
|
+
export declare function parseSchematic(input: string | unknown): SchematicDocument;
|
|
449
|
+
|
|
450
|
+
export declare interface PinAnchor {
|
|
451
|
+
/** Connection point (outer end of the pin stub) in symbol space. */
|
|
452
|
+
readonly x: number;
|
|
453
|
+
readonly y: number;
|
|
454
|
+
/** Side the pin is displayed on; inferred from the position when omitted. */
|
|
455
|
+
readonly side?: PinSide;
|
|
456
|
+
readonly label?: DevicePinLabel;
|
|
457
|
+
readonly displayName?: string;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/** Bounding box of a device's pins; `undefined` when it declares none. */
|
|
461
|
+
export declare function pinsBounds(pins: Readonly<Record<string, PinAnchor>>): Rect | undefined;
|
|
462
|
+
|
|
463
|
+
/** Side of the symbol body a pin is drawn on; controls stub direction and label placement. */
|
|
464
|
+
export declare type PinSide = 'left' | 'right' | 'top' | 'bottom';
|
|
465
|
+
|
|
466
|
+
/** Side a pin is drawn on: its declared side, else the closest edge of the body outline. */
|
|
467
|
+
export declare function pinSide(pin: PinAnchor, outline: Rect | undefined): PinSide | undefined;
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* Inner end of a pin stub, where it meets the body outline. Together with the anchor it forms the
|
|
471
|
+
* grabbable pin: rendering draws that line and hit testing accepts clicks anywhere along it.
|
|
472
|
+
*/
|
|
473
|
+
export declare function pinStubEnd(body: Rect, anchor: {
|
|
474
|
+
readonly x: number;
|
|
475
|
+
readonly y: number;
|
|
476
|
+
}, side: PinSide): {
|
|
477
|
+
readonly x: number;
|
|
478
|
+
readonly y: number;
|
|
479
|
+
};
|
|
480
|
+
|
|
481
|
+
export declare interface Placement {
|
|
482
|
+
readonly x: number;
|
|
483
|
+
readonly y: number;
|
|
484
|
+
readonly rotation: number;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* Junctions that must let go of `wireId`: its new geometry no longer passes through them.
|
|
489
|
+
*
|
|
490
|
+
* A junction left with fewer than two wires is dropped instead of being kept dangling. Pure
|
|
491
|
+
* geometry: the caller applies the resulting commands.
|
|
492
|
+
*/
|
|
493
|
+
export declare function planJunctionRelease(document: SchematicDocument, wireId: string, points: readonly Point[], options?: JunctionReleaseOptions): readonly JunctionRelease[];
|
|
494
|
+
|
|
495
|
+
/** 2D point shared by the `.sch` and `.cnv` contracts. */
|
|
496
|
+
export declare interface Point {
|
|
497
|
+
readonly x: number;
|
|
498
|
+
readonly y: number;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
export declare interface PointMove {
|
|
502
|
+
readonly from: Point;
|
|
503
|
+
readonly to: Point;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
/** True when `point` lies on any segment of the polyline, endpoints included. */
|
|
507
|
+
export declare function pointOnPolyline(points: readonly Point[], point: Point, tolerance?: number): boolean;
|
|
508
|
+
|
|
509
|
+
/** Point at position `t` along segment `segment` of a polyline. */
|
|
510
|
+
export declare function pointOnPolylineAt(points: readonly Point[], segment: number, t: number): Point | undefined;
|
|
511
|
+
|
|
512
|
+
export declare function pointsEqual(a: Point, b: Point, tolerance?: number): boolean;
|
|
513
|
+
|
|
514
|
+
export declare const POWER_DEVICE = "builtin:power";
|
|
515
|
+
|
|
516
|
+
/** Closest point on the closed segment `a`–`b`, plus its position `t` in `[0, 1]`. */
|
|
517
|
+
export declare function projectOnSegment(point: Point, a: Point, b: Point): {
|
|
518
|
+
readonly x: number;
|
|
519
|
+
readonly y: number;
|
|
520
|
+
readonly t: number;
|
|
521
|
+
};
|
|
522
|
+
|
|
523
|
+
/** Property value types a device may declare (#7). */
|
|
524
|
+
export declare const PROPERTY_TYPES: readonly ["string", "integer", "number", "boolean", "color", "enum", "image", "binary"];
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* Descriptor of one device property (#7). `default` is the declared default, `title` falls back to
|
|
528
|
+
* the key, and the remaining fields carry the constraints of the type.
|
|
529
|
+
*/
|
|
530
|
+
declare interface PropertyDescriptor_2 {
|
|
531
|
+
readonly key: string;
|
|
532
|
+
readonly type: PropertyType;
|
|
533
|
+
readonly required?: boolean;
|
|
534
|
+
readonly group?: string;
|
|
535
|
+
readonly order?: number;
|
|
536
|
+
readonly editor?: DevicePropertyEditor;
|
|
537
|
+
readonly title?: string;
|
|
538
|
+
readonly description?: string;
|
|
539
|
+
/** Declared default; absent when the description omits it or it breaks its own constraints. */
|
|
540
|
+
readonly default?: PropertyValue;
|
|
541
|
+
/** When true an explicit `null` is a valid instance value. */
|
|
542
|
+
readonly nullable?: boolean;
|
|
543
|
+
/** `string`: maximum length in Unicode code points. */
|
|
544
|
+
readonly maxLength?: number;
|
|
545
|
+
/** `integer` / `number`: closed lower bound. */
|
|
546
|
+
readonly min?: number;
|
|
547
|
+
/** `integer` / `number`: closed upper bound. */
|
|
548
|
+
readonly max?: number;
|
|
549
|
+
/** `number`: open lower bound; mutually exclusive with `min`. */
|
|
550
|
+
readonly exclusiveMin?: number;
|
|
551
|
+
/** `integer` / `number`: editing step, always greater than zero. */
|
|
552
|
+
readonly step?: number;
|
|
553
|
+
/** `number`: display unit of the stored value. */
|
|
554
|
+
readonly unit?: string;
|
|
555
|
+
/** `color`: whether `#RRGGBBAA` values are accepted. */
|
|
556
|
+
readonly alpha?: boolean;
|
|
557
|
+
/** `enum`: non-empty option list. */
|
|
558
|
+
readonly options?: readonly PropertyOption[];
|
|
559
|
+
/** `image` / `binary`: host-side payload limit in bytes. */
|
|
560
|
+
readonly maxBytes?: number;
|
|
561
|
+
/** `image`: host-side pixel limit. */
|
|
562
|
+
readonly maxPixels?: number;
|
|
563
|
+
}
|
|
564
|
+
export { PropertyDescriptor_2 as PropertyDescriptor }
|
|
565
|
+
|
|
566
|
+
export declare interface PropertyOption {
|
|
567
|
+
readonly value: string;
|
|
568
|
+
readonly label: string;
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
export declare type PropertyType = (typeof PROPERTY_TYPES)[number];
|
|
572
|
+
|
|
573
|
+
/**
|
|
574
|
+
* Instance property value stored in `symbol.properties` (see #6 / #7): a scalar, a resource
|
|
575
|
+
* reference for `image` / `binary` properties, or `null` for an explicitly cleared nullable one.
|
|
576
|
+
*/
|
|
577
|
+
export declare type PropertyValue = string | number | boolean | AssetReference | null;
|
|
578
|
+
|
|
579
|
+
export declare interface PropertyValueProblem {
|
|
580
|
+
readonly code: 'schema/invalid-type' | 'schema/invalid-value';
|
|
581
|
+
readonly message: string;
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
/** Constraint violation of `value` for `descriptor`; `undefined` when the value is acceptable. */
|
|
585
|
+
export declare function propertyValueProblem(descriptor: PropertyDescriptor_2, value: unknown): PropertyValueProblem | undefined;
|
|
586
|
+
|
|
587
|
+
/** Parses the `properties` object of a device description, skipping unusable declarations. */
|
|
588
|
+
export declare function readPropertyDescriptors(raw: unknown): ReadonlyMap<string, PropertyDescriptor_2>;
|
|
589
|
+
|
|
590
|
+
export declare interface Rect {
|
|
591
|
+
readonly x: number;
|
|
592
|
+
readonly y: number;
|
|
593
|
+
readonly width: number;
|
|
594
|
+
readonly height: number;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
/**
|
|
598
|
+
* Local anchor of a symbol's reference designator: the explicit override, else the body's
|
|
599
|
+
* top-left corner lifted by {@link REFERENCE_DEFAULT_OFFSET}.
|
|
600
|
+
*/
|
|
601
|
+
export declare function referenceAnchor(outline: Rect | undefined, override?: Point): Point;
|
|
602
|
+
|
|
603
|
+
/** World position of a symbol's reference designator anchor. */
|
|
604
|
+
export declare function referencePosition(placement: Placement, outline: Rect | undefined, override?: Point): Point;
|
|
605
|
+
|
|
606
|
+
export declare interface ReroutedWire {
|
|
607
|
+
readonly points: readonly Point[];
|
|
608
|
+
/** Every point that changed, so junctions and anchors can follow. */
|
|
609
|
+
readonly moves: readonly PointMove[];
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
/**
|
|
613
|
+
* Moves a wire endpoint to `to` while keeping every segment horizontal or vertical.
|
|
614
|
+
*
|
|
615
|
+
* The displacement is absorbed segment by segment (the classic orthogonal drag): the point after
|
|
616
|
+
* the moved end is shifted just enough to restore the original orientation, and the correction is
|
|
617
|
+
* passed on until a segment can take it. No extra points are inserted, so the wire never doubles
|
|
618
|
+
* back on itself.
|
|
619
|
+
*/
|
|
620
|
+
export declare function rerouteWireEndpoint(wire: SchematicWire, from: Point, to: Point): ReroutedWire | undefined;
|
|
621
|
+
|
|
622
|
+
export declare const RESERVED_PACKAGE_NAMESPACE = "builtin";
|
|
623
|
+
|
|
624
|
+
export declare interface ResolvedDevice {
|
|
625
|
+
readonly reference: DeviceReference;
|
|
626
|
+
readonly packageId: string;
|
|
627
|
+
readonly deviceId: string;
|
|
628
|
+
readonly displayName: string;
|
|
629
|
+
readonly description: string | undefined;
|
|
630
|
+
/** Designator prefix declared by the device description; `undefined` when it declares none. */
|
|
631
|
+
readonly designatorPrefix: string | undefined;
|
|
632
|
+
/** Property descriptors declared by `properties` (#7), keyed by property key. */
|
|
633
|
+
readonly propertyDescriptors: ReadonlyMap<string, PropertyDescriptor_2>;
|
|
634
|
+
readonly symbol: DeviceSymbolDefinition | undefined;
|
|
635
|
+
readonly raw: Readonly<Record<string, unknown>>;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
/** Rotates counter-clockwise around the origin. Rotation is expressed in degrees. */
|
|
639
|
+
export declare function rotatePoint(point: Point, degrees: number): Point;
|
|
640
|
+
|
|
641
|
+
export declare function samePoint(a: Point, b: Point): boolean;
|
|
642
|
+
|
|
643
|
+
/**
|
|
644
|
+
* Schema version of the `.sch` contract (see x-botlab/mica-js#6).
|
|
645
|
+
*
|
|
646
|
+
* 2D placement lives in the separate `.cnv` canvas contract (see x-botlab/mica-js#67 and
|
|
647
|
+
* `@mica-js/document/canvas`).
|
|
648
|
+
*/
|
|
649
|
+
export declare const SCHEMATIC_VERSION = 1;
|
|
650
|
+
|
|
651
|
+
export declare type SchematicCommand = {
|
|
652
|
+
readonly type: 'add-symbol';
|
|
653
|
+
readonly id?: string;
|
|
654
|
+
readonly device: string;
|
|
655
|
+
readonly x: number;
|
|
656
|
+
readonly y: number;
|
|
657
|
+
readonly rotation?: number;
|
|
658
|
+
readonly properties?: Readonly<Record<string, PropertyValue>>;
|
|
659
|
+
/** Component reference designator; defaults to the new symbol's id. */
|
|
660
|
+
readonly designator?: string;
|
|
661
|
+
/** Net name for labels / power / ground; power and ground fall back to VCC / GND. */
|
|
662
|
+
readonly net?: string;
|
|
663
|
+
/** Reference designator anchor in symbol-local coordinates; `null` clears it. */
|
|
664
|
+
readonly reference?: Point | null;
|
|
665
|
+
} | {
|
|
666
|
+
readonly type: 'update-symbol';
|
|
667
|
+
readonly id: string;
|
|
668
|
+
readonly device?: string;
|
|
669
|
+
readonly x?: number;
|
|
670
|
+
readonly y?: number;
|
|
671
|
+
readonly rotation?: number;
|
|
672
|
+
/** Replaces the whole property map when provided. */
|
|
673
|
+
readonly properties?: Readonly<Record<string, PropertyValue>>;
|
|
674
|
+
/** Reference designator; `null` clears the override, `undefined` keeps it. */
|
|
675
|
+
readonly designator?: string | null;
|
|
676
|
+
/** Net name; `null` clears it, `undefined` keeps it. */
|
|
677
|
+
readonly net?: string | null;
|
|
678
|
+
/** Reference designator anchor; `null` clears it, `undefined` keeps it. */
|
|
679
|
+
readonly reference?: Point | null;
|
|
680
|
+
} | {
|
|
681
|
+
readonly type: 'remove-symbol';
|
|
682
|
+
readonly id: string;
|
|
683
|
+
} | {
|
|
684
|
+
readonly type: 'set-symbol-property';
|
|
685
|
+
readonly id: string;
|
|
686
|
+
readonly key: string;
|
|
687
|
+
readonly value: PropertyValue;
|
|
688
|
+
} | {
|
|
689
|
+
readonly type: 'remove-symbol-property';
|
|
690
|
+
readonly id: string;
|
|
691
|
+
readonly key: string;
|
|
692
|
+
} | {
|
|
693
|
+
readonly type: 'add-wire';
|
|
694
|
+
readonly id?: string;
|
|
695
|
+
readonly points: readonly Point[];
|
|
696
|
+
} | {
|
|
697
|
+
readonly type: 'set-wire-points';
|
|
698
|
+
readonly id: string;
|
|
699
|
+
readonly points: readonly Point[];
|
|
700
|
+
} | {
|
|
701
|
+
readonly type: 'remove-wire';
|
|
702
|
+
readonly id: string;
|
|
703
|
+
} | {
|
|
704
|
+
readonly type: 'add-junction';
|
|
705
|
+
readonly id?: string;
|
|
706
|
+
readonly x: number;
|
|
707
|
+
readonly y: number;
|
|
708
|
+
readonly wires: readonly string[];
|
|
709
|
+
} | {
|
|
710
|
+
readonly type: 'update-junction';
|
|
711
|
+
readonly id: string;
|
|
712
|
+
readonly x?: number;
|
|
713
|
+
readonly y?: number;
|
|
714
|
+
readonly wires?: readonly string[];
|
|
715
|
+
} | {
|
|
716
|
+
readonly type: 'remove-junction';
|
|
717
|
+
readonly id: string;
|
|
718
|
+
};
|
|
719
|
+
|
|
720
|
+
/** Root of a `.sch` file; the file name is the schematic's identity. */
|
|
721
|
+
export declare interface SchematicDocument {
|
|
722
|
+
readonly version: SchematicVersion;
|
|
723
|
+
readonly sheet: SchematicSheet;
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
export declare interface SchematicEditOptions extends SchematicTopologyOptions {
|
|
727
|
+
readonly createId?: ElementIdFactory;
|
|
728
|
+
/** How to handle junctions that stop lying on a wire after its geometry changes. */
|
|
729
|
+
readonly onJunctionConflict?: 'reject' | 'remove';
|
|
730
|
+
/** Receives cascaded removals such as junctions dropped with their wire. */
|
|
731
|
+
readonly onEffect?: (effect: EditEffect) => void;
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
/**
|
|
735
|
+
* Thrown when input violates the schematic format contract.
|
|
736
|
+
* `diagnostics` carries every problem found, so callers can report them all at once.
|
|
737
|
+
*/
|
|
738
|
+
export declare class SchematicError extends Error {
|
|
739
|
+
readonly diagnostics: readonly Diagnostic[];
|
|
740
|
+
constructor(diagnostics: readonly Diagnostic[]);
|
|
741
|
+
/** Code of the first diagnostic, for coarse programmatic handling. */
|
|
742
|
+
get code(): DiagnosticCode | undefined;
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
export declare interface SchematicJunction {
|
|
746
|
+
readonly id: string;
|
|
747
|
+
readonly x: number;
|
|
748
|
+
readonly y: number;
|
|
749
|
+
readonly wires: readonly string[];
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
export declare interface SchematicNet {
|
|
753
|
+
/** Name contributed by the single naming connection point; `null` when anonymous. */
|
|
754
|
+
readonly name: string | null;
|
|
755
|
+
readonly wireIds: readonly string[];
|
|
756
|
+
readonly members: readonly SchematicNetMember[];
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
export declare type SchematicNetMember = {
|
|
760
|
+
readonly kind: 'pin';
|
|
761
|
+
readonly symbolId: string;
|
|
762
|
+
readonly pinId: string;
|
|
763
|
+
} | {
|
|
764
|
+
readonly kind: 'label';
|
|
765
|
+
readonly symbolId: string;
|
|
766
|
+
} | {
|
|
767
|
+
readonly kind: 'power';
|
|
768
|
+
readonly symbolId: string;
|
|
769
|
+
} | {
|
|
770
|
+
readonly kind: 'ground';
|
|
771
|
+
readonly symbolId: string;
|
|
772
|
+
};
|
|
773
|
+
|
|
774
|
+
export declare interface SchematicPinInstance {
|
|
775
|
+
readonly symbolId: string;
|
|
776
|
+
readonly pinId: string;
|
|
777
|
+
readonly position: Point;
|
|
778
|
+
/** True when the pin is not connected to any wire, label or other pin. */
|
|
779
|
+
readonly open: boolean;
|
|
780
|
+
/** Name of the net the pin belongs to; `null` for anonymous nets. */
|
|
781
|
+
readonly netName: string | null;
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
export declare interface SchematicSheet {
|
|
785
|
+
readonly symbols: readonly SchematicSymbol[];
|
|
786
|
+
readonly wires: readonly SchematicWire[];
|
|
787
|
+
readonly junctions: readonly SchematicJunction[];
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
export declare interface SchematicSymbol extends Placement {
|
|
791
|
+
/** Stable identity used by selections, undo and `.view` layout keys. */
|
|
792
|
+
readonly id: string;
|
|
793
|
+
readonly device: string;
|
|
794
|
+
/** Instance property overrides; absent means "use device defaults". */
|
|
795
|
+
readonly properties?: Readonly<Record<string, PropertyValue>>;
|
|
796
|
+
/**
|
|
797
|
+
* Reference designator of a component (`U1`, `R2`); defaults to {@link id}.
|
|
798
|
+
* Only components carry one — the format rejects it elsewhere.
|
|
799
|
+
*/
|
|
800
|
+
readonly designator?: string;
|
|
801
|
+
/**
|
|
802
|
+
* Net name of a net label, power or ground symbol (`VCC`, `N1`). It is the text drawn next to
|
|
803
|
+
* the anchor and the key same-named ports merge on. Only net-naming symbols carry one.
|
|
804
|
+
*/
|
|
805
|
+
readonly net?: string;
|
|
806
|
+
/**
|
|
807
|
+
* Reference designator anchor in symbol-local coordinates (unrotated, unplaced).
|
|
808
|
+
* Absent means the default position at the body's top-left corner.
|
|
809
|
+
*/
|
|
810
|
+
readonly reference?: Point;
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
export declare interface SchematicTopology {
|
|
814
|
+
readonly nets: readonly SchematicNet[];
|
|
815
|
+
readonly pins: readonly SchematicPinInstance[];
|
|
816
|
+
readonly danglingWireEnds: readonly DanglingWireEnd[];
|
|
817
|
+
/** Bounding box of all wires, pins and symbol outlines. */
|
|
818
|
+
readonly bounds: Rect | undefined;
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
export declare interface SchematicTopologyOptions {
|
|
822
|
+
readonly devices?: DeviceSymbolProvider;
|
|
823
|
+
/** Coordinate comparison tolerance in page units; defaults to exact matching. */
|
|
824
|
+
readonly tolerance?: number;
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
export declare type SchematicVersion = typeof SCHEMATIC_VERSION;
|
|
828
|
+
|
|
829
|
+
export declare interface SchematicWire {
|
|
830
|
+
readonly id: string;
|
|
831
|
+
readonly points: readonly Point[];
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
export declare interface SegmentProjection {
|
|
835
|
+
/** Closest point of the polyline. */
|
|
836
|
+
readonly point: Point;
|
|
837
|
+
/** Index of the segment that holds the closest point. */
|
|
838
|
+
readonly segment: number;
|
|
839
|
+
/** Position along that segment, in `[0, 1]`. */
|
|
840
|
+
readonly t: number;
|
|
841
|
+
readonly distance: number;
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
/** Serializes with a fixed field order and 2-space indentation, matching the examples in #6. */
|
|
845
|
+
export declare function serializeSchematic(document: SchematicDocument): string;
|
|
846
|
+
|
|
847
|
+
/**
|
|
848
|
+
* Splits `wireId` at `point`, which must lie strictly inside the polyline.
|
|
849
|
+
* Junctions that only touch the second half are re-pointed to the new wire.
|
|
850
|
+
*
|
|
851
|
+
* @throws {SchematicError} when the wire is unknown or `point` is not an interior point.
|
|
852
|
+
*/
|
|
853
|
+
export declare function splitWireAt(document: SchematicDocument, wireId: string, point: Point, options?: WireEditOptions): SplitWireResult;
|
|
854
|
+
|
|
855
|
+
export declare interface SplitWireResult {
|
|
856
|
+
readonly document: SchematicDocument;
|
|
857
|
+
/** Wire that keeps the original id (the part before `point`). */
|
|
858
|
+
readonly firstWireId: string;
|
|
859
|
+
readonly secondWireId: string;
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
/**
|
|
863
|
+
* Moves a wire endpoint to `to` by stretching or bending it, leaving the original run in place.
|
|
864
|
+
*
|
|
865
|
+
* Unlike {@link rerouteWireEndpoint}, which absorbs the move by shifting the neighbouring points,
|
|
866
|
+
* this keeps every existing point: a move along the attached segment only changes its length, and a
|
|
867
|
+
* perpendicular move appends an orthogonal fold at the moved end. That is the behaviour net labels
|
|
868
|
+
* and power ports need while being dragged — the wire follows them instead of sliding away.
|
|
869
|
+
*/
|
|
870
|
+
export declare function stretchWireEndpoint(wire: SchematicWire, from: Point, to: Point): ReroutedWire | undefined;
|
|
871
|
+
|
|
872
|
+
/** Bounding box of a symbol: its transformed outline, else its pins, else its origin. */
|
|
873
|
+
export declare function symbolBounds(placement: Placement, outline: Rect | undefined, pins: Readonly<Record<string, PinAnchor>>): Rect | undefined;
|
|
874
|
+
|
|
875
|
+
/** Applies a symbol placement to a pre-placement anchor. */
|
|
876
|
+
export declare function symbolPinPosition(placement: Placement, anchor: PinAnchor): Point;
|
|
877
|
+
|
|
878
|
+
/** What a placed symbol is for: the single question the rest of the code asks about it. */
|
|
879
|
+
export declare type SymbolRole = 'component' | 'net-label' | 'power' | 'ground' | 'text';
|
|
880
|
+
|
|
881
|
+
/** Role of a symbol, derived from its device reference; unknown devices are components. */
|
|
882
|
+
export declare function symbolRole(device: string): SymbolRole;
|
|
883
|
+
|
|
884
|
+
export declare interface SymbolSynthesisInput {
|
|
885
|
+
readonly name: string;
|
|
886
|
+
readonly pins: Readonly<Record<string, DevicePinDeclaration>>;
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
export declare interface SymbolSynthesisOptions {
|
|
890
|
+
/** Distance between pin rows, in page units. Defaults to 10. */
|
|
891
|
+
readonly pinPitch?: number;
|
|
892
|
+
/** Stub length outside the body. Defaults to 10. */
|
|
893
|
+
readonly stubLength?: number;
|
|
894
|
+
/** Minimum body width. Defaults to 60. */
|
|
895
|
+
readonly minWidth?: number;
|
|
896
|
+
/** Minimum body height. Defaults to 40. */
|
|
897
|
+
readonly minHeight?: number;
|
|
898
|
+
/** Horizontal padding between the body edge and pin labels. Defaults to 10. */
|
|
899
|
+
readonly horizontalPadding?: number;
|
|
900
|
+
/** Vertical padding above the first and below the last pin row. Defaults to 10. */
|
|
901
|
+
readonly verticalPadding?: number;
|
|
902
|
+
/** Approximate glyph width of the device name. Defaults to 5.5. */
|
|
903
|
+
readonly characterWidth?: number;
|
|
904
|
+
/** Approximate glyph width of a pin name. Defaults to 4.5. */
|
|
905
|
+
readonly labelCharacterWidth?: number;
|
|
906
|
+
/** Gap between the device name and the side pin labels. Defaults to 12. */
|
|
907
|
+
readonly nameGap?: number;
|
|
908
|
+
/** Inset of a top/bottom pin label from the body edge. Defaults to 10. */
|
|
909
|
+
readonly labelInset?: number;
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
/**
|
|
913
|
+
* Derives symbol geometry from pin declarations: no coordinates or body size are authored.
|
|
914
|
+
* Pins keep their declaration order within a side and snap to `pinPitch`.
|
|
915
|
+
*/
|
|
916
|
+
export declare function synthesizeDeviceSymbol(input: SymbolSynthesisInput, options?: SymbolSynthesisOptions): DeviceSymbolDefinition;
|
|
917
|
+
|
|
918
|
+
/** Free-standing annotation; it is not a connection point and never joins a net. */
|
|
919
|
+
export declare const TEXT_DEVICE = "builtin:text";
|
|
920
|
+
|
|
921
|
+
/** Text of a `builtin:text` symbol, falling back to a placeholder. */
|
|
922
|
+
export declare function textDeviceContent(symbol: {
|
|
923
|
+
readonly properties?: Readonly<Record<string, unknown>>;
|
|
924
|
+
}): string;
|
|
925
|
+
|
|
926
|
+
export declare interface WireEditOptions {
|
|
927
|
+
readonly tolerance?: number;
|
|
928
|
+
readonly createId?: ElementIdFactory;
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
export { }
|