@tscircuit/schematic-viewer 1.0.12 → 1.0.13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscircuit/schematic-viewer",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "main": "dist/index.js",
5
5
  "license": "MIT",
6
6
  "repository": "tscircuit/schematic-viewer",
@@ -48,6 +48,27 @@ export interface SchematicComponent {
48
48
  }
49
49
  }
50
50
 
51
+ export interface SchematicBox {
52
+ type: "schematic_box"
53
+ drawing_type: "box"
54
+ schematic_box_id: string
55
+ schematic_component_id: string
56
+ x: number
57
+ y: number
58
+ width: number
59
+ height: number
60
+ }
61
+
62
+ export interface SchematicLine {
63
+ type: "schematic_line"
64
+ drawing_type: "line"
65
+ schematic_component_id: string
66
+ x1: number
67
+ y1: number
68
+ x2: number
69
+ y2: number
70
+ }
71
+
51
72
  export interface SchematicTrace {
52
73
  type: "schematic_trace"
53
74
  schematic_trace_id: string
@@ -7,11 +7,22 @@ export const collectElementRefs = (elm: AnyElement, allElms: AnyElement[]) => {
7
7
  e.source_component_id === (elm as any).source_component_id
8
8
  )
9
9
  if (
10
- ["schematic_component", "schematic_trace", "schematic_port"].includes(
11
- elm.type
12
- )
10
+ [
11
+ "schematic_component",
12
+ "schematic_trace",
13
+ "schematic_port",
14
+ "schematic_box",
15
+ "schematic_line",
16
+ ].includes(elm.type)
13
17
  ) {
18
+ const schematic_children = allElms.filter(
19
+ (e) =>
20
+ "schematic_component_id" in e &&
21
+ e.schematic_component_id === (elm as any).schematic_component_id
22
+ )
23
+
14
24
  return {
25
+ schematic_children,
15
26
  schematic: elm,
16
27
  source: source_component,
17
28
  }
@@ -0,0 +1,29 @@
1
+ import * as Type from "lib/types"
2
+ import { directionToVec } from "lib/utils/direction-to-vec"
3
+ import * as Component from "./"
4
+
5
+ interface Props {
6
+ box: {
7
+ schematic: Type.SchematicBox
8
+ }
9
+ }
10
+
11
+ export const SchematicBox = ({ box: { schematic } }: Props) => {
12
+ const { width: w, height: h } = schematic
13
+ return (
14
+ <Component.SVGPathComponent
15
+ rotation={0}
16
+ center={schematic}
17
+ size={{ width: schematic.width, height: schematic.height }}
18
+ paths={[
19
+ {
20
+ stroke: "red",
21
+ strokeWidth: 0.2,
22
+ d: `M 0 0 l ${w} 0 l 0 ${h} l -${w} 0 z`,
23
+ },
24
+ ]}
25
+ />
26
+ )
27
+ }
28
+
29
+ export default SchematicBox
@@ -5,6 +5,7 @@ interface Props {
5
5
  component: {
6
6
  source: Type.SourceComponent
7
7
  schematic: Type.SchematicComponent
8
+ schematic_children: any[]
8
9
  }
9
10
  }
10
11
 
@@ -3,7 +3,9 @@ import { collectElementRefs } from "lib/utils/collect-element-refs"
3
3
  import SchematicComponent from "./SchematicComponent"
4
4
  import SchematicPort from "./SchematicPort"
5
5
  import SchematicText from "./SchematicText"
6
+ import SchematicBox from "./SchematicBox"
6
7
  import SchematicTrace from "./SchematicTrace"
8
+ import SchematicLine from "./SchematicLine"
7
9
 
8
10
  /**
9
11
  * Render any @tsbuilder/builder AnyElement that can be put on a schematic.
@@ -37,6 +39,18 @@ export const SchematicElement = ({
37
39
  )
38
40
  }
39
41
 
42
+ if (element.type === "schematic_box") {
43
+ return (
44
+ <SchematicBox box={collectElementRefs(element, allElements) as any} />
45
+ )
46
+ }
47
+
48
+ if (element.type === "schematic_line") {
49
+ return (
50
+ <SchematicLine line={collectElementRefs(element, allElements) as any} />
51
+ )
52
+ }
53
+
40
54
  if (element.type === "schematic_text") {
41
55
  return <SchematicText schematic_text={element} />
42
56
  }
@@ -0,0 +1,35 @@
1
+ import * as Type from "lib/types"
2
+ import { directionToVec } from "lib/utils/direction-to-vec"
3
+ import * as Component from "."
4
+
5
+ interface Props {
6
+ line: {
7
+ schematic: Type.SchematicLine
8
+ }
9
+ }
10
+
11
+ export const SchematicLine = ({ line: { schematic } }: Props) => {
12
+ const { x1, x2, y1, y2 } = schematic
13
+ const dx = x2 - x1
14
+ const dy = y2 - y1
15
+ const width = Math.abs(dx) + 0.1
16
+ const height = Math.abs(dy) + 0.1
17
+ const center = { x: x1 + dx / 2, y: y1 + dy / 2 }
18
+
19
+ return (
20
+ <Component.SVGPathComponent
21
+ rotation={0}
22
+ center={center}
23
+ size={{ width, height }}
24
+ paths={[
25
+ {
26
+ stroke: "red",
27
+ strokeWidth: 10,
28
+ d: `M 0 0 l ${dx * 100} ${dy * 100}`,
29
+ },
30
+ ]}
31
+ />
32
+ )
33
+ }
34
+
35
+ export default SchematicLine
@@ -23,6 +23,7 @@ export const SchematicText = ({ schematic_text }: Props) => {
23
23
  } else if (anchor === "right") {
24
24
  offset = [-bounds.width, -bounds.height / 2]
25
25
  }
26
+
26
27
  return (
27
28
  <div
28
29
  ref={boundsRef}
@@ -0,0 +1,92 @@
1
+ import { Schematic } from "../Schematic"
2
+
3
+ const soup = [
4
+ {
5
+ type: "source_component",
6
+ source_component_id: "net_alias_0",
7
+ ftype: "net_alias",
8
+ source: {
9
+ type: "source_component",
10
+ source_component_id: "net_alias_0",
11
+ ftype: "net_alias",
12
+ },
13
+ },
14
+ {
15
+ type: "schematic_component",
16
+ schematic_component_id: "schematic_net_alias_component_0",
17
+ source_component_id: "net_alias_0",
18
+ center: {
19
+ x: 2,
20
+ y: 2,
21
+ },
22
+ rotation: 0,
23
+ size: {
24
+ width: 0,
25
+ height: 0,
26
+ },
27
+ source: {
28
+ type: "source_component",
29
+ source_component_id: "net_alias_0",
30
+ ftype: "net_alias",
31
+ },
32
+ },
33
+ {
34
+ type: "source_port",
35
+ name: "gnd",
36
+ source_port_id: "source_port_0",
37
+ },
38
+ {
39
+ type: "schematic_port",
40
+ schematic_port_id: "schematic_port_0",
41
+ source_port_id: "source_port_0",
42
+ center: {
43
+ x: 2,
44
+ y: 2,
45
+ },
46
+ source: {
47
+ type: "source_port",
48
+ name: "gnd",
49
+ source_port_id: "source_port_0",
50
+ },
51
+ },
52
+ {
53
+ drawing_type: "line",
54
+ type: "schematic_line",
55
+ x1: 0,
56
+ y1: 1,
57
+ x2: 4,
58
+ y2: 1,
59
+ schematic_component_id: "schematic_net_alias_component_0",
60
+ source: null,
61
+ },
62
+ {
63
+ drawing_type: "line",
64
+ type: "schematic_line",
65
+ x1: 2,
66
+ y1: 1,
67
+ x2: 2,
68
+ y2: 2,
69
+ schematic_component_id: "schematic_net_alias_component_0",
70
+ source: null,
71
+ },
72
+ {
73
+ anchor: "center",
74
+ type: "schematic_text",
75
+ position: {
76
+ x: 2,
77
+ y: 0.75,
78
+ },
79
+ text: "gnd",
80
+ schematic_component_id: "schematic_net_alias_component_0",
81
+ source: null,
82
+ },
83
+ ]
84
+
85
+ export const NetAliasSoup = () => {
86
+ return <Schematic style={{ height: 500 }} soup={soup} />
87
+ }
88
+
89
+ export default {
90
+ title: "NetAliasSoup",
91
+ component: NetAliasSoup,
92
+ }