ouider 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,4 +1,24 @@
1
- 'use strict';var k=require('route-parser');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var k__default=/*#__PURE__*/_interopDefault(k);var A=(s,e,t,n)=>{for(var o=e,c=s.length-1,i;c>=0;c--)(i=s[c])&&(o=(i(o))||o);return o};var T=class{constructor(e){this.events=e;}emit(e,...t){let n=this.events[e];n&&n(...t);}};var P=class{components=new Map;register(e,t){let n=e.toLocaleLowerCase();if(this.components.has(n)){console.warn(`[OUID] - ${n} component already registered`);return}console.debug("Registering new component: "+e,t),this.components.set(n,t);}unregister(e){let t=e.toLocaleLowerCase();this.components.delete(t);}get(e){return this.components.get(e.toLocaleLowerCase())}getAll(){return Array.from(this.components.entries())}},x=new P;var v=class{constructor(e){this.value=e;}};function E(s){return typeof s=="object"&&!Array.isArray(s)&&"value"in s&&s instanceof v}function B(s,e){let t=(n,o=new Map)=>{if(o.has(n))return o[n];let c=new Proxy(n,{set:(i,r,a)=>{let p=i[r];return typeof a=="object"?i[r]=t(a):i[r]=a,e.didChange(r,p,a),true},get:(i,r)=>Reflect.get(i,r)});o[n]=c;for(let i=n;i;i=Object.getPrototypeOf(i))Object.keys(i).forEach(r=>{let a=n[r];typeof a=="object"&&(n[r]=t(a,o));});return c};if(typeof s=="function")throw new Error("Can't create reactive element over a function");return typeof s!="object"&&typeof s!="symbol"?new Proxy(new v(s),{set:(n,o,c)=>{if(o!=="value")throw new Error(`Undefined property ${String(o)} access`);let i=n[o];return n[o]=c,e.didChange(o,i,c),true},get:(n,o)=>{if(o!=="value")throw new Error(`Undefined property ${String(o)} access`);return n[o]}}):new v(t(s))}var C=class{THRESHOLD_TIME=50;debounceTime=new Date().getTime();state;listeners=[];timer=null;constructor(e){this.state=new Proxy(e,{set:(t,n,o)=>{let c=t[n];return t[n]=o,this.didChange(n,c,o),true},get:(t,n)=>t[n]});}wrap(e){return B(e,this)}has(e){return e in this.state}setValue(e,t){this.state[e]=t;}getValue(e){return this.state[e]}get value(){return this.state}dispatchChanges(e,t,n){for(let o of this.listeners)o(e,t,n);}didChange(e,t,n){let o=Date.now();o-this.debounceTime<=this.THRESHOLD_TIME&&clearTimeout(this.timer),this.debounceTime=o,this.timer=setTimeout(()=>{this.dispatchChanges(e,t,n);},this.THRESHOLD_TIME);}watch(e){return this.listeners.push(e),this.listeners.length-1}unwatch(e){if(typeof e=="number"){this.listeners.splice(e,1);return}this.listeners.splice(this.listeners.indexOf(e),1);}};function _(s){return function(e){let t=class extends e{template=s.template;css=s.css};console.log("Construct",s.css);let n=t;return x.register(s.tag,n),t}}function b(s,e,t){return new s(e,t)}var O=class{state;parent=void 0;emits;props;provides=new Map;constructor(e={},t={}){this.state=new C(this),this.props=e,this.emits=new T(t);}onMounted(){}willMount(){}willUnmount(){}provide(e,t){this.provides.set(e,t);}inject(e){let t=this;for(;t;){if(t.provides.has(e))return t.provides.get(e);t=t.parent;}}};function N(s){let e=document.createElement("style");return console.log("css:",s),e.innerHTML=s,document.head.appendChild(e),e}function S(s){s&&document.head.removeChild(s);}function U(s){return s.replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}function h(s){return E(s)?s.value:s}function F(s){let e={};for(let t=s;t;t=Object.getPrototypeOf(t))Object.getOwnPropertyNames(t).forEach(n=>{let o=s[n];typeof o=="function"&&n!=="constructor"&&!n.startsWith("__")&&!n.endsWith("__")?n in e||(e[n]=o.bind(s)):n!=="constructor"&&!n.startsWith("__")&&!n.endsWith("__")&&(n in e||(e[n]=o));});return e}function G(s){return typeof s=="function"&&!("prototype"in s)}var g=class s{constructor(e,t,n,...o){this.app=e;this.component=t;this.parentContext=n;for(let c of o)this.stack.push(c);}static PROVIDE_TOKEN="RENDER_CONTEXT";bindings=[];directives=[];mountedComponents=new WeakMap;stack=[];get hostElement(){return this.component._hostElement}bind(e){this.bindings.push(e);}directive(e){this.directives.push(e);}evaluateExpression(e){return this.resolve(e)}resolve(e,t=true,...n){let o=this.component.state.value,i={...F(o)};for(let r of [...this.stack.toReversed(),...n])Object.assign(i,r);try{let r=`${t?'"use strict";':""}return ${e};`,a=new Function(...Object.keys(i),r);return a.bind(this.component),a.apply(this.component,Object.values(i))}catch(r){console.log(this),console.error(r);}}updateValue(e,t){e.split(/[\.\[]/)[0]in this.component?this.resolve(`this.${e}=__o_model_value__`,true,{__o_model_value__:t}):this.resolve(`${e}=__o_model_value__`,true,{__o_model_value__:t}),this.component.state.didChange("","","");}push(e){this.stack.unshift(e);}pop(){this.stack.shift();}updateBindings(){this.bindings.forEach(e=>this.updateBinding(e));}updateBinding(e){if(e.type==="model")e.node.value=h(e.context.resolve(e.key));else if(e.type==="interpolation")e.node.textContent=e.template?.replace(/\{\{(.*?)\}\}/g,(t,n)=>(n=n.trim(),h(e.context.resolve(n))))??"";else if(e.type==="attribute"){let t=e.key,n=h(this.resolve(e.template));t==="class"?this.expandClass(e.node,n):t==="style"?this.expandStyle(e.node,n):typeof n!="object"&&typeof n!="function"&&typeof n!="symbol"&&typeof n<"u"&&e.node.setAttribute(t,n.toString());}else if(e.type==="prop"&&e.context.component){let t=h(this.resolve(e.template));try{console.log({...e.context.component}),e.context.component.props[e.key]=t,e.context.updateBindings(),e.context.updateDirectives();}catch(n){console.error(n);}}}updateDirectives(){for(let e of this.directives){if(e.type==="if"){let t=false;try{t=e.context.evaluateExpression(e.expr),E(t)&&(t=t.value);}catch(n){console.error("Error:",n);}t?e.active!==true&&(e.active=true,e.placeholder.after(e.node),e.context.render(e.node),e.context.updateBindings()):t||e.active!==false&&(this.unmountComponent(e.node),e.node.remove(),e.active=false);}if(e.type==="for"){console.log("Start for directive",e);let t=e.children??new Map,n=new Map,o=(r,a)=>e.key?h(e.context.resolve(e.key,true,{[e.item]:r})):a,c=h(e.context.resolve(e.list))||[];console.log("For-directive",c);let i=e.placeholder;c.forEach(async(r,a)=>{let p=o(r,a),d=t.get(p),l=d?.node,m={[e.item]:r},u=d?.ctx??new s(this.app,this.component,null);u.stack=[m,...e.context.stack],l?(u.updateBindings(),u.updateDirectives()):(l=e.node.cloneNode(true),u.render(l),i.after(l),u.updateBindings(),u.updateDirectives()),i=l,n.set(p,{node:l,ctx:u});}),t.forEach((r,a)=>{n.has(a)||(this.unmountComponent(r.node),r.node.remove());}),e.children=n;}}}render(e){switch(e.nodeType){case Node.TEXT_NODE:this.handleTextNode(e);break;case Node.ELEMENT_NODE:this.handleElementNode(e);break;default:console.warn("Unknown node",e);}}expandClass(e,t){let n=t;typeof t=="object"&&(Array.isArray(t)?n=t.join(" "):n=Object.keys(t).filter(o=>t[o]).join(" ")),e.setAttribute("class",n);}expandStyle(e,t){let n=t;typeof t=="object"&&!Array.isArray(t)&&(n=Object.keys(t).map(o=>`${o}: ${t[o]}`).join(";")),e.setAttribute("style",n);}expandStandardAttributes(e){[...e.attributes].filter(t=>t.name.startsWith(":")).filter(t=>[":id",":style",":class",":placeholder",":name"].includes(t.name)).forEach(t=>{let n=t.name.substring(1);this.bind({type:"attribute",node:e,key:n,context:this,template:t.value.trim()}),e.removeAttribute(t.name);});}handleElementNode(e){let t=null;if(e.hasAttribute("o-if")){let r=e.getAttribute("o-if"),a=document.createComment("o-if:"+r);e.parentNode?.insertBefore(a,e),e.removeAttribute("o-if"),this.directive({type:"if",expr:r,node:e,placeholder:a,context:this,active:void 0}),t="if";}if(e.hasAttribute("o-for")){if(t==="if")throw new Error("Can't have o-if and o-for on the same component");let r=e.getAttribute("o-for"),[a,p]=r.split(" of ").map(m=>m.trim()),d=document.createComment("for:"+r),l=e.getAttribute(":key");e.parentNode?.insertBefore(d,e),e.removeAttribute("o-for"),e.removeAttribute(":key"),e.remove(),this.directive({type:"for",item:a,list:p,node:e,placeholder:d,context:this,key:l}),t="for";}let n=e.tagName.toLowerCase(),o=x.get(n);t!=="for"&&[...e.attributes].forEach(r=>{if(r.name==="o-model"){let a=r.value.trim();if(e.tagName==="INPUT"||e.tagName==="TEXTAREA"){let p=e;p.value=h(this.resolve(a)),p.addEventListener("input",d=>{let l=d.target.value;this.updateValue(a,l);}),this.bind({node:e,key:a,type:"model",context:this});}e.removeAttribute(r.name);}});let c={},i={};if(t!=="for"){let{props:r,events:a}=this.componentAttributes(e,this);c=r,i=a,this.expandStandardAttributes(e);}if(Object.keys(i).forEach(r=>{let a=i[r];o||e.addEventListener(r,p=>{typeof a=="function"&&a.apply(this.component,[p]);}),e.removeAttribute("@"+r);}),!t){if(o){this.mountComponent(e,o,this,c,i);return}[...e.childNodes].forEach(r=>this.render(r));}}handleTextNode(e){let t=e.textContent?.match(/\{\{(.*?)\}\}/g);t&&t.forEach(n=>{let o=n.replace(/[{}]/g,"").trim();this.bind({type:"interpolation",node:e,key:o,template:e.textContent,context:this});});}componentAttributes(e,t){let n={},o={},c=["import","interface","module","o-model","o-if","o-for"];return [...e.attributes].filter(i=>!c.includes(i.name)).forEach(i=>{let r=i.name;if(r.startsWith("@")){let d=t?.resolve(i.value,true);if(typeof d!="function")throw new Error("Event handler can only be function");r=r.substring(1),o[r]=d;return}let a=null,p=i.value;r.startsWith(":")&&(a=i.value,r=r.substring(1),p=t?.resolve(i.value),E(p)&&(p=p.value)),r=U(r),n[r]={name:r,value:p,expr:a};}),{props:n,events:o}}async mountComponent(e,t,n,o={},c={}){let i=document.createElement("div"),r=new s(this.app,null,null),a={};Object.keys(o).forEach(u=>{let f=o[u];f.expr&&this.bind({type:"prop",node:i,key:u,context:r,template:f.expr}),a[u]=f.value;});let p=await s.h(t,a,c);r.component=p,r.stack=[p.props],Object.keys(o).filter(u=>!o[u].expr).forEach(u=>i.setAttribute(u,o[u].value)),i.classList.add("o-component-host"),e.tagName.toLowerCase()!=="div"&&i.classList.add("c-"+e.tagName.toLowerCase()),p.willMount(),i.innerHTML=p.template.trim(),p.css&&(p.cssInstance=N(p.css));let d=Array.from(e.childNodes),l=i.querySelectorAll("o-slot");l&&l.forEach(u=>{let f=u.getAttribute("name");d.filter(y=>f?f&&y.nodeType===Node.ELEMENT_NODE&&y.getAttribute("slot")===f:y.nodeType!==Node.ELEMENT_NODE||!y.hasAttribute("slot")).forEach(y=>u.parentNode?.insertBefore(y,u));});let m=i;e.innerHTML="",e.appendChild(i),p.state.watch(()=>{r.updateBindings(),r.updateDirectives();}),p._hostElement=m,p.parent=n?.component??void 0,p.provide(s.PROVIDE_TOKEN,this),r.render(m),r.updateBindings(),r.updateDirectives(),this.mountedComponents.set(m,p),p.onMounted();}unmountComponent(e){let t=this.mountedComponents.get(e);t&&(S(t.cssInstance),t.willUnmount(),t._hostElement=null),e.querySelectorAll("*").forEach(n=>{this.unmountComponent(n);}),this.mountedComponents.delete(e);}static h(e,t,n){return G(e)?e().then(o=>b(o.default,t,n)):b(e,t,n)}};function W(s){return typeof s=="function"}var R=class s{constructor(e){this.root=e;s.currentApp=this;}static currentApp=null;providers=new Map;provide(e,t){if(this.providers.has(e)){console.warn(`[OUID] - Provider ${e} already exists`);return}this.providers.set(e,W(t)?{provide:t}:{value:t});}inject(e){return this.providers.get(e).value}use(e){return e.install(this),this}host;mount(e){let t=document.getElementById(e);if(!t)throw new Error("No selector found for "+e);this.host=t;let n=new g(this,null,null);n.mountComponent(this.host,this.root,null).then(()=>{n.updateBindings(),n.updateDirectives();});}};function de(s,e){R.currentApp.provide(s,e);}function j(s){return R.currentApp.inject(s)}exports.RouterComponent=class w extends O{routeStateHander=null;router;willMount(){}onMounted(){this.router=V(),console.log("Router mounted"),this.routeStateHander=this.router.bind(this),this.routeStateHander();}willUnmount(){console.log("Router will unmount"),this.router.unbind(this.routeStateHander);}};exports.RouterComponent=A([_({tag:"o-router",template:`
1
+ import it from'route-parser';var Q=Object.defineProperty;var at=(a,t,e)=>t in a?Q(a,t,{enumerable:true,configurable:true,writable:true,value:e}):a[t]=e;var d=(a,t)=>Q(a,"name",{value:t,configurable:true});var l=(a,t,e)=>at(a,typeof t!="symbol"?t+"":t,e);var $=class ${constructor(){l(this,"components",new Map);}register(t,e){console.log(`[OUID] - Registering component: ${t}`);let n=t.toLocaleLowerCase();if(this.components.has(n)){console.warn(`[OUID] - ${n} component already registered`);return}this.components.set(n,e);}unregister(t){let e=t.toLocaleLowerCase();this.components.delete(e);}get(t){return this.components.get(t.toLocaleLowerCase())}has(t){return this.components.has(t)}getAll(){return Array.from(this.components.entries())}};d($,"ComponentsRegistry");var _=$,T=new _;var H=class H{constructor(t){l(this,"events");this.events=t;}emit(t,...e){let n=this.events[t];console.log("Emitting event",t,n),n&&n(...e);}};d(H,"Emits");var M=H;var q=class q{constructor(t){l(this,"value");this.value=t;}};d(q,"Stated");var j=q;function tt(a){return typeof a=="object"&&!Array.isArray(a)&&"value"in a&&a instanceof j}d(tt,"isStated");function ct(a,t){let e=d((n,s=new Map)=>{if(s.has(n))return s.get(n);let o=new Proxy(n,{set:d((c,h,p)=>{let y=c[h];return typeof p=="object"?c[h]=e(p):c[h]=p,t.didChange(h,y,p),true},"set"),get:d((c,h)=>Reflect.get(c,h),"get")});s.set(n,o);for(let c=n;c;c=Object.getPrototypeOf(c))Object.keys(c).forEach(h=>{let p=n[h];typeof p=="object"&&(n[h]=e(p,s));});return o},"proxify");if(typeof a=="function")throw new Error("Can't create reactive element over a function");return typeof a!="object"&&typeof a!="symbol"?new Proxy(new j(a),{set:d((n,s,o)=>{if(s!=="value")throw new Error(`Undefined property ${String(s)} access`);let c=n[s];return n[s]=o,t.didChange(s,c,o),true},"set"),get:d((n,s)=>{if(s!=="value")throw new Error(`Undefined property ${String(s)} access`);return n[s]},"get")}):new j(e(a))}d(ct,"stated");var W=class W{constructor(t){l(this,"THRESHOLD_TIME",50);l(this,"debounceTime",new Date().getTime());l(this,"state");l(this,"listeners",[]);l(this,"timer",null);this.state=new Proxy(t,{set:d((e,n,s)=>{let o=e[n];return e[n]=s,this.didChange(n,o,s),true},"set"),get:d((e,n)=>e[n],"get")});}wrap(t){return ct(t,this)}has(t){return t in this.state}setValue(t,e){this.state[t]=e;}getValue(t){return this.state[t]}get value(){return this.state}dispatchChanges(t,e,n){for(let s of this.listeners)s(t,e,n);}async didChange(t,e,n){let s=Date.now();s-this.debounceTime<=this.THRESHOLD_TIME&&this.timer&&await OUID.clearTimeout(this.timer),this.debounceTime=s,this.timer=await OUID.setTimeout(()=>{this.dispatchChanges(t,e,n);},this.THRESHOLD_TIME);}watch(t){return this.listeners.push(t),this.listeners.length-1}unwatch(t){if(typeof t=="number"){this.listeners.splice(t,1);return}this.listeners.splice(this.listeners.indexOf(t),1);}};d(W,"State");var k=W;var lt=0;function nt(a){return function(t){var s;let e=(s=class extends t{constructor(){super(...arguments);l(this,"template",a.template);l(this,"css",a.css);l(this,"tag",a.tag);l(this,"use",a.use);l(this,"hostClasses",a.hostClasses);l(this,"hash","component-"+lt+"-"+a.tag);}},d(s,"WithDecoration"),s),n=e;return n.tag=a.tag,e}}d(nt,"Component");var V=class V{constructor(t,e=[]){l(this,"node");l(this,"children");this.node=t,this.children=e;}attachTo(t){if(typeof this.node=="string"){t.innerHTML=this.node;return}let e=this.node;for(let n of this.children)n.attachTo(e);t.appendChild(e);}static of(t,e=[]){return new V(t,e)}addChild(t){return this.children.push(t),this}};d(V,"RenderNode");var P=V,S=class S{constructor(t,e){l(this,"data");l(this,"css");this.data=t,this.css=e;}toString(){let t=this.css?this.css+`
2
+ `:"";for(let e in this.data){let n=this.data[e];typeof n=="string"?t+=`${e} { ${n} }
3
+ `:n instanceof S&&(t+=`${e} {
4
+ ${n.toString()}}
5
+ `);}return t}static of(t,...e){return new S(t,e.join(`
6
+ `))}};d(S,"StyleData");var et=S;function F(a,t,e){return new a(t,e)}d(F,"createComponent");var J=class J{constructor(t={},e={}){l(this,"state");l(this,"parent");l(this,"emits");l(this,"props");l(this,"provides",new Map);this.state=new k(this),this.props=t,this.emits=new M(e);}onMounted(){}willMount(){}willUnmount(){}provide(t,e){this.provides.set(t,e);}inject(t){let e=this;for(;e;){if(e.provides.has(t))return e.provides.get(t);e=e.parent;}}decorateHostElement(t){return Promise.resolve()}};d(J,"OComponent");var U=J;function N(a){let t=Date.now();return `${(1e3+Math.floor(Math.random()*9e3)+a.length).toString(16)}-${t.toString(16)}`}d(N,"generateUIID");(function(a){var c,h,p,y,m;let t=(c=class{constructor(){l(this,"actions",[]);}async exec(){}add(i){return this.actions.push(i),this}async commit(){let i=this.actions;this.actions=[],await Promise.all(i.map(async r=>await r()));}},d(c,"BatchActions"),c);a.BatchActions=t;let e=(h=class{constructor(i){l(this,"node");l(this,"operations",[]);this.node=i;}async exec(){let i=this.operations.map(r=>typeof r=="object"?this.node[r.fn].apply(this.node,r.args):Promise.resolve(r()));try{await Promise.all(i);}catch{console.error("Error while batch updates");}}append(i,...r){return this.operations.push({fn:i,args:r}),this}add(i){return this.operations.push(i),this}addEventListener(i,r){return this.append("addEventListener",i,r)}setProperty(i,r){return this.append("setAttribute",i,r)}dettachEventListener(i,r){return this.append("dettachEventListener",i,r)}invoke(i,...r){return this.append("invoke",i,...r)}dispatchEvent(i,r,u){return this.append("dispatchEvent",i,r,u)}addClass(...i){return this.append("addClass",...i)}removeClass(...i){return this.append("removeClass",...i)}setAttribute(i,r){return this.append("setAttribute",i,r)}removeAttribute(i){return this.append("removeAttribute",i)}appendChild(i){return this.append("appendChild",i)}removeChild(i){return this.append("removeChild",i)}remove(){return this.append("remove")}removeAndRelease(){return this.append("removeAndRelease")}release(){return this.append("release")}innerHTML(i){return this.append("setHTML",i)}replaceChildNode(i,r){return this.append("replaceChildNode",i,r)}replaceWith(i){return this.append("replaceWith",i)}after(i){return this.append("after",i)}setInnerText(i){return this.append("setInnerText",i)}setContentText(i){return this.append("setContentText",i)}insertBefore(i,r){return this.append("insertBefore",i,r)}setInputValue(i){return this.append("setInputValue",i)}setStyle(i,r){return this.append("setStyle",i,r)}},d(h,"BatchUpdates"),h);a.BatchUpdates=e;let n=(p=class{constructor(i,r){l(this,"uid");l(this,"tag");this.uid=i,this.tag=r;}async addEventListener(i,r){return f.addEventListener(this,i,r)}async dettachEventListener(i,r){await f.dettachEventListener(this,i,r);}async invoke(i,...r){await f.call("invokeObjectMethod",this.uid,i,...r);}async getProperty(i){return await f.call("getObjectProperty",this.uid,i)}async setProperty(i,r){await f.call("setObjectProperty",this.uid,i,r);}async dispatchEvent(i,r,u){await f.call("dispatchEvent",this.uid,i,r,u);}},d(p,"OObject"),p);a.OObject=n;let s=(y=class extends n{constructor(r){super(r.uid,r.tag);l(this,"textContent");l(this,"type","Unknown");l(this,"attributes");l(this,"children");l(this,"classes");l(this,"style");for(let u in r)this[u]=r[u];this.attributes??(this.attributes=[]),this.classes??(this.classes=[]),this.style??(this.style="");}},d(y,"ONode"),y);a.ONode=s;let o=(m=class extends s{constructor(r){super(r);l(this,"_hydrated",false);}async addClass(...r){await f.call("addClass",this.uid,...r);}async removeClass(...r){await f.call("removeClass",this.uid,...r);}async setAttribute(r,u){let v=await f.call("setAttribute",this.uid,r,u);v&&(this.attributes=v);}async removeAttribute(r){let u=await f.call("removeAttribute",this.uid,r);u&&(this.attributes=u);}async appendChild(r){await f.call("appendChild",this.uid,r.uid);}set innerHTML(r){this.setHTML(r);}async cloneNode(r){let u=await f.call("cloneNode",this.uid,r);return u?new m(u):null}async remove(){await f.call("removeNode",this.uid);}async removeAndRelease(){await this.remove(),await this.release();}async removeChild(r){await f.call("removeChild",this.uid,r.uid);}async replaceChildNode(r,u){await f.call("removeChild",this.uid,r.uid,u.uid);}async replaceWith(r){await f.call("replaceWith",this.uid,r.uid);}async after(r){await f.call("insertAfter",this.uid,r.uid);}async setHTML(r){await f.call("setInnerHTML",this.uid,r);}async HTML(){return await f.call("getInnerHTML",this.uid)??""}async setInnerText(r){await f.call("setInnerText",this.uid,r);}async setContentText(r){await f.call("setContentText",this.uid,r);}async getContentText(){return await f.call("getContentText",this.uid)??""}async content(){try{return await f.call("getInnerText",this.uid)??""}catch(r){return console.error(r),""}}async childNodes(){return (await f.call("childNodes",this.uid))?.map(r=>new m(r))??[]}hasAttribute(r){return !!this.attributes.find(u=>u.name===r)}async getAttribute(r){return await f.call("getAttribte",this.uid,r)??""}attribute(r){return this.attributes.find(u=>u.name===r)?.value??null}async nextSibling(){let r=await f.call("nextSibling",this.uid);return r?new m(r):null}async getAttributeNames(){return await f.call("getAttributeNames",this.uid)??[]}async parentNode(){let r=await f.call("parentNode",this.uid);return r?new m(r):null}async insertBefore(r,u){await f.call("insertBefore",this.uid,u.uid,r.uid);}async setInputValue(r){await f.call("setInputValue",this.uid,r);}async inputValue(r){return await f.call("inputValue",this.uid,r)??""}get hydrated(){return this._hydrated}hydrate(){this._hydrated=true,this.addClass("hydrated");}async query(r,u){return await f.query(r,u,this.uid)}async queryAll(r,u){return await f.queryAll(r,u,this.uid)}async release(){await f.call("releaseNode",this.uid);}async setStyle(r,u){await f.call("setStyle",this.uid,r,u);}updates(){return new e(this)}},d(m,"OElement"),m);a.OElement=o;})(b||(b={}));function Rt(){return function(a,t,e){e.value;e.value=async(...s)=>{let o=s[0];try{let c=await f.invoke(t,[{props:o.getSafePropsForNative}]);console.log("result from native function"),o.setSafePropsFromNative;}catch{console.error("Failed to invoke native function");}};}}d(Rt,"Native");var Y=class Y{constructor(){l(this,"callbacks",new Map);l(this,"DOM_EVENT_LISTENERS",new Map);l(this,"timers",new Map);l(this,"_config");l(this,"listeners",new Map);this.subscribe("__ouid_native_event_success__",(t,e)=>{let n=this.callbacks.get(t);if(n)return this.callbacks.delete(t),n.success(...JSON.parse(e))}),this.subscribe("__ouid_native_event_error__",(t,e)=>{let n=this.callbacks.get(t);if(n)return console.error("Failure:",t,e),this.callbacks.delete(t),n.error(...JSON.parse(e))}),this.subscribe("__ouid_web_event__",(t,e)=>{let n=this.DOM_EVENT_LISTENERS.get(t);if(n){let o=JSON.parse(e)[1];return o&&(o.target=o?.target?new b.OElement(o.target):null),n(o)}});}config(t){return this._config=t,this}invoke(t,...e){let n=N(t);return new Promise((s,o)=>{this.callbacks.set(n,{success:s,error:o});try{if(!WebOUID)throw new Error("NativeOUID bridge not available");WebOUID.invoke(n,t,JSON.stringify(e));}catch(c){console.error(c),this.callbacks.delete(n);}})}registerComponent(t,e){T.register(t,e);}unregisterComponent(t,e){T.unregister(t);}async call(t,...e){try{return (await this.invoke(`_ouid_${t}`,...e)).data}catch(n){return console.error(n),null}}emit(t,e){WebOUID?.invoke("event",t,JSON.stringify(e));}subscribe(t,e){this.listeners.has(t)||(this.listeners.set(t,[]),globalThis[t]=(n,s)=>{this.listeners.get(t)?.forEach(o=>o(n,s));}),this.listeners.get(t).push(e);}async query(t,e,n){let s=await this.call("query",t,e,n);return s?new b.OElement(s):null}async queryAll(t,e,n){let s=await this.call("queryAll",t,e,n);return s?s.map(o=>new b.OElement(o)):[]}async createElement(t,e={}){let n=await this.call("createElement",t,e);return n?new b.OElement(n):null}async createComment(t){let e=await this.call("createComment",t);return e?new b.OElement(e):null}async addEventListener(t,e,n){let s=N(e+(typeof t=="string"?t:t.tag));return this.DOM_EVENT_LISTENERS.set(s,n),await f.call("attachEventListener",typeof t=="string"?t:t.uid,s,e),s}async dettachEventListener(t,e,n){this.DOM_EVENT_LISTENERS.delete(n),await f.call("dettachEventListener",typeof t=="string"?t:t.uid,n,e);}async injectComponentStyles(t){let e=await f.call("injectComponentStyles",t);return e?new b.OElement(e):null}async rejectComponentStyles(t){await f.call("rejectComponentStyles",t.uid);}async getOObject(t){let e=await f.call("getOObject",t);return e?new b.OObject(e.uid,e.tag):null}async acquireObject(t){let e=await f.call("acquireObject",t);return e?new b.OObject(e.uid,e.tag):null}async setTimeout(t,e){let n=N("setTimeout"+e);this.DOM_EVENT_LISTENERS.set(n,()=>{t();let o=this.timers.get(s);o&&(this.timers.delete(s),this.DOM_EVENT_LISTENERS.delete(o));});let s=await f.call("setTimeout",n,e)??-1;return console.log("Timer id",s),s>=0&&this.timers.set(s,n),s}async clearTimeout(t){let e=this.timers.get(t);e&&(this.timers.delete(t),this.DOM_EVENT_LISTENERS.delete(e),await f.call("clearTimeout",t));}async setInterval(t,e){let n=N("setInterval"+e);this.DOM_EVENT_LISTENERS.set(n,t);let s=await f.call("setInterval",n,e)??-1;return s>=0&&this.timers.set(s,n),s}async clearInterval(t){let e=this.timers.get(t);e&&(this.timers.delete(t),this.DOM_EVENT_LISTENERS.delete(e),await f.call("clearInterval",t));}async fetch(t,e,n="json"){return await f.call("fetch",t,e,n)}};d(Y,"OUIDBridge");var K=Y,f=new K;globalThis.OUID=f;var b;function ut(a){return a.replace(/-([a-z])/g,(t,e)=>e.toUpperCase())}d(ut,"toCamelCase");function ht(a){return a.replace(/(?!^)([A-Z])/g,(t,e)=>`-${e.toLowerCase()}`)}d(ht,"toSnakeCase");function x(a){return tt(a)?a.value:a}d(x,"normaliseValue");function dt(a){let t={};for(let e=a;e;e=Object.getPrototypeOf(e))Object.getOwnPropertyNames(e).forEach(n=>{let s=a[n];typeof s=="function"&&n!=="constructor"&&!n.startsWith("__")&&!n.endsWith("__")?n in t||(t[n]=s.bind(a)):n!=="constructor"&&!n.startsWith("__")&&!n.endsWith("__")&&(n in t||(t[n]=s));});return t}d(dt,"toObjectWithFunctions");function pt(a){return typeof a=="function"&&!("prototype"in a)}d(pt,"isLazyLoader");var E=class E{constructor(t,e,n,...s){l(this,"app");l(this,"component");l(this,"parentContext");l(this,"bindings",[]);l(this,"directives",[]);l(this,"mountedComponents",new WeakMap);l(this,"componentsRegistry",new _);l(this,"updatingDirectives",false);l(this,"updatingBindings",false);l(this,"stack",[]);l(this,"hydradationActions",new b.BatchActions);this.app=t,this.component=e,this.parentContext=n;for(let o of s)this.stack.push(o);}get hostElement(){return this.component._hostElement}bind(t){this.bindings.push(t);}directive(t){this.directives.push(t);}evaluateExpression(t){return this.resolve(t)}resolve(t,e=true,...n){if(!t)return;let s=this.component.state.value,c={...dt(s)};for(let h of [...this.stack.reverse(),...n])Object.assign(c,h);try{let h=`${e?'"use strict";':""}return ${t};`,p=Object.keys(c),y=new Function(...p,h);return y.bind(this.component),y.apply(this.component,Object.values(c))}catch(h){console.log(this,t),console.error(h);}}updateValue(t,e){t.split(/[\.\[]/)[0]in this.component?this.resolve(`this.${t}=__o_model_value__`,true,{__o_model_value__:e}):this.resolve(`${t}=__o_model_value__`,true,{__o_model_value__:e}),this.component.state.didChange("","","");}push(t){this.stack.unshift(t);}pop(){this.stack.shift();}resolveTag(t){let e=this;for(;;){if(e.componentsRegistry.has(t))return e.componentsRegistry.get(t);if(e=e?.parentContext??null,!e)break}return T.get(t)}async updateBindings(t){if(this.updatingBindings)return;let e=!t;t=t??new b.BatchActions,this.updatingBindings=true,this.bindings.forEach(n=>this.updateBinding(n,t)),e&&await t.commit(),this.updatingBindings=false;}updateBinding(t,e){if(t.type==="model")t.node.setProperty("value",x(t.context.resolve(t.key)));else if(t.type==="interpolation")e.add(async()=>{await t.node.setContentText(t.template?.replace(/\{\{(.*?)\}\}/g,(n,s)=>(s=s.trim(),x(t.context.resolve(s))))??"");});else if(t.type==="attribute"){let n=t.key,s=x(this.resolve(t.template));n==="class"?e.add(()=>this.expandClass(t.node,s)):n==="style"?this.expandStyle(t.node,s):typeof s!="object"&&typeof s!="function"&&typeof s!="symbol"&&typeof s<"u"&&e.add(()=>t.node.setAttribute(n,s.toString()));}else if(t.type==="prop"&&t.context.component){let n=x(this.resolve(t.template));try{t.context.component.props[t.key]=n,t.context.updateBindings(),t.context.updateDirectives();}catch(s){console.error(s);}}}async updateDirectives(t){if(this.updatingDirectives)return;let e=!t;this.updatingDirectives=true,t=t??new b.BatchActions;for(let n of this.directives){if(n.type==="if"){if(!x(n.context.evaluateExpression(n.expr))){if(n.active===false)continue;n.active=false,n.renderedNode&&(n.destroy?(this.unmountComponent(n.node),await n.renderedNode.removeAndRelease()):await n.renderedNode.addClass("oui-hidden"));continue}if(n.active===true)continue;n.active=true;let o=n.renderedNode;if(!o||n.destroy){let c=await n.node.cloneNode(true);n.renderedNode=c,await n.context.render(c),await n.placeholder.after(c),await n.context.hydradationActions.commit();}else await o.removeClass("oui-hidden");}if(n.type==="for"){let s=n.children??new Map,o=new Map,c=d((y,m)=>n.key?x(n.context.resolve(n.key,true,{[n.item]:y})):m,"keyFn"),h=x(n.context.resolve(n.list))||[],p=n.placeholder;for(let y=0;y<h.length;y++){let m=h[y],O=c(m,y),i=s.get(O),r,u;i?(r=i.node,u=i.ctx,console.log("Reusing entry"),u.stack=[{[n.item]:m},...n.context.stack],r.uid!==(await p.nextSibling())?.uid&&await p.after(r),await Promise.all([u.updateBindings(),u.updateDirectives()])):(u=new E(this.app,this.component,this),u.hydradationActions=this.hydradationActions,u.stack=[{[n.item]:m},...n.context.stack],r=await n.node.cloneNode(true),await u.render(r),await p.after(r),u.updateDirectives()),p=r,o.set(O,{node:r,ctx:u});}for(let[y,m]of s.entries())o.has(y)||(this.unmountComponent(m.node),t.add(()=>m.node.removeAndRelease()));n.children=o;}}e&&await t.commit(),await this.hydradationActions.commit(),this.updatingDirectives=false;}async render(t,e){if(!t.hydrated&&!(e?.skipSlotted&&t.hasAttribute("slotted"))){switch(t.type){case "Text":this.handleTextNode(t);break;case "Element":await this.handleElementNode(t,e);break;default:console.warn("Unknown node",t);}await Promise.all([this.updateBindings(),this.updateDirectives()]),this.hydradationActions.add(()=>t.hydrate());}}async expandClass(t,e){let n;typeof e=="object"?Array.isArray(e)?n=e:n=Object.keys(e).filter(s=>e[s]):n=e.toString().split(/\s+/),n.length>0&&await t.addClass(...n);}expandStyle(t,e){let n=e;typeof e=="object"&&!Array.isArray(e)&&(n=Object.keys(e).filter(s=>e[s]).map(s=>`${ht(s)}: ${e[s]}`).join(";")),n&&t.setAttribute("style",n);}expandStandardAttributes(t){let e=t.updates();[...t.attributes].filter(n=>n.name.startsWith(":")).forEach(n=>{let s=n.name.substring(1);this.bind({type:"attribute",node:t,key:s,context:this,template:n.value.trim()}),e.removeAttribute(n.name);}),e.exec();}async handleElementNode(t,e){let n=await t.parentNode(),s=null,o=t.hasAttribute("o-if")?"o-if":t.hasAttribute("o-show")?"o-show":null;if(o){let u=await t.getAttribute(o),v=await OUID.createComment(o+":"+u),w=o==="o-if";await n.insertBefore(v,t),await t.updates().removeAttribute(o).remove().exec(),this.directive({type:"if",expr:u,node:t,placeholder:v,context:this,active:void 0,destroy:w}),s="if";return}if(t.hasAttribute("o-for")){if(s==="if")throw new Error("Can't have o-if and o-for on the same component");let u=await t.getAttribute("o-for"),[v,w]=u.split(" of ").map(I=>I.trim()),g=await OUID.createComment("for:"+u),C=t.attribute(":key")??"";await n?.insertBefore(g,t),await t.updates().removeAttribute("o-for").removeAttribute(":key").remove().exec(),this.directive({type:"for",item:v,list:w,node:t,placeholder:g,context:this,key:C}),s="for";return}let c=t.tag.toLowerCase(),h=this.resolveTag(c),p=t.updates();[...t.attributes].forEach(async u=>{if(u.name==="o-model"){let v=u.value.trim();(t.tag==="input"||t.tag==="textarea")&&(p.setInputValue(x(this.resolve(v))).addEventListener("input",async w=>{let g=await w.target.getProperty("value");this.updateValue(v,g);}),this.bind({node:t,key:v,type:"model",context:this})),p.removeAttribute(u.name);}});let y={},m={},{props:O,events:i}=this.componentAttributes(t,this);if(y=O,m=i,this.expandStandardAttributes(t),Object.keys(m).forEach(async u=>{let v=m[u];h||p.addEventListener(u,w=>{typeof v=="function"&&v.apply(this.component,[w]);}),p.removeAttribute("@"+u);}),await p.exec(),h){await this.mountComponent(t,h,this,y,m);return}let r=await t.childNodes();e?.skipSlotted&&(r=r.filter(u=>!u.hasAttribute("slotted")));for(let u of r)await this.render(u,e);}handleTextNode(t){let e=t.textContent?.match(/\{\{(.*?)\}\}/g);e&&e.forEach(n=>{let s=n.replace(/[{}]/g,"").trim();this.bind({type:"interpolation",node:t,key:s,template:t.textContent,context:this});});}componentAttributes(t,e){let n={},s={},o=["import","interface","module","o-model","o-if","o-for"];return [...t.attributes].filter(c=>!o.includes(c.name)).forEach(c=>{let h=c.name;if(h.startsWith("@")){let m=e?.resolve(c.value,true);if(typeof m!="function")throw new Error("Event handler can only be function");h=h.substring(1),s[h]=m;return}let p=null,y=c.value;h.startsWith(":")&&(p=c.value,h=h.substring(1),y=x(e?.resolve(c.value))),h=ut(h),n[h]={name:h,value:y,expr:p};}),{props:n,events:s}}async mountComponent(t,e,n,s={},o={}){if(this.mountedComponents.has(t))return;let c=new E(this.app,{},this),h={};Object.keys(s).forEach(w=>{let g=s[w];g.expr&&this.bind({type:"prop",node:t,key:w,context:c,template:g.expr}),h[w]=g.value;});let p=await ft(e,h,o);c.component=p,c.stack=[],this.mountedComponents.set(t,p);let y=t.updates();Object.keys(s).filter(w=>!s[w].expr).forEach(w=>y.setAttribute(w,s[w].value));let m=p.hostClasses??[];m&&(m=typeof m=="string"?[m]:m),m.push("o-component-host"),t.tag.toLowerCase()!=="div"&&m.push("c-"+t.tag.toLowerCase()),y.addClass(...m),await y.exec(),await p.decorateHostElement(t);let O=p.use??{};if(Object.keys(O).forEach(w=>{let g=O[w],C=w;c.componentsRegistry.register(C,g);}),p.willMount(),!e.cssInstance){let w=p.style?p.style()?.toString():p.css;w&&(e.cssInstance??(e.cssInstance=await OUID.injectComponentStyles(w)));}let i=e.cssInstance;if(i){let w=E.STYLE_REF.get(i)??0;E.STYLE_REF.set(i,w+1),p.cssInstance=i;}let r=await t.childNodes();if(p.render){let w=await p.render(c);w&&w.attachTo(t);}else await t.setHTML(p.template.trim());let u=await t.queryAll("slot");if(u){let w=u.filter(g=>!g.classes?.includes("hydrated")).map(async g=>{let C=g.attribute("name");for(let I of r.filter(D=>C?C&&D.type==="Element"&&D.attribute("slot")===C:D.type!=="Element"||!D.hasAttribute("slot")))await I.setAttribute("slotted","true"),await g.appendChild(I),await this.render(I);});await Promise.all(w);}p._hostElement=t,p.parent=n?.component??void 0,p.provide(E.PROVIDE_TOKEN,this);let v=await t.childNodes();await Promise.all(v.map(w=>c.render(w,{skipSlotted:true}))),c.updateDirectives(),p.onMounted(),await c.hydradationActions.commit(),p.state.watch(()=>{c.updateBindings(),c.updateDirectives();});}async unmountComponent(t){let e=this.mountedComponents.get(t);if(e){let s=e.cssInstance;if(s){let o=E.STYLE_REF.get(s)??1;o===1?(await OUID.rejectComponentStyles(s),E.STYLE_REF.delete(s)):E.STYLE_REF.set(s,o-1);}e.willUnmount(),e._hostElement=null,e.cssInstance=null;}let n=await t.queryAll("*")??[];for(let s of n)await this.unmountComponent(s);this.mountedComponents.delete(t);}};d(E,"RenderContext"),l(E,"PROVIDE_TOKEN","RENDER_CONTEXT"),l(E,"STYLE_REF",new WeakMap);var A=E;async function Bt(a,t,e=[],n){let s=t??{},o=await OUID.createElement(a,Object.keys(s).reduce((c,h)=>(c[h]=s[h],c),{}));return Object.keys(n??{}).forEach(c=>{o?.addEventListener(c,h=>{let p=n[c];typeof p=="function"&&p(h);});}),new P(o,e)}d(Bt,"node");function ft(a,t,e){return pt(a)?a().then(n=>F(n.default,t,e)):F(a,t,e)}d(ft,"o");function mt(a){return typeof a=="function"}d(mt,"isProvideFunction");var L=class L{constructor(t,e){l(this,"root");l(this,"options");l(this,"providers",new Map);this.root=t,this.options=e,L.currentApp=this;}provide(t,e){if(this.providers.has(t)){console.warn(`[OUID] - Provider ${t} already exists`);return}this.providers.set(t,mt(e)?{provide:e}:{value:e});}inject(t){return this.providers.get(t)?.value}use(t,e){return t.install(this,e),this}async mount(t){if(!globalThis.__OUI_PUR_JS_CONTEXT__)return;this.options?.css&&(console.log("Injecting app css",this.options.css),await OUID.injectComponentStyles(this.options.css)),await OUID.injectComponentStyles(`
7
+ * {
8
+ ${t} * {
9
+ visibility: hidden;
10
+ }
11
+ ${t} *.hydrated {
12
+ visibility: inherit;
13
+ }
14
+ .oui-hidden {
15
+ display: none !important;
16
+ }
17
+ `);let e=await OUID.query(t);if(console.log("Mounting app on",e),!e)throw new Error("No selector found for "+t);let n=new A(this,{},null);n.mountComponent(e,this.root,null).then(()=>{n.updateBindings(),n.updateDirectives();});}};d(L,"App"),l(L,"currentApp",null);var B=L;function Wt(a,t){B.currentApp?.provide(a,t);}d(Wt,"provide");function st(a){return B.currentApp?.inject(a)??void 0}d(st,"inject");function wt(a,t,e,n){var s=arguments.length,o=s<3?t:n===null?n=Object.getOwnPropertyDescriptor(t,e):n,c;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")o=Reflect.decorate(a,t,e,n);else for(var h=a.length-1;h>=0;h--)(c=a[h])&&(o=(s<3?c(o):s>3?c(t,e,o):c(t,e))||o);return s>3&&o&&Object.defineProperty(t,e,o),o}d(wt,"_ts_decorate");var X=class X extends U{constructor(){super(...arguments);l(this,"router");}willMount(){}onMounted(){this.router=yt(),console.log("Router mounted"),this.router?.bind(this).then(e=>{e?.();});}willUnmount(){console.log("Router will unmount"),this.router?.unbind();}};d(X,"ORouter");var R=X;R=wt([nt({tag:"o-router",template:`
2
18
  <div id="router-view"></div>
3
- `})],exports.RouterComponent);var D="OROUTER_TOKEN",M="ACTIVE_ROUTE";function V(){return j(D)}function Ce(s){return new L(s)}function H(s,e){let t=new k__default.default(s.path).reverse(e);return t===false?"":t}var L=class{constructor(e){this.routes=e;}guards=[];install(e){e.provide(D,this);}resolve(e){let t=new k__default.default(e),n=e.split("?").reverse()[0].split("&").reduce((o,c)=>{let i=c.split("=");return o[i[0]]=decodeURIComponent(i[1]),o},{});for(let o of this.routes){let c=t.match(o.path);if(c)return {route:o,params:c,query:n}}return null}push(e){if(!e.path&&!e.name){console.warn("[OUID-Router]: no path or name provided to push");return}if(e.name){let t=this.routes.find(o=>o.name===e.name);if(!t){console.warn("[OUID-Router]: No matched route name found");return}let n=H(t,e.params);window.history.pushState({},"",n),window.dispatchEvent(new PopStateEvent("popstate"));return}if(e.absolute&&window.history.pushState({},"",e.path),e.path){let t=this.routes.find(n=>n.path===e.path);if(t){let n=H(t,e.params);window.history.pushState({},"",n),window.dispatchEvent(new PopStateEvent("popstate"));return}}}async beforeRouteGoing(e,t){for(let n of this.guards.filter(o=>o.type==="before")){let o=await n.fn(e,t);if(o)return o}}async afterRouteGoing(e,t){for(let n of this.guards.filter(o=>o.type==="after")){let o=await n.fn(e,t);if(o)return o}}bind(e){let t=async()=>{console.log("Handling routing",this);let n=window.location.pathname,o=this.resolve(n);if(console.log("Matched::",o),!o){console.warn(`[Router] No route found for: ${n}`);return}let c=await this.beforeRouteGoing({url:n,path:n,name:o.route.name},e.inject(M));if(c){typeof c=="object"&&"name"in c&&this.push({name:c.name,params:c.params});return}let i=e.inject(g.PROVIDE_TOKEN),r=i.hostElement.querySelector("#router-view");console.log("Outlet",r),r&&(r.innerHTML="",e.provide(M,{params:o.params,query:o.query}),await i.mountComponent(r,o.route.component,i),await this.afterRouteGoing({url:n,path:n,name:o.route.name},e.inject(M)));};return window.addEventListener("popstate",t.bind(this)),t}unbind(e){window.removeEventListener("popstate",e);}beforeEach(e){let t={fn:e,type:"before"};return this.guards.push(t),()=>{this.guards.splice(this.guards.indexOf(t));}}afterEach(e){let t={fn:e,type:"after"};return this.guards.push(t),()=>{this.guards.splice(this.guards.indexOf(t));}}};exports.ACTIVE_ROUTE_TOKEN=M;exports.App=R;exports.Component=_;exports.Emits=T;exports.OComponent=O;exports.ROUTER_INJECTION_TOKEN=D;exports.RenderContext=g;exports.Router=L;exports.State=C;exports.Stated=v;exports.createComponent=b;exports.createRouter=Ce;exports.inject=j;exports.isStated=E;exports.provide=de;exports.stated=B;exports.useRouter=V;//# sourceMappingURL=index.js.map
19
+ `,css:`
20
+ #router-view {
21
+ height: 100%;
22
+ }
23
+ `})],R);var ot="OROUTER_TOKEN",z="ACTIVE_ROUTE";function yt(){return st(ot)}d(yt,"useRouter");function Xt(a){return new G(a)}d(Xt,"createRouter");function rt(a,t){let e=new it(a.path).reverse(t);return e===false?"":e}d(rt,"generatePath");var Z=class Z{constructor(t){l(this,"routes");l(this,"windowObject",null);l(this,"guards",[]);l(this,"eventRegistration",null);this.routes=t;}install(t){t.provide(ot,this),OUID.registerComponent("o-router",R);}resolve(t){let e=new it(t),n=t.split("?").reverse()[0].split("&").reduce((s,o)=>{let c=o.split("=");return s[c[0]]=decodeURIComponent(c[1]),s},{});for(let s of this.routes){let o=e.match(s.path);if(o)return {route:s,params:o,query:n}}return null}push(t){if(!t.path&&!t.name){console.warn("[OUID-Router]: no path or name provided to push");return}if(t.name){let e=this.routes.find(s=>s.name===t.name);if(!e){console.warn("[OUID-Router]: No matched route name found");return}let n=rt(e,t.params??{});this.windowObject?.invoke("history.pushState",{},"",n),this.windowObject?.dispatchEvent("popstate","PopStateEvent",{state:{}});return}if(t.absolute&&t.path&&this.windowObject?.invoke("history.pushState",{},"",t.path),t.path){let e=this.routes.find(n=>n.path===t.path);if(e){let n=rt(e,t.params??{});this.windowObject?.invoke("history.pushState",{},"",n),this.windowObject?.dispatchEvent("popstate","PopStateEvent",{state:{}});return}}}pop(){this.windowObject?.invoke("history.back"),this.windowObject?.dispatchEvent("popstate","PopStateEvent",{state:{}});}async beforeRouteGoing(t,e){for(let n of this.guards.filter(s=>s.type==="before")){let s=await n.fn(t,e);if(s)return s}}async afterRouteGoing(t,e){for(let n of this.guards.filter(s=>s.type==="after")){let s=await n.fn(t,e);if(s)return s}}async bind(t){this.windowObject=await OUID.acquireObject("window");let e=d(async()=>{console.log("Handling routing",this);let n=await this.windowObject?.getProperty("location.pathname"),s=this.resolve(n);if(console.log("Matched::",s),!s){console.warn(`[Router] No route found for: ${n}`);return}let o=await this.beforeRouteGoing({url:n,path:n,name:s.route.name},t.inject(z));if(o){typeof o=="object"&&"name"in o&&this.push({name:o.name,params:o.params});return}let c=t.inject(A.PROVIDE_TOKEN),h=await c?.hostElement.query("#router-view");console.log("Outlet",h),h&&(h.innerHTML="",t.provide(z,{params:s.params,query:s.query}),await c?.mountComponent(h,s.route.component,c),await this.afterRouteGoing({url:n,path:n,name:s.route.name},t.inject(z)));},"handler");return this.eventRegistration=await this.windowObject.addEventListener("popstate",e.bind(this)),e}unbind(){this.eventRegistration&&this.windowObject?.dettachEventListener("popstate",this.eventRegistration);}beforeEach(t){let e={fn:t,type:"before"};return this.guards.push(e),()=>{this.guards.splice(this.guards.indexOf(e));}}afterEach(t){let e={fn:t,type:"after"};return this.guards.push(e),()=>{this.guards.splice(this.guards.indexOf(e));}}};d(Z,"Router");var G=Z;function ee(){return T.getAll().reduce((t,[e,n])=>(t[e]=n,t),{})}d(ee,"components");export{z as ACTIVE_ROUTE_TOKEN,B as App,nt as Component,M as Emits,Rt as Native,U as OComponent,b as ODOM,R as ORouter,f as OUID,K as OUIDBridge,ot as ROUTER_INJECTION_TOKEN,A as RenderContext,P as RenderNode,G as Router,k as State,j as Stated,et as StyleData,ee as components,F as createComponent,Xt as createRouter,st as inject,tt as isStated,Bt as node,ft as o,Wt as provide,ct as stated,yt as useRouter};//# sourceMappingURL=index.js.map
4
24
  //# sourceMappingURL=index.js.map