text: !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).funcyjs={})}(this,function(e){"use strict";const t=new(WeakMap||Map);let o;const n=(e,n)=>(...s)=>{if(void 0===o)throw new Error("Hook was called outside of run()!");const r=t.get(o);return r.hookStateIndex++,void 0===r.hookStates[r.hookStateIndex]&&(r.hookStates[r.hookStateIndex]={value:void 0},r.hookStates[r.hookStateIndex].hookApi=((e,t)=>{const n=t.hookStates[t.hookStateIndex];return{onCleanUp(e){n.cleanUp=e},beforeNextRun(e){n.beforeNextRun=e},afterCurrentRun(e){n.afterCurrentRun=e},getContext:()=>o,getValue:e=>(void 0===n.value&&(n.value=e),n.value),setValue(o,s=!1){let r=n.value;n.value=o,!s&&t.onValueChange&&t.onValueChange(e,o,r)}}})(e,r)),n(r.hookStates[r.hookStateIndex].hookApi,...s)};function s(e,t){for(const o of t)o[e]&&(o[e](),o[e]=void 0)}const r=(e,o)=>{if(!(e instanceof Object))throw new Error("Context must be an object!");t.set(e,{hookStates:[],hookStateIndex:-1,onValueChange:o})},a=e=>{const o=t.get(e);s("cleanUp",o.hookStates),o.hookStates.length=0,o.delete(e)},i=n("useReducer",({getValue:e,setValue:t},o,n)=>{const s=e(n);return[s,e=>{t(o(s,e))}]}),u=n("useEffect",({getValue:e,setValue:t,onCleanUp:o,afterCurrentRun:n},s,r)=>{let{values:a,cleanUp:i}=e({}),u=!1;if(a!==r&&a&&a.length>0){u=!0;let e=a.length;for(;e--;)if(r[e]!==a[e]){u=!1;break}a=r}u||(i&&i(),n(()=>{i=s(),t({values:r,cleanUp:i}),o(i?()=>{i()}:void 0)}))}),d=new Map;let h=!1;const c=[],l=e=>((e,n,...r)=>{if(void 0!==o)throw new Error("Tried to start a run before the end of the previous run!");if(!t.has(e))throw new Error("Tried to start a run without a registered context!");o=e;const a=t.get(o);a.hookStateIndex=-1,s("beforeNextRun",a.hookStates);const i=n(...r),u=e=>(s("afterCurrentRun",a.hookStates),o=void 0,e);return i instanceof Promise?i.then(u):u(i)})(e,e.render),p=async()=>{const e=c.length;h=!0,Promise.resolve().then(async()=>{let t=e;for(;t--;)await l(c[e-t-1]);c.splice(0,e),h=!1,c.length>0&&p()})},f=(e,t)=>{(-1===c.indexOf(e)&&!0===e._isConnected||t)&&c.push(e),h||p()},C=e=>{const t=d.get(e);return d.delete(e),t};let g=1e5;const k=(e,t)=>{(e instanceof NodeList?t.contains(e[0]):t.contains(e))||(t.innerHTML="",e instanceof NodeList?e.forEach(e=>t.appendChild(e)):t.appendChild(e))},S=new Map;const v=n("useAttribute",(e,{getContext:t})=>{const o=t();return[o.getAttribute(e),t=>{o.skipQueue=!0,o.setAttribute(e,t)}]}),w=n("useCSS",(e,...t)=>{const{getContext:o}=t.pop();let n;n=(n=e instanceof Array?e.map((e,o)=>t[o]?e+t[o]:e).join(""):e).replace(/ +(?= )/g,"").replace(/\n/g,"");const s=o()._shadowRoot,r=document.createElement("style");r.innerHTML=n,u(()=>(s.appendChild(r),()=>{s.removeChild(r)}))}),x=n("useExposeMethod",(e,t,{getContext:o})=>{o()[e]=((...e)=>t(...e))}),b=n("useRenderer",(e,{getContext:t,getState:o})=>{const n=o(e);t()._renderer=n}),m=n("useHostElement",({getContext:e})=>e()),_=n("useShadowRoot",({getContext:e})=>e()._shadowRoot),R=n("useConnectedState",({getContext:e})=>{return e()._isConnected});e.defineComponent=((e,t,o={})=>{S.has(e)?console.warn(`Component ${e} was already defined.`):(S.set(e,t),function(e,t={}){customElements.define(e,class extends HTMLElement{constructor(){super(),this._props={},this._renderer=k,this._isConnected=!1,r(this,(e,t,o)=>{"useReducer"===e&&t!==o&&f(element)})}connectedCallback(){this._shadowRoot||(this._shadowRoot=this.attachShadow({mode:"open",...t.shadowOptions?t.shadowOptions:{}})),this._isConnected||(this._isConnected=!0,f(this))}disconnectedCallback(){this._isConnected&&(this._isConnected=!1,f(this))}destroy(){this.parentElement.removeChild(this),a(this)}async render(){const t=this.getAttribute("data-props");t&&(this._props=C(t),this.skipQueue=!0,this.removeAttribute("data-props"));const o=await Promise.resolve().then(()=>S.get(e)(this._props));await this._renderer(o,this._shadowRoot),this.init=!1}attributeChangedCallback(e,t,o){this.init||(this.skipQueue||t===o||f(this),this.skipQueue=!1)}static get observedAttributes(){let e=["data-props"];return t.observedAttributes&&(e=e.concat(t.observedAttributes)),e}})}(e,o))}),e.prps=(e=>{return{"data-props":(e=>{let t=g.toString(16);return g++,t.length%2&&(t="0"+t),d.set(t,e),t})(e)}}),e.createHook=n,e.useReducer=i,e.useState=(e=>{const[t,o]=i((e,t)=>t.value,e);return[t,e=>o({type:"set_state",value:e})]}),e.useEffect=u,e.useAttribute=v,e.useCSS=w,e.useExposeMethod=x,e.useRenderer=b,e.useHostElement=m,e.useShadowRoot=_,e.useConnectedState=R,Object.defineProperty(e,"__esModule",{value:!0})});
  //# sourceMappingURL=core.min.js.map
  