react-tiling-workspace 0.0.0-stage → 0.1.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 (48) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +147 -2
  3. package/dist/components/LayoutPickerDialog-C-Sb3uOl.cjs +517 -0
  4. package/dist/components/LayoutPickerDialog-C-Sb3uOl.cjs.map +1 -0
  5. package/dist/components/LayoutPickerDialog-STglqYFI.mjs +500 -0
  6. package/dist/components/LayoutPickerDialog-STglqYFI.mjs.map +1 -0
  7. package/dist/components/icons-0kjsH_LJ.cjs +144 -0
  8. package/dist/components/icons-0kjsH_LJ.cjs.map +1 -0
  9. package/dist/components/icons-BgtEPXL8.mjs +97 -0
  10. package/dist/components/icons-BgtEPXL8.mjs.map +1 -0
  11. package/dist/components/layout-picker.cjs +5 -0
  12. package/dist/components/layout-picker.d.cts +22 -0
  13. package/dist/components/layout-picker.d.mts +22 -0
  14. package/dist/components/layout-picker.mjs +2 -0
  15. package/dist/components/mobile.cjs +575 -0
  16. package/dist/components/mobile.cjs.map +1 -0
  17. package/dist/components/mobile.d.cts +42 -0
  18. package/dist/components/mobile.d.mts +42 -0
  19. package/dist/components/mobile.mjs +574 -0
  20. package/dist/components/mobile.mjs.map +1 -0
  21. package/dist/components/topbar.cjs +94 -0
  22. package/dist/components/topbar.cjs.map +1 -0
  23. package/dist/components/topbar.d.cts +38 -0
  24. package/dist/components/topbar.d.mts +38 -0
  25. package/dist/components/topbar.mjs +93 -0
  26. package/dist/components/topbar.mjs.map +1 -0
  27. package/dist/components/types-DkwWFcD5.d.mts +32 -0
  28. package/dist/components/types-qsXC_48o.d.cts +32 -0
  29. package/dist/index.cjs +3336 -0
  30. package/dist/index.cjs.map +1 -0
  31. package/dist/index.d.cts +243 -0
  32. package/dist/index.d.mts +243 -0
  33. package/dist/index.mjs +3320 -0
  34. package/dist/index.mjs.map +1 -0
  35. package/dist/server/server.cjs +104 -0
  36. package/dist/server/server.cjs.map +1 -0
  37. package/dist/server/server.d.cts +71 -0
  38. package/dist/server/server.d.mts +71 -0
  39. package/dist/server/server.mjs +95 -0
  40. package/dist/server/server.mjs.map +1 -0
  41. package/dist/server/shortcuts.cjs +32 -0
  42. package/dist/server/shortcuts.cjs.map +1 -0
  43. package/dist/server/shortcuts.d.cts +6 -0
  44. package/dist/server/shortcuts.d.mts +6 -0
  45. package/dist/server/shortcuts.mjs +31 -0
  46. package/dist/server/shortcuts.mjs.map +1 -0
  47. package/dist/theme.css +119 -0
  48. package/package.json +113 -4
