@tscircuit/internal-dynamic-import 0.0.19 → 0.0.21

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 tscircuit Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import { JscadOperation } from 'jscad-planner';
2
2
  import * as circuit_json_to_gltf from 'circuit-json-to-gltf';
3
- import { AnyCircuitElement, SourceComponentBase, PcbComponent, CircuitJson, SchematicNetLabel, PCBTrace, PCBPort, LayerRef as LayerRef$1, Ring, NinePointAnchor, PcbRenderLayer, PcbBoard, PcbCopperPour, PcbCopperText, PcbCourtyardCircle, PcbCutout, PcbFabricationNoteDimension, PcbFabricationNotePath, PcbFabricationNoteRect, PcbFabricationNoteText, PcbHole, PCBKeepout, PcbNoteDimension, PcbNotePath, PcbNoteRect, PcbNoteText, PcbPanel, PcbPlatedHole, PcbSilkscreenCircle, PcbSilkscreenGraphic, PcbSilkscreenLine, PcbSilkscreenOval, PcbSilkscreenPath, PcbSilkscreenPill, PcbSilkscreenRect, PcbSilkscreenText, PcbSmtPad, PcbVia, PcbSolderPaste, PcbTrace, PCBVia, SimulationExperiment, SimulationTransientVoltageGraph, SimulationVoltageProbe, PcbPort, SchematicComponent } from 'circuit-json';
3
+ import { AnyCircuitElement, SourceComponentBase, PcbComponent, CircuitJson, SchematicNetLabel, PCBTrace, PCBPort, LayerRef as LayerRef$1, Point as Point$1, Ring, NinePointAnchor, PcbRenderLayer, PcbBoard, PcbCopperPour, PcbCopperText, PcbCourtyardCircle, PcbCutout, PcbFabricationNoteDimension, PcbFabricationNotePath, PcbFabricationNoteRect, PcbFabricationNoteText, PcbHole, PCBKeepout, PcbNoteDimension, PcbNotePath, PcbNoteRect, PcbNoteText, PcbPanel, PcbPlatedHole, PcbSilkscreenCircle, PcbSilkscreenGraphic, PcbSilkscreenLine, PcbSilkscreenOval, PcbSilkscreenPath, PcbSilkscreenPill, PcbSilkscreenRect, PcbSilkscreenText, PcbSmtPad, PcbVia, PcbSolderPaste, PcbTrace, PCBVia, SimulationExperiment, SimulationTransientVoltageGraph, SimulationVoltageProbe, PcbPort, SchematicComponent } from 'circuit-json';
4
4
  import { BpcGraph } from 'bpc-graph';
5
5
  import { RenderOptionsInput } from 'poppygl';
6
6
  import { z, AnyZodObject } from 'zod';
7
- import { CircuitJsonUtilObjects, cju } from '@tscircuit/circuit-json-util';
8
7
  import { KicadSch, KicadPcb, SchematicSymbol, KicadSym } from 'kicadts';
8
+ import { CircuitJsonUtilObjects, cju } from '@tscircuit/circuit-json-util';
9
9
  import { Matrix } from 'transformation-matrix';
10
10
  import { LightBurnProject } from 'lbrnts';
11
11
  import { Box } from '@tscircuit/simple-3d-svg';
