react-panel-layout 0.4.2 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/dist/FloatingPanelFrame-6W5OexYe.js +98 -0
  2. package/dist/FloatingPanelFrame-6W5OexYe.js.map +1 -0
  3. package/dist/FloatingPanelFrame-D9Cp2al1.cjs +2 -0
  4. package/dist/FloatingPanelFrame-D9Cp2al1.cjs.map +1 -0
  5. package/dist/GridLayout-BzrIDrC9.js +1465 -0
  6. package/dist/GridLayout-BzrIDrC9.js.map +1 -0
  7. package/dist/GridLayout-ZrOhoLLB.cjs +2 -0
  8. package/dist/GridLayout-ZrOhoLLB.cjs.map +1 -0
  9. package/dist/PanelSystemContext.d.ts +9 -0
  10. package/dist/components/grid/GridLayerList.d.ts +3 -0
  11. package/dist/components/grid/GridLayout.d.ts +5 -0
  12. package/dist/components/paneling/FloatingPanelFrame.d.ts +4 -0
  13. package/dist/components/window/FloatingWindow.d.ts +15 -0
  14. package/dist/config/panelRouter.d.ts +2 -2
  15. package/dist/config.cjs +1 -1
  16. package/dist/config.cjs.map +1 -1
  17. package/dist/config.js +1 -1
  18. package/dist/config.js.map +1 -1
  19. package/dist/constants/styles.d.ts +3 -1
  20. package/dist/floating.cjs +1 -1
  21. package/dist/floating.js +1 -1
  22. package/dist/hooks/ContentCacheContext.d.ts +59 -0
  23. package/dist/hooks/useContainerScroll.d.ts +23 -0
  24. package/dist/hooks/useContentCache.d.ts +67 -0
  25. package/dist/hooks/useDocumentScroll.d.ts +13 -0
  26. package/dist/hooks/useScrollContainer.d.ts +21 -0
  27. package/dist/index.cjs +2 -2
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.d.ts +4 -1
  30. package/dist/index.js +950 -878
  31. package/dist/index.js.map +1 -1
  32. package/dist/modules/grid/GridLayoutContext.d.ts +5 -0
  33. package/dist/modules/grid/resizeHandles.d.ts +14 -0
  34. package/dist/modules/grid/trackUtils.d.ts +29 -0
  35. package/dist/modules/grid/useGridTracks.d.ts +6 -15
  36. package/dist/modules/grid/useLayerInteractions.d.ts +2 -1
  37. package/dist/modules/window/useFloatingState.d.ts +9 -0
  38. package/dist/pivot.cjs +1 -1
  39. package/dist/pivot.js +1 -1
  40. package/dist/sticky-header/StickyHeader.d.ts +53 -0
  41. package/dist/sticky-header/index.d.ts +7 -0
  42. package/dist/sticky-header/types.d.ts +50 -0
  43. package/dist/sticky-header.cjs +2 -0
  44. package/dist/sticky-header.cjs.map +1 -0
  45. package/dist/sticky-header.js +198 -0
  46. package/dist/sticky-header.js.map +1 -0
  47. package/dist/styles-CA2_zLZt.js +52 -0
  48. package/dist/{styles-DcG3aIFx.cjs.map → styles-CA2_zLZt.js.map} +1 -1
  49. package/dist/styles-PsqGOEJP.cjs +2 -0
  50. package/dist/styles-PsqGOEJP.cjs.map +1 -0
  51. package/dist/types.d.ts +79 -4
  52. package/dist/useIsomorphicLayoutEffect-DGRNF4Lf.cjs +2 -0
  53. package/dist/useIsomorphicLayoutEffect-DGRNF4Lf.cjs.map +1 -0
  54. package/dist/useIsomorphicLayoutEffect-DhmEnmZ_.js +6 -0
  55. package/dist/useIsomorphicLayoutEffect-DhmEnmZ_.js.map +1 -0
  56. package/dist/usePivot-BS-DGfwd.cjs +2 -0
  57. package/dist/usePivot-BS-DGfwd.cjs.map +1 -0
  58. package/dist/usePivot-BvOGxLQQ.js +124 -0
  59. package/dist/usePivot-BvOGxLQQ.js.map +1 -0
  60. package/dist/utils/css.d.ts +19 -0
  61. package/package.json +6 -1
  62. package/dist/FloatingPanelFrame-SOrLGjZd.js +0 -67
  63. package/dist/FloatingPanelFrame-SOrLGjZd.js.map +0 -1
  64. package/dist/FloatingPanelFrame-XtBcHANI.cjs +0 -2
  65. package/dist/FloatingPanelFrame-XtBcHANI.cjs.map +0 -1
  66. package/dist/GridLayout-CLvW8jID.js +0 -1352
  67. package/dist/GridLayout-CLvW8jID.js.map +0 -1
  68. package/dist/GridLayout-qufTyOQM.cjs +0 -2
  69. package/dist/GridLayout-qufTyOQM.cjs.map +0 -1
  70. package/dist/styles-DcG3aIFx.cjs +0 -2
  71. package/dist/styles-w0ZixggV.js +0 -51
  72. package/dist/styles-w0ZixggV.js.map +0 -1
  73. package/dist/usePivot-C8q0pMgW.cjs +0 -2
  74. package/dist/usePivot-C8q0pMgW.cjs.map +0 -1
  75. package/dist/usePivot-z9gumDf-.js +0 -97
  76. package/dist/usePivot-z9gumDf-.js.map +0 -1
