UNPKG

grapper

Version:

Data Visualization Microframework

1 lines 30.2 kB
/* grapper - 1.1.0-beta.3 [module:component] */ var an="function",ue="undefined",S="object",L="string",W="array",C="number",k="boolean",un="date",ln="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,an),le=t=>H(t,C)&&!isNaN(t),ot=t=>!Number.isNaN(t),E=t=>H(t,ue),fe=t=>H(t,ln),he=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 fn(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 de(t){if(N(t))return t.trim().startsWith("[")?(t.match(/\[(.*?)[^\]]]/g)||[]).map(e=>de(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=hn(t.trim()),e===W)return de(t);if(e===S)return fn(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===un){try{let r=new Date(t);if(ot(r.getTime()))return r}catch{}return}if(E(e)||e===L)return n?`"${t}"`:t}function hn(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 pe=new WeakSet,nt=!1,Mt=(t,e)=>!y(t)||b(t)||!f(e)?t:function n(r){if(pe.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 pe.add(i),i}(t);Mt.stop=()=>nt=!0;Mt.start=()=>nt=!1;var ft=Mt;var rt=!1,ht=!0;function dn(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(dn(t),t);for(let n in e)y(e[n])&&(e[n]=B(e[n]));return e}function me(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 ye(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 pn(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 mn(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 yn(){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(),mn.call(this,new.target),f(this[G])&&yn.call(this)}[$](e,n={},r=!1){return this.dispatchEvent(new CustomEvent(e,{bubbles:!0,cancelable:!0,detail:n,composed:r}))}};function gn(t,e){e.propertyName||(e.propertyName=ct(e.name)),Ee(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,xn(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,En(e,d,u))}function En(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 xn(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 Ee(t,e){It(t.prototype,e.name,{set:xe(e),get:$n(e),configurable:!0,enumerable:!1}),pt.has(t)||pt.set(t,{}),pt.get(t)[e.name]=e.value}function Nn(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 xe(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)&&me(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)&&pn(this,t.attribute,e,t.type===k),Nn.call(this,t,e)))}}function $n(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=>xe(t).call(this,n));default:return e[t.name]}}}}function ge(t,e){e=e.toLowerCase(),customElements.get(e)||customElements.define(e,t)}function Ne(t,e={}){return e.prop=(...n)=>(n.forEach(r=>Ee(t,{...r})),e),e.attr=(...n)=>(n.forEach(r=>gn(t,{...r})),e),e.tag=n=>(ge(t,n),e),e.alias=n=>(ge(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 $e=1,kt=Symbol(),Ht=Symbol(),Z=Symbol(),R=Symbol(),Se=Symbol(),Vt=Symbol(),we=(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[Se])&&this[Se](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(),we(this,kt)}disconnectedCallback(){window.cancelAnimationFrame(this[x]._resizeObserver),we(this,Ht)}};v.prototype[kt]=[];v.prototype[Ht]=[];function Sn(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 wn(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]()}),$e))}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")}),$e))}}function yt(t){wn(t);let e=Ne(t,{style:(...n)=>(n.forEach(r=>Sn(t,{...r})),e)});return e}v.RENDER=R;v.REFRESH=Z;v.ONCONNECT=kt;v.ONDISCONNECT=Ht;var An="intersection.enter",Tn="intersection.exit",gt=Symbol();function bn(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(An)):(n=!1,e(Tn))})},{root:null,rootMargin:"0px",threshold:Array(21).fill(0).map((r,i)=>i*.05)}),this[gt].observe(this._el||this)}var Bt=bn;var Ae=Symbol();function Rn(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:On})}var Te=(t,e)=>e&&e.split(/\s+/).forEach(n=>t.add(n)),vn=(t,e)=>e&&e.split(/\s+/).forEach(n=>t.remove(n)),be=(t,e)=>{e.preventDefault();let n=()=>{t.removeEventListener("render",n),t[$](e.type,e.detail,e.composed)};t.addEventListener("render",n)};function On(){let t=this[x];if(this[Ae])return Bt.call(this,t.intersectionRatio);this[Ae]=!0;let e=this.classList;this.addEventListener("intersection.enter",n=>{Te(e,t.intersectionOnceClass),Te(e,t.intersectionClass),this.rendered||be(this,n)}),this.addEventListener("intersection.exit",n=>{vn(e,t.intersectionClass),this.rendered||be(this,n)}),Bt.call(this,t.intersectionRatio)}var Re=Rn;var Gt=new Map,Cn=/function\s+([\p{L}\p{Nl}$_][\p{L}\p{Nl}$_\p{Mn}\p{Mc}\p{Nd}\p{Pc}]*)\s*\(/gmu,Ln=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?Ln:Function)(...t,e);return Gt.set(r,i),i}function ve(t,e){let n=[...e.matchAll(Cn)].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(),Oe=(t,e,n)=>Object.defineProperty(t,e,{enumerable:!1,configurable:!0,writable:!0,value:n}),_n=(t,e)=>e===qt?t:ye(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]={}),Oe(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=_n(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}),Oe(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",Mn="http://www.w3.org/2000/svg",In="svg",Wt="d",Ce="transform",Me="appendChild",Kt="insertBefore",Le="insertAdjacentElement",Ie="attach",Pe="innerHTML",Jt=new WeakMap,Xt=new Set,Pn=t=>fe(t)||t.startsWith("_")||["el","gSVG","then"].includes(t),Un=()=>Qt+Math.random().toString(32).substring(2),jt=t=>y(t)&&!b(t)&&t[Symbol.toStringTag]===Qt,Dn=t=>wt(document.createElementNS(Mn,t)),xt=t=>N(t)?Dn(t):y(t)&&t!==null?jt(t)?t:wt(t):t,Fn=t=>({content:Pe,source:"outerHTML",parent:"parentElement",next:"nextElementSibling",previous:"previousElementSibling",add:Me,addBefore:Kt})[t]||t,Vn=t=>["append","before","after",Me,Kt,Le].includes(t)?function(...e){let n=[],r=[],i=[];return t===Le?(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(Ie))),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(Ie)),this}id(e){return e?(this._el.setAttribute("id",e),this):this._el.id||(this._el.id=Un())}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(Pn(r))return n[r];if(!E(n[r]))return(...c)=>(D(e,r,c),n[r].call(e,...c));if([Wt,Ce,"$"+Wt,"$"+Ce].includes(r)){let c="";r[0]==="$"&&(r=r.substring(1));let a=r===Wt?kn:Hn,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=Fn(r),o=Vn(i)||t[i];return f(o)?(...c)=>{D(e,r,c);let s=o.call(t,...c);return E(s)?e:De(s)}:Ue(t,i,e)}});return Jt.set(t,e),e},Ue=(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 De(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===Pe)return n;Xt.add(i)}return s!==0&&!s?t?.removeAttribute&&t.removeAttribute(i):t?.setAttribute&&t.setAttribute(i,he(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):Ue(t[i],s,n,i)},set(c,s,a){return t[i][s]=a,!0}})},De=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,Fe=[],D=(t,e,n,r=[])=>{for(let i of Fe)i(z,t,e,n,r)},Nt={},kn=(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(",")}`),Hn=(t,e,n)=>(D(t,`transform.${e}`,n),`${e}(${n.join(",")})`);function z(t){return D(null,"",[t]),xt(E(t)?In:t)}z.isWrapped=jt;var $t=t=>e=>f(e)?e(t):Object.assign(t,e),Zt={install:Ve,extendConstructor:$t(z),extendInstance:$t(St.prototype),extendPath:$t(Nt),beforeEveryCall(t){f(t)&&Fe.push(t)}};Zt.extendSetup=$t(Zt);function Ve(t){return t(Zt),z}z.install=Ve;var it=z;var te="animate",Bn="path",ke="d",He="transform",ze="rotate",q="translate",Be="inherit",Ge="finished",Gn=[ze,"skewX","skewY"],zn=[q,"width","height","x","y","cx","cy","r","rx","ry","dx","dy"],qn=(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 Yn=t=>t.replace(/([A-Z])/g,"-$1").toLowerCase();function Wn(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)||qn(this.tagName(),O)?p.add(O):O===ke?w.d=`${Bn}("${w.d}")`:O===He&&(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 cn=g[O];p in m[O]&&(w.push(cn.computedOffset),V.push(m[O][p]))}w[0]!==0&&(w.unshift(0),V.unshift(this[p]()||Be)),w[w.length-1]!==1&&(w.push(1),V.push(this[p]()||Be)),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===ze){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)=>Gn.includes(m)?l+"deg":zn.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=Yn(p);T.startsWith("text-")?this._el.style[p]=l[p]:p!=="offset"&&p in l&&this._el.setAttribute(T,T===ke?P(l[p]):T===He?Lt(l[p]):A(l[p]))}s.forEach(p=>p[Ge](!0));let m=this._el.querySelectorAll(te),g=this._el.querySelectorAll(`${te}[${Ge}]`);m.length===g.length&&m.forEach(p=>p.remove()),f(r)&&r.call(this,Y)}),this}function Jn(t){t.extendInstance({animateTo:Wn})}var qe=Jn;var Tt={},Ye=Symbol(),Ze=Symbol(),_=Symbol(),Q=Symbol(),At=Symbol(),re=Symbol(),We=Symbol(),ne="error",Xn="unknown",Je='an invalid "g-for" expression',Kn="undefined",Zn="NaN (Not a Number)",bt=(t,e)=>new Error(`The expression "${t}" return ${e} value`),Xe="class",Ke="style",Qn=(t,e,n)=>{throw new Error(t+` in ${e} `+n)},jn=(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 Qe(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 je(t){try{return new Function(`let ${t} = 0`),!0}catch{return!1}}function tr(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[_]),Qe(t)}});j({name:"g-bind",alias:":",arg:!0,exec(t,{expr:e,arg:n,data:r,evalExpr:i}){n=jn(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===Xe?[...o.classList]:n===Ke?[...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}),We}});let s=i(e,c);if(E(s))throw bt(e,Kn);if(n===Xe){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===Ke){Object.entries(s).forEach(([a,u])=>t.style[a](u));return}s!==We&&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[Ye]&&(t[Ye]=!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(Qe(t)),o=0;return ir(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[Ze]=!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 er(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 nr(t){return t.replace(/[{}()[\]]/g,"").split(",").map(e=>(e.includes(":")?e.split(":")[1].trim():e).trim())}function rr(t,e){return t[Symbol.iterator]?e==="of"?{iterator:[...t],type:W}:{type:ne}:le(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:Xn}}function tn(t,e,n=null){let r=Object.keys(e).filter(je),o=Et(r,`return ( ${t} ); `).apply(n,r.map(c=>e[c]));if(!ot(o))throw bt(t,Zn);return o}function ir(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,Je);let[,a,u,d]=s;u=u.trim(),a=a.trim(),d=d.trim();let h=tn(d,e)||[],{iterator:A,type:P}=rr(h,u);if(P===ne)throw bt(t,Je);P===S&&!a.startsWith("[")&&(a=`[${a.replace(/(^\()|(\)$)/g,"")}]`);let Lt=nr(a),et=a.startsWith("(")?a:`(${a})`,U=Object.keys(e).filter(je),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[Ze])return;let i=t.outerHTML();t[Q]=t[Q]||[];let o=t.attributes();for(let s of[...o]){let a=s.name,u=er(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:tn,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(tr(s.el),e,n):s.el?.nodeType===1&&st(s,e,n)}function sr(t={},e=Qn){st(this,t,e),this.dispatchEvent(new Event("render"))}function or(){return this.outerHTML().replaceAll("<!-- ref -->","")}function cr(t){t.install(qe),t.extendInstance({render:sr,source:or}),t.extendSetup({extendTemplate:{defineDirective:j,getDirective(e){return Tt[e]}}})}var en=cr;var nn=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:nn(t+n*Math.cos(i)),y:nn(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 ar(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 ur(t,e,n,r,i=0){return`${vt(t,e,n,r,i)}L${t},${e}Z`}function lr(t){t.extendConstructor({polar2cartesian:Rt,degrees2radians:ie}),t.extendview&&t.extendview({polar2cartesian:Rt,degrees2radians:ie}),t.extendPath({arc:vt,barArc:ar,circleSlice:ur})}var rn=lr;var se="update",tt="svg",oe="methods",ce="config",ae="data",Ot="-src",sn=t=>`script[type=${t}],g-script[type=${t}]`,on=["0px","auto"],fr=t=>{let e=getComputedStyle(t.el);return on.includes(e.width)&&on.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(sn("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(sn(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=>ve({$: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)),fr(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(Re).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 hr=t=>{t.extendSetup({extendview(e){f(e)?e(F.prototype):Object.assign(F.prototype,e)}})};it.install(hr).install(en).install(rn);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 dr(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}export{dr as default};