@surdeddd/bottom-sheet 0.23.2 → 0.23.4

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 (62) hide show
  1. package/README.md +18 -16
  2. package/README.ru.md +697 -0
  3. package/dist/{BottomSheetCore-CQStdVy2.d.cts → BottomSheetCore-C5tJYVMY.d.cts} +4 -1
  4. package/dist/{BottomSheetCore-9i-Uh6T3.d.ts → BottomSheetCore-DxSrC4QC.d.ts} +4 -1
  5. package/dist/{BottomSheetEngine-CsQWHLNb.d.cts → BottomSheetEngine-B3F9qukX.d.cts} +1 -1
  6. package/dist/{BottomSheetEngine-Dn6h-7gF.d.ts → BottomSheetEngine-BchzgqGG.d.ts} +1 -1
  7. package/dist/core.cjs +43 -13
  8. package/dist/core.d.cts +2 -2
  9. package/dist/core.d.ts +2 -2
  10. package/dist/core.js +43 -13
  11. package/dist/debug.d.cts +3 -2
  12. package/dist/debug.d.ts +3 -2
  13. package/dist/{default-features-DkG9aho0.d.cts → default-features-BGiCSmV1.d.cts} +1 -1
  14. package/dist/{default-features-C3cilcW9.d.ts → default-features-DwVTzDwP.d.ts} +1 -1
  15. package/dist/element.cjs +107 -21
  16. package/dist/element.d.cts +5 -3
  17. package/dist/element.d.ts +5 -3
  18. package/dist/element.iife.global.js +2 -2
  19. package/dist/element.js +107 -21
  20. package/dist/features.cjs +56 -3
  21. package/dist/features.d.cts +3 -3
  22. package/dist/features.d.ts +3 -3
  23. package/dist/features.js +56 -3
  24. package/dist/{index-CnsJQZp2.d.ts → index-C7TSQkVK.d.cts} +3 -2
  25. package/dist/{index-CVGC5B5D.d.cts → index-CdM1tke5.d.ts} +3 -2
  26. package/dist/index.cjs +96 -16
  27. package/dist/index.d.cts +7 -6
  28. package/dist/index.d.ts +7 -6
  29. package/dist/index.js +96 -16
  30. package/dist/integrations/formik.d.cts +3 -2
  31. package/dist/integrations/formik.d.ts +3 -2
  32. package/dist/integrations/react-hook-form.d.cts +3 -2
  33. package/dist/integrations/react-hook-form.d.ts +3 -2
  34. package/dist/overlay.d.cts +2 -1
  35. package/dist/overlay.d.ts +2 -1
  36. package/dist/preact.d.cts +2 -2
  37. package/dist/preact.d.ts +2 -2
  38. package/dist/qwik-lib/index.qwik.cjs +87 -16
  39. package/dist/qwik-lib/index.qwik.mjs +87 -16
  40. package/dist/qwik.cjs +96 -16
  41. package/dist/qwik.d.cts +5 -3
  42. package/dist/qwik.d.ts +5 -3
  43. package/dist/qwik.js +96 -16
  44. package/dist/react.cjs +96 -16
  45. package/dist/react.d.cts +8 -5
  46. package/dist/react.d.ts +8 -5
  47. package/dist/react.js +96 -16
  48. package/dist/solid.cjs +96 -16
  49. package/dist/solid.d.cts +4 -1
  50. package/dist/solid.d.ts +4 -1
  51. package/dist/solid.js +96 -16
  52. package/dist/solid.source.jsx +96 -16
  53. package/dist/svelte-core.cjs +98 -16
  54. package/dist/svelte-core.js +97 -17
  55. package/dist/svelte-src/BottomSheet.svelte +1 -1
  56. package/dist/svelte.cjs +97 -18
  57. package/dist/svelte.js +97 -18
  58. package/dist/vue.cjs +96 -16
  59. package/dist/vue.js +96 -16
  60. package/dist/webgl.d.cts +3 -2
  61. package/dist/webgl.d.ts +3 -2
  62. package/package.json +32 -34
