@window-splitter/state 0.2.2 → 0.2.3--canary.823a479.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/.tshy/commonjs.json +1 -0
  2. package/.tshy/esm.json +1 -0
  3. package/.tshy-build/esm/index.d.ts +327 -0
  4. package/.tshy-build/esm/index.d.ts.map +1 -0
  5. package/.tshy-build/esm/index.js +964 -0
  6. package/.tshy-build/esm/index.js.map +1 -0
  7. package/.tshy-build/esm/package.json +3 -0
  8. package/.turbo/turbo-build.log +1 -1
  9. package/.turbo/turbo-lint.log +1 -1
  10. package/.turbo/turbo-test.log +1023 -129
  11. package/coverage/clover.xml +358 -345
  12. package/coverage/coverage-final.json +1 -1
  13. package/coverage/index.html +18 -18
  14. package/coverage/index.ts.html +624 -402
  15. package/dist/commonjs/index.d.ts +22 -9
  16. package/dist/commonjs/index.d.ts.map +1 -1
  17. package/dist/commonjs/index.js +189 -134
  18. package/dist/commonjs/index.js.map +1 -1
  19. package/dist/esm/index.d.ts +22 -9
  20. package/dist/esm/index.d.ts.map +1 -1
  21. package/dist/esm/index.js +188 -114
  22. package/dist/esm/index.js.map +1 -1
  23. package/package.json +6 -6
  24. package/src/index.ts +279 -153
  25. package/src/machine.test.ts +174 -85
  26. package/src/package.json +3 -0
  27. package/src/utils.test.ts +22 -9
  28. package/dist/commonjs/machine.test.d.ts +0 -5
  29. package/dist/commonjs/machine.test.d.ts.map +0 -1
  30. package/dist/commonjs/machine.test.js +0 -1038
  31. package/dist/commonjs/machine.test.js.map +0 -1
  32. package/dist/commonjs/utils.test.d.ts +0 -2
  33. package/dist/commonjs/utils.test.d.ts.map +0 -1
  34. package/dist/commonjs/utils.test.js +0 -79
  35. package/dist/commonjs/utils.test.js.map +0 -1
  36. package/dist/esm/machine.test.d.ts +0 -5
  37. package/dist/esm/machine.test.d.ts.map +0 -1
  38. package/dist/esm/machine.test.js +0 -1036
  39. package/dist/esm/machine.test.js.map +0 -1
  40. package/dist/esm/utils.test.d.ts +0 -2
  41. package/dist/esm/utils.test.d.ts.map +0 -1
  42. package/dist/esm/utils.test.js +0 -77
  43. package/dist/esm/utils.test.js.map +0 -1
package/dist/esm/index.js CHANGED
@@ -1,15 +1,15 @@
1
1
  import { raf } from "@react-spring/rafz";
2
- import { createMachine, assign, enqueueActions, fromPromise } from "xstate";
2
+ import { createMachine, assign, enqueueActions, fromPromise, } from "xstate";
3
3
  import invariant from "invariant";
4
- import * as easings from "d3-ease";
4
+ import Big from "big.js";
5
5
  // #region Constants
6
6
  /** The default amount a user can `dragOvershoot` before the panel collapses */
7
7
  const COLLAPSE_THRESHOLD = 50;
