@destyler/splitter 0.0.3 → 0.0.5

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.
@@ -1,16 +1,2013 @@
1
1
  'use strict';
2
2
 
3
- const index = require('./index.cjs');
4
- require('vue');
5
- require('@destyler/primitive');
6
- require('@destyler/shared');
7
- require('@destyler/composition');
8
- require('@destyler/directives');
9
- require('nanoid/non-secure');
3
+ const vue = require('vue');
4
+ const primitive = require('@destyler/primitive');
5
+ const shared = require('@destyler/shared');
6
+ const composition = require('@destyler/composition');
10
7
 
8
+ function assert(expectedCondition, message = "Assertion failed!") {
9
+ if (!expectedCondition) {
10
+ console.error(message);
11
+ throw new Error(message);
12
+ }
13
+ }
11
14
 
15
+ function getPanelGroupElement(id, rootElement = document) {
16
+ if (!shared.isBrowser)
17
+ return null;
18
+ if (rootElement instanceof HTMLElement && rootElement?.dataset?.panelGroupId === id) {
19
+ return rootElement;
20
+ }
21
+ const element = rootElement.querySelector(
22
+ `[data-panel-group][data-panel-group-id="${id}"]`
23
+ );
24
+ if (element)
25
+ return element;
26
+ return null;
27
+ }
28
+ function getResizeHandleElement(id, scope = document) {
29
+ if (!shared.isBrowser)
30
+ return null;
31
+ const element = scope.querySelector(`[data-panel-resize-handle-id="${id}"]`);
32
+ if (element)
33
+ return element;
34
+ return null;
35
+ }
36
+ function getResizeHandleElementIndex(groupId, id, scope = document) {
37
+ if (!shared.isBrowser)
38
+ return null;
39
+ const handles = getResizeHandleElementsForGroup(groupId, scope);
40
+ const index = handles.findIndex(
41
+ (handle) => handle.getAttribute("data-panel-resize-handle-id") === id
42
+ );
43
+ return index ?? null;
44
+ }
45
+ function getResizeHandleElementsForGroup(groupId, scope = document) {
46
+ if (!shared.isBrowser)
47
+ return [];
48
+ return Array.from(
49
+ scope.querySelectorAll(
50
+ `[data-panel-resize-handle-id][data-panel-group-id="${groupId}"]`
51
+ )
52
+ );
53
+ }
54
+ function getResizeHandlePanelIds(groupId, handleId, panelsArray, scope = document) {
55
+ const handle = getResizeHandleElement(handleId, scope);
56
+ const handles = getResizeHandleElementsForGroup(groupId, scope);
57
+ const index = handle ? handles.indexOf(handle) : -1;
58
+ const idBefore = panelsArray[index]?.id ?? null;
59
+ const idAfter = panelsArray[index + 1]?.id ?? null;
60
+ return [idBefore, idAfter];
61
+ }
12
62
 
