@tscircuit/core 0.0.1448 → 0.0.1449
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.js +148 -75
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -22810,7 +22810,7 @@ function Group_getRoutingPhasePlans(group) {
|
|
|
22810
22810
|
var package_default = {
|
|
22811
22811
|
name: "@tscircuit/core",
|
|
22812
22812
|
type: "module",
|
|
22813
|
-
version: "0.0.
|
|
22813
|
+
version: "0.0.1448",
|
|
22814
22814
|
types: "dist/index.d.ts",
|
|
22815
22815
|
main: "dist/index.js",
|
|
22816
22816
|
module: "dist/index.js",
|
|
@@ -25741,6 +25741,150 @@ function inflateSourceResistor(sourceElm, inflatorContext) {
|
|
|
25741
25741
|
}
|
|
25742
25742
|
}
|
|
25743
25743
|
|
|
25744
|
+
// lib/components/normal-components/Switch.ts
|
|
25745
|
+
import { switchProps } from "@tscircuit/props";
|
|
25746
|
+
import { frequency, ms } from "circuit-json";
|
|
25747
|
+
function hasSimProps(props) {
|
|
25748
|
+
return props.simSwitchFrequency !== void 0 || props.simCloseAt !== void 0 || props.simOpenAt !== void 0 || props.simStartClosed !== void 0 || props.simStartOpen !== void 0;
|
|
25749
|
+
}
|
|
25750
|
+
var Switch = class extends NormalComponent3 {
|
|
25751
|
+
_getSwitchType() {
|
|
25752
|
+
const props = this._parsedProps;
|
|
25753
|
+
if (!props) return "spst";
|
|
25754
|
+
if (props.dpdt) return "dpdt";
|
|
25755
|
+
if (props.spst) return "spst";
|
|
25756
|
+
if (props.spdt) return "spdt";
|
|
25757
|
+
if (props.dpst) return "dpst";
|
|
25758
|
+
return props.type ?? "spst";
|
|
25759
|
+
}
|
|
25760
|
+
get config() {
|
|
25761
|
+
const switchType = this._getSwitchType();
|
|
25762
|
+
const isNormallyClosed = this._parsedProps?.isNormallyClosed ?? false;
|
|
25763
|
+
const symbolMap = {
|
|
25764
|
+
spst: isNormallyClosed ? "spst_normally_closed_switch" : "spst_switch",
|
|
25765
|
+
spdt: isNormallyClosed ? "spdt_normally_closed_switch" : "spdt_switch",
|
|
25766
|
+
dpst: isNormallyClosed ? "dpst_normally_closed_switch" : "dpst_switch",
|
|
25767
|
+
dpdt: isNormallyClosed ? "dpdt_normally_closed_switch" : "dpdt_switch"
|
|
25768
|
+
};
|
|
25769
|
+
return {
|
|
25770
|
+
componentName: "Switch",
|
|
25771
|
+
schematicSymbolName: this.props.symbolName ?? symbolMap[switchType],
|
|
25772
|
+
zodProps: switchProps,
|
|
25773
|
+
shouldRenderAsSchematicBox: false
|
|
25774
|
+
};
|
|
25775
|
+
}
|
|
25776
|
+
doInitialSourceRender() {
|
|
25777
|
+
const { db } = this.root;
|
|
25778
|
+
const props = this._parsedProps ?? {};
|
|
25779
|
+
const source_component = db.source_component.insert({
|
|
25780
|
+
ftype: "simple_switch",
|
|
25781
|
+
name: this.name,
|
|
25782
|
+
are_pins_interchangeable: this._getSwitchType() === "spst",
|
|
25783
|
+
display_name: props?.displayName
|
|
25784
|
+
});
|
|
25785
|
+
this.source_component_id = source_component.source_component_id;
|
|
25786
|
+
}
|
|
25787
|
+
doInitialSimulationRender() {
|
|
25788
|
+
const { _parsedProps: props } = this;
|
|
25789
|
+
if (!hasSimProps(props)) {
|
|
25790
|
+
return;
|
|
25791
|
+
}
|
|
25792
|
+
const { db } = this.root;
|
|
25793
|
+
const simulationSwitch = {
|
|
25794
|
+
type: "simulation_switch",
|
|
25795
|
+
source_component_id: this.source_component_id || ""
|
|
25796
|
+
};
|
|
25797
|
+
if (props.simSwitchFrequency !== void 0) {
|
|
25798
|
+
simulationSwitch.switching_frequency = frequency.parse(
|
|
25799
|
+
props.simSwitchFrequency
|
|
25800
|
+
);
|
|
25801
|
+
}
|
|
25802
|
+
if (props.simCloseAt !== void 0) {
|
|
25803
|
+
simulationSwitch.closes_at = ms.parse(props.simCloseAt);
|
|
25804
|
+
}
|
|
25805
|
+
if (props.simOpenAt !== void 0) {
|
|
25806
|
+
simulationSwitch.opens_at = ms.parse(props.simOpenAt);
|
|
25807
|
+
}
|
|
25808
|
+
if (props.simStartOpen !== void 0) {
|
|
25809
|
+
simulationSwitch.starts_closed = !props.simStartOpen;
|
|
25810
|
+
}
|
|
25811
|
+
if (props.simStartClosed !== void 0) {
|
|
25812
|
+
simulationSwitch.starts_closed = props.simStartClosed;
|
|
25813
|
+
}
|
|
25814
|
+
db.simulation_switch.insert(simulationSwitch);
|
|
25815
|
+
}
|
|
25816
|
+
};
|
|
25817
|
+
|
|
25818
|
+
// lib/components/primitive-components/Group/Subcircuit/inflators/inflateSourceSwitch.ts
|
|
25819
|
+
var getImportedSwitchProps = (sourceElm, inflatorContext) => {
|
|
25820
|
+
const sourcePorts = inflatorContext.injectionDb.source_port.list().filter(
|
|
25821
|
+
(port) => port.source_component_id === sourceElm.source_component_id
|
|
25822
|
+
);
|
|
25823
|
+
const pinLabels = {};
|
|
25824
|
+
let highestPinNumber = 0;
|
|
25825
|
+
for (const sourcePort of sourcePorts) {
|
|
25826
|
+
const pinNumber = sourcePort.pin_number;
|
|
25827
|
+
if (pinNumber === void 0 || pinNumber === null) continue;
|
|
25828
|
+
highestPinNumber = Math.max(highestPinNumber, pinNumber);
|
|
25829
|
+
const labels = Array.from(
|
|
25830
|
+
new Set(
|
|
25831
|
+
[sourcePort.name, ...sourcePort.port_hints ?? []].filter(
|
|
25832
|
+
(label) => typeof label === "string" && label.length > 0
|
|
25833
|
+
)
|
|
25834
|
+
)
|
|
25835
|
+
);
|
|
25836
|
+
if (labels.length > 0) {
|
|
25837
|
+
pinLabels[`pin${pinNumber}`] = labels;
|
|
25838
|
+
}
|
|
25839
|
+
}
|
|
25840
|
+
let type = "spst";
|
|
25841
|
+
if (highestPinNumber >= 5) type = "dpdt";
|
|
25842
|
+
else if (highestPinNumber === 4) type = "dpst";
|
|
25843
|
+
else if (highestPinNumber === 3) type = "spdt";
|
|
25844
|
+
return {
|
|
25845
|
+
type,
|
|
25846
|
+
pinLabels: Object.keys(pinLabels).length > 0 ? pinLabels : void 0
|
|
25847
|
+
};
|
|
25848
|
+
};
|
|
25849
|
+
function inflateSourceSwitch(sourceElm, inflatorContext) {
|
|
25850
|
+
const { injectionDb, subcircuit, groupsMap } = inflatorContext;
|
|
25851
|
+
const pcbElm = injectionDb.pcb_component.getWhere({
|
|
25852
|
+
source_component_id: sourceElm.source_component_id
|
|
25853
|
+
});
|
|
25854
|
+
const { pcbX, pcbY } = getInflatedPcbPlacement({
|
|
25855
|
+
pcbComponent: pcbElm,
|
|
25856
|
+
sourceGroupId: sourceElm.source_group_id,
|
|
25857
|
+
inflatorContext
|
|
25858
|
+
});
|
|
25859
|
+
const importedSwitchProps = getImportedSwitchProps(sourceElm, inflatorContext);
|
|
25860
|
+
const switchComponent = new Switch({
|
|
25861
|
+
name: sourceElm.name,
|
|
25862
|
+
displayName: sourceElm.display_name,
|
|
25863
|
+
...importedSwitchProps,
|
|
25864
|
+
layer: pcbElm?.layer,
|
|
25865
|
+
pcbX,
|
|
25866
|
+
pcbY,
|
|
25867
|
+
pcbRotation: pcbElm?.rotation,
|
|
25868
|
+
doNotPlace: pcbElm?.do_not_place,
|
|
25869
|
+
obstructsWithinBounds: pcbElm?.obstructs_within_bounds
|
|
25870
|
+
});
|
|
25871
|
+
if (pcbElm) {
|
|
25872
|
+
const footprint = inflateFootprintComponent(pcbElm, {
|
|
25873
|
+
...inflatorContext,
|
|
25874
|
+
normalComponent: switchComponent
|
|
25875
|
+
});
|
|
25876
|
+
if (footprint) {
|
|
25877
|
+
switchComponent.add(footprint);
|
|
25878
|
+
}
|
|
25879
|
+
}
|
|
25880
|
+
if (sourceElm.source_group_id && groupsMap?.has(sourceElm.source_group_id)) {
|
|
25881
|
+
const group = groupsMap.get(sourceElm.source_group_id);
|
|
25882
|
+
group.add(switchComponent);
|
|
25883
|
+
} else {
|
|
25884
|
+
subcircuit.add(switchComponent);
|
|
25885
|
+
}
|
|
25886
|
+
}
|
|
25887
|
+
|
|
25744
25888
|
// lib/utils/pcbTraceRouteToPcbPath.ts
|
|
25745
25889
|
function pcbTraceRouteToPcbPath(route) {
|
|
25746
25890
|
if (route.length <= 2) {
|
|
@@ -26053,6 +26197,9 @@ var inflateCircuitJson = (target, circuitJson, children) => {
|
|
|
26053
26197
|
case "simple_push_button":
|
|
26054
26198
|
inflateSourcePushButton(sourceComponent, inflationCtx);
|
|
26055
26199
|
break;
|
|
26200
|
+
case "simple_switch":
|
|
26201
|
+
inflateSourceSwitch(sourceComponent, inflationCtx);
|
|
26202
|
+
break;
|
|
26056
26203
|
default:
|
|
26057
26204
|
throw new Error(
|
|
26058
26205
|
`No inflator implemented for source component ftype: "${sourceComponent.ftype}"`
|
|
@@ -32386,80 +32533,6 @@ var OpAmp = class extends NormalComponent3 {
|
|
|
32386
32533
|
negative_supply = this.portMap.negative_supply;
|
|
32387
32534
|
};
|
|
32388
32535
|
|
|
32389
|
-
// lib/components/normal-components/Switch.ts
|
|
32390
|
-
import { switchProps } from "@tscircuit/props";
|
|
32391
|
-
import { frequency, ms } from "circuit-json";
|
|
32392
|
-
function hasSimProps(props) {
|
|
32393
|
-
return props.simSwitchFrequency !== void 0 || props.simCloseAt !== void 0 || props.simOpenAt !== void 0 || props.simStartClosed !== void 0 || props.simStartOpen !== void 0;
|
|
32394
|
-
}
|
|
32395
|
-
var Switch = class extends NormalComponent3 {
|
|
32396
|
-
_getSwitchType() {
|
|
32397
|
-
const props = this._parsedProps;
|
|
32398
|
-
if (!props) return "spst";
|
|
32399
|
-
if (props.dpdt) return "dpdt";
|
|
32400
|
-
if (props.spst) return "spst";
|
|
32401
|
-
if (props.spdt) return "spdt";
|
|
32402
|
-
if (props.dpst) return "dpst";
|
|
32403
|
-
return props.type ?? "spst";
|
|
32404
|
-
}
|
|
32405
|
-
get config() {
|
|
32406
|
-
const switchType = this._getSwitchType();
|
|
32407
|
-
const isNormallyClosed = this._parsedProps?.isNormallyClosed ?? false;
|
|
32408
|
-
const symbolMap = {
|
|
32409
|
-
spst: isNormallyClosed ? "spst_normally_closed_switch" : "spst_switch",
|
|
32410
|
-
spdt: isNormallyClosed ? "spdt_normally_closed_switch" : "spdt_switch",
|
|
32411
|
-
dpst: isNormallyClosed ? "dpst_normally_closed_switch" : "dpst_switch",
|
|
32412
|
-
dpdt: isNormallyClosed ? "dpdt_normally_closed_switch" : "dpdt_switch"
|
|
32413
|
-
};
|
|
32414
|
-
return {
|
|
32415
|
-
componentName: "Switch",
|
|
32416
|
-
schematicSymbolName: this.props.symbolName ?? symbolMap[switchType],
|
|
32417
|
-
zodProps: switchProps,
|
|
32418
|
-
shouldRenderAsSchematicBox: false
|
|
32419
|
-
};
|
|
32420
|
-
}
|
|
32421
|
-
doInitialSourceRender() {
|
|
32422
|
-
const { db } = this.root;
|
|
32423
|
-
const props = this._parsedProps ?? {};
|
|
32424
|
-
const source_component = db.source_component.insert({
|
|
32425
|
-
ftype: "simple_switch",
|
|
32426
|
-
name: this.name,
|
|
32427
|
-
are_pins_interchangeable: this._getSwitchType() === "spst",
|
|
32428
|
-
display_name: props?.displayName
|
|
32429
|
-
});
|
|
32430
|
-
this.source_component_id = source_component.source_component_id;
|
|
32431
|
-
}
|
|
32432
|
-
doInitialSimulationRender() {
|
|
32433
|
-
const { _parsedProps: props } = this;
|
|
32434
|
-
if (!hasSimProps(props)) {
|
|
32435
|
-
return;
|
|
32436
|
-
}
|
|
32437
|
-
const { db } = this.root;
|
|
32438
|
-
const simulationSwitch = {
|
|
32439
|
-
type: "simulation_switch",
|
|
32440
|
-
source_component_id: this.source_component_id || ""
|
|
32441
|
-
};
|
|
32442
|
-
if (props.simSwitchFrequency !== void 0) {
|
|
32443
|
-
simulationSwitch.switching_frequency = frequency.parse(
|
|
32444
|
-
props.simSwitchFrequency
|
|
32445
|
-
);
|
|
32446
|
-
}
|
|
32447
|
-
if (props.simCloseAt !== void 0) {
|
|
32448
|
-
simulationSwitch.closes_at = ms.parse(props.simCloseAt);
|
|
32449
|
-
}
|
|
32450
|
-
if (props.simOpenAt !== void 0) {
|
|
32451
|
-
simulationSwitch.opens_at = ms.parse(props.simOpenAt);
|
|
32452
|
-
}
|
|
32453
|
-
if (props.simStartOpen !== void 0) {
|
|
32454
|
-
simulationSwitch.starts_closed = !props.simStartOpen;
|
|
32455
|
-
}
|
|
32456
|
-
if (props.simStartClosed !== void 0) {
|
|
32457
|
-
simulationSwitch.starts_closed = props.simStartClosed;
|
|
32458
|
-
}
|
|
32459
|
-
db.simulation_switch.insert(simulationSwitch);
|
|
32460
|
-
}
|
|
32461
|
-
};
|
|
32462
|
-
|
|
32463
32536
|
// lib/components/normal-components/TestPoint.ts
|
|
32464
32537
|
import { testpointProps } from "@tscircuit/props";
|
|
32465
32538
|
var TESTPOINT_DEFAULTS = {
|