@tscircuit/internal-dynamic-import 0.0.18 → 0.0.19
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,3 +1,4 @@
|
|
|
1
|
+
import { JscadOperation } from 'jscad-planner';
|
|
1
2
|
import * as circuit_json_to_gltf from 'circuit-json-to-gltf';
|
|
2
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
4
|
import { BpcGraph } from 'bpc-graph';
|
|
@@ -10,6 +11,104 @@ import { LightBurnProject } from 'lbrnts';
|
|
|
10
11
|
import { Box } from '@tscircuit/simple-3d-svg';
|
|
11
12
|
import { INode } from 'svgson';
|
|
12
13
|
|
|
14
|
+
type StepColorInput = number[] | string;
|
|
15
|
+
|
|
16
|
+
interface Geom3Like$1 {
|
|
17
|
+
polygons: Array<{
|
|
18
|
+
vertices: any[];
|
|
19
|
+
}>;
|
|
20
|
+
transforms?: number[];
|
|
21
|
+
color?: StepColorInput;
|
|
22
|
+
}
|
|
23
|
+
interface RenderedModel$1 {
|
|
24
|
+
geometries: Array<{
|
|
25
|
+
geom: Geom3Like$1;
|
|
26
|
+
color?: StepColorInput;
|
|
27
|
+
}>;
|
|
28
|
+
}
|
|
29
|
+
interface JscadToStepOptions {
|
|
30
|
+
/** Merge adjacent coplanar polygons into faces with inner bounds for holes. Default: true. */
|
|
31
|
+
mergeCoplanarFaces?: boolean;
|
|
32
|
+
}
|
|
33
|
+
declare function jscadToStep(operation: JscadOperation | RenderedModel$1, options?: JscadToStepOptions): string;
|
|
34
|
+
|
|
35
|
+
type JscadToStepModule_JscadToStepOptions = JscadToStepOptions;
|
|
36
|
+
declare const JscadToStepModule_jscadToStep: typeof jscadToStep;
|
|
37
|
+
declare namespace JscadToStepModule {
|
|
38
|
+
export { type JscadToStepModule_JscadToStepOptions as JscadToStepOptions, JscadToStepModule_jscadToStep as jscadToStep };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
type Point3$1 = readonly [number, number, number];
|
|
42
|
+
type ParasolidColorInput = string | readonly number[];
|
|
43
|
+
type ParasolidRgbColor = readonly [number, number, number];
|
|
44
|
+
/** Also accepts JSON-exported JSCAD vertices and typed coordinate arrays. */
|
|
45
|
+
type Geom3Vertex = ArrayLike<number> | {
|
|
46
|
+
readonly pos: ArrayLike<number>;
|
|
47
|
+
} | {
|
|
48
|
+
readonly position: ArrayLike<number>;
|
|
49
|
+
};
|
|
50
|
+
interface Geom3Like {
|
|
51
|
+
readonly polygons: readonly {
|
|
52
|
+
readonly vertices: readonly Geom3Vertex[];
|
|
53
|
+
readonly color?: ParasolidColorInput;
|
|
54
|
+
}[];
|
|
55
|
+
/** JSCAD's column-major, lazily applied affine matrix. */
|
|
56
|
+
readonly transforms?: ArrayLike<number>;
|
|
57
|
+
readonly color?: ParasolidColorInput;
|
|
58
|
+
}
|
|
59
|
+
type JscadGeometryInput = JscadOperation | Geom3Like;
|
|
60
|
+
/** The vanilla renderer can use either jscad-planner or @jscad/modeling. */
|
|
61
|
+
interface RenderedModel {
|
|
62
|
+
readonly geometries: readonly {
|
|
63
|
+
readonly geom: JscadGeometryInput;
|
|
64
|
+
readonly color?: ParasolidColorInput;
|
|
65
|
+
readonly name?: string;
|
|
66
|
+
}[];
|
|
67
|
+
}
|
|
68
|
+
type JscadToParasolidInput = JscadGeometryInput | readonly JscadGeometryInput[] | RenderedModel;
|
|
69
|
+
interface JscadToParasolidOptions {
|
|
70
|
+
/** Merge adjacent coplanar CAD faces. Default true; curves remain faceted. */
|
|
71
|
+
readonly mergeCoplanarFaces?: boolean;
|
|
72
|
+
/** Input length unit. X_T coordinates are always written in metres. */
|
|
73
|
+
readonly units?: "mm" | "m";
|
|
74
|
+
/** Reserved for future X_T name attributes; not transmitted yet. */
|
|
75
|
+
readonly name?: string;
|
|
76
|
+
}
|
|
77
|
+
interface ParasolidBodyInput {
|
|
78
|
+
readonly polygons: readonly (readonly Point3$1[])[];
|
|
79
|
+
readonly name?: string;
|
|
80
|
+
readonly color?: ParasolidRgbColor;
|
|
81
|
+
readonly faceColors?: readonly (ParasolidRgbColor | undefined)[];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Resolve JSCAD geometry into world-coordinate polygon bodies, in input units.
|
|
86
|
+
* No caller-owned geometry or matrices are mutated. RGB colors are preserved;
|
|
87
|
+
* alpha is not represented by the supported native color attributes.
|
|
88
|
+
* The converter validates planarity and closed-manifold topology before serialization.
|
|
89
|
+
*/
|
|
90
|
+
declare function jscadToParasolidBodies(input: JscadToParasolidInput, options?: JscadToParasolidOptions): ParasolidBodyInput[];
|
|
91
|
+
/**
|
|
92
|
+
* Convert JSCAD/modelprinter geometry to native Parasolid text (.x_t).
|
|
93
|
+
* Curves remain JSCAD's planar facets; this does not reconstruct analytic curves.
|
|
94
|
+
*/
|
|
95
|
+
declare function jscadToParasolid(input: JscadToParasolidInput, options?: JscadToParasolidOptions): string;
|
|
96
|
+
|
|
97
|
+
type JscadToParasolidModule_Geom3Like = Geom3Like;
|
|
98
|
+
type JscadToParasolidModule_Geom3Vertex = Geom3Vertex;
|
|
99
|
+
type JscadToParasolidModule_JscadGeometryInput = JscadGeometryInput;
|
|
100
|
+
type JscadToParasolidModule_JscadToParasolidInput = JscadToParasolidInput;
|
|
101
|
+
type JscadToParasolidModule_JscadToParasolidOptions = JscadToParasolidOptions;
|
|
102
|
+
type JscadToParasolidModule_ParasolidBodyInput = ParasolidBodyInput;
|
|
103
|
+
type JscadToParasolidModule_ParasolidColorInput = ParasolidColorInput;
|
|
104
|
+
type JscadToParasolidModule_ParasolidRgbColor = ParasolidRgbColor;
|
|
105
|
+
type JscadToParasolidModule_RenderedModel = RenderedModel;
|
|
106
|
+
declare const JscadToParasolidModule_jscadToParasolid: typeof jscadToParasolid;
|
|
107
|
+
declare const JscadToParasolidModule_jscadToParasolidBodies: typeof jscadToParasolidBodies;
|
|
108
|
+
declare namespace JscadToParasolidModule {
|
|
109
|
+
export { type JscadToParasolidModule_Geom3Like as Geom3Like, type JscadToParasolidModule_Geom3Vertex as Geom3Vertex, type JscadToParasolidModule_JscadGeometryInput as JscadGeometryInput, type JscadToParasolidModule_JscadToParasolidInput as JscadToParasolidInput, type JscadToParasolidModule_JscadToParasolidOptions as JscadToParasolidOptions, type JscadToParasolidModule_ParasolidBodyInput as ParasolidBodyInput, type JscadToParasolidModule_ParasolidColorInput as ParasolidColorInput, type JscadToParasolidModule_ParasolidRgbColor as ParasolidRgbColor, type Point3$1 as Point3, type JscadToParasolidModule_RenderedModel as RenderedModel, JscadToParasolidModule_jscadToParasolid as jscadToParasolid, JscadToParasolidModule_jscadToParasolidBodies as jscadToParasolidBodies };
|
|
110
|
+
}
|
|
111
|
+
|
|
13
112
|
type CameraOptions = {
|
|
14
113
|
camPos: readonly [number, number, number];
|
|
15
114
|
lookAt: readonly [number, number, number];
|
|
@@ -4397,10 +4496,12 @@ declare namespace SchematicPlacementAnalysisModule {
|
|
|
4397
4496
|
export { SchematicPlacementAnalysisModule_SchematicPlacementAnalysis as SchematicPlacementAnalysis, type SchematicPlacementAnalysisModule_SchematicPlacementIssueArtifact as SchematicPlacementIssueArtifact, SchematicPlacementAnalysisModule_analyzeSchematicPlacement as analyzeSchematicPlacement, SchematicPlacementAnalysisModule_createSchematicPlacementIssueArtifacts as createSchematicPlacementIssueArtifacts };
|
|
4398
4497
|
}
|
|
4399
4498
|
|
|
4400
|
-
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", "@tscircuit/circuit-json-schematic-placement-analysis"];
|
|
4499
|
+
declare const supportedModules: readonly ["jscad-to-step", "jscad-to-parasolid", "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", "@tscircuit/circuit-json-schematic-placement-analysis"];
|
|
4401
4500
|
type SupportedModuleName = (typeof supportedModules)[number];
|
|
4402
4501
|
type SupportedModuleSpecifier = SupportedModuleName | `${SupportedModuleName}@${string}`;
|
|
4403
4502
|
interface SupportedModuleMap {
|
|
4503
|
+
"jscad-to-step": typeof JscadToStepModule;
|
|
4504
|
+
"jscad-to-parasolid": typeof JscadToParasolidModule;
|
|
4404
4505
|
"circuit-json-to-3d-png": typeof CircuitJsonTo3dPngModule;
|
|
4405
4506
|
"circuit-json-to-bom-csv": typeof CircuitJsonToBomCsvModule;
|
|
4406
4507
|
"circuit-json-to-bpc": typeof CircuitJsonToBpcModule;
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../lib/dynamic-module-registry.ts","../lib/supported-modules.ts","../lib/import-urls.ts","../lib/create-importer.ts","../lib/dynamic-import-resolver.ts","../lib/index.ts"],"names":["importer"],"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;;;AChBO,IAAM,gBAAA,GAAmB;AAAA,EAC9B,wBAAA;AAAA,EACA,yBAAA;AAAA,EACA,qBAAA;AAAA,EACA,kCAAA;AAAA,EACA,mCAAA;AAAA,EACA,wBAAA;AAAA,EACA,sBAAA;AAAA,EACA,uBAAA;AAAA,EACA,sBAAA;AAAA,EACA,yBAAA;AAAA,EACA,kCAAA;AAAA,EACA,2BAAA;AAAA,EACA,uBAAA;AAAA,EACA,sBAAA;AAAA,EACA,2BAAA;AAAA,EACA,mBAAA;AAAA,EACA,gBAAA;AAAA,EACA,uBAAA;AAAA,EACA;AACF;AAsCO,IAAM,aAAA,GAAgB,CAAC,SAAA,KAA8B;AAE1D,EAAA,MAAM,wBAAwB,SAAA,CAAU,OAAA;AAAA,IACtC,GAAA;AAAA,IACA,SAAA,CAAU,UAAA,CAAW,GAAG,CAAA,GAAI,CAAA,GAAI;AAAA,GAClC;AACA,EAAA,OAAO,0BAA0B,EAAA,GAC7B,SAAA,GACA,SAAA,CAAU,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AAA,eAAeA,UAAS,SAAA,EAAqC;AAC3D,IAAA,MAAM,MAAA,GAAS,OAAA,CAAQ,GAAA,CAAI,SAAS,CAAA;AACpC,IAAA,IAAI,CAAC,MAAA,EAAQ;AACX,MAAA,IAAI,QAAA,EAAU,OAAO,QAAA,CAAS,SAAS,CAAA;AACvC,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA,kCAAA,EAAqC,SAAS,CAAA,CAAE,CAAA;AAAA,IAClE;AACA,IAAA,IAAI,CAAC,OAAA,CAAQ,GAAA,CAAI,SAAS,CAAA,EAAG;AAC3B,MAAA,MAAM,IAAA,GAAO,QAAQ,OAAA,EAAQ,CAC1B,KAAK,MAAM,CAAA,CACX,KAAA,CAAM,CAAC,KAAA,KAAU;AAChB,QAAA,OAAA,CAAQ,OAAO,SAAS,CAAA;AACxB,QAAA,MAAM,KAAA;AAAA,MACR,CAAC,CAAA;AACH,MAAA,OAAA,CAAQ,GAAA,CAAI,WAAW,IAAI,CAAA;AAAA,IAC7B;AACA,IAAA,OAAO,OAAA,CAAQ,IAAI,SAAS,CAAA;AAAA,EAC9B;AACA,EAAA,OAAOA,SAAAA;AACT;;;ACvBA,IAAM,aAAa,kCAAA,EAAmC;AAMtD,eAAe,SAAS,SAAA,EAAqC;AAC3D,EAAA,MAAM,WAAW,wBAAA,EAAyB;AAC1C,EAAA,OAAO,WAAW,QAAA,CAAS,SAAA,EAAW,UAAU,CAAA,GAAI,WAAW,SAAS,CAAA;AAC1E;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\"\nimport type * as SchematicPlacementAnalysisModule from \"./type-bundles/@tscircuit/circuit-json-schematic-placement-analysis\"\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 \"@tscircuit/circuit-json-schematic-placement-analysis\",\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 \"@tscircuit/circuit-json-schematic-placement-analysis\": typeof SchematicPlacementAnalysisModule\n}\n\nexport type StripVersion<TSpecifier extends string> =\n TSpecifier extends SupportedModuleName\n ? TSpecifier\n : {\n [TName in SupportedModuleName]: TSpecifier extends `${TName}@${string}`\n ? TName\n : never\n }[SupportedModuleName]\n\nexport const getModuleName = (specifier: string): string => {\n // A scoped name's leading @ is part of the name, not a version separator.\n const versionSeparatorIndex = specifier.indexOf(\n \"@\",\n specifier.startsWith(\"@\") ? 1 : 0,\n )\n return versionSeparatorIndex === -1\n ? specifier\n : specifier.slice(0, versionSeparatorIndex)\n}\n","import { getModuleName, supportedModules } from \"./supported-modules\"\n\ndeclare global {\n interface Window {\n TSCIRCUIT_JSCDN_BASE_URL?: string\n }\n}\n\nconst defaultBaseUrl = \"https://jscdn.tscircuit.com\"\n\nfunction getConfiguredBaseUrl(): string | undefined {\n return typeof window !== \"undefined\"\n ? window.TSCIRCUIT_JSCDN_BASE_URL || undefined\n : undefined\n}\n\nconst supportedModuleSet = new Set<string>(supportedModules)\nconst browserEntrypoints = new Map<string, string>([\n [\"@tscircuit/circuit-json-schematic-placement-analysis\", \"dist/browser.js\"],\n])\n\nfunction assertSupportedModule(specifier: string) {\n if (!supportedModuleSet.has(getModuleName(specifier))) {\n throw new Error(`Unsupported module: ${specifier}`)\n }\n}\n\nexport const getImportUrl = (specifier: string): string => {\n assertSupportedModule(specifier)\n const moduleName = getModuleName(specifier)\n const version =\n specifier.length === moduleName.length\n ? \"latest\"\n : specifier.slice(moduleName.length + 1)\n const entrypoint = browserEntrypoints.get(moduleName) ?? \"+esm\"\n const configuredBaseUrl = getConfiguredBaseUrl()\n const baseUrl = (configuredBaseUrl ?? defaultBaseUrl).replace(/\\/+$/, \"\")\n const url = `${baseUrl}/${moduleName}/${version}/${entrypoint}`\n return configuredBaseUrl ? new URL(url, window.location.href).href : url\n}\n\nexport const getImportUrls = (specifier: string): string[] => {\n const url = getImportUrl(specifier)\n return getConfiguredBaseUrl() ? [url] : [url, `https://esm.run/${specifier}`]\n}\n","import { getDynamicModuleRegistry } from \"./dynamic-module-registry\"\nimport { getImportUrls } from \"./import-urls\"\n\n/** Internal dependency seam lets tests observe CDN attempts without a network. */\nexport function createDefaultDynamicImportResolver(\n importModule: (url: string) => Promise<unknown> = (url) =>\n import(/* @vite-ignore */ /* webpackIgnore: true */ url),\n) {\n return async (specifier: string): Promise<unknown> => {\n const modules = getDynamicModuleRegistry()\n if (Object.hasOwn(modules, specifier)) return modules[specifier]\n\n let lastError: unknown\n for (const importUrl of getImportUrls(specifier)) {\n try {\n const mod = await importModule(importUrl)\n // A versioned module never silently satisfies a different version or\n // an unversioned request for latest.\n modules[specifier] = mod\n return mod\n } catch (error) {\n lastError = error\n }\n }\n throw lastError\n }\n}\n","export type DynamicModuleResolver = (\n specifier: string,\n) => unknown | PromiseLike<unknown>\n\n/** A custom resolver can delegate to the default registry/CDN resolver. */\nexport type DynamicImportResolver = (\n specifier: string,\n defaultResolver: DynamicModuleResolver,\n) => unknown | PromiseLike<unknown>\n\ndeclare global {\n var tscircuitDynamicImportResolver: DynamicImportResolver | undefined\n}\n\nexport const getDynamicImportResolver = () =>\n globalThis.tscircuitDynamicImportResolver\n\n/** Configure before requesting modules, separately in each JavaScript realm. */\nexport function setDynamicImportResolver(\n resolver: DynamicImportResolver | undefined,\n): void {\n globalThis.tscircuitDynamicImportResolver = resolver\n}\n\n/**\n * Create an importer from exact specifier keys and lazy module loaders.\n * Missing keys reject unless a fallback is supplied; loader failures retry\n * through the same loader on the next request.\n */\nexport function createDynamicImporter<\n TLoaders extends Record<string, () => unknown | PromiseLike<unknown>>,\n>(loaders: TLoaders, fallback?: DynamicModuleResolver) {\n const entries = new Map(Object.entries(loaders))\n const pending = new Map<string, Promise<unknown>>()\n\n function importer<TSpecifier extends keyof TLoaders & string>(\n specifier: TSpecifier,\n ): Promise<Awaited<ReturnType<TLoaders[TSpecifier]>>>\n function importer(specifier: string): Promise<unknown>\n async function importer(specifier: string): Promise<unknown> {\n const loader = entries.get(specifier)\n if (!loader) {\n if (fallback) return fallback(specifier)\n throw new Error(`No bundled module registered for: ${specifier}`)\n }\n if (!pending.has(specifier)) {\n const load = Promise.resolve()\n .then(loader)\n .catch((error) => {\n pending.delete(specifier)\n throw error\n })\n pending.set(specifier, load)\n }\n return pending.get(specifier)!\n }\n return importer\n}\n","import { createDefaultDynamicImportResolver } from \"./create-importer\"\nimport { getDynamicImportResolver } from \"./dynamic-import-resolver\"\nimport {\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 setDynamicImportResolver,\n createDynamicImporter,\n} from \"./dynamic-import-resolver\"\nexport type {\n DynamicImportResolver,\n DynamicModuleResolver,\n} from \"./dynamic-import-resolver\"\nexport {\n getModuleName,\n supportedModules,\n} from \"./supported-modules\"\nexport type {\n StripVersion,\n SupportedModuleMap,\n SupportedModuleName,\n SupportedModuleSpecifier,\n} from \"./supported-modules\"\n\nexport { getImportUrl, getImportUrls } from \"./import-urls\"\n\nconst loadModule = createDefaultDynamicImportResolver()\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 const resolver = getDynamicImportResolver()\n return resolver ? resolver(specifier, loadModule) : loadModule(specifier)\n}\n\nexport default importer\n"]}
|
|
1
|
+
{"version":3,"sources":["../lib/dynamic-module-registry.ts","../lib/supported-modules.ts","../lib/import-urls.ts","../lib/create-importer.ts","../lib/dynamic-import-resolver.ts","../lib/index.ts"],"names":["importer"],"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;;;ACdO,IAAM,gBAAA,GAAmB;AAAA,EAC9B,eAAA;AAAA,EACA,oBAAA;AAAA,EACA,wBAAA;AAAA,EACA,yBAAA;AAAA,EACA,qBAAA;AAAA,EACA,kCAAA;AAAA,EACA,mCAAA;AAAA,EACA,wBAAA;AAAA,EACA,sBAAA;AAAA,EACA,uBAAA;AAAA,EACA,sBAAA;AAAA,EACA,yBAAA;AAAA,EACA,kCAAA;AAAA,EACA,2BAAA;AAAA,EACA,uBAAA;AAAA,EACA,sBAAA;AAAA,EACA,2BAAA;AAAA,EACA,mBAAA;AAAA,EACA,gBAAA;AAAA,EACA,uBAAA;AAAA,EACA;AACF;AAwCO,IAAM,aAAA,GAAgB,CAAC,SAAA,KAA8B;AAE1D,EAAA,MAAM,wBAAwB,SAAA,CAAU,OAAA;AAAA,IACtC,GAAA;AAAA,IACA,SAAA,CAAU,UAAA,CAAW,GAAG,CAAA,GAAI,CAAA,GAAI;AAAA,GAClC;AACA,EAAA,OAAO,0BAA0B,EAAA,GAC7B,SAAA,GACA,SAAA,CAAU,KAAA,CAAM,GAAG,qBAAqB,CAAA;AAC9C;;;ACrFA,IAAM,cAAA,GAAiB,6BAAA;AAEvB,SAAS,oBAAA,GAA2C;AAClD,EAAA,OAAO,OAAO,MAAA,KAAW,WAAA,GACrB,M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,QAAA,EAAU,OAAO,QAAA,CAAS,SAAS,CAAA;AACvC,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA,kCAAA,EAAqC,SAAS,CAAA,CAAE,CAAA;AAAA,IAClE;AACA,IAAA,IAAI,CAAC,OAAA,CAAQ,GAAA,CAAI,SAAS,CAAA,EAAG;AAC3B,MAAA,MAAM,IAAA,GAAO,QAAQ,OAAA,EAAQ,CAC1B,KAAK,MAAM,CAAA,CACX,KAAA,CAAM,CAAC,KAAA,KAAU;AAChB,QAAA,OAAA,CAAQ,OAAO,SAAS,CAAA;AACxB,QAAA,MAAM,KAAA;AAAA,MACR,CAAC,CAAA;AACH,MAAA,OAAA,CAAQ,GAAA,CAAI,WAAW,IAAI,CAAA;AAAA,IAC7B;AACA,IAAA,OAAO,OAAA,CAAQ,IAAI,SAAS,CAAA;AAAA,EAC9B;AACA,EAAA,OAAOA,SAAAA;AACT;;;ACvBA,IAAM,aAAa,kCAAA,EAAmC;AAMtD,eAAe,SAAS,SAAA,EAAqC;AAC3D,EAAA,MAAM,WAAW,wBAAA,EAAyB;AAC1C,EAAA,OAAO,WAAW,QAAA,CAAS,SAAA,EAAW,UAAU,CAAA,GAAI,WAAW,SAAS,CAAA;AAC1E;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 JscadToStepModule from \"./type-bundles/jscad-to-step\"\nimport type * as JscadToParasolidModule from \"./type-bundles/jscad-to-parasolid\"\nimport 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\"\nimport type * as SchematicPlacementAnalysisModule from \"./type-bundles/@tscircuit/circuit-json-schematic-placement-analysis\"\n\nexport const supportedModules = [\n \"jscad-to-step\",\n \"jscad-to-parasolid\",\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 \"@tscircuit/circuit-json-schematic-placement-analysis\",\n] as const\n\nexport type SupportedModuleName = (typeof supportedModules)[number]\nexport type SupportedModuleSpecifier =\n | SupportedModuleName\n | `${SupportedModuleName}@${string}`\n\nexport interface SupportedModuleMap {\n \"jscad-to-step\": typeof JscadToStepModule\n \"jscad-to-parasolid\": typeof JscadToParasolidModule\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 \"@tscircuit/circuit-json-schematic-placement-analysis\": typeof SchematicPlacementAnalysisModule\n}\n\nexport type StripVersion<TSpecifier extends string> =\n TSpecifier extends SupportedModuleName\n ? TSpecifier\n : {\n [TName in SupportedModuleName]: TSpecifier extends `${TName}@${string}`\n ? TName\n : never\n }[SupportedModuleName]\n\nexport const getModuleName = (specifier: string): string => {\n // A scoped name's leading @ is part of the name, not a version separator.\n const versionSeparatorIndex = specifier.indexOf(\n \"@\",\n specifier.startsWith(\"@\") ? 1 : 0,\n )\n return versionSeparatorIndex === -1\n ? specifier\n : specifier.slice(0, versionSeparatorIndex)\n}\n","import { getModuleName, supportedModules } from \"./supported-modules\"\n\ndeclare global {\n interface Window {\n TSCIRCUIT_JSCDN_BASE_URL?: string\n }\n}\n\nconst defaultBaseUrl = \"https://jscdn.tscircuit.com\"\n\nfunction getConfiguredBaseUrl(): string | undefined {\n return typeof window !== \"undefined\"\n ? window.TSCIRCUIT_JSCDN_BASE_URL || undefined\n : undefined\n}\n\nconst supportedModuleSet = new Set<string>(supportedModules)\nconst browserEntrypoints = new Map<string, string>([\n [\"@tscircuit/circuit-json-schematic-placement-analysis\", \"dist/browser.js\"],\n])\n\nfunction assertSupportedModule(specifier: string) {\n if (!supportedModuleSet.has(getModuleName(specifier))) {\n throw new Error(`Unsupported module: ${specifier}`)\n }\n}\n\nexport const getImportUrl = (specifier: string): string => {\n assertSupportedModule(specifier)\n const moduleName = getModuleName(specifier)\n const version =\n specifier.length === moduleName.length\n ? \"latest\"\n : specifier.slice(moduleName.length + 1)\n const entrypoint = browserEntrypoints.get(moduleName) ?? \"+esm\"\n const configuredBaseUrl = getConfiguredBaseUrl()\n const baseUrl = (configuredBaseUrl ?? defaultBaseUrl).replace(/\\/+$/, \"\")\n const url = `${baseUrl}/${moduleName}/${version}/${entrypoint}`\n return configuredBaseUrl ? new URL(url, window.location.href).href : url\n}\n\nexport const getImportUrls = (specifier: string): string[] => {\n const url = getImportUrl(specifier)\n return getConfiguredBaseUrl() ? [url] : [url, `https://esm.run/${specifier}`]\n}\n","import { getDynamicModuleRegistry } from \"./dynamic-module-registry\"\nimport { getImportUrls } from \"./import-urls\"\n\n/** Internal dependency seam lets tests observe CDN attempts without a network. */\nexport function createDefaultDynamicImportResolver(\n importModule: (url: string) => Promise<unknown> = (url) =>\n import(/* @vite-ignore */ /* webpackIgnore: true */ url),\n) {\n return async (specifier: string): Promise<unknown> => {\n const modules = getDynamicModuleRegistry()\n if (Object.hasOwn(modules, specifier)) return modules[specifier]\n\n let lastError: unknown\n for (const importUrl of getImportUrls(specifier)) {\n try {\n const mod = await importModule(importUrl)\n // A versioned module never silently satisfies a different version or\n // an unversioned request for latest.\n modules[specifier] = mod\n return mod\n } catch (error) {\n lastError = error\n }\n }\n throw lastError\n }\n}\n","export type DynamicModuleResolver = (\n specifier: string,\n) => unknown | PromiseLike<unknown>\n\n/** A custom resolver can delegate to the default registry/CDN resolver. */\nexport type DynamicImportResolver = (\n specifier: string,\n defaultResolver: DynamicModuleResolver,\n) => unknown | PromiseLike<unknown>\n\ndeclare global {\n var tscircuitDynamicImportResolver: DynamicImportResolver | undefined\n}\n\nexport const getDynamicImportResolver = () =>\n globalThis.tscircuitDynamicImportResolver\n\n/** Configure before requesting modules, separately in each JavaScript realm. */\nexport function setDynamicImportResolver(\n resolver: DynamicImportResolver | undefined,\n): void {\n globalThis.tscircuitDynamicImportResolver = resolver\n}\n\n/**\n * Create an importer from exact specifier keys and lazy module loaders.\n * Missing keys reject unless a fallback is supplied; loader failures retry\n * through the same loader on the next request.\n */\nexport function createDynamicImporter<\n TLoaders extends Record<string, () => unknown | PromiseLike<unknown>>,\n>(loaders: TLoaders, fallback?: DynamicModuleResolver) {\n const entries = new Map(Object.entries(loaders))\n const pending = new Map<string, Promise<unknown>>()\n\n function importer<TSpecifier extends keyof TLoaders & string>(\n specifier: TSpecifier,\n ): Promise<Awaited<ReturnType<TLoaders[TSpecifier]>>>\n function importer(specifier: string): Promise<unknown>\n async function importer(specifier: string): Promise<unknown> {\n const loader = entries.get(specifier)\n if (!loader) {\n if (fallback) return fallback(specifier)\n throw new Error(`No bundled module registered for: ${specifier}`)\n }\n if (!pending.has(specifier)) {\n const load = Promise.resolve()\n .then(loader)\n .catch((error) => {\n pending.delete(specifier)\n throw error\n })\n pending.set(specifier, load)\n }\n return pending.get(specifier)!\n }\n return importer\n}\n","import { createDefaultDynamicImportResolver } from \"./create-importer\"\nimport { getDynamicImportResolver } from \"./dynamic-import-resolver\"\nimport {\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 setDynamicImportResolver,\n createDynamicImporter,\n} from \"./dynamic-import-resolver\"\nexport type {\n DynamicImportResolver,\n DynamicModuleResolver,\n} from \"./dynamic-import-resolver\"\nexport {\n getModuleName,\n supportedModules,\n} from \"./supported-modules\"\nexport type {\n StripVersion,\n SupportedModuleMap,\n SupportedModuleName,\n SupportedModuleSpecifier,\n} from \"./supported-modules\"\n\nexport { getImportUrl, getImportUrls } from \"./import-urls\"\n\nconst loadModule = createDefaultDynamicImportResolver()\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 const resolver = getDynamicImportResolver()\n return resolver ? resolver(specifier, loadModule) : loadModule(specifier)\n}\n\nexport default importer\n"]}
|
package/lib/supported-modules.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type * as JscadToStepModule from "./type-bundles/jscad-to-step"
|
|
2
|
+
import type * as JscadToParasolidModule from "./type-bundles/jscad-to-parasolid"
|
|
1
3
|
import type * as CircuitJsonTo3dPngModule from "./type-bundles/circuit-json-to-3d-png"
|
|
2
4
|
import type * as CircuitJsonToBomCsvModule from "./type-bundles/circuit-json-to-bom-csv"
|
|
3
5
|
import type * as CircuitJsonToBpcModule from "./type-bundles/circuit-json-to-bpc"
|
|
@@ -19,6 +21,8 @@ import type * as KicadToCircuitJsonModule from "./type-bundles/kicad-to-circuit-
|
|
|
19
21
|
import type * as SchematicPlacementAnalysisModule from "./type-bundles/@tscircuit/circuit-json-schematic-placement-analysis"
|
|
20
22
|
|
|
21
23
|
export const supportedModules = [
|
|
24
|
+
"jscad-to-step",
|
|
25
|
+
"jscad-to-parasolid",
|
|
22
26
|
"circuit-json-to-3d-png",
|
|
23
27
|
"circuit-json-to-bom-csv",
|
|
24
28
|
"circuit-json-to-bpc",
|
|
@@ -46,6 +50,8 @@ export type SupportedModuleSpecifier =
|
|
|
46
50
|
| `${SupportedModuleName}@${string}`
|
|
47
51
|
|
|
48
52
|
export interface SupportedModuleMap {
|
|
53
|
+
"jscad-to-step": typeof JscadToStepModule
|
|
54
|
+
"jscad-to-parasolid": typeof JscadToParasolidModule
|
|
49
55
|
"circuit-json-to-3d-png": typeof CircuitJsonTo3dPngModule
|
|
50
56
|
"circuit-json-to-bom-csv": typeof CircuitJsonToBomCsvModule
|
|
51
57
|
"circuit-json-to-bpc": typeof CircuitJsonToBpcModule
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { JscadOperation } from 'jscad-planner';
|
|
2
|
+
|
|
3
|
+
type Point3 = readonly [number, number, number];
|
|
4
|
+
type ParasolidColorInput = string | readonly number[];
|
|
5
|
+
type ParasolidRgbColor = readonly [number, number, number];
|
|
6
|
+
/** Also accepts JSON-exported JSCAD vertices and typed coordinate arrays. */
|
|
7
|
+
type Geom3Vertex = ArrayLike<number> | {
|
|
8
|
+
readonly pos: ArrayLike<number>;
|
|
9
|
+
} | {
|
|
10
|
+
readonly position: ArrayLike<number>;
|
|
11
|
+
};
|
|
12
|
+
interface Geom3Like {
|
|
13
|
+
readonly polygons: readonly {
|
|
14
|
+
readonly vertices: readonly Geom3Vertex[];
|
|
15
|
+
readonly color?: ParasolidColorInput;
|
|
16
|
+
}[];
|
|
17
|
+
/** JSCAD's column-major, lazily applied affine matrix. */
|
|
18
|
+
readonly transforms?: ArrayLike<number>;
|
|
19
|
+
readonly color?: ParasolidColorInput;
|
|
20
|
+
}
|
|
21
|
+
type JscadGeometryInput = JscadOperation | Geom3Like;
|
|
22
|
+
/** The vanilla renderer can use either jscad-planner or @jscad/modeling. */
|
|
23
|
+
interface RenderedModel {
|
|
24
|
+
readonly geometries: readonly {
|
|
25
|
+
readonly geom: JscadGeometryInput;
|
|
26
|
+
readonly color?: ParasolidColorInput;
|
|
27
|
+
readonly name?: string;
|
|
28
|
+
}[];
|
|
29
|
+
}
|
|
30
|
+
type JscadToParasolidInput = JscadGeometryInput | readonly JscadGeometryInput[] | RenderedModel;
|
|
31
|
+
interface JscadToParasolidOptions {
|
|
32
|
+
/** Merge adjacent coplanar CAD faces. Default true; curves remain faceted. */
|
|
33
|
+
readonly mergeCoplanarFaces?: boolean;
|
|
34
|
+
/** Input length unit. X_T coordinates are always written in metres. */
|
|
35
|
+
readonly units?: "mm" | "m";
|
|
36
|
+
/** Reserved for future X_T name attributes; not transmitted yet. */
|
|
37
|
+
readonly name?: string;
|
|
38
|
+
}
|
|
39
|
+
interface ParasolidBodyInput {
|
|
40
|
+
readonly polygons: readonly (readonly Point3[])[];
|
|
41
|
+
readonly name?: string;
|
|
42
|
+
readonly color?: ParasolidRgbColor;
|
|
43
|
+
readonly faceColors?: readonly (ParasolidRgbColor | undefined)[];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Resolve JSCAD geometry into world-coordinate polygon bodies, in input units.
|
|
48
|
+
* No caller-owned geometry or matrices are mutated. RGB colors are preserved;
|
|
49
|
+
* alpha is not represented by the supported native color attributes.
|
|
50
|
+
* The converter validates planarity and closed-manifold topology before serialization.
|
|
51
|
+
*/
|
|
52
|
+
declare function jscadToParasolidBodies(input: JscadToParasolidInput, options?: JscadToParasolidOptions): ParasolidBodyInput[];
|
|
53
|
+
/**
|
|
54
|
+
* Convert JSCAD/modelprinter geometry to native Parasolid text (.x_t).
|
|
55
|
+
* Curves remain JSCAD's planar facets; this does not reconstruct analytic curves.
|
|
56
|
+
*/
|
|
57
|
+
declare function jscadToParasolid(input: JscadToParasolidInput, options?: JscadToParasolidOptions): string;
|
|
58
|
+
|
|
59
|
+
export { type Geom3Like, type Geom3Vertex, type JscadGeometryInput, type JscadToParasolidInput, type JscadToParasolidOptions, type ParasolidBodyInput, type ParasolidColorInput, type ParasolidRgbColor, type Point3, type RenderedModel, jscadToParasolid, jscadToParasolidBodies };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { JscadOperation } from 'jscad-planner';
|
|
2
|
+
|
|
3
|
+
type StepColorInput = number[] | string;
|
|
4
|
+
|
|
5
|
+
interface Geom3Like {
|
|
6
|
+
polygons: Array<{
|
|
7
|
+
vertices: any[];
|
|
8
|
+
}>;
|
|
9
|
+
transforms?: number[];
|
|
10
|
+
color?: StepColorInput;
|
|
11
|
+
}
|
|
12
|
+
interface RenderedModel {
|
|
13
|
+
geometries: Array<{
|
|
14
|
+
geom: Geom3Like;
|
|
15
|
+
color?: StepColorInput;
|
|
16
|
+
}>;
|
|
17
|
+
}
|
|
18
|
+
interface JscadToStepOptions {
|
|
19
|
+
/** Merge adjacent coplanar polygons into faces with inner bounds for holes. Default: true. */
|
|
20
|
+
mergeCoplanarFaces?: boolean;
|
|
21
|
+
}
|
|
22
|
+
declare function jscadToStep(operation: JscadOperation | RenderedModel, options?: JscadToStepOptions): string;
|
|
23
|
+
|
|
24
|
+
export { type JscadToStepOptions, jscadToStep };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tscircuit/internal-dynamic-import",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.19",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/tscircuit/internal-dynamic-import"
|
|
@@ -58,6 +58,8 @@
|
|
|
58
58
|
"kicad-to-circuit-json": "0.0.98",
|
|
59
59
|
"tsup": "8.5.1",
|
|
60
60
|
"typescript": "5.9.3",
|
|
61
|
-
"@tscircuit/circuit-json-schematic-placement-analysis": "https://jscdn.tscircuit.com/@tscircuit/circuit-json-schematic-placement-analysis/0.0.46.tgz"
|
|
61
|
+
"@tscircuit/circuit-json-schematic-placement-analysis": "https://jscdn.tscircuit.com/@tscircuit/circuit-json-schematic-placement-analysis/0.0.46.tgz",
|
|
62
|
+
"jscad-to-step": "0.0.11",
|
|
63
|
+
"jscad-to-parasolid": "0.0.4"
|
|
62
64
|
}
|
|
63
65
|
}
|