@tscircuit/schematic-viewer 0.0.1 → 0.0.3
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/dist/Schematic.d.ts +6 -0
- package/dist/Schematic.js +1183 -139
- package/dist/Schematic.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +9652 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/hooks/index.d.ts +1 -0
- package/dist/lib/hooks/use-maybe-promise.d.ts +3 -0
- package/dist/lib/render-context/index.d.ts +10 -0
- package/dist/lib/types/core.d.ts +149 -0
- package/dist/lib/types/index.d.ts +4 -0
- package/dist/lib/types/route-solver.d.ts +24 -0
- package/dist/lib/types/source-component.d.ts +44 -0
- package/dist/lib/types/util.d.ts +14 -0
- package/dist/lib/utils/direction-to-vec.d.ts +13 -0
- package/dist/lib/utils/get-svg-path-bounds.d.ts +10 -0
- package/dist/lib/utils/point-math.d.ts +20 -0
- package/dist/pages/_app.d.ts +5 -0
- package/dist/pages/_app.js +950 -8
- package/dist/pages/_app.js.map +1 -1
- package/dist/pages/index.d.ts +3 -0
- package/dist/pages/index.js +1190 -140
- package/dist/pages/index.js.map +1 -1
- package/dist/pages/led-circuit-react.d.ts +3 -0
- package/dist/pages/led-circuit-react.js +7595 -49
- package/dist/pages/led-circuit-react.js.map +1 -1
- package/dist/pages/led-circuit.d.ts +3 -0
- package/dist/pages/led-circuit.js +1195 -140
- package/dist/pages/led-circuit.js.map +1 -1
- package/dist/schematic-components/MovableGrid/MovableGrid.stories.d.ts +7 -0
- package/dist/schematic-components/MovableGrid/MovableGrid.stories.js +3062 -2
- package/dist/schematic-components/MovableGrid/MovableGrid.stories.js.map +1 -1
- package/dist/schematic-components/MovableGrid/index.d.ts +3 -0
- package/dist/schematic-components/MovableGrid/index.js +3058 -1
- package/dist/schematic-components/MovableGrid/index.js.map +1 -1
- package/dist/schematic-components/ProjectComponent.d.ts +10 -0
- package/dist/schematic-components/ProjectComponent.js +1174 -136
- package/dist/schematic-components/ProjectComponent.js.map +1 -1
- package/dist/schematic-components/RenderError.d.ts +6 -0
- package/dist/schematic-components/RenderError.js +3069 -11
- package/dist/schematic-components/RenderError.js.map +1 -1
- package/dist/schematic-components/SVGPathComponent.d.ts +19 -0
- package/dist/schematic-components/SVGPathComponent.js +3067 -6
- package/dist/schematic-components/SVGPathComponent.js.map +1 -1
- package/dist/schematic-components/SchematicBug.d.ts +13 -0
- package/dist/schematic-components/SchematicBug.js +3090 -26
- package/dist/schematic-components/SchematicBug.js.map +1 -1
- package/dist/schematic-components/SchematicComponent.d.ts +13 -0
- package/dist/schematic-components/SchematicComponent.js +1090 -77
- package/dist/schematic-components/SchematicComponent.js.map +1 -1
- package/dist/schematic-components/SchematicGroup.d.ts +3 -0
- package/dist/schematic-components/SchematicPort.d.ts +13 -0
- package/dist/schematic-components/SchematicPort.js +997 -18
- package/dist/schematic-components/SchematicPort.js.map +1 -1
- package/dist/schematic-components/SchematicText.d.ts +10 -0
- package/dist/schematic-components/SchematicText.js +3059 -6
- package/dist/schematic-components/SchematicText.js.map +1 -1
- package/dist/schematic-components/SchematicTrace.d.ts +13 -0
- package/dist/schematic-components/SchematicTrace.js +3098 -25
- package/dist/schematic-components/SchematicTrace.js.map +1 -1
- package/dist/schematic-components/SimpleCapacitor.d.ts +13 -0
- package/dist/schematic-components/SimpleCapacitor.js +3079 -12
- package/dist/schematic-components/SimpleCapacitor.js.map +1 -1
- package/dist/schematic-components/SimpleDiode.d.ts +13 -0
- package/dist/schematic-components/SimpleDiode.js +3079 -12
- package/dist/schematic-components/SimpleDiode.js.map +1 -1
- package/dist/schematic-components/SimpleGround.d.ts +13 -0
- package/dist/schematic-components/SimpleGround.js +3080 -13
- package/dist/schematic-components/SimpleGround.js.map +1 -1
- package/dist/schematic-components/SimpleInductor.d.ts +13 -0
- package/dist/schematic-components/SimpleInductor.js +3080 -13
- package/dist/schematic-components/SimpleInductor.js.map +1 -1
- package/dist/schematic-components/SimplePowerSource.d.ts +13 -0
- package/dist/schematic-components/SimplePowerSource.js +3080 -13
- package/dist/schematic-components/SimplePowerSource.js.map +1 -1
- package/dist/schematic-components/SimpleResistor.d.ts +13 -0
- package/dist/schematic-components/SimpleResistor.js +3080 -13
- package/dist/schematic-components/SimpleResistor.js.map +1 -1
- package/dist/schematic-components/index.d.ts +18 -0
- package/dist/schematic-components/index.js +1175 -137
- package/dist/schematic-components/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/pages/led-circuit.tsx +8 -1
- package/tsconfig.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as useMaybePromise } from './use-maybe-promise.js';
|
|
@@ -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,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 };
|