@tscircuit/props 0.0.687 → 0.0.689

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.
@@ -44,6 +44,11 @@ export interface PinAttributeMap {
44
44
  requiresGround?: boolean
45
45
  providesVoltage?: string | number
46
46
  requiresVoltage?: string | number
47
+ /**
48
+ * Allowed relative deviation from requiresVoltage, e.g. 0.05 or "5%" for ±5%.
49
+ * Parsed as a fraction from 0 to 1; omitted values remain undefined.
50
+ */
51
+ requiredVoltageTolerance?: number | string
47
52
  doNotConnect?: boolean
48
53
  includeInBoardPinout?: boolean
49
54
  highlightColor?: string
@@ -83,6 +88,24 @@ export const pinAttributeMap = z.object({
83
88
  requiresGround: z.boolean().optional(),
84
89
  providesVoltage: z.union([z.string(), z.number()]).optional(),
85
90
  requiresVoltage: z.union([z.string(), z.number()]).optional(),
91
+ requiredVoltageTolerance: z
92
+ .union([
93
+ z.number(),
94
+ z
95
+ .string()
96
+ .trim()
97
+ .regex(
98
+ /^(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?\s*%?$/,
99
+ "Expected a tolerance fraction or percentage",
100
+ )
101
+ .transform((value) =>
102
+ value.endsWith("%")
103
+ ? Number(value.slice(0, -1)) / 100
104
+ : Number(value),
105
+ ),
106
+ ])
107
+ .pipe(z.number().finite().min(0).max(1))
108
+ .optional(),
86
109
  doNotConnect: z.boolean().optional(),
87
110
  includeInBoardPinout: z.boolean().optional(),
88
111
  highlightColor: z.string().optional(),
@@ -4,7 +4,9 @@ import { cadModelBase, type CadModelBase } from "../common/cadModel"
4
4
  import { url } from "lib/common/url"
5
5
  import { z } from "zod"
6
6
 
7
+ /** Parsed CAD model props. Author model strings with CadModelPropsInput. */
7
8
  export interface CadModelProps extends CadModelBase {
9
+ /** Canonical model URL after parsing; authored model strings resolve to this field. */
8
10
  modelUrl: string
9
11
  stepUrl?: string
10
12
  pcbX?: Distance
@@ -38,6 +40,42 @@ const cadModelBaseWithUrl = cadModelBase.extend({
38
40
  const cadModelObject = cadModelBaseWithUrl.merge(pcbPosition)
39
41
  expectTypesMatch<CadModelProps, z.input<typeof cadModelObject>>(true)
40
42
 
41
- export const cadmodelProps = z.union([z.null(), url, cadModelObject])
43
+ const cadModelInputObject = cadModelBase
44
+ .extend({
45
+ /** Modelprinter specification or HTTP(S) URL; mutually exclusive with modelUrl. */
46
+ model: z.string().trim().min(1).optional(),
47
+ modelUrl: url.optional(),
48
+ })
49
+ .merge(pcbPosition)
50
+ .refine(
51
+ (props) => (props.model === undefined) !== (props.modelUrl === undefined),
52
+ {
53
+ message: "Provide exactly one of model or modelUrl",
54
+ path: ["model"],
55
+ },
56
+ )
57
+ .transform(({ model, ...props }) => ({
58
+ ...props,
59
+ modelUrl:
60
+ model === undefined
61
+ ? props.modelUrl!
62
+ : /^https?:\/\//i.test(model)
63
+ ? model
64
+ : `https://modelcdn.tscircuit.com/jscad_models/${encodeURIComponent(model)}.glb`,
65
+ }))
66
+ .pipe(cadModelObject)
67
+
68
+ expectTypesMatch<
69
+ z.output<typeof cadModelObject>,
70
+ z.output<typeof cadModelInputObject>
71
+ >(true)
72
+
73
+ /**
74
+ * Object inputs require exactly one of model or modelUrl. Modelprinter strings
75
+ * are trimmed and resolved to modelUrl; HTTP(S) model URLs are preserved.
76
+ * Parsed objects retain the existing CadModelProps shape, without a model field.
77
+ * Existing modelUrl objects, bare URL strings, and null remain supported.
78
+ */
79
+ export const cadmodelProps = z.union([z.null(), url, cadModelInputObject])
42
80
 
43
81
  export type CadModelPropsInput = z.input<typeof cadmodelProps>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscircuit/props",
3
- "version": "0.0.687",
3
+ "version": "0.0.689",
4
4
  "description": "Props for tscircuit builtin component types",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",