@tscircuit/props 0.0.684 → 0.0.685

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.
@@ -1,5 +1,6 @@
1
1
  import { assemblyCadAssemblyProps } from "./cadassembly"
2
2
  import { assemblyDeviceProps } from "./device"
3
+ import { assemblyPrintedPartProps } from "./printedpart"
3
4
  import { assemblyMotorProps } from "./motor"
4
5
  import { assemblyScreenProps } from "./screen"
5
6
  import { assemblySubassemblyProps } from "./subassembly"
@@ -7,6 +8,7 @@ import { assemblySubassemblyProps } from "./subassembly"
7
8
  export * from "./board-mounting"
8
9
  export * from "./device"
9
10
  export * from "./motor"
11
+ export * from "./printedpart"
10
12
  export * from "./screen"
11
13
  export * from "./subassembly"
12
14
  export * from "./cadassembly"
@@ -14,6 +16,7 @@ export * from "./cadassembly"
14
16
  export const assemblyProps = {
15
17
  device: assemblyDeviceProps,
16
18
  motor: assemblyMotorProps,
19
+ printedpart: assemblyPrintedPartProps,
17
20
  screen: assemblyScreenProps,
18
21
  subassembly: assemblySubassemblyProps,
19
22
  cadassembly: assemblyCadAssemblyProps,
@@ -0,0 +1,86 @@
1
+ import { type CadModelProp, cadModelProp } from "lib/common/cadModel"
2
+ import { url } from "lib/common/url"
3
+ import { distance, type Distance } from "lib/common/distance"
4
+ import { expectTypesMatch } from "lib/typecheck"
5
+ import { isValidElement, type ReactElement } from "react"
6
+ import { z } from "zod"
7
+
8
+ /** Provide exactly one of jscad, model, modelUrl, or cadModel. */
9
+ export interface AssemblyPrintedPartProps {
10
+ /** Stable identity used by assembly mounting selectors. */
11
+ name: string
12
+ displayName?: string
13
+ /** Pure jscad-fiber JSX in right-handed local XYZ, dimensions in millimeters.
14
+ * Named reference rectangles define attachment faces; they add no material.
15
+ * Hooks, async components, and raw kernel geometry are not supported.
16
+ */
17
+ jscad?: ReactElement
18
+ /** Modelprinter/footprinter string or model URL. */
19
+ model?: string
20
+ modelUrl?: string
21
+ cadModel?: CadModelProp
22
+ /** Assembly mounting target. */
23
+ mountedTo?: string
24
+ /** Name of this part's reference rectangle to mate with mountedTo.
25
+ * Both props must be supplied together; outward normals oppose and local
26
+ * in-plane X directions align. Without them the part uses its local origin.
27
+ */
28
+ mountFace?: string
29
+ /** Nonnegative surface clearance in mm or a unit string; defaults to zero.
30
+ * Requires mountedTo. Positive values separate the mating faces.
31
+ */
32
+ mountGap?: Distance
33
+ }
34
+
35
+ export const assemblyPrintedPartProps = z
36
+ .object({
37
+ name: z.string().trim().min(1),
38
+ displayName: z.string().optional(),
39
+ jscad: z
40
+ .custom<ReactElement>(isValidElement, "Expected jscad-fiber JSX")
41
+ .optional(),
42
+ model: z.string().trim().min(1).optional(),
43
+ modelUrl: url
44
+ .refine((value) => value.trim().length > 0, "modelUrl cannot be empty")
45
+ .optional(),
46
+ cadModel: cadModelProp.optional(),
47
+ mountedTo: z
48
+ .string()
49
+ .trim()
50
+ .regex(/^.+\.[^.]+$/, "Expected part.face")
51
+ .optional(),
52
+ mountFace: z.string().trim().min(1).optional(),
53
+ mountGap: distance.pipe(z.number().nonnegative().finite()).optional(),
54
+ })
55
+ .superRefine((part, ctx) => {
56
+ if (
57
+ [part.jscad, part.model, part.modelUrl, part.cadModel].filter(
58
+ (value) => value !== undefined,
59
+ ).length !== 1
60
+ ) {
61
+ ctx.addIssue({
62
+ code: z.ZodIssueCode.custom,
63
+ path: ["jscad"],
64
+ message: "Provide exactly one of jscad, model, modelUrl, or cadModel",
65
+ })
66
+ }
67
+ if ((part.mountedTo === undefined) !== (part.mountFace === undefined)) {
68
+ ctx.addIssue({
69
+ code: z.ZodIssueCode.custom,
70
+ path: ["mountFace"],
71
+ message: "Provide mountedTo and mountFace together",
72
+ })
73
+ }
74
+ if (part.mountGap !== undefined && part.mountedTo === undefined) {
75
+ ctx.addIssue({
76
+ code: z.ZodIssueCode.custom,
77
+ path: ["mountGap"],
78
+ message: "mountGap requires mountedTo",
79
+ })
80
+ }
81
+ })
82
+
83
+ export type AssemblyPrintedPartPropsInput = z.input<
84
+ typeof assemblyPrintedPartProps
85
+ >
86
+ expectTypesMatch<AssemblyPrintedPartProps, AssemblyPrintedPartPropsInput>(true)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscircuit/props",
3
- "version": "0.0.684",
3
+ "version": "0.0.685",
4
4
  "description": "Props for tscircuit builtin component types",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",