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