well-petal 0.0.4 → 0.0.5

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/.prettierrc CHANGED
@@ -1,4 +1,5 @@
1
1
  {
2
2
  "tabWidth": 2,
3
- "useTabs": false
3
+ "useTabs": false,
4
+ "printWidth": 200
4
5
  }
package/dist/petal.js CHANGED
@@ -56,7 +56,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac
56
56
  \**********************/
57
57
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
58
58
 
59
- eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var gsap__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! gsap */ \"./node_modules/gsap/index.js\");\n\nconst validAnimations = [\n \"scale\",\n \"slide-up\",\n \"slide-down\",\n \"slide-left\",\n \"slide-right\",\n];\n// Initialize popup triggers\ndocument\n .querySelectorAll(\"[petal-el='trigger'], [petal-el='mask']\")\n .forEach((trigger) => {\n const popupName = trigger.getAttribute(\"petal\");\n if (!popupName) {\n logError(\"NO_NAME\", \"\", trigger);\n return;\n }\n const popup = document.querySelector(`[petal='${popupName}'][petal-el='popup']`);\n if (!popup) {\n logError(\"NO_POPUP\", popupName, trigger);\n return;\n }\n // Popup Elements\n const mask = popup.querySelector(\"[petal-el='mask']\");\n const slot = popup.querySelector(\"[petal-el='slot']\");\n // Popup Settings\n const animation = getPopupAnimation(popup.getAttribute(\"petal-el\"));\n const animationMobile = getPopupAnimation(popup.getAttribute(\"petal-anim-mobile\")) || animation;\n const duration = parseFloat(popup.getAttribute(\"petal-duration\") || \"1\");\n // Initialize GSAP timeline\n const tl = gsap__WEBPACK_IMPORTED_MODULE_0__[\"default\"].timeline();\n trigger.addEventListener(\"click\", () => animate(popup));\n // Animate open/close\n function animate(popup) {\n // Check if the popup is open or closed\n const open = popup.style.display !== \"none\" ||\n getComputedStyle(popup).display !== \"none\";\n // If the popup is closed, open it\n if (!open)\n tl.set(popup, { display: \"flex\" });\n // Animate the mask\n if (mask) {\n const maskAnim = open ? animateMaskOpen() : animateMaskClosed();\n tl.fromTo(mask, maskAnim.from, maskAnim.to, \"<\");\n }\n // Animate the popup\n if (slot) {\n const anim = isMobile()\n ? getAnimation(animationMobile, open)\n : getAnimation(animation, open);\n anim.to.duration = duration;\n tl.fromTo(slot, anim.from, anim.to);\n }\n else {\n console.warn(\"A slot was not found for this popup.\");\n }\n // If the popup is open, hide it\n if (open) {\n // Pause all <video> elements inside the popup before hiding it\n popup.querySelectorAll(\"video\").forEach((video) => {\n if (!video.paused)\n video.pause();\n });\n tl.set(popup, { display: \"none\" });\n }\n }\n});\n// Reusable mask animations\nfunction animateMaskOpen() {\n return {\n from: { opacity: 0 },\n to: { opacity: 0.15, duration: 0.5 },\n };\n}\nfunction animateMaskClosed() {\n return {\n from: { opacity: 0.15 },\n to: { opacity: 0, duration: 0.5 },\n };\n}\n// Animation selection\nfunction getAnimation(animation, reversed) {\n var _a;\n const map = {\n scale: [animateScaleDown, animateScaleUp],\n \"slide-up\": [animateSlideDown, animateSlideUp],\n \"slide-down\": [animateSlideUp, animateSlideDown],\n \"slide-left\": [animateSlideRight, animateSlideLeft],\n \"slide-right\": [animateSlideLeft, animateSlideRight],\n };\n const [normal, reverse] = (_a = map[animation]) !== null && _a !== void 0 ? _a : [\n animateScaleDown,\n animateScaleUp,\n ];\n return reversed ? reverse() : normal();\n}\n// Individual animations\nfunction animateScaleUp() {\n return {\n from: { scale: 0 },\n to: { scale: 1, opacity: 1, ease: \"power3.inOut\" },\n };\n}\nfunction animateScaleDown() {\n return {\n from: { scale: 1 },\n to: { scale: 0, opacity: 0, ease: \"power3.inOut\" },\n };\n}\nfunction animateSlideUp() {\n return {\n from: { y: \"100%\", x: \"0%\" },\n to: { y: \"0%\", opacity: 1, ease: \"power3.inOut\" },\n };\n}\nfunction animateSlideDown() {\n return {\n from: { y: \"0%\", x: \"0%\" },\n to: { y: \"100%\", opacity: 1, ease: \"power3.inOut\" },\n };\n}\nfunction animateSlideRight() {\n return {\n from: { x: \"0%\", y: \"0%\" },\n to: { x: \"100%\", opacity: 1, ease: \"power3.inOut\" },\n };\n}\nfunction animateSlideLeft() {\n return {\n from: { x: \"100%\", y: \"0%\" },\n to: { x: \"0%\", opacity: 1, ease: \"power3.inOut\" },\n };\n}\n// Device check\nfunction isMobile() {\n return window.innerWidth <= 768;\n}\n// Validate popup animation string\nfunction isPopupAnimation(value) {\n return validAnimations.includes(value);\n}\n// Safe parser with fallback\nfunction getPopupAnimation(raw) {\n return isPopupAnimation(raw !== null && raw !== void 0 ? raw : \"\") ? raw : \"slide-up\";\n}\n// Centralized error logging\nfunction logError(error, popupName, trigger) {\n switch (error) {\n case \"NO_NAME\":\n console.error(`Trigger is missing the \"petal\" attribute:`, trigger);\n break;\n case \"NO_POPUP\":\n console.error(`Popup with name \"${popupName}\" not found for trigger:`, trigger);\n break;\n default:\n console.error(`Popup error [${error}] for \"${popupName}\":`, trigger);\n }\n}\n\n\n//# sourceURL=webpack://petal/./src/petal.ts?");
59
+ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var gsap__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! gsap */ \"./node_modules/gsap/index.js\");\n\nconst validAnimations = [\"scale\", \"slide-up\", \"slide-down\", \"slide-left\", \"slide-right\"];\n// Initialize popup triggers\ndocument.querySelectorAll(\"[petal-el='trigger'], [petal-el='mask']\").forEach((trigger) => {\n const popupName = trigger.getAttribute(\"petal\");\n if (!popupName) {\n logError(\"NO_NAME\", \"\", trigger);\n return;\n }\n const popup = document.querySelector(`[petal='${popupName}'][petal-el='popup']`);\n if (!popup) {\n logError(\"NO_POPUP\", popupName, trigger);\n return;\n }\n // Popup Elements\n const mask = popup.querySelector(\"[petal-el='mask']\");\n const slot = popup.querySelector(\"[petal-el='slot']\");\n // Mask Settings\n const maskOpacity = parseFloat((mask === null || mask === void 0 ? void 0 : mask.getAttribute(\"petal-mask-opacity\")) || \"0.15\");\n // Popup Settings\n const animation = getPopupAnimation(popup.getAttribute(\"petal-el\"));\n const animationMobile = getPopupAnimation(popup.getAttribute(\"petal-anim-mobile\")) || animation;\n const duration = parseFloat(popup.getAttribute(\"petal-duration\") || \"1\");\n // Initialize GSAP timeline\n const tl = gsap__WEBPACK_IMPORTED_MODULE_0__[\"default\"].timeline();\n trigger.addEventListener(\"click\", () => animate(popup));\n // Animate open/close\n function animate(popup) {\n // Check if the popup is open or closed\n const open = popup.style.display !== \"none\" || getComputedStyle(popup).display !== \"none\";\n // If the popup is closed, open it\n if (!open)\n tl.set(popup, { display: \"flex\" });\n // Animate the mask\n if (mask) {\n const maskAnim = open ? animateMaskClosed(maskOpacity) : animateMaskOpen(maskOpacity);\n tl.fromTo(mask, maskAnim.from, maskAnim.to, \"<\");\n }\n // Animate the popup\n if (slot) {\n const anim = isMobile() ? getAnimation(animationMobile, open) : getAnimation(animation, open);\n anim.to.duration = duration;\n tl.fromTo(slot, anim.from, anim.to);\n }\n else {\n console.warn(\"A slot was not found for this popup.\");\n }\n // If the popup is open, hide it\n if (open) {\n // Pause all <video> elements inside the popup before hiding it\n popup.querySelectorAll(\"video\").forEach((video) => {\n if (!video.paused)\n video.pause();\n });\n tl.set(popup, { display: \"none\" });\n }\n }\n});\n// Reusable mask animations\nfunction animateMaskOpen(opacity) {\n return {\n from: { opacity: 0 },\n to: { opacity: opacity, duration: 0.5 },\n };\n}\nfunction animateMaskClosed(opacity) {\n return {\n from: { opacity: opacity },\n to: { opacity: 0, duration: 0.5 },\n };\n}\n// Animation selection\nfunction getAnimation(animation, reversed) {\n var _a;\n const map = {\n scale: [animateScaleDown, animateScaleUp],\n \"slide-up\": [animateSlideDown, animateSlideUp],\n \"slide-down\": [animateSlideUp, animateSlideDown],\n \"slide-left\": [animateSlideRight, animateSlideLeft],\n \"slide-right\": [animateSlideLeft, animateSlideRight],\n };\n const [normal, reverse] = (_a = map[animation]) !== null && _a !== void 0 ? _a : [animateScaleDown, animateScaleUp];\n return reversed ? reverse() : normal();\n}\n// Individual animations\nfunction animateScaleUp() {\n return {\n from: { scale: 0 },\n to: { scale: 1, opacity: 1, ease: \"power3.inOut\" },\n };\n}\nfunction animateScaleDown() {\n return {\n from: { scale: 1 },\n to: { scale: 0, opacity: 0, ease: \"power3.inOut\" },\n };\n}\nfunction animateSlideUp() {\n return {\n from: { y: \"100%\", x: \"0%\" },\n to: { y: \"0%\", opacity: 1, ease: \"power3.inOut\" },\n };\n}\nfunction animateSlideDown() {\n return {\n from: { y: \"0%\", x: \"0%\" },\n to: { y: \"100%\", opacity: 1, ease: \"power3.inOut\" },\n };\n}\nfunction animateSlideRight() {\n return {\n from: { x: \"0%\", y: \"0%\" },\n to: { x: \"100%\", opacity: 1, ease: \"power3.inOut\" },\n };\n}\nfunction animateSlideLeft() {\n return {\n from: { x: \"100%\", y: \"0%\" },\n to: { x: \"0%\", opacity: 1, ease: \"power3.inOut\" },\n };\n}\n// Device check\nfunction isMobile() {\n return window.innerWidth <= 768;\n}\n// Validate popup animation string\nfunction isPopupAnimation(value) {\n return validAnimations.includes(value);\n}\n// Safe parser with fallback\nfunction getPopupAnimation(raw) {\n return isPopupAnimation(raw !== null && raw !== void 0 ? raw : \"\") ? raw : \"slide-up\";\n}\n// Centralized error logging\nfunction logError(error, popupName, trigger) {\n switch (error) {\n case \"NO_NAME\":\n console.error(`Trigger is missing the \"petal\" attribute:`, trigger);\n break;\n case \"NO_POPUP\":\n console.error(`Popup with name \"${popupName}\" not found for trigger:`, trigger);\n break;\n default:\n console.error(`Popup error [${error}] for \"${popupName}\":`, trigger);\n }\n}\n\n\n//# sourceURL=webpack://petal/./src/petal.ts?");
60
60
 
