@vkm-js/animate
Version:
An Alpinejs to animate things with Intersection Observer.
70 lines (66 loc) • 2.41 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// packages/animate/builds/module.js
var module_exports = {};
__export(module_exports, {
animate: () => src_default,
default: () => module_default
});
module.exports = __toCommonJS(module_exports);
// packages/animate/src/index.js
function src_default(Alpine) {
Alpine.directive("animate", (el, { value, modifiers }) => {
const animationTypes = ["fade", "zoom", "up", "down"];
const type = modifiers.find((mod) => animationTypes.includes(mod)) || "fade";
const modifierDuration = modifiers.find((mod) => /^\d+$/.test(mod));
const duration = modifierDuration || value || "1000";
el.style.transition = `all ${duration}ms ease`;
switch (type) {
case "fade":
el.style.opacity = 0;
break;
case "up":
el.style.opacity = 0;
el.style.transform = "translateY(20px)";
break;
case "down":
el.style.opacity = 0;
el.style.transform = "translateY(-50px)";
break;
case "zoom":
el.style.opacity = 0;
el.style.transform = "scale(0.8)";
break;
}
const observer = new IntersectionObserver(([entry]) => {
if (entry.isIntersecting) {
el.style.opacity = 1;
if (type === "up" || type === "down") el.style.transform = "translateY(0)";
if (type === "zoom") el.style.transform = "scale(1)";
observer.unobserve(el);
}
}, { threshold: 0.1 });
observer.observe(el);
});
}
// packages/animate/builds/module.js
var module_default = src_default;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
animate
});