8
- function makePercentUnit(value) {
9
- return { type: "percent", value };
8
+ export function makePercentUnit(value) {
9
+ return { type: "percent", value: new Big(value) };
10
10
  }
11
- function makePixelUnit(value) {
12
- return { type: "pixel", value };
11
+ export function makePixelUnit(value) {
12
+ return { type: "pixel", value: new Big(value) };
13
13
  }
14
14
  function getCollapseAnimation(panel) {
15
15
  let easeFn = collapseAnimations.linear;
@@ -28,13 +28,47 @@ function getCollapseAnimation(panel) {
28
28
  }
29
29
  return { ease: easeFn, duration };
30
30
  }
31
+ /** Copied from https://github.com/d3/d3-ease */
31
32
  const collapseAnimations = {
32
- "ease-in-out": easings.easeQuadInOut,
33
- bounce: easings.easeBackInOut,
34
- linear: easings.easeLinear,
33
+ "ease-in-out": function quadInOut(t) {
34
+ return ((t *= 2) <= 1 ? t * t : --t * (2 - t) + 1) / 2;
35
+ },
36
+ bounce: function backInOut(t) {
37
+ const s = 1.70158;
38
+ return (((t *= 2) < 1
39
+ ? t * t * ((s + 1) * t - s)
40
+ : (t -= 2) * t * ((s + 1) * t + s) + 2) / 2);
41
+ },
42
+ linear: function linear(t) {
43
+ return +t;
44
+ },
35
45
  };
36
46
  // #endregion
37
47
  // #region Helpers
48
+ export function prepareSnapshot(snapshot) {
49
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
50
+ const snapshotContext = snapshot
51
+ .context;
52
+ snapshotContext.dragOvershoot = new Big(snapshotContext.dragOvershoot);
53
+ for (const item of snapshotContext.items) {
54
+ if (isPanelData(item)) {
55
+ item.currentValue.value = new Big(item.currentValue.value);
56
+ if (item.collapsedSize) {
57
+ item.collapsedSize.value = new Big(item.collapsedSize.value);
58
+ }
59
+ if (item.min) {
60
+ item.min.value = new Big(item.min.value);
61
+ }
62
+ if (item.max && item.max !== "1fr") {
63
+ item.max.value = new Big(item.max.value);
64
+ }
65
+ }
66
+ else {
67
+ item.size.value = new Big(item.size.value);
68
+ }
69
+ }
70
+ return snapshot;
71
+ }
38
72
  /** Assert that the provided event is one of the accepted types */
39
73
  function isEvent(event, eventType) {
40
74
  invariant(eventType.includes(event.type), `Invalid event type: ${eventType}. Expected: ${eventType.join(" | ")}`);
@@ -72,6 +106,13 @@ export function initializePanel(item) {
72
106
  };
73
107
  return { ...data, currentValue: makePixelUnit(-1) };
74
108
  }
109
+ export function initializePanelHandleData(item) {
110
+ return {
111
+ type: "handle",
112
+ ...item,
113
+ size: parseUnit(item.size),
114
+ };
115
+ }
75
116
  /** Parse a `Unit` string or `clamp` value */
76
117
  export function parseUnit(unit) {
77
118
  if (unit === "1fr") {
@@ -88,9 +129,9 @@ export function parseUnit(unit) {
88
129
  /** Convert a `Unit` to a percentage of the group size */
89
130
  export function getUnitPercentageValue(groupsSize, unit) {
90
131
  if (unit.type === "pixel") {
91
- return unit.value / groupsSize;
132
+ return groupsSize === 0 ? 0 : unit.value.div(groupsSize).toNumber();
92
133
  }
93
- return unit.value;
134
+ return unit.value.toNumber();
94
135
  }
95
136
  export function getGroupSize(context) {
96
137
  return context.orientation === "horizontal"
@@ -102,11 +143,16 @@ export function getUnitPixelValue(context, unit) {
102
143
  const parsed = unit === "1fr" ? parseUnit(unit) : unit;
103
144
  return parsed.type === "pixel"
104
145
  ? parsed.value
105
- : (parsed.value / 100) * getGroupSize(context);
146
+ : new Big(parsed.value).div(100).mul(getGroupSize(context));
106
147
  }
107
148
  /** Clamp a new `currentValue` given the panel's constraints. */
108
149
  function clampUnit(context, item, value) {
109
- return Math.min(Math.max(value, getUnitPixelValue(context, item.min)), getUnitPixelValue(context, item.max));
150
+ const min = getUnitPixelValue(context, item.min);
151
+ const max = getUnitPixelValue(context, item.max);
152
+ if (value.gte(min) && value.lte(max)) {
153
+ return value;
154
+ }
155
+ return value.lt(min) ? min : max;
110
156
  }
111
157
  /** Get a panel with a particular ID. */
112
158
  export function getPanelWithId(context, panelId) {
@@ -188,15 +234,20 @@ function sortWithOrder(items) {
188
234
  return withoutOrder;
189
235
  }
190
236
  /** Check if the panel has space available to add to */
191
- function panelHasSpace(context, item) {
237
+ function panelHasSpace(context, item, adjustment) {
192
238
  invariant(item.currentValue.type === "pixel", `panelHasSpace only works with number values: ${item.id} ${item.currentValue}`);
193
239
  if (item.collapsible && !item.collapsed) {
194
240
  return true;
195
241
  }
196
- return item.currentValue.value > getUnitPixelValue(context, item.min);
242
+ if (adjustment === "add") {
243
+ return (item.currentValue.value.gte(getUnitPixelValue(context, item.min)) &&
244
+ item.currentValue.value.lt(getUnitPixelValue(context, item.max)));
245
+ }
246
+ return (item.currentValue.value.gt(getUnitPixelValue(context, item.min)) &&
247
+ item.currentValue.value.lte(getUnitPixelValue(context, item.max)));
197
248
  }
198
249
  /** Search in a `direction` for a panel that still has space to expand. */
199
- function findPanelWithSpace(context, items, start, direction, disregardCollapseBuffer) {
250
+ function findPanelWithSpace(context, items, start, direction, adjustment, disregardCollapseBuffer) {
200
251
  const slice = direction === -1 ? items.slice(0, start + 1).reverse() : items.slice(start);
201
252
  for (const panel of slice) {
202
253
  if (!isPanelData(panel)) {
@@ -205,36 +256,36 @@ function findPanelWithSpace(context, items, start, direction, disregardCollapseB
205
256
  const targetPanel = disregardCollapseBuffer
206
257
  ? createUnrestrainedPanel(context, panel)
207
258
  : panel;
208
- if (panelHasSpace(context, targetPanel)) {
259
+ if (panelHasSpace(context, targetPanel, adjustment)) {
209
260
  return panel;
210
261
  }
211
262
  }
212
263
  }
213
264
  /** Add up all the static values in the layout */
214
265
  function getStaticWidth(context) {
215
- let width = 0;
266
+ let width = new Big(0);
216
267
  for (const item of context.items) {
217
268
  if (isPanelHandle(item)) {
218
- width += item.size.value;
269
+ width = width.add(item.size.value);
219
270
  }
220
271
  else if (isPanelData(item) &&
221
272
  item.collapsed &&
222
273
  item.currentValue.type === "pixel") {
223
- width += item.currentValue.value;
274
+ width = width.add(item.currentValue.value);
224
275
  }
225
276
  else if (isPanelData(item) &&
226
277
  item.default &&
227
278
  item.default.type === "pixel") {
228
- width += item.default.value;
279
+ width = width.add(item.default.value);
229
280
  }
230
281
  }
231
282
  return width;
232
283
  }
233
284
  function formatUnit(unit) {
234
285
  if (unit.type === "pixel") {
235
- return `${unit.value}px`;
286
+ return `${unit.value.toNumber()}px`;
236
287
  }
237
- return `${unit.value}%`;
288
+ return `${unit.value.toNumber()}%`;
238
289
  }
239
290
  /** Build the grid template from the item values. */
240
291
  export function buildTemplate(context) {
@@ -244,7 +295,10 @@ export function buildTemplate(context) {
244
295
  if (item.type === "panel") {
245
296
  const min = formatUnit(item.min);
246
297
  if (item.currentValue.type === "pixel" &&
247
- item.currentValue.value !== -1) {
298
+ item.currentValue.value.toNumber() !== -1) {
299
+ if (item.currentValue.value.toNumber() < 0) {
300
+ return "0px";
301
+ }
248
302
  return formatUnit(item.currentValue);
249
303
  }
250
304
  else if (item.currentValue.type === "percent") {
@@ -273,11 +327,11 @@ function addDeDuplicatedItems(items, newItem) {
273
327
  }
274
328
  return sortWithOrder([...restItems, newItem]);
275
329
  }
276
- function createUnrestrainedPanel(context, data) {
330
+ function createUnrestrainedPanel(_, data) {
277
331
  return {
278
332
  ...data,
279
- min: makePixelUnit(0),
280
- max: makePixelUnit(getGroupSize(context)),
333
+ min: makePixelUnit(-100000),
334
+ max: makePixelUnit(100000),
281
335
  };
282
336
  }
283
337
  // #endregion
@@ -341,8 +395,10 @@ export function prepareItems(context) {
341
395
  if (item.currentValue.type === "pixel") {
342
396
  continue;
343
397
  }
344
- // TODO: Decimal proposal
345
- item.currentValue = makePixelUnit(Math.round((getGroupSize(context) - staticWidth) * item.currentValue.value));
398
+ const pixel = new Big(getGroupSize(context))
399
+ .minus(staticWidth)
400
+ .mul(item.currentValue.value);
401
+ item.currentValue = makePixelUnit(pixel.toNumber());
346
402
  }
347
403
  return newItems;
348
404
  }
@@ -362,60 +418,64 @@ function updateLayout(context, dragEvent) {
362
418
  }
363
419
  const moveDirection = moveAmount / Math.abs(moveAmount);
364
420
  // Go forward into the shrinking panels to find a panel that still has space.
365
- const panelBefore = findPanelWithSpace(context, newItems, handleIndex + moveDirection, moveDirection, dragEvent.disregardCollapseBuffer);
421
+ const panelBefore = findPanelWithSpace(context, newItems, handleIndex + moveDirection, moveDirection, "subtract", dragEvent.disregardCollapseBuffer);
366
422
  // No panel with space, just record the drag overshoot
367
423
  if (!panelBefore) {
368
424
  return {
369
- dragOvershoot: context.dragOvershoot + moveAmount,
425
+ dragOvershoot: context.dragOvershoot.add(moveAmount),
370
426
  };
371
427
  }
372
428
  invariant(isPanelData(panelBefore), `Expected panel before: ${handle.id}`);
373
429
  const panelAfter = newItems[handleIndex - moveDirection];
374
430
  invariant(panelAfter && isPanelData(panelAfter), `Expected panel after: ${handle.id}`);
375
- const newDragOvershoot = context.dragOvershoot + moveAmount;
431
+ if (panelAfter.currentValue.value.eq(getUnitPixelValue(context, panelAfter.max))) {
432
+ return {
433
+ dragOvershoot: context.dragOvershoot.add(moveAmount),
434
+ };
435
+ }
436
+ const newDragOvershoot = context.dragOvershoot.add(moveAmount);
376
437
  // Don't let the panel expand until the threshold is reached
377
438
  if (!dragEvent.disregardCollapseBuffer) {
378
- if (panelAfter.collapsible && panelAfter.collapsed) {
379
- const isInLeftBuffer = newDragOvershoot < 0 && moveDirection > 0;
380
- const isInLeftOvershoot = newDragOvershoot > 0 && moveDirection > 0;
381
- const isInRightBuffer = newDragOvershoot > 0 && moveDirection < 0;
382
- const isInRightOvershoot = newDragOvershoot < 0 && moveDirection < 0;
383
- const potentialNewValue = panelAfter.currentValue.value +
384
- newDragOvershoot * (isInRightBuffer ? moveDirection : 1);
385
- const min = getUnitPixelValue(context, panelAfter.min);
386
- if ((newDragOvershoot === 0 ||
439
+ const isInLeftBuffer = newDragOvershoot.lt(0) && moveDirection > 0;
440
+ const isInLeftOvershoot = newDragOvershoot.gt(0) && moveDirection > 0;
441
+ const isInRightBuffer = newDragOvershoot.gt(0) && moveDirection < 0;
442
+ const isInRightOvershoot = newDragOvershoot.lt(0) && moveDirection < 0;
443
+ const potentialNewValue = panelAfter.currentValue.value.add(new Big(newDragOvershoot).mul(isInRightBuffer ? moveDirection : 1));
444
+ const min = getUnitPixelValue(context, panelAfter.min);
445
+ const isInDragBugger = newDragOvershoot.abs().lt(COLLAPSE_THRESHOLD) &&
446
+ panelAfter.collapsible &&
447
+ panelAfter.collapsed &&
448
+ (isInLeftOvershoot || isInRightOvershoot);
449
+ if (potentialNewValue.lte(min) &&
450
+ (newDragOvershoot.eq(0) ||
387
451
  isInRightBuffer ||
388
452
  isInLeftBuffer ||
389
- ((isInLeftOvershoot || isInRightOvershoot) &&
390
- Math.abs(newDragOvershoot) < COLLAPSE_THRESHOLD)) &&
391
- potentialNewValue < min) {
392
- return { dragOvershoot: newDragOvershoot };
393
- }
453
+ isInDragBugger)) {
454
+ return { dragOvershoot: newDragOvershoot };
394
455
  }
395
- // Don't let the panel collapse until the threshold is reached
396
- else if (panelBefore.collapsible &&
397
- panelBefore.currentValue.value ===
398
- getUnitPixelValue(context, panelBefore.min)) {
399
- const potentialNewValue = panelBefore.currentValue.value - Math.abs(newDragOvershoot);
400
- if (Math.abs(newDragOvershoot) < COLLAPSE_THRESHOLD &&
401
- potentialNewValue >
402
- getUnitPixelValue(context, panelBefore.collapsedSize)) {
403
- return { dragOvershoot: newDragOvershoot };
404
- }
456
+ }
457
+ // Don't let the panel collapse until the threshold is reached
458
+ if (panelBefore.collapsible &&
459
+ panelBefore.currentValue.value ===
460
+ getUnitPixelValue(context, panelBefore.min)) {
461
+ const potentialNewValue = panelBefore.currentValue.value.sub(newDragOvershoot.abs());
462
+ if (newDragOvershoot.abs().lt(COLLAPSE_THRESHOLD) &&
463
+ potentialNewValue.gt(getUnitPixelValue(context, panelBefore.collapsedSize))) {
464
+ return { dragOvershoot: newDragOvershoot };
405
465
  }
406
466
  }
407
467
  // Apply the move amount to the panel before the slider
408
468
  const unrestrainedPanelBefore = createUnrestrainedPanel(context, panelBefore);
409
469
  const panelBeforePreviousValue = panelBefore.currentValue.value;
410
- const panelBeforeNewValueRaw = panelBefore.currentValue.value - moveAmount * moveDirection;
470
+ const panelBeforeNewValueRaw = panelBefore.currentValue.value.minus(new Big(moveAmount).mul(moveDirection));
411
471
  let panelBeforeNewValue = dragEvent.disregardCollapseBuffer
412
472
  ? clampUnit(context, unrestrainedPanelBefore, panelBeforeNewValueRaw)
413
473
  : clampUnit(context, panelBefore, panelBeforeNewValueRaw);
414
474
  // Also apply the move amount the panel after the slider
415
475
  const unrestrainedPanelAfter = createUnrestrainedPanel(context, panelAfter);
416
476
  const panelAfterPreviousValue = panelAfter.currentValue.value;
417
- const applied = panelBeforePreviousValue - panelBeforeNewValue;
418
- const panelAfterNewValueRaw = panelAfter.currentValue.value + applied;
477
+ const applied = panelBeforePreviousValue.minus(panelBeforeNewValue);
478
+ const panelAfterNewValueRaw = panelAfter.currentValue.value.add(applied);
419
479
  let panelAfterNewValue = dragEvent.disregardCollapseBuffer
420
480
  ? clampUnit(context, unrestrainedPanelAfter, panelAfterNewValueRaw)
421
481
  : clampUnit(context, panelAfter, panelAfterNewValueRaw);
@@ -437,23 +497,23 @@ function updateLayout(context, dragEvent) {
437
497
  // Calculate the amount "extra" after the minSize the panel should grow
438
498
  const extra =
439
499
  // Take the size it was at
440
- getUnitPixelValue(context, panelAfter.collapsedSize) +
500
+ getUnitPixelValue(context, panelAfter.collapsedSize)
441
501
  // Add in the full overshoot so the cursor is near the slider
442
- Math.abs(context.dragOvershoot) -
502
+ .add(context.dragOvershoot.abs())
443
503
  // Subtract the min size of the panel
444
- panelAfterNewValue +
504
+ .sub(panelAfterNewValue
445
505
  // Then re-add the move amount
446
- Math.abs(moveAmount);
506
+ .add(Math.abs(moveAmount)));
447
507
  panelAfter.collapsed = false;
448
- if (extra > 0) {
449
- panelAfterNewValue += extra;
508
+ if (extra.gt(0)) {
509
+ panelAfterNewValue = panelAfterNewValue.add(extra);
450
510
  }
451
- panelBeforeNewValue -=
511
+ panelBeforeNewValue = panelBeforeNewValue
452
512
  // Subtract the delta of the after panel's size
453
- panelAfterNewValue -
454
- panelAfterPreviousValue -
455
- // And then re-apply the movement value
456
- Math.abs(moveAmount);
513
+ .minus(panelAfterNewValue
514
+ .minus(panelAfterPreviousValue)
515
+ // And then re-apply the movement value
516
+ .minus(Math.abs(moveAmount)));
457
517
  if (panelAfter.onCollapseChange?.current &&
458
518
  !panelAfter.collapseIsControlled &&
459
519
  !dragEvent.controlled) {
@@ -476,22 +536,21 @@ function updateLayout(context, dragEvent) {
476
536
  panelBefore.collapsed = true;
477
537
  panelBeforeNewValue = getUnitPixelValue(context, panelBefore.collapsedSize);
478
538
  // Add the extra space created to the before panel
479
- panelAfterNewValue += panelBeforePreviousValue - panelBeforeNewValue;
539
+ panelAfterNewValue = panelAfterNewValue.add(panelBeforePreviousValue.minus(panelBeforeNewValue));
480
540
  if (panelBefore.onCollapseChange?.current &&
481
541
  !panelBefore.collapseIsControlled &&
482
542
  !dragEvent.controlled) {
483
543
  panelBefore.onCollapseChange.current(true);
484
544
  }
485
545
  }
486
- panelBefore.currentValue = makePixelUnit(panelBeforeNewValue);
487
- panelAfter.currentValue = makePixelUnit(panelAfterNewValue);
488
- const leftoverSpace = getGroupSize(context) -
489
- newItems.reduce((acc, b) => acc +
490
- // in updateLayout the panel units will always be numbers
491
- (isPanelData(b) ? b.currentValue.value : b.size.value), 0);
492
- // TODO: this is wrong?
493
- panelBefore.currentValue.value += leftoverSpace;
494
- return { items: newItems, dragOvershoot: 0 };
546
+ panelBefore.currentValue = { type: "pixel", value: panelBeforeNewValue };
547
+ panelAfter.currentValue = { type: "pixel", value: panelAfterNewValue };
548
+ const leftoverSpace = new Big(getGroupSize(context)).minus(newItems.reduce((acc, b) => acc.add(isPanelData(b) ? b.currentValue.value : b.size.value), new Big(0)));
549
+ if (leftoverSpace.gt(0)) {
550
+ panelBefore.currentValue.value =
551
+ panelBefore.currentValue.value.add(leftoverSpace);
552
+ }
553
+ return { items: newItems };
495
554
  }
496
555
  /** Converts the items to percentages */
497
556
  export function commitLayout(context) {
@@ -515,7 +574,10 @@ export function commitLayout(context) {
515
574
  }
516
575
  newItems[index] = {
517
576
  ...item,
518
- currentValue: makePercentUnit(item.currentValue.value / (getGroupSize(context) - staticWidth)),
577
+ currentValue: {
578
+ type: "percent",
579
+ value: item.currentValue.value.div(new Big(getGroupSize(context)).sub(staticWidth)),
580
+ },
519
581
  };
520
582
  });
521
583
  return newItems;
@@ -535,7 +597,7 @@ export function dragHandlePayload({ delta, orientation, shiftKey = false, }) {
535
597
  /** Iteratively applies a large delta value simulating a user's drag */
536
598
  function iterativelyUpdateLayout({ context, handleId, delta, direction, controlled, disregardCollapseBuffer, }) {
537
599
  let newContext = context;
538
- for (let i = 0; i < Math.abs(delta); i++) {
600
+ for (let i = 0; i < delta.abs().toNumber(); i++) {
539
601
  newContext = updateLayout({
540
602
  ...context,
541
603
  ...newContext,
@@ -555,10 +617,11 @@ function iterativelyUpdateLayout({ context, handleId, delta, direction, controll
555
617
  function applyDeltaInBothDirections(context, newItems, itemIndex, delta) {
556
618
  let hasTriedBothDirections = false;
557
619
  let direction = 1;
620
+ let deltaLeft = new Big(delta);
558
621
  // Starting from where the items was removed add space to the panels around it.
559
622
  // This is only needed for conditional rendering.
560
- while (delta !== 0) {
561
- const targetPanel = findPanelWithSpace(context, newItems, itemIndex + direction, direction);
623
+ while (deltaLeft.toNumber() !== 0) {
624
+ const targetPanel = findPanelWithSpace(context, newItems, itemIndex + direction, direction, delta.gt(0) ? "add" : "subtract");
562
625
  if (!targetPanel) {
563
626
  if (hasTriedBothDirections) {
564
627
  break;
@@ -570,44 +633,47 @@ function applyDeltaInBothDirections(context, newItems, itemIndex, delta) {
570
633
  }
571
634
  }
572
635
  const oldValue = targetPanel.currentValue.value;
573
- const newValue = clampUnit(context, targetPanel, oldValue + delta);
636
+ const newValue = clampUnit(context, targetPanel, oldValue.add(deltaLeft));
574
637
  targetPanel.currentValue.value = newValue;
575
- delta -= newValue - oldValue;
638
+ deltaLeft = deltaLeft.sub(newValue.sub(oldValue));
576
639
  direction = direction === 1 ? -1 : 1;
577
640
  }
578
641
  }
579
642
  const animationActor = fromPromise(({ input: { send, context, event } }) => new Promise((resolve) => {
580
643
  const panel = getPanelWithId(context, event.panelId);
581
644
  const handle = getHandleForPanelId(context, event.panelId);
582
- let direction = handle.direction;
583
- let fullDelta = 0;
645
+ let direction = new Big(handle.direction);
646
+ let fullDelta = new Big(0);
584
647
  if (event.type === "expandPanel") {
585
- fullDelta =
586
- (panel.sizeBeforeCollapse ?? getUnitPixelValue(context, panel.min)) -
587
- panel.currentValue.value;
648
+ fullDelta = new Big(panel.sizeBeforeCollapse ?? getUnitPixelValue(context, panel.min)).minus(panel.currentValue.value);
588
649
  }
589
650
  else {
590
651
  const collapsedSize = getUnitPixelValue(context, panel.collapsedSize);
591
- panel.sizeBeforeCollapse = panel.currentValue.value;
592
- direction *= -1;
593
- fullDelta = panel.currentValue.value - collapsedSize;
652
+ panel.sizeBeforeCollapse = panel.currentValue.value.toNumber();
653
+ direction = direction.mul(new Big(-1));
654
+ fullDelta = panel.currentValue.value.minus(collapsedSize);
594
655
  }
595
656
  const fps = 60;
596
657
  const { duration, ease } = getCollapseAnimation(panel);
597
658
  const totalFrames = Math.ceil(panel.collapseAnimation ? duration / (1000 / fps) : 1);
598
659
  let frame = 0;
599
- let appliedDelta = 0;
660
+ let appliedDelta = new Big(0);
600
661
  function renderFrame() {
601
- const progress = (frame++ + 1) / totalFrames;
602
- const e = panel.collapseAnimation ? ease(progress) : 1;
603
- const delta = (e * fullDelta - appliedDelta) * direction;
604
- send({ type: "applyDelta", handleId: handle.item.id, delta });
605
- appliedDelta +=
606
- Math.abs(delta) *
607
- ((delta > 0 && direction === -1) || (delta < 0 && direction === 1)
608
- ? -1
609
- : 1);
610
- if (e === 1) {
662
+ const progress = ++frame / totalFrames;
663
+ const e = new Big(panel.collapseAnimation ? ease(progress) : 1);
664
+ const delta = e.mul(fullDelta).sub(appliedDelta).mul(direction);
665
+ send({
666
+ type: "applyDelta",
667
+ handleId: handle.item.id,
668
+ delta: delta.toNumber(),
669
+ });
670
+ appliedDelta = appliedDelta.add(delta
671
+ .abs()
672
+ .mul((delta.gt(0) && direction.lt(0)) ||
673
+ (delta.lt(0) && direction.gt(0))
674
+ ? -1
675
+ : 1));
676
+ if (e.eq(1)) {
611
677
  const action = event.type === "expandPanel" ? "expand" : "collapse";
612
678
  resolve({ panelId: panel.id, action });
613
679
  return false;
@@ -627,7 +693,7 @@ export const groupMachine = createMachine({
627
693
  size: { width: 0, height: 0 },
628
694
  items: input.initialItems || [],
629
695
  orientation: input.orientation || "horizontal",
630
- dragOvershoot: 0,
696
+ dragOvershoot: new Big(0),
631
697
  autosaveId: input.autosaveId,
632
698
  groupId: input.groupId,
633
699
  }),
@@ -810,23 +876,29 @@ export const groupMachine = createMachine({
810
876
  });
811
877
  const itemIndex = newItems.findIndex((item) => item.id === event.data.id);
812
878
  const newContext = { ...context, items: newItems };
813
- const overflowDueToHandles = context.items.reduce((acc, i) => {
879
+ const overflowDueToHandles = context.items
880
+ .reduce((acc, i) => {
814
881
  if (isPanelHandle(i)) {
815
- return acc + getUnitPixelValue(context, i.size);
882
+ return acc.add(getUnitPixelValue(context, i.size));
816
883
  }
817
- return acc + i.currentValue.value;
818
- }, 0) - getGroupSize(context);
819
- applyDeltaInBothDirections(newContext, newItems, itemIndex, -1 * (currentValue.value + overflowDueToHandles));
884
+ return acc.add(i.currentValue.value);
885
+ }, new Big(0))
886
+ .minus(getGroupSize(context));
887
+ applyDeltaInBothDirections(newContext, newItems, itemIndex, currentValue.value.add(overflowDueToHandles).neg());
820
888
  return newItems;
821
889
  },
822
890
  }),
823
891
  assignPanelHandleData: assign({
824
892
  items: ({ context, event }) => {
825
893
  isEvent(event, ["registerPanelHandle"]);
894
+ const unit = parseUnit(event.data.size);
826
895
  return addDeDuplicatedItems(context.items, {
827
896
  type: "handle",
828
897
  ...event.data,
829
- size: event.data.size,
898
+ size: {
899
+ type: "pixel",
900
+ value: new Big(unit.value),
901
+ },
830
902
  });
831
903
  },
832
904
  }),
@@ -854,7 +926,7 @@ export const groupMachine = createMachine({
854
926
  enqueue.assign(updateLayout(context, event));
855
927
  }),
856
928
  commit: assign({
857
- dragOvershoot: 0,
929
+ dragOvershoot: new Big(0),
858
930
  items: ({ context }) => commitLayout(context),
859
931
  }),
860
932
  onApplyDelta: assign(({ context, event }) => {
@@ -876,7 +948,9 @@ export const groupMachine = createMachine({
876
948
  const current = panel.currentValue.value;
877
949
  const newSize = clampUnit(context, panel, getUnitPixelValue(context, parseUnit(event.size)));
878
950
  const isBigger = newSize > current;
879
- const delta = isBigger ? newSize - current : current - newSize;
951
+ const delta = isBigger
952
+ ? newSize.minus(current)
953
+ : current.minus(newSize);
880
954
  enqueue.assign(iterativelyUpdateLayout({
881
955
  context,
882
956
  direction: (handle.direction * (isBigger ? 1 : -1)),