snice 2.1.2 → 2.1.4

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,15 +1,15 @@
1
1
  /*!
2
- * snice v2.1.1
2
+ * snice v2.1.3
3
3
  * Imperative TypeScript framework for building vanilla web components with decorators, routing, and controllers. No virtual DOM, no build complexity.
4
4
  * (c) 2024
5
5
  * Released under the MIT License.
6
6
  */
7
- var Snice=function(t){"use strict";const e=(globalThis.snice||(globalThis.snice={controllerRegistry:new Map,controllerIdCounter:0,symbols:new Map}),globalThis.snice);function n(t){return e.symbols.has(t)||e.symbols.set(t,Symbol(t)),e.symbols.get(t)}const o=n("is-controller-class"),r=n("is-controller-instance"),s=n("is-element-class"),i=n("channel-handlers"),a=n("ready-promise"),c=n("ready-resolve"),l=n("controller"),u=n("on-handlers"),h=n("controller-key"),d=n("controller-name"),p=n("controller-id"),f=n("controller-operations"),m=n("native-controller"),y=n("cleanup"),g=n("properties"),b=n("property-values"),w=n("properties-initialized"),v=n("property-watchers"),E=n("explicitly-set-properties"),S=n("router-context");n("current-page-marker");const T=n("context-request-handler"),A=n("page-transition"),O=n("created-at"),N=n("ready-handlers"),C=n("dispose-handlers"),P=n("observers"),I=n("parts"),L=n("part-timers");function x(t,e){const n=t.constructor.prototype[u];if(n){t[y]||(t[y]={events:[],channels:[]});for(const o of n){const n=o.method.bind(t),r=o.options||{},[s,i]=o.eventName.split(":"),a=t=>!i||"keydown"!==s&&"keyup"!==s&&"keypress"!==s?t:e=>{const n=e,o=t=>"Space"===t?" ":t;if(i.startsWith("~")){const r=o(i.slice(1));return void(n.key===r&&t(e))}if(i.includes("+")){const r=i.split("+"),s=o(r[r.length-1]),a=r.slice(0,-1);if(n.key!==s)return;const c=new Set(a.map(t=>t.toLowerCase())),l=c.has("ctrl"),u=c.has("shift"),h=c.has("alt"),d=c.has("meta")||c.has("cmd");n.ctrlKey===l&&n.shiftKey===u&&n.altKey===h&&n.metaKey===d&&t(e)}else{const r=o(i);n.key!==r||n.ctrlKey||n.shiftKey||n.altKey||n.metaKey||t(e)}},c=(t=>{if(r.debounce){let e;return function(...n){clearTimeout(e),e=setTimeout(()=>t.apply(this,n),r.debounce)}}if(r.throttle){let e,n=0;return function(...o){const s=Date.now(),i=r.throttle-(s-n);i<=0?(clearTimeout(e),n=s,t.apply(this,o)):e||(e=setTimeout(()=>{n=Date.now(),e=null,t.apply(this,o)},i))}}return t})(n),l=a(t=>{try{return r.preventDefault&&t.preventDefault(),r.stopPropagation&&t.stopPropagation(),c(t)}catch(t){console.error(`Error in event handler ${o.methodName}:`,t)}});if(o.selector){const n=e.shadowRoot||e,i=t=>{const e=t.target;let n=!1;if(e.matches&&e.matches(o.selector))n=!0;else if(e.closest){e.closest(o.selector)&&(n=!0)}n&&(r.preventDefault&&t.preventDefault(),r.stopPropagation&&(t.stopPropagation(),t.stopImmediatePropagation()),l(t))},a={capture:r.capture||!1,once:r.once||!1,passive:r.passive||!1};n.addEventListener(s,i,a),t[y].events.push(()=>{n.removeEventListener(s,i,a)})}else{const n={capture:r.capture||!1,once:r.once||!1,passive:r.passive||!1};e.addEventListener(s,l,n),t[y].events.push(()=>{e.removeEventListener(s,l,n)})}}}}function k(t){if(t[y]?.events){for(const e of t[y].events)e();t[y].events=[]}}const R=new Map,q=new WeakMap;function $(t,e){const n=t.constructor.prototype[P];if(n&&Array.isArray(n)&&0!==n.length){t[y]?t[y].observers||(t[y].observers=[]):t[y]={events:[],channels:[],observers:[]};for(const o of n){const n=o.method.bind(t),r=o.options?.throttle?F(n,o.options.throttle):n;switch(o.type){case"intersection":D(t,e,o,r);break;case"resize":M(t,e,o,r);break;case"media":j(t,e,o,r);break;case"mutation":z(t,e,o,r);break;default:console.warn(`Unknown observer type: ${o.type}`)}}}}function D(t,e,n,o){const r={threshold:n.options?.threshold??0,rootMargin:n.options?.rootMargin??"0px",root:n.options?.root??null},s=JSON.stringify(r),i=t=>{for(const e of t)try{!1===o(e)&&a&&a.unobserve(e.target)}catch(t){console.error(`Error in intersection observer ${n.methodName}:`,t)}};if("undefined"==typeof IntersectionObserver)return void console.warn("IntersectionObserver is not available in this environment");let a=q.get({instance:t,options:s});a||(a=new IntersectionObserver(i,r),q.set({instance:t,options:s},a));const c=n.selector?Array.from(e.shadowRoot?.querySelectorAll(n.selector)||[]):[e];c.forEach(t=>a.observe(t)),t[y].observers.push(()=>{c.forEach(t=>a.unobserve(t)),0===a.takeRecords().length&&a.disconnect()})}function M(t,e,n,o){const r=n.options?.box||"content-box";if("undefined"==typeof ResizeObserver)return void console.warn("ResizeObserver is not available in this environment");const s=new ResizeObserver(t=>{for(const e of t)try{o(e)}catch(t){console.error(`Error in resize observer ${n.methodName}:`,t)}});(n.selector?Array.from(e.shadowRoot?.querySelectorAll(n.selector)||[]):[e]).forEach(t=>{s.observe(t,{box:r})}),t[y].observers.push(()=>{s.disconnect()})}function j(t,e,n,o){const r=n.target;if(!r)return void console.warn("Media query observer requires a query string");let s=R.get(r);if(!s)try{s=window.matchMedia(r),R.set(r,s)}catch(t){return void console.error(`Invalid media query: ${r}`,t)}const i=t=>{try{o(t.matches)}catch(t){console.error(`Error in media query observer ${n.methodName}:`,t)}};i(s);const a=t=>i(t);s.addEventListener?(s.addEventListener("change",a),t[y].observers.push(()=>{s.removeEventListener("change",a)})):(s.addListener(a),t[y].observers.push(()=>{s.removeListener(a)}))}function z(t,e,n,o){const s=n.target.split(":"),i=s[0]||"childList",a=s[1],c={};switch(i){case"childList":c.childList=!0;break;case"attributes":c.attributes=!0,a&&(c.attributeFilter=[a]);break;default:return void console.warn(`Unknown mutation type: ${i}`)}n.options?.subtree&&(c.subtree=!0,n.options.maxDepth&&console.warn("maxDepth is set but requires custom implementation"));const l=new MutationObserver(t=>{try{if(n.options?.maxDepth&&n.options.subtree){const r=n.options.maxDepth,s=t.filter(t=>{let n=0,o=t.target;const s=e.shadowRoot||e;for(;o&&o!==s&&n<r;)o=o.parentNode,n++;return n<r});s.length>0&&o(s)}else o(t)}catch(t){console.error(`Error in mutation observer ${n.methodName}:`,t)}}),u=!0===t[r];(n.selector?Array.from(e.shadowRoot?.querySelectorAll(n.selector)||[]):u&&e.shadowRoot?[e.shadowRoot]:[e]).forEach(t=>{l.observe(t,c)}),t[y].observers.push(()=>{l.disconnect()})}function F(t,e){let n=0,o=null;return function(...r){const s=Date.now(),i=e-(s-n);if(i<=0)return o&&(clearTimeout(o),o=null),n=s,t.apply(this,r);o||(o=setTimeout(()=>{n=Date.now(),o=null,t.apply(this,r)},i))}}function U(t){if(t[y]?.observers){for(const e of t[y].observers)e();t[y].observers=[]}}function H(t,e){const n=t.constructor.prototype[i];if(n){t[y]||(t[y]={events:[],channels:[]});for(const o of n){const n=o.method.bind(t),r=`@request/${o.channelName}`;let s,i,a=0;const c=(t=>o.options?.debounce?(...e)=>new Promise((n,r)=>{clearTimeout(s),s=setTimeout(async()=>{try{const o=await t(...e);n(o)}catch(t){r(t)}},o.options.debounce)}):o.options?.throttle?(...e)=>{const n=Date.now(),r=o.options.throttle-(n-a);return r<=0?(clearTimeout(i),a=n,t(...e)):i?Promise.resolve(void 0):new Promise((n,o)=>{i=setTimeout(async()=>{a=Date.now(),i=null;try{const o=await t(...e);n(o)}catch(t){o(t)}},r)})}:t)(n),l=t=>{const{data:e,discovery:n,payload:r}=t.detail;t.preventDefault(),t.stopImmediatePropagation(),t.stopPropagation(),n.resolve(),Promise.resolve(c(r)).then(t=>{e.resolve(t)}).catch(t=>{e.reject(t),console.error(`Error in response handler ${o.methodName}:`,t)})};e.addEventListener(r,l),t[y].channels.push(()=>{e.removeEventListener(r,l)})}}}function B(t){if(t[y]?.channels){for(const e of t[y].channels)e();t[y].channels=[]}}class G{constructor(){this.cleanupFns=new Map,this.pendingOperations=new Set}register(t,e){this.cleanupFns.set(t,e)}unregister(t){this.cleanupFns.delete(t)}async cleanup(){await Promise.all(this.pendingOperations);for(const t of this.cleanupFns.values())try{await t()}catch(t){console.error("Error during cleanup:",t)}this.cleanupFns.clear()}async runOperation(t){const e=t(),n=e.then(()=>{},()=>{});this.pendingOperations.add(n);try{const t=await e;return this.pendingOperations.delete(n),t}catch(t){throw this.pendingOperations.delete(n),t}}}async function K(t,n){const o=t[h],s=t[d],i=t[m];if(void 0!==i&&i!==n)return;if(s===n&&o)return;o&&await W(t);const a=e.controllerRegistry.get(n);if(!a)throw new Error(`Controller "${n}" not found in registry`);const c=new a;e.controllerIdCounter+=1;const l=e.controllerIdCounter,u=new G;c[r]=!0,c[p]=l,c.element=t;const y=t[S];void 0!==y&&(c[S]=y),t[h]=c,t[d]=n,t[f]=u,await t.ready,await u.runOperation(async()=>{await c.attach(t)}),x(c,t),$(c,t),H(c,t),t.dispatchEvent(new CustomEvent("@snice/controller-attached",{detail:{name:n,controller:c}}))}async function W(t){const e=t[h],n=t[d],o=t[f];e&&(o?await o.runOperation(async()=>{await e.detach(t)}):await e.detach(t),e.element=null,k(e),U(e),B(e),o&&await o.cleanup(),delete e[S],delete t[h],delete t[d],delete t[f],t.dispatchEvent(new CustomEvent("@snice/controller-detached",{detail:{name:n,controller:e}})))}function _(t){t.prototype[s]=!0;const e=t.prototype.connectedCallback,n=t.prototype.disconnectedCallback,o=t.prototype.attributeChangedCallback,r=t.observedAttributes||[];r.includes("controller")||r.push("controller");const i=t[g];if(i)for(const[t,e]of i){const n="string"==typeof e.attribute?e.attribute:t.toLowerCase();r.includes(n)||r.push(n)}Object.defineProperty(t,"observedAttributes",{get:()=>r,configurable:!0}),Object.defineProperty(t.prototype,"ready",{get(){return this[a]||(this[a]=new Promise(t=>{this[c]=t})),this[a]},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"controller",{get(){return this[l]},set(t){const e=this[l];this[l]=t,t!==e&&t?K(this,t).catch(e=>{console.error(`Failed to attach controller "${t}":`,e)}):!t&&e&&W(this).catch(t=>{console.error("Failed to detach controller:",t)})},enumerable:!0,configurable:!0}),t.prototype.connectedCallback=async function(){this[a]||(this[a]=new Promise(t=>{this[c]=t}));try{const n=t[g];if(n)for(const[t,e]of n)if(this.hasAttribute(t)){const n=this.getAttribute(t);switch(this[E]||(this[E]=new Set),this[E].add(t),e.type){case Boolean:this[t]=null!==n&&"false"!==n;break;case Number:this[t]=Number(n);break;case String:this[t]=n;break;case Date:this[t]=n?new Date(n):null;break;case BigInt:n&&n.endsWith("n")?this[t]=BigInt(n.slice(0,-1)):this[t]=n?BigInt(n):null;break;case Q:this[t]=Q.parse(n);break;default:this[t]=n}}if(this[w]=!0,n)for(const[t,e]of n){const n=this[E]&&this[E].has(t),o=t in this[b];if(e.reflect&&o&&(n||void 0!==this[b][t])){const n=this[b][t],o="string"==typeof e.attribute?e.attribute:t.toLowerCase();if(null!=n&&!1!==n&&(e.type!==Q||!Array.isArray(n)||0!==n.length)){let t;t=n instanceof Date?n.toISOString():"bigint"==typeof n?n.toString()+"n":e.type===Q&&Array.isArray(n)?Q.serialize(n):String(n),this.setAttribute(o,t)}}}k(this),this.shadowRoot||this.attachShadow({mode:"open"});let o="";if(this.html)try{const t=this.html(),e=t instanceof Promise?await t:t;void 0!==e&&(o+=e)}catch(t){console.error(`Error in html() method for ${this.tagName}:`,t)}if(this.css)try{const t=this.css(),e=t instanceof Promise?await t:t;if(e){o+=`<style data-component-css>${Array.isArray(e)?e.join("\n"):e}</style>`}}catch(t){console.error(`Error in css() method for ${this.tagName}:`,t)}o&&(this.shadowRoot.innerHTML=o);const r=t[I];if(r&&this.shadowRoot)for(const[t,e]of r)try{const n=this.shadowRoot.querySelector(`[part="${t}"]`);if(n){const t=e.method.call(this),o=t instanceof Promise?await t:t;void 0!==o&&(n.innerHTML=o)}}catch(e){console.error(`Error rendering @part('${t}') in ${this.tagName}:`,e)}e&&e.call(this);const s=this.getAttribute("controller");s&&(this.controller=s),x(this,this),H(this,this);try{$(this,this)}catch(t){console.error(`Error setting up observers for ${this.tagName}:`,t)}const i=t[N];if(i)for(const t of i)try{await t.method.call(this)}catch(e){console.error(`Error in @ready handler ${t.methodName}:`,e)}}finally{this[c]&&(this[c](),this[c]=null)}},t.prototype.disconnectedCallback=async function(){const e=t[C];if(e)for(const t of e)try{await t.method.call(this)}catch(e){console.error(`Error in @dispose handler ${t.methodName}:`,e)}n&&n.call(this),this[l]&&W(this).catch(t=>{console.error("Failed to detach controller:",t)}),k(this),B(this),U(this)},t.prototype.attributeChangedCallback=function(e,n,r){if(o?.call(this,e,n,r),"controller"===e)this.controller=r;else{const n=t[g];if(n)for(const[o,s]of n){if(("string"==typeof s.attribute?s.attribute:o.toLowerCase())===e){const e=this[b]?.[o];let n;if(n=s.type===Boolean?null!==r&&"false"!==r:s.type===Number?Number(r):s.type===Date?r?new Date(r):null:s.type===BigInt?r&&r.endsWith("n")?BigInt(r.slice(0,-1)):r?BigInt(r):null:s.type===Q?Q.parse(r):"number"==typeof e&&null!==r?Number(r):r,e!==n){this[E]||(this[E]=new Set),this[E].add(o),this[b]||(this[b]={}),this[b][o]=n;const r=t[v];if(r){if(r.has(o)){const t=r.get(o);for(const r of t)try{r.method.call(this,e,n,o)}catch(t){console.error(`Error in @watch('${o}') method ${r.methodName}:`,t)}}if(r.has("*")){const t=r.get("*");for(const r of t)try{r.method.call(this,e,n,o)}catch(t){console.error(`Error in @watch('*') method ${r.methodName}:`,t)}}}}break}}}}}class Q{static{this.SEPARATOR=","}static serialize(t){return Array.isArray(t)?t.map(t=>{if("string"==typeof t){if(t.includes(Q.SEPARATOR))throw new Error(`SimpleArray strings cannot contain the character "${Q.SEPARATOR}" (U+FF0C)`);return t}if("number"==typeof t||"boolean"==typeof t)return String(t);throw new Error("SimpleArray only supports string, number, and boolean types. Got: "+typeof t)}).join(Q.SEPARATOR):""}static parse(t){return null==t||""===t?[]:t.split(Q.SEPARATOR).map(t=>{if(/^-?\d+\.?\d*$/.test(t)){const e=Number(t);if(!isNaN(e))return e}return"true"===t||"false"!==t&&t})}}
7
+ var Snice=function(t){"use strict";const e=(globalThis.snice||(globalThis.snice={controllerRegistry:new Map,controllerIdCounter:0,symbols:new Map}),globalThis.snice);function n(t){return e.symbols.has(t)||e.symbols.set(t,Symbol(t)),e.symbols.get(t)}const o=n("is-controller-class"),r=n("is-controller-instance"),s=n("is-element-class"),i=n("channel-handlers"),a=n("ready-promise"),c=n("ready-resolve"),l=n("controller"),u=n("on-handlers"),h=n("controller-key"),d=n("controller-name"),p=n("controller-id"),f=n("controller-operations"),m=n("native-controller"),y=n("cleanup"),g=n("properties"),b=n("property-values"),w=n("properties-initialized"),v=n("property-watchers"),E=n("explicitly-set-properties"),S=n("router-context");n("current-page-marker");const A=n("context-request-handler"),T=n("page-transition"),O=n("created-at"),N=n("ready-handlers"),C=n("dispose-handlers"),L=n("observers"),P=n("parts"),I=n("part-timers"),x=n("dispatch-timers");function k(t,e){const n=t.constructor.prototype[u];if(n){t[y]||(t[y]={events:[],channels:[]});for(const o of n){const n=t[o.method.name],r=n?n.bind(t):o.method.bind(t),s=o.options||{},[i,a]=o.eventName.split(":"),c=t=>!a||"keydown"!==i&&"keyup"!==i&&"keypress"!==i?t:e=>{const n=e,o=t=>"Space"===t?" ":t;if(a.startsWith("~")){const r=o(a.slice(1));return void(n.key===r&&t(e))}if(a.includes("+")){const r=a.split("+"),s=o(r[r.length-1]),i=r.slice(0,-1);if(n.key!==s)return;const c=new Set(i.map(t=>t.toLowerCase())),l=c.has("ctrl"),u=c.has("shift"),h=c.has("alt"),d=c.has("meta")||c.has("cmd");n.ctrlKey===l&&n.shiftKey===u&&n.altKey===h&&n.metaKey===d&&t(e)}else{const r=o(a);n.key!==r||n.ctrlKey||n.shiftKey||n.altKey||n.metaKey||t(e)}},l=(t=>{if(s.debounce){let e;return function(...n){clearTimeout(e),e=setTimeout(()=>t.apply(this,n),s.debounce)}}if(s.throttle){let e,n=0;return function(...o){const r=Date.now(),i=s.throttle-(r-n);i<=0?(clearTimeout(e),n=r,t.apply(this,o)):e||(e=setTimeout(()=>{n=Date.now(),e=null,t.apply(this,o)},i))}}return t})(r),u=c(t=>{try{return s.preventDefault&&t.preventDefault(),s.stopPropagation&&t.stopPropagation(),l(t)}catch(t){console.error(`Error in event handler ${o.methodName}:`,t)}});if(o.selector){const n=e.shadowRoot||e,r=t=>{const e=t.target;let n=!1;if(e.matches&&e.matches(o.selector))n=!0;else if(e.closest){e.closest(o.selector)&&(n=!0)}n&&(s.preventDefault&&t.preventDefault(),s.stopPropagation&&(t.stopPropagation(),t.stopImmediatePropagation()),u(t))},a={capture:s.capture||!1,once:s.once||!1,passive:s.passive||!1};n.addEventListener(i,r,a),t[y].events.push(()=>{n.removeEventListener(i,r,a)})}else{const n={capture:s.capture||!1,once:s.once||!1,passive:s.passive||!1};e.addEventListener(i,u,n),t[y].events.push(()=>{e.removeEventListener(i,u,n)})}}}}function R(t){if(t[y]?.events){for(const e of t[y].events)e();t[y].events=[]}}const q=new Map,$=new WeakMap;function D(t,e){const n=t.constructor.prototype[L];if(n&&Array.isArray(n)&&0!==n.length){t[y]?t[y].observers||(t[y].observers=[]):t[y]={events:[],channels:[],observers:[]};for(const o of n){const n=o.method.bind(t),r=o.options?.throttle?U(n,o.options.throttle):n;switch(o.type){case"intersection":M(t,e,o,r);break;case"resize":j(t,e,o,r);break;case"media":z(t,e,o,r);break;case"mutation":F(t,e,o,r);break;default:console.warn(`Unknown observer type: ${o.type}`)}}}}function M(t,e,n,o){const r={threshold:n.options?.threshold??0,rootMargin:n.options?.rootMargin??"0px",root:n.options?.root??null},s=JSON.stringify(r),i=t=>{for(const e of t)try{!1===o(e)&&a&&a.unobserve(e.target)}catch(t){console.error(`Error in intersection observer ${n.methodName}:`,t)}};if("undefined"==typeof IntersectionObserver)return void console.warn("IntersectionObserver is not available in this environment");let a=$.get({instance:t,options:s});a||(a=new IntersectionObserver(i,r),$.set({instance:t,options:s},a));const c=n.selector?Array.from(e.shadowRoot?.querySelectorAll(n.selector)||[]):[e];c.forEach(t=>a.observe(t)),t[y].observers.push(()=>{c.forEach(t=>a.unobserve(t)),0===a.takeRecords().length&&a.disconnect()})}function j(t,e,n,o){const r=n.options?.box||"content-box";if("undefined"==typeof ResizeObserver)return void console.warn("ResizeObserver is not available in this environment");const s=new ResizeObserver(t=>{for(const e of t)try{o(e)}catch(t){console.error(`Error in resize observer ${n.methodName}:`,t)}});(n.selector?Array.from(e.shadowRoot?.querySelectorAll(n.selector)||[]):[e]).forEach(t=>{s.observe(t,{box:r})}),t[y].observers.push(()=>{s.disconnect()})}function z(t,e,n,o){const r=n.target;if(!r)return void console.warn("Media query observer requires a query string");let s=q.get(r);if(!s)try{s=window.matchMedia(r),q.set(r,s)}catch(t){return void console.error(`Invalid media query: ${r}`,t)}const i=t=>{try{o(t.matches)}catch(t){console.error(`Error in media query observer ${n.methodName}:`,t)}};i(s);const a=t=>i(t);s.addEventListener?(s.addEventListener("change",a),t[y].observers.push(()=>{s.removeEventListener("change",a)})):(s.addListener(a),t[y].observers.push(()=>{s.removeListener(a)}))}function F(t,e,n,o){const s=n.target.split(":"),i=s[0]||"childList",a=s[1],c={};switch(i){case"childList":c.childList=!0;break;case"attributes":c.attributes=!0,a&&(c.attributeFilter=[a]);break;default:return void console.warn(`Unknown mutation type: ${i}`)}n.options?.subtree&&(c.subtree=!0,n.options.maxDepth&&console.warn("maxDepth is set but requires custom implementation"));const l=new MutationObserver(t=>{try{if(n.options?.maxDepth&&n.options.subtree){const r=n.options.maxDepth,s=t.filter(t=>{let n=0,o=t.target;const s=e.shadowRoot||e;for(;o&&o!==s&&n<r;)o=o.parentNode,n++;return n<r});s.length>0&&o(s)}else o(t)}catch(t){console.error(`Error in mutation observer ${n.methodName}:`,t)}}),u=!0===t[r];(n.selector?Array.from(e.shadowRoot?.querySelectorAll(n.selector)||[]):u&&e.shadowRoot?[e.shadowRoot]:[e]).forEach(t=>{l.observe(t,c)}),t[y].observers.push(()=>{l.disconnect()})}function U(t,e){let n=0,o=null;return function(...r){const s=Date.now(),i=e-(s-n);if(i<=0)return o&&(clearTimeout(o),o=null),n=s,t.apply(this,r);o||(o=setTimeout(()=>{n=Date.now(),o=null,t.apply(this,r)},i))}}function H(t){if(t[y]?.observers){for(const e of t[y].observers)e();t[y].observers=[]}}function B(t,e){const n=t.constructor.prototype[i];if(n){t[y]||(t[y]={events:[],channels:[]});for(const o of n){const n=o.method.bind(t),r=`@request/${o.channelName}`;let s,i,a=0;const c=(t=>o.options?.debounce?(...e)=>new Promise((n,r)=>{clearTimeout(s),s=setTimeout(async()=>{try{const o=await t(...e);n(o)}catch(t){r(t)}},o.options.debounce)}):o.options?.throttle?(...e)=>{const n=Date.now(),r=o.options.throttle-(n-a);return r<=0?(clearTimeout(i),a=n,t(...e)):i?Promise.resolve(void 0):new Promise((n,o)=>{i=setTimeout(async()=>{a=Date.now(),i=null;try{const o=await t(...e);n(o)}catch(t){o(t)}},r)})}:t)(n),l=t=>{const{data:e,discovery:n,payload:r}=t.detail;t.preventDefault(),t.stopImmediatePropagation(),t.stopPropagation(),n.resolve(),Promise.resolve(c(r)).then(t=>{e.resolve(t)}).catch(t=>{e.reject(t),console.error(`Error in response handler ${o.methodName}:`,t)})};e.addEventListener(r,l),t[y].channels.push(()=>{e.removeEventListener(r,l)})}}}function G(t){if(t[y]?.channels){for(const e of t[y].channels)e();t[y].channels=[]}}class K{constructor(){this.cleanupFns=new Map,this.pendingOperations=new Set}register(t,e){this.cleanupFns.set(t,e)}unregister(t){this.cleanupFns.delete(t)}async cleanup(){await Promise.all(this.pendingOperations);for(const t of this.cleanupFns.values())try{await t()}catch(t){console.error("Error during cleanup:",t)}this.cleanupFns.clear()}async runOperation(t){const e=t(),n=e.then(()=>{},()=>{});this.pendingOperations.add(n);try{const t=await e;return this.pendingOperations.delete(n),t}catch(t){throw this.pendingOperations.delete(n),t}}}async function W(t,n){const o=t[h],s=t[d],i=t[m];if(void 0!==i&&i!==n)return;if(s===n&&o)return;o&&await _(t);const a=e.controllerRegistry.get(n);if(!a)throw new Error(`Controller "${n}" not found in registry`);const c=new a;e.controllerIdCounter+=1;const l=e.controllerIdCounter,u=new K;c[r]=!0,c[p]=l,c.element=t;const y=t[S];void 0!==y&&(c[S]=y),t[h]=c,t[d]=n,t[f]=u,await t.ready,await u.runOperation(async()=>{await c.attach(t)}),k(c,t),D(c,t),B(c,t),t.dispatchEvent(new CustomEvent("@snice/controller-attached",{detail:{name:n,controller:c}}))}async function _(t){const e=t[h],n=t[d],o=t[f];e&&(o?await o.runOperation(async()=>{await e.detach(t)}):await e.detach(t),e.element=null,R(e),H(e),G(e),o&&await o.cleanup(),delete e[S],delete t[h],delete t[d],delete t[f],t.dispatchEvent(new CustomEvent("@snice/controller-detached",{detail:{name:n,controller:e}})))}function Q(t){t.prototype[s]=!0;const e=t.prototype.connectedCallback,n=t.prototype.disconnectedCallback,o=t.prototype.attributeChangedCallback,r=t.observedAttributes||[];r.includes("controller")||r.push("controller");const i=t[g];if(i)for(const[t,e]of i){const n="string"==typeof e.attribute?e.attribute:t.toLowerCase();r.includes(n)||r.push(n)}Object.defineProperty(t,"observedAttributes",{get:()=>r,configurable:!0}),Object.defineProperty(t.prototype,"ready",{get(){return this[a]||(this[a]=new Promise(t=>{this[c]=t})),this[a]},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"controller",{get(){return this[l]},set(t){const e=this[l];this[l]=t,t!==e&&t?W(this,t).catch(e=>{console.error(`Failed to attach controller "${t}":`,e)}):!t&&e&&_(this).catch(t=>{console.error("Failed to detach controller:",t)})},enumerable:!0,configurable:!0}),t.prototype.connectedCallback=async function(){this[a]||(this[a]=new Promise(t=>{this[c]=t}));try{const n=t[g];if(n)for(const[t,e]of n)if(this.hasAttribute(t)){const n=this.getAttribute(t);switch(this[E]||(this[E]=new Set),this[E].add(t),e.type){case Boolean:this[t]=null!==n&&"false"!==n;break;case Number:this[t]=Number(n);break;case String:this[t]=n;break;case Date:this[t]=n?new Date(n):null;break;case BigInt:n&&n.endsWith("n")?this[t]=BigInt(n.slice(0,-1)):this[t]=n?BigInt(n):null;break;case J:this[t]=J.parse(n);break;default:this[t]=n}}if(this[w]=!0,n)for(const[t,e]of n){const n=this[E]&&this[E].has(t),o=t in this[b];if(e.reflect&&o&&(n||void 0!==this[b][t])){const n=this[b][t],o="string"==typeof e.attribute?e.attribute:t.toLowerCase();if(null!=n&&!1!==n&&(e.type!==J||!Array.isArray(n)||0!==n.length)){let t;t=n instanceof Date?n.toISOString():"bigint"==typeof n?n.toString()+"n":e.type===J&&Array.isArray(n)?J.serialize(n):String(n),this.setAttribute(o,t)}}}R(this),this.shadowRoot||this.attachShadow({mode:"open"});let o="";if(this.html)try{const t=this.html(),e=t instanceof Promise?await t:t;void 0!==e&&(o+=e)}catch(t){console.error(`Error in html() method for ${this.tagName}:`,t)}if(this.css)try{const t=this.css(),e=t instanceof Promise?await t:t;if(e){o+=`<style data-component-css>${Array.isArray(e)?e.join("\n"):e}</style>`}}catch(t){console.error(`Error in css() method for ${this.tagName}:`,t)}o&&(this.shadowRoot.innerHTML=o);const r=t[P];if(r&&this.shadowRoot)for(const[t,e]of r)try{const n=this.shadowRoot.querySelector(`[part="${t}"]`);if(n){const t=e.method.call(this),o=t instanceof Promise?await t:t;void 0!==o&&(n.innerHTML=o)}}catch(e){console.error(`Error rendering @part('${t}') in ${this.tagName}:`,e)}e&&e.call(this);const s=this.getAttribute("controller");s&&(this.controller=s),k(this,this),B(this,this);try{D(this,this)}catch(t){console.error(`Error setting up observers for ${this.tagName}:`,t)}const i=t[N];if(i)for(const t of i)try{await t.method.call(this)}catch(e){console.error(`Error in @ready handler ${t.methodName}:`,e)}}finally{this[c]&&(this[c](),this[c]=null)}},t.prototype.disconnectedCallback=async function(){const e=t[C];if(e)for(const t of e)try{await t.method.call(this)}catch(e){console.error(`Error in @dispose handler ${t.methodName}:`,e)}n&&n.call(this),this[l]&&_(this).catch(t=>{console.error("Failed to detach controller:",t)}),R(this),G(this),H(this)},t.prototype.attributeChangedCallback=function(e,n,r){if(o?.call(this,e,n,r),"controller"===e)this.controller=r;else{const n=t[g];if(n)for(const[o,s]of n){if(("string"==typeof s.attribute?s.attribute:o.toLowerCase())===e){const e=this[b]?.[o];let n;if(n=s.type===Boolean?null!==r&&"false"!==r:s.type===Number?Number(r):s.type===Date?r?new Date(r):null:s.type===BigInt?r&&r.endsWith("n")?BigInt(r.slice(0,-1)):r?BigInt(r):null:s.type===J?J.parse(r):"number"==typeof e&&null!==r?Number(r):r,e!==n){this[E]||(this[E]=new Set),this[E].add(o),this[b]||(this[b]={}),this[b][o]=n;const r=t[v];if(r){if(r.has(o)){const t=r.get(o);for(const r of t)try{r.method.call(this,e,n,o)}catch(t){console.error(`Error in @watch('${o}') method ${r.methodName}:`,t)}}if(r.has("*")){const t=r.get("*");for(const r of t)try{r.method.call(this,e,n,o)}catch(t){console.error(`Error in @watch('*') method ${r.methodName}:`,t)}}}}break}}}}}class J{static{this.SEPARATOR=","}static serialize(t){return Array.isArray(t)?t.map(t=>{if("string"==typeof t){if(t.includes(J.SEPARATOR))throw new Error(`SimpleArray strings cannot contain the character "${J.SEPARATOR}" (U+FF0C)`);return t}if("number"==typeof t||"boolean"==typeof t)return String(t);throw new Error("SimpleArray only supports string, number, and boolean types. Got: "+typeof t)}).join(J.SEPARATOR):""}static parse(t){return null==t||""===t?[]:t.split(J.SEPARATOR).map(t=>{if(/^-?\d+\.?\d*$/.test(t)){const e=Number(t);if(!isNaN(e))return e}return"true"===t||"false"!==t&&t})}}
8
8
  /*!
9
9
  * pica-route v1.1.2
10
10
  * A pure URL pattern matching library compatible with route-parser API
11
11
  * (c) 2024
12
12
  * Released under the MIT License.
13
13
  */
14
- class J{constructor(t){this.parsed=this.parsePattern(t)}get spec(){return this.parsed.template}parsePattern(t){let e=t,n="",o=!1;const r=t.indexOf("?");return-1!==r&&(e=t.slice(0,r),n=t.slice(r+1),e.endsWith("(")&&n.endsWith(")")&&(o=!0,e=e.slice(0,-1),n=n.slice(0,-1))),{pathSegments:this.parseSegments(e),querySegments:n?this.parseQuerySegments(n):[],queryOptional:o,template:t}}parseSegments(t){const e=[];let n=0;for(;n<t.length;){switch(t[n]){case"(":const{segments:o,endIndex:r}=this.parseOptionalGroup(t,n);e.push({type:"optional",segments:o}),n=r+1;break;case":":const{name:s,endIndex:i}=this.parseIdentifier(t,n+1);e.push({type:"param",name:s}),n=i;break;case"*":const{name:a,endIndex:c}=this.parseIdentifier(t,n+1);e.push({type:"splat",name:a}),n=c;break;default:const{value:l,endIndex:u}=this.parseLiteral(t,n);l&&e.push({type:"literal",value:l}),n=u}}return e}parseOptionalGroup(t,e){let n=1,o=e+1;for(;o<t.length&&n>0;)"("===t[o]&&n++,")"===t[o]&&n--,o++;const r=t.slice(e+1,o-1);return{segments:this.parseSegments(r),endIndex:o-1}}parseIdentifier(t,e){let n=e;for(;n<t.length&&/[\w-]/.test(t[n]);)n++;return{name:t.slice(e,n),endIndex:n}}parseLiteral(t,e){let n=e;for(;n<t.length&&!"(:*(".includes(t[n]);)n++;return{value:t.slice(e,n),endIndex:n}}parseQuerySegments(t){let e=t;e.startsWith("(")&&e.endsWith(")")&&(e=e.slice(1,-1));const n=[];let o=0;for(;o<e.length;)if(":"===e[o]){const{name:t,endIndex:r}=this.parseIdentifier(e,o+1);n.push({type:"param",name:t}),o=r}else{const{value:t,endIndex:r}=this.parseQueryLiteral(e,o);t&&n.push({type:"literal",value:t}),o=r}return n}parseQueryLiteral(t,e){let n=e;for(;n<t.length&&":"!==t[n];)n++;return{value:t.slice(e,n),endIndex:n}}getAllParamNames(){const t=new Set,e=n=>{for(const o of n)switch(o.type){case"param":case"splat":t.add(o.name);break;case"optional":e(o.segments)}};return e(this.parsed.pathSegments),e(this.parsed.querySegments),Array.from(t)}canMatchRemainingSegments(t,e,n){let o=e;for(const e of n)if("literal"===e.type){const n=t.indexOf(e.value,o);if(-1===n)return!1;o=n+e.value.length}return!0}match(t){const[e,n]=t.split("?"),o=this.matchPath(e,this.parsed.pathSegments);if(!1===o)return!1;const r=this.matchQuery(n||"",this.parsed.querySegments);if(!1===r)return!1;const s=this.getAllParamNames(),i={};for(const t of s)i[t]=void 0;return Object.assign(i,o,r),i}matchPath(t,e){const n={};let o=0;for(let r=0;r<e.length;r++){const s=e[r],i=e.slice(r+1),a=this.matchSegment(t,o,s,i);if(!1===a)return!1;Object.assign(n,a.params),o=a.nextIndex}return!(o<t.length)&&n}matchSegment(t,e,n,o=[]){switch(n.type){case"literal":return t.slice(e,e+n.value.length)===n.value&&{params:{},nextIndex:e+n.value.length};case"param":{let r=e;const s=o[0];let i,a=["/","?"];if(s&&"literal"===s.type){const n=s.value,o=t.indexOf(n,e);if(-1===o)return!1;r=o}else for(;r<t.length&&!a.includes(t[r]);)r++;if(r===e)return!1;try{i=decodeURIComponent(t.slice(e,r))}catch(n){i=t.slice(e,r)}return!(r<t.length&&"?"===t[r]&&o.length>0)&&{params:{[n.name]:i},nextIndex:r}}case"splat":{let r=t.length;const s=o[0];if(s)switch(s.type){case"literal":if("."===s.value){const n=t.indexOf(".",e);-1!==n&&(r=n)}else{const n=t.lastIndexOf(s.value);-1!==n&&n>=e&&(r=n)}break;case"param":let n=-1;for(let o=t.length-1;o>=e;o--)if("/"===t[o]){n=o;break}-1!==n&&(r=n);break;case"splat":let o=-1;for(let n=t.length-1;n>e;n--)if("/"===t[n]){o=n+1;break}if(-1!==o)r=o;else{const n=t.slice(e).split("/").filter(t=>t);r=n.length>1?e+n.slice(0,-1).join("/").length+1:e}break;case"optional":const i=t=>{for(const e of t){if("literal"===e.type)return e.value;if("optional"===e.type){const t=i(e.segments);if(t)return t}}return null},a=i(s.segments);if(a){const n=t.lastIndexOf(a);-1!==n&&n>=e&&(r=n)}}const i=t.indexOf("?",e);let a;-1!==i&&i<r&&(r=i);try{a=decodeURIComponent(t.slice(e,r))}catch(n){a=t.slice(e,r)}return{params:{[n.name]:a},nextIndex:r}}case"optional":{let r=e,s={},i=!0;for(let e=0;e<n.segments.length;e++){const o=n.segments[e],a=n.segments.slice(e+1),c=this.matchSegment(t,r,o,a);if(!1===c){i=!1;break}Object.assign(s,c.params),r=c.nextIndex}if(i){if(this.canMatchRemainingSegments(t,r,o))return{params:s,nextIndex:r}}return{params:{},nextIndex:e}}default:return!1}}findNextLiteral(t){for(const e of t){if("literal"===e.type)return e;if("optional"===e.type){const t=this.findNextLiteral(e.segments);if(t)return t}}return null}matchQuery(t,e){if(0===e.length)return{};const n={};let o=0;for(const r of e)switch(r.type){case"literal":if(t.slice(o,o+r.value.length)!==r.value)return!1;o+=r.value.length;break;case"param":{let e,s=o;for(;s<t.length&&"&"!==t[s];)s++;if(s===o)return!1;try{e=decodeURIComponent(t.slice(o,s))}catch(n){e=t.slice(o,s)}n[r.name]=e,o=s;break}}return n}reverse(t={}){const e=this.reverseSegments(this.parsed.pathSegments,t);if(!1===e)return!1;let n=e;if(this.parsed.querySegments.length>0){const e=this.reverseSegments(this.parsed.querySegments,t);if(!this.parsed.queryOptional&&!1===e)return!1;e&&""!==e&&(n+="?"+e)}return n}reverseSegments(t,e,n=!1){let o="";for(let r=0;r<t.length;r++){const s=t[r],i=t.slice(r+1);switch(s.type){case"literal":o+=s.value;break;case"param":case"splat":if(!(s.name in e))return!1;o+=String(e[s.name]);break;case"optional":if(this.hasAllParams(s.segments,e,n)||this.hasLaterOptionalGroupNeedingParams(i,e,s.segments)){const t=this.reverseSegments(s.segments,e,!0);if(!1===t)return!1;o+=t}}}return o}hasLaterOptionalGroupNeedingParams(t,e,n){for(const o of t)if("optional"===o.type&&this.hasAnyParamInSegments(o.segments,e))return this.hasOnlyLiteralsAndOptionals(n);return!1}hasOnlyLiteralsAndOptionals(t){for(const e of t)if("param"===e.type||"splat"===e.type)return!1;return!0}hasAllParams(t,e,n=!1){let o=!1,r=!1,s=!1,i=!0;for(const n of t)switch(n.type){case"param":case"splat":i=!1,n.name in e&&void 0!==e[n.name]?o=!0:s=!0}const a=n||o&&!s;for(const n of t)if("optional"===n.type){this.hasAllParams(n.segments,e,a)&&(r=!0)}return!(!o||s)||(!(!r||s)||!(!i||!n))}hasOnlyOptionalMissingParams(t,e){for(const n of t)switch(n.type){case"param":case"splat":if(!(n.name in e))return!1}return!0}hasAnyParamInSegments(t,e){for(const n of t)switch(n.type){case"param":case"splat":if(n.name in e)return!0;break;case"optional":if(this.hasAnyParamInSegments(n.segments,e))return!0}return!1}}function V(t){const e={};return t.split(";").forEach(t=>{const[n,o]=t.split(":").map(t=>t.trim());n&&o&&(e[n]=o)}),e}var X;return function(t){t.SUCCESS="success",t.GUARDS_FAILED="guards-failed",t.NOT_FOUND="not-found"}(X||(X={})),t.IS_CONTROLLER_INSTANCE=r,t.Router=function(t){const e=[];let n,o,r,s=!1,i=null,a=null;const c=t.context||{};function l(t){if(!i||!a)return null;const e=t.querySelectorAll(i);for(const t of e){if(t[O]===a)return t}return null}function u(t,i,a,c,l){e.push({route:new J(t),tag:i,transition:a,guards:c,layout:l}),s=!1,"/404"===t&&(n=i),"/403"===t&&(o=i),"/"===t&&(r=i)}function h(){switch(t.type){case"hash":return window.location.hash.slice(1);case"pushstate":return window.location.pathname}}async function d(t){let e;const n=!!o;if(n&&(e=document.createElement(o),e[S]=c),!n){const t=document.createElement("div");t.className="default-403",t.innerHTML="<h1>403</h1><p>Unauthorized</p>",e=t}t.innerHTML="",t.appendChild(e),i=null,a=null}async function p(t,e,n){if(!!!t)return!0;const o=Array.isArray(t)?t:[t];for(const t of o){if(!await t(c,e))return await d(n),!1}return!0}function f(e){if(!1===e)return null;if(!!e)return e;return!!t.layout?t.layout:null}function m(t){if(!(t!==i))return{element:null,needsNewLayout:!1};i=t;if(!!t){const e=Date.now();a=e;const n=document.createElement(t);return n[S]=c,n[O]=e,{element:n,needsNewLayout:!0}}return a=null,{element:null,needsNewLayout:!0}}async function y(t,e,n,o,r){const s=o||l(t);if(!s)return;const i=s.querySelector('[slot="page"]');if(!(!n||!i))return e.setAttribute("slot","page"),await v(s,i,e,n),void(r&&(t.innerHTML="",t.appendChild(s)));s.querySelectorAll('[slot="page"]').forEach(t=>t.remove()),e.setAttribute("slot","page"),s.appendChild(e),r&&(t.innerHTML="",t.appendChild(s))}async function b(t,e,n){const o=t.children[0];!n||!o?(t.innerHTML="",t.appendChild(e)):await v(t,o,e,n)}async function w(o){const s=document.querySelector(t.target);if(!s)throw new Error(`Target element not found: ${t.target}`);window.scrollTo(0,0);if((""===o.trim()||"/"===o)&&!!r){const n=e.find(t=>t.route.match("/"));if(!await p(n?.guards,{},s))return;const{element:o,transition:i,layout:a}=function(){const t=document.createElement(r);t[S]=c;const n=customElements.get(r),o=n?.[A],s=e.find(t=>t.route.match("/"));return{element:t,transition:o,layout:s?.layout}}(),u=f(a),{element:h,needsNewLayout:d}=m(u),g=i||t.transition;return null!==h||null!==l(s)?void await y(s,o,g,h,d):void await b(s,o,g)}const i=await async function(t,n){for(const o of e){const e=o.route.match(t);if(!1===e)continue;if(!await p(o.guards,e,n))return{result:X.GUARDS_FAILED};const r=document.createElement(o.tag);r[S]=c;const s=e;return Object.keys(s).forEach(t=>r.setAttribute(t,s[t])),{result:X.SUCCESS,element:r,transition:o.transition,layout:o.layout}}return{result:X.NOT_FOUND}}(o,s);if(i.result===X.GUARDS_FAILED)return;if(i.result===X.SUCCESS){const{element:e,transition:n,layout:o}=i,r=f(o),{element:a,needsNewLayout:c}=m(r),u=n||t.transition;return null!==a||null!==l(s)?void await y(s,e,u,a,c):void await b(s,e,u)}const{element:a,transition:u,layout:h}=function(){if(n){const t=document.createElement(n);t[S]=c;const e=customElements.get(n),o=e?.[A];return{element:t,transition:o,layout:void 0}}const t=document.createElement("div");return t.className="default-404",t.innerHTML="<h1>404</h1><p>Page not found</p>",{element:t,transition:void 0,layout:void 0}}(),d=f(h),{element:g,needsNewLayout:w}=m(d),v=u||t.transition;null!==g||null!==l(s)?await y(s,a,v,g,w):await b(s,a,v)}async function v(t,e,n,o){return async function(t,e,n,o={}){const r=o.outDuration||300,s=o.inDuration||300,i=o.mode||"sequential",a=o.out?V(o.out):{opacity:"0"},c={opacity:"0"},l=o.in?V(o.in):{opacity:"1"},u=t.style,h=u.position,d=t.tagName.includes("-")&&t.shadowRoot;d||(u.position="relative");const p=e.hasAttribute("slot")||n.hasAttribute("slot");p?(e.style.position="absolute",e.style.width="100%",e.style.height="100%",e.style.transition=`opacity ${r}ms ease-in-out`,n.style.position="absolute",n.style.width="100%",n.style.height="100%",n.style.transition=`opacity ${s}ms ease-in-out`):(e.style.position="absolute",e.style.top="0",e.style.left="0",e.style.width="100%",e.style.transition=`all ${r}ms ease-in-out`,n.style.position="absolute",n.style.top="0",n.style.left="0",n.style.width="100%"),Object.assign(n.style,c),n.style.transition=`all ${s}ms ease-in-out`,t.appendChild(n),n.offsetHeight,"simultaneous"===i?(Object.assign(e.style,a),Object.assign(n.style,l),await new Promise(t=>setTimeout(t,Math.max(r,s)))):(Object.assign(e.style,a),await new Promise(t=>setTimeout(t,r)),Object.assign(n.style,l),await new Promise(t=>setTimeout(t,s))),e.remove(),p?(n.style.position="",n.style.width="",n.style.height="",n.style.transition=""):(n.style.position="",n.style.top="",n.style.left="",n.style.width="",n.style.transition=""),Object.keys({...c,...l}).forEach(t=>{n.style[t]=""}),d||(u.position=h)}(t,e,n,o)}return{page:function(t){return function(e,n){if(n.metadata&&n.metadata[g]){e[g]||(e[g]=new Map);for(const[t,o]of n.metadata[g])e[g].set(t,o)}_(e),e[A]=t.transition;const o=e.prototype.connectedCallback;e.prototype.connectedCallback=function(){o?.call(this);const t=t=>{void 0!==this[S]&&(t.detail.context=this[S],t.stopPropagation())};this.addEventListener("@context/request",t),this[T]=t};const r=e.prototype.disconnectedCallback;return e.prototype.disconnectedCallback=function(){r?.call(this);const t=this[T];t&&(this.removeEventListener("@context/request",t),delete this[T]),delete this[S]},customElements.define(t.tag,e),t.routes.forEach(e=>u(e,t.tag,t.transition,t.guards,t.layout)),e}},initialize:function(){if(!!!document.querySelector(t.target))throw new Error(`Target element not found: ${t.target}`);!s&&(e.sort((t,e)=>e.route.spec.length-t.route.spec.length),s=!0),function(){const e="hash"===t.type,n="pushstate"===t.type;e&&window.addEventListener("hashchange",()=>{document.querySelector(t.target)&&w(h())}),n&&window.addEventListener("popstate",()=>{document.querySelector(t.target)&&w(h())})}(),w(h())},navigate:w,register:u,context:c}},t.SimpleArray=Q,t.applyElementFunctionality=_,t.attachController=K,t.cleanupNativeElementControllers=function(){const t=globalThis.sniceNativeControllerObserver;t&&(t.disconnect(),delete globalThis.sniceNativeControllerObserver,delete globalThis.sniceNativeControllersInitialized)},t.context=function(){return function(t,e){const n=e.name;return function(t){if(!Object.hasOwnProperty.call(this.constructor.prototype,n)){const t={get(){if(void 0!==this[S])return this[S];const t={target:this},e=new CustomEvent("@context/request",{bubbles:!0,cancelable:!0,detail:t});let n=!0===this[r]&&this.element?this.element:this;if(n&&n.dispatchEvent){if(n.getRootNode&&n.getRootNode()instanceof ShadowRoot){const t=n.getRootNode();n=t.host}return n.dispatchEvent(e),void 0!==t.context?(this[S]=t.context,t.context):void 0}},set(){},configurable:!0,enumerable:!0};Object.defineProperty(this.constructor.prototype,n,t)}return t}}},t.controller=function(t){return function(n,r){return e.controllerRegistry.set(t,n),n.prototype[o]=!0,n}},t.detachController=W,t.dispatch=function(t,e){return function(n,o){let r,s,i=0;return function(...o){const a=n.apply(this,o),c=n=>{if(void 0===n&&!1===e?.dispatchOnUndefined)return;const o=new CustomEvent(t,{bubbles:!0,composed:!0,...e,detail:n});this.dispatchEvent(o)},l=t=>{if(e?.debounce)clearTimeout(r),r=setTimeout(()=>c(t),e.debounce);else if(e?.throttle){const n=Date.now(),o=e.throttle-(n-i);o<=0?(clearTimeout(s),i=n,c(t)):s||(s=setTimeout(()=>{i=Date.now(),s=null,c(t)},o))}else c(t)};return a instanceof Promise?a.then(t=>(l(t),t)):(l(a),a)}}},t.dispose=function(){return function(t,e){const n=e.name;e.addInitializer(function(){const e=this.constructor;e[C]||(e[C]=[]),e[C].push({methodName:n,method:t})})}},t.element=function(t){return function(e,n){if(n.metadata&&n.metadata[g]){e[g]||(e[g]=new Map);for(const[t,o]of n.metadata[g])e[g].set(t,o)}return _(e),customElements.define(t,e),e}},t.getController=function(t){return t[h]},t.getSymbol=n,t.layout=function(t){return function(e,n){if(n.metadata&&n.metadata[g]){e[g]||(e[g]=new Map);for(const[t,o]of n.metadata[g])e[g].set(t,o)}return _(e),customElements.define(t,e),e}},t.observe=function(t,e,n){let o,r;return"string"==typeof e?(o=e,r=n):(o=void 0,r=e),function(e,n){const s=n.name;n.addInitializer(function(){const n=this.constructor;n.prototype[P]||(n.prototype[P]=[]);const i=Array.isArray(t)?t:[t];for(const t of i){const[i,...a]=t.split(":");n.prototype[P].push({type:i,target:a.join(":"),selector:o,methodName:s,method:e,options:r})}})}},t.on=function(t,e,n){let o,r;return"string"==typeof e?(o=e,r=n):(o=void 0,r=e),function(e,n){const s=n.name;n.addInitializer(function(){const n=this.constructor;n.prototype[u]||(n.prototype[u]=[]);const i=Array.isArray(t)?t:[t];for(const t of i)n.prototype[u].push({eventName:t,selector:o,methodName:s,method:e,options:r})})}},t.part=function(t,e={}){return function(n,o){const r=o.name;return o.addInitializer(function(){const e=this.constructor;e[I]||(e[I]=new Map),e[I].set(t,{methodName:r,method:n})}),function(...o){this[L]||(this[L]=new Map),this[L].has(t)||this[L].set(t,{throttleTimer:null,debounceTimer:null,lastThrottleCall:0});const r=this[L].get(t),s=n.apply(this,o),i=e=>{if(this.shadowRoot&&void 0!==e){const n=this.shadowRoot.querySelector(`[part="${t}"]`);n&&(n.innerHTML=e)}};if(s instanceof Promise){if(void 0!==e.debounce&&e.debounce>0)return r.debounceTimer&&clearTimeout(r.debounceTimer),r.debounceTimer=setTimeout(async()=>{const t=await s;i(t)},e.debounce),s;if(void 0!==e.throttle&&e.throttle>0){const t=Date.now();if(0===r.lastThrottleCall||t-r.lastThrottleCall>=e.throttle)return r.lastThrottleCall=t,s.then(t=>(i(t),t));if(!r.throttleTimer){const n=e.throttle-(t-r.lastThrottleCall);r.throttleTimer=setTimeout(async()=>{r.throttleTimer=null,r.lastThrottleCall=Date.now();const t=await s;i(t)},n)}return s}return s.then(t=>(i(t),t))}if(void 0!==e.debounce&&e.debounce>0)return r.debounceTimer&&clearTimeout(r.debounceTimer),r.debounceTimer=setTimeout(()=>{i(s)},e.debounce),s;if(void 0!==e.throttle&&e.throttle>0){const t=Date.now();if(0===r.lastThrottleCall||t-r.lastThrottleCall>=e.throttle)r.lastThrottleCall=t,i(s);else if(!r.throttleTimer){const n=e.throttle-(t-r.lastThrottleCall);r.throttleTimer=setTimeout(()=>{r.throttleTimer=null,r.lastThrottleCall=Date.now(),i(s)},n)}return s}return i(s),s}}},t.property=function(t){return function(e,n){const o=n.name;return n.metadata||(n.metadata={}),n.metadata[g]||(n.metadata[g]=new Map),n.metadata[g].set(o,t||{}),t?.reflect&&t?.type===Array&&console.warn(`⚠️ Property '${o}' uses reflect:true with Array type.`),t?.reflect&&t?.type===Object&&console.warn(`⚠️ Property '${o}' uses reflect:true with Object type.`),n.addInitializer(function(){}),function(e){if(!Object.hasOwnProperty.call(this.constructor.prototype,o)){const e={get(){return this[b]||(this[b]={}),this[b][o]},set(e){this[b]||(this[b]={}),this[E]||(this[E]=new Set);const n=this[b][o];if(n===e)return;const r=void 0===n&&!this[w];if((void 0!==n||r&&null!=e)&&this[E].add(o),this[b][o]=e,t?.reflect&&this.setAttribute&&this[w]&&this[E].has(o)){const n="string"==typeof t.attribute?t.attribute:o.toLowerCase();if(null==e||!1===e||t?.type===Q&&Array.isArray(e)&&0===e.length)this.removeAttribute(n);else{let o;o=e instanceof Date?e.toISOString():"bigint"==typeof e?e.toString()+"n":t?.type===Q&&Array.isArray(e)?Q.serialize(e):String(e),this.setAttribute(n,o)}}const s=this.constructor[v];if(s){if(s.has(o)){const t=s.get(o);for(const r of t)try{r.method.call(this,n,e,o)}catch(t){console.error(`Error in @watch('${o}') method ${r.methodName}:`,t)}}if(s.has("*")){const t=s.get("*");for(const r of t)try{r.method.call(this,n,e,o)}catch(t){console.error(`Error in @watch('*') method ${r.methodName}:`,t)}}}this.requestUpdate&&this.requestUpdate(o,n)},configurable:!0,enumerable:!0};Object.defineProperty(this.constructor.prototype,o,e)}return this[b]||(this[b]={}),this[b][o]=e,e}}},t.query=function(t,e={}){return function(n,o){const{light:s=!1,shadow:i=!0}=e,a=o.name;return function(e){if(!Object.hasOwnProperty.call(this.constructor.prototype,a)){const e={get(){const e=!0===this[r]&&this.element?this.element:this;let n=null;return i&&e.shadowRoot&&(n=e.shadowRoot.querySelector(t)),!n&&s&&(n=e.querySelector(t)),n||null},set(){},configurable:!0,enumerable:!0};Object.defineProperty(this.constructor.prototype,a,e)}return e}}},t.queryAll=function(t,e={}){return function(n,o){const{light:s=!1,shadow:i=!0}=e,a=o.name;return function(e){if(!Object.hasOwnProperty.call(this.constructor.prototype,a)){const e={get(){const e=!0===this[r]&&this.element?this.element:this,n=[];if(i&&e.shadowRoot){const o=e.shadowRoot.querySelectorAll(t);n.push(...o)}if(s){const o=e.querySelectorAll(t);n.push(...o)}return n},set(){},configurable:!0,enumerable:!0};Object.defineProperty(this.constructor.prototype,a,e)}return e}}},t.ready=function(){return function(t,e){const n=e.name;e.addInitializer(function(){const e=this.constructor;e[N]||(e[N]=[]),e[N].push({methodName:n,method:t})})}},t.request=function(t,e){return function(n,o){let s,i,a=0;return async function(...o){const c=async()=>{const s=e?.timeout??12e4,i=e?.discoveryTimeout??50,a=n.apply(this,o),{value:c,done:l}=await a.next();if(l)return c;let u,h;const d=new Promise((t,e)=>{u=t,h=e});let p,f,m;const y=new Promise((e,n)=>{p=e,f=n,m=setTimeout(()=>{n(new Error(`Request "${t}" timed out after ${i}ms - no handler found`))},i)}),g=new CustomEvent(`@request/${t}`,{bubbles:void 0===e?.bubbles||e.bubbles,cancelable:e?.cancelable||!1,composed:!0,detail:{payload:c,discovery:{resolve:()=>{clearTimeout(m),p()},reject:f},data:{resolve:u,reject:h}}});(!0===this[r]&&this.element?this.element:this).dispatchEvent(g);try{await y;const e=setTimeout(()=>{h(new Error(`Request "${t}" timed out after ${s}ms`))},s),n=await d;clearTimeout(e);const{value:o}=await a.next(n);return o}catch(t){try{await a.throw(t)}catch(t){throw t}}};if(e?.debounce)return new Promise((t,n)=>{clearTimeout(s),s=setTimeout(async()=>{try{const e=await c();t(e)}catch(t){n(t)}},e.debounce)});if(e?.throttle){const t=Date.now(),n=e.throttle-(t-a);return n<=0?(clearTimeout(i),a=t,c()):i?Promise.resolve():new Promise((t,e)=>{i=setTimeout(async()=>{a=Date.now(),i=null;try{const e=await c();t(e)}catch(t){e(t)}},n)})}return c()}}},t.respond=function(t,e){return function(n,o){const r=o.name;o.addInitializer(function(){const o=this.constructor;o.prototype[i]||(o.prototype[i]=[]),o.prototype[i].push({channelName:t,methodName:r,method:n,options:e})})}},t.useNativeElementControllers=function(){if(globalThis.sniceNativeControllersInitialized)return;function t(t){if(!(t instanceof HTMLElement))return;if(t.tagName.includes("-"))return;if(t[s])return;const e=t.getAttribute("controller"),n=t[m];e&&e!==n?(t[m]=e,t.ready||(t.ready=Promise.resolve()),n&&W(t).catch(t=>{console.error("Failed to detach old controller from native element:",t)}),K(t,e).catch(t=>{console.error(`Failed to attach controller "${e}" to native element:`,t)})):!e&&n&&(delete t[m],delete t[d],W(t).catch(t=>{console.error("Failed to detach controller from native element:",t)}))}globalThis.sniceNativeControllersInitialized=!0;const e=new MutationObserver(e=>{for(const n of e)"attributes"===n.type&&"controller"===n.attributeName?t(n.target):"childList"===n.type&&n.addedNodes.forEach(e=>{e instanceof HTMLElement&&(t(e),e.querySelectorAll('[controller]:not([class*="-"])').forEach(t))})});"loading"===document.readyState?document.addEventListener("DOMContentLoaded",()=>{document.querySelectorAll('[controller]:not([class*="-"])').forEach(t),e.observe(document.body,{attributes:!0,attributeFilter:["controller"],childList:!0,subtree:!0})}):(document.querySelectorAll('[controller]:not([class*="-"])').forEach(t),e.observe(document.body,{attributes:!0,attributeFilter:["controller"],childList:!0,subtree:!0})),globalThis.sniceNativeControllerObserver=e},t.watch=function(...t){return function(e,n){const o=n.name;n.addInitializer(function(){const n=this.constructor;n[v]||(n[v]=new Map);for(const r of t)n[v].has(r)||n[v].set(r,[]),n[v].get(r).push({methodName:o,method:e})})}},t}({});
14
+ class V{constructor(t){this.parsed=this.parsePattern(t)}get spec(){return this.parsed.template}parsePattern(t){let e=t,n="",o=!1;const r=t.indexOf("?");return-1!==r&&(e=t.slice(0,r),n=t.slice(r+1),e.endsWith("(")&&n.endsWith(")")&&(o=!0,e=e.slice(0,-1),n=n.slice(0,-1))),{pathSegments:this.parseSegments(e),querySegments:n?this.parseQuerySegments(n):[],queryOptional:o,template:t}}parseSegments(t){const e=[];let n=0;for(;n<t.length;){switch(t[n]){case"(":const{segments:o,endIndex:r}=this.parseOptionalGroup(t,n);e.push({type:"optional",segments:o}),n=r+1;break;case":":const{name:s,endIndex:i}=this.parseIdentifier(t,n+1);e.push({type:"param",name:s}),n=i;break;case"*":const{name:a,endIndex:c}=this.parseIdentifier(t,n+1);e.push({type:"splat",name:a}),n=c;break;default:const{value:l,endIndex:u}=this.parseLiteral(t,n);l&&e.push({type:"literal",value:l}),n=u}}return e}parseOptionalGroup(t,e){let n=1,o=e+1;for(;o<t.length&&n>0;)"("===t[o]&&n++,")"===t[o]&&n--,o++;const r=t.slice(e+1,o-1);return{segments:this.parseSegments(r),endIndex:o-1}}parseIdentifier(t,e){let n=e;for(;n<t.length&&/[\w-]/.test(t[n]);)n++;return{name:t.slice(e,n),endIndex:n}}parseLiteral(t,e){let n=e;for(;n<t.length&&!"(:*(".includes(t[n]);)n++;return{value:t.slice(e,n),endIndex:n}}parseQuerySegments(t){let e=t;e.startsWith("(")&&e.endsWith(")")&&(e=e.slice(1,-1));const n=[];let o=0;for(;o<e.length;)if(":"===e[o]){const{name:t,endIndex:r}=this.parseIdentifier(e,o+1);n.push({type:"param",name:t}),o=r}else{const{value:t,endIndex:r}=this.parseQueryLiteral(e,o);t&&n.push({type:"literal",value:t}),o=r}return n}parseQueryLiteral(t,e){let n=e;for(;n<t.length&&":"!==t[n];)n++;return{value:t.slice(e,n),endIndex:n}}getAllParamNames(){const t=new Set,e=n=>{for(const o of n)switch(o.type){case"param":case"splat":t.add(o.name);break;case"optional":e(o.segments)}};return e(this.parsed.pathSegments),e(this.parsed.querySegments),Array.from(t)}canMatchRemainingSegments(t,e,n){let o=e;for(const e of n)if("literal"===e.type){const n=t.indexOf(e.value,o);if(-1===n)return!1;o=n+e.value.length}return!0}match(t){const[e,n]=t.split("?"),o=this.matchPath(e,this.parsed.pathSegments);if(!1===o)return!1;const r=this.matchQuery(n||"",this.parsed.querySegments);if(!1===r)return!1;const s=this.getAllParamNames(),i={};for(const t of s)i[t]=void 0;return Object.assign(i,o,r),i}matchPath(t,e){const n={};let o=0;for(let r=0;r<e.length;r++){const s=e[r],i=e.slice(r+1),a=this.matchSegment(t,o,s,i);if(!1===a)return!1;Object.assign(n,a.params),o=a.nextIndex}return!(o<t.length)&&n}matchSegment(t,e,n,o=[]){switch(n.type){case"literal":return t.slice(e,e+n.value.length)===n.value&&{params:{},nextIndex:e+n.value.length};case"param":{let r=e;const s=o[0];let i,a=["/","?"];if(s&&"literal"===s.type){const n=s.value,o=t.indexOf(n,e);if(-1===o)return!1;r=o}else for(;r<t.length&&!a.includes(t[r]);)r++;if(r===e)return!1;try{i=decodeURIComponent(t.slice(e,r))}catch(n){i=t.slice(e,r)}return!(r<t.length&&"?"===t[r]&&o.length>0)&&{params:{[n.name]:i},nextIndex:r}}case"splat":{let r=t.length;const s=o[0];if(s)switch(s.type){case"literal":if("."===s.value){const n=t.indexOf(".",e);-1!==n&&(r=n)}else{const n=t.lastIndexOf(s.value);-1!==n&&n>=e&&(r=n)}break;case"param":let n=-1;for(let o=t.length-1;o>=e;o--)if("/"===t[o]){n=o;break}-1!==n&&(r=n);break;case"splat":let o=-1;for(let n=t.length-1;n>e;n--)if("/"===t[n]){o=n+1;break}if(-1!==o)r=o;else{const n=t.slice(e).split("/").filter(t=>t);r=n.length>1?e+n.slice(0,-1).join("/").length+1:e}break;case"optional":const i=t=>{for(const e of t){if("literal"===e.type)return e.value;if("optional"===e.type){const t=i(e.segments);if(t)return t}}return null},a=i(s.segments);if(a){const n=t.lastIndexOf(a);-1!==n&&n>=e&&(r=n)}}const i=t.indexOf("?",e);let a;-1!==i&&i<r&&(r=i);try{a=decodeURIComponent(t.slice(e,r))}catch(n){a=t.slice(e,r)}return{params:{[n.name]:a},nextIndex:r}}case"optional":{let r=e,s={},i=!0;for(let e=0;e<n.segments.length;e++){const o=n.segments[e],a=n.segments.slice(e+1),c=this.matchSegment(t,r,o,a);if(!1===c){i=!1;break}Object.assign(s,c.params),r=c.nextIndex}if(i){if(this.canMatchRemainingSegments(t,r,o))return{params:s,nextIndex:r}}return{params:{},nextIndex:e}}default:return!1}}findNextLiteral(t){for(const e of t){if("literal"===e.type)return e;if("optional"===e.type){const t=this.findNextLiteral(e.segments);if(t)return t}}return null}matchQuery(t,e){if(0===e.length)return{};const n={};let o=0;for(const r of e)switch(r.type){case"literal":if(t.slice(o,o+r.value.length)!==r.value)return!1;o+=r.value.length;break;case"param":{let e,s=o;for(;s<t.length&&"&"!==t[s];)s++;if(s===o)return!1;try{e=decodeURIComponent(t.slice(o,s))}catch(n){e=t.slice(o,s)}n[r.name]=e,o=s;break}}return n}reverse(t={}){const e=this.reverseSegments(this.parsed.pathSegments,t);if(!1===e)return!1;let n=e;if(this.parsed.querySegments.length>0){const e=this.reverseSegments(this.parsed.querySegments,t);if(!this.parsed.queryOptional&&!1===e)return!1;e&&""!==e&&(n+="?"+e)}return n}reverseSegments(t,e,n=!1){let o="";for(let r=0;r<t.length;r++){const s=t[r],i=t.slice(r+1);switch(s.type){case"literal":o+=s.value;break;case"param":case"splat":if(!(s.name in e))return!1;o+=String(e[s.name]);break;case"optional":if(this.hasAllParams(s.segments,e,n)||this.hasLaterOptionalGroupNeedingParams(i,e,s.segments)){const t=this.reverseSegments(s.segments,e,!0);if(!1===t)return!1;o+=t}}}return o}hasLaterOptionalGroupNeedingParams(t,e,n){for(const o of t)if("optional"===o.type&&this.hasAnyParamInSegments(o.segments,e))return this.hasOnlyLiteralsAndOptionals(n);return!1}hasOnlyLiteralsAndOptionals(t){for(const e of t)if("param"===e.type||"splat"===e.type)return!1;return!0}hasAllParams(t,e,n=!1){let o=!1,r=!1,s=!1,i=!0;for(const n of t)switch(n.type){case"param":case"splat":i=!1,n.name in e&&void 0!==e[n.name]?o=!0:s=!0}const a=n||o&&!s;for(const n of t)if("optional"===n.type){this.hasAllParams(n.segments,e,a)&&(r=!0)}return!(!o||s)||(!(!r||s)||!(!i||!n))}hasOnlyOptionalMissingParams(t,e){for(const n of t)switch(n.type){case"param":case"splat":if(!(n.name in e))return!1}return!0}hasAnyParamInSegments(t,e){for(const n of t)switch(n.type){case"param":case"splat":if(n.name in e)return!0;break;case"optional":if(this.hasAnyParamInSegments(n.segments,e))return!0}return!1}}function X(t){const e={};return t.split(";").forEach(t=>{const[n,o]=t.split(":").map(t=>t.trim());n&&o&&(e[n]=o)}),e}var Y;return function(t){t.SUCCESS="success",t.GUARDS_FAILED="guards-failed",t.NOT_FOUND="not-found"}(Y||(Y={})),t.IS_CONTROLLER_INSTANCE=r,t.Router=function(t){const e=[];let n,o,r,s=!1,i=null,a=null;const c=t.context||{};function l(t){if(!i||!a)return null;const e=t.querySelectorAll(i);for(const t of e){if(t[O]===a)return t}return null}function u(t,i,a,c,l){e.push({route:new V(t),tag:i,transition:a,guards:c,layout:l}),s=!1,"/404"===t&&(n=i),"/403"===t&&(o=i),"/"===t&&(r=i)}function h(){switch(t.type){case"hash":return window.location.hash.slice(1);case"pushstate":return window.location.pathname}}async function d(t){let e;const n=!!o;if(n&&(e=document.createElement(o),e[S]=c),!n){const t=document.createElement("div");t.className="default-403",t.innerHTML="<h1>403</h1><p>Unauthorized</p>",e=t}t.innerHTML="",t.appendChild(e),i=null,a=null}async function p(t,e,n){if(!!!t)return!0;const o=Array.isArray(t)?t:[t];for(const t of o){if(!await t(c,e))return await d(n),!1}return!0}function f(e){if(!1===e)return null;if(!!e)return e;return!!t.layout?t.layout:null}function m(t){if(!(t!==i))return{element:null,needsNewLayout:!1};i=t;if(!!t){const e=Date.now();a=e;const n=document.createElement(t);return n[S]=c,n[O]=e,{element:n,needsNewLayout:!0}}return a=null,{element:null,needsNewLayout:!0}}async function y(t,e,n,o,r){const s=o||l(t);if(!s)return;const i=s.querySelector('[slot="page"]');if(!(!n||!i))return e.setAttribute("slot","page"),await v(s,i,e,n),void(r&&(t.innerHTML="",t.appendChild(s)));s.querySelectorAll('[slot="page"]').forEach(t=>t.remove()),e.setAttribute("slot","page"),s.appendChild(e),r&&(t.innerHTML="",t.appendChild(s))}async function b(t,e,n){const o=t.children[0];!n||!o?(t.innerHTML="",t.appendChild(e)):await v(t,o,e,n)}async function w(o){const s=document.querySelector(t.target);if(!s)throw new Error(`Target element not found: ${t.target}`);window.scrollTo(0,0);if((""===o.trim()||"/"===o)&&!!r){const n=e.find(t=>t.route.match("/"));if(!await p(n?.guards,{},s))return;const{element:o,transition:i,layout:a}=function(){const t=document.createElement(r);t[S]=c;const n=customElements.get(r),o=n?.[T],s=e.find(t=>t.route.match("/"));return{element:t,transition:o,layout:s?.layout}}(),u=f(a),{element:h,needsNewLayout:d}=m(u),g=i||t.transition;return null!==h||null!==l(s)?void await y(s,o,g,h,d):void await b(s,o,g)}const i=await async function(t,n){for(const o of e){const e=o.route.match(t);if(!1===e)continue;if(!await p(o.guards,e,n))return{result:Y.GUARDS_FAILED};const r=document.createElement(o.tag);r[S]=c;const s=e;return Object.keys(s).forEach(t=>r.setAttribute(t,s[t])),{result:Y.SUCCESS,element:r,transition:o.transition,layout:o.layout}}return{result:Y.NOT_FOUND}}(o,s);if(i.result===Y.GUARDS_FAILED)return;if(i.result===Y.SUCCESS){const{element:e,transition:n,layout:o}=i,r=f(o),{element:a,needsNewLayout:c}=m(r),u=n||t.transition;return null!==a||null!==l(s)?void await y(s,e,u,a,c):void await b(s,e,u)}const{element:a,transition:u,layout:h}=function(){if(n){const t=document.createElement(n);t[S]=c;const e=customElements.get(n),o=e?.[T];return{element:t,transition:o,layout:void 0}}const t=document.createElement("div");return t.className="default-404",t.innerHTML="<h1>404</h1><p>Page not found</p>",{element:t,transition:void 0,layout:void 0}}(),d=f(h),{element:g,needsNewLayout:w}=m(d),v=u||t.transition;null!==g||null!==l(s)?await y(s,a,v,g,w):await b(s,a,v)}async function v(t,e,n,o){return async function(t,e,n,o={}){const r=o.outDuration||300,s=o.inDuration||300,i=o.mode||"sequential",a=o.out?X(o.out):{opacity:"0"},c={opacity:"0"},l=o.in?X(o.in):{opacity:"1"},u=t.style,h=u.position,d=t.tagName.includes("-")&&t.shadowRoot;d||(u.position="relative");const p=e.hasAttribute("slot")||n.hasAttribute("slot");p?(e.style.position="absolute",e.style.width="100%",e.style.height="100%",e.style.transition=`opacity ${r}ms ease-in-out`,n.style.position="absolute",n.style.width="100%",n.style.height="100%",n.style.transition=`opacity ${s}ms ease-in-out`):(e.style.position="absolute",e.style.top="0",e.style.left="0",e.style.width="100%",e.style.transition=`all ${r}ms ease-in-out`,n.style.position="absolute",n.style.top="0",n.style.left="0",n.style.width="100%"),Object.assign(n.style,c),n.style.transition=`all ${s}ms ease-in-out`,t.appendChild(n),n.offsetHeight,"simultaneous"===i?(Object.assign(e.style,a),Object.assign(n.style,l),await new Promise(t=>setTimeout(t,Math.max(r,s)))):(Object.assign(e.style,a),await new Promise(t=>setTimeout(t,r)),Object.assign(n.style,l),await new Promise(t=>setTimeout(t,s))),e.remove(),p?(n.style.position="",n.style.width="",n.style.height="",n.style.transition=""):(n.style.position="",n.style.top="",n.style.left="",n.style.width="",n.style.transition=""),Object.keys({...c,...l}).forEach(t=>{n.style[t]=""}),d||(u.position=h)}(t,e,n,o)}return{page:function(t){return function(e,n){if(n.metadata&&n.metadata[g]){e[g]||(e[g]=new Map);for(const[t,o]of n.metadata[g])e[g].set(t,o)}Q(e),e[T]=t.transition;const o=e.prototype.connectedCallback;e.prototype.connectedCallback=function(){o?.call(this);const t=t=>{void 0!==this[S]&&(t.detail.context=this[S],t.stopPropagation())};this.addEventListener("@context/request",t),this[A]=t};const r=e.prototype.disconnectedCallback;return e.prototype.disconnectedCallback=function(){r?.call(this);const t=this[A];t&&(this.removeEventListener("@context/request",t),delete this[A]),delete this[S]},customElements.define(t.tag,e),t.routes.forEach(e=>u(e,t.tag,t.transition,t.guards,t.layout)),e}},initialize:function(){if(!!!document.querySelector(t.target))throw new Error(`Target element not found: ${t.target}`);!s&&(e.sort((t,e)=>e.route.spec.length-t.route.spec.length),s=!0),function(){const e="hash"===t.type,n="pushstate"===t.type;e&&window.addEventListener("hashchange",()=>{document.querySelector(t.target)&&w(h())}),n&&window.addEventListener("popstate",()=>{document.querySelector(t.target)&&w(h())})}(),w(h())},navigate:w,register:u,context:c}},t.SimpleArray=J,t.applyElementFunctionality=Q,t.attachController=W,t.cleanupNativeElementControllers=function(){const t=globalThis.sniceNativeControllerObserver;t&&(t.disconnect(),delete globalThis.sniceNativeControllerObserver,delete globalThis.sniceNativeControllersInitialized)},t.context=function(){return function(t,e){const n=e.name;return function(t){if(!Object.hasOwnProperty.call(this.constructor.prototype,n)){const t={get(){if(void 0!==this[S])return this[S];const t={target:this},e=new CustomEvent("@context/request",{bubbles:!0,cancelable:!0,detail:t});let n=!0===this[r]&&this.element?this.element:this;if(n&&n.dispatchEvent){if(n.getRootNode&&n.getRootNode()instanceof ShadowRoot){const t=n.getRootNode();n=t.host}return n.dispatchEvent(e),void 0!==t.context?(this[S]=t.context,t.context):void 0}},set(){},configurable:!0,enumerable:!0};Object.defineProperty(this.constructor.prototype,n,t)}return t}}},t.controller=function(t){return function(n,r){return e.controllerRegistry.set(t,n),n.prototype[o]=!0,n}},t.detachController=_,t.dispatch=function(t,e){return function(n,o){return function(...r){this[x]||(this[x]=new Map);const s=`${t}_${o.name}`;this[x].has(s)||this[x].set(s,{debounceTimeout:null,throttleLastCall:0,throttleTimeout:null});const i=this[x].get(s),a=n.apply(this,r),c=n=>{if(void 0===n&&!1===e?.dispatchOnUndefined)return;const o=new CustomEvent(t,{bubbles:!0,composed:!0,...e,detail:n});this.dispatchEvent(o)},l=t=>{if(e?.debounce)clearTimeout(i.debounceTimeout),i.debounceTimeout=setTimeout(()=>c(t),e.debounce);else if(e?.throttle){const n=Date.now(),o=e.throttle-(n-i.throttleLastCall);o<=0?(clearTimeout(i.throttleTimeout),i.throttleLastCall=n,c(t)):i.throttleTimeout||(i.throttleTimeout=setTimeout(()=>{i.throttleLastCall=Date.now(),i.throttleTimeout=null,c(t)},o))}else c(t)};return a instanceof Promise?a.then(t=>(l(t),t)):(l(a),a)}}},t.dispose=function(){return function(t,e){const n=e.name;e.addInitializer(function(){const e=this.constructor;e[C]||(e[C]=[]),e[C].push({methodName:n,method:t})})}},t.element=function(t){return function(e,n){if(n.metadata&&n.metadata[g]){e[g]||(e[g]=new Map);for(const[t,o]of n.metadata[g])e[g].set(t,o)}return Q(e),customElements.define(t,e),e}},t.getController=function(t){return t[h]},t.getSymbol=n,t.layout=function(t){return function(e,n){if(n.metadata&&n.metadata[g]){e[g]||(e[g]=new Map);for(const[t,o]of n.metadata[g])e[g].set(t,o)}return Q(e),customElements.define(t,e),e}},t.observe=function(t,e,n){let o,r;return"string"==typeof e?(o=e,r=n):(o=void 0,r=e),function(e,n){const s=n.name;n.addInitializer(function(){const n=this.constructor;n.prototype[L]||(n.prototype[L]=[]);const i=Array.isArray(t)?t:[t];for(const t of i){const[i,...a]=t.split(":");n.prototype[L].push({type:i,target:a.join(":"),selector:o,methodName:s,method:e,options:r})}})}},t.on=function(t,e,n){let o,r;return"string"==typeof e?(o=e,r=n):(o=void 0,r=e),function(e,n){const s=n.name;n.addInitializer(function(){const n=this.constructor;n.prototype[u]||(n.prototype[u]=[]);const i=Array.isArray(t)?t:[t];for(const t of i)n.prototype[u].push({eventName:t,selector:o,methodName:s,method:e,options:r})})}},t.part=function(t,e={}){return function(n,o){const r=o.name;return o.addInitializer(function(){const e=this.constructor;e[P]||(e[P]=new Map),e[P].set(t,{methodName:r,method:n})}),function(...o){this[I]||(this[I]=new Map),this[I].has(t)||this[I].set(t,{throttleTimer:null,debounceTimer:null,lastThrottleCall:0});const r=this[I].get(t),s=(...e)=>{const o=n.apply(this,e),r=e=>{const n=void 0!==e,o=this.shadowRoot?.querySelector(`[part="${t}"]`);n&&o&&(o.innerHTML=e)};return o instanceof Promise?o.then(t=>(r(t),t)):(r(o),o)},i=void 0!==e.debounce&&e.debounce>0,a=void 0!==e.throttle&&e.throttle>0;switch(!0){case i:return clearTimeout(r.debounceTimer),void(r.debounceTimer=setTimeout(()=>s(...o),e.debounce));case a:{const t=e.throttle,n=Date.now();if(0===r.lastThrottleCall||n-r.lastThrottleCall>=t)return r.lastThrottleCall=n,s(...o);if(!!!r.throttleTimer){const e=t-(n-r.lastThrottleCall);r.throttleTimer=setTimeout(()=>{r.throttleTimer=null,r.lastThrottleCall=Date.now(),s(...o)},e)}return}default:return s(...o)}}}},t.property=function(t){return function(e,n){const o=n.name;return n.metadata||(n.metadata={}),n.metadata[g]||(n.metadata[g]=new Map),n.metadata[g].set(o,t||{}),t?.reflect&&t?.type===Array&&console.warn(`⚠️ Property '${o}' uses reflect:true with Array type.`),t?.reflect&&t?.type===Object&&console.warn(`⚠️ Property '${o}' uses reflect:true with Object type.`),n.addInitializer(function(){}),function(e){if(!Object.hasOwnProperty.call(this.constructor.prototype,o)){const e={get(){return this[b]||(this[b]={}),this[b][o]},set(e){this[b]||(this[b]={}),this[E]||(this[E]=new Set);const n=this[b][o];if(n===e)return;const r=void 0===n&&!this[w];if((void 0!==n||r&&null!=e)&&this[E].add(o),this[b][o]=e,t?.reflect&&this.setAttribute&&this[w]&&this[E].has(o)){const n="string"==typeof t.attribute?t.attribute:o.toLowerCase();if(null==e||!1===e||t?.type===J&&Array.isArray(e)&&0===e.length)this.removeAttribute(n);else{let o;o=e instanceof Date?e.toISOString():"bigint"==typeof e?e.toString()+"n":t?.type===J&&Array.isArray(e)?J.serialize(e):String(e),this.setAttribute(n,o)}}const s=this.constructor[v];if(s){if(s.has(o)){const t=s.get(o);for(const r of t)try{r.method.call(this,n,e,o)}catch(t){console.error(`Error in @watch('${o}') method ${r.methodName}:`,t)}}if(s.has("*")){const t=s.get("*");for(const r of t)try{r.method.call(this,n,e,o)}catch(t){console.error(`Error in @watch('*') method ${r.methodName}:`,t)}}}this.requestUpdate&&this.requestUpdate(o,n)},configurable:!0,enumerable:!0};Object.defineProperty(this.constructor.prototype,o,e)}return this[b]||(this[b]={}),this[b][o]=e,e}}},t.query=function(t,e={}){return function(n,o){const{light:s=!1,shadow:i=!0}=e,a=o.name;return function(e){if(!Object.hasOwnProperty.call(this.constructor.prototype,a)){const e={get(){const e=!0===this[r]&&this.element?this.element:this;let n=null;return i&&e.shadowRoot&&(n=e.shadowRoot.querySelector(t)),!n&&s&&(n=e.querySelector(t)),n||null},set(){},configurable:!0,enumerable:!0};Object.defineProperty(this.constructor.prototype,a,e)}return e}}},t.queryAll=function(t,e={}){return function(n,o){const{light:s=!1,shadow:i=!0}=e,a=o.name;return function(e){if(!Object.hasOwnProperty.call(this.constructor.prototype,a)){const e={get(){const e=!0===this[r]&&this.element?this.element:this,n=[];if(i&&e.shadowRoot){const o=e.shadowRoot.querySelectorAll(t);n.push(...o)}if(s){const o=e.querySelectorAll(t);n.push(...o)}return n},set(){},configurable:!0,enumerable:!0};Object.defineProperty(this.constructor.prototype,a,e)}return e}}},t.ready=function(){return function(t,e){const n=e.name;e.addInitializer(function(){const e=this.constructor;e[N]||(e[N]=[]),e[N].push({methodName:n,method:t})})}},t.request=function(t,e){return function(n,o){let s,i,a=0;return async function(...o){const c=async()=>{const s=e?.timeout??12e4,i=e?.discoveryTimeout??50,a=n.apply(this,o),{value:c,done:l}=await a.next();if(l)return c;let u,h;const d=new Promise((t,e)=>{u=t,h=e});let p,f,m;const y=new Promise((e,n)=>{p=e,f=n,m=setTimeout(()=>{n(new Error(`Request "${t}" timed out after ${i}ms - no handler found`))},i)}),g=new CustomEvent(`@request/${t}`,{bubbles:void 0===e?.bubbles||e.bubbles,cancelable:e?.cancelable||!1,composed:!0,detail:{payload:c,discovery:{resolve:()=>{clearTimeout(m),p()},reject:f},data:{resolve:u,reject:h}}});(!0===this[r]&&this.element?this.element:this).dispatchEvent(g);try{await y;const e=setTimeout(()=>{h(new Error(`Request "${t}" timed out after ${s}ms`))},s),n=await d;clearTimeout(e);const{value:o}=await a.next(n);return o}catch(t){try{await a.throw(t)}catch(t){throw t}}};if(e?.debounce)return new Promise((t,n)=>{clearTimeout(s),s=setTimeout(async()=>{try{const e=await c();t(e)}catch(t){n(t)}},e.debounce)});if(e?.throttle){const t=Date.now(),n=e.throttle-(t-a);return n<=0?(clearTimeout(i),a=t,c()):i?Promise.resolve():new Promise((t,e)=>{i=setTimeout(async()=>{a=Date.now(),i=null;try{const e=await c();t(e)}catch(t){e(t)}},n)})}return c()}}},t.respond=function(t,e){return function(n,o){const r=o.name;o.addInitializer(function(){const o=this.constructor;o.prototype[i]||(o.prototype[i]=[]),o.prototype[i].push({channelName:t,methodName:r,method:n,options:e})})}},t.useNativeElementControllers=function(){if(globalThis.sniceNativeControllersInitialized)return;function t(t){if(!(t instanceof HTMLElement))return;if(t.tagName.includes("-"))return;if(t[s])return;const e=t.getAttribute("controller"),n=t[m];e&&e!==n?(t[m]=e,t.ready||(t.ready=Promise.resolve()),n&&_(t).catch(t=>{console.error("Failed to detach old controller from native element:",t)}),W(t,e).catch(t=>{console.error(`Failed to attach controller "${e}" to native element:`,t)})):!e&&n&&(delete t[m],delete t[d],_(t).catch(t=>{console.error("Failed to detach controller from native element:",t)}))}globalThis.sniceNativeControllersInitialized=!0;const e=new MutationObserver(e=>{for(const n of e)"attributes"===n.type&&"controller"===n.attributeName?t(n.target):"childList"===n.type&&n.addedNodes.forEach(e=>{e instanceof HTMLElement&&(t(e),e.querySelectorAll('[controller]:not([class*="-"])').forEach(t))})});"loading"===document.readyState?document.addEventListener("DOMContentLoaded",()=>{document.querySelectorAll('[controller]:not([class*="-"])').forEach(t),e.observe(document.body,{attributes:!0,attributeFilter:["controller"],childList:!0,subtree:!0})}):(document.querySelectorAll('[controller]:not([class*="-"])').forEach(t),e.observe(document.body,{attributes:!0,attributeFilter:["controller"],childList:!0,subtree:!0})),globalThis.sniceNativeControllerObserver=e},t.watch=function(...t){return function(e,n){const o=n.name;n.addInitializer(function(){const n=this.constructor;n[v]||(n[v]=new Map);for(const r of t)n[v].has(r)||n[v].set(r,[]),n[v].get(r).push({methodName:o,method:e})})}},t}({});
15
15
  //# sourceMappingURL=index.iife.min.js.map