@tscircuit/core 0.0.160 → 0.0.162
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 +10 -6
- package/dist/index.js +95 -105
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { traceProps, SchematicPortArrangement, groupProps, boardProps, capacitor
|
|
|
3
3
|
import React, { ReactElement } from 'react';
|
|
4
4
|
import * as zod from 'zod';
|
|
5
5
|
import { ZodType, z } from 'zod';
|
|
6
|
-
import { SchSymbol, BaseSymbolName } from 'schematic-symbols';
|
|
6
|
+
import { symbols, SchSymbol, BaseSymbolName } from 'schematic-symbols';
|
|
7
7
|
import { PcbTraceError, PcbPlacementError, LayerRef, AnyCircuitElement, AnySourceComponent, RouteHintPoint } from 'circuit-json';
|
|
8
8
|
import { Matrix } from 'transformation-matrix';
|
|
9
9
|
import { SoupUtilObjects } from '@tscircuit/soup-util';
|
|
@@ -130,7 +130,7 @@ interface ISubcircuit extends PrimitiveComponent {
|
|
|
130
130
|
|
|
131
131
|
interface BaseComponentConfig {
|
|
132
132
|
componentName: string;
|
|
133
|
-
schematicSymbolName?:
|
|
133
|
+
schematicSymbolName?: string | null;
|
|
134
134
|
zodProps: ZodType;
|
|
135
135
|
sourceFtype?: AnySourceComponent["ftype"] | null;
|
|
136
136
|
shouldRenderAsSchematicBox?: boolean;
|
|
@@ -238,6 +238,8 @@ declare abstract class PrimitiveComponent<ZodProps extends ZodType = any> extend
|
|
|
238
238
|
* component
|
|
239
239
|
*/
|
|
240
240
|
computeSchematicGlobalTransform(): Matrix;
|
|
241
|
+
_getSchematicSymbolName(): keyof typeof symbols | undefined;
|
|
242
|
+
_getSchematicSymbolNameOrThrow(): keyof typeof symbols;
|
|
241
243
|
getSchematicSymbol(): SchSymbol | null;
|
|
242
244
|
/**
|
|
243
245
|
* Subcircuit groups have a prop called "layout" that can include manual
|
|
@@ -281,12 +283,12 @@ declare abstract class PrimitiveComponent<ZodProps extends ZodType = any> extend
|
|
|
281
283
|
doesSelectorMatch(selector: string): boolean;
|
|
282
284
|
getSubcircuit(): ISubcircuit;
|
|
283
285
|
selectAll(selector: string): PrimitiveComponent[];
|
|
284
|
-
selectOne(selector: string, options?: {
|
|
286
|
+
selectOne<T = PrimitiveComponent>(selector: string, options?: {
|
|
285
287
|
type?: string;
|
|
286
288
|
port?: boolean;
|
|
287
289
|
pcbPrimitive?: boolean;
|
|
288
290
|
schematicPrimitive?: boolean;
|
|
289
|
-
}):
|
|
291
|
+
}): T | null;
|
|
290
292
|
getAvailablePcbLayers(): string[];
|
|
291
293
|
getDescendants(): PrimitiveComponent[];
|
|
292
294
|
/**
|
|
@@ -722,7 +724,9 @@ declare class NormalComponent<ZodProps extends ZodType = any, PortNames extends
|
|
|
722
724
|
* 2. `props.footprint`
|
|
723
725
|
*
|
|
724
726
|
*/
|
|
725
|
-
initPorts(
|
|
727
|
+
initPorts(opts?: {
|
|
728
|
+
additionalAliases?: Record<`pin${number}`, string[]>;
|
|
729
|
+
}): void;
|
|
726
730
|
_getImpliedFootprintString(): string | null;
|
|
727
731
|
_addChildrenFromStringFootprint(): void;
|
|
728
732
|
get portMap(): PortMap<PortNames>;
|
|
@@ -3787,7 +3791,7 @@ declare class PowerSource extends NormalComponent<typeof powerSourceProps, Polar
|
|
|
3787
3791
|
declare class Resistor extends NormalComponent<typeof resistorProps, PassivePorts> {
|
|
3788
3792
|
get config(): {
|
|
3789
3793
|
componentName: string;
|
|
3790
|
-
schematicSymbolName:
|
|
3794
|
+
schematicSymbolName: string;
|
|
3791
3795
|
zodProps: zod.ZodObject<zod.objectUtil.extendShape<zod.objectUtil.extendShape<zod.objectUtil.extendShape<{
|
|
3792
3796
|
pcbX: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
|
|
3793
3797
|
pcbY: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
|
package/dist/index.js
CHANGED
|
@@ -545,7 +545,7 @@ var PrimitiveComponent = class extends Renderable {
|
|
|
545
545
|
newProps,
|
|
546
546
|
changedProps: Object.keys(props)
|
|
547
547
|
});
|
|
548
|
-
this.parent?.onChildChanged(this);
|
|
548
|
+
this.parent?.onChildChanged?.(this);
|
|
549
549
|
}
|
|
550
550
|
/**
|
|
551
551
|
* Computes a transformation matrix from the props of this component for PCB
|
|
@@ -664,10 +664,36 @@ var PrimitiveComponent = class extends Renderable {
|
|
|
664
664
|
this.computeSchematicPropsTransform()
|
|
665
665
|
);
|
|
666
666
|
}
|
|
667
|
+
_getSchematicSymbolName() {
|
|
668
|
+
const { _parsedProps: props } = this;
|
|
669
|
+
const base_symbol_name = this.config.schematicSymbolName;
|
|
670
|
+
const symbol_name_horz = `${base_symbol_name}_horz`;
|
|
671
|
+
const symbol_name_vert = `${base_symbol_name}_vert`;
|
|
672
|
+
if (symbol_name_horz in symbols) {
|
|
673
|
+
if (props.schRotation === 0 || props.schRotation === void 0)
|
|
674
|
+
return symbol_name_horz;
|
|
675
|
+
if (props.schRotation === 180) return symbol_name_vert;
|
|
676
|
+
}
|
|
677
|
+
if (symbol_name_vert in symbols) {
|
|
678
|
+
if (props.schRotation === 90) return symbol_name_vert;
|
|
679
|
+
if (props.schRotation === 270) return symbol_name_vert;
|
|
680
|
+
}
|
|
681
|
+
if (base_symbol_name in symbols) return base_symbol_name;
|
|
682
|
+
return void 0;
|
|
683
|
+
}
|
|
684
|
+
_getSchematicSymbolNameOrThrow() {
|
|
685
|
+
const symbol_name = this._getSchematicSymbolName();
|
|
686
|
+
if (!symbol_name) {
|
|
687
|
+
throw new Error(
|
|
688
|
+
`No schematic symbol found (given: "${this.config.schematicSymbolName}")`
|
|
689
|
+
);
|
|
690
|
+
}
|
|
691
|
+
return symbol_name;
|
|
692
|
+
}
|
|
667
693
|
getSchematicSymbol() {
|
|
668
|
-
const
|
|
669
|
-
if (!
|
|
670
|
-
return symbols[
|
|
694
|
+
const symbol_name = this._getSchematicSymbolName();
|
|
695
|
+
if (!symbol_name) return null;
|
|
696
|
+
return symbols[symbol_name] ?? null;
|
|
671
697
|
}
|
|
672
698
|
/**
|
|
673
699
|
* Subcircuit groups have a prop called "layout" that can include manual
|
|
@@ -712,7 +738,7 @@ var PrimitiveComponent = class extends Renderable {
|
|
|
712
738
|
onPropsChange(params) {
|
|
713
739
|
}
|
|
714
740
|
onChildChanged(child) {
|
|
715
|
-
this.parent?.onChildChanged(child);
|
|
741
|
+
this.parent?.onChildChanged?.(child);
|
|
716
742
|
}
|
|
717
743
|
add(component) {
|
|
718
744
|
component.onAddToParent(this);
|
|
@@ -1727,9 +1753,9 @@ var Port = class extends PrimitiveComponent {
|
|
|
1727
1753
|
return Array.from(
|
|
1728
1754
|
/* @__PURE__ */ new Set([
|
|
1729
1755
|
...props.aliases ?? [],
|
|
1730
|
-
props.name,
|
|
1756
|
+
...props.name ? [props.name] : [],
|
|
1731
1757
|
...typeof props.pinNumber === "number" ? [`pin${props.pinNumber}`, props.pinNumber.toString()] : [],
|
|
1732
|
-
...this.externallyAddedAliases
|
|
1758
|
+
...this.externallyAddedAliases ?? []
|
|
1733
1759
|
])
|
|
1734
1760
|
);
|
|
1735
1761
|
}
|
|
@@ -1867,12 +1893,19 @@ var Port = class extends PrimitiveComponent {
|
|
|
1867
1893
|
};
|
|
1868
1894
|
|
|
1869
1895
|
// lib/utils/getPortFromHints.ts
|
|
1896
|
+
var getPinNumberFromLabels = (labels) => {
|
|
1897
|
+
const pinNumber = labels.find((p) => /^(pin)?\d+$/.test(p));
|
|
1898
|
+
if (!pinNumber) return null;
|
|
1899
|
+
return Number.parseInt(pinNumber.replace(/^pin/, ""));
|
|
1900
|
+
};
|
|
1870
1901
|
function getPortFromHints(hints) {
|
|
1871
|
-
const pinNumber = hints
|
|
1902
|
+
const pinNumber = getPinNumberFromLabels(hints);
|
|
1872
1903
|
if (!pinNumber) return null;
|
|
1873
1904
|
return new Port({
|
|
1874
|
-
pinNumber
|
|
1875
|
-
aliases: hints.filter(
|
|
1905
|
+
pinNumber,
|
|
1906
|
+
aliases: hints.filter(
|
|
1907
|
+
(p) => p.toString() !== pinNumber.toString() && p !== `pin${pinNumber}`
|
|
1908
|
+
)
|
|
1876
1909
|
});
|
|
1877
1910
|
}
|
|
1878
1911
|
|
|
@@ -2365,7 +2398,7 @@ var NormalComponent = class extends PrimitiveComponent {
|
|
|
2365
2398
|
* 2. `props.footprint`
|
|
2366
2399
|
*
|
|
2367
2400
|
*/
|
|
2368
|
-
initPorts() {
|
|
2401
|
+
initPorts(opts = {}) {
|
|
2369
2402
|
const { config } = this;
|
|
2370
2403
|
const portsToCreate = [];
|
|
2371
2404
|
const schPortArrangement = this._parsedProps.schPortArrangement;
|
|
@@ -2377,7 +2410,8 @@ var NormalComponent = class extends PrimitiveComponent {
|
|
|
2377
2410
|
portsToCreate.push(
|
|
2378
2411
|
new Port(
|
|
2379
2412
|
{
|
|
2380
|
-
pinNumber
|
|
2413
|
+
pinNumber,
|
|
2414
|
+
aliases: opts.additionalAliases?.[`pin${pinNumber}`] ?? []
|
|
2381
2415
|
},
|
|
2382
2416
|
{
|
|
2383
2417
|
originDescription: `schPortArrangement:${side}`
|
|
@@ -2395,7 +2429,8 @@ var NormalComponent = class extends PrimitiveComponent {
|
|
|
2395
2429
|
portsToCreate.push(
|
|
2396
2430
|
new Port(
|
|
2397
2431
|
{
|
|
2398
|
-
pinNumber: pinNum
|
|
2432
|
+
pinNumber: pinNum++,
|
|
2433
|
+
aliases: opts.additionalAliases?.[`pin${pinNum}`] ?? []
|
|
2399
2434
|
},
|
|
2400
2435
|
{
|
|
2401
2436
|
originDescription: `schPortArrangement:${side}`
|
|
@@ -2419,7 +2454,10 @@ var NormalComponent = class extends PrimitiveComponent {
|
|
|
2419
2454
|
{
|
|
2420
2455
|
pinNumber: parseInt(pinNumber),
|
|
2421
2456
|
name: primaryLabel,
|
|
2422
|
-
aliases:
|
|
2457
|
+
aliases: [
|
|
2458
|
+
...otherLabels,
|
|
2459
|
+
...opts.additionalAliases?.[`pin${parseInt(pinNumber)}`] ?? []
|
|
2460
|
+
]
|
|
2423
2461
|
},
|
|
2424
2462
|
{
|
|
2425
2463
|
originDescription: `pinLabels:pin${pinNumber}`
|
|
@@ -2433,10 +2471,16 @@ var NormalComponent = class extends PrimitiveComponent {
|
|
|
2433
2471
|
}
|
|
2434
2472
|
}
|
|
2435
2473
|
if (config.schematicSymbolName) {
|
|
2436
|
-
const sym = symbols2[
|
|
2474
|
+
const sym = symbols2[this._getSchematicSymbolNameOrThrow()];
|
|
2437
2475
|
if (!sym) return;
|
|
2438
2476
|
for (const symPort of sym.ports) {
|
|
2439
|
-
const
|
|
2477
|
+
const pinNumber = getPinNumberFromLabels(symPort.labels);
|
|
2478
|
+
if (!pinNumber) continue;
|
|
2479
|
+
const port = getPortFromHints(
|
|
2480
|
+
symPort.labels.concat(
|
|
2481
|
+
opts.additionalAliases?.[`pin${pinNumber}`] ?? []
|
|
2482
|
+
)
|
|
2483
|
+
);
|
|
2440
2484
|
if (port) {
|
|
2441
2485
|
port.originDescription = `schematicSymbol:labels[0]:${symPort.labels[0]}`;
|
|
2442
2486
|
port.schematicSymbolPortDef = symPort;
|
|
@@ -2533,21 +2577,7 @@ var NormalComponent = class extends PrimitiveComponent {
|
|
|
2533
2577
|
_doInitialSchematicComponentRenderWithSymbol() {
|
|
2534
2578
|
const { db } = this.root;
|
|
2535
2579
|
const { _parsedProps: props } = this;
|
|
2536
|
-
const
|
|
2537
|
-
const symbol_name_horz = `${base_symbol_name}_horz`;
|
|
2538
|
-
let symbol_name;
|
|
2539
|
-
if (!base_symbol_name) {
|
|
2540
|
-
throw new Error(
|
|
2541
|
-
"No schematic symbol defined (schematicSymbolName not provided)"
|
|
2542
|
-
);
|
|
2543
|
-
}
|
|
2544
|
-
if (base_symbol_name in symbols2) {
|
|
2545
|
-
symbol_name = base_symbol_name;
|
|
2546
|
-
} else if (symbol_name_horz in symbols2) {
|
|
2547
|
-
symbol_name = symbol_name_horz;
|
|
2548
|
-
} else {
|
|
2549
|
-
throw new Error(`Could not find schematic-symbol: "${base_symbol_name}"`);
|
|
2550
|
-
}
|
|
2580
|
+
const symbol_name = this._getSchematicSymbolNameOrThrow();
|
|
2551
2581
|
const symbol = symbols2[symbol_name];
|
|
2552
2582
|
if (symbol) {
|
|
2553
2583
|
const schematic_component2 = db.schematic_component.insert({
|
|
@@ -4127,26 +4157,18 @@ var Capacitor = class extends NormalComponent {
|
|
|
4127
4157
|
get config() {
|
|
4128
4158
|
return {
|
|
4129
4159
|
componentName: "Capacitor",
|
|
4130
|
-
schematicSymbolName: this.props.symbolName ?? "
|
|
4160
|
+
schematicSymbolName: this.props.symbolName ?? "capacitor",
|
|
4131
4161
|
zodProps: capacitorProps,
|
|
4132
4162
|
sourceFtype: FTYPE.simple_capacitor
|
|
4133
4163
|
};
|
|
4134
4164
|
}
|
|
4135
4165
|
initPorts() {
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
|
|
4139
|
-
|
|
4140
|
-
|
|
4141
|
-
|
|
4142
|
-
);
|
|
4143
|
-
this.add(
|
|
4144
|
-
new Port({
|
|
4145
|
-
name: "pin2",
|
|
4146
|
-
pinNumber: 2,
|
|
4147
|
-
aliases: ["cathode", "neg", "right"]
|
|
4148
|
-
})
|
|
4149
|
-
);
|
|
4166
|
+
super.initPorts({
|
|
4167
|
+
additionalAliases: {
|
|
4168
|
+
pin1: ["anode", "pos", "left"],
|
|
4169
|
+
pin2: ["cathode", "neg", "right"]
|
|
4170
|
+
}
|
|
4171
|
+
});
|
|
4150
4172
|
}
|
|
4151
4173
|
_getSchematicSymbolDisplayValue() {
|
|
4152
4174
|
return `${formatSiUnit(this._parsedProps.capacitance)}F`;
|
|
@@ -4233,27 +4255,19 @@ var Diode = class extends NormalComponent {
|
|
|
4233
4255
|
// @ts-ignore
|
|
4234
4256
|
get config() {
|
|
4235
4257
|
return {
|
|
4236
|
-
schematicSymbolName: this.props.symbolName ?? "
|
|
4258
|
+
schematicSymbolName: this.props.symbolName ?? "diode",
|
|
4237
4259
|
componentName: "Diode",
|
|
4238
4260
|
zodProps: diodeProps,
|
|
4239
4261
|
sourceFtype: "simple_diode"
|
|
4240
4262
|
};
|
|
4241
4263
|
}
|
|
4242
4264
|
initPorts() {
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
);
|
|
4250
|
-
this.add(
|
|
4251
|
-
new Port({
|
|
4252
|
-
name: "pin2",
|
|
4253
|
-
pinNumber: 2,
|
|
4254
|
-
aliases: ["cathode", "neg", "right"]
|
|
4255
|
-
})
|
|
4256
|
-
);
|
|
4265
|
+
super.initPorts({
|
|
4266
|
+
additionalAliases: {
|
|
4267
|
+
pin1: ["anode", "pos", "left"],
|
|
4268
|
+
pin2: ["cathode", "neg", "right"]
|
|
4269
|
+
}
|
|
4270
|
+
});
|
|
4257
4271
|
}
|
|
4258
4272
|
pos = this.portMap.pin1;
|
|
4259
4273
|
anode = this.portMap.pin1;
|
|
@@ -4308,26 +4322,18 @@ var Led = class extends NormalComponent {
|
|
|
4308
4322
|
get config() {
|
|
4309
4323
|
return {
|
|
4310
4324
|
componentName: "Led",
|
|
4311
|
-
schematicSymbolName: this.props.symbolName ?? "
|
|
4325
|
+
schematicSymbolName: this.props.symbolName ?? "led",
|
|
4312
4326
|
zodProps: ledProps,
|
|
4313
4327
|
sourceFtype: "simple_diode"
|
|
4314
4328
|
};
|
|
4315
4329
|
}
|
|
4316
4330
|
initPorts() {
|
|
4317
|
-
|
|
4318
|
-
|
|
4319
|
-
|
|
4320
|
-
|
|
4321
|
-
|
|
4322
|
-
|
|
4323
|
-
);
|
|
4324
|
-
this.add(
|
|
4325
|
-
new Port({
|
|
4326
|
-
name: "pin2",
|
|
4327
|
-
pinNumber: 2,
|
|
4328
|
-
aliases: ["cathode", "neg", "right"]
|
|
4329
|
-
})
|
|
4330
|
-
);
|
|
4331
|
+
super.initPorts({
|
|
4332
|
+
additionalAliases: {
|
|
4333
|
+
pin1: ["anode", "pos", "left"],
|
|
4334
|
+
pin2: ["cathode", "neg", "right"]
|
|
4335
|
+
}
|
|
4336
|
+
});
|
|
4331
4337
|
}
|
|
4332
4338
|
pos = this.portMap.pin1;
|
|
4333
4339
|
anode = this.portMap.pin1;
|
|
@@ -4369,26 +4375,18 @@ var Resistor = class extends NormalComponent {
|
|
|
4369
4375
|
get config() {
|
|
4370
4376
|
return {
|
|
4371
4377
|
componentName: "Resistor",
|
|
4372
|
-
schematicSymbolName: this.props.symbolName ?? "
|
|
4378
|
+
schematicSymbolName: this.props.symbolName ?? "boxresistor",
|
|
4373
4379
|
zodProps: resistorProps,
|
|
4374
4380
|
sourceFtype: "simple_resistor"
|
|
4375
4381
|
};
|
|
4376
4382
|
}
|
|
4377
4383
|
initPorts() {
|
|
4378
|
-
|
|
4379
|
-
|
|
4380
|
-
|
|
4381
|
-
|
|
4382
|
-
|
|
4383
|
-
|
|
4384
|
-
);
|
|
4385
|
-
this.add(
|
|
4386
|
-
new Port({
|
|
4387
|
-
name: "pin2",
|
|
4388
|
-
pinNumber: 2,
|
|
4389
|
-
aliases: ["cathode", "neg", "right"]
|
|
4390
|
-
})
|
|
4391
|
-
);
|
|
4384
|
+
super.initPorts({
|
|
4385
|
+
additionalAliases: {
|
|
4386
|
+
pin1: ["anode", "pos", "left"],
|
|
4387
|
+
pin2: ["cathode", "neg", "right"]
|
|
4388
|
+
}
|
|
4389
|
+
});
|
|
4392
4390
|
}
|
|
4393
4391
|
_getSchematicSymbolDisplayValue() {
|
|
4394
4392
|
return `${formatSiUnit2(this._parsedProps.resistance)}\u03A9`;
|
|
@@ -4860,20 +4858,12 @@ var Inductor = class extends NormalComponent {
|
|
|
4860
4858
|
};
|
|
4861
4859
|
}
|
|
4862
4860
|
initPorts() {
|
|
4863
|
-
|
|
4864
|
-
|
|
4865
|
-
|
|
4866
|
-
|
|
4867
|
-
|
|
4868
|
-
|
|
4869
|
-
);
|
|
4870
|
-
this.add(
|
|
4871
|
-
new Port({
|
|
4872
|
-
name: "pin2",
|
|
4873
|
-
pinNumber: 2,
|
|
4874
|
-
aliases: ["cathode", "neg", "right"]
|
|
4875
|
-
})
|
|
4876
|
-
);
|
|
4861
|
+
super.initPorts({
|
|
4862
|
+
additionalAliases: {
|
|
4863
|
+
pin1: ["anode", "pos", "left"],
|
|
4864
|
+
pin2: ["cathode", "neg", "right"]
|
|
4865
|
+
}
|
|
4866
|
+
});
|
|
4877
4867
|
}
|
|
4878
4868
|
doInitialSourceRender() {
|
|
4879
4869
|
const { db } = this.root;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tscircuit/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.162",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.js",
|
|
@@ -45,13 +45,13 @@
|
|
|
45
45
|
"@tscircuit/soup-util": "^0.0.33",
|
|
46
46
|
"circuit-json": "^0.0.99",
|
|
47
47
|
"circuit-json-to-connectivity-map": "^0.0.17",
|
|
48
|
-
"circuit-to-svg": "^0.0.
|
|
48
|
+
"circuit-to-svg": "^0.0.71",
|
|
49
49
|
"format-si-unit": "^0.0.2",
|
|
50
50
|
"nanoid": "^5.0.7",
|
|
51
51
|
"performance-now": "^2.1.0",
|
|
52
52
|
"react": "^18.3.1",
|
|
53
53
|
"react-reconciler": "^0.29.2",
|
|
54
|
-
"schematic-symbols": "0.0.
|
|
54
|
+
"schematic-symbols": "^0.0.92",
|
|
55
55
|
"transformation-matrix": "^2.16.1",
|
|
56
56
|
"zod": "^3.23.8"
|
|
57
57
|
}
|