@tscircuit/props 0.0.681 → 0.0.683
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 +13 -10
- package/dist/index.d.ts +568 -483
- package/dist/index.js +1285 -1229
- package/dist/index.js.map +1 -1
- package/lib/assembly/board-mounting.ts +56 -0
- package/lib/assembly/index.ts +1 -0
- package/lib/assembly/motor.ts +11 -0
- package/lib/components/board.ts +26 -15
- package/lib/components/copper-pour.ts +40 -21
- package/package.json +1 -1
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { AutocompleteString } from "lib/common/autocomplete"
|
|
2
|
+
import { z } from "zod"
|
|
3
|
+
|
|
4
|
+
export type BoardMountRotationAnchor = AutocompleteString<
|
|
5
|
+
"topedge" | "bottomedge" | "leftedge" | "rightedge"
|
|
6
|
+
>
|
|
7
|
+
|
|
8
|
+
export type BoardMountOrientation =
|
|
9
|
+
| "top_layer_toward_mount_face"
|
|
10
|
+
| "bottom_layer_toward_mount_face"
|
|
11
|
+
|
|
12
|
+
const identityPathPattern =
|
|
13
|
+
"[A-Za-z_][A-Za-z0-9_-]*(?:\\.[A-Za-z_][A-Za-z0-9_-]*)*"
|
|
14
|
+
const referencePattern =
|
|
15
|
+
"[A-Za-z_][A-Za-z0-9_-]*(?:\\.[A-Za-z_][A-Za-z0-9_-]*)+"
|
|
16
|
+
const reference = new RegExp(`^${referencePattern}$`)
|
|
17
|
+
const anchor = new RegExp(`^${identityPathPattern}$`)
|
|
18
|
+
const expression = new RegExp(
|
|
19
|
+
`^calc\\(\\s*(${referencePattern})\\s*(?:([+-])\\s*((?:\\d+(?:\\.\\d*)?|\\.\\d+))\\s*(degcw|degccw))?\\s*\\)$`,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
export const boardMountRotation = z
|
|
23
|
+
.string()
|
|
24
|
+
.trim()
|
|
25
|
+
.superRefine((value, ctx) => {
|
|
26
|
+
if (reference.test(value)) return
|
|
27
|
+
const match = expression.exec(value)
|
|
28
|
+
if (!match) {
|
|
29
|
+
ctx.addIssue({
|
|
30
|
+
code: z.ZodIssueCode.custom,
|
|
31
|
+
message:
|
|
32
|
+
"Expected a qualified mounting reference or calc(reference +/- Ndegcw|Ndegccw)",
|
|
33
|
+
})
|
|
34
|
+
return
|
|
35
|
+
}
|
|
36
|
+
if (match[3] !== undefined && !Number.isFinite(Number(match[3]))) {
|
|
37
|
+
ctx.addIssue({
|
|
38
|
+
code: z.ZodIssueCode.custom,
|
|
39
|
+
message: "Mount rotation angle must be finite",
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
export const boardMountRotationAnchor = z
|
|
45
|
+
.custom<BoardMountRotationAnchor>((value) => typeof value === "string", {
|
|
46
|
+
message: "Expected a board edge or component identity path",
|
|
47
|
+
})
|
|
48
|
+
.transform((value) => value.trim())
|
|
49
|
+
.refine((value) => anchor.test(value), {
|
|
50
|
+
message: "Expected a board edge or component identity path",
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
export const boardMountOrientation = z.enum([
|
|
54
|
+
"top_layer_toward_mount_face",
|
|
55
|
+
"bottom_layer_toward_mount_face",
|
|
56
|
+
])
|
package/lib/assembly/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { assemblyMotorProps } from "./motor"
|
|
|
4
4
|
import { assemblyScreenProps } from "./screen"
|
|
5
5
|
import { assemblySubassemblyProps } from "./subassembly"
|
|
6
6
|
|
|
7
|
+
export * from "./board-mounting"
|
|
7
8
|
export * from "./device"
|
|
8
9
|
export * from "./motor"
|
|
9
10
|
export * from "./screen"
|
package/lib/assembly/motor.ts
CHANGED
|
@@ -23,6 +23,8 @@ export interface AssemblyMotorProps {
|
|
|
23
23
|
* shaft. Defaults to "z+", the native shaft axis of the NEMA models.
|
|
24
24
|
*/
|
|
25
25
|
shaftFacingDirection?: CadModelAxisDirection
|
|
26
|
+
/** e.g. "jst-ph-6". */
|
|
27
|
+
wireConnection?: "none" | "stubs" | "jst-ph-6"
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
export const assemblyMotorProps = z
|
|
@@ -34,8 +36,17 @@ export const assemblyMotorProps = z
|
|
|
34
36
|
standard: z.enum(["nema8", "nema17", "nema23"]).optional(),
|
|
35
37
|
model: z.string().trim().min(1).optional(),
|
|
36
38
|
shaftFacingDirection: cadModelAxisDirection.default("z+"),
|
|
39
|
+
wireConnection: z.enum(["none", "stubs", "jst-ph-6"]).optional(),
|
|
37
40
|
})
|
|
38
41
|
.superRefine((motor, context) => {
|
|
42
|
+
if (motor.model !== undefined && motor.wireConnection !== undefined) {
|
|
43
|
+
context.addIssue({
|
|
44
|
+
code: z.ZodIssueCode.custom,
|
|
45
|
+
message:
|
|
46
|
+
"Set wireConnection in the custom model string, or use standard",
|
|
47
|
+
path: ["wireConnection"],
|
|
48
|
+
})
|
|
49
|
+
}
|
|
39
50
|
if (motor.standard === undefined && motor.model === undefined) {
|
|
40
51
|
context.addIssue({
|
|
41
52
|
code: z.ZodIssueCode.custom,
|
package/lib/components/board.ts
CHANGED
|
@@ -5,6 +5,13 @@ import { type Point, point } from "lib/common/point"
|
|
|
5
5
|
import { expectTypesMatch } from "lib/typecheck"
|
|
6
6
|
import { z } from "zod"
|
|
7
7
|
import { subcircuitGroupProps, type SubcircuitGroupProps } from "./group"
|
|
8
|
+
import {
|
|
9
|
+
boardMountOrientation,
|
|
10
|
+
boardMountRotation,
|
|
11
|
+
boardMountRotationAnchor,
|
|
12
|
+
type BoardMountOrientation,
|
|
13
|
+
type BoardMountRotationAnchor,
|
|
14
|
+
} from "../assembly/board-mounting"
|
|
8
15
|
|
|
9
16
|
const boardColorPresets = [
|
|
10
17
|
"not_specified",
|
|
@@ -78,17 +85,16 @@ export const boardOutlinePoint = z
|
|
|
78
85
|
export interface BoardProps
|
|
79
86
|
extends Omit<SubcircuitGroupProps, "subcircuit" | "connections" | "outline"> {
|
|
80
87
|
title?: string
|
|
81
|
-
/**
|
|
82
|
-
* Assembly mounting target, such as "NEMA17.backface". Trimmed; omitted
|
|
83
|
-
* leaves the board unattached. The target face is resolved by the consumer.
|
|
84
|
-
*/
|
|
88
|
+
/** e.g. "NEMA17.backface". */
|
|
85
89
|
mountedTo?: string
|
|
86
|
-
/**
|
|
87
|
-
* Nonnegative finite clearance between the target mounting face and the
|
|
88
|
-
* nearest PCB surface, in millimeters or a unit string. Parsed to mm.
|
|
89
|
-
* Omitted leaves the gap unset; only meaningful when mountedTo is supplied.
|
|
90
|
-
*/
|
|
90
|
+
/** Clearance from the mounting face, e.g. "6mm". */
|
|
91
91
|
mountGap?: Distance
|
|
92
|
+
/** e.g. "J_USB" or "rightedge". */
|
|
93
|
+
mountRotationAnchor?: BoardMountRotationAnchor
|
|
94
|
+
/** e.g. "calc(NEMA17.wireside-90degcw)". */
|
|
95
|
+
mountRotation?: string
|
|
96
|
+
/** e.g. "top_layer_toward_mount_face". */
|
|
97
|
+
mountOrientation?: BoardMountOrientation
|
|
92
98
|
/** Fabricator preset, preserved as supplied. Omitted leaves the preset unset. */
|
|
93
99
|
fabricatorPreset?:
|
|
94
100
|
| "jlcpcb_economy"
|
|
@@ -169,15 +175,20 @@ export const boardProps = subcircuitGroupProps
|
|
|
169
175
|
.trim()
|
|
170
176
|
.min(1)
|
|
171
177
|
.optional()
|
|
172
|
-
.describe(
|
|
173
|
-
'Assembly mounting target, such as "NEMA17.backface". Trimmed; omitted leaves the board unattached. The target face is resolved by the consumer.',
|
|
174
|
-
),
|
|
178
|
+
.describe('e.g. "NEMA17.backface".'),
|
|
175
179
|
mountGap: distance
|
|
176
180
|
.pipe(z.number().nonnegative().finite())
|
|
177
181
|
.optional()
|
|
178
|
-
.describe(
|
|
179
|
-
|
|
180
|
-
)
|
|
182
|
+
.describe('Clearance from the mounting face, e.g. "6mm".'),
|
|
183
|
+
mountRotationAnchor: boardMountRotationAnchor
|
|
184
|
+
.optional()
|
|
185
|
+
.describe('e.g. "J_USB" or "rightedge".'),
|
|
186
|
+
mountRotation: boardMountRotation
|
|
187
|
+
.optional()
|
|
188
|
+
.describe('e.g. "calc(NEMA17.wireside-90degcw)".'),
|
|
189
|
+
mountOrientation: boardMountOrientation
|
|
190
|
+
.optional()
|
|
191
|
+
.describe('e.g. "top_layer_toward_mount_face".'),
|
|
181
192
|
fabricatorPreset: z
|
|
182
193
|
.enum([
|
|
183
194
|
"jlcpcb_economy",
|
|
@@ -9,10 +9,14 @@ export interface CopperPourProps {
|
|
|
9
9
|
layer: LayerRefInput
|
|
10
10
|
connectsTo: string
|
|
11
11
|
/**
|
|
12
|
-
* Fill with a 45-degree crosshatch (0.25mm copper width, 1mm pitch).
|
|
12
|
+
* Fill with a 45-degree crosshatch (defaults: 0.25mm copper width, 1mm pitch).
|
|
13
13
|
* Preserves solid copper around boundaries and connections. Defaults to false.
|
|
14
14
|
*/
|
|
15
15
|
crosshatch?: boolean
|
|
16
|
+
/** Repeat spacing perpendicular to the hatch strips. Defaults to 1mm when crosshatch is enabled. */
|
|
17
|
+
crosshatchPitch?: Distance
|
|
18
|
+
/** Copper strip width, also used for the solid rim. Defaults to 0.25mm; must be less than the pitch when crosshatch is enabled. */
|
|
19
|
+
crosshatchWidth?: Distance
|
|
16
20
|
/**
|
|
17
21
|
* Reserves the pour region during autorouting so unrelated traces do not
|
|
18
22
|
* split it. Vias may still cross the region using antipads.
|
|
@@ -28,26 +32,41 @@ export interface CopperPourProps {
|
|
|
28
32
|
coveredWithSolderMask?: boolean
|
|
29
33
|
}
|
|
30
34
|
|
|
31
|
-
export const copperPourProps = z
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
.
|
|
38
|
-
.optional()
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
35
|
+
export const copperPourProps = z
|
|
36
|
+
.object({
|
|
37
|
+
name: z.string().optional(),
|
|
38
|
+
layer: layer_ref,
|
|
39
|
+
connectsTo: z.string(),
|
|
40
|
+
crosshatch: z.boolean().optional(),
|
|
41
|
+
crosshatchPitch: distance.pipe(z.number().finite().positive()).optional(),
|
|
42
|
+
crosshatchWidth: distance.pipe(z.number().finite().positive()).optional(),
|
|
43
|
+
unbroken: z
|
|
44
|
+
.boolean()
|
|
45
|
+
.optional()
|
|
46
|
+
.describe(
|
|
47
|
+
"Reserves the pour region during autorouting so unrelated traces do not split it. Vias may still cross the region using antipads.",
|
|
48
|
+
),
|
|
49
|
+
padMargin: distance.optional(),
|
|
50
|
+
traceMargin: distance.optional(),
|
|
51
|
+
clearance: distance.optional(),
|
|
52
|
+
boardEdgeMargin: distance.optional(),
|
|
53
|
+
cutoutMargin: distance.optional(),
|
|
54
|
+
useThermalReliefs: z.boolean().optional(),
|
|
55
|
+
outline: z.array(point).optional(),
|
|
56
|
+
coveredWithSolderMask: z.boolean().optional().default(true),
|
|
57
|
+
})
|
|
58
|
+
.superRefine((props, ctx) => {
|
|
59
|
+
if (
|
|
60
|
+
props.crosshatch &&
|
|
61
|
+
(props.crosshatchWidth ?? 0.25) >= (props.crosshatchPitch ?? 1)
|
|
62
|
+
) {
|
|
63
|
+
ctx.addIssue({
|
|
64
|
+
code: z.ZodIssueCode.custom,
|
|
65
|
+
path: ["crosshatchWidth"],
|
|
66
|
+
message: "crosshatchWidth must be less than crosshatchPitch",
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
})
|
|
51
70
|
|
|
52
71
|
expectTypesMatch<CopperPourProps, z.input<typeof copperPourProps>>(true)
|
|
53
72
|
|