@tscircuit/schematic-viewer 1.4.2 → 2.0.0

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 (96) hide show
  1. package/README.md +16 -26
  2. package/biome.json +8 -1
  3. package/bun.lockb +0 -0
  4. package/cosmos.config.json +3 -0
  5. package/cosmos.decorator.tsx +3 -0
  6. package/dist/index.d.ts +6 -11
  7. package/dist/index.js +54 -2485
  8. package/dist/index.js.map +1 -1
  9. package/examples/resistor-and-capacitor.fixture.tsx +14 -0
  10. package/index.html +12 -0
  11. package/lib/components/SchematicViewer.tsx +78 -0
  12. package/lib/dev/render-to-circuit-json.ts +8 -0
  13. package/lib/index.ts +1 -0
  14. package/package.json +27 -74
  15. package/src/main.tsx +20 -0
  16. package/test.ts +0 -0
  17. package/tsconfig.json +28 -25
  18. package/vite.config.js +12 -4
  19. package/.codesandbox/tasks.json +0 -36
  20. package/.github/workflows/chromatic.yml +0 -30
  21. package/.github/workflows/npm-build.yml +0 -26
  22. package/.github/workflows/npm-typecheck.yml +0 -26
  23. package/.github/workflows/release.yml +0 -29
  24. package/.prettierrc +0 -1
  25. package/.storybook/main.ts +0 -12
  26. package/.storybook/preview.ts +0 -17
  27. package/ava.config.js +0 -7
  28. package/dist/index.css +0 -7
  29. package/dist/index.css.map +0 -1
  30. package/next-env.d.ts +0 -5
  31. package/parsel.d.ts +0 -81
  32. package/release.config.js +0 -15
  33. package/renovate.json +0 -17
  34. package/src/Schematic.tsx +0 -246
  35. package/src/index.ts +0 -1
  36. package/src/lib/hooks/index.ts +0 -1
  37. package/src/lib/hooks/use-maybe-promise.ts +0 -14
  38. package/src/lib/render-context/index.ts +0 -28
  39. package/src/lib/types/core.ts +0 -181
  40. package/src/lib/types/index.ts +0 -4
  41. package/src/lib/types/route-solver.ts +0 -10
  42. package/src/lib/types/source-component.ts +0 -73
  43. package/src/lib/types/util.ts +0 -52
  44. package/src/lib/utils/collect-element-refs.ts +0 -45
  45. package/src/lib/utils/colors.ts +0 -235
  46. package/src/lib/utils/direction-to-vec.ts +0 -50
  47. package/src/lib/utils/get-rotation-from-anchor-side.ts +0 -11
  48. package/src/lib/utils/get-svg-path-bounds.ts +0 -22
  49. package/src/lib/utils/get-vec-from-anchor-side.ts +0 -11
  50. package/src/lib/utils/point-math.ts +0 -26
  51. package/src/pages/_app.tsx +0 -23
  52. package/src/pages/index.tsx +0 -10
  53. package/src/pages/led-circuit-react.tsx +0 -54
  54. package/src/pages/style.css +0 -5
  55. package/src/schematic-components/ContextProviders.tsx +0 -15
  56. package/src/schematic-components/DebugPoint.tsx +0 -25
  57. package/src/schematic-components/RenderError.tsx +0 -23
  58. package/src/schematic-components/SVGPathComponent.tsx +0 -183
  59. package/src/schematic-components/SVGPathComponent2.tsx +0 -76
  60. package/src/schematic-components/SchematicChip.tsx +0 -202
  61. package/src/schematic-components/SchematicComponent.tsx +0 -51
  62. package/src/schematic-components/SchematicComponentFromSymbol.tsx +0 -46
  63. package/src/schematic-components/SchematicElement.tsx +0 -43
  64. package/src/schematic-components/SchematicGroup.tsx +0 -3
  65. package/src/schematic-components/SchematicNetLabel.tsx +0 -63
  66. package/src/schematic-components/SchematicText.tsx +0 -44
  67. package/src/schematic-components/SchematicTrace.tsx +0 -51
  68. package/src/schematic-components/TableViewer.tsx +0 -13
  69. package/src/schematic-components/index.tsx +0 -9
  70. package/src/stories/basics/schematic-net-label.stories.tsx +0 -138
  71. package/src/stories/basics/schematic-net-labels-2.stories.tsx +0 -35
  72. package/src/stories/bug-connections.stories.tsx +0 -31
  73. package/src/stories/bug-high-port-numbers.stories.tsx +0 -130
  74. package/src/stories/bug-one-sided.stories.tsx +0 -34
  75. package/src/stories/bug-pin-spacing.stories.tsx +0 -52
  76. package/src/stories/bugs/bug1-y-flip.stories.tsx +0 -20
  77. package/src/stories/bugs/bug2-component-bounds.stories.tsx +0 -62
  78. package/src/stories/bugs/bug3-scaling-trace.stories.tsx +0 -24
  79. package/src/stories/bugs/bug4-schematic-line.stories.tsx +0 -17
  80. package/src/stories/bugs/bug5-diode.stories.tsx +0 -16
  81. package/src/stories/bugs/bug6-trace-scaling.stories.tsx +0 -18
  82. package/src/stories/bugs/bug7-multiple-schematic-panning.stories.tsx +0 -23
  83. package/src/stories/bugs/bug8-autolayout.stories.tsx +0 -43
  84. package/src/stories/circuit-components/diode.stories.tsx +0 -16
  85. package/src/stories/circuit-components/netalias.stories.tsx +0 -14
  86. package/src/stories/circuit-components/resistor.stories.tsx +0 -16
  87. package/src/stories/component-drawing-example.stories.tsx +0 -17
  88. package/src/stories/led-circuit-react.stories.tsx +0 -48
  89. package/src/stories/net-alias.stories.tsx +0 -92
  90. package/src/stories/off-center-render.stories.tsx +0 -29
  91. package/src/stories/rotated-resistor.stories.tsx +0 -23
  92. package/src/stories/schematic-path.stories.tsx +0 -40
  93. package/src/stories/three-sided-bug.stories.tsx +0 -30
  94. package/tsconfig.tsbuildinfo +0 -1
  95. package/tsup.config.ts +0 -8
  96. package/vercel.json +0 -3
