@surdeddd/bottom-sheet 0.5.0 → 0.6.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.
package/dist/vue.js CHANGED
@@ -2620,7 +2620,9 @@ var BottomSheetEngine = class {
2620
2620
  const previousSize = this.size;
2621
2621
  this.scrollCache.cache(previousId, previousSize, target.size);
2622
2622
  this.activeId = id;
2623
- if (wasClosed && target.size > 0) {
2623
+ const rawTargetSize = this.snapPointsRaw.find((p) => p.id === id)?.size;
2624
+ const opensToRest = id === "closed" || rawTargetSize === 0;
2625
+ if (wasClosed && !opensToRest) {
2624
2626
  this.opening = true;
2625
2627
  sheetStack.promote(this.id);
2626
2628
  }
@@ -3427,6 +3429,38 @@ var BottomSheetEngine = class {
3427
3429
  }
3428
3430
  };
3429
3431
 
3432
+ // src/core/features/teleport.ts
3433
+ var resolveTeleportTarget = (target) => {
3434
+ if (!target) return null;
3435
+ if (typeof target !== "string") return target;
3436
+ if (typeof document === "undefined") return null;
3437
+ if (target === "body") return document.body;
3438
+ return document.querySelector(target);
3439
+ };
3440
+ var teleportElements = (els, target) => {
3441
+ const records = [];
3442
+ for (const el of els) {
3443
+ if (!el || el.parentNode === target) continue;
3444
+ records.push({ el, parent: el.parentNode, next: el.nextSibling });
3445
+ target.appendChild(el);
3446
+ }
3447
+ return () => {
3448
+ for (let i = records.length - 1; i >= 0; i--) {
3449
+ const { el, parent, next } = records[i];
3450
+ if (parent && parent.isConnected) {
3451
+ const before = next && next.parentNode === parent ? next : null;
3452
+ try {
3453
+ parent.insertBefore(el, before);
3454
+ } catch {
3455
+ el.parentNode?.removeChild(el);
3456
+ }
3457
+ } else {
3458
+ el.parentNode?.removeChild(el);
3459
+ }
3460
+ }
3461
+ };
3462
+ };
3463
+
3430
3464
  // src/vue/useBottomSheet.ts
3431
3465
  function useBottomSheet(opts) {
3432
3466
  const sheetRef = ref(null);
@@ -3443,13 +3477,20 @@ function useBottomSheet(opts) {
3443
3477
  isAnimating: false,
3444
3478
  progress: 0
3445
3479
  });
3480
+ let restoreTeleport = null;
3446
3481
  const sync = () => {
3447
3482
  if (!engine) return;
3448
3483
  Object.assign(state, engine.state);
3449
3484
  };
3450
3485
  onMounted(() => {
3451
3486
  if (!sheetRef.value) return;
3452
- const { onSnap, ...engineOpts } = opts;
3487
+ const {
3488
+ onSnap,
3489
+ teleportTo,
3490
+ backdropColor,
3491
+ backdropOpacity,
3492
+ ...engineOpts
3493
+ } = opts;
3453
3494
  engine = new BottomSheetEngine({
3454
3495
  ...engineOpts,
3455
3496
  element: sheetRef.value,
@@ -3459,6 +3500,17 @@ function useBottomSheet(opts) {
3459
3500
  scrim: screenRef.value ?? void 0
3460
3501
  });
3461
3502
  sync();
3503
+ const target = resolveTeleportTarget(teleportTo);
3504
+ if (target) {
3505
+ restoreTeleport = teleportElements(
3506
+ [backdropRef.value, screenRef.value, sheetRef.value],
3507
+ target
3508
+ );
3509
+ }
3510
+ if (backdropColor !== void 0) engine.setScrimColor(backdropColor);
3511
+ if (backdropOpacity !== void 0) {
3512
+ engine.setBackdropRange([0, backdropOpacity]);
3513
+ }
3462
3514
  engine.on("snap", (payload) => {
3463
3515
  sync();
3464
3516
  onSnap?.(payload.id);
@@ -3474,6 +3526,8 @@ function useBottomSheet(opts) {
3474
3526
  pending.length = 0;
3475
3527
  });
3476
3528
  onBeforeUnmount(() => {
3529
+ restoreTeleport?.();
3530
+ restoreTeleport = null;
3477
3531
  engine?.destroy();
3478
3532
  engine = null;
3479
3533
  });
@@ -3702,6 +3756,23 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
3702
3756
  type: null,
3703
3757
  required: false
3704
3758
  },
3759
+ teleportTo: {
3760
+ type: [
3761
+ String,
3762
+ null,
3763
+ Object
3764
+ ],
3765
+ required: false,
3766
+ default: "body"
3767
+ },
3768
+ backdropColor: {
3769
+ type: String,
3770
+ required: false
3771
+ },
3772
+ backdropOpacity: {
3773
+ type: Number,
3774
+ required: false
3775
+ },
3705
3776
  onSnap: {
3706
3777
  type: Function,
3707
3778
  required: false
@@ -3734,11 +3805,6 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
3734
3805
  required: false,
3735
3806
  default: true
3736
3807
  },
3737
- teleportTo: {
3738
- type: null,
3739
- required: false,
3740
- default: "body"
3741
- },
3742
3808
  anchors: {
3743
3809
  type: Array,
3744
3810
  required: false
@@ -3746,14 +3812,6 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
3746
3812
  scrimStages: {
3747
3813
  type: [Object, null],
3748
3814
  required: false
3749
- },
3750
- backdropColor: {
3751
- type: String,
3752
- required: false
3753
- },
3754
- backdropOpacity: {
3755
- type: Number,
3756
- required: false
3757
3815
  }
3758
3816
  },
3759
3817
  emits: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@surdeddd/bottom-sheet",
3
- "version": "0.5.0",
3
+ "version": "0.6.1",
4
4
  "description": "Universal, headless bottom sheet — framework-agnostic core with React, Vue 3, Svelte, Solid, Qwik, Preact, Lit and Custom Element adapters. Pointer Events, snap points, momentum, a11y, SSR-safe.",
5
5
  "type": "module",
6
6
  "license": "MIT",