@@ -0,0 +1,1465 @@
1
+ import { jsxs as H, Fragment as N, jsx as h } from "react/jsx-runtime";
2
+ import * as i from "react";
3
+ import { F as Pt, e as yt, a as Lt, b as Mt, f as Dt, d as Ut } from "./FloatingPanelFrame-6W5OexYe.js";
4
+ import { C as jt, D as Kt, o as Zt, p as qt, q as Jt, r as Qt, s as te, G as Y, t as T, u as ee, v as ne, w as oe, R as ut, x as re, y as Q } from "./styles-CA2_zLZt.js";
5
+ import { a as se, u as ie } from "./usePivot-BvOGxLQQ.js";
6
+ import { createPortal as ae } from "react-dom";
7
+ import { u as It } from "./useIsomorphicLayoutEffect-DhmEnmZ_.js";
8
+ const ce = () => {
9
+ const t = /* @__PURE__ */ new Map();
10
+ return (e) => {
11
+ if (!e)
12
+ return;
13
+ const n = t.get(e);
14
+ if (n !== void 0)
15
+ return n;
16
+ const o = t.size;
17
+ return t.set(e, o), o;
18
+ };
19
+ }, ue = ce(), tt = /* @__PURE__ */ new Map(), le = (t) => {
20
+ const e = `ovs-threshold:${t.threshold}-rootMargin:${t.rootMargin}-root:${ue(t.root)}`;
21
+ if (tt.has(e))
22
+ return tt.get(e);
23
+ const n = new class {
24
+ #t = /* @__PURE__ */ new Map();
25
+ #e = new IntersectionObserver((o) => {
26
+ o.forEach((r) => {
27
+ const s = this.#t.get(r.target);
28
+ s && s(r);
29
+ });
30
+ }, t);
31
+ observe(o, r) {
32
+ return this.#t.set(o, r), this.#e.observe(o), () => {
33
+ this.#t.delete(o), this.#e.unobserve(o);
34
+ };
35
+ }
36
+ }();
37
+ return tt.set(e, n), n;
38
+ }, lt = Object.freeze({
39
+ x: 0,
40
+ y: 0,
41
+ width: 0,
42
+ height: 0,
43
+ top: 0,
44
+ right: 0,
45
+ bottom: 0,
46
+ left: 0
47
+ });
48
+ function de(t, { threshold: e = 0, rootMargin: n = "0px", root: o = null }) {
49
+ const [r, s] = i.useState(null);
50
+ return i.useEffect(() => {
51
+ const u = t.current;
52
+ return u ? le({
53
+ threshold: e,
54
+ rootMargin: n,
55
+ root: o
56
+ }).observe(u, (a) => {
57
+ s({
58
+ isIntersecting: a.isIntersecting,
59
+ boundingClientRect: a.boundingClientRect,
60
+ intersectionRatio: a.intersectionRatio,
61
+ intersectionRect: a.intersectionRect,
62
+ rootBounds: a.rootBounds,
63
+ target: a.target,
64
+ time: a.time
65
+ });
66
+ }) : void 0;
67
+ }, [t, e, n, o]), i.useMemo(() => ({
68
+ isIntersecting: r?.isIntersecting ?? !1,
69
+ boundingClientRect: r?.boundingClientRect ?? lt,
70
+ intersectionRatio: r?.intersectionRatio ?? 0,
71
+ intersectionRect: r?.intersectionRect ?? lt,
72
+ rootBounds: r?.rootBounds ?? null,
73
+ target: r?.target ?? t.current,
74
+ time: r?.time ?? 0
75
+ }), [r, t]);
76
+ }
77
+ const dt = {
78
+ position: "fixed",
79
+ inset: 0,
80
+ background: jt
81
+ }, fe = {
82
+ willChange: "transform"
83
+ }, ft = {
84
+ left: {
85
+ top: 0,
86
+ bottom: 0,
87
+ left: 0,
88
+ transform: "translateX(-100%)"
89
+ },
90
+ right: {
91
+ top: 0,
92
+ bottom: 0,
93
+ right: 0,
94
+ transform: "translateX(100%)"
95
+ },
96
+ top: {
97
+ top: 0,
98
+ left: 0,
99
+ right: 0,
100
+ transform: "translateY(-100%)"
101
+ },
102
+ bottom: {
103
+ bottom: 0,
104
+ left: 0,
105
+ right: 0,
106
+ transform: "translateY(100%)"
107
+ }
108
+ }, ge = (t, e, n) => t === "none" ? void 0 : `transform ${e ?? Kt} ${n ?? Zt}`, pe = (t, e) => t ? e : !1, he = ({ chrome: t, frameStyle: e, header: n, dismissible: o, onClose: r, children: s }) => t ? /* @__PURE__ */ H(Pt, { style: e, children: [
109
+ /* @__PURE__ */ h(me, { header: n, dismissible: o, onClose: r }),
110
+ /* @__PURE__ */ h(
111
+ yt,
112
+ {
113
+ style: { padding: qt, flex: 1, display: "flex", flexDirection: "column" },
114
+ children: s
115
+ }
116
+ )
117
+ ] }) : /* @__PURE__ */ h(N, { children: s }), me = ({ header: t, dismissible: e, onClose: n }) => {
118
+ if (!t)
119
+ return null;
120
+ const o = t.showCloseButton ?? !0, r = pe(e, o);
121
+ return /* @__PURE__ */ h(i.Activity, { mode: t ? "visible" : "hidden", children: /* @__PURE__ */ H(
122
+ Lt,
123
+ {
124
+ style: { padding: `${Qt} ${te}`, gap: Jt },
125
+ children: [
126
+ /* @__PURE__ */ h(i.Activity, { mode: t ? "visible" : "hidden", children: /* @__PURE__ */ h(Mt, { children: t.title }) }),
127
+ /* @__PURE__ */ h(i.Activity, { mode: r ? "visible" : "hidden", children: /* @__PURE__ */ h(
128
+ Dt,
129
+ {
130
+ onClick: n,
131
+ "aria-label": "Close drawer",
132
+ style: { marginLeft: "auto" }
133
+ }
134
+ ) })
135
+ ]
136
+ }
137
+ ) });
138
+ }, we = ({
139
+ id: t,
140
+ config: e,
141
+ isOpen: n,
142
+ onClose: o,
143
+ children: r,
144
+ zIndex: s,
145
+ width: u,
146
+ height: c,
147
+ position: a
148
+ }) => {
149
+ const {
150
+ dismissible: l = !0,
151
+ header: g,
152
+ chrome: f = !0,
153
+ inline: m = !1,
154
+ transitionMode: w = "css",
155
+ transitionDuration: C,
156
+ transitionEasing: z
157
+ } = e, L = i.useCallback(
158
+ (I, R) => I || (R ? R.left !== void 0 ? "left" : R.right !== void 0 ? "right" : R.top !== void 0 ? "top" : R.bottom !== void 0 ? "bottom" : "right" : "right"),
159
+ []
160
+ )(e.anchor, a), x = {
161
+ left: "translateX(0)",
162
+ right: "translateX(0)",
163
+ top: "translateY(0)",
164
+ bottom: "translateY(0)"
165
+ }, $ = i.useMemo(() => {
166
+ const I = ge(w, C, z), R = {
167
+ ...fe,
168
+ ...m ? { position: "absolute" } : { position: "fixed" },
169
+ ...ft[L],
170
+ transform: n ? x[L] : ft[L].transform,
171
+ transition: I
172
+ };
173
+ return s !== void 0 && (R.zIndex = s), u !== void 0 && (R.width = typeof u == "number" ? `${u}px` : u), c !== void 0 && (R.height = typeof c == "number" ? `${c}px` : c), R;
174
+ }, [c, m, n, L, C, z, w, u, s]), M = g?.title ?? e.ariaLabel ?? "Drawer", D = i.useMemo(() => {
175
+ const I = m ? { ...dt, position: "absolute" } : dt, R = w === "none" ? void 0 : `opacity ${C ?? "220ms"} ease`;
176
+ return {
177
+ ...I,
178
+ opacity: n ? 1 : 0,
179
+ pointerEvents: n ? "auto" : "none",
180
+ transition: R,
181
+ zIndex: s !== void 0 ? s - 1 : void 0
182
+ };
183
+ }, [m, n, C, w, s]), A = i.useMemo(() => {
184
+ const I = L === "left" || L === "right", R = { borderRadius: 0 };
185
+ return I && (R.height = "100%"), R;
186
+ }, [L]);
187
+ return /* @__PURE__ */ H(N, { children: [
188
+ /* @__PURE__ */ h("div", { style: D, onClick: l ? o : void 0 }),
189
+ /* @__PURE__ */ h(
190
+ "div",
191
+ {
192
+ "data-layer-id": t,
193
+ "data-placement": L,
194
+ style: $,
195
+ role: "dialog",
196
+ "aria-modal": l ? !0 : void 0,
197
+ "aria-hidden": n ? void 0 : !0,
198
+ "aria-label": M,
199
+ children: /* @__PURE__ */ h(
200
+ he,
201
+ {
202
+ chrome: f,
203
+ frameStyle: A,
204
+ header: g,
205
+ dismissible: l,
206
+ onClose: o,
207
+ children: r
208
+ }
209
+ )
210
+ }
211
+ )
212
+ ] });
213
+ }, be = (t, e) => new Promise((n) => {
214
+ let o = !1;
215
+ const r = () => {
216
+ o || (o = !0, t.removeEventListener("transitionend", s), n());
217
+ }, s = (u) => {
218
+ u.target === t && r();
219
+ };
220
+ t.addEventListener("transitionend", s), setTimeout(r, e + 50);
221
+ }), Tt = async (t, e, n, o) => {
222
+ switch (e) {
223
+ case "none":
224
+ t();
225
+ return;
226
+ case "css":
227
+ t(), n && await be(n, o);
228
+ return;
229
+ }
230
+ }, Vn = (t) => {
231
+ const [e, n] = i.useState({}), o = i.useRef(t);
232
+ o.current = t;
233
+ const r = i.useCallback(
234
+ async (a, l, g) => {
235
+ const { mode: f = "none", element: m, duration: w = 300 } = g ?? {};
236
+ await Tt(() => {
237
+ n((y) => y[a] === l ? y : { ...y, [a]: l });
238
+ }, f, m?.current, w);
239
+ const z = o.current;
240
+ l ? z?.onOpen?.(a) : z?.onClose?.(a), z?.onTransitionEnd?.(a, l);
241
+ },
242
+ []
243
+ ), s = i.useCallback((a) => e[a] ?? !1, [e]), u = i.useCallback(
244
+ (a, l) => r(a, !0, l),
245
+ [r]
246
+ ), c = i.useCallback(
247
+ (a, l) => r(a, !1, l),
248
+ [r]
249
+ );
250
+ return { state: s, open: u, close: c };
251
+ }, ve = (t) => {
252
+ if (!t)
253
+ return 300;
254
+ const e = t.match(/(\d+)/);
255
+ return e ? parseInt(e[1], 10) : 300;
256
+ }, Se = (t) => {
257
+ const [e, n] = i.useState(() => {
258
+ const a = {};
259
+ return t.forEach((l) => {
260
+ l.drawer && (a[l.id] = l.drawer.defaultOpen ?? !1);
261
+ }), a;
262
+ }), o = i.useMemo(() => {
263
+ const a = /* @__PURE__ */ new Map();
264
+ return t.forEach((l) => a.set(l.id, l)), a;
265
+ }, [t]), r = i.useCallback(
266
+ async (a, l, g) => {
267
+ const f = o.get(a);
268
+ if (!f?.drawer)
269
+ return;
270
+ const m = g?.mode ?? f.drawer.transitionMode ?? "css", w = g?.duration ?? ve(f.drawer.transitionDuration), C = g?.element?.current;
271
+ await Tt(() => {
272
+ f.drawer?.open === void 0 && n((y) => y[a] === l ? y : { ...y, [a]: l }), f.drawer?.onStateChange?.(l);
273
+ }, m, C, w);
274
+ },
275
+ [o]
276
+ ), s = i.useCallback(
277
+ (a) => {
278
+ const l = o.get(a);
279
+ return l?.drawer?.open !== void 0 ? l.drawer.open : e[a] ?? !1;
280
+ },
281
+ [o, e]
282
+ ), u = i.useCallback(
283
+ (a, l) => r(a, !0, l),
284
+ [r]
285
+ ), c = i.useCallback(
286
+ (a, l) => r(a, !1, l),
287
+ [r]
288
+ );
289
+ return { state: s, open: u, close: c };
290
+ }, Ce = ({ layers: t }) => {
291
+ const e = Se(t), n = i.useMemo(() => t.filter((r) => r.drawer), [t]), o = i.useMemo(() => {
292
+ const r = /* @__PURE__ */ new Map();
293
+ return n.forEach((s) => {
294
+ r.set(s.id, () => e.close(s.id));
295
+ }), r;
296
+ }, [n, e.close]);
297
+ return /* @__PURE__ */ h(N, { children: n.map((r) => {
298
+ if (!r.drawer)
299
+ return null;
300
+ const s = e.state(r.id), u = o.get(r.id);
301
+ return u ? /* @__PURE__ */ h(
302
+ we,
303
+ {
304
+ id: r.id,
305
+ config: r.drawer,
306
+ isOpen: s,
307
+ onClose: u,
308
+ zIndex: r.zIndex,
309
+ width: r.width,
310
+ height: r.height,
311
+ position: r.position,
312
+ children: r.component
313
+ },
314
+ r.id
315
+ ) : null;
316
+ }) });
317
+ }, xt = i.createContext(null), ze = ({ value: t, children: e }) => /* @__PURE__ */ h(xt.Provider, { value: t, children: e }), kt = () => {
318
+ const t = i.useContext(xt);
319
+ if (!t)
320
+ throw new Error("useGridLayoutContext must be used within a GridLayoutProvider.");
321
+ return t;
322
+ }, At = i.createContext(null), Ht = () => {
323
+ const t = i.useContext(At);
324
+ if (!t)
325
+ throw new Error("usePanelSystem must be used within a PanelSystemProvider.");
326
+ return t;
327
+ }, Ee = ({ config: t, layers: e, style: n, children: o }) => {
328
+ const r = i.useMemo(() => {
329
+ const l = /* @__PURE__ */ new Map();
330
+ return e.forEach((g) => {
331
+ l.set(g.id, g);
332
+ }), l;
333
+ }, [e]), s = i.useCallback(
334
+ (l) => r.get(l)?.component ?? null,
335
+ [r]
336
+ ), u = i.useMemo(() => e.map((l) => l.id), [e]), { getCachedContent: c } = se({
337
+ resolveContent: s,
338
+ validIds: u
339
+ }), a = i.useMemo(
340
+ () => ({
341
+ config: t,
342
+ style: n,
343
+ layers: {
344
+ defs: e,
345
+ layerById: r
346
+ },
347
+ getCachedContent: c
348
+ }),
349
+ [t, n, e, r, c]
350
+ );
351
+ return /* @__PURE__ */ h(At.Provider, { value: a, children: o });
352
+ }, Nt = i.createContext(null), $t = ({ layerId: t, children: e }) => {
353
+ const n = i.useMemo(() => ({ layerId: t }), [t]);
354
+ return /* @__PURE__ */ h(Nt.Provider, { value: n, children: e });
355
+ }, Xn = () => {
356
+ const t = i.useContext(Nt);
357
+ if (!t)
358
+ throw new Error("useLayerInstance must be used within a LayerInstanceProvider.");
359
+ return t;
360
+ }, gt = (t, e, n) => {
361
+ if (typeof t == "number" && Number.isFinite(t))
362
+ return t;
363
+ throw new Error(`Popup layer "${n}" requires a numeric "${e}" value.`);
364
+ }, Ft = (t, e) => {
365
+ if (!t)
366
+ throw new Error(`Popup layer "${e}" must define position (left/top).`);
367
+ return {
368
+ left: gt(t.left, "left", e),
369
+ top: gt(t.top, "top", e)
370
+ };
371
+ }, V = (t) => `${Math.round(t)}`, G = (t) => {
372
+ if (t !== void 0)
373
+ return t ? "yes" : "no";
374
+ }, Re = (t, e, n, o, r) => {
375
+ const s = {}, u = Ft(e, t);
376
+ if (typeof n != "number" || typeof o != "number")
377
+ throw new Error(`Popup layer "${t}" requires numeric width/height.`);
378
+ s.width = V(n), s.height = V(o), s.left = V(u.left), s.top = V(u.top);
379
+ const c = r?.features;
380
+ if (c) {
381
+ const a = G(c.toolbar), l = G(c.menubar), g = G(c.location), f = G(c.status), m = G(c.resizable), w = G(c.scrollbars);
382
+ a !== void 0 && (s.toolbar = a), l !== void 0 && (s.menubar = l), g !== void 0 && (s.location = g), f !== void 0 && (s.status = f), m !== void 0 && (s.resizable = m), w !== void 0 && (s.scrollbars = w);
383
+ }
384
+ return Object.entries(s).map(([a, l]) => `${a}=${l}`).join(",");
385
+ }, pt = (t, e, n, o, r) => {
386
+ const s = Ft(n, e);
387
+ if (typeof o != "number" || typeof r != "number")
388
+ throw new Error(`Popup layer "${e}" requires numeric width/height.`);
389
+ t.moveTo(Math.round(s.left), Math.round(s.top)), t.resizeTo(Math.round(o), Math.round(r));
390
+ }, Pe = ({ layer: t }) => {
391
+ const e = t.floating;
392
+ if (!e)
393
+ throw new Error(`Layer "${t.id}" is missing floating configuration required for popup mode.`);
394
+ if ((e.mode ?? "embedded") !== "popup")
395
+ throw new Error(`PopupLayerPortal received layer "${t.id}" that is not configured for popup mode.`);
396
+ const o = i.useRef(null), r = i.useRef(null), [s, u] = i.useState(!1);
397
+ return i.useEffect(() => {
398
+ if (typeof window > "u")
399
+ return;
400
+ const c = Re(t.id, t.position, t.width, t.height, e.popup), a = e.popup?.name ?? t.id, l = ye(
401
+ a,
402
+ c,
403
+ {
404
+ position: t.position,
405
+ size: { width: t.width, height: t.height }
406
+ },
407
+ e.popup
408
+ );
409
+ if (!l)
410
+ throw new Error(`Failed to open popup window for layer "${t.id}".`);
411
+ const g = l;
412
+ r.current = g, e.popup?.focus !== !1 && g.focus(), g.document.title || (g.document.title = t.id), g.document.body.innerHTML = "";
413
+ const f = g.document.createElement("div");
414
+ f.dataset.layerId = t.id, g.document.body.appendChild(f), o.current = f, u(!0), pt(g, t.id, t.position, t.width, t.height);
415
+ const m = () => {
416
+ r.current = null, o.current = null, u(!1);
417
+ };
418
+ return g.addEventListener("beforeunload", m), () => {
419
+ g.removeEventListener("beforeunload", m), e.popup?.closeOnUnmount !== !1 && g.close(), r.current = null, o.current = null, u(!1);
420
+ };
421
+ }, [
422
+ e.popup?.closeOnUnmount,
423
+ e.popup?.features?.location,
424
+ e.popup?.features?.menubar,
425
+ e.popup?.features?.resizable,
426
+ e.popup?.features?.scrollbars,
427
+ e.popup?.features?.status,
428
+ e.popup?.features?.toolbar,
429
+ e.popup?.focus,
430
+ e.popup?.name,
431
+ t.id
432
+ ]), i.useEffect(() => {
433
+ const c = r.current;
434
+ c && pt(c, t.id, t.position, t.width, t.height);
435
+ }, [t.position?.left, t.position?.top, t.height, t.width, t.id]), !s || !o.current ? null : ae(/* @__PURE__ */ h($t, { layerId: t.id, children: t.component }), o.current);
436
+ }, ye = (t, e, n, o) => {
437
+ const r = o?.createWindow;
438
+ return r ? r({ name: t, features: e, bounds: n }) : window.open("", t, e);
439
+ }, Le = ({ onClick: t }) => /* @__PURE__ */ h(Ut, { children: /* @__PURE__ */ h(Dt, { onClick: t, "aria-label": "Close window", "data-drag-ignore": "true" }) }), Me = ({ header: t, draggable: e, onClose: n }) => {
440
+ if (!t)
441
+ return null;
442
+ const o = t.showCloseButton ?? !1;
443
+ return /* @__PURE__ */ H(Lt, { ...e ? { "data-drag-handle": "true" } : {}, style: { cursor: e ? "grab" : void 0 }, children: [
444
+ t.title ? /* @__PURE__ */ h(Mt, { children: t.title }) : null,
445
+ o ? /* @__PURE__ */ h(Le, { onClick: n }) : null
446
+ ] });
447
+ }, De = ({ header: t, draggable: e, chrome: n, onClose: o, children: r }) => n ? /* @__PURE__ */ H(Pt, { style: { height: "100%", width: "100%" }, children: [
448
+ /* @__PURE__ */ h(Me, { header: t, draggable: e, onClose: o }),
449
+ /* @__PURE__ */ h(yt, { style: { flex: 1, display: "flex", flexDirection: "column" }, children: r })
450
+ ] }) : /* @__PURE__ */ h(N, { children: r }), _t = ({ id: t, config: e, onClose: n, children: o }) => {
451
+ const r = e.chrome ?? !1, s = e.draggable ?? !1, u = e.header?.title ?? e.ariaLabel ?? "Floating window";
452
+ return /* @__PURE__ */ h("div", { "data-floating-window": t, role: "dialog", "aria-label": u, style: { height: "100%", width: "100%" }, children: /* @__PURE__ */ h(De, { header: e.header, draggable: s, chrome: r, onClose: n, children: o }) });
453
+ };
454
+ _t.displayName = "FloatingWindow";
455
+ const Gt = {
456
+ position: "absolute",
457
+ pointerEvents: "auto",
458
+ boxSizing: "border-box",
459
+ background: "transparent",
460
+ border: "none"
461
+ }, Ie = {
462
+ ...Gt,
463
+ width: T,
464
+ height: T,
465
+ zIndex: 2
466
+ }, Te = {
467
+ ...Gt,
468
+ zIndex: 1
469
+ }, xe = {
470
+ "top-left": {
471
+ top: 0,
472
+ left: 0,
473
+ transform: "translate(-50%, -50%)",
474
+ cursor: "nwse-resize"
475
+ },
476
+ "top-right": {
477
+ top: 0,
478
+ right: 0,
479
+ transform: "translate(50%, -50%)",
480
+ cursor: "nesw-resize"
481
+ },
482
+ "bottom-left": {
483
+ bottom: 0,
484
+ left: 0,
485
+ transform: "translate(-50%, 50%)",
486
+ cursor: "nesw-resize"
487
+ },
488
+ "bottom-right": {
489
+ bottom: 0,
490
+ right: 0,
491
+ transform: "translate(50%, 50%)",
492
+ cursor: "nwse-resize"
493
+ }
494
+ }, ke = {
495
+ left: {
496
+ top: T,
497
+ bottom: T,
498
+ left: 0,
499
+ width: Y,
500
+ transform: "translateX(-50%)",
501
+ cursor: "ew-resize"
502
+ },
503
+ right: {
504
+ top: T,
505
+ bottom: T,
506
+ right: 0,
507
+ width: Y,
508
+ transform: "translateX(50%)",
509
+ cursor: "ew-resize"
510
+ },
511
+ top: {
512
+ left: T,
513
+ right: T,
514
+ top: 0,
515
+ height: Y,
516
+ transform: "translateY(-50%)",
517
+ cursor: "ns-resize"
518
+ },
519
+ bottom: {
520
+ left: T,
521
+ right: T,
522
+ bottom: 0,
523
+ height: Y,
524
+ transform: "translateY(50%)",
525
+ cursor: "ns-resize"
526
+ }
527
+ }, Ae = [
528
+ { key: "top-left", variant: "corner", horizontal: "left", vertical: "top" },
529
+ { key: "top-right", variant: "corner", horizontal: "right", vertical: "top" },
530
+ { key: "bottom-left", variant: "corner", horizontal: "left", vertical: "bottom" },
531
+ { key: "bottom-right", variant: "corner", horizontal: "right", vertical: "bottom" },
532
+ { key: "left", variant: "edge", horizontal: "left" },
533
+ { key: "right", variant: "edge", horizontal: "right" },
534
+ { key: "top", variant: "edge", vertical: "top" },
535
+ { key: "bottom", variant: "edge", vertical: "bottom" }
536
+ ], He = ({ layerId: t, onPointerDown: e }) => /* @__PURE__ */ h(N, { children: Ae.map((n) => {
537
+ const o = n.variant === "corner" ? Ie : Te, r = n.variant === "corner" ? xe[n.key] : ke[n.key], s = { ...o, ...r }, u = n.variant === "corner" ? { "data-resize-corner": n.key } : { "data-resize-edge": n.key };
538
+ return /* @__PURE__ */ h(
539
+ "div",
540
+ {
541
+ role: "presentation",
542
+ "aria-hidden": "true",
543
+ style: s,
544
+ ...u,
545
+ "data-layer-id": t,
546
+ onPointerDown: (c) => e(n, c)
547
+ },
548
+ n.key
549
+ );
550
+ }) }), Ne = ({ pivot: t }) => {
551
+ const { Outlet: e } = ie({
552
+ items: t.items,
553
+ activeId: t.activeId,
554
+ defaultActiveId: t.defaultActiveId,
555
+ onActiveChange: t.onActiveChange,
556
+ transitionMode: t.transitionMode
557
+ });
558
+ return /* @__PURE__ */ h(e, {});
559
+ }, Wt = i.memo(({ layer: t, onClose: e }) => {
560
+ const { getCachedContent: n } = Ht(), o = t.pivot ? /* @__PURE__ */ h(Ne, { pivot: t.pivot }) : /* @__PURE__ */ h(N, { children: n(t.id) });
561
+ return t.floating?.chrome ? /* @__PURE__ */ h(_t, { id: t.id, config: t.floating, onClose: e, children: o }) : o;
562
+ });
563
+ Wt.displayName = "LayerContentRenderer";
564
+ const Ot = i.memo(({ layerId: t, isResizable: e, onPointerDown: n }) => e ? /* @__PURE__ */ h(He, { layerId: t, onPointerDown: n }) : null);
565
+ Ot.displayName = "LayerResizeHandles";
566
+ const $e = (t, e) => t ? "auto" : e ? "visible" : "hidden", Bt = i.memo(({ layer: t, handleLayerPointerDown: e }) => {
567
+ const { getLayerRenderState: n } = kt(), { style: o, isResizable: r, isResizing: s, onResizeHandlePointerDown: u } = n(t), c = i.useMemo(() => {
568
+ const g = {};
569
+ return t.gridArea && (g.gridArea = t.gridArea), t.gridRow && (g.gridRow = t.gridRow), t.gridColumn && (g.gridColumn = t.gridColumn), g;
570
+ }, [t.gridArea, t.gridRow, t.gridColumn]), a = i.useMemo(() => {
571
+ const g = !!t.floating, f = $e(t.scrollable, g), m = {
572
+ ...o,
573
+ ...c,
574
+ minWidth: 0,
575
+ minHeight: 0,
576
+ overflow: f
577
+ };
578
+ return r ? { ...m, position: "relative" } : m;
579
+ }, [o, c, r, t.scrollable, t.floating]), l = i.useCallback(() => {
580
+ t.floating?.onClose?.();
581
+ }, [t.floating]);
582
+ return /* @__PURE__ */ H(
583
+ "div",
584
+ {
585
+ "data-layer-id": t.id,
586
+ "data-draggable": !!t.floating?.draggable,
587
+ "data-resizable": r,
588
+ "data-resizing": s,
589
+ style: a,
590
+ onPointerDown: e,
591
+ children: [
592
+ /* @__PURE__ */ h($t, { layerId: t.id, children: /* @__PURE__ */ h(Wt, { layer: t, onClose: l }) }),
593
+ /* @__PURE__ */ h(Ot, { layerId: t.id, isResizable: r, onPointerDown: u })
594
+ ]
595
+ }
596
+ );
597
+ });
598
+ Bt.displayName = "EmbeddedLayer";
599
+ const Fe = ({ layers: t }) => {
600
+ const { handleLayerPointerDown: e } = kt();
601
+ return /* @__PURE__ */ h(N, { children: t.map((n) => {
602
+ const o = n.floating?.mode ?? "embedded";
603
+ return n.floating && o === "popup" ? /* @__PURE__ */ h(Pe, { layer: n }, n.id) : /* @__PURE__ */ h(Bt, { layer: n, handleLayerPointerDown: e }, n.id);
604
+ }) });
605
+ };
606
+ function W(t) {
607
+ const e = i.useRef(t);
608
+ return e.current = t, i.useCallback((...n) => {
609
+ const o = e.current;
610
+ if (o)
611
+ return o(...n);
612
+ }, []);
613
+ }
614
+ function et(t, e) {
615
+ const n = W(e.onMove), o = W(e.onUp), r = W(e.onCancel);
616
+ i.useEffect(() => {
617
+ if (t)
618
+ return e.onMove && document.addEventListener("pointermove", n, { passive: !1 }), e.onUp && document.addEventListener("pointerup", o), e.onCancel && document.addEventListener("pointercancel", r), () => {
619
+ e.onMove && document.removeEventListener("pointermove", n), e.onUp && document.removeEventListener("pointerup", o), e.onCancel && document.removeEventListener("pointercancel", r);
620
+ };
621
+ }, [t, e.onMove, e.onUp, e.onCancel, n, o, r]);
622
+ }
623
+ function _e(t, e, n) {
624
+ i.useEffect(() => {
625
+ const o = t.current;
626
+ if (!(!e || !o || n === void 0))
627
+ return o.setPointerCapture(n), () => {
628
+ o.hasPointerCapture && o.hasPointerCapture(n) && o.releasePointerCapture(n);
629
+ };
630
+ }, [t, e, n]);
631
+ }
632
+ function Ge(t, e, n = ["pointerdown", "pointermove", "pointerup"]) {
633
+ i.useEffect(() => {
634
+ const o = t.current;
635
+ if (!e || !o)
636
+ return;
637
+ const r = (s) => {
638
+ s.preventDefault();
639
+ };
640
+ return n.forEach((s) => {
641
+ o.addEventListener(s, r, { passive: !1 });
642
+ }), () => {
643
+ n.forEach((s) => {
644
+ o.removeEventListener(s, r);
645
+ });
646
+ };
647
+ }, [t, e, n]);
648
+ }
649
+ function We(t, e, n) {
650
+ const { onMove: o, onUp: r, onCancel: s, pointerId: u, capturePointer: c = !0, preventDefaults: a = !0 } = n;
651
+ et(e, { onMove: o, onUp: r, onCancel: s }), _e(t, e ? c : !1, u), Ge(t, e ? a : !1);
652
+ }
653
+ const Oe = (t) => {
654
+ const e = i.useRef(null), n = i.useRef(null), o = i.useRef(0), [r, s] = i.useState(!1), u = W((f) => {
655
+ t.onResize?.(f);
656
+ }), c = i.useCallback(
657
+ (f) => t.axis === "x" ? f.clientX : f.clientY,
658
+ [t.axis]
659
+ ), a = i.useCallback(
660
+ (f) => {
661
+ f.preventDefault(), e.current = f.currentTarget, n.current = f.pointerId, o.current = c(f), s(!0);
662
+ },
663
+ [c]
664
+ ), l = i.useCallback(
665
+ (f) => {
666
+ const m = c(f), w = m - o.current;
667
+ w !== 0 && (o.current = m, u(w));
668
+ },
669
+ [c, u]
670
+ ), g = i.useCallback(() => {
671
+ s(!1), n.current = null;
672
+ }, []);
673
+ return We(e, r, {
674
+ onMove: l,
675
+ onUp: g,
676
+ pointerId: n.current ?? void 0,
677
+ capturePointer: !0,
678
+ preventDefaults: !1
679
+ }), {
680
+ ref: e,
681
+ onPointerDown: a,
682
+ isDragging: r
683
+ };
684
+ }, Be = ({
685
+ element: t,
686
+ component: e
687
+ }) => i.forwardRef(({ children: n, ...o }, r) => t ? i.cloneElement(
688
+ t,
689
+ { ...o, ref: r },
690
+ n ?? t.props.children
691
+ ) : e ? /* @__PURE__ */ h(e, { ...o, ref: r, children: n }) : /* @__PURE__ */ h("div", { ...o, ref: r, children: n }));
692
+ function Ye({
693
+ element: t,
694
+ component: e
695
+ }) {
696
+ return i.useMemo(
697
+ () => Be({
698
+ element: t,
699
+ component: e
700
+ }),
701
+ [e, t]
702
+ );
703
+ }
704
+ const Ve = {
705
+ position: "absolute",
706
+ zIndex: re
707
+ }, Xe = {
708
+ vertical: {
709
+ width: ut,
710
+ height: "100%",
711
+ top: 0,
712
+ cursor: "col-resize"
713
+ },
714
+ horizontal: {
715
+ width: "100%",
716
+ height: ut,
717
+ left: 0,
718
+ cursor: "row-resize"
719
+ }
720
+ }, Ue = {
721
+ idle: oe,
722
+ hovered: ne,
723
+ dragging: ee
724
+ }, je = ({
725
+ direction: t,
726
+ onResize: e,
727
+ component: n,
728
+ element: o,
729
+ children: r
730
+ }) => {
731
+ const s = t === "vertical" ? "x" : "y", { ref: u, isDragging: c, onPointerDown: a } = Oe({ axis: s, onResize: e }), [l, g] = i.useState(!1), f = i.useCallback(() => {
732
+ g(!0);
733
+ }, []), m = i.useCallback(() => {
734
+ g(!1);
735
+ }, []), w = Ye({
736
+ element: o,
737
+ component: n
738
+ }), C = i.useMemo(() => c ? "dragging" : l ? "hovered" : "idle", [c, l]), z = i.useMemo(() => ({
739
+ ...Ve,
740
+ ...Xe[t],
741
+ backgroundColor: Ue[C],
742
+ touchAction: "none"
743
+ }), [t, C]);
744
+ return /* @__PURE__ */ h(
745
+ w,
746
+ {
747
+ ref: u,
748
+ style: z,
749
+ role: "separator",
750
+ "aria-orientation": t,
751
+ "aria-hidden": void 0,
752
+ "data-resize-handle": "true",
753
+ "data-direction": t,
754
+ "data-is-dragging": c ? "true" : void 0,
755
+ onPointerDown: a,
756
+ onPointerEnter: f,
757
+ onPointerLeave: m,
758
+ children: r
759
+ }
760
+ );
761
+ }, ht = {
762
+ position: "absolute",
763
+ pointerEvents: "auto"
764
+ }, mt = ({
765
+ direction: t,
766
+ trackIndex: e,
767
+ align: n,
768
+ gap: o,
769
+ span: r,
770
+ onResize: s
771
+ }) => {
772
+ const u = t === "col" ? "vertical" : "horizontal", c = i.useCallback(
773
+ (g) => {
774
+ const f = n === "start" ? -g : g;
775
+ s(t, e, f);
776
+ },
777
+ [n, t, e, s]
778
+ ), a = i.useMemo(() => t === "col" ? {
779
+ gridColumn: `${e + 1} / ${e + 2}`,
780
+ gridRow: `${r.start} / ${r.end}`
781
+ } : {
782
+ gridRow: `${e + 1} / ${e + 2}`,
783
+ gridColumn: `${r.start} / ${r.end}`
784
+ }, [t, e, r]), l = i.useMemo(() => {
785
+ const f = Math.max(0, o) / 2 + Q / 2;
786
+ return t === "col" ? {
787
+ ...ht,
788
+ width: Q,
789
+ height: "100%",
790
+ top: 0,
791
+ bottom: 0,
792
+ ...n === "start" ? { left: -f } : { right: -f }
793
+ } : {
794
+ ...ht,
795
+ width: "100%",
796
+ height: Q,
797
+ left: 0,
798
+ right: 0,
799
+ ...n === "start" ? { top: -f } : { bottom: -f }
800
+ };
801
+ }, [n, t, o]);
802
+ return /* @__PURE__ */ h("div", { "data-resizable": "true", style: { ...a, position: "relative", pointerEvents: "none" }, children: /* @__PURE__ */ h("div", { "data-direction": u, "data-align": n, "data-handle": "true", style: l, children: /* @__PURE__ */ h(je, { direction: u, onResize: c }) }) });
803
+ }, Ke = (t) => {
804
+ const e = /* @__PURE__ */ new Map();
805
+ t.forEach((o, r) => {
806
+ o.forEach((s, u) => {
807
+ if (!s || s === ".")
808
+ return;
809
+ const c = e.get(s);
810
+ if (c) {
811
+ const l = {
812
+ rowStart: Math.min(c.rowStart, r),
813
+ rowEnd: Math.max(c.rowEnd, r),
814
+ colStart: Math.min(c.colStart, u),
815
+ colEnd: Math.max(c.colEnd, u)
816
+ };
817
+ e.set(s, l);
818
+ return;
819
+ }
820
+ const a = {
821
+ rowStart: r,
822
+ rowEnd: r,
823
+ colStart: u,
824
+ colEnd: u
825
+ };
826
+ e.set(s, a);
827
+ });
828
+ });
829
+ const n = /* @__PURE__ */ new Map();
830
+ return e.forEach((o, r) => {
831
+ const s = o.rowStart + 1, u = o.rowEnd + 2, c = o.colStart + 1, a = o.colEnd + 2, l = {
832
+ gridArea: r,
833
+ gridRow: `${s} / ${u}`,
834
+ gridColumn: `${c} / ${a}`
835
+ };
836
+ n.set(r, l);
837
+ }), n;
838
+ }, Ze = (t, e) => {
839
+ if ((t.positionMode ?? "grid") !== "grid")
840
+ return t;
841
+ const o = t.gridArea ?? t.id, r = e.get(o);
842
+ if (!r)
843
+ return t;
844
+ const s = !t.gridArea, u = !t.gridRow, c = !t.gridColumn;
845
+ return !s && !u && !c ? t : {
846
+ ...t,
847
+ gridArea: s ? r.gridArea : t.gridArea,
848
+ gridRow: u ? r.gridRow : t.gridRow,
849
+ gridColumn: c ? r.gridColumn : t.gridColumn
850
+ };
851
+ }, qe = (t, e) => {
852
+ const n = i.useMemo(() => Ke(t.areas), [t.areas]), o = i.useMemo(() => e.map((c) => Ze(c, n)), [e, n]), r = i.useMemo(
853
+ () => o.filter((c) => c.visible !== !1),
854
+ [o]
855
+ ), s = i.useMemo(
856
+ () => r.filter((c) => !c.drawer),
857
+ [r]
858
+ ), u = i.useMemo(() => {
859
+ const c = /* @__PURE__ */ new Map();
860
+ return o.forEach((a) => {
861
+ c.set(a.id, a);
862
+ }), c;
863
+ }, [o]);
864
+ return {
865
+ normalizedLayers: o,
866
+ visibleLayers: r,
867
+ regularLayers: s,
868
+ layerById: u
869
+ };
870
+ }, Je = (t) => {
871
+ if (!t)
872
+ return { rowGap: 0, columnGap: 0 };
873
+ const e = t.split(/\s+/).map((o) => o.trim()).filter(Boolean), n = (o) => {
874
+ const r = o.match(/^(-?\d+(?:\.\d+)?)px$/);
875
+ return r ? Number.parseFloat(r[1]) : 0;
876
+ };
877
+ if (e.length === 1) {
878
+ const o = n(e[0]);
879
+ return { rowGap: o, columnGap: o };
880
+ }
881
+ return {
882
+ rowGap: n(e[0]),
883
+ columnGap: n(e[1])
884
+ };
885
+ }, Qe = (t, e) => {
886
+ if (!t)
887
+ return [];
888
+ const n = getComputedStyle(t);
889
+ return (e === "col" ? n.gridTemplateColumns : n.gridTemplateRows).split(/\s+/).map((r) => parseFloat(r)).filter((r) => !Number.isNaN(r));
890
+ }, Yt = (t, e = Number.NEGATIVE_INFINITY, n = Number.POSITIVE_INFINITY) => Math.min(Math.max(t, e), n), Un = (t, e) => typeof t != "number" || !Number.isFinite(t) ? e : t, K = (t, e) => `${t}-${e}`, tn = (t, e, n, o) => {
891
+ const r = K(n, o), s = e[r];
892
+ return s !== void 0 ? `minmax(${t.minSize ?? 0}px, ${s}px)` : t.size;
893
+ }, wt = (t, e, n) => t.map((o, r) => tn(o, e, n, r)).join(" "), X = (t, e) => t.reduce((n, o, r) => (o.resizable && o.size.endsWith("px") && (n[K(e, r)] = parseInt(o.size, 10)), n), {}), en = ({
894
+ trackSizes: t,
895
+ track: e,
896
+ direction: n,
897
+ trackIndex: o,
898
+ containerRef: r
899
+ }) => {
900
+ const s = K(n, o), u = t[s];
901
+ if (u !== void 0)
902
+ return u;
903
+ const a = Qe(r?.current ?? null, n)[o];
904
+ return a !== void 0 && a > 0 ? a : e.size.endsWith("px") ? Number.parseInt(e.size, 10) : 300;
905
+ }, nn = (t, e) => t.reduce((n, o, r) => r === e ? n : o.size.includes("fr") ? n + 100 : n + (o.minSize ?? 50), 0), on = ({
906
+ track: t,
907
+ tracks: e,
908
+ trackIndex: n,
909
+ direction: o,
910
+ containerRef: r,
911
+ gapSizes: s
912
+ }) => {
913
+ if (!r?.current)
914
+ return t.maxSize;
915
+ const u = o === "col" ? r.current.offsetWidth : r.current.offsetHeight, c = nn(e, n), a = e.length - 1, l = o === "col" ? s.columnGap : s.rowGap, g = a * l, f = u - c - g;
916
+ return t.maxSize !== void 0 ? Math.min(t.maxSize, f) : f;
917
+ }, rn = (t, e, n) => Yt(t, e ?? Number.NEGATIVE_INFINITY, n ?? Number.POSITIVE_INFINITY), bt = (t, e) => {
918
+ const n = t.length, o = [];
919
+ for (let u = 0; u < n; u++) {
920
+ const c = t[u], a = c[e], l = c[e + 1];
921
+ a !== l && o.push(u);
922
+ }
923
+ if (o.length === 0)
924
+ return { start: 1, end: n + 1 };
925
+ const r = Math.min(...o), s = Math.max(...o);
926
+ return { start: r + 1, end: s + 2 };
927
+ }, vt = (t, e) => {
928
+ const n = t[e], o = t[e + 1], r = n?.length ?? 0, s = [];
929
+ for (let a = 0; a < r; a++) {
930
+ const l = n?.[a], g = o?.[a];
931
+ l !== g && s.push(a);
932
+ }
933
+ if (s.length === 0)
934
+ return { start: 1, end: r + 1 };
935
+ const u = Math.min(...s), c = Math.max(...s);
936
+ return { start: u + 1, end: c + 2 };
937
+ }, sn = (t, e) => {
938
+ if (t.length === 0)
939
+ return [];
940
+ const n = e.length;
941
+ if (t.length === 1)
942
+ return t[0]?.resizable ? [{ trackIndex: 0, align: "end", span: { start: 1, end: n + 1 } }] : [];
943
+ const o = [];
944
+ return Array.from({ length: t.length - 1 }, (s, u) => u).forEach((s) => {
945
+ const u = t[s];
946
+ if (t[s + 1]?.resizable) {
947
+ const a = bt(e, s);
948
+ o.push({ trackIndex: s + 1, align: "start", span: a });
949
+ return;
950
+ }
951
+ if (u?.resizable) {
952
+ const a = bt(e, s);
953
+ o.push({ trackIndex: s, align: "end", span: a });
954
+ }
955
+ }), o;
956
+ }, an = (t, e) => {
957
+ if (t.length === 0)
958
+ return [];
959
+ const n = e[0]?.length ?? 0;
960
+ if (t.length === 1)
961
+ return t[0]?.resizable ? [{ trackIndex: 0, align: "end", span: { start: 1, end: n + 1 } }] : [];
962
+ const o = [];
963
+ return Array.from({ length: t.length - 1 }, (s, u) => u).forEach((s) => {
964
+ const u = t[s];
965
+ if (t[s + 1]?.resizable) {
966
+ const a = vt(e, s);
967
+ o.push({ trackIndex: s + 1, align: "start", span: a });
968
+ return;
969
+ }
970
+ if (u?.resizable) {
971
+ const a = vt(e, s);
972
+ o.push({ trackIndex: s, align: "end", span: a });
973
+ }
974
+ }), o;
975
+ }, cn = (t) => t !== void 0 ? { gap: t } : {}, un = (t, e) => {
976
+ const n = Object.keys(e), o = {};
977
+ for (const g of n)
978
+ o[g] = t[g] ?? e[g];
979
+ const r = Object.keys(t), s = r.length !== n.length, u = r.some(
980
+ (g) => !Object.prototype.hasOwnProperty.call(o, g)
981
+ ), c = s ? !0 : u, a = n.some((g) => t[g] !== o[g]);
982
+ return (c ? !0 : a) ? o : null;
983
+ }, ln = (t, e, n) => {
984
+ const [o, r] = i.useState(() => ({
985
+ ...X(t.columns, "col"),
986
+ ...X(t.rows, "row")
987
+ }));
988
+ It(() => {
989
+ const f = {
990
+ ...X(t.columns, "col"),
991
+ ...X(t.rows, "row")
992
+ };
993
+ r((m) => un(m, f) ?? m);
994
+ }, [t.columns, t.rows]);
995
+ const s = i.useMemo(() => t.areas.map((f) => `"${f.join(" ")}"`).join(" "), [t.areas]), u = i.useMemo(() => Je(t.gap), [t.gap]), c = i.useMemo(
996
+ () => sn(t.columns, t.areas),
997
+ [t.columns, t.areas]
998
+ ), a = i.useMemo(
999
+ () => an(t.rows, t.areas),
1000
+ [t.rows, t.areas]
1001
+ ), l = i.useMemo(() => ({
1002
+ ...t.style,
1003
+ ...e,
1004
+ gridTemplateAreas: s,
1005
+ gridTemplateRows: wt(t.rows, o, "row"),
1006
+ gridTemplateColumns: wt(t.columns, o, "col"),
1007
+ ...cn(t.gap)
1008
+ }), [s, t.columns, t.gap, t.rows, t.style, e, o]), g = i.useCallback(
1009
+ (f, m, w) => {
1010
+ const C = f === "row" ? t.rows : t.columns, z = C[m];
1011
+ if (!z || !z.resizable)
1012
+ return;
1013
+ const y = en({
1014
+ trackSizes: o,
1015
+ track: z,
1016
+ direction: f,
1017
+ trackIndex: m,
1018
+ containerRef: n
1019
+ }), L = on({
1020
+ track: z,
1021
+ tracks: C,
1022
+ trackIndex: m,
1023
+ direction: f,
1024
+ containerRef: n,
1025
+ gapSizes: u
1026
+ }), x = K(f, m);
1027
+ r(($) => {
1028
+ const M = y + w, D = rn(M, z.minSize, L);
1029
+ return { ...$, [x]: D };
1030
+ });
1031
+ },
1032
+ [t.columns, t.rows, o, n, u]
1033
+ );
1034
+ return {
1035
+ columnHandles: c,
1036
+ rowHandles: a,
1037
+ gapSizes: u,
1038
+ gridStyle: l,
1039
+ handleResize: g
1040
+ };
1041
+ }, dn = (t) => t.positionMode ? t.positionMode : t.floating ? (t.floating.mode ?? "embedded") === "embedded" ? "absolute" : "relative" : "grid", fn = (t) => ({ position: t === "grid" ? "relative" : t }), gn = (t, e) => e !== "grid" ? {} : {
1042
+ gridArea: t.gridArea,
1043
+ gridRow: t.gridRow,
1044
+ gridColumn: t.gridColumn
1045
+ }, pn = (t) => t ? {
1046
+ top: t.top,
1047
+ right: t.right,
1048
+ bottom: t.bottom,
1049
+ left: t.left
1050
+ } : {}, hn = (t) => t !== void 0 ? { zIndex: t } : {}, mn = (t, e) => ({
1051
+ width: t,
1052
+ height: e
1053
+ }), wn = (t, e) => t.pointerEvents !== void 0 ? typeof t.pointerEvents == "boolean" ? { pointerEvents: t.pointerEvents ? "auto" : "none" } : { pointerEvents: t.pointerEvents } : e === "absolute" || e === "fixed" ? { pointerEvents: "auto" } : {}, bn = (t) => t.floating ? t.floating.position ?? t.floating.defaultPosition ?? t.position : t.position, vn = (t) => {
1054
+ if (t.floating) {
1055
+ const e = t.floating.size ?? t.floating.defaultSize;
1056
+ if (e)
1057
+ return {
1058
+ width: e.width,
1059
+ height: e.height
1060
+ };
1061
+ }
1062
+ return {
1063
+ width: t.width,
1064
+ height: t.height
1065
+ };
1066
+ }, Sn = (t) => t.floating?.zIndex !== void 0 ? t.floating.zIndex : t.zIndex, Cn = (t) => {
1067
+ const e = dn(t), n = bn(t), o = vn(t), r = Sn(t);
1068
+ return {
1069
+ ...t.style,
1070
+ ...fn(e),
1071
+ ...gn(t, e),
1072
+ ...pn(n),
1073
+ ...hn(r),
1074
+ ...mn(o.width, o.height),
1075
+ ...wn(t, e)
1076
+ };
1077
+ }, zn = (t) => {
1078
+ const e = t.floating;
1079
+ return e ? e.mode ?? "embedded" : null;
1080
+ }, _ = (t) => zn(t) !== "embedded" ? null : t.floating ?? null, St = (t) => t instanceof HTMLElement ? ["INPUT", "TEXTAREA", "SELECT", "BUTTON"].includes(t.tagName) : !1, Ct = (t, e, n) => {
1081
+ const o = e ?? Number.NEGATIVE_INFINITY, r = n ?? Number.POSITIVE_INFINITY;
1082
+ return Yt(t, o, r);
1083
+ }, zt = (t, e, n) => {
1084
+ if (typeof t == "number" && Number.isFinite(t))
1085
+ return t;
1086
+ throw new Error(
1087
+ `Floating layer "${n}" must provide a numeric "${e}" value when draggable mode is enabled.`
1088
+ );
1089
+ }, Et = (t) => {
1090
+ const e = _(t);
1091
+ if (!e)
1092
+ throw new Error(`Floating layer "${t.id}" is missing floating configuration required for dragging.`);
1093
+ const n = e.position ?? e.defaultPosition ?? t.position;
1094
+ if (!n)
1095
+ throw new Error(`Floating layer "${t.id}" must define position with left and top values.`);
1096
+ return {
1097
+ left: zt(n.left, "left", t.id),
1098
+ top: zt(n.top, "top", t.id)
1099
+ };
1100
+ }, En = (t) => {
1101
+ const e = _(t);
1102
+ return e ? e.constraints ?? {} : {};
1103
+ }, Rn = (t, e, n) => t ? t === "left" ? e - n : e + n : e, Pn = (t, e, n) => t ? t === "top" ? e - n : e + n : e, yn = (t, e, n) => !t || t === "right" ? e : e + n, Ln = (t, e, n) => !t || t === "bottom" ? e : e + n, nt = (t, e) => t ? t.dataset.layerId === e ? t : nt(t.parentElement, e) : null, ot = (t, e, n) => !t || n?.(t) ? null : e(t) ? t : ot(t.parentElement, e, n), Mn = (t) => t instanceof HTMLElement ? ot(
1104
+ t,
1105
+ (e) => e.dataset.dragHandle === "true",
1106
+ (e) => e.dataset.dragIgnore === "true"
1107
+ ) : null, Rt = (t) => t instanceof HTMLElement ? ot(
1108
+ t,
1109
+ (e) => e.dataset.resizeCorner !== void 0 || e.dataset.resizeEdge !== void 0
1110
+ ) !== null : !1, U = (t) => {
1111
+ const e = _(t);
1112
+ return e ? e.resizable === !0 : !1;
1113
+ }, j = (t) => {
1114
+ if (!_(t))
1115
+ return null;
1116
+ const n = Tn(t);
1117
+ if (!n)
1118
+ throw new Error(`Floating layer "${t.id}" must define width and height when resizable or draggable.`);
1119
+ return {
1120
+ width: n.width,
1121
+ height: n.height
1122
+ };
1123
+ }, Dn = (t, e, n) => {
1124
+ const o = t.filter(U).reduce((f, m) => {
1125
+ if (n === m.id) {
1126
+ const C = e[m.id];
1127
+ if (C)
1128
+ return f[m.id] = C, f;
1129
+ }
1130
+ const w = j(m);
1131
+ return w && (f[m.id] = w), f;
1132
+ }, {}), r = Object.keys(e), s = Object.keys(o), u = r.length !== s.length, c = r.some((f) => !Object.prototype.hasOwnProperty.call(o, f)), a = u ? !0 : c, l = s.some((f) => {
1133
+ const m = e[f], w = o[f];
1134
+ return !m || !w ? !0 : m.width !== w.width || m.height !== w.height;
1135
+ });
1136
+ return {
1137
+ sizes: o,
1138
+ changed: a ? !0 : l
1139
+ };
1140
+ }, In = ({
1141
+ layers: t,
1142
+ layerById: e,
1143
+ isRootLevel: n
1144
+ }) => {
1145
+ const [o, r] = i.useState(null), [s, u] = i.useState(null), [c, a] = i.useState({}), [l, g] = i.useState({}), f = i.useRef(null), m = i.useRef(null), w = W((p, d) => {
1146
+ e.get(p)?.floating?.onMove?.(d);
1147
+ }), C = W((p, d) => {
1148
+ e.get(p)?.floating?.onResize?.(d);
1149
+ });
1150
+ It(() => {
1151
+ const { sizes: p, changed: d } = Dn(t, l, s);
1152
+ d && g(p);
1153
+ }, [t, s]);
1154
+ const z = i.useCallback(
1155
+ (p, d, b, v) => {
1156
+ const S = Et(d), P = c[p] ?? { x: 0, y: 0 }, E = {
1157
+ pointerStartX: v.clientX,
1158
+ pointerStartY: v.clientY,
1159
+ initialTranslationX: P.x,
1160
+ initialTranslationY: P.y,
1161
+ baseLeft: S.left,
1162
+ baseTop: S.top,
1163
+ layerId: p,
1164
+ pointerId: v.pointerId,
1165
+ target: b
1166
+ };
1167
+ if (E.target.setPointerCapture)
1168
+ try {
1169
+ E.target.setPointerCapture(E.pointerId);
1170
+ } catch {
1171
+ }
1172
+ f.current = E, r(p);
1173
+ },
1174
+ [c]
1175
+ ), y = i.useCallback(
1176
+ (p) => {
1177
+ const d = p.target, b = Mn(d);
1178
+ if (!b)
1179
+ return;
1180
+ const v = b.closest("[data-layer-id]")?.getAttribute("data-layer-id");
1181
+ if (!v)
1182
+ return;
1183
+ const S = e.get(v);
1184
+ if (!S)
1185
+ return;
1186
+ const P = _(S);
1187
+ if (!(!P || P.draggable !== !0) && !St(p.target) && !Rt(p.target) && b) {
1188
+ const E = nt(b, v);
1189
+ if (!E)
1190
+ return;
1191
+ z(v, S, E, p);
1192
+ return;
1193
+ }
1194
+ },
1195
+ [z, e]
1196
+ ), L = i.useCallback(
1197
+ (p, d) => {
1198
+ const b = e.get(p), v = b ? _(b) : null;
1199
+ if (!b || !v || v.draggable !== !0 || St(d.target) || Rt(d.target))
1200
+ return;
1201
+ const S = nt(d.currentTarget, p);
1202
+ S && z(p, b, S, d);
1203
+ },
1204
+ [z, e]
1205
+ ), x = i.useCallback(
1206
+ (p, d, b) => {
1207
+ const v = e.get(p);
1208
+ if (!v || !U(v))
1209
+ return;
1210
+ const S = l[p] ?? j(v);
1211
+ if (!S)
1212
+ return;
1213
+ const P = Et(v), E = En(v), k = c[p] ?? { x: 0, y: 0 };
1214
+ if (b.stopPropagation(), b.preventDefault(), b.currentTarget.setPointerCapture)
1215
+ try {
1216
+ b.currentTarget.setPointerCapture(b.pointerId);
1217
+ } catch {
1218
+ }
1219
+ m.current = {
1220
+ layerId: p,
1221
+ pointerId: b.pointerId,
1222
+ horizontalEdge: d.horizontal,
1223
+ verticalEdge: d.vertical,
1224
+ startX: b.clientX,
1225
+ startY: b.clientY,
1226
+ startWidth: S.width,
1227
+ startHeight: S.height,
1228
+ startPosition: k,
1229
+ baseLeft: P.left,
1230
+ baseTop: P.top,
1231
+ minWidth: E.minWidth,
1232
+ maxWidth: E.maxWidth,
1233
+ minHeight: E.minHeight,
1234
+ maxHeight: E.maxHeight,
1235
+ target: b.currentTarget
1236
+ }, u(p);
1237
+ },
1238
+ [e, c, l]
1239
+ ), $ = i.useCallback(
1240
+ (p) => {
1241
+ const d = f.current;
1242
+ if (!d)
1243
+ return;
1244
+ const b = p.clientX - d.pointerStartX, v = p.clientY - d.pointerStartY, S = {
1245
+ x: d.initialTranslationX + b,
1246
+ y: d.initialTranslationY + v
1247
+ };
1248
+ a((P) => ({ ...P, [d.layerId]: S })), w(d.layerId, {
1249
+ left: d.baseLeft + S.x,
1250
+ top: d.baseTop + S.y
1251
+ });
1252
+ },
1253
+ [w]
1254
+ ), M = i.useCallback(
1255
+ (p) => {
1256
+ const d = m.current;
1257
+ if (!d || d.pointerId !== p.pointerId || !e.get(d.layerId))
1258
+ return;
1259
+ const v = p.clientX - d.startX, S = p.clientY - d.startY, P = Rn(d.horizontalEdge, d.startWidth, v), E = Pn(d.verticalEdge, d.startHeight, S), k = Ct(P, d.minWidth, d.maxWidth), F = Ct(E, d.minHeight, d.maxHeight), O = d.startWidth - k, Z = d.startHeight - F, it = yn(
1260
+ d.horizontalEdge,
1261
+ d.startPosition.x,
1262
+ O
1263
+ ), Xt = Ln(d.verticalEdge, d.startPosition.y, Z), q = l[d.layerId], at = { width: k, height: F };
1264
+ (!q || q.width !== k || q.height !== F) && (g((J) => ({
1265
+ ...J,
1266
+ [d.layerId]: at
1267
+ })), C(d.layerId, at));
1268
+ const ct = c[d.layerId] ?? { x: 0, y: 0 }, B = { x: it, y: Xt };
1269
+ (ct.x !== B.x || ct.y !== B.y) && (a((J) => ({
1270
+ ...J,
1271
+ [d.layerId]: B
1272
+ })), w(d.layerId, {
1273
+ left: d.baseLeft + B.x,
1274
+ top: d.baseTop + B.y
1275
+ }));
1276
+ },
1277
+ [e, c, l, w, C]
1278
+ ), D = i.useCallback((p) => {
1279
+ const d = f.current;
1280
+ if (d) {
1281
+ if (d.pointerId === p.pointerId && d.target.releasePointerCapture)
1282
+ try {
1283
+ d.target.releasePointerCapture(d.pointerId);
1284
+ } catch {
1285
+ }
1286
+ f.current = null;
1287
+ }
1288
+ r(null);
1289
+ }, []), A = i.useCallback((p) => {
1290
+ const d = m.current;
1291
+ if (d) {
1292
+ if (d.pointerId === p.pointerId && d.target.releasePointerCapture)
1293
+ try {
1294
+ d.target.releasePointerCapture(d.pointerId);
1295
+ } catch {
1296
+ }
1297
+ m.current = null;
1298
+ }
1299
+ u(null);
1300
+ }, []);
1301
+ et(o !== null, {
1302
+ onMove: $,
1303
+ onUp: D,
1304
+ onCancel: D
1305
+ }), et(s !== null, {
1306
+ onMove: M,
1307
+ onUp: A,
1308
+ onCancel: A
1309
+ });
1310
+ const I = i.useCallback(
1311
+ (p) => {
1312
+ const d = Cn(p), b = _(p);
1313
+ if (!b || b.draggable !== !0)
1314
+ return d;
1315
+ const v = c[p.id], S = o === p.id, P = s === p.id, E = v ? { transform: `translate(${v.x}px, ${v.y}px)` } : {}, k = l[p.id], F = U(p) ? j(p) : null, O = k ?? F, Z = O ? { width: `${O.width}px`, height: `${O.height}px` } : {};
1316
+ return {
1317
+ ...d,
1318
+ ...Z,
1319
+ ...E,
1320
+ ...S || P ? { cursor: "grabbing" } : {}
1321
+ };
1322
+ },
1323
+ [o, c, l, s]
1324
+ ), R = i.useCallback(
1325
+ (p) => {
1326
+ if (!U(p))
1327
+ return { isResizable: !1 };
1328
+ const b = l[p.id], v = j(p);
1329
+ return (b ?? v) !== null ? { isResizable: !0, onPointerDown: (k, F) => {
1330
+ x(p.id, k, F);
1331
+ } } : { isResizable: !1 };
1332
+ },
1333
+ [x, l]
1334
+ ), rt = i.useCallback(
1335
+ (p) => {
1336
+ const { isResizable: d, onPointerDown: b } = R(p), v = I(p), S = s === p.id;
1337
+ return {
1338
+ style: v,
1339
+ isResizable: d,
1340
+ isResizing: S,
1341
+ onResizeHandlePointerDown: (P, E) => {
1342
+ b && b(P, E);
1343
+ }
1344
+ };
1345
+ },
1346
+ [I, R, s]
1347
+ ), st = i.useCallback(
1348
+ (p) => ({
1349
+ "data-drag-handle": "true",
1350
+ role: "button",
1351
+ "aria-roledescription": "Drag handle",
1352
+ "aria-label": "Drag layer",
1353
+ onPointerDown: (d) => {
1354
+ L(p, d);
1355
+ }
1356
+ }),
1357
+ [L]
1358
+ );
1359
+ return {
1360
+ providerValue: i.useMemo(
1361
+ () => ({
1362
+ handleLayerPointerDown: y,
1363
+ getLayerRenderState: rt,
1364
+ getLayerHandleProps: st,
1365
+ isRootLevel: n
1366
+ }),
1367
+ [st, rt, y, n]
1368
+ ),
1369
+ draggingLayerId: o,
1370
+ resizingLayerId: s
1371
+ };
1372
+ }, Tn = (t) => {
1373
+ if (t.floating) {
1374
+ const e = t.floating.size ?? t.floating.defaultSize;
1375
+ if (e)
1376
+ return { width: e.width, height: e.height };
1377
+ }
1378
+ if (typeof t.width == "number" && typeof t.height == "number")
1379
+ return { width: t.width, height: t.height };
1380
+ }, Vt = {
1381
+ display: "grid",
1382
+ width: "100%",
1383
+ height: "100%",
1384
+ overflow: "hidden"
1385
+ }, xn = {
1386
+ touchAction: "none",
1387
+ WebkitTouchCallout: "none",
1388
+ WebkitUserSelect: "none",
1389
+ userSelect: "none"
1390
+ }, kn = {
1391
+ ...Vt,
1392
+ overflow: "visible",
1393
+ height: "auto",
1394
+ minHeight: "100%"
1395
+ }, An = (t) => t ? kn : Vt, jn = ({ config: t, layers: e, style: n, root: o = !1 }) => {
1396
+ const r = i.useRef(null), { isIntersecting: s } = de(r, { threshold: 0 });
1397
+ return /* @__PURE__ */ h(Ee, { config: t, layers: e, style: n, children: /* @__PURE__ */ h(Hn, { gridRef: r, isIntersecting: s, isRoot: o }) });
1398
+ }, Hn = ({ gridRef: t, isIntersecting: e, isRoot: n }) => {
1399
+ const { config: o, style: r, layers: s } = Ht(), { normalizedLayers: u, visibleLayers: c, regularLayers: a, layerById: l } = qe(o, s.defs), { columnHandles: g, rowHandles: f, gapSizes: m, gridStyle: w, handleResize: C } = ln(o, r, t), { providerValue: z, draggingLayerId: y, resizingLayerId: L } = In({
1400
+ layers: u,
1401
+ layerById: l,
1402
+ isRootLevel: n
1403
+ }), x = y ? !0 : !!L, $ = i.useMemo(() => ({
1404
+ ...An(n),
1405
+ ...w,
1406
+ ...x ? xn : {}
1407
+ }), [w, x, n]);
1408
+ return /* @__PURE__ */ H(N, { children: [
1409
+ /* @__PURE__ */ H(
1410
+ "div",
1411
+ {
1412
+ ref: t,
1413
+ style: $,
1414
+ "data-dragging": !!y,
1415
+ "data-resizing": !!L,
1416
+ "data-visible": e,
1417
+ children: [
1418
+ /* @__PURE__ */ h(ze, { value: z, children: /* @__PURE__ */ h(Fe, { layers: a }) }),
1419
+ g.map(({ trackIndex: M, align: D, span: A }) => /* @__PURE__ */ h(
1420
+ mt,
1421
+ {
1422
+ direction: "col",
1423
+ trackIndex: M,
1424
+ align: D,
1425
+ gap: m.columnGap,
1426
+ span: A,
1427
+ onResize: C
1428
+ },
1429
+ `col-${M}:${D}`
1430
+ )),
1431
+ f.map(({ trackIndex: M, align: D, span: A }) => /* @__PURE__ */ h(
1432
+ mt,
1433
+ {
1434
+ direction: "row",
1435
+ trackIndex: M,
1436
+ align: D,
1437
+ gap: m.rowGap,
1438
+ span: A,
1439
+ onResize: C
1440
+ },
1441
+ `row-${M}:${D}`
1442
+ ))
1443
+ ]
1444
+ }
1445
+ ),
1446
+ /* @__PURE__ */ h(Ce, { layers: c })
1447
+ ] });
1448
+ };
1449
+ export {
1450
+ we as D,
1451
+ _t as F,
1452
+ jn as G,
1453
+ je as R,
1454
+ Xn as a,
1455
+ kt as b,
1456
+ W as c,
1457
+ Ye as d,
1458
+ Yt as e,
1459
+ Ce as f,
1460
+ Vn as g,
1461
+ Tt as r,
1462
+ Un as t,
1463
+ Oe as u
1464
+ };
1465
+ //# sourceMappingURL=GridLayout-BzrIDrC9.js.map