package/src/Schematic.tsx DELETED
@@ -1,246 +0,0 @@
1
- import { useRenderedCircuit } from "@tscircuit/core"
2
- import { findBoundsAndCenter } from "@tscircuit/soup-util"
3
- import type { AnyCircuitElement } from "circuit-json"
4
- import { useGlobalStore } from "lib/render-context"
5
- import type React from "react"
6
- import { useCallback, useEffect, useRef, useState } from "react"
7
- import { ErrorBoundary as TypedErrorBoundary } from "react-error-boundary"
8
- import { SuperGrid, toMMSI } from "react-supergrid"
9
- import useMeasure from "react-use-measure"
10
- import { ContextProviders } from "schematic-components"
11
- import { SchematicElement } from "schematic-components/SchematicElement"
12
- import {
13
- type Matrix,
14
- applyToPoint,
15
- compose,
16
- inverse,
17
- scale,
18
- translate,
19
- } from "transformation-matrix"
20
- import { TableViewer } from "./schematic-components/TableViewer"
21
-
22
- const ErrorBoundary = TypedErrorBoundary as any
23
-
24
- const fallbackRender: any =
25
- (elm) =>
26
- ({ error, resetErrorBoundary }: any) => {
27
- return (
28
- <div style={{ color: "red" }}>
29
- error rendering {elm.type}: {error.toString()}
30
- </div>
31
- )
32
- }
33
-
34
- const toMMSINeg = (v: number, z: number) =>
35
- v >= 0 ? toMMSI(v, z) : `-${toMMSI(-v, z)}`
36
-
37
- export interface SchematicProps {
38
- children?: any
39
- soup?: AnyCircuitElement[]
40
- style?: React.CSSProperties
41
- showTable?: boolean
42
- _soupPostProcessor?: (soup: AnyCircuitElement[]) => AnyCircuitElement[]
43
- }
44
-
45
- export const Schematic = (props: SchematicProps) => {
46
- return (
47
- <ContextProviders>
48
- <SchematicWithoutContext {...props} />
49
- </ContextProviders>
50
- )
51
- }
52
-
53
- export const SchematicWithoutContext = ({
54
- children,
55
- soup,
56
- style,
57
- showTable = false,
58
- _soupPostProcessor,
59
- }: SchematicProps) => {
60
- const {
61
- circuitJson: circuitJsonFromChildren,
62
- error: errorFromChildren,
63
- isLoading,
64
- } = useRenderedCircuit(children)
65
-
66
- const [elements, setElements] = useState<AnyCircuitElement[]>([])
67
- const { setCameraTransform } = useGlobalStore()
68
- const [boundsRef, bounds] = useMeasure()
69
- const containerRef = useRef<HTMLDivElement>(null)
70
- const transformRef = useRef<Matrix>(compose(translate(0, 0), scale(1, 1)))
71
- const isDraggingRef = useRef(false)
72
- const lastMousePosRef = useRef({ x: 0, y: 0 })
73
- const [, forceUpdate] = useState({})
74
-
75
- const updateTransform = useCallback(
76
- (newTransform: Matrix) => {
77
- transformRef.current = newTransform
78
- setCameraTransform(newTransform)
79
- forceUpdate({})
80
- },
81
- [setCameraTransform],
82
- )
83
-
84
- useEffect(() => {
85
- let processedElements: AnyCircuitElement[] = []
86
- if (circuitJsonFromChildren && (!soup || soup.length === 0)) {
87
- processedElements = circuitJsonFromChildren as AnyCircuitElement[]
88
- } else if (soup && soup.length > 0) {
89
- processedElements = soup
90
- }
91
-
92
- if (processedElements.length > 0) {
93
- if (_soupPostProcessor) {
94
- processedElements = _soupPostProcessor(processedElements)
95
- }
96
- setElements(processedElements)
97
- }
98
- }, [circuitJsonFromChildren, soup, _soupPostProcessor])
99
-
100
- useEffect(() => {
101
- if (elements.length > 0 && containerRef.current) {
102
- const elmBounds = containerRef.current.getBoundingClientRect()
103
-
104
- const { center, width, height } = elements.some((e) =>
105
- e.type.startsWith("schematic_"),
106
- )
107
- ? findBoundsAndCenter(
108
- elements.filter((e) => e.type.startsWith("schematic_")),
109
- )
110
- : { center: { x: 0, y: 0 }, width: 0.001, height: 0.001 }
111
-
112
- const scaleFactor = Math.min(
113
- (elmBounds.width ?? 0) / width,
114
- (elmBounds.height ?? 0) / height,
115
- 100,
116
- )
117
-
118
- const newTransform = compose(
119
- translate((elmBounds.width ?? 0) / 2, (elmBounds.height ?? 0) / 2),
120
- scale(scaleFactor, -scaleFactor, 0, 0),
121
- translate(-center.x, -center.y),
122
- )
123
-
124
- updateTransform(newTransform)
125
- }
126
- }, [elements, updateTransform])
127
-
128
- const handleMouseDown = useCallback((e: React.MouseEvent) => {
129
- isDraggingRef.current = true
130
- lastMousePosRef.current = { x: e.clientX, y: e.clientY }
131
- }, [])
132
-
133
- const handleMouseMove = useCallback(
134
- (e: React.MouseEvent) => {
135
- if (!isDraggingRef.current) return
136
-
137
- const dx = e.clientX - lastMousePosRef.current.x
138
- const dy = e.clientY - lastMousePosRef.current.y
139
- lastMousePosRef.current = { x: e.clientX, y: e.clientY }
140
-
141
- const scale = transformRef.current.a // Assuming uniform scaling
142
- const dragSensitivity = 150 / scale // Adjust this value to change drag speed
143
-
144
- const newTransform = compose(
145
- translate(dx * dragSensitivity, dy * dragSensitivity),
146
- transformRef.current,
147
- )
148
- updateTransform(newTransform)
149
- },
150
- [updateTransform],
151
- )
152
-
153
- const handleMouseUp = useCallback(() => {
154
- isDraggingRef.current = false
155
- }, [])
156
-
157
- const handleWheel = useCallback(
158
- (e: WheelEvent) => {
159
- e.preventDefault()
160
- const scaleMultiplier = 0.999 ** e.deltaY
161
-
162
- if (containerRef.current) {
163
- const rect = containerRef.current.getBoundingClientRect()
164
- const mouseX = e.clientX - rect.left
165
- const mouseY = e.clientY - rect.top
166
-
167
- const inverseTransform = inverse(transformRef.current)
168
- const transformedPoint = applyToPoint(inverseTransform, {
169
- x: mouseX,
170
- y: mouseY,
171
- })
172
-
173
- const newTransform = compose(
174
- transformRef.current,
175
- translate(transformedPoint.x, transformedPoint.y),
176
- scale(scaleMultiplier, scaleMultiplier),
177
- translate(-transformedPoint.x, -transformedPoint.y),
178
- )
179
-
180
- updateTransform(newTransform)
181
- }
182
- },
183
- [updateTransform],
184
- )
185
-
186
- useEffect(() => {
187
- const container = containerRef.current
188
- if (container) {
189
- container.addEventListener("wheel", handleWheel, { passive: false })
190
- return () => {
191
- container.removeEventListener("wheel", handleWheel)
192
- }
193
- }
194
- }, [handleWheel])
195
-
196
- if (errorFromChildren) {
197
- return <div>Error: {errorFromChildren.message}</div>
198
- }
199
-
200
- return (
201
- <>
202
- <div
203
- style={{
204
- width: "100%",
205
- backgroundColor: "rgba(255,255,255,0)",
206
- minHeight: 200,
207
- overflow: "hidden",
208
- position: "relative",
209
- isolation: "isolate",
210
- cursor: isDraggingRef.current ? "grabbing" : "grab",
211
- ...style,
212
- }}
213
- ref={(el) => {
214
- containerRef.current = el
215
- boundsRef(el)
216
- }}
217
- onMouseDown={handleMouseDown}
218
- onMouseMove={handleMouseMove}
219
- onMouseUp={handleMouseUp}
220
- onMouseLeave={handleMouseUp}
221
- >
222
- <SuperGrid
223
- stringifyCoord={(x, y, z) => {
224
- if (z === 0) return ""
225
- return `${toMMSINeg(x, z)}, ${toMMSINeg(y, z)}`
226
- }}
227
- width={bounds.width}
228
- height={bounds.height}
229
- transform={transformRef.current}
230
- />
231
- {elements?.map((elm, i) => (
232
- <ErrorBoundary key={`${elm}`} fallbackRender={fallbackRender(elm)}>
233
- <SchematicElement
234
- element={elm}
235
- allElements={elements}
236
- key={JSON.stringify(elm)}
237
- />
238
- </ErrorBoundary>
239
- ))}
240
- </div>
241
- {showTable !== false && elements && (
242
- <TableViewer elements={elements as any} />
243
- )}
244
- </>
245
- )
246
- }
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./Schematic"
@@ -1 +0,0 @@
1
- export * from "./use-maybe-promise"
@@ -1,14 +0,0 @@
1
- import { useEffect, useState } from "react"
2
-
3
- export const useMaybePromise = <T>(promise: Promise<T> | T): T | null => {
4
- const [state, setState] = useState<T | null>(null)
5
- useEffect(() => {
6
- if (promise instanceof Promise) {
7
- promise.then(setState)
8
- } else {
9
- setState(promise)
10
- }
11
- }, [promise])
12
- return state
13
- }
14
- export default useMaybePromise
@@ -1,28 +0,0 @@
1
- import {
2
- createStore as createZustandStore,
3
- useStore as useZustandStore,
4
- UseBoundStore,
5
- } from "zustand"
6
- import { Matrix, compose, scale } from "transformation-matrix"
7
- import { useContext } from "react"
8
- import { StoreContext } from "schematic-components/"
9
-
10
- interface RenderContextState {
11
- camera_transform: Matrix
12
- setCameraTransform: (transform: Matrix) => void
13
- }
14
-
15
- export const createRenderContextStore = () =>
16
- createZustandStore<RenderContextState>((set) => ({
17
- camera_transform: compose(scale(100, 100, 0, 0)),
18
- setCameraTransform: (transform: Matrix) =>
19
- set({ camera_transform: transform }),
20
- }))
21
-
22
- export const useGlobalStore = <T = RenderContextState>(
23
- s?: (state: RenderContextState) => T,
24
- ): T => {
25
- const store = useContext(StoreContext)
26
-
27
- return useZustandStore(store as any, s as any)
28
- }
@@ -1,181 +0,0 @@
1
- import { AnySourceComponent, SourceComponent } from "./source-component"
2
- import {
3
- Size,
4
- Point,
5
- PcbTrace,
6
- PcbComponent,
7
- PcbPort,
8
- SourceGroup,
9
- } from "circuit-json"
10
-
11
- export interface SchematicConfig {
12
- type: "schematic_config"
13
- }
14
-
15
- export interface SourceConfig {
16
- type: "source_config"
17
- }
18
-
19
- export interface SchematicGroup {
20
- type: "schematic_group"
21
- schematic_group_id: string
22
- source_group_id: string
23
- center: Point
24
- size: Size
25
- children_schematic_component_ids: string[]
26
- children_schematic_trace_ids: string[]
27
- }
28
-
29
- export interface SchematicComponent {
30
- type: "schematic_component"
31
- rotation: number
32
- size: Size
33
- center: Point
34
- source_component_id: string
35
- schematic_component_id: string
36
-
37
- // TODO only for schematic-bug
38
- port_arrangement?: {
39
- left_size: number
40
- right_size: number
41
- top_size?: number
42
- bottom_size?: number
43
- }
44
- port_labels?: {
45
- [port_number: string]: string
46
- }
47
- }
48
-
49
- export interface SchematicBox {
50
- type: "schematic_box"
51
- drawing_type: "box"
52
- schematic_box_id: string
53
- schematic_component_id: string
54
- x: number
55
- y: number
56
- width: number
57
- height: number
58
- }
59
-
60
- export interface SchematicLine {
61
- type: "schematic_line"
62
- drawing_type: "line"
63
- schematic_component_id: string
64
- x1: number
65
- y1: number
66
- x2: number
67
- y2: number
68
- }
69
-
70
- export interface SchematicPath {
71
- type: "schematic_path"
72
- drawing_type: "path"
73
- schematic_component_id: string
74
- points: Array<{
75
- x: number
76
- y: number
77
- }>
78
- is_filled: boolean
79
- is_closed: boolean
80
- fill_color?: "red" | "blue"
81
- }
82
-
83
- export interface SchematicTrace {
84
- type: "schematic_trace"
85
- schematic_trace_id: string
86
- source_trace_id: string
87
- edges: Array<{
88
- from: { x: number; y: number }
89
- to: { x: number; y: number }
90
- from_schematic_port_id?: string
91
- to_schematic_port_id?: string
92
- }>
93
- }
94
-
95
- export interface SchematicText {
96
- type: "schematic_text"
97
- schematic_component_id: string
98
- schematic_text_id: string
99
- text: string
100
- position: Point
101
- anchor: "center" | "left" | "right" | "top" | "bottom"
102
- }
103
-
104
- export interface SchematicPort {
105
- type: "schematic_port"
106
- schematic_port_id: string
107
- source_port_id: string
108
- center: Point
109
- facing_direction?: "up" | "down" | "left" | "right"
110
- }
111
-
112
- export interface PCBGroup {
113
- type: "pcb_group"
114
- source_group_id: string
115
- }
116
-
117
- export interface PCBConfig {
118
- type: "pcb_config"
119
- dimension_unit: "mm"
120
- }
121
-
122
- export interface SourceTrace {
123
- type: "source_trace"
124
- source_trace_id: string
125
- connected_source_port_ids: string[]
126
- }
127
-
128
- export interface SourcePort {
129
- type: "source_port"
130
- name: string
131
- pin_number?: number
132
- source_port_id: string
133
- source_component_id: string
134
- }
135
-
136
- export interface Project {
137
- type: "project"
138
- schematic_config: SchematicConfig
139
- schematic_components: SchematicComponent[]
140
- schematic_groups: SchematicGroup[]
141
- schematic_traces: SchematicTrace[]
142
- schematic_texts: SchematicText[]
143
- schematic_ports: SchematicPort[]
144
- pcb_config: PCBConfig
145
- pcb_groups: PCBGroup[]
146
- pcb_components: PcbComponent[]
147
- pcb_traces: PcbTrace[]
148
- pcb_ports: PcbPort[]
149
- source_config: SourceConfig
150
- source_traces: SourceTrace[]
151
- source_groups: SourceGroup[]
152
- source_components: SourceComponent[]
153
- source_ports: SourcePort[]
154
- }
155
-
156
- export type AnyElement =
157
- | Project
158
- | SourceConfig
159
- | AnySourceComponent
160
- | SourceGroup
161
- | SourceTrace
162
- | SourcePort
163
- | PcbTrace
164
- | PcbComponent
165
- | PCBGroup
166
- | PCBConfig
167
- | PcbPort
168
- | SchematicGroup
169
- | SchematicComponent
170
- | SchematicTrace
171
- | SchematicConfig
172
- | SchematicPort
173
- | SchematicText
174
- | SchematicLine
175
- | SchematicPath
176
-
177
- export type ElementType = AnyElement["type"]
178
- export type ElementOfType<T extends ElementType> = Extract<
179
- AnyElement,
180
- { type: T }
181
- >
@@ -1,4 +0,0 @@
1
- export * from "./core"
2
- export * from "./source-component"
3
- export * from "./util"
4
- export * from "./route-solver"
@@ -1,10 +0,0 @@
1
- export type RouteSolver = (params: {
2
- terminals: Array<{
3
- x: number
4
- y: number
5
- facing_direction?: "up" | "down" | "left" | "right"
6
- }>
7
- obstacles: Array<{ cx: number; cy: number; w: number; h: number }>
8
- }) => Promise<
9
- Array<{ from: { x: number; y: number }; to: { x: number; y: number } }>
10
- >
@@ -1,73 +0,0 @@
1
- import { NumberWithUnit } from "./util"
2
-
3
- export interface SourceComponentBase {
4
- type: "source_component"
5
- /** The functional type of this component, e.g. resistor, capacitor etc. */
6
- ftype?: string
7
- source_component_id: string
8
- name: string
9
- }
10
-
11
- export interface SimpleResistor extends SourceComponentBase {
12
- ftype: "simple_resistor"
13
- // Resistance measured in ohms
14
- resistance: NumberWithUnit<"ohm">
15
- }
16
-
17
- export interface SimpleCapacitor extends SourceComponentBase {
18
- ftype: "simple_capacitor"
19
- // Capacitance measured in farads
20
- capacitance: NumberWithUnit<"farad">
21
- }
22
-
23
- export interface SimpleInductor extends SourceComponentBase {
24
- ftype: "simple_inductor"
25
- // Inductance measured in henries
26
- inductance: NumberWithUnit<"henry">
27
- }
28
-
29
- export interface SimpleDiode extends SourceComponentBase {
30
- ftype: "simple_diode"
31
- }
32
-
33
- export type LightEmittingDiode = SimpleDiode & {
34
- ftype: "led"
35
- }
36
-
37
- export interface SimpleBug extends SourceComponentBase {
38
- manufacturerPartNumber: any
39
- ftype: "simple_bug"
40
- }
41
- export interface SimpleChip extends SourceComponentBase {
42
- manufacturerPartNumber: any
43
- ftype: "simple_chip"
44
- }
45
-
46
- export interface SimplePowerSource extends SourceComponentBase {
47
- ftype: "simple_power_source"
48
- voltage: NumberWithUnit<"volt">
49
- }
50
-
51
- export interface SimpleGround extends SourceComponentBase {
52
- ftype: "simple_ground"
53
- }
54
-
55
- export type AnySourceComponent =
56
- | SimpleResistor
57
- | SimpleCapacitor
58
- | SimpleBug
59
- | SimpleChip
60
- | SimpleInductor
61
- | SimplePowerSource
62
- | SimpleGround
63
- | SimpleDiode
64
- | LightEmittingDiode
65
- | Omit<SourceComponentBase, "ftype">
66
-
67
- export type SourceComponentFType = Extract<
68
- AnySourceComponent,
69
- { ftype: string }
70
- >["ftype"]
71
- export type SourceComponent<
72
- T extends SourceComponentFType = SourceComponentFType,
73
- > = Extract<AnySourceComponent, { ftype: T }>
@@ -1,52 +0,0 @@
1
- // Currently, removing uncommon SI Prefixes for type simplicity.
2
- export type SIPrefix =
3
- // | "y"
4
- // | "yocto"
5
- // | "z"
6
- // | "zepto"
7
- // | "atto"
8
- // | "a"
9
- | "femto"
10
- | "f"
11
- | "u"
12
- | "micro"
13
- // | "d"
14
- // | "deci"
15
- | "c"
16
- | "centi"
17
- | "m"
18
- | "milli"
19
- | "k"
20
- | "kilo"
21
- | "M"
22
- | "mega"
23
- // | "G"
24
- // | "T"
25
- // | "P"
26
- // | "E"
27
- // | "Z"
28
- // | "Y"
29
-
30
- export type UnitAbbreviations = {
31
- farad: "F"
32
- ohm: "Ω"
33
- henry: "H"
34
- meter: "m"
35
- volt: "V"
36
- }
37
-
38
- export type Unit = "ohm" | "farad" | "henry" | "meter" | "volt"
39
-
40
- export type UnitOrAbbreviation = UnitAbbreviations[Unit] | Unit
41
-
42
- export type NumberWithAnyUnit =
43
- | `${number}${UnitOrAbbreviation}`
44
- | `${number} ${UnitOrAbbreviation}`
45
- | `${number}${SIPrefix}${UnitOrAbbreviation}`
46
- | `${number} ${SIPrefix}${UnitOrAbbreviation}`
47
-
48
- export type NumberWithUnit<T extends Unit> =
49
- | `${number}${T | UnitAbbreviations[T]}`
50
- | `${number} ${T | UnitAbbreviations[T]}`
51
- | `${number}${SIPrefix}${T | UnitAbbreviations[T]}`
52
- | `${number} ${SIPrefix}${T | UnitAbbreviations[T]}`
@@ -1,45 +0,0 @@
1
- import { AnyCircuitElement, SourcePort } from "circuit-json"
2
-
3
- export const collectElementRefs = (
4
- elm: AnyCircuitElement,
5
- allElms: AnyCircuitElement[],
6
- ) => {
7
- const source_port = allElms.find(
8
- (e) =>
9
- e.type === "source_port" &&
10
- e.source_port_id === (elm as any).source_port_id,
11
- ) as SourcePort | null
12
- const source_component_id: string =
13
- (elm as any).source_component_id ?? source_port?.source_component_id
14
- const source_component = allElms.find(
15
- (e) =>
16
- e.type === "source_component" &&
17
- e.source_component_id === source_component_id,
18
- )
19
- if (
20
- [
21
- "schematic_component",
22
- "schematic_trace",
23
- "schematic_port",
24
- "schematic_box",
25
- "schematic_line",
26
- "schematic_path",
27
- ].includes(elm.type)
28
- ) {
29
- const schematic_children = allElms.filter(
30
- (e) =>
31
- "schematic_component_id" in e &&
32
- e.schematic_component_id === (elm as any).schematic_component_id,
33
- )
34
-
35
- return {
36
- schematic_children,
37
- schematic: elm,
38
- source: source_component,
39
- source_component,
40
- source_port,
41
- allElements: allElms,
42
- }
43
- }
44
- return null
45
- }