snice 2.1.2 → 2.1.3

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,14 +1,14 @@
1
1
  /*!
2
- * snice v2.1.1
2
+ * snice v2.1.2
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
- const t=(globalThis.snice||(globalThis.snice={controllerRegistry:new Map,controllerIdCounter:0,symbols:new Map}),globalThis.snice);function e(e){return t.symbols.has(e)||t.symbols.set(e,Symbol(e)),t.symbols.get(e)}const n=e("is-controller-class"),o=e("is-controller-instance"),r=e("is-element-class"),s=e("channel-handlers"),i=e("ready-promise"),a=e("ready-resolve"),c=e("controller"),l=e("on-handlers"),u=e("controller-key"),h=e("controller-name"),d=e("controller-id"),p=e("controller-operations"),f=e("native-controller"),m=e("cleanup"),y=e("properties"),g=e("property-values"),b=e("properties-initialized"),w=e("property-watchers"),v=e("explicitly-set-properties"),E=e("router-context");e("current-page-marker");const S=e("context-request-handler"),T=e("page-transition"),A=e("created-at"),O=e("ready-handlers"),N=e("dispose-handlers"),P=e("observers"),C=e("parts"),I=e("part-timers");function L(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)n.prototype[l].push({eventName:t,selector:o,methodName:s,method:e,options:r})})}}function x(t,e){const n=t.constructor.prototype[l];if(n){t[m]||(t[m]={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[m].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[m].events.push(()=>{e.removeEventListener(s,l,n)})}}}}function k(t){if(t[m]?.events){for(const e of t[m].events)e();t[m].events=[]}}function R(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)}}}const $=new Map,q=new WeakMap;function D(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})}})}}function M(t,e){const n=t.constructor.prototype[P];if(n&&Array.isArray(n)&&0!==n.length){t[m]?t[m].observers||(t[m].observers=[]):t[m]={events:[],channels:[],observers:[]};for(const o of n){const n=o.method.bind(t),r=o.options?.throttle?H(n,o.options.throttle):n;switch(o.type){case"intersection":j(t,e,o,r);break;case"resize":z(t,e,o,r);break;case"media":F(t,e,o,r);break;case"mutation":U(t,e,o,r);break;default:console.warn(`Unknown observer type: ${o.type}`)}}}}function j(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[m].observers.push(()=>{c.forEach(t=>a.unobserve(t)),0===a.takeRecords().length&&a.disconnect()})}function z(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[m].observers.push(()=>{s.disconnect()})}function F(t,e,n,o){const r=n.target;if(!r)return void console.warn("Media query observer requires a query string");let s=$.get(r);if(!s)try{s=window.matchMedia(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[m].observers.push(()=>{s.removeEventListener("change",a)})):(s.addListener(a),t[m].observers.push(()=>{s.removeListener(a)}))}function U(t,e,n,r){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 o=n.options.maxDepth,s=t.filter(t=>{let n=0,r=t.target;const s=e.shadowRoot||e;for(;r&&r!==s&&n<o;)r=r.parentNode,n++;return n<o});s.length>0&&r(s)}else r(t)}catch(t){console.error(`Error in mutation observer ${n.methodName}:`,t)}}),u=!0===t[o];(n.selector?Array.from(e.shadowRoot?.querySelectorAll(n.selector)||[]):u&&e.shadowRoot?[e.shadowRoot]:[e]).forEach(t=>{l.observe(t,c)}),t[m].observers.push(()=>{l.disconnect()})}function H(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 B(t){if(t[m]?.observers){for(const e of t[m].observers)e();t[m].observers=[]}}function G(t,e){return function(n,r){let s,i,a=0;return async function(...r){const c=async()=>{const s=e?.timeout??12e4,i=e?.discoveryTimeout??50,a=n.apply(this,r),{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[o]&&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()}}}function K(t,e){return function(n,o){const r=o.name;o.addInitializer(function(){const o=this.constructor;o.prototype[s]||(o.prototype[s]=[]),o.prototype[s].push({channelName:t,methodName:r,method:n,options:e})})}}function W(t,e){const n=t.constructor.prototype[s];if(n){t[m]||(t[m]={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[m].channels.push(()=>{e.removeEventListener(r,l)})}}}function Q(t){if(t[m]?.channels){for(const e of t[m].channels)e();t[m].channels=[]}}class _{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}}}function J(e){return function(o,r){return t.controllerRegistry.set(e,o),o.prototype[n]=!0,o}}async function V(e,n){const r=e[u],s=e[h],i=e[f];if(void 0!==i&&i!==n)return;if(s===n&&r)return;r&&await X(e);const a=t.controllerRegistry.get(n);if(!a)throw new Error(`Controller "${n}" not found in registry`);const c=new a;t.controllerIdCounter+=1;const l=t.controllerIdCounter,m=new _;c[o]=!0,c[d]=l,c.element=e;const y=e[E];void 0!==y&&(c[E]=y),e[u]=c,e[h]=n,e[p]=m,await e.ready,await m.runOperation(async()=>{await c.attach(e)}),x(c,e),M(c,e),W(c,e),e.dispatchEvent(new CustomEvent("@snice/controller-attached",{detail:{name:n,controller:c}}))}async function X(t){const e=t[u],n=t[h],o=t[p];e&&(o?await o.runOperation(async()=>{await e.detach(t)}):await e.detach(t),e.element=null,k(e),B(e),Q(e),o&&await o.cleanup(),delete e[E],delete t[u],delete t[h],delete t[p],t.dispatchEvent(new CustomEvent("@snice/controller-detached",{detail:{name:n,controller:e}})))}function Y(t){return t[u]}function Z(){if(globalThis.sniceNativeControllersInitialized)return;function t(t){if(!(t instanceof HTMLElement))return;if(t.tagName.includes("-"))return;if(t[r])return;const e=t.getAttribute("controller"),n=t[f];e&&e!==n?(t[f]=e,t.ready||(t.ready=Promise.resolve()),n&&X(t).catch(t=>{console.error("Failed to detach old controller from native element:",t)}),V(t,e).catch(t=>{console.error(`Failed to attach controller "${e}" to native element:`,t)})):!e&&n&&(delete t[f],delete t[h],X(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}function tt(){const t=globalThis.sniceNativeControllerObserver;t&&(t.disconnect(),delete globalThis.sniceNativeControllerObserver,delete globalThis.sniceNativeControllersInitialized)}function et(t){t.prototype[r]=!0;const e=t.prototype.connectedCallback,n=t.prototype.disconnectedCallback,o=t.prototype.attributeChangedCallback,s=t.observedAttributes||[];s.includes("controller")||s.push("controller");const l=t[y];if(l)for(const[t,e]of l){const n="string"==typeof e.attribute?e.attribute:t.toLowerCase();s.includes(n)||s.push(n)}Object.defineProperty(t,"observedAttributes",{get:()=>s,configurable:!0}),Object.defineProperty(t.prototype,"ready",{get(){return this[i]||(this[i]=new Promise(t=>{this[a]=t})),this[i]},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"controller",{get(){return this[c]},set(t){const e=this[c];this[c]=t,t!==e&&t?V(this,t).catch(e=>{console.error(`Failed to attach controller "${t}":`,e)}):!t&&e&&X(this).catch(t=>{console.error("Failed to detach controller:",t)})},enumerable:!0,configurable:!0}),t.prototype.connectedCallback=async function(){this[i]||(this[i]=new Promise(t=>{this[a]=t}));try{const n=t[y];if(n)for(const[t,e]of n)if(this.hasAttribute(t)){const n=this.getAttribute(t);switch(this[v]||(this[v]=new Set),this[v].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 at:this[t]=at.parse(n);break;default:this[t]=n}}if(this[b]=!0,n)for(const[t,e]of n){const n=this[v]&&this[v].has(t),o=t in this[g];if(e.reflect&&o&&(n||void 0!==this[g][t])){const n=this[g][t],o="string"==typeof e.attribute?e.attribute:t.toLowerCase();if(null!=n&&!1!==n&&(e.type!==at||!Array.isArray(n)||0!==n.length)){let t;t=n instanceof Date?n.toISOString():"bigint"==typeof n?n.toString()+"n":e.type===at&&Array.isArray(n)?at.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[C];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),W(this,this);try{M(this,this)}catch(t){console.error(`Error setting up observers for ${this.tagName}:`,t)}const i=t[O];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[a]&&(this[a](),this[a]=null)}},t.prototype.disconnectedCallback=async function(){const e=t[N];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[c]&&X(this).catch(t=>{console.error("Failed to detach controller:",t)}),k(this),Q(this),B(this)},t.prototype.attributeChangedCallback=function(e,n,r){if(o?.call(this,e,n,r),"controller"===e)this.controller=r;else{const n=t[y];if(n)for(const[o,s]of n){if(("string"==typeof s.attribute?s.attribute:o.toLowerCase())===e){const e=this[g]?.[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===at?at.parse(r):"number"==typeof e&&null!==r?Number(r):r,e!==n){this[v]||(this[v]=new Set),this[v].add(o),this[g]||(this[g]={}),this[g][o]=n;const r=t[w];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}}}}}function nt(t){return function(e,n){if(n.metadata&&n.metadata[y]){e[y]||(e[y]=new Map);for(const[t,o]of n.metadata[y])e[y].set(t,o)}return et(e),customElements.define(t,e),e}}function ot(t){return function(e,n){if(n.metadata&&n.metadata[y]){e[y]||(e[y]=new Map);for(const[t,o]of n.metadata[y])e[y].set(t,o)}return et(e),customElements.define(t,e),e}}function rt(t){return function(e,n){const o=n.name;return n.metadata||(n.metadata={}),n.metadata[y]||(n.metadata[y]=new Map),n.metadata[y].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[g]||(this[g]={}),this[g][o]},set(e){this[g]||(this[g]={}),this[v]||(this[v]=new Set);const n=this[g][o];if(n===e)return;const r=void 0===n&&!this[b];if((void 0!==n||r&&null!=e)&&this[v].add(o),this[g][o]=e,t?.reflect&&this.setAttribute&&this[b]&&this[v].has(o)){const n="string"==typeof t.attribute?t.attribute:o.toLowerCase();if(null==e||!1===e||t?.type===at&&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===at&&Array.isArray(e)?at.serialize(e):String(e),this.setAttribute(n,o)}}const s=this.constructor[w];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[g]||(this[g]={}),this[g][o]=e,e}}}function st(t,e={}){return function(n,r){const{light:s=!1,shadow:i=!0}=e,a=r.name;return function(e){if(!Object.hasOwnProperty.call(this.constructor.prototype,a)){const e={get(){const e=!0===this[o]&&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}}}function it(t,e={}){return function(n,r){const{light:s=!1,shadow:i=!0}=e,a=r.name;return function(e){if(!Object.hasOwnProperty.call(this.constructor.prototype,a)){const e={get(){const e=!0===this[o]&&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}}}class at{static{this.SEPARATOR=","}static serialize(t){return Array.isArray(t)?t.map(t=>{if("string"==typeof t){if(t.includes(at.SEPARATOR))throw new Error(`SimpleArray strings cannot contain the character "${at.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(at.SEPARATOR):""}static parse(t){return null==t||""===t?[]:t.split(at.SEPARATOR).map(t=>{if(/^-?\d+\.?\d*$/.test(t)){const e=Number(t);if(!isNaN(e))return e}return"true"===t||"false"!==t&&t})}}function ct(...t){return function(e,n){const o=n.name;n.addInitializer(function(){const n=this.constructor;n[w]||(n[w]=new Map);for(const r of t)n[w].has(r)||n[w].set(r,[]),n[w].get(r).push({methodName:o,method:e})})}}function lt(){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[E])return this[E];const t={target:this},e=new CustomEvent("@context/request",{bubbles:!0,cancelable:!0,detail:t});let n=!0===this[o]&&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[E]=t.context,t.context):void 0}},set(){},configurable:!0,enumerable:!0};Object.defineProperty(this.constructor.prototype,n,t)}return t}}}function ut(){return function(t,e){const n=e.name;e.addInitializer(function(){const e=this.constructor;e[O]||(e[O]=[]),e[O].push({methodName:n,method:t})})}}function ht(){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})})}}function dt(t,e={}){return function(n,o){const r=o.name;return o.addInitializer(function(){const e=this.constructor;e[C]||(e[C]=new Map),e[C].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=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}}}
7
+ const t=(globalThis.snice||(globalThis.snice={controllerRegistry:new Map,controllerIdCounter:0,symbols:new Map}),globalThis.snice);function e(e){return t.symbols.has(e)||t.symbols.set(e,Symbol(e)),t.symbols.get(e)}const n=e("is-controller-class"),o=e("is-controller-instance"),r=e("is-element-class"),s=e("channel-handlers"),i=e("ready-promise"),a=e("ready-resolve"),c=e("controller"),l=e("on-handlers"),u=e("controller-key"),h=e("controller-name"),d=e("controller-id"),p=e("controller-operations"),f=e("native-controller"),m=e("cleanup"),y=e("properties"),g=e("property-values"),b=e("properties-initialized"),w=e("property-watchers"),v=e("explicitly-set-properties"),E=e("router-context");e("current-page-marker");const S=e("context-request-handler"),T=e("page-transition"),A=e("created-at"),O=e("ready-handlers"),N=e("dispose-handlers"),P=e("observers"),L=e("parts"),I=e("part-timers"),C=e("dispatch-timers");function x(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)n.prototype[l].push({eventName:t,selector:o,methodName:s,method:e,options:r})})}}function k(t,e){const n=t.constructor.prototype[l];if(n){t[m]||(t[m]={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[m].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[m].events.push(()=>{e.removeEventListener(s,l,n)})}}}}function R(t){if(t[m]?.events){for(const e of t[m].events)e();t[m].events=[]}}function $(t,e){return function(n,o){return function(...r){this[C]||(this[C]=new Map);const s=`${t}_${o.name}`;this[C].has(s)||this[C].set(s,{debounceTimeout:null,throttleLastCall:0,throttleTimeout:null});const i=this[C].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)}}}const q=new Map,D=new WeakMap;function M(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})}})}}function j(t,e){const n=t.constructor.prototype[P];if(n&&Array.isArray(n)&&0!==n.length){t[m]?t[m].observers||(t[m].observers=[]):t[m]={events:[],channels:[],observers:[]};for(const o of n){const n=o.method.bind(t),r=o.options?.throttle?B(n,o.options.throttle):n;switch(o.type){case"intersection":z(t,e,o,r);break;case"resize":F(t,e,o,r);break;case"media":U(t,e,o,r);break;case"mutation":H(t,e,o,r);break;default:console.warn(`Unknown observer type: ${o.type}`)}}}}function z(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=D.get({instance:t,options:s});a||(a=new IntersectionObserver(i,r),D.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[m].observers.push(()=>{c.forEach(t=>a.unobserve(t)),0===a.takeRecords().length&&a.disconnect()})}function F(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[m].observers.push(()=>{s.disconnect()})}function U(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[m].observers.push(()=>{s.removeEventListener("change",a)})):(s.addListener(a),t[m].observers.push(()=>{s.removeListener(a)}))}function H(t,e,n,r){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 o=n.options.maxDepth,s=t.filter(t=>{let n=0,r=t.target;const s=e.shadowRoot||e;for(;r&&r!==s&&n<o;)r=r.parentNode,n++;return n<o});s.length>0&&r(s)}else r(t)}catch(t){console.error(`Error in mutation observer ${n.methodName}:`,t)}}),u=!0===t[o];(n.selector?Array.from(e.shadowRoot?.querySelectorAll(n.selector)||[]):u&&e.shadowRoot?[e.shadowRoot]:[e]).forEach(t=>{l.observe(t,c)}),t[m].observers.push(()=>{l.disconnect()})}function B(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 G(t){if(t[m]?.observers){for(const e of t[m].observers)e();t[m].observers=[]}}function K(t,e){return function(n,r){let s,i,a=0;return async function(...r){const c=async()=>{const s=e?.timeout??12e4,i=e?.discoveryTimeout??50,a=n.apply(this,r),{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[o]&&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()}}}function W(t,e){return function(n,o){const r=o.name;o.addInitializer(function(){const o=this.constructor;o.prototype[s]||(o.prototype[s]=[]),o.prototype[s].push({channelName:t,methodName:r,method:n,options:e})})}}function Q(t,e){const n=t.constructor.prototype[s];if(n){t[m]||(t[m]={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[m].channels.push(()=>{e.removeEventListener(r,l)})}}}function _(t){if(t[m]?.channels){for(const e of t[m].channels)e();t[m].channels=[]}}class J{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}}}function V(e){return function(o,r){return t.controllerRegistry.set(e,o),o.prototype[n]=!0,o}}async function X(e,n){const r=e[u],s=e[h],i=e[f];if(void 0!==i&&i!==n)return;if(s===n&&r)return;r&&await Y(e);const a=t.controllerRegistry.get(n);if(!a)throw new Error(`Controller "${n}" not found in registry`);const c=new a;t.controllerIdCounter+=1;const l=t.controllerIdCounter,m=new J;c[o]=!0,c[d]=l,c.element=e;const y=e[E];void 0!==y&&(c[E]=y),e[u]=c,e[h]=n,e[p]=m,await e.ready,await m.runOperation(async()=>{await c.attach(e)}),k(c,e),j(c,e),Q(c,e),e.dispatchEvent(new CustomEvent("@snice/controller-attached",{detail:{name:n,controller:c}}))}async function Y(t){const e=t[u],n=t[h],o=t[p];e&&(o?await o.runOperation(async()=>{await e.detach(t)}):await e.detach(t),e.element=null,R(e),G(e),_(e),o&&await o.cleanup(),delete e[E],delete t[u],delete t[h],delete t[p],t.dispatchEvent(new CustomEvent("@snice/controller-detached",{detail:{name:n,controller:e}})))}function Z(t){return t[u]}function tt(){if(globalThis.sniceNativeControllersInitialized)return;function t(t){if(!(t instanceof HTMLElement))return;if(t.tagName.includes("-"))return;if(t[r])return;const e=t.getAttribute("controller"),n=t[f];e&&e!==n?(t[f]=e,t.ready||(t.ready=Promise.resolve()),n&&Y(t).catch(t=>{console.error("Failed to detach old controller from native element:",t)}),X(t,e).catch(t=>{console.error(`Failed to attach controller "${e}" to native element:`,t)})):!e&&n&&(delete t[f],delete t[h],Y(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}function et(){const t=globalThis.sniceNativeControllerObserver;t&&(t.disconnect(),delete globalThis.sniceNativeControllerObserver,delete globalThis.sniceNativeControllersInitialized)}function nt(t){t.prototype[r]=!0;const e=t.prototype.connectedCallback,n=t.prototype.disconnectedCallback,o=t.prototype.attributeChangedCallback,s=t.observedAttributes||[];s.includes("controller")||s.push("controller");const l=t[y];if(l)for(const[t,e]of l){const n="string"==typeof e.attribute?e.attribute:t.toLowerCase();s.includes(n)||s.push(n)}Object.defineProperty(t,"observedAttributes",{get:()=>s,configurable:!0}),Object.defineProperty(t.prototype,"ready",{get(){return this[i]||(this[i]=new Promise(t=>{this[a]=t})),this[i]},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"controller",{get(){return this[c]},set(t){const e=this[c];this[c]=t,t!==e&&t?X(this,t).catch(e=>{console.error(`Failed to attach controller "${t}":`,e)}):!t&&e&&Y(this).catch(t=>{console.error("Failed to detach controller:",t)})},enumerable:!0,configurable:!0}),t.prototype.connectedCallback=async function(){this[i]||(this[i]=new Promise(t=>{this[a]=t}));try{const n=t[y];if(n)for(const[t,e]of n)if(this.hasAttribute(t)){const n=this.getAttribute(t);switch(this[v]||(this[v]=new Set),this[v].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 ct:this[t]=ct.parse(n);break;default:this[t]=n}}if(this[b]=!0,n)for(const[t,e]of n){const n=this[v]&&this[v].has(t),o=t in this[g];if(e.reflect&&o&&(n||void 0!==this[g][t])){const n=this[g][t],o="string"==typeof e.attribute?e.attribute:t.toLowerCase();if(null!=n&&!1!==n&&(e.type!==ct||!Array.isArray(n)||0!==n.length)){let t;t=n instanceof Date?n.toISOString():"bigint"==typeof n?n.toString()+"n":e.type===ct&&Array.isArray(n)?ct.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[L];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),Q(this,this);try{j(this,this)}catch(t){console.error(`Error setting up observers for ${this.tagName}:`,t)}const i=t[O];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[a]&&(this[a](),this[a]=null)}},t.prototype.disconnectedCallback=async function(){const e=t[N];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[c]&&Y(this).catch(t=>{console.error("Failed to detach controller:",t)}),R(this),_(this),G(this)},t.prototype.attributeChangedCallback=function(e,n,r){if(o?.call(this,e,n,r),"controller"===e)this.controller=r;else{const n=t[y];if(n)for(const[o,s]of n){if(("string"==typeof s.attribute?s.attribute:o.toLowerCase())===e){const e=this[g]?.[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===ct?ct.parse(r):"number"==typeof e&&null!==r?Number(r):r,e!==n){this[v]||(this[v]=new Set),this[v].add(o),this[g]||(this[g]={}),this[g][o]=n;const r=t[w];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}}}}}function ot(t){return function(e,n){if(n.metadata&&n.metadata[y]){e[y]||(e[y]=new Map);for(const[t,o]of n.metadata[y])e[y].set(t,o)}return nt(e),customElements.define(t,e),e}}function rt(t){return function(e,n){if(n.metadata&&n.metadata[y]){e[y]||(e[y]=new Map);for(const[t,o]of n.metadata[y])e[y].set(t,o)}return nt(e),customElements.define(t,e),e}}function st(t){return function(e,n){const o=n.name;return n.metadata||(n.metadata={}),n.metadata[y]||(n.metadata[y]=new Map),n.metadata[y].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[g]||(this[g]={}),this[g][o]},set(e){this[g]||(this[g]={}),this[v]||(this[v]=new Set);const n=this[g][o];if(n===e)return;const r=void 0===n&&!this[b];if((void 0!==n||r&&null!=e)&&this[v].add(o),this[g][o]=e,t?.reflect&&this.setAttribute&&this[b]&&this[v].has(o)){const n="string"==typeof t.attribute?t.attribute:o.toLowerCase();if(null==e||!1===e||t?.type===ct&&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===ct&&Array.isArray(e)?ct.serialize(e):String(e),this.setAttribute(n,o)}}const s=this.constructor[w];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[g]||(this[g]={}),this[g][o]=e,e}}}function it(t,e={}){return function(n,r){const{light:s=!1,shadow:i=!0}=e,a=r.name;return function(e){if(!Object.hasOwnProperty.call(this.constructor.prototype,a)){const e={get(){const e=!0===this[o]&&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}}}function at(t,e={}){return function(n,r){const{light:s=!1,shadow:i=!0}=e,a=r.name;return function(e){if(!Object.hasOwnProperty.call(this.constructor.prototype,a)){const e={get(){const e=!0===this[o]&&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}}}class ct{static{this.SEPARATOR=","}static serialize(t){return Array.isArray(t)?t.map(t=>{if("string"==typeof t){if(t.includes(ct.SEPARATOR))throw new Error(`SimpleArray strings cannot contain the character "${ct.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(ct.SEPARATOR):""}static parse(t){return null==t||""===t?[]:t.split(ct.SEPARATOR).map(t=>{if(/^-?\d+\.?\d*$/.test(t)){const e=Number(t);if(!isNaN(e))return e}return"true"===t||"false"!==t&&t})}}function lt(...t){return function(e,n){const o=n.name;n.addInitializer(function(){const n=this.constructor;n[w]||(n[w]=new Map);for(const r of t)n[w].has(r)||n[w].set(r,[]),n[w].get(r).push({methodName:o,method:e})})}}function ut(){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[E])return this[E];const t={target:this},e=new CustomEvent("@context/request",{bubbles:!0,cancelable:!0,detail:t});let n=!0===this[o]&&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[E]=t.context,t.context):void 0}},set(){},configurable:!0,enumerable:!0};Object.defineProperty(this.constructor.prototype,n,t)}return t}}}function ht(){return function(t,e){const n=e.name;e.addInitializer(function(){const e=this.constructor;e[O]||(e[O]=[]),e[O].push({methodName:n,method:t})})}}function dt(){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})})}}function pt(t,e={}){return function(n,o){const r=o.name;return o.addInitializer(function(){const e=this.constructor;e[L]||(e[L]=new Map),e[L].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)}}}}
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
- */class pt{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 ft(t){const e={};return t.split(";").forEach(t=>{const[n,o]=t.split(":").map(t=>t.trim());n&&o&&(e[n]=o)}),e}var mt;function yt(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[A]===a)return t}return null}function u(t,i,a,c,l){e.push({route:new pt(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[E]=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[E]=c,n[A]=e,{element:n,needsNewLayout:!0}}return a=null,{element:null,needsNewLayout:!0}}async function g(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[E]=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),y=i||t.transition;return null!==h||null!==l(s)?void await g(s,o,y,h,d):void await b(s,o,y)}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:mt.GUARDS_FAILED};const r=document.createElement(o.tag);r[E]=c;const s=e;return Object.keys(s).forEach(t=>r.setAttribute(t,s[t])),{result:mt.SUCCESS,element:r,transition:o.transition,layout:o.layout}}return{result:mt.NOT_FOUND}}(o,s);if(i.result===mt.GUARDS_FAILED)return;if(i.result===mt.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 g(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[E]=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:y,needsNewLayout:w}=m(d),v=u||t.transition;null!==y||null!==l(s)?await g(s,a,v,y,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?ft(o.out):{opacity:"0"},c={opacity:"0"},l=o.in?ft(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[y]){e[y]||(e[y]=new Map);for(const[t,o]of n.metadata[y])e[y].set(t,o)}et(e),e[T]=t.transition;const o=e.prototype.connectedCallback;e.prototype.connectedCallback=function(){o?.call(this);const t=t=>{void 0!==this[E]&&(t.detail.context=this[E],t.stopPropagation())};this.addEventListener("@context/request",t),this[S]=t};const r=e.prototype.disconnectedCallback;return e.prototype.disconnectedCallback=function(){r?.call(this);const t=this[S];t&&(this.removeEventListener("@context/request",t),delete this[S]),delete this[E]},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}}!function(t){t.SUCCESS="success",t.GUARDS_FAILED="guards-failed",t.NOT_FOUND="not-found"}(mt||(mt={}));export{o as IS_CONTROLLER_INSTANCE,yt as Router,at as SimpleArray,et as applyElementFunctionality,V as attachController,tt as cleanupNativeElementControllers,lt as context,J as controller,X as detachController,R as dispatch,ht as dispose,nt as element,Y as getController,e as getSymbol,ot as layout,D as observe,L as on,dt as part,rt as property,st as query,it as queryAll,ut as ready,G as request,K as respond,Z as useNativeElementControllers,ct as watch};
13
+ */class ft{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 mt(t){const e={};return t.split(";").forEach(t=>{const[n,o]=t.split(":").map(t=>t.trim());n&&o&&(e[n]=o)}),e}var yt;function gt(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[A]===a)return t}return null}function u(t,i,a,c,l){e.push({route:new ft(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[E]=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[E]=c,n[A]=e,{element:n,needsNewLayout:!0}}return a=null,{element:null,needsNewLayout:!0}}async function g(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[E]=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),y=i||t.transition;return null!==h||null!==l(s)?void await g(s,o,y,h,d):void await b(s,o,y)}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:yt.GUARDS_FAILED};const r=document.createElement(o.tag);r[E]=c;const s=e;return Object.keys(s).forEach(t=>r.setAttribute(t,s[t])),{result:yt.SUCCESS,element:r,transition:o.transition,layout:o.layout}}return{result:yt.NOT_FOUND}}(o,s);if(i.result===yt.GUARDS_FAILED)return;if(i.result===yt.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 g(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[E]=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:y,needsNewLayout:w}=m(d),v=u||t.transition;null!==y||null!==l(s)?await g(s,a,v,y,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?mt(o.out):{opacity:"0"},c={opacity:"0"},l=o.in?mt(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[y]){e[y]||(e[y]=new Map);for(const[t,o]of n.metadata[y])e[y].set(t,o)}nt(e),e[T]=t.transition;const o=e.prototype.connectedCallback;e.prototype.connectedCallback=function(){o?.call(this);const t=t=>{void 0!==this[E]&&(t.detail.context=this[E],t.stopPropagation())};this.addEventListener("@context/request",t),this[S]=t};const r=e.prototype.disconnectedCallback;return e.prototype.disconnectedCallback=function(){r?.call(this);const t=this[S];t&&(this.removeEventListener("@context/request",t),delete this[S]),delete this[E]},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}}!function(t){t.SUCCESS="success",t.GUARDS_FAILED="guards-failed",t.NOT_FOUND="not-found"}(yt||(yt={}));export{o as IS_CONTROLLER_INSTANCE,gt as Router,ct as SimpleArray,nt as applyElementFunctionality,X as attachController,et as cleanupNativeElementControllers,ut as context,V as controller,Y as detachController,$ as dispatch,dt as dispose,ot as element,Z as getController,e as getSymbol,rt as layout,M as observe,x as on,pt as part,st as property,it as query,at as queryAll,ht as ready,K as request,W as respond,tt as useNativeElementControllers,lt as watch};
14
14
  //# sourceMappingURL=index.esm.min.js.map