package/dist/element.cjs CHANGED
@@ -3,8 +3,13 @@
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
- var __esm = (fn, res) => function __init() {
7
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
6
+ var __esm = (fn, res, err) => function __init() {
7
+ if (err) throw err[0];
8
+ try {
9
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
+ } catch (e) {
11
+ throw err = [e], e;
12
+ }
8
13
  };
9
14
  var __export = (target, all) => {
10
15
  for (var name in all)
@@ -99,9 +104,10 @@ function buildTransformTemplate(axis) {
99
104
  return (offset) => `translate3d(${offset}px, 0, 0)`;
100
105
  }
101
106
  }
102
- var layoutAxis;
107
+ var offsetFromMatrix, layoutAxis;
103
108
  var init_transform = __esm({
104
109
  "src/core/primitives/transform.ts"() {
110
+ offsetFromMatrix = (axis, m) => axis === "bottom" ? m.m42 : axis === "top" ? -m.m42 : axis === "left" ? -m.m41 : m.m41;
105
111
  layoutAxis = (axis) => axis === "left" || axis === "right" ? "width" : "height";
106
112
  }
107
113
  });
@@ -1288,7 +1294,7 @@ var init_animation = __esm({
1288
1294
  }
1289
1295
  const step = (now) => {
1290
1296
  if (cancelled) return;
1291
- const elapsed = now - start;
1297
+ const elapsed = Math.max(0, now - start);
1292
1298
  const t = Math.min(elapsed / duration, 1);
1293
1299
  const value = from + (to - from) * easing(t);
1294
1300
  onUpdate(value);
@@ -1346,8 +1352,8 @@ var init_spring = __esm({
1346
1352
  resolveFn = resolve;
1347
1353
  const step = (now) => {
1348
1354
  if (cancelled) return;
1349
- const dt = Math.min((now - lastTime) / 1e3, MAX_DT);
1350
- lastTime = now;
1355
+ const dt = Math.min(Math.max(0, now - lastTime) / 1e3, MAX_DT);
1356
+ lastTime = Math.max(lastTime, now);
1351
1357
  const steps = Math.max(1, Math.ceil(dt * 240));
1352
1358
  const subDt = dt / steps;
1353
1359
  let stepsLeft = steps;
@@ -1460,10 +1466,11 @@ function sampleTweenSettle(from, to, durationMs, easing) {
1460
1466
  durationMs
1461
1467
  };
1462
1468
  }
1463
- var SIM_HZ, SAMPLE_STRIDE, MAX_SIM_MS;
1469
+ var SETTLE_ANIMATION_ID, SIM_HZ, SAMPLE_STRIDE, MAX_SIM_MS;
1464
1470
  var init_waapi_settle = __esm({
1465
1471
  "src/core/animation/waapi-settle.ts"() {
1466
1472
  init_spring();
1473
+ SETTLE_ANIMATION_ID = "bs-settle";
1467
1474
  SIM_HZ = 240;
1468
1475
  SAMPLE_STRIDE = 4;
1469
1476
  MAX_SIM_MS = 3e3;
@@ -1489,6 +1496,7 @@ var init_animation_runner = __esm({
1489
1496
  __publicField(this, "isDragging");
1490
1497
  __publicField(this, "applyAux");
1491
1498
  __publicField(this, "getTransformFor");
1499
+ __publicField(this, "readShownSize");
1492
1500
  __publicField(this, "settleWaapi");
1493
1501
  __publicField(this, "currentWaapi", null);
1494
1502
  __publicField(this, "animationKind");
@@ -1508,6 +1516,7 @@ var init_animation_runner = __esm({
1508
1516
  this.isDragging = deps.isDragging;
1509
1517
  this.applyAux = deps.applyAux;
1510
1518
  this.getTransformFor = deps.getTransformFor;
1519
+ this.readShownSize = deps.readShownSize;
1511
1520
  this.settleWaapi = opts.settleAnimation === "waapi";
1512
1521
  const preset = resolveAnimationPreset(opts.animation);
1513
1522
  this.animationKind = preset.kind;
@@ -1540,10 +1549,12 @@ var init_animation_runner = __esm({
1540
1549
  const entry = this.currentWaapi;
1541
1550
  this.currentWaapi = null;
1542
1551
  entry.stop();
1552
+ const size = this.readShownSize?.() ?? entry.sizeNow();
1543
1553
  try {
1544
1554
  entry.anim.cancel();
1545
1555
  } catch {
1546
1556
  }
1557
+ this.applySizeFn(size);
1547
1558
  }
1548
1559
  cancel() {
1549
1560
  this.currentTween?.cancel();
@@ -1553,6 +1564,7 @@ var init_animation_runner = __esm({
1553
1564
  async animateTo(target, velocityPxPerMs) {
1554
1565
  if (target === this.getSize()) {
1555
1566
  if (!this.isAnimating && !this.isDragging()) {
1567
+ this.applySizeFn(target);
1556
1568
  this.element.style.willChange = "";
1557
1569
  }
1558
1570
  return;
@@ -1589,6 +1601,7 @@ var init_animation_runner = __esm({
1589
1601
  return;
1590
1602
  }
1591
1603
  }
1604
+ let current = false;
1592
1605
  if (this.animationKind === "spring") {
1593
1606
  const spring = runSpring({
1594
1607
  from: this.getSize(),
@@ -1599,7 +1612,8 @@ var init_animation_runner = __esm({
1599
1612
  });
1600
1613
  this.currentSpring = spring;
1601
1614
  await spring.promise;
1602
- if (this.currentSpring === spring) this.currentSpring = null;
1615
+ current = this.currentSpring === spring;
1616
+ if (current) this.currentSpring = null;
1603
1617
  } else {
1604
1618
  const tw = tween({
1605
1619
  from: this.getSize(),
@@ -1610,11 +1624,15 @@ var init_animation_runner = __esm({
1610
1624
  });
1611
1625
  this.currentTween = tw;
1612
1626
  await tw.promise;
1613
- if (this.currentTween === tw) this.currentTween = null;
1627
+ current = this.currentTween === tw;
1628
+ if (current) this.currentTween = null;
1614
1629
  }
1615
1630
  if (!this.isAnimating) {
1616
1631
  this.getRootEl()?.removeAttribute("data-animating");
1617
- if (!this.isDragging()) this.element.style.willChange = "";
1632
+ if (!this.isDragging()) {
1633
+ if (current) this.applySizeFn(this.getSize());
1634
+ this.element.style.willChange = "";
1635
+ }
1618
1636
  }
1619
1637
  }
1620
1638
  async runWaapiSettle(samples, target) {
@@ -1628,11 +1646,11 @@ var init_animation_runner = __esm({
1628
1646
  easing: "linear",
1629
1647
  fill: "forwards"
1630
1648
  });
1649
+ anim.id = SETTLE_ANIMATION_ID;
1631
1650
  let stopped = false;
1632
1651
  let auxRaf = 0;
1633
1652
  const lastIdx = samples.values.length - 1;
1634
- const auxTick = () => {
1635
- if (stopped) return;
1653
+ const sizeNow = () => {
1636
1654
  const at = Math.min(
1637
1655
  (Number(anim.currentTime) || 0) / samples.stepMs,
1638
1656
  lastIdx
@@ -1640,7 +1658,11 @@ var init_animation_runner = __esm({
1640
1658
  const idx = Math.floor(at);
1641
1659
  const from = samples.values[idx];
1642
1660
  const to = samples.values[Math.min(idx + 1, lastIdx)];
1643
- applyAux(from + (to - from) * (at - idx));
1661
+ return from + (to - from) * (at - idx);
1662
+ };
1663
+ const auxTick = () => {
1664
+ if (stopped) return;
1665
+ applyAux(sizeNow());
1644
1666
  auxRaf = requestAnimationFrame(auxTick);
1645
1667
  };
1646
1668
  auxRaf = requestAnimationFrame(auxTick);
@@ -1649,7 +1671,8 @@ var init_animation_runner = __esm({
1649
1671
  stop: () => {
1650
1672
  stopped = true;
1651
1673
  cancelAnimationFrame(auxRaf);
1652
- }
1674
+ },
1675
+ sizeNow
1653
1676
  };
1654
1677
  this.currentWaapi = entry;
1655
1678
  try {
@@ -2888,6 +2911,7 @@ var init_BottomSheetCore = __esm({
2888
2911
  __publicField(this, "closeOnBack");
2889
2912
  __publicField(this, "routedTo");
2890
2913
  __publicField(this, "fitContentToSnap");
2914
+ __publicField(this, "settleAnimation");
2891
2915
  __publicField(this, "persistent");
2892
2916
  __publicField(this, "disableCloseFlag");
2893
2917
  __publicField(this, "disableDragFlag");
@@ -2992,6 +3016,11 @@ var init_BottomSheetCore = __esm({
2992
3016
  const cap = this.snaps.getMaxAxisSize();
2993
3017
  const shown = cap > 0 && !this.allowOvershoot ? Math.min(size, cap) : size;
2994
3018
  return this.transformTemplate(cap - shown);
3019
+ },
3020
+ readShownSize: () => {
3021
+ const shown = getComputedStyle(this.element).transform;
3022
+ if (!shown || shown === "none") return void 0;
3023
+ return this.snaps.getMaxAxisSize() - offsetFromMatrix(this.mode, new DOMMatrix(shown));
2995
3024
  }
2996
3025
  },
2997
3026
  resolved.animation
@@ -3006,6 +3035,7 @@ var init_BottomSheetCore = __esm({
3006
3035
  this.closeOnBack = resolved.closeOnBack;
3007
3036
  this.routedTo = opts.routedTo;
3008
3037
  this.fitContentToSnap = opts.fitContentToSnap === true;
3038
+ this.settleAnimation = opts.settleAnimation;
3009
3039
  this.persistent = resolved.persistent;
3010
3040
  this.disableCloseFlag = resolved.disableClose;
3011
3041
  this.disableDragFlag = resolved.disableDrag;
@@ -3108,7 +3138,8 @@ var init_BottomSheetCore = __esm({
3108
3138
  closeOnRouteChange: this.closeOnRouteChange,
3109
3139
  persistKey: this.persistKey,
3110
3140
  autoCollapseAfter,
3111
- fitContentToSnap: this.fitContentToSnap
3141
+ fitContentToSnap: this.fitContentToSnap,
3142
+ settleAnimation: this.settleAnimation
3112
3143
  },
3113
3144
  isDestroyed: () => this.destroyed,
3114
3145
  isDragging: () => this.isDraggingAny(),
@@ -4000,7 +4031,11 @@ var init_BottomSheetCore = __esm({
4000
4031
  const offset = cap - clamped;
4001
4032
  const style = this.element.style;
4002
4033
  if (!skipTransform) style.transform = this.transformTemplate(offset);
4003
- if (this.sizeWriteSentinel.shouldWrite(clamped, SIZE_WRITE_EPSILON)) {
4034
+ const sizeChanged = this.sizeWriteSentinel.shouldWrite(
4035
+ clamped,
4036
+ this.animation.isAnimating || this.isDraggingAny() ? SIZE_WRITE_EPSILON : 0
4037
+ );
4038
+ if (sizeChanged) {
4004
4039
  style.setProperty("--bs-size", `${clamped}px`);
4005
4040
  if (this.scrimParent) {
4006
4041
  this.scrimParent.style.setProperty("--bs-size", `${clamped}px`);
@@ -4027,7 +4062,7 @@ var init_BottomSheetCore = __esm({
4027
4062
  }
4028
4063
  }
4029
4064
  this.scrim.applyOpacity(progress, progressChanged);
4030
- if (progressChanged && this.bus.listenerCount("progress") > 0) {
4065
+ if ((progressChanged || sizeChanged) && this.bus.listenerCount("progress") > 0) {
4031
4066
  this.progressPayload.value = progress;
4032
4067
  this.progressPayload.size = clamped;
4033
4068
  this.emit("progress", this.progressPayload);
@@ -4571,10 +4606,14 @@ function contentFitFeature() {
4571
4606
  return;
4572
4607
  }
4573
4608
  const sheet = ctx.element;
4609
+ const waapi = ctx.options.settleAnimation === "waapi";
4574
4610
  let inset = 0;
4575
4611
  let unpaddedMax = -1;
4576
4612
  let top = 0;
4577
4613
  let resting = false;
4614
+ let liftMax = 0;
4615
+ let followed = null;
4616
+ let follower = null;
4578
4617
  const put = (name, px) => sheet.style.setProperty(name, `${px}px`);
4579
4618
  const hiddenAt = (size) => sheet.dataset.mode === "bottom" ? Math.max(0, ctx.getMaxAxisSize() - size) : 0;
4580
4619
  const follow = (size) => {
@@ -4588,8 +4627,45 @@ function contentFitFeature() {
4588
4627
  top = limit;
4589
4628
  }
4590
4629
  };
4630
+ const unfollow = () => {
4631
+ follower?.cancel();
4632
+ follower = null;
4633
+ followed = null;
4634
+ };
4635
+ const followSettle = () => {
4636
+ if (followed?.playState === "running") return;
4637
+ const settleAnim = sheet.getAnimations?.().find((a) => a.id === SETTLE_ANIMATION_ID);
4638
+ const footer = sheet.querySelector(".bs-footer");
4639
+ if (!settleAnim || !footer) return;
4640
+ const effect = settleAnim.effect;
4641
+ unfollow();
4642
+ const own = footer.animate(
4643
+ effect.getKeyframes().map((k) => ({
4644
+ offset: k.computedOffset,
4645
+ transform: `translateY(${-Math.min(
4646
+ Math.max(0, parseFloat(String(k.transform).split(",")[1]) || 0),
4647
+ liftMax
4648
+ )}px)`
4649
+ })),
4650
+ {
4651
+ duration: effect.getTiming().duration,
4652
+ easing: "linear",
4653
+ fill: "forwards"
4654
+ }
4655
+ );
4656
+ follower = own;
4657
+ followed = settleAnim;
4658
+ const done = () => {
4659
+ if (followed === settleAnim) unfollow();
4660
+ };
4661
+ settleAnim.ready.then(() => {
4662
+ if (follower === own) own.startTime = settleAnim.startTime;
4663
+ }, done);
4664
+ settleAnim.finished.then(done, done);
4665
+ };
4591
4666
  const settle = () => {
4592
4667
  if (ctx.isDestroyed()) return;
4668
+ unfollow();
4593
4669
  const size = ctx.getSize();
4594
4670
  if (!resting) {
4595
4671
  unpaddedMax = -1;
@@ -4597,7 +4673,6 @@ function contentFitFeature() {
4597
4673
  }
4598
4674
  inset = hiddenAt(size);
4599
4675
  put(INSET_VAR, inset);
4600
- put(SIZE_VAR, size);
4601
4676
  put(CAP_VAR, ctx.getMaxAxisSize());
4602
4677
  if (!resting) {
4603
4678
  resting = true;
@@ -4609,9 +4684,13 @@ function contentFitFeature() {
4609
4684
  if (resting) {
4610
4685
  resting = false;
4611
4686
  sheet.setAttribute(FIT_ATTR, "moving");
4612
- put(LIFT_VAR, scroller.offsetHeight);
4687
+ liftMax = scroller.offsetHeight;
4688
+ put(LIFT_VAR, liftMax);
4613
4689
  }
4614
4690
  follow(size);
4691
+ if (waapi && ctx.isAnimating() && sheet.dataset.mode === "bottom") {
4692
+ followSettle();
4693
+ }
4615
4694
  };
4616
4695
  const moving = () => ctx.isAnimating() || ctx.isDragging();
4617
4696
  const whenIdle = () => {
@@ -4624,13 +4703,20 @@ function contentFitFeature() {
4624
4703
  );
4625
4704
  const offSnap = ctx.on("snap", settle);
4626
4705
  const offDragStart = ctx.on("dragstart", () => move(ctx.getSize()));
4706
+ const offBeforeSnap = ctx.on("before-snap", () => {
4707
+ queueMicrotask(() => {
4708
+ if (!ctx.isDestroyed() && ctx.isAnimating()) move(ctx.getSize());
4709
+ });
4710
+ });
4627
4711
  const observer = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(whenIdle);
4628
4712
  observer?.observe(document.documentElement);
4629
4713
  window.addEventListener("orientationchange", whenIdle);
4630
4714
  return () => {
4715
+ unfollow();
4631
4716
  offProgress();
4632
4717
  offSnap();
4633
4718
  offDragStart();
4719
+ offBeforeSnap();
4634
4720
  observer?.disconnect();
4635
4721
  window.removeEventListener("orientationchange", whenIdle);
4636
4722
  sheet.removeAttribute(FIT_ATTR);
@@ -4641,11 +4727,11 @@ function contentFitFeature() {
4641
4727
  }
4642
4728
  };
4643
4729
  }
4644
- var INSET_VAR, SIZE_VAR, CAP_VAR, LIFT_VAR, FIT_ATTR;
4730
+ var INSET_VAR, CAP_VAR, LIFT_VAR, FIT_ATTR;
4645
4731
  var init_content_fit = __esm({
4646
4732
  "src/core/features/content-fit.ts"() {
4733
+ init_waapi_settle();
4647
4734
  INSET_VAR = "--bs-content-inset";
4648
- SIZE_VAR = "--bs-size";
4649
4735
  CAP_VAR = "--bs-max-size";
4650
4736
  LIFT_VAR = "--bs-footer-lift-max";
4651
4737
  FIT_ATTR = "data-bs-fit-content";
@@ -1,5 +1,6 @@
1
- import { B as BottomSheetEngine } from './BottomSheetEngine-CsQWHLNb.cjs';
2
- import { C as CloseReason, A as AnchorOptions, i as ScrimStagesOptions, d as EngineState } from './BottomSheetCore-CQStdVy2.cjs';
1
+ import { BottomSheetEngine } from './index.cjs';
2
+ import { CloseReason, EngineState } from './core.cjs';
3
+ import { AnchorOptions, ScrimStagesOptions } from './index.cjs';
3
4
  import './transform-jVfAikE9.cjs';
4
5
 
5
6
  declare const BaseHTMLElement: typeof HTMLElement;
@@ -58,4 +59,5 @@ type TypedBottomSheetElement<TId extends string = string> = HTMLElement & {
58
59
  };
59
60
  declare const defineBottomSheet: (tag?: string) => void;
60
61
 
61
- export { BottomSheetElement, type TypedBottomSheetElement, defineBottomSheet };
62
+ export { BottomSheetElement, defineBottomSheet };
63
+ export type { TypedBottomSheetElement };
package/dist/element.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { B as BottomSheetEngine } from './BottomSheetEngine-Dn6h-7gF.js';
2
- import { C as CloseReason, A as AnchorOptions, i as ScrimStagesOptions, d as EngineState } from './BottomSheetCore-9i-Uh6T3.js';
1
+ import { BottomSheetEngine } from './index.js';
2
+ import { CloseReason, EngineState } from './core.js';
3
+ import { AnchorOptions, ScrimStagesOptions } from './index.js';
3
4
  import './transform-jVfAikE9.js';
4
5
 
5
6
  declare const BaseHTMLElement: typeof HTMLElement;
@@ -58,4 +59,5 @@ type TypedBottomSheetElement<TId extends string = string> = HTMLElement & {
58
59
  };
59
60
  declare const defineBottomSheet: (tag?: string) => void;
60
61
 
61
- export { BottomSheetElement, type TypedBottomSheetElement, defineBottomSheet };
62
+ export { BottomSheetElement, defineBottomSheet };
63
+ export type { TypedBottomSheetElement };