@tscircuit/schematic-viewer 0.0.1 → 0.0.2

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 (48) hide show
  1. package/dist/Schematic.d.ts +6 -0
  2. package/dist/Schematic.js +5 -2
  3. package/dist/Schematic.js.map +1 -1
  4. package/dist/index.d.ts +1 -0
  5. package/dist/index.js +8611 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/lib/hooks/index.d.ts +1 -0
  8. package/dist/lib/hooks/use-maybe-promise.d.ts +3 -0
  9. package/dist/lib/render-context/index.d.ts +10 -0
  10. package/dist/lib/types/core.d.ts +149 -0
  11. package/dist/lib/types/index.d.ts +4 -0
  12. package/dist/lib/types/route-solver.d.ts +24 -0
  13. package/dist/lib/types/source-component.d.ts +44 -0
  14. package/dist/lib/types/util.d.ts +14 -0
  15. package/dist/lib/utils/direction-to-vec.d.ts +13 -0
  16. package/dist/lib/utils/get-svg-path-bounds.d.ts +10 -0
  17. package/dist/lib/utils/point-math.d.ts +20 -0
  18. package/dist/pages/_app.d.ts +5 -0
  19. package/dist/pages/index.d.ts +3 -0
  20. package/dist/pages/index.js +5 -2
  21. package/dist/pages/index.js.map +1 -1
  22. package/dist/pages/led-circuit-react.d.ts +3 -0
  23. package/dist/pages/led-circuit-react.js +6476 -21
  24. package/dist/pages/led-circuit-react.js.map +1 -1
  25. package/dist/pages/led-circuit.d.ts +3 -0
  26. package/dist/pages/led-circuit.js +5 -2
  27. package/dist/pages/led-circuit.js.map +1 -1
  28. package/dist/schematic-components/MovableGrid/MovableGrid.stories.d.ts +7 -0
  29. package/dist/schematic-components/MovableGrid/index.d.ts +3 -0
  30. package/dist/schematic-components/ProjectComponent.d.ts +10 -0
  31. package/dist/schematic-components/RenderError.d.ts +6 -0
  32. package/dist/schematic-components/SVGPathComponent.d.ts +19 -0
  33. package/dist/schematic-components/SchematicBug.d.ts +13 -0
  34. package/dist/schematic-components/SchematicComponent.d.ts +13 -0
  35. package/dist/schematic-components/SchematicGroup.d.ts +3 -0
  36. package/dist/schematic-components/SchematicPort.d.ts +13 -0
  37. package/dist/schematic-components/SchematicText.d.ts +10 -0
  38. package/dist/schematic-components/SchematicTrace.d.ts +13 -0
  39. package/dist/schematic-components/SimpleCapacitor.d.ts +13 -0
  40. package/dist/schematic-components/SimpleDiode.d.ts +13 -0
  41. package/dist/schematic-components/SimpleGround.d.ts +13 -0
  42. package/dist/schematic-components/SimpleInductor.d.ts +13 -0
  43. package/dist/schematic-components/SimplePowerSource.d.ts +13 -0
  44. package/dist/schematic-components/SimpleResistor.d.ts +13 -0
  45. package/dist/schematic-components/index.d.ts +18 -0
  46. package/package.json +1 -1
  47. package/src/index.ts +1 -0
  48. package/tsconfig.json +1 -2
