@maomaolabs/core 1.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.
@@ -0,0 +1,1042 @@
1
+ "use client";
2
+ import { jsx as i, Fragment as X, jsxs as _ } from "react/jsx-runtime";
3
+ import C, { useSyncExternalStore as ve, useState as $, useRef as z, useEffect as V, memo as Y, useCallback as f, useMemo as D, createContext as ge, useContext as xe } from "react";
4
+ import { createPortal as ie } from "react-dom";
5
+ function wn({ children: e }) {
6
+ return /* @__PURE__ */ i(X, { children: e });
7
+ }
8
+ function ye(e) {
9
+ let t;
10
+ const o = /* @__PURE__ */ new Set(), n = (r, l) => {
11
+ const u = typeof r == "function" ? r(t) : r;
12
+ u !== t && (t = l ? u : Object.assign({}, t, u), o.forEach((d) => d()));
13
+ }, s = () => t, c = (r) => (o.add(r), () => {
14
+ o.delete(r);
15
+ });
16
+ t = e(n, s);
17
+ const a = (r) => {
18
+ const l = ve(c, s, s);
19
+ return r ? r(l) : l;
20
+ };
21
+ return Object.assign(a, {
22
+ getState: s,
23
+ setState: n,
24
+ subscribe: c
25
+ }), a;
26
+ }
27
+ const se = 768, Me = 200, ze = () => typeof window < "u" && window.innerWidth <= se, te = (e, t) => {
28
+ const o = e.find((r) => r.id === t);
29
+ if (!o)
30
+ return e;
31
+ const c = [...[...e].sort((r, l) => (r.zIndex || 0) - (l.zIndex || 0)).filter((r) => r.id !== t), o], a = new Map(c.map((r, l) => [r.id, l + 1]));
32
+ return e.map((r) => ({
33
+ ...r,
34
+ zIndex: a.get(r.id)
35
+ }));
36
+ }, ee = ye((e) => ({
37
+ windows: [],
38
+ snapPreview: null,
39
+ setSnapPreview: (t) => e({ snapPreview: t }),
40
+ openWindow: (t) => {
41
+ e((o) => {
42
+ const n = o.windows;
43
+ if (n.find((h) => h.id === t.id))
44
+ return {
45
+ windows: te(n, t.id).map(
46
+ (x) => x.id === t.id ? { ...x, isMinimized: !1 } : x
47
+ )
48
+ };
49
+ const c = ze(), { initialSize: a, initialPosition: r, ...l } = t, u = t, d = n.length > 0 ? Math.max(...n.map((h) => h.zIndex || 0)) : 0, m = {
50
+ ...l,
51
+ zIndex: d + 1,
52
+ isMinimized: !1,
53
+ isMaximized: c || !!t.isMaximized,
54
+ isSnapped: !!u.isSnapped,
55
+ size: u.size || a || { width: 400, height: 300 },
56
+ position: u.position || r || { x: 50, y: 50 }
57
+ };
58
+ return { windows: [...n, m] };
59
+ });
60
+ },
61
+ closeWindow: (t) => {
62
+ e((o) => ({
63
+ windows: o.windows.filter((n) => n.id !== t)
64
+ }));
65
+ },
66
+ focusWindow: (t) => {
67
+ e((o) => o.windows.some((c) => c.id === t) ? {
68
+ windows: te(o.windows, t).map(
69
+ (c) => c.id === t ? { ...c, isMinimized: !1 } : c
70
+ )
71
+ } : o);
72
+ },
73
+ updateWindow: (t, o) => {
74
+ e((n) => ({
75
+ windows: n.windows.map((s) => s.id === t ? { ...s, ...o } : s)
76
+ }));
77
+ }
78
+ }));
79
+ function re() {
80
+ return ee((e) => ({
81
+ openWindow: e.openWindow,
82
+ closeWindow: e.closeWindow,
83
+ focusWindow: e.focusWindow,
84
+ updateWindow: e.updateWindow
85
+ }));
86
+ }
87
+ function le() {
88
+ return ee((e) => ({
89
+ snapPreview: e.snapPreview,
90
+ setSnapPreview: e.setSnapPreview
91
+ }));
92
+ }
93
+ function ce() {
94
+ return ee((e) => e.windows);
95
+ }
96
+ function we() {
97
+ const [e, t] = $(!1);
98
+ return {
99
+ isOpen: e,
100
+ setIsOpen: t,
101
+ toggleOpen: () => {
102
+ t((n) => !n);
103
+ }
104
+ };
105
+ }
106
+ const Ce = "_container_173at_1", $e = "_menuLeft_173at_29", Ne = "_dockWrapper_173at_43", Le = "_menuRight_173at_55", We = "_dock_173at_43", Te = "_catIcon_173at_103", ke = "_launcher_173at_119", Re = "_folderWrapper_173at_159", Ie = "_folderMenuPortal_173at_173", Se = "_folderMenuPortalVisible_173at_217", Be = "_folderLabel_173at_229", Ee = "_menuContentBase_173at_263", Oe = "_menuContentRight_173at_379 _menuContentBase_173at_263", He = "_menuOpen_173at_389", Ae = "_menuClosed_173at_401", De = "_menuContentLeft_173at_413 _menuContentBase_173at_263", g = {
107
+ container: Ce,
108
+ menuLeft: $e,
109
+ dockWrapper: Ne,
110
+ menuRight: Le,
111
+ dock: We,
112
+ catIcon: Te,
113
+ launcher: ke,
114
+ folderWrapper: Re,
115
+ folderMenuPortal: Ie,
116
+ folderMenuPortalVisible: Se,
117
+ folderLabel: Be,
118
+ menuContentBase: Ee,
119
+ menuContentRight: Oe,
120
+ menuOpen: He,
121
+ menuClosed: Ae,
122
+ menuContentLeft: De
123
+ }, Pe = "_zzzContainer_13qis_1", Fe = "_z_13qis_1", Ve = "_floatZ_13qis_1", J = {
124
+ zzzContainer: Pe,
125
+ z: Fe,
126
+ floatZ: Ve
127
+ };
128
+ function ae({ show: e }) {
129
+ return /* @__PURE__ */ i(X, { children: e && /* @__PURE__ */ _("div", { className: J.zzzContainer, "aria-hidden": "true", children: [
130
+ /* @__PURE__ */ i("span", { className: J.z, children: "z" }),
131
+ /* @__PURE__ */ i("span", { className: J.z, children: "z" }),
132
+ /* @__PURE__ */ i("span", { className: J.z, children: "z" })
133
+ ] }) });
134
+ }
135
+ const je = "_buttonWrapper_1hhpx_1", qe = "_button_1hhpx_1", Ze = "_activeIndicator_1hhpx_61", Xe = "_preview_1hhpx_85", Ye = "_fadeIn_1hhpx_1", Ge = "_previewHeader_1hhpx_125", Ke = "_previewTitle_1hhpx_143", Je = "_previewClose_1hhpx_163", Qe = "_previewBody_1hhpx_203", Ue = "_previewContent_1hhpx_231", et = "_labelTooltip_1hhpx_255", tt = "_fadeInLabel_1hhpx_1", B = {
136
+ buttonWrapper: je,
137
+ button: qe,
138
+ activeIndicator: Ze,
139
+ preview: Xe,
140
+ fadeIn: Ye,
141
+ previewHeader: Ge,
142
+ previewTitle: Ke,
143
+ previewClose: Je,
144
+ previewBody: Qe,
145
+ previewContent: Ue,
146
+ labelTooltip: et,
147
+ fadeInLabel: tt
148
+ };
149
+ function nt({ windowId: e }) {
150
+ const t = z(null);
151
+ return V(() => {
152
+ const o = t.current;
153
+ if (!o)
154
+ return;
155
+ const n = ot(e);
156
+ if (!n) {
157
+ o.replaceChildren();
158
+ return;
159
+ }
160
+ const s = it(n);
161
+ o.replaceChildren(s);
162
+ }, [e]), /* @__PURE__ */ i("div", { ref: t, className: "window-preview-container" });
163
+ }
164
+ function ot(e) {
165
+ const t = document.getElementById(`window-${e}`);
166
+ return t instanceof HTMLElement ? t : null;
167
+ }
168
+ function it(e) {
169
+ const t = e.cloneNode(!0);
170
+ return st(t), t;
171
+ }
172
+ function st(e) {
173
+ e.removeAttribute("id"), e.querySelectorAll("[id]").forEach((o) => o.removeAttribute("id")), rt(e);
174
+ const t = e.querySelector(".window-scrollbar");
175
+ t && t.style.setProperty("display", "flex", "important");
176
+ }
177
+ function rt(e) {
178
+ const t = {
179
+ display: "flex",
180
+ position: "static",
181
+ transform: "none",
182
+ opacity: "1",
183
+ width: "100%",
184
+ height: "100%",
185
+ minHeight: "0",
186
+ visibility: "visible",
187
+ zIndex: "auto",
188
+ boxShadow: "none"
189
+ };
190
+ for (const [o, n] of Object.entries(t))
191
+ e.style.setProperty(o, n, "important");
192
+ }
193
+ const lt = "_controls_1014q_1", ct = "_button_1014q_13", at = "_close_1014q_59", Z = {
194
+ controls: lt,
195
+ button: ct,
196
+ close: at
197
+ }, dt = () => /* @__PURE__ */ _("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
198
+ /* @__PURE__ */ i("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
199
+ /* @__PURE__ */ i("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
200
+ ] });
201
+ function de({ onClose: e, disabled: t }) {
202
+ return /* @__PURE__ */ i(
203
+ "button",
204
+ {
205
+ className: `terminal-btn close ${Z.button} ${Z.close}`,
206
+ onClick: e,
207
+ disabled: t,
208
+ title: "Close",
209
+ children: /* @__PURE__ */ i(dt, {})
210
+ }
211
+ );
212
+ }
213
+ function ut({ icon: e, onClick: t, label: o, isActive: n, onClose: s, component: c, windowId: a, showTooltip: r = !0 }) {
214
+ const [l, u] = $(!1), d = z(null), m = z(null), h = () => {
215
+ m.current && (clearTimeout(m.current), m.current = null), u(!0);
216
+ }, x = () => {
217
+ m.current = setTimeout(() => {
218
+ u(!1);
219
+ }, 100);
220
+ };
221
+ return /* @__PURE__ */ _(
222
+ "div",
223
+ {
224
+ ref: d,
225
+ className: B.buttonWrapper,
226
+ onMouseEnter: h,
227
+ onMouseLeave: x,
228
+ children: [
229
+ l && typeof document < "u" && ie(
230
+ n && s ? /* @__PURE__ */ _(
231
+ "div",
232
+ {
233
+ className: B.preview,
234
+ style: {
235
+ left: d.current ? d.current.getBoundingClientRect().left + d.current.getBoundingClientRect().width / 2 : 0,
236
+ top: d.current ? d.current.getBoundingClientRect().top : 0
237
+ },
238
+ onMouseEnter: h,
239
+ onMouseLeave: x,
240
+ children: [
241
+ /* @__PURE__ */ _("div", { className: B.previewHeader, children: [
242
+ /* @__PURE__ */ i("span", { className: B.previewTitle, children: o }),
243
+ /* @__PURE__ */ i(
244
+ de,
245
+ {
246
+ onClose: (p) => {
247
+ p == null || p.preventDefault(), p == null || p.stopPropagation(), s();
248
+ }
249
+ }
250
+ )
251
+ ] }),
252
+ /* @__PURE__ */ i("div", { className: B.previewBody, onClick: (p) => {
253
+ p.stopPropagation(), t();
254
+ }, children: /* @__PURE__ */ i("div", { className: B.previewContent, children: a ? /* @__PURE__ */ i(nt, { windowId: a }) : c }) })
255
+ ]
256
+ }
257
+ ) : r ? /* @__PURE__ */ i(
258
+ "div",
259
+ {
260
+ className: B.labelTooltip,
261
+ style: {
262
+ left: d.current ? d.current.getBoundingClientRect().left + d.current.getBoundingClientRect().width / 2 : 0,
263
+ top: d.current ? d.current.getBoundingClientRect().top : 0
264
+ },
265
+ children: o
266
+ }
267
+ ) : null,
268
+ document.body
269
+ ),
270
+ /* @__PURE__ */ _(
271
+ "button",
272
+ {
273
+ onClick: t,
274
+ "aria-label": o,
275
+ className: B.button,
276
+ children: [
277
+ e,
278
+ n && /* @__PURE__ */ i("div", { className: B.activeIndicator })
279
+ ]
280
+ }
281
+ )
282
+ ]
283
+ }
284
+ );
285
+ }
286
+ const mt = C.memo(ut), G = mt, ue = Y(({ window: e, currentWindows: t, openWindow: o }) => {
287
+ const n = t.some((c) => c.id === e.id), s = f(() => o(e), [o, e]);
288
+ return /* @__PURE__ */ i(
289
+ G,
290
+ {
291
+ icon: e.icon,
292
+ label: e.title,
293
+ onClick: s,
294
+ isActive: n
295
+ }
296
+ );
297
+ }), me = () => /* @__PURE__ */ i("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ i("path", { d: "M4 20h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.93a2 2 0 0 1-1.66-.9l-.82-1.2A2 2 0 0 0 7.93 2H4a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2Z" }) }), ht = Y(({ folder: e, currentWindows: t, openWindow: o }) => {
298
+ const [n, s] = $(!1), [c, a] = $(!1), [r, l] = $(!1), [u, d] = $(null), m = z(null), h = z(null);
299
+ V(() => {
300
+ if (n) {
301
+ if (m.current) {
302
+ const b = m.current.getBoundingClientRect();
303
+ d({
304
+ left: b.left + b.width / 2,
305
+ bottom: window.innerHeight - b.top + 10
306
+ });
307
+ }
308
+ a(!0), requestAnimationFrame(() => l(!0));
309
+ } else {
310
+ l(!1);
311
+ const b = setTimeout(() => {
312
+ a(!1);
313
+ }, 200);
314
+ return () => clearTimeout(b);
315
+ }
316
+ }, [n]);
317
+ const x = f(() => {
318
+ h.current && (clearTimeout(h.current), h.current = null), s(!0);
319
+ }, []), p = f(() => {
320
+ h.current = setTimeout(() => {
321
+ s(!1);
322
+ }, 200);
323
+ }, []);
324
+ return /* @__PURE__ */ _(
325
+ "div",
326
+ {
327
+ ref: m,
328
+ className: g.folderWrapper,
329
+ onMouseEnter: x,
330
+ onMouseLeave: p,
331
+ children: [
332
+ c && u && typeof document < "u" && ie(
333
+ /* @__PURE__ */ _(
334
+ "div",
335
+ {
336
+ className: `${g.folderMenuPortal} ${r ? g.folderMenuPortalVisible : ""}`,
337
+ style: {
338
+ left: u.left,
339
+ bottom: u.bottom
340
+ },
341
+ onMouseEnter: x,
342
+ onMouseLeave: p,
343
+ children: [
344
+ e.apps.map((b) => /* @__PURE__ */ i(
345
+ ue,
346
+ {
347
+ window: b,
348
+ currentWindows: t,
349
+ openWindow: o
350
+ },
351
+ b.id
352
+ )),
353
+ /* @__PURE__ */ i("div", { className: g.folderLabel, children: e.title })
354
+ ]
355
+ }
356
+ ),
357
+ document.body
358
+ ),
359
+ /* @__PURE__ */ i(
360
+ G,
361
+ {
362
+ icon: e.icon || /* @__PURE__ */ i(me, {}),
363
+ label: e.title,
364
+ onClick: () => s((b) => !b),
365
+ isActive: !1,
366
+ showTooltip: !1
367
+ }
368
+ )
369
+ ]
370
+ }
371
+ );
372
+ }), ft = Y(({ window: e, currentWindows: t, openWindow: o, closeWindow: n }) => {
373
+ const s = t.some((r) => r.id === e.id), c = f(() => o({ ...e, zIndex: 0, layer: e.layer || "normal" }), [o, e]), a = f(() => n(e.id), [n, e.id]);
374
+ return /* @__PURE__ */ i(
375
+ G,
376
+ {
377
+ icon: e.icon,
378
+ label: e.title,
379
+ onClick: c,
380
+ isActive: s,
381
+ onClose: a,
382
+ component: e.component,
383
+ windowId: e.id
384
+ }
385
+ );
386
+ });
387
+ function _t(e) {
388
+ return "apps" in e;
389
+ }
390
+ function he(e, t) {
391
+ const o = D(() => Array.isArray(e) ? e : [], [e]);
392
+ return D(() => o, [o]), {
393
+ windowsOptions: o,
394
+ isFolder: _t
395
+ };
396
+ }
397
+ const U = {
398
+ idle: `/\\_/\\
399
+ ( -.- )
400
+ > ^ <`,
401
+ active: `/\\_/\\
402
+ ( >.< )
403
+ > ^ <`,
404
+ open: `/\\_/\\
405
+ ( ^.^ )
406
+ > ^ <`
407
+ };
408
+ function pt({
409
+ openWindow: e,
410
+ closeWindow: t,
411
+ toolbarItems: o = [],
412
+ currentWindows: n,
413
+ isOpen: s,
414
+ toggleOpen: c,
415
+ setIsOpen: a,
416
+ showLogo: r = !0
417
+ }) {
418
+ const l = C.useRef(null), { windowsOptions: u, isFolder: d } = he(o), m = s ? U.open : n.length > 0 ? U.active : U.idle, h = () => {
419
+ l.current && (clearTimeout(l.current), l.current = null);
420
+ }, x = () => {
421
+ h(), a(!0);
422
+ }, p = () => {
423
+ h();
424
+ }, b = () => {
425
+ l.current = setTimeout(() => {
426
+ a(!1);
427
+ }, 100);
428
+ };
429
+ return C.useEffect(() => () => {
430
+ l.current && clearTimeout(l.current);
431
+ }, []), /* @__PURE__ */ _(
432
+ "div",
433
+ {
434
+ className: g.container,
435
+ role: "toolbar",
436
+ "aria-label": "Desktop Toolbar",
437
+ children: [
438
+ /* @__PURE__ */ i("div", { className: `${g.menuLeft} ${n.length > 0 ? g.menuOpen : g.menuClosed}`, children: /* @__PURE__ */ i("div", { className: g.menuContentLeft, children: n.map((y) => /* @__PURE__ */ i(
439
+ ft,
440
+ {
441
+ window: y,
442
+ currentWindows: n,
443
+ openWindow: e,
444
+ closeWindow: t
445
+ },
446
+ y.id
447
+ )) }) }),
448
+ /* @__PURE__ */ i(
449
+ "div",
450
+ {
451
+ className: g.dockWrapper,
452
+ onMouseEnter: x,
453
+ onMouseLeave: b,
454
+ children: /* @__PURE__ */ i("div", { className: g.dock, children: /* @__PURE__ */ _(
455
+ "button",
456
+ {
457
+ className: g.launcher,
458
+ onClick: c,
459
+ "aria-label": s ? "Close Menu" : "Open Menu",
460
+ "aria-expanded": s,
461
+ children: [
462
+ r && /* @__PURE__ */ _(X, { children: [
463
+ /* @__PURE__ */ i(ae, { show: !s && n.length === 0 }),
464
+ /* @__PURE__ */ i("span", { className: `${g.catIcon}`, children: m })
465
+ ] }),
466
+ !r && /* @__PURE__ */ i("span", { className: g.catIcon, style: { fontSize: "1.5rem" }, children: "🪟" })
467
+ ]
468
+ }
469
+ ) })
470
+ }
471
+ ),
472
+ /* @__PURE__ */ i(
473
+ "div",
474
+ {
475
+ className: `${g.menuRight} ${s ? g.menuOpen : g.menuClosed}`,
476
+ onMouseEnter: p,
477
+ onMouseLeave: b,
478
+ children: /* @__PURE__ */ i("div", { className: g.menuContentRight, children: u.map((y, T) => d(y) ? /* @__PURE__ */ i(
479
+ ht,
480
+ {
481
+ folder: y,
482
+ currentWindows: n,
483
+ openWindow: e
484
+ },
485
+ y.id ?? T
486
+ ) : n.some((N) => N.id === y.id) ? null : /* @__PURE__ */ i(
487
+ ue,
488
+ {
489
+ window: y,
490
+ currentWindows: n,
491
+ openWindow: e
492
+ },
493
+ y.id
494
+ )) })
495
+ }
496
+ )
497
+ ]
498
+ }
499
+ );
500
+ }
501
+ const bt = "_desktopOnly_ec5se_1", vt = "_mobileOnly_ec5se_9", gt = "_icon_ec5se_17", ne = {
502
+ desktopOnly: bt,
503
+ mobileOnly: vt,
504
+ icon: gt
505
+ }, xt = "_pawButton_n7khn_1", yt = "_mobileItems_n7khn_57", Mt = "_mobileItemsVisible_n7khn_103", zt = "_mobileIcon_n7khn_115", wt = "_folderContainer_n7khn_191", Ct = "_folderHeader_n7khn_203", $t = "_folderContent_n7khn_213", O = {
506
+ pawButton: xt,
507
+ mobileItems: yt,
508
+ mobileItemsVisible: Mt,
509
+ mobileIcon: zt,
510
+ folderContainer: wt,
511
+ folderHeader: Ct,
512
+ folderContent: $t
513
+ }, fe = Y(({ window: e, currentWindows: t, openWindow: o, closeMenu: n }) => {
514
+ const s = t.some((a) => a.id === e.id), c = f(() => {
515
+ o(e), n();
516
+ }, [o, e, n]);
517
+ return /* @__PURE__ */ i(
518
+ G,
519
+ {
520
+ icon: e.icon,
521
+ label: e.title,
522
+ onClick: c,
523
+ isActive: s,
524
+ showTooltip: !1
525
+ }
526
+ );
527
+ }), Nt = Y(({ folder: e, currentWindows: t, openWindow: o, closeMenu: n }) => {
528
+ const [s, c] = $(!1);
529
+ return /* @__PURE__ */ _("div", { className: O.folderContainer, children: [
530
+ /* @__PURE__ */ i("div", { className: O.folderHeader, children: /* @__PURE__ */ i(
531
+ G,
532
+ {
533
+ icon: e.icon || /* @__PURE__ */ i(me, {}),
534
+ label: e.title,
535
+ onClick: () => c((a) => !a),
536
+ isActive: s,
537
+ showTooltip: !1
538
+ }
539
+ ) }),
540
+ s && /* @__PURE__ */ i("div", { className: O.folderContent, children: e.apps.map((a) => /* @__PURE__ */ i(
541
+ fe,
542
+ {
543
+ window: a,
544
+ currentWindows: t,
545
+ openWindow: o,
546
+ closeMenu: n
547
+ },
548
+ a.id
549
+ )) })
550
+ ] });
551
+ }), oe = {
552
+ IDLE: `/\\_/\\
553
+ ( -.- )`,
554
+ OPEN: `/\\_/\\
555
+ ( ^.^ )`
556
+ };
557
+ function Lt({
558
+ openWindow: e,
559
+ toolbarItems: t,
560
+ currentWindows: o,
561
+ isOpen: n,
562
+ toggleOpen: s,
563
+ setIsOpen: c
564
+ }) {
565
+ const { windowsOptions: a, isFolder: r } = he(t), l = n ? oe.OPEN : oe.IDLE, u = () => c(!1);
566
+ return /* @__PURE__ */ _("div", { className: ne.mobileOnly, children: [
567
+ /* @__PURE__ */ i("div", { className: `${O.mobileItems} ${n ? O.mobileItemsVisible : ""}`, children: a.length === 0 ? /* @__PURE__ */ i("span", { children: "No apps available" }) : a.map((d, m) => r(d) ? /* @__PURE__ */ i(
568
+ Nt,
569
+ {
570
+ folder: d,
571
+ currentWindows: o,
572
+ openWindow: e,
573
+ closeMenu: u
574
+ },
575
+ d.id || m
576
+ ) : /* @__PURE__ */ i(
577
+ fe,
578
+ {
579
+ window: d,
580
+ currentWindows: o,
581
+ openWindow: e,
582
+ closeMenu: u
583
+ },
584
+ d.id
585
+ )) }),
586
+ /* @__PURE__ */ _(
587
+ "button",
588
+ {
589
+ className: `${O.pawButton} ${n ? O.pawButtonActive : ""}`,
590
+ onClick: s,
591
+ children: [
592
+ /* @__PURE__ */ i(ae, { show: !n }),
593
+ /* @__PURE__ */ i("span", { className: `${ne.icon} ${O.mobileIcon}`, children: l })
594
+ ]
595
+ }
596
+ )
597
+ ] });
598
+ }
599
+ function _e(e = 768) {
600
+ const [t, o] = $(!1);
601
+ return V(() => {
602
+ const n = window.matchMedia(`(max-width: ${e}px)`), s = () => o(n.matches);
603
+ return s(), n.addEventListener("change", s), () => n.removeEventListener("change", s);
604
+ }, [e]), t;
605
+ }
606
+ function Cn({ toolbarItems: e, ...t }) {
607
+ const { openWindow: o, closeWindow: n } = re(), s = ce(), { isOpen: c, toggleOpen: a, setIsOpen: r } = we(), l = _e();
608
+ return /* @__PURE__ */ i(X, { children: l ? /* @__PURE__ */ i(
609
+ Lt,
610
+ {
611
+ openWindow: o,
612
+ toolbarItems: e,
613
+ currentWindows: s,
614
+ isOpen: c,
615
+ toggleOpen: a,
616
+ setIsOpen: r
617
+ }
618
+ ) : /* @__PURE__ */ i(
619
+ pt,
620
+ {
621
+ openWindow: o,
622
+ closeWindow: n,
623
+ toolbarItems: e,
624
+ currentWindows: s,
625
+ isOpen: c,
626
+ toggleOpen: a,
627
+ setIsOpen: r,
628
+ showLogo: t.showLogo
629
+ }
630
+ ) });
631
+ }
632
+ const pe = ge(null), Wt = () => {
633
+ const e = xe(pe);
634
+ if (!e)
635
+ throw new Error("useWindowUI must be used within Window (WindowContext.Provider)");
636
+ return e;
637
+ }, Tt = 300, kt = 42, Rt = { width: 500, height: 300 }, It = { x: 100, y: 100 }, F = 20;
638
+ function St(e, t, o, n, s) {
639
+ const c = z(!1), a = z({ x: 0, y: 0 }), r = f((d) => {
640
+ if (!c.current)
641
+ return;
642
+ s == null || s(d.clientX, d.clientY);
643
+ const m = Math.min(
644
+ Math.max(0, d.clientX - a.current.x),
645
+ window.innerWidth - e.width
646
+ ), h = Math.min(
647
+ Math.max(0, d.clientY - a.current.y),
648
+ window.innerHeight - e.height
649
+ );
650
+ o.current && (o.current.style.left = `${m}px`, o.current.style.top = `${h}px`), n({ x: m, y: h });
651
+ }, [e, n, s]), l = f((d) => {
652
+ var m;
653
+ (m = window.getSelection()) == null || m.removeAllRanges(), document.body.style.userSelect = "none", a.current = {
654
+ x: d.clientX - t.x,
655
+ y: d.clientY - t.y
656
+ }, c.current = !0;
657
+ }, [t.x, t.y]), u = f(() => {
658
+ c.current = !1, document.body.style.userSelect = "auto";
659
+ }, []);
660
+ return D(() => ({
661
+ dragTo: r,
662
+ startDrag: l,
663
+ stopDrag: u,
664
+ isDragging: c
665
+ }), [r, l, u]);
666
+ }
667
+ function Bt(e, t, o) {
668
+ const n = z(!1), s = z({ x: 0, y: 0, w: 0, h: 0 }), c = f((l) => {
669
+ if (!n.current)
670
+ return;
671
+ const u = Math.min(window.innerWidth, Math.max(Tt, s.current.w + l.clientX - s.current.x)), d = Math.min(window.innerHeight, Math.max(kt, s.current.h + l.clientY - s.current.y));
672
+ t.current && (t.current.style.width = `${u}px`, t.current.style.height = `${d}px`), o({ width: u, height: d });
673
+ }, [o]), a = f((l) => {
674
+ var u;
675
+ (u = window.getSelection()) == null || u.removeAllRanges(), document.body.style.userSelect = "none", s.current = { x: l.clientX, y: l.clientY, w: e.width, h: e.height }, n.current = !0;
676
+ }, [e.width, e.height]), r = f(() => {
677
+ n.current = !1, document.body.style.userSelect = "auto";
678
+ }, []);
679
+ return D(() => ({
680
+ resizeTo: c,
681
+ startResize: a,
682
+ stopResize: r,
683
+ isResizing: n
684
+ }), [c, a, r]);
685
+ }
686
+ function Et(e) {
687
+ const t = z(null), o = f((s, c) => {
688
+ const a = window.innerWidth, r = window.innerHeight;
689
+ let l = null;
690
+ s < F ? c < F ? l = "top-left" : c > r - F ? l = "bottom-left" : l = "left" : s > a - F && (c < F ? l = "top-right" : c > r - F ? l = "bottom-right" : l = "right"), l !== t.current && (t.current = l, e == null || e(l ? { side: l } : null));
691
+ }, [e]), n = f(() => {
692
+ t.current = null, e == null || e(null);
693
+ }, [e]);
694
+ return D(() => ({ currentSide: t, detectSnap: o, resetSnap: n }), [o, n]);
695
+ }
696
+ function Ot({
697
+ initialSize: e = Rt,
698
+ initialPosition: t = It,
699
+ isSnapped: o,
700
+ onSnap: n,
701
+ onUnsnap: s,
702
+ setSnapPreview: c,
703
+ onPositionChange: a,
704
+ onSizeChange: r
705
+ }) {
706
+ const [l, u] = $(e), [d, m] = $(t), [h, x] = $(!1), [p, b] = $(!1), y = z(e), T = z(t), N = z(null), E = f((w) => {
707
+ T.current = w;
708
+ }, []), H = f((w) => {
709
+ y.current = w;
710
+ }, []);
711
+ V(() => {
712
+ u(e), H(e);
713
+ }, [e, H]), V(() => {
714
+ m(t), E(t);
715
+ }, [t, E]);
716
+ const k = Et(c), R = St(l, d, N, E, k.detectSnap), L = Bt(l, N, H), P = f((w) => {
717
+ x(!0), R.startDrag(w);
718
+ }, [R]), K = f((w) => {
719
+ b(!0), L.startResize(w);
720
+ }, [L]);
721
+ return V(() => {
722
+ if (!h && !p)
723
+ return;
724
+ const w = (S) => {
725
+ R.dragTo(S), L.resizeTo(S);
726
+ }, I = () => {
727
+ if (R.isDragging.current) {
728
+ const S = T.current.x !== d.x || T.current.y !== d.y;
729
+ m(T.current), k.currentSide.current && n ? (n(k.currentSide.current), k.resetSnap()) : S && (o && (s == null || s()), a == null || a(T.current)), R.stopDrag(), x(!1);
730
+ }
731
+ L.isResizing.current && (u(y.current), r == null || r(y.current), o && (s == null || s()), L.stopResize(), b(!1));
732
+ };
733
+ return window.addEventListener("mousemove", w), window.addEventListener("mouseup", I), () => {
734
+ window.removeEventListener("mousemove", w), window.removeEventListener("mouseup", I);
735
+ };
736
+ }, [R, L, n, s, o, k, a, r, h, p]), D(() => ({
737
+ size: l,
738
+ position: d,
739
+ windowRef: N,
740
+ drag: P,
741
+ resize: K,
742
+ isDragging: h,
743
+ isResizing: p
744
+ }), [l, d, h, p, P, K]);
745
+ }
746
+ const Ht = () => /* @__PURE__ */ i("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ i("rect", { x: "3", y: "3", width: "18", height: "18", rx: "2", ry: "2" }) }), At = () => /* @__PURE__ */ _("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
747
+ /* @__PURE__ */ i("rect", { x: "5", y: "9", width: "14", height: "14", rx: "2", ry: "2" }),
748
+ /* @__PURE__ */ i("path", { d: "M9 5h10a2 2 0 0 1 2 2v10" })
749
+ ] });
750
+ function Dt({ onClick: e, isMaximized: t, disabled: o }) {
751
+ return /* @__PURE__ */ i(
752
+ "button",
753
+ {
754
+ className: `terminal-btn ${Z.button}`,
755
+ onClick: () => {
756
+ e();
757
+ },
758
+ disabled: o,
759
+ title: t ? "Restore" : "Maximize",
760
+ children: t ? /* @__PURE__ */ i(At, {}) : /* @__PURE__ */ i(Ht, {})
761
+ }
762
+ );
763
+ }
764
+ const Pt = () => /* @__PURE__ */ i("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ i("line", { x1: "5", y1: "12", x2: "19", y2: "12" }) });
765
+ function Ft({ onClick: e, isMinimized: t, disabled: o }) {
766
+ return /* @__PURE__ */ i(
767
+ "button",
768
+ {
769
+ className: `terminal-btn ${Z.button}`,
770
+ onClick: () => {
771
+ e();
772
+ },
773
+ disabled: o || t,
774
+ title: t ? "Restore" : "Minimize",
775
+ children: /* @__PURE__ */ i(Pt, {})
776
+ }
777
+ );
778
+ }
779
+ const Vt = "_container_m621b_1", jt = "_header_m621b_27", qt = "_body_m621b_57", Zt = "_resizeHandle_m621b_73", Xt = "_content_m621b_93", Yt = "_scrollbar_m621b_181", Gt = "_transition_m621b_225", Kt = "_focused_m621b_247", Jt = "_maximized_m621b_261", Qt = "_minimized_m621b_279", Ut = "_visible_m621b_287", en = "_hidden_m621b_297", tn = "_scrollbarX_m621b_351", W = {
780
+ container: Vt,
781
+ header: jt,
782
+ body: qt,
783
+ resizeHandle: Zt,
784
+ content: Xt,
785
+ scrollbar: Yt,
786
+ transition: Gt,
787
+ focused: Kt,
788
+ maximized: Jt,
789
+ minimized: Qt,
790
+ visible: Ut,
791
+ hidden: en,
792
+ scrollbarX: tn
793
+ }, nn = "_title_tn8yk_1", on = "_brandText_tn8yk_25", sn = "_windowIcon_tn8yk_35", Q = {
794
+ title: nn,
795
+ brandText: on,
796
+ windowIcon: sn
797
+ };
798
+ function rn({ onClose: e, title: t, icon: o, canMinimize: n, canMaximize: s, canClose: c }) {
799
+ const {
800
+ drag: a,
801
+ isMaximized: r,
802
+ isMinimized: l,
803
+ minimize: u,
804
+ maximize: d,
805
+ restore: m
806
+ } = Wt(), h = _e(se);
807
+ return /* @__PURE__ */ _(
808
+ "div",
809
+ {
810
+ className: `window-header ${W.header}`,
811
+ onMouseDown: a,
812
+ children: [
813
+ /* @__PURE__ */ _("span", { className: `window-title ${Q.title}`, children: [
814
+ o && /* @__PURE__ */ i("span", { className: `window-icon ${Q.windowIcon} ${Q.brandText}`, children: o }),
815
+ /* @__PURE__ */ i("span", { className: `brand-text ${Q.brandText}`, children: t })
816
+ ] }),
817
+ /* @__PURE__ */ _("div", { className: `window-controls ${Z.controls}`, children: [
818
+ /* @__PURE__ */ i(Ft, { onClick: u, isMinimized: l, disabled: n === !1 }),
819
+ /* @__PURE__ */ i(Dt, { onClick: r ? m : d, isMaximized: r, disabled: s === !1 || h }),
820
+ /* @__PURE__ */ i(de, { onClose: e, disabled: c === !1 })
821
+ ] })
822
+ ]
823
+ }
824
+ );
825
+ }
826
+ const ln = ({ window: e }) => {
827
+ const { closeWindow: t, focusWindow: o, updateWindow: n } = re(), { setSnapPreview: s } = le(), [c, a] = C.useState(!1), [r, l] = C.useState(!1), u = C.useRef(null);
828
+ C.useEffect(() => {
829
+ let M;
830
+ return M = requestAnimationFrame(() => a(!0)), () => {
831
+ cancelAnimationFrame(M), u.current && clearTimeout(u.current);
832
+ };
833
+ }, []);
834
+ const d = f(() => {
835
+ l(!0), u.current = setTimeout(() => {
836
+ t(e.id);
837
+ }, Me);
838
+ }, [t, e.id]), m = f(() => {
839
+ n(e.id, { isMinimized: !0 });
840
+ }, [n, e.id]), h = f(() => {
841
+ n(e.id, { isMaximized: !0, isMinimized: !1, isSnapped: !1 });
842
+ }, [n, e.id]), x = f(() => {
843
+ n(e.id, { isMinimized: !1, isMaximized: !1, isSnapped: !1 });
844
+ }, [n, e.id]), p = C.useCallback((M) => {
845
+ let be = window.innerWidth / 2, j = window.innerHeight, A = 0, q = 0;
846
+ M === "left" ? A = 0 : M === "right" ? A = window.innerWidth / 2 : M === "top-left" ? (j = window.innerHeight / 2, A = 0, q = 0) : M === "top-right" ? (j = window.innerHeight / 2, A = window.innerWidth / 2, q = 0) : M === "bottom-left" ? (j = window.innerHeight / 2, A = 0, q = window.innerHeight / 2) : M === "bottom-right" && (j = window.innerHeight / 2, A = window.innerWidth / 2, q = window.innerHeight / 2), n(e.id, {
847
+ isSnapped: !0,
848
+ isMaximized: !1,
849
+ isMinimized: !1,
850
+ size: { width: be, height: j },
851
+ position: { x: A, y: q }
852
+ });
853
+ }, [n, e.id]), b = C.useCallback(() => {
854
+ n(e.id, { isSnapped: !1 });
855
+ }, [n, e.id]), y = C.useCallback((M) => {
856
+ n(e.id, { position: M });
857
+ }, [n, e.id]), T = C.useCallback((M) => {
858
+ n(e.id, { size: M });
859
+ }, [n, e.id]), {
860
+ size: N,
861
+ position: E,
862
+ isDragging: H,
863
+ isResizing: k,
864
+ drag: R,
865
+ resize: L,
866
+ windowRef: P
867
+ } = Ot({
868
+ initialSize: e.size,
869
+ initialPosition: e.position,
870
+ isMinimized: e.isMinimized || !1,
871
+ isMaximized: e.isMaximized || !1,
872
+ isSnapped: e.isSnapped || !1,
873
+ onSnap: p,
874
+ onUnsnap: b,
875
+ setSnapPreview: s,
876
+ onPositionChange: y,
877
+ onSizeChange: T
878
+ }), K = D(() => ({
879
+ size: N,
880
+ position: E,
881
+ isDragging: H,
882
+ isResizing: k,
883
+ drag: R,
884
+ resize: L,
885
+ windowRef: P,
886
+ isMinimized: e.isMinimized || !1,
887
+ isMaximized: e.isMaximized || !1,
888
+ isSnapped: e.isSnapped || !1,
889
+ minimize: m,
890
+ maximize: h,
891
+ restore: x
892
+ }), [N, E, H, k, R, L, P, e.isMinimized, e.isMaximized, e.isSnapped, m, h, x]), w = c && !r && !e.isMinimized, I = e.isMaximized, S = e.isMinimized;
893
+ return /* @__PURE__ */ i(pe.Provider, { value: K, children: /* @__PURE__ */ _(
894
+ "div",
895
+ {
896
+ ref: P,
897
+ id: `window-${e.id}`,
898
+ role: "dialog",
899
+ "aria-label": e.title,
900
+ "aria-modal": "false",
901
+ tabIndex: -1,
902
+ className: `window-container
903
+ ${W.container}
904
+ ${!H && !k ? `${W.transition} window-transition` : ""}
905
+ ${w ? W.visible : W.hidden}
906
+ ${I ? W.maximized : ""}
907
+ ${S ? W.minimized : ""}
908
+ `,
909
+ style: {
910
+ width: I ? void 0 : N.width,
911
+ height: S || I ? void 0 : N.height,
912
+ left: I ? void 0 : E.x,
913
+ top: I ? void 0 : E.y,
914
+ zIndex: e.zIndex,
915
+ display: "flex",
916
+ pointerEvents: S ? "none" : "auto"
917
+ },
918
+ onMouseDown: () => o(e.id),
919
+ children: [
920
+ /* @__PURE__ */ i(
921
+ rn,
922
+ {
923
+ onClose: d,
924
+ title: e.title,
925
+ icon: e.icon,
926
+ canClose: e.canClose,
927
+ canMinimize: e.canMinimize,
928
+ canMaximize: e.canMaximize
929
+ }
930
+ ),
931
+ /* @__PURE__ */ i(
932
+ "div",
933
+ {
934
+ className: `window-scrollbar ${W.scrollbar} ${W.content}`,
935
+ style: { display: S ? "none" : "flex" },
936
+ children: e.component
937
+ }
938
+ ),
939
+ !I && /* @__PURE__ */ i(
940
+ "div",
941
+ {
942
+ className: `window-resize-handle ${W.resizeHandle}`,
943
+ onMouseDown: L
944
+ }
945
+ )
946
+ ]
947
+ }
948
+ ) });
949
+ }, cn = C.memo(ln), an = "_overlay_16s5n_1", dn = "_overlayCorner_16s5n_37", un = "_visible_16s5n_69", mn = "_left_16s5n_89", hn = "_right_16s5n_101", fn = "_topLeft_16s5n_113", _n = "_topRight_16s5n_129", pn = "_bottomLeft_16s5n_145", bn = "_bottomRight_16s5n_161", v = {
950
+ overlay: an,
951
+ overlayCorner: dn,
952
+ visible: un,
953
+ left: mn,
954
+ right: hn,
955
+ topLeft: fn,
956
+ topRight: _n,
957
+ bottomLeft: pn,
958
+ bottomRight: bn
959
+ };
960
+ function vn({ side: e }) {
961
+ return e ? /* @__PURE__ */ _(X, { children: [
962
+ /* @__PURE__ */ i(
963
+ "div",
964
+ {
965
+ className: `
966
+ ${v.overlay}
967
+ ${v.left}
968
+ ${e === "left" ? v.visible : ""}
969
+ `
970
+ }
971
+ ),
972
+ /* @__PURE__ */ i(
973
+ "div",
974
+ {
975
+ className: `
976
+ ${v.overlay}
977
+ ${v.right}
978
+ ${e === "right" ? v.visible : ""}
979
+ `
980
+ }
981
+ ),
982
+ /* @__PURE__ */ i(
983
+ "div",
984
+ {
985
+ className: `
986
+ ${v.overlayCorner}
987
+ ${v.topLeft}
988
+ ${e === "top-left" ? v.visible : ""}
989
+ `
990
+ }
991
+ ),
992
+ /* @__PURE__ */ i(
993
+ "div",
994
+ {
995
+ className: `
996
+ ${v.overlayCorner}
997
+ ${v.topRight}
998
+ ${e === "top-right" ? v.visible : ""}
999
+ `
1000
+ }
1001
+ ),
1002
+ /* @__PURE__ */ i(
1003
+ "div",
1004
+ {
1005
+ className: `
1006
+ ${v.overlayCorner}
1007
+ ${v.bottomLeft}
1008
+ ${e === "bottom-left" ? v.visible : ""}
1009
+ `
1010
+ }
1011
+ ),
1012
+ /* @__PURE__ */ i(
1013
+ "div",
1014
+ {
1015
+ className: `
1016
+ ${v.overlayCorner}
1017
+ ${v.bottomRight}
1018
+ ${e === "bottom-right" ? v.visible : ""}
1019
+ `
1020
+ }
1021
+ )
1022
+ ] }) : null;
1023
+ }
1024
+ const gn = "_manager_1t6jq_1", xn = {
1025
+ manager: gn
1026
+ };
1027
+ function $n() {
1028
+ const e = ce(), { snapPreview: t } = le();
1029
+ return /* @__PURE__ */ _("div", { className: xn.manager, children: [
1030
+ /* @__PURE__ */ i(vn, { side: t ? t.side : null }),
1031
+ e.map((o) => /* @__PURE__ */ i(cn, { window: o }, o.id))
1032
+ ] });
1033
+ }
1034
+ export {
1035
+ Cn as Toolbar,
1036
+ cn as Window,
1037
+ $n as WindowManager,
1038
+ wn as WindowSystemProvider,
1039
+ re as useWindowActions,
1040
+ le as useWindowSnap,
1041
+ ce as useWindows
1042
+ };