@tscircuit/props 0.0.490 → 0.0.492

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.
@@ -20,6 +20,7 @@ import {
20
20
  } from "./kicadSymbolMetadata"
21
21
  import { type PcbStyle, pcbStyle } from "./pcbStyle"
22
22
  import { type PcbSx, pcbSx } from "./pcbSx"
23
+ import { pinAttributeMap, type PinAttributeMap } from "./pinAttributeMap"
23
24
  import { type SchStyle, schStyle } from "./schStyle"
24
25
  import { type SymbolProp, symbolProp } from "./symbolProp"
25
26
  import { url } from "./url"
@@ -229,129 +230,6 @@ export const supplierProps = z.object({
229
230
 
230
231
  expectTypesMatch<SupplierProps, z.input<typeof supplierProps>>(true)
231
232
 
232
- export interface PinAttributeMap {
233
- capabilities?: Array<
234
- | "i2c_sda"
235
- | "i2c_scl"
236
- | "spi_cs"
237
- | "spi_sck"
238
- | "spi_mosi"
239
- | "spi_miso"
240
- | "uart_tx"
241
- | "uart_rx"
242
- >
243
- activeCapabilities?: Array<
244
- | "i2c_sda"
245
- | "i2c_scl"
246
- | "spi_cs"
247
- | "spi_sck"
248
- | "spi_mosi"
249
- | "spi_miso"
250
- | "uart_tx"
251
- | "uart_rx"
252
- >
253
- activeCapability?:
254
- | "i2c_sda"
255
- | "i2c_scl"
256
- | "spi_cs"
257
- | "spi_sck"
258
- | "spi_mosi"
259
- | "spi_miso"
260
- | "uart_tx"
261
- | "uart_rx"
262
- providesPower?: boolean
263
- requiresPower?: boolean
264
- providesGround?: boolean
265
- requiresGround?: boolean
266
- providesVoltage?: string | number
267
- requiresVoltage?: string | number
268
- doNotConnect?: boolean
269
- includeInBoardPinout?: boolean
270
- highlightColor?: string
271
- mustBeConnected?: boolean
272
- canUseInternalPullup?: boolean
273
- isUsingInternalPullup?: boolean
274
- needsExternalPullup?: boolean
275
- canUseInternalPulldown?: boolean
276
- isUsingInternalPulldown?: boolean
277
- needsExternalPulldown?: boolean
278
- canUseOpenDrain?: boolean
279
- isUsingOpenDrain?: boolean
280
- canUsePushPull?: boolean
281
- isUsingPushPull?: boolean
282
- shouldHaveDecouplingCapacitor?: boolean
283
- recommendedDecouplingCapacitorCapacitance?: string | number
284
- }
285
-
286
- export const pinAttributeMap = z.object({
287
- capabilities: z
288
- .array(
289
- z.enum([
290
- "i2c_sda",
291
- "i2c_scl",
292
- "spi_cs",
293
- "spi_sck",
294
- "spi_mosi",
295
- "spi_miso",
296
- "uart_tx",
297
- "uart_rx",
298
- ]),
299
- )
300
- .optional(),
301
- activeCapabilities: z
302
- .array(
303
- z.enum([
304
- "i2c_sda",
305
- "i2c_scl",
306
- "spi_cs",
307
- "spi_sck",
308
- "spi_mosi",
309
- "spi_miso",
310
- "uart_tx",
311
- "uart_rx",
312
- ]),
313
- )
314
- .optional(),
315
- activeCapability: z
316
- .enum([
317
- "i2c_sda",
318
- "i2c_scl",
319
- "spi_cs",
320
- "spi_sck",
321
- "spi_mosi",
322
- "spi_miso",
323
- "uart_tx",
324
- "uart_rx",
325
- ])
326
- .optional(),
327
- providesPower: z.boolean().optional(),
328
- requiresPower: z.boolean().optional(),
329
- providesGround: z.boolean().optional(),
330
- requiresGround: z.boolean().optional(),
331
- providesVoltage: z.union([z.string(), z.number()]).optional(),
332
- requiresVoltage: z.union([z.string(), z.number()]).optional(),
333
- doNotConnect: z.boolean().optional(),
334
- includeInBoardPinout: z.boolean().optional(),
335
- highlightColor: z.string().optional(),
336
- mustBeConnected: z.boolean().optional(),
337
- canUseInternalPullup: z.boolean().optional(),
338
- isUsingInternalPullup: z.boolean().optional(),
339
- needsExternalPullup: z.boolean().optional(),
340
- canUseInternalPulldown: z.boolean().optional(),
341
- isUsingInternalPulldown: z.boolean().optional(),
342
- needsExternalPulldown: z.boolean().optional(),
343
- canUseOpenDrain: z.boolean().optional(),
344
- isUsingOpenDrain: z.boolean().optional(),
345
- canUsePushPull: z.boolean().optional(),
346
- isUsingPushPull: z.boolean().optional(),
347
- shouldHaveDecouplingCapacitor: z.boolean().optional(),
348
- recommendedDecouplingCapacitorCapacitance: z
349
- .union([z.string(), z.number()])
350
- .optional(),
351
- })
352
-
353
- expectTypesMatch<PinAttributeMap, z.input<typeof pinAttributeMap>>(true)
354
-
355
233
  export interface CommonComponentProps<PinLabel extends string = string>
356
234
  extends CommonLayoutProps {
357
235
  key?: any
@@ -0,0 +1,77 @@
1
+ import { z } from "zod"
2
+ import { expectTypesMatch } from "../typecheck"
3
+
4
+ export const pinCapability = z.enum([
5
+ "i2c_sda",
6
+ "i2c_scl",
7
+ "spi_cs",
8
+ "spi_sck",
9
+ "spi_mosi",
10
+ "spi_miso",
11
+ "uart_tx",
12
+ "uart_rx",
13
+ ])
14
+
15
+ export type PinCapability = z.input<typeof pinCapability>
16
+
17
+ export interface PinAttributeMap {
18
+ capabilities?: Array<PinCapability>
19
+ activeCapabilities?: Array<PinCapability>
20
+ activeCapability?: PinCapability
21
+ providesPower?: boolean
22
+ requiresPower?: boolean
23
+ providesGround?: boolean
24
+ requiresGround?: boolean
25
+ providesVoltage?: string | number
26
+ requiresVoltage?: string | number
27
+ doNotConnect?: boolean
28
+ includeInBoardPinout?: boolean
29
+ highlightColor?: string
30
+ mustBeConnected?: boolean
31
+ canUseInternalPullup?: boolean
32
+ isUsingInternalPullup?: boolean
33
+ needsExternalPullup?: boolean
34
+ canUseInternalPulldown?: boolean
35
+ isUsingInternalPulldown?: boolean
36
+ needsExternalPulldown?: boolean
37
+ canUseOpenDrain?: boolean
38
+ isUsingOpenDrain?: boolean
39
+ canUsePushPull?: boolean
40
+ isUsingPushPull?: boolean
41
+ shouldHaveDecouplingCapacitor?: boolean
42
+ recommendedDecouplingCapacitorCapacitance?: string | number
43
+ isGpio?: boolean
44
+ }
45
+
46
+ export const pinAttributeMap = z.object({
47
+ capabilities: z.array(pinCapability).optional(),
48
+ activeCapabilities: z.array(pinCapability).optional(),
49
+ activeCapability: pinCapability.optional(),
50
+ providesPower: z.boolean().optional(),
51
+ requiresPower: z.boolean().optional(),
52
+ providesGround: z.boolean().optional(),
53
+ requiresGround: z.boolean().optional(),
54
+ providesVoltage: z.union([z.string(), z.number()]).optional(),
55
+ requiresVoltage: z.union([z.string(), z.number()]).optional(),
56
+ doNotConnect: z.boolean().optional(),
57
+ includeInBoardPinout: z.boolean().optional(),
58
+ highlightColor: z.string().optional(),
59
+ mustBeConnected: z.boolean().optional(),
60
+ canUseInternalPullup: z.boolean().optional(),
61
+ isUsingInternalPullup: z.boolean().optional(),
62
+ needsExternalPullup: z.boolean().optional(),
63
+ canUseInternalPulldown: z.boolean().optional(),
64
+ isUsingInternalPulldown: z.boolean().optional(),
65
+ needsExternalPulldown: z.boolean().optional(),
66
+ canUseOpenDrain: z.boolean().optional(),
67
+ isUsingOpenDrain: z.boolean().optional(),
68
+ canUsePushPull: z.boolean().optional(),
69
+ isUsingPushPull: z.boolean().optional(),
70
+ shouldHaveDecouplingCapacitor: z.boolean().optional(),
71
+ recommendedDecouplingCapacitorCapacitance: z
72
+ .union([z.string(), z.number()])
73
+ .optional(),
74
+ isGpio: z.boolean().optional(),
75
+ })
76
+
77
+ expectTypesMatch<PinAttributeMap, z.input<typeof pinAttributeMap>>(true)
@@ -121,6 +121,51 @@ export type PlatedHoleProps =
121
121
  | PillWithRectPadPlatedHoleProps
122
122
  | HoleWithPolygonPadPlatedHoleProps
123
123
 
124
+ const DEFAULT_PIN_HEADER_HOLE_DIAMETER = "0.04in"
125
+ const DEFAULT_PIN_HEADER_OUTER_DIAMETER = "0.1in"
126
+
127
+ const inferPlatedHoleShapeAndDefaults = (rawProps: unknown): unknown => {
128
+ if (!rawProps || typeof rawProps !== "object") return rawProps
129
+
130
+ const props = { ...(rawProps as Record<string, unknown>) }
131
+
132
+ if (props.shape !== undefined) return props
133
+
134
+ if (props.padOutline !== undefined) {
135
+ props.shape = "hole_with_polygon_pad"
136
+ return props
137
+ }
138
+
139
+ if (props.rectPadWidth !== undefined || props.rectPadHeight !== undefined) {
140
+ if (props.holeDiameter !== undefined) {
141
+ props.shape = "circular_hole_with_rect_pad"
142
+ return props
143
+ }
144
+
145
+ props.shape = "pill_hole_with_rect_pad"
146
+ return props
147
+ }
148
+
149
+ if (
150
+ props.outerDiameter !== undefined ||
151
+ props.holeDiameter !== undefined ||
152
+ props.padDiameter !== undefined
153
+ ) {
154
+ props.shape = "circle"
155
+ return props
156
+ }
157
+
158
+ if (props.outerWidth !== undefined || props.outerHeight !== undefined) {
159
+ props.shape = props.rectPad === true ? "pill" : "oval"
160
+ return props
161
+ }
162
+
163
+ props.shape = "circle"
164
+ props.holeDiameter = DEFAULT_PIN_HEADER_HOLE_DIAMETER
165
+ props.outerDiameter = DEFAULT_PIN_HEADER_OUTER_DIAMETER
166
+ return props
167
+ }
168
+
124
169
  const distanceHiddenUndefined = z
125
170
  .custom<z.input<typeof distance>>()
126
171
  .transform((a) => {
@@ -128,7 +173,7 @@ const distanceHiddenUndefined = z
128
173
  return distance.parse(a)
129
174
  })
130
175
 
131
- export const platedHoleProps = z
176
+ const platedHolePropsByShape = z
132
177
  .discriminatedUnion("shape", [
133
178
  pcbLayoutProps.omit({ pcbRotation: true, layer: true }).extend({
134
179
  name: z.string().optional(),
@@ -220,7 +265,7 @@ export const platedHoleProps = z
220
265
  coveredWithSolderMask: z.boolean().optional(),
221
266
  }),
222
267
  ])
223
- .refine((a) => {
268
+ .transform((a) => {
224
269
  if ("innerWidth" in a && a.innerWidth !== undefined) {
225
270
  a.holeWidth ??= a.innerWidth
226
271
  }
@@ -230,6 +275,11 @@ export const platedHoleProps = z
230
275
  return a
231
276
  })
232
277
 
233
- type InferredPlatedHoleProps = z.input<typeof platedHoleProps>
278
+ export const platedHoleProps = z.preprocess(
279
+ inferPlatedHoleShapeAndDefaults,
280
+ platedHolePropsByShape,
281
+ )
282
+
283
+ type InferredPlatedHoleProps = z.input<typeof platedHolePropsByShape>
234
284
 
235
285
  expectTypesMatch<PlatedHoleProps, InferredPlatedHoleProps>(true)
package/lib/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from "./common/direction"
2
2
  export * from "./common/portHints"
3
3
  export * from "./common/layout"
4
+ export * from "./common/pinAttributeMap"
4
5
  export * from "./common/point3"
5
6
  export * from "./common/portHints"
6
7
  export * from "./common/footprintProp"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscircuit/props",
3
- "version": "0.0.490",
3
+ "version": "0.0.492",
4
4
  "description": "Props for tscircuit builtin component types",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",