@tscircuit/props 0.0.638 → 0.0.640
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 +27 -2
- package/dist/index.d.ts +66 -9
- package/dist/index.js +182 -151
- package/dist/index.js.map +1 -1
- package/lib/components/schematic-graphic.ts +62 -0
- package/lib/components/schematic-sheet.ts +12 -4
- package/lib/index.ts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { z } from "zod"
|
|
2
|
+
import { type Distance, distance } from "lib/common/distance"
|
|
3
|
+
import { url } from "lib/common/url"
|
|
4
|
+
import { expectTypesMatch } from "lib/typecheck"
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Props for embedding an image or raw SVG graphic in a schematic sheet.
|
|
8
|
+
* At least one source is required; both sources may be provided.
|
|
9
|
+
* When both are provided, imageUrl is the canonical asset source and
|
|
10
|
+
* svgContent is optional materialized fallback content.
|
|
11
|
+
*/
|
|
12
|
+
export interface SchematicGraphicProps {
|
|
13
|
+
/** URL or static-file import for the canonical source SVG asset. */
|
|
14
|
+
imageUrl?: string
|
|
15
|
+
/**
|
|
16
|
+
* Complete SVG markup, including its dimensions or viewBox. Used as the
|
|
17
|
+
* source when imageUrl is omitted, or as fallback content when both exist.
|
|
18
|
+
*/
|
|
19
|
+
svgContent?: string
|
|
20
|
+
/** Optional rendered width of the graphic. */
|
|
21
|
+
width?: Distance
|
|
22
|
+
/** Optional rendered height of the graphic. */
|
|
23
|
+
height?: Distance
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const nonemptyUrl = url.refine((value) => value.trim().length > 0, {
|
|
27
|
+
message: "imageUrl cannot be empty",
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
const positiveDistance = (fieldName: "width" | "height") =>
|
|
31
|
+
distance.refine((value) => Number.isFinite(value) && value > 0, {
|
|
32
|
+
message: `${fieldName} must be a positive finite distance`,
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
export const schematicGraphicProps = z
|
|
36
|
+
.object({
|
|
37
|
+
imageUrl: nonemptyUrl.optional(),
|
|
38
|
+
svgContent: z
|
|
39
|
+
.string()
|
|
40
|
+
.refine((value) => value.trim().length > 0, {
|
|
41
|
+
message: "svgContent cannot be empty",
|
|
42
|
+
})
|
|
43
|
+
.optional(),
|
|
44
|
+
width: positiveDistance("width").optional(),
|
|
45
|
+
height: positiveDistance("height").optional(),
|
|
46
|
+
})
|
|
47
|
+
.superRefine(({ imageUrl, svgContent }, ctx) => {
|
|
48
|
+
if (imageUrl === undefined && svgContent === undefined) {
|
|
49
|
+
ctx.addIssue({
|
|
50
|
+
code: z.ZodIssueCode.custom,
|
|
51
|
+
message: "At least one of imageUrl or svgContent is required",
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
export type InferredSchematicGraphicProps = z.input<
|
|
57
|
+
typeof schematicGraphicProps
|
|
58
|
+
>
|
|
59
|
+
|
|
60
|
+
expectTypesMatch<SchematicGraphicProps, z.input<typeof schematicGraphicProps>>(
|
|
61
|
+
true,
|
|
62
|
+
)
|
|
@@ -1,22 +1,30 @@
|
|
|
1
1
|
import { z } from "zod"
|
|
2
|
+
import { distance } from "circuit-json"
|
|
3
|
+
import type { Distance } from "lib/common/distance"
|
|
2
4
|
import { expectTypesMatch } from "lib/typecheck"
|
|
3
5
|
|
|
4
6
|
export type SchematicSheetSize = "A4" | "ANSI_B"
|
|
5
7
|
|
|
6
8
|
export interface SchematicSheetProps {
|
|
7
|
-
name
|
|
8
|
-
displayName
|
|
9
|
+
name?: string
|
|
10
|
+
displayName?: string
|
|
9
11
|
sheetIndex?: number
|
|
10
12
|
/** Sheet size used to render the schematic. Defaults to A4. */
|
|
11
13
|
sheetSize?: SchematicSheetSize
|
|
14
|
+
/** Explicit schematic sheet width. Overrides the width from sheetSize. */
|
|
15
|
+
sheetWidth?: Distance
|
|
16
|
+
/** Explicit schematic sheet height. Overrides the height from sheetSize. */
|
|
17
|
+
sheetHeight?: Distance
|
|
12
18
|
children?: any
|
|
13
19
|
}
|
|
14
20
|
|
|
15
21
|
export const schematicSheetProps = z.object({
|
|
16
|
-
name: z.string(),
|
|
17
|
-
displayName: z.string(),
|
|
22
|
+
name: z.string().optional(),
|
|
23
|
+
displayName: z.string().optional(),
|
|
18
24
|
sheetIndex: z.number().optional(),
|
|
19
25
|
sheetSize: z.enum(["A4", "ANSI_B"]).default("A4"),
|
|
26
|
+
sheetWidth: distance.pipe(z.number().positive()).optional(),
|
|
27
|
+
sheetHeight: distance.pipe(z.number().positive()).optional(),
|
|
20
28
|
children: z.any().optional(),
|
|
21
29
|
})
|
|
22
30
|
|
package/lib/index.ts
CHANGED
|
@@ -121,6 +121,7 @@ export * from "./components/schematic-row"
|
|
|
121
121
|
export * from "./components/schematic-cell"
|
|
122
122
|
export * from "./components/schematic-section"
|
|
123
123
|
export * from "./components/schematic-sheet"
|
|
124
|
+
export * from "./components/schematic-graphic"
|
|
124
125
|
export * from "./components/copper-text"
|
|
125
126
|
export * from "./components/silkscreen-text"
|
|
126
127
|
export * from "./components/silkscreen-path"
|