@tscircuit/internal-dynamic-import 0.0.14 → 0.0.16

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/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as circuit_json_to_gltf from 'circuit-json-to-gltf';
2
2
  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
3
  import { BpcGraph } from 'bpc-graph';
4
+ import { RenderOptionsInput } from 'poppygl';
4
5
  import { z, AnyZodObject } from 'zod';
5
6
  import { CircuitJsonUtilObjects, cju } from '@tscircuit/circuit-json-util';
6
7
  import { KicadSch, KicadPcb, SchematicSymbol, KicadSym } from 'kicadts';
@@ -175,6 +176,182 @@ declare namespace CircuitJsonToConnectivityMapModule {
175
176
  export { CircuitJsonToConnectivityMapModule_ConnectivityMap as ConnectivityMap, CircuitJsonToConnectivityMapModule_PcbConnectivityMap as PcbConnectivityMap, CircuitJsonToConnectivityMapModule_findConnectedNetworks as findConnectedNetworks, CircuitJsonToConnectivityMapModule_getFullConnectivityMapFromCircuitJson as getFullConnectivityMapFromCircuitJson, CircuitJsonToConnectivityMapModule_getSourcePortConnectivityMapFromCircuitJson as getSourcePortConnectivityMapFromCircuitJson };
176
177
  }
177
178
 
