@tscircuit/props 0.0.639 → 0.0.641

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,41 @@
1
+ import { layer_ref, type LayerRefInput } from "circuit-json"
2
+ import { expectTypesMatch } from "lib/typecheck"
3
+ import { z } from "zod"
4
+ import { point, type Point } from "./point"
5
+
6
+ export interface PcbPathPoint extends Point {
7
+ via?: boolean
8
+ fromLayer?: LayerRefInput
9
+ toLayer?: LayerRefInput
10
+ }
11
+
12
+ const basePcbPathPoint = point.extend({
13
+ via: z.boolean().optional(),
14
+ fromLayer: layer_ref.optional(),
15
+ toLayer: layer_ref.optional(),
16
+ })
17
+
18
+ export const pcbPathPoint = basePcbPathPoint.superRefine((value, ctx) => {
19
+ if (value.via) {
20
+ if (!value.toLayer) {
21
+ ctx.addIssue({
22
+ code: z.ZodIssueCode.custom,
23
+ message: "toLayer is required when via is true",
24
+ path: ["toLayer"],
25
+ })
26
+ }
27
+ } else if (value.fromLayer || value.toLayer) {
28
+ ctx.addIssue({
29
+ code: z.ZodIssueCode.custom,
30
+ message: "fromLayer/toLayer are only allowed when via is true",
31
+ path: ["via"],
32
+ })
33
+ }
34
+ })
35
+
36
+ export const pcbPath = z.array(z.union([pcbPathPoint, z.string()]))
37
+
38
+ export type PcbPath = Array<PcbPathPoint | string>
39
+
40
+ expectTypesMatch<PcbPathPoint, z.input<typeof pcbPathPoint>>(true)
41
+ expectTypesMatch<PcbPath, z.input<typeof pcbPath>>(true)
@@ -0,0 +1,23 @@
1
+ import {
2
+ type CommonComponentProps,
3
+ commonComponentProps,
4
+ } from "lib/common/layout"
5
+ import { type PcbPath, pcbPath } from "lib/common/pcbPath"
6
+ import { expectTypesMatch } from "lib/typecheck"
7
+ import { z } from "zod"
8
+
9
+ /** Props for an antenna component with an optional explicit PCB path. */
10
+ export interface AntennaProps extends CommonComponentProps {
11
+ /**
12
+ * Explicit antenna path. Entries use the same selector, point, and via
13
+ * syntax as trace pcbPath entries.
14
+ */
15
+ pcbPath?: PcbPath
16
+ }
17
+
18
+ export const antennaProps = commonComponentProps.extend({
19
+ pcbPath: pcbPath.optional(),
20
+ })
21
+
22
+ type InferredAntennaProps = z.input<typeof antennaProps>
23
+ expectTypesMatch<AntennaProps, InferredAntennaProps>(true)
@@ -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(),
@@ -1,6 +1,7 @@
1
- import { distance, layer_ref, route_hint_point } from "circuit-json"
1
+ import { distance, route_hint_point } from "circuit-json"
2
2
  import { z } from "zod"
3
3
  import { point } from "../common/point"
4
+ import { pcbPath } from "../common/pcbPath"
4
5
 
5
6
  export const portRef = z.union([
6
7
  z.string(),
@@ -13,32 +14,6 @@ export const portRef = z.union([
13
14
  ),
14
15
  ])
15
16
 
16
- const pcbPathPoint = point
17
- .extend({
18
- via: z.boolean().optional(),
19
- fromLayer: layer_ref.optional(),
20
- toLayer: layer_ref.optional(),
21
- })
22
- .superRefine((value, ctx) => {
23
- if (value.via) {
24
- if (!value.toLayer) {
25
- ctx.addIssue({
26
- code: z.ZodIssueCode.custom,
27
- message: "toLayer is required when via is true",
28
- path: ["toLayer"],
29
- })
30
- }
31
- } else if (value.fromLayer || value.toLayer) {
32
- ctx.addIssue({
33
- code: z.ZodIssueCode.custom,
34
- message: "fromLayer/toLayer are only allowed when via is true",
35
- path: ["via"],
36
- })
37
- }
38
- })
39
-
40
- const pcbPath = z.array(z.union([pcbPathPoint, z.string()]))
41
-
42
17
  const baseTraceProps = z.object({
43
18
  key: z.string().optional(),
44
19
  name: z.string().optional(),
package/lib/index.ts CHANGED
@@ -6,6 +6,7 @@ export * from "./common/portHints"
6
6
  export * from "./common/layout"
7
7
  export * from "./common/pinAttributeMap"
8
8
  export * from "./common/point3"
9
+ export * from "./common/pcbPath"
9
10
  export * from "./common/portHints"
10
11
  export * from "./common/footprintProp"
11
12
  export * from "./common/symbolProp"
@@ -57,6 +58,7 @@ export * from "./components/drc-check"
57
58
  export * from "./components/smtpad"
58
59
  export * from "./components/solderpaste"
59
60
  export * from "./components/hole"
61
+ export * from "./components/antenna"
60
62
  export * from "./components/trace"
61
63
  export * from "./components/bus"
62
64
  export * from "./components/differentialpair"
@@ -121,6 +123,7 @@ export * from "./components/schematic-row"
121
123
  export * from "./components/schematic-cell"
122
124
  export * from "./components/schematic-section"
123
125
  export * from "./components/schematic-sheet"
126
+ export * from "./components/schematic-graphic"
124
127
  export * from "./components/copper-text"
125
128
  export * from "./components/silkscreen-text"
126
129
  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.641",
4
4
  "description": "Props for tscircuit builtin component types",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",