@tscircuit/props 0.0.682 → 0.0.683

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,56 @@
1
+ import type { AutocompleteString } from "lib/common/autocomplete"
2
+ import { z } from "zod"
3
+
4
+ export type BoardMountRotationAnchor = AutocompleteString<
5
+ "topedge" | "bottomedge" | "leftedge" | "rightedge"
6
+ >
7
+
8
+ export type BoardMountOrientation =
9
+ | "top_layer_toward_mount_face"
10
+ | "bottom_layer_toward_mount_face"
11
+
12
+ const identityPathPattern =
13
+ "[A-Za-z_][A-Za-z0-9_-]*(?:\\.[A-Za-z_][A-Za-z0-9_-]*)*"
14
+ const referencePattern =
15
+ "[A-Za-z_][A-Za-z0-9_-]*(?:\\.[A-Za-z_][A-Za-z0-9_-]*)+"
16
+ const reference = new RegExp(`^${referencePattern}$`)
17
+ const anchor = new RegExp(`^${identityPathPattern}$`)
18
+ const expression = new RegExp(
19
+ `^calc\\(\\s*(${referencePattern})\\s*(?:([+-])\\s*((?:\\d+(?:\\.\\d*)?|\\.\\d+))\\s*(degcw|degccw))?\\s*\\)$`,
20
+ )
21
+
22
+ export const boardMountRotation = z
23
+ .string()
24
+ .trim()
25
+ .superRefine((value, ctx) => {
26
+ if (reference.test(value)) return
27
+ const match = expression.exec(value)
28
+ if (!match) {
29
+ ctx.addIssue({
30
+ code: z.ZodIssueCode.custom,
31
+ message:
32
+ "Expected a qualified mounting reference or calc(reference +/- Ndegcw|Ndegccw)",
33
+ })
34
+ return
35
+ }
36
+ if (match[3] !== undefined && !Number.isFinite(Number(match[3]))) {
37
+ ctx.addIssue({
38
+ code: z.ZodIssueCode.custom,
39
+ message: "Mount rotation angle must be finite",
40
+ })
41
+ }
42
+ })
43
+
44
+ export const boardMountRotationAnchor = z
45
+ .custom<BoardMountRotationAnchor>((value) => typeof value === "string", {
46
+ message: "Expected a board edge or component identity path",
47
+ })
48
+ .transform((value) => value.trim())
49
+ .refine((value) => anchor.test(value), {
50
+ message: "Expected a board edge or component identity path",
51
+ })
52
+
53
+ export const boardMountOrientation = z.enum([
54
+ "top_layer_toward_mount_face",
55
+ "bottom_layer_toward_mount_face",
56
+ ])
@@ -4,6 +4,7 @@ import { assemblyMotorProps } from "./motor"
4
4
  import { assemblyScreenProps } from "./screen"
5
5
  import { assemblySubassemblyProps } from "./subassembly"
6
6
 
7
+ export * from "./board-mounting"
7
8
  export * from "./device"
8
9
  export * from "./motor"
9
10
  export * from "./screen"
@@ -23,6 +23,8 @@ export interface AssemblyMotorProps {
23
23
  * shaft. Defaults to "z+", the native shaft axis of the NEMA models.
24
24
  */
25
25
  shaftFacingDirection?: CadModelAxisDirection
26
+ /** e.g. "jst-ph-6". */
27
+ wireConnection?: "none" | "stubs" | "jst-ph-6"
26
28
  }
27
29
 
28
30
  export const assemblyMotorProps = z
@@ -34,8 +36,17 @@ export const assemblyMotorProps = z
34
36
  standard: z.enum(["nema8", "nema17", "nema23"]).optional(),
35
37
  model: z.string().trim().min(1).optional(),
36
38
  shaftFacingDirection: cadModelAxisDirection.default("z+"),
39
+ wireConnection: z.enum(["none", "stubs", "jst-ph-6"]).optional(),
37
40
  })