package/dist/index.mjs ADDED
@@ -0,0 +1,3320 @@
1
+ "use client";
2
+ import { Fragment, useCallback, useEffect, useId, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState } from "react";
3
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
4
+ // src/hooks/useIsDesktop.ts
5
+ /**
6
+ * Returns whether the viewport matches the desktop breakpoint (`>= breakpointPx`, default `1024px`).
7
+ * Returns `null` during SSR and before client mount to avoid hydration mismatches.
8
+ */
9
+ function useIsDesktop(breakpointPx = 1024) {
10
+ const [isDesktop, setIsDesktop] = useState(null);
11
+ useEffect(() => {
12
+ const mql = window.matchMedia(`(min-width: ${breakpointPx}px)`);
13
+ const update = () => setIsDesktop(mql.matches);
14
+ update();
15
+ mql.addEventListener("change", update);
16
+ return () => mql.removeEventListener("change", update);
17
+ }, [breakpointPx]);
18
+ return isDesktop;
19
+ }
20
+ // src/layout.ts
21
+ const MAX_WORKSPACE_SPLIT_DEPTH = 4;
22
+ function computeReadingTargetPx(direction, openTotalPx, openCount) {
23
+ const minOpenPx = direction === "horizontal" ? 120 : 92;
24
+ const preferredReadingPx = direction === "horizontal" ? 320 : 220;
25
+ const equalSharePx = Math.floor(openTotalPx / Math.max(1, openCount));
26
+ return Math.max(minOpenPx + 24, Math.min(preferredReadingPx, equalSharePx));
27
+ }
28
+ function findPanelPath(node, id) {
29
+ if (!node) return null;
30
+ if (node.type === "panel") return node.id === id ? [] : null;
31
+ for (let i = 0; i < node.children.length; i += 1) {
32
+ const subPath = findPanelPath(node.children[i], id);
33
+ if (subPath !== null) return [i, ...subPath];
34
+ }
35
+ return null;
36
+ }
37
+ function getResponsiveCompactAxis(widthPx, heightPx) {
38
+ if (widthPx < 120) return "horizontal";
39
+ if (heightPx < 92) return "vertical";
40
+ return null;
41
+ }
42
+ function getPanelIds(tree) {
43
+ if (!tree) return [];
44
+ if (tree.type === "panel") return [tree.id];
45
+ return tree.children.flatMap((child) => getPanelIds(child));
46
+ }
47
+ function isNodeFolded(node, folds) {
48
+ if (node.type === "panel") return (folds[node.id] ?? "open") === "folded";
49
+ return node.children.length > 0 && node.children.every((child) => isNodeFolded(child, folds));
50
+ }
51
+ function setNodeFoldState(node, folds, state) {
52
+ const ids = getPanelIds(node);
53
+ if (ids.length === 0) return folds;
54
+ let changed = false;
55
+ for (const id of ids) if ((folds[id] ?? "open") !== state) {
56
+ changed = true;
57
+ break;
58
+ }
59
+ if (!changed) return folds;
60
+ const next = { ...folds };
61
+ for (const id of ids) next[id] = state;
62
+ return next;
63
+ }
64
+ function normalizeLayoutTree(node) {
65
+ if (node.type === "panel") return node;
66
+ const rawSizes = node.children.map((_, index) => node.sizes?.[index] ?? 1);
67
+ const nextChildren = [];
68
+ const nextSizes = [];
69
+ let hasExplicitSizes = Boolean(node.sizes);
70
+ for (let i = 0; i < node.children.length; i += 1) {
71
+ const normalizedChild = normalizeLayoutTree(node.children[i]);
72
+ const weight = rawSizes[i];
73
+ if (normalizedChild.type === "split" && normalizedChild.direction === node.direction) {
74
+ const childSizes = normalizedChild.children.map((_, childIdx) => normalizedChild.sizes?.[childIdx] ?? 1);
75
+ const childTotal = childSizes.reduce((acc, value) => acc + value, 0) || 1;
76
+ for (let j = 0; j < normalizedChild.children.length; j += 1) {
77
+ nextChildren.push(normalizedChild.children[j]);
78
+ nextSizes.push(weight * (childSizes[j] / childTotal));
79
+ }
80
+ if (normalizedChild.sizes) hasExplicitSizes = true;
81
+ } else {
82
+ nextChildren.push(normalizedChild);
83
+ nextSizes.push(weight);
84
+ }
85
+ }
86
+ if (nextChildren.length === 1) return nextChildren[0];
87
+ return hasExplicitSizes ? {
88
+ type: "split",
89
+ direction: node.direction,
90
+ children: nextChildren,
91
+ sizes: nextSizes
92
+ } : {
93
+ type: "split",
94
+ direction: node.direction,
95
+ children: nextChildren
96
+ };
97
+ }
98
+ function validateLayoutTree(value, knownIds) {
99
+ const seen = /* @__PURE__ */ new Set();
100
+ function visit(node, splitDepthCount) {
101
+ if (!node || typeof node !== "object") return false;
102
+ const candidate = node;
103
+ if (candidate.type === "panel") {
104
+ if (typeof candidate.id !== "string" || !knownIds.has(candidate.id)) return false;
105
+ const id = candidate.id;
106
+ if (seen.has(id)) return false;
107
+ seen.add(id);
108
+ return true;
109
+ }
110
+ if (candidate.type !== "split" || candidate.direction !== "horizontal" && candidate.direction !== "vertical" || !Array.isArray(candidate.children) || candidate.children.length < 2 || splitDepthCount >= 4) return false;
111
+ if (candidate.sizes !== void 0 && (!Array.isArray(candidate.sizes) || candidate.sizes.length !== candidate.children.length || candidate.sizes.some((size) => typeof size !== "number" || !Number.isFinite(size) || size <= 0))) return false;
112
+ return candidate.children.every((child) => visit(child, splitDepthCount + 1));
113
+ }
114
+ return visit(value, 0);
115
+ }
116
+ function createHorizontalTree(ids) {
117
+ if (ids.length === 0) return null;
118
+ const children = ids.map((id) => ({
119
+ type: "panel",
120
+ id
121
+ }));
122
+ return children.length === 1 ? children[0] : {
123
+ type: "split",
124
+ direction: "horizontal",
125
+ children
126
+ };
127
+ }
128
+ function instantiateLayoutTemplate(template, ids) {
129
+ if (template.type === "panel") {
130
+ const id = ids[template.index];
131
+ return id === void 0 ? null : {
132
+ type: "panel",
133
+ id
134
+ };
135
+ }
136
+ const children = template.children.map((child) => instantiateLayoutTemplate(child, ids)).filter((child) => child !== null);
137
+ if (children.length === 0) return null;
138
+ if (children.length === 1) return children[0];
139
+ return normalizeLayoutTree({
140
+ type: "split",
141
+ direction: template.direction,
142
+ children
143
+ });
144
+ }
145
+ function layoutTemplateSignature(template) {
146
+ if (template.type === "panel") return "p";
147
+ return `${template.direction === "horizontal" ? "h" : "v"}(${template.children.map(layoutTemplateSignature).join(",")})`;
148
+ }
149
+ function layoutTreeSignature(tree) {
150
+ if (tree.type === "panel") return "p";
151
+ return `${tree.direction === "horizontal" ? "h" : "v"}(${tree.children.map(layoutTreeSignature).join(",")})`;
152
+ }
153
+ function removePanel(node, id) {
154
+ if (node.type === "panel") return node.id === id ? null : node;
155
+ const nextChildren = [];
156
+ const nextSizes = [];
157
+ for (let i = 0; i < node.children.length; i += 1) {
158
+ const child = removePanel(node.children[i], id);
159
+ if (child !== null) {
160
+ nextChildren.push(child);
161
+ nextSizes.push(node.sizes?.[i] ?? 1);
162
+ }
163
+ }
164
+ if (nextChildren.length === 0) return null;
165
+ if (nextChildren.length === 1) return nextChildren[0];
166
+ return normalizeLayoutTree({
167
+ ...node,
168
+ children: nextChildren,
169
+ sizes: node.sizes ? nextSizes : void 0
170
+ });
171
+ }
172
+ function insertBesidePanel(node, targetId, sourceId, position) {
173
+ if (node.type === "panel") {
174
+ if (node.id !== targetId) return node;
175
+ const source = {
176
+ type: "panel",
177
+ id: sourceId
178
+ };
179
+ return {
180
+ type: "split",
181
+ direction: position === "left" || position === "right" ? "horizontal" : "vertical",
182
+ children: position === "left" || position === "top" ? [source, node] : [node, source]
183
+ };
184
+ }
185
+ return normalizeLayoutTree({
186
+ ...node,
187
+ children: node.children.map((child) => insertBesidePanel(child, targetId, sourceId, position)),
188
+ sizes: node.sizes
189
+ });
190
+ }
191
+ function movePanelInTree(tree, sourceId, targetId, position, knownIds) {
192
+ if (!tree || sourceId === targetId) return null;
193
+ const stripped = removePanel(tree, sourceId);
194
+ if (!stripped) return {
195
+ type: "panel",
196
+ id: sourceId
197
+ };
198
+ const candidate = insertBesidePanel(stripped, targetId, sourceId, position);
199
+ if (splitDepth(candidate) > 4 || !validateLayoutTree(candidate, knownIds)) return null;
200
+ return candidate;
201
+ }
202
+ function getSplitAtPath(node, path) {
203
+ let current = node;
204
+ for (const index of path) {
205
+ if (current.type !== "split" || !current.children[index]) return null;
206
+ current = current.children[index];
207
+ }
208
+ return current;
209
+ }
210
+ function resizeSplitAtPath(node, path, index, firstSize, secondSize) {
211
+ if (path.length === 0) {
212
+ if (node.type !== "split") return node;
213
+ const sizes = node.children.map((_, childIndex) => node.sizes?.[childIndex] ?? 1);
214
+ if (index < 0 || index + 1 >= sizes.length) return node;
215
+ const pairTotal = sizes[index] + sizes[index + 1];
216
+ const measuredTotal = Math.max(1, firstSize + secondSize);
217
+ sizes[index] = Math.max(.05, pairTotal * (firstSize / measuredTotal));
218
+ sizes[index + 1] = Math.max(.05, pairTotal * (secondSize / measuredTotal));
219
+ return {
220
+ ...node,
221
+ sizes
222
+ };
223
+ }
224
+ if (node.type !== "split") return node;
225
+ const [head, ...tail] = path;
226
+ return {
227
+ ...node,
228
+ children: node.children.map((child, childIndex) => childIndex === head ? resizeSplitAtPath(child, tail, index, firstSize, secondSize) : child)
229
+ };
230
+ }
231
+ function setSplitChildWeightsAtPath(node, path, weights) {
232
+ if (path.length === 0) {
233
+ if (node.type !== "split" || weights.length !== node.children.length) return node;
234
+ return {
235
+ ...node,
236
+ sizes: weights.map((weight) => Math.max(.05, weight))
237
+ };
238
+ }
239
+ if (node.type !== "split") return node;
240
+ const [head, ...tail] = path;
241
+ return {
242
+ ...node,
243
+ children: node.children.map((child, childIndex) => childIndex === head ? setSplitChildWeightsAtPath(child, tail, weights) : child)
244
+ };
245
+ }
246
+ function growSplitChildWeightsToMinimum(weights, sizesPx, foldedChildren, targetIndex, minimumTargetPx, minimumDonorPx = minimumTargetPx) {
247
+ if (weights.length !== sizesPx.length || sizesPx.length !== foldedChildren.length || targetIndex < 0 || targetIndex >= sizesPx.length || foldedChildren[targetIndex]) return null;
248
+ const neededPx = minimumTargetPx - sizesPx[targetIndex];
249
+ if (neededPx <= 0) return null;
250
+ const desiredSizes = [...sizesPx];
251
+ const donors = sizesPx.map((size, index) => ({
252
+ index,
253
+ spare: !foldedChildren[index] && index !== targetIndex ? Math.max(0, size - minimumDonorPx) : 0
254
+ })).filter((donor) => donor.spare > 0).sort((a, b) => b.spare - a.spare);
255
+ let remainingPx = neededPx;
256
+ for (const donor of donors) {
257
+ const contribution = Math.min(remainingPx, donor.spare);
258
+ desiredSizes[donor.index] -= contribution;
259
+ remainingPx -= contribution;
260
+ if (remainingPx <= 0) break;
261
+ }
262
+ const transferredPx = neededPx - remainingPx;
263
+ if (transferredPx <= 0) return null;
264
+ desiredSizes[targetIndex] += transferredPx;
265
+ const openWeightTotal = weights.reduce((total, weight, index) => total + (foldedChildren[index] ? 0 : weight), 0);
266
+ const openSizeTotal = sizesPx.reduce((total, size, index) => total + (foldedChildren[index] ? 0 : size), 0);
267
+ if (openWeightTotal <= 0 || openSizeTotal <= 0) return null;
268
+ const weightPerPixel = openWeightTotal / openSizeTotal;
269
+ return weights.map((weight, index) => foldedChildren[index] ? weight : desiredSizes[index] * weightPerPixel);
270
+ }
271
+ function growChildWeightsWithFallback(weights, sizesPx, foldedChildren, targetIndex, desiredTargetPx, preferredDonorFloorPx, fallbackDonorFloorPx) {
272
+ return growSplitChildWeightsToMinimum(weights, sizesPx, foldedChildren, targetIndex, desiredTargetPx, preferredDonorFloorPx) ?? growSplitChildWeightsToMinimum(weights, sizesPx, foldedChildren, targetIndex, desiredTargetPx, fallbackDonorFloorPx);
273
+ }
274
+ function equalizeSplitAtPath(node, path, index) {
275
+ if (path.length === 0) {
276
+ if (node.type !== "split") return node;
277
+ const sizes = node.children.map((_, childIndex) => node.sizes?.[childIndex] ?? 1);
278
+ if (index < 0 || index + 1 >= sizes.length) return node;
279
+ const avg = (sizes[index] + sizes[index + 1]) / 2;
280
+ sizes[index] = avg;
281
+ sizes[index + 1] = avg;
282
+ return {
283
+ ...node,
284
+ sizes
285
+ };
286
+ }
287
+ if (node.type !== "split") return node;
288
+ const [head, ...tail] = path;
289
+ return {
290
+ ...node,
291
+ children: node.children.map((child, childIndex) => childIndex === head ? equalizeSplitAtPath(child, tail, index) : child)
292
+ };
293
+ }
294
+ function setSplitPairWeightsAtPath(node, path, index, firstWeight, secondWeight) {
295
+ if (path.length === 0) {
296
+ if (node.type !== "split") return node;
297
+ const sizes = node.children.map((_, childIndex) => node.sizes?.[childIndex] ?? 1);
298
+ if (index < 0 || index + 1 >= sizes.length) return node;
299
+ sizes[index] = Math.max(.15, firstWeight);
300
+ sizes[index + 1] = Math.max(.15, secondWeight);
301
+ return {
302
+ ...node,
303
+ sizes
304
+ };
305
+ }
306
+ if (node.type !== "split") return node;
307
+ const [head, ...tail] = path;
308
+ return {
309
+ ...node,
310
+ children: node.children.map((child, childIndex) => childIndex === head ? setSplitPairWeightsAtPath(child, tail, index, firstWeight, secondWeight) : child)
311
+ };
312
+ }
313
+ /**
314
+ * Computes the next split tree and fold map for a single divider drag frame.
315
+ * Supports recursive subtrees (folding all panels inside a nested column/row),
316
+ * hysteresis when dragging a folded panel back open, and preserves the fold-point
317
+ * proportions so unaffected siblings do not jump when a panel folds.
318
+ */
319
+ function computeResizeStep({ tree, folds, path, index, direction, startFirstPx, startSecondPx, deltaPx }) {
320
+ const split = getSplitAtPath(tree, path);
321
+ if (!split || split.type !== "split") return {
322
+ tree,
323
+ folds,
324
+ nearFoldSide: null,
325
+ snappedSide: null
326
+ };
327
+ const first = split.children[index];
328
+ const second = split.children[index + 1];
329
+ if (!first || !second) return {
330
+ tree,
331
+ folds,
332
+ nearFoldSide: null,
333
+ snappedSide: null
334
+ };
335
+ const snapThreshold = direction === "horizontal" ? 96 : 76;
336
+ const unfoldThreshold = direction === "horizontal" ? 128 : 104;
337
+ const minOpenPx = direction === "horizontal" ? 120 : 92;
338
+ const totalPx = Math.max(1, startFirstPx + startSecondPx);
339
+ const rawFirstPx = startFirstPx + deltaPx;
340
+ const rawSecondPx = totalPx - rawFirstPx;
341
+ const firstFolded = isNodeFolded(first, folds);
342
+ const secondFolded = isNodeFolded(second, folds);
343
+ const pairFirstWeight = split.sizes?.[index] ?? 1;
344
+ const pairSecondWeight = split.sizes?.[index + 1] ?? 1;
345
+ const pairTotalWeight = pairFirstWeight + pairSecondWeight;
346
+ const foldedSizePx = direction === "horizontal" ? 46 : 44;
347
+ const foldChild = (side) => {
348
+ const nextFolds = setNodeFoldState(side === "first" ? first : second, folds, "folded");
349
+ const safeFirstPx = Math.max(0, Math.min(totalPx, rawFirstPx));
350
+ const safeSecondPx = totalPx - safeFirstPx;
351
+ const foldedWeight = pairTotalWeight * ((side === "first" ? safeFirstPx : safeSecondPx) / totalPx);
352
+ const expandedNeighborWeight = pairTotalWeight * ((totalPx - foldedSizePx) / totalPx);
353
+ return {
354
+ tree: setSplitPairWeightsAtPath(tree, path, index, side === "first" ? foldedWeight : expandedNeighborWeight, side === "second" ? foldedWeight : expandedNeighborWeight),
355
+ folds: nextFolds,
356
+ nearFoldSide: null,
357
+ snappedSide: side
358
+ };
359
+ };
360
+ const unfoldChild = (side) => {
361
+ const nextFolds = setNodeFoldState(side === "first" ? first : second, folds, "open");
362
+ if (firstFolded && secondFolded && pairTotalWeight < 1) {
363
+ const unfoldedWeight = Math.max(1, pairTotalWeight);
364
+ const stillFoldedWeight = side === "first" ? pairSecondWeight : pairFirstWeight;
365
+ return {
366
+ tree: setSplitPairWeightsAtPath(tree, path, index, side === "first" ? unfoldedWeight : stillFoldedWeight, side === "second" ? unfoldedWeight : stillFoldedWeight),
367
+ folds: nextFolds,
368
+ nearFoldSide: null,
369
+ snappedSide: null
370
+ };
371
+ }
372
+ const openTarget = Math.max(minOpenPx, side === "first" ? rawFirstPx : rawSecondPx);
373
+ const openSibling = Math.max(minOpenPx, totalPx - openTarget);
374
+ return {
375
+ tree: resizeSplitAtPath(tree, path, index, side === "first" ? openTarget : openSibling, side === "second" ? openTarget : openSibling),
376
+ folds: nextFolds,
377
+ nearFoldSide: null,
378
+ snappedSide: null
379
+ };
380
+ };
381
+ if (firstFolded && rawFirstPx >= unfoldThreshold) return unfoldChild("first");
382
+ if (secondFolded && rawSecondPx >= unfoldThreshold) return unfoldChild("second");
383
+ if (firstFolded) return {
384
+ tree,
385
+ folds,
386
+ nearFoldSide: null,
387
+ snappedSide: "first"
388
+ };
389
+ if (secondFolded) return {
390
+ tree,
391
+ folds,
392
+ nearFoldSide: null,
393
+ snappedSide: "second"
394
+ };
395
+ if (rawFirstPx <= snapThreshold && totalPx > snapThreshold * 1.6) return foldChild("first");
396
+ if (rawSecondPx <= snapThreshold && totalPx > snapThreshold * 1.6) return foldChild("second");
397
+ const minClampPx = Math.min(snapThreshold + 4, Math.max(1, Math.floor(totalPx * .25)));
398
+ const clampedFirst = Math.max(minClampPx, Math.min(totalPx - minClampPx, rawFirstPx));
399
+ const clampedSecond = Math.max(minClampPx, totalPx - clampedFirst);
400
+ let nearFoldSide = null;
401
+ if (totalPx > snapThreshold * 1.6) {
402
+ if (rawFirstPx <= snapThreshold + 38) nearFoldSide = "first";
403
+ else if (rawSecondPx <= snapThreshold + 38) nearFoldSide = "second";
404
+ }
405
+ return {
406
+ tree: resizeSplitAtPath(tree, path, index, clampedFirst, clampedSecond),
407
+ folds,
408
+ nearFoldSide,
409
+ snappedSide: null
410
+ };
411
+ }
412
+ function computeKeyboardResizeStep({ tree, folds, path, index, deltaRatio }) {
413
+ const split = getSplitAtPath(tree, path);
414
+ if (!split || split.type !== "split") return {
415
+ tree,
416
+ folds
417
+ };
418
+ const first = split.children[index];
419
+ const second = split.children[index + 1];
420
+ if (!first || !second) return {
421
+ tree,
422
+ folds
423
+ };
424
+ const firstFolded = isNodeFolded(first, folds);
425
+ const secondFolded = isNodeFolded(second, folds);
426
+ const sizes = split.children.map((_, i) => split.sizes?.[i] ?? 1);
427
+ const firstWeight = sizes[index] ?? 1;
428
+ const secondWeight = sizes[index + 1] ?? 1;
429
+ const total = firstWeight + secondWeight;
430
+ if (firstFolded) {
431
+ if (deltaRatio <= 0) return {
432
+ tree,
433
+ folds
434
+ };
435
+ const nextFolds = setNodeFoldState(first, folds, "open");
436
+ const nextFirst = Math.max(total * .25, firstWeight);
437
+ return {
438
+ tree: setSplitPairWeightsAtPath(tree, path, index, nextFirst, Math.max(.15, secondFolded ? secondWeight : total - nextFirst)),
439
+ folds: nextFolds
440
+ };
441
+ }
442
+ if (secondFolded) {
443
+ if (deltaRatio >= 0) return {
444
+ tree,
445
+ folds
446
+ };
447
+ const nextFolds = setNodeFoldState(second, folds, "open");
448
+ const nextSecond = Math.max(total * .25, secondWeight);
449
+ return {
450
+ tree: setSplitPairWeightsAtPath(tree, path, index, Math.max(.15, total - nextSecond), nextSecond),
451
+ folds: nextFolds
452
+ };
453
+ }
454
+ const nextFirst = Math.max(total * .15, Math.min(total * .85, firstWeight + total * deltaRatio));
455
+ return {
456
+ tree: resizeSplitAtPath(tree, path, index, nextFirst, total - nextFirst),
457
+ folds
458
+ };
459
+ }
460
+ function splitDepth(node) {
461
+ if (node.type === "panel") return 0;
462
+ return 1 + Math.max(...node.children.map(splitDepth));
463
+ }
464
+ // src/utils/dom.ts
465
+ function isEditableTarget(target) {
466
+ if (!(target instanceof HTMLElement)) return false;
467
+ if (target.isContentEditable) return true;
468
+ const tag = target.tagName;
469
+ return tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT";
470
+ }
471
+ function hasOpenModal() {
472
+ if (typeof document === "undefined") return false;
473
+ return Boolean(document.querySelector("[role=\"dialog\"][aria-modal=\"true\"]"));
474
+ }
475
+ // src/components/icons.tsx
476
+ function SvgIcon({ children, className = "size-4", ...rest }) {
477
+ return /* @__PURE__ */ jsx("svg", {
478
+ viewBox: "0 0 24 24",
479
+ fill: "none",
480
+ stroke: "currentColor",
481
+ strokeWidth: 1.85,
482
+ strokeLinecap: "round",
483
+ strokeLinejoin: "round",
484
+ "aria-hidden": "true",
485
+ className,
486
+ ...rest,
487
+ children
488
+ });
489
+ }
490
+ function PlusIcon(props) {
491
+ return /* @__PURE__ */ jsxs(SvgIcon, {
492
+ ...props,
493
+ children: [/* @__PURE__ */ jsx("path", { d: "M12 5v14" }), /* @__PURE__ */ jsx("path", { d: "M5 12h14" })]
494
+ });
495
+ }
496
+ function CloseIcon(props) {
497
+ return /* @__PURE__ */ jsxs(SvgIcon, {
498
+ ...props,
499
+ children: [/* @__PURE__ */ jsx("path", { d: "M18 6 6 18" }), /* @__PURE__ */ jsx("path", { d: "m6 6 12 12" })]
500
+ });
501
+ }
502
+ function MinusIcon(props) {
503
+ return /* @__PURE__ */ jsx(SvgIcon, {
504
+ ...props,
505
+ children: /* @__PURE__ */ jsx("path", { d: "M5 12h14" })
506
+ });
507
+ }
508
+ function ChevronUpIcon(props) {
509
+ return /* @__PURE__ */ jsx(SvgIcon, {
510
+ ...props,
511
+ children: /* @__PURE__ */ jsx("path", { d: "m18 15-6-6-6 6" })
512
+ });
513
+ }
514
+ function ChevronDownIcon(props) {
515
+ return /* @__PURE__ */ jsx(SvgIcon, {
516
+ ...props,
517
+ children: /* @__PURE__ */ jsx("path", { d: "m6 9 6 6 6-6" })
518
+ });
519
+ }
520
+ function ChevronLeftIcon(props) {
521
+ return /* @__PURE__ */ jsx(SvgIcon, {
522
+ ...props,
523
+ children: /* @__PURE__ */ jsx("path", { d: "m15 18-6-6 6-6" })
524
+ });
525
+ }
526
+ function ChevronRightIcon(props) {
527
+ return /* @__PURE__ */ jsx(SvgIcon, {
528
+ ...props,
529
+ children: /* @__PURE__ */ jsx("path", { d: "m9 18 6-6-6-6" })
530
+ });
531
+ }
532
+ function GripVerticalIcon(props) {
533
+ return /* @__PURE__ */ jsxs(SvgIcon, {
534
+ ...props,
535
+ children: [
536
+ /* @__PURE__ */ jsx("circle", {
537
+ cx: "9",
538
+ cy: "6",
539
+ r: "1",
540
+ fill: "currentColor",
541
+ stroke: "none"
542
+ }),
543
+ /* @__PURE__ */ jsx("circle", {
544
+ cx: "9",
545
+ cy: "12",
546
+ r: "1",
547
+ fill: "currentColor",
548
+ stroke: "none"
549
+ }),
550
+ /* @__PURE__ */ jsx("circle", {
551
+ cx: "9",
552
+ cy: "18",
553
+ r: "1",
554
+ fill: "currentColor",
555
+ stroke: "none"
556
+ }),
557
+ /* @__PURE__ */ jsx("circle", {
558
+ cx: "15",
559
+ cy: "6",
560
+ r: "1",
561
+ fill: "currentColor",
562
+ stroke: "none"
563
+ }),
564
+ /* @__PURE__ */ jsx("circle", {
565
+ cx: "15",
566
+ cy: "12",
567
+ r: "1",
568
+ fill: "currentColor",
569
+ stroke: "none"
570
+ }),
571
+ /* @__PURE__ */ jsx("circle", {
572
+ cx: "15",
573
+ cy: "18",
574
+ r: "1",
575
+ fill: "currentColor",
576
+ stroke: "none"
577
+ })
578
+ ]
579
+ });
580
+ }
581
+ function MaximizeIcon(props) {
582
+ return /* @__PURE__ */ jsxs(SvgIcon, {
583
+ ...props,
584
+ children: [
585
+ /* @__PURE__ */ jsx("polyline", { points: "15 3 21 3 21 9" }),
586
+ /* @__PURE__ */ jsx("polyline", { points: "9 21 3 21 3 15" }),
587
+ /* @__PURE__ */ jsx("line", {
588
+ x1: "21",
589
+ x2: "14",
590
+ y1: "3",
591
+ y2: "10"
592
+ }),
593
+ /* @__PURE__ */ jsx("line", {
594
+ x1: "3",
595
+ x2: "10",
596
+ y1: "21",
597
+ y2: "14"
598
+ })
599
+ ]
600
+ });
601
+ }
602
+ function MinimizeIcon(props) {
603
+ return /* @__PURE__ */ jsxs(SvgIcon, {
604
+ ...props,
605
+ children: [
606
+ /* @__PURE__ */ jsx("polyline", { points: "4 14 10 14 10 20" }),
607
+ /* @__PURE__ */ jsx("polyline", { points: "20 10 14 10 14 4" }),
608
+ /* @__PURE__ */ jsx("line", {
609
+ x1: "14",
610
+ x2: "21",
611
+ y1: "10",
612
+ y2: "3"
613
+ }),
614
+ /* @__PURE__ */ jsx("line", {
615
+ x1: "3",
616
+ x2: "10",
617
+ y1: "21",
618
+ y2: "14"
619
+ })
620
+ ]
621
+ });
622
+ }
623
+ function LayoutIcon(props) {
624
+ return /* @__PURE__ */ jsxs(SvgIcon, {
625
+ ...props,
626
+ children: [
627
+ /* @__PURE__ */ jsx("rect", {
628
+ width: "18",
629
+ height: "18",
630
+ x: "3",
631
+ y: "3",
632
+ rx: "2.5"
633
+ }),
634
+ /* @__PURE__ */ jsx("path", { d: "M3 9h18" }),
635
+ /* @__PURE__ */ jsx("path", { d: "M9 21V9" })
636
+ ]
637
+ });
638
+ }
639
+ function CheckIcon(props) {
640
+ return /* @__PURE__ */ jsx(SvgIcon, {
641
+ ...props,
642
+ children: /* @__PURE__ */ jsx("path", { d: "M20 6 9 17l-5-5" })
643
+ });
644
+ }
645
+ function BookmarkIcon(props) {
646
+ return /* @__PURE__ */ jsx(SvgIcon, {
647
+ ...props,
648
+ children: /* @__PURE__ */ jsx("path", { d: "m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z" })
649
+ });
650
+ }
651
+ function RotateCcwIcon(props) {
652
+ return /* @__PURE__ */ jsxs(SvgIcon, {
653
+ ...props,
654
+ children: [/* @__PURE__ */ jsx("path", { d: "M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8" }), /* @__PURE__ */ jsx("path", { d: "M3 3v5h5" })]
655
+ });
656
+ }
657
+ function MenuIcon(props) {
658
+ return /* @__PURE__ */ jsxs(SvgIcon, {
659
+ ...props,
660
+ children: [
661
+ /* @__PURE__ */ jsx("line", {
662
+ x1: "4",
663
+ x2: "20",
664
+ y1: "12",
665
+ y2: "12"
666
+ }),
667
+ /* @__PURE__ */ jsx("line", {
668
+ x1: "4",
669
+ x2: "20",
670
+ y1: "6",
671
+ y2: "6"
672
+ }),
673
+ /* @__PURE__ */ jsx("line", {
674
+ x1: "4",
675
+ x2: "20",
676
+ y1: "18",
677
+ y2: "18"
678
+ })
679
+ ]
680
+ });
681
+ }
682
+ function LoaderIcon(props) {
683
+ return /* @__PURE__ */ jsx(SvgIcon, {
684
+ ...props,
685
+ children: /* @__PURE__ */ jsx("path", { d: "M21 12a9 9 0 1 1-6.219-8.56" })
686
+ });
687
+ }
688
+ // src/components/MobileBottomBar.tsx
689
+ const NAV_HEIGHT_PX = 64;
690
+ const NAV_BORDER_PX = 1;
691
+ const MAX_SLOTS = 5;
692
+ const KNOB_RADIUS_PX = 18;
693
+ const TAB_KNOB_START_PX = 9;
694
+ const FILLET_PX = 26;
695
+ const PANEL_GAP_PX = 10;
696
+ const PANEL_PAD_X_PX = 6;
697
+ const PANEL_PAD_Y_PX = 4;
698
+ const PANEL_EDGE_PX = 10;
699
+ const PANEL_CORNER_PX = 18;
700
+ const ITEM_WIDTH_PX = 76;
701
+ const ITEM_HEIGHT_PX = 48;
702
+ const ITEM_GAP_PX = 4;
703
+ const EASE_OUT = "ease-[cubic-bezier(0.22,1,0.36,1)]";
704
+ const clamp = (value, min, max) => Math.min(Math.max(value, min), Math.max(min, max));
705
+ const clamp01 = (value) => Math.min(1, Math.max(0, value));
706
+ const lerp = (a, b, t) => a + (b - a) * t;
707
+ const roundHalf = (value) => Math.round(value * 2) / 2;
708
+ const f = (value) => Math.round(value * 100) / 100;
709
+ /**
710
+ * One continuous outline: a rounded pill, two concave fillets, and a circular knob.
711
+ * `p` is the morph progress: at 0 the shape is only the knob, at 1 the pill has
712
+ * been pushed up out of it with the neck stretched between the two. It can go a
713
+ * touch past 1 (spring overshoot), which gives the liquid feel.
714
+ */
715
+ function buildMorphPath(g, rawP) {
716
+ const p = Math.max(0, rawP);
717
+ const pw = Math.min(1, p * 1.08);
718
+ const { cx, ky, kr, pillH } = g;
719
+ const k = lerp(g.knobFrom, kr, clamp01(p * 4));
720
+ const knobL = cx - k;
721
+ const knobR = cx + k;
722
+ const L = lerp(knobL, g.left, pw);
723
+ const R = lerp(knobR, g.right, pw);
724
+ const T = ky * (1 - p);
725
+ const B = ky - (ky - pillH) * p;
726
+ const h = B - T;
727
+ const rt = Math.min(g.corner, h / 2, (R - L) / 2);
728
+ const K = .5523;
729
+ const reach = FILLET_PX * pw;
730
+ const edgeThreshold = rt + 6;
731
+ const rightRoom = R - knobR;
732
+ const mergeRight = rightRoom < edgeThreshold;
733
+ let rightSideCmds;
734
+ if (mergeRight) {
735
+ const joinY = Math.max(T + rt, B - (edgeThreshold - rightRoom) * .85 * pw);
736
+ const midY = (joinY + ky) / 2;
737
+ rightSideCmds = [`L ${f(R)} ${f(joinY)}`, `C ${f(R)} ${f(midY)} ${f(knobR)} ${f(midY)} ${f(knobR)} ${f(ky)}`];
738
+ } else {
739
+ const rbR = Math.min(rt, Math.max(rightRoom - 6, 4));
740
+ const filletR = Math.min(R - rbR, knobR + reach);
741
+ const neckY = ky - (ky - B) * K;
742
+ rightSideCmds = [
743
+ `L ${f(R)} ${f(B - rbR)}`,
744
+ `Q ${f(R)} ${f(B)} ${f(R - rbR)} ${f(B)}`,
745
+ `L ${f(filletR)} ${f(B)}`,
746
+ `C ${f(filletR + (knobR - filletR) * K)} ${f(B)} ${f(knobR)} ${f(neckY)} ${f(knobR)} ${f(ky)}`
747
+ ];
748
+ }
749
+ const leftRoom = knobL - L;
750
+ const mergeLeft = leftRoom < edgeThreshold;
751
+ let leftSideCmds;
752
+ if (mergeLeft) {
753
+ const joinY = Math.max(T + rt, B - (edgeThreshold - leftRoom) * .85 * pw);
754
+ const midY = (joinY + ky) / 2;
755
+ leftSideCmds = [`C ${f(knobL)} ${f(midY)} ${f(L)} ${f(midY)} ${f(L)} ${f(joinY)}`];
756
+ } else {
757
+ const rbL = Math.min(rt, Math.max(leftRoom - 6, 4));
758
+ const filletL = Math.max(L + rbL, knobL - reach);
759
+ const neckY = ky - (ky - B) * K;
760
+ leftSideCmds = [
761
+ `C ${f(knobL)} ${f(neckY)} ${f(filletL + (knobL - filletL) * K)} ${f(B)} ${f(filletL)} ${f(B)}`,
762
+ `L ${f(L + rbL)} ${f(B)}`,
763
+ `Q ${f(L)} ${f(B)} ${f(L)} ${f(B - rbL)}`
764
+ ];
765
+ }
766
+ return [
767
+ `M ${f(L + rt)} ${f(T)}`,
768
+ `L ${f(R - rt)} ${f(T)}`,
769
+ `Q ${f(R)} ${f(T)} ${f(R)} ${f(T + rt)}`,
770
+ ...rightSideCmds,
771
+ `A ${f(k)} ${f(k)} 0 1 1 ${f(knobL)} ${f(ky)}`,
772
+ ...leftSideCmds,
773
+ `L ${f(L)} ${f(T + rt)}`,
774
+ `Q ${f(L)} ${f(T)} ${f(L + rt)} ${f(T)}`,
775
+ "Z"
776
+ ].join(" ");
777
+ }
778
+ /**
779
+ * Mobile bottom navigation.
780
+ *
781
+ * - A soft pill glides behind the active tab.
782
+ * - A submenu pops out of whichever slot opens it: the trigger becomes a circular
783
+ * knob, and the submenu is one fluid shape fused to it with smooth concave
784
+ * curves, in the same colour. The shape is morphed on a spring, so it truly
785
+ * stretches up out of the button instead of just scaling in.
786
+ * - `action` slots get a quiet filled well, `accent` is a circular accent button.
787
+ * Everything stays inside the bar.
788
+ * - Colours come from `--rtw-*` CSS variables so the host theme stays in control.
789
+ */
790
+ function MobileBottomBar({ items, activeId, onSelect, ariaLabel = "Mobile navigation", zIndexClassName = "z-30" }) {
791
+ const navRef = useRef(null);
792
+ const panelRef = useRef(null);
793
+ const pathRef = useRef(null);
794
+ const triggerRef = useRef(null);
795
+ const geometryRef = useRef(null);
796
+ const lastDrawnGeometryRef = useRef(null);
797
+ const switchTweenRef = useRef(null);
798
+ const phaseRef = useRef("closed");
799
+ const menuIdRef = useRef(null);
800
+ const pendingRef = useRef(null);
801
+ const openedByKeyboardRef = useRef(false);
802
+ const progressRef = useRef(0);
803
+ const velocityRef = useRef(0);
804
+ const targetRef = useRef(0);
805
+ const rafRef = useRef(null);
806
+ const lastFrameRef = useRef(0);
807
+ const finishCloseRef = useRef(() => {});
808
+ const closeMenuRef = useRef(() => {});
809
+ const submenuId = useId();
810
+ const [mountedMenuId, setMountedMenuId] = useState(null);
811
+ const [isOpen, setIsOpen] = useState(false);
812
+ const [navWidth, setNavWidth] = useState(375);
813
+ const [anchor, setAnchor] = useState({
814
+ x: 187,
815
+ y: 25
816
+ });
817
+ const [pill, setPill] = useState({
818
+ x: 0,
819
+ width: 0,
820
+ visible: false,
821
+ instant: true
822
+ });
823
+ const accentItem = items.find((item) => item.variant === "accent") ?? null;
824
+ const otherItems = items.filter((item) => item.variant !== "accent");
825
+ const maxOthers = accentItem ? 4 : MAX_SLOTS;
826
+ const needsOverflow = otherItems.length > maxOthers;
827
+ const visibleItems = needsOverflow ? otherItems.slice(0, maxOthers - 1) : otherItems;
828
+ const overflowItems = needsOverflow ? otherItems.slice(maxOthers - 1) : [];
829
+ const moreItem = needsOverflow ? {
830
+ id: "__overflow__",
831
+ label: "More",
832
+ icon: /* @__PURE__ */ jsx(MenuIcon, {}),
833
+ variant: "submenu",
834
+ active: overflowItems.some((item) => activeId === item.id || item.active),
835
+ subItems: overflowItems.map((item) => ({
836
+ id: item.id,
837
+ label: item.label,
838
+ icon: item.icon,
839
+ active: activeId === item.id || Boolean(item.active),
840
+ onSelect: () => {
841
+ if (item.onClick) item.onClick();
842
+ else onSelect?.(item.id);
843
+ }
844
+ }))
845
+ } : null;
846
+ const row = moreItem ? [...visibleItems, moreItem] : visibleItems;
847
+ const centerIndex = Math.ceil(row.length / 2);
848
+ const slots = accentItem ? [
849
+ ...row.slice(0, centerIndex),
850
+ accentItem,
851
+ ...row.slice(centerIndex)
852
+ ] : row;
853
+ const menuItem = slots.find((item) => item.id === mountedMenuId) ?? null;
854
+ const subItems = menuItem?.subItems ?? [];
855
+ const openMenuId = isOpen ? mountedMenuId : null;
856
+ let geometry = null;
857
+ let panel = {
858
+ left: 0,
859
+ width: 0,
860
+ top: 0,
861
+ height: 0,
862
+ svgHeight: 0
863
+ };
864
+ if (menuItem && subItems.length > 0) {
865
+ const cols = Math.min(4, subItems.length);
866
+ const rows = Math.ceil(subItems.length / cols);
867
+ const pillH = rows * ITEM_HEIGHT_PX + (rows - 1) * ITEM_GAP_PX + 8;
868
+ const layoutCols = Math.max(cols, 2);
869
+ const idealWidth = layoutCols * ITEM_WIDTH_PX + (layoutCols - 1) * ITEM_GAP_PX + 12;
870
+ const width = Math.min(idealWidth, navWidth - 20);
871
+ const left = clamp(anchor.x - width / 2, PANEL_EDGE_PX, navWidth - width - PANEL_EDGE_PX);
872
+ const ky = pillH + PANEL_GAP_PX + anchor.y;
873
+ geometry = {
874
+ cx: anchor.x,
875
+ ky,
876
+ kr: KNOB_RADIUS_PX,
877
+ knobFrom: menuItem.variant === "accent" ? KNOB_RADIUS_PX : TAB_KNOB_START_PX,
878
+ left: Math.min(left, anchor.x - KNOB_RADIUS_PX),
879
+ right: Math.max(left + width, anchor.x + KNOB_RADIUS_PX),
880
+ pillH,
881
+ corner: PANEL_CORNER_PX
882
+ };
883
+ panel = {
884
+ left,
885
+ width,
886
+ top: anchor.y - NAV_BORDER_PX - ky,
887
+ height: pillH,
888
+ svgHeight: ky + KNOB_RADIUS_PX + 2
889
+ };
890
+ }
891
+ const gridCols = Math.min(4, Math.max(1, subItems.length));
892
+ const prefersReducedMotion = useCallback(() => typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches, []);
893
+ const draw = useCallback((progress, now = performance.now()) => {
894
+ const path = pathRef.current;
895
+ const targetG = geometryRef.current;
896
+ if (!path || !targetG) return;
897
+ let g = targetG;
898
+ const tween = switchTweenRef.current;
899
+ if (tween) {
900
+ const rawT = clamp01((now - tween.startTime) / tween.duration);
901
+ const t = 1 - Math.pow(1 - rawT, 3);
902
+ g = {
903
+ cx: lerp(tween.from.cx, targetG.cx, t),
904
+ ky: lerp(tween.from.ky, targetG.ky, t),
905
+ kr: lerp(tween.from.kr, targetG.kr, t),
906
+ knobFrom: lerp(tween.from.knobFrom, targetG.knobFrom, t),
907
+ left: lerp(tween.from.left, targetG.left, t),
908
+ right: lerp(tween.from.right, targetG.right, t),
909
+ pillH: lerp(tween.from.pillH, targetG.pillH, t),
910
+ corner: lerp(tween.from.corner, targetG.corner, t)
911
+ };
912
+ if (rawT >= 1) switchTweenRef.current = null;
913
+ }
914
+ lastDrawnGeometryRef.current = g;
915
+ path.setAttribute("d", buildMorphPath(g, progress));
916
+ }, []);
917
+ const tick = useCallback((now) => {
918
+ const dt = clamp((now - lastFrameRef.current) / 1e3, .001, .032);
919
+ lastFrameRef.current = now;
920
+ const target = targetRef.current;
921
+ const opening = target === 1;
922
+ const stiffness = opening ? 340 : 880;
923
+ const damping = opening ? 26 : 58;
924
+ let p = progressRef.current;
925
+ let v = velocityRef.current;
926
+ const h = dt / 2;
927
+ for (let i = 0; i < 2; i += 1) {
928
+ v += (stiffness * (target - p) - damping * v) * h;
929
+ p += v * h;
930
+ }
931
+ if (!opening && p < 0) {
932
+ p = 0;
933
+ v = 0;
934
+ }
935
+ progressRef.current = p;
936
+ velocityRef.current = v;
937
+ draw(p, now);
938
+ if (Math.abs(target - p) < .001 && Math.abs(v) < .02 && switchTweenRef.current === null) {
939
+ progressRef.current = target;
940
+ velocityRef.current = 0;
941
+ draw(target, now);
942
+ rafRef.current = null;
943
+ if (target === 0) finishCloseRef.current();
944
+ return;
945
+ }
946
+ rafRef.current = window.requestAnimationFrame(tick);
947
+ }, [draw]);
948
+ const animateTo = useCallback((target) => {
949
+ targetRef.current = target;
950
+ if (prefersReducedMotion()) {
951
+ if (rafRef.current !== null) window.cancelAnimationFrame(rafRef.current);
952
+ rafRef.current = null;
953
+ progressRef.current = target;
954
+ velocityRef.current = 0;
955
+ draw(target);
956
+ if (target === 0) finishCloseRef.current();
957
+ return;
958
+ }
959
+ if (rafRef.current === null) {
960
+ lastFrameRef.current = performance.now();
961
+ rafRef.current = window.requestAnimationFrame(tick);
962
+ }
963
+ }, [
964
+ draw,
965
+ prefersReducedMotion,
966
+ tick
967
+ ]);
968
+ useEffect(() => () => {
969
+ if (rafRef.current !== null) window.cancelAnimationFrame(rafRef.current);
970
+ }, []);
971
+ const measure = useCallback(() => {
972
+ const nav = navRef.current;
973
+ if (!nav) return;
974
+ const navRect = nav.getBoundingClientRect();
975
+ setNavWidth((prev) => prev === navRect.width ? prev : navRect.width);
976
+ const trigger = triggerRef.current;
977
+ if (trigger?.isConnected && nav.contains(trigger)) {
978
+ const rect = (trigger.querySelector("[data-anchor]") ?? trigger).getBoundingClientRect();
979
+ const x = roundHalf(rect.left - navRect.left + rect.width / 2);
980
+ const y = roundHalf(rect.top - navRect.top + rect.height / 2);
981
+ setAnchor((prev) => prev.x === x && prev.y === y ? prev : {
982
+ x,
983
+ y
984
+ });
985
+ }
986
+ const pillTarget = nav.querySelector("[data-pill-target=\"true\"]");
987
+ if (pillTarget) {
988
+ const rect = pillTarget.getBoundingClientRect();
989
+ const x = roundHalf(rect.left - navRect.left);
990
+ const width = roundHalf(rect.width);
991
+ setPill((prev) => {
992
+ const next = {
993
+ x,
994
+ width,
995
+ visible: true,
996
+ instant: !prev.visible
997
+ };
998
+ return prev.x === next.x && prev.width === next.width && prev.visible === next.visible && prev.instant === next.instant ? prev : next;
999
+ });
1000
+ } else setPill((prev) => prev.visible ? {
1001
+ ...prev,
1002
+ visible: false,
1003
+ instant: false
1004
+ } : prev);
1005
+ }, []);
1006
+ useLayoutEffect(() => {
1007
+ measure();
1008
+ geometryRef.current = geometry;
1009
+ if (geometry) draw(progressRef.current);
1010
+ });
1011
+ useLayoutEffect(() => {
1012
+ const nav = navRef.current;
1013
+ if (!nav) return;
1014
+ window.addEventListener("resize", measure);
1015
+ window.addEventListener("orientationchange", measure);
1016
+ const observer = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(measure);
1017
+ observer?.observe(nav);
1018
+ return () => {
1019
+ window.removeEventListener("resize", measure);
1020
+ window.removeEventListener("orientationchange", measure);
1021
+ observer?.disconnect();
1022
+ };
1023
+ }, [measure]);
1024
+ function openMenu(id, trigger, viaKeyboard) {
1025
+ const isSwitching = phaseRef.current !== "closed" && menuIdRef.current !== id;
1026
+ if (isSwitching && !prefersReducedMotion() && lastDrawnGeometryRef.current) switchTweenRef.current = {
1027
+ from: lastDrawnGeometryRef.current,
1028
+ startTime: performance.now(),
1029
+ duration: 220
1030
+ };
1031
+ else if (!isSwitching) switchTweenRef.current = null;
1032
+ pendingRef.current = null;
1033
+ openedByKeyboardRef.current = viaKeyboard;
1034
+ triggerRef.current = trigger;
1035
+ measure();
1036
+ if (phaseRef.current === "closed") {
1037
+ progressRef.current = 0;
1038
+ velocityRef.current = 0;
1039
+ }
1040
+ phaseRef.current = "open";
1041
+ menuIdRef.current = id;
1042
+ setMountedMenuId(id);
1043
+ setIsOpen(true);
1044
+ animateTo(1);
1045
+ }
1046
+ function closeMenu(restoreFocus = false) {
1047
+ if (phaseRef.current === "closed") return;
1048
+ const trigger = triggerRef.current;
1049
+ if (restoreFocus && trigger?.isConnected) trigger.focus({ preventScroll: true });
1050
+ else if (panelRef.current?.contains(document.activeElement)) document.activeElement.blur();
1051
+ if (phaseRef.current === "closing") return;
1052
+ phaseRef.current = "closing";
1053
+ setIsOpen(false);
1054
+ animateTo(0);
1055
+ }
1056
+ function finishClose() {
1057
+ phaseRef.current = "closed";
1058
+ menuIdRef.current = null;
1059
+ triggerRef.current = null;
1060
+ setMountedMenuId(null);
1061
+ const pending = pendingRef.current;
1062
+ if (pending && pending.trigger.isConnected) {
1063
+ pendingRef.current = null;
1064
+ openMenu(pending.id, pending.trigger, pending.viaKeyboard);
1065
+ }
1066
+ pendingRef.current = null;
1067
+ }
1068
+ finishCloseRef.current = finishClose;
1069
+ closeMenuRef.current = closeMenu;
1070
+ useEffect(() => {
1071
+ if (!mountedMenuId) return;
1072
+ function onKeyDown(event) {
1073
+ if (event.key === "Escape") {
1074
+ event.preventDefault();
1075
+ closeMenuRef.current(true);
1076
+ }
1077
+ }
1078
+ window.addEventListener("keydown", onKeyDown);
1079
+ return () => window.removeEventListener("keydown", onKeyDown);
1080
+ }, [mountedMenuId]);
1081
+ useEffect(() => {
1082
+ if (!isOpen || !openedByKeyboardRef.current) return;
1083
+ openedByKeyboardRef.current = false;
1084
+ panelRef.current?.querySelector("[role=\"menuitem\"]")?.focus({ preventScroll: true });
1085
+ }, [isOpen, mountedMenuId]);
1086
+ function handleSlotClick(item, event) {
1087
+ if (item.subItems && item.subItems.length > 0) {
1088
+ if (mountedMenuId === item.id && phaseRef.current === "open") closeMenu();
1089
+ else openMenu(item.id, event.currentTarget, event.detail === 0);
1090
+ return;
1091
+ }
1092
+ if (mountedMenuId) closeMenu();
1093
+ if (item.onClick) item.onClick();
1094
+ else onSelect?.(item.id);
1095
+ }
1096
+ function handleMenuKeyDown(event) {
1097
+ if (event.key === "Tab") {
1098
+ closeMenu();
1099
+ return;
1100
+ }
1101
+ const entries = Array.from(event.currentTarget.querySelectorAll("[role=\"menuitem\"]"));
1102
+ const current = entries.indexOf(document.activeElement);
1103
+ let next = -1;
1104
+ if (event.key === "ArrowRight") next = (current + 1) % entries.length;
1105
+ else if (event.key === "ArrowLeft") next = (current - 1 + entries.length) % entries.length;
1106
+ else if (event.key === "Home") next = 0;
1107
+ else if (event.key === "End") next = entries.length - 1;
1108
+ if (next >= 0) {
1109
+ event.preventDefault();
1110
+ entries[next]?.focus();
1111
+ }
1112
+ }
1113
+ function renderSlot(item) {
1114
+ const hasSubmenu = Boolean(item.subItems && item.subItems.length > 0);
1115
+ const isAccent = item.variant === "accent";
1116
+ const isAction = item.variant === "action";
1117
+ const isMenuMounted = mountedMenuId === item.id;
1118
+ const isMenuOpen = openMenuId === item.id;
1119
+ const isTabActive = !isAction && !isAccent && (activeId === item.id || Boolean(item.active));
1120
+ const isPillTarget = isTabActive && !isMenuOpen;
1121
+ const wellShape = isAccent ? "-my-1 size-9" : "h-7 w-12";
1122
+ const wellTone = isAccent ? "bg-[var(--rtw-accent,#6366f1)] text-[var(--rtw-accent-foreground,#ffffff)]" : isMenuOpen ? "text-[var(--rtw-accent-foreground,#ffffff)]" : isAction ? "bg-[var(--rtw-surface-subtle,#edf1f7)] text-[var(--rtw-text-strong,#0f172a)] group-hover/slot:bg-[var(--rtw-border,#dfe5ef)]" : isTabActive ? "text-[var(--rtw-accent,#6366f1)]" : "text-[var(--rtw-text-subtle,#64748b)] group-hover/slot:text-[var(--rtw-text-strong,#0f172a)]";
1123
+ const labelTone = isAccent || isMenuOpen || isTabActive ? "text-[var(--rtw-accent,#6366f1)]" : isAction ? "text-[var(--rtw-text-strong,#0f172a)]" : "text-[var(--rtw-text-subtle,#64748b)] group-hover/slot:text-[var(--rtw-text-strong,#0f172a)]";
1124
+ const glyphMotion = `transition-[transform,opacity] duration-[280ms] ${EASE_OUT} motion-reduce:transition-none`;
1125
+ let glyph;
1126
+ if (item.loading) glyph = /* @__PURE__ */ jsx(LoaderIcon, { className: "size-5 animate-spin" });
1127
+ else if (isAccent) glyph = /* @__PURE__ */ jsx("span", {
1128
+ "aria-hidden": "true",
1129
+ style: { transform: isMenuOpen ? "rotate(135deg)" : "rotate(0deg)" },
1130
+ className: `flex size-[22px] items-center justify-center transition-transform duration-[260ms] ${EASE_OUT} motion-reduce:!transition-none [&>svg]:size-[22px]`,
1131
+ children: item.icon
1132
+ });
1133
+ else if (hasSubmenu) glyph = /* @__PURE__ */ jsxs("span", {
1134
+ className: "relative flex size-5 items-center justify-center",
1135
+ children: [/* @__PURE__ */ jsx("span", {
1136
+ "aria-hidden": "true",
1137
+ className: `absolute inset-0 flex items-center justify-center [&>svg]:size-5 ${glyphMotion} ${isMenuOpen ? "scale-50 -rotate-90 opacity-0" : "scale-100 rotate-0 opacity-100"}`,
1138
+ children: item.icon
1139
+ }), /* @__PURE__ */ jsx(CloseIcon, {
1140
+ "aria-hidden": "true",
1141
+ className: `absolute size-[19px] ${glyphMotion} ${isMenuOpen ? "scale-100 rotate-0 opacity-100" : "scale-50 rotate-90 opacity-0"}`
1142
+ })]
1143
+ });
1144
+ else glyph = /* @__PURE__ */ jsx("span", {
1145
+ "aria-hidden": "true",
1146
+ className: "flex size-5 items-center justify-center [&>svg]:size-5",
1147
+ children: item.icon
1148
+ });
1149
+ return /* @__PURE__ */ jsxs("button", {
1150
+ type: "button",
1151
+ "data-pill-target": isPillTarget ? "true" : void 0,
1152
+ onClick: (event) => handleSlotClick(item, event),
1153
+ "aria-haspopup": hasSubmenu ? "menu" : void 0,
1154
+ "aria-controls": hasSubmenu && isMenuMounted ? submenuId : void 0,
1155
+ "aria-expanded": hasSubmenu ? isMenuOpen : void 0,
1156
+ "aria-current": isTabActive ? "page" : void 0,
1157
+ className: "group/slot relative flex min-w-0 flex-1 cursor-pointer select-none flex-col items-center gap-[5px] pt-2.5 outline-none [-webkit-tap-highlight-color:transparent]",
1158
+ children: [/* @__PURE__ */ jsxs("span", {
1159
+ "data-anchor": "true",
1160
+ className: `relative flex items-center justify-center rounded-full transition-[background-color,color] duration-200 group-focus-visible/slot:ring-2 group-focus-visible/slot:ring-[var(--rtw-accent,#6366f1)]/60 motion-reduce:transition-none ${wellShape} ${wellTone}`,
1161
+ children: [/* @__PURE__ */ jsx("span", {
1162
+ className: "flex items-center justify-center transition-transform duration-150 group-active/slot:scale-90 motion-reduce:transition-none",
1163
+ children: glyph
1164
+ }), item.badge !== void 0 && item.badge !== 0 && !isMenuOpen && /* @__PURE__ */ jsx("span", {
1165
+ className: "absolute left-1/2 top-0 ml-1 min-w-4 -translate-y-0.5 rounded-full bg-[var(--rtw-accent,#6366f1)] px-1 text-center text-[9px] font-semibold leading-4 text-[var(--rtw-accent-foreground,#ffffff)]",
1166
+ children: item.badge
1167
+ })]
1168
+ }), /* @__PURE__ */ jsx("span", {
1169
+ className: `max-w-full truncate text-[10px] font-medium leading-[10px] transition-colors duration-200 motion-reduce:transition-none ${labelTone}`,
1170
+ children: item.renderLabel ? item.renderLabel() : item.label
1171
+ })]
1172
+ }, item.id);
1173
+ }
1174
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [mountedMenuId && /* @__PURE__ */ jsx("div", {
1175
+ "aria-hidden": "true",
1176
+ onClick: () => closeMenu(),
1177
+ className: `fixed inset-0 bg-[var(--rtw-scrim,rgba(15,23,42,0.18))] transition-opacity motion-reduce:transition-none lg:hidden ${zIndexClassName} ${isOpen ? "pointer-events-auto duration-200 opacity-100" : "pointer-events-none duration-120 opacity-0"}`
1178
+ }), /* @__PURE__ */ jsxs("nav", {
1179
+ ref: navRef,
1180
+ "aria-label": ariaLabel,
1181
+ style: { height: `calc(${NAV_HEIGHT_PX}px + env(safe-area-inset-bottom))` },
1182
+ className: `fixed inset-x-0 bottom-0 flex items-stretch border-t border-[var(--rtw-border,#dfe5ef)] bg-[var(--rtw-surface,#ffffff)]/90 pb-[env(safe-area-inset-bottom)] backdrop-blur-xl lg:hidden ${zIndexClassName}`,
1183
+ children: [
1184
+ /* @__PURE__ */ jsx("span", {
1185
+ "aria-hidden": "true",
1186
+ style: {
1187
+ transform: `translateX(${pill.x}px)`,
1188
+ opacity: pill.visible ? 1 : 0,
1189
+ top: 0,
1190
+ width: pill.width
1191
+ },
1192
+ className: `pointer-events-none absolute left-0 z-10 h-[2.5px] rounded-b-full bg-[var(--rtw-accent,#6366f1)] motion-reduce:transition-none ${pill.instant ? "transition-opacity duration-200" : `transition-[transform,width,opacity] duration-[320ms] ${EASE_OUT}`}`
1193
+ }),
1194
+ geometry && /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("svg", {
1195
+ "aria-hidden": "true",
1196
+ width: navWidth,
1197
+ height: panel.svgHeight,
1198
+ viewBox: `0 0 ${navWidth} ${panel.svgHeight}`,
1199
+ style: { top: panel.top },
1200
+ className: "pointer-events-none absolute left-0 z-[1] overflow-visible drop-shadow-[0_8px_20px_rgba(15,23,42,0.2)]",
1201
+ children: /* @__PURE__ */ jsx("path", {
1202
+ ref: pathRef,
1203
+ fill: "var(--rtw-accent, #6366f1)"
1204
+ })
1205
+ }), /* @__PURE__ */ jsx("div", {
1206
+ id: submenuId,
1207
+ ref: panelRef,
1208
+ role: "menu",
1209
+ "aria-label": `${menuItem?.label ?? ""} options`,
1210
+ "aria-hidden": !isOpen,
1211
+ onKeyDown: handleMenuKeyDown,
1212
+ style: {
1213
+ top: panel.top,
1214
+ left: panel.left,
1215
+ width: panel.width,
1216
+ height: panel.height,
1217
+ padding: `${PANEL_PAD_Y_PX}px ${PANEL_PAD_X_PX}px`,
1218
+ gap: ITEM_GAP_PX,
1219
+ gridTemplateColumns: `repeat(${gridCols}, minmax(0, 1fr))`
1220
+ },
1221
+ className: `absolute z-20 grid items-center transition-[left,width,top,height] duration-[220ms] ${EASE_OUT} motion-reduce:transition-none ${isOpen ? "pointer-events-auto" : "pointer-events-none"}`,
1222
+ children: subItems.map((sub, index) => /* @__PURE__ */ jsx("button", {
1223
+ type: "button",
1224
+ role: "menuitem",
1225
+ tabIndex: isOpen ? 0 : -1,
1226
+ onClick: () => {
1227
+ closeMenu(true);
1228
+ sub.onSelect();
1229
+ },
1230
+ className: `flex h-12 min-w-0 cursor-pointer items-center justify-center rounded-2xl px-1 text-[var(--rtw-accent-foreground,#ffffff)] outline-none transition-[background-color,transform] duration-150 [-webkit-tap-highlight-color:transparent] active:scale-95 focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[var(--rtw-accent-foreground,#ffffff)]/70 motion-reduce:transition-none ${sub.active ? "bg-[var(--rtw-accent-foreground,#ffffff)]/18" : "hover:bg-[var(--rtw-accent-foreground,#ffffff)]/10"}`,
1231
+ children: /* @__PURE__ */ jsxs("span", {
1232
+ style: {
1233
+ transitionDelay: isOpen ? `${65 + index * 22}ms` : "0ms",
1234
+ transitionDuration: isOpen ? "200ms" : "50ms"
1235
+ },
1236
+ className: `flex min-w-0 flex-col items-center gap-1 transition-[opacity,transform] ${EASE_OUT} motion-reduce:transition-none ${isOpen ? "translate-y-0 opacity-100" : "translate-y-2 opacity-0"}`,
1237
+ children: [/* @__PURE__ */ jsx("span", {
1238
+ "aria-hidden": "true",
1239
+ className: "flex size-5 items-center justify-center [&>svg]:size-5",
1240
+ children: sub.icon
1241
+ }), /* @__PURE__ */ jsx("span", {
1242
+ className: "max-w-full truncate text-[10px] font-medium leading-[10px]",
1243
+ children: sub.label
1244
+ })]
1245
+ })
1246
+ }, sub.id))
1247
+ })] }),
1248
+ /* @__PURE__ */ jsx("div", {
1249
+ className: "relative z-10 flex min-w-0 flex-1 items-stretch",
1250
+ children: slots.map(renderSlot)
1251
+ })
1252
+ ]
1253
+ })] });
1254
+ }
1255
+ // src/components/TooltipSlot.tsx
1256
+ function TooltipSlot({ renderTooltip, label, shortcut, side = "bottom", children }) {
1257
+ if (!renderTooltip) return /* @__PURE__ */ jsx(Fragment$1, { children });
1258
+ return /* @__PURE__ */ jsx(Fragment$1, { children: renderTooltip({
1259
+ label,
1260
+ shortcut,
1261
+ side,
1262
+ children
1263
+ }) });
1264
+ }
1265
+ // src/components/WorkspaceLayoutNode.tsx
1266
+ function nodeContains(node, id) {
1267
+ return node.type === "panel" ? node.id === id : node.children.some((child) => nodeContains(child, id));
1268
+ }
1269
+ function countNodePanels(node) {
1270
+ return node.type === "panel" ? 1 : node.children.reduce((total, child) => total + countNodePanels(child), 0);
1271
+ }
1272
+ function getDropLabel(position) {
1273
+ switch (position) {
1274
+ case "left": return "Split Left";
1275
+ case "right": return "Split Right";
1276
+ case "top": return "Stack Above";
1277
+ case "bottom": return "Stack Below";
1278
+ }
1279
+ }
1280
+ function getOppositeFoldSide(side) {
1281
+ switch (side) {
1282
+ case "left": return "right";
1283
+ case "right": return "left";
1284
+ case "up": return "down";
1285
+ case "down": return "up";
1286
+ }
1287
+ }
1288
+ function getSlotFoldSide(direction, children, index, folds) {
1289
+ const allBeforeFolded = index > 0 && children.slice(0, index).every((child) => isNodeFolded(child, folds));
1290
+ const allAfterFolded = index < children.length - 1 && children.slice(index + 1).every((child) => isNodeFolded(child, folds));
1291
+ if (direction === "horizontal") {
1292
+ if (index === 0 || allBeforeFolded) return "left";
1293
+ if (index === children.length - 1 || allAfterFolded) return "right";
1294
+ return index < children.length / 2 ? "left" : "right";
1295
+ }
1296
+ if (index === 0 || allBeforeFolded) return "up";
1297
+ if (index === children.length - 1 || allAfterFolded) return "down";
1298
+ return index < children.length / 2 ? "up" : "down";
1299
+ }
1300
+ function renderFoldChevron(side, className = "size-3.5") {
1301
+ switch (side) {
1302
+ case "left": return /* @__PURE__ */ jsx(ChevronLeftIcon, { className });
1303
+ case "right": return /* @__PURE__ */ jsx(ChevronRightIcon, { className });
1304
+ case "up": return /* @__PURE__ */ jsx(ChevronUpIcon, { className });
1305
+ case "down": return /* @__PURE__ */ jsx(ChevronDownIcon, { className });
1306
+ }
1307
+ }
1308
+ function DropZoneOverlay({ position, compact = false, showLabel = true }) {
1309
+ if (compact) return /* @__PURE__ */ jsx("div", {
1310
+ "aria-hidden": "true",
1311
+ "data-drop-position": position,
1312
+ className: `rtw-animate-drop pointer-events-none absolute z-30 flex items-center justify-center rounded-lg border border-[var(--rtw-accent,#6366f1)] bg-[var(--rtw-accent-tint-strong,rgba(99,102,241,0.22))] ${position === "left" ? "inset-y-1 left-1 w-[calc(44%-0.25rem)] border-l-[3px]" : position === "right" ? "inset-y-1 right-1 w-[calc(44%-0.25rem)] border-r-[3px]" : position === "top" ? "inset-x-1 top-1 h-[calc(44%-0.25rem)] border-t-[3px]" : "inset-x-1 bottom-1 h-[calc(44%-0.25rem)] border-b-[3px]"}`,
1313
+ children: showLabel && /* @__PURE__ */ jsx("span", {
1314
+ className: "truncate rounded bg-[var(--rtw-accent,#6366f1)] px-1.5 py-0.5 text-[10px] font-semibold tracking-tight text-[var(--rtw-accent-foreground,#ffffff)] shadow-sm",
1315
+ children: getDropLabel(position)
1316
+ })
1317
+ });
1318
+ return /* @__PURE__ */ jsx("div", {
1319
+ "aria-hidden": "true",
1320
+ "data-drop-position": position,
1321
+ className: `rtw-animate-drop pointer-events-none absolute z-30 flex items-center justify-center rounded-xl border-2 border-dashed border-[var(--rtw-accent,#6366f1)] bg-[var(--rtw-accent-tint-strong,rgba(99,102,241,0.2))] backdrop-blur-[2px] ${position === "left" ? "inset-y-2 left-2 w-[calc(38%-0.5rem)]" : position === "right" ? "inset-y-2 right-2 w-[calc(38%-0.5rem)]" : position === "top" ? "inset-x-2 top-2 h-[calc(46%-0.5rem)]" : "inset-x-2 bottom-2 h-[calc(46%-0.5rem)]"}`,
1322
+ children: /* @__PURE__ */ jsx("span", {
1323
+ className: "rounded-lg bg-[var(--rtw-accent,#6366f1)] px-2.5 py-1 text-[11px] font-semibold tracking-tight text-[var(--rtw-accent-foreground,#ffffff)] shadow-md",
1324
+ children: getDropLabel(position)
1325
+ })
1326
+ });
1327
+ }
1328
+ function WorkspaceLayoutNodeView({ node, path, parentDirection, parentFoldSide = null, collapsedAxis = null, collapsedFoldSide = null, panels, folds, maximizedId, focusedPanelId, draggedId, dragOverTarget, activeDividerKey = null, nearFoldTarget = null, renderTooltip, onFocusPanel, onDragStart, onDragEnd, onPanelDragOver, onPanelDragLeave, onPanelDrop, onToggleFold, onMaximize, onMinimize, onRestoreCompactPanel, onResizeStart, onEqualize, onKeyboardResize }) {
1329
+ const panelElementRef = useRef(null);
1330
+ const [panelSize, setPanelSize] = useState(null);
1331
+ const pathKey = path.join(".");
1332
+ const panelNodeId = node.type === "panel" ? node.id : "";
1333
+ const containsMaximized = maximizedId !== null && nodeContains(node, maximizedId);
1334
+ const hidden = maximizedId !== null && !containsMaximized;
1335
+ useEffect(() => {
1336
+ const panelElement = panelElementRef.current;
1337
+ if (!panelElement || typeof ResizeObserver === "undefined" || hidden) {
1338
+ if (!hidden) setPanelSize(null);
1339
+ return;
1340
+ }
1341
+ const updatePanelSize = () => {
1342
+ const rect = panelElement.getBoundingClientRect();
1343
+ if (rect.width === 0 && rect.height === 0) return;
1344
+ setPanelSize((previous) => previous?.width === rect.width && previous.height === rect.height ? previous : {
1345
+ width: rect.width,
1346
+ height: rect.height
1347
+ });
1348
+ };
1349
+ updatePanelSize();
1350
+ const observer = new ResizeObserver(updatePanelSize);
1351
+ observer.observe(panelElement);
1352
+ return () => observer.disconnect();
1353
+ }, [
1354
+ node.type,
1355
+ panelNodeId,
1356
+ pathKey,
1357
+ hidden
1358
+ ]);
1359
+ if (node.type === "split") {
1360
+ const sizes = node.children.map((_, index) => node.sizes?.[index] ?? 1);
1361
+ const isInsideHorizontalRail = collapsedAxis === "horizontal";
1362
+ const isInsideVerticalBar = collapsedAxis === "vertical";
1363
+ const renderDirection = isInsideHorizontalRail ? "vertical" : isInsideVerticalBar ? "horizontal" : node.direction;
1364
+ const handleDividerKeyDown = (event, index, direction) => {
1365
+ if (event.key === "Enter" || event.key === " ") {
1366
+ event.preventDefault();
1367
+ onEqualize?.(path, index);
1368
+ return;
1369
+ }
1370
+ if (direction === "horizontal") {
1371
+ if (event.key === "ArrowLeft") {
1372
+ event.preventDefault();
1373
+ onKeyboardResize?.(path, index, direction, -.08);
1374
+ } else if (event.key === "ArrowRight") {
1375
+ event.preventDefault();
1376
+ onKeyboardResize?.(path, index, direction, .08);
1377
+ }
1378
+ } else if (event.key === "ArrowUp") {
1379
+ event.preventDefault();
1380
+ onKeyboardResize?.(path, index, direction, -.08);
1381
+ } else if (event.key === "ArrowDown") {
1382
+ event.preventDefault();
1383
+ onKeyboardResize?.(path, index, direction, .08);
1384
+ }
1385
+ };
1386
+ return /* @__PURE__ */ jsx("div", {
1387
+ "data-layout-path": pathKey,
1388
+ "data-render-direction": renderDirection,
1389
+ className: `flex min-h-0 min-w-0 ${renderDirection === "horizontal" ? "flex-row" : "flex-col"} ${isInsideHorizontalRail || isInsideVerticalBar ? "gap-1.5" : ""} ${hidden ? "hidden" : ""}`,
1390
+ style: {
1391
+ flex: "1 1 0%",
1392
+ minWidth: 0,
1393
+ minHeight: 0
1394
+ },
1395
+ children: node.children.map((child, index) => {
1396
+ const childPath = [...path, index];
1397
+ const childIsFolded = isNodeFolded(child, folds);
1398
+ const isMaximizedSibling = containsMaximized && !nodeContains(child, maximizedId);
1399
+ const isNearFold = nearFoldTarget?.pathKey === pathKey && nearFoldTarget.childIndex === index;
1400
+ const slotFoldSide = getSlotFoldSide(node.direction, node.children, index, folds);
1401
+ let childCollapsedAxis = collapsedAxis;
1402
+ let childCollapsedFoldSide = collapsedFoldSide;
1403
+ if (!collapsedAxis && childIsFolded && !containsMaximized) {
1404
+ childCollapsedAxis = node.direction;
1405
+ childCollapsedFoldSide = slotFoldSide;
1406
+ }
1407
+ const childStyle = isMaximizedSibling ? {
1408
+ flex: "0 0 0px",
1409
+ minWidth: 0,
1410
+ minHeight: 0,
1411
+ overflow: "hidden"
1412
+ } : containsMaximized ? {
1413
+ flex: "1 1 0%",
1414
+ minWidth: 0,
1415
+ minHeight: 0,
1416
+ overflow: "hidden"
1417
+ } : isInsideHorizontalRail || isInsideVerticalBar ? {
1418
+ flex: `${countNodePanels(child)} 1 0%`,
1419
+ minWidth: 0,
1420
+ minHeight: 0,
1421
+ overflow: "hidden"
1422
+ } : childIsFolded && !containsMaximized && !isInsideHorizontalRail && !isInsideVerticalBar ? node.direction === "horizontal" ? {
1423
+ flex: `0 0 46px`,
1424
+ width: 46,
1425
+ minWidth: 46,
1426
+ minHeight: 0,
1427
+ overflow: "hidden"
1428
+ } : {
1429
+ flex: `0 0 44px`,
1430
+ height: 44,
1431
+ minHeight: 44,
1432
+ minWidth: 0,
1433
+ overflow: "hidden"
1434
+ } : {
1435
+ flex: `${sizes[index]} 1 0%`,
1436
+ minWidth: 0,
1437
+ minHeight: 0,
1438
+ overflow: "hidden"
1439
+ };
1440
+ const isDividerActive = activeDividerKey === `${pathKey}:${index}`;
1441
+ const showDivider = !maximizedId && !isInsideHorizontalRail && !isInsideVerticalBar && index < node.children.length - 1;
1442
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("div", {
1443
+ "data-layout-child": true,
1444
+ "data-folded": childIsFolded ? "true" : "false",
1445
+ style: childStyle,
1446
+ className: "rtw-split-child relative flex min-h-0 min-w-0",
1447
+ children: [/* @__PURE__ */ jsx(WorkspaceLayoutNodeView, {
1448
+ node: child,
1449
+ path: childPath,
1450
+ parentDirection: node.direction,
1451
+ parentFoldSide: slotFoldSide,
1452
+ collapsedAxis: childCollapsedAxis,
1453
+ collapsedFoldSide: childCollapsedFoldSide,
1454
+ panels,
1455
+ folds,
1456
+ maximizedId,
1457
+ focusedPanelId,
1458
+ draggedId,
1459
+ dragOverTarget,
1460
+ activeDividerKey,
1461
+ nearFoldTarget,
1462
+ renderTooltip,
1463
+ onFocusPanel,
1464
+ onDragStart,
1465
+ onDragEnd,
1466
+ onPanelDragOver,
1467
+ onPanelDragLeave,
1468
+ onPanelDrop,
1469
+ onToggleFold,
1470
+ onMaximize,
1471
+ onMinimize,
1472
+ onRestoreCompactPanel,
1473
+ onResizeStart,
1474
+ onEqualize,
1475
+ onKeyboardResize
1476
+ }), isNearFold && !childIsFolded && /* @__PURE__ */ jsx("div", {
1477
+ "aria-hidden": "true",
1478
+ className: "rtw-animate-drop pointer-events-none absolute inset-0 z-30 flex items-center justify-center rounded-[var(--rtw-radius-panel,0.875rem)] border-2 border-dashed border-[var(--rtw-accent,#6366f1)] bg-[var(--rtw-accent-tint-strong,rgba(99,102,241,0.18))] backdrop-blur-[2px]",
1479
+ children: /* @__PURE__ */ jsxs("div", {
1480
+ className: "flex flex-col items-center gap-1 rounded-lg bg-[var(--rtw-surface,#ffffff)]/95 px-2.5 py-1.5 text-[11px] font-semibold text-[var(--rtw-accent,#6366f1)] shadow-md",
1481
+ children: [renderFoldChevron(slotFoldSide, "size-4"), /* @__PURE__ */ jsx("span", {
1482
+ className: "whitespace-nowrap",
1483
+ children: "Fold"
1484
+ })]
1485
+ })
1486
+ })]
1487
+ }), showDivider && /* @__PURE__ */ jsxs("div", {
1488
+ role: "separator",
1489
+ tabIndex: 0,
1490
+ "aria-label": node.direction === "horizontal" ? "Resize columns (double-click to equalize)" : "Resize rows (double-click to equalize)",
1491
+ "aria-orientation": node.direction === "horizontal" ? "vertical" : "horizontal",
1492
+ title: "Drag to resize · Double-click to equalize",
1493
+ onPointerDown: (event) => onResizeStart(event, path, index, node.direction),
1494
+ onDoubleClick: () => onEqualize?.(path, index),
1495
+ onKeyDown: (event) => handleDividerKeyDown(event, index, node.direction),
1496
+ className: `group relative z-10 flex shrink-0 touch-none select-none items-center justify-center bg-transparent outline-none focus-visible:ring-2 focus-visible:ring-[var(--rtw-accent,#6366f1)] ${node.direction === "horizontal" ? "w-2.5 cursor-col-resize" : "h-2.5 cursor-row-resize"}`,
1497
+ children: [/* @__PURE__ */ jsx("span", {
1498
+ "aria-hidden": "true",
1499
+ "data-divider-track": true,
1500
+ className: `pointer-events-none absolute rounded-full bg-[var(--rtw-accent-ring-subtle,rgba(99,102,241,0.28))] ${node.direction === "horizontal" ? "inset-y-0 left-1/2 w-[2px] -translate-x-1/2" : "inset-x-0 top-1/2 h-[2px] -translate-y-1/2"} ${isDividerActive ? "opacity-100" : "opacity-0 group-hover:opacity-100 group-focus-visible:opacity-100"}`
1501
+ }), /* @__PURE__ */ jsx("div", { className: `relative rounded-full transition-all duration-150 ${node.direction === "horizontal" ? isDividerActive ? "h-12 w-1 bg-[var(--rtw-accent,#6366f1)] shadow-[0_0_10px_var(--rtw-accent-ring,rgba(99,102,241,0.48))]" : "h-7 w-[3px] bg-[var(--rtw-border-strong,#c9d3e2)]/75 group-hover:h-11 group-hover:w-1 group-hover:bg-[var(--rtw-accent,#6366f1)] group-focus-visible:bg-[var(--rtw-accent,#6366f1)]" : isDividerActive ? "h-1 w-12 bg-[var(--rtw-accent,#6366f1)] shadow-[0_0_10px_var(--rtw-accent-ring,rgba(99,102,241,0.48))]" : "h-[3px] w-7 bg-[var(--rtw-border-strong,#c9d3e2)]/75 group-hover:h-1 group-hover:w-11 group-hover:bg-[var(--rtw-accent,#6366f1)] group-focus-visible:bg-[var(--rtw-accent,#6366f1)]"}` })]
1502
+ })] }, child.type === "panel" ? child.id : childPath.join("."));
1503
+ })
1504
+ });
1505
+ }
1506
+ const panel = panels.get(node.id);
1507
+ if (!panel) return null;
1508
+ const folded = (folds[node.id] ?? "open") === "folded";
1509
+ const isMaximized = maximizedId === node.id;
1510
+ const isFocused = focusedPanelId === node.id;
1511
+ const isBeingDragged = draggedId === node.id;
1512
+ const isDropTarget = dragOverTarget?.panelId === node.id && draggedId !== node.id;
1513
+ const dropPosition = isDropTarget ? dragOverTarget.position : null;
1514
+ const responsiveCompactAxis = panelSize && !folded && !isMaximized && !hidden && panelSize.width > 0 && panelSize.height > 0 ? getResponsiveCompactAxis(panelSize.width, panelSize.height) : null;
1515
+ const compactButtonSize = panelSize ? Math.max(16, Math.min(32, Math.floor(Math.min(panelSize.width, panelSize.height) - 4))) : 24;
1516
+ const showVerticalRailDetails = !panelSize || panelSize.height >= 160 && panelSize.width >= 38;
1517
+ const showFoldedBarTitle = !panelSize || panelSize.width >= 150 && panelSize.height >= 36;
1518
+ const showFoldedBarActions = !panelSize || panelSize.width >= 240 && panelSize.height >= 36;
1519
+ const showCompactBarTitle = Boolean(panelSize) && panelSize.width >= 150 && panelSize.height >= 44;
1520
+ const showCompactBarActions = Boolean(panelSize) && panelSize.width >= 280 && panelSize.height >= 48;
1521
+ const showCompactDropLabel = !panelSize || panelSize.width >= 110 && panelSize.height >= 40;
1522
+ const effectiveAxis = collapsedAxis ?? parentDirection ?? "vertical";
1523
+ const isVerticalRail = folded && !isMaximized && effectiveAxis === "horizontal";
1524
+ const isHorizontalBar = folded && !isMaximized && effectiveAxis !== "horizontal";
1525
+ const foldLabel = folded ? `Unfold ${panel.title}` : `Fold ${panel.title}`;
1526
+ const maximizeLabel = isMaximized ? `Restore ${panel.title}` : `Maximize ${panel.title}`;
1527
+ const foldDirectionSide = collapsedFoldSide ?? parentFoldSide ?? (parentDirection === "horizontal" ? "left" : "up");
1528
+ const unfoldDirectionSide = getOppositeFoldSide(foldDirectionSide);
1529
+ const canFold = !isMaximized && parentDirection !== null;
1530
+ const handleHeaderDragStart = (event) => {
1531
+ event.dataTransfer.effectAllowed = "move";
1532
+ try {
1533
+ event.dataTransfer.setData("text/plain", node.id);
1534
+ } catch {}
1535
+ onDragStart(node.id);
1536
+ };
1537
+ if (isVerticalRail) return /* @__PURE__ */ jsxs("section", {
1538
+ ref: panelElementRef,
1539
+ "data-layout-path": pathKey,
1540
+ "data-panel-id": node.id,
1541
+ "data-folded": "true",
1542
+ tabIndex: -1,
1543
+ onMouseDown: () => onFocusPanel(node.id),
1544
+ onFocusCapture: () => onFocusPanel(node.id),
1545
+ onClick: () => onToggleFold(node.id),
1546
+ onDragOver: (event) => onPanelDragOver(event, node.id),
1547
+ onDragLeave: (event) => onPanelDragLeave(event, node.id),
1548
+ onDrop: (event) => onPanelDrop(event, node.id),
1549
+ style: {
1550
+ flex: "1 1 0%",
1551
+ minWidth: 0,
1552
+ minHeight: 0
1553
+ },
1554
+ className: `group/rail relative flex min-h-0 cursor-pointer flex-col items-center overflow-hidden rounded-[var(--rtw-radius-panel,0.875rem)] border bg-[var(--rtw-surface-header,#f8fafc)] shadow-[var(--rtw-shadow-panel)] outline-none transition-[border-color,background-color,box-shadow,opacity] duration-150 ${showVerticalRailDetails ? "justify-between py-2" : "justify-center p-1"} ${isBeingDragged ? "opacity-45" : "opacity-100"} ${isDropTarget ? "border-[var(--rtw-accent,#6366f1)] ring-2 ring-inset ring-[var(--rtw-accent-ring)]" : isFocused ? "border-[var(--rtw-accent,#6366f1)]/60 bg-[var(--rtw-surface,#ffffff)]" : "border-[var(--rtw-border,#dfe5ef)] hover:border-[var(--rtw-accent,#6366f1)]/45 hover:bg-[var(--rtw-surface,#ffffff)]"}`,
1555
+ children: [
1556
+ isFocused && /* @__PURE__ */ jsx("span", {
1557
+ "aria-hidden": "true",
1558
+ className: "pointer-events-none absolute inset-y-2 left-0 w-[2.5px] rounded-r-full bg-[var(--rtw-accent,#6366f1)]"
1559
+ }),
1560
+ dropPosition && /* @__PURE__ */ jsx(DropZoneOverlay, {
1561
+ position: dropPosition,
1562
+ compact: true,
1563
+ showLabel: false
1564
+ }),
1565
+ /* @__PURE__ */ jsx("div", {
1566
+ draggable: true,
1567
+ onDragStart: handleHeaderDragStart,
1568
+ onDragEnd,
1569
+ className: "flex shrink-0 flex-col items-center gap-1.5",
1570
+ children: /* @__PURE__ */ jsx(TooltipSlot, {
1571
+ renderTooltip,
1572
+ label: foldLabel,
1573
+ shortcut: ["F"],
1574
+ side: "right",
1575
+ children: /* @__PURE__ */ jsx("button", {
1576
+ type: "button",
1577
+ onClick: (event) => {
1578
+ event.stopPropagation();
1579
+ onToggleFold(node.id);
1580
+ },
1581
+ "aria-label": foldLabel,
1582
+ title: `${foldLabel} (F)`,
1583
+ style: {
1584
+ width: showVerticalRailDetails ? 32 : compactButtonSize,
1585
+ height: showVerticalRailDetails ? 32 : compactButtonSize
1586
+ },
1587
+ className: "flex shrink-0 cursor-pointer items-center justify-center rounded-lg bg-[var(--rtw-accent-tint,rgba(99,102,241,0.12))] text-[var(--rtw-accent,#6366f1)] transition-transform duration-150 hover:scale-105 hover:bg-[var(--rtw-accent-tint-strong)] focus-visible:outline-2 focus-visible:outline-[var(--rtw-accent,#6366f1)]",
1588
+ children: /* @__PURE__ */ jsx("span", {
1589
+ "aria-hidden": "true",
1590
+ className: "flex size-4 items-center justify-center",
1591
+ children: panel.icon
1592
+ })
1593
+ })
1594
+ })
1595
+ }),
1596
+ showVerticalRailDetails && /* @__PURE__ */ jsx("button", {
1597
+ type: "button",
1598
+ draggable: true,
1599
+ onDragStart: handleHeaderDragStart,
1600
+ onDragEnd,
1601
+ onClick: (event) => {
1602
+ event.stopPropagation();
1603
+ onToggleFold(node.id);
1604
+ },
1605
+ "aria-label": `Expand ${panel.title}`,
1606
+ title: `Click to expand ${panel.title} · Drag to move`,
1607
+ className: "flex min-h-0 flex-1 w-full cursor-pointer items-start justify-center overflow-hidden px-1 pt-2.5 pb-2 text-[var(--rtw-text-muted,#475569)] transition-colors hover:text-[var(--rtw-text-strong,#0f172a)] focus-visible:outline-2 focus-visible:outline-inset focus-visible:outline-[var(--rtw-accent,#6366f1)]",
1608
+ children: /* @__PURE__ */ jsx("span", {
1609
+ className: "max-h-full truncate text-[12px] font-semibold tracking-[0.02em] [writing-mode:vertical-rl] rotate-180",
1610
+ children: panel.title
1611
+ })
1612
+ }),
1613
+ showVerticalRailDetails && /* @__PURE__ */ jsxs("div", {
1614
+ className: "flex shrink-0 flex-col items-center gap-1",
1615
+ children: [
1616
+ /* @__PURE__ */ jsx(TooltipSlot, {
1617
+ renderTooltip,
1618
+ label: foldLabel,
1619
+ shortcut: ["F"],
1620
+ side: "right",
1621
+ children: /* @__PURE__ */ jsx("button", {
1622
+ type: "button",
1623
+ onClick: (event) => {
1624
+ event.stopPropagation();
1625
+ onToggleFold(node.id);
1626
+ },
1627
+ "aria-label": `Unfold ${panel.title} rail`,
1628
+ title: `${foldLabel} (F)`,
1629
+ className: "inline-flex size-7 cursor-pointer items-center justify-center rounded-md text-[var(--rtw-text-subtle,#64748b)] transition-colors hover:bg-[var(--rtw-surface-hover,#e5ebf3)] hover:text-[var(--rtw-accent,#6366f1)]",
1630
+ children: renderFoldChevron(unfoldDirectionSide)
1631
+ })
1632
+ }),
1633
+ /* @__PURE__ */ jsx(TooltipSlot, {
1634
+ renderTooltip,
1635
+ label: maximizeLabel,
1636
+ shortcut: ["M"],
1637
+ side: "right",
1638
+ children: /* @__PURE__ */ jsx("button", {
1639
+ type: "button",
1640
+ onClick: (event) => {
1641
+ event.stopPropagation();
1642
+ onMaximize(node.id);
1643
+ },
1644
+ "aria-label": maximizeLabel,
1645
+ title: `${maximizeLabel} (M)`,
1646
+ className: "inline-flex size-7 cursor-pointer items-center justify-center rounded-md text-[var(--rtw-text-subtle,#64748b)] transition-colors hover:bg-[var(--rtw-surface-hover,#e5ebf3)] hover:text-[var(--rtw-text-strong,#0f172a)]",
1647
+ children: /* @__PURE__ */ jsx(MaximizeIcon, { className: "size-3.5" })
1648
+ })
1649
+ }),
1650
+ /* @__PURE__ */ jsx(TooltipSlot, {
1651
+ renderTooltip,
1652
+ label: `Dock ${panel.title}`,
1653
+ shortcut: ["X"],
1654
+ side: "right",
1655
+ children: /* @__PURE__ */ jsx("button", {
1656
+ type: "button",
1657
+ onClick: (event) => {
1658
+ event.stopPropagation();
1659
+ onMinimize(node.id);
1660
+ },
1661
+ "aria-label": `Minimize ${panel.title}`,
1662
+ title: `Minimize ${panel.title} to top bar (X)`,
1663
+ className: "inline-flex size-7 cursor-pointer items-center justify-center rounded-md text-[var(--rtw-text-subtle,#64748b)] transition-colors hover:bg-[var(--rtw-surface-hover,#e5ebf3)] hover:text-[var(--rtw-text-strong,#0f172a)]",
1664
+ children: /* @__PURE__ */ jsx(MinusIcon, { className: "size-3.5" })
1665
+ })
1666
+ })
1667
+ ]
1668
+ })
1669
+ ]
1670
+ });
1671
+ if (isHorizontalBar) return /* @__PURE__ */ jsxs("section", {
1672
+ ref: panelElementRef,
1673
+ "data-layout-path": pathKey,
1674
+ "data-panel-id": node.id,
1675
+ "data-folded": "true",
1676
+ tabIndex: -1,
1677
+ onMouseDown: () => onFocusPanel(node.id),
1678
+ onFocusCapture: () => onFocusPanel(node.id),
1679
+ onClick: () => onToggleFold(node.id),
1680
+ onDragOver: (event) => onPanelDragOver(event, node.id),
1681
+ onDragLeave: (event) => onPanelDragLeave(event, node.id),
1682
+ onDrop: (event) => onPanelDrop(event, node.id),
1683
+ style: {
1684
+ flex: "1 1 0%",
1685
+ minWidth: 0,
1686
+ minHeight: 0
1687
+ },
1688
+ className: `relative flex h-full cursor-pointer items-center overflow-hidden rounded-[var(--rtw-radius-panel,0.875rem)] border bg-[var(--rtw-surface-header,#f8fafc)] shadow-[var(--rtw-shadow-panel)] outline-none transition-[border-color,background-color,opacity] duration-150 ${showFoldedBarTitle ? "justify-between gap-2 px-2.5" : "justify-center p-1"} ${isBeingDragged ? "opacity-45" : "opacity-100"} ${isDropTarget ? "border-[var(--rtw-accent,#6366f1)] ring-2 ring-inset ring-[var(--rtw-accent-ring)]" : isFocused ? "border-[var(--rtw-accent,#6366f1)]/60 bg-[var(--rtw-surface,#ffffff)]" : "border-[var(--rtw-border,#dfe5ef)] hover:border-[var(--rtw-accent,#6366f1)]/45 hover:bg-[var(--rtw-surface,#ffffff)]"}`,
1689
+ children: [
1690
+ dropPosition && /* @__PURE__ */ jsx(DropZoneOverlay, {
1691
+ position: dropPosition,
1692
+ compact: true,
1693
+ showLabel: showCompactDropLabel
1694
+ }),
1695
+ /* @__PURE__ */ jsx(TooltipSlot, {
1696
+ renderTooltip,
1697
+ label: foldLabel,
1698
+ shortcut: ["F"],
1699
+ children: /* @__PURE__ */ jsxs("button", {
1700
+ type: "button",
1701
+ draggable: true,
1702
+ onDragStart: handleHeaderDragStart,
1703
+ onDragEnd,
1704
+ onClick: (event) => {
1705
+ event.stopPropagation();
1706
+ onToggleFold(node.id);
1707
+ },
1708
+ "aria-label": `Expand ${panel.title}`,
1709
+ title: `Click to expand ${panel.title} · Drag to move`,
1710
+ className: `flex min-w-0 cursor-pointer items-center text-left outline-none ${showFoldedBarTitle ? "flex-1 gap-2.5 py-1" : "justify-center"}`,
1711
+ children: [/* @__PURE__ */ jsx("span", {
1712
+ "aria-hidden": "true",
1713
+ style: showFoldedBarTitle ? void 0 : {
1714
+ width: Math.min(28, compactButtonSize),
1715
+ height: Math.min(28, compactButtonSize)
1716
+ },
1717
+ className: "flex size-6 shrink-0 items-center justify-center rounded-md bg-[var(--rtw-accent-tint,rgba(99,102,241,0.12))] text-[var(--rtw-accent,#6366f1)]",
1718
+ children: panel.icon
1719
+ }), showFoldedBarTitle && /* @__PURE__ */ jsx(Fragment$1, { children: /* @__PURE__ */ jsx("h2", {
1720
+ className: "truncate text-[13px] font-semibold tracking-[-0.01em] text-[var(--rtw-text-strong,#0f172a)]",
1721
+ children: panel.title
1722
+ }) })]
1723
+ })
1724
+ }),
1725
+ showFoldedBarActions && /* @__PURE__ */ jsxs("div", {
1726
+ className: "flex shrink-0 items-center gap-0.5",
1727
+ children: [
1728
+ /* @__PURE__ */ jsx(TooltipSlot, {
1729
+ renderTooltip,
1730
+ label: foldLabel,
1731
+ shortcut: ["F"],
1732
+ children: /* @__PURE__ */ jsx("button", {
1733
+ type: "button",
1734
+ onClick: (event) => {
1735
+ event.stopPropagation();
1736
+ onToggleFold(node.id);
1737
+ },
1738
+ "aria-label": foldLabel,
1739
+ title: `${foldLabel} (F)`,
1740
+ className: "inline-flex size-7 cursor-pointer items-center justify-center rounded-md text-[var(--rtw-accent,#6366f1)] transition-colors hover:bg-[var(--rtw-accent-tint)]",
1741
+ children: renderFoldChevron(unfoldDirectionSide)
1742
+ })
1743
+ }),
1744
+ /* @__PURE__ */ jsx(TooltipSlot, {
1745
+ renderTooltip,
1746
+ label: `Dock ${panel.title}`,
1747
+ shortcut: ["X"],
1748
+ children: /* @__PURE__ */ jsx("button", {
1749
+ type: "button",
1750
+ onClick: (event) => {
1751
+ event.stopPropagation();
1752
+ onMinimize(node.id);
1753
+ },
1754
+ "aria-label": `Minimize ${panel.title}`,
1755
+ title: `Minimize ${panel.title} to top bar (X)`,
1756
+ className: "inline-flex size-7 cursor-pointer items-center justify-center rounded-md text-[var(--rtw-text-subtle,#64748b)] transition-colors hover:bg-[var(--rtw-surface-hover,#e5ebf3)] hover:text-[var(--rtw-text-strong,#0f172a)]",
1757
+ children: /* @__PURE__ */ jsx(MinusIcon, { className: "size-3.5" })
1758
+ })
1759
+ }),
1760
+ /* @__PURE__ */ jsx(TooltipSlot, {
1761
+ renderTooltip,
1762
+ label: maximizeLabel,
1763
+ shortcut: ["M"],
1764
+ children: /* @__PURE__ */ jsx("button", {
1765
+ type: "button",
1766
+ onClick: (event) => {
1767
+ event.stopPropagation();
1768
+ onMaximize(node.id);
1769
+ },
1770
+ "aria-label": maximizeLabel,
1771
+ title: `${maximizeLabel} (M)`,
1772
+ className: "inline-flex size-7 cursor-pointer items-center justify-center rounded-md text-[var(--rtw-text-subtle,#64748b)] transition-colors hover:bg-[var(--rtw-surface-hover,#e5ebf3)] hover:text-[var(--rtw-text-strong,#0f172a)]",
1773
+ children: /* @__PURE__ */ jsx(MaximizeIcon, { className: "size-3.5" })
1774
+ })
1775
+ })
1776
+ ]
1777
+ })
1778
+ ]
1779
+ });
1780
+ const isCompactVertical = responsiveCompactAxis === "vertical";
1781
+ const isCompactHorizontal = responsiveCompactAxis === "horizontal";
1782
+ const isCompact = isCompactVertical || isCompactHorizontal;
1783
+ const restoreLabel = `Restore ${panel.title} to reading size`;
1784
+ return /* @__PURE__ */ jsxs("section", {
1785
+ ref: panelElementRef,
1786
+ "data-layout-path": pathKey,
1787
+ "data-panel-id": node.id,
1788
+ "data-folded": "false",
1789
+ "data-compact": isCompact ? "true" : void 0,
1790
+ "data-compact-axis": responsiveCompactAxis ?? void 0,
1791
+ "data-focused": isCompact ? void 0 : isFocused ? "true" : "false",
1792
+ tabIndex: -1,
1793
+ onClick: responsiveCompactAxis ? () => onRestoreCompactPanel(node.id, path, responsiveCompactAxis) : void 0,
1794
+ onMouseDown: () => onFocusPanel(node.id),
1795
+ onFocusCapture: () => onFocusPanel(node.id),
1796
+ onDragOver: (event) => onPanelDragOver(event, node.id),
1797
+ onDragLeave: (event) => onPanelDragLeave(event, node.id),
1798
+ onDrop: (event) => onPanelDrop(event, node.id),
1799
+ style: {
1800
+ flex: "1 1 0%",
1801
+ minWidth: 0,
1802
+ minHeight: 0
1803
+ },
1804
+ className: `${isCompact ? `rtw-compact-panel relative flex min-h-0 min-w-0 cursor-pointer items-center overflow-hidden rounded-[var(--rtw-radius-panel,0.875rem)] border bg-[var(--rtw-surface-header,#f8fafc)] shadow-[var(--rtw-shadow-panel)] outline-none transition-[border-color,background-color,opacity] duration-150 ${isCompactVertical ? showCompactBarTitle ? "justify-between gap-2 px-2.5" : "justify-center px-2.5" : "justify-center"}` : "rtw-animate-panel group/panel relative flex min-h-0 flex-col overflow-hidden rounded-[var(--rtw-radius-panel,0.875rem)] border bg-[var(--rtw-surface,#ffffff)] shadow-[var(--rtw-shadow-panel)] outline-none transition-[border-color,box-shadow,opacity] duration-150"} ${isBeingDragged ? "opacity-45" : "opacity-100"} ${isDropTarget ? "border-[var(--rtw-accent,#6366f1)] ring-2 ring-inset ring-[var(--rtw-accent-ring)]" : isFocused ? isCompact ? "border-[var(--rtw-accent,#6366f1)]/60 bg-[var(--rtw-surface,#ffffff)]" : "border-[var(--rtw-accent,#6366f1)]/55 ring-1 ring-inset ring-[var(--rtw-accent-ring-subtle)]" : isCompact ? "border-[var(--rtw-border,#dfe5ef)] hover:border-[var(--rtw-accent,#6366f1)]/45" : "border-[var(--rtw-border,#dfe5ef)]"}`,
1805
+ children: [
1806
+ !isCompact && /* @__PURE__ */ jsx("span", {
1807
+ "aria-hidden": "true",
1808
+ className: `pointer-events-none absolute inset-x-0 top-0 z-10 h-[2px] bg-[var(--rtw-accent,#6366f1)] transition-opacity duration-200 ${isFocused ? "opacity-100" : "opacity-0"}`
1809
+ }),
1810
+ dropPosition && /* @__PURE__ */ jsx(DropZoneOverlay, {
1811
+ position: dropPosition,
1812
+ compact: isCompact,
1813
+ showLabel: isCompact ? showCompactDropLabel : true
1814
+ }),
1815
+ isCompactVertical ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(TooltipSlot, {
1816
+ renderTooltip,
1817
+ label: restoreLabel,
1818
+ side: "top",
1819
+ children: /* @__PURE__ */ jsxs("button", {
1820
+ type: "button",
1821
+ draggable: true,
1822
+ onDragStart: handleHeaderDragStart,
1823
+ onDragEnd,
1824
+ onClick: (event) => {
1825
+ event.stopPropagation();
1826
+ onRestoreCompactPanel(node.id, path, "vertical");
1827
+ },
1828
+ "aria-label": restoreLabel,
1829
+ title: restoreLabel,
1830
+ className: `flex min-w-0 cursor-pointer items-center text-left outline-none ${showCompactBarTitle ? "flex-1 gap-2.5" : "justify-center"}`,
1831
+ children: [/* @__PURE__ */ jsx("span", {
1832
+ "aria-hidden": "true",
1833
+ style: {
1834
+ width: Math.min(24, compactButtonSize),
1835
+ height: Math.min(24, compactButtonSize)
1836
+ },
1837
+ className: "flex shrink-0 items-center justify-center rounded-md bg-[var(--rtw-accent-tint,rgba(99,102,241,0.12))] text-[var(--rtw-accent,#6366f1)]",
1838
+ children: panel.icon
1839
+ }), showCompactBarTitle && /* @__PURE__ */ jsx("span", {
1840
+ className: "truncate text-[13px] font-semibold text-[var(--rtw-text-strong,#0f172a)]",
1841
+ children: panel.title
1842
+ })]
1843
+ })
1844
+ }), showCompactBarActions && /* @__PURE__ */ jsxs("div", {
1845
+ className: "flex shrink-0 items-center gap-0.5",
1846
+ children: [
1847
+ /* @__PURE__ */ jsx(TooltipSlot, {
1848
+ renderTooltip,
1849
+ label: restoreLabel,
1850
+ children: /* @__PURE__ */ jsx("button", {
1851
+ type: "button",
1852
+ onClick: (event) => {
1853
+ event.stopPropagation();
1854
+ onRestoreCompactPanel(node.id, path, "vertical");
1855
+ },
1856
+ "aria-label": restoreLabel,
1857
+ title: restoreLabel,
1858
+ className: "inline-flex size-7 cursor-pointer items-center justify-center rounded-md text-[var(--rtw-accent,#6366f1)] transition-colors hover:bg-[var(--rtw-accent-tint)]",
1859
+ children: renderFoldChevron(unfoldDirectionSide)
1860
+ })
1861
+ }),
1862
+ /* @__PURE__ */ jsx(TooltipSlot, {
1863
+ renderTooltip,
1864
+ label: `Minimize ${panel.title}`,
1865
+ shortcut: ["X"],
1866
+ children: /* @__PURE__ */ jsx("button", {
1867
+ type: "button",
1868
+ onClick: (event) => {
1869
+ event.stopPropagation();
1870
+ onMinimize(node.id);
1871
+ },
1872
+ "aria-label": `Minimize ${panel.title}`,
1873
+ title: `Minimize ${panel.title} to top bar (X)`,
1874
+ className: "inline-flex size-7 cursor-pointer items-center justify-center rounded-md text-[var(--rtw-text-subtle,#64748b)] transition-colors hover:bg-[var(--rtw-surface-hover,#e5ebf3)] hover:text-[var(--rtw-text-strong,#0f172a)]",
1875
+ children: /* @__PURE__ */ jsx(MinusIcon, { className: "size-3.5" })
1876
+ })
1877
+ }),
1878
+ /* @__PURE__ */ jsx(TooltipSlot, {
1879
+ renderTooltip,
1880
+ label: maximizeLabel,
1881
+ shortcut: ["M"],
1882
+ children: /* @__PURE__ */ jsx("button", {
1883
+ type: "button",
1884
+ onClick: (event) => {
1885
+ event.stopPropagation();
1886
+ onMaximize(node.id);
1887
+ },
1888
+ "aria-label": maximizeLabel,
1889
+ title: `${maximizeLabel} (M)`,
1890
+ className: "inline-flex size-7 cursor-pointer items-center justify-center rounded-md text-[var(--rtw-text-subtle,#64748b)] transition-colors hover:bg-[var(--rtw-surface-hover,#e5ebf3)] hover:text-[var(--rtw-text-strong,#0f172a)]",
1891
+ children: /* @__PURE__ */ jsx(MaximizeIcon, { className: "size-3.5" })
1892
+ })
1893
+ })
1894
+ ]
1895
+ })] }) : isCompactHorizontal ? /* @__PURE__ */ jsx(TooltipSlot, {
1896
+ renderTooltip,
1897
+ label: `Click to restore ${panel.title} to reading size`,
1898
+ side: "right",
1899
+ children: /* @__PURE__ */ jsx("button", {
1900
+ type: "button",
1901
+ draggable: true,
1902
+ onDragStart: handleHeaderDragStart,
1903
+ onDragEnd,
1904
+ onClick: (event) => {
1905
+ event.stopPropagation();
1906
+ onRestoreCompactPanel(node.id, path, "horizontal");
1907
+ },
1908
+ "aria-label": `Focus compact panel ${panel.title}`,
1909
+ title: `Click to restore ${panel.title} to reading size`,
1910
+ style: {
1911
+ width: compactButtonSize,
1912
+ height: compactButtonSize
1913
+ },
1914
+ className: "flex shrink-0 cursor-pointer items-center justify-center rounded-lg bg-[var(--rtw-accent-tint,rgba(99,102,241,0.12))] text-[var(--rtw-accent,#6366f1)] outline-none transition-colors hover:bg-[var(--rtw-accent-tint-strong)] focus-visible:ring-2 focus-visible:ring-[var(--rtw-accent,#6366f1)]",
1915
+ children: /* @__PURE__ */ jsx("span", {
1916
+ "aria-hidden": "true",
1917
+ className: "flex size-4 items-center justify-center",
1918
+ children: panel.icon
1919
+ })
1920
+ })
1921
+ }) : /* @__PURE__ */ jsxs("header", {
1922
+ draggable: !isMaximized,
1923
+ onDragStart: handleHeaderDragStart,
1924
+ onDragEnd,
1925
+ onDoubleClick: () => onMaximize(node.id),
1926
+ className: "flex h-10 shrink-0 cursor-grab select-none items-center justify-between gap-2 border-b border-[var(--rtw-border-muted,#eaedf4)] bg-[var(--rtw-surface-header,#f8fafc)] px-2.5 active:cursor-grabbing",
1927
+ children: [/* @__PURE__ */ jsxs("div", {
1928
+ title: "Double-click to maximize or restore · Drag to rearrange",
1929
+ className: "flex min-w-0 flex-1 items-center gap-2",
1930
+ children: [
1931
+ !isMaximized && /* @__PURE__ */ jsx("span", {
1932
+ "aria-hidden": "true",
1933
+ className: "flex shrink-0 items-center text-[var(--rtw-text-faint,#94a3b8)] opacity-50 transition-opacity duration-150 group-hover/panel:opacity-100",
1934
+ children: /* @__PURE__ */ jsx(GripVerticalIcon, { className: "size-3.5" })
1935
+ }),
1936
+ /* @__PURE__ */ jsx("span", {
1937
+ "aria-hidden": "true",
1938
+ className: `flex size-6 shrink-0 items-center justify-center rounded-md transition-colors duration-150 ${isFocused ? "bg-[var(--rtw-accent-tint,rgba(99,102,241,0.12))] text-[var(--rtw-accent,#6366f1)]" : "bg-[var(--rtw-surface-subtle,#edf1f7)] text-[var(--rtw-text-muted,#475569)]"}`,
1939
+ children: panel.icon
1940
+ }),
1941
+ /* @__PURE__ */ jsx("h2", {
1942
+ className: "truncate text-[13px] font-semibold tracking-[-0.01em] text-[var(--rtw-text-strong,#0f172a)]",
1943
+ children: panel.title
1944
+ })
1945
+ ]
1946
+ }), /* @__PURE__ */ jsxs("div", {
1947
+ className: "flex shrink-0 items-center gap-0.5",
1948
+ children: [
1949
+ canFold && /* @__PURE__ */ jsx(TooltipSlot, {
1950
+ renderTooltip,
1951
+ label: foldLabel,
1952
+ shortcut: ["F"],
1953
+ children: /* @__PURE__ */ jsx("button", {
1954
+ type: "button",
1955
+ onClick: (event) => {
1956
+ event.stopPropagation();
1957
+ onToggleFold(node.id);
1958
+ },
1959
+ "aria-label": foldLabel,
1960
+ title: `${foldLabel} (F)`,
1961
+ className: "inline-flex size-7 cursor-pointer items-center justify-center rounded-md text-[var(--rtw-text-subtle,#64748b)] transition-colors duration-150 hover:bg-[var(--rtw-surface-hover,#e5ebf3)] hover:text-[var(--rtw-text-strong,#0f172a)] focus-visible:outline-2 focus-visible:outline-[var(--rtw-accent,#6366f1)]",
1962
+ children: renderFoldChevron(foldDirectionSide)
1963
+ })
1964
+ }),
1965
+ /* @__PURE__ */ jsx(TooltipSlot, {
1966
+ renderTooltip,
1967
+ label: `Minimize ${panel.title} to top bar`,
1968
+ shortcut: ["X"],
1969
+ children: /* @__PURE__ */ jsx("button", {
1970
+ type: "button",
1971
+ onClick: (event) => {
1972
+ event.stopPropagation();
1973
+ onMinimize(node.id);
1974
+ },
1975
+ "aria-label": `Minimize ${panel.title}`,
1976
+ title: `Minimize ${panel.title} to top bar (X)`,
1977
+ className: "inline-flex size-7 cursor-pointer items-center justify-center rounded-md text-[var(--rtw-text-subtle,#64748b)] transition-colors duration-150 hover:bg-[var(--rtw-surface-hover,#e5ebf3)] hover:text-[var(--rtw-text-strong,#0f172a)] focus-visible:outline-2 focus-visible:outline-[var(--rtw-accent,#6366f1)]",
1978
+ children: /* @__PURE__ */ jsx(MinusIcon, { className: "size-3.5" })
1979
+ })
1980
+ }),
1981
+ /* @__PURE__ */ jsx(TooltipSlot, {
1982
+ renderTooltip,
1983
+ label: maximizeLabel,
1984
+ shortcut: ["M"],
1985
+ children: /* @__PURE__ */ jsx("button", {
1986
+ type: "button",
1987
+ onClick: (event) => {
1988
+ event.stopPropagation();
1989
+ onMaximize(node.id);
1990
+ },
1991
+ "aria-label": maximizeLabel,
1992
+ title: `${maximizeLabel} (M)`,
1993
+ className: "inline-flex size-7 cursor-pointer items-center justify-center rounded-md text-[var(--rtw-text-subtle,#64748b)] transition-colors duration-150 hover:bg-[var(--rtw-surface-hover,#e5ebf3)] hover:text-[var(--rtw-text-strong,#0f172a)] focus-visible:outline-2 focus-visible:outline-[var(--rtw-accent,#6366f1)]",
1994
+ children: isMaximized ? /* @__PURE__ */ jsx(MinimizeIcon, { className: "size-3.5" }) : /* @__PURE__ */ jsx(MaximizeIcon, { className: "size-3.5" })
1995
+ })
1996
+ })
1997
+ ]
1998
+ })]
1999
+ }),
2000
+ /* @__PURE__ */ jsx("div", {
2001
+ "aria-hidden": isCompact || void 0,
2002
+ className: isCompact ? "hidden" : "flex min-h-0 min-w-0 flex-1 flex-col overflow-auto",
2003
+ children: /* @__PURE__ */ jsx("div", {
2004
+ className: "flex min-h-0 min-w-[120px] flex-1 flex-col",
2005
+ children: panel.content
2006
+ })
2007
+ }, "panel-body")
2008
+ ]
2009
+ });
2010
+ }
2011
+ // src/components/LayoutPickerDialog.tsx
2012
+ function columnsTemplate(columns) {
2013
+ let index = 0;
2014
+ const columnNodes = columns.map((rowCount) => {
2015
+ const panels = Array.from({ length: rowCount }, () => ({
2016
+ type: "panel",
2017
+ index: index++
2018
+ }));
2019
+ return panels.length === 1 ? panels[0] : {
2020
+ type: "split",
2021
+ direction: "vertical",
2022
+ children: panels
2023
+ };
2024
+ });
2025
+ return columnNodes.length === 1 ? columnNodes[0] : {
2026
+ type: "split",
2027
+ direction: "horizontal",
2028
+ children: columnNodes
2029
+ };
2030
+ }
2031
+ function rowsTemplate(rows) {
2032
+ let index = 0;
2033
+ const rowNodes = rows.map((colCount) => {
2034
+ const panels = Array.from({ length: colCount }, () => ({
2035
+ type: "panel",
2036
+ index: index++
2037
+ }));
2038
+ return panels.length === 1 ? panels[0] : {
2039
+ type: "split",
2040
+ direction: "horizontal",
2041
+ children: panels
2042
+ };
2043
+ });
2044
+ return rowNodes.length === 1 ? rowNodes[0] : {
2045
+ type: "split",
2046
+ direction: "vertical",
2047
+ children: rowNodes
2048
+ };
2049
+ }
2050
+ const DEFAULT_LAYOUT_PRESETS = {
2051
+ 1: [{
2052
+ id: "1-single",
2053
+ label: "Single Focus",
2054
+ layout: columnsTemplate([1])
2055
+ }],
2056
+ 2: [{
2057
+ id: "2-cols",
2058
+ label: "Split Columns",
2059
+ layout: columnsTemplate([1, 1])
2060
+ }, {
2061
+ id: "2-rows",
2062
+ label: "Stacked Rows",
2063
+ layout: columnsTemplate([2])
2064
+ }],
2065
+ 3: [
2066
+ {
2067
+ id: "3-cols",
2068
+ label: "Three Columns",
2069
+ layout: columnsTemplate([
2070
+ 1,
2071
+ 1,
2072
+ 1
2073
+ ])
2074
+ },
2075
+ {
2076
+ id: "3-1-2",
2077
+ label: "Focus + Two Stacked",
2078
+ layout: columnsTemplate([1, 2])
2079
+ },
2080
+ {
2081
+ id: "3-2-1",
2082
+ label: "Two Stacked + Focus",
2083
+ layout: columnsTemplate([2, 1])
2084
+ },
2085
+ {
2086
+ id: "3-top-2",
2087
+ label: "Hero + Two Below",
2088
+ layout: rowsTemplate([1, 2])
2089
+ },
2090
+ {
2091
+ id: "3-2-bottom",
2092
+ label: "Two Above + Wide",
2093
+ layout: rowsTemplate([2, 1])
2094
+ },
2095
+ {
2096
+ id: "3-rows",
2097
+ label: "Three Stacked",
2098
+ layout: columnsTemplate([3])
2099
+ }
2100
+ ],
2101
+ 4: [
2102
+ {
2103
+ id: "4-studio",
2104
+ label: "Studio Trio",
2105
+ layout: columnsTemplate([
2106
+ 1,
2107
+ 2,
2108
+ 1
2109
+ ])
2110
+ },
2111
+ {
2112
+ id: "4-grid",
2113
+ label: "2 × 2 Grid",
2114
+ layout: columnsTemplate([2, 2])
2115
+ },
2116
+ {
2117
+ id: "4-1-1-2",
2118
+ label: "Two Cols + Stacked",
2119
+ layout: columnsTemplate([
2120
+ 1,
2121
+ 1,
2122
+ 2
2123
+ ])
2124
+ },
2125
+ {
2126
+ id: "4-top-3",
2127
+ label: "Top Banner + Three",
2128
+ layout: rowsTemplate([1, 3])
2129
+ },
2130
+ {
2131
+ id: "4-1-3",
2132
+ label: "Focus + Three Rail",
2133
+ layout: columnsTemplate([1, 3])
2134
+ },
2135
+ {
2136
+ id: "4-cols",
2137
+ label: "Four Columns",
2138
+ layout: columnsTemplate([
2139
+ 1,
2140
+ 1,
2141
+ 1,
2142
+ 1
2143
+ ])
2144
+ }
2145
+ ],
2146
+ 5: [
2147
+ {
2148
+ id: "5-1-2-2",
2149
+ label: "Focus + 2 × 2",
2150
+ layout: columnsTemplate([
2151
+ 1,
2152
+ 2,
2153
+ 2
2154
+ ])
2155
+ },
2156
+ {
2157
+ id: "5-2-1-2",
2158
+ label: "Command Center",
2159
+ layout: columnsTemplate([
2160
+ 2,
2161
+ 1,
2162
+ 2
2163
+ ])
2164
+ },
2165
+ {
2166
+ id: "5-2-2-1",
2167
+ label: "2 × 2 + Focus",
2168
+ layout: columnsTemplate([
2169
+ 2,
2170
+ 2,
2171
+ 1
2172
+ ])
2173
+ },
2174
+ {
2175
+ id: "5-top-2-2",
2176
+ label: "Header + 2 × 2",
2177
+ layout: rowsTemplate([
2178
+ 1,
2179
+ 2,
2180
+ 2
2181
+ ])
2182
+ },
2183
+ {
2184
+ id: "5-2-3",
2185
+ label: "Two Left + Three Right",
2186
+ layout: columnsTemplate([2, 3])
2187
+ },
2188
+ {
2189
+ id: "5-cols",
2190
+ label: "Five Columns",
2191
+ layout: columnsTemplate([
2192
+ 1,
2193
+ 1,
2194
+ 1,
2195
+ 1,
2196
+ 1
2197
+ ])
2198
+ }
2199
+ ],
2200
+ 6: [
2201
+ {
2202
+ id: "6-3x2",
2203
+ label: "3 × 2 Grid",
2204
+ layout: columnsTemplate([
2205
+ 2,
2206
+ 2,
2207
+ 2
2208
+ ])
2209
+ },
2210
+ {
2211
+ id: "6-2x3",
2212
+ label: "2 × 3 Grid",
2213
+ layout: columnsTemplate([3, 3])
2214
+ },
2215
+ {
2216
+ id: "6-1-2-3",
2217
+ label: "Cascade 1-2-3",
2218
+ layout: columnsTemplate([
2219
+ 1,
2220
+ 2,
2221
+ 3
2222
+ ])
2223
+ },
2224
+ {
2225
+ id: "6-1-1-2-2",
2226
+ label: "Two Cols + 2 × 2",
2227
+ layout: columnsTemplate([
2228
+ 1,
2229
+ 1,
2230
+ 2,
2231
+ 2
2232
+ ])
2233
+ }
2234
+ ],
2235
+ 7: [
2236
+ {
2237
+ id: "7-2-2-3",
2238
+ label: "2 + 2 + 3 Studio",
2239
+ layout: columnsTemplate([
2240
+ 2,
2241
+ 2,
2242
+ 3
2243
+ ])
2244
+ },
2245
+ {
2246
+ id: "7-3-2-2",
2247
+ label: "3 + 2 + 2 Studio",
2248
+ layout: columnsTemplate([
2249
+ 3,
2250
+ 2,
2251
+ 2
2252
+ ])
2253
+ },
2254
+ {
2255
+ id: "7-2-3-2",
2256
+ label: "2 + 3 + 2 Center",
2257
+ layout: columnsTemplate([
2258
+ 2,
2259
+ 3,
2260
+ 2
2261
+ ])
2262
+ },
2263
+ {
2264
+ id: "7-1-2-2-2",
2265
+ label: "Focus + Three Pairs",
2266
+ layout: columnsTemplate([
2267
+ 1,
2268
+ 2,
2269
+ 2,
2270
+ 2
2271
+ ])
2272
+ },
2273
+ {
2274
+ id: "7-3-4",
2275
+ label: "3 Left + 4 Right",
2276
+ layout: columnsTemplate([3, 4])
2277
+ }
2278
+ ]
2279
+ };
2280
+ function generateFallbackPresets(count) {
2281
+ if (count <= 1) return DEFAULT_LAYOUT_PRESETS[1];
2282
+ if (count > 5) {
2283
+ const makeBalancedColumns = (columnCount) => {
2284
+ const base = Math.floor(count / columnCount);
2285
+ const extraPanels = count % columnCount;
2286
+ return Array.from({ length: columnCount }, (_, index) => base + (index < extraPanels ? 1 : 0));
2287
+ };
2288
+ const gridColumns = makeBalancedColumns(Math.ceil(Math.sqrt(count)));
2289
+ const twoColumns = makeBalancedColumns(2);
2290
+ return [{
2291
+ id: `${count}-grid`,
2292
+ label: `${gridColumns.join(" + ")} Grid`,
2293
+ layout: columnsTemplate(gridColumns)
2294
+ }, {
2295
+ id: `${count}-2cols`,
2296
+ label: `${twoColumns.join(" + ")} Split`,
2297
+ layout: columnsTemplate(twoColumns)
2298
+ }];
2299
+ }
2300
+ const cols = Array.from({ length: count }, () => 1);
2301
+ const half = Math.ceil(count / 2);
2302
+ const twoCols = [half, count - half].filter((n) => n > 0);
2303
+ return [
2304
+ {
2305
+ id: `${count}-cols`,
2306
+ label: `${count} Columns`,
2307
+ layout: columnsTemplate(cols)
2308
+ },
2309
+ {
2310
+ id: `${count}-2cols`,
2311
+ label: `${twoCols.join(" + ")} Split`,
2312
+ layout: columnsTemplate(twoCols)
2313
+ },
2314
+ {
2315
+ id: `${count}-rows`,
2316
+ label: `${count} Stacked`,
2317
+ layout: columnsTemplate([count])
2318
+ }
2319
+ ];
2320
+ }
2321
+ function LayoutPickerDialog({ currentOpenCount, currentSignature, maxPanels = 7, presets: customPresets = DEFAULT_LAYOUT_PRESETS, onApplyLayout, onSaveAsDefault, renderFooterExtra, renderTooltip, open: controlledOpen, onOpenChange, iconOnly = false, trigger }) {
2322
+ const maxSections = Math.max(1, maxPanels);
2323
+ const sectionCounts = Array.from({ length: maxSections }, (_, i) => i + 1);
2324
+ const [uncontrolledOpen, setUncontrolledOpen] = useState(false);
2325
+ const open = controlledOpen ?? uncontrolledOpen;
2326
+ const setOpen = (next) => {
2327
+ if (controlledOpen === void 0) setUncontrolledOpen(next);
2328
+ onOpenChange?.(next);
2329
+ };
2330
+ const [savingDefault, setSavingDefault] = useState(false);
2331
+ const [selectedCount, setSelectedCount] = useState(() => Math.min(maxSections, Math.max(1, currentOpenCount || Math.min(4, maxSections))));
2332
+ useEffect(() => {
2333
+ if (!open) return;
2334
+ setSelectedCount(Math.min(maxSections, Math.max(1, currentOpenCount || Math.min(4, maxSections))));
2335
+ }, [
2336
+ open,
2337
+ currentOpenCount,
2338
+ maxSections
2339
+ ]);
2340
+ useEffect(() => {
2341
+ if (!open) return;
2342
+ function handleKeyDown(event) {
2343
+ if (event.key === "Escape") setOpen(false);
2344
+ }
2345
+ window.addEventListener("keydown", handleKeyDown);
2346
+ return () => window.removeEventListener("keydown", handleKeyDown);
2347
+ }, [open]);
2348
+ const presets = customPresets[selectedCount] ?? generateFallbackPresets(selectedCount);
2349
+ const renderPreview = (node, current, key = "root") => {
2350
+ if (node.type === "panel") return /* @__PURE__ */ jsxs("div", {
2351
+ className: `flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden rounded-[6px] border transition-colors duration-150 ${current ? "border-[var(--rtw-accent,#6366f1)]/45 bg-[var(--rtw-surface,#ffffff)] shadow-[0_1px_2px_rgba(15,23,42,0.06)]" : "border-[var(--rtw-border-strong,#c9d3e2)]/85 bg-[var(--rtw-surface,#ffffff)] shadow-[0_1px_2px_rgba(15,23,42,0.03)] group-hover:border-[var(--rtw-accent,#6366f1)]/45"}`,
2352
+ children: [/* @__PURE__ */ jsx("div", {
2353
+ className: `flex h-[8px] w-full shrink-0 items-center border-b px-1.5 transition-colors duration-150 ${current ? "border-[var(--rtw-accent,#6366f1)]/20 bg-[var(--rtw-accent-tint,rgba(99,102,241,0.14))]" : "border-[var(--rtw-border-muted,#eaedf4)] bg-[var(--rtw-surface-header,#f8fafc)] group-hover:bg-[var(--rtw-accent-tint,rgba(99,102,241,0.08))]"}`,
2354
+ children: /* @__PURE__ */ jsx("span", { className: `h-[2.5px] w-3.5 rounded-full transition-colors duration-150 ${current ? "bg-[var(--rtw-accent,#6366f1)]/60" : "bg-[var(--rtw-border-strong,#c9d3e2)] group-hover:bg-[var(--rtw-accent,#6366f1)]/45"}` })
2355
+ }), /* @__PURE__ */ jsx("div", {
2356
+ className: "flex min-h-0 flex-1 items-center justify-center overflow-hidden p-1",
2357
+ children: /* @__PURE__ */ jsx("span", {
2358
+ className: `text-[11px] font-semibold leading-none tabular-nums transition-colors duration-150 ${current ? "text-[var(--rtw-accent,#6366f1)]/85" : "text-[var(--rtw-text-faint,#94a3b8)]/80 group-hover:text-[var(--rtw-text-subtle,#64748b)]"}`,
2359
+ children: node.index + 1
2360
+ })
2361
+ })]
2362
+ }, key);
2363
+ return /* @__PURE__ */ jsx("div", {
2364
+ className: `flex min-h-0 min-w-0 flex-1 gap-2 ${node.direction === "horizontal" ? "flex-row" : "flex-col"}`,
2365
+ children: node.children.map((child, index) => renderPreview(child, current, `${key}-${index}`))
2366
+ }, key);
2367
+ };
2368
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [trigger === void 0 ? /* @__PURE__ */ jsx(TooltipSlot, {
2369
+ renderTooltip,
2370
+ label: "Choose workspace layout",
2371
+ side: "bottom",
2372
+ children: /* @__PURE__ */ jsxs("button", {
2373
+ type: "button",
2374
+ onClick: () => setOpen(true),
2375
+ "aria-label": "Choose workspace layout",
2376
+ title: renderTooltip ? void 0 : "Choose workspace layout",
2377
+ className: iconOnly ? "inline-flex size-8 cursor-pointer items-center justify-center rounded-lg text-[var(--rtw-text-muted,#475569)] transition-colors hover:bg-[var(--rtw-surface-subtle,#edf1f7)] hover:text-[var(--rtw-text-strong,#0f172a)]" : "inline-flex h-8 cursor-pointer items-center gap-1.5 whitespace-nowrap rounded-lg border border-[var(--rtw-border,#dfe5ef)] bg-[var(--rtw-surface-header,#f8fafc)] px-2.5 text-xs font-medium text-[var(--rtw-text,#1e293b)] transition-colors hover:border-[var(--rtw-border-strong,#c9d3e2)] hover:bg-[var(--rtw-surface-subtle,#edf1f7)]",
2378
+ children: [/* @__PURE__ */ jsx(LayoutIcon, { className: "size-3.5 text-[var(--rtw-accent,#6366f1)]" }), !iconOnly && /* @__PURE__ */ jsx("span", { children: "Layouts" })]
2379
+ })
2380
+ }) : trigger, open && /* @__PURE__ */ jsx("div", {
2381
+ role: "dialog",
2382
+ "aria-modal": "true",
2383
+ "aria-labelledby": "rtw-layout-picker-title",
2384
+ className: "rtw-animate-backdrop fixed inset-0 z-50 flex items-center justify-center bg-black/45 p-4 backdrop-blur-sm",
2385
+ onClick: () => setOpen(false),
2386
+ children: /* @__PURE__ */ jsxs("div", {
2387
+ className: "rtw-animate-modal flex max-h-[calc(100dvh-2rem)] w-full max-w-6xl flex-col overflow-hidden rounded-[var(--rtw-radius-dialog,1rem)] border border-[var(--rtw-border,#dfe5ef)] bg-[var(--rtw-surface,#ffffff)] shadow-[var(--rtw-shadow-dialog)]",
2388
+ onClick: (e) => e.stopPropagation(),
2389
+ children: [
2390
+ /* @__PURE__ */ jsxs("div", {
2391
+ className: "flex shrink-0 items-center justify-between border-b border-[var(--rtw-border-muted,#eaedf4)] bg-[var(--rtw-surface-header,#f8fafc)] px-6 py-4",
2392
+ children: [/* @__PURE__ */ jsxs("div", {
2393
+ className: "flex items-center gap-3",
2394
+ children: [/* @__PURE__ */ jsx("span", {
2395
+ className: "grid size-9 place-items-center rounded-xl bg-[var(--rtw-accent-tint,rgba(99,102,241,0.12))] text-[var(--rtw-accent,#6366f1)]",
2396
+ children: /* @__PURE__ */ jsx(LayoutIcon, { className: "size-4.5" })
2397
+ }), /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("h2", {
2398
+ id: "rtw-layout-picker-title",
2399
+ className: "text-sm font-semibold tracking-[-0.01em] text-[var(--rtw-text-strong,#0f172a)]",
2400
+ children: "Workspace Layouts"
2401
+ }), /* @__PURE__ */ jsx("p", {
2402
+ className: "text-xs text-[var(--rtw-text-subtle,#64748b)]",
2403
+ children: "Choose a panel count and click any layout to arrange your workspace."
2404
+ })] })]
2405
+ }), /* @__PURE__ */ jsx("button", {
2406
+ type: "button",
2407
+ onClick: () => setOpen(false),
2408
+ "aria-label": "Close layout dialog",
2409
+ className: "flex size-8 cursor-pointer items-center justify-center rounded-lg text-[var(--rtw-text-subtle,#64748b)] transition-colors hover:bg-[var(--rtw-surface-hover,#e5ebf3)] hover:text-[var(--rtw-text-strong,#0f172a)]",
2410
+ children: /* @__PURE__ */ jsx(CloseIcon, { className: "size-4" })
2411
+ })]
2412
+ }),
2413
+ /* @__PURE__ */ jsxs("div", {
2414
+ className: "space-y-5 overflow-y-auto p-6",
2415
+ children: [/* @__PURE__ */ jsxs("div", {
2416
+ className: "flex flex-wrap items-center justify-between gap-3",
2417
+ children: [/* @__PURE__ */ jsxs("div", {
2418
+ className: "flex items-center gap-2",
2419
+ children: [/* @__PURE__ */ jsx("span", {
2420
+ className: "text-xs font-medium text-[var(--rtw-text-muted,#475569)]",
2421
+ children: "Visible panels"
2422
+ }), /* @__PURE__ */ jsxs("span", {
2423
+ className: "rounded-md bg-[var(--rtw-surface-subtle,#edf1f7)] px-1.5 py-0.5 text-[11px] font-medium tabular-nums text-[var(--rtw-text-subtle,#64748b)]",
2424
+ children: [
2425
+ presets.length,
2426
+ " ",
2427
+ presets.length === 1 ? "layout" : "layouts"
2428
+ ]
2429
+ })]
2430
+ }), /* @__PURE__ */ jsx("div", {
2431
+ role: "group",
2432
+ "aria-label": "Number of panels",
2433
+ className: "inline-flex items-center gap-0.5 rounded-xl border border-[var(--rtw-border,#dfe5ef)] bg-[var(--rtw-surface-subtle,#edf1f7)] p-1",
2434
+ children: sectionCounts.map((count) => {
2435
+ const isSelected = selectedCount === count;
2436
+ return /* @__PURE__ */ jsx("button", {
2437
+ type: "button",
2438
+ onClick: () => setSelectedCount(count),
2439
+ "aria-pressed": isSelected,
2440
+ className: `flex h-7 min-w-9 cursor-pointer items-center justify-center rounded-lg px-2.5 text-xs font-semibold tabular-nums transition-all duration-150 ${isSelected ? "bg-[var(--rtw-accent,#6366f1)] text-[var(--rtw-accent-foreground,#ffffff)] shadow-sm" : "text-[var(--rtw-text-muted,#475569)] hover:bg-[var(--rtw-surface-hover,#e5ebf3)]/60 hover:text-[var(--rtw-text-strong,#0f172a)]"}`,
2441
+ children: count
2442
+ }, count);
2443
+ })
2444
+ })]
2445
+ }), /* @__PURE__ */ jsx("div", {
2446
+ className: "grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3",
2447
+ children: presets.map((preset) => {
2448
+ const isCurrent = layoutTemplateSignature(preset.layout) === currentSignature;
2449
+ return /* @__PURE__ */ jsxs("button", {
2450
+ type: "button",
2451
+ "aria-label": `Apply ${preset.label}`,
2452
+ "aria-pressed": isCurrent,
2453
+ title: preset.label,
2454
+ onClick: () => {
2455
+ onApplyLayout(preset.layout);
2456
+ setOpen(false);
2457
+ },
2458
+ className: `group relative flex aspect-[16/10] w-full cursor-pointer overflow-hidden rounded-xl border p-3 text-left transition-all duration-150 ${isCurrent ? "border-[var(--rtw-accent,#6366f1)] bg-[var(--rtw-accent-tint,rgba(99,102,241,0.08))] ring-2 ring-[var(--rtw-accent-ring,rgba(99,102,241,0.48))] shadow-sm" : "border-[var(--rtw-border,#dfe5ef)] bg-[var(--rtw-bg,#f1f4f9)] hover:-translate-y-0.5 hover:border-[var(--rtw-accent,#6366f1)]/60 hover:bg-[var(--rtw-surface-subtle,#edf1f7)] hover:shadow-md"}`,
2459
+ children: [renderPreview(preset.layout, isCurrent), isCurrent && /* @__PURE__ */ jsx("span", {
2460
+ "aria-hidden": "true",
2461
+ className: "absolute right-2 top-2 z-10 grid size-5 place-items-center rounded-full bg-[var(--rtw-accent,#6366f1)] text-[var(--rtw-accent-foreground,#ffffff)] shadow-sm ring-2 ring-[var(--rtw-surface,#ffffff)]",
2462
+ children: /* @__PURE__ */ jsx(CheckIcon, { className: "size-3" })
2463
+ })]
2464
+ }, preset.id);
2465
+ })
2466
+ })]
2467
+ }),
2468
+ (onSaveAsDefault || renderFooterExtra) && /* @__PURE__ */ jsxs("div", {
2469
+ className: "flex shrink-0 flex-wrap items-center justify-between gap-2 border-t border-[var(--rtw-border-muted,#eaedf4)] bg-[var(--rtw-surface-header,#f8fafc)] px-6 py-3.5",
2470
+ children: [onSaveAsDefault ? /* @__PURE__ */ jsxs("button", {
2471
+ type: "button",
2472
+ disabled: savingDefault,
2473
+ onClick: async () => {
2474
+ setSavingDefault(true);
2475
+ try {
2476
+ await onSaveAsDefault();
2477
+ } finally {
2478
+ setSavingDefault(false);
2479
+ }
2480
+ },
2481
+ className: "inline-flex h-8 cursor-pointer items-center gap-1.5 whitespace-nowrap rounded-lg border border-[var(--rtw-border-strong,#c9d3e2)] bg-[var(--rtw-surface,#ffffff)] px-3 text-xs font-medium text-[var(--rtw-text,#1e293b)] transition-colors hover:border-[var(--rtw-accent,#6366f1)]/60 hover:text-[var(--rtw-accent,#6366f1)] disabled:opacity-50",
2482
+ children: [/* @__PURE__ */ jsx(BookmarkIcon, { className: "size-3.5 text-[var(--rtw-accent,#6366f1)]" }), /* @__PURE__ */ jsx("span", { children: savingDefault ? "Saving…" : "Save current as default" })]
2483
+ }) : /* @__PURE__ */ jsx("span", {}), renderFooterExtra?.({ close: () => setOpen(false) })]
2484
+ })
2485
+ ]
2486
+ })
2487
+ })] });
2488
+ }
2489
+ // src/components/WorkspaceTopBar.tsx
2490
+ function WorkspaceTopBar({ isDesktop, allPanels, activePanels, minimizedPanels, layoutSignature, isDropActive, isDraggingPanel = false, presets, renderTooltip, renderTopBarActions, renderLayoutFooterExtra, onDragOver, onDragLeave, onDrop, onPanelDragStart, onPanelDragEnd, onRestore, onApplyLayout, onSaveAsDefault, onResetLayout }) {
2491
+ if (isDesktop) return /* @__PURE__ */ jsxs("header", {
2492
+ onDragOver,
2493
+ onDragLeave,
2494
+ onDrop,
2495
+ className: `flex min-h-13 shrink-0 flex-wrap items-center justify-between gap-3 border-b px-3.5 py-2 transition-all duration-150 sm:px-4 ${isDropActive ? "border-[var(--rtw-accent,#6366f1)] bg-[var(--rtw-surface-drop,rgba(99,102,241,0.08))] ring-1 ring-inset ring-[var(--rtw-accent,#6366f1)]/40" : "border-[var(--rtw-border,#dfe5ef)] bg-[var(--rtw-surface,#ffffff)]"}`,
2496
+ children: [/* @__PURE__ */ jsxs("div", {
2497
+ className: "flex min-h-8 min-w-0 flex-1 flex-wrap items-center gap-2",
2498
+ children: [isDraggingPanel && /* @__PURE__ */ jsx("div", {
2499
+ className: `inline-flex h-8 items-center gap-1.5 rounded-lg border border-dashed px-3 text-xs font-medium transition-colors ${isDropActive ? "border-[var(--rtw-accent,#6366f1)] bg-[var(--rtw-accent-tint)] text-[var(--rtw-accent,#6366f1)]" : "border-[var(--rtw-border-dashed,#b9c5d6)] text-[var(--rtw-text-muted,#475569)]"}`,
2500
+ children: /* @__PURE__ */ jsx("span", { children: isDropActive ? "Release to dock panel" : "Drop here to dock panel" })
2501
+ }), !isDraggingPanel && minimizedPanels.length === 0 ? /* @__PURE__ */ jsx("span", {
2502
+ className: "text-xs font-medium text-[var(--rtw-text-faint,#94a3b8)]",
2503
+ children: "Drag any panel header here to dock · Double-click dividers to equalize"
2504
+ }) : minimizedPanels.map((panel) => {
2505
+ const panelNumber = allPanels.findIndex((p) => p.id === panel.id) + 1;
2506
+ return /* @__PURE__ */ jsx(TooltipSlot, {
2507
+ renderTooltip,
2508
+ label: `Restore ${panel.title}`,
2509
+ shortcut: panelNumber > 0 ? [String(panelNumber)] : void 0,
2510
+ side: "bottom",
2511
+ children: /* @__PURE__ */ jsxs("button", {
2512
+ type: "button",
2513
+ draggable: true,
2514
+ onDragStart: (event) => {
2515
+ event.dataTransfer.effectAllowed = "move";
2516
+ try {
2517
+ event.dataTransfer.setData("text/plain", panel.id);
2518
+ } catch {}
2519
+ onPanelDragStart?.(panel.id);
2520
+ },
2521
+ onDragEnd: onPanelDragEnd,
2522
+ onClick: () => onRestore(panel.id),
2523
+ title: renderTooltip ? void 0 : `Restore ${panel.title}`,
2524
+ className: "group/dock inline-flex h-8 cursor-grab items-center gap-1.5 whitespace-nowrap rounded-lg border border-[var(--rtw-border,#dfe5ef)] bg-[var(--rtw-surface-header,#f8fafc)] px-2.5 text-xs font-medium text-[var(--rtw-text,#1e293b)] transition-all duration-150 hover:border-[var(--rtw-accent,#6366f1)]/55 hover:bg-[var(--rtw-accent-tint)] hover:text-[var(--rtw-accent,#6366f1)] active:cursor-grabbing",
2525
+ children: [
2526
+ /* @__PURE__ */ jsx("span", {
2527
+ "aria-hidden": "true",
2528
+ className: "flex size-3.5 items-center justify-center text-[var(--rtw-text-subtle,#64748b)] transition-colors group-hover/dock:text-[var(--rtw-accent,#6366f1)]",
2529
+ children: panel.icon
2530
+ }),
2531
+ /* @__PURE__ */ jsx("span", { children: panel.title }),
2532
+ /* @__PURE__ */ jsx(PlusIcon, { className: "size-3 opacity-60 transition-transform duration-150 group-hover/dock:rotate-90 group-hover/dock:opacity-100" })
2533
+ ]
2534
+ })
2535
+ }, panel.id);
2536
+ })]
2537
+ }), /* @__PURE__ */ jsxs("div", {
2538
+ className: "flex shrink-0 items-center gap-2",
2539
+ children: [/* @__PURE__ */ jsxs("div", {
2540
+ className: "flex items-center gap-1",
2541
+ children: [/* @__PURE__ */ jsx(LayoutPickerDialog, {
2542
+ maxPanels: allPanels.length,
2543
+ presets,
2544
+ currentOpenCount: activePanels.length,
2545
+ currentSignature: layoutSignature,
2546
+ onApplyLayout,
2547
+ onSaveAsDefault,
2548
+ renderFooterExtra: renderLayoutFooterExtra,
2549
+ renderTooltip
2550
+ }), /* @__PURE__ */ jsx(TooltipSlot, {
2551
+ renderTooltip,
2552
+ label: "Reset layout",
2553
+ shortcut: ["R"],
2554
+ side: "bottom",
2555
+ children: /* @__PURE__ */ jsx("button", {
2556
+ type: "button",
2557
+ onClick: onResetLayout,
2558
+ "aria-label": "Reset layout",
2559
+ title: renderTooltip ? void 0 : "Reset layout (R)",
2560
+ className: "inline-flex size-8 cursor-pointer items-center justify-center rounded-lg border border-transparent text-[var(--rtw-text-muted,#475569)] transition-colors hover:border-[var(--rtw-border,#dfe5ef)] hover:bg-[var(--rtw-surface-subtle,#edf1f7)] hover:text-[var(--rtw-text-strong,#0f172a)]",
2561
+ children: /* @__PURE__ */ jsx(RotateCcwIcon, { className: "size-3.5" })
2562
+ })
2563
+ })]
2564
+ }), renderTopBarActions && /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("span", {
2565
+ "aria-hidden": "true",
2566
+ className: "h-4 w-px bg-[var(--rtw-border,#dfe5ef)]"
2567
+ }), renderTopBarActions({
2568
+ openCount: activePanels.length,
2569
+ layoutSignature
2570
+ })] })]
2571
+ })]
2572
+ });
2573
+ return null;
2574
+ }
2575
+ // src/components/TilingWorkspace.tsx
2576
+ const DEFAULT_STORAGE_KEY = "react-tiling-workspace.layout.v2";
2577
+ function getDefaultState(panelList, panelMap, defaultLayout) {
2578
+ const knownIds = new Set(panelMap.keys());
2579
+ if (defaultLayout && !validateLayoutTree(defaultLayout, knownIds)) throw new Error(`Invalid defaultLayout: expected a valid split tree with unique declared panel IDs and no more than 4 split levels.`);
2580
+ const defaultIds = panelList.filter((panel) => panel.defaultOpen !== false).map((panel) => panel.id);
2581
+ return {
2582
+ tree: defaultLayout ?? createHorizontalTree(defaultIds.length > 0 ? defaultIds : panelList.slice(0, 1).map((p) => p.id)),
2583
+ folds: {},
2584
+ maximizedId: null
2585
+ };
2586
+ }
2587
+ function getDropPosition(event) {
2588
+ const rect = event.currentTarget.getBoundingClientRect();
2589
+ const relativeX = (event.clientX - rect.left) / Math.max(1, rect.width);
2590
+ if (relativeX < .28) return "left";
2591
+ if (relativeX > .72) return "right";
2592
+ return (event.clientY - rect.top) / Math.max(1, rect.height) < .5 ? "top" : "bottom";
2593
+ }
2594
+ function WorkspaceBodySkeleton() {
2595
+ return /* @__PURE__ */ jsxs("div", {
2596
+ className: "flex min-h-0 flex-1 gap-2.5 bg-[var(--rtw-bg,#f1f4f9)] p-2.5",
2597
+ "aria-busy": "true",
2598
+ children: [/* @__PURE__ */ jsx("div", { className: "flex-1 animate-pulse rounded-[var(--rtw-radius-panel,0.875rem)] border border-[var(--rtw-border,#dfe5ef)] bg-[var(--rtw-surface,#ffffff)]" }), /* @__PURE__ */ jsx("div", { className: "hidden flex-1 animate-pulse rounded-[var(--rtw-radius-panel,0.875rem)] border border-[var(--rtw-border,#dfe5ef)] bg-[var(--rtw-surface,#ffffff)] lg:block" })]
2599
+ });
2600
+ }
2601
+ function TilingWorkspace({ panels, defaultLayout, storageKey = DEFAULT_STORAGE_KEY, layout: controlledLayout, onLayoutChange, commandsRef, keyboardShortcuts = true, embedded = false, breakpointPx = 1024, presets, onSaveAsDefault, renderTooltip, renderTopBarActions, renderLayoutFooterExtra, mobileQuickActions, mobileQuickActionLabel = "Actions", mobileQuickActionIcon = /* @__PURE__ */ jsx(PlusIcon, {}), renderMobileBottomBar, className }) {
2602
+ const panelMap = useMemo(() => new Map(panels.map((panel) => [panel.id, panel])), [panels]);
2603
+ const knownIdsKey = panels.map((panel) => panel.id).join("\0");
2604
+ const knownIds = useMemo(() => new Set(knownIdsKey ? knownIdsKey.split("\0") : []), [knownIdsKey]);
2605
+ const knownIdsRef = useRef(knownIds);
2606
+ knownIdsRef.current = knownIds;
2607
+ const defaultState = useMemo(() => getDefaultState(panels, panelMap, defaultLayout), [
2608
+ panels,
2609
+ panelMap,
2610
+ defaultLayout
2611
+ ]);
2612
+ const [uncontrolledLayout, setUncontrolledLayout] = useState(defaultState);
2613
+ const rawLayout = controlledLayout ?? uncontrolledLayout;
2614
+ const isInvalidTree = rawLayout.tree !== null && !validateLayoutTree(rawLayout.tree, knownIds);
2615
+ if (controlledLayout && isInvalidTree) throw new Error(`Invalid controlled layout: expected a valid split tree with unique declared panel IDs and no more than 4 split levels.`);
2616
+ const layout = isInvalidTree ? {
2617
+ ...rawLayout,
2618
+ tree: defaultState.tree,
2619
+ folds: {},
2620
+ maximizedId: null
2621
+ } : rawLayout;
2622
+ const openIds = useMemo(() => getPanelIds(layout.tree), [layout.tree]);
2623
+ const [mobileTab, setMobileTab] = useState(openIds[0] ?? panels[0]?.id ?? null);
2624
+ const [focusedPanelId, setFocusedPanelId] = useState(openIds[0] ?? panels[0]?.id ?? null);
2625
+ const [draggedId, setDraggedId] = useState(null);
2626
+ const [dragOverTarget, setDragOverTarget] = useState(null);
2627
+ const [isResizing, setIsResizing] = useState(false);
2628
+ const [activeDividerKey, setActiveDividerKey] = useState(null);
2629
+ const [nearFoldTarget, setNearFoldTarget] = useState(null);
2630
+ const rootRef = useRef(null);
2631
+ const containerRef = useRef(null);
2632
+ const resizeRef = useRef(null);
2633
+ const hydratedStorageKeyRef = useRef(null);
2634
+ const latestLayoutRef = useRef(layout);
2635
+ latestLayoutRef.current = layout;
2636
+ const onLayoutChangeRef = useRef(onLayoutChange);
2637
+ onLayoutChangeRef.current = onLayoutChange;
2638
+ const isControlled = controlledLayout !== void 0;
2639
+ const isDesktop = useIsDesktop(breakpointPx);
2640
+ const persistLayout = useCallback((next) => {
2641
+ if (!storageKey) return;
2642
+ try {
2643
+ window.localStorage.setItem(storageKey, JSON.stringify(next));
2644
+ } catch {}
2645
+ }, [storageKey]);
2646
+ const updateLayout = useCallback((updater, options) => {
2647
+ const previous = latestLayoutRef.current;
2648
+ const next = typeof updater === "function" ? updater(previous) : updater;
2649
+ if (next === previous) return;
2650
+ if (next.tree && !validateLayoutTree(next.tree, knownIdsRef.current)) return;
2651
+ latestLayoutRef.current = next;
2652
+ if (!isControlled) setUncontrolledLayout(next);
2653
+ if (!options?.skipPersist) persistLayout(next);
2654
+ onLayoutChangeRef.current?.(next);
2655
+ }, [isControlled, persistLayout]);
2656
+ useEffect(() => {
2657
+ if (isControlled || !storageKey) return;
2658
+ if (hydratedStorageKeyRef.current === storageKey) return;
2659
+ hydratedStorageKeyRef.current = storageKey;
2660
+ try {
2661
+ const raw = window.localStorage.getItem(storageKey);
2662
+ if (!raw) return;
2663
+ const parsed = JSON.parse(raw);
2664
+ if (parsed.tree === null || validateLayoutTree(parsed.tree, knownIdsRef.current)) {
2665
+ const tree = parsed.tree ?? null;
2666
+ const ids = getPanelIds(tree);
2667
+ const restored = {
2668
+ tree,
2669
+ folds: parsed.folds ?? {},
2670
+ maximizedId: parsed.maximizedId && ids.includes(parsed.maximizedId) ? parsed.maximizedId : null
2671
+ };
2672
+ latestLayoutRef.current = restored;
2673
+ setUncontrolledLayout(restored);
2674
+ setMobileTab(ids[0] ?? null);
2675
+ }
2676
+ } catch {}
2677
+ }, [isControlled, storageKey]);
2678
+ useEffect(() => {
2679
+ function handlePointerMove(event) {
2680
+ const resize = resizeRef.current;
2681
+ if (!resize) return;
2682
+ const deltaPx = resize.direction === "horizontal" ? event.clientX - resize.startX : event.clientY - resize.startY;
2683
+ let nextNearFold = null;
2684
+ updateLayout((previous) => {
2685
+ if (!previous.tree) return previous;
2686
+ const result = computeResizeStep({
2687
+ tree: previous.tree,
2688
+ folds: previous.folds,
2689
+ path: resize.path,
2690
+ index: resize.index,
2691
+ direction: resize.direction,
2692
+ startFirstPx: resize.startFirstPx,
2693
+ startSecondPx: resize.startSecondPx,
2694
+ deltaPx
2695
+ });
2696
+ if (result.nearFoldSide) nextNearFold = {
2697
+ pathKey: resize.pathKey,
2698
+ childIndex: result.nearFoldSide === "first" ? resize.index : resize.index + 1
2699
+ };
2700
+ if (result.tree === previous.tree && result.folds === previous.folds) return previous;
2701
+ return {
2702
+ ...previous,
2703
+ tree: result.tree,
2704
+ folds: result.folds
2705
+ };
2706
+ }, { skipPersist: true });
2707
+ setNearFoldTarget((prev) => {
2708
+ if (!nextNearFold && !prev) return prev;
2709
+ if (nextNearFold && prev && nextNearFold.pathKey === prev.pathKey && nextNearFold.childIndex === prev.childIndex) return prev;
2710
+ return nextNearFold;
2711
+ });
2712
+ }
2713
+ function handlePointerUp() {
2714
+ if (!resizeRef.current) return;
2715
+ resizeRef.current = null;
2716
+ document.body.style.userSelect = "";
2717
+ document.body.style.cursor = "";
2718
+ setIsResizing(false);
2719
+ setActiveDividerKey(null);
2720
+ setNearFoldTarget(null);
2721
+ persistLayout(latestLayoutRef.current);
2722
+ }
2723
+ window.addEventListener("pointermove", handlePointerMove);
2724
+ window.addEventListener("pointerup", handlePointerUp);
2725
+ window.addEventListener("pointercancel", handlePointerUp);
2726
+ return () => {
2727
+ window.removeEventListener("pointermove", handlePointerMove);
2728
+ window.removeEventListener("pointerup", handlePointerUp);
2729
+ window.removeEventListener("pointercancel", handlePointerUp);
2730
+ };
2731
+ }, [persistLayout, updateLayout]);
2732
+ const findOwnedElement = useCallback((selector) => {
2733
+ const root = rootRef.current;
2734
+ if (!root) return null;
2735
+ return Array.from(root.querySelectorAll(selector)).find((element) => element.closest("[data-rtw-root=\"true\"]") === root) ?? null;
2736
+ }, []);
2737
+ const getSplitChildElements = useCallback((splitPath) => {
2738
+ const splitElement = findOwnedElement(`[data-layout-path="${splitPath.join(".")}"]`);
2739
+ if (!splitElement) return null;
2740
+ return Array.from(splitElement.children).filter((element) => element instanceof HTMLElement && element.hasAttribute("data-layout-child"));
2741
+ }, [findOwnedElement]);
2742
+ const handleResizeStart = useCallback((event, path, index, direction) => {
2743
+ event.preventDefault();
2744
+ const pathKey = path.join(".");
2745
+ const childElements = getSplitChildElements(path) ?? [];
2746
+ const first = childElements[index]?.getBoundingClientRect();
2747
+ const second = childElements[index + 1]?.getBoundingClientRect();
2748
+ if (!first || !second) return;
2749
+ resizeRef.current = {
2750
+ path,
2751
+ pathKey,
2752
+ index,
2753
+ direction,
2754
+ startX: event.clientX,
2755
+ startY: event.clientY,
2756
+ startFirstPx: direction === "horizontal" ? first.width : first.height,
2757
+ startSecondPx: direction === "horizontal" ? second.width : second.height
2758
+ };
2759
+ setIsResizing(true);
2760
+ setActiveDividerKey(`${pathKey}:${index}`);
2761
+ document.body.style.userSelect = "none";
2762
+ document.body.style.cursor = direction === "horizontal" ? "col-resize" : "row-resize";
2763
+ }, [getSplitChildElements]);
2764
+ const handleRestoreCompactPanel = useCallback((id, panelPath, direction) => {
2765
+ const minimumSizePx = direction === "horizontal" ? 120 : 92;
2766
+ const snapFloorPx = (direction === "horizontal" ? 96 : 76) + 4;
2767
+ const axis = direction === "horizontal" ? "width" : "height";
2768
+ const panelElement = findOwnedElement(`[data-layout-path="${panelPath.join(".")}"]`);
2769
+ if (!panelElement || panelElement.dataset.panelId !== id) return;
2770
+ const currentPanelSize = panelElement.getBoundingClientRect()[axis];
2771
+ if (currentPanelSize >= minimumSizePx + 4) return;
2772
+ updateLayout((previous) => {
2773
+ if (!previous.tree) return previous;
2774
+ for (let depth = panelPath.length - 1; depth >= 0; depth -= 1) {
2775
+ const splitPath = panelPath.slice(0, depth);
2776
+ const split = getSplitAtPath(previous.tree, splitPath);
2777
+ if (!split || split.type !== "split" || split.direction !== direction) continue;
2778
+ const targetIndex = panelPath[depth];
2779
+ const childElements = getSplitChildElements(splitPath);
2780
+ if (!childElements || childElements.length !== split.children.length || targetIndex === void 0) continue;
2781
+ const childSizes = childElements.map((element) => element.getBoundingClientRect()[axis]);
2782
+ const foldedChildren = childElements.map((element) => element.dataset.folded === "true");
2783
+ const readingTargetPx = computeReadingTargetPx(direction, childSizes.reduce((sum, size, index) => sum + (foldedChildren[index] ? 0 : size), 0), foldedChildren.filter((isFolded) => !isFolded).length);
2784
+ const weights = split.children.map((_, index) => split.sizes?.[index] ?? 1);
2785
+ const targetChildPx = childSizes[targetIndex] ?? currentPanelSize;
2786
+ const nestedRatio = Math.max(.1, currentPanelSize / Math.max(1, targetChildPx));
2787
+ const nextWeights = growChildWeightsWithFallback(weights, childSizes, foldedChildren, targetIndex, Math.max(readingTargetPx, Math.ceil(readingTargetPx / nestedRatio)), minimumSizePx, snapFloorPx);
2788
+ if (!nextWeights) continue;
2789
+ return {
2790
+ ...previous,
2791
+ tree: setSplitChildWeightsAtPath(previous.tree, splitPath, nextWeights)
2792
+ };
2793
+ }
2794
+ return previous;
2795
+ });
2796
+ }, [
2797
+ findOwnedElement,
2798
+ getSplitChildElements,
2799
+ updateLayout
2800
+ ]);
2801
+ const handleEqualize = useCallback((path, index) => {
2802
+ updateLayout((previous) => {
2803
+ if (!previous.tree) return previous;
2804
+ return {
2805
+ ...previous,
2806
+ tree: equalizeSplitAtPath(previous.tree, path, index)
2807
+ };
2808
+ });
2809
+ }, [updateLayout]);
2810
+ const handleKeyboardResize = useCallback((path, index, _direction, deltaRatio) => {
2811
+ updateLayout((previous) => {
2812
+ if (!previous.tree) return previous;
2813
+ const result = computeKeyboardResizeStep({
2814
+ tree: previous.tree,
2815
+ folds: previous.folds,
2816
+ path,
2817
+ index,
2818
+ deltaRatio
2819
+ });
2820
+ if (result.tree === previous.tree && result.folds === previous.folds) return previous;
2821
+ return {
2822
+ ...previous,
2823
+ tree: result.tree,
2824
+ folds: result.folds
2825
+ };
2826
+ });
2827
+ }, [updateLayout]);
2828
+ const toggleFold = useCallback((id) => {
2829
+ updateLayout((previous) => {
2830
+ if (!previous.tree || previous.tree.type === "panel") return previous;
2831
+ const wasFolded = (previous.folds[id] ?? "open") === "folded";
2832
+ const nextFolds = {
2833
+ ...previous.folds,
2834
+ [id]: wasFolded ? "open" : "folded"
2835
+ };
2836
+ let nextTree = previous.tree;
2837
+ if (wasFolded) {
2838
+ const panelPath = findPanelPath(previous.tree, id);
2839
+ if (panelPath) {
2840
+ const expectedSplitPx = {
2841
+ horizontal: null,
2842
+ vertical: null
2843
+ };
2844
+ for (let depth = 0; depth < panelPath.length; depth += 1) {
2845
+ const splitPath = panelPath.slice(0, depth);
2846
+ const split = getSplitAtPath(nextTree, splitPath);
2847
+ const targetIndex = panelPath[depth];
2848
+ if (!split || split.type !== "split" || targetIndex === void 0) continue;
2849
+ const targetChild = split.children[targetIndex];
2850
+ if (!targetChild) continue;
2851
+ const childUnfoldedNow = isNodeFolded(targetChild, previous.folds) && !isNodeFolded(targetChild, nextFolds);
2852
+ const isLeafSplit = depth === panelPath.length - 1;
2853
+ if (!childUnfoldedNow && !isLeafSplit) continue;
2854
+ const axis = split.direction === "horizontal" ? "width" : "height";
2855
+ const childElements = getSplitChildElements(splitPath);
2856
+ if (!childElements || childElements.length !== split.children.length) continue;
2857
+ const domSizes = childElements.map((element) => element.getBoundingClientRect()[axis]);
2858
+ const domTotal = domSizes.reduce((sum, s) => sum + s, 0);
2859
+ const expectedTotal = expectedSplitPx[split.direction];
2860
+ const scale = expectedTotal && expectedTotal > domTotal && domTotal > 0 ? expectedTotal / domTotal : 1;
2861
+ const childSizes = domSizes.map((s) => s * scale);
2862
+ const stillFolded = split.children.map((child, index) => index !== targetIndex && isNodeFolded(child, nextFolds));
2863
+ const openAndTargetPx = childSizes.reduce((sum, size, index) => sum + (stillFolded[index] ? 0 : size), 0);
2864
+ const weights = split.children.map((_, index) => split.sizes?.[index] ?? 1);
2865
+ const openAndTargetWeight = weights.reduce((sum, weight, index) => sum + (stillFolded[index] ? 0 : weight), 0);
2866
+ if (openAndTargetPx <= 0 || openAndTargetWeight <= 0) continue;
2867
+ const projectedOpenPx = openAndTargetPx * (weights[targetIndex] / openAndTargetWeight);
2868
+ const minOpenPx = split.direction === "horizontal" ? 120 : 92;
2869
+ const snapFloorPx = (split.direction === "horizontal" ? 96 : 76) + 4;
2870
+ if (projectedOpenPx < minOpenPx + 24) {
2871
+ const openCount = stillFolded.filter((isFolded) => !isFolded).length;
2872
+ const nextWeights = growChildWeightsWithFallback(weights, childSizes, stillFolded, targetIndex, computeReadingTargetPx(split.direction, openAndTargetPx, openCount), minOpenPx, snapFloorPx);
2873
+ if (nextWeights) {
2874
+ nextTree = setSplitChildWeightsAtPath(nextTree, splitPath, nextWeights);
2875
+ const nextOpenWeight = nextWeights.reduce((sum, weight, index) => sum + (stillFolded[index] ? 0 : weight), 0);
2876
+ expectedSplitPx[split.direction] = openAndTargetPx * (nextWeights[targetIndex] / Math.max(1e-4, nextOpenWeight));
2877
+ continue;
2878
+ }
2879
+ }
2880
+ expectedSplitPx[split.direction] = projectedOpenPx;
2881
+ }
2882
+ }
2883
+ }
2884
+ return {
2885
+ ...previous,
2886
+ tree: nextTree,
2887
+ maximizedId: previous.maximizedId === id ? null : previous.maximizedId,
2888
+ folds: nextFolds
2889
+ };
2890
+ });
2891
+ }, [getSplitChildElements, updateLayout]);
2892
+ const toggleMaximize = useCallback((id) => {
2893
+ updateLayout((previous) => ({
2894
+ ...previous,
2895
+ maximizedId: previous.maximizedId === id ? null : id,
2896
+ folds: {
2897
+ ...previous.folds,
2898
+ [id]: "open"
2899
+ }
2900
+ }));
2901
+ }, [updateLayout]);
2902
+ const minimizePanel = useCallback((id, clearMobileTab = false) => {
2903
+ updateLayout((previous) => ({
2904
+ ...previous,
2905
+ tree: previous.tree ? removePanel(previous.tree, id) : null,
2906
+ maximizedId: previous.maximizedId === id ? null : previous.maximizedId
2907
+ }));
2908
+ if (clearMobileTab || mobileTab === id) {
2909
+ const remaining = openIds.filter((panelId) => panelId !== id);
2910
+ setMobileTab(remaining[0] ?? null);
2911
+ }
2912
+ }, [
2913
+ mobileTab,
2914
+ openIds,
2915
+ updateLayout
2916
+ ]);
2917
+ const restorePanel = useCallback((id) => {
2918
+ updateLayout((previous) => {
2919
+ if (getPanelIds(previous.tree).includes(id)) return previous;
2920
+ let tree = previous.tree;
2921
+ const leaf = {
2922
+ type: "panel",
2923
+ id
2924
+ };
2925
+ if (!tree) tree = leaf;
2926
+ else if (tree.type === "split" && tree.direction === "horizontal") tree = normalizeLayoutTree({
2927
+ ...tree,
2928
+ children: [...tree.children, leaf],
2929
+ sizes: void 0
2930
+ });
2931
+ else tree = normalizeLayoutTree({
2932
+ type: "split",
2933
+ direction: "horizontal",
2934
+ children: [tree, leaf]
2935
+ });
2936
+ return {
2937
+ ...previous,
2938
+ tree,
2939
+ folds: {
2940
+ ...previous.folds,
2941
+ [id]: "open"
2942
+ }
2943
+ };
2944
+ });
2945
+ setMobileTab(id);
2946
+ }, [updateLayout]);
2947
+ const handleSelectMobileTab = useCallback((id) => {
2948
+ if (!openIds.includes(id)) restorePanel(id);
2949
+ setMobileTab(id);
2950
+ }, [openIds, restorePanel]);
2951
+ const focusPanel = useCallback((id) => {
2952
+ if (!panelMap.has(id)) return;
2953
+ if (!openIds.includes(id)) restorePanel(id);
2954
+ setMobileTab(id);
2955
+ setFocusedPanelId(id);
2956
+ window.requestAnimationFrame(() => {
2957
+ findOwnedElement(`[data-panel-id="${id}"]`)?.focus({ preventScroll: true });
2958
+ });
2959
+ }, [
2960
+ findOwnedElement,
2961
+ openIds,
2962
+ panelMap,
2963
+ restorePanel
2964
+ ]);
2965
+ const applyLayoutPreset = useCallback((template) => {
2966
+ let nextFirstId = null;
2967
+ updateLayout((previous) => {
2968
+ const currentOpenIds = getPanelIds(previous.tree);
2969
+ const tree = instantiateLayoutTemplate(template, [...currentOpenIds, ...panels.map((panel) => panel.id).filter((id) => !currentOpenIds.includes(id))]);
2970
+ if (tree && !validateLayoutTree(tree, knownIds)) return previous;
2971
+ nextFirstId = getPanelIds(tree)[0] ?? null;
2972
+ return {
2973
+ tree,
2974
+ folds: {},
2975
+ maximizedId: null
2976
+ };
2977
+ });
2978
+ setMobileTab(nextFirstId);
2979
+ }, [
2980
+ knownIds,
2981
+ panels,
2982
+ updateLayout
2983
+ ]);
2984
+ const movePanel = useCallback((sourceId, targetId, position) => {
2985
+ if (sourceId === targetId) return;
2986
+ updateLayout((previous) => {
2987
+ const candidate = movePanelInTree(previous.tree, sourceId, targetId, position, knownIds);
2988
+ if (!candidate) return previous;
2989
+ return {
2990
+ ...previous,
2991
+ tree: candidate,
2992
+ maximizedId: null,
2993
+ folds: {
2994
+ ...previous.folds,
2995
+ [sourceId]: "open"
2996
+ }
2997
+ };
2998
+ });
2999
+ }, [knownIds, updateLayout]);
3000
+ const handleResetLayout = useCallback(() => {
3001
+ updateLayout(defaultState);
3002
+ setMobileTab(getPanelIds(defaultState.tree)[0] ?? null);
3003
+ }, [defaultState, updateLayout]);
3004
+ const getFocusedPanelId = useCallback(() => layout.maximizedId ?? (focusedPanelId && openIds.includes(focusedPanelId) ? focusedPanelId : openIds[0] ?? null), [
3005
+ focusedPanelId,
3006
+ layout.maximizedId,
3007
+ openIds
3008
+ ]);
3009
+ const commands = useMemo(() => ({
3010
+ focusPanel,
3011
+ getFocusedPanelId,
3012
+ toggleFold: (id) => {
3013
+ const targetId = id ?? getFocusedPanelId();
3014
+ if (targetId) toggleFold(targetId);
3015
+ },
3016
+ toggleMaximize: (id) => {
3017
+ const targetId = id ?? getFocusedPanelId();
3018
+ if (targetId) toggleMaximize(targetId);
3019
+ },
3020
+ minimizePanel: (id) => {
3021
+ const targetId = id ?? getFocusedPanelId();
3022
+ if (targetId) minimizePanel(targetId);
3023
+ },
3024
+ restorePanel,
3025
+ resetLayout: handleResetLayout
3026
+ }), [
3027
+ focusPanel,
3028
+ getFocusedPanelId,
3029
+ handleResetLayout,
3030
+ minimizePanel,
3031
+ restorePanel,
3032
+ toggleFold,
3033
+ toggleMaximize
3034
+ ]);
3035
+ useImperativeHandle(commandsRef, () => commands, [commands]);
3036
+ useEffect(() => {
3037
+ if (!keyboardShortcuts) return;
3038
+ function handleWorkspaceKeyDown(event) {
3039
+ if (event.metaKey || event.ctrlKey || event.altKey) return;
3040
+ if (isEditableTarget(event.target) || hasOpenModal()) return;
3041
+ const key = event.key.toLowerCase();
3042
+ if (key >= "1" && key <= String(Math.min(9, panels.length))) {
3043
+ const target = panels[Number(key) - 1];
3044
+ if (!target) return;
3045
+ event.preventDefault();
3046
+ focusPanel(target.id);
3047
+ return;
3048
+ }
3049
+ if (key === "r") {
3050
+ event.preventDefault();
3051
+ handleResetLayout();
3052
+ return;
3053
+ }
3054
+ const activeId = layout.maximizedId ?? (focusedPanelId && openIds.includes(focusedPanelId) ? focusedPanelId : openIds[0]);
3055
+ if (!activeId) return;
3056
+ if (key === "f") {
3057
+ event.preventDefault();
3058
+ toggleFold(activeId);
3059
+ } else if (key === "m") {
3060
+ event.preventDefault();
3061
+ toggleMaximize(activeId);
3062
+ } else if (key === "x") {
3063
+ event.preventDefault();
3064
+ minimizePanel(activeId);
3065
+ }
3066
+ }
3067
+ window.addEventListener("keydown", handleWorkspaceKeyDown);
3068
+ return () => window.removeEventListener("keydown", handleWorkspaceKeyDown);
3069
+ }, [
3070
+ focusedPanelId,
3071
+ handleResetLayout,
3072
+ layout.maximizedId,
3073
+ minimizePanel,
3074
+ openIds,
3075
+ panels,
3076
+ keyboardShortcuts,
3077
+ focusPanel,
3078
+ restorePanel,
3079
+ toggleFold,
3080
+ toggleMaximize
3081
+ ]);
3082
+ const activePanels = openIds.map((id) => panelMap.get(id)).filter((panel) => Boolean(panel));
3083
+ const minimizedPanels = panels.filter((panel) => !openIds.includes(panel.id));
3084
+ const mobileOrderedPanels = [...activePanels, ...minimizedPanels];
3085
+ const currentMobilePanel = mobileTab && openIds.includes(mobileTab) ? panelMap.get(mobileTab) ?? null : null;
3086
+ const layoutSignature = layout.tree ? layoutTreeSignature(layout.tree) : "";
3087
+ const hasQuickActions = Boolean(mobileQuickActions && mobileQuickActions.length > 0);
3088
+ const topPanels = hasQuickActions ? mobileOrderedPanels.slice(0, 3) : mobileOrderedPanels.slice(0, 4);
3089
+ const morePanels = hasQuickActions ? mobileOrderedPanels.slice(3) : mobileOrderedPanels.slice(4);
3090
+ const toMobileTab = (panel) => ({
3091
+ id: panel.id,
3092
+ label: panel.shortTitle ?? panel.title,
3093
+ icon: panel.icon,
3094
+ variant: "tab",
3095
+ onClick: () => handleSelectMobileTab(panel.id)
3096
+ });
3097
+ const mobileNavItems = [
3098
+ ...topPanels[0] ? [toMobileTab(topPanels[0])] : [],
3099
+ ...topPanels[1] ? [toMobileTab(topPanels[1])] : [],
3100
+ ...hasQuickActions ? [{
3101
+ id: "__quick_action__",
3102
+ label: mobileQuickActionLabel,
3103
+ icon: mobileQuickActionIcon,
3104
+ variant: "accent",
3105
+ subItems: mobileQuickActions
3106
+ }] : [],
3107
+ ...topPanels[2] ? [toMobileTab(topPanels[2])] : [],
3108
+ ...!hasQuickActions && topPanels[3] ? [toMobileTab(topPanels[3])] : [],
3109
+ ...morePanels.length > 0 ? [{
3110
+ id: "__more__",
3111
+ label: "More",
3112
+ icon: /* @__PURE__ */ jsx(MenuIcon, {}),
3113
+ variant: "submenu",
3114
+ active: Boolean(currentMobilePanel && morePanels.some((panel) => panel.id === currentMobilePanel.id)),
3115
+ subItems: morePanels.map((panel) => ({
3116
+ id: panel.id,
3117
+ label: panel.shortTitle ?? panel.title,
3118
+ icon: panel.icon,
3119
+ active: currentMobilePanel?.id === panel.id,
3120
+ onSelect: () => handleSelectMobileTab(panel.id)
3121
+ }))
3122
+ }] : []
3123
+ ];
3124
+ const rootClassName = className ? `flex flex-col overflow-hidden bg-[var(--rtw-bg,#f1f4f9)] ${className}` : embedded ? "flex h-[480px] flex-col overflow-hidden rounded-2xl border border-[var(--rtw-border,#dfe5ef)] bg-[var(--rtw-bg,#f1f4f9)] lg:h-auto lg:min-h-[420px] lg:flex-1" : "flex h-dvh flex-col overflow-hidden bg-[var(--rtw-bg,#f1f4f9)]";
3125
+ return /* @__PURE__ */ jsxs("div", {
3126
+ ref: rootRef,
3127
+ "data-rtw-root": "true",
3128
+ "data-rtw-resizing": isResizing ? "true" : void 0,
3129
+ className: rootClassName,
3130
+ children: [isDesktop !== null && /* @__PURE__ */ jsx(WorkspaceTopBar, {
3131
+ isDesktop,
3132
+ allPanels: panels,
3133
+ activePanels,
3134
+ minimizedPanels,
3135
+ mobileActivePanel: currentMobilePanel,
3136
+ layoutSignature,
3137
+ isDropActive: dragOverTarget === "topbar",
3138
+ isDraggingPanel: Boolean(draggedId && openIds.includes(draggedId)),
3139
+ presets,
3140
+ renderTooltip,
3141
+ renderTopBarActions,
3142
+ renderLayoutFooterExtra,
3143
+ onPanelDragStart: setDraggedId,
3144
+ onPanelDragEnd: () => {
3145
+ setDraggedId(null);
3146
+ setDragOverTarget(null);
3147
+ },
3148
+ onDragOver: (event) => {
3149
+ if (!draggedId || !openIds.includes(draggedId)) return;
3150
+ event.preventDefault();
3151
+ setDragOverTarget("topbar");
3152
+ },
3153
+ onDragLeave: (event) => {
3154
+ if (event.currentTarget.contains(event.relatedTarget)) return;
3155
+ if (dragOverTarget === "topbar") setDragOverTarget(null);
3156
+ },
3157
+ onDrop: (event) => {
3158
+ event.preventDefault();
3159
+ if (draggedId && openIds.includes(draggedId)) minimizePanel(draggedId);
3160
+ setDraggedId(null);
3161
+ setDragOverTarget(null);
3162
+ },
3163
+ onRestore: restorePanel,
3164
+ onCloseMobilePanel: (id) => minimizePanel(id, true),
3165
+ onApplyLayout: applyLayoutPreset,
3166
+ onSaveAsDefault: onSaveAsDefault ? () => onSaveAsDefault(layout.tree) : void 0,
3167
+ onResetLayout: handleResetLayout
3168
+ }), isDesktop === null ? /* @__PURE__ */ jsx(WorkspaceBodySkeleton, {}) : isDesktop ? activePanels.length === 0 ? /* @__PURE__ */ jsxs("div", {
3169
+ onDragOver: (event) => {
3170
+ if (!draggedId || openIds.includes(draggedId)) return;
3171
+ event.preventDefault();
3172
+ if (dragOverTarget !== "empty") setDragOverTarget("empty");
3173
+ },
3174
+ onDragLeave: (event) => {
3175
+ if (event.currentTarget.contains(event.relatedTarget)) return;
3176
+ if (dragOverTarget === "empty") setDragOverTarget(null);
3177
+ },
3178
+ onDrop: (event) => {
3179
+ event.preventDefault();
3180
+ if (draggedId && !openIds.includes(draggedId)) restorePanel(draggedId);
3181
+ setDraggedId(null);
3182
+ setDragOverTarget(null);
3183
+ },
3184
+ className: `m-4 flex min-h-0 flex-1 flex-col items-center justify-center gap-3 rounded-[var(--rtw-radius-panel,0.875rem)] border border-dashed p-8 text-center transition-colors ${dragOverTarget === "empty" ? "border-[var(--rtw-accent,#6366f1)] bg-[var(--rtw-surface-drop,rgba(99,102,241,0.08))]" : "border-[var(--rtw-border-dashed,#b9c5d6)] bg-[var(--rtw-surface,#ffffff)]"}`,
3185
+ children: [/* @__PURE__ */ jsx("p", {
3186
+ className: "text-sm font-medium text-[var(--rtw-text-muted,#475569)]",
3187
+ children: dragOverTarget === "empty" ? "Drop here to open panel" : "All panels are docked in the top bar"
3188
+ }), /* @__PURE__ */ jsx("button", {
3189
+ type: "button",
3190
+ onClick: handleResetLayout,
3191
+ className: "inline-flex h-9 cursor-pointer items-center gap-2 rounded-lg bg-[var(--rtw-accent,#6366f1)] px-4 text-xs font-semibold text-[var(--rtw-accent-foreground,#ffffff)] transition-opacity hover:opacity-90",
3192
+ children: "Restore default layout"
3193
+ })]
3194
+ }) : /* @__PURE__ */ jsx("div", {
3195
+ ref: containerRef,
3196
+ className: "flex min-h-0 flex-1 overflow-hidden bg-[var(--rtw-bg,#f1f4f9)] p-2.5",
3197
+ children: layout.tree && /* @__PURE__ */ jsx(WorkspaceLayoutNodeView, {
3198
+ node: layout.tree,
3199
+ path: [],
3200
+ parentDirection: null,
3201
+ panels: panelMap,
3202
+ folds: layout.folds,
3203
+ maximizedId: layout.maximizedId,
3204
+ focusedPanelId,
3205
+ draggedId,
3206
+ dragOverTarget: dragOverTarget && dragOverTarget !== "topbar" && dragOverTarget !== "empty" ? dragOverTarget : null,
3207
+ activeDividerKey,
3208
+ nearFoldTarget,
3209
+ renderTooltip,
3210
+ onFocusPanel: setFocusedPanelId,
3211
+ onDragStart: setDraggedId,
3212
+ onDragEnd: () => {
3213
+ setDraggedId(null);
3214
+ setDragOverTarget(null);
3215
+ },
3216
+ onPanelDragOver: (event, panelId) => {
3217
+ if (!draggedId || draggedId === panelId) return;
3218
+ const position = getDropPosition(event);
3219
+ if (!movePanelInTree(layout.tree, draggedId, panelId, position, knownIds)) {
3220
+ setDragOverTarget((previous) => previous && previous !== "topbar" && previous !== "empty" && previous.panelId === panelId ? null : previous);
3221
+ return;
3222
+ }
3223
+ event.preventDefault();
3224
+ setDragOverTarget((previous) => previous && previous !== "topbar" && previous !== "empty" && previous.panelId === panelId && previous.position === position ? previous : {
3225
+ panelId,
3226
+ position
3227
+ });
3228
+ },
3229
+ onPanelDragLeave: (event, panelId) => {
3230
+ if (event.currentTarget.contains(event.relatedTarget)) return;
3231
+ if (dragOverTarget && dragOverTarget !== "topbar" && dragOverTarget !== "empty" && dragOverTarget.panelId === panelId) setDragOverTarget(null);
3232
+ },
3233
+ onPanelDrop: (event, panelId) => {
3234
+ event.preventDefault();
3235
+ if (draggedId) movePanel(draggedId, panelId, getDropPosition(event));
3236
+ setDraggedId(null);
3237
+ setDragOverTarget(null);
3238
+ },
3239
+ onToggleFold: toggleFold,
3240
+ onMaximize: toggleMaximize,
3241
+ onMinimize: minimizePanel,
3242
+ onResizeStart: handleResizeStart,
3243
+ onEqualize: handleEqualize,
3244
+ onKeyboardResize: handleKeyboardResize,
3245
+ onRestoreCompactPanel: handleRestoreCompactPanel
3246
+ })
3247
+ }) : /* @__PURE__ */ jsxs(Fragment$1, { children: [!currentMobilePanel ? /* @__PURE__ */ jsx("div", {
3248
+ className: `flex flex-1 flex-col items-center justify-center gap-3 rounded-[var(--rtw-radius-panel,0.875rem)] border border-dashed border-[var(--rtw-border-dashed,#b9c5d6)] bg-[var(--rtw-surface,#ffffff)] p-6 text-center ${embedded ? "m-3" : "m-3 mb-[72px]"}`,
3249
+ children: /* @__PURE__ */ jsx("p", {
3250
+ className: "text-sm font-medium text-[var(--rtw-text-subtle,#64748b)]",
3251
+ children: "Choose a panel from the bottom bar"
3252
+ })
3253
+ }) : /* @__PURE__ */ jsx("div", {
3254
+ className: `flex-1 overflow-y-auto bg-[var(--rtw-surface,#ffffff)] ${embedded ? "pb-0" : "pb-[60px]"}`,
3255
+ children: activePanels.map((panel) => /* @__PURE__ */ jsx("div", {
3256
+ "data-panel-id": panel.id,
3257
+ tabIndex: -1,
3258
+ className: currentMobilePanel.id === panel.id ? "h-full" : "hidden",
3259
+ children: panel.content
3260
+ }, panel.id))
3261
+ }), renderMobileBottomBar ? renderMobileBottomBar({
3262
+ panels: mobileOrderedPanels,
3263
+ activePanel: currentMobilePanel,
3264
+ selectTab: handleSelectMobileTab
3265
+ }) : embedded ? /* @__PURE__ */ jsx("div", {
3266
+ className: "flex shrink-0 items-center justify-around gap-1 border-t border-[var(--rtw-border,#dfe5ef)] bg-[var(--rtw-surface,#ffffff)] px-2 py-1.5",
3267
+ children: mobileOrderedPanels.map((panel) => {
3268
+ const isActive = currentMobilePanel?.id === panel.id;
3269
+ return /* @__PURE__ */ jsxs("button", {
3270
+ type: "button",
3271
+ onClick: () => handleSelectMobileTab(panel.id),
3272
+ className: `flex min-h-10 flex-1 cursor-pointer items-center justify-center gap-1.5 rounded-lg px-2 text-xs font-medium transition-colors ${isActive ? "bg-[var(--rtw-accent,#6366f1)] text-[var(--rtw-accent-foreground,#ffffff)]" : "text-[var(--rtw-text-subtle,#64748b)] hover:bg-[var(--rtw-surface-subtle,#edf1f7)]"}`,
3273
+ children: [/* @__PURE__ */ jsx("span", {
3274
+ "aria-hidden": "true",
3275
+ className: "flex size-3.5 shrink-0 items-center justify-center",
3276
+ children: panel.icon
3277
+ }), /* @__PURE__ */ jsx("span", {
3278
+ className: "truncate",
3279
+ children: panel.shortTitle ?? panel.title
3280
+ })]
3281
+ }, panel.id);
3282
+ })
3283
+ }) : /* @__PURE__ */ jsx(MobileBottomBar, {
3284
+ items: mobileNavItems,
3285
+ activeId: currentMobilePanel?.id ?? null,
3286
+ ariaLabel: "Workspace navigation"
3287
+ })] })]
3288
+ });
3289
+ }
3290
+ // src/shortcuts.ts
3291
+ const DEFAULT_WORKSPACE_SHORTCUTS = [
3292
+ {
3293
+ id: "focus-panel",
3294
+ label: "Focus or restore a panel",
3295
+ keys: "1–9"
3296
+ },
3297
+ {
3298
+ id: "toggle-fold",
3299
+ label: "Fold or unfold the focused panel",
3300
+ keys: "F"
3301
+ },
3302
+ {
3303
+ id: "toggle-maximize",
3304
+ label: "Maximize or restore the focused panel",
3305
+ keys: "M"
3306
+ },
3307
+ {
3308
+ id: "minimize-panel",
3309
+ label: "Minimize the focused panel",
3310
+ keys: "X"
3311
+ },
3312
+ {
3313
+ id: "reset-layout",
3314
+ label: "Reset the workspace layout",
3315
+ keys: "R"
3316
+ }
3317
+ ];
3318
+ export { DEFAULT_LAYOUT_PRESETS, DEFAULT_WORKSPACE_SHORTCUTS, LayoutPickerDialog, MAX_WORKSPACE_SPLIT_DEPTH, MobileBottomBar, TilingWorkspace, WorkspaceLayoutNodeView as WorkspaceColumn, WorkspaceTopBar, equalizeSplitAtPath, getPanelIds, isNodeFolded, layoutTemplateSignature, layoutTreeSignature, normalizeLayoutTree, useIsDesktop, validateLayoutTree };
3319
+
3320
+ //# sourceMappingURL=index.mjs.map