Current section

Files

Jump to
live_motion priv static live_motion.min.js
Raw

priv/static/live_motion.min.js

var LiveMotion=(()=>{var at=Object.defineProperty,Ht=Object.defineProperties;var Qt=Object.getOwnPropertyDescriptors;var W=Object.getOwnPropertySymbols;var At=Object.prototype.hasOwnProperty,St=Object.prototype.propertyIsEnumerable;var wt=(t,e,s)=>e in t?at(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s,Mt=(t,e)=>{for(var s in e||(e={}))At.call(e,s)&&wt(t,s,e[s]);if(W)for(var s of W(e))St.call(e,s)&&wt(t,s,e[s]);return t},Ot=(t,e)=>Ht(t,Qt(e)),Yt=t=>at(t,"__esModule",{value:!0});var Et=(t,e)=>{var s={};for(var n in t)At.call(t,n)&&e.indexOf(n)<0&&(s[n]=t[n]);if(t!=null&&W)for(var n of W(t))e.indexOf(n)<0&&St.call(t,n)&&(s[n]=t[n]);return s};var te=(t,e)=>{Yt(t);for(var s in e)at(t,s,{get:e[s],enumerable:!0})};var Oe={};te(Oe,{createLiveMotion:()=>Me});var J=class{setAnimation(e){this.animation=e,e==null||e.finished.then(()=>this.clearAnimation()).catch(()=>{})}clearAnimation(){this.animation=this.generator=void 0}};var ct=new WeakMap;function X(t){return ct.has(t)||ct.set(t,{transforms:[],values:new Map}),ct.get(t)}function Dt(t,e){return t.has(e)||t.set(e,new J),t.get(e)}function lt(t,e){t.indexOf(e)===-1&&t.push(e)}var mt=(t,e,s)=>Math.min(Math.max(s,t),e);var x={duration:.3,delay:0,endDelay:0,repeat:0,easing:"ease"};var k=t=>typeof t=="number";var I=t=>typeof t=="object"&&Boolean(t.createAnimation),ft=t=>Array.isArray(t)&&k(t[0]),E=t=>Array.isArray(t)&&!k(t[0]);var N=(t,e,s)=>-s*t+s*e+t;var L=()=>{},S=t=>t;var V=(t,e,s)=>e-t==0?1:(s-t)/(e-t);function Z(t,e){let s=t[t.length-1];for(let n=1;n<=e;n++){let i=V(0,e,n);t.push(N(s,1,i))}}function ut(t){let e=[0];return Z(e,t-1),e}var w={ms:t=>t*1e3,s:t=>t/1e3};function pt(t,e){return e?t*(1e3/e):0}var dt=(t,e,s)=>{let n=e-t;return((s-t)%n+n)%n+t};var ee=["","X","Y","Z"],se=["translate","scale","rotate","skew"],q={x:"translateX",y:"translateY",z:"translateZ"},Rt={syntax:"<angle>",initialValue:"0deg",toDefaultUnit:t=>t+"deg"},ne={translate:{syntax:"<length-percentage>",initialValue:"0px",toDefaultUnit:t=>t+"px"},rotate:Rt,scale:{syntax:"<number>",initialValue:1,toDefaultUnit:S},skew:Rt},D=new Map,H=t=>`--motion-${t}`,Q=["x","y","z"];se.forEach(t=>{ee.forEach(e=>{Q.push(t+e),D.set(H(t+e),ne[t])})});var ie=(t,e)=>Q.indexOf(t)-Q.indexOf(e),oe=new Set(Q),Y=t=>oe.has(t),_t=(t,e)=>{q[e]&&(e=q[e]);let{transforms:s}=X(t);lt(s,e),t.style.transform=re(s)},re=t=>t.sort(ie).reduce(ae,"").trim(),ae=(t,e)=>`${t} ${e}(var(${H(e)}))`;var G=t=>t.startsWith("--"),kt=new Set;function Ft(t){if(!kt.has(t)){kt.add(t);try{let{syntax:e,initialValue:s}=D.has(t)?D.get(t):{};CSS.registerProperty({name:t,inherits:!1,syntax:e,initialValue:s})}catch(e){}}}var It=(t,e,s)=>(((1-3*s+3*e)*t+(3*s-6*e))*t+3*e)*t,ce=1e-7,le=12;function me(t,e,s,n,i){let o,r,a=0;do r=e+(s-e)/2,o=It(r,n,i)-t,o>0?s=r:e=r;while(Math.abs(o)>ce&&++a<le);return r}function F(t,e,s,n){if(t===e&&s===n)return S;let i=o=>me(o,0,1,t,s);return o=>o===0||o===1?o:It(i(o),e,n)}var gt=(t,e="end")=>s=>{s=e==="end"?Math.min(s,.999):Math.max(s,.001);let n=s*t,i=e==="end"?Math.floor(n):Math.ceil(n);return mt(0,1,i/t)};var Pt={ease:F(.25,.1,.25,1),"ease-in":F(.42,0,1,1),"ease-in-out":F(.42,0,.58,1),"ease-out":F(0,0,.58,1)},fe=/\((.*?)\)/;function ht(t){if(typeof t=="function")return t;if(Array.isArray(t))return F(...t);if(Pt[t])return Pt[t];if(t.startsWith("steps")){let e=fe.exec(t);if(e){let s=e[1].split(",");return gt(parseFloat(s[0]),s[1].trim())}}return S}function Ct(t,e){return E(t)?t[dt(0,t.length,e)]:t}var ue=t=>Math.min(1,Math.max(t,0));function Nt(t,e=ut(t.length),s=S){let n=t.length,i=n-e.length;return i>0&&Z(e,i),o=>{let r=0;for(;r<n-2&&!(o<e[r+1]);r++);let a=ue(V(e[r],e[r+1],o));return a=Ct(s,r)(a),N(t[r],t[r+1],a)}}var P=class{constructor(e,s=[0,1],{easing:n=x.easing,duration:i=x.duration,delay:o=x.delay,endDelay:r=x.endDelay,repeat:a=x.repeat,offset:c,direction:g="normal"}={}){if(this.startTime=null,this.rate=1,this.t=0,this.cancelTimestamp=null,this.playState="idle",this.finished=new Promise((d,f)=>{this.resolve=d,this.reject=f}),I(n)){let d=n.createAnimation(s,()=>"0",!0);n=d.easing,d.keyframes!==void 0&&(s=d.keyframes),d.duration!==void 0&&(i=d.duration)}let l=i*(a+1),u=Nt(s,c,E(n)?n.map(ht):ht(n));this.tick=d=>{var f;this.pauseTime&&(d=this.pauseTime);let p=(d-this.startTime)*this.rate;this.t=p,p/=1e3,p=Math.max(p-o,0),this.playState==="finished"&&(p=l);let M=p/i,T=Math.floor(M),j=M%1;!j&&M>=1&&(j=1),j===1&&T--;let y=T%2;(g==="reverse"||g==="alternate"&&y||g==="alternate-reverse"&&!y)&&(j=1-j);let b=u(p>=l?1:Math.min(j,1));e(b),this.playState==="finished"||p>=l+r?(this.playState="finished",(f=this.resolve)===null||f===void 0||f.call(this,b)):this.playState!=="idle"&&(this.frameRequestId=requestAnimationFrame(this.tick))},this.play()}play(){var e;let s=performance.now();this.playState="running",this.pauseTime?this.startTime=s-(this.pauseTime-((e=this.startTime)!==null&&e!==void 0?e:0)):this.startTime||(this.startTime=s),this.cancelTimestamp=this.startTime,this.pauseTime=void 0,requestAnimationFrame(this.tick)}pause(){this.playState="paused",this.pauseTime=performance.now()}finish(){this.playState="finished",this.tick(0)}stop(){var e;this.playState="idle",this.frameRequestId!==void 0&&cancelAnimationFrame(this.frameRequestId),(e=this.reject)===null||e===void 0||e.call(this,!1)}cancel(){this.stop(),this.tick(this.cancelTimestamp)}reverse(){this.rate*=-1}commitStyles(){}get currentTime(){return this.t}set currentTime(e){this.pauseTime||this.rate===0?this.pauseTime=e:this.startTime=performance.now()-e/this.rate}get playbackRate(){return this.rate}set playbackRate(e){this.rate=e}};var yt=t=>ft(t)?pe(t):t,pe=([t,e,s,n])=>`cubic-bezier(${t}, ${e}, ${s}, ${n})`;var Lt=t=>document.createElement("div").animate(t,{duration:.001}),Vt={cssRegisterProperty:()=>typeof CSS!="undefined"&&Object.hasOwnProperty.call(CSS,"registerProperty"),waapi:()=>Object.hasOwnProperty.call(Element.prototype,"animate"),partialKeyframes:()=>{try{Lt({opacity:[1]})}catch(t){return!1}return!0},finished:()=>Boolean(Lt({opacity:[0,1]}).finished)},xt={},U={};for(let t in Vt)U[t]=()=>(xt[t]===void 0&&(xt[t]=Vt[t]()),xt[t]);function qt(t,e){for(let s=0;s<t.length;s++)t[s]===null&&(t[s]=s?t[s-1]:e());return t}var Gt=t=>Array.isArray(t)?t:[t];function $(t){return q[t]&&(t=q[t]),Y(t)?H(t):t}var C={get:(t,e)=>{e=$(e);let s=G(e)?t.style.getPropertyValue(e):getComputedStyle(t)[e];if(!s&&s!==0){let n=D.get(e);n&&(s=n.initialValue)}return s},set:(t,e,s)=>{e=$(e),G(e)?t.style.setProperty(e,s):t.style[e]=s}};function tt(t,e=!0){if(!(!t||t.playState==="finished"))try{t.stop?t.stop():(e&&t.commitStyles(),t.cancel())}catch(s){}}function de(){return window.__MOTION_DEV_TOOLS_RECORD}function Ut(t,e,s,n={}){let i=de(),o=n.record!==!1&&i,r,{duration:a=x.duration,delay:c=x.delay,endDelay:g=x.endDelay,repeat:l=x.repeat,easing:u=x.easing,direction:d,offset:f,allowWebkitAcceleration:p=!1}=n,M=X(t),T=U.waapi(),j=Y(e);j&&_t(t,e);let y=$(e),b=Dt(M.values,y),v=D.get(y);return tt(b.animation,!(I(u)&&b.generator)&&n.record!==!1),()=>{let _=()=>{var m,A;return(A=(m=C.get(t,y))!==null&&m!==void 0?m:v==null?void 0:v.initialValue)!==null&&A!==void 0?A:0},h=qt(Gt(s),_);if(I(u)){let m=u.createAnimation(h,_,j,y,b);u=m.easing,m.keyframes!==void 0&&(h=m.keyframes),m.duration!==void 0&&(a=m.duration)}if(G(y)&&(U.cssRegisterProperty()?Ft(y):T=!1),T){v&&(h=h.map(O=>k(O)?v.toDefaultUnit(O):O));let m=!U.partialKeyframes()&&h.length===1;(o||m)&&h.unshift(_());let A={delay:w.ms(c),duration:w.ms(a),endDelay:w.ms(g),easing:E(u)?void 0:yt(u),direction:d,iterations:l+1,fill:"both"};r=t.animate({[y]:h,offset:f,easing:E(u)?u.map(yt):void 0},A),r.finished||(r.finished=new Promise((O,K)=>{r.onfinish=O,r.oncancel=K}));let rt=h[h.length-1];r.finished.then(()=>{C.set(t,y,rt),r.cancel()}).catch(L),p||(r.playbackRate=1.000001)}else if(j&&h.every(k)){h.length===1&&h.unshift(parseFloat(_()));let m=A=>{v&&(A=v.toDefaultUnit(A)),C.set(t,y,A)};r=new P(m,h,Object.assign(Object.assign({},n),{duration:a,easing:u}))}else{let m=h[h.length-1];C.set(t,y,v&&k(m)?v.toDefaultUnit(m):m)}return o&&i(t,e,h,{duration:a,delay:c,easing:u,repeat:l,offset:f},"motion-one"),b.setAnimation(r),r}}var $t=(t,e)=>t[e]?Object.assign(Object.assign({},t),t[e]):Object.assign({},t);function zt(t,e){var s;return typeof t=="string"?e?((s=e[t])!==null&&s!==void 0||(e[t]=document.querySelectorAll(t)),t=e[t]):t=document.querySelectorAll(t):t instanceof Element&&(t=[t]),Array.from(t)}var ge=t=>t(),z=(t,e=x.duration)=>new Proxy({animations:t.map(ge).filter(Boolean),duration:e},he),Bt=t=>t.animations[0],he={get:(t,e)=>{var s,n;switch(e){case"duration":return t.duration;case"currentTime":let i=((s=Bt(t))===null||s===void 0?void 0:s[e])||0;return i?i/1e3:0;case"playbackRate":return(n=Bt(t))===null||n===void 0?void 0:n[e];case"finished":return t.finished||(t.finished=Promise.all(t.animations.map(ye)).catch(L)),t.finished;case"stop":return()=>t.animations.forEach(o=>tt(o));default:return()=>t.animations.forEach(o=>o[e]())}},set:(t,e,s)=>{switch(e){case"currentTime":s=w.ms(s);case"currentTime":case"playbackRate":for(let n=0;n<t.animations.length;n++)t.animations[n][e]=s;return!0}return!1}},ye=t=>t.finished;function Kt(t,e,s){return typeof t=="function"?t(e,s):t}function vt(t,e,s={}){t=zt(t);let n=t.length,i=[];for(let o=0;o<n;o++){let r=t[o];for(let a in e){let c=$t(s,a);c.delay=Kt(c.delay,o,n);let g=Ut(r,a,e[a],c);i.push(g)}}return z(i,s.duration)}var xe=5;function B(t,e,s){let n=Math.max(e-xe,0);return pt(s-t(n),e-n)}var R={stiffness:100,damping:10,mass:1};var Wt=(t=R.stiffness,e=R.damping,s=R.mass)=>e/(2*Math.sqrt(t*s));function Jt(t,e,s){return t<e&&s>=e||t>e&&s<=e}var jt=({stiffness:t=R.stiffness,damping:e=R.damping,mass:s=R.mass,from:n=0,to:i=1,velocity:o=0,restSpeed:r=2,restDistance:a=.5}={})=>{o=o?w.s(o):0;let c={done:!1,hasReachedTarget:!1,current:n,target:i},g=i-n,l=Math.sqrt(t/s)/1e3,u=Wt(t,e,s),d;if(u<1){let f=l*Math.sqrt(1-u*u);d=p=>i-Math.exp(-u*l*p)*((-o+u*l*g)/f*Math.sin(f*p)+g*Math.cos(f*p))}else d=f=>i-Math.exp(-l*f)*(g+(-o+l*g)*f);return f=>{c.current=d(f);let p=f===0?o:B(d,f,c.current),M=Math.abs(p)<=r,T=Math.abs(i-c.current)<=a;return c.done=M&&T,c.hasReachedTarget=Jt(n,i,c.current),c}};var Tt=10,ve=1e4;function bt(t){let e,s=Tt,n=t(0),i=[n.current];for(;!n.done&&s<ve;)n=t(s),i.push(n.done?n.target:n.current),e===void 0&&n.hasReachedTarget&&(e=s),s+=Tt;let o=s-Tt;return i.length===1&&i.push(n.current),{keyframes:i,duration:o/1e3,overshootDuration:(e!=null?e:o)/1e3}}function Xt(t){let e=new WeakMap;return(s={})=>{let n=new Map,i=(r=0,a=100,c=0,g=!1)=>{let l=`${r}-${a}-${c}-${g}`;return n.has(l)||n.set(l,t(Object.assign({from:r,to:a,velocity:c,restSpeed:g?.05:2,restDistance:g?.01:.5},s))),n.get(l)},o=r=>(e.has(r)||e.set(r,bt(r)),e.get(r));return{createAnimation:(r,a,c,g,l)=>{var u,d;let f,p=r.length;if(c&&p<=2&&r.every(je)){let T=r[p-1],j=p===1?null:r[0],y=0,b=0,v=l==null?void 0:l.generator;if(v){let{animation:m,generatorStartTime:A}=l,rt=(m==null?void 0:m.startTime)||A||0,O=(m==null?void 0:m.currentTime)||performance.now()-rt,K=v(O).current;b=(u=j)!==null&&u!==void 0?u:K,(p===1||p===2&&r[0]===null)&&(y=B(Zt=>v(Zt).current,O,K))}else b=(d=j)!==null&&d!==void 0?d:parseFloat(a());let _=i(b,T,y,g==null?void 0:g.includes("scale")),h=o(_);f=Object.assign(Object.assign({},h),{easing:"linear"}),l&&(l.generator=_,l.generatorStartTime=performance.now())}else{let T=o(i(0,100));f={easing:"ease",duration:T.overshootDuration}}return f}}}}var je=t=>typeof t!="string";var et=Xt(jt);function Te(t,e){return z([()=>{let s=new P(t,[0,1],e);return s.finished.catch(()=>{}),s}],e==null?void 0:e.duration)}function st(t,e,s){return(typeof t=="function"?Te:vt)(t,e,s)}var be=10*1e3,Ae=300,nt=(t,e)=>{var i;let{keyframes:s,transition:n}=e;if(((i=n==null?void 0:n.__easing)==null?void 0:i[0])==="spring"){let o=n,{__easing:[r,a]}=o,c=Et(o,["__easing"]);return st(t,s,Ot(Mt({},c),{easing:et(a)}))}else return st(t,s,n)},it=(t,e,s)=>new Promise((n,i)=>{liveSocket.transition(e,()=>{nt(t,s).finished.then(n).catch(i)})});function Se(){return{Motion:{getConfig(){return this.el.dataset.motion?JSON.parse(this.el.dataset.motion):void 0},maybeAnimate(){let t=this.getConfig()||{};t.defer||nt(this.el,t)},mounted(){this.maybeAnimate()},updated(){this.animate()}}}}function we(t,e){t.dataset.motion&&(t.getAttribute("style")===null?e.removeAttribute("style"):e.setAttribute("style",t.getAttribute("style")))}function Me(){return window.addEventListener("live_motion:animate",t=>{let{keyframes:e,transition:s}=t.detail||{};nt(t.target,{keyframes:e,transition:s})}),window.addEventListener("live_motion:hide",t=>{var s;let e=t.target;if(((s=t.detail)==null?void 0:s.keyframes)&&Object.keys(t.detail.keyframes).length>0){let{keyframes:n,transition:i}=t.detail,o=ot(i);it(e,o,{keyframes:n,transition:i}).then(()=>e.style.display="none")}else{liveSocket.isDebugEnabled()&&!e.dataset.motion&&console.warn("[LiveMotion] Motion configuration is not defined. Did you forget to make your target a LiveMotion.motion component?");let{exit:n,transition:i}=JSON.parse(e.dataset.motion);if(n){let o=ot(i);it(e,o,{keyframes:n,transition:i}).then(()=>e.style.display="none")}}}),window.addEventListener("live_motion:show",t=>{var s;let e=t.target;if(((s=t.detail)==null?void 0:s.keyframes)&&Object.keys(t.detail.keyframes).length>0){let{keyframes:n,transition:i,display:o}=t.detail,r=ot(i);e.style.display=o,it(e,r,{keyframes:n,transition:i})}else{liveSocket.isDebugEnabled()&&!e.dataset.motion&&console.warn("[LiveMotion] Motion configuration is not defined. Did you forget to make your target a LiveMotion.motion component?");let{keyframes:n,transition:i}=JSON.parse(e.dataset.motion),o=ot(i);e.style.display=t.detail.display,it(e,o,{keyframes:n,transition:i})}}),window.addEventListener("live_motion:toggle",t=>{let{keyframes:e,transition:s}=t.detail||{},n=t.target.dataset.motionToggle==="true",i=!e.in||!e.out?e:n?e.in:e.out,o=!s.in||!s.out?s:n?s.in:s.out;nt(t.target,{keyframes:i,transition:o}),t.target.dataset.motionToggle=!n}),{hook:Se(),handleMotionUpdates:we}}function ot(t){var e;return((e=t==null?void 0:t.__easing)==null?void 0:e[0])==="spring"?be:typeof(t==null?void 0:t.duration)!="undefined"?t.duration*1e3:Ae}return Oe;})();