UNPKG

alpinejs-flux

Version:

Simplifies the process of applying CSS classes with x-transition as a template and makes them reusable within single attribute.

2 lines (1 loc) 1.24 kB
function l(o){let[t,n,r,i="",e=""]=o,s=`${t} ${i}`.trim(),a=`${t} ${e}`.trim();return{"x-transition:enter":s,"x-transition:enter-start":n,"x-transition:enter-end":r,"x-transition:leave":a,"x-transition:leave-start":r,"x-transition:leave-end":n}}function x(o){let t={};for(let n in o){let r=o[n];t[`x-transition:${n}`]=r}return t}function p(o,t=null){if(!t)throw new Error("x-flux: Template "+o+" does not exist in the config.");try{return Array.isArray(t)?l(t):x(t)}catch{throw new Error("x-flux: Only accept array or object.")}}function c(o,t,n){let r=p(t,n);if(!r)throw new Error("x-flux: No transitions found for "+t);for(let i in r){let e=r[i];o.setAttribute(i,e)}o.removeAttribute("x-flux")}function u(o,t,n,r=null){o.magic(t,i=>()=>{c(i,n,r)})}function f(o){let t=o.split("-");if(t.length===1)return o;let n=t.slice(1).map(r=>r.charAt(0).toUpperCase()+r.slice(1));return t[0]+n.join("")}function d(o,t){o.directive("flux",(n,{expression:r},{evaluate:i})=>{let e=i(r),s=Array.isArray(e)?"":e,a=s?t[s]:e;c(n,s,a)}).before("transition");for(let n in t){let r=f(n),i=t[n]||null;u(o,r,n,i)}o.magic("flux",n=>(r="",i=null,e=!0)=>{if(i){let a=f(r);t[r]=i,u(o,a,r,i)}if(!e)return;let s=t[r]||null;c(n,r,s)})}var M=d;export{M as default};