@zag-js/splitter 0.1.13 → 0.1.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,31 +1,4 @@
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/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
23
- connect: () => connect,
24
- machine: () => machine
25
- });
26
- module.exports = __toCommonJS(src_exports);
27
-
28
- // ../../utilities/dom/dist/index.mjs
1
+ // ../../utilities/dom/dist/index.js
29
2
  var dataAttr = (guard) => {
30
3
  return guard ? "" : void 0;
31
4
  };
@@ -506,9 +479,9 @@ function connect(state2, send, normalize) {
506
479
  }
507
480
 
508
481
  // src/splitter.machine.ts
509
- var import_core = require("@zag-js/core");
482
+ import { createMachine, guards } from "@zag-js/core";
510
483
 
511
- // ../../utilities/number/dist/index.mjs
484
+ // ../../utilities/number/dist/index.js
512
485
  function round(v, t) {
513
486
  let num = valueOf(v);
514
487
  const p = 10 ** (t ?? 10);
@@ -556,9 +529,9 @@ function decimalOperation(a, op, b) {
556
529
  var nf = new Intl.NumberFormat("en-US", { style: "decimal", maximumFractionDigits: 20 });
557
530
 
558
531
  // src/splitter.machine.ts
559
- var { not } = import_core.guards;
532
+ var { not } = guards;
560
533
  function machine(ctx) {
561
- return (0, import_core.createMachine)(
534
+ return createMachine(
562
535
  {
563
536
  id: "splitter",
564
537
  initial: "unknown",
@@ -769,8 +742,7 @@ function machine(ctx) {
769
742
  }
770
743
  );
771
744
  }
772
- // Annotate the CommonJS export names for ESM import in node:
773
- 0 && (module.exports = {
745
+ export {
774
746
  connect,
775
747
  machine
776
- });
748
+ };
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
+ "type": "module",
2
3
  "name": "@zag-js/splitter",
3
- "version": "0.1.13",
4
+ "version": "0.1.14",
4
5
  "description": "Core logic for the splitter widget implemented as a state machine",
5
6
  "keywords": [
6
7
  "js",
@@ -17,7 +18,6 @@
17
18
  "license": "MIT",
18
19
  "main": "dist/index.js",
19
20
  "types": "dist/index.d.ts",
20
- "module": "dist/index.mjs",
21
21
  "repository": "https://github.com/chakra-ui/zag/tree/main/packages/splitter",
22
22
  "sideEffects": false,
23
23
  "files": [
@@ -30,17 +30,17 @@
30
30
  "url": "https://github.com/chakra-ui/zag/issues"
31
31
  },
32
32
  "dependencies": {
33
- "@zag-js/core": "0.1.10",
34
- "@zag-js/types": "0.2.5"
33
+ "@zag-js/core": "0.1.11",
34
+ "@zag-js/types": "0.2.6"
35
35
  },
36
36
  "devDependencies": {
37
- "@zag-js/dom-utils": "0.1.11",
38
- "@zag-js/number-utils": "0.1.4"
37
+ "@zag-js/dom-utils": "0.1.12",
38
+ "@zag-js/number-utils": "0.1.5"
39
39
  },
40
40
  "scripts": {
41
- "build-fast": "tsup src/index.ts --format=esm,cjs",
41
+ "build-fast": "tsup src/index.ts --format=esm",
42
42
  "start": "pnpm build --watch",
43
- "build": "tsup src/index.ts --format=esm,cjs --dts",
43
+ "build": "tsup src/index.ts --format=esm --dts",
44
44
  "test": "jest --config ../../../jest.config.js --rootDir . --passWithNoTests",
45
45
  "lint": "eslint src --ext .ts,.tsx",
46
46
  "test-ci": "pnpm test --ci --runInBand",
package/dist/index.mjs DELETED
@@ -1,748 +0,0 @@
1
- // ../../utilities/dom/dist/index.mjs
2
- var dataAttr = (guard) => {
3
- return guard ? "" : void 0;
4
- };
5
- var runIfFn = (v, ...a) => {
6
- const res = typeof v === "function" ? v(...a) : v;
7
- return res ?? void 0;
8
- };
9
- var callAll = (...fns) => (...a) => {
10
- fns.forEach(function(fn) {
11
- fn == null ? void 0 : fn(...a);
12
- });
13
- };
14
- var isArray = (v) => Array.isArray(v);
15
- var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
16
- var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
17
- var isDom = () => typeof window !== "undefined";
18
- function getPlatform() {
19
- const agent = navigator.userAgentData;
20
- return (agent == null ? void 0 : agent.platform) ?? navigator.platform;
21
- }
22
- var pt = (v) => isDom() && v.test(getPlatform());
23
- var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
24
- var isMac = () => pt(/^Mac/) && !isTouchDevice;
25
- var isApple = () => pt(/mac|iphone|ipad|ipod/i);
26
- var isIos = () => isApple() && !isMac();
27
- function isDocument(el) {
28
- return el.nodeType === Node.DOCUMENT_NODE;
29
- }
30
- function isWindow(value) {
31
- return (value == null ? void 0 : value.toString()) === "[object Window]";
32
- }
33
- function getDocument(el) {
34
- if (isWindow(el))
35
- return el.document;
36
- if (isDocument(el))
37
- return el;
38
- return (el == null ? void 0 : el.ownerDocument) ?? document;
39
- }
40
- function defineDomHelpers(helpers) {
41
- const dom2 = {
42
- getRootNode: (ctx) => {
43
- var _a;
44
- return ((_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) ?? document;
45
- },
46
- getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
47
- getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
48
- getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
49
- getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
50
- };
51
- return {
52
- ...dom2,
53
- ...helpers
54
- };
55
- }
56
- var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
57
- var supportsTouchEvent = () => isDom() && window.ontouchstart === null;
58
- var supportsMouseEvent = () => isDom() && window.onmousedown === null;
59
- var isMouseEvent = (v) => isObject(v) && hasProp(v, "button");
60
- var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
61
- var isLeftClick = (v) => v.button === 0;
62
- function getElementOffset(element) {
63
- let left = 0;
64
- let top = 0;
65
- let el = element;
66
- if (el.parentNode) {
67
- do {
68
- left += el.offsetLeft;
69
- top += el.offsetTop;
70
- } while ((el = el.offsetParent) && el.nodeType < 9);
71
- el = element;
72
- do {
73
- left -= el.scrollLeft;
74
- top -= el.scrollTop;
75
- } while ((el = el.parentNode) && !/body/i.test(el.nodeName));
76
- }
77
- return {
78
- top,
79
- right: innerWidth - left - element.offsetWidth,
80
- bottom: innerHeight - top - element.offsetHeight,
81
- left
82
- };
83
- }
84
- function getPointRelativeToNode(point, element) {
85
- const offset = getElementOffset(element);
86
- const x = point.x - offset.left;
87
- const y = point.y - offset.top;
88
- return { x, y };
89
- }
90
- var rtlKeyMap = {
91
- ArrowLeft: "ArrowRight",
92
- ArrowRight: "ArrowLeft"
93
- };
94
- var sameKeyMap = {
95
- Up: "ArrowUp",
96
- Down: "ArrowDown",
97
- Esc: "Escape",
98
- " ": "Space",
99
- ",": "Comma",
100
- Left: "ArrowLeft",
101
- Right: "ArrowRight"
102
- };
103
- function getEventKey(event, options = {}) {
104
- const { dir = "ltr", orientation = "horizontal" } = options;
105
- let { key } = event;
106
- key = sameKeyMap[key] ?? key;
107
- const isRtl = dir === "rtl" && orientation === "horizontal";
108
- if (isRtl && key in rtlKeyMap) {
109
- key = rtlKeyMap[key];
110
- }
111
- return key;
112
- }
113
- var PAGE_KEYS = /* @__PURE__ */ new Set(["PageUp", "PageDown"]);
114
- var ARROW_KEYS = /* @__PURE__ */ new Set(["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"]);
115
- function getEventStep(event) {
116
- if (event.ctrlKey || event.metaKey) {
117
- return 0.1;
118
- } else {
119
- const isPageKey = PAGE_KEYS.has(event.key);
120
- const isSkipKey = isPageKey || event.shiftKey && ARROW_KEYS.has(event.key);
121
- return isSkipKey ? 10 : 1;
122
- }
123
- }
124
- var isRef = (v) => hasProp(v, "current");
125
- var fallback2 = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
126
- function extractInfo(event, type = "page") {
127
- const point = isTouchEvent(event) ? event.touches[0] || event.changedTouches[0] || fallback2 : event;
128
- return {
129
- point: {
130
- x: point[`${type}X`],
131
- y: point[`${type}Y`]
132
- }
133
- };
134
- }
135
- function addDomEvent(target, eventName, handler, options) {
136
- const node = isRef(target) ? target.current : runIfFn(target);
137
- node == null ? void 0 : node.addEventListener(eventName, handler, options);
138
- return () => {
139
- node == null ? void 0 : node.removeEventListener(eventName, handler, options);
140
- };
141
- }
142
- function addPointerEvent(target, event, listener, options) {
143
- const type = getEventName(event) ?? event;
144
- return addDomEvent(target, type, wrapHandler(listener, event === "pointerdown"), options);
145
- }
146
- function wrapHandler(fn, filter = false) {
147
- const listener = (event) => {
148
- fn(event, extractInfo(event));
149
- };
150
- return filter ? filterPrimaryPointer(listener) : listener;
151
- }
152
- function filterPrimaryPointer(fn) {
153
- return (event) => {
154
- const win = event.view ?? window;
155
- const isMouseEvent2 = event instanceof win.MouseEvent;
156
- const isPrimary = !isMouseEvent2 || isMouseEvent2 && event.button === 0;
157
- if (isPrimary)
158
- fn(event);
159
- };
160
- }
161
- var mouseEventNames = {
162
- pointerdown: "mousedown",
163
- pointermove: "mousemove",
164
- pointerup: "mouseup",
165
- pointercancel: "mousecancel",
166
- pointerover: "mouseover",
167
- pointerout: "mouseout",
168
- pointerenter: "mouseenter",
169
- pointerleave: "mouseleave"
170
- };
171
- var touchEventNames = {
172
- pointerdown: "touchstart",
173
- pointermove: "touchmove",
174
- pointerup: "touchend",
175
- pointercancel: "touchcancel"
176
- };
177
- function getEventName(evt) {
178
- if (supportsPointerEvent())
179
- return evt;
180
- if (supportsTouchEvent())
181
- return touchEventNames[evt];
182
- if (supportsMouseEvent())
183
- return mouseEventNames[evt];
184
- return evt;
185
- }
186
- function nextTick(fn) {
187
- const set = /* @__PURE__ */ new Set();
188
- function raf2(fn2) {
189
- const id = globalThis.requestAnimationFrame(fn2);
190
- set.add(() => globalThis.cancelAnimationFrame(id));
191
- }
192
- raf2(() => raf2(fn));
193
- return function cleanup() {
194
- set.forEach(function(fn2) {
195
- fn2();
196
- });
197
- };
198
- }
199
- function raf(fn) {
200
- const id = globalThis.requestAnimationFrame(fn);
201
- return function cleanup() {
202
- globalThis.cancelAnimationFrame(id);
203
- };
204
- }
205
- var state = "default";
206
- var savedUserSelect = "";
207
- var modifiedElementMap = /* @__PURE__ */ new WeakMap();
208
- function disableTextSelection({ target, doc } = {}) {
209
- const _document = doc ?? document;
210
- if (isIos()) {
211
- if (state === "default") {
212
- savedUserSelect = _document.documentElement.style.webkitUserSelect;
213
- _document.documentElement.style.webkitUserSelect = "none";
214
- }
215
- state = "disabled";
216
- } else if (target) {
217
- modifiedElementMap.set(target, target.style.userSelect);
218
- target.style.userSelect = "none";
219
- }
220
- return () => restoreTextSelection({ target, doc: _document });
221
- }
222
- function restoreTextSelection({ target, doc } = {}) {
223
- const _document = doc ?? document;
224
- if (isIos()) {
225
- if (state !== "disabled")
226
- return;
227
- state = "restoring";
228
- setTimeout(() => {
229
- nextTick(() => {
230
- if (state === "restoring") {
231
- if (_document.documentElement.style.webkitUserSelect === "none") {
232
- _document.documentElement.style.webkitUserSelect = savedUserSelect || "";
233
- }
234
- savedUserSelect = "";
235
- state = "default";
236
- }
237
- });
238
- }, 300);
239
- } else {
240
- if (target && modifiedElementMap.has(target)) {
241
- let targetOldUserSelect = modifiedElementMap.get(target);
242
- if (target.style.userSelect === "none") {
243
- target.style.userSelect = targetOldUserSelect ?? "";
244
- }
245
- if (target.getAttribute("style") === "") {
246
- target.removeAttribute("style");
247
- }
248
- modifiedElementMap.delete(target);
249
- }
250
- }
251
- }
252
- var THRESHOLD = 5;
253
- function trackPointerMove(doc, opts) {
254
- const { onPointerMove, onPointerUp } = opts;
255
- const handlePointerMove = (event, info) => {
256
- const { point: p } = info;
257
- const distance = Math.sqrt(p.x ** 2 + p.y ** 2);
258
- if (distance < THRESHOLD)
259
- return;
260
- if (isMouseEvent(event) && isLeftClick(event)) {
261
- onPointerUp();
262
- return;
263
- }
264
- onPointerMove(info, event);
265
- };
266
- return callAll(
267
- addPointerEvent(doc, "pointermove", handlePointerMove, false),
268
- addPointerEvent(doc, "pointerup", onPointerUp, false),
269
- addPointerEvent(doc, "pointercancel", onPointerUp, false),
270
- addPointerEvent(doc, "contextmenu", onPointerUp, false),
271
- disableTextSelection({ doc })
272
- );
273
- }
274
-
275
- // src/splitter.dom.ts
276
- var dom = defineDomHelpers({
277
- getRootId: (ctx) => {
278
- var _a;
279
- return ((_a = ctx.ids) == null ? void 0 : _a.root) ?? `splitter:${ctx.id}`;
280
- },
281
- getSplitterId: (ctx) => {
282
- var _a;
283
- return ((_a = ctx.ids) == null ? void 0 : _a.splitter) ?? `splitter:${ctx.id}:splitter`;
284
- },
285
- getToggleButtonId: (ctx) => {
286
- var _a;
287
- return ((_a = ctx.ids) == null ? void 0 : _a.toggleBtn) ?? `splitter:${ctx.id}:toggle-btn`;
288
- },
289
- getLabelId: (ctx) => {
290
- var _a;
291
- return ((_a = ctx.ids) == null ? void 0 : _a.label) ?? `splitter:${ctx.id}:label`;
292
- },
293
- getPrimaryPaneId: (ctx) => {
294
- var _a;
295
- return ((_a = ctx.ids) == null ? void 0 : _a.primaryPane) ?? `splitter:${ctx.id}:primary`;
296
- },
297
- getSecondaryPaneId: (ctx) => {
298
- var _a;
299
- return ((_a = ctx.ids) == null ? void 0 : _a.secondaryPane) ?? `splitter:${ctx.id}:secondary`;
300
- },
301
- getSplitterEl: (ctx) => dom.getById(ctx, dom.getSplitterId(ctx)),
302
- getPrimaryPaneEl: (ctx) => dom.getById(ctx, dom.getPrimaryPaneId(ctx)),
303
- getCursor(ctx) {
304
- if (ctx.disabled || ctx.fixed)
305
- return "default";
306
- const x = ctx.isHorizontal;
307
- let cursor = x ? "col-resize" : "row-resize";
308
- if (ctx.isAtMin)
309
- cursor = x ? "e-resize" : "s-resize";
310
- if (ctx.isAtMax)
311
- cursor = x ? "w-resize" : "n-resize";
312
- return cursor;
313
- }
314
- });
315
-
316
- // src/splitter.connect.ts
317
- function connect(state2, send, normalize) {
318
- const isHorizontal = state2.context.isHorizontal;
319
- const isDisabled = state2.context.disabled;
320
- const isFocused = state2.hasTag("focus");
321
- const isDragging = state2.matches("dragging");
322
- const isAtMin = state2.context.isAtMin;
323
- const isAtMax = state2.context.isAtMax;
324
- const min = state2.context.min;
325
- const max = state2.context.max;
326
- const value = state2.context.value;
327
- return {
328
- isCollapsed: isAtMin,
329
- isExpanded: isAtMax,
330
- isFocused,
331
- isDragging,
332
- value,
333
- collapse() {
334
- send("COLLAPSE");
335
- },
336
- expand() {
337
- send("EXPAND");
338
- },
339
- toggle() {
340
- send("TOGGLE");
341
- },
342
- setSize(size) {
343
- send({ type: "SET_SIZE", size });
344
- },
345
- rootProps: normalize.element({
346
- "data-part": "root",
347
- "data-orientation": state2.context.orientation,
348
- "data-disabled": dataAttr(isDisabled),
349
- id: dom.getRootId(state2.context),
350
- style: {
351
- display: "flex",
352
- flex: "1 1 0%",
353
- flexDirection: isHorizontal ? "row" : "column"
354
- }
355
- }),
356
- secondaryPaneProps: normalize.element({
357
- "data-part": "secondary-pane",
358
- "data-disabled": dataAttr(isDisabled),
359
- id: dom.getSecondaryPaneId(state2.context),
360
- style: {
361
- height: isHorizontal ? "100%" : "auto",
362
- width: isHorizontal ? "auto" : "100%",
363
- flex: "1 1 auto",
364
- position: "relative"
365
- }
366
- }),
367
- primaryPaneProps: normalize.element({
368
- "data-part": "primary-pane",
369
- id: dom.getPrimaryPaneId(state2.context),
370
- "data-disabled": dataAttr(isDisabled),
371
- "data-state": isAtMax ? "at-max" : isAtMin ? "at-min" : "between",
372
- style: {
373
- visibility: "visible",
374
- flex: `0 0 ${value}px`,
375
- position: "relative",
376
- userSelect: isDragging ? "none" : "auto",
377
- ...isHorizontal ? { minWidth: `${min}px`, maxWidth: `${max}px` } : { minHeight: `${min}px`, maxHeight: `${max}px` }
378
- }
379
- }),
380
- toggleButtonProps: normalize.element({
381
- "data-part": "toggle-button",
382
- id: dom.getToggleButtonId(state2.context),
383
- "aria-label": state2.context.isAtMin ? "Expand Primary Pane" : "Collapse Primary Pane",
384
- onClick() {
385
- send("TOGGLE");
386
- }
387
- }),
388
- labelProps: normalize.element({
389
- "data-part": "label",
390
- id: dom.getLabelId(state2.context)
391
- }),
392
- splitterProps: normalize.element({
393
- "data-part": "splitter",
394
- id: dom.getSplitterId(state2.context),
395
- role: "separator",
396
- tabIndex: isDisabled ? void 0 : 0,
397
- "aria-valuenow": value,
398
- "aria-valuemin": min,
399
- "aria-valuemax": max,
400
- "aria-orientation": state2.context.orientation,
401
- "aria-labelledby": dom.getLabelId(state2.context),
402
- "aria-controls": dom.getPrimaryPaneId(state2.context),
403
- "data-orientation": state2.context.orientation,
404
- "data-focus": dataAttr(isFocused),
405
- "data-disabled": dataAttr(isDisabled),
406
- style: {
407
- touchAction: "none",
408
- userSelect: "none",
409
- WebkitUserSelect: "none",
410
- msUserSelect: "none",
411
- flex: "0 0 auto",
412
- cursor: dom.getCursor(state2.context),
413
- minHeight: isHorizontal ? "0px" : void 0,
414
- minWidth: isHorizontal ? void 0 : "0px"
415
- },
416
- onPointerDown(event) {
417
- if (isDisabled) {
418
- event.preventDefault();
419
- return;
420
- }
421
- send("POINTER_DOWN");
422
- event.preventDefault();
423
- event.stopPropagation();
424
- },
425
- onPointerOver() {
426
- if (isDisabled)
427
- return;
428
- send("POINTER_OVER");
429
- },
430
- onPointerLeave() {
431
- if (isDisabled)
432
- return;
433
- send("POINTER_LEAVE");
434
- },
435
- onBlur() {
436
- send("BLUR");
437
- },
438
- onFocus() {
439
- send("FOCUS");
440
- },
441
- onDoubleClick() {
442
- if (isDisabled)
443
- return;
444
- send("DOUBLE_CLICK");
445
- },
446
- onKeyDown(event) {
447
- if (isDisabled)
448
- return;
449
- const step = getEventStep(event) * state2.context.step;
450
- const keyMap = {
451
- ArrowUp() {
452
- send({ type: "ARROW_UP", step });
453
- },
454
- ArrowDown() {
455
- send({ type: "ARROW_DOWN", step });
456
- },
457
- ArrowLeft() {
458
- send({ type: "ARROW_LEFT", step });
459
- },
460
- ArrowRight() {
461
- send({ type: "ARROW_RIGHT", step });
462
- },
463
- Home() {
464
- send("HOME");
465
- },
466
- End() {
467
- send("END");
468
- }
469
- };
470
- const key = getEventKey(event, state2.context);
471
- const exec = keyMap[key];
472
- if (exec) {
473
- exec(event);
474
- event.preventDefault();
475
- }
476
- }
477
- })
478
- };
479
- }
480
-
481
- // src/splitter.machine.ts
482
- import { createMachine, guards } from "@zag-js/core";
483
-
484
- // ../../utilities/number/dist/index.mjs
485
- function round(v, t) {
486
- let num = valueOf(v);
487
- const p = 10 ** (t ?? 10);
488
- num = Math.round(num * p) / p;
489
- return t ? num.toFixed(t) : v.toString();
490
- }
491
- function clamp(v, o) {
492
- return Math.min(Math.max(valueOf(v), o.min), o.max);
493
- }
494
- function countDecimals(value) {
495
- if (!Number.isFinite(value))
496
- return 0;
497
- let e = 1, p = 0;
498
- while (Math.round(value * e) / e !== value) {
499
- e *= 10;
500
- p += 1;
501
- }
502
- return p;
503
- }
504
- var increment = (v, s) => decimalOperation(valueOf(v), "+", s);
505
- var decrement = (v, s) => decimalOperation(valueOf(v), "-", s);
506
- function snapToStep(value, step) {
507
- const num = valueOf(value);
508
- const p = countDecimals(step);
509
- const v = Math.round(num / step) * step;
510
- return round(v, p);
511
- }
512
- function valueOf(v) {
513
- if (typeof v === "number")
514
- return v;
515
- const num = parseFloat(v.toString().replace(/[^\w.-]+/g, ""));
516
- return !Number.isNaN(num) ? num : 0;
517
- }
518
- function decimalOperation(a, op, b) {
519
- let result = op === "+" ? a + b : a - b;
520
- if (a % 1 !== 0 || b % 1 !== 0) {
521
- const multiplier = 10 ** Math.max(countDecimals(a), countDecimals(b));
522
- a = Math.round(a * multiplier);
523
- b = Math.round(b * multiplier);
524
- result = op === "+" ? a + b : a - b;
525
- result /= multiplier;
526
- }
527
- return result;
528
- }
529
- var nf = new Intl.NumberFormat("en-US", { style: "decimal", maximumFractionDigits: 20 });
530
-
531
- // src/splitter.machine.ts
532
- var { not } = guards;
533
- function machine(ctx) {
534
- return createMachine(
535
- {
536
- id: "splitter",
537
- initial: "unknown",
538
- context: {
539
- orientation: "horizontal",
540
- min: 224,
541
- max: 340,
542
- step: 1,
543
- value: 256,
544
- snapOffset: 0,
545
- ...ctx
546
- },
547
- computed: {
548
- isHorizontal: (ctx2) => ctx2.orientation === "horizontal",
549
- isAtMin: (ctx2) => ctx2.value === ctx2.min,
550
- isAtMax: (ctx2) => ctx2.value === ctx2.max
551
- },
552
- on: {
553
- COLLAPSE: {
554
- actions: "setToMin"
555
- },
556
- EXPAND: {
557
- actions: "setToMax"
558
- },
559
- TOGGLE: [
560
- {
561
- guard: "isCollapsed",
562
- actions: "setToMax"
563
- },
564
- {
565
- actions: "setToMin"
566
- }
567
- ]
568
- },
569
- states: {
570
- unknown: {
571
- on: {
572
- SETUP: "idle"
573
- }
574
- },
575
- idle: {
576
- on: {
577
- POINTER_OVER: {
578
- guard: not("isFixed"),
579
- target: "hover:temp"
580
- },
581
- POINTER_LEAVE: "idle",
582
- FOCUS: "focused"
583
- }
584
- },
585
- "hover:temp": {
586
- after: {
587
- HOVER_DELAY: "hover"
588
- },
589
- on: {
590
- POINTER_DOWN: {
591
- target: "dragging",
592
- actions: ["invokeOnChangeStart"]
593
- },
594
- POINTER_LEAVE: "idle"
595
- }
596
- },
597
- hover: {
598
- tags: ["focus"],
599
- on: {
600
- POINTER_DOWN: {
601
- target: "dragging",
602
- actions: ["invokeOnChangeStart"]
603
- },
604
- POINTER_LEAVE: "idle"
605
- }
606
- },
607
- focused: {
608
- tags: ["focus"],
609
- on: {
610
- BLUR: "idle",
611
- POINTER_DOWN: {
612
- target: "dragging",
613
- actions: ["invokeOnChangeStart"]
614
- },
615
- ARROW_LEFT: {
616
- guard: "isHorizontal",
617
- actions: "decrement"
618
- },
619
- ARROW_RIGHT: {
620
- guard: "isHorizontal",
621
- actions: "increment"
622
- },
623
- ARROW_UP: {
624
- guard: "isVertical",
625
- actions: "increment"
626
- },
627
- ARROW_DOWN: {
628
- guard: "isVertical",
629
- actions: "decrement"
630
- },
631
- ENTER: [
632
- {
633
- guard: "isCollapsed",
634
- actions: "setToMin"
635
- },
636
- { actions: "setToMin" }
637
- ],
638
- HOME: {
639
- actions: "setToMin"
640
- },
641
- END: {
642
- actions: "setToMax"
643
- },
644
- DOUBLE_CLICK: [
645
- {
646
- guard: "isCollapsed",
647
- actions: "setToMax"
648
- },
649
- { actions: "setToMin" }
650
- ]
651
- }
652
- },
653
- dragging: {
654
- tags: ["focus"],
655
- entry: "focusSplitter",
656
- activities: "trackPointerMove",
657
- on: {
658
- POINTER_UP: {
659
- target: "focused",
660
- actions: ["invokeOnChangeEnd"]
661
- },
662
- POINTER_MOVE: {
663
- actions: "setPointerValue"
664
- }
665
- }
666
- }
667
- }
668
- },
669
- {
670
- activities: {
671
- trackPointerMove: (ctx2, _evt, { send }) => {
672
- const doc = dom.getDoc(ctx2);
673
- return trackPointerMove(doc, {
674
- onPointerMove(info) {
675
- send({ type: "POINTER_MOVE", point: info.point });
676
- doc.documentElement.style.cursor = dom.getCursor(ctx2);
677
- },
678
- onPointerUp() {
679
- send("POINTER_UP");
680
- doc.documentElement.style.cursor = "";
681
- }
682
- });
683
- }
684
- },
685
- guards: {
686
- isCollapsed: (ctx2) => ctx2.isAtMin,
687
- isHorizontal: (ctx2) => ctx2.isHorizontal,
688
- isVertical: (ctx2) => !ctx2.isHorizontal,
689
- isFixed: (ctx2) => !!ctx2.fixed
690
- },
691
- delays: {
692
- HOVER_DELAY: 250
693
- },
694
- actions: {
695
- invokeOnChange(ctx2, evt) {
696
- var _a;
697
- if (evt.type !== "SETUP") {
698
- (_a = ctx2.onChange) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
699
- }
700
- },
701
- invokeOnChangeStart(ctx2) {
702
- var _a;
703
- (_a = ctx2.onChangeStart) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
704
- },
705
- invokeOnChangeEnd(ctx2) {
706
- var _a;
707
- (_a = ctx2.onChangeEnd) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
708
- },
709
- setToMin(ctx2) {
710
- ctx2.value = ctx2.min;
711
- },
712
- setToMax(ctx2) {
713
- ctx2.value = ctx2.max;
714
- },
715
- increment(ctx2, evt) {
716
- ctx2.value = clamp(increment(ctx2.value, evt.step), ctx2);
717
- },
718
- decrement(ctx2, evt) {
719
- ctx2.value = clamp(decrement(ctx2.value, evt.step), ctx2);
720
- },
721
- focusSplitter(ctx2) {
722
- raf(() => {
723
- var _a;
724
- return (_a = dom.getSplitterEl(ctx2)) == null ? void 0 : _a.focus();
725
- });
726
- },
727
- setPointerValue(ctx2, evt) {
728
- const el = dom.getPrimaryPaneEl(ctx2);
729
- if (!el)
730
- return;
731
- const relativePoint = getPointRelativeToNode(evt.point, el);
732
- let currentPoint = ctx2.isHorizontal ? relativePoint.x : relativePoint.y;
733
- let value = parseFloat(snapToStep(clamp(currentPoint, ctx2), ctx2.step));
734
- if (Math.abs(value - ctx2.min) <= ctx2.snapOffset) {
735
- value = ctx2.min;
736
- } else if (Math.abs(value - ctx2.max) <= ctx2.snapOffset) {
737
- value = ctx2.max;
738
- }
739
- ctx2.value = value;
740
- }
741
- }
742
- }
743
- );
744
- }
745
- export {
746
- connect,
747
- machine
748
- };