@zag-js/splitter 1.34.1 → 1.35.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/dist/index.d.mts +9 -254
  2. package/dist/index.d.ts +9 -254
  3. package/dist/index.js +37 -1158
  4. package/dist/index.mjs +11 -1151
  5. package/dist/splitter.anatomy.d.mts +6 -0
  6. package/dist/splitter.anatomy.d.ts +6 -0
  7. package/dist/splitter.anatomy.js +34 -0
  8. package/dist/splitter.anatomy.mjs +8 -0
  9. package/dist/splitter.connect.d.mts +7 -0
  10. package/dist/splitter.connect.d.ts +7 -0
  11. package/dist/splitter.connect.js +298 -0
  12. package/dist/splitter.connect.mjs +263 -0
  13. package/dist/splitter.dom.d.mts +19 -0
  14. package/dist/splitter.dom.d.ts +19 -0
  15. package/dist/splitter.dom.js +89 -0
  16. package/dist/splitter.dom.mjs +52 -0
  17. package/dist/splitter.machine.d.mts +7 -0
  18. package/dist/splitter.machine.d.ts +7 -0
  19. package/dist/splitter.machine.js +509 -0
  20. package/dist/splitter.machine.mjs +482 -0
  21. package/dist/splitter.props.d.mts +12 -0
  22. package/dist/splitter.props.d.ts +12 -0
  23. package/dist/splitter.props.js +63 -0
  24. package/dist/splitter.props.mjs +33 -0
  25. package/dist/splitter.types.d.mts +237 -0
  26. package/dist/splitter.types.d.ts +237 -0
  27. package/dist/splitter.types.js +18 -0
  28. package/dist/splitter.types.mjs +0 -0
  29. package/dist/utils/aria.d.mts +27 -0
  30. package/dist/utils/aria.d.ts +27 -0
  31. package/dist/utils/aria.js +79 -0
  32. package/dist/utils/aria.mjs +53 -0
  33. package/dist/utils/fuzzy.d.mts +10 -0
  34. package/dist/utils/fuzzy.d.ts +10 -0
  35. package/dist/utils/fuzzy.js +60 -0
  36. package/dist/utils/fuzzy.mjs +32 -0
  37. package/dist/utils/panel.d.mts +34 -0
  38. package/dist/utils/panel.d.ts +34 -0
  39. package/dist/utils/panel.js +147 -0
  40. package/dist/utils/panel.mjs +114 -0
  41. package/dist/utils/resize-by-delta.d.mts +20 -0
  42. package/dist/utils/resize-by-delta.d.ts +20 -0
  43. package/dist/utils/resize-by-delta.js +165 -0
  44. package/dist/utils/resize-by-delta.mjs +140 -0
  45. package/dist/utils/resize-panel.d.mts +16 -0
  46. package/dist/utils/resize-panel.d.ts +16 -0
  47. package/dist/utils/resize-panel.js +51 -0
  48. package/dist/utils/resize-panel.mjs +26 -0
  49. package/dist/utils/validate-sizes.d.mts +15 -0
  50. package/dist/utils/validate-sizes.d.ts +15 -0
  51. package/dist/utils/validate-sizes.js +72 -0
  52. package/dist/utils/validate-sizes.mjs +47 -0
  53. package/package.json +17 -7
