@labpane/os 1.1.0 → 1.3.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.
package/dist/index.js CHANGED
@@ -1,10 +1,14 @@
1
1
  // workspace.tsx
2
2
  import {
3
- useEffect as useEffect2,
3
+ memo as memo3,
4
+ useCallback as useCallback2,
5
+ useDeferredValue,
6
+ useEffect as useEffect5,
4
7
  useId as useId2,
5
- useLayoutEffect as useLayoutEffect4,
6
- useRef as useRef5,
7
- useState as useState4
8
+ useLayoutEffect as useLayoutEffect8,
9
+ useMemo as useMemo3,
10
+ useRef as useRef9,
11
+ useState as useState5
8
12
  } from "react";
9
13
 
10
14
  // context.ts
@@ -52,9 +56,9 @@ function densitySize(density) {
52
56
  const [from, to] = value < compact.value ? [dense, compact] : [compact, comfortable];
53
57
  const amount = (value - from.value) / (to.value - from.value);
54
58
  return Object.fromEntries(
55
- Object.keys(from).map((key) => [
56
- key,
57
- from[key] + (to[key] - from[key]) * amount
59
+ Object.keys(from).map((key2) => [
60
+ key2,
61
+ from[key2] + (to[key2] - from[key2]) * amount
58
62
  ])
59
63
  );
60
64
  }
@@ -67,15 +71,32 @@ function useTabSize() {
67
71
  function useWorkspaceIds() {
68
72
  const prefix = useContext(WorkspaceId);
69
73
  return {
70
- tab: (key) => `${prefix}-tab-${encodeURIComponent(key)}`,
71
- panel: (key) => `${prefix}-panel-${encodeURIComponent(key)}`
74
+ tab: (key2) => `${prefix}-tab-${encodeURIComponent(key2)}`,
75
+ panel: (key2) => `${prefix}-panel-${encodeURIComponent(key2)}`
72
76
  };
73
77
  }
78
+ var TabLinks = createContext(/* @__PURE__ */ new Map());
79
+ function useTabLinks() {
80
+ const links = useContext(TabLinks);
81
+ return useMemo(
82
+ () => ({
83
+ register: (key2) => (element) => {
84
+ if (element) links.set(key2, element);
85
+ else links.delete(key2);
86
+ },
87
+ get: (key2) => links.get(key2),
88
+ focus: (key2) => requestAnimationFrame(() => links.get(key2)?.focus())
89
+ }),
90
+ [links]
91
+ );
92
+ }
74
93
 
75
94
  // surface.tsx
76
95
  import {
77
96
  Fragment,
97
+ memo,
78
98
  useLayoutEffect,
99
+ useMemo as useMemo2,
79
100
  useRef,
80
101
  useState
81
102
  } from "react";
@@ -102,14 +123,14 @@ function reconcileLayout(node, keys, active, preferred) {
102
123
  return first && second ? first === node2.first && second === node2.second ? node2 : { ...node2, first, second } : first ?? second;
103
124
  }
104
125
  const tabs = node2.tabs.filter(
105
- (key) => keys.includes(key) && !seen.has(key) && !!seen.add(key)
126
+ (key2) => keys.includes(key2) && !seen.has(key2) && !!seen.add(key2)
106
127
  );
107
128
  if (!tabs.length) return void 0;
108
129
  const selected = tabs.includes(active ?? "") ? active : tabs.includes(node2.active ?? "") ? node2.active : tabs[0];
109
130
  return tabs.length === node2.tabs.length && selected === node2.active ? node2 : { ...node2, tabs, active: selected };
110
131
  };
111
132
  let next = clean(node) ?? { id: "primary", tabs: [] };
112
- const missing = keys.filter((key) => !seen.has(key));
133
+ const missing = keys.filter((key2) => !seen.has(key2));
113
134
  if (missing.length) {
114
135
  const leaves = panes(next), target = leaves.find((p) => p.id === preferred) ?? leaves[0];
115
136
  next = updateLayout(next, target.id, (node2) => ({
@@ -122,7 +143,7 @@ function reconcileLayout(node, keys, active, preferred) {
122
143
  }
123
144
  function restoreLayout(value, keys) {
124
145
  const ids = /* @__PURE__ */ new Set();
125
- function read(value2, depth = 0) {
146
+ function read2(value2, depth = 0) {
126
147
  const n = value2;
127
148
  if (!n || depth > 12 || typeof n.id !== "string" || !n.id || ids.has(n.id))
128
149
  throw Error("Invalid layout");
@@ -134,11 +155,11 @@ function restoreLayout(value, keys) {
134
155
  id: n.id,
135
156
  axis: n.axis,
136
157
  ratio: clamp(n.ratio, 0.05, 0.95),
137
- first: read(n.first, depth + 1),
138
- second: read(n.second, depth + 1)
158
+ first: read2(n.first, depth + 1),
159
+ second: read2(n.second, depth + 1)
139
160
  };
140
161
  }
141
- if (!Array.isArray(n.tabs) || n.tabs.some((key) => typeof key !== "string"))
162
+ if (!Array.isArray(n.tabs) || n.tabs.some((key2) => typeof key2 !== "string"))
142
163
  throw Error("Invalid tabs");
143
164
  return {
144
165
  id: n.id,
@@ -147,7 +168,7 @@ function restoreLayout(value, keys) {
147
168
  };
148
169
  }
149
170
  try {
150
- return reconcileLayout(read(JSON.parse(value ?? "null")), keys);
171
+ return reconcileLayout(read2(JSON.parse(value ?? "null")), keys);
151
172
  } catch {
152
173
  return { id: "primary", tabs: keys, active: keys[0] };
153
174
  }
@@ -156,26 +177,26 @@ var newId = () => crypto.randomUUID?.() ?? Array.from(
156
177
  crypto.getRandomValues(new Uint8Array(16)),
157
178
  (byte) => byte.toString(16).padStart(2, "0")
158
179
  ).join("");
159
- function dockTab(layout, key, target, edge, index) {
160
- const leaves = panes(layout), source = leaves.find((p) => p.tabs.includes(key)), destination = leaves.find((p) => p.id === target);
180
+ function dockTab(layout, key2, target, edge, index) {
181
+ const leaves = panes(layout), source = leaves.find((p) => p.tabs.includes(key2)), destination = leaves.find((p) => p.id === target);
161
182
  if (!source || !destination || source === destination && (!edge || source.tabs.length === 1))
162
183
  return layout;
163
184
  let next = updateLayout(layout, source.id, (node) => {
164
- const pane = node, index2 = pane.tabs.indexOf(key), tabs = pane.tabs.filter((k) => k !== key);
185
+ const pane = node, index2 = pane.tabs.indexOf(key2), tabs = pane.tabs.filter((k) => k !== key2);
165
186
  return {
166
187
  ...pane,
167
188
  tabs,
168
- active: pane.active === key ? tabs[Math.min(index2, tabs.length - 1)] : pane.active
189
+ active: pane.active === key2 ? tabs[Math.min(index2, tabs.length - 1)] : pane.active
169
190
  };
170
191
  });
171
192
  next = updateLayout(next, target, (node) => {
172
193
  const pane = node;
173
194
  if (!edge) {
174
195
  const tabs = [...pane.tabs];
175
- tabs.splice(index ?? tabs.length, 0, key);
176
- return { ...pane, tabs, active: key };
196
+ tabs.splice(index ?? tabs.length, 0, key2);
197
+ return { ...pane, tabs, active: key2 };
177
198
  }
178
- const added = { id: newId(), tabs: [key], active: key };
199
+ const added = { id: newId(), tabs: [key2], active: key2 };
179
200
  return {
180
201
  id: newId(),
181
202
  axis: edge === "bottom" ? "y" : "x",
@@ -187,7 +208,7 @@ function dockTab(layout, key, target, edge, index) {
187
208
  return reconcileLayout(
188
209
  next,
189
210
  leaves.flatMap((p) => p.tabs),
190
- key
211
+ key2
191
212
  );
192
213
  }
193
214
  function minimumSize(node, gap = gutter) {
@@ -248,6 +269,38 @@ function dropRegion(box, edge, gap = gutter) {
248
269
  return box;
249
270
  }
250
271
 
272
+ // overlay.ts
273
+ var overlays = ["dialog", "alertdialog", "menu", "listbox"].map((role) => `[role="${role}"]`).concat("[data-labpane-overlay]").join(", ");
274
+ function hasOpenOverlay() {
275
+ const full = document.fullscreenElement;
276
+ return !!full && full !== document.documentElement || !!document.querySelector(overlays);
277
+ }
278
+
279
+ // frame-task.ts
280
+ function frameTask(run) {
281
+ let frame2;
282
+ let pending2;
283
+ const flush2 = () => {
284
+ if (frame2 !== void 0) cancelAnimationFrame(frame2);
285
+ frame2 = void 0;
286
+ const next = pending2;
287
+ pending2 = void 0;
288
+ if (next) run(next.value);
289
+ };
290
+ return {
291
+ schedule(value) {
292
+ pending2 = { value };
293
+ if (frame2 === void 0) frame2 = requestAnimationFrame(flush2);
294
+ },
295
+ flush: flush2,
296
+ cancel() {
297
+ if (frame2 !== void 0) cancelAnimationFrame(frame2);
298
+ frame2 = void 0;
299
+ pending2 = void 0;
300
+ }
301
+ };
302
+ }
303
+
251
304
  // surface.tsx
252
305
  import { jsx, jsxs } from "react/jsx-runtime";
253
306
  var position = (box) => ({
@@ -256,6 +309,26 @@ var position = (box) => ({
256
309
  width: box.width,
257
310
  height: box.height
258
311
  });
312
+ var PaneHeader = memo(function PaneHeader2({
313
+ pane,
314
+ first,
315
+ last,
316
+ docking,
317
+ insertion,
318
+ board,
319
+ render
320
+ }) {
321
+ const ids = useWorkspaceIds();
322
+ return render(
323
+ pane,
324
+ first,
325
+ last,
326
+ { ...docking, insertion },
327
+ (key2 = pane.active) => board.current?.querySelector(
328
+ key2 ? `#${CSS.escape(ids.panel(key2))}` : `[data-pane-sheet="${CSS.escape(pane.id)}"]:not([hidden]):not([data-drag-content])`
329
+ ) ?? null
330
+ );
331
+ });
259
332
  function WorkspaceSurface({
260
333
  layout,
261
334
  change,
@@ -276,6 +349,15 @@ function WorkspaceSurface({
276
349
  const [preview, setPreview] = useState();
277
350
  const previewRef = useRef(void 0);
278
351
  const [resizing, setResizing] = useState(false);
352
+ const [resizeDraft, setResizeDraft] = useState();
353
+ const resizeDraftRef = useRef(void 0);
354
+ const displayedLayout = resizeDraft?.base === layout ? resizeDraft.layout : layout;
355
+ const cancelResize = () => {
356
+ resizePointer.cancel();
357
+ resizeDraftRef.current = void 0;
358
+ setResizeDraft(void 0);
359
+ setResizing(false);
360
+ };
279
361
  const geometry = [
280
362
  size.width,
281
363
  size.height,
@@ -289,19 +371,29 @@ function WorkspaceSurface({
289
371
  previousGeometry.current = geometry;
290
372
  }, [geometry]);
291
373
  useLayoutEffect(() => {
292
- const observer = new ResizeObserver(([entry]) => {
374
+ const observer2 = new ResizeObserver(([entry]) => {
293
375
  const { width, height } = entry.contentRect;
294
376
  setSize({ width, height });
295
377
  });
296
- observer.observe(board.current);
297
- return () => observer.disconnect();
378
+ observer2.observe(board.current);
379
+ return () => observer2.disconnect();
298
380
  }, []);
299
381
  const { leaves, dividers } = layoutBoxes(
300
- layout,
382
+ displayedLayout,
301
383
  size.width,
302
384
  size.height,
303
385
  gutter2
304
- ), required = minimumSize(layout, gutter2);
386
+ ), required = minimumSize(displayedLayout, gutter2);
387
+ const [resizePointer] = useState(
388
+ () => frameTask((resize) => resize())
389
+ );
390
+ useLayoutEffect(() => {
391
+ addEventListener("blur", cancelResize);
392
+ return () => {
393
+ resizePointer.cancel();
394
+ removeEventListener("blur", cancelResize);
395
+ };
396
+ }, [resizePointer]);
305
397
  const show = (next) => {
306
398
  if (previewRef.current?.pane === next?.pane && previewRef.current?.edge === next?.edge && previewRef.current?.index === next?.index && previewRef.current?.key === next?.key)
307
399
  return;
@@ -311,18 +403,18 @@ function WorkspaceSurface({
311
403
  const canSplit = (box, edge) => edge === "bottom" ? box.height >= minimum.y * 2 + rowGap : box.width >= minimum.x * 2 + columnGap;
312
404
  const docking = {
313
405
  paneCount: leaves.length,
314
- next: (key) => {
315
- const index = leaves.findIndex((p) => p.pane.tabs.includes(key));
406
+ next: (key2) => {
407
+ const index = leaves.findIndex((p) => p.pane.tabs.includes(key2));
316
408
  change(
317
- dockTab(layout, key, leaves[(index + 1) % leaves.length].pane.id)
409
+ dockTab(layout, key2, leaves[(index + 1) % leaves.length].pane.id)
318
410
  );
319
411
  },
320
- move: ({ key, x, y, detached: wasDetached }) => {
412
+ move: ({ key: key2, x, y, detached: wasDetached }) => {
321
413
  const bounds = board.current.getBoundingClientRect(), localX = x - bounds.left, localY = y - bounds.top;
322
414
  const target = leaves.find(
323
415
  (p) => localX >= p.x && localX <= p.x + p.width && localY >= p.y && localY <= p.y + p.height
324
416
  );
325
- const source = leaves.find((p) => p.pane.tabs.includes(key));
417
+ const source = leaves.find((p) => p.pane.tabs.includes(key2));
326
418
  const margin = wasDetached ? 8 : 24;
327
419
  const detached = localY > source.y + tabHeight + margin || localY < source.y - margin || !!target && (localX < source.x - margin || localX > source.x + source.width + margin);
328
420
  if (!detached) {
@@ -335,7 +427,7 @@ function WorkspaceSurface({
335
427
  else if (localX < target.x + target.width * 0.28) edge = "left";
336
428
  else if (localX > target.x + target.width * 0.72) edge = "right";
337
429
  }
338
- const valid = target && (!edge || canSplit(target, edge)) && (!target.pane.tabs.includes(key) || !!edge && target.pane.tabs.length > 1);
430
+ const valid = target && (!edge || canSplit(target, edge)) && (!target.pane.tabs.includes(key2) || !!edge && target.pane.tabs.length > 1);
339
431
  let index;
340
432
  if (valid && !edge) {
341
433
  const nav = board.current.querySelector(
@@ -370,7 +462,7 @@ function WorkspaceSurface({
370
462
  );
371
463
  }
372
464
  }
373
- show(valid ? { pane: target.pane.id, key, edge, index } : { key });
465
+ show(valid ? { pane: target.pane.id, key: key2, edge, index } : { key: key2 });
374
466
  return true;
375
467
  },
376
468
  drop: () => {
@@ -383,23 +475,45 @@ function WorkspaceSurface({
383
475
  return true;
384
476
  },
385
477
  cancel: () => show(),
386
- split: (key, edge) => {
387
- const target = leaves.find((p) => p.pane.tabs.includes(key));
478
+ split: (key2, edge) => {
479
+ const target = leaves.find((p) => p.pane.tabs.includes(key2));
388
480
  if (!target || target.pane.tabs.length < 2 || !canSplit(target, edge))
389
481
  return false;
390
- change(dockTab(layout, key, target.pane.id, edge));
482
+ change(dockTab(layout, key2, target.pane.id, edge));
391
483
  return true;
392
484
  }
393
485
  };
394
486
  const lifted = preview?.key;
487
+ const operations = useRef(docking);
488
+ useLayoutEffect(() => {
489
+ operations.current = docking;
490
+ });
491
+ const paneCount = leaves.length;
492
+ const stableDocking = useMemo2(
493
+ () => ({
494
+ paneCount,
495
+ move: (drag) => operations.current.move(drag),
496
+ drop: () => operations.current.drop(),
497
+ cancel: () => operations.current.cancel(),
498
+ split: (key2, edge) => operations.current.split(key2, edge),
499
+ next: (key2) => operations.current.next(key2)
500
+ }),
501
+ [paneCount]
502
+ );
503
+ const sourcePreview = useMemo2(() => {
504
+ if (!lifted) return;
505
+ const pane = panes(displayedLayout).find(
506
+ (pane2) => pane2.tabs.includes(lifted)
507
+ );
508
+ if (!pane) return;
509
+ const remaining = pane.tabs.filter((key2) => key2 !== lifted);
510
+ return {
511
+ ...pane,
512
+ active: remaining[Math.min(pane.tabs.indexOf(lifted), remaining.length - 1)]
513
+ };
514
+ }, [displayedLayout, lifted]);
395
515
  const regions = leaves.map(({ pane, ...box }) => {
396
- if (lifted && pane.tabs.includes(lifted)) {
397
- const remaining = pane.tabs.filter((key) => key !== lifted);
398
- pane = {
399
- ...pane,
400
- active: remaining[Math.min(pane.tabs.indexOf(lifted), remaining.length - 1)]
401
- };
402
- }
516
+ if (sourcePreview?.id === pane.id) pane = sourcePreview;
403
517
  if (preview?.pane !== pane.id || !preview.edge) return { pane, box };
404
518
  const drop = dropRegion(box, preview.edge, gutter2);
405
519
  if (preview.edge === "left")
@@ -437,17 +551,17 @@ function WorkspaceSurface({
437
551
  ...position({ ...box, height: tabHeight }),
438
552
  transitionDuration: transition ? "var(--workspace-duration, 180ms)" : "0ms"
439
553
  },
440
- children: header(
441
- pane,
442
- index === 0,
443
- pane.id === topRight,
554
+ children: /* @__PURE__ */ jsx(
555
+ PaneHeader,
444
556
  {
445
- ...docking,
446
- insertion: preview?.pane === pane.id ? preview.index : void 0
447
- },
448
- (key = pane.active) => board.current?.querySelector(
449
- key ? `[id="${CSS.escape(ids.panel(key))}"]` : `[data-pane-sheet="${CSS.escape(pane.id)}"]:not([hidden]):not([data-drag-content])`
450
- ) ?? null
557
+ pane,
558
+ first: index === 0,
559
+ last: pane.id === topRight,
560
+ docking: stableDocking,
561
+ insertion: preview?.pane === pane.id ? preview.index : void 0,
562
+ board,
563
+ render: header
564
+ }
451
565
  )
452
566
  },
453
567
  pane.id
@@ -456,12 +570,19 @@ function WorkspaceSurface({
456
570
  dividers.map(({ split, bounds, ratio, low, high, ...box }) => {
457
571
  const axis = split.axis, horizontal = axis === "x", dimension = horizontal ? "width" : "height";
458
572
  const primary = panes(split.first).filter((p) => p.active);
459
- const resize = (value) => change(
460
- updateLayout(layout, split.id, (node) => ({
573
+ const resize = (value, preview2 = false) => {
574
+ const next = updateLayout(displayedLayout, split.id, (node) => ({
461
575
  ...node,
462
576
  ratio: Math.max(low, Math.min(high, value))
463
- }))
464
- );
577
+ }));
578
+ if (preview2) {
579
+ resizeDraftRef.current = { base: layout, layout: next };
580
+ setResizeDraft(resizeDraftRef.current);
581
+ } else {
582
+ cancelResize();
583
+ change(next);
584
+ }
585
+ };
465
586
  const target = /* @__PURE__ */ jsx(
466
587
  "div",
467
588
  {
@@ -492,14 +613,26 @@ function WorkspaceSurface({
492
613
  onPointerMove: (event) => {
493
614
  if (!event.currentTarget.hasPointerCapture(event.pointerId))
494
615
  return;
495
- const b = board.current.getBoundingClientRect();
496
- const coordinate = horizontal ? event.clientX - b.left : event.clientY - b.top;
497
- resize(
498
- (coordinate - bounds[axis]) / (bounds[dimension] - gutter2[axis])
499
- );
616
+ const { clientX, clientY } = event;
617
+ resizePointer.schedule(() => {
618
+ const b = board.current.getBoundingClientRect();
619
+ const coordinate = horizontal ? clientX - b.left : clientY - b.top;
620
+ resize(
621
+ (coordinate - bounds[axis]) / (bounds[dimension] - gutter2[axis]),
622
+ true
623
+ );
624
+ });
625
+ },
626
+ onPointerUp: () => {
627
+ resizePointer.flush();
628
+ const draft = resizeDraftRef.current;
629
+ if (draft?.base === layout) change(draft.layout);
630
+ cancelResize();
500
631
  },
501
- onLostPointerCapture: () => setResizing(false),
632
+ onPointerCancel: cancelResize,
633
+ onLostPointerCapture: cancelResize,
502
634
  onKeyDown: (event) => {
635
+ if (hasOpenOverlay()) return;
503
636
  const step = event.shiftKey ? 0.1 : 0.02;
504
637
  const values = {
505
638
  [horizontal ? "ArrowLeft" : "ArrowUp"]: ratio - step,
@@ -567,6 +700,7 @@ var ChevronRightIcon = icon(4 / 3, "m6 4 4 4-4 4");
567
700
  var XIcon = icon(7 / 6, "m12 4-8 8", "m4 4 8 8");
568
701
 
569
702
  // frame.tsx
703
+ import { memo as memo2 } from "react";
570
704
  import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
571
705
  var reach = 16;
572
706
  var shoulder = [
@@ -629,7 +763,7 @@ function paneShape(leftGap, rightGap, bottom, morph = true, size = densityPreset
629
763
  const leftCorner = morph && leftGap < reach ? "" : ` A15.5 15.5 0 0 1 ${left + 15.5} ${baseline} H0`;
630
764
  return `${tabShape(morph ? leftGap : reach, morph ? rightGap : reach, size)[1]}${rightCorner} V${bottom - 15.5} A15.5 15.5 0 0 1 ${right - 15.5} ${bottom} H${left + 15.5} A15.5 15.5 0 0 1 ${left} ${bottom - 15.5} V${cornerBottom}${leftCorner} Z`;
631
765
  }
632
- function TabSurface({
766
+ var TabSurface = memo2(function TabSurface2({
633
767
  selected,
634
768
  keyboardFocus = false,
635
769
  width
@@ -665,94 +799,204 @@ function TabSurface({
665
799
  ]
666
800
  }
667
801
  );
668
- }
802
+ });
669
803
 
670
804
  // drag-content.ts
671
805
  import { useEffect, useRef as useRef2 } from "react";
806
+
807
+ // geometry-task.ts
808
+ var pending = /* @__PURE__ */ new Set();
809
+ var observed = /* @__PURE__ */ new Map();
810
+ var animations = /* @__PURE__ */ new Map();
811
+ var observer;
812
+ var frame;
813
+ var microtask = false;
814
+ function flush() {
815
+ if (frame !== void 0) cancelAnimationFrame(frame);
816
+ frame = void 0;
817
+ for (const [element, animation] of animations) {
818
+ for (const task of observed.get(element) ?? []) pending.add(task);
819
+ if (!element.isConnected || animation.playState !== "running")
820
+ animations.delete(element);
821
+ }
822
+ const reads = [...pending];
823
+ pending.clear();
824
+ const writes = reads.map((task) => {
825
+ const resized = task.resized;
826
+ task.resized = false;
827
+ return task.read(resized);
828
+ });
829
+ for (const write of writes) write?.();
830
+ if (animations.size && frame === void 0)
831
+ frame = requestAnimationFrame(flush);
832
+ }
833
+ function followGeometry(element, animation) {
834
+ animations.set(element, animation);
835
+ if (frame === void 0) frame = requestAnimationFrame(flush);
836
+ }
837
+ function geometryTask(read2) {
838
+ const task = { read: read2, resized: false };
839
+ return {
840
+ schedule() {
841
+ pending.add(task);
842
+ if (frame === void 0) frame = requestAnimationFrame(flush);
843
+ },
844
+ // Wait for layout effects, but measure before paint.
845
+ commit(resized = false) {
846
+ task.resized ||= resized;
847
+ pending.add(task);
848
+ if (microtask) return;
849
+ microtask = true;
850
+ queueMicrotask(() => {
851
+ microtask = false;
852
+ flush();
853
+ });
854
+ },
855
+ flush() {
856
+ pending.add(task);
857
+ flush();
858
+ },
859
+ cancel() {
860
+ pending.delete(task);
861
+ task.resized = false;
862
+ if (!pending.size && !animations.size && frame !== void 0) {
863
+ cancelAnimationFrame(frame);
864
+ frame = void 0;
865
+ }
866
+ },
867
+ observe(elements) {
868
+ observer ??= new ResizeObserver((entries) => {
869
+ for (const { target } of entries)
870
+ for (const task2 of observed.get(target) ?? []) {
871
+ task2.resized = true;
872
+ pending.add(task2);
873
+ }
874
+ flush();
875
+ });
876
+ for (const element of elements) {
877
+ let callbacks = observed.get(element);
878
+ if (!callbacks) {
879
+ observed.set(element, callbacks = /* @__PURE__ */ new Set());
880
+ observer.observe(element);
881
+ }
882
+ callbacks.add(task);
883
+ }
884
+ return () => {
885
+ for (const element of elements) {
886
+ const callbacks = observed.get(element);
887
+ callbacks?.delete(task);
888
+ if (!callbacks?.size) {
889
+ observed.delete(element);
890
+ observer?.unobserve(element);
891
+ }
892
+ }
893
+ if (!observed.size) {
894
+ observer?.disconnect();
895
+ observer = void 0;
896
+ }
897
+ };
898
+ }
899
+ };
900
+ }
901
+
902
+ // drag-content.ts
672
903
  function useDragContent() {
673
904
  const generation = useRef2(0);
674
905
  const current = useRef2(void 0);
675
- const release = (animate = true) => {
906
+ const prepareRelease = (animate = true) => {
676
907
  const preview = current.current;
677
908
  if (!preview) return;
678
- current.current = void 0;
679
- const version = ++generation.current;
680
909
  const { element, inert } = preview;
681
910
  const from = element.getBoundingClientRect();
682
- element.removeAttribute("data-drag-content");
683
- element.inert = inert;
684
- element.style.transition = "none";
685
- for (const name of ["x", "y", "width", "height"])
686
- element.style.removeProperty(`--lab-drag-${name}`);
687
- requestAnimationFrame(() => {
688
- if (version !== generation.current) return;
689
- const to = element.getBoundingClientRect();
690
- element.style.removeProperty("transition");
691
- if (!animate || !element.isConnected || !to.width || matchMedia("(prefers-reduced-motion: reduce)").matches)
692
- return;
693
- const resized = Math.abs(from.width - to.width) > 0.5 || Math.abs(from.height - to.height) > 0.5;
694
- element.animate(
695
- [
696
- {
697
- transform: `translate(${from.left - to.left}px, ${from.top - to.top}px)`,
698
- width: `${from.width}px`,
699
- height: `${from.height}px`,
700
- filter: "blur(0)",
701
- opacity: 1
702
- },
703
- {
704
- filter: resized ? "blur(3px)" : "blur(0)",
705
- opacity: resized ? 0.85 : 1,
706
- offset: 0.35
707
- },
708
- {
709
- transform: "none",
710
- width: `${to.width}px`,
711
- height: `${to.height}px`,
712
- filter: "blur(0)",
713
- opacity: 1
714
- }
715
- ],
716
- { duration: 220, easing: "cubic-bezier(.2,.8,.2,1)" }
717
- );
718
- });
911
+ return () => {
912
+ current.current = void 0;
913
+ const version = ++generation.current;
914
+ element.removeAttribute("data-drag-content");
915
+ element.inert = inert;
916
+ element.style.transition = "none";
917
+ element.style.removeProperty("transform");
918
+ for (const name of ["width", "height"])
919
+ element.style.removeProperty(`--lab-drag-${name}`);
920
+ requestAnimationFrame(() => {
921
+ if (version !== generation.current) return;
922
+ const to = element.getBoundingClientRect();
923
+ element.style.removeProperty("transition");
924
+ if (!animate || !element.isConnected || !to.width || matchMedia("(prefers-reduced-motion: reduce)").matches)
925
+ return;
926
+ const resized = Math.abs(from.width - to.width) > 0.5 || Math.abs(from.height - to.height) > 0.5;
927
+ const animation = element.animate(
928
+ [
929
+ {
930
+ transform: `translate(${from.left - to.left}px, ${from.top - to.top}px)`,
931
+ width: `${from.width}px`,
932
+ height: `${from.height}px`,
933
+ filter: "blur(0)",
934
+ opacity: 1
935
+ },
936
+ {
937
+ filter: resized ? "blur(3px)" : "blur(0)",
938
+ opacity: resized ? 0.85 : 1,
939
+ offset: 0.35
940
+ },
941
+ {
942
+ transform: "none",
943
+ width: `${to.width}px`,
944
+ height: `${to.height}px`,
945
+ filter: "blur(0)",
946
+ opacity: 1
947
+ }
948
+ ],
949
+ { duration: 220, easing: "cubic-bezier(.2,.8,.2,1)" }
950
+ );
951
+ followGeometry(element, animation);
952
+ });
953
+ };
719
954
  };
955
+ const release = (animate = true) => prepareRelease(animate)?.();
720
956
  useEffect(() => () => release(false), []);
721
957
  return {
722
958
  release,
723
- lift(element, tab, fallback) {
724
- if (current.current?.element !== element) {
725
- release(false);
726
- generation.current++;
727
- element.getAnimations().forEach((animation) => animation.cancel());
728
- const bounds = element.hidden ? fallback : element.getBoundingClientRect();
729
- current.current = {
730
- element,
731
- width: bounds.width,
732
- height: bounds.height,
733
- offset: Math.max(
734
- 8,
735
- Math.min(
736
- tab.getBoundingClientRect().left - bounds.left,
737
- bounds.width - tab.offsetWidth - 8
738
- )
739
- ),
740
- inert: element.inert
741
- };
742
- for (const [name, value] of Object.entries({
743
- width: `${bounds.width}px`,
744
- height: `${bounds.height}px`
745
- }))
746
- element.style.setProperty(`--lab-drag-${name}`, String(value));
747
- element.inert = true;
748
- element.setAttribute("data-drag-content", "");
749
- }
750
- return current.current;
959
+ prepareRelease,
960
+ prepareLift(element, tab, fallback) {
961
+ if (current.current?.element === element)
962
+ return { ...current.current, apply: () => {
963
+ } };
964
+ const releasePrevious = prepareRelease(false);
965
+ const animations2 = element.getAnimations();
966
+ const bounds = element.hidden ? fallback : element.getBoundingClientRect();
967
+ const preview = {
968
+ element,
969
+ width: bounds.width,
970
+ height: bounds.height,
971
+ offset: Math.max(
972
+ 8,
973
+ Math.min(
974
+ tab.getBoundingClientRect().left - bounds.left,
975
+ bounds.width - tab.offsetWidth - 8
976
+ )
977
+ ),
978
+ inert: element.inert
979
+ };
980
+ return {
981
+ ...preview,
982
+ apply: () => {
983
+ releasePrevious?.();
984
+ generation.current++;
985
+ animations2.forEach((animation) => animation.cancel());
986
+ current.current = preview;
987
+ for (const [name, value] of Object.entries({
988
+ width: `${bounds.width}px`,
989
+ height: `${bounds.height}px`
990
+ }))
991
+ element.style.setProperty(`--lab-drag-${name}`, String(value));
992
+ element.inert = true;
993
+ element.setAttribute("data-drag-content", "");
994
+ }
995
+ };
751
996
  },
752
997
  move(x, y) {
753
998
  const element = current.current?.element;
754
- element?.style.setProperty("--lab-drag-x", `${x}px`);
755
- element?.style.setProperty("--lab-drag-y", `${y}px`);
999
+ element?.style.setProperty("transform", `translate3d(${x}px, ${y}px, 0)`);
756
1000
  }
757
1001
  };
758
1002
  }
@@ -760,8 +1004,11 @@ function useDragContent() {
760
1004
  // tabs.tsx
761
1005
  import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
762
1006
  var motion = { duration: 160, easing: "cubic-bezier(.2,.8,.2,1)" };
1007
+ var pathData = (path, value) => {
1008
+ if (path.getAttribute("d") !== value) path.setAttribute("d", value);
1009
+ };
763
1010
  function WorkspaceTabs({
764
- items,
1011
+ items: sourceItems,
765
1012
  active,
766
1013
  onClose,
767
1014
  onDuplicate,
@@ -772,27 +1019,28 @@ function WorkspaceTabs({
772
1019
  docking,
773
1020
  menu
774
1021
  }) {
1022
+ const [draftOrder, setDraftOrder] = React.useState();
1023
+ const itemOrder = new Map(draftOrder?.map((key2, index) => [key2, index]));
1024
+ const items = draftOrder ? sourceItems.slice().sort(
1025
+ (a, b) => (itemOrder.get(a.key) ?? Infinity) - (itemOrder.get(b.key) ?? Infinity)
1026
+ ) : sourceItems;
775
1027
  const ids = useWorkspaceIds();
1028
+ const tabLinks = useTabLinks();
776
1029
  const content = useDragContent();
777
1030
  const density = useTabSize();
778
1031
  const [metrics, setMetrics] = React.useState({
779
- available: Infinity,
1032
+ width: density.width,
780
1033
  overflow: false,
781
1034
  left: false,
782
1035
  right: false
783
1036
  });
784
1037
  const measured = React.useRef(metrics);
785
- const { available } = metrics;
786
1038
  const size = {
787
1039
  ...density,
788
- width: fitTabWidth(
789
- density.width,
790
- available,
791
- items.length + (docking.insertion === void 0 ? 0 : 1)
792
- )
1040
+ width: metrics.width
793
1041
  }, { width: tabWidth, height, contentHeight } = size, width = tabWidth + 16;
794
- const links = items.map(({ key, label }) => [key, label]);
795
- const tabOrder = JSON.stringify(items.map(({ key }) => key));
1042
+ const links = items.map(({ key: key2, label }) => [key2, label]);
1043
+ const tabOrder = JSON.stringify(items.map(({ key: key2 }) => key2));
796
1044
  const labels = new Map(links);
797
1045
  const navRef = React.useRef(null);
798
1046
  const stripRef = React.useRef(null);
@@ -817,102 +1065,130 @@ function WorkspaceTabs({
817
1065
  maskedOutline.current = null;
818
1066
  };
819
1067
  const settling = React.useRef(void 0);
1068
+ const animations2 = React.useRef(/* @__PURE__ */ new Map());
1069
+ const transitions = React.useRef(/* @__PURE__ */ new Map());
820
1070
  const positions = React.useRef({
821
1071
  order: "",
822
1072
  tabs: /* @__PURE__ */ new Map()
823
1073
  });
824
- const frame = React.useRef(0);
825
1074
  const suppressClick = React.useRef(false);
826
- const tabElement = (key) => navRef.current?.querySelector(
827
- `a[data-tab="${CSS.escape(key)}"]`
828
- )?.parentElement;
829
- const reveal = (key = active) => {
830
- const nav = navRef.current, tab = tabElement(key);
1075
+ const tabElement = (key2) => tabLinks.get(key2)?.parentElement;
1076
+ const readReveal = (key2 = active) => {
1077
+ const nav = navRef.current, tab = tabElement(key2);
831
1078
  if (!nav || !tab || drag.current?.moved || docking.insertion !== void 0)
832
1079
  return;
833
- nav.scrollLeft = Math.max(
1080
+ const left = Math.max(
834
1081
  tab.offsetLeft + tab.offsetWidth + 8 - nav.clientWidth,
835
1082
  Math.min(nav.scrollLeft, tab.offsetLeft - 8)
836
1083
  );
1084
+ if (left === nav.scrollLeft) return;
1085
+ return {
1086
+ delta: left - nav.scrollLeft,
1087
+ apply: () => {
1088
+ nav.scrollLeft = left;
1089
+ }
1090
+ };
837
1091
  };
838
- const draw = () => {
839
- const current = drag.current, ghost2 = ghostRef.current, nav = navRef.current, bounds = dragBoundary?.getBoundingClientRect(), floating = !!ghost2 && !!current?.detached, tab = (floating ? null : ghost2) ?? tabElement(active), frame2 = frameRef.current;
840
- if (ghost2 && current?.moved && bounds) {
1092
+ const reveal = (key2 = active) => readReveal(key2)?.apply();
1093
+ const readDrawing = (scrollDelta = 0) => {
1094
+ const current = drag.current, ghost2 = ghostRef.current, nav = navRef.current, bounds = dragBoundary?.getBoundingClientRect(), floating = !!ghost2 && !!current?.detached, tab = (floating ? null : ghost2) ?? tabElement(active), frame2 = frameRef.current, sheet = surface(), sheetBox = sheet?.getBoundingClientRect(), navBox = nav?.getBoundingClientRect(), origin = frame2?.parentElement?.getBoundingClientRect();
1095
+ let box = tab && (tab !== ghost2 || !current?.moved) ? tab.getBoundingClientRect() : void 0;
1096
+ if (box && tab !== ghost2 && scrollDelta)
1097
+ box = new DOMRect(box.x - scrollDelta, box.y, box.width, box.height);
1098
+ const lift = ghost2 && current?.moved && floating ? (() => {
841
1099
  const sheet2 = surface(current.key);
842
- const preview = floating && sheet2 ? content.lift(sheet2, ghost2, current.sheet) : void 0;
843
- const left2 = floating ? 8 : bounds.left + 8, right2 = floating ? innerWidth - 8 : bounds.right - 8;
844
- const x2 = Math.max(
845
- left2,
846
- Math.min(current.x - current.offset, right2 - ghost2.offsetWidth)
847
- );
848
- const y = floating ? Math.max(
849
- 0,
850
- Math.min(current.y - current.offsetY, innerHeight - height - 8)
851
- ) : nav.getBoundingClientRect().top;
852
- ghost2.style.left = `${x2}px`;
853
- ghost2.style.top = `${y}px`;
854
- if (preview) {
855
- content.move(x2 - preview.offset, y + height - 1);
856
- const left3 = preview.offset - 8, right3 = preview.width - preview.offset - tabWidth - 8;
857
- ghost2.querySelector("svg > path").setAttribute("d", tabShape(left3, right3, size)[0]);
858
- const outline = ghost2.querySelector("[data-tab-outline]");
859
- outline.style.visibility = "visible";
860
- outline.setAttribute(
861
- "d",
862
- paneShape(left3, right3, height + preview.height - 1.5, true, size)
1100
+ return sheet2 ? content.prepareLift(sheet2, ghost2, current.sheet) : void 0;
1101
+ })() : void 0;
1102
+ const release = ghost2 && current?.moved && !lift ? content.prepareRelease() : void 0;
1103
+ return () => {
1104
+ if (ghost2 && current?.moved && bounds) {
1105
+ const preview = lift;
1106
+ preview?.apply();
1107
+ const left2 = floating ? 8 : bounds.left + 8, right2 = floating ? innerWidth - 8 : bounds.right - 8;
1108
+ const x2 = Math.max(
1109
+ left2,
1110
+ Math.min(current.x - current.offset, right2 - tabWidth)
863
1111
  );
864
- } else content.release();
865
- }
866
- restoreFrame();
867
- if (!tab || !bounds || !frame2) {
868
- if (frame2) frame2.style.visibility = "hidden";
869
- return;
870
- }
871
- const box = tab.getBoundingClientRect();
872
- const sheet = surface(), sheetBox = sheet?.getBoundingClientRect();
873
- const attached = Math.abs(box.top - bounds.top) < 0.5 && !!sheet;
874
- const left = attached ? box.left - 8 - sheetBox.left : 16, right = attached ? sheetBox.right - box.right - 8 : 16;
875
- if (ghost2 && !floating) {
876
- const [fill, outline] = tabShape(
877
- Math.max(0, left),
878
- Math.max(0, right),
879
- size
1112
+ const y = floating ? Math.max(
1113
+ 0,
1114
+ Math.min(current.y - current.offsetY, innerHeight - height - 8)
1115
+ ) : navBox.top;
1116
+ if (tab === ghost2) box = new DOMRect(x2, y, tabWidth, height);
1117
+ ghost2.style.translate = `${x2}px ${y}px`;
1118
+ if (preview) {
1119
+ content.move(x2 - preview.offset, y + height - 1);
1120
+ const left3 = preview.offset - 8, right3 = preview.width - preview.offset - tabWidth - 8;
1121
+ pathData(
1122
+ ghost2.querySelector("svg > path"),
1123
+ tabShape(left3, right3, size)[0]
1124
+ );
1125
+ const outline = ghost2.querySelector("[data-tab-outline]");
1126
+ outline.style.visibility = "visible";
1127
+ pathData(
1128
+ outline,
1129
+ paneShape(left3, right3, height + preview.height - 1.5, true, size)
1130
+ );
1131
+ } else release?.();
1132
+ }
1133
+ if (!tab || !box || !bounds || !frame2) {
1134
+ restoreFrame();
1135
+ if (frame2) frame2.style.visibility = "hidden";
1136
+ return;
1137
+ }
1138
+ const attached = Math.abs(box.top - bounds.top) < 0.5 && !!sheet;
1139
+ const left = attached ? box.left - 8 - sheetBox.left : 16, right = attached ? sheetBox.right - box.right - 8 : 16;
1140
+ if (ghost2 && !floating) {
1141
+ const [fill, outline] = tabShape(
1142
+ Math.max(0, left),
1143
+ Math.max(0, right),
1144
+ size
1145
+ );
1146
+ pathData(ghost2.querySelector("svg > path"), fill);
1147
+ pathData(ghost2.querySelector("[data-tab-outline]"), outline);
1148
+ }
1149
+ const stroke = tab.querySelector("[data-tab-outline]");
1150
+ if (maskedOutline.current !== stroke)
1151
+ maskedOutline.current?.style.removeProperty("visibility");
1152
+ stroke.style.visibility = attached ? "hidden" : "visible";
1153
+ maskedOutline.current = stroke;
1154
+ frame2.style.visibility = attached ? "visible" : "hidden";
1155
+ if (maskedSheet.current !== (attached ? sheet : null))
1156
+ maskedSheet.current?.style.removeProperty("border-color");
1157
+ maskedSheet.current = attached ? sheet : null;
1158
+ if (!attached) return;
1159
+ sheet.style.borderColor = "transparent";
1160
+ maskedSheet.current = sheet;
1161
+ const x = box.left - 8, bottom = sheetBox.bottom - box.top - 0.5;
1162
+ frame2.style.left = `${x - origin.left}px`;
1163
+ frame2.style.top = `${box.top - origin.top}px`;
1164
+ const viewport = ghost2 && !floating ? sheetBox : navBox, clipLeft = Math.max(-left, viewport.left - x), clipRight = Math.min(width + right, viewport.right - x);
1165
+ frame2.style.clipPath = `polygon(${clipLeft}px 0px, ${clipRight}px 0px, ${clipRight}px ${height - 1}px, ${width + right}px ${height - 1}px, ${width + right}px ${bottom + 1}px, ${-left}px ${bottom + 1}px, ${-left}px ${height - 1}px, ${clipLeft}px ${height - 1}px)`;
1166
+ pathData(
1167
+ frame2.querySelector("path"),
1168
+ paneShape(left, right, bottom, !!ghost2 && !floating, size) + ((!ghost2 || floating) && clipLeft > 0 ? ` M0 ${height - 0.5} H${Math.min(width, clipLeft)}` : "") + ((!ghost2 || floating) && clipRight < width ? ` M${Math.max(0, clipRight)} ${height - 0.5} H${width}` : "")
880
1169
  );
881
- ghost2.querySelector("svg > path").setAttribute("d", fill);
882
- ghost2.querySelector("[data-tab-outline]").setAttribute("d", outline);
883
- }
884
- const stroke = tab.querySelector("[data-tab-outline]");
885
- stroke.style.visibility = attached ? "hidden" : "visible";
886
- maskedOutline.current = stroke;
887
- frame2.style.visibility = attached ? "visible" : "hidden";
888
- if (!attached) return;
889
- sheet.style.borderColor = "transparent";
890
- maskedSheet.current = sheet;
891
- const x = box.left - 8, bottom = sheetBox.bottom - box.top - 0.5;
892
- const origin = frame2.parentElement.getBoundingClientRect();
893
- frame2.style.left = `${x - origin.left}px`;
894
- frame2.style.top = `${box.top - origin.top}px`;
895
- const viewport = ghost2 && !floating ? sheetBox : nav.getBoundingClientRect(), clipLeft = Math.max(-left, viewport.left - x), clipRight = Math.min(width + right, viewport.right - x);
896
- frame2.style.clipPath = `polygon(${clipLeft}px 0px, ${clipRight}px 0px, ${clipRight}px ${height - 1}px, ${width + right}px ${height - 1}px, ${width + right}px ${bottom + 1}px, ${-left}px ${bottom + 1}px, ${-left}px ${height - 1}px, ${clipLeft}px ${height - 1}px)`;
897
- frame2.querySelector("path").setAttribute(
898
- "d",
899
- paneShape(left, right, bottom, !!ghost2 && !floating, size) + ((!ghost2 || floating) && clipLeft > 0 ? ` M0 ${height - 0.5} H${Math.min(width, clipLeft)}` : "") + ((!ghost2 || floating) && clipRight < width ? ` M${Math.max(0, clipRight)} ${height - 0.5} H${width}` : "")
900
- );
1170
+ };
901
1171
  };
902
1172
  const animate = (element, from) => {
903
- const transform = getComputedStyle(element).transform;
904
- if (transform !== "none") from += new DOMMatrixReadOnly(transform).m41;
905
- element.getAnimations().forEach((animation) => animation.cancel());
906
- if (!matchMedia("(prefers-reduced-motion: reduce)").matches)
907
- element.animate(
1173
+ animations2.current.get(element)?.cancel();
1174
+ if (!matchMedia("(prefers-reduced-motion: reduce)").matches) {
1175
+ const animation = element.animate(
908
1176
  [{ transform: `translateX(${from}px)` }, { transform: "none" }],
909
1177
  motion
910
1178
  );
1179
+ animations2.current.set(element, animation);
1180
+ const remove = () => {
1181
+ if (animations2.current.get(element) === animation)
1182
+ animations2.current.delete(element);
1183
+ };
1184
+ animation.onfinish = remove;
1185
+ animation.oncancel = remove;
1186
+ }
911
1187
  };
912
- const settle = (key) => requestAnimationFrame(() => {
1188
+ const settle = (key2) => requestAnimationFrame(() => {
913
1189
  if (drag.current) return;
914
- reveal(key);
915
- const ghost2 = ghostRef.current, slot = tabElement(key);
1190
+ reveal(key2);
1191
+ const ghost2 = ghostRef.current, slot = tabElement(key2);
916
1192
  if (!ghost2 || !slot || matchMedia("(prefers-reduced-motion: reduce)").matches) {
917
1193
  setDragging(void 0);
918
1194
  return;
@@ -931,35 +1207,44 @@ function WorkspaceTabs({
931
1207
  latest.current.refresh();
932
1208
  });
933
1209
  const finish = (cancel = false) => {
1210
+ if (cancel) pointer.current.cancel();
1211
+ else pointer.current.flush();
934
1212
  const current = drag.current;
935
1213
  if (!current) return;
936
1214
  drag.current = void 0;
1215
+ pointer.current.cancel();
937
1216
  suppressClick.current = current.moved;
938
1217
  content.release();
939
1218
  if (cancel) {
940
1219
  docking.cancel();
941
- if (current.moved) onReorder(current.order);
942
1220
  announce("");
943
1221
  }
944
- if (current.moved && (cancel || !docking.drop())) settle(current.key);
1222
+ const dropped = !cancel && current.moved && docking.drop();
1223
+ if (!cancel && !dropped && current.previewOrder)
1224
+ onReorder(current.previewOrder);
1225
+ setDraftOrder(void 0);
1226
+ if (current.moved && !dropped) settle(current.key);
945
1227
  else setDragging(void 0);
946
1228
  };
947
- const move = (from, to) => {
948
- const order = links.map(([key]) => key), index = order.indexOf(to);
1229
+ const move = (from, to, preview = false) => {
1230
+ const order = links.map(([key2]) => key2), index = order.indexOf(to);
949
1231
  if (from === to || index < 0) return;
950
1232
  order.splice(order.indexOf(from), 1);
951
1233
  order.splice(index, 0, from);
952
- onReorder(order);
1234
+ if (preview && drag.current) {
1235
+ drag.current.previewOrder = order;
1236
+ setDraftOrder(order);
1237
+ } else onReorder(order);
953
1238
  announce(`${labels.get(from)}: position ${index + 1} of ${order.length}`);
954
1239
  };
955
- const focusTab = (key) => requestAnimationFrame(() => document.getElementById(ids.tab(key))?.focus());
956
- const split = (key, edge) => {
1240
+ const split = (key2, edge) => {
957
1241
  announce(
958
- docking.split(key, edge) ? `${labels.get(key)} split ${edge}` : "Open another tab or make this pane larger to split it"
1242
+ docking.split(key2, edge) ? `${labels.get(key2)} split ${edge}` : "Open another tab or make this pane larger to split it"
959
1243
  );
960
- focusTab(key);
1244
+ tabLinks.focus(key2);
961
1245
  };
962
- const keyDown = (event, key, index) => {
1246
+ const keyDown = (event, key2, index) => {
1247
+ if (hasOpenOverlay()) return;
963
1248
  if (event.key === "Escape") return finish(true);
964
1249
  const edges = {
965
1250
  ArrowLeft: "left",
@@ -968,9 +1253,9 @@ function WorkspaceTabs({
968
1253
  };
969
1254
  const edge = edges[event.key];
970
1255
  if (event.altKey && edge) {
971
- if (event.shiftKey) split(key, edge);
1256
+ if (event.shiftKey) split(key2, edge);
972
1257
  else if (edge !== "bottom")
973
- move(key, items[index + (edge === "left" ? -1 : 1)]?.key ?? key);
1258
+ move(key2, items[index + (edge === "left" ? -1 : 1)]?.key ?? key2);
974
1259
  else return;
975
1260
  } else {
976
1261
  if (event.altKey || event.ctrlKey || event.metaKey) return;
@@ -981,71 +1266,128 @@ function WorkspaceTabs({
981
1266
  ArrowRight: (index + 1) % items.length
982
1267
  };
983
1268
  const target = targets[event.key];
984
- if (target !== void 0)
985
- document.getElementById(ids.tab(items[target].key))?.focus();
986
- else if (event.key === "Delete") onClose(key);
987
- else if (event.key === " ") onSelect(key);
1269
+ if (target !== void 0) tabLinks.get(items[target].key)?.focus();
1270
+ else if (event.key === "Delete") onClose(key2);
1271
+ else if (event.key === " ") onSelect(key2);
988
1272
  else return;
989
1273
  }
990
1274
  event.preventDefault();
991
1275
  };
992
- const measure = () => {
1276
+ const readMetrics = () => {
993
1277
  const nav = navRef.current, strip = stripRef.current;
994
1278
  if (!nav || !strip || !dragBoundary) return;
995
- const trailing = strip.parentElement.nextElementSibling?.getBoundingClientRect().width ?? 0;
1279
+ const toolbarStyle = getComputedStyle(dragBoundary);
1280
+ const gap = parseFloat(toolbarStyle.columnGap) || 0;
1281
+ let trailing = parseFloat(toolbarStyle.paddingRight) || 0;
1282
+ for (let element = strip.parentElement.nextElementSibling; element; element = element.nextElementSibling)
1283
+ trailing += element.getBoundingClientRect().width + gap;
996
1284
  const availableWidth = Math.max(
997
1285
  0,
998
- dragBoundary.getBoundingClientRect().right - strip.getBoundingClientRect().left - trailing - 4
1286
+ dragBoundary.getBoundingClientRect().right - strip.getBoundingClientRect().left - trailing
999
1287
  );
1000
1288
  const inserting = docking.insertion === void 0 ? 0 : 1;
1001
1289
  const count = items.length - (drag.current?.detached ? 1 : 0) + inserting;
1290
+ const fittedWidth = fitTabWidth(
1291
+ density.width,
1292
+ availableWidth,
1293
+ items.length + inserting
1294
+ );
1002
1295
  const next = {
1003
- available: availableWidth,
1004
- overflow: count * fitTabWidth(density.width, availableWidth, items.length + inserting) + 16 > availableWidth + 1,
1296
+ width: fittedWidth,
1297
+ overflow: count * fittedWidth + 16 > availableWidth + 1,
1005
1298
  left: nav.scrollLeft > 1,
1006
1299
  right: nav.scrollLeft + nav.clientWidth < nav.scrollWidth - 1
1007
1300
  };
1008
1301
  const current = measured.current;
1009
- if (next.available !== current.available || next.overflow !== current.overflow || next.left !== current.left || next.right !== current.right) {
1010
- measured.current = next;
1011
- setMetrics(next);
1012
- }
1302
+ return () => {
1303
+ if (next.width !== current.width || next.overflow !== current.overflow || next.left !== current.left || next.right !== current.right) {
1304
+ measured.current = next;
1305
+ setMetrics(next);
1306
+ }
1307
+ };
1013
1308
  };
1014
- const follow = () => {
1015
- const nav = navRef.current;
1016
- if ([surface(), nav, ghostRef.current].some(
1017
- (element) => element?.getAnimations({ subtree: element === nav }).some((animation) => animation.playState === "running")
1018
- ))
1019
- frame.current = requestAnimationFrame(() => latest.current.refresh());
1309
+ const runningAnimations = () => {
1310
+ for (const target of transitions.current.keys())
1311
+ if (target instanceof Node && !target.isConnected)
1312
+ transitions.current.delete(target);
1313
+ return transitions.current.size > 0 || settling.current?.playState === "running" || [...animations2.current.values()].some(
1314
+ (animation) => animation.playState === "running"
1315
+ );
1020
1316
  };
1021
- const refresh = (resized = false) => {
1022
- cancelAnimationFrame(frame.current);
1023
- measure();
1024
- if (resized) reveal();
1025
- draw();
1026
- follow();
1317
+ const readFrame = (resized = false) => {
1318
+ const metrics2 = readMetrics();
1319
+ const scroll = resized ? readReveal() : void 0;
1320
+ const follow = runningAnimations();
1321
+ const draw = readDrawing(scroll?.delta);
1322
+ return () => {
1323
+ metrics2?.();
1324
+ scroll?.apply();
1325
+ draw();
1326
+ if (follow) geometry.schedule();
1327
+ };
1027
1328
  };
1028
- const latest = React.useRef({ refresh, finish });
1329
+ const refresh = (resized = false) => geometry.commit(resized);
1330
+ const movePointer = () => {
1331
+ const current = drag.current, nav = navRef.current;
1332
+ if (!current?.moved || !nav) return;
1333
+ current.detached = docking.move(current);
1334
+ if (!current.detached) {
1335
+ const { left, right } = nav.getBoundingClientRect();
1336
+ const scroll = current.x < left + 24 ? -16 : current.x > right - 24 ? 16 : 0;
1337
+ const before = nav.scrollLeft;
1338
+ if (scroll) nav.scrollLeft += scroll;
1339
+ const index = Math.max(
1340
+ 0,
1341
+ Math.min(
1342
+ items.length - 1,
1343
+ Math.floor(
1344
+ (Math.max(left + 8, Math.min(current.x, right - 8)) - left + nav.scrollLeft - 8) / tabWidth
1345
+ )
1346
+ )
1347
+ );
1348
+ move(current.key, items[index].key, true);
1349
+ if (scroll && before !== nav.scrollLeft)
1350
+ pointer.current.schedule(void 0);
1351
+ }
1352
+ geometry.flush();
1353
+ };
1354
+ const latest = React.useRef({ refresh, finish, movePointer, readFrame });
1355
+ const [geometry] = React.useState(
1356
+ () => geometryTask((resized) => latest.current.readFrame(resized))
1357
+ );
1358
+ const pointer = React.useRef(
1359
+ void 0
1360
+ );
1361
+ if (!pointer.current)
1362
+ pointer.current = frameTask(() => latest.current.movePointer());
1029
1363
  const detached = !!dragging && !!drag.current?.detached;
1030
1364
  React.useLayoutEffect(() => {
1031
- latest.current = { refresh, finish };
1365
+ latest.current = { refresh, finish, movePointer, readFrame };
1366
+ });
1367
+ React.useLayoutEffect(() => {
1032
1368
  const order = JSON.stringify([tabOrder, docking.insertion]);
1033
1369
  const previous = positions.current;
1034
1370
  positions.current = { order, tabs: /* @__PURE__ */ new Map() };
1035
- for (const element of navRef.current.children) {
1036
- const key = element.querySelector("a")?.dataset.tab;
1037
- if (!key) continue;
1038
- const left = element.offsetLeft, from = previous.tabs.get(key);
1039
- if (previous.order !== order && key !== dragging && from !== void 0 && from !== left)
1040
- animate(element, from - left);
1041
- positions.current.tabs.set(key, left);
1371
+ const slots = items.map(({ key: key2 }) => {
1372
+ const element = tabElement(key2);
1373
+ const left = element.offsetLeft, from = previous.tabs.get(key2);
1374
+ const displaced = previous.order !== order && key2 !== dragging && from !== void 0 && from !== left;
1375
+ const transform = displaced ? getComputedStyle(element).transform : "none";
1376
+ const offset = transform === "none" ? 0 : new DOMMatrixReadOnly(transform).m41;
1377
+ return {
1378
+ key: key2,
1379
+ element,
1380
+ left,
1381
+ delta: displaced ? from - left + offset : 0
1382
+ };
1383
+ });
1384
+ for (const { key: key2, element, left, delta } of slots) {
1385
+ if (delta) animate(element, delta);
1386
+ positions.current.tabs.set(key2, left);
1042
1387
  }
1043
- cancelAnimationFrame(frame.current);
1044
- draw();
1045
- follow();
1046
- });
1388
+ }, [tabOrder, docking.insertion, tabWidth, dragging, detached]);
1047
1389
  React.useLayoutEffect(
1048
- () => refresh(),
1390
+ () => refresh(true),
1049
1391
  // oxlint-disable-next-line react-hooks/exhaustive-deps -- the inputs refresh measures
1050
1392
  [
1051
1393
  dragBoundary,
@@ -1053,43 +1395,84 @@ function WorkspaceTabs({
1053
1395
  tabOrder,
1054
1396
  docking.insertion,
1055
1397
  tabWidth,
1398
+ density.width,
1056
1399
  height,
1057
1400
  metrics.overflow,
1058
1401
  dragging,
1059
1402
  detached
1060
1403
  ]
1061
1404
  );
1062
- React.useLayoutEffect(() => reveal(), [active, tabOrder, docking.insertion]);
1063
1405
  React.useLayoutEffect(() => {
1064
1406
  const nav = navRef.current;
1065
- const resize = () => latest.current.refresh(true), scroll = () => latest.current.refresh(), blur = () => latest.current.finish(true);
1407
+ const board = dragBoundary?.closest(".lab-board");
1408
+ const trackedTransitions = transitions.current;
1409
+ const transition = (event) => {
1410
+ const target = event.target;
1411
+ const name = event.propertyName;
1412
+ if ([
1413
+ "color",
1414
+ "background-color",
1415
+ "fill",
1416
+ "stroke",
1417
+ "opacity",
1418
+ "filter",
1419
+ "box-shadow"
1420
+ ].includes(name))
1421
+ return;
1422
+ if (event.type === "transitionrun") {
1423
+ if (target !== surface() && !(target instanceof Node && dragBoundary?.contains(target)))
1424
+ return;
1425
+ const properties = transitions.current.get(target) ?? /* @__PURE__ */ new Set();
1426
+ properties.add(name);
1427
+ transitions.current.set(target, properties);
1428
+ geometry.schedule();
1429
+ } else {
1430
+ const properties = transitions.current.get(target);
1431
+ properties?.delete(name);
1432
+ if (!properties?.size) transitions.current.delete(target);
1433
+ }
1434
+ };
1435
+ for (const name of ["transitionrun", "transitionend", "transitioncancel"])
1436
+ board?.addEventListener(name, transition);
1437
+ const scroll = () => latest.current.refresh(), blur = () => latest.current.finish(true);
1066
1438
  const wheel = (event) => {
1067
1439
  if (event.ctrlKey || Math.abs(event.deltaX) >= Math.abs(event.deltaY) || nav.scrollWidth <= nav.clientWidth)
1068
1440
  return;
1069
1441
  event.preventDefault();
1070
1442
  nav.scrollLeft += event.deltaY * (event.deltaMode === 1 ? 16 : event.deltaMode === 2 ? nav.clientWidth : 1);
1071
1443
  };
1072
- const observer = new ResizeObserver(resize);
1073
- for (const element of [
1074
- nav,
1075
- stripRef.current,
1076
- dragBoundary,
1077
- ...dragBoundary?.children ?? [],
1078
- surface()
1079
- ])
1080
- if (element) observer.observe(element);
1444
+ const unobserve = geometry.observe(
1445
+ [
1446
+ nav,
1447
+ stripRef.current,
1448
+ dragBoundary,
1449
+ ...dragBoundary?.children ?? [],
1450
+ surface()
1451
+ ].filter((element) => !!element)
1452
+ );
1081
1453
  addEventListener("scroll", scroll, true);
1082
1454
  addEventListener("blur", blur);
1083
1455
  nav.addEventListener("wheel", wheel, { passive: false });
1084
1456
  return () => {
1085
- observer.disconnect();
1457
+ for (const name of ["transitionrun", "transitionend", "transitioncancel"])
1458
+ board?.removeEventListener(name, transition);
1459
+ trackedTransitions.clear();
1460
+ unobserve();
1086
1461
  removeEventListener("scroll", scroll, true);
1087
1462
  removeEventListener("blur", blur);
1088
1463
  nav.removeEventListener("wheel", wheel);
1089
- cancelAnimationFrame(frame.current);
1464
+ geometry.cancel();
1090
1465
  restoreFrame();
1091
1466
  };
1092
1467
  }, [active, dragBoundary]);
1468
+ React.useEffect(
1469
+ () => () => {
1470
+ pointer.current.cancel();
1471
+ settling.current?.cancel();
1472
+ for (const animation of animations2.current.values()) animation.cancel();
1473
+ },
1474
+ []
1475
+ );
1093
1476
  const scrollButton = (direction) => metrics.overflow && /* @__PURE__ */ jsx4(
1094
1477
  "button",
1095
1478
  {
@@ -1121,6 +1504,8 @@ function WorkspaceTabs({
1121
1504
  onKeyDownCapture: () => setPointerFocus(false),
1122
1505
  onBlurCapture: () => setPointerFocus(false),
1123
1506
  onPointerDownCapture: () => {
1507
+ pointer.current.cancel();
1508
+ setDraftOrder(void 0);
1124
1509
  content.release(false);
1125
1510
  settling.current?.cancel();
1126
1511
  setDragging(void 0);
@@ -1141,111 +1526,100 @@ function WorkspaceTabs({
1141
1526
  if (!current.moved && Math.hypot(x - current.x, event.clientY - current.y) < 6)
1142
1527
  return;
1143
1528
  if (!current.moved && active !== current.key) onSelect(current.key);
1529
+ if (!current.moved) setDragging(current.key);
1144
1530
  current.moved = true;
1145
1531
  if (!nav.hasPointerCapture(event.pointerId))
1146
1532
  nav.setPointerCapture(event.pointerId);
1147
- setDragging(current.key);
1148
1533
  event.preventDefault();
1149
1534
  current.x = x;
1150
1535
  current.y = event.clientY;
1151
- current.detached = docking.move(current);
1152
- if (!current.detached) {
1153
- const { left, right } = nav.getBoundingClientRect();
1154
- nav.scrollLeft += x < left + 24 ? -16 : x > right - 24 ? 16 : 0;
1155
- const index = Math.max(
1156
- 0,
1157
- Math.min(
1158
- items.length - 1,
1159
- Math.floor(
1160
- (Math.max(left + 8, Math.min(x, right - 8)) - left + nav.scrollLeft - 8) / tabWidth
1161
- )
1162
- )
1163
- );
1164
- move(current.key, items[index].key);
1165
- }
1166
- refresh();
1536
+ pointer.current.schedule(void 0);
1167
1537
  },
1168
1538
  onPointerUp: () => finish(),
1169
1539
  onPointerCancel: () => finish(true),
1540
+ onLostPointerCapture: (event) => {
1541
+ if (event.target === event.currentTarget) finish(true);
1542
+ },
1170
1543
  className: "lab-tablist",
1171
1544
  children: [
1172
- links.map(([key, text], index) => {
1173
- const actions = [
1545
+ links.map(([key2, text], index) => {
1546
+ const actions = menu ? [
1174
1547
  ...onDuplicate ? [
1175
1548
  {
1176
1549
  label: "Duplicate tab",
1177
1550
  onSelect: () => {
1178
- menuFocus.current = onDuplicate(key);
1551
+ menuFocus.current = onDuplicate(key2);
1179
1552
  }
1180
1553
  }
1181
1554
  ] : [],
1182
1555
  {
1183
1556
  label: "Move left",
1184
- onSelect: () => move(key, items[index - 1].key),
1557
+ onSelect: () => move(key2, items[index - 1].key),
1185
1558
  disabled: !index
1186
1559
  },
1187
1560
  {
1188
1561
  label: "Move right",
1189
- onSelect: () => move(key, items[index + 1].key),
1562
+ onSelect: () => move(key2, items[index + 1].key),
1190
1563
  disabled: index === items.length - 1
1191
1564
  },
1192
1565
  {
1193
1566
  label: "Move to next pane",
1194
- onSelect: () => docking.next(key),
1567
+ onSelect: () => docking.next(key2),
1195
1568
  disabled: docking.paneCount < 2
1196
1569
  },
1197
1570
  null,
1198
1571
  ...["left", "right", "bottom"].map((edge) => ({
1199
1572
  label: `Split ${edge === "bottom" ? "below" : edge}`,
1200
- onSelect: () => split(key, edge),
1573
+ onSelect: () => split(key2, edge),
1201
1574
  disabled: items.length < 2
1202
1575
  })),
1203
1576
  null,
1204
- { label: "Close tab", onSelect: () => onClose(key) }
1205
- ];
1577
+ { label: "Close tab", onSelect: () => onClose(key2) }
1578
+ ] : [];
1206
1579
  const target = /* @__PURE__ */ jsxs3(
1207
1580
  "div",
1208
1581
  {
1209
1582
  role: "presentation",
1210
1583
  className: "lab-tab",
1211
- "data-dragging": dragging === key || void 0,
1584
+ "data-dragging": dragging === key2 || void 0,
1212
1585
  style: {
1213
1586
  paddingTop: height - contentHeight,
1214
- marginRight: dragging === key && drag.current?.detached ? -tabWidth : 0,
1587
+ marginRight: dragging === key2 && drag.current?.detached ? -tabWidth : 0,
1215
1588
  marginLeft: docking.insertion === index ? tabWidth : 0,
1216
- zIndex: active === key ? links.length + 1 : links.length - index
1589
+ zIndex: active === key2 ? links.length + 1 : links.length - index
1217
1590
  },
1218
1591
  children: [
1219
1592
  /* @__PURE__ */ jsx4(
1220
1593
  TabSurface,
1221
1594
  {
1222
1595
  width: tabWidth,
1223
- selected: active === key,
1596
+ selected: active === key2,
1224
1597
  keyboardFocus: !pointerFocus
1225
1598
  }
1226
1599
  ),
1227
1600
  /* @__PURE__ */ jsxs3(
1228
1601
  "a",
1229
1602
  {
1230
- id: ids.tab(key),
1603
+ ref: tabLinks.register(key2),
1604
+ id: ids.tab(key2),
1231
1605
  role: "tab",
1232
- tabIndex: active === key ? 0 : -1,
1233
- "aria-selected": active === key,
1234
- "aria-controls": ids.panel(key),
1606
+ tabIndex: active === key2 ? 0 : -1,
1607
+ "aria-selected": active === key2,
1608
+ "aria-controls": ids.panel(key2),
1235
1609
  href: items[index].href,
1236
- "data-tab": key,
1610
+ "data-tab": key2,
1237
1611
  style: { width: tabWidth, height: contentHeight },
1238
1612
  onClick: (event) => {
1239
1613
  const { metaKey, ctrlKey, shiftKey, altKey } = event;
1240
1614
  if (metaKey || ctrlKey || shiftKey || altKey) return;
1241
1615
  event.preventDefault();
1242
- onSelect(key);
1616
+ onSelect(key2);
1243
1617
  },
1244
- onFocus: () => onSelect(key),
1618
+ onFocus: () => onSelect(key2),
1245
1619
  draggable: false,
1246
1620
  title: text,
1247
1621
  "aria-keyshortcuts": "ArrowLeft ArrowRight Home End Delete Alt+ArrowLeft Alt+ArrowRight Alt+Shift+ArrowLeft Alt+Shift+ArrowRight Alt+Shift+ArrowDown",
1248
- onKeyDown: (event) => keyDown(event, key, index),
1622
+ onKeyDown: (event) => keyDown(event, key2, index),
1249
1623
  onPointerDown: (event) => {
1250
1624
  if (event.button !== 0 || !event.isPrimary) return;
1251
1625
  if (event.pointerType === "mouse") event.preventDefault();
@@ -1254,15 +1628,14 @@ function WorkspaceTabs({
1254
1628
  setPointerFocus(true);
1255
1629
  const box = event.currentTarget.parentElement.getBoundingClientRect();
1256
1630
  drag.current = {
1257
- key,
1631
+ key: key2,
1258
1632
  offset: event.clientX - box.left,
1259
1633
  offsetY: event.clientY - box.top,
1260
1634
  sheet: surface().getBoundingClientRect(),
1261
1635
  x: event.clientX,
1262
1636
  y: event.clientY,
1263
1637
  detached: false,
1264
- moved: false,
1265
- order: links.map(([path]) => path)
1638
+ moved: false
1266
1639
  };
1267
1640
  },
1268
1641
  className: "lab-tab-link",
@@ -1272,7 +1645,7 @@ function WorkspaceTabs({
1272
1645
  ]
1273
1646
  }
1274
1647
  ),
1275
- /* @__PURE__ */ jsx4(CloseTab, { label: text, onClick: () => onClose(key) })
1648
+ /* @__PURE__ */ jsx4(CloseTab, { label: text, onClick: () => onClose(key2) })
1276
1649
  ]
1277
1650
  }
1278
1651
  );
@@ -1280,11 +1653,11 @@ function WorkspaceTabs({
1280
1653
  target,
1281
1654
  actions,
1282
1655
  () => {
1283
- focusTab(menuFocus.current ?? key);
1656
+ tabLinks.focus(menuFocus.current ?? key2);
1284
1657
  menuFocus.current = void 0;
1285
1658
  },
1286
- key
1287
- ) : target }, key);
1659
+ key2
1660
+ ) : target }, key2);
1288
1661
  }),
1289
1662
  docking.insertion === items.length && /* @__PURE__ */ jsx4(
1290
1663
  "div",
@@ -1421,11 +1794,226 @@ function useUnsavedChanges(dirty) {
1421
1794
  }, [dirty, report]);
1422
1795
  }
1423
1796
 
1797
+ // tab-state.ts
1798
+ import * as React3 from "react";
1799
+ var key = /* @__PURE__ */ Symbol.for("labpane.tab-state");
1800
+ var registry = globalThis;
1801
+ var TabStateContext = registry[key] ??= React3.createContext(
1802
+ { active: true, visible: true }
1803
+ );
1804
+ function useTabActive() {
1805
+ return React3.useContext(TabStateContext).active;
1806
+ }
1807
+ function useTabVisible() {
1808
+ return React3.useContext(TabStateContext).visible;
1809
+ }
1810
+ function useTabVisibleRef() {
1811
+ const visible = useTabVisible();
1812
+ const ref = React3.useRef(visible);
1813
+ React3.useLayoutEffect(() => {
1814
+ ref.current = visible;
1815
+ }, [visible]);
1816
+ return ref;
1817
+ }
1818
+ function useShownOnce(visible) {
1819
+ const [shown, setShown] = React3.useState(visible);
1820
+ React3.useEffect(() => {
1821
+ if (visible) setShown(true);
1822
+ }, [visible]);
1823
+ return shown;
1824
+ }
1825
+
1826
+ // leave-tab.ts
1827
+ import { createContext as createContext4, useContext as useContext4, useLayoutEffect as useLayoutEffect6, useRef as useRef7 } from "react";
1828
+
1829
+ // tab-map.ts
1830
+ import { useLayoutEffect as useLayoutEffect5, useRef as useRef6 } from "react";
1831
+ function useTabMap(tabs) {
1832
+ const map = useRef6(/* @__PURE__ */ new Map());
1833
+ useLayoutEffect5(() => {
1834
+ for (const key2 of map.current.keys())
1835
+ if (!tabs.some((tab) => tab.key === key2)) map.current.delete(key2);
1836
+ }, [tabs]);
1837
+ return map.current;
1838
+ }
1839
+
1840
+ // leave-tab.ts
1841
+ function useOpeners(tabs, front) {
1842
+ const openers = useTabMap(tabs);
1843
+ const previous = useRef7({
1844
+ keys: /* @__PURE__ */ new Set()
1845
+ });
1846
+ useLayoutEffect6(() => {
1847
+ const keys = new Set(tabs.map((tab) => tab.key));
1848
+ const { keys: known, front: before } = previous.current;
1849
+ previous.current = { keys, front };
1850
+ if (before === void 0 || !keys.has(before)) return;
1851
+ for (const key2 of keys)
1852
+ if (key2 !== before && (!known.has(key2) || key2 === front))
1853
+ openers.set(key2, before);
1854
+ }, [tabs, front, openers]);
1855
+ return openers;
1856
+ }
1857
+ var LeaveTab = createContext4(() => {
1858
+ });
1859
+ function useLeaveTab() {
1860
+ return useContext4(LeaveTab);
1861
+ }
1862
+
1863
+ // tab-history.ts
1864
+ import { createContext as createContext5, useContext as useContext5, useSyncExternalStore } from "react";
1865
+ function createTabHistory(initial) {
1866
+ const paths = [initial];
1867
+ const listeners = /* @__PURE__ */ new Set();
1868
+ let index = 0;
1869
+ const go = (to) => {
1870
+ index = to;
1871
+ current = snapshot();
1872
+ listeners.forEach((listener) => listener());
1873
+ };
1874
+ const navigate = (path) => {
1875
+ if (path === paths[index]) return;
1876
+ paths.splice(index + 1, Infinity, path);
1877
+ go(index + 1);
1878
+ };
1879
+ const back = () => {
1880
+ if (index > 0) go(index - 1);
1881
+ };
1882
+ const forward = () => {
1883
+ if (index < paths.length - 1) go(index + 1);
1884
+ };
1885
+ const snapshot = () => ({
1886
+ path: paths[index],
1887
+ canGoBack: index > 0,
1888
+ canGoForward: index < paths.length - 1,
1889
+ navigate,
1890
+ back,
1891
+ forward
1892
+ });
1893
+ let current = snapshot();
1894
+ return {
1895
+ subscribe: (listener) => {
1896
+ listeners.add(listener);
1897
+ return () => {
1898
+ listeners.delete(listener);
1899
+ };
1900
+ },
1901
+ get: () => current
1902
+ };
1903
+ }
1904
+ var TabHistoryContext = createContext5(createTabHistory(""));
1905
+ function useTabHistory() {
1906
+ const store = useContext5(TabHistoryContext);
1907
+ return useSyncExternalStore(store.subscribe, store.get, store.get);
1908
+ }
1909
+ function useTabHistories(tabs) {
1910
+ const stores = useTabMap(tabs);
1911
+ return (tab) => {
1912
+ let store = stores.get(tab.key);
1913
+ if (!store) stores.set(tab.key, store = createTabHistory(tab.href ?? ""));
1914
+ return store;
1915
+ };
1916
+ }
1917
+
1918
+ // browser-history.ts
1919
+ import { useEffect as useEffect4, useLayoutEffect as useLayoutEffect7, useRef as useRef8 } from "react";
1920
+ var read = (state) => state?.labpane;
1921
+ function createBrowserHistory(front) {
1922
+ const session = Date.now();
1923
+ let serial = 0;
1924
+ let position2 = 0;
1925
+ let below = 0;
1926
+ let above = 0;
1927
+ let hopping = false;
1928
+ let queued = false;
1929
+ const mark = (serial2) => ({ labpane: { session, serial: serial2 } });
1930
+ const push = (path) => history.pushState(mark(++serial), "", path);
1931
+ const hop = () => {
1932
+ hopping = true;
1933
+ history.back();
1934
+ };
1935
+ const settle = () => {
1936
+ hopping = false;
1937
+ if (!queued) return;
1938
+ queued = false;
1939
+ sync();
1940
+ };
1941
+ const move = (to, direction) => {
1942
+ position2 = to;
1943
+ below = Math.max(0, below + direction);
1944
+ above = Math.max(0, above - direction);
1945
+ };
1946
+ function sync() {
1947
+ const tab = front();
1948
+ if (!tab) return;
1949
+ if (hopping) {
1950
+ queued = true;
1951
+ return;
1952
+ }
1953
+ history.replaceState(mark(position2), "", tab.path);
1954
+ if (tab.canGoBack && !below || !tab.canGoForward && above) {
1955
+ push(tab.path);
1956
+ position2 = serial;
1957
+ below += 1;
1958
+ above = 0;
1959
+ }
1960
+ if (tab.canGoForward && !above) {
1961
+ push(tab.path);
1962
+ above = 1;
1963
+ hop();
1964
+ }
1965
+ }
1966
+ function pop(event) {
1967
+ const landed = read(event.state);
1968
+ if (!landed) return;
1969
+ if (landed.session !== session) return history.back();
1970
+ if (landed.serial === position2) return settle();
1971
+ const tab = front();
1972
+ if (landed.serial > position2) {
1973
+ if (!tab?.canGoForward) {
1974
+ above += 1;
1975
+ queued = true;
1976
+ return hop();
1977
+ }
1978
+ move(landed.serial, 1);
1979
+ tab.forward();
1980
+ } else {
1981
+ move(landed.serial, -1);
1982
+ if (tab?.canGoBack) tab.back();
1983
+ else history.back();
1984
+ }
1985
+ }
1986
+ return { sync, pop };
1987
+ }
1988
+ function useBrowserHistory(front) {
1989
+ const latest = useRef8(front);
1990
+ useLayoutEffect7(() => {
1991
+ latest.current = front;
1992
+ });
1993
+ const browser = useRef8(
1994
+ void 0
1995
+ );
1996
+ useEffect4(() => {
1997
+ if (!front) return;
1998
+ const { sync, pop } = browser.current ??= createBrowserHistory(
1999
+ () => latest.current?.get()
2000
+ );
2001
+ addEventListener("popstate", pop);
2002
+ sync();
2003
+ const unsubscribe = front.subscribe(sync);
2004
+ return () => {
2005
+ unsubscribe();
2006
+ removeEventListener("popstate", pop);
2007
+ };
2008
+ }, [front]);
2009
+ }
2010
+
1424
2011
  // workspace.tsx
1425
2012
  import { Fragment as Fragment3, jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
1426
2013
  function Workspace(props) {
1427
2014
  const id = useId2();
1428
- return /* @__PURE__ */ jsx6(WorkspaceId.Provider, { value: id, children: /* @__PURE__ */ jsx6(WorkspaceDensity.Provider, { value: props.density ?? 100, children: /* @__PURE__ */ jsx6(WorkspaceContent, { ...props }) }) });
2015
+ const [links] = useState5(() => /* @__PURE__ */ new Map());
2016
+ return /* @__PURE__ */ jsx6(WorkspaceId.Provider, { value: id, children: /* @__PURE__ */ jsx6(TabLinks.Provider, { value: links, children: /* @__PURE__ */ jsx6(WorkspaceDensity.Provider, { value: props.density ?? 100, children: /* @__PURE__ */ jsx6(WorkspaceContent, { ...props }) }) }) });
1429
2017
  }
1430
2018
  function WorkspaceContent({
1431
2019
  density = 100,
@@ -1442,70 +2030,98 @@ function WorkspaceContent({
1442
2030
  confirmClose,
1443
2031
  layout,
1444
2032
  onLayoutChange: change,
2033
+ history: history2,
1445
2034
  className,
1446
2035
  children,
1447
2036
  empty
1448
2037
  }) {
1449
- const ids = useWorkspaceIds();
2038
+ const links = useTabLinks();
2039
+ const tabsByKey = useMemo3(
2040
+ () => new Map(tabs.map((tab) => [tab.key, tab])),
2041
+ [tabs]
2042
+ );
1450
2043
  const { height, contentHeight, logoSize } = useTabSize();
1451
- const corner2 = useRef5(null);
1452
- const [reserve, setReserve] = useState4(0);
2044
+ const corner2 = useRef9(null);
2045
+ const [reserve, setReserve] = useState5(0);
1453
2046
  const hasTrailing = !!trailing;
1454
- useLayoutEffect4(() => {
2047
+ useLayoutEffect8(() => {
1455
2048
  const element = corner2.current;
1456
2049
  if (!element) return setReserve(0);
1457
- const observer = new ResizeObserver(() => setReserve(element.offsetWidth));
1458
- observer.observe(element);
1459
- return () => observer.disconnect();
2050
+ const observer2 = new ResizeObserver(() => setReserve(element.offsetWidth));
2051
+ observer2.observe(element);
2052
+ return () => observer2.disconnect();
1460
2053
  }, [hasTrailing]);
1461
- const root = useRef5(null);
1462
- const [inset, setInset] = useState4(0);
1463
- useLayoutEffect4(() => {
2054
+ const root = useRef9(null);
2055
+ const [inset, setInset] = useState5(0);
2056
+ useLayoutEffect8(() => {
1464
2057
  if (!titleBar) return setInset(0);
1465
2058
  const measure = () => setInset(root.current.getBoundingClientRect().top);
1466
2059
  measure();
1467
2060
  addEventListener("resize", measure);
1468
2061
  return () => removeEventListener("resize", measure);
1469
2062
  }, [titleBar]);
1470
- const preferredPane = useRef5(void 0);
2063
+ const preferredPane = useRef9(void 0);
1471
2064
  const visibleLayout = reconcileLayout(
1472
2065
  layout,
1473
2066
  tabs.map((t) => t.key),
1474
2067
  active,
1475
2068
  preferredPane.current
1476
2069
  );
1477
- useLayoutEffect4(() => {
2070
+ useLayoutEffect8(() => {
1478
2071
  if (visibleLayout !== layout) change(visibleLayout);
1479
2072
  }, [visibleLayout, layout]);
1480
- const dirty = useRef5(/* @__PURE__ */ new Map());
1481
- useEffect2(() => {
2073
+ const front = active ?? panes(visibleLayout)[0]?.active;
2074
+ const openers = useOpeners(tabs, front);
2075
+ const historyOf = useTabHistories(tabs);
2076
+ const frontTab = tabsByKey.get(front ?? "");
2077
+ useBrowserHistory(history2 && frontTab ? historyOf(frontTab) : void 0);
2078
+ const dirty = useRef9(/* @__PURE__ */ new Map());
2079
+ useEffect5(() => {
1482
2080
  const warn = (event) => {
1483
2081
  if (dirty.current.size) event.preventDefault();
1484
2082
  };
1485
2083
  addEventListener("beforeunload", warn);
1486
2084
  return () => removeEventListener("beforeunload", warn);
1487
2085
  }, []);
1488
- function close(key) {
1489
- const pane = panes(visibleLayout).find((p) => p.tabs.includes(key));
2086
+ function close(key2, next) {
2087
+ const pane = panes(visibleLayout).find((p) => p.tabs.includes(key2));
1490
2088
  if (!pane) return;
1491
- const remaining = pane.tabs.filter((k) => k !== key);
1492
- const opener = tabs.find((tab) => tab.key === key)?.opener;
1493
- const neighbor = remaining.find((key2) => key2 === opener) ?? remaining[Math.min(pane.tabs.indexOf(key), remaining.length - 1)] ?? tabs.find((t) => t.key !== key)?.key;
1494
- onClose(key, neighbor);
2089
+ const remaining = pane.tabs.filter((k) => k !== key2);
2090
+ const opener = tabsByKey.get(key2)?.opener;
2091
+ const neighbor = next ?? remaining.find((key3) => key3 === opener) ?? remaining[Math.min(pane.tabs.indexOf(key2), remaining.length - 1)] ?? tabs.find((t) => t.key !== key2)?.key;
2092
+ onClose(key2, neighbor);
1495
2093
  requestAnimationFrame(
1496
- () => (document.getElementById(
1497
- ids.tab(key === pane.active ? neighbor ?? "" : pane.active ?? "")
2094
+ () => (links.get(
2095
+ key2 === pane.active ? neighbor ?? "" : pane.active ?? ""
1498
2096
  ) ?? root.current?.querySelector(
1499
2097
  ".lab-toolbar-end button, [data-pane-sheet]"
1500
2098
  ))?.focus({ preventScroll: true })
1501
2099
  );
1502
2100
  }
1503
- const focus = (key) => requestAnimationFrame(() => document.getElementById(ids.tab(key))?.focus());
2101
+ function requestClose(key2, next) {
2102
+ if (![...dirty.current.values()].includes(key2)) return close(key2, next);
2103
+ const tab = tabsByKey.get(key2);
2104
+ const element = links.get(key2);
2105
+ Promise.resolve(
2106
+ confirmClose ? confirmClose(tab) : confirm(`Discard changes in ${tab.label}?`)
2107
+ ).then((discard) => {
2108
+ if (discard) close(key2, next);
2109
+ else requestAnimationFrame(() => element?.focus());
2110
+ });
2111
+ }
2112
+ function leave(key2) {
2113
+ const opener = openers.get(key2) ?? tabsByKey.get(key2)?.opener;
2114
+ requestClose(key2, tabsByKey.has(opener ?? "") ? opener : void 0);
2115
+ }
2116
+ const services = useRef9(leave);
2117
+ useLayoutEffect8(() => {
2118
+ services.current = leave;
2119
+ });
1504
2120
  const paneOf = (pane) => ({
1505
2121
  id: pane.id,
1506
2122
  tabs: pane.tabs,
1507
2123
  active: pane.active,
1508
- focus
2124
+ focus: links.focus
1509
2125
  });
1510
2126
  return /* @__PURE__ */ jsx6(Fragment3, { children: /* @__PURE__ */ jsxs5(
1511
2127
  "div",
@@ -1523,7 +2139,7 @@ function WorkspaceContent({
1523
2139
  },
1524
2140
  className: className ? `lab-workspace ${className}` : "lab-workspace",
1525
2141
  onKeyDown: (event) => {
1526
- if (event.key !== "F6") return;
2142
+ if (event.key !== "F6" || hasOpenOverlay()) return;
1527
2143
  event.preventDefault();
1528
2144
  const selected = Array.from(
1529
2145
  event.currentTarget.querySelectorAll(
@@ -1558,11 +2174,11 @@ function WorkspaceContent({
1558
2174
  },
1559
2175
  docking,
1560
2176
  surface,
1561
- items: pane.tabs.map((key) => tabs.find((t) => t.key === key)),
2177
+ items: pane.tabs.map((key2) => tabsByKey.get(key2)),
1562
2178
  active: pane.active,
1563
2179
  onSelect,
1564
- onDuplicate: onDuplicate ? (key) => {
1565
- const copy = onDuplicate(key), index = pane.tabs.indexOf(key) + 1;
2180
+ onDuplicate: onDuplicate ? (key2) => {
2181
+ const copy = onDuplicate(key2), index = pane.tabs.indexOf(key2) + 1;
1566
2182
  change(
1567
2183
  updateLayout(visibleLayout, pane.id, () => ({
1568
2184
  ...pane,
@@ -1576,18 +2192,7 @@ function WorkspaceContent({
1576
2192
  );
1577
2193
  return copy;
1578
2194
  } : void 0,
1579
- onClose: (key) => {
1580
- if (![...dirty.current.values()].includes(key))
1581
- return close(key);
1582
- const tab = tabs.find((tab2) => tab2.key === key);
1583
- const element = document.getElementById(ids.tab(key));
1584
- Promise.resolve(
1585
- confirmClose ? confirmClose(tab) : confirm(`Discard changes in ${tab.label}?`)
1586
- ).then((discard) => {
1587
- if (discard) close(key);
1588
- else requestAnimationFrame(() => element?.focus());
1589
- });
1590
- },
2195
+ onClose: requestClose,
1591
2196
  onReorder: (keys) => change(
1592
2197
  updateLayout(visibleLayout, pane.id, (node) => ({
1593
2198
  ...node,
@@ -1601,11 +2206,12 @@ function WorkspaceContent({
1601
2206
  const region = regions.find(
1602
2207
  (r) => r.pane.tabs.includes(tab.key)
1603
2208
  );
2209
+ const hidden = tab.key !== region.pane.active && tab.key !== lifted;
1604
2210
  return /* @__PURE__ */ jsx6(
1605
2211
  TabPanel,
1606
2212
  {
1607
2213
  tab,
1608
- hidden: tab.key !== region.pane.active && tab.key !== lifted,
2214
+ hidden,
1609
2215
  pane: region.pane.id,
1610
2216
  box: region.box,
1611
2217
  transition,
@@ -1614,10 +2220,17 @@ function WorkspaceContent({
1614
2220
  if (active !== tab.key) onSelect(tab.key);
1615
2221
  },
1616
2222
  children: /* @__PURE__ */ jsx6(
1617
- UnsavedChanges.Provider,
2223
+ TabBody,
1618
2224
  {
1619
- value: (source, changed) => changed ? dirty.current.set(source, tab.key) : dirty.current.delete(source),
1620
- children: children(tab, paneOf(region.pane))
2225
+ tab,
2226
+ pane: region.pane,
2227
+ focus: links.focus,
2228
+ active: tab.key === front,
2229
+ visible: !hidden,
2230
+ history: historyOf(tab),
2231
+ services,
2232
+ dirty: dirty.current,
2233
+ render: children
1621
2234
  }
1622
2235
  )
1623
2236
  },
@@ -1641,6 +2254,39 @@ function WorkspaceContent({
1641
2254
  }
1642
2255
  ) });
1643
2256
  }
2257
+ var TabBody = memo3(function TabBody2({
2258
+ tab,
2259
+ pane,
2260
+ focus,
2261
+ active,
2262
+ visible,
2263
+ history: history2,
2264
+ services,
2265
+ dirty,
2266
+ render
2267
+ }) {
2268
+ const key2 = tab.key;
2269
+ const [leave] = useState5(() => () => services.current(key2));
2270
+ const report = useCallback2(
2271
+ (source, changed) => {
2272
+ if (changed) dirty.set(source, key2);
2273
+ else dirty.delete(source);
2274
+ },
2275
+ [dirty, key2]
2276
+ );
2277
+ const requested = useMemo3(
2278
+ () => ({ render, tab, pane, focus }),
2279
+ [render, tab, pane, focus]
2280
+ );
2281
+ const deferred = useDeferredValue(requested);
2282
+ const inputs = visible ? requested : deferred;
2283
+ const content = useMemo3(
2284
+ () => inputs.render(inputs.tab, { ...inputs.pane, focus: inputs.focus }),
2285
+ [inputs]
2286
+ );
2287
+ const state = useMemo3(() => ({ active, visible }), [active, visible]);
2288
+ return /* @__PURE__ */ jsx6(TabStateContext.Provider, { value: state, children: /* @__PURE__ */ jsx6(LeaveTab.Provider, { value: leave, children: /* @__PURE__ */ jsx6(TabHistoryContext.Provider, { value: history2, children: /* @__PURE__ */ jsx6(UnsavedChanges.Provider, { value: report, children: content }) }) }) });
2289
+ });
1644
2290
  function TabPanel({
1645
2291
  tab,
1646
2292
  hidden,
@@ -1652,8 +2298,8 @@ function TabPanel({
1652
2298
  }) {
1653
2299
  const ids = useWorkspaceIds();
1654
2300
  const { height, borderWidth } = useTabSize();
1655
- const viewport = useRef5(null);
1656
- useLayoutEffect4(() => {
2301
+ const viewport = useRef9(null);
2302
+ useLayoutEffect8(() => {
1657
2303
  viewport.current?.scrollTo(0, 0);
1658
2304
  }, [tab?.scrollKey]);
1659
2305
  return (
@@ -1696,9 +2342,9 @@ function TabPanel({
1696
2342
 
1697
2343
  // workspace-frame.tsx
1698
2344
  import {
1699
- useLayoutEffect as useLayoutEffect5,
1700
- useRef as useRef6,
1701
- useState as useState5
2345
+ useLayoutEffect as useLayoutEffect9,
2346
+ useRef as useRef10,
2347
+ useState as useState6
1702
2348
  } from "react";
1703
2349
  import { jsx as jsx7, jsxs as jsxs6 } from "react/jsx-runtime";
1704
2350
  function WorkspaceFrame({
@@ -1706,25 +2352,25 @@ function WorkspaceFrame({
1706
2352
  change,
1707
2353
  children
1708
2354
  }) {
1709
- const viewport = useRef6(null);
1710
- const drag = useRef6(void 0);
1711
- const [available, setAvailable] = useState5(0);
1712
- const [draft, setDraft] = useState5();
2355
+ const viewport = useRef10(null);
2356
+ const drag = useRef10(void 0);
2357
+ const [available, setAvailable] = useState6(0);
2358
+ const [draft, setDraft] = useState6();
1713
2359
  const compact = Math.min(1600, available);
1714
2360
  const width = draft ?? (expanded ? available : compact);
1715
2361
  const cancel = () => {
1716
2362
  drag.current = void 0;
1717
2363
  setDraft(void 0);
1718
2364
  };
1719
- useLayoutEffect5(() => {
1720
- const observer = new ResizeObserver(() => {
2365
+ useLayoutEffect9(() => {
2366
+ const observer2 = new ResizeObserver(() => {
1721
2367
  setAvailable(viewport.current.clientWidth);
1722
2368
  cancel();
1723
2369
  });
1724
- observer.observe(viewport.current);
2370
+ observer2.observe(viewport.current);
1725
2371
  addEventListener("blur", cancel);
1726
2372
  return () => {
1727
- observer.disconnect();
2373
+ observer2.disconnect();
1728
2374
  removeEventListener("blur", cancel);
1729
2375
  };
1730
2376
  }, []);
@@ -1803,10 +2449,10 @@ function WorkspaceFrame({
1803
2449
 
1804
2450
  // window.tsx
1805
2451
  import {
1806
- useEffect as useEffect3,
1807
- useLayoutEffect as useLayoutEffect6,
1808
- useRef as useRef7,
1809
- useState as useState6
2452
+ useEffect as useEffect6,
2453
+ useLayoutEffect as useLayoutEffect10,
2454
+ useRef as useRef11,
2455
+ useState as useState7
1810
2456
  } from "react";
1811
2457
  import { Fragment as Fragment4, jsx as jsx8, jsxs as jsxs7 } from "react/jsx-runtime";
1812
2458
  var client = typeof window !== "undefined";
@@ -1820,8 +2466,8 @@ var setFullscreen = (host, on) => {
1820
2466
  var interactive = "a, button, input, select, textarea, label, summary, [contenteditable], [role=button], [role=tab], [role=separator], [role=menuitem], .lab-tab";
1821
2467
  var draggable = (target) => target instanceof Element && !target.closest(interactive) && (!!target.closest(".lab-toolbar, [data-window-drag]") || target.matches(".lab-workspace") || !!target.querySelector(".lab-workspace"));
1822
2468
  function useFullscreen(host) {
1823
- const [full, setFull] = useState6(() => isFullscreen(host));
1824
- useEffect3(() => {
2469
+ const [full, setFull] = useState7(() => isFullscreen(host));
2470
+ useEffect6(() => {
1825
2471
  const update = () => setFull(isFullscreen(host));
1826
2472
  update();
1827
2473
  window.addEventListener("resize", update);
@@ -1834,7 +2480,7 @@ function useFullscreen(host) {
1834
2480
  return [full, (on) => setFullscreen(host, on)];
1835
2481
  }
1836
2482
  function useWindowFrame(host) {
1837
- useEffect3(() => {
2483
+ useEffect6(() => {
1838
2484
  if (!host) return;
1839
2485
  const root = document.documentElement;
1840
2486
  let armed = false;
@@ -1870,7 +2516,7 @@ function useWindowFrame(host) {
1870
2516
  const dblclick = (event) => {
1871
2517
  if (draggable(event.target)) host.toggleMaximize();
1872
2518
  };
1873
- const key = (event) => {
2519
+ const key2 = (event) => {
1874
2520
  const shortcut = host.platform === "macos" ? event.ctrlKey && event.metaKey && event.code === "KeyF" : event.key === "F11";
1875
2521
  if (!host.fullscreen || !shortcut) return;
1876
2522
  event.preventDefault();
@@ -1880,13 +2526,13 @@ function useWindowFrame(host) {
1880
2526
  window.addEventListener("mousedown", down);
1881
2527
  window.addEventListener("mouseup", up);
1882
2528
  window.addEventListener("dblclick", dblclick);
1883
- window.addEventListener("keydown", key);
2529
+ window.addEventListener("keydown", key2);
1884
2530
  return () => {
1885
2531
  window.removeEventListener("mousemove", move);
1886
2532
  window.removeEventListener("mousedown", down);
1887
2533
  window.removeEventListener("mouseup", up);
1888
2534
  window.removeEventListener("dblclick", dblclick);
1889
- window.removeEventListener("keydown", key);
2535
+ window.removeEventListener("keydown", key2);
1890
2536
  if (cursor) root.style.cursor = "";
1891
2537
  };
1892
2538
  }, [host]);
@@ -1906,9 +2552,9 @@ var glyph = (children) => /* @__PURE__ */ jsx8(
1906
2552
  );
1907
2553
  function TrafficLights({ host }) {
1908
2554
  const [full] = useFullscreen(host);
1909
- const spacer = useRef7(null);
2555
+ const spacer = useRef11(null);
1910
2556
  const shown = host.platform === "macos" && !full;
1911
- useLayoutEffect6(() => {
2557
+ useLayoutEffect10(() => {
1912
2558
  const element = spacer.current;
1913
2559
  const toolbar = element?.closest(".lab-toolbar");
1914
2560
  if (!element || !toolbar || !host.trafficLights) return;
@@ -1920,9 +2566,9 @@ function TrafficLights({ host }) {
1920
2566
  element.style.width = `${end - element.getBoundingClientRect().left - gap}px`;
1921
2567
  };
1922
2568
  place();
1923
- const observer = new ResizeObserver(place);
1924
- observer.observe(toolbar);
1925
- return () => observer.disconnect();
2569
+ const observer2 = new ResizeObserver(place);
2570
+ observer2.observe(toolbar);
2571
+ return () => observer2.disconnect();
1926
2572
  }, [host, shown]);
1927
2573
  return shown ? /* @__PURE__ */ jsx8("div", { ref: spacer, className: "lab-traffic-lights" }) : null;
1928
2574
  }
@@ -1935,16 +2581,16 @@ function desktopSlots(host, menu) {
1935
2581
  }
1936
2582
  function WindowControls({ host }) {
1937
2583
  const [full] = useFullscreen(host);
1938
- const [max, setMax] = useState6(maximized);
1939
- const [top, setTop] = useState6(0);
1940
- const spacer = useRef7(null);
2584
+ const [max, setMax] = useState7(maximized);
2585
+ const [top, setTop] = useState7(0);
2586
+ const spacer = useRef11(null);
1941
2587
  const hidden = host.platform === "macos" || full;
1942
2588
  const measure = () => {
1943
2589
  setMax(maximized());
1944
2590
  if (spacer.current) setTop(spacer.current.getBoundingClientRect().top);
1945
2591
  };
1946
- useLayoutEffect6(measure);
1947
- useEffect3(() => {
2592
+ useLayoutEffect10(measure);
2593
+ useEffect6(() => {
1948
2594
  window.addEventListener("resize", measure);
1949
2595
  return () => window.removeEventListener("resize", measure);
1950
2596
  }, []);
@@ -2002,10 +2648,17 @@ export {
2002
2648
  densitySize,
2003
2649
  desktopSlots,
2004
2650
  dockTab,
2651
+ hasOpenOverlay,
2005
2652
  panes,
2006
2653
  reconcileLayout,
2007
2654
  restoreLayout,
2008
2655
  useFullscreen,
2656
+ useLeaveTab,
2657
+ useShownOnce,
2658
+ useTabActive,
2659
+ useTabHistory,
2660
+ useTabVisible,
2661
+ useTabVisibleRef,
2009
2662
  useUnsavedChanges,
2010
2663
  useWindowFrame
2011
2664
  };