179
+ interface FdmComponentBoxOptions {
180
+ /** Number of compartments per row. Defaults to a near-square layout. */
181
+ columns?: number;
182
+ /** Clear X dimension of each compartment, in millimetres. */
183
+ compartmentWidth?: number;
184
+ /** Clear Y dimension of each compartment, in millimetres. */
185
+ compartmentDepth?: number;
186
+ /** Clear Z depth from the floor to the rim, in millimetres. */
187
+ compartmentHeight?: number;
188
+ /** Thickness of outside and divider walls, in millimetres. */
189
+ wallThickness?: number;
190
+ /** Thickness beneath each compartment, in millimetres. */
191
+ floorThickness?: number;
192
+ /** Solid Y-depth behind each compartment that carries its label. */
193
+ labelBandDepth?: number;
194
+ /** Height of the raised label above the box rim, in millimetres. */
195
+ labelThickness?: number;
196
+ /** Empty margin around each label, in millimetres. */
197
+ labelPadding?: number;
198
+ /** Smallest allowed text stroke, in millimetres. */
199
+ minimumLabelStrokeWidth?: number;
200
+ /** Include source components that do not have a pcb_component record. */
201
+ includeUnplacedComponents?: boolean;
202
+ /** Include test points, which are excluded from assembly compartments by default. */
203
+ includeTestPoints?: boolean;
204
+ /** Group confidently identical BOM parts into one compartment. Defaults to true. */
205
+ groupByComponent?: boolean;
206
+ /** Core 3MF display color for the box material, as #RRGGBB or #RRGGBBAA. */
207
+ boxColor?: string;
208
+ /** Core 3MF display color for the label material, as #RRGGBB or #RRGGBBAA. */
209
+ labelColor?: string;
210
+ /** Title stored in the 3MF model metadata. */
211
+ title?: string;
212
+ }
213
+ interface ComponentGroup {
214
+ /** Stable description of the BOM identity used for this group. */
215
+ componentKey: string;
216
+ /** Every refdes whose physical parts belong in this compartment. */
217
+ referenceDesignators: string[];
218
+ quantity: number;
219
+ componentType?: string;
220
+ manufacturerPartNumber?: string;
221
+ supplierPartNumbers?: Record<string, string[]>;
222
+ footprint?: string;
223
+ }
224
+ interface FdmComponentBoxDimensions {
225
+ /** Overall X dimension, in millimetres. */
226
+ width: number;
227
+ /** Overall Y dimension, in millimetres. */
228
+ depth: number;
229
+ /** Overall Z dimension excluding raised text, in millimetres. */
230
+ height: number;
231
+ columns: number;
232
+ rows: number;
233
+ }
234
+ interface CompartmentPlacement {
235
+ /** Primary refdes, retained for compatibility with one-component compartments. */
236
+ refdes: string;
237
+ /** All refdes values assigned to this compartment. */
238
+ referenceDesignators: string[];
239
+ /** Text physically embossed above the compartment. */
240
+ label: string;
241
+ componentKey: string;
242
+ quantity: number;
243
+ row: number;
244
+ column: number;
245
+ /** Cavity center in the box coordinate frame, in millimetres. */
246
+ center: {
247
+ x: number;
248
+ y: number;
249
+ };
250
+ /** Center of the solid label band behind this cavity, in millimetres. */
251
+ labelCenter: {
252
+ x: number;
253
+ y: number;
254
+ };
255
+ width: number;
256
+ depth: number;
257
+ }
258
+ interface FdmComponentBoxMeshStats {
259
+ boxTriangles: number;
260
+ labelTriangles: number;
261
+ totalTriangles: number;
262
+ }
263
+ interface FdmComponentBoxResult {
264
+ /** Ready-to-write 3MF package bytes. */
265
+ threeMf: Uint8Array;
266
+ /** Naturally sorted refdes values represented by all compartments. */
267
+ componentRefdes: string[];
268
+ /** BOM-aware groups, one per generated compartment. */
269
+ componentGroups: ComponentGroup[];
270
+ dimensions: FdmComponentBoxDimensions;
271
+ compartments: CompartmentPlacement[];
272
+ meshStats: FdmComponentBoxMeshStats;
273
+ }
274
+ interface ResolvedFdmComponentBoxOptions {
275
+ columns: number;
276
+ compartmentWidth: number;
277
+ compartmentDepth: number;
278
+ compartmentHeight: number;
279
+ wallThickness: number;
280
+ floorThickness: number;
281
+ labelBandDepth: number;
282
+ labelThickness: number;
283
+ labelPadding: number;
284
+ minimumLabelStrokeWidth: number;
285
+ includeUnplacedComponents: boolean;
286
+ includeTestPoints: boolean;
287
+ groupByComponent: boolean;
288
+ boxColor: string;
289
+ labelColor: string;
290
+ title: string;
291
+ }
292
+ declare const DEFAULT_FDM_COMPONENT_BOX_OPTIONS: {
293
+ readonly compartmentWidth: 26;
294
+ readonly compartmentDepth: 22;
295
+ readonly compartmentHeight: 12;
296
+ readonly wallThickness: 1.6;
297
+ readonly floorThickness: 1.6;
298
+ readonly labelBandDepth: 6.5;
299
+ readonly labelThickness: 0.6;
300
+ readonly labelPadding: 0.75;
301
+ readonly minimumLabelStrokeWidth: 0.45;
302
+ readonly includeUnplacedComponents: false;
303
+ readonly includeTestPoints: false;
304
+ readonly groupByComponent: true;
305
+ readonly boxColor: "#D9D9D9FF";
306
+ readonly labelColor: "#151515FF";
307
+ };
308
+
309
+ declare const createFdmComponentBox: (circuitJson: CircuitJson, options?: FdmComponentBoxOptions) => Promise<FdmComponentBoxResult>;
310
+ /** Convert Circuit JSON directly to a ready-to-write 3MF byte array. */
311
+ declare const circuitJsonToFdmComponentBox: (circuitJson: CircuitJson, options?: FdmComponentBoxOptions) => Promise<Uint8Array>;
312
+
313
+ interface ExtractComponentGroupsOptions {
314
+ includeUnplacedComponents?: boolean;
315
+ includeTestPoints?: boolean;
316
+ groupByComponent?: boolean;
317
+ }
318
+ declare const naturalRefdesCollator: Intl.Collator;
319
+ declare const extractComponentGroups: (circuitJson: CircuitJson, options?: ExtractComponentGroupsOptions) => ComponentGroup[];
320
+
321
+ /**
322
+ * Returns the physical component refdes values that should receive pockets.
323
+ *
324
+ * When the document contains pcb_component records, unplaced source components
325
+ * are omitted by default. Source-only Circuit JSON falls back to all source
326
+ * components so partially rendered documents remain useful.
327
+ */
328
+ declare const extractComponentRefdes: (circuitJson: CircuitJson, options?: Omit<ExtractComponentGroupsOptions, "groupByComponent">) => string[];
329
+
330
+ type FdmComponentBoxPngOptions = RenderOptionsInput;
331
+ /** Render a deterministic, pure-JavaScript PNG preview directly from Circuit JSON. */
332
+ declare const renderFdmComponentBoxPng: (circuitJson: CircuitJson, boxOptions?: FdmComponentBoxOptions, renderOptions?: FdmComponentBoxPngOptions) => Promise<Uint8Array>;
333
+
334
+ declare const CircuitJsonToFdmComponentBoxModule_CircuitJson: typeof CircuitJson;
335
+ type CircuitJsonToFdmComponentBoxModule_CompartmentPlacement = CompartmentPlacement;
336
+ type CircuitJsonToFdmComponentBoxModule_ComponentGroup = ComponentGroup;
337
+ declare const CircuitJsonToFdmComponentBoxModule_DEFAULT_FDM_COMPONENT_BOX_OPTIONS: typeof DEFAULT_FDM_COMPONENT_BOX_OPTIONS;
338
+ type CircuitJsonToFdmComponentBoxModule_ExtractComponentGroupsOptions = ExtractComponentGroupsOptions;
339
+ type CircuitJsonToFdmComponentBoxModule_FdmComponentBoxDimensions = FdmComponentBoxDimensions;
340
+ type CircuitJsonToFdmComponentBoxModule_FdmComponentBoxMeshStats = FdmComponentBoxMeshStats;
341
+ type CircuitJsonToFdmComponentBoxModule_FdmComponentBoxOptions = FdmComponentBoxOptions;
342
+ type CircuitJsonToFdmComponentBoxModule_FdmComponentBoxPngOptions = FdmComponentBoxPngOptions;
343
+ type CircuitJsonToFdmComponentBoxModule_FdmComponentBoxResult = FdmComponentBoxResult;
344
+ type CircuitJsonToFdmComponentBoxModule_ResolvedFdmComponentBoxOptions = ResolvedFdmComponentBoxOptions;
345
+ declare const CircuitJsonToFdmComponentBoxModule_circuitJsonToFdmComponentBox: typeof circuitJsonToFdmComponentBox;
346
+ declare const CircuitJsonToFdmComponentBoxModule_createFdmComponentBox: typeof createFdmComponentBox;
347
+ declare const CircuitJsonToFdmComponentBoxModule_extractComponentGroups: typeof extractComponentGroups;
348
+ declare const CircuitJsonToFdmComponentBoxModule_extractComponentRefdes: typeof extractComponentRefdes;
349
+ declare const CircuitJsonToFdmComponentBoxModule_naturalRefdesCollator: typeof naturalRefdesCollator;
350
+ declare const CircuitJsonToFdmComponentBoxModule_renderFdmComponentBoxPng: typeof renderFdmComponentBoxPng;
351
+ declare namespace CircuitJsonToFdmComponentBoxModule {
352
+ export { CircuitJsonToFdmComponentBoxModule_CircuitJson as CircuitJson, type CircuitJsonToFdmComponentBoxModule_CompartmentPlacement as CompartmentPlacement, type CircuitJsonToFdmComponentBoxModule_ComponentGroup as ComponentGroup, CircuitJsonToFdmComponentBoxModule_DEFAULT_FDM_COMPONENT_BOX_OPTIONS as DEFAULT_FDM_COMPONENT_BOX_OPTIONS, type CircuitJsonToFdmComponentBoxModule_ExtractComponentGroupsOptions as ExtractComponentGroupsOptions, type CircuitJsonToFdmComponentBoxModule_FdmComponentBoxDimensions as FdmComponentBoxDimensions, type CircuitJsonToFdmComponentBoxModule_FdmComponentBoxMeshStats as FdmComponentBoxMeshStats, type CircuitJsonToFdmComponentBoxModule_FdmComponentBoxOptions as FdmComponentBoxOptions, type CircuitJsonToFdmComponentBoxModule_FdmComponentBoxPngOptions as FdmComponentBoxPngOptions, type CircuitJsonToFdmComponentBoxModule_FdmComponentBoxResult as FdmComponentBoxResult, type CircuitJsonToFdmComponentBoxModule_ResolvedFdmComponentBoxOptions as ResolvedFdmComponentBoxOptions, CircuitJsonToFdmComponentBoxModule_circuitJsonToFdmComponentBox as circuitJsonToFdmComponentBox, CircuitJsonToFdmComponentBoxModule_createFdmComponentBox as createFdmComponentBox, CircuitJsonToFdmComponentBoxModule_extractComponentGroups as extractComponentGroups, CircuitJsonToFdmComponentBoxModule_extractComponentRefdes as extractComponentRefdes, CircuitJsonToFdmComponentBoxModule_naturalRefdesCollator as naturalRefdesCollator, CircuitJsonToFdmComponentBoxModule_renderFdmComponentBoxPng as renderFdmComponentBoxPng };
353
+ }
354
+
178
355
  interface ExcellonDrillCommandDef<K extends string, T extends AnyZodObject | z.ZodIntersection<any, any>> {
179
356
  command_code: K;
180
357
  schema: T;
@@ -3621,7 +3798,7 @@ declare namespace KicadToCircuitJsonModule {
3621
3798
  export { KicadToCircuitJsonModule_CollectFootprintsStage as CollectFootprintsStage, KicadToCircuitJsonModule_CollectGraphicsStage as CollectGraphicsStage, KicadToCircuitJsonModule_CollectLibrarySymbolsStage as CollectLibrarySymbolsStage, KicadToCircuitJsonModule_CollectNetsStage as CollectNetsStage, KicadToCircuitJsonModule_CollectSchematicTracesStage as CollectSchematicTracesStage, KicadToCircuitJsonModule_CollectSourceTracesStage as CollectSourceTracesStage, KicadToCircuitJsonModule_CollectSymbolLibrarySymbolsStage as CollectSymbolLibrarySymbolsStage, KicadToCircuitJsonModule_CollectTracesStage as CollectTracesStage, KicadToCircuitJsonModule_CollectViasStage as CollectViasStage, KicadToCircuitJsonModule_CollectZonesStage as CollectZonesStage, type KicadToCircuitJsonModule_ConverterContext as ConverterContext, KicadToCircuitJsonModule_ConverterStage as ConverterStage, KicadToCircuitJsonModule_InitializePcbContextStage as InitializePcbContextStage, KicadToCircuitJsonModule_InitializeSchematicContextStage as InitializeSchematicContextStage, KicadToCircuitJsonModule_InitializeSymbolLibraryContextStage as InitializeSymbolLibraryContextStage, KicadToCircuitJsonModule_KicadFootprintToCircuitJsonConverter as KicadFootprintToCircuitJsonConverter, KicadToCircuitJsonModule_KicadSymbolToCircuitJsonConverter as KicadSymbolToCircuitJsonConverter, KicadToCircuitJsonModule_KicadToCircuitJsonConverter as KicadToCircuitJsonConverter };
3622
3799
  }
3623
3800
 
3624
- declare const supportedModules: readonly ["circuit-json-to-3d-png", "circuit-json-to-bom-csv", "circuit-json-to-bpc", "circuit-json-to-connectivity-map", "circuit-json-to-gerber", "circuit-json-to-gltf", "circuit-json-to-kicad", "circuit-json-to-lbrn", "circuit-json-to-pnp-csv", "circuit-json-to-readable-netlist", "circuit-json-to-simple-3d", "circuit-json-to-spice", "circuit-json-to-step", "circuit-json-to-tscircuit", "circuit-to-canvas", "circuit-to-svg", "kicad-to-circuit-json"];
3801
+ declare const supportedModules: readonly ["circuit-json-to-3d-png", "circuit-json-to-bom-csv", "circuit-json-to-bpc", "circuit-json-to-connectivity-map", "circuit-json-to-fdm-component-box", "circuit-json-to-gerber", "circuit-json-to-gltf", "circuit-json-to-kicad", "circuit-json-to-lbrn", "circuit-json-to-pnp-csv", "circuit-json-to-readable-netlist", "circuit-json-to-simple-3d", "circuit-json-to-spice", "circuit-json-to-step", "circuit-json-to-tscircuit", "circuit-to-canvas", "circuit-to-svg", "kicad-to-circuit-json"];
3625
3802
  type SupportedModuleName = (typeof supportedModules)[number];
3626
3803
  type SupportedModuleSpecifier = SupportedModuleName | `${SupportedModuleName}@${string}`;
3627
3804
  interface SupportedModuleMap {
@@ -3629,6 +3806,7 @@ interface SupportedModuleMap {
3629
3806
  "circuit-json-to-bom-csv": typeof CircuitJsonToBomCsvModule;
3630
3807
  "circuit-json-to-bpc": typeof CircuitJsonToBpcModule;
3631
3808
  "circuit-json-to-connectivity-map": typeof CircuitJsonToConnectivityMapModule;
3809
+ "circuit-json-to-fdm-component-box": typeof CircuitJsonToFdmComponentBoxModule;
3632
3810
  "circuit-json-to-gerber": typeof CircuitJsonToGerberModule;
3633
3811
  "circuit-json-to-gltf": typeof CircuitJsonToGltfModule;
3634
3812
  "circuit-json-to-kicad": typeof CircuitJsonToKicadModule;
package/dist/index.js CHANGED
@@ -18,6 +18,7 @@ var supportedModules = [
18
18
  "circuit-json-to-bom-csv",
19
19
  "circuit-json-to-bpc",
20
20
  "circuit-json-to-connectivity-map",
21
+ "circuit-json-to-fdm-component-box",
21
22
  "circuit-json-to-gerber",
22
23
  "circuit-json-to-gltf",
23
24
  "circuit-json-to-kicad",
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../lib/dynamic-module-registry.ts","../lib/supported-modules.ts","../lib/index.ts"],"names":[],"mappings":";AAYO,IAAM,2BAA2B,MAA6B;AACnE,EAAA,IAAI,WAAW,uBAAA,EAAyB;AACtC,IAAA,OAAO,UAAA,CAAW,uBAAA;AAAA,EACpB;AAEA,EAAA,MAAM,WAAkC,EAAC;AACzC,EAAA,UAAA,CAAW,uBAAA,GAA0B,QAAA;AACrC,EAAA,OAAO,QAAA;AACT;AAUO,SAAS,qBAAA,CACd,MACA,GAAA,EACS;AACT,EAAA,wBAAA,EAAyB,CAAE,IAAI,CAAA,GAAI,GAAA;AACnC,EAAA,OAAO,GAAA;AACT;;;AClBO,IAAM,gBAAA,GAAmB;AAAA,EAC9B,wBAAA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,SAAA,EAAmB;AAChD,EAAA,MAAM,UAAA,GAAa,cAAc,SAAS,CAAA;AAE1C,EAAA,IAAI,CAAC,kBAAA,CAAmB,GAAA,CAAI,UAAU,CAAA,EAAG;AACvC,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,oBAAA,EAAuB,SAAS,CAAA,CAAE,CAAA;AAAA,EACpD;AACF;AAMA,eAAe,SAAS,SAAA,EAAqC;AAC3D,EAAA,IAAI,SAAA;AAEJ,EAAA,KAAA,MAAW,SAAA,IAAa,aAAA,CAAc,SAAS,CAAA,EAAG;AAChD,IAAA,IAAI;AACF,MAAA,MAAM,MAAM,MAAM;AAAA;AAAA,QAA0B;AAAA,OAAA;AAC5C,MAAA,OAAO,qBAAA,CAAsB,aAAA,CAAc,SAAS,CAAA,EAAG,GAAG,CAAA;AAAA,IAC5D,SAAS,KAAA,EAAO;AACd,MAAA,SAAA,GAAY,KAAA;AAAA,IACd;AAAA,EACF;AAEA,EAAA,MAAM,SAAA;AACR;AAEA,IAAO,aAAA,GAAQ","file":"index.js","sourcesContent":["import type {\n SupportedModuleMap,\n SupportedModuleName,\n} from \"./supported-modules\"\n\nexport type DynamicModuleRegistry = Partial<SupportedModuleMap> &\n Record<string, unknown>\n\ndeclare global {\n var tscircuitDynamicModules: DynamicModuleRegistry | undefined\n}\n\nexport const getDynamicModuleRegistry = (): DynamicModuleRegistry => {\n if (globalThis.tscircuitDynamicModules) {\n return globalThis.tscircuitDynamicModules\n }\n\n const registry: DynamicModuleRegistry = {}\n globalThis.tscircuitDynamicModules = registry\n return registry\n}\n\nexport function registerDynamicModule<TSpecifier extends SupportedModuleName>(\n name: TSpecifier,\n mod: SupportedModuleMap[TSpecifier],\n): SupportedModuleMap[TSpecifier]\nexport function registerDynamicModule<TModule>(\n name: string,\n mod: TModule,\n): TModule\nexport function registerDynamicModule<TModule>(\n name: string,\n mod: TModule,\n): TModule {\n getDynamicModuleRegistry()[name] = mod\n return mod\n}\n","import type * as CircuitJsonTo3dPngModule from \"./type-bundles/circuit-json-to-3d-png\"\nimport type * as CircuitJsonToBomCsvModule from \"./type-bundles/circuit-json-to-bom-csv\"\nimport type * as CircuitJsonToBpcModule from \"./type-bundles/circuit-json-to-bpc\"\nimport type * as CircuitJsonToConnectivityMapModule from \"./type-bundles/circuit-json-to-connectivity-map\"\nimport type * as CircuitJsonToGerberModule from \"./type-bundles/circuit-json-to-gerber\"\nimport type * as CircuitJsonToGltfModule from \"./type-bundles/circuit-json-to-gltf\"\nimport type * as CircuitJsonToKicadModule from \"./type-bundles/circuit-json-to-kicad\"\nimport type * as CircuitJsonToLbrnModule from \"./type-bundles/circuit-json-to-lbrn\"\nimport type * as CircuitJsonToPnpCsvModule from \"./type-bundles/circuit-json-to-pnp-csv\"\nimport type * as CircuitJsonToReadableNetlistModule from \"./type-bundles/circuit-json-to-readable-netlist\"\nimport type * as CircuitJsonToSimple3dModule from \"./type-bundles/circuit-json-to-simple-3d\"\nimport type * as CircuitJsonToSpiceModule from \"./type-bundles/circuit-json-to-spice\"\nimport type * as CircuitJsonToStepModule from \"./type-bundles/circuit-json-to-step\"\nimport type * as CircuitJsonToTscircuitModule from \"./type-bundles/circuit-json-to-tscircuit\"\nimport type * as CircuitToCanvasModule from \"./type-bundles/circuit-to-canvas\"\nimport type * as CircuitToSvgModule from \"./type-bundles/circuit-to-svg\"\nimport type * as KicadToCircuitJsonModule from \"./type-bundles/kicad-to-circuit-json\"\n\nexport const supportedModules = [\n \"circuit-json-to-3d-png\",\n \"circuit-json-to-bom-csv\",\n \"circuit-json-to-bpc\",\n \"circuit-json-to-connectivity-map\",\n \"circuit-json-to-gerber\",\n \"circuit-json-to-gltf\",\n \"circuit-json-to-kicad\",\n \"circuit-json-to-lbrn\",\n \"circuit-json-to-pnp-csv\",\n \"circuit-json-to-readable-netlist\",\n \"circuit-json-to-simple-3d\",\n \"circuit-json-to-spice\",\n \"circuit-json-to-step\",\n \"circuit-json-to-tscircuit\",\n \"circuit-to-canvas\",\n \"circuit-to-svg\",\n \"kicad-to-circuit-json\",\n] as const\n\nexport type SupportedModuleName = (typeof supportedModules)[number]\nexport type SupportedModuleSpecifier =\n | SupportedModuleName\n | `${SupportedModuleName}@${string}`\n\nexport interface SupportedModuleMap {\n \"circuit-json-to-3d-png\": typeof CircuitJsonTo3dPngModule\n \"circuit-json-to-bom-csv\": typeof CircuitJsonToBomCsvModule\n \"circuit-json-to-bpc\": typeof CircuitJsonToBpcModule\n \"circuit-json-to-connectivity-map\": typeof CircuitJsonToConnectivityMapModule\n \"circuit-json-to-gerber\": typeof CircuitJsonToGerberModule\n \"circuit-json-to-gltf\": typeof CircuitJsonToGltfModule\n \"circuit-json-to-kicad\": typeof CircuitJsonToKicadModule\n \"circuit-json-to-lbrn\": typeof CircuitJsonToLbrnModule\n \"circuit-json-to-pnp-csv\": typeof CircuitJsonToPnpCsvModule\n \"circuit-json-to-readable-netlist\": typeof CircuitJsonToReadableNetlistModule\n \"circuit-json-to-simple-3d\": typeof CircuitJsonToSimple3dModule\n \"circuit-json-to-spice\": typeof CircuitJsonToSpiceModule\n \"circuit-json-to-step\": typeof CircuitJsonToStepModule\n \"circuit-json-to-tscircuit\": typeof CircuitJsonToTscircuitModule\n \"circuit-to-canvas\": typeof CircuitToCanvasModule\n \"circuit-to-svg\": typeof CircuitToSvgModule\n \"kicad-to-circuit-json\": typeof KicadToCircuitJsonModule\n}\n\nexport type StripVersion<TSpecifier extends string> =\n TSpecifier extends `${infer TBase}@${string}`\n ? TBase extends SupportedModuleName\n ? TBase\n : never\n : TSpecifier extends SupportedModuleName\n ? TSpecifier\n : never\n\nexport const getModuleName = (specifier: string): string => {\n const versionSeparatorIndex = specifier.indexOf(\"@\")\n return versionSeparatorIndex === -1\n ? specifier\n : specifier.slice(0, versionSeparatorIndex)\n}\n","import { registerDynamicModule } from \"./dynamic-module-registry\"\nimport {\n getModuleName,\n supportedModules,\n type StripVersion,\n type SupportedModuleMap,\n type SupportedModuleSpecifier,\n} from \"./supported-modules\"\n\nexport {\n getDynamicModuleRegistry,\n registerDynamicModule,\n} from \"./dynamic-module-registry\"\nexport type { DynamicModuleRegistry } from \"./dynamic-module-registry\"\nexport {\n getModuleName,\n supportedModules,\n} from \"./supported-modules\"\nexport type {\n StripVersion,\n SupportedModuleMap,\n SupportedModuleName,\n SupportedModuleSpecifier,\n} from \"./supported-modules\"\n\nconst supportedModuleSet = new Set<string>(supportedModules)\n\nexport const getImportUrl = (specifier: string): string => {\n assertSupportedModule(specifier)\n\n return getJscdnImportUrl(specifier)\n}\n\nexport const getImportUrls = (specifier: string): string[] => {\n assertSupportedModule(specifier)\n\n return [getJscdnImportUrl(specifier), `https://esm.run/${specifier}`]\n}\n\nfunction getJscdnImportUrl(specifier: string): string {\n const moduleName = getModuleName(specifier)\n const version =\n specifier.length === moduleName.length\n ? \"latest\"\n : specifier.slice(moduleName.length + 1)\n\n return `https://jscdn.tscircuit.com/${moduleName}/${version}/+esm`\n}\n\nfunction assertSupportedModule(specifier: string) {\n const moduleName = getModuleName(specifier)\n\n if (!supportedModuleSet.has(moduleName)) {\n throw new Error(`Unsupported module: ${specifier}`)\n }\n}\n\nasync function importer<TSpecifier extends SupportedModuleSpecifier>(\n specifier: TSpecifier,\n): Promise<SupportedModuleMap[StripVersion<TSpecifier>]>\nasync function importer(specifier: string): Promise<unknown>\nasync function importer(specifier: string): Promise<unknown> {\n let lastError: unknown\n\n for (const importUrl of getImportUrls(specifier)) {\n try {\n const mod = await import(/* @vite-ignore */ importUrl)\n return registerDynamicModule(getModuleName(specifier), mod)\n } catch (error) {\n lastError = error\n }\n }\n\n throw lastError\n}\n\nexport default importer\n"]}
1
+ {"version":3,"sources":["../lib/dynamic-module-registry.ts","../lib/supported-modules.ts","../lib/index.ts"],"names":[],"mappings":";AAYO,IAAM,2BAA2B,MAA6B;AACnE,EAAA,IAAI,WAAW,uBAAA,EAAyB;AACtC,IAAA,OAAO,UAAA,CAAW,uBAAA;AAAA,EACpB;AAEA,EAAA,MAAM,WAAkC,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AAS,CAAA;AAC1C,EAAA,MAAM,OAAA,GACJ,SAAA,CAAU,MAAA,KAAW,UAAA,CAAW,MAAA,GAC5B,WACA,SAAA,CAAU,KAAA,CAAM,UAAA,CAAW,MAAA,GAAS,CAAC,CAAA;AAE3C,EAAA,OAAO,CAAA,4BAAA,EAA+B,UAAU,CAAA,CAAA,EAAI,OAAO,CAAA,KAAA,CAAA;AAC7D;AAEA,SAAS,sBAAsB,SAAA,EAAmB;AAChD,EAAA,MAAM,UAAA,GAAa,cAAc,SAAS,CAAA;AAE1C,EAAA,IAAI,CAAC,kBAAA,CAAmB,GAAA,CAAI,UAAU,CAAA,EAAG;AACvC,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,oBAAA,EAAuB,SAAS,CAAA,CAAE,CAAA;AAAA,EACpD;AACF;AAMA,eAAe,SAAS,SAAA,EAAqC;AAC3D,EAAA,IAAI,SAAA;AAEJ,EAAA,KAAA,MAAW,SAAA,IAAa,aAAA,CAAc,SAAS,CAAA,EAAG;AAChD,IAAA,IAAI;AACF,MAAA,MAAM,MAAM,MAAM;AAAA;AAAA,QAA0B;AAAA,OAAA;AAC5C,MAAA,OAAO,qBAAA,CAAsB,aAAA,CAAc,SAAS,CAAA,EAAG,GAAG,CAAA;AAAA,IAC5D,SAAS,KAAA,EAAO;AACd,MAAA,SAAA,GAAY,KAAA;AAAA,IACd;AAAA,EACF;AAEA,EAAA,MAAM,SAAA;AACR;AAEA,IAAO,aAAA,GAAQ","file":"index.js","sourcesContent":["import type {\n SupportedModuleMap,\n SupportedModuleName,\n} from \"./supported-modules\"\n\nexport type DynamicModuleRegistry = Partial<SupportedModuleMap> &\n Record<string, unknown>\n\ndeclare global {\n var tscircuitDynamicModules: DynamicModuleRegistry | undefined\n}\n\nexport const getDynamicModuleRegistry = (): DynamicModuleRegistry => {\n if (globalThis.tscircuitDynamicModules) {\n return globalThis.tscircuitDynamicModules\n }\n\n const registry: DynamicModuleRegistry = {}\n globalThis.tscircuitDynamicModules = registry\n return registry\n}\n\nexport function registerDynamicModule<TSpecifier extends SupportedModuleName>(\n name: TSpecifier,\n mod: SupportedModuleMap[TSpecifier],\n): SupportedModuleMap[TSpecifier]\nexport function registerDynamicModule<TModule>(\n name: string,\n mod: TModule,\n): TModule\nexport function registerDynamicModule<TModule>(\n name: string,\n mod: TModule,\n): TModule {\n getDynamicModuleRegistry()[name] = mod\n return mod\n}\n","import type * as CircuitJsonTo3dPngModule from \"./type-bundles/circuit-json-to-3d-png\"\nimport type * as CircuitJsonToBomCsvModule from \"./type-bundles/circuit-json-to-bom-csv\"\nimport type * as CircuitJsonToBpcModule from \"./type-bundles/circuit-json-to-bpc\"\nimport type * as CircuitJsonToConnectivityMapModule from \"./type-bundles/circuit-json-to-connectivity-map\"\nimport type * as CircuitJsonToFdmComponentBoxModule from \"./type-bundles/circuit-json-to-fdm-component-box\"\nimport type * as CircuitJsonToGerberModule from \"./type-bundles/circuit-json-to-gerber\"\nimport type * as CircuitJsonToGltfModule from \"./type-bundles/circuit-json-to-gltf\"\nimport type * as CircuitJsonToKicadModule from \"./type-bundles/circuit-json-to-kicad\"\nimport type * as CircuitJsonToLbrnModule from \"./type-bundles/circuit-json-to-lbrn\"\nimport type * as CircuitJsonToPnpCsvModule from \"./type-bundles/circuit-json-to-pnp-csv\"\nimport type * as CircuitJsonToReadableNetlistModule from \"./type-bundles/circuit-json-to-readable-netlist\"\nimport type * as CircuitJsonToSimple3dModule from \"./type-bundles/circuit-json-to-simple-3d\"\nimport type * as CircuitJsonToSpiceModule from \"./type-bundles/circuit-json-to-spice\"\nimport type * as CircuitJsonToStepModule from \"./type-bundles/circuit-json-to-step\"\nimport type * as CircuitJsonToTscircuitModule from \"./type-bundles/circuit-json-to-tscircuit\"\nimport type * as CircuitToCanvasModule from \"./type-bundles/circuit-to-canvas\"\nimport type * as CircuitToSvgModule from \"./type-bundles/circuit-to-svg\"\nimport type * as KicadToCircuitJsonModule from \"./type-bundles/kicad-to-circuit-json\"\n\nexport const supportedModules = [\n \"circuit-json-to-3d-png\",\n \"circuit-json-to-bom-csv\",\n \"circuit-json-to-bpc\",\n \"circuit-json-to-connectivity-map\",\n \"circuit-json-to-fdm-component-box\",\n \"circuit-json-to-gerber\",\n \"circuit-json-to-gltf\",\n \"circuit-json-to-kicad\",\n \"circuit-json-to-lbrn\",\n \"circuit-json-to-pnp-csv\",\n \"circuit-json-to-readable-netlist\",\n \"circuit-json-to-simple-3d\",\n \"circuit-json-to-spice\",\n \"circuit-json-to-step\",\n \"circuit-json-to-tscircuit\",\n \"circuit-to-canvas\",\n \"circuit-to-svg\",\n \"kicad-to-circuit-json\",\n] as const\n\nexport type SupportedModuleName = (typeof supportedModules)[number]\nexport type SupportedModuleSpecifier =\n | SupportedModuleName\n | `${SupportedModuleName}@${string}`\n\nexport interface SupportedModuleMap {\n \"circuit-json-to-3d-png\": typeof CircuitJsonTo3dPngModule\n \"circuit-json-to-bom-csv\": typeof CircuitJsonToBomCsvModule\n \"circuit-json-to-bpc\": typeof CircuitJsonToBpcModule\n \"circuit-json-to-connectivity-map\": typeof CircuitJsonToConnectivityMapModule\n \"circuit-json-to-fdm-component-box\": typeof CircuitJsonToFdmComponentBoxModule\n \"circuit-json-to-gerber\": typeof CircuitJsonToGerberModule\n \"circuit-json-to-gltf\": typeof CircuitJsonToGltfModule\n \"circuit-json-to-kicad\": typeof CircuitJsonToKicadModule\n \"circuit-json-to-lbrn\": typeof CircuitJsonToLbrnModule\n \"circuit-json-to-pnp-csv\": typeof CircuitJsonToPnpCsvModule\n \"circuit-json-to-readable-netlist\": typeof CircuitJsonToReadableNetlistModule\n \"circuit-json-to-simple-3d\": typeof CircuitJsonToSimple3dModule\n \"circuit-json-to-spice\": typeof CircuitJsonToSpiceModule\n \"circuit-json-to-step\": typeof CircuitJsonToStepModule\n \"circuit-json-to-tscircuit\": typeof CircuitJsonToTscircuitModule\n \"circuit-to-canvas\": typeof CircuitToCanvasModule\n \"circuit-to-svg\": typeof CircuitToSvgModule\n \"kicad-to-circuit-json\": typeof KicadToCircuitJsonModule\n}\n\nexport type StripVersion<TSpecifier extends string> =\n TSpecifier extends `${infer TBase}@${string}`\n ? TBase extends SupportedModuleName\n ? TBase\n : never\n : TSpecifier extends SupportedModuleName\n ? TSpecifier\n : never\n\nexport const getModuleName = (specifier: string): string => {\n const versionSeparatorIndex = specifier.indexOf(\"@\")\n return versionSeparatorIndex === -1\n ? specifier\n : specifier.slice(0, versionSeparatorIndex)\n}\n","import { registerDynamicModule } from \"./dynamic-module-registry\"\nimport {\n getModuleName,\n supportedModules,\n type StripVersion,\n type SupportedModuleMap,\n type SupportedModuleSpecifier,\n} from \"./supported-modules\"\n\nexport {\n getDynamicModuleRegistry,\n registerDynamicModule,\n} from \"./dynamic-module-registry\"\nexport type { DynamicModuleRegistry } from \"./dynamic-module-registry\"\nexport {\n getModuleName,\n supportedModules,\n} from \"./supported-modules\"\nexport type {\n StripVersion,\n SupportedModuleMap,\n SupportedModuleName,\n SupportedModuleSpecifier,\n} from \"./supported-modules\"\n\nconst supportedModuleSet = new Set<string>(supportedModules)\n\nexport const getImportUrl = (specifier: string): string => {\n assertSupportedModule(specifier)\n\n return getJscdnImportUrl(specifier)\n}\n\nexport const getImportUrls = (specifier: string): string[] => {\n assertSupportedModule(specifier)\n\n return [getJscdnImportUrl(specifier), `https://esm.run/${specifier}`]\n}\n\nfunction getJscdnImportUrl(specifier: string): string {\n const moduleName = getModuleName(specifier)\n const version =\n specifier.length === moduleName.length\n ? \"latest\"\n : specifier.slice(moduleName.length + 1)\n\n return `https://jscdn.tscircuit.com/${moduleName}/${version}/+esm`\n}\n\nfunction assertSupportedModule(specifier: string) {\n const moduleName = getModuleName(specifier)\n\n if (!supportedModuleSet.has(moduleName)) {\n throw new Error(`Unsupported module: ${specifier}`)\n }\n}\n\nasync function importer<TSpecifier extends SupportedModuleSpecifier>(\n specifier: TSpecifier,\n): Promise<SupportedModuleMap[StripVersion<TSpecifier>]>\nasync function importer(specifier: string): Promise<unknown>\nasync function importer(specifier: string): Promise<unknown> {\n let lastError: unknown\n\n for (const importUrl of getImportUrls(specifier)) {\n try {\n const mod = await import(/* @vite-ignore */ importUrl)\n return registerDynamicModule(getModuleName(specifier), mod)\n } catch (error) {\n lastError = error\n }\n }\n\n throw lastError\n}\n\nexport default importer\n"]}
package/package.json CHANGED
@@ -1,6 +1,10 @@
1
1
  {
2
2
  "name": "@tscircuit/internal-dynamic-import",
3
- "version": "0.0.14",
3
+ "version": "0.0.16",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "https://github.com/tscircuit/internal-dynamic-import"
7
+ },
4
8
  "description": "Type-safe dynamic imports for selected tscircuit packages via jscdn and fallback to jsDelivr",
5
9
  "type": "module",
6
10
  "main": "./dist/index.js",
@@ -32,6 +36,7 @@
32
36
  "circuit-json-to-bom-csv": "0.0.14",
33
37
  "circuit-json-to-bpc": "0.0.13",
34
38
  "circuit-json-to-connectivity-map": "0.0.23",
39
+ "circuit-json-to-fdm-component-box": "0.0.2",
35
40
  "circuit-json-to-gerber": "0.0.84",
36
41
  "circuit-json-to-gltf": "0.0.106",
37
42
  "circuit-json-to-kicad": "0.0.137",