@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 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["samePoint"],"sources":["../../src/format/types.ts","../../src/schematic/device/reference.ts","../../src/schematic/format/parse-schematic.ts","../../src/schematic/format/serialize.ts","../../src/schematic/geometry/point.ts","../../src/schematic/geometry/transform.ts","../../src/schematic/netlist/derive.ts","../../src/schematic/load/load.ts","../../src/schematic/device/properties.ts","../../src/schematic/edit/ids.ts","../../src/schematic/edit/commands.ts","../../src/schematic/edit/junctions.ts","../../src/schematic/edit/wires.ts","../../src/schematic/geometry/reroute.ts","../../src/schematic/device/synthesis.ts","../../src/schematic/device/symbol.ts","../../src/schematic/device/metadata.ts","../../src/schematic/device/registry.ts","../../src/schematic/device/designator.ts"],"sourcesContent":["import type { Point, PropertyValue } from './value';\n\n/**\n * Schema version of the `.sch` contract (see x-botlab/mica-js#6).\n *\n * 2D placement lives in the separate `.cnv` canvas contract (see x-botlab/mica-js#67 and\n * `@mica-js/document/canvas`).\n */\nexport const SCHEMATIC_VERSION = 1;\n\nexport type SchematicVersion = typeof SCHEMATIC_VERSION;\n\nexport interface Rect {\n readonly x: number;\n readonly y: number;\n readonly width: number;\n readonly height: number;\n}\n\nexport interface Placement {\n readonly x: number;\n readonly y: number;\n readonly rotation: number;\n}\n\nexport interface SchematicSymbol extends Placement {\n /** Stable identity used by selections, undo and `.view` layout keys. */\n readonly id: string;\n readonly device: string;\n /** Instance property overrides; absent means \"use device defaults\". */\n readonly properties?: Readonly<Record<string, PropertyValue>>;\n /**\n * Reference designator of a component (`U1`, `R2`); defaults to {@link id}.\n * Only components carry one — the format rejects it elsewhere.\n */\n readonly designator?: string;\n /**\n * Net name of a net label, power or ground symbol (`VCC`, `N1`). It is the text drawn next to\n * the anchor and the key same-named ports merge on. Only net-naming symbols carry one.\n */\n readonly net?: string;\n /**\n * Reference designator anchor in symbol-local coordinates (unrotated, unplaced).\n * Absent means the default position at the body's top-left corner.\n */\n readonly reference?: Point;\n}\n\nexport interface SchematicWire {\n readonly id: string;\n readonly points: readonly Point[];\n}\n\nexport interface SchematicJunction {\n readonly id: string;\n readonly x: number;\n readonly y: number;\n readonly wires: readonly string[];\n}\n\nexport interface SchematicSheet {\n readonly symbols: readonly SchematicSymbol[];\n readonly wires: readonly SchematicWire[];\n readonly junctions: readonly SchematicJunction[];\n}\n\n/** Root of a `.sch` file; the file name is the schematic's identity. */\nexport interface SchematicDocument {\n readonly version: SchematicVersion;\n readonly sheet: SchematicSheet;\n}\n","export const LABEL_DEVICE = 'builtin:label';\nexport const POWER_DEVICE = 'builtin:power';\nexport const GROUND_DEVICE = 'builtin:ground';\n/** Free-standing annotation; it is not a connection point and never joins a net. */\nexport const TEXT_DEVICE = 'builtin:text';\nexport const RESERVED_PACKAGE_NAMESPACE = 'builtin';\n\n/** Builtin symbols recognised by the loader instead of the device registry. */\nexport type BuiltinSymbolKind = 'label' | 'power' | 'ground';\n\nconst BUILTIN_DEVICES: Readonly<Record<string, BuiltinSymbolKind>> = {\n [LABEL_DEVICE]: 'label',\n [POWER_DEVICE]: 'power',\n [GROUND_DEVICE]: 'ground',\n};\n\nexport const DEFAULT_POWER_LABEL = 'VCC';\nexport const DEFAULT_GROUND_LABEL = 'GND';\nexport const DEFAULT_TEXT_CONTENT = '文本';\n\nexport interface DeviceReference {\n readonly raw: string;\n readonly packageId: string;\n readonly deviceId: string;\n}\n\nconst PACKAGE_NAMESPACE_PATTERN = /^@[A-Za-z0-9][A-Za-z0-9._+-]*$/;\nconst PACKAGE_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._+-]*$/;\nconst DEVICE_ID_PATTERN = /^(?:[A-Za-z0-9][A-Za-z0-9._+-]*|-[A-Za-z0-9-]*)$/;\n\n/**\n * Splits `<packageId>:<deviceId>`. Package ids follow npm conventions and may be scoped\n * (`@scope/name`); device ids accept metadata identifiers plus the legacy identifier charset.\n */\nexport function parseDeviceReference(raw: string): DeviceReference | undefined {\n const separator = raw.indexOf(':');\n if (separator <= 0 || separator === raw.length - 1) {\n return undefined;\n }\n if (raw.indexOf(':', separator + 1) !== -1) {\n return undefined;\n }\n const packageId = raw.slice(0, separator);\n const deviceId = raw.slice(separator + 1);\n if (!isValidPackageId(packageId) || !DEVICE_ID_PATTERN.test(deviceId)) {\n return undefined;\n }\n return { raw, packageId, deviceId };\n}\n\nexport function isValidPackageId(packageId: string): boolean {\n if (packageId.startsWith('@')) {\n const parts = packageId.split('/');\n if (parts.length !== 2) {\n return false;\n }\n const [scope, name] = parts;\n return (\n scope !== undefined &&\n name !== undefined &&\n PACKAGE_NAMESPACE_PATTERN.test(scope) &&\n PACKAGE_NAME_PATTERN.test(name)\n );\n }\n return PACKAGE_NAME_PATTERN.test(packageId);\n}\n\n/** `builtin` is reserved for loader-provided symbols such as `builtin:label`. */\nexport function isReservedPackageId(packageId: string): boolean {\n return (\n packageId === RESERVED_PACKAGE_NAMESPACE ||\n packageId.startsWith(`${RESERVED_PACKAGE_NAMESPACE}/`)\n );\n}\n\nexport function isLabelDevice(raw: string): boolean {\n return raw === LABEL_DEVICE;\n}\n\n/** True for the free-standing text annotation (`builtin:text`). */\nexport function isTextDevice(raw: string): boolean {\n return raw === TEXT_DEVICE;\n}\n\n/** Text of a `builtin:text` symbol, falling back to a placeholder. */\nexport function textDeviceContent(symbol: {\n readonly properties?: Readonly<Record<string, unknown>>;\n}): string {\n const text = symbol.properties?.['text'];\n return typeof text === 'string' && text.length > 0 ? text : DEFAULT_TEXT_CONTENT;\n}\n\n/** Returns the builtin kind for `builtin:label` / `builtin:power` / `builtin:ground`. */\nexport function builtinSymbolKind(raw: string): BuiltinSymbolKind | undefined {\n return BUILTIN_DEVICES[raw];\n}\n\nexport function isBuiltinDevice(raw: string): boolean {\n return builtinSymbolKind(raw) !== undefined;\n}\n\n/** What a placed symbol is for: the single question the rest of the code asks about it. */\nexport type SymbolRole = 'component' | 'net-label' | 'power' | 'ground' | 'text';\n\n/** Role of a symbol, derived from its device reference; unknown devices are components. */\nexport function symbolRole(device: string): SymbolRole {\n switch (builtinSymbolKind(device)) {\n case 'label':\n return 'net-label';\n case 'power':\n return 'power';\n case 'ground':\n return 'ground';\n default:\n return isTextDevice(device) ? 'text' : 'component';\n }\n}\n\n/** Only components are annotated with a reference designator. */\nexport function hasDesignator(role: SymbolRole): boolean {\n return role === 'component';\n}\n\n/** Net labels, power and ground ports name the net they attach to. */\nexport function namesNet(role: SymbolRole): boolean {\n return role === 'net-label' || role === 'power' || role === 'ground';\n}\n\n/** Reference designator of a component; `undefined` for symbols that have none. */\nexport function designatorOf(symbol: {\n readonly id: string;\n readonly device: string;\n readonly designator?: string;\n}): string | undefined {\n return hasDesignator(symbolRole(symbol.device)) ? (symbol.designator ?? symbol.id) : undefined;\n}\n\n/** Net name of a label / power / ground symbol; `undefined` when the symbol names no net. */\nexport function netNameOf(symbol: {\n readonly device: string;\n readonly net?: string;\n}): string | undefined {\n switch (symbolRole(symbol.device)) {\n case 'power':\n return symbol.net ?? DEFAULT_POWER_LABEL;\n case 'ground':\n return symbol.net ?? DEFAULT_GROUND_LABEL;\n case 'net-label':\n return symbol.net;\n default:\n return undefined;\n }\n}\n\n/** Net name a freshly placed symbol of `role` gets when none is given. */\nexport function defaultNetName(role: SymbolRole): string | undefined {\n switch (role) {\n case 'power':\n return DEFAULT_POWER_LABEL;\n case 'ground':\n return DEFAULT_GROUND_LABEL;\n default:\n return undefined;\n }\n}\n\nexport function formatDeviceReference(packageId: string, deviceId: string): string {\n return `${packageId}:${deviceId}`;\n}\n","import type { Diagnostic } from '../../format/diagnostics';\nimport { SchematicError } from '../../format/errors';\nimport { parseInput } from '../../format/input';\nimport { isUuidV4 } from '../../format/uuid';\nimport type {\n SchematicDocument,\n SchematicJunction,\n SchematicSheet,\n SchematicSymbol,\n SchematicWire,\n} from '../../format/types';\nimport { SCHEMATIC_VERSION } from '../../format/types';\nimport type { Point } from '../../format/value';\nimport {\n designatorOf,\n hasDesignator,\n namesNet,\n symbolRole,\n type SymbolRole,\n} from '../device/reference';\nimport {\n checkDuplicateIds,\n forbidUnknownFields,\n hasErrors,\n isRecord,\n readArrayField,\n readIntegerField,\n readNumberField,\n readObjectField,\n readPoint,\n readProperties,\n readStringField,\n report,\n type IdentifiedEntry,\n} from '../../format/validate';\n\n/** @throws {SchematicError} when the input does not match the `.sch` contract. */\nexport function parseSchematic(input: string | unknown): SchematicDocument {\n const diagnostics: Diagnostic[] = [];\n const parsed = parseInput(input, diagnostics);\n if (!parsed.ok) {\n throw new SchematicError(diagnostics);\n }\n const value = readDocument(parsed.value, diagnostics);\n if (value === undefined || hasErrors(diagnostics)) {\n throw new SchematicError(diagnostics);\n }\n return value;\n}\n\nfunction readDocument(value: unknown, diagnostics: Diagnostic[]): SchematicDocument | undefined {\n if (!isRecord(value)) {\n report(diagnostics, 'json/not-object', 'Schematic must be a JSON object.', []);\n return undefined;\n }\n forbidUnknownFields(value, ['version', 'sheet'], [], diagnostics);\n const version = readVersion(value, diagnostics);\n const sheet = readSheet(readObjectField(value, 'sheet', [], diagnostics), diagnostics);\n if (version === undefined || sheet === undefined) {\n return undefined;\n }\n return { version, sheet };\n}\n\nfunction readVersion(\n value: Record<string, unknown>,\n diagnostics: Diagnostic[],\n): typeof SCHEMATIC_VERSION | undefined {\n const version = readIntegerField(value, 'version', [], diagnostics);\n if (version === undefined) {\n return undefined;\n }\n if (version !== SCHEMATIC_VERSION) {\n report(\n diagnostics,\n 'schema/unsupported-version',\n `Unsupported version ${version}; expected ${SCHEMATIC_VERSION}.`,\n ['version'],\n );\n return undefined;\n }\n return SCHEMATIC_VERSION;\n}\n\nfunction readSheet(\n value: Record<string, unknown> | undefined,\n diagnostics: Diagnostic[],\n): SchematicSheet | undefined {\n if (value === undefined) {\n return undefined;\n }\n forbidUnknownFields(value, ['symbols', 'wires', 'junctions'], ['sheet'], diagnostics);\n const rawSymbols = readArrayField(value, 'symbols', ['sheet'], diagnostics) ?? [];\n const rawWires = readArrayField(value, 'wires', ['sheet'], diagnostics) ?? [];\n const rawJunctions = readArrayField(value, 'junctions', ['sheet'], diagnostics) ?? [];\n\n const symbols: SchematicSymbol[] = [];\n const symbolIds: IdentifiedEntry[] = [];\n rawSymbols.forEach((item, index) => {\n const path = ['sheet', 'symbols', String(index)];\n const symbol = readSymbol(item, path, diagnostics);\n if (symbol !== undefined) {\n symbols.push(symbol);\n symbolIds.push({ id: symbol.id, path: [...path, 'id'] });\n }\n });\n\n const wires: SchematicWire[] = [];\n const wireIds: IdentifiedEntry[] = [];\n rawWires.forEach((item, index) => {\n const path = ['sheet', 'wires', String(index)];\n const wire = readWire(item, path, diagnostics);\n if (wire !== undefined) {\n wires.push(wire);\n wireIds.push({ id: wire.id, path: [...path, 'id'] });\n }\n });\n\n const knownWireIds = new Set(wires.map((wire) => wire.id));\n const junctions: SchematicJunction[] = [];\n const junctionIds: IdentifiedEntry[] = [];\n rawJunctions.forEach((item, index) => {\n const path = ['sheet', 'junctions', String(index)];\n const junction = readJunction(item, path, diagnostics);\n if (junction === undefined) {\n return;\n }\n const seenWireIds = new Set<string>();\n junction.wires.forEach((wireId, wireIndex) => {\n const wirePath = [...path, 'wires', String(wireIndex)];\n if (seenWireIds.has(wireId)) {\n report(\n diagnostics,\n 'junction/duplicate-wire',\n `Junction \"${junction.id}\" references wire \"${wireId}\" more than once.`,\n wirePath,\n { kind: 'junction', id: junction.id },\n );\n } else {\n seenWireIds.add(wireId);\n }\n if (!knownWireIds.has(wireId)) {\n report(\n diagnostics,\n 'junction/unknown-wire',\n `Junction \"${junction.id}\" references unknown wire \"${wireId}\".`,\n wirePath,\n { kind: 'junction', id: junction.id },\n );\n }\n });\n junctions.push(junction);\n junctionIds.push({ id: junction.id, path: [...path, 'id'] });\n });\n\n checkDuplicateIds(symbolIds, 'symbol', diagnostics);\n checkDuplicateDesignators(symbols, diagnostics);\n checkDuplicateIds(wireIds, 'wire', diagnostics);\n checkDuplicateIds(junctionIds, 'junction', diagnostics);\n\n return { symbols, wires, junctions };\n}\n\n/** Two components must not share a reference designator. */\nfunction checkDuplicateDesignators(\n symbols: readonly SchematicSymbol[],\n diagnostics: Diagnostic[],\n): void {\n const seen = new Set<string>();\n symbols.forEach((symbol, index) => {\n const designator = designatorOf(symbol);\n if (designator === undefined) {\n return;\n }\n if (seen.has(designator)) {\n report(\n diagnostics,\n 'symbol/designator-duplicate',\n `Reference designator ${JSON.stringify(designator)} is used more than once.`,\n ['sheet', 'symbols', String(index), 'designator'],\n { kind: 'symbol', id: symbol.id },\n );\n return;\n }\n seen.add(designator);\n });\n}\n\nfunction readSymbol(\n value: unknown,\n path: readonly string[],\n diagnostics: Diagnostic[],\n): SchematicSymbol | undefined {\n if (!isRecord(value)) {\n report(diagnostics, 'schema/invalid-type', 'Symbol must be an object.', path);\n return undefined;\n }\n forbidUnknownFields(\n value,\n ['id', 'device', 'x', 'y', 'rotation', 'properties', 'designator', 'net', 'reference'],\n path,\n diagnostics,\n );\n const id = readId(value, path, diagnostics);\n const device = readStringField(value, 'device', path, diagnostics, { nonEmpty: true });\n const x = readNumberField(value, 'x', path, diagnostics);\n const y = readNumberField(value, 'y', path, diagnostics);\n const rotation = readNumberField(value, 'rotation', path, diagnostics);\n const properties =\n value['properties'] === undefined\n ? undefined\n : readProperties(value['properties'], [...path, 'properties'], diagnostics);\n const reference =\n value['reference'] === undefined\n ? undefined\n : readPoint(value['reference'], [...path, 'reference'], diagnostics);\n const designator = readRoleField(value, 'designator', device, path, diagnostics, hasDesignator);\n const net = readRoleField(value, 'net', device, path, diagnostics, namesNet);\n if (device !== undefined) {\n const role = symbolRole(device);\n if (namesNet(role) && net === undefined && value['net'] === undefined) {\n report(\n diagnostics,\n 'symbol/missing-net',\n `Symbols of role \"${role}\" must name the net they attach to.`,\n [...path, 'net'],\n );\n }\n if (!hasDesignator(role) && value['reference'] !== undefined) {\n report(\n diagnostics,\n 'symbol/unsupported-field',\n `Symbols of role \"${role}\" carry no reference designator.`,\n [...path, 'reference'],\n );\n }\n }\n if (\n id === undefined ||\n device === undefined ||\n x === undefined ||\n y === undefined ||\n rotation === undefined ||\n (value['reference'] !== undefined && reference === undefined)\n ) {\n return undefined;\n }\n return {\n id,\n device,\n x,\n y,\n rotation,\n ...(properties === undefined ? {} : { properties }),\n ...(designator === undefined ? {} : { designator }),\n ...(net === undefined ? {} : { net }),\n ...(reference === undefined ? {} : { reference }),\n };\n}\n\n/**\n * Reads a field that only some symbol roles may carry, so the format cannot describe a power\n * symbol with a reference designator or a resistor with a net name.\n */\nfunction readRoleField(\n value: Record<string, unknown>,\n field: 'designator' | 'net',\n device: string | undefined,\n path: readonly string[],\n diagnostics: Diagnostic[],\n allowed: (role: SymbolRole) => boolean,\n): string | undefined {\n const raw = value[field];\n if (raw === undefined || device === undefined) {\n return undefined;\n }\n const role = symbolRole(device);\n if (!allowed(role)) {\n report(\n diagnostics,\n 'symbol/unsupported-field',\n `Symbols of role \"${role}\" must not declare \"${field}\".`,\n [...path, field],\n );\n return undefined;\n }\n return readStringField(value, field, path, diagnostics, { nonEmpty: true });\n}\n\nfunction readWire(\n value: unknown,\n path: readonly string[],\n diagnostics: Diagnostic[],\n): SchematicWire | undefined {\n if (!isRecord(value)) {\n report(diagnostics, 'schema/invalid-type', 'Wire must be an object.', path);\n return undefined;\n }\n forbidUnknownFields(value, ['id', 'points'], path, diagnostics);\n const id = readId(value, path, diagnostics);\n const rawPoints = readArrayField(value, 'points', path, diagnostics);\n const points: Point[] = [];\n if (rawPoints !== undefined) {\n if (rawPoints.length < 2) {\n report(diagnostics, 'wire/invalid-points', 'Wire must contain at least two points.', [\n ...path,\n 'points',\n ]);\n }\n rawPoints.forEach((item, index) => {\n const point = readPoint(item, [...path, 'points', String(index)], diagnostics);\n if (point !== undefined) {\n points.push(point);\n }\n });\n }\n if (id === undefined || rawPoints === undefined) {\n return undefined;\n }\n for (let index = 1; index < points.length; index += 1) {\n const previous = points[index - 1];\n const current = points[index];\n if (previous === undefined || current === undefined) {\n continue;\n }\n if (previous.x !== current.x && previous.y !== current.y) {\n report(diagnostics, 'wire/not-orthogonal', 'Wire segments must be horizontal or vertical.', [\n ...path,\n 'points',\n String(index),\n ]);\n return undefined;\n }\n }\n return { id, points };\n}\n\nfunction readJunction(\n value: unknown,\n path: readonly string[],\n diagnostics: Diagnostic[],\n): SchematicJunction | undefined {\n if (!isRecord(value)) {\n report(diagnostics, 'schema/invalid-type', 'Junction must be an object.', path);\n return undefined;\n }\n forbidUnknownFields(value, ['id', 'x', 'y', 'wires'], path, diagnostics);\n const id = readId(value, path, diagnostics);\n const x = readNumberField(value, 'x', path, diagnostics);\n const y = readNumberField(value, 'y', path, diagnostics);\n const rawWires = readArrayField(value, 'wires', path, diagnostics);\n const wires: string[] = [];\n if (rawWires !== undefined) {\n if (rawWires.length < 2) {\n report(diagnostics, 'schema/invalid-value', 'Junction must reference at least two wires.', [\n ...path,\n 'wires',\n ]);\n }\n rawWires.forEach((item, index) => {\n const wirePath = [...path, 'wires', String(index)];\n if (typeof item !== 'string') {\n report(\n diagnostics,\n 'schema/invalid-type',\n 'Junction wire reference must be a string.',\n wirePath,\n );\n return;\n }\n if (item.length === 0) {\n report(\n diagnostics,\n 'schema/invalid-value',\n 'Junction wire reference must not be empty.',\n wirePath,\n );\n return;\n }\n wires.push(item);\n });\n }\n if (id === undefined || x === undefined || y === undefined || rawWires === undefined) {\n return undefined;\n }\n return { id, x, y, wires };\n}\n\nfunction readId(\n value: Record<string, unknown>,\n path: readonly string[],\n diagnostics: Diagnostic[],\n): string | undefined {\n const id = readStringField(value, 'id', path, diagnostics, { nonEmpty: true });\n if (id === undefined) {\n return undefined;\n }\n if (!isUuidV4(id)) {\n report(diagnostics, 'schema/invalid-value', 'Field \"id\" must be a UUID v4.', [...path, 'id']);\n return undefined;\n }\n return id;\n}\n","import type { SchematicDocument } from '../../format/types';\nimport type { PropertyValue } from '../../format/value';\n\n/** Serializes with a fixed field order and 2-space indentation, matching the examples in #6. */\nexport function serializeSchematic(document: SchematicDocument): string {\n const serializable = {\n version: document.version,\n sheet: {\n symbols: document.sheet.symbols.map((symbol) => {\n const serialized: Record<string, unknown> = {\n id: symbol.id,\n device: symbol.device,\n x: symbol.x,\n y: symbol.y,\n rotation: symbol.rotation,\n };\n if (symbol.properties !== undefined && Object.keys(symbol.properties).length > 0) {\n serialized['properties'] = sortProperties(symbol.properties);\n }\n // Role-scoped fields are written explicitly so the file states what the symbol is for.\n if (symbol.designator !== undefined) {\n serialized['designator'] = symbol.designator;\n }\n if (symbol.net !== undefined) {\n serialized['net'] = symbol.net;\n }\n if (symbol.reference !== undefined) {\n serialized['reference'] = { x: symbol.reference.x, y: symbol.reference.y };\n }\n return serialized;\n }),\n wires: document.sheet.wires.map((wire) => ({\n id: wire.id,\n points: wire.points.map((point) => ({ x: point.x, y: point.y })),\n })),\n junctions: document.sheet.junctions.map((junction) => ({\n id: junction.id,\n x: junction.x,\n y: junction.y,\n wires: [...junction.wires],\n })),\n },\n };\n return `${JSON.stringify(serializable, null, 2)}\\n`;\n}\n\nfunction sortProperties(\n properties: Readonly<Record<string, PropertyValue>>,\n): Record<string, PropertyValue> {\n const sorted: Record<string, PropertyValue> = Object.create(null);\n for (const key of Object.keys(properties).sort()) {\n const value = properties[key];\n if (value !== undefined) {\n sorted[key] = value;\n }\n }\n return sorted;\n}\n","import type { Rect } from '../../format/types';\nimport type { Point } from '../../format/value';\n\n/** Default comparison tolerance, in page units. */\nexport const DEFAULT_TOLERANCE = 0;\n\nexport function distance(a: Point, b: Point): number {\n return Math.hypot(b.x - a.x, b.y - a.y);\n}\n\nexport function samePoint(a: Point, b: Point): boolean {\n return a.x === b.x && a.y === b.y;\n}\n\nexport function pointsEqual(a: Point, b: Point, tolerance = DEFAULT_TOLERANCE): boolean {\n return distance(a, b) <= tolerance;\n}\n\n/** Closest point on the closed segment `a`–`b`, plus its position `t` in `[0, 1]`. */\nexport function projectOnSegment(\n point: Point,\n a: Point,\n b: Point,\n): { readonly x: number; readonly y: number; readonly t: number } {\n const dx = b.x - a.x;\n const dy = b.y - a.y;\n const lengthSquared = dx * dx + dy * dy;\n if (lengthSquared === 0) {\n return { x: a.x, y: a.y, t: 0 };\n }\n const raw = ((point.x - a.x) * dx + (point.y - a.y) * dy) / lengthSquared;\n const t = raw < 0 ? 0 : raw > 1 ? 1 : raw;\n return { x: a.x + dx * t, y: a.y + dy * t, t };\n}\n\nexport interface SegmentProjection {\n /** Closest point of the polyline. */\n readonly point: Point;\n /** Index of the segment that holds the closest point. */\n readonly segment: number;\n /** Position along that segment, in `[0, 1]`. */\n readonly t: number;\n readonly distance: number;\n}\n\n/** Closest point on a polyline, with the segment it belongs to; `undefined` when empty. */\nexport function nearestPointOnPolyline(\n points: readonly Point[],\n point: Point,\n): SegmentProjection | undefined {\n let best: SegmentProjection | undefined;\n for (let index = 1; index < points.length; index += 1) {\n const a = points[index - 1];\n const b = points[index];\n if (a === undefined || b === undefined) {\n continue;\n }\n const projected = projectOnSegment(point, a, b);\n const candidate: SegmentProjection = {\n point: { x: projected.x, y: projected.y },\n segment: index - 1,\n t: projected.t,\n distance: distance(point, projected),\n };\n if (best === undefined || candidate.distance < best.distance) {\n best = candidate;\n }\n }\n const only = points[0];\n if (best === undefined && only !== undefined) {\n return { point: only, segment: 0, t: 0, distance: distance(point, only) };\n }\n return best;\n}\n\n/** Point at position `t` along segment `segment` of a polyline. */\nexport function pointOnPolylineAt(\n points: readonly Point[],\n segment: number,\n t: number,\n): Point | undefined {\n const a = points[segment];\n if (a === undefined) {\n return undefined;\n }\n const b = points[segment + 1] ?? a;\n return { x: a.x + (b.x - a.x) * t, y: a.y + (b.y - a.y) * t };\n}\n\n/** True when `point` lies on the closed segment `a`–`b`, within `tolerance`. */\nexport function pointOnSegment(\n point: Point,\n a: Point,\n b: Point,\n tolerance = DEFAULT_TOLERANCE,\n): boolean {\n const dx = b.x - a.x;\n const dy = b.y - a.y;\n const length = Math.hypot(dx, dy);\n if (length === 0) {\n return pointsEqual(point, a, tolerance);\n }\n const area = (point.x - a.x) * dy - (point.y - a.y) * dx;\n if (Math.abs(area) / length > tolerance) {\n return false;\n }\n const projection = ((point.x - a.x) * dx + (point.y - a.y) * dy) / (length * length);\n const overhang = tolerance / length;\n if (projection < -overhang || projection > 1 + overhang) {\n return false;\n }\n return distanceToSegment(point, a, b) <= tolerance;\n}\n\nexport function distanceToSegment(point: Point, a: Point, b: Point): number {\n const dx = b.x - a.x;\n const dy = b.y - a.y;\n const lengthSquared = dx * dx + dy * dy;\n if (lengthSquared === 0) {\n return distance(point, a);\n }\n const t = ((point.x - a.x) * dx + (point.y - a.y) * dy) / lengthSquared;\n const clamped = t < 0 ? 0 : t > 1 ? 1 : t;\n return distance(point, { x: a.x + clamped * dx, y: a.y + clamped * dy });\n}\n\n/** True when `point` lies on any segment of the polyline, endpoints included. */\nexport function pointOnPolyline(\n points: readonly Point[],\n point: Point,\n tolerance = DEFAULT_TOLERANCE,\n): boolean {\n if (points.length === 1) {\n const [only] = points;\n return only !== undefined && pointsEqual(only, point, tolerance);\n }\n for (let index = 1; index < points.length; index += 1) {\n const previous = points[index - 1];\n const current = points[index];\n if (\n previous !== undefined &&\n current !== undefined &&\n pointOnSegment(point, previous, current, tolerance)\n ) {\n return true;\n }\n }\n return false;\n}\n\nexport function boundsOfPoints(points: readonly Point[]): Rect | undefined {\n const [first, ...rest] = points;\n if (first === undefined) {\n return undefined;\n }\n let minX = first.x;\n let minY = first.y;\n let maxX = first.x;\n let maxY = first.y;\n for (const point of rest) {\n minX = Math.min(minX, point.x);\n minY = Math.min(minY, point.y);\n maxX = Math.max(maxX, point.x);\n maxY = Math.max(maxY, point.y);\n }\n return { x: minX, y: minY, width: maxX - minX, height: maxY - minY };\n}\n\nexport function unionBounds(a: Rect | undefined, b: Rect | undefined): Rect | undefined {\n if (a === undefined) {\n return b;\n }\n if (b === undefined) {\n return a;\n }\n const minX = Math.min(a.x, b.x);\n const minY = Math.min(a.y, b.y);\n const maxX = Math.max(a.x + a.width, b.x + b.width);\n const maxY = Math.max(a.y + a.height, b.y + b.height);\n return { x: minX, y: minY, width: maxX - minX, height: maxY - minY };\n}\n","import type { Placement, Rect } from '../../format/types';\nimport type { Point } from '../../format/value';\nimport type { PinAnchor } from '../device/symbol';\nimport { boundsOfPoints } from './point';\n\n/** Rotates counter-clockwise around the origin. Rotation is expressed in degrees. */\nexport function rotatePoint(point: Point, degrees: number): Point {\n const radians = (degrees * Math.PI) / 180;\n const cos = Math.cos(radians);\n const sin = Math.sin(radians);\n return {\n x: point.x * cos - point.y * sin,\n y: point.x * sin + point.y * cos,\n };\n}\n\n/** Applies a symbol placement to a pre-placement anchor. */\nexport function symbolPinPosition(placement: Placement, anchor: PinAnchor): Point {\n const rotated = rotatePoint(anchor, placement.rotation);\n return { x: placement.x + rotated.x, y: placement.y + rotated.y };\n}\n\n/** Distance between the reference default anchor and the body's top-left corner. */\nexport const REFERENCE_DEFAULT_OFFSET = 4;\n\n/**\n * Local anchor of a symbol's reference designator: the explicit override, else the body's\n * top-left corner lifted by {@link REFERENCE_DEFAULT_OFFSET}.\n */\nexport function referenceAnchor(outline: Rect | undefined, override?: Point): Point {\n if (override !== undefined) {\n return { x: override.x, y: override.y };\n }\n if (outline === undefined) {\n return { x: 0, y: -REFERENCE_DEFAULT_OFFSET };\n }\n return { x: outline.x, y: outline.y - REFERENCE_DEFAULT_OFFSET };\n}\n\n/** World position of a symbol's reference designator anchor. */\nexport function referencePosition(\n placement: Placement,\n outline: Rect | undefined,\n override?: Point,\n): Point {\n return symbolPinPosition(placement, referenceAnchor(outline, override));\n}\n\n/** Bounding box of a symbol: its transformed outline, else its pins, else its origin. */\nexport function symbolBounds(\n placement: Placement,\n outline: Rect | undefined,\n pins: Readonly<Record<string, PinAnchor>>,\n): Rect | undefined {\n if (outline !== undefined) {\n const corners: Point[] = [\n { x: outline.x, y: outline.y },\n { x: outline.x + outline.width, y: outline.y },\n { x: outline.x, y: outline.y + outline.height },\n { x: outline.x + outline.width, y: outline.y + outline.height },\n ];\n return boundsOfPoints(corners.map((corner) => symbolPinPosition(placement, corner)));\n }\n const anchors = Object.values(pins).map((anchor) => symbolPinPosition(placement, anchor));\n if (anchors.length > 0) {\n return boundsOfPoints(anchors);\n }\n return { x: placement.x, y: placement.y, width: 0, height: 0 };\n}\n","import type { Diagnostic } from '../../format/diagnostics';\nimport { throwIfErrors } from '../../format/errors';\nimport type { Rect, SchematicDocument } from '../../format/types';\nimport type { Point } from '../../format/value';\nimport { builtinSymbolKind, netNameOf, parseDeviceReference } from '../device/reference';\nimport type { DeviceSymbolProvider } from '../device/symbol';\nimport {\n boundsOfPoints,\n pointOnPolyline,\n pointsEqual,\n unionBounds,\n DEFAULT_TOLERANCE,\n} from '../geometry/point';\nimport { symbolBounds, symbolPinPosition } from '../geometry/transform';\n\nexport interface SchematicPinInstance {\n readonly symbolId: string;\n readonly pinId: string;\n readonly position: Point;\n /** True when the pin is not connected to any wire, label or other pin. */\n readonly open: boolean;\n /** Name of the net the pin belongs to; `null` for anonymous nets. */\n readonly netName: string | null;\n}\n\nexport type SchematicNetMember =\n | { readonly kind: 'pin'; readonly symbolId: string; readonly pinId: string }\n | { readonly kind: 'label'; readonly symbolId: string }\n | { readonly kind: 'power'; readonly symbolId: string }\n | { readonly kind: 'ground'; readonly symbolId: string };\n\nexport interface SchematicNet {\n /** Name contributed by the single naming connection point; `null` when anonymous. */\n readonly name: string | null;\n readonly wireIds: readonly string[];\n readonly members: readonly SchematicNetMember[];\n}\n\nexport interface DanglingWireEnd {\n readonly wireId: string;\n readonly end: 'start' | 'end';\n readonly point: Point;\n}\n\nexport interface SchematicTopologyOptions {\n readonly devices?: DeviceSymbolProvider;\n /** Coordinate comparison tolerance in page units; defaults to exact matching. */\n readonly tolerance?: number;\n}\n\nexport interface SchematicTopology {\n readonly nets: readonly SchematicNet[];\n readonly pins: readonly SchematicPinInstance[];\n readonly danglingWireEnds: readonly DanglingWireEnd[];\n /** Bounding box of all wires, pins and symbol outlines. */\n readonly bounds: Rect | undefined;\n}\n\ntype Connection =\n | {\n readonly kind: 'pin';\n readonly symbolId: string;\n readonly pinId: string;\n readonly point: Point;\n }\n | {\n readonly kind: 'label' | 'power' | 'ground';\n readonly symbolId: string;\n readonly point: Point;\n /** Net name contributed by this connection point. */\n readonly name: string;\n };\n\n/**\n * Derives nets from wires, explicit junctions and symbol connection points (#6).\n *\n * @throws {SchematicError} when a device cannot be resolved or a net has conflicting labels.\n */\nexport function deriveSchematicTopology(\n document: SchematicDocument,\n options: SchematicTopologyOptions = {},\n): SchematicTopology {\n const diagnostics: Diagnostic[] = [];\n const tolerance = options.tolerance ?? DEFAULT_TOLERANCE;\n const { devices } = options;\n const { symbols, wires, junctions } = document.sheet;\n\n const connections: Connection[] = [];\n let bounds: Rect | undefined;\n\n for (const symbol of symbols) {\n bounds = unionBounds(bounds, { x: symbol.x, y: symbol.y, width: 0, height: 0 });\n const builtin = builtinSymbolKind(symbol.device);\n if (builtin !== undefined) {\n const net = netNameOf(symbol);\n if (net !== undefined) {\n connections.push({\n kind: builtin,\n symbolId: symbol.id,\n point: { x: symbol.x, y: symbol.y },\n name: net,\n });\n }\n continue;\n }\n\n const reference = parseDeviceReference(symbol.device);\n if (reference === undefined) {\n if (devices !== undefined) {\n diagnostics.push({\n severity: 'error',\n code: 'device/invalid-reference',\n message: `Symbol \"${symbol.id}\" has an invalid device reference ${JSON.stringify(symbol.device)}.`,\n entity: { kind: 'symbol', id: symbol.id },\n });\n }\n continue;\n }\n if (devices === undefined) {\n continue;\n }\n\n const definition = devices.getDeviceSymbol(reference);\n const name = devices.getDeviceName(reference);\n if (name === undefined) {\n diagnostics.push({\n severity: 'error',\n code: 'device/unresolved',\n message: `Symbol \"${symbol.id}\" references unresolved device ${JSON.stringify(symbol.device)}.`,\n entity: { kind: 'symbol', id: symbol.id },\n });\n continue;\n }\n if (definition === undefined) {\n continue;\n }\n\n bounds = unionBounds(bounds, symbolBounds(symbol, definition.bounds, definition.pins));\n for (const [pinId, anchor] of Object.entries(definition.pins)) {\n const position = symbolPinPosition(symbol, anchor);\n connections.push({ kind: 'pin', symbolId: symbol.id, pinId, point: position });\n bounds = unionBounds(bounds, { x: position.x, y: position.y, width: 0, height: 0 });\n }\n }\n\n for (const wire of wires) {\n bounds = unionBounds(bounds, boundsOfPoints(wire.points));\n }\n\n const wireIndex = new Map<string, number>();\n wires.forEach((wire, index) => wireIndex.set(wire.id, index));\n const wireCount = wires.length;\n const parent = new Array<number>(wireCount + connections.length);\n for (let index = 0; index < parent.length; index += 1) {\n parent[index] = index;\n }\n\n const find = (node: number): number => {\n let root = node;\n while (parent[root] !== root) {\n const next = parent[root] as number;\n parent[root] = parent[next] as number;\n root = next;\n }\n return root;\n };\n\n const union = (a: number, b: number): void => {\n const rootA = find(a);\n const rootB = find(b);\n if (rootA !== rootB) {\n parent[rootB] = rootA;\n }\n };\n\n for (const junction of junctions) {\n const targets = junction.wires\n .map((wireId) => wireIndex.get(wireId))\n .filter((index): index is number => index !== undefined);\n const [first, ...rest] = targets;\n if (first === undefined) {\n continue;\n }\n for (const target of rest) {\n union(first, target);\n }\n }\n\n /** Wire index → connection indexes attached to it. */\n const wireAttachments = new Map<number, number[]>();\n connections.forEach((connection, connectionIndex) => {\n wires.forEach((wire, index) => {\n if (!pointOnPolyline(wire.points, connection.point, tolerance)) {\n return;\n }\n union(index, wireCount + connectionIndex);\n const attached = wireAttachments.get(index);\n if (attached === undefined) {\n wireAttachments.set(index, [connectionIndex]);\n } else {\n attached.push(connectionIndex);\n }\n });\n });\n\n const groups = new Map<number, { wires: number[]; connections: number[] }>();\n const groupOf = (root: number): { wires: number[]; connections: number[] } => {\n const existing = groups.get(root);\n if (existing !== undefined) {\n return existing;\n }\n const created = { wires: [], connections: [] };\n groups.set(root, created);\n return created;\n };\n wires.forEach((_, index) => {\n groupOf(find(index)).wires.push(index);\n });\n connections.forEach((_, connectionIndex) => {\n groupOf(find(wireCount + connectionIndex)).connections.push(connectionIndex);\n });\n\n const netOfConnection = new Map<number, SchematicNet>();\n const nets: SchematicNet[] = [];\n for (const group of mergeGroupsByName(groups, connections, diagnostics)) {\n const connected = group.wires.length > 0 || group.connections.length >= 2;\n if (group.connections.length === 0 || !connected) {\n continue;\n }\n const name = group.name;\n\n const members: SchematicNetMember[] = group.connections\n .map((index) => connections[index])\n .map((connection): SchematicNetMember | undefined => {\n if (connection === undefined) {\n return undefined;\n }\n return connection.kind === 'pin'\n ? { kind: 'pin', symbolId: connection.symbolId, pinId: connection.pinId }\n : { kind: connection.kind, symbolId: connection.symbolId };\n })\n .filter((member): member is SchematicNetMember => member !== undefined)\n .sort(compareMembers);\n\n const net: SchematicNet = {\n name,\n wireIds: group.wires\n .map((index) => wires[index]?.id)\n .filter((id): id is string => id !== undefined)\n .sort(),\n members,\n };\n nets.push(net);\n for (const index of group.connections) {\n netOfConnection.set(index, net);\n }\n }\n\n const pins: SchematicPinInstance[] = [];\n connections.forEach((connection, index) => {\n if (connection.kind !== 'pin') {\n return;\n }\n const net = netOfConnection.get(index);\n pins.push({\n symbolId: connection.symbolId,\n pinId: connection.pinId,\n position: connection.point,\n open: net === undefined,\n netName: net?.name ?? null,\n });\n });\n pins.sort((a, b) => a.symbolId.localeCompare(b.symbolId) || a.pinId.localeCompare(b.pinId));\n\n const danglingWireEnds: DanglingWireEnd[] = [];\n wires.forEach((wire, index) => {\n const endpoints: readonly { end: 'start' | 'end'; point: Point | undefined }[] = [\n { end: 'start', point: wire.points[0] },\n { end: 'end', point: wire.points[wire.points.length - 1] },\n ];\n for (const { end, point } of endpoints) {\n if (point === undefined) {\n continue;\n }\n const attached = (wireAttachments.get(index) ?? []).some((connectionIndex) => {\n const connection = connections[connectionIndex];\n return connection !== undefined && pointsEqual(connection.point, point, tolerance);\n });\n const junctioned = junctions.some(\n (junction) =>\n junction.wires.includes(wire.id) &&\n pointsEqual({ x: junction.x, y: junction.y }, point, tolerance),\n );\n if (!attached && !junctioned) {\n danglingWireEnds.push({ wireId: wire.id, end, point });\n }\n }\n });\n danglingWireEnds.sort((a, b) => a.wireId.localeCompare(b.wireId) || a.end.localeCompare(b.end));\n\n throwIfErrors(diagnostics);\n\n return {\n nets: nets.sort(\n (a, b) => compareNetNames(a.name, b.name) || compareMembers(a.members[0], b.members[0]),\n ),\n pins,\n danglingWireEnds,\n bounds,\n };\n}\n\n/** A connected group of wires and connection points, named by the labels attached to it. */\ninterface NetGroup {\n readonly wires: number[];\n readonly connections: number[];\n readonly name: string | null;\n}\n\n/**\n * Folds groups that carry the same net name into one group: net names are the merge key, so two\n * `VCC` ports on separate wires are the same net (KiCad-style name-based connectivity).\n * A group that declares two different names is an error.\n */\nfunction mergeGroupsByName(\n groups: ReadonlyMap<number, { wires: number[]; connections: number[] }>,\n connections: readonly Connection[],\n diagnostics: Diagnostic[],\n): readonly NetGroup[] {\n const byName = new Map<string, { wires: number[]; connections: number[] }>();\n const merged: NetGroup[] = [];\n for (const group of groups.values()) {\n const names = group.connections\n .map((index) => connections[index])\n .filter(\n (connection): connection is Extract<Connection, { kind: 'label' | 'power' | 'ground' }> =>\n connection !== undefined && connection.kind !== 'pin',\n )\n .map((connection) => connection.name)\n .sort();\n if (names.length > 1) {\n diagnostics.push({\n severity: 'error',\n code: 'net/naming-conflict',\n message: `Net has conflicting names: ${names.map((item) => JSON.stringify(item)).join(', ')}.`,\n });\n }\n const name = names.length === 1 ? (names[0] as string) : null;\n // Only groups that already connect something are folded together: merging is about joining\n // nets, not about giving free-floating labels a net of their own.\n if (name === null || (group.wires.length === 0 && group.connections.length < 2)) {\n merged.push({ wires: group.wires, connections: group.connections, name });\n continue;\n }\n const existing = byName.get(name);\n if (existing === undefined) {\n const created = { wires: [...group.wires], connections: [...group.connections] };\n byName.set(name, created);\n merged.push({ ...created, name });\n continue;\n }\n existing.wires.push(...group.wires);\n existing.connections.push(...group.connections);\n }\n return merged;\n}\n\nconst KIND_ORDER: readonly SchematicNetMember['kind'][] = ['label', 'power', 'ground', 'pin'];\n\nfunction compareMembers(\n a: SchematicNetMember | undefined,\n b: SchematicNetMember | undefined,\n): number {\n if (a === undefined || b === undefined) {\n return a === undefined ? (b === undefined ? 0 : 1) : -1;\n }\n if (a.kind !== b.kind) {\n return KIND_ORDER.indexOf(a.kind) - KIND_ORDER.indexOf(b.kind);\n }\n const bySymbol = a.symbolId.localeCompare(b.symbolId);\n if (bySymbol !== 0) {\n return bySymbol;\n }\n const pinA = a.kind === 'pin' ? a.pinId : '';\n const pinB = b.kind === 'pin' ? b.pinId : '';\n return pinA.localeCompare(pinB);\n}\n\nfunction compareNetNames(a: string | null, b: string | null): number {\n if (a === null || b === null) {\n return a === null ? (b === null ? 0 : 1) : -1;\n }\n return a.localeCompare(b);\n}\n","import { parseSchematic } from '../format/parse-schematic';\nimport type { SchematicDocument } from '../../format/types';\nimport {\n deriveSchematicTopology,\n type SchematicTopology,\n type SchematicTopologyOptions,\n} from '../netlist/derive';\n\nexport type LoadSchematicOptions = SchematicTopologyOptions;\n\nexport interface LoadedSchematic {\n readonly document: SchematicDocument;\n readonly topology: SchematicTopology;\n}\n\n/** Parses a schematic and derives its topology. @throws {SchematicError} on any contract violation. */\nexport function loadSchematic(\n source: string | SchematicDocument,\n options: LoadSchematicOptions = {},\n): LoadedSchematic {\n const document = parseSchematic(source);\n return { document, topology: deriveSchematicTopology(document, options) };\n}\n","import { isAssetReference } from '../../format/value';\nimport type { PropertyValue } from '../../format/value';\nimport { isRecord } from '../../format/validate';\nimport type { DevicePropertyEditor } from './metadata';\n\n/** Property value types a device may declare (#7). */\nexport const PROPERTY_TYPES = [\n 'string',\n 'integer',\n 'number',\n 'boolean',\n 'color',\n 'enum',\n 'image',\n 'binary',\n] as const;\n\nexport type PropertyType = (typeof PROPERTY_TYPES)[number];\n\nexport interface PropertyOption {\n readonly value: string;\n readonly label: string;\n}\n\n/**\n * Descriptor of one device property (#7). `default` is the declared default, `title` falls back to\n * the key, and the remaining fields carry the constraints of the type.\n */\nexport interface PropertyDescriptor {\n readonly key: string;\n readonly type: PropertyType;\n readonly required?: boolean;\n readonly group?: string;\n readonly order?: number;\n readonly editor?: DevicePropertyEditor;\n readonly title?: string;\n readonly description?: string;\n /** Declared default; absent when the description omits it or it breaks its own constraints. */\n readonly default?: PropertyValue;\n /** When true an explicit `null` is a valid instance value. */\n readonly nullable?: boolean;\n /** `string`: maximum length in Unicode code points. */\n readonly maxLength?: number;\n /** `integer` / `number`: closed lower bound. */\n readonly min?: number;\n /** `integer` / `number`: closed upper bound. */\n readonly max?: number;\n /** `number`: open lower bound; mutually exclusive with `min`. */\n readonly exclusiveMin?: number;\n /** `integer` / `number`: editing step, always greater than zero. */\n readonly step?: number;\n /** `number`: display unit of the stored value. */\n readonly unit?: string;\n /** `color`: whether `#RRGGBBAA` values are accepted. */\n readonly alpha?: boolean;\n /** `enum`: non-empty option list. */\n readonly options?: readonly PropertyOption[];\n /** `image` / `binary`: host-side payload limit in bytes. */\n readonly maxBytes?: number;\n /** `image`: host-side pixel limit. */\n readonly maxPixels?: number;\n}\n\nexport interface PropertyValueProblem {\n readonly code: 'schema/invalid-type' | 'schema/invalid-value';\n readonly message: string;\n}\n\nconst COLOR_PATTERN = /^#([0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/;\n\nexport function isPropertyType(value: unknown): value is PropertyType {\n return typeof value === 'string' && (PROPERTY_TYPES as readonly string[]).includes(value);\n}\n\n/** Uppercases a `#RRGGBB` / `#RRGGBBAA` color; `undefined` when the text is not a color. */\nexport function normalizeColor(value: string): string | undefined {\n return COLOR_PATTERN.test(value) ? value.toUpperCase() : undefined;\n}\n\n/** Parses one declared property; `undefined` when the type is unknown or the descriptor unusable. */\nexport function parsePropertyDescriptor(key: string, raw: unknown): PropertyDescriptor | undefined {\n if (!isRecord(raw)) {\n return undefined;\n }\n const type = raw['type'];\n if (!isPropertyType(type)) {\n return undefined;\n }\n const draft: {\n -readonly [K in keyof PropertyDescriptor]: PropertyDescriptor[K];\n } = { key, type };\n\n const title = readText(raw['title']);\n if (title !== undefined) {\n draft.title = title;\n }\n const description = readText(raw['description']);\n if (description !== undefined) {\n draft.description = description;\n }\n if (raw['nullable'] === true) {\n draft.nullable = true;\n }\n\n if (type === 'string') {\n const maxLength = readCount(raw['maxLength']);\n if (maxLength !== undefined) {\n draft.maxLength = maxLength;\n }\n }\n if (type === 'integer' || type === 'number') {\n const min = readFinite(raw['min']);\n if (min !== undefined) {\n draft.min = min;\n }\n const max = readFinite(raw['max']);\n if (max !== undefined) {\n draft.max = max;\n }\n const step = readFinite(raw['step']);\n if (step !== undefined && step > 0) {\n draft.step = step;\n }\n if (type === 'number') {\n const exclusiveMin = readFinite(raw['exclusiveMin']);\n if (exclusiveMin !== undefined) {\n draft.exclusiveMin = exclusiveMin;\n }\n const unit = readText(raw['unit']);\n if (unit !== undefined) {\n draft.unit = unit;\n }\n }\n }\n if (type === 'color' && raw['alpha'] === true) {\n draft.alpha = true;\n }\n if (type === 'enum') {\n const options = readOptions(raw['options']);\n if (options === undefined) {\n return undefined;\n }\n draft.options = options;\n }\n if (type === 'image' || type === 'binary') {\n const maxBytes = readCount(raw['maxBytes']);\n if (maxBytes !== undefined) {\n draft.maxBytes = maxBytes;\n }\n if (type === 'image') {\n const maxPixels = readCount(raw['maxPixels']);\n if (maxPixels !== undefined) {\n draft.maxPixels = maxPixels;\n }\n }\n }\n\n const defaultValue = raw['default'];\n if (defaultValue !== undefined && propertyValueProblem(draft, defaultValue) === undefined) {\n draft.default = defaultValue as PropertyValue;\n }\n return draft;\n}\n\n/** Parses the `properties` object of a device description, skipping unusable declarations. */\nexport function readPropertyDescriptors(raw: unknown): ReadonlyMap<string, PropertyDescriptor> {\n const descriptors = new Map<string, PropertyDescriptor>();\n if (!isRecord(raw)) {\n return descriptors;\n }\n for (const [key, value] of Object.entries(raw)) {\n if (key.length === 0) {\n continue;\n }\n const descriptor = parsePropertyDescriptor(key, value);\n if (descriptor !== undefined) {\n descriptors.set(key, descriptor);\n }\n }\n return descriptors;\n}\n\n/** Constraint violation of `value` for `descriptor`; `undefined` when the value is acceptable. */\nexport function propertyValueProblem(\n descriptor: PropertyDescriptor,\n value: unknown,\n): PropertyValueProblem | undefined {\n const key = descriptor.key;\n if (value === null) {\n return descriptor.nullable === true\n ? undefined\n : { code: 'schema/invalid-value', message: `Property \"${key}\" is not nullable.` };\n }\n switch (descriptor.type) {\n case 'string': {\n if (typeof value !== 'string') {\n return { code: 'schema/invalid-type', message: `Property \"${key}\" must be a string.` };\n }\n const maxLength = descriptor.maxLength;\n if (maxLength !== undefined && [...value].length > maxLength) {\n return {\n code: 'schema/invalid-value',\n message: `Property \"${key}\" must be at most ${String(maxLength)} characters.`,\n };\n }\n return undefined;\n }\n case 'integer': {\n if (typeof value !== 'number' || !Number.isSafeInteger(value)) {\n return {\n code: 'schema/invalid-type',\n message: `Property \"${key}\" must be a safe integer.`,\n };\n }\n return boundProblem(descriptor, value);\n }\n case 'number': {\n if (typeof value !== 'number' || !Number.isFinite(value)) {\n return {\n code: 'schema/invalid-type',\n message: `Property \"${key}\" must be a finite number.`,\n };\n }\n if (descriptor.exclusiveMin !== undefined && value <= descriptor.exclusiveMin) {\n return {\n code: 'schema/invalid-value',\n message: `Property \"${key}\" must be greater than ${String(descriptor.exclusiveMin)}.`,\n };\n }\n return boundProblem(descriptor, value);\n }\n case 'boolean':\n return typeof value === 'boolean'\n ? undefined\n : { code: 'schema/invalid-type', message: `Property \"${key}\" must be a boolean.` };\n case 'color': {\n if (typeof value !== 'string') {\n return { code: 'schema/invalid-type', message: `Property \"${key}\" must be a string.` };\n }\n const normalized = normalizeColor(value);\n if (normalized === undefined) {\n return {\n code: 'schema/invalid-value',\n message: `Property \"${key}\" must be a \"#RRGGBB\" color.`,\n };\n }\n if (descriptor.alpha !== true && normalized.length === 9) {\n return {\n code: 'schema/invalid-value',\n message: `Property \"${key}\" does not accept alpha; use \"#RRGGBB\".`,\n };\n }\n return undefined;\n }\n case 'enum': {\n if (typeof value !== 'string') {\n return { code: 'schema/invalid-type', message: `Property \"${key}\" must be a string.` };\n }\n const allowed = (descriptor.options ?? []).map((option) => option.value);\n return allowed.includes(value)\n ? undefined\n : {\n code: 'schema/invalid-value',\n message: `Property \"${key}\" must be one of ${allowed.map((entry) => JSON.stringify(entry)).join(', ')}.`,\n };\n }\n case 'image':\n case 'binary':\n return isAssetReference(value)\n ? undefined\n : {\n code: 'schema/invalid-type',\n message: `Property \"${key}\" must be a resource reference { \"src\", \"mode\" }.`,\n };\n }\n}\n\n/** Canonical stored value: colors are uppercased, everything else is stored as given. */\nexport function normalizePropertyValue(\n descriptor: PropertyDescriptor,\n value: PropertyValue,\n): PropertyValue {\n if (descriptor.type === 'color' && typeof value === 'string') {\n return normalizeColor(value) ?? value;\n }\n return value;\n}\n\nfunction boundProblem(\n descriptor: PropertyDescriptor,\n value: number,\n): PropertyValueProblem | undefined {\n const key = descriptor.key;\n if (descriptor.min !== undefined && value < descriptor.min) {\n return {\n code: 'schema/invalid-value',\n message: `Property \"${key}\" must be at least ${String(descriptor.min)}.`,\n };\n }\n if (descriptor.max !== undefined && value > descriptor.max) {\n return {\n code: 'schema/invalid-value',\n message: `Property \"${key}\" must be at most ${String(descriptor.max)}.`,\n };\n }\n return undefined;\n}\n\nfunction readText(value: unknown): string | undefined {\n return typeof value === 'string' && value.length > 0 ? value : undefined;\n}\n\nfunction readFinite(value: unknown): number | undefined {\n return typeof value === 'number' && Number.isFinite(value) ? value : undefined;\n}\n\nfunction readCount(value: unknown): number | undefined {\n return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0 ? value : undefined;\n}\n\nfunction readOptions(value: unknown): readonly PropertyOption[] | undefined {\n if (!Array.isArray(value) || value.length === 0) {\n return undefined;\n }\n const options: PropertyOption[] = [];\n const seen = new Set<string>();\n for (const entry of value) {\n if (!isRecord(entry)) {\n return undefined;\n }\n const optionValue = entry['value'];\n const label = entry['label'];\n if (\n typeof optionValue !== 'string' ||\n optionValue.length === 0 ||\n typeof label !== 'string' ||\n label.length === 0 ||\n seen.has(optionValue)\n ) {\n return undefined;\n }\n seen.add(optionValue);\n options.push({ value: optionValue, label });\n }\n return options;\n}\n","import type { SchematicDocument } from '../../format/types';\n\nexport type ElementKind = 'symbol' | 'wire' | 'junction';\n\nexport type ElementIdFactory = (kind: ElementKind, document: SchematicDocument) => string;\n\nfunction usedIds(document: SchematicDocument, kind: ElementKind): ReadonlySet<string> {\n const ids =\n kind === 'symbol'\n ? document.sheet.symbols.map((symbol) => symbol.id)\n : kind === 'wire'\n ? document.sheet.wires.map((wire) => wire.id)\n : document.sheet.junctions.map((junction) => junction.id);\n return new Set(ids);\n}\n\n/**\n * Random UUID v4, falling back to `getRandomValues` (or `Math.random` in ancient runtimes).\n * Ids are opaque identity: they never collide with the designators and net names users edit.\n */\nexport function createUuid(): string {\n const source = randomSource();\n if (typeof source?.randomUUID === 'function') {\n return source.randomUUID();\n }\n const bytes = new Uint8Array(16);\n if (typeof source?.getRandomValues === 'function') {\n source.getRandomValues(bytes);\n } else {\n for (let index = 0; index < bytes.length; index += 1) {\n bytes[index] = Math.floor(Math.random() * 256);\n }\n }\n bytes[6] = ((bytes[6] ?? 0) & 0x0f) | 0x40;\n bytes[8] = ((bytes[8] ?? 0) & 0x3f) | 0x80;\n const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, '0')).join('');\n return [\n hex.slice(0, 8),\n hex.slice(8, 12),\n hex.slice(12, 16),\n hex.slice(16, 20),\n hex.slice(20),\n ].join('-');\n}\n\n/** Web Crypto as available in browsers and Node; core does not depend on either's typings. */\ninterface RandomSource {\n randomUUID?: () => string;\n getRandomValues?: (array: Uint8Array) => Uint8Array;\n}\n\nfunction randomSource(): RandomSource | undefined {\n return (globalThis as { crypto?: RandomSource }).crypto;\n}\n\n/** Fresh UUID v4 that no element of `kind` uses yet. */\nexport const defaultElementIdFactory: ElementIdFactory = (kind, document) => {\n const used = usedIds(document, kind);\n let id = createUuid();\n while (used.has(id)) {\n id = createUuid();\n }\n return id;\n};\n","import { isAssetReference } from '../../format/value';\nimport type { Diagnostic } from '../../format/diagnostics';\nimport { throwIfErrors } from '../../format/errors';\nimport { parseSchematic } from '../format/parse-schematic';\nimport type { Point, PropertyValue } from '../../format/value';\nimport type {\n SchematicDocument,\n SchematicJunction,\n SchematicSymbol,\n SchematicWire,\n} from '../../format/types';\nimport { toPointer } from '../../format/validate';\nimport {\n normalizePropertyValue,\n propertyValueProblem,\n type PropertyDescriptor,\n} from '../device/properties';\nimport { parseDeviceReference } from '../device/reference';\nimport { defaultNetName, hasDesignator, namesNet, symbolRole } from '../device/reference';\nimport type { SymbolRole } from '../device/reference';\nimport type { SchematicTopologyOptions } from '../netlist/derive';\nimport { DEFAULT_TOLERANCE, pointOnPolyline } from '../geometry/point';\nimport { defaultElementIdFactory, type ElementIdFactory } from './ids';\n\nexport type SchematicCommand =\n | {\n readonly type: 'add-symbol';\n readonly id?: string;\n readonly device: string;\n readonly x: number;\n readonly y: number;\n readonly rotation?: number;\n readonly properties?: Readonly<Record<string, PropertyValue>>;\n /** Component reference designator; defaults to the new symbol's id. */\n readonly designator?: string;\n /** Net name for labels / power / ground; power and ground fall back to VCC / GND. */\n readonly net?: string;\n /** Reference designator anchor in symbol-local coordinates; `null` clears it. */\n readonly reference?: Point | null;\n }\n | {\n readonly type: 'update-symbol';\n readonly id: string;\n readonly device?: string;\n readonly x?: number;\n readonly y?: number;\n readonly rotation?: number;\n /** Replaces the whole property map when provided. */\n readonly properties?: Readonly<Record<string, PropertyValue>>;\n /** Reference designator; `null` clears the override, `undefined` keeps it. */\n readonly designator?: string | null;\n /** Net name; `null` clears it, `undefined` keeps it. */\n readonly net?: string | null;\n /** Reference designator anchor; `null` clears it, `undefined` keeps it. */\n readonly reference?: Point | null;\n }\n | { readonly type: 'remove-symbol'; readonly id: string }\n | {\n readonly type: 'set-symbol-property';\n readonly id: string;\n readonly key: string;\n readonly value: PropertyValue;\n }\n | { readonly type: 'remove-symbol-property'; readonly id: string; readonly key: string }\n | { readonly type: 'add-wire'; readonly id?: string; readonly points: readonly Point[] }\n | { readonly type: 'set-wire-points'; readonly id: string; readonly points: readonly Point[] }\n | { readonly type: 'remove-wire'; readonly id: string }\n | {\n readonly type: 'add-junction';\n readonly id?: string;\n readonly x: number;\n readonly y: number;\n readonly wires: readonly string[];\n }\n | {\n readonly type: 'update-junction';\n readonly id: string;\n readonly x?: number;\n readonly y?: number;\n readonly wires?: readonly string[];\n }\n | { readonly type: 'remove-junction'; readonly id: string };\n\nexport interface EditEffect {\n readonly kind: 'junction-removed';\n readonly id: string;\n readonly reason: 'wire-removed' | 'junction-detached';\n}\n\nexport interface SchematicEditOptions extends SchematicTopologyOptions {\n readonly createId?: ElementIdFactory;\n /** How to handle junctions that stop lying on a wire after its geometry changes. */\n readonly onJunctionConflict?: 'reject' | 'remove';\n /** Receives cascaded removals such as junctions dropped with their wire. */\n readonly onEffect?: (effect: EditEffect) => void;\n}\n\n/**\n * Applies an edit command to a copy of `document`.\n *\n * @throws {SchematicError} when the command is invalid; the input document is never mutated.\n */\nexport function applySchematicCommand(\n document: SchematicDocument,\n command: SchematicCommand,\n options: SchematicEditOptions = {},\n): SchematicDocument {\n const symbols = [...document.sheet.symbols];\n const wires = [...document.sheet.wires];\n const junctions = [...document.sheet.junctions];\n const diagnostics: Diagnostic[] = [];\n const effects: EditEffect[] = [];\n const createId = options.createId ?? defaultElementIdFactory;\n const draft = (): SchematicDocument => ({ ...document, sheet: { symbols, wires, junctions } });\n\n switch (command.type) {\n case 'add-symbol': {\n const device = requireDevice(command.device, diagnostics);\n const id = command.id ?? createId('symbol', draft());\n const properties = normalizeProperties(\n command.properties,\n deviceDescriptors(device, options),\n diagnostics,\n );\n const reference = resolveReference(\n command.reference,\n undefined,\n ['sheet', 'symbols'],\n diagnostics,\n );\n if (device !== undefined) {\n const role = symbolRole(device);\n const designator = resolveDesignator(command.designator, role, id, diagnostics);\n const net = resolveNet(command.net, role, diagnostics);\n symbols.push(\n withProperties(\n {\n id,\n device,\n x: command.x,\n y: command.y,\n rotation: command.rotation ?? 0,\n ...(designator === undefined ? {} : { designator }),\n ...(net === undefined ? {} : { net }),\n ...(hasDesignator(role) && reference !== undefined ? { reference } : {}),\n },\n properties,\n ),\n );\n }\n break;\n }\n case 'update-symbol': {\n const index = findIndex(symbols, command.id, 'symbol', diagnostics);\n const current = index === -1 ? undefined : symbols[index];\n if (current !== undefined) {\n const device =\n command.device === undefined\n ? current.device\n : requireDevice(command.device, diagnostics);\n const properties =\n command.properties === undefined\n ? current.properties\n : normalizeProperties(\n command.properties,\n deviceDescriptors(device, options),\n diagnostics,\n );\n const reference = resolveReference(\n command.reference,\n current.reference,\n ['sheet', 'symbols', String(index)],\n diagnostics,\n );\n if (device !== undefined) {\n const role = symbolRole(device);\n const designator = resolveOptionalText(\n command.designator,\n current.designator,\n hasDesignator(role),\n 'designator',\n diagnostics,\n );\n const net = resolveOptionalText(\n command.net,\n current.net,\n namesNet(role),\n 'net',\n diagnostics,\n );\n symbols[index] = withProperties(\n {\n id: current.id,\n device,\n x: command.x ?? current.x,\n y: command.y ?? current.y,\n rotation: command.rotation ?? current.rotation,\n ...(designator === undefined ? {} : { designator }),\n ...(net === undefined ? {} : { net }),\n ...(hasDesignator(role) && reference !== undefined ? { reference } : {}),\n },\n properties,\n );\n }\n }\n break;\n }\n case 'remove-symbol': {\n const index = findIndex(symbols, command.id, 'symbol', diagnostics);\n if (index !== -1) {\n symbols.splice(index, 1);\n }\n break;\n }\n case 'set-symbol-property': {\n const index = findIndex(symbols, command.id, 'symbol', diagnostics);\n const current = index === -1 ? undefined : symbols[index];\n if (current !== undefined) {\n const value = checkPropertyValue(\n command.key,\n command.value,\n deviceDescriptors(current.device, options)?.get(command.key),\n diagnostics,\n );\n if (value !== undefined) {\n symbols[index] = withProperties(baseOf(current), {\n ...(current.properties ?? {}),\n [command.key]: value,\n });\n }\n }\n break;\n }\n case 'remove-symbol-property': {\n const index = findIndex(symbols, command.id, 'symbol', diagnostics);\n const current = index === -1 ? undefined : symbols[index];\n if (current !== undefined) {\n const properties = { ...(current.properties ?? {}) };\n if (!Object.prototype.hasOwnProperty.call(properties, command.key)) {\n diagnostics.push({\n severity: 'error',\n code: 'edit/unknown-entity',\n message: `Symbol \"${current.id}\" has no property ${JSON.stringify(command.key)}.`,\n entity: { kind: 'symbol', id: current.id },\n });\n } else {\n delete properties[command.key];\n symbols[index] = withProperties(baseOf(current), properties);\n }\n }\n break;\n }\n case 'add-wire': {\n const id = command.id ?? createId('wire', draft());\n const wire = makeWire(id, command.points, diagnostics);\n if (wire !== undefined) {\n wires.push(wire);\n }\n break;\n }\n case 'set-wire-points': {\n const index = findIndex(wires, command.id, 'wire', diagnostics);\n if (index !== -1) {\n const wire = makeWire(command.id, command.points, diagnostics);\n if (wire !== undefined) {\n wires[index] = wire;\n }\n }\n break;\n }\n case 'remove-wire': {\n const index = findIndex(wires, command.id, 'wire', diagnostics);\n if (index !== -1) {\n wires.splice(index, 1);\n for (let junctionIndex = junctions.length - 1; junctionIndex >= 0; junctionIndex -= 1) {\n const junction = junctions[junctionIndex];\n if (junction === undefined || !junction.wires.includes(command.id)) {\n continue;\n }\n effects.push({ kind: 'junction-removed', id: junction.id, reason: 'wire-removed' });\n junctions.splice(junctionIndex, 1);\n }\n }\n break;\n }\n case 'add-junction': {\n const id = command.id ?? createId('junction', draft());\n const junction = makeJunction(id, command.x, command.y, command.wires, diagnostics);\n if (junction !== undefined) {\n junctions.push(junction);\n }\n break;\n }\n case 'update-junction': {\n const index = findIndex(junctions, command.id, 'junction', diagnostics);\n const current = index === -1 ? undefined : junctions[index];\n if (current !== undefined) {\n const junction = makeJunction(\n current.id,\n command.x ?? current.x,\n command.y ?? current.y,\n command.wires ?? current.wires,\n diagnostics,\n );\n if (junction !== undefined) {\n junctions[index] = junction;\n }\n }\n break;\n }\n case 'remove-junction': {\n const index = findIndex(junctions, command.id, 'junction', diagnostics);\n if (index !== -1) {\n junctions.splice(index, 1);\n }\n break;\n }\n default: {\n diagnostics.push({\n severity: 'error',\n code: 'edit/invalid-command',\n message: `Unsupported command ${JSON.stringify((command as { type?: unknown }).type)}.`,\n });\n }\n }\n\n throwIfErrors(diagnostics);\n\n const result = validateSheet(draft(), options, diagnostics, effects);\n throwIfErrors(diagnostics);\n\n for (const effect of effects) {\n options.onEffect?.(effect);\n }\n return result;\n}\n\nfunction validateSheet(\n candidate: SchematicDocument,\n options: SchematicEditOptions,\n diagnostics: Diagnostic[],\n effects: EditEffect[],\n): SchematicDocument {\n // Structural re-validation: ids, required fields, wire point counts, junction references.\n const parsed = parseSchematic(candidate);\n const tolerance = options.tolerance ?? DEFAULT_TOLERANCE;\n const wireById = new Map(parsed.sheet.wires.map((wire) => [wire.id, wire]));\n const survivingJunctions: SchematicJunction[] = [];\n let cascaded = false;\n\n for (const junction of parsed.sheet.junctions) {\n const detached = junction.wires.some((wireId) => {\n const wire = wireById.get(wireId);\n return (\n wire === undefined ||\n !pointOnPolyline(wire.points, { x: junction.x, y: junction.y }, tolerance)\n );\n });\n if (!detached) {\n survivingJunctions.push(junction);\n continue;\n }\n if (options.onJunctionConflict === 'remove') {\n cascaded = true;\n effects.push({ kind: 'junction-removed', id: junction.id, reason: 'junction-detached' });\n continue;\n }\n diagnostics.push({\n severity: 'error',\n code: 'junction/off-wire',\n message: `Junction \"${junction.id}\" no longer lies on every referenced wire.`,\n pointer: toPointer(['sheet', 'junctions']),\n entity: { kind: 'junction', id: junction.id },\n });\n }\n\n if (!cascaded) {\n return parsed;\n }\n return { ...parsed, sheet: { ...parsed.sheet, junctions: survivingJunctions } };\n}\n\nfunction makeWire(\n id: string,\n points: readonly Point[],\n diagnostics: Diagnostic[],\n): SchematicWire | undefined {\n if (points.length < 2) {\n diagnostics.push({\n severity: 'error',\n code: 'wire/invalid-points',\n message: `Wire \"${id}\" must contain at least two points.`,\n entity: { kind: 'wire', id },\n });\n return undefined;\n }\n return { id, points: points.map((point) => ({ x: point.x, y: point.y })) };\n}\n\nfunction makeJunction(\n id: string,\n x: number,\n y: number,\n wires: readonly string[],\n diagnostics: Diagnostic[],\n): SchematicJunction | undefined {\n if (wires.length < 2) {\n diagnostics.push({\n severity: 'error',\n code: 'schema/invalid-value',\n message: `Junction \"${id}\" must reference at least two wires.`,\n entity: { kind: 'junction', id },\n });\n return undefined;\n }\n return { id, x, y, wires: [...wires] };\n}\n\nfunction requireDevice(device: string, diagnostics: Diagnostic[]): string | undefined {\n if (parseDeviceReference(device) === undefined) {\n diagnostics.push({\n severity: 'error',\n code: 'device/invalid-reference',\n message: `Invalid device reference ${JSON.stringify(device)}.`,\n });\n return undefined;\n }\n return device;\n}\n\nfunction baseOf(symbol: SchematicSymbol): Omit<SchematicSymbol, 'properties' | 'reference'> {\n return {\n id: symbol.id,\n device: symbol.device,\n x: symbol.x,\n y: symbol.y,\n rotation: symbol.rotation,\n ...(symbol.designator === undefined ? {} : { designator: symbol.designator }),\n ...(symbol.net === undefined ? {} : { net: symbol.net }),\n };\n}\n\n/**\n * Reference designator for a new symbol: components keep `undefined` (the id doubles as the\n * default designator), everything else must not have one.\n */\nfunction resolveDesignator(\n value: string | undefined,\n role: SymbolRole,\n id: string,\n diagnostics: Diagnostic[],\n): string | undefined {\n if (!hasDesignator(role)) {\n if (value !== undefined) {\n diagnostics.push({\n severity: 'error',\n code: 'symbol/unsupported-field',\n message: `Symbols of role \"${role}\" carry no reference designator.`,\n });\n }\n return undefined;\n }\n const trimmed = value?.trim();\n return trimmed === undefined || trimmed.length === 0 || trimmed === id ? undefined : trimmed;\n}\n\n/** Net name for a new symbol; labels need one, power and ground fall back to their default. */\nfunction resolveNet(\n value: string | undefined,\n role: SymbolRole,\n diagnostics: Diagnostic[],\n): string | undefined {\n if (!namesNet(role)) {\n if (value !== undefined) {\n diagnostics.push({\n severity: 'error',\n code: 'symbol/unsupported-field',\n message: `Symbols of role \"${role}\" name no net.`,\n });\n }\n return undefined;\n }\n const trimmed = value?.trim();\n if (trimmed !== undefined && trimmed.length > 0) {\n return trimmed;\n }\n const fallback = defaultNetName(role);\n if (fallback === undefined) {\n diagnostics.push({\n severity: 'error',\n code: 'symbol/missing-net',\n message: `Symbols of role \"${role}\" must name the net they attach to.`,\n });\n }\n return fallback;\n}\n\n/** `null` clears the field, `undefined` keeps it, and unsupported roles cannot set it. */\nfunction resolveOptionalText(\n value: string | null | undefined,\n current: string | undefined,\n supported: boolean,\n field: 'designator' | 'net',\n diagnostics: Diagnostic[],\n): string | undefined {\n if (value === undefined) {\n return current;\n }\n if (!supported) {\n diagnostics.push({\n severity: 'error',\n code: 'symbol/unsupported-field',\n message: `This symbol must not declare \"${field}\".`,\n });\n return undefined;\n }\n if (value === null) {\n return undefined;\n }\n const trimmed = value.trim();\n if (trimmed.length === 0) {\n diagnostics.push({\n severity: 'error',\n code: 'schema/invalid-value',\n message: `${field === 'net' ? 'Net name' : 'Reference designator'} must not be empty.`,\n });\n return undefined;\n }\n return trimmed;\n}\n\nfunction withProperties(\n symbol: Omit<SchematicSymbol, 'properties'>,\n properties: Readonly<Record<string, PropertyValue>> | undefined,\n): SchematicSymbol {\n if (properties === undefined || Object.keys(properties).length === 0) {\n return symbol;\n }\n return { ...symbol, properties };\n}\n\n/** `reference: null` clears the override and falls back to the default anchor. */\nfunction resolveReference(\n value: Point | null | undefined,\n current: Point | undefined,\n path: readonly string[],\n diagnostics: Diagnostic[],\n): Point | undefined {\n if (value === undefined) {\n return current;\n }\n if (value === null) {\n return undefined;\n }\n if (typeof value !== 'object' || !Number.isFinite(value.x) || !Number.isFinite(value.y)) {\n diagnostics.push({\n severity: 'error',\n code: 'schema/invalid-value',\n message: 'Symbol reference must contain finite x and y numbers.',\n pointer: toPointer([...path, 'reference']),\n });\n return undefined;\n }\n return { x: value.x, y: value.y };\n}\n\n/** Property descriptors of `device`, when the caller supplied a device registry (#7). */\nfunction deviceDescriptors(\n device: string | undefined,\n options: SchematicEditOptions,\n): ReadonlyMap<string, PropertyDescriptor> | undefined {\n const reference = device === undefined ? undefined : parseDeviceReference(device);\n return reference === undefined\n ? undefined\n : options.devices?.getDevicePropertyDescriptors?.(reference);\n}\n\nfunction normalizeProperties(\n properties: Readonly<Record<string, PropertyValue>> | undefined,\n descriptors: ReadonlyMap<string, PropertyDescriptor> | undefined,\n diagnostics: Diagnostic[],\n): Readonly<Record<string, PropertyValue>> | undefined {\n if (properties === undefined) {\n return undefined;\n }\n const normalized: Record<string, PropertyValue> = {};\n for (const [key, value] of Object.entries(properties)) {\n if (key.length === 0) {\n diagnostics.push({\n severity: 'error',\n code: 'schema/invalid-value',\n message: 'Property keys must not be empty.',\n });\n continue;\n }\n const checked = checkPropertyValue(key, value, descriptors?.get(key), diagnostics);\n if (checked !== undefined) {\n normalized[key] = checked;\n }\n }\n return normalized;\n}\n\nfunction checkPropertyValue(\n key: string,\n value: PropertyValue,\n descriptor: PropertyDescriptor | undefined,\n diagnostics: Diagnostic[],\n): PropertyValue | undefined {\n if (key.length === 0) {\n diagnostics.push({\n severity: 'error',\n code: 'schema/invalid-value',\n message: 'Property keys must not be empty.',\n });\n return undefined;\n }\n if (descriptor !== undefined) {\n const problem = propertyValueProblem(descriptor, value);\n if (problem !== undefined) {\n diagnostics.push({ severity: 'error', code: problem.code, message: problem.message });\n return undefined;\n }\n return normalizePropertyValue(descriptor, value);\n }\n if (typeof value === 'string' || typeof value === 'boolean' || value === null) {\n return value;\n }\n if (typeof value === 'number') {\n if (!Number.isFinite(value)) {\n diagnostics.push({\n severity: 'error',\n code: 'schema/invalid-value',\n message: `Property \"${key}\" must be a finite number.`,\n });\n return undefined;\n }\n return value;\n }\n if (isAssetReference(value)) {\n return value;\n }\n diagnostics.push({\n severity: 'error',\n code: 'schema/invalid-value',\n message: `Property \"${key}\" must be a string, finite number, boolean, resource reference or null.`,\n });\n return undefined;\n}\n\nfunction findIndex<T extends { readonly id: string }>(\n items: readonly T[],\n id: string,\n kind: 'symbol' | 'wire' | 'junction',\n diagnostics: Diagnostic[],\n): number {\n const index = items.findIndex((item) => item.id === id);\n if (index === -1) {\n diagnostics.push({\n severity: 'error',\n code: 'edit/unknown-entity',\n message: `Unknown ${kind} \"${id}\".`,\n entity: { kind, id },\n });\n }\n return index;\n}\n","import type { SchematicDocument } from '../../format/types';\nimport type { Point } from '../../format/value';\nimport { pointOnPolyline } from '../geometry/point';\n\nexport interface JunctionReleaseOptions {\n readonly tolerance?: number;\n}\n\nexport interface JunctionRelease {\n readonly id: string;\n /** Remaining participating wires; `undefined` means the junction has to be removed. */\n readonly wires: readonly string[] | undefined;\n}\n\n/**\n * Junctions that must let go of `wireId`: its new geometry no longer passes through them.\n *\n * A junction left with fewer than two wires is dropped instead of being kept dangling. Pure\n * geometry: the caller applies the resulting commands.\n */\nexport function planJunctionRelease(\n document: SchematicDocument,\n wireId: string,\n points: readonly Point[],\n options: JunctionReleaseOptions = {},\n): readonly JunctionRelease[] {\n const tolerance = options.tolerance ?? 0;\n const releases: JunctionRelease[] = [];\n for (const junction of document.sheet.junctions) {\n if (!junction.wires.includes(wireId)) {\n continue;\n }\n if (pointOnPolyline(points, { x: junction.x, y: junction.y }, tolerance)) {\n continue;\n }\n const remaining = junction.wires.filter((id) => id !== wireId);\n releases.push({ id: junction.id, wires: remaining.length < 2 ? undefined : remaining });\n }\n return releases;\n}\n\nexport interface JunctionJoin {\n readonly id: string;\n readonly wires: readonly string[];\n}\n\n/**\n * The junction sitting exactly at `point`, extended with `wireId`, so a wire that ends on an\n * existing junction actually joins it. `undefined` when there is nothing to join.\n */\nexport function joinJunctionAt(\n document: SchematicDocument,\n wireId: string,\n point: Point,\n): JunctionJoin | undefined {\n const junction = document.sheet.junctions.find(\n (candidate) => candidate.x === point.x && candidate.y === point.y,\n );\n if (junction === undefined || junction.wires.includes(wireId)) {\n return undefined;\n }\n return { id: junction.id, wires: [...junction.wires, wireId] };\n}\n","import { SchematicError } from '../../format/errors';\nimport { parseSchematic } from '../format/parse-schematic';\nimport type { SchematicDocument, SchematicJunction, SchematicWire } from '../../format/types';\nimport type { Point } from '../../format/value';\nimport { DEFAULT_TOLERANCE, pointOnPolyline, pointsEqual } from '../geometry/point';\nimport { defaultElementIdFactory, type ElementIdFactory } from './ids';\n\nexport interface WireEditOptions {\n readonly tolerance?: number;\n readonly createId?: ElementIdFactory;\n}\n\nexport interface SplitWireResult {\n readonly document: SchematicDocument;\n /** Wire that keeps the original id (the part before `point`). */\n readonly firstWireId: string;\n readonly secondWireId: string;\n}\n\nexport interface MergeWiresResult {\n readonly document: SchematicDocument;\n /** Wire that kept its id and absorbed the other one. */\n readonly wireId: string;\n readonly removedWireId: string;\n readonly removedJunctionId: string;\n}\n\n/**\n * Splits `wireId` at `point`, which must lie strictly inside the polyline.\n * Junctions that only touch the second half are re-pointed to the new wire.\n *\n * @throws {SchematicError} when the wire is unknown or `point` is not an interior point.\n */\nexport function splitWireAt(\n document: SchematicDocument,\n wireId: string,\n point: Point,\n options: WireEditOptions = {},\n): SplitWireResult {\n const tolerance = options.tolerance ?? DEFAULT_TOLERANCE;\n const wire = document.sheet.wires.find((candidate) => candidate.id === wireId);\n if (wire === undefined) {\n throw new SchematicError([\n {\n severity: 'error',\n code: 'edit/unknown-entity',\n message: `Unknown wire \"${wireId}\".`,\n entity: { kind: 'wire', id: wireId },\n },\n ]);\n }\n\n const split = splitPoints(wire.points, point, tolerance);\n if (split === undefined) {\n throw new SchematicError([\n {\n severity: 'error',\n code: 'wire/invalid-points',\n message: `Point (${point.x}, ${point.y}) is not an interior point of wire \"${wireId}\".`,\n entity: { kind: 'wire', id: wireId },\n },\n ]);\n }\n\n const firstWireId = wireId;\n const secondWireId =\n options.createId?.('wire', document) ?? defaultElementIdFactory('wire', document);\n if (secondWireId === firstWireId) {\n throw new SchematicError([\n {\n severity: 'error',\n code: 'edit/invalid-command',\n message: `Generated wire id \"${secondWireId}\" collides with the split wire.`,\n entity: { kind: 'wire', id: wireId },\n },\n ]);\n }\n\n const [firstPoints, secondPoints] = split;\n const wires: SchematicWire[] = [];\n for (const candidate of document.sheet.wires) {\n if (candidate.id !== wireId) {\n wires.push(candidate);\n continue;\n }\n wires.push({ id: firstWireId, points: firstPoints });\n wires.push({ id: secondWireId, points: secondPoints });\n }\n\n const junctions = document.sheet.junctions.map((junction) =>\n remapJunction(\n junction,\n wireId,\n firstWireId,\n secondWireId,\n firstPoints,\n secondPoints,\n point,\n tolerance,\n ),\n );\n\n return {\n document: validate({ ...document, sheet: { ...document.sheet, wires, junctions } }),\n firstWireId,\n secondWireId,\n };\n}\n\n/**\n * Merges the two collinear wires meeting at `junctionId` into one wire and removes the junction.\n * Returns `undefined` when the junction does not describe such a splice.\n *\n * @throws {SchematicError} when the junction is unknown.\n */\nexport function mergeWiresAtJunction(\n document: SchematicDocument,\n junctionId: string,\n options: WireEditOptions = {},\n): MergeWiresResult | undefined {\n const tolerance = options.tolerance ?? DEFAULT_TOLERANCE;\n const junction = document.sheet.junctions.find((candidate) => candidate.id === junctionId);\n if (junction === undefined) {\n throw new SchematicError([\n {\n severity: 'error',\n code: 'edit/unknown-entity',\n message: `Unknown junction \"${junctionId}\".`,\n entity: { kind: 'junction', id: junctionId },\n },\n ]);\n }\n if (junction.wires.length !== 2) {\n return undefined;\n }\n\n const [firstId, secondId] = junction.wires as [string, string];\n const first = document.sheet.wires.find((wire) => wire.id === firstId);\n const second = document.sheet.wires.find((wire) => wire.id === secondId);\n if (first === undefined || second === undefined) {\n return undefined;\n }\n\n const merged = mergePoints(first.points, second.points, junction, tolerance);\n if (merged === undefined) {\n return undefined;\n }\n\n const wires: SchematicWire[] = [];\n for (const candidate of document.sheet.wires) {\n if (candidate.id === secondId) {\n continue;\n }\n wires.push(candidate.id === firstId ? { id: firstId, points: merged } : candidate);\n }\n\n const junctions = document.sheet.junctions\n .filter((candidate) => candidate.id !== junctionId)\n .map((candidate) =>\n candidate.wires.includes(secondId)\n ? { ...candidate, wires: candidate.wires.map((id) => (id === secondId ? firstId : id)) }\n : candidate,\n );\n\n return {\n document: validate({ ...document, sheet: { ...document.sheet, wires, junctions } }),\n wireId: firstId,\n removedWireId: secondId,\n removedJunctionId: junctionId,\n };\n}\n\nfunction validate(document: SchematicDocument): SchematicDocument {\n return parseSchematic(document);\n}\n\nfunction splitPoints(\n points: readonly Point[],\n point: Point,\n tolerance: number,\n): readonly [readonly Point[], readonly Point[]] | undefined {\n const first = points[0];\n const last = points[points.length - 1];\n if (first === undefined || last === undefined) {\n return undefined;\n }\n if (pointsEqual(first, point, tolerance) || pointsEqual(last, point, tolerance)) {\n return undefined;\n }\n if (!pointOnPolyline(points, point, tolerance)) {\n return undefined;\n }\n for (let index = 1; index < points.length; index += 1) {\n const previous = points[index - 1];\n const current = points[index];\n if (previous === undefined || current === undefined) {\n continue;\n }\n if (!pointOnPolyline([previous, current], point, tolerance)) {\n continue;\n }\n const firstPoints = [...points.slice(0, index), { x: point.x, y: point.y }];\n const secondPoints = [{ x: point.x, y: point.y }, ...points.slice(index)];\n return [firstPoints, secondPoints];\n }\n return undefined;\n}\n\nfunction remapJunction(\n junction: SchematicJunction,\n wireId: string,\n firstWireId: string,\n secondWireId: string,\n firstPoints: readonly Point[],\n secondPoints: readonly Point[],\n splitPoint: Point,\n tolerance: number,\n): SchematicJunction {\n if (!junction.wires.includes(wireId)) {\n return junction;\n }\n const point = { x: junction.x, y: junction.y };\n if (pointsEqual(point, splitPoint, tolerance)) {\n const others = junction.wires.filter((id) => id !== wireId);\n return { ...junction, wires: [firstWireId, secondWireId, ...others] };\n }\n const onFirst = pointOnPolyline(firstPoints, point, tolerance);\n const onSecond = pointOnPolyline(secondPoints, point, tolerance);\n if (onFirst && !onSecond) {\n return junction;\n }\n if (onSecond && !onFirst) {\n return { ...junction, wires: junction.wires.map((id) => (id === wireId ? secondWireId : id)) };\n }\n return junction;\n}\n\nfunction mergePoints(\n first: readonly Point[],\n second: readonly Point[],\n junction: SchematicJunction,\n tolerance: number,\n): readonly Point[] | undefined {\n const at = { x: junction.x, y: junction.y };\n const firstStart = first[0];\n const firstEnd = first[first.length - 1];\n const secondStart = second[0];\n const secondEnd = second[second.length - 1];\n if (\n firstStart === undefined ||\n firstEnd === undefined ||\n secondStart === undefined ||\n secondEnd === undefined\n ) {\n return undefined;\n }\n\n const firstStartsAt = pointsEqual(firstStart, at, tolerance);\n const firstEndsAt = pointsEqual(firstEnd, at, tolerance);\n const secondStartsAt = pointsEqual(secondStart, at, tolerance);\n const secondEndsAt = pointsEqual(secondEnd, at, tolerance);\n\n let head: readonly Point[] | undefined;\n let tail: readonly Point[] | undefined;\n if (firstEndsAt && secondStartsAt) {\n head = first;\n tail = second;\n } else if (secondEndsAt && firstStartsAt) {\n head = second;\n tail = first;\n } else if (firstEndsAt && secondEndsAt) {\n head = first;\n tail = [...second].reverse();\n } else if (firstStartsAt && secondStartsAt) {\n head = [...first].reverse();\n tail = second;\n }\n if (head === undefined || tail === undefined || !isContinuous(head, tail)) {\n return undefined;\n }\n return [...head, ...tail.slice(1)];\n}\n\n/** True when the last segment of `a` and the first segment of `b` are collinear. */\nfunction isContinuous(a: readonly Point[], b: readonly Point[]): boolean {\n const a1 = a[a.length - 2];\n const a2 = a[a.length - 1];\n const b1 = b[0];\n const b2 = b[1];\n if (a1 === undefined || a2 === undefined || b1 === undefined || b2 === undefined) {\n return false;\n }\n const ax = a2.x - a1.x;\n const ay = a2.y - a1.y;\n const bx = b2.x - b1.x;\n const by = b2.y - b1.y;\n const cross = ax * by - ay * bx;\n const scale = Math.hypot(ax, ay) * Math.hypot(bx, by);\n if (scale === 0) {\n return false;\n }\n return Math.abs(cross) / scale <= 1e-9 && ax * bx + ay * by > 0;\n}\n","import type { SchematicWire } from '../../format/types';\nimport type { Point } from '../../format/value';\n\nexport interface PointMove {\n readonly from: Point;\n readonly to: Point;\n}\n\nexport interface ReroutedWire {\n readonly points: readonly Point[];\n /** Every point that changed, so junctions and anchors can follow. */\n readonly moves: readonly PointMove[];\n}\n\n/**\n * Moves a wire endpoint to `to` while keeping every segment horizontal or vertical.\n *\n * The displacement is absorbed segment by segment (the classic orthogonal drag): the point after\n * the moved end is shifted just enough to restore the original orientation, and the correction is\n * passed on until a segment can take it. No extra points are inserted, so the wire never doubles\n * back on itself.\n */\nexport function rerouteWireEndpoint(\n wire: SchematicWire,\n from: Point,\n to: Point,\n): ReroutedWire | undefined {\n const points = wire.points;\n const first = points[0];\n const last = points[points.length - 1];\n if (first === undefined || last === undefined) {\n return undefined;\n }\n if (samePoint(first, from)) {\n return rerouteFrom(points, to, 'start');\n }\n if (samePoint(last, from)) {\n return rerouteFrom(points, to, 'end');\n }\n return undefined;\n}\n\nfunction rerouteFrom(points: readonly Point[], target: Point, end: 'start' | 'end'): ReroutedWire {\n const next = points.map((point) => ({ x: point.x, y: point.y }));\n const first = next[0];\n const last = next[next.length - 1];\n if (first === undefined || last === undefined) {\n return { points: next, moves: [] };\n }\n\n if (end === 'start') {\n next[0] = { x: target.x, y: target.y };\n for (let index = 0; index < next.length - 1; index += 1) {\n const a = next[index];\n const b = next[index + 1];\n if (a === undefined || b === undefined || a.x === b.x || a.y === b.y) {\n break;\n }\n const horizontal = points[index]?.y === points[index + 1]?.y;\n next[index + 1] = horizontal ? { x: b.x, y: a.y } : { x: a.x, y: b.y };\n }\n } else {\n next[next.length - 1] = { x: target.x, y: target.y };\n for (let index = next.length - 1; index > 0; index -= 1) {\n const a = next[index - 1];\n const b = next[index];\n if (a === undefined || b === undefined || a.x === b.x || a.y === b.y) {\n break;\n }\n const horizontal = points[index - 1]?.y === points[index]?.y;\n next[index - 1] = horizontal ? { x: a.x, y: b.y } : { x: b.x, y: a.y };\n }\n }\n\n const moves: PointMove[] = [];\n for (let index = 0; index < points.length; index += 1) {\n const before = points[index];\n const after = next[index];\n if (before !== undefined && after !== undefined && !samePoint(before, after)) {\n moves.push({ from: before, to: after });\n }\n }\n return { points: dropRepeatedPoints(next), moves };\n}\n\nfunction dropRepeatedPoints(points: readonly Point[]): readonly Point[] {\n const result: Point[] = [];\n for (const point of points) {\n const previous = result[result.length - 1];\n if (previous === undefined || !samePoint(previous, point)) {\n result.push(point);\n }\n }\n return result.length >= 2 ? result : points;\n}\n\n/**\n * Moves a wire endpoint to `to` by stretching or bending it, leaving the original run in place.\n *\n * Unlike {@link rerouteWireEndpoint}, which absorbs the move by shifting the neighbouring points,\n * this keeps every existing point: a move along the attached segment only changes its length, and a\n * perpendicular move appends an orthogonal fold at the moved end. That is the behaviour net labels\n * and power ports need while being dragged — the wire follows them instead of sliding away.\n */\nexport function stretchWireEndpoint(\n wire: SchematicWire,\n from: Point,\n to: Point,\n): ReroutedWire | undefined {\n const points = wire.points;\n const first = points[0];\n const last = points[points.length - 1];\n if (first === undefined || last === undefined) {\n return undefined;\n }\n if (samePoint(first, from)) {\n return stretchAt(points, to, 'start');\n }\n if (samePoint(last, from)) {\n return stretchAt(points, to, 'end');\n }\n return undefined;\n}\n\nfunction stretchAt(points: readonly Point[], target: Point, end: 'start' | 'end'): ReroutedWire {\n const anchor = end === 'start' ? points[0] : points[points.length - 1];\n const neighbor = end === 'start' ? points[1] : points[points.length - 2];\n if (anchor === undefined) {\n return { points, moves: [] };\n }\n if (neighbor === undefined) {\n const next = points.map((point) => ({ x: point.x, y: point.y }));\n if (end === 'start') {\n next[0] = { x: target.x, y: target.y };\n } else {\n next[next.length - 1] = { x: target.x, y: target.y };\n }\n return { points: next, moves: [{ from: anchor, to: target }] };\n }\n\n const horizontal = neighbor.y === anchor.y;\n const perpendicular = horizontal ? target.y !== anchor.y : target.x !== anchor.x;\n if (!perpendicular) {\n const next = points.map((point) => ({ x: point.x, y: point.y }));\n if (end === 'start') {\n next[0] = { x: target.x, y: target.y };\n } else {\n next[next.length - 1] = { x: target.x, y: target.y };\n }\n return { points: dropRepeatedPoints(next), moves: [{ from: anchor, to: target }] };\n }\n\n // Turn at the anchor first, then run perpendicular; a pure perpendicular move adds one segment.\n const elbow = horizontal ? { x: anchor.x, y: target.y } : { x: target.x, y: anchor.y };\n const turn = samePoint(elbow, target) ? [] : [elbow];\n const next = end === 'start' ? [target, ...turn, ...points] : [...points, ...turn, target];\n return { points: dropRepeatedPoints(next), moves: [] };\n}\n\nfunction samePoint(left: Point, right: Point): boolean {\n return left.x === right.x && left.y === right.y;\n}\n","import type { Rect } from '../../format/types';\nimport type { DeviceSymbolDefinition, PinAnchor, PinSide } from './symbol';\n\n/** Pin declaration subset used for symbol synthesis (see #11 / #12). */\nexport interface DevicePinDeclaration {\n /** Display side; pins without a side are drawn on the left. */\n readonly side?: PinSide;\n}\n\nexport interface SymbolSynthesisOptions {\n /** Distance between pin rows, in page units. Defaults to 10. */\n readonly pinPitch?: number;\n /** Stub length outside the body. Defaults to 10. */\n readonly stubLength?: number;\n /** Minimum body width. Defaults to 60. */\n readonly minWidth?: number;\n /** Minimum body height. Defaults to 40. */\n readonly minHeight?: number;\n /** Horizontal padding between the body edge and pin labels. Defaults to 10. */\n readonly horizontalPadding?: number;\n /** Vertical padding above the first and below the last pin row. Defaults to 10. */\n readonly verticalPadding?: number;\n /** Approximate glyph width of the device name. Defaults to 5.5. */\n readonly characterWidth?: number;\n /** Approximate glyph width of a pin name. Defaults to 4.5. */\n readonly labelCharacterWidth?: number;\n /** Gap between the device name and the side pin labels. Defaults to 12. */\n readonly nameGap?: number;\n /** Inset of a top/bottom pin label from the body edge. Defaults to 10. */\n readonly labelInset?: number;\n}\n\nexport interface SymbolSynthesisInput {\n readonly name: string;\n readonly pins: Readonly<Record<string, DevicePinDeclaration>>;\n}\n\nconst DEFAULT_PIN_SIDE: PinSide = 'left';\n\n/** Half height of a centred glyph box, in `characterWidth` units. */\nconst NAME_HALF_EXTENT = 1;\n\n/**\n * Derives symbol geometry from pin declarations: no coordinates or body size are authored.\n * Pins keep their declaration order within a side and snap to `pinPitch`.\n */\nexport function synthesizeDeviceSymbol(\n input: SymbolSynthesisInput,\n options: SymbolSynthesisOptions = {},\n): DeviceSymbolDefinition {\n const pinPitch = options.pinPitch ?? 10;\n const stubLength = options.stubLength ?? 10;\n const minWidth = options.minWidth ?? 60;\n const minHeight = options.minHeight ?? 40;\n const horizontalPadding = options.horizontalPadding ?? 10;\n const verticalPadding = options.verticalPadding ?? 10;\n const characterWidth = options.characterWidth ?? 5.5;\n const labelCharacterWidth = options.labelCharacterWidth ?? 4.5;\n const nameGap = options.nameGap ?? 12;\n const labelInset = options.labelInset ?? 10;\n\n const sides: Record<PinSide, string[]> = { left: [], right: [], top: [], bottom: [] };\n for (const [pinId, declaration] of Object.entries(input.pins)) {\n sides[declaration.side ?? DEFAULT_PIN_SIDE].push(pinId);\n }\n\n const rows = Math.max(sides.left.length, sides.right.length);\n const columns = Math.max(sides.top.length, sides.bottom.length);\n const height = Math.max(\n minHeight,\n verticalPadding * 2 + Math.max(rows - 1, 0) * pinPitch + pinPitch,\n // Rotated top/bottom labels must clear the centred device name.\n 2 *\n (NAME_HALF_EXTENT * characterWidth +\n pinPitch / 2 +\n labelInset +\n rotatedHalf(sides, labelCharacterWidth)),\n );\n const width = Math.max(\n minWidth,\n horizontalPadding * 2 + Math.max(columns - 1, 0) * pinPitch + pinPitch,\n );\n\n const leftText = longest(sides.left);\n const rightText = longest(sides.right);\n const contentWidth =\n (leftText + rightText) * labelCharacterWidth +\n input.name.length * characterWidth +\n horizontalPadding * 2 +\n nameGap * 2;\n const bodyWidth = Math.ceil(Math.max(width, contentWidth) / pinPitch) * pinPitch;\n const bodyHeight = Math.ceil(height / pinPitch) * pinPitch;\n\n const body: Rect = {\n x: -bodyWidth / 2,\n y: -bodyHeight / 2,\n width: bodyWidth,\n height: bodyHeight,\n };\n\n const pins: Record<string, PinAnchor> = Object.create(null);\n\n const placeVertical = (pinIds: readonly string[], side: 'left' | 'right'): void => {\n const start = -((pinIds.length - 1) * pinPitch) / 2;\n pinIds.forEach((pinId, index) => {\n const y = start + index * pinPitch;\n const x = side === 'left' ? body.x - stubLength : body.x + body.width + stubLength;\n pins[pinId] = { x, y, side };\n });\n };\n placeVertical(sides.left, 'left');\n placeVertical(sides.right, 'right');\n\n const placeHorizontal = (pinIds: readonly string[], side: 'top' | 'bottom'): void => {\n const start = -((pinIds.length - 1) * pinPitch) / 2;\n pinIds.forEach((pinId, index) => {\n const x = start + index * pinPitch;\n const y = side === 'top' ? body.y - stubLength : body.y + body.height + stubLength;\n pins[pinId] = { x, y, side };\n });\n };\n placeHorizontal(sides.top, 'top');\n placeHorizontal(sides.bottom, 'bottom');\n\n return { name: input.name, pins, bounds: body };\n}\n\nfunction longest(pinIds: readonly string[]): number {\n return pinIds.reduce((max, pinId) => Math.max(max, pinId.length), 0);\n}\n\nfunction rotatedHalf(\n sides: Readonly<Record<PinSide, readonly string[]>>,\n characterWidth: number,\n): number {\n return (Math.max(longest(sides.top), longest(sides.bottom)) * characterWidth) / 2;\n}\n","import type { Rect } from '../../format/types';\nimport type { DeviceGraphic, DevicePinLabel, DeviceSymbolAnnotations } from './metadata';\nimport type { PropertyDescriptor } from './properties';\nimport type { DeviceReference } from './reference';\n\n/** Side of the symbol body a pin is drawn on; controls stub direction and label placement. */\nexport type PinSide = 'left' | 'right' | 'top' | 'bottom';\n\nexport interface PinAnchor {\n /** Connection point (outer end of the pin stub) in symbol space. */\n readonly x: number;\n readonly y: number;\n /** Side the pin is displayed on; inferred from the position when omitted. */\n readonly side?: PinSide;\n readonly label?: DevicePinLabel;\n readonly displayName?: string;\n}\n\nexport interface DeviceSymbolDefinition {\n /** Name rendered at the centre of the symbol. */\n readonly name: string;\n /** Pin id to pre-placement anchor coordinate in symbol space. */\n readonly pins: Readonly<Record<string, PinAnchor>>;\n /** Optional outline used by the editor to draw the symbol body. */\n readonly bounds?: Rect;\n readonly graphics?: readonly DeviceGraphic[];\n readonly annotations?: DeviceSymbolAnnotations;\n}\n\nexport interface DeviceSymbolGeometry {\n /** Placement-independent geometry, as provided by the device description. */\n readonly name?: string;\n readonly pins: Readonly<Record<string, PinAnchor>>;\n readonly bounds?: Rect;\n readonly graphics?: readonly DeviceGraphic[];\n readonly annotations?: DeviceSymbolAnnotations;\n}\n\nexport interface DeviceSymbolProvider {\n /** Symbol geometry; `undefined` when the device is unknown or has no geometry. */\n getDeviceSymbol(reference: DeviceReference): DeviceSymbolDefinition | undefined;\n /** Name rendered on the symbol: the symbol name, else the display name. `undefined` when unknown. */\n getDeviceName(reference: DeviceReference): string | undefined;\n /**\n * Reference-designator prefix the device declares (`U`, `R`, `DS`, …); `undefined` when the\n * provider does not describe one, in which case placement falls back to the global default.\n */\n getDeviceDesignatorPrefix?(reference: DeviceReference): string | undefined;\n /**\n * Property descriptors the device declares (#7); `undefined` when the provider does not describe\n * them, in which case property editing is restricted to structural validation only.\n */\n getDevicePropertyDescriptors?(\n reference: DeviceReference,\n ): ReadonlyMap<string, PropertyDescriptor> | undefined;\n}\n\n/** Bounding box of a device's pins; `undefined` when it declares none. */\nexport function pinsBounds(pins: Readonly<Record<string, PinAnchor>>): Rect | undefined {\n const points = Object.values(pins);\n if (points.length === 0) {\n return undefined;\n }\n let minX = Number.POSITIVE_INFINITY;\n let minY = Number.POSITIVE_INFINITY;\n let maxX = Number.NEGATIVE_INFINITY;\n let maxY = Number.NEGATIVE_INFINITY;\n for (const point of points) {\n minX = Math.min(minX, point.x);\n minY = Math.min(minY, point.y);\n maxX = Math.max(maxX, point.x);\n maxY = Math.max(maxY, point.y);\n }\n return { x: minX, y: minY, width: maxX - minX, height: maxY - minY };\n}\n\n/** Side a pin is drawn on: its declared side, else the closest edge of the body outline. */\nexport function pinSide(pin: PinAnchor, outline: Rect | undefined): PinSide | undefined {\n if (pin.side !== undefined) {\n return pin.side;\n }\n if (outline === undefined) {\n return undefined;\n }\n const dx = (pin.x - (outline.x + outline.width / 2)) / Math.max(outline.width / 2, 1e-6);\n const dy = (pin.y - (outline.y + outline.height / 2)) / Math.max(outline.height / 2, 1e-6);\n if (Math.abs(dx) >= Math.abs(dy)) {\n return dx >= 0 ? 'right' : 'left';\n }\n return dy >= 0 ? 'bottom' : 'top';\n}\n\n/**\n * Inner end of a pin stub, where it meets the body outline. Together with the anchor it forms the\n * grabbable pin: rendering draws that line and hit testing accepts clicks anywhere along it.\n */\nexport function pinStubEnd(\n body: Rect,\n anchor: { readonly x: number; readonly y: number },\n side: PinSide,\n): { readonly x: number; readonly y: number } {\n switch (side) {\n case 'left':\n return { x: body.x, y: anchor.y };\n case 'right':\n return { x: body.x + body.width, y: anchor.y };\n case 'top':\n return { x: anchor.x, y: body.y };\n case 'bottom':\n return { x: anchor.x, y: body.y + body.height };\n }\n}\n","import type { Diagnostic } from '../../format/diagnostics';\nimport { SchematicError } from '../../format/errors';\nimport { parseInput } from '../../format/input';\nimport { isRecord } from '../../format/validate';\nimport type { Rect } from '../../format/types';\nimport { propertyValueProblem, type PropertyDescriptor } from './properties';\nimport type { DeviceSymbolDefinition, PinAnchor } from './symbol';\nimport { synthesizeDeviceSymbol } from './synthesis';\n\nexport type DeviceCoordinate = readonly [number, number];\nexport type DeviceTextAlign = 'left' | 'center' | 'right';\nexport interface DeviceGraphicStyle {\n readonly fill?: 'none' | 'foreground' | 'background';\n readonly strokeWidth?: number;\n}\nexport type DeviceGraphic = DeviceGraphicStyle &\n (\n | { readonly type: 'line'; readonly from: DeviceCoordinate; readonly to: DeviceCoordinate }\n | {\n readonly type: 'polyline';\n readonly points: readonly DeviceCoordinate[];\n readonly closed?: boolean;\n }\n | {\n readonly type: 'rect';\n readonly x: number;\n readonly y: number;\n readonly width: number;\n readonly height: number;\n }\n | { readonly type: 'circle'; readonly center: DeviceCoordinate; readonly radius: number }\n | {\n readonly type: 'arc';\n readonly center: DeviceCoordinate;\n readonly radius: number;\n readonly startAngle: number;\n readonly sweepAngle: number;\n }\n | {\n readonly type: 'text';\n readonly position: DeviceCoordinate;\n readonly text: string;\n readonly align?: DeviceTextAlign;\n readonly fontSize?: number;\n }\n );\nexport interface DevicePinLabel {\n readonly visible: boolean;\n readonly position?: DeviceCoordinate;\n readonly align?: DeviceTextAlign;\n}\nexport interface DeviceSymbolAnnotations {\n readonly designator?: { readonly position: DeviceCoordinate; readonly align?: DeviceTextAlign };\n}\nexport type DevicePropertyEditor =\n | {\n readonly kind: 'number';\n readonly min?: number;\n readonly max?: number;\n readonly step?: number;\n }\n | { readonly kind: 'text' | 'textarea' | 'checkbox' | 'file' }\n | { readonly kind: 'select'; readonly labels?: Readonly<Record<string, string>> };\nexport interface DevicePropertyMetadata {\n readonly type: 'number' | 'boolean' | 'string' | 'enum' | 'bytes';\n readonly required: boolean;\n readonly nullable?: boolean;\n readonly default?: unknown;\n readonly enumName?: string;\n readonly values?: readonly string[];\n readonly title?: string;\n readonly description?: string;\n readonly unit?: string;\n readonly group?: string;\n readonly order?: number;\n readonly editor?: DevicePropertyEditor;\n}\nexport interface DevicePinMetadata {\n readonly label?: string;\n readonly description?: string;\n readonly group?: string;\n}\nexport interface DevicePortMetadata {\n readonly direction: 'input' | 'output';\n readonly type:\n | 'boolean'\n | 'number'\n | 'string'\n | 'vec2d'\n | 'vec3d'\n | 'bytes'\n | 'bytes<rgb565>'\n | 'bytes<segments>';\n readonly title?: string;\n readonly description?: string;\n readonly delivery?: 'level' | 'message';\n}\nexport interface DeviceMetadata {\n readonly kind: 'device';\n readonly id: string;\n readonly version: string;\n readonly displayName: string;\n readonly description?: string;\n readonly license?: string;\n readonly tags?: readonly string[];\n readonly designatorPrefix?: string;\n readonly properties?: Readonly<Record<string, DevicePropertyMetadata>>;\n readonly pins?: Readonly<Record<string, DevicePinMetadata>>;\n readonly ports?: Readonly<Record<string, DevicePortMetadata>>;\n readonly symbol?: {\n readonly bounds: Rect;\n readonly graphics: readonly DeviceGraphic[];\n readonly pins: Readonly<\n Record<\n string,\n {\n readonly position: DeviceCoordinate;\n readonly direction: 'left' | 'right' | 'up' | 'down';\n readonly label?: DevicePinLabel;\n }\n >\n >;\n readonly annotations?: DeviceSymbolAnnotations;\n };\n}\n\ntype Check = (value: unknown, path: string, diagnostics: Diagnostic[]) => void;\nconst fail = (path: string, diagnostics: Diagnostic[], message: string): void => {\n diagnostics.push({\n severity: 'error',\n code: 'device/invalid-description',\n pointer: path,\n message,\n });\n};\nconst text: Check = (v, p, d) => {\n if (typeof v !== 'string') fail(p, d, 'Expected a string.');\n};\nconst nonempty: Check = (v, p, d) => {\n if (typeof v !== 'string' || v.length === 0) fail(p, d, 'Expected a nonempty string.');\n};\nconst number: Check = (v, p, d) => {\n if (typeof v !== 'number' || !Number.isFinite(v)) fail(p, d, 'Expected a finite number.');\n};\nconst positive: Check = (v, p, d) => {\n number(v, p, d);\n if (typeof v === 'number' && v <= 0) fail(p, d, 'Expected a positive number.');\n};\nconst boolean: Check = (v, p, d) => {\n if (typeof v !== 'boolean') fail(p, d, 'Expected a boolean.');\n};\nconst choice =\n (...values: readonly unknown[]): Check =>\n (v, p, d) => {\n if (!values.includes(v)) fail(p, d, `Expected one of ${values.join(', ')}.`);\n };\nconst pointer = (key: string): string => key.replaceAll('~', '~0').replaceAll('/', '~1');\nconst object =\n (fields: Readonly<Record<string, Check>>, required: readonly string[] = []): Check =>\n (v, p, d) => {\n if (!isRecord(v)) {\n fail(p, d, 'Expected an object.');\n return;\n }\n for (const key of required)\n if (!Object.hasOwn(v, key)) fail(`${p}/${pointer(key)}`, d, 'Required field is missing.');\n for (const [key, value] of Object.entries(v)) {\n const check = Object.hasOwn(fields, key) ? fields[key] : undefined;\n if (check === undefined) fail(`${p}/${pointer(key)}`, d, 'Unknown field.');\n else check(value, `${p}/${pointer(key)}`, d);\n }\n };\nconst map =\n (check: Check): Check =>\n (v, p, d) => {\n if (!isRecord(v)) {\n fail(p, d, 'Expected a map.');\n return;\n }\n for (const [key, value] of Object.entries(v)) check(value, `${p}/${pointer(key)}`, d);\n };\nconst tuple: Check = (v, p, d) => {\n if (!Array.isArray(v) || v.length !== 2) {\n fail(p, d, 'Expected two coordinates.');\n return;\n }\n v.forEach((value, index) => number(value, `${p}/${index}`, d));\n};\nconst strings: Check = (v, p, d) => {\n if (!Array.isArray(v)) {\n fail(p, d, 'Expected an array.');\n return;\n }\n v.forEach((value, index) => nonempty(value, `${p}/${index}`, d));\n if (new Set(v).size !== v.length) fail(p, d, 'Values must be unique.');\n};\nconst align = choice('left', 'center', 'right');\nconst label = object({ visible: boolean, position: tuple, align }, ['visible']);\nconst editor: Check = (v, p, d) => {\n const fields: Record<string, Check> = {\n kind: choice('number', 'text', 'textarea', 'checkbox', 'file', 'select'),\n };\n if (isRecord(v) && v.kind === 'number')\n Object.assign(fields, { min: number, max: number, step: positive });\n if (isRecord(v) && v.kind === 'select') fields.labels = map(text);\n object(fields, ['kind'])(v, p, d);\n};\nconst property: Check = (v, p, d) => {\n object(\n {\n type: choice('number', 'boolean', 'string', 'enum', 'bytes'),\n required: boolean,\n nullable: boolean,\n default: () => {},\n enumName: nonempty,\n values: strings,\n title: text,\n description: text,\n unit: text,\n group: text,\n order: (value, path, diagnostics) => {\n if (typeof value !== 'number' || !Number.isInteger(value) || value < 0)\n fail(path, diagnostics, 'Expected a nonnegative integer.');\n },\n editor,\n },\n ['type', 'required'],\n )(v, p, d);\n if (!isRecord(v)) return;\n if (v.required === true && Object.hasOwn(v, 'default'))\n fail(`${p}/default`, d, 'Required properties cannot declare defaults.');\n if (v.type === 'enum') {\n if (!Object.hasOwn(v, 'enumName') || !Object.hasOwn(v, 'values'))\n fail(p, d, 'Enum properties require enumName and values.');\n if (Array.isArray(v.values) && v.values.length === 0)\n fail(`${p}/values`, d, 'Enum values cannot be empty.');\n } else if (Object.hasOwn(v, 'enumName') || Object.hasOwn(v, 'values'))\n fail(p, d, 'Only enum properties declare enumName and values.');\n};\nconst graphic: Check = (v, p, d) => {\n const common = {\n type: choice('line', 'polyline', 'rect', 'circle', 'arc', 'text'),\n fill: choice('none', 'foreground', 'background'),\n strokeWidth: positive,\n };\n const variants: Record<string, { fields: Record<string, Check>; required: string[] }> = {\n line: { fields: { from: tuple, to: tuple }, required: ['from', 'to'] },\n polyline: {\n fields: {\n points: (value, path, diagnostics) => {\n if (!Array.isArray(value) || value.length < 2) {\n fail(path, diagnostics, 'Expected at least two points.');\n return;\n }\n value.forEach((point, index) => tuple(point, `${path}/${index}`, diagnostics));\n },\n closed: boolean,\n },\n required: ['points'],\n },\n rect: {\n fields: { x: number, y: number, width: positive, height: positive },\n required: ['x', 'y', 'width', 'height'],\n },\n circle: { fields: { center: tuple, radius: positive }, required: ['center', 'radius'] },\n arc: {\n fields: {\n center: tuple,\n radius: positive,\n startAngle: number,\n sweepAngle: (value, path, diagnostics) => {\n number(value, path, diagnostics);\n if (typeof value === 'number' && (value === 0 || value < -360 || value > 360))\n fail(path, diagnostics, 'Sweep must be nonzero and within [-360, 360].');\n },\n },\n required: ['center', 'radius', 'startAngle', 'sweepAngle'],\n },\n text: {\n fields: { position: tuple, text, align, fontSize: positive },\n required: ['position', 'text'],\n },\n };\n const variant =\n isRecord(v) && typeof v.type === 'string' && Object.hasOwn(variants, v.type)\n ? variants[v.type]\n : undefined;\n object({ ...common, ...variant?.fields }, ['type', ...(variant?.required ?? [])])(v, p, d);\n};\nconst graphics: Check = (v, p, d) => {\n if (!Array.isArray(v)) fail(p, d, 'Expected graphics array.');\n else v.forEach((value, i) => graphic(value, `${p}/${i}`, d));\n};\nconst annotations = object({\n designator: object({ position: tuple, align }, ['position']),\n});\n\n/** Shared validation for optional presentation data on legacy normalized geometry. */\nexport function validateSymbolPresentation(\n value: Record<string, unknown>,\n diagnostics: Diagnostic[],\n): void {\n if (value.graphics !== undefined) graphics(value.graphics, '/symbol/graphics', diagnostics);\n if (value.annotations !== undefined)\n annotations(value.annotations, '/symbol/annotations', diagnostics);\n if (!isRecord(value.pins)) return;\n for (const [id, pin] of Object.entries(value.pins)) {\n if (!isRecord(pin)) continue;\n const path = `/symbol/pins/${pointer(id)}`;\n if (pin.label !== undefined) label(pin.label, `${path}/label`, diagnostics);\n if (pin.displayName !== undefined) text(pin.displayName, `${path}/displayName`, diagnostics);\n }\n}\n\nconst checkMetadata = object(\n {\n kind: choice('device'),\n id: (v, p, d) => {\n if (typeof v !== 'string' || !/^[A-Za-z0-9-]+$/.test(v)) fail(p, d, 'Invalid device id.');\n },\n version: nonempty,\n displayName: nonempty,\n description: nonempty,\n license: nonempty,\n tags: strings,\n designatorPrefix: (v, p, d) => {\n if (typeof v !== 'string' || !/^\\S+$/.test(v))\n fail(p, d, 'Expected a nonempty prefix without whitespace.');\n },\n properties: map(property),\n pins: map(object({ label: text, description: text, group: text })),\n ports: map(\n object(\n {\n direction: choice('input', 'output'),\n type: choice(\n 'boolean',\n 'number',\n 'string',\n 'vec2d',\n 'vec3d',\n 'bytes',\n 'bytes<rgb565>',\n 'bytes<segments>',\n ),\n title: text,\n description: text,\n delivery: choice('level', 'message'),\n },\n ['direction', 'type'],\n ),\n ),\n symbol: object(\n {\n bounds: object({ x: number, y: number, width: positive, height: positive }, [\n 'x',\n 'y',\n 'width',\n 'height',\n ]),\n graphics,\n pins: map(\n object({ position: tuple, direction: choice('left', 'right', 'up', 'down'), label }, [\n 'position',\n 'direction',\n ]),\n ),\n annotations,\n },\n ['bounds', 'graphics', 'pins'],\n ),\n },\n ['kind', 'id', 'version', 'displayName'],\n);\n\n/** Validates JSON text or an object, throwing the existing diagnostic-bearing format error. */\nexport function parseDeviceMetadata(input: unknown): DeviceMetadata {\n const diagnostics: Diagnostic[] = [];\n const parsed = parseInput(input, diagnostics);\n if (parsed.ok) checkMetadata(parsed.value, '', diagnostics);\n if (diagnostics.length > 0) throw new SchematicError(diagnostics);\n return parsed.value as DeviceMetadata;\n}\n\nexport function deviceMetadataPropertyDescriptors(\n metadata: DeviceMetadata,\n): ReadonlyMap<string, PropertyDescriptor> {\n return new Map(\n Object.entries(metadata.properties ?? {}).map(([key, value]) => {\n const descriptor: PropertyDescriptor = {\n key,\n type: value.type === 'bytes' ? 'binary' : value.type,\n required: value.required,\n ...(value.nullable === undefined ? {} : { nullable: value.nullable }),\n ...(value.title === undefined ? {} : { title: value.title }),\n ...(value.description === undefined ? {} : { description: value.description }),\n ...(value.unit === undefined ? {} : { unit: value.unit }),\n ...(value.group === undefined ? {} : { group: value.group }),\n ...(value.order === undefined ? {} : { order: value.order }),\n ...(value.editor === undefined ? {} : { editor: value.editor }),\n ...(value.type === 'number' && value.editor?.kind === 'number'\n ? {\n ...(value.editor.min === undefined ? {} : { min: value.editor.min }),\n ...(value.editor.max === undefined ? {} : { max: value.editor.max }),\n ...(value.editor.step === undefined ? {} : { step: value.editor.step }),\n }\n : {}),\n ...(value.type === 'enum'\n ? {\n options: value.values!.map((option) => ({\n value: option,\n label:\n value.editor?.kind === 'select'\n ? (value.editor.labels?.[option] ?? option)\n : option,\n })),\n }\n : {}),\n };\n // Metadata defaults are unrestricted JSON; only instance-compatible defaults enter the document model.\n if (\n Object.hasOwn(value, 'default') &&\n propertyValueProblem(descriptor, value.default) === undefined\n ) {\n return [\n key,\n {\n ...descriptor,\n default: value.default as PropertyDescriptor['default'],\n } as PropertyDescriptor,\n ];\n }\n return [key, descriptor];\n }),\n );\n}\n\nexport function deviceMetadataSymbol(metadata: DeviceMetadata): DeviceSymbolDefinition {\n const symbol = metadata.symbol;\n const base =\n symbol === undefined\n ? synthesizeDeviceSymbol({\n name: metadata.displayName,\n pins: Object.fromEntries(Object.keys(metadata.pins ?? {}).map((id) => [id, {}])),\n })\n : undefined;\n const pins: Record<string, PinAnchor> = Object.create(null);\n for (const [id, pin] of Object.entries(symbol?.pins ?? base!.pins)) {\n const caption = metadata.pins?.[id]?.label;\n if (symbol !== undefined) {\n const custom = symbol.pins[id]!;\n pins[id] = {\n x: custom.position[0],\n y: custom.position[1],\n side:\n custom.direction === 'up'\n ? 'top'\n : custom.direction === 'down'\n ? 'bottom'\n : custom.direction,\n ...(custom.label === undefined ? {} : { label: custom.label }),\n ...(caption === undefined ? {} : { displayName: caption }),\n };\n } else\n pins[id] = {\n ...(pin as PinAnchor),\n ...(caption === undefined ? {} : { displayName: caption }),\n };\n }\n return symbol === undefined\n ? { ...base!, pins }\n : {\n name: metadata.displayName,\n bounds: symbol.bounds,\n graphics: symbol.graphics,\n pins,\n ...(symbol.annotations === undefined ? {} : { annotations: symbol.annotations }),\n };\n}\n","import type { Diagnostic } from '../../format/diagnostics';\nimport { SchematicError, throwIfErrors } from '../../format/errors';\nimport type { Rect } from '../../format/types';\nimport { isRecord } from '../../format/validate';\nimport {\n formatDeviceReference,\n isReservedPackageId,\n isValidPackageId,\n parseDeviceReference,\n type DeviceReference,\n} from './reference';\nimport type {\n DeviceSymbolDefinition,\n DeviceSymbolGeometry,\n DeviceSymbolProvider,\n PinAnchor,\n PinSide,\n} from './symbol';\nimport { readPropertyDescriptors, type PropertyDescriptor } from './properties';\nimport {\n parseDeviceMetadata,\n deviceMetadataSymbol,\n deviceMetadataPropertyDescriptors,\n validateSymbolPresentation,\n} from './metadata';\nimport { synthesizeDeviceSymbol, type DevicePinDeclaration } from './synthesis';\n\nconst PIN_SIDES: readonly PinSide[] = ['left', 'right', 'top', 'bottom'];\n\nexport interface DeviceRegistrationEntry {\n /** Device id, unique within the package. */\n readonly id: string;\n /** Display name; defaults to the device id. */\n readonly displayName?: string;\n readonly description?: string;\n /**\n * Reference-designator prefix used when the device is placed (`U1`, `R3`, `DS2`, …).\n * Falls back to `raw.designatorPrefix`, then to the global default `U`.\n */\n readonly designatorPrefix?: string;\n /** Schematic symbol; omitted when the device has no geometry yet. */\n readonly symbol?: DeviceSymbolGeometry;\n /** Remaining device description fields (#5 pins, #7 properties, #10 ports, ...), kept as-is. */\n readonly raw?: Readonly<Record<string, unknown>>;\n}\n\n/** Package data prepared by the host from the #11 `devices` index and device descriptions. */\nexport interface DevicePackageRegistration {\n readonly packageId: string;\n readonly devices: readonly DeviceRegistrationEntry[];\n}\n\nexport interface ResolvedDevice {\n readonly reference: DeviceReference;\n readonly packageId: string;\n readonly deviceId: string;\n readonly displayName: string;\n readonly description: string | undefined;\n /** Designator prefix declared by the device description; `undefined` when it declares none. */\n readonly designatorPrefix: string | undefined;\n /** Property descriptors declared by `properties` (#7), keyed by property key. */\n readonly propertyDescriptors: ReadonlyMap<string, PropertyDescriptor>;\n readonly symbol: DeviceSymbolDefinition | undefined;\n readonly raw: Readonly<Record<string, unknown>>;\n}\n\nexport interface DeviceRegisterOptions {\n readonly replace?: boolean;\n}\n\nexport interface DeviceRegistry extends DeviceSymbolProvider {\n /** @throws {SchematicError} when the package data is invalid; nothing is registered then. */\n registerPackage(registration: DevicePackageRegistration, options?: DeviceRegisterOptions): void;\n resolve(reference: DeviceReference | string): ResolvedDevice | undefined;\n listDevices(packageId?: string): readonly ResolvedDevice[];\n /** Non-fatal diagnostics collected while registering packages (currently `device/no-symbol`). */\n readonly diagnostics: readonly Diagnostic[];\n}\n\ninterface StoredPackage {\n readonly packageId: string;\n readonly devices: ReadonlyMap<string, ResolvedDevice>;\n}\n\nexport function createDeviceRegistry(\n packages: readonly DevicePackageRegistration[] = [],\n): DeviceRegistry {\n const stored = new Map<string, StoredPackage>();\n const registrationDiagnostics: Diagnostic[] = [];\n\n const getDeviceName = (reference: DeviceReference): string | undefined => {\n const device = lookup(reference);\n // `symbol.name` already resolves to displayName or device id when the description omits it.\n return device?.symbol?.name ?? device?.displayName;\n };\n\n const lookup = (reference: DeviceReference): ResolvedDevice | undefined => {\n const pkg = stored.get(reference.packageId);\n return pkg?.devices.get(reference.deviceId);\n };\n\n const registry: DeviceRegistry = {\n registerPackage(registration, options) {\n const diagnostics: Diagnostic[] = [];\n const packageId = registration.packageId;\n if (!isValidPackageId(packageId)) {\n throw new SchematicError([\n {\n severity: 'error',\n code: 'device/invalid-package',\n message: `Invalid package id ${JSON.stringify(packageId)}.`,\n },\n ]);\n }\n if (isReservedPackageId(packageId)) {\n throw new SchematicError([\n {\n severity: 'error',\n code: 'device/reserved-namespace',\n message: `Package id ${JSON.stringify(packageId)} uses the reserved \"builtin\" namespace.`,\n },\n ]);\n }\n if (stored.has(packageId) && options?.replace !== true) {\n throw new SchematicError([\n {\n severity: 'error',\n code: 'device/duplicate-package',\n message: `Package ${JSON.stringify(packageId)} is already registered.`,\n },\n ]);\n }\n\n const devices = new Map<string, ResolvedDevice>();\n const reportedUnknownPins = new Set<string>();\n for (const entry of registration.devices) {\n const deviceId = typeof entry.id === 'string' ? entry.id : '';\n if (deviceId.length === 0) {\n diagnostics.push({\n severity: 'error',\n code: 'device/invalid-description',\n message: `Package ${JSON.stringify(packageId)} contains a device without an id.`,\n });\n continue;\n }\n const devicePath = `${packageId}:${deviceId}`;\n if (devices.has(deviceId)) {\n diagnostics.push({\n severity: 'error',\n code: 'device/duplicate-device',\n message: `Device ${JSON.stringify(devicePath)} is declared more than once.`,\n });\n continue;\n }\n\n const raw = isRecord(entry.raw) ? entry.raw : Object.create(null);\n if (raw.kind === 'device') {\n try {\n const metadata = parseDeviceMetadata(raw);\n if (metadata.id !== deviceId) {\n diagnostics.push({\n severity: 'error',\n code: 'device/invalid-description',\n message: `Device ${JSON.stringify(devicePath)} metadata id does not match its registration id.`,\n });\n continue;\n }\n devices.set(deviceId, {\n reference: { raw: formatDeviceReference(packageId, deviceId), packageId, deviceId },\n packageId,\n deviceId,\n displayName: metadata.displayName,\n description: metadata.description,\n designatorPrefix: metadata.designatorPrefix,\n propertyDescriptors: deviceMetadataPropertyDescriptors(metadata),\n symbol: deviceMetadataSymbol(metadata),\n raw,\n });\n } catch (error) {\n if (!(error instanceof SchematicError)) throw error;\n diagnostics.push(...error.diagnostics);\n }\n continue;\n }\n const displayName =\n typeof entry.displayName === 'string' && entry.displayName.length > 0\n ? entry.displayName\n : deviceId;\n const symbol = readSymbolGeometry(entry, raw, devicePath, diagnostics, reportedUnknownPins);\n const designatorPrefix = readDesignatorPrefix(entry, raw);\n\n devices.set(deviceId, {\n reference: {\n raw: formatDeviceReference(packageId, deviceId),\n packageId,\n deviceId,\n },\n packageId,\n deviceId,\n displayName,\n description: typeof entry.description === 'string' ? entry.description : undefined,\n designatorPrefix,\n propertyDescriptors: readPropertyDescriptors(raw['properties']),\n symbol,\n raw,\n });\n }\n\n registrationDiagnostics.push(...diagnostics);\n throwIfErrors(diagnostics);\n stored.set(packageId, { packageId, devices });\n },\n\n resolve(reference) {\n const parsed = typeof reference === 'string' ? parseDeviceReference(reference) : reference;\n if (parsed === undefined) {\n return undefined;\n }\n return lookup(parsed);\n },\n\n listDevices(packageId) {\n const packages = packageId === undefined ? [...stored.values()] : [stored.get(packageId)];\n const devices: ResolvedDevice[] = [];\n for (const pkg of packages) {\n if (pkg === undefined) {\n continue;\n }\n devices.push(...pkg.devices.values());\n }\n return devices.sort(\n (a, b) => a.packageId.localeCompare(b.packageId) || a.deviceId.localeCompare(b.deviceId),\n );\n },\n\n getDeviceSymbol(reference) {\n return lookup(reference)?.symbol;\n },\n\n getDeviceName,\n\n getDeviceDesignatorPrefix(reference) {\n return lookup(reference)?.designatorPrefix;\n },\n\n getDevicePropertyDescriptors(reference) {\n return lookup(reference)?.propertyDescriptors;\n },\n\n get diagnostics() {\n return registrationDiagnostics;\n },\n };\n\n for (const registration of packages) {\n registry.registerPackage(registration);\n }\n\n return registry;\n}\n\n/** Designator prefix declared on the entry, else inside `raw`, else `undefined` (caller defaults). */\nfunction readDesignatorPrefix(\n entry: DeviceRegistrationEntry,\n raw: Readonly<Record<string, unknown>>,\n): string | undefined {\n const declared = entry.designatorPrefix ?? raw['designatorPrefix'];\n if (typeof declared !== 'string') {\n return undefined;\n }\n const trimmed = declared.trim();\n return trimmed.length === 0 ? undefined : trimmed;\n}\n\nfunction readSymbolGeometry(\n entry: DeviceRegistrationEntry,\n raw: Readonly<Record<string, unknown>>,\n devicePath: string,\n diagnostics: Diagnostic[],\n reportedUnknownPins: Set<string>,\n): DeviceSymbolDefinition | undefined {\n const displayName =\n typeof entry.displayName === 'string' && entry.displayName.length > 0\n ? entry.displayName\n : entry.id;\n const symbol = entry.symbol;\n\n if (symbol === undefined) {\n // No explicit geometry: derive it from the #5 / #11 pin declaration.\n const declarations = readPinDeclarations(raw['pins']);\n if (declarations === undefined) {\n diagnostics.push({\n severity: 'warning',\n code: 'device/no-symbol',\n message: `Device ${JSON.stringify(devicePath)} has neither symbol geometry nor pin declarations.`,\n });\n return undefined;\n }\n const synthesized = synthesizeDeviceSymbol({ name: displayName, pins: declarations });\n return synthesized;\n }\n\n if (!isRecord(symbol)) {\n diagnostics.push({\n severity: 'error',\n code: 'device/invalid-description',\n message: `Device ${JSON.stringify(devicePath)} has an invalid symbol definition.`,\n });\n return undefined;\n }\n\n validateSymbolPresentation(symbol, diagnostics);\n const pins = readPins(symbol.pins, devicePath, diagnostics);\n if (pins === undefined) {\n return undefined;\n }\n\n const declaredPins = readDeclaredPinIds(raw.pins);\n if (declaredPins !== undefined) {\n for (const pinId of Object.keys(pins)) {\n if (!declaredPins.has(pinId) && !reportedUnknownPins.has(`${devicePath}\\u0000${pinId}`)) {\n reportedUnknownPins.add(`${devicePath}\\u0000${pinId}`);\n diagnostics.push({\n severity: 'error',\n code: 'device/unknown-pin',\n message: `Device ${JSON.stringify(devicePath)} symbol declares pin ${JSON.stringify(pinId)} which is absent from the pin declaration.`,\n });\n }\n }\n }\n\n const bounds = readBounds(symbol.bounds, devicePath, diagnostics);\n const declaredName =\n typeof symbol.name === 'string' && symbol.name.length > 0 ? symbol.name : undefined;\n const name = declaredName ?? displayName;\n\n return {\n name,\n pins,\n ...(bounds === undefined ? {} : { bounds }),\n ...(symbol.graphics === undefined ? {} : { graphics: symbol.graphics }),\n ...(symbol.annotations === undefined ? {} : { annotations: symbol.annotations }),\n };\n}\n\nfunction readPinDeclarations(value: unknown): Record<string, DevicePinDeclaration> | undefined {\n if (!isRecord(value) || Object.keys(value).length === 0) {\n return undefined;\n }\n const declarations: Record<string, DevicePinDeclaration> = Object.create(null);\n for (const [pinId, pin] of Object.entries(value)) {\n if (pinId.length === 0 || !isRecord(pin)) {\n return undefined;\n }\n const declaration: {\n -readonly [K in keyof DevicePinDeclaration]: DevicePinDeclaration[K];\n } = {};\n if (PIN_SIDES.includes(pin.side as PinSide)) {\n declaration.side = pin.side as PinSide;\n }\n declarations[pinId] = declaration;\n }\n return declarations;\n}\n\nfunction readPins(\n value: unknown,\n devicePath: string,\n diagnostics: Diagnostic[],\n): Record<string, PinAnchor> | undefined {\n if (!isRecord(value)) {\n diagnostics.push({\n severity: 'error',\n code: 'device/invalid-description',\n message: `Device ${JSON.stringify(devicePath)} symbol must declare a pins object.`,\n });\n return undefined;\n }\n const pins: Record<string, PinAnchor> = Object.create(null);\n let failed = false;\n for (const [pinId, anchor] of Object.entries(value)) {\n if (pinId.length === 0) {\n diagnostics.push({\n severity: 'error',\n code: 'device/invalid-description',\n message: `Device ${JSON.stringify(devicePath)} symbol declares an empty pin id.`,\n });\n failed = true;\n continue;\n }\n if (!isRecord(anchor) || !Number.isFinite(anchor.x) || !Number.isFinite(anchor.y)) {\n diagnostics.push({\n severity: 'error',\n code: 'device/invalid-description',\n message: `Device ${JSON.stringify(devicePath)} pin ${JSON.stringify(pinId)} must have finite x and y anchors.`,\n });\n failed = true;\n continue;\n }\n const side = anchor.side;\n if (side !== undefined && !PIN_SIDES.includes(side as PinSide)) {\n diagnostics.push({\n severity: 'error',\n code: 'device/invalid-description',\n message: `Device ${JSON.stringify(devicePath)} pin ${JSON.stringify(pinId)} has invalid side ${JSON.stringify(side)}.`,\n });\n failed = true;\n continue;\n }\n const presentation = anchor as unknown as PinAnchor;\n pins[pinId] = {\n x: anchor.x as number,\n y: anchor.y as number,\n ...(side === undefined ? {} : { side: side as PinSide }),\n ...(presentation.label === undefined ? {} : { label: presentation.label }),\n ...(presentation.displayName === undefined ? {} : { displayName: presentation.displayName }),\n };\n }\n return failed ? undefined : pins;\n}\n\nfunction readBounds(\n value: unknown,\n devicePath: string,\n diagnostics: Diagnostic[],\n): Rect | undefined {\n if (value === undefined) {\n return undefined;\n }\n if (\n !isRecord(value) ||\n !Number.isFinite(value.x) ||\n !Number.isFinite(value.y) ||\n !Number.isFinite(value.width) ||\n !Number.isFinite(value.height)\n ) {\n diagnostics.push({\n severity: 'error',\n code: 'device/invalid-description',\n message: `Device ${JSON.stringify(devicePath)} symbol bounds must have finite x, y, width and height.`,\n });\n return undefined;\n }\n return {\n x: value.x as number,\n y: value.y as number,\n width: value.width as number,\n height: value.height as number,\n };\n}\n\nfunction readDeclaredPinIds(value: unknown): Set<string> | undefined {\n if (!isRecord(value)) {\n return undefined;\n }\n return new Set(Object.keys(value));\n}\n","import type { SchematicDocument } from '../../format/types';\nimport { designatorOf, parseDeviceReference } from './reference';\nimport type { DeviceSymbolProvider } from './symbol';\n\n/** Prefix used when neither the host nor the device description provides one. */\nexport const DEFAULT_DESIGNATOR_PREFIX = 'U';\n\n/**\n * Picks the reference designator of a newly placed component. Hosts replace this when their\n * naming rules go beyond the device's own prefix.\n */\nexport type DesignatorFactory = (device: string, document: SchematicDocument) => string;\n\n/** Smallest unused `<prefix><n>` designator. */\nexport function nextDesignator(\n document: SchematicDocument,\n prefix: string = DEFAULT_DESIGNATOR_PREFIX,\n): string {\n const used = new Set(\n document.sheet.symbols\n .map((symbol) => designatorOf(symbol))\n .filter((designator): designator is string => designator !== undefined),\n );\n for (let index = 1; index < Number.MAX_SAFE_INTEGER; index += 1) {\n const candidate = `${prefix}${index}`;\n if (!used.has(candidate)) {\n return candidate;\n }\n }\n return prefix;\n}\n\n/**\n * Designator policy derived from the device descriptions: `<device prefix><n>`, falling back to\n * `U` for devices that declare none.\n */\nexport function createDesignatorFactory(\n devices: DeviceSymbolProvider | undefined,\n): DesignatorFactory {\n return (device, document) => nextDesignator(document, designatorPrefixOf(devices, device));\n}\n\n/** Prefix the device declares, else {@link DEFAULT_DESIGNATOR_PREFIX}. */\nexport function designatorPrefixOf(\n devices: DeviceSymbolProvider | undefined,\n device: string,\n): string {\n const reference = parseDeviceReference(device);\n const declared =\n reference === undefined ? undefined : devices?.getDeviceDesignatorPrefix?.(reference);\n return declared ?? DEFAULT_DESIGNATOR_PREFIX;\n}\n\n/** Default policy for providers without device data: `U1`, `U2`, … */\nexport const defaultDesignatorFactory: DesignatorFactory = (device, document) =>\n nextDesignator(document);\n"],"mappings":";;;;;;;;;AAQA,IAAa,oBAAoB;;;ACRjC,IAAa,eAAe;AAC5B,IAAa,eAAe;AAC5B,IAAa,gBAAgB;;AAE7B,IAAa,cAAc;AAC3B,IAAa,6BAA6B;AAK1C,IAAM,kBAA+D;EAClE,eAAe;EACf,eAAe;EACf,gBAAgB;AACnB;AAEA,IAAa,sBAAsB;AACnC,IAAa,uBAAuB;AACpC,IAAa,uBAAuB;AAQpC,IAAM,4BAA4B;AAClC,IAAM,uBAAuB;AAC7B,IAAM,oBAAoB;;;;;AAM1B,SAAgB,qBAAqB,KAA0C;CAC7E,MAAM,YAAY,IAAI,QAAQ,GAAG;CACjC,IAAI,aAAa,KAAK,cAAc,IAAI,SAAS,GAC/C;CAEF,IAAI,IAAI,QAAQ,KAAK,YAAY,CAAC,MAAM,IACtC;CAEF,MAAM,YAAY,IAAI,MAAM,GAAG,SAAS;CACxC,MAAM,WAAW,IAAI,MAAM,YAAY,CAAC;CACxC,IAAI,CAAC,iBAAiB,SAAS,KAAK,CAAC,kBAAkB,KAAK,QAAQ,GAClE;CAEF,OAAO;EAAE;EAAK;EAAW;CAAS;AACpC;AAEA,SAAgB,iBAAiB,WAA4B;CAC3D,IAAI,UAAU,WAAW,GAAG,GAAG;EAC7B,MAAM,QAAQ,UAAU,MAAM,GAAG;EACjC,IAAI,MAAM,WAAW,GACnB,OAAO;EAET,MAAM,CAAC,OAAO,QAAQ;EACtB,OACE,UAAU,KAAA,KAC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