native-document 1.0.35 → 1.0.37

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.
@@ -1 +1 @@
1
- var NativeDocument=function(t){"use strict";let n={};n={log(){},warn(){},error(){},disable(){}};var r=n;const o=function(){let e=0;const t=new Map;return{register(n){const r=++e;return t.set(r,new WeakRef(n)),r},unregister(e){t.delete(e)},getObservableById:e=>t.get(e)?.deref(),cleanup(){for(const[e,n]of t){const e=n.deref();e&&e.cleanup()}t.clear()},cleanObservables(e){if(t.size<e)return;let n=0;for(const[e,r]of t)r.deref()||(t.delete(e),n++);n>0&&r.log("Memory Auto Clean",`🧹 Cleaned ${n} orphaned observables`)}}}();class s extends Error{constructor(e,t={}){super(e),this.name="NativeDocumentError",this.context=t,this.timestamp=(new Date).toISOString()}}function i(e,t){this.observable=e,this.checker=t,this.unSubscriptions=[]}i.prototype.__$isObservableChecker=!0,i.prototype.subscribe=function(e){const t=this.observable.subscribe(t=>{e&&e(this.checker(t))});return this.unSubscriptions.push(t),t},i.prototype.check=function(e){return this.observable.check(()=>e(this.val()))},i.prototype.val=function(){return this.checker&&this.checker(this.observable.val())},i.prototype.set=function(e){return this.observable.set(e)},i.prototype.trigger=function(){return this.observable.trigger()},i.prototype.cleanup=function(){return this.observable.cleanup()};const a=function(){const e=new Map,t=new Map;return{list:()=>t,add(n,r){if(!r||"object"!=typeof r)throw new Error(`Plugin ${n} must be an object`);if(!e.has(n)){r.$name=n,e.set(n,r),"function"==typeof r?.init&&r.init();for(const e in r)/^on[A-Z]/.test(e)&&(t.has(e)||t.set(e,new Set),t.get(e).add(r))}},remove(n){if(!e.has(n))return;const r=e.get(n);"function"==typeof r.cleanup&&r.cleanup();for(const[e,n]of t.entries())n.has(r)&&n.delete(r),0===n.size&&t.delete(e);e.delete(n)},emit(e,...n){const o="on"+e;if(!t.has(o))return;const s=t.get(o);for(const e of s){const t=e[o];if("function"==typeof t)try{t.call(e,...n)}catch(t){r.error("Plugin Manager",`Error in plugin ${e.$name} for event ${o}`,t)}}}}}();function u(e){this.$previousValue=e,this.$currentValue=e,this.$isCleanedUp=!1,this.$listeners=null,this.$watchers=null,this.$memoryId=null,a.emit("CreateObservable",this)}Object.defineProperty(u.prototype,"$value",{get(){return this.$currentValue},set(e){this.set(e)},configurable:!0}),u.prototype.__$isObservable=!0;const l=function(){};u.prototype.triggerListeners=function(e){const t=this.$listeners,n=this.$previousValue,r=this.$currentValue;if(e=e||{},t?.length)for(let o=0,s=t.length;o<s;o++)t[o](r,n,e)},u.prototype.triggerWatchers=function(){if(!this.$watchers)return;const e=this.$watchers,t=this.$previousValue,n=this.$currentValue;if(e.has(n)){const t=e.get(n);"function"==typeof t?t(!0):t.set?t.set(!0):t.forEach(e=>{e.set?e.set(!0):e(!0)})}if(e.has(t)){const n=e.get(t);"function"==typeof n?n(!1):n.set?n.set(!1):n.forEach(e=>{e.set?e.set(!1):e(!1)})}},u.prototype.triggerAll=function(e){this.triggerListeners(e),this.triggerWatchers()},u.prototype.assocTrigger=function(){this.$watchers?.size&&this.$listeners?.length?this.trigger=this.triggerAll:this.$listeners?.length?this.trigger=this.triggerListeners:this.$watchers?.size?this.trigger=this.triggerWatchers:this.trigger=l},u.prototype.trigger=l,u.prototype.set=function(e){const t="function"==typeof e?e(this.$currentValue):e;this.$currentValue!==t&&(this.$previousValue=this.$currentValue,this.$currentValue=t,a.emit("ObservableBeforeChange",this),this.trigger(),this.$previousValue=null,a.emit("ObservableAfterChange",this))},u.prototype.val=function(){return this.$currentValue},u.prototype.disconnectAll=function(){if(this.$listeners?.splice(0),this.$previousValue=null,this.$currentValue=null,this.$watchers)for(const[e,t]of this.$watchers)m.isArray(t)&&t.splice(0);this.$watchers?.clear(),this.$listeners=null,this.$watchers=null,this.trigger=l},u.prototype.cleanup=function(){o.unregister(this.$memoryId),this.disconnectAll(),this.$isCleanedUp=!0,delete this.$value},u.prototype.subscribe=function(e,t=null){if(this.$listeners=this.$listeners??[],this.$isCleanedUp)return r.warn("Observable subscription","⚠️ Attempted to subscribe to a cleaned up observable."),()=>{};if("function"!=typeof e)throw new s("Callback must be a function");return this.$listeners.push(e),this.assocTrigger(),a.emit("ObservableSubscribe",this,t),()=>{this.unsubscribe(e),this.assocTrigger(),a.emit("ObservableUnsubscribe",this)}},u.prototype.on=function(e,t){this.$watchers=this.$watchers??new Map;let n=this.$watchers.get(e);if(n){if(!m.isArray(n))return n=[n],void this.$watchers.set(e,n);n.push(t)}else this.$watchers.set(e,t);return this.assocTrigger(),()=>{const r=n.indexOf(t);n?.splice(r,1),1===n.size?this.$watchers.set(e,n[0]):0===n.size&&(this.$watchers?.delete(e),n=null),this.assocTrigger()}},u.prototype.unsubscribe=function(e){const t=this.$listeners.indexOf(e);t>-1&&this.$listeners.splice(t,1),this.assocTrigger()},u.prototype.check=function(e){return new i(this,e)},u.prototype.get=u.prototype.check,u.prototype.when=function(e){return{$target:e,$observer:this}},u.prototype.toString=function(){return this.$memoryId||o.register(this),"{{#ObItem::("+this.$memoryId+")}}"};const c=(e,t,n)=>{if(m.isFunction(n))return n(e,t);if(m.isObservable(e)){const r=e.val();return r&&n?r[n]:t}return m.isObject(e)?e[n]??t:e},h=function(e,t){return e.replace(new RegExp(`^[${t}]+|[${t}]+$`,"g"),"")},d={mounted:new WeakMap,mountedSupposedSize:0,unmounted:new WeakMap,unmountedSupposedSize:0,observer:null,checkMutation:function(e){for(const t of e){if(d.mountedSupposedSize>0)for(const e of t.addedNodes){const t=d.mounted.get(e);t&&(t.inDom=!0,t.mounted&&t.mounted(e))}if(d.unmountedSupposedSize>0)for(const e of t.removedNodes){const t=d.unmounted.get(e);t&&(t.inDom=!1,t.unmounted&&!0===t.unmounted(e)&&(t.disconnect(),e.nd?.remove()))}}},watch:function(e,t=!1){let n={inDom:t,mounted:null,unmounted:null,disconnect:()=>{d.mounted.delete(e),d.unmounted.delete(e),d.mountedSupposedSize--,d.unmountedSupposedSize--,n=null}};return{disconnect:n.disconnect,mounted:t=>{n.mounted=t,d.mounted.set(e,n),d.mountedSupposedSize++},unmounted:t=>{n.unmounted=t,d.unmounted.set(e,n),d.unmountedSupposedSize++}}}};d.observer=new MutationObserver(d.checkMutation),d.observer.observe(document.body,{childList:!0,subtree:!0});const p=["Click","DblClick","MouseDown","MouseEnter","MouseLeave","MouseMove","MouseOut","MouseOver","MouseUp","Wheel","KeyDown","KeyPress","KeyUp","Blur","Change","Focus","Input","Invalid","Reset","Search","Select","Submit","Drag","DragEnd","DragEnter","DragLeave","DragOver","DragStart","Drop","AfterPrint","BeforePrint","BeforeUnload","Error","HashChange","Load","Offline","Online","PageHide","PageShow","Resize","Scroll","Unload","Abort","CanPlay","CanPlayThrough","DurationChange","Emptied","Ended","LoadedData","LoadedMetadata","LoadStart","Pause","Play","Playing","Progress","RateChange","Seeked","Seeking","Stalled","Suspend","TimeUpdate","VolumeChange","Waiting","TouchCancel","TouchEnd","TouchMove","TouchStart","AnimationEnd","AnimationIteration","AnimationStart","TransitionEnd","Copy","Cut","Paste","FocusIn","FocusOut","ContextMenu"];function f(e){this.$element=e,this.$observer=null,a.emit("NDElementCreated",e,this)}f.prototype.__$isNDElement=!0;for(const e of p){const t=e.toLowerCase();f.prototype["on"+e]=function(e){return this.$element.addEventListener(t,e),this},f.prototype["onPrevent"+e]=function(e){return this.$element.addEventListener(t,function(t){t.preventDefault(),e&&e(t)}),this},f.prototype["onStop"+e]=function(e){return this.$element.addEventListener(t,function(t){t.stopPropagation(),e&&e(t)}),this},f.prototype["onPreventStop"+e]=function(e){return this.$element.addEventListener(t,function(t){t.stopPropagation(),t.preventDefault(),e&&e(t)}),this}}f.prototype.valueOf=function(){return this.$element},f.prototype.ref=function(e,t){return e[t]=this.$element,this},f.prototype.unmountChildren=function(){let e=this.$element;for(let t=0,n=e.children.length;t<n;t++){let n=e.children[t];n.$ndProx||n.nd?.remove(),n=null}return e=null,this},f.prototype.remove=function(){let e=this.$element;return e.nd.unmountChildren(),e.$ndProx=null,delete e.nd?.on?.prevent,delete e.nd?.on,delete e.nd,e=null,this},f.prototype.lifecycle=function(e){return this.$observer=this.$observer||d.watch(this.$element),e.mounted&&this.$observer.mounted(e.mounted),e.unmounted&&this.$observer.unmounted(e.unmounted),this},f.prototype.mounted=function(e){return this.lifecycle({mounted:e})},f.prototype.unmounted=function(e){return this.lifecycle({unmounted:e})},f.prototype.htmlElement=function(){return this.$element},f.prototype.node=f.prototype.htmlElement,f.prototype.attach=function(e,t){return t.$hydrate(this.$element,e),this.$element};const m={isObservable:e=>e instanceof u||e instanceof i||e?.__$isObservable,isProxy:e=>e?.__isProxy__,isObservableChecker:e=>e instanceof i||e?.__$isObservableChecker,isArray:e=>Array.isArray(e),isString:e=>"string"==typeof e,isNumber:e=>"number"==typeof e,isBoolean:e=>"boolean"==typeof e,isFunction:e=>"function"==typeof e,isAsyncFunction:e=>"function"==typeof e&&"AsyncFunction"===e.constructor.name,isObject:e=>"object"==typeof e,isJson:e=>"object"==typeof e&&null!==e&&"Object"===e.constructor.name&&!Array.isArray(e),isElement:e=>e instanceof HTMLElement||e instanceof DocumentFragment||e instanceof Text,isFragment:e=>e instanceof DocumentFragment,isStringOrObservable(e){return this.isString(e)||this.isObservable(e)},isValidChild(e){return null===e||this.isElement(e)||this.isObservable(e)||this.isNDElement(e)||["string","number","boolean"].includes(typeof e)},isNDElement:e=>e instanceof f||e?.constructor?.__$isNDElement,isValidChildren(e){Array.isArray(e)||(e=[e]);return 0===e.filter(e=>!this.isValidChild(e)).length},validateChildren(e){Array.isArray(e)||(e=[e]);const t=e.filter(e=>!this.isValidChild(e));if(t.length>0)throw new s(`Invalid children detected: ${t.map(e=>typeof e).join(", ")}`);return e},containsObservables:e=>!!e&&(m.isObject(e)&&Object.values(e).some(e=>m.isObservable(e))),containsObservableReference:e=>!(!e||"string"!=typeof e)&&/\{\{#ObItem::\([0-9]+\)\}\}/.test(e),validateAttributes(e){if(!e||"object"!=typeof e)return e;const t=[],n=Object.keys(e).filter(e=>t.includes(e));return n.length>0&&r.warn("Validator",`Reserved attributes found: ${n.join(", ")}`),e},validateEventCallback(e){if("function"!=typeof e)throw new s("Event callback must be a function")}};function b(e,t=!1){const n=document.createDocumentFragment(),o=document.createComment("Anchor Start : "+e),s=document.createComment("/ Anchor End "+e);n.appendChild(o),n.appendChild(s),n.nativeInsertBefore=n.insertBefore,n.nativeAppendChild=n.appendChild;const i=e=>(console.log("on passwr ici ",t||e.firstChild===o&&e.lastChild===s),t||e.firstChild===o&&e.lastChild===s);return n.appendElement=function(e,t=null){i(s.parentNode)?t&&t!==s?s.parentNode.insertBefore(e,s):s.parentNode.append(e,s):s.parentNode!==n?s.parentNode?.insertBefore(e,t||s):s.parentNode.nativeInsertBefore(e,t||s)},n.appendChild=function(e,t=null){const n=s.parentNode;n?function(e,t,n){const r=m.isElement(t)?t:E.getChild(t);e!==r?i(e)?e.append(r,s):e.insertBefore(r,n):e.nativeInsertBefore(r,n)}(n,e,t=t??s):r.error("Anchor","Anchor : parent not found",e)},n.removeChildren=function(){const e=s.parentNode;if(e===n)return;if(i(e))return void e.replaceChildren(o,s);let t,r=o.nextSibling;const a=document.createDocumentFragment();for(;r&&r!==s;)t=r.nextSibling,a.append(r),r=t;a.replaceChildren()},n.remove=function(){const e=s.parentNode;if(e===n)return;if(i(e))return void e.replaceChildren(s,s);let t,r=o.nextSibling;for(;r!==s;)t=r.nextSibling,n.nativeAppendChild(r),r=t},n.removeWithAnchors=function(){n.removeChildren(),o.remove(),s.remove()},n.replaceContent=function(e){const t=s.parentNode;t&&(i(t)?t.replaceChildren(o,e,s):(n.removeChildren(),t.insertBefore(e,s)))},n.insertBefore=function(e,t=null){n.appendChild(e,t)},n.clear=function(){n.remove()},n.endElement=function(){return s},n.startElement=function(){return o},n}const g=["checked","selected","disabled","readonly","required","autofocus","multiple","autocomplete","hidden","contenteditable","spellcheck","translate","draggable","async","defer","autoplay","controls","loop","muted","download","reversed","open","default","formnovalidate","novalidate","scoped","itemscope","allowfullscreen","allowpaymentrequest","playsinline"];function v(e){return new u(e)}function y(e,t){for(let n in t){const r=t[n];m.isObservable(r)?(e.classList.toggle(n,r.val()),r.subscribe(t=>e.classList.toggle(n,t))):r.$observer?(e.classList.toggle(n,r.$observer.val()===r.$target),r.$observer.on(r.$target,function(t){e.classList.toggle(n,t)})):r.$hydrate?r.$hydrate(e,n):e.classList.toggle(n,r)}}function w(e,t){for(let n in t){const r=t[n];m.isObservable(r)?(e.style[n]=r.val(),r.subscribe(t=>{e.style[n]=t})):e.style[n]=r}}function $(e,t,n){const r=m.isObservable(n)?n.val():n;m.isBoolean(r)?e[t]=r:e[t]=r===e.value,m.isObservable(n)&&(["checked"].includes(t)&&e.addEventListener("input",()=>{m.isBoolean(r)?n.set(e[t]):n.set(e.value)}),n.subscribe(n=>{m.isBoolean(n)?e[t]=n:e[t]=n===e.value}))}function C(e,t,n){const r=n=>{"value"!==t?e.setAttribute(t,n):e.value=n};r(n.val()),n.subscribe(r),"value"===t&&e.addEventListener("input",()=>n.set(e.value))}v.getById=function(e){const t=o.getObservableById(parseInt(e));if(!t)throw new s("Observable.getById : No observable found with id "+e);return t},v.cleanup=function(e){e.cleanup()},v.autoCleanup=function(e=!1,t={}){if(!e)return;const{interval:n=6e4,threshold:r=100}=t;window.addEventListener("beforeunload",()=>{o.cleanup()}),setInterval(()=>o.cleanObservables(r),n)};const O=new Map;let S=null;const E={createTextNode:()=>(S||(S=document.createTextNode("")),S.cloneNode()),createObservableNode(e,t){const n=E.createTextNode();return t.subscribe(e=>n.nodeValue=e),n.nodeValue=t.val(),e&&e.appendChild(n),n},createHydratableNode(e,t){const n=E.createTextNode();return t.$hydrate(n),n},createStaticTextNode(e,t){let n=E.createTextNode();return n.nodeValue=t,e&&e.appendChild(n),n},createElement(e){if(e){if(O.has(e))return O.get(e).cloneNode();const t=document.createElement(e);return O.set(e,t),t.cloneNode()}return new b("Fragment")},processChildren(e,t){if(null===e)return;const n=Array.isArray(e)?e:[e];a.emit("BeforeProcessChildren",t);for(let e=0,r=n.length;e<r;e++){let r=this.getChild(n[e]);null!==r&&t.appendChild(r)}a.emit("AfterProcessChildren",t)},getChild(e){if(null===e)return null;if(m.isString(e)&&(e=e.resolveObservableTemplate?e.resolveObservableTemplate():e,m.isString(e)))return E.createStaticTextNode(null,e);if(m.isElement(e))return e;if(m.isObservable(e))return E.createObservableNode(null,e);if(m.isNDElement(e))return e.$element??e.$build?.()??null;if(m.isArray(e)){const t=document.createDocumentFragment();for(let n=0,r=e.length;n<r;n++)t.appendChild(this.getChild(e[n]));return t}return m.isFunction(e)?(a.emit("BeforeProcessComponent",e),this.getChild(e())):e?.$hydrate?E.createHydratableNode(null,e):E.createStaticTextNode(null,e)},processAttributes(e,t){m.isFragment(e)||t&&function(e,t){if(m.validateAttributes(t),!m.isObject(t))throw new s("Attributes must be an object");for(let n in t){const r=n.toLowerCase();let o=t[r];if(m.isString(o)){if(o=o.resolveObservableTemplate?o.resolveObservableTemplate():o,m.isString(o)){e.setAttribute(r,o);continue}const t=o.filter(e=>m.isObservable(e));o=v.computed(()=>o.map(e=>m.isObservable(e)?e.val():e).join(" ")||" ",t)}"class"===r&&m.isJson(o)?y(e,o):"style"===r&&m.isJson(o)?w(e,o):g.includes(r)?$(e,r,o):m.isObservable(o)?C(e,r,o):e.setAttribute(r,o)}}(e,t)},setup:(e,t,n)=>(a.emit("Setup",e,t,n),e)};Object.defineProperty(HTMLElement.prototype,"nd",{configurable:!0,get(){return this.$nd||(this.$nd=new f(this),this.$nd.nd=this.$nd),this.$nd}});let A=e=>e;t.ArgTypes={},t.ArgTypes={string:()=>!0,number:()=>!0,boolean:()=>!0,observable:()=>!0,element:()=>!0,function:()=>!0,object:()=>!0,objectNotNull:()=>!0,children:()=>!0,attributes:()=>!0,optional:()=>!0,oneOf:()=>!0};const k=function(e,t=null){if(!m.isJson(e)||e?.$hydrate){const n=t;t=e,e=n}return{props:e,children:t}},I=function(e){return m.isObservable(e)?E.createObservableNode(null,e):E.createStaticTextNode(null,e)};function N(e,t){return(n,r=null)=>function(e,t,n=null,r){const{props:o,children:s=null}=k(t,n),i=E.createElement(e),a="function"==typeof r?r(i):i;return E.processAttributes(a,o),E.processChildren(s,a),E.setup(a,o,r)}(e.toLowerCase(),n,r,t)}const T=new WeakMap;function x(e){let t=null;const n=(e,t)=>{const r=T.get(e);if(e instanceof Text)return r?.value?r.value(t):e.cloneNode(!0);const o=e.cloneNode();((e,t,n)=>{if(!t)return null;const r={};if(t.attributes)for(const e in t.attributes)r[e]=t.attributes[e](...n);if(t.classes){r.class={};for(const e in t.classes)r.class[e]=t.classes[e](...n)}if(t.styles){r.style={};for(const e in t.styles)r.style[e]=t.styles[e](...n)}Object.keys(r)&&E.processAttributes(e,r)})(o,r,t),function(e,t,n){if(!t?.attaches)return null;for(const r in t.attaches)e.nd[r](function(...e){t.attaches[r].call(this,...e,...n)})}(o,r,t);for(let r=0,s=e.childNodes.length;r<s;r++){const s=e.childNodes[r],i=n(s,t);o.appendChild(i)}return o};this.clone=r=>{t||(t=e(this));const o=n(t,r);return a.emit("NodeTemplateInstanceCreated",o),o};const r=(e,t)=>({$hydrate:function(n,r){T.has(n)||T.set(n,{});const o=T.get(n);"value"!==t?(o[t]=o[t]||{},o[t][r]=e):o.value=e}});this.style=e=>r(e,"styles"),this.class=e=>r(e,"classes"),this.value=e=>r(function(t){return I(e(...t))},"value"),this.attr=e=>r(e,"attributes"),this.attach=e=>r(e,"attaches")}Function.prototype.args=function(...e){return this},Function.prototype.cached=function(...e){let t=null,n=function(){return t};return()=>(t||(t=this.apply(this,e),t.cloneNode?n=function(){return t.cloneNode(!0)}:t.$element&&(n=function(){return new f(t.$element.cloneNode(!0))})),n())},Function.prototype.errorBoundary=function(e){return(...t)=>{try{return this.apply(this,t)}catch(t){return e(t)}}},String.prototype.use=function(e){const t=this;return v.computed(()=>t.replace(/\$\{(.*?)}/g,(t,n)=>{const r=e[n];return m.isObservable(r)?r.val():r}),Object.values(e))},String.prototype.resolveObservableTemplate=function(){return m.containsObservableReference(this)?this.split(/(\{\{#ObItem::\([0-9]+\)\}\})/g).filter(Boolean).map(e=>{if(!m.containsObservableReference(e))return e;const[t,n]=e.match(/\{\{#ObItem::\(([0-9]+)\)\}\}/);return v.getById(n)}):this.valueOf()};const D=["push","pop","shift","unshift","reverse","sort","splice"];v.array=function(e){if(!Array.isArray(e))throw new s("Observable.array : target must be an array");const t=v(e);a.emit("CreateObservableArray",t),D.forEach(e=>{t[e]=function(...n){const r=t.val()[e](...n);return t.trigger({action:e,args:n,result:r}),r}}),t.clear=function(){return t.val().length=0,t.trigger({action:"clear"}),!0},t.merge=function(e){t.$value.push(...e),t.trigger({action:"merge",args:e})},t.populateAndRender=function(e,n){t.trigger({action:"populate",args:[t.val(),e,n]})},t.remove=function(e){const n=t.val().splice(e,1);return 0===n.length?[]:(t.trigger({action:"remove",args:[e],result:n[0]}),n)},t.swap=function(e,n){const r=t.val(),o=r.length;if(o<e||o<n)return!1;if(n<e){const t=e;e=n,n=t}const s=r[e],i=r[n];return r[e]=i,r[n]=s,t.trigger({action:"swap",args:[e,n],result:[s,i]}),!0},t.length=function(){return t.val().length};return["map","filter","reduce","some","every","find","findIndex","concat"].forEach(e=>{t[e]=function(...n){return t.val()[e](...n)}}),t},v.batch=function(e){const t=v(0),n=function(){if(m.isAsyncFunction(e))return e(...arguments).then(()=>{t.trigger()}).catch(e=>{throw e});e(...arguments),t.trigger()};return n.$observer=t,n},v.init=function(e){const t={};for(const n in e){const r=e[n];m.isJson(r)?t[n]=v.init(r):m.isArray(r)?t[n]=v.array(r):t[n]=v(r)}const n=function(){};return new Proxy(t,{get:(e,r)=>"__isProxy__"===r||("$value"===r?function(){const e={};for(const n in t){const r=t[n];m.isObservable(r)?e[n]=r.val():m.isProxy(r)?e[n]=r.$value:e[n]=r}return e}():"$clone"===r?n:void 0!==e[r]?e[r]:void 0),set(e,t,n){void 0!==e[t]&&e[t].set(n)}})},v.value=function(e){if(m.isObservable(e))return e.val();if(m.isProxy(e))return e.$value;if(m.isArray(e)){const t=[];for(let n=0,r=e.length;n<r;n++){const r=e[n];t.push(v.value(r))}return t}return e},v.update=function(e,t){for(const n in t){const r=e[n],o=t[n];if(m.isObservable(r)){if(m.isArray(o)){v.update(r,o);continue}r.set(o)}else m.isProxy(r)?v.update(r,o):e[n]=o}},v.object=v.init,v.json=v.init,v.computed=function(e,t=[]){const n=new u(e()),r=()=>n.set(e());if(a.emit("CreateObservableComputed",n,t),m.isFunction(t)){if(!m.isObservable(t.$observer))throw new s("Observable.computed : dependencies must be valid batch function");return t.$observer.subscribe(r),n}return t.forEach(e=>e.subscribe(r)),n};const F=function(){const e=new Map;return{use(t){const{observer:n,subscribers:r}=e.get(t),o=v(n.val()),s=n.subscribe(e=>o.set(e)),i=o.subscribe(e=>n.set(e));return o.destroy=()=>{s(),i(),o.cleanup()},r.add(o),o},follow(e){return this.use(e)},create(t,n){const r=v(n);return e.set(t,{observer:r,subscribers:new Set}),r},get(t){const n=e.get(t);return n?n.observer:null},getWithSubscribers:t=>e.get(t),delete(t){const n=e.get(t);n&&(n.observer.cleanup(),n.subscribers.forEach(e=>e.destroy()),n.observer.clear())}}}();const P=function(e,t,n=null){if(!m.isObservable(e))return r.warn("ShowIf","ShowIf : condition must be an Observable / "+n,e);const o=new b("Show if : "+(n||""));let s=null;const i=()=>s||(s=E.getChild(t),s);return e.val()&&o.appendChild(i()),e.subscribe(e=>{e?o.appendChild(i()):o.remove()}),o},R=function(e,t,n=!0){if(!m.isObservable(e))throw new s("Toggle : condition must be an Observable");const r=new b,o=new Map,i=function(e){if(n&&o.has(e))return o.get(e);let r=t[e];return r?(r=E.getChild(r),n&&o.set(e,r),r):null},a=e.val(),u=i(a);return u&&r.appendChild(u),e.subscribe(e=>{const t=i(e);r.remove(),t&&r.appendChild(t)}),r},L=function(e,t,n){if(!m.isObservable(e))throw new s("Toggle : condition must be an Observable");return R(e,{true:t,false:n})},B=N("div"),M=N("span"),q=N("label"),j=N("p"),_=j,V=N("strong"),H=N("h1"),z=N("h2"),W=N("h3"),U=N("h4"),J=N("h5"),K=N("h6"),Q=N("br"),Z=N("a"),G=N("pre"),X=N("code"),Y=N("blockquote"),ee=N("hr"),te=N("em"),ne=N("small"),re=N("mark"),oe=N("del"),se=N("ins"),ie=N("sub"),ae=N("sup"),ue=N("abbr"),le=N("cite"),ce=N("q"),he=N("dl"),de=N("dt"),pe=N("dd"),fe=N("form",function(e){return e.submit=function(t){return"function"==typeof t?(e.onSubmit(e=>{e.preventDefault(),t(e)}),e):(this.setAttribute("action",t),e)},e.multipartFormData=function(){return this.setAttribute("enctype","multipart/form-data"),e},e.post=function(t){return this.setAttribute("method","post"),this.setAttribute("action",t),e},e.get=function(e){this.setAttribute("method","get"),this.setAttribute("action",e)},e}),me=N("input"),be=N("textarea"),ge=be,ve=N("select"),ye=N("fieldset"),we=N("option"),$e=N("legend"),Ce=N("datalist"),Oe=N("output"),Se=N("progress"),Ee=N("meter"),Ae=N("button"),ke=N("main"),Ie=N("section"),Ne=N("article"),Te=N("aside"),xe=N("nav"),De=N("figure"),Fe=N("figcaption"),Pe=N("header"),Re=N("footer"),Le=N("img"),Be=function(e,t){return Le({src:e,...t})},Me=N("details"),qe=N("summary"),je=N("dialog"),_e=N("menu"),Ve=N("ol"),He=N("ul"),ze=N("li"),We=ze,Ue=Ve,Je=He,Ke=N("audio"),Qe=N("video"),Ze=N("source"),Ge=N("track"),Xe=N("canvas"),Ye=N("svg"),et=N("time"),tt=N("data"),nt=N("address"),rt=N("kbd"),ot=N("samp"),st=N("var"),it=N("wbr"),at=N("caption"),ut=N("table"),lt=N("thead"),ct=N("tfoot"),ht=N("tbody"),dt=N("tr"),pt=dt,ft=N("th"),mt=ft,bt=ft,gt=N("td"),vt=gt,yt=N("");var wt=Object.freeze({__proto__:null,Abbr:ue,Address:nt,Anchor:b,Article:Ne,Aside:Te,AsyncImg:function(e,t,n,r){const o=Be(t||e,n),i=new Image;return i.onload=()=>{m.isFunction(r)&&r(null,o),o.src=e},i.onerror=()=>{m.isFunction(r)&&r(new s("Image not found"))},m.isObservable(e)&&e.subscribe(e=>{i.src=e}),i.src=e,o},Audio:Ke,BaseImage:Le,Blockquote:Y,Br:Q,Button:Ae,Canvas:Xe,Caption:at,Checkbox:e=>me({type:"checkbox",...e}),Cite:le,Code:X,ColorInput:e=>me({type:"color",...e}),Data:tt,Datalist:Ce,DateInput:e=>me({type:"date",...e}),DateTimeInput:e=>me({type:"datetime-local",...e}),Dd:pe,Del:oe,Details:Me,Dialog:je,Div:B,Dl:he,Dt:de,Em:te,EmailInput:e=>me({type:"email",...e}),FieldSet:ye,FigCaption:Fe,Figure:De,FileInput:e=>me({type:"file",...e}),Footer:Re,ForEach:function(e,t,n){const o=new b("ForEach"),s=o.endElement();o.startElement();let i=new Map,a=null;const u=new Set,l=e=>{for(const[t,n]of i.entries()){if(u.has(t))continue;const r=n.child?.deref();e&&r&&e.removeChild(r),n.indexObserver?.cleanup(),n.child=null,n.indexObserver=null,i.delete(n.keyId),a&&a.delete(n.keyId)}},h=(e,o)=>{const s=c(e,o,n);if(i.has(s)){const e=i.get(s);if(e.indexObserver?.set(o),e.isNew=!1,e.child?.deref())return s;i.delete(s)}try{const n=t.length>=2?v(o):null;let r=E.getChild(t(e,n));i.set(s,{keyId:s,isNew:!0,child:new WeakRef(r),indexObserver:n})}catch(e){throw r.error("ForEach",`Error creating element for key ${s}`,e),e}return s},d=()=>{const t=s.parentNode;if(!t)return;const n=m.isObservable(e)?e.val():e;if(u.clear(),Array.isArray(n))for(let e=0,t=n.length;e<t;e++){const t=h(n[e],e);u.add(t)}else for(const e in n){const t=h(n[e],e);u.add(t)}if(0===u.size)return o.removeChildren(),l(),void a?.clear();l(t),a&&0!==a.size?(()=>{let e=document.createDocumentFragment();const t=Array.from(u);Array.from(a);for(const n in t){const r=t[n],o=i.get(r);if(!o)continue;const s=o.child.deref();s&&e.appendChild(s)}o.replaceContent(e)})():(e=>{const t=document.createDocumentFragment();for(const e of u){const n=i.get(e);if(!n)continue;const r=n.child?.deref();r&&t.appendChild(r)}e.insertBefore(t,s)})(t),a?.clear(),a=new Set([...u])};return d(),m.isObservable(e)&&e.subscribe(d),o},ForEachArray:function(e,t,n,r={}){const o=new b("ForEach Array"),s=o.endElement(),i=o.startElement();let a=new Map,u=0;const l=t.length>=2,h=new WeakMap,d=()=>{o.removeChildren(),y(),u=0},p=(e,t)=>h.has(e)?h.get(e):c(e,t,n),f=e=>$(p(e)),g=(e,t=!0)=>{if(!e)return;const n=e.child;e.indexObserver?.deref()?.cleanup(),e.child=null,e.indexObserver=null,t&&(n?.remove(),a.delete(e.keyId))},y=()=>{for(const[e,t]of a.entries())g(t,!1);a.clear()},w=(e,n)=>{const r=p(e,n);if(a.has(r)){const e=a.get(r);e.indexObserver?.deref()?.set(n);const t=e.child;if(t)return t;a.delete(r)}const o=l?v(n):null;let s=E.getChild(t(e,o));return a.set(r,{keyId:r,child:s,indexObserver:o?new WeakRef(o):null}),h.set(e,r),s},$=function(e){const t=a.get(e);if(!t)return null;const n=t.child;return n||(g(t,!1),null)},C=function(e,t){const n=a.get(e);if(!n)return null;const r=n.child;if(!r)return null;t?t.appendChild(r):r.remove()},O={toFragment(e,t=0){const n=document.createDocumentFragment();for(let t=0,r=e.length;t<r;t++)n.append(w(e[t],u)),u++;return n},add(e,t=0){const n=O.toFragment(e);setTimeout(()=>{o.appendElement(n)},t)},replace(e){d(),O.add(e)},reOrder(e){let t=null;const n=document.createDocumentFragment();for(const r of e)t=f(r),t&&n.appendChild(t);t=null,o.appendElement(n,s)},removeOne(e,t){((e,t=!0)=>{g(a.get(e),t)})(p(e,t),!0)},clear:d,merge(e){O.add(e,0)},push(e){let t=0;r.pushDelay&&(t=r.pushDelay(e)??0),O.add(e,t)},populate([e,t,n]){const r=document.createDocumentFragment();for(let o=0;o<t;o++){const t=n(o);e.push(t),r.append(w(t,o)),u++}o.appendChild(r),r.replaceChildren()},unshift(e){o.insertBefore(O.toFragment(e),i.nextSibling)},splice(e,t){const[n,r,...i]=e;let a=null;const u=document.createDocumentFragment();if(t.length>0){let e=p(t[0],n);if(1===t.length)C(e,u);else if(t.length>1){const r=$(e);a=r?.previousSibling;for(let e=0;e<t.length;e++){const r=p(t[e],n+e);C(r,u)}}}else a=s;u.replaceChildren(),i&&i.length&&a&&o.insertBefore(O.toFragment(i),a.nextSibling)},reverse(e,t){O.reOrder(t)},sort(e,t){O.reOrder(t)},remove(e,t){O.removeOne(t)},pop(e,t){O.removeOne(t)},shift(e,t){O.removeOne(t)},swap(e,t){const n=s.parentNode;let r=f(t[0]),o=f(t[1]);if(!r||!o)return;const i=o.nextSibling;n.insertBefore(o,r),n.insertBefore(r,i),r=null,o=null}},S=(e,t,n)=>{if("clear"!==n.action&&e.length){if(n?.action)O[n.action]&&O[n.action](n.args,n.result);else{if(0===u)return void O.add(e);O.replace(e)}((e,t=0)=>{if(!l)return;let n=t;for(let r=t,o=e?.length;r<o;r++){const t=a.get(p(e[r],r));t&&(t.indexObserver?.deref()?.set(n),n++)}})(e,0)}else{if(0===u)return;d()}};return S(e.val(),0,{action:null}),m.isObservable(e)&&e.subscribe(S),o},Form:fe,Fragment:yt,H1:H,H2:z,H3:W,H4:U,H5:J,H6:K,Header:Pe,HiddenInput:e=>me({type:"hidden",...e}),HideIf:function(e,t,n){const r=v(!e.val());return e.subscribe(e=>r.set(!e)),P(r,t,n)},HideIfNot:function(e,t,n){return P(e,t,n)},Hr:ee,Img:Be,Input:me,Ins:se,Kbd:rt,Label:q,LazyImg:function(e,t){return Be(e,{...t,loading:"lazy"})},Legend:$e,Li:We,Link:Z,ListItem:ze,Main:ke,Mark:re,Match:R,Menu:_e,Meter:Ee,MonthInput:e=>me({type:"month",...e}),NativeDocumentFragment:b,Nav:xe,NumberInput:e=>me({type:"number",...e}),Ol:Ue,Option:we,OrderedList:Ve,Output:Oe,P:j,Paragraph:_,PasswordInput:e=>me({type:"password",...e}),Pre:G,Progress:Se,Quote:ce,Radio:e=>me({type:"radio",...e}),RangeInput:e=>me({type:"range",...e}),ReadonlyInput:e=>me({readonly:!0,...e}),Samp:ot,SearchInput:e=>me({type:"search",...e}),Section:Ie,Select:ve,ShowIf:P,SimpleButton:(e,t)=>Ae(e,{type:"button",...t}),Small:ne,Source:Ze,Span:M,Strong:V,Sub:ie,SubmitButton:(e,t)=>Ae(e,{type:"submit",...t}),Summary:qe,Sup:ae,Svg:Ye,Switch:L,TBody:ht,TBodyCell:vt,TFoot:ct,TFootCell:bt,THead:lt,THeadCell:mt,TRow:pt,Table:ut,Td:gt,TelInput:e=>me({type:"tel",...e}),TextArea:be,TextInput:ge,Th:ft,Time:et,TimeInput:e=>me({type:"time",...e}),Tr:dt,Track:Ge,Ul:Je,UnorderedList:He,UrlInput:e=>me({type:"url",...e}),Var:st,Video:Qe,Wbr:it,WeekInput:e=>me({type:"week",...e}),When:function(e){if(!m.isObservable(e))throw new s("When : condition must be an Observable");let t=null,n=null;return{show(e){return t=e,this},otherwise:r=>(n=r,L(e,t,n))}}});const $t={};function Ct(e,t,n={}){e="/"+h(e,"/");let r=null,o=n.name||null;const s=n.middlewares||[],i=n.shouldRebuild||!1,a=n.with||{},u={},l=[],c=e=>{if(!e)return null;const[t,n]=e.split(":");let r=a[t];return!r&&n&&(r=$t[n]),r||(r="[^/]+"),r=r.replace("(","(?:"),{name:t,pattern:`(${r})`}},d=()=>{if(r)return r;const t=e.replace(/\{(.*?)}/gi,(e,t)=>{const n=c(t);return n&&n.pattern?(u[n.name]=n.pattern,l.push(n.name),n.pattern):e});return r=new RegExp("^"+t+"$"),r};this.name=()=>o,this.component=()=>t,this.middlewares=()=>s,this.shouldRebuild=()=>i,this.path=()=>e,this.match=function(e){e="/"+h(e,"/");if(!d().exec(e))return!1;const t={};return d().exec(e).forEach((e,n)=>{if(n<1)return;const r=l[n-1];t[r]=e}),t},this.url=function(t){const n=e.replace(/\{(.*?)}/gi,(e,n)=>{const r=c(n);if(t.params&&t.params[r.name])return t.params[r.name];throw new Error(`Missing parameter '${r.name}'`)}),r="object"==typeof t.query?new URLSearchParams(t.query).toString():null;return(t.basePath?t.basePath:"")+(r?`${n}?${r}`:n)}}class Ot extends Error{constructor(e,t){super(e),this.context=t}}const St=(e,t)=>{const n=[];return e.forEach(e=>{n.push(h(e.suffix,"/"))}),n.push(h(t,"/")),n.join("/")},Et=(e,t)=>{const n=[];return e.forEach(e=>{e.options.middlewares&&n.push(...e.options.middlewares)}),t&&n.push(...t),n},At=(e,t)=>{const n=[];return e.forEach(e=>{e.options?.name&&n.push(e.options.name)}),t&&n.push(t),n.join(".")};function kt(){const e=[];let t=0;const n=n=>{const o=t+n;if(!e[o])return;t=o;const{route:s,params:i,query:a,path:u}=e[o];r(u)},r=e=>{window.location.replace(`${window.location.pathname}${window.location.search}#${e}`)},o=()=>window.location.hash.slice(1);this.push=function(n){const{route:s,params:i,query:a,path:u}=this.resolve(n);u!==o()&&(e.splice(t+1),e.push({route:s,params:i,query:a,path:u}),t++,r(u))},this.replace=function(n){const{route:r,params:s,query:i,path:a}=this.resolve(n);a!==o()&&(e[t]={route:r,params:s,query:i,path:a})},this.forward=function(){return t<e.length-1&&n(1)},this.back=function(){return t>0&&n(-1)},this.init=function(n){window.addEventListener("hashchange",()=>{const{route:e,params:t,query:n,path:r}=this.resolve(o());this.handleRouteChange(e,t,n,r)});const{route:r,params:s,query:i,path:a}=this.resolve(n||o());e.push({route:r,params:s,query:i,path:a}),t=0,this.handleRouteChange(r,s,i,a)}}function It(){this.push=function(e){try{const{route:t,path:n,params:r,query:o}=this.resolve(e);if(window.history.state&&window.history.state.path===n)return;window.history.pushState({name:t.name(),params:r,path:n},t.name()||n,n),this.handleRouteChange(t,r,o,n)}catch(e){r.error("HistoryRouter","Error in pushState",e)}},this.replace=function(e){const{route:t,path:n,params:o}=this.resolve(e);try{window.history.replaceState({name:t.name(),params:o,path:n},t.name()||n,n),this.handleRouteChange(t,o,{},n)}catch(e){r.error("HistoryRouter","Error in replaceState",e)}},this.forward=function(){window.history.forward()},this.back=function(){window.history.back()},this.init=function(e){window.addEventListener("popstate",e=>{try{if(!e.state||!e.state.path)return;const t=e.state.path,{route:n,params:r,query:o,path:s}=this.resolve(t);if(!n)return;this.handleRouteChange(n,r,o,s)}catch(e){r.error("HistoryRouter","Error in popstate event",e)}});const{route:t,params:n,query:o,path:s}=this.resolve(e||window.location.pathname+window.location.search);this.handleRouteChange(t,n,o,s)}}function Nt(){const e=[];let t=0;const n=n=>{const r=t+n;if(!e[r])return;t=r;const{route:o,params:s,query:i,path:a}=e[r];this.handleRouteChange(o,s,i,a)};this.push=function(n){const{route:r,params:o,query:s,path:i}=this.resolve(n);e[t]&&e[t].path===i||(e.splice(t+1),e.push({route:r,params:o,query:s,path:i}),t++,this.handleRouteChange(r,o,s,i))},this.replace=function(n){const{route:r,params:o,query:s,path:i}=this.resolve(n);e[t]={route:r,params:o,query:s,path:i},this.handleRouteChange(r,o,s,i)},this.forward=function(){return t<e.length-1&&n(1)},this.back=function(){return t>0&&n(-1)},this.init=function(n){const r=n||window.location.pathname+window.location.search,{route:o,params:s,query:i,path:a}=this.resolve(r);e.push({route:o,params:s,query:i,path:a}),t=0,this.handleRouteChange(o,s,i,a)}}const Tt="default";function xt(e={}){const t=[],n={},o=[],s=[],i={route:null,params:null,query:null,path:null,hash:null};if("hash"===e.mode)kt.apply(this,[]);else if("history"===e.mode)It.apply(this,[]);else{if("memory"!==e.mode)throw new Ot("Invalid router mode "+e.mode);Nt.apply(this,[])}const a=function(e,t){for(const n of s)try{n(e),t&&t(e)}catch(e){r.warn("Route Listener","Error in listener:",e)}};this.routes=()=>[...t],this.currentState=()=>({...i}),this.add=function(e,r,s){const i=new Ct(St(o,e),r,{...s,middlewares:Et(o,s?.middlewares||[]),name:s?.name?At(o,s.name):null});return t.push(i),i.name()&&(n[i.name()]=i),this},this.group=function(e,t,n){if(!m.isFunction(n))throw new Ot("Callback must be a function");return o.push({suffix:e,options:t}),n(),o.pop(),this},this.generateUrl=function(e,t={},r={}){const o=n[e];if(!o)throw new Ot(`Route not found for name: ${e}`);return o.url({params:t,query:r})},this.resolve=function(e){if(m.isJson(e)){const t=n[e.name];if(!t)throw new Ot(`Route not found for name: ${e.name}`);return{route:t,params:e.params,query:e.query,path:t.url({...e})}}const[r,o]=e.split("?"),s="/"+h(r,"/");let i,a=null;for(const e of t)if(i=e.match(s),i){a=e;break}if(!a)throw new Ot(`Route not found for url: ${r}`);const u={};if(o){const e=new URLSearchParams(o).entries();for(const[t,n]of e)u[t]=n}return{route:a,params:i,query:u,path:e}},this.subscribe=function(e){if(!m.isFunction(e))throw new Ot("Listener must be a function");return s.push(e),()=>{s.splice(s.indexOf(e),1)}},this.handleRouteChange=function(e,t,n,r){i.route=e,i.params=t,i.query=n,i.path=r;const o=[...e.middlewares(),a];let s=0;const u={...i},l=e=>{if(s++,!(s>=o.length))return o[s](e||u,l)};return o[s](u,l)}}function Dt(e,t){const{to:n,href:r,...o}=e,s=n||r;if(m.isString(s)){const e=xt.get();return Z({...o,href:s},t).nd.onPreventClick(()=>{e.push(s)})}const i=s.router||Tt,a=xt.get(i);if(!a)throw new Ot('Router not found "'+i+'" for link "'+s.name+'"');const u=a.generateUrl(s.name,s.params,s.query);return Z({...o,href:u},t).nd.onPreventClick(()=>{a.push(u)})}xt.routers={},xt.create=function(t,n){if(!m.isFunction(n))throw r.error("Router","Callback must be a function",e),new Ot("Callback must be a function");const o=new xt(t);return xt.routers[t.name||Tt]=o,n(o),o.init(t.entry),o.mount=function(e){if(m.isString(e)){const t=document.querySelector(e);if(!t)throw new Ot(`Container not found for selector: ${e}`);e=t}else if(!m.isElement(e))throw new Ot("Container must be a string or an Element");return function(e,t){const n=new Map,r=function(e){t.innerHTML="",t.appendChild(e)},o=function(e){if(!e.route)return;const{route:t,params:o,query:s,path:i}=e;if(n.has(i)){const e=n.get(i);return void r(e)}const a=t.component()({params:o,query:s});n.set(i,a),r(a)};return e.subscribe(o),o(e.currentState()),t}(o,e)},o},xt.get=function(e){const t=xt.routers[e||Tt];if(!t)throw new Ot(`Router not found for name: ${e}`);return t},xt.push=function(e,t=null){return xt.get(t).push(e)},xt.replace=function(e,t=null){return xt.get(t).replace(e)},xt.forward=function(e=null){return xt.get(e).forward()},xt.back=function(e=null){return xt.get(e).back()},Dt.blank=function(e,t){return Z({...e,target:"_blank"},t)};var Ft=Object.freeze({__proto__:null,Link:Dt,RouteParamPatterns:$t,Router:xt});return t.ElementCreator=E,t.HtmlElementWrapper=N,t.NDElement=f,t.Observable=v,t.Store=F,t.TemplateCloner=x,t.classPropertyAccumulator=function(e=[]){let t=m.isString(e)?e.split(" ").filter(Boolean):e;const n=m.isArray(t);return{add(e,r=!0){n?t.push(e):t[e]=r},value:()=>n?t.join(" "):{...t}}},t.createTextNode=I,t.cssPropertyAccumulator=function(e={}){let t=m.isString(e)?e.split(";").filter(Boolean):e;const n=m.isArray(t);return{add(e,r){n?t.push(e+" : "+r):t[e]=r},value:()=>n?t.join(";").concat(";"):{...t}}},t.elements=wt,t.normalizeComponentArgs=k,t.router=Ft,t.useCache=function(e){let t=null;return a.emit("NodeTemplateStored",e),function(...n){return t||(t=new x(e),a.emit("NodeTemplateCreated",t)),t.clone(n)}},t.withValidation=A,t}({});
1
+ var NativeDocument=function(t){"use strict";let n={};n={log(){},warn(){},error(){},disable(){}};var r=n;const o=function(){let e=0;const t=new Map;return{register(n){const r=++e;return t.set(r,new WeakRef(n)),r},unregister(e){t.delete(e)},getObservableById:e=>t.get(e)?.deref(),cleanup(){for(const[e,n]of t){const e=n.deref();e&&e.cleanup()}t.clear()},cleanObservables(e){if(t.size<e)return;let n=0;for(const[e,r]of t)r.deref()||(t.delete(e),n++);n>0&&r.log("Memory Auto Clean",`🧹 Cleaned ${n} orphaned observables`)}}}();class s extends Error{constructor(e,t={}){super(e),this.name="NativeDocumentError",this.context=t,this.timestamp=(new Date).toISOString()}}function i(e,t){this.observable=e,this.checker=t,this.unSubscriptions=[]}i.prototype.__$isObservableChecker=!0,i.prototype.subscribe=function(e){const t=this.observable.subscribe(t=>{e&&e(this.checker(t))});return this.unSubscriptions.push(t),t},i.prototype.check=function(e){return this.observable.check(()=>e(this.val()))},i.prototype.val=function(){return this.checker&&this.checker(this.observable.val())},i.prototype.set=function(e){return this.observable.set(e)},i.prototype.trigger=function(){return this.observable.trigger()},i.prototype.cleanup=function(){return this.observable.cleanup()};const a=function(){const e=new Map,t=new Map;return{list:()=>t,add(n,r){if(!r||"object"!=typeof r)throw new Error(`Plugin ${n} must be an object`);if(!e.has(n)){r.$name=n,e.set(n,r),"function"==typeof r?.init&&r.init();for(const e in r)if(/^on[A-Z]/.test(e)){const n=e.replace(/^on/,"");t.has(n)||t.set(n,new Set),t.get(n).add(r)}}},remove(n){if(!e.has(n))return;const r=e.get(n);"function"==typeof r.cleanup&&r.cleanup();for(const[e,n]of t.entries())n.has(r)&&n.delete(r),0===n.size&&t.delete(e);e.delete(n)},emit(e,...n){if(!t.has(e))return;const o=t.get(e);for(const t of o){const o=t[e];if("function"==typeof o)try{o.call(t,...n)}catch(n){r.error("Plugin Manager",`Error in plugin ${t.$name} for event ${e}`,n)}}}}}();function u(e){this.$previousValue=null,this.$currentValue=e,this.$isCleanedUp=!1,this.$listeners=null,this.$watchers=null,this.$memoryId=null,a.emit("CreateObservable",this)}Object.defineProperty(u.prototype,"$value",{get(){return this.$currentValue},set(e){this.set(e)},configurable:!0}),u.prototype.__$isObservable=!0;const l=function(){};u.prototype.triggerFirstListener=function(e){this.$listeners[0](this.$currentValue,this.$previousValue,e||{})},u.prototype.triggerListeners=function(e){const t=this.$listeners,n=this.$previousValue,r=this.$currentValue;e=e||DEFAULT_OPERATIONS;for(let o=0,s=t.length;o<s;o++)t[o](r,n,e)};const c=function(e,t){"function"!=typeof e?e.set?e.set(t):e.forEach(e=>{e.set?e.set(t):e(t)}):e(t)};u.prototype.triggerWatchers=function(){if(!this.$watchers)return;const e=this.$watchers,t=this.$previousValue,n=this.$currentValue;if(e.has(n)){const t=e.get(n);c(t,!0)}if(e.has(t)){const n=e.get(t);c(n,!1)}},u.prototype.triggerAll=function(e){this.triggerListeners(e),this.triggerWatchers()},u.prototype.triggerWatchersAndFirstListener=function(e){this.triggerListeners(e),this.triggerWatchers()},u.prototype.assocTrigger=function(){this.$watchers?.size&&this.$listeners?.length?this.trigger=1===this.$listeners.length?this.triggerWatchersAndFirstListener:this.triggerAll:this.$listeners?.length?this.trigger=1===this.$listeners.length?this.triggerFirstListener:this.triggerListeners:this.$watchers?.size?this.trigger=this.triggerWatchers:this.trigger=l},u.prototype.trigger=l,u.prototype.set=function(e){const t="function"==typeof e?e(this.$currentValue):e;this.$currentValue!==t&&(this.$previousValue=this.$currentValue,this.$currentValue=t,a.emit("ObservableBeforeChange",this),this.trigger(),this.$previousValue=null,a.emit("ObservableAfterChange",this))},u.prototype.val=function(){return this.$currentValue},u.prototype.disconnectAll=function(){if(this.$listeners?.splice(0),this.$previousValue=null,this.$currentValue=null,this.$watchers)for(const[e,t]of this.$watchers)y.isArray(t)&&t.splice(0);this.$watchers?.clear(),this.$listeners=null,this.$watchers=null,this.trigger=l},u.prototype.cleanup=function(){o.unregister(this.$memoryId),this.disconnectAll(),this.$isCleanedUp=!0,delete this.$value},u.prototype.subscribe=function(e,t=null){if(this.$listeners=this.$listeners??[],this.$isCleanedUp)return r.warn("Observable subscription","⚠️ Attempted to subscribe to a cleaned up observable."),()=>{};if("function"!=typeof e)throw new s("Callback must be a function");return this.$listeners.push(e),this.assocTrigger(),a.emit("ObservableSubscribe",this,t),()=>{this.unsubscribe(e),this.assocTrigger(),a.emit("ObservableUnsubscribe",this)}},u.prototype.on=function(e,t){this.$watchers=this.$watchers??new Map;let n=this.$watchers.get(e);if(n){if(!y.isArray(n))return n=[n],void this.$watchers.set(e,n);n.push(t)}else this.$watchers.set(e,t);return this.assocTrigger(),()=>{const r=n.indexOf(t);n?.splice(r,1),1===n.size?this.$watchers.set(e,n[0]):0===n.size&&(this.$watchers?.delete(e),n=null),this.assocTrigger()}},u.prototype.unsubscribe=function(e){const t=this.$listeners.indexOf(e);t>-1&&this.$listeners.splice(t,1),this.assocTrigger()},u.prototype.check=function(e){return new i(this,e)},u.prototype.get=u.prototype.check,u.prototype.when=function(e){return{$target:e,$observer:this}},u.prototype.toString=function(){return this.$memoryId||o.register(this),"{{#ObItem::("+this.$memoryId+")}}"};const h=(e,t,n)=>{if(y.isFunction(n))return n(e,t);if(y.isObservable(e)){const r=e.val();return r&&n?r[n]:t}return y.isObject(e)?e[n]?.val?.()??e[n]??t:e},d=function(e,t){return e.replace(new RegExp(`^[${t}]+|[${t}]+$`,"g"),"")},p={mounted:new WeakMap,mountedSupposedSize:0,unmounted:new WeakMap,unmountedSupposedSize:0,observer:null,checkMutation:function(e){for(const t of e){if(p.mountedSupposedSize>0)for(const e of t.addedNodes){const t=p.mounted.get(e);t&&(t.inDom=!0,t.mounted&&t.mounted(e))}if(p.unmountedSupposedSize>0)for(const e of t.removedNodes){const t=p.unmounted.get(e);t&&(t.inDom=!1,t.unmounted&&!0===t.unmounted(e)&&(t.disconnect(),e.nd?.remove()))}}},watch:function(e,t=!1){let n={inDom:t,mounted:null,unmounted:null,disconnect:()=>{p.mounted.delete(e),p.unmounted.delete(e),p.mountedSupposedSize--,p.unmountedSupposedSize--,n=null}};return{disconnect:n.disconnect,mounted:t=>{n.mounted=t,p.mounted.set(e,n),p.mountedSupposedSize++},unmounted:t=>{n.unmounted=t,p.unmounted.set(e,n),p.unmountedSupposedSize++}}}};p.observer=new MutationObserver(p.checkMutation),p.observer.observe(document.body,{childList:!0,subtree:!0});const f=["Click","DblClick","MouseDown","MouseEnter","MouseLeave","MouseMove","MouseOut","MouseOver","MouseUp","Wheel","KeyDown","KeyPress","KeyUp","Blur","Change","Focus","Input","Invalid","Reset","Search","Select","Submit","Drag","DragEnd","DragEnter","DragLeave","DragOver","DragStart","Drop","AfterPrint","BeforePrint","BeforeUnload","Error","HashChange","Load","Offline","Online","PageHide","PageShow","Resize","Scroll","Unload","Abort","CanPlay","CanPlayThrough","DurationChange","Emptied","Ended","LoadedData","LoadedMetadata","LoadStart","Pause","Play","Playing","Progress","RateChange","Seeked","Seeking","Stalled","Suspend","TimeUpdate","VolumeChange","Waiting","TouchCancel","TouchEnd","TouchMove","TouchStart","AnimationEnd","AnimationIteration","AnimationStart","TransitionEnd","Copy","Cut","Paste","FocusIn","FocusOut","ContextMenu"];function m(e){this.$element=e,this.$observer=null,a.emit("NDElementCreated",e,this)}m.prototype.__$isNDElement=!0,m.prototype.valueOf=function(){return this.$element},m.prototype.ref=function(e,t){return e[t]=this.$element,this},m.prototype.unmountChildren=function(){let e=this.$element;for(let t=0,n=e.children.length;t<n;t++){let n=e.children[t];n.$ndProx||n.nd?.remove(),n=null}return e=null,this},m.prototype.remove=function(){let e=this.$element;return e.nd.unmountChildren(),e.$ndProx=null,delete e.nd?.on?.prevent,delete e.nd?.on,delete e.nd,e=null,this},m.prototype.lifecycle=function(e){return this.$observer=this.$observer||p.watch(this.$element),e.mounted&&this.$observer.mounted(e.mounted),e.unmounted&&this.$observer.unmounted(e.unmounted),this},m.prototype.mounted=function(e){return this.lifecycle({mounted:e})},m.prototype.unmounted=function(e){return this.lifecycle({unmounted:e})},m.prototype.htmlElement=function(){return this.$element},m.prototype.node=m.prototype.htmlElement,m.prototype.attach=function(e){return e.$hydrate(this.$element),this.$element};const b=1,g=3,v=11,y={isObservable:e=>e?.__$isObservable||e instanceof u||e instanceof i,isProxy:e=>e?.__isProxy__,isObservableChecker:e=>e?.__$isObservableChecker||e instanceof i,isArray:e=>Array.isArray(e),isString:e=>"string"==typeof e,isNumber:e=>"number"==typeof e,isBoolean:e=>"boolean"==typeof e,isFunction:e=>"function"==typeof e,isAsyncFunction:e=>"function"==typeof e&&"AsyncFunction"===e.constructor.name,isObject:e=>"object"==typeof e,isJson:e=>"object"==typeof e&&null!==e&&!Array.isArray(e)&&"Object"===e.constructor.name,isElement:e=>e&&(e.nodeType===b||e.nodeType===g||e.nodeType===v),isFragment:e=>e?.nodeType===v,isStringOrObservable(e){return this.isString(e)||this.isObservable(e)},isValidChild(e){return null===e||this.isElement(e)||this.isObservable(e)||this.isNDElement(e)||["string","number","boolean"].includes(typeof e)},isNDElement:e=>e?.__$isNDElement||e instanceof m,isValidChildren(e){Array.isArray(e)||(e=[e]);return 0===e.filter(e=>!this.isValidChild(e)).length},validateChildren(e){Array.isArray(e)||(e=[e]);const t=e.filter(e=>!this.isValidChild(e));if(t.length>0)throw new s(`Invalid children detected: ${t.map(e=>typeof e).join(", ")}`);return e},containsObservables:e=>!!e&&(y.isObject(e)&&Object.values(e).some(e=>y.isObservable(e))),containsObservableReference:e=>!(!e||"string"!=typeof e)&&/\{\{#ObItem::\([0-9]+\)\}\}/.test(e),validateAttributes(e){},validateEventCallback(e){if("function"!=typeof e)throw new s("Event callback must be a function")}};function w(e,t=!1){const n=document.createDocumentFragment(),o=document.createComment("Anchor Start : "+e),s=document.createComment("/ Anchor End "+e);n.appendChild(o),n.appendChild(s),n.nativeInsertBefore=n.insertBefore,n.nativeAppendChild=n.appendChild;const i=e=>t||e.firstChild===o&&e.lastChild===s;return n.appendElement=function(e,t=null){const r=o.parentNode,i=t||s;r!==n?r?.insertBefore(e,i):r.nativeInsertBefore(e,i)},n.appendChild=function(e,t=null){const n=s.parentNode;n?function(e,t,n){const r=y.isElement(t)?t:D.getChild(t);e!==r?i(e)||n===s?e.append(r,n):e.insertBefore(r,n):e.nativeInsertBefore(r,n)}(n,e,t=t??s):r.error("Anchor","Anchor : parent not found",e)},n.removeChildren=function(){const e=s.parentNode;if(e===n)return;if(i(e))return void e.replaceChildren(o,s);let t,r=o.nextSibling;const a=document.createDocumentFragment();for(;r&&r!==s;)t=r.nextSibling,a.append(r),r=t;a.replaceChildren()},n.remove=function(){const e=s.parentNode;if(e===n)return;if(i(e))return void e.replaceChildren(s,s);let t,r=o.nextSibling;for(;r!==s;)t=r.nextSibling,n.nativeAppendChild(r),r=t},n.removeWithAnchors=function(){n.removeChildren(),o.remove(),s.remove()},n.replaceContent=function(e){const t=s.parentNode;t&&(i(t)?t.replaceChildren(o,e,s):(n.removeChildren(),t.insertBefore(e,s)))},n.insertBefore=function(e,t=null){n.appendChild(e,t)},n.clear=function(){n.remove()},n.endElement=function(){return s},n.startElement=function(){return o},n.getByIndex=function(e){let t=o;for(let n=0;n<=e;n++){if(!t.nextSibling)return null;t=t.nextSibling}return t!==o?t:null},n}const $=["checked","selected","disabled","readonly","required","autofocus","multiple","autocomplete","hidden","contenteditable","spellcheck","translate","draggable","async","defer","autoplay","controls","loop","muted","download","reversed","open","default","formnovalidate","novalidate","scoped","itemscope","allowfullscreen","allowpaymentrequest","playsinline"];function C(e){return new u(e)}function O(e,t,n){e.classes.toggle(t,n)}function S(e,t,n){e.style[t]=n}function A(e,t,n){y.isBoolean(n)?e[t]=n:e[t]=n===e.value}function E(e,t,n,r){y.isBoolean(n)?r.set(e[t]):r.set(e.value)}function I(e,t){for(let n in t){const r=t[n];y.isObservable(r)?(e.classes.toggle(n,r.val()),r.subscribe(O.bind(null,e,n))):r.$observer?(e.classes.toggle(n,r.$observer.val()===r.$target),r.$observer.on(r.$target,O.bind(null,e,n))):r.$hydrate?r.$hydrate(e,n):e.classes.toggle(n,r)}t=null}function k(e,t){for(let n in t){const r=t[n];y.isObservable(r)?(e.style[n]=r.val(),r.subscribe(S.bind(null,e,n))):e.style[n]=r}}function x(e,t,n){const r=y.isObservable(n)?n.val():n;y.isBoolean(r)?e[t]=r:e[t]=r===e.value,y.isObservable(n)&&(["checked"].includes(t)&&e.addEventListener("input",E.bind(null,e,t,r)),n.subscribe(A.bind(null,e,t)))}function F(e,t,n){const r=n=>{"value"!==t?e.setAttribute(t,n):e.value=n};r(n.val()),n.subscribe(r),"value"===t&&e.addEventListener("input",()=>n.set(e.value))}C.getById=function(e){const t=o.getObservableById(parseInt(e));if(!t)throw new s("Observable.getById : No observable found with id "+e);return t},C.cleanup=function(e){e.cleanup()},C.autoCleanup=function(e=!1,t={}){if(!e)return;const{interval:n=6e4,threshold:r=100}=t;window.addEventListener("beforeunload",()=>{o.cleanup()}),setInterval(()=>o.cleanObservables(r),n)};const T=new Map;let N=null;const D={createTextNode:()=>(N||(N=document.createTextNode("")),N.cloneNode()),createObservableNode(e,t){const n=D.createTextNode();return t.subscribe(e=>n.nodeValue=e),n.nodeValue=t.val(),e&&e.appendChild(n),n},createHydratableNode(e,t){const n=D.createTextNode();return t.$hydrate(n),n},createStaticTextNode(e,t){let n=D.createTextNode();return n.nodeValue=t,e&&e.appendChild(n),n},createElement(e){if(e){if(T.has(e))return T.get(e).cloneNode();const t=document.createElement(e);return T.set(e,t),t.cloneNode()}return new w("Fragment")},processChildren(e,t){if(null!==e){if(a.emit("BeforeProcessChildren",t),Array.isArray(e))for(let n=0,r=e.length;n<r;n++){let r=this.getChild(e[n]);null!==r&&t.appendChild(r)}else{let n=this.getChild(e);n&&t.appendChild(n)}a.emit("AfterProcessChildren",t)}},getChild(e){if(null===e)return null;if(y.isString(e)&&(e=e.resolveObservableTemplate?e.resolveObservableTemplate():e,y.isString(e)))return D.createStaticTextNode(null,e);if(y.isElement(e))return e;if(y.isObservable(e))return D.createObservableNode(null,e);if(y.isNDElement(e))return e.$element??e.$build?.()??null;if(y.isArray(e)){const t=document.createDocumentFragment();for(let n=0,r=e.length;n<r;n++)t.appendChild(this.getChild(e[n]));return t}return y.isFunction(e)?(a.emit("BeforeProcessComponent",e),this.getChild(e())):e?.$hydrate?D.createHydratableNode(null,e):D.createStaticTextNode(null,e)},processAttributes(e,t){y.isFragment(e)||t&&function(e,t){if(!y.isObject(t))throw new s("Attributes must be an object");for(let n in t){const r=n.toLowerCase();let o=t[r];if(y.isString(o)){if(o=o.resolveObservableTemplate?o.resolveObservableTemplate():o,y.isString(o)){e.setAttribute(r,o);continue}const t=o.filter(e=>y.isObservable(e));o=C.computed(()=>o.map(e=>y.isObservable(e)?e.val():e).join(" ")||" ",t)}"class"===r&&y.isObject(o)?I(e,o):"style"===r&&y.isObject(o)?k(e,o):$.includes(r)?x(e,r,o):y.isObservable(o)?F(e,r,o):o.$hydrate?o.$hydrate(e,r):e.setAttribute(r,o)}}(e,t)},setup:(e,t,n)=>(a.emit("Setup",e,t,n),e)};Object.defineProperty(HTMLElement.prototype,"nd",{configurable:!0,get(){return new m(this)}});const P={getClasses(){return this.$element.className?.split(" ").filter(Boolean)},add(e){const t=this.getClasses();t.indexOf(e)>=0||(t.push(e),this.$element.className=t.join(" "))},remove(e){const t=this.getClasses(),n=t.indexOf(e);n<0||(t.splice(n,1),this.$element.className=t.join(" "))},toggle(e,t=void 0){const n=this.getClasses(),r=n.indexOf(e);if(r>=0){if(!0===t)return;n.splice(r,1)}else{if(!1===t)return;n.push(e)}this.$element.className=n.join(" ")},contains(e){return this.getClasses().indexOf(e)>=0}};Object.defineProperty(HTMLElement.prototype,"classes",{configurable:!0,get(){return{$element:this,...P}}});let L=e=>e;t.ArgTypes={},t.ArgTypes={string:()=>!0,number:()=>!0,boolean:()=>!0,observable:()=>!0,element:()=>!0,function:()=>!0,object:()=>!0,objectNotNull:()=>!0,children:()=>!0,attributes:()=>!0,optional:()=>!0,oneOf:()=>!0};const R=function(e,t=null){if(!y.isJson(e)||e?.$hydrate){const n=t;t=e,e=n}return{props:e,children:t}},B=function(e){return y.isObservable(e)?D.createObservableNode(null,e):D.createStaticTextNode(null,e)};function M(e,t,n,r=null){let{props:o,children:s=null}=R(n,r),i=D.createElement(e),a=t&&"function"==typeof t?t(i):i;return o&&D.processAttributes(a,o),s&&D.processChildren(s,a),D.setup(a,o,t)}function j(e,t){return M.bind(null,e.toLowerCase(),t)}const q=new WeakMap;function _(e){let t=null;const n=(e,t)=>{const r=q.get(e);if(3===e.nodeType)return r&&r.value?r.value(t):e.cloneNode(!0);const o=e.cloneNode();r&&(((e,t,n)=>{let r=null;if(t.attributes){r=r||{};for(const e in t.attributes)r[e]=t.attributes[e](...n)}if(t.classes){r=r||{},r.class={};for(const e in t.classes)r.class[e]=t.classes[e](...n)}if(t.styles){r=r||{},r.style={};for(const e in t.styles)r.style[e]=t.styles[e](...n)}r&&D.processAttributes(e,r)})(o,r,t),function(e,t,n){if(!t.attach)return null;t.attach(e,...n)}(o,r,t));const s=e.childNodes;for(let e=0,r=s.length;e<r;e++){const r=s[e],i=n(r,t);o.appendChild(i)}return o};this.clone=r=>(t||(t=e(this)),n(t,r));const r=(e,t)=>({$hydrate:(n,r)=>function(e,t,n,r){q.has(n)||q.set(n,{});const o=q.get(n);"value"!==t?"attach"!==t?(o[t]=o[t]||{},o[t][r]=e):o.attach=e:o.value=e}(e,t,n,r)});this.style=e=>r(e,"styles"),this.class=e=>r(e,"classes"),this.property=e=>this.value(e),this.value=e=>r("function"!=typeof e?function(t){const n=t[0];return B(n[e])}:function(t){return B(e(...t))},"value"),this.attr=e=>r(e,"attributes"),this.attach=e=>r(e,"attach")}Function.prototype.args=function(...e){return this},Function.prototype.cached=function(...e){let t=null,n=function(){return t};return()=>(t||(t=this.apply(this,e),t.cloneNode?n=function(){return t.cloneNode(!0)}:t.$element&&(n=function(){return new m(t.$element.cloneNode(!0))})),n())},Function.prototype.errorBoundary=function(e){return(...t)=>{try{return this.apply(this,t)}catch(t){return e(t)}}},String.prototype.use=function(e){const t=this;return C.computed(()=>t.replace(/\$\{(.*?)}/g,(t,n)=>{const r=e[n];return y.isObservable(r)?r.val():r}),Object.values(e))},String.prototype.resolveObservableTemplate=function(){return y.containsObservableReference(this)?this.split(/(\{\{#ObItem::\([0-9]+\)\}\})/g).filter(Boolean).map(e=>{if(!y.containsObservableReference(e))return e;const[t,n]=e.match(/\{\{#ObItem::\(([0-9]+)\)\}\}/);return C.getById(n)}):this.valueOf()},function(){const e={},t=function(t,n,r){if(!t)return;if(!e[n]){const o=new WeakMap;return e[n]=o,void o.set(t,r)}const o=e[n];if(!o.has(t))return void o.set(t,r);const s=o.get(t);y.isArray(s)?s.push(r):o.set(t,[store[n],r])},n=function(e,t,n){return e.addEventListener(t,t=>{t.preventDefault(),n&&n.call(e,t)}),this},r=function(e,t,n){return e.addEventListener(t,t=>{t.stopPropagation(),n&&n.call(e,t)}),this},o=function(e,t,n){return e.addEventListener(t,t=>{t.stopPropagation(),t.preventDefault(),n&&n.call(e,t)}),this},s=function(t,n,r){return r?(t.addEventListener(n,r),this):(function(t,n){t.addEventListener(n,r=>{const o=e[n];if(!o)return;let s=r.target;for(;s&&s!==t;){const e=o.get(s);if(e){if(y.isFunction(e))e.call(s,r);else for(let t=0;t<e.length;t++)e[t].call(s,r);return}s=s.parentElement}})}(t,n),this)};for(const e of f){const i=e.toLowerCase();m.prototype["on"+e]=function(e){return this.$element.addEventListener(i,e),this},m.prototype["onPrevent"+e]=function(e){return n(this.$element,i,e)},m.prototype["onStop"+e]=function(e){return r(this.$element,i,e)},m.prototype["onPreventStop"+e]=function(e){return o(this.$element,i,e)},m.prototype["when"+e]=function(e){return t(this.$element,i,e),this},m.prototype["capture"+e]=function(e){return s(this.$element,i,e),this}}}();const V=["push","pop","shift","unshift","reverse","sort","splice"];C.array=function(e){if(!Array.isArray(e))throw new s("Observable.array : target must be an array");const t=C(e);a.emit("CreateObservableArray",t),V.forEach(e=>{t[e]=function(...n){const r=t.val()[e](...n);return t.trigger({action:e,args:n,result:r}),r}}),t.clear=function(){return t.val().length=0,t.trigger({action:"clear"}),!0},t.merge=function(e){t.$value.push(...e),t.trigger({action:"merge",args:e})},t.populateAndRender=function(e,n){t.trigger({action:"populate",args:[t.val(),e,n]})},t.remove=function(e){const n=t.val().splice(e,1);return 0===n.length?[]:(t.trigger({action:"remove",args:[e],result:n[0]}),n)},t.swap=function(e,n){const r=t.val(),o=r.length;if(o<e||o<n)return!1;if(n<e){const t=e;e=n,n=t}const s=r[e],i=r[n];return r[e]=i,r[n]=s,t.trigger({action:"swap",args:[e,n],result:[s,i]}),!0},t.length=function(){return t.val().length};return["map","filter","reduce","some","every","find","findIndex","concat","includes","indexOf"].forEach(e=>{t[e]=(...n)=>t.val()[e](...n)}),t},C.batch=function(e){const t=C(0),n=function(){if(y.isAsyncFunction(e))return e(...arguments).then(()=>{t.trigger()}).catch(e=>{throw e});e(...arguments),t.trigger()};return n.$observer=t,n},C.init=function(e){const t={};for(const n in e){const r=e[n];y.isJson(r)?t[n]=C.init(r):y.isArray(r)?t[n]=C.array(r):t[n]=C(r)}const n=function(){},r=function(e){C.update(o,e)},o=new Proxy(t,{get:(e,o)=>"__isProxy__"===o||("$value"===o?function(){const e={};for(const n in t){const r=t[n];y.isObservable(r)?e[n]=r.val():y.isProxy(r)?e[n]=r.$value:e[n]=r}return e}():"$clone"===o?n:"$observables"===o?Object.values(e):"$updateWith"===o?r:void 0!==e[o]?e[o]:void 0),set:(e,t,n)=>void 0===e[t]||(y.isObservable(n)?e[t].set(n.val()):e[t].set(n),!0)});return o},C.arrayOfObject=function(e){return e.map(e=>C.object(e))},C.value=function(e){if(y.isObservable(e))return e.val();if(y.isProxy(e))return e.$value;if(y.isArray(e)){const t=[];for(let n=0,r=e.length;n<r;n++){const r=e[n];t.push(C.value(r))}return t}return e},C.update=function(e,t){y.isProxy(t)&&(t=t.$value);for(const n in t){const r=e[n],o=t[n];if(y.isObservable(r)){if(y.isArray(o)){r.set([...o]);continue}r.set(o)}else y.isProxy(r)?C.update(r,o):e[n]=o}},C.object=C.init,C.json=C.init,C.computed=function(e,t=[]){const n=new u(e()),r=()=>n.set(e());if(a.emit("CreateObservableComputed",n,t),y.isFunction(t)){if(!y.isObservable(t.$observer))throw new s("Observable.computed : dependencies must be valid batch function");return t.$observer.subscribe(r),n}return t.forEach(e=>{y.isProxy(e)?e.$observables.forEach(e=>{e.subscribe(r)}):e.subscribe(r)}),n};const H=function(){const e=new Map;return{use(t){const{observer:n,subscribers:r}=e.get(t),o=C(n.val()),s=n.subscribe(e=>o.set(e)),i=o.subscribe(e=>n.set(e));return o.destroy=()=>{s(),i(),o.cleanup()},r.add(o),o},follow(e){return this.use(e)},create(t,n){const r=C(n);return e.set(t,{observer:r,subscribers:new Set}),r},get(t){const n=e.get(t);return n?n.observer:null},getWithSubscribers:t=>e.get(t),delete(t){const n=e.get(t);n&&(n.observer.cleanup(),n.subscribers.forEach(e=>e.destroy()),n.observer.clear())}}}();const W=function(e,t,{comment:n=null,shouldKeepInCache:o=!0}={}){if(!y.isObservable(e))return r.warn("ShowIf","ShowIf : condition must be an Observable / "+n,e);const s=new w("Show if : "+(n||""));let i=null;const a=()=>(i&&o||(i=D.getChild(t),y.isFragment(i)&&(i=Array.from(i.children))),i);return e.val()&&s.appendChild(a()),e.subscribe(e=>{e?s.appendChild(a()):s.remove()}),s},z=function(e,t,n=!0){if(!y.isObservable(e))throw new s("Toggle : condition must be an Observable");const r=new w,o=new Map,i=function(e){if(n&&o.has(e))return o.get(e);let r=t[e];return r?(r=D.getChild(r),y.isFragment(r)&&(r=Array.from(r.children)),n&&o.set(e,r),r):null},a=e.val(),u=i(a);return u&&r.appendChild(u),e.subscribe(e=>{const t=i(e);r.remove(),t&&r.appendChild(t)}),r},U=function(e,t,n){if(!y.isObservable(e))throw new s("Toggle : condition must be an Observable");return z(e,{true:t,false:n})},K=j("div"),J=j("span"),Q=j("label"),Z=j("p"),G=Z,X=j("strong"),Y=j("h1"),ee=j("h2"),te=j("h3"),ne=j("h4"),re=j("h5"),oe=j("h6"),se=j("br"),ie=j("a"),ae=j("pre"),ue=j("code"),le=j("blockquote"),ce=j("hr"),he=j("em"),de=j("small"),pe=j("mark"),fe=j("del"),me=j("ins"),be=j("sub"),ge=j("sup"),ve=j("abbr"),ye=j("cite"),we=j("q"),$e=j("dl"),Ce=j("dt"),Oe=j("dd"),Se=j("form",function(e){return e.submit=function(t){return"function"==typeof t?(e.onSubmit(e=>{e.preventDefault(),t(e)}),e):(this.setAttribute("action",t),e)},e.multipartFormData=function(){return this.setAttribute("enctype","multipart/form-data"),e},e.post=function(t){return this.setAttribute("method","post"),this.setAttribute("action",t),e},e.get=function(e){this.setAttribute("method","get"),this.setAttribute("action",e)},e}),Ae=j("input"),Ee=j("textarea"),Ie=Ee,ke=j("select"),xe=j("fieldset"),Fe=j("option"),Te=j("legend"),Ne=j("datalist"),De=j("output"),Pe=j("progress"),Le=j("meter"),Re=j("button"),Be=j("main"),Me=j("section"),je=j("article"),qe=j("aside"),_e=j("nav"),Ve=j("figure"),He=j("figcaption"),We=j("header"),ze=j("footer"),Ue=j("img"),Ke=function(e,t){return Ue({src:e,...t})},Je=j("details"),Qe=j("summary"),Ze=j("dialog"),Ge=j("menu"),Xe=j("ol"),Ye=j("ul"),et=j("li"),tt=et,nt=Xe,rt=Ye,ot=j("audio"),st=j("video"),it=j("source"),at=j("track"),ut=j("canvas"),lt=j("svg"),ct=j("time"),ht=j("data"),dt=j("address"),pt=j("kbd"),ft=j("samp"),mt=j("var"),bt=j("wbr"),gt=j("caption"),vt=j("table"),yt=j("thead"),wt=j("tfoot"),$t=j("tbody"),Ct=j("tr"),Ot=Ct,St=j("th"),At=St,Et=St,It=j("td"),kt=It,xt=j("");var Ft=Object.freeze({__proto__:null,Abbr:ve,Address:dt,Anchor:w,Article:je,Aside:qe,AsyncImg:function(e,t,n,r){const o=Ke(t||e,n),i=new Image;return i.onload=()=>{y.isFunction(r)&&r(null,o),o.src=e},i.onerror=()=>{y.isFunction(r)&&r(new s("Image not found"))},y.isObservable(e)&&e.subscribe(e=>{i.src=e}),i.src=e,o},Audio:ot,BaseImage:Ue,Blockquote:le,Br:se,Button:Re,Canvas:ut,Caption:gt,Checkbox:e=>Ae({type:"checkbox",...e}),Cite:ye,Code:ue,ColorInput:e=>Ae({type:"color",...e}),Data:ht,Datalist:Ne,DateInput:e=>Ae({type:"date",...e}),DateTimeInput:e=>Ae({type:"datetime-local",...e}),Dd:Oe,Del:fe,Details:Je,Dialog:Ze,Div:K,Dl:$e,Dt:Ce,Em:he,EmailInput:e=>Ae({type:"email",...e}),FieldSet:xe,FigCaption:He,Figure:Ve,FileInput:e=>Ae({type:"file",...e}),Footer:ze,ForEach:function(e,t,n,{shouldKeepItemsInCache:o=!1}={}){const i=new w("ForEach"),a=i.endElement();i.startElement();let u=new Map,l=null;const c=new Set,d=e=>{if(!o)for(const[t,n]of u.entries()){if(c.has(t))continue;const r=n.child?.deref();e&&r&&e.removeChild(r),n.indexObserver?.cleanup(),n.child=null,n.indexObserver=null,u.delete(n.keyId),l&&l.delete(n.keyId)}},p=(e,o)=>{const i=h(e,o,n);if(u.has(i)){const e=u.get(i);if(e.indexObserver?.set(o),e.isNew=!1,e.child?.deref())return i;u.delete(i)}try{const n=t.length>=2?C(o):null;let r=D.getChild(t(e,n));if(!r||y.isFragment(r))throw new s("ForEachArray child can't be null or undefined!");u.set(i,{keyId:i,isNew:!0,child:new WeakRef(r),indexObserver:n})}catch(e){throw r.error("ForEach",`Error creating element for key ${i}`,e),e}return i},f=()=>{const t=a.parentNode;if(!t)return;const n=y.isObservable(e)?e.val():e;if(c.clear(),Array.isArray(n))for(let e=0,t=n.length;e<t;e++){const t=p(n[e],e);c.add(t)}else for(const e in n){const t=p(n[e],e);c.add(t)}if(0===c.size)return i.removeChildren(),d(),void l?.clear();d(t),l&&0!==l.size?(()=>{let e=document.createDocumentFragment();const t=Array.from(c);Array.from(l);for(const n in t){const r=t[n],o=u.get(r);if(!o)continue;const s=o.child.deref();s&&e.appendChild(s)}i.replaceContent(e)})():(e=>{const t=document.createDocumentFragment();for(const e of c){const n=u.get(e);if(!n)continue;const r=n.child?.deref();r&&t.appendChild(r)}e.insertBefore(t,a)})(t),l?.clear(),l=new Set([...c])};return f(),y.isObservable(e)&&e.subscribe(f),i},ForEachArray:function(e,t,n,r={}){const o=new w("ForEach Array"),i=o.endElement(),a=o.startElement();let u=new Map,l=0;const c=t.length>=2,d=new WeakMap,p=()=>{o.removeChildren(),g(),l=0},f=(e,t)=>d.has(e)?d.get(e):h(e,t,n),m=e=>$(f(e)),b=(e,t=!0)=>{if(e){if(t){const t=e.child;t?.remove(),u.delete(e.keyId)}e.indexObserver?.deref()?.cleanup()}},g=()=>{if(!r.shouldKeepItemsInCache)if(c){for(const[e,t]of u.entries())b(t,!1);u.clear()}else u.clear()},v=(e,n)=>{const r=f(e,n);if(u.has(r)){const e=u.get(r);e.indexObserver?.deref()?.set(n);const t=e.child;if(t)return t;u.delete(r)}const o=c?C(n):null;let i=D.getChild(t(e,o));if(!i||y.isFragment(i))throw new s("ForEachArray child can't be null or undefined!");return u.set(r,{keyId:r,child:i,indexObserver:o?new WeakRef(o):null}),d.set(e,r),i},$=function(e){const t=u.get(e);if(!t)return null;const n=t.child;return n||(b(t,!1),null)},O=function(e,t){const n=u.get(e);if(!n)return null;const r=n.child;if(!r)return null;t?t.appendChild(r):r.remove()},S={toFragment(e,t=0){const n=document.createDocumentFragment();for(let t=0,r=e.length;t<r;t++)n.appendChild(v(e[t],l)),l++;return n},add(e,t=2){const n=S.toFragment(e);setTimeout(()=>{o.appendElement(n)},t)},replace(e){p(),S.add(e)},reOrder(e){let t=null;const n=document.createDocumentFragment();for(const r of e)t=m(r),t&&n.appendChild(t);t=null,o.appendElement(n,i)},removeOne(e,t){((e,t=!0)=>{b(u.get(e),t)})(f(e,t),!0)},clear:p,merge(e){S.add(e)},push(e){let t=0;r.pushDelay&&(t=r.pushDelay(e)??0),S.add(e,t)},populate([e,t,n]){const r=document.createDocumentFragment();for(let o=0;o<t;o++){const t=n(o);e.push(t),r.append(v(t,o)),l++}o.appendChild(r),r.replaceChildren()},unshift(e){o.insertBefore(S.toFragment(e),a.nextSibling)},splice(e,t){const[n,r,...s]=e;let a=null;const u=document.createDocumentFragment();if(t.length>0){let e=f(t[0],n);if(1===t.length)O(e,u);else if(t.length>1){const r=$(e);a=r?.previousSibling;for(let e=0;e<t.length;e++){const r=f(t[e],n+e);O(r,u)}}}else a=i;u.replaceChildren(),s&&s.length&&a&&o.insertBefore(S.toFragment(s),a.nextSibling)},reverse(e,t){S.reOrder(t)},sort(e,t){S.reOrder(t)},remove(e,t){S.removeOne(t)},pop(e,t){S.removeOne(t)},shift(e,t){S.removeOne(t)},swap(e,t){const n=i.parentNode;let r=m(t[0]),o=m(t[1]);if(!r||!o)return;const s=o.nextSibling;n.insertBefore(o,r),n.insertBefore(r,s),r=null,o=null}},A=(e,t,n)=>{if("clear"!==n.action&&e.length){if(n?.action)S[n.action]&&S[n.action](n.args,n.result);else{if(0===l)return void S.add(e);S.replace(e)}((e,t=0)=>{if(!c)return;let n=t;for(let r=t,o=e?.length;r<o;r++){const t=u.get(f(e[r],r));t&&(t.indexObserver?.deref()?.set(n),n++)}})(e,0)}else{if(0===l)return;p()}};return e.val().length&&A(e.val(),0,{action:null}),y.isObservable(e)&&e.subscribe(A),o},Form:Se,Fragment:xt,H1:Y,H2:ee,H3:te,H4:ne,H5:re,H6:oe,Header:We,HiddenInput:e=>Ae({type:"hidden",...e}),HideIf:function(e,t,n){const r=C(!e.val());return e.subscribe(e=>r.set(!e)),W(r,t,n)},HideIfNot:function(e,t,n){return W(e,t,n)},Hr:ce,Img:Ke,Input:Ae,Ins:me,Kbd:pt,Label:Q,LazyImg:function(e,t){return Ke(e,{...t,loading:"lazy"})},Legend:Te,Li:tt,Link:ie,ListItem:et,Main:Be,Mark:pe,Match:z,Menu:Ge,Meter:Le,MonthInput:e=>Ae({type:"month",...e}),NativeDocumentFragment:w,Nav:_e,NumberInput:e=>Ae({type:"number",...e}),Ol:nt,Option:Fe,OrderedList:Xe,Output:De,P:Z,Paragraph:G,PasswordInput:e=>Ae({type:"password",...e}),Pre:ae,Progress:Pe,Quote:we,Radio:e=>Ae({type:"radio",...e}),RangeInput:e=>Ae({type:"range",...e}),ReadonlyInput:e=>Ae({readonly:!0,...e}),Samp:ft,SearchInput:e=>Ae({type:"search",...e}),Section:Me,Select:ke,ShowIf:W,SimpleButton:(e,t)=>Re(e,{type:"button",...t}),Small:de,Source:it,Span:J,Strong:X,Sub:be,SubmitButton:(e,t)=>Re(e,{type:"submit",...t}),Summary:Qe,Sup:ge,Svg:lt,Switch:U,TBody:$t,TBodyCell:kt,TFoot:wt,TFootCell:Et,THead:yt,THeadCell:At,TRow:Ot,Table:vt,Td:It,TelInput:e=>Ae({type:"tel",...e}),TextArea:Ee,TextInput:Ie,Th:St,Time:ct,TimeInput:e=>Ae({type:"time",...e}),Tr:Ct,Track:at,Ul:rt,UnorderedList:Ye,UrlInput:e=>Ae({type:"url",...e}),Var:mt,Video:st,Wbr:bt,WeekInput:e=>Ae({type:"week",...e}),When:function(e){if(!y.isObservable(e))throw new s("When : condition must be an Observable");let t=null,n=null;return{show(e){return t=e,this},otherwise:r=>(n=r,U(e,t,n))}}});const Tt={};function Nt(e,t,n={}){e="/"+d(e,"/");let r=null,o=n.name||null;const s=n.middlewares||[],i=n.shouldRebuild||!1,a=n.with||{},u={},l=[],c=e=>{if(!e)return null;const[t,n]=e.split(":");let r=a[t];return!r&&n&&(r=Tt[n]),r||(r="[^/]+"),r=r.replace("(","(?:"),{name:t,pattern:`(${r})`}},h=()=>{if(r)return r;const t=e.replace(/\{(.*?)}/gi,(e,t)=>{const n=c(t);return n&&n.pattern?(u[n.name]=n.pattern,l.push(n.name),n.pattern):e});return r=new RegExp("^"+t+"$"),r};this.name=()=>o,this.component=()=>t,this.middlewares=()=>s,this.shouldRebuild=()=>i,this.path=()=>e,this.match=function(e){e="/"+d(e,"/");if(!h().exec(e))return!1;const t={};return h().exec(e).forEach((e,n)=>{if(n<1)return;const r=l[n-1];t[r]=e}),t},this.url=function(t){const n=e.replace(/\{(.*?)}/gi,(e,n)=>{const r=c(n);if(t.params&&t.params[r.name])return t.params[r.name];throw new Error(`Missing parameter '${r.name}'`)}),r="object"==typeof t.query?new URLSearchParams(t.query).toString():null;return(t.basePath?t.basePath:"")+(r?`${n}?${r}`:n)}}class Dt extends Error{constructor(e,t){super(e),this.context=t}}const Pt=(e,t)=>{const n=[];return e.forEach(e=>{n.push(d(e.suffix,"/"))}),n.push(d(t,"/")),n.join("/")},Lt=(e,t)=>{const n=[];return e.forEach(e=>{e.options.middlewares&&n.push(...e.options.middlewares)}),t&&n.push(...t),n},Rt=(e,t)=>{const n=[];return e.forEach(e=>{e.options?.name&&n.push(e.options.name)}),t&&n.push(t),n.join(".")};function Bt(){const e=[];let t=0;const n=n=>{const o=t+n;if(!e[o])return;t=o;const{route:s,params:i,query:a,path:u}=e[o];r(u)},r=e=>{window.location.replace(`${window.location.pathname}${window.location.search}#${e}`)},o=()=>window.location.hash.slice(1);this.push=function(n){const{route:s,params:i,query:a,path:u}=this.resolve(n);u!==o()&&(e.splice(t+1),e.push({route:s,params:i,query:a,path:u}),t++,r(u))},this.replace=function(n){const{route:r,params:s,query:i,path:a}=this.resolve(n);a!==o()&&(e[t]={route:r,params:s,query:i,path:a})},this.forward=function(){return t<e.length-1&&n(1)},this.back=function(){return t>0&&n(-1)},this.init=function(n){window.addEventListener("hashchange",()=>{const{route:e,params:t,query:n,path:r}=this.resolve(o());this.handleRouteChange(e,t,n,r)});const{route:r,params:s,query:i,path:a}=this.resolve(n||o());e.push({route:r,params:s,query:i,path:a}),t=0,this.handleRouteChange(r,s,i,a)}}function Mt(){this.push=function(e){try{const{route:t,path:n,params:r,query:o}=this.resolve(e);if(window.history.state&&window.history.state.path===n)return;window.history.pushState({name:t.name(),params:r,path:n},t.name()||n,n),this.handleRouteChange(t,r,o,n)}catch(e){r.error("HistoryRouter","Error in pushState",e)}},this.replace=function(e){const{route:t,path:n,params:o}=this.resolve(e);try{window.history.replaceState({name:t.name(),params:o,path:n},t.name()||n,n),this.handleRouteChange(t,o,{},n)}catch(e){r.error("HistoryRouter","Error in replaceState",e)}},this.forward=function(){window.history.forward()},this.back=function(){window.history.back()},this.init=function(e){window.addEventListener("popstate",e=>{try{if(!e.state||!e.state.path)return;const t=e.state.path,{route:n,params:r,query:o,path:s}=this.resolve(t);if(!n)return;this.handleRouteChange(n,r,o,s)}catch(e){r.error("HistoryRouter","Error in popstate event",e)}});const{route:t,params:n,query:o,path:s}=this.resolve(e||window.location.pathname+window.location.search);this.handleRouteChange(t,n,o,s)}}function jt(){const e=[];let t=0;const n=n=>{const r=t+n;if(!e[r])return;t=r;const{route:o,params:s,query:i,path:a}=e[r];this.handleRouteChange(o,s,i,a)};this.push=function(n){const{route:r,params:o,query:s,path:i}=this.resolve(n);e[t]&&e[t].path===i||(e.splice(t+1),e.push({route:r,params:o,query:s,path:i}),t++,this.handleRouteChange(r,o,s,i))},this.replace=function(n){const{route:r,params:o,query:s,path:i}=this.resolve(n);e[t]={route:r,params:o,query:s,path:i},this.handleRouteChange(r,o,s,i)},this.forward=function(){return t<e.length-1&&n(1)},this.back=function(){return t>0&&n(-1)},this.init=function(n){const r=n||window.location.pathname+window.location.search,{route:o,params:s,query:i,path:a}=this.resolve(r);e.push({route:o,params:s,query:i,path:a}),t=0,this.handleRouteChange(o,s,i,a)}}const qt="default";function _t(e={}){const t=[],n={},o=[],s=[],i={route:null,params:null,query:null,path:null,hash:null};if("hash"===e.mode)Bt.apply(this,[]);else if("history"===e.mode)Mt.apply(this,[]);else{if("memory"!==e.mode)throw new Dt("Invalid router mode "+e.mode);jt.apply(this,[])}const a=function(e,t){for(const n of s)try{n(e),t&&t(e)}catch(e){r.warn("Route Listener","Error in listener:",e)}};this.routes=()=>[...t],this.currentState=()=>({...i}),this.add=function(e,r,s){const i=new Nt(Pt(o,e),r,{...s,middlewares:Lt(o,s?.middlewares||[]),name:s?.name?Rt(o,s.name):null});return t.push(i),i.name()&&(n[i.name()]=i),this},this.group=function(e,t,n){if(!y.isFunction(n))throw new Dt("Callback must be a function");return o.push({suffix:e,options:t}),n(),o.pop(),this},this.generateUrl=function(e,t={},r={}){const o=n[e];if(!o)throw new Dt(`Route not found for name: ${e}`);return o.url({params:t,query:r})},this.resolve=function(e){if(y.isJson(e)){const t=n[e.name];if(!t)throw new Dt(`Route not found for name: ${e.name}`);return{route:t,params:e.params,query:e.query,path:t.url({...e})}}const[r,o]=e.split("?"),s="/"+d(r,"/");let i,a=null;for(const e of t)if(i=e.match(s),i){a=e;break}if(!a)throw new Dt(`Route not found for url: ${r}`);const u={};if(o){const e=new URLSearchParams(o).entries();for(const[t,n]of e)u[t]=n}return{route:a,params:i,query:u,path:e}},this.subscribe=function(e){if(!y.isFunction(e))throw new Dt("Listener must be a function");return s.push(e),()=>{s.splice(s.indexOf(e),1)}},this.handleRouteChange=function(e,t,n,r){i.route=e,i.params=t,i.query=n,i.path=r;const o=[...e.middlewares(),a];let s=0;const u={...i},l=e=>{if(s++,!(s>=o.length))return o[s](e||u,l)};return o[s](u,l)}}function Vt(e,t){const{to:n,href:r,...o}=e,s=n||r;if(y.isString(s)){const e=_t.get();return ie({...o,href:s},t).nd.onPreventClick(()=>{e.push(s)})}const i=s.router||qt,a=_t.get(i);if(!a)throw new Dt('Router not found "'+i+'" for link "'+s.name+'"');const u=a.generateUrl(s.name,s.params,s.query);return ie({...o,href:u},t).nd.onPreventClick(()=>{a.push(u)})}_t.routers={},_t.create=function(t,n){if(!y.isFunction(n))throw r.error("Router","Callback must be a function",e),new Dt("Callback must be a function");const o=new _t(t);return _t.routers[t.name||qt]=o,n(o),o.init(t.entry),o.mount=function(e){if(y.isString(e)){const t=document.querySelector(e);if(!t)throw new Dt(`Container not found for selector: ${e}`);e=t}else if(!y.isElement(e))throw new Dt("Container must be a string or an Element");return function(e,t){const n=new Map,r=function(e){t.innerHTML="",t.appendChild(e)},o=function(e){if(!e.route)return;const{route:t,params:o,query:s,path:i}=e;if(n.has(i)){const e=n.get(i);return void r(e)}const a=t.component()({params:o,query:s});n.set(i,a),r(a)};return e.subscribe(o),o(e.currentState()),t}(o,e)},o},_t.get=function(e){const t=_t.routers[e||qt];if(!t)throw new Dt(`Router not found for name: ${e}`);return t},_t.push=function(e,t=null){return _t.get(t).push(e)},_t.replace=function(e,t=null){return _t.get(t).replace(e)},_t.forward=function(e=null){return _t.get(e).forward()},_t.back=function(e=null){return _t.get(e).back()},Vt.blank=function(e,t){return ie({...e,target:"_blank"},t)};var Ht=Object.freeze({__proto__:null,Link:Vt,RouteParamPatterns:Tt,Router:_t});return t.ElementCreator=D,t.HtmlElementWrapper=j,t.NDElement=m,t.Observable=C,t.Store=H,t.TemplateCloner=_,t.classPropertyAccumulator=function(e=[]){let t=y.isString(e)?e.split(" ").filter(Boolean):e;const n=y.isArray(t);return{add(e,r=!0){n?t.push(e):t[e]=r},value:()=>n?t.join(" "):{...t}}},t.createTextNode=B,t.cssPropertyAccumulator=function(e={}){let t=y.isString(e)?e.split(";").filter(Boolean):e;const n=y.isArray(t);return{add(e,r){n?t.push(e+" : "+r):t[e]=r},value:()=>n?t.join(";").concat(";"):{...t}}},t.elements=Ft,t.normalizeComponentArgs=R,t.router=Ht,t.useCache=function(e){let t=null;const n=function(n){return t||(t=new _(e)),t.clone(n)};return e.length<2?function(...e){return n(e)}:function(e,t,...r){return n([e,t,...r])}},t.withValidation=L,t}({});
package/index.js CHANGED
@@ -4,6 +4,7 @@ export { NDElement } from './src/wrappers/NDElement'
4
4
  export { TemplateCloner, useCache } from './src/wrappers/TemplateCloner'
5
5
 
6
6
  import './src/utils/prototypes.js';
7
+ import './src/wrappers/NDElementEventPrototypes';
7
8
 
8
9
  export * from './src/utils/property-accumulator';
9
10
  export * from './src/utils/plugins-manager';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "native-document",
3
- "version": "1.0.35",
3
+ "version": "1.0.37",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -11,7 +11,7 @@ import Validator from "../utils/validator";
11
11
  * @class ObservableItem
12
12
  */
13
13
  export default function ObservableItem(value) {
14
- this.$previousValue = value;
14
+ this.$previousValue = null;
15
15
  this.$currentValue = value;
16
16
  this.$isCleanedUp = false;
17
17
 
@@ -35,19 +35,33 @@ Object.defineProperty(ObservableItem.prototype, '$value', {
35
35
  ObservableItem.prototype.__$isObservable = true;
36
36
 
37
37
  const noneTrigger = function() {};
38
+ ObservableItem.prototype.triggerFirstListener = function(operations) {
39
+ this.$listeners[0](this.$currentValue, this.$previousValue, operations || {});
40
+ }
38
41
  ObservableItem.prototype.triggerListeners = function(operations) {
39
42
  const $listeners = this.$listeners;
40
43
  const $previousValue = this.$previousValue;
41
44
  const $currentValue = this.$currentValue;
42
45
 
43
- operations = operations || {};
44
- if($listeners?.length) {
45
- for(let i = 0, length = $listeners.length; i < length; i++) {
46
- $listeners[i]($currentValue, $previousValue, operations);
47
- }
46
+ operations = operations || DEFAULT_OPERATIONS;
47
+ for(let i = 0, length = $listeners.length; i < length; i++) {
48
+ $listeners[i]($currentValue, $previousValue, operations);
48
49
  }
49
50
  };
50
51
 
52
+ const handleWatcherCallback = function(callbacks, value) {
53
+ if(typeof callbacks === "function") {
54
+ callbacks(value);
55
+ return;
56
+ }
57
+ if (callbacks.set) {
58
+ callbacks.set(value);
59
+ return;
60
+ }
61
+ callbacks.forEach(callback => {
62
+ callback.set ? callback.set(value) : callback(value);
63
+ });
64
+ }
51
65
  ObservableItem.prototype.triggerWatchers = function() {
52
66
  if(!this.$watchers) {
53
67
  return;
@@ -59,28 +73,11 @@ ObservableItem.prototype.triggerWatchers = function() {
59
73
 
60
74
  if($watchers.has($currentValue)) {
61
75
  const $currentValueCallbacks = $watchers.get($currentValue);
62
- if(typeof $currentValueCallbacks === "function") {
63
- $currentValueCallbacks(true);
64
- } else if ($currentValueCallbacks.set) {
65
- $currentValueCallbacks.set(true)
66
- }
67
- else {
68
- $currentValueCallbacks.forEach(callback => {
69
- callback.set ? callback.set(true) : callback(true);
70
- });
71
- }
76
+ handleWatcherCallback($currentValueCallbacks, true);
72
77
  }
73
78
  if($watchers.has($previousValue)) {
74
79
  const $previousValueCallbacks = $watchers.get($previousValue);
75
- if(typeof $previousValueCallbacks === "function") {
76
- $previousValueCallbacks(false);
77
- } else if($previousValueCallbacks.set) {
78
- $previousValueCallbacks.set(false)
79
- } else {
80
- $previousValueCallbacks.forEach(callback => {
81
- callback.set ? callback.set(false) : callback(false);
82
- });
83
- }
80
+ handleWatcherCallback($previousValueCallbacks, false);
84
81
  }
85
82
  };
86
83
 
@@ -89,13 +86,18 @@ ObservableItem.prototype.triggerAll = function(operations) {
89
86
  this.triggerWatchers();
90
87
  };
91
88
 
89
+ ObservableItem.prototype.triggerWatchersAndFirstListener = function(operations) {
90
+ this.triggerListeners(operations);
91
+ this.triggerWatchers();
92
+ };
93
+
92
94
  ObservableItem.prototype.assocTrigger = function() {
93
95
  if(this.$watchers?.size && this.$listeners?.length) {
94
- this.trigger = this.triggerAll;
96
+ this.trigger = (this.$listeners.length === 1) ? this.triggerWatchersAndFirstListener : this.triggerAll;
95
97
  return;
96
98
  }
97
99
  if(this.$listeners?.length) {
98
- this.trigger = this.triggerListeners;
100
+ this.trigger = (this.$listeners.length === 1) ? this.triggerFirstListener : this.triggerListeners;
99
101
  return;
100
102
  }
101
103
  if(this.$watchers?.size) {
@@ -73,9 +73,9 @@ Observable.array = function(target) {
73
73
  return observer.val().length;
74
74
  }
75
75
 
76
- const overrideMethods = ['map', 'filter', 'reduce', 'some', 'every', 'find', 'findIndex', 'concat'];
76
+ const overrideMethods = ['map', 'filter', 'reduce', 'some', 'every', 'find', 'findIndex', 'concat', 'includes', 'indexOf'];
77
77
  overrideMethods.forEach((method) => {
78
- observer[method] = function(...args) {
78
+ observer[method] = (...args) => {
79
79
  return observer.val()[method](...args);
80
80
  };
81
81
  })
@@ -25,7 +25,15 @@ Observable.computed = function(callback, dependencies = []) {
25
25
  return observable;
26
26
  }
27
27
 
28
- dependencies.forEach(dependency => dependency.subscribe(updatedValue));
28
+ dependencies.forEach(dependency => {
29
+ if(Validator.isProxy(dependency)) {
30
+ dependency.$observables.forEach((observable) => {
31
+ observable.subscribe(updatedValue);
32
+ });
33
+ return;
34
+ }
35
+ dependency.subscribe(updatedValue);
36
+ });
29
37
 
30
38
  return observable;
31
39
  };
@@ -3,13 +3,13 @@ import {Observable} from "../Observable";
3
3
 
4
4
  /**
5
5
  *
6
- * @param {Object} value
6
+ * @param {Object} initialValue
7
7
  * @returns {Proxy}
8
8
  */
9
- Observable.init = function(value) {
9
+ Observable.init = function(initialValue) {
10
10
  const data = {};
11
- for(const key in value) {
12
- const itemValue = value[key];
11
+ for(const key in initialValue) {
12
+ const itemValue = initialValue[key];
13
13
  if(Validator.isJson(itemValue)) {
14
14
  data[key] = Observable.init(itemValue);
15
15
  continue;
@@ -38,8 +38,11 @@ Observable.init = function(value) {
38
38
  const $clone = function() {
39
39
 
40
40
  };
41
+ const $updateWith = function(values) {
42
+ Observable.update(proxy, values);
43
+ };
41
44
 
42
- return new Proxy(data, {
45
+ const proxy = new Proxy(data, {
43
46
  get(target, property) {
44
47
  if(property === '__isProxy__') {
45
48
  return true;
@@ -50,6 +53,12 @@ Observable.init = function(value) {
50
53
  if(property === '$clone') {
51
54
  return $clone;
52
55
  }
56
+ if(property === '$observables') {
57
+ return Object.values(target);
58
+ }
59
+ if(property === '$updateWith') {
60
+ return $updateWith;
61
+ }
53
62
  if(target[property] !== undefined) {
54
63
  return target[property];
55
64
  }
@@ -57,12 +66,27 @@ Observable.init = function(value) {
57
66
  },
58
67
  set(target, prop, newValue) {
59
68
  if(target[prop] !== undefined) {
60
- target[prop].set(newValue);
69
+ Validator.isObservable(newValue)
70
+ ? target[prop].set(newValue.val())
71
+ : target[prop].set(newValue);
72
+ return true;
61
73
  }
74
+ return true;
62
75
  }
63
- })
76
+ });
77
+
78
+ return proxy;
64
79
  };
65
80
 
81
+ /**
82
+ *
83
+ * @param {any[]} data
84
+ * @return Proxy[]
85
+ */
86
+ Observable.arrayOfObject = function(data) {
87
+ return data.map(item => Observable.object(item));
88
+ }
89
+
66
90
  /**
67
91
  * Get the value of an observable or an object of observables.
68
92
  * @param {ObservableItem|Object<ObservableItem>} data
@@ -88,13 +112,16 @@ Observable.value = function(data) {
88
112
 
89
113
 
90
114
  Observable.update = function($target, data) {
115
+ if(Validator.isProxy(data)) {
116
+ data = data.$value;
117
+ }
91
118
  for(const key in data) {
92
119
  const targetItem = $target[key];
93
120
  const newValue = data[key];
94
121
 
95
122
  if(Validator.isObservable(targetItem)) {
96
123
  if(Validator.isArray(newValue)) {
97
- Observable.update(targetItem, newValue);
124
+ targetItem.set([...newValue]);
98
125
  continue;
99
126
  }
100
127
  targetItem.set(newValue);
@@ -15,10 +15,7 @@ export default function Anchor(name, isUniqueChild = false) {
15
15
  element.nativeInsertBefore = element.insertBefore;
16
16
  element.nativeAppendChild = element.appendChild;
17
17
 
18
- const isParentUniqueChild = (parent) => {
19
- console.log('on passwr ici ', isUniqueChild || (parent.firstChild === anchorStart && parent.lastChild === anchorEnd))
20
- return isUniqueChild || (parent.firstChild === anchorStart && parent.lastChild === anchorEnd);
21
- };
18
+ const isParentUniqueChild = (parent) => (isUniqueChild || (parent.firstChild === anchorStart && parent.lastChild === anchorEnd))
22
19
 
23
20
  const insertBefore = function(parent, child, target) {
24
21
  const element = Validator.isElement(child) ? child : ElementCreator.getChild(child);
@@ -26,25 +23,21 @@ export default function Anchor(name, isUniqueChild = false) {
26
23
  parent.nativeInsertBefore(element, target);
27
24
  return;
28
25
  }
29
- if(isParentUniqueChild(parent)) {
30
- parent.append(element, anchorEnd);
26
+ if(isParentUniqueChild(parent) || target === anchorEnd) {
27
+ parent.append(element, target);
31
28
  return;
32
29
  }
33
30
  parent.insertBefore(element, target);
34
31
  };
35
32
 
36
33
  element.appendElement = function(child, before = null) {
37
- if(isParentUniqueChild(anchorEnd.parentNode)) {
38
- (before && before !== anchorEnd)
39
- ? anchorEnd.parentNode.insertBefore(child, anchorEnd)
40
- : anchorEnd.parentNode.append(child, anchorEnd);
41
- return;
42
- }
43
- if(anchorEnd.parentNode === element) {
44
- anchorEnd.parentNode.nativeInsertBefore(child, before || anchorEnd);
34
+ const parentNode = anchorStart.parentNode;
35
+ const targetBefore = before || anchorEnd;
36
+ if(parentNode === element) {
37
+ parentNode.nativeInsertBefore(child, targetBefore);
45
38
  return;
46
39
  }
47
- anchorEnd.parentNode?.insertBefore(child, before || anchorEnd);
40
+ parentNode?.insertBefore(child, targetBefore);
48
41
  };
49
42
 
50
43
  element.appendChild = function(child, before = null) {
@@ -123,9 +116,21 @@ export default function Anchor(name, isUniqueChild = false) {
123
116
  element.endElement = function() {
124
117
  return anchorEnd;
125
118
  };
119
+
126
120
  element.startElement = function() {
127
121
  return anchorStart;
128
122
  };
129
123
 
124
+ element.getByIndex = function(index) {
125
+ let currentNode = anchorStart;
126
+ for(let i = 0; i <= index; i++) {
127
+ if(!currentNode.nextSibling) {
128
+ return null;
129
+ }
130
+ currentNode = currentNode.nextSibling;
131
+ }
132
+ return currentNode !== anchorStart ? currentNode : null;
133
+ };
134
+
130
135
  return element;
131
136
  };
@@ -1,9 +1,9 @@
1
1
  import Anchor from "../anchor";
2
2
  import {Observable} from "../../data/Observable";
3
3
  import Validator from "../../utils/validator";
4
- import DebugManager from "../../utils/debug-manager";
5
4
  import {getKey} from "../../utils/helpers";
6
5
  import { ElementCreator } from "../../wrappers/ElementCreator";
6
+ import NativeDocumentError from "../../errors/NativeDocumentError";
7
7
 
8
8
  export function ForEachArray(data, callback, key, configs = {}) {
9
9
  const element = new Anchor('ForEach Array');
@@ -50,14 +50,12 @@ export function ForEachArray(data, callback, key, configs = {}) {
50
50
  if(!cacheItem) {
51
51
  return;
52
52
  }
53
- const child = cacheItem.child;
54
- cacheItem.indexObserver?.deref()?.cleanup();
55
- cacheItem.child = null;
56
- cacheItem.indexObserver = null;
57
53
  if(removeChild) {
54
+ const child = cacheItem.child;
58
55
  child?.remove();
59
56
  cache.delete(cacheItem.keyId);
60
57
  }
58
+ cacheItem.indexObserver?.deref()?.cleanup();
61
59
  }
62
60
 
63
61
  const removeCacheItemByKey = (keyId, removeChild = true) => {
@@ -65,6 +63,13 @@ export function ForEachArray(data, callback, key, configs = {}) {
65
63
  };
66
64
 
67
65
  const cleanCache = () => {
66
+ if(configs.shouldKeepItemsInCache) {
67
+ return;
68
+ }
69
+ if(!isIndexRequired) {
70
+ cache.clear();
71
+ return;
72
+ }
68
73
  for (const [keyId, cacheItem] of cache.entries()) {
69
74
  removeCacheItem(cacheItem, false);
70
75
  }
@@ -86,6 +91,9 @@ export function ForEachArray(data, callback, key, configs = {}) {
86
91
 
87
92
  const indexObserver = isIndexRequired ? Observable(indexKey) : null;
88
93
  let child = ElementCreator.getChild(callback(item, indexObserver));
94
+ if(!child || Validator.isFragment(child)) {
95
+ throw new NativeDocumentError("ForEachArray child can't be null or undefined!");
96
+ }
89
97
  cache.set(keyId, {
90
98
  keyId,
91
99
  child: child,
@@ -128,12 +136,12 @@ export function ForEachArray(data, callback, key, configs = {}) {
128
136
  toFragment(items, startIndexFrom = 0){
129
137
  const fragment = document.createDocumentFragment();
130
138
  for(let i = 0, length = items.length; i < length; i++) {
131
- fragment.append(buildItem(items[i], lastNumberOfItems));
139
+ fragment.appendChild(buildItem(items[i], lastNumberOfItems));
132
140
  lastNumberOfItems++;
133
141
  }
134
142
  return fragment;
135
143
  },
136
- add(items, delay = 0) {
144
+ add(items, delay = 2) {
137
145
  const fragment = Actions.toFragment(items);
138
146
  setTimeout(() => {
139
147
  element.appendElement(fragment);
@@ -160,7 +168,7 @@ export function ForEachArray(data, callback, key, configs = {}) {
160
168
  },
161
169
  clear,
162
170
  merge(items) {
163
- Actions.add(items, 0);
171
+ Actions.add(items);
164
172
  },
165
173
  push(items) {
166
174
  let delay = 0;
@@ -267,7 +275,9 @@ export function ForEachArray(data, callback, key, configs = {}) {
267
275
  updateIndexObservers(items, 0);
268
276
  };
269
277
 
270
- buildContent(data.val(), null, {action: null});
278
+ if(data.val().length) {
279
+ buildContent(data.val(), null, {action: null});
280
+ }
271
281
  if(Validator.isObservable(data)) {
272
282
  data.subscribe(buildContent);
273
283
  }