@tscircuit/core 0.0.73 → 0.0.74

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.
Files changed (57) hide show
  1. package/package.json +2 -4
  2. package/index.ts +0 -1
  3. package/lib/Project.ts +0 -131
  4. package/lib/components/base-components/NormalComponent.ts +0 -419
  5. package/lib/components/base-components/PrimitiveComponent.ts +0 -478
  6. package/lib/components/base-components/Renderable.ts +0 -126
  7. package/lib/components/index.ts +0 -25
  8. package/lib/components/normal-components/Board.ts +0 -49
  9. package/lib/components/normal-components/Capacitor.ts +0 -70
  10. package/lib/components/normal-components/Chip.ts +0 -98
  11. package/lib/components/normal-components/Diode.ts +0 -27
  12. package/lib/components/normal-components/Jumper.ts +0 -101
  13. package/lib/components/normal-components/Led.ts +0 -27
  14. package/lib/components/normal-components/Resistor.ts +0 -59
  15. package/lib/components/primitive-components/Constraint.ts +0 -91
  16. package/lib/components/primitive-components/FabricationNotePath.ts +0 -50
  17. package/lib/components/primitive-components/FabricationNoteText.ts +0 -26
  18. package/lib/components/primitive-components/Footprint.ts +0 -239
  19. package/lib/components/primitive-components/Group.ts +0 -42
  20. package/lib/components/primitive-components/Hole.ts +0 -65
  21. package/lib/components/primitive-components/Keepout.ts +0 -58
  22. package/lib/components/primitive-components/Net.ts +0 -171
  23. package/lib/components/primitive-components/PlatedHole.ts +0 -116
  24. package/lib/components/primitive-components/Port.ts +0 -236
  25. package/lib/components/primitive-components/SilkscreenPath.ts +0 -48
  26. package/lib/components/primitive-components/SilkscreenText.ts +0 -25
  27. package/lib/components/primitive-components/SmtPad.ts +0 -162
  28. package/lib/components/primitive-components/Trace.ts +0 -635
  29. package/lib/components/primitive-components/TraceHint.ts +0 -71
  30. package/lib/fiber/catalogue.ts +0 -22
  31. package/lib/fiber/create-instance-from-react-element.ts +0 -179
  32. package/lib/fiber/intrinsic-jsx.ts +0 -48
  33. package/lib/index.ts +0 -5
  34. package/lib/register-catalogue.ts +0 -12
  35. package/lib/soup/underscorifyPinStyles.ts +0 -25
  36. package/lib/soup/underscorifyPortArrangement.ts +0 -51
  37. package/lib/utils/autorouting/SimpleRouteJson.ts +0 -48
  38. package/lib/utils/autorouting/computeObstacleBounds.ts +0 -10
  39. package/lib/utils/autorouting/findPossibleTraceLayerCombinations.ts +0 -102
  40. package/lib/utils/autorouting/mergeRoutes.ts +0 -71
  41. package/lib/utils/components/createNetsFromProps.ts +0 -15
  42. package/lib/utils/constants.ts +0 -35
  43. package/lib/utils/createComponentsFromSoup.ts +0 -79
  44. package/lib/utils/extend-aliases.ts +0 -12
  45. package/lib/utils/get-bounds-of-pcb-components.ts +0 -41
  46. package/lib/utils/get-relative-direction.ts +0 -14
  47. package/lib/utils/getClosest.ts +0 -35
  48. package/lib/utils/getPortFromHints.ts +0 -10
  49. package/lib/utils/pairs.ts +0 -10
  50. package/lib/utils/projectPointInDirection.ts +0 -18
  51. package/lib/utils/range.ts +0 -8
  52. package/lib/utils/schematic/getAllDimensionsForSchematicBox.ts +0 -330
  53. package/lib/utils/schematic/getSizeOfSidesFromPortArrangement.ts +0 -47
  54. package/lib/utils/selector-matching/index.ts +0 -2
  55. package/lib/utils/selector-matching/is-matching-path-selector.ts +0 -32
  56. package/lib/utils/selector-matching/is-matching-selector.ts +0 -64
  57. package/lib/utils/try-now.ts +0 -7
