@tachui/viewport 0.8.0-alpha

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,2823 @@
1
+ var J = Object.defineProperty;
2
+ var Z = (n, e, t) => e in n ? J(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
+ var o = (n, e, t) => Z(n, typeof e != "symbol" ? e + "" : e, t);
4
+ import { createSignal as z, mountComponentTree as Y, createRoot as ee, withComponentContext as te, createContext as ne, useContext as ie } from "@tachui/core";
5
+ function O(n = {}) {
6
+ const e = se(), t = le(e, n), i = ue(), s = pe(), a = we();
7
+ return {
8
+ platform: e,
9
+ capabilities: t,
10
+ userAgent: i,
11
+ screenSize: s,
12
+ isTouch: a
13
+ };
14
+ }
15
+ function se() {
16
+ return oe() ? "electron" : re() ? "mobile" : ae() ? "embedded" : "web";
17
+ }
18
+ function oe() {
19
+ return typeof window < "u" ? !!window.electronAPI || !!window.electron || !!window.require || navigator.userAgent.toLowerCase().includes("electron") : typeof process < "u" ? !!process.electron || !!process.versions?.electron || process.env.ELECTRON === "true" : !1;
20
+ }
21
+ function re() {
22
+ if (typeof window > "u") return !1;
23
+ const n = "ontouchstart" in window && !("onmousedown" in window), e = window.innerWidth <= 768 || window.innerHeight <= 768, t = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
24
+ navigator.userAgent
25
+ ), i = window.matchMedia?.("(pointer: coarse)")?.matches, s = window.matchMedia?.("(max-width: 768px)")?.matches;
26
+ return n || e && t || i || s;
27
+ }
28
+ function ae() {
29
+ if (typeof window > "u") return !1;
30
+ try {
31
+ return window.self !== window.top;
32
+ } catch {
33
+ return !0;
34
+ }
35
+ }
36
+ function le(n, e) {
37
+ const t = {
38
+ multiWindow: !1,
39
+ nativeWindows: !1,
40
+ modalOverlays: !0,
41
+ crossWindowCommunication: !1,
42
+ windowResizing: !1,
43
+ windowMinimizing: !1,
44
+ fullscreenSupport: !1,
45
+ menuBarSupport: !1
46
+ };
47
+ switch (n) {
48
+ case "electron":
49
+ return {
50
+ ...t,
51
+ multiWindow: !0,
52
+ nativeWindows: !0,
53
+ crossWindowCommunication: !0,
54
+ windowResizing: !0,
55
+ windowMinimizing: !0,
56
+ fullscreenSupport: !0,
57
+ menuBarSupport: !0
58
+ };
59
+ case "web":
60
+ return {
61
+ ...t,
62
+ multiWindow: e.enablePopupTest ? de() : !1,
63
+ crossWindowCommunication: ce() || he(),
64
+ fullscreenSupport: V(),
65
+ windowResizing: !1,
66
+ // Browser windows can't be resized programmatically
67
+ windowMinimizing: !1
68
+ };
69
+ case "mobile":
70
+ return {
71
+ ...t,
72
+ fullscreenSupport: V(),
73
+ modalOverlays: !0
74
+ };
75
+ case "embedded":
76
+ return {
77
+ ...t,
78
+ modalOverlays: !0
79
+ };
80
+ default:
81
+ return t;
82
+ }
83
+ }
84
+ function de() {
85
+ if (typeof window > "u" || typeof window.navigator < "u" && window.navigator.userAgent.includes("jsdom"))
86
+ return !1;
87
+ try {
88
+ const n = window.open("", "", "width=1,height=1");
89
+ return n ? (n.close(), !0) : !1;
90
+ } catch {
91
+ return !1;
92
+ }
93
+ }
94
+ function ce() {
95
+ return typeof window < "u" && "BroadcastChannel" in window;
96
+ }
97
+ function he() {
98
+ return typeof window < "u" && "MessageChannel" in window;
99
+ }
100
+ function V() {
101
+ return typeof document > "u" ? !1 : !!(document.fullscreenEnabled || document.webkitFullscreenEnabled || document.mozFullScreenEnabled || document.msFullscreenEnabled);
102
+ }
103
+ function ue() {
104
+ return typeof navigator > "u" ? "unknown" : navigator.userAgent;
105
+ }
106
+ function pe() {
107
+ return typeof window > "u" ? { width: 1920, height: 1080 } : {
108
+ width: window.screen?.width || window.innerWidth || 1920,
109
+ height: window.screen?.height || window.innerHeight || 1080
110
+ };
111
+ }
112
+ function we() {
113
+ return typeof window > "u" ? !1 : "ontouchstart" in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0;
114
+ }
115
+ function fe() {
116
+ if (typeof navigator > "u")
117
+ return {
118
+ name: "unknown",
119
+ version: "unknown",
120
+ engine: "unknown"
121
+ };
122
+ const n = navigator.userAgent;
123
+ let e = "unknown", t = "unknown", i = "unknown";
124
+ if (n.includes("Chrome")) {
125
+ e = "Chrome";
126
+ const s = n.match(/Chrome\/(\d+)/);
127
+ t = s ? s[1] : "unknown", i = "Blink";
128
+ } else if (n.includes("Firefox")) {
129
+ e = "Firefox";
130
+ const s = n.match(/Firefox\/(\d+)/);
131
+ t = s ? s[1] : "unknown", i = "Gecko";
132
+ } else if (n.includes("Safari") && !n.includes("Chrome")) {
133
+ e = "Safari";
134
+ const s = n.match(/Version\/(\d+)/);
135
+ t = s ? s[1] : "unknown", i = "WebKit";
136
+ } else if (n.includes("Edge")) {
137
+ e = "Edge";
138
+ const s = n.match(/Edge\/(\d+)/) || n.match(/Edg\/(\d+)/);
139
+ t = s ? s[1] : "unknown", i = "Blink";
140
+ }
141
+ return { name: e, version: t, engine: i };
142
+ }
143
+ function me() {
144
+ if (typeof navigator > "u")
145
+ return {
146
+ name: "unknown",
147
+ version: "unknown"
148
+ };
149
+ const n = navigator.userAgent;
150
+ let e = "unknown", t = "unknown";
151
+ if (n.includes("Windows"))
152
+ e = "Windows", n.includes("Windows NT 10.0") ? t = "10/11" : n.includes("Windows NT 6.3") ? t = "8.1" : n.includes("Windows NT 6.2") ? t = "8" : n.includes("Windows NT 6.1") && (t = "7");
153
+ else if (n.includes("Mac OS X")) {
154
+ e = "macOS";
155
+ const i = n.match(/Mac OS X (\d+_\d+_?\d*)/);
156
+ i && (t = i[1].replace(/_/g, "."));
157
+ } else if (n.includes("Linux"))
158
+ e = "Linux";
159
+ else if (n.includes("Android")) {
160
+ e = "Android";
161
+ const i = n.match(/Android (\d+\.?\d*\.?\d*)/);
162
+ t = i ? i[1] : "unknown";
163
+ } else if (n.includes("iPhone OS") || n.includes("OS ")) {
164
+ e = "iOS";
165
+ const i = n.match(/OS (\d+_\d+_?\d*)/);
166
+ i && (t = i[1].replace(/_/g, "."));
167
+ }
168
+ return { name: e, version: t };
169
+ }
170
+ function ge() {
171
+ return typeof window > "u" ? {
172
+ webgl: !1,
173
+ webgl2: !1,
174
+ webWorkers: !1,
175
+ serviceWorkers: !1,
176
+ pushNotifications: !1,
177
+ webAssembly: !1,
178
+ intersectionObserver: !1,
179
+ resizeObserver: !1
180
+ } : {
181
+ webgl: !!window.WebGLRenderingContext,
182
+ webgl2: !!window.WebGL2RenderingContext,
183
+ webWorkers: "Worker" in window,
184
+ serviceWorkers: "serviceWorker" in navigator,
185
+ pushNotifications: "PushManager" in window,
186
+ webAssembly: "WebAssembly" in window,
187
+ intersectionObserver: "IntersectionObserver" in window,
188
+ resizeObserver: "ResizeObserver" in window
189
+ };
190
+ }
191
+ function H(n) {
192
+ return {
193
+ canOpenWindow: (e = !1) => e ? n.capabilities.nativeWindows : n.capabilities.multiWindow || n.capabilities.modalOverlays,
194
+ canCommunicateBetweenWindows: () => n.capabilities.crossWindowCommunication,
195
+ canResizeWindows: () => n.capabilities.windowResizing,
196
+ canMinimizeWindows: () => n.capabilities.windowMinimizing,
197
+ canUseFullscreen: () => n.capabilities.fullscreenSupport,
198
+ canUseMenuBar: () => n.capabilities.menuBarSupport,
199
+ getOptimalViewportType: (e = !1) => e && n.capabilities.nativeWindows ? "window" : n.capabilities.modalOverlays ? "modal" : n.platform === "mobile" ? "sheet" : "portal"
200
+ };
201
+ }
202
+ class be {
203
+ // Fallback strategies
204
+ createModal(e) {
205
+ throw new Error("Modal fallback not implemented");
206
+ }
207
+ createPortal(e) {
208
+ throw new Error("Portal fallback not implemented");
209
+ }
210
+ }
211
+ class D extends be {
212
+ constructor(t = {}) {
213
+ super();
214
+ o(this, "environment");
215
+ o(this, "portals", /* @__PURE__ */ new Map());
216
+ o(this, "modals", /* @__PURE__ */ new Map());
217
+ o(this, "popups", /* @__PURE__ */ new Map());
218
+ o(this, "portalContainer", null);
219
+ o(this, "broadcastChannel", null);
220
+ this.environment = O(t), this.initializePortalContainer();
221
+ }
222
+ /**
223
+ * Check if we can create a window with given config
224
+ */
225
+ canCreateWindow(t) {
226
+ if (!t.preferNativeWindow)
227
+ return !0;
228
+ try {
229
+ return this.environment.capabilities.multiWindow;
230
+ } catch {
231
+ return !1;
232
+ }
233
+ }
234
+ /**
235
+ * Create a viewport instance
236
+ */
237
+ createWindow(t) {
238
+ switch (this.determineWindowType(t)) {
239
+ case "window":
240
+ return this.createPopupWindow(t);
241
+ case "modal":
242
+ return this.createModal(t);
243
+ case "portal":
244
+ return this.createPortal(t);
245
+ default:
246
+ return this.createModal(t);
247
+ }
248
+ }
249
+ /**
250
+ * Destroy a window
251
+ */
252
+ async destroyWindow(t) {
253
+ const i = this.portals.get(t);
254
+ if (i) {
255
+ i.dispose(), this.portals.delete(t);
256
+ return;
257
+ }
258
+ const s = this.modals.get(t);
259
+ if (s) {
260
+ s.dispose(), this.modals.delete(t);
261
+ return;
262
+ }
263
+ const a = this.popups.get(t);
264
+ if (a) {
265
+ a.dispose(), this.popups.delete(t);
266
+ return;
267
+ }
268
+ }
269
+ /**
270
+ * Set up cross-window communication
271
+ */
272
+ setupCrossWindowCommunication() {
273
+ if ("BroadcastChannel" in window)
274
+ this.broadcastChannel = new BroadcastChannel("tachui-viewport"), this.broadcastChannel.addEventListener(
275
+ "message",
276
+ (t) => {
277
+ this.handleCrossWindowMessage(t.data);
278
+ }
279
+ );
280
+ else {
281
+ const t = (i) => {
282
+ if (i.key === "tachui-viewport-message")
283
+ try {
284
+ const s = JSON.parse(i.newValue || "{}");
285
+ this.handleCrossWindowMessage(s);
286
+ } catch {
287
+ }
288
+ };
289
+ typeof window < "u" && window.addEventListener("storage", t);
290
+ }
291
+ }
292
+ /**
293
+ * Broadcast message to other windows
294
+ */
295
+ broadcastMessage(t, i) {
296
+ const s = {
297
+ ...t,
298
+ timestamp: Date.now(),
299
+ source: window.location.href
300
+ };
301
+ this.broadcastChannel ? this.broadcastChannel.postMessage(s) : (localStorage.setItem(
302
+ "tachui-viewport-message",
303
+ JSON.stringify(s)
304
+ ), setTimeout(() => {
305
+ localStorage.removeItem("tachui-viewport-message");
306
+ }, 100));
307
+ }
308
+ /**
309
+ * Optimize for web platform
310
+ */
311
+ optimizeForPlatform() {
312
+ document.documentElement.style.setProperty(
313
+ "--tachui-modal-backdrop-blur",
314
+ "8px"
315
+ ), document.documentElement.style.setProperty(
316
+ "--tachui-modal-animation-duration",
317
+ "200ms"
318
+ ), document.documentElement.style.setProperty("--tachui-modal-z-index", "1000"), this.injectGlobalStyles();
319
+ }
320
+ /**
321
+ * Create popup window (native browser window)
322
+ */
323
+ createPopupWindow(t) {
324
+ const i = new ye(t);
325
+ return this.popups.set(t.id, i), i;
326
+ }
327
+ /**
328
+ * Create modal overlay
329
+ */
330
+ createModal(t) {
331
+ const i = new ve(t);
332
+ return this.modals.set(t.id, i), i;
333
+ }
334
+ /**
335
+ * Create portal
336
+ */
337
+ createPortal(t) {
338
+ const i = new We(t, this.portalContainer);
339
+ return this.portals.set(t.id, i), i;
340
+ }
341
+ /**
342
+ * Determine optimal window type
343
+ */
344
+ determineWindowType(t) {
345
+ return t.preferNativeWindow && this.environment.capabilities.multiWindow ? "window" : t.modal !== !1 ? "modal" : "portal";
346
+ }
347
+ /**
348
+ * Initialize portal container
349
+ */
350
+ initializePortalContainer() {
351
+ let t = document.getElementById("app");
352
+ if (t) {
353
+ this.portalContainer = t;
354
+ return;
355
+ }
356
+ t = document.getElementById("tachui-portals"), t || (t = document.createElement("div"), t.id = "tachui-portals", t.style.position = "relative", t.style.zIndex = "999", document.body.appendChild(t)), this.portalContainer = t;
357
+ }
358
+ /**
359
+ * Handle cross-window messages
360
+ */
361
+ handleCrossWindowMessage(t) {
362
+ this.portals.forEach((i) => i.receiveMessage(t)), this.modals.forEach((i) => i.receiveMessage(t)), this.popups.forEach((i) => i.receiveMessage(t));
363
+ }
364
+ /**
365
+ * Inject global CSS styles
366
+ */
367
+ injectGlobalStyles() {
368
+ const t = "tachui-viewport-styles";
369
+ if (document.getElementById(t))
370
+ return;
371
+ const i = document.createElement("style");
372
+ i.id = t, i.textContent = `
373
+ .tachui-modal-backdrop {
374
+ position: fixed;
375
+ top: 0;
376
+ left: 0;
377
+ right: 0;
378
+ bottom: 0;
379
+ background: rgba(0, 0, 0, 0.5);
380
+ backdrop-filter: blur(var(--tachui-modal-backdrop-blur, 8px));
381
+ z-index: var(--tachui-modal-z-index, 1000);
382
+ display: flex;
383
+ align-items: center;
384
+ justify-content: center;
385
+ animation: tachui-fade-in var(--tachui-modal-animation-duration, 200ms) ease-out;
386
+ }
387
+
388
+ .tachui-modal-content {
389
+ background: white;
390
+ border-radius: 8px;
391
+ box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
392
+ max-width: 90vw;
393
+ max-height: 90vh;
394
+ overflow: auto;
395
+ animation: tachui-scale-in var(--tachui-modal-animation-duration, 200ms) ease-out;
396
+ }
397
+
398
+ .tachui-portal {
399
+ position: relative;
400
+ }
401
+
402
+ @keyframes tachui-fade-in {
403
+ from {
404
+ opacity: 0;
405
+ }
406
+ to {
407
+ opacity: 1;
408
+ }
409
+ }
410
+
411
+ @keyframes tachui-scale-in {
412
+ from {
413
+ opacity: 0;
414
+ transform: scale(0.95);
415
+ }
416
+ to {
417
+ opacity: 1;
418
+ transform: scale(1);
419
+ }
420
+ }
421
+
422
+ @media (prefers-reduced-motion: reduce) {
423
+ .tachui-modal-backdrop,
424
+ .tachui-modal-content {
425
+ animation: none;
426
+ }
427
+ }
428
+ `, document.head.appendChild(i);
429
+ }
430
+ }
431
+ class ye {
432
+ constructor(e) {
433
+ o(this, "id");
434
+ o(this, "type", "window");
435
+ o(this, "config");
436
+ o(this, "state");
437
+ o(this, "nativeWindow", null);
438
+ o(this, "messageHandlers", /* @__PURE__ */ new Set());
439
+ o(this, "eventHandlers", /* @__PURE__ */ new Map());
440
+ o(this, "setState");
441
+ this.id = e.id, this.config = e;
442
+ const [t, i] = z({
443
+ id: e.id,
444
+ title: e.title || e.id,
445
+ isVisible: !1,
446
+ isMinimized: !1,
447
+ isMaximized: !1,
448
+ isFullscreen: !1,
449
+ isFocused: !1,
450
+ bounds: {
451
+ x: e.x || 100,
452
+ y: e.y || 100,
453
+ width: e.width || 800,
454
+ height: e.height || 600
455
+ },
456
+ // Phase 2: Enhanced state properties
457
+ isPooled: !1,
458
+ lastUsed: Date.now(),
459
+ groupId: void 0,
460
+ tabIndex: void 0,
461
+ parentWindowId: void 0
462
+ });
463
+ this.state = t, this.setState = i;
464
+ }
465
+ render(e) {
466
+ this.nativeWindow && (this.nativeWindow.document.title = this.config.title || this.config.id);
467
+ }
468
+ async show() {
469
+ if (this.nativeWindow && !this.nativeWindow.closed) {
470
+ this.nativeWindow.focus();
471
+ return;
472
+ }
473
+ const e = this.buildWindowFeatures();
474
+ if (this.nativeWindow = window.open("", this.config.id, e), !this.nativeWindow)
475
+ throw new Error(
476
+ "Failed to open popup window (likely blocked by popup blocker)"
477
+ );
478
+ this.setupPopupEventHandlers(), this.setState((t) => ({
479
+ ...t,
480
+ isVisible: !0,
481
+ isFocused: !0
482
+ }));
483
+ }
484
+ async hide() {
485
+ this.nativeWindow && !this.nativeWindow.closed && this.nativeWindow.blur();
486
+ }
487
+ async focus() {
488
+ this.nativeWindow && !this.nativeWindow.closed && this.nativeWindow.focus();
489
+ }
490
+ async minimize() {
491
+ }
492
+ async maximize() {
493
+ }
494
+ async restore() {
495
+ }
496
+ async close() {
497
+ this.nativeWindow && !this.nativeWindow.closed && this.nativeWindow.close(), this.dispose();
498
+ }
499
+ dispose() {
500
+ this.messageHandlers.clear(), this.eventHandlers.clear(), this.nativeWindow = null;
501
+ }
502
+ postMessage(e) {
503
+ this.nativeWindow && !this.nativeWindow.closed && this.nativeWindow.postMessage(e, "*");
504
+ }
505
+ onMessage(e) {
506
+ return this.messageHandlers.add(e), () => this.messageHandlers.delete(e);
507
+ }
508
+ receiveMessage(e) {
509
+ this.messageHandlers.forEach((t) => t(e));
510
+ }
511
+ onShow(e) {
512
+ return this.addEventListener("show", e);
513
+ }
514
+ onHide(e) {
515
+ return this.addEventListener("hide", e);
516
+ }
517
+ onFocus(e) {
518
+ return this.addEventListener("focus", e);
519
+ }
520
+ onBlur(e) {
521
+ return this.addEventListener("blur", e);
522
+ }
523
+ onResize(e) {
524
+ return () => {
525
+ };
526
+ }
527
+ onClose(e) {
528
+ return this.addEventListener("close", e);
529
+ }
530
+ addEventListener(e, t) {
531
+ return this.eventHandlers.has(e) || this.eventHandlers.set(e, /* @__PURE__ */ new Set()), this.eventHandlers.get(e).add(t), () => {
532
+ this.eventHandlers.get(e)?.delete(t);
533
+ };
534
+ }
535
+ emit(e) {
536
+ const t = this.eventHandlers.get(e);
537
+ t && t.forEach((i) => i());
538
+ }
539
+ buildWindowFeatures() {
540
+ const e = [];
541
+ return this.config.width && e.push(`width=${this.config.width}`), this.config.height && e.push(`height=${this.config.height}`), this.config.x && e.push(`left=${this.config.x}`), this.config.y && e.push(`top=${this.config.y}`), e.push(`resizable=${this.config.resizable !== !1 ? "yes" : "no"}`), e.push("scrollbars=yes"), e.push("status=no"), e.push("toolbar=no"), e.push("menubar=no"), e.push("location=no"), e.join(",");
542
+ }
543
+ setupPopupEventHandlers() {
544
+ if (!this.nativeWindow) return;
545
+ const e = () => {
546
+ if (this.nativeWindow?.closed) {
547
+ this.emit("close");
548
+ return;
549
+ }
550
+ setTimeout(e, 1e3);
551
+ };
552
+ e(), window.addEventListener("message", (t) => {
553
+ t.source === this.nativeWindow && this.messageHandlers.forEach((i) => i(t.data));
554
+ });
555
+ }
556
+ // ==================== Phase 2: Enhanced Methods ====================
557
+ /**
558
+ * Window pooling and reuse
559
+ */
560
+ async prepareForReuse() {
561
+ this.nativeWindow && !this.nativeWindow.closed && (this.nativeWindow.document.body.innerHTML = "", this.nativeWindow.document.title = ""), this.messageHandlers.clear();
562
+ }
563
+ isReusable() {
564
+ return this.nativeWindow != null && !this.nativeWindow.closed;
565
+ }
566
+ markAsUsed() {
567
+ this.setState((e) => ({
568
+ ...e,
569
+ lastUsed: Date.now()
570
+ }));
571
+ }
572
+ async returnToPool() {
573
+ await this.hide(), this.setState((e) => ({
574
+ ...e,
575
+ isPooled: !0,
576
+ lastUsed: Date.now()
577
+ }));
578
+ }
579
+ /**
580
+ * State synchronization (limited in popup windows due to cross-origin restrictions)
581
+ */
582
+ syncState(e, t) {
583
+ if (!(!this.nativeWindow || this.nativeWindow.closed))
584
+ try {
585
+ this.nativeWindow.postMessage(
586
+ { type: "sync_state", key: e, value: t },
587
+ "*"
588
+ );
589
+ } catch (i) {
590
+ console.warn("Failed to sync state to popup window:", i);
591
+ }
592
+ }
593
+ getSharedState(e) {
594
+ }
595
+ onSharedStateChange(e, t) {
596
+ return () => {
597
+ };
598
+ }
599
+ /**
600
+ * Tab grouping (not supported for popup windows)
601
+ */
602
+ async attachToTab(e) {
603
+ throw new Error("Tab grouping not supported for popup windows");
604
+ }
605
+ async detachFromTab() {
606
+ return this;
607
+ }
608
+ getTabContainer() {
609
+ return null;
610
+ }
611
+ getTabIndex() {
612
+ return this.state().tabIndex || 0;
613
+ }
614
+ setTabIndex(e) {
615
+ this.setState((t) => ({
616
+ ...t,
617
+ tabIndex: e
618
+ }));
619
+ }
620
+ /**
621
+ * Parent-child relationships (limited for popup windows)
622
+ */
623
+ setParentWindow(e) {
624
+ this.setState((t) => ({
625
+ ...t,
626
+ parentWindowId: e.id
627
+ }));
628
+ }
629
+ getParentWindow() {
630
+ return null;
631
+ }
632
+ getChildWindows() {
633
+ return [];
634
+ }
635
+ addChildWindow(e) {
636
+ }
637
+ removeChildWindow(e) {
638
+ }
639
+ }
640
+ class ve {
641
+ constructor(e) {
642
+ o(this, "id");
643
+ o(this, "type", "modal");
644
+ o(this, "config");
645
+ o(this, "state");
646
+ o(this, "backdropElement", null);
647
+ o(this, "contentElement", null);
648
+ o(this, "messageHandlers", /* @__PURE__ */ new Set());
649
+ o(this, "eventHandlers", /* @__PURE__ */ new Map());
650
+ o(this, "setState");
651
+ // ==================== Phase 2: Enhanced Methods ====================
652
+ o(this, "sharedState", /* @__PURE__ */ new Map());
653
+ o(this, "stateChangeCallbacks", /* @__PURE__ */ new Map());
654
+ o(this, "childWindows", /* @__PURE__ */ new Map());
655
+ o(this, "parentWindow", null);
656
+ o(this, "tabContainer", null);
657
+ this.id = e.id, this.config = e;
658
+ const [t, i] = z({
659
+ id: e.id,
660
+ title: e.title || e.id,
661
+ isVisible: !1,
662
+ isMinimized: !1,
663
+ isMaximized: !1,
664
+ isFullscreen: !1,
665
+ isFocused: !1,
666
+ bounds: {
667
+ x: 0,
668
+ y: 0,
669
+ width: e.width || 600,
670
+ height: e.height || 400
671
+ },
672
+ zIndex: 1e3,
673
+ // Phase 2: Enhanced state properties
674
+ isPooled: !1,
675
+ lastUsed: Date.now(),
676
+ groupId: void 0,
677
+ tabIndex: void 0,
678
+ parentWindowId: void 0
679
+ });
680
+ this.state = t, this.setState = i, this.createElement();
681
+ }
682
+ render(e) {
683
+ this.contentElement && (this.contentElement.innerHTML = `<div>Modal: ${this.config.title}</div>`);
684
+ }
685
+ async show() {
686
+ this.backdropElement && (document.body.appendChild(this.backdropElement), this.setState((e) => ({
687
+ ...e,
688
+ isVisible: !0,
689
+ isFocused: !0
690
+ })), this.emit("show"));
691
+ }
692
+ async hide() {
693
+ this.backdropElement?.parentNode && this.backdropElement.parentNode.removeChild(this.backdropElement), this.setState((e) => ({
694
+ ...e,
695
+ isVisible: !1,
696
+ isFocused: !1
697
+ })), this.emit("hide");
698
+ }
699
+ async focus() {
700
+ this.contentElement && this.contentElement.focus(), this.emit("focus");
701
+ }
702
+ async minimize() {
703
+ await this.hide();
704
+ }
705
+ async maximize() {
706
+ }
707
+ async restore() {
708
+ await this.show();
709
+ }
710
+ async close() {
711
+ await this.hide(), this.emit("close"), this.dispose();
712
+ }
713
+ dispose() {
714
+ this.backdropElement?.parentNode && this.backdropElement.parentNode.removeChild(this.backdropElement), this.messageHandlers.clear(), this.eventHandlers.clear();
715
+ }
716
+ postMessage(e) {
717
+ }
718
+ onMessage(e) {
719
+ return this.messageHandlers.add(e), () => this.messageHandlers.delete(e);
720
+ }
721
+ receiveMessage(e) {
722
+ this.messageHandlers.forEach((t) => t(e));
723
+ }
724
+ onShow(e) {
725
+ return this.addEventListener("show", e);
726
+ }
727
+ onHide(e) {
728
+ return this.addEventListener("hide", e);
729
+ }
730
+ onFocus(e) {
731
+ return this.addEventListener("focus", e);
732
+ }
733
+ onBlur(e) {
734
+ return this.addEventListener("blur", e);
735
+ }
736
+ onResize(e) {
737
+ return () => {
738
+ };
739
+ }
740
+ onClose(e) {
741
+ return this.addEventListener("close", e);
742
+ }
743
+ addEventListener(e, t) {
744
+ return this.eventHandlers.has(e) || this.eventHandlers.set(e, /* @__PURE__ */ new Set()), this.eventHandlers.get(e).add(t), () => {
745
+ this.eventHandlers.get(e)?.delete(t);
746
+ };
747
+ }
748
+ emit(e) {
749
+ const t = this.eventHandlers.get(e);
750
+ t && t.forEach((i) => i());
751
+ }
752
+ createElement() {
753
+ this.backdropElement = document.createElement("div"), this.backdropElement.className = "tachui-modal-backdrop", this.contentElement = document.createElement("div"), this.contentElement.className = "tachui-modal-content", this.contentElement.style.width = `${this.config.width || 600}px`, this.contentElement.style.height = `${this.config.height || 400}px`, this.backdropElement.appendChild(this.contentElement), this.backdropElement.addEventListener("click", (e) => {
754
+ e.target === this.backdropElement && this.config.backdropDismiss !== !1 && this.close();
755
+ }), document.addEventListener("keydown", (e) => {
756
+ e.key === "Escape" && this.config.escapeKeyDismiss !== !1 && this.close();
757
+ });
758
+ }
759
+ /**
760
+ * Window pooling and reuse
761
+ */
762
+ async prepareForReuse() {
763
+ this.contentElement && (this.contentElement.innerHTML = ""), this.messageHandlers.clear(), this.sharedState.clear(), this.stateChangeCallbacks.clear();
764
+ }
765
+ isReusable() {
766
+ return this.backdropElement != null && this.contentElement != null;
767
+ }
768
+ markAsUsed() {
769
+ this.setState((e) => ({
770
+ ...e,
771
+ lastUsed: Date.now()
772
+ }));
773
+ }
774
+ async returnToPool() {
775
+ await this.hide(), this.setState((e) => ({
776
+ ...e,
777
+ isPooled: !0,
778
+ lastUsed: Date.now()
779
+ }));
780
+ }
781
+ /**
782
+ * State synchronization (full support for modals)
783
+ */
784
+ syncState(e, t) {
785
+ this.sharedState.set(e, t);
786
+ const i = this.stateChangeCallbacks.get(e);
787
+ i && i.forEach((s) => s(t)), this.childWindows.forEach((s) => {
788
+ s.syncState(e, t);
789
+ });
790
+ }
791
+ getSharedState(e) {
792
+ return this.sharedState.get(e);
793
+ }
794
+ onSharedStateChange(e, t) {
795
+ return this.stateChangeCallbacks.has(e) || this.stateChangeCallbacks.set(e, /* @__PURE__ */ new Set()), this.stateChangeCallbacks.get(e).add(t), () => {
796
+ this.stateChangeCallbacks.get(e)?.delete(t);
797
+ };
798
+ }
799
+ /**
800
+ * Tab grouping (web modal tab simulation)
801
+ */
802
+ async attachToTab(e) {
803
+ this.tabContainer = e, this.createTabInterface();
804
+ }
805
+ async detachFromTab() {
806
+ return this.tabContainer = null, this.removeTabInterface(), this;
807
+ }
808
+ getTabContainer() {
809
+ return this.tabContainer;
810
+ }
811
+ getTabIndex() {
812
+ return this.state().tabIndex || 0;
813
+ }
814
+ setTabIndex(e) {
815
+ this.setState((t) => ({
816
+ ...t,
817
+ tabIndex: e
818
+ }));
819
+ }
820
+ /**
821
+ * Parent-child relationships (full support for modals)
822
+ */
823
+ setParentWindow(e) {
824
+ this.parentWindow = e, this.setState((t) => ({
825
+ ...t,
826
+ parentWindowId: e.id
827
+ }));
828
+ }
829
+ getParentWindow() {
830
+ return this.parentWindow;
831
+ }
832
+ getChildWindows() {
833
+ return Array.from(this.childWindows.values());
834
+ }
835
+ addChildWindow(e) {
836
+ this.childWindows.set(e.id, e), e.setParentWindow(this);
837
+ }
838
+ removeChildWindow(e) {
839
+ this.childWindows.delete(e);
840
+ }
841
+ /**
842
+ * Tab interface helpers
843
+ */
844
+ createTabInterface() {
845
+ if (!this.contentElement || !this.tabContainer) return;
846
+ const e = document.createElement("div");
847
+ e.className = "tachui-modal-tab-header", e.style.cssText = `
848
+ display: flex;
849
+ border-bottom: 1px solid #e0e0e0;
850
+ background: #f5f5f5;
851
+ min-height: 40px;
852
+ `, this.contentElement.insertBefore(e, this.contentElement.firstChild);
853
+ }
854
+ removeTabInterface() {
855
+ if (!this.contentElement) return;
856
+ const e = this.contentElement.querySelector(
857
+ ".tachui-modal-tab-header"
858
+ );
859
+ e && e.remove();
860
+ }
861
+ }
862
+ class We {
863
+ constructor(e, t) {
864
+ o(this, "id");
865
+ o(this, "type", "portal");
866
+ o(this, "config");
867
+ o(this, "state");
868
+ o(this, "portalElement", null);
869
+ o(this, "messageHandlers", /* @__PURE__ */ new Set());
870
+ o(this, "eventHandlers", /* @__PURE__ */ new Map());
871
+ o(this, "cleanupFunction", null);
872
+ o(this, "setState");
873
+ // ==================== Phase 2: Enhanced Methods ====================
874
+ o(this, "sharedState", /* @__PURE__ */ new Map());
875
+ o(this, "stateChangeCallbacks", /* @__PURE__ */ new Map());
876
+ o(this, "childWindows", /* @__PURE__ */ new Map());
877
+ o(this, "parentWindow", null);
878
+ o(this, "tabContainer", null);
879
+ this.container = t, this.id = e.id, this.config = e;
880
+ const [i, s] = z({
881
+ id: e.id,
882
+ title: e.title || e.id,
883
+ isVisible: !1,
884
+ isMinimized: !1,
885
+ isMaximized: !1,
886
+ isFullscreen: !1,
887
+ isFocused: !1,
888
+ bounds: {
889
+ x: e.x || 0,
890
+ y: e.y || 0,
891
+ width: e.width || 400,
892
+ height: e.height || 300
893
+ },
894
+ // Phase 2: Enhanced state properties
895
+ isPooled: !1,
896
+ lastUsed: Date.now(),
897
+ groupId: void 0,
898
+ tabIndex: void 0,
899
+ parentWindowId: void 0
900
+ });
901
+ this.state = i, this.setState = s, this.createElement();
902
+ }
903
+ render(e) {
904
+ if (this.portalElement) {
905
+ this.portalElement.innerHTML = "";
906
+ try {
907
+ const t = Y(e, this.portalElement);
908
+ this.cleanupFunction = t;
909
+ } catch (t) {
910
+ console.error("Error during mountComponentTree:", t);
911
+ }
912
+ }
913
+ }
914
+ async show() {
915
+ this.portalElement && (this.container.id === "app" && (this.container.innerHTML = ""), this.container.appendChild(this.portalElement), this.portalElement.style.display = "block", this.setState((e) => ({
916
+ ...e,
917
+ isVisible: !0
918
+ })), this.emit("show"));
919
+ }
920
+ async hide() {
921
+ this.portalElement && (this.portalElement.style.display = "none"), this.setState((e) => ({
922
+ ...e,
923
+ isVisible: !1
924
+ })), this.emit("hide");
925
+ }
926
+ async focus() {
927
+ this.emit("focus");
928
+ }
929
+ async minimize() {
930
+ await this.hide();
931
+ }
932
+ async maximize() {
933
+ }
934
+ async restore() {
935
+ await this.show();
936
+ }
937
+ async close() {
938
+ this.portalElement?.parentNode && this.portalElement.parentNode.removeChild(this.portalElement), this.emit("close"), this.dispose();
939
+ }
940
+ dispose() {
941
+ this.cleanupFunction && (this.cleanupFunction(), this.cleanupFunction = null), this.portalElement?.parentNode && this.portalElement.parentNode.removeChild(this.portalElement), this.messageHandlers.clear(), this.eventHandlers.clear();
942
+ }
943
+ postMessage(e) {
944
+ }
945
+ onMessage(e) {
946
+ return this.messageHandlers.add(e), () => this.messageHandlers.delete(e);
947
+ }
948
+ receiveMessage(e) {
949
+ this.messageHandlers.forEach((t) => t(e));
950
+ }
951
+ onShow(e) {
952
+ return this.addEventListener("show", e);
953
+ }
954
+ onHide(e) {
955
+ return this.addEventListener("hide", e);
956
+ }
957
+ onFocus(e) {
958
+ return this.addEventListener("focus", e);
959
+ }
960
+ onBlur(e) {
961
+ return this.addEventListener("blur", e);
962
+ }
963
+ onResize(e) {
964
+ return () => {
965
+ };
966
+ }
967
+ onClose(e) {
968
+ return this.addEventListener("close", e);
969
+ }
970
+ addEventListener(e, t) {
971
+ return this.eventHandlers.has(e) || this.eventHandlers.set(e, /* @__PURE__ */ new Set()), this.eventHandlers.get(e).add(t), () => {
972
+ this.eventHandlers.get(e)?.delete(t);
973
+ };
974
+ }
975
+ emit(e) {
976
+ const t = this.eventHandlers.get(e);
977
+ t && t.forEach((i) => i());
978
+ }
979
+ createElement() {
980
+ this.portalElement = document.createElement("div"), this.portalElement.className = "tachui-portal", this.container && this.container.id === "app" ? (this.portalElement.style.position = "static", this.portalElement.style.width = "100%", this.portalElement.style.height = "auto", this.portalElement.style.background = "transparent", this.portalElement.style.border = "none", this.portalElement.style.display = "block") : (this.portalElement.style.position = "absolute", this.portalElement.style.left = `${this.config.x || 0}px`, this.portalElement.style.top = `${this.config.y || 0}px`, this.portalElement.style.width = `${this.config.width || 400}px`, this.portalElement.style.height = `${this.config.height || 300}px`, this.portalElement.style.background = "white", this.portalElement.style.border = "1px solid #ccc", this.portalElement.style.borderRadius = "8px", this.portalElement.style.boxShadow = "0 4px 12px rgba(0, 0, 0, 0.15)", this.portalElement.style.display = "none");
981
+ }
982
+ /**
983
+ * Window pooling and reuse (excellent for portals)
984
+ */
985
+ async prepareForReuse() {
986
+ this.portalElement && (this.portalElement.innerHTML = ""), this.messageHandlers.clear(), this.sharedState.clear(), this.stateChangeCallbacks.clear();
987
+ }
988
+ isReusable() {
989
+ return this.portalElement != null;
990
+ }
991
+ markAsUsed() {
992
+ this.setState((e) => ({
993
+ ...e,
994
+ lastUsed: Date.now()
995
+ }));
996
+ }
997
+ async returnToPool() {
998
+ await this.hide(), this.setState((e) => ({
999
+ ...e,
1000
+ isPooled: !0,
1001
+ lastUsed: Date.now()
1002
+ }));
1003
+ }
1004
+ /**
1005
+ * State synchronization (full support for portals)
1006
+ */
1007
+ syncState(e, t) {
1008
+ this.sharedState.set(e, t);
1009
+ const i = this.stateChangeCallbacks.get(e);
1010
+ i && i.forEach((s) => s(t)), this.childWindows.forEach((s) => {
1011
+ s.syncState(e, t);
1012
+ });
1013
+ }
1014
+ getSharedState(e) {
1015
+ return this.sharedState.get(e);
1016
+ }
1017
+ onSharedStateChange(e, t) {
1018
+ return this.stateChangeCallbacks.has(e) || this.stateChangeCallbacks.set(e, /* @__PURE__ */ new Set()), this.stateChangeCallbacks.get(e).add(t), () => {
1019
+ this.stateChangeCallbacks.get(e)?.delete(t);
1020
+ };
1021
+ }
1022
+ /**
1023
+ * Tab grouping (portal-based tab simulation)
1024
+ */
1025
+ async attachToTab(e) {
1026
+ this.tabContainer = e, this.createPortalTabInterface();
1027
+ }
1028
+ async detachFromTab() {
1029
+ return this.tabContainer = null, this.removePortalTabInterface(), this;
1030
+ }
1031
+ getTabContainer() {
1032
+ return this.tabContainer;
1033
+ }
1034
+ getTabIndex() {
1035
+ return this.state().tabIndex || 0;
1036
+ }
1037
+ setTabIndex(e) {
1038
+ this.setState((t) => ({
1039
+ ...t,
1040
+ tabIndex: e
1041
+ }));
1042
+ }
1043
+ /**
1044
+ * Parent-child relationships (full support for portals)
1045
+ */
1046
+ setParentWindow(e) {
1047
+ this.parentWindow = e, this.setState((t) => ({
1048
+ ...t,
1049
+ parentWindowId: e.id
1050
+ }));
1051
+ }
1052
+ getParentWindow() {
1053
+ return this.parentWindow;
1054
+ }
1055
+ getChildWindows() {
1056
+ return Array.from(this.childWindows.values());
1057
+ }
1058
+ addChildWindow(e) {
1059
+ this.childWindows.set(e.id, e), e.setParentWindow(this);
1060
+ }
1061
+ removeChildWindow(e) {
1062
+ this.childWindows.delete(e);
1063
+ }
1064
+ /**
1065
+ * Portal tab interface helpers
1066
+ */
1067
+ createPortalTabInterface() {
1068
+ if (!this.portalElement || !this.tabContainer) return;
1069
+ const e = document.createElement("div");
1070
+ e.className = "tachui-portal-tab-header", e.style.cssText = `
1071
+ display: flex;
1072
+ background: #f8f9fa;
1073
+ border-bottom: 1px solid #dee2e6;
1074
+ min-height: 36px;
1075
+ padding: 0 8px;
1076
+ align-items: center;
1077
+ `, this.portalElement.insertBefore(e, this.portalElement.firstChild);
1078
+ }
1079
+ removePortalTabInterface() {
1080
+ if (!this.portalElement) return;
1081
+ const e = this.portalElement.querySelector(
1082
+ ".tachui-portal-tab-header"
1083
+ );
1084
+ e && e.remove();
1085
+ }
1086
+ }
1087
+ class A {
1088
+ constructor(e, t = {}) {
1089
+ o(this, "adapter");
1090
+ o(this, "windows", /* @__PURE__ */ new Map());
1091
+ o(this, "windowGroups", /* @__PURE__ */ new Map());
1092
+ o(this, "eventHandlers", /* @__PURE__ */ new Map());
1093
+ // Phase 2: Global state management
1094
+ o(this, "globalState", /* @__PURE__ */ new Map());
1095
+ o(this, "globalStateCallbacks", /* @__PURE__ */ new Map());
1096
+ o(this, "environment");
1097
+ o(this, "platformConfig");
1098
+ this.platformConfig = t, this.environment = O(t), e ? this.adapter = e : this.adapter = this.createDefaultAdapter(), this.adapter.setupCrossWindowCommunication(), this.adapter.optimizeForPlatform();
1099
+ }
1100
+ /**
1101
+ * Open a new window/viewport
1102
+ */
1103
+ async openWindow(e, t, i = {}) {
1104
+ const s = this.windows.get(e);
1105
+ if (s)
1106
+ return await s.show(), await s.focus(), s;
1107
+ const a = {
1108
+ id: e,
1109
+ title: i.title || e,
1110
+ width: i.width || 800,
1111
+ height: i.height || 600,
1112
+ ...i
1113
+ };
1114
+ this.getOptimalWindowType(i);
1115
+ const r = this.adapter.createWindow(a);
1116
+ return this.windows.set(e, r), r.render(t), this.setupWindowEventHandlers(r), await r.show(), this.emit("window:opened", { window: r }), r;
1117
+ }
1118
+ /**
1119
+ * Dismiss/close a window
1120
+ */
1121
+ async dismissWindow(e) {
1122
+ const t = this.windows.get(e);
1123
+ if (!t)
1124
+ throw new Error(`Window with id '${e}' not found`);
1125
+ await t.close(), this.windows.delete(e), this.emit("window:closed", { windowId: e });
1126
+ }
1127
+ /**
1128
+ * Get a specific window
1129
+ */
1130
+ getWindow(e) {
1131
+ return this.windows.get(e) || null;
1132
+ }
1133
+ /**
1134
+ * Get all open windows
1135
+ */
1136
+ getAllWindows() {
1137
+ return Array.from(this.windows.values());
1138
+ }
1139
+ /**
1140
+ * Create a window group for data-driven window management
1141
+ */
1142
+ createWindowGroup(e) {
1143
+ if (this.windowGroups.has(e))
1144
+ return this.windowGroups.get(e);
1145
+ const t = new Se(e, this);
1146
+ return this.windowGroups.set(e, t), t;
1147
+ }
1148
+ /**
1149
+ * Check if we can open a window with given options
1150
+ */
1151
+ canOpenWindow(e = {}) {
1152
+ return H(this.environment).canOpenWindow(e.preferNativeWindow);
1153
+ }
1154
+ /**
1155
+ * Get optimal window type for given options
1156
+ */
1157
+ getOptimalWindowType(e = {}) {
1158
+ const t = H(this.environment);
1159
+ return e.preferNativeWindow && this.environment.capabilities.nativeWindows ? "window" : e.modal !== !1 && this.environment.capabilities.modalOverlays ? "modal" : t.getOptimalViewportType(e.preferNativeWindow);
1160
+ }
1161
+ /**
1162
+ * Event handling
1163
+ */
1164
+ onWindowOpened(e) {
1165
+ return this.on("window:opened", ({ window: t }) => e(t));
1166
+ }
1167
+ onWindowClosed(e) {
1168
+ return this.on("window:closed", ({ windowId: t }) => e(t));
1169
+ }
1170
+ /**
1171
+ * Generic event subscription
1172
+ */
1173
+ on(e, t) {
1174
+ return this.eventHandlers.has(e) || this.eventHandlers.set(e, /* @__PURE__ */ new Set()), this.eventHandlers.get(e).add(t), () => {
1175
+ this.eventHandlers.get(e)?.delete(t);
1176
+ };
1177
+ }
1178
+ /**
1179
+ * Emit an event to all handlers
1180
+ */
1181
+ emit(e, t) {
1182
+ const i = this.eventHandlers.get(e);
1183
+ i && i.forEach((s) => s(t));
1184
+ }
1185
+ /**
1186
+ * Set up event handlers for a window
1187
+ */
1188
+ setupWindowEventHandlers(e) {
1189
+ e.onFocus(() => {
1190
+ this.emit("window:focused", { windowId: e.id });
1191
+ }), e.onResize((t) => {
1192
+ this.emit("window:resized", { windowId: e.id, bounds: t });
1193
+ }), e.onClose(() => {
1194
+ this.windows.delete(e.id), this.emit("window:closed", { windowId: e.id });
1195
+ });
1196
+ }
1197
+ /**
1198
+ * Create default adapter based on platform
1199
+ */
1200
+ createDefaultAdapter() {
1201
+ switch (this.environment.platform) {
1202
+ case "electron":
1203
+ return new D(this.platformConfig);
1204
+ default:
1205
+ return new D(this.platformConfig);
1206
+ }
1207
+ }
1208
+ // ==================== Phase 2: Global State Management ====================
1209
+ /**
1210
+ * Synchronize state globally across all windows
1211
+ */
1212
+ syncGlobalState(e, t, i) {
1213
+ this.globalState.set(e, t);
1214
+ const s = this.globalStateCallbacks.get(e);
1215
+ s && s.forEach((a) => a(t)), this.windows.forEach((a) => {
1216
+ a.syncState(e, t);
1217
+ }), this.windowGroups.forEach((a, r) => {
1218
+ r !== i && a.syncStateInternal(e, t);
1219
+ });
1220
+ }
1221
+ /**
1222
+ * Get global shared state
1223
+ */
1224
+ getGlobalState(e) {
1225
+ return this.globalState.get(e);
1226
+ }
1227
+ /**
1228
+ * Listen for global state changes
1229
+ */
1230
+ onGlobalStateChange(e, t) {
1231
+ return this.globalStateCallbacks.has(e) || this.globalStateCallbacks.set(e, /* @__PURE__ */ new Set()), this.globalStateCallbacks.get(e).add(t), () => {
1232
+ this.globalStateCallbacks.get(e)?.delete(t);
1233
+ };
1234
+ }
1235
+ /**
1236
+ * Get window group by ID
1237
+ */
1238
+ getWindowGroup(e) {
1239
+ return this.windowGroups.get(e) || null;
1240
+ }
1241
+ /**
1242
+ * Get all window groups
1243
+ */
1244
+ getAllWindowGroups() {
1245
+ return Array.from(this.windowGroups.values());
1246
+ }
1247
+ /**
1248
+ * Window group management utilities
1249
+ */
1250
+ configureWindowGroupDefaults(e, t) {
1251
+ const i = this.windowGroups.get(e);
1252
+ i && (t.groupingStrategy && i.setGroupingStrategy(t.groupingStrategy), t.tabConfig && i.configureTabbing(t.tabConfig), t.poolConfig && i.configurePool(t.poolConfig), t.stateSyncScope && i.enableStateSync(t.stateSyncScope));
1253
+ }
1254
+ /**
1255
+ * Cleanup all resources
1256
+ */
1257
+ dispose() {
1258
+ this.globalState.clear(), this.globalStateCallbacks.clear();
1259
+ const e = Array.from(this.windows.values()).map(
1260
+ (t) => t.close().catch(() => {
1261
+ })
1262
+ // Ignore errors during cleanup
1263
+ );
1264
+ Promise.all(e).finally(() => {
1265
+ this.windows.clear(), this.windowGroups.clear(), this.eventHandlers.clear();
1266
+ });
1267
+ }
1268
+ }
1269
+ class Se {
1270
+ constructor(e, t, i = "any") {
1271
+ o(this, "windows", /* @__PURE__ */ new Map());
1272
+ o(this, "defaultOptions", {});
1273
+ o(this, "maxInstances", 1 / 0);
1274
+ // Phase 2: Enhanced features
1275
+ o(this, "groupingStrategy", "stack");
1276
+ o(this, "tabConfig", {
1277
+ enabled: !1,
1278
+ tabPosition: "top",
1279
+ allowDetach: !0,
1280
+ allowReorder: !0
1281
+ });
1282
+ o(this, "poolConfig", {
1283
+ enabled: !1,
1284
+ maxPoolSize: 5,
1285
+ reuseThreshold: 3e4,
1286
+ // 30 seconds
1287
+ keepAliveTime: 3e5
1288
+ // 5 minutes
1289
+ });
1290
+ o(this, "stateSyncScope", "none");
1291
+ o(this, "sharedState", /* @__PURE__ */ new Map());
1292
+ o(this, "stateCallbacks", /* @__PURE__ */ new Map());
1293
+ o(this, "windowPool", /* @__PURE__ */ new Map());
1294
+ o(this, "eventCallbacks", /* @__PURE__ */ new Map());
1295
+ o(this, "windowMetadata", /* @__PURE__ */ new Map());
1296
+ this.id = e, this.manager = t, this.dataType = i, this.startPoolCleanup();
1297
+ }
1298
+ /**
1299
+ * Open a window for specific data (Enhanced with pooling and reuse)
1300
+ */
1301
+ async openWindow(e, t) {
1302
+ const i = this.createDataKey(e), s = `${this.id}:${i}`, a = this.windows.get(i);
1303
+ if (a)
1304
+ return await a.show(), await a.focus(), a.markAsUsed(), a;
1305
+ let r = await this.getPooledWindow();
1306
+ if (r) {
1307
+ const c = t(e);
1308
+ return r.render(c), this.setWindowGroupMetadata(r, {
1309
+ id: s,
1310
+ groupId: this.id,
1311
+ isPooled: !1,
1312
+ lastUsed: Date.now()
1313
+ }), await r.show(), await r.focus(), this.windows.set(i, r), this.emitEvent("window:reused", r, e), r;
1314
+ }
1315
+ if (this.windows.size >= this.maxInstances) {
1316
+ const c = this.windows.values().next().value;
1317
+ c && (this.poolConfig.enabled ? await this.returnToPool(c) : await c.close());
1318
+ }
1319
+ const h = t(e);
1320
+ return r = await this.manager.openWindow(
1321
+ s,
1322
+ h,
1323
+ this.defaultOptions
1324
+ ), this.setWindowGroupMetadata(r, {
1325
+ groupId: this.id,
1326
+ isPooled: !1,
1327
+ lastUsed: Date.now(),
1328
+ tabIndex: this.tabConfig.enabled ? this.windows.size : void 0
1329
+ }), this.windows.set(i, r), r.onClose(() => {
1330
+ this.poolConfig.enabled && r.isReusable() ? this.returnToPool(r) : (this.windows.delete(i), this.emitEvent("window:destroyed", r.id), this.windows.size === 0 && this.emitEvent("group:empty"));
1331
+ }), this.groupingStrategy !== "stack" && this.applyGroupingStrategy(), this.emitEvent("window:created", r), this.windows.size >= this.maxInstances && this.emitEvent("group:full"), r;
1332
+ }
1333
+ /**
1334
+ * Get window for specific data
1335
+ */
1336
+ getWindowForData(e) {
1337
+ const t = this.createDataKey(e);
1338
+ return this.windows.get(t) || null;
1339
+ }
1340
+ /**
1341
+ * Get all windows in this group
1342
+ */
1343
+ getAllWindows() {
1344
+ return Array.from(this.windows.values());
1345
+ }
1346
+ /**
1347
+ * Close all windows in this group
1348
+ */
1349
+ async closeAllWindows() {
1350
+ const e = Array.from(this.windows.values()).map(
1351
+ (t) => t.close().catch(() => {
1352
+ })
1353
+ // Ignore errors
1354
+ );
1355
+ await Promise.all(e), this.windows.clear();
1356
+ }
1357
+ /**
1358
+ * Set default options for windows in this group
1359
+ */
1360
+ setDefaultOptions(e) {
1361
+ this.defaultOptions = { ...e };
1362
+ }
1363
+ /**
1364
+ * Set maximum number of instances
1365
+ */
1366
+ setMaxInstances(e) {
1367
+ this.maxInstances = Math.max(1, e);
1368
+ }
1369
+ // ==================== Phase 2: Enhanced Features ====================
1370
+ /**
1371
+ * Window grouping and tabbing
1372
+ */
1373
+ setGroupingStrategy(e) {
1374
+ this.groupingStrategy = e, this.applyGroupingStrategy();
1375
+ }
1376
+ getGroupingStrategy() {
1377
+ return this.groupingStrategy;
1378
+ }
1379
+ configureTabbing(e) {
1380
+ this.tabConfig = { ...e }, e.enabled && this.manager.environment.platform === "electron" && this.enableTabGrouping();
1381
+ }
1382
+ getTabConfig() {
1383
+ return { ...this.tabConfig };
1384
+ }
1385
+ /**
1386
+ * Window pooling and reuse
1387
+ */
1388
+ configurePool(e) {
1389
+ this.poolConfig = { ...e }, e.enabled && this.startPoolCleanup();
1390
+ }
1391
+ getPoolConfig() {
1392
+ return { ...this.poolConfig };
1393
+ }
1394
+ getPooledWindows() {
1395
+ return Array.from(this.windowPool.values());
1396
+ }
1397
+ async returnToPool(e) {
1398
+ if (!this.poolConfig.enabled) {
1399
+ await e.close();
1400
+ return;
1401
+ }
1402
+ await e.prepareForReuse(), await e.hide(), this.setWindowGroupMetadata(e, {
1403
+ isPooled: !0,
1404
+ lastUsed: Date.now()
1405
+ }), this.windowPool.set(e.id, e), this.windows.delete(this.getDataKeyForWindow(e)), this.emitEvent("window:pooled", e);
1406
+ }
1407
+ /**
1408
+ * State synchronization
1409
+ */
1410
+ enableStateSync(e) {
1411
+ this.stateSyncScope = e;
1412
+ }
1413
+ syncState(e, t) {
1414
+ this.syncStateInternal(e, t), this.stateSyncScope === "group" ? this.syncStateToGroupWindows(e, t) : this.stateSyncScope === "global" && this.manager.syncGlobalState(e, t, this.id);
1415
+ }
1416
+ /**
1417
+ * Internal state sync without propagation (prevents recursion)
1418
+ */
1419
+ syncStateInternal(e, t) {
1420
+ this.sharedState.set(e, t);
1421
+ const i = this.stateCallbacks.get(e);
1422
+ i && i.forEach((s) => s(t));
1423
+ }
1424
+ getSharedState(e) {
1425
+ return this.sharedState.get(e);
1426
+ }
1427
+ onStateChange(e, t) {
1428
+ return this.stateCallbacks.has(e) || this.stateCallbacks.set(e, /* @__PURE__ */ new Set()), this.stateCallbacks.get(e).add(t), () => {
1429
+ this.stateCallbacks.get(e)?.delete(t);
1430
+ };
1431
+ }
1432
+ /**
1433
+ * Window lifecycle events
1434
+ */
1435
+ onWindowCreated(e) {
1436
+ return this.addEventCallback("window:created", e);
1437
+ }
1438
+ onWindowDestroyed(e) {
1439
+ return this.addEventCallback("window:destroyed", e);
1440
+ }
1441
+ onWindowReused(e) {
1442
+ return this.addEventCallback("window:reused", e);
1443
+ }
1444
+ /**
1445
+ * Group-level events
1446
+ */
1447
+ onGroupEmpty(e) {
1448
+ return this.addEventCallback("group:empty", e);
1449
+ }
1450
+ onGroupFull(e) {
1451
+ return this.addEventCallback("group:full", e);
1452
+ }
1453
+ // ==================== Private Implementation ====================
1454
+ /**
1455
+ * Apply grouping strategy to existing windows
1456
+ */
1457
+ applyGroupingStrategy() {
1458
+ const e = this.getAllWindows();
1459
+ switch (this.groupingStrategy) {
1460
+ case "tabs":
1461
+ this.arrangeWindowsAsTabs(e);
1462
+ break;
1463
+ case "cascade":
1464
+ this.arrangeWindowsAsCascade(e);
1465
+ break;
1466
+ case "tile":
1467
+ this.arrangeWindowsAsTiles(e);
1468
+ break;
1469
+ default:
1470
+ this.arrangeWindowsAsStack(e);
1471
+ break;
1472
+ }
1473
+ }
1474
+ /**
1475
+ * Enable tab grouping for windows
1476
+ */
1477
+ enableTabGrouping() {
1478
+ !this.tabConfig.enabled || this.manager.environment.platform;
1479
+ }
1480
+ /**
1481
+ * Start pool cleanup timer
1482
+ */
1483
+ startPoolCleanup() {
1484
+ this.poolConfig.enabled && setInterval(() => {
1485
+ this.cleanupPool();
1486
+ }, 6e4);
1487
+ }
1488
+ /**
1489
+ * Clean up expired pooled windows
1490
+ */
1491
+ cleanupPool() {
1492
+ const e = Date.now(), t = [];
1493
+ this.windowPool.forEach((i, s) => {
1494
+ const a = this.getWindowGroupMetadata(i);
1495
+ e - (a.lastUsed || 0) > this.poolConfig.keepAliveTime && t.push(s);
1496
+ }), t.forEach(async (i) => {
1497
+ const s = this.windowPool.get(i);
1498
+ s && (await s.dispose(), this.windowPool.delete(i));
1499
+ });
1500
+ }
1501
+ /**
1502
+ * Try to get a pooled window for reuse
1503
+ */
1504
+ async getPooledWindow() {
1505
+ if (!this.poolConfig.enabled || this.windowPool.size === 0)
1506
+ return null;
1507
+ let e = null, t = 0;
1508
+ return this.windowPool.forEach((i) => {
1509
+ const s = this.getWindowGroupMetadata(i), a = Date.now() - (s.lastUsed || 0);
1510
+ if (a < this.poolConfig.reuseThreshold) {
1511
+ const r = this.poolConfig.reuseThreshold - a;
1512
+ r > t && (e = i, t = r);
1513
+ }
1514
+ }), e && (this.windowPool.delete(e.id), this.setWindowGroupMetadata(e, {
1515
+ isPooled: !1,
1516
+ lastUsed: Date.now()
1517
+ })), e;
1518
+ }
1519
+ /**
1520
+ * Sync state to all windows in group (with recursion prevention)
1521
+ */
1522
+ syncStateToGroupWindows(e, t) {
1523
+ this.windows.forEach((i) => {
1524
+ const s = this.getWindowGroupMetadata(i);
1525
+ this.setWindowGroupMetadata(i, {
1526
+ ...s,
1527
+ [`shared:${e}`]: t
1528
+ });
1529
+ });
1530
+ }
1531
+ /**
1532
+ * Get data key for a window instance
1533
+ */
1534
+ getDataKeyForWindow(e) {
1535
+ for (const [t, i] of this.windows.entries())
1536
+ if (i.id === e.id)
1537
+ return t;
1538
+ return "";
1539
+ }
1540
+ /**
1541
+ * Window arrangement strategies
1542
+ */
1543
+ arrangeWindowsAsTabs(e) {
1544
+ this.manager.environment.platform === "electron" || this.arrangeWindowsAsModalTabs(e);
1545
+ }
1546
+ arrangeWindowsAsCascade(e) {
1547
+ e.forEach((t, i) => {
1548
+ const s = i * 30;
1549
+ this.setWindowGroupMetadata(t, {
1550
+ cascadeOffset: s,
1551
+ arrangementStyle: "cascade"
1552
+ });
1553
+ });
1554
+ }
1555
+ arrangeWindowsAsTiles(e) {
1556
+ const t = typeof window < "u" ? window.screen.width : 1920, i = typeof window < "u" ? window.screen.height : 1080, s = Math.ceil(Math.sqrt(e.length)), a = Math.ceil(e.length / s), r = t / s, h = i / a;
1557
+ e.forEach((c, l) => {
1558
+ const w = l % s, F = Math.floor(l / s);
1559
+ this.setWindowGroupMetadata(c, {
1560
+ tilePosition: {
1561
+ col: w,
1562
+ row: F,
1563
+ x: w * r,
1564
+ y: F * h,
1565
+ width: r,
1566
+ height: h
1567
+ },
1568
+ arrangementStyle: "tile"
1569
+ });
1570
+ });
1571
+ }
1572
+ arrangeWindowsAsStack(e) {
1573
+ }
1574
+ arrangeWindowsAsModalTabs(e) {
1575
+ }
1576
+ /**
1577
+ * Window metadata management (workaround for signal setter access)
1578
+ */
1579
+ setWindowGroupMetadata(e, t) {
1580
+ this.windowMetadata.set(e.id, {
1581
+ ...this.windowMetadata.get(e.id),
1582
+ ...t
1583
+ });
1584
+ }
1585
+ getWindowGroupMetadata(e) {
1586
+ return this.windowMetadata.get(e.id) || {};
1587
+ }
1588
+ /**
1589
+ * Event management helpers
1590
+ */
1591
+ addEventCallback(e, t) {
1592
+ return this.eventCallbacks.has(e) || this.eventCallbacks.set(e, /* @__PURE__ */ new Set()), this.eventCallbacks.get(e).add(t), () => {
1593
+ this.eventCallbacks.get(e)?.delete(t);
1594
+ };
1595
+ }
1596
+ emitEvent(e, ...t) {
1597
+ const i = this.eventCallbacks.get(e);
1598
+ i && i.forEach((s) => s(...t));
1599
+ }
1600
+ /**
1601
+ * Create a unique key for data
1602
+ */
1603
+ createDataKey(e) {
1604
+ if (e == null)
1605
+ return "null";
1606
+ if (typeof e == "string" || typeof e == "number" || typeof e == "boolean")
1607
+ return String(e);
1608
+ if (typeof e == "object" && "id" in e)
1609
+ return String(e.id);
1610
+ try {
1611
+ return JSON.stringify(e);
1612
+ } catch {
1613
+ return String(e);
1614
+ }
1615
+ }
1616
+ }
1617
+ let m = null;
1618
+ function u(n = {}) {
1619
+ return m || (m = new A(void 0, n)), m;
1620
+ }
1621
+ function R(n) {
1622
+ m?.dispose(), m = n;
1623
+ }
1624
+ function Ee() {
1625
+ m?.dispose(), m = null;
1626
+ }
1627
+ function y(n) {
1628
+ return {
1629
+ type: "window-scene",
1630
+ sceneType: "window",
1631
+ id: n.id,
1632
+ title: n.title || n.id,
1633
+ content: n.children,
1634
+ options: n,
1635
+ // Render method for scene management
1636
+ render() {
1637
+ return {
1638
+ type: "component",
1639
+ id: `window-scene-${n.id}`,
1640
+ props: {},
1641
+ render: () => ({
1642
+ type: "element",
1643
+ tag: "div",
1644
+ props: {},
1645
+ children: [],
1646
+ element: document.createElement("div")
1647
+ })
1648
+ };
1649
+ },
1650
+ // Open this window
1651
+ async open() {
1652
+ const e = u(), t = ee(() => te((i) => n.children(), `Window-${n.id}`)({}));
1653
+ await e.openWindow(n.id, t, n);
1654
+ },
1655
+ // Close this window
1656
+ async close() {
1657
+ await u().dismissWindow(n.id);
1658
+ }
1659
+ };
1660
+ }
1661
+ function T(n) {
1662
+ const e = u(), t = e.createWindowGroup(n.id);
1663
+ n.groupingStrategy && t.setGroupingStrategy(n.groupingStrategy), n.tabConfig && t.configureTabbing(n.tabConfig), n.poolConfig && t.configurePool(n.poolConfig), n.stateSyncScope && t.enableStateSync(n.stateSyncScope), n.maxInstances && t.setMaxInstances(n.maxInstances);
1664
+ const {
1665
+ groupingStrategy: i,
1666
+ tabConfig: s,
1667
+ poolConfig: a,
1668
+ stateSyncScope: r,
1669
+ maxInstances: h,
1670
+ ...c
1671
+ } = n;
1672
+ return t.setDefaultOptions(c), {
1673
+ type: "window-group",
1674
+ sceneType: "window-group",
1675
+ id: n.id,
1676
+ title: n.title || n.id,
1677
+ content: n.children,
1678
+ options: n,
1679
+ group: t,
1680
+ // Render method for scene management
1681
+ render() {
1682
+ return {
1683
+ type: "component",
1684
+ id: `window-group-${n.id}`,
1685
+ props: {},
1686
+ render: () => ({
1687
+ type: "element",
1688
+ tag: "div",
1689
+ props: {},
1690
+ children: [],
1691
+ element: document.createElement("div")
1692
+ })
1693
+ };
1694
+ },
1695
+ // Open a window (data-driven or simple)
1696
+ async open(l) {
1697
+ if (l !== void 0 && n.for)
1698
+ await t.openWindow(
1699
+ l,
1700
+ n.children
1701
+ );
1702
+ else {
1703
+ const w = n.children();
1704
+ await e.openWindow(n.id, w, n);
1705
+ }
1706
+ },
1707
+ // Open window for specific data
1708
+ async openForData(l) {
1709
+ if (!n.for)
1710
+ throw new Error(
1711
+ 'WindowGroup must specify "for" parameter for data-driven windows'
1712
+ );
1713
+ await t.openWindow(
1714
+ l,
1715
+ n.children
1716
+ );
1717
+ },
1718
+ // Close all windows in this group
1719
+ async closeAll() {
1720
+ await t.closeAllWindows();
1721
+ },
1722
+ // Get all windows in this group
1723
+ getWindows() {
1724
+ return t.getAllWindows();
1725
+ },
1726
+ // Phase 2: Enhanced methods
1727
+ configureGrouping(l) {
1728
+ t.setGroupingStrategy(l);
1729
+ },
1730
+ configureTabs(l) {
1731
+ t.configureTabbing(l);
1732
+ },
1733
+ configurePooling(l) {
1734
+ t.configurePool(l);
1735
+ },
1736
+ enableStateSync(l) {
1737
+ t.enableStateSync(l);
1738
+ },
1739
+ syncGroupState(l, w) {
1740
+ t.syncState(l, w);
1741
+ },
1742
+ getGroupState(l) {
1743
+ return t.getSharedState(l);
1744
+ },
1745
+ onGroupStateChange(l, w) {
1746
+ return t.onStateChange(l, w);
1747
+ }
1748
+ };
1749
+ }
1750
+ function M(n) {
1751
+ return {
1752
+ type: "app",
1753
+ scenes: n.children,
1754
+ render() {
1755
+ return {
1756
+ type: "component",
1757
+ id: "tachui-app",
1758
+ props: {},
1759
+ render: () => ({
1760
+ type: "element",
1761
+ tag: "div",
1762
+ props: {},
1763
+ children: [],
1764
+ element: document.createElement("div")
1765
+ })
1766
+ };
1767
+ },
1768
+ // Initialize all scenes
1769
+ async initialize() {
1770
+ if (!u(n.platformConfig)) {
1771
+ const { initializeViewportSystem: t } = await Promise.resolve().then(() => ct);
1772
+ t();
1773
+ }
1774
+ },
1775
+ // Get scene by ID
1776
+ getScene(e) {
1777
+ return n.children.find((t) => t.id === e);
1778
+ },
1779
+ // Open a specific scene
1780
+ async openScene(e, t) {
1781
+ const i = this.getScene(e);
1782
+ if (!i)
1783
+ throw new Error(`Scene with id '${e}' not found`);
1784
+ i.type === "window-scene" ? await i.open() : i.type === "window-group" && await i.open(t);
1785
+ }
1786
+ };
1787
+ }
1788
+ const k = {
1789
+ /**
1790
+ * Create a document window group
1791
+ */
1792
+ documentGroup(n, e, t, i) {
1793
+ return T({
1794
+ id: n,
1795
+ title: e,
1796
+ for: t,
1797
+ children: i,
1798
+ width: 800,
1799
+ height: 600,
1800
+ resizable: !0
1801
+ });
1802
+ },
1803
+ /**
1804
+ * Create a settings window
1805
+ */
1806
+ settingsWindow(n) {
1807
+ return y({
1808
+ id: "settings",
1809
+ title: "Settings",
1810
+ width: 600,
1811
+ height: 400,
1812
+ resizable: !1,
1813
+ children: n
1814
+ });
1815
+ },
1816
+ /**
1817
+ * Create an inspector window
1818
+ */
1819
+ inspectorWindow(n) {
1820
+ return y({
1821
+ id: "inspector",
1822
+ title: "Inspector",
1823
+ width: 300,
1824
+ height: 500,
1825
+ resizable: !0,
1826
+ alwaysOnTop: !0,
1827
+ children: n
1828
+ });
1829
+ },
1830
+ /**
1831
+ * Create a palette window
1832
+ */
1833
+ paletteWindow(n, e, t) {
1834
+ return y({
1835
+ id: n,
1836
+ title: e,
1837
+ width: 250,
1838
+ height: 400,
1839
+ resizable: !1,
1840
+ alwaysOnTop: !0,
1841
+ children: t
1842
+ });
1843
+ }
1844
+ }, $ = {
1845
+ /**
1846
+ * Basic app with main window and settings
1847
+ */
1848
+ basicApp: () => M({
1849
+ children: [
1850
+ y({
1851
+ id: "main",
1852
+ title: "My App",
1853
+ children: () => ({
1854
+ type: "component",
1855
+ id: "main-content",
1856
+ props: {},
1857
+ render: () => ({
1858
+ type: "element",
1859
+ tag: "div",
1860
+ props: {},
1861
+ children: [],
1862
+ element: document.createElement("div")
1863
+ })
1864
+ })
1865
+ }),
1866
+ k.settingsWindow(() => ({
1867
+ type: "component",
1868
+ id: "settings-content",
1869
+ props: {},
1870
+ render: () => ({
1871
+ type: "element",
1872
+ tag: "div",
1873
+ props: {},
1874
+ children: [],
1875
+ element: document.createElement("div")
1876
+ })
1877
+ }))
1878
+ ]
1879
+ }),
1880
+ /**
1881
+ * Document-based app
1882
+ */
1883
+ documentApp: () => M({
1884
+ children: [
1885
+ T({
1886
+ id: "document",
1887
+ title: "Document",
1888
+ for: class {
1889
+ constructor() {
1890
+ o(this, "id");
1891
+ o(this, "title");
1892
+ }
1893
+ },
1894
+ children: (n) => ({
1895
+ type: "component",
1896
+ id: `document-${n.id}`,
1897
+ props: {},
1898
+ render: () => ({
1899
+ type: "element",
1900
+ tag: "div",
1901
+ props: {},
1902
+ children: [],
1903
+ element: document.createElement("div")
1904
+ })
1905
+ })
1906
+ }),
1907
+ k.settingsWindow(() => ({
1908
+ type: "component",
1909
+ id: "settings",
1910
+ props: {},
1911
+ render: () => ({
1912
+ type: "element",
1913
+ tag: "div",
1914
+ props: {},
1915
+ children: [],
1916
+ element: document.createElement("div")
1917
+ })
1918
+ }))
1919
+ ]
1920
+ })
1921
+ }, q = ne(null);
1922
+ function B({
1923
+ children: n,
1924
+ manager: e
1925
+ }) {
1926
+ const t = e || u(), i = {
1927
+ openWindow: async (s, a, r) => await t.openWindow(s, a, r),
1928
+ dismissWindow: async (s) => await t.dismissWindow(s),
1929
+ viewportEnvironment: t.environment,
1930
+ currentWindow: null
1931
+ // This would be set based on current context
1932
+ };
1933
+ return {
1934
+ type: "context-provider",
1935
+ context: q,
1936
+ value: i,
1937
+ children: Array.isArray(n) ? n : [n]
1938
+ };
1939
+ }
1940
+ function v() {
1941
+ const n = ie(q);
1942
+ if (!n)
1943
+ throw new Error(
1944
+ "useViewportEnvironment must be used within a ViewportEnvironmentProvider"
1945
+ );
1946
+ return n();
1947
+ }
1948
+ function P() {
1949
+ const { openWindow: n } = v();
1950
+ return n;
1951
+ }
1952
+ function x() {
1953
+ const { dismissWindow: n } = v();
1954
+ return n;
1955
+ }
1956
+ function _() {
1957
+ const { viewportEnvironment: n } = v();
1958
+ return n;
1959
+ }
1960
+ function Ce() {
1961
+ const { currentWindow: n } = v();
1962
+ return n;
1963
+ }
1964
+ function Me() {
1965
+ return u();
1966
+ }
1967
+ function ke(n, e) {
1968
+ return (t) => B({
1969
+ children: n(t),
1970
+ manager: e
1971
+ });
1972
+ }
1973
+ function Pe(n) {
1974
+ return (e) => {
1975
+ const t = P(), i = x(), s = _();
1976
+ return n({
1977
+ ...e,
1978
+ openWindow: t,
1979
+ dismissWindow: i,
1980
+ viewportEnvironment: s
1981
+ });
1982
+ };
1983
+ }
1984
+ const xe = {
1985
+ openWindow: "openWindow",
1986
+ dismissWindow: "dismissWindow",
1987
+ viewportEnvironment: "viewportEnvironment",
1988
+ currentWindow: "currentWindow"
1989
+ };
1990
+ function Te(n) {
1991
+ return v()[n];
1992
+ }
1993
+ var d = /* @__PURE__ */ ((n) => (n[n.Clean = 0] = "Clean", n[n.Check = 1] = "Check", n[n.Dirty = 2] = "Dirty", n[n.Disposed = 3] = "Disposed", n))(d || {}), Ie = Object.defineProperty, He = (n, e, t) => e in n ? Ie(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, f = (n, e, t) => He(n, typeof e != "symbol" ? e + "" : e, t);
1994
+ let De = 0, S = null, ze = null;
1995
+ function j() {
1996
+ return S;
1997
+ }
1998
+ function Q() {
1999
+ return ze;
2000
+ }
2001
+ class K {
2002
+ constructor(e, t = null) {
2003
+ f(this, "id"), f(this, "owner"), f(this, "fn"), f(this, "sources", /* @__PURE__ */ new Set()), f(this, "observers", /* @__PURE__ */ new Set()), f(this, "state", d.Dirty), f(this, "value"), this.id = ++De, this.fn = e, this.owner = t, t && !t.disposed && t.sources.add(this);
2004
+ }
2005
+ execute() {
2006
+ if (this.state === d.Disposed)
2007
+ return this.value;
2008
+ for (const t of this.sources)
2009
+ t && typeof t == "object" && "removeObserver" in t && t.removeObserver(this);
2010
+ this.sources.clear();
2011
+ const e = S;
2012
+ S = this;
2013
+ try {
2014
+ return this.state = d.Clean, this.value = this.fn(), this.value;
2015
+ } catch (t) {
2016
+ throw this.state = d.Disposed, (typeof process > "u" || process.env.NODE_ENV !== "test") && console.error("Error in computation:", t), t;
2017
+ } finally {
2018
+ S = e;
2019
+ }
2020
+ }
2021
+ dispose() {
2022
+ if (this.state !== d.Disposed) {
2023
+ this.state = d.Disposed;
2024
+ for (const e of this.sources)
2025
+ e && typeof e == "object" && "removeObserver" in e && e.removeObserver(this);
2026
+ this.sources.clear();
2027
+ for (const e of this.observers)
2028
+ e.sources.delete(this);
2029
+ this.observers.clear(), this.owner && !this.owner.disposed && this.owner.sources.delete(this);
2030
+ }
2031
+ }
2032
+ }
2033
+ var Oe = Object.defineProperty, Ae = (n, e, t) => e in n ? Oe(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, I = (n, e, t) => Ae(n, typeof e != "symbol" ? e + "" : e, t);
2034
+ let _e = 0;
2035
+ class Fe {
2036
+ constructor(e) {
2037
+ I(this, "id"), I(this, "observers", /* @__PURE__ */ new Set()), I(this, "_value"), this.id = ++_e, this._value = e;
2038
+ }
2039
+ /**
2040
+ * Get the current value and track dependency
2041
+ */
2042
+ getValue() {
2043
+ const e = j();
2044
+ return e && e.state !== d.Disposed && (this.observers.add(e), e.sources.add(this)), this._value;
2045
+ }
2046
+ /**
2047
+ * Get the current value without tracking dependency
2048
+ */
2049
+ peek() {
2050
+ return this._value;
2051
+ }
2052
+ /**
2053
+ * Set a new value and notify observers
2054
+ */
2055
+ set(e) {
2056
+ const t = typeof e == "function" ? e(this._value) : e;
2057
+ return t !== this._value && (this._value = t, this.notify()), t;
2058
+ }
2059
+ /**
2060
+ * Notify all observers that this signal has changed
2061
+ */
2062
+ notify() {
2063
+ for (const e of this.observers)
2064
+ e.state !== d.Disposed && (e.state = d.Dirty, Ve(e));
2065
+ }
2066
+ /**
2067
+ * Remove an observer (cleanup)
2068
+ */
2069
+ removeObserver(e) {
2070
+ this.observers.delete(e);
2071
+ }
2072
+ /**
2073
+ * Get debug information about this signal
2074
+ */
2075
+ [Symbol.for("tachui.debug")]() {
2076
+ return {
2077
+ id: this.id,
2078
+ value: this._value,
2079
+ observerCount: this.observers.size,
2080
+ type: "Signal"
2081
+ };
2082
+ }
2083
+ }
2084
+ const E = /* @__PURE__ */ new Set();
2085
+ let C = !1;
2086
+ function Ve(n) {
2087
+ E.add(n), !C && queueMicrotask(Ge);
2088
+ }
2089
+ function Ge() {
2090
+ if (!C) {
2091
+ C = !0;
2092
+ try {
2093
+ for (; E.size > 0; ) {
2094
+ const n = Array.from(E).sort((e, t) => e.id - t.id);
2095
+ E.clear();
2096
+ for (const e of n)
2097
+ e.state === d.Dirty && e.execute();
2098
+ }
2099
+ } finally {
2100
+ C = !1;
2101
+ }
2102
+ }
2103
+ }
2104
+ function Ne(n) {
2105
+ const e = new Fe(n), t = e.getValue.bind(e);
2106
+ t.peek = e.peek.bind(e);
2107
+ const i = e.set.bind(e);
2108
+ return Object.defineProperty(t, Symbol.for("tachui.signal"), {
2109
+ value: e,
2110
+ enumerable: !1
2111
+ }), [t, i];
2112
+ }
2113
+ function G(n) {
2114
+ return typeof n == "function" && Symbol.for("tachui.signal") in n;
2115
+ }
2116
+ const Le = (n, e) => n === e;
2117
+ var Ue = Object.defineProperty, Re = (n, e, t) => e in n ? Ue(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, p = (n, e, t) => Re(n, typeof e != "symbol" ? e + "" : e, t), W = /* @__PURE__ */ ((n) => (n[n.Immediate = 0] = "Immediate", n[n.High = 1] = "High", n[n.Normal = 2] = "Normal", n[n.Low = 3] = "Low", n[n.Idle = 4] = "Idle", n))(W || {});
2118
+ class $e extends Error {
2119
+ constructor(e, t, i) {
2120
+ super(e), this.cause = t, this.node = i, this.name = "ReactiveError";
2121
+ }
2122
+ }
2123
+ const qe = class b {
2124
+ constructor() {
2125
+ p(this, "updateQueues", /* @__PURE__ */ new Map()), p(this, "isFlushPending", !1), p(this, "isDestroyed", !1), p(this, "errorHandlers", /* @__PURE__ */ new Set()), p(this, "maxRetries", 3), p(this, "totalUpdateCycles", 0), p(this, "totalUpdateTime", 0), p(this, "errorCount", 0), p(this, "nodeRegistry", /* @__PURE__ */ new WeakSet());
2126
+ for (const e of Object.values(W))
2127
+ typeof e == "number" && this.updateQueues.set(e, /* @__PURE__ */ new Set());
2128
+ }
2129
+ static getInstance() {
2130
+ return b.instance || (b.instance = new b()), b.instance;
2131
+ }
2132
+ /**
2133
+ * Schedule reactive node for update
2134
+ */
2135
+ schedule(e) {
2136
+ this.isDestroyed || (this.nodeRegistry.add(e), this.getQueue(e.priority).add(e), this.isFlushPending || (this.isFlushPending = !0, this.scheduleFlush(e.priority)));
2137
+ }
2138
+ /**
2139
+ * Process all queued updates by priority
2140
+ */
2141
+ async flush() {
2142
+ if (this.isDestroyed) return;
2143
+ this.isFlushPending = !1;
2144
+ const e = performance.now();
2145
+ try {
2146
+ for (const t of [
2147
+ 0,
2148
+ 1,
2149
+ 2,
2150
+ 3,
2151
+ 4
2152
+ /* Idle */
2153
+ ]) {
2154
+ const i = this.updateQueues.get(t);
2155
+ if (!i || i.size === 0) continue;
2156
+ const s = Array.from(i);
2157
+ i.clear();
2158
+ for (const a of s)
2159
+ try {
2160
+ await this.updateNodeWithRetry(a);
2161
+ } catch (r) {
2162
+ this.handleReactiveError(
2163
+ new $e(`Failed to update ${a.type} node ${a.id}`, r, a)
2164
+ );
2165
+ }
2166
+ if (this.hasHigherPriorityWork(t))
2167
+ return this.flush();
2168
+ }
2169
+ this.totalUpdateCycles++;
2170
+ } finally {
2171
+ const t = performance.now();
2172
+ this.totalUpdateTime += t - e;
2173
+ }
2174
+ }
2175
+ /**
2176
+ * Update node with retry logic
2177
+ */
2178
+ async updateNodeWithRetry(e, t = 1) {
2179
+ try {
2180
+ e.notify();
2181
+ } catch (i) {
2182
+ if (t < this.maxRetries)
2183
+ return console.warn(`Reactive update failed, retrying (${t}/${this.maxRetries})`), await new Promise((s) => setTimeout(s, t * 10)), this.updateNodeWithRetry(e, t + 1);
2184
+ throw i;
2185
+ }
2186
+ }
2187
+ /**
2188
+ * Schedule flush based on priority
2189
+ */
2190
+ scheduleFlush(e) {
2191
+ switch (e) {
2192
+ case 0:
2193
+ this.flush();
2194
+ break;
2195
+ case 1:
2196
+ queueMicrotask(() => this.flush());
2197
+ break;
2198
+ case 2:
2199
+ typeof requestAnimationFrame < "u" ? requestAnimationFrame(() => this.flush()) : queueMicrotask(() => this.flush());
2200
+ break;
2201
+ case 3:
2202
+ case 4:
2203
+ typeof requestIdleCallback < "u" ? requestIdleCallback(() => this.flush(), { timeout: 1e3 }) : setTimeout(() => this.flush(), 50);
2204
+ break;
2205
+ }
2206
+ }
2207
+ /**
2208
+ * Check if there's higher priority work waiting
2209
+ */
2210
+ hasHigherPriorityWork(e) {
2211
+ for (let t = 0; t < e; t++) {
2212
+ const i = this.updateQueues.get(t);
2213
+ if (i && i.size > 0)
2214
+ return !0;
2215
+ }
2216
+ return !1;
2217
+ }
2218
+ /**
2219
+ * Get queue for priority level
2220
+ */
2221
+ getQueue(e) {
2222
+ const t = this.updateQueues.get(e);
2223
+ if (!t)
2224
+ throw new Error(`Invalid priority level: ${e}`);
2225
+ return t;
2226
+ }
2227
+ /**
2228
+ * Register error handler
2229
+ */
2230
+ onError(e) {
2231
+ return this.errorHandlers.add(e), () => this.errorHandlers.delete(e);
2232
+ }
2233
+ /**
2234
+ * Handle reactive errors with recovery
2235
+ */
2236
+ handleReactiveError(e) {
2237
+ this.errorCount++;
2238
+ let t = !1;
2239
+ for (const i of this.errorHandlers)
2240
+ try {
2241
+ i(e), t = !0;
2242
+ } catch (s) {
2243
+ console.error("Error handler threw error:", s);
2244
+ }
2245
+ if (!t && (console.error("Unhandled reactive error:", e), process.env.NODE_ENV === "development"))
2246
+ throw e;
2247
+ }
2248
+ /**
2249
+ * Get performance metrics
2250
+ */
2251
+ getPerformanceMetrics() {
2252
+ let e = 0;
2253
+ for (const t of this.updateQueues.values())
2254
+ e += t.size;
2255
+ return {
2256
+ totalNodes: e,
2257
+ updateCycles: this.totalUpdateCycles,
2258
+ averageUpdateTime: this.totalUpdateCycles > 0 ? this.totalUpdateTime / this.totalUpdateCycles : 0,
2259
+ memoryUsage: this.estimateMemoryUsage(),
2260
+ errorCount: this.errorCount
2261
+ };
2262
+ }
2263
+ /**
2264
+ * Estimate memory usage (rough approximation)
2265
+ */
2266
+ estimateMemoryUsage() {
2267
+ let e = 0;
2268
+ for (const t of this.updateQueues.values())
2269
+ e += t.size * 50;
2270
+ return e += this.errorHandlers.size * 100, e;
2271
+ }
2272
+ /**
2273
+ * Check if node is scheduled
2274
+ */
2275
+ hasNode(e) {
2276
+ for (const t of this.updateQueues.values())
2277
+ if (t.has(e))
2278
+ return !0;
2279
+ return !1;
2280
+ }
2281
+ /**
2282
+ * Flush all pending updates synchronously
2283
+ */
2284
+ flushSync() {
2285
+ this.isFlushPending && (this.isFlushPending = !1, this.flush());
2286
+ }
2287
+ /**
2288
+ * Clear all pending updates
2289
+ */
2290
+ clearPending() {
2291
+ for (const e of this.updateQueues.values())
2292
+ e.clear();
2293
+ this.isFlushPending = !1;
2294
+ }
2295
+ /**
2296
+ * Cleanup all reactive nodes and destroy scheduler
2297
+ */
2298
+ destroy() {
2299
+ this.isDestroyed = !0;
2300
+ for (const e of this.updateQueues.values()) {
2301
+ for (const t of e)
2302
+ try {
2303
+ t.cleanup();
2304
+ } catch (i) {
2305
+ console.error("Error cleaning up reactive node:", i);
2306
+ }
2307
+ e.clear();
2308
+ }
2309
+ this.updateQueues.clear(), this.errorHandlers.clear(), b.instance = null;
2310
+ }
2311
+ /**
2312
+ * Get debug information
2313
+ */
2314
+ getDebugInfo() {
2315
+ const e = {};
2316
+ for (const [t, i] of this.updateQueues)
2317
+ e[W[t]] = i.size;
2318
+ return {
2319
+ isFlushPending: this.isFlushPending,
2320
+ isDestroyed: this.isDestroyed,
2321
+ queueSizes: e,
2322
+ errorHandlerCount: this.errorHandlers.size,
2323
+ performance: this.getPerformanceMetrics()
2324
+ };
2325
+ }
2326
+ };
2327
+ p(qe, "instance", null);
2328
+ var Be = Object.defineProperty, je = (n, e, t) => e in n ? Be(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, g = (n, e, t) => je(n, typeof e != "symbol" ? e + "" : e, t);
2329
+ class Qe extends K {
2330
+ constructor(e, t = {}, i = Q()) {
2331
+ super(e, i), g(this, "type", "computed"), g(this, "priority"), g(this, "_hasValue", !1), g(this, "_error", null), g(this, "equalsFn"), g(this, "options"), this.priority = t.priority ?? W.Normal, this.equalsFn = t.equals ?? Le, this.options = t;
2332
+ }
2333
+ /**
2334
+ * Get the computed value, tracking dependency and lazily computing
2335
+ */
2336
+ getValue() {
2337
+ const e = j();
2338
+ return e && e.state !== d.Disposed && (this.observers.add(e), e.sources.add(this)), (this.state === d.Dirty || !this._hasValue) && (this.execute(), this._hasValue = !0), this.value;
2339
+ }
2340
+ /**
2341
+ * Get the current value without tracking dependency
2342
+ */
2343
+ peek() {
2344
+ return (this.state === d.Dirty || !this._hasValue) && (this.execute(), this._hasValue = !0), this.value;
2345
+ }
2346
+ /**
2347
+ * Remove an observer (cleanup)
2348
+ */
2349
+ removeObserver(e) {
2350
+ this.observers.delete(e);
2351
+ }
2352
+ /**
2353
+ * Execute the computation and notify observers
2354
+ */
2355
+ execute() {
2356
+ const e = this._hasValue ? this.value : void 0, t = super.execute();
2357
+ if (!this._hasValue || !this.equalsFn(e, t))
2358
+ for (const i of this.observers)
2359
+ i.state !== d.Disposed && (i.state = d.Dirty, "execute" in i && typeof i.execute == "function" && queueMicrotask(() => {
2360
+ i.state === d.Dirty && i.execute();
2361
+ }));
2362
+ return t;
2363
+ }
2364
+ /**
2365
+ * Notify method for ReactiveNode compatibility
2366
+ */
2367
+ notify() {
2368
+ this.execute();
2369
+ }
2370
+ /**
2371
+ * Complete cleanup for memory management
2372
+ */
2373
+ cleanup() {
2374
+ for (const e of this.sources)
2375
+ "removeObserver" in e && e.removeObserver(this);
2376
+ this.sources.clear();
2377
+ for (const e of this.observers)
2378
+ e.sources.delete(this);
2379
+ this.observers.clear(), this._hasValue = !1, this._error = null, this.state = d.Disposed;
2380
+ }
2381
+ /**
2382
+ * Dispose the computed value
2383
+ */
2384
+ dispose() {
2385
+ this.cleanup(), super.dispose();
2386
+ }
2387
+ /**
2388
+ * Debug information
2389
+ */
2390
+ [Symbol.for("tachui.debug")]() {
2391
+ return {
2392
+ id: this.id,
2393
+ type: this.type,
2394
+ value: this._hasValue ? this.value : void 0,
2395
+ hasValue: this._hasValue,
2396
+ error: this._error?.message,
2397
+ state: this.state,
2398
+ sourceCount: this.sources.size,
2399
+ observerCount: this.observers.size,
2400
+ priority: W[this.priority],
2401
+ debugName: this.options.debugName,
2402
+ equalsFn: this.equalsFn.name || "anonymous"
2403
+ };
2404
+ }
2405
+ toString() {
2406
+ return `Computed(${this.options.debugName || this.id}): ${this._hasValue ? this.value : "no value"}`;
2407
+ }
2408
+ }
2409
+ function Ke(n, e) {
2410
+ const t = new Qe(n, e), i = t.getValue.bind(t);
2411
+ return i.peek = t.peek.bind(t), Object.defineProperty(i, Symbol.for("tachui.computed"), {
2412
+ value: t,
2413
+ enumerable: !1
2414
+ }), i;
2415
+ }
2416
+ function N(n) {
2417
+ return typeof n == "function" && Symbol.for("tachui.computed") in n;
2418
+ }
2419
+ const [Xe, wt] = Ne("light");
2420
+ Ke(() => {
2421
+ const n = Xe();
2422
+ return n === "system" ? Je() : n;
2423
+ });
2424
+ function Je() {
2425
+ return typeof window < "u" && window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
2426
+ }
2427
+ typeof globalThis.__DEV__ > "u" && (globalThis.__DEV__ = process.env.NODE_ENV !== "production");
2428
+ var Ze = Object.defineProperty, Ye = (n, e, t) => e in n ? Ze(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, L = (n, e, t) => Ye(n, typeof e != "symbol" ? e + "" : e, t);
2429
+ class et {
2430
+ constructor() {
2431
+ L(this, "pending", /* @__PURE__ */ new Set()), L(this, "isFlushScheduled", !1);
2432
+ }
2433
+ schedule(e) {
2434
+ this.pending.add(e), this.isFlushScheduled || (this.isFlushScheduled = !0, queueMicrotask(() => this.flush()));
2435
+ }
2436
+ flush() {
2437
+ if (this.pending.size === 0) {
2438
+ this.isFlushScheduled = !1;
2439
+ return;
2440
+ }
2441
+ const e = Array.from(this.pending);
2442
+ this.pending.clear(), this.isFlushScheduled = !1;
2443
+ for (const t of e)
2444
+ try {
2445
+ t();
2446
+ } catch (i) {
2447
+ console.error("Error in scheduled task:", i);
2448
+ }
2449
+ this.pending.size > 0 && (this.isFlushScheduled = !0, queueMicrotask(() => this.flush()));
2450
+ }
2451
+ }
2452
+ new et();
2453
+ function U(n, e = {}) {
2454
+ const t = Q();
2455
+ let i;
2456
+ const s = () => {
2457
+ const r = n(i);
2458
+ return i = r, r;
2459
+ }, a = new K(s, t);
2460
+ return e.name && Object.defineProperty(a, "name", {
2461
+ value: e.name,
2462
+ enumerable: !1
2463
+ }), a.execute(), a;
2464
+ }
2465
+ class tt {
2466
+ constructor(e) {
2467
+ this.properties = e;
2468
+ }
2469
+ /**
2470
+ * Helper to resolve reactive properties
2471
+ */
2472
+ resolveReactiveProps(e, t) {
2473
+ const i = {};
2474
+ for (const [s, a] of Object.entries(e))
2475
+ i[s] = a;
2476
+ return i;
2477
+ }
2478
+ /**
2479
+ * Apply a single style change to an element with reactive support
2480
+ */
2481
+ applyStyleChange(e, t, i) {
2482
+ if (e instanceof HTMLElement) {
2483
+ const s = this.toCSSProperty(t);
2484
+ if (G(i) || N(i))
2485
+ U(() => {
2486
+ const a = i(), r = String(a);
2487
+ if (r.includes("!important")) {
2488
+ const h = r.replace(/\s*!important\s*$/, "").trim();
2489
+ e.style.setProperty(s, h, "important");
2490
+ } else
2491
+ e.style.setProperty(s, r);
2492
+ });
2493
+ else {
2494
+ const a = String(i);
2495
+ if (a.includes("!important")) {
2496
+ const r = a.replace(/\s*!important\s*$/, "").trim();
2497
+ e.style.setProperty(s, r, "important");
2498
+ } else
2499
+ e.style.setProperty(s, a);
2500
+ }
2501
+ }
2502
+ }
2503
+ /**
2504
+ * Convert camelCase property to CSS kebab-case
2505
+ */
2506
+ toCSSProperty(e) {
2507
+ return e.replace(/([A-Z])/g, "-$1").toLowerCase();
2508
+ }
2509
+ /**
2510
+ * Convert value to CSS value string
2511
+ */
2512
+ toCSSValue(e) {
2513
+ return typeof e == "number" ? `${e}px` : String(e);
2514
+ }
2515
+ /**
2516
+ * Convert value to CSS value string with property-specific handling
2517
+ */
2518
+ toCSSValueForProperty(e, t) {
2519
+ return typeof t == "number" ? [
2520
+ "opacity",
2521
+ "z-index",
2522
+ "line-height",
2523
+ "flex-grow",
2524
+ "flex-shrink",
2525
+ "order",
2526
+ "column-count",
2527
+ "font-weight"
2528
+ ].includes(e) ? String(t) : `${t}px` : String(t);
2529
+ }
2530
+ /**
2531
+ * Apply multiple CSS properties to an element with reactive support
2532
+ */
2533
+ applyStyles(e, t) {
2534
+ if (e instanceof HTMLElement || e.style) {
2535
+ const i = e.style;
2536
+ for (const [s, a] of Object.entries(t))
2537
+ if (a !== void 0) {
2538
+ const r = this.toCSSProperty(s);
2539
+ if (G(a) || N(a))
2540
+ U(() => {
2541
+ const h = a(), c = this.toCSSValueForProperty(
2542
+ r,
2543
+ h
2544
+ );
2545
+ if (i.setProperty)
2546
+ if (typeof c == "string" && c.includes("!important")) {
2547
+ const l = c.replace(/\s*!important\s*$/, "").trim();
2548
+ i.setProperty(r, l, "important");
2549
+ } else
2550
+ i.setProperty(r, c);
2551
+ else
2552
+ i[r] = c;
2553
+ });
2554
+ else {
2555
+ const h = this.toCSSValueForProperty(r, a);
2556
+ if (i.setProperty)
2557
+ if (typeof h == "string" && h.includes("!important")) {
2558
+ const c = h.replace(/\s*!important\s*$/, "").trim();
2559
+ i.setProperty(r, c, "important");
2560
+ } else
2561
+ i.setProperty(r, h);
2562
+ else
2563
+ i[r] = h;
2564
+ }
2565
+ }
2566
+ }
2567
+ }
2568
+ /**
2569
+ * Add CSS classes to an element
2570
+ */
2571
+ addClasses(e, t) {
2572
+ e instanceof HTMLElement && e.classList.add(...t);
2573
+ }
2574
+ /**
2575
+ * Remove CSS classes from an element
2576
+ */
2577
+ removeClasses(e, t) {
2578
+ e instanceof HTMLElement && e.classList.remove(...t);
2579
+ }
2580
+ /**
2581
+ * Create a style computation context
2582
+ */
2583
+ createStyleContext(e, t, i) {
2584
+ return {
2585
+ componentId: e,
2586
+ element: t,
2587
+ modifiers: i,
2588
+ signals: /* @__PURE__ */ new Set(),
2589
+ cleanup: []
2590
+ };
2591
+ }
2592
+ }
2593
+ class X extends tt {
2594
+ constructor() {
2595
+ super(...arguments);
2596
+ o(this, "type", "viewportLifecycle");
2597
+ o(this, "priority", 100);
2598
+ }
2599
+ // High priority for lifecycle events
2600
+ apply(t, i) {
2601
+ i.element && (this.properties.onAppear || this.properties.onDisappear) && this.setupLifecycleObserver(i.element, this.properties);
2602
+ }
2603
+ setupLifecycleObserver(t, i) {
2604
+ new IntersectionObserver(
2605
+ (a) => {
2606
+ a.forEach((r) => {
2607
+ r.isIntersecting && i.onAppear ? i.onAppear() : !r.isIntersecting && i.onDisappear && i.onDisappear();
2608
+ });
2609
+ },
2610
+ {
2611
+ threshold: 0.1,
2612
+ // Trigger when 10% of element is visible
2613
+ rootMargin: "10px"
2614
+ // Add some margin for better UX
2615
+ }
2616
+ ).observe(t);
2617
+ }
2618
+ }
2619
+ function nt(n) {
2620
+ return new X({ onAppear: n });
2621
+ }
2622
+ function it(n) {
2623
+ return new X({ onDisappear: n });
2624
+ }
2625
+ const st = {
2626
+ // Manager
2627
+ getManager: u,
2628
+ // Environment
2629
+ useOpenWindow: P,
2630
+ useDismissWindow: x,
2631
+ useViewportInfo: _,
2632
+ // Components
2633
+ Window: y,
2634
+ WindowGroup: T,
2635
+ App: M,
2636
+ // Utilities
2637
+ Utils: k,
2638
+ Examples: $
2639
+ };
2640
+ function ot(n) {
2641
+ const e = new A(n?.customAdapter);
2642
+ return R(e), e;
2643
+ }
2644
+ const rt = {
2645
+ isWindow: (n) => n.type === "window",
2646
+ isModal: (n) => n.type === "modal",
2647
+ isPortal: (n) => n.type === "portal",
2648
+ isSheet: (n) => n.type === "sheet",
2649
+ isPopover: (n) => n.type === "popover"
2650
+ }, at = {
2651
+ /**
2652
+ * Check if running in Electron
2653
+ */
2654
+ isElectron: () => u().environment.platform === "electron",
2655
+ /**
2656
+ * Check if on mobile
2657
+ */
2658
+ isMobile: () => u().environment.platform === "mobile",
2659
+ /**
2660
+ * Check if multi-window is supported
2661
+ */
2662
+ supportsMultiWindow: () => u().environment.capabilities.multiWindow,
2663
+ /**
2664
+ * Check if native windows are supported
2665
+ */
2666
+ supportsNativeWindows: () => u().environment.capabilities.nativeWindows,
2667
+ /**
2668
+ * Get optimal window type for current platform
2669
+ */
2670
+ getOptimalWindowType: (n = !1) => u().getOptimalWindowType({ preferNativeWindow: n })
2671
+ }, lt = {
2672
+ /**
2673
+ * Standard document window
2674
+ */
2675
+ document: (n) => ({
2676
+ title: n || "Document",
2677
+ width: 800,
2678
+ height: 600,
2679
+ resizable: !0,
2680
+ minimizable: !0,
2681
+ maximizable: !0
2682
+ }),
2683
+ /**
2684
+ * Settings/preferences window
2685
+ */
2686
+ settings: (n) => ({
2687
+ title: n || "Settings",
2688
+ width: 600,
2689
+ height: 400,
2690
+ resizable: !1,
2691
+ minimizable: !1,
2692
+ maximizable: !1,
2693
+ modal: !0
2694
+ }),
2695
+ /**
2696
+ * Inspector/sidebar window
2697
+ */
2698
+ inspector: (n) => ({
2699
+ title: n || "Inspector",
2700
+ width: 300,
2701
+ height: 500,
2702
+ resizable: !0,
2703
+ alwaysOnTop: !0
2704
+ }),
2705
+ /**
2706
+ * Palette/tool window
2707
+ */
2708
+ palette: (n) => ({
2709
+ title: n || "Palette",
2710
+ width: 250,
2711
+ height: 400,
2712
+ resizable: !1,
2713
+ alwaysOnTop: !0
2714
+ }),
2715
+ /**
2716
+ * Dialog/alert window
2717
+ */
2718
+ dialog: (n) => ({
2719
+ title: n || "Dialog",
2720
+ width: 400,
2721
+ height: 200,
2722
+ resizable: !1,
2723
+ modal: !0,
2724
+ minimizable: !1,
2725
+ maximizable: !1
2726
+ }),
2727
+ /**
2728
+ * Fullscreen window
2729
+ */
2730
+ fullscreen: (n) => ({
2731
+ title: n || "Fullscreen",
2732
+ width: typeof window < "u" && window.screen?.width || 1920,
2733
+ height: typeof window < "u" && window.screen?.height || 1080,
2734
+ resizable: !1,
2735
+ minimizable: !1,
2736
+ maximizable: !1
2737
+ })
2738
+ }, dt = {
2739
+ DEFAULT_WINDOW_WIDTH: 800,
2740
+ DEFAULT_WINDOW_HEIGHT: 600,
2741
+ MIN_WINDOW_WIDTH: 300,
2742
+ MIN_WINDOW_HEIGHT: 200,
2743
+ MODAL_Z_INDEX: 1e3,
2744
+ PORTAL_Z_INDEX: 999,
2745
+ ANIMATION_DURATION: 200
2746
+ }, ct = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
2747
+ __proto__: null,
2748
+ App: M,
2749
+ EnvironmentKeys: xe,
2750
+ ExampleScenes: $,
2751
+ PlatformUtils: at,
2752
+ TachUIViewportManager: A,
2753
+ Viewport: st,
2754
+ ViewportConstants: dt,
2755
+ ViewportEnvironmentProvider: B,
2756
+ ViewportTypeGuards: rt,
2757
+ WebViewportAdapter: D,
2758
+ Window: y,
2759
+ WindowConfigs: lt,
2760
+ WindowGroup: T,
2761
+ WindowUtils: k,
2762
+ checkFeatureSupport: ge,
2763
+ createCapabilityChecker: H,
2764
+ createWindowAwareComponent: Pe,
2765
+ detectViewportEnvironment: O,
2766
+ disposeViewportManager: Ee,
2767
+ getBrowserInfo: fe,
2768
+ getEnvironmentValue: Te,
2769
+ getOSInfo: me,
2770
+ getViewportManager: u,
2771
+ initializeViewportSystem: ot,
2772
+ onAppear: nt,
2773
+ onDisappear: it,
2774
+ setViewportManager: R,
2775
+ useCurrentWindow: Ce,
2776
+ useDismissWindow: x,
2777
+ useEnvironmentDismissWindow: x,
2778
+ useEnvironmentOpenWindow: P,
2779
+ useOpenWindow: P,
2780
+ useViewportEnvironment: v,
2781
+ useViewportInfo: _,
2782
+ useViewportManager: Me,
2783
+ withViewportEnvironment: ke
2784
+ }, Symbol.toStringTag, { value: "Module" }));
2785
+ export {
2786
+ M as App,
2787
+ xe as EnvironmentKeys,
2788
+ $ as ExampleScenes,
2789
+ at as PlatformUtils,
2790
+ A as TachUIViewportManager,
2791
+ st as Viewport,
2792
+ dt as ViewportConstants,
2793
+ B as ViewportEnvironmentProvider,
2794
+ rt as ViewportTypeGuards,
2795
+ D as WebViewportAdapter,
2796
+ y as Window,
2797
+ lt as WindowConfigs,
2798
+ T as WindowGroup,
2799
+ k as WindowUtils,
2800
+ ge as checkFeatureSupport,
2801
+ H as createCapabilityChecker,
2802
+ Pe as createWindowAwareComponent,
2803
+ O as detectViewportEnvironment,
2804
+ Ee as disposeViewportManager,
2805
+ fe as getBrowserInfo,
2806
+ Te as getEnvironmentValue,
2807
+ me as getOSInfo,
2808
+ u as getViewportManager,
2809
+ ot as initializeViewportSystem,
2810
+ nt as onAppear,
2811
+ it as onDisappear,
2812
+ R as setViewportManager,
2813
+ Ce as useCurrentWindow,
2814
+ x as useDismissWindow,
2815
+ x as useEnvironmentDismissWindow,
2816
+ P as useEnvironmentOpenWindow,
2817
+ P as useOpenWindow,
2818
+ v as useViewportEnvironment,
2819
+ _ as useViewportInfo,
2820
+ Me as useViewportManager,
2821
+ ke as withViewportEnvironment
2822
+ };
2823
+ //# sourceMappingURL=index.js.map