well-petal 0.0.3 → 0.0.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.
- package/dist/petal.js +1 -1
- package/package.json +1 -1
- package/src/petal.ts +17 -4
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 const open = popup.style.display
|
|
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?");
|
|
60
60
|
|
|
61
61
|
/***/ })
|
|
62
62
|
|
package/package.json
CHANGED
package/src/petal.ts
CHANGED
|
@@ -59,16 +59,21 @@ document
|
|
|
59
59
|
|
|
60
60
|
// Animate open/close
|
|
61
61
|
function animate(popup: HTMLElement): void {
|
|
62
|
+
// Check if the popup is open or closed
|
|
62
63
|
const open =
|
|
63
|
-
popup.style.display
|
|
64
|
-
getComputedStyle(popup).display
|
|
65
|
-
if (open) tl.set(popup, { display: "flex" });
|
|
64
|
+
popup.style.display !== "none" ||
|
|
65
|
+
getComputedStyle(popup).display !== "none";
|
|
66
66
|
|
|
67
|
+
// If the popup is closed, open it
|
|
68
|
+
if (!open) tl.set(popup, { display: "flex" });
|
|
69
|
+
|
|
70
|
+
// Animate the mask
|
|
67
71
|
if (mask) {
|
|
68
72
|
const maskAnim = open ? animateMaskOpen() : animateMaskClosed();
|
|
69
73
|
tl.fromTo(mask, maskAnim.from, maskAnim.to, "<");
|
|
70
74
|
}
|
|
71
75
|
|
|
76
|
+
// Animate the popup
|
|
72
77
|
if (slot) {
|
|
73
78
|
const anim = isMobile()
|
|
74
79
|
? getAnimation(animationMobile, open)
|
|
@@ -79,7 +84,15 @@ document
|
|
|
79
84
|
console.warn("A slot was not found for this popup.");
|
|
80
85
|
}
|
|
81
86
|
|
|
82
|
-
|
|
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
|
+
}
|
|
83
96
|
}
|
|
84
97
|
});
|
|
85
98
|
|