@tscircuit/props 0.0.644 → 0.0.645
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 +6518 -6433
- package/dist/index.js +1192 -1155
- package/dist/index.js.map +1 -1
- package/lib/assembly/index.ts +3 -0
- package/lib/assembly/screen.ts +69 -0
- package/package.json +1 -1
package/lib/assembly/index.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { assemblyDeviceProps } from "./device"
|
|
2
|
+
import { assemblyScreenProps } from "./screen"
|
|
2
3
|
|
|
3
4
|
export * from "./device"
|
|
5
|
+
export * from "./screen"
|
|
4
6
|
|
|
5
7
|
export const assemblyProps = {
|
|
6
8
|
device: assemblyDeviceProps,
|
|
9
|
+
screen: assemblyScreenProps,
|
|
7
10
|
} as const
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { type Distance, distance } from "lib/common/distance"
|
|
2
|
+
import { expectTypesMatch } from "lib/typecheck"
|
|
3
|
+
import { z } from "zod"
|
|
4
|
+
|
|
5
|
+
export interface AssemblyScreenProps {
|
|
6
|
+
/** Stable product-level identity for the screen assembly. */
|
|
7
|
+
name: string
|
|
8
|
+
/** Selector for the connector that the screen attaches to. */
|
|
9
|
+
connectsTo: string
|
|
10
|
+
/**
|
|
11
|
+
* Outer width of the screen body, including its bezel but excluding the flex
|
|
12
|
+
* cable. When supplied, it must be provided together with `height`.
|
|
13
|
+
*/
|
|
14
|
+
width?: Distance
|
|
15
|
+
/**
|
|
16
|
+
* Outer height of the screen body, including its bezel but excluding the flex
|
|
17
|
+
* cable. When supplied, it must be provided together with `width`.
|
|
18
|
+
*/
|
|
19
|
+
height?: Distance
|
|
20
|
+
/**
|
|
21
|
+
* Advanced modelprinter string used to render the screen assembly. Required
|
|
22
|
+
* when `width` and `height` are omitted.
|
|
23
|
+
*/
|
|
24
|
+
cadModel?: string
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const nonemptyString = (fieldName: "name" | "connectsTo" | "cadModel") =>
|
|
28
|
+
z.string().refine((value) => value.trim().length > 0, {
|
|
29
|
+
message: `${fieldName} cannot be empty`,
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
const positiveDistance = (fieldName: "width" | "height") =>
|
|
33
|
+
distance.refine((value) => Number.isFinite(value) && value > 0, {
|
|
34
|
+
message: `${fieldName} must be a positive finite distance`,
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
export const assemblyScreenProps = z
|
|
38
|
+
.object({
|
|
39
|
+
name: nonemptyString("name"),
|
|
40
|
+
connectsTo: nonemptyString("connectsTo"),
|
|
41
|
+
width: positiveDistance("width").optional(),
|
|
42
|
+
height: positiveDistance("height").optional(),
|
|
43
|
+
cadModel: nonemptyString("cadModel").optional(),
|
|
44
|
+
})
|
|
45
|
+
.superRefine((screen, context) => {
|
|
46
|
+
const hasWidth = screen.width !== undefined
|
|
47
|
+
const hasHeight = screen.height !== undefined
|
|
48
|
+
|
|
49
|
+
if (hasWidth !== hasHeight) {
|
|
50
|
+
context.addIssue({
|
|
51
|
+
code: z.ZodIssueCode.custom,
|
|
52
|
+
message: "width and height must be provided together",
|
|
53
|
+
path: hasWidth ? ["height"] : ["width"],
|
|
54
|
+
})
|
|
55
|
+
return
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (!hasWidth && screen.cadModel === undefined) {
|
|
59
|
+
context.addIssue({
|
|
60
|
+
code: z.ZodIssueCode.custom,
|
|
61
|
+
message: "provide either width and height or cadModel",
|
|
62
|
+
path: [],
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
export type AssemblyScreenPropsInput = z.input<typeof assemblyScreenProps>
|
|
68
|
+
|
|
69
|
+
expectTypesMatch<AssemblyScreenProps, AssemblyScreenPropsInput>(true)
|