@tscircuit/props 0.0.549 → 0.0.550

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,55 @@
1
+ import {
2
+ type CommonComponentProps,
3
+ commonComponentProps,
4
+ } from "lib/common/layout"
5
+ import { createConnectionsProp } from "lib/common/connectionsProp"
6
+ import type { Connections } from "lib/utility-types/connections-and-selectors"
7
+ import { expectTypesMatch } from "lib/typecheck"
8
+ import { z } from "zod"
9
+
10
+ export const ammeterPinLabels = ["pin1", "pin2", "pos", "neg"] as const
11
+ export type AmmeterPinLabels = (typeof ammeterPinLabels)[number]
12
+
13
+ export interface AmmeterDisplayOptions {
14
+ label?: string
15
+ center?: number
16
+ offsetDivs?: number
17
+ unitsPerDiv?: number
18
+ }
19
+
20
+ export interface AmmeterProps<PinLabel extends string = string>
21
+ extends CommonComponentProps<PinLabel> {
22
+ connections: Connections<AmmeterPinLabels>
23
+ color?: string
24
+ display?: AmmeterDisplayOptions
25
+ }
26
+
27
+ const hasAmmeterConnectionPair = (
28
+ connections: Connections<AmmeterPinLabels>,
29
+ ) => {
30
+ return (
31
+ (connections.pos !== undefined && connections.neg !== undefined) ||
32
+ (connections.pin1 !== undefined && connections.pin2 !== undefined)
33
+ )
34
+ }
35
+
36
+ export const ammeterDisplayOptions = z.object({
37
+ label: z.string().optional(),
38
+ center: z.number().optional(),
39
+ offsetDivs: z.number().optional(),
40
+ unitsPerDiv: z.number().optional(),
41
+ })
42
+
43
+ export const ammeterProps = commonComponentProps.extend({
44
+ connections: createConnectionsProp(ammeterPinLabels).refine(
45
+ hasAmmeterConnectionPair,
46
+ "Ammeter connections must include either pos/neg or pin1/pin2",
47
+ ),
48
+ color: z.string().optional(),
49
+ display: ammeterDisplayOptions.optional(),
50
+ })
51
+
52
+ export const ammeterPins = ammeterPinLabels
53
+
54
+ type InferredAmmeterProps = z.input<typeof ammeterProps>
55
+ expectTypesMatch<AmmeterProps, InferredAmmeterProps>(true)
package/lib/index.ts CHANGED
@@ -95,6 +95,7 @@ export * from "./components/power-source"
95
95
  export * from "./components/voltagesource"
96
96
  export * from "./components/currentsource"
97
97
  export * from "./components/voltageprobe"
98
+ export * from "./components/ammeter"
98
99
  export * from "./components/schematic-arc"
99
100
  export * from "./components/toolingrail"
100
101
  export * from "./components/schematic-box"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscircuit/props",
3
- "version": "0.0.549",
3
+ "version": "0.0.550",
4
4
  "description": "Props for tscircuit builtin component types",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",