@surdeddd/bottom-sheet 0.7.0 → 0.8.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.
@@ -236,6 +236,7 @@ declare class BottomSheetEngine {
236
236
  private progressWriteSentinel;
237
237
  private isTopSheet;
238
238
  private opening;
239
+ private allowOvershoot;
239
240
  private progressPayload;
240
241
  private dragContextBuf;
241
242
  private bus;
@@ -294,8 +295,9 @@ declare class BottomSheetEngine {
294
295
  setSnapPoints(points: EngineOptions["snapPoints"], allowed?: string[]): void;
295
296
  recompute(): void;
296
297
  private contentTargets;
297
- private measureContentExtent;
298
+ private measureSheetNatural;
298
299
  private measureFitSize;
300
+ private containingExtent;
299
301
  private installFitObserver;
300
302
  destroy(): void;
301
303
  private emit;
@@ -236,6 +236,7 @@ declare class BottomSheetEngine {
236
236
  private progressWriteSentinel;
237
237
  private isTopSheet;
238
238
  private opening;
239
+ private allowOvershoot;
239
240
  private progressPayload;
240
241
  private dragContextBuf;
241
242
  private bus;
@@ -294,8 +295,9 @@ declare class BottomSheetEngine {
294
295
  setSnapPoints(points: EngineOptions["snapPoints"], allowed?: string[]): void;
295
296
  recompute(): void;
296
297
  private contentTargets;
297
- private measureContentExtent;
298
+ private measureSheetNatural;
298
299
  private measureFitSize;
300
+ private containingExtent;
299
301
  private installFitObserver;
300
302
  destroy(): void;
301
303
  private emit;
package/dist/element.cjs CHANGED
@@ -2599,6 +2599,7 @@ var init_BottomSheetEngine = __esm({
2599
2599
  __publicField(this, "progressWriteSentinel", new WriteSentinel());
2600
2600
  __publicField(this, "isTopSheet", true);
2601
2601
  __publicField(this, "opening", false);
2602
+ __publicField(this, "allowOvershoot", false);
2602
2603
  __publicField(this, "progressPayload", {
2603
2604
  value: 0,
2604
2605
  size: 0
@@ -3151,45 +3152,52 @@ var init_BottomSheetEngine = __esm({
3151
3152
  }
3152
3153
  return out;
3153
3154
  }
3154
- measureContentExtent(vertical) {
3155
+ measureSheetNatural(vertical) {
3156
+ const el = this.element;
3155
3157
  const content = this.scrollContainer;
3156
- if (!content) return 0;
3157
- const targets = this.contentTargets();
3158
- if (targets.length === 0) {
3159
- return vertical ? content.scrollHeight : content.scrollWidth;
3158
+ if (!content) {
3159
+ return vertical ? el.offsetHeight : el.offsetWidth;
3160
3160
  }
3161
- let min = Infinity;
3162
- let max = -Infinity;
3163
- for (const el of targets) {
3164
- const r = el.getBoundingClientRect();
3165
- if (vertical) {
3166
- if (r.top < min) min = r.top;
3167
- if (r.bottom > max) max = r.bottom;
3168
- } else {
3169
- if (r.left < min) min = r.left;
3170
- if (r.right > max) max = r.right;
3171
- }
3172
- }
3173
- if (!isFinite(min) || !isFinite(max) || max <= min) {
3174
- return vertical ? content.scrollHeight : content.scrollWidth;
3175
- }
3176
- let pad = 0;
3177
- if (typeof getComputedStyle !== "undefined") {
3178
- const cs = getComputedStyle(content);
3179
- pad = vertical ? (parseFloat(cs.paddingTop) || 0) + (parseFloat(cs.paddingBottom) || 0) : (parseFloat(cs.paddingLeft) || 0) + (parseFloat(cs.paddingRight) || 0);
3180
- }
3181
- return max - min + pad;
3161
+ const axis = vertical ? "height" : "width";
3162
+ const sheetStyle = el.style;
3163
+ const cs = content.style;
3164
+ const prevSheet = sheetStyle[axis];
3165
+ const prevFlex = cs.flex;
3166
+ const prevContent = vertical ? cs.height : cs.width;
3167
+ sheetStyle[axis] = "auto";
3168
+ cs.flex = "none";
3169
+ if (vertical) cs.height = "auto";
3170
+ else cs.width = "auto";
3171
+ const poked = vertical ? el.offsetHeight : el.offsetWidth;
3172
+ const contentBox = vertical ? content.clientHeight : content.clientWidth;
3173
+ const contentScroll = vertical ? content.scrollHeight : content.scrollWidth;
3174
+ const natural = Math.max(poked, poked - contentBox + contentScroll);
3175
+ sheetStyle[axis] = prevSheet;
3176
+ cs.flex = prevFlex;
3177
+ if (vertical) cs.height = prevContent;
3178
+ else cs.width = prevContent;
3179
+ return natural;
3182
3180
  }
3183
3181
  measureFitSize() {
3184
3182
  const vertical = layoutAxis(this.mode) === "height";
3185
- const handleSize = vertical ? this.handle.offsetHeight : this.handle.offsetWidth;
3186
- const content = this.scrollContainer;
3187
- const natural = content ? handleSize + this.measureContentExtent(vertical) : handleSize;
3183
+ const natural = this.measureSheetNatural(vertical);
3188
3184
  const capped = this.maxHeightCap !== void 0 ? Math.min(natural, this.maxHeightCap) : natural;
3189
3185
  if (typeof window === "undefined") return capped;
3190
- const viewport = vertical ? window.innerHeight : window.innerWidth;
3186
+ const viewport = this.containingExtent(vertical);
3191
3187
  return viewport > 0 ? Math.min(capped, viewport) : capped;
3192
3188
  }
3189
+ // The fit cap is the sheet's containing block, not always the window: a
3190
+ // position:fixed sheet nested under a transform/filter/will-change ancestor
3191
+ // is clipped to that ancestor, so capping by window.innerHeight oversizes the
3192
+ // sheet and the content/footer get clipped. offsetParent resolves to that
3193
+ // ancestor when present, and is null (→ viewport) for a plain fixed sheet.
3194
+ containingExtent(vertical) {
3195
+ const op = this.element.offsetParent;
3196
+ if (op && op !== document.body && op !== document.documentElement) {
3197
+ return vertical ? op.clientHeight : op.clientWidth;
3198
+ }
3199
+ return vertical ? window.innerHeight : window.innerWidth;
3200
+ }
3193
3201
  installFitObserver() {
3194
3202
  if (typeof ResizeObserver === "undefined") return;
3195
3203
  if (!this.snapPointsRaw.some((p) => p.size === "fit" || p.size === "content"))
@@ -3270,6 +3278,10 @@ var init_BottomSheetEngine = __esm({
3270
3278
  this.backdrop.style.opacity = "";
3271
3279
  this.backdrop.style.pointerEvents = "";
3272
3280
  }
3281
+ if (this.anchorHost) {
3282
+ this.anchorHost.style.removeProperty("--bs-size");
3283
+ this.anchorHost.style.removeProperty("--bs-progress");
3284
+ }
3273
3285
  if (this.screenComponent) {
3274
3286
  this.screenComponent.style.opacity = "";
3275
3287
  this.screenComponent.style.display = "";
@@ -3281,6 +3293,7 @@ var init_BottomSheetEngine = __esm({
3281
3293
  this.bus.emit(event, payload);
3282
3294
  }
3283
3295
  newCycle() {
3296
+ this.allowOvershoot = false;
3284
3297
  this.currentAbort.abort();
3285
3298
  this.currentAbort = new AbortController();
3286
3299
  return this.currentAbort.signal;
@@ -3346,6 +3359,7 @@ var init_BottomSheetEngine = __esm({
3346
3359
  seen.add(p.id);
3347
3360
  }
3348
3361
  this.snaps.setRaw(this.snapPointsRaw);
3362
+ this.clampToMaxHeight();
3349
3363
  this.scrim.invalidateOpacityCache();
3350
3364
  }
3351
3365
  getAllowedRange() {
@@ -3552,9 +3566,13 @@ var init_BottomSheetEngine = __esm({
3552
3566
  this.opening = true;
3553
3567
  sheetStack.promote(this.id);
3554
3568
  }
3555
- void this.animation.animateTo(target.size, velocity).then(() => {
3556
- this.opening = false;
3569
+ const settleCap = this.snaps.getMaxAxisSize();
3570
+ const settleSize = settleCap > 0 ? Math.min(target.size, settleCap) : target.size;
3571
+ this.allowOvershoot = true;
3572
+ void this.animation.animateTo(settleSize, velocity).then(() => {
3557
3573
  if (signal.aborted) return;
3574
+ this.allowOvershoot = false;
3575
+ this.opening = false;
3558
3576
  this.scrollCache.restore(target.id, previousSize, target.size);
3559
3577
  this.updateAriaSlider();
3560
3578
  this.emit("snap", {
@@ -3586,7 +3604,7 @@ var init_BottomSheetEngine = __esm({
3586
3604
  }
3587
3605
  applySize(size) {
3588
3606
  const cap = this.snaps.getMaxAxisSize();
3589
- const clamped = cap > 0 && size > cap && !this.gesture?.isDragging ? cap : size;
3607
+ const clamped = cap > 0 && size > cap && !this.gesture?.isDragging && !this.allowOvershoot ? cap : size;
3590
3608
  this.size = clamped;
3591
3609
  const offset = cap - clamped;
3592
3610
  const style = this.element.style;
@@ -1,4 +1,4 @@
1
- import { B as BottomSheetEngine, C as CloseReason, A as AnchorOptions, S as ScrimStagesOptions, E as EngineState } from './BottomSheetEngine-CqiCz64W.cjs';
1
+ import { B as BottomSheetEngine, C as CloseReason, A as AnchorOptions, S as ScrimStagesOptions, E as EngineState } from './BottomSheetEngine-7BDK2OWX.cjs';
2
2
  import './transform-jVfAikE9.cjs';
3
3
 
4
4
  declare const BaseHTMLElement: typeof HTMLElement;
package/dist/element.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { B as BottomSheetEngine, C as CloseReason, A as AnchorOptions, S as ScrimStagesOptions, E as EngineState } from './BottomSheetEngine-BHjKFtnM.js';
1
+ import { B as BottomSheetEngine, C as CloseReason, A as AnchorOptions, S as ScrimStagesOptions, E as EngineState } from './BottomSheetEngine-BFTb0-4Z.js';
2
2
  import './transform-jVfAikE9.js';
3
3
 
4
4
  declare const BaseHTMLElement: typeof HTMLElement;