@tscircuit/internal-dynamic-import 0.0.6 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/index.d.ts +426 -16
- package/dist/index.js +30 -9
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -19,4 +19,6 @@ async function main() {
|
|
|
19
19
|
}
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
Runtime imports
|
|
22
|
+
Runtime imports try jscdn first through `https://jscdn.tscircuit.com/.../+esm`
|
|
23
|
+
and fall back to `https://esm.run/...` if the jscdn import fails. Omitting a
|
|
24
|
+
version uses `latest`; adding `@...` preserves the requested version/tag.
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { AnyCircuitElement, SourceComponentBase, PcbComponent, CircuitJson, Sche
|
|
|
2
2
|
import { BpcGraph } from 'bpc-graph';
|
|
3
3
|
import { z, AnyZodObject } from 'zod';
|
|
4
4
|
import { CircuitJsonUtilObjects, cju } from '@tscircuit/circuit-json-util';
|
|
5
|
-
import { KicadSch, KicadPcb, SchematicSymbol } from 'kicadts';
|
|
5
|
+
import { KicadSch, KicadPcb, SchematicSymbol, KicadSym } from 'kicadts';
|
|
6
6
|
import { Matrix } from 'transformation-matrix';
|
|
7
7
|
import { LightBurnProject } from 'lbrnts';
|
|
8
8
|
import { Box } from '@tscircuit/simple-3d-svg';
|
|
@@ -1116,7 +1116,7 @@ interface KicadLibraryOutput {
|
|
|
1116
1116
|
symLibTableString: string;
|
|
1117
1117
|
model3dSourcePaths: string[];
|
|
1118
1118
|
}
|
|
1119
|
-
interface ConverterContext {
|
|
1119
|
+
interface ConverterContext$1 {
|
|
1120
1120
|
db: CircuitJsonUtilObjects;
|
|
1121
1121
|
circuitJson: CircuitJson;
|
|
1122
1122
|
kicadSch?: KicadSch;
|
|
@@ -1152,13 +1152,13 @@ interface ConverterContext {
|
|
|
1152
1152
|
footprintEntries?: FootprintEntry[];
|
|
1153
1153
|
libraryOutput?: KicadLibraryOutput;
|
|
1154
1154
|
}
|
|
1155
|
-
declare abstract class ConverterStage<Input, Output> {
|
|
1155
|
+
declare abstract class ConverterStage$1<Input, Output> {
|
|
1156
1156
|
MAX_ITERATIONS: number;
|
|
1157
1157
|
iteration: number;
|
|
1158
1158
|
finished: boolean;
|
|
1159
1159
|
input: Input;
|
|
1160
|
-
ctx: ConverterContext;
|
|
1161
|
-
constructor(input: Input, ctx: ConverterContext);
|
|
1160
|
+
ctx: ConverterContext$1;
|
|
1161
|
+
constructor(input: Input, ctx: ConverterContext$1);
|
|
1162
1162
|
step(): void;
|
|
1163
1163
|
_step(): void;
|
|
1164
1164
|
runUntilFinished(): void;
|
|
@@ -1166,11 +1166,11 @@ declare abstract class ConverterStage<Input, Output> {
|
|
|
1166
1166
|
}
|
|
1167
1167
|
|
|
1168
1168
|
declare class CircuitJsonToKicadSchConverter {
|
|
1169
|
-
ctx: ConverterContext;
|
|
1170
|
-
pipeline: ConverterStage<CircuitJson, KicadSch>[];
|
|
1169
|
+
ctx: ConverterContext$1;
|
|
1170
|
+
pipeline: ConverterStage$1<CircuitJson, KicadSch>[];
|
|
1171
1171
|
currentStageIndex: number;
|
|
1172
1172
|
finished: boolean;
|
|
1173
|
-
get currentStage(): ConverterStage<CircuitJson, KicadSch> | undefined;
|
|
1173
|
+
get currentStage(): ConverterStage$1<CircuitJson, KicadSch> | undefined;
|
|
1174
1174
|
constructor(circuitJson: CircuitJson);
|
|
1175
1175
|
step(): void;
|
|
1176
1176
|
runUntilFinished(): void;
|
|
@@ -1195,11 +1195,11 @@ interface CircuitJsonToKicadPcbOptions {
|
|
|
1195
1195
|
projectName?: string;
|
|
1196
1196
|
}
|
|
1197
1197
|
declare class CircuitJsonToKicadPcbConverter {
|
|
1198
|
-
ctx: ConverterContext;
|
|
1199
|
-
pipeline: ConverterStage<CircuitJson, KicadPcb>[];
|
|
1198
|
+
ctx: ConverterContext$1;
|
|
1199
|
+
pipeline: ConverterStage$1<CircuitJson, KicadPcb>[];
|
|
1200
1200
|
currentStageIndex: number;
|
|
1201
1201
|
finished: boolean;
|
|
1202
|
-
get currentStage(): ConverterStage<CircuitJson, KicadPcb> | undefined;
|
|
1202
|
+
get currentStage(): ConverterStage$1<CircuitJson, KicadPcb> | undefined;
|
|
1203
1203
|
constructor(circuitJson: CircuitJson, options?: CircuitJsonToKicadPcbOptions);
|
|
1204
1204
|
step(): void;
|
|
1205
1205
|
runUntilFinished(): void;
|
|
@@ -1362,11 +1362,11 @@ interface CircuitJsonToKicadLibraryOptions {
|
|
|
1362
1362
|
}
|
|
1363
1363
|
|
|
1364
1364
|
declare class CircuitJsonToKicadLibraryConverter {
|
|
1365
|
-
ctx: ConverterContext;
|
|
1366
|
-
pipeline: ConverterStage<CircuitJson, KicadLibraryOutput>[];
|
|
1365
|
+
ctx: ConverterContext$1;
|
|
1366
|
+
pipeline: ConverterStage$1<CircuitJson, KicadLibraryOutput>[];
|
|
1367
1367
|
currentStageIndex: number;
|
|
1368
1368
|
finished: boolean;
|
|
1369
|
-
get currentStage(): ConverterStage<CircuitJson, KicadLibraryOutput> | undefined;
|
|
1369
|
+
get currentStage(): ConverterStage$1<CircuitJson, KicadLibraryOutput> | undefined;
|
|
1370
1370
|
constructor(circuitJson: CircuitJson, options?: CircuitJsonToKicadLibraryOptions);
|
|
1371
1371
|
step(): void;
|
|
1372
1372
|
runUntilFinished(): void;
|
|
@@ -3054,7 +3054,415 @@ declare namespace CircuitToSvgModule {
|
|
|
3054
3054
|
export { type CircuitToSvgModule_AssemblySvgContext as AssemblySvgContext, CircuitToSvgModule_CIRCUIT_TO_SVG_VERSION as CIRCUIT_TO_SVG_VERSION, type CircuitToSvgModule_CircuitJsonWithSimulation as CircuitJsonWithSimulation, type CircuitToSvgModule_ColorMap as ColorMap, type CircuitToSvgModule_ColorOverrides as ColorOverrides, type CircuitToSvgModule_PcbColorMap as PcbColorMap, type CircuitToSvgModule_PcbColorOverrides as PcbColorOverrides, type CircuitToSvgModule_PcbContext as PcbContext, type CircuitToSvgModule_PcbSvgOptions as PcbSvgOptions, type CircuitToSvgModule_PinoutLabel as PinoutLabel, type CircuitToSvgModule_PinoutSvgContext as PinoutSvgContext, CircuitToSvgModule_circuitJsonToPcbSvg as circuitJsonToPcbSvg, CircuitToSvgModule_circuitJsonToSchematicSvg as circuitJsonToSchematicSvg, CircuitToSvgModule_convertCircuitJsonToAssemblySvg as convertCircuitJsonToAssemblySvg, CircuitToSvgModule_convertCircuitJsonToPcbSvg as convertCircuitJsonToPcbSvg, CircuitToSvgModule_convertCircuitJsonToPinoutSvg as convertCircuitJsonToPinoutSvg, CircuitToSvgModule_convertCircuitJsonToSchematicSimulationSvg as convertCircuitJsonToSchematicSimulationSvg, CircuitToSvgModule_convertCircuitJsonToSchematicSvg as convertCircuitJsonToSchematicSvg, CircuitToSvgModule_convertCircuitJsonToSimulationGraphSvg as convertCircuitJsonToSimulationGraphSvg, CircuitToSvgModule_convertCircuitJsonToSolderPasteMask as convertCircuitJsonToSolderPasteMask, CircuitToSvgModule_createErrorTextOverlay as createErrorTextOverlay, CircuitToSvgModule_createSvgObjectsForSchComponentPortHovers as createSvgObjectsForSchComponentPortHovers, CircuitToSvgModule_getSoftwareUsedString as getSoftwareUsedString, CircuitToSvgModule_isSimulationExperiment as isSimulationExperiment, CircuitToSvgModule_isSimulationTransientVoltageGraph as isSimulationTransientVoltageGraph, CircuitToSvgModule_isSimulationVoltageProbe as isSimulationVoltageProbe };
|
|
3055
3055
|
}
|
|
3056
3056
|
|
|
3057
|
-
|
|
3057
|
+
interface ConverterContext {
|
|
3058
|
+
db: CircuitJsonUtilObjects;
|
|
3059
|
+
kicadPcb?: KicadPcb;
|
|
3060
|
+
kicadSch?: KicadSch;
|
|
3061
|
+
kicadSymbolLib?: KicadSym;
|
|
3062
|
+
k2cMatSch?: Matrix;
|
|
3063
|
+
k2cMatPcb?: Matrix;
|
|
3064
|
+
netNumToName?: Map<number, string>;
|
|
3065
|
+
netNumToSourceNetId?: Map<number, string>;
|
|
3066
|
+
netNumToSourcePortIds?: Map<number, string[]>;
|
|
3067
|
+
footprintUuidToComponentId?: Map<string, string>;
|
|
3068
|
+
footprintUuidToSourceComponentId?: Map<string, string>;
|
|
3069
|
+
symbolUuidToComponentId?: Map<string, string>;
|
|
3070
|
+
warnings?: string[];
|
|
3071
|
+
stats?: {
|
|
3072
|
+
components?: number;
|
|
3073
|
+
pads?: number;
|
|
3074
|
+
vias?: number;
|
|
3075
|
+
traces?: number;
|
|
3076
|
+
labels?: number;
|
|
3077
|
+
copper_pours?: number;
|
|
3078
|
+
};
|
|
3079
|
+
}
|
|
3080
|
+
/**
|
|
3081
|
+
* Base class for converter stages that process KiCad data into Circuit JSON.
|
|
3082
|
+
* Each stage performs a specific transformation step and can run iteratively.
|
|
3083
|
+
*/
|
|
3084
|
+
declare abstract class ConverterStage {
|
|
3085
|
+
protected ctx: ConverterContext;
|
|
3086
|
+
protected MAX_ITERATIONS: number;
|
|
3087
|
+
protected iterationCount: number;
|
|
3088
|
+
finished: boolean;
|
|
3089
|
+
constructor(ctx: ConverterContext);
|
|
3090
|
+
/**
|
|
3091
|
+
* Perform one step of the conversion process.
|
|
3092
|
+
* Returns true if the stage has more work to do, false if finished.
|
|
3093
|
+
*/
|
|
3094
|
+
abstract step(): boolean;
|
|
3095
|
+
/**
|
|
3096
|
+
* Run this stage until completion or max iterations reached.
|
|
3097
|
+
*/
|
|
3098
|
+
runUntilFinished(): void;
|
|
3099
|
+
}
|
|
3100
|
+
|
|
3101
|
+
declare class KicadFootprintToCircuitJsonConverter {
|
|
3102
|
+
fsMap: Record<string, string>;
|
|
3103
|
+
ctx?: ConverterContext;
|
|
3104
|
+
addFile(filePath: string, content: string): void;
|
|
3105
|
+
private _findFileWithExtension;
|
|
3106
|
+
private initializeContext;
|
|
3107
|
+
private ensureFootprintUuid;
|
|
3108
|
+
runUntilFinished(): void;
|
|
3109
|
+
getOutput(): AnyCircuitElement[];
|
|
3110
|
+
getOutputString(): string;
|
|
3111
|
+
getWarnings(): string[];
|
|
3112
|
+
getStats(): {
|
|
3113
|
+
components?: number;
|
|
3114
|
+
pads?: number;
|
|
3115
|
+
vias?: number;
|
|
3116
|
+
traces?: number;
|
|
3117
|
+
labels?: number;
|
|
3118
|
+
copper_pours?: number;
|
|
3119
|
+
};
|
|
3120
|
+
}
|
|
3121
|
+
|
|
3122
|
+
declare class KicadSymbolToCircuitJsonConverter {
|
|
3123
|
+
fsMap: Record<string, string>;
|
|
3124
|
+
ctx?: ConverterContext;
|
|
3125
|
+
currentStageIndex: number;
|
|
3126
|
+
pipeline?: ConverterStage[];
|
|
3127
|
+
get currentStage(): ConverterStage | undefined;
|
|
3128
|
+
addFile(filePath: string, content: string): void;
|
|
3129
|
+
private _findFileWithExtension;
|
|
3130
|
+
initializePipeline(): void;
|
|
3131
|
+
step(): boolean;
|
|
3132
|
+
runUntilFinished(): void;
|
|
3133
|
+
getOutput(): AnyCircuitElement[];
|
|
3134
|
+
getOutputString(): string;
|
|
3135
|
+
getWarnings(): string[];
|
|
3136
|
+
getStats(): {
|
|
3137
|
+
components?: number;
|
|
3138
|
+
pads?: number;
|
|
3139
|
+
vias?: number;
|
|
3140
|
+
traces?: number;
|
|
3141
|
+
labels?: number;
|
|
3142
|
+
copper_pours?: number;
|
|
3143
|
+
};
|
|
3144
|
+
}
|
|
3145
|
+
|
|
3146
|
+
declare class KicadToCircuitJsonConverter {
|
|
3147
|
+
fsMap: Record<string, string>;
|
|
3148
|
+
ctx?: ConverterContext;
|
|
3149
|
+
currentStageIndex: number;
|
|
3150
|
+
pipeline?: ConverterStage[];
|
|
3151
|
+
get currentStage(): ConverterStage | undefined;
|
|
3152
|
+
addFile(filePath: string, content: string): void;
|
|
3153
|
+
_findFileWithExtension(extension: string): string | null;
|
|
3154
|
+
initializePipeline(): void;
|
|
3155
|
+
step(): boolean;
|
|
3156
|
+
runUntilFinished(): void;
|
|
3157
|
+
getOutput(): AnyCircuitElement[];
|
|
3158
|
+
getOutputString(): string;
|
|
3159
|
+
getWarnings(): string[];
|
|
3160
|
+
getStats(): {
|
|
3161
|
+
components?: number;
|
|
3162
|
+
pads?: number;
|
|
3163
|
+
vias?: number;
|
|
3164
|
+
traces?: number;
|
|
3165
|
+
labels?: number;
|
|
3166
|
+
copper_pours?: number;
|
|
3167
|
+
};
|
|
3168
|
+
}
|
|
3169
|
+
|
|
3170
|
+
/**
|
|
3171
|
+
* InitializeSchematicContextStage sets up the coordinate transformation
|
|
3172
|
+
* from KiCad schematic space to Circuit JSON space.
|
|
3173
|
+
*
|
|
3174
|
+
* KiCad→CJ schematic transform (inverse of CJ→KiCad):
|
|
3175
|
+
* - CJ→KiCad used: translate(KICAD_CENTER) ∘ scale(15, -15) ∘ translate(-center)
|
|
3176
|
+
* - KiCad→CJ uses: translate(center) ∘ scale(1/15, -1/15) ∘ translate(-KICAD_CENTER)
|
|
3177
|
+
*/
|
|
3178
|
+
declare class InitializeSchematicContextStage extends ConverterStage {
|
|
3179
|
+
step(): boolean;
|
|
3180
|
+
}
|
|
3181
|
+
|
|
3182
|
+
/**
|
|
3183
|
+
* CollectLibrarySymbolsStage extracts KiCad schematic symbols and creates:
|
|
3184
|
+
* - source_component entries (with ftype inferred from library id)
|
|
3185
|
+
* - schematic_component entries with positions
|
|
3186
|
+
* - schematic_port entries for each pin
|
|
3187
|
+
*/
|
|
3188
|
+
declare class CollectLibrarySymbolsStage extends ConverterStage {
|
|
3189
|
+
private processedSymbols;
|
|
3190
|
+
step(): boolean;
|
|
3191
|
+
private processSymbol;
|
|
3192
|
+
private getProperty;
|
|
3193
|
+
private inferFtype;
|
|
3194
|
+
private estimateSize;
|
|
3195
|
+
private createPorts;
|
|
3196
|
+
private inferPinDirection;
|
|
3197
|
+
}
|
|
3198
|
+
|
|
3199
|
+
/**
|
|
3200
|
+
* CollectSchematicTracesStage converts KiCad schematic wires and junctions
|
|
3201
|
+
* into Circuit JSON schematic_trace elements.
|
|
3202
|
+
*/
|
|
3203
|
+
declare class CollectSchematicTracesStage extends ConverterStage {
|
|
3204
|
+
step(): boolean;
|
|
3205
|
+
private processWire;
|
|
3206
|
+
private processJunction;
|
|
3207
|
+
}
|
|
3208
|
+
|
|
3209
|
+
/**
|
|
3210
|
+
* InitializePcbContextStage sets up the coordinate transformation
|
|
3211
|
+
* from KiCad PCB space to Circuit JSON space.
|
|
3212
|
+
*
|
|
3213
|
+
* KiCad→CJ PCB transform (inverse of CJ→KiCad):
|
|
3214
|
+
* - CJ→KiCad used: translate(100, 100) ∘ scale(1, -1)
|
|
3215
|
+
* - KiCad→CJ uses: scale(1, -1) ∘ translate(-100, -100)
|
|
3216
|
+
*/
|
|
3217
|
+
declare class InitializePcbContextStage extends ConverterStage {
|
|
3218
|
+
step(): boolean;
|
|
3219
|
+
private calculateBoardCenter;
|
|
3220
|
+
private getGraphicRects;
|
|
3221
|
+
private getRectStartEnd;
|
|
3222
|
+
}
|
|
3223
|
+
|
|
3224
|
+
/**
|
|
3225
|
+
* CollectNetsStage builds a mapping from KiCad net numbers to meaningful net names.
|
|
3226
|
+
* Prefers KiCad's actual net names, falls back to "Net-<n>" for unnamed nets.
|
|
3227
|
+
*/
|
|
3228
|
+
declare class CollectNetsStage extends ConverterStage {
|
|
3229
|
+
step(): boolean;
|
|
3230
|
+
}
|
|
3231
|
+
|
|
3232
|
+
/**
|
|
3233
|
+
* CollectFootprintsStage converts KiCad footprints into Circuit JSON pcb_components,
|
|
3234
|
+
* along with their associated pads (SMT, plated holes, NPTH) and silkscreen text.
|
|
3235
|
+
*/
|
|
3236
|
+
declare class CollectFootprintsStage extends ConverterStage {
|
|
3237
|
+
private processedFootprints;
|
|
3238
|
+
step(): boolean;
|
|
3239
|
+
}
|
|
3240
|
+
|
|
3241
|
+
/**
|
|
3242
|
+
* CollectTracesStage converts KiCad PCB segments (traces) into Circuit JSON pcb_trace elements.
|
|
3243
|
+
* Connected copper primitives are stitched into contiguous pcb_trace routes.
|
|
3244
|
+
*/
|
|
3245
|
+
declare class CollectTracesStage extends ConverterStage {
|
|
3246
|
+
private readonly PORT_MATCH_TOLERANCE;
|
|
3247
|
+
private readonly POINT_KEY_PRECISION;
|
|
3248
|
+
private readonly sourceTraceIdByNetTraceKey;
|
|
3249
|
+
step(): boolean;
|
|
3250
|
+
private getTracePrimitiveFromSegment;
|
|
3251
|
+
private getTracePrimitiveFromArc;
|
|
3252
|
+
private getTracePrimitiveFromVia;
|
|
3253
|
+
private createTracesFromPrimitives;
|
|
3254
|
+
private createTracesFromPrimitiveGroup;
|
|
3255
|
+
private createTraceGraph;
|
|
3256
|
+
private walkTracePath;
|
|
3257
|
+
private insertTracePath;
|
|
3258
|
+
private getPathRoutePoints;
|
|
3259
|
+
private isTerminalNode;
|
|
3260
|
+
private getPrimitiveGroupKey;
|
|
3261
|
+
private getPointKey;
|
|
3262
|
+
private getPointFromKey;
|
|
3263
|
+
private getTraceGraphNodeKey;
|
|
3264
|
+
private getTraceGraphNodeFromKey;
|
|
3265
|
+
private getOrientedTraceEdgeStartKey;
|
|
3266
|
+
private getOrientedTraceEdgeEndKey;
|
|
3267
|
+
private pointsMatch;
|
|
3268
|
+
private getPcbTraceNodeKey;
|
|
3269
|
+
private annotatePrimitivesWithConnectedSourcePorts;
|
|
3270
|
+
private getSegmentNet;
|
|
3271
|
+
private findPortAtPosition;
|
|
3272
|
+
private getConnectedSourcePortIds;
|
|
3273
|
+
private getSourcePortIdsForTrace;
|
|
3274
|
+
private getTraceConnectedSourcePortIds;
|
|
3275
|
+
private createSourceTraceForPath;
|
|
3276
|
+
private getNetTraceKey;
|
|
3277
|
+
}
|
|
3278
|
+
|
|
3279
|
+
/**
|
|
3280
|
+
* CollectViasStage converts KiCad vias into Circuit JSON pcb_via elements.
|
|
3281
|
+
*/
|
|
3282
|
+
declare class CollectViasStage extends ConverterStage {
|
|
3283
|
+
step(): boolean;
|
|
3284
|
+
private processVia;
|
|
3285
|
+
}
|
|
3286
|
+
|
|
3287
|
+
/**
|
|
3288
|
+
* CollectZonesStage converts KiCad zones with filled copper into Circuit JSON pcb_copper_pour elements.
|
|
3289
|
+
* Zones define copper pours/planes that are typically used for ground and power nets.
|
|
3290
|
+
*/
|
|
3291
|
+
declare class CollectZonesStage extends ConverterStage {
|
|
3292
|
+
step(): boolean;
|
|
3293
|
+
private isZoneFilled;
|
|
3294
|
+
private createCopperPourFromZone;
|
|
3295
|
+
private getZonePolygonRecords;
|
|
3296
|
+
private createZonePolygonRecordsFromShape;
|
|
3297
|
+
private getPolygonLayers;
|
|
3298
|
+
private getZoneLayers;
|
|
3299
|
+
private getZoneLayerLabel;
|
|
3300
|
+
private extractPointsFromPts;
|
|
3301
|
+
}
|
|
3302
|
+
|
|
3303
|
+
/**
|
|
3304
|
+
* CollectGraphicsStage processes KiCad graphics elements:
|
|
3305
|
+
* - gr_line on Edge.Cuts → pcb_board.outline
|
|
3306
|
+
* - gr_text on silk/fab layers → matching silkscreen/fabrication output
|
|
3307
|
+
* - gr_line/gr_arc on silk/fab/courtyard layers → matching PCB output
|
|
3308
|
+
* - gr_rect on copper layers (filled) → pcb_smtpad
|
|
3309
|
+
* - gr_poly on copper layers (filled) → pcb_smtpad (polygon)
|
|
3310
|
+
*/
|
|
3311
|
+
declare class CollectGraphicsStage extends ConverterStage {
|
|
3312
|
+
step(): boolean;
|
|
3313
|
+
private createBoardOutline;
|
|
3314
|
+
private createBoardContours;
|
|
3315
|
+
private getFootprintEdgeCutPrimitives;
|
|
3316
|
+
private transformFootprintPrimitive;
|
|
3317
|
+
private transformFootprintPoint;
|
|
3318
|
+
private orderConnectedContours;
|
|
3319
|
+
private reverseBoardPrimitive;
|
|
3320
|
+
private getRectEdgeCutPrimitives;
|
|
3321
|
+
private getRectStartEnd;
|
|
3322
|
+
private getBoardContourPoints;
|
|
3323
|
+
private getPrimitivePoints;
|
|
3324
|
+
private createEdgeCutCutout;
|
|
3325
|
+
private createEdgeCutCircleHole;
|
|
3326
|
+
private calculatePolygonArea;
|
|
3327
|
+
private createGraphicPath;
|
|
3328
|
+
private createGraphicArc;
|
|
3329
|
+
private insertRouteGraphic;
|
|
3330
|
+
private processRectangle;
|
|
3331
|
+
private createGraphicText;
|
|
3332
|
+
private pointsEqual;
|
|
3333
|
+
private pointsEqualKicad;
|
|
3334
|
+
private calculateWidth;
|
|
3335
|
+
private calculateHeight;
|
|
3336
|
+
private processPolygon;
|
|
3337
|
+
}
|
|
3338
|
+
|
|
3339
|
+
/**
|
|
3340
|
+
* CollectSourceTracesStage extracts logical nets from KiCad PCB by analyzing net
|
|
3341
|
+
* assignments on pads and copper.
|
|
3342
|
+
*
|
|
3343
|
+
* This stage:
|
|
3344
|
+
* 1. Iterates through all footprints and their pads
|
|
3345
|
+
* 2. Builds a mapping of nets to connected pads
|
|
3346
|
+
* 3. Creates source_port elements for each pad
|
|
3347
|
+
* 4. Creates source_net elements for each net. Physical trace collection creates
|
|
3348
|
+
* smaller source_trace elements that point at these source nets.
|
|
3349
|
+
*/
|
|
3350
|
+
declare class CollectSourceTracesStage extends ConverterStage {
|
|
3351
|
+
private processedNets;
|
|
3352
|
+
step(): boolean;
|
|
3353
|
+
private collectNetsFromCopper;
|
|
3354
|
+
private getSegmentNet;
|
|
3355
|
+
private processFootprintPads;
|
|
3356
|
+
private getPadNet;
|
|
3357
|
+
private getOrCreateSourcePort;
|
|
3358
|
+
private getSourcePortName;
|
|
3359
|
+
private getSourcePortPinNumber;
|
|
3360
|
+
private createSourceNet;
|
|
3361
|
+
}
|
|
3362
|
+
|
|
3363
|
+
/**
|
|
3364
|
+
* InitializeSymbolLibraryContextStage prepares shared state for .kicad_sym
|
|
3365
|
+
* conversion. Symbol libraries have no schematic placements, so this branch
|
|
3366
|
+
* emits source-level Circuit JSON only.
|
|
3367
|
+
*/
|
|
3368
|
+
declare class InitializeSymbolLibraryContextStage extends ConverterStage {
|
|
3369
|
+
step(): boolean;
|
|
3370
|
+
}
|
|
3371
|
+
|
|
3372
|
+
/**
|
|
3373
|
+
* CollectSymbolLibrarySymbolsStage converts KiCad symbol-library definitions
|
|
3374
|
+
* into source-level Circuit JSON:
|
|
3375
|
+
* - source_component for each top-level library symbol
|
|
3376
|
+
* - source_port for each physical pin in the symbol definition
|
|
3377
|
+
* - schematic_component and schematic_port preview geometry for snapshots
|
|
3378
|
+
*/
|
|
3379
|
+
declare class CollectSymbolLibrarySymbolsStage extends ConverterStage {
|
|
3380
|
+
private processedSymbols;
|
|
3381
|
+
private previewIndex;
|
|
3382
|
+
step(): boolean;
|
|
3383
|
+
private processSymbol;
|
|
3384
|
+
private getKicadSymbolExportFileName;
|
|
3385
|
+
private getSymbolName;
|
|
3386
|
+
private getSymbolProperties;
|
|
3387
|
+
private collectPins;
|
|
3388
|
+
private collectPolylines;
|
|
3389
|
+
private collectRectangles;
|
|
3390
|
+
private collectCircles;
|
|
3391
|
+
private collectArcs;
|
|
3392
|
+
private collectTexts;
|
|
3393
|
+
private createSchematicPreview;
|
|
3394
|
+
private getPreviewCenter;
|
|
3395
|
+
private getPinBounds;
|
|
3396
|
+
private getPreviewScale;
|
|
3397
|
+
private createSchematicPrimitives;
|
|
3398
|
+
private createPropertyTextPrimitives;
|
|
3399
|
+
private shouldRenderProperty;
|
|
3400
|
+
private getTextAnchor;
|
|
3401
|
+
private createPolylinePrimitives;
|
|
3402
|
+
private toSchematicPoint;
|
|
3403
|
+
private toStrokeWidth;
|
|
3404
|
+
private isFilled;
|
|
3405
|
+
private getFillColor;
|
|
3406
|
+
private getFontSize;
|
|
3407
|
+
private getPolylinePoints;
|
|
3408
|
+
private getShapeChildren;
|
|
3409
|
+
private getShapeChild;
|
|
3410
|
+
private getShapePoint;
|
|
3411
|
+
private getShapeNumber;
|
|
3412
|
+
private getShapeStroke;
|
|
3413
|
+
private getShapeFillType;
|
|
3414
|
+
private getArcPoints;
|
|
3415
|
+
private getArcGeometry;
|
|
3416
|
+
private getAngleDegrees;
|
|
3417
|
+
private getManufacturerPartNumber;
|
|
3418
|
+
private createSourceComponentData;
|
|
3419
|
+
private inferFtype;
|
|
3420
|
+
private getPortName;
|
|
3421
|
+
private getSourcePortPinMetadata;
|
|
3422
|
+
private getSchematicPortPinMetadata;
|
|
3423
|
+
private pinAngleToSideOfComponent;
|
|
3424
|
+
}
|
|
3425
|
+
|
|
3426
|
+
type KicadToCircuitJsonModule_CollectFootprintsStage = CollectFootprintsStage;
|
|
3427
|
+
declare const KicadToCircuitJsonModule_CollectFootprintsStage: typeof CollectFootprintsStage;
|
|
3428
|
+
type KicadToCircuitJsonModule_CollectGraphicsStage = CollectGraphicsStage;
|
|
3429
|
+
declare const KicadToCircuitJsonModule_CollectGraphicsStage: typeof CollectGraphicsStage;
|
|
3430
|
+
type KicadToCircuitJsonModule_CollectLibrarySymbolsStage = CollectLibrarySymbolsStage;
|
|
3431
|
+
declare const KicadToCircuitJsonModule_CollectLibrarySymbolsStage: typeof CollectLibrarySymbolsStage;
|
|
3432
|
+
type KicadToCircuitJsonModule_CollectNetsStage = CollectNetsStage;
|
|
3433
|
+
declare const KicadToCircuitJsonModule_CollectNetsStage: typeof CollectNetsStage;
|
|
3434
|
+
type KicadToCircuitJsonModule_CollectSchematicTracesStage = CollectSchematicTracesStage;
|
|
3435
|
+
declare const KicadToCircuitJsonModule_CollectSchematicTracesStage: typeof CollectSchematicTracesStage;
|
|
3436
|
+
type KicadToCircuitJsonModule_CollectSourceTracesStage = CollectSourceTracesStage;
|
|
3437
|
+
declare const KicadToCircuitJsonModule_CollectSourceTracesStage: typeof CollectSourceTracesStage;
|
|
3438
|
+
type KicadToCircuitJsonModule_CollectSymbolLibrarySymbolsStage = CollectSymbolLibrarySymbolsStage;
|
|
3439
|
+
declare const KicadToCircuitJsonModule_CollectSymbolLibrarySymbolsStage: typeof CollectSymbolLibrarySymbolsStage;
|
|
3440
|
+
type KicadToCircuitJsonModule_CollectTracesStage = CollectTracesStage;
|
|
3441
|
+
declare const KicadToCircuitJsonModule_CollectTracesStage: typeof CollectTracesStage;
|
|
3442
|
+
type KicadToCircuitJsonModule_CollectViasStage = CollectViasStage;
|
|
3443
|
+
declare const KicadToCircuitJsonModule_CollectViasStage: typeof CollectViasStage;
|
|
3444
|
+
type KicadToCircuitJsonModule_CollectZonesStage = CollectZonesStage;
|
|
3445
|
+
declare const KicadToCircuitJsonModule_CollectZonesStage: typeof CollectZonesStage;
|
|
3446
|
+
type KicadToCircuitJsonModule_ConverterContext = ConverterContext;
|
|
3447
|
+
type KicadToCircuitJsonModule_ConverterStage = ConverterStage;
|
|
3448
|
+
declare const KicadToCircuitJsonModule_ConverterStage: typeof ConverterStage;
|
|
3449
|
+
type KicadToCircuitJsonModule_InitializePcbContextStage = InitializePcbContextStage;
|
|
3450
|
+
declare const KicadToCircuitJsonModule_InitializePcbContextStage: typeof InitializePcbContextStage;
|
|
3451
|
+
type KicadToCircuitJsonModule_InitializeSchematicContextStage = InitializeSchematicContextStage;
|
|
3452
|
+
declare const KicadToCircuitJsonModule_InitializeSchematicContextStage: typeof InitializeSchematicContextStage;
|
|
3453
|
+
type KicadToCircuitJsonModule_InitializeSymbolLibraryContextStage = InitializeSymbolLibraryContextStage;
|
|
3454
|
+
declare const KicadToCircuitJsonModule_InitializeSymbolLibraryContextStage: typeof InitializeSymbolLibraryContextStage;
|
|
3455
|
+
type KicadToCircuitJsonModule_KicadFootprintToCircuitJsonConverter = KicadFootprintToCircuitJsonConverter;
|
|
3456
|
+
declare const KicadToCircuitJsonModule_KicadFootprintToCircuitJsonConverter: typeof KicadFootprintToCircuitJsonConverter;
|
|
3457
|
+
type KicadToCircuitJsonModule_KicadSymbolToCircuitJsonConverter = KicadSymbolToCircuitJsonConverter;
|
|
3458
|
+
declare const KicadToCircuitJsonModule_KicadSymbolToCircuitJsonConverter: typeof KicadSymbolToCircuitJsonConverter;
|
|
3459
|
+
type KicadToCircuitJsonModule_KicadToCircuitJsonConverter = KicadToCircuitJsonConverter;
|
|
3460
|
+
declare const KicadToCircuitJsonModule_KicadToCircuitJsonConverter: typeof KicadToCircuitJsonConverter;
|
|
3461
|
+
declare namespace KicadToCircuitJsonModule {
|
|
3462
|
+
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 };
|
|
3463
|
+
}
|
|
3464
|
+
|
|
3465
|
+
declare const supportedModules: readonly ["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"];
|
|
3058
3466
|
type SupportedModuleName = (typeof supportedModules)[number];
|
|
3059
3467
|
type SupportedModuleSpecifier = SupportedModuleName | `${SupportedModuleName}@${string}`;
|
|
3060
3468
|
interface SupportedModuleMap {
|
|
@@ -3073,6 +3481,7 @@ interface SupportedModuleMap {
|
|
|
3073
3481
|
"circuit-json-to-tscircuit": typeof CircuitJsonToTscircuitModule;
|
|
3074
3482
|
"circuit-to-canvas": typeof CircuitToCanvasModule;
|
|
3075
3483
|
"circuit-to-svg": typeof CircuitToSvgModule;
|
|
3484
|
+
"kicad-to-circuit-json": typeof KicadToCircuitJsonModule;
|
|
3076
3485
|
}
|
|
3077
3486
|
type StripVersion<TSpecifier extends string> = TSpecifier extends `${infer TBase}@${string}` ? TBase extends SupportedModuleName ? TBase : never : TSpecifier extends SupportedModuleName ? TSpecifier : never;
|
|
3078
3487
|
declare const getModuleName: (specifier: string) => string;
|
|
@@ -3086,7 +3495,8 @@ declare function registerDynamicModule<TSpecifier extends SupportedModuleName>(n
|
|
|
3086
3495
|
declare function registerDynamicModule<TModule>(name: string, mod: TModule): TModule;
|
|
3087
3496
|
|
|
3088
3497
|
declare const getImportUrl: (specifier: string) => string;
|
|
3498
|
+
declare const getImportUrls: (specifier: string) => string[];
|
|
3089
3499
|
declare function importer<TSpecifier extends SupportedModuleSpecifier>(specifier: TSpecifier): Promise<SupportedModuleMap[StripVersion<TSpecifier>]>;
|
|
3090
3500
|
declare function importer(specifier: string): Promise<unknown>;
|
|
3091
3501
|
|
|
3092
|
-
export { type DynamicModuleRegistry, type StripVersion, type SupportedModuleMap, type SupportedModuleName, type SupportedModuleSpecifier, importer as default, getDynamicModuleRegistry, getImportUrl, getModuleName, registerDynamicModule, supportedModules };
|
|
3502
|
+
export { type DynamicModuleRegistry, type StripVersion, type SupportedModuleMap, type SupportedModuleName, type SupportedModuleSpecifier, importer as default, getDynamicModuleRegistry, getImportUrl, getImportUrls, getModuleName, registerDynamicModule, supportedModules };
|
package/dist/index.js
CHANGED
|
@@ -28,7 +28,8 @@ var supportedModules = [
|
|
|
28
28
|
"circuit-json-to-step",
|
|
29
29
|
"circuit-json-to-tscircuit",
|
|
30
30
|
"circuit-to-canvas",
|
|
31
|
-
"circuit-to-svg"
|
|
31
|
+
"circuit-to-svg",
|
|
32
|
+
"kicad-to-circuit-json"
|
|
32
33
|
];
|
|
33
34
|
var getModuleName = (specifier) => {
|
|
34
35
|
const versionSeparatorIndex = specifier.indexOf("@");
|
|
@@ -38,21 +39,41 @@ var getModuleName = (specifier) => {
|
|
|
38
39
|
// lib/index.ts
|
|
39
40
|
var supportedModuleSet = new Set(supportedModules);
|
|
40
41
|
var getImportUrl = (specifier) => {
|
|
42
|
+
assertSupportedModule(specifier);
|
|
43
|
+
return getJscdnImportUrl(specifier);
|
|
44
|
+
};
|
|
45
|
+
var getImportUrls = (specifier) => {
|
|
46
|
+
assertSupportedModule(specifier);
|
|
47
|
+
return [getJscdnImportUrl(specifier), `https://esm.run/${specifier}`];
|
|
48
|
+
};
|
|
49
|
+
function getJscdnImportUrl(specifier) {
|
|
50
|
+
const moduleName = getModuleName(specifier);
|
|
51
|
+
const version = specifier.length === moduleName.length ? "latest" : specifier.slice(moduleName.length + 1);
|
|
52
|
+
return `https://jscdn.tscircuit.com/${moduleName}/${version}/+esm`;
|
|
53
|
+
}
|
|
54
|
+
function assertSupportedModule(specifier) {
|
|
41
55
|
const moduleName = getModuleName(specifier);
|
|
42
56
|
if (!supportedModuleSet.has(moduleName)) {
|
|
43
57
|
throw new Error(`Unsupported module: ${specifier}`);
|
|
44
58
|
}
|
|
45
|
-
|
|
46
|
-
};
|
|
59
|
+
}
|
|
47
60
|
async function importer(specifier) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
61
|
+
let lastError;
|
|
62
|
+
for (const importUrl of getImportUrls(specifier)) {
|
|
63
|
+
try {
|
|
64
|
+
const mod = await import(
|
|
65
|
+
/* @vite-ignore */
|
|
66
|
+
importUrl
|
|
67
|
+
);
|
|
68
|
+
return registerDynamicModule(getModuleName(specifier), mod);
|
|
69
|
+
} catch (error) {
|
|
70
|
+
lastError = error;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
throw lastError;
|
|
53
74
|
}
|
|
54
75
|
var index_default = importer;
|
|
55
76
|
|
|
56
|
-
export { index_default as default, getDynamicModuleRegistry, getImportUrl, getModuleName, registerDynamicModule, supportedModules };
|
|
77
|
+
export { index_default as default, getDynamicModuleRegistry, getImportUrl, getImportUrls, getModuleName, registerDynamicModule, supportedModules };
|
|
57
78
|
//# sourceMappingURL=index.js.map
|
|
58
79
|
//# sourceMappingURL=index.js.map
|
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;;;
|
|
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;;;ACnBO,IAAM,gBAAA,GAAmB;AAAA,EAC9B,yBAAA;AAAA,EACA,qBAAA;AAAA,EACA,kCAAA;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;AACF;AAmCO,IAAM,aAAA,GAAgB,CAAC,SAAA,KAA8B;AAC1D,EAAA,MAAM,qBAAA,GAAwB,SAAA,CAAU,OAAA,CAAQ,GAAG,CAAA;AACnD,EAAA,OAAO,0BAA0B,EAAA,GAC7B,SAAA,GACA,SAAA,CAAU,KAAA,CAAM,GAAG,qBAAqB,CAAA;AAC9C;;;ACjDA,IAAM,kBAAA,GAAqB,IAAI,GAAA,CAAY,gBAAgB,CAAA;AAEpD,IAAM,YAAA,GAAe,CAAC,SAAA,KAA8B;AACzD,EAAA,qBAAA,CAAsB,SAAS,CAAA;AAE/B,EAAA,OAAO,kBAAkB,SAAS,CAAA;AACpC;AAEO,IAAM,aAAA,GAAgB,CAAC,SAAA,KAAgC;AAC5D,EAAA,qBAAA,CAAsB,SAAS,CAAA;AAE/B,EAAA,OAAO,CAAC,iBAAA,CAAkB,SAAS,CAAA,EAAG,CAAA,gBAAA,EAAmB,SAAS,CAAA,CAAE,CAAA;AACtE;AAEA,SAAS,kBAAkB,SAAA,EAA2B;AACpD,EAAA,MAAM,UAAA,GAAa,cAAc,SAAS,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 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-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-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"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tscircuit/internal-dynamic-import",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "Type-safe dynamic imports for selected tscircuit packages via jsDelivr",
|
|
3
|
+
"version": "0.0.8",
|
|
4
|
+
"description": "Type-safe dynamic imports for selected tscircuit packages via jscdn and fallback to jsDelivr",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"module": "./dist/index.js",
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
"circuit-json-to-tscircuit": "0.0.14",
|
|
44
44
|
"circuit-to-canvas": "0.0.94",
|
|
45
45
|
"circuit-to-svg": "0.0.339",
|
|
46
|
+
"kicad-to-circuit-json": "0.0.98",
|
|
46
47
|
"tsup": "8.5.1",
|
|
47
48
|
"typescript": "5.9.3"
|
|
48
49
|
}
|