kicadts 0.0.9 → 0.0.11

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/README.md CHANGED
@@ -183,36 +183,26 @@ await fs.writeFile("Demo_TestPad.kicad_mod", footprint.getString())
183
183
 
184
184
  ## Load Existing KiCad Files
185
185
 
186
- Parsing works for schematics, boards, footprints, or any KiCad S-expression. `parseKicadSexpr` returns an array of `SxClass` instances; narrow to the concrete class with `instanceof` and mutate as needed.
186
+ Use the specialized parse functions to load and validate schematics, boards, or footprints. Each function ensures the root element is the expected type.
187
187
 
188
188
  ```ts
189
189
  import { promises as fs } from "node:fs"
190
- import { KicadPcb, KicadSch, Footprint, parseKicadSexpr } from "kicadts"
190
+ import { parseKicadSch, parseKicadPcb, parseKicadMod } from "kicadts"
191
191
 
192
- const load = async (path: string) => {
193
- const raw = await fs.readFile(path, "utf8")
194
- const [root] = parseKicadSexpr(raw)
192
+ // Load and modify a schematic
193
+ const schematic = parseKicadSch(await fs.readFile("existing.kicad_sch", "utf8"))
194
+ schematic.generator = "kicadts"
195
+ await fs.writeFile("existing.kicad_sch", schematic.getString())
195
196
 
196
- if (root instanceof KicadSch) {
197
- root.generator = "kicadts"
198
- return root
199
- }
197
+ // Load and modify a PCB
198
+ const pcb = parseKicadPcb(await fs.readFile("existing.kicad_pcb", "utf8"))
199
+ pcb.generatorVersion = "(generated programmatically)"
200
+ await fs.writeFile("existing.kicad_pcb", pcb.getString())
200
201
 
201
- if (root instanceof KicadPcb) {
202
- root.generatorVersion = "(generated programmatically)"
203
- return root
204
- }
205
-
206
- if (root instanceof Footprint) {
207
- root.descr = "Imported with kicadts"
208
- return root
209
- }
210
-
211
- throw new Error(`Unsupported root token: ${root.token}`)
212
- }
213
-
214
- const updated = await load("existing.kicad_sch")
215
- await fs.writeFile("existing.kicad_sch", updated.getString())
202
+ // Load and modify a footprint
203
+ const footprint = parseKicadMod(await fs.readFile("Demo_TestPad.kicad_mod", "utf8"))
204
+ footprint.descr = "Imported with kicadts"
205
+ await fs.writeFile("Demo_TestPad.kicad_mod", footprint.getString())
216
206
  ```
217
207
 
218
- Any class exposes `getChildren()` if you need to walk the tree manually, and snapshot tests (`bun test`) ensure the emitted S-expression stays identical to KiCads own formatting.
208
+ For generic S-expression parsing, use `parseKicadSexpr` which returns an array of `SxClass` instances. Any class exposes `getChildren()` if you need to walk the tree manually, and snapshot tests (`bun test`) ensure the emitted S-expression stays identical to KiCad's own formatting.
package/dist/index.d.ts CHANGED
@@ -1195,38 +1195,6 @@ declare class Label extends SxClass {
1195
1195
  getString(): string;
1196
1196
  }
1197
1197
 
