@zag-js/splitter 0.2.5 → 0.2.7

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.
@@ -0,0 +1,792 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/splitter.machine.ts
21
+ var splitter_machine_exports = {};
22
+ __export(splitter_machine_exports, {
23
+ machine: () => machine
24
+ });
25
+ module.exports = __toCommonJS(splitter_machine_exports);
26
+ var import_core = require("@zag-js/core");
27
+
28
+ // ../../utilities/core/src/functions.ts
29
+ var runIfFn = (v, ...a) => {
30
+ const res = typeof v === "function" ? v(...a) : v;
31
+ return res != null ? res : void 0;
32
+ };
33
+ var callAll = (...fns) => (...a) => {
34
+ fns.forEach(function(fn) {
35
+ fn == null ? void 0 : fn(...a);
36
+ });
37
+ };
38
+
39
+ // ../../utilities/core/src/guard.ts
40
+ var isArray = (v) => Array.isArray(v);
41
+ var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
42
+ var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
43
+
44
+ // ../../utilities/core/src/object.ts
45
+ function compact(obj) {
46
+ if (obj === void 0)
47
+ return obj;
48
+ return Object.fromEntries(
49
+ Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value])
50
+ );
51
+ }
52
+
53
+ // ../../utilities/dom/src/platform.ts
54
+ var isDom = () => typeof window !== "undefined";
55
+ function getPlatform() {
56
+ var _a;
57
+ const agent = navigator.userAgentData;
58
+ return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
59
+ }
60
+ var pt = (v) => isDom() && v.test(getPlatform());
61
+ var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
62
+ var isMac = () => pt(/^Mac/) && !isTouchDevice;
63
+ var isApple = () => pt(/mac|iphone|ipad|ipod/i);
64
+ var isIos = () => isApple() && !isMac();
65
+
66
+ // ../../utilities/dom/src/query.ts
67
+ function isDocument(el) {
68
+ return el.nodeType === Node.DOCUMENT_NODE;
69
+ }
70
+ function isWindow(value) {
71
+ return (value == null ? void 0 : value.toString()) === "[object Window]";
72
+ }
73
+ function getDocument(el) {
74
+ var _a;
75
+ if (isWindow(el))
76
+ return el.document;
77
+ if (isDocument(el))
78
+ return el;
79
+ return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
80
+ }
81
+ function defineDomHelpers(helpers) {
82
+ const dom2 = {
83
+ getRootNode: (ctx) => {
84
+ var _a, _b;
85
+ return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
86
+ },
87
+ getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
88
+ getWin: (ctx) => {
89
+ var _a;
90
+ return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
91
+ },
92
+ getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
93
+ getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
94
+ };
95
+ return {
96
+ ...dom2,
97
+ ...helpers
98
+ };
99
+ }
100
+
101
+ // ../../utilities/dom/src/event.ts
102
+ var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
103
+ var supportsTouchEvent = () => isDom() && window.ontouchstart === null;
104
+ var supportsMouseEvent = () => isDom() && window.onmousedown === null;
105
+ var isMouseEvent = (v) => isObject(v) && hasProp(v, "button");
106
+ var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
107
+ var isLeftClick = (v) => v.button === 0;
108
+
109
+ // ../../utilities/dom/src/get-element-offset.ts
110
+ function getElementOffset(element) {
111
+ let left = 0;
112
+ let top = 0;
113
+ let el = element;
114
+ if (el.parentNode) {
115
+ do {
116
+ left += el.offsetLeft;
117
+ top += el.offsetTop;
118
+ } while ((el = el.offsetParent) && el.nodeType < 9);
119
+ el = element;
120
+ do {
121
+ left -= el.scrollLeft;
122
+ top -= el.scrollTop;
123
+ } while ((el = el.parentNode) && !/body/i.test(el.nodeName));
124
+ }
125
+ return {
126
+ top,
127
+ right: innerWidth - left - element.offsetWidth,
128
+ bottom: innerHeight - top - element.offsetHeight,
129
+ left
130
+ };
131
+ }
132
+
133
+ // ../../utilities/dom/src/get-point-relative-to-element.ts
134
+ function getPointRelativeToNode(point, element) {
135
+ const offset = getElementOffset(element);
136
+ const x = point.x - offset.left;
137
+ const y = point.y - offset.top;
138
+ return { x, y };
139
+ }
140
+ var clampPercent = (value) => Math.max(0, Math.min(100, value));
141
+ function getPointPercentRelativeToNode(point, element) {
142
+ const relativePoint = getPointRelativeToNode(point, element);
143
+ const x = relativePoint.x / element.offsetWidth * 100;
144
+ const y = relativePoint.y / element.offsetHeight * 100;
145
+ return { x: clampPercent(x), y: clampPercent(y) };
146
+ }
147
+ function normalizePointValue(point, options) {
148
+ const { dir = "ltr", orientation = "horizontal" } = options;
149
+ const { x, y } = point;
150
+ let result = { x, y };
151
+ if (orientation === "horizontal" && dir === "rtl") {
152
+ result = { x: 100 - x, y };
153
+ }
154
+ return orientation === "horizontal" ? result.x : result.y;
155
+ }
156
+
157
+ // ../../utilities/dom/src/listener.ts
158
+ var isRef = (v) => hasProp(v, "current");
159
+ var fallback = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
160
+ function extractInfo(event, type = "page") {
161
+ const point = isTouchEvent(event) ? event.touches[0] || event.changedTouches[0] || fallback : event;
162
+ return {
163
+ point: {
164
+ x: point[`${type}X`],
165
+ y: point[`${type}Y`]
166
+ }
167
+ };
168
+ }
169
+ function addDomEvent(target, eventName, handler, options) {
170
+ const node = isRef(target) ? target.current : runIfFn(target);
171
+ node == null ? void 0 : node.addEventListener(eventName, handler, options);
172
+ return () => {
173
+ node == null ? void 0 : node.removeEventListener(eventName, handler, options);
174
+ };
175
+ }
176
+ function addPointerEvent(target, event, listener, options) {
177
+ var _a;
178
+ const type = (_a = getEventName(event)) != null ? _a : event;
179
+ return addDomEvent(target, type, wrapHandler(listener, event === "pointerdown"), options);
180
+ }
181
+ function wrapHandler(fn, filter = false) {
182
+ const listener = (event) => {
183
+ fn(event, extractInfo(event));
184
+ };
185
+ return filter ? filterPrimaryPointer(listener) : listener;
186
+ }
187
+ function filterPrimaryPointer(fn) {
188
+ return (event) => {
189
+ var _a;
190
+ const win = (_a = event.view) != null ? _a : window;
191
+ const isMouseEvent2 = event instanceof win.MouseEvent;
192
+ const isPrimary = !isMouseEvent2 || isMouseEvent2 && event.button === 0;
193
+ if (isPrimary)
194
+ fn(event);
195
+ };
196
+ }
197
+ var mouseEventNames = {
198
+ pointerdown: "mousedown",
199
+ pointermove: "mousemove",
200
+ pointerup: "mouseup",
201
+ pointercancel: "mousecancel",
202
+ pointerover: "mouseover",
203
+ pointerout: "mouseout",
204
+ pointerenter: "mouseenter",
205
+ pointerleave: "mouseleave"
206
+ };
207
+ var touchEventNames = {
208
+ pointerdown: "touchstart",
209
+ pointermove: "touchmove",
210
+ pointerup: "touchend",
211
+ pointercancel: "touchcancel"
212
+ };
213
+ function getEventName(evt) {
214
+ if (supportsPointerEvent())
215
+ return evt;
216
+ if (supportsTouchEvent())
217
+ return touchEventNames[evt];
218
+ if (supportsMouseEvent())
219
+ return mouseEventNames[evt];
220
+ return evt;
221
+ }
222
+
223
+ // ../../utilities/dom/src/next-tick.ts
224
+ function nextTick(fn) {
225
+ const set = /* @__PURE__ */ new Set();
226
+ function raf2(fn2) {
227
+ const id = globalThis.requestAnimationFrame(fn2);
228
+ set.add(() => globalThis.cancelAnimationFrame(id));
229
+ }
230
+ raf2(() => raf2(fn));
231
+ return function cleanup() {
232
+ set.forEach(function(fn2) {
233
+ fn2();
234
+ });
235
+ };
236
+ }
237
+ function raf(fn) {
238
+ const id = globalThis.requestAnimationFrame(fn);
239
+ return function cleanup() {
240
+ globalThis.cancelAnimationFrame(id);
241
+ };
242
+ }
243
+
244
+ // ../../utilities/dom/src/nodelist.ts
245
+ function queryAll(root, selector) {
246
+ var _a;
247
+ return Array.from((_a = root == null ? void 0 : root.querySelectorAll(selector)) != null ? _a : []);
248
+ }
249
+
250
+ // ../../utilities/dom/src/text-selection.ts
251
+ var state = "default";
252
+ var savedUserSelect = "";
253
+ var modifiedElementMap = /* @__PURE__ */ new WeakMap();
254
+ function disableTextSelection({ target, doc } = {}) {
255
+ const _document = doc != null ? doc : document;
256
+ if (isIos()) {
257
+ if (state === "default") {
258
+ savedUserSelect = _document.documentElement.style.webkitUserSelect;
259
+ _document.documentElement.style.webkitUserSelect = "none";
260
+ }
261
+ state = "disabled";
262
+ } else if (target) {
263
+ modifiedElementMap.set(target, target.style.userSelect);
264
+ target.style.userSelect = "none";
265
+ }
266
+ return () => restoreTextSelection({ target, doc: _document });
267
+ }
268
+ function restoreTextSelection({ target, doc } = {}) {
269
+ const _document = doc != null ? doc : document;
270
+ if (isIos()) {
271
+ if (state !== "disabled")
272
+ return;
273
+ state = "restoring";
274
+ setTimeout(() => {
275
+ nextTick(() => {
276
+ if (state === "restoring") {
277
+ if (_document.documentElement.style.webkitUserSelect === "none") {
278
+ _document.documentElement.style.webkitUserSelect = savedUserSelect || "";
279
+ }
280
+ savedUserSelect = "";
281
+ state = "default";
282
+ }
283
+ });
284
+ }, 300);
285
+ } else {
286
+ if (target && modifiedElementMap.has(target)) {
287
+ let targetOldUserSelect = modifiedElementMap.get(target);
288
+ if (target.style.userSelect === "none") {
289
+ target.style.userSelect = targetOldUserSelect != null ? targetOldUserSelect : "";
290
+ }
291
+ if (target.getAttribute("style") === "") {
292
+ target.removeAttribute("style");
293
+ }
294
+ modifiedElementMap.delete(target);
295
+ }
296
+ }
297
+ }
298
+
299
+ // ../../utilities/dom/src/pointer-event.ts
300
+ var THRESHOLD = 5;
301
+ function trackPointerMove(doc, opts) {
302
+ const { onPointerMove, onPointerUp } = opts;
303
+ const handlePointerMove = (event, info) => {
304
+ const { point: p } = info;
305
+ const distance = Math.sqrt(p.x ** 2 + p.y ** 2);
306
+ if (distance < THRESHOLD)
307
+ return;
308
+ if (isMouseEvent(event) && isLeftClick(event)) {
309
+ onPointerUp();
310
+ return;
311
+ }
312
+ onPointerMove(info, event);
313
+ };
314
+ return callAll(
315
+ addPointerEvent(doc, "pointermove", handlePointerMove, false),
316
+ addPointerEvent(doc, "pointerup", onPointerUp, false),
317
+ addPointerEvent(doc, "pointercancel", onPointerUp, false),
318
+ addPointerEvent(doc, "contextmenu", onPointerUp, false),
319
+ disableTextSelection({ doc })
320
+ );
321
+ }
322
+
323
+ // src/splitter.dom.ts
324
+ var dom = defineDomHelpers({
325
+ getRootId: (ctx) => `splitter:${ctx.id}`,
326
+ getResizeTriggerId: (ctx, id) => `splitter:${ctx.id}:splitter:${id}`,
327
+ getToggleTriggerId: (ctx) => `splitter:${ctx.id}:toggle-btn`,
328
+ getLabelId: (ctx) => `splitter:${ctx.id}:label`,
329
+ getPanelId: (ctx, id) => `splitter:${ctx.id}:panel:${id}`,
330
+ globalCursorId: (ctx) => `splitter:${ctx.id}:global-cursor`,
331
+ getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
332
+ getResizeTriggerEl: (ctx, id) => dom.getById(ctx, dom.getResizeTriggerId(ctx, id)),
333
+ getPanelEl: (ctx, id) => dom.getById(ctx, dom.getPanelId(ctx, id)),
334
+ getCursor(ctx) {
335
+ const x = ctx.isHorizontal;
336
+ let cursor = x ? "col-resize" : "row-resize";
337
+ if (ctx.activeResizeState.isAtMin)
338
+ cursor = x ? "e-resize" : "s-resize";
339
+ if (ctx.activeResizeState.isAtMax)
340
+ cursor = x ? "w-resize" : "n-resize";
341
+ return cursor;
342
+ },
343
+ getPanelStyle(ctx, id) {
344
+ var _a, _b;
345
+ const flexGrow = (_b = (_a = ctx.panels.find((panel) => panel.id === id)) == null ? void 0 : _a.size) != null ? _b : "0";
346
+ return {
347
+ flexBasis: 0,
348
+ flexGrow,
349
+ flexShrink: 1,
350
+ overflow: "hidden"
351
+ };
352
+ },
353
+ getActiveHandleEl(ctx) {
354
+ const activeId = ctx.activeResizeId;
355
+ if (activeId == null)
356
+ return;
357
+ return dom.getById(ctx, dom.getResizeTriggerId(ctx, activeId));
358
+ },
359
+ getResizeTriggerEls(ctx) {
360
+ const ownerId = CSS.escape(dom.getRootId(ctx));
361
+ return queryAll(dom.getRootEl(ctx), `[role=separator][data-ownedby='${ownerId}']`);
362
+ },
363
+ setupGlobalCursor(ctx) {
364
+ const styleEl = dom.getById(ctx, dom.globalCursorId(ctx));
365
+ const textContent = `* { cursor: ${dom.getCursor(ctx)} !important; }`;
366
+ if (styleEl) {
367
+ styleEl.textContent = textContent;
368
+ } else {
369
+ const style = dom.getDoc(ctx).createElement("style");
370
+ style.id = dom.globalCursorId(ctx);
371
+ style.textContent = textContent;
372
+ dom.getDoc(ctx).head.appendChild(style);
373
+ }
374
+ },
375
+ removeGlobalCursor(ctx) {
376
+ var _a;
377
+ (_a = dom.getById(ctx, dom.globalCursorId(ctx))) == null ? void 0 : _a.remove();
378
+ }
379
+ });
380
+
381
+ // src/splitter.utils.ts
382
+ function validateSize(key, size) {
383
+ if (Math.floor(size) > 100) {
384
+ throw new Error(`Total ${key} of panels cannot be greater than 100`);
385
+ }
386
+ }
387
+ function getNormalizedPanels(ctx) {
388
+ let numOfPanelsWithoutSize = 0;
389
+ let totalSize = 0;
390
+ let totalMinSize = 0;
391
+ const panels = ctx.size.map((panel) => {
392
+ var _a, _b;
393
+ const minSize = (_a = panel.minSize) != null ? _a : 10;
394
+ const maxSize = (_b = panel.maxSize) != null ? _b : 100;
395
+ totalMinSize += minSize;
396
+ if (panel.size == null) {
397
+ numOfPanelsWithoutSize++;
398
+ } else {
399
+ totalSize += panel.size;
400
+ }
401
+ return {
402
+ ...panel,
403
+ minSize,
404
+ maxSize
405
+ };
406
+ });
407
+ validateSize("minSize", totalMinSize);
408
+ validateSize("size", totalSize);
409
+ let end = 0;
410
+ let remainingSize = 0;
411
+ const result = panels.map((panel) => {
412
+ let start = end;
413
+ if (panel.size != null) {
414
+ end += panel.size;
415
+ remainingSize = panel.size - panel.minSize;
416
+ return {
417
+ ...panel,
418
+ start,
419
+ end,
420
+ remainingSize
421
+ };
422
+ }
423
+ const size = (100 - totalSize) / numOfPanelsWithoutSize;
424
+ end += size;
425
+ remainingSize = size - panel.minSize;
426
+ return { ...panel, size, start, end, remainingSize };
427
+ });
428
+ return result;
429
+ }
430
+ function getHandlePanels(ctx, id = ctx.activeResizeId) {
431
+ var _a;
432
+ const [beforeId, afterId] = (_a = id == null ? void 0 : id.split(":")) != null ? _a : [];
433
+ if (!beforeId || !afterId)
434
+ return;
435
+ const beforeIndex = ctx.previousPanels.findIndex((panel) => panel.id === beforeId);
436
+ const afterIndex = ctx.previousPanels.findIndex((panel) => panel.id === afterId);
437
+ if (beforeIndex === -1 || afterIndex === -1)
438
+ return;
439
+ const before = ctx.previousPanels[beforeIndex];
440
+ const after = ctx.previousPanels[afterIndex];
441
+ return {
442
+ before: {
443
+ ...before,
444
+ index: beforeIndex
445
+ },
446
+ after: {
447
+ ...after,
448
+ index: afterIndex
449
+ }
450
+ };
451
+ }
452
+ function getHandleBounds(ctx, id = ctx.activeResizeId) {
453
+ const panels = getHandlePanels(ctx, id);
454
+ if (!panels)
455
+ return;
456
+ const { before, after } = panels;
457
+ return {
458
+ min: Math.max(before.start + before.minSize, after.end - after.maxSize),
459
+ max: Math.min(after.end - after.minSize, before.maxSize + before.start)
460
+ };
461
+ }
462
+ function getPanelBounds(ctx, id) {
463
+ const bounds = getHandleBounds(ctx, id);
464
+ const panels = getHandlePanels(ctx, id);
465
+ if (!bounds || !panels)
466
+ return;
467
+ const { before, after } = panels;
468
+ const beforeMin = Math.abs(before.start - bounds.min);
469
+ const afterMin = after.size + (before.size - beforeMin);
470
+ const beforeMax = Math.abs(before.start - bounds.max);
471
+ const afterMax = after.size - (beforeMax - before.size);
472
+ return {
473
+ before: {
474
+ index: before.index,
475
+ min: beforeMin,
476
+ max: beforeMax,
477
+ isAtMin: beforeMin === before.size,
478
+ isAtMax: beforeMax === before.size,
479
+ up(step) {
480
+ return Math.min(before.size + step, beforeMax);
481
+ },
482
+ down(step) {
483
+ return Math.max(before.size - step, beforeMin);
484
+ }
485
+ },
486
+ after: {
487
+ index: after.index,
488
+ min: afterMin,
489
+ max: afterMax,
490
+ isAtMin: afterMin === after.size,
491
+ isAtMax: afterMax === after.size,
492
+ up(step) {
493
+ return Math.min(after.size + step, afterMin);
494
+ },
495
+ down(step) {
496
+ return Math.max(after.size - step, afterMax);
497
+ }
498
+ }
499
+ };
500
+ }
501
+ function clamp(value, min, max) {
502
+ return Math.min(Math.max(value, min), max);
503
+ }
504
+
505
+ // src/splitter.machine.ts
506
+ function machine(userContext) {
507
+ const ctx = compact(userContext);
508
+ return (0, import_core.createMachine)(
509
+ {
510
+ id: "splitter",
511
+ initial: "unknown",
512
+ context: {
513
+ orientation: "horizontal",
514
+ activeResizeId: null,
515
+ previousPanels: [],
516
+ size: [],
517
+ initialSize: [],
518
+ activeResizeState: {
519
+ isAtMin: false,
520
+ isAtMax: false
521
+ },
522
+ ...ctx
523
+ },
524
+ created: ["setPreviousPanels", "setInitialSize"],
525
+ watch: {
526
+ size: ["setActiveResizeState"]
527
+ },
528
+ computed: {
529
+ isHorizontal: (ctx2) => ctx2.orientation === "horizontal",
530
+ panels: (ctx2) => getNormalizedPanels(ctx2)
531
+ },
532
+ on: {
533
+ COLLAPSE: {
534
+ actions: "setStartPanelToMin"
535
+ },
536
+ EXPAND: {
537
+ actions: "setStartPanelToMax"
538
+ },
539
+ TOGGLE: [
540
+ {
541
+ guard: "isStartPanelAtMin",
542
+ actions: "setStartPanelToMax"
543
+ },
544
+ {
545
+ actions: "setStartPanelToMin"
546
+ }
547
+ ]
548
+ },
549
+ states: {
550
+ unknown: {
551
+ on: {
552
+ SETUP: "idle"
553
+ }
554
+ },
555
+ idle: {
556
+ entry: ["clearActiveHandleId"],
557
+ on: {
558
+ POINTER_OVER: {
559
+ target: "hover:temp",
560
+ actions: ["setActiveHandleId"]
561
+ },
562
+ FOCUS: {
563
+ target: "focused",
564
+ actions: ["setActiveHandleId"]
565
+ },
566
+ DOUBLE_CLICK: {
567
+ actions: ["resetStartPanel", "setPreviousPanels"]
568
+ }
569
+ }
570
+ },
571
+ "hover:temp": {
572
+ after: {
573
+ HOVER_DELAY: "hover"
574
+ },
575
+ on: {
576
+ POINTER_DOWN: {
577
+ target: "dragging",
578
+ actions: ["setActiveHandleId", "invokeOnResizeStart"]
579
+ },
580
+ POINTER_LEAVE: "idle"
581
+ }
582
+ },
583
+ hover: {
584
+ tags: ["focus"],
585
+ on: {
586
+ POINTER_DOWN: {
587
+ target: "dragging",
588
+ actions: ["invokeOnResizeStart"]
589
+ },
590
+ POINTER_LEAVE: "idle"
591
+ }
592
+ },
593
+ focused: {
594
+ tags: ["focus"],
595
+ on: {
596
+ BLUR: "idle",
597
+ POINTER_DOWN: {
598
+ target: "dragging",
599
+ actions: ["setActiveHandleId", "invokeOnResizeStart"]
600
+ },
601
+ ARROW_LEFT: {
602
+ guard: "isHorizontal",
603
+ actions: ["shrinkStartPanel", "setPreviousPanels"]
604
+ },
605
+ ARROW_RIGHT: {
606
+ guard: "isHorizontal",
607
+ actions: ["expandStartPanel", "setPreviousPanels"]
608
+ },
609
+ ARROW_UP: {
610
+ guard: "isVertical",
611
+ actions: ["shrinkStartPanel", "setPreviousPanels"]
612
+ },
613
+ ARROW_DOWN: {
614
+ guard: "isVertical",
615
+ actions: ["expandStartPanel", "setPreviousPanels"]
616
+ },
617
+ ENTER: [
618
+ {
619
+ guard: "isStartPanelAtMax",
620
+ actions: ["setStartPanelToMin", "setPreviousPanels"]
621
+ },
622
+ { actions: ["setStartPanelToMax", "setPreviousPanels"] }
623
+ ],
624
+ HOME: {
625
+ actions: ["setStartPanelToMin", "setPreviousPanels"]
626
+ },
627
+ END: {
628
+ actions: ["setStartPanelToMax", "setPreviousPanels"]
629
+ }
630
+ }
631
+ },
632
+ dragging: {
633
+ tags: ["focus"],
634
+ entry: "focusResizeHandle",
635
+ activities: ["trackPointerMove"],
636
+ on: {
637
+ POINTER_MOVE: {
638
+ actions: ["setPointerValue", "setGlobalCursor"]
639
+ },
640
+ POINTER_UP: {
641
+ target: "focused",
642
+ actions: ["invokeOnResizeEnd", "setPreviousPanels", "clearGlobalCursor", "blurResizeHandle"]
643
+ }
644
+ }
645
+ }
646
+ }
647
+ },
648
+ {
649
+ activities: {
650
+ trackPointerMove: (ctx2, _evt, { send }) => {
651
+ const doc = dom.getDoc(ctx2);
652
+ return trackPointerMove(doc, {
653
+ onPointerMove(info) {
654
+ send({ type: "POINTER_MOVE", point: info.point });
655
+ },
656
+ onPointerUp() {
657
+ send("POINTER_UP");
658
+ }
659
+ });
660
+ }
661
+ },
662
+ guards: {
663
+ isStartPanelAtMin: (ctx2) => ctx2.activeResizeState.isAtMin,
664
+ isStartPanelAtMax: (ctx2) => ctx2.activeResizeState.isAtMax,
665
+ isHorizontal: (ctx2) => ctx2.isHorizontal,
666
+ isVertical: (ctx2) => !ctx2.isHorizontal
667
+ },
668
+ delays: {
669
+ HOVER_DELAY: 250
670
+ },
671
+ actions: {
672
+ setGlobalCursor(ctx2) {
673
+ dom.setupGlobalCursor(ctx2);
674
+ },
675
+ clearGlobalCursor(ctx2) {
676
+ dom.removeGlobalCursor(ctx2);
677
+ },
678
+ invokeOnResize(ctx2) {
679
+ var _a;
680
+ (_a = ctx2.onResize) == null ? void 0 : _a.call(ctx2, { size: ctx2.size, activeHandleId: ctx2.activeResizeId });
681
+ },
682
+ invokeOnResizeStart(ctx2) {
683
+ var _a;
684
+ (_a = ctx2.onResizeStart) == null ? void 0 : _a.call(ctx2, { size: ctx2.size, activeHandleId: ctx2.activeResizeId });
685
+ },
686
+ invokeOnResizeEnd(ctx2) {
687
+ var _a;
688
+ (_a = ctx2.onResizeEnd) == null ? void 0 : _a.call(ctx2, { size: ctx2.size, activeHandleId: ctx2.activeResizeId });
689
+ },
690
+ setActiveHandleId(ctx2, evt) {
691
+ ctx2.activeResizeId = evt.id;
692
+ },
693
+ clearActiveHandleId(ctx2) {
694
+ ctx2.activeResizeId = null;
695
+ },
696
+ setInitialSize(ctx2) {
697
+ ctx2.initialSize = ctx2.panels.slice().map((panel) => ({
698
+ id: panel.id,
699
+ size: panel.size
700
+ }));
701
+ },
702
+ setStartPanelToMin(ctx2) {
703
+ const bounds = getPanelBounds(ctx2);
704
+ if (!bounds)
705
+ return;
706
+ const { before, after } = bounds;
707
+ ctx2.size[before.index].size = before.min;
708
+ ctx2.size[after.index].size = after.min;
709
+ },
710
+ setStartPanelToMax(ctx2) {
711
+ const bounds = getPanelBounds(ctx2);
712
+ if (!bounds)
713
+ return;
714
+ const { before, after } = bounds;
715
+ ctx2.size[before.index].size = before.max;
716
+ ctx2.size[after.index].size = after.max;
717
+ },
718
+ expandStartPanel(ctx2, evt) {
719
+ const bounds = getPanelBounds(ctx2);
720
+ if (!bounds)
721
+ return;
722
+ const { before, after } = bounds;
723
+ ctx2.size[before.index].size = before.up(evt.step);
724
+ ctx2.size[after.index].size = after.down(evt.step);
725
+ },
726
+ shrinkStartPanel(ctx2, evt) {
727
+ const bounds = getPanelBounds(ctx2);
728
+ if (!bounds)
729
+ return;
730
+ const { before, after } = bounds;
731
+ ctx2.size[before.index].size = before.down(evt.step);
732
+ ctx2.size[after.index].size = after.up(evt.step);
733
+ },
734
+ resetStartPanel(ctx2, evt) {
735
+ const bounds = getPanelBounds(ctx2, evt.id);
736
+ if (!bounds)
737
+ return;
738
+ const { before, after } = bounds;
739
+ ctx2.size[before.index].size = ctx2.initialSize[before.index].size;
740
+ ctx2.size[after.index].size = ctx2.initialSize[after.index].size;
741
+ },
742
+ focusResizeHandle(ctx2) {
743
+ raf(() => {
744
+ var _a;
745
+ (_a = dom.getActiveHandleEl(ctx2)) == null ? void 0 : _a.focus();
746
+ });
747
+ },
748
+ blurResizeHandle(ctx2) {
749
+ raf(() => {
750
+ var _a;
751
+ (_a = dom.getActiveHandleEl(ctx2)) == null ? void 0 : _a.blur();
752
+ });
753
+ },
754
+ setPreviousPanels(ctx2) {
755
+ ctx2.previousPanels = ctx2.panels.slice();
756
+ },
757
+ setActiveResizeState(ctx2) {
758
+ const panels = getPanelBounds(ctx2);
759
+ if (!panels)
760
+ return;
761
+ const { before } = panels;
762
+ ctx2.activeResizeState = {
763
+ isAtMin: before.isAtMin,
764
+ isAtMax: before.isAtMax
765
+ };
766
+ },
767
+ setPointerValue(ctx2, evt) {
768
+ const panels = getHandlePanels(ctx2);
769
+ const bounds = getHandleBounds(ctx2);
770
+ const rootEl = dom.getRootEl(ctx2);
771
+ if (!panels || !rootEl || !bounds)
772
+ return;
773
+ const percent = getPointPercentRelativeToNode(evt.point, rootEl);
774
+ let pointValue = normalizePointValue(percent, ctx2);
775
+ ctx2.activeResizeState = {
776
+ isAtMin: pointValue < bounds.min,
777
+ isAtMax: pointValue > bounds.max
778
+ };
779
+ pointValue = clamp(pointValue, bounds.min, bounds.max);
780
+ const { before, after } = panels;
781
+ const offset = pointValue - before.end;
782
+ ctx2.size[before.index].size = before.size + offset;
783
+ ctx2.size[after.index].size = after.size - offset;
784
+ }
785
+ }
786
+ }
787
+ );
788
+ }
789
+ // Annotate the CommonJS export names for ESM import in node:
790
+ 0 && (module.exports = {
791
+ machine
792
+ });