@tscircuit/schematic-viewer 1.4.3 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/.github/workflows/bun-pver-release.yml +24 -0
  2. package/.github/workflows/{npm-typecheck.yml → bun-typecheck.yml} +6 -6
  3. package/LICENSE +21 -0
  4. package/README.md +16 -26
  5. package/biome.json +8 -1
  6. package/bun.lockb +0 -0
  7. package/cosmos.config.json +3 -0
  8. package/cosmos.decorator.tsx +3 -0
  9. package/examples/resistor-and-capacitor.fixture.tsx +14 -0
  10. package/index.html +12 -0
  11. package/lib/components/SchematicViewer.tsx +79 -0
  12. package/lib/dev/render-to-circuit-json.ts +7 -0
  13. package/lib/index.ts +1 -0
  14. package/package.json +27 -74
  15. package/src/main.tsx +20 -0
  16. package/test.ts +0 -0
  17. package/tsconfig.json +28 -25
  18. package/vite.config.js +12 -4
  19. package/.codesandbox/tasks.json +0 -36
  20. package/.github/workflows/chromatic.yml +0 -30
  21. package/.github/workflows/npm-build.yml +0 -26
  22. package/.github/workflows/release.yml +0 -29
  23. package/.prettierrc +0 -1
  24. package/.storybook/main.ts +0 -12
  25. package/.storybook/preview.ts +0 -17
  26. package/ava.config.js +0 -7
  27. package/dist/index.css +0 -7
  28. package/dist/index.css.map +0 -1
  29. package/dist/index.d.ts +0 -15
  30. package/dist/index.js +0 -2502
  31. package/dist/index.js.map +0 -1
  32. package/next-env.d.ts +0 -5
  33. package/parsel.d.ts +0 -81
  34. package/release.config.js +0 -15
  35. package/renovate.json +0 -17
  36. package/src/Schematic.tsx +0 -250
  37. package/src/index.ts +0 -1
  38. package/src/lib/hooks/index.ts +0 -1
  39. package/src/lib/hooks/use-maybe-promise.ts +0 -14
  40. package/src/lib/render-context/index.ts +0 -28
  41. package/src/lib/types/core.ts +0 -181
  42. package/src/lib/types/index.ts +0 -4
  43. package/src/lib/types/route-solver.ts +0 -10
  44. package/src/lib/types/source-component.ts +0 -73
  45. package/src/lib/types/util.ts +0 -52
  46. package/src/lib/utils/collect-element-refs.ts +0 -45
  47. package/src/lib/utils/colors.ts +0 -235
  48. package/src/lib/utils/direction-to-vec.ts +0 -50
  49. package/src/lib/utils/get-rotation-from-anchor-side.ts +0 -11
  50. package/src/lib/utils/get-svg-path-bounds.ts +0 -22
  51. package/src/lib/utils/get-vec-from-anchor-side.ts +0 -11
  52. package/src/lib/utils/point-math.ts +0 -26
  53. package/src/pages/_app.tsx +0 -23
  54. package/src/pages/index.tsx +0 -10
  55. package/src/pages/led-circuit-react.tsx +0 -54
  56. package/src/pages/style.css +0 -5
  57. package/src/schematic-components/ContextProviders.tsx +0 -15
  58. package/src/schematic-components/DebugPoint.tsx +0 -25
  59. package/src/schematic-components/RenderError.tsx +0 -23
  60. package/src/schematic-components/SVGPathComponent.tsx +0 -183
  61. package/src/schematic-components/SVGPathComponent2.tsx +0 -76
  62. package/src/schematic-components/SchematicChip.tsx +0 -202
  63. package/src/schematic-components/SchematicComponent.tsx +0 -51
  64. package/src/schematic-components/SchematicComponentFromSymbol.tsx +0 -46
  65. package/src/schematic-components/SchematicElement.tsx +0 -43
  66. package/src/schematic-components/SchematicGroup.tsx +0 -3
  67. package/src/schematic-components/SchematicNetLabel.tsx +0 -63
  68. package/src/schematic-components/SchematicText.tsx +0 -44
  69. package/src/schematic-components/SchematicTrace.tsx +0 -51
  70. package/src/schematic-components/TableViewer.tsx +0 -13
  71. package/src/schematic-components/index.tsx +0 -9
  72. package/src/stories/basics/schematic-net-label.stories.tsx +0 -138
  73. package/src/stories/basics/schematic-net-labels-2.stories.tsx +0 -35
  74. package/src/stories/bug-connections.stories.tsx +0 -31
  75. package/src/stories/bug-high-port-numbers.stories.tsx +0 -130
  76. package/src/stories/bug-one-sided.stories.tsx +0 -34
  77. package/src/stories/bug-pin-spacing.stories.tsx +0 -52
  78. package/src/stories/bugs/bug1-y-flip.stories.tsx +0 -20
  79. package/src/stories/bugs/bug2-component-bounds.stories.tsx +0 -62
  80. package/src/stories/bugs/bug3-scaling-trace.stories.tsx +0 -24
  81. package/src/stories/bugs/bug4-schematic-line.stories.tsx +0 -17
  82. package/src/stories/bugs/bug5-diode.stories.tsx +0 -16
  83. package/src/stories/bugs/bug6-trace-scaling.stories.tsx +0 -18
  84. package/src/stories/bugs/bug7-multiple-schematic-panning.stories.tsx +0 -23
  85. package/src/stories/bugs/bug8-autolayout.stories.tsx +0 -43
  86. package/src/stories/circuit-components/diode.stories.tsx +0 -16
  87. package/src/stories/circuit-components/netalias.stories.tsx +0 -14
  88. package/src/stories/circuit-components/resistor.stories.tsx +0 -16
  89. package/src/stories/component-drawing-example.stories.tsx +0 -17
  90. package/src/stories/led-circuit-react.stories.tsx +0 -48
  91. package/src/stories/net-alias.stories.tsx +0 -92
  92. package/src/stories/off-center-render.stories.tsx +0 -29
  93. package/src/stories/rotated-resistor.stories.tsx +0 -23
  94. package/src/stories/schematic-path.stories.tsx +0 -40
  95. package/src/stories/three-sided-bug.stories.tsx +0 -30
  96. package/tsconfig.tsbuildinfo +0 -1
  97. package/tsup.config.ts +0 -8
  98. package/vercel.json +0 -3
