UNPKG

grapper

Version:

Data Visualization Microframework

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