@tscircuit/core 0.0.1014 → 0.0.1016
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 +505 -270
- package/dist/index.js +157 -22
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -472,6 +472,47 @@ var InvalidProps = class extends Error {
|
|
|
472
472
|
// lib/fiber/create-instance-from-react-element.ts
|
|
473
473
|
import { identity as identity2 } from "transformation-matrix";
|
|
474
474
|
|
|
475
|
+
// lib/utils/pcbSx/convert-pcb-style-to-pcb-sx.ts
|
|
476
|
+
function convertPcbStyleToPcbSx(pcbStyle) {
|
|
477
|
+
if (!pcbStyle) return void 0;
|
|
478
|
+
const sx = {};
|
|
479
|
+
if (pcbStyle.silkscreenFontSize !== void 0) {
|
|
480
|
+
sx["& silkscreentext"] = {
|
|
481
|
+
fontSize: pcbStyle.silkscreenFontSize
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
if (Object.keys(sx).length === 0) return void 0;
|
|
485
|
+
return sx;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
// lib/utils/pcbSx/get-resolved-pcb-sx.ts
|
|
489
|
+
function getResolvedPcbSx({
|
|
490
|
+
parentResolvedPcbSx,
|
|
491
|
+
pcbStyle,
|
|
492
|
+
ownPcbSx
|
|
493
|
+
}) {
|
|
494
|
+
const styleSx = convertPcbStyleToPcbSx(pcbStyle);
|
|
495
|
+
const result = {};
|
|
496
|
+
const allKeys = /* @__PURE__ */ new Set();
|
|
497
|
+
if (parentResolvedPcbSx) {
|
|
498
|
+
for (const k of Object.keys(parentResolvedPcbSx)) allKeys.add(k);
|
|
499
|
+
}
|
|
500
|
+
if (styleSx) {
|
|
501
|
+
for (const k of Object.keys(styleSx)) allKeys.add(k);
|
|
502
|
+
}
|
|
503
|
+
if (ownPcbSx) {
|
|
504
|
+
for (const k of Object.keys(ownPcbSx)) allKeys.add(k);
|
|
505
|
+
}
|
|
506
|
+
for (const key of allKeys) {
|
|
507
|
+
result[key] = {
|
|
508
|
+
...parentResolvedPcbSx?.[key],
|
|
509
|
+
...styleSx?.[key],
|
|
510
|
+
...ownPcbSx?.[key]
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
return result;
|
|
514
|
+
}
|
|
515
|
+
|
|
475
516
|
// lib/components/base-components/PrimitiveComponent/PrimitiveComponent.ts
|
|
476
517
|
import "debug";
|
|
477
518
|
|
|
@@ -891,6 +932,13 @@ var PrimitiveComponent2 = class extends Renderable {
|
|
|
891
932
|
const myPropertyObject = this._parsedProps?.[propertyName];
|
|
892
933
|
return { ...parentPropertyObject, ...myPropertyObject };
|
|
893
934
|
}
|
|
935
|
+
getResolvedPcbSx() {
|
|
936
|
+
return getResolvedPcbSx({
|
|
937
|
+
parentResolvedPcbSx: this.parent?.getResolvedPcbSx?.(),
|
|
938
|
+
pcbStyle: this._parsedProps?.pcbStyle,
|
|
939
|
+
ownPcbSx: this._parsedProps?.pcbSx
|
|
940
|
+
});
|
|
941
|
+
}
|
|
894
942
|
get lowercaseComponentName() {
|
|
895
943
|
return this.componentName.toLowerCase();
|
|
896
944
|
}
|
|
@@ -3326,10 +3374,86 @@ function normalizeTextForCircuitJson(text) {
|
|
|
3326
3374
|
return text.replace(/\\n/g, "\n");
|
|
3327
3375
|
}
|
|
3328
3376
|
|
|
3377
|
+
// lib/utils/pcbSx/resolve-pcb-property.ts
|
|
3378
|
+
function parseSegment(seg) {
|
|
3379
|
+
const bracketIdx = seg.indexOf("[");
|
|
3380
|
+
if (bracketIdx === -1) return { tag: seg };
|
|
3381
|
+
const tag = seg.slice(0, bracketIdx);
|
|
3382
|
+
const attrPart = seg.slice(bracketIdx + 1, seg.lastIndexOf("]"));
|
|
3383
|
+
const m = attrPart.match(/^(\w+)(\^=|\$=|=)['"]?(.*?)['"]?$/);
|
|
3384
|
+
if (!m) return { tag };
|
|
3385
|
+
return { tag, attrName: m[1], attrOp: m[2], attrValue: m[3] };
|
|
3386
|
+
}
|
|
3387
|
+
function componentMatchesSegment(component, seg) {
|
|
3388
|
+
if (component.lowercaseComponentName !== seg.tag) return false;
|
|
3389
|
+
if (!seg.attrName) return true;
|
|
3390
|
+
const attrVal = component.props?.[seg.attrName];
|
|
3391
|
+
if (attrVal === void 0) return false;
|
|
3392
|
+
const valStr = String(attrVal);
|
|
3393
|
+
switch (seg.attrOp) {
|
|
3394
|
+
case "^=":
|
|
3395
|
+
return valStr.startsWith(seg.attrValue);
|
|
3396
|
+
case "$=":
|
|
3397
|
+
return valStr.endsWith(seg.attrValue);
|
|
3398
|
+
case "=":
|
|
3399
|
+
return valStr === seg.attrValue;
|
|
3400
|
+
default:
|
|
3401
|
+
return false;
|
|
3402
|
+
}
|
|
3403
|
+
}
|
|
3404
|
+
function matchesCompoundSelector(component, segments) {
|
|
3405
|
+
if (!componentMatchesSegment(component, segments[segments.length - 1])) {
|
|
3406
|
+
return false;
|
|
3407
|
+
}
|
|
3408
|
+
let segIdx = segments.length - 2;
|
|
3409
|
+
let current = component.parent;
|
|
3410
|
+
while (segIdx >= 0 && current) {
|
|
3411
|
+
if (componentMatchesSegment(current, segments[segIdx])) {
|
|
3412
|
+
segIdx--;
|
|
3413
|
+
}
|
|
3414
|
+
current = current.parent;
|
|
3415
|
+
}
|
|
3416
|
+
return segIdx < 0;
|
|
3417
|
+
}
|
|
3418
|
+
function resolvePcbProperty({
|
|
3419
|
+
propertyName,
|
|
3420
|
+
resolvedPcbSx,
|
|
3421
|
+
pathFromAmpersand,
|
|
3422
|
+
component
|
|
3423
|
+
}) {
|
|
3424
|
+
if (!resolvedPcbSx) return void 0;
|
|
3425
|
+
let result;
|
|
3426
|
+
let bestSpecificity = 0;
|
|
3427
|
+
for (const [key, entry] of Object.entries(resolvedPcbSx)) {
|
|
3428
|
+
if (!entry || !(propertyName in entry)) continue;
|
|
3429
|
+
const selectorBody = key.startsWith("& ") ? key.slice(2) : key;
|
|
3430
|
+
if (selectorBody === pathFromAmpersand) {
|
|
3431
|
+
const specificity = 1;
|
|
3432
|
+
if (specificity > bestSpecificity) {
|
|
3433
|
+
bestSpecificity = specificity;
|
|
3434
|
+
result = entry[propertyName];
|
|
3435
|
+
}
|
|
3436
|
+
continue;
|
|
3437
|
+
}
|
|
3438
|
+
if (!component) continue;
|
|
3439
|
+
const segments = selectorBody.split(/\s+/).map(parseSegment);
|
|
3440
|
+
if (segments.length < 2) continue;
|
|
3441
|
+
if (matchesCompoundSelector(component, segments)) {
|
|
3442
|
+
const specificity = segments.length;
|
|
3443
|
+
if (specificity > bestSpecificity) {
|
|
3444
|
+
bestSpecificity = specificity;
|
|
3445
|
+
result = entry[propertyName];
|
|
3446
|
+
}
|
|
3447
|
+
}
|
|
3448
|
+
}
|
|
3449
|
+
return result;
|
|
3450
|
+
}
|
|
3451
|
+
|
|
3329
3452
|
// lib/components/primitive-components/SilkscreenText.ts
|
|
3330
3453
|
var SilkscreenText = class extends PrimitiveComponent2 {
|
|
3331
3454
|
pcb_silkscreen_text_ids = [];
|
|
3332
3455
|
isPcbPrimitive = true;
|
|
3456
|
+
_footprinterFontSize;
|
|
3333
3457
|
get config() {
|
|
3334
3458
|
return {
|
|
3335
3459
|
componentName: "SilkscreenText",
|
|
@@ -3358,7 +3482,13 @@ var SilkscreenText = class extends PrimitiveComponent2 {
|
|
|
3358
3482
|
const uniqueLayers = new Set(props.layers);
|
|
3359
3483
|
if (props.layer) uniqueLayers.add(props.layer);
|
|
3360
3484
|
const targetLayers = uniqueLayers.size > 0 ? Array.from(uniqueLayers) : ["top"];
|
|
3361
|
-
const
|
|
3485
|
+
const resolvedPcbSxFontSize = resolvePcbProperty({
|
|
3486
|
+
propertyName: "fontSize",
|
|
3487
|
+
resolvedPcbSx: this.getResolvedPcbSx(),
|
|
3488
|
+
pathFromAmpersand: "silkscreentext",
|
|
3489
|
+
component: this
|
|
3490
|
+
});
|
|
3491
|
+
const fontSize = props.fontSize ?? resolvedPcbSxFontSize ?? this.getInheritedProperty("pcbStyle")?.silkscreenFontSize ?? this._footprinterFontSize ?? 1;
|
|
3362
3492
|
for (const layer of targetLayers) {
|
|
3363
3493
|
const pcb_silkscreen_text = db.pcb_silkscreen_text.insert({
|
|
3364
3494
|
anchor_alignment: props.anchorAlignment,
|
|
@@ -3382,7 +3512,13 @@ var SilkscreenText = class extends PrimitiveComponent2 {
|
|
|
3382
3512
|
}
|
|
3383
3513
|
getPcbSize() {
|
|
3384
3514
|
const { _parsedProps: props } = this;
|
|
3385
|
-
const
|
|
3515
|
+
const resolvedPcbSxFontSize = resolvePcbProperty({
|
|
3516
|
+
propertyName: "fontSize",
|
|
3517
|
+
resolvedPcbSx: this.getResolvedPcbSx(),
|
|
3518
|
+
pathFromAmpersand: "silkscreentext",
|
|
3519
|
+
component: this
|
|
3520
|
+
});
|
|
3521
|
+
const fontSize = props.fontSize ?? resolvedPcbSxFontSize ?? this.getInheritedProperty("pcbStyle")?.silkscreenFontSize ?? this._footprinterFontSize ?? 1;
|
|
3386
3522
|
const text = props.text ?? "";
|
|
3387
3523
|
const textWidth = text.length * fontSize;
|
|
3388
3524
|
const textHeight = fontSize;
|
|
@@ -3600,15 +3736,16 @@ var createPinrowSilkscreenText = ({
|
|
|
3600
3736
|
} else if (typeof pinLabels === "object") {
|
|
3601
3737
|
label = String(pinLabels[pinNum] ?? pinNum);
|
|
3602
3738
|
}
|
|
3603
|
-
|
|
3739
|
+
const silkscreenText = new SilkscreenText({
|
|
3604
3740
|
anchorAlignment: anchorAlignment || "center",
|
|
3605
3741
|
text: label ?? pinNum,
|
|
3606
3742
|
layer: layer || "top",
|
|
3607
|
-
fontSize: elm.font_size + 0.2,
|
|
3608
3743
|
pcbX: isNaN(elm.anchor_position.x) ? 0 : elm.anchor_position.x,
|
|
3609
3744
|
pcbY: elm.anchor_position.y,
|
|
3610
3745
|
pcbRotation: readableRotation ?? 0
|
|
3611
3746
|
});
|
|
3747
|
+
silkscreenText._footprinterFontSize = elm.font_size + 0.2;
|
|
3748
|
+
return silkscreenText;
|
|
3612
3749
|
};
|
|
3613
3750
|
|
|
3614
3751
|
// lib/utils/createComponentsFromCircuitJson.ts
|
|
@@ -3853,16 +3990,15 @@ var createComponentsFromCircuitJson = ({
|
|
|
3853
3990
|
})
|
|
3854
3991
|
);
|
|
3855
3992
|
} else {
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
);
|
|
3993
|
+
const silkscreenText = new SilkscreenText({
|
|
3994
|
+
anchorAlignment: elm.anchor_alignment || "center",
|
|
3995
|
+
text: componentName || elm.text,
|
|
3996
|
+
pcbX: Number.isNaN(elm.anchor_position.x) ? 0 : elm.anchor_position.x,
|
|
3997
|
+
pcbY: elm.anchor_position.y,
|
|
3998
|
+
pcbRotation: ccwRotation ?? 0
|
|
3999
|
+
});
|
|
4000
|
+
silkscreenText._footprinterFontSize = elm.font_size + 0.2;
|
|
4001
|
+
components.push(silkscreenText);
|
|
3866
4002
|
}
|
|
3867
4003
|
} else if (elm.type === "pcb_trace") {
|
|
3868
4004
|
components.push(
|
|
@@ -8484,12 +8620,9 @@ function NormalComponent_doInitialPcbFootprintStringRender(component, queueAsync
|
|
|
8484
8620
|
resolverFn = libMap;
|
|
8485
8621
|
}
|
|
8486
8622
|
if (!resolverFn) return;
|
|
8487
|
-
const resolvedPcbStyle = component.getInheritedMergedProperty("pcbStyle");
|
|
8488
8623
|
queueAsyncEffect("load-lib-footprint", async () => {
|
|
8489
8624
|
try {
|
|
8490
|
-
const result = await resolverFn(libRef.footprintName
|
|
8491
|
-
resolvedPcbStyle
|
|
8492
|
-
});
|
|
8625
|
+
const result = await resolverFn(libRef.footprintName);
|
|
8493
8626
|
let circuitJson = null;
|
|
8494
8627
|
if (Array.isArray(result)) {
|
|
8495
8628
|
circuitJson = result;
|
|
@@ -8507,7 +8640,9 @@ function NormalComponent_doInitialPcbFootprintStringRender(component, queueAsync
|
|
|
8507
8640
|
},
|
|
8508
8641
|
circuitJson
|
|
8509
8642
|
);
|
|
8510
|
-
|
|
8643
|
+
const fpWrapper = new Footprint({ src: footprint });
|
|
8644
|
+
for (const c of fpComponents) fpWrapper.add(c);
|
|
8645
|
+
component.add(fpWrapper);
|
|
8511
8646
|
if (!Array.isArray(result) && result.cadModel) {
|
|
8512
8647
|
component._asyncFootprintCadModel = result.cadModel;
|
|
8513
8648
|
}
|
|
@@ -16747,7 +16882,7 @@ var Board = class extends Group6 {
|
|
|
16747
16882
|
);
|
|
16748
16883
|
}
|
|
16749
16884
|
let outlineTranslation = { x: 0, y: 0 };
|
|
16750
|
-
if (outline && outline.length > 0 && this.parent?.lowercaseComponentName === "panel") {
|
|
16885
|
+
if (outline && outline.length > 0 && (this.parent?.lowercaseComponentName === "panel" || this.parent?.lowercaseComponentName === "subpanel")) {
|
|
16751
16886
|
const outlineBounds = getBoundsFromPoints4(outline);
|
|
16752
16887
|
if (outlineBounds) {
|
|
16753
16888
|
const outlineCenterX = (outlineBounds.minX + outlineBounds.maxX) / 2;
|
|
@@ -22093,7 +22228,7 @@ import { identity as identity5 } from "transformation-matrix";
|
|
|
22093
22228
|
var package_default = {
|
|
22094
22229
|
name: "@tscircuit/core",
|
|
22095
22230
|
type: "module",
|
|
22096
|
-
version: "0.0.
|
|
22231
|
+
version: "0.0.1015",
|
|
22097
22232
|
types: "dist/index.d.ts",
|
|
22098
22233
|
main: "dist/index.js",
|
|
22099
22234
|
module: "dist/index.js",
|
|
@@ -22137,7 +22272,7 @@ var package_default = {
|
|
|
22137
22272
|
"@tscircuit/math-utils": "^0.0.29",
|
|
22138
22273
|
"@tscircuit/miniflex": "^0.0.4",
|
|
22139
22274
|
"@tscircuit/ngspice-spice-engine": "^0.0.8",
|
|
22140
|
-
"@tscircuit/props": "^0.0.
|
|
22275
|
+
"@tscircuit/props": "^0.0.470",
|
|
22141
22276
|
"@tscircuit/schematic-match-adapt": "^0.0.16",
|
|
22142
22277
|
"@tscircuit/schematic-trace-solver": "^v0.0.45",
|
|
22143
22278
|
"@tscircuit/solver-utils": "^0.0.3",
|
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.1016",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.js",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"@tscircuit/math-utils": "^0.0.29",
|
|
46
46
|
"@tscircuit/miniflex": "^0.0.4",
|
|
47
47
|
"@tscircuit/ngspice-spice-engine": "^0.0.8",
|
|
48
|
-
"@tscircuit/props": "^0.0.
|
|
48
|
+
"@tscircuit/props": "^0.0.470",
|
|
49
49
|
"@tscircuit/schematic-match-adapt": "^0.0.16",
|
|
50
50
|
"@tscircuit/schematic-trace-solver": "^v0.0.45",
|
|
51
51
|
"@tscircuit/solver-utils": "^0.0.3",
|