@tscircuit/props 0.0.707 → 0.0.708

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.
@@ -0,0 +1,15 @@
1
+ import { assemblyDrawingTitleBlockProps } from "./titleblock"
2
+ import { assemblyDrawingPageProps } from "./page"
3
+ import { assemblyDrawingPartViewProps } from "./partview"
4
+
5
+ export * from "./page"
6
+ export * from "./page-size"
7
+ export * from "./titleblock"
8
+ export * from "./partview"
9
+
10
+ /** Drawing namespace; pages contain configured part views. */
11
+ export const assemblyDrawingProps = {
12
+ page: assemblyDrawingPageProps,
13
+ titleblock: assemblyDrawingTitleBlockProps,
14
+ partview: assemblyDrawingPartViewProps,
15
+ } as const
@@ -0,0 +1,37 @@
1
+ import { z } from "zod"
2
+
3
+ /** Landscape dimensions in mm. ISO A-series / ASME Y14.1 decimal-inch sheets. */
4
+ export const assemblyDrawingPageSizes = {
5
+ iso_a0: [1189, 841],
6
+ iso_a1: [841, 594],
7
+ iso_a2: [594, 420],
8
+ iso_a3: [420, 297],
9
+ iso_a4: [297, 210],
10
+ ansi_a: [279.4, 215.9],
11
+ ansi_b: [431.8, 279.4],
12
+ ansi_c: [558.8, 431.8],
13
+ ansi_d: [863.6, 558.8],
14
+ ansi_e: [1117.6, 863.6],
15
+ } as const
16
+ export const assemblyDrawingPageSize = z.enum([
17
+ "iso_a0",
18
+ "iso_a1",
19
+ "iso_a2",
20
+ "iso_a3",
21
+ "iso_a4",
22
+ "ansi_a",
23
+ "ansi_b",
24
+ "ansi_c",
25
+ "ansi_d",
26
+ "ansi_e",
27
+ ])
28
+ export type AssemblyDrawingPageSize = z.infer<typeof assemblyDrawingPageSize>
29
+ export function getAssemblyDrawingPageDimensions(
30
+ size: AssemblyDrawingPageSize,
31
+ orientation: "landscape" | "portrait" = "landscape",
32
+ ) {
33
+ const [width, height] = assemblyDrawingPageSizes[size]
34
+ return orientation === "portrait"
35
+ ? { width: height, height: width }
36
+ : { width, height }
37
+ }
@@ -0,0 +1,64 @@
1
+ import { z } from "zod"
2
+ import {
3
+ assemblyDrawingPageSize,
4
+ getAssemblyDrawingPageDimensions,
5
+ type AssemblyDrawingPageSize,
6
+ } from "./page-size"
7
+ import { distance } from "circuit-json"
8
+ import type { Distance } from "lib/common/distance"
9
+ import { expectTypesMatch } from "lib/typecheck"
10
+
11
+ /** A paper-space drawing page containing configured part views. */
12
+ export interface AssemblyDrawingPageProps {
13
+ name?: string
14
+ displayName?: string
15
+ /** Standard sheet size; landscape by default. Mutually exclusive with width/height. */
16
+ size?: AssemblyDrawingPageSize
17
+ orientation?: "landscape" | "portrait"
18
+ /** Custom paper dimensions in mm when numeric; unit strings are accepted. */
19
+ width?: Distance
20
+ height?: Distance
21
+ children?: any
22
+ }
23
+
24
+ export const assemblyDrawingPageProps = z
25
+ .object({
26
+ name: z.string().optional(),
27
+ displayName: z.string().optional(),
28
+ size: assemblyDrawingPageSize.optional(),
29
+ orientation: z.enum(["landscape", "portrait"]).optional(),
30
+ width: distance.pipe(z.number().finite().positive()).optional(),
31
+ height: distance.pipe(z.number().finite().positive()).optional(),
32
+ children: z.any().optional(),
33
+ })
34
+ .superRefine((page, ctx) => {
35
+ if (
36
+ page.size
37
+ ? page.width != null || page.height != null
38
+ : page.width == null || page.height == null
39
+ )
40
+ ctx.addIssue({
41
+ code: "custom",
42
+ message: "Specify size or both width and height, exclusively",
43
+ })
44
+ if (!page.size && page.orientation)
45
+ ctx.addIssue({
46
+ code: "custom",
47
+ path: ["orientation"],
48
+ message: "Orientation requires a standard size",
49
+ })
50
+ })
51
+ .transform((page) => ({
52
+ ...page,
53
+ ...(page.size
54
+ ? getAssemblyDrawingPageDimensions(page.size, page.orientation)
55
+ : { width: page.width!, height: page.height! }),
56
+ }))
57
+
58
+ export type InferredAssemblyDrawingPageProps = z.input<
59
+ typeof assemblyDrawingPageProps
60
+ >
61
+ expectTypesMatch<
62
+ AssemblyDrawingPageProps,
63
+ z.input<typeof assemblyDrawingPageProps>
64
+ >(true)
@@ -0,0 +1,118 @@
1
+ import { z } from "zod"
2
+ import { distance } from "circuit-json"
3
+ import type { Distance } from "lib/common/distance"
4
+ import { expectTypesMatch } from "lib/typecheck"
5
+
6
+ /** Axis names use tscircuit CAD coordinates: mm, +Z up. The camera sits on
7
+ * the named side of the model and looks toward its center. */
8
+ export type AssemblyDrawingPartViewDirection =
9
+ | "x+"
10
+ | "x-"
11
+ | "y+"
12
+ | "y-"
13
+ | "z+"
14
+ | "z-"
15
+ | "isometric"
16
+
17
+ export interface AssemblyDrawingSectionPlane {
18
+ axis: "x" | "y" | "z"
19
+ /** Plane coordinate in CAD world space, numeric mm or a distance string. */
20
+ offset: Distance
21
+ /** Retain coordinates <= offset or >= offset, respectively. */
22
+ keepSide: "less" | "greater"
23
+ /** Physical distance between 45-degree strokes on the model. Defaults to 1mm. */
24
+ hatchSpacing?: Distance
25
+ }
26
+
27
+ export const assemblyDrawingSectionPlane = z.object({
28
+ axis: z.enum(["x", "y", "z"]),
29
+ offset: distance.pipe(z.number().finite()),
30
+ keepSide: z.enum(["less", "greater"]),
31
+ hatchSpacing: distance.pipe(z.number().finite().positive()).default(1),
32
+ })
33
+
34
+ /** An orthographic viewport within an assembly.drawing.page. */
35
+ export interface AssemblyDrawingPartViewProps {
36
+ name?: string
37
+ displayName?: string
38
+ /** Selector for the board, group or assembly geometry shown in this view. */
39
+ partRef: string
40
+ direction: AssemblyDrawingPartViewDirection
41
+ /** Viewport center relative to the paper center, mm; +X right, +Y up. Defaults to 0 on axes without a relative reference. */
42
+ centerX?: Distance
43
+ centerY?: Distance
44
+ /** Sibling part-view selector; infer centerX with this viewport left of the reference. Conflicts with rightOfRef and centerX. */
45
+ leftOfRef?: string
46
+ /** Sibling part-view selector; infer centerX with this viewport right of the reference. Conflicts with leftOfRef and centerX. */
47
+ rightOfRef?: string
48
+ /** Sibling part-view selector; infer centerY with this viewport above the reference. Conflicts with belowRef and centerY. */
49
+ aboveRef?: string
50
+ /** Sibling part-view selector; infer centerY with this viewport below the reference. Conflicts with aboveRef and centerY. */
51
+ belowRef?: string
52
+ /** Paper-space viewport size; dimensions must be positive. */
53
+ width: Distance
54
+ height: Distance
55
+ /** Draw obscured edges as dashed strokes. Defaults to false. */
56
+ showHiddenEdges?: boolean
57
+ /** A planar cut with diagonal hatching on closed cut surfaces. */
58
+ section?: AssemblyDrawingSectionPlane
59
+ }
60
+
61
+ export const assemblyDrawingPartViewProps = z
62
+ .object({
63
+ name: z.string().optional(),
64
+ displayName: z.string().optional(),
65
+ partRef: z.string().min(1),
66
+ direction: z.enum(["x+", "x-", "y+", "y-", "z+", "z-", "isometric"]),
67
+ centerX: distance.pipe(z.number().finite()).optional(),
68
+ centerY: distance.pipe(z.number().finite()).optional(),
69
+ leftOfRef: z.string().trim().min(1).optional(),
70
+ rightOfRef: z.string().trim().min(1).optional(),
71
+ aboveRef: z.string().trim().min(1).optional(),
72
+ belowRef: z.string().trim().min(1).optional(),
73
+ width: distance.pipe(z.number().finite().positive()),
74
+ height: distance.pipe(z.number().finite().positive()),
75
+ showHiddenEdges: z.boolean().default(false),
76
+ section: assemblyDrawingSectionPlane.optional(),
77
+ })
78
+ .superRefine((view, ctx) => {
79
+ for (const [center, negative, positive] of [
80
+ ["centerX", "leftOfRef", "rightOfRef"],
81
+ ["centerY", "belowRef", "aboveRef"],
82
+ ] as const) {
83
+ if (view[negative] !== undefined && view[positive] !== undefined)
84
+ ctx.addIssue({
85
+ code: "custom",
86
+ path: [positive],
87
+ message: `${negative} and ${positive} are mutually exclusive`,
88
+ })
89
+ if (
90
+ view[center] !== undefined &&
91
+ (view[negative] !== undefined || view[positive] !== undefined)
92
+ )
93
+ ctx.addIssue({
94
+ code: "custom",
95
+ path: [center],
96
+ message: `${center} cannot be combined with ${negative} or ${positive}`,
97
+ })
98
+ }
99
+ })
100
+ .transform((view) => ({
101
+ ...view,
102
+ ...(view.leftOfRef || view.rightOfRef
103
+ ? {}
104
+ : { centerX: view.centerX ?? 0 }),
105
+ ...(view.aboveRef || view.belowRef ? {} : { centerY: view.centerY ?? 0 }),
106
+ }))
107
+
108
+ export type InferredAssemblyDrawingPartViewProps = z.input<
109
+ typeof assemblyDrawingPartViewProps
110
+ >
111
+ expectTypesMatch<
112
+ AssemblyDrawingSectionPlane,
113
+ z.input<typeof assemblyDrawingSectionPlane>
114
+ >(true)
115
+ expectTypesMatch<
116
+ AssemblyDrawingPartViewProps,
117
+ z.input<typeof assemblyDrawingPartViewProps>
118
+ >(true)
@@ -0,0 +1,43 @@
1
+ import { z } from "zod"
2
+ import { expectTypesMatch } from "lib/typecheck"
3
+
4
+ /** Optional page child. Metadata fields reference ISO 7200:2004. */
5
+ export interface AssemblyDrawingTitleBlockProps {
6
+ name?: string
7
+ title: string
8
+ legalOwner?: string
9
+ identificationNumber?: string
10
+ revisionIndex?: string
11
+ dateOfIssue?: string
12
+ creator?: string
13
+ approvalPerson?: string
14
+ sheetNumber?: number
15
+ numberOfSheets?: number
16
+ }
17
+ export const assemblyDrawingTitleBlockProps = z
18
+ .object({
19
+ name: z.string().optional(),
20
+ title: z.string().min(1),
21
+ legalOwner: z.string().optional(),
22
+ identificationNumber: z.string().optional(),
23
+ revisionIndex: z.string().optional(),
24
+ dateOfIssue: z.string().optional(),
25
+ creator: z.string().optional(),
26
+ approvalPerson: z.string().optional(),
27
+ sheetNumber: z.number().int().positive().optional(),
28
+ numberOfSheets: z.number().int().positive().optional(),
29
+ })
30
+ .refine(
31
+ (block) =>
32
+ block.sheetNumber == null ||
33
+ block.numberOfSheets == null ||
34
+ block.sheetNumber <= block.numberOfSheets,
35
+ {
36
+ message: "sheetNumber must not exceed numberOfSheets",
37
+ path: ["sheetNumber"],
38
+ },
39
+ )
40
+ expectTypesMatch<
41
+ AssemblyDrawingTitleBlockProps,
42
+ z.input<typeof assemblyDrawingTitleBlockProps>
43
+ >(true)
@@ -1,3 +1,4 @@
1
+ import { assemblyDrawingProps } from "./drawing"
1
2
  import { assemblyCadAssemblyProps } from "./cadassembly"
2
3
  import { assemblyCableProps } from "./cable"
3
4
  import { assemblyBoltProps } from "./bolt"
@@ -11,6 +12,7 @@ import { assemblyScreenProps } from "./screen"
11
12
  import { assemblySubassemblyProps } from "./subassembly"
12
13
  import { assemblyExplosionProps } from "./explosion"
13
14
 
15
+ export * from "./drawing"
14
16
  export * from "./board-mounting"
15
17
  export * from "./bolt"
16
18
  export * from "./fastener"
@@ -26,6 +28,7 @@ export * from "./cadassembly"
26
28
  export * from "./explosion"
27
29
 
28
30
  export const assemblyProps = {
31
+ drawing: assemblyDrawingProps,
29
32
  explosion: assemblyExplosionProps,
30
33
  bolt: assemblyBoltProps,
31
34
  fastener: assemblyFastenerProps,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscircuit/props",
3
- "version": "0.0.707",
3
+ "version": "0.0.708",
4
4
  "description": "Props for tscircuit builtin component types",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",