@crvouga/mockingbird-runtime 0.0.0-reserved → 0.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 (81) hide show
  1. package/README.md +130 -1
  2. package/dist/adapter-node.d.ts +2521 -0
  3. package/dist/adapter-node.js +6920 -0
  4. package/dist/adapter-node.js.map +7 -0
  5. package/dist/admin-ui.js +25 -0
  6. package/dist/admin-ui.js.map +7 -0
  7. package/dist/chunk-2KDYLZXC.js +118 -0
  8. package/dist/chunk-2KDYLZXC.js.map +7 -0
  9. package/dist/chunk-2Y25NPCV.js +1289 -0
  10. package/dist/chunk-2Y25NPCV.js.map +7 -0
  11. package/dist/chunk-4SAK6MQT.js +246 -0
  12. package/dist/chunk-4SAK6MQT.js.map +7 -0
  13. package/dist/chunk-ANCCZFF2.js +778 -0
  14. package/dist/chunk-ANCCZFF2.js.map +7 -0
  15. package/dist/chunk-EBGYPQPA.js +198 -0
  16. package/dist/chunk-EBGYPQPA.js.map +7 -0
  17. package/dist/chunk-EQLY2YOA.js +274 -0
  18. package/dist/chunk-EQLY2YOA.js.map +7 -0
  19. package/dist/chunk-G62YDIIJ.js +7664 -0
  20. package/dist/chunk-G62YDIIJ.js.map +7 -0
  21. package/dist/chunk-HU6IOAFC.js +437 -0
  22. package/dist/chunk-HU6IOAFC.js.map +7 -0
  23. package/dist/chunk-RNAHPNUJ.js +97 -0
  24. package/dist/chunk-RNAHPNUJ.js.map +7 -0
  25. package/dist/chunk-UP4QOSFD.js +87 -0
  26. package/dist/chunk-UP4QOSFD.js.map +7 -0
  27. package/dist/chunk-XNS34BPF.js +2489 -0
  28. package/dist/chunk-XNS34BPF.js.map +7 -0
  29. package/dist/core.d.ts +356 -0
  30. package/dist/core.js +51 -0
  31. package/dist/core.js.map +7 -0
  32. package/dist/crypto-XS5XCMRJ.js +21 -0
  33. package/dist/crypto-XS5XCMRJ.js.map +7 -0
  34. package/dist/helpers-UD7CG4WQ.js +18 -0
  35. package/dist/helpers-UD7CG4WQ.js.map +7 -0
  36. package/dist/http-codec.d.ts +72 -0
  37. package/dist/http-codec.js +25 -0
  38. package/dist/http-codec.js.map +7 -0
  39. package/dist/http-provider.d.ts +3243 -0
  40. package/dist/http-provider.js +37920 -0
  41. package/dist/http-provider.js.map +7 -0
  42. package/dist/index.d.ts +10 -0
  43. package/dist/index.js +23 -0
  44. package/dist/index.js.map +7 -0
  45. package/dist/mqtt-broker/node.d.ts +632 -0
  46. package/dist/mqtt-broker/node.js +355 -0
  47. package/dist/mqtt-broker/node.js.map +7 -0
  48. package/dist/mqtt-broker.d.ts +990 -0
  49. package/dist/mqtt-broker.js +913 -0
  50. package/dist/mqtt-broker.js.map +7 -0
  51. package/dist/openapi-metadata.d.ts +290 -0
  52. package/dist/openapi-metadata.js +28 -0
  53. package/dist/openapi-metadata.js.map +7 -0
  54. package/dist/openapi.d.ts +252 -0
  55. package/dist/openapi.js +45 -0
  56. package/dist/openapi.js.map +7 -0
  57. package/dist/preview/artifacts.d.ts +19 -0
  58. package/dist/preview/artifacts.js +40 -0
  59. package/dist/preview/artifacts.js.map +7 -0
  60. package/dist/preview/bridge.d.ts +21 -0
  61. package/dist/preview/bridge.js +9 -0
  62. package/dist/preview/bridge.js.map +7 -0
  63. package/dist/preview/harness.d.ts +12 -0
  64. package/dist/preview/harness.js +65 -0
  65. package/dist/preview/harness.js.map +7 -0
  66. package/dist/preview/host.d.ts +30 -0
  67. package/dist/preview/host.js +70 -0
  68. package/dist/preview/host.js.map +7 -0
  69. package/dist/service/admin.d.ts +106 -0
  70. package/dist/service/admin.js +340 -0
  71. package/dist/service/admin.js.map +7 -0
  72. package/dist/service.d.ts +2665 -0
  73. package/dist/service.js +264 -0
  74. package/dist/service.js.map +7 -0
  75. package/dist/sqlite.d.ts +69 -0
  76. package/dist/sqlite.js +19 -0
  77. package/dist/sqlite.js.map +7 -0
  78. package/dist/ui.d.ts +37 -0
  79. package/dist/ui.js +702 -0
  80. package/dist/ui.js.map +7 -0
  81. package/package.json +130 -6
