@tscircuit/footprinter 0.0.6 → 0.0.8
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/package.json +1 -1
- package/src/fn/bga.ts +55 -1
- package/src/footprinter.ts +10 -5
- package/src/helpers/is-not-null.ts +3 -0
- package/tsconfig.json +1 -0
- package/src/helpers/zod/bga-def.ts +0 -56
package/package.json
CHANGED
package/src/fn/bga.ts
CHANGED
|
@@ -1,7 +1,61 @@
|
|
|
1
1
|
import type { AnySoupElement, PCBSMTPad } from "@tscircuit/soup"
|
|
2
2
|
import { rectpad } from "../helpers/rectpad"
|
|
3
|
-
import { type BgaDefInput, bga_def } from "../helpers/zod/bga-def"
|
|
4
3
|
import { ALPHABET } from "../helpers/zod/ALPHABET"
|
|
4
|
+
import { z } from "zod"
|
|
5
|
+
import { length, distance } from "@tscircuit/soup"
|
|
6
|
+
import { dim2d } from "src/helpers/zod/dim-2d"
|
|
7
|
+
import { function_call } from "src/helpers/zod/function-call"
|
|
8
|
+
import type { NowDefined } from "src/helpers/zod/now-defined"
|
|
9
|
+
|
|
10
|
+
export const bga_def = z
|
|
11
|
+
.object({
|
|
12
|
+
num_pins: z.number(),
|
|
13
|
+
grid: dim2d.optional(),
|
|
14
|
+
p: distance.default("0.8mm"),
|
|
15
|
+
w: length.optional(),
|
|
16
|
+
h: length.optional(),
|
|
17
|
+
ball: length.optional().describe("ball diameter"),
|
|
18
|
+
pad: length.optional().describe("pad width/height"),
|
|
19
|
+
|
|
20
|
+
tlorigin: z.boolean().optional(),
|
|
21
|
+
blorigin: z.boolean().optional(),
|
|
22
|
+
trorigin: z.boolean().optional(),
|
|
23
|
+
brorigin: z.boolean().optional(),
|
|
24
|
+
|
|
25
|
+
missing: function_call.default([]),
|
|
26
|
+
})
|
|
27
|
+
.transform((a) => {
|
|
28
|
+
let origin: "tl" | "bl" | "tr" | "br" = "tl"
|
|
29
|
+
if (a.blorigin) origin = "bl"
|
|
30
|
+
if (a.trorigin) origin = "tr"
|
|
31
|
+
if (a.brorigin) origin = "br"
|
|
32
|
+
|
|
33
|
+
if (!a.grid) {
|
|
34
|
+
// find the largest square for the number of pins
|
|
35
|
+
const largest_square = Math.ceil(Math.sqrt(a.num_pins))
|
|
36
|
+
a.grid = { x: largest_square, y: largest_square }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (a.missing) {
|
|
40
|
+
a.missing = a.missing.map((s) => {
|
|
41
|
+
if (typeof s === "number") return s
|
|
42
|
+
if (s === "center") return "center"
|
|
43
|
+
if (s === "topleft") return "topleft"
|
|
44
|
+
const m = s.match(/([A-Z]+)(\d+)/)
|
|
45
|
+
if (!m) return s
|
|
46
|
+
let Y = ALPHABET.indexOf(m[1]!)
|
|
47
|
+
let X = parseInt(m[2]!) - 1
|
|
48
|
+
return Y * a.grid!.x + X + 1
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const new_def = { ...a, origin }
|
|
53
|
+
|
|
54
|
+
return new_def as NowDefined<typeof new_def, "w" | "h" | "grid">
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
export type BgaDefInput = z.input<typeof bga_def>
|
|
58
|
+
export type BgaDef = z.infer<typeof bga_def>
|
|
5
59
|
|
|
6
60
|
export const bga = (params: BgaDefInput): AnySoupElement[] => {
|
|
7
61
|
const bga_params = bga_def.parse(params)
|
package/src/footprinter.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { led } from "./fn/led"
|
|
|
5
5
|
import { res } from "./fn/res"
|
|
6
6
|
import { bga } from "./fn/bga"
|
|
7
7
|
import type { AnySoupElement } from "@tscircuit/soup"
|
|
8
|
+
import { isNotNull } from "./helpers/is-not-null"
|
|
8
9
|
|
|
9
10
|
export type FootprinterParamsBuilder<K extends string> = {
|
|
10
11
|
[P in K | "params" | "soup"]: P extends "params" | "soup"
|
|
@@ -48,11 +49,15 @@ export type Footprinter = {
|
|
|
48
49
|
export const string = (def: string): Footprinter => {
|
|
49
50
|
let fp = footprinter()
|
|
50
51
|
|
|
51
|
-
const def_parts = def
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
const def_parts = def
|
|
53
|
+
.split("_")
|
|
54
|
+
.map((s) => {
|
|
55
|
+
const m = s.match(/([a-z]+)([\(\d\.\+\?].*)?/)
|
|
56
|
+
const [_, fn, v] = m ?? []
|
|
57
|
+
if (v?.includes("?")) return null
|
|
58
|
+
return { fn: m?.[1]!, v: m?.[2]! }
|
|
59
|
+
})
|
|
60
|
+
.filter(isNotNull)
|
|
56
61
|
|
|
57
62
|
for (const { fn, v } of def_parts) {
|
|
58
63
|
fp = fp[fn](v)
|
package/tsconfig.json
CHANGED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { z } from "zod"
|
|
2
|
-
import { length, distance } from "@tscircuit/soup"
|
|
3
|
-
import { dim2d } from "./dim-2d"
|
|
4
|
-
import { function_call } from "./function-call"
|
|
5
|
-
import type { NowDefined } from "./now-defined"
|
|
6
|
-
import { ALPHABET } from "./ALPHABET"
|
|
7
|
-
|
|
8
|
-
export const bga_def = z
|
|
9
|
-
.object({
|
|
10
|
-
num_pins: z.number(),
|
|
11
|
-
grid: dim2d.optional(),
|
|
12
|
-
p: distance.default("0.8mm"),
|
|
13
|
-
w: length.optional(),
|
|
14
|
-
h: length.optional(),
|
|
15
|
-
ball: length.optional().describe("ball diameter"),
|
|
16
|
-
pad: length.optional().describe("pad width/height"),
|
|
17
|
-
|
|
18
|
-
tlorigin: z.boolean().optional(),
|
|
19
|
-
blorigin: z.boolean().optional(),
|
|
20
|
-
trorigin: z.boolean().optional(),
|
|
21
|
-
brorigin: z.boolean().optional(),
|
|
22
|
-
|
|
23
|
-
missing: function_call.default([]),
|
|
24
|
-
})
|
|
25
|
-
.transform((a) => {
|
|
26
|
-
let origin: "tl" | "bl" | "tr" | "br" = "tl"
|
|
27
|
-
if (a.blorigin) origin = "bl"
|
|
28
|
-
if (a.trorigin) origin = "tr"
|
|
29
|
-
if (a.brorigin) origin = "br"
|
|
30
|
-
|
|
31
|
-
if (!a.grid) {
|
|
32
|
-
// find the largest square for the number of pins
|
|
33
|
-
const largest_square = Math.ceil(Math.sqrt(a.num_pins))
|
|
34
|
-
a.grid = { x: largest_square, y: largest_square }
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (a.missing) {
|
|
38
|
-
a.missing = a.missing.map((s) => {
|
|
39
|
-
if (typeof s === "number") return s
|
|
40
|
-
if (s === "center") return "center"
|
|
41
|
-
if (s === "topleft") return "topleft"
|
|
42
|
-
const m = s.match(/([A-Z]+)(\d+)/)
|
|
43
|
-
if (!m) return s
|
|
44
|
-
let Y = ALPHABET.indexOf(m[1]!)
|
|
45
|
-
let X = parseInt(m[2]!) - 1
|
|
46
|
-
return Y * a.grid!.x + X + 1
|
|
47
|
-
})
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const new_def = { ...a, origin }
|
|
51
|
-
|
|
52
|
-
return new_def as NowDefined<typeof new_def, "w" | "h" | "grid">
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
export type BgaDefInput = z.input<typeof bga_def>
|
|
56
|
-
export type BgaDef = z.infer<typeof bga_def>
|