@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,236 +0,0 @@
1
- import type { PCBSMTPad } from "@tscircuit/soup"
2
- import { PrimitiveComponent } from "../base-components/PrimitiveComponent"
3
- import { z } from "zod"
4
- import { getRelativeDirection } from "lib/utils/get-relative-direction"
5
- import { symbols, type SchSymbol } from "schematic-symbols"
6
- import { applyToPoint, compose, translate } from "transformation-matrix"
7
- import type { Trace } from "./Trace"
8
-
9
- export const portProps = z.object({
10
- name: z.string().optional(),
11
- pinNumber: z.number().optional(),
12
- aliases: z.array(z.string()).optional(),
13
- })
14
-
15
- export type PortProps = z.infer<typeof portProps>
16
-
17
- export class Port extends PrimitiveComponent<typeof portProps> {
18
- source_port_id: string | null = null
19
- pcb_port_id: string | null = null
20
- schematic_port_id: string | null = null
21
-
22
- schematicSymbolPortDef: SchSymbol["ports"][number] | null = null
23
- matchedComponents: PrimitiveComponent[]
24
- facingDirection: "up" | "down" | "left" | "right" | null = null
25
-
26
- constructor(props: z.input<typeof portProps>) {
27
- if (!props.name && props.pinNumber) props.name = `pin${props.pinNumber}`
28
- if (!props.name) {
29
- throw new Error("Port must have a name or a pinNumber")
30
- }
31
- super(props)
32
- this.matchedComponents = []
33
- }
34
-
35
- _getGlobalPcbPositionBeforeLayout(): { x: number; y: number } {
36
- const matchedPcbElm = this.matchedComponents.find((c) => c.isPcbPrimitive)
37
-
38
- if (!matchedPcbElm) {
39
- throw new Error(
40
- `Port ${this} has no matched pcb component, can't get global schematic position`,
41
- )
42
- }
43
-
44
- return matchedPcbElm?._getGlobalPcbPositionBeforeLayout() ?? { x: 0, y: 0 }
45
- }
46
-
47
- _getPcbCircuitJsonBounds() {
48
- if (!this.pcb_port_id) {
49
- return super._getPcbCircuitJsonBounds()
50
- }
51
- const { db } = this.root!
52
- const pcb_port = db.pcb_port.get(this.pcb_port_id)!
53
- return {
54
- center: { x: pcb_port.x, y: pcb_port.y },
55
- bounds: { left: 0, top: 0, right: 0, bottom: 0 },
56
- width: 0,
57
- height: 0,
58
- }
59
- }
60
-
61
- _getGlobalPcbPositionAfterLayout(): { x: number; y: number } {
62
- return this._getPcbCircuitJsonBounds().center
63
- }
64
-
65
- _getGlobalSchematicPositionBeforeLayout(): { x: number; y: number } {
66
- if (!this.schematicSymbolPortDef) {
67
- return applyToPoint(this.parent!.computeSchematicGlobalTransform(), {
68
- x: 0,
69
- y: 0,
70
- })
71
- throw new Error(
72
- `Could not find schematic symbol port for port ${this} so couldn't determine port position`,
73
- )
74
- }
75
-
76
- const symbol = this.parent?.getSchematicSymbol()
77
- if (!symbol) throw new Error(`Could not find parent symbol for ${this}`)
78
-
79
- const transform = compose(
80
- this.parent!.computeSchematicGlobalTransform(),
81
- translate(-symbol.center.x, -symbol.center.y),
82
- )
83
-
84
- return applyToPoint(transform, this.schematicSymbolPortDef)
85
- }
86
-
87
- /**
88
- * Smtpads and platedholes call this method to register themselves as a match
89
- * for this port. All the matching is done by primitives other than the Port,
90
- * but everyone registers themselves as a match with their Port.
91
- */
92
- registerMatch(component: PrimitiveComponent) {
93
- this.matchedComponents.push(component)
94
- }
95
- getNameAndAliases() {
96
- const { _parsedProps: props } = this
97
- return Array.from(
98
- new Set([
99
- ...(props.aliases ?? []),
100
- props.name,
101
- ...(typeof props.pinNumber === "number"
102
- ? [`pin${props.pinNumber}`, props.pinNumber.toString()]
103
- : []),
104
- ...this.externallyAddedAliases,
105
- ]),
106
- ) as string[]
107
- }
108
- isMatchingPort(port: Port) {
109
- return this.isMatchingAnyOf(port.getNameAndAliases())
110
- }
111
- getPortSelector() {
112
- // TODO this.parent.getSubcircuitSelector() >
113
- return `.${this.parent?.props.name} > port.${this.props.name}`
114
- }
115
- getAvailablePcbLayers(): string[] {
116
- return Array.from(
117
- new Set(this.matchedComponents.flatMap((c) => c.getAvailablePcbLayers())),
118
- )
119
- }
120
-
121
- /**
122
- * Return traces that are explicitly connected to this port (not via a net)
123
- */
124
- _getDirectlyConnectedTraces(): Trace[] {
125
- const allSubcircuitTraces = this.getSubcircuit().selectAll(
126
- "trace",
127
- ) as Trace[]
128
-
129
- const connectedTraces = allSubcircuitTraces.filter((trace) =>
130
- trace._isExplicitlyConnectedToPort(this),
131
- )
132
-
133
- return connectedTraces
134
- }
135
-
136
- doInitialSourceRender(): void {
137
- const { db } = this.root!
138
- const { _parsedProps: props } = this
139
-
140
- const port_hints = this.getNameAndAliases()
141
-
142
- const source_port = db.source_port.insert({
143
- name: props.name!,
144
- pin_number: props.pinNumber,
145
- port_hints,
146
- source_component_id: this.parent?.source_component_id!,
147
- })
148
-
149
- this.source_port_id = source_port.source_port_id
150
- }
151
-
152
- doInitialSourceParentAttachment(): void {
153
- const { db } = this.root!
154
- if (!this.parent?.source_component_id) {
155
- throw new Error(
156
- `${this.getString()} has no parent source component (parent: ${this.parent?.getString()})`,
157
- )
158
- }
159
-
160
- db.source_port.update(this.source_port_id!, {
161
- source_component_id: this.parent?.source_component_id!,
162
- })
163
-
164
- this.source_component_id = this.parent?.source_component_id
165
- }
166
-
167
- doInitialPcbPortRender(): void {
168
- const { db } = this.root!
169
- const { matchedComponents } = this
170
-
171
- if (!this.parent?.pcb_component_id) {
172
- throw new Error(
173
- `${this.getString()} has no parent pcb component, cannot render pcb_port (parent: ${this.parent?.getString()})`,
174
- )
175
- }
176
-
177
- const pcbMatches = matchedComponents.filter((c) => c.isPcbPrimitive)
178
-
179
- if (pcbMatches.length === 0) return
180
-
181
- if (pcbMatches.length > 1) {
182
- throw new Error(
183
- `${this.getString()} has multiple pcb matches, unclear how to place pcb_port: ${pcbMatches.map((c) => c.getString()).join(", ")}`,
184
- )
185
- }
186
-
187
- const pcbMatch: any = pcbMatches[0]
188
-
189
- if ("_getPcbCircuitJsonBounds" in pcbMatch) {
190
- const pcb_port = db.pcb_port.insert({
191
- pcb_component_id: this.parent?.pcb_component_id!,
192
- layers: this.getAvailablePcbLayers(),
193
-
194
- ...pcbMatch._getPcbCircuitJsonBounds().center,
195
-
196
- source_port_id: this.source_port_id!,
197
- })
198
- this.pcb_port_id = pcb_port.pcb_port_id
199
- } else {
200
- throw new Error(
201
- `${pcbMatch.getString()} does not have a _getGlobalPcbPositionBeforeLayout method (needed for pcb_port placement)`,
202
- )
203
- }
204
- }
205
-
206
- doInitialSchematicPortRender(): void {
207
- const { db } = this.root!
208
- const { _parsedProps: props } = this
209
-
210
- if (!this.parent) return
211
-
212
- const center = this._getGlobalSchematicPositionBeforeLayout()
213
- const parentCenter = this.parent?._getGlobalSchematicPositionBeforeLayout()
214
-
215
- this.facingDirection = getRelativeDirection(parentCenter, center)
216
-
217
- const schematic_port = db.schematic_port.insert({
218
- schematic_component_id: this.parent?.schematic_component_id!,
219
- center,
220
- source_port_id: this.source_port_id!,
221
- facing_direction: this.facingDirection,
222
- })
223
-
224
- this.schematic_port_id = schematic_port.schematic_port_id
225
- }
226
-
227
- _setPositionFromLayout(newCenter: { x: number; y: number }): void {
228
- const { db } = this.root!
229
- if (!this.pcb_port_id) return
230
-
231
- db.pcb_port.update(this.pcb_port_id!, {
232
- x: newCenter.x,
233
- y: newCenter.y,
234
- })
235
- }
236
- }
@@ -1,48 +0,0 @@
1
- import { silkscreenPathProps } from "@tscircuit/props"
2
- import { PrimitiveComponent } from "../base-components/PrimitiveComponent"
3
- import { applyToPoint } from "transformation-matrix"
4
-
5
- export class SilkscreenPath extends PrimitiveComponent<
6
- typeof silkscreenPathProps
7
- > {
8
- pcb_silkscreen_path_id: string | null = null
9
-
10
- get config() {
11
- return {
12
- zodProps: silkscreenPathProps,
13
- }
14
- }
15
-
16
- doInitialPcbPrimitiveRender(): void {
17
- const { db } = this.root!
18
- const { _parsedProps: props } = this
19
-
20
- const layer = props.layer ?? "top"
21
- if (layer !== "top" && layer !== "bottom") {
22
- throw new Error(
23
- `Invalid layer "${layer}" for SilkscreenPath. Must be "top" or "bottom".`,
24
- )
25
- }
26
-
27
- const transform = this._computePcbGlobalTransformBeforeLayout()
28
-
29
- const pcb_silkscreen_path = db.pcb_silkscreen_path.insert({
30
- pcb_component_id: this.parent?.pcb_component_id!,
31
- layer,
32
- route: props.route.map((p) => {
33
- const transformedPosition = applyToPoint(transform, {
34
- x: p.x,
35
- y: p.y,
36
- })
37
- return {
38
- ...p,
39
- x: transformedPosition.x,
40
- y: transformedPosition.y,
41
- }
42
- }),
43
- stroke_width: props.strokeWidth ?? 0.1,
44
- })
45
-
46
- this.pcb_silkscreen_path_id = pcb_silkscreen_path.pcb_silkscreen_path_id
47
- }
48
- }
@@ -1,25 +0,0 @@
1
- import { PrimitiveComponent } from "../base-components/PrimitiveComponent"
2
- import { silkscreenTextProps } from "@tscircuit/props"
3
-
4
- export class SilkscreenText extends PrimitiveComponent<
5
- typeof silkscreenTextProps
6
- > {
7
- doInitialPcbPrimitiveRender(): void {
8
- const { db } = this.root!
9
- const { _parsedProps: props } = this
10
- const container = this.getPrimitiveContainer()!
11
-
12
- db.pcb_silkscreen_text.insert({
13
- anchor_alignment: props.anchorAlignment,
14
- anchor_position: {
15
- x: props.pcbX ?? 0,
16
- y: props.pcbY ?? 0,
17
- },
18
- font: props.font ?? "tscircuit2024",
19
- font_size: props.fontSize ?? 1,
20
- layer: "top",
21
- text: props.text ?? "",
22
- pcb_component_id: container.pcb_component_id!,
23
- })
24
- }
25
- }
@@ -1,162 +0,0 @@
1
- import { PrimitiveComponent } from "../base-components/PrimitiveComponent"
2
- import { smtPadProps } from "@tscircuit/props"
3
- import type { Port } from "./Port"
4
- import type { RenderPhaseFn } from "../base-components/Renderable"
5
- import type { LayerRef, PCBSMTPad } from "@tscircuit/soup"
6
- import { decomposeTSR } from "transformation-matrix"
7
-
8
- export class SmtPad extends PrimitiveComponent<typeof smtPadProps> {
9
- pcb_smtpad_id: string | null = null
10
-
11
- matchedPort: Port | null = null
12
-
13
- isPcbPrimitive = true
14
-
15
- get config() {
16
- return {
17
- zodProps: smtPadProps,
18
- }
19
- }
20
-
21
- getPcbSize(): { width: number; height: number } {
22
- const { _parsedProps: props } = this
23
- if (props.shape === "circle") {
24
- return { width: props.radius! * 2, height: props.radius! * 2 }
25
- }
26
- if (props.shape === "rect") {
27
- return { width: props.width!, height: props.height! }
28
- }
29
- throw new Error(
30
- `getPcbSize for shape "${(props as any).shape}" not implemented for ${this.componentName}`,
31
- )
32
- }
33
-
34
- doInitialPortMatching(): void {
35
- const parentPorts = this.getPrimitiveContainer()?.selectAll(
36
- "port",
37
- ) as Port[]
38
-
39
- if (!this.props.portHints) {
40
- return
41
- }
42
-
43
- for (const port of parentPorts) {
44
- if (port.isMatchingAnyOf(this.props.portHints)) {
45
- this.matchedPort = port
46
- port.registerMatch(this)
47
- return
48
- }
49
- }
50
- }
51
-
52
- getAvailablePcbLayers(): string[] {
53
- return this.props.layer ? [this.props.layer as LayerRef] : []
54
- }
55
-
56
- doInitialPcbPrimitiveRender(): void {
57
- const { db } = this.root!
58
- const { _parsedProps: props } = this
59
- if (!props.portHints) return
60
- const position = this._getGlobalPcbPositionBeforeLayout()
61
- const decomposedMat = decomposeTSR(
62
- this._computePcbGlobalTransformBeforeLayout(),
63
- )
64
- const isRotated90 =
65
- Math.abs(decomposedMat.rotation.angle * (180 / Math.PI) - 90) < 0.01
66
- let pcb_smtpad: PCBSMTPad | null = null
67
- const pcb_component_id =
68
- this.parent?.pcb_component_id ??
69
- this.getPrimitiveContainer()?.pcb_component_id!
70
- if (props.shape === "circle") {
71
- pcb_smtpad = db.pcb_smtpad.insert({
72
- pcb_component_id,
73
- pcb_port_id: this.matchedPort?.pcb_port_id!, // port likely isn't matched
74
- layer: props.layer ?? "top",
75
- shape: "circle",
76
-
77
- // @ts-ignore: no idea why this is triggering
78
- radius: props.radius!,
79
-
80
- port_hints: props.portHints.map((ph) => ph.toString()),
81
-
82
- x: position.x,
83
- y: position.y,
84
- })
85
- } else if (props.shape === "rect") {
86
- pcb_smtpad = db.pcb_smtpad.insert({
87
- pcb_component_id,
88
- pcb_port_id: this.matchedPort?.pcb_port_id!, // port likely isn't matched
89
- layer: props.layer ?? "top",
90
- shape: "rect",
91
-
92
- ...(isRotated90
93
- ? { width: props.height, height: props.width }
94
- : { width: props.width, height: props.height }),
95
-
96
- port_hints: props.portHints.map((ph) => ph.toString()),
97
-
98
- x: position.x,
99
- y: position.y,
100
- })
101
- }
102
- if (pcb_smtpad) {
103
- this.pcb_smtpad_id = pcb_smtpad.pcb_smtpad_id
104
- }
105
- }
106
-
107
- doInitialPcbPortAttachment(): void {
108
- const { db } = this.root!
109
- db.pcb_smtpad.update(this.pcb_smtpad_id!, {
110
- pcb_port_id: this.matchedPort?.pcb_port_id!,
111
- })
112
- }
113
-
114
- _getPcbCircuitJsonBounds(): {
115
- center: { x: number; y: number }
116
- bounds: { left: number; top: number; right: number; bottom: number }
117
- width: number
118
- height: number
119
- } {
120
- const { db } = this.root!
121
- const smtpad = db.pcb_smtpad.get(this.pcb_smtpad_id!)!
122
-
123
- if (smtpad.shape === "rect") {
124
- return {
125
- center: { x: smtpad.x, y: smtpad.y },
126
- bounds: {
127
- left: smtpad.x - smtpad.width / 2,
128
- top: smtpad.y - smtpad.height / 2,
129
- right: smtpad.x + smtpad.width / 2,
130
- bottom: smtpad.y + smtpad.height / 2,
131
- },
132
- width: smtpad.width,
133
- height: smtpad.height,
134
- }
135
- }
136
- if (smtpad.shape === "circle") {
137
- return {
138
- center: { x: smtpad.x, y: smtpad.y },
139
- bounds: {
140
- left: smtpad.x - smtpad.radius,
141
- top: smtpad.y - smtpad.radius,
142
- right: smtpad.x + smtpad.radius,
143
- bottom: smtpad.y + smtpad.radius,
144
- },
145
- width: smtpad.radius * 2,
146
- height: smtpad.radius * 2,
147
- }
148
- }
149
- throw new Error(
150
- `circuitJson bounds calculation not implemented for shape "${(smtpad as any).shape}"`,
151
- )
152
- }
153
-
154
- _setPositionFromLayout(newCenter: { x: number; y: number }) {
155
- const { db } = this.root!
156
- db.pcb_smtpad.update(this.pcb_smtpad_id!, {
157
- x: newCenter.x,
158
- y: newCenter.y,
159
- })
160
- this.matchedPort?._setPositionFromLayout(newCenter)
161
- }
162
- }