@tscircuit/schematic-viewer 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.d.ts +3 -4
- package/dist/index.js +694 -687
- package/dist/index.js.map +1 -1
- package/package.json +5 -6
- package/src/Schematic.tsx +139 -65
- package/src/lib/types/core.ts +14 -49
- package/src/lib/types/source-component.ts +5 -0
- package/src/lib/utils/collect-element-refs.ts +1 -0
- package/src/lib/utils/colors.ts +236 -0
- package/src/schematic-components/SVGPathComponent.tsx +84 -144
- package/src/schematic-components/SchematicChip.tsx +183 -0
- package/src/schematic-components/SchematicComponent.tsx +18 -24
- package/src/schematic-components/SchematicComponentFromSymbol.tsx +44 -0
- package/src/schematic-components/SchematicElement.tsx +0 -28
- package/src/schematic-components/SchematicTrace.tsx +4 -3
- package/src/schematic-components/index.tsx +7 -14
- package/src/stories/basics/schematic-net-labels-2.stories.tsx +22 -20
- package/src/stories/bug-connections.stories.tsx +3 -0
- package/src/stories/bug-high-port-numbers.stories.tsx +99 -85
- package/src/stories/bugs/bug3-scaling-trace.stories.tsx +11 -5
- package/src/stories/bugs/bug4-schematic-line.stories.tsx +0 -1
- package/src/stories/bugs/bug5-diode.stories.tsx +0 -1
- package/src/stories/bugs/bug8-autolayout.stories.tsx +20 -29
- package/src/stories/circuit-components/diode.stories.tsx +3 -1
- package/src/stories/circuit-components/resistor.stories.tsx +3 -1
- package/src/stories/led-circuit-react.stories.tsx +40 -48
- package/src/pages/led-circuit.tsx +0 -96
- package/src/schematic-components/ProjectComponent.tsx +0 -70
- package/src/schematic-components/SchematicBox.tsx +0 -29
- package/src/schematic-components/SchematicBug.tsx +0 -107
- package/src/schematic-components/SchematicLine.tsx +0 -48
- package/src/schematic-components/SchematicPath.tsx +0 -51
- package/src/schematic-components/SchematicPort.tsx +0 -63
- package/src/schematic-components/SimpleCapacitor.tsx +0 -29
- package/src/schematic-components/SimpleDiode.tsx +0 -42
- package/src/schematic-components/SimpleGround.tsx +0 -30
- package/src/schematic-components/SimpleInductor.tsx +0 -29
- package/src/schematic-components/SimplePowerSource.tsx +0 -43
- package/src/schematic-components/SimpleResistor.tsx +0 -28
- package/src/stories/led-circuit-builder.stories.tsx +0 -104
package/dist/index.js
CHANGED
|
@@ -89,8 +89,8 @@ var require_use_sync_external_store_shim_development = __commonJS({
|
|
|
89
89
|
if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart === "function") {
|
|
90
90
|
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
|
|
91
91
|
}
|
|
92
|
-
var
|
|
93
|
-
var ReactSharedInternals =
|
|
92
|
+
var React2 = require("react");
|
|
93
|
+
var ReactSharedInternals = React2.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
|
94
94
|
function error(format) {
|
|
95
95
|
{
|
|
96
96
|
{
|
|
@@ -120,13 +120,13 @@ var require_use_sync_external_store_shim_development = __commonJS({
|
|
|
120
120
|
return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y;
|
|
121
121
|
}
|
|
122
122
|
var objectIs = typeof Object.is === "function" ? Object.is : is;
|
|
123
|
-
var
|
|
123
|
+
var useState4 = React2.useState, useEffect3 = React2.useEffect, useLayoutEffect = React2.useLayoutEffect, useDebugValue2 = React2.useDebugValue;
|
|
124
124
|
var didWarnOld18Alpha = false;
|
|
125
125
|
var didWarnUncachedGetSnapshot = false;
|
|
126
126
|
function useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot) {
|
|
127
127
|
{
|
|
128
128
|
if (!didWarnOld18Alpha) {
|
|
129
|
-
if (
|
|
129
|
+
if (React2.startTransition !== void 0) {
|
|
130
130
|
didWarnOld18Alpha = true;
|
|
131
131
|
error("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release.");
|
|
132
132
|
}
|
|
@@ -142,7 +142,7 @@ var require_use_sync_external_store_shim_development = __commonJS({
|
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
|
-
var _useState =
|
|
145
|
+
var _useState = useState4({
|
|
146
146
|
inst: {
|
|
147
147
|
value,
|
|
148
148
|
getSnapshot
|
|
@@ -157,7 +157,7 @@ var require_use_sync_external_store_shim_development = __commonJS({
|
|
|
157
157
|
});
|
|
158
158
|
}
|
|
159
159
|
}, [subscribe, value, getSnapshot]);
|
|
160
|
-
|
|
160
|
+
useEffect3(function() {
|
|
161
161
|
if (checkIfSnapshotChanged(inst)) {
|
|
162
162
|
forceUpdate({
|
|
163
163
|
inst
|
|
@@ -191,7 +191,7 @@ var require_use_sync_external_store_shim_development = __commonJS({
|
|
|
191
191
|
var canUseDOM = !!(typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined");
|
|
192
192
|
var isServerEnvironment = !canUseDOM;
|
|
193
193
|
var shim = isServerEnvironment ? useSyncExternalStore$1 : useSyncExternalStore;
|
|
194
|
-
var useSyncExternalStore$2 =
|
|
194
|
+
var useSyncExternalStore$2 = React2.useSyncExternalStore !== void 0 ? React2.useSyncExternalStore : shim;
|
|
195
195
|
exports.useSyncExternalStore = useSyncExternalStore$2;
|
|
196
196
|
if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop === "function") {
|
|
197
197
|
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
|
|
@@ -285,16 +285,16 @@ var require_with_selector_development = __commonJS({
|
|
|
285
285
|
if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart === "function") {
|
|
286
286
|
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
|
|
287
287
|
}
|
|
288
|
-
var
|
|
288
|
+
var React2 = require("react");
|
|
289
289
|
var shim = require_shim();
|
|
290
290
|
function is(x, y) {
|
|
291
291
|
return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y;
|
|
292
292
|
}
|
|
293
293
|
var objectIs = typeof Object.is === "function" ? Object.is : is;
|
|
294
294
|
var useSyncExternalStore = shim.useSyncExternalStore;
|
|
295
|
-
var
|
|
295
|
+
var useRef3 = React2.useRef, useEffect3 = React2.useEffect, useMemo3 = React2.useMemo, useDebugValue2 = React2.useDebugValue;
|
|
296
296
|
function useSyncExternalStoreWithSelector2(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
|
|
297
|
-
var instRef =
|
|
297
|
+
var instRef = useRef3(null);
|
|
298
298
|
var inst;
|
|
299
299
|
if (instRef.current === null) {
|
|
300
300
|
inst = {
|
|
@@ -349,7 +349,7 @@ var require_with_selector_development = __commonJS({
|
|
|
349
349
|
return [getSnapshotWithSelector, getServerSnapshotWithSelector];
|
|
350
350
|
}, [getSnapshot, getServerSnapshot, selector, isEqual]), getSelection = _useMemo[0], getServerSelection = _useMemo[1];
|
|
351
351
|
var value = useSyncExternalStore(subscribe, getSelection, getServerSelection);
|
|
352
|
-
|
|
352
|
+
useEffect3(function() {
|
|
353
353
|
inst.hasValue = true;
|
|
354
354
|
inst.value = value;
|
|
355
355
|
}, [value]);
|
|
@@ -939,8 +939,8 @@ __export(src_exports, {
|
|
|
939
939
|
module.exports = __toCommonJS(src_exports);
|
|
940
940
|
|
|
941
941
|
// src/Schematic.tsx
|
|
942
|
-
var
|
|
943
|
-
var
|
|
942
|
+
var import_core = require("@tscircuit/core");
|
|
943
|
+
var import_soup_util = require("@tscircuit/soup-util");
|
|
944
944
|
|
|
945
945
|
// node_modules/zustand/esm/vanilla.mjs
|
|
946
946
|
var import_meta = {};
|
|
@@ -1012,6 +1012,20 @@ function applyToPoint(matrix, point) {
|
|
|
1012
1012
|
};
|
|
1013
1013
|
}
|
|
1014
1014
|
|
|
1015
|
+
// node_modules/transformation-matrix/src/inverse.js
|
|
1016
|
+
function inverse(matrix) {
|
|
1017
|
+
const { a, b, c, d, e, f } = matrix;
|
|
1018
|
+
const denom = a * d - b * c;
|
|
1019
|
+
return {
|
|
1020
|
+
a: d / denom,
|
|
1021
|
+
b: b / -denom,
|
|
1022
|
+
c: c / -denom,
|
|
1023
|
+
d: a / denom,
|
|
1024
|
+
e: (d * e - c * f) / -denom,
|
|
1025
|
+
f: (b * e - a * f) / denom
|
|
1026
|
+
};
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1015
1029
|
// node_modules/transformation-matrix/src/utils.js
|
|
1016
1030
|
function isUndefined(val) {
|
|
1017
1031
|
return typeof val === "undefined";
|
|
@@ -1222,7 +1236,275 @@ peg$SyntaxError.buildMessage = function(expected, found) {
|
|
|
1222
1236
|
};
|
|
1223
1237
|
|
|
1224
1238
|
// src/lib/render-context/index.ts
|
|
1225
|
-
var
|
|
1239
|
+
var import_react6 = require("react");
|
|
1240
|
+
|
|
1241
|
+
// src/schematic-components/ContextProviders.tsx
|
|
1242
|
+
var import_react2 = require("react");
|
|
1243
|
+
var import_react3 = require("react");
|
|
1244
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
1245
|
+
var StoreContext = (0, import_react3.createContext)(null);
|
|
1246
|
+
var ContextProviders = ({ children }) => {
|
|
1247
|
+
const store = (0, import_react2.useMemo)(() => createRenderContextStore(), []);
|
|
1248
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StoreContext.Provider, { value: store, children });
|
|
1249
|
+
};
|
|
1250
|
+
|
|
1251
|
+
// src/schematic-components/RenderError.tsx
|
|
1252
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
1253
|
+
var RenderError_default = ({ text }) => {
|
|
1254
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1255
|
+
"div",
|
|
1256
|
+
{
|
|
1257
|
+
style: {
|
|
1258
|
+
position: "fixed",
|
|
1259
|
+
backgroundColor: "red",
|
|
1260
|
+
color: "white",
|
|
1261
|
+
fontSize: 14,
|
|
1262
|
+
fontFamily: "sans-serif",
|
|
1263
|
+
padding: 5,
|
|
1264
|
+
right: 0,
|
|
1265
|
+
top: 0,
|
|
1266
|
+
opacity: 0.75
|
|
1267
|
+
},
|
|
1268
|
+
children: text
|
|
1269
|
+
}
|
|
1270
|
+
);
|
|
1271
|
+
};
|
|
1272
|
+
|
|
1273
|
+
// src/lib/utils/colors.ts
|
|
1274
|
+
var colorMap = {
|
|
1275
|
+
"3d_viewer": {
|
|
1276
|
+
background_bottom: "rgb(102, 102, 128)",
|
|
1277
|
+
background_top: "rgb(204, 204, 230)",
|
|
1278
|
+
board: "rgb(51, 43, 23)",
|
|
1279
|
+
copper: "rgb(179, 156, 0)",
|
|
1280
|
+
silkscreen_bottom: "rgb(230, 230, 230)",
|
|
1281
|
+
silkscreen_top: "rgb(230, 230, 230)",
|
|
1282
|
+
soldermask: "rgb(20, 51, 36)",
|
|
1283
|
+
solderpaste: "rgb(128, 128, 128)"
|
|
1284
|
+
},
|
|
1285
|
+
board: {
|
|
1286
|
+
anchor: "rgb(255, 38, 226)",
|
|
1287
|
+
aux_items: "rgb(255, 255, 255)",
|
|
1288
|
+
b_adhes: "rgb(0, 0, 132)",
|
|
1289
|
+
b_crtyd: "rgb(255, 38, 226)",
|
|
1290
|
+
b_fab: "rgb(88, 93, 132)",
|
|
1291
|
+
b_mask: "rgba(2, 255, 238, 0.400)",
|
|
1292
|
+
b_paste: "rgb(0, 194, 194)",
|
|
1293
|
+
b_silks: "rgb(232, 178, 167)",
|
|
1294
|
+
background: "rgb(0, 16, 35)",
|
|
1295
|
+
cmts_user: "rgb(89, 148, 220)",
|
|
1296
|
+
copper: {
|
|
1297
|
+
b: "rgb(77, 127, 196)",
|
|
1298
|
+
f: "rgb(200, 52, 52)",
|
|
1299
|
+
in1: "rgb(127, 200, 127)",
|
|
1300
|
+
in10: "rgb(237, 124, 51)",
|
|
1301
|
+
in11: "rgb(91, 195, 235)",
|
|
1302
|
+
in12: "rgb(247, 111, 142)",
|
|
1303
|
+
in13: "rgb(167, 165, 198)",
|
|
1304
|
+
in14: "rgb(40, 204, 217)",
|
|
1305
|
+
in15: "rgb(232, 178, 167)",
|
|
1306
|
+
in16: "rgb(242, 237, 161)",
|
|
1307
|
+
in17: "rgb(237, 124, 51)",
|
|
1308
|
+
in18: "rgb(91, 195, 235)",
|
|
1309
|
+
in19: "rgb(247, 111, 142)",
|
|
1310
|
+
in2: "rgb(206, 125, 44)",
|
|
1311
|
+
in20: "rgb(167, 165, 198)",
|
|
1312
|
+
in21: "rgb(40, 204, 217)",
|
|
1313
|
+
in22: "rgb(232, 178, 167)",
|
|
1314
|
+
in23: "rgb(242, 237, 161)",
|
|
1315
|
+
in24: "rgb(237, 124, 51)",
|
|
1316
|
+
in25: "rgb(91, 195, 235)",
|
|
1317
|
+
in26: "rgb(247, 111, 142)",
|
|
1318
|
+
in27: "rgb(167, 165, 198)",
|
|
1319
|
+
in28: "rgb(40, 204, 217)",
|
|
1320
|
+
in29: "rgb(232, 178, 167)",
|
|
1321
|
+
in3: "rgb(79, 203, 203)",
|
|
1322
|
+
in30: "rgb(242, 237, 161)",
|
|
1323
|
+
in4: "rgb(219, 98, 139)",
|
|
1324
|
+
in5: "rgb(167, 165, 198)",
|
|
1325
|
+
in6: "rgb(40, 204, 217)",
|
|
1326
|
+
in7: "rgb(232, 178, 167)",
|
|
1327
|
+
in8: "rgb(242, 237, 161)",
|
|
1328
|
+
in9: "rgb(141, 203, 129)"
|
|
1329
|
+
},
|
|
1330
|
+
cursor: "rgb(255, 255, 255)",
|
|
1331
|
+
drc: "rgb(194, 194, 194)",
|
|
1332
|
+
drc_error: "rgba(215, 91, 107, 0.800)",
|
|
1333
|
+
drc_exclusion: "rgb(255, 255, 255)",
|
|
1334
|
+
drc_warning: "rgba(255, 208, 66, 0.902)",
|
|
1335
|
+
dwgs_user: "rgb(194, 194, 194)",
|
|
1336
|
+
eco1_user: "rgb(180, 219, 210)",
|
|
1337
|
+
eco2_user: "rgb(216, 200, 82)",
|
|
1338
|
+
edge_cuts: "rgb(208, 210, 205)",
|
|
1339
|
+
f_adhes: "rgb(132, 0, 132)",
|
|
1340
|
+
f_crtyd: "rgb(255, 0, 245)",
|
|
1341
|
+
f_fab: "rgb(175, 175, 175)",
|
|
1342
|
+
f_mask: "rgba(216, 100, 255, 0.400)",
|
|
1343
|
+
f_paste: "rgba(180, 160, 154, 0.902)",
|
|
1344
|
+
f_silks: "rgb(242, 237, 161)",
|
|
1345
|
+
footprint_text_back: "rgb(0, 0, 132)",
|
|
1346
|
+
footprint_text_front: "rgb(194, 194, 194)",
|
|
1347
|
+
footprint_text_invisible: "rgb(132, 132, 132)",
|
|
1348
|
+
grid: "rgb(132, 132, 132)",
|
|
1349
|
+
grid_axes: "rgb(194, 194, 194)",
|
|
1350
|
+
margin: "rgb(255, 38, 226)",
|
|
1351
|
+
microvia: "rgb(0, 132, 132)",
|
|
1352
|
+
no_connect: "rgb(0, 0, 132)",
|
|
1353
|
+
pad_back: "rgb(77, 127, 196)",
|
|
1354
|
+
pad_front: "rgb(200, 52, 52)",
|
|
1355
|
+
pad_plated_hole: "rgb(194, 194, 0)",
|
|
1356
|
+
pad_through_hole: "rgb(227, 183, 46)",
|
|
1357
|
+
plated_hole: "rgb(26, 196, 210)",
|
|
1358
|
+
ratsnest: "rgba(245, 255, 213, 0.702)",
|
|
1359
|
+
select_overlay: "rgb(4, 255, 67)",
|
|
1360
|
+
through_via: "rgb(236, 236, 236)",
|
|
1361
|
+
user_1: "rgb(194, 194, 194)",
|
|
1362
|
+
user_2: "rgb(89, 148, 220)",
|
|
1363
|
+
user_3: "rgb(180, 219, 210)",
|
|
1364
|
+
user_4: "rgb(216, 200, 82)",
|
|
1365
|
+
user_5: "rgb(194, 194, 194)",
|
|
1366
|
+
user_6: "rgb(89, 148, 220)",
|
|
1367
|
+
user_7: "rgb(180, 219, 210)",
|
|
1368
|
+
user_8: "rgb(216, 200, 82)",
|
|
1369
|
+
user_9: "rgb(232, 178, 167)",
|
|
1370
|
+
via_blind_buried: "rgb(187, 151, 38)",
|
|
1371
|
+
via_hole: "rgb(227, 183, 46)",
|
|
1372
|
+
via_micro: "rgb(0, 132, 132)",
|
|
1373
|
+
via_through: "rgb(236, 236, 236)",
|
|
1374
|
+
worksheet: "rgb(200, 114, 171)"
|
|
1375
|
+
},
|
|
1376
|
+
gerbview: {
|
|
1377
|
+
axes: "rgb(0, 0, 132)",
|
|
1378
|
+
background: "rgb(0, 0, 0)",
|
|
1379
|
+
dcodes: "rgb(255, 255, 255)",
|
|
1380
|
+
grid: "rgb(132, 132, 132)",
|
|
1381
|
+
layers: [
|
|
1382
|
+
"rgb(132, 0, 0)",
|
|
1383
|
+
"rgb(194, 194, 0)",
|
|
1384
|
+
"rgb(194, 0, 194)",
|
|
1385
|
+
"rgb(194, 0, 0)",
|
|
1386
|
+
"rgb(0, 132, 132)",
|
|
1387
|
+
"rgb(0, 132, 0)",
|
|
1388
|
+
"rgb(0, 0, 132)",
|
|
1389
|
+
"rgb(132, 132, 132)",
|
|
1390
|
+
"rgb(132, 0, 132)",
|
|
1391
|
+
"rgb(194, 194, 194)",
|
|
1392
|
+
"rgb(132, 0, 132)",
|
|
1393
|
+
"rgb(132, 0, 0)",
|
|
1394
|
+
"rgb(132, 132, 0)",
|
|
1395
|
+
"rgb(194, 194, 194)",
|
|
1396
|
+
"rgb(0, 0, 132)",
|
|
1397
|
+
"rgb(0, 132, 0)",
|
|
1398
|
+
"rgb(132, 0, 0)",
|
|
1399
|
+
"rgb(194, 194, 0)",
|
|
1400
|
+
"rgb(194, 0, 194)",
|
|
1401
|
+
"rgb(194, 0, 0)",
|
|
1402
|
+
"rgb(0, 132, 132)",
|
|
1403
|
+
"rgb(0, 132, 0)",
|
|
1404
|
+
"rgb(0, 0, 132)",
|
|
1405
|
+
"rgb(132, 132, 132)",
|
|
1406
|
+
"rgb(132, 0, 132)",
|
|
1407
|
+
"rgb(194, 194, 194)",
|
|
1408
|
+
"rgb(132, 0, 132)",
|
|
1409
|
+
"rgb(132, 0, 0)",
|
|
1410
|
+
"rgb(132, 132, 0)",
|
|
1411
|
+
"rgb(194, 194, 194)",
|
|
1412
|
+
"rgb(0, 0, 132)",
|
|
1413
|
+
"rgb(0, 132, 0)",
|
|
1414
|
+
"rgb(132, 0, 0)",
|
|
1415
|
+
"rgb(194, 194, 0)",
|
|
1416
|
+
"rgb(194, 0, 194)",
|
|
1417
|
+
"rgb(194, 0, 0)",
|
|
1418
|
+
"rgb(0, 132, 132)",
|
|
1419
|
+
"rgb(0, 132, 0)",
|
|
1420
|
+
"rgb(0, 0, 132)",
|
|
1421
|
+
"rgb(132, 132, 132)",
|
|
1422
|
+
"rgb(132, 0, 132)",
|
|
1423
|
+
"rgb(194, 194, 194)",
|
|
1424
|
+
"rgb(132, 0, 132)",
|
|
1425
|
+
"rgb(132, 0, 0)",
|
|
1426
|
+
"rgb(132, 132, 0)",
|
|
1427
|
+
"rgb(194, 194, 194)",
|
|
1428
|
+
"rgb(0, 0, 132)",
|
|
1429
|
+
"rgb(0, 132, 0)",
|
|
1430
|
+
"rgb(132, 0, 0)",
|
|
1431
|
+
"rgb(194, 194, 0)",
|
|
1432
|
+
"rgb(194, 0, 194)",
|
|
1433
|
+
"rgb(194, 0, 0)",
|
|
1434
|
+
"rgb(0, 132, 132)",
|
|
1435
|
+
"rgb(0, 132, 0)",
|
|
1436
|
+
"rgb(0, 0, 132)",
|
|
1437
|
+
"rgb(132, 132, 132)",
|
|
1438
|
+
"rgb(132, 0, 132)",
|
|
1439
|
+
"rgb(194, 194, 194)",
|
|
1440
|
+
"rgb(132, 0, 132)",
|
|
1441
|
+
"rgb(132, 0, 0)"
|
|
1442
|
+
],
|
|
1443
|
+
negative_objects: "rgb(132, 132, 132)",
|
|
1444
|
+
worksheet: "rgb(0, 0, 132)"
|
|
1445
|
+
},
|
|
1446
|
+
meta: {
|
|
1447
|
+
filename: "kicad_2020",
|
|
1448
|
+
name: "KiCad 2020",
|
|
1449
|
+
version: 2
|
|
1450
|
+
},
|
|
1451
|
+
palette: [
|
|
1452
|
+
"rgb(132, 0, 0)",
|
|
1453
|
+
"rgb(194, 194, 0)",
|
|
1454
|
+
"rgb(194, 0, 194)",
|
|
1455
|
+
"rgb(194, 0, 0)",
|
|
1456
|
+
"rgb(0, 132, 132)",
|
|
1457
|
+
"rgb(0, 132, 0)",
|
|
1458
|
+
"rgb(0, 0, 132)",
|
|
1459
|
+
"rgb(132, 132, 132)",
|
|
1460
|
+
"rgb(132, 0, 132)",
|
|
1461
|
+
"rgb(194, 194, 194)",
|
|
1462
|
+
"rgb(132, 0, 132)",
|
|
1463
|
+
"rgb(132, 0, 0)",
|
|
1464
|
+
"rgb(132, 132, 0)",
|
|
1465
|
+
"rgb(194, 194, 194)",
|
|
1466
|
+
"rgb(0, 0, 132)",
|
|
1467
|
+
"rgb(0, 132, 0)"
|
|
1468
|
+
],
|
|
1469
|
+
schematic: {
|
|
1470
|
+
aux_items: "rgb(46, 46, 46)",
|
|
1471
|
+
background: "rgb(245, 241, 237)",
|
|
1472
|
+
brightened: "rgb(255, 0, 255)",
|
|
1473
|
+
bus: "rgb(0, 0, 132)",
|
|
1474
|
+
bus_junction: "rgb(0, 0, 132)",
|
|
1475
|
+
component_body: "rgb(255, 255, 194)",
|
|
1476
|
+
component_outline: "rgb(132, 0, 0)",
|
|
1477
|
+
cursor: "rgb(15, 15, 15)",
|
|
1478
|
+
erc_error: "rgba(230, 9, 13, 0.800)",
|
|
1479
|
+
erc_warning: "rgba(209, 146, 0, 0.800)",
|
|
1480
|
+
fields: "rgb(132, 0, 132)",
|
|
1481
|
+
grid: "rgb(181, 181, 181)",
|
|
1482
|
+
grid_axes: "rgb(0, 0, 132)",
|
|
1483
|
+
hidden: "rgb(194, 194, 194)",
|
|
1484
|
+
junction: "rgb(0, 150, 0)",
|
|
1485
|
+
label_global: "rgb(132, 0, 0)",
|
|
1486
|
+
label_hier: "rgb(114, 86, 0)",
|
|
1487
|
+
label_local: "rgb(15, 15, 15)",
|
|
1488
|
+
net_name: "rgb(132, 132, 132)",
|
|
1489
|
+
no_connect: "rgb(0, 0, 132)",
|
|
1490
|
+
note: "rgb(0, 0, 194)",
|
|
1491
|
+
override_item_colors: false,
|
|
1492
|
+
pin: "rgb(132, 0, 0)",
|
|
1493
|
+
pin_name: "rgb(0, 100, 100)",
|
|
1494
|
+
pin_number: "rgb(169, 0, 0)",
|
|
1495
|
+
reference: "rgb(0, 100, 100)",
|
|
1496
|
+
shadow: "rgba(102, 179, 255, 0.800)",
|
|
1497
|
+
sheet: "rgb(132, 0, 0)",
|
|
1498
|
+
sheet_background: "rgba(253, 255, 231, 0.000)",
|
|
1499
|
+
sheet_fields: "rgb(132, 0, 132)",
|
|
1500
|
+
sheet_filename: "rgb(114, 86, 0)",
|
|
1501
|
+
sheet_label: "rgb(0, 100, 100)",
|
|
1502
|
+
sheet_name: "rgb(0, 100, 100)",
|
|
1503
|
+
value: "rgb(0, 100, 100)",
|
|
1504
|
+
wire: "rgb(0, 150, 0)",
|
|
1505
|
+
worksheet: "rgb(132, 0, 0)"
|
|
1506
|
+
}
|
|
1507
|
+
};
|
|
1226
1508
|
|
|
1227
1509
|
// src/lib/utils/get-svg-path-bounds.ts
|
|
1228
1510
|
var import_svg_path_bounds = __toESM(require_svg_path_bounds());
|
|
@@ -1242,8 +1524,8 @@ function getSVGPathBounds(ds) {
|
|
|
1242
1524
|
var get_svg_path_bounds_default = getSVGPathBounds;
|
|
1243
1525
|
|
|
1244
1526
|
// src/schematic-components/SVGPathComponent.tsx
|
|
1245
|
-
var
|
|
1246
|
-
var
|
|
1527
|
+
var import_react4 = require("react");
|
|
1528
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
1247
1529
|
var SVGPathComponent = ({
|
|
1248
1530
|
size,
|
|
1249
1531
|
center,
|
|
@@ -1255,14 +1537,8 @@ var SVGPathComponent = ({
|
|
|
1255
1537
|
hoverContent
|
|
1256
1538
|
}) => {
|
|
1257
1539
|
const ct = useGlobalStore((s) => s.camera_transform);
|
|
1258
|
-
const pathBounds = get_svg_path_bounds_default(paths.map((p) => p.d));
|
|
1259
|
-
const
|
|
1260
|
-
if (badRatio) {
|
|
1261
|
-
}
|
|
1262
|
-
const padding = {
|
|
1263
|
-
x: 0,
|
|
1264
|
-
y: 0
|
|
1265
|
-
};
|
|
1540
|
+
const pathBounds = get_svg_path_bounds_default(paths.filter((p) => p.type !== "circle").map((p) => p.d));
|
|
1541
|
+
const padding = { x: 0, y: 0 };
|
|
1266
1542
|
const absoluteCenter = applyToPoint(ct, center);
|
|
1267
1543
|
const innerSize = {
|
|
1268
1544
|
width: size.width * ct.a,
|
|
@@ -1272,81 +1548,50 @@ var SVGPathComponent = ({
|
|
|
1272
1548
|
width: innerSize.width + padding.x * 2,
|
|
1273
1549
|
height: innerSize.height + padding.y * 2
|
|
1274
1550
|
};
|
|
1275
|
-
const [hovering, setHovering] = (0,
|
|
1551
|
+
const [hovering, setHovering] = (0, import_react4.useState)(false);
|
|
1276
1552
|
const svgLeft = absoluteCenter.x - fullSize.width / 2;
|
|
1277
1553
|
const svgTop = absoluteCenter.y - fullSize.height / 2;
|
|
1278
1554
|
const preferredRatio = pathBounds.width === 0 ? innerSize.height / pathBounds.height : innerSize.width / pathBounds.width;
|
|
1279
1555
|
const svgToScreen = compose(
|
|
1280
|
-
// translate(0, 0)
|
|
1281
1556
|
scale(
|
|
1282
1557
|
pathBounds.width === 0 ? preferredRatio : fullSize.width / pathBounds.width,
|
|
1283
1558
|
pathBounds.height === 0 ? preferredRatio : fullSize.height / pathBounds.height
|
|
1284
1559
|
),
|
|
1285
1560
|
translate(-pathBounds.minX, -pathBounds.minY)
|
|
1286
|
-
// translate(center.x, center.y)
|
|
1287
1561
|
);
|
|
1288
|
-
return /* @__PURE__ */ (0,
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
fontSize: 14
|
|
1562
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1563
|
+
"svg",
|
|
1564
|
+
{
|
|
1565
|
+
onMouseOver: () => setHovering(Boolean(hoverContent)),
|
|
1566
|
+
onMouseOut: () => setHovering(false),
|
|
1567
|
+
style: {
|
|
1568
|
+
position: "absolute",
|
|
1569
|
+
cursor: hovering ? "pointer" : void 0,
|
|
1570
|
+
zIndex,
|
|
1571
|
+
transform: [
|
|
1572
|
+
invertY ? "scale(1, 1)" : "scale(1, -1)",
|
|
1573
|
+
shiftToBottom ? "translate(0, 100%)" : "",
|
|
1574
|
+
rotation === 0 ? "" : `rotate(${rotation}deg)`
|
|
1575
|
+
].join(" "),
|
|
1576
|
+
left: svgLeft,
|
|
1577
|
+
top: svgTop
|
|
1578
|
+
},
|
|
1579
|
+
overflow: "visible",
|
|
1580
|
+
width: fullSize.width,
|
|
1581
|
+
height: fullSize.height,
|
|
1582
|
+
children: paths.map(
|
|
1583
|
+
(p, i) => p.type === "circle" ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1584
|
+
"circle",
|
|
1585
|
+
{
|
|
1586
|
+
cx: p.cx,
|
|
1587
|
+
cy: p.cy,
|
|
1588
|
+
r: p.r,
|
|
1589
|
+
fill: p.fill ?? "none",
|
|
1590
|
+
strokeWidth: 1.5 * (p.strokeWidth || 1),
|
|
1591
|
+
stroke: p.stroke || "red"
|
|
1319
1592
|
},
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
)
|
|
1323
|
-
] }),
|
|
1324
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1325
|
-
"svg",
|
|
1326
|
-
{
|
|
1327
|
-
onMouseOver: () => setHovering(Boolean(hoverContent)),
|
|
1328
|
-
onMouseOut: () => setHovering(false),
|
|
1329
|
-
style: {
|
|
1330
|
-
position: "absolute",
|
|
1331
|
-
// backgroundColor: hovering ? "rgba(0, 0, 255, 0.5)" : "transparent",
|
|
1332
|
-
cursor: hovering ? "pointer" : void 0,
|
|
1333
|
-
zIndex,
|
|
1334
|
-
transform: [
|
|
1335
|
-
invertY ? "scale(1, 1)" : "scale(1, -1)",
|
|
1336
|
-
// TODO based on ct.d
|
|
1337
|
-
shiftToBottom ? "translate(0, 100%)" : "",
|
|
1338
|
-
rotation === 0 ? "" : `rotate(${rotation}rad)`
|
|
1339
|
-
].join(" "),
|
|
1340
|
-
left: svgLeft,
|
|
1341
|
-
top: svgTop
|
|
1342
|
-
// overflow: "hidden",
|
|
1343
|
-
// backgroundColor: badRatio ? "rgba(255, 0, 0, 0.1)" : "transparent",
|
|
1344
|
-
// backgroundColor: "rgba(255, 0, 0, 0.1)",
|
|
1345
|
-
},
|
|
1346
|
-
overflow: "visible",
|
|
1347
|
-
width: fullSize.width,
|
|
1348
|
-
height: fullSize.height,
|
|
1349
|
-
children: paths.map((p, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1593
|
+
i
|
|
1594
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1350
1595
|
"path",
|
|
1351
1596
|
{
|
|
1352
1597
|
transform: toSVG(svgToScreen),
|
|
@@ -1354,157 +1599,18 @@ var SVGPathComponent = ({
|
|
|
1354
1599
|
strokeLinecap: "round",
|
|
1355
1600
|
strokeWidth: 1.5 * (p.strokeWidth || 1),
|
|
1356
1601
|
stroke: p.stroke || "red",
|
|
1357
|
-
d: p.d
|
|
1602
|
+
d: p.d || ""
|
|
1358
1603
|
},
|
|
1359
1604
|
i
|
|
1360
|
-
)
|
|
1361
|
-
|
|
1362
|
-
)
|
|
1363
|
-
] });
|
|
1364
|
-
};
|
|
1365
|
-
var SVGPathComponent_default = SVGPathComponent;
|
|
1366
|
-
|
|
1367
|
-
// src/schematic-components/SimpleResistor.tsx
|
|
1368
|
-
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
1369
|
-
var SimpleResistor = ({ component: { source, schematic } }) => {
|
|
1370
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1371
|
-
SVGPathComponent_default,
|
|
1372
|
-
{
|
|
1373
|
-
rotation: schematic.rotation,
|
|
1374
|
-
center: schematic.center,
|
|
1375
|
-
size: schematic.size,
|
|
1376
|
-
paths: [
|
|
1377
|
-
{
|
|
1378
|
-
stroke: "red",
|
|
1379
|
-
strokeWidth: 1,
|
|
1380
|
-
d: "M 0 15 l 10 0 l 0 -6 l 20 0 l 0 12 l -20 0 l 0 -6 m 20 0 l 10 0"
|
|
1381
|
-
}
|
|
1382
|
-
]
|
|
1383
|
-
}
|
|
1384
|
-
);
|
|
1385
|
-
};
|
|
1386
|
-
|
|
1387
|
-
// src/schematic-components/SimpleCapacitor.tsx
|
|
1388
|
-
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
1389
|
-
var SimpleCapacitor = ({
|
|
1390
|
-
component: { source, schematic }
|
|
1391
|
-
}) => {
|
|
1392
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1393
|
-
SVGPathComponent_default,
|
|
1394
|
-
{
|
|
1395
|
-
rotation: schematic.rotation,
|
|
1396
|
-
center: schematic.center,
|
|
1397
|
-
size: schematic.size,
|
|
1398
|
-
paths: [
|
|
1399
|
-
{ stroke: "red", strokeWidth: 1, d: "M 0 15 l 12 0" },
|
|
1400
|
-
{ stroke: "red", strokeWidth: 1, d: "M 12 0 l 0 30" },
|
|
1401
|
-
{ stroke: "red", strokeWidth: 1, d: "M 18 0 l 0 30" },
|
|
1402
|
-
{ stroke: "red", strokeWidth: 1, d: "M 18 15 l 12 0" }
|
|
1403
|
-
]
|
|
1404
|
-
}
|
|
1405
|
-
);
|
|
1406
|
-
};
|
|
1407
|
-
|
|
1408
|
-
// src/lib/hooks/use-maybe-promise.ts
|
|
1409
|
-
var import_react3 = require("react");
|
|
1410
|
-
|
|
1411
|
-
// src/schematic-components/ProjectComponent.tsx
|
|
1412
|
-
var import_builder = require("@tscircuit/builder");
|
|
1413
|
-
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1414
|
-
|
|
1415
|
-
// src/schematic-components/SchematicComponent.tsx
|
|
1416
|
-
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1417
|
-
var SchematicComponent = ({ component }) => {
|
|
1418
|
-
const { source, schematic } = component;
|
|
1419
|
-
if (!source.ftype)
|
|
1420
|
-
return null;
|
|
1421
|
-
switch (source.ftype) {
|
|
1422
|
-
case "simple_resistor": {
|
|
1423
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SimpleResistor, { component: { source, schematic } });
|
|
1424
|
-
}
|
|
1425
|
-
case "simple_capacitor": {
|
|
1426
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SimpleCapacitor, { component: { source, schematic } });
|
|
1427
|
-
}
|
|
1428
|
-
case "simple_power_source": {
|
|
1429
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SimplePowerSource, { component: { source, schematic } });
|
|
1430
|
-
}
|
|
1431
|
-
case "simple_ground": {
|
|
1432
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SimpleGround, { component: { source, schematic } });
|
|
1433
|
-
}
|
|
1434
|
-
case "simple_inductor": {
|
|
1435
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SimpleInductor, { component: { source, schematic } });
|
|
1436
|
-
}
|
|
1437
|
-
case "simple_bug": {
|
|
1438
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SchematicBug, { component: { source, schematic } });
|
|
1439
|
-
}
|
|
1440
|
-
case "simple_diode": {
|
|
1441
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SimpleDiode, { component: { source, schematic } });
|
|
1442
|
-
}
|
|
1443
|
-
default: {
|
|
1444
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
|
|
1445
|
-
"unknown ftype: ",
|
|
1446
|
-
component.source.ftype
|
|
1447
|
-
] });
|
|
1448
|
-
}
|
|
1449
|
-
}
|
|
1450
|
-
};
|
|
1451
|
-
var SchematicComponent_default = SchematicComponent;
|
|
1452
|
-
|
|
1453
|
-
// src/lib/utils/direction-to-vec.ts
|
|
1454
|
-
var directionToVec = (direction) => {
|
|
1455
|
-
if (direction === "up")
|
|
1456
|
-
return { x: 0, y: 1 };
|
|
1457
|
-
else if (direction === "down")
|
|
1458
|
-
return { x: 0, y: -1 };
|
|
1459
|
-
else if (direction === "left")
|
|
1460
|
-
return { x: -1, y: 0 };
|
|
1461
|
-
else if (direction === "right")
|
|
1462
|
-
return { x: 1, y: 0 };
|
|
1463
|
-
else
|
|
1464
|
-
throw new Error(`Invalid direction "${direction}"`);
|
|
1465
|
-
};
|
|
1466
|
-
|
|
1467
|
-
// src/schematic-components/SchematicPort.tsx
|
|
1468
|
-
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
1469
|
-
var SchematicPort = ({
|
|
1470
|
-
port: { source_port, source_component, schematic }
|
|
1471
|
-
}) => {
|
|
1472
|
-
const hoverName = source_component?.name ? `.${source_component.name} > .${source_port?.name ?? source_port?.pin_number}` : `.${source_port?.name ?? source_port?.pin_number}`;
|
|
1473
|
-
const vec = directionToVec(schematic.facing_direction);
|
|
1474
|
-
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1475
|
-
SVGPathComponent,
|
|
1476
|
-
{
|
|
1477
|
-
rotation: 0,
|
|
1478
|
-
hoverContent: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { children: [
|
|
1479
|
-
hoverName,
|
|
1480
|
-
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("br", {}),
|
|
1481
|
-
source_port?.pin_number && `Pin ${source_port.pin_number}`
|
|
1482
|
-
] }),
|
|
1483
|
-
center: schematic.center,
|
|
1484
|
-
size: {
|
|
1485
|
-
width: 0.2 + Math.abs(vec.x) * 0.04,
|
|
1486
|
-
height: 0.2 + Math.abs(vec.y) * 0.04
|
|
1487
|
-
},
|
|
1488
|
-
zIndex: 10,
|
|
1489
|
-
paths: [
|
|
1490
|
-
{
|
|
1491
|
-
stroke: "blue",
|
|
1492
|
-
strokeWidth: 1,
|
|
1493
|
-
d: "M 0 0 l 10 0 l 0 10 l -10 0 z"
|
|
1494
|
-
},
|
|
1495
|
-
schematic.facing_direction ? {
|
|
1496
|
-
stroke: "blue",
|
|
1497
|
-
strokeWidth: 0.5,
|
|
1498
|
-
d: `M 5 5 l ${vec.x * 7} ${vec.y * 7}`
|
|
1499
|
-
} : null
|
|
1500
|
-
].filter(Boolean)
|
|
1605
|
+
)
|
|
1606
|
+
)
|
|
1501
1607
|
}
|
|
1502
1608
|
);
|
|
1503
1609
|
};
|
|
1504
|
-
var
|
|
1610
|
+
var SVGPathComponent_default = SVGPathComponent;
|
|
1505
1611
|
|
|
1506
1612
|
// node_modules/react-use-measure/dist/web.js
|
|
1507
|
-
var
|
|
1613
|
+
var import_react5 = require("react");
|
|
1508
1614
|
var import_debounce = __toESM(require_debounce());
|
|
1509
1615
|
function useMeasure(_temp) {
|
|
1510
1616
|
let {
|
|
@@ -1522,7 +1628,7 @@ function useMeasure(_temp) {
|
|
|
1522
1628
|
if (!ResizeObserver) {
|
|
1523
1629
|
throw new Error("This browser does not support ResizeObserver out of the box. See: https://github.com/react-spring/react-use-measure/#resize-observer-polyfills");
|
|
1524
1630
|
}
|
|
1525
|
-
const [bounds, set] = (0,
|
|
1631
|
+
const [bounds, set] = (0, import_react5.useState)({
|
|
1526
1632
|
left: 0,
|
|
1527
1633
|
top: 0,
|
|
1528
1634
|
width: 0,
|
|
@@ -1532,7 +1638,7 @@ function useMeasure(_temp) {
|
|
|
1532
1638
|
x: 0,
|
|
1533
1639
|
y: 0
|
|
1534
1640
|
});
|
|
1535
|
-
const state = (0,
|
|
1641
|
+
const state = (0, import_react5.useRef)({
|
|
1536
1642
|
element: null,
|
|
1537
1643
|
scrollContainers: null,
|
|
1538
1644
|
resizeObserver: null,
|
|
@@ -1540,12 +1646,12 @@ function useMeasure(_temp) {
|
|
|
1540
1646
|
});
|
|
1541
1647
|
const scrollDebounce = debounce ? typeof debounce === "number" ? debounce : debounce.scroll : null;
|
|
1542
1648
|
const resizeDebounce = debounce ? typeof debounce === "number" ? debounce : debounce.resize : null;
|
|
1543
|
-
const mounted = (0,
|
|
1544
|
-
(0,
|
|
1649
|
+
const mounted = (0, import_react5.useRef)(false);
|
|
1650
|
+
(0, import_react5.useEffect)(() => {
|
|
1545
1651
|
mounted.current = true;
|
|
1546
1652
|
return () => void (mounted.current = false);
|
|
1547
1653
|
});
|
|
1548
|
-
const [forceRefresh, resizeChange, scrollChange] = (0,
|
|
1654
|
+
const [forceRefresh, resizeChange, scrollChange] = (0, import_react5.useMemo)(() => {
|
|
1549
1655
|
const callback = () => {
|
|
1550
1656
|
if (!state.current.element)
|
|
1551
1657
|
return;
|
|
@@ -1611,22 +1717,22 @@ function useMeasure(_temp) {
|
|
|
1611
1717
|
};
|
|
1612
1718
|
useOnWindowScroll(scrollChange, Boolean(scroll));
|
|
1613
1719
|
useOnWindowResize(resizeChange);
|
|
1614
|
-
(0,
|
|
1720
|
+
(0, import_react5.useEffect)(() => {
|
|
1615
1721
|
removeListeners();
|
|
1616
1722
|
addListeners();
|
|
1617
1723
|
}, [scroll, scrollChange, resizeChange]);
|
|
1618
|
-
(0,
|
|
1724
|
+
(0, import_react5.useEffect)(() => removeListeners, []);
|
|
1619
1725
|
return [ref, bounds, forceRefresh];
|
|
1620
1726
|
}
|
|
1621
1727
|
function useOnWindowResize(onWindowResize) {
|
|
1622
|
-
(0,
|
|
1728
|
+
(0, import_react5.useEffect)(() => {
|
|
1623
1729
|
const cb = onWindowResize;
|
|
1624
1730
|
window.addEventListener("resize", cb);
|
|
1625
1731
|
return () => void window.removeEventListener("resize", cb);
|
|
1626
1732
|
}, [onWindowResize]);
|
|
1627
1733
|
}
|
|
1628
1734
|
function useOnWindowScroll(onScroll, enabled) {
|
|
1629
|
-
(0,
|
|
1735
|
+
(0, import_react5.useEffect)(() => {
|
|
1630
1736
|
if (enabled) {
|
|
1631
1737
|
const cb = onScroll;
|
|
1632
1738
|
window.addEventListener("scroll", cb, {
|
|
@@ -1654,7 +1760,7 @@ var keys = ["x", "y", "top", "bottom", "left", "right", "width", "height"];
|
|
|
1654
1760
|
var areBoundsEqual = (a, b) => keys.every((key) => a[key] === b[key]);
|
|
1655
1761
|
|
|
1656
1762
|
// src/schematic-components/SchematicText.tsx
|
|
1657
|
-
var
|
|
1763
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1658
1764
|
var SchematicText = ({ schematic_text }) => {
|
|
1659
1765
|
const ct = useGlobalStore((s) => s.camera_transform);
|
|
1660
1766
|
const { text, position, anchor } = schematic_text;
|
|
@@ -1670,7 +1776,7 @@ var SchematicText = ({ schematic_text }) => {
|
|
|
1670
1776
|
}
|
|
1671
1777
|
const fontTransformRatio = 0.15;
|
|
1672
1778
|
const projectedTextSize = fontTransformRatio * ct.a;
|
|
1673
|
-
return /* @__PURE__ */ (0,
|
|
1779
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1674
1780
|
"div",
|
|
1675
1781
|
{
|
|
1676
1782
|
ref: boundsRef,
|
|
@@ -1687,85 +1793,222 @@ var SchematicText = ({ schematic_text }) => {
|
|
|
1687
1793
|
};
|
|
1688
1794
|
var SchematicText_default = SchematicText;
|
|
1689
1795
|
|
|
1690
|
-
// src/schematic-components/
|
|
1691
|
-
var
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1796
|
+
// src/schematic-components/SchematicChip.tsx
|
|
1797
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1798
|
+
var SchematicChip = ({ component: { source, schematic, allElements } }) => {
|
|
1799
|
+
const { center, size, rotation, schematic_component_id } = schematic;
|
|
1800
|
+
const { manufacturerPartNumber, name } = source;
|
|
1801
|
+
const chipWidth = size.width;
|
|
1802
|
+
const chipHeight = size.height;
|
|
1803
|
+
const paths = [];
|
|
1804
|
+
paths.push({
|
|
1805
|
+
type: "path",
|
|
1806
|
+
strokeWidth: 0.02,
|
|
1807
|
+
stroke: colorMap.schematic.component_outline,
|
|
1808
|
+
fill: colorMap.schematic.component_body,
|
|
1809
|
+
d: `M ${-chipWidth / 2},${-chipHeight / 2} h ${chipWidth} v ${chipHeight} h ${-chipWidth} Z`
|
|
1810
|
+
});
|
|
1811
|
+
const schematicPorts = allElements.filter(
|
|
1812
|
+
(item) => item.type === "schematic_port" && item.schematic_component_id === schematic_component_id
|
|
1813
|
+
);
|
|
1814
|
+
const portLength = 0.2;
|
|
1815
|
+
const circleRadius = 0.05;
|
|
1816
|
+
const labelOffset = 0.1;
|
|
1817
|
+
const pinLabels = [];
|
|
1818
|
+
schematicPorts.forEach((port) => {
|
|
1819
|
+
const { side, pinNumber, distanceFromEdge } = port.center;
|
|
1820
|
+
let x = 0, y = 0, endX = 0, endY = 0;
|
|
1821
|
+
let labelX = 0, labelY = 0;
|
|
1822
|
+
let textAnchor = "middle";
|
|
1823
|
+
switch (side) {
|
|
1824
|
+
case "left":
|
|
1825
|
+
x = -chipWidth / 2;
|
|
1826
|
+
y = -chipHeight / 2 + distanceFromEdge;
|
|
1827
|
+
endX = x - portLength;
|
|
1828
|
+
endY = y;
|
|
1829
|
+
labelX = endX;
|
|
1830
|
+
labelY = y + labelOffset;
|
|
1831
|
+
textAnchor = "end";
|
|
1832
|
+
break;
|
|
1833
|
+
case "right":
|
|
1834
|
+
x = chipWidth / 2;
|
|
1835
|
+
y = chipHeight / 2 - distanceFromEdge;
|
|
1836
|
+
endX = x + portLength;
|
|
1837
|
+
endY = y;
|
|
1838
|
+
labelX = endX - labelOffset;
|
|
1839
|
+
labelY = y + labelOffset;
|
|
1840
|
+
textAnchor = "start";
|
|
1841
|
+
break;
|
|
1842
|
+
case "bottom":
|
|
1843
|
+
x = -chipWidth / 2 + distanceFromEdge;
|
|
1844
|
+
y = -chipHeight / 2;
|
|
1845
|
+
endX = x;
|
|
1846
|
+
endY = y - portLength;
|
|
1847
|
+
labelX = x;
|
|
1848
|
+
labelY = endY + labelOffset;
|
|
1849
|
+
break;
|
|
1850
|
+
case "top":
|
|
1851
|
+
x = chipWidth / 2 - distanceFromEdge;
|
|
1852
|
+
y = chipHeight / 2;
|
|
1853
|
+
endX = x;
|
|
1854
|
+
endY = y + portLength;
|
|
1855
|
+
labelX = x;
|
|
1856
|
+
labelY = endY + labelOffset;
|
|
1857
|
+
break;
|
|
1858
|
+
}
|
|
1859
|
+
paths.push({
|
|
1860
|
+
type: "path",
|
|
1861
|
+
strokeWidth: 0.02,
|
|
1862
|
+
stroke: colorMap.schematic.component_outline,
|
|
1863
|
+
d: `M ${x},${y} L ${endX},${endY}`
|
|
1864
|
+
});
|
|
1865
|
+
paths.push({
|
|
1866
|
+
type: "circle",
|
|
1867
|
+
cx: endX,
|
|
1868
|
+
cy: endY,
|
|
1869
|
+
r: circleRadius,
|
|
1870
|
+
strokeWidth: 0.01,
|
|
1871
|
+
stroke: colorMap.schematic.component_outline,
|
|
1872
|
+
fill: colorMap.schematic.component_outline
|
|
1873
|
+
});
|
|
1874
|
+
if (pinNumber !== void 0) {
|
|
1875
|
+
pinLabels.push({
|
|
1876
|
+
x: labelX,
|
|
1877
|
+
y: labelY,
|
|
1878
|
+
text: `${pinNumber}`,
|
|
1879
|
+
anchor: textAnchor
|
|
1880
|
+
});
|
|
1881
|
+
}
|
|
1882
|
+
});
|
|
1883
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
1884
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1885
|
+
SVGPathComponent_default,
|
|
1886
|
+
{
|
|
1887
|
+
rotation,
|
|
1888
|
+
center,
|
|
1889
|
+
size,
|
|
1890
|
+
paths
|
|
1891
|
+
}
|
|
1892
|
+
),
|
|
1893
|
+
pinLabels.map((label, index) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1894
|
+
SchematicText_default,
|
|
1895
|
+
{
|
|
1896
|
+
schematic_text: {
|
|
1897
|
+
anchor: label.anchor,
|
|
1898
|
+
position: {
|
|
1899
|
+
x: center.x + label.x,
|
|
1900
|
+
y: center.y + label.y
|
|
1901
|
+
},
|
|
1902
|
+
schematic_component_id: "SYNTHETIC",
|
|
1903
|
+
schematic_text_id: `PIN_LABEL_${index}`,
|
|
1904
|
+
text: label.text,
|
|
1905
|
+
type: "schematic_text"
|
|
1906
|
+
}
|
|
1709
1907
|
},
|
|
1710
|
-
|
|
1908
|
+
index
|
|
1909
|
+
)),
|
|
1910
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1911
|
+
SchematicText_default,
|
|
1912
|
+
{
|
|
1913
|
+
schematic_text: {
|
|
1914
|
+
anchor: "center",
|
|
1915
|
+
position: {
|
|
1916
|
+
x: center.x,
|
|
1917
|
+
y: center.y - chipHeight / 2 - 0.2
|
|
1918
|
+
},
|
|
1919
|
+
schematic_component_id: "SYNTHETIC",
|
|
1920
|
+
schematic_text_id: "SYNTHETIC_MPN",
|
|
1921
|
+
text: manufacturerPartNumber,
|
|
1922
|
+
type: "schematic_text"
|
|
1923
|
+
}
|
|
1924
|
+
}
|
|
1925
|
+
),
|
|
1926
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1927
|
+
SchematicText_default,
|
|
1928
|
+
{
|
|
1929
|
+
schematic_text: {
|
|
1930
|
+
anchor: "center",
|
|
1931
|
+
position: {
|
|
1932
|
+
x: center.x,
|
|
1933
|
+
y: center.y + chipHeight / 2 + 0.2
|
|
1934
|
+
},
|
|
1935
|
+
schematic_component_id: "SYNTHETIC",
|
|
1936
|
+
schematic_text_id: "SYNTHETIC_NAME",
|
|
1937
|
+
text: name,
|
|
1938
|
+
type: "schematic_text"
|
|
1939
|
+
}
|
|
1940
|
+
}
|
|
1941
|
+
)
|
|
1942
|
+
] });
|
|
1943
|
+
};
|
|
1944
|
+
|
|
1945
|
+
// src/schematic-components/SchematicComponent.tsx
|
|
1946
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
1947
|
+
var SchematicComponent = ({ component }) => {
|
|
1948
|
+
const { source, schematic, allElements } = component;
|
|
1949
|
+
if (!source.ftype)
|
|
1950
|
+
return null;
|
|
1951
|
+
switch (source.ftype) {
|
|
1952
|
+
case "simple_resistor":
|
|
1953
|
+
case "simple_capacitor":
|
|
1954
|
+
case "simple_power_source":
|
|
1955
|
+
case "simple_ground":
|
|
1956
|
+
case "simple_inductor":
|
|
1957
|
+
case "simple_diode": {
|
|
1958
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(SchematicComponentFromSymbol, { component: { source, schematic } });
|
|
1711
1959
|
}
|
|
1712
|
-
|
|
1960
|
+
case "simple_chip":
|
|
1961
|
+
case "simple_bug": {
|
|
1962
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(SchematicChip, { component: { source, schematic, allElements } });
|
|
1963
|
+
}
|
|
1964
|
+
default: {
|
|
1965
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { children: [
|
|
1966
|
+
"unknown ftype: ",
|
|
1967
|
+
component.source.ftype
|
|
1968
|
+
] });
|
|
1969
|
+
}
|
|
1970
|
+
}
|
|
1713
1971
|
};
|
|
1972
|
+
var SchematicComponent_default = SchematicComponent;
|
|
1714
1973
|
|
|
1715
|
-
// src/schematic-components/
|
|
1716
|
-
var
|
|
1717
|
-
var
|
|
1718
|
-
|
|
1719
|
-
center,
|
|
1720
|
-
|
|
1721
|
-
paths
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1974
|
+
// src/schematic-components/SchematicComponentFromSymbol.tsx
|
|
1975
|
+
var import_schematic_symbols = require("schematic-symbols");
|
|
1976
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
1977
|
+
var SchematicComponentFromSymbol = ({ component: { source, schematic } }) => {
|
|
1978
|
+
const { center, rotation } = schematic;
|
|
1979
|
+
const symbol = import_schematic_symbols.symbols[schematic.symbol_name];
|
|
1980
|
+
const paths = symbol.primitives.filter((p) => p.type === "path").map((p) => ({
|
|
1981
|
+
stroke: colorMap.schematic.component_outline,
|
|
1982
|
+
strokeWidth: 0.02,
|
|
1983
|
+
d: p.points.reduce(
|
|
1984
|
+
(acc, point, index) => {
|
|
1985
|
+
const command = index === 0 ? "M" : "L";
|
|
1986
|
+
return `${acc} ${command} ${point.x} ${point.y}`;
|
|
1987
|
+
},
|
|
1988
|
+
""
|
|
1989
|
+
)
|
|
1990
|
+
}));
|
|
1991
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1992
|
+
SVGPathComponent_default,
|
|
1731
1993
|
{
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
bottom: 0,
|
|
1738
|
-
// backgroundColor: hovering ? "rgba(0, 0, 255, 0.5)" : "transparent",
|
|
1739
|
-
pointerEvents: "none",
|
|
1740
|
-
zIndex
|
|
1741
|
-
// overflow: "hidden",
|
|
1742
|
-
// backgroundColor: badRatio ? "rgba(255, 0, 0, 0.1)" : "transparent",
|
|
1743
|
-
// backgroundColor: "rgba(255, 0, 0, 0.1)",
|
|
1994
|
+
rotation,
|
|
1995
|
+
center,
|
|
1996
|
+
size: {
|
|
1997
|
+
width: symbol?.size.width,
|
|
1998
|
+
height: symbol?.size.height
|
|
1744
1999
|
},
|
|
1745
|
-
|
|
1746
|
-
children: paths.map((p, i) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
1747
|
-
"path",
|
|
1748
|
-
{
|
|
1749
|
-
transform: toSVG(ct),
|
|
1750
|
-
fill: p.fill ?? "none",
|
|
1751
|
-
strokeLinecap: "round",
|
|
1752
|
-
strokeWidth: 1.5 * (p.strokeWidth || 1),
|
|
1753
|
-
stroke: p.stroke || "red",
|
|
1754
|
-
d: p.d
|
|
1755
|
-
},
|
|
1756
|
-
i
|
|
1757
|
-
))
|
|
2000
|
+
paths
|
|
1758
2001
|
}
|
|
1759
2002
|
);
|
|
1760
2003
|
};
|
|
1761
|
-
var SVGPathComponent2_default = SVGPathComponent2;
|
|
1762
2004
|
|
|
1763
2005
|
// src/schematic-components/SchematicTrace.tsx
|
|
1764
|
-
var
|
|
2006
|
+
var import_svg_path_generator = __toESM(require_svg_path_generator2());
|
|
2007
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
1765
2008
|
var SchematicTrace = ({ trace: { source, schematic } }) => {
|
|
1766
2009
|
const edges = schematic.edges;
|
|
1767
2010
|
if (edges.length === 0) {
|
|
1768
|
-
return /* @__PURE__ */ (0,
|
|
2011
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(RenderError_default, { text: `Route with 0 edges (${source.source_trace_id})` });
|
|
1769
2012
|
}
|
|
1770
2013
|
const path = (0, import_svg_path_generator.default)();
|
|
1771
2014
|
for (let i = 0; i < edges.length; i++) {
|
|
@@ -1780,16 +2023,16 @@ var SchematicTrace = ({ trace: { source, schematic } }) => {
|
|
|
1780
2023
|
x: pathBounds.minX + pathBounds.width / 2,
|
|
1781
2024
|
y: pathBounds.minY + pathBounds.height / 2
|
|
1782
2025
|
};
|
|
1783
|
-
return /* @__PURE__ */ (0,
|
|
1784
|
-
|
|
2026
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
2027
|
+
SVGPathComponent_default,
|
|
1785
2028
|
{
|
|
1786
2029
|
rotation: 0,
|
|
1787
2030
|
center,
|
|
1788
2031
|
size: pathBounds,
|
|
1789
2032
|
paths: [
|
|
1790
2033
|
{
|
|
1791
|
-
stroke:
|
|
1792
|
-
strokeWidth: 0.
|
|
2034
|
+
stroke: colorMap.schematic.wire,
|
|
2035
|
+
strokeWidth: 0.01,
|
|
1793
2036
|
d
|
|
1794
2037
|
}
|
|
1795
2038
|
]
|
|
@@ -1798,212 +2041,18 @@ var SchematicTrace = ({ trace: { source, schematic } }) => {
|
|
|
1798
2041
|
};
|
|
1799
2042
|
var SchematicTrace_default = SchematicTrace;
|
|
1800
2043
|
|
|
1801
|
-
// src/schematic-components/SchematicBug.tsx
|
|
1802
|
-
var import_builder2 = require("@tscircuit/builder");
|
|
1803
|
-
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
1804
|
-
var SchematicBug = ({ component: { source, schematic } }) => {
|
|
1805
|
-
const location = schematic.center;
|
|
1806
|
-
const port_arrangement = {
|
|
1807
|
-
top_size: 0,
|
|
1808
|
-
bottom_size: 0,
|
|
1809
|
-
...schematic.port_arrangement
|
|
1810
|
-
};
|
|
1811
|
-
const manufacturerPartNumber = source.manufacturerPartNumber;
|
|
1812
|
-
let bugw = schematic.size.width;
|
|
1813
|
-
let bugh = schematic.size.height;
|
|
1814
|
-
const { total_ports, width, height } = (0, import_builder2.getPortArrangementSize)(port_arrangement);
|
|
1815
|
-
const port_indices = (0, import_builder2.getPortIndices)(port_arrangement);
|
|
1816
|
-
if (isNaN(bugw))
|
|
1817
|
-
bugw = width;
|
|
1818
|
-
if (isNaN(bugh))
|
|
1819
|
-
bugh = height;
|
|
1820
|
-
const paths = [
|
|
1821
|
-
{
|
|
1822
|
-
stroke: "red",
|
|
1823
|
-
strokeWidth: 0.02,
|
|
1824
|
-
d: `M ${-bugw / 2} ${-bugh / 2} L ${bugw / 2} ${-bugh / 2} L ${bugw / 2} ${bugh / 2} L ${-bugw / 2} ${bugh / 2}Z`
|
|
1825
|
-
},
|
|
1826
|
-
...port_indices.map((portNum) => {
|
|
1827
|
-
const pos = (0, import_builder2.getPortPosition)(
|
|
1828
|
-
{ ...port_arrangement, pin_spacing: schematic.pin_spacing },
|
|
1829
|
-
portNum
|
|
1830
|
-
);
|
|
1831
|
-
const x2 = pos.side === "left" ? -bugw / 2 : pos.side === "right" ? bugw / 2 : pos.x;
|
|
1832
|
-
const y2 = pos.side === "top" ? bugh / 2 : pos.side === "bottom" ? -bugh / 2 : pos.y;
|
|
1833
|
-
return {
|
|
1834
|
-
stroke: "red",
|
|
1835
|
-
strokeWidth: 0.02,
|
|
1836
|
-
d: `M ${pos.x} ${pos.y} L ${x2} ${y2}`
|
|
1837
|
-
};
|
|
1838
|
-
})
|
|
1839
|
-
];
|
|
1840
|
-
const actualSize = get_svg_path_bounds_default(paths.map((p) => p.d).join(" "));
|
|
1841
|
-
const actualCenter = {
|
|
1842
|
-
x: schematic.center.x + (actualSize.minX + actualSize.maxX) / 2,
|
|
1843
|
-
y: schematic.center.y + (actualSize.minY + actualSize.maxY) / 2
|
|
1844
|
-
};
|
|
1845
|
-
return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_jsx_runtime11.Fragment, { children: [
|
|
1846
|
-
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
1847
|
-
SVGPathComponent_default,
|
|
1848
|
-
{
|
|
1849
|
-
rotation: schematic.rotation,
|
|
1850
|
-
center: actualCenter,
|
|
1851
|
-
size: actualSize,
|
|
1852
|
-
paths
|
|
1853
|
-
}
|
|
1854
|
-
),
|
|
1855
|
-
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
1856
|
-
SchematicText_default,
|
|
1857
|
-
{
|
|
1858
|
-
schematic_text: {
|
|
1859
|
-
anchor: "bottom",
|
|
1860
|
-
position: {
|
|
1861
|
-
x: location.x + actualSize.minX / 1.5,
|
|
1862
|
-
y: location.y + actualSize.minY
|
|
1863
|
-
},
|
|
1864
|
-
schematic_component_id: "SYNTHETIC",
|
|
1865
|
-
schematic_text_id: "SYNTHETIC",
|
|
1866
|
-
text: manufacturerPartNumber,
|
|
1867
|
-
type: "schematic_text"
|
|
1868
|
-
}
|
|
1869
|
-
}
|
|
1870
|
-
)
|
|
1871
|
-
] });
|
|
1872
|
-
};
|
|
1873
|
-
|
|
1874
|
-
// src/schematic-components/SimplePowerSource.tsx
|
|
1875
|
-
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
1876
|
-
var SimplePowerSource = ({
|
|
1877
|
-
component: { source, schematic }
|
|
1878
|
-
}) => {
|
|
1879
|
-
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
1880
|
-
SVGPathComponent_default,
|
|
1881
|
-
{
|
|
1882
|
-
rotation: schematic.rotation,
|
|
1883
|
-
center: schematic.center,
|
|
1884
|
-
size: schematic.size,
|
|
1885
|
-
invertY: true,
|
|
1886
|
-
paths: [
|
|
1887
|
-
{
|
|
1888
|
-
stroke: "red",
|
|
1889
|
-
strokeWidth: 1,
|
|
1890
|
-
d: "M 0 -17 L 0 -3 M -8 3 L 8 3 M 0 17 L 0 3 M -12 -3 L 12 -3"
|
|
1891
|
-
},
|
|
1892
|
-
// positive symbol
|
|
1893
|
-
{
|
|
1894
|
-
stroke: "red",
|
|
1895
|
-
strokeWidth: 0.5,
|
|
1896
|
-
d: "M 8 -9 L 8 -6 M 9.5 -7.5 L 6.5 -7.5"
|
|
1897
|
-
},
|
|
1898
|
-
// negative symbol
|
|
1899
|
-
{
|
|
1900
|
-
stroke: "red",
|
|
1901
|
-
strokeWidth: 0.5,
|
|
1902
|
-
d: "M 9.5 7.5 L 6.5 7.5"
|
|
1903
|
-
}
|
|
1904
|
-
]
|
|
1905
|
-
}
|
|
1906
|
-
);
|
|
1907
|
-
};
|
|
1908
|
-
|
|
1909
|
-
// src/schematic-components/SimpleGround.tsx
|
|
1910
|
-
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
1911
|
-
var SimpleGround = ({ component: { source, schematic } }) => {
|
|
1912
|
-
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
1913
|
-
SVGPathComponent_default,
|
|
1914
|
-
{
|
|
1915
|
-
rotation: schematic.rotation,
|
|
1916
|
-
center: schematic.center,
|
|
1917
|
-
size: schematic.size,
|
|
1918
|
-
invertY: true,
|
|
1919
|
-
shiftToBottom: true,
|
|
1920
|
-
paths: [
|
|
1921
|
-
{
|
|
1922
|
-
stroke: "red",
|
|
1923
|
-
strokeWidth: 0.7,
|
|
1924
|
-
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"
|
|
1925
|
-
}
|
|
1926
|
-
]
|
|
1927
|
-
}
|
|
1928
|
-
);
|
|
1929
|
-
};
|
|
1930
|
-
|
|
1931
|
-
// src/schematic-components/SimpleInductor.tsx
|
|
1932
|
-
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
1933
|
-
var SimpleInductor = ({ component: { source, schematic } }) => {
|
|
1934
|
-
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
1935
|
-
SVGPathComponent_default,
|
|
1936
|
-
{
|
|
1937
|
-
rotation: schematic.rotation,
|
|
1938
|
-
center: schematic.center,
|
|
1939
|
-
size: schematic.size,
|
|
1940
|
-
paths: [
|
|
1941
|
-
{
|
|
1942
|
-
stroke: "red",
|
|
1943
|
-
strokeWidth: 1,
|
|
1944
|
-
// https://commons.wikimedia.org/wiki/File:Electrical_symbols_library.svg
|
|
1945
|
-
d: "m 371,710.41665 h -14 c -0.0421,-16.39898 -14.02104,-16.39898 -14,0 -0.021,-16.399 -14.04182,-16.34072 -14,0 -2.6e-4,-16.45722 -14.04236,-16.45722 -14,0 2.8e-4,-16.3407 -13.97896,-16.39898 -14,0 -0.0421,-16.39898 -13.91338,-16.39898 -13.91338,0 H 273"
|
|
1946
|
-
}
|
|
1947
|
-
]
|
|
1948
|
-
}
|
|
1949
|
-
);
|
|
1950
|
-
};
|
|
1951
|
-
|
|
1952
|
-
// src/schematic-components/SimpleDiode.tsx
|
|
1953
|
-
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
1954
|
-
var SimpleDiode = ({ component: { source, schematic } }) => {
|
|
1955
|
-
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
1956
|
-
SVGPathComponent_default,
|
|
1957
|
-
{
|
|
1958
|
-
rotation: schematic.rotation,
|
|
1959
|
-
center: schematic.center,
|
|
1960
|
-
size: {
|
|
1961
|
-
height: 0.5,
|
|
1962
|
-
width: 1
|
|
1963
|
-
},
|
|
1964
|
-
paths: [
|
|
1965
|
-
{ stroke: "red", strokeWidth: 2, d: "M 0,0 H 21" },
|
|
1966
|
-
{ stroke: "red", strokeWidth: 2, d: "M 49,0 H 59" },
|
|
1967
|
-
{ stroke: "red", strokeWidth: 2, d: "M 49,0 L 21 14 V -14 Z" },
|
|
1968
|
-
{ stroke: "red", strokeWidth: 2, d: "M 49,-14 V 14" }
|
|
1969
|
-
// For LEDs
|
|
1970
|
-
// {
|
|
1971
|
-
// stroke: "red",
|
|
1972
|
-
// strokeWidth: 2,
|
|
1973
|
-
// d: "M 35 -32 l 7 5.25 l 1.75 -9.625 z m 3.5 2.625 l -5.25 7",
|
|
1974
|
-
// },
|
|
1975
|
-
// {
|
|
1976
|
-
// stroke: "red",
|
|
1977
|
-
// strokeWidth: 2,
|
|
1978
|
-
// d: "M 52 -26 l 7 5.25 l 1.75 -9.625 z m 3.5 2.625 l -5.25 7",
|
|
1979
|
-
// },
|
|
1980
|
-
]
|
|
1981
|
-
}
|
|
1982
|
-
);
|
|
1983
|
-
};
|
|
1984
|
-
|
|
1985
|
-
// src/schematic-components/ContextProviders.tsx
|
|
1986
|
-
var import_react5 = require("react");
|
|
1987
|
-
var import_react6 = require("react");
|
|
1988
|
-
var import_jsx_runtime16 = require("react/jsx-runtime");
|
|
1989
|
-
var StoreContext = (0, import_react6.createContext)(null);
|
|
1990
|
-
var ContextProviders = ({ children }) => {
|
|
1991
|
-
const store = (0, import_react5.useMemo)(() => createRenderContextStore(), []);
|
|
1992
|
-
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(StoreContext.Provider, { value: store, children });
|
|
1993
|
-
};
|
|
1994
|
-
|
|
1995
2044
|
// src/lib/render-context/index.ts
|
|
1996
2045
|
var createRenderContextStore = () => createStore((set) => ({
|
|
1997
2046
|
camera_transform: compose(scale(100, 100, 0, 0)),
|
|
1998
2047
|
setCameraTransform: (transform2) => set({ camera_transform: transform2 })
|
|
1999
2048
|
}));
|
|
2000
2049
|
var useGlobalStore = (s) => {
|
|
2001
|
-
const store = (0,
|
|
2050
|
+
const store = (0, import_react6.useContext)(StoreContext);
|
|
2002
2051
|
return useStore(store, s);
|
|
2003
2052
|
};
|
|
2004
2053
|
|
|
2005
2054
|
// src/Schematic.tsx
|
|
2006
|
-
var
|
|
2055
|
+
var import_react8 = require("react");
|
|
2007
2056
|
var import_react_error_boundary = require("react-error-boundary");
|
|
2008
2057
|
var import_react_supergrid = require("react-supergrid");
|
|
2009
2058
|
|
|
@@ -2032,68 +2081,13 @@ var collectElementRefs = (elm, allElms) => {
|
|
|
2032
2081
|
schematic: elm,
|
|
2033
2082
|
source: source_component,
|
|
2034
2083
|
source_component,
|
|
2035
|
-
source_port
|
|
2084
|
+
source_port,
|
|
2085
|
+
allElements: allElms
|
|
2036
2086
|
};
|
|
2037
2087
|
}
|
|
2038
2088
|
return null;
|
|
2039
2089
|
};
|
|
2040
2090
|
|
|
2041
|
-
// src/schematic-components/SchematicBox.tsx
|
|
2042
|
-
var import_jsx_runtime17 = require("react/jsx-runtime");
|
|
2043
|
-
var SchematicBox = ({ box: { schematic } }) => {
|
|
2044
|
-
const { width: w, height: h } = schematic;
|
|
2045
|
-
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
2046
|
-
SVGPathComponent,
|
|
2047
|
-
{
|
|
2048
|
-
rotation: 0,
|
|
2049
|
-
center: schematic,
|
|
2050
|
-
size: { width: schematic.width, height: schematic.height },
|
|
2051
|
-
paths: [
|
|
2052
|
-
{
|
|
2053
|
-
stroke: "red",
|
|
2054
|
-
strokeWidth: 0.02,
|
|
2055
|
-
d: `M 0 0 l ${w} 0 l 0 ${h} l -${w} 0 z`
|
|
2056
|
-
}
|
|
2057
|
-
]
|
|
2058
|
-
}
|
|
2059
|
-
);
|
|
2060
|
-
};
|
|
2061
|
-
var SchematicBox_default = SchematicBox;
|
|
2062
|
-
|
|
2063
|
-
// src/schematic-components/SchematicLine.tsx
|
|
2064
|
-
var import_svg_path_generator2 = __toESM(require_svg_path_generator2());
|
|
2065
|
-
var import_jsx_runtime18 = require("react/jsx-runtime");
|
|
2066
|
-
var SchematicLine = ({ line: { schematic } }) => {
|
|
2067
|
-
const { x1, x2, y1, y2 } = schematic;
|
|
2068
|
-
const dx = x2 - x1;
|
|
2069
|
-
const dy = y2 - y1;
|
|
2070
|
-
const path = (0, import_svg_path_generator2.default)();
|
|
2071
|
-
path.moveTo(x1, y1);
|
|
2072
|
-
path.lineTo(x2, y2);
|
|
2073
|
-
const d = path.toString();
|
|
2074
|
-
const pathBounds = get_svg_path_bounds_default(d);
|
|
2075
|
-
const center = {
|
|
2076
|
-
x: pathBounds.minX + pathBounds.width / 2,
|
|
2077
|
-
y: pathBounds.minY + pathBounds.height / 2
|
|
2078
|
-
};
|
|
2079
|
-
return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
|
2080
|
-
SVGPathComponent,
|
|
2081
|
-
{
|
|
2082
|
-
rotation: 0,
|
|
2083
|
-
center,
|
|
2084
|
-
size: pathBounds,
|
|
2085
|
-
paths: [
|
|
2086
|
-
{
|
|
2087
|
-
stroke: "red",
|
|
2088
|
-
strokeWidth: 0.02,
|
|
2089
|
-
d
|
|
2090
|
-
}
|
|
2091
|
-
]
|
|
2092
|
-
}
|
|
2093
|
-
);
|
|
2094
|
-
};
|
|
2095
|
-
var SchematicLine_default = SchematicLine;
|
|
2096
|
-
|
|
2097
2091
|
// src/lib/utils/get-rotation-from-anchor-side.ts
|
|
2098
2092
|
var getRotationFromAnchorSide = (anchor_side) => {
|
|
2099
2093
|
if (anchor_side === "left")
|
|
@@ -2121,7 +2115,7 @@ var getVecFromAnchorSide = (anchor_side) => {
|
|
|
2121
2115
|
};
|
|
2122
2116
|
|
|
2123
2117
|
// src/schematic-components/SchematicNetLabel.tsx
|
|
2124
|
-
var
|
|
2118
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
2125
2119
|
var SchematicNetLabel = ({
|
|
2126
2120
|
net_label
|
|
2127
2121
|
}) => {
|
|
@@ -2133,8 +2127,8 @@ var SchematicNetLabel = ({
|
|
|
2133
2127
|
const anchor_dist = is_vertical ? 0.04 : text_width / 4;
|
|
2134
2128
|
anchor_vec.x *= anchor_dist;
|
|
2135
2129
|
anchor_vec.y *= anchor_dist;
|
|
2136
|
-
return /* @__PURE__ */ (0,
|
|
2137
|
-
/* @__PURE__ */ (0,
|
|
2130
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
|
|
2131
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
2138
2132
|
SVGPathComponent_default,
|
|
2139
2133
|
{
|
|
2140
2134
|
rotation: getRotationFromAnchorSide(anchor_side),
|
|
@@ -2153,7 +2147,7 @@ var SchematicNetLabel = ({
|
|
|
2153
2147
|
]
|
|
2154
2148
|
}
|
|
2155
2149
|
),
|
|
2156
|
-
/* @__PURE__ */ (0,
|
|
2150
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
2157
2151
|
SchematicText_default,
|
|
2158
2152
|
{
|
|
2159
2153
|
schematic_text: {
|
|
@@ -2172,56 +2166,14 @@ var SchematicNetLabel = ({
|
|
|
2172
2166
|
] });
|
|
2173
2167
|
};
|
|
2174
2168
|
|
|
2175
|
-
// src/schematic-components/SchematicPath.tsx
|
|
2176
|
-
var import_svg_path_generator3 = __toESM(require_svg_path_generator2());
|
|
2177
|
-
var import_jsx_runtime20 = require("react/jsx-runtime");
|
|
2178
|
-
var SchematicPath = (props) => {
|
|
2179
|
-
const { points, is_filled, is_closed, fill_color } = props.path.schematic;
|
|
2180
|
-
if (points.length === 0)
|
|
2181
|
-
return null;
|
|
2182
|
-
const path = (0, import_svg_path_generator3.default)();
|
|
2183
|
-
path.moveTo(points[0].x, points[0].y);
|
|
2184
|
-
for (const point of points.slice(1)) {
|
|
2185
|
-
path.lineTo(point.x, point.y);
|
|
2186
|
-
}
|
|
2187
|
-
if (is_closed) {
|
|
2188
|
-
path.closePath();
|
|
2189
|
-
}
|
|
2190
|
-
const d = path.toString();
|
|
2191
|
-
const pathBounds = get_svg_path_bounds_default(d);
|
|
2192
|
-
pathBounds.height = Math.max(pathBounds.height, 1);
|
|
2193
|
-
pathBounds.width = Math.max(pathBounds.width, 1);
|
|
2194
|
-
const center = {
|
|
2195
|
-
x: pathBounds.minX + pathBounds.width / 2,
|
|
2196
|
-
y: pathBounds.minY + pathBounds.height / 2
|
|
2197
|
-
};
|
|
2198
|
-
return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
|
|
2199
|
-
SVGPathComponent,
|
|
2200
|
-
{
|
|
2201
|
-
rotation: 0,
|
|
2202
|
-
center,
|
|
2203
|
-
size: pathBounds,
|
|
2204
|
-
paths: [
|
|
2205
|
-
{
|
|
2206
|
-
stroke: is_filled ? "none" : fill_color ?? "red",
|
|
2207
|
-
strokeWidth: 0.02,
|
|
2208
|
-
fill: is_filled ? fill_color ?? "red" : void 0,
|
|
2209
|
-
d
|
|
2210
|
-
}
|
|
2211
|
-
]
|
|
2212
|
-
}
|
|
2213
|
-
);
|
|
2214
|
-
};
|
|
2215
|
-
var SchematicPath_default = SchematicPath;
|
|
2216
|
-
|
|
2217
2169
|
// src/schematic-components/SchematicElement.tsx
|
|
2218
|
-
var
|
|
2170
|
+
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
2219
2171
|
var SchematicElement = ({
|
|
2220
2172
|
element,
|
|
2221
2173
|
allElements
|
|
2222
2174
|
}) => {
|
|
2223
2175
|
if (element.type === "schematic_component") {
|
|
2224
|
-
return /* @__PURE__ */ (0,
|
|
2176
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
2225
2177
|
SchematicComponent_default,
|
|
2226
2178
|
{
|
|
2227
2179
|
component: collectElementRefs(element, allElements)
|
|
@@ -2229,47 +2181,32 @@ var SchematicElement = ({
|
|
|
2229
2181
|
);
|
|
2230
2182
|
}
|
|
2231
2183
|
if (element.type === "schematic_trace") {
|
|
2232
|
-
return /* @__PURE__ */ (0,
|
|
2233
|
-
}
|
|
2234
|
-
if (element.type === "schematic_port") {
|
|
2235
|
-
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(SchematicPort_default, { port: collectElementRefs(element, allElements) });
|
|
2236
|
-
}
|
|
2237
|
-
if (element.type === "schematic_box") {
|
|
2238
|
-
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(SchematicBox_default, { box: collectElementRefs(element, allElements) });
|
|
2239
|
-
}
|
|
2240
|
-
if (element.type === "schematic_line") {
|
|
2241
|
-
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(SchematicLine_default, { line: collectElementRefs(element, allElements) });
|
|
2242
|
-
}
|
|
2243
|
-
if (element.type === "schematic_path") {
|
|
2244
|
-
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(SchematicPath_default, { path: collectElementRefs(element, allElements) });
|
|
2184
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(SchematicTrace_default, { trace: collectElementRefs(element, allElements) });
|
|
2245
2185
|
}
|
|
2246
2186
|
if (element.type === "schematic_text") {
|
|
2247
|
-
return /* @__PURE__ */ (0,
|
|
2187
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(SchematicText_default, { schematic_text: element });
|
|
2248
2188
|
}
|
|
2249
2189
|
if (element.type === "schematic_net_label") {
|
|
2250
|
-
return /* @__PURE__ */ (0,
|
|
2190
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(SchematicNetLabel, { net_label: element });
|
|
2251
2191
|
}
|
|
2252
2192
|
return null;
|
|
2253
2193
|
};
|
|
2254
2194
|
|
|
2255
|
-
// src/Schematic.tsx
|
|
2256
|
-
var import_use_mouse_matrix_transform = require("use-mouse-matrix-transform");
|
|
2257
|
-
|
|
2258
2195
|
// src/schematic-components/TableViewer.tsx
|
|
2259
|
-
var
|
|
2260
|
-
var
|
|
2261
|
-
var LazyTableViewer = (0,
|
|
2196
|
+
var import_react7 = require("react");
|
|
2197
|
+
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
2198
|
+
var LazyTableViewer = (0, import_react7.lazy)(
|
|
2262
2199
|
() => import("@tscircuit/table-viewer").then((m) => ({
|
|
2263
2200
|
default: m.SoupTableViewer
|
|
2264
2201
|
}))
|
|
2265
2202
|
);
|
|
2266
|
-
var TableViewer = (params) => /* @__PURE__ */ (0,
|
|
2203
|
+
var TableViewer = (params) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_react7.Suspense, { fallback: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { children: "Loading..." }), children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(LazyTableViewer, { ...params }) });
|
|
2267
2204
|
|
|
2268
2205
|
// src/Schematic.tsx
|
|
2269
|
-
var
|
|
2206
|
+
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
2270
2207
|
var ErrorBoundary = import_react_error_boundary.ErrorBoundary;
|
|
2271
2208
|
var fallbackRender = (elm) => ({ error, resetErrorBoundary }) => {
|
|
2272
|
-
return /* @__PURE__ */ (0,
|
|
2209
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { style: { color: "red" }, children: [
|
|
2273
2210
|
"error rendering ",
|
|
2274
2211
|
elm.type,
|
|
2275
2212
|
": ",
|
|
@@ -2278,70 +2215,136 @@ var fallbackRender = (elm) => ({ error, resetErrorBoundary }) => {
|
|
|
2278
2215
|
};
|
|
2279
2216
|
var toMMSINeg = (v, z) => v >= 0 ? (0, import_react_supergrid.toMMSI)(v, z) : `-${(0, import_react_supergrid.toMMSI)(-v, z)}`;
|
|
2280
2217
|
var Schematic = (props) => {
|
|
2281
|
-
return /* @__PURE__ */ (0,
|
|
2218
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(ContextProviders, { children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(SchematicWithoutContext, { ...props }) });
|
|
2282
2219
|
};
|
|
2283
2220
|
var SchematicWithoutContext = ({
|
|
2284
2221
|
children,
|
|
2285
|
-
|
|
2286
|
-
soup: initialSoup,
|
|
2222
|
+
soup,
|
|
2287
2223
|
style,
|
|
2288
2224
|
showTable = false,
|
|
2289
2225
|
_soupPostProcessor
|
|
2290
2226
|
}) => {
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2227
|
+
const {
|
|
2228
|
+
circuitJson: circuitJsonFromChildren,
|
|
2229
|
+
error: errorFromChildren,
|
|
2230
|
+
isLoading
|
|
2231
|
+
} = (0, import_core.useRenderedCircuit)(children);
|
|
2232
|
+
const [elements, setElements] = (0, import_react8.useState)([]);
|
|
2233
|
+
const { setCameraTransform } = useGlobalStore();
|
|
2295
2234
|
const [boundsRef, bounds] = useMeasure();
|
|
2296
|
-
const
|
|
2297
|
-
|
|
2298
|
-
|
|
2235
|
+
const containerRef = (0, import_react8.useRef)(null);
|
|
2236
|
+
const transformRef = (0, import_react8.useRef)(compose(translate(0, 0), scale(1, 1)));
|
|
2237
|
+
const isDraggingRef = (0, import_react8.useRef)(false);
|
|
2238
|
+
const lastMousePosRef = (0, import_react8.useRef)({ x: 0, y: 0 });
|
|
2239
|
+
const [, forceUpdate] = (0, import_react8.useState)({});
|
|
2240
|
+
const updateTransform = (0, import_react8.useCallback)(
|
|
2241
|
+
(newTransform) => {
|
|
2242
|
+
transformRef.current = newTransform;
|
|
2243
|
+
setCameraTransform(newTransform);
|
|
2244
|
+
forceUpdate({});
|
|
2245
|
+
},
|
|
2246
|
+
[setCameraTransform]
|
|
2247
|
+
);
|
|
2248
|
+
(0, import_react8.useEffect)(() => {
|
|
2249
|
+
let processedElements = [];
|
|
2250
|
+
if (circuitJsonFromChildren && (!soup || soup.length === 0)) {
|
|
2251
|
+
processedElements = circuitJsonFromChildren;
|
|
2252
|
+
} else if (soup && soup.length > 0) {
|
|
2253
|
+
processedElements = soup;
|
|
2299
2254
|
}
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2255
|
+
if (processedElements.length > 0) {
|
|
2256
|
+
if (_soupPostProcessor) {
|
|
2257
|
+
processedElements = _soupPostProcessor(processedElements);
|
|
2258
|
+
}
|
|
2259
|
+
setElements(processedElements);
|
|
2260
|
+
}
|
|
2261
|
+
}, [circuitJsonFromChildren, soup, _soupPostProcessor]);
|
|
2262
|
+
(0, import_react8.useEffect)(() => {
|
|
2263
|
+
if (elements.length > 0 && containerRef.current) {
|
|
2264
|
+
const elmBounds = containerRef.current.getBoundingClientRect();
|
|
2265
|
+
const { center, width, height } = elements.some(
|
|
2306
2266
|
(e) => e.type.startsWith("schematic_")
|
|
2307
|
-
) ? (0,
|
|
2308
|
-
|
|
2267
|
+
) ? (0, import_soup_util.findBoundsAndCenter)(
|
|
2268
|
+
elements.filter((e) => e.type.startsWith("schematic_"))
|
|
2309
2269
|
) : { center: { x: 0, y: 0 }, width: 1e-3, height: 1e-3 };
|
|
2310
2270
|
const scaleFactor = Math.min(
|
|
2311
2271
|
(elmBounds.width ?? 0) / width,
|
|
2312
2272
|
(elmBounds.height ?? 0) / height,
|
|
2313
2273
|
100
|
|
2314
2274
|
);
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
translate((elmBounds.width ?? 0) / 2, (elmBounds.height ?? 0) / 2),
|
|
2320
|
-
scale(scaleFactor, -scaleFactor, 0, 0),
|
|
2321
|
-
translate(-center.x, -center.y)
|
|
2322
|
-
)
|
|
2275
|
+
const newTransform = compose(
|
|
2276
|
+
translate((elmBounds.width ?? 0) / 2, (elmBounds.height ?? 0) / 2),
|
|
2277
|
+
scale(scaleFactor, -scaleFactor, 0, 0),
|
|
2278
|
+
translate(-center.x, -center.y)
|
|
2323
2279
|
);
|
|
2280
|
+
updateTransform(newTransform);
|
|
2281
|
+
}
|
|
2282
|
+
}, [elements, bounds.width, bounds.height, updateTransform]);
|
|
2283
|
+
const handleMouseDown = (0, import_react8.useCallback)((e) => {
|
|
2284
|
+
isDraggingRef.current = true;
|
|
2285
|
+
lastMousePosRef.current = { x: e.clientX, y: e.clientY };
|
|
2286
|
+
}, []);
|
|
2287
|
+
const handleMouseMove = (0, import_react8.useCallback)(
|
|
2288
|
+
(e) => {
|
|
2289
|
+
if (!isDraggingRef.current)
|
|
2290
|
+
return;
|
|
2291
|
+
const dx = e.clientX - lastMousePosRef.current.x;
|
|
2292
|
+
const dy = e.clientY - lastMousePosRef.current.y;
|
|
2293
|
+
lastMousePosRef.current = { x: e.clientX, y: e.clientY };
|
|
2294
|
+
const scale2 = transformRef.current.a;
|
|
2295
|
+
const dragSensitivity = 150 / scale2;
|
|
2296
|
+
const newTransform = compose(
|
|
2297
|
+
translate(dx * dragSensitivity, dy * dragSensitivity),
|
|
2298
|
+
transformRef.current
|
|
2299
|
+
);
|
|
2300
|
+
updateTransform(newTransform);
|
|
2324
2301
|
},
|
|
2325
|
-
[
|
|
2302
|
+
[updateTransform]
|
|
2326
2303
|
);
|
|
2327
|
-
(0,
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
if (
|
|
2335
|
-
|
|
2304
|
+
const handleMouseUp = (0, import_react8.useCallback)(() => {
|
|
2305
|
+
isDraggingRef.current = false;
|
|
2306
|
+
}, []);
|
|
2307
|
+
const handleWheel = (0, import_react8.useCallback)(
|
|
2308
|
+
(e) => {
|
|
2309
|
+
e.preventDefault();
|
|
2310
|
+
const scaleMultiplier = Math.pow(0.999, e.deltaY);
|
|
2311
|
+
if (containerRef.current) {
|
|
2312
|
+
const rect = containerRef.current.getBoundingClientRect();
|
|
2313
|
+
const mouseX = e.clientX - rect.left;
|
|
2314
|
+
const mouseY = e.clientY - rect.top;
|
|
2315
|
+
const inverseTransform = inverse(transformRef.current);
|
|
2316
|
+
const transformedPoint = applyToPoint(inverseTransform, {
|
|
2317
|
+
x: mouseX,
|
|
2318
|
+
y: mouseY
|
|
2319
|
+
});
|
|
2320
|
+
const newTransform = compose(
|
|
2321
|
+
transformRef.current,
|
|
2322
|
+
translate(transformedPoint.x, transformedPoint.y),
|
|
2323
|
+
scale(scaleMultiplier, scaleMultiplier),
|
|
2324
|
+
translate(-transformedPoint.x, -transformedPoint.y)
|
|
2325
|
+
);
|
|
2326
|
+
updateTransform(newTransform);
|
|
2336
2327
|
}
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2328
|
+
},
|
|
2329
|
+
[updateTransform]
|
|
2330
|
+
);
|
|
2331
|
+
(0, import_react8.useEffect)(() => {
|
|
2332
|
+
const container = containerRef.current;
|
|
2333
|
+
if (container) {
|
|
2334
|
+
container.addEventListener("wheel", handleWheel, { passive: false });
|
|
2335
|
+
return () => {
|
|
2336
|
+
container.removeEventListener("wheel", handleWheel);
|
|
2337
|
+
};
|
|
2338
|
+
}
|
|
2339
|
+
}, [handleWheel]);
|
|
2340
|
+
if (errorFromChildren) {
|
|
2341
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { children: [
|
|
2342
|
+
"Error: ",
|
|
2343
|
+
errorFromChildren.message
|
|
2344
|
+
] });
|
|
2345
|
+
}
|
|
2346
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_jsx_runtime12.Fragment, { children: [
|
|
2347
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
|
|
2345
2348
|
"div",
|
|
2346
2349
|
{
|
|
2347
2350
|
style: {
|
|
@@ -2351,15 +2354,19 @@ var SchematicWithoutContext = ({
|
|
|
2351
2354
|
overflow: "hidden",
|
|
2352
2355
|
position: "relative",
|
|
2353
2356
|
isolation: "isolate",
|
|
2354
|
-
cursor: "grab",
|
|
2357
|
+
cursor: isDraggingRef.current ? "grabbing" : "grab",
|
|
2355
2358
|
...style
|
|
2356
2359
|
},
|
|
2357
2360
|
ref: (el) => {
|
|
2358
|
-
|
|
2361
|
+
containerRef.current = el;
|
|
2359
2362
|
boundsRef(el);
|
|
2360
2363
|
},
|
|
2364
|
+
onMouseDown: handleMouseDown,
|
|
2365
|
+
onMouseMove: handleMouseMove,
|
|
2366
|
+
onMouseUp: handleMouseUp,
|
|
2367
|
+
onMouseLeave: handleMouseUp,
|
|
2361
2368
|
children: [
|
|
2362
|
-
/* @__PURE__ */ (0,
|
|
2369
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
2363
2370
|
import_react_supergrid.SuperGrid,
|
|
2364
2371
|
{
|
|
2365
2372
|
stringifyCoord: (x, y, z) => {
|
|
@@ -2369,10 +2376,10 @@ var SchematicWithoutContext = ({
|
|
|
2369
2376
|
},
|
|
2370
2377
|
width: bounds.width,
|
|
2371
2378
|
height: bounds.height,
|
|
2372
|
-
transform:
|
|
2379
|
+
transform: transformRef.current
|
|
2373
2380
|
}
|
|
2374
2381
|
),
|
|
2375
|
-
elements?.map((elm, i) => /* @__PURE__ */ (0,
|
|
2382
|
+
elements?.map((elm, i) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(ErrorBoundary, { fallbackRender: fallbackRender(elm), children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
2376
2383
|
SchematicElement,
|
|
2377
2384
|
{
|
|
2378
2385
|
element: elm,
|
|
@@ -2383,7 +2390,7 @@ var SchematicWithoutContext = ({
|
|
|
2383
2390
|
]
|
|
2384
2391
|
}
|
|
2385
2392
|
),
|
|
2386
|
-
showTable !== false && elements && /* @__PURE__ */ (0,
|
|
2393
|
+
showTable !== false && elements && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(TableViewer, { elements })
|
|
2387
2394
|
] });
|
|
2388
2395
|
};
|
|
2389
2396
|
// Annotate the CommonJS export names for ESM import in node:
|