@tscircuit/props 0.0.688 → 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.
@@ -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.688",
3
+ "version": "0.0.689",
4
4
  "description": "Props for tscircuit builtin component types",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",