index.cjs 1.7 KB

12
  1. "use strict";const p=e=>e!=null&&typeof e=="object"||!1,k=e=>p(e)&&typeof e.nodeType=="number"&&[1,2,3,4,5,6,7,8,9,10,11].some(t=>e.nodeType===t)||!1,u=e=>k(e)&&e.nodeType===1||!1,v=e=>typeof e=="function"||!1,d="1.0.7",_="PositionObserver Error";class y{entries;static version=d;_tick;_root;_callback;constructor(t,i){if(!v(t))throw new Error(`${_}: ${t} is not a function.`);this.entries=new Map,this._callback=t,this._root=u(i?.root)?i.root:document?.documentElement,this._tick=0}observe=t=>{if(!u(t))throw new Error(`${_}: ${t} is not an instance of Element.`);this._root.contains(t)&&this._new(t).then(({boundingClientRect:i})=>{if(i&&!this.getEntry(t)){const{clientWidth:s,clientHeight:n}=this._root;this.entries.set(t,{target:t,boundingClientRect:i,clientWidth:s,clientHeight:n})}this._tick||(this._tick=requestAnimationFrame(this._runCallback))})};unobserve=t=>{this.entries.has(t)&&this.entries.delete(t)};_runCallback=()=>{if(!this.entries.size)return;const{clientWidth:t,clientHeight:i}=this._root,s=new Promise(n=>{const o=[];this.entries.forEach(({target:r,boundingClientRect:c,clientWidth:a,clientHeight:f})=>{this._root.contains(r)&&this._new(r).then(({boundingClientRect:h,isIntersecting:m})=>{if(!m)return;const{left:b,top:w}=h;if(c.top!==w||c.left!==b||a!==t||f!==i){const l={target:r,boundingClientRect:h,clientHeight:i,clientWidth:t};this.entries.set(r,l),o.push(l)}})}),n(o)});this._tick=requestAnimationFrame(async()=>{const n=await s;n.length&&this._callback(n,this),this._runCallback()})};_new=t=>new Promise(i=>{new IntersectionObserver(([n],o)=>{o.disconnect(),i(n)}).observe(t)});getEntry=t=>this.entries.get(t);disconnect=()=>{cancelAnimationFrame(this._tick),this.entries.clear(),this._tick=0}}module.exports=y;
  2. //# sourceMappingURL=index.cjs.map