forked from formkit/auto-animate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.min.js
1 lines (1 loc) · 5.18 KB
/
index.min.js
1
const e=new Set,t=new WeakMap,n=new WeakMap,o=new WeakMap,i=new WeakMap,r=new WeakMap,a=new WeakMap,s=new WeakMap;let d;const l="__aa_tgt",c="__aa_del",f=e=>{const r=function(e){return e.reduce(((e,t)=>{if(!1===e)return!1;if(t.target instanceof Element){if(b(t.target),!e.has(t.target)){e.add(t.target);for(let n=0;n<t.target.children.length;n++){const o=t.target.children.item(n);if(o){if(c in o)return!1;b(t.target,o),e.add(o)}}}if(t.removedNodes.length)for(let o=0;o<t.removedNodes.length;o++){const i=t.removedNodes[o];if(c in i)return!1;i instanceof Element&&(e.add(i),b(t.target,i),n.set(i,[t.previousSibling,t.nextSibling]))}}return e}),new Set)}(e);r&&r.forEach((e=>function(e){var r;const a=d.contains(e),s=t.has(e);a&&n.has(e)&&n.delete(e);o.has(e)&&(null===(r=o.get(e))||void 0===r||r.cancel());s&&a?function(e){const n=t.get(e),i=v(e);let r;if(!n)return;const a=x(e);if("function"!=typeof a){const t=n.left-i.left,o=n.top-i.top,[s,d,l,c]=M(e,n,i),f={transform:`translate(${t}px, ${o}px)`},u={transform:"translate(0, 0)"};s!==d&&(f.width=`${s}px`,u.width=`${d}px`),l!==c&&(f.height=`${l}px`,u.height=`${c}px`),r=e.animate([f,u],a)}else r=new Animation(a(e,"remain",n,i)),r.play();o.set(e,r),t.set(e,i),r.addEventListener("finish",p.bind(null,e))}(e):s&&!a?function(e){if(!n.has(e)||!t.has(e))return;const[r,a]=n.get(e);Object.defineProperty(e,c,{value:!0}),a&&a.parentNode&&a.parentNode instanceof Element?a.parentNode.insertBefore(e,a):r&&r.parentNode&&r.parentNode.appendChild(e);const[s,d,l,f]=function(e){const n=t.get(e),[o,,i]=M(e,n,v(e));let r=e.parentElement;for(;r&&("static"===getComputedStyle(r).position||r instanceof HTMLBodyElement);)r=r.parentElement;r||(r=document.body);const a=getComputedStyle(r),s=t.get(r)||v(r),d=Math.round(n.top-s.top)-y(a.borderTopWidth),l=Math.round(n.left-s.left)-y(a.borderLeftWidth);return[d,l,o,i]}(e),u=x(e),p=t.get(e);let h;Object.assign(e.style,{position:"absolute",top:`${s}px`,left:`${d}px`,width:`${l}px`,height:`${f}px`,margin:0,pointerEvents:"none",transformOrigin:"center",zIndex:100}),"function"!=typeof u?h=e.animate([{transform:"scale(1)",opacity:1},{transform:"scale(.98)",opacity:0}],{duration:u.duration,easing:"ease-out"}):(h=new Animation(u(e,"remove",p)),h.play());o.set(e,h),h.addEventListener("finish",(()=>{var r;e.remove(),t.delete(e),n.delete(e),o.delete(e),null===(r=i.get(e))||void 0===r||r.disconnect()}))}(e):function(e){const n=v(e);t.set(e,n);const i=x(e);let r;"function"!=typeof i?r=e.animate([{transform:"scale(.98)",opacity:0},{transform:"scale(0.98)",opacity:0,offset:.5},{transform:"scale(1)",opacity:1}],{duration:1.5*i.duration,easing:"ease-in"}):(r=new Animation(i(e,"add",n)),r.play());o.set(e,r),r.addEventListener("finish",p.bind(null,e))}(e)}(e)))},u=n=>{n.forEach((n=>{n.target===d&&(clearTimeout(s.get(d)),s.set(d,setTimeout((()=>{e.forEach((e=>E(e,(e=>g((()=>p(e)))))))}),100))),t.has(n.target)&&p(n.target)}))};function p(e){clearTimeout(s.get(e));const n=x(e),r="function"==typeof n?500:n.duration;s.set(e,setTimeout((()=>{const n=o.get(e);n&&!n.finished||(t.set(e,v(e)),function(e){const n=i.get(e);null==n||n.disconnect();let o=t.get(e),r=0;o||(o=v(e),t.set(e,o));const{offsetWidth:a,offsetHeight:s}=d,l=[o.top-5,a-(o.left+5+o.width),s-(o.top+5+o.height),o.left-5].map((e=>-1*Math.floor(e)+"px")).join(" "),c=new IntersectionObserver((()=>{++r>1&&p(e)}),{root:d,threshold:1,rootMargin:l});c.observe(e),i.set(e,c)}(e))}),r))}function h(e){setTimeout((()=>{r.set(e,setInterval((()=>g(p.bind(null,e))),2e3))}),Math.round(2e3*Math.random()))}function g(e){"function"==typeof requestIdleCallback?requestIdleCallback((()=>e())):requestAnimationFrame((()=>e()))}let m,w;function b(e,t){t||l in e?t&&!(l in t)&&Object.defineProperty(t,l,{value:e}):Object.defineProperty(e,l,{value:e})}function y(e){return Number(e.replace(/[^0-9.\-]/g,""))}function v(e){const t=e.getBoundingClientRect(),n=x(e),o="function"!=typeof n&&n.scrollContainer?n.scrollContainer.scrollTop:window.scrollY,i="function"!=typeof n&&n.scrollContainer?n.scrollContainer.scrollLeft:window.scrollX;return{top:t.top+o,left:t.left+i,width:t.width,height:t.height}}function M(e,t,n){let o=t.width,i=t.height,r=n.width,a=n.height;const s=getComputedStyle(e);if("content-box"===s.getPropertyValue("box-sizing")){const e=y(s.paddingTop)+y(s.paddingBottom)+y(s.borderTopWidth)+y(s.borderBottomWidth),t=y(s.paddingLeft)+y(s.paddingRight)+y(s.borderRightWidth)+y(s.borderLeftWidth);o-=t,r-=t,i-=e,a-=e}return[o,r,i,a].map(Math.round)}function x(e){return l in e&&a.has(e[l])?a.get(e[l]):{duration:250,easing:"ease-in-out"}}function E(e,...t){t.forEach((t=>t(e,a.has(e))));for(let n=0;n<e.children.length;n++){const o=e.children.item(n);o&&t.forEach((e=>e(o,a.has(o))))}}function W(t,n={}){if(m&&w){if(window.matchMedia("(prefers-reduced-motion: reduce)").matches)return;"static"===getComputedStyle(t).position&&Object.assign(t.style,{position:"relative"}),E(t,p,h,(e=>null==w?void 0:w.observe(e))),"function"==typeof n?a.set(t,n):a.set(t,{duration:250,easing:"ease-in-out",...n}),m.observe(t,{childList:!0}),e.add(t)}}"undefined"!=typeof window&&(d=document.documentElement,m=new MutationObserver(f),w=new ResizeObserver(u),w.observe(d));const C={mounted:(e,t)=>{W(e,t.value||{})}};export{W as default,M as getTransitionSizes,C as vAutoAnimate};