@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.
- package/README.md +16 -26
- package/biome.json +8 -1
- package/bun.lockb +0 -0
- package/cosmos.config.json +3 -0
- package/cosmos.decorator.tsx +3 -0
- package/dist/index.d.ts +6 -11
- package/dist/index.js +54 -2485
- package/dist/index.js.map +1 -1
- package/examples/resistor-and-capacitor.fixture.tsx +14 -0
- package/index.html +12 -0
- package/lib/components/SchematicViewer.tsx +78 -0
- package/lib/dev/render-to-circuit-json.ts +8 -0
- package/lib/index.ts +1 -0
- package/package.json +27 -74
- package/src/main.tsx +20 -0
- package/test.ts +0 -0
- package/tsconfig.json +28 -25
- package/vite.config.js +12 -4
- package/.codesandbox/tasks.json +0 -36
- package/.github/workflows/chromatic.yml +0 -30
- package/.github/workflows/npm-build.yml +0 -26
- package/.github/workflows/npm-typecheck.yml +0 -26
- package/.github/workflows/release.yml +0 -29
- package/.prettierrc +0 -1
- package/.storybook/main.ts +0 -12
- package/.storybook/preview.ts +0 -17
- package/ava.config.js +0 -7
- package/dist/index.css +0 -7
- package/dist/index.css.map +0 -1
- package/next-env.d.ts +0 -5
- package/parsel.d.ts +0 -81
- package/release.config.js +0 -15
- package/renovate.json +0 -17
- package/src/Schematic.tsx +0 -246
- package/src/index.ts +0 -1
- package/src/lib/hooks/index.ts +0 -1
- package/src/lib/hooks/use-maybe-promise.ts +0 -14
- package/src/lib/render-context/index.ts +0 -28
- package/src/lib/types/core.ts +0 -181
- package/src/lib/types/index.ts +0 -4
- package/src/lib/types/route-solver.ts +0 -10
- package/src/lib/types/source-component.ts +0 -73
- package/src/lib/types/util.ts +0 -52
- package/src/lib/utils/collect-element-refs.ts +0 -45
- package/src/lib/utils/colors.ts +0 -235
- package/src/lib/utils/direction-to-vec.ts +0 -50
- package/src/lib/utils/get-rotation-from-anchor-side.ts +0 -11
- package/src/lib/utils/get-svg-path-bounds.ts +0 -22
- package/src/lib/utils/get-vec-from-anchor-side.ts +0 -11
- package/src/lib/utils/point-math.ts +0 -26
- package/src/pages/_app.tsx +0 -23
- package/src/pages/index.tsx +0 -10
- package/src/pages/led-circuit-react.tsx +0 -54
- package/src/pages/style.css +0 -5
- package/src/schematic-components/ContextProviders.tsx +0 -15
- package/src/schematic-components/DebugPoint.tsx +0 -25
- package/src/schematic-components/RenderError.tsx +0 -23
- package/src/schematic-components/SVGPathComponent.tsx +0 -183
- package/src/schematic-components/SVGPathComponent2.tsx +0 -76
- package/src/schematic-components/SchematicChip.tsx +0 -202
- package/src/schematic-components/SchematicComponent.tsx +0 -51
- package/src/schematic-components/SchematicComponentFromSymbol.tsx +0 -46
- package/src/schematic-components/SchematicElement.tsx +0 -43
- package/src/schematic-components/SchematicGroup.tsx +0 -3
- package/src/schematic-components/SchematicNetLabel.tsx +0 -63
- package/src/schematic-components/SchematicText.tsx +0 -44
- package/src/schematic-components/SchematicTrace.tsx +0 -51
- package/src/schematic-components/TableViewer.tsx +0 -13
- package/src/schematic-components/index.tsx +0 -9
- package/src/stories/basics/schematic-net-label.stories.tsx +0 -138
- package/src/stories/basics/schematic-net-labels-2.stories.tsx +0 -35
- package/src/stories/bug-connections.stories.tsx +0 -31
- package/src/stories/bug-high-port-numbers.stories.tsx +0 -130
- package/src/stories/bug-one-sided.stories.tsx +0 -34
- package/src/stories/bug-pin-spacing.stories.tsx +0 -52
- package/src/stories/bugs/bug1-y-flip.stories.tsx +0 -20
- package/src/stories/bugs/bug2-component-bounds.stories.tsx +0 -62
- package/src/stories/bugs/bug3-scaling-trace.stories.tsx +0 -24
- package/src/stories/bugs/bug4-schematic-line.stories.tsx +0 -17
- package/src/stories/bugs/bug5-diode.stories.tsx +0 -16
- package/src/stories/bugs/bug6-trace-scaling.stories.tsx +0 -18
- package/src/stories/bugs/bug7-multiple-schematic-panning.stories.tsx +0 -23
- package/src/stories/bugs/bug8-autolayout.stories.tsx +0 -43
- package/src/stories/circuit-components/diode.stories.tsx +0 -16
- package/src/stories/circuit-components/netalias.stories.tsx +0 -14
- package/src/stories/circuit-components/resistor.stories.tsx +0 -16
- package/src/stories/component-drawing-example.stories.tsx +0 -17
- package/src/stories/led-circuit-react.stories.tsx +0 -48
- package/src/stories/net-alias.stories.tsx +0 -92
- package/src/stories/off-center-render.stories.tsx +0 -29
- package/src/stories/rotated-resistor.stories.tsx +0 -23
- package/src/stories/schematic-path.stories.tsx +0 -40
- package/src/stories/three-sided-bug.stories.tsx +0 -30
- package/tsconfig.tsbuildinfo +0 -1
- package/tsup.config.ts +0 -8
- package/vercel.json +0 -3
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import { useGlobalStore } from "lib/render-context"
|
|
2
|
-
import getSVGPathBounds from "lib/utils/get-svg-path-bounds"
|
|
3
|
-
import { useState } from "react"
|
|
4
|
-
import {
|
|
5
|
-
applyToPoint,
|
|
6
|
-
compose,
|
|
7
|
-
scale,
|
|
8
|
-
toSVG,
|
|
9
|
-
translate,
|
|
10
|
-
} from "transformation-matrix"
|
|
11
|
-
import "../pages/style.css"
|
|
12
|
-
interface PathProps {
|
|
13
|
-
type?: "path"
|
|
14
|
-
strokeWidth: number
|
|
15
|
-
stroke: string
|
|
16
|
-
fill?: string
|
|
17
|
-
d: string
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
interface CircleProps {
|
|
21
|
-
type: "circle"
|
|
22
|
-
cx: number
|
|
23
|
-
cy: number
|
|
24
|
-
r: number
|
|
25
|
-
strokeWidth: number
|
|
26
|
-
stroke: string
|
|
27
|
-
fill?: string
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
interface TextProps {
|
|
31
|
-
type: "text"
|
|
32
|
-
cx: number
|
|
33
|
-
cy: number
|
|
34
|
-
text: string
|
|
35
|
-
fontSize?: number
|
|
36
|
-
fill: string
|
|
37
|
-
anchor?: "start" | "middle" | "end"
|
|
38
|
-
rotation?: number
|
|
39
|
-
stroke?: string
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export type SVGElement = PathProps | CircleProps | TextProps
|
|
43
|
-
|
|
44
|
-
interface Props {
|
|
45
|
-
rotation: number
|
|
46
|
-
center: { x: number; y: number }
|
|
47
|
-
size: { width: number; height: number }
|
|
48
|
-
invertY?: boolean
|
|
49
|
-
shiftToBottom?: boolean
|
|
50
|
-
paths: SVGElement[]
|
|
51
|
-
zIndex?: number
|
|
52
|
-
hoverContent?: any
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export const SVGPathComponent = ({
|
|
56
|
-
size,
|
|
57
|
-
center,
|
|
58
|
-
rotation,
|
|
59
|
-
paths,
|
|
60
|
-
zIndex,
|
|
61
|
-
invertY,
|
|
62
|
-
shiftToBottom,
|
|
63
|
-
hoverContent,
|
|
64
|
-
}: Props) => {
|
|
65
|
-
const ct = useGlobalStore((s) => s.camera_transform)
|
|
66
|
-
const pathBounds = getSVGPathBounds(
|
|
67
|
-
paths
|
|
68
|
-
.filter((p): p is PathProps => p.type !== "circle" && p.type !== "text")
|
|
69
|
-
.map((p) => p.d),
|
|
70
|
-
)
|
|
71
|
-
const padding = { x: 0, y: 0 }
|
|
72
|
-
const absoluteCenter = applyToPoint(ct, center)
|
|
73
|
-
const innerSize = {
|
|
74
|
-
width: size.width * ct.a,
|
|
75
|
-
height: size.height * Math.abs(ct.d),
|
|
76
|
-
}
|
|
77
|
-
const fullSize = {
|
|
78
|
-
width: innerSize.width + padding.x * 2,
|
|
79
|
-
height: innerSize.height + padding.y * 2,
|
|
80
|
-
}
|
|
81
|
-
const [hovering, setHovering] = useState(false)
|
|
82
|
-
const svgLeft = absoluteCenter.x - fullSize.width / 2
|
|
83
|
-
const svgTop = absoluteCenter.y - fullSize.height / 2
|
|
84
|
-
const preferredRatio =
|
|
85
|
-
pathBounds.width === 0
|
|
86
|
-
? innerSize.height / pathBounds.height
|
|
87
|
-
: innerSize.width / pathBounds.width
|
|
88
|
-
const svgToScreen = compose(
|
|
89
|
-
scale(
|
|
90
|
-
pathBounds.width === 0
|
|
91
|
-
? preferredRatio
|
|
92
|
-
: fullSize.width / pathBounds.width,
|
|
93
|
-
pathBounds.height === 0
|
|
94
|
-
? preferredRatio
|
|
95
|
-
: fullSize.height / pathBounds.height,
|
|
96
|
-
),
|
|
97
|
-
translate(-pathBounds.minX, -pathBounds.minY),
|
|
98
|
-
)
|
|
99
|
-
|
|
100
|
-
const baseFontSize = 0.15 // Fixed base font size in schematic units
|
|
101
|
-
|
|
102
|
-
return (
|
|
103
|
-
// biome-ignore lint/a11y/noSvgWithoutTitle: <explanation>
|
|
104
|
-
<svg
|
|
105
|
-
onMouseOver={() => setHovering(Boolean(hoverContent))}
|
|
106
|
-
onFocus={() => setHovering(Boolean(hoverContent))}
|
|
107
|
-
onMouseOut={() => setHovering(false)}
|
|
108
|
-
onBlur={() => setHovering(false)}
|
|
109
|
-
style={{
|
|
110
|
-
position: "absolute",
|
|
111
|
-
cursor: hovering ? "pointer" : undefined,
|
|
112
|
-
zIndex,
|
|
113
|
-
transform: [
|
|
114
|
-
invertY ? "scale(1, 1)" : "scale(1, -1)",
|
|
115
|
-
shiftToBottom ? "translate(0, 100%)" : "",
|
|
116
|
-
rotation === 0 ? "" : `rotate(${rotation}deg)`,
|
|
117
|
-
].join(" "),
|
|
118
|
-
left: svgLeft,
|
|
119
|
-
top: svgTop,
|
|
120
|
-
}}
|
|
121
|
-
overflow="visible"
|
|
122
|
-
width={fullSize.width}
|
|
123
|
-
height={fullSize.height}
|
|
124
|
-
>
|
|
125
|
-
{paths.map((p, i) => {
|
|
126
|
-
if (p.type === "circle") {
|
|
127
|
-
return (
|
|
128
|
-
<circle
|
|
129
|
-
key={`${p.type}-${i}`}
|
|
130
|
-
transform={toSVG(compose(scale(1, 1), svgToScreen))}
|
|
131
|
-
cx={p.cx}
|
|
132
|
-
cy={p.cy}
|
|
133
|
-
r={p.r}
|
|
134
|
-
fill={"none"}
|
|
135
|
-
strokeWidth={2.25 * (p.strokeWidth || 1)}
|
|
136
|
-
stroke={p.stroke || "red"}
|
|
137
|
-
/>
|
|
138
|
-
)
|
|
139
|
-
}
|
|
140
|
-
if (p.type === "text") {
|
|
141
|
-
const transformedPos = applyToPoint(svgToScreen, { x: p.cx, y: p.cy })
|
|
142
|
-
const scaleFactor = fullSize.width / pathBounds.width || 1
|
|
143
|
-
|
|
144
|
-
return (
|
|
145
|
-
<g key={`${p.type}-${i}`}>
|
|
146
|
-
<text
|
|
147
|
-
className="schematic-text"
|
|
148
|
-
x={transformedPos.x}
|
|
149
|
-
y={transformedPos.y}
|
|
150
|
-
fill={p.fill}
|
|
151
|
-
fontSize={baseFontSize * scaleFactor}
|
|
152
|
-
textAnchor={p.anchor || "middle"}
|
|
153
|
-
dominantBaseline="middle"
|
|
154
|
-
transform={`scale(1,-1) rotate(${p.rotation || 0})`}
|
|
155
|
-
style={{
|
|
156
|
-
transformBox: "fill-box",
|
|
157
|
-
transformOrigin: "center",
|
|
158
|
-
}}
|
|
159
|
-
stroke={p.stroke}
|
|
160
|
-
>
|
|
161
|
-
{p.text}
|
|
162
|
-
</text>
|
|
163
|
-
</g>
|
|
164
|
-
)
|
|
165
|
-
}
|
|
166
|
-
// Handle the "path" type directly
|
|
167
|
-
return (
|
|
168
|
-
<path
|
|
169
|
-
key={`${p.type}-${i}`}
|
|
170
|
-
transform={toSVG(svgToScreen)}
|
|
171
|
-
fill={p.fill ?? "none"}
|
|
172
|
-
strokeLinecap="round"
|
|
173
|
-
strokeWidth={1.5 * (p.strokeWidth || 1)}
|
|
174
|
-
stroke={p.stroke || "red"}
|
|
175
|
-
d={p.d || ""}
|
|
176
|
-
/>
|
|
177
|
-
)
|
|
178
|
-
})}
|
|
179
|
-
</svg>
|
|
180
|
-
)
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
export default SVGPathComponent
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { useGlobalStore } from "lib/render-context"
|
|
2
|
-
import getSVGPathBounds from "lib/utils/get-svg-path-bounds"
|
|
3
|
-
import { useCallback, useState } from "react"
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
applyToPoint,
|
|
7
|
-
toSVG,
|
|
8
|
-
inverse,
|
|
9
|
-
compose,
|
|
10
|
-
translate,
|
|
11
|
-
scale,
|
|
12
|
-
} from "transformation-matrix"
|
|
13
|
-
|
|
14
|
-
interface Props {
|
|
15
|
-
rotation: number
|
|
16
|
-
center: { x: number; y: number }
|
|
17
|
-
size: { width: number; height: number }
|
|
18
|
-
invertY?: boolean
|
|
19
|
-
shiftToBottom?: boolean
|
|
20
|
-
paths: Array<{
|
|
21
|
-
strokeWidth: number
|
|
22
|
-
stroke: string
|
|
23
|
-
fill?: string
|
|
24
|
-
d: string
|
|
25
|
-
}>
|
|
26
|
-
zIndex?: number
|
|
27
|
-
hoverContent?: any
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export const SVGPathComponent2 = ({
|
|
31
|
-
size,
|
|
32
|
-
center,
|
|
33
|
-
rotation,
|
|
34
|
-
paths,
|
|
35
|
-
zIndex,
|
|
36
|
-
invertY,
|
|
37
|
-
shiftToBottom,
|
|
38
|
-
hoverContent,
|
|
39
|
-
}: Props) => {
|
|
40
|
-
const ct = useGlobalStore((c) => c.camera_transform)
|
|
41
|
-
const pathBounds = getSVGPathBounds(paths.map((p) => p.d))
|
|
42
|
-
// Margin in SVG Space
|
|
43
|
-
|
|
44
|
-
return (
|
|
45
|
-
<svg
|
|
46
|
-
style={{
|
|
47
|
-
position: "absolute",
|
|
48
|
-
left: 0,
|
|
49
|
-
top: 0,
|
|
50
|
-
right: 0,
|
|
51
|
-
bottom: 0,
|
|
52
|
-
// backgroundColor: hovering ? "rgba(0, 0, 255, 0.5)" : "transparent",
|
|
53
|
-
pointerEvents: "none",
|
|
54
|
-
zIndex,
|
|
55
|
-
// overflow: "hidden",
|
|
56
|
-
// backgroundColor: badRatio ? "rgba(255, 0, 0, 0.1)" : "transparent",
|
|
57
|
-
// backgroundColor: "rgba(255, 0, 0, 0.1)",
|
|
58
|
-
}}
|
|
59
|
-
overflow="visible"
|
|
60
|
-
>
|
|
61
|
-
{paths.map((p, i) => (
|
|
62
|
-
<path
|
|
63
|
-
key={i}
|
|
64
|
-
transform={toSVG(ct)}
|
|
65
|
-
fill={p.fill ?? "none"}
|
|
66
|
-
strokeLinecap="round"
|
|
67
|
-
strokeWidth={1.5 * (p.strokeWidth || 1)}
|
|
68
|
-
stroke={p.stroke || "red"}
|
|
69
|
-
d={p.d}
|
|
70
|
-
/>
|
|
71
|
-
))}
|
|
72
|
-
</svg>
|
|
73
|
-
)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export default SVGPathComponent2
|
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AnyCircuitElement,
|
|
3
|
-
SchematicPort as OriginalSchematicPort,
|
|
4
|
-
SchematicComponent,
|
|
5
|
-
} from "circuit-json"
|
|
6
|
-
import type * as Type from "lib/types"
|
|
7
|
-
import { colorMap } from "lib/utils/colors"
|
|
8
|
-
import type React from "react"
|
|
9
|
-
import SVGPathComponent from "./SVGPathComponent"
|
|
10
|
-
import SchematicText from "./SchematicText"
|
|
11
|
-
|
|
12
|
-
interface Props {
|
|
13
|
-
component: {
|
|
14
|
-
source: Type.SimpleBug
|
|
15
|
-
schematic: SchematicComponent
|
|
16
|
-
allElements: AnyCircuitElement[]
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
type ExtendedCenter = OriginalSchematicPort["center"] & {
|
|
21
|
-
side: "left" | "right" | "top" | "bottom" | "center"
|
|
22
|
-
pinNumber: number
|
|
23
|
-
distanceFromEdge: number
|
|
24
|
-
trueIndex: number
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
type SchematicPort = Omit<OriginalSchematicPort, "center"> & {
|
|
28
|
-
center: ExtendedCenter
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export const SchematicChip: React.FC<Props> = ({
|
|
32
|
-
component: { source, schematic, allElements },
|
|
33
|
-
}) => {
|
|
34
|
-
const { center, size, rotation, schematic_component_id } = schematic
|
|
35
|
-
const { manufacturerPartNumber, name } = source
|
|
36
|
-
const chipWidth = size.width
|
|
37
|
-
const chipHeight = size.height
|
|
38
|
-
|
|
39
|
-
const paths: Array<{
|
|
40
|
-
type: "path" | "circle" | "text"
|
|
41
|
-
strokeWidth: number
|
|
42
|
-
stroke: string
|
|
43
|
-
fill?: string
|
|
44
|
-
d?: string
|
|
45
|
-
cx?: number
|
|
46
|
-
cy?: number
|
|
47
|
-
r?: number
|
|
48
|
-
text?: string
|
|
49
|
-
anchor?: string
|
|
50
|
-
rotation?: number
|
|
51
|
-
}> = []
|
|
52
|
-
|
|
53
|
-
// Main chip rectangle
|
|
54
|
-
paths.push({
|
|
55
|
-
type: "path",
|
|
56
|
-
strokeWidth: 0.02,
|
|
57
|
-
stroke: colorMap.schematic.component_outline,
|
|
58
|
-
fill: colorMap.schematic.component_body,
|
|
59
|
-
d: `M ${-chipWidth / 2},${-chipHeight / 2} h ${chipWidth} v ${chipHeight} h ${-chipWidth} Z`,
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
const schematicPorts = allElements.filter(
|
|
63
|
-
(item): item is SchematicPort =>
|
|
64
|
-
item.type === "schematic_port" &&
|
|
65
|
-
item.schematic_component_id === schematic_component_id,
|
|
66
|
-
)
|
|
67
|
-
|
|
68
|
-
const portLength = 0.5
|
|
69
|
-
const circleRadius = 0.04
|
|
70
|
-
const labelOffset = 0.1
|
|
71
|
-
|
|
72
|
-
for (const port of schematicPorts) {
|
|
73
|
-
const { side, pinNumber, distanceFromEdge } = port.center
|
|
74
|
-
let x = 0
|
|
75
|
-
let y = 0
|
|
76
|
-
let endX = 0
|
|
77
|
-
let endY = 0
|
|
78
|
-
let pinX = 0
|
|
79
|
-
let pinY = 0
|
|
80
|
-
let textAnchor = "middle"
|
|
81
|
-
let rotation = 0
|
|
82
|
-
|
|
83
|
-
if (side === "center") {
|
|
84
|
-
continue
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
switch (side) {
|
|
88
|
-
case "left":
|
|
89
|
-
x = -chipWidth / 2
|
|
90
|
-
y = -chipHeight / 2 + distanceFromEdge
|
|
91
|
-
endX = x - portLength
|
|
92
|
-
endY = y
|
|
93
|
-
pinX = x - portLength / 2
|
|
94
|
-
pinY = y + labelOffset
|
|
95
|
-
textAnchor = "middle"
|
|
96
|
-
break
|
|
97
|
-
case "right":
|
|
98
|
-
x = chipWidth / 2
|
|
99
|
-
y = chipHeight / 2 - distanceFromEdge
|
|
100
|
-
endX = x + portLength
|
|
101
|
-
endY = y
|
|
102
|
-
pinX = x + portLength / 2 - labelOffset
|
|
103
|
-
pinY = y + labelOffset
|
|
104
|
-
textAnchor = "start"
|
|
105
|
-
break
|
|
106
|
-
case "bottom":
|
|
107
|
-
x = -chipWidth / 2 + distanceFromEdge
|
|
108
|
-
y = -chipHeight / 2
|
|
109
|
-
endX = x
|
|
110
|
-
endY = y - portLength
|
|
111
|
-
pinX = x - labelOffset
|
|
112
|
-
pinY = y - portLength / 2
|
|
113
|
-
rotation = -90
|
|
114
|
-
break
|
|
115
|
-
case "top":
|
|
116
|
-
x = chipWidth / 2 - distanceFromEdge
|
|
117
|
-
y = chipHeight / 2
|
|
118
|
-
endX = x
|
|
119
|
-
endY = y + portLength
|
|
120
|
-
pinX = x - labelOffset
|
|
121
|
-
pinY = y + portLength / 2
|
|
122
|
-
rotation = -90
|
|
123
|
-
break
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// Port line
|
|
127
|
-
paths.push({
|
|
128
|
-
type: "path",
|
|
129
|
-
strokeWidth: 0.015,
|
|
130
|
-
stroke: colorMap.schematic.component_outline,
|
|
131
|
-
d: `M ${x},${y} L ${endX},${endY}`,
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
// Port circle at the end of the line
|
|
135
|
-
paths.push({
|
|
136
|
-
type: "circle",
|
|
137
|
-
cx: endX,
|
|
138
|
-
cy: endY,
|
|
139
|
-
r: circleRadius,
|
|
140
|
-
strokeWidth: 0.005,
|
|
141
|
-
stroke: colorMap.schematic.component_outline,
|
|
142
|
-
fill: colorMap.schematic.component_outline,
|
|
143
|
-
})
|
|
144
|
-
|
|
145
|
-
// Add pin number
|
|
146
|
-
if (pinNumber !== undefined) {
|
|
147
|
-
paths.push({
|
|
148
|
-
type: "text",
|
|
149
|
-
cx: pinX,
|
|
150
|
-
cy: pinY,
|
|
151
|
-
text: `${pinNumber}`,
|
|
152
|
-
anchor: textAnchor,
|
|
153
|
-
rotation: rotation,
|
|
154
|
-
strokeWidth: 0.005,
|
|
155
|
-
stroke: colorMap.schematic.pin_number,
|
|
156
|
-
})
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
return (
|
|
161
|
-
<>
|
|
162
|
-
<SVGPathComponent
|
|
163
|
-
rotation={rotation}
|
|
164
|
-
center={center}
|
|
165
|
-
size={size}
|
|
166
|
-
paths={paths as any}
|
|
167
|
-
/>
|
|
168
|
-
<SchematicText
|
|
169
|
-
schematic_text={{
|
|
170
|
-
anchor: "right",
|
|
171
|
-
rotation: 0,
|
|
172
|
-
position: {
|
|
173
|
-
x: center.x,
|
|
174
|
-
y: center.y - chipHeight / 2 - 0.2,
|
|
175
|
-
},
|
|
176
|
-
schematic_component_id: "SYNTHETIC",
|
|
177
|
-
schematic_text_id: "SYNTHETIC_MPN",
|
|
178
|
-
text: manufacturerPartNumber,
|
|
179
|
-
type: "schematic_text",
|
|
180
|
-
color: colorMap.schematic.reference,
|
|
181
|
-
}}
|
|
182
|
-
/>
|
|
183
|
-
<SchematicText
|
|
184
|
-
schematic_text={{
|
|
185
|
-
anchor: "right",
|
|
186
|
-
rotation: 0,
|
|
187
|
-
position: {
|
|
188
|
-
x: center.x,
|
|
189
|
-
y: center.y + chipHeight / 2 + 0.2,
|
|
190
|
-
},
|
|
191
|
-
schematic_component_id: "SYNTHETIC",
|
|
192
|
-
schematic_text_id: "SYNTHETIC_NAME",
|
|
193
|
-
text: name,
|
|
194
|
-
type: "schematic_text",
|
|
195
|
-
color: colorMap.schematic.reference,
|
|
196
|
-
}}
|
|
197
|
-
/>
|
|
198
|
-
</>
|
|
199
|
-
)
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
export default SchematicChip
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AnyCircuitElement,
|
|
3
|
-
SchematicComponent as SchematicComponentType,
|
|
4
|
-
} from "circuit-json"
|
|
5
|
-
import * as Component from "./"
|
|
6
|
-
|
|
7
|
-
interface Props {
|
|
8
|
-
component: {
|
|
9
|
-
source: any
|
|
10
|
-
schematic: SchematicComponentType
|
|
11
|
-
schematic_children: any[]
|
|
12
|
-
allElements: AnyCircuitElement[]
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @deprecated ftype-style rendering is being deprecated in favor of the builder
|
|
18
|
-
* generating schematic lines directly
|
|
19
|
-
*/
|
|
20
|
-
export const SchematicComponent = ({ component }: Props) => {
|
|
21
|
-
const { source, schematic, allElements } = component
|
|
22
|
-
if (!source.ftype) return null
|
|
23
|
-
|
|
24
|
-
switch (source.ftype) {
|
|
25
|
-
case "simple_resistor":
|
|
26
|
-
case "simple_capacitor":
|
|
27
|
-
case "simple_power_source":
|
|
28
|
-
case "simple_ground":
|
|
29
|
-
case "simple_inductor":
|
|
30
|
-
case "simple_diode": {
|
|
31
|
-
return (
|
|
32
|
-
<Component.SchematicComponentFromSymbol
|
|
33
|
-
component={{ source, schematic }}
|
|
34
|
-
/>
|
|
35
|
-
)
|
|
36
|
-
}
|
|
37
|
-
case "simple_chip":
|
|
38
|
-
case "simple_bug": {
|
|
39
|
-
return (
|
|
40
|
-
<Component.SchematicChip
|
|
41
|
-
component={{ source, schematic, allElements }}
|
|
42
|
-
/>
|
|
43
|
-
)
|
|
44
|
-
}
|
|
45
|
-
default: {
|
|
46
|
-
return <div>unknown ftype: {component.source.ftype}</div>
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export default SchematicComponent
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { SchematicComponent, SourceSimpleResistor } from "circuit-json"
|
|
2
|
-
import { colorMap } from "lib/utils/colors"
|
|
3
|
-
import { symbols } from "schematic-symbols"
|
|
4
|
-
import SVGPathComponent from "./SVGPathComponent"
|
|
5
|
-
|
|
6
|
-
interface Props {
|
|
7
|
-
component: {
|
|
8
|
-
source: SourceSimpleResistor
|
|
9
|
-
schematic: SchematicComponent
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const SchematicComponentFromSymbol = ({
|
|
14
|
-
component: { source, schematic },
|
|
15
|
-
}: Props) => {
|
|
16
|
-
const { center, rotation } = schematic
|
|
17
|
-
// Get the resistor symbol paths
|
|
18
|
-
const symbol = symbols[schematic.symbol_name]
|
|
19
|
-
const paths = symbol.primitives
|
|
20
|
-
.filter((p: any) => p.type === "path")
|
|
21
|
-
.map((p: any) => ({
|
|
22
|
-
stroke: colorMap.schematic.component_outline,
|
|
23
|
-
strokeWidth: 0.02,
|
|
24
|
-
d: p.points.reduce(
|
|
25
|
-
(acc: string, point: { x: number; y: number }, index: number) => {
|
|
26
|
-
const command = index === 0 ? "M" : "L"
|
|
27
|
-
return `${acc} ${command} ${point.x} ${point.y}`
|
|
28
|
-
},
|
|
29
|
-
"",
|
|
30
|
-
),
|
|
31
|
-
}))
|
|
32
|
-
|
|
33
|
-
return (
|
|
34
|
-
<SVGPathComponent
|
|
35
|
-
rotation={rotation}
|
|
36
|
-
center={center}
|
|
37
|
-
size={{
|
|
38
|
-
width: symbol?.size.width,
|
|
39
|
-
height: symbol?.size.height,
|
|
40
|
-
}}
|
|
41
|
-
paths={paths}
|
|
42
|
-
/>
|
|
43
|
-
)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export default SchematicComponentFromSymbol
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { AnyCircuitElement } from "circuit-json"
|
|
2
|
-
import { collectElementRefs } from "lib/utils/collect-element-refs"
|
|
3
|
-
import SchematicComponent from "./SchematicComponent"
|
|
4
|
-
import { SchematicNetLabel } from "./SchematicNetLabel"
|
|
5
|
-
import SchematicText from "./SchematicText"
|
|
6
|
-
import SchematicTrace from "./SchematicTrace"
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Render any @tsbuilder/builder AnyElement that can be put on a schematic.
|
|
10
|
-
*/
|
|
11
|
-
export const SchematicElement = ({
|
|
12
|
-
element,
|
|
13
|
-
allElements,
|
|
14
|
-
}: {
|
|
15
|
-
element: AnyCircuitElement
|
|
16
|
-
allElements: AnyCircuitElement[]
|
|
17
|
-
}) => {
|
|
18
|
-
// A lot of the split logic for element types into a project is here:
|
|
19
|
-
// https://github.com/tscircuit/builder/blob/7e7bef9c0aadd11999795003b8986f0d244c111f/src/lib/project/create-project-from-elements.ts#L13
|
|
20
|
-
if (element.type === "schematic_component") {
|
|
21
|
-
return (
|
|
22
|
-
<SchematicComponent
|
|
23
|
-
component={collectElementRefs(element, allElements) as any}
|
|
24
|
-
/>
|
|
25
|
-
)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (element.type === "schematic_trace") {
|
|
29
|
-
return (
|
|
30
|
-
<SchematicTrace trace={collectElementRefs(element, allElements) as any} />
|
|
31
|
-
)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (element.type === "schematic_text") {
|
|
35
|
-
return <SchematicText schematic_text={element} />
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (element.type === "schematic_net_label") {
|
|
39
|
-
return <SchematicNetLabel net_label={element} />
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return null
|
|
43
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import type { SchematicNetLabel as SchematicNetLabelObject } from "@tscircuit/soup"
|
|
2
|
-
import SVGPathComponent from "./SVGPathComponent"
|
|
3
|
-
import SchematicText from "./SchematicText"
|
|
4
|
-
import { getRotationFromAnchorSide } from "lib/utils/get-rotation-from-anchor-side"
|
|
5
|
-
import { getVecFromAnchorSide } from "lib/utils/get-vec-from-anchor-side"
|
|
6
|
-
import { colorMap } from "lib/utils/colors"
|
|
7
|
-
|
|
8
|
-
export const SchematicNetLabel = ({
|
|
9
|
-
net_label,
|
|
10
|
-
}: {
|
|
11
|
-
net_label: SchematicNetLabelObject
|
|
12
|
-
}) => {
|
|
13
|
-
const anchor_side = net_label.anchor_side
|
|
14
|
-
const is_vertical = anchor_side === "top" || anchor_side === "bottom"
|
|
15
|
-
const text_width = is_vertical ? 0.3 : net_label.text.length * 0.15
|
|
16
|
-
// TODO add text
|
|
17
|
-
const path_width = 31 + net_label.text.length * 5
|
|
18
|
-
|
|
19
|
-
const anchor_vec = getVecFromAnchorSide(anchor_side)
|
|
20
|
-
// const anchor_dist = 0 // text_width / 4 - 0.025
|
|
21
|
-
const anchor_dist = is_vertical ? 0.04 : text_width / 4 // - 0.025
|
|
22
|
-
anchor_vec.x *= anchor_dist
|
|
23
|
-
anchor_vec.y *= anchor_dist
|
|
24
|
-
|
|
25
|
-
return (
|
|
26
|
-
<>
|
|
27
|
-
<SVGPathComponent
|
|
28
|
-
rotation={getRotationFromAnchorSide(anchor_side)}
|
|
29
|
-
center={net_label.center}
|
|
30
|
-
// fixed size?
|
|
31
|
-
size={{
|
|
32
|
-
width: 0.05 + text_width,
|
|
33
|
-
height:
|
|
34
|
-
0.2 +
|
|
35
|
-
(is_vertical ? 0.1 * Math.max(1, net_label.text.length - 2) : 0),
|
|
36
|
-
}}
|
|
37
|
-
paths={[
|
|
38
|
-
{
|
|
39
|
-
stroke: "gray",
|
|
40
|
-
strokeWidth: 0.75,
|
|
41
|
-
// d: `M 0 15 L 5 15 L 11 9 L ${path_width} 9 L ${path_width} 21 L 11 21 L 5 15`,
|
|
42
|
-
d: `M 0 15 L 5 15 L 11 5 L ${path_width} 5 L ${path_width} 26 L 11 26 L 5 15`,
|
|
43
|
-
},
|
|
44
|
-
]}
|
|
45
|
-
/>
|
|
46
|
-
<SchematicText
|
|
47
|
-
schematic_text={{
|
|
48
|
-
rotation: is_vertical ? 0 : getRotationFromAnchorSide(anchor_side),
|
|
49
|
-
anchor: is_vertical ? "center" : anchor_side,
|
|
50
|
-
position: {
|
|
51
|
-
x: net_label.center.x + anchor_vec.x,
|
|
52
|
-
y: net_label.center.y + anchor_vec.y,
|
|
53
|
-
},
|
|
54
|
-
schematic_component_id: "SYNTHETIC",
|
|
55
|
-
schematic_text_id: "SYNTHETIC",
|
|
56
|
-
text: net_label.text,
|
|
57
|
-
type: "schematic_text",
|
|
58
|
-
color: colorMap.schematic.net_name,
|
|
59
|
-
}}
|
|
60
|
-
/>
|
|
61
|
-
</>
|
|
62
|
-
)
|
|
63
|
-
}
|