package/dist/ui.js ADDED
@@ -0,0 +1,702 @@
1
+ // ../ui/dist/reset.js
2
+ var CSS_RESET = `*,
3
+ *::before,
4
+ *::after {
5
+ box-sizing: border-box;
6
+ margin: 0;
7
+ padding: 0;
8
+ }
9
+
10
+ * {
11
+ scrollbar-width: thin;
12
+ scrollbar-color: color-mix(in srgb, CanvasText 35%, Canvas) Canvas;
13
+ }
14
+
15
+ *::-webkit-scrollbar {
16
+ width: 12px;
17
+ height: 12px;
18
+ }
19
+
20
+ *::-webkit-scrollbar-track,
21
+ *::-webkit-scrollbar-corner {
22
+ background: Canvas;
23
+ }
24
+
25
+ *::-webkit-scrollbar-thumb {
26
+ background: color-mix(in srgb, CanvasText 35%, Canvas);
27
+ border: 3px solid Canvas;
28
+ border-radius: 999px;
29
+ }
30
+
31
+ html {
32
+ hanging-punctuation: first allow-end last;
33
+ -webkit-text-size-adjust: none;
34
+ text-size-adjust: none;
35
+ tab-size: 4;
36
+ font-family:
37
+ ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI Variable", "Segoe UI",
38
+ "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
39
+ font-size: 16px;
40
+ line-height: 1.5;
41
+ -webkit-font-smoothing: antialiased;
42
+ -moz-osx-font-smoothing: grayscale;
43
+ text-rendering: optimizeLegibility;
44
+ -webkit-tap-highlight-color: transparent;
45
+ scroll-behavior: smooth;
46
+ background: Canvas;
47
+ color: CanvasText;
48
+ }
49
+
50
+ body {
51
+ min-height: 100svh;
52
+ line-height: 1.5;
53
+ background: Canvas;
54
+ color: CanvasText;
55
+ }
56
+
57
+ h1 {
58
+ font-size: 2em;
59
+ }
60
+
61
+ h2 {
62
+ font-size: 1.5em;
63
+ }
64
+
65
+ h3 {
66
+ font-size: 1.17em;
67
+ }
68
+
69
+ h4 {
70
+ font-size: 1em;
71
+ }
72
+
73
+ h5 {
74
+ font-size: 0.83em;
75
+ }
76
+
77
+ h6 {
78
+ font-size: 0.67em;
79
+ }
80
+
81
+ h1,
82
+ h2,
83
+ h3,
84
+ h4,
85
+ h5,
86
+ h6 {
87
+ font-weight: 700;
88
+ line-height: 1.2;
89
+ text-wrap: balance;
90
+ overflow-wrap: break-word;
91
+ }
92
+
93
+ p,
94
+ li,
95
+ figcaption,
96
+ dd,
97
+ dt,
98
+ blockquote {
99
+ overflow-wrap: break-word;
100
+ }
101
+
102
+ p,
103
+ li,
104
+ figcaption,
105
+ blockquote {
106
+ text-wrap: pretty;
107
+ }
108
+
109
+ ul,
110
+ ol,
111
+ menu {
112
+ list-style: none;
113
+ }
114
+
115
+ a {
116
+ color: inherit;
117
+ text-decoration: underline;
118
+ text-decoration-thickness: 1px;
119
+ text-underline-offset: 0.15em;
120
+ text-decoration-skip-ink: auto;
121
+ }
122
+
123
+ b,
124
+ strong {
125
+ font-weight: 700;
126
+ }
127
+
128
+ small {
129
+ font-size: 0.875em;
130
+ }
131
+
132
+ code,
133
+ kbd,
134
+ samp,
135
+ pre {
136
+ font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
137
+ font-size: 1em;
138
+ }
139
+
140
+ sub,
141
+ sup {
142
+ font-size: 75%;
143
+ line-height: 0;
144
+ position: relative;
145
+ vertical-align: baseline;
146
+ }
147
+
148
+ sub {
149
+ bottom: -0.25em;
150
+ }
151
+
152
+ sup {
153
+ top: -0.5em;
154
+ }
155
+
156
+ abbr[title] {
157
+ text-decoration: underline dotted;
158
+ text-underline-offset: 0.15em;
159
+ }
160
+
161
+ mark {
162
+ background: Mark;
163
+ color: MarkText;
164
+ }
165
+
166
+ hr {
167
+ height: 0;
168
+ border: 0;
169
+ border-top: 1px solid color-mix(in srgb, CanvasText 20%, transparent);
170
+ color: inherit;
171
+ }
172
+
173
+ img,
174
+ picture,
175
+ video,
176
+ canvas {
177
+ display: block;
178
+ max-width: 100%;
179
+ }
180
+
181
+ img,
182
+ video {
183
+ height: auto;
184
+ }
185
+
186
+ svg {
187
+ overflow: hidden;
188
+ }
189
+
190
+ iframe {
191
+ border: 0;
192
+ max-width: 100%;
193
+ }
194
+
195
+ table {
196
+ border-collapse: collapse;
197
+ border-spacing: 0;
198
+ }
199
+
200
+ fieldset {
201
+ border: 0;
202
+ min-inline-size: 0;
203
+ }
204
+
205
+ legend {
206
+ padding: 0;
207
+ }
208
+
209
+ button,
210
+ input,
211
+ select,
212
+ textarea,
213
+ optgroup {
214
+ font: inherit;
215
+ letter-spacing: inherit;
216
+ color: inherit;
217
+ margin: 0;
218
+ vertical-align: middle;
219
+ }
220
+
221
+ button,
222
+ input[type="button"],
223
+ input[type="submit"],
224
+ input[type="reset"] {
225
+ appearance: none;
226
+ background: none;
227
+ border: 0;
228
+ padding: 0;
229
+ cursor: pointer;
230
+ text-align: center;
231
+ }
232
+
233
+ input,
234
+ textarea,
235
+ select {
236
+ background-color: Canvas;
237
+ border: 1px solid color-mix(in srgb, CanvasText 28%, transparent);
238
+ border-radius: 0;
239
+ padding: 0.5em 0.65em;
240
+ }
241
+
242
+ input[type="checkbox"],
243
+ input[type="radio"],
244
+ input[type="range"],
245
+ input[type="file"],
246
+ input[type="color"],
247
+ input[type="button"],
248
+ input[type="submit"],
249
+ input[type="reset"],
250
+ input[type="image"],
251
+ input[type="hidden"] {
252
+ background: none;
253
+ border: 0;
254
+ padding: 0;
255
+ border-radius: 0;
256
+ }
257
+
258
+ input[type="checkbox"],
259
+ input[type="radio"] {
260
+ accent-color: CanvasText;
261
+ }
262
+
263
+ input[type="search"] {
264
+ appearance: none;
265
+ background-color: Canvas;
266
+ border: 1px solid color-mix(in srgb, CanvasText 28%, transparent);
267
+ }
268
+
269
+ input[type="search"]::-webkit-search-decoration,
270
+ input[type="search"]::-webkit-search-cancel-button,
271
+ input[type="search"]::-webkit-search-results-button,
272
+ input[type="search"]::-webkit-search-results-decoration {
273
+ -webkit-appearance: none;
274
+ display: none;
275
+ }
276
+
277
+ input[type="number"] {
278
+ appearance: textfield;
279
+ background-color: Canvas;
280
+ border: 1px solid color-mix(in srgb, CanvasText 28%, transparent);
281
+ }
282
+
283
+ input[type="number"]::-webkit-inner-spin-button,
284
+ input[type="number"]::-webkit-outer-spin-button {
285
+ -webkit-appearance: none;
286
+ margin: 0;
287
+ }
288
+
289
+ textarea {
290
+ resize: vertical;
291
+ }
292
+
293
+ ::placeholder {
294
+ opacity: 1;
295
+ color: color-mix(in srgb, CanvasText 45%, transparent);
296
+ }
297
+
298
+ :focus-visible {
299
+ outline: 2px solid CanvasText;
300
+ outline-offset: 2px;
301
+ }
302
+
303
+ :focus:not(:focus-visible) {
304
+ outline: none;
305
+ }
306
+
307
+ :disabled,
308
+ [disabled] {
309
+ cursor: default;
310
+ opacity: 0.6;
311
+ }
312
+
313
+ label,
314
+ summary,
315
+ select,
316
+ [role="button"] {
317
+ cursor: pointer;
318
+ }
319
+
320
+ summary {
321
+ display: list-item;
322
+ }
323
+
324
+ details {
325
+ display: block;
326
+ }
327
+
328
+ dialog {
329
+ margin: auto;
330
+ padding: 1rem;
331
+ border: 1px solid color-mix(in srgb, CanvasText 20%, transparent);
332
+ background: Canvas;
333
+ color: CanvasText;
334
+ max-width: calc(100vw - 2rem);
335
+ max-height: calc(100svh - 2rem);
336
+ }
337
+
338
+ dialog:not([open]) {
339
+ display: none;
340
+ }
341
+
342
+ ::backdrop {
343
+ background: color-mix(in srgb, CanvasText 40%, transparent);
344
+ }
345
+
346
+ [hidden] {
347
+ display: none !important;
348
+ }
349
+
350
+ ::selection {
351
+ background: Highlight;
352
+ color: HighlightText;
353
+ }
354
+
355
+ @media (prefers-reduced-motion: reduce) {
356
+ *,
357
+ *::before,
358
+ *::after {
359
+ animation-duration: 0.01ms !important;
360
+ animation-iteration-count: 1 !important;
361
+ transition-duration: 0.01ms !important;
362
+ scroll-behavior: auto !important;
363
+ }
364
+ }
365
+
366
+ @media (pointer: coarse) {
367
+ input,
368
+ select,
369
+ textarea {
370
+ font-size: max(16px, 1em);
371
+ }
372
+ }`;
373
+ function scopeReset(root) {
374
+ return scopeStylesheet(CSS_RESET, root).replaceAll("100dvh", "100%").replaceAll("100svh", "100%").replaceAll("100vh", "100%");
375
+ }
376
+ function scopeStylesheet(css, root) {
377
+ let out = "";
378
+ let cursor = 0;
379
+ while (cursor < css.length) {
380
+ const brace = css.indexOf("{", cursor);
381
+ if (brace === -1) {
382
+ out += css.slice(cursor);
383
+ break;
384
+ }
385
+ const prelude = css.slice(cursor, brace);
386
+ const trimmed = prelude.trimStart();
387
+ if (trimmed.startsWith("@media") || trimmed.startsWith("@supports")) {
388
+ const end = skipBlock(css, brace);
389
+ const body = css.slice(brace + 1, end - 1);
390
+ out += `${css.slice(cursor, brace + 1)}${scopeStylesheet(body, root)}}`;
391
+ cursor = end;
392
+ continue;
393
+ }
394
+ if (trimmed.startsWith("@")) {
395
+ const end = skipBlock(css, brace);
396
+ out += css.slice(cursor, end);
397
+ cursor = end;
398
+ continue;
399
+ }
400
+ const close = prelude.lastIndexOf("}");
401
+ const head = close === -1 ? "" : prelude.slice(0, close + 1);
402
+ const selector = close === -1 ? prelude : prelude.slice(close + 1);
403
+ out += `${head}${scopeSelectorList(selector, root)}{`;
404
+ cursor = brace + 1;
405
+ }
406
+ return out;
407
+ }
408
+ function scopeSelectorList(selector, root) {
409
+ const where = `:where(${root})`;
410
+ return splitSelectors(selector).map((part) => scopeOne(part.trim(), where)).filter((part) => part !== "").join(",\n");
411
+ }
412
+ function scopeOne(selector, where) {
413
+ if (selector === "html" || selector === "body" || selector === ":root")
414
+ return where;
415
+ if (selector.startsWith("*")) {
416
+ const rest = selector.slice(1);
417
+ return `${where}${rest},
418
+ ${where} ${selector}`;
419
+ }
420
+ if (selector.startsWith(":"))
421
+ return `${where}${selector},
422
+ ${where} ${selector}`;
423
+ return `${where} ${selector}`;
424
+ }
425
+ function splitSelectors(selector) {
426
+ const parts = [];
427
+ let current = "";
428
+ let depth = 0;
429
+ for (const char of selector) {
430
+ if (char === "(")
431
+ depth++;
432
+ else if (char === ")")
433
+ depth = Math.max(0, depth - 1);
434
+ if (char === "," && depth === 0) {
435
+ parts.push(current);
436
+ current = "";
437
+ continue;
438
+ }
439
+ current += char;
440
+ }
441
+ parts.push(current);
442
+ return parts;
443
+ }
444
+ function skipBlock(css, openBrace) {
445
+ let depth = 0;
446
+ for (let index = openBrace; index < css.length; index++) {
447
+ const char = css[index];
448
+ if (char === "{")
449
+ depth++;
450
+ else if (char === "}") {
451
+ depth--;
452
+ if (depth === 0)
453
+ return index + 1;
454
+ }
455
+ }
456
+ return css.length;
457
+ }
458
+
459
+ // ../ui/dist/system-harness.js
460
+ function mountSystemHarness(host, surfaces, options = {}) {
461
+ const ids = /* @__PURE__ */ new Set(["system"]);
462
+ for (const surface of surfaces) {
463
+ if (!surface.id || ids.has(surface.id))
464
+ throw new Error(`Duplicate or reserved surface: ${surface.id}`);
465
+ ids.add(surface.id);
466
+ }
467
+ const doc = host.ownerDocument;
468
+ const win = doc.defaultView ?? window;
469
+ const shell = doc.createElement("div");
470
+ shell.className = "msh";
471
+ const style = doc.createElement("style");
472
+ style.textContent = `
473
+ .msh{position:relative;height:100%;min-height:240px;isolation:isolate;color:CanvasText;background:Canvas;font:14px system-ui}
474
+ .msh-panel{height:100%;overflow:auto}.msh [hidden]{display:none!important}
475
+ .msh-chrome{position:absolute;inset:0;pointer-events:none;z-index:1000}
476
+ .msh-handle{position:absolute;pointer-events:auto;touch-action:none;width:44px;height:44px;border-radius:50%;border:1px solid #777;background:#17212f;color:white;box-shadow:0 2px 12px #0004;cursor:grab;font:20px system-ui}
477
+ .msh-home button,.msh-status button{display:block;padding:12px;width:100%;text-align:left;border:0;border-radius:6px;background:transparent;color:inherit;font:inherit;cursor:pointer}
478
+ .msh-home button:hover{background:#8883}
479
+ .msh-home,.msh-status{max-width:640px;padding:32px;margin:auto}
480
+ .msh :focus-visible{outline:2px solid #477bff;outline-offset:2px}
481
+ `;
482
+ const chrome = doc.createElement("div");
483
+ chrome.className = "msh-chrome";
484
+ const handle = doc.createElement("button");
485
+ handle.type = "button";
486
+ handle.className = "msh-handle";
487
+ handle.textContent = "\u25A6";
488
+ handle.setAttribute("aria-label", "Switch apps");
489
+ handle.dataset.testid = "system-switcher";
490
+ handle.hidden = surfaces.length === 0;
491
+ chrome.append(handle);
492
+ shell.append(style, chrome);
493
+ host.append(shell);
494
+ let destroyed = false;
495
+ let current = "";
496
+ const controller = new AbortController();
497
+ const entries = [];
498
+ const all = [
499
+ {
500
+ id: "system",
501
+ label: "System",
502
+ mount(panel) {
503
+ const home = doc.createElement("div");
504
+ home.className = "msh-home";
505
+ const heading = doc.createElement("h1");
506
+ heading.textContent = "System";
507
+ const intro = doc.createElement("p");
508
+ intro.textContent = "Your whole system, running in this browser. Open an app or inspect the services behind it.";
509
+ home.append(heading, intro);
510
+ for (const surface of surfaces) {
511
+ const button = doc.createElement("button");
512
+ button.textContent = surface.label;
513
+ button.onclick = () => {
514
+ void show(surface.id);
515
+ };
516
+ home.append(button);
517
+ }
518
+ panel.append(home);
519
+ return () => home.remove();
520
+ }
521
+ },
522
+ ...surfaces
523
+ ];
524
+ for (const spec of all) {
525
+ const panel = doc.createElement("section");
526
+ panel.className = "msh-panel";
527
+ panel.dataset.surface = spec.id;
528
+ panel.setAttribute("aria-label", spec.label);
529
+ panel.tabIndex = -1;
530
+ panel.hidden = true;
531
+ shell.insertBefore(panel, chrome);
532
+ entries.push({ spec, panel });
533
+ }
534
+ function load(entry) {
535
+ if (entry.pending)
536
+ return entry.pending;
537
+ entry.panel.setAttribute("aria-busy", "true");
538
+ const status = doc.createElement("div");
539
+ status.className = "msh-status";
540
+ status.setAttribute("role", "status");
541
+ status.textContent = "Loading\u2026";
542
+ const content = doc.createElement("div");
543
+ content.style.height = "100%";
544
+ entry.panel.replaceChildren(status, content);
545
+ entry.pending = Promise.resolve().then(() => {
546
+ if (destroyed)
547
+ return;
548
+ return entry.spec.mount(content, controller.signal);
549
+ }).then((dispose) => {
550
+ status.remove();
551
+ if (destroyed)
552
+ dispose?.();
553
+ else
554
+ entry.dispose = dispose;
555
+ }).catch((error) => {
556
+ if (destroyed)
557
+ return;
558
+ content.remove();
559
+ status.textContent = `Unable to open ${entry.spec.label}: ${error instanceof Error ? error.message : String(error)}`;
560
+ const retry = doc.createElement("button");
561
+ retry.textContent = "Retry";
562
+ retry.onclick = () => {
563
+ entry.pending = void 0;
564
+ void load(entry);
565
+ };
566
+ status.append(retry);
567
+ }).finally(() => entry.panel.removeAttribute("aria-busy"));
568
+ return entry.pending;
569
+ }
570
+ async function show(id) {
571
+ if (destroyed)
572
+ return;
573
+ const entry = entries.find((e) => e.spec.id === id) ?? entries[0];
574
+ if (!entry)
575
+ return;
576
+ current = entry.spec.id;
577
+ const next = entries[(entries.indexOf(entry) + 1) % entries.length];
578
+ handle.title = `Switch to ${next?.spec.label ?? "System"}`;
579
+ handle.setAttribute("aria-description", handle.title);
580
+ for (const candidate of entries) {
581
+ candidate.panel.hidden = candidate !== entry;
582
+ candidate.panel.inert = candidate !== entry;
583
+ }
584
+ if (entries.some((candidate) => candidate.panel.hidden && candidate.panel.contains(doc.activeElement))) {
585
+ entry.panel.focus();
586
+ }
587
+ if (options.syncUrl) {
588
+ const url = new URL(win.location.href);
589
+ url.searchParams.set("surface", current);
590
+ if (url.href !== win.location.href)
591
+ win.history.pushState(null, "", url);
592
+ }
593
+ await load(entry);
594
+ }
595
+ handle.onclick = () => {
596
+ if (dragged) {
597
+ dragged = false;
598
+ return;
599
+ }
600
+ const next = entries[(entries.findIndex((entry) => entry.spec.id === current) + 1) % entries.length];
601
+ if (next)
602
+ void show(next.spec.id);
603
+ };
604
+ let x = Infinity;
605
+ let y = Infinity;
606
+ const position = () => {
607
+ x = Math.max(0, Math.min(x, shell.clientWidth - 52));
608
+ y = Math.max(0, Math.min(y, shell.clientHeight - 52));
609
+ handle.style.left = `${x}px`;
610
+ handle.style.top = `${y}px`;
611
+ };
612
+ const snap = () => {
613
+ const maxX = Math.max(0, shell.clientWidth - 52);
614
+ const maxY = Math.max(0, shell.clientHeight - 52);
615
+ const minX = Math.min(8, maxX);
616
+ const minY = Math.min(8, maxY);
617
+ x = Math.max(minX, Math.min(x, maxX));
618
+ y = Math.max(minY, Math.min(y, maxY));
619
+ const distances = [x - minX, maxX - x, y - minY, maxY - y];
620
+ const edge = distances.indexOf(Math.min(...distances));
621
+ if (edge === 0)
622
+ x = minX;
623
+ else if (edge === 1)
624
+ x = maxX;
625
+ else if (edge === 2)
626
+ y = minY;
627
+ else
628
+ y = maxY;
629
+ handle.style.transition = win.matchMedia("(prefers-reduced-motion: reduce)").matches ? "none" : "left 160ms ease-out, top 160ms ease-out";
630
+ position();
631
+ };
632
+ let drag;
633
+ let dragged = false;
634
+ handle.onpointerdown = (event) => {
635
+ if (event.button !== 0)
636
+ return;
637
+ dragged = false;
638
+ handle.style.transition = "none";
639
+ drag = { x: event.clientX, y: event.clientY, left: x, top: y };
640
+ handle.setPointerCapture(event.pointerId);
641
+ };
642
+ handle.onpointermove = (event) => {
643
+ if (!drag)
644
+ return;
645
+ const dx = event.clientX - drag.x;
646
+ const dy = event.clientY - drag.y;
647
+ if (Math.hypot(dx, dy) > 5)
648
+ dragged = true;
649
+ if (!dragged)
650
+ return;
651
+ x = drag.left + dx;
652
+ y = drag.top + dy;
653
+ position();
654
+ };
655
+ handle.onpointerup = () => {
656
+ drag = void 0;
657
+ snap();
658
+ };
659
+ handle.onpointercancel = () => {
660
+ drag = void 0;
661
+ dragged = false;
662
+ snap();
663
+ };
664
+ handle.onlostpointercapture = () => {
665
+ drag = void 0;
666
+ snap();
667
+ };
668
+ const resize = new ResizeObserver(snap);
669
+ resize.observe(shell);
670
+ const fromUrl = () => new URL(win.location.href).searchParams.get("surface") ?? options.initial ?? "system";
671
+ const pop = () => {
672
+ void show(fromUrl());
673
+ };
674
+ if (options.syncUrl)
675
+ win.addEventListener("popstate", pop);
676
+ void show(options.syncUrl ? fromUrl() : options.initial ?? "system");
677
+ return {
678
+ show,
679
+ active: () => current,
680
+ destroy() {
681
+ if (destroyed)
682
+ return;
683
+ destroyed = true;
684
+ controller.abort();
685
+ resize.disconnect();
686
+ win.removeEventListener("popstate", pop);
687
+ for (const entry of entries) {
688
+ try {
689
+ entry.dispose?.();
690
+ } catch {
691
+ }
692
+ }
693
+ shell.remove();
694
+ }
695
+ };
696
+ }
697
+ export {
698
+ CSS_RESET,
699
+ mountSystemHarness,
700
+ scopeReset
701
+ };
702
+ //# sourceMappingURL=ui.js.map