61
61
  /***/ })
62
62
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "well-petal",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "Webflow Popups powered by attributes",
5
5
  "main": "petal.js",
6
6
  "scripts": {
package/src/petal.ts CHANGED
@@ -1,125 +1,97 @@
1
1
  import gsap from "gsap";
2
2
 
3
3
  // Popup animation types
4
- export type PopupAnimation =
5
- | "scale"
6
- | "slide-up"
7
- | "slide-down"
8
- | "slide-left"
9
- | "slide-right";
10
-
11
- const validAnimations: PopupAnimation[] = [
12
- "scale",
13
- "slide-up",
14
- "slide-down",
15
- "slide-left",
16
- "slide-right",
17
- ];
4
+ export type PopupAnimation = "scale" | "slide-up" | "slide-down" | "slide-left" | "slide-right";
5
+
6
+ const validAnimations: PopupAnimation[] = ["scale", "slide-up", "slide-down", "slide-left", "slide-right"];
18
7
 
19
8
  // Error types for debug logging
20
- export type ErrorType =
21
- | "NO_NAME"
22
- | "NO_TRIGGER"
23
- | "NO_POPUP"
24
- | "NO_MASK"
25
- | "NO_SLOT";
9
+ export type ErrorType = "NO_NAME" | "NO_TRIGGER" | "NO_POPUP" | "NO_MASK" | "NO_SLOT";
26
10
 
27
11
  // Initialize popup triggers
28
- document
29
- .querySelectorAll("[petal-el='trigger'], [petal-el='mask']")
30
- .forEach((trigger) => {
31
- const popupName = trigger.getAttribute("petal");
32
- if (!popupName) {
33
- logError("NO_NAME", "", trigger);
34
- return;
12
+ document.querySelectorAll("[petal-el='trigger'], [petal-el='mask']").forEach((trigger) => {
13
+ const popupName = trigger.getAttribute("petal");
14
+ if (!popupName) {
15
+ logError("NO_NAME", "", trigger);
16
+ return;
17
+ }
18
+
19
+ const popup = document.querySelector(`[petal='${popupName}'][petal-el='popup']`) as HTMLElement | null;
20
+ if (!popup) {
21
+ logError("NO_POPUP", popupName, trigger);
22
+ return;
23
+ }
24
+
25
+ // Popup Elements
26
+ const mask = popup.querySelector("[petal-el='mask']");
27
+ const slot = popup.querySelector("[petal-el='slot']");
28
+
29
+ // Mask Settings
30
+ const maskOpacity = parseFloat(mask?.getAttribute("petal-mask-opacity") || "0.15");
31
+
32
+ // Popup Settings
33
+ const animation = getPopupAnimation(popup.getAttribute("petal-el"));
34
+ const animationMobile = getPopupAnimation(popup.getAttribute("petal-anim-mobile")) || animation;
35
+ const duration = parseFloat(popup.getAttribute("petal-duration") || "1");
36
+
37
+ // Initialize GSAP timeline
38
+ const tl = gsap.timeline();
39
+
40
+ trigger.addEventListener("click", () => animate(popup));
41
+
42
+ // Animate open/close
43
+ function animate(popup: HTMLElement): void {
44
+ // Check if the popup is open or closed
45
+ const open = popup.style.display !== "none" || getComputedStyle(popup).display !== "none";
46
+
47
+ // If the popup is closed, open it
48
+ if (!open) tl.set(popup, { display: "flex" });
49
+
50
+ // Animate the mask
51
+ if (mask) {
52
+ const maskAnim = open ? animateMaskClosed(maskOpacity) : animateMaskOpen(maskOpacity);
53
+ tl.fromTo(mask, maskAnim.from, maskAnim.to, "<");
35
54
  }
36
55
 
37
- const popup = document.querySelector(
38
- `[petal='${popupName}'][petal-el='popup']`,
39
- ) as HTMLElement | null;
40
- if (!popup) {
41
- logError("NO_POPUP", popupName, trigger);
42
- return;
56
+ // Animate the popup
57
+ if (slot) {
58
+ const anim = isMobile() ? getAnimation(animationMobile, open) : getAnimation(animation, open);
59
+ anim.to.duration = duration;
60
+ tl.fromTo(slot, anim.from, anim.to);
61
+ } else {
62
+ console.warn("A slot was not found for this popup.");
43
63
  }
44
64
 
45
- // Popup Elements
46
- const mask = popup.querySelector("[petal-el='mask']");
47
- const slot = popup.querySelector("[petal-el='slot']");
48
-
49
- // Popup Settings
50
- const animation = getPopupAnimation(popup.getAttribute("petal-el"));
51
- const animationMobile =
52
- getPopupAnimation(popup.getAttribute("petal-anim-mobile")) || animation;
53
- const duration = parseFloat(popup.getAttribute("petal-duration") || "1");
54
-
55
- // Initialize GSAP timeline
56
- const tl = gsap.timeline();
57
-
58
- trigger.addEventListener("click", () => animate(popup));
59
-
60
- // Animate open/close
61
- function animate(popup: HTMLElement): void {
62
- // Check if the popup is open or closed
63
- const open =
64
- popup.style.display !== "none" ||
65
- getComputedStyle(popup).display !== "none";
66
-
67
- // If the popup is closed, open it
68
- if (!open) tl.set(popup, { display: "flex" });
69
-
70
- // Animate the mask
71
- if (mask) {
72
- const maskAnim = open ? animateMaskOpen() : animateMaskClosed();
73
- tl.fromTo(mask, maskAnim.from, maskAnim.to, "<");
74
- }
75
-
76
- // Animate the popup
77
- if (slot) {
78
- const anim = isMobile()
79
- ? getAnimation(animationMobile, open)
80
- : getAnimation(animation, open);
81
- anim.to.duration = duration;
82
- tl.fromTo(slot, anim.from, anim.to);
83
- } else {
84
- console.warn("A slot was not found for this popup.");
85
- }
86
-
87
- // If the popup is open, hide it
88
- if (open) {
89
- // Pause all <video> elements inside the popup before hiding it
90
- popup.querySelectorAll("video").forEach((video) => {
91
- if (!video.paused) video.pause();
92
- });
93
-
94
- tl.set(popup, { display: "none" });
95
- }
65
+ // If the popup is open, hide it
66
+ if (open) {
67
+ // Pause all <video> elements inside the popup before hiding it
68
+ popup.querySelectorAll("video").forEach((video) => {
69
+ if (!video.paused) video.pause();
70
+ });
71
+
72
+ tl.set(popup, { display: "none" });
96
73
  }
97
- });
74
+ }
75
+ });
98
76
 
99
77
  // Reusable mask animations
100
- function animateMaskOpen(): GSAPTweenVars {
78
+ function animateMaskOpen(opacity: number): GSAPTweenVars {
101
79
  return {
102
80
  from: { opacity: 0 },
103
- to: { opacity: 0.15, duration: 0.5 },
81
+ to: { opacity: opacity, duration: 0.5 },
104
82
  };
105
83
  }
106
84
 
107
- function animateMaskClosed(): GSAPTweenVars {
85
+ function animateMaskClosed(opacity: number): GSAPTweenVars {
108
86
  return {
109
- from: { opacity: 0.15 },
87
+ from: { opacity: opacity },
110
88
  to: { opacity: 0, duration: 0.5 },
111
89
  };
112
90
  }
113
91
 
114
92
  // Animation selection
115
- function getAnimation(
116
- animation: PopupAnimation,
117
- reversed: boolean,
118
- ): GSAPTweenVars {
119
- const map: Record<
120
- PopupAnimation,
121
- [() => GSAPTweenVars, () => GSAPTweenVars]
122
- > = {
93
+ function getAnimation(animation: PopupAnimation, reversed: boolean): GSAPTweenVars {
94
+ const map: Record<PopupAnimation, [() => GSAPTweenVars, () => GSAPTweenVars]> = {
123
95
  scale: [animateScaleDown, animateScaleUp],
124
96
  "slide-up": [animateSlideDown, animateSlideUp],
125
97
  "slide-down": [animateSlideUp, animateSlideDown],
@@ -127,10 +99,7 @@ function getAnimation(
127
99
  "slide-right": [animateSlideLeft, animateSlideRight],
128
100
  };
129
101
 
130
- const [normal, reverse] = map[animation] ?? [
131
- animateScaleDown,
132
- animateScaleUp,
133
- ];
102
+ const [normal, reverse] = map[animation] ?? [animateScaleDown, animateScaleUp];
134
103
  return reversed ? reverse() : normal();
135
104
  }
136
105
 
@@ -199,10 +168,7 @@ function logError(error: ErrorType, popupName: string, trigger: Element): void {
199
168
  console.error(`Trigger is missing the "petal" attribute:`, trigger);
200
169
  break;
201
170
  case "NO_POPUP":
202
- console.error(
203
- `Popup with name "${popupName}" not found for trigger:`,
204
- trigger,
205
- );
171
+ console.error(`Popup with name "${popupName}" not found for trigger:`, trigger);
206
172
  break;
207
173
  default:
208
174
  console.error(`Popup error [${error}] for "${popupName}":`, trigger);