apprun 3.33.10 → 3.35.0

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,4 +1,4 @@
1
- class t{constructor(){this._events={}}on(t,s,i={}){this._events[t]=this._events[t]||[],this._events[t].push({fn:s,options:i})}off(t,s){const i=this._events[t]||[];this._events[t]=i.filter((t=>t.fn!==s))}find(t){return this._events[t]}run(t,...s){const i=this.getSubscribers(t,this._events);return console.assert(i&&i.length>0,"No subscriber for event: "+t),i.forEach((i=>{const{fn:e,options:n}=i;return n.delay?this.delay(t,e,s,n):Object.keys(n).length>0?e.apply(this,[...s,n]):e.apply(this,s),!i.options.once})),i.length}once(t,s,i={}){this.on(t,s,Object.assign(Object.assign({},i),{once:!0}))}delay(t,s,i,e){e._t&&clearTimeout(e._t),e._t=setTimeout((()=>{clearTimeout(e._t),Object.keys(e).length>0?s.apply(this,[...i,e]):s.apply(this,i)}),e.delay)}runAsync(t,...s){const i=this.getSubscribers(t,this._events);console.assert(i&&i.length>0,"No subscriber for event: "+t);const e=i.map((t=>{const{fn:i,options:e}=t;return Object.keys(e).length>0?i.apply(this,[...s,e]):i.apply(this,s)}));return Promise.all(e)}query(t,...s){return this.runAsync(t,...s)}getSubscribers(t,s){const i=s[t]||[];return s[t]=i.filter((t=>!t.options.once)),Object.keys(s).filter((s=>s.endsWith("*")&&t.startsWith(s.replace("*","")))).sort(((t,s)=>s.length-t.length)).forEach((e=>i.push(...s[e].map((s=>Object.assign(Object.assign({},s),{options:Object.assign(Object.assign({},s.options),{event:t})})))))),i}}let s;const i="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};i.app&&i._AppRunVersions?s=i.app:(s=new t,i.app=s,i._AppRunVersions="AppRun-3");var e=s;const n=(t,s)=>(s?t.state[s]:t.state)||"",o=(t,s,i)=>{if(s){const e=t.state||{};e[s]=i,t.setState(e)}else t.setState(i)},r=(t,s)=>{if(Array.isArray(t))return t.map((t=>r(t,s)));{let{type:i,tag:h,props:c,children:l}=t;return h=h||i,l=l||(null==c?void 0:c.children),c&&Object.keys(c).forEach((t=>{t.startsWith("$")&&(((t,s,i,r)=>{if(t.startsWith("$on")){const i=s[t];if(t=t.substring(1),"boolean"==typeof i)s[t]=s=>r.run?r.run(t,s):e.run(t,s);else if("string"==typeof i)s[t]=t=>r.run?r.run(i,t):e.run(i,t);else if("function"==typeof i)s[t]=t=>r.setState(i(r.state,t));else if(Array.isArray(i)){const[n,...o]=i;"string"==typeof n?s[t]=t=>r.run?r.run(n,...o,t):e.run(n,...o,t):"function"==typeof n&&(s[t]=t=>r.setState(n(r.state,...o,t)))}}else if("$bind"===t){const e=s.type||"text",h="string"==typeof s[t]?s[t]:s.name;if("input"===i)switch(e){case"checkbox":s.checked=n(r,h),s.onclick=t=>o(r,h||t.target.name,t.target.checked);break;case"radio":s.checked=n(r,h)===s.value,s.onclick=t=>o(r,h||t.target.name,t.target.value);break;case"number":case"range":s.value=n(r,h),s.oninput=t=>o(r,h||t.target.name,Number(t.target.value));break;default:s.value=n(r,h),s.oninput=t=>o(r,h||t.target.name,t.target.value)}else"select"===i?(s.value=n(r,h),s.onchange=t=>{t.target.multiple||o(r,h||t.target.name,t.target.value)}):"option"===i?(s.selected=n(r,h),s.onclick=t=>o(r,h||t.target.name,t.target.selected)):"textarea"===i&&(s.innerHTML=n(r,h),s.oninput=t=>o(r,h||t.target.name,t.target.value))}else e.run("$",{key:t,tag:i,props:s,component:r})})(t,c,h,s),delete c[t])})),l&&r(l,s),t}};function h(t,...s){return l(s)}const c="_props";function l(t){const s=[],i=t=>{null!=t&&""!==t&&!1!==t&&s.push("function"==typeof t||"object"==typeof t?t:`${t}`)};return t&&t.forEach((t=>{Array.isArray(t)?t.forEach((t=>i(t))):i(t)})),s}function u(t,s,...i){const e=l(i);if("string"==typeof t)return{tag:t,props:s,children:e};if(Array.isArray(t))return t;if(void 0===t&&i)return e;if(Object.getPrototypeOf(t).i)return{tag:t,props:s,children:e};if("function"==typeof t)return t(s,e);throw new Error(`Unknown tag in vdom ${t}`)}const a=new WeakMap,f=(t,s,i={})=>{if(null==s||!1===s)return;!function(t,s,i={}){if(null==s||!1===s)return;if(s=m(s,i),!t)return;const e="SVG"===t.nodeName;Array.isArray(s)?p(t,s,e):p(t,[s],e)}("string"==typeof t&&t?document.getElementById(t)||document.querySelector(t):t,s=r(s,i),i)};function d(t,s,i){3!==s._op&&(i=i||"svg"===s.tag,!function(t,s){const i=t.nodeName,e=`${s.tag||""}`;return i.toUpperCase()===e.toUpperCase()}(t,s)?t.parentNode.replaceChild(b(s,i),t):(!(2&s._op)&&p(t,s.children,i),!(1&s._op)&&w(t,s.props,i)))}function p(t,s,i){var e,n;const o=(null===(e=t.childNodes)||void 0===e?void 0:e.length)||0,r=(null==s?void 0:s.length)||0,h=Math.min(o,r);for(let e=0;e<h;e++){const n=s[e];if(3===n._op)continue;const o=t.childNodes[e];if("string"==typeof n)o.textContent!==n&&(3===o.nodeType?o.nodeValue=n:t.replaceChild(v(n),o));else if(n instanceof HTMLElement||n instanceof SVGElement)t.insertBefore(n,o);else{const s=n.props&&n.props.key;if(s)if(o.key===s)d(t.childNodes[e],n,i);else{const r=a[s];if(r){const s=r.nextSibling;t.insertBefore(r,o),s?t.insertBefore(o,s):t.appendChild(o),d(t.childNodes[e],n,i)}else t.replaceChild(b(n,i),o)}else d(t.childNodes[e],n,i)}}let c=(null===(n=t.childNodes)||void 0===n?void 0:n.length)||0;for(;c>h;)t.removeChild(t.lastChild),c--;if(r>h){const e=document.createDocumentFragment();for(let t=h;t<s.length;t++)e.appendChild(b(s[t],i));t.appendChild(e)}}const y=t=>{const s=document.createElement("section");return s.insertAdjacentHTML("afterbegin",t),Array.from(s.children)};function v(t){if(0===(null==t?void 0:t.indexOf("_html:"))){const s=document.createElement("div");return s.insertAdjacentHTML("afterbegin",t.substring(6)),s}return document.createTextNode(null!=t?t:"")}function b(t,s){if(t instanceof HTMLElement||t instanceof SVGElement)return t;if("string"==typeof t)return v(t);if(!t.tag||"function"==typeof t.tag)return v(JSON.stringify(t));const i=(s=s||"svg"===t.tag)?document.createElementNS("http://www.w3.org/2000/svg",t.tag):document.createElement(t.tag);return w(i,t.props,s),t.children&&t.children.forEach((t=>i.appendChild(b(t,s)))),i}function w(t,s,i){const e=t[c]||{};s=function(t,s){s.class=s.class||s.className,delete s.className;const i={};return t&&Object.keys(t).forEach((t=>i[t]=null)),Object.keys(s).forEach((t=>i[t]=s[t])),i}(e,s||{}),t[c]=s;for(const e in s){const n=s[e];if(e.startsWith("data-")){const s=e.substring(5).replace(/-(\w)/g,(t=>t[1].toUpperCase()));t.dataset[s]!==n&&(n||""===n?t.dataset[s]=n:delete t.dataset[s])}else if("style"===e)if(t.style.cssText&&(t.style.cssText=""),"string"==typeof n)t.style.cssText=n;else for(const s in n)t.style[s]!==n[s]&&(t.style[s]=n[s]);else if(e.startsWith("xlink")){const s=e.replace("xlink","").toLowerCase();null==n||!1===n?t.removeAttributeNS("http://www.w3.org/1999/xlink",s):t.setAttributeNS("http://www.w3.org/1999/xlink",s,n)}else e.startsWith("on")?n&&"function"!=typeof n?"string"==typeof n&&(n?t.setAttribute(e,n):t.removeAttribute(e)):t[e]=n:/^id$|^class$|^list$|^readonly$|^contenteditable$|^role|-|^for$/g.test(e)||i?t.getAttribute(e)!==n&&(n?t.setAttribute(e,n):t.removeAttribute(e)):t[e]!==n&&(t[e]=n);"key"===e&&n&&(a[n]=t)}s&&"function"==typeof s.ref&&window.requestAnimationFrame((()=>s.ref(t)))}function m(t,s,i=0){var e;if("string"==typeof t)return t;if(Array.isArray(t))return t.map((t=>m(t,s,i++)));let n=t;if(t&&"function"==typeof t.tag&&Object.getPrototypeOf(t.tag).i&&(n=function(t,s,i){const{tag:e,props:n,children:o}=t;let r=`_${i}`,h=n&&n.id;h?r=h:h=`_${i}${Date.now()}`;let c="section";n&&n.as&&(c=n.as,delete n.as),s.v||(s.v={});let l=s.v[r];if(l&&l instanceof e&&l.element)l.renderState(l.state);else{const t=document.createElement(c);l=s.v[r]=new e(Object.assign(Object.assign({},n),{children:o})).mount(t,{render:!0})}if(l.mounted){const t=l.mounted(n,o,l.state);void 0!==t&&l.setState(t)}return w(l.element,n,!1),l.element}(t,s,i)),n&&Array.isArray(n.children)){const t=null===(e=n.props)||void 0===e?void 0:e._component;if(t){let s=0;n.children=n.children.map((i=>m(i,t,s++)))}else n.children=n.children.map((t=>m(t,s,i++)))}return n}const g=(t,s={})=>class extends HTMLElement{constructor(){super()}get component(){return this._component}get state(){return this._component.state}static get observedAttributes(){return(s.observedAttributes||[]).map((t=>t.toLowerCase()))}connectedCallback(){if(this.isConnected&&!this._component){const i=s||{};this._shadowRoot=i.shadow?this.attachShadow({mode:"open"}):this;const e=i.observedAttributes||[],n=e.reduce(((t,s)=>{const i=s.toLowerCase();return i!==s&&(t[i]=s),t}),{});this._attrMap=t=>n[t]||t;const o={};Array.from(this.attributes).forEach((t=>o[this._attrMap(t.name)]=t.value)),e.forEach((t=>{void 0!==this[t]&&(o[t]=this[t]),Object.defineProperty(this,t,{get:()=>o[t],set(s){this.attributeChangedCallback(t,o[t],s)},configurable:!0,enumerable:!0})})),requestAnimationFrame((()=>{const s=this.children?Array.from(this.children):[];if(this._component=new t(Object.assign(Object.assign({},o),{children:s})).mount(this._shadowRoot,i),this._component._props=o,this._component.dispatchEvent=this.dispatchEvent.bind(this),this._component.mounted){const t=this._component.mounted(o,s,this._component.state);void 0!==t&&(this._component.state=t)}this.on=this._component.on.bind(this._component),this.run=this._component.run.bind(this._component),!1!==i.render&&this._component.run(".")}))}}disconnectedCallback(){var t,s,i,e;null===(s=null===(t=this._component)||void 0===t?void 0:t.unload)||void 0===s||s.call(t),null===(e=null===(i=this._component)||void 0===i?void 0:i.unmount)||void 0===e||e.call(i),this._component=null}attributeChangedCallback(t,i,e){if(this._component){const n=this._attrMap(t);this._component._props[n]=e,this._component.run("attributeChanged",n,i,e),e!==i&&!1!==s.render&&window.requestAnimationFrame((()=>{this._component.run(".")}))}}};var $=(t,s,i)=>{"undefined"!=typeof customElements&&customElements.define(t,g(s,i))};const S={meta:new WeakMap,defineMetadata(t,s,i){this.meta.has(i)||this.meta.set(i,{}),this.meta.get(i)[t]=s},getMetadataKeys(t){return t=Object.getPrototypeOf(t),this.meta.get(t)?Object.keys(this.meta.get(t)):[]},getMetadata(t,s){return s=Object.getPrototypeOf(s),this.meta.get(s)?this.meta.get(s)[t]:null}};function O(t,s={}){return(i,e,n)=>{const o=t?t.toString():e;return S.defineMetadata(`apprun-update:${o}`,{name:o,key:e,options:s},i),n}}function A(t,s={}){return function(i,e){const n=t?t.toString():e;S.defineMetadata(`apprun-update:${n}`,{name:n,key:e,options:s},i)}}function _(t,s){return function(i){return $(t,i,s),i}}const j=new Map;e.find("get-components")||e.on("get-components",(t=>t.components=j));const k=t=>t;class E{renderState(t,s=null){if(!this.view)return;let i=s||this.view(t);if(e.debug&&e.run("debug",{component:this,_:i?".":"-",state:t,vdom:i,el:this.element}),"object"!=typeof document)return;const n="string"==typeof this.element&&this.element?document.getElementById(this.element)||document.querySelector(this.element):this.element;if(!n)return;const o="_c";this.unload?n._component===this&&n.getAttribute(o)===this.tracking_id||(this.tracking_id=(new Date).valueOf().toString(),n.setAttribute(o,this.tracking_id),"undefined"!=typeof MutationObserver&&(this.observer||(this.observer=new MutationObserver((t=>{t[0].oldValue!==this.tracking_id&&document.body.contains(n)||(this.unload(this.state),this.observer.disconnect(),this.observer=null)}))),this.observer.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeOldValue:!0,attributeFilter:[o]}))):n.removeAttribute&&n.removeAttribute(o),n._component=this,!s&&i&&(i=r(i,this),this.options.transition&&document&&document.startViewTransition?document.startViewTransition((()=>e.render(n,i,this))):e.render(n,i,this)),this.rendered&&this.rendered(this.state)}setState(t,s={render:!0,history:!1}){const i=async t=>{try{for(;;){const{value:i,done:e}=await t.next();if(e)break;this.setState(i,s)}}catch(t){console.error("Error in async iterator:",t)}},e=t;if(null==e?void 0:e[Symbol.asyncIterator])this.setState(i(e[Symbol.asyncIterator]()),s);else if((null==e?void 0:e[Symbol.iterator])&&"function"==typeof e.next)for(const t of e)this.setState(t,s);else if(t&&t instanceof Promise)Promise.resolve(t).then((i=>{this.setState(i,s),this._state=t}));else{if(this._state=t,null==t)return;this.state=t,!1!==s.render&&(s.transition&&document&&document.startViewTransition?document.startViewTransition((()=>this.renderState(t))):this.renderState(t)),!1!==s.history&&this.enable_history&&(this._history=[...this._history,t],this._history_idx=this._history.length-1),"function"==typeof s.callback&&s.callback(this.state)}}constructor(s,i,e,n){this.state=s,this.view=i,this.update=e,this.options=n,this._app=new t,this._actions=[],this._global_events=[],this._history=[],this._history_idx=-1,this._history_prev=()=>{this._history_idx--,this._history_idx>=0?this.setState(this._history[this._history_idx],{render:!0,history:!1}):this._history_idx=0},this._history_next=()=>{this._history_idx++,this._history_idx<this._history.length?this.setState(this._history[this._history_idx],{render:!0,history:!1}):this._history_idx=this._history.length-1},this.start=(t=null,s)=>{if(this.mount(t,Object.assign({render:!0},s)),this.mounted&&"function"==typeof this.mounted){const t=this.mounted({},[],this.state);void 0!==t&&this.setState(t)}return this}}mount(t=null,s){var i,n;return console.assert(!this.element,"Component already mounted."),this.options=s=Object.assign(Object.assign({},this.options),s),this.element=t,this.global_event=s.global_event,this.enable_history=!!s.history,this.enable_history&&(this.on(s.history.prev||"history-prev",this._history_prev),this.on(s.history.next||"history-next",this._history_next)),s.route&&(this.update=this.update||{},this.update[s.route]||(this.update[s.route]=k)),this.add_actions(),this.state=null!==(n=null!==(i=this.state)&&void 0!==i?i:this.model)&&void 0!==n?n:{},"function"==typeof this.state&&(this.state=this.state()),this.setState(this.state,{render:!!s.render,history:!0}),e.debug&&(j.get(t)?j.get(t).push(this):j.set(t,[this])),this}is_global_event(t){return t&&(this.global_event||this._global_events.indexOf(t)>=0||t.startsWith("#")||t.startsWith("/")||t.startsWith("@"))}add_action(t,s,i={}){s&&"function"==typeof s&&(i.global&&this._global_events.push(t),this.on(t,((...n)=>{e.debug&&e.run("debug",{component:this,_:">",event:t,p:n,current_state:this.state,options:i});const o=s(this.state,...n);e.debug&&e.run("debug",{component:this,_:"<",event:t,p:n,newState:o,state:this.state,options:i}),this.setState(o,i)}),i))}add_actions(){const t=this.update||{};S.getMetadataKeys(this).forEach((s=>{if(s.startsWith("apprun-update:")){const i=S.getMetadata(s,this);t[i.name]=[this[i.key].bind(this),i.options]}}));const s={};Array.isArray(t)?t.forEach((t=>{const[i,e,n]=t;i.toString().split(",").forEach((t=>s[t.trim()]=[e,n]))})):Object.keys(t).forEach((i=>{const e=t[i];("function"==typeof e||Array.isArray(e))&&i.split(",").forEach((t=>s[t.trim()]=e))})),s["."]||(s["."]=k),Object.keys(s).forEach((t=>{const i=s[t];"function"==typeof i?this.add_action(t,i):Array.isArray(i)&&this.add_action(t,i[0],i[1])}))}run(t,...s){if(this.state instanceof Promise)return Promise.resolve(this.state).then((i=>{this.state=i,this.run(t,...s)}));{const i=t.toString();return this.is_global_event(i)?e.run(i,...s):this._app.run(i,...s)}}on(t,s,i){const n=t.toString();return this._actions.push({name:n,fn:s}),this.is_global_event(n)?e.on(n,s,i):this._app.on(n,s,i)}runAsync(t,...s){const i=t.toString();return this.is_global_event(i)?e.runAsync(i,...s):this._app.runAsync(i,...s)}query(t,...s){return this.runAsync(t,...s)}unmount(){var t;null===(t=this.observer)||void 0===t||t.disconnect(),this._actions.forEach((t=>{const{name:s,fn:i}=t;this.is_global_event(s)?e.off(s,i):this._app.off(s,i)}))}}E.i=!0;const M="//",C="///",x=t=>{if(t||(t="#"),t.startsWith("#")){const[s,...i]=t.split("/");e.run(s,...i)||e.run(C,s,...i),e.run(M,s,...i)}else if(t.startsWith("/")){const[s,i,...n]=t.split("/");e.run("/"+i,...n)||e.run(C,"/"+i,...n),e.run(M,"/"+i,...n)}else e.run(t)||e.run(C,t),e.run(M,t)};if(!e.start){e.h=e.createElement=u,e.render=f,e.Fragment=h,e.webComponent=$,e.safeHTML=y,e.start=(t,s,i,e,n)=>{const o=Object.assign({render:!0,global_event:!0},n),r=new E(s,i,e);return n&&n.rendered&&(r.rendered=n.rendered),n&&n.mounted&&(r.mounted=n.mounted),r.start(t,o),r};const t=t=>{};e.on("$",t),e.on("debug",(s=>t)),e.on(M,t),e.on("#",t),e.route=x,e.on("route",(t=>e.route&&e.route(t))),"object"==typeof document&&document.addEventListener("DOMContentLoaded",(()=>{e.route===x&&(window.onpopstate=()=>x(location.hash),document.body.hasAttribute("apprun-no-init")||e["no-init-route"]||x(location.hash))})),"object"==typeof window&&(window.Component=E,window._React=window.React,window.React=e,window.on=A,window.customElement=_,window.safeHTML=y),e.use_render=(t,s=0)=>{e.render=0===s?(s,i)=>t(i,s):(s,i)=>t(s,i)},e.use_react=(t,s)=>{e.h=e.createElement=t.createElement,e.Fragment=t.Fragment,e.render=(t,i)=>s.render(i,t),t.version&&t.version.startsWith("18")&&(e.render=(t,i)=>{t&&i&&(t._root||(t._root=s.createRoot(t)),t._root.render(i))})},e.use_prettyLink=()=>{window.onload=()=>e.route(location.pathname),window.addEventListener("popstate",(()=>e.route(location.pathname))),document.body.addEventListener("click",(t=>{const s=t.target,i="A"===s.tagName?s:s.closest("a");i&&i.origin===location.origin&&(t.preventDefault(),history.pushState(null,"",i.pathname),e.route(i.pathname))}))}}
1
+ class t{constructor(){this._events={}}on(t,s,i={}){this._events[t]=this._events[t]||[],this._events[t].push({fn:s,options:i})}off(t,s){const i=this._events[t]||[];this._events[t]=i.filter((t=>t.fn!==s))}find(t){return this._events[t]}run(t,...s){const i=this.getSubscribers(t,this._events);return console.assert(i&&i.length>0,"No subscriber for event: "+t),i.forEach((i=>{const{fn:e,options:n}=i;return n.delay?this.delay(t,e,s,n):Object.keys(n).length>0?e.apply(this,[...s,n]):e.apply(this,s),!i.options.once})),i.length}once(t,s,i={}){this.on(t,s,Object.assign(Object.assign({},i),{once:!0}))}delay(t,s,i,e){e._t&&clearTimeout(e._t),e._t=setTimeout((()=>{clearTimeout(e._t),Object.keys(e).length>0?s.apply(this,[...i,e]):s.apply(this,i)}),e.delay)}runAsync(t,...s){const i=this.getSubscribers(t,this._events);console.assert(i&&i.length>0,"No subscriber for event: "+t);const e=i.map((t=>{const{fn:i,options:e}=t;return Object.keys(e).length>0?i.apply(this,[...s,e]):i.apply(this,s)}));return Promise.all(e)}query(t,...s){return this.runAsync(t,...s)}getSubscribers(t,s){const i=s[t]||[];return s[t]=i.filter((t=>!t.options.once)),Object.keys(s).filter((s=>s.endsWith("*")&&t.startsWith(s.replace("*","")))).sort(((t,s)=>s.length-t.length)).forEach((e=>i.push(...s[e].map((s=>Object.assign(Object.assign({},s),{options:Object.assign(Object.assign({},s.options),{event:t})})))))),i}}let s;const i="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};i.app&&i._AppRunVersions?s=i.app:(s=new t,i.app=s,i._AppRunVersions="AppRun-3.3.11");var e=s;const n=(t,s)=>(s?t.state[s]:t.state)||"",o=(t,s,i)=>{if(s){const e=t.state||{};e[s]=i,t.setState(e)}else t.setState(i)},r=(t,s)=>{if(Array.isArray(t))return t.map((t=>r(t,s)));{let{type:i,tag:h,props:c,children:l}=t;return h=h||i,l=l||(null==c?void 0:c.children),c&&Object.keys(c).forEach((t=>{t.startsWith("$")&&(((t,s,i,r)=>{if(t.startsWith("$on")){const i=s[t];if(t=t.substring(1),"boolean"==typeof i)s[t]=s=>r.run?r.run(t,s):e.run(t,s);else if("string"==typeof i)s[t]=t=>r.run?r.run(i,t):e.run(i,t);else if("function"==typeof i)s[t]=t=>r.setState(i(r.state,t));else if(Array.isArray(i)){const[n,...o]=i;"string"==typeof n?s[t]=t=>r.run?r.run(n,...o,t):e.run(n,...o,t):"function"==typeof n&&(s[t]=t=>r.setState(n(r.state,...o,t)))}}else if("$bind"===t){const e=s.type||"text",h="string"==typeof s[t]?s[t]:s.name;if("input"===i)switch(e){case"checkbox":s.checked=n(r,h),s.onclick=t=>o(r,h||t.target.name,t.target.checked);break;case"radio":s.checked=n(r,h)===s.value,s.onclick=t=>o(r,h||t.target.name,t.target.value);break;case"number":case"range":s.value=n(r,h),s.oninput=t=>o(r,h||t.target.name,Number(t.target.value));break;default:s.value=n(r,h),s.oninput=t=>o(r,h||t.target.name,t.target.value)}else"select"===i?(s.value=n(r,h),s.onchange=t=>{t.target.multiple||o(r,h||t.target.name,t.target.value)}):"option"===i?(s.selected=n(r,h),s.onclick=t=>o(r,h||t.target.name,t.target.selected)):"textarea"===i&&(s.innerHTML=n(r,h),s.oninput=t=>o(r,h||t.target.name,t.target.value))}else e.run("$",{key:t,tag:i,props:s,component:r})})(t,c,h,s),delete c[t])})),l&&r(l,s),t}};function h(t,...s){return l(s)}const c="_props";function l(t){const s=[],i=t=>{null!=t&&""!==t&&!1!==t&&s.push("function"==typeof t||"object"==typeof t?t:`${t}`)};return t&&t.forEach((t=>{Array.isArray(t)?t.forEach((t=>i(t))):i(t)})),s}function u(t,s,...i){const e=l(i);if("string"==typeof t)return{tag:t,props:s,children:e};if(Array.isArray(t))return t;if(void 0===t&&i)return e;if(Object.getPrototypeOf(t).i)return{tag:t,props:s,children:e};if("function"==typeof t)return t(s,e);throw new Error(`Unknown tag in vdom ${t}`)}const a=new WeakMap,f=(t,s,i={})=>{if(null==s||!1===s)return;!function(t,s,i={}){if(null==s||!1===s)return;if(s=m(s,i),!t)return;const e="SVG"===t.nodeName;Array.isArray(s)?p(t,s,e):p(t,[s],e)}("string"==typeof t&&t?document.getElementById(t)||document.querySelector(t):t,s=r(s,i),i)};function d(t,s,i){3!==s._op&&(i=i||"svg"===s.tag,!function(t,s){const i=t.nodeName,e=`${s.tag||""}`;return i.toUpperCase()===e.toUpperCase()}(t,s)?t.parentNode.replaceChild(b(s,i),t):(!(2&s._op)&&p(t,s.children,i),!(1&s._op)&&w(t,s.props,i)))}function p(t,s,i){var e,n;const o=(null===(e=t.childNodes)||void 0===e?void 0:e.length)||0,r=(null==s?void 0:s.length)||0,h=Math.min(o,r);for(let e=0;e<h;e++){const n=s[e];if(3===n._op)continue;const o=t.childNodes[e];if("string"==typeof n)o.textContent!==n&&(3===o.nodeType?o.nodeValue=n:t.replaceChild(v(n),o));else if(n instanceof HTMLElement||n instanceof SVGElement)t.insertBefore(n,o);else{const s=n.props&&n.props.key;if(s)if(o.key===s)d(t.childNodes[e],n,i);else{const r=a[s];if(r){const s=r.nextSibling;t.insertBefore(r,o),s?t.insertBefore(o,s):t.appendChild(o),d(t.childNodes[e],n,i)}else t.replaceChild(b(n,i),o)}else d(t.childNodes[e],n,i)}}let c=(null===(n=t.childNodes)||void 0===n?void 0:n.length)||0;for(;c>h;)t.removeChild(t.lastChild),c--;if(r>h){const e=document.createDocumentFragment();for(let t=h;t<s.length;t++)e.appendChild(b(s[t],i));t.appendChild(e)}}const y=t=>{const s=document.createElement("section");return s.insertAdjacentHTML("afterbegin",t),Array.from(s.children)};function v(t){if(0===(null==t?void 0:t.indexOf("_html:"))){const s=document.createElement("div");return s.insertAdjacentHTML("afterbegin",t.substring(6)),s}return document.createTextNode(null!=t?t:"")}function b(t,s){if(t instanceof HTMLElement||t instanceof SVGElement)return t;if("string"==typeof t)return v(t);if(!t.tag||"function"==typeof t.tag)return v(JSON.stringify(t));const i=(s=s||"svg"===t.tag)?document.createElementNS("http://www.w3.org/2000/svg",t.tag):document.createElement(t.tag);return w(i,t.props,s),t.children&&t.children.forEach((t=>i.appendChild(b(t,s)))),i}function w(t,s,i){const e=t[c]||{};s=function(t,s){s.class=s.class||s.className,delete s.className;const i={};return t&&Object.keys(t).forEach((t=>i[t]=null)),Object.keys(s).forEach((t=>i[t]=s[t])),i}(e,s||{}),t[c]=s;for(const e in s){const n=s[e];if(e.startsWith("data-")){const s=e.substring(5).replace(/-(\w)/g,(t=>t[1].toUpperCase()));t.dataset[s]!==n&&(n||""===n?t.dataset[s]=n:delete t.dataset[s])}else if("style"===e)if(t.style.cssText&&(t.style.cssText=""),"string"==typeof n)t.style.cssText=n;else for(const s in n)t.style[s]!==n[s]&&(t.style[s]=n[s]);else if(e.startsWith("xlink")){const s=e.replace("xlink","").toLowerCase();null==n||!1===n?t.removeAttributeNS("http://www.w3.org/1999/xlink",s):t.setAttributeNS("http://www.w3.org/1999/xlink",s,n)}else e.startsWith("on")?n&&"function"!=typeof n?"string"==typeof n&&(n?t.setAttribute(e,n):t.removeAttribute(e)):t[e]=n:/^id$|^class$|^list$|^readonly$|^contenteditable$|^role|-|^for$/g.test(e)||i?t.getAttribute(e)!==n&&(n?t.setAttribute(e,n):t.removeAttribute(e)):t[e]!==n&&(t[e]=n);"key"===e&&n&&(a[n]=t)}s&&"function"==typeof s.ref&&window.requestAnimationFrame((()=>s.ref(t)))}function m(t,s,i=0){var e;if("string"==typeof t)return t;if(Array.isArray(t))return t.map((t=>m(t,s,i++)));let n=t;if(t&&"function"==typeof t.tag&&Object.getPrototypeOf(t.tag).i&&(n=function(t,s,i){const{tag:e,props:n,children:o}=t;let r=`_${i}`,h=n&&n.id;h?r=h:h=`_${i}${Date.now()}`;let c="section";n&&n.as&&(c=n.as,delete n.as),s.v||(s.v={});let l=s.v[r];if(l&&l instanceof e&&l.element)l.renderState(l.state);else{const t=document.createElement(c);l=s.v[r]=new e(Object.assign(Object.assign({},n),{children:o})).mount(t,{render:!0})}if(l.mounted){const t=l.mounted(n,o,l.state);void 0!==t&&l.setState(t)}return w(l.element,n,!1),l.element}(t,s,i)),n&&Array.isArray(n.children)){const t=null===(e=n.props)||void 0===e?void 0:e._component;if(t){let s=0;n.children=n.children.map((i=>m(i,t,s++)))}else n.children=n.children.map((t=>m(t,s,i++)))}return n}const g=(t,s={})=>class extends HTMLElement{constructor(){super()}get component(){return this._component}get state(){return this._component.state}static get observedAttributes(){return(s.observedAttributes||[]).map((t=>t.toLowerCase()))}connectedCallback(){if(this.isConnected&&!this._component){const i=s||{};this._shadowRoot=i.shadow?this.attachShadow({mode:"open"}):this;const e=i.observedAttributes||[],n=e.reduce(((t,s)=>{const i=s.toLowerCase();return i!==s&&(t[i]=s),t}),{});this._attrMap=t=>n[t]||t;const o={};Array.from(this.attributes).forEach((t=>o[this._attrMap(t.name)]=t.value)),e.forEach((t=>{void 0!==this[t]&&(o[t]=this[t]),Object.defineProperty(this,t,{get:()=>o[t],set(s){this.attributeChangedCallback(t,o[t],s)},configurable:!0,enumerable:!0})})),requestAnimationFrame((()=>{const s=this.children?Array.from(this.children):[];if(this._component=new t(Object.assign(Object.assign({},o),{children:s})).mount(this._shadowRoot,i),this._component._props=o,this._component.dispatchEvent=this.dispatchEvent.bind(this),this._component.mounted){const t=this._component.mounted(o,s,this._component.state);void 0!==t&&(this._component.state=t)}this.on=this._component.on.bind(this._component),this.run=this._component.run.bind(this._component),!1!==i.render&&this._component.run(".")}))}}disconnectedCallback(){var t,s,i,e;null===(s=null===(t=this._component)||void 0===t?void 0:t.unload)||void 0===s||s.call(t),null===(e=null===(i=this._component)||void 0===i?void 0:i.unmount)||void 0===e||e.call(i),this._component=null}attributeChangedCallback(t,i,e){if(this._component){const n=this._attrMap(t);this._component._props[n]=e,this._component.run("attributeChanged",n,i,e),e!==i&&!1!==s.render&&window.requestAnimationFrame((()=>{this._component.run(".")}))}}};var $=(t,s,i)=>{"undefined"!=typeof customElements&&customElements.define(t,g(s,i))};const S={meta:new WeakMap,defineMetadata(t,s,i){this.meta.has(i)||this.meta.set(i,{}),this.meta.get(i)[t]=s},getMetadataKeys(t){return t=Object.getPrototypeOf(t),this.meta.get(t)?Object.keys(this.meta.get(t)):[]},getMetadata(t,s){return s=Object.getPrototypeOf(s),this.meta.get(s)?this.meta.get(s)[t]:null}};function O(t,s={}){return(i,e,n)=>{const o=t?t.toString():e;return S.defineMetadata(`apprun-update:${o}`,{name:o,key:e,options:s},i),n}}function A(t,s={}){return function(i,e){const n=t?t.toString():e;S.defineMetadata(`apprun-update:${n}`,{name:n,key:e,options:s},i)}}function _(t,s){return function(i){return $(t,i,s),i}}const j=new Map;e.find("get-components")||e.on("get-components",(t=>t.components=j));const k=t=>t;class E{renderState(t,s=null){if(!this.view)return;let i=s||this.view(t);if(e.debug&&e.run("debug",{component:this,_:i?".":"-",state:t,vdom:i,el:this.element}),"object"!=typeof document)return;const n="string"==typeof this.element&&this.element?document.getElementById(this.element)||document.querySelector(this.element):this.element;if(!n)return;const o="_c";this.unload?n._component===this&&n.getAttribute(o)===this.tracking_id||(this.tracking_id=(new Date).valueOf().toString(),n.setAttribute(o,this.tracking_id),"undefined"!=typeof MutationObserver&&(this.observer||(this.observer=new MutationObserver((t=>{t[0].oldValue!==this.tracking_id&&document.body.contains(n)||(this.unload(this.state),this.observer.disconnect(),this.observer=null)}))),this.observer.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeOldValue:!0,attributeFilter:[o]}))):n.removeAttribute&&n.removeAttribute(o),n._component=this,!s&&i&&(i=r(i,this),this.options.transition&&document&&document.startViewTransition?document.startViewTransition((()=>e.render(n,i,this))):e.render(n,i,this)),this.rendered&&this.rendered(this.state)}setState(t,s={render:!0,history:!1}){const i=async t=>{try{for(;;){const{value:i,done:e}=await t.next();if(e)break;this.setState(i,s)}}catch(t){console.error("Error in async iterator:",t)}},e=t;if(null==e?void 0:e[Symbol.asyncIterator])this.setState(i(e[Symbol.asyncIterator]()),s);else if((null==e?void 0:e[Symbol.iterator])&&"function"==typeof e.next)for(const t of e)this.setState(t,s);else if(t&&t instanceof Promise)Promise.resolve(t).then((i=>{this.setState(i,s),this._state=t}));else{if(this._state=t,null==t)return;this.state=t,!1!==s.render&&(s.transition&&document&&document.startViewTransition?document.startViewTransition((()=>this.renderState(t))):this.renderState(t)),!1!==s.history&&this.enable_history&&(this._history=[...this._history,t],this._history_idx=this._history.length-1),"function"==typeof s.callback&&s.callback(this.state)}}constructor(s,i,e,n){this.state=s,this.view=i,this.update=e,this.options=n,this._app=new t,this._actions=[],this._global_events=[],this._history=[],this._history_idx=-1,this._history_prev=()=>{this._history_idx--,this._history_idx>=0?this.setState(this._history[this._history_idx],{render:!0,history:!1}):this._history_idx=0},this._history_next=()=>{this._history_idx++,this._history_idx<this._history.length?this.setState(this._history[this._history_idx],{render:!0,history:!1}):this._history_idx=this._history.length-1},this.start=(t=null,s)=>{if(this.mount(t,Object.assign({render:!0},s)),this.mounted&&"function"==typeof this.mounted){const t=this.mounted({},[],this.state);void 0!==t&&this.setState(t)}return this}}mount(t=null,s){var i,n;return console.assert(!this.element,"Component already mounted."),this.options=s=Object.assign(Object.assign({},this.options),s),this.element=t,this.global_event=s.global_event,this.enable_history=!!s.history,this.enable_history&&(this.on(s.history.prev||"history-prev",this._history_prev),this.on(s.history.next||"history-next",this._history_next)),s.route&&(this.update=this.update||{},this.update[s.route]||(this.update[s.route]=k)),this.add_actions(),this.state=null!==(n=null!==(i=this.state)&&void 0!==i?i:this.model)&&void 0!==n?n:{},"function"==typeof this.state&&(this.state=this.state()),this.setState(this.state,{render:!!s.render,history:!0}),e.debug&&(j.get(t)?j.get(t).push(this):j.set(t,[this])),this}is_global_event(t){return t&&(this.global_event||this._global_events.indexOf(t)>=0||t.startsWith("#")||t.startsWith("/")||t.startsWith("@"))}add_action(t,s,i={}){s&&"function"==typeof s&&(i.global&&this._global_events.push(t),this.on(t,((...n)=>{e.debug&&e.run("debug",{component:this,_:">",event:t,p:n,current_state:this.state,options:i});const o=s(this.state,...n);e.debug&&e.run("debug",{component:this,_:"<",event:t,p:n,newState:o,state:this.state,options:i}),this.setState(o,i)}),i))}add_actions(){const t=this.update||{};S.getMetadataKeys(this).forEach((s=>{if(s.startsWith("apprun-update:")){const i=S.getMetadata(s,this);t[i.name]=[this[i.key].bind(this),i.options]}}));const s={};Array.isArray(t)?t.forEach((t=>{const[i,e,n]=t;i.toString().split(",").forEach((t=>s[t.trim()]=[e,n]))})):Object.keys(t).forEach((i=>{const e=t[i];("function"==typeof e||Array.isArray(e))&&i.split(",").forEach((t=>s[t.trim()]=e))})),s["."]||(s["."]=k),Object.keys(s).forEach((t=>{const i=s[t];"function"==typeof i?this.add_action(t,i):Array.isArray(i)&&this.add_action(t,i[0],i[1])}))}run(t,...s){if(this.state instanceof Promise)return Promise.resolve(this.state).then((i=>{this.state=i,this.run(t,...s)}));{const i=t.toString();return this.is_global_event(i)?e.run(i,...s):this._app.run(i,...s)}}on(t,s,i){const n=t.toString();return this._actions.push({name:n,fn:s}),this.is_global_event(n)?e.on(n,s,i):this._app.on(n,s,i)}runAsync(t,...s){const i=t.toString();return this.is_global_event(i)?e.runAsync(i,...s):this._app.runAsync(i,...s)}query(t,...s){return this.runAsync(t,...s)}unmount(){var t;null===(t=this.observer)||void 0===t||t.disconnect(),this._actions.forEach((t=>{const{name:s,fn:i}=t;this.is_global_event(s)?e.off(s,i):this._app.off(s,i)}))}}E.i=!0;const M="//",C="///",x=t=>{if(e.lastUrl!==t)if(e.lastUrl=t,t||(t="#"),t.startsWith("#")){const[s,...i]=t.split("/");e.run(s,...i)||e.run(C,s,...i),e.run(M,s,...i)}else if(t.startsWith("/")){const[s,i,...n]=t.split("/");e.run("/"+i,...n)||e.run(C,"/"+i,...n),e.run(M,"/"+i,...n)}else e.run(t)||e.run(C,t),e.run(M,t)};if(!e.start){e.version="3.35.0",e.h=e.createElement=u,e.render=f,e.Fragment=h,e.webComponent=$,e.safeHTML=y,e.start=(t,s,i,e,n)=>{const o=Object.assign({render:!0,global_event:!0},n),r=new E(s,i,e);return n&&n.rendered&&(r.rendered=n.rendered),n&&n.mounted&&(r.mounted=n.mounted),r.start(t,o),r};const t=t=>{};e.on("debug",(s=>t)),e.on(M,t),e.on(C,t),e.route=x,e.on("route",(t=>e.route&&e.route(t))),"object"==typeof document&&document.addEventListener("DOMContentLoaded",(()=>{const t=document.body.hasAttribute("apprun-no-init")||e["no-init-route"]||!1,s=e.find("#")||e.find("#/")||!1;window.addEventListener("hashchange",(()=>x(location.hash))),window.addEventListener("popstate",(()=>x(location.pathname))),s?t&&x(location.hash):(t&&x(location.pathname),document.body.addEventListener("click",(t=>{const s=t.target,i="A"===s.tagName?s:s.closest("a");i&&i.origin===location.origin&&(t.preventDefault(),history.pushState(null,"",i.pathname),x(i.pathname))})))})),"object"==typeof window&&(window.Component=E,window._React=window.React,window.React=e,window.on=A,window.customElement=_,window.safeHTML=y),e.use_render=(t,s=0)=>{e.render=0===s?(s,i)=>t(i,s):(s,i)=>t(s,i)},e.use_react=(t,s)=>{e.h=e.createElement=t.createElement,e.Fragment=t.Fragment,e.render=(t,i)=>s.render(i,t),t.version&&t.version.startsWith("18")&&(e.render=(t,i)=>{t&&i&&(t._root||(t._root=s.createRoot(t)),t._root.render(i))})}}
2
2
  /**
3
3
  * @license
4
4
  * Copyright 2019 Google LLC