@@ -0,0 +1 @@
1
+ export { default as useMaybePromise } from './use-maybe-promise.js';
@@ -0,0 +1,3 @@
1
+ declare const useMaybePromise: <T>(promise: T | Promise<T>) => T;
2
+
3
+ export { useMaybePromise as default, useMaybePromise };
@@ -0,0 +1,10 @@
1
+ import * as zustand from 'zustand';
2
+ import { Matrix } from 'transformation-matrix';
3
+
4
+ interface RenderContextState {
5
+ camera_transform: Matrix;
6
+ }
7
+ declare const useRenderContext: zustand.UseBoundStore<zustand.StoreApi<RenderContextState>>;
8
+ declare const useCameraTransform: () => Matrix;
9
+
10
+ export { useCameraTransform, useRenderContext };
@@ -0,0 +1,149 @@
1
+ import { SourceComponent } from './source-component.js';
2
+ import './util.js';
3
+
4
+ interface SchematicConfig {
5
+ type: "schematic_config";
6
+ }
7
+ interface Point {
8
+ x: number;
9
+ y: number;
10
+ }
11
+ interface Size {
12
+ width: number;
13
+ height: number;
14
+ }
15
+ interface SourceConfig {
16
+ type: "source_config";
17
+ }
18
+ interface SchematicGroup {
19
+ type: "schematic_group";
20
+ schematic_group_id: string;
21
+ source_group_id: string;
22
+ center: Point;
23
+ size: Size;
24
+ children_schematic_component_ids: string[];
25
+ children_schematic_trace_ids: string[];
26
+ }
27
+ interface SchematicComponent {
28
+ type: "schematic_component";
29
+ rotation: number;
30
+ size: Size;
31
+ center: Point;
32
+ source_component_id: string;
33
+ schematic_component_id: string;
34
+ port_arrangement?: {
35
+ left_size: number;
36
+ right_size: number;
37
+ top_size?: number;
38
+ bottom_size?: number;
39
+ };
40
+ port_labels?: {
41
+ [port_number: string]: string;
42
+ };
43
+ }
44
+ interface SchematicTrace {
45
+ type: "schematic_trace";
46
+ schematic_trace_id: string;
47
+ source_trace_id: string;
48
+ edges: Array<{
49
+ from: {
50
+ x: number;
51
+ y: number;
52
+ };
53
+ to: {
54
+ x: number;
55
+ y: number;
56
+ };
57
+ from_schematic_port_id?: string;
58
+ to_schematic_port_id?: string;
59
+ }>;
60
+ }
61
+ interface SchematicText {
62
+ type: "schematic_text";
63
+ schematic_component_id: string;
64
+ schematic_text_id: string;
65
+ text: string;
66
+ position: Point;
67
+ anchor: "center" | "left" | "right" | "top" | "bottom";
68
+ }
69
+ interface SchematicPort {
70
+ type: "schematic_port";
71
+ schematic_port_id: string;
72
+ source_port_id: string;
73
+ center: Point;
74
+ facing_direction?: "up" | "down" | "left" | "right";
75
+ }
76
+ interface PCBTrace {
77
+ type: "pcb_trace";
78
+ source_trace_id: string;
79
+ pcb_trace_id: string;
80
+ route: Array<{
81
+ x: number;
82
+ y: number;
83
+ strokeWidth: number;
84
+ cap: "butt" | "round" | "square";
85
+ start_pcb_port_id?: string;
86
+ end_pcb_port_id?: string;
87
+ }>;
88
+ }
89
+ interface PCBComponent {
90
+ type: "pcb_component";
91
+ pcb_component_id: string;
92
+ source_component_id: string;
93
+ }
94
+ interface PCBPort {
95
+ type: "pcb_port";
96
+ pcb_port_id: string;
97
+ source_port_id: string;
98
+ }
99
+ interface PCBGroup {
100
+ type: "pcb_group";
101
+ source_group_id: string;
102
+ }
103
+ interface PCBConfig {
104
+ type: "pcb_config";
105
+ dimension_unit: "mm";
106
+ }
107
+ interface SourceTrace {
108
+ type: "source_trace";
109
+ source_trace_id: string;
110
+ connected_source_port_ids: string[];
111
+ }
112
+ interface SourceGroup {
113
+ type: "source_group";
114
+ source_group_id: string;
115
+ name: string;
116
+ children_source_component_ids: string[];
117
+ }
118
+ interface SourcePort {
119
+ type: "source_port";
120
+ name: string;
121
+ source_port_id: string;
122
+ source_component_id: string;
123
+ }
124
+ interface Project {
125
+ type: "project";
126
+ schematic_config: SchematicConfig;
127
+ schematic_components: SchematicComponent[];
128
+ schematic_groups: SchematicGroup[];
129
+ schematic_traces: SchematicTrace[];
130
+ schematic_texts: SchematicText[];
131
+ schematic_ports: SchematicPort[];
132
+ pcb_config: PCBConfig;
133
+ pcb_groups: PCBGroup[];
134
+ pcb_components: PCBComponent[];
135
+ pcb_traces: PCBTrace[];
136
+ pcb_ports: PCBPort[];
137
+ source_config: SourceConfig;
138
+ source_traces: SourceTrace[];
139
+ source_groups: SourceGroup[];
140
+ source_components: SourceComponent[];
141
+ source_ports: SourcePort[];
142
+ }
143
+ declare type AnyElement = Project | SourceConfig | SourceComponent | SourceGroup | SourceTrace | SourcePort | PCBTrace | PCBComponent | PCBGroup | PCBConfig | PCBPort | SchematicGroup | SchematicComponent | SchematicTrace | SchematicConfig | SchematicPort | SchematicText;
144
+ declare type ElementType = AnyElement["type"];
145
+ declare type ElementOfType<T extends ElementType> = Extract<AnyElement, {
146
+ type: T;
147
+ }>;
148
+
149
+ export { AnyElement, ElementOfType, ElementType, PCBComponent, PCBConfig, PCBGroup, PCBPort, PCBTrace, Point, Project, SchematicComponent, SchematicConfig, SchematicGroup, SchematicPort, SchematicText, SchematicTrace, Size, SourceConfig, SourceGroup, SourcePort, SourceTrace };
@@ -0,0 +1,4 @@
1
+ export { AnyElement, ElementOfType, ElementType, PCBComponent, PCBConfig, PCBGroup, PCBPort, PCBTrace, Point, Project, SchematicComponent, SchematicConfig, SchematicGroup, SchematicPort, SchematicText, SchematicTrace, Size, SourceConfig, SourceGroup, SourcePort, SourceTrace } from './core.js';
2
+ export { AnySourceComponent, LightEmittingDiode, SimpleBug, SimpleCapacitor, SimpleDiode, SimpleGround, SimpleInductor, SimplePowerSource, SimpleResistor, SourceComponent, SourceComponentBase, SourceComponentFType } from './source-component.js';
3
+ export { NumberWithAnyUnit, NumberWithUnit, SIPrefix, Unit, UnitAbbreviations, UnitOrAbbreviation } from './util.js';
4
+ export { RouteSolver } from './route-solver.js';
@@ -0,0 +1,24 @@
1
+ declare type RouteSolver = (params: {
2
+ terminals: Array<{
3
+ x: number;
4
+ y: number;
5
+ facing_direction?: "up" | "down" | "left" | "right";
6
+ }>;
7
+ obstacles: Array<{
8
+ cx: number;
9
+ cy: number;
10
+ w: number;
11
+ h: number;
12
+ }>;
13
+ }) => Promise<Array<{
14
+ from: {
15
+ x: number;
16
+ y: number;
17
+ };
18
+ to: {
19
+ x: number;
20
+ y: number;
21
+ };
22
+ }>>;
23
+
24
+ export { RouteSolver };
@@ -0,0 +1,44 @@
1
+ import { NumberWithUnit } from './util.js';
2
+
3
+ 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
+ interface SimpleResistor extends SourceComponentBase {
11
+ ftype: "simple_resistor";
12
+ resistance: NumberWithUnit<"ohm">;
13
+ }
14
+ interface SimpleCapacitor extends SourceComponentBase {
15
+ ftype: "simple_capacitor";
16
+ capacitance: NumberWithUnit<"farad">;
17
+ }
18
+ interface SimpleInductor extends SourceComponentBase {
19
+ ftype: "simple_inductor";
20
+ inductance: NumberWithUnit<"henry">;
21
+ }
22
+ interface SimpleDiode extends SourceComponentBase {
23
+ ftype: "simple_diode";
24
+ }
25
+ declare type LightEmittingDiode = SimpleDiode & {
26
+ ftype: "led";
27
+ };
28
+ interface SimpleBug extends SourceComponentBase {
29
+ ftype: "simple_bug";
30
+ }
31
+ interface SimplePowerSource extends SourceComponentBase {
32
+ ftype: "simple_power_source";
33
+ voltage: NumberWithUnit<"volt">;
34
+ }
35
+ interface SimpleGround extends SourceComponentBase {
36
+ ftype: "simple_ground";
37
+ }
38
+ declare type AnySourceComponent = SimpleResistor | SimpleCapacitor | SimpleBug | SimpleInductor | SimplePowerSource | SimpleGround | SimpleDiode | LightEmittingDiode;
39
+ declare type SourceComponentFType = AnySourceComponent["ftype"];
40
+ declare type SourceComponent<T extends SourceComponentFType = SourceComponentFType> = Extract<AnySourceComponent, {
41
+ ftype: T;
42
+ }>;
43
+
44
+ export { AnySourceComponent, LightEmittingDiode, SimpleBug, SimpleCapacitor, SimpleDiode, SimpleGround, SimpleInductor, SimplePowerSource, SimpleResistor, SourceComponent, SourceComponentBase, SourceComponentFType };
@@ -0,0 +1,14 @@
1
+ declare type SIPrefix = "femto" | "f" | "u" | "micro" | "c" | "centi" | "m" | "milli" | "k" | "kilo" | "M" | "mega";
2
+ declare type UnitAbbreviations = {
3
+ farad: "F";
4
+ ohm: "Ω";
5
+ henry: "H";
6
+ meter: "m";
7
+ volt: "V";
8
+ };
9
+ declare type Unit = "ohm" | "farad" | "henry" | "meter" | "volt";
10
+ declare type UnitOrAbbreviation = UnitAbbreviations[Unit] | Unit;
11
+ declare type NumberWithAnyUnit = `${number}${UnitOrAbbreviation}` | `${number} ${UnitOrAbbreviation}` | `${number}${SIPrefix}${UnitOrAbbreviation}` | `${number} ${SIPrefix}${UnitOrAbbreviation}`;
12
+ declare type NumberWithUnit<T extends Unit> = `${number}${T | UnitAbbreviations[T]}` | `${number} ${T | UnitAbbreviations[T]}` | `${number}${SIPrefix}${T | UnitAbbreviations[T]}` | `${number} ${SIPrefix}${T | UnitAbbreviations[T]}`;
13
+
14
+ export { NumberWithAnyUnit, NumberWithUnit, SIPrefix, Unit, UnitAbbreviations, UnitOrAbbreviation };
@@ -0,0 +1,13 @@
1
+ declare const directionToVec: (direction: "up" | "down" | "left" | "right") => {
2
+ x: number;
3
+ y: number;
4
+ };
5
+ declare const vecToDirection: ({ x, y }: {
6
+ x: number;
7
+ y: number;
8
+ }) => "left" | "right" | "up" | "down";
9
+ declare const rotateClockwise: (direction: "up" | "down" | "left" | "right") => "left" | "right" | "up" | "down";
10
+ declare const rotateCounterClockwise: (direction: "up" | "down" | "left" | "right") => "left" | "right" | "up" | "down";
11
+ declare const rotateDirection: (direction: "up" | "down" | "left" | "right", num90DegreeClockwiseTurns: number) => "left" | "right" | "up" | "down";
12
+
13
+ export { directionToVec, rotateClockwise, rotateCounterClockwise, rotateDirection, vecToDirection };
@@ -0,0 +1,10 @@
1
+ declare function getSVGPathBounds(ds: string[] | string): {
2
+ minX: number;
3
+ maxX: number;
4
+ minY: number;
5
+ maxY: number;
6
+ width: number;
7
+ height: number;
8
+ };
9
+
10
+ export { getSVGPathBounds as default, getSVGPathBounds };
@@ -0,0 +1,20 @@
1
+ declare type Point = {
2
+ x: number;
3
+ y: number;
4
+ };
5
+ declare function sub(p1: Point, p2: Point): {
6
+ x: number;
7
+ y: number;
8
+ };
9
+ declare function mult(p1: Point, p2: Point): {
10
+ x: number;
11
+ y: number;
12
+ };
13
+ declare function mag(p1: Point, p2: Point): number;
14
+ declare function componentSum(p1: Point): number;
15
+ declare function norm(p1: Point): {
16
+ x: number;
17
+ y: number;
18
+ };
19
+
20
+ export { Point, componentSum, mag, mult, norm, sub };
@@ -0,0 +1,5 @@
1
+ declare const App: ({ Component }: {
2
+ Component: any;
3
+ }) => JSX.Element;
4
+
5
+ export { App, App as default };
@@ -0,0 +1,3 @@
1
+ declare const _default: () => JSX.Element;
2
+
3
+ export { _default as default };
@@ -8570,14 +8570,17 @@ var Schematic = ({
8570
8570
  const [elements, setElements] = (0, import_react2.useState)(initialElements);
8571
8571
  const [project, setProject] = (0, import_react2.useState)(null);
8572
8572
  (0, import_react2.useEffect)(() => {
8573
- if (initialElements) {
8574
- setProject((0, import_builder2.createProjectFromElements)(elements));
8573
+ if (initialElements.length > 0) {
8574
+ setProject((0, import_builder2.createProjectFromElements)(initialElements));
8575
8575
  return;
8576
8576
  }
8577
8577
  const projectBuilder = (0, import_builder2.createProjectBuilder)();
8578
8578
  (0, import_react_fiber.createRoot)().render(children, projectBuilder).then(async (elements2) => {
8579
8579
  setElements(elements2);
8580
8580
  setProject((0, import_builder2.createProjectFromElements)(elements2));
8581
+ }).catch((e) => {
8582
+ console.error("ERROR RENDERING CIRCUIT");
8583
+ throw e;
8581
8584
  });
8582
8585
  }, [children]);
8583
8586
  if (elements.length === 0)