@tscircuit/schematic-viewer 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,2113 @@
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
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.js
32
+ var require_use_sync_external_store_shim_production_min = __commonJS({
33
+ "node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.js"(exports) {
34
+ "use strict";
35
+ var e = require("react");
36
+ function h(a, b) {
37
+ return a === b && (0 !== a || 1 / a === 1 / b) || a !== a && b !== b;
38
+ }
39
+ var k = "function" === typeof Object.is ? Object.is : h;
40
+ var l = e.useState;
41
+ var m = e.useEffect;
42
+ var n = e.useLayoutEffect;
43
+ var p = e.useDebugValue;
44
+ function q(a, b) {
45
+ var d = b(), f = l({ inst: { value: d, getSnapshot: b } }), c = f[0].inst, g = f[1];
46
+ n(function() {
47
+ c.value = d;
48
+ c.getSnapshot = b;
49
+ r(c) && g({ inst: c });
50
+ }, [a, d, b]);
51
+ m(function() {
52
+ r(c) && g({ inst: c });
53
+ return a(function() {
54
+ r(c) && g({ inst: c });
55
+ });
56
+ }, [a]);
57
+ p(d);
58
+ return d;
59
+ }
60
+ function r(a) {
61
+ var b = a.getSnapshot;
62
+ a = a.value;
63
+ try {
64
+ var d = b();
65
+ return !k(a, d);
66
+ } catch (f) {
67
+ return true;
68
+ }
69
+ }
70
+ function t(a, b) {
71
+ return b();
72
+ }
73
+ var u = "undefined" === typeof window || "undefined" === typeof window.document || "undefined" === typeof window.document.createElement ? t : q;
74
+ exports.useSyncExternalStore = void 0 !== e.useSyncExternalStore ? e.useSyncExternalStore : u;
75
+ }
76
+ });
77
+
78
+ // node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js
79
+ var require_use_sync_external_store_shim_development = __commonJS({
80
+ "node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js"(exports) {
81
+ "use strict";
82
+ if (process.env.NODE_ENV !== "production") {
83
+ (function() {
84
+ "use strict";
85
+ if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart === "function") {
86
+ __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
87
+ }
88
+ var React = require("react");
89
+ var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
90
+ function error(format) {
91
+ {
92
+ {
93
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
94
+ args[_key2 - 1] = arguments[_key2];
95
+ }
96
+ printWarning("error", format, args);
97
+ }
98
+ }
99
+ }
100
+ function printWarning(level, format, args) {
101
+ {
102
+ var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
103
+ var stack = ReactDebugCurrentFrame.getStackAddendum();
104
+ if (stack !== "") {
105
+ format += "%s";
106
+ args = args.concat([stack]);
107
+ }
108
+ var argsWithFormat = args.map(function(item) {
109
+ return String(item);
110
+ });
111
+ argsWithFormat.unshift("Warning: " + format);
112
+ Function.prototype.apply.call(console[level], console, argsWithFormat);
113
+ }
114
+ }
115
+ function is(x, y) {
116
+ return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y;
117
+ }
118
+ var objectIs = typeof Object.is === "function" ? Object.is : is;
119
+ var useState4 = React.useState, useEffect4 = React.useEffect, useLayoutEffect = React.useLayoutEffect, useDebugValue2 = React.useDebugValue;
120
+ var didWarnOld18Alpha = false;
121
+ var didWarnUncachedGetSnapshot = false;
122
+ function useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot) {
123
+ {
124
+ if (!didWarnOld18Alpha) {
125
+ if (React.startTransition !== void 0) {
126
+ didWarnOld18Alpha = true;
127
+ 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.");
128
+ }
129
+ }
130
+ }
131
+ var value = getSnapshot();
132
+ {
133
+ if (!didWarnUncachedGetSnapshot) {
134
+ var cachedValue = getSnapshot();
135
+ if (!objectIs(value, cachedValue)) {
136
+ error("The result of getSnapshot should be cached to avoid an infinite loop");
137
+ didWarnUncachedGetSnapshot = true;
138
+ }
139
+ }
140
+ }
141
+ var _useState = useState4({
142
+ inst: {
143
+ value,
144
+ getSnapshot
145
+ }
146
+ }), inst = _useState[0].inst, forceUpdate = _useState[1];
147
+ useLayoutEffect(function() {
148
+ inst.value = value;
149
+ inst.getSnapshot = getSnapshot;
150
+ if (checkIfSnapshotChanged(inst)) {
151
+ forceUpdate({
152
+ inst
153
+ });
154
+ }
155
+ }, [subscribe, value, getSnapshot]);
156
+ useEffect4(function() {
157
+ if (checkIfSnapshotChanged(inst)) {
158
+ forceUpdate({
159
+ inst
160
+ });
161
+ }
162
+ var handleStoreChange = function() {
163
+ if (checkIfSnapshotChanged(inst)) {
164
+ forceUpdate({
165
+ inst
166
+ });
167
+ }
168
+ };
169
+ return subscribe(handleStoreChange);
170
+ }, [subscribe]);
171
+ useDebugValue2(value);
172
+ return value;
173
+ }
174
+ function checkIfSnapshotChanged(inst) {
175
+ var latestGetSnapshot = inst.getSnapshot;
176
+ var prevValue = inst.value;
177
+ try {
178
+ var nextValue = latestGetSnapshot();
179
+ return !objectIs(prevValue, nextValue);
180
+ } catch (error2) {
181
+ return true;
182
+ }
183
+ }
184
+ function useSyncExternalStore$1(subscribe, getSnapshot, getServerSnapshot) {
185
+ return getSnapshot();
186
+ }
187
+ var canUseDOM = !!(typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined");
188
+ var isServerEnvironment = !canUseDOM;
189
+ var shim = isServerEnvironment ? useSyncExternalStore$1 : useSyncExternalStore;
190
+ var useSyncExternalStore$2 = React.useSyncExternalStore !== void 0 ? React.useSyncExternalStore : shim;
191
+ exports.useSyncExternalStore = useSyncExternalStore$2;
192
+ if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop === "function") {
193
+ __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
194
+ }
195
+ })();
196
+ }
197
+ }
198
+ });
199
+
200
+ // node_modules/use-sync-external-store/shim/index.js
201
+ var require_shim = __commonJS({
202
+ "node_modules/use-sync-external-store/shim/index.js"(exports, module2) {
203
+ "use strict";
204
+ if (process.env.NODE_ENV === "production") {
205
+ module2.exports = require_use_sync_external_store_shim_production_min();
206
+ } else {
207
+ module2.exports = require_use_sync_external_store_shim_development();
208
+ }
209
+ }
210
+ });
211
+
212
+ // node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.js
213
+ var require_with_selector_production_min = __commonJS({
214
+ "node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.js"(exports) {
215
+ "use strict";
216
+ var h = require("react");
217
+ var n = require_shim();
218
+ function p(a, b) {
219
+ return a === b && (0 !== a || 1 / a === 1 / b) || a !== a && b !== b;
220
+ }
221
+ var q = "function" === typeof Object.is ? Object.is : p;
222
+ var r = n.useSyncExternalStore;
223
+ var t = h.useRef;
224
+ var u = h.useEffect;
225
+ var v = h.useMemo;
226
+ var w = h.useDebugValue;
227
+ exports.useSyncExternalStoreWithSelector = function(a, b, e, l, g) {
228
+ var c = t(null);
229
+ if (null === c.current) {
230
+ var f = { hasValue: false, value: null };
231
+ c.current = f;
232
+ } else
233
+ f = c.current;
234
+ c = v(function() {
235
+ function a2(a3) {
236
+ if (!c2) {
237
+ c2 = true;
238
+ d2 = a3;
239
+ a3 = l(a3);
240
+ if (void 0 !== g && f.hasValue) {
241
+ var b2 = f.value;
242
+ if (g(b2, a3))
243
+ return k = b2;
244
+ }
245
+ return k = a3;
246
+ }
247
+ b2 = k;
248
+ if (q(d2, a3))
249
+ return b2;
250
+ var e2 = l(a3);
251
+ if (void 0 !== g && g(b2, e2))
252
+ return b2;
253
+ d2 = a3;
254
+ return k = e2;
255
+ }
256
+ var c2 = false, d2, k, m = void 0 === e ? null : e;
257
+ return [function() {
258
+ return a2(b());
259
+ }, null === m ? void 0 : function() {
260
+ return a2(m());
261
+ }];
262
+ }, [b, e, l, g]);
263
+ var d = r(a, c[0], c[1]);
264
+ u(function() {
265
+ f.hasValue = true;
266
+ f.value = d;
267
+ }, [d]);
268
+ w(d);
269
+ return d;
270
+ };
271
+ }
272
+ });
273
+
274
+ // node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js
275
+ var require_with_selector_development = __commonJS({
276
+ "node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js"(exports) {
277
+ "use strict";
278
+ if (process.env.NODE_ENV !== "production") {
279
+ (function() {
280
+ "use strict";
281
+ if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart === "function") {
282
+ __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
283
+ }
284
+ var React = require("react");
285
+ var shim = require_shim();
286
+ function is(x, y) {
287
+ return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y;
288
+ }
289
+ var objectIs = typeof Object.is === "function" ? Object.is : is;
290
+ var useSyncExternalStore = shim.useSyncExternalStore;
291
+ var useRef2 = React.useRef, useEffect4 = React.useEffect, useMemo2 = React.useMemo, useDebugValue2 = React.useDebugValue;
292
+ function useSyncExternalStoreWithSelector2(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
293
+ var instRef = useRef2(null);
294
+ var inst;
295
+ if (instRef.current === null) {
296
+ inst = {
297
+ hasValue: false,
298
+ value: null
299
+ };
300
+ instRef.current = inst;
301
+ } else {
302
+ inst = instRef.current;
303
+ }
304
+ var _useMemo = useMemo2(function() {
305
+ var hasMemo = false;
306
+ var memoizedSnapshot;
307
+ var memoizedSelection;
308
+ var memoizedSelector = function(nextSnapshot) {
309
+ if (!hasMemo) {
310
+ hasMemo = true;
311
+ memoizedSnapshot = nextSnapshot;
312
+ var _nextSelection = selector(nextSnapshot);
313
+ if (isEqual !== void 0) {
314
+ if (inst.hasValue) {
315
+ var currentSelection = inst.value;
316
+ if (isEqual(currentSelection, _nextSelection)) {
317
+ memoizedSelection = currentSelection;
318
+ return currentSelection;
319
+ }
320
+ }
321
+ }
322
+ memoizedSelection = _nextSelection;
323
+ return _nextSelection;
324
+ }
325
+ var prevSnapshot = memoizedSnapshot;
326
+ var prevSelection = memoizedSelection;
327
+ if (objectIs(prevSnapshot, nextSnapshot)) {
328
+ return prevSelection;
329
+ }
330
+ var nextSelection = selector(nextSnapshot);
331
+ if (isEqual !== void 0 && isEqual(prevSelection, nextSelection)) {
332
+ return prevSelection;
333
+ }
334
+ memoizedSnapshot = nextSnapshot;
335
+ memoizedSelection = nextSelection;
336
+ return nextSelection;
337
+ };
338
+ var maybeGetServerSnapshot = getServerSnapshot === void 0 ? null : getServerSnapshot;
339
+ var getSnapshotWithSelector = function() {
340
+ return memoizedSelector(getSnapshot());
341
+ };
342
+ var getServerSnapshotWithSelector = maybeGetServerSnapshot === null ? void 0 : function() {
343
+ return memoizedSelector(maybeGetServerSnapshot());
344
+ };
345
+ return [getSnapshotWithSelector, getServerSnapshotWithSelector];
346
+ }, [getSnapshot, getServerSnapshot, selector, isEqual]), getSelection = _useMemo[0], getServerSelection = _useMemo[1];
347
+ var value = useSyncExternalStore(subscribe, getSelection, getServerSelection);
348
+ useEffect4(function() {
349
+ inst.hasValue = true;
350
+ inst.value = value;
351
+ }, [value]);
352
+ useDebugValue2(value);
353
+ return value;
354
+ }
355
+ exports.useSyncExternalStoreWithSelector = useSyncExternalStoreWithSelector2;
356
+ if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop === "function") {
357
+ __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
358
+ }
359
+ })();
360
+ }
361
+ }
362
+ });
363
+
364
+ // node_modules/use-sync-external-store/shim/with-selector.js
365
+ var require_with_selector = __commonJS({
366
+ "node_modules/use-sync-external-store/shim/with-selector.js"(exports, module2) {
367
+ "use strict";
368
+ if (process.env.NODE_ENV === "production") {
369
+ module2.exports = require_with_selector_production_min();
370
+ } else {
371
+ module2.exports = require_with_selector_development();
372
+ }
373
+ }
374
+ });
375
+
376
+ // node_modules/parse-svg-path/index.js
377
+ var require_parse_svg_path = __commonJS({
378
+ "node_modules/parse-svg-path/index.js"(exports, module2) {
379
+ module2.exports = parse;
380
+ var length = { a: 7, c: 6, h: 1, l: 2, m: 2, q: 4, s: 4, t: 2, v: 1, z: 0 };
381
+ var segment = /([astvzqmhlc])([^astvzqmhlc]*)/ig;
382
+ function parse(path) {
383
+ var data = [];
384
+ path.replace(segment, function(_, command, args) {
385
+ var type = command.toLowerCase();
386
+ args = parseValues(args);
387
+ if (type == "m" && args.length > 2) {
388
+ data.push([command].concat(args.splice(0, 2)));
389
+ type = "l";
390
+ command = command == "m" ? "l" : "L";
391
+ }
392
+ while (true) {
393
+ if (args.length == length[type]) {
394
+ args.unshift(command);
395
+ return data.push(args);
396
+ }
397
+ if (args.length < length[type])
398
+ throw new Error("malformed path data");
399
+ data.push([command].concat(args.splice(0, length[type])));
400
+ }
401
+ });
402
+ return data;
403
+ }
404
+ var number = /-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/ig;
405
+ function parseValues(args) {
406
+ var numbers = args.match(number);
407
+ return numbers ? numbers.map(Number) : [];
408
+ }
409
+ }
410
+ });
411
+
412
+ // node_modules/abs-svg-path/index.js
413
+ var require_abs_svg_path = __commonJS({
414
+ "node_modules/abs-svg-path/index.js"(exports, module2) {
415
+ module2.exports = absolutize;
416
+ function absolutize(path) {
417
+ var startX = 0;
418
+ var startY = 0;
419
+ var x = 0;
420
+ var y = 0;
421
+ return path.map(function(seg) {
422
+ seg = seg.slice();
423
+ var type = seg[0];
424
+ var command = type.toUpperCase();
425
+ if (type != command) {
426
+ seg[0] = command;
427
+ switch (type) {
428
+ case "a":
429
+ seg[6] += x;
430
+ seg[7] += y;
431
+ break;
432
+ case "v":
433
+ seg[1] += y;
434
+ break;
435
+ case "h":
436
+ seg[1] += x;
437
+ break;
438
+ default:
439
+ for (var i = 1; i < seg.length; ) {
440
+ seg[i++] += x;
441
+ seg[i++] += y;
442
+ }
443
+ }
444
+ }
445
+ switch (command) {
446
+ case "Z":
447
+ x = startX;
448
+ y = startY;
449
+ break;
450
+ case "H":
451
+ x = seg[1];
452
+ break;
453
+ case "V":
454
+ y = seg[1];
455
+ break;
456
+ case "M":
457
+ x = startX = seg[1];
458
+ y = startY = seg[2];
459
+ break;
460
+ default:
461
+ x = seg[seg.length - 2];
462
+ y = seg[seg.length - 1];
463
+ }
464
+ return seg;
465
+ });
466
+ }
467
+ }
468
+ });
469
+
470
+ // node_modules/svg-arc-to-cubic-bezier/modules/index.js
471
+ var modules_exports = {};
472
+ __export(modules_exports, {
473
+ default: () => modules_default
474
+ });
475
+ var _slicedToArray, TAU, mapToEllipse, approxUnitArc, vectorAngle, getArcCenter, arcToBezier, modules_default;
476
+ var init_modules = __esm({
477
+ "node_modules/svg-arc-to-cubic-bezier/modules/index.js"() {
478
+ _slicedToArray = function() {
479
+ function sliceIterator(arr, i) {
480
+ var _arr = [];
481
+ var _n = true;
482
+ var _d = false;
483
+ var _e = void 0;
484
+ try {
485
+ for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
486
+ _arr.push(_s.value);
487
+ if (i && _arr.length === i)
488
+ break;
489
+ }
490
+ } catch (err) {
491
+ _d = true;
492
+ _e = err;
493
+ } finally {
494
+ try {
495
+ if (!_n && _i["return"])
496
+ _i["return"]();
497
+ } finally {
498
+ if (_d)
499
+ throw _e;
500
+ }
501
+ }
502
+ return _arr;
503
+ }
504
+ return function(arr, i) {
505
+ if (Array.isArray(arr)) {
506
+ return arr;
507
+ } else if (Symbol.iterator in Object(arr)) {
508
+ return sliceIterator(arr, i);
509
+ } else {
510
+ throw new TypeError("Invalid attempt to destructure non-iterable instance");
511
+ }
512
+ };
513
+ }();
514
+ TAU = Math.PI * 2;
515
+ mapToEllipse = function mapToEllipse2(_ref, rx, ry, cosphi, sinphi, centerx, centery) {
516
+ var x = _ref.x, y = _ref.y;
517
+ x *= rx;
518
+ y *= ry;
519
+ var xp = cosphi * x - sinphi * y;
520
+ var yp = sinphi * x + cosphi * y;
521
+ return {
522
+ x: xp + centerx,
523
+ y: yp + centery
524
+ };
525
+ };
526
+ approxUnitArc = function approxUnitArc2(ang1, ang2) {
527
+ var a = ang2 === 1.5707963267948966 ? 0.551915024494 : ang2 === -1.5707963267948966 ? -0.551915024494 : 4 / 3 * Math.tan(ang2 / 4);
528
+ var x1 = Math.cos(ang1);
529
+ var y1 = Math.sin(ang1);
530
+ var x2 = Math.cos(ang1 + ang2);
531
+ var y2 = Math.sin(ang1 + ang2);
532
+ return [{
533
+ x: x1 - y1 * a,
534
+ y: y1 + x1 * a
535
+ }, {
536
+ x: x2 + y2 * a,
537
+ y: y2 - x2 * a
538
+ }, {
539
+ x: x2,
540
+ y: y2
541
+ }];
542
+ };
543
+ vectorAngle = function vectorAngle2(ux, uy, vx, vy) {
544
+ var sign = ux * vy - uy * vx < 0 ? -1 : 1;
545
+ var dot = ux * vx + uy * vy;
546
+ if (dot > 1) {
547
+ dot = 1;
548
+ }
549
+ if (dot < -1) {
550
+ dot = -1;
551
+ }
552
+ return sign * Math.acos(dot);
553
+ };
554
+ getArcCenter = function getArcCenter2(px, py, cx, cy, rx, ry, largeArcFlag, sweepFlag, sinphi, cosphi, pxp, pyp) {
555
+ var rxsq = Math.pow(rx, 2);
556
+ var rysq = Math.pow(ry, 2);
557
+ var pxpsq = Math.pow(pxp, 2);
558
+ var pypsq = Math.pow(pyp, 2);
559
+ var radicant = rxsq * rysq - rxsq * pypsq - rysq * pxpsq;
560
+ if (radicant < 0) {
561
+ radicant = 0;
562
+ }
563
+ radicant /= rxsq * pypsq + rysq * pxpsq;
564
+ radicant = Math.sqrt(radicant) * (largeArcFlag === sweepFlag ? -1 : 1);
565
+ var centerxp = radicant * rx / ry * pyp;
566
+ var centeryp = radicant * -ry / rx * pxp;
567
+ var centerx = cosphi * centerxp - sinphi * centeryp + (px + cx) / 2;
568
+ var centery = sinphi * centerxp + cosphi * centeryp + (py + cy) / 2;
569
+ var vx1 = (pxp - centerxp) / rx;
570
+ var vy1 = (pyp - centeryp) / ry;
571
+ var vx2 = (-pxp - centerxp) / rx;
572
+ var vy2 = (-pyp - centeryp) / ry;
573
+ var ang1 = vectorAngle(1, 0, vx1, vy1);
574
+ var ang2 = vectorAngle(vx1, vy1, vx2, vy2);
575
+ if (sweepFlag === 0 && ang2 > 0) {
576
+ ang2 -= TAU;
577
+ }
578
+ if (sweepFlag === 1 && ang2 < 0) {
579
+ ang2 += TAU;
580
+ }
581
+ return [centerx, centery, ang1, ang2];
582
+ };
583
+ arcToBezier = function arcToBezier2(_ref2) {
584
+ 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;
585
+ var curves = [];
586
+ if (rx === 0 || ry === 0) {
587
+ return [];
588
+ }
589
+ var sinphi = Math.sin(xAxisRotation * TAU / 360);
590
+ var cosphi = Math.cos(xAxisRotation * TAU / 360);
591
+ var pxp = cosphi * (px - cx) / 2 + sinphi * (py - cy) / 2;
592
+ var pyp = -sinphi * (px - cx) / 2 + cosphi * (py - cy) / 2;
593
+ if (pxp === 0 && pyp === 0) {
594
+ return [];
595
+ }
596
+ rx = Math.abs(rx);
597
+ ry = Math.abs(ry);
598
+ var lambda = Math.pow(pxp, 2) / Math.pow(rx, 2) + Math.pow(pyp, 2) / Math.pow(ry, 2);
599
+ if (lambda > 1) {
600
+ rx *= Math.sqrt(lambda);
601
+ ry *= Math.sqrt(lambda);
602
+ }
603
+ 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];
604
+ var ratio = Math.abs(ang2) / (TAU / 4);
605
+ if (Math.abs(1 - ratio) < 1e-7) {
606
+ ratio = 1;
607
+ }
608
+ var segments = Math.max(Math.ceil(ratio), 1);
609
+ ang2 /= segments;
610
+ for (var i = 0; i < segments; i++) {
611
+ curves.push(approxUnitArc(ang1, ang2));
612
+ ang1 += ang2;
613
+ }
614
+ return curves.map(function(curve) {
615
+ var _mapToEllipse = mapToEllipse(curve[0], rx, ry, cosphi, sinphi, centerx, centery), x1 = _mapToEllipse.x, y1 = _mapToEllipse.y;
616
+ var _mapToEllipse2 = mapToEllipse(curve[1], rx, ry, cosphi, sinphi, centerx, centery), x2 = _mapToEllipse2.x, y2 = _mapToEllipse2.y;
617
+ var _mapToEllipse3 = mapToEllipse(curve[2], rx, ry, cosphi, sinphi, centerx, centery), x = _mapToEllipse3.x, y = _mapToEllipse3.y;
618
+ return { x1, y1, x2, y2, x, y };
619
+ });
620
+ };
621
+ modules_default = arcToBezier;
622
+ }
623
+ });
624
+
625
+ // node_modules/normalize-svg-path/index.js
626
+ var require_normalize_svg_path = __commonJS({
627
+ "node_modules/normalize-svg-path/index.js"(exports, module2) {
628
+ "use strict";
629
+ module2.exports = normalize;
630
+ var arcToCurve = (init_modules(), __toCommonJS(modules_exports));
631
+ function normalize(path) {
632
+ var prev;
633
+ var result = [];
634
+ var bezierX = 0;
635
+ var bezierY = 0;
636
+ var startX = 0;
637
+ var startY = 0;
638
+ var quadX = null;
639
+ var quadY = null;
640
+ var x = 0;
641
+ var y = 0;
642
+ for (var i = 0, len = path.length; i < len; i++) {
643
+ var seg = path[i];
644
+ var command = seg[0];
645
+ switch (command) {
646
+ case "M":
647
+ startX = seg[1];
648
+ startY = seg[2];
649
+ break;
650
+ case "A":
651
+ var curves = arcToCurve({
652
+ px: x,
653
+ py: y,
654
+ cx: seg[6],
655
+ cy: seg[7],
656
+ rx: seg[1],
657
+ ry: seg[2],
658
+ xAxisRotation: seg[3],
659
+ largeArcFlag: seg[4],
660
+ sweepFlag: seg[5]
661
+ });
662
+ if (!curves.length)
663
+ continue;
664
+ for (var j = 0, c; j < curves.length; j++) {
665
+ c = curves[j];
666
+ seg = ["C", c.x1, c.y1, c.x2, c.y2, c.x, c.y];
667
+ if (j < curves.length - 1)
668
+ result.push(seg);
669
+ }
670
+ break;
671
+ case "S":
672
+ var cx = x;
673
+ var cy = y;
674
+ if (prev == "C" || prev == "S") {
675
+ cx += cx - bezierX;
676
+ cy += cy - bezierY;
677
+ }
678
+ seg = ["C", cx, cy, seg[1], seg[2], seg[3], seg[4]];
679
+ break;
680
+ case "T":
681
+ if (prev == "Q" || prev == "T") {
682
+ quadX = x * 2 - quadX;
683
+ quadY = y * 2 - quadY;
684
+ } else {
685
+ quadX = x;
686
+ quadY = y;
687
+ }
688
+ seg = quadratic(x, y, quadX, quadY, seg[1], seg[2]);
689
+ break;
690
+ case "Q":
691
+ quadX = seg[1];
692
+ quadY = seg[2];
693
+ seg = quadratic(x, y, seg[1], seg[2], seg[3], seg[4]);
694
+ break;
695
+ case "L":
696
+ seg = line(x, y, seg[1], seg[2]);
697
+ break;
698
+ case "H":
699
+ seg = line(x, y, seg[1], y);
700
+ break;
701
+ case "V":
702
+ seg = line(x, y, x, seg[1]);
703
+ break;
704
+ case "Z":
705
+ seg = line(x, y, startX, startY);
706
+ break;
707
+ }
708
+ prev = command;
709
+ x = seg[seg.length - 2];
710
+ y = seg[seg.length - 1];
711
+ if (seg.length > 4) {
712
+ bezierX = seg[seg.length - 4];
713
+ bezierY = seg[seg.length - 3];
714
+ } else {
715
+ bezierX = x;
716
+ bezierY = y;
717
+ }
718
+ result.push(seg);
719
+ }
720
+ return result;
721
+ }
722
+ function line(x1, y1, x2, y2) {
723
+ return ["C", x1, y1, x2, y2, x2, y2];
724
+ }
725
+ function quadratic(x1, y1, cx, cy, x2, y2) {
726
+ return [
727
+ "C",
728
+ x1 / 3 + 2 / 3 * cx,
729
+ y1 / 3 + 2 / 3 * cy,
730
+ x2 / 3 + 2 / 3 * cx,
731
+ y2 / 3 + 2 / 3 * cy,
732
+ x2,
733
+ y2
734
+ ];
735
+ }
736
+ }
737
+ });
738
+
739
+ // node_modules/is-svg-path/index.js
740
+ var require_is_svg_path = __commonJS({
741
+ "node_modules/is-svg-path/index.js"(exports, module2) {
742
+ "use strict";
743
+ module2.exports = function isPath(str) {
744
+ if (typeof str !== "string")
745
+ return false;
746
+ str = str.trim();
747
+ if (/^[mzlhvcsqta]\s*[-+.0-9][^mlhvzcsqta]+/i.test(str) && /[\dz]$/i.test(str) && str.length > 4)
748
+ return true;
749
+ return false;
750
+ };
751
+ }
752
+ });
753
+
754
+ // node_modules/svg-path-bounds/index.js
755
+ var require_svg_path_bounds = __commonJS({
756
+ "node_modules/svg-path-bounds/index.js"(exports, module2) {
757
+ "use strict";
758
+ var parse = require_parse_svg_path();
759
+ var abs = require_abs_svg_path();
760
+ var normalize = require_normalize_svg_path();
761
+ var isSvgPath = require_is_svg_path();
762
+ module2.exports = pathBounds;
763
+ function pathBounds(path) {
764
+ if (Array.isArray(path) && path.length === 1 && typeof path[0] === "string")
765
+ path = path[0];
766
+ if (typeof path === "string") {
767
+ if (!isSvgPath(path))
768
+ throw Error("String is not an SVG path.");
769
+ path = parse(path);
770
+ }
771
+ if (!Array.isArray(path))
772
+ throw Error("Argument should be a string or an array of path segments.");
773
+ path = abs(path);
774
+ path = normalize(path);
775
+ if (!path.length)
776
+ return [0, 0, 0, 0];
777
+ var bounds = [Infinity, Infinity, -Infinity, -Infinity];
778
+ for (var i = 0, l = path.length; i < l; i++) {
779
+ var points = path[i].slice(1);
780
+ for (var j = 0; j < points.length; j += 2) {
781
+ if (points[j + 0] < bounds[0])
782
+ bounds[0] = points[j + 0];
783
+ if (points[j + 1] < bounds[1])
784
+ bounds[1] = points[j + 1];
785
+ if (points[j + 0] > bounds[2])
786
+ bounds[2] = points[j + 0];
787
+ if (points[j + 1] > bounds[3])
788
+ bounds[3] = points[j + 1];
789
+ }
790
+ }
791
+ return bounds;
792
+ }
793
+ }
794
+ });
795
+
796
+ // node_modules/debounce/index.js
797
+ var require_debounce = __commonJS({
798
+ "node_modules/debounce/index.js"(exports, module2) {
799
+ function debounce(func, wait, immediate) {
800
+ var timeout, args, context, timestamp, result;
801
+ if (null == wait)
802
+ wait = 100;
803
+ function later() {
804
+ var last = Date.now() - timestamp;
805
+ if (last < wait && last >= 0) {
806
+ timeout = setTimeout(later, wait - last);
807
+ } else {
808
+ timeout = null;
809
+ if (!immediate) {
810
+ result = func.apply(context, args);
811
+ context = args = null;
812
+ }
813
+ }
814
+ }
815
+ ;
816
+ var debounced = function() {
817
+ context = this;
818
+ args = arguments;
819
+ timestamp = Date.now();
820
+ var callNow = immediate && !timeout;
821
+ if (!timeout)
822
+ timeout = setTimeout(later, wait);
823
+ if (callNow) {
824
+ result = func.apply(context, args);
825
+ context = args = null;
826
+ }
827
+ return result;
828
+ };
829
+ debounced.clear = function() {
830
+ if (timeout) {
831
+ clearTimeout(timeout);
832
+ timeout = null;
833
+ }
834
+ };
835
+ debounced.flush = function() {
836
+ if (timeout) {
837
+ result = func.apply(context, args);
838
+ context = args = null;
839
+ clearTimeout(timeout);
840
+ timeout = null;
841
+ }
842
+ };
843
+ return debounced;
844
+ }
845
+ debounce.debounce = debounce;
846
+ module2.exports = debounce;
847
+ }
848
+ });
849
+
850
+ // node_modules/svg-path-generator/lib/svg-path-generator.js
851
+ var require_svg_path_generator = __commonJS({
852
+ "node_modules/svg-path-generator/lib/svg-path-generator.js"(exports, module2) {
853
+ function SvgPathGenerator(path) {
854
+ if (!(this instanceof SvgPathGenerator)) {
855
+ return new SvgPathGenerator(path);
856
+ }
857
+ this.currentPath = (path || "") + " ";
858
+ this.isRelative = false;
859
+ }
860
+ module2.exports = SvgPathGenerator;
861
+ SvgPathGenerator.prototype.toString = function() {
862
+ return this.end();
863
+ };
864
+ SvgPathGenerator.prototype.moveTo = function() {
865
+ this._appendData("M", arguments);
866
+ return this;
867
+ };
868
+ SvgPathGenerator.prototype.close = SvgPathGenerator.prototype.closePath = function() {
869
+ this._appendData("Z", []);
870
+ return this;
871
+ };
872
+ SvgPathGenerator.prototype.lineTo = function() {
873
+ this._appendData("L", arguments);
874
+ return this;
875
+ };
876
+ SvgPathGenerator.prototype.horizontalLineTo = function(x) {
877
+ this._appendData("H", [x]);
878
+ return this;
879
+ };
880
+ SvgPathGenerator.prototype.verticalLineTo = function(y) {
881
+ this._appendData("V", [y]);
882
+ return this;
883
+ };
884
+ SvgPathGenerator.prototype.curveTo = function() {
885
+ this._appendData("C", arguments);
886
+ return this;
887
+ };
888
+ SvgPathGenerator.prototype.smoothCurveTo = function() {
889
+ this._appendData("S", arguments);
890
+ return this;
891
+ };
892
+ SvgPathGenerator.prototype.bezierCurveTo = function() {
893
+ this._appendData("Q", arguments);
894
+ return this;
895
+ };
896
+ SvgPathGenerator.prototype.smoothBezierCurveTo = function() {
897
+ this._appendData("T", arguments);
898
+ return this;
899
+ };
900
+ SvgPathGenerator.prototype.ellipticalArc = function() {
901
+ this._appendData("A", arguments);
902
+ return this;
903
+ };
904
+ SvgPathGenerator.prototype.relative = function() {
905
+ this.isRelative = true;
906
+ return this;
907
+ };
908
+ SvgPathGenerator.prototype.end = function() {
909
+ return this.currentPath.trim();
910
+ };
911
+ SvgPathGenerator.prototype._appendData = function(symbol, args) {
912
+ args = Array.prototype.slice.call(args);
913
+ if (this.isRelative) {
914
+ symbol = symbol.toLowerCase();
915
+ this.isRelative = false;
916
+ }
917
+ this.currentPath += symbol + " " + args.join(" ") + " ";
918
+ };
919
+ }
920
+ });
921
+
922
+ // node_modules/svg-path-generator/index.js
923
+ var require_svg_path_generator2 = __commonJS({
924
+ "node_modules/svg-path-generator/index.js"(exports, module2) {
925
+ module2.exports = require_svg_path_generator();
926
+ }
927
+ });
928
+
929
+ // node_modules/lodash/_baseRange.js
930
+ var require_baseRange = __commonJS({
931
+ "node_modules/lodash/_baseRange.js"(exports, module2) {
932
+ var nativeCeil = Math.ceil;
933
+ var nativeMax = Math.max;
934
+ function baseRange(start, end, step, fromRight) {
935
+ var index = -1, length = nativeMax(nativeCeil((end - start) / (step || 1)), 0), result = Array(length);
936
+ while (length--) {
937
+ result[fromRight ? length : ++index] = start;
938
+ start += step;
939
+ }
940
+ return result;
941
+ }
942
+ module2.exports = baseRange;
943
+ }
944
+ });
945
+
946
+ // node_modules/lodash/eq.js
947
+ var require_eq = __commonJS({
948
+ "node_modules/lodash/eq.js"(exports, module2) {
949
+ function eq(value, other) {
950
+ return value === other || value !== value && other !== other;
951
+ }
952
+ module2.exports = eq;
953
+ }
954
+ });
955
+
956
+ // node_modules/lodash/_freeGlobal.js
957
+ var require_freeGlobal = __commonJS({
958
+ "node_modules/lodash/_freeGlobal.js"(exports, module2) {
959
+ var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
960
+ module2.exports = freeGlobal;
961
+ }
962
+ });
963
+
964
+ // node_modules/lodash/_root.js
965
+ var require_root = __commonJS({
966
+ "node_modules/lodash/_root.js"(exports, module2) {
967
+ var freeGlobal = require_freeGlobal();
968
+ var freeSelf = typeof self == "object" && self && self.Object === Object && self;
969
+ var root = freeGlobal || freeSelf || Function("return this")();
970
+ module2.exports = root;
971
+ }
972
+ });
973
+
974
+ // node_modules/lodash/_Symbol.js
975
+ var require_Symbol = __commonJS({
976
+ "node_modules/lodash/_Symbol.js"(exports, module2) {
977
+ var root = require_root();
978
+ var Symbol2 = root.Symbol;
979
+ module2.exports = Symbol2;
980
+ }
981
+ });
982
+
983
+ // node_modules/lodash/_getRawTag.js
984
+ var require_getRawTag = __commonJS({
985
+ "node_modules/lodash/_getRawTag.js"(exports, module2) {
986
+ var Symbol2 = require_Symbol();
987
+ var objectProto = Object.prototype;
988
+ var hasOwnProperty = objectProto.hasOwnProperty;
989
+ var nativeObjectToString = objectProto.toString;
990
+ var symToStringTag = Symbol2 ? Symbol2.toStringTag : void 0;
991
+ function getRawTag(value) {
992
+ var isOwn = hasOwnProperty.call(value, symToStringTag), tag = value[symToStringTag];
993
+ try {
994
+ value[symToStringTag] = void 0;
995
+ var unmasked = true;
996
+ } catch (e) {
997
+ }
998
+ var result = nativeObjectToString.call(value);
999
+ if (unmasked) {
1000
+ if (isOwn) {
1001
+ value[symToStringTag] = tag;
1002
+ } else {
1003
+ delete value[symToStringTag];
1004
+ }
1005
+ }
1006
+ return result;
1007
+ }
1008
+ module2.exports = getRawTag;
1009
+ }
1010
+ });
1011
+
1012
+ // node_modules/lodash/_objectToString.js
1013
+ var require_objectToString = __commonJS({
1014
+ "node_modules/lodash/_objectToString.js"(exports, module2) {
1015
+ var objectProto = Object.prototype;
1016
+ var nativeObjectToString = objectProto.toString;
1017
+ function objectToString(value) {
1018
+ return nativeObjectToString.call(value);
1019
+ }
1020
+ module2.exports = objectToString;
1021
+ }
1022
+ });
1023
+
1024
+ // node_modules/lodash/_baseGetTag.js
1025
+ var require_baseGetTag = __commonJS({
1026
+ "node_modules/lodash/_baseGetTag.js"(exports, module2) {
1027
+ var Symbol2 = require_Symbol();
1028
+ var getRawTag = require_getRawTag();
1029
+ var objectToString = require_objectToString();
1030
+ var nullTag = "[object Null]";
1031
+ var undefinedTag = "[object Undefined]";
1032
+ var symToStringTag = Symbol2 ? Symbol2.toStringTag : void 0;
1033
+ function baseGetTag(value) {
1034
+ if (value == null) {
1035
+ return value === void 0 ? undefinedTag : nullTag;
1036
+ }
1037
+ return symToStringTag && symToStringTag in Object(value) ? getRawTag(value) : objectToString(value);
1038
+ }
1039
+ module2.exports = baseGetTag;
1040
+ }
1041
+ });
1042
+
1043
+ // node_modules/lodash/isObject.js
1044
+ var require_isObject = __commonJS({
1045
+ "node_modules/lodash/isObject.js"(exports, module2) {
1046
+ function isObject2(value) {
1047
+ var type = typeof value;
1048
+ return value != null && (type == "object" || type == "function");
1049
+ }
1050
+ module2.exports = isObject2;
1051
+ }
1052
+ });
1053
+
1054
+ // node_modules/lodash/isFunction.js
1055
+ var require_isFunction = __commonJS({
1056
+ "node_modules/lodash/isFunction.js"(exports, module2) {
1057
+ var baseGetTag = require_baseGetTag();
1058
+ var isObject2 = require_isObject();
1059
+ var asyncTag = "[object AsyncFunction]";
1060
+ var funcTag = "[object Function]";
1061
+ var genTag = "[object GeneratorFunction]";
1062
+ var proxyTag = "[object Proxy]";
1063
+ function isFunction(value) {
1064
+ if (!isObject2(value)) {
1065
+ return false;
1066
+ }
1067
+ var tag = baseGetTag(value);
1068
+ return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
1069
+ }
1070
+ module2.exports = isFunction;
1071
+ }
1072
+ });
1073
+
1074
+ // node_modules/lodash/isLength.js
1075
+ var require_isLength = __commonJS({
1076
+ "node_modules/lodash/isLength.js"(exports, module2) {
1077
+ var MAX_SAFE_INTEGER = 9007199254740991;
1078
+ function isLength(value) {
1079
+ return typeof value == "number" && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
1080
+ }
1081
+ module2.exports = isLength;
1082
+ }
1083
+ });
1084
+
1085
+ // node_modules/lodash/isArrayLike.js
1086
+ var require_isArrayLike = __commonJS({
1087
+ "node_modules/lodash/isArrayLike.js"(exports, module2) {
1088
+ var isFunction = require_isFunction();
1089
+ var isLength = require_isLength();
1090
+ function isArrayLike(value) {
1091
+ return value != null && isLength(value.length) && !isFunction(value);
1092
+ }
1093
+ module2.exports = isArrayLike;
1094
+ }
1095
+ });
1096
+
1097
+ // node_modules/lodash/_isIndex.js
1098
+ var require_isIndex = __commonJS({
1099
+ "node_modules/lodash/_isIndex.js"(exports, module2) {
1100
+ var MAX_SAFE_INTEGER = 9007199254740991;
1101
+ var reIsUint = /^(?:0|[1-9]\d*)$/;
1102
+ function isIndex(value, length) {
1103
+ var type = typeof value;
1104
+ length = length == null ? MAX_SAFE_INTEGER : length;
1105
+ return !!length && (type == "number" || type != "symbol" && reIsUint.test(value)) && (value > -1 && value % 1 == 0 && value < length);
1106
+ }
1107
+ module2.exports = isIndex;
1108
+ }
1109
+ });
1110
+
1111
+ // node_modules/lodash/_isIterateeCall.js
1112
+ var require_isIterateeCall = __commonJS({
1113
+ "node_modules/lodash/_isIterateeCall.js"(exports, module2) {
1114
+ var eq = require_eq();
1115
+ var isArrayLike = require_isArrayLike();
1116
+ var isIndex = require_isIndex();
1117
+ var isObject2 = require_isObject();
1118
+ function isIterateeCall(value, index, object) {
1119
+ if (!isObject2(object)) {
1120
+ return false;
1121
+ }
1122
+ var type = typeof index;
1123
+ if (type == "number" ? isArrayLike(object) && isIndex(index, object.length) : type == "string" && index in object) {
1124
+ return eq(object[index], value);
1125
+ }
1126
+ return false;
1127
+ }
1128
+ module2.exports = isIterateeCall;
1129
+ }
1130
+ });
1131
+
1132
+ // node_modules/lodash/_trimmedEndIndex.js
1133
+ var require_trimmedEndIndex = __commonJS({
1134
+ "node_modules/lodash/_trimmedEndIndex.js"(exports, module2) {
1135
+ var reWhitespace = /\s/;
1136
+ function trimmedEndIndex(string) {
1137
+ var index = string.length;
1138
+ while (index-- && reWhitespace.test(string.charAt(index))) {
1139
+ }
1140
+ return index;
1141
+ }
1142
+ module2.exports = trimmedEndIndex;
1143
+ }
1144
+ });
1145
+
1146
+ // node_modules/lodash/_baseTrim.js
1147
+ var require_baseTrim = __commonJS({
1148
+ "node_modules/lodash/_baseTrim.js"(exports, module2) {
1149
+ var trimmedEndIndex = require_trimmedEndIndex();
1150
+ var reTrimStart = /^\s+/;
1151
+ function baseTrim(string) {
1152
+ return string ? string.slice(0, trimmedEndIndex(string) + 1).replace(reTrimStart, "") : string;
1153
+ }
1154
+ module2.exports = baseTrim;
1155
+ }
1156
+ });
1157
+
1158
+ // node_modules/lodash/isObjectLike.js
1159
+ var require_isObjectLike = __commonJS({
1160
+ "node_modules/lodash/isObjectLike.js"(exports, module2) {
1161
+ function isObjectLike(value) {
1162
+ return value != null && typeof value == "object";
1163
+ }
1164
+ module2.exports = isObjectLike;
1165
+ }
1166
+ });
1167
+
1168
+ // node_modules/lodash/isSymbol.js
1169
+ var require_isSymbol = __commonJS({
1170
+ "node_modules/lodash/isSymbol.js"(exports, module2) {
1171
+ var baseGetTag = require_baseGetTag();
1172
+ var isObjectLike = require_isObjectLike();
1173
+ var symbolTag = "[object Symbol]";
1174
+ function isSymbol(value) {
1175
+ return typeof value == "symbol" || isObjectLike(value) && baseGetTag(value) == symbolTag;
1176
+ }
1177
+ module2.exports = isSymbol;
1178
+ }
1179
+ });
1180
+
1181
+ // node_modules/lodash/toNumber.js
1182
+ var require_toNumber = __commonJS({
1183
+ "node_modules/lodash/toNumber.js"(exports, module2) {
1184
+ var baseTrim = require_baseTrim();
1185
+ var isObject2 = require_isObject();
1186
+ var isSymbol = require_isSymbol();
1187
+ var NAN = 0 / 0;
1188
+ var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
1189
+ var reIsBinary = /^0b[01]+$/i;
1190
+ var reIsOctal = /^0o[0-7]+$/i;
1191
+ var freeParseInt = parseInt;
1192
+ function toNumber(value) {
1193
+ if (typeof value == "number") {
1194
+ return value;
1195
+ }
1196
+ if (isSymbol(value)) {
1197
+ return NAN;
1198
+ }
1199
+ if (isObject2(value)) {
1200
+ var other = typeof value.valueOf == "function" ? value.valueOf() : value;
1201
+ value = isObject2(other) ? other + "" : other;
1202
+ }
1203
+ if (typeof value != "string") {
1204
+ return value === 0 ? value : +value;
1205
+ }
1206
+ value = baseTrim(value);
1207
+ var isBinary = reIsBinary.test(value);
1208
+ return isBinary || reIsOctal.test(value) ? freeParseInt(value.slice(2), isBinary ? 2 : 8) : reIsBadHex.test(value) ? NAN : +value;
1209
+ }
1210
+ module2.exports = toNumber;
1211
+ }
1212
+ });
1213
+
1214
+ // node_modules/lodash/toFinite.js
1215
+ var require_toFinite = __commonJS({
1216
+ "node_modules/lodash/toFinite.js"(exports, module2) {
1217
+ var toNumber = require_toNumber();
1218
+ var INFINITY = 1 / 0;
1219
+ var MAX_INTEGER = 17976931348623157e292;
1220
+ function toFinite(value) {
1221
+ if (!value) {
1222
+ return value === 0 ? value : 0;
1223
+ }
1224
+ value = toNumber(value);
1225
+ if (value === INFINITY || value === -INFINITY) {
1226
+ var sign = value < 0 ? -1 : 1;
1227
+ return sign * MAX_INTEGER;
1228
+ }
1229
+ return value === value ? value : 0;
1230
+ }
1231
+ module2.exports = toFinite;
1232
+ }
1233
+ });
1234
+
1235
+ // node_modules/lodash/_createRange.js
1236
+ var require_createRange = __commonJS({
1237
+ "node_modules/lodash/_createRange.js"(exports, module2) {
1238
+ var baseRange = require_baseRange();
1239
+ var isIterateeCall = require_isIterateeCall();
1240
+ var toFinite = require_toFinite();
1241
+ function createRange(fromRight) {
1242
+ return function(start, end, step) {
1243
+ if (step && typeof step != "number" && isIterateeCall(start, end, step)) {
1244
+ end = step = void 0;
1245
+ }
1246
+ start = toFinite(start);
1247
+ if (end === void 0) {
1248
+ end = start;
1249
+ start = 0;
1250
+ } else {
1251
+ end = toFinite(end);
1252
+ }
1253
+ step = step === void 0 ? start < end ? 1 : -1 : toFinite(step);
1254
+ return baseRange(start, end, step, fromRight);
1255
+ };
1256
+ }
1257
+ module2.exports = createRange;
1258
+ }
1259
+ });
1260
+
1261
+ // node_modules/lodash/range.js
1262
+ var require_range = __commonJS({
1263
+ "node_modules/lodash/range.js"(exports, module2) {
1264
+ var createRange = require_createRange();
1265
+ var range2 = createRange();
1266
+ module2.exports = range2;
1267
+ }
1268
+ });
1269
+
1270
+ // src/index.ts
1271
+ var src_exports = {};
1272
+ __export(src_exports, {
1273
+ Schematic: () => Schematic
1274
+ });
1275
+ module.exports = __toCommonJS(src_exports);
1276
+
1277
+ // src/Schematic.tsx
1278
+ var import_react4 = require("react");
1279
+ var import_builder2 = require("@tscircuit/builder");
1280
+ var import_react_fiber = require("@tscircuit/react-fiber");
1281
+
1282
+ // src/lib/utils/collect-element-refs.ts
1283
+ var collectElementRefs = (elm, allElms) => {
1284
+ const source_component = allElms.find(
1285
+ (e) => e.type === "source_component" && e.source_component_id === elm.source_component_id
1286
+ );
1287
+ if (["schematic_component", "schematic_trace", "schematic_port"].includes(
1288
+ elm.type
1289
+ )) {
1290
+ return {
1291
+ schematic: elm,
1292
+ source: source_component
1293
+ };
1294
+ }
1295
+ return null;
1296
+ };
1297
+
1298
+ // node_modules/zustand/esm/vanilla.mjs
1299
+ var createStoreImpl = (createState) => {
1300
+ let state;
1301
+ const listeners = /* @__PURE__ */ new Set();
1302
+ const setState = (partial, replace) => {
1303
+ const nextState = typeof partial === "function" ? partial(state) : partial;
1304
+ if (nextState !== state) {
1305
+ const previousState = state;
1306
+ state = replace ? nextState : Object.assign({}, state, nextState);
1307
+ listeners.forEach((listener) => listener(state, previousState));
1308
+ }
1309
+ };
1310
+ const getState = () => state;
1311
+ const subscribe = (listener) => {
1312
+ listeners.add(listener);
1313
+ return () => listeners.delete(listener);
1314
+ };
1315
+ const destroy = () => listeners.clear();
1316
+ const api = { setState, getState, subscribe, destroy };
1317
+ state = createState(
1318
+ setState,
1319
+ getState,
1320
+ api
1321
+ );
1322
+ return api;
1323
+ };
1324
+ var createStore = (createState) => createState ? createStoreImpl(createState) : createStoreImpl;
1325
+
1326
+ // node_modules/zustand/esm/index.mjs
1327
+ var import_react = require("react");
1328
+ var import_with_selector = __toESM(require_with_selector(), 1);
1329
+ var { useSyncExternalStoreWithSelector } = import_with_selector.default;
1330
+ function useStore(api, selector = api.getState, equalityFn) {
1331
+ const slice = useSyncExternalStoreWithSelector(
1332
+ api.subscribe,
1333
+ api.getState,
1334
+ api.getServerState || api.getState,
1335
+ selector,
1336
+ equalityFn
1337
+ );
1338
+ (0, import_react.useDebugValue)(slice);
1339
+ return slice;
1340
+ }
1341
+ var createImpl = (createState) => {
1342
+ const api = typeof createState === "function" ? createStore(createState) : createState;
1343
+ const useBoundStore = (selector, equalityFn) => useStore(api, selector, equalityFn);
1344
+ Object.assign(useBoundStore, api);
1345
+ return useBoundStore;
1346
+ };
1347
+ var create = (createState) => createState ? createImpl(createState) : createImpl;
1348
+ var create$1 = create;
1349
+
1350
+ // node_modules/transformation-matrix/src/applyToPoint.js
1351
+ function applyToPoint(matrix, point) {
1352
+ return Array.isArray(point) ? [
1353
+ matrix.a * point[0] + matrix.c * point[1] + matrix.e,
1354
+ matrix.b * point[0] + matrix.d * point[1] + matrix.f
1355
+ ] : {
1356
+ x: matrix.a * point.x + matrix.c * point.y + matrix.e,
1357
+ y: matrix.b * point.x + matrix.d * point.y + matrix.f
1358
+ };
1359
+ }
1360
+
1361
+ // node_modules/transformation-matrix/src/utils.js
1362
+ function isUndefined(val) {
1363
+ return typeof val === "undefined";
1364
+ }
1365
+
1366
+ // node_modules/transformation-matrix/src/translate.js
1367
+ function translate(tx, ty = 0) {
1368
+ return {
1369
+ a: 1,
1370
+ c: 0,
1371
+ e: tx,
1372
+ b: 0,
1373
+ d: 1,
1374
+ f: ty
1375
+ };
1376
+ }
1377
+
1378
+ // node_modules/transformation-matrix/src/transform.js
1379
+ function transform(...matrices) {
1380
+ matrices = Array.isArray(matrices[0]) ? matrices[0] : matrices;
1381
+ const multiply = (m1, m2) => {
1382
+ return {
1383
+ a: m1.a * m2.a + m1.c * m2.b,
1384
+ c: m1.a * m2.c + m1.c * m2.d,
1385
+ e: m1.a * m2.e + m1.c * m2.f + m1.e,
1386
+ b: m1.b * m2.a + m1.d * m2.b,
1387
+ d: m1.b * m2.c + m1.d * m2.d,
1388
+ f: m1.b * m2.e + m1.d * m2.f + m1.f
1389
+ };
1390
+ };
1391
+ switch (matrices.length) {
1392
+ case 0:
1393
+ throw new Error("no matrices provided");
1394
+ case 1:
1395
+ return matrices[0];
1396
+ case 2:
1397
+ return multiply(matrices[0], matrices[1]);
1398
+ default: {
1399
+ const [m1, m2, ...rest] = matrices;
1400
+ const m = multiply(m1, m2);
1401
+ return transform(m, ...rest);
1402
+ }
1403
+ }
1404
+ }
1405
+ function compose(...matrices) {
1406
+ return transform(...matrices);
1407
+ }
1408
+
1409
+ // node_modules/transformation-matrix/src/rotate.js
1410
+ var { cos, sin, PI } = Math;
1411
+
1412
+ // node_modules/transformation-matrix/src/scale.js
1413
+ function scale(sx, sy = void 0, cx = void 0, cy = void 0) {
1414
+ if (isUndefined(sy))
1415
+ sy = sx;
1416
+ const scaleMatrix = {
1417
+ a: sx,
1418
+ c: 0,
1419
+ e: 0,
1420
+ b: 0,
1421
+ d: sy,
1422
+ f: 0
1423
+ };
1424
+ if (isUndefined(cx) || isUndefined(cy)) {
1425
+ return scaleMatrix;
1426
+ }
1427
+ return transform([
1428
+ translate(cx, cy),
1429
+ scaleMatrix,
1430
+ translate(-cx, -cy)
1431
+ ]);
1432
+ }
1433
+
1434
+ // node_modules/transformation-matrix/src/skew.js
1435
+ var { tan } = Math;
1436
+
1437
+ // node_modules/transformation-matrix/src/fromTransformAttribute.autogenerated.js
1438
+ function peg$subclass(child, parent) {
1439
+ function C() {
1440
+ this.constructor = child;
1441
+ }
1442
+ C.prototype = parent.prototype;
1443
+ child.prototype = new C();
1444
+ }
1445
+ function peg$SyntaxError(message, expected, found, location) {
1446
+ var self2 = Error.call(this, message);
1447
+ if (Object.setPrototypeOf) {
1448
+ Object.setPrototypeOf(self2, peg$SyntaxError.prototype);
1449
+ }
1450
+ self2.expected = expected;
1451
+ self2.found = found;
1452
+ self2.location = location;
1453
+ self2.name = "SyntaxError";
1454
+ return self2;
1455
+ }
1456
+ peg$subclass(peg$SyntaxError, Error);
1457
+ function peg$padEnd(str, targetLength, padString) {
1458
+ padString = padString || " ";
1459
+ if (str.length > targetLength) {
1460
+ return str;
1461
+ }
1462
+ targetLength -= str.length;
1463
+ padString += padString.repeat(targetLength);
1464
+ return str + padString.slice(0, targetLength);
1465
+ }
1466
+ peg$SyntaxError.prototype.format = function(sources) {
1467
+ var str = "Error: " + this.message;
1468
+ if (this.location) {
1469
+ var src = null;
1470
+ var k;
1471
+ for (k = 0; k < sources.length; k++) {
1472
+ if (sources[k].source === this.location.source) {
1473
+ src = sources[k].text.split(/\r\n|\n|\r/g);
1474
+ break;
1475
+ }
1476
+ }
1477
+ var s = this.location.start;
1478
+ var loc = this.location.source + ":" + s.line + ":" + s.column;
1479
+ if (src) {
1480
+ var e = this.location.end;
1481
+ var filler = peg$padEnd("", s.line.toString().length, " ");
1482
+ var line = src[s.line - 1];
1483
+ var last = s.line === e.line ? e.column : line.length + 1;
1484
+ var hatLen = last - s.column || 1;
1485
+ str += "\n --> " + loc + "\n" + filler + " |\n" + s.line + " | " + line + "\n" + filler + " | " + peg$padEnd("", s.column - 1, " ") + peg$padEnd("", hatLen, "^");
1486
+ } else {
1487
+ str += "\n at " + loc;
1488
+ }
1489
+ }
1490
+ return str;
1491
+ };
1492
+ peg$SyntaxError.buildMessage = function(expected, found) {
1493
+ var DESCRIBE_EXPECTATION_FNS = {
1494
+ literal: function(expectation) {
1495
+ return '"' + literalEscape(expectation.text) + '"';
1496
+ },
1497
+ class: function(expectation) {
1498
+ var escapedParts = expectation.parts.map(function(part) {
1499
+ return Array.isArray(part) ? classEscape(part[0]) + "-" + classEscape(part[1]) : classEscape(part);
1500
+ });
1501
+ return "[" + (expectation.inverted ? "^" : "") + escapedParts.join("") + "]";
1502
+ },
1503
+ any: function() {
1504
+ return "any character";
1505
+ },
1506
+ end: function() {
1507
+ return "end of input";
1508
+ },
1509
+ other: function(expectation) {
1510
+ return expectation.description;
1511
+ }
1512
+ };
1513
+ function hex(ch) {
1514
+ return ch.charCodeAt(0).toString(16).toUpperCase();
1515
+ }
1516
+ function literalEscape(s) {
1517
+ 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) {
1518
+ return "\\x0" + hex(ch);
1519
+ }).replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) {
1520
+ return "\\x" + hex(ch);
1521
+ });
1522
+ }
1523
+ function classEscape(s) {
1524
+ 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) {
1525
+ return "\\x0" + hex(ch);
1526
+ }).replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) {
1527
+ return "\\x" + hex(ch);
1528
+ });
1529
+ }
1530
+ function describeExpectation(expectation) {
1531
+ return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation);
1532
+ }
1533
+ function describeExpected(expected2) {
1534
+ var descriptions = expected2.map(describeExpectation);
1535
+ var i, j;
1536
+ descriptions.sort();
1537
+ if (descriptions.length > 0) {
1538
+ for (i = 1, j = 1; i < descriptions.length; i++) {
1539
+ if (descriptions[i - 1] !== descriptions[i]) {
1540
+ descriptions[j] = descriptions[i];
1541
+ j++;
1542
+ }
1543
+ }
1544
+ descriptions.length = j;
1545
+ }
1546
+ switch (descriptions.length) {
1547
+ case 1:
1548
+ return descriptions[0];
1549
+ case 2:
1550
+ return descriptions[0] + " or " + descriptions[1];
1551
+ default:
1552
+ return descriptions.slice(0, -1).join(", ") + ", or " + descriptions[descriptions.length - 1];
1553
+ }
1554
+ }
1555
+ function describeFound(found2) {
1556
+ return found2 ? '"' + literalEscape(found2) + '"' : "end of input";
1557
+ }
1558
+ return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found.";
1559
+ };
1560
+
1561
+ // src/lib/render-context/index.ts
1562
+ var useRenderContext = create$1((set, get) => ({
1563
+ camera_transform: compose(scale(100, 100, 0, 0)),
1564
+ setCameraTransform: (transform2) => set({ camera_transform: transform2 })
1565
+ }));
1566
+ var useCameraTransform = () => useRenderContext((s) => s.camera_transform);
1567
+
1568
+ // src/lib/utils/get-svg-path-bounds.ts
1569
+ var import_svg_path_bounds = __toESM(require_svg_path_bounds());
1570
+ function getSVGPathBounds(ds) {
1571
+ if (typeof ds === "string")
1572
+ ds = [ds];
1573
+ let minX = Infinity, maxX = -Infinity, minY = Infinity, maxY = -Infinity;
1574
+ for (const d of ds) {
1575
+ const [left, top, right, bottom] = (0, import_svg_path_bounds.default)(d);
1576
+ minX = Math.min(left, minX);
1577
+ maxX = Math.max(right, maxX);
1578
+ minY = Math.min(top, minY);
1579
+ maxY = Math.max(bottom, maxY);
1580
+ }
1581
+ return { minX, maxX, minY, maxY, width: maxX - minX, height: maxY - minY };
1582
+ }
1583
+ var get_svg_path_bounds_default = getSVGPathBounds;
1584
+
1585
+ // src/schematic-components/SVGPathComponent.tsx
1586
+ var SVGPathComponent = ({ size, center, rotation, paths }) => {
1587
+ const ct = useCameraTransform();
1588
+ const pathBounds = get_svg_path_bounds_default(paths.map((p) => p.d));
1589
+ const badRatio = Math.abs(pathBounds.width / pathBounds.height - size.width / size.height) > 0.01;
1590
+ if (badRatio) {
1591
+ console.warn(
1592
+ `Ratio doesn't match for component. ${pathBounds.width}:${pathBounds.height} is not close to ${size.width}:${size.height}`
1593
+ );
1594
+ }
1595
+ pathBounds.height = Math.max(pathBounds.height, 1);
1596
+ pathBounds.width = Math.max(pathBounds.width, 1);
1597
+ const absoluteCenter = applyToPoint(ct, center);
1598
+ const absoluteSize = {
1599
+ width: Math.max(1, size.width * ct.a),
1600
+ height: Math.max(1, size.height * ct.d)
1601
+ };
1602
+ return <svg style={{
1603
+ position: "absolute",
1604
+ transform: rotation === 0 ? "" : `rotate(${rotation}rad)`,
1605
+ left: absoluteCenter.x - absoluteSize.width / 2,
1606
+ top: absoluteCenter.y - absoluteSize.height / 2
1607
+ }} overflow="visible" width={absoluteSize.width} height={absoluteSize.height} viewBox={`${pathBounds.minX} ${pathBounds.minY} ${pathBounds.width} ${pathBounds.height}`}>{paths.map((p, i) => <path key={i} fill="none" strokeWidth={2 * (p.strokeWidth || 1)} stroke={p.stroke || "red"} d={p.d} />)}</svg>;
1608
+ };
1609
+ var SVGPathComponent_default = SVGPathComponent;
1610
+
1611
+ // src/schematic-components/SimpleResistor.tsx
1612
+ var SimpleResistor = ({ component: { source, schematic } }) => {
1613
+ return <SVGPathComponent_default rotation={schematic.rotation} center={schematic.center} size={schematic.size} paths={[
1614
+ {
1615
+ stroke: "red",
1616
+ strokeWidth: 1,
1617
+ 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"
1618
+ }
1619
+ ]} />;
1620
+ };
1621
+
1622
+ // src/schematic-components/SimpleCapacitor.tsx
1623
+ var SimpleCapacitor = ({
1624
+ component: { source, schematic }
1625
+ }) => {
1626
+ return <SVGPathComponent_default rotation={schematic.rotation} center={schematic.center} size={schematic.size} paths={[
1627
+ { stroke: "red", strokeWidth: 1, d: "M 0 15 l 12 0" },
1628
+ { stroke: "red", strokeWidth: 2, d: "M 12 0 l 0 30" },
1629
+ { stroke: "red", strokeWidth: 2, d: "M 18 0 l 0 30" },
1630
+ { stroke: "red", strokeWidth: 1, d: "M 18 15 l 12 0" }
1631
+ ]} />;
1632
+ };
1633
+
1634
+ // src/lib/hooks/use-maybe-promise.ts
1635
+ var import_react2 = require("react");
1636
+
1637
+ // src/schematic-components/ProjectComponent.tsx
1638
+ var import_builder = require("@tscircuit/builder");
1639
+
1640
+ // src/lib/utils/direction-to-vec.ts
1641
+ var directionToVec = (direction) => {
1642
+ if (direction === "up")
1643
+ return { x: 0, y: -1 };
1644
+ else if (direction === "down")
1645
+ return { x: 0, y: 1 };
1646
+ else if (direction === "left")
1647
+ return { x: -1, y: 0 };
1648
+ else if (direction === "right")
1649
+ return { x: 1, y: 0 };
1650
+ else
1651
+ throw new Error("Invalid direction");
1652
+ };
1653
+
1654
+ // src/schematic-components/SchematicPort.tsx
1655
+ var SchematicPort = ({ port: { source, schematic } }) => {
1656
+ return <SVGPathComponent rotation={0} center={schematic.center} size={{ width: 0.2, height: 0.2 }} paths={[
1657
+ {
1658
+ stroke: "blue",
1659
+ strokeWidth: 1,
1660
+ d: "M 0 0 l 10 0 l 0 10 l -10 0 z"
1661
+ },
1662
+ schematic.facing_direction ? {
1663
+ stroke: "blue",
1664
+ strokeWidth: 0.5,
1665
+ d: `M 5 5 l ${directionToVec(schematic.facing_direction).x * 7} ${directionToVec(schematic.facing_direction).y * 7}`
1666
+ } : null
1667
+ ].filter(Boolean)} />;
1668
+ };
1669
+ var SchematicPort_default = SchematicPort;
1670
+
1671
+ // node_modules/react-use-measure/dist/web.js
1672
+ var import_react3 = require("react");
1673
+ var import_debounce = __toESM(require_debounce());
1674
+ function useMeasure(_temp) {
1675
+ let {
1676
+ debounce,
1677
+ scroll,
1678
+ polyfill,
1679
+ offsetSize
1680
+ } = _temp === void 0 ? {
1681
+ debounce: 0,
1682
+ scroll: false,
1683
+ offsetSize: false
1684
+ } : _temp;
1685
+ const ResizeObserver = polyfill || (typeof window === "undefined" ? class ResizeObserver {
1686
+ } : window.ResizeObserver);
1687
+ if (!ResizeObserver) {
1688
+ 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");
1689
+ }
1690
+ const [bounds, set] = (0, import_react3.useState)({
1691
+ left: 0,
1692
+ top: 0,
1693
+ width: 0,
1694
+ height: 0,
1695
+ bottom: 0,
1696
+ right: 0,
1697
+ x: 0,
1698
+ y: 0
1699
+ });
1700
+ const state = (0, import_react3.useRef)({
1701
+ element: null,
1702
+ scrollContainers: null,
1703
+ resizeObserver: null,
1704
+ lastBounds: bounds
1705
+ });
1706
+ const scrollDebounce = debounce ? typeof debounce === "number" ? debounce : debounce.scroll : null;
1707
+ const resizeDebounce = debounce ? typeof debounce === "number" ? debounce : debounce.resize : null;
1708
+ const mounted = (0, import_react3.useRef)(false);
1709
+ (0, import_react3.useEffect)(() => {
1710
+ mounted.current = true;
1711
+ return () => void (mounted.current = false);
1712
+ });
1713
+ const [forceRefresh, resizeChange, scrollChange] = (0, import_react3.useMemo)(() => {
1714
+ const callback = () => {
1715
+ if (!state.current.element)
1716
+ return;
1717
+ const {
1718
+ left,
1719
+ top,
1720
+ width,
1721
+ height,
1722
+ bottom,
1723
+ right,
1724
+ x,
1725
+ y
1726
+ } = state.current.element.getBoundingClientRect();
1727
+ const size = {
1728
+ left,
1729
+ top,
1730
+ width,
1731
+ height,
1732
+ bottom,
1733
+ right,
1734
+ x,
1735
+ y
1736
+ };
1737
+ if (state.current.element instanceof HTMLElement && offsetSize) {
1738
+ size.height = state.current.element.offsetHeight;
1739
+ size.width = state.current.element.offsetWidth;
1740
+ }
1741
+ Object.freeze(size);
1742
+ if (mounted.current && !areBoundsEqual(state.current.lastBounds, size))
1743
+ set(state.current.lastBounds = size);
1744
+ };
1745
+ return [callback, resizeDebounce ? (0, import_debounce.default)(callback, resizeDebounce) : callback, scrollDebounce ? (0, import_debounce.default)(callback, scrollDebounce) : callback];
1746
+ }, [set, offsetSize, scrollDebounce, resizeDebounce]);
1747
+ function removeListeners() {
1748
+ if (state.current.scrollContainers) {
1749
+ state.current.scrollContainers.forEach((element) => element.removeEventListener("scroll", scrollChange, true));
1750
+ state.current.scrollContainers = null;
1751
+ }
1752
+ if (state.current.resizeObserver) {
1753
+ state.current.resizeObserver.disconnect();
1754
+ state.current.resizeObserver = null;
1755
+ }
1756
+ }
1757
+ function addListeners() {
1758
+ if (!state.current.element)
1759
+ return;
1760
+ state.current.resizeObserver = new ResizeObserver(scrollChange);
1761
+ state.current.resizeObserver.observe(state.current.element);
1762
+ if (scroll && state.current.scrollContainers) {
1763
+ state.current.scrollContainers.forEach((scrollContainer) => scrollContainer.addEventListener("scroll", scrollChange, {
1764
+ capture: true,
1765
+ passive: true
1766
+ }));
1767
+ }
1768
+ }
1769
+ const ref = (node) => {
1770
+ if (!node || node === state.current.element)
1771
+ return;
1772
+ removeListeners();
1773
+ state.current.element = node;
1774
+ state.current.scrollContainers = findScrollContainers(node);
1775
+ addListeners();
1776
+ };
1777
+ useOnWindowScroll(scrollChange, Boolean(scroll));
1778
+ useOnWindowResize(resizeChange);
1779
+ (0, import_react3.useEffect)(() => {
1780
+ removeListeners();
1781
+ addListeners();
1782
+ }, [scroll, scrollChange, resizeChange]);
1783
+ (0, import_react3.useEffect)(() => removeListeners, []);
1784
+ return [ref, bounds, forceRefresh];
1785
+ }
1786
+ function useOnWindowResize(onWindowResize) {
1787
+ (0, import_react3.useEffect)(() => {
1788
+ const cb = onWindowResize;
1789
+ window.addEventListener("resize", cb);
1790
+ return () => void window.removeEventListener("resize", cb);
1791
+ }, [onWindowResize]);
1792
+ }
1793
+ function useOnWindowScroll(onScroll, enabled) {
1794
+ (0, import_react3.useEffect)(() => {
1795
+ if (enabled) {
1796
+ const cb = onScroll;
1797
+ window.addEventListener("scroll", cb, {
1798
+ capture: true,
1799
+ passive: true
1800
+ });
1801
+ return () => void window.removeEventListener("scroll", cb, true);
1802
+ }
1803
+ }, [onScroll, enabled]);
1804
+ }
1805
+ function findScrollContainers(element) {
1806
+ const result = [];
1807
+ if (!element || element === document.body)
1808
+ return result;
1809
+ const {
1810
+ overflow,
1811
+ overflowX,
1812
+ overflowY
1813
+ } = window.getComputedStyle(element);
1814
+ if ([overflow, overflowX, overflowY].some((prop) => prop === "auto" || prop === "scroll"))
1815
+ result.push(element);
1816
+ return [...result, ...findScrollContainers(element.parentElement)];
1817
+ }
1818
+ var keys = ["x", "y", "top", "bottom", "left", "right", "width", "height"];
1819
+ var areBoundsEqual = (a, b) => keys.every((key) => a[key] === b[key]);
1820
+
1821
+ // src/schematic-components/SchematicText.tsx
1822
+ var SchematicText = ({ schematic_text }) => {
1823
+ const ct = useCameraTransform();
1824
+ const { text, position, anchor } = schematic_text;
1825
+ const tPos = applyToPoint(ct, position);
1826
+ const [boundsRef, bounds] = useMeasure();
1827
+ let offset = [0, 0];
1828
+ if (anchor === "center") {
1829
+ offset = [-bounds.width / 2, -bounds.height / 2];
1830
+ } else if (anchor === "left") {
1831
+ offset = [0, -bounds.height / 2];
1832
+ } else if (anchor === "right") {
1833
+ offset = [-bounds.width, -bounds.height / 2];
1834
+ }
1835
+ return <div ref={boundsRef} style={{
1836
+ fontFamily: "'IBM Plex Mono', monospace",
1837
+ position: "absolute",
1838
+ left: tPos.x + offset[0],
1839
+ top: tPos.y + offset[1]
1840
+ }}>{text}</div>;
1841
+ };
1842
+ var SchematicText_default = SchematicText;
1843
+
1844
+ // src/schematic-components/SchematicTrace.tsx
1845
+ var import_svg_path_generator = __toESM(require_svg_path_generator2());
1846
+
1847
+ // src/schematic-components/RenderError.tsx
1848
+ var RenderError_default = ({ text }) => {
1849
+ return <div style={{
1850
+ position: "fixed",
1851
+ backgroundColor: "red",
1852
+ color: "white",
1853
+ fontSize: 14,
1854
+ fontFamily: "sans-serif",
1855
+ padding: 5,
1856
+ right: 0,
1857
+ top: 0,
1858
+ opacity: 0.75
1859
+ }}>{text}</div>;
1860
+ };
1861
+
1862
+ // src/schematic-components/SchematicTrace.tsx
1863
+ var SchematicTrace = ({ trace: { source, schematic } }) => {
1864
+ const edges = schematic.edges;
1865
+ if (edges.length === 0) {
1866
+ return <RenderError_default text="Route with 0 edges" />;
1867
+ }
1868
+ const path = (0, import_svg_path_generator.default)();
1869
+ for (let i = 0; i < edges.length; i++) {
1870
+ path.moveTo(edges[i].from.x, edges[i].from.y);
1871
+ path.lineTo(edges[i].to.x, edges[i].to.y);
1872
+ }
1873
+ const d = path.toString();
1874
+ const pathBounds = get_svg_path_bounds_default(d);
1875
+ pathBounds.height = Math.max(pathBounds.height, 1);
1876
+ pathBounds.width = Math.max(pathBounds.width, 1);
1877
+ const center = {
1878
+ x: pathBounds.minX + pathBounds.width / 2,
1879
+ y: pathBounds.minY + pathBounds.height / 2
1880
+ };
1881
+ return <SVGPathComponent_default rotation={0} center={center} size={pathBounds} paths={[
1882
+ {
1883
+ stroke: "green",
1884
+ strokeWidth: 0.02,
1885
+ d
1886
+ }
1887
+ ]} />;
1888
+ };
1889
+ var SchematicTrace_default = SchematicTrace;
1890
+
1891
+ // src/schematic-components/SchematicBug.tsx
1892
+ var import_range = __toESM(require_range());
1893
+ var SchematicBug = ({ component: { source, schematic } }) => {
1894
+ const ports_arrangement = schematic.port_arrangement;
1895
+ const port_labels = schematic.port_labels;
1896
+ const bugw = 30;
1897
+ const rh = 15;
1898
+ const pd = 7.5;
1899
+ const bugh = Math.max(ports_arrangement.left_size, ports_arrangement.right_size) * rh;
1900
+ return <SVGPathComponent_default rotation={schematic.rotation} center={schematic.center} size={schematic.size} paths={[
1901
+ {
1902
+ stroke: "red",
1903
+ strokeWidth: 1,
1904
+ d: `M 0 0 L ${bugw} 0 L ${bugw} ${bugh} L 0 ${bugh}Z`
1905
+ },
1906
+ ...(0, import_range.default)(
1907
+ 0,
1908
+ ports_arrangement.left_size + ports_arrangement.right_size
1909
+ ).map((i) => {
1910
+ const ls = ports_arrangement.left_size;
1911
+ const left = i < ls;
1912
+ const rowi = i % ls;
1913
+ const p1 = [left ? 0 : bugw, rh / 2 + rowi * rh];
1914
+ const rd = [left ? -pd : pd, 0];
1915
+ return {
1916
+ stroke: "red",
1917
+ strokeWidth: 1,
1918
+ d: `M ${p1.join(" ")} l ${rd.join(" ")}`
1919
+ };
1920
+ })
1921
+ ]} />;
1922
+ };
1923
+
1924
+ // src/schematic-components/SimplePowerSource.tsx
1925
+ var SimplePowerSource = ({
1926
+ component: { source, schematic }
1927
+ }) => {
1928
+ return <SVGPathComponent_default rotation={schematic.rotation} center={schematic.center} size={schematic.size} paths={[
1929
+ {
1930
+ stroke: "red",
1931
+ strokeWidth: 1,
1932
+ 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"
1933
+ }
1934
+ ]} />;
1935
+ };
1936
+
1937
+ // src/schematic-components/SimpleGround.tsx
1938
+ var SimpleGround = ({ component: { source, schematic } }) => {
1939
+ return <SVGPathComponent_default rotation={schematic.rotation} center={schematic.center} size={schematic.size} paths={[
1940
+ {
1941
+ stroke: "red",
1942
+ strokeWidth: 0.7,
1943
+ 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"
1944
+ }
1945
+ ]} />;
1946
+ };
1947
+
1948
+ // src/schematic-components/SimpleInductor.tsx
1949
+ var SimpleInductor = ({ component: { source, schematic } }) => {
1950
+ return <SVGPathComponent_default rotation={schematic.rotation} center={schematic.center} size={schematic.size} paths={[
1951
+ {
1952
+ stroke: "red",
1953
+ strokeWidth: 1,
1954
+ 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"
1955
+ }
1956
+ ]} />;
1957
+ };
1958
+
1959
+ // src/schematic-components/SimpleDiode.tsx
1960
+ var SimpleDiode = ({ component: { source, schematic } }) => {
1961
+ return <SVGPathComponent_default rotation={schematic.rotation} center={schematic.center} size={schematic.size} paths={[
1962
+ { stroke: "red", strokeWidth: 2, d: "M 0,0 H 21" },
1963
+ { stroke: "red", strokeWidth: 2, d: "M 49,0 H 59" },
1964
+ { stroke: "red", strokeWidth: 2, d: "M 49,0 L 21 14 V -14 Z" },
1965
+ { stroke: "red", strokeWidth: 2, d: "M 49,-14 V 14" }
1966
+ ]} />;
1967
+ };
1968
+
1969
+ // src/schematic-components/SchematicComponent.tsx
1970
+ var SchematicComponent = ({ component }) => {
1971
+ const { source, schematic } = component;
1972
+ switch (source.ftype) {
1973
+ case "simple_resistor": {
1974
+ return <SimpleResistor component={{ source, schematic }} />;
1975
+ }
1976
+ case "simple_capacitor": {
1977
+ return <SimpleCapacitor component={{ source, schematic }} />;
1978
+ }
1979
+ case "simple_power_source": {
1980
+ return <SimplePowerSource component={{ source, schematic }} />;
1981
+ }
1982
+ case "simple_ground": {
1983
+ return <SimpleGround component={{ source, schematic }} />;
1984
+ }
1985
+ case "simple_inductor": {
1986
+ return <SimpleInductor component={{ source, schematic }} />;
1987
+ }
1988
+ case "simple_bug": {
1989
+ return <SchematicBug component={{ source, schematic }} />;
1990
+ }
1991
+ case "simple_diode": {
1992
+ return <SimpleDiode component={{ source, schematic }} />;
1993
+ }
1994
+ default: {
1995
+ return <div>
1996
+ {"unknown ftype: "}
1997
+ {component.source.ftype}
1998
+ </div>;
1999
+ }
2000
+ }
2001
+ };
2002
+ var SchematicComponent_default = SchematicComponent;
2003
+
2004
+ // src/schematic-components/SchematicElement.tsx
2005
+ var SchematicElement = ({
2006
+ element,
2007
+ allElements
2008
+ }) => {
2009
+ if (element.type === "schematic_component") {
2010
+ return <SchematicComponent_default component={collectElementRefs(element, allElements)} />;
2011
+ }
2012
+ if (element.type === "schematic_trace") {
2013
+ return <SchematicTrace_default trace={collectElementRefs(element, allElements)} />;
2014
+ }
2015
+ if (element.type === "schematic_port") {
2016
+ return <SchematicPort_default port={collectElementRefs(element, allElements)} />;
2017
+ }
2018
+ if (element.type === "schematic_text") {
2019
+ return <SchematicText_default schematic_text={element} />;
2020
+ }
2021
+ return null;
2022
+ };
2023
+
2024
+ // src/Schematic.tsx
2025
+ var import_use_mouse_matrix_transform = require("use-mouse-matrix-transform");
2026
+ var import_react_error_boundary = require("react-error-boundary");
2027
+ var fallbackRender = (elm) => ({ error, resetErrorBoundary }) => {
2028
+ return <div style={{ color: "red" }}>
2029
+ {"error rendering "}
2030
+ {elm.type}
2031
+ {": "}
2032
+ {error.toString()}
2033
+ </div>;
2034
+ };
2035
+ var Schematic = ({
2036
+ children,
2037
+ elements: initialElements = [],
2038
+ style
2039
+ }) => {
2040
+ const [elements, setElements] = (0, import_react4.useState)(initialElements);
2041
+ const [project, setProject] = (0, import_react4.useState)(null);
2042
+ const setCameraTransform = useRenderContext((s) => s.setCameraTransform);
2043
+ const { ref } = (0, import_use_mouse_matrix_transform.useMouseMatrixTransform)({
2044
+ onSetTransform: (transform2) => setCameraTransform(transform2),
2045
+ initialTransform: compose(scale(100, 100, 0, 0))
2046
+ });
2047
+ (0, import_react4.useEffect)(() => {
2048
+ if (initialElements.length > 0) {
2049
+ setProject((0, import_builder2.createProjectFromElements)(initialElements));
2050
+ return;
2051
+ }
2052
+ const projectBuilder = (0, import_builder2.createProjectBuilder)();
2053
+ (0, import_react_fiber.createRoot)().render(children, projectBuilder).then(async (elements2) => {
2054
+ setElements(elements2);
2055
+ setProject((0, import_builder2.createProjectFromElements)(elements2));
2056
+ }).catch((e) => {
2057
+ console.error("ERROR RENDERING CIRCUIT");
2058
+ throw e;
2059
+ });
2060
+ }, [children]);
2061
+ if (elements.length === 0)
2062
+ return null;
2063
+ return <div style={{
2064
+ width: "100%",
2065
+ backgroundColor: "rgba(255,255,255,0)",
2066
+ minHeight: 200,
2067
+ overflow: "hidden",
2068
+ position: "relative",
2069
+ cursor: "grab",
2070
+ ...style
2071
+ }} ref={ref}>{elements.map((elm) => <import_react_error_boundary.ErrorBoundary fallbackRender={fallbackRender(elm)}><SchematicElement element={elm} allElements={elements} key={JSON.stringify(elm)} /></import_react_error_boundary.ErrorBoundary>)}</div>;
2072
+ };
2073
+ // Annotate the CommonJS export names for ESM import in node:
2074
+ 0 && (module.exports = {
2075
+ Schematic
2076
+ });
2077
+ /**
2078
+ * @license React
2079
+ * use-sync-external-store-shim.development.js
2080
+ *
2081
+ * Copyright (c) Facebook, Inc. and its affiliates.
2082
+ *
2083
+ * This source code is licensed under the MIT license found in the
2084
+ * LICENSE file in the root directory of this source tree.
2085
+ */
2086
+ /**
2087
+ * @license React
2088
+ * use-sync-external-store-shim.production.min.js
2089
+ *
2090
+ * Copyright (c) Facebook, Inc. and its affiliates.
2091
+ *
2092
+ * This source code is licensed under the MIT license found in the
2093
+ * LICENSE file in the root directory of this source tree.
2094
+ */
2095
+ /**
2096
+ * @license React
2097
+ * use-sync-external-store-shim/with-selector.development.js
2098
+ *
2099
+ * Copyright (c) Facebook, Inc. and its affiliates.
2100
+ *
2101
+ * This source code is licensed under the MIT license found in the
2102
+ * LICENSE file in the root directory of this source tree.
2103
+ */
2104
+ /**
2105
+ * @license React
2106
+ * use-sync-external-store-shim/with-selector.production.min.js
2107
+ *
2108
+ * Copyright (c) Facebook, Inc. and its affiliates.
2109
+ *
2110
+ * This source code is licensed under the MIT license found in the
2111
+ * LICENSE file in the root directory of this source tree.
2112
+ */
2113
+ //# sourceMappingURL=index.js.map