native-document 1.0.24 → 1.0.26

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 i extends Error{constructor(e,t={}){super(e),this.name="NativeDocumentError",this.context=t,this.timestamp=(new Date).toISOString()}}function s(e,t){this.observable=e,this.checker=t,this.unSubscriptions=[]}function a(e){this.$previousValue=e,this.$currentValue=e,this.$isCleanedUp=!1,this.$listeners=null,this.$watchers=null,this.$memoryId=null}s.prototype.__$isObservableChecker=!0,s.prototype.subscribe=function(e){const t=this.observable.subscribe(t=>{e&&e(this.checker(t))});return this.unSubscriptions.push(t),t},s.prototype.check=function(e){return this.observable.check(()=>e(this.val()))},s.prototype.val=function(){return this.checker&&this.checker(this.observable.val())},s.prototype.set=function(e){return this.observable.set(e)},s.prototype.trigger=function(){return this.observable.trigger()},s.prototype.cleanup=function(){return this.observable.cleanup()},Object.defineProperty(a.prototype,"$value",{get(){return this.$currentValue},set(e){this.set(e)},configurable:!0}),a.prototype.__$isObservable=!0;const u=function(){};a.prototype.triggerListeners=function(e){const t=this.$listeners,n=this.$previousValue,r=this.$currentValue;if(e=e||{},t?.length)for(let o=0,i=t.length;o<i;o++)t[o](r,n,e)},a.prototype.triggerWatchers=function(){if(!this.$watchers)return;const e=this.$watchers,t=this.$previousValue,n=this.$currentValue;e.has(n)&&e.get(n).forEach(e=>{e.set?e.set(!0):e(!0)}),e.has(t)&&e.get(t).forEach(e=>{e.set?e.set(!1):e(!1)})},a.prototype.triggerAll=function(e){this.triggerListeners(e),this.triggerWatchers()},a.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=u},a.prototype.trigger=u,a.prototype.set=function(e){const t="function"==typeof e?e(this.$currentValue):e;this.$currentValue!==t&&(this.$previousValue=this.$currentValue,this.$currentValue=t,this.trigger())},a.prototype.val=function(){return this.$currentValue},a.prototype.disconnectAll=function(){if(this.$listeners?.splice(0),this.$previousValue=null,this.$currentValue=null,this.$watchers)for(const[e,t]of this.$watchers)t.splice(0);this.$watchers?.clear(),this.$listeners=null,this.$watchers=null,this.trigger=u},a.prototype.cleanup=function(){o.unregister(this.$memoryId),this.disconnectAll(),this.$isCleanedUp=!0,delete this.$value},a.prototype.subscribe=function(e){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 i("Callback must be a function");return this.$listeners.push(e),this.assocTrigger(),()=>{this.unsubscribe(e),this.assocTrigger()}},a.prototype.on=function(e,t){this.$watchers=this.$watchers??new Map;let n=this.$watchers.get(e);return n||(n=[],this.$watchers.set(e,n)),n.push(t),this.assocTrigger(),()=>{const r=n.indexOf(t);n?.splice(r,1),0===n.size&&(this.$watchers?.delete(e),n=null),this.assocTrigger()}},a.prototype.unsubscribe=function(e){const t=this.$listeners.indexOf(e);t>-1&&this.$listeners.splice(t,1),this.assocTrigger()},a.prototype.check=function(e){return new s(this,e)},a.prototype.get=a.prototype.check,a.prototype.toString=function(){return this.$memoryId||o.register(this),"{{#ObItem::("+this.$memoryId+")}}"};const l=(e,t,n)=>{if(f.isFunction(n))return n(e,t);if(f.isObservable(e)){const r=e.val();return r&&n?r[n]:t}return f.isObject(e)?e[n]??t:e},c=function(e,t){return e.replace(new RegExp(`^[${t}]+|[${t}]+$`,"g"),"")},h={mounted:new WeakMap,mountedSupposedSize:0,unmounted:new WeakMap,unmountedSupposedSize:0,observer:null,checkMutation:function(e){for(const t of e){if(h.mountedSupposedSize>0)for(const e of t.addedNodes){const t=h.mounted.get(e);t&&(t.inDom=!0,t.mounted&&t.mounted(e))}if(h.unmountedSupposedSize>0)for(const e of t.removedNodes){const t=h.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:()=>{h.mounted.delete(e),h.unmounted.delete(e),h.mountedSupposedSize--,h.unmountedSupposedSize--,n=null}};return{disconnect:n.disconnect,mounted:t=>{n.mounted=t,h.mounted.set(e,n),h.mountedSupposedSize++},unmounted:t=>{n.unmounted=t,h.unmounted.set(e,n),h.unmountedSupposedSize++}}}};h.observer=new MutationObserver(h.checkMutation),h.observer.observe(document.body,{childList:!0,subtree:!0});const d=["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"];function p(e){this.$element=e,this.$observer=null}p.prototype.__$isNDElement=!0;for(const e of d){const t=e.toLowerCase();p.prototype["on"+e]=function(e){return this.$element.addEventListener(t,e),this},p.prototype["onPrevent"+e]=function(e){return this.$element.addEventListener(t,function(t){t.preventDefault(),e(t)}),this},p.prototype["onStop"+e]=function(e){return this.$element.addEventListener(t,function(t){t.stopPropagation(),e(t)}),this},p.prototype["onPreventStop"+e]=function(e){return this.$element.addEventListener(t,function(t){t.stopPropagation(),t.preventDefault(),e(t)}),this}}p.prototype.ref=function(e,t){return e[t]=this.$element,this},p.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},p.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},p.prototype.lifecycle=function(e){return this.$observer=this.$observer||h.watch(this.$element),e.mounted&&this.$observer.mounted(e.mounted),e.unmounted&&this.$observer.unmounted(e.unmounted),this},p.prototype.mounted=function(e){return this.lifecycle({mounted:e})},p.prototype.unmounted=function(e){return this.lifecycle({unmounted:e})},p.prototype.htmlElement=function(){return this.$element},p.prototype.node=p.prototype.htmlElement;const f={isObservable:e=>e instanceof a||e instanceof s||e?.__$isObservable,isProxy:e=>e?.__isProxy__,isObservableChecker:e=>e instanceof s||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 p||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 i(`Invalid children detected: ${t.map(e=>typeof e).join(", ")}`);return e},containsObservables:e=>!!e&&(f.isObject(e)&&Object.values(e).some(e=>f.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 i("Event callback must be a function")}};function m(e){const t=document.createDocumentFragment(),n=document.createComment("Anchor Start : "+e),o=document.createComment("/ Anchor End "+e);t.appendChild(n),t.appendChild(o),t.nativeInsertBefore=t.insertBefore,t.nativeAppendChild=t.appendChild;const i=function(e,n,r){e!==t?e.insertBefore(S.getChild(n),r):e.nativeInsertBefore(S.getChild(n),r)};return t.appendElement=function(e,n=null){o.parentNode!==t?o.parentNode?.insertBefore(e,n||o):o.parentNode.nativeInsertBefore(e,n||o)},t.appendChild=function(e,n=null){const s=o.parentNode;if(s){if(n=n??o,f.isArray(e)){const r=document.createDocumentFragment();for(let t=0,n=e.length;t<n;t++)r.appendChild(S.getChild(e[t]));return i(s,r,n),t}i(s,e,n)}else r.error("Anchor","Anchor : parent not found",e)},t.removeChildren=function(){const e=o.parentNode;if(e===t)return;if(e.firstChild===n&&e.lastChild===o)return void e.replaceChildren(n,o);let r,i=n.nextSibling;const s=document.createDocumentFragment();for(;i&&i!==o;)r=i.nextSibling,s.append(i),i=r;s.replaceChildren()},t.remove=function(){if(o.parentNode===t)return;let e,r=n.nextSibling;for(;r!==o;)e=r.nextSibling,t.nativeAppendChild(r),r=e},t.removeWithAnchors=function(){t.removeChildren(),n.remove(),o.remove()},t.replaceContent=function(e){const r=o.parentNode;r&&(r.firstChild!==n||r.lastChild!==o?(t.removeChildren(),r.insertBefore(e,o)):r.replaceChildren(n,e,o))},t.insertBefore=function(e,n=null){t.appendChild(e,n)},t.clear=function(){t.remove()},t.endElement=function(){return o},t.startElement=function(){return n},t}const b=["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 g(e){return new a(e)}function v(e,t){for(let n in t){const r=t[n];f.isObservable(r)?(e.classList.toggle(n,r.val()),r.subscribe(t=>e.classList.toggle(n,t))):e.classList.toggle(n,r)}}function y(e,t){for(let n in t){const r=t[n];f.isObservable(r)?(e.style[n]=r.val(),r.subscribe(t=>{e.style[n]=t})):e.style[n]=r}}function w(e,t,n){const r=f.isObservable(n)?n.val():n;f.isBoolean(r)?e[t]=r:e[t]=r===e.value,f.isObservable(n)&&(["checked"].includes(t)&&e.addEventListener("input",()=>{f.isBoolean(r)?n.set(e[t]):n.set(e.value)}),n.subscribe(n=>{f.isBoolean(n)?e[t]=n:e[t]=n===e.value}))}function $(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))}g.getById=function(e){const t=o.getObservableById(parseInt(e));if(!t)throw new i("Observable.getById : No observable found with id "+e);return t},g.cleanup=function(e){e.cleanup()},g.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 C=new Map;let O=null;const S={createTextNode:()=>(O||(O=document.createTextNode("")),O.cloneNode()),createObservableNode(e,t){const n=S.createTextNode();return t.subscribe(e=>n.nodeValue=String(e)),n.nodeValue=t.val(),e&&e.appendChild(n),n},createStaticTextNode(e,t){let n=S.createTextNode();return n.nodeValue=String(t),e&&e.appendChild(n),n},createElement(e){if(e){if(C.has(e))return C.get(e).cloneNode();const t=document.createElement(e);return C.set(e,t),t.cloneNode()}return new m("Fragment")},processChildren(e,t){if(null===e)return;const n=Array.isArray(e)?e:[e];for(let e=0,r=n.length;e<r;e++){let r=this.getChild(n[e]);null!==r&&t.appendChild(r)}},getChild(e){if(null===e)return null;if(f.isString(e)&&f.isFunction(e.resolveObservableTemplate)&&(e=e.resolveObservableTemplate()),f.isString(e))return S.createStaticTextNode(null,e);if(f.isObservable(e))return S.createObservableNode(null,e);if(f.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 f.isFunction(e)?this.getChild(e()):f.isElement(e)?e:f.isNDElement(e)?e.$element??e.$build?.()??null:S.createStaticTextNode(null,e)},processAttributes(e,t){f.isFragment(e)||t&&function(e,t){if(f.validateAttributes(t),!f.isObject(t))throw new i("Attributes must be an object");for(let n in t){const r=n.toLowerCase();let o=t[r];if(f.isString(o)&&f.isFunction(o.resolveObservableTemplate)){if(o=o.resolveObservableTemplate(),f.isString(o)){e.setAttribute(r,o);continue}const t=o.filter(e=>f.isObservable(e));o=g.computed(()=>o.map(e=>f.isObservable(e)?e.val():e).join(" ")||" ",t)}"class"===r&&f.isJson(o)?v(e,o):"style"===r&&f.isJson(o)?y(e,o):b.includes(r)?w(e,r,o):f.isObservable(o)?$(e,r,o):e.setAttribute(r,o)}}(e,t)},setup:(e,t,n)=>e};function E(e,t){const n=e.toLowerCase();return function(e,o=null){try{if(!f.isJson(e)){const t=o;o=e,e=t}const r=S.createElement(n),i="function"==typeof t?t(r):r;return S.processAttributes(i,e),S.processChildren(o,i),S.setup(i,e,t)}catch(e){r.error("ElementCreation",`Error creating ${n}`,e)}}}Object.defineProperty(HTMLElement.prototype,"nd",{configurable:!0,get(){return this.$nd||(this.$nd=new p(this),this.$nd.nd=this.$nd),this.$nd}});class A extends Error{constructor(e,t){super(`${e}\n\n${t.join("\n")}\n\n`)}}const k={string:e=>({name:e,type:"string",validate:e=>f.isString(e)}),number:e=>({name:e,type:"number",validate:e=>f.isNumber(e)}),boolean:e=>({name:e,type:"boolean",validate:e=>f.isBoolean(e)}),observable:e=>({name:e,type:"observable",validate:e=>f.isObservable(e)}),element:e=>({name:e,type:"element",validate:e=>f.isElement(e)}),function:e=>({name:e,type:"function",validate:e=>f.isFunction(e)}),object:e=>({name:e,type:"object",validate:e=>f.isObject(e)}),objectNotNull:e=>({name:e,type:"object",validate:e=>f.isObject(e)&&null!==e}),children:e=>({name:e,type:"children",validate:e=>f.validateChildren(e)}),attributes:e=>({name:e,type:"attributes",validate:e=>f.validateAttributes(e)}),optional:e=>({...e,optional:!0}),oneOf:(e,...t)=>({name:e,type:"oneOf",types:t,validate:e=>t.some(t=>t.validate(e))})},I=(e,t,n="Function")=>{if(!f.isArray(t))throw new i("withValidation : argSchema must be an array");return function(...r){return((e,t,n="Function")=>{if(!t)return;const r=[],o=t.filter(e=>!e.optional).length;if(e.length<o&&r.push(`${n}: Expected at least ${o} arguments, got ${e.length}`),t.forEach((t,o)=>{const i=o+1,s=e[o];if(void 0!==s){if(!t.validate(s)){const e=s?.constructor?.name||typeof s;r.push(`${n}: Invalid argument '${t.name}' at position ${i}, expected ${t.type}, got ${e}`)}}else t.optional||r.push(`${n}: Missing required argument '${t.name}' at position ${i}`)}),r.length>0)throw new A("Argument validation failed",r)})(r,t,e.name||n),e.apply(this,r)}};Function.prototype.args=function(...e){return I(this,e)},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 g.computed(()=>t.replace(/\$\{(.*?)}/g,(t,n)=>{const r=e[n];return f.isObservable(r)?r.val():r}),Object.values(e))},String.prototype.resolveObservableTemplate=function(){return f.containsObservableReference(this)?this.split(/(\{\{#ObItem::\([0-9]+\)\}\})/g).filter(Boolean).map(e=>{if(!f.containsObservableReference(e))return e;const[t,n]=e.match(/\{\{#ObItem::\(([0-9]+)\)\}\}/);return g.getById(n)}):this.valueOf()};const F=["push","pop","shift","unshift","reverse","sort","splice"];g.array=function(e){if(!Array.isArray(e))throw new i("Observable.array : target must be an array");const t=g(e);F.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.set([...t.val(),...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 i=r[e],s=r[n];return r[e]=s,r[n]=i,t.trigger({action:"swap",args:[e,n],result:[i,s]}),!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},g.batch=function(e){const t=g(0),n=function(){if(f.isAsyncFunction(e))return e(...arguments).then(()=>{t.trigger()}).catch(e=>{throw e});e(...arguments),t.trigger()};return n.$observer=t,n},g.init=function(e){const t={};for(const n in e){const r=e[n];f.isJson(r)?t[n]=g.init(r):f.isArray(r)?t[n]=g.array(r):t[n]=g(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];f.isObservable(r)?e[n]=r.val():f.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)}})},g.value=function(e){if(f.isObservable(e))return e.val();if(f.isProxy(e))return e.$value;if(f.isArray(e)){const t=[];for(let n=0,r=e.length;n<r;n++){const r=e[n];t.push(g.value(r))}return t}return e},g.update=function(e,t){for(const n in t){const r=e[n],o=t[n];if(f.isObservable(r)){if(f.isArray(o)){g.update(r,o);continue}r.set(o)}else f.isProxy(r)?g.update(r,o):e[n]=o}},g.object=g.init,g.json=g.init,g.computed=function(e,t=[]){const n=new a(e()),r=()=>n.set(e());if(f.isFunction(t)){if(!f.isObservable(t.$observer))throw new i("Observable.computed : dependencies must be valid batch function");return t.$observer.subscribe(r),n}return t.forEach(e=>e.subscribe(r)),n};const x=function(){const e=new Map;return{use(t){const{observer:n,subscribers:r}=e.get(t),o=g(n.val()),i=n.subscribe(e=>o.set(e)),s=o.subscribe(e=>n.set(e));return o.destroy=()=>{i(),s(),o.cleanup()},r.add(o),o},follow(e){return this.use(e)},create(t,n){const r=g(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 D=function(e,t,n=null){if(!f.isObservable(e))return r.warn("ShowIf","ShowIf : condition must be an Observable / "+n,e);const o=new m("Show if : "+(n||""));let i=null;const s=()=>i||(i=S.getChild(t),i);return e.val()&&o.appendChild(s()),e.subscribe(e=>{e?o.appendChild(s()):o.remove()}),o},T=function(e,t,n=!0){if(!f.isObservable(e))throw new i("Toggle : condition must be an Observable");const r=new m,o=new Map,s=function(e){if(n&&o.has(e))return o.get(e);let r=t[e];return r?(r=S.getChild(r),n&&o.set(e,r),r):null},a=e.val(),u=s(a);return u&&r.appendChild(u),e.subscribe(e=>{const t=s(e);r.remove(),t&&r.appendChild(t)}),r},R=function(e,t,n){if(!f.isObservable(e))throw new i("Toggle : condition must be an Observable");return T(e,{true:t,false:n})},N=E("div"),L=E("span"),P=E("label"),q=E("p"),B=q,M=E("strong"),j=E("h1"),_=E("h2"),V=E("h3"),H=E("h4"),z=E("h5"),W=E("h6"),U=E("br"),J=E("a"),K=E("pre"),Q=E("code"),G=E("blockquote"),X=E("hr"),Y=E("em"),Z=E("small"),ee=E("mark"),te=E("del"),ne=E("ins"),re=E("sub"),oe=E("sup"),ie=E("abbr"),se=E("cite"),ae=E("q"),ue=E("dl"),le=E("dt"),ce=E("dd"),he=E("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}),de=E("input"),pe=E("textarea"),fe=pe,me=E("select"),be=E("fieldset"),ge=E("option"),ve=E("legend"),ye=E("datalist"),we=E("output"),$e=E("progress"),Ce=E("meter"),Oe=E("button"),Se=E("main"),Ee=E("section"),Ae=E("article"),ke=E("aside"),Ie=E("nav"),Fe=E("figure"),xe=E("figcaption"),De=E("header"),Te=E("footer"),Re=E("img"),Ne=function(e,t){return Re({src:e,...t})},Le=E("details"),Pe=E("summary"),qe=E("dialog"),Be=E("menu"),Me=E("ol"),je=E("ul"),_e=E("li"),Ve=_e,He=Me,ze=je,We=E("audio"),Ue=E("video"),Je=E("source"),Ke=E("track"),Qe=E("canvas"),Ge=E("svg"),Xe=E("time"),Ye=E("data"),Ze=E("address"),et=E("kbd"),tt=E("samp"),nt=E("var"),rt=E("wbr"),ot=E("caption"),it=E("table"),st=E("thead"),at=E("tfoot"),ut=E("tbody"),lt=E("tr"),ct=lt,ht=E("th"),dt=ht,pt=ht,ft=E("td"),mt=ft,bt=E("");var gt=Object.freeze({__proto__:null,Abbr:ie,Address:Ze,Anchor:m,Article:Ae,Aside:ke,AsyncImg:function(e,t,n,r){const o=Ne(t||e,n),s=new Image;return s.onload=()=>{f.isFunction(r)&&r(null,o),o.src=e},s.onerror=()=>{f.isFunction(r)&&r(new i("Image not found"))},f.isObservable(e)&&e.subscribe(e=>{s.src=e}),s.src=e,o},Audio:We,BaseImage:Re,Blockquote:G,Br:U,Button:Oe,Canvas:Qe,Caption:ot,Checkbox:e=>de({type:"checkbox",...e}),Cite:se,Code:Q,ColorInput:e=>de({type:"color",...e}),Data:Ye,Datalist:ye,DateInput:e=>de({type:"date",...e}),DateTimeInput:e=>de({type:"datetime-local",...e}),Dd:ce,Del:te,Details:Le,Dialog:qe,Div:N,Dl:ue,Dt:le,Em:Y,EmailInput:e=>de({type:"email",...e}),FieldSet:be,FigCaption:xe,Figure:Fe,FileInput:e=>de({type:"file",...e}),Footer:Te,ForEach:function(e,t,n){const o=new m("ForEach"),i=o.endElement();o.startElement();let s=new Map,a=null;const u=new Set,c=e=>{for(const[t,n]of s.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,s.delete(n.keyId),a&&a.delete(n.keyId)}},h=(e,o)=>{const i=l(e,o,n);if(s.has(i)){const e=s.get(i);if(e.indexObserver?.set(o),e.isNew=!1,e.child?.deref())return i;s.delete(i)}try{const n=t.length>=2?g(o):null;let r=S.getChild(t(e,n));s.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},d=()=>{const t=i.parentNode;if(!t)return;const n=f.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(),c(),void a?.clear();c(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=s.get(r);if(!o)continue;const i=o.child.deref();i&&e.appendChild(i)}o.replaceContent(e)})():(e=>{const t=document.createDocumentFragment();for(const e of u){const n=s.get(e);if(!n)continue;const r=n.child?.deref();r&&t.appendChild(r)}e.insertBefore(t,i)})(t),a?.clear(),a=new Set([...u])};return d(),f.isObservable(e)&&e.subscribe(d),o},ForEachArray:function(e,t,n,o={}){const i=new m("ForEach Array"),s=i.endElement(),a=i.startElement();let u=new Map,c=0;const h=t.length>=2,d=new WeakMap,p=()=>{i.removeChildren(),w(),c=0},b=(e,t)=>d.has(e)?d.get(e):l(e,t,n),v=e=>C(b(e)),y=(e,t=!0)=>{if(!e)return;const n=e.child;e.indexObserver?.deref()?.cleanup(),e.child=null,e.indexObserver=null,t&&(n?.remove(),u.delete(e.keyId))},w=()=>{for(const[e,t]of u.entries())y(t,!1);u.clear()},$=(e,n)=>{const o=b(e,n);if(u.has(o)){const e=u.get(o);e.indexObserver?.deref()?.set(n);const t=e.child;if(t)return t;u.delete(o)}try{const r=h?g(n):null;let i=S.getChild(t(e,r));return u.set(o,{keyId:o,child:i,indexObserver:r?new WeakRef(r):null}),d.set(e,o),i}catch(e){throw r.error("ForEach",`Error creating element for key ${o}`,e),e}},C=function(e){const t=u.get(e);if(!t)return null;const n=t.child;return n||(y(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()},E={toFragment(e,t=0){const n=document.createDocumentFragment();for(let t=0,r=e.length;t<r;t++)n.append($(e[t],c)),c++;return n},add(e,t=0){setTimeout(()=>{i.appendElement(E.toFragment(e))},t)},replace(e){p(),E.add(e)},reOrder(e){let t=null;const n=document.createDocumentFragment();for(const r of e)t=v(r),t&&n.appendChild(t);t=null,i.appendElement(n,s)},removeOne(e,t){let n=v(e);n&&((e,t=!0)=>{y(u.get(e),t)})(b(e,t),!0),n=null},clear:p,merge(e){E.add(e,0)},push(e){let t=0;o.pushDelay&&(t=o.pushDelay(e)??0),E.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($(t,o)),c++}i.appendChild(r),r.replaceChildren()},unshift(e){i.insertBefore(E.toFragment(e),a.nextSibling)},splice(e,t){const[n,r,...o]=e;let a=null;const u=document.createDocumentFragment();if(t.length>0){let e=b(t[0],n);if(1===t.length)O(e,u);else if(t.length>1){const r=C(e);a=r?.previousSibling;for(let e=0;e<t.length;e++){const r=b(t[e],n+e);O(r,u)}}}else a=s;u.replaceChildren(),o&&o.length&&a&&i.insertBefore(E.toFragment(o),a.nextSibling)},reverse(e,t){E.reOrder(t)},sort(e,t){E.reOrder(t)},remove(e,t){E.removeOne(t)},pop(e,t){E.removeOne(t)},shift(e,t){E.removeOne(t)},swap(e,t){const n=s.parentNode;let r=v(t[0]),o=v(t[1]);if(!r||!o)return;const i=o.nextSibling;n.insertBefore(o,r),n.insertBefore(r,i),r=null,o=null}},A=(e,t,n)=>{if("populate"===n?.action)E.populate(n.args,n.result);else{if("clear"===n.action||!e.length){if(0===c)return;p()}if(n?.action)E[n.action]&&E[n.action](n.args,n.result);else{if(0===c)return void E.add(e);E.replace(e)}}((e,t=0)=>{if(!h)return;let n=t;for(let r=t,o=e?.length;r<o;r++){const t=u.get(b(e[r],r));t&&(t.indexObserver?.deref()?.set(n),n++)}})(e,0)};return A(e.val(),0,{action:null}),f.isObservable(e)&&e.subscribe(A),i},Form:he,Fragment:bt,H1:j,H2:_,H3:V,H4:H,H5:z,H6:W,Header:De,HiddenInput:e=>de({type:"hidden",...e}),HideIf:function(e,t,n){const r=g(!e.val());return e.subscribe(e=>r.set(!e)),D(r,t,n)},HideIfNot:function(e,t,n){return D(e,t,n)},Hr:X,Img:Ne,Input:de,Ins:ne,Kbd:et,Label:P,LazyImg:function(e,t){return Ne(e,{...t,loading:"lazy"})},Legend:ve,Li:Ve,Link:J,ListItem:_e,Main:Se,Mark:ee,Match:T,Menu:Be,Meter:Ce,MonthInput:e=>de({type:"month",...e}),NativeDocumentFragment:m,Nav:Ie,NumberInput:e=>de({type:"number",...e}),Ol:He,Option:ge,OrderedList:Me,Output:we,P:q,Paragraph:B,PasswordInput:e=>de({type:"password",...e}),Pre:K,Progress:$e,Quote:ae,Radio:e=>de({type:"radio",...e}),RangeInput:e=>de({type:"range",...e}),ReadonlyInput:e=>de({readonly:!0,...e}),Samp:tt,SearchInput:e=>de({type:"search",...e}),Section:Ee,Select:me,ShowIf:D,SimpleButton:(e,t)=>Oe(e,{type:"button",...t}),Small:Z,Source:Je,Span:L,Strong:M,Sub:re,SubmitButton:(e,t)=>Oe(e,{type:"submit",...t}),Summary:Pe,Sup:oe,Svg:Ge,Switch:R,TBody:ut,TBodyCell:mt,TFoot:at,TFootCell:pt,THead:st,THeadCell:dt,TRow:ct,Table:it,Td:ft,TelInput:e=>de({type:"tel",...e}),TextArea:pe,TextInput:fe,Th:ht,Time:Xe,TimeInput:e=>de({type:"time",...e}),Tr:lt,Track:Ke,Ul:ze,UnorderedList:je,UrlInput:e=>de({type:"url",...e}),Var:nt,Video:Ue,Wbr:rt,WeekInput:e=>de({type:"week",...e}),When:function(e){if(!f.isObservable(e))throw new i("When : condition must be an Observable");let t=null,n=null;return{show(e){return t=e,this},otherwise:r=>(n=r,R(e,t,n))}}});const vt={};function yt(e,t,n={}){e="/"+c(e,"/");let r=null,o=n.name||null;const i=n.middlewares||[],s=n.shouldRebuild||!1,a=n.with||{},u={},l=[],h=e=>{if(!e)return null;const[t,n]=e.split(":");let r=a[t];return!r&&n&&(r=vt[n]),r||(r="[^/]+"),r=r.replace("(","(?:"),{name:t,pattern:`(${r})`}},d=()=>{if(r)return r;const t=e.replace(/\{(.*?)}/gi,(e,t)=>{const n=h(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=()=>i,this.shouldRebuild=()=>s,this.path=()=>e,this.match=function(e){e="/"+c(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=h(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 wt extends Error{constructor(e,t){super(e),this.context=t}}const $t=(e,t)=>{const n=[];return e.forEach(e=>{n.push(c(e.suffix,"/"))}),n.push(c(t,"/")),n.join("/")},Ct=(e,t)=>{const n=[];return e.forEach(e=>{e.options.middlewares&&n.push(...e.options.middlewares)}),t&&n.push(...t),n},Ot=(e,t)=>{const n=[];return e.forEach(e=>{e.options?.name&&n.push(e.options.name)}),t&&n.push(t),n.join(".")};function St(){const e=[];let t=0;const n=n=>{const o=t+n;if(!e[o])return;t=o;const{route:i,params:s,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:i,params:s,query:a,path:u}=this.resolve(n);u!==o()&&(e.splice(t+1),e.push({route:i,params:s,query:a,path:u}),t++,r(u))},this.replace=function(n){const{route:r,params:i,query:s,path:a}=this.resolve(n);a!==o()&&(e[t]={route:r,params:i,query:s,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:i,query:s,path:a}=this.resolve(n||o());e.push({route:r,params:i,query:s,path:a}),t=0,this.handleRouteChange(r,i,s,a)}}function Et(){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:i}=this.resolve(t);if(!n)return;this.handleRouteChange(n,r,o,i)}catch(e){r.error("HistoryRouter","Error in popstate event",e)}});const{route:t,params:n,query:o,path:i}=this.resolve(e||window.location.pathname+window.location.search);this.handleRouteChange(t,n,o,i)}}function At(){const e=[];let t=0;const n=n=>{const r=t+n;if(!e[r])return;t=r;const{route:o,params:i,query:s,path:a}=e[r];this.handleRouteChange(o,i,s,a)};this.push=function(n){const{route:r,params:o,query:i,path:s}=this.resolve(n);e[t]&&e[t].path===s||(e.splice(t+1),e.push({route:r,params:o,query:i,path:s}),t++,this.handleRouteChange(r,o,i,s))},this.replace=function(n){const{route:r,params:o,query:i,path:s}=this.resolve(n);e[t]={route:r,params:o,query:i,path:s},this.handleRouteChange(r,o,i,s)},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:i,query:s,path:a}=this.resolve(r);e.push({route:o,params:i,query:s,path:a}),t=0,this.handleRouteChange(o,i,s,a)}}const kt="default";function It(e={}){const t=[],n={},o=[],i=[],s={route:null,params:null,query:null,path:null,hash:null};if("hash"===e.mode)St.apply(this,[]);else if("history"===e.mode)Et.apply(this,[]);else{if("memory"!==e.mode)throw new wt("Invalid router mode "+e.mode);At.apply(this,[])}const a=function(e,t){for(const n of i)try{n(e),t&&t(e)}catch(e){r.warn("Route Listener","Error in listener:",e)}};this.routes=()=>[...t],this.currentState=()=>({...s}),this.add=function(e,r,i){const s=new yt($t(o,e),r,{...i,middlewares:Ct(o,i?.middlewares||[]),name:i?.name?Ot(o,i.name):null});return t.push(s),s.name()&&(n[s.name()]=s),this},this.group=function(e,t,n){if(!f.isFunction(n))throw new wt("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 wt(`Route not found for name: ${e}`);return o.url({params:t,query:r})},this.resolve=function(e){if(f.isJson(e)){const t=n[e.name];if(!t)throw new wt(`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("?"),i="/"+c(r,"/");let s,a=null;for(const e of t)if(s=e.match(i),s){a=e;break}if(!a)throw new wt(`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:s,query:u,path:e}},this.subscribe=function(e){if(!f.isFunction(e))throw new wt("Listener must be a function");return i.push(e),()=>{i.splice(i.indexOf(e),1)}},this.handleRouteChange=function(e,t,n,r){s.route=e,s.params=t,s.query=n,s.path=r;const o=[...e.middlewares(),a];let i=0;const u={...s},l=e=>{if(i++,!(i>=o.length))return o[i](e||u,l)};return o[i](u,l)}}function Ft(e,t){const{to:n,href:r,...o}=e,i=n||r;if(f.isString(i)){const e=It.get();return J({...o,href:i},t).nd.onPreventClick(()=>{e.push(i)})}const s=i.router||kt,a=It.get(s);if(!a)throw new wt('Router not found "'+s+'" for link "'+i.name+'"');const u=a.generateUrl(i.name,i.params,i.query);return J({...o,href:u},t).nd.onPreventClick(()=>{a.push(u)})}It.routers={},It.create=function(t,n){if(!f.isFunction(n))throw r.error("Router","Callback must be a function",e),new wt("Callback must be a function");const o=new It(t);return It.routers[t.name||kt]=o,n(o),o.init(t.entry),o.mount=function(e){if(f.isString(e)){const t=document.querySelector(e);if(!t)throw new wt(`Container not found for selector: ${e}`);e=t}else if(!f.isElement(e))throw new wt("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:i,path:s}=e;if(n.has(s)){const e=n.get(s);return void r(e)}const a=t.component()({params:o,query:i});n.set(s,a),r(a)};return e.subscribe(o),o(e.currentState()),t}(o,e)},o},It.get=function(e){const t=It.routers[e||kt];if(!t)throw new wt(`Router not found for name: ${e}`);return t},It.push=function(e,t=null){return It.get(t).push(e)},It.replace=function(e,t=null){return It.get(t).replace(e)},It.forward=function(e=null){return It.get(e).forward()},It.back=function(e=null){return It.get(e).back()},Ft.blank=function(e,t){return J({...e,target:"_blank"},t)};var xt=Object.freeze({__proto__:null,Link:Ft,RouteParamPatterns:vt,Router:It});return t.ArgTypes=k,t.ElementCreator=S,t.HtmlElementWrapper=E,t.NDElement=p,t.Observable=g,t.Store=x,t.elements=gt,t.router=xt,t.withValidation=I,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=[]}function a(e){this.$previousValue=e,this.$currentValue=e,this.$isCleanedUp=!1,this.$listeners=null,this.$watchers=null,this.$memoryId=null}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()},Object.defineProperty(a.prototype,"$value",{get(){return this.$currentValue},set(e){this.set(e)},configurable:!0}),a.prototype.__$isObservable=!0;const u=function(){};a.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)},a.prototype.triggerWatchers=function(){if(!this.$watchers)return;const e=this.$watchers,t=this.$previousValue,n=this.$currentValue;e.has(n)&&e.get(n).forEach(e=>{e.set?e.set(!0):e(!0)}),e.has(t)&&e.get(t).forEach(e=>{e.set?e.set(!1):e(!1)})},a.prototype.triggerAll=function(e){this.triggerListeners(e),this.triggerWatchers()},a.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=u},a.prototype.trigger=u,a.prototype.set=function(e){const t="function"==typeof e?e(this.$currentValue):e;this.$currentValue!==t&&(this.$previousValue=this.$currentValue,this.$currentValue=t,this.trigger())},a.prototype.val=function(){return this.$currentValue},a.prototype.disconnectAll=function(){if(this.$listeners?.splice(0),this.$previousValue=null,this.$currentValue=null,this.$watchers)for(const[e,t]of this.$watchers)t.splice(0);this.$watchers?.clear(),this.$listeners=null,this.$watchers=null,this.trigger=u},a.prototype.cleanup=function(){o.unregister(this.$memoryId),this.disconnectAll(),this.$isCleanedUp=!0,delete this.$value},a.prototype.subscribe=function(e){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(),()=>{this.unsubscribe(e),this.assocTrigger()}},a.prototype.on=function(e,t){this.$watchers=this.$watchers??new Map;let n=this.$watchers.get(e);return n||(n=[],this.$watchers.set(e,n)),n.push(t),this.assocTrigger(),()=>{const r=n.indexOf(t);n?.splice(r,1),0===n.size&&(this.$watchers?.delete(e),n=null),this.assocTrigger()}},a.prototype.unsubscribe=function(e){const t=this.$listeners.indexOf(e);t>-1&&this.$listeners.splice(t,1),this.assocTrigger()},a.prototype.check=function(e){return new i(this,e)},a.prototype.get=a.prototype.check,a.prototype.is=function(e){return{$target:e,$observer:this}},a.prototype.toString=function(){return this.$memoryId||o.register(this),"{{#ObItem::("+this.$memoryId+")}}"};const l=(e,t,n)=>{if(f.isFunction(n))return n(e,t);if(f.isObservable(e)){const r=e.val();return r&&n?r[n]:t}return f.isObject(e)?e[n]??t:e},c=function(e,t){return e.replace(new RegExp(`^[${t}]+|[${t}]+$`,"g"),"")},h={mounted:new WeakMap,mountedSupposedSize:0,unmounted:new WeakMap,unmountedSupposedSize:0,observer:null,checkMutation:function(e){for(const t of e){if(h.mountedSupposedSize>0)for(const e of t.addedNodes){const t=h.mounted.get(e);t&&(t.inDom=!0,t.mounted&&t.mounted(e))}if(h.unmountedSupposedSize>0)for(const e of t.removedNodes){const t=h.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:()=>{h.mounted.delete(e),h.unmounted.delete(e),h.mountedSupposedSize--,h.unmountedSupposedSize--,n=null}};return{disconnect:n.disconnect,mounted:t=>{n.mounted=t,h.mounted.set(e,n),h.mountedSupposedSize++},unmounted:t=>{n.unmounted=t,h.unmounted.set(e,n),h.unmountedSupposedSize++}}}};h.observer=new MutationObserver(h.checkMutation),h.observer.observe(document.body,{childList:!0,subtree:!0});const d=["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"];function p(e){this.$element=e,this.$observer=null}p.prototype.__$isNDElement=!0;for(const e of d){const t=e.toLowerCase();p.prototype["on"+e]=function(e){return this.$element.addEventListener(t,e),this},p.prototype["onPrevent"+e]=function(e){return this.$element.addEventListener(t,function(t){t.preventDefault(),e(t)}),this},p.prototype["onStop"+e]=function(e){return this.$element.addEventListener(t,function(t){t.stopPropagation(),e(t)}),this},p.prototype["onPreventStop"+e]=function(e){return this.$element.addEventListener(t,function(t){t.stopPropagation(),t.preventDefault(),e(t)}),this}}p.prototype.ref=function(e,t){return e[t]=this.$element,this},p.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},p.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},p.prototype.lifecycle=function(e){return this.$observer=this.$observer||h.watch(this.$element),e.mounted&&this.$observer.mounted(e.mounted),e.unmounted&&this.$observer.unmounted(e.unmounted),this},p.prototype.mounted=function(e){return this.lifecycle({mounted:e})},p.prototype.unmounted=function(e){return this.lifecycle({unmounted:e})},p.prototype.htmlElement=function(){return this.$element},p.prototype.node=p.prototype.htmlElement;const f={isObservable:e=>e instanceof a||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 p||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&&(f.isObject(e)&&Object.values(e).some(e=>f.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 m(e){const t=document.createDocumentFragment(),n=document.createComment("Anchor Start : "+e),o=document.createComment("/ Anchor End "+e);t.appendChild(n),t.appendChild(o),t.nativeInsertBefore=t.insertBefore,t.nativeAppendChild=t.appendChild;const s=function(e,n,r){e!==t?e.insertBefore(S.getChild(n),r):e.nativeInsertBefore(S.getChild(n),r)};return t.appendElement=function(e,n=null){o.parentNode!==t?o.parentNode?.insertBefore(e,n||o):o.parentNode.nativeInsertBefore(e,n||o)},t.appendChild=function(e,n=null){const i=o.parentNode;if(i){if(n=n??o,f.isArray(e)){const r=document.createDocumentFragment();for(let t=0,n=e.length;t<n;t++)r.appendChild(S.getChild(e[t]));return s(i,r,n),t}s(i,e,n)}else r.error("Anchor","Anchor : parent not found",e)},t.removeChildren=function(){const e=o.parentNode;if(e===t)return;if(e.firstChild===n&&e.lastChild===o)return void e.replaceChildren(n,o);let r,s=n.nextSibling;const i=document.createDocumentFragment();for(;s&&s!==o;)r=s.nextSibling,i.append(s),s=r;i.replaceChildren()},t.remove=function(){if(o.parentNode===t)return;let e,r=n.nextSibling;for(;r!==o;)e=r.nextSibling,t.nativeAppendChild(r),r=e},t.removeWithAnchors=function(){t.removeChildren(),n.remove(),o.remove()},t.replaceContent=function(e){const r=o.parentNode;r&&(r.firstChild!==n||r.lastChild!==o?(t.removeChildren(),r.insertBefore(e,o)):r.replaceChildren(n,e,o))},t.insertBefore=function(e,n=null){t.appendChild(e,n)},t.clear=function(){t.remove()},t.endElement=function(){return o},t.startElement=function(){return n},t}const b=["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 g(e){return new a(e)}function v(e,t){for(let n in t){const r=t[n];f.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.$observer.on(r.$target,function(t){e.classList.toggle(n,t)})):e.classList.toggle(n,r)}}function y(e,t){for(let n in t){const r=t[n];f.isObservable(r)?(e.style[n]=r.val(),r.subscribe(t=>{e.style[n]=t})):e.style[n]=r}}function w(e,t,n){const r=f.isObservable(n)?n.val():n;f.isBoolean(r)?e[t]=r:e[t]=r===e.value,f.isObservable(n)&&(["checked"].includes(t)&&e.addEventListener("input",()=>{f.isBoolean(r)?n.set(e[t]):n.set(e.value)}),n.subscribe(n=>{f.isBoolean(n)?e[t]=n:e[t]=n===e.value}))}function $(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))}g.getById=function(e){const t=o.getObservableById(parseInt(e));if(!t)throw new s("Observable.getById : No observable found with id "+e);return t},g.cleanup=function(e){e.cleanup()},g.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 C=new Map;let O=null;const S={createTextNode:()=>(O||(O=document.createTextNode("")),O.cloneNode()),createObservableNode(e,t){const n=S.createTextNode();return t.subscribe(e=>n.nodeValue=String(e)),n.nodeValue=t.val(),e&&e.appendChild(n),n},createStaticTextNode(e,t){let n=S.createTextNode();return n.nodeValue=String(t),e&&e.appendChild(n),n},createElement(e){if(e){if(C.has(e))return C.get(e).cloneNode();const t=document.createElement(e);return C.set(e,t),t.cloneNode()}return new m("Fragment")},processChildren(e,t){if(null===e)return;const n=Array.isArray(e)?e:[e];for(let e=0,r=n.length;e<r;e++){let r=this.getChild(n[e]);null!==r&&t.appendChild(r)}},getChild(e){if(null===e)return null;if(f.isString(e)&&(e=e.resolveObservableTemplate?e.resolveObservableTemplate():e,f.isString(e)))return S.createStaticTextNode(null,e);if(f.isElement(e))return e;if(f.isObservable(e))return S.createObservableNode(null,e);if(f.isNDElement(e))return e.$element??e.$build?.()??null;if(f.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 f.isFunction(e)?this.getChild(e()):S.createStaticTextNode(null,e)},processAttributes(e,t){f.isFragment(e)||t&&function(e,t){if(f.validateAttributes(t),!f.isObject(t))throw new s("Attributes must be an object");for(let n in t){const r=n.toLowerCase();let o=t[r];if(f.isString(o)){if(o=o.resolveObservableTemplate?o.resolveObservableTemplate():o,f.isString(o)){e.setAttribute(r,o);continue}const t=o.filter(e=>f.isObservable(e));o=g.computed(()=>o.map(e=>f.isObservable(e)?e.val():e).join(" ")||" ",t)}"class"===r&&f.isJson(o)?v(e,o):"style"===r&&f.isJson(o)?y(e,o):b.includes(r)?w(e,r,o):f.isObservable(o)?$(e,r,o):e.setAttribute(r,o)}}(e,t)},setup:(e,t,n)=>e};function E(e,t){const n=e.toLowerCase();return function(e,o=null){try{if(!f.isJson(e)){const t=o;o=e,e=t}const r=S.createElement(n),s="function"==typeof t?t(r):r;return S.processAttributes(s,e),S.processChildren(o,s),S.setup(s,e,t)}catch(e){r.error("ElementCreation",`Error creating ${n}`,e)}}}Object.defineProperty(HTMLElement.prototype,"nd",{configurable:!0,get(){return this.$nd||(this.$nd=new p(this),this.$nd.nd=this.$nd),this.$nd}});class A extends Error{constructor(e,t){super(`${e}\n\n${t.join("\n")}\n\n`)}}const k={string:e=>({name:e,type:"string",validate:e=>f.isString(e)}),number:e=>({name:e,type:"number",validate:e=>f.isNumber(e)}),boolean:e=>({name:e,type:"boolean",validate:e=>f.isBoolean(e)}),observable:e=>({name:e,type:"observable",validate:e=>f.isObservable(e)}),element:e=>({name:e,type:"element",validate:e=>f.isElement(e)}),function:e=>({name:e,type:"function",validate:e=>f.isFunction(e)}),object:e=>({name:e,type:"object",validate:e=>f.isObject(e)}),objectNotNull:e=>({name:e,type:"object",validate:e=>f.isObject(e)&&null!==e}),children:e=>({name:e,type:"children",validate:e=>f.validateChildren(e)}),attributes:e=>({name:e,type:"attributes",validate:e=>f.validateAttributes(e)}),optional:e=>({...e,optional:!0}),oneOf:(e,...t)=>({name:e,type:"oneOf",types:t,validate:e=>t.some(t=>t.validate(e))})},I=(e,t,n="Function")=>{if(!f.isArray(t))throw new s("withValidation : argSchema must be an array");return function(...r){return((e,t,n="Function")=>{if(!t)return;const r=[],o=t.filter(e=>!e.optional).length;if(e.length<o&&r.push(`${n}: Expected at least ${o} arguments, got ${e.length}`),t.forEach((t,o)=>{const s=o+1,i=e[o];if(void 0!==i){if(!t.validate(i)){const e=i?.constructor?.name||typeof i;r.push(`${n}: Invalid argument '${t.name}' at position ${s}, expected ${t.type}, got ${e}`)}}else t.optional||r.push(`${n}: Missing required argument '${t.name}' at position ${s}`)}),r.length>0)throw new A("Argument validation failed",r)})(r,t,e.name||n),e.apply(this,r)}};Function.prototype.args=function(...e){return I(this,e)},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 g.computed(()=>t.replace(/\$\{(.*?)}/g,(t,n)=>{const r=e[n];return f.isObservable(r)?r.val():r}),Object.values(e))},String.prototype.resolveObservableTemplate=function(){return f.containsObservableReference(this)?this.split(/(\{\{#ObItem::\([0-9]+\)\}\})/g).filter(Boolean).map(e=>{if(!f.containsObservableReference(e))return e;const[t,n]=e.match(/\{\{#ObItem::\(([0-9]+)\)\}\}/);return g.getById(n)}):this.valueOf()};const x=["push","pop","shift","unshift","reverse","sort","splice"];g.array=function(e){if(!Array.isArray(e))throw new s("Observable.array : target must be an array");const t=g(e);x.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.set([...t.val(),...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},g.batch=function(e){const t=g(0),n=function(){if(f.isAsyncFunction(e))return e(...arguments).then(()=>{t.trigger()}).catch(e=>{throw e});e(...arguments),t.trigger()};return n.$observer=t,n},g.init=function(e){const t={};for(const n in e){const r=e[n];f.isJson(r)?t[n]=g.init(r):f.isArray(r)?t[n]=g.array(r):t[n]=g(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];f.isObservable(r)?e[n]=r.val():f.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)}})},g.value=function(e){if(f.isObservable(e))return e.val();if(f.isProxy(e))return e.$value;if(f.isArray(e)){const t=[];for(let n=0,r=e.length;n<r;n++){const r=e[n];t.push(g.value(r))}return t}return e},g.update=function(e,t){for(const n in t){const r=e[n],o=t[n];if(f.isObservable(r)){if(f.isArray(o)){g.update(r,o);continue}r.set(o)}else f.isProxy(r)?g.update(r,o):e[n]=o}},g.object=g.init,g.json=g.init,g.computed=function(e,t=[]){const n=new a(e()),r=()=>n.set(e());if(f.isFunction(t)){if(!f.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 D=function(){const e=new Map;return{use(t){const{observer:n,subscribers:r}=e.get(t),o=g(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=g(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 F=function(e,t,n=null){if(!f.isObservable(e))return r.warn("ShowIf","ShowIf : condition must be an Observable / "+n,e);const o=new m("Show if : "+(n||""));let s=null;const i=()=>s||(s=S.getChild(t),s);return e.val()&&o.appendChild(i()),e.subscribe(e=>{e?o.appendChild(i()):o.remove()}),o},T=function(e,t,n=!0){if(!f.isObservable(e))throw new s("Toggle : condition must be an Observable");const r=new m,o=new Map,i=function(e){if(n&&o.has(e))return o.get(e);let r=t[e];return r?(r=S.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},R=function(e,t,n){if(!f.isObservable(e))throw new s("Toggle : condition must be an Observable");return T(e,{true:t,false:n})},L=E("div"),N=E("span"),P=E("label"),q=E("p"),B=q,M=E("strong"),j=E("h1"),_=E("h2"),V=E("h3"),H=E("h4"),z=E("h5"),W=E("h6"),U=E("br"),J=E("a"),K=E("pre"),Q=E("code"),G=E("blockquote"),X=E("hr"),Y=E("em"),Z=E("small"),ee=E("mark"),te=E("del"),ne=E("ins"),re=E("sub"),oe=E("sup"),se=E("abbr"),ie=E("cite"),ae=E("q"),ue=E("dl"),le=E("dt"),ce=E("dd"),he=E("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}),de=E("input"),pe=E("textarea"),fe=pe,me=E("select"),be=E("fieldset"),ge=E("option"),ve=E("legend"),ye=E("datalist"),we=E("output"),$e=E("progress"),Ce=E("meter"),Oe=E("button"),Se=E("main"),Ee=E("section"),Ae=E("article"),ke=E("aside"),Ie=E("nav"),xe=E("figure"),De=E("figcaption"),Fe=E("header"),Te=E("footer"),Re=E("img"),Le=function(e,t){return Re({src:e,...t})},Ne=E("details"),Pe=E("summary"),qe=E("dialog"),Be=E("menu"),Me=E("ol"),je=E("ul"),_e=E("li"),Ve=_e,He=Me,ze=je,We=E("audio"),Ue=E("video"),Je=E("source"),Ke=E("track"),Qe=E("canvas"),Ge=E("svg"),Xe=E("time"),Ye=E("data"),Ze=E("address"),et=E("kbd"),tt=E("samp"),nt=E("var"),rt=E("wbr"),ot=E("caption"),st=E("table"),it=E("thead"),at=E("tfoot"),ut=E("tbody"),lt=E("tr"),ct=lt,ht=E("th"),dt=ht,pt=ht,ft=E("td"),mt=ft,bt=E("");var gt=Object.freeze({__proto__:null,Abbr:se,Address:Ze,Anchor:m,Article:Ae,Aside:ke,AsyncImg:function(e,t,n,r){const o=Le(t||e,n),i=new Image;return i.onload=()=>{f.isFunction(r)&&r(null,o),o.src=e},i.onerror=()=>{f.isFunction(r)&&r(new s("Image not found"))},f.isObservable(e)&&e.subscribe(e=>{i.src=e}),i.src=e,o},Audio:We,BaseImage:Re,Blockquote:G,Br:U,Button:Oe,Canvas:Qe,Caption:ot,Checkbox:e=>de({type:"checkbox",...e}),Cite:ie,Code:Q,ColorInput:e=>de({type:"color",...e}),Data:Ye,Datalist:ye,DateInput:e=>de({type:"date",...e}),DateTimeInput:e=>de({type:"datetime-local",...e}),Dd:ce,Del:te,Details:Ne,Dialog:qe,Div:L,Dl:ue,Dt:le,Em:Y,EmailInput:e=>de({type:"email",...e}),FieldSet:be,FigCaption:De,Figure:xe,FileInput:e=>de({type:"file",...e}),Footer:Te,ForEach:function(e,t,n){const o=new m("ForEach"),s=o.endElement();o.startElement();let i=new Map,a=null;const u=new Set,c=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=l(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?g(o):null;let r=S.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=f.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(),c(),void a?.clear();c(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(),f.isObservable(e)&&e.subscribe(d),o},ForEachArray:function(e,t,n,o={}){const s=new m("ForEach Array"),i=s.endElement(),a=s.startElement();let u=new Map,c=0;const h=t.length>=2,d=new WeakMap,p=()=>{s.removeChildren(),w(),c=0},b=(e,t)=>d.has(e)?d.get(e):l(e,t,n),v=e=>C(b(e)),y=(e,t=!0)=>{if(!e)return;const n=e.child;e.indexObserver?.deref()?.cleanup(),e.child=null,e.indexObserver=null,t&&(n?.remove(),u.delete(e.keyId))},w=()=>{for(const[e,t]of u.entries())y(t,!1);u.clear()},$=(e,n)=>{const o=b(e,n);if(u.has(o)){const e=u.get(o);e.indexObserver?.deref()?.set(n);const t=e.child;if(t)return t;u.delete(o)}try{const r=h?g(n):null;let s=S.getChild(t(e,r));return u.set(o,{keyId:o,child:s,indexObserver:r?new WeakRef(r):null}),d.set(e,o),s}catch(e){throw r.error("ForEach",`Error creating element for key ${o}`,e),e}},C=function(e){const t=u.get(e);if(!t)return null;const n=t.child;return n||(y(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()},E={toFragment(e,t=0){const n=document.createDocumentFragment();for(let t=0,r=e.length;t<r;t++)n.append($(e[t],c)),c++;return n},add(e,t=0){const n=E.toFragment(e);setTimeout(()=>{s.appendElement(n)},t)},replace(e){p(),E.add(e)},reOrder(e){let t=null;const n=document.createDocumentFragment();for(const r of e)t=v(r),t&&n.appendChild(t);t=null,s.appendElement(n,i)},removeOne(e,t){let n=v(e);n&&((e,t=!0)=>{y(u.get(e),t)})(b(e,t),!0),n=null},clear:p,merge(e){E.add(e,0)},push(e){let t=0;o.pushDelay&&(t=o.pushDelay(e)??0),E.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($(t,o)),c++}s.appendChild(r),r.replaceChildren()},unshift(e){s.insertBefore(E.toFragment(e),a.nextSibling)},splice(e,t){const[n,r,...o]=e;let a=null;const u=document.createDocumentFragment();if(t.length>0){let e=b(t[0],n);if(1===t.length)O(e,u);else if(t.length>1){const r=C(e);a=r?.previousSibling;for(let e=0;e<t.length;e++){const r=b(t[e],n+e);O(r,u)}}}else a=i;u.replaceChildren(),o&&o.length&&a&&s.insertBefore(E.toFragment(o),a.nextSibling)},reverse(e,t){E.reOrder(t)},sort(e,t){E.reOrder(t)},remove(e,t){E.removeOne(t)},pop(e,t){E.removeOne(t)},shift(e,t){E.removeOne(t)},swap(e,t){const n=i.parentNode;let r=v(t[0]),o=v(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)E[n.action]&&E[n.action](n.args,n.result);else{if(0===c)return void E.add(e);E.replace(e)}((e,t=0)=>{if(!h)return;let n=t;for(let r=t,o=e?.length;r<o;r++){const t=u.get(b(e[r],r));t&&(t.indexObserver?.deref()?.set(n),n++)}})(e,0)}else{if(0===c)return;p()}};return A(e.val(),0,{action:null}),f.isObservable(e)&&e.subscribe(A),s},Form:he,Fragment:bt,H1:j,H2:_,H3:V,H4:H,H5:z,H6:W,Header:Fe,HiddenInput:e=>de({type:"hidden",...e}),HideIf:function(e,t,n){const r=g(!e.val());return e.subscribe(e=>r.set(!e)),F(r,t,n)},HideIfNot:function(e,t,n){return F(e,t,n)},Hr:X,Img:Le,Input:de,Ins:ne,Kbd:et,Label:P,LazyImg:function(e,t){return Le(e,{...t,loading:"lazy"})},Legend:ve,Li:Ve,Link:J,ListItem:_e,Main:Se,Mark:ee,Match:T,Menu:Be,Meter:Ce,MonthInput:e=>de({type:"month",...e}),NativeDocumentFragment:m,Nav:Ie,NumberInput:e=>de({type:"number",...e}),Ol:He,Option:ge,OrderedList:Me,Output:we,P:q,Paragraph:B,PasswordInput:e=>de({type:"password",...e}),Pre:K,Progress:$e,Quote:ae,Radio:e=>de({type:"radio",...e}),RangeInput:e=>de({type:"range",...e}),ReadonlyInput:e=>de({readonly:!0,...e}),Samp:tt,SearchInput:e=>de({type:"search",...e}),Section:Ee,Select:me,ShowIf:F,SimpleButton:(e,t)=>Oe(e,{type:"button",...t}),Small:Z,Source:Je,Span:N,Strong:M,Sub:re,SubmitButton:(e,t)=>Oe(e,{type:"submit",...t}),Summary:Pe,Sup:oe,Svg:Ge,Switch:R,TBody:ut,TBodyCell:mt,TFoot:at,TFootCell:pt,THead:it,THeadCell:dt,TRow:ct,Table:st,Td:ft,TelInput:e=>de({type:"tel",...e}),TextArea:pe,TextInput:fe,Th:ht,Time:Xe,TimeInput:e=>de({type:"time",...e}),Tr:lt,Track:Ke,Ul:ze,UnorderedList:je,UrlInput:e=>de({type:"url",...e}),Var:nt,Video:Ue,Wbr:rt,WeekInput:e=>de({type:"week",...e}),When:function(e){if(!f.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,R(e,t,n))}}});const vt={};function yt(e,t,n={}){e="/"+c(e,"/");let r=null,o=n.name||null;const s=n.middlewares||[],i=n.shouldRebuild||!1,a=n.with||{},u={},l=[],h=e=>{if(!e)return null;const[t,n]=e.split(":");let r=a[t];return!r&&n&&(r=vt[n]),r||(r="[^/]+"),r=r.replace("(","(?:"),{name:t,pattern:`(${r})`}},d=()=>{if(r)return r;const t=e.replace(/\{(.*?)}/gi,(e,t)=>{const n=h(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="/"+c(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=h(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 wt extends Error{constructor(e,t){super(e),this.context=t}}const $t=(e,t)=>{const n=[];return e.forEach(e=>{n.push(c(e.suffix,"/"))}),n.push(c(t,"/")),n.join("/")},Ct=(e,t)=>{const n=[];return e.forEach(e=>{e.options.middlewares&&n.push(...e.options.middlewares)}),t&&n.push(...t),n},Ot=(e,t)=>{const n=[];return e.forEach(e=>{e.options?.name&&n.push(e.options.name)}),t&&n.push(t),n.join(".")};function St(){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 Et(){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 At(){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 kt="default";function It(e={}){const t=[],n={},o=[],s=[],i={route:null,params:null,query:null,path:null,hash:null};if("hash"===e.mode)St.apply(this,[]);else if("history"===e.mode)Et.apply(this,[]);else{if("memory"!==e.mode)throw new wt("Invalid router mode "+e.mode);At.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 yt($t(o,e),r,{...s,middlewares:Ct(o,s?.middlewares||[]),name:s?.name?Ot(o,s.name):null});return t.push(i),i.name()&&(n[i.name()]=i),this},this.group=function(e,t,n){if(!f.isFunction(n))throw new wt("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 wt(`Route not found for name: ${e}`);return o.url({params:t,query:r})},this.resolve=function(e){if(f.isJson(e)){const t=n[e.name];if(!t)throw new wt(`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="/"+c(r,"/");let i,a=null;for(const e of t)if(i=e.match(s),i){a=e;break}if(!a)throw new wt(`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(!f.isFunction(e))throw new wt("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 xt(e,t){const{to:n,href:r,...o}=e,s=n||r;if(f.isString(s)){const e=It.get();return J({...o,href:s},t).nd.onPreventClick(()=>{e.push(s)})}const i=s.router||kt,a=It.get(i);if(!a)throw new wt('Router not found "'+i+'" for link "'+s.name+'"');const u=a.generateUrl(s.name,s.params,s.query);return J({...o,href:u},t).nd.onPreventClick(()=>{a.push(u)})}It.routers={},It.create=function(t,n){if(!f.isFunction(n))throw r.error("Router","Callback must be a function",e),new wt("Callback must be a function");const o=new It(t);return It.routers[t.name||kt]=o,n(o),o.init(t.entry),o.mount=function(e){if(f.isString(e)){const t=document.querySelector(e);if(!t)throw new wt(`Container not found for selector: ${e}`);e=t}else if(!f.isElement(e))throw new wt("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},It.get=function(e){const t=It.routers[e||kt];if(!t)throw new wt(`Router not found for name: ${e}`);return t},It.push=function(e,t=null){return It.get(t).push(e)},It.replace=function(e,t=null){return It.get(t).replace(e)},It.forward=function(e=null){return It.get(e).forward()},It.back=function(e=null){return It.get(e).back()},xt.blank=function(e,t){return J({...e,target:"_blank"},t)};var Dt=Object.freeze({__proto__:null,Link:xt,RouteParamPatterns:vt,Router:It});return t.ArgTypes=k,t.ElementCreator=S,t.HtmlElementWrapper=E,t.NDElement=p,t.Observable=g,t.Store=D,t.elements=gt,t.router=Dt,t.withValidation=I,t}({});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "native-document",
3
- "version": "1.0.24",
3
+ "version": "1.0.26",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -194,7 +194,7 @@ ObservableItem.prototype.check = function(callback) {
194
194
  };
195
195
  ObservableItem.prototype.get = ObservableItem.prototype.check;
196
196
 
197
- ObservableItem.prototype.is = function(value) {
197
+ ObservableItem.prototype.when = function(value) {
198
198
  return {$target: value, $observer: this};
199
199
  };
200
200
 
@@ -139,8 +139,9 @@ export function ForEachArray(data, callback, key, configs = {}) {
139
139
  return fragment;
140
140
  },
141
141
  add(items, delay = 0) {
142
+ const fragment = Actions.toFragment(items);
142
143
  setTimeout(() => {
143
- element.appendElement(Actions.toFragment(items))
144
+ element.appendElement(fragment);
144
145
  }, delay);
145
146
  },
146
147
  replace(items) {
@@ -253,26 +254,23 @@ export function ForEachArray(data, callback, key, configs = {}) {
253
254
  };
254
255
 
255
256
  const buildContent = (items, _, operations) => {
256
- if(operations?.action === 'populate') {
257
- Actions.populate(operations.args, operations.result);
258
- } else {
259
- if(operations.action === 'clear' || !items.length) {
260
- if(lastNumberOfItems === 0) {
261
- return;
262
- }
263
- clear();
257
+ if(operations.action === 'clear' || !items.length) {
258
+ if(lastNumberOfItems === 0) {
259
+ return;
264
260
  }
261
+ clear();
262
+ return;
263
+ }
265
264
 
266
- if(!operations?.action) {
267
- if(lastNumberOfItems === 0) {
268
- Actions.add(items);
269
- return;
270
- }
271
- Actions.replace(items);
272
- }
273
- else if(Actions[operations.action]) {
274
- Actions[operations.action](operations.args, operations.result);
265
+ if(!operations?.action) {
266
+ if(lastNumberOfItems === 0) {
267
+ Actions.add(items);
268
+ return;
275
269
  }
270
+ Actions.replace(items);
271
+ }
272
+ else if(Actions[operations.action]) {
273
+ Actions[operations.action](operations.args, operations.result);
276
274
  }
277
275
 
278
276
  updateIndexObservers(items, 0);