@@ -1,79 +0,0 @@
1
- import type { AnySoupElement } from "@tscircuit/soup"
2
- import type { PrimitiveComponent } from "../components/base-components/PrimitiveComponent"
3
- import { SmtPad } from "lib/components/primitive-components/SmtPad"
4
- import { SilkscreenPath } from "lib/components/primitive-components/SilkscreenPath"
5
- import { PlatedHole } from "lib/components/primitive-components/PlatedHole"
6
- import { Keepout } from "lib/components/primitive-components/Keepout"
7
-
8
- export const createComponentsFromSoup = (
9
- soup: AnySoupElement[],
10
- ): PrimitiveComponent[] => {
11
- const components: PrimitiveComponent[] = []
12
- for (const elm of soup) {
13
- if (elm.type === "pcb_smtpad" && elm.shape === "rect") {
14
- components.push(
15
- new SmtPad({
16
- pcbX: elm.x,
17
- pcbY: elm.y,
18
- layer: elm.layer,
19
- shape: "rect",
20
- height: elm.height,
21
- width: elm.width,
22
- portHints: elm.port_hints,
23
- }),
24
- )
25
- } else if (elm.type === "pcb_smtpad" && elm.shape === "circle") {
26
- components.push(
27
- new SmtPad({
28
- pcbX: elm.x,
29
- pcbY: elm.y,
30
- layer: elm.layer,
31
- shape: "circle",
32
- radius: elm.radius,
33
- portHints: elm.port_hints,
34
- }),
35
- )
36
- } else if (elm.type === "pcb_silkscreen_path") {
37
- components.push(
38
- new SilkscreenPath({
39
- layer: elm.layer,
40
- route: elm.route,
41
- strokeWidth: elm.stroke_width,
42
- }),
43
- )
44
- } else if (elm.type === "pcb_plated_hole" && elm.shape === "circle") {
45
- if (elm.shape === "circle") {
46
- components.push(
47
- new PlatedHole({
48
- pcbX: elm.x,
49
- pcbY: elm.y,
50
- shape: "circle",
51
- holeDiameter: elm.hole_diameter,
52
- outerDiameter: elm.outer_diameter,
53
- portHints: elm.port_hints,
54
- }),
55
- )
56
- }
57
- } else if (elm.type === "pcb_keepout" && elm.shape === "circle") {
58
- components.push(
59
- new Keepout({
60
- pcbX: elm.center.x,
61
- pcbY: elm.center.y,
62
- shape: "circle",
63
- radius: elm.radius,
64
- }),
65
- )
66
- } else if (elm.type === "pcb_keepout" && elm.shape === "rect") {
67
- components.push(
68
- new Keepout({
69
- pcbX: elm.center.x,
70
- pcbY: elm.center.y,
71
- shape: "rect",
72
- width: elm.width,
73
- height: elm.height,
74
- }),
75
- )
76
- }
77
- }
78
- return components
79
- }
@@ -1,12 +0,0 @@
1
- export const extendAliases = (
2
- aliases: string[],
3
- additionalAliases: Record<string, string[]>,
4
- ): string[] => {
5
- return Array.from(
6
- new Set(
7
- aliases.flatMap((alias) => {
8
- return [alias, ...(additionalAliases[alias] || [])]
9
- }),
10
- ),
11
- )
12
- }
@@ -1,41 +0,0 @@
1
- import type { PrimitiveComponent } from "lib/components/base-components/PrimitiveComponent"
2
-
3
- export function getBoundsOfPcbComponents(components: PrimitiveComponent[]) {
4
- let minX = Infinity
5
- let minY = Infinity
6
- let maxX = -Infinity
7
- let maxY = -Infinity
8
-
9
- for (const child of components) {
10
- if (child.isPcbPrimitive) {
11
- const { x, y } = child._getGlobalPcbPositionBeforeLayout()
12
- const { width, height } = child.getPcbSize()
13
- minX = Math.min(minX, x - width / 2)
14
- minY = Math.min(minY, y - height / 2)
15
- maxX = Math.max(maxX, x + width / 2)
16
- maxY = Math.max(maxY, y + height / 2)
17
- } else if (child.componentName === "Footprint") {
18
- const childBounds = getBoundsOfPcbComponents(child.children)
19
-
20
- minX = Math.min(minX, childBounds.minX)
21
- minY = Math.min(minY, childBounds.minY)
22
- maxX = Math.max(maxX, childBounds.maxX)
23
- maxY = Math.max(maxY, childBounds.maxY)
24
- }
25
- }
26
-
27
- let width = maxX - minX
28
- let height = maxY - minY
29
-
30
- if (width < 0) width = 0
31
- if (height < 0) height = 0
32
-
33
- return {
34
- minX,
35
- minY,
36
- maxX,
37
- maxY,
38
- width,
39
- height,
40
- }
41
- }
@@ -1,14 +0,0 @@
1
- // Return "up", "down", "left", or "right" based on the angle between two points
2
- // A & B. The direction is relative to A. So if B is to the right of A, the
3
- // direction is "right". The largest distance wins
4
- export function getRelativeDirection(
5
- pointA: { x: number; y: number },
6
- pointB: { x: number; y: number },
7
- ): "up" | "down" | "left" | "right" {
8
- const dx = pointB.x - pointA.x
9
- const dy = pointB.y - pointA.y
10
- if (Math.abs(dx) > Math.abs(dy)) {
11
- return dx > 0 ? "right" : "left"
12
- }
13
- return dy > 0 ? "down" : "up"
14
- }
@@ -1,35 +0,0 @@
1
- export type PointLike =
2
- | { _getGlobalPcbPositionBeforeLayout: () => { x: number; y: number } }
3
- | { x: number; y: number }
4
-
5
- const getDistance = (a: PointLike, b: PointLike) => {
6
- const aPos =
7
- "_getGlobalPcbPositionBeforeLayout" in a
8
- ? a._getGlobalPcbPositionBeforeLayout()
9
- : a
10
- const bPos =
11
- "_getGlobalPcbPositionBeforeLayout" in b
12
- ? b._getGlobalPcbPositionBeforeLayout()
13
- : b
14
- return Math.sqrt((aPos.x - bPos.x) ** 2 + (aPos.y - bPos.y) ** 2)
15
- }
16
-
17
- export function getClosest<T extends PointLike, U extends PointLike>(
18
- point: T,
19
- candidates: U[],
20
- ): U {
21
- if (candidates.length === 0)
22
- throw new Error("No candidates given to getClosest method")
23
- let closest: U = candidates[0]
24
- let closestDist = Infinity
25
-
26
- for (const candidate of candidates) {
27
- const dist = getDistance(point, candidate)
28
- if (dist < closestDist) {
29
- closest = candidate
30
- closestDist = dist
31
- }
32
- }
33
-
34
- return closest
35
- }
@@ -1,10 +0,0 @@
1
- import { Port } from "lib/components/primitive-components/Port"
2
-
3
- export function getPortFromHints(hints: string[]): Port | null {
4
- const pinNumber = hints.find((p) => /^(pin)?\d+$/.test(p))
5
- if (!pinNumber) return null
6
- return new Port({
7
- pinNumber: Number.parseInt(pinNumber.replace(/^pin/, "")),
8
- aliases: hints.filter((p) => p !== pinNumber),
9
- })
10
- }
@@ -1,10 +0,0 @@
1
- /**
2
- * Return pairs of adjacent elements in an array.
3
- */
4
- export function pairs<T>(arr: Array<T>): Array<[T, T]> {
5
- const result: Array<[T, T]> = []
6
- for (let i = 0; i < arr.length - 1; i++) {
7
- result.push([arr[i], arr[i + 1]])
8
- }
9
- return result
10
- }
@@ -1,18 +0,0 @@
1
- export const projectPointInDirection = (
2
- point: { x: number; y: number },
3
- direction: "up" | "down" | "left" | "right",
4
- distance: number,
5
- ) => {
6
- switch (direction) {
7
- case "up":
8
- return { x: point.x, y: point.y - distance }
9
- case "down":
10
- return { x: point.x, y: point.y + distance }
11
- case "left":
12
- return { x: point.x - distance, y: point.y }
13
- case "right":
14
- return { x: point.x + distance, y: point.y }
15
- default:
16
- throw new Error(`Unknown direction "${direction}"`)
17
- }
18
- }
@@ -1,8 +0,0 @@
1
- // same signature as lodash.range
2
- export const range = (start: number, end: number, step = 1) => {
3
- const result: number[] = []
4
- for (let i = start; i < end; i += step) {
5
- result.push(i)
6
- }
7
- return result
8
- }
@@ -1,330 +0,0 @@
1
- import { current } from "@tscircuit/soup"
2
- import { getSizeOfSidesFromPortArrangement } from "./getSizeOfSidesFromPortArrangement"
3
- import { schematicPortArrangement } from "@tscircuit/props"
4
- import { z } from "zod"
5
-
6
- export type VerticalPortSideConfiguration = {
7
- direction?: "top-to-bottom" | "bottom-to-top"
8
- pins: number[]
9
- }
10
- export type HorizontalPortSideConfiguration = {
11
- direction?: "left-to-right" | "right-to-left"
12
- pins: number[]
13
- }
14
-
15
- export type ExplicitPinMappingArrangement = {
16
- leftSide?: VerticalPortSideConfiguration
17
- rightSide?: VerticalPortSideConfiguration
18
- topSide?: HorizontalPortSideConfiguration
19
- bottomSide?: HorizontalPortSideConfiguration
20
- }
21
- /** @deprecated prefer SidePinCounts */
22
- export interface SideSizes {
23
- leftSize?: number
24
- rightSize?: number
25
- topSize?: number
26
- bottomSize?: number
27
- }
28
-
29
- export interface SidePinCounts {
30
- leftPinCount?: number
31
- rightPinCount?: number
32
- topPinCount?: number
33
- bottomPinCount?: number
34
- }
35
-
36
- export type PortArrangement =
37
- | SideSizes
38
- | SidePinCounts
39
- | ExplicitPinMappingArrangement
40
-
41
- interface Params {
42
- schWidth?: number
43
- schHeight?: number
44
- portDistanceFromEdge?: number
45
- schPinSpacing: number
46
- schPinStyle?: Record<
47
- `pin${number}` | number | `${number}`,
48
- {
49
- leftMargin?: number
50
- rightMargin?: number
51
- topMargin?: number
52
- bottomMargin?: number
53
- }
54
- >
55
- pinCount?: number
56
- schPortArrangement?: PortArrangement
57
- }
58
-
59
- type Side = "left" | "right" | "top" | "bottom"
60
-
61
- export interface SchematicBoxDimensions {
62
- pinCount: number
63
- getPortPositionByPinNumber(pinNumber: number): { x: number; y: number }
64
- getSize(): { width: number; height: number }
65
- }
66
-
67
- /**
68
- * Get the dimensions of a schematic box based on the provided parameters.
69
- *
70
- * A schematic box is a rectangular box with a set of pins on the sides.
71
- *
72
- * The user can customize the position of the pins and the spacing between them,
73
- * this makes computing the box fairly complicated.
74
- *
75
- * A note on the internals:
76
- * * A "true port" refers to a pin/port before it's remapped by the user to a
77
- * different position. True Pin 1 is guaranteed to be in the top-left corner
78
- * * We basically iterate over each side and compute how far we are from the
79
- * edge for that side by adding margins together
80
- */
81
- export const getAllDimensionsForSchematicBox = (
82
- params: Params,
83
- ): SchematicBoxDimensions => {
84
- const portDistanceFromEdge =
85
- params.portDistanceFromEdge ?? params.schPinSpacing * 2
86
-
87
- let sidePinCounts = params.schPortArrangement
88
- ? getSizeOfSidesFromPortArrangement(params.schPortArrangement)
89
- : null
90
-
91
- const sideLengths: Record<Side, number> = {
92
- left: 0,
93
- right: 0,
94
- top: 0,
95
- bottom: 0,
96
- }
97
-
98
- let pinCount: number | null = params.pinCount ?? null
99
-
100
- if (pinCount === null) {
101
- if (sidePinCounts) {
102
- pinCount =
103
- sidePinCounts.leftSize + sidePinCounts.rightSize + sidePinCounts.topSize
104
- } else {
105
- throw new Error("Could not determine pin count for the schematic box")
106
- }
107
- }
108
-
109
- if (pinCount && !sidePinCounts) {
110
- const rightSize = Math.floor(pinCount / 2)
111
- sidePinCounts = {
112
- leftSize: pinCount - rightSize,
113
- rightSize: rightSize,
114
- topSize: 0,
115
- bottomSize: 0,
116
- }
117
- }
118
-
119
- if (!sidePinCounts) {
120
- throw new Error("Could not determine side sizes for the schematic box")
121
- }
122
-
123
- // Map the indices to the sides they correspond to
124
- const orderedTruePorts: Array<{
125
- trueIndex: number
126
- pinNumber: number
127
- side: "left" | "right" | "top" | "bottom"
128
- distanceFromEdge: number
129
- }> = []
130
- let currentDistanceFromEdge = 0
131
- let truePinIndex = 0
132
- // moving downward from the top-left corner
133
- for (let sideIndex = 0; sideIndex < sidePinCounts.leftSize; sideIndex++) {
134
- const pinNumber = truePinIndex + 1 // TODO check mapping from schPortArrangement
135
- const pinStyle =
136
- params.schPinStyle?.[`pin${pinNumber}`] ?? params.schPinStyle?.[pinNumber]
137
-
138
- if (pinStyle?.topMargin) {
139
- currentDistanceFromEdge += pinStyle.topMargin
140
- }
141
-
142
- orderedTruePorts.push({
143
- trueIndex: truePinIndex,
144
- pinNumber,
145
- side: "left",
146
- distanceFromEdge: currentDistanceFromEdge,
147
- })
148
-
149
- if (pinStyle?.bottomMargin) {
150
- currentDistanceFromEdge += pinStyle.bottomMargin
151
- }
152
-
153
- const isLastPinOnSide = sideIndex === sidePinCounts.leftSize - 1
154
- if (!isLastPinOnSide) {
155
- currentDistanceFromEdge += params.schPinSpacing
156
- } else {
157
- sideLengths.left = currentDistanceFromEdge
158
- }
159
- truePinIndex++
160
- }
161
-
162
- currentDistanceFromEdge = 0
163
- // moving rightward from the left-bottom corner
164
- for (let sideIndex = 0; sideIndex < sidePinCounts.bottomSize; sideIndex++) {
165
- const pinNumber = truePinIndex + 1 // TODO check mapping from schPortArrangement
166
- const pinStyle =
167
- params.schPinStyle?.[`pin${pinNumber}`] ?? params.schPinStyle?.[pinNumber]
168
-
169
- if (pinStyle?.leftMargin) {
170
- currentDistanceFromEdge += pinStyle.leftMargin
171
- }
172
-
173
- orderedTruePorts.push({
174
- trueIndex: truePinIndex,
175
- pinNumber,
176
- side: "bottom",
177
- distanceFromEdge: currentDistanceFromEdge,
178
- })
179
-
180
- if (pinStyle?.rightMargin) {
181
- currentDistanceFromEdge += pinStyle.rightMargin
182
- }
183
-
184
- const isLastPinOnSide = sideIndex === sidePinCounts.bottomSize - 1
185
- if (!isLastPinOnSide) {
186
- currentDistanceFromEdge += params.schPinSpacing
187
- } else {
188
- sideLengths.bottom = currentDistanceFromEdge
189
- }
190
- truePinIndex++
191
- }
192
-
193
- currentDistanceFromEdge = 0
194
- // moving upward from the bottom-right corner
195
- for (let sideIndex = 0; sideIndex < sidePinCounts.rightSize; sideIndex++) {
196
- const pinNumber = truePinIndex + 1 // TODO check mapping from schPortArrangement
197
- const pinStyle =
198
- params.schPinStyle?.[`pin${pinNumber}`] ?? params.schPinStyle?.[pinNumber]
199
-
200
- if (pinStyle?.bottomMargin) {
201
- currentDistanceFromEdge += pinStyle.bottomMargin
202
- }
203
-
204
- orderedTruePorts.push({
205
- trueIndex: truePinIndex,
206
- pinNumber,
207
- side: "right",
208
- distanceFromEdge: currentDistanceFromEdge,
209
- })
210
-
211
- if (pinStyle?.topMargin) {
212
- currentDistanceFromEdge += pinStyle.topMargin
213
- }
214
-
215
- const isLastPinOnSide = sideIndex === sidePinCounts.rightSize - 1
216
- if (!isLastPinOnSide) {
217
- currentDistanceFromEdge += params.schPinSpacing
218
- } else {
219
- sideLengths.right = currentDistanceFromEdge
220
- }
221
- truePinIndex++
222
- }
223
-
224
- currentDistanceFromEdge = 0
225
- // moving leftward from the top-right corner
226
- for (let sideIndex = 0; sideIndex < sidePinCounts.topSize; sideIndex++) {
227
- const pinNumber = truePinIndex + 1 // TODO check mapping from schPortArrangement
228
- const pinStyle =
229
- params.schPinStyle?.[`pin${pinNumber}`] ?? params.schPinStyle?.[pinNumber]
230
-
231
- if (pinStyle?.rightMargin) {
232
- currentDistanceFromEdge += pinStyle.rightMargin
233
- }
234
-
235
- orderedTruePorts.push({
236
- trueIndex: truePinIndex,
237
- pinNumber,
238
- side: "top",
239
- distanceFromEdge: currentDistanceFromEdge,
240
- })
241
-
242
- if (pinStyle?.leftMargin) {
243
- currentDistanceFromEdge += pinStyle.leftMargin
244
- }
245
-
246
- const isLastPinOnSide = sideIndex === sidePinCounts.topSize - 1
247
- if (!isLastPinOnSide) {
248
- currentDistanceFromEdge += params.schPinSpacing
249
- } else {
250
- sideLengths.top = currentDistanceFromEdge
251
- }
252
- truePinIndex++
253
- }
254
-
255
- // Use lengths to determine schWidth and schHeight
256
- let schWidth = params.schWidth
257
- if (!schWidth) {
258
- schWidth = Math.max(
259
- sideLengths.top + params.schPinSpacing * 2,
260
- sideLengths.bottom + params.schPinSpacing * 2,
261
- )
262
- }
263
- let schHeight = params.schHeight
264
- if (!schHeight) {
265
- schHeight = Math.max(
266
- sideLengths.left + params.schPinSpacing * 2,
267
- sideLengths.right + params.schPinSpacing * 2,
268
- )
269
- }
270
-
271
- const trueEdgePositions = {
272
- // Top left corner
273
- left: {
274
- x: -schWidth / 2 - portDistanceFromEdge,
275
- y: sideLengths.left / 2,
276
- },
277
- // bottom left corner
278
- bottom: {
279
- x: -sideLengths.bottom / 2,
280
- y: -schHeight / 2 - portDistanceFromEdge,
281
- },
282
- // bottom right corner
283
- right: {
284
- x: schWidth / 2 + portDistanceFromEdge,
285
- y: -sideLengths.right / 2,
286
- },
287
- // top right corner
288
- top: {
289
- x: sideLengths.top / 2,
290
- y: schHeight / 2 + portDistanceFromEdge,
291
- },
292
- }
293
-
294
- const trueEdgeTraversalDirections = {
295
- left: { x: 0, y: -1 },
296
- right: { x: 0, y: 1 },
297
- top: { x: -1, y: 0 },
298
- bottom: { x: 1, y: 0 },
299
- }
300
-
301
- const truePortsWithPositions = orderedTruePorts.map((p) => {
302
- const { distanceFromEdge, side } = p
303
- const edgePos = trueEdgePositions[side]
304
- const edgeDir = trueEdgeTraversalDirections[side]
305
-
306
- return {
307
- x: edgePos.x + distanceFromEdge * edgeDir.x,
308
- y: edgePos.y + distanceFromEdge * edgeDir.y,
309
- ...p,
310
- }
311
- })
312
-
313
- return {
314
- getPortPositionByPinNumber(pinNumber: number): { x: number; y: number } {
315
- const port = truePortsWithPositions.find(
316
- (p) => p.pinNumber.toString() === pinNumber.toString(),
317
- )
318
- if (!port) {
319
- throw new Error(
320
- `Could not find port for pin number ${pinNumber}, available pins: ${truePortsWithPositions.map((tp) => tp.pinNumber).join(", ")}`,
321
- )
322
- }
323
- return port
324
- },
325
- getSize(): { width: number; height: number } {
326
- return { width: schWidth, height: schHeight }
327
- },
328
- pinCount,
329
- }
330
- }
@@ -1,47 +0,0 @@
1
- import type {
2
- ExplicitPinMappingArrangement,
3
- PortArrangement,
4
- } from "./getAllDimensionsForSchematicBox"
5
-
6
- export const hasExplicitPinMapping = (
7
- pa: PortArrangement,
8
- ): pa is ExplicitPinMappingArrangement => {
9
- for (const side of [
10
- "leftSide",
11
- "rightSide",
12
- "topSide",
13
- "bottomSide",
14
- ] as const) {
15
- if (side in pa && typeof (pa as any)[side] === "number") {
16
- throw new Error(
17
- `A number was specified for "${side}", you probably meant to use "size" not "side"`,
18
- )
19
- }
20
- }
21
- return (
22
- "leftSide" in pa ||
23
- "rightSide" in pa ||
24
- "topSide" in pa ||
25
- "bottomSide" in pa
26
- )
27
- }
28
-
29
- export const getSizeOfSidesFromPortArrangement = (
30
- pa: PortArrangement,
31
- ): {
32
- leftSize: number
33
- rightSize: number
34
- topSize: number
35
- bottomSize: number
36
- } => {
37
- if (hasExplicitPinMapping(pa)) {
38
- return {
39
- leftSize: pa.leftSide?.pins.length ?? 0,
40
- rightSize: pa.rightSide?.pins.length ?? 0,
41
- topSize: pa.topSide?.pins.length ?? 0,
42
- bottomSize: pa.bottomSide?.pins.length ?? 0,
43
- }
44
- }
45
- const { leftSize = 0, rightSize = 0, topSize = 0, bottomSize = 0 } = pa as any
46
- return { leftSize, rightSize, topSize, bottomSize }
47
- }
@@ -1,2 +0,0 @@
1
- export * from "./is-matching-selector"
2
- export * from "./is-matching-path-selector"
@@ -1,32 +0,0 @@
1
- import type { PrimitiveComponent } from "lib/components"
2
- import type { Primitive } from "schematic-symbols/drawing/types"
3
-
4
- import { isMatchingSelector } from "./is-matching-selector"
5
-
6
- /**
7
- * Determines if a component matches a path selector, meaning that the last
8
- * selector matches the current component, and the previous selectors match
9
- * the parent components.
10
- */
11
- export function isMatchingPathSelector(
12
- component: PrimitiveComponent,
13
- selector: string,
14
- ): boolean {
15
- const selectorParts = selector.split(/\> /g).map((part) => part.trim())
16
- let currentComponent: PrimitiveComponent | null = component
17
-
18
- // Iterate through selector parts from right to left
19
- for (let i = selectorParts.length - 1; i >= 0; i--) {
20
- if (!currentComponent) return false
21
-
22
- if (!isMatchingSelector(currentComponent, selectorParts[i])) {
23
- return false
24
- }
25
-
26
- // Move to the parent component for the next iteration
27
- currentComponent = currentComponent.parent
28
- }
29
-
30
- // If we've matched all parts of the selector, it's a match
31
- return true
32
- }