grapper
Version:
Data Visualization Microframework
1 lines • 10.5 kB
JavaScript
/* grapper - 1.0.1 [module:core] */ var he="function",K="undefined",E="object",A="string",D="array",y="number",g="boolean",de="date";var M=(e,t)=>typeof e===t,me=(e,t)=>e instanceof t,p=e=>M(e,E),x=e=>M(e,A),u=e=>M(e,he);var q=e=>!Number.isNaN(e),a=e=>M(e,K);var ye=e=>Array.isArray(e),B=e=>me(e,Date)&&!isNaN(e),d=e=>e===null,Q=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 Z(e){if(x(e))return e.trim().startsWith("[")?(e.match(/\[(.*?)[^\]]]/g)||[]).map(t=>Z(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 Z(e);if(t===E)return Ee(e);if(a(t)||t===y){if(a(e)||e==="")return;let r=+e;if(q(r)||t===y)return r}if(a(t)||t===g){if(e==="true")return!0;if(e==="false")return!1;if(t===g)return e==="0"?!1:!!e}if(t===de){try{let r=new Date(e);if(q(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 j=new WeakSet,w=!1,v=(e,t)=>!p(e)||d(e)||!u(t)?e:function n(r){if(j.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)&&B(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}),B(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 j.add(s),s}(e);v.stop=()=>w=!0;v.start=()=>w=!1;var U=v;var b=!1,I=!0;function Ne(e){return e===null?null:e.constructor?new e.constructor:{}}function F(e){if(!p(e))return e;let t=e===null?null:Object.assign(Ne(e),e);for(let n in t)p(t[n])&&(t[n]=F(t[n]));return t}function ee(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 I;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 J=f[_];if(!o(i[J],c[J]))return b}}return I}function o(i,c){if(i===c)return I;let f=typeof i;return f!==typeof c?b:f===y&&isNaN(i)&&isNaN(c)?I:f===E?s(i,c):b}return o(e,t)}var C=globalThis.GRAPHANE_PREFIX||"g-",l=Symbol(),$=Symbol(),h=Symbol(),k=Object.defineProperty;function ge(e,t,n,r=!1){if(!(e.ready===!1||!t))if(r)n?e.setAttribute(t,""):e.removeAttribute(t);else{let s=d(n)||a(n)?"":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)?F(n[r]):s}else r in this[l]||(this[l][r]=F(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=Q(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;k(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;k(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===g?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){k(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&&(U.stop(),t=e.schema.normalize(t),U.start()),!(!p(t)&&ee(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)&&ge(this,e.attribute,t,e.type===g),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 g:return!!t[e.name];case E:case D:return U(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 z(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 G(e,t){return function(...n){if(e.apply(this,n))return t.apply(this,n)}}function H(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,W=Symbol(),X=Symbol(),T=Symbol(),R=Symbol(),se=Symbol(),P=Symbol(),ce=(e,t)=>e[t]?.forEach(n=>u(n)&&n.apply(e)),N=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,W)}disconnectedCallback(){window.cancelAnimationFrame(this[l]._resizeObserver),ce(this,X)}};N.prototype[W]=[];N.prototype[X]=[];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]=G(function(){return this.rendered=!1,this.ready},z(H(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]=G(function(n){return n&&(this[l].rendered=!0),this.ready&&this[l].rendered},z(H(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}N.RENDER=R;N.REFRESH=T;N.ONCONNECT=W;N.ONDISCONNECT=X;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",Me="intersection.exit",V=Symbol();function Ue(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(Me))})},{root:null,rootMargin:"0px",threshold:Array(21).fill(0).map((r,s)=>s*.05)}),this[V].observe(this._el||this)}var Y=Ue;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:Fe})}var ae=(e,t)=>t&&t.split(/\s+/).forEach(n=>e.add(n)),Ie=(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 Fe(){let e=this[l];if(this[le])return Y.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=>{Ie(t,e.intersectionClass),this.rendered||pe(this,n)}),Y.call(this,e.intersectionRatio)}export{N as Base,$ as CHANGE,C as COMPONENT_PREFIX,l as CONTEXT,P as CSS_PROPS,h as FIRE_EVENT,W as ONCONNECT,X 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};