@tscircuit/core 0.0.45 → 0.0.47
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 +3 -1
- package/dist/index.js +79 -67
- package/lib/components/base-components/Renderable.ts +2 -0
- package/lib/components/primitive-components/Group.ts +28 -1
- package/lib/components/primitive-components/Trace.ts +3 -14
- package/lib/components/primitive-components/TraceHint.ts +11 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -41,7 +41,7 @@ declare class Circuit {
|
|
|
41
41
|
*/
|
|
42
42
|
declare const Project: typeof Circuit;
|
|
43
43
|
|
|
44
|
-
declare const orderedRenderPhases: readonly ["ReactSubtreesRender", "InitializePortsFromChildren", "CreateNetsFromProps", "CreateTracesFromProps", "SourceRender", "SourceParentAttachment", "PortDiscovery", "PortMatching", "SourceTraceRender", "SchematicComponentRender", "SchematicLayout", "SchematicPortRender", "SchematicTraceRender", "PcbComponentRender", "PcbPrimitiveRender", "PcbFootprintLayout", "PcbPortRender", "PcbPortAttachment", "PcbLayout", "PcbTraceRender", "PcbRouteNetIslands", "PcbComponentSizeCalculation", "CadModelRender"];
|
|
44
|
+
declare const orderedRenderPhases: readonly ["ReactSubtreesRender", "InitializePortsFromChildren", "CreateNetsFromProps", "CreateTracesFromProps", "CreateTraceHintsFromProps", "SourceRender", "SourceParentAttachment", "PortDiscovery", "PortMatching", "SourceTraceRender", "SchematicComponentRender", "SchematicLayout", "SchematicPortRender", "SchematicTraceRender", "PcbComponentRender", "PcbPrimitiveRender", "PcbFootprintLayout", "PcbPortRender", "PcbPortAttachment", "PcbLayout", "PcbTraceRender", "PcbTraceHintRender", "PcbRouteNetIslands", "PcbComponentSizeCalculation", "CadModelRender"];
|
|
45
45
|
type RenderPhase = (typeof orderedRenderPhases)[number];
|
|
46
46
|
type RenderPhaseFn<K extends RenderPhase = RenderPhase> = `doInitial${K}` | `update${K}` | `remove${K}`;
|
|
47
47
|
type RenderPhaseStates = Record<RenderPhase, {
|
|
@@ -643,6 +643,7 @@ declare class Group<Props extends z.ZodType<any, any, any> = typeof groupProps>
|
|
|
643
643
|
get config(): {
|
|
644
644
|
zodProps: Props;
|
|
645
645
|
};
|
|
646
|
+
doInitialCreateTraceHintsFromProps(): void;
|
|
646
647
|
}
|
|
647
648
|
|
|
648
649
|
declare class Board extends Group<typeof boardProps> {
|
|
@@ -2448,6 +2449,7 @@ declare class TraceHint extends PrimitiveComponent<typeof traceHintProps> {
|
|
|
2448
2449
|
matchedPort: Port | null;
|
|
2449
2450
|
doInitialPortMatching(): void;
|
|
2450
2451
|
getPcbRouteHints(): Array<RouteHintPoint>;
|
|
2452
|
+
doInitialPcbTraceHintRender(): void;
|
|
2451
2453
|
}
|
|
2452
2454
|
|
|
2453
2455
|
interface SchematicBoxDimensions {
|
package/dist/index.js
CHANGED
|
@@ -44,6 +44,7 @@ var orderedRenderPhases = [
|
|
|
44
44
|
"InitializePortsFromChildren",
|
|
45
45
|
"CreateNetsFromProps",
|
|
46
46
|
"CreateTracesFromProps",
|
|
47
|
+
"CreateTraceHintsFromProps",
|
|
47
48
|
"SourceRender",
|
|
48
49
|
"SourceParentAttachment",
|
|
49
50
|
"PortDiscovery",
|
|
@@ -60,6 +61,7 @@ var orderedRenderPhases = [
|
|
|
60
61
|
"PcbPortAttachment",
|
|
61
62
|
"PcbLayout",
|
|
62
63
|
"PcbTraceRender",
|
|
64
|
+
"PcbTraceHintRender",
|
|
63
65
|
"PcbRouteNetIslands",
|
|
64
66
|
"PcbComponentSizeCalculation",
|
|
65
67
|
"CadModelRender"
|
|
@@ -164,20 +166,6 @@ function isMatchingSelector(component, selector) {
|
|
|
164
166
|
});
|
|
165
167
|
}
|
|
166
168
|
|
|
167
|
-
// lib/utils/selector-matching/is-matching-path-selector.ts
|
|
168
|
-
function isMatchingPathSelector(component, selector) {
|
|
169
|
-
const selectorParts = selector.split(/\> /g).map((part) => part.trim());
|
|
170
|
-
let currentComponent = component;
|
|
171
|
-
for (let i = selectorParts.length - 1; i >= 0; i--) {
|
|
172
|
-
if (!currentComponent) return false;
|
|
173
|
-
if (!isMatchingSelector(currentComponent, selectorParts[i])) {
|
|
174
|
-
return false;
|
|
175
|
-
}
|
|
176
|
-
currentComponent = currentComponent.parent;
|
|
177
|
-
}
|
|
178
|
-
return true;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
169
|
// lib/components/base-components/PrimitiveComponent.ts
|
|
182
170
|
var PrimitiveComponent = class extends Renderable {
|
|
183
171
|
parent = null;
|
|
@@ -1948,15 +1936,89 @@ import { boardProps } from "@tscircuit/props";
|
|
|
1948
1936
|
import { identity as identity4 } from "transformation-matrix";
|
|
1949
1937
|
|
|
1950
1938
|
// lib/components/primitive-components/Group.ts
|
|
1951
|
-
import {
|
|
1939
|
+
import {
|
|
1940
|
+
groupProps
|
|
1941
|
+
} from "@tscircuit/props";
|
|
1952
1942
|
import "transformation-matrix";
|
|
1953
1943
|
import "zod";
|
|
1944
|
+
|
|
1945
|
+
// lib/components/primitive-components/TraceHint.ts
|
|
1946
|
+
import "@tscircuit/props";
|
|
1947
|
+
import { applyToPoint as applyToPoint4 } from "transformation-matrix";
|
|
1948
|
+
var TraceHint = class extends PrimitiveComponent {
|
|
1949
|
+
matchedPort = null;
|
|
1950
|
+
doInitialPortMatching() {
|
|
1951
|
+
const { db } = this.root;
|
|
1952
|
+
const { _parsedProps: props, parent } = this;
|
|
1953
|
+
if (!parent) return;
|
|
1954
|
+
if (parent.componentName === "Trace") {
|
|
1955
|
+
this.renderError(
|
|
1956
|
+
`Port inference inside trace is not yet supported (${this})`
|
|
1957
|
+
);
|
|
1958
|
+
return;
|
|
1959
|
+
}
|
|
1960
|
+
if (!parent) throw new Error("TraceHint has no parent");
|
|
1961
|
+
if (!props.for) {
|
|
1962
|
+
this.renderError(`TraceHint has no for property (${this})`);
|
|
1963
|
+
return;
|
|
1964
|
+
}
|
|
1965
|
+
const port = parent.selectOne(props.for, { type: "port" });
|
|
1966
|
+
if (!port) {
|
|
1967
|
+
this.renderError(
|
|
1968
|
+
`${this} could not find port for selector "${props.for}"`
|
|
1969
|
+
);
|
|
1970
|
+
}
|
|
1971
|
+
this.matchedPort = port;
|
|
1972
|
+
port.registerMatch(this);
|
|
1973
|
+
}
|
|
1974
|
+
getPcbRouteHints() {
|
|
1975
|
+
const { _parsedProps: props } = this;
|
|
1976
|
+
const offsets = props.offset ? [props.offset] : props.offsets;
|
|
1977
|
+
if (!offsets) return [];
|
|
1978
|
+
const globalTransform = this._computePcbGlobalTransformBeforeLayout();
|
|
1979
|
+
return offsets.map(
|
|
1980
|
+
(offset) => ({
|
|
1981
|
+
...applyToPoint4(globalTransform, offset),
|
|
1982
|
+
via: offset.via,
|
|
1983
|
+
to_layer: offset.to_layer,
|
|
1984
|
+
trace_width: offset.trace_width
|
|
1985
|
+
})
|
|
1986
|
+
);
|
|
1987
|
+
}
|
|
1988
|
+
doInitialPcbTraceHintRender() {
|
|
1989
|
+
const { db } = this.root;
|
|
1990
|
+
const { _parsedProps: props } = this;
|
|
1991
|
+
db.pcb_trace_hint.insert({
|
|
1992
|
+
pcb_component_id: this.matchedPort?.pcb_component_id,
|
|
1993
|
+
pcb_port_id: this.matchedPort?.pcb_port_id,
|
|
1994
|
+
route: this.getPcbRouteHints()
|
|
1995
|
+
});
|
|
1996
|
+
}
|
|
1997
|
+
};
|
|
1998
|
+
|
|
1999
|
+
// lib/components/primitive-components/Group.ts
|
|
1954
2000
|
var Group = class extends NormalComponent {
|
|
1955
2001
|
get config() {
|
|
1956
2002
|
return {
|
|
1957
2003
|
zodProps: groupProps
|
|
1958
2004
|
};
|
|
1959
2005
|
}
|
|
2006
|
+
doInitialCreateTraceHintsFromProps() {
|
|
2007
|
+
const { _parsedProps: props } = this;
|
|
2008
|
+
const { db } = this.root;
|
|
2009
|
+
const groupProps2 = props;
|
|
2010
|
+
if (!this.isSubcircuit) return;
|
|
2011
|
+
const manualTraceHints = groupProps2.layout?.manual_trace_hints;
|
|
2012
|
+
if (!manualTraceHints) return;
|
|
2013
|
+
for (const manualTraceHint of manualTraceHints) {
|
|
2014
|
+
this.add(
|
|
2015
|
+
new TraceHint({
|
|
2016
|
+
for: manualTraceHint.pcb_port_selector,
|
|
2017
|
+
offsets: manualTraceHint.offsets
|
|
2018
|
+
})
|
|
2019
|
+
);
|
|
2020
|
+
}
|
|
2021
|
+
}
|
|
1960
2022
|
};
|
|
1961
2023
|
|
|
1962
2024
|
// lib/components/normal-components/Board.ts
|
|
@@ -2335,13 +2397,8 @@ searched component ${targetComponent.getString()}, which has ports: ${targetComp
|
|
|
2335
2397
|
const hints = ports.flatMap(
|
|
2336
2398
|
(port) => port.matchedComponents.filter((c) => c.componentName === "TraceHint")
|
|
2337
2399
|
);
|
|
2338
|
-
const
|
|
2339
|
-
|
|
2340
|
-
manualTraceHints.filter(
|
|
2341
|
-
(hint) => ports.some(
|
|
2342
|
-
(port) => isMatchingPathSelector(port, hint.pcb_port_selector)
|
|
2343
|
-
)
|
|
2344
|
-
).flatMap((hint) => hint.offsets)
|
|
2400
|
+
const pcbRouteHints = (this._parsedProps.pcbRouteHints ?? []).concat(
|
|
2401
|
+
hints.flatMap((h) => h.getPcbRouteHints())
|
|
2345
2402
|
);
|
|
2346
2403
|
if (ports.length > 2) {
|
|
2347
2404
|
this.renderError(
|
|
@@ -2653,51 +2710,6 @@ var Capacitor = class extends NormalComponent {
|
|
|
2653
2710
|
}
|
|
2654
2711
|
};
|
|
2655
2712
|
|
|
2656
|
-
// lib/components/primitive-components/TraceHint.ts
|
|
2657
|
-
import "@tscircuit/props";
|
|
2658
|
-
import { applyToPoint as applyToPoint4 } from "transformation-matrix";
|
|
2659
|
-
var TraceHint = class extends PrimitiveComponent {
|
|
2660
|
-
matchedPort = null;
|
|
2661
|
-
doInitialPortMatching() {
|
|
2662
|
-
const { db } = this.root;
|
|
2663
|
-
const { _parsedProps: props, parent } = this;
|
|
2664
|
-
if (!parent) return;
|
|
2665
|
-
if (parent.componentName === "Trace") {
|
|
2666
|
-
this.renderError(
|
|
2667
|
-
`Port inference inside trace is not yet supported (${this})`
|
|
2668
|
-
);
|
|
2669
|
-
return;
|
|
2670
|
-
}
|
|
2671
|
-
if (!parent) throw new Error("TraceHint has no parent");
|
|
2672
|
-
if (!props.for) {
|
|
2673
|
-
this.renderError(`TraceHint has no for property (${this})`);
|
|
2674
|
-
return;
|
|
2675
|
-
}
|
|
2676
|
-
const port = parent.selectOne(props.for, { type: "port" });
|
|
2677
|
-
if (!port) {
|
|
2678
|
-
this.renderError(
|
|
2679
|
-
`${this} could not find port for selector "${props.for}"`
|
|
2680
|
-
);
|
|
2681
|
-
}
|
|
2682
|
-
this.matchedPort = port;
|
|
2683
|
-
port.registerMatch(this);
|
|
2684
|
-
}
|
|
2685
|
-
getPcbRouteHints() {
|
|
2686
|
-
const { _parsedProps: props } = this;
|
|
2687
|
-
const offsets = props.offset ? [props.offset] : props.offsets;
|
|
2688
|
-
if (!offsets) return [];
|
|
2689
|
-
const globalTransform = this._computePcbGlobalTransformBeforeLayout();
|
|
2690
|
-
return offsets.map(
|
|
2691
|
-
(offset) => ({
|
|
2692
|
-
...applyToPoint4(globalTransform, offset),
|
|
2693
|
-
via: offset.via,
|
|
2694
|
-
to_layer: offset.to_layer,
|
|
2695
|
-
trace_width: offset.trace_width
|
|
2696
|
-
})
|
|
2697
|
-
);
|
|
2698
|
-
}
|
|
2699
|
-
};
|
|
2700
|
-
|
|
2701
2713
|
// lib/components/normal-components/Chip.ts
|
|
2702
2714
|
import { chipProps } from "@tscircuit/props";
|
|
2703
2715
|
|
|
@@ -6,6 +6,7 @@ export const orderedRenderPhases = [
|
|
|
6
6
|
"InitializePortsFromChildren",
|
|
7
7
|
"CreateNetsFromProps",
|
|
8
8
|
"CreateTracesFromProps",
|
|
9
|
+
"CreateTraceHintsFromProps",
|
|
9
10
|
"SourceRender",
|
|
10
11
|
"SourceParentAttachment",
|
|
11
12
|
"PortDiscovery",
|
|
@@ -22,6 +23,7 @@ export const orderedRenderPhases = [
|
|
|
22
23
|
"PcbPortAttachment",
|
|
23
24
|
"PcbLayout",
|
|
24
25
|
"PcbTraceRender",
|
|
26
|
+
"PcbTraceHintRender",
|
|
25
27
|
"PcbRouteNetIslands",
|
|
26
28
|
"PcbComponentSizeCalculation",
|
|
27
29
|
"CadModelRender",
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
groupProps,
|
|
3
|
+
type GroupProps,
|
|
4
|
+
type SubcircuitGroupProps,
|
|
5
|
+
} from "@tscircuit/props"
|
|
2
6
|
import { PrimitiveComponent } from "../base-components/PrimitiveComponent"
|
|
3
7
|
import { compose, identity } from "transformation-matrix"
|
|
4
8
|
import { z } from "zod"
|
|
5
9
|
import { NormalComponent } from "../base-components/NormalComponent"
|
|
10
|
+
import { TraceHint } from "./TraceHint"
|
|
6
11
|
|
|
7
12
|
export class Group<
|
|
8
13
|
Props extends z.ZodType<any, any, any> = typeof groupProps,
|
|
@@ -12,4 +17,26 @@ export class Group<
|
|
|
12
17
|
zodProps: groupProps as unknown as Props,
|
|
13
18
|
}
|
|
14
19
|
}
|
|
20
|
+
|
|
21
|
+
doInitialCreateTraceHintsFromProps(): void {
|
|
22
|
+
const { _parsedProps: props } = this
|
|
23
|
+
const { db } = this.root!
|
|
24
|
+
|
|
25
|
+
const groupProps = props as SubcircuitGroupProps
|
|
26
|
+
|
|
27
|
+
if (!this.isSubcircuit) return
|
|
28
|
+
|
|
29
|
+
const manualTraceHints = groupProps.layout?.manual_trace_hints
|
|
30
|
+
|
|
31
|
+
if (!manualTraceHints) return
|
|
32
|
+
|
|
33
|
+
for (const manualTraceHint of manualTraceHints) {
|
|
34
|
+
this.add(
|
|
35
|
+
new TraceHint({
|
|
36
|
+
for: manualTraceHint.pcb_port_selector,
|
|
37
|
+
offsets: manualTraceHint.offsets,
|
|
38
|
+
}),
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
15
42
|
}
|
|
@@ -304,20 +304,9 @@ export class Trace extends PrimitiveComponent<typeof traceProps> {
|
|
|
304
304
|
port.matchedComponents.filter((c) => c.componentName === "TraceHint"),
|
|
305
305
|
) as TraceHint[]
|
|
306
306
|
|
|
307
|
-
const
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
const pcbRouteHints = (this._parsedProps.pcbRouteHints ?? [])
|
|
311
|
-
.concat(hints.flatMap((h) => h.getPcbRouteHints()))
|
|
312
|
-
.concat(
|
|
313
|
-
manualTraceHints
|
|
314
|
-
.filter((hint: { pcb_port_selector: string }) =>
|
|
315
|
-
ports.some((port) =>
|
|
316
|
-
isMatchingPathSelector(port, hint.pcb_port_selector),
|
|
317
|
-
),
|
|
318
|
-
)
|
|
319
|
-
.flatMap((hint: { offsets: RouteHintPoint[] }) => hint.offsets),
|
|
320
|
-
)
|
|
307
|
+
const pcbRouteHints = (this._parsedProps.pcbRouteHints ?? []).concat(
|
|
308
|
+
hints.flatMap((h) => h.getPcbRouteHints()),
|
|
309
|
+
)
|
|
321
310
|
|
|
322
311
|
if (ports.length > 2) {
|
|
323
312
|
this.renderError(
|
|
@@ -57,4 +57,15 @@ export class TraceHint extends PrimitiveComponent<typeof traceHintProps> {
|
|
|
57
57
|
}),
|
|
58
58
|
)
|
|
59
59
|
}
|
|
60
|
+
|
|
61
|
+
doInitialPcbTraceHintRender(): void {
|
|
62
|
+
const { db } = this.root!
|
|
63
|
+
const { _parsedProps: props } = this
|
|
64
|
+
|
|
65
|
+
db.pcb_trace_hint.insert({
|
|
66
|
+
pcb_component_id: this.matchedPort?.pcb_component_id!,
|
|
67
|
+
pcb_port_id: this.matchedPort?.pcb_port_id!,
|
|
68
|
+
route: this.getPcbRouteHints(),
|
|
69
|
+
})
|
|
70
|
+
}
|
|
60
71
|
}
|