react-panel-layout 0.4.1 → 0.5.0

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