@tscircuit/props 0.0.686 → 0.0.688
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 +274 -8
- package/dist/index.js +41 -3
- package/dist/index.js.map +1 -1
- package/lib/assembly/motor.ts +53 -1
- package/lib/common/pinAttributeMap.ts +23 -0
- package/package.json +1 -1
package/lib/assembly/motor.ts
CHANGED
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
type CadModelAxisDirection,
|
|
3
3
|
cadModelAxisDirection,
|
|
4
4
|
} from "lib/common/cadModel"
|
|
5
|
+
import { distance, type Distance } from "lib/common/distance"
|
|
5
6
|
import { expectTypesMatch } from "lib/typecheck"
|
|
6
7
|
import { z } from "zod"
|
|
7
8
|
|
|
@@ -25,6 +26,18 @@ export interface AssemblyMotorProps {
|
|
|
25
26
|
shaftFacingDirection?: CadModelAxisDirection
|
|
26
27
|
/** e.g. "jst-ph-6". */
|
|
27
28
|
wireConnection?: "none" | "stubs" | "jst-ph-6"
|
|
29
|
+
/** Assembly mounting target, e.g. "FRAME.xMotor"; paired with mountFace.
|
|
30
|
+
* Face mating determines orientation, so shaftFacingDirection must be omitted.
|
|
31
|
+
*/
|
|
32
|
+
mountedTo?: string
|
|
33
|
+
/** This motor's mating face, e.g. "frontface" or "backface".
|
|
34
|
+
* Outward normals oppose and in-plane X directions align with the target.
|
|
35
|
+
*/
|
|
36
|
+
mountFace?: string
|
|
37
|
+
/** Nonnegative surface clearance in mm or a unit string; defaults to zero.
|
|
38
|
+
* Requires mountedTo. Positive values separate the mating faces.
|
|
39
|
+
*/
|
|
40
|
+
mountGap?: Distance
|
|
28
41
|
}
|
|
29
42
|
|
|
30
43
|
export const assemblyMotorProps = z
|
|
@@ -35,10 +48,41 @@ export const assemblyMotorProps = z
|
|
|
35
48
|
displayName: z.string().optional(),
|
|
36
49
|
standard: z.enum(["nema8", "nema17", "nema23"]).optional(),
|
|
37
50
|
model: z.string().trim().min(1).optional(),
|
|
38
|
-
shaftFacingDirection: cadModelAxisDirection.
|
|
51
|
+
shaftFacingDirection: cadModelAxisDirection.optional(),
|
|
39
52
|
wireConnection: z.enum(["none", "stubs", "jst-ph-6"]).optional(),
|
|
53
|
+
mountedTo: z
|
|
54
|
+
.string()
|
|
55
|
+
.trim()
|
|
56
|
+
.regex(/^.+\.[^.]+$/, "Expected part.face")
|
|
57
|
+
.optional(),
|
|
58
|
+
mountFace: z.string().trim().min(1).optional(),
|
|
59
|
+
mountGap: distance.pipe(z.number().nonnegative().finite()).optional(),
|
|
40
60
|
})
|
|
41
61
|
.superRefine((motor, context) => {
|
|
62
|
+
if ((motor.mountedTo === undefined) !== (motor.mountFace === undefined)) {
|
|
63
|
+
context.addIssue({
|
|
64
|
+
code: z.ZodIssueCode.custom,
|
|
65
|
+
message: "Provide mountedTo and mountFace together",
|
|
66
|
+
path: ["mountFace"],
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
if (motor.mountGap !== undefined && motor.mountedTo === undefined) {
|
|
70
|
+
context.addIssue({
|
|
71
|
+
code: z.ZodIssueCode.custom,
|
|
72
|
+
message: "mountGap requires mountedTo",
|
|
73
|
+
path: ["mountGap"],
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
if (
|
|
77
|
+
motor.mountedTo !== undefined &&
|
|
78
|
+
motor.shaftFacingDirection !== undefined
|
|
79
|
+
) {
|
|
80
|
+
context.addIssue({
|
|
81
|
+
code: z.ZodIssueCode.custom,
|
|
82
|
+
message: "Mounted motors derive shaft direction from the mating faces",
|
|
83
|
+
path: ["shaftFacingDirection"],
|
|
84
|
+
})
|
|
85
|
+
}
|
|
42
86
|
if (motor.model !== undefined && motor.wireConnection !== undefined) {
|
|
43
87
|
context.addIssue({
|
|
44
88
|
code: z.ZodIssueCode.custom,
|
|
@@ -62,6 +106,14 @@ export const assemblyMotorProps = z
|
|
|
62
106
|
})
|
|
63
107
|
}
|
|
64
108
|
})
|
|
109
|
+
.transform((motor) =>
|
|
110
|
+
motor.mountedTo === undefined
|
|
111
|
+
? {
|
|
112
|
+
...motor,
|
|
113
|
+
shaftFacingDirection: motor.shaftFacingDirection ?? ("z+" as const),
|
|
114
|
+
}
|
|
115
|
+
: motor,
|
|
116
|
+
)
|
|
65
117
|
|
|
66
118
|
export type AssemblyMotorPropsInput = z.input<typeof assemblyMotorProps>
|
|
67
119
|
|
|
@@ -44,6 +44,11 @@ export interface PinAttributeMap {
|
|
|
44
44
|
requiresGround?: boolean
|
|
45
45
|
providesVoltage?: string | number
|
|
46
46
|
requiresVoltage?: string | number
|
|
47
|
+
/**
|
|
48
|
+
* Allowed relative deviation from requiresVoltage, e.g. 0.05 or "5%" for ±5%.
|
|
49
|
+
* Parsed as a fraction from 0 to 1; omitted values remain undefined.
|
|
50
|
+
*/
|
|
51
|
+
requiredVoltageTolerance?: number | string
|
|
47
52
|
doNotConnect?: boolean
|
|
48
53
|
includeInBoardPinout?: boolean
|
|
49
54
|
highlightColor?: string
|
|
@@ -83,6 +88,24 @@ export const pinAttributeMap = z.object({
|
|
|
83
88
|
requiresGround: z.boolean().optional(),
|
|
84
89
|
providesVoltage: z.union([z.string(), z.number()]).optional(),
|
|
85
90
|
requiresVoltage: z.union([z.string(), z.number()]).optional(),
|
|
91
|
+
requiredVoltageTolerance: z
|
|
92
|
+
.union([
|
|
93
|
+
z.number(),
|
|
94
|
+
z
|
|
95
|
+
.string()
|
|
96
|
+
.trim()
|
|
97
|
+
.regex(
|
|
98
|
+
/^(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?\s*%?$/,
|
|
99
|
+
"Expected a tolerance fraction or percentage",
|
|
100
|
+
)
|
|
101
|
+
.transform((value) =>
|
|
102
|
+
value.endsWith("%")
|
|
103
|
+
? Number(value.slice(0, -1)) / 100
|
|
104
|
+
: Number(value),
|
|
105
|
+
),
|
|
106
|
+
])
|
|
107
|
+
.pipe(z.number().finite().min(0).max(1))
|
|
108
|
+
.optional(),
|
|
86
109
|
doNotConnect: z.boolean().optional(),
|
|
87
110
|
includeInBoardPinout: z.boolean().optional(),
|
|
88
111
|
highlightColor: z.string().optional(),
|