38
41
  .superRefine((motor, context) => {
42
+ if (motor.model !== undefined && motor.wireConnection !== undefined) {
43
+ context.addIssue({
44
+ code: z.ZodIssueCode.custom,
45
+ message:
46
+ "Set wireConnection in the custom model string, or use standard",
47
+ path: ["wireConnection"],
48
+ })
49
+ }
39
50
  if (motor.standard === undefined && motor.model === undefined) {
40
51
  context.addIssue({
41
52
  code: z.ZodIssueCode.custom,
@@ -5,6 +5,13 @@ import { type Point, point } from "lib/common/point"
5
5
  import { expectTypesMatch } from "lib/typecheck"
6
6
  import { z } from "zod"
7
7
  import { subcircuitGroupProps, type SubcircuitGroupProps } from "./group"
8
+ import {
9
+ boardMountOrientation,
10
+ boardMountRotation,
11
+ boardMountRotationAnchor,
12
+ type BoardMountOrientation,
13
+ type BoardMountRotationAnchor,
14
+ } from "../assembly/board-mounting"
8
15
 
9
16
  const boardColorPresets = [
10
17
  "not_specified",
@@ -78,17 +85,16 @@ export const boardOutlinePoint = z
78
85
  export interface BoardProps
79
86
  extends Omit<SubcircuitGroupProps, "subcircuit" | "connections" | "outline"> {
80
87
  title?: string
81
- /**
82
- * Assembly mounting target, such as "NEMA17.backface". Trimmed; omitted
83
- * leaves the board unattached. The target face is resolved by the consumer.
84
- */
88
+ /** e.g. "NEMA17.backface". */
85
89
  mountedTo?: string
86
- /**
87
- * Nonnegative finite clearance between the target mounting face and the
88
- * nearest PCB surface, in millimeters or a unit string. Parsed to mm.
89
- * Omitted leaves the gap unset; only meaningful when mountedTo is supplied.
90
- */
90
+ /** Clearance from the mounting face, e.g. "6mm". */
91
91
  mountGap?: Distance
92
+ /** e.g. "J_USB" or "rightedge". */
93
+ mountRotationAnchor?: BoardMountRotationAnchor
94
+ /** e.g. "calc(NEMA17.wireside-90degcw)". */
95
+ mountRotation?: string
96
+ /** e.g. "top_layer_toward_mount_face". */
97
+ mountOrientation?: BoardMountOrientation
92
98
  /** Fabricator preset, preserved as supplied. Omitted leaves the preset unset. */
93
99
  fabricatorPreset?:
94
100
  | "jlcpcb_economy"
@@ -169,15 +175,20 @@ export const boardProps = subcircuitGroupProps
169
175
  .trim()
170
176
  .min(1)
171
177
  .optional()
172
- .describe(
173
- 'Assembly mounting target, such as "NEMA17.backface". Trimmed; omitted leaves the board unattached. The target face is resolved by the consumer.',
174
- ),
178
+ .describe('e.g. "NEMA17.backface".'),
175
179
  mountGap: distance
176
180
  .pipe(z.number().nonnegative().finite())
177
181
  .optional()
178
- .describe(
179
- "Nonnegative finite clearance between the target mounting face and the nearest PCB surface, in millimeters or a unit string, parsed to mm. Omitted leaves the gap unset; only meaningful when mountedTo is supplied.",
180
- ),
182
+ .describe('Clearance from the mounting face, e.g. "6mm".'),
183
+ mountRotationAnchor: boardMountRotationAnchor
184
+ .optional()
185
+ .describe('e.g. "J_USB" or "rightedge".'),
186
+ mountRotation: boardMountRotation
187
+ .optional()
188
+ .describe('e.g. "calc(NEMA17.wireside-90degcw)".'),
189
+ mountOrientation: boardMountOrientation
190
+ .optional()
191
+ .describe('e.g. "top_layer_toward_mount_face".'),
181
192
  fabricatorPreset: z
182
193
  .enum([
183
194
  "jlcpcb_economy",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscircuit/props",
3
- "version": "0.0.682",
3
+ "version": "0.0.683",
4
4
  "description": "Props for tscircuit builtin component types",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",