UNPKG

@graphery/svg

Version:
1 lines 1.02 kB
(()=>{function i(l,s){Object.assign(s.prototype,{styleObserver(r,e){let t=this,a=this.el.tagName.toLowerCase()==="svg"?this.el:this.closest("svg").el;return g(a,r,e),t}})}let p=100;let y=0,b=0,n=new Map,f=!1;function g(l,s,r){typeof s=="string"&&(s=[s]);let e;n.has(l)?e=n.get(l):(e={computedStyles:getComputedStyle(l),styles:{},keys:[]},n.set(l,e));for(let t of s)e.styles[t]||(e.styles[t]={lastValue:e.computedStyles[t],callbacks:new Set},e.keys.push(t)),e.styles[t].callbacks.add(r);u()}function u(l){if(!f||l-b<p){f=!0,y=window.requestAnimationFrame(u);return}if(!l)return;b=l;let s=null;for(let[r,e]of n.entries()){for(let t of e.keys){let a=e.computedStyles.getPropertyValue(t),o=e.styles[t].lastValue;if(a!==o){s||(s=new Map);for(let c of e.styles[t].callbacks)s.has(c)?s.get(c)[t]={current:a,last:o}:s.set(c,{[t]:{current:a,last:o}});e.styles[t].lastValue=a}}if(s){for(let[t,a]of s.entries())t.call(r,a);s=null}}y=window.requestAnimationFrame(u)}(typeof gobalThis!="undefined"?globalThis:window).gySVG.extend(i);})();