package/dist/index.js DELETED
@@ -1,2502 +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 __esm = (fn, res) => function __init() {
8
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
9
- };
10
- var __commonJS = (cb, mod) => function __require() {
11
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
12
- };
13
- var __export = (target, all) => {
14
- for (var name in all)
15
- __defProp(target, name, { get: all[name], enumerable: true });
16
- };
17
- var __copyProps = (to, from, except, desc) => {
18
- if (from && typeof from === "object" || typeof from === "function") {
19
- for (let key of __getOwnPropNames(from))
20
- if (!__hasOwnProp.call(to, key) && key !== except)
21
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
22
- }
23
- return to;
24
- };
25
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
26
- // If the importer is in node compatibility mode or this is not an ESM
27
- // file that has been converted to a CommonJS file using a Babel-
28
- // compatible transform (i.e. "__esModule" has not been set), then set
29
- // "default" to the CommonJS "module.exports" for node compatibility.
30
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
31
- mod
32
- ));
33
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
34
-
35
- // node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.js
36
- var require_use_sync_external_store_shim_production_min = __commonJS({
37
- "node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.js"(exports) {
38
- "use strict";
39
- var e = require("react");
40
- function h(a, b) {
41
- return a === b && (0 !== a || 1 / a === 1 / b) || a !== a && b !== b;
42
- }
43
- var k = "function" === typeof Object.is ? Object.is : h;
44
- var l = e.useState;
45
- var m = e.useEffect;
46
- var n = e.useLayoutEffect;
47
- var p = e.useDebugValue;
48
- function q(a, b) {
49
- var d = b(), f = l({ inst: { value: d, getSnapshot: b } }), c = f[0].inst, g = f[1];
50
- n(function() {
51
- c.value = d;
52
- c.getSnapshot = b;
53
- r(c) && g({ inst: c });
54
- }, [a, d, b]);
55
- m(function() {
56
- r(c) && g({ inst: c });
57
- return a(function() {
58
- r(c) && g({ inst: c });
59
- });
60
- }, [a]);
61
- p(d);
62
- return d;
63
- }
64
- function r(a) {
65
- var b = a.getSnapshot;
66
- a = a.value;
67
- try {
68
- var d = b();
69
- return !k(a, d);
70
- } catch (f) {
71
- return true;
72
- }
73
- }
74
- function t(a, b) {
75
- return b();
76
- }
77
- var u = "undefined" === typeof window || "undefined" === typeof window.document || "undefined" === typeof window.document.createElement ? t : q;
78
- exports.useSyncExternalStore = void 0 !== e.useSyncExternalStore ? e.useSyncExternalStore : u;
79
- }
80
- });
81
-
82
- // node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js
83
- var require_use_sync_external_store_shim_development = __commonJS({
84
- "node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js"(exports) {
85
- "use strict";
86
- if (process.env.NODE_ENV !== "production") {
87
- (function() {
88
- "use strict";
89
- if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart === "function") {
90
- __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
91
- }
92
- var React = require("react");
93
- var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
94
- function error(format) {
95
- {
96
- {
97
- for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
98
- args[_key2 - 1] = arguments[_key2];
99
- }
100
- printWarning("error", format, args);
101
- }
102
- }
103
- }
104
- function printWarning(level, format, args) {
105
- {
106
- var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
107
- var stack = ReactDebugCurrentFrame.getStackAddendum();
108
- if (stack !== "") {
109
- format += "%s";
110
- args = args.concat([stack]);
111
- }
112
- var argsWithFormat = args.map(function(item) {
113
- return String(item);
114
- });
115
- argsWithFormat.unshift("Warning: " + format);
116
- Function.prototype.apply.call(console[level], console, argsWithFormat);
117
- }
118
- }
119
- function is(x, y) {
120
- return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y;
121
- }
122
- var objectIs = typeof Object.is === "function" ? Object.is : is;
123
- var useState4 = React.useState, useEffect3 = React.useEffect, useLayoutEffect = React.useLayoutEffect, useDebugValue2 = React.useDebugValue;
124
- var didWarnOld18Alpha = false;
125
- var didWarnUncachedGetSnapshot = false;
126
- function useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot) {
127
- {
128
- if (!didWarnOld18Alpha) {
129
- if (React.startTransition !== void 0) {
130
- didWarnOld18Alpha = true;
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
- }
133
- }
134
- }
135
- var value = getSnapshot();
136
- {
137
- if (!didWarnUncachedGetSnapshot) {
138
- var cachedValue = getSnapshot();
139
- if (!objectIs(value, cachedValue)) {
140
- error("The result of getSnapshot should be cached to avoid an infinite loop");
141
- didWarnUncachedGetSnapshot = true;
142
- }
143
- }
144
- }
145
- var _useState = useState4({
146
- inst: {
147
- value,
148
- getSnapshot
149
- }
150
- }), inst = _useState[0].inst, forceUpdate = _useState[1];
151
- useLayoutEffect(function() {
152
- inst.value = value;
153
- inst.getSnapshot = getSnapshot;
154
- if (checkIfSnapshotChanged(inst)) {
155
- forceUpdate({
156
- inst
157
- });
158
- }
159
- }, [subscribe, value, getSnapshot]);
160
- useEffect3(function() {
161
- if (checkIfSnapshotChanged(inst)) {
162
- forceUpdate({
163
- inst
164
- });
165
- }
166
- var handleStoreChange = function() {
167
- if (checkIfSnapshotChanged(inst)) {
168
- forceUpdate({
169
- inst
170
- });
171
- }
172
- };
173
- return subscribe(handleStoreChange);
174
- }, [subscribe]);
175
- useDebugValue2(value);
176
- return value;
177
- }
178
- function checkIfSnapshotChanged(inst) {
179
- var latestGetSnapshot = inst.getSnapshot;
180
- var prevValue = inst.value;
181
- try {
182
- var nextValue = latestGetSnapshot();
183
- return !objectIs(prevValue, nextValue);
184
- } catch (error2) {
185
- return true;
186
- }
187
- }
188
- function useSyncExternalStore$1(subscribe, getSnapshot, getServerSnapshot) {
189
- return getSnapshot();
190
- }
191
- var canUseDOM = !!(typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined");
192
- var isServerEnvironment = !canUseDOM;
193
- var shim = isServerEnvironment ? useSyncExternalStore$1 : useSyncExternalStore;
194
- var useSyncExternalStore$2 = React.useSyncExternalStore !== void 0 ? React.useSyncExternalStore : shim;
195
- exports.useSyncExternalStore = useSyncExternalStore$2;
196
- if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop === "function") {
197
- __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
198
- }
199
- })();
200
- }
201
- }
202
- });
203
-
204
- // node_modules/use-sync-external-store/shim/index.js
205
- var require_shim = __commonJS({
206
- "node_modules/use-sync-external-store/shim/index.js"(exports, module2) {
207
- "use strict";
208
- if (process.env.NODE_ENV === "production") {
209
- module2.exports = require_use_sync_external_store_shim_production_min();
210
- } else {
211
- module2.exports = require_use_sync_external_store_shim_development();
212
- }
213
- }
214
- });
215
-
216
- // node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.js
217
- var require_with_selector_production_min = __commonJS({
218
- "node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.js"(exports) {
219
- "use strict";
220
- var h = require("react");
221
- var n = require_shim();
222
- function p(a, b) {
223
- return a === b && (0 !== a || 1 / a === 1 / b) || a !== a && b !== b;
224
- }
225
- var q = "function" === typeof Object.is ? Object.is : p;
226
- var r = n.useSyncExternalStore;
227
- var t = h.useRef;
228
- var u = h.useEffect;
229
- var v = h.useMemo;
230
- var w = h.useDebugValue;
231
- exports.useSyncExternalStoreWithSelector = function(a, b, e, l, g) {
232
- var c = t(null);
233
- if (null === c.current) {
234
- var f = { hasValue: false, value: null };
235
- c.current = f;
236
- } else
237
- f = c.current;
238
- c = v(function() {
239
- function a2(a3) {
240
- if (!c2) {
241
- c2 = true;
242
- d2 = a3;
243
- a3 = l(a3);
244
- if (void 0 !== g && f.hasValue) {
245
- var b2 = f.value;
246
- if (g(b2, a3))
247
- return k = b2;
248
- }
249
- return k = a3;
250
- }
251
- b2 = k;
252
- if (q(d2, a3))
253
- return b2;
254
- var e2 = l(a3);
255
- if (void 0 !== g && g(b2, e2))
256
- return b2;
257
- d2 = a3;
258
- return k = e2;
259
- }
260
- var c2 = false, d2, k, m = void 0 === e ? null : e;
261
- return [function() {
262
- return a2(b());
263
- }, null === m ? void 0 : function() {
264
- return a2(m());
265
- }];
266
- }, [b, e, l, g]);
267
- var d = r(a, c[0], c[1]);
268
- u(function() {
269
- f.hasValue = true;
270
- f.value = d;
271
- }, [d]);
272
- w(d);
273
- return d;
274
- };
275
- }
276
- });
277
-
278
- // node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js
279
- var require_with_selector_development = __commonJS({
280
- "node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js"(exports) {
281
- "use strict";
282
- if (process.env.NODE_ENV !== "production") {
283
- (function() {
284
- "use strict";
285
- if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart === "function") {
286
- __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
287
- }
288
- var React = require("react");
289
- var shim = require_shim();
290
- function is(x, y) {
291
- return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y;
292
- }
293
- var objectIs = typeof Object.is === "function" ? Object.is : is;
294
- var useSyncExternalStore = shim.useSyncExternalStore;
295
- var useRef3 = React.useRef, useEffect3 = React.useEffect, useMemo3 = React.useMemo, useDebugValue2 = React.useDebugValue;
296
- function useSyncExternalStoreWithSelector2(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
297
- var instRef = useRef3(null);
298
- var inst;
299
- if (instRef.current === null) {
300
- inst = {
301
- hasValue: false,
302
- value: null
303
- };
304
- instRef.current = inst;
305
- } else {
306
- inst = instRef.current;
307
- }
308
- var _useMemo = useMemo3(function() {
309
- var hasMemo = false;
310
- var memoizedSnapshot;
311
- var memoizedSelection;
312
- var memoizedSelector = function(nextSnapshot) {
313
- if (!hasMemo) {
314
- hasMemo = true;
315
- memoizedSnapshot = nextSnapshot;
316
- var _nextSelection = selector(nextSnapshot);
317
- if (isEqual !== void 0) {
318
- if (inst.hasValue) {
319
- var currentSelection = inst.value;
320
- if (isEqual(currentSelection, _nextSelection)) {
321
- memoizedSelection = currentSelection;
322
- return currentSelection;
323
- }
324
- }
325
- }
326
- memoizedSelection = _nextSelection;
327
- return _nextSelection;
328
- }
329
- var prevSnapshot = memoizedSnapshot;
330
- var prevSelection = memoizedSelection;
331
- if (objectIs(prevSnapshot, nextSnapshot)) {
332
- return prevSelection;
333
- }
334
- var nextSelection = selector(nextSnapshot);
335
- if (isEqual !== void 0 && isEqual(prevSelection, nextSelection)) {
336
- return prevSelection;
337
- }
338
- memoizedSnapshot = nextSnapshot;
339
- memoizedSelection = nextSelection;
340
- return nextSelection;
341
- };
342
- var maybeGetServerSnapshot = getServerSnapshot === void 0 ? null : getServerSnapshot;
343
- var getSnapshotWithSelector = function() {
344
- return memoizedSelector(getSnapshot());
345
- };
346
- var getServerSnapshotWithSelector = maybeGetServerSnapshot === null ? void 0 : function() {
347
- return memoizedSelector(maybeGetServerSnapshot());
348
- };
349
- return [getSnapshotWithSelector, getServerSnapshotWithSelector];
350
- }, [getSnapshot, getServerSnapshot, selector, isEqual]), getSelection = _useMemo[0], getServerSelection = _useMemo[1];
351
- var value = useSyncExternalStore(subscribe, getSelection, getServerSelection);
352
- useEffect3(function() {
353
- inst.hasValue = true;
354
- inst.value = value;
355
- }, [value]);
356
- useDebugValue2(value);
357
- return value;
358
- }
359
- exports.useSyncExternalStoreWithSelector = useSyncExternalStoreWithSelector2;
360
- if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop === "function") {
361
- __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
362
- }
363
- })();
364
- }
365
- }
366
- });
367
-
368
- // node_modules/use-sync-external-store/shim/with-selector.js
369
- var require_with_selector = __commonJS({
370
- "node_modules/use-sync-external-store/shim/with-selector.js"(exports, module2) {
371
- "use strict";
372
- if (process.env.NODE_ENV === "production") {
373
- module2.exports = require_with_selector_production_min();
374
- } else {
375
- module2.exports = require_with_selector_development();
376
- }
377
- }
378
- });
379
-
380
- // node_modules/parse-svg-path/index.js
381
- var require_parse_svg_path = __commonJS({
382
- "node_modules/parse-svg-path/index.js"(exports, module2) {
383
- module2.exports = parse;
384
- var length = { a: 7, c: 6, h: 1, l: 2, m: 2, q: 4, s: 4, t: 2, v: 1, z: 0 };
385
- var segment = /([astvzqmhlc])([^astvzqmhlc]*)/ig;
386
- function parse(path) {
387
- var data = [];
388
- path.replace(segment, function(_, command, args) {
389
- var type = command.toLowerCase();
390
- args = parseValues(args);
391
- if (type == "m" && args.length > 2) {
392
- data.push([command].concat(args.splice(0, 2)));
393
- type = "l";
394
- command = command == "m" ? "l" : "L";
395
- }
396
- while (true) {
397
- if (args.length == length[type]) {
398
- args.unshift(command);
399
- return data.push(args);
400
- }
401
- if (args.length < length[type])
402
- throw new Error("malformed path data");
403
- data.push([command].concat(args.splice(0, length[type])));
404
- }
405
- });
406
- return data;
407
- }
408
- var number = /-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/ig;
409
- function parseValues(args) {
410
- var numbers = args.match(number);
411
- return numbers ? numbers.map(Number) : [];
412
- }
413
- }
414
- });
415
-
416
- // node_modules/abs-svg-path/index.js
417
- var require_abs_svg_path = __commonJS({
418
- "node_modules/abs-svg-path/index.js"(exports, module2) {
419
- module2.exports = absolutize;
420
- function absolutize(path) {
421
- var startX = 0;
422
- var startY = 0;
423
- var x = 0;
424
- var y = 0;
425
- return path.map(function(seg) {
426
- seg = seg.slice();
427
- var type = seg[0];
428
- var command = type.toUpperCase();
429
- if (type != command) {
430
- seg[0] = command;
431
- switch (type) {
432
- case "a":
433
- seg[6] += x;
434
- seg[7] += y;
435
- break;
436
- case "v":
437
- seg[1] += y;
438
- break;
439
- case "h":
440
- seg[1] += x;
441
- break;
442
- default:
443
- for (var i = 1; i < seg.length; ) {
444
- seg[i++] += x;
445
- seg[i++] += y;
446
- }
447
- }
448
- }
449
- switch (command) {
450
- case "Z":
451
- x = startX;
452
- y = startY;
453
- break;
454
- case "H":
455
- x = seg[1];
456
- break;
457
- case "V":
458
- y = seg[1];
459
- break;
460
- case "M":
461
- x = startX = seg[1];
462
- y = startY = seg[2];
463
- break;
464
- default:
465
- x = seg[seg.length - 2];
466
- y = seg[seg.length - 1];
467
- }
468
- return seg;
469
- });
470
- }
471
- }
472
- });
473
-
474
- // node_modules/svg-arc-to-cubic-bezier/modules/index.js
475
- var modules_exports = {};
476
- __export(modules_exports, {
477
- default: () => modules_default
478
- });
479
- var _slicedToArray, TAU, mapToEllipse, approxUnitArc, vectorAngle, getArcCenter, arcToBezier, modules_default;
480
- var init_modules = __esm({
481
- "node_modules/svg-arc-to-cubic-bezier/modules/index.js"() {
482
- _slicedToArray = function() {
483
- function sliceIterator(arr, i) {
484
- var _arr = [];
485
- var _n = true;
486
- var _d = false;
487
- var _e = void 0;
488
- try {
489
- for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
490
- _arr.push(_s.value);
491
- if (i && _arr.length === i)
492
- break;
493
- }
494
- } catch (err) {
495
- _d = true;
496
- _e = err;
497
- } finally {
498
- try {
499
- if (!_n && _i["return"])
500
- _i["return"]();
501
- } finally {
502
- if (_d)
503
- throw _e;
504
- }
505
- }
506
- return _arr;
507
- }
508
- return function(arr, i) {
509
- if (Array.isArray(arr)) {
510
- return arr;
511
- } else if (Symbol.iterator in Object(arr)) {
512
- return sliceIterator(arr, i);
513
- } else {
514
- throw new TypeError("Invalid attempt to destructure non-iterable instance");
515
- }
516
- };
517
- }();
518
- TAU = Math.PI * 2;
519
- mapToEllipse = function mapToEllipse2(_ref, rx, ry, cosphi, sinphi, centerx, centery) {
520
- var x = _ref.x, y = _ref.y;
521
- x *= rx;
522
- y *= ry;
523
- var xp = cosphi * x - sinphi * y;
524
- var yp = sinphi * x + cosphi * y;
525
- return {
526
- x: xp + centerx,
527
- y: yp + centery
528
- };
529
- };
530
- approxUnitArc = function approxUnitArc2(ang1, ang2) {
531
- var a = ang2 === 1.5707963267948966 ? 0.551915024494 : ang2 === -1.5707963267948966 ? -0.551915024494 : 4 / 3 * Math.tan(ang2 / 4);
532
- var x1 = Math.cos(ang1);
533
- var y1 = Math.sin(ang1);
534
- var x2 = Math.cos(ang1 + ang2);
535
- var y2 = Math.sin(ang1 + ang2);
536
- return [{
537
- x: x1 - y1 * a,
538
- y: y1 + x1 * a
539
- }, {
540
- x: x2 + y2 * a,
541
- y: y2 - x2 * a
542
- }, {
543
- x: x2,
544
- y: y2
545
- }];
546
- };
547
- vectorAngle = function vectorAngle2(ux, uy, vx, vy) {
548
- var sign = ux * vy - uy * vx < 0 ? -1 : 1;
549
- var dot = ux * vx + uy * vy;
550
- if (dot > 1) {
551
- dot = 1;
552
- }
553
- if (dot < -1) {
554
- dot = -1;
555
- }
556
- return sign * Math.acos(dot);
557
- };
558
- getArcCenter = function getArcCenter2(px, py, cx, cy, rx, ry, largeArcFlag, sweepFlag, sinphi, cosphi, pxp, pyp) {
559
- var rxsq = Math.pow(rx, 2);
560
- var rysq = Math.pow(ry, 2);
561
- var pxpsq = Math.pow(pxp, 2);
562
- var pypsq = Math.pow(pyp, 2);
563
- var radicant = rxsq * rysq - rxsq * pypsq - rysq * pxpsq;
564
- if (radicant < 0) {
565
- radicant = 0;
566
- }
567
- radicant /= rxsq * pypsq + rysq * pxpsq;
568
- radicant = Math.sqrt(radicant) * (largeArcFlag === sweepFlag ? -1 : 1);
569
- var centerxp = radicant * rx / ry * pyp;
570
- var centeryp = radicant * -ry / rx * pxp;
571
- var centerx = cosphi * centerxp - sinphi * centeryp + (px + cx) / 2;
572
- var centery = sinphi * centerxp + cosphi * centeryp + (py + cy) / 2;
573
- var vx1 = (pxp - centerxp) / rx;
574
- var vy1 = (pyp - centeryp) / ry;
575
- var vx2 = (-pxp - centerxp) / rx;
576
- var vy2 = (-pyp - centeryp) / ry;
577
- var ang1 = vectorAngle(1, 0, vx1, vy1);
578
- var ang2 = vectorAngle(vx1, vy1, vx2, vy2);
579
- if (sweepFlag === 0 && ang2 > 0) {
580
- ang2 -= TAU;
581
- }
582
- if (sweepFlag === 1 && ang2 < 0) {
583
- ang2 += TAU;
584
- }
585
- return [centerx, centery, ang1, ang2];
586
- };
587
- arcToBezier = function arcToBezier2(_ref2) {
588
- var px = _ref2.px, py = _ref2.py, cx = _ref2.cx, cy = _ref2.cy, rx = _ref2.rx, ry = _ref2.ry, _ref2$xAxisRotation = _ref2.xAxisRotation, xAxisRotation = _ref2$xAxisRotation === void 0 ? 0 : _ref2$xAxisRotation, _ref2$largeArcFlag = _ref2.largeArcFlag, largeArcFlag = _ref2$largeArcFlag === void 0 ? 0 : _ref2$largeArcFlag, _ref2$sweepFlag = _ref2.sweepFlag, sweepFlag = _ref2$sweepFlag === void 0 ? 0 : _ref2$sweepFlag;
589
- var curves = [];
590
- if (rx === 0 || ry === 0) {
591
- return [];
592
- }
593
- var sinphi = Math.sin(xAxisRotation * TAU / 360);
594
- var cosphi = Math.cos(xAxisRotation * TAU / 360);
595
- var pxp = cosphi * (px - cx) / 2 + sinphi * (py - cy) / 2;
596
- var pyp = -sinphi * (px - cx) / 2 + cosphi * (py - cy) / 2;
597
- if (pxp === 0 && pyp === 0) {
598
- return [];
599
- }
600
- rx = Math.abs(rx);
601
- ry = Math.abs(ry);
602
- var lambda = Math.pow(pxp, 2) / Math.pow(rx, 2) + Math.pow(pyp, 2) / Math.pow(ry, 2);
603
- if (lambda > 1) {
604
- rx *= Math.sqrt(lambda);
605
- ry *= Math.sqrt(lambda);
606
- }
607
- var _getArcCenter = getArcCenter(px, py, cx, cy, rx, ry, largeArcFlag, sweepFlag, sinphi, cosphi, pxp, pyp), _getArcCenter2 = _slicedToArray(_getArcCenter, 4), centerx = _getArcCenter2[0], centery = _getArcCenter2[1], ang1 = _getArcCenter2[2], ang2 = _getArcCenter2[3];
608
- var ratio = Math.abs(ang2) / (TAU / 4);
609
- if (Math.abs(1 - ratio) < 1e-7) {
610
- ratio = 1;
611
- }
612
- var segments = Math.max(Math.ceil(ratio), 1);
613
- ang2 /= segments;
614
- for (var i = 0; i < segments; i++) {
615
- curves.push(approxUnitArc(ang1, ang2));
616
- ang1 += ang2;
617
- }
618
- return curves.map(function(curve) {
619
- var _mapToEllipse = mapToEllipse(curve[0], rx, ry, cosphi, sinphi, centerx, centery), x1 = _mapToEllipse.x, y1 = _mapToEllipse.y;
620
- var _mapToEllipse2 = mapToEllipse(curve[1], rx, ry, cosphi, sinphi, centerx, centery), x2 = _mapToEllipse2.x, y2 = _mapToEllipse2.y;
621
- var _mapToEllipse3 = mapToEllipse(curve[2], rx, ry, cosphi, sinphi, centerx, centery), x = _mapToEllipse3.x, y = _mapToEllipse3.y;
622
- return { x1, y1, x2, y2, x, y };
623
- });
624
- };
625
- modules_default = arcToBezier;
626
- }
627
- });
628
-
629
- // node_modules/normalize-svg-path/index.js
630
- var require_normalize_svg_path = __commonJS({
631
- "node_modules/normalize-svg-path/index.js"(exports, module2) {
632
- "use strict";
633
- module2.exports = normalize;
634
- var arcToCurve = (init_modules(), __toCommonJS(modules_exports));
635
- function normalize(path) {
636
- var prev;
637
- var result = [];
638
- var bezierX = 0;
639
- var bezierY = 0;
640
- var startX = 0;
641
- var startY = 0;
642
- var quadX = null;
643
- var quadY = null;
644
- var x = 0;
645
- var y = 0;
646
- for (var i = 0, len = path.length; i < len; i++) {
647
- var seg = path[i];
648
- var command = seg[0];
649
- switch (command) {
650
- case "M":
651
- startX = seg[1];
652
- startY = seg[2];
653
- break;
654
- case "A":
655
- var curves = arcToCurve({
656
- px: x,
657
- py: y,
658
- cx: seg[6],
659
- cy: seg[7],
660
- rx: seg[1],
661
- ry: seg[2],
662
- xAxisRotation: seg[3],
663
- largeArcFlag: seg[4],
664
- sweepFlag: seg[5]
665
- });
666
- if (!curves.length)
667
- continue;
668
- for (var j = 0, c; j < curves.length; j++) {
669
- c = curves[j];
670
- seg = ["C", c.x1, c.y1, c.x2, c.y2, c.x, c.y];
671
- if (j < curves.length - 1)
672
- result.push(seg);
673
- }
674
- break;
675
- case "S":
676
- var cx = x;
677
- var cy = y;
678
- if (prev == "C" || prev == "S") {
679
- cx += cx - bezierX;
680
- cy += cy - bezierY;
681
- }
682
- seg = ["C", cx, cy, seg[1], seg[2], seg[3], seg[4]];
683
- break;
684
- case "T":
685
- if (prev == "Q" || prev == "T") {
686
- quadX = x * 2 - quadX;
687
- quadY = y * 2 - quadY;
688
- } else {
689
- quadX = x;
690
- quadY = y;
691
- }
692
- seg = quadratic(x, y, quadX, quadY, seg[1], seg[2]);
693
- break;
694
- case "Q":
695
- quadX = seg[1];
696
- quadY = seg[2];
697
- seg = quadratic(x, y, seg[1], seg[2], seg[3], seg[4]);
698
- break;
699
- case "L":
700
- seg = line(x, y, seg[1], seg[2]);
701
- break;
702
- case "H":
703
- seg = line(x, y, seg[1], y);
704
- break;
705
- case "V":
706
- seg = line(x, y, x, seg[1]);
707
- break;
708
- case "Z":
709
- seg = line(x, y, startX, startY);
710
- break;
711
- }
712
- prev = command;
713
- x = seg[seg.length - 2];
714
- y = seg[seg.length - 1];
715
- if (seg.length > 4) {
716
- bezierX = seg[seg.length - 4];
717
- bezierY = seg[seg.length - 3];
718
- } else {
719
- bezierX = x;
720
- bezierY = y;
721
- }
722
- result.push(seg);
723
- }
724
- return result;
725
- }
726
- function line(x1, y1, x2, y2) {
727
- return ["C", x1, y1, x2, y2, x2, y2];
728
- }
729
- function quadratic(x1, y1, cx, cy, x2, y2) {
730
- return [
731
- "C",
732
- x1 / 3 + 2 / 3 * cx,
733
- y1 / 3 + 2 / 3 * cy,
734
- x2 / 3 + 2 / 3 * cx,
735
- y2 / 3 + 2 / 3 * cy,
736
- x2,
737
- y2
738
- ];
739
- }
740
- }
741
- });
742
-
743
- // node_modules/is-svg-path/index.js
744
- var require_is_svg_path = __commonJS({
745
- "node_modules/is-svg-path/index.js"(exports, module2) {
746
- "use strict";
747
- module2.exports = function isPath(str) {
748
- if (typeof str !== "string")
749
- return false;
750
- str = str.trim();
751
- if (/^[mzlhvcsqta]\s*[-+.0-9][^mlhvzcsqta]+/i.test(str) && /[\dz]$/i.test(str) && str.length > 4)
752
- return true;
753
- return false;
754
- };
755
- }
756
- });
757
-
758
- // node_modules/svg-path-bounds/index.js
759
- var require_svg_path_bounds = __commonJS({
760
- "node_modules/svg-path-bounds/index.js"(exports, module2) {
761
- "use strict";
762
- var parse = require_parse_svg_path();
763
- var abs = require_abs_svg_path();
764
- var normalize = require_normalize_svg_path();
765
- var isSvgPath = require_is_svg_path();
766
- module2.exports = pathBounds;
767
- function pathBounds(path) {
768
- if (Array.isArray(path) && path.length === 1 && typeof path[0] === "string")
769
- path = path[0];
770
- if (typeof path === "string") {
771
- if (!isSvgPath(path))
772
- throw Error("String is not an SVG path.");
773
- path = parse(path);
774
- }
775
- if (!Array.isArray(path))
776
- throw Error("Argument should be a string or an array of path segments.");
777
- path = abs(path);
778
- path = normalize(path);
779
- if (!path.length)
780
- return [0, 0, 0, 0];
781
- var bounds = [Infinity, Infinity, -Infinity, -Infinity];
782
- for (var i = 0, l = path.length; i < l; i++) {
783
- var points = path[i].slice(1);
784
- for (var j = 0; j < points.length; j += 2) {
785
- if (points[j + 0] < bounds[0])
786
- bounds[0] = points[j + 0];
787
- if (points[j + 1] < bounds[1])
788
- bounds[1] = points[j + 1];
789
- if (points[j + 0] > bounds[2])
790
- bounds[2] = points[j + 0];
791
- if (points[j + 1] > bounds[3])
792
- bounds[3] = points[j + 1];
793
- }
794
- }
795
- return bounds;
796
- }
797
- }
798
- });
799
-
800
- // node_modules/debounce/index.js
801
- var require_debounce = __commonJS({
802
- "node_modules/debounce/index.js"(exports, module2) {
803
- function debounce(func, wait, immediate) {
804
- var timeout, args, context, timestamp, result;
805
- if (null == wait)
806
- wait = 100;
807
- function later() {
808
- var last = Date.now() - timestamp;
809
- if (last < wait && last >= 0) {
810
- timeout = setTimeout(later, wait - last);
811
- } else {
812
- timeout = null;
813
- if (!immediate) {
814
- result = func.apply(context, args);
815
- context = args = null;
816
- }
817
- }
818
- }
819
- ;
820
- var debounced = function() {
821
- context = this;
822
- args = arguments;
823
- timestamp = Date.now();
824
- var callNow = immediate && !timeout;
825
- if (!timeout)
826
- timeout = setTimeout(later, wait);
827
- if (callNow) {
828
- result = func.apply(context, args);
829
- context = args = null;
830
- }
831
- return result;
832
- };
833
- debounced.clear = function() {
834
- if (timeout) {
835
- clearTimeout(timeout);
836
- timeout = null;
837
- }
838
- };
839
- debounced.flush = function() {
840
- if (timeout) {
841
- result = func.apply(context, args);
842
- context = args = null;
843
- clearTimeout(timeout);
844
- timeout = null;
845
- }
846
- };
847
- return debounced;
848
- }
849
- debounce.debounce = debounce;
850
- module2.exports = debounce;
851
- }
852
- });
853
-
854
- // node_modules/svg-path-generator/lib/svg-path-generator.js
855
- var require_svg_path_generator = __commonJS({
856
- "node_modules/svg-path-generator/lib/svg-path-generator.js"(exports, module2) {
857
- function SvgPathGenerator(path) {
858
- if (!(this instanceof SvgPathGenerator)) {
859
- return new SvgPathGenerator(path);
860
- }
861
- this.currentPath = (path || "") + " ";
862
- this.isRelative = false;
863
- }
864
- module2.exports = SvgPathGenerator;
865
- SvgPathGenerator.prototype.toString = function() {
866
- return this.end();
867
- };
868
- SvgPathGenerator.prototype.moveTo = function() {
869
- this._appendData("M", arguments);
870
- return this;
871
- };
872
- SvgPathGenerator.prototype.close = SvgPathGenerator.prototype.closePath = function() {
873
- this._appendData("Z", []);
874
- return this;
875
- };
876
- SvgPathGenerator.prototype.lineTo = function() {
877
- this._appendData("L", arguments);
878
- return this;
879
- };
880
- SvgPathGenerator.prototype.horizontalLineTo = function(x) {
881
- this._appendData("H", [x]);
882
- return this;
883
- };
884
- SvgPathGenerator.prototype.verticalLineTo = function(y) {
885
- this._appendData("V", [y]);
886
- return this;
887
- };
888
- SvgPathGenerator.prototype.curveTo = function() {
889
- this._appendData("C", arguments);
890
- return this;
891
- };
892
- SvgPathGenerator.prototype.smoothCurveTo = function() {
893
- this._appendData("S", arguments);
894
- return this;
895
- };
896
- SvgPathGenerator.prototype.bezierCurveTo = function() {
897
- this._appendData("Q", arguments);
898
- return this;
899
- };
900
- SvgPathGenerator.prototype.smoothBezierCurveTo = function() {
901
- this._appendData("T", arguments);
902
- return this;
903
- };
904
- SvgPathGenerator.prototype.ellipticalArc = function() {
905
- this._appendData("A", arguments);
906
- return this;
907
- };
908
- SvgPathGenerator.prototype.relative = function() {
909
- this.isRelative = true;
910
- return this;
911
- };
912
- SvgPathGenerator.prototype.end = function() {
913
- return this.currentPath.trim();
914
- };
915
- SvgPathGenerator.prototype._appendData = function(symbol, args) {
916
- args = Array.prototype.slice.call(args);
917
- if (this.isRelative) {
918
- symbol = symbol.toLowerCase();
919
- this.isRelative = false;
920
- }
921
- this.currentPath += symbol + " " + args.join(" ") + " ";
922
- };
923
- }
924
- });
925
-
926
- // node_modules/svg-path-generator/index.js
927
- var require_svg_path_generator2 = __commonJS({
928
- "node_modules/svg-path-generator/index.js"(exports, module2) {
929
- module2.exports = require_svg_path_generator();
930
- }
931
- });
932
-
933
- // src/index.ts
934
- var src_exports = {};
935
- __export(src_exports, {
936
- Schematic: () => Schematic,
937
- SchematicWithoutContext: () => SchematicWithoutContext
938
- });
939
- module.exports = __toCommonJS(src_exports);
940
-
941
- // src/Schematic.tsx
942
- var import_core = require("@tscircuit/core");
943
- var import_soup_util = require("@tscircuit/soup-util");
944
-
945
- // node_modules/zustand/esm/vanilla.mjs
946
- var import_meta = {};
947
- var createStoreImpl = (createState) => {
948
- let state;
949
- const listeners = /* @__PURE__ */ new Set();
950
- const setState = (partial, replace) => {
951
- const nextState = typeof partial === "function" ? partial(state) : partial;
952
- if (!Object.is(nextState, state)) {
953
- const previousState = state;
954
- state = (replace != null ? replace : typeof nextState !== "object" || nextState === null) ? nextState : Object.assign({}, state, nextState);
955
- listeners.forEach((listener) => listener(state, previousState));
956
- }
957
- };
958
- const getState = () => state;
959
- const getInitialState = () => initialState;
960
- const subscribe = (listener) => {
961
- listeners.add(listener);
962
- return () => listeners.delete(listener);
963
- };
964
- const destroy = () => {
965
- if ((import_meta.env ? import_meta.env.MODE : void 0) !== "production") {
966
- console.warn(
967
- "[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."
968
- );
969
- }
970
- listeners.clear();
971
- };
972
- const api = { setState, getState, getInitialState, subscribe, destroy };
973
- const initialState = state = createState(setState, getState, api);
974
- return api;
975
- };
976
- var createStore = (createState) => createState ? createStoreImpl(createState) : createStoreImpl;
977
-
978
- // node_modules/zustand/esm/index.mjs
979
- var import_react = __toESM(require("react"), 1);
980
- var import_with_selector = __toESM(require_with_selector(), 1);
981
- var import_meta2 = {};
982
- var { useDebugValue } = import_react.default;
983
- var { useSyncExternalStoreWithSelector } = import_with_selector.default;
984
- var didWarnAboutEqualityFn = false;
985
- var identity = (arg) => arg;
986
- function useStore(api, selector = identity, equalityFn) {
987
- if ((import_meta2.env ? import_meta2.env.MODE : void 0) !== "production" && equalityFn && !didWarnAboutEqualityFn) {
988
- console.warn(
989
- "[DEPRECATED] Use `createWithEqualityFn` instead of `create` or use `useStoreWithEqualityFn` instead of `useStore`. They can be imported from 'zustand/traditional'. https://github.com/pmndrs/zustand/discussions/1937"
990
- );
991
- didWarnAboutEqualityFn = true;
992
- }
993
- const slice = useSyncExternalStoreWithSelector(
994
- api.subscribe,
995
- api.getState,
996
- api.getServerState || api.getInitialState,
997
- selector,
998
- equalityFn
999
- );
1000
- useDebugValue(slice);
1001
- return slice;
1002
- }
1003
-
1004
- // node_modules/transformation-matrix/src/applyToPoint.js
1005
- function applyToPoint(matrix, point) {
1006
- return Array.isArray(point) ? [
1007
- matrix.a * point[0] + matrix.c * point[1] + matrix.e,
1008
- matrix.b * point[0] + matrix.d * point[1] + matrix.f
1009
- ] : {
1010
- x: matrix.a * point.x + matrix.c * point.y + matrix.e,
1011
- y: matrix.b * point.x + matrix.d * point.y + matrix.f
1012
- };
1013
- }
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
-
1029
- // node_modules/transformation-matrix/src/utils.js
1030
- function isUndefined(val) {
1031
- return typeof val === "undefined";
1032
- }
1033
-
1034
- // node_modules/transformation-matrix/src/translate.js
1035
- function translate(tx, ty = 0) {
1036
- return {
1037
- a: 1,
1038
- c: 0,
1039
- e: tx,
1040
- b: 0,
1041
- d: 1,
1042
- f: ty
1043
- };
1044
- }
1045
-
1046
- // node_modules/transformation-matrix/src/transform.js
1047
- function transform(...matrices) {
1048
- matrices = Array.isArray(matrices[0]) ? matrices[0] : matrices;
1049
- const multiply = (m1, m2) => {
1050
- return {
1051
- a: m1.a * m2.a + m1.c * m2.b,
1052
- c: m1.a * m2.c + m1.c * m2.d,
1053
- e: m1.a * m2.e + m1.c * m2.f + m1.e,
1054
- b: m1.b * m2.a + m1.d * m2.b,
1055
- d: m1.b * m2.c + m1.d * m2.d,
1056
- f: m1.b * m2.e + m1.d * m2.f + m1.f
1057
- };
1058
- };
1059
- switch (matrices.length) {
1060
- case 0:
1061
- throw new Error("no matrices provided");
1062
- case 1:
1063
- return matrices[0];
1064
- case 2:
1065
- return multiply(matrices[0], matrices[1]);
1066
- default: {
1067
- const [m1, m2, ...rest] = matrices;
1068
- const m = multiply(m1, m2);
1069
- return transform(m, ...rest);
1070
- }
1071
- }
1072
- }
1073
- function compose(...matrices) {
1074
- return transform(...matrices);
1075
- }
1076
-
1077
- // node_modules/transformation-matrix/src/rotate.js
1078
- var { cos, sin, PI } = Math;
1079
-
1080
- // node_modules/transformation-matrix/src/scale.js
1081
- function scale(sx, sy = void 0, cx = void 0, cy = void 0) {
1082
- if (isUndefined(sy))
1083
- sy = sx;
1084
- const scaleMatrix = {
1085
- a: sx,
1086
- c: 0,
1087
- e: 0,
1088
- b: 0,
1089
- d: sy,
1090
- f: 0
1091
- };
1092
- if (isUndefined(cx) || isUndefined(cy)) {
1093
- return scaleMatrix;
1094
- }
1095
- return transform([
1096
- translate(cx, cy),
1097
- scaleMatrix,
1098
- translate(-cx, -cy)
1099
- ]);
1100
- }
1101
-
1102
- // node_modules/transformation-matrix/src/skew.js
1103
- var { tan } = Math;
1104
-
1105
- // node_modules/transformation-matrix/src/toString.js
1106
- function toSVG(matrix) {
1107
- return toString(matrix);
1108
- }
1109
- function toString(matrix) {
1110
- return `matrix(${matrix.a},${matrix.b},${matrix.c},${matrix.d},${matrix.e},${matrix.f})`;
1111
- }
1112
-
1113
- // node_modules/transformation-matrix/src/fromTransformAttribute.autogenerated.js
1114
- function peg$subclass(child, parent) {
1115
- function C() {
1116
- this.constructor = child;
1117
- }
1118
- C.prototype = parent.prototype;
1119
- child.prototype = new C();
1120
- }
1121
- function peg$SyntaxError(message, expected, found, location) {
1122
- var self = Error.call(this, message);
1123
- if (Object.setPrototypeOf) {
1124
- Object.setPrototypeOf(self, peg$SyntaxError.prototype);
1125
- }
1126
- self.expected = expected;
1127
- self.found = found;
1128
- self.location = location;
1129
- self.name = "SyntaxError";
1130
- return self;
1131
- }
1132
- peg$subclass(peg$SyntaxError, Error);
1133
- function peg$padEnd(str, targetLength, padString) {
1134
- padString = padString || " ";
1135
- if (str.length > targetLength) {
1136
- return str;
1137
- }
1138
- targetLength -= str.length;
1139
- padString += padString.repeat(targetLength);
1140
- return str + padString.slice(0, targetLength);
1141
- }
1142
- peg$SyntaxError.prototype.format = function(sources) {
1143
- var str = "Error: " + this.message;
1144
- if (this.location) {
1145
- var src = null;
1146
- var k;
1147
- for (k = 0; k < sources.length; k++) {
1148
- if (sources[k].source === this.location.source) {
1149
- src = sources[k].text.split(/\r\n|\n|\r/g);
1150
- break;
1151
- }
1152
- }
1153
- var s = this.location.start;
1154
- var offset_s = this.location.source && typeof this.location.source.offset === "function" ? this.location.source.offset(s) : s;
1155
- var loc = this.location.source + ":" + offset_s.line + ":" + offset_s.column;
1156
- if (src) {
1157
- var e = this.location.end;
1158
- var filler = peg$padEnd("", offset_s.line.toString().length, " ");
1159
- var line = src[s.line - 1];
1160
- var last = s.line === e.line ? e.column : line.length + 1;
1161
- var hatLen = last - s.column || 1;
1162
- str += "\n --> " + loc + "\n" + filler + " |\n" + offset_s.line + " | " + line + "\n" + filler + " | " + peg$padEnd("", s.column - 1, " ") + peg$padEnd("", hatLen, "^");
1163
- } else {
1164
- str += "\n at " + loc;
1165
- }
1166
- }
1167
- return str;
1168
- };
1169
- peg$SyntaxError.buildMessage = function(expected, found) {
1170
- var DESCRIBE_EXPECTATION_FNS = {
1171
- literal: function(expectation) {
1172
- return '"' + literalEscape(expectation.text) + '"';
1173
- },
1174
- class: function(expectation) {
1175
- var escapedParts = expectation.parts.map(function(part) {
1176
- return Array.isArray(part) ? classEscape(part[0]) + "-" + classEscape(part[1]) : classEscape(part);
1177
- });
1178
- return "[" + (expectation.inverted ? "^" : "") + escapedParts.join("") + "]";
1179
- },
1180
- any: function() {
1181
- return "any character";
1182
- },
1183
- end: function() {
1184
- return "end of input";
1185
- },
1186
- other: function(expectation) {
1187
- return expectation.description;
1188
- }
1189
- };
1190
- function hex(ch) {
1191
- return ch.charCodeAt(0).toString(16).toUpperCase();
1192
- }
1193
- function literalEscape(s) {
1194
- return s.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\0/g, "\\0").replace(/\t/g, "\\t").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/[\x00-\x0F]/g, function(ch) {
1195
- return "\\x0" + hex(ch);
1196
- }).replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) {
1197
- return "\\x" + hex(ch);
1198
- });
1199
- }
1200
- function classEscape(s) {
1201
- return s.replace(/\\/g, "\\\\").replace(/\]/g, "\\]").replace(/\^/g, "\\^").replace(/-/g, "\\-").replace(/\0/g, "\\0").replace(/\t/g, "\\t").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/[\x00-\x0F]/g, function(ch) {
1202
- return "\\x0" + hex(ch);
1203
- }).replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) {
1204
- return "\\x" + hex(ch);
1205
- });
1206
- }
1207
- function describeExpectation(expectation) {
1208
- return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation);
1209
- }
1210
- function describeExpected(expected2) {
1211
- var descriptions = expected2.map(describeExpectation);
1212
- var i, j;
1213
- descriptions.sort();
1214
- if (descriptions.length > 0) {
1215
- for (i = 1, j = 1; i < descriptions.length; i++) {
1216
- if (descriptions[i - 1] !== descriptions[i]) {
1217
- descriptions[j] = descriptions[i];
1218
- j++;
1219
- }
1220
- }
1221
- descriptions.length = j;
1222
- }
1223
- switch (descriptions.length) {
1224
- case 1:
1225
- return descriptions[0];
1226
- case 2:
1227
- return descriptions[0] + " or " + descriptions[1];
1228
- default:
1229
- return descriptions.slice(0, -1).join(", ") + ", or " + descriptions[descriptions.length - 1];
1230
- }
1231
- }
1232
- function describeFound(found2) {
1233
- return found2 ? '"' + literalEscape(found2) + '"' : "end of input";
1234
- }
1235
- return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found.";
1236
- };
1237
-
1238
- // src/lib/render-context/index.ts
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
- };
1508
-
1509
- // src/lib/utils/get-svg-path-bounds.ts
1510
- var import_svg_path_bounds = __toESM(require_svg_path_bounds());
1511
- function getSVGPathBounds(ds) {
1512
- if (typeof ds === "string")
1513
- ds = [ds];
1514
- let minX = Infinity, maxX = -Infinity, minY = Infinity, maxY = -Infinity;
1515
- for (const d of ds) {
1516
- const [left, top, right, bottom] = (0, import_svg_path_bounds.default)(d);
1517
- minX = Math.min(left, minX);
1518
- maxX = Math.max(right, maxX);
1519
- minY = Math.min(top, minY);
1520
- maxY = Math.max(bottom, maxY);
1521
- }
1522
- return { minX, maxX, minY, maxY, width: maxX - minX, height: maxY - minY };
1523
- }
1524
- var get_svg_path_bounds_default = getSVGPathBounds;
1525
-
1526
- // src/schematic-components/SVGPathComponent.tsx
1527
- var import_react4 = require("react");
1528
- var import_jsx_runtime3 = require("react/jsx-runtime");
1529
- var SVGPathComponent = ({
1530
- size,
1531
- center,
1532
- rotation,
1533
- paths,
1534
- zIndex,
1535
- invertY,
1536
- shiftToBottom,
1537
- hoverContent
1538
- }) => {
1539
- const ct = useGlobalStore((s) => s.camera_transform);
1540
- const pathBounds = get_svg_path_bounds_default(
1541
- paths.filter((p) => p.type !== "circle" && p.type !== "text").map((p) => p.d)
1542
- );
1543
- const padding = { x: 0, y: 0 };
1544
- const absoluteCenter = applyToPoint(ct, center);
1545
- const innerSize = {
1546
- width: size.width * ct.a,
1547
- height: size.height * Math.abs(ct.d)
1548
- };
1549
- const fullSize = {
1550
- width: innerSize.width + padding.x * 2,
1551
- height: innerSize.height + padding.y * 2
1552
- };
1553
- const [hovering, setHovering] = (0, import_react4.useState)(false);
1554
- const svgLeft = absoluteCenter.x - fullSize.width / 2;
1555
- const svgTop = absoluteCenter.y - fullSize.height / 2;
1556
- const preferredRatio = pathBounds.width === 0 ? innerSize.height / pathBounds.height : innerSize.width / pathBounds.width;
1557
- const svgToScreen = compose(
1558
- scale(
1559
- pathBounds.width === 0 ? preferredRatio : fullSize.width / pathBounds.width,
1560
- pathBounds.height === 0 ? preferredRatio : fullSize.height / pathBounds.height
1561
- ),
1562
- translate(-pathBounds.minX, -pathBounds.minY)
1563
- );
1564
- const baseFontSize = 0.15;
1565
- return (
1566
- // biome-ignore lint/a11y/noSvgWithoutTitle: <explanation>
1567
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1568
- "svg",
1569
- {
1570
- onMouseOver: () => setHovering(Boolean(hoverContent)),
1571
- onFocus: () => setHovering(Boolean(hoverContent)),
1572
- onMouseOut: () => setHovering(false),
1573
- onBlur: () => setHovering(false),
1574
- style: {
1575
- position: "absolute",
1576
- cursor: hovering ? "pointer" : void 0,
1577
- zIndex,
1578
- transform: [
1579
- invertY ? "scale(1, 1)" : "scale(1, -1)",
1580
- shiftToBottom ? "translate(0, 100%)" : "",
1581
- rotation === 0 ? "" : `rotate(${rotation}deg)`
1582
- ].join(" "),
1583
- left: svgLeft,
1584
- top: svgTop
1585
- },
1586
- overflow: "visible",
1587
- width: fullSize.width,
1588
- height: fullSize.height,
1589
- children: paths.map((p, i) => {
1590
- if (p.type === "circle") {
1591
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1592
- "circle",
1593
- {
1594
- transform: toSVG(compose(scale(1, 1), svgToScreen)),
1595
- cx: p.cx,
1596
- cy: p.cy,
1597
- r: p.r,
1598
- fill: "none",
1599
- strokeWidth: 2.25 * (p.strokeWidth || 1),
1600
- stroke: p.stroke || "red"
1601
- },
1602
- `${p.type}-${i}`
1603
- );
1604
- }
1605
- if (p.type === "text") {
1606
- const transformedPos = applyToPoint(svgToScreen, { x: p.cx, y: p.cy });
1607
- const scaleFactor = fullSize.width / pathBounds.width || 1;
1608
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("g", { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1609
- "text",
1610
- {
1611
- className: "schematic-text",
1612
- x: transformedPos.x,
1613
- y: transformedPos.y,
1614
- fill: p.fill,
1615
- fontSize: baseFontSize * scaleFactor,
1616
- textAnchor: p.anchor || "middle",
1617
- dominantBaseline: "middle",
1618
- transform: `scale(1,-1) rotate(${p.rotation || 0})`,
1619
- style: {
1620
- transformBox: "fill-box",
1621
- transformOrigin: "center"
1622
- },
1623
- stroke: p.stroke,
1624
- children: p.text
1625
- }
1626
- ) }, `${p.type}-${i}`);
1627
- }
1628
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1629
- "path",
1630
- {
1631
- transform: toSVG(svgToScreen),
1632
- fill: p.fill ?? "none",
1633
- strokeLinecap: "round",
1634
- strokeWidth: 1.5 * (p.strokeWidth || 1),
1635
- stroke: p.stroke || "red",
1636
- d: p.d || ""
1637
- },
1638
- `${p.type}-${i}`
1639
- );
1640
- })
1641
- }
1642
- )
1643
- );
1644
- };
1645
- var SVGPathComponent_default = SVGPathComponent;
1646
-
1647
- // node_modules/react-use-measure/dist/web.js
1648
- var import_react5 = require("react");
1649
- var import_debounce = __toESM(require_debounce());
1650
- function useMeasure(_temp) {
1651
- let {
1652
- debounce,
1653
- scroll,
1654
- polyfill,
1655
- offsetSize
1656
- } = _temp === void 0 ? {
1657
- debounce: 0,
1658
- scroll: false,
1659
- offsetSize: false
1660
- } : _temp;
1661
- const ResizeObserver = polyfill || (typeof window === "undefined" ? class ResizeObserver {
1662
- } : window.ResizeObserver);
1663
- if (!ResizeObserver) {
1664
- 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");
1665
- }
1666
- const [bounds, set] = (0, import_react5.useState)({
1667
- left: 0,
1668
- top: 0,
1669
- width: 0,
1670
- height: 0,
1671
- bottom: 0,
1672
- right: 0,
1673
- x: 0,
1674
- y: 0
1675
- });
1676
- const state = (0, import_react5.useRef)({
1677
- element: null,
1678
- scrollContainers: null,
1679
- resizeObserver: null,
1680
- lastBounds: bounds
1681
- });
1682
- const scrollDebounce = debounce ? typeof debounce === "number" ? debounce : debounce.scroll : null;
1683
- const resizeDebounce = debounce ? typeof debounce === "number" ? debounce : debounce.resize : null;
1684
- const mounted = (0, import_react5.useRef)(false);
1685
- (0, import_react5.useEffect)(() => {
1686
- mounted.current = true;
1687
- return () => void (mounted.current = false);
1688
- });
1689
- const [forceRefresh, resizeChange, scrollChange] = (0, import_react5.useMemo)(() => {
1690
- const callback = () => {
1691
- if (!state.current.element)
1692
- return;
1693
- const {
1694
- left,
1695
- top,
1696
- width,
1697
- height,
1698
- bottom,
1699
- right,
1700
- x,
1701
- y
1702
- } = state.current.element.getBoundingClientRect();
1703
- const size = {
1704
- left,
1705
- top,
1706
- width,
1707
- height,
1708
- bottom,
1709
- right,
1710
- x,
1711
- y
1712
- };
1713
- if (state.current.element instanceof HTMLElement && offsetSize) {
1714
- size.height = state.current.element.offsetHeight;
1715
- size.width = state.current.element.offsetWidth;
1716
- }
1717
- Object.freeze(size);
1718
- if (mounted.current && !areBoundsEqual(state.current.lastBounds, size))
1719
- set(state.current.lastBounds = size);
1720
- };
1721
- return [callback, resizeDebounce ? (0, import_debounce.default)(callback, resizeDebounce) : callback, scrollDebounce ? (0, import_debounce.default)(callback, scrollDebounce) : callback];
1722
- }, [set, offsetSize, scrollDebounce, resizeDebounce]);
1723
- function removeListeners() {
1724
- if (state.current.scrollContainers) {
1725
- state.current.scrollContainers.forEach((element) => element.removeEventListener("scroll", scrollChange, true));
1726
- state.current.scrollContainers = null;
1727
- }
1728
- if (state.current.resizeObserver) {
1729
- state.current.resizeObserver.disconnect();
1730
- state.current.resizeObserver = null;
1731
- }
1732
- }
1733
- function addListeners() {
1734
- if (!state.current.element)
1735
- return;
1736
- state.current.resizeObserver = new ResizeObserver(scrollChange);
1737
- state.current.resizeObserver.observe(state.current.element);
1738
- if (scroll && state.current.scrollContainers) {
1739
- state.current.scrollContainers.forEach((scrollContainer) => scrollContainer.addEventListener("scroll", scrollChange, {
1740
- capture: true,
1741
- passive: true
1742
- }));
1743
- }
1744
- }
1745
- const ref = (node) => {
1746
- if (!node || node === state.current.element)
1747
- return;
1748
- removeListeners();
1749
- state.current.element = node;
1750
- state.current.scrollContainers = findScrollContainers(node);
1751
- addListeners();
1752
- };
1753
- useOnWindowScroll(scrollChange, Boolean(scroll));
1754
- useOnWindowResize(resizeChange);
1755
- (0, import_react5.useEffect)(() => {
1756
- removeListeners();
1757
- addListeners();
1758
- }, [scroll, scrollChange, resizeChange]);
1759
- (0, import_react5.useEffect)(() => removeListeners, []);
1760
- return [ref, bounds, forceRefresh];
1761
- }
1762
- function useOnWindowResize(onWindowResize) {
1763
- (0, import_react5.useEffect)(() => {
1764
- const cb = onWindowResize;
1765
- window.addEventListener("resize", cb);
1766
- return () => void window.removeEventListener("resize", cb);
1767
- }, [onWindowResize]);
1768
- }
1769
- function useOnWindowScroll(onScroll, enabled) {
1770
- (0, import_react5.useEffect)(() => {
1771
- if (enabled) {
1772
- const cb = onScroll;
1773
- window.addEventListener("scroll", cb, {
1774
- capture: true,
1775
- passive: true
1776
- });
1777
- return () => void window.removeEventListener("scroll", cb, true);
1778
- }
1779
- }, [onScroll, enabled]);
1780
- }
1781
- function findScrollContainers(element) {
1782
- const result = [];
1783
- if (!element || element === document.body)
1784
- return result;
1785
- const {
1786
- overflow,
1787
- overflowX,
1788
- overflowY
1789
- } = window.getComputedStyle(element);
1790
- if ([overflow, overflowX, overflowY].some((prop) => prop === "auto" || prop === "scroll"))
1791
- result.push(element);
1792
- return [...result, ...findScrollContainers(element.parentElement)];
1793
- }
1794
- var keys = ["x", "y", "top", "bottom", "left", "right", "width", "height"];
1795
- var areBoundsEqual = (a, b) => keys.every((key) => a[key] === b[key]);
1796
-
1797
- // src/schematic-components/SchematicText.tsx
1798
- var import_jsx_runtime4 = require("react/jsx-runtime");
1799
- var SchematicText = ({ schematic_text }) => {
1800
- const ct = useGlobalStore((s) => s.camera_transform);
1801
- const { text, position, anchor } = schematic_text;
1802
- const tPos = applyToPoint(ct, position);
1803
- const [boundsRef, bounds] = useMeasure();
1804
- let offset = [0, 0];
1805
- if (anchor === "center") {
1806
- offset = [-bounds.width / 2, -bounds.height / 2];
1807
- } else if (anchor === "left") {
1808
- offset = [0, -bounds.height / 2];
1809
- } else if (anchor === "right") {
1810
- offset = [-bounds.width, -bounds.height / 2];
1811
- }
1812
- const fontTransformRatio = 0.15;
1813
- const projectedTextSize = fontTransformRatio * ct.a;
1814
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1815
- "div",
1816
- {
1817
- ref: boundsRef,
1818
- style: {
1819
- fontFamily: "'IBM Plex Mono', monospace",
1820
- position: "absolute",
1821
- fontSize: projectedTextSize,
1822
- left: tPos.x + offset[0],
1823
- top: tPos.y + offset[1],
1824
- color: schematic_text.color
1825
- },
1826
- children: text
1827
- }
1828
- );
1829
- };
1830
- var SchematicText_default = SchematicText;
1831
-
1832
- // src/schematic-components/SchematicChip.tsx
1833
- var import_jsx_runtime5 = require("react/jsx-runtime");
1834
- var SchematicChip = ({
1835
- component: { source, schematic, allElements }
1836
- }) => {
1837
- const { center, size, rotation, schematic_component_id } = schematic;
1838
- const { manufacturerPartNumber, name } = source;
1839
- const chipWidth = size.width;
1840
- const chipHeight = size.height;
1841
- const paths = [];
1842
- paths.push({
1843
- type: "path",
1844
- strokeWidth: 0.02,
1845
- stroke: colorMap.schematic.component_outline,
1846
- fill: colorMap.schematic.component_body,
1847
- d: `M ${-chipWidth / 2},${-chipHeight / 2} h ${chipWidth} v ${chipHeight} h ${-chipWidth} Z`
1848
- });
1849
- const schematicPorts = allElements.filter(
1850
- (item) => item.type === "schematic_port" && item.schematic_component_id === schematic_component_id
1851
- );
1852
- const portLength = 0.5;
1853
- const circleRadius = 0.04;
1854
- const labelOffset = 0.1;
1855
- for (const port of schematicPorts) {
1856
- const { side, pinNumber, distanceFromEdge } = port.center;
1857
- let x = 0;
1858
- let y = 0;
1859
- let endX = 0;
1860
- let endY = 0;
1861
- let pinX = 0;
1862
- let pinY = 0;
1863
- let textAnchor = "middle";
1864
- let rotation2 = 0;
1865
- if (side === "center") {
1866
- continue;
1867
- }
1868
- switch (side) {
1869
- case "left":
1870
- x = -chipWidth / 2;
1871
- y = -chipHeight / 2 + distanceFromEdge;
1872
- endX = x - portLength;
1873
- endY = y;
1874
- pinX = x - portLength / 2;
1875
- pinY = y + labelOffset;
1876
- textAnchor = "middle";
1877
- break;
1878
- case "right":
1879
- x = chipWidth / 2;
1880
- y = chipHeight / 2 - distanceFromEdge;
1881
- endX = x + portLength;
1882
- endY = y;
1883
- pinX = x + portLength / 2 - labelOffset;
1884
- pinY = y + labelOffset;
1885
- textAnchor = "start";
1886
- break;
1887
- case "bottom":
1888
- x = -chipWidth / 2 + distanceFromEdge;
1889
- y = -chipHeight / 2;
1890
- endX = x;
1891
- endY = y - portLength;
1892
- pinX = x - labelOffset;
1893
- pinY = y - portLength / 2;
1894
- rotation2 = -90;
1895
- break;
1896
- case "top":
1897
- x = chipWidth / 2 - distanceFromEdge;
1898
- y = chipHeight / 2;
1899
- endX = x;
1900
- endY = y + portLength;
1901
- pinX = x - labelOffset;
1902
- pinY = y + portLength / 2;
1903
- rotation2 = -90;
1904
- break;
1905
- }
1906
- paths.push({
1907
- type: "path",
1908
- strokeWidth: 0.015,
1909
- stroke: colorMap.schematic.component_outline,
1910
- d: `M ${x},${y} L ${endX},${endY}`
1911
- });
1912
- paths.push({
1913
- type: "circle",
1914
- cx: endX,
1915
- cy: endY,
1916
- r: circleRadius,
1917
- strokeWidth: 5e-3,
1918
- stroke: colorMap.schematic.component_outline,
1919
- fill: colorMap.schematic.component_outline
1920
- });
1921
- if (pinNumber !== void 0) {
1922
- paths.push({
1923
- type: "text",
1924
- cx: pinX,
1925
- cy: pinY,
1926
- text: `${pinNumber}`,
1927
- anchor: textAnchor,
1928
- rotation: rotation2,
1929
- strokeWidth: 5e-3,
1930
- stroke: colorMap.schematic.pin_number
1931
- });
1932
- }
1933
- }
1934
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
1935
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1936
- SVGPathComponent_default,
1937
- {
1938
- rotation,
1939
- center,
1940
- size,
1941
- paths
1942
- }
1943
- ),
1944
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1945
- SchematicText_default,
1946
- {
1947
- schematic_text: {
1948
- anchor: "right",
1949
- rotation: 0,
1950
- position: {
1951
- x: center.x,
1952
- y: center.y - chipHeight / 2 - 0.2
1953
- },
1954
- schematic_component_id: "SYNTHETIC",
1955
- schematic_text_id: "SYNTHETIC_MPN",
1956
- text: manufacturerPartNumber,
1957
- type: "schematic_text",
1958
- color: colorMap.schematic.reference
1959
- }
1960
- }
1961
- ),
1962
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1963
- SchematicText_default,
1964
- {
1965
- schematic_text: {
1966
- anchor: "right",
1967
- rotation: 0,
1968
- position: {
1969
- x: center.x,
1970
- y: center.y + chipHeight / 2 + 0.2
1971
- },
1972
- schematic_component_id: "SYNTHETIC",
1973
- schematic_text_id: "SYNTHETIC_NAME",
1974
- text: name,
1975
- type: "schematic_text",
1976
- color: colorMap.schematic.reference
1977
- }
1978
- }
1979
- )
1980
- ] });
1981
- };
1982
-
1983
- // src/schematic-components/SchematicComponent.tsx
1984
- var import_jsx_runtime6 = require("react/jsx-runtime");
1985
- var SchematicComponent = ({ component }) => {
1986
- const { source, schematic, allElements } = component;
1987
- if (!source.ftype)
1988
- return null;
1989
- switch (source.ftype) {
1990
- case "simple_resistor":
1991
- case "simple_capacitor":
1992
- case "simple_power_source":
1993
- case "simple_ground":
1994
- case "simple_inductor":
1995
- case "simple_diode": {
1996
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1997
- SchematicComponentFromSymbol,
1998
- {
1999
- component: { source, schematic }
2000
- }
2001
- );
2002
- }
2003
- case "simple_chip":
2004
- case "simple_bug": {
2005
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
2006
- SchematicChip,
2007
- {
2008
- component: { source, schematic, allElements }
2009
- }
2010
- );
2011
- }
2012
- default: {
2013
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { children: [
2014
- "unknown ftype: ",
2015
- component.source.ftype
2016
- ] });
2017
- }
2018
- }
2019
- };
2020
- var SchematicComponent_default = SchematicComponent;
2021
-
2022
- // src/schematic-components/SchematicComponentFromSymbol.tsx
2023
- var import_schematic_symbols = require("schematic-symbols");
2024
- var import_jsx_runtime7 = require("react/jsx-runtime");
2025
- var SchematicComponentFromSymbol = ({
2026
- component: { source, schematic }
2027
- }) => {
2028
- const { center, rotation } = schematic;
2029
- const symbol = import_schematic_symbols.symbols[schematic.symbol_name];
2030
- const paths = symbol.primitives.filter((p) => p.type === "path").map((p) => ({
2031
- stroke: colorMap.schematic.component_outline,
2032
- strokeWidth: 0.02,
2033
- d: p.points.reduce(
2034
- (acc, point, index) => {
2035
- const command = index === 0 ? "M" : "L";
2036
- return `${acc} ${command} ${point.x} ${point.y}`;
2037
- },
2038
- ""
2039
- )
2040
- }));
2041
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2042
- SVGPathComponent_default,
2043
- {
2044
- rotation,
2045
- center,
2046
- size: {
2047
- width: symbol?.size.width,
2048
- height: symbol?.size.height
2049
- },
2050
- paths
2051
- }
2052
- );
2053
- };
2054
-
2055
- // src/schematic-components/SchematicTrace.tsx
2056
- var import_svg_path_generator = __toESM(require_svg_path_generator2());
2057
- var import_jsx_runtime8 = require("react/jsx-runtime");
2058
- var SchematicTrace = ({ trace: { source, schematic } }) => {
2059
- const edges = schematic.edges;
2060
- if (edges.length === 0) {
2061
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(RenderError_default, { text: `Route with 0 edges (${source.source_trace_id})` });
2062
- }
2063
- const path = (0, import_svg_path_generator.default)();
2064
- for (let i = 0; i < edges.length; i++) {
2065
- path.moveTo(edges[i].from.x, edges[i].from.y);
2066
- path.lineTo(edges[i].to.x, edges[i].to.y);
2067
- }
2068
- const d = path.toString();
2069
- const pathBounds = get_svg_path_bounds_default(d);
2070
- pathBounds.height = Math.max(pathBounds.height, 1);
2071
- pathBounds.width = Math.max(pathBounds.width, 1);
2072
- const center = {
2073
- x: pathBounds.minX + pathBounds.width / 2,
2074
- y: pathBounds.minY + pathBounds.height / 2
2075
- };
2076
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2077
- SVGPathComponent_default,
2078
- {
2079
- rotation: 0,
2080
- center,
2081
- size: pathBounds,
2082
- paths: [
2083
- {
2084
- stroke: colorMap.schematic.wire,
2085
- strokeWidth: 0.01,
2086
- d
2087
- }
2088
- ]
2089
- }
2090
- );
2091
- };
2092
- var SchematicTrace_default = SchematicTrace;
2093
-
2094
- // src/lib/render-context/index.ts
2095
- var createRenderContextStore = () => createStore((set) => ({
2096
- camera_transform: compose(scale(100, 100, 0, 0)),
2097
- setCameraTransform: (transform2) => set({ camera_transform: transform2 })
2098
- }));
2099
- var useGlobalStore = (s) => {
2100
- const store = (0, import_react6.useContext)(StoreContext);
2101
- return useStore(store, s);
2102
- };
2103
-
2104
- // src/Schematic.tsx
2105
- var import_react8 = require("react");
2106
- var import_react_error_boundary = require("react-error-boundary");
2107
- var import_react_supergrid = require("react-supergrid");
2108
-
2109
- // src/lib/utils/collect-element-refs.ts
2110
- var collectElementRefs = (elm, allElms) => {
2111
- const source_port = allElms.find(
2112
- (e) => e.type === "source_port" && e.source_port_id === elm.source_port_id
2113
- );
2114
- const source_component_id = elm.source_component_id ?? source_port?.source_component_id;
2115
- const source_component = allElms.find(
2116
- (e) => e.type === "source_component" && e.source_component_id === source_component_id
2117
- );
2118
- if ([
2119
- "schematic_component",
2120
- "schematic_trace",
2121
- "schematic_port",
2122
- "schematic_box",
2123
- "schematic_line",
2124
- "schematic_path"
2125
- ].includes(elm.type)) {
2126
- const schematic_children = allElms.filter(
2127
- (e) => "schematic_component_id" in e && e.schematic_component_id === elm.schematic_component_id
2128
- );
2129
- return {
2130
- schematic_children,
2131
- schematic: elm,
2132
- source: source_component,
2133
- source_component,
2134
- source_port,
2135
- allElements: allElms
2136
- };
2137
- }
2138
- return null;
2139
- };
2140
-
2141
- // src/lib/utils/get-rotation-from-anchor-side.ts
2142
- var getRotationFromAnchorSide = (anchor_side) => {
2143
- if (anchor_side === "left")
2144
- return 0;
2145
- if (anchor_side === "top")
2146
- return Math.PI * 3 / 2;
2147
- if (anchor_side === "right")
2148
- return Math.PI;
2149
- if (anchor_side === "bottom")
2150
- return Math.PI / 2;
2151
- return 0;
2152
- };
2153
-
2154
- // src/lib/utils/get-vec-from-anchor-side.ts
2155
- var getVecFromAnchorSide = (anchor_side) => {
2156
- if (anchor_side === "left")
2157
- return { x: -1, y: 0 };
2158
- if (anchor_side === "top")
2159
- return { x: 0, y: -1 };
2160
- if (anchor_side === "right")
2161
- return { x: 1, y: 0 };
2162
- if (anchor_side === "bottom")
2163
- return { x: 0, y: 1 };
2164
- throw new Error(`invalid anchor side "${anchor_side}"`);
2165
- };
2166
-
2167
- // src/schematic-components/SchematicNetLabel.tsx
2168
- var import_jsx_runtime9 = require("react/jsx-runtime");
2169
- var SchematicNetLabel = ({
2170
- net_label
2171
- }) => {
2172
- const anchor_side = net_label.anchor_side;
2173
- const is_vertical = anchor_side === "top" || anchor_side === "bottom";
2174
- const text_width = is_vertical ? 0.3 : net_label.text.length * 0.15;
2175
- const path_width = 31 + net_label.text.length * 5;
2176
- const anchor_vec = getVecFromAnchorSide(anchor_side);
2177
- const anchor_dist = is_vertical ? 0.04 : text_width / 4;
2178
- anchor_vec.x *= anchor_dist;
2179
- anchor_vec.y *= anchor_dist;
2180
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
2181
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
2182
- SVGPathComponent_default,
2183
- {
2184
- rotation: getRotationFromAnchorSide(anchor_side),
2185
- center: net_label.center,
2186
- size: {
2187
- width: 0.05 + text_width,
2188
- height: 0.2 + (is_vertical ? 0.1 * Math.max(1, net_label.text.length - 2) : 0)
2189
- },
2190
- paths: [
2191
- {
2192
- stroke: "gray",
2193
- strokeWidth: 0.75,
2194
- // d: `M 0 15 L 5 15 L 11 9 L ${path_width} 9 L ${path_width} 21 L 11 21 L 5 15`,
2195
- d: `M 0 15 L 5 15 L 11 5 L ${path_width} 5 L ${path_width} 26 L 11 26 L 5 15`
2196
- }
2197
- ]
2198
- }
2199
- ),
2200
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
2201
- SchematicText_default,
2202
- {
2203
- schematic_text: {
2204
- rotation: is_vertical ? 0 : getRotationFromAnchorSide(anchor_side),
2205
- anchor: is_vertical ? "center" : anchor_side,
2206
- position: {
2207
- x: net_label.center.x + anchor_vec.x,
2208
- y: net_label.center.y + anchor_vec.y
2209
- },
2210
- schematic_component_id: "SYNTHETIC",
2211
- schematic_text_id: "SYNTHETIC",
2212
- text: net_label.text,
2213
- type: "schematic_text",
2214
- color: colorMap.schematic.net_name
2215
- }
2216
- }
2217
- )
2218
- ] });
2219
- };
2220
-
2221
- // src/schematic-components/SchematicElement.tsx
2222
- var import_jsx_runtime10 = require("react/jsx-runtime");
2223
- var SchematicElement = ({
2224
- element,
2225
- allElements
2226
- }) => {
2227
- if (element.type === "schematic_component") {
2228
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
2229
- SchematicComponent_default,
2230
- {
2231
- component: collectElementRefs(element, allElements)
2232
- }
2233
- );
2234
- }
2235
- if (element.type === "schematic_trace") {
2236
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(SchematicTrace_default, { trace: collectElementRefs(element, allElements) });
2237
- }
2238
- if (element.type === "schematic_text") {
2239
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(SchematicText_default, { schematic_text: element });
2240
- }
2241
- if (element.type === "schematic_net_label") {
2242
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(SchematicNetLabel, { net_label: element });
2243
- }
2244
- return null;
2245
- };
2246
-
2247
- // src/schematic-components/TableViewer.tsx
2248
- var import_react7 = require("react");
2249
- var import_jsx_runtime11 = require("react/jsx-runtime");
2250
- var LazyTableViewer = (0, import_react7.lazy)(
2251
- () => import("@tscircuit/table-viewer").then((m) => ({
2252
- default: m.SoupTableViewer
2253
- }))
2254
- );
2255
- 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 }) });
2256
-
2257
- // src/Schematic.tsx
2258
- var import_jsx_runtime12 = require("react/jsx-runtime");
2259
- var ErrorBoundary = import_react_error_boundary.ErrorBoundary;
2260
- var fallbackRender = (elm) => ({ error, resetErrorBoundary }) => {
2261
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { style: { color: "red" }, children: [
2262
- "error rendering ",
2263
- elm.type,
2264
- ": ",
2265
- error.toString()
2266
- ] });
2267
- };
2268
- var toMMSINeg = (v, z) => v >= 0 ? (0, import_react_supergrid.toMMSI)(v, z) : `-${(0, import_react_supergrid.toMMSI)(-v, z)}`;
2269
- var Schematic = (props) => {
2270
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(ContextProviders, { children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(SchematicWithoutContext, { ...props }) });
2271
- };
2272
- var SchematicWithoutContext = ({
2273
- children,
2274
- soup,
2275
- style,
2276
- showTable = false,
2277
- _soupPostProcessor
2278
- }) => {
2279
- const {
2280
- circuitJson: circuitJsonFromChildren,
2281
- error: errorFromChildren,
2282
- isLoading
2283
- } = (0, import_core.useRenderedCircuit)(children);
2284
- const [elements, setElements] = (0, import_react8.useState)([]);
2285
- const { setCameraTransform } = useGlobalStore();
2286
- const [boundsRef, bounds] = useMeasure();
2287
- const containerRef = (0, import_react8.useRef)(null);
2288
- const transformRef = (0, import_react8.useRef)(compose(translate(0, 0), scale(1, 1)));
2289
- const isDraggingRef = (0, import_react8.useRef)(false);
2290
- const lastMousePosRef = (0, import_react8.useRef)({ x: 0, y: 0 });
2291
- const [, forceUpdate] = (0, import_react8.useState)({});
2292
- const updateTransform = (0, import_react8.useCallback)(
2293
- (newTransform) => {
2294
- transformRef.current = newTransform;
2295
- setCameraTransform(newTransform);
2296
- forceUpdate({});
2297
- },
2298
- [setCameraTransform]
2299
- );
2300
- (0, import_react8.useEffect)(() => {
2301
- let processedElements = [];
2302
- if (circuitJsonFromChildren && (!soup || soup.length === 0)) {
2303
- processedElements = circuitJsonFromChildren;
2304
- } else if (soup && soup.length > 0) {
2305
- processedElements = soup;
2306
- }
2307
- if (processedElements.length > 0) {
2308
- if (_soupPostProcessor) {
2309
- processedElements = _soupPostProcessor(processedElements);
2310
- }
2311
- setElements(processedElements);
2312
- }
2313
- }, [circuitJsonFromChildren, soup, _soupPostProcessor]);
2314
- (0, import_react8.useEffect)(() => {
2315
- if (elements.length > 0 && containerRef.current) {
2316
- const elmBounds = containerRef.current.getBoundingClientRect();
2317
- const { center, width, height } = elements.some(
2318
- (e) => e.type.startsWith("schematic_")
2319
- ) ? (0, import_soup_util.findBoundsAndCenter)(
2320
- elements.filter((e) => e.type.startsWith("schematic_"))
2321
- ) : { center: { x: 0, y: 0 }, width: 1e-3, height: 1e-3 };
2322
- const scaleFactor = Math.min(
2323
- (elmBounds.width ?? 0) / width,
2324
- (elmBounds.height ?? 0) / height,
2325
- 100
2326
- );
2327
- const newTransform = compose(
2328
- translate((elmBounds.width ?? 0) / 2, (elmBounds.height ?? 0) / 2),
2329
- scale(scaleFactor, -scaleFactor, 0, 0),
2330
- translate(-center.x, -center.y)
2331
- );
2332
- updateTransform(newTransform);
2333
- }
2334
- }, [elements, updateTransform]);
2335
- const handleMouseDown = (0, import_react8.useCallback)((e) => {
2336
- isDraggingRef.current = true;
2337
- lastMousePosRef.current = { x: e.clientX, y: e.clientY };
2338
- }, []);
2339
- const handleMouseMove = (0, import_react8.useCallback)(
2340
- (e) => {
2341
- if (!isDraggingRef.current)
2342
- return;
2343
- const dx = e.clientX - lastMousePosRef.current.x;
2344
- const dy = e.clientY - lastMousePosRef.current.y;
2345
- lastMousePosRef.current = { x: e.clientX, y: e.clientY };
2346
- const inverseTransform = inverse(transformRef.current);
2347
- const dragStart = applyToPoint(inverseTransform, { x: 0, y: 0 });
2348
- const dragEnd = applyToPoint(inverseTransform, { x: dx, y: dy });
2349
- const worldDx = dragEnd.x - dragStart.x;
2350
- const worldDy = dragEnd.y - dragStart.y;
2351
- const newTransform = compose(
2352
- transformRef.current,
2353
- translate(worldDx, worldDy)
2354
- );
2355
- updateTransform(newTransform);
2356
- },
2357
- [updateTransform]
2358
- );
2359
- const handleMouseUp = (0, import_react8.useCallback)(() => {
2360
- isDraggingRef.current = false;
2361
- }, []);
2362
- const handleWheel = (0, import_react8.useCallback)(
2363
- (e) => {
2364
- e.preventDefault();
2365
- const scaleMultiplier = 0.999 ** e.deltaY;
2366
- if (containerRef.current) {
2367
- const rect = containerRef.current.getBoundingClientRect();
2368
- const mouseX = e.clientX - rect.left;
2369
- const mouseY = e.clientY - rect.top;
2370
- const inverseTransform = inverse(transformRef.current);
2371
- const transformedPoint = applyToPoint(inverseTransform, {
2372
- x: mouseX,
2373
- y: mouseY
2374
- });
2375
- const newTransform = compose(
2376
- transformRef.current,
2377
- translate(transformedPoint.x, transformedPoint.y),
2378
- scale(scaleMultiplier, scaleMultiplier),
2379
- translate(-transformedPoint.x, -transformedPoint.y)
2380
- );
2381
- updateTransform(newTransform);
2382
- }
2383
- },
2384
- [updateTransform]
2385
- );
2386
- (0, import_react8.useEffect)(() => {
2387
- const container = containerRef.current;
2388
- if (container) {
2389
- container.addEventListener("wheel", handleWheel, { passive: false });
2390
- return () => {
2391
- container.removeEventListener("wheel", handleWheel);
2392
- };
2393
- }
2394
- }, [handleWheel]);
2395
- if (errorFromChildren) {
2396
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { children: [
2397
- "Error: ",
2398
- errorFromChildren.message
2399
- ] });
2400
- }
2401
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_jsx_runtime12.Fragment, { children: [
2402
- /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
2403
- "div",
2404
- {
2405
- style: {
2406
- width: "100%",
2407
- backgroundColor: "rgba(255,255,255,0)",
2408
- minHeight: 200,
2409
- overflow: "hidden",
2410
- position: "relative",
2411
- isolation: "isolate",
2412
- cursor: isDraggingRef.current ? "grabbing" : "grab",
2413
- ...style
2414
- },
2415
- ref: (el) => {
2416
- containerRef.current = el;
2417
- boundsRef(el);
2418
- },
2419
- onMouseDown: handleMouseDown,
2420
- onMouseMove: handleMouseMove,
2421
- onMouseUp: handleMouseUp,
2422
- onMouseLeave: handleMouseUp,
2423
- children: [
2424
- /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
2425
- import_react_supergrid.SuperGrid,
2426
- {
2427
- stringifyCoord: (x, y, z) => {
2428
- if (z === 0)
2429
- return "";
2430
- return `${toMMSINeg(x, z)}, ${toMMSINeg(y, z)}`;
2431
- },
2432
- width: bounds.width,
2433
- height: bounds.height,
2434
- transform: transformRef.current
2435
- }
2436
- ),
2437
- elements?.map((elm, i) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(ErrorBoundary, { fallbackRender: fallbackRender(elm), children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
2438
- SchematicElement,
2439
- {
2440
- element: elm,
2441
- allElements: elements
2442
- },
2443
- JSON.stringify(elm)
2444
- ) }, `${elm}`))
2445
- ]
2446
- }
2447
- ),
2448
- showTable !== false && elements && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(TableViewer, { elements })
2449
- ] });
2450
- };
2451
- // Annotate the CommonJS export names for ESM import in node:
2452
- 0 && (module.exports = {
2453
- Schematic,
2454
- SchematicWithoutContext
2455
- });
2456
- /*! Bundled license information:
2457
-
2458
- use-sync-external-store/cjs/use-sync-external-store-shim.production.min.js:
2459
- (**
2460
- * @license React
2461
- * use-sync-external-store-shim.production.min.js
2462
- *
2463
- * Copyright (c) Facebook, Inc. and its affiliates.
2464
- *
2465
- * This source code is licensed under the MIT license found in the
2466
- * LICENSE file in the root directory of this source tree.
2467
- *)
2468
-
2469
- use-sync-external-store/cjs/use-sync-external-store-shim.development.js:
2470
- (**
2471
- * @license React
2472
- * use-sync-external-store-shim.development.js
2473
- *
2474
- * Copyright (c) Facebook, Inc. and its affiliates.
2475
- *
2476
- * This source code is licensed under the MIT license found in the
2477
- * LICENSE file in the root directory of this source tree.
2478
- *)
2479
-
2480
- use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.js:
2481
- (**
2482
- * @license React
2483
- * use-sync-external-store-shim/with-selector.production.min.js
2484
- *
2485
- * Copyright (c) Facebook, Inc. and its affiliates.
2486
- *
2487
- * This source code is licensed under the MIT license found in the
2488
- * LICENSE file in the root directory of this source tree.
2489
- *)
2490
-
2491
- use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js:
2492
- (**
2493
- * @license React
2494
- * use-sync-external-store-shim/with-selector.development.js
2495
- *
2496
- * Copyright (c) Facebook, Inc. and its affiliates.
2497
- *
2498
- * This source code is licensed under the MIT license found in the
2499
- * LICENSE file in the root directory of this source tree.
2500
- *)
2501
- */
2502
- //# sourceMappingURL=index.js.map