@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,70 +0,0 @@
1
- import { capacitorProps, ledProps } from "@tscircuit/props"
2
- import { FTYPE, SYMBOL } from "lib/utils/constants"
3
- import { NormalComponent } from "../base-components/NormalComponent"
4
- import type { capacitance, SourceSimpleCapacitorInput } from "@tscircuit/soup"
5
- import { Trace } from "../primitive-components/Trace"
6
-
7
- type PortNames =
8
- | "1"
9
- | "2"
10
- | "pin1"
11
- | "pin2"
12
- | "left"
13
- | "right"
14
- | "anode"
15
- | "cathode"
16
-
17
- export class Capacitor extends NormalComponent<
18
- typeof capacitorProps,
19
- PortNames
20
- > {
21
- get config() {
22
- return {
23
- // schematicSymbolName: BASE_SYMBOLS.capacitor,
24
- zodProps: ledProps,
25
- sourceFtype: FTYPE.simple_capacitor,
26
- }
27
- }
28
-
29
- pin1 = this.portMap.pin1
30
- pin2 = this.portMap.pin2
31
-
32
- doInitialCreateNetsFromProps() {
33
- this._createNetsFromProps([
34
- this.props.decouplingFor,
35
- this.props.decouplingTo,
36
- ])
37
- }
38
-
39
- doInitialCreateTracesFromProps() {
40
- if (this.props.decouplingFor && this.props.decouplingTo) {
41
- this.add(
42
- new Trace({
43
- from: `${this.getSubcircuitSelector()} > port.1`,
44
- to: this.props.decouplingFor,
45
- }),
46
- )
47
- this.add(
48
- new Trace({
49
- from: `${this.getSubcircuitSelector()} > port.2`,
50
- to: this.props.decouplingTo,
51
- }),
52
- )
53
- }
54
- }
55
-
56
- doInitialSourceRender() {
57
- const { db } = this.root!
58
- const { _parsedProps: props } = this
59
- const source_component = db.source_component.insert({
60
- ftype: "simple_capacitor",
61
- name: props.name,
62
- // @ts-ignore
63
- manufacturer_part_number: props.manufacturerPartNumber ?? props.mfn,
64
- supplier_part_numbers: props.supplierPartNumbers,
65
-
66
- capacitance: props.capacitance,
67
- } as SourceSimpleCapacitorInput)
68
- this.source_component_id = source_component.source_component_id
69
- }
70
- }
@@ -1,98 +0,0 @@
1
- import { NormalComponent } from "lib/components/base-components/NormalComponent"
2
- import { chipProps } from "@tscircuit/props"
3
- import { Port } from "../primitive-components/Port"
4
- import type { BaseSymbolName } from "lib/utils/constants"
5
- import {
6
- getAllDimensionsForSchematicBox,
7
- type SchematicBoxDimensions,
8
- } from "lib/utils/schematic/getAllDimensionsForSchematicBox"
9
- import { underscorifyPortArrangement } from "lib/soup/underscorifyPortArrangement"
10
- import { underscorifyPinStyles } from "lib/soup/underscorifyPinStyles"
11
-
12
- export class Chip<PinLabels extends string = never> extends NormalComponent<
13
- typeof chipProps,
14
- PinLabels
15
- > {
16
- schematicDimensions: SchematicBoxDimensions | null = null
17
-
18
- get config() {
19
- return {
20
- zodProps: chipProps,
21
- }
22
- }
23
-
24
- doInitialSourceRender(): void {
25
- const { db } = this.root!
26
- const { _parsedProps: props } = this
27
-
28
- const source_component = db.source_component.insert({
29
- ftype: "simple_chip",
30
- name: props.name,
31
- manufacturer_part_number: props.manufacturerPartNumber,
32
- supplier_part_numbers: props.supplierPartNumbers,
33
- })
34
-
35
- this.source_component_id = source_component.source_component_id!
36
- }
37
-
38
- doInitialSchematicComponentRender() {
39
- const { db } = this.root!
40
- const { _parsedProps: props } = this
41
-
42
- const ports = this.children.filter((child) => child instanceof Port)
43
-
44
- const pinSpacing = props.schPinSpacing ?? 0.2
45
-
46
- const dimensions = getAllDimensionsForSchematicBox({
47
- schWidth: props.schWidth,
48
- schHeight: props.schHeight,
49
- schPinSpacing: pinSpacing,
50
- schPinStyle: props.schPinStyle,
51
-
52
- pinCount: ports.length,
53
-
54
- // @ts-ignore there's a subtley in the definition difference with
55
- // leftSide/rightSide/topSide/bottomSide in how the direction is defined
56
- // that doesn't really matter
57
- schPortArrangement: props.schPortArrangement,
58
- })
59
- this.schematicDimensions = dimensions
60
-
61
- const schematic_component = db.schematic_component.insert({
62
- center: { x: props.schX ?? 0, y: props.schY ?? 0 },
63
- rotation: props.schRotation ?? 0,
64
- size: dimensions.getSize(),
65
-
66
- port_arrangement: underscorifyPortArrangement(
67
- props.schPortArrangement as any,
68
- ),
69
-
70
- pin_spacing: pinSpacing,
71
-
72
- // @ts-ignore soup needs to support distance for pin_styles
73
- pin_styles: underscorifyPinStyles(props.schPinStyle),
74
-
75
- port_labels: props.pinLabels,
76
-
77
- source_component_id: this.source_component_id!,
78
- })
79
-
80
- this.schematic_component_id = schematic_component.schematic_component_id
81
- }
82
-
83
- doInitialPcbComponentRender() {
84
- const { db } = this.root!
85
- const { _parsedProps: props } = this
86
-
87
- const pcb_component = db.pcb_component.insert({
88
- center: { x: props.pcbX ?? 0, y: props.pcbY ?? 0 },
89
- width: 2, // Default width, adjust as needed
90
- height: 3, // Default height, adjust as needed
91
- layer: props.layer ?? "top",
92
- rotation: props.pcbRotation ?? 0,
93
- source_component_id: this.source_component_id!,
94
- })
95
-
96
- this.pcb_component_id = pcb_component.pcb_component_id
97
- }
98
- }
@@ -1,27 +0,0 @@
1
- import { diodeProps } from "@tscircuit/props"
2
- import {
3
- FTYPE,
4
- SYMBOL,
5
- type Ftype,
6
- type TwoPinPorts,
7
- } from "lib/utils/constants"
8
- import { Port } from "../primitive-components/Port"
9
- import { NormalComponent } from "../base-components/NormalComponent"
10
-
11
- export class Diode extends NormalComponent<typeof diodeProps, TwoPinPorts> {
12
- pin1 = this.portMap.pin1
13
- pin2 = this.portMap.pin2
14
-
15
- get config() {
16
- return {
17
- // schematicSymbolName: "diode" as BaseSymbolName,
18
- zodProps: diodeProps,
19
- sourceFtype: "simple_diode" as Ftype,
20
- }
21
- }
22
-
23
- initPorts() {
24
- this.add(new Port({ name: "pin1", aliases: ["1", "pin1"] }))
25
- this.add(new Port({ name: "pin2", aliases: ["2", "pin2"] }))
26
- }
27
- }
@@ -1,101 +0,0 @@
1
- import { NormalComponent } from "lib/components/base-components/NormalComponent"
2
- import { jumperProps } from "@tscircuit/props"
3
- import { Port } from "../primitive-components/Port"
4
- import type { BaseSymbolName } from "lib/utils/constants"
5
- import {
6
- getAllDimensionsForSchematicBox,
7
- type SchematicBoxDimensions,
8
- } from "lib/utils/schematic/getAllDimensionsForSchematicBox"
9
- import { underscorifyPortArrangement } from "lib/soup/underscorifyPortArrangement"
10
- import { underscorifyPinStyles } from "lib/soup/underscorifyPinStyles"
11
-
12
- export class Jumper<PinLabels extends string = never> extends NormalComponent<
13
- typeof jumperProps,
14
- PinLabels
15
- > {
16
- schematicDimensions: SchematicBoxDimensions | null = null
17
-
18
- get config() {
19
- return {
20
- zodProps: jumperProps,
21
- }
22
- }
23
-
24
- doInitialSourceRender(): void {
25
- const { db } = this.root!
26
- const { _parsedProps: props } = this
27
-
28
- const source_component = db.source_component.insert({
29
- ftype: "simple_chip", // TODO unknown or jumper
30
- name: props.name,
31
- manufacturer_part_number: props.manufacturerPartNumber,
32
- supplier_part_numbers: props.supplierPartNumbers,
33
- })
34
-
35
- this.source_component_id = source_component.source_component_id!
36
- }
37
-
38
- doInitialSchematicComponentRender() {
39
- const { db } = this.root!
40
- const { _parsedProps: props } = this
41
-
42
- const ports = this.children.filter((child) => child instanceof Port)
43
-
44
- const pinSpacing = props.schPinSpacing ?? 0.2
45
-
46
- const dimensions = getAllDimensionsForSchematicBox({
47
- schWidth: props.schWidth,
48
- schHeight: props.schHeight,
49
- schPinSpacing: pinSpacing,
50
- schPinStyle: props.schPinStyle,
51
-
52
- pinCount: ports.length,
53
-
54
- // @ts-ignore there's a subtley in the definition difference with
55
- // leftSide/rightSide/topSide/bottomSide in how the direction is defined
56
- // that doesn't really matter
57
- schPortArrangement: {
58
- // TODO use schematic direction or schPortArrangement
59
- rightSize: ports.length,
60
- },
61
- })
62
- this.schematicDimensions = dimensions
63
-
64
- const schematic_component = db.schematic_component.insert({
65
- center: { x: props.schX ?? 0, y: props.schY ?? 0 },
66
- rotation: props.schRotation ?? 0,
67
- size: dimensions.getSize(),
68
-
69
- port_arrangement: underscorifyPortArrangement(
70
- props.schPortArrangement as any,
71
- ),
72
-
73
- pin_spacing: pinSpacing,
74
-
75
- // @ts-ignore soup needs to support distance for pin_styles
76
- pin_styles: underscorifyPinStyles(props.schPinStyle),
77
-
78
- port_labels: props.pinLabels,
79
-
80
- source_component_id: this.source_component_id!,
81
- })
82
-
83
- this.schematic_component_id = schematic_component.schematic_component_id
84
- }
85
-
86
- doInitialPcbComponentRender() {
87
- const { db } = this.root!
88
- const { _parsedProps: props } = this
89
-
90
- const pcb_component = db.pcb_component.insert({
91
- center: { x: props.pcbX ?? 0, y: props.pcbY ?? 0 },
92
- width: 2, // Default width, adjust as needed
93
- height: 3, // Default height, adjust as needed
94
- layer: props.layer ?? "top",
95
- rotation: props.pcbRotation ?? 0,
96
- source_component_id: this.source_component_id!,
97
- })
98
-
99
- this.pcb_component_id = pcb_component.pcb_component_id
100
- }
101
- }
@@ -1,27 +0,0 @@
1
- import { ledProps } from "@tscircuit/props"
2
- import type {
3
- BaseSymbolName,
4
- Ftype,
5
- PolarizedPassivePorts,
6
- } from "lib/utils/constants"
7
- import { NormalComponent } from "../base-components/NormalComponent"
8
-
9
- export class Led extends NormalComponent<
10
- typeof ledProps,
11
- PolarizedPassivePorts
12
- > {
13
- get config() {
14
- return {
15
- schematicSymbolName: "led" as BaseSymbolName,
16
- zodProps: ledProps,
17
- sourceFtype: "simple_diode" as Ftype,
18
- }
19
- }
20
-
21
- pos = this.portMap.pin1
22
- pin1 = this.portMap.pin1
23
- anode = this.portMap.pin1
24
- neg = this.portMap.pin2
25
- pin2 = this.portMap.pin2
26
- cathode = this.portMap.pin2
27
- }
@@ -1,59 +0,0 @@
1
- import { resistorProps } from "@tscircuit/props"
2
- import type { PassivePorts, Ftype, BaseSymbolName } from "lib/utils/constants"
3
- import { NormalComponent } from "../base-components/NormalComponent"
4
- import type { SourceSimpleResistorInput } from "@tscircuit/soup"
5
- import { z } from "zod"
6
- import { Trace } from "../primitive-components/Trace"
7
- import { Net } from "../primitive-components/Net"
8
-
9
- export class Resistor extends NormalComponent<
10
- typeof resistorProps,
11
- PassivePorts
12
- > {
13
- get config() {
14
- return {
15
- schematicSymbolName: "boxresistor" as BaseSymbolName,
16
- zodProps: resistorProps,
17
- sourceFtype: "simple_resistor" as Ftype,
18
- }
19
- }
20
-
21
- pin1 = this.portMap.pin1
22
- pin2 = this.portMap.pin2
23
-
24
- doInitialCreateNetsFromProps() {
25
- this._createNetsFromProps([this.props.pullupFor, this.props.pullupTo])
26
- }
27
-
28
- doInitialCreateTracesFromProps() {
29
- if (this.props.pullupFor && this.props.pullupTo) {
30
- this.add(
31
- new Trace({
32
- from: `${this.getSubcircuitSelector()} > port.1`,
33
- to: this.props.pullupFor,
34
- }),
35
- )
36
- this.add(
37
- new Trace({
38
- from: `${this.getSubcircuitSelector()} > port.2`,
39
- to: this.props.pullupTo,
40
- }),
41
- )
42
- }
43
- }
44
-
45
- doInitialSourceRender() {
46
- const { db } = this.root!
47
- const { _parsedProps: props } = this
48
- const source_component = db.source_component.insert({
49
- ftype: "simple_resistor",
50
- name: props.name,
51
- // @ts-ignore
52
- manufacturer_part_number: props.manufacturerPartNumber ?? props.mfn,
53
- supplier_part_numbers: props.supplierPartNumbers,
54
-
55
- resistance: props.resistance,
56
- } as SourceSimpleResistorInput)
57
- this.source_component_id = source_component.source_component_id
58
- }
59
- }
@@ -1,91 +0,0 @@
1
- import { constraintProps } from "@tscircuit/props"
2
- import { z } from "zod"
3
- import { PrimitiveComponent } from "../base-components/PrimitiveComponent"
4
-
5
- const edgeSpecifiers = [
6
- "leftedge",
7
- "rightedge",
8
- "topedge",
9
- "bottomedge",
10
- "center",
11
- ] as const
12
-
13
- export type EdgeSpecifier = (typeof edgeSpecifiers)[number]
14
-
15
- export class Constraint extends PrimitiveComponent<typeof constraintProps> {
16
- componentName = "Constraint"
17
-
18
- get config() {
19
- return {
20
- zodProps: constraintProps,
21
- }
22
- }
23
-
24
- constructor(props: z.input<typeof constraintProps>) {
25
- super(props)
26
- if ("xdist" in props || "ydist" in props) {
27
- if (!("edgeToEdge" in props) && !("centerToCenter" in props)) {
28
- // TODO don't throw an error if the selectors specify an edge
29
- throw new Error(
30
- `edgeToEdge, centerToCenter must be set for xDist or yDist for ${this}`,
31
- )
32
- }
33
- }
34
- if ("for" in props && props.for.length < 2) {
35
- throw new Error(`"for" must have at least two selectors for ${this}`)
36
- }
37
- }
38
-
39
- _getAllReferencedComponents(): {
40
- componentsWithSelectors: Array<{
41
- component: PrimitiveComponent<any>
42
- selector: string
43
- componentSelector: string
44
- edge: EdgeSpecifier | undefined
45
- }>
46
- } {
47
- const componentsWithSelectors: Array<{
48
- component: PrimitiveComponent<any>
49
- selector: string
50
- componentSelector: string
51
- edge: EdgeSpecifier | undefined
52
- }> = []
53
-
54
- const container = this.getPrimitiveContainer()!
55
-
56
- function addComponentFromSelector(selector: string) {
57
- // TODO this selector has to be modified in case it contains a leftedge,
58
- // center/topedge/rightedge indicator
59
- const maybeEdge = selector.split(" ").pop() as EdgeSpecifier
60
- const edge = edgeSpecifiers.includes(maybeEdge) ? maybeEdge : undefined
61
- const componentSelector = edge
62
- ? selector.replace(` ${edge}`, "")
63
- : selector
64
- const component = container.selectOne(componentSelector, {
65
- pcbPrimitive: true,
66
- })
67
- if (component) {
68
- componentsWithSelectors.push({
69
- selector,
70
- component,
71
- componentSelector,
72
- edge,
73
- })
74
- }
75
- }
76
-
77
- for (const key of ["left", "right", "top", "bottom"]) {
78
- if (key in this._parsedProps) {
79
- addComponentFromSelector((this._parsedProps as any)[key] as string)
80
- }
81
- }
82
-
83
- if ("for" in this._parsedProps) {
84
- for (const selector of this._parsedProps.for) {
85
- addComponentFromSelector(selector)
86
- }
87
- }
88
-
89
- return { componentsWithSelectors }
90
- }
91
- }
@@ -1,50 +0,0 @@
1
- import { fabricationNotePathProps } from "@tscircuit/props"
2
- import { PrimitiveComponent } from "../base-components/PrimitiveComponent"
3
- import { applyToPoint } from "transformation-matrix"
4
-
5
- export class FabricationNotePath extends PrimitiveComponent<
6
- typeof fabricationNotePathProps
7
- > {
8
- fabrication_note_path_id: string | null = null
9
-
10
- get config() {
11
- return {
12
- zodProps: fabricationNotePathProps,
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 fabrication_note_path = db.pcb_fabrication_note_path.insert({
30
- pcb_component_id: this.parent?.pcb_component_id!,
31
- layer,
32
- color: props.color,
33
- route: props.route.map((p) => {
34
- const transformedPosition = applyToPoint(transform, {
35
- x: p.x,
36
- y: p.y,
37
- })
38
- return {
39
- ...p,
40
- x: transformedPosition.x,
41
- y: transformedPosition.y,
42
- }
43
- }),
44
- stroke_width: props.strokeWidth ?? 0.1,
45
- })
46
-
47
- this.fabrication_note_path_id =
48
- fabrication_note_path.pcb_fabrication_note_path_id
49
- }
50
- }
@@ -1,26 +0,0 @@
1
- import { PrimitiveComponent } from "../base-components/PrimitiveComponent"
2
- import { fabricationNoteTextProps } from "@tscircuit/props"
3
-
4
- export class FabricationNoteText extends PrimitiveComponent<
5
- typeof fabricationNoteTextProps
6
- > {
7
- doInitialPcbPrimitiveRender(): void {
8
- const { db } = this.root!
9
- const { _parsedProps: props } = this
10
- const container = this.getPrimitiveContainer()!
11
-
12
- db.pcb_fabrication_note_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
- color: props.color,
22
- text: props.text ?? "",
23
- pcb_component_id: container.pcb_component_id!,
24
- })
25
- }
26
- }