@@ -1447,9 +1447,18 @@ declare namespace CircuitJsonToGltfModule {
1447
1447
 
1448
1448
  type PaperSize = "A0" | "A1" | "A2" | "A3" | "A4" | "A5";
1449
1449
  interface PaperDimensions {
1450
+ /** Effective page width after orientation, in millimeters. */
1450
1451
  width: number;
1452
+ /** Effective page height after orientation, in millimeters. */
1451
1453
  height: number;
1452
- name: PaperSize;
1454
+ name: PaperSize | string;
1455
+ /** Raw custom dimensions written to KiCad's `(paper width height)` form. */
1456
+ customSize?: {
1457
+ width: number;
1458
+ height: number;
1459
+ };
1460
+ /** Whether KiCad writes the page with its `portrait` flag. */
1461
+ isPortrait?: boolean;
1453
1462
  }
1454
1463
 
1455
1464
  type SchematicPortId = string;
@@ -1499,6 +1508,25 @@ interface ConverterContext$1 {
1499
1508
  c2kMatPcb?: Matrix;
1500
1509
  /** Selected paper size for schematic */
1501
1510
  schematicPaperSize?: PaperDimensions;
1511
+ /**
1512
+ * UUID written as this file's own top-level `(uuid ...)`. When set,
1513
+ * InitializeSchematicStage uses it instead of generating a random one so the
1514
+ * root uuid can be shared across the root file, child files, sheet nodes and
1515
+ * the `.kicad_pro`.
1516
+ */
1517
+ schematicFileUuid?: string;
1518
+ /**
1519
+ * Prefix used for every symbol `(instances ... (path ...))` in this file.
1520
+ * Root/legacy files use `/<rootUuid>`; child sheet files use
1521
+ * `/<rootUuid>/<sheetNodeUuid>` (KiCad requires the root uuid first).
1522
+ */
1523
+ symbolInstancePathPrefix?: string;
1524
+ /**
1525
+ * Lib id for each schematic component whose pin numbering differs from an
1526
+ * earlier instance of the same library symbol, keyed by
1527
+ * schematic_component_id. Set by AddLibrarySymbolsStage.
1528
+ */
1529
+ schematicComponentLibraryIds?: Map<string, string>;
1502
1530
  pinPositions?: Map<SchematicPortId, {
1503
1531
  x: number;
1504
1532
  y: number;
@@ -1510,6 +1538,7 @@ interface ConverterContext$1 {
1510
1538
  }>;
1511
1539
  pcbNetMap?: Map<string, PcbNetInfo>;
1512
1540
  numLayers?: number;
1541
+ edgeCutsWidth?: number;
1513
1542
  /** Project name used as the .3dshapes folder for user-provided 3D models */
1514
1543
  projectName?: string;
1515
1544
  /** CDN URLs of 3D models needed for this PCB (collected during footprint stage) */
@@ -1535,20 +1564,125 @@ declare abstract class ConverterStage$1<Input, Output> {
1535
1564
  getOutput(): Output;
1536
1565
  }
1537
1566
 
1567
+ /** Fields common to the root page and every child schematic file. */
1568
+ interface SchematicSheetPlanEntryBase {
1569
+ /** Value written to the KiCad `(property "Sheetname" ...)` */
1570
+ sheetName: string;
1571
+ /** Sanitized, unique file stem (no extension) used to derive `filename` */
1572
+ fileBaseName: string;
1573
+ /** File name for this sheet's `.kicad_sch` (root filename is overridden by the caller) */
1574
+ filename: string;
1575
+ /** KiCad page number ("1" for root, "2".. for children) */
1576
+ pageNumber: string;
1577
+ /** UUID written as this file's own top-level `(uuid ...)` */
1578
+ fileUuid: string;
1579
+ }
1580
+ /** The top-level root schematic (page "1"); it holds the `(sheet)` nodes. */
1581
+ interface RootSchematicSheetPlanEntry extends SchematicSheetPlanEntryBase {
1582
+ schematicSheetId: null;
1583
+ }
1584
+ /**
1585
+ * One circuit-json `schematic_sheet`, emitted as a `(sheet)` node on the root
1586
+ * page plus its own child `.kicad_sch` file.
1587
+ */
1588
+ interface ChildSchematicSheetPlanEntry extends SchematicSheetPlanEntryBase {
1589
+ /** circuit-json schematic_sheet_id this file represents */
1590
+ schematicSheetId: string;
1591
+ /**
1592
+ * UUID of the `(sheet)` node placed on the root page. It is the second segment
1593
+ * of the symbol instance path for symbols on this sheet (`/<rootUuid>/<sheetNodeUuid>`).
1594
+ */
1595
+ sheetNodeUuid: string;
1596
+ }
1597
+ /**
1598
+ * Blueprint of the KiCad schematic files to emit for one circuit-json input:
1599
+ * the root `.kicad_sch` plus one child `.kicad_sch` per `schematic_sheet`, each
1600
+ * with the UUIDs, filename, and page number KiCad needs. Computed up front (with
1601
+ * no file content) so the schematic converter and the `.kicad_pro` converter
1602
+ * agree on the same identifiers.
1603
+ */
1604
+ interface SchematicSheetPlan {
1605
+ /**
1606
+ * UUID of the root schematic file. Every symbol instance path begins with
1607
+ * this uuid (KiCad requirement), so it is shared by the root file, the child
1608
+ * files, the `(sheet)` nodes, and the `.kicad_pro` sheets list.
1609
+ */
1610
+ rootUuid: string;
1611
+ root: RootSchematicSheetPlanEntry;
1612
+ children: ChildSchematicSheetPlanEntry[];
1613
+ /** True when the design has `schematic_sheet`s and must be emitted as a hierarchy */
1614
+ isHierarchical: boolean;
1615
+ }
1616
+
1617
+ interface KicadSchematicTitleBlockMetadata {
1618
+ company?: string;
1619
+ comments?: Array<{
1620
+ index: number;
1621
+ text: string;
1622
+ }>;
1623
+ date?: string;
1624
+ revision?: string;
1625
+ title?: string;
1626
+ }
1627
+
1628
+ interface KicadSchFile {
1629
+ filename: string;
1630
+ content: string;
1631
+ }
1632
+ interface KicadSchFileOutputOptions {
1633
+ schematicFilename: string;
1634
+ }
1635
+ interface CircuitJsonToKicadSchConverterOptions {
1636
+ paperSize?: PaperDimensions;
1637
+ schematicSheets?: KicadSchematicSheetOptions[];
1638
+ titleBlock?: KicadSchematicTitleBlockMetadata;
1639
+ }
1640
+ interface KicadSchematicSheetOptions {
1641
+ /** Position of Circuit JSON (0, 0) on the KiCad page, in millimeters. */
1642
+ circuitOrigin: Point$1;
1643
+ /** Geometry of this child sheet's hierarchy node on the root page. */
1644
+ hierarchyNode?: {
1645
+ position: Point$1;
1646
+ size: {
1647
+ height: number;
1648
+ width: number;
1649
+ };
1650
+ };
1651
+ /** Omit for a standalone schematic or the root sheet. */
1652
+ schematicSheetId?: string;
1653
+ }
1538
1654
  declare class CircuitJsonToKicadSchConverter {
1539
1655
  ctx: ConverterContext$1;
1540
1656
  pipeline: ConverterStage$1<CircuitJson, KicadSch>[];
1541
1657
  currentStageIndex: number;
1542
1658
  finished: boolean;
1659
+ circuitJson: CircuitJson;
1660
+ schematicSheetPlan: SchematicSheetPlan;
1661
+ private files;
1662
+ private built;
1663
+ private readonly options;
1543
1664
  get currentStage(): ConverterStage$1<CircuitJson, KicadSch> | undefined;
1544
- constructor(circuitJson: CircuitJson);
1665
+ constructor(circuitJson: CircuitJson, options?: CircuitJsonToKicadSchConverterOptions);
1545
1666
  step(): void;
1546
1667
  runUntilFinished(): void;
1547
1668
  getOutput(): KicadSch;
1548
1669
  /**
1549
- * Get the output as a string
1670
+ * Get the (root) schematic as a string.
1550
1671
  */
1551
1672
  getOutputString(): string;
1673
+ /**
1674
+ * Returns every KiCad schematic file produced by this converter.
1675
+ *
1676
+ * For a design with no `schematic_sheet` elements this is a single root file.
1677
+ * For a hierarchical design it is the root file (named by
1678
+ * `options.schematicFilename`) followed by one child `.kicad_sch` per sheet,
1679
+ * each named after its sheet and referenced by the root via `Sheetfile`.
1680
+ */
1681
+ getOutputFiles(options: KicadSchFileOutputOptions): KicadSchFile[];
1682
+ /** Builds the root + child `.kicad_sch` files for a hierarchical design. */
1683
+ private buildAll;
1684
+ /** Builds one child/root `.kicad_sch` for a sheet, run to completion. */
1685
+ private buildSheetFile;
1552
1686
  }
1553
1687
 
1554
1688
  interface CircuitJsonToKicadPcbOptions {
@@ -1563,6 +1697,11 @@ interface CircuitJsonToKicadPcbOptions {
1563
1697
  * e.g. "index" → "3dmodels/index.3dshapes/{filename}"
1564
1698
  */
1565
1699
  projectName?: string;
1700
+ /**
1701
+ * Stroke width in millimetres for generated Edge.Cuts graphics.
1702
+ * Defaults to 0.1 mm when the source format does not provide one.
1703
+ */
1704
+ edgeCutsWidth?: number;
1566
1705
  }
1567
1706
  declare class CircuitJsonToKicadPcbConverter {
1568
1707
  ctx: ConverterContext$1;
@@ -1589,6 +1728,12 @@ interface CircuitJsonToKicadProOptions {
1589
1728
  projectName?: string;
1590
1729
  schematicFilename?: string;
1591
1730
  pcbFilename?: string;
1731
+ /**
1732
+ * Sheet plan produced by CircuitJsonToKicadSchConverter. When provided, the
1733
+ * project's `sheets` list uses the same root/sheet-node UUIDs so the
1734
+ * `.kicad_pro` stays consistent with the generated `.kicad_sch` hierarchy.
1735
+ */
1736
+ schematicSheetPlan?: SchematicSheetPlan;
1592
1737
  }
1593
1738
  interface KicadProNetClass {
1594
1739
  bus_width?: number;
@@ -1703,6 +1848,24 @@ declare class CircuitJsonToKicadProConverter {
1703
1848
  getOutputString(): string;
1704
1849
  }
1705
1850
 
1851
+ interface CircuitJsonToKicadModOptions {
1852
+ libraryName?: string;
1853
+ footprintLibraryName?: string;
1854
+ footprintName?: string;
1855
+ }
1856
+ declare class CircuitJsonToKicadModConverter {
1857
+ private readonly libraryConverter;
1858
+ private readonly footprintName?;
1859
+ constructor(circuitJson: CircuitJson, options?: CircuitJsonToKicadModOptions);
1860
+ get finished(): boolean;
1861
+ get currentStage(): ConverterStage$1<CircuitJson, KicadLibraryOutput> | undefined;
1862
+ step(): void;
1863
+ runUntilFinished(): void;
1864
+ getOutput(): FootprintEntry;
1865
+ getOutputString(): string;
1866
+ getModel3dSourcePaths(): string[];
1867
+ }
1868
+
1706
1869
  type ModelFetchResponse = {
1707
1870
  ok: boolean;
1708
1871
  arrayBuffer: () => Promise<ArrayBuffer>;
@@ -1833,12 +1996,16 @@ declare class KicadLibraryConverter {
1833
1996
 
1834
1997
  type CircuitJsonToKicadModule_CircuitJsonToKicadLibraryConverter = CircuitJsonToKicadLibraryConverter;
1835
1998
  declare const CircuitJsonToKicadModule_CircuitJsonToKicadLibraryConverter: typeof CircuitJsonToKicadLibraryConverter;
1999
+ type CircuitJsonToKicadModule_CircuitJsonToKicadModConverter = CircuitJsonToKicadModConverter;
2000
+ declare const CircuitJsonToKicadModule_CircuitJsonToKicadModConverter: typeof CircuitJsonToKicadModConverter;
1836
2001
  type CircuitJsonToKicadModule_CircuitJsonToKicadPcbConverter = CircuitJsonToKicadPcbConverter;
1837
2002
  declare const CircuitJsonToKicadModule_CircuitJsonToKicadPcbConverter: typeof CircuitJsonToKicadPcbConverter;
2003
+ type CircuitJsonToKicadModule_CircuitJsonToKicadPcbOptions = CircuitJsonToKicadPcbOptions;
1838
2004
  type CircuitJsonToKicadModule_CircuitJsonToKicadProConverter = CircuitJsonToKicadProConverter;
1839
2005
  declare const CircuitJsonToKicadModule_CircuitJsonToKicadProConverter: typeof CircuitJsonToKicadProConverter;
1840
2006
  type CircuitJsonToKicadModule_CircuitJsonToKicadSchConverter = CircuitJsonToKicadSchConverter;
1841
2007
  declare const CircuitJsonToKicadModule_CircuitJsonToKicadSchConverter: typeof CircuitJsonToKicadSchConverter;
2008
+ type CircuitJsonToKicadModule_CircuitJsonToKicadSchConverterOptions = CircuitJsonToKicadSchConverterOptions;
1842
2009
  type CircuitJsonToKicadModule_FootprintEntry = FootprintEntry;
1843
2010
  type CircuitJsonToKicadModule_Kicad3dModelLoadError = Kicad3dModelLoadError;
1844
2011
  type CircuitJsonToKicadModule_KicadLibraryConverter = KicadLibraryConverter;
@@ -1846,12 +2013,15 @@ declare const CircuitJsonToKicadModule_KicadLibraryConverter: typeof KicadLibrar
1846
2013
  type CircuitJsonToKicadModule_KicadLibraryConverterOptions = KicadLibraryConverterOptions;
1847
2014
  type CircuitJsonToKicadModule_KicadLibraryConverterOutput = KicadLibraryConverterOutput;
1848
2015
  type CircuitJsonToKicadModule_KicadLibraryOutput = KicadLibraryOutput;
2016
+ type CircuitJsonToKicadModule_KicadSchFile = KicadSchFile;
2017
+ type CircuitJsonToKicadModule_KicadSchFileOutputOptions = KicadSchFileOutputOptions;
2018
+ type CircuitJsonToKicadModule_KicadSchematicSheetOptions = KicadSchematicSheetOptions;
1849
2019
  type CircuitJsonToKicadModule_LoadedKicad3dModelFile = LoadedKicad3dModelFile;
1850
2020
  type CircuitJsonToKicadModule_ResolveAndLoadKicad3dModelFilesOptions = ResolveAndLoadKicad3dModelFilesOptions;
1851
2021
  type CircuitJsonToKicadModule_SymbolEntry = SymbolEntry;
1852
2022
  declare const CircuitJsonToKicadModule_resolveAndLoadKicad3dModelFiles: typeof resolveAndLoadKicad3dModelFiles;
1853
2023
  declare namespace CircuitJsonToKicadModule {
1854
- export { CircuitJsonToKicadModule_CircuitJsonToKicadLibraryConverter as CircuitJsonToKicadLibraryConverter, CircuitJsonToKicadModule_CircuitJsonToKicadPcbConverter as CircuitJsonToKicadPcbConverter, CircuitJsonToKicadModule_CircuitJsonToKicadProConverter as CircuitJsonToKicadProConverter, CircuitJsonToKicadModule_CircuitJsonToKicadSchConverter as CircuitJsonToKicadSchConverter, type CircuitJsonToKicadModule_FootprintEntry as FootprintEntry, type CircuitJsonToKicadModule_Kicad3dModelLoadError as Kicad3dModelLoadError, CircuitJsonToKicadModule_KicadLibraryConverter as KicadLibraryConverter, type CircuitJsonToKicadModule_KicadLibraryConverterOptions as KicadLibraryConverterOptions, type CircuitJsonToKicadModule_KicadLibraryConverterOutput as KicadLibraryConverterOutput, type CircuitJsonToKicadModule_KicadLibraryOutput as KicadLibraryOutput, type CircuitJsonToKicadModule_LoadedKicad3dModelFile as LoadedKicad3dModelFile, type CircuitJsonToKicadModule_ResolveAndLoadKicad3dModelFilesOptions as ResolveAndLoadKicad3dModelFilesOptions, type CircuitJsonToKicadModule_SymbolEntry as SymbolEntry, CircuitJsonToKicadModule_resolveAndLoadKicad3dModelFiles as resolveAndLoadKicad3dModelFiles };
2024
+ export { CircuitJsonToKicadModule_CircuitJsonToKicadLibraryConverter as CircuitJsonToKicadLibraryConverter, CircuitJsonToKicadModule_CircuitJsonToKicadModConverter as CircuitJsonToKicadModConverter, CircuitJsonToKicadModule_CircuitJsonToKicadPcbConverter as CircuitJsonToKicadPcbConverter, type CircuitJsonToKicadModule_CircuitJsonToKicadPcbOptions as CircuitJsonToKicadPcbOptions, CircuitJsonToKicadModule_CircuitJsonToKicadProConverter as CircuitJsonToKicadProConverter, CircuitJsonToKicadModule_CircuitJsonToKicadSchConverter as CircuitJsonToKicadSchConverter, type CircuitJsonToKicadModule_CircuitJsonToKicadSchConverterOptions as CircuitJsonToKicadSchConverterOptions, type CircuitJsonToKicadModule_FootprintEntry as FootprintEntry, type CircuitJsonToKicadModule_Kicad3dModelLoadError as Kicad3dModelLoadError, CircuitJsonToKicadModule_KicadLibraryConverter as KicadLibraryConverter, type CircuitJsonToKicadModule_KicadLibraryConverterOptions as KicadLibraryConverterOptions, type CircuitJsonToKicadModule_KicadLibraryConverterOutput as KicadLibraryConverterOutput, type CircuitJsonToKicadModule_KicadLibraryOutput as KicadLibraryOutput, type CircuitJsonToKicadModule_KicadSchFile as KicadSchFile, type CircuitJsonToKicadModule_KicadSchFileOutputOptions as KicadSchFileOutputOptions, type CircuitJsonToKicadModule_KicadSchematicSheetOptions as KicadSchematicSheetOptions, type CircuitJsonToKicadModule_LoadedKicad3dModelFile as LoadedKicad3dModelFile, type CircuitJsonToKicadModule_ResolveAndLoadKicad3dModelFilesOptions as ResolveAndLoadKicad3dModelFilesOptions, type CircuitJsonToKicadModule_SymbolEntry as SymbolEntry, CircuitJsonToKicadModule_resolveAndLoadKicad3dModelFiles as resolveAndLoadKicad3dModelFiles };
1855
2025
  }
1856
2026
 
1857
2027
  interface ConvertCircuitJsonToLbrnOptions {
@@ -1,13 +1,22 @@
1
- import { CircuitJson } from 'circuit-json';
2
- import { CircuitJsonUtilObjects, cju } from '@tscircuit/circuit-json-util';
1
+ import { CircuitJson, Point } from 'circuit-json';
3
2
  import { KicadSch, KicadPcb, SchematicSymbol } from 'kicadts';
3
+ import { CircuitJsonUtilObjects, cju } from '@tscircuit/circuit-json-util';
4
4
  import { Matrix } from 'transformation-matrix';
5
5
 
6
6
  type PaperSize = "A0" | "A1" | "A2" | "A3" | "A4" | "A5";
7
7
  interface PaperDimensions {
8
+ /** Effective page width after orientation, in millimeters. */
8
9
  width: number;
10
+ /** Effective page height after orientation, in millimeters. */
9
11
  height: number;
10
- name: PaperSize;
12
+ name: PaperSize | string;
13
+ /** Raw custom dimensions written to KiCad's `(paper width height)` form. */
14
+ customSize?: {
15
+ width: number;
16
+ height: number;
17
+ };
18
+ /** Whether KiCad writes the page with its `portrait` flag. */
19
+ isPortrait?: boolean;
11
20
  }
12
21
 
13
22
  type SchematicPortId = string;
@@ -57,6 +66,25 @@ interface ConverterContext {
57
66
  c2kMatPcb?: Matrix;
58
67
  /** Selected paper size for schematic */
59
68
  schematicPaperSize?: PaperDimensions;
69
+ /**
70
+ * UUID written as this file's own top-level `(uuid ...)`. When set,
71
+ * InitializeSchematicStage uses it instead of generating a random one so the
72
+ * root uuid can be shared across the root file, child files, sheet nodes and
73
+ * the `.kicad_pro`.
74
+ */
75
+ schematicFileUuid?: string;
76
+ /**
77
+ * Prefix used for every symbol `(instances ... (path ...))` in this file.
78
+ * Root/legacy files use `/<rootUuid>`; child sheet files use
79
+ * `/<rootUuid>/<sheetNodeUuid>` (KiCad requires the root uuid first).
80
+ */
81
+ symbolInstancePathPrefix?: string;
82
+ /**
83
+ * Lib id for each schematic component whose pin numbering differs from an
84
+ * earlier instance of the same library symbol, keyed by
85
+ * schematic_component_id. Set by AddLibrarySymbolsStage.
86
+ */
87
+ schematicComponentLibraryIds?: Map<string, string>;
60
88
  pinPositions?: Map<SchematicPortId, {
61
89
  x: number;
62
90
  y: number;
@@ -68,6 +96,7 @@ interface ConverterContext {
68
96
  }>;
69
97
  pcbNetMap?: Map<string, PcbNetInfo>;
70
98
  numLayers?: number;
99
+ edgeCutsWidth?: number;
71
100
  /** Project name used as the .3dshapes folder for user-provided 3D models */
72
101
  projectName?: string;
73
102
  /** CDN URLs of 3D models needed for this PCB (collected during footprint stage) */
@@ -93,20 +122,125 @@ declare abstract class ConverterStage<Input, Output> {
93
122
  getOutput(): Output;
94
123
  }
95
124
 
125
+ /** Fields common to the root page and every child schematic file. */
126
+ interface SchematicSheetPlanEntryBase {
127
+ /** Value written to the KiCad `(property "Sheetname" ...)` */
128
+ sheetName: string;
129
+ /** Sanitized, unique file stem (no extension) used to derive `filename` */
130
+ fileBaseName: string;
131
+ /** File name for this sheet's `.kicad_sch` (root filename is overridden by the caller) */
132
+ filename: string;
133
+ /** KiCad page number ("1" for root, "2".. for children) */
134
+ pageNumber: string;
135
+ /** UUID written as this file's own top-level `(uuid ...)` */
136
+ fileUuid: string;
137
+ }
138
+ /** The top-level root schematic (page "1"); it holds the `(sheet)` nodes. */
139
+ interface RootSchematicSheetPlanEntry extends SchematicSheetPlanEntryBase {
140
+ schematicSheetId: null;
141
+ }
142
+ /**
143
+ * One circuit-json `schematic_sheet`, emitted as a `(sheet)` node on the root
144
+ * page plus its own child `.kicad_sch` file.
145
+ */
146
+ interface ChildSchematicSheetPlanEntry extends SchematicSheetPlanEntryBase {
147
+ /** circuit-json schematic_sheet_id this file represents */
148
+ schematicSheetId: string;
149
+ /**
150
+ * UUID of the `(sheet)` node placed on the root page. It is the second segment
151
+ * of the symbol instance path for symbols on this sheet (`/<rootUuid>/<sheetNodeUuid>`).
152
+ */
153
+ sheetNodeUuid: string;
154
+ }
155
+ /**
156
+ * Blueprint of the KiCad schematic files to emit for one circuit-json input:
157
+ * the root `.kicad_sch` plus one child `.kicad_sch` per `schematic_sheet`, each
158
+ * with the UUIDs, filename, and page number KiCad needs. Computed up front (with
159
+ * no file content) so the schematic converter and the `.kicad_pro` converter
160
+ * agree on the same identifiers.
161
+ */
162
+ interface SchematicSheetPlan {
163
+ /**
164
+ * UUID of the root schematic file. Every symbol instance path begins with
165
+ * this uuid (KiCad requirement), so it is shared by the root file, the child
166
+ * files, the `(sheet)` nodes, and the `.kicad_pro` sheets list.
167
+ */
168
+ rootUuid: string;
169
+ root: RootSchematicSheetPlanEntry;
170
+ children: ChildSchematicSheetPlanEntry[];
171
+ /** True when the design has `schematic_sheet`s and must be emitted as a hierarchy */
172
+ isHierarchical: boolean;
173
+ }
174
+
175
+ interface KicadSchematicTitleBlockMetadata {
176
+ company?: string;
177
+ comments?: Array<{
178
+ index: number;
179
+ text: string;
180
+ }>;
181
+ date?: string;
182
+ revision?: string;
183
+ title?: string;
184
+ }
185
+
186
+ interface KicadSchFile {
187
+ filename: string;
188
+ content: string;
189
+ }
190
+ interface KicadSchFileOutputOptions {
191
+ schematicFilename: string;
192
+ }
193
+ interface CircuitJsonToKicadSchConverterOptions {
194
+ paperSize?: PaperDimensions;
195
+ schematicSheets?: KicadSchematicSheetOptions[];
196
+ titleBlock?: KicadSchematicTitleBlockMetadata;
197
+ }
198
+ interface KicadSchematicSheetOptions {
199
+ /** Position of Circuit JSON (0, 0) on the KiCad page, in millimeters. */
200
+ circuitOrigin: Point;
201
+ /** Geometry of this child sheet's hierarchy node on the root page. */
202
+ hierarchyNode?: {
203
+ position: Point;
204
+ size: {
205
+ height: number;
206
+ width: number;
207
+ };
208
+ };
209
+ /** Omit for a standalone schematic or the root sheet. */
210
+ schematicSheetId?: string;
211
+ }
96
212
  declare class CircuitJsonToKicadSchConverter {
97
213
  ctx: ConverterContext;
98
214
  pipeline: ConverterStage<CircuitJson, KicadSch>[];
99
215
  currentStageIndex: number;
100
216
  finished: boolean;
217
+ circuitJson: CircuitJson;
218
+ schematicSheetPlan: SchematicSheetPlan;
219
+ private files;
220
+ private built;
221
+ private readonly options;
101
222
  get currentStage(): ConverterStage<CircuitJson, KicadSch> | undefined;
102
- constructor(circuitJson: CircuitJson);
223
+ constructor(circuitJson: CircuitJson, options?: CircuitJsonToKicadSchConverterOptions);
103
224
  step(): void;
104
225
  runUntilFinished(): void;
105
226
  getOutput(): KicadSch;
106
227
  /**
107
- * Get the output as a string
228
+ * Get the (root) schematic as a string.
108
229
  */
109
230
  getOutputString(): string;
231
+ /**
232
+ * Returns every KiCad schematic file produced by this converter.
233
+ *
234
+ * For a design with no `schematic_sheet` elements this is a single root file.
235
+ * For a hierarchical design it is the root file (named by
236
+ * `options.schematicFilename`) followed by one child `.kicad_sch` per sheet,
237
+ * each named after its sheet and referenced by the root via `Sheetfile`.
238
+ */
239
+ getOutputFiles(options: KicadSchFileOutputOptions): KicadSchFile[];
240
+ /** Builds the root + child `.kicad_sch` files for a hierarchical design. */
241
+ private buildAll;
242
+ /** Builds one child/root `.kicad_sch` for a sheet, run to completion. */
243
+ private buildSheetFile;
110
244
  }
111
245
 
112
246
  interface CircuitJsonToKicadPcbOptions {
@@ -121,6 +255,11 @@ interface CircuitJsonToKicadPcbOptions {
121
255
  * e.g. "index" → "3dmodels/index.3dshapes/{filename}"
122
256
  */
123
257
  projectName?: string;
258
+ /**
259
+ * Stroke width in millimetres for generated Edge.Cuts graphics.
260
+ * Defaults to 0.1 mm when the source format does not provide one.
261
+ */
262
+ edgeCutsWidth?: number;
124
263
  }
125
264
  declare class CircuitJsonToKicadPcbConverter {
126
265
  ctx: ConverterContext;
@@ -147,6 +286,12 @@ interface CircuitJsonToKicadProOptions {
147
286
  projectName?: string;
148
287
  schematicFilename?: string;
149
288
  pcbFilename?: string;
289
+ /**
290
+ * Sheet plan produced by CircuitJsonToKicadSchConverter. When provided, the
291
+ * project's `sheets` list uses the same root/sheet-node UUIDs so the
292
+ * `.kicad_pro` stays consistent with the generated `.kicad_sch` hierarchy.
293
+ */
294
+ schematicSheetPlan?: SchematicSheetPlan;
150
295
  }
151
296
  interface KicadProNetClass {
152
297
  bus_width?: number;
@@ -261,6 +406,24 @@ declare class CircuitJsonToKicadProConverter {
261
406
  getOutputString(): string;
262
407
  }
263
408
 
409
+ interface CircuitJsonToKicadModOptions {
410
+ libraryName?: string;
411
+ footprintLibraryName?: string;
412
+ footprintName?: string;
413
+ }
414
+ declare class CircuitJsonToKicadModConverter {
415
+ private readonly libraryConverter;
416
+ private readonly footprintName?;
417
+ constructor(circuitJson: CircuitJson, options?: CircuitJsonToKicadModOptions);
418
+ get finished(): boolean;
419
+ get currentStage(): ConverterStage<CircuitJson, KicadLibraryOutput> | undefined;
420
+ step(): void;
421
+ runUntilFinished(): void;
422
+ getOutput(): FootprintEntry;
423
+ getOutputString(): string;
424
+ getModel3dSourcePaths(): string[];
425
+ }
426
+
264
427
  type ModelFetchResponse = {
265
428
  ok: boolean;
266
429
  arrayBuffer: () => Promise<ArrayBuffer>;
@@ -389,4 +552,4 @@ declare class KicadLibraryConverter {
389
552
  getOutput(): KicadLibraryConverterOutput;
390
553
  }
391
554
 
392
- export { CircuitJsonToKicadLibraryConverter, CircuitJsonToKicadPcbConverter, CircuitJsonToKicadProConverter, CircuitJsonToKicadSchConverter, type FootprintEntry, type Kicad3dModelLoadError, KicadLibraryConverter, type KicadLibraryConverterOptions, type KicadLibraryConverterOutput, type KicadLibraryOutput, type LoadedKicad3dModelFile, type ResolveAndLoadKicad3dModelFilesOptions, type SymbolEntry, resolveAndLoadKicad3dModelFiles };
555
+ export { CircuitJsonToKicadLibraryConverter, CircuitJsonToKicadModConverter, CircuitJsonToKicadPcbConverter, type CircuitJsonToKicadPcbOptions, CircuitJsonToKicadProConverter, CircuitJsonToKicadSchConverter, type CircuitJsonToKicadSchConverterOptions, type FootprintEntry, type Kicad3dModelLoadError, KicadLibraryConverter, type KicadLibraryConverterOptions, type KicadLibraryConverterOutput, type KicadLibraryOutput, type KicadSchFile, type KicadSchFileOutputOptions, type KicadSchematicSheetOptions, type LoadedKicad3dModelFile, type ResolveAndLoadKicad3dModelFilesOptions, type SymbolEntry, resolveAndLoadKicad3dModelFiles };
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/internal-dynamic-import",
3
- "version": "0.0.19",
3
+ "license": "MIT",
4
+ "version": "0.0.21",
4
5
  "repository": {
5
6
  "type": "git",
6
7
  "url": "https://github.com/tscircuit/internal-dynamic-import"
@@ -45,7 +46,7 @@
45
46
  "circuit-json-to-fdm-component-box": "0.0.2",
46
47
  "circuit-json-to-gerber": "0.0.84",
47
48
  "circuit-json-to-gltf": "0.0.106",
48
- "circuit-json-to-kicad": "0.0.137",
49
+ "circuit-json-to-kicad": "0.0.241",
49
50
  "circuit-json-to-lbrn": "0.0.69",
50
51
  "circuit-json-to-pnp-csv": "0.0.8",
51
52
  "circuit-json-to-readable-netlist": "0.0.15",