@@ -0,0 +1,89 @@
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.dom.ts
21
+ var splitter_dom_exports = {};
22
+ __export(splitter_dom_exports, {
23
+ getCursor: () => getCursor,
24
+ getGlobalCursorId: () => getGlobalCursorId,
25
+ getLabelId: () => getLabelId,
26
+ getPanelEl: () => getPanelEl,
27
+ getPanelEls: () => getPanelEls,
28
+ getPanelId: () => getPanelId,
29
+ getResizeTriggerEl: () => getResizeTriggerEl,
30
+ getResizeTriggerEls: () => getResizeTriggerEls,
31
+ getResizeTriggerId: () => getResizeTriggerId,
32
+ getRootEl: () => getRootEl,
33
+ getRootId: () => getRootId,
34
+ removeGlobalCursor: () => removeGlobalCursor,
35
+ setupGlobalCursor: () => setupGlobalCursor
36
+ });
37
+ module.exports = __toCommonJS(splitter_dom_exports);
38
+ var import_dom_query = require("@zag-js/dom-query");
39
+ var getRootId = (ctx) => ctx.ids?.root ?? `splitter:${ctx.id}`;
40
+ var getResizeTriggerId = (ctx, id) => ctx.ids?.resizeTrigger?.(id) ?? `splitter:${ctx.id}:splitter:${id}`;
41
+ var getLabelId = (ctx) => ctx.ids?.label ?? `splitter:${ctx.id}:label`;
42
+ var getPanelId = (ctx, id) => ctx.ids?.panel?.(id) ?? `splitter:${ctx.id}:panel:${id}`;
43
+ var getPanelEls = (ctx) => (0, import_dom_query.queryAll)(getRootEl(ctx), `[data-part=panel][data-ownedby=${getRootId(ctx)}]`);
44
+ var getGlobalCursorId = (ctx) => `splitter:${ctx.id}:global-cursor`;
45
+ var getRootEl = (ctx) => ctx.getById(getRootId(ctx));
46
+ var getResizeTriggerEl = (ctx, id) => ctx.getById(getResizeTriggerId(ctx, id));
47
+ var getPanelEl = (ctx, id) => ctx.getById(getPanelId(ctx, id));
48
+ var getCursor = (state, x) => {
49
+ let cursor = x ? "col-resize" : "row-resize";
50
+ if (state.isAtMin) cursor = x ? "e-resize" : "s-resize";
51
+ if (state.isAtMax) cursor = x ? "w-resize" : "n-resize";
52
+ return cursor;
53
+ };
54
+ var getResizeTriggerEls = (ctx) => {
55
+ return (0, import_dom_query.queryAll)(getRootEl(ctx), `[role=separator][data-ownedby='${CSS.escape(getRootId(ctx))}']`);
56
+ };
57
+ var setupGlobalCursor = (ctx, state, x, nonce) => {
58
+ const styleEl = ctx.getById(getGlobalCursorId(ctx));
59
+ const textContent = `* { cursor: ${getCursor(state, x)} !important; }`;
60
+ if (styleEl) {
61
+ styleEl.textContent = textContent;
62
+ } else {
63
+ const style = ctx.getDoc().createElement("style");
64
+ if (nonce) style.nonce = nonce;
65
+ style.id = getGlobalCursorId(ctx);
66
+ style.textContent = textContent;
67
+ ctx.getDoc().head.appendChild(style);
68
+ }
69
+ };
70
+ var removeGlobalCursor = (ctx) => {
71
+ const styleEl = ctx.getById(getGlobalCursorId(ctx));
72
+ styleEl?.remove();
73
+ };
74
+ // Annotate the CommonJS export names for ESM import in node:
75
+ 0 && (module.exports = {
76
+ getCursor,
77
+ getGlobalCursorId,
78
+ getLabelId,
79
+ getPanelEl,
80
+ getPanelEls,
81
+ getPanelId,
82
+ getResizeTriggerEl,
83
+ getResizeTriggerEls,
84
+ getResizeTriggerId,
85
+ getRootEl,
86
+ getRootId,
87
+ removeGlobalCursor,
88
+ setupGlobalCursor
89
+ });
@@ -0,0 +1,52 @@
1
+ // src/splitter.dom.ts
2
+ import { queryAll } from "@zag-js/dom-query";
3
+ var getRootId = (ctx) => ctx.ids?.root ?? `splitter:${ctx.id}`;
4
+ var getResizeTriggerId = (ctx, id) => ctx.ids?.resizeTrigger?.(id) ?? `splitter:${ctx.id}:splitter:${id}`;
5
+ var getLabelId = (ctx) => ctx.ids?.label ?? `splitter:${ctx.id}:label`;
6
+ var getPanelId = (ctx, id) => ctx.ids?.panel?.(id) ?? `splitter:${ctx.id}:panel:${id}`;
7
+ var getPanelEls = (ctx) => queryAll(getRootEl(ctx), `[data-part=panel][data-ownedby=${getRootId(ctx)}]`);
8
+ var getGlobalCursorId = (ctx) => `splitter:${ctx.id}:global-cursor`;
9
+ var getRootEl = (ctx) => ctx.getById(getRootId(ctx));
10
+ var getResizeTriggerEl = (ctx, id) => ctx.getById(getResizeTriggerId(ctx, id));
11
+ var getPanelEl = (ctx, id) => ctx.getById(getPanelId(ctx, id));
12
+ var getCursor = (state, x) => {
13
+ let cursor = x ? "col-resize" : "row-resize";
14
+ if (state.isAtMin) cursor = x ? "e-resize" : "s-resize";
15
+ if (state.isAtMax) cursor = x ? "w-resize" : "n-resize";
16
+ return cursor;
17
+ };
18
+ var getResizeTriggerEls = (ctx) => {
19
+ return queryAll(getRootEl(ctx), `[role=separator][data-ownedby='${CSS.escape(getRootId(ctx))}']`);
20
+ };
21
+ var setupGlobalCursor = (ctx, state, x, nonce) => {
22
+ const styleEl = ctx.getById(getGlobalCursorId(ctx));
23
+ const textContent = `* { cursor: ${getCursor(state, x)} !important; }`;
24
+ if (styleEl) {
25
+ styleEl.textContent = textContent;
26
+ } else {
27
+ const style = ctx.getDoc().createElement("style");
28
+ if (nonce) style.nonce = nonce;
29
+ style.id = getGlobalCursorId(ctx);
30
+ style.textContent = textContent;
31
+ ctx.getDoc().head.appendChild(style);
32
+ }
33
+ };
34
+ var removeGlobalCursor = (ctx) => {
35
+ const styleEl = ctx.getById(getGlobalCursorId(ctx));
36
+ styleEl?.remove();
37
+ };
38
+ export {
39
+ getCursor,
40
+ getGlobalCursorId,
41
+ getLabelId,
42
+ getPanelEl,
43
+ getPanelEls,
44
+ getPanelId,
45
+ getResizeTriggerEl,
46
+ getResizeTriggerEls,
47
+ getResizeTriggerId,
48
+ getRootEl,
49
+ getRootId,
50
+ removeGlobalCursor,
51
+ setupGlobalCursor
52
+ };
@@ -0,0 +1,7 @@
1
+ import * as _zag_js_core from '@zag-js/core';
2
+ import { SplitterSchema } from './splitter.types.mjs';
3
+ import '@zag-js/types';
4
+
5
+ declare const machine: _zag_js_core.Machine<SplitterSchema>;
6
+
7
+ export { machine };
@@ -0,0 +1,7 @@
1
+ import * as _zag_js_core from '@zag-js/core';
2
+ import { SplitterSchema } from './splitter.types.js';
3
+ import '@zag-js/types';
4
+
5
+ declare const machine: _zag_js_core.Machine<SplitterSchema>;
6
+
7
+ export { machine };
@@ -0,0 +1,509 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/splitter.machine.ts
31
+ var splitter_machine_exports = {};
32
+ __export(splitter_machine_exports, {
33
+ machine: () => machine
34
+ });
35
+ module.exports = __toCommonJS(splitter_machine_exports);
36
+ var import_core = require("@zag-js/core");
37
+ var import_dom_query = require("@zag-js/dom-query");
38
+ var import_utils = require("@zag-js/utils");
39
+ var dom = __toESM(require("./splitter.dom.cjs"));
40
+ var import_aria = require("./utils/aria.cjs");
41
+ var import_fuzzy = require("./utils/fuzzy.cjs");
42
+ var import_panel = require("./utils/panel.cjs");
43
+ var import_resize_by_delta = require("./utils/resize-by-delta.cjs");
44
+ var import_validate_sizes = require("./utils/validate-sizes.cjs");
45
+ var machine = (0, import_core.createMachine)({
46
+ props({ props }) {
47
+ (0, import_utils.ensureProps)(props, ["panels"]);
48
+ return {
49
+ orientation: "horizontal",
50
+ defaultSize: [],
51
+ dir: "ltr",
52
+ ...props,
53
+ panels: (0, import_panel.sortPanels)(props.panels)
54
+ };
55
+ },
56
+ initialState() {
57
+ return "idle";
58
+ },
59
+ context({ prop, bindable, getContext, getRefs }) {
60
+ return {
61
+ size: bindable(() => ({
62
+ value: prop("size"),
63
+ defaultValue: prop("defaultSize"),
64
+ isEqual(a, b) {
65
+ return b != null && (0, import_fuzzy.fuzzySizeEqual)(a, b);
66
+ },
67
+ onChange(value) {
68
+ const ctx = getContext();
69
+ const refs = getRefs();
70
+ const sizesBeforeCollapse = refs.get("panelSizeBeforeCollapse");
71
+ const expandToSizes = Object.fromEntries(sizesBeforeCollapse.entries());
72
+ const resizeTriggerId = ctx.get("dragState")?.resizeTriggerId ?? null;
73
+ const layout = (0, import_panel.getPanelLayout)(prop("panels"));
74
+ prop("onResize")?.({
75
+ size: value,
76
+ layout,
77
+ resizeTriggerId,
78
+ expandToSizes
79
+ });
80
+ }
81
+ })),
82
+ dragState: bindable(() => ({
83
+ defaultValue: null
84
+ })),
85
+ keyboardState: bindable(() => ({
86
+ defaultValue: null
87
+ }))
88
+ };
89
+ },
90
+ watch({ track, action, prop }) {
91
+ track([() => (0, import_panel.serializePanels)(prop("panels"))], () => {
92
+ action(["syncSize"]);
93
+ });
94
+ },
95
+ refs() {
96
+ return {
97
+ panelSizeBeforeCollapse: /* @__PURE__ */ new Map(),
98
+ prevDelta: 0,
99
+ panelIdToLastNotifiedSizeMap: /* @__PURE__ */ new Map()
100
+ };
101
+ },
102
+ computed: {
103
+ horizontal({ prop }) {
104
+ return prop("orientation") === "horizontal";
105
+ }
106
+ },
107
+ on: {
108
+ "SIZE.SET": {
109
+ actions: ["setSize"]
110
+ },
111
+ "PANEL.COLLAPSE": {
112
+ actions: ["collapsePanel"]
113
+ },
114
+ "PANEL.EXPAND": {
115
+ actions: ["expandPanel"]
116
+ },
117
+ "PANEL.RESIZE": {
118
+ actions: ["resizePanel"]
119
+ }
120
+ },
121
+ entry: ["syncSize"],
122
+ exit: ["clearGlobalCursor"],
123
+ states: {
124
+ idle: {
125
+ entry: ["clearDraggingState", "clearKeyboardState"],
126
+ on: {
127
+ POINTER_OVER: {
128
+ target: "hover:temp",
129
+ actions: ["setKeyboardState"]
130
+ },
131
+ FOCUS: {
132
+ target: "focused",
133
+ actions: ["setKeyboardState"]
134
+ },
135
+ POINTER_DOWN: {
136
+ target: "dragging",
137
+ actions: ["setDraggingState"]
138
+ }
139
+ }
140
+ },
141
+ "hover:temp": {
142
+ effects: ["waitForHoverDelay"],
143
+ on: {
144
+ HOVER_DELAY: {
145
+ target: "hover"
146
+ },
147
+ POINTER_DOWN: {
148
+ target: "dragging",
149
+ actions: ["setDraggingState"]
150
+ },
151
+ POINTER_LEAVE: {
152
+ target: "idle"
153
+ }
154
+ }
155
+ },
156
+ hover: {
157
+ tags: ["focus"],
158
+ on: {
159
+ POINTER_DOWN: {
160
+ target: "dragging",
161
+ actions: ["setDraggingState"]
162
+ },
163
+ POINTER_LEAVE: {
164
+ target: "idle"
165
+ }
166
+ }
167
+ },
168
+ focused: {
169
+ tags: ["focus"],
170
+ on: {
171
+ BLUR: {
172
+ target: "idle"
173
+ },
174
+ ENTER: {
175
+ actions: ["collapseOrExpandPanel"]
176
+ },
177
+ POINTER_DOWN: {
178
+ target: "dragging",
179
+ actions: ["setDraggingState"]
180
+ },
181
+ KEYBOARD_MOVE: {
182
+ actions: ["invokeOnResizeStart", "setKeyboardValue", "invokeOnResizeEnd"]
183
+ },
184
+ "FOCUS.CYCLE": {
185
+ actions: ["focusNextResizeTrigger"]
186
+ }
187
+ }
188
+ },
189
+ dragging: {
190
+ tags: ["focus"],
191
+ effects: ["trackPointerMove"],
192
+ entry: ["invokeOnResizeStart"],
193
+ on: {
194
+ POINTER_MOVE: {
195
+ actions: ["setPointerValue", "setGlobalCursor"]
196
+ },
197
+ POINTER_UP: {
198
+ target: "idle",
199
+ actions: ["invokeOnResizeEnd", "clearGlobalCursor"]
200
+ }
201
+ }
202
+ }
203
+ },
204
+ implementations: {
205
+ effects: {
206
+ waitForHoverDelay: ({ send }) => {
207
+ return (0, import_utils.setRafTimeout)(() => {
208
+ send({ type: "HOVER_DELAY" });
209
+ }, 250);
210
+ },
211
+ trackPointerMove: ({ scope, send }) => {
212
+ const doc = scope.getDoc();
213
+ return (0, import_dom_query.trackPointerMove)(doc, {
214
+ onPointerMove(info) {
215
+ send({ type: "POINTER_MOVE", point: info.point });
216
+ },
217
+ onPointerUp() {
218
+ send({ type: "POINTER_UP" });
219
+ }
220
+ });
221
+ }
222
+ },
223
+ actions: {
224
+ setSize(params) {
225
+ const { context, event, prop } = params;
226
+ const unsafeSize = event.size;
227
+ const prevSize = context.get("size");
228
+ const panels = prop("panels");
229
+ const safeSize = (0, import_validate_sizes.validateSizes)({
230
+ size: unsafeSize,
231
+ panels
232
+ });
233
+ if (!(0, import_utils.isEqual)(prevSize, safeSize)) {
234
+ setSize(params, safeSize);
235
+ }
236
+ },
237
+ syncSize({ context, prop }) {
238
+ const panels = prop("panels");
239
+ let prevSize = context.get("size");
240
+ let unsafeSize = null;
241
+ if (prevSize.length === 0) {
242
+ unsafeSize = (0, import_panel.getUnsafeDefaultSize)({
243
+ panels,
244
+ size: context.initial("size")
245
+ });
246
+ }
247
+ const nextSize = (0, import_validate_sizes.validateSizes)({
248
+ size: unsafeSize ?? prevSize,
249
+ panels
250
+ });
251
+ if (!(0, import_utils.isEqual)(prevSize, nextSize)) {
252
+ context.set("size", nextSize);
253
+ }
254
+ },
255
+ setDraggingState({ context, event, prop, scope }) {
256
+ const orientation = prop("orientation");
257
+ const size = context.get("size");
258
+ const resizeTriggerId = event.id;
259
+ const panelGroupEl = dom.getRootEl(scope);
260
+ if (!panelGroupEl) return;
261
+ const handleElement = dom.getResizeTriggerEl(scope, resizeTriggerId);
262
+ (0, import_utils.ensure)(handleElement, () => `Drag handle element not found for id "${resizeTriggerId}"`);
263
+ const initialCursorPosition = orientation === "horizontal" ? event.point.x : event.point.y;
264
+ context.set("dragState", {
265
+ resizeTriggerId: event.id,
266
+ resizeTriggerRect: handleElement.getBoundingClientRect(),
267
+ initialCursorPosition,
268
+ initialSize: size
269
+ });
270
+ },
271
+ clearDraggingState({ context }) {
272
+ context.set("dragState", null);
273
+ },
274
+ setKeyboardState({ context, event }) {
275
+ context.set("keyboardState", {
276
+ resizeTriggerId: event.id
277
+ });
278
+ },
279
+ clearKeyboardState({ context }) {
280
+ context.set("keyboardState", null);
281
+ },
282
+ collapsePanel(params) {
283
+ const { context, prop, event, refs } = params;
284
+ const prevSize = context.get("size");
285
+ const panels = prop("panels");
286
+ const panel = panels.find((panel2) => panel2.id === event.id);
287
+ (0, import_utils.ensure)(panel, () => `Panel data not found for id "${event.id}"`);
288
+ if (panel.collapsible) {
289
+ const { collapsedSize = 0, panelSize, pivotIndices } = (0, import_panel.panelDataHelper)(panels, panel, prevSize);
290
+ (0, import_utils.ensure)(panelSize, () => `Panel size not found for panel "${panel.id}"`);
291
+ if (!(0, import_fuzzy.fuzzyNumbersEqual)(panelSize, collapsedSize)) {
292
+ refs.get("panelSizeBeforeCollapse").set(panel.id, panelSize);
293
+ const isLastPanel = (0, import_panel.findPanelDataIndex)(panels, panel) === panels.length - 1;
294
+ const delta = isLastPanel ? panelSize - collapsedSize : collapsedSize - panelSize;
295
+ const nextSize = (0, import_resize_by_delta.resizeByDelta)({
296
+ delta,
297
+ initialSize: prevSize,
298
+ panels,
299
+ pivotIndices,
300
+ prevSize,
301
+ trigger: "imperative-api"
302
+ });
303
+ if (!(0, import_utils.isEqual)(prevSize, nextSize)) {
304
+ setSize(params, nextSize);
305
+ }
306
+ }
307
+ }
308
+ },
309
+ expandPanel(params) {
310
+ const { context, prop, event, refs } = params;
311
+ const panels = prop("panels");
312
+ const prevSize = context.get("size");
313
+ const panel = panels.find((panel2) => panel2.id === event.id);
314
+ (0, import_utils.ensure)(panel, () => `Panel data not found for id "${event.id}"`);
315
+ if (panel.collapsible) {
316
+ const {
317
+ collapsedSize = 0,
318
+ panelSize = 0,
319
+ minSize: minSizeFromProps = 0,
320
+ pivotIndices
321
+ } = (0, import_panel.panelDataHelper)(panels, panel, prevSize);
322
+ const minSize = event.minSize ?? minSizeFromProps;
323
+ if ((0, import_fuzzy.fuzzyNumbersEqual)(panelSize, collapsedSize)) {
324
+ const prevPanelSize = refs.get("panelSizeBeforeCollapse").get(panel.id);
325
+ const baseSize = prevPanelSize != null && prevPanelSize >= minSize ? prevPanelSize : minSize;
326
+ const isLastPanel = (0, import_panel.findPanelDataIndex)(panels, panel) === panels.length - 1;
327
+ const delta = isLastPanel ? panelSize - baseSize : baseSize - panelSize;
328
+ const nextSize = (0, import_resize_by_delta.resizeByDelta)({
329
+ delta,
330
+ initialSize: prevSize,
331
+ panels,
332
+ pivotIndices,
333
+ prevSize,
334
+ trigger: "imperative-api"
335
+ });
336
+ if (!(0, import_utils.isEqual)(prevSize, nextSize)) {
337
+ setSize(params, nextSize);
338
+ }
339
+ }
340
+ }
341
+ },
342
+ resizePanel(params) {
343
+ const { context, prop, event } = params;
344
+ const prevSize = context.get("size");
345
+ const panels = prop("panels");
346
+ const panel = (0, import_panel.getPanelById)(panels, event.id);
347
+ const unsafePanelSize = event.size;
348
+ const { panelSize, pivotIndices } = (0, import_panel.panelDataHelper)(panels, panel, prevSize);
349
+ (0, import_utils.ensure)(panelSize, () => `Panel size not found for panel "${panel.id}"`);
350
+ const isLastPanel = (0, import_panel.findPanelDataIndex)(panels, panel) === panels.length - 1;
351
+ const delta = isLastPanel ? panelSize - unsafePanelSize : unsafePanelSize - panelSize;
352
+ const nextSize = (0, import_resize_by_delta.resizeByDelta)({
353
+ delta,
354
+ initialSize: prevSize,
355
+ panels,
356
+ pivotIndices,
357
+ prevSize,
358
+ trigger: "imperative-api"
359
+ });
360
+ if (!(0, import_utils.isEqual)(prevSize, nextSize)) {
361
+ setSize(params, nextSize);
362
+ }
363
+ },
364
+ setPointerValue(params) {
365
+ const { context, event, prop, scope } = params;
366
+ const dragState = context.get("dragState");
367
+ if (!dragState) return;
368
+ const { resizeTriggerId, initialSize, initialCursorPosition } = dragState;
369
+ const panels = prop("panels");
370
+ const panelGroupElement = dom.getRootEl(scope);
371
+ (0, import_utils.ensure)(panelGroupElement, () => `Panel group element not found`);
372
+ const pivotIndices = resizeTriggerId.split(":").map((id) => panels.findIndex((panel) => panel.id === id));
373
+ const horizontal = prop("orientation") === "horizontal";
374
+ const cursorPosition = horizontal ? event.point.x : event.point.y;
375
+ const groupRect = panelGroupElement.getBoundingClientRect();
376
+ const groupSizeInPixels = horizontal ? groupRect.width : groupRect.height;
377
+ const offsetPixels = cursorPosition - initialCursorPosition;
378
+ const offsetPercentage = offsetPixels / groupSizeInPixels * 100;
379
+ const prevSize = context.get("size");
380
+ const nextSize = (0, import_resize_by_delta.resizeByDelta)({
381
+ delta: offsetPercentage,
382
+ initialSize: initialSize ?? prevSize,
383
+ panels,
384
+ pivotIndices,
385
+ prevSize,
386
+ trigger: "mouse-or-touch"
387
+ });
388
+ if (!(0, import_utils.isEqual)(prevSize, nextSize)) {
389
+ setSize(params, nextSize);
390
+ }
391
+ },
392
+ setKeyboardValue(params) {
393
+ const { context, event, prop } = params;
394
+ const panelDataArray = prop("panels");
395
+ const resizeTriggerId = event.id;
396
+ const delta = event.delta;
397
+ const pivotIndices = resizeTriggerId.split(":").map((id) => panelDataArray.findIndex((panelData) => panelData.id === id));
398
+ const prevSize = context.get("size");
399
+ const nextSize = (0, import_resize_by_delta.resizeByDelta)({
400
+ delta,
401
+ initialSize: prevSize,
402
+ panels: panelDataArray,
403
+ pivotIndices,
404
+ prevSize,
405
+ trigger: "keyboard"
406
+ });
407
+ if (!(0, import_utils.isEqual)(prevSize, nextSize)) {
408
+ setSize(params, nextSize);
409
+ }
410
+ },
411
+ invokeOnResizeEnd({ context, prop }) {
412
+ queueMicrotask(() => {
413
+ const dragState = context.get("dragState");
414
+ prop("onResizeEnd")?.({
415
+ size: context.get("size"),
416
+ resizeTriggerId: dragState?.resizeTriggerId ?? null
417
+ });
418
+ });
419
+ },
420
+ invokeOnResizeStart({ prop }) {
421
+ queueMicrotask(() => {
422
+ prop("onResizeStart")?.();
423
+ });
424
+ },
425
+ collapseOrExpandPanel(params) {
426
+ const { context, prop } = params;
427
+ const panelDataArray = prop("panels");
428
+ const sizes = context.get("size");
429
+ const resizeTriggerId = context.get("keyboardState")?.resizeTriggerId;
430
+ const [idBefore, idAfter] = resizeTriggerId?.split(":") ?? [];
431
+ const index = panelDataArray.findIndex((panelData2) => panelData2.id === idBefore);
432
+ if (index === -1) return;
433
+ const panelData = panelDataArray[index];
434
+ (0, import_utils.ensure)(panelData, () => `No panel data found for index ${index}`);
435
+ const size = sizes[index];
436
+ const { collapsedSize = 0, collapsible, minSize = 0 } = panelData;
437
+ if (size != null && collapsible) {
438
+ const pivotIndices = [idBefore, idAfter].map(
439
+ (id) => panelDataArray.findIndex((panelData2) => panelData2.id === id)
440
+ );
441
+ const nextSize = (0, import_resize_by_delta.resizeByDelta)({
442
+ delta: (0, import_fuzzy.fuzzyNumbersEqual)(size, collapsedSize) ? minSize - collapsedSize : collapsedSize - size,
443
+ initialSize: context.initial("size"),
444
+ panels: panelDataArray,
445
+ pivotIndices,
446
+ prevSize: sizes,
447
+ trigger: "keyboard"
448
+ });
449
+ if (!(0, import_utils.isEqual)(sizes, nextSize)) {
450
+ setSize(params, nextSize);
451
+ }
452
+ }
453
+ },
454
+ setGlobalCursor({ context, scope, prop }) {
455
+ const dragState = context.get("dragState");
456
+ if (!dragState) return;
457
+ const panels = prop("panels");
458
+ const horizontal = prop("orientation") === "horizontal";
459
+ const [idBefore] = dragState.resizeTriggerId.split(":");
460
+ const indexBefore = panels.findIndex((panel2) => panel2.id === idBefore);
461
+ const panel = panels[indexBefore];
462
+ const size = context.get("size");
463
+ const aria = (0, import_aria.getAriaValue)(size, panels, dragState.resizeTriggerId);
464
+ const isAtMin = (0, import_fuzzy.fuzzyNumbersEqual)(aria.valueNow, aria.valueMin) || (0, import_fuzzy.fuzzyNumbersEqual)(aria.valueNow, panel.collapsedSize);
465
+ const isAtMax = (0, import_fuzzy.fuzzyNumbersEqual)(aria.valueNow, aria.valueMax);
466
+ const cursorState = { isAtMin, isAtMax };
467
+ dom.setupGlobalCursor(scope, cursorState, horizontal, prop("nonce"));
468
+ },
469
+ clearGlobalCursor({ scope }) {
470
+ dom.removeGlobalCursor(scope);
471
+ },
472
+ focusNextResizeTrigger({ event, scope }) {
473
+ const resizeTriggers = dom.getResizeTriggerEls(scope);
474
+ const index = resizeTriggers.findIndex((el) => el.dataset.id === event.id);
475
+ const handleEl = event.shiftKey ? (0, import_utils.prev)(resizeTriggers, index) : (0, import_utils.next)(resizeTriggers, index);
476
+ handleEl?.focus();
477
+ }
478
+ }
479
+ }
480
+ });
481
+ function setSize(params, sizes) {
482
+ const { refs, prop, context } = params;
483
+ const panelsArray = prop("panels");
484
+ const onCollapse = prop("onCollapse");
485
+ const onExpand = prop("onExpand");
486
+ const panelIdToLastNotifiedSizeMap = refs.get("panelIdToLastNotifiedSizeMap");
487
+ context.set("size", sizes);
488
+ sizes.forEach((size, index) => {
489
+ const panelData = panelsArray[index];
490
+ (0, import_utils.ensure)(panelData, () => `Panel data not found for index ${index}`);
491
+ const { collapsedSize = 0, collapsible, id: panelId } = panelData;
492
+ const lastNotifiedSize = panelIdToLastNotifiedSizeMap.get(panelId);
493
+ if (lastNotifiedSize == null || size !== lastNotifiedSize) {
494
+ panelIdToLastNotifiedSizeMap.set(panelId, size);
495
+ if (collapsible && (onCollapse || onExpand)) {
496
+ if ((lastNotifiedSize == null || (0, import_fuzzy.fuzzyNumbersEqual)(lastNotifiedSize, collapsedSize)) && !(0, import_fuzzy.fuzzyNumbersEqual)(size, collapsedSize)) {
497
+ onExpand?.({ panelId, size });
498
+ }
499
+ if (onCollapse && (lastNotifiedSize == null || !(0, import_fuzzy.fuzzyNumbersEqual)(lastNotifiedSize, collapsedSize)) && (0, import_fuzzy.fuzzyNumbersEqual)(size, collapsedSize)) {
500
+ onCollapse?.({ panelId, size });
501
+ }
502
+ }
503
+ }
504
+ });
505
+ }
506
+ // Annotate the CommonJS export names for ESM import in node:
507
+ 0 && (module.exports = {
508
+ machine
509
+ });