@tscircuit/props 0.0.668 → 0.0.670
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.
- package/README.md +2 -0
- package/dist/index.d.ts +2688 -353
- package/dist/index.js +41 -16
- package/dist/index.js.map +1 -1
- package/lib/assembly/device.ts +8 -0
- package/lib/assembly/screen.ts +22 -3
- package/lib/assembly/subassembly.ts +25 -8
- package/lib/common/schematicSize.ts +3 -2
- package/lib/components/diode.ts +8 -0
- package/lib/components/led.ts +4 -0
- package/package.json +1 -1
package/lib/assembly/device.ts
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
|
+
import { url } from "lib/common/url"
|
|
1
2
|
import { expectTypesMatch } from "lib/typecheck"
|
|
2
3
|
import { z } from "zod"
|
|
3
4
|
|
|
4
5
|
export interface AssemblyDeviceProps {
|
|
5
6
|
/** Product-level assembly identity. */
|
|
6
7
|
name?: string
|
|
8
|
+
/** Imported CAD model URL. Mutually exclusive with cadModel where supported. */
|
|
9
|
+
modelUrl?: string
|
|
7
10
|
}
|
|
8
11
|
|
|
9
12
|
export const assemblyDeviceProps = z.object({
|
|
10
13
|
name: z.string().optional(),
|
|
14
|
+
modelUrl: url
|
|
15
|
+
.refine((value) => value.trim().length > 0, {
|
|
16
|
+
message: "modelUrl cannot be empty",
|
|
17
|
+
})
|
|
18
|
+
.optional(),
|
|
11
19
|
})
|
|
12
20
|
|
|
13
21
|
export type AssemblyDevicePropsInput = z.input<typeof assemblyDeviceProps>
|
package/lib/assembly/screen.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { url } from "lib/common/url"
|
|
1
2
|
import { type Distance, distance } from "lib/common/distance"
|
|
2
3
|
import { expectTypesMatch } from "lib/typecheck"
|
|
3
4
|
import { z } from "zod"
|
|
@@ -5,6 +6,8 @@ import { z } from "zod"
|
|
|
5
6
|
export interface AssemblyScreenProps {
|
|
6
7
|
/** Stable product-level identity for the screen assembly. */
|
|
7
8
|
name: string
|
|
9
|
+
/** Imported CAD model URL. Mutually exclusive with cadModel where supported. */
|
|
10
|
+
modelUrl?: string
|
|
8
11
|
/** Selector for the connector that the screen attaches to. */
|
|
9
12
|
connectsTo: string
|
|
10
13
|
/**
|
|
@@ -19,7 +22,7 @@ export interface AssemblyScreenProps {
|
|
|
19
22
|
height?: Distance
|
|
20
23
|
/**
|
|
21
24
|
* Advanced modelprinter string used to render the screen assembly. Required
|
|
22
|
-
* when `width` and `
|
|
25
|
+
* when `width`, `height`, and `modelUrl` are omitted.
|
|
23
26
|
*/
|
|
24
27
|
cadModel?: string
|
|
25
28
|
}
|
|
@@ -37,12 +40,24 @@ const positiveDistance = (fieldName: "width" | "height") =>
|
|
|
37
40
|
export const assemblyScreenProps = z
|
|
38
41
|
.object({
|
|
39
42
|
name: nonemptyString("name"),
|
|
43
|
+
modelUrl: url
|
|
44
|
+
.refine((value) => value.trim().length > 0, {
|
|
45
|
+
message: "modelUrl cannot be empty",
|
|
46
|
+
})
|
|
47
|
+
.optional(),
|
|
40
48
|
connectsTo: nonemptyString("connectsTo"),
|
|
41
49
|
width: positiveDistance("width").optional(),
|
|
42
50
|
height: positiveDistance("height").optional(),
|
|
43
51
|
cadModel: nonemptyString("cadModel").optional(),
|
|
44
52
|
})
|
|
45
53
|
.superRefine((screen, context) => {
|
|
54
|
+
if (screen.modelUrl !== undefined && screen.cadModel !== undefined) {
|
|
55
|
+
context.addIssue({
|
|
56
|
+
code: z.ZodIssueCode.custom,
|
|
57
|
+
message: "Provide either modelUrl or cadModel, not both",
|
|
58
|
+
path: ["modelUrl"],
|
|
59
|
+
})
|
|
60
|
+
}
|
|
46
61
|
const hasWidth = screen.width !== undefined
|
|
47
62
|
const hasHeight = screen.height !== undefined
|
|
48
63
|
|
|
@@ -55,10 +70,14 @@ export const assemblyScreenProps = z
|
|
|
55
70
|
return
|
|
56
71
|
}
|
|
57
72
|
|
|
58
|
-
if (
|
|
73
|
+
if (
|
|
74
|
+
!hasWidth &&
|
|
75
|
+
screen.cadModel === undefined &&
|
|
76
|
+
screen.modelUrl === undefined
|
|
77
|
+
) {
|
|
59
78
|
context.addIssue({
|
|
60
79
|
code: z.ZodIssueCode.custom,
|
|
61
|
-
message: "provide
|
|
80
|
+
message: "provide width and height, cadModel, or modelUrl",
|
|
62
81
|
path: [],
|
|
63
82
|
})
|
|
64
83
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { url } from "lib/common/url"
|
|
1
2
|
import { type CadModelProp, cadModelProp } from "lib/common/cadModel"
|
|
2
3
|
import { expectTypesMatch } from "lib/typecheck"
|
|
3
4
|
import type { ReactNode } from "react"
|
|
@@ -6,6 +7,8 @@ import { z } from "zod"
|
|
|
6
7
|
export interface AssemblySubassemblyProps {
|
|
7
8
|
/** Stable identity used by selectors from other assembly elements. */
|
|
8
9
|
name: string
|
|
10
|
+
/** Imported CAD model URL. Mutually exclusive with cadModel where supported. */
|
|
11
|
+
modelUrl?: string
|
|
9
12
|
/** Human-facing alternate to the stable name. */
|
|
10
13
|
displayName?: string
|
|
11
14
|
/** Optional CAD geometry using the existing component cadModel formats. */
|
|
@@ -14,14 +17,28 @@ export interface AssemblySubassemblyProps {
|
|
|
14
17
|
children?: ReactNode
|
|
15
18
|
}
|
|
16
19
|
|
|
17
|
-
export const assemblySubassemblyProps = z
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
export const assemblySubassemblyProps = z
|
|
21
|
+
.object({
|
|
22
|
+
name: z.string().refine((value) => value.trim().length > 0, {
|
|
23
|
+
message: "name cannot be empty",
|
|
24
|
+
}),
|
|
25
|
+
displayName: z.string().optional(),
|
|
26
|
+
modelUrl: url
|
|
27
|
+
.refine((value) => value.trim().length > 0, {
|
|
28
|
+
message: "modelUrl cannot be empty",
|
|
29
|
+
})
|
|
30
|
+
.optional(),
|
|
31
|
+
cadModel: cadModelProp.optional(),
|
|
32
|
+
children: z.custom<ReactNode>().optional(),
|
|
33
|
+
})
|
|
34
|
+
.refine(
|
|
35
|
+
(assembly) =>
|
|
36
|
+
assembly.modelUrl === undefined || assembly.cadModel === undefined,
|
|
37
|
+
{
|
|
38
|
+
message: "Provide either modelUrl or cadModel, not both",
|
|
39
|
+
path: ["modelUrl"],
|
|
40
|
+
},
|
|
41
|
+
)
|
|
25
42
|
|
|
26
43
|
export type AssemblySubassemblyPropsInput = z.input<
|
|
27
44
|
typeof assemblySubassemblyProps
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { distance } from "circuit-json"
|
|
2
2
|
import { z } from "zod"
|
|
3
3
|
|
|
4
|
-
export const schematicSymbolSize =
|
|
5
|
-
.
|
|
4
|
+
export const schematicSymbolSize = z
|
|
5
|
+
.enum(["xs", "sm", "default", "md"])
|
|
6
|
+
.or(distance.pipe(z.number().finite()))
|
|
6
7
|
.describe("distance between pin1 and pin2 of the schematic symbol")
|
|
7
8
|
|
|
8
9
|
export type SchematicSymbolSize = z.input<typeof schematicSymbolSize>
|
package/lib/components/diode.ts
CHANGED
|
@@ -11,6 +11,11 @@ import {
|
|
|
11
11
|
} from "lib/common/schematicOrientation"
|
|
12
12
|
import { schematicPinLabel } from "lib/common/schematicPinLabel"
|
|
13
13
|
|
|
14
|
+
import {
|
|
15
|
+
schematicSymbolSize,
|
|
16
|
+
type SchematicSymbolSize,
|
|
17
|
+
} from "lib/common/schematicSize"
|
|
18
|
+
|
|
14
19
|
export const diodePins = lrPolarPins
|
|
15
20
|
export type DiodePinLabels = (typeof diodePins)[number]
|
|
16
21
|
export type DiodePinLabelsProp<PinLabel extends string = string> = Partial<
|
|
@@ -60,6 +65,7 @@ export const diodeProps = commonComponentProps
|
|
|
60
65
|
photo: z.boolean().optional(),
|
|
61
66
|
tvs: z.boolean().optional(),
|
|
62
67
|
schOrientation: schematicOrientation.optional(),
|
|
68
|
+
schSize: schematicSymbolSize.optional(),
|
|
63
69
|
pinLabels: diodePinLabelsProp.optional(),
|
|
64
70
|
})
|
|
65
71
|
.superRefine((data, ctx) => {
|
|
@@ -146,6 +152,8 @@ export interface DiodeProps<PinLabel extends string = string>
|
|
|
146
152
|
photo?: boolean
|
|
147
153
|
tvs?: boolean
|
|
148
154
|
schOrientation?: SchematicOrientation
|
|
155
|
+
/** Select a compact schematic symbol; omitted, default, and md retain the standard symbol. */
|
|
156
|
+
schSize?: SchematicSymbolSize
|
|
149
157
|
}
|
|
150
158
|
|
|
151
159
|
export type InferredDiodeProps = z.input<typeof diodeProps>
|
package/lib/components/led.ts
CHANGED
|
@@ -5,6 +5,8 @@ import { createConnectionsProp } from "lib/common/connectionsProp"
|
|
|
5
5
|
import { diodePinLabelsProp } from "lib/components/diode"
|
|
6
6
|
import { schematicPinLabel } from "lib/common/schematicPinLabel"
|
|
7
7
|
|
|
8
|
+
import { schematicSymbolSize } from "lib/common/schematicSize"
|
|
9
|
+
|
|
8
10
|
export type LedPinLabels = (typeof lrPolarPins)[number]
|
|
9
11
|
|
|
10
12
|
const legacyNumericLedPinLabelsProp = z
|
|
@@ -24,6 +26,8 @@ export const ledProps = commonComponentProps.extend({
|
|
|
24
26
|
wavelength: z.string().optional(),
|
|
25
27
|
schDisplayValue: z.string().optional(),
|
|
26
28
|
schOrientation: schematicOrientation.optional(),
|
|
29
|
+
/** Select a compact schematic symbol; omitted, default, and md retain the standard symbol. */
|
|
30
|
+
schSize: schematicSymbolSize.optional(),
|
|
27
31
|
// Numeric keys are accepted for compatibility with legacy generated LED
|
|
28
32
|
// wrappers, then normalized to the canonical pin1/pin2 representation.
|
|
29
33
|
pinLabels: diodePinLabelsProp.or(legacyNumericLedPinLabelsProp).optional(),
|