@tscircuit/props 0.0.644 → 0.0.646

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,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)
@@ -30,6 +30,8 @@ export interface AutoroutingPhaseProps extends RoutingTolerances, FanoutProps {
30
30
  }
31
31
  connection?: string
32
32
  connections?: string[]
33
+ // Reroutes traces selected by region or connection. The simplify autorouter
34
+ // may omit a selector to simplify every existing trace in the phase.
33
35
  reroute?: boolean
34
36
  }
35
37
 
@@ -55,8 +57,20 @@ export const autoroutingPhaseProps = z
55
57
  ...fanoutProps.shape,
56
58
  })
57
59
  .superRefine((value, ctx) => {
60
+ const isSimplifyAutorouter =
61
+ value.autorouter === "simplify" ||
62
+ (typeof value.autorouter === "object" &&
63
+ value.autorouter?.preset === "simplify")
64
+
65
+ if (isSimplifyAutorouter && value.reroute !== true) {
66
+ console.warn(
67
+ 'The "simplify" autorouter preset should only be used with reroute=true',
68
+ )
69
+ }
70
+
58
71
  if (
59
72
  value.reroute !== undefined &&
73
+ !(isSimplifyAutorouter && value.reroute === true) &&
60
74
  value.region === undefined &&
61
75
  value.connection === undefined &&
62
76
  value.connections === undefined
@@ -356,6 +356,7 @@ export interface AutorouterConfig {
356
356
  | "tscircuit_beta"
357
357
  | "krt"
358
358
  | "freerouting"
359
+ | "simplify"
359
360
  | "laser_prefab" // Prefabricated PCB with laser copper ablation
360
361
  | "single_layer_fanout"
361
362
  | "fanout"
@@ -376,6 +377,7 @@ export type AutorouterPreset =
376
377
  | "tscircuit_beta"
377
378
  | "krt"
378
379
  | "freerouting"
380
+ | "simplify"
379
381
  | "laser_prefab"
380
382
  | "single_layer_fanout"
381
383
  | "fanout"
@@ -443,6 +445,7 @@ export const autorouterConfig = z.object({
443
445
  "tscircuit_beta",
444
446
  "krt",
445
447
  "freerouting",
448
+ "simplify",
446
449
  "laser_prefab",
447
450
  "single_layer_fanout",
448
451
  "fanout",
@@ -466,6 +469,7 @@ export const autorouterPreset = z.union([
466
469
  z.literal("tscircuit_beta"),
467
470
  z.literal("krt"),
468
471
  z.literal("freerouting"),
472
+ z.literal("simplify"),
469
473
  z.literal("laser_prefab"), // Prefabricated PCB with laser copper ablation
470
474
  z.literal("single_layer_fanout"),
471
475
  z.literal("fanout"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscircuit/props",
3
- "version": "0.0.644",
3
+ "version": "0.0.646",
4
4
  "description": "Props for tscircuit builtin component types",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",