13
- exports.DestylerSplitterGroup = index.DestylerSplitterGroup;
14
- exports.DestylerSplitterPanel = index.DestylerSplitterPanel;
15
- exports.DestylerSplitterResizeHandle = index.DestylerSplitterResizeHandle;
16
- exports.DestylerSplitterRoot = index.DestylerSplitterRoot;
63
+ function useWindowSplitterResizeHandlerBehavior({
64
+ disabled,
65
+ handleId,
66
+ resizeHandler,
67
+ panelGroupElement
68
+ }) {
69
+ vue.watchEffect((onCleanup) => {
70
+ const _panelGroupElement = panelGroupElement.value;
71
+ if (disabled.value || resizeHandler.value === null || _panelGroupElement === null)
72
+ return;
73
+ const handleElement = getResizeHandleElement(handleId, _panelGroupElement);
74
+ if (handleElement == null)
75
+ return;
76
+ const onKeyDown = (event) => {
77
+ if (event.defaultPrevented)
78
+ return;
79
+ switch (event.key) {
80
+ case "ArrowDown":
81
+ case "ArrowLeft":
82
+ case "ArrowRight":
83
+ case "ArrowUp":
84
+ case "End":
85
+ case "Home": {
86
+ event.preventDefault();
87
+ resizeHandler.value?.(event);
88
+ break;
89
+ }
90
+ case "F6": {
91
+ event.preventDefault();
92
+ const groupId = handleElement.getAttribute("data-panel-group-id");
93
+ assert(groupId);
94
+ const handles = getResizeHandleElementsForGroup(
95
+ groupId,
96
+ _panelGroupElement
97
+ );
98
+ const index = getResizeHandleElementIndex(
99
+ groupId,
100
+ handleId,
101
+ _panelGroupElement
102
+ );
103
+ assert(index !== null);
104
+ const nextIndex = event.shiftKey ? index > 0 ? index - 1 : handles.length - 1 : index + 1 < handles.length ? index + 1 : 0;
105
+ const nextHandle = handles[nextIndex];
106
+ nextHandle.focus();
107
+ break;
108
+ }
109
+ }
110
+ };
111
+ handleElement.addEventListener("keydown", onKeyDown);
112
+ onCleanup(() => {
113
+ handleElement.removeEventListener("keydown", onKeyDown);
114
+ });
115
+ });
116
+ }
117
+
118
+ let currentCursorStyle = null;
119
+ let styleElement = null;
120
+ function getCursorStyle(state, constraintFlags) {
121
+ if (constraintFlags) {
122
+ const horizontalMin = (constraintFlags & EXCEEDED_HORIZONTAL_MIN) !== 0;
123
+ const horizontalMax = (constraintFlags & EXCEEDED_HORIZONTAL_MAX) !== 0;
124
+ const verticalMin = (constraintFlags & EXCEEDED_VERTICAL_MIN) !== 0;
125
+ const verticalMax = (constraintFlags & EXCEEDED_VERTICAL_MAX) !== 0;
126
+ if (horizontalMin) {
127
+ if (verticalMin)
128
+ return "se-resize";
129
+ else if (verticalMax)
130
+ return "ne-resize";
131
+ else
132
+ return "e-resize";
133
+ } else if (horizontalMax) {
134
+ if (verticalMin)
135
+ return "sw-resize";
136
+ else if (verticalMax)
137
+ return "nw-resize";
138
+ else
139
+ return "w-resize";
140
+ } else if (verticalMin) {
141
+ return "s-resize";
142
+ } else if (verticalMax) {
143
+ return "n-resize";
144
+ }
145
+ }
146
+ switch (state) {
147
+ case "horizontal":
148
+ return "ew-resize";
149
+ case "intersection":
150
+ return "move";
151
+ case "vertical":
152
+ return "ns-resize";
153
+ }
154
+ }
155
+ function resetGlobalCursorStyle() {
156
+ if (styleElement !== null) {
157
+ document.head.removeChild(styleElement);
158
+ currentCursorStyle = null;
159
+ styleElement = null;
160
+ }
161
+ }
162
+ function setGlobalCursorStyle(state, constraintFlags) {
163
+ const style = getCursorStyle(state, constraintFlags);
164
+ if (currentCursorStyle === style)
165
+ return;
166
+ currentCursorStyle = style;
167
+ if (styleElement === null) {
168
+ styleElement = document.createElement("style");
169
+ document.head.appendChild(styleElement);
170
+ }
171
+ styleElement.innerHTML = `*{cursor: ${style}!important;}`;
172
+ }
173
+ function computePanelFlexBoxStyle({
174
+ defaultSize,
175
+ dragState,
176
+ layout,
177
+ panelData,
178
+ panelIndex,
179
+ precision = 3
180
+ }) {
181
+ const size = layout[panelIndex];
182
+ let flexGrow;
183
+ if (size == null) {
184
+ flexGrow = defaultSize !== void 0 ? defaultSize.toPrecision(precision) : "1";
185
+ } else if (panelData.length === 1) {
186
+ flexGrow = "1";
187
+ } else {
188
+ flexGrow = size.toPrecision(precision);
189
+ }
190
+ return {
191
+ flexBasis: 0,
192
+ flexGrow,
193
+ flexShrink: 1,
194
+ overflow: "hidden",
195
+ pointerEvents: dragState !== null ? "none" : void 0
196
+ };
197
+ }
198
+
199
+ function isKeyDown(event) {
200
+ return event.type === "keydown";
201
+ }
202
+ function isMouseEvent(event) {
203
+ return event.type.startsWith("mouse");
204
+ }
205
+ function isTouchEvent(event) {
206
+ return event.type.startsWith("touch");
207
+ }
208
+ function getResizeEventCoordinates(event) {
209
+ if (isMouseEvent(event)) {
210
+ return {
211
+ x: event.clientX,
212
+ y: event.clientY
213
+ };
214
+ } else if (isTouchEvent(event)) {
215
+ const touch = event.touches[0];
216
+ if (touch && touch.clientX && touch.clientY) {
217
+ return {
218
+ x: touch.clientX,
219
+ y: touch.clientY
220
+ };
221
+ }
222
+ }
223
+ return {
224
+ x: Number.POSITIVE_INFINITY,
225
+ y: Number.POSITIVE_INFINITY
226
+ };
227
+ }
228
+ function getResizeEventCursorPosition(direction, event) {
229
+ const isHorizontal = direction === "horizontal";
230
+ const { x, y } = getResizeEventCoordinates(event);
231
+ return isHorizontal ? x : y;
232
+ }
233
+
234
+ function intersects(rectOne, rectTwo, strict) {
235
+ if (strict) {
236
+ return rectOne.x < rectTwo.x + rectTwo.width && rectOne.x + rectOne.width > rectTwo.x && rectOne.y < rectTwo.y + rectTwo.height && rectOne.y + rectOne.height > rectTwo.y;
237
+ } else {
238
+ return rectOne.x <= rectTwo.x + rectTwo.width && rectOne.x + rectOne.width >= rectTwo.x && rectOne.y <= rectTwo.y + rectTwo.height && rectOne.y + rectOne.height >= rectTwo.y;
239
+ }
240
+ }
241
+
242
+ function compare(a, b) {
243
+ if (a === b)
244
+ throw new Error("Cannot compare node with itself");
245
+ const ancestors = {
246
+ a: getAncestors(a),
247
+ b: getAncestors(b)
248
+ };
249
+ let common_ancestor;
250
+ while (ancestors.a.at(-1) === ancestors.b.at(-1)) {
251
+ a = ancestors.a.pop();
252
+ b = ancestors.b.pop();
253
+ common_ancestor = a;
254
+ }
255
+ assert(common_ancestor);
256
+ const z_indexes = {
257
+ a: getZIndex(findStackingContext(ancestors.a)),
258
+ b: getZIndex(findStackingContext(ancestors.b))
259
+ };
260
+ if (z_indexes.a === z_indexes.b) {
261
+ const children = common_ancestor.childNodes;
262
+ const furthest_ancestors = {
263
+ a: ancestors.a.at(-1),
264
+ b: ancestors.b.at(-1)
265
+ };
266
+ let i = children.length;
267
+ while (i--) {
268
+ const child = children[i];
269
+ if (child === furthest_ancestors.a)
270
+ return 1;
271
+ if (child === furthest_ancestors.b)
272
+ return -1;
273
+ }
274
+ }
275
+ return Math.sign(z_indexes.a - z_indexes.b);
276
+ }
277
+ const props = /\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;
278
+ function isFlexItem(node) {
279
+ const display = getComputedStyle(getParent(node)).display;
280
+ return display === "flex" || display === "inline-flex";
281
+ }
282
+ function createsStackingContext(node) {
283
+ const style = getComputedStyle(node);
284
+ if (style.position === "fixed")
285
+ return true;
286
+ if (style.zIndex !== "auto" && (style.position !== "static" || isFlexItem(node))) {
287
+ return true;
288
+ }
289
+ if (+style.opacity < 1)
290
+ return true;
291
+ if ("transform" in style && style.transform !== "none")
292
+ return true;
293
+ if ("webkitTransform" in style && style.webkitTransform !== "none")
294
+ return true;
295
+ if ("mixBlendMode" in style && style.mixBlendMode !== "normal")
296
+ return true;
297
+ if ("filter" in style && style.filter !== "none")
298
+ return true;
299
+ if ("webkitFilter" in style && style.webkitFilter !== "none")
300
+ return true;
301
+ if ("isolation" in style && style.isolation === "isolate")
302
+ return true;
303
+ if (props.test(style.willChange))
304
+ return true;
305
+ if (style.webkitOverflowScrolling === "touch")
306
+ return true;
307
+ return false;
308
+ }
309
+ function findStackingContext(nodes) {
310
+ let i = nodes.length;
311
+ while (i--) {
312
+ const node = nodes[i];
313
+ assert(node);
314
+ if (createsStackingContext(node))
315
+ return node;
316
+ }
317
+ return null;
318
+ }
319
+ function getZIndex(node) {
320
+ return node && Number(getComputedStyle(node).zIndex) || 0;
321
+ }
322
+ function getAncestors(node) {
323
+ const ancestors = [];
324
+ while (node) {
325
+ ancestors.push(node);
326
+ node = getParent(node);
327
+ }
328
+ return ancestors;
329
+ }
330
+ function getParent(node) {
331
+ return node.parentNode?.host || node.parentNode;
332
+ }
333
+
334
+ const EXCEEDED_HORIZONTAL_MIN = 1;
335
+ const EXCEEDED_HORIZONTAL_MAX = 2;
336
+ const EXCEEDED_VERTICAL_MIN = 4;
337
+ const EXCEEDED_VERTICAL_MAX = 8;
338
+ function getInputType() {
339
+ if (typeof matchMedia === "function")
340
+ return matchMedia("(pointer:coarse)").matches ? "coarse" : "fine";
341
+ }
342
+ const isCoarsePointer = getInputType() === "coarse";
343
+ const intersectingHandles = [];
344
+ let isPointerDown = false;
345
+ const ownerDocumentCounts = /* @__PURE__ */ new Map();
346
+ const panelConstraintFlags = /* @__PURE__ */ new Map();
347
+ const registeredResizeHandlers = /* @__PURE__ */ new Set();
348
+ function registerResizeHandle(resizeHandleId, element, direction, hitAreaMargins, setResizeHandlerState) {
349
+ const { ownerDocument } = element;
350
+ const data = {
351
+ direction,
352
+ element,
353
+ hitAreaMargins,
354
+ setResizeHandlerState
355
+ };
356
+ const count = ownerDocumentCounts.get(ownerDocument) ?? 0;
357
+ ownerDocumentCounts.set(ownerDocument, count + 1);
358
+ registeredResizeHandlers.add(data);
359
+ updateListeners();
360
+ return function unregisterResizeHandle() {
361
+ panelConstraintFlags.delete(resizeHandleId);
362
+ registeredResizeHandlers.delete(data);
363
+ const count2 = ownerDocumentCounts.get(ownerDocument) ?? 1;
364
+ ownerDocumentCounts.set(ownerDocument, count2 - 1);
365
+ updateListeners();
366
+ if (count2 === 1)
367
+ ownerDocumentCounts.delete(ownerDocument);
368
+ };
369
+ }
370
+ function handlePointerDown(event) {
371
+ const { target } = event;
372
+ const { x, y } = getResizeEventCoordinates(event);
373
+ isPointerDown = true;
374
+ recalculateIntersectingHandles({ target, x, y });
375
+ updateListeners();
376
+ if (intersectingHandles.length > 0) {
377
+ updateResizeHandlerStates("down", event);
378
+ event.preventDefault();
379
+ }
380
+ }
381
+ function handlePointerMove(event) {
382
+ const { x, y } = getResizeEventCoordinates(event);
383
+ if (!isPointerDown) {
384
+ const { target } = event;
385
+ recalculateIntersectingHandles({ target, x, y });
386
+ }
387
+ updateResizeHandlerStates("move", event);
388
+ updateCursor();
389
+ if (intersectingHandles.length > 0)
390
+ event.preventDefault();
391
+ }
392
+ function handlePointerUp(event) {
393
+ const { target } = event;
394
+ const { x, y } = getResizeEventCoordinates(event);
395
+ panelConstraintFlags.clear();
396
+ isPointerDown = false;
397
+ if (intersectingHandles.length > 0)
398
+ event.preventDefault();
399
+ updateResizeHandlerStates("up", event);
400
+ recalculateIntersectingHandles({ target, x, y });
401
+ updateCursor();
402
+ updateListeners();
403
+ }
404
+ function recalculateIntersectingHandles({
405
+ target,
406
+ x,
407
+ y
408
+ }) {
409
+ intersectingHandles.splice(0);
410
+ let targetElement = null;
411
+ if (target instanceof HTMLElement)
412
+ targetElement = target;
413
+ registeredResizeHandlers.forEach((data) => {
414
+ const { element: dragHandleElement, hitAreaMargins } = data;
415
+ const dragHandleRect = dragHandleElement.getBoundingClientRect();
416
+ const { bottom, left, right, top } = dragHandleRect;
417
+ const margin = isCoarsePointer ? hitAreaMargins.coarse : hitAreaMargins.fine;
418
+ const eventIntersects = x >= left - margin && x <= right + margin && y >= top - margin && y <= bottom + margin;
419
+ if (eventIntersects) {
420
+ if (targetElement !== null && dragHandleElement !== targetElement && !dragHandleElement.contains(targetElement) && !targetElement.contains(dragHandleElement) && compare(targetElement, dragHandleElement) > 0) {
421
+ let currentElement = targetElement;
422
+ let didIntersect = false;
423
+ while (currentElement) {
424
+ if (currentElement.contains(dragHandleElement)) {
425
+ break;
426
+ } else if (intersects(
427
+ currentElement.getBoundingClientRect(),
428
+ dragHandleRect,
429
+ true
430
+ )) {
431
+ didIntersect = true;
432
+ break;
433
+ }
434
+ currentElement = currentElement.parentElement;
435
+ }
436
+ if (didIntersect)
437
+ return;
438
+ }
439
+ intersectingHandles.push(data);
440
+ }
441
+ });
442
+ }
443
+ function reportConstraintsViolation(resizeHandleId, flag) {
444
+ panelConstraintFlags.set(resizeHandleId, flag);
445
+ }
446
+ function updateCursor() {
447
+ let intersectsHorizontal = false;
448
+ let intersectsVertical = false;
449
+ intersectingHandles.forEach((data) => {
450
+ const { direction } = data;
451
+ if (direction === "horizontal")
452
+ intersectsHorizontal = true;
453
+ else
454
+ intersectsVertical = true;
455
+ });
456
+ let constraintFlags = 0;
457
+ panelConstraintFlags.forEach((flag) => {
458
+ constraintFlags |= flag;
459
+ });
460
+ if (intersectsHorizontal && intersectsVertical)
461
+ setGlobalCursorStyle("intersection", constraintFlags);
462
+ else if (intersectsHorizontal)
463
+ setGlobalCursorStyle("horizontal", constraintFlags);
464
+ else if (intersectsVertical)
465
+ setGlobalCursorStyle("vertical", constraintFlags);
466
+ else
467
+ resetGlobalCursorStyle();
468
+ }
469
+ function updateListeners() {
470
+ ownerDocumentCounts.forEach((_, ownerDocument) => {
471
+ const { body } = ownerDocument;
472
+ body.removeEventListener("contextmenu", handlePointerUp);
473
+ body.removeEventListener("mousedown", handlePointerDown);
474
+ body.removeEventListener("mouseleave", handlePointerMove);
475
+ body.removeEventListener("mousemove", handlePointerMove);
476
+ body.removeEventListener("touchmove", handlePointerMove);
477
+ body.removeEventListener("touchstart", handlePointerDown);
478
+ });
479
+ window.removeEventListener("mouseup", handlePointerUp);
480
+ window.removeEventListener("touchcancel", handlePointerUp);
481
+ window.removeEventListener("touchend", handlePointerUp);
482
+ if (registeredResizeHandlers.size > 0) {
483
+ if (isPointerDown) {
484
+ if (intersectingHandles.length > 0) {
485
+ ownerDocumentCounts.forEach((count, ownerDocument) => {
486
+ const { body } = ownerDocument;
487
+ if (count > 0) {
488
+ body.addEventListener("contextmenu", handlePointerUp);
489
+ body.addEventListener("mouseleave", handlePointerMove);
490
+ body.addEventListener("mousemove", handlePointerMove);
491
+ body.addEventListener("touchmove", handlePointerMove, {
492
+ passive: false
493
+ });
494
+ }
495
+ });
496
+ }
497
+ window.addEventListener("mouseup", handlePointerUp);
498
+ window.addEventListener("touchcancel", handlePointerUp);
499
+ window.addEventListener("touchend", handlePointerUp);
500
+ } else {
501
+ ownerDocumentCounts.forEach((count, ownerDocument) => {
502
+ const { body } = ownerDocument;
503
+ if (count > 0) {
504
+ body.addEventListener("mousedown", handlePointerDown);
505
+ body.addEventListener("mousemove", handlePointerMove);
506
+ body.addEventListener("touchmove", handlePointerMove, {
507
+ passive: false
508
+ });
509
+ body.addEventListener("touchstart", handlePointerDown);
510
+ }
511
+ });
512
+ }
513
+ }
514
+ }
515
+ function updateResizeHandlerStates(action, event) {
516
+ registeredResizeHandlers.forEach((data) => {
517
+ const { setResizeHandlerState } = data;
518
+ const isActive = intersectingHandles.includes(data);
519
+ setResizeHandlerState(action, isActive, event);
520
+ });
521
+ }
522
+
523
+ function debounce(callback, durationMs = 10) {
524
+ let timeoutId = null;
525
+ const callable = (...args) => {
526
+ if (timeoutId !== null)
527
+ clearTimeout(timeoutId);
528
+ timeoutId = setTimeout(() => {
529
+ callback(...args);
530
+ }, durationMs);
531
+ };
532
+ return callable;
533
+ }
534
+
535
+ function determinePivotIndices(groupId, dragHandleId, panelGroupElement) {
536
+ const index = getResizeHandleElementIndex(
537
+ groupId,
538
+ dragHandleId,
539
+ panelGroupElement
540
+ );
541
+ return index != null ? [index, index + 1] : [-1, -1];
542
+ }
543
+
544
+ const PRECISION = 10;
545
+
546
+ function fuzzyCompareNumbers(actual, expected, fractionDigits = PRECISION) {
547
+ actual = Number.parseFloat(actual.toFixed(fractionDigits));
548
+ expected = Number.parseFloat(expected.toFixed(fractionDigits));
549
+ const delta = actual - expected;
550
+ if (delta === 0)
551
+ return 0;
552
+ else
553
+ return delta > 0 ? 1 : -1;
554
+ }
555
+ function fuzzyNumbersEqual(actual, expected, fractionDigits) {
556
+ return fuzzyCompareNumbers(actual, expected, fractionDigits) === 0;
557
+ }
558
+
559
+ function resizePanel({
560
+ panelConstraints: panelConstraintsArray,
561
+ panelIndex,
562
+ size
563
+ }) {
564
+ const panelConstraints = panelConstraintsArray[panelIndex];
565
+ assert(panelConstraints != null);
566
+ const { collapsedSize = 0, collapsible, maxSize = 100, minSize = 0 } = panelConstraints;
567
+ if (fuzzyCompareNumbers(size, minSize) < 0) {
568
+ if (collapsible) {
569
+ const halfwayPoint = (collapsedSize + minSize) / 2;
570
+ if (fuzzyCompareNumbers(size, halfwayPoint) < 0)
571
+ size = collapsedSize;
572
+ else
573
+ size = minSize;
574
+ } else {
575
+ size = minSize;
576
+ }
577
+ }
578
+ size = Math.min(maxSize, size);
579
+ size = Number.parseFloat(size.toFixed(PRECISION));
580
+ return size;
581
+ }
582
+
583
+ function validatePanelGroupLayout({
584
+ layout: prevLayout,
585
+ panelConstraints
586
+ }) {
587
+ const nextLayout = [...prevLayout];
588
+ const nextLayoutTotalSize = nextLayout.reduce(
589
+ (accumulated, current) => accumulated + current,
590
+ 0
591
+ );
592
+ if (nextLayout.length !== panelConstraints.length) {
593
+ throw new Error(
594
+ `Invalid ${panelConstraints.length} panel layout: ${nextLayout.map((size) => `${size}%`).join(", ")}`
595
+ );
596
+ } else if (!fuzzyNumbersEqual(nextLayoutTotalSize, 100)) {
597
+ {
598
+ console.warn(
599
+ `WARNING: Invalid layout total size: ${nextLayout.map((size) => `${size}%`).join(", ")}. Layout normalization will be applied.`
600
+ );
601
+ }
602
+ for (let index = 0; index < panelConstraints.length; index++) {
603
+ const unsafeSize = nextLayout[index];
604
+ assert(unsafeSize != null);
605
+ const safeSize = 100 / nextLayoutTotalSize * unsafeSize;
606
+ nextLayout[index] = safeSize;
607
+ }
608
+ }
609
+ let remainingSize = 0;
610
+ for (let index = 0; index < panelConstraints.length; index++) {
611
+ const unsafeSize = nextLayout[index];
612
+ assert(unsafeSize != null);
613
+ const safeSize = resizePanel({
614
+ panelConstraints,
615
+ panelIndex: index,
616
+ size: unsafeSize
617
+ });
618
+ if (unsafeSize !== safeSize) {
619
+ remainingSize += unsafeSize - safeSize;
620
+ nextLayout[index] = safeSize;
621
+ }
622
+ }
623
+ if (!fuzzyNumbersEqual(remainingSize, 0)) {
624
+ for (let index = 0; index < panelConstraints.length; index++) {
625
+ const prevSize = nextLayout[index];
626
+ assert(prevSize != null);
627
+ const unsafeSize = prevSize + remainingSize;
628
+ const safeSize = resizePanel({
629
+ panelConstraints,
630
+ panelIndex: index,
631
+ size: unsafeSize
632
+ });
633
+ if (prevSize !== safeSize) {
634
+ remainingSize -= safeSize - prevSize;
635
+ nextLayout[index] = safeSize;
636
+ if (fuzzyNumbersEqual(remainingSize, 0))
637
+ break;
638
+ }
639
+ }
640
+ }
641
+ return nextLayout;
642
+ }
643
+
644
+ function callPanelCallbacks(panelsArray, layout, panelIdToLastNotifiedSizeMap) {
645
+ layout.forEach((size, index) => {
646
+ const panelData = panelsArray[index];
647
+ assert(panelData);
648
+ const { callbacks, constraints, id: panelId } = panelData;
649
+ const { collapsedSize = 0, collapsible } = constraints;
650
+ const lastNotifiedSize = panelIdToLastNotifiedSizeMap[panelId];
651
+ if (lastNotifiedSize == null || size !== lastNotifiedSize) {
652
+ panelIdToLastNotifiedSizeMap[panelId] = size;
653
+ const { onCollapse, onExpand, onResize } = callbacks;
654
+ if (onResize)
655
+ onResize(size, lastNotifiedSize);
656
+ if (collapsible && (onCollapse || onExpand)) {
657
+ if (onExpand && (lastNotifiedSize == null || lastNotifiedSize === collapsedSize) && size !== collapsedSize) {
658
+ onExpand();
659
+ }
660
+ if (onCollapse && (lastNotifiedSize == null || lastNotifiedSize !== collapsedSize) && size === collapsedSize) {
661
+ onCollapse();
662
+ }
663
+ }
664
+ }
665
+ });
666
+ }
667
+
668
+ function compareLayouts(a, b) {
669
+ if (a.length !== b.length) {
670
+ return false;
671
+ } else {
672
+ for (let index = 0; index < a.length; index++) {
673
+ if (a[index] !== b[index])
674
+ return false;
675
+ }
676
+ }
677
+ return true;
678
+ }
679
+ function adjustLayoutByDelta({
680
+ delta,
681
+ layout: prevLayout,
682
+ panelConstraints: panelConstraintsArray,
683
+ pivotIndices,
684
+ trigger
685
+ }) {
686
+ if (fuzzyNumbersEqual(delta, 0))
687
+ return prevLayout;
688
+ const nextLayout = [...prevLayout];
689
+ const [firstPivotIndex, secondPivotIndex] = pivotIndices;
690
+ assert(firstPivotIndex != null);
691
+ assert(secondPivotIndex != null);
692
+ let deltaApplied = 0;
693
+ {
694
+ if (trigger === "keyboard") {
695
+ {
696
+ const index = delta < 0 ? secondPivotIndex : firstPivotIndex;
697
+ const panelConstraints = panelConstraintsArray[index];
698
+ assert(panelConstraints);
699
+ if (panelConstraints.collapsible) {
700
+ const prevSize = prevLayout[index];
701
+ assert(prevSize != null);
702
+ const panelConstraints2 = panelConstraintsArray[index];
703
+ assert(panelConstraints2);
704
+ const { collapsedSize = 0, minSize = 0 } = panelConstraints2;
705
+ if (fuzzyNumbersEqual(prevSize, collapsedSize)) {
706
+ const localDelta = minSize - prevSize;
707
+ if (fuzzyCompareNumbers(localDelta, Math.abs(delta)) > 0)
708
+ delta = delta < 0 ? 0 - localDelta : localDelta;
709
+ }
710
+ }
711
+ }
712
+ {
713
+ const index = delta < 0 ? firstPivotIndex : secondPivotIndex;
714
+ const panelConstraints = panelConstraintsArray[index];
715
+ assert(panelConstraints);
716
+ const { collapsible } = panelConstraints;
717
+ if (collapsible) {
718
+ const prevSize = prevLayout[index];
719
+ assert(prevSize != null);
720
+ const panelConstraints2 = panelConstraintsArray[index];
721
+ assert(panelConstraints2);
722
+ const { collapsedSize = 0, minSize = 0 } = panelConstraints2;
723
+ if (fuzzyNumbersEqual(prevSize, minSize)) {
724
+ const localDelta = prevSize - collapsedSize;
725
+ if (fuzzyCompareNumbers(localDelta, Math.abs(delta)) > 0)
726
+ delta = delta < 0 ? 0 - localDelta : localDelta;
727
+ }
728
+ }
729
+ }
730
+ }
731
+ }
732
+ {
733
+ const increment = delta < 0 ? 1 : -1;
734
+ let index = delta < 0 ? secondPivotIndex : firstPivotIndex;
735
+ let maxAvailableDelta = 0;
736
+ while (true) {
737
+ const prevSize = prevLayout[index];
738
+ assert(prevSize != null);
739
+ const maxSafeSize = resizePanel({
740
+ panelConstraints: panelConstraintsArray,
741
+ panelIndex: index,
742
+ size: 100
743
+ });
744
+ const delta2 = maxSafeSize - prevSize;
745
+ maxAvailableDelta += delta2;
746
+ index += increment;
747
+ if (index < 0 || index >= panelConstraintsArray.length)
748
+ break;
749
+ }
750
+ const minAbsDelta = Math.min(Math.abs(delta), Math.abs(maxAvailableDelta));
751
+ delta = delta < 0 ? 0 - minAbsDelta : minAbsDelta;
752
+ }
753
+ {
754
+ const pivotIndex = delta < 0 ? firstPivotIndex : secondPivotIndex;
755
+ let index = pivotIndex;
756
+ while (index >= 0 && index < panelConstraintsArray.length) {
757
+ const deltaRemaining = Math.abs(delta) - Math.abs(deltaApplied);
758
+ const prevSize = prevLayout[index];
759
+ assert(prevSize != null);
760
+ const unsafeSize = prevSize - deltaRemaining;
761
+ const safeSize = resizePanel({
762
+ panelConstraints: panelConstraintsArray,
763
+ panelIndex: index,
764
+ size: unsafeSize
765
+ });
766
+ if (!fuzzyNumbersEqual(prevSize, safeSize)) {
767
+ deltaApplied += prevSize - safeSize;
768
+ nextLayout[index] = safeSize;
769
+ if (deltaApplied.toPrecision(3).localeCompare(Math.abs(delta).toPrecision(3), void 0, {
770
+ numeric: true
771
+ }) >= 0) {
772
+ break;
773
+ }
774
+ }
775
+ if (delta < 0)
776
+ index--;
777
+ else
778
+ index++;
779
+ }
780
+ }
781
+ if (fuzzyNumbersEqual(deltaApplied, 0)) {
782
+ return prevLayout;
783
+ }
784
+ {
785
+ const pivotIndex = delta < 0 ? secondPivotIndex : firstPivotIndex;
786
+ const prevSize = prevLayout[pivotIndex];
787
+ assert(prevSize != null);
788
+ const unsafeSize = prevSize + deltaApplied;
789
+ const safeSize = resizePanel({
790
+ panelConstraints: panelConstraintsArray,
791
+ panelIndex: pivotIndex,
792
+ size: unsafeSize
793
+ });
794
+ nextLayout[pivotIndex] = safeSize;
795
+ if (!fuzzyNumbersEqual(safeSize, unsafeSize)) {
796
+ let deltaRemaining = unsafeSize - safeSize;
797
+ const pivotIndex2 = delta < 0 ? secondPivotIndex : firstPivotIndex;
798
+ let index = pivotIndex2;
799
+ while (index >= 0 && index < panelConstraintsArray.length) {
800
+ const prevSize2 = nextLayout[index];
801
+ assert(prevSize2 != null);
802
+ const unsafeSize2 = prevSize2 + deltaRemaining;
803
+ const safeSize2 = resizePanel({
804
+ panelConstraints: panelConstraintsArray,
805
+ panelIndex: index,
806
+ size: unsafeSize2
807
+ });
808
+ if (!fuzzyNumbersEqual(prevSize2, safeSize2)) {
809
+ deltaRemaining -= safeSize2 - prevSize2;
810
+ nextLayout[index] = safeSize2;
811
+ }
812
+ if (fuzzyNumbersEqual(deltaRemaining, 0))
813
+ break;
814
+ if (delta > 0)
815
+ index--;
816
+ else
817
+ index++;
818
+ }
819
+ }
820
+ }
821
+ const totalSize = nextLayout.reduce((total, size) => size + total, 0);
822
+ if (!fuzzyNumbersEqual(totalSize, 100))
823
+ return prevLayout;
824
+ return nextLayout;
825
+ }
826
+
827
+ function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement) {
828
+ const isHorizontal = direction === "horizontal";
829
+ const handleElement = getResizeHandleElement(dragHandleId, panelGroupElement);
830
+ assert(handleElement);
831
+ const groupId = handleElement.getAttribute("data-panel-group-id");
832
+ assert(groupId);
833
+ const { initialCursorPosition } = initialDragState;
834
+ const cursorPosition = getResizeEventCursorPosition(direction, event);
835
+ const groupElement = getPanelGroupElement(groupId, panelGroupElement);
836
+ assert(groupElement);
837
+ const groupRect = groupElement.getBoundingClientRect();
838
+ const groupSizeInPixels = isHorizontal ? groupRect.width : groupRect.height;
839
+ const offsetPixels = cursorPosition - initialCursorPosition;
840
+ const offsetPercentage = offsetPixels / groupSizeInPixels * 100;
841
+ return offsetPercentage;
842
+ }
843
+ function calculateDeltaPercentage(event, dragHandleId, direction, initialDragState, keyboardResizeBy, panelGroupElement) {
844
+ if (isKeyDown(event)) {
845
+ const isHorizontal = direction === "horizontal";
846
+ let delta = 0;
847
+ if (event.shiftKey)
848
+ delta = 100;
849
+ else
850
+ delta = keyboardResizeBy ?? 10;
851
+ let movement = 0;
852
+ switch (event.key) {
853
+ case "ArrowDown":
854
+ movement = isHorizontal ? 0 : delta;
855
+ break;
856
+ case "ArrowLeft":
857
+ movement = isHorizontal ? -delta : 0;
858
+ break;
859
+ case "ArrowRight":
860
+ movement = isHorizontal ? delta : 0;
861
+ break;
862
+ case "ArrowUp":
863
+ movement = isHorizontal ? 0 : -delta;
864
+ break;
865
+ case "End":
866
+ movement = 100;
867
+ break;
868
+ case "Home":
869
+ movement = -100;
870
+ break;
871
+ }
872
+ return movement;
873
+ } else {
874
+ if (initialDragState == null)
875
+ return 0;
876
+ return calculateDragOffsetPercentage(
877
+ event,
878
+ dragHandleId,
879
+ direction,
880
+ initialDragState,
881
+ panelGroupElement
882
+ );
883
+ }
884
+ }
885
+ function calculateAriaValues({
886
+ layout,
887
+ panelsArray,
888
+ pivotIndices
889
+ }) {
890
+ let currentMinSize = 0;
891
+ let currentMaxSize = 100;
892
+ let totalMinSize = 0;
893
+ let totalMaxSize = 0;
894
+ const firstIndex = pivotIndices[0];
895
+ assert(firstIndex != null);
896
+ panelsArray.forEach((panelData, index) => {
897
+ const { constraints } = panelData;
898
+ const { maxSize = 100, minSize = 0 } = constraints;
899
+ if (index === firstIndex) {
900
+ currentMinSize = minSize;
901
+ currentMaxSize = maxSize;
902
+ } else {
903
+ totalMinSize += minSize;
904
+ totalMaxSize += maxSize;
905
+ }
906
+ });
907
+ const valueMax = Math.min(currentMaxSize, 100 - totalMinSize);
908
+ const valueMin = Math.max(currentMinSize, 100 - totalMaxSize);
909
+ const valueNow = layout[firstIndex];
910
+ return {
911
+ valueMax,
912
+ valueMin,
913
+ valueNow
914
+ };
915
+ }
916
+ function calculateUnsafeDefaultLayout({
917
+ panelDataArray
918
+ }) {
919
+ const layout = Array(panelDataArray.length);
920
+ const panelConstraintsArray = panelDataArray.map(
921
+ (panelData) => panelData.constraints
922
+ );
923
+ let numPanelsWithSizes = 0;
924
+ let remainingSize = 100;
925
+ for (let index = 0; index < panelDataArray.length; index++) {
926
+ const panelConstraints = panelConstraintsArray[index];
927
+ assert(panelConstraints);
928
+ const { defaultSize } = panelConstraints;
929
+ if (defaultSize != null) {
930
+ numPanelsWithSizes++;
931
+ layout[index] = defaultSize;
932
+ remainingSize -= defaultSize;
933
+ }
934
+ }
935
+ for (let index = 0; index < panelDataArray.length; index++) {
936
+ const panelConstraints = panelConstraintsArray[index];
937
+ assert(panelConstraints);
938
+ const { defaultSize } = panelConstraints;
939
+ if (defaultSize != null)
940
+ continue;
941
+ const numRemainingPanels = panelDataArray.length - numPanelsWithSizes;
942
+ const size = remainingSize / numRemainingPanels;
943
+ numPanelsWithSizes++;
944
+ layout[index] = size;
945
+ remainingSize -= size;
946
+ }
947
+ return layout;
948
+ }
949
+
950
+ function initializeDefaultStorage(storageObject) {
951
+ try {
952
+ if (typeof localStorage !== "undefined") {
953
+ storageObject.getItem = (name) => {
954
+ return localStorage.getItem(name);
955
+ };
956
+ storageObject.setItem = (name, value) => {
957
+ localStorage.setItem(name, value);
958
+ };
959
+ } else {
960
+ throw new TypeError("localStorage not supported in this environment");
961
+ }
962
+ } catch (error) {
963
+ console.error(error);
964
+ storageObject.getItem = () => null;
965
+ storageObject.setItem = () => {
966
+ };
967
+ }
968
+ }
969
+ function getPanelGroupKey(autoSaveId) {
970
+ return `destyler:${autoSaveId}`;
971
+ }
972
+ function getPanelKey(panels) {
973
+ return panels.map((panel) => {
974
+ const { constraints, id, idIsFromProps, order } = panel;
975
+ if (idIsFromProps) {
976
+ return id;
977
+ } else {
978
+ return order ? `${order}:${JSON.stringify(constraints)}` : JSON.stringify(constraints);
979
+ }
980
+ }).sort((a, b) => a.localeCompare(b)).join(",");
981
+ }
982
+ function loadSerializedPanelGroupState(autoSaveId, storage) {
983
+ try {
984
+ const panelGroupKey = getPanelGroupKey(autoSaveId);
985
+ const serialized = storage.getItem(panelGroupKey);
986
+ if (serialized) {
987
+ const parsed = JSON.parse(serialized);
988
+ if (typeof parsed === "object" && parsed != null)
989
+ return parsed;
990
+ }
991
+ } catch (error) {
992
+ }
993
+ return null;
994
+ }
995
+ function loadPanelGroupState(autoSaveId, panels, storage) {
996
+ const state = loadSerializedPanelGroupState(autoSaveId, storage) ?? {};
997
+ const panelKey = getPanelKey(panels);
998
+ return state[panelKey] ?? null;
999
+ }
1000
+ function savePanelGroupState(autoSaveId, panels, panelSizesBeforeCollapse, sizes, storage) {
1001
+ const panelGroupKey = getPanelGroupKey(autoSaveId);
1002
+ const panelKey = getPanelKey(panels);
1003
+ const state = loadSerializedPanelGroupState(autoSaveId, storage) ?? {};
1004
+ state[panelKey] = {
1005
+ expandToSizes: Object.fromEntries(panelSizesBeforeCollapse.entries()),
1006
+ layout: sizes
1007
+ };
1008
+ try {
1009
+ storage.setItem(panelGroupKey, JSON.stringify(state));
1010
+ } catch (error) {
1011
+ console.error(error);
1012
+ }
1013
+ }
1014
+
1015
+ function useWindowSplitterPanelGroupBehavior({
1016
+ eagerValuesRef,
1017
+ groupId,
1018
+ layout,
1019
+ panelDataArray,
1020
+ panelGroupElement,
1021
+ setLayout
1022
+ }) {
1023
+ vue.watchEffect((onCleanup) => {
1024
+ const _panelGroupElement = panelGroupElement.value;
1025
+ if (!_panelGroupElement)
1026
+ return;
1027
+ const resizeHandleElements = getResizeHandleElementsForGroup(
1028
+ groupId,
1029
+ _panelGroupElement
1030
+ );
1031
+ for (let index = 0; index < panelDataArray.length - 1; index++) {
1032
+ const { valueMax, valueMin, valueNow } = calculateAriaValues({
1033
+ layout: layout.value,
1034
+ panelsArray: panelDataArray,
1035
+ pivotIndices: [index, index + 1]
1036
+ });
1037
+ const resizeHandleElement = resizeHandleElements[index];
1038
+ if (resizeHandleElement == null) {
1039
+ if (undefined.DEV)
1040
+ console.warn(`WARNING: Missing resize handle for PanelGroup "${groupId}"`);
1041
+ } else {
1042
+ const panelData = panelDataArray[index];
1043
+ assert(panelData);
1044
+ resizeHandleElement.setAttribute("aria-controls", panelData.id);
1045
+ resizeHandleElement.setAttribute(
1046
+ "aria-valuemax",
1047
+ `${Math.round(valueMax)}`
1048
+ );
1049
+ resizeHandleElement.setAttribute(
1050
+ "aria-valuemin",
1051
+ `${Math.round(valueMin)}`
1052
+ );
1053
+ resizeHandleElement.setAttribute(
1054
+ "aria-valuenow",
1055
+ valueNow != null ? `${Math.round(valueNow)}` : ""
1056
+ );
1057
+ }
1058
+ }
1059
+ onCleanup(() => {
1060
+ resizeHandleElements.forEach((resizeHandleElement) => {
1061
+ resizeHandleElement.removeAttribute("aria-controls");
1062
+ resizeHandleElement.removeAttribute("aria-valuemax");
1063
+ resizeHandleElement.removeAttribute("aria-valuemin");
1064
+ resizeHandleElement.removeAttribute("aria-valuenow");
1065
+ });
1066
+ });
1067
+ });
1068
+ vue.watchEffect((onCleanup) => {
1069
+ const _panelGroupElement = panelGroupElement.value;
1070
+ if (!_panelGroupElement)
1071
+ return;
1072
+ const eagerValues = eagerValuesRef.value;
1073
+ assert(eagerValues);
1074
+ const { panelDataArray: panelDataArray2 } = eagerValues;
1075
+ const groupElement = getPanelGroupElement(groupId, _panelGroupElement);
1076
+ assert(groupElement != null, `No group found for id "${groupId}"`);
1077
+ const handles = getResizeHandleElementsForGroup(groupId, _panelGroupElement);
1078
+ assert(handles);
1079
+ const cleanupFunctions = handles.map((handle) => {
1080
+ const handleId = handle.getAttribute("data-panel-resize-handle-id");
1081
+ assert(handleId);
1082
+ const [idBefore, idAfter] = getResizeHandlePanelIds(
1083
+ groupId,
1084
+ handleId,
1085
+ panelDataArray2,
1086
+ _panelGroupElement
1087
+ );
1088
+ if (idBefore == null || idAfter == null)
1089
+ return () => {
1090
+ };
1091
+ const onKeyDown = (event) => {
1092
+ if (event.defaultPrevented)
1093
+ return;
1094
+ switch (event.key) {
1095
+ case "Enter": {
1096
+ event.preventDefault();
1097
+ const index = panelDataArray2.findIndex(
1098
+ (panelData) => panelData.id === idBefore
1099
+ );
1100
+ if (index >= 0) {
1101
+ const panelData = panelDataArray2[index];
1102
+ assert(panelData);
1103
+ const size = layout.value[index];
1104
+ const {
1105
+ collapsedSize = 0,
1106
+ collapsible,
1107
+ minSize = 0
1108
+ } = panelData.constraints;
1109
+ if (size != null && collapsible) {
1110
+ const nextLayout = adjustLayoutByDelta({
1111
+ delta: fuzzyNumbersEqual(size, collapsedSize) ? minSize - collapsedSize : collapsedSize - size,
1112
+ layout: layout.value,
1113
+ panelConstraints: panelDataArray2.map(
1114
+ (panelData2) => panelData2.constraints
1115
+ ),
1116
+ pivotIndices: determinePivotIndices(
1117
+ groupId,
1118
+ handleId,
1119
+ _panelGroupElement
1120
+ ),
1121
+ trigger: "keyboard"
1122
+ });
1123
+ if (layout.value !== nextLayout)
1124
+ setLayout(nextLayout);
1125
+ }
1126
+ }
1127
+ break;
1128
+ }
1129
+ }
1130
+ };
1131
+ handle.addEventListener("keydown", onKeyDown);
1132
+ return () => {
1133
+ handle.removeEventListener("keydown", onKeyDown);
1134
+ };
1135
+ });
1136
+ onCleanup(() => {
1137
+ cleanupFunctions.forEach((cleanupFunction) => cleanupFunction());
1138
+ });
1139
+ });
1140
+ }
1141
+
1142
+ const defaultStorage = {
1143
+ getItem: (name) => {
1144
+ initializeDefaultStorage(defaultStorage);
1145
+ return defaultStorage.getItem(name);
1146
+ },
1147
+ setItem: (name, value) => {
1148
+ initializeDefaultStorage(defaultStorage);
1149
+ defaultStorage.setItem(name, value);
1150
+ }
1151
+ };
1152
+ const splitterGroupProps = {
1153
+ ...primitive.primitiveProps,
1154
+ /**
1155
+ * Group id; falls back to `useId` when not provided.
1156
+ */
1157
+ id: {
1158
+ type: String,
1159
+ required: false
1160
+ },
1161
+ /**
1162
+ * Unique id used to auto-save group
1163
+ * arrangement via `localStorage`.
1164
+ *
1165
+ * @default null
1166
+ */
1167
+ autoSaveId: {
1168
+ type: String,
1169
+ required: false,
1170
+ default: null
1171
+ },
1172
+ /**
1173
+ * The group orientation of splitter.
1174
+ */
1175
+ direction: {
1176
+ type: String,
1177
+ required: true
1178
+ },
1179
+ /**
1180
+ * Step size when arrow key was pressed.
1181
+ *
1182
+ * @default 10
1183
+ */
1184
+ keyboardResizeBy: {
1185
+ type: Number,
1186
+ required: false,
1187
+ default: 10
1188
+ },
1189
+ /**
1190
+ * Custom storage API; defaults to localStorage
1191
+ *
1192
+ * @default () => defaultStorage
1193
+ */
1194
+ storage: {
1195
+ type: Object,
1196
+ required: false,
1197
+ default: () => defaultStorage
1198
+ }
1199
+ };
1200
+ const splitterGroupEmits = {
1201
+ /**
1202
+ * Event handler called when group layout changes
1203
+ */
1204
+ layout: (_layout) => true
1205
+ };
1206
+ const [injectPanelGroupContext, providePanelGroupContext] = shared.createContext("PanelGroup");
1207
+ const SplitterGroup = vue.defineComponent({
1208
+ name: "DestylerSplitterGroup",
1209
+ props: splitterGroupProps,
1210
+ emits: splitterGroupEmits,
1211
+ slots: Object,
1212
+ setup(props, { emit }) {
1213
+ const LOCAL_STORAGE_DEBOUNCE_INTERVAL = 100;
1214
+ const debounceMap = {};
1215
+ const groupId = composition.useId(props.id, "destyler-splitter-group");
1216
+ const dir = composition.useDirection();
1217
+ const { forwardRef, currentElement: panelGroupElementRef } = composition.useForwardExpose();
1218
+ const dragState = vue.ref(null);
1219
+ const layout = vue.ref([]);
1220
+ const panelIdToLastNotifiedSizeMapRef = vue.ref({});
1221
+ const panelSizeBeforeCollapseRef = vue.ref(/* @__PURE__ */ new Map());
1222
+ const prevDeltaRef = vue.ref(0);
1223
+ const committedValuesRef = vue.computed(() => ({
1224
+ autoSaveId: props.autoSaveId,
1225
+ direction: props.direction,
1226
+ dragState: dragState.value,
1227
+ id: groupId,
1228
+ keyboardResizeBy: props.keyboardResizeBy,
1229
+ storage: props.storage
1230
+ }));
1231
+ const eagerValuesRef = vue.ref({
1232
+ layout: layout.value,
1233
+ panelDataArray: [],
1234
+ panelDataArrayChanged: false
1235
+ });
1236
+ const setLayout = (val) => layout.value = val;
1237
+ useWindowSplitterPanelGroupBehavior({
1238
+ eagerValuesRef,
1239
+ groupId,
1240
+ layout,
1241
+ panelDataArray: eagerValuesRef.value.panelDataArray,
1242
+ setLayout,
1243
+ panelGroupElement: panelGroupElementRef
1244
+ });
1245
+ vue.watchEffect(() => {
1246
+ const { panelDataArray } = eagerValuesRef.value;
1247
+ const { autoSaveId } = props;
1248
+ if (autoSaveId) {
1249
+ if (layout.value.length === 0 || layout.value.length !== panelDataArray.length)
1250
+ return;
1251
+ let debouncedSave = debounceMap[autoSaveId];
1252
+ if (!debouncedSave) {
1253
+ debouncedSave = debounce(
1254
+ savePanelGroupState,
1255
+ LOCAL_STORAGE_DEBOUNCE_INTERVAL
1256
+ );
1257
+ debounceMap[autoSaveId] = debouncedSave;
1258
+ }
1259
+ const clonedPanelDataArray = [...panelDataArray];
1260
+ const clonedPanelSizesBeforeCollapse = new Map(
1261
+ panelSizeBeforeCollapseRef.value
1262
+ );
1263
+ debouncedSave(
1264
+ autoSaveId,
1265
+ clonedPanelDataArray,
1266
+ clonedPanelSizesBeforeCollapse,
1267
+ layout.value,
1268
+ props.storage
1269
+ );
1270
+ }
1271
+ });
1272
+ function getPanelStyle(panelData, defaultSize) {
1273
+ const { panelDataArray } = eagerValuesRef.value;
1274
+ const panelIndex = findPanelDataIndex(panelDataArray, panelData);
1275
+ return computePanelFlexBoxStyle({
1276
+ defaultSize,
1277
+ dragState: dragState.value,
1278
+ layout: layout.value,
1279
+ panelData: panelDataArray,
1280
+ panelIndex
1281
+ });
1282
+ }
1283
+ function registerPanel(panelData) {
1284
+ const { panelDataArray } = eagerValuesRef.value;
1285
+ panelDataArray.push(panelData);
1286
+ panelDataArray.sort((panelA, panelB) => {
1287
+ const orderA = panelA.order;
1288
+ const orderB = panelB.order;
1289
+ if (orderA == null && orderB == null)
1290
+ return 0;
1291
+ else if (orderA == null)
1292
+ return -1;
1293
+ else if (orderB == null)
1294
+ return 1;
1295
+ else
1296
+ return orderA - orderB;
1297
+ });
1298
+ eagerValuesRef.value.panelDataArrayChanged = true;
1299
+ }
1300
+ vue.watch(() => eagerValuesRef.value.panelDataArrayChanged, () => {
1301
+ if (eagerValuesRef.value.panelDataArrayChanged) {
1302
+ eagerValuesRef.value.panelDataArrayChanged = false;
1303
+ const { autoSaveId, storage } = committedValuesRef.value;
1304
+ const { layout: prevLayout, panelDataArray } = eagerValuesRef.value;
1305
+ let unsafeLayout = null;
1306
+ if (autoSaveId) {
1307
+ const state = loadPanelGroupState(autoSaveId, panelDataArray, storage);
1308
+ if (state) {
1309
+ panelSizeBeforeCollapseRef.value = new Map(
1310
+ Object.entries(state.expandToSizes)
1311
+ );
1312
+ unsafeLayout = state.layout;
1313
+ }
1314
+ }
1315
+ if (unsafeLayout === null) {
1316
+ unsafeLayout = calculateUnsafeDefaultLayout({
1317
+ panelDataArray
1318
+ });
1319
+ }
1320
+ const nextLayout = validatePanelGroupLayout({
1321
+ layout: unsafeLayout,
1322
+ panelConstraints: panelDataArray.map(
1323
+ (panelData) => panelData.constraints
1324
+ )
1325
+ });
1326
+ if (!shared.areEqual(prevLayout, nextLayout)) {
1327
+ setLayout(nextLayout);
1328
+ eagerValuesRef.value.layout = nextLayout;
1329
+ emit("layout", nextLayout);
1330
+ callPanelCallbacks(
1331
+ panelDataArray,
1332
+ nextLayout,
1333
+ panelIdToLastNotifiedSizeMapRef.value
1334
+ );
1335
+ }
1336
+ }
1337
+ });
1338
+ function registerResizeHandle(dragHandleId) {
1339
+ return function resizeHandler(event) {
1340
+ event.preventDefault();
1341
+ const panelGroupElement = panelGroupElementRef.value;
1342
+ if (!panelGroupElement)
1343
+ return () => null;
1344
+ const { direction, dragState: dragState2, id: groupId2, keyboardResizeBy } = committedValuesRef.value;
1345
+ const { layout: prevLayout, panelDataArray } = eagerValuesRef.value;
1346
+ const { initialLayout } = dragState2 ?? {};
1347
+ const pivotIndices = determinePivotIndices(
1348
+ groupId2,
1349
+ dragHandleId,
1350
+ panelGroupElement
1351
+ );
1352
+ let delta = calculateDeltaPercentage(
1353
+ event,
1354
+ dragHandleId,
1355
+ direction,
1356
+ dragState2,
1357
+ keyboardResizeBy,
1358
+ panelGroupElement
1359
+ );
1360
+ if (delta === 0)
1361
+ return;
1362
+ const isHorizontal = direction === "horizontal";
1363
+ if (dir.value === "rtl" && isHorizontal)
1364
+ delta = -delta;
1365
+ const panelConstraints = panelDataArray.map((panelData) => panelData.constraints);
1366
+ const nextLayout = adjustLayoutByDelta({
1367
+ delta,
1368
+ layout: initialLayout ?? prevLayout,
1369
+ panelConstraints,
1370
+ pivotIndices,
1371
+ trigger: isKeyDown(event) ? "keyboard" : "mouse-or-touch"
1372
+ });
1373
+ const layoutChanged = !compareLayouts(prevLayout, nextLayout);
1374
+ if (isMouseEvent(event) || isTouchEvent(event)) {
1375
+ if (prevDeltaRef.value !== delta) {
1376
+ prevDeltaRef.value = delta;
1377
+ if (!layoutChanged) {
1378
+ if (isHorizontal) {
1379
+ reportConstraintsViolation(
1380
+ dragHandleId,
1381
+ delta < 0 ? EXCEEDED_HORIZONTAL_MIN : EXCEEDED_HORIZONTAL_MAX
1382
+ );
1383
+ } else {
1384
+ reportConstraintsViolation(
1385
+ dragHandleId,
1386
+ delta < 0 ? EXCEEDED_VERTICAL_MIN : EXCEEDED_VERTICAL_MAX
1387
+ );
1388
+ }
1389
+ } else {
1390
+ reportConstraintsViolation(dragHandleId, 0);
1391
+ }
1392
+ }
1393
+ }
1394
+ if (layoutChanged) {
1395
+ setLayout(nextLayout);
1396
+ eagerValuesRef.value.layout = nextLayout;
1397
+ emit("layout", nextLayout);
1398
+ callPanelCallbacks(
1399
+ panelDataArray,
1400
+ nextLayout,
1401
+ panelIdToLastNotifiedSizeMapRef.value
1402
+ );
1403
+ }
1404
+ };
1405
+ }
1406
+ function resizePanel(panelData, unsafePanelSize) {
1407
+ const { layout: prevLayout, panelDataArray } = eagerValuesRef.value;
1408
+ const panelConstraintsArray = panelDataArray.map((panelData2) => panelData2.constraints);
1409
+ const { panelSize, pivotIndices } = panelDataHelper(
1410
+ panelDataArray,
1411
+ panelData,
1412
+ prevLayout
1413
+ );
1414
+ assert(panelSize != null);
1415
+ const isLastPanel = findPanelDataIndex(panelDataArray, panelData) === panelDataArray.length - 1;
1416
+ const delta = isLastPanel ? panelSize - unsafePanelSize : unsafePanelSize - panelSize;
1417
+ const nextLayout = adjustLayoutByDelta({
1418
+ delta,
1419
+ layout: prevLayout,
1420
+ panelConstraints: panelConstraintsArray,
1421
+ pivotIndices,
1422
+ trigger: "imperative-api"
1423
+ });
1424
+ if (!compareLayouts(prevLayout, nextLayout)) {
1425
+ setLayout(nextLayout);
1426
+ eagerValuesRef.value.layout = nextLayout;
1427
+ emit("layout", nextLayout);
1428
+ callPanelCallbacks(
1429
+ panelDataArray,
1430
+ nextLayout,
1431
+ panelIdToLastNotifiedSizeMapRef.value
1432
+ );
1433
+ }
1434
+ }
1435
+ function reevaluatePanelConstraints(panelData, prevConstraints) {
1436
+ const { layout: layout2, panelDataArray } = eagerValuesRef.value;
1437
+ const {
1438
+ collapsedSize: prevCollapsedSize = 0,
1439
+ collapsible: prevCollapsible
1440
+ } = prevConstraints;
1441
+ const {
1442
+ collapsedSize: nextCollapsedSize = 0,
1443
+ collapsible: nextCollapsible,
1444
+ maxSize: nextMaxSize = 100,
1445
+ minSize: nextMinSize = 0
1446
+ } = panelData.constraints;
1447
+ const { panelSize: prevPanelSize } = panelDataHelper(
1448
+ panelDataArray,
1449
+ panelData,
1450
+ layout2
1451
+ );
1452
+ if (prevPanelSize === null) {
1453
+ return;
1454
+ }
1455
+ if (prevCollapsible && nextCollapsible && prevPanelSize === prevCollapsedSize) {
1456
+ if (prevCollapsedSize !== nextCollapsedSize) {
1457
+ resizePanel(panelData, nextCollapsedSize);
1458
+ }
1459
+ } else if (prevPanelSize < nextMinSize) {
1460
+ resizePanel(panelData, nextMinSize);
1461
+ } else if (prevPanelSize > nextMaxSize) {
1462
+ resizePanel(panelData, nextMaxSize);
1463
+ }
1464
+ }
1465
+ function startDragging(dragHandleId, event) {
1466
+ const { direction } = committedValuesRef.value;
1467
+ const { layout: layout2 } = eagerValuesRef.value;
1468
+ if (!panelGroupElementRef.value)
1469
+ return;
1470
+ const handleElement = getResizeHandleElement(
1471
+ dragHandleId,
1472
+ panelGroupElementRef.value
1473
+ );
1474
+ assert(handleElement);
1475
+ const initialCursorPosition = getResizeEventCursorPosition(
1476
+ direction,
1477
+ event
1478
+ );
1479
+ dragState.value = {
1480
+ dragHandleId,
1481
+ dragHandleRect: handleElement.getBoundingClientRect(),
1482
+ initialCursorPosition,
1483
+ initialLayout: layout2
1484
+ };
1485
+ }
1486
+ function stopDragging() {
1487
+ dragState.value = null;
1488
+ }
1489
+ function unregisterPanel(panelData) {
1490
+ const { panelDataArray } = eagerValuesRef.value;
1491
+ const index = findPanelDataIndex(panelDataArray, panelData);
1492
+ if (index >= 0) {
1493
+ panelDataArray.splice(index, 1);
1494
+ delete panelIdToLastNotifiedSizeMapRef.value[panelData.id];
1495
+ eagerValuesRef.value.panelDataArrayChanged = true;
1496
+ }
1497
+ }
1498
+ function collapsePanel(panelData) {
1499
+ const { layout: prevLayout, panelDataArray } = eagerValuesRef.value;
1500
+ if (panelData.constraints.collapsible) {
1501
+ const panelConstraintsArray = panelDataArray.map(
1502
+ (panelData2) => panelData2.constraints
1503
+ );
1504
+ const {
1505
+ collapsedSize = 0,
1506
+ panelSize,
1507
+ pivotIndices
1508
+ } = panelDataHelper(panelDataArray, panelData, prevLayout);
1509
+ assert(
1510
+ panelSize != null,
1511
+ `Panel size not found for panel "${panelData.id}"`
1512
+ );
1513
+ if (panelSize !== collapsedSize) {
1514
+ panelSizeBeforeCollapseRef.value.set(panelData.id, panelSize);
1515
+ const isLastPanel = findPanelDataIndex(panelDataArray, panelData) === panelDataArray.length - 1;
1516
+ const delta = isLastPanel ? panelSize - collapsedSize : collapsedSize - panelSize;
1517
+ const nextLayout = adjustLayoutByDelta({
1518
+ delta,
1519
+ layout: prevLayout,
1520
+ panelConstraints: panelConstraintsArray,
1521
+ pivotIndices,
1522
+ trigger: "imperative-api"
1523
+ });
1524
+ if (!compareLayouts(prevLayout, nextLayout)) {
1525
+ setLayout(nextLayout);
1526
+ eagerValuesRef.value.layout = nextLayout;
1527
+ emit("layout", nextLayout);
1528
+ callPanelCallbacks(
1529
+ panelDataArray,
1530
+ nextLayout,
1531
+ panelIdToLastNotifiedSizeMapRef.value
1532
+ );
1533
+ }
1534
+ }
1535
+ }
1536
+ }
1537
+ function expandPanel(panelData) {
1538
+ const { layout: prevLayout, panelDataArray } = eagerValuesRef.value;
1539
+ if (panelData.constraints.collapsible) {
1540
+ const panelConstraintsArray = panelDataArray.map(
1541
+ (panelData2) => panelData2.constraints
1542
+ );
1543
+ const {
1544
+ collapsedSize = 0,
1545
+ panelSize,
1546
+ minSize = 0,
1547
+ pivotIndices
1548
+ } = panelDataHelper(panelDataArray, panelData, prevLayout);
1549
+ if (panelSize === collapsedSize) {
1550
+ const prevPanelSize = panelSizeBeforeCollapseRef.value.get(
1551
+ panelData.id
1552
+ );
1553
+ const baseSize = prevPanelSize != null && prevPanelSize >= minSize ? prevPanelSize : minSize;
1554
+ const isLastPanel = findPanelDataIndex(panelDataArray, panelData) === panelDataArray.length - 1;
1555
+ const delta = isLastPanel ? panelSize - baseSize : baseSize - panelSize;
1556
+ const nextLayout = adjustLayoutByDelta({
1557
+ delta,
1558
+ layout: prevLayout,
1559
+ panelConstraints: panelConstraintsArray,
1560
+ pivotIndices,
1561
+ trigger: "imperative-api"
1562
+ });
1563
+ if (!compareLayouts(prevLayout, nextLayout)) {
1564
+ setLayout(nextLayout);
1565
+ eagerValuesRef.value.layout = nextLayout;
1566
+ emit("layout", nextLayout);
1567
+ callPanelCallbacks(
1568
+ panelDataArray,
1569
+ nextLayout,
1570
+ panelIdToLastNotifiedSizeMapRef.value
1571
+ );
1572
+ }
1573
+ }
1574
+ }
1575
+ }
1576
+ function getPanelSize(panelData) {
1577
+ const { layout: layout2, panelDataArray } = eagerValuesRef.value;
1578
+ const { panelSize } = panelDataHelper(panelDataArray, panelData, layout2);
1579
+ assert(
1580
+ panelSize != null,
1581
+ `Panel size not found for panel "${panelData.id}"`
1582
+ );
1583
+ return panelSize;
1584
+ }
1585
+ function isPanelCollapsed(panelData) {
1586
+ const { layout: layout2, panelDataArray } = eagerValuesRef.value;
1587
+ const {
1588
+ collapsedSize = 0,
1589
+ collapsible,
1590
+ panelSize
1591
+ } = panelDataHelper(panelDataArray, panelData, layout2);
1592
+ return collapsible === true && panelSize === collapsedSize;
1593
+ }
1594
+ function isPanelExpanded(panelData) {
1595
+ const { layout: layout2, panelDataArray } = eagerValuesRef.value;
1596
+ const {
1597
+ collapsedSize = 0,
1598
+ collapsible,
1599
+ panelSize
1600
+ } = panelDataHelper(panelDataArray, panelData, layout2);
1601
+ assert(
1602
+ panelSize != null,
1603
+ `Panel size not found for panel "${panelData.id}"`
1604
+ );
1605
+ return !collapsible || panelSize > collapsedSize;
1606
+ }
1607
+ providePanelGroupContext({
1608
+ direction: props.direction,
1609
+ dragState: dragState.value,
1610
+ groupId,
1611
+ reevaluatePanelConstraints,
1612
+ registerPanel,
1613
+ registerResizeHandle,
1614
+ resizePanel,
1615
+ startDragging,
1616
+ stopDragging,
1617
+ unregisterPanel,
1618
+ panelGroupElement: panelGroupElementRef,
1619
+ collapsePanel,
1620
+ expandPanel,
1621
+ isPanelCollapsed,
1622
+ isPanelExpanded,
1623
+ getPanelSize,
1624
+ getPanelStyle
1625
+ });
1626
+ function findPanelDataIndex(panelDataArray, panelData) {
1627
+ return panelDataArray.findIndex(
1628
+ (prevPanelData) => prevPanelData === panelData || prevPanelData.id === panelData.id
1629
+ );
1630
+ }
1631
+ function panelDataHelper(panelDataArray, panelData, layout2) {
1632
+ const panelIndex = findPanelDataIndex(panelDataArray, panelData);
1633
+ const isLastPanel = panelIndex === panelDataArray.length - 1;
1634
+ const pivotIndices = isLastPanel ? [panelIndex - 1, panelIndex] : [panelIndex, panelIndex + 1];
1635
+ const panelSize = layout2[panelIndex];
1636
+ return {
1637
+ ...panelData.constraints,
1638
+ panelSize,
1639
+ pivotIndices
1640
+ };
1641
+ }
1642
+ return {
1643
+ forwardRef,
1644
+ groupId,
1645
+ layout
1646
+ };
1647
+ },
1648
+ render() {
1649
+ return vue.h(primitive.Primitive, {
1650
+ "as": this.$props.as,
1651
+ "asChild": this.$props.asChild,
1652
+ "ref": (el) => this.forwardRef(el),
1653
+ "style": {
1654
+ display: "flex",
1655
+ flexDirection: this.$props.direction === "horizontal" ? "row" : "column",
1656
+ height: "100%",
1657
+ overflow: "hidden",
1658
+ width: "100%"
1659
+ },
1660
+ "data-panel-group": "",
1661
+ "data-orientation": this.$props.direction,
1662
+ "data-panel-group-id": this.groupId
1663
+ }, () => this.$slots.default?.({ layout: this.layout }));
1664
+ }
1665
+ });
1666
+
1667
+ const splitterResizeHandleProps = {
1668
+ ...primitive.primitiveProps,
1669
+ /**
1670
+ * Resize handle id (unique within group);
1671
+ * falls back to `useId` when not provided
1672
+ */
1673
+ id: {
1674
+ type: String,
1675
+ required: false
1676
+ },
1677
+ /**
1678
+ * Allow this much margin when determining resizable handle hit detection
1679
+ */
1680
+ hitAreaMargins: {
1681
+ type: Object,
1682
+ required: false
1683
+ },
1684
+ /**
1685
+ * Tabindex for the handle
1686
+ *
1687
+ * @default 0
1688
+ */
1689
+ tabindex: {
1690
+ type: Number,
1691
+ required: false,
1692
+ default: 0
1693
+ },
1694
+ /**
1695
+ * Disable drag handle
1696
+ */
1697
+ disabled: {
1698
+ type: Boolean,
1699
+ required: false
1700
+ }
1701
+ };
1702
+ const splitterResizeHandleEmits = {
1703
+ /**
1704
+ * Event handler called when dragging the handler.
1705
+ */
1706
+ dragging: (_isDragging) => true
1707
+ };
1708
+ const SplitterResizeHandle = vue.defineComponent({
1709
+ name: "DestylerSplitterResizeHandle",
1710
+ props: splitterResizeHandleProps,
1711
+ emits: splitterResizeHandleEmits,
1712
+ setup(props, { emit }) {
1713
+ const { forwardRef, currentElement } = composition.useForwardExpose();
1714
+ const { disabled } = vue.toRefs(props);
1715
+ const panelGroupContext = injectPanelGroupContext();
1716
+ if (panelGroupContext === null) {
1717
+ throw new Error(
1718
+ "DestylerSplitterResizeHandle components must be rendered within a PanelGroup container"
1719
+ );
1720
+ }
1721
+ const {
1722
+ direction,
1723
+ groupId,
1724
+ registerResizeHandle: registerResizeHandleWithParentGroup,
1725
+ startDragging,
1726
+ stopDragging,
1727
+ panelGroupElement
1728
+ } = panelGroupContext;
1729
+ const resizeHandleId = composition.useId(props.id, "destyler-splitter-resize-handle");
1730
+ const state = vue.ref("inactive");
1731
+ const isFocused = vue.ref(false);
1732
+ const resizeHandler = vue.ref(null);
1733
+ vue.watch(disabled, () => {
1734
+ if (!shared.isBrowser)
1735
+ return;
1736
+ if (disabled.value)
1737
+ resizeHandler.value = null;
1738
+ else
1739
+ resizeHandler.value = registerResizeHandleWithParentGroup(resizeHandleId);
1740
+ }, { immediate: true });
1741
+ vue.watchEffect((onCleanup) => {
1742
+ if (disabled.value || resizeHandler.value === null)
1743
+ return;
1744
+ const element = currentElement.value;
1745
+ if (!element)
1746
+ return;
1747
+ assert(element);
1748
+ const setResizeHandlerState = (action, isActive, event) => {
1749
+ if (isActive) {
1750
+ switch (action) {
1751
+ case "down": {
1752
+ state.value = "drag";
1753
+ startDragging(resizeHandleId, event);
1754
+ emit("dragging", true);
1755
+ break;
1756
+ }
1757
+ case "move": {
1758
+ if (state.value !== "drag")
1759
+ state.value = "hover";
1760
+ resizeHandler.value?.(event);
1761
+ break;
1762
+ }
1763
+ case "up": {
1764
+ state.value = "hover";
1765
+ stopDragging();
1766
+ emit("dragging", false);
1767
+ break;
1768
+ }
1769
+ }
1770
+ } else {
1771
+ state.value = "inactive";
1772
+ }
1773
+ };
1774
+ onCleanup(registerResizeHandle(
1775
+ resizeHandleId,
1776
+ element,
1777
+ direction,
1778
+ {
1779
+ coarse: props.hitAreaMargins?.coarse ?? 15,
1780
+ fine: props.hitAreaMargins?.fine ?? 5
1781
+ },
1782
+ setResizeHandlerState
1783
+ ));
1784
+ });
1785
+ useWindowSplitterResizeHandlerBehavior({
1786
+ disabled,
1787
+ resizeHandler,
1788
+ handleId: resizeHandleId,
1789
+ panelGroupElement
1790
+ });
1791
+ return {
1792
+ resizeHandleId,
1793
+ disabled,
1794
+ state,
1795
+ direction,
1796
+ groupId,
1797
+ isFocused,
1798
+ forwardRef
1799
+ };
1800
+ },
1801
+ render() {
1802
+ return vue.h(primitive.Primitive, {
1803
+ "id": this.resizeHandleId,
1804
+ "ref": (el) => this.forwardRef(el),
1805
+ "style": {
1806
+ touchAction: "none",
1807
+ userSelect: "none"
1808
+ },
1809
+ "role": "separator",
1810
+ "data-resize-handle": "",
1811
+ "tabindex": this.$props.tabindex,
1812
+ "data-state": this.state,
1813
+ "data-disabled": this.disabled ? "" : void 0,
1814
+ "data-orientation": this.direction,
1815
+ "data-panel-group-id": this.groupId,
1816
+ "data-resize-handle-active": this.state === "drag" ? "pointer" : this.isFocused ? "keyboard" : void 0,
1817
+ "data-resize-handle-state": this.state,
1818
+ "data-panel-resize-handle-enabled": !this.disabled,
1819
+ "data-panel-resize-handle-id": this.resizeHandleId,
1820
+ "onBlur": () => {
1821
+ this.isFocused = false;
1822
+ },
1823
+ "onFocus": () => {
1824
+ this.isFocused = false;
1825
+ }
1826
+ }, () => this.$slots.default?.());
1827
+ }
1828
+ });
1829
+
1830
+ const splitterPanelProps = {
1831
+ ...primitive.primitiveProps,
1832
+ /**
1833
+ * The size of panel when it is collapsed.
1834
+ */
1835
+ collapsedSize: {
1836
+ type: Number,
1837
+ required: false
1838
+ },
1839
+ /**
1840
+ * Should panel collapse when resized beyond its `minSize`. When `true`, it will be collapsed to `collapsedSize`.
1841
+ */
1842
+ collapsible: {
1843
+ type: Boolean,
1844
+ required: false
1845
+ },
1846
+ /**
1847
+ * Initial size of panel (numeric value between 1-100)
1848
+ *
1849
+ * @default false
1850
+ */
1851
+ defaultSize: {
1852
+ type: Number,
1853
+ required: false
1854
+ },
1855
+ /*
1856
+ * Panel id (unique within group);
1857
+ falls back to `useId` when not provided
1858
+ */
1859
+ id: {
1860
+ type: String,
1861
+ required: false
1862
+ },
1863
+ /**
1864
+ * The maximum allowable size of panel (numeric value between 1-100); defaults to `100`
1865
+ */
1866
+ maxSize: {
1867
+ type: Number,
1868
+ required: false
1869
+ },
1870
+ /**
1871
+ * The minimum allowable size of panel (numeric value between 1-100); defaults to `10`
1872
+ */
1873
+ minSize: {
1874
+ type: Number,
1875
+ required: false
1876
+ },
1877
+ /**
1878
+ * The order of panel within group; required for groups with conditionally rendered panels
1879
+ */
1880
+ order: {
1881
+ type: Number,
1882
+ required: false
1883
+ }
1884
+ };
1885
+ const splitterPanelEmits = {
1886
+ /**
1887
+ * Event handler called when panel is collapsed.
1888
+ */
1889
+ collapse: () => true,
1890
+ /**
1891
+ * Event handler called when panel is expanded.
1892
+ */
1893
+ expand: () => true,
1894
+ /**
1895
+ * Event handler called when panel is resized;
1896
+ * size parameter is a numeric value
1897
+ * between 1-100.
1898
+ */
1899
+ resize: (_size, _prevSize) => true
1900
+ };
1901
+ const SplitterPanel = vue.defineComponent({
1902
+ name: "DestylerSplitterPanel",
1903
+ props: splitterPanelProps,
1904
+ emits: splitterPanelEmits,
1905
+ slots: Object,
1906
+ setup(props, { emit, expose }) {
1907
+ const panelGroupContext = injectPanelGroupContext();
1908
+ if (panelGroupContext === null) {
1909
+ throw new Error(
1910
+ "SplitterPanel components must be rendered within a SplitterGroup container"
1911
+ );
1912
+ }
1913
+ const { collapsePanel, expandPanel, getPanelSize, getPanelStyle, isPanelCollapsed, resizePanel, groupId, reevaluatePanelConstraints, registerPanel, unregisterPanel } = panelGroupContext;
1914
+ const panelId = composition.useId(props.id, "destyler-splitter-panel");
1915
+ const panelDataRef = vue.computed(() => ({
1916
+ callbacks: {
1917
+ onCollapse: () => emit("collapse"),
1918
+ onExpand: () => emit("expand"),
1919
+ onResize: (...args) => emit("resize", ...args)
1920
+ },
1921
+ constraints: {
1922
+ collapsedSize: props.collapsedSize,
1923
+ collapsible: props.collapsible,
1924
+ defaultSize: props.defaultSize,
1925
+ maxSize: props.maxSize,
1926
+ minSize: props.minSize
1927
+ },
1928
+ id: panelId,
1929
+ idIsFromProps: props.id !== void 0,
1930
+ order: props.order
1931
+ }));
1932
+ vue.watch(() => panelDataRef.value.constraints, (prevConstraints, constraints) => {
1933
+ if (prevConstraints.collapsedSize !== constraints.collapsedSize || prevConstraints.collapsible !== constraints.collapsible || prevConstraints.maxSize !== constraints.maxSize || prevConstraints.minSize !== constraints.minSize) {
1934
+ reevaluatePanelConstraints(panelDataRef.value, prevConstraints);
1935
+ }
1936
+ }, { deep: true });
1937
+ vue.onMounted(() => {
1938
+ const panelData = panelDataRef.value;
1939
+ registerPanel(panelData);
1940
+ vue.onUnmounted(() => {
1941
+ unregisterPanel(panelData);
1942
+ });
1943
+ });
1944
+ const style = vue.computed(() => getPanelStyle(panelDataRef.value, props.defaultSize));
1945
+ const isCollapsed = vue.computed(() => isPanelCollapsed(panelDataRef.value));
1946
+ const isExpanded = vue.computed(() => !isCollapsed.value);
1947
+ expose({
1948
+ collapse: () => {
1949
+ collapsePanel(panelDataRef.value);
1950
+ },
1951
+ expand: () => {
1952
+ expandPanel(panelDataRef.value);
1953
+ },
1954
+ getSize() {
1955
+ return getPanelSize(panelDataRef.value);
1956
+ },
1957
+ resize: (size) => {
1958
+ resizePanel(panelDataRef.value, size);
1959
+ },
1960
+ isCollapsed,
1961
+ isExpanded
1962
+ });
1963
+ return {
1964
+ groupId,
1965
+ panelId,
1966
+ style,
1967
+ isCollapsed,
1968
+ isExpanded
1969
+ };
1970
+ },
1971
+ render() {
1972
+ return vue.h(primitive.Primitive, {
1973
+ "id": this.groupId,
1974
+ "as": this.$props.as,
1975
+ "asChild": this.$props.asChild,
1976
+ "style": this.style,
1977
+ "data-panel": "",
1978
+ "data-panel-collapsible": this.$props.collapsible || void 0,
1979
+ "data-panel-group-id": this.groupId,
1980
+ "data-panel-id": this.panelId,
1981
+ "data-panel-size": Number.parseFloat(`${this.style.flexGrow}`).toFixed(1)
1982
+ }, () => this.$slots.default?.({ isCollapsed: this.isCollapsed, isExpanded: this.isExpanded }));
1983
+ }
1984
+ });
1985
+
1986
+ const splitterRootProps = {
1987
+ ...primitive.primitiveProps
1988
+ };
1989
+ const SplitterRoot = vue.defineComponent({
1990
+ name: "DestylerSplitterRoot",
1991
+ props: splitterRootProps,
1992
+ setup(_) {
1993
+ composition.useForwardExpose();
1994
+ },
1995
+ render() {
1996
+ return vue.h(primitive.Primitive, {
1997
+ as: this.$props.as,
1998
+ asChild: this.$props.asChild
1999
+ }, () => this.$slots.default?.());
2000
+ }
2001
+ });
2002
+
2003
+ exports.SplitterGroup = SplitterGroup;
2004
+ exports.SplitterPanel = SplitterPanel;
2005
+ exports.SplitterResizeHandle = SplitterResizeHandle;
2006
+ exports.SplitterRoot = SplitterRoot;
2007
+ exports.splitterGroupEmits = splitterGroupEmits;
2008
+ exports.splitterGroupProps = splitterGroupProps;
2009
+ exports.splitterPanelEmits = splitterPanelEmits;
2010
+ exports.splitterPanelProps = splitterPanelProps;
2011
+ exports.splitterResizeHandleEmits = splitterResizeHandleEmits;
2012
+ exports.splitterResizeHandleProps = splitterResizeHandleProps;
2013
+ exports.splitterRootProps = splitterRootProps;