UNPKG

graphane

Version:

Data Visualization Microframework

1 lines 10.5 kB
/* graphane - 1.0.1 [module:core] */ var he="function",Q="undefined",E="object",A="string",D="array",y="number",N="boolean",de="date";var B="";var U=(e,t)=>typeof e===t,me=(e,t)=>e instanceof t,p=e=>U(e,E),x=e=>U(e,A),u=e=>U(e,he);var K=e=>!Number.isNaN(e),a=e=>U(e,Q);var ye=e=>Array.isArray(e),v=e=>me(e,Date)&&!isNaN(e),d=e=>e===null,Z=e=>e.replace(/-([a-z0-9])/g,(t,n)=>n.toUpperCase());function Ee(e){if(x(e))try{return JSON.parse(`{${e.replace(/^\s*{/,"").replace(/}\s*$/,"").split(/((?:[^;^,"']|"[^"]*"|'[^']*')+)/).filter(t=>!["",";",","].includes(t.trim())).map(t=>t.split(":")).map(t=>`"${t[0].trim()}":${O(t[1].trim(),void 0,!0)}`).join(",")}}`)}catch{try{return O(e)}catch(n){console.error(n);return}}if(p(e))return e}function j(e){if(x(e))return e.trim().startsWith("[")?(e.match(/\[(.*?)[^\]]]/g)||[]).map(t=>j(t.substring(1,t.length-1))):e.split(/[,;]/).map(t=>O(t.trim()));if(ye(e))return e}function O(e,t,n=!1){if(!x(e))return e;if(e=xe(e.trim()),t===D)return j(e);if(t===E)return Ee(e);if(a(t)||t===y){if(a(e)||e==="")return;let r=+e;if(K(r)||t===y)return r}if(a(t)||t===N){if(e==="true")return!0;if(e==="false")return!1;if(t===N)return e==="0"?!1:!!e}if(t===de){try{let r=new Date(e);if(K(r.getTime()))return r}catch{}return}if(a(t)||t===A)return n?`"${e}"`:e}function xe(e){return e[0]==="'"&&e[e.length-1]==="'"||e[0]==='"'&&e[e.length-1]==='"'?e.substring(1,e.length-1):e}var ee=new WeakSet,w=!1,k=(e,t)=>!p(e)||d(e)||!u(t)?e:function n(r){if(ee.has(r))return r;for(let o in r)p(r[o])&&!d(r[o])&&(r[o]=n(r[o]));let s=new Proxy(r,{get(o,i){let c=Reflect.get(r,i);return u(c)&&v(o)&&x(i)&&i.substring(0,3)==="set"&&u(t)&&(c=function(...f){let m=Reflect.get(o,i).apply(o,f);return!w&&t(e),m}),v(o)?c.bind(o):c},set(o,i,c){let f,m=o[i]===c;return p(c)&&!d(c)?f=Reflect.set(o,i,n(c)):f=Reflect.set(o,i,c),!w&&!m&&t(e),f},deleteProperty(o,i){let c=Reflect.deleteProperty(o,i);return!w&&t(e),c}});return ee.add(s),s}(e);k.stop=()=>w=!0;k.start=()=>w=!1;var M=k;var b=!1,F=!0;function ge(e){return e===null?null:e.constructor?new e.constructor:{}}function I(e){if(!p(e))return e;let t=e===null?null:Object.assign(ge(e),e);for(let n in t)p(t[n])&&(t[n]=I(t[n]));return t}function te(e,t){let n=[],r=[];function s(i,c){if(d(i)||d(c))return b;if(u(i.valueOf)&&u(c.valueOf)&&(i!==i.valueOf()||c!==c.valueOf()))return i.valueOf()===c.valueOf()&&i.constructor===c.constructor;if(n.indexOf(i)>-1&&r.indexOf(c)>-1)return F;let f=Object.keys(i),m=Object.keys(c);if(f.length!==m.length)return b;if(f.length>0){n.push(i),r.push(c);let _=f.length;for(;_--;){let q=f[_];if(!o(i[q],c[q]))return b}}return F}function o(i,c){if(i===c)return F;let f=typeof i;return f!==typeof c?b:f===y&&isNaN(i)&&isNaN(c)?F:f===E?s(i,c):b}return o(e,t)}var C=globalThis.GRAPHANE_PREFIX||"g-",l=Symbol(),$=Symbol(),h=Symbol(),z=Object.defineProperty;function Ne(e,t,n,r=!1){if(!(e.ready===!1||!t))if(r)n?e.setAttribute(t,B):e.removeAttribute(t);else{let s=d(n)||a(n)?B:n.toString();e.hasAttribute(t)&&e.getAttribute(t)!==s&&e.setAttribute(t,s)}}function Oe(e){this[l]={};let t=e;do{let n=L.get(t);for(let r in n)if(n.hasOwnProperty(r)&&this.hasOwnProperty(r)){let s=this[r];delete this[r],this[r]=a(s)?I(n[r]):s}else r in this[l]||(this[l][r]=I(n[r]));t=Object.getPrototypeOf(t)}while(t!==HTMLElement)}function Se(){new MutationObserver(e=>{e.some(t=>!t.attributeName)&&this[h]("update"),(a(this.ready)||this.ready)&&u(this[$])&&this[$](e)}).observe(this,{attributes:!0,childList:!0,subtree:!0,characterData:!0})}var L=new WeakMap,S=class extends HTMLElement{constructor(){super(),Oe.call(this,new.target),u(this[$])&&Se.call(this)}[h](t,n={},r=!1){return this.dispatchEvent(new CustomEvent(t,{bubbles:!0,cancelable:!0,detail:n,composed:r}))}};function Te(e,t){t.propertyName||(t.propertyName=Z(t.name)),ne(e,{...t,name:t.propertyName,attribute:t.name});let n=Object.getPrototypeOf(e),r="observedAttributes",s=Object.getOwnPropertyDescriptor(e,r),o=Object.getOwnPropertyDescriptor(n,r),i=s?s.get:void 0;z(e,r,Ae(e,t,n,i,s,o));let c="attributeChangedCallback",f=Object.getOwnPropertyDescriptor(e.prototype,c),m=Object.getOwnPropertyDescriptor(n.prototype,c),_=f?f.value:void 0;z(e.prototype,c,Re(t,_,m))}function Re(e,t,n){return{value:function(r,s,o){if(e.name===r){let i=e.propertyName;this[i]!==o&&(e.type===N?this[i]=this.hasAttribute(e.name):this[i]=O(o,e.type))}else t&&t.apply(this,arguments);n?.value&&n.value.apply(this,arguments)},enumerable:!1,writable:!0,configurable:!0}}function Ae(e,t,n,r,s,o){let i={enumerable:!1,configurable:!0};return s?o?i.get=function(){return[t.name,...r.call(e),...o.get.call(n)]}:i.get=function(){return[t.name,...r.call(e)]}:i.get=o?function(){return[t.name,...o.get.call(n)]}:function(){return[t.name]},i}function ne(e,t){z(e.prototype,t.name,{set:re(t),get:be(t),configurable:!0,enumerable:!1}),L.has(e)||L.set(e,{}),L.get(e)[t.name]=t.value}function we(e,t){d(e.posUpdateEvent)||(e.posUpdateEvent?this[h](e.posUpdateEvent,{[e.name]:t}):this[h]("update",{[e.name]:t})),u(e.posUpdate)?e.posUpdate.call(this,t):u(this[e.posUpdate])&&this[e.posUpdate]()}function re(e){return function(t){let n=this[l];u(e.preUpdate)&&!e.preUpdate.call(this,t)||(e.schema&&(M.stop(),t=e.schema.normalize(t),M.start()),!(!p(t)&&te(n[e.name],t))&&(u(e.set)?e.set.call(this,t):n[e.name]=x(t)&&e.type?O(t,e.type):t,e.attribute&&![D,E].includes(e.type)&&Ne(this,e.attribute,t,e.type===N),we.call(this,e,t)))}}function be(e){return function(){if(u(e.get))return e.get.call(this);{let t=this[l];switch(e.type){case y:return a(t[e.name])?void 0:Number(t[e.name]);case N:return!!t[e.name];case E:case D:return M(t[e.name]||(e.type===E?{}:[]),n=>re(e).call(this,n));default:return t[e.name]}}}}function $e(e,t){t=C+t.toLowerCase(),customElements.get(t)||customElements.define(t,e)}function ie(e,t={}){return t.prop=(...n)=>(n.forEach(r=>ne(e,{...r})),t),t.attr=(...n)=>(n.forEach(r=>Te(e,{...r})),t),t.tag=n=>($e(e,n),t),t.extension=t.ext=n=>(n.call(t,t,e),t),t}S.CHANGE=$;S.FIRE_EVENT=h;function H(e,t){let n=new WeakMap,r=[];return function(...s){return clearTimeout(n.get(this)),new Promise((o,i)=>{r.push({resolve:o,reject:i}),n.set(this,setTimeout(()=>{try{let c=e.apply(this,s);r.forEach(f=>f.resolve(c))}catch(c){r.forEach(f=>f.reject(c))}finally{r.length=0}},t))})}}function W(e,t){return function(...n){if(e.apply(this,n))return t.apply(this,n)}}function G(e,t){return function(...n){let r=e.apply(this,n);return u(r.then)?r.then(s=>t.call(this,s)||s):t.call(this,r)||r}}var oe=1,X=Symbol(),Y=Symbol(),T=Symbol(),R=Symbol(),se=Symbol(),P=Symbol(),ce=(e,t)=>e[t]?.forEach(n=>u(n)&&n.apply(e)),g=class extends S{constructor(t){super(),this.attachShadow({mode:"open"}),this[l].ready=t||!1,this[l].rendered=!1,a(t)&&(this.ready=!0)}get ready(){return this[l].ready}set ready(t){let n=this[l],r=n.ready;n.ready=!!t,r===!1&&n.ready===!0&&(this[h]("ready",{ready:!0}),u(this[R])&&this[R]())}get rendered(){return this[l].rendered}set rendered(t){let n=this[l],r=n.rendered;n.rendered=!!t,r===!1&&n.rendered===!0&&this[h]("render",{rendered:!0})}connectedCallback(){let t=this.getBoundingClientRect(),n=getComputedStyle(this).flexDirection,r=()=>{let{width:s,height:o}=this.getBoundingClientRect(),i=getComputedStyle(this).flexDirection;(s!==t.width||o!==t.height||i!==n)&&(u(this[se])&&this[se](s,o,s-t.width,o-t.height),t={width:s,height:o},n=i,this[h]("resize",t)),this[l]._resizeObserver=window.requestAnimationFrame(r)};r(),ce(this,X)}disconnectedCallback(){window.cancelAnimationFrame(this[l]._resizeObserver),ce(this,Y)}};g.prototype[X]=[];g.prototype[Y]=[];function Ce(e,t){let n={name:t.name.startsWith("--")?t.name:`--${C}${t.name}`,initialValue:t.initialValue??t.value??"",syntax:t.syntax??"*",inherits:t.inherits??!0};e.prototype[P]||(e.prototype[P]={}),e.prototype[P][n.name]=n}function Pe(e){if(u(e.prototype[R])){let t=e.prototype[R];e.prototype[R]=W(function(){return this.rendered=!1,this.ready},H(G(async function(){return t.apply(this)},function(n){this.rendered=n!==!1,this.rendered&&u(this[T])&&this[T]()}),oe))}if(u(e.prototype[T])){let t=e.prototype[T];e.prototype[T]=W(function(n){return n&&(this[l].rendered=!0),this.ready&&this[l].rendered},H(G(async function(...n){return t.apply(this,n)},function(){this[h]("refresh")}),oe))}}function Qe(e){Pe(e);let t=ie(e,{style:(...n)=>(n.forEach(r=>Ce(e,{...r})),t)});return t}g.RENDER=R;g.REFRESH=T;g.ONCONNECT=X;g.ONDISCONNECT=Y;var ue=e=>e.startsWith("--")?e:`--${C}${e}`;function tt(e,t,n){n=p(n)?n.name:n;let r=getComputedStyle(e).getPropertyValue(n);return(a(r)||r==="")&&t&&t.hasOwnProperty(n)?t[n].value:r}function fe(e){return e[P]||{}}function nt(e){return Object.keys(fe(e))}function _e(e,t){let n=fe(e);return t=ue(p(t)?t.name:t),n[t]}function rt(e,...t){let n="",r="";for(let s=0;s<t.length;s++){let o=_e(e,t[s]);n+=`${n?", ":""} var(${ue(o?.name||t[s])}`,r=o?.initialValue}return r&&(n+=`, ${r}`),n+=")".repeat(t.length),n}var De="intersection.enter",Ue="intersection.exit",V=Symbol();function Me(e){let t=r=>this.dispatchEvent(new CustomEvent(r,{bubbles:!0,cancelable:!0,composed:!0})),n=!1;this[V]&&this[V].disconnect(),this[V]=new IntersectionObserver(r=>{r.forEach(s=>{s.isIntersecting&&s.intersectionRatio>=e?n||(n=!0,t(De)):(n=!1,t(Ue))})},{root:null,rootMargin:"0px",threshold:Array(21).fill(0).map((r,s)=>s*.05)}),this[V].observe(this._el||this)}var J=Me;var le=Symbol();function ft(e){e.attr({name:"intersection-once-class",type:A,value:""}).attr({name:"intersection-class",type:A,value:""}).attr({name:"intersection-ratio",type:y,value:0,posUpdate:Ie})}var ae=(e,t)=>t&&t.split(/\s+/).forEach(n=>e.add(n)),Fe=(e,t)=>t&&t.split(/\s+/).forEach(n=>e.remove(n)),pe=(e,t)=>{t.preventDefault();let n=()=>{e.removeEventListener("render",n),e[h](t.type,t.detail,t.composed)};e.addEventListener("render",n)};function Ie(){let e=this[l];if(this[le])return J.call(this,e.intersectionRatio);this[le]=!0;let t=this.classList;this.addEventListener("intersection.enter",n=>{ae(t,e.intersectionOnceClass),ae(t,e.intersectionClass),this.rendered||pe(this,n)}),this.addEventListener("intersection.exit",n=>{Fe(t,e.intersectionClass),this.rendered||pe(this,n)}),J.call(this,e.intersectionRatio)}export{g as Base,$ as CHANGE,C as COMPONENT_PREFIX,l as CONTEXT,P as CSS_PROPS,h as FIRE_EVENT,X as ONCONNECT,Y as ONDISCONNECT,T as REFRESH,R as RENDER,se as RESIZE,S as Simple,Qe as define,nt as getCSSProperties,_e as getCSSProperty,fe as getCSSPropertyDescriptors,tt as getCSSPropertyValue,rt as getCSSVar,ft as intersectionCoreExtension};