@tscircuit/props 0.0.697 → 0.0.698
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 +164 -112
- package/dist/index.d.ts +186 -1
- package/dist/index.js +505 -427
- package/dist/index.js.map +1 -1
- package/lib/components/pcb-return-current-excitation.ts +110 -0
- package/lib/components/pcb-return-current-simulation.ts +25 -0
- package/lib/index.ts +1 -0
- package/lib/simulation/index.ts +10 -0
- package/package.json +1 -1
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { layer_ref, type LayerRefInput } from "circuit-json"
|
|
2
|
+
import { expectTypesMatch } from "lib/typecheck"
|
|
3
|
+
import { z } from "zod"
|
|
4
|
+
|
|
5
|
+
/** A signal driver/load pair and its explicit ground return terminals.
|
|
6
|
+
* Selectors resolve inside the containing board/subcircuit. The initial core
|
|
7
|
+
* implementation accepts physical PCB ports/pads, not standalone via contacts.
|
|
8
|
+
* This definition neither connects the selected pins nor runs a simulation.
|
|
9
|
+
*/
|
|
10
|
+
export interface PcbReturnCurrentExcitationProps {
|
|
11
|
+
/** Readable excitation name for diagnostics; not stored on its Circuit JSON record. */
|
|
12
|
+
name?: string
|
|
13
|
+
/** Signal driver port selector, e.g. ".U1 > .OUT". */
|
|
14
|
+
source: string
|
|
15
|
+
/** Signal receiving port selector, e.g. ".U2 > .IN". */
|
|
16
|
+
load: string
|
|
17
|
+
/** Ground net selector, e.g. "net.GND"; its copper and connections must already exist. */
|
|
18
|
+
ground: string
|
|
19
|
+
/** Positive in-phase peak signal current. Numbers are amperes, not RMS; strings use ampere units. */
|
|
20
|
+
current: number | string
|
|
21
|
+
/** Load-side GND port where positive return current enters the return conductor. */
|
|
22
|
+
returnSource: string
|
|
23
|
+
/** Driver-side GND port where positive return current leaves the return conductor. */
|
|
24
|
+
returnSink: string
|
|
25
|
+
/** Positive real source-port resistance. Numbers are ohms; complex impedances are unsupported. */
|
|
26
|
+
sourceImpedance: number | string
|
|
27
|
+
/** Positive real load-port resistance. Numbers are ohms; complex impedances are unsupported. */
|
|
28
|
+
loadImpedance: number | string
|
|
29
|
+
/** Optional trace selector to disambiguate multiple routes between the signal ports. */
|
|
30
|
+
trace?: string
|
|
31
|
+
/** Contact layer for a load-side PCB port spanning multiple copper layers. */
|
|
32
|
+
returnSourceLayer?: LayerRefInput
|
|
33
|
+
/** Contact layer for a driver-side PCB port spanning multiple copper layers. */
|
|
34
|
+
returnSinkLayer?: LayerRefInput
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const selector = z.string().trim().min(1, "Provide a nonempty selector")
|
|
38
|
+
const quantity = "[+-]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:[eE][+-]?\\d+)?"
|
|
39
|
+
const prefixScale: Record<string, number> = {
|
|
40
|
+
"": 1,
|
|
41
|
+
y: 1e-24,
|
|
42
|
+
z: 1e-21,
|
|
43
|
+
a: 1e-18,
|
|
44
|
+
f: 1e-15,
|
|
45
|
+
p: 1e-12,
|
|
46
|
+
n: 1e-9,
|
|
47
|
+
u: 1e-6,
|
|
48
|
+
µ: 1e-6,
|
|
49
|
+
μ: 1e-6,
|
|
50
|
+
m: 1e-3,
|
|
51
|
+
k: 1e3,
|
|
52
|
+
M: 1e6,
|
|
53
|
+
G: 1e9,
|
|
54
|
+
T: 1e12,
|
|
55
|
+
P: 1e15,
|
|
56
|
+
E: 1e18,
|
|
57
|
+
Z: 1e21,
|
|
58
|
+
Y: 1e24,
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Full-string parsing preserves scientific notation and rejects other
|
|
62
|
+
// dimensions. The generic Circuit JSON converters currently do neither.
|
|
63
|
+
function positiveQuantity(unit: string, label: string, example: string) {
|
|
64
|
+
const pattern = new RegExp(
|
|
65
|
+
`^(${quantity})\\s*(?:([yzafpnumkMGTPEZYµμ]?)(?:${unit}))?$`,
|
|
66
|
+
)
|
|
67
|
+
return z
|
|
68
|
+
.union([
|
|
69
|
+
z.number(),
|
|
70
|
+
z
|
|
71
|
+
.string()
|
|
72
|
+
.trim()
|
|
73
|
+
.regex(pattern, `Use ${label} or a unit string, e.g. ${example}`),
|
|
74
|
+
])
|
|
75
|
+
.transform((value) => {
|
|
76
|
+
if (typeof value === "number") return value
|
|
77
|
+
const match = pattern.exec(value)!
|
|
78
|
+
return Number(match[1]) * prefixScale[match[2] ?? ""]!
|
|
79
|
+
})
|
|
80
|
+
.pipe(z.number().finite().positive(`${label} must be greater than zero`))
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const positiveCurrent = positiveQuantity("A", "peak amperes", "5mA")
|
|
84
|
+
const positiveResistance = positiveQuantity(
|
|
85
|
+
"ohms?|Ohms?|Ω",
|
|
86
|
+
"real ohms",
|
|
87
|
+
"100ohm",
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
export const pcbReturnCurrentExcitationProps = z
|
|
91
|
+
.object({
|
|
92
|
+
name: z.string().trim().min(1).optional(),
|
|
93
|
+
source: selector,
|
|
94
|
+
load: selector,
|
|
95
|
+
ground: selector,
|
|
96
|
+
current: positiveCurrent,
|
|
97
|
+
returnSource: selector,
|
|
98
|
+
returnSink: selector,
|
|
99
|
+
sourceImpedance: positiveResistance,
|
|
100
|
+
loadImpedance: positiveResistance,
|
|
101
|
+
trace: selector.optional(),
|
|
102
|
+
returnSourceLayer: layer_ref.optional(),
|
|
103
|
+
returnSinkLayer: layer_ref.optional(),
|
|
104
|
+
})
|
|
105
|
+
.strict()
|
|
106
|
+
|
|
107
|
+
expectTypesMatch<
|
|
108
|
+
PcbReturnCurrentExcitationProps,
|
|
109
|
+
z.input<typeof pcbReturnCurrentExcitationProps>
|
|
110
|
+
>(true)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { expectTypesMatch } from "lib/typecheck"
|
|
2
|
+
import type { ReactNode } from "react"
|
|
3
|
+
import { z } from "zod"
|
|
4
|
+
|
|
5
|
+
/** Defines a pending PCB return-current experiment; rendering does not run it.
|
|
6
|
+
* Frequency, mesh and sampling settings are supplied to the simulation CLI.
|
|
7
|
+
*/
|
|
8
|
+
export interface PcbReturnCurrentSimulationProps {
|
|
9
|
+
/** Stable identity and readable name for the experiment. */
|
|
10
|
+
name?: string
|
|
11
|
+
/** One or more nested simulation.pcbreturncurrentexcitation elements. */
|
|
12
|
+
children?: ReactNode
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const pcbReturnCurrentSimulationProps = z
|
|
16
|
+
.object({
|
|
17
|
+
name: z.string().trim().min(1).optional(),
|
|
18
|
+
children: z.custom<ReactNode>().optional(),
|
|
19
|
+
})
|
|
20
|
+
.strict()
|
|
21
|
+
|
|
22
|
+
expectTypesMatch<
|
|
23
|
+
PcbReturnCurrentSimulationProps,
|
|
24
|
+
z.input<typeof pcbReturnCurrentSimulationProps>
|
|
25
|
+
>(true)
|
package/lib/index.ts
CHANGED
|
@@ -81,6 +81,7 @@ export * from "./components/analogtransientsimulation"
|
|
|
81
81
|
export * from "./components/analogdcoperatingpointsimulation"
|
|
82
82
|
export * from "./components/analogdcsweepsimulation"
|
|
83
83
|
export * from "./components/analogacsweepsimulation"
|
|
84
|
+
export * from "./simulation"
|
|
84
85
|
export * from "./components/analogsweepparameter"
|
|
85
86
|
export * from "./components/autoroutingphase"
|
|
86
87
|
export * from "./components/spicemodel"
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { pcbReturnCurrentExcitationProps } from "../components/pcb-return-current-excitation"
|
|
2
|
+
import { pcbReturnCurrentSimulationProps } from "../components/pcb-return-current-simulation"
|
|
3
|
+
|
|
4
|
+
export * from "../components/pcb-return-current-excitation"
|
|
5
|
+
export * from "../components/pcb-return-current-simulation"
|
|
6
|
+
|
|
7
|
+
export const simulationProps = {
|
|
8
|
+
pcbreturncurrentsimulation: pcbReturnCurrentSimulationProps,
|
|
9
|
+
pcbreturncurrentexcitation: pcbReturnCurrentExcitationProps,
|
|
10
|
+
} as const
|