@tscircuit/props 0.0.639 → 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.
@@ -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
+ )
@@ -6,8 +6,8 @@ import { expectTypesMatch } from "lib/typecheck"
6
6
  export type SchematicSheetSize = "A4" | "ANSI_B"
7
7
 
8
8
  export interface SchematicSheetProps {
9
- name: string
10
- displayName: string
9
+ name?: string
10
+ displayName?: string
11
11
  sheetIndex?: number
12
12
  /** Sheet size used to render the schematic. Defaults to A4. */
13
13
  sheetSize?: SchematicSheetSize
@@ -19,8 +19,8 @@ export interface SchematicSheetProps {
19
19
  }
20
20
 
21
21
  export const schematicSheetProps = z.object({
22
- name: z.string(),
23
- displayName: z.string(),
22
+ name: z.string().optional(),
23
+ displayName: z.string().optional(),
24
24
  sheetIndex: z.number().optional(),
25
25
  sheetSize: z.enum(["A4", "ANSI_B"]).default("A4"),
26
26
  sheetWidth: distance.pipe(z.number().positive()).optional(),
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"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscircuit/props",
3
- "version": "0.0.639",
3
+ "version": "0.0.640",
4
4
  "description": "Props for tscircuit builtin component types",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",