UNPKG

grapper

Version:

Data Visualization Microframework

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