grapper
Version:
Data Visualization Microframework
1 lines • 1.04 kB
JavaScript
/* grapper - 1.1.0-beta.3 [plugin.observe.style] */ (()=>{var f=0,y=0,r=new Map,d=!1;function b(l,s=()=>{}){let n=this.el;typeof l=="string"&&(l=[l]);let e;r.has(n)?e=r.get(n):(e={computedStyles:getComputedStyle(n),styles:{},keys:[]},r.set(n,e));for(let t of l)e.styles[t]||(e.styles[t]={lastValue:e.computedStyles[t],callbacks:new Set},e.keys.push(t)),e.styles[t].callbacks.add(s);return u(),this}function u(l){if(!d||l-y<100){d=!0,f=window.requestAnimationFrame(u);return}if(!l)return;y=l;let s=null;for(let[n,e]of r.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 i of e.styles[t].callbacks)s.has(i)?s.get(i)[t]={current:a,last:o}:s.set(i,{[t]:{current:a,last:o}});e.styles[t].lastValue=a}}if(s){for(let[t,a]of s.entries())t.call(n,a);s=null}}f=window.requestAnimationFrame(u)}function g(l){l.extendInstance({styleObserver:b})}var c=g;globalThis.gSVG&&globalThis.gSVG.install(c);customElements.whenDefined("grapper-view").then(l=>{l.install(c)});})();