ouider 0.0.7 → 0.0.8
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/dom/dom.cjs +1 -1
- package/dist/dom/dom.cjs.map +1 -1
- package/dist/dom/dom.js +1 -1
- package/dist/dom/dom.js.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
'use strict';var dt=require('route-parser');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var dt__default=/*#__PURE__*/_interopDefault(dt);var nt=Object.defineProperty;var mt=(i,t,e)=>t in i?nt(i,t,{enumerable:true,configurable:true,writable:true,value:e}):i[t]=e;var u=(i,t)=>nt(i,"name",{value:t,configurable:true});var l=(i,t,e)=>mt(i,typeof t!="symbol"?t+"":t,e);var q=class q{constructor(){l(this,"components",new Map);}register(t,e){console.log(`[OUID] - Registering component: ${t}`);let n=t.toLocaleLowerCase();
|
|
1
|
+
'use strict';var dt=require('route-parser');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var dt__default=/*#__PURE__*/_interopDefault(dt);var nt=Object.defineProperty;var mt=(i,t,e)=>t in i?nt(i,t,{enumerable:true,configurable:true,writable:true,value:e}):i[t]=e;var u=(i,t)=>nt(i,"name",{value:t,configurable:true});var l=(i,t,e)=>mt(i,typeof t!="symbol"?t+"":t,e);var q=class q{constructor(){l(this,"components",new Map);}register(t,e){console.log(`[OUID] - Registering component: ${t}`);let n=t.toLocaleLowerCase();this.components.has(n)||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())}};u(q,"ComponentsRegistry");var k=q,T=new k;var $=class ${constructor(t){l(this,"events");this.events=t;}emit(t,...e){let n=this.events[t];n&&n(...e);}};u($,"Emits");var P=$;var W=class W{constructor(t){l(this,"value");this.value=t;}};u(W,"Stated");var j=W;function st(i){return typeof i=="object"&&!Array.isArray(i)&&"value"in i&&i instanceof j}u(st,"isStated");function wt(i,t){let e=u((n,s=new Map)=>{if(s.has(n))return s.get(n);let o=new Proxy(n,{set:u((c,p,h)=>{let y=c[p];return typeof h=="object"?c[p]=e(h):c[p]=h,t.didChange(p,y,h),true},"set"),get:u((c,p)=>Reflect.get(c,p),"get")});s.set(n,o);for(let c=n;c;c=Object.getPrototypeOf(c))Object.keys(c).forEach(p=>{let h=n[p];typeof h=="object"&&(n[p]=e(h,s));});return o},"proxify");if(typeof i=="function")throw new Error("Can't create reactive element over a function");return typeof i!="object"&&typeof i!="symbol"?new Proxy(new j(i),{set:u((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:u((n,s)=>{if(s!=="value")throw new Error(`Undefined property ${String(s)} access`);return n[s]},"get")}):new j(e(i))}u(wt,"stated");var F=class F{constructor(t){l(this,"THRESHOLD_TIME",20);l(this,"debounceTime",new Date().getTime());l(this,"state");l(this,"listeners",[]);l(this,"timer",null);this.state=new Proxy(t,{set:u((e,n,s)=>{let o=e[n];return e[n]=s,this.didChange(n,o,s),true},"set"),get:u((e,n)=>e[n],"get")});}wrap(t){return wt(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&&clearTimeout(this.timer),this.debounceTime=s,this.timer=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);}};u(F,"State");var U=F;var yt=0;function rt(i){return function(t){var s;let e=(s=class extends t{constructor(){super(...arguments);l(this,"template",i.template);l(this,"css",i.css);l(this,"tag",i.tag);l(this,"use",i.use);l(this,"hostClasses",i.hostClasses);l(this,"hash","component-"+yt+"-"+i.tag);}},u(s,"WithDecoration"),s),n=e;return n.tag=i.tag,e}}u(rt,"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}};u(V,"RenderNode");var S=V,I=class I{constructor(t,e){l(this,"data");l(this,"css");this.data=t,this.css=e;}toString(){let t=this.css?this.css+`
|
|
2
2
|
`:"";for(let e in this.data){let n=this.data[e];typeof n=="string"?t+=`${e} { ${n} }
|
|
3
3
|
`:n instanceof I&&(t+=`${e} {
|
|
4
4
|
${n.toString()}}
|
|
5
5
|
`);}return t}static of(t,...e){return new I(t,e.join(`
|
|
6
|
-
`))}};u(I,"StyleData");var B=I;function Y(i,t,e){return new i(t,e)}u(Y,"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 U(this),this.props=t,this.emits=new P(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()}};u(J,"OComponent");var _=J;function N(i){let t=Date.now();return `${(1e3+Math.floor(Math.random()*9e3)+i.length).toString(16)}-${t.toString(16)}`}u(N,"generateUIID");(function(i){var c,p,h,y,v;let t=(c=class{constructor(){l(this,"actions",[]);}async exec(){await this.commit();}add(a){return this.actions.push(a),this}async commit(){let a=this.actions;this.actions=[],await Promise.all(a.map(async r=>await r()));}},u(c,"BatchActions"),c);i.BatchActions=t;let e=(p=class{constructor(a){l(this,"node");l(this,"operations",[]);this.node=a;}async exec(){let a=this.operations.map(r=>typeof r=="object"?this.node[r.fn].apply(this.node,r.args):Promise.resolve(r()));try{await Promise.all(a);}catch{console.error("Error while batch updates");}}append(a,...r){return this.operations.push({fn:a,args:r}),this}add(a){return this.operations.push(a),this}addEventListener(a,r){return this.append("addEventListener",a,r)}setProperty(a,r){return this.append("setAttribute",a,r)}dettachEventListener(a,r){return this.append("dettachEventListener",a,r)}invoke(a,...r){return this.append("invoke",a,...r)}dispatchEvent(a,r,d){return this.append("dispatchEvent",a,r,d)}addClass(...a){return this.append("addClass",...a)}removeClass(...a){return this.append("removeClass",...a)}setAttribute(a,r){return this.append("setAttribute",a,r)}removeAttribute(a){return this.append("removeAttribute",a)}appendChild(a){return this.append("appendChild",a)}removeChild(a){return this.append("removeChild",a)}remove(){return this.append("remove")}removeAndRelease(){return this.append("removeAndRelease")}release(){return this.append("release")}innerHTML(a){return this.append("setHTML",a)}replaceChildNode(a,r){return this.append("replaceChildNode",a,r)}replaceWith(a){return this.append("replaceWith",a)}after(a){return this.append("after",a)}setInnerText(a){return this.append("setInnerText",a)}setContentText(a){return this.append("setContentText",a)}insertBefore(a,r){return this.append("insertBefore",a,r)}setInputValue(a){return this.append("setInputValue",a)}setStyle(a,r){return this.append("setStyle",a,r)}},u(p,"BatchUpdates"),p);i.BatchUpdates=e;let n=(h=class{constructor(a,r){l(this,"uid");l(this,"tag");this.uid=a,this.tag=r;}async addEventListener(a,r){return f.addEventListener(this,a,r)}async dettachEventListener(a,r){await f.dettachEventListener(this,a,r);}async invoke(a,...r){await f.call("invokeObjectMethod",this.uid,a,...r);}async getProperty(a){return await f.call("getObjectProperty",this.uid,a)}async setProperty(a,r){await f.call("setObjectProperty",this.uid,a,r);}async dispatchEvent(a,r,d){await f.call("dispatchEvent",this.uid,a,r,d);}},u(h,"OObject"),h);i.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 d in r)this[d]=r[d];this.attributes??(this.attributes=[]),this.classes??(this.classes=[]),this.style??(this.style="");}},u(y,"ONode"),y);i.ONode=s;let o=(v=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,d){let w=await f.call("setAttribute",this.uid,r,d);w&&(this.attributes=w);}async removeAttribute(r){let d=await f.call("removeAttribute",this.uid,r);d&&(this.attributes=d);}async appendChild(r){await f.call("appendChild",this.uid,r.uid);}set innerHTML(r){this.setHTML(r);}async cloneNode(r){let d=await f.call("cloneNode",this.uid,r);return d?new v(d):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,d){await f.call("removeChild",this.uid,r.uid,d.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 v(r))??[]}hasAttribute(r){return !!this.attributes.find(d=>d.name===r)}async getAttribute(r){return await f.call("getAttribte",this.uid,r)??""}attribute(r){return this.attributes.find(d=>d.name===r)?.value??null}async nextSibling(){let r=await f.call("nextSibling",this.uid);return r?new v(r):null}async getAttributeNames(){return await f.call("getAttributeNames",this.uid)??[]}async parentNode(){let r=await f.call("parentNode",this.uid);return r?new v(r):null}async insertBefore(r,d){await f.call("insertBefore",this.uid,d.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,d){return await f.query(r,d,this.uid)}async queryAll(r,d){return await f.queryAll(r,d,this.uid)}async release(){await f.call("releaseNode",this.uid);}async setStyle(r,d){await f.call("setStyle",this.uid,r,d);}updates(){return new e(this)}},u(v,"OElement"),v);i.OElement=o;})(exports.ODOM||(exports.ODOM={}));function qt(){return function(i,t,e){e.value;e.value=async(...s)=>{let o=s[0];try{let c=await f.invoke(t,[{props:o.getSafePropsForNative}]);o.setSafePropsFromNative;}catch{console.error("Failed to invoke native function");}};}}u(qt,"Native");var z=class z{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 exports.ODOM.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 exports.ODOM.OElement(s):null}async queryAll(t,e,n){let s=await this.call("queryAll",t,e,n);return s?s.map(o=>new exports.ODOM.OElement(o)):[]}async createElement(t,e={}){let n=await this.call("createElement",t,e);return n?new exports.ODOM.OElement(n):null}async createComment(t){let e=await this.call("createComment",t);return e?new exports.ODOM.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 exports.ODOM.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 exports.ODOM.OObject(e.uid,e.tag):null}async acquireObject(t){let e=await f.call("acquireObject",t);return e?new exports.ODOM.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 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)}};u(z,"OUIDBridge");var K=z,f=new Proxy(new K,{get:u((i,t)=>t in i?i[t]:async(...e)=>await i.call(t,...e),"get")});globalThis.OUID=f;exports.ODOM=void 0;function vt(i){return i.replace(/-([a-z])/g,(t,e)=>e.toUpperCase())}u(vt,"toCamelCase");function gt(i){return i.replace(/(?!^)([A-Z])/g,(t,e)=>`-${e.toLowerCase()}`)}u(gt,"toSnakeCase");function C(i){return st(i)?i.value:i}u(C,"normaliseValue");var bt=typeof globalThis.queueMicrotask=="function",R=u(i=>i?bt?queueMicrotask(i):Promise.resolve().then(i):Promise.resolve(),"deferMicro"),zt=u(()=>new Promise(i=>setTimeout(i,0)),"deferMacro");function Et(i){return typeof i=="function"&&!("prototype"in i)}u(Et,"isLazyLoader");var it=new Map,at=new Map,ot=new WeakMap;function ct(i){if(!i||typeof i!="object"&&typeof i!="function")return {};let t=ot.get(i);if(t)return t;let e=Object.create(null);for(let n=i;n&&n!==Object.prototype;n=Object.getPrototypeOf(n))for(let s of Object.getOwnPropertyNames(n)){if(s==="constructor"||s.startsWith("__")||s.endsWith("__")||s in e)continue;let o=Object.getOwnPropertyDescriptor(n,s);if(!o)continue;let c=o.value??(o.get?o.get.call(i):void 0);e[s]=typeof c=="function"?c.bind(i):c;}return ot.set(i,e),e}u(ct,"getMethodsView");function lt(i,t){let e=it.get(i);return e||(e=new Function("s","with (s) { return ("+i+"); }"),it.set(i,e)),e(t)}u(lt,"evalInScope");function xt(i){let t=at.get(i);if(t)return t;let e=[],n=0;for(;n<i.length;){let s=i.indexOf("{{",n);if(s<0){e.push({t:i.slice(n)});break}s>n&&e.push({t:i.slice(n,s)});let o=i.indexOf("}}",s+2),c=o>=0?i.slice(s+2,o).trim():i.slice(s+2).trim();e.push({e:c}),n=o>=0?o+2:i.length;}return t=u(s=>{let o="";for(let c of e)if(c.t!==void 0)o+=c.t;else if(c.e!==void 0){let p=lt(c.e,s);o+=p==null?"":String(p);}return o},"fn"),at.set(i,t),t}u(xt,"compileInterpolated");var x=class x{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 k);l(this,"updatingDirectives",false);l(this,"updatingBindings",false);l(this,"_stack",[]);l(this,"flatStack",Object.create(null));l(this,"hydradationActions",new exports.ODOM.BatchActions);this.app=t,this.component=e,this.parentContext=n;for(let o of s)this.push(o);}get hostElement(){return this.component._hostElement}get stack(){return this._stack}set stack(t){this.flatStack=Object.create(null),this._stack=[];for(let e of t)this.push(e);}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??{},o=ct(s),c=new Proxy(Object.create(null),{get:u((p,h)=>{for(let y=n.length-1;y>=0;y--)if(h in n[y])return n[y][h];return h in this.flatStack?this.flatStack[h]:h in o?o[h]:s[h]},"get"),has:u((p,h)=>n.some(y=>h in y)||h in this.flatStack||h in o||h in s,"has")});try{return lt(t,c)}catch(p){console.log(this,t),console.error(p);return}}updateValue(t,e){let n=t.split(/[\.\[]/)[0];n 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(n,void 0,e);}push(t){this._stack.unshift(t),Object.assign(this.flatStack,t);}pop(){let t=this._stack.shift();if(t)for(let e of Object.keys(t))delete this.flatStack[e];}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 exports.ODOM.BatchActions,this.updatingBindings=true;for(let n of this.bindings)this.updateBinding(n,t);this.updatingBindings=false,e&&await t.commit();}updateBinding(t,e){if(t.type==="model"){t.node.setProperty("value",C(t.context.resolve(t.key)));return}if(t.type==="interpolation"){e.add(async()=>{let n=t.templateFn({...this.flatStack,...ct(this.component.state?.value??{}),...this.component.state?.value??{}});await t.node.setContentText(n);});return}if(t.type==="attribute"){let n=t.key,s=C(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()));return}if(t.type==="prop"&&t.context.component){let n=C(this.resolve(t.template));try{t.context.component.props[t.key]=n,t.context.updateBindings(),t.context.updateDirectives();}catch(s){console.error(s);}return}}async updateDirectives(t){if(this.updatingDirectives)return;let e=!t;this.updatingDirectives=true,t=t??new exports.ODOM.BatchActions;for(let n of this.directives){if(n.type==="if"){if(!C(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=u((r,d)=>n.key?C(n.context.resolve(n.key,true,{[n.item]:r})):d,"keyFn"),p=C(n.context.resolve(n.list))||[],h=new exports.ODOM.BatchActions,y=32,v=0,m=[],a=n.placeholder;for(let r=0;r<p.length;r++){let d=p[r],w=c(d,r),b=s.get(w),E,O,M=a;b?(E=b.node,O=b.ctx,O.stack=[{[n.item]:d},...n.context.stack],h.add(async()=>{let et=await a.nextSibling();E.uid!==et?.uid&&h.add(()=>M.after(E));}),await Promise.all([O.updateBindings(t),O.updateDirectives(t)])):(O=new x(this.app,this.component,this),O.hydradationActions=this.hydradationActions,O.stack=[{[n.item]:d},...n.context.stack],E=await n.node.cloneNode(true),h.add(async()=>{await M.after(E);}),m.push(async()=>{await O.render(E),await O.updateDirectives(t);})),a=E,o.set(w,{node:E,ctx:O}),++v>=y&&(v=0,await h.commit(),await R());}for(let[r,d]of s.entries())o.has(r)||(this.unmountComponent(d.node),h.add(()=>d.node.removeAndRelease()));if(await h.commit(),m.length)for(let d=0;d<m.length;d+=12){let w=m.slice(d,d+12).map(b=>b());await Promise.all(w),await R();}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"))return;switch(t.type){case "Text":this.handleTextNode(t);break;case "Element":await this.handleElementNode(t,e);break;default:console.warn("Unknown node",t);}let n=new exports.ODOM.BatchActions;await Promise.all([this.updateBindings(n),this.updateDirectives(n)]),n.commit(),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=>`${gt(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 d=await t.getAttribute(o),w=await OUID.createComment(o+":"+d),b=o==="o-if";await n.insertBefore(w,t),await t.updates().removeAttribute(o).remove().exec(),this.directive({type:"if",expr:d,node:t,placeholder:w,context:this,active:void 0,destroy:b}),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 d=await t.getAttribute("o-for"),[w,b]=d.split(" of ").map(M=>M.trim()),E=await OUID.createComment("for:"+d),O=t.attribute(":key")??"";await n?.insertBefore(E,t),await t.updates().removeAttribute("o-for").removeAttribute(":key").remove().exec(),this.directive({type:"for",item:w,list:b,node:t,placeholder:E,context:this,key:O}),s="for";return}let c=t.tag.toLowerCase(),p=this.resolveTag(c),h=t.updates();[...t.attributes].forEach(async d=>{if(d.name==="o-model"){let w=d.value.trim();(t.tag==="input"||t.tag==="textarea")&&(h.setInputValue(C(this.resolve(w))).addEventListener("input",async b=>{let E=await b.target.getProperty("value");this.updateValue(w,E);}),this.bind({node:t,key:w,type:"model",context:this})),h.removeAttribute(d.name);}});let y={},v={},{props:m,events:a}=this.componentAttributes(t,this);if(y=m,v=a,this.expandStandardAttributes(t),Object.keys(v).forEach(async d=>{let w=v[d];p||h.addEventListener(d,b=>{typeof w=="function"&&w.apply(this.component,[b]);}),h.removeAttribute("@"+d);}),await h.exec(),p){await this.mountComponent(t,p,this,y,v);return}let r=await t.childNodes();e?.skipSlotted&&(r=r.filter(d=>!d.hasAttribute("slotted")));for(let d of r)await this.render(d,e);}handleTextNode(t){let e=t.textContent??"";e.includes("{{")&&this.bind({type:"interpolation",node:t,key:"__template__",templateFn:xt(e),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 p=c.name;if(p.startsWith("@")){let v=e?.resolve(c.value,true);if(typeof v!="function")throw new Error("Event handler can only be function");p=p.substring(1),s[p]=v;return}let h=null,y=c.value;p.startsWith(":")&&(h=c.value,p=p.substring(1),y=C(e?.resolve(c.value))),p=vt(p),n[p]={name:p,value:y,expr:h};}),{props:n,events:s}}async mountComponent(t,e,n,s={},o={}){if(this.mountedComponents.has(t))return;let c=new x(this.app,{},this),p={};for(let m of Object.keys(s)){let a=s[m];a.expr&&this.bind({type:"prop",node:t,key:m,context:c,template:a.expr}),p[m]=a.value;}let h=await Ot(e,p,o);c.component=h,c.stack=[],this.mountedComponents.set(t,h);{let m=t.updates();for(let r of Object.keys(s))s[r].expr||m.setAttribute(r,s[r].value);let a=h.hostClasses??[];a&&(a=typeof a=="string"?[a]:a),a.push("o-component-host"),t.tag.toLowerCase()!=="div"&&a.push("c-"+t.tag.toLowerCase()),m.addClass(...a),await m.exec();}R(async()=>{try{await h.decorateHostElement(t);}catch{}});{let m=h.use??{};for(let a of Object.keys(m))c.componentsRegistry.register(a,m[a]);}if(h.willMount(),!e.cssInstance){let m=h.style?h.style()?.toString():h.css;m&&(e.cssInstance??(e.cssInstance=await OUID.injectComponentStyles(m)));}R(()=>{let m=e.cssInstance;if(m){let a=x.STYLE_REF.get(m)??0;x.STYLE_REF.set(m,a+1),h.cssInstance=m;}});let y=await t.childNodes();if(h.render){let m=await h.render(c);m&&m.attachTo(t);}else await t.setHTML(h.template.trim());let v=await t.queryAll("slot");v&&v.length&&await Promise.all(v.filter(m=>!m.classes?.includes("hydrated")).map(async m=>{let a=m.attribute("name"),r=y.filter(w=>a?w.type==="Element"&&w.attribute("slot")===a:w.type!=="Element"||!w.hasAttribute("slot"));if(!r.length)return;let d=new exports.ODOM.BatchActions;for(let w of r)d.add(()=>w.setAttribute("slotted","true")),d.add(()=>m.appendChild(w));await d.commit(),await Promise.all(r.map(w=>this.render(w)));})),h._hostElement=t,h.parent=n?.component??void 0,h.provide(x.PROVIDE_TOKEN,this);{let m=await t.childNodes(),a=6,r=0;for(;r<m.length;){let d=m.slice(r,r+a);await Promise.all(d.map(w=>c.render(w,{skipSlotted:true}))),r+=a;}await c.hydradationActions.commit();}R(()=>{try{h.onMounted();}catch{}}),h.state.watch(()=>{let m=new exports.ODOM.BatchActions;c.updateBindings(m),c.updateDirectives(m),m.commit();});}async unmountComponent(t){let e=this.mountedComponents.get(t);if(e){let s=e.cssInstance;if(s){let o=x.STYLE_REF.get(s)??1;o===1?(await OUID.rejectComponentStyles(s),x.STYLE_REF.delete(s)):x.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);}};u(x,"RenderContext"),l(x,"PROVIDE_TOKEN","RENDER_CONTEXT"),l(x,"STYLE_REF",new WeakMap);var A=x;async function Gt(i,t,e=[],n){let s=t??{},o=await OUID.createElement(i,Object.keys(s).reduce((c,p)=>(c[p]=s[p],c),{}));return Object.keys(n??{}).forEach(c=>{o?.addEventListener(c,p=>{let h=n[c];typeof h=="function"&&h(p);});}),new S(o,e)}u(Gt,"node");function Ot(i,t,e){return Et(i)?i().then(n=>Y(n.default,t,e)):Y(i,t,e)}u(Ot,"o");function Ct(i){return typeof i=="function"}u(Ct,"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,Ct(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&&await OUID.injectComponentStyles(this.options.css),await OUID.injectComponentStyles(`
|
|
6
|
+
`))}};u(I,"StyleData");var B=I;function Y(i,t,e){return new i(t,e)}u(Y,"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 U(this),this.props=t,this.emits=new P(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()}};u(J,"OComponent");var _=J;function N(i){let t=Date.now();return `${(1e3+Math.floor(Math.random()*9e3)+i.length).toString(16)}-${t.toString(16)}`}u(N,"generateUIID");(function(i){var c,p,h,y,v;let t=(c=class{constructor(){l(this,"actions",[]);}async exec(){await this.commit();}add(a){return this.actions.push(a),this}async commit(){let a=this.actions;this.actions=[],await Promise.all(a.map(async r=>await r()));}},u(c,"BatchActions"),c);i.BatchActions=t;let e=(p=class{constructor(a){l(this,"node");l(this,"operations",[]);this.node=a;}async exec(){let a=this.operations.map(r=>typeof r=="object"?this.node[r.fn].apply(this.node,r.args):Promise.resolve(r()));try{await Promise.all(a);}catch{console.error("Error while batch updates");}}append(a,...r){return this.operations.push({fn:a,args:r}),this}add(a){return this.operations.push(a),this}addEventListener(a,r){return this.append("addEventListener",a,r)}setProperty(a,r){return this.append("setAttribute",a,r)}dettachEventListener(a,r){return this.append("dettachEventListener",a,r)}invoke(a,...r){return this.append("invoke",a,...r)}dispatchEvent(a,r,d){return this.append("dispatchEvent",a,r,d)}addClass(...a){return this.append("addClass",...a)}removeClass(...a){return this.append("removeClass",...a)}setAttribute(a,r){return this.append("setAttribute",a,r)}removeAttribute(a){return this.append("removeAttribute",a)}appendChild(a){return this.append("appendChild",a)}removeChild(a){return this.append("removeChild",a)}remove(){return this.append("remove")}removeAndRelease(){return this.append("removeAndRelease")}release(){return this.append("release")}innerHTML(a){return this.append("setHTML",a)}replaceChildNode(a,r){return this.append("replaceChildNode",a,r)}replaceWith(a){return this.append("replaceWith",a)}after(a){return this.append("after",a)}setInnerText(a){return this.append("setInnerText",a)}setContentText(a){return this.append("setContentText",a)}insertBefore(a,r){return this.append("insertBefore",a,r)}setInputValue(a){return this.append("setInputValue",a)}setStyle(a,r){return this.append("setStyle",a,r)}},u(p,"BatchUpdates"),p);i.BatchUpdates=e;let n=(h=class{constructor(a,r){l(this,"uid");l(this,"tag");this.uid=a,this.tag=r;}async addEventListener(a,r){return f.addEventListener(this,a,r)}async dettachEventListener(a,r){await f.dettachEventListener(this,a,r);}async invoke(a,...r){await f.call("invokeObjectMethod",this.uid,a,...r);}async getProperty(a){return await f.call("getObjectProperty",this.uid,a)}async setProperty(a,r){await f.call("setObjectProperty",this.uid,a,r);}async dispatchEvent(a,r,d){await f.call("dispatchEvent",this.uid,a,r,d);}},u(h,"OObject"),h);i.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 d in r)this[d]=r[d];this.attributes??(this.attributes=[]),this.classes??(this.classes=[]),this.style??(this.style="");}},u(y,"ONode"),y);i.ONode=s;let o=(v=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,d){let w=await f.call("setAttribute",this.uid,r,d);w&&(this.attributes=w);}async removeAttribute(r){let d=await f.call("removeAttribute",this.uid,r);d&&(this.attributes=d);}async appendChild(r){await f.call("appendChild",this.uid,r.uid);}set innerHTML(r){this.setHTML(r);}async cloneNode(r){let d=await f.call("cloneNode",this.uid,r);return d?new v(d):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,d){await f.call("removeChild",this.uid,r.uid,d.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 v(r))??[]}hasAttribute(r){return !!this.attributes.find(d=>d.name===r)}async getAttribute(r){return await f.call("getAttribte",this.uid,r)??""}attribute(r){return this.attributes.find(d=>d.name===r)?.value??null}async nextSibling(){let r=await f.call("nextSibling",this.uid);return r?new v(r):null}async getAttributeNames(){return await f.call("getAttributeNames",this.uid)??[]}async parentNode(){let r=await f.call("parentNode",this.uid);return r?new v(r):null}async insertBefore(r,d){await f.call("insertBefore",this.uid,d.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,d){return await f.query(r,d,this.uid)}async queryAll(r,d){return await f.queryAll(r,d,this.uid)}async release(){await f.call("releaseNode",this.uid);}async setStyle(r,d){await f.call("setStyle",this.uid,r,d);}updates(){return new e(this)}},u(v,"OElement"),v);i.OElement=o;})(exports.ODOM||(exports.ODOM={}));function qt(){return function(i,t,e){e.value;e.value=async(...s)=>{let o=s[0];try{let c=await f.invoke(t,[{props:o.getSafePropsForNative}]);o.setSafePropsFromNative;}catch{console.error("Failed to invoke native function");}};}}u(qt,"Native");var z=class z{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 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 exports.ODOM.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 exports.ODOM.OElement(s):null}async queryAll(t,e,n){let s=await this.call("queryAll",t,e,n);return s?s.map(o=>new exports.ODOM.OElement(o)):[]}async createElement(t,e={}){let n=await this.call("createElement",t,e);return n?new exports.ODOM.OElement(n):null}async createComment(t){let e=await this.call("createComment",t);return e?new exports.ODOM.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 exports.ODOM.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 exports.ODOM.OObject(e.uid,e.tag):null}async acquireObject(t){let e=await f.call("acquireObject",t);return e?new exports.ODOM.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 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)}async alert(t){await f.call("alert",t);}async prompt(t){await f.call("prompt",t);}};u(z,"OUIDBridge");var K=z,f=new Proxy(new K,{get:u((i,t)=>t in i?i[t]:async(...e)=>await i.call(t,...e),"get")});globalThis.OUID=f;exports.ODOM=void 0;function vt(i){return i.replace(/-([a-z])/g,(t,e)=>e.toUpperCase())}u(vt,"toCamelCase");function gt(i){return i.replace(/(?!^)([A-Z])/g,(t,e)=>`-${e.toLowerCase()}`)}u(gt,"toSnakeCase");function C(i){return st(i)?i.value:i}u(C,"normaliseValue");var bt=typeof globalThis.queueMicrotask=="function",R=u(i=>i?bt?queueMicrotask(i):Promise.resolve().then(i):Promise.resolve(),"deferMicro"),zt=u(()=>new Promise(i=>setTimeout(i,0)),"deferMacro");function Et(i){return typeof i=="function"&&!("prototype"in i)}u(Et,"isLazyLoader");var it=new Map,at=new Map,ot=new WeakMap;function ct(i){if(!i||typeof i!="object"&&typeof i!="function")return {};let t=ot.get(i);if(t)return t;let e=Object.create(null);for(let n=i;n&&n!==Object.prototype;n=Object.getPrototypeOf(n))for(let s of Object.getOwnPropertyNames(n)){if(s==="constructor"||s.startsWith("__")||s.endsWith("__")||s in e)continue;let o=Object.getOwnPropertyDescriptor(n,s);if(!o)continue;let c=o.value??(o.get?o.get.call(i):void 0);e[s]=typeof c=="function"?c.bind(i):c;}return ot.set(i,e),e}u(ct,"getMethodsView");function lt(i,t){let e=it.get(i);return e||(e=new Function("s","with (s) { return ("+i+"); }"),it.set(i,e)),e(t)}u(lt,"evalInScope");function xt(i){let t=at.get(i);if(t)return t;let e=[],n=0;for(;n<i.length;){let s=i.indexOf("{{",n);if(s<0){e.push({t:i.slice(n)});break}s>n&&e.push({t:i.slice(n,s)});let o=i.indexOf("}}",s+2),c=o>=0?i.slice(s+2,o).trim():i.slice(s+2).trim();e.push({e:c}),n=o>=0?o+2:i.length;}return t=u(s=>{let o="";for(let c of e)if(c.t!==void 0)o+=c.t;else if(c.e!==void 0){let p=lt(c.e,s);o+=p==null?"":String(p);}return o},"fn"),at.set(i,t),t}u(xt,"compileInterpolated");var O=class O{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 k);l(this,"updatingDirectives",false);l(this,"updatingBindings",false);l(this,"_stack",[]);l(this,"flatStack",Object.create(null));l(this,"hydradationActions",new exports.ODOM.BatchActions);this.app=t,this.component=e,this.parentContext=n;for(let o of s)this.push(o);}get hostElement(){return this.component._hostElement}get stack(){return this._stack}set stack(t){this.flatStack=Object.create(null),this._stack=[];for(let e of t)this.push(e);}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??{},o=ct(s),c=new Proxy(Object.create(null),{get:u((p,h)=>{for(let y=n.length-1;y>=0;y--)if(h in n[y])return n[y][h];return h in this.flatStack?this.flatStack[h]:h in o?o[h]:s[h]},"get"),has:u((p,h)=>n.some(y=>h in y)||h in this.flatStack||h in o||h in s,"has")});try{return lt(t,c)}catch{return}}updateValue(t,e){let n=t.split(/[\.\[]/)[0];n in this.component?this.resolve(`${t}=__o_model_value__`,true,{__o_model_value__:e}):this.resolve(`${t}=__o_model_value__`,true,{__o_model_value__:e}),this.component.state.didChange(n,void 0,e);}push(t){this._stack.unshift(t),Object.assign(this.flatStack,t);}pop(){let t=this._stack.shift();if(t)for(let e of Object.keys(t))delete this.flatStack[e];}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 exports.ODOM.BatchActions,this.updatingBindings=true;for(let n of this.bindings)this.updateBinding(n,t);this.updatingBindings=false,e&&await t.commit();}updateBinding(t,e){if(t.type==="model"){t.node.setProperty("value",C(t.context.resolve(t.key)));return}if(t.type==="interpolation"){e.add(async()=>{let n=t.templateFn({...this.flatStack,...ct(this.component.state?.value??{}),...this.component.state?.value??{}});await t.node.setContentText(n);});return}if(t.type==="attribute"){let n=t.key,s=C(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()));return}if(t.type==="prop"&&t.context.component){let n=C(this.resolve(t.template));try{t.context.component.props[t.key]=n,t.context.updateBindings(),t.context.updateDirectives();}catch(s){console.error(s);}return}}async updateDirectives(t){if(this.updatingDirectives)return;let e=!t;this.updatingDirectives=true,t=t??new exports.ODOM.BatchActions;for(let n of this.directives){if(n.type==="if"){if(!C(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=u((r,d)=>n.key?C(n.context.resolve(n.key,true,{[n.item]:r})):d,"keyFn"),p=C(n.context.resolve(n.list))||[],h=new exports.ODOM.BatchActions,y=32,v=0,m=[],a=n.placeholder;for(let r=0;r<p.length;r++){let d=p[r],w=c(d,r),b=s.get(w),x,E,D=a;b?(x=b.node,E=b.ctx,E.stack=[{[n.item]:d},...n.context.stack],h.add(async()=>{let et=await a.nextSibling();x.uid!==et?.uid&&h.add(()=>D.after(x));}),await Promise.all([E.updateBindings(t),E.updateDirectives(t)])):(E=new O(this.app,this.component,this),E.hydradationActions=this.hydradationActions,E.stack=[{[n.item]:d},...n.context.stack],x=await n.node.cloneNode(true),h.add(async()=>{await D.after(x);}),m.push(async()=>{await E.render(x),await E.updateDirectives(t);})),a=x,o.set(w,{node:x,ctx:E}),++v>=y&&(v=0,await h.commit(),await R());}for(let[r,d]of s.entries())o.has(r)||(this.unmountComponent(d.node),h.add(()=>d.node.removeAndRelease()));if(await h.commit(),m.length)for(let d=0;d<m.length;d+=12){let w=m.slice(d,d+12).map(b=>b());await Promise.all(w),await R();}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"))return;switch(t.type){case "Text":this.handleTextNode(t);break;case "Element":await this.handleElementNode(t,e);break;}let n=new exports.ODOM.BatchActions;await Promise.all([this.updateBindings(n),this.updateDirectives(n)]),n.commit(),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=>`${gt(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 d=await t.getAttribute(o),w=await OUID.createComment(o+":"+d),b=o==="o-if";await n.insertBefore(w,t),await t.updates().removeAttribute(o).remove().exec(),this.directive({type:"if",expr:d,node:t,placeholder:w,context:this,active:void 0,destroy:b}),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 d=await t.getAttribute("o-for"),[w,b]=d.split(" of ").map(D=>D.trim()),x=await OUID.createComment("for:"+d),E=t.attribute(":key")??"";await n?.insertBefore(x,t),await t.updates().removeAttribute("o-for").removeAttribute(":key").remove().exec(),this.directive({type:"for",item:w,list:b,node:t,placeholder:x,context:this,key:E}),s="for";return}let c=t.tag.toLowerCase(),p=this.resolveTag(c),h=t.updates();[...t.attributes].forEach(async d=>{if(d.name==="o-model"){let w=d.value.trim(),b="input";t.tag==="selection"&&(b="change"),h.setInputValue(C(this.resolve(w))).addEventListener(b,async x=>{let E=await x.target.getProperty("value");this.updateValue(w,E);}),this.bind({node:t,key:w,type:"model",context:this}),h.removeAttribute(d.name);}});let y={},v={},{props:m,events:a}=this.componentAttributes(t,this);if(y=m,v=a,this.expandStandardAttributes(t),Object.keys(v).forEach(async d=>{let w=v[d];p||h.addEventListener(d,b=>{typeof w=="function"&&w.apply(this.component,[b]);}),h.removeAttribute("@"+d);}),await h.exec(),p){await this.mountComponent(t,p,this,y,v);return}let r=await t.childNodes();e?.skipSlotted&&(r=r.filter(d=>!d.hasAttribute("slotted")));for(let d of r)await this.render(d,e);}handleTextNode(t){let e=t.textContent??"";e.includes("{{")&&this.bind({type:"interpolation",node:t,key:"__template__",templateFn:xt(e),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 p=c.name;if(p.startsWith("@")){let v=e?.resolve(c.value,true);if(typeof v!="function")throw new Error("Event handler can only be function");p=p.substring(1),s[p]=v;return}let h=null,y=c.value;p.startsWith(":")&&(h=c.value,p=p.substring(1),y=C(e?.resolve(c.value))),p=vt(p),n[p]={name:p,value:y,expr:h};}),{props:n,events:s}}async mountComponent(t,e,n,s={},o={}){if(this.mountedComponents.has(t))return;let c=new O(this.app,{},this),p={};for(let m of Object.keys(s)){let a=s[m];a.expr&&this.bind({type:"prop",node:t,key:m,context:c,template:a.expr}),p[m]=a.value;}let h=await Ot(e,p,o);c.component=h,c.stack=[],this.mountedComponents.set(t,h);{let m=t.updates();for(let r of Object.keys(s))s[r].expr||m.setAttribute(r,s[r].value);let a=h.hostClasses??[];a&&(a=typeof a=="string"?[a]:a),a.push("o-component-host"),t.tag.toLowerCase()!=="div"&&a.push("c-"+t.tag.toLowerCase()),m.addClass(...a),await m.exec();}R(async()=>{try{await h.decorateHostElement(t);}catch{}});{let m=h.use??{};for(let a of Object.keys(m))c.componentsRegistry.register(a,m[a]);}if(h.willMount(),!e.cssInstance){let m=h.style?h.style()?.toString():h.css;m&&(e.cssInstance??(e.cssInstance=await OUID.injectComponentStyles(m)));}R(()=>{let m=e.cssInstance;if(m){let a=O.STYLE_REF.get(m)??0;O.STYLE_REF.set(m,a+1),h.cssInstance=m;}});let y=await t.childNodes();if(h.render){let m=await h.render(c);m&&m.attachTo(t);}else await t.setHTML(h.template.trim());let v=await t.queryAll("slot");v&&v.length&&await Promise.all(v.filter(m=>!m.classes?.includes("hydrated")).map(async m=>{let a=m.attribute("name"),r=y.filter(w=>a?w.type==="Element"&&w.attribute("slot")===a:w.type!=="Element"||!w.hasAttribute("slot"));if(!r.length)return;let d=new exports.ODOM.BatchActions;for(let w of r)d.add(()=>w.setAttribute("slotted","true")),d.add(()=>m.appendChild(w));await d.commit(),await Promise.all(r.map(w=>this.render(w)));})),h._hostElement=t,h.parent=n?.component??void 0,h.provide(O.PROVIDE_TOKEN,this);{let m=await t.childNodes(),a=6,r=0;for(;r<m.length;){let d=m.slice(r,r+a);await Promise.all(d.map(w=>c.render(w,{skipSlotted:true}))),r+=a;}await c.hydradationActions.commit();}R(()=>{try{h.onMounted();}catch{}}),h.state.watch(()=>{let m=new exports.ODOM.BatchActions;c.updateBindings(m),c.updateDirectives(m),m.commit();});}async unmountComponent(t){let e=this.mountedComponents.get(t);if(e){let s=e.cssInstance;if(s){let o=O.STYLE_REF.get(s)??1;o===1?(await OUID.rejectComponentStyles(s),O.STYLE_REF.delete(s)):O.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);}};u(O,"RenderContext"),l(O,"PROVIDE_TOKEN","RENDER_CONTEXT"),l(O,"STYLE_REF",new WeakMap);var A=O;async function Gt(i,t,e=[],n){let s=t??{},o=await OUID.createElement(i,Object.keys(s).reduce((c,p)=>(c[p]=s[p],c),{}));return Object.keys(n??{}).forEach(c=>{o?.addEventListener(c,p=>{let h=n[c];typeof h=="function"&&h(p);});}),new S(o,e)}u(Gt,"node");function Ot(i,t,e){return Et(i)?i().then(n=>Y(n.default,t,e)):Y(i,t,e)}u(Ot,"o");function Ct(i){return typeof i=="function"}u(Ct,"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,Ct(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&&await OUID.injectComponentStyles(this.options.css),await OUID.injectComponentStyles(`
|
|
7
7
|
* {
|
|
8
8
|
${t} * {
|
|
9
9
|
visibility: hidden;
|