1198
- interface SchematicTextConstructorParams {
1199
- value?: string;
1200
- excludeFromSim?: boolean | ExcludeFromSim;
1201
- at?: AtInput;
1202
- effects?: TextEffects;
1203
- uuid?: string | Uuid;
1204
- }
1205
- declare class SchematicText extends SxClass {
1206
- static token: string;
1207
- static parentToken: string;
1208
- token: string;
1209
- private _value;
1210
- private _sxExcludeFromSim?;
1211
- private _sxAt?;
1212
- private _sxEffects?;
1213
- private _sxUuid?;
1214
- constructor(params?: SchematicTextConstructorParams);
1215
- static fromSexprPrimitives(primitiveSexprs: PrimitiveSExpr[]): SchematicText;
1216
- get value(): string;
1217
- set value(newValue: string);
1218
- get excludeFromSim(): boolean;
1219
- set excludeFromSim(value: boolean);
1220
- get at(): At | undefined;
1221
- set at(value: AtInput | undefined);
1222
- get effects(): TextEffects | undefined;
1223
- set effects(value: TextEffects | undefined);
1224
- get uuid(): Uuid | undefined;
1225
- set uuid(value: Uuid | string | undefined);
1226
- getChildren(): SxClass[];
1227
- getString(): string;
1228
- }
1229
-
1230
1198
  declare class PropertyHide extends SxPrimitiveBoolean {
1231
1199
  static token: string;
1232
1200
  static parentToken: string;
@@ -1283,6 +1251,79 @@ declare class Property extends SxClass {
1283
1251
  getString(): string;
1284
1252
  }
1285
1253
 
1254
+ type GlobalLabelShape = "input" | "output" | "bidirectional" | "tri_state" | "passive";
1255
+ interface GlobalLabelConstructorParams {
1256
+ value?: string;
1257
+ shape?: GlobalLabelShape;
1258
+ at?: AtInput;
1259
+ effects?: TextEffects;
1260
+ uuid?: string | Uuid;
1261
+ fieldsAutoplaced?: boolean | FieldsAutoplaced;
1262
+ properties?: Property[];
1263
+ }
1264
+ declare class GlobalLabel extends SxClass {
1265
+ static token: string;
1266
+ static parentToken: string;
1267
+ token: string;
1268
+ private _value;
1269
+ private _shape;
1270
+ private _sxAt?;
1271
+ private _sxEffects?;
1272
+ private _sxUuid?;
1273
+ private _sxFieldsAutoplaced?;
1274
+ private _properties;
1275
+ constructor(params?: GlobalLabelConstructorParams);
1276
+ static fromSexprPrimitives(primitiveSexprs: PrimitiveSExpr[]): GlobalLabel;
1277
+ get value(): string;
1278
+ set value(newValue: string);
1279
+ get shape(): GlobalLabelShape;
1280
+ set shape(value: GlobalLabelShape);
1281
+ get at(): At | undefined;
1282
+ set at(value: AtInput | undefined);
1283
+ get effects(): TextEffects | undefined;
1284
+ set effects(value: TextEffects | undefined);
1285
+ get uuid(): Uuid | undefined;
1286
+ set uuid(value: Uuid | string | undefined);
1287
+ get fieldsAutoplaced(): boolean;
1288
+ set fieldsAutoplaced(value: boolean);
1289
+ get properties(): Property[];
1290
+ set properties(value: Property[]);
1291
+ getChildren(): SxClass[];
1292
+ getString(): string;
1293
+ }
1294
+
1295
+ interface SchematicTextConstructorParams {
1296
+ value?: string;
1297
+ excludeFromSim?: boolean | ExcludeFromSim;
1298
+ at?: AtInput;
1299
+ effects?: TextEffects;
1300
+ uuid?: string | Uuid;
1301
+ }
1302
+ declare class SchematicText extends SxClass {
1303
+ static token: string;
1304
+ static parentToken: string;
1305
+ token: string;
1306
+ private _value;
1307
+ private _sxExcludeFromSim?;
1308
+ private _sxAt?;
1309
+ private _sxEffects?;
1310
+ private _sxUuid?;
1311
+ constructor(params?: SchematicTextConstructorParams);
1312
+ static fromSexprPrimitives(primitiveSexprs: PrimitiveSExpr[]): SchematicText;
1313
+ get value(): string;
1314
+ set value(newValue: string);
1315
+ get excludeFromSim(): boolean;
1316
+ set excludeFromSim(value: boolean);
1317
+ get at(): At | undefined;
1318
+ set at(value: AtInput | undefined);
1319
+ get effects(): TextEffects | undefined;
1320
+ set effects(value: TextEffects | undefined);
1321
+ get uuid(): Uuid | undefined;
1322
+ set uuid(value: Uuid | string | undefined);
1323
+ getChildren(): SxClass[];
1324
+ getString(): string;
1325
+ }
1326
+
1286
1327
  declare class SheetInstancesRoot extends SxClass {
1287
1328
  static token: string;
1288
1329
  token: string;
@@ -1528,6 +1569,7 @@ interface KicadSchConstructorParams {
1528
1569
  symbols?: SchematicSymbol[];
1529
1570
  texts?: SchematicText[];
1530
1571
  labels?: Label[];
1572
+ globalLabels?: GlobalLabel[];
1531
1573
  wires?: Wire[];
1532
1574
  junctions?: Junction[];
1533
1575
  }
@@ -1549,6 +1591,7 @@ declare class KicadSch extends SxClass {
1549
1591
  private _symbols;
1550
1592
  private _texts;
1551
1593
  private _labels;
1594
+ private _globalLabels;
1552
1595
  private _wires;
1553
1596
  private _junctions;
1554
1597
  constructor(params?: KicadSchConstructorParams);
@@ -1583,6 +1626,8 @@ declare class KicadSch extends SxClass {
1583
1626
  set texts(value: SchematicText[]);
1584
1627
  get labels(): Label[];
1585
1628
  set labels(value: Label[]);
1629
+ get globalLabels(): GlobalLabel[];
1630
+ set globalLabels(value: GlobalLabel[]);
1586
1631
  get junctions(): Junction[];
1587
1632
  set junctions(value: Junction[]);
1588
1633
  get wires(): Wire[];
@@ -4473,5 +4518,8 @@ declare class KicadPcb extends SxClass {
4473
4518
  }
4474
4519
 
4475
4520
  declare const parseKicadSexpr: (sexpr: string) => SxClass[];
4521
+ declare const parseKicadSch: (sexpr: string) => KicadSch;
4522
+ declare const parseKicadPcb: (sexpr: string) => KicadPcb;
4523
+ declare const parseKicadMod: (sexpr: string) => Footprint;
4476
4524
 
4477
- export { At, type AtInput, Bus, type BusConstructorParams, BusEntry, type BusEntryConstructorParams, BusEntrySize, Color, Dnp, EmbeddedFonts, ExcludeFromSim, FieldsAutoplaced, Footprint, FootprintAttr, FootprintAutoplaceCost180, FootprintAutoplaceCost90, FootprintClearance, type FootprintConstructorParams, FootprintDescr, FootprintLocked, FootprintModel, FootprintNetTiePadGroups, FootprintPad, type FootprintPadConstructorParams, FootprintPath, FootprintPlaced, FootprintPrivateLayers, FootprintSheetfile, FootprintSheetname, FootprintSolderMaskMargin, FootprintSolderPasteMargin, FootprintSolderPasteRatio, FootprintTags, FootprintTedit, FootprintThermalGap, FootprintThermalWidth, FootprintZoneConnect, FpArc, type FpArcConstructorParams, FpArcEnd, FpArcMid, FpArcStart, FpCircle, FpCircleCenter, type FpCircleConstructorParams, FpCircleEnd, FpCircleFill, FpLine, type FpLineConstructorParams, FpLineEnd, FpLineStart, FpPoly, type FpPolyConstructorParams, FpPolyFill, FpPolyLocked, FpRect, type FpRectConstructorParams, FpRectEnd, FpRectFill, FpRectStart, FpText, FpTextBox, FpTextBoxAngle, type FpTextBoxConstructorParams, FpTextBoxEnd, FpTextBoxStart, type FpTextConstructorParams, type FpTextType, GrLine, GrLineAngle, type GrLineConstructorParams, GrLineEnd, GrLineLocked, type GrLinePoint, GrLineStart, GrText, type GrTextConstructorParams, type GrTextPosition, Image, type ImageConstructorParams, ImageData, ImageScale, InBom, Junction, type JunctionConstructorParams, JunctionDiameter, KicadPcb, type KicadPcbConstructorParams, KicadSch, type KicadSchConstructorParams, KicadSchGenerator, KicadSchGeneratorVersion, KicadSchVersion, Label, type LabelConstructorParams, Layer, Layers, LibSymbols, type ModelVector, NoConnect, type NoConnectConstructorParams, OnBoard, PadChamfer, PadChamferRatio, PadClearance, PadDieLength, PadDrill, PadDrillOffset, PadLayers, type PadLayersInput, PadNet, PadOptions, type PadOptionsAnchorShape, type PadOptionsClearanceType, PadPinFunction, PadPinType, PadPrimitiveGrArc, type PadPrimitiveGrArcConstructorParams, PadPrimitiveGrCircle, type PadPrimitiveGrCircleConstructorParams, PadPrimitiveGrLine, PadPrimitiveGrPoly, PadPrimitives, PadRectDelta, PadRoundrectRratio, PadSize, type PadSizeInput, PadSolderMaskMargin, PadSolderPasteMargin, PadSolderPasteMarginRatio, PadTeardrops, PadThermalBridgeAngle, PadThermalGap, PadThermalWidth, PadZoneConnect, Paper, PcbGeneral, PcbGeneralLegacyTeardrops, PcbGeneralThickness, PcbGenerator, PcbGeneratorVersion, PcbLayerDefinition, PcbLayers, PcbNet, PcbPlotParams, PcbVersion, PlotParamCreateGerberJobFile, PlotParamCrossoutDnpOnFab, PlotParamDashedLineDashRatio, PlotParamDashedLineGapRatio, PlotParamDisableApertMacros, PlotParamDrillShape, PlotParamDxfImperialUnits, PlotParamDxfPolygonMode, PlotParamDxfUsePcbnewFont, PlotParamExcludeEdgeLayer, PlotParamHideDnpOnFab, PlotParamHpglPenDiameter, PlotParamHpglPenNumber, PlotParamHpglPenOverlay, PlotParamHpglPenSpeed, PlotParamLayerSelection, PlotParamLineWidth, PlotParamMirror, PlotParamMode, PlotParamOutputDirectory, PlotParamOutputFormat, PlotParamPadOnSilk, PlotParamPdfBackFpPropertyPopups, PlotParamPdfFrontFpPropertyPopups, PlotParamPdfMetadata, PlotParamPdfSingleDocument, PlotParamPlotBlackAndWhite, PlotParamPlotFrameRef, PlotParamPlotInvisible, PlotParamPlotInvisibleText, PlotParamPlotOnAllLayers, PlotParamPlotOnAllLayersSelection, PlotParamPlotOtherText, PlotParamPlotPadNumbers, PlotParamPlotReference, PlotParamPlotValue, PlotParamProperty, PlotParamPsA4Output, PlotParamPsNegative, PlotParamScaleSelection, PlotParamSketchDnpOnFab, PlotParamSketchPadsOnFab, PlotParamSubtractMaskFromSilk, PlotParamSvgPrecision, PlotParamUseAuxOrigin, PlotParamUseGerberAdvancedAttributes, PlotParamUseGerberAttributes, PlotParamUseGerberExtensions, PlotParamViaOnMask, Property, type PropertyConstructorParams, PropertyHide, PropertyUnlocked, Pts, type RGBAColor, RenderCache, SchematicSymbol, type SchematicSymbolConstructorParams, SchematicText, type SchematicTextConstructorParams, Segment, type SegmentConstructorParams, SegmentEnd, SegmentLocked, SegmentNet, SegmentStart, Setup, SetupAllowSoldermaskBridgesInFootprints, SetupAuxAxisOrigin, SetupEdgeWidth, SetupGridOrigin, SetupLastTraceWidth, SetupModEdgeWidth, SetupModTextSize, SetupModTextWidth, SetupPadDrill, SetupPadSize, SetupPadToMaskClearance, SetupPadToPasteClearance, SetupPadToPasteClearanceRatio, SetupPadToPasteClearanceValues, SetupPcbTextSize, SetupPcbTextWidth, type SetupProperty, type SetupPropertyValues, SetupSegmentWidth, SetupSolderMaskMinWidth, SetupTenting, SetupTraceClearance, SetupTraceMin, SetupTraceWidth, SetupUviaDrill, SetupUviaMinDrill, SetupUviaMinSize, SetupUviaSize, SetupUviasAllowed, SetupViaDrill, SetupViaMinDrill, SetupViaMinSize, SetupViaSize, SetupVisibleElements, SetupZone45Only, SetupZoneClearance, Sheet, type SheetConstructorParams, SheetFill, SheetInstancePage, SheetInstancePath, SheetInstances, SheetInstancesForSheet, SheetInstancesProject, SheetInstancesRoot, SheetInstancesRootPage, SheetInstancesRootPath, SheetPin, type SheetPinElectricalType, SheetProperty, SheetSize, Stackup, StackupCastellatedPads, StackupCopperFinish, StackupDielectricConstraints, StackupEdgeConnector, StackupEdgePlating, StackupLayer, StackupLayerColor, StackupLayerEpsilonR, StackupLayerLossTangent, StackupLayerMaterial, StackupLayerThickness, StackupLayerType, type StandardPaperSize, Stroke, type StrokeProperty, StrokeType, type StrokeTypeString, SxClass, SymbolArc, SymbolArcEnd, SymbolArcFill, SymbolArcMid, SymbolArcStart, SymbolCircle, SymbolCircleCenter, SymbolCircleFill, SymbolCircleRadius, SymbolDuplicatePinNumbersAreJumpers, SymbolFillType, SymbolInstancePath, SymbolInstanceReference, SymbolInstanceUnit, SymbolInstances, SymbolInstancesProject, SymbolLibId, SymbolPin, SymbolPinLength, SymbolPinName, SymbolPinNames, SymbolPinNamesHide, SymbolPinNamesOffset, SymbolPinNumber, SymbolPinNumbers, SymbolPinNumbersHide, SymbolPolyline, SymbolPolylineFill, SymbolPower, SymbolProperty, SymbolPropertyId, SymbolRectangle, SymbolRectangleEnd, SymbolRectangleFill, SymbolRectangleStart, SymbolText, SymbolUnit, TextEffects, type TextEffectsConstructorParams, TextEffectsFont, TextEffectsFontFace, TextEffectsFontLineSpacing, type TextEffectsFontProperty, TextEffectsFontSize, TextEffectsFontThickness, TextEffectsJustify, type TextEffectsProperty, TitleBlock, TitleBlockComment, TitleBlockCompany, type TitleBlockConstructorParams, TitleBlockDate, TitleBlockRevision, TitleBlockTitle, Unit, type UnitString, Uuid, Via, type ViaConstructorParams, ViaNet, Width, Wire, type WireConstructorParams, Xy, Zone, parseKicadSexpr };
4525
+ export { At, type AtInput, Bus, type BusConstructorParams, BusEntry, type BusEntryConstructorParams, BusEntrySize, Color, Dnp, EmbeddedFonts, ExcludeFromSim, FieldsAutoplaced, Footprint, FootprintAttr, FootprintAutoplaceCost180, FootprintAutoplaceCost90, FootprintClearance, type FootprintConstructorParams, FootprintDescr, FootprintLocked, FootprintModel, FootprintNetTiePadGroups, FootprintPad, type FootprintPadConstructorParams, FootprintPath, FootprintPlaced, FootprintPrivateLayers, FootprintSheetfile, FootprintSheetname, FootprintSolderMaskMargin, FootprintSolderPasteMargin, FootprintSolderPasteRatio, FootprintTags, FootprintTedit, FootprintThermalGap, FootprintThermalWidth, FootprintZoneConnect, FpArc, type FpArcConstructorParams, FpArcEnd, FpArcMid, FpArcStart, FpCircle, FpCircleCenter, type FpCircleConstructorParams, FpCircleEnd, FpCircleFill, FpLine, type FpLineConstructorParams, FpLineEnd, FpLineStart, FpPoly, type FpPolyConstructorParams, FpPolyFill, FpPolyLocked, FpRect, type FpRectConstructorParams, FpRectEnd, FpRectFill, FpRectStart, FpText, FpTextBox, FpTextBoxAngle, type FpTextBoxConstructorParams, FpTextBoxEnd, FpTextBoxStart, type FpTextConstructorParams, type FpTextType, GlobalLabel, type GlobalLabelConstructorParams, type GlobalLabelShape, GrLine, GrLineAngle, type GrLineConstructorParams, GrLineEnd, GrLineLocked, type GrLinePoint, GrLineStart, GrText, type GrTextConstructorParams, type GrTextPosition, Image, type ImageConstructorParams, ImageData, ImageScale, InBom, Junction, type JunctionConstructorParams, JunctionDiameter, KicadPcb, type KicadPcbConstructorParams, KicadSch, type KicadSchConstructorParams, KicadSchGenerator, KicadSchGeneratorVersion, KicadSchVersion, Label, type LabelConstructorParams, Layer, Layers, LibSymbols, type ModelVector, NoConnect, type NoConnectConstructorParams, OnBoard, PadChamfer, PadChamferRatio, PadClearance, PadDieLength, PadDrill, PadDrillOffset, PadLayers, type PadLayersInput, PadNet, PadOptions, type PadOptionsAnchorShape, type PadOptionsClearanceType, PadPinFunction, PadPinType, PadPrimitiveGrArc, type PadPrimitiveGrArcConstructorParams, PadPrimitiveGrCircle, type PadPrimitiveGrCircleConstructorParams, PadPrimitiveGrLine, PadPrimitiveGrPoly, PadPrimitives, PadRectDelta, PadRoundrectRratio, PadSize, type PadSizeInput, PadSolderMaskMargin, PadSolderPasteMargin, PadSolderPasteMarginRatio, PadTeardrops, PadThermalBridgeAngle, PadThermalGap, PadThermalWidth, PadZoneConnect, Paper, PcbGeneral, PcbGeneralLegacyTeardrops, PcbGeneralThickness, PcbGenerator, PcbGeneratorVersion, PcbLayerDefinition, PcbLayers, PcbNet, PcbPlotParams, PcbVersion, PlotParamCreateGerberJobFile, PlotParamCrossoutDnpOnFab, PlotParamDashedLineDashRatio, PlotParamDashedLineGapRatio, PlotParamDisableApertMacros, PlotParamDrillShape, PlotParamDxfImperialUnits, PlotParamDxfPolygonMode, PlotParamDxfUsePcbnewFont, PlotParamExcludeEdgeLayer, PlotParamHideDnpOnFab, PlotParamHpglPenDiameter, PlotParamHpglPenNumber, PlotParamHpglPenOverlay, PlotParamHpglPenSpeed, PlotParamLayerSelection, PlotParamLineWidth, PlotParamMirror, PlotParamMode, PlotParamOutputDirectory, PlotParamOutputFormat, PlotParamPadOnSilk, PlotParamPdfBackFpPropertyPopups, PlotParamPdfFrontFpPropertyPopups, PlotParamPdfMetadata, PlotParamPdfSingleDocument, PlotParamPlotBlackAndWhite, PlotParamPlotFrameRef, PlotParamPlotInvisible, PlotParamPlotInvisibleText, PlotParamPlotOnAllLayers, PlotParamPlotOnAllLayersSelection, PlotParamPlotOtherText, PlotParamPlotPadNumbers, PlotParamPlotReference, PlotParamPlotValue, PlotParamProperty, PlotParamPsA4Output, PlotParamPsNegative, PlotParamScaleSelection, PlotParamSketchDnpOnFab, PlotParamSketchPadsOnFab, PlotParamSubtractMaskFromSilk, PlotParamSvgPrecision, PlotParamUseAuxOrigin, PlotParamUseGerberAdvancedAttributes, PlotParamUseGerberAttributes, PlotParamUseGerberExtensions, PlotParamViaOnMask, Property, type PropertyConstructorParams, PropertyHide, PropertyUnlocked, Pts, type RGBAColor, RenderCache, SchematicSymbol, type SchematicSymbolConstructorParams, SchematicText, type SchematicTextConstructorParams, Segment, type SegmentConstructorParams, SegmentEnd, SegmentLocked, SegmentNet, SegmentStart, Setup, SetupAllowSoldermaskBridgesInFootprints, SetupAuxAxisOrigin, SetupEdgeWidth, SetupGridOrigin, SetupLastTraceWidth, SetupModEdgeWidth, SetupModTextSize, SetupModTextWidth, SetupPadDrill, SetupPadSize, SetupPadToMaskClearance, SetupPadToPasteClearance, SetupPadToPasteClearanceRatio, SetupPadToPasteClearanceValues, SetupPcbTextSize, SetupPcbTextWidth, type SetupProperty, type SetupPropertyValues, SetupSegmentWidth, SetupSolderMaskMinWidth, SetupTenting, SetupTraceClearance, SetupTraceMin, SetupTraceWidth, SetupUviaDrill, SetupUviaMinDrill, SetupUviaMinSize, SetupUviaSize, SetupUviasAllowed, SetupViaDrill, SetupViaMinDrill, SetupViaMinSize, SetupViaSize, SetupVisibleElements, SetupZone45Only, SetupZoneClearance, Sheet, type SheetConstructorParams, SheetFill, SheetInstancePage, SheetInstancePath, SheetInstances, SheetInstancesForSheet, SheetInstancesProject, SheetInstancesRoot, SheetInstancesRootPage, SheetInstancesRootPath, SheetPin, type SheetPinElectricalType, SheetProperty, SheetSize, Stackup, StackupCastellatedPads, StackupCopperFinish, StackupDielectricConstraints, StackupEdgeConnector, StackupEdgePlating, StackupLayer, StackupLayerColor, StackupLayerEpsilonR, StackupLayerLossTangent, StackupLayerMaterial, StackupLayerThickness, StackupLayerType, type StandardPaperSize, Stroke, type StrokeProperty, StrokeType, type StrokeTypeString, SxClass, SymbolArc, SymbolArcEnd, SymbolArcFill, SymbolArcMid, SymbolArcStart, SymbolCircle, SymbolCircleCenter, SymbolCircleFill, SymbolCircleRadius, SymbolDuplicatePinNumbersAreJumpers, SymbolFillType, SymbolInstancePath, SymbolInstanceReference, SymbolInstanceUnit, SymbolInstances, SymbolInstancesProject, SymbolLibId, SymbolPin, SymbolPinLength, SymbolPinName, SymbolPinNames, SymbolPinNamesHide, SymbolPinNamesOffset, SymbolPinNumber, SymbolPinNumbers, SymbolPinNumbersHide, SymbolPolyline, SymbolPolylineFill, SymbolPower, SymbolProperty, SymbolPropertyId, SymbolRectangle, SymbolRectangleEnd, SymbolRectangleFill, SymbolRectangleStart, SymbolText, SymbolUnit, TextEffects, type TextEffectsConstructorParams, TextEffectsFont, TextEffectsFontFace, TextEffectsFontLineSpacing, type TextEffectsFontProperty, TextEffectsFontSize, TextEffectsFontThickness, TextEffectsJustify, type TextEffectsProperty, TitleBlock, TitleBlockComment, TitleBlockCompany, type TitleBlockConstructorParams, TitleBlockDate, TitleBlockRevision, TitleBlockTitle, Unit, type UnitString, Uuid, Via, type ViaConstructorParams, ViaNet, Width, Wire, type WireConstructorParams, Xy, Zone, parseKicadMod, parseKicadPcb, parseKicadSch, parseKicadSexpr };
package/dist/index.js CHANGED
@@ -3776,121 +3776,6 @@ var Label = class _Label extends SxClass {
3776
3776
  };
3777
3777
  SxClass.register(Label);
3778
3778
 
3779
- // lib/sexpr/classes/SchematicText.ts
3780
- var SUPPORTED_TOKENS6 = /* @__PURE__ */ new Set(["exclude_from_sim", "at", "effects", "uuid"]);
3781
- var SchematicText = class _SchematicText extends SxClass {
3782
- static token = "text";
3783
- static parentToken = "kicad_sch";
3784
- token = "text";
3785
- _value = "";
3786
- _sxExcludeFromSim;
3787
- _sxAt;
3788
- _sxEffects;
3789
- _sxUuid;
3790
- constructor(params = {}) {
3791
- super();
3792
- if (params.value !== void 0) {
3793
- this.value = params.value;
3794
- }
3795
- if (params.excludeFromSim !== void 0) {
3796
- this.excludeFromSim = typeof params.excludeFromSim === "boolean" ? params.excludeFromSim : params.excludeFromSim.value;
3797
- }
3798
- if (params.at !== void 0) {
3799
- this.at = params.at;
3800
- }
3801
- if (params.effects !== void 0) {
3802
- this.effects = params.effects;
3803
- }
3804
- if (params.uuid !== void 0) {
3805
- this.uuid = params.uuid;
3806
- }
3807
- }
3808
- static fromSexprPrimitives(primitiveSexprs) {
3809
- const [textPrimitive, ...rest] = primitiveSexprs;
3810
- const value = toStringValue(textPrimitive);
3811
- if (value === void 0) {
3812
- throw new Error("text expects a string value");
3813
- }
3814
- const text = new _SchematicText();
3815
- text._value = value;
3816
- const { propertyMap, arrayPropertyMap } = SxClass.parsePrimitivesToClassProperties(rest, this.token);
3817
- const unsupportedTokens = Object.keys(propertyMap).filter(
3818
- (token) => !SUPPORTED_TOKENS6.has(token)
3819
- );
3820
- if (unsupportedTokens.length > 0) {
3821
- throw new Error(
3822
- `Unsupported child tokens inside text expression: ${unsupportedTokens.join(", ")}`
3823
- );
3824
- }
3825
- for (const [token, entries] of Object.entries(arrayPropertyMap)) {
3826
- if (!SUPPORTED_TOKENS6.has(token)) {
3827
- throw new Error(
3828
- `Unsupported child tokens inside text expression: ${token}`
3829
- );
3830
- }
3831
- if (entries.length > 1) {
3832
- throw new Error(`text does not support repeated child tokens: ${token}`);
3833
- }
3834
- }
3835
- text._sxExcludeFromSim = arrayPropertyMap.exclude_from_sim?.[0] ?? propertyMap.exclude_from_sim;
3836
- text._sxAt = arrayPropertyMap.at?.[0] ?? propertyMap.at;
3837
- text._sxEffects = arrayPropertyMap.effects?.[0] ?? propertyMap.effects;
3838
- text._sxUuid = arrayPropertyMap.uuid?.[0] ?? propertyMap.uuid;
3839
- return text;
3840
- }
3841
- get value() {
3842
- return this._value;
3843
- }
3844
- set value(newValue) {
3845
- this._value = newValue;
3846
- }
3847
- get excludeFromSim() {
3848
- return this._sxExcludeFromSim?.value ?? false;
3849
- }
3850
- set excludeFromSim(value) {
3851
- this._sxExcludeFromSim = value ? new ExcludeFromSim(true) : void 0;
3852
- }
3853
- get at() {
3854
- return this._sxAt;
3855
- }
3856
- set at(value) {
3857
- this._sxAt = value !== void 0 ? At.from(value) : void 0;
3858
- }
3859
- get effects() {
3860
- return this._sxEffects;
3861
- }
3862
- set effects(value) {
3863
- this._sxEffects = value;
3864
- }
3865
- get uuid() {
3866
- return this._sxUuid;
3867
- }
3868
- set uuid(value) {
3869
- if (value === void 0) {
3870
- this._sxUuid = void 0;
3871
- return;
3872
- }
3873
- this._sxUuid = value instanceof Uuid ? value : new Uuid(value);
3874
- }
3875
- getChildren() {
3876
- const children = [];
3877
- if (this._sxExcludeFromSim) children.push(this._sxExcludeFromSim);
3878
- if (this._sxAt) children.push(this._sxAt);
3879
- if (this._sxEffects) children.push(this._sxEffects);
3880
- if (this._sxUuid) children.push(this._sxUuid);
3881
- return children;
3882
- }
3883
- getString() {
3884
- const lines = [`(text ${quoteSExprString(this._value)}`];
3885
- for (const child of this.getChildren()) {
3886
- lines.push(child.getStringIndented());
3887
- }
3888
- lines.push(")");
3889
- return lines.join("\n");
3890
- }
3891
- };
3892
- SxClass.register(SchematicText);
3893
-
3894
3779
  // lib/sexpr/classes/PropertyHide.ts
3895
3780
  var PropertyHide = class extends SxPrimitiveBoolean {
3896
3781
  static token = "hide";
@@ -4138,6 +4023,285 @@ var Property = class _Property extends SxClass {
4138
4023
  };
4139
4024
  SxClass.register(Property);
4140
4025
 
4026
+ // lib/sexpr/classes/GlobalLabel.ts
4027
+ var SUPPORTED_TOKENS6 = /* @__PURE__ */ new Set([
4028
+ "shape",
4029
+ "at",
4030
+ "effects",
4031
+ "uuid",
4032
+ "fields_autoplaced",
4033
+ "property"
4034
+ ]);
4035
+ var GlobalLabel = class _GlobalLabel extends SxClass {
4036
+ static token = "global_label";
4037
+ static parentToken = "kicad_sch";
4038
+ token = "global_label";
4039
+ _value = "";
4040
+ _shape = "input";
4041
+ _sxAt;
4042
+ _sxEffects;
4043
+ _sxUuid;
4044
+ _sxFieldsAutoplaced;
4045
+ _properties = [];
4046
+ constructor(params = {}) {
4047
+ super();
4048
+ if (params.value !== void 0) {
4049
+ this.value = params.value;
4050
+ }
4051
+ if (params.shape !== void 0) {
4052
+ this.shape = params.shape;
4053
+ }
4054
+ if (params.at !== void 0) {
4055
+ this.at = params.at;
4056
+ }
4057
+ if (params.effects !== void 0) {
4058
+ this.effects = params.effects;
4059
+ }
4060
+ if (params.uuid !== void 0) {
4061
+ this.uuid = params.uuid;
4062
+ }
4063
+ if (params.fieldsAutoplaced !== void 0) {
4064
+ if (params.fieldsAutoplaced instanceof FieldsAutoplaced) {
4065
+ this._sxFieldsAutoplaced = params.fieldsAutoplaced;
4066
+ } else {
4067
+ this.fieldsAutoplaced = params.fieldsAutoplaced;
4068
+ }
4069
+ }
4070
+ if (params.properties !== void 0) {
4071
+ this.properties = params.properties;
4072
+ }
4073
+ }
4074
+ static fromSexprPrimitives(primitiveSexprs) {
4075
+ const [textPrimitive, ...rest] = primitiveSexprs;
4076
+ const value = toStringValue(textPrimitive);
4077
+ if (value === void 0) {
4078
+ throw new Error("global_label expects a string value");
4079
+ }
4080
+ const globalLabel = new _GlobalLabel();
4081
+ globalLabel._value = value;
4082
+ let shapeIndex = -1;
4083
+ for (let i = 0; i < rest.length; i++) {
4084
+ const item = rest[i];
4085
+ if (Array.isArray(item) && item[0] === "shape" && item.length === 2) {
4086
+ shapeIndex = i;
4087
+ const shapeValue = toStringValue(item[1]);
4088
+ if (shapeValue) {
4089
+ globalLabel._shape = shapeValue;
4090
+ }
4091
+ break;
4092
+ }
4093
+ }
4094
+ const restWithoutShape = shapeIndex >= 0 ? rest.filter((_, i) => i !== shapeIndex) : rest;
4095
+ const { propertyMap, arrayPropertyMap } = SxClass.parsePrimitivesToClassProperties(restWithoutShape, this.token);
4096
+ const unsupportedTokens = Object.keys(propertyMap).filter(
4097
+ (token) => !SUPPORTED_TOKENS6.has(token)
4098
+ );
4099
+ if (unsupportedTokens.length > 0) {
4100
+ throw new Error(
4101
+ `Unsupported child tokens inside global_label expression: ${unsupportedTokens.join(", ")}`
4102
+ );
4103
+ }
4104
+ for (const [token, entries] of Object.entries(arrayPropertyMap)) {
4105
+ if (!SUPPORTED_TOKENS6.has(token)) {
4106
+ throw new Error(
4107
+ `Unsupported child tokens inside global_label expression: ${token}`
4108
+ );
4109
+ }
4110
+ if (token !== "property" && entries.length > 1) {
4111
+ throw new Error(
4112
+ `global_label does not support repeated child tokens: ${token}`
4113
+ );
4114
+ }
4115
+ }
4116
+ globalLabel._sxAt = arrayPropertyMap.at?.[0] ?? propertyMap.at;
4117
+ globalLabel._sxEffects = arrayPropertyMap.effects?.[0] ?? propertyMap.effects;
4118
+ globalLabel._sxUuid = arrayPropertyMap.uuid?.[0] ?? propertyMap.uuid;
4119
+ globalLabel._sxFieldsAutoplaced = arrayPropertyMap.fields_autoplaced?.[0] ?? propertyMap.fields_autoplaced;
4120
+ globalLabel._properties = arrayPropertyMap.property ?? [];
4121
+ return globalLabel;
4122
+ }
4123
+ get value() {
4124
+ return this._value;
4125
+ }
4126
+ set value(newValue) {
4127
+ this._value = newValue;
4128
+ }
4129
+ get shape() {
4130
+ return this._shape;
4131
+ }
4132
+ set shape(value) {
4133
+ this._shape = value;
4134
+ }
4135
+ get at() {
4136
+ return this._sxAt;
4137
+ }
4138
+ set at(value) {
4139
+ this._sxAt = value !== void 0 ? At.from(value) : void 0;
4140
+ }
4141
+ get effects() {
4142
+ return this._sxEffects;
4143
+ }
4144
+ set effects(value) {
4145
+ this._sxEffects = value;
4146
+ }
4147
+ get uuid() {
4148
+ return this._sxUuid;
4149
+ }
4150
+ set uuid(value) {
4151
+ if (value === void 0) {
4152
+ this._sxUuid = void 0;
4153
+ return;
4154
+ }
4155
+ this._sxUuid = value instanceof Uuid ? value : new Uuid(value);
4156
+ }
4157
+ get fieldsAutoplaced() {
4158
+ return this._sxFieldsAutoplaced?.value ?? false;
4159
+ }
4160
+ set fieldsAutoplaced(value) {
4161
+ this._sxFieldsAutoplaced = new FieldsAutoplaced(value);
4162
+ }
4163
+ get properties() {
4164
+ return [...this._properties];
4165
+ }
4166
+ set properties(value) {
4167
+ this._properties = [...value];
4168
+ }
4169
+ getChildren() {
4170
+ const children = [];
4171
+ if (this._sxAt) children.push(this._sxAt);
4172
+ if (this._sxEffects) children.push(this._sxEffects);
4173
+ if (this._sxUuid) children.push(this._sxUuid);
4174
+ children.push(...this._properties);
4175
+ if (this._sxFieldsAutoplaced) children.push(this._sxFieldsAutoplaced);
4176
+ return children;
4177
+ }
4178
+ getString() {
4179
+ const lines = [`(global_label ${quoteSExprString(this._value)}`];
4180
+ lines.push(` (shape ${this._shape})`);
4181
+ for (const child of this.getChildren()) {
4182
+ lines.push(child.getStringIndented());
4183
+ }
4184
+ lines.push(")");
4185
+ return lines.join("\n");
4186
+ }
4187
+ };
4188
+ SxClass.register(GlobalLabel);
4189
+
4190
+ // lib/sexpr/classes/SchematicText.ts
4191
+ var SUPPORTED_TOKENS7 = /* @__PURE__ */ new Set(["exclude_from_sim", "at", "effects", "uuid"]);
4192
+ var SchematicText = class _SchematicText extends SxClass {
4193
+ static token = "text";
4194
+ static parentToken = "kicad_sch";
4195
+ token = "text";
4196
+ _value = "";
4197
+ _sxExcludeFromSim;
4198
+ _sxAt;
4199
+ _sxEffects;
4200
+ _sxUuid;
4201
+ constructor(params = {}) {
4202
+ super();
4203
+ if (params.value !== void 0) {
4204
+ this.value = params.value;
4205
+ }
4206
+ if (params.excludeFromSim !== void 0) {
4207
+ this.excludeFromSim = typeof params.excludeFromSim === "boolean" ? params.excludeFromSim : params.excludeFromSim.value;
4208
+ }
4209
+ if (params.at !== void 0) {
4210
+ this.at = params.at;
4211
+ }
4212
+ if (params.effects !== void 0) {
4213
+ this.effects = params.effects;
4214
+ }
4215
+ if (params.uuid !== void 0) {
4216
+ this.uuid = params.uuid;
4217
+ }
4218
+ }
4219
+ static fromSexprPrimitives(primitiveSexprs) {
4220
+ const [textPrimitive, ...rest] = primitiveSexprs;
4221
+ const value = toStringValue(textPrimitive);
4222
+ if (value === void 0) {
4223
+ throw new Error("text expects a string value");
4224
+ }
4225
+ const text = new _SchematicText();
4226
+ text._value = value;
4227
+ const { propertyMap, arrayPropertyMap } = SxClass.parsePrimitivesToClassProperties(rest, this.token);
4228
+ const unsupportedTokens = Object.keys(propertyMap).filter(
4229
+ (token) => !SUPPORTED_TOKENS7.has(token)
4230
+ );
4231
+ if (unsupportedTokens.length > 0) {
4232
+ throw new Error(
4233
+ `Unsupported child tokens inside text expression: ${unsupportedTokens.join(", ")}`
4234
+ );
4235
+ }
4236
+ for (const [token, entries] of Object.entries(arrayPropertyMap)) {
4237
+ if (!SUPPORTED_TOKENS7.has(token)) {
4238
+ throw new Error(
4239
+ `Unsupported child tokens inside text expression: ${token}`
4240
+ );
4241
+ }
4242
+ if (entries.length > 1) {
4243
+ throw new Error(`text does not support repeated child tokens: ${token}`);
4244
+ }
4245
+ }
4246
+ text._sxExcludeFromSim = arrayPropertyMap.exclude_from_sim?.[0] ?? propertyMap.exclude_from_sim;
4247
+ text._sxAt = arrayPropertyMap.at?.[0] ?? propertyMap.at;
4248
+ text._sxEffects = arrayPropertyMap.effects?.[0] ?? propertyMap.effects;
4249
+ text._sxUuid = arrayPropertyMap.uuid?.[0] ?? propertyMap.uuid;
4250
+ return text;
4251
+ }
4252
+ get value() {
4253
+ return this._value;
4254
+ }
4255
+ set value(newValue) {
4256
+ this._value = newValue;
4257
+ }
4258
+ get excludeFromSim() {
4259
+ return this._sxExcludeFromSim?.value ?? false;
4260
+ }
4261
+ set excludeFromSim(value) {
4262
+ this._sxExcludeFromSim = value ? new ExcludeFromSim(true) : void 0;
4263
+ }
4264
+ get at() {
4265
+ return this._sxAt;
4266
+ }
4267
+ set at(value) {
4268
+ this._sxAt = value !== void 0 ? At.from(value) : void 0;
4269
+ }
4270
+ get effects() {
4271
+ return this._sxEffects;
4272
+ }
4273
+ set effects(value) {
4274
+ this._sxEffects = value;
4275
+ }
4276
+ get uuid() {
4277
+ return this._sxUuid;
4278
+ }
4279
+ set uuid(value) {
4280
+ if (value === void 0) {
4281
+ this._sxUuid = void 0;
4282
+ return;
4283
+ }
4284
+ this._sxUuid = value instanceof Uuid ? value : new Uuid(value);
4285
+ }
4286
+ getChildren() {
4287
+ const children = [];
4288
+ if (this._sxExcludeFromSim) children.push(this._sxExcludeFromSim);
4289
+ if (this._sxAt) children.push(this._sxAt);
4290
+ if (this._sxEffects) children.push(this._sxEffects);
4291
+ if (this._sxUuid) children.push(this._sxUuid);
4292
+ return children;
4293
+ }
4294
+ getString() {
4295
+ const lines = [`(text ${quoteSExprString(this._value)}`];
4296
+ for (const child of this.getChildren()) {
4297
+ lines.push(child.getStringIndented());
4298
+ }
4299
+ lines.push(")");
4300
+ return lines.join("\n");
4301
+ }
4302
+ };
4303
+ SxClass.register(SchematicText);
4304
+
4141
4305
  // lib/sexpr/classes/SheetInstancesRoot.ts
4142
4306
  var SUPPORTED_ARRAY_TOKENS2 = /* @__PURE__ */ new Set(["page"]);
4143
4307
  var SheetInstancesRoot = class _SheetInstancesRoot extends SxClass {
@@ -4873,6 +5037,7 @@ var MULTI_CHILD_TOKENS = /* @__PURE__ */ new Set([
4873
5037
  "symbol",
4874
5038
  "text",
4875
5039
  "label",
5040
+ "global_label",
4876
5041
  "junction",
4877
5042
  "wire",
4878
5043
  "sheet_instances"
@@ -4899,6 +5064,7 @@ var KicadSch = class _KicadSch extends SxClass {
4899
5064
  _symbols = [];
4900
5065
  _texts = [];
4901
5066
  _labels = [];
5067
+ _globalLabels = [];
4902
5068
  _wires = [];
4903
5069
  _junctions = [];
4904
5070
  constructor(params = {}) {
@@ -4954,6 +5120,9 @@ var KicadSch = class _KicadSch extends SxClass {
4954
5120
  if (params.labels !== void 0) {
4955
5121
  this.labels = params.labels;
4956
5122
  }
5123
+ if (params.globalLabels !== void 0) {
5124
+ this.globalLabels = params.globalLabels;
5125
+ }
4957
5126
  if (params.wires !== void 0) {
4958
5127
  this.wires = params.wires;
4959
5128
  }
@@ -5010,6 +5179,7 @@ var KicadSch = class _KicadSch extends SxClass {
5010
5179
  symbols: arrayPropertyMap.symbol ?? [],
5011
5180
  texts: arrayPropertyMap.text ?? [],
5012
5181
  labels: arrayPropertyMap.label ?? [],
5182
+ globalLabels: arrayPropertyMap.global_label ?? [],
5013
5183
  junctions: arrayPropertyMap.junction ?? [],
5014
5184
  wires: arrayPropertyMap.wire ?? []
5015
5185
  });
@@ -5112,6 +5282,12 @@ var KicadSch = class _KicadSch extends SxClass {
5112
5282
  set labels(value) {
5113
5283
  this._labels = [...value];
5114
5284
  }
5285
+ get globalLabels() {
5286
+ return [...this._globalLabels];
5287
+ }
5288
+ set globalLabels(value) {
5289
+ this._globalLabels = [...value];
5290
+ }
5115
5291
  get junctions() {
5116
5292
  return [...this._junctions];
5117
5293
  }
@@ -5141,6 +5317,7 @@ var KicadSch = class _KicadSch extends SxClass {
5141
5317
  children.push(...this._symbols);
5142
5318
  children.push(...this._texts);
5143
5319
  children.push(...this._labels);
5320
+ children.push(...this._globalLabels);
5144
5321
  children.push(...this._junctions);
5145
5322
  children.push(...this._wires);
5146
5323
  return children;
@@ -6046,7 +6223,7 @@ var GrLineStart = class _GrLineStart extends SxClass {
6046
6223
  SxClass.register(GrLineStart);
6047
6224
 
6048
6225
  // lib/sexpr/classes/PadPrimitiveGrLine.ts
6049
- var SUPPORTED_TOKENS7 = /* @__PURE__ */ new Set(["start", "end", "width"]);
6226
+ var SUPPORTED_TOKENS8 = /* @__PURE__ */ new Set(["start", "end", "width"]);
6050
6227
  var PadPrimitiveGrLine = class _PadPrimitiveGrLine extends SxClass {
6051
6228
  static token = "gr_line";
6052
6229
  static parentToken = "primitives";
@@ -6058,14 +6235,14 @@ var PadPrimitiveGrLine = class _PadPrimitiveGrLine extends SxClass {
6058
6235
  const line = new _PadPrimitiveGrLine();
6059
6236
  const { propertyMap, arrayPropertyMap } = SxClass.parsePrimitivesToClassProperties(primitiveSexprs, this.token);
6060
6237
  for (const token of Object.keys(propertyMap)) {
6061
- if (!SUPPORTED_TOKENS7.has(token)) {
6238
+ if (!SUPPORTED_TOKENS8.has(token)) {
6062
6239
  throw new Error(
6063
6240
  `pad primitive gr_line encountered unsupported child token "${token}"`
6064
6241
  );
6065
6242
  }
6066
6243
  }
6067
6244
  for (const [token, entries] of Object.entries(arrayPropertyMap)) {
6068
- if (!SUPPORTED_TOKENS7.has(token)) {
6245
+ if (!SUPPORTED_TOKENS8.has(token)) {
6069
6246
  throw new Error(
6070
6247
  `pad primitive gr_line encountered unsupported child token "${token}"`
6071
6248
  );
@@ -6147,7 +6324,7 @@ var PadPrimitiveGrLine = class _PadPrimitiveGrLine extends SxClass {
6147
6324
  SxClass.register(PadPrimitiveGrLine);
6148
6325
 
6149
6326
  // lib/sexpr/classes/PadPrimitiveGrArc.ts
6150
- var SUPPORTED_TOKENS8 = /* @__PURE__ */ new Set(["start", "mid", "end", "width"]);
6327
+ var SUPPORTED_TOKENS9 = /* @__PURE__ */ new Set(["start", "mid", "end", "width"]);
6151
6328
  var PadPrimitiveGrArc = class _PadPrimitiveGrArc extends SxClass {
6152
6329
  static token = "gr_arc";
6153
6330
  static parentToken = "primitives";
@@ -6167,14 +6344,14 @@ var PadPrimitiveGrArc = class _PadPrimitiveGrArc extends SxClass {
6167
6344
  const arc = new _PadPrimitiveGrArc();
6168
6345
  const { propertyMap, arrayPropertyMap } = SxClass.parsePrimitivesToClassProperties(primitiveSexprs, this.token);
6169
6346
  for (const token of Object.keys(propertyMap)) {
6170
- if (!SUPPORTED_TOKENS8.has(token)) {
6347
+ if (!SUPPORTED_TOKENS9.has(token)) {
6171
6348
  throw new Error(
6172
6349
  `pad primitive gr_arc encountered unsupported child token "${token}"`
6173
6350
  );
6174
6351
  }
6175
6352
  }
6176
6353
  for (const [token, entries] of Object.entries(arrayPropertyMap)) {
6177
- if (!SUPPORTED_TOKENS8.has(token)) {
6354
+ if (!SUPPORTED_TOKENS9.has(token)) {
6178
6355
  throw new Error(
6179
6356
  `pad primitive gr_arc encountered unsupported child token "${token}"`
6180
6357
  );
@@ -6344,7 +6521,7 @@ var PadPrimitiveGrArcEnd = class _PadPrimitiveGrArcEnd extends PadPrimitiveGrArc
6344
6521
  SxClass.register(PadPrimitiveGrArcEnd);
6345
6522
 
6346
6523
  // lib/sexpr/classes/PadPrimitiveGrCircle.ts
6347
- var SUPPORTED_TOKENS9 = /* @__PURE__ */ new Set(["center", "end", "width", "fill"]);
6524
+ var SUPPORTED_TOKENS10 = /* @__PURE__ */ new Set(["center", "end", "width", "fill"]);
6348
6525
  var PadPrimitiveGrCircle = class _PadPrimitiveGrCircle extends SxClass {
6349
6526
  static token = "gr_circle";
6350
6527
  static parentToken = "primitives";
@@ -6364,14 +6541,14 @@ var PadPrimitiveGrCircle = class _PadPrimitiveGrCircle extends SxClass {
6364
6541
  const circle = new _PadPrimitiveGrCircle();
6365
6542
  const { propertyMap, arrayPropertyMap } = SxClass.parsePrimitivesToClassProperties(primitiveSexprs, this.token);
6366
6543
  for (const token of Object.keys(propertyMap)) {
6367
- if (!SUPPORTED_TOKENS9.has(token)) {
6544
+ if (!SUPPORTED_TOKENS10.has(token)) {
6368
6545
  throw new Error(
6369
6546
  `pad primitive gr_circle encountered unsupported child token "${token}"`
6370
6547
  );
6371
6548
  }
6372
6549
  }
6373
6550
  for (const [token, entries] of Object.entries(arrayPropertyMap)) {
6374
- if (!SUPPORTED_TOKENS9.has(token)) {
6551
+ if (!SUPPORTED_TOKENS10.has(token)) {
6375
6552
  throw new Error(
6376
6553
  `pad primitive gr_circle encountered unsupported child token "${token}"`
6377
6554
  );
@@ -7139,7 +7316,7 @@ var SINGLE_TOKENS = /* @__PURE__ */ new Set([
7139
7316
  "teardrops"
7140
7317
  ]);
7141
7318
  var MULTI_TOKENS = /* @__PURE__ */ new Set(["property"]);
7142
- var SUPPORTED_TOKENS10 = /* @__PURE__ */ new Set([...SINGLE_TOKENS, ...MULTI_TOKENS]);
7319
+ var SUPPORTED_TOKENS11 = /* @__PURE__ */ new Set([...SINGLE_TOKENS, ...MULTI_TOKENS]);
7143
7320
  var ensureSingle = (arrayPropertyMap, token) => {
7144
7321
  const entries = arrayPropertyMap[token];
7145
7322
  if (entries && entries.length > 1) {
@@ -7278,12 +7455,12 @@ var FootprintPad = class _FootprintPad extends SxClass {
7278
7455
  }
7279
7456
  const { propertyMap, arrayPropertyMap } = SxClass.parsePrimitivesToClassProperties(primitiveNodes, this.token);
7280
7457
  for (const token of Object.keys(propertyMap)) {
7281
- if (!SUPPORTED_TOKENS10.has(token)) {
7458
+ if (!SUPPORTED_TOKENS11.has(token)) {
7282
7459
  throw new Error(`pad encountered unsupported child token "${token}"`);
7283
7460
  }
7284
7461
  }
7285
7462
  for (const [token, entries] of Object.entries(arrayPropertyMap)) {
7286
- if (!SUPPORTED_TOKENS10.has(token)) {
7463
+ if (!SUPPORTED_TOKENS11.has(token)) {
7287
7464
  throw new Error(`pad encountered unsupported child token "${token}"`);
7288
7465
  }
7289
7466
  if (!MULTI_TOKENS.has(token) && entries.length > 1) {
@@ -9149,7 +9326,7 @@ var FpPolyLocked = class _FpPolyLocked extends SxPrimitiveBoolean {
9149
9326
  SxClass.register(FpPolyLocked);
9150
9327
 
9151
9328
  // lib/sexpr/classes/FpPoly.ts
9152
- var SUPPORTED_TOKENS11 = /* @__PURE__ */ new Set([
9329
+ var SUPPORTED_TOKENS12 = /* @__PURE__ */ new Set([
9153
9330
  "pts",
9154
9331
  "xy",
9155
9332
  "layer",
@@ -9184,12 +9361,12 @@ var FpPoly = class _FpPoly extends SxClass {
9184
9361
  const { propertyMap, arrayPropertyMap } = SxClass.parsePrimitivesToClassProperties(primitiveSexprs, this.token);
9185
9362
  const unexpectedTokens = /* @__PURE__ */ new Set();
9186
9363
  for (const token of Object.keys(propertyMap)) {
9187
- if (!SUPPORTED_TOKENS11.has(token)) {
9364
+ if (!SUPPORTED_TOKENS12.has(token)) {
9188
9365
  unexpectedTokens.add(token);
9189
9366
  }
9190
9367
  }
9191
9368
  for (const token of Object.keys(arrayPropertyMap)) {
9192
- if (!SUPPORTED_TOKENS11.has(token)) {
9369
+ if (!SUPPORTED_TOKENS12.has(token)) {
9193
9370
  unexpectedTokens.add(token);
9194
9371
  }
9195
9372
  if (token !== "xy" && arrayPropertyMap[token].length > 1) {
@@ -9242,7 +9419,7 @@ var FpPoly = class _FpPoly extends SxClass {
9242
9419
  `fp_poly child token must be a string, received: ${JSON.stringify(token)}`
9243
9420
  );
9244
9421
  }
9245
- if (!SUPPORTED_TOKENS11.has(token)) {
9422
+ if (!SUPPORTED_TOKENS12.has(token)) {
9246
9423
  throw new Error(
9247
9424
  `Unsupported child token inside fp_poly expression: ${token}`
9248
9425
  );
@@ -9867,7 +10044,7 @@ var MULTI_TOKENS2 = /* @__PURE__ */ new Set([
9867
10044
  "pad",
9868
10045
  "model"
9869
10046
  ]);
9870
- var SUPPORTED_TOKENS12 = /* @__PURE__ */ new Set([...SINGLE_TOKENS2, ...MULTI_TOKENS2]);
10047
+ var SUPPORTED_TOKENS13 = /* @__PURE__ */ new Set([...SINGLE_TOKENS2, ...MULTI_TOKENS2]);
9871
10048
  var Footprint = class _Footprint extends SxClass {
9872
10049
  static token = "footprint";
9873
10050
  token = "footprint";
@@ -9977,14 +10154,14 @@ var Footprint = class _Footprint extends SxClass {
9977
10154
  }
9978
10155
  const { propertyMap, arrayPropertyMap } = SxClass.parsePrimitivesToClassProperties(rawNodes, this.token);
9979
10156
  for (const token of Object.keys(propertyMap)) {
9980
- if (!SUPPORTED_TOKENS12.has(token)) {
10157
+ if (!SUPPORTED_TOKENS13.has(token)) {
9981
10158
  throw new Error(
9982
10159
  `footprint encountered unsupported child token "${token}"`
9983
10160
  );
9984
10161
  }
9985
10162
  }
9986
10163
  for (const [token, entries] of Object.entries(arrayPropertyMap)) {
9987
- if (!SUPPORTED_TOKENS12.has(token)) {
10164
+ if (!SUPPORTED_TOKENS13.has(token)) {
9988
10165
  throw new Error(
9989
10166
  `footprint encountered unsupported child token "${token}"`
9990
10167
  );
@@ -14016,6 +14193,33 @@ SxClass.register(KicadPcb);
14016
14193
  var parseKicadSexpr = (sexpr) => {
14017
14194
  return SxClass.parse(sexpr);
14018
14195
  };
14196
+ var parseKicadSch = (sexpr) => {
14197
+ const [root] = parseKicadSexpr(sexpr);
14198
+ if (!(root instanceof KicadSch)) {
14199
+ throw new Error(
14200
+ `Expected KicadSch root, got ${root?.constructor.name ?? "undefined"}`
14201
+ );
14202
+ }
14203
+ return root;
14204
+ };
14205
+ var parseKicadPcb = (sexpr) => {
14206
+ const [root] = parseKicadSexpr(sexpr);
14207
+ if (!(root instanceof KicadPcb)) {
14208
+ throw new Error(
14209
+ `Expected KicadPcb root, got ${root?.constructor.name ?? "undefined"}`
14210
+ );
14211
+ }
14212
+ return root;
14213
+ };
14214
+ var parseKicadMod = (sexpr) => {
14215
+ const [root] = parseKicadSexpr(sexpr);
14216
+ if (!(root instanceof Footprint)) {
14217
+ throw new Error(
14218
+ `Expected Footprint root, got ${root?.constructor.name ?? "undefined"}`
14219
+ );
14220
+ }
14221
+ return root;
14222
+ };
14019
14223
  export {
14020
14224
  At,
14021
14225
  Bus,
@@ -14072,6 +14276,7 @@ export {
14072
14276
  FpTextBoxAngle,
14073
14277
  FpTextBoxEnd,
14074
14278
  FpTextBoxStart,
14279
+ GlobalLabel,
14075
14280
  GrLine,
14076
14281
  GrLineAngle,
14077
14282
  GrLineEnd,
@@ -14316,5 +14521,8 @@ export {
14316
14521
  Wire,
14317
14522
  Xy,
14318
14523
  Zone,
14524
+ parseKicadMod,
14525
+ parseKicadPcb,
14526
+ parseKicadSch,
14319
14527
  parseKicadSexpr
14320
14528
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "kicadts",
3
3
  "main": "dist/index.js",
4
- "version": "0.0.9",
4
+ "version": "0.0.11",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",