@abhivarde/svelte-drawer 0.0.19 → 0.0.20

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.
@@ -25,8 +25,26 @@
25
25
  });
26
26
 
27
27
  let previouslyFocusedElement: HTMLElement | null = null;
28
-
29
28
  let visible = false;
29
+ let previousSnapPoint: number | undefined = undefined;
30
+
31
+ $effect(() => {
32
+ if (
33
+ open &&
34
+ snapPoints &&
35
+ snapPoints.length > 0 &&
36
+ activeSnapPoint !== undefined
37
+ ) {
38
+ if (
39
+ previousSnapPoint !== undefined &&
40
+ previousSnapPoint !== activeSnapPoint
41
+ ) {
42
+ const snapPos = (1 - activeSnapPoint) * 100;
43
+ drawerPosition.set(snapPos, { duration: 220 });
44
+ }
45
+ previousSnapPoint = activeSnapPoint;
46
+ }
47
+ });
30
48
 
31
49
  $effect(() => {
32
50
  if (open) {
@@ -67,6 +85,7 @@
67
85
 
68
86
  setTimeout(() => {
69
87
  visible = false;
88
+ previousSnapPoint = undefined;
70
89
  }, 180);
71
90
  }
72
91
  });
@@ -28,8 +28,6 @@
28
28
  let dragging = false;
29
29
 
30
30
  function snapPointToPosition(snapPoint: number): number {
31
- // snapPoint is 0-1 where 1 = fully open (0% position)
32
- // Convert: 1 -> 0%, 0.5 -> 50%, 0 -> 100%
33
31
  return (1 - snapPoint) * 100;
34
32
  }
35
33
 
@@ -56,25 +54,6 @@
56
54
  function getTransform(): string {
57
55
  const pos = drawer.drawerPosition.current;
58
56
 
59
- if (
60
- drawer.snapPoints &&
61
- drawer.activeSnapPoint !== undefined &&
62
- !dragging &&
63
- drawer.open
64
- ) {
65
- const snapPos = snapPointToPosition(drawer.activeSnapPoint);
66
- switch (drawer.direction) {
67
- case "bottom":
68
- return `translateY(${snapPos}%)`;
69
- case "top":
70
- return `translateY(-${snapPos}%)`;
71
- case "left":
72
- return `translateX(-${snapPos}%)`;
73
- case "right":
74
- return `translateX(${snapPos}%)`;
75
- }
76
- }
77
-
78
57
  switch (drawer.direction) {
79
58
  case "bottom":
80
59
  return `translateY(${pos}%)`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abhivarde/svelte-drawer",
3
- "version": "0.0.19",
3
+ "version": "0.0.20",
4
4
  "description": "A drawer component for Svelte 5, inspired by Vaul",
5
5
  "author": "Abhi Varde",
6
6
  "license": "MIT",