@tscircuit/props 0.0.695 → 0.0.697

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,6 +1,8 @@
1
1
  import { assemblyCadAssemblyProps } from "./cadassembly"
2
2
  import { assemblyCableProps } from "./cable"
3
3
  import { assemblyDeviceProps } from "./device"
4
+ import { assemblyPartProps } from "./part"
5
+ import { assemblyReferenceSurfaceProps } from "./referencesurface"
4
6
  import { assemblyPrintedPartProps } from "./printedpart"
5
7
  import { assemblyMotorProps } from "./motor"
6
8
  import { assemblyScreenProps } from "./screen"
@@ -10,6 +12,8 @@ export * from "./board-mounting"
10
12
  export * from "./cable"
11
13
  export * from "./device"
12
14
  export * from "./motor"
15
+ export * from "./part"
16
+ export * from "./referencesurface"
13
17
  export * from "./printedpart"
14
18
  export * from "./screen"
15
19
  export * from "./subassembly"
@@ -19,6 +23,8 @@ export const assemblyProps = {
19
23
  cable: assemblyCableProps,
20
24
  device: assemblyDeviceProps,
21
25
  motor: assemblyMotorProps,
26
+ part: assemblyPartProps,
27
+ referencesurface: assemblyReferenceSurfaceProps,
22
28
  printedpart: assemblyPrintedPartProps,
23
29
  screen: assemblyScreenProps,
24
30
  subassembly: assemblySubassemblyProps,
@@ -0,0 +1,47 @@
1
+ import { type CadModelProp, cadModelProp } from "lib/common/cadModel"
2
+ import { url } from "lib/common/url"
3
+ import { expectTypesMatch } from "lib/typecheck"
4
+ import { z } from "zod"
5
+ import type { ReactNode } from "react"
6
+
7
+ /** A generic component of an assembly, with optional CAD geometry. */
8
+ export interface AssemblyPartProps {
9
+ /** Stable identity used by assembly selectors. */
10
+ name: string
11
+ /** Human-facing alternate to the stable name. */
12
+ displayName?: string
13
+ /** Modelprinter/footprinter string, trimmed; mutually exclusive with modelUrl and cadModel. */
14
+ model?: string
15
+ /** Imported CAD model URL; mutually exclusive with model and cadModel. */
16
+ modelUrl?: string
17
+ /** Existing component CAD model formats; mutually exclusive with model and modelUrl. */
18
+ cadModel?: CadModelProp
19
+ /** Reference surfaces defining named mounting frames for this part. */
20
+ children?: ReactNode
21
+ }
22
+
23
+ export const assemblyPartProps = z
24
+ .object({
25
+ name: z.string().trim().min(1),
26
+ displayName: z.string().optional(),
27
+ model: z.string().trim().min(1).optional(),
28
+ modelUrl: url
29
+ .refine((value) => value.trim().length > 0, "modelUrl cannot be empty")
30
+ .optional(),
31
+ cadModel: cadModelProp.optional(),
32
+ children: z.custom<ReactNode>().optional(),
33
+ })
34
+ .refine(
35
+ (part) =>
36
+ [part.model, part.modelUrl, part.cadModel].filter(
37
+ (value) => value !== undefined,
38
+ ).length <= 1,
39
+ {
40
+ message: "Provide only one of model, modelUrl, or cadModel",
41
+ path: ["model"],
42
+ },
43
+ )
44
+
45
+ export type AssemblyPartPropsInput = z.input<typeof assemblyPartProps>
46
+
47
+ expectTypesMatch<AssemblyPartProps, AssemblyPartPropsInput>(true)
@@ -2,7 +2,7 @@ import { type CadModelProp, cadModelProp } from "lib/common/cadModel"
2
2
  import { url } from "lib/common/url"
3
3
  import { distance, type Distance } from "lib/common/distance"
4
4
  import { expectTypesMatch } from "lib/typecheck"
5
- import { isValidElement, type ReactElement } from "react"
5
+ import { isValidElement, type ReactElement, type ReactNode } from "react"
6
6
  import { z } from "zod"
7
7
 
8
8
  /** Provide exactly one of jscad, model, modelUrl, or cadModel. */
@@ -10,6 +10,12 @@ export interface AssemblyPrintedPartProps {
10
10
  /** Stable identity used by assembly mounting selectors. */
11
11
  name: string
12
12
  displayName?: string
13
+ /** Color for the rendered printed part. Omit to retain authored materials. */
14
+ color?: string
15
+ /** Printable material classification; omitted when unspecified. */
16
+ material?: "pla" | "petg" | "nylon"
17
+ /** Reference surfaces defining named mounting frames, alongside CAD children. */
18
+ children?: ReactNode
13
19
  /** Pure jscad-fiber JSX in right-handed local XYZ, dimensions in millimeters.
14
20
  * Named reference rectangles define attachment faces; they add no material.
15
21
  * Hooks, async components, and raw kernel geometry are not supported.
@@ -36,6 +42,9 @@ export const assemblyPrintedPartProps = z
36
42
  .object({
37
43
  name: z.string().trim().min(1),
38
44
  displayName: z.string().optional(),
45
+ color: z.string().trim().min(1).optional(),
46
+ material: z.enum(["pla", "petg", "nylon"]).optional(),
47
+ children: z.custom<ReactNode>().optional(),
39
48
  jscad: z
40
49
  .custom<ReactElement>(isValidElement, "Expected jscad-fiber JSX")
41
50
  .optional(),
@@ -0,0 +1,80 @@
1
+ import { type Distance, distance } from "lib/common/distance"
2
+ import { expectTypesMatch } from "lib/typecheck"
3
+ import { z } from "zod"
4
+
5
+ /** A named, non-solid mounting frame in the owning part's local, right-handed
6
+ * XYZ (mm). Offsets locate its origin; its normal and tangent are directions.
7
+ */
8
+ export interface AssemblyReferenceSurfaceProps {
9
+ /** Unique within the part; defaults to "anchor". Use PART.name to mount to it. */
10
+ name?: string
11
+ /** Reference shape; defaults to rect. Does not create solid geometry. */
12
+ shape?: "rect"
13
+ /** Defaults to xy. Positive normals: xy +Z, xz +Y, yz +X. */
14
+ plane?: "xy" | "xz" | "yz"
15
+ /** Outward normal, perpendicular to plane. Defaults: xy z+, xz y+, yz x+.
16
+ * Reversing the normal retains the local X tangent. Replaces positive/negative.
17
+ */
18
+ normalDirection?: "x+" | "x-" | "y+" | "y-" | "z+" | "z-"
19
+ /** Surface center offsets from the part origin, in mm or unit strings; each defaults to zero. */
20
+ centerXOffset?: Distance
21
+ centerYOffset?: Distance
22
+ centerZOffset?: Distance
23
+ /** Optional rectangular extents along the tangent and its perpendicular.
24
+ * Supply width and height together. Mounting uses the center, not the edges.
25
+ */
26
+ width?: Distance
27
+ height?: Distance
28
+ }
29
+
30
+ const offset = distance.pipe(z.number().finite())
31
+ const extent = distance.pipe(z.number().positive().finite())
32
+
33
+ export const assemblyReferenceSurfaceProps = z
34
+ .object({
35
+ name: z.string().trim().min(1).default("anchor"),
36
+ shape: z.literal("rect").default("rect"),
37
+ plane: z.enum(["xy", "xz", "yz"]).default("xy"),
38
+ normalDirection: z.enum(["x+", "x-", "y+", "y-", "z+", "z-"]).optional(),
39
+ centerXOffset: offset.default(0),
40
+ centerYOffset: offset.default(0),
41
+ centerZOffset: offset.default(0),
42
+ width: extent.optional(),
43
+ height: extent.optional(),
44
+ })
45
+ .refine(
46
+ (surface) =>
47
+ (surface.width === undefined) === (surface.height === undefined),
48
+ {
49
+ message: "Provide width and height together",
50
+ path: ["width"],
51
+ },
52
+ )
53
+ .superRefine((surface, ctx) => {
54
+ const normalAxis =
55
+ surface.plane === "xy" ? "z" : surface.plane === "xz" ? "y" : "x"
56
+ if (surface.normalDirection && surface.normalDirection[0] !== normalAxis)
57
+ ctx.addIssue({
58
+ code: z.ZodIssueCode.custom,
59
+ path: ["normalDirection"],
60
+ message: `normalDirection must be ${normalAxis}+ or ${normalAxis}- for plane ${surface.plane}`,
61
+ })
62
+ })
63
+ .transform((surface) => ({
64
+ ...surface,
65
+ normalDirection:
66
+ surface.normalDirection ??
67
+ (surface.plane === "xy"
68
+ ? ("z+" as const)
69
+ : surface.plane === "xz"
70
+ ? ("y+" as const)
71
+ : ("x+" as const)),
72
+ }))
73
+
74
+ export type AssemblyReferenceSurfacePropsInput = z.input<
75
+ typeof assemblyReferenceSurfaceProps
76
+ >
77
+ expectTypesMatch<
78
+ AssemblyReferenceSurfaceProps,
79
+ AssemblyReferenceSurfacePropsInput
80
+ >(true)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscircuit/props",
3
- "version": "0.0.695",
3
+ "version": "0.0.697",
4
4
  "description": "Props for tscircuit builtin component types",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",