@tscircuit/schematic-viewer 0.0.2 → 0.0.4
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/index.d.ts +6 -1
- package/dist/index.js +35176 -5772
- package/dist/index.js.map +1 -1
- package/package.json +3 -5
- package/src/pages/led-circuit.tsx +8 -1
- package/tsconfig.json +2 -1
- package/dist/Schematic.d.ts +0 -6
- package/dist/Schematic.js +0 -8609
- package/dist/Schematic.js.map +0 -1
- package/dist/lib/hooks/index.d.ts +0 -1
- package/dist/lib/hooks/index.js +0 -2170
- package/dist/lib/hooks/index.js.map +0 -1
- package/dist/lib/hooks/use-maybe-promise.d.ts +0 -3
- package/dist/lib/hooks/use-maybe-promise.js +0 -2170
- package/dist/lib/hooks/use-maybe-promise.js.map +0 -1
- package/dist/lib/render-context/index.d.ts +0 -10
- package/dist/lib/render-context/index.js +0 -45
- package/dist/lib/render-context/index.js.map +0 -1
- package/dist/lib/types/core.d.ts +0 -149
- package/dist/lib/types/core.js +0 -18
- package/dist/lib/types/core.js.map +0 -1
- package/dist/lib/types/index.d.ts +0 -4
- package/dist/lib/types/index.js +0 -18
- package/dist/lib/types/index.js.map +0 -1
- package/dist/lib/types/route-solver.d.ts +0 -24
- package/dist/lib/types/route-solver.js +0 -18
- package/dist/lib/types/route-solver.js.map +0 -1
- package/dist/lib/types/source-component.d.ts +0 -44
- package/dist/lib/types/source-component.js +0 -18
- package/dist/lib/types/source-component.js.map +0 -1
- package/dist/lib/types/util.d.ts +0 -14
- package/dist/lib/types/util.js +0 -18
- package/dist/lib/types/util.js.map +0 -1
- package/dist/lib/utils/direction-to-vec.d.ts +0 -13
- package/dist/lib/utils/direction-to-vec.js +0 -96
- package/dist/lib/utils/direction-to-vec.js.map +0 -1
- package/dist/lib/utils/get-svg-path-bounds.d.ts +0 -10
- package/dist/lib/utils/get-svg-path-bounds.js +0 -51
- package/dist/lib/utils/get-svg-path-bounds.js.map +0 -1
- package/dist/lib/utils/point-math.d.ts +0 -20
- package/dist/lib/utils/point-math.js +0 -57
- package/dist/lib/utils/point-math.js.map +0 -1
- package/dist/pages/_app.d.ts +0 -5
- package/dist/pages/_app.js +0 -2714
- package/dist/pages/_app.js.map +0 -1
- package/dist/pages/index.d.ts +0 -3
- package/dist/pages/index.js +0 -8615
- package/dist/pages/index.js.map +0 -1
- package/dist/pages/led-circuit-react.d.ts +0 -3
- package/dist/pages/led-circuit-react.js +0 -8640
- package/dist/pages/led-circuit-react.js.map +0 -1
- package/dist/pages/led-circuit.d.ts +0 -3
- package/dist/pages/led-circuit.js +0 -8659
- package/dist/pages/led-circuit.js.map +0 -1
- package/dist/schematic-components/MovableGrid/MovableGrid.stories.d.ts +0 -7
- package/dist/schematic-components/MovableGrid/MovableGrid.stories.js +0 -47
- package/dist/schematic-components/MovableGrid/MovableGrid.stories.js.map +0 -1
- package/dist/schematic-components/MovableGrid/index.d.ts +0 -3
- package/dist/schematic-components/MovableGrid/index.js +0 -34
- package/dist/schematic-components/MovableGrid/index.js.map +0 -1
- package/dist/schematic-components/ProjectComponent.d.ts +0 -10
- package/dist/schematic-components/ProjectComponent.js +0 -8584
- package/dist/schematic-components/ProjectComponent.js.map +0 -1
- package/dist/schematic-components/RenderError.d.ts +0 -6
- package/dist/schematic-components/RenderError.js +0 -40
- package/dist/schematic-components/RenderError.js.map +0 -1
- package/dist/schematic-components/SVGPathComponent.d.ts +0 -19
- package/dist/schematic-components/SVGPathComponent.js +0 -90
- package/dist/schematic-components/SVGPathComponent.js.map +0 -1
- package/dist/schematic-components/SchematicBug.d.ts +0 -13
- package/dist/schematic-components/SchematicBug.js +0 -468
- package/dist/schematic-components/SchematicBug.js.map +0 -1
- package/dist/schematic-components/SchematicComponent.d.ts +0 -13
- package/dist/schematic-components/SchematicComponent.js +0 -8451
- package/dist/schematic-components/SchematicComponent.js.map +0 -1
- package/dist/schematic-components/SchematicGroup.d.ts +0 -3
- package/dist/schematic-components/SchematicGroup.js +0 -32
- package/dist/schematic-components/SchematicGroup.js.map +0 -1
- package/dist/schematic-components/SchematicPort.d.ts +0 -13
- package/dist/schematic-components/SchematicPort.js +0 -8348
- package/dist/schematic-components/SchematicPort.js.map +0 -1
- package/dist/schematic-components/SchematicText.d.ts +0 -10
- package/dist/schematic-components/SchematicText.js +0 -71
- package/dist/schematic-components/SchematicText.js.map +0 -1
- package/dist/schematic-components/SchematicTrace.d.ts +0 -13
- package/dist/schematic-components/SchematicTrace.js +0 -137
- package/dist/schematic-components/SchematicTrace.js.map +0 -1
- package/dist/schematic-components/SimpleCapacitor.d.ts +0 -13
- package/dist/schematic-components/SimpleCapacitor.js +0 -103
- package/dist/schematic-components/SimpleCapacitor.js.map +0 -1
- package/dist/schematic-components/SimpleDiode.d.ts +0 -13
- package/dist/schematic-components/SimpleDiode.js +0 -101
- package/dist/schematic-components/SimpleDiode.js.map +0 -1
- package/dist/schematic-components/SimpleGround.d.ts +0 -13
- package/dist/schematic-components/SimpleGround.js +0 -102
- package/dist/schematic-components/SimpleGround.js.map +0 -1
- package/dist/schematic-components/SimpleInductor.d.ts +0 -13
- package/dist/schematic-components/SimpleInductor.js +0 -102
- package/dist/schematic-components/SimpleInductor.js.map +0 -1
- package/dist/schematic-components/SimplePowerSource.d.ts +0 -13
- package/dist/schematic-components/SimplePowerSource.js +0 -104
- package/dist/schematic-components/SimplePowerSource.js.map +0 -1
- package/dist/schematic-components/SimpleResistor.d.ts +0 -13
- package/dist/schematic-components/SimpleResistor.js +0 -102
- package/dist/schematic-components/SimpleResistor.js.map +0 -1
- package/dist/schematic-components/index.d.ts +0 -18
- package/dist/schematic-components/index.js +0 -8618
- package/dist/schematic-components/index.js.map +0 -1
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { SchematicText as SchematicText$1 } from '../lib/types/core.js';
|
|
2
|
-
import '../lib/types/source-component.js';
|
|
3
|
-
import '../lib/types/util.js';
|
|
4
|
-
|
|
5
|
-
interface Props {
|
|
6
|
-
schematic_text: SchematicText$1;
|
|
7
|
-
}
|
|
8
|
-
declare const SchematicText: ({ schematic_text }: Props) => JSX.Element;
|
|
9
|
-
|
|
10
|
-
export { SchematicText, SchematicText as default };
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
-
mod
|
|
22
|
-
));
|
|
23
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
-
|
|
25
|
-
// src/schematic-components/SchematicText.tsx
|
|
26
|
-
var SchematicText_exports = {};
|
|
27
|
-
__export(SchematicText_exports, {
|
|
28
|
-
SchematicText: () => SchematicText,
|
|
29
|
-
default: () => SchematicText_default
|
|
30
|
-
});
|
|
31
|
-
module.exports = __toCommonJS(SchematicText_exports);
|
|
32
|
-
|
|
33
|
-
// src/lib/render-context/index.ts
|
|
34
|
-
var import_zustand = __toESM(require("zustand"));
|
|
35
|
-
var import_transformation_matrix = require("transformation-matrix");
|
|
36
|
-
var useRenderContext = (0, import_zustand.default)()(
|
|
37
|
-
(set, get) => ({
|
|
38
|
-
camera_transform: (0, import_transformation_matrix.compose)((0, import_transformation_matrix.scale)(100, 100, 0, 0))
|
|
39
|
-
})
|
|
40
|
-
);
|
|
41
|
-
var useCameraTransform = () => useRenderContext((s) => s.camera_transform);
|
|
42
|
-
|
|
43
|
-
// src/schematic-components/SchematicText.tsx
|
|
44
|
-
var import_transformation_matrix2 = require("transformation-matrix");
|
|
45
|
-
var import_react_use_measure = __toESM(require("react-use-measure"));
|
|
46
|
-
var SchematicText = ({ schematic_text }) => {
|
|
47
|
-
const ct = useCameraTransform();
|
|
48
|
-
const { text, position, anchor } = schematic_text;
|
|
49
|
-
const tPos = (0, import_transformation_matrix2.applyToPoint)(ct, position);
|
|
50
|
-
const [boundsRef, bounds] = (0, import_react_use_measure.default)();
|
|
51
|
-
let offset = [0, 0];
|
|
52
|
-
if (anchor === "center") {
|
|
53
|
-
offset = [-bounds.width / 2, -bounds.height / 2];
|
|
54
|
-
} else if (anchor === "left") {
|
|
55
|
-
offset = [0, -bounds.height / 2];
|
|
56
|
-
} else if (anchor === "right") {
|
|
57
|
-
offset = [-bounds.width, -bounds.height / 2];
|
|
58
|
-
}
|
|
59
|
-
return <div ref={boundsRef} style={{
|
|
60
|
-
fontFamily: "'IBM Plex Mono', monospace",
|
|
61
|
-
position: "absolute",
|
|
62
|
-
left: tPos.x + offset[0],
|
|
63
|
-
top: tPos.y + offset[1]
|
|
64
|
-
}}>{text}</div>;
|
|
65
|
-
};
|
|
66
|
-
var SchematicText_default = SchematicText;
|
|
67
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
68
|
-
0 && (module.exports = {
|
|
69
|
-
SchematicText
|
|
70
|
-
});
|
|
71
|
-
//# sourceMappingURL=SchematicText.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/schematic-components/SchematicText.tsx","../../src/lib/render-context/index.ts"],"sourcesContent":["import * as Type from \"lib/types\"\nimport SVGPathComponent from \"./SVGPathComponent\"\nimport Path from \"svg-path-generator\"\nimport getSVGPathBounds from \"lib/utils/get-svg-path-bounds\"\nimport { useCameraTransform } from \"lib/render-context\"\nimport { applyToPoint } from \"transformation-matrix\"\nimport useMeasure from \"react-use-measure\"\n\ninterface Props {\n schematic_text: Type.SchematicText\n}\n\nexport const SchematicText = ({ schematic_text }: Props) => {\n const ct = useCameraTransform()\n const { text, position, anchor } = schematic_text\n const tPos = applyToPoint(ct, position)\n const [boundsRef, bounds] = useMeasure()\n let offset = [0, 0]\n if (anchor === \"center\") {\n offset = [-bounds.width / 2, -bounds.height / 2]\n } else if (anchor === \"left\") {\n offset = [0, -bounds.height / 2]\n } else if (anchor === \"right\") {\n offset = [-bounds.width, -bounds.height / 2]\n }\n return (\n <div\n ref={boundsRef}\n style={{\n fontFamily: \"'IBM Plex Mono', monospace\",\n position: \"absolute\",\n left: tPos.x + offset[0],\n top: tPos.y + offset[1],\n }}\n >\n {text}\n </div>\n )\n}\n\nexport default SchematicText\n","import createStore from \"zustand\"\nimport { Matrix, compose, scale } from \"transformation-matrix\"\n\ninterface RenderContextState {\n camera_transform: Matrix\n}\n\nexport const useRenderContext = createStore<RenderContextState>()(\n (set, get) => ({\n camera_transform: compose(scale(100, 100, 0, 0)),\n })\n)\n\nexport const useCameraTransform = () =>\n useRenderContext((s) => s.camera_transform)\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,qBAAwB;AACxB,mCAAuC;AAMhC,IAAM,uBAAmB,eAAAA,SAAgC;AAAA,EAC9D,CAAC,KAAK,SAAS;AAAA,IACb,sBAAkB,0CAAQ,oCAAM,KAAK,KAAK,GAAG,CAAC,CAAC;AAAA,EACjD;AACF;AAEO,IAAM,qBAAqB,MAChC,iBAAiB,CAAC,MAAM,EAAE,gBAAgB;;;ADT5C,IAAAC,gCAA6B;AAC7B,+BAAuB;AAMhB,IAAM,gBAAgB,CAAC,EAAE,eAAe,MAAa;AAC1D,QAAM,KAAK,mBAAmB;AAC9B,QAAM,EAAE,MAAM,UAAU,OAAO,IAAI;AACnC,QAAM,WAAO,4CAAa,IAAI,QAAQ;AACtC,QAAM,CAAC,WAAW,MAAM,QAAI,yBAAAC,SAAW;AACvC,MAAI,SAAS,CAAC,GAAG,CAAC;AAClB,MAAI,WAAW,UAAU;AACvB,aAAS,CAAC,CAAC,OAAO,QAAQ,GAAG,CAAC,OAAO,SAAS,CAAC;AAAA,EACjD,WAAW,WAAW,QAAQ;AAC5B,aAAS,CAAC,GAAG,CAAC,OAAO,SAAS,CAAC;AAAA,EACjC,WAAW,WAAW,SAAS;AAC7B,aAAS,CAAC,CAAC,OAAO,OAAO,CAAC,OAAO,SAAS,CAAC;AAAA,EAC7C;AACA,SACE,CAAC,IACC,KAAK,WACL,OAAO;AAAA,IACL,YAAY;AAAA,IACZ,UAAU;AAAA,IACV,MAAM,KAAK,IAAI,OAAO;AAAA,IACtB,KAAK,KAAK,IAAI,OAAO;AAAA,EACvB,IAEC,KACH,EAVC;AAYL;AAEA,IAAO,wBAAQ;","names":["createStore","import_transformation_matrix","useMeasure"]}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { SourceTrace, SchematicTrace as SchematicTrace$1 } from '../lib/types/core.js';
|
|
2
|
-
import '../lib/types/source-component.js';
|
|
3
|
-
import '../lib/types/util.js';
|
|
4
|
-
|
|
5
|
-
interface Props {
|
|
6
|
-
trace: {
|
|
7
|
-
source: SourceTrace;
|
|
8
|
-
schematic: SchematicTrace$1;
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
declare const SchematicTrace: ({ trace: { source, schematic } }: Props) => JSX.Element;
|
|
12
|
-
|
|
13
|
-
export { SchematicTrace, SchematicTrace as default };
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
-
mod
|
|
22
|
-
));
|
|
23
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
-
|
|
25
|
-
// src/schematic-components/SchematicTrace.tsx
|
|
26
|
-
var SchematicTrace_exports = {};
|
|
27
|
-
__export(SchematicTrace_exports, {
|
|
28
|
-
SchematicTrace: () => SchematicTrace,
|
|
29
|
-
default: () => SchematicTrace_default
|
|
30
|
-
});
|
|
31
|
-
module.exports = __toCommonJS(SchematicTrace_exports);
|
|
32
|
-
|
|
33
|
-
// src/lib/render-context/index.ts
|
|
34
|
-
var import_zustand = __toESM(require("zustand"));
|
|
35
|
-
var import_transformation_matrix = require("transformation-matrix");
|
|
36
|
-
var useRenderContext = (0, import_zustand.default)()(
|
|
37
|
-
(set, get) => ({
|
|
38
|
-
camera_transform: (0, import_transformation_matrix.compose)((0, import_transformation_matrix.scale)(100, 100, 0, 0))
|
|
39
|
-
})
|
|
40
|
-
);
|
|
41
|
-
var useCameraTransform = () => useRenderContext((s) => s.camera_transform);
|
|
42
|
-
|
|
43
|
-
// src/lib/utils/get-svg-path-bounds.ts
|
|
44
|
-
var import_svg_path_bounds = __toESM(require("svg-path-bounds"));
|
|
45
|
-
function getSVGPathBounds(ds) {
|
|
46
|
-
if (typeof ds === "string")
|
|
47
|
-
ds = [ds];
|
|
48
|
-
let minX = Infinity, maxX = -Infinity, minY = Infinity, maxY = -Infinity;
|
|
49
|
-
for (const d of ds) {
|
|
50
|
-
const [left, top, right, bottom] = (0, import_svg_path_bounds.default)(d);
|
|
51
|
-
minX = Math.min(left, minX);
|
|
52
|
-
maxX = Math.max(right, maxX);
|
|
53
|
-
minY = Math.min(top, minY);
|
|
54
|
-
maxY = Math.max(bottom, maxY);
|
|
55
|
-
}
|
|
56
|
-
return { minX, maxX, minY, maxY, width: maxX - minX, height: maxY - minY };
|
|
57
|
-
}
|
|
58
|
-
var get_svg_path_bounds_default = getSVGPathBounds;
|
|
59
|
-
|
|
60
|
-
// src/schematic-components/SVGPathComponent.tsx
|
|
61
|
-
var import_transformation_matrix2 = require("transformation-matrix");
|
|
62
|
-
var SVGPathComponent = ({ size, center, rotation, paths }) => {
|
|
63
|
-
const ct = useCameraTransform();
|
|
64
|
-
const pathBounds = get_svg_path_bounds_default(paths.map((p) => p.d));
|
|
65
|
-
const badRatio = Math.abs(pathBounds.width / pathBounds.height - size.width / size.height) > 0.01;
|
|
66
|
-
if (badRatio) {
|
|
67
|
-
console.warn(
|
|
68
|
-
`Ratio doesn't match for component. ${pathBounds.width}:${pathBounds.height} is not close to ${size.width}:${size.height}`
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
pathBounds.height = Math.max(pathBounds.height, 1);
|
|
72
|
-
pathBounds.width = Math.max(pathBounds.width, 1);
|
|
73
|
-
const absoluteCenter = (0, import_transformation_matrix2.applyToPoint)(ct, center);
|
|
74
|
-
const absoluteSize = {
|
|
75
|
-
width: Math.max(1, size.width * ct.a),
|
|
76
|
-
height: Math.max(1, size.height * ct.d)
|
|
77
|
-
};
|
|
78
|
-
return <svg style={{
|
|
79
|
-
position: "absolute",
|
|
80
|
-
transform: rotation === 0 ? "" : `rotate(${rotation}rad)`,
|
|
81
|
-
left: absoluteCenter.x - absoluteSize.width / 2,
|
|
82
|
-
top: absoluteCenter.y - absoluteSize.height / 2
|
|
83
|
-
}} overflow="visible" width={absoluteSize.width} height={absoluteSize.height} viewBox={`${pathBounds.minX} ${pathBounds.minY} ${pathBounds.width} ${pathBounds.height}`}>{paths.map((p, i) => <path key={i} fill="none" strokeWidth={2 * (p.strokeWidth || 1)} stroke={p.stroke || "red"} d={p.d} />)}</svg>;
|
|
84
|
-
};
|
|
85
|
-
var SVGPathComponent_default = SVGPathComponent;
|
|
86
|
-
|
|
87
|
-
// src/schematic-components/SchematicTrace.tsx
|
|
88
|
-
var import_svg_path_generator = __toESM(require("svg-path-generator"));
|
|
89
|
-
|
|
90
|
-
// src/schematic-components/RenderError.tsx
|
|
91
|
-
var RenderError_default = ({ text }) => {
|
|
92
|
-
return <div style={{
|
|
93
|
-
position: "fixed",
|
|
94
|
-
backgroundColor: "red",
|
|
95
|
-
color: "white",
|
|
96
|
-
fontSize: 14,
|
|
97
|
-
fontFamily: "sans-serif",
|
|
98
|
-
padding: 5,
|
|
99
|
-
right: 0,
|
|
100
|
-
top: 0,
|
|
101
|
-
opacity: 0.75
|
|
102
|
-
}}>{text}</div>;
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
// src/schematic-components/SchematicTrace.tsx
|
|
106
|
-
var SchematicTrace = ({ trace: { source, schematic } }) => {
|
|
107
|
-
const edges = schematic.edges;
|
|
108
|
-
if (edges.length === 0) {
|
|
109
|
-
return <RenderError_default text="Route with 0 edges" />;
|
|
110
|
-
}
|
|
111
|
-
const path = (0, import_svg_path_generator.default)();
|
|
112
|
-
for (let i = 0; i < edges.length; i++) {
|
|
113
|
-
path.moveTo(edges[i].from.x, edges[i].from.y);
|
|
114
|
-
path.lineTo(edges[i].to.x, edges[i].to.y);
|
|
115
|
-
}
|
|
116
|
-
const d = path.toString();
|
|
117
|
-
const pathBounds = get_svg_path_bounds_default(d);
|
|
118
|
-
pathBounds.height = Math.max(pathBounds.height, 1);
|
|
119
|
-
pathBounds.width = Math.max(pathBounds.width, 1);
|
|
120
|
-
const center = {
|
|
121
|
-
x: pathBounds.minX + pathBounds.width / 2,
|
|
122
|
-
y: pathBounds.minY + pathBounds.height / 2
|
|
123
|
-
};
|
|
124
|
-
return <SVGPathComponent_default rotation={0} center={center} size={pathBounds} paths={[
|
|
125
|
-
{
|
|
126
|
-
stroke: "green",
|
|
127
|
-
strokeWidth: 0.02,
|
|
128
|
-
d
|
|
129
|
-
}
|
|
130
|
-
]} />;
|
|
131
|
-
};
|
|
132
|
-
var SchematicTrace_default = SchematicTrace;
|
|
133
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
134
|
-
0 && (module.exports = {
|
|
135
|
-
SchematicTrace
|
|
136
|
-
});
|
|
137
|
-
//# sourceMappingURL=SchematicTrace.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/schematic-components/SchematicTrace.tsx","../../src/lib/render-context/index.ts","../../src/lib/utils/get-svg-path-bounds.ts","../../src/schematic-components/SVGPathComponent.tsx","../../src/schematic-components/RenderError.tsx"],"sourcesContent":["import * as Type from \"lib/types\"\nimport SVGPathComponent from \"./SVGPathComponent\"\nimport Path from \"svg-path-generator\"\nimport getSVGPathBounds from \"lib/utils/get-svg-path-bounds\"\nimport RenderError from \"./RenderError\"\n\ninterface Props {\n trace: {\n source: Type.SourceTrace\n schematic: Type.SchematicTrace\n }\n}\n\nexport const SchematicTrace = ({ trace: { source, schematic } }: Props) => {\n const edges = schematic.edges\n if (edges.length === 0) {\n return <RenderError text=\"Route with 0 edges\" />\n }\n const path = Path()\n for (let i = 0; i < edges.length; i++) {\n path.moveTo(edges[i].from.x, edges[i].from.y)\n path.lineTo(edges[i].to.x, edges[i].to.y)\n }\n const d = path.toString()\n const pathBounds = getSVGPathBounds(d)\n pathBounds.height = Math.max(pathBounds.height, 1)\n pathBounds.width = Math.max(pathBounds.width, 1)\n const center = {\n x: pathBounds.minX + pathBounds.width / 2,\n y: pathBounds.minY + pathBounds.height / 2,\n }\n return (\n <SVGPathComponent\n rotation={0}\n center={center}\n size={pathBounds}\n paths={[\n {\n stroke: \"green\",\n strokeWidth: 0.02,\n d,\n },\n ]}\n />\n )\n}\n\nexport default SchematicTrace\n","import createStore from \"zustand\"\nimport { Matrix, compose, scale } from \"transformation-matrix\"\n\ninterface RenderContextState {\n camera_transform: Matrix\n}\n\nexport const useRenderContext = createStore<RenderContextState>()(\n (set, get) => ({\n camera_transform: compose(scale(100, 100, 0, 0)),\n })\n)\n\nexport const useCameraTransform = () =>\n useRenderContext((s) => s.camera_transform)\n","import svgPathBounds from \"svg-path-bounds\"\n\nexport function getSVGPathBounds(ds: string[] | string) {\n if (typeof ds === \"string\") ds = [ds]\n let minX = Infinity,\n maxX = -Infinity,\n minY = Infinity,\n maxY = -Infinity\n\n for (const d of ds) {\n const [left, top, right, bottom] = svgPathBounds(d)\n\n minX = Math.min(left, minX)\n maxX = Math.max(right, maxX)\n minY = Math.min(top, minY)\n maxY = Math.max(bottom, maxY)\n }\n\n return { minX, maxX, minY, maxY, width: maxX - minX, height: maxY - minY }\n}\n\nexport default getSVGPathBounds\n","import { useCameraTransform } from \"lib/render-context\"\nimport getSVGPathBounds from \"lib/utils/get-svg-path-bounds\"\n\nimport { applyToPoint } from \"transformation-matrix\"\n\ninterface Props {\n rotation: number\n center: { x: number; y: number }\n size: { width: number; height: number }\n paths: Array<{\n strokeWidth: number\n stroke: string\n d: string\n }>\n}\n\nexport const SVGPathComponent = ({ size, center, rotation, paths }: Props) => {\n const ct = useCameraTransform()\n const pathBounds = getSVGPathBounds(paths.map((p) => p.d))\n // Margin in SVG Space\n const badRatio =\n Math.abs(pathBounds.width / pathBounds.height - size.width / size.height) >\n 0.01\n if (badRatio) {\n console.warn(\n `Ratio doesn't match for component. ${pathBounds.width}:${pathBounds.height} is not close to ${size.width}:${size.height}`\n )\n }\n pathBounds.height = Math.max(pathBounds.height, 1)\n pathBounds.width = Math.max(pathBounds.width, 1)\n const absoluteCenter = applyToPoint(ct, center)\n const absoluteSize = {\n width: Math.max(1, size.width * ct.a),\n height: Math.max(1, size.height * ct.d),\n }\n\n return (\n <svg\n style={{\n position: \"absolute\",\n transform: rotation === 0 ? \"\" : `rotate(${rotation}rad)`,\n left: absoluteCenter.x - absoluteSize.width / 2,\n top: absoluteCenter.y - absoluteSize.height / 2,\n // backgroundColor: badRatio ? \"rgba(255, 0, 0, 0.5)\" : \"transparent\",\n }}\n overflow=\"visible\"\n width={absoluteSize.width}\n height={absoluteSize.height}\n viewBox={`${pathBounds.minX} ${pathBounds.minY} ${pathBounds.width} ${pathBounds.height}`}\n >\n {paths.map((p, i) => (\n <path\n key={i}\n fill=\"none\"\n strokeWidth={2 * (p.strokeWidth || 1)}\n stroke={p.stroke || \"red\"}\n d={p.d}\n />\n ))}\n </svg>\n )\n}\n\nexport default SVGPathComponent\n","interface Props {\n text: string\n}\n\nexport default ({ text }: Props) => {\n return (\n <div\n style={{\n position: \"fixed\",\n backgroundColor: \"red\",\n color: \"white\",\n fontSize: 14,\n fontFamily: \"sans-serif\",\n padding: 5,\n right: 0,\n top: 0,\n opacity: 0.75,\n }}\n >\n {text}\n </div>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,qBAAwB;AACxB,mCAAuC;AAMhC,IAAM,uBAAmB,eAAAA,SAAgC;AAAA,EAC9D,CAAC,KAAK,SAAS;AAAA,I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,GAAG,GAAG,CAAC;AAAA,EAC1C;AACA,QAAM,IAAI,KAAK,SAAS;AACxB,QAAM,aAAa,4BAAiB,CAAC;AACrC,aAAW,SAAS,KAAK,IAAI,WAAW,QAAQ,CAAC;AACjD,aAAW,QAAQ,KAAK,IAAI,WAAW,OAAO,CAAC;AAC/C,QAAM,SAAS;AAAA,IACb,GAAG,WAAW,OAAO,WAAW,QAAQ;AAAA,IACxC,GAAG,WAAW,OAAO,WAAW,SAAS;AAAA,EAC3C;AACA,SACE,CAAC,yBACC,UAAU,GACV,QAAQ,QACR,MAAM,YACN,OAAO;AAAA,IACL;AAAA,MACE,QAAQ;AAAA,MACR,aAAa;AAAA,MACb;AAAA,IACF;AAAA,EACF,GACF;AAEJ;AAEA,IAAO,yBAAQ;","names":["createStore","svgPathBounds","import_transformation_matrix","Path"]}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { SchematicComponent } from '../lib/types/core.js';
|
|
2
|
-
import { SimpleCapacitor as SimpleCapacitor$1 } from '../lib/types/source-component.js';
|
|
3
|
-
import '../lib/types/util.js';
|
|
4
|
-
|
|
5
|
-
interface Props {
|
|
6
|
-
component: {
|
|
7
|
-
source: SimpleCapacitor$1;
|
|
8
|
-
schematic: SchematicComponent;
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
declare const SimpleCapacitor: ({ component: { source, schematic }, }: Props) => JSX.Element;
|
|
12
|
-
|
|
13
|
-
export { SimpleCapacitor, SimpleCapacitor as default };
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
-
mod
|
|
22
|
-
));
|
|
23
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
-
|
|
25
|
-
// src/schematic-components/SimpleCapacitor.tsx
|
|
26
|
-
var SimpleCapacitor_exports = {};
|
|
27
|
-
__export(SimpleCapacitor_exports, {
|
|
28
|
-
SimpleCapacitor: () => SimpleCapacitor,
|
|
29
|
-
default: () => SimpleCapacitor_default
|
|
30
|
-
});
|
|
31
|
-
module.exports = __toCommonJS(SimpleCapacitor_exports);
|
|
32
|
-
|
|
33
|
-
// src/lib/render-context/index.ts
|
|
34
|
-
var import_zustand = __toESM(require("zustand"));
|
|
35
|
-
var import_transformation_matrix = require("transformation-matrix");
|
|
36
|
-
var useRenderContext = (0, import_zustand.default)()(
|
|
37
|
-
(set, get) => ({
|
|
38
|
-
camera_transform: (0, import_transformation_matrix.compose)((0, import_transformation_matrix.scale)(100, 100, 0, 0))
|
|
39
|
-
})
|
|
40
|
-
);
|
|
41
|
-
var useCameraTransform = () => useRenderContext((s) => s.camera_transform);
|
|
42
|
-
|
|
43
|
-
// src/lib/utils/get-svg-path-bounds.ts
|
|
44
|
-
var import_svg_path_bounds = __toESM(require("svg-path-bounds"));
|
|
45
|
-
function getSVGPathBounds(ds) {
|
|
46
|
-
if (typeof ds === "string")
|
|
47
|
-
ds = [ds];
|
|
48
|
-
let minX = Infinity, maxX = -Infinity, minY = Infinity, maxY = -Infinity;
|
|
49
|
-
for (const d of ds) {
|
|
50
|
-
const [left, top, right, bottom] = (0, import_svg_path_bounds.default)(d);
|
|
51
|
-
minX = Math.min(left, minX);
|
|
52
|
-
maxX = Math.max(right, maxX);
|
|
53
|
-
minY = Math.min(top, minY);
|
|
54
|
-
maxY = Math.max(bottom, maxY);
|
|
55
|
-
}
|
|
56
|
-
return { minX, maxX, minY, maxY, width: maxX - minX, height: maxY - minY };
|
|
57
|
-
}
|
|
58
|
-
var get_svg_path_bounds_default = getSVGPathBounds;
|
|
59
|
-
|
|
60
|
-
// src/schematic-components/SVGPathComponent.tsx
|
|
61
|
-
var import_transformation_matrix2 = require("transformation-matrix");
|
|
62
|
-
var SVGPathComponent = ({ size, center, rotation, paths }) => {
|
|
63
|
-
const ct = useCameraTransform();
|
|
64
|
-
const pathBounds = get_svg_path_bounds_default(paths.map((p) => p.d));
|
|
65
|
-
const badRatio = Math.abs(pathBounds.width / pathBounds.height - size.width / size.height) > 0.01;
|
|
66
|
-
if (badRatio) {
|
|
67
|
-
console.warn(
|
|
68
|
-
`Ratio doesn't match for component. ${pathBounds.width}:${pathBounds.height} is not close to ${size.width}:${size.height}`
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
pathBounds.height = Math.max(pathBounds.height, 1);
|
|
72
|
-
pathBounds.width = Math.max(pathBounds.width, 1);
|
|
73
|
-
const absoluteCenter = (0, import_transformation_matrix2.applyToPoint)(ct, center);
|
|
74
|
-
const absoluteSize = {
|
|
75
|
-
width: Math.max(1, size.width * ct.a),
|
|
76
|
-
height: Math.max(1, size.height * ct.d)
|
|
77
|
-
};
|
|
78
|
-
return <svg style={{
|
|
79
|
-
position: "absolute",
|
|
80
|
-
transform: rotation === 0 ? "" : `rotate(${rotation}rad)`,
|
|
81
|
-
left: absoluteCenter.x - absoluteSize.width / 2,
|
|
82
|
-
top: absoluteCenter.y - absoluteSize.height / 2
|
|
83
|
-
}} overflow="visible" width={absoluteSize.width} height={absoluteSize.height} viewBox={`${pathBounds.minX} ${pathBounds.minY} ${pathBounds.width} ${pathBounds.height}`}>{paths.map((p, i) => <path key={i} fill="none" strokeWidth={2 * (p.strokeWidth || 1)} stroke={p.stroke || "red"} d={p.d} />)}</svg>;
|
|
84
|
-
};
|
|
85
|
-
var SVGPathComponent_default = SVGPathComponent;
|
|
86
|
-
|
|
87
|
-
// src/schematic-components/SimpleCapacitor.tsx
|
|
88
|
-
var SimpleCapacitor = ({
|
|
89
|
-
component: { source, schematic }
|
|
90
|
-
}) => {
|
|
91
|
-
return <SVGPathComponent_default rotation={schematic.rotation} center={schematic.center} size={schematic.size} paths={[
|
|
92
|
-
{ stroke: "red", strokeWidth: 1, d: "M 0 15 l 12 0" },
|
|
93
|
-
{ stroke: "red", strokeWidth: 2, d: "M 12 0 l 0 30" },
|
|
94
|
-
{ stroke: "red", strokeWidth: 2, d: "M 18 0 l 0 30" },
|
|
95
|
-
{ stroke: "red", strokeWidth: 1, d: "M 18 15 l 12 0" }
|
|
96
|
-
]} />;
|
|
97
|
-
};
|
|
98
|
-
var SimpleCapacitor_default = SimpleCapacitor;
|
|
99
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
100
|
-
0 && (module.exports = {
|
|
101
|
-
SimpleCapacitor
|
|
102
|
-
});
|
|
103
|
-
//# sourceMappingURL=SimpleCapacitor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/schematic-components/SimpleCapacitor.tsx","../../src/lib/render-context/index.ts","../../src/lib/utils/get-svg-path-bounds.ts","../../src/schematic-components/SVGPathComponent.tsx"],"sourcesContent":["import * as Type from \"lib/types\"\nimport SVGPathComponent from \"./SVGPathComponent\"\n\ninterface Props {\n component: {\n source: Type.SimpleCapacitor\n schematic: Type.SchematicComponent\n }\n}\n\nexport const SimpleCapacitor = ({\n component: { source, schematic },\n}: Props) => {\n return (\n <SVGPathComponent\n rotation={schematic.rotation}\n center={schematic.center}\n size={schematic.size}\n paths={[\n { stroke: \"red\", strokeWidth: 1, d: \"M 0 15 l 12 0\" },\n { stroke: \"red\", strokeWidth: 2, d: \"M 12 0 l 0 30\" },\n { stroke: \"red\", strokeWidth: 2, d: \"M 18 0 l 0 30\" },\n { stroke: \"red\", strokeWidth: 1, d: \"M 18 15 l 12 0\" },\n ]}\n />\n )\n}\n\nexport default SimpleCapacitor\n","import createStore from \"zustand\"\nimport { Matrix, compose, scale } from \"transformation-matrix\"\n\ninterface RenderContextState {\n camera_transform: Matrix\n}\n\nexport const useRenderContext = createStore<RenderContextState>()(\n (set, get) => ({\n camera_transform: compose(scale(100, 100, 0, 0)),\n })\n)\n\nexport const useCameraTransform = () =>\n useRenderContext((s) => s.camera_transform)\n","import svgPathBounds from \"svg-path-bounds\"\n\nexport function getSVGPathBounds(ds: string[] | string) {\n if (typeof ds === \"string\") ds = [ds]\n let minX = Infinity,\n maxX = -Infinity,\n minY = Infinity,\n maxY = -Infinity\n\n for (const d of ds) {\n const [left, top, right, bottom] = svgPathBounds(d)\n\n minX = Math.min(left, minX)\n maxX = Math.max(right, maxX)\n minY = Math.min(top, minY)\n maxY = Math.max(bottom, maxY)\n }\n\n return { minX, maxX, minY, maxY, width: maxX - minX, height: maxY - minY }\n}\n\nexport default getSVGPathBounds\n","import { useCameraTransform } from \"lib/render-context\"\nimport getSVGPathBounds from \"lib/utils/get-svg-path-bounds\"\n\nimport { applyToPoint } from \"transformation-matrix\"\n\ninterface Props {\n rotation: number\n center: { x: number; y: number }\n size: { width: number; height: number }\n paths: Array<{\n strokeWidth: number\n stroke: string\n d: string\n }>\n}\n\nexport const SVGPathComponent = ({ size, center, rotation, paths }: Props) => {\n const ct = useCameraTransform()\n const pathBounds = getSVGPathBounds(paths.map((p) => p.d))\n // Margin in SVG Space\n const badRatio =\n Math.abs(pathBounds.width / pathBounds.height - size.width / size.height) >\n 0.01\n if (badRatio) {\n console.warn(\n `Ratio doesn't match for component. ${pathBounds.width}:${pathBounds.height} is not close to ${size.width}:${size.height}`\n )\n }\n pathBounds.height = Math.max(pathBounds.height, 1)\n pathBounds.width = Math.max(pathBounds.width, 1)\n const absoluteCenter = applyToPoint(ct, center)\n const absoluteSize = {\n width: Math.max(1, size.width * ct.a),\n height: Math.max(1, size.height * ct.d),\n }\n\n return (\n <svg\n style={{\n position: \"absolute\",\n transform: rotation === 0 ? \"\" : `rotate(${rotation}rad)`,\n left: absoluteCenter.x - absoluteSize.width / 2,\n top: absoluteCenter.y - absoluteSize.height / 2,\n // backgroundColor: badRatio ? \"rgba(255, 0, 0, 0.5)\" : \"transparent\",\n }}\n overflow=\"visible\"\n width={absoluteSize.width}\n height={absoluteSize.height}\n viewBox={`${pathBounds.minX} ${pathBounds.minY} ${pathBounds.width} ${pathBounds.height}`}\n >\n {paths.map((p, i) => (\n <path\n key={i}\n fill=\"none\"\n strokeWidth={2 * (p.strokeWidth || 1)}\n stroke={p.stroke || \"red\"}\n d={p.d}\n />\n ))}\n </svg>\n )\n}\n\nexport default SVGPathComponent\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,qBAAwB;AACxB,mCAAuC;AAMhC,IAAM,uBAAmB,eAAAA,SAAgC;AAAA,EAC9D,CAAC,KAAK,SAAS;AAAA,IACb,sBAAkB,0CAAQ,oCAAM,KAAK,KAAK,GAAG,CAAC,CAAC;AAAA,EACjD;AACF;AAEO,IAAM,qBAAqB,MAChC,iBAAiB,CAAC,MAAM,EAAE,gBAAgB;;;ACd5C,6BAA0B;AAEnB,SAAS,iBAAiB,IAAuB;AACtD,MAAI,OAAO,OAAO;AAAU,SAAK,CAAC,EAAE;AACpC,MAAI,OAAO,UACT,OAAO,WACP,OAAO,UACP,OAAO;AAET,aAAW,KAAK,IAAI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a,OACpB,QAAQ,aAAa,QACrB,SAAS,GAAG,WAAW,QAAQ,WAAW,QAAQ,WAAW,SAAS,WAAW,WAEhF,MAAM,IAAI,CAAC,GAAG,MACb,CAAC,KACC,KAAK,GACL,KAAK,OACL,aAAa,KAAK,EAAE,eAAe,IACnC,QAAQ,EAAE,UAAU,OACpB,GAAG,EAAE,GACP,EACD,EACH,EAtBC;AAwBL;AAEA,IAAO,2BAAQ;;;AHrDR,IAAM,kBAAkB,CAAC;AAAA,EAC9B,WAAW,EAAE,QAAQ,UAAU;AACjC,MAAa;AACX,SACE,CAAC,yBACC,UAAU,UAAU,UACpB,QAAQ,UAAU,QAClB,MAAM,UAAU,MAChB,OAAO;AAAA,IACL,EAAE,QAAQ,OAAO,aAAa,GAAG,GAAG,gBAAgB;AAAA,IACpD,EAAE,QAAQ,OAAO,aAAa,GAAG,GAAG,gBAAgB;AAAA,IACpD,EAAE,QAAQ,OAAO,aAAa,GAAG,GAAG,gBAAgB;AAAA,IACpD,EAAE,QAAQ,OAAO,aAAa,GAAG,GAAG,iBAAiB;AAAA,EACvD,GACF;AAEJ;AAEA,IAAO,0BAAQ;","names":["createStore","svgPathBounds","import_transformation_matrix"]}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { SchematicComponent } from '../lib/types/core.js';
|
|
2
|
-
import { SimpleDiode as SimpleDiode$1 } from '../lib/types/source-component.js';
|
|
3
|
-
import '../lib/types/util.js';
|
|
4
|
-
|
|
5
|
-
interface Props {
|
|
6
|
-
component: {
|
|
7
|
-
source: SimpleDiode$1;
|
|
8
|
-
schematic: SchematicComponent;
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
declare const SimpleDiode: ({ component: { source, schematic } }: Props) => JSX.Element;
|
|
12
|
-
|
|
13
|
-
export { SimpleDiode, SimpleDiode as default };
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
-
mod
|
|
22
|
-
));
|
|
23
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
-
|
|
25
|
-
// src/schematic-components/SimpleDiode.tsx
|
|
26
|
-
var SimpleDiode_exports = {};
|
|
27
|
-
__export(SimpleDiode_exports, {
|
|
28
|
-
SimpleDiode: () => SimpleDiode,
|
|
29
|
-
default: () => SimpleDiode_default
|
|
30
|
-
});
|
|
31
|
-
module.exports = __toCommonJS(SimpleDiode_exports);
|
|
32
|
-
|
|
33
|
-
// src/lib/render-context/index.ts
|
|
34
|
-
var import_zustand = __toESM(require("zustand"));
|
|
35
|
-
var import_transformation_matrix = require("transformation-matrix");
|
|
36
|
-
var useRenderContext = (0, import_zustand.default)()(
|
|
37
|
-
(set, get) => ({
|
|
38
|
-
camera_transform: (0, import_transformation_matrix.compose)((0, import_transformation_matrix.scale)(100, 100, 0, 0))
|
|
39
|
-
})
|
|
40
|
-
);
|
|
41
|
-
var useCameraTransform = () => useRenderContext((s) => s.camera_transform);
|
|
42
|
-
|
|
43
|
-
// src/lib/utils/get-svg-path-bounds.ts
|
|
44
|
-
var import_svg_path_bounds = __toESM(require("svg-path-bounds"));
|
|
45
|
-
function getSVGPathBounds(ds) {
|
|
46
|
-
if (typeof ds === "string")
|
|
47
|
-
ds = [ds];
|
|
48
|
-
let minX = Infinity, maxX = -Infinity, minY = Infinity, maxY = -Infinity;
|
|
49
|
-
for (const d of ds) {
|
|
50
|
-
const [left, top, right, bottom] = (0, import_svg_path_bounds.default)(d);
|
|
51
|
-
minX = Math.min(left, minX);
|
|
52
|
-
maxX = Math.max(right, maxX);
|
|
53
|
-
minY = Math.min(top, minY);
|
|
54
|
-
maxY = Math.max(bottom, maxY);
|
|
55
|
-
}
|
|
56
|
-
return { minX, maxX, minY, maxY, width: maxX - minX, height: maxY - minY };
|
|
57
|
-
}
|
|
58
|
-
var get_svg_path_bounds_default = getSVGPathBounds;
|
|
59
|
-
|
|
60
|
-
// src/schematic-components/SVGPathComponent.tsx
|
|
61
|
-
var import_transformation_matrix2 = require("transformation-matrix");
|
|
62
|
-
var SVGPathComponent = ({ size, center, rotation, paths }) => {
|
|
63
|
-
const ct = useCameraTransform();
|
|
64
|
-
const pathBounds = get_svg_path_bounds_default(paths.map((p) => p.d));
|
|
65
|
-
const badRatio = Math.abs(pathBounds.width / pathBounds.height - size.width / size.height) > 0.01;
|
|
66
|
-
if (badRatio) {
|
|
67
|
-
console.warn(
|
|
68
|
-
`Ratio doesn't match for component. ${pathBounds.width}:${pathBounds.height} is not close to ${size.width}:${size.height}`
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
pathBounds.height = Math.max(pathBounds.height, 1);
|
|
72
|
-
pathBounds.width = Math.max(pathBounds.width, 1);
|
|
73
|
-
const absoluteCenter = (0, import_transformation_matrix2.applyToPoint)(ct, center);
|
|
74
|
-
const absoluteSize = {
|
|
75
|
-
width: Math.max(1, size.width * ct.a),
|
|
76
|
-
height: Math.max(1, size.height * ct.d)
|
|
77
|
-
};
|
|
78
|
-
return <svg style={{
|
|
79
|
-
position: "absolute",
|
|
80
|
-
transform: rotation === 0 ? "" : `rotate(${rotation}rad)`,
|
|
81
|
-
left: absoluteCenter.x - absoluteSize.width / 2,
|
|
82
|
-
top: absoluteCenter.y - absoluteSize.height / 2
|
|
83
|
-
}} overflow="visible" width={absoluteSize.width} height={absoluteSize.height} viewBox={`${pathBounds.minX} ${pathBounds.minY} ${pathBounds.width} ${pathBounds.height}`}>{paths.map((p, i) => <path key={i} fill="none" strokeWidth={2 * (p.strokeWidth || 1)} stroke={p.stroke || "red"} d={p.d} />)}</svg>;
|
|
84
|
-
};
|
|
85
|
-
var SVGPathComponent_default = SVGPathComponent;
|
|
86
|
-
|
|
87
|
-
// src/schematic-components/SimpleDiode.tsx
|
|
88
|
-
var SimpleDiode = ({ component: { source, schematic } }) => {
|
|
89
|
-
return <SVGPathComponent_default rotation={schematic.rotation} center={schematic.center} size={schematic.size} paths={[
|
|
90
|
-
{ stroke: "red", strokeWidth: 2, d: "M 0,0 H 21" },
|
|
91
|
-
{ stroke: "red", strokeWidth: 2, d: "M 49,0 H 59" },
|
|
92
|
-
{ stroke: "red", strokeWidth: 2, d: "M 49,0 L 21 14 V -14 Z" },
|
|
93
|
-
{ stroke: "red", strokeWidth: 2, d: "M 49,-14 V 14" }
|
|
94
|
-
]} />;
|
|
95
|
-
};
|
|
96
|
-
var SimpleDiode_default = SimpleDiode;
|
|
97
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
98
|
-
0 && (module.exports = {
|
|
99
|
-
SimpleDiode
|
|
100
|
-
});
|
|
101
|
-
//# sourceMappingURL=SimpleDiode.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/schematic-components/SimpleDiode.tsx","../../src/lib/render-context/index.ts","../../src/lib/utils/get-svg-path-bounds.ts","../../src/schematic-components/SVGPathComponent.tsx"],"sourcesContent":["import * as Type from \"lib/types\"\nimport SVGPathComponent from \"./SVGPathComponent\"\n\ninterface Props {\n component: {\n source: Type.SimpleDiode\n schematic: Type.SchematicComponent\n }\n}\n\nexport const SimpleDiode = ({ component: { source, schematic } }: Props) => {\n return (\n <SVGPathComponent\n rotation={schematic.rotation}\n center={schematic.center}\n size={schematic.size}\n paths={[\n { stroke: \"red\", strokeWidth: 2, d: \"M 0,0 H 21\" },\n { stroke: \"red\", strokeWidth: 2, d: \"M 49,0 H 59\" },\n { stroke: \"red\", strokeWidth: 2, d: \"M 49,0 L 21 14 V -14 Z\" },\n { stroke: \"red\", strokeWidth: 2, d: \"M 49,-14 V 14\" },\n // For LEDs\n // {\n // stroke: \"red\",\n // strokeWidth: 2,\n // d: \"M 35 -32 l 7 5.25 l 1.75 -9.625 z m 3.5 2.625 l -5.25 7\",\n // },\n // {\n // stroke: \"red\",\n // strokeWidth: 2,\n // d: \"M 52 -26 l 7 5.25 l 1.75 -9.625 z m 3.5 2.625 l -5.25 7\",\n // },\n ]}\n />\n )\n}\n\nexport default SimpleDiode\n","import createStore from \"zustand\"\nimport { Matrix, compose, scale } from \"transformation-matrix\"\n\ninterface RenderContextState {\n camera_transform: Matrix\n}\n\nexport const useRenderContext = createStore<RenderContextState>()(\n (set, get) => ({\n camera_transform: compose(scale(100, 100, 0, 0)),\n })\n)\n\nexport const useCameraTransform = () =>\n useRenderContext((s) => s.camera_transform)\n","import svgPathBounds from \"svg-path-bounds\"\n\nexport function getSVGPathBounds(ds: string[] | string) {\n if (typeof ds === \"string\") ds = [ds]\n let minX = Infinity,\n maxX = -Infinity,\n minY = Infinity,\n maxY = -Infinity\n\n for (const d of ds) {\n const [left, top, right, bottom] = svgPathBounds(d)\n\n minX = Math.min(left, minX)\n maxX = Math.max(right, maxX)\n minY = Math.min(top, minY)\n maxY = Math.max(bottom, maxY)\n }\n\n return { minX, maxX, minY, maxY, width: maxX - minX, height: maxY - minY }\n}\n\nexport default getSVGPathBounds\n","import { useCameraTransform } from \"lib/render-context\"\nimport getSVGPathBounds from \"lib/utils/get-svg-path-bounds\"\n\nimport { applyToPoint } from \"transformation-matrix\"\n\ninterface Props {\n rotation: number\n center: { x: number; y: number }\n size: { width: number; height: number }\n paths: Array<{\n strokeWidth: number\n stroke: string\n d: string\n }>\n}\n\nexport const SVGPathComponent = ({ size, center, rotation, paths }: Props) => {\n const ct = useCameraTransform()\n const pathBounds = getSVGPathBounds(paths.map((p) => p.d))\n // Margin in SVG Space\n const badRatio =\n Math.abs(pathBounds.width / pathBounds.height - size.width / size.height) >\n 0.01\n if (badRatio) {\n console.warn(\n `Ratio doesn't match for component. ${pathBounds.width}:${pathBounds.height} is not close to ${size.width}:${size.height}`\n )\n }\n pathBounds.height = Math.max(pathBounds.height, 1)\n pathBounds.width = Math.max(pathBounds.width, 1)\n const absoluteCenter = applyToPoint(ct, center)\n const absoluteSize = {\n width: Math.max(1, size.width * ct.a),\n height: Math.max(1, size.height * ct.d),\n }\n\n return (\n <svg\n style={{\n position: \"absolute\",\n transform: rotation === 0 ? \"\" : `rotate(${rotation}rad)`,\n left: absoluteCenter.x - absoluteSize.width / 2,\n top: absoluteCenter.y - absoluteSize.height / 2,\n // backgroundColor: badRatio ? \"rgba(255, 0, 0, 0.5)\" : \"transparent\",\n }}\n overflow=\"visible\"\n width={absoluteSize.width}\n height={absoluteSize.height}\n viewBox={`${pathBounds.minX} ${pathBounds.minY} ${pathBounds.width} ${pathBounds.height}`}\n >\n {paths.map((p, i) => (\n <path\n key={i}\n fill=\"none\"\n strokeWidth={2 * (p.strokeWidth || 1)}\n stroke={p.stroke || \"red\"}\n d={p.d}\n />\n ))}\n </svg>\n )\n}\n\nexport default SVGPathComponent\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,qBAAwB;AACxB,mCAAuC;AAMhC,IAAM,uBAAm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QAAM,eAAe;AAAA,IACnB,OAAO,KAAK,IAAI,GAAG,KAAK,QAAQ,GAAG,CAAC;AAAA,IACpC,QAAQ,KAAK,IAAI,GAAG,KAAK,SAAS,GAAG,CAAC;AAAA,EACxC;AAEA,SACE,CAAC,IACC,OAAO;AAAA,IACL,UAAU;AAAA,IACV,WAAW,aAAa,IAAI,KAAK,UAAU;AAAA,IAC3C,MAAM,eAAe,IAAI,aAAa,QAAQ;AAAA,IAC9C,KAAK,eAAe,IAAI,aAAa,SAAS;AAAA,EAEhD,GACA,SAAS,UACT,OAAO,aAAa,OACpB,QAAQ,aAAa,QACrB,SAAS,GAAG,WAAW,QAAQ,WAAW,QAAQ,WAAW,SAAS,WAAW,WAEhF,MAAM,IAAI,CAAC,GAAG,MACb,CAAC,KACC,KAAK,GACL,KAAK,OACL,aAAa,KAAK,EAAE,eAAe,IACnC,QAAQ,EAAE,UAAU,OACpB,GAAG,EAAE,GACP,EACD,EACH,EAtBC;AAwBL;AAEA,IAAO,2BAAQ;;;AHrDR,IAAM,cAAc,CAAC,EAAE,WAAW,EAAE,QAAQ,UAAU,EAAE,MAAa;AAC1E,SACE,CAAC,yBACC,UAAU,UAAU,UACpB,QAAQ,UAAU,QAClB,MAAM,UAAU,MAChB,OAAO;AAAA,IACL,EAAE,QAAQ,OAAO,aAAa,GAAG,GAAG,aAAa;AAAA,IACjD,EAAE,QAAQ,OAAO,aAAa,GAAG,GAAG,cAAc;AAAA,IAClD,EAAE,QAAQ,OAAO,aAAa,GAAG,GAAG,yBAAyB;AAAA,IAC7D,EAAE,QAAQ,OAAO,aAAa,GAAG,GAAG,gBAAgB;AAAA,EAYtD,GACF;AAEJ;AAEA,IAAO,sBAAQ;","names":["createStore","svgPathBounds","import_transformation_matrix"]}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { SchematicComponent } from '../lib/types/core.js';
|
|
2
|
-
import { SimpleGround as SimpleGround$1 } from '../lib/types/source-component.js';
|
|
3
|
-
import '../lib/types/util.js';
|
|
4
|
-
|
|
5
|
-
interface Props {
|
|
6
|
-
component: {
|
|
7
|
-
source: SimpleGround$1;
|
|
8
|
-
schematic: SchematicComponent;
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
declare const SimpleGround: ({ component: { source, schematic } }: Props) => JSX.Element;
|
|
12
|
-
|
|
13
|
-
export { SimpleGround, SimpleGround as default };
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
-
mod
|
|
22
|
-
));
|
|
23
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
-
|
|
25
|
-
// src/schematic-components/SimpleGround.tsx
|
|
26
|
-
var SimpleGround_exports = {};
|
|
27
|
-
__export(SimpleGround_exports, {
|
|
28
|
-
SimpleGround: () => SimpleGround,
|
|
29
|
-
default: () => SimpleGround_default
|
|
30
|
-
});
|
|
31
|
-
module.exports = __toCommonJS(SimpleGround_exports);
|
|
32
|
-
|
|
33
|
-
// src/lib/render-context/index.ts
|
|
34
|
-
var import_zustand = __toESM(require("zustand"));
|
|
35
|
-
var import_transformation_matrix = require("transformation-matrix");
|
|
36
|
-
var useRenderContext = (0, import_zustand.default)()(
|
|
37
|
-
(set, get) => ({
|
|
38
|
-
camera_transform: (0, import_transformation_matrix.compose)((0, import_transformation_matrix.scale)(100, 100, 0, 0))
|
|
39
|
-
})
|
|
40
|
-
);
|
|
41
|
-
var useCameraTransform = () => useRenderContext((s) => s.camera_transform);
|
|
42
|
-
|
|
43
|
-
// src/lib/utils/get-svg-path-bounds.ts
|
|
44
|
-
var import_svg_path_bounds = __toESM(require("svg-path-bounds"));
|
|
45
|
-
function getSVGPathBounds(ds) {
|
|
46
|
-
if (typeof ds === "string")
|
|
47
|
-
ds = [ds];
|
|
48
|
-
let minX = Infinity, maxX = -Infinity, minY = Infinity, maxY = -Infinity;
|
|
49
|
-
for (const d of ds) {
|
|
50
|
-
const [left, top, right, bottom] = (0, import_svg_path_bounds.default)(d);
|
|
51
|
-
minX = Math.min(left, minX);
|
|
52
|
-
maxX = Math.max(right, maxX);
|
|
53
|
-
minY = Math.min(top, minY);
|
|
54
|
-
maxY = Math.max(bottom, maxY);
|
|
55
|
-
}
|
|
56
|
-
return { minX, maxX, minY, maxY, width: maxX - minX, height: maxY - minY };
|
|
57
|
-
}
|
|
58
|
-
var get_svg_path_bounds_default = getSVGPathBounds;
|
|
59
|
-
|
|
60
|
-
// src/schematic-components/SVGPathComponent.tsx
|
|
61
|
-
var import_transformation_matrix2 = require("transformation-matrix");
|
|
62
|
-
var SVGPathComponent = ({ size, center, rotation, paths }) => {
|
|
63
|
-
const ct = useCameraTransform();
|
|
64
|
-
const pathBounds = get_svg_path_bounds_default(paths.map((p) => p.d));
|
|
65
|
-
const badRatio = Math.abs(pathBounds.width / pathBounds.height - size.width / size.height) > 0.01;
|
|
66
|
-
if (badRatio) {
|
|
67
|
-
console.warn(
|
|
68
|
-
`Ratio doesn't match for component. ${pathBounds.width}:${pathBounds.height} is not close to ${size.width}:${size.height}`
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
pathBounds.height = Math.max(pathBounds.height, 1);
|
|
72
|
-
pathBounds.width = Math.max(pathBounds.width, 1);
|
|
73
|
-
const absoluteCenter = (0, import_transformation_matrix2.applyToPoint)(ct, center);
|
|
74
|
-
const absoluteSize = {
|
|
75
|
-
width: Math.max(1, size.width * ct.a),
|
|
76
|
-
height: Math.max(1, size.height * ct.d)
|
|
77
|
-
};
|
|
78
|
-
return <svg style={{
|
|
79
|
-
position: "absolute",
|
|
80
|
-
transform: rotation === 0 ? "" : `rotate(${rotation}rad)`,
|
|
81
|
-
left: absoluteCenter.x - absoluteSize.width / 2,
|
|
82
|
-
top: absoluteCenter.y - absoluteSize.height / 2
|
|
83
|
-
}} overflow="visible" width={absoluteSize.width} height={absoluteSize.height} viewBox={`${pathBounds.minX} ${pathBounds.minY} ${pathBounds.width} ${pathBounds.height}`}>{paths.map((p, i) => <path key={i} fill="none" strokeWidth={2 * (p.strokeWidth || 1)} stroke={p.stroke || "red"} d={p.d} />)}</svg>;
|
|
84
|
-
};
|
|
85
|
-
var SVGPathComponent_default = SVGPathComponent;
|
|
86
|
-
|
|
87
|
-
// src/schematic-components/SimpleGround.tsx
|
|
88
|
-
var SimpleGround = ({ component: { source, schematic } }) => {
|
|
89
|
-
return <SVGPathComponent_default rotation={schematic.rotation} center={schematic.center} size={schematic.size} paths={[
|
|
90
|
-
{
|
|
91
|
-
stroke: "red",
|
|
92
|
-
strokeWidth: 0.7,
|
|
93
|
-
d: "M -3 3 L 3 3 M -6 0 L 6 0 M -9 -3 L 9 -3 M 0 -3 L 0 -12"
|
|
94
|
-
}
|
|
95
|
-
]} />;
|
|
96
|
-
};
|
|
97
|
-
var SimpleGround_default = SimpleGround;
|
|
98
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
99
|
-
0 && (module.exports = {
|
|
100
|
-
SimpleGround
|
|
101
|
-
});
|
|
102
|
-
//# sourceMappingURL=SimpleGround.js.map
|