/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/cradova@3.16.2/dist/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
var makeElement=(e,t)=>{const r={};let o;if(0===t.length)return e;for(let n=0;n<t.length;n++){let i=t[n];if("function"==typeof i&&(i=isArrowFunc(i)?i():toComp(i)),i instanceof HTMLElement||i instanceof DocumentFragment)e.appendChild(i);else if(Array.isArray(i)){if(i[1]instanceof Signal){i[1].computed(i[0],(()=>{e.innerHTML="",e.appendChild(unroll_child_list([i[1].data[i[0]]]))})),e.appendChild(unroll_child_list([i[1].data[i[0]]]));continue}e.appendChild(unroll_child_list(i))}else"string"!=typeof i?"object"!=typeof i||Object.assign(r,i):o=i}if("object"==typeof r&&e)for(const[t,o]of Object.entries(r))if("style"!==t||"object"!=typeof o)if("onmount"!==t||"function"!=typeof r.onmount)if(t.includes("data-")||t.includes("aria-"))e.setAttribute(t,o);else{if(Array.isArray(o)){if("ref"===t&&2===o.length&&o[0]instanceof RefInstance&&"string"==typeof o[1]){const[t,r]=o;t.refs[r]=e;continue}if(2===o.length&&o[1]instanceof Signal&&"string"==typeof o[0]){const r=o[0],n=o[1];n.computed([r],(()=>{e.setAttribute(t,n.data[r])})),e.setAttribute(t,n.data[r]);continue}}e[t]=o}else window.CradovaEvent.after_comp_is_mounted.push(r.onmount.bind(e));else Object.assign(e.style,o);return void 0!==o&&e.appendChild(document.createTextNode(o)),e},cra=e=>(...t)=>makeElement(document.createElement(e),t);function unroll_child_list(e){const t=new DocumentFragment;for(let r of e)if(Array.isArray(r))t.appendChild(unroll_child_list(r));else{if("function"==typeof r&&(r=isArrowFunc(r)?r():toComp(r),"function"==typeof r&&(r=isArrowFunc(r)?r():toComp(r))),r instanceof HTMLElement||r instanceof DocumentFragment){t.appendChild(r);continue}"string"==typeof r&&t.appendChild(document.createTextNode(r))}return t}var $case=(e,t)=>r=>{if(r===e)return t};function $switch(e,...t){let r;if(t.length)for(let o=0;o<t.length&&(r=t[o](e),!r);o++);return r}function loop(e,t){return Array.isArray(e)?e.map(t):void 0}var fragment=function(e){const t=document.createDocumentFragment();for(let r=0;r<e.length;r++){let o=e[r];"function"==typeof o&&(o=o()),o instanceof HTMLElement||o instanceof DocumentFragment?t.appendChild(o):o instanceof String?t.appendChild(document.createTextNode(o)):console.error(" ✘  Cradova err:   wrong element type"+o)}return t};function depsAreEqual(e,t){if(!e||!t||e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(!Object.is(e[r],t[r]))return!1;return!0}function useState(e){const t=this;if("function"!=typeof t||!t._state)throw new Error("Cradova Hook Error: useState called outside of a Cradova component context.");const r=++t._state_index;t._state.length<=r&&(t._state[r]=e);return[t._state[r],e=>{const o=t._state[r];let n;n="function"==typeof e?e(o):e,Object.is(o,n)||(t._state[r]=n,compManager.recall(t))}]}function useEffect(e,t){const r=this;if("function"!=typeof r||!r._effect_tracker)throw new Error("Cradova Hook Error: useEffect called outside of a Cradova component context.");const o=++r._effect_index,n=r._effect_tracker,i=n[o]?.deps;let s=!1;void 0===t?s=!0:n[o]&&depsAreEqual(i,t)||(s=!0),n[o]?n[o].deps=t:n[o]={deps:t},s&&compManager.scheduleEffect(r,o,e)}function useMemo(e,t){const r=this;if("function"!=typeof r||!r._memo_tracker)throw new Error("Cradova Hook Error: useMemo called outside of a Cradova component context.");const o=++r._memo_index,n=r._memo_tracker,i=n[o],s=i?.deps;let a=!1;if(void 0!==t&&i&&depsAreEqual(s,t)||(a=!0),a){const r=e();return n[o]={deps:t,value:r},r}return i.value}function useCallback(e,t){return useMemo.call(this,(()=>e),t)}function useRef(){return new RefInstance}function useReducer(e,t,r){const o=this;if("function"!=typeof o||!o._reducer_tracker)throw new Error("Cradova Hook Error: useReducer called outside of a Cradova component context.");const n=++o._reducer_index,i=o._reducer_tracker;if(i.length<=n){const e="function"==typeof r?r(t):t;i[n]={state:e}}return[i[n].state,t=>{const r=i[n],s=r.state;let a;try{a=e(s,t)}catch(e){throw console.error("Cradova err: Error occurred in reducer:",e),e}Object.is(s,a)||(r.state=a,compManager.recall(o))}]}var isArrowFunc=e=>!e.hasOwnProperty("prototype"),DEFAULT_COMPONENT_PROPS={rendered:!1,published:!1,reference:null,_state_index:-1,_effect_index:-1,_memo_index:-1,_reducer_index:-1,useState:useState,useEffect:useEffect,useMemo:useMemo,useCallback:useCallback,useRef:useRef,useReducer:useReducer};function resetComponent(e){return"number"==typeof e._state_index?(e._state_index=-1,e._effect_index=-1,e._memo_index=-1,e._reducer_index=-1,compManager.cleanupEffects(e),e):e}var toComp=(e,t)=>(Object.assign(e,{...DEFAULT_COMPONENT_PROPS}),e._state=[],e._effect_tracker=[],e._memo_tracker=[],e._reducer_tracker=[],e._args=t,compManager.render(e)),toCompNoRender=e=>("number"!=typeof e._state_index&&Object.assign(e,{...DEFAULT_COMPONENT_PROPS}),e._state_index=-1,e._effect_index=-1,e._memo_index=-1,e._reducer_index=-1,compManager.cleanupEffects(e),e),compManager={render(e){const t=e(e,...e._args||[]);return t instanceof HTMLElement||t instanceof DocumentFragment?(e.reference=t,e.rendered=!0,e.published=!0,queueMicrotask((()=>{this.runScheduledEffects(e)})),t):(console.error(" Cradova err : Component function must return an HTMLElement. Got:",t),void(e.rendered=!1))},recall(e){e.rendered&&e.published&&queueMicrotask((()=>{this.activate(e)})),window.CradovaEvent.dispatchEvent("after_page_is_killed"),window.CradovaEvent.dispatchEvent("after_comp_is_mounted")},activate(e){if(e.published=!1,!e.rendered||!e.reference)return;const t=e.reference;if(document.body.contains(t)){resetComponent(e);const r=e(e,...e._args||[]);r instanceof HTMLElement||r instanceof DocumentFragment?(t.insertAdjacentElement("beforebegin",r),t.remove(),e.reference=r,e.published=!0,this.runScheduledEffects(e)):(console.error(" Cradova err : Component function must return an HTMLElement during update. Got:",r),e.reference=t,e.published=!1)}else this.unmount(e)},_effectsToRun:new Map,scheduleEffect(e,t,r){this._effectsToRun.has(e)||this._effectsToRun.set(e,new Map),this._effectsToRun.get(e).set(t,r)},runScheduledEffects(e){const t=this._effectsToRun.get(e);t&&0!==t.size&&(t.forEach(((t,r)=>{const o=e._effect_tracker[r];if(o&&"function"==typeof o.cleanup){try{o.cleanup()}catch(e){console.error("Cradova err: Error during effect cleanup:",e)}o.cleanup=void 0}try{const e=t();o&&(o.cleanup=e)}catch(e){console.error("Cradova err: Error during effect execution:",e)}})),this._effectsToRun.delete(e))},cleanupEffects(e){e._effect_tracker?.length&&e._effect_tracker.forEach((e=>{if("function"==typeof e?.cleanup)try{e.cleanup()}catch(e){console.error("Cradova err: Error during component cleanup/unmount:",e)}}))},unmount(e){this.cleanupEffects(e),e.reference=null,e.rendered=!1,e.published=!1,this._effectsToRun.delete(e)}};function invoke(e,...t){return toComp(e,t)}var useExternalEffect=e=>(t,...r)=>e(t,...r),a=cra("a"),audio=cra("audio"),button=cra("button"),canvas=cra("canvas"),div=cra("div"),footer=cra("footer"),form=cra("form"),h1=cra("h1"),h2=cra("h2"),h3=cra("h3"),h4=cra("h4"),h5=cra("h5"),h6=cra("h6"),header=cra("header"),i=cra("i"),iframe=cra("iframe"),img=cra("img"),input=cra("input"),label=cra("label"),li=cra("li"),main=cra("main"),nav=cra("nav"),ol=cra("ol"),option=cra("option"),p=cra("p"),section=cra("section"),select=cra("select"),span=cra("span"),textarea=cra("textarea"),ul=cra("ul"),video=cra("video"),tbody=cra("table"),table=cra("tbody"),td=cra("td"),tr=cra("tr"),raw=e=>{const t=document.createElement("div");Array.isArray(e)?t.innerHTML=e[0]:"string"==typeof e&&(t.innerHTML=e);const r=new DocumentFragment;return r.append(...Array.from(t.children)),r};class cradovaEvent{after_comp_is_mounted=[];after_page_is_killed=[];async dispatchEvent(e){const t=this[e];for(;0!==t.length;){const e=await t.shift()();"function"==typeof e&&this.after_page_is_killed.push(e)}}}window.CradovaEvent=new cradovaEvent;class Signal{pn;subscribers={};data={};picker={};soft={};passers;queue=new Set;constructor(e,t){if(!e||"object"!=typeof e||Array.isArray(e))throw new Error("Initial signal value must be an object");if(this.picker=e,t&&t.persistName){this.pn=t.persistName;const r=localStorage.getItem(t.persistName);if(r&&"undefined"!==r){const t=JSON.parse(r);this.picker=Object.assign(e,t)}}for(const e in this.picker)Object.defineProperty(this.data,e,{set:t=>{this.picker[e]=t,this.queue.add(e),queueMicrotask((()=>this.queue.size&&this.publish()))},get:()=>this.picker[e],enumerable:!0,configurable:!0}),Object.defineProperty(this.soft,e,{set:t=>{this.picker[e]=t},enumerable:!0,configurable:!0})}publish(){const e=new Set;this.queue.add("__ALL__");for(const t of this.queue)if(this.picker.hasOwnProperty(t)||"__ALL__"===t){const r=this.subscribers[t];if(r)for(const t of r)e.add(t)}else"__ALL__"!==t&&delete this.subscribers[t];this.queue.clear();for(const t of e.values())t.published?compManager.recall(t):t();this.pn&&localStorage.setItem(this.pn,JSON.stringify(this.picker))}set(e){Object.assign(this.picker,e),this.queue=new Set(Object.keys(this.subscribers)),queueMicrotask((()=>this.publish()))}computed(e,t){if(!e)return void console.error(` ✘  Cradova err:  eventName ${String(e)} or listener ${String(t)} is not a valid event name or function`);"function"==typeof e&&(t=e,e="__ALL__"),this.subscribers[e]||(this.subscribers[e]=[]);if(!isArrowFunc(t)){const r=toComp(t);return void 0!==r&&r instanceof HTMLElement&&r instanceof DocumentFragment?(this.subscribers[e].push(t),r):void console.error(` ✘  Cradova err:  ${String(t)} is not a valid element or function`)}this.subscribers[e].push(t)}get pass(){if(this.passers)return this.passers;const e=Object.keys(this.picker);this.passers={};for(const t of e)this.passers[t]=[t,this];return this.passers}clearPersist(){this.pn&&localStorage.removeItem(this.pn)}}class List{state;item;length;itemHeight=35;windowCoverage=500;itemsInVisibleRange=20;scrollingDirection="vertical";opts;columns=1;container;rendered=!1;scrollPos=0;subscribers=[];list;listContainer;constructor(e,t,r){this.state=e,this.item=t||((e,t)=>div(String(e)+" "+t)),this.length=e.length,this.opts=r,this.itemHeight=r?.itemHeight||35,this.columns=r?.columns||1,this.windowCoverage=r?.windowHeight||r?.windowWidth||500,this.itemsInVisibleRange=r?.itemsInVisibleRange||20,this.scrollingDirection=r?.scrollingDirection||"vertical",this.container=div({className:this.opts?.className,onscroll:e=>{this.scrollPos=Math.floor("vertical"===this.scrollingDirection?e.target.scrollTop:e.target.scrollLeft),requestAnimationFrame((()=>this.render()))},style:{overflowY:"vertical"===this.scrollingDirection?"scroll":"hidden",overflowX:"horizontal"===this.scrollingDirection?"scroll":"hidden"}},div({id:"listContainer",style:{height:`${Math.round(this.length*this.itemHeight/this.columns)}px`}},div({id:"list",className:this.opts?.className,style:{transform:"vertical"===this.scrollingDirection?`translateY(${this.scrollPos}px)`:`translateX(${this.scrollPos}px)`}}))),this.listContainer=this.container.querySelector("#listContainer"),this.list=this.container.querySelector("#list")}get Element(){if(!this.rendered){this.render(),this.rendered=!0;const e=()=>{const e=this.container.getBoundingClientRect();e.top<0&&e.bottom>window.innerHeight&&(this.scrollPos=Math.abs(e.top),requestAnimationFrame((()=>this.render())))};window.addEventListener("scroll",e),window.CradovaEvent.after_page_is_killed.push((()=>{window.removeEventListener("scroll",e)}))}return this.container}render(){const e=Math.floor(this.scrollPos/this.itemHeight)*this.columns;this.list.style.transform="vertical"===this.scrollingDirection?`translateY(${Math.floor(this.scrollPos/this.itemHeight)*this.itemHeight}px)`:`translateX(${Math.floor(this.scrollPos/this.itemHeight)*this.itemHeight}px)`;const t=(Math.ceil(this.windowCoverage/this.itemHeight)+this.itemsInVisibleRange)*this.columns,r=Math.min(this.length-1,e+t-1);for(let t=this.list.children.length-1;t>=0;t--){const o=this.list.children[t],n=parseInt(o.dataset.index||"-1",10);(n<e||n>r)&&this.list.removeChild(o)}for(let t=e;t<=r;t++)if(!this.list.querySelector(`[data-index="${t}"]`)){const e=this.item(this.state[t],t);e.dataset.index=String(t);let r=!1;for(const o of this.list.children){if(t<parseInt(o.dataset.index||"-1",10)){this.list.insertBefore(e,o),r=!0;break}}r||this.list.appendChild(e)}r+1>=this.length&&this.opts?.onScrollEnd?.()}computed(e){if(!e)return void console.error(` ✘  Cradova err:  listener ${String(e)} is not a valid event name or function`);this.subscribers||(this.subscribers=[]);if(!isArrowFunc(e)){const t=toComp(e);return void 0!==t&&t instanceof HTMLElement&&t instanceof DocumentFragment?(this.subscribers.push(e),t):void console.error(` ✘  Cradova err:  ${String(e)} is not a valid element or function`)}this.subscribers.push(e)}diffDOMBeforeUpdatingState(e){this.length!==e.length&&(this.listContainer.style.height=`${Math.round(e.length*this.itemHeight/this.columns)}px`,this.length=e.length),this.state=e,this.render(),queueMicrotask((()=>{for(const e of this.subscribers)e.published?compManager.recall(e):e()}))}get data(){return{[Symbol.iterator]:()=>this.state[Symbol.iterator](),next:()=>this.state[Symbol.iterator]().next()}}get(e){return this.state[e]}indexOf(e){return this.state.indexOf(e)}update(e,t){const r=[...this.state];e>=0&&e<this.state.length&&this.state[e]!==t&&(r[e]=t),this.diffDOMBeforeUpdatingState(r)}push(e){const t=[...this.state];t.push(e),this.diffDOMBeforeUpdatingState(t)}map(e){return[...this.state].map(e)}splice(e,t=1,...r){const o=[...this.state];e>=0&&e<this.state.length&&t>0&&o.splice(e,t,...r),this.diffDOMBeforeUpdatingState(o)}set(e){const t=e instanceof Function?e(this.state):e;this.diffDOMBeforeUpdatingState(t)}}class Page{_name;_html;_template;_unload_CB;_activate_CB;constructor(e){const{template:t,title:r}=e;if("function"!=typeof t)throw new Error(" ✘  Cradova err:  template function for the page is not a function");this._html=t,this._name=r||document.title}set onDeactivate(e){this._unload_CB=e}set onActivate(e){this._activate_CB=e}async _load(){this._name&&(document.title=this._name),window.CradovaEvent.dispatchEvent("after_page_is_killed"),this._template=div({id:"page"},this._html),RouterBox.doc.innerHTML="",RouterBox.doc.appendChild(this._template),this._activate_CB&&await this._activate_CB.apply(this),window.CradovaEvent.dispatchEvent("after_comp_is_mounted")}}class RouterBoxClass{doc=null;lastNavigatedRouteController;nextRouteController;lastNavigatedRoute;pageShow=null;pageHide=null;errorHandler;loadingPage=null;pageData={params:{}};routes={};paused=!1;route(e,t){return t||console.error(" ✘  Cradova err:  not a valid page  ",t),this.routes[e]=t}async router(){const e=window.location.href;let t,r;if(this.paused)window.location.hash="paused";else if(e!==this.lastNavigatedRoute)if(this.nextRouteController?(t=this.nextRouteController,this.nextRouteController=void 0):[t,r]=this.checker(e),void 0!==t)try{if("function"==typeof t&&(this.loadingPage instanceof Page&&await this.loadingPage._load(),t=await t()),t?.default&&(t=t.default),!t)return;r&&(this.pageData.params=r),await t._load(),this.lastNavigatedRouteController&&(this.lastNavigatedRouteController._template=void 0)&&this.lastNavigatedRouteController._unload_CB?.apply(this.lastNavigatedRouteController),this.lastNavigatedRoute=e,this.lastNavigatedRouteController=t}catch(t){"function"==typeof this.errorHandler?this.errorHandler(t,e):console.error(t)}else this.routes["*"]&&await this.routes["*"]._load()}checker(e){if("/"!==e[0]&&(e=e.slice(e.indexOf("/",8))),this.routes[e])return[this.routes[e],{path:e}];if(e.includes("?")){let t;const r={};if([e,t]=e.split("?"),new URLSearchParams(t).forEach(((e,t)=>{r[t]=e})),this.routes[e])return[this.routes[e],r]}for(const t in this.routes){if(t.includes(":")){const r=e.split("/"),o=t.split("/");e.endsWith("/")&&r.pop();let n=0,i=0;if(o.length===r.length){for(let e=0;e<o.length;e++)o[e].includes(":")?i++:r[e]===o[e]&&n++;if(n+i===o.length){const e={};for(let t=0;t<o.length;t++)o[t].includes(":")&&(e[o[t].split(":")[1]]=r[t]);return[this.routes[t],e]}}}if(t.includes("*")){const r=t.slice(0,-1);if(e.startsWith(r))return[this.routes[t],{extraPath:e.slice(r.length)}]}}return[]}}var RouterBox=new RouterBoxClass;class Router{static BrowserRoutes(e){for(const t in e){const r=e[t];"object"==typeof r&&"function"==typeof r.then||"function"==typeof r?RouterBox.routes[t]=async()=>{const e="function"==typeof r?await r():await r;return RouterBox.route(t,e)}:RouterBox.route(t,r)}Router._mount()}static pauseNavigation(){RouterBox.paused=!0,window.location.hash="paused"}static resumeNavigation(){RouterBox.paused=!1,window.location.replace(window.location.pathname+window.location.search),history.go(-1)}static navigate(e,t){if(RouterBox.paused)return;"string"!=typeof e&&console.error(" ✘  Cradova err:  href must be a defined path but got "+e+" instead");let r,o=null;e.includes(".")?window.location.href=e:([o,r]=RouterBox.checker(e),o&&(RouterBox.nextRouteController=o,window.history.pushState({},"",e)),RouterBox.pageData.params=r,RouterBox.pageData.data=t,RouterBox.router())}static setLoadingPage(e){if(!(e instanceof Page))throw new Error(" ✘  Cradova err:  Loading Page should be a cradova page class");RouterBox.loadingPage=e}static get PageData(){return RouterBox.pageData}static addErrorHandler(e){if("function"!=typeof e)throw new Error(" ✘  Cradova err:  callback for error event is not a function");RouterBox.errorHandler=e}static _mount(){let e=document.querySelector("[data-wrapper=app]");if(!e)throw new Error("✘  Cradova err: please add '<div data-wrapper=\"app\"></div>' to the body of your index.html file ");RouterBox.doc=e,window.addEventListener("pageshow",(()=>RouterBox.router())),window.addEventListener("hashchange",(()=>{RouterBox.paused?history.forward():RouterBox.router()})),window.addEventListener("popstate",(e=>{e.preventDefault(),RouterBox.paused?history.forward():RouterBox.router()}))}}class RefInstance{$refs={};current(e){return document.contains(this.$refs[e])||(this.$refs[e]=void 0),this.$refs[e]}get refs(){return this.$refs}bind(e){return[this,e]}}export{video,useExternalEffect,ul,tr,toCompNoRender,toComp,textarea,td,tbody,table,span,select,section,raw,p,option,ol,nav,makeElement,main,loop,li,label,isArrowFunc,invoke,input,img,iframe,i,header,h6,h5,h4,h3,h2,h1,fragment,form,footer,div,cra,compManager,canvas,button,audio,a,Signal,Router,RefInstance,Page,List,$switch,$case};
//# sourceMappingURL=/sm/9c4439b3e6e6dd2c40acee2e69d508f2ceaa9879c745434c89bc7367fa17442e.map