grapper
Version:
Data Visualization Microframework
1 lines • 28.1 kB
JavaScript
/* grapper - 1.1.0-rc.1 [view] */ (()=>{var dn="function",oe="undefined",A="object",k="string",q="array",C="number",V="boolean",pn="date",mn="symbol";var G=(t,e)=>typeof t===e,H=(t,e)=>t instanceof e,E=t=>G(t,A),N=t=>G(t,k),d=t=>G(t,dn),ce=t=>G(t,C)&&!isNaN(t),ot=t=>!Number.isNaN(t),g=t=>G(t,oe),ue=t=>G(t,mn),ae=t=>G(t,V),M=t=>Array.isArray(t),wt=t=>H(t,Date)&&!isNaN(t),b=t=>t===null,ct=t=>t.replace(/-([a-z0-9])/g,(e,n)=>n.toUpperCase());function yn(t){if(N(t))try{return JSON.parse(`{${t.replace(/^\s*{/,"").replace(/}\s*$/,"").split(/((?:[^;^,"']|"[^"]*"|'[^']*')+)/).filter(e=>!["",";",","].includes(e.trim())).map(e=>e.split(":")).map(e=>`"${e[0].trim()}":${L(e[1].trim(),void 0,!0)}`).join(",")}}`)}catch{try{return L(t)}catch(n){console.error(n);return}}if(E(t))return t}function fe(t){if(N(t))return t.trim().startsWith("[")?(t.match(/\[(.*?)[^\]]]/g)||[]).map(e=>fe(e.substring(1,e.length-1))):t.split(/[,;]/).map(e=>L(e.trim()));if(M(t))return t}function L(t,e,n=!1){if(!N(t))return t;if(t=En(t.trim()),e===q)return fe(t);if(e===A)return yn(t);if(g(e)||e===C){if(g(t)||t==="")return;let r=+t;if(ot(r)||e===C)return r}if(g(e)||e===V){if(t==="true")return!0;if(t==="false")return!1;if(e===V)return t==="0"?!1:!!t}if(e===pn){try{let r=new Date(t);if(ot(r.getTime()))return r}catch{}return}if(g(e)||e===k)return n?`"${t}"`:t}function En(t){return t[0]==="'"&&t[t.length-1]==="'"||t[0]==='"'&&t[t.length-1]==='"'?t.substring(1,t.length-1):t}function le(t){return/^\s*{/.test(t)&&/}\s*$/.test(t)}function he(t){return/^\s*\[/.test(t)&&/]\s*$/.test(t)}function de(t){let e=[],n=t.split(/(\r\n|\r|\n)/).map(r=>r.trim()).filter(r=>r);return n.length===0?[]:n.length===1?L(n[0]):n.reduce((r,i,o)=>{let u={},s=i.split(/((?:[^;^,"']|"[^"]*"|'[^']*')+)/).filter(c=>!["",";",","].includes(c.trim()));return o===0?(e=[...s.map(c=>L(c))],r):(s.forEach((c,f)=>{u[e[f]]=L(c)}),r.push(u),r)},[])}function Rt(t){let e=`return (${t});`,n=new Function(e)();return d(n)?n():n}var pe=new WeakSet,et=!1,Ot=(t,e)=>!E(t)||b(t)||!d(e)?t:function n(r){if(pe.has(r))return r;for(let o in r)E(r[o])&&!b(r[o])&&(r[o]=n(r[o]));let i=new Proxy(r,{get(o,u){let s=Reflect.get(r,u);return d(s)&&wt(o)&&N(u)&&u.substring(0,3)==="set"&&d(e)&&(s=function(...c){let f=Reflect.get(o,u).apply(o,c);return!et&&e(t),f}),wt(o)?s.bind(o):s},set(o,u,s){let c,f=o[u]===s;return E(s)&&!b(s)?c=Reflect.set(o,u,n(s)):c=Reflect.set(o,u,s),!et&&!f&&e(t),c},deleteProperty(o,u){let s=Reflect.deleteProperty(o,u);return!et&&e(t),s}});return pe.add(i),i}(t);Ot.stop=()=>et=!0;Ot.start=()=>et=!1;var ut=Ot;var nt=!1,at=!0;function gn(t){return t===null?null:t.constructor?new t.constructor:{}}function B(t){if(!E(t))return t;let e=t===null?null:Object.assign(gn(t),t);for(let n in e)E(e[n])&&(e[n]=B(e[n]));return e}function me(t,e){let n=[],r=[];function i(u,s){if(b(u)||b(s))return nt;if(d(u.valueOf)&&d(s.valueOf)&&(u!==u.valueOf()||s!==s.valueOf()))return u.valueOf()===s.valueOf()&&u.constructor===s.constructor;if(n.indexOf(u)>-1&&r.indexOf(s)>-1)return at;let c=Object.keys(u),f=Object.keys(s);if(c.length!==f.length)return nt;if(c.length>0){n.push(u),r.push(s);let h=c.length;for(;h--;){let l=c[h];if(!o(u[l],s[l]))return nt}}return at}function o(u,s){if(u===s)return at;let c=typeof u;return c!==typeof s?nt:c===C&&isNaN(u)&&isNaN(s)?at:c===A?i(u,s):nt}return o(t,e)}function ye(t,e){let n=t,r=N(e)?e.split("."):e;for(let i=0;i<r.length;i++){if(g(n[r[i]]))return;n=n[r[i]]}return n}var $=Symbol(),z=Symbol(),T=Symbol(),Ct=Object.defineProperty;function $n(t,e,n,r=!1){if(!(t.ready===!1||!e))if(r)n?t.setAttribute(e,""):t.removeAttribute(e);else{let i=b(n)||g(n)?"":n.toString();t.hasAttribute(e)&&t.getAttribute(e)!==i&&t.setAttribute(e,i)}}function Nn(t){this[$]={};let e=t;do{let n=ft.get(e);for(let r in n)if(n.hasOwnProperty(r)&&this.hasOwnProperty(r)){let i=this[r];delete this[r],this[r]=g(i)?B(n[r]):i}else r in this[$]||(this[$][r]=B(n[r]));e=Object.getPrototypeOf(e)}while(e!==HTMLElement)}function xn(){new MutationObserver(t=>{t.some(e=>!e.attributeName)&&this[T]("update"),(g(this.ready)||this.ready)&&d(this[z])&&this[z](t)}).observe(this,{attributes:!0,childList:!0,subtree:!0,characterData:!0})}var ft=new WeakMap,J=class extends HTMLElement{constructor(){super(),Nn.call(this,new.target),d(this[z])&&xn.call(this)}[T](e,n={},r=!1){return this.dispatchEvent(new CustomEvent(e,{bubbles:!0,cancelable:!0,detail:n,composed:r}))}};function Sn(t,e){e.propertyName||(e.propertyName=ct(e.name)),ge(t,{...e,name:e.propertyName,attribute:e.name});let n=Object.getPrototypeOf(t),r="observedAttributes",i=Object.getOwnPropertyDescriptor(t,r),o=Object.getOwnPropertyDescriptor(n,r),u=i?i.get:void 0;Ct(t,r,Tn(t,e,n,u,i,o));let s="attributeChangedCallback",c=Object.getOwnPropertyDescriptor(t.prototype,s),f=Object.getOwnPropertyDescriptor(n.prototype,s),h=c?c.value:void 0;Ct(t.prototype,s,An(e,h,f))}function An(t,e,n){return{value:function(r,i,o){if(t.name===r){let u=t.propertyName;this[u]!==o&&(t.type===V?this[u]=this.hasAttribute(t.name):this[u]=L(o,t.type))}else e&&e.apply(this,arguments);n?.value&&n.value.apply(this,arguments)},enumerable:!1,writable:!0,configurable:!0}}function Tn(t,e,n,r,i,o){let u={enumerable:!1,configurable:!0};return i?o?u.get=function(){return[e.name,...r.call(t),...o.get.call(n)]}:u.get=function(){return[e.name,...r.call(t)]}:u.get=o?function(){return[e.name,...o.get.call(n)]}:function(){return[e.name]},u}function ge(t,e){Ct(t.prototype,e.name,{set:$e(e),get:wn(e),configurable:!0,enumerable:!1}),ft.has(t)||ft.set(t,{}),ft.get(t)[e.name]=e.value}function bn(t,e){b(t.posUpdateEvent)||(t.posUpdateEvent?this[T](t.posUpdateEvent,{[t.name]:e}):this[T]("update",{[t.name]:e})),d(t.posUpdate)?t.posUpdate.call(this,e):d(this[t.posUpdate])&&this[t.posUpdate]()}function $e(t){return function(e){let n=this[$];d(t.preUpdate)&&!t.preUpdate.call(this,e)||(t.schema&&(ut.stop(),e=t.schema.normalize(e),ut.start()),!(!E(e)&&me(n[t.name],e))&&(d(t.set)?t.set.call(this,e):n[t.name]=N(e)&&t.type?L(e,t.type):e,t.attribute&&![q,A].includes(t.type)&&$n(this,t.attribute,e,t.type===V),bn.call(this,t,e)))}}function wn(t){return function(){if(d(t.get))return t.get.call(this);{let e=this[$];switch(t.type){case C:return g(e[t.name])?void 0:Number(e[t.name]);case V:return!!e[t.name];case A:case q:return ut(e[t.name]||(t.type===A?{}:[]),n=>$e(t).call(this,n));default:return e[t.name]}}}}function Ee(t,e){e=e.toLowerCase(),customElements.get(e)||customElements.define(e,t)}function Ne(t,e={}){return e.prop=(...n)=>(n.forEach(r=>ge(t,{...r})),e),e.attr=(...n)=>(n.forEach(r=>Sn(t,{...r})),e),e.tag=n=>(Ee(t,n),e),e.alias=n=>(Ee(class extends t{},n),e),e.extension=e.ext=n=>(n.call(e,e,t),e),e}J.CHANGE=z;J.FIRE_EVENT=T;function vt(t,e){let n=new WeakMap;return function(...r){clearTimeout(n.get(this)),n.set(this,setTimeout(()=>{t.apply(this,r)},e))}}function _t(t,e){let n=new WeakMap,r=[];return function(...i){return clearTimeout(n.get(this)),new Promise((o,u)=>{r.push({resolve:o,reject:u}),n.set(this,setTimeout(()=>{try{let s=t.apply(this,i);r.forEach(c=>c.resolve(s))}catch(s){r.forEach(c=>c.reject(s))}finally{r.length=0}},e))})}}function Lt(t,e){return function(...n){if(t.apply(this,n))return e.apply(this,n)}}function Mt(t,e){return function(...n){let r=t.apply(this,n);return d(r.then)?r.then(i=>e.call(this,i)||i):e.call(this,r)||r}}var xe=1,It=Symbol(),Pt=Symbol(),X=Symbol(),P=Symbol(),Se=(t,e)=>t[e]?.forEach(n=>d(n)&&n.apply(t)),v=class extends J{constructor(e){super(),this.attachShadow({mode:"open"}),this[$].ready=e||!1,this[$].rendered=!1,g(e)&&(this.ready=!0)}get ready(){return this[$].ready}set ready(e){let n=this[$],r=n.ready;n.ready=!!e,r===!1&&n.ready===!0&&(this[T]("ready",{ready:!0}),d(this[P])&&this[P]())}get rendered(){return this[$].rendered}set rendered(e){let n=this[$],r=n.rendered;n.rendered=!!e,r===!1&&n.rendered===!0&&this[T]("render",{rendered:!0})}connectedCallback(){Se(this,It)}disconnectedCallback(){Se(this,Pt)}};v.prototype[It]=[];v.prototype[Pt]=[];function Rn(t){if(d(t.prototype[P])){let e=t.prototype[P];t.prototype[P]=Lt(function(){return this.rendered=!1,this.ready},_t(Mt(async function(){return e.apply(this)},function(n){this.rendered=n!==!1,this.rendered&&d(this[X])&&this[X]()}),xe))}if(d(t.prototype[X])){let e=t.prototype[X];t.prototype[X]=Lt(function(n){return n&&(this[$].rendered=!0),this.ready&&this[$].rendered},_t(Mt(async function(...n){return e.apply(this,n)},function(){this[T]("refresh")}),xe))}}function Ae(t,e={}){return Rn(t),Ne(t,e)}v.RENDER=P;v.REFRESH=X;v.ONCONNECT=It;v.ONDISCONNECT=Pt;var On="intersection.enter",Cn="intersection.exit",ht=Symbol();function vn(t){let e=i=>{setTimeout(()=>(this._el||this.svg?._el||this).dispatchEvent(new CustomEvent(i,{bubbles:!0,cancelable:!0,composed:!0})),50)},n=!0,r=!1;this[ht]&&this[ht].disconnect(),this[ht]=new IntersectionObserver(i=>{i.forEach(o=>{o.isIntersecting&&o.intersectionRatio>=t?r||(r=!0,e(On)):(r||n)&&(r=!1,e(Cn))}),n=!1},{root:null,rootMargin:"0px",threshold:Array(21).fill(0).map((i,o)=>o*.05)}),this[ht].observe(this._el||this)}var Ut=vn;var Te=Symbol();function _n(t){t.attr({name:"intersection-once-class",type:k,value:""}).attr({name:"intersection-class",type:k,value:""}).attr({name:"intersection-ratio",type:C,value:0,posUpdate:Mn})}var be=(t,e)=>e&&e.split(/\s+/).forEach(n=>t.add(n)),Ln=(t,e)=>e&&e.split(/\s+/).forEach(n=>t.remove(n)),we=(t,e)=>{e.preventDefault();let n=()=>{t.removeEventListener("render",n),t[T](e.type,e.detail,e.composed)};t.addEventListener("render",n)};function Mn(){let t=this[$];if(this[Te])return Ut.call(this,t.intersectionRatio);this[Te]=!0;let e=this.classList;this.addEventListener("intersection.enter",n=>{be(e,t.intersectionOnceClass),be(e,t.intersectionClass),this.rendered||we(this,n)}),this.addEventListener("intersection.exit",n=>{Ln(e,t.intersectionClass),this.rendered||we(this,n)}),Ut.call(this,t.intersectionRatio)}var Re=_n;var Dt=new Map,In=/function\s+([\p{L}\p{Nl}$_][\p{L}\p{Nl}$_\p{Mn}\p{Mc}\p{Nd}\p{Pc}]*)\s*\(/gmu,Pn=async function(){}.constructor;function dt(t,e,n=!1){let r=`${t.join(",")} ${e}`;if(Dt.has(r))return Dt.get(r);let i=new(n?Pn:Function)(...t,e);return Dt.set(r,i),i}function Oe(t,e){let n=[...e.matchAll(In)].map(i=>i[1]);return dt(Object.keys(t),`${e}; return {${n.map(i=>`${i}: typeof ${i} === 'function' ? ${i} : undefined`)}}; `)(...Object.values(t))}var Vt=Symbol(),Ft=Symbol(),Ce=(t,e,n)=>Object.defineProperty(t,e,{enumerable:!1,configurable:!0,writable:!0,value:n}),Un=(t,e)=>e===Vt?t:ye(t,e),Dn=Symbol();function kt(t={}){if(!E(t))return t;let e={};function n(r,i,o,u){r in t||(e[r]||(e[r]={}),Ce(t,r,(s=void 0,c=Vt,f)=>{if(N(s)||g(s)){if(c=s||Vt,!f&&c in e[r])return e[r][c];s=t}let h=s.reduce((l,R)=>{let w=Un(R,c);return g(w)?l:l===Ft?w:o(l,w)},d(i)?i():i);return h=d(u)?u(h):h,!f&&t!==s&&(e[r][c]=h),h===i?0:h}),Ce(t,r+"Before",(s,c)=>t[r](t.slice(0,s),c,Dn)))}return n("$min",Ft,(r,i)=>i>r?r:i),n("$max",Ft,(r,i)=>i<r?r:i),n("$count",0,r=>r+1),n("$sum",0,(r,i)=>i+r),n("$avg",()=>({n:0,i:0}),(r,i)=>(r.n++,r.i+=Number(i),r),r=>isNaN(r.i/r.n)?0:r.i/r.n),n("$distinct",()=>new Set,(r,i)=>(r.add(i),r),r=>[...r]),t}var Wt="gSVGObject",Fn="http://www.w3.org/2000/svg",Vn="svg",Gt="d",ve="transform",Me="appendChild",zt="insertBefore",_e="insertAdjacentElement",Ie="attach",Pe="innerHTML",Ht=new WeakMap,Bt=new Set,kn=t=>ue(t)||t.startsWith("_")||["el","gSVG","then"].includes(t),Gn=()=>Wt+Math.random().toString(32).substring(2),qt=t=>E(t)&&!b(t)&&t[Symbol.toStringTag]===Wt,Hn=t=>gt(document.createElementNS(Fn,t)),pt=t=>N(t)?Hn(t):E(t)&&t!==null?qt(t)?t:gt(t):t,Bn=t=>({content:Pe,source:"outerHTML",parent:"parentElement",next:"nextElementSibling",previous:"previousElementSibling",add:Me,addBefore:zt})[t]||t,zn=t=>["append","before","after",Me,zt,_e].includes(t)?function(...e){let n=[],r=[],i=[];return t===_e?(n.push(e[0]),r.push(pt(e[1]))):t===zt?(r.push(pt(e[0])),i.push(e[1]||this.firstChild||null)):r.push(...e.map(pt)),r.every(o=>o?._el)?(this[t](...n,...r.map(o=>o._el),...i),r.forEach(o=>o._el.dispatchEvent(new Event(Ie))),r.length>1?r:r[0]):null}:null,Et=class t{constructor(e){this._el=e,this.gSVG=Y}get[Symbol.toStringTag](){return Wt}get el(){return this._el}attachTo(e){return(E(e)?qt(e)?e._el:e:document.querySelector(e)).appendChild(this._el),this._el.dispatchEvent(new Event(Ie)),this}id(e){return e?(this._el.setAttribute("id",e),this):this._el.id||(this._el.id=Gn())}ref(){return`#${this.id()}`}url(){return`url(${this.ref()})`}parents(){let e=[],n=this;for(;(n=n.parentElement())&&H(n,t);)e.push(n);return e}top(){return this.parents()?.pop()||this}},gt=t=>{if(!E(t)||b(t))return null;if(Ht.has(t))return Ht.get(t);let e=new Proxy(new Et(t),{get(n,r){if(kn(r))return n[r];if(!g(n[r]))return(...u)=>(U(e,r,u),n[r].call(e,...u));if([Gt,ve,"$"+Gt,"$"+ve].includes(r)){let u="";r[0]==="$"&&(r=r.substring(1));let c=r===Gt?Yn:Wn,f=new Proxy(h=>(U(e,r,[h]),g(h)?t.getAttribute(r):(h?t.setAttribute(r,h):t.removeAttribute(r),e)),{get(h,l){return l in h?Reflect.get(h,l):(...R)=>{if(l===Symbol.toPrimitive){let w=u;return u="",w}return u+=c(e,l,R),t?.setAttribute(r,u),f}}});return f}let i=Bn(r),o=zn(i)||t[i];return d(o)?(...u)=>{U(e,r,u);let s=o.call(t,...u);return g(s)?e:De(s)}:Ue(t,i,e)}});return Ht.set(t,e),e},Ue=(t,e,n,r)=>{let i=e.replace(/_/g,"-"),o=(...u)=>{if(U(n,r?`${r}.${e}`:e,u),u.length===0){let c=t?.hasAttribute&&t.hasAttribute(i)?t.getAttribute(i):t[i];return De(c)}let s=u[0];if(H(t,CSSStyleDeclaration))return t[i]=s,n;if(i in t&&!Bt.has(i)){let c=t[i];if(String(c)===String(s))return n;try{t[i]=s}catch{Bt.add(i)}if(E(t[i])&&t[i]===s||t[i]!==c||i===Pe)return n;Bt.add(i)}return s!==0&&!s?t?.removeAttribute&&t.removeAttribute(i):t?.setAttribute&&t.setAttribute(i,ae(s)?"":String(u)),n};return new Proxy(o,{get(u,s){let c=t[i][s];return d(c)?(...f)=>(U(n,`${e}.${s}`,f),c.call(t[i],...f)||n):Ue(t[i],s,n,i)},set(u,s,c){return t[i][s]=c,!0}})},De=t=>H(t,HTMLCollection)||H(t,NodeList)?[...t].map(e=>gt(e)):H(t,SVGElement)?gt(t):N(t)?t===""||isNaN(t)?t:Number(t):t,Fe=[],U=(t,e,n,r=[])=>{for(let i of Fe)i(Y,t,e,n,r)},mt={},Yn=(t,e,n)=>(U(t,`d.${e}`,n,Object.keys(mt).map(r=>`d.${r}`)),mt[e]?mt[e].apply(t,n):`${e}${n.join(",")}`),Wn=(t,e,n)=>(U(t,`transform.${e}`,n),`${e}(${n.join(",")})`);function Y(t){return U(null,"",[t]),pt(g(t)?Vn:t)}Y.isWrapped=qt;var yt=t=>e=>d(e)?e(t):Object.assign(t,e),Yt={install:Ve,extendConstructor:yt(Y),extendInstance:yt(Et.prototype),extendPath:yt(mt),beforeEveryCall(t){d(t)&&Fe.push(t)}};Yt.extendSetup=yt(Yt);function Ve(t){return t(Yt),Y}Y.install=Ve;var K=Y;var Jt="animate",qn="path",ke="d",Ge="transform",Jn="rotate",Z="translate",He="inherit",Be="finished",Xn=t=>/^(rotate|skewX|skewY)$/.test(t),Kn=t=>/^(translate|width|height|x|y|cx|cy|r|rx|ry|dx|dy)$/.test(t),Zn=(t,e)=>t&&/^(text|tspan)$/.test(t)&&/^([xy])$/.test(e),Xt=!1;if(window.matchMedia){let t=window.matchMedia("(prefers-reduced-motion: reduce)");Xt=t.matches,t.addEventListener("change",()=>{Xt=t.matches})}var Qn=t=>t.replace(/([A-Z])/g,"-$1").toLowerCase();function jn(t,e={duration:200},n=null,r=null){let i=this.gSVG,o=a=>{let m=E(a)?{...a}:{duration:a};return Xt&&(m.duration=0),m.fill="none",m},u=a=>{a=M(a)?a:[a];let m=window.getComputedStyle(this._el),y=[],p=new Set;for(let S of a){let x={};for(let F in S){let O=ct(F);x[O]=l(S[F],O),!(O in m)||Zn(this.tagName(),O)?p.add(O):O===ke?x.d=`${qn}("${x.d}")`:O===Ge&&(x.transform=f(x.transform))}y.push(x)}return c(p,y),y},s=[],c=(a,m)=>{if(a.size){let y=new KeyframeEffect(null,m).getKeyframes();for(let p of a){let S=i(Jt).attributeName(p).dur(tt.duration+"ms").fill("freeze").begin("indefinite");if(m.length===1)S.to(m[0][p]);else{let x=[],F=[];for(let O in y){let hn=y[O];p in m[O]&&(x.push(hn.computedOffset),F.push(m[O][p]))}x[0]!==0&&(x.unshift(0),F.unshift(this[p]()||He)),x[x.length-1]!==1&&(x.push(1),F.push(this[p]()||He)),S.keyTimes(x.join(";")).values(F.join(";"))}s.push(S),S.attachTo(this),S.beginElementAt((tt.delay||0)/1e3)}}},f=a=>{N(a)&&(a=JSON.parse("{"+a.trim().replace(/^(\w+)\s*\(\s*([^)]+)\s*\)\s*$/,(y,p,S)=>`"${p}": [${S.trim().split(/\s*,\s*|\s+/).map(x=>/^[-+]?\d+(?:\.\d+)?$/.test(x)?x:`"${x}"`).join(", ")}]`)+"}"));let m="";for(let y in a)if(y===Jn){let p=h(a[y]);p.length>1&&(m+=`${Z}(${l(p[1],Z)},${l(p[2],Z)}) `),m+=`${y}(${l(p[0],y)}) `,p.length>1&&(m+=`${Z}(-${l(p[1],Z)},-${l(p[2],Z)}) `)}else m+=`${y}(${h(a[y]).map(p=>l(p,y)).join(",")}) `;return m},h=a=>M(a)?a:String(a).split(/\s+|,/),l=(a,m)=>N(a)&&/deg|px/.test(a)?a:Xn(m)?a+"deg":Kn(m)?a+"px":a,R=a=>N(a)?a.replace(/(deg)|(px)/g,"").trim():a,w=a=>a.replace(/(path\s*\(\s*["'])|(["']\s*\)\s*$)/g,"").trim().replace(/([a-zA-Z])\s*/g,"$1").replace(/\s+/g,","),bt=a=>{let m=/translate\((.*)px,(.*)px\) rotate\((.*)deg\) translate\((.*)px,(.*)px\)\s+/,y=m.exec(a);return y&&Number(y[1])===Number(y[4])*-1&&Number(y[2])===Number(y[5])*-1?a=a.replace(m,`rotate(${y[3]}, ${y[1]}, ${y[2]})`):a=R(a),a},tt=o(e),I=u(t),W=this._el.animate(I,tt);return W.ready.then(()=>d(n)&&n.call(this,W)),W.finished.then(()=>{let a=I[I.length-1];for(let p in a){let S=Qn(p);S.startsWith("text-")?this._el.style[p]=a[p]:p!=="offset"&&p in a&&this._el.setAttribute(S,S===ke?w(a[p]):S===Ge?bt(a[p]):R(a[p]))}s.forEach(p=>p[Be](!0));let m=this._el.querySelectorAll(Jt),y=this._el.querySelectorAll(`${Jt}[${Be}]`);m.length===y.length&&m.forEach(p=>p.remove()),d(r)&&r.call(this,W)}),this}function tr(t){t.extendInstance({animateTo:jn})}var ze=tr;var Nt={},Ye=Symbol(),Ke=Symbol(),_=Symbol(),Q=Symbol(),$t=Symbol(),Zt=Symbol(),We=Symbol(),Kt="error",er="unknown",qe='an invalid "g-for" expression',nr="undefined",rr="NaN (Not a Number)",xt=(t,e)=>new Error(`The expression "${t}" return ${e} value`),Je="class",Xe="style",ir=(t,e,n)=>{throw new Error(t+` in ${e} `+n)},sr=(t=>e=>t[e]||e)("attributeName attributeType baseFrequency calcMode clipPathUnits diffuseConstant edgeMode gradientTransform gradientUnits kernelMatrix kernelUnitLength lengthAdjust limitingConeAngle markerHeight markerUnits markerWidth maskContentUnits maskUnits numOctaves pathLength patternContentUnits patternTransform patternUnits pointsAtX pointsAtY pointsAtZ preserveAlpha preserveAspectRatio primitiveUnits refX refY requiredExtensions requiredFeatures specularConstant specularExponent spreadMethod startOffset stdDeviation stitchTiles surfaceScale systemLanguage tableValues targetX targetY textLength viewBox xChannelSelector yChannelSelector zoomAndPan".split(" ").reduce((t,e)=>(t[e.toLowerCase()]=e,t),{}));function Ze(t){if(!t?.el?.parentNode)return null;let e=document.createComment(" ref ");return t.parentNode().insertBefore(e,t.el),t.remove(),e[Zt]=t,e}function Qe(t){try{return new Function(`let ${t} = 0`),!0}catch{return!1}}function or(t){let e=t[Zt];return t.parentNode.insertBefore(e.el,t),t.remove(),e}j({name:"g-content",exec(t,{expr:e,ctx:n,evalExpr:r}){let i={...n,$$:{fromURL:async c=>{let f=await fetch(c);if(f.status===200)return f.text();console.warn(`Failed to load URL: ${c} (${f.status})`)},element:t,currentContent:t.content,...n.$||{}}};i.$=i.$$;let o=r(e,i),u=new CustomEvent("load",{bubbles:!0,detail:t}),s=c=>g(c)?"":c;E(o)&&o.then?o.then(c=>{t.content(s(c)),t.dispatchEvent(u)}):(t.content(s(o)),t.dispatchEvent(u))}});j({name:"g-if",exec(t,{expr:e,ctx:n,evalExpr:r}){if(!r(e,n))return t[_]&&(t[_].forEach(i=>i.remove()),delete t[_]),Ze(t)}});j({name:"g-bind",alias:":",arg:!0,exec(t,{expr:e,arg:n,ctx:r,evalExpr:i}){n=sr(n);let o=t._el,u={...r,$$:["d","transform"].includes(n)?t["$"+n]:{}};Object.assign(u.$$,{get element(){return t},get attribute(){return n},currentValue(){return n===Je?[...o.classList]:n===Xe?[...o.style].reduce((c,f)=>(c[f]=o.style[f],c),{}):t[n]()},dynamic(c,f=200,h=0){return t.animateTo((M(c)?c:[c]).map(l=>E(l)&&"offset"in l?{[n]:l.value,offset:l.offset}:{[n]:l}),{duration:f,delay:h}),We},...r.$||{}}),u.$=u.$$;let s=i(e,u);if(g(s))throw xt(e,nr);if(n===Je){let c=l=>t.classList.add(l),f=l=>t.classList.remove(l),h=l=>Object.entries(l).forEach(([R,w])=>w?c(R):f(R));if(M(s)){s.forEach(l=>N(l)?c(l):E(l)?h(l):void 0);return}if(E(s)){h(s);return}s&&c(s);return}if(n===Xe){Object.entries(s).forEach(([c,f])=>t.style[c](f));return}s!==We&&t[n](s)}});j({name:"g-on",alias:"@",arg:!0,exec(t,{expr:e,arg:n,ctx:r,evalExpr:i,error:o,code:u}){t[$t]=t[$t]||{};let s=t[$t][n]=t[$t][n]||new Map;s.has(e)&&t.removeEventListener(n,s.get(e));let c=function(f){try{let h=i(e,r,t);d(h)&&h.call(t,f)}catch(h){o(h.message,{directive:"g-on",argument:n,expression:e,toString(){return`g-on:${n}="${e}"`}},u)}};t.addEventListener(n,c),s.set(e,c),n==="init"&&!t[Ye]&&(t[Ye]=!0,t.dispatchEvent(new Event("init")))}});j({name:"g-for",tmpl:!0,exec(t,{expr:e,ctx:n,error:r}){t[_]=t[_]||[];let i=t.gSVG(Ze(t)),o=0;return fr(e,n,u=>{if(t[_][o])rt(t[_][o],u,r,!1);else{let s=t.gSVG(t.tagName());s[Q]=t[Q].filter(c=>c.name!=="g-for"),[...t.attributes()].forEach(c=>{c.name!=="g-for"&&s.setAttribute(c.name,c.value)}),t.children().forEach(c=>{s.add(c.cloneNode(!0))}),i.before(s),rt(s,u,r),s[Ke]=!0,t[_].push(s)}o++},u=>{for(;t[_].length>u.length;)t[_].pop().remove()}),!0}});function j({name:t,alias:e,arg:n,tmpl:r,exec:i}){let o=`^(${t}${n?":":""}${e?`|${e})`:")"}${n?"(.*)$":"$"}`,u=new RegExp(o,"i");Nt[t]={name:t,alias:e,arg:n,tmpl:r,exec:i,check:u}}function cr(t){for(let e in Nt){let n=Nt[e],r=n.check.exec(t);if(r){let i=r[2];return{...n,arg:i}}}}function ur(t){return t.replace(/[{}()[\]]/g,"").split(",").map(e=>(e.includes(":")?e.split(":")[1].trim():e).trim())}function ar(t,e){return t[Symbol.iterator]?e==="of"?{iterator:[...t],type:q}:{type:Kt}:ce(t)?{iterator:Array(t<0?0:0|t).fill(0).map((n,r)=>r+(e==="of"?0:1)),type:C}:E(t)?e==="in"?{iterator:Object.entries(t).map(n=>n.reverse()),type:A}:{type:Kt}:{iterator:t,type:er}}function je(t,e,n=null){let r=Object.keys(e).filter(Qe),o=dt(r,`return ( ${t} ); `).apply(n,r.map(u=>e[u]));if(!ot(o))throw xt(t,rr);return o}function fr(t,e,n,r){let i="__$$i",o="__$$c",u="__$$f",s=t.match(/^\s*([\s\S]+?)[\s*|)}\]](of|in)[\s*|({[]([\s\S]+?)\s*$/);if(!s)throw xt(t,qe);let[,c,f,h]=s;f=f.trim(),c=c.trim(),h=h.trim();let l=je(h,e)||[],{iterator:R,type:w}=ar(l,f);if(w===Kt)throw xt(t,qe);w===A&&!c.startsWith("[")&&(c=`[${c.replace(/(^\()|(\)$)/g,"")}]`);let bt=ur(c),tt=c.startsWith("(")?c:`(${c})`,I=Object.keys(e).filter(Qe),W=` ${i}.forEach(${tt} => { ${o}({${I}${I.length?",":""}${bt.join(",")}}); }); ${u}(${i}); `;return dt([...I,i,o,u],W)(...I.map(m=>e[m]),R,n,r)}function rt(t,e,n,r=!0){if(r&&t[Ke])return;let i=t.outerHTML();t[Q]=t[Q]||[];let o=t.attributes();for(let s of[...o]){let c=s.name,f=cr(c);f&&(t[Q].push({...f,expr:s.value}),t.removeAttribute(c))}let u=!1;for(let s of t[Q]){u=s.tmpl||u;try{if(s.exec(t,{...s,ctx:e,evalExpr:je,error:n,code:i}))return}catch(c){n(c.message,{directive:s.name,argument:s.arg,expression:s.expr,toString(){return`${s.name}${s.arg?":"+s.arg:""}="${s.expr}"`}},i)}}if(!u)for(let s of t.childNodes())s.el[Zt]?rt(or(s.el),e,n):s.el?.nodeType===1&&rt(s,e,n)}function lr(t={},e=ir){rt(this,t,e),this.dispatchEvent(new Event("render"))}function hr(){return this.outerHTML().replaceAll("<!-- ref -->","")}function dr(t){t.install(ze),t.extendInstance({render:lr,source:hr}),t.extendSetup({extendTemplate:{defineDirective:j,getDirective(e){return Nt[e]}}})}var tn=dr;var en=t=>Math.round(t*1e4)/1e4;function Qt(t){return(t-90)*Math.PI/180}function St(t,e,n,r){let i=Qt(r);return{x:en(t+n*Math.cos(i)),y:en(e+n*Math.sin(i))}}function At(t,e,n,r,i=0){i=Math.abs(i)>=360?i%360:i,r=Math.abs(r)>360?r%360:r,r=Math.abs(r)===360?r>0?359.9:-359.9:r;let o=i+r,u=r>0?1:0,s=Math.abs(o-i)<=180?0:1,c=i<0?(360+i)%360:i,f=o<0?(360+o)%360:o,h=St(t,e,n,c),l=St(t,e,n,f);return`M${h.x},${h.y}A${n},${n},0,${s},${u},${l.x},${l.y}`}function pr(t,e,n,r,i,o=0){let u=At(t,e,n+r/2,i,o),s=At(t,e,n-r/2,-i,o+i);return u+"L"+s.substring(1)+"Z"}function mr(t,e,n,r,i=0){return`${At(t,e,n,r,i)}L${t},${e}Z`}function yr(t){t.extendConstructor({polar2cartesian:St,degrees2radians:Qt}),t.extendview&&t.extendview({polar2cartesian:St,degrees2radians:Qt}),t.extendPath({arc:At,barArc:pr,circleSlice:mr})}var nn=yr;var jt="update",fn="load",ne="template",it="svg",re="data",ie="methods",se="config",rn="plugin",Tt="Src",te="src",sn="trust-origin",on="same-origin",cn=t=>`script[type=${t}],g-script[type=${t}]`,st=(t,e)=>t.querySelector(e),ee=(t,e)=>t?.getAttribute(e),Er=(t,e)=>t?.hasAttribute(e),un=["0px","auto"],gr=t=>{let e=getComputedStyle(t.el);return un.includes(e.width)&&un.includes(e.height)},an=t=>({get svg(){return t.svg},get data(){return t.data},get config(){return t.config},get methods(){return t.methods},polar2cartesian:t.polar2cartesian,degrees2radians:t.degrees2radians,grapperView:t}),D=class extends v{static install(e){K.install(e)}#t=null;#r=!1;#i=!1;#s=[];#e=[];#h=vt(function(e,n){this[T](e,n)},1);#n(e,n,r,i){let o={message:e,scope:n,code:r,toString:()=>`${e}${n?` in ${n}`:""} ${r}`};i.push(o),console.warn(`Grapper view - Error: ${o}`),this.#h.call(this,"error",this.errors)}#d(e){return e.length=0,(n,r="",i="")=>this.#n(n,r,i,this.#s)}async#c(e,n){let r=await fetch(e,n?{}:{mode:on,credentials:on});if(r.status!==200)throw new Error(`${r.statusText} (${r.status}): ${r.url}`);return r.text()}async#p(){let e=[...this.querySelectorAll(cn(rn))];for(let n of e){let r=ee(n,te);if(r){let i=new URL(r,document.location.href);try{let o=await import(i.href);o?.default&&K.install(o.default)}catch(o){this.#n(o.message,rn,r,this.#e)}}}}async#u(){let e=this[$];this.#t=null,e.content.innerHTML="";let n=st(this,ne);if(e.templateSrc||(e.templateSrc=ee(n,te)),e.templateSrc)try{e.content.innerHTML=await this.#c(e.templateSrc,n?.hasAttribute(sn))}catch(i){this.#n(i.message,it,e.templateSrc,this.#e)}else{let i=n?.content||st(this,it);i&&e.content.append(i.cloneNode(!0))}let r=st(e.content,it);return this.#t=r?K(r):null,!0}async#o(e,n){let r=this[$],i=e+"Src",o=st(this,cn(e)),u=!0;o&&(r[i]=ee(o,te),u=Er(o,sn));let s=r[i]?await this.#c(r[i],u).catch(c=>this.#n(c.message,e,r[i],this.#e)):o?.textContent;if(s)try{r[e]=n(s,!r[i])}catch(c){this.#n(c.message,e,s,this.#e)}}#a(){return this.#o(ie,e=>Oe({$:an(this)},e))}#f(){return this.#o(se,(e,n)=>n?Rt(e):JSON.parse(e))}#l(){return this.#o(re,(e,n)=>le(e)||he(e)?n?Rt(e):JSON.parse(e):de(e))}constructor(){super();let e=this[$],n="_loading_";this.shadowRoot.innerHTML=` <style> :host { display : inline-block; width : max-content; height : max-content; } .${n} { display : none; } </style><span class="${n}"></span>`,e.content=st(this.shadowRoot,"span"),this.addEventListener("render",()=>{e.content.classList.remove(n)})}[P](){return!this.load()}async[z](e){let n=[];for(let r of e){let i=r.target;if(i===this&&!r.attributeName)return this.load();if([it,ne].includes(i.tagName.toLowerCase()))n.push(this.#u());else if(i.tagName==="SCRIPT"){let o={data:this.#l,methods:this.#a,config:this.#f}[i.type.toLowerCase()];o&&n.push(o.bind(this)())}}if(n.length)return await Promise.all(n),this.update()}async load(){return this.#r=!1,this.#e=[],await this.#p(),await Promise.all([this.#u(),this.#f(),this.#a(),this.#l()]),this.#r=!0,this[T](fn),this.update(!0)}async update(e=!1){if(!(this.#i&&!e)&&this.#t){this.rendered=!1,this.#i=!0;let n=this[$],r=n.methods?.data?n.methods.data(kt(B(n.data))):kt(B(n.data)),i={...n.methods,...M(r)?{}:r,data:r,$:an(this)};await this.#t.render(i,this.#d(this.#s)),gr(this.#t)&&this.#t.width("100%").height("100%"),this.#i=!1,this.rendered=!0}}get[it](){return this.#t}get loaded(){return this.#r}get errors(){return[...this.#e,...this.#s]}get version(){return"1.1.0-rc.1"}get gSVG(){return K}};D.prototype.update=vt(D.prototype.update,1);var ln=Ae(D).ext(Re).attr({name:re,type:A,value:[],posUpdate:jt}).attr({name:"value",set(t){this.data={value:t}},get(){return this.data?.value}}).attr({name:se,type:A,value:{},posUpdate:jt}).prop({name:ie,type:A,value:{},posUpdate:jt});[ne+Tt,re+Tt,ie+Tt,se+Tt].forEach(t=>{ln.prop({name:t,type:k,value:"",posUpdate:fn})});ln.tag("grapper-view").alias("g-composer");var $r=t=>{t.extendSetup({extendview(e){d(e)?e(D.prototype):Object.assign(D.prototype,e)}})};K.install($r).install(tn).install(nn);})();