UNPKG

graphane

Version:

Data Visualization Microframework

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