snice 7.2.0 → 7.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/skills/snice/SKILL.md +36 -13
- package/README.md +11 -6
- package/adapters/react/SniceProvider.js +1 -1
- package/adapters/react/SniceRouter.d.ts +2 -0
- package/adapters/react/SniceRouter.js +3 -2
- package/adapters/react/SniceRouter.js.map +1 -1
- package/adapters/react/matchRoute.d.ts +4 -1
- package/adapters/react/matchRoute.js +13 -3
- package/adapters/react/matchRoute.js.map +1 -1
- package/adapters/react/useRequestHandler.js +1 -1
- package/bin/analyzer-contracts.js +4 -1
- package/bin/project-analyzer.js +521 -20
- package/bin/snice.js +77 -13
- package/bin/templates/AI_GUIDANCE.md +6 -1
- package/bin/templates/default/README.md +1 -1
- package/bin/templates/default/src/components/app-header.ts +11 -16
- package/bin/templates/default/src/components/notification-badge.ts +5 -14
- package/bin/templates/default/src/components/search-bar.ts +21 -65
- package/bin/templates/default/src/pages/dashboard.ts +15 -11
- package/bin/templates/default/src/pages/data.ts +10 -13
- package/bin/templates/default/src/pages/notifications.ts +4 -9
- package/bin/templates/default/src/pages/profile.ts +2 -8
- package/bin/templates/default/src/pages/settings.ts +16 -16
- package/dist/app-context.d.ts +10 -10
- package/dist/cdn/accordion/snice-accordion.js +1 -1
- package/dist/cdn/action-bar/snice-action-bar.js +1 -1
- package/dist/cdn/activity-feed/snice-activity-feed.js +1 -1
- package/dist/cdn/alert/snice-alert.js +1 -1
- package/dist/cdn/app-tiles/snice-app-tiles.js +1 -1
- package/dist/cdn/approval-flow/snice-approval-flow.js +1 -1
- package/dist/cdn/audio-recorder/snice-audio-recorder.js +1 -1
- package/dist/cdn/availability/snice-availability.js +1 -1
- package/dist/cdn/avatar/snice-avatar.js +1 -1
- package/dist/cdn/avatar-group/snice-avatar-group.js +1 -1
- package/dist/cdn/badge/snice-badge.js +1 -1
- package/dist/cdn/banner/snice-banner.js +1 -1
- package/dist/cdn/binpack/snice-binpack.js +1 -1
- package/dist/cdn/book/snice-book.js +1 -1
- package/dist/cdn/booking/snice-booking.js +1 -1
- package/dist/cdn/breadcrumbs/snice-breadcrumbs.js +1 -1
- package/dist/cdn/button/snice-button.js +1 -1
- package/dist/cdn/calendar/snice-calendar.js +1 -1
- package/dist/cdn/camera/snice-camera.js +1 -1
- package/dist/cdn/camera-annotate/snice-camera-annotate.js +1 -1
- package/dist/cdn/candlestick/snice-candlestick.js +1 -1
- package/dist/cdn/card/snice-card.js +1 -1
- package/dist/cdn/carousel/snice-carousel.js +1 -1
- package/dist/cdn/cart/snice-cart.js +1 -1
- package/dist/cdn/chart/snice-chart.js +1 -1
- package/dist/cdn/chat/snice-chat.js +1 -1
- package/dist/cdn/checkbox/snice-checkbox.js +1 -1
- package/dist/cdn/chip/snice-chip.js +1 -1
- package/dist/cdn/code-block/snice-code-block.js +1 -1
- package/dist/cdn/color-display/snice-color-display.js +1 -1
- package/dist/cdn/color-picker/snice-color-picker.js +1 -1
- package/dist/cdn/command-palette/snice-command-palette.js +1 -1
- package/dist/cdn/comments/snice-comments.js +1 -1
- package/dist/cdn/countdown/snice-countdown.js +1 -1
- package/dist/cdn/cropper/snice-cropper.js +1 -1
- package/dist/cdn/data-card/snice-data-card.js +1 -1
- package/dist/cdn/date-picker/snice-date-picker.js +1 -1
- package/dist/cdn/date-range-picker/snice-date-range-picker.js +1 -1
- package/dist/cdn/date-time-picker/snice-date-time-picker.js +1 -1
- package/dist/cdn/diff/snice-diff.js +1 -1
- package/dist/cdn/divider/snice-divider.js +1 -1
- package/dist/cdn/doc/snice-doc.js +1 -1
- package/dist/cdn/draw/snice-draw.js +1 -1
- package/dist/cdn/drawer/snice-drawer.js +1 -1
- package/dist/cdn/empty-state/snice-empty-state.js +1 -1
- package/dist/cdn/estimate/snice-estimate.js +1 -1
- package/dist/cdn/file-gallery/snice-file-gallery.js +1 -1
- package/dist/cdn/file-upload/snice-file-upload.js +1 -1
- package/dist/cdn/flip-card/snice-flip-card.js +1 -1
- package/dist/cdn/flow/snice-flow.js +1 -1
- package/dist/cdn/form-layout/snice-form-layout.js +1 -1
- package/dist/cdn/funnel/snice-funnel.js +1 -1
- package/dist/cdn/gantt/snice-gantt.js +1 -1
- package/dist/cdn/gauge/snice-gauge.js +1 -1
- package/dist/cdn/grid/snice-grid.js +1 -1
- package/dist/cdn/heatmap/snice-heatmap.js +1 -1
- package/dist/cdn/image/snice-image.js +1 -1
- package/dist/cdn/input/snice-input.js +1 -1
- package/dist/cdn/invoice/snice-invoice.js +1 -1
- package/dist/cdn/kanban/snice-kanban.js +1 -1
- package/dist/cdn/key-value/snice-key-value.js +1 -1
- package/dist/cdn/kpi/snice-kpi.js +1 -1
- package/dist/cdn/layout/snice-layout.js +1 -1
- package/dist/cdn/leaderboard/snice-leaderboard.js +1 -1
- package/dist/cdn/link/snice-link.js +1 -1
- package/dist/cdn/link-preview/snice-link-preview.js +1 -1
- package/dist/cdn/list/snice-list.js +1 -1
- package/dist/cdn/location/snice-location.js +1 -1
- package/dist/cdn/login/snice-login.js +1 -1
- package/dist/cdn/map/snice-map.js +1 -1
- package/dist/cdn/markdown/snice-markdown.js +1 -1
- package/dist/cdn/masonry/snice-masonry.js +1 -1
- package/dist/cdn/menu/snice-menu.js +1 -1
- package/dist/cdn/message-strip/snice-message-strip.js +1 -1
- package/dist/cdn/modal/snice-modal.js +1 -1
- package/dist/cdn/music-player/snice-music-player.js +1 -1
- package/dist/cdn/nav/snice-nav.js +1 -1
- package/dist/cdn/network-graph/snice-network-graph.js +1 -1
- package/dist/cdn/notification-center/snice-notification-center.js +1 -1
- package/dist/cdn/order-tracker/snice-order-tracker.js +1 -1
- package/dist/cdn/org-chart/snice-org-chart.js +1 -1
- package/dist/cdn/pagination/snice-pagination.js +1 -1
- package/dist/cdn/paint/snice-paint.js +1 -1
- package/dist/cdn/pdf-viewer/snice-pdf-viewer.js +1 -1
- package/dist/cdn/permission-matrix/snice-permission-matrix.js +1 -1
- package/dist/cdn/podcast-player/snice-podcast-player.js +1 -1
- package/dist/cdn/popover/snice-popover.js +1 -1
- package/dist/cdn/pricing-table/snice-pricing-table.js +1 -1
- package/dist/cdn/product-card/snice-product-card.js +1 -1
- package/dist/cdn/progress/snice-progress.js +1 -1
- package/dist/cdn/progress-ring/snice-progress-ring.js +1 -1
- package/dist/cdn/qr-code/snice-qr-code.js +1 -1
- package/dist/cdn/qr-reader/snice-qr-reader.js +1 -1
- package/dist/cdn/radio/snice-radio.js +1 -1
- package/dist/cdn/range-slider/snice-range-slider.js +1 -1
- package/dist/cdn/rating/snice-rating.js +1 -1
- package/dist/cdn/receipt/snice-receipt.js +1 -1
- package/dist/cdn/recipe/snice-recipe.js +1 -1
- package/dist/cdn/runtime/README.md +2 -2
- package/dist/cdn/runtime/snice-runtime.esm.js +333 -192
- package/dist/cdn/runtime/snice-runtime.esm.js.map +1 -1
- package/dist/cdn/runtime/snice-runtime.esm.min.js +1 -1
- package/dist/cdn/runtime/snice-runtime.esm.min.js.map +1 -1
- package/dist/cdn/runtime/snice-runtime.js +333 -191
- package/dist/cdn/runtime/snice-runtime.js.map +1 -1
- package/dist/cdn/runtime/snice-runtime.min.js +1 -1
- package/dist/cdn/runtime/snice-runtime.min.js.map +1 -1
- package/dist/cdn/sankey/snice-sankey.js +1 -1
- package/dist/cdn/segmented-control/snice-segmented-control.js +1 -1
- package/dist/cdn/select/snice-select.js +1 -1
- package/dist/cdn/skeleton/snice-skeleton.js +1 -1
- package/dist/cdn/slider/snice-slider.js +1 -1
- package/dist/cdn/sortable/snice-sortable.js +1 -1
- package/dist/cdn/sparkline/snice-sparkline.js +1 -1
- package/dist/cdn/spinner/snice-spinner.js +1 -1
- package/dist/cdn/split-button/snice-split-button.js +1 -1
- package/dist/cdn/split-pane/snice-split-pane.js +1 -1
- package/dist/cdn/spotlight/snice-spotlight.js +1 -1
- package/dist/cdn/stat-group/snice-stat-group.js +1 -1
- package/dist/cdn/step-input/snice-step-input.js +1 -1
- package/dist/cdn/stepper/snice-stepper.js +1 -1
- package/dist/cdn/switch/snice-switch.js +1 -1
- package/dist/cdn/table/snice-table.esm.js +1 -1
- package/dist/cdn/table/snice-table.js +1 -1
- package/dist/cdn/tabs/snice-tabs.js +1 -1
- package/dist/cdn/tag/snice-tag.js +1 -1
- package/dist/cdn/tag-input/snice-tag-input.js +1 -1
- package/dist/cdn/terminal/snice-terminal.js +1 -1
- package/dist/cdn/testimonial/snice-testimonial.js +1 -1
- package/dist/cdn/textarea/snice-textarea.js +1 -1
- package/dist/cdn/time-picker/snice-time-picker.js +1 -1
- package/dist/cdn/time-range-picker/snice-time-range-picker.js +1 -1
- package/dist/cdn/timeline/snice-timeline.js +1 -1
- package/dist/cdn/timer/snice-timer.js +1 -1
- package/dist/cdn/toast/snice-toast.js +1 -1
- package/dist/cdn/tooltip/snice-tooltip.js +1 -1
- package/dist/cdn/tree/snice-tree.js +1 -1
- package/dist/cdn/treemap/snice-treemap.js +1 -1
- package/dist/cdn/user-card/snice-user-card.js +1 -1
- package/dist/cdn/video-player/snice-video-player.js +1 -1
- package/dist/cdn/virtual-scroller/snice-virtual-scroller.js +1 -1
- package/dist/cdn/waterfall/snice-waterfall.js +1 -1
- package/dist/cdn/weather/snice-weather.js +1 -1
- package/dist/cdn/work-order/snice-work-order.js +1 -1
- package/dist/components/pagination/snice-pagination.types.d.ts +5 -0
- package/dist/context-provider.d.ts +11 -1
- package/dist/context.d.ts +5 -6
- package/dist/index.cjs +330 -188
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.esm.js +330 -189
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +330 -188
- package/dist/index.iife.js.map +1 -1
- package/dist/react/SniceProvider.js +1 -1
- package/dist/react/SniceRouter.d.ts +2 -0
- package/dist/react/SniceRouter.js +3 -2
- package/dist/react/SniceRouter.js.map +1 -1
- package/dist/react/index.js +1 -1
- package/dist/react/matchRoute.d.ts +4 -1
- package/dist/react/matchRoute.js +13 -3
- package/dist/react/matchRoute.js.map +1 -1
- package/dist/react/useRequestHandler.js +1 -1
- package/dist/symbols.cjs +1 -1
- package/dist/symbols.esm.js +1 -1
- package/dist/testing-dom.cjs +48 -0
- package/dist/testing-dom.cjs.map +1 -0
- package/dist/testing-dom.d.ts +23 -0
- package/dist/testing-dom.esm.js +45 -0
- package/dist/testing-dom.esm.js.map +1 -0
- package/dist/transitions.cjs +1 -1
- package/dist/transitions.esm.js +1 -1
- package/dist/types/context.d.ts +8 -8
- package/dist/types/page-options.d.ts +15 -1
- package/dist/types/router-instance.d.ts +2 -1
- package/dist/utils.d.ts +3 -1
- package/docs/ai/README.md +6 -4
- package/docs/ai/api.md +13 -2
- package/docs/ai/architecture.md +28 -11
- package/docs/ai/bindings.md +1 -1
- package/docs/ai/cli.md +26 -1
- package/docs/ai/components/badge.md +4 -0
- package/docs/ai/components/pagination.md +4 -2
- package/docs/ai/components/segmented-control.md +5 -1
- package/docs/ai/controllers.md +41 -12
- package/docs/ai/decorators.md +3 -3
- package/docs/ai/events.md +8 -2
- package/docs/ai/fetcher.md +32 -1
- package/docs/ai/lifecycle.md +4 -1
- package/docs/ai/patterns.md +9 -4
- package/docs/ai/react-integration.md +1 -0
- package/docs/ai/request-response.md +20 -6
- package/docs/ai/routing.md +33 -4
- package/docs/ai/testing.md +71 -0
- package/docs/bindings.md +1 -1
- package/docs/cli.md +27 -2
- package/docs/components/badge.md +4 -0
- package/docs/components/pagination.md +8 -5
- package/docs/components/segmented-control.md +5 -1
- package/docs/controllers.md +46 -15
- package/docs/events.md +11 -2
- package/docs/fetcher.md +32 -1
- package/docs/lifecycle.md +5 -1
- package/docs/react-integration.md +1 -0
- package/docs/request-response.md +25 -7
- package/docs/routing.md +39 -3
- package/docs/testing.md +71 -0
- package/package.json +6 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
globalThis.snice||(globalThis.snice={controllerRegistry:new Map,pendingControllerAttachments:new Map,controllerIdCounter:0}),globalThis.snice.pendingControllerAttachments??=new Map;const e=globalThis.snice;function t(e){return Symbol.for(`snice:${e}`)}const n=t("is-controller-class"),o=t("is-controller-instance"),r=t("is-daemon-class"),s=t("is-daemon-instance"),i=t("is-element-class"),a=t("channel-handlers"),c=t("daemon-state"),l=t("ready-promise"),h=t("ready-resolve"),u=t("ready-reject"),d=t("ready-handlers-running"),f=t("rendered-promise"),m=t("rendered-resolve"),p=t("pending-reconnect-render"),y=t("render-depth"),g=t("render-root"),b=t("element-options"),v=t("controller"),w=t("initialized"),E=t("controller-key"),N=t("controller-name"),A=t("controller-id"),S=t("controller-operations"),T=t("native-controller"),_=t("controller-registry-name"),x=t("direct-controller"),C=t("controller-attribute-sync"),O=t("pending-controller-binding"),$=t("cleanup"),k=t("properties"),L=t("property-values"),P=t("property-defaults"),j=t("property-wrappers"),M=t("pre-init-property-values"),R=t("pre-upgrade-property-bindings"),I=t("properties-initialized"),D=t("property-watchers"),V=t("explicitly-set-properties"),q=t("router-context"),B=t("page-transition"),F=t("created-at"),W=t("ready-handlers"),z=t("dispose-handlers"),U=t("reconnect-handlers"),H=t("moved-handlers"),K=t("adopted-handlers"),G=t("observers"),Q=t("setting-from-property"),J=t("moved-timers"),X=t("adopted-timers"),Y=t("dispatch-timers"),Z=t("render-method"),ee=t("render-options"),te=t("render-instance"),ne=t("render-timers"),oe=t("render-callbacks"),re=t("styles-method"),se=t("styles-applied"),ie=t("parent-styles-methods"),ae=t("snice-element-base"),ce=t("context-handler"),le=t("navigation-context-instance"),he=t("registered-elements"),ue=t("is-updating"),de=t("context-register"),fe=t("context-unregister"),me=t("context-notify-element"),pe=t("context-timer"),ye=t("context-called"),ge=t("context-update"),be=t("context-methods"),ve=t("watch-methods"),we=t("observe-methods"),Ee=t("on-methods"),Ne=t("respond-methods"),Ae=t("ready-methods"),Se=t("dispose-methods"),Te=t("reconnect-methods"),_e=t("moved-methods"),xe=t("adopted-methods"),Ce=t("controller-abort"),Oe=t("controller-attached"),$e=t("property-definers");class ke{static{this.SEPARATOR=","}static serialize(e){return Array.isArray(e)?e.map(e=>{if("string"==typeof e){if(e.includes(ke.SEPARATOR))throw new Error(`SimpleArray strings cannot contain the character "${ke.SEPARATOR}" (U+FF0C)`);return e}if("number"==typeof e||"boolean"==typeof e)return String(e);throw new Error("SimpleArray only supports string, number, and boolean types. Got: "+typeof e)}).join(ke.SEPARATOR):""}static parse(e){return null==e||""===e?[]:e.split(ke.SEPARATOR).map(e=>{if(/^-?\d+\.?\d*$/.test(e)){const t=Number(e);if(!isNaN(t))return t}return"true"===e||"false"!==e&&e})}}var Le,Pe,je,Me;!function(e){e.SEQUENTIAL="sequential",e.SIMULTANEOUS="simultaneous"}(Le||(Le={}));const Re=Symbol.for("snice:registered-elements-set");let Ie=0;class De{constructor(e={},t=[],n="",o={},r){if(this[Pe]=new WeakMap,this[je]=new Set,this[Me]=!1,this.id=Ie++,this.application=e,this.navigation={placards:t,route:n,params:o},r&&"function"==typeof r.create)this.fetch=r.create(this);else{if("function"!=typeof fetch)throw new Error("No fetch implementation available");this.fetch=fetch.bind(this)}}[(Pe=he,je=Re,Me=ue,de)](e,t){const n=this[he];let o=n.get(e);o||(o=new Set,n.set(e,o)),o.add(t),this[Re].add(e)}[fe](e,t){const n=this[he];if(void 0!==t){const o=n.get(e);if(!o)return;if(o.delete(t),o.size>0)return}n.delete(e),this[Re].delete(e)}[ge](e,t,n,o){this.application=e,this.navigation.placards=t,this.navigation.route=n,this.navigation.params=o,this.notify()}update(){this.notify()}notify(){if(this[ue])return;this[ue]=!0;const e=this[Re],t=this[he];for(const n of e){const e=t.get(n);if(e)for(const t of e)if("function"==typeof n[t])try{n[t](this)}catch(e){console.error(`Error calling @context method ${t}:`,e)}}this[ue]=!1}[me](e){const t=this[he].get(e);if(t)for(const n of t)"function"==typeof e[n]&&e[n](this)}}function Ve(e){if(null!=e)return"string"==typeof e?String:"number"==typeof e?Number:"boolean"==typeof e?Boolean:e instanceof Date?Date:"bigint"==typeof e?BigInt:Array.isArray(e)?Array:void 0}function qe(e,t,n,o){const r=t.type||Ve(o);if(t.converter?.fromAttribute)return t.converter.fromAttribute(e,r);switch(r){case Boolean:return null!==e&&"false"!==e;case Number:return null!==e?Number(e):null;case String:return e;case Date:return e?new Date(e):null;case BigInt:return e&&e.endsWith("n")?BigInt(e.slice(0,-1)):e?BigInt(e):null;case ke:return ke.parse(e);case Array:try{return e?JSON.parse(e):[]}catch{return[]}case Object:try{return e?JSON.parse(e):{}}catch{return{}}default:return"number"==typeof n&&null!==e?Number(e):e}}function Be(e,t){return e!==t&&(e==e||t==t)}function Fe(e,t){return"string"==typeof e.attribute?e.attribute.toLowerCase():!0===e.attribute||"kebab"===e.attributeNaming?t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase():t.toLowerCase()}function We(e){return String(e??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function ze(e){return String(e??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function Ue(e,t={}){let n;try{n=String(e??"")}catch{return!1}if(!n||/[\u0000-\u001f\u007f]/.test(n))return!1;const o=n.trim();if(!o)return!1;const r=t.allowed??["http:","https:","mailto:","tel:"];try{const e=new URL(o,"http://__snice-relative.invalid/"),t=/^[a-z][a-z\d+.-]*:/i.test(o),n=/^[\\/]{2}/.test(o);return!t&&!n||r.some(t=>"string"==typeof t&&t.toLowerCase()===e.protocol)}catch{return!1}}function He(e){const t=String(e).trim(),n=parseFloat(t);let o;return o=isNaN(n)?0:/ms$/i.test(t)?n:/s$/i.test(t)?1e3*n:/m$/i.test(t)?6e4*n:/h$/i.test(t)?36e5*n:n,{milliseconds:()=>o,seconds:()=>o/1e3,minutes:()=>o/6e4}}function Ke(e,t){return e[t]||(e[t]=new Set),e[t]}function Ge(e,t){return e[t]||(e[t]={}),e[t]}function Qe(e,t,n,o,r){const s=t[D];if(!s)return;const i=[n],a=t[k]?.get(n),c=a&&"string"==typeof a.attribute?a.attribute:null;c&&c!==n&&i.push(c);for(const t of i)if(s.has(t))for(const i of s.get(t))try{i.method.call(e,o,r,n)}catch(e){console.error(`Error in @watch('${t}') method ${i.methodName}:`,e)}if(s.has("*"))for(const t of s.get("*"))try{t.method.call(e,o,r,n)}catch(e){console.error(`Error in @watch('*') method ${t.methodName}:`,e)}}function Je(e,t){let n=null;return function(...o){null!==n&&clearTimeout(n),n=setTimeout(()=>{e.apply(this,o),n=null},t)}}function Xe(e,t){let n=0,o=null;return function(...r){const s=Date.now(),i=t-(s-n);if(i<=0)return o&&(clearTimeout(o),o=null),n=s,e.apply(this,r);o||(o=setTimeout(()=>{n=Date.now(),o=null,e.apply(this,r)},i))}}function Ye(e,t){if(null==t)return e;if("global"===t)return"undefined"!=typeof document?document:null;if("function"==typeof t)try{return t.call(e)||null}catch{return null}return"string"==typeof t?e.closest?.(t)||null:t&&"function"==typeof t.addEventListener?t:null}function Ze(e,t,n){if(null==e||!1===e||t?.type===ke&&Array.isArray(e)&&0===e.length)return null;if(t.converter?.toAttribute)return t.converter.toAttribute(e,t.type);switch(t.type||Ve(n)){case Boolean:return"true";case Date:return e instanceof Date?e.toISOString():String(e);case BigInt:return"bigint"==typeof e?e.toString()+"n":String(e);case ke:return Array.isArray(e)?ke.serialize(e):String(e);case Array:return Array.isArray(e)?JSON.stringify(e):String(e);case Object:return"object"==typeof e&&null!==e?JSON.stringify(e):String(e);default:return String(e)}}const et=new WeakSet,tt=new Map;function nt(e,t,n){let o,r;return"string"==typeof t?(o=t,r=n):(o=void 0,r=t),function(t,n){const s=n.name;n.addInitializer(function(){const n=this.constructor;if(Object.prototype.hasOwnProperty.call(n,we)||(n[we]=new Set),n[we].has(t))return;if(n[we].add(t),!Object.prototype.hasOwnProperty.call(n,G)){const e=n[G];n[G]=e?[...e]:[]}const i=Array.isArray(e)?e:[e];for(const e of i){const[i,...a]=e.split(":"),c=a.join(":");n[G].push({type:i,target:c,selector:o,methodName:s,method:t,options:r})}})}}function ot(e,t){const n=e.constructor[G];if(n&&Array.isArray(n)&&0!==n.length){e[$]?e[$].observers||(e[$].observers=[]):e[$]={events:[],channels:[],observers:[]};for(const o of n){const n=o.method.bind(e),r=o.options?.throttle?Xe(n,o.options.throttle):n;switch(o.type){case"intersection":rt(e,t,o,r);break;case"resize":st(e,t,o,r);break;case"media":it(e,0,o,r);break;case"mutation":at(e,t,o,r);break;default:console.warn(`Unknown observer type: ${o.type}`)}}}}function rt(e,t,n,o){const r={threshold:n.options?.threshold??0,rootMargin:n.options?.rootMargin??"0px",root:n.options?.root??null};if("undefined"==typeof IntersectionObserver)return void console.warn("IntersectionObserver is not available in this environment");const s=new IntersectionObserver(e=>{for(const t of e)try{!1===o(t)&&s&&s.unobserve(t.target)}catch(e){console.error(`Error in intersection observer ${n.methodName}:`,e)}},r),i=n.selector?Array.from(t.shadowRoot?.querySelectorAll(n.selector)||[]):[t];i.forEach(e=>s.observe(e)),e[$].observers.push(()=>{i.forEach(e=>s.unobserve(e)),0===s.takeRecords().length&&s.disconnect()})}function st(e,t,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(e=>{for(const t of e)try{o(t)}catch(e){console.error(`Error in resize observer ${n.methodName}:`,e)}});(n.selector?Array.from(t.shadowRoot?.querySelectorAll(n.selector)||[]):[t]).forEach(e=>{s.observe(e,{box:r})}),e[$].observers.push(()=>{s.disconnect()})}function it(e,t,n,o){const r=n.target;if(!r)return void console.warn("Media query observer requires a query string");let s=tt.get(r);if(!s)try{s=window.matchMedia(r),tt.set(r,s)}catch(e){return void console.error(`Invalid media query: ${r}`,e)}const i=e=>{try{o(e.matches)}catch(e){console.error(`Error in media query observer ${n.methodName}:`,e)}};i(s);const a=e=>i(e);s.addEventListener?(s.addEventListener("change",a),e[$].observers.push(()=>{s.removeEventListener("change",a)})):(s.addListener(a),e[$].observers.push(()=>{s.removeListener(a)}))}function at(e,t,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(/^[.#[]/.test(i)?console.warn(`@observe: "mutation:${i}" — "${i}" looks like a selector. Selectors are the second argument — did you mean @observe('mutation:childList', '${i}')?`):console.warn(`Unknown mutation type: ${i} (expected childList or attributes)`))}n.options?.subtree&&(c.subtree=!0,n.options.maxDepth&&console.warn("maxDepth is set but requires custom implementation"));const l=!(!n.options?.maxDepth||!n.options.subtree),h=new MutationObserver(e=>{try{if(!l)return void r(e);const o=n.options.maxDepth,s=t.shadowRoot||t,i=e.filter(e=>{let t=0,n=e.target;for(;n&&n!==s&&t<o;)n=n.parentNode,t++;return t<o});i.length>0&&r(i)}catch(e){console.error(`Error in mutation observer ${n.methodName}:`,e)}}),u=!0===e[o];(n.selector?Array.from(t.shadowRoot?.querySelectorAll(n.selector)||[]):u&&t.shadowRoot?[t.shadowRoot]:[t]).forEach(e=>{h.observe(e,c)}),e[$].observers.push(()=>{h.disconnect()})}function ct(e){if(e[$]?.observers){for(const t of e[$].observers)t();e[$].observers=[]}}const lt="@context/request",ht=new WeakMap;function ut(e){if(!e||"object"!=typeof e&&"function"!=typeof e)return;const t=function(e){return!e||"object"!=typeof e&&"function"!=typeof e?null:!0===e[o]?e.element&&"function"==typeof e.element.dispatchEvent?e.element:null:"function"==typeof e.dispatchEvent?e:null}(e);if(t){const e={};if(t.dispatchEvent(new CustomEvent(lt,{bubbles:!0,composed:!0,cancelable:!0,detail:e})),void 0!==e.context)return e.context}const n=e;return void 0!==n[q]?n[q]:!0===n[o]&&void 0!==n.element?.[q]?n.element[q]:void 0}function dt(e){return!!e&&("object"==typeof e||"function"==typeof e)&&!0===e[r]}function ft(e){if(!dt(e))throw new TypeError("Application contexts may provide only instances of @daemon classes.");let t=e[c];if(!t){t={target:new EventTarget,bindings:0,active:!1};try{Object.defineProperty(e,c,{value:t,configurable:!0}),Object.defineProperty(e,s,{value:!0,configurable:!0})}catch{throw new TypeError("@daemon instances must remain extensible until they are provided to an app context.")}}return t}function mt(e,t){if("string"!=typeof t||!t.trim())throw new TypeError("Daemon addresses must be non-empty strings.");const n=ut(e);if(!n)throw new Error(`[snice] ${function(e){const t=e;return!0===t?.[o]?"controller":dt(t)?"@daemon instance":"element"}(e)} cannot resolve daemon "${t}" because no app context is provided.`);const r=n.daemons?.[t];if(!r)throw new Error(`[snice] app context does not provide daemon "${t}".`);if(!dt(r))throw new TypeError(`[snice] app context entry "${t}" is not an instance of an @daemon class.`);const s=ft(r);if(!s.active)throw new Error(`[snice] daemon "${t}" is not active because its app context has not been provided.`);return s.target}function pt(e){return dt(e)?function(e){return ft(e).target}(e):!0===e?.[o]?e.element&&"function"==typeof e.element.dispatchEvent?e.element:null:e&&"function"==typeof e.dispatchEvent?e:null}function yt(e,t){return function(n,o){let r,s,i=0;const a=[];return async function(...o){const c=async()=>{const r=t?.timeout??12e4,s=t?.discoveryTimeout??50,i=void 0!==t?.daemon?mt(this,t.daemon):pt(this);if(!i)throw new TypeError(`@request('${e}') requires an element, attached controller, or provided @daemon instance.`);const a=n.apply(this,o),{value:c,done:l}=await a.next();if(l)return c;let h,u;const d=new Promise((e,t)=>{h=e,u=t});let f,m,p,y=!1;const g=new Promise((t,n)=>{f=t,m=n,p=setTimeout(()=>{n(new Error(`Request "${e}" found no @respond('${e}') handler within ${s}ms — attach a responding controller/element, or pass { optional: true } to resolve undefined when unhandled.`))},s)}),b=new CustomEvent(`@request/${e}`,{bubbles:void 0===t?.bubbles||t.bubbles,cancelable:t?.cancelable||!1,composed:!0,detail:{payload:c,discovery:{resolve:()=>{y=!0,clearTimeout(p),f()},reject:m},data:{resolve:h,reject:u}}});i.dispatchEvent(b);try{await g;const t=setTimeout(()=>{u(new Error(`Request "${e}" timed out after ${r}ms`))},r),n=await d;clearTimeout(t);const{value:o}=await a.next(n);return o}catch(e){if(t?.optional&&!y){const{value:e}=await a.next(void 0);return e}const{value:n}=await a.throw(e);return n}};if(t?.debounce)return new Promise((e,n)=>{clearTimeout(r),r=setTimeout(async()=>{try{e(await c())}catch(e){n(e)}},t.debounce)});if(!t?.throttle)return c();const l=Date.now(),h=t.throttle-(l-i);if(h<=0){clearTimeout(s),s=null,i=l;const e=a.splice(0),t=c();return e.length&&t.then(t=>{for(const n of e)n.resolve(t)},t=>{for(const n of e)n.reject(t)}),t}return new Promise(s?(e,t)=>{a.push({resolve:e,reject:t})}:(e,t)=>{a.push({resolve:e,reject:t}),s=setTimeout(async()=>{i=Date.now(),s=null;const e=a.splice(0);try{const t=await c();for(const n of e)n.resolve(t)}catch(t){for(const n of e)n.reject(t)}},h)})}}}function gt(e,t){return function(n,o){const r=o.name;o.addInitializer(function(){const o=this.constructor;if(Object.prototype.hasOwnProperty.call(o,Ne)||(o[Ne]=new Set),!o[Ne].has(n)){if(o[Ne].add(n),!Object.prototype.hasOwnProperty.call(o,a)){const e=o[a];o[a]=e?[...e]:[]}o[a].push({channelName:e,methodName:r,method:n,options:t})}})}}function bt(e,t){const n=e.constructor[a];if(n){e[$]||(e[$]={events:[],channels:[]});for(const o of n){const n=o.method.bind(e),r=`@request/${o.channelName}`;let s,i,a=0;const c=[];let l=null;const h=(e=>o.options?.debounce?(...t)=>new Promise((n,r)=>{clearTimeout(s),s=setTimeout(async()=>{try{n(await e(...t))}catch(e){r(e)}},o.options.debounce)}):o.options?.throttle?(...t)=>{const n=Date.now(),r=o.options.throttle-(n-a);if(r<=0){clearTimeout(i),i=null,a=n;const o=c.splice(0);l=null;const r=e(...t);return o.length&&Promise.resolve(r).then(e=>{for(const t of o)t.resolve(e)},e=>{for(const t of o)t.reject(e)}),r}return l=t,new Promise((n,o)=>{c.push({resolve:n,reject:o}),i||(i=setTimeout(async()=>{a=Date.now(),i=null;const n=c.splice(0),o=l??t;l=null;try{const t=await e(...o);for(const e of n)e.resolve(t)}catch(e){for(const t of n)t.reject(e)}},r))})}:e)(n),u=e=>{const{data:t,discovery:n,payload:r}=e.detail;e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation(),n.resolve(),Promise.resolve(h(r)).then(e=>{t.resolve(e)}).catch(e=>{t.reject(e),console.error(`Error in response handler ${o.methodName}:`,e)})};let d=t;if(void 0!==o.options?.daemon)try{d=mt(e,o.options.daemon)}catch(e){console.warn(`[snice/@respond] ${e.message} Responder "${o.channelName}" skipped.`);continue}d.addEventListener(r,u),e[$].channels.push(()=>{d.removeEventListener(r,u)})}}}function vt(e){if(e[$]?.channels){for(const t of e[$].channels)t();e[$].channels=[]}}const wt=new Set(["once","prevent","preventdefault","stop","stoppropagation","capture","passive"]);function Et(e){const t=e.lastIndexOf(".");if(t<0)return;const n=e.slice(t+1).toLowerCase();wt.has(n)&&console.warn(`snice: "@${e}" is not a valid modifier — once/preventDefault/stopPropagation/capture are @on() options, not template modifiers. This registers a listener for event "${e}", which never fires.`)}function Nt(e){const t=e.startsWith("~");t&&(e=e.substring(1));const n=e.split("+"),o={key:"",anyModifiers:t};for(const e of n){const t=e.toLowerCase();"ctrl"===t||"control"===t?o.ctrl=!0:"alt"===t?o.alt=!0:"shift"===t?o.shift=!0:"meta"===t||"cmd"===t||"command"===t?o.meta=!0:o.key=At(e)}return o}function At(e){return{esc:"Escape",escape:"Escape",enter:"Enter",return:"Enter",space:" ",spacebar:" ",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight",arrowup:"ArrowUp",arrowdown:"ArrowDown",arrowleft:"ArrowLeft",arrowright:"ArrowRight",delete:"Delete",del:"Delete",backspace:"Backspace",tab:"Tab",home:"Home",end:"End",pageup:"PageUp",pagedown:"PageDown"}[e.toLowerCase()]||e}function St(e,t){return e.key===t.key&&(!!t.anyModifiers||(t.ctrl?e.ctrlKey:!e.ctrlKey)&&(t.alt?e.altKey:!e.altKey)&&(t.shift?e.shiftKey:!e.shiftKey)&&(t.meta?e.metaKey:!e.metaKey))}const Tt=t("on-handlers");function _t(e,t,n){let o=null,r={};return"string"==typeof t?(o=t,r=n||{}):t&&"object"==typeof t?r=t:null===t&&n&&(r=n),function(t,n){const s=n.name;return n.addInitializer(function(){const n=this.constructor,i=Array.isArray(e)?e:[e],a=`${s}::${i.join(",")}::${o??""}::daemon:${r.daemon??""}`;if(Object.prototype.hasOwnProperty.call(n,Ee)||(n[Ee]=new Set),!n[Ee].has(a)){if(n[Ee].add(a),!Object.prototype.hasOwnProperty.call(n,Tt)){const e=n[Tt];n[Tt]=e?[...e]:[]}for(const e of i)n[Tt].push({eventName:e,selector:o,methodName:s,method:t,options:r})}}),t}}function xt(e,t){let n=0;return function(...o){const r=Date.now();r-n>=t&&(n=r,e.apply(this,o))}}const Ct=new Set(["scroll","focus","blur","load","unload","error","resize","abort","mouseenter","mouseleave","pointerenter","pointerleave"]);function Ot(e,t){const n=e.constructor[Tt];if(n&&Array.isArray(n)&&0!==n.length){e[$]?e[$].events?e[$].events.length>0&&$t(e):e[$].events=[]:e[$]={events:[],channels:[],observers:[]};for(const o of n){const n=e[o.methodName];let r=n?n.bind(e):o.method.bind(e);const s=o.options||{},i=["keydown","keyup","keypress"].includes(o.eventName.split(".")[0].split(":")[0]),a=i?o.eventName.indexOf("."):-1,c=i?o.eventName.indexOf(":"):-1,l=a>0&&c>0?Math.min(a,c):Math.max(a,c),h=l>0?o.eventName.substring(0,l):o.eventName,u=l>0?o.eventName.substring(l+1):null;l<=0&&Et(o.eventName),s.debounce&&s.debounce>0?r=Je(r,s.debounce):s.throttle&&s.throttle>0&&(r=xt(r,s.throttle));let d=null;u&&["keydown","keyup","keypress"].includes(h)&&(d=Nt(u));const f=(e=>d?t=>{St(t,d)&&e(t)}:e)(r),m=void 0!==s.scope,p=void 0!==s.daemon;if(m&&p){console.warn(`[snice/@on] "${o.eventName}" cannot use both scope and daemon — listener skipped.`);continue}if((p||dt(e))&&o.selector){console.warn(`[snice/@on] "${o.eventName}" cannot delegate "${o.selector}" on a daemon target — listener skipped.`);continue}const y=m||p;let g=null;if(p)try{g=mt(e,s.daemon)}catch(e){console.warn(`[snice/@on] ${e.message} Listener "${o.eventName}" skipped.`);continue}else if(m&&(g=Ye(t,s.scope),!g)){console.warn(`[snice/@on] scope did not resolve for "${o.eventName}" on ${o.methodName} — listener skipped.`);continue}if(o.selector){const n=y?g:t.shadowRoot||t,r=e=>{const t=e.target;if(t.matches&&t.matches(o.selector)&&t||t.closest&&t.closest(o.selector)){s.preventDefault&&e.preventDefault(),s.stopPropagation&&(e.stopPropagation(),e.stopImmediatePropagation());try{f(e)}catch(e){console.error(`Error in event handler ${o.methodName}:`,e)}}},i=Ct.has(h),a={capture:void 0!==s.capture?s.capture:i,once:s.once||!1,passive:s.passive||!1};n.addEventListener(h,r,a),e[$].events.push({target:n,eventName:h,handler:r,options:a})}else{const n=y?null:t.shadowRoot,r=Symbol(),i=e=>{if(!e[r]){e[r]=!0,s.preventDefault&&e.preventDefault(),s.stopPropagation&&e.stopPropagation();try{f(e)}catch(e){console.error(`Error in event handler ${o.methodName}:`,e)}}},a={capture:s.capture||!1,once:s.once||!1,passive:s.passive||!1};if(y){g.addEventListener(h,i,a),e[$].events.push({target:g,eventName:h,handler:i,options:a});continue}n&&(n.addEventListener(h,i,a),e[$].events.push({target:n,eventName:h,handler:i,options:a})),t.addEventListener(h,i,a),e[$].events.push({target:t,eventName:h,handler:i,options:a})}}}}function $t(e){if(e[$]?.events){for(const{target:t,eventName:n,handler:o,options:r}of e[$].events)t.removeEventListener(n,o,r);e[$].events=[]}}class kt{constructor(){this.cleanupFns=new Map,this.pendingOperations=new Set}register(e,t){this.cleanupFns.set(e,t)}unregister(e){this.cleanupFns.delete(e)}async cleanup(){await Promise.all(this.pendingOperations);for(const e of this.cleanupFns.values())try{await e()}catch(e){console.error("Error during cleanup:",e)}this.cleanupFns.clear()}async runOperation(e){const t=e(),n=t.then(()=>{},()=>{});this.pendingOperations.add(n);try{const e=await t;return this.pendingOperations.delete(n),e}catch(e){throw this.pendingOperations.delete(n),e}}}function Lt(t){return function(o,r){const s=globalThis.snice?.controllerRegistry;if(!s)throw new Error("Snice global registry not initialized");s.set(t,o),o.prototype[n]=!0,Object.defineProperty(o,_,{value:t,configurable:!0});const i=e.pendingControllerAttachments.get(t);return i&&(e.pendingControllerAttachments.delete(t),queueMicrotask(()=>{for(const e of i){const n=e[T];(void 0===n?e[v]:n)===t&&It(e,t).catch(e=>{"ControllerAttachAborted"!==e?.name&&console.error(`Failed to attach controller "${t}":`,e)})}})),o}}function Pt(t,n){if(e.controllerRegistry.has(n))return void queueMicrotask(()=>{const e=t[T];(void 0===e?t[v]:e)===n&&It(t,n).catch(e=>{"ControllerAttachAborted"!==e?.name&&console.error(`Failed to attach controller "${n}":`,e)})});let o=e.pendingControllerAttachments.get(n);o||(o=new Set,e.pendingControllerAttachments.set(n,o)),o.add(t),queueMicrotask(()=>{e.pendingControllerAttachments.get(n)?.has(t)&&console.error(`Failed to attach controller "${n}":`,new Error(`Controller "${n}" not found in registry`))})}function jt(e){return"string"==typeof e?e:e?.name||"(anonymous controller class)"}function Mt(e,t){if(null===t){if(!e.hasAttribute("controller"))return}else if(e.getAttribute("controller")===t)return;e[C]=!0;try{null===t?e.removeAttribute("controller"):e.setAttribute("controller",t)}finally{delete e[C]}}function Rt(e){if(!e[x])return!1;const t=e[N];return"function"==typeof t&&(Mt(e,function(e){const t=Object.prototype.hasOwnProperty.call(e,_)?e[_]:void 0;return"string"==typeof t?t:jt(e)}(t)),!0)}async function It(t,r){if("string"!=typeof r){if("function"!=typeof r)throw new Error(`attachController: expected a controller name or a controller class, got ${typeof r}. Controller instances are not supported — pass the class itself.`);if("function"!=typeof(s=r)||!0!==s.prototype?.[n])throw new Error(`Controller class "${jt(r)}" must be decorated with @controller('name') before it can be attached.`)}var s;const i=jt(r),a=t[E],c=t[T];if("string"==typeof r&&void 0!==c&&c!==r)return;if(t[N]===r&&a)return void("string"!=typeof r&&Rt(t));if(a&&(await Dt(t),t[E]&&t[N]===r))return void("string"!=typeof r&&Rt(t));let l;if("string"==typeof r){const e=globalThis.snice?.controllerRegistry;if(!e)throw new Error("Snice global registry not initialized");if(l=e.get(r),!l)throw new Error(`Controller "${r}" not found in registry`)}else l=r;const h=new l;"string"!=typeof r&&(t[x]=!0,delete t[T]),e.controllerIdCounter+=1;const u=e.controllerIdCounter,f=new kt;h[o]=!0,h[A]=u,h.element=t;const m=t[q];if(void 0!==m&&(h[q]=m),t[E]=h,t[N]=r,t[S]=f,"string"!=typeof r&&Rt(t),!t[d]){const e=new AbortController;t[Ce]=e;const n=3e4;try{await Promise.race([t.ready,new Promise((t,o)=>{const r=()=>{const e=new Error(`attachController("${i}"): aborted before element was ready (likely detached or never connected)`);e.name="ControllerAttachAborted",o(e)};if(e.signal.aborted)return r();e.signal.addEventListener("abort",r,{once:!0});const s=setTimeout(()=>o(new Error(`attachController("${i}"): element did not become ready within ${n}ms (did you forget to appendChild it?)`)),n);e.signal.addEventListener("abort",()=>clearTimeout(s),{once:!0})})])}catch(e){throw t[E]===h&&("string"!=typeof r&&Mt(t,null),delete t[E],delete t[N],delete t[S],"string"!=typeof r&&delete t[x]),e}finally{t[Ce]===e&&delete t[Ce]}}h[Oe]=!0,await f.runOperation(async()=>{await h.attach(t)}),ot(h,t),bt(h,t),Ot(h,t),t.dispatchEvent(new CustomEvent("controller-attached",{detail:{name:i,controller:h}}))}async function Dt(e){const t=e[Ce];t&&t.abort();const n=e[E],o=e[N],r=e[S];n&&("function"==typeof o&&Mt(e,null),delete e[E],delete e[N],delete e[S],"function"==typeof o&&delete e[x],n[Oe]&&(r?await r.runOperation(async()=>{await n.detach(e)}):await n.detach(e),n.element=null,ct(n),vt(n),$t(n),r&&await r.cleanup(),delete n[q],e.dispatchEvent(new CustomEvent("controller-detached",{detail:{name:void 0===o?void 0:jt(o),controller:n}}))))}function Vt(e){return e[E]}function qt(){if(globalThis.sniceNativeControllersInitialized)return;function e(e){if(!(e instanceof HTMLElement))return;if(!e.tagName||e.tagName.includes("-"))return;if(e[i])return;if(e[x])return void Rt(e);const t=e.getAttribute("controller"),n=e[T];if(t!==n&&(t||void 0!==n)){if(!t)return delete e[T],delete e[N],void Dt(e).catch(e=>{console.error("Failed to detach controller from native element:",e)});e[T]=t,e.ready||(e.ready=Promise.resolve()),n&&Dt(e).catch(e=>{console.error("Failed to detach old controller from native element:",e)}),It(e,t).catch(n=>{"ControllerAttachAborted"!==n?.name?n?.message!==`Controller "${t}" not found in registry`?console.error(`Failed to attach controller "${t}" to native element:`,n):Pt(e,t):console.debug(`Controller "${t}" attach aborted (element detached before ready)`)})}}globalThis.sniceNativeControllersInitialized=!0;const t=new MutationObserver(t=>{for(const n of t)"attributes"===n.type&&"controller"===n.attributeName?e(n.target):"childList"===n.type&&n.addedNodes.forEach(t=>{t instanceof HTMLElement&&(e(t),t.querySelectorAll("[controller]").forEach(e))})});function n(){document.querySelectorAll("[controller]").forEach(e),t.observe(document.body,{attributes:!0,attributeFilter:["controller"],childList:!0,subtree:!0})}"loading"===document.readyState?document.addEventListener("DOMContentLoaded",n):n(),globalThis.sniceNativeControllerObserver=t}const Bt=t("context-handlers");function Ft(e={}){return function(t,n){const o=n.name;return n.addInitializer(function(){const n=this.constructor;if(Object.prototype.hasOwnProperty.call(n,be)||(n[be]=new Set),!n[be].has(t)){if(n[be].add(t),!Object.prototype.hasOwnProperty.call(n,Bt)){const e=n[Bt];n[Bt]=e?[...e]:[]}n[Bt].push({methodName:o,method:t,options:e})}}),t}}function Wt(e){const t=e.constructor[Bt];if(!t||!Array.isArray(t)||0===t.length)return;const n=e[ce];if(n){e[le]=n;for(const o of t){const{methodName:t,method:r,options:s}=o,i=`__wrapped_${t}`;e[i]=function(n){const o=e[ye]||(e[ye]=new Set);if(s.once&&o.has(t))return;const a=()=>{if(r.call(e,n),s.once){o.add(t);const n=e[le];n&&"function"==typeof n[fe]&&n[fe](e,i)}},c=e[pe]||(e[pe]={}),l=t;if(s.debounce)return clearTimeout(c[l]?.timeout),void(c[l]={timeout:setTimeout(a,s.debounce)});if(s.throttle){const e=Date.now();return void(e-(c[l]?.lastCall||0)>=s.throttle&&(c[l]={lastCall:e},a()))}a()},"function"==typeof n[de]&&n[de](e,i)}}}const zt=Symbol.for("snice:html-result"),Ut=Symbol.for("snice:css-result"),Ht=new WeakMap;function Kt(e,...t){return{_$litType$:zt,strings:e,values:t}}function Gt(e,...t){return{_$litType$:zt,strings:e,values:t,svg:!0}}function Qt(e,...t){const n=0===t.length?Ht.get(e):void 0;if(n)return n;let o=e[0];for(let n=0;n<t.length;n++){const r=t[n];o+=(Xt(r)?r.cssText:String(r))+e[n+1]}const r={_$litType$:Ut,cssText:o};if("undefined"!=typeof CSSStyleSheet&&"undefined"!=typeof Document&&"adoptedStyleSheets"in Document.prototype)try{const e=new CSSStyleSheet;e.replaceSync(o),r.styleSheet=e}catch(e){}return 0===t.length&&Ht.set(e,r),r}function Jt(e){return e&&e._$litType$===zt}function Xt(e){return e&&e._$litType$===Ut}const Yt=Symbol.for("snice:nothing"),Zt=Symbol.for("snice:unsafe-html");function en(e){return{_$litType$:Zt,html:e}}function tn(e){return e&&e._$litType$===Zt}const nn=Symbol.for("snice:repeat-result");function on(e,t){if(!t||"function"!=typeof t.key||"function"!=typeof t.render)throw new TypeError("snice: repeat() requires { key, render }.");const n=null==e?[]:Array.from(e),o=n.map(t.key),r=new Set;for(const e of o){if(r.has(e))throw new Error(`snice: repeat() received duplicate key ${String(e)}.`);r.add(e)}return{_$repeat$:nn,items:n,keys:o,values:n.map(t.render),empty:0===n.length?"function"==typeof t.empty?t.empty():t.empty:void 0}}const rn=new WeakSet;function sn(e){return e[g]||e.shadowRoot||null}function an(e){const t=sn(e);if(t)return t;const n=e.constructor[b];let o;if(o="light"===n?.renderRoot||!1===n?.shadow?e:"function"==typeof e.createRenderRoot?e.createRenderRoot():e.attachShadow({mode:"string"==typeof n?.shadow?n.shadow:"open",delegatesFocus:n?.delegatesFocus}),o!==e&&!(o instanceof ShadowRoot))throw new TypeError("snice: createRenderRoot() must return the host element or a ShadowRoot.");return e[g]=o,rn.add(e),o}function cn(e){const t=e.getRootNode();if(t instanceof ShadowRoot)return t.host;let n=e;for(;n;){if(n instanceof HTMLElement&&rn.has(n))return n;n=n.parentNode}return null}const ln=`snice$${Math.random().toFixed(9).slice(2)}$`,hn="?"+ln,un=`\x3c!--${hn}--\x3e`,dn=new RegExp(ln.replace(/\$/g,"\\$"),"g"),fn=new WeakMap,mn=Symbol("not-committed");function pn(e,t){const n=e.localName;if(!n?.includes("-"))return;const o=e.ownerDocument?.defaultView?.customElements??globalThis.customElements;if(o?.get(n))return;const r=e;r[R]||(r[R]=new Set),r[R].add(t)}const yn=Symbol.for("snice:no-change"),gn=Symbol.for("snice:live");function bn(e){return{_$liveMarker$:gn,value:e}}const vn=e=>null===e||"object"!=typeof e&&"function"!=typeof e,wn=e=>!!e&&"function"==typeof e[Symbol.asyncIterator];class En{constructor(e,t,n){this.parts=[],this.keyIndex=-1,this.element=t;const o=document.createTreeWalker(t.content,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT|NodeFilter.SHOW_TEXT);let r=0;const s=[];let i;for(;null!==(i=o.nextNode());)if(i.nodeType===Node.ELEMENT_NODE){const e=i,t=e.tagName.toLowerCase(),o=e.parentElement?.tagName.toLowerCase();if(("else"===t||"else-if"===t)&&"if"!==o)throw new Error(`snice: <${t}> must be a direct child of <if>.`);if(("when"===t||"default"===t)&&"case"!==o)throw new Error(`snice: <${t}> must be a direct child of <case>.`);if("if"===t){const t=e.getAttribute("value");if(!t||!t.includes(ln))throw new Error("snice: <if> requires a condition expression.");e.removeAttribute("value"),this.parts.push({type:"conditional-if",index:r++,element:e});continue}if("case"===t){const t=e.getAttribute("value");if(!t||!t.includes(ln))throw new Error("snice: <case> requires a value expression.");for(const t of Array.from(e.childNodes))if(t.nodeType===Node.ELEMENT_NODE){const e=t.tagName.toLowerCase();if("when"!==e&&"default"!==e)throw new Error("snice: <case> may contain only direct <when> and <default> branches.")}else if(t.nodeType===Node.TEXT_NODE&&t.textContent?.trim()||t.nodeType===Node.COMMENT_NODE&&t.data.includes(ln))throw new Error("snice: content inside <case> must be nested in a <when> or <default> branch.");e.removeAttribute("value"),this.parts.push({type:"conditional-case",index:r++,element:e});continue}if("else-if"===t){const t=e.getAttribute("value");if(!t||!t.includes(ln))throw new Error("snice: <else-if> requires a condition expression.");e.removeAttribute("value"),this.parts.push({type:"conditional-else-if",index:r++,element:e});continue}if("when"===t){const t=e.getAttribute("value");t&&t.includes(ln)&&(e.removeAttribute("value"),this.parts.push({type:"conditional-when",index:r++,element:e}));continue}if(e.hasAttributes()){const t=e.attributes,o=[];for(let s=0;s<t.length;s++){const i=t[s],a=i.value;if(a.includes(ln)){o.push(i);const t=n[r]||i.name,s=a.split(ln),c=s.length-1;if(/^@@?|^[.?]/.test(t)||t.startsWith("...")||t.startsWith("class:")||t.startsWith("style:")){const e=s.some(e=>""!==e);(c>1||e)&&console.warn(`snice: binding "${t}" takes a single expression; static text and extra interpolations are ignored. Use a plain attribute for string interpolation.`)}if(t.startsWith("...")){const n=t.slice(3).toLowerCase();if(!["props","properties","attrs","attributes","events"].includes(n))throw new Error(`snice: unknown spread binding "${t}". Use ...props, ...attrs, or ...events.`);this.parts.push({type:"spread",index:r,name:n,element:e}),r+=c}else if(t.startsWith("class:")){if(!t.slice(6))throw new Error("snice: class: binding requires a class name.");this.parts.push({type:"class",index:r,name:t.slice(6),element:e}),r+=c}else if(t.startsWith("style:")){if(!t.slice(6))throw new Error("snice: style: binding requires a CSS property name.");this.parts.push({type:"style",index:r,name:t.slice(6),element:e}),r+=c}else if(t.startsWith("@@")){if(!t.slice(2).split("|")[0])throw new Error("snice: event binding requires an event name.");this.parts.push({type:"event",index:r,name:t.slice(1),element:e}),r+=c}else if(t.startsWith("@")){if(!t.slice(1).split("|")[0])throw new Error("snice: event binding requires an event name.");this.parts.push({type:"event",index:r,name:t.slice(1),element:e}),r+=c}else if(t.startsWith(".")){if(!t.slice(1))throw new Error("snice: property binding requires a property name.");this.parts.push({type:"property",index:r,name:t.slice(1),element:e}),r+=c}else if(t.startsWith("?")){if(!t.slice(1))throw new Error("snice: boolean binding requires an attribute name.");this.parts.push({type:"boolean-attribute",index:r,name:t.slice(1),element:e}),r+=c}else"controller"===i.name&&2===s.length&&""===s[0]&&""===s[1]?(this.parts.push({type:"controller",index:r,element:e}),r+=c):(this.parts.push({type:"attribute",index:r,name:i.name,element:e,attrStrings:s}),r+=c)}}for(const t of o)e.removeAttribute(t.name)}}else if(i.nodeType===Node.COMMENT_NODE){const e=i;if(e.data===hn){const t=e.parentNode,n=document.createComment("");t.insertBefore(n,e.nextSibling),this.parts.push({type:"node",index:r++,startNode:e,endNode:n})}else if(e.data.includes(ln)){const t=e.data.split(dn);this.parts.push({type:"comment",index:r,startNode:e,attrStrings:t}),r+=t.length-1}}else if(i.nodeType===Node.TEXT_NODE){const e=i,t=e.data;if(t.includes(ln)){const n=e.parentNode,o=t.split(dn),i=o.length-1;for(let t=0;t<i;t++){n.insertBefore(document.createTextNode(o[t]),e);const s=document.createComment(""),i=document.createComment("");n.insertBefore(s,e),n.insertBefore(i,e),this.parts.push({type:"node",index:r++,startNode:s,endNode:i})}""!==o[i]?e.data=o[i]:s.push(e)}}for(const e of s)e.parentNode?.removeChild(e);for(const e of this.parts)if("attribute"===e.type&&"key"===e.name){this.keyIndex=e.index;break}}}function Nn(e){const{strings:t}=e,n=fn.get(t);if(n)return n;const o=[],r=[];let s=!1,i=!1,a=!1,c="",l="";for(let e=0;e<t.length;e++){const n=t[e];if(o.push(n),e<t.length-1){for(let e=0;e<n.length;e++){const t=n[e];if(a)"-"===t&&n.startsWith("--\x3e",e)&&(a=!1,e+=2);else if(s){if(i)t===c&&(i=!1,c="");else if(">"===t)s=!1;else if('"'===t||"'"===t)i=!0,c=t;else if("="===t){let t=e-1;for(;t>=0&&/[\w\-\.@\?/:\+~|]/.test(n[t]);)t--;l=n.substring(t+1,e).trim()}}else"<"===t&&(n.startsWith("\x3c!--",e)?(a=!0,e+=3):/[A-Za-z!/?]/.test(n[e+1]||"")&&(s=!0))}if(a)r.push(""),o.push(ln);else if(i)r.push(l),o.push(ln);else if(s){const s=n.trimEnd();if(s.endsWith("=")){let e=s.length-2;for(;e>=0&&/[\w\-\.@\?\/:\+~|]/.test(s[e]);)e--;l=s.substring(e+1,s.length-1).trim(),r.push(l),o.push(ln)}else{if(!n.match(/<(if|else-if|case|when)\s*$/)){const o=(n.slice(-40)+"${…}"+(t[e+1]??"").slice(0,40)).replace(/\s+/g," ").trim();throw new Error(`snice: expressions directly in opening tags are not supported; use an explicit attribute, property, event, class, style, or named spread binding. Near "${o}".`)}l="value",r.push("value"),o.push(`value="${ln}"`)}}else r.push(""),o.push(un)}}const h=o.join(""),u=document.createElement("template");if(e.svg){u.innerHTML=`<svg>${h}</svg>`;const e=u.content.firstElementChild;for(;e.firstChild;)u.content.insertBefore(e.firstChild,e);u.content.removeChild(e)}else u.innerHTML=h;let d;try{d=new En(e,u,r)}catch(e){throw function(e,t){if(e instanceof Error&&/\bNear "[\s\S]*"\.$/.test(e.message))return e;const n=e instanceof Error?e.message:String(e),o=Array.from(t).join("${…}").replace(/\s+/g," ").trim(),r=/<([a-z][a-z0-9-]*)>/i.exec(n)?.[1],s=/binding "([^"]+)"/i.exec(n)?.[1],i=r?`<${r}`:s??"",a=i?o.indexOf(i):-1,c=a>=0?a:0,l=Math.max(0,c-40),h=Math.min(o.length,c+80),u=h<o.length?"…":"";return new Error(`${n} Near "${l>0?"…":""}${o.slice(l,h)}${u}".`,{cause:e})}(e,t)}return fn.set(t,d),d}function An(e){if(!Jt(e))return;const t=Nn(e);return-1===t.keyIndex?void 0:e.values[t.keyIndex]}class Sn{constructor(e){this.parts=[],this.fragment=null,this.conditionalParts=[],this.regularParts=[],this.template=Nn(e),this.strings=e.strings}isSameTemplate(e){return this.strings===e}renderFragment(){if(!this.fragment){this.fragment=this.template.element.content.cloneNode(!0);const e=document.createTreeWalker(this.template.element.content,NodeFilter.SHOW_ALL),t=document.createTreeWalker(this.fragment,NodeFilter.SHOW_ALL),n=new Map;let o=e.currentNode,r=t.currentNode;for(;o&&r;)n.set(o,r),o=e.nextNode(),r=t.nextNode();const s=new Set;for(const e of this.template.parts)"conditional-when"===e.type&&s.add(n.get(e.element));for(let e=0;e<this.template.parts.length;e++){const t=this.template.parts[e];let o;switch(t.type){case"node":const e=n.get(t.startNode),r=n.get(t.endNode);o=new _n(e,r);break;case"attribute":const i=n.get(t.element);o=new xn(i,t.name,t.attrStrings);break;case"property":const a=n.get(t.element);o=new Ln(a,t.name);break;case"boolean-attribute":const c=n.get(t.element);o=new jn(c,t.name);break;case"event":const l=n.get(t.element);o=new Mn(l,t.name);break;case"class":const h=n.get(t.element);o=new On(h,t.name);break;case"style":const u=n.get(t.element);o=new $n(u,t.name);break;case"spread":const d=n.get(t.element);o=new kn(d,t.name);break;case"controller":const f=n.get(t.element);o=new Pn(f);break;case"conditional-if":const m=n.get(t.element);o=new In(m);break;case"conditional-else-if":const p=n.get(t.element);o=new Vn(p);break;case"conditional-case":const y=n.get(t.element);o=new qn(y,s);break;case"conditional-when":const g=n.get(t.element);o=new Fn(g);break;case"comment":const b=n.get(t.startNode);o=new Cn(b,t.attrStrings);break;default:throw new Error(`Unknown part type: ${t.type}`)}this.parts.push(o),o instanceof In||o instanceof Vn||o instanceof qn||o instanceof Fn?this.conditionalParts.push({part:o,index:t.index}):this.regularParts.push({part:o,index:t.index})}}return this.fragment}render(e){const t=this.renderFragment();return this.update(e),t}update(e){for(const{part:t,index:n}of this.conditionalParts)t.commit(e[n]);const t=new Set;for(const{part:e}of this.conditionalParts){const n=e instanceof Vn||e instanceof Fn?e.coordinator:e;t.has(n)||(t.add(n),(n instanceof In||n instanceof qn)&&n.flush())}for(const{part:t,index:n}of this.regularParts)t instanceof xn&&void 0!==t.strings||t instanceof Cn?t.commit(e,n):t.commit(e[n]);let n;for(const e of this.parts)try{e.isConnected?e.reconnected():e.disconnected()}catch(e){n??=e}if(n)throw n}clear(){let e;for(const t of this.parts)try{t.destroy()}catch(t){e??=t}if(e)throw e}disconnected(e=!1){let t;for(const n of this.parts)try{n.disconnected(e)}catch(e){t??=e}if(t)throw t}reconnected(){let e;for(const t of this.parts)try{t.reconnected()}catch(t){e??=t}if(e)throw e}}class Tn{get isConnected(){return this.element?.isConnected??!1}disconnected(e=!1){}reconnected(){}destroy(){let e;try{this.clear()}catch(t){e=t}if(e)throw e}}class _n extends Tn{constructor(e,t){super(),this.type="node",this._committedValue=mn,this._itemKeys=null,this._asyncSource=null,this._asyncVersion=0,this._asyncIterator=null,this._asyncRunning=!1,this._asyncStarted=!1,this._asyncCompleted=!1,this._asyncPaused=!1,this._committingAsyncValue=!1,this.startNode=e,this.endNode=t}commit(e){if(e!==yn)if((e=>!!e&&"function"==typeof e.then)(e)||wn(e))this._commitAsync(e);else if(!this._committingAsyncValue&&this._asyncSource&&this._cancelAsync(!0),e!==Yt&&null!=e&&""!==e)vn(e)?e!==this._committedValue&&this._commitText(e):Jt(e)?this._commitTemplateResult(e):function(e){return!!e&&e._$repeat$===nn}(e)?0===e.values.length?this.commit(e.empty??Yt):this._commitIterable(e.values,e.keys):tn(e)?this._commitUnsafeHTML(e):void 0===e.nodeType?(e=>Array.isArray(e)||"function"==typeof e?.[Symbol.iterator])(e)?this._commitIterable(e):this._commitText(e):this._commitNode(e);else{if(this._committedValue!==Yt){const e=this._clear();if(this._committedValue=Yt,e)throw e}this._committedValue=Yt}}_commitText(e){if(this._committedValue!==mn&&this._committedValue!==Yt&&vn(this._committedValue)&&!Array.isArray(this._committedValue)){const t=this.startNode.nextSibling;if(t&&t.nodeType===Node.TEXT_NODE)return t.data=String(e),void(this._committedValue=e)}const t=this._clear();if(this._insertBefore(document.createTextNode(String(e))),this._committedValue=e,t)throw t}_commitTemplateResult(e){const t=this._committedValue;if(t instanceof Sn){const n=fn.get(e.strings);if(n&&t.template===n)return void t.update(e.values)}const n=new Sn(e),o=n.renderFragment();try{n.update(e.values)}catch(e){throw n.clear(),e}const r=this._committedValue,s=this._itemKeys,i=this.endNode.ownerDocument.createDocumentFragment();let a=this.startNode.nextSibling;for(;a&&a!==this.endNode;){const e=a.nextSibling;i.appendChild(a),a=e}this._insertBefore(o),this._committedValue=n,this._itemKeys=null;try{this.isConnected&&n.reconnected()}catch(e){try{n.clear()}catch(e){console.error("snice: failed to clean up a rejected nested template:",e)}let t=this.startNode.nextSibling;for(;t&&t!==this.endNode;){const e=t.nextSibling;t.remove(),t=e}throw this._insertBefore(i),this._committedValue=r,this._itemKeys=s,e}this._disposeCommitted(r)}_commitIterable(e,t){const n=Array.isArray(e)?e:Array.from(e),o=t?Array.from(t):n.map(An);if(o.length!==n.length)throw new Error("snice: keyed iterable produced a different number of keys and values.");const r=o.filter(e=>void 0!==e);if(r.length>0&&r.length!==o.length&&console.warn("snice: a list mixes keyed and unkeyed items. Identity falls back to position; use repeat(items, { key, render }) for deterministic updates."),r.length>0&&new Set(r).size!==r.length)throw new Error("snice: a keyed list contains duplicate keys.");let s;Array.isArray(this._committedValue)&&this._committedValue[0]instanceof _n||(s=this._clear(),this._committedValue=[],this._itemKeys=null);const i=n.length>0&&o.every(e=>void 0!==e),a=this._itemKeys;if(i&&a&&this._committedValue.length>0&&(a.length!==o.length||!o.every((e,t)=>e===a[t]))){if(s??=this._reconcileKeyed(n,o,this._committedValue,a),this._itemKeys=o,s)throw s;return}const c=this._committedValue;let l=0;for(const e of n){let t;if(l>=c.length){const e=document.createComment(""),n=document.createComment("");this._insertBefore(e),this._insertBefore(n),t=new _n(e,n),c.push(t)}else t=c[l];t.commit(e),l++}if(l<c.length){for(let e=l;e<c.length;e++){const t=c[e];try{t.destroy()}catch(e){s??=e}t.startNode.remove(),t.endNode.remove()}c.length=l}if(this._itemKeys=i?o:null,s)throw s}_reconcileKeyed(e,t,n,o){const r=this.endNode.parentNode;let s;const i=new Map;for(let e=0;e<n.length;e++)i.has(o[e])||i.set(o[e],n[e]);const a=new Set,c=new Array(e.length).fill(null);for(let n=0;n<e.length;n++){const e=i.get(t[n]);e&&!a.has(e)&&(a.add(e),c[n]=e)}for(const e of n)if(!a.has(e)){try{e.destroy()}catch(e){s??=e}e.startNode.remove(),e.endNode.remove()}let l=this.startNode.nextSibling;for(let t=0;t<c.length;t++){let n=c[t];if(n)if(n.startNode===l)l=n.endNode.nextSibling;else{const e=document.createDocumentFragment();let t=n.startNode;const o=n.endNode.nextSibling;for(;t&&t!==o;){const n=t.nextSibling;e.appendChild(t),t=n}r.insertBefore(e,l)}else{const e=document.createComment(""),o=document.createComment("");r.insertBefore(e,l),r.insertBefore(o,l),n=new _n(e,o),c[t]=n}n.commit(e[t])}return this._committedValue=c,s}_commitNode(e){if(this._committedValue!==e){const t=this._clear();if(this._insertBefore(e),this._committedValue=e,t)throw t}}_commitUnsafeHTML(e){const t=this._committedValue;if(tn(t)&&t.html===e.html)return;const n=this._clear(),o=document.createElement("template");if(o.innerHTML=e.html,this._insertBefore(o.content),this._committedValue=e,n)throw n}_commitAsync(e){if(e===this._asyncSource)return;this._cancelAsync(!1),this._asyncSource=e,this._asyncStarted=!1,this._asyncCompleted=!1,this._asyncPaused=!1;const t=this._clear();if(this._committedValue=Yt,this._startAsyncSource(),t)throw t}_startAsyncSource(e=!1){const t=this._asyncSource;if(!t||this._asyncRunning||this._asyncCompleted||!e&&!this.isConnected)return;this._asyncRunning=!0,this._asyncStarted=!0,this._asyncPaused=!1;const n=++this._asyncVersion;if(wn(t)){try{this._asyncIterator=t[Symbol.asyncIterator]()}catch(e){return this._asyncRunning=!1,this._asyncCompleted=!0,void console.error("snice: async iterable template value failed:",e)}(async()=>{try{for(;this._asyncIterator;){const e=await this._asyncIterator.next();if(e.done||n!==this._asyncVersion)break;this._commitAsyncValue(e.value)}}catch(e){n===this._asyncVersion&&console.error("snice: async iterable template value failed:",e)}finally{n===this._asyncVersion&&(this._asyncIterator=null,this._asyncRunning=!1,this._asyncCompleted=!0)}})()}else Promise.resolve(t).then(e=>{if(n===this._asyncVersion){this._asyncRunning=!1,this._asyncCompleted=!0;try{this._commitAsyncValue(e)}catch(e){console.error("snice: promise template value failed:",e)}}},e=>{n===this._asyncVersion&&(this._asyncRunning=!1,this._asyncCompleted=!0,console.error("snice: promise template value failed:",e))})}_commitAsyncValue(e){this._committingAsyncValue=!0;try{this.commit(e)}finally{this._committingAsyncValue=!1}}_cancelAsync(e){this._asyncVersion++;const t=this._asyncIterator;if(this._asyncIterator=null,this._asyncRunning=!1,e&&(this._asyncSource=null,this._asyncStarted=!1,this._asyncCompleted=!1,this._asyncPaused=!1),t?.return)try{Promise.resolve(t.return()).catch(()=>{})}catch{}}_insertBefore(e){this.endNode.parentNode?.insertBefore(e,this.endNode)}_clear(){const e=this.startNode.parentNode,t=this._committedValue;let n;try{this._disposeCommitted(t)}catch(e){n=e}if(!e)return this._committedValue=Yt,n;let o=this.startNode.nextSibling;for(;o&&o!==this.endNode;){const t=o.nextSibling;e.removeChild(o),o=t}return this._committedValue=Yt,n}_disposeCommitted(e){let t;if(e instanceof Sn)try{e.clear()}catch(e){t=e}else if(Array.isArray(e))for(const n of e)if(n instanceof _n)try{n.destroy()}catch(e){t??=e}if(t)throw t}clear(){this._cancelAsync(!0);const e=this._clear();if(e)throw e}get isConnected(){return this.startNode.isConnected}disconnected(e=!1){let t;if(this._committedValue instanceof Sn)try{this._committedValue.disconnected(e)}catch(e){t??=e}else if(Array.isArray(this._committedValue))for(const n of this._committedValue)if(n instanceof _n)try{n.disconnected(e)}catch(e){t??=e}if(this._asyncSource&&this._asyncRunning&&(this._cancelAsync(!1),this._asyncPaused=!0),t)throw t}reconnected(){let e;if(this._committedValue instanceof Sn)try{this._committedValue.reconnected()}catch(t){e??=t}else if(Array.isArray(this._committedValue))for(const t of this._committedValue)if(t instanceof _n)try{t.reconnected()}catch(t){e??=t}if(!this._asyncSource||this._asyncStarted&&!this._asyncPaused||this._startAsyncSource(!0),e)throw e}}class xn extends Tn{constructor(e,t,n){super(),this.type="attribute",this._committedValue=mn,this.lastValues=null,this.lastValueIndex=0,this.element=e,this.name=t,n&&(n.length>2||""!==n[0]||""!==n[1])?(this._committedValue=new Array(n.length-1).fill(mn),this.strings=n):this._committedValue=mn}commit(e,t=0){let n,o=!1;if(void 0===this.strings){if(e===yn)return;if(o=!vn(e)||e!==this._committedValue&&e!==yn,!o)return;this._committedValue=e,n=e}else{const r=e;this.lastValues=[...r],this.lastValueIndex=t;const s=this._committedValue;n=this.strings[0];for(let e=0;e<this.strings.length-1;e++){let i=r[t+e];i===yn&&(i=s[e],i===mn&&(i="")),o=o||!vn(i)||i!==s[e],i===Yt?n=Yt:n!==Yt&&(n=n+(i??"")+this.strings[e+1]),s[e]=i}if(!o)return}this._commitValue(n)}_commitValue(e){e===Yt?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,String(e??""))}clear(){this.element.removeAttribute(this.name)}}class Cn extends Tn{constructor(e,t){super(),this.type="node",this.lastValues=null,this.lastValueIndex=0,this.node=e,this.strings=t,this._committedValues=new Array(t.length-1).fill(mn)}commit(e,t=0){const n=e;this.lastValues=[...n],this.lastValueIndex=t;let o=!1,r=this.strings[0];for(let e=0;e<this.strings.length-1;e++){let s=n[t+e];s===yn&&(s=this._committedValues[e],s===mn&&(s="")),o=o||!vn(s)||s!==this._committedValues[e],this._committedValues[e]=s,r+=String(s===Yt?"":s??"")+this.strings[e+1]}if(o){if(r.includes("--")||r.endsWith("-"))throw new Error('snice: comment expressions cannot produce "--" or end with "-".');this.node.data=r}}clear(){}}class On extends Tn{constructor(e,t){super(),this.type="class",this.committed=mn,this.element=e,this.name=t}commit(e){if(e===yn)return;const t=e!==Yt&&Boolean(e);t!==this.committed&&(this.committed=t,this.element.classList.toggle(this.name,t))}clear(){this.element.classList.remove(this.name),this.committed=mn}}class $n extends Tn{constructor(e,t){super(),this.type="style",this.committed=mn,this.element=e,this.name=t}commit(e){if(e===yn||Object.is(e,this.committed))return;this.committed=e;const t=this.element.style;e===Yt||null==e||!1===e?t.removeProperty(this.name):t.setProperty(this.name,String(e))}clear(){this.element.style.removeProperty(this.name),this.committed=mn}}class kn extends Tn{constructor(e,t){super(),this.type="spread",this.committed={},this.listeners=new Map,this.consumedOnce=new Map,this.element=e,this.name=t}commit(e){if(e===yn)return;if(e!==Yt&&null!=e||(e={}),"object"!=typeof e||Array.isArray(e))throw new TypeError(`snice: ...${this.name} expects an object.`);const t=e;"events"===this.name?this.commitEvents(t):"props"===this.name||"properties"===this.name?this.commitProperties(t):this.commitAttributes(t),this.committed={...t}}commitProperties(e){for(const t of Object.keys(this.committed))Object.prototype.hasOwnProperty.call(e,t)||(pn(this.element,t),this.element[t]=void 0);for(const[t,n]of Object.entries(e))Object.is(this.committed[t],n)||(pn(this.element,t),this.element[t]=n===Yt?void 0:n)}commitAttributes(e){for(const t of Object.keys(this.committed))Object.prototype.hasOwnProperty.call(e,t)||this.element.removeAttribute(t);for(const[t,n]of Object.entries(e))Object.is(this.committed[t],n)||(n===Yt||null==n||!1===n?this.element.removeAttribute(t):this.element.setAttribute(t,!0===n?"":String(n)))}commitEvents(e){!function(e,t){const n=new Set;for(const[o,r]of Object.entries(e)){const e=o.startsWith("@")?o.slice(1):o;if(!e)throw new TypeError(`snice: ${t} contains an empty event name.`);if(n.has(e))throw new TypeError(`snice: ${t} contains duplicate event name "${e}".`);if(n.add(e),r!==Yt&&null!=r&&!1!==r&&"function"!=typeof r&&(!r||"object"!=typeof r||"function"!=typeof r.handleEvent))throw new TypeError(`snice: ${t} event "${e}" expects a function, EventListenerObject, or null.`)}}(e,`...${this.name}`);for(const[t,n]of this.consumedOnce){const o=Object.keys(e).find(e=>this.eventName(e)===t);o&&Object.is(e[o],n)||this.consumedOnce.delete(t)}for(const[t,n]of this.listeners){const o=Object.keys(e).find(e=>this.eventName(e)===t);o&&Object.is(e[o],n.value)||(this.element.removeEventListener(t,n.listener,n.options),this.listeners.delete(t))}for(const[t,n]of Object.entries(e)){const e=this.eventName(t);if(this.listeners.has(e))continue;const o=!!n&&"object"==typeof n&&"function"==typeof n.handleEvent;if(n===Yt||null==n||!1===n)continue;if(this.consumedOnce.has(e)&&Object.is(this.consumedOnce.get(e),n))continue;this.consumedOnce.delete(e);const r=o?n:void 0,s=t=>{r?.once&&this.consumedOnce.set(e,n),o?n.handleEvent(t):n.call(this.resolveHost(),t)};this.element.addEventListener(e,s,r),this.listeners.set(e,{value:n,listener:s,options:r})}}eventName(e){return e.startsWith("@")?e.slice(1):e}resolveHost(){return cn(this.element)||this.element}clear(){if("events"===this.name){for(const[e,t]of this.listeners)this.element.removeEventListener(e,t.listener,t.options);this.listeners.clear(),this.consumedOnce.clear()}else if("props"!==this.name&&"properties"!==this.name)for(const e of Object.keys(this.committed))this.element.removeAttribute(e);this.committed={}}disconnected(e=!1){"events"!==this.name||e||this.detachListeners()}reconnected(){"events"===this.name&&0===this.listeners.size&&this.commitEvents(this.committed)}detachListeners(){for(const[e,t]of this.listeners)this.element.removeEventListener(e,t.listener,t.options);this.listeners.clear()}}class Ln extends Tn{constructor(e,t){super(),this.type="property",this._committedValue=mn,this.element=e,this.name=t}commit(e){if(e!==yn){if(function(e){return e&&e._$liveMarker$===gn}(e)){if((e=e.value)===yn)return;if(e===this.element[this.name])return void(this._committedValue=e)}else if(e===this._committedValue)return;this._committedValue=e,pn(this.element,this.name),this.element[this.name]=e===Yt?void 0:e}}clear(){this._committedValue=mn}}class Pn extends Tn{constructor(e){super(),this.type="controller",this._committedValue=mn,this.element=e}commit(e){if(e===yn)return;const t=null==e||!1===e||""===e||e===Yt?null:e,n=this._committedValue===mn,o=n?null:this._committedValue;if(!n&&t===o)return;this._committedValue=t;const r=this.element;"function"==typeof o&&"function"!=typeof t&&(void 0!==r[O]?delete r[O]:r[i]?r.controller=null:this._detach()),"function"==typeof t?this.isConnected?this._apply(t):this.element.localName.includes("-")&&!r[i]&&(r[O]=t):"string"==typeof t?this.element.setAttribute("controller",t):"string"==typeof o&&this.element.removeAttribute("controller")}_apply(e){const t=this.element;t[i]?t.controller!==e?t.controller=e:this._attach(e):this.element.localName.includes("-")?t[O]=e:(t.ready||(t.ready=Promise.resolve()),this._attach(e))}_attach(e){It(this.element,e).catch(t=>{"ControllerAttachAborted"!==t?.name&&console.error(`Failed to attach controller "${e?.name||e}":`,t)})}_detach(){Dt(this.element).catch(e=>{console.error("Failed to detach controller:",e)})}disconnected(e=!1){if("function"!=typeof this._committedValue)return;const t=this.element;void 0===t[O]&&(t[i]||this._detach())}reconnected(){const e=this._committedValue;"function"==typeof e&&this._apply(e)}clear(){const e=this.element;void 0!==e[O]&&delete e[O];const t=this._committedValue;this._committedValue=mn,"function"==typeof t&&(e[i]||this._detach())}}class jn extends Tn{constructor(e,t){super(),this.type="boolean-attribute",this._committedValue=mn,this.element=e,this.name=t}commit(e){if(e===yn)return;const t=!!e&&e!==Yt;t!==this._committedValue&&(this._committedValue=t,t?this.element.setAttribute(this.name,""):this.element.removeAttribute(this.name))}clear(){this.element.removeAttribute(this.name),this._committedValue=mn}}class Mn extends Tn{constructor(e,t){super(),this.type="event",this.listener=null,this.listenerOptions=void 0,this.value=void 0,this.keyFilter=null,this.host=null,this.modifiers=new Set,this.once=!1,this.onceConsumed=!1,this.element=e;const[n,...o]=t.split("|"),r={preventdefault:"prevent",stoppropagation:"stop",stopimmediatepropagation:"immediate"},s=new Set(["prevent","stop","immediate","once","capture","passive","self"]);for(const e of o){const n=r[e.toLowerCase()]||e.toLowerCase();if(!s.has(n))throw new Error(`snice: unknown event modifier "${e}" in @${t}. Supported modifiers: prevent, stop, immediate, once, capture, passive, self.`);this.modifiers.add(n)}if(this.modifiers.has("passive")&&this.modifiers.has("prevent"))throw new Error(`snice: @${t} cannot combine passive and prevent.`);const i=["keydown","keyup","keypress"].includes(n.split(".")[0].split(":")[0]),a=i?n.indexOf("."):-1,c=i?n.indexOf(":"):-1,l=a>0&&c>0?Math.min(a,c):Math.max(a,c);if(l>0){const e=n.substring(0,l),t=n.substring(l+1);this.eventName=e,this.keyFilter=Nt(t)}else this.eventName=n,Et(n)}commit(e){if(e===yn)return;e===Yt&&(e=null);const t=!!e&&"object"==typeof e&&"function"==typeof e.handleEvent;if(null!=e&&!1!==e&&"function"!=typeof e&&!t)throw new TypeError(`snice: @${this.eventName} expects a function, EventListenerObject, or null.`);if(t&&this.modifiers.has("prevent")&&e.passive)throw new Error(`snice: @${this.eventName} cannot combine a passive listener object with prevent.`);if(e!==this.value||null==e){if(this.listener&&(this.element.removeEventListener(this.eventName,this.listener,this.listenerOptions),this.listener=null,this.listenerOptions=void 0),null==e||!1===e)return this.value=e,void(this.onceConsumed=!1);this.onceConsumed=!1;try{this.attachListener(e,t),this.value=e}catch(e){throw this.value=void 0,e}}}attachListener(e,t){const n=this.keyFilter,o=r=>{this.modifiers.has("self")&&r.target!==this.element||n&&!St(r,n)||(this.once&&(this.onceConsumed=!0,this.element.removeEventListener(this.eventName,o,s),this.listener=null,this.listenerOptions=void 0),this.modifiers.has("prevent")&&r.preventDefault(),this.modifiers.has("immediate")?r.stopImmediatePropagation():this.modifiers.has("stop")&&r.stopPropagation(),t?e.handleEvent(r):(this.host||(this.host=cn(this.element)),e.call(this.host||this.element,r)))},r=t?e:{};this.once=this.modifiers.has("once")||!!r.once;const s={capture:this.modifiers.has("capture")||r.capture,passive:this.modifiers.has("passive")||r.passive,signal:r.signal};this.element.addEventListener(this.eventName,o,s),this.listener=o,this.listenerOptions=s}clear(){this.detachListener(),this.value=void 0,this.host=null,this.onceConsumed=!1}detachListener(){this.listener&&(this.element.removeEventListener(this.eventName,this.listener,this.listenerOptions),this.listener=null,this.listenerOptions=void 0)}disconnected(e=!1){e||this.detachListener(),this.host=null}reconnected(){this.listener||this.onceConsumed||null==this.value||!1===this.value||this.attachListener(this.value,"object"==typeof this.value)}}const Rn=Symbol("not-set");class In extends Tn{constructor(e){super(),this.type="node",this.conditions=[Rn],this.branches=[],this.defaultBranch=-1,this.currentBranch=-1;const t=e.parentNode;this.startNode=document.createComment("if"),this.endNode=document.createComment("/if"),t.insertBefore(this.startNode,e),t.insertBefore(this.endNode,e.nextSibling);const n=document.createDocumentFragment();this.branches.push(n);let o=!1,r=n;for(const t of Array.from(e.childNodes)){const e=t.nodeType===Node.ELEMENT_NODE?t.tagName.toLowerCase():"";if("else-if"===e||"else"===e){o=!0;const n=t,s=document.createDocumentFragment();for(;n.firstChild;)s.appendChild(n.firstChild);const i=this.branches.push(s)-1;if(r=s,"else-if"===e){if(-1!==this.defaultBranch)throw new Error("snice: <else> must be the final branch inside <if>.");this.conditions[i]=Rn,Dn.set(n,{coordinator:this,index:i})}else{if(-1!==this.defaultBranch)throw new Error("snice: <if> may contain only one <else> branch.");this.defaultBranch=i}n.remove();continue}o?t.nodeType!==Node.TEXT_NODE||t.textContent?.trim()?r.appendChild(t):t.remove():n.appendChild(t)}t.removeChild(e)}commit(e){e!==yn&&(this.conditions[0]=e)}setAlternative(e,t){t!==yn&&(this.conditions[e]=t)}flush(){let e=-1;for(let t=0;t<this.conditions.length;t++)if(this.conditions[t]!==Rn&&this.conditions[t]!==Yt&&Boolean(this.conditions[t])){e=t;break}-1===e&&(e=this.defaultBranch),e!==this.currentBranch&&(this.collectCurrent(),this.currentBranch=e,-1!==e&&this.branches[e].hasChildNodes()&&this.startNode.parentNode?.insertBefore(this.branches[e],this.endNode))}collectCurrent(){if(-1===this.currentBranch)return;const e=this.branches[this.currentBranch];let t=this.startNode.nextSibling;for(;t&&t!==this.endNode;){const n=t.nextSibling;e.appendChild(t),t=n}}clear(){this.collectCurrent(),this.currentBranch=-1}get isConnected(){return this.startNode.isConnected}}const Dn=new WeakMap;class Vn extends Tn{constructor(e){super(),this.type="node";const t=Dn.get(e);if(!t)throw new Error("snice: <else-if> must be a direct child of <if>.");this.coordinator=t.coordinator,this.index=t.index}commit(e){this.coordinator.setAlternative(this.index,e)}clear(){}get isConnected(){return this.coordinator.isConnected}}class qn extends Tn{constructor(e,t){super(),this.type="node",this.value=Rn,this.branches=[],this.defaultBranch=-1,this.currentBranch=-1;const n=e.parentNode;this.startNode=document.createComment("case"),this.endNode=document.createComment("/case"),n.insertBefore(this.startNode,e),n.insertBefore(this.endNode,e.nextSibling);for(const n of Array.from(e.children)){const e=n.tagName.toLowerCase();if("when"===e){const e=document.createDocumentFragment();for(;n.firstChild;)e.appendChild(n.firstChild);const o=t.has(n),r=this.branches.push({fragment:e,dynamic:o,expected:o?Rn:n.getAttribute("value")??""})-1;o&&Bn.set(n,{coordinator:this,index:r})}else if("default"===e){if(-1!==this.defaultBranch)throw new Error("snice: <case> may contain only one <default> branch.");const e=document.createDocumentFragment();for(;n.firstChild;)e.appendChild(n.firstChild);this.defaultBranch=this.branches.push({fragment:e,dynamic:!1,expected:Rn})-1}}n.removeChild(e)}commit(e){e!==yn&&(this.value=e)}setExpected(e,t){t!==yn&&(this.branches[e].expected=t)}flush(){let e=this.branches.findIndex((e,t)=>t!==this.defaultBranch&&(e.dynamic?Object.is(this.value,e.expected):String(this.value)===e.expected));-1===e&&(e=this.defaultBranch),e!==this.currentBranch&&(this.collectCurrent(),this.currentBranch=e,-1!==e&&this.branches[e].fragment.hasChildNodes()&&this.startNode.parentNode?.insertBefore(this.branches[e].fragment,this.endNode))}collectCurrent(){if(-1===this.currentBranch)return;const e=this.branches[this.currentBranch].fragment;let t=this.startNode.nextSibling;for(;t&&t!==this.endNode;){const n=t.nextSibling;e.appendChild(t),t=n}}clear(){this.collectCurrent(),this.currentBranch=-1}get isConnected(){return this.startNode.isConnected}}const Bn=new WeakMap;class Fn extends Tn{constructor(e){super(),this.type="node";const t=Bn.get(e);if(!t)throw new Error("snice: dynamic <when> must be a direct child of <case>.");this.coordinator=t.coordinator,this.index=t.index}commit(e){this.coordinator.setExpected(this.index,e)}clear(){}get isConnected(){return this.coordinator.isConnected}}const Wn=new WeakSet,zn=new WeakSet,Un=["a[href]","area[href]","button:not([disabled])",'input:not([disabled]):not([type="hidden"])',"select:not([disabled])","textarea:not([disabled])","iframe","object","embed","summary","audio[controls]","video[controls]",'[contenteditable]:not([contenteditable="false"])','[tabindex]:not([tabindex="-1"])'].join(",");function Hn(e){try{e.focus()}catch{return!1}return function(e){const t=e.getRootNode().activeElement;return t===e||Boolean(t&&e.contains(t))}(e)}function Kn(e){return e?Array.from(e.querySelectorAll("[autofocus]")).filter(e=>!zn.has(e)):[]}function Gn(e){return e?Array.from(e.querySelectorAll(Un)):[]}function Qn(e){if(Wn.has(e)||!function(e){return!(!e.hasAttribute("autofocus")||zn.has(e))||Kn(sn(e)).length>0}(e))return;Wn.add(e);const t=()=>{const t=e.ownerDocument.defaultView,n=()=>{Wn.delete(e),function(e){if(!e.isConnected)return;const t=sn(e),n=[];if(e.hasAttribute("autofocus")&&!zn.has(e)&&n.push(e),n.push(...Kn(t)),0!==n.length)if(function(e){const t=e.activeElement;return Boolean(t&&t!==e.body&&t!==e.documentElement)}(e.ownerDocument))for(const e of n)zn.add(e);else for(const o of n){if(zn.add(o),Hn(o))return;if(o===e)for(const e of Gn(t))if(Hn(e))return}}(e)};t?.requestAnimationFrame?t.requestAnimationFrame(n):queueMicrotask(n)};Promise.resolve(e.ready).then(t,t)}let Jn=!1;function Xn(e){Jn=e}function Yn(e){e[m]||(e[f]=new Promise(t=>{e[m]=t}))}function Zn(e){const t=e[m];t&&(e[m]=null,t())}const eo=new class{constructor(){this.pending=new Set,this.scheduled=!1}schedule(e,t){t.sync?ro(e,t):(this.pending.add(e),this.scheduled||(this.scheduled=!0,queueMicrotask(()=>this.flush())))}flush(){const e=Array.from(this.pending);this.pending.clear(),this.scheduled=!1;for(const t of e)t.isConnected?ro(t,t[ee]||{}):t[p]=!0}remove(e){this.pending.delete(e)}};function to(e){return Object.prototype.hasOwnProperty.call(e,te)}function no(e){const t=e[oe];if(!t||0===t.length)return;const n=[...t];e[oe]=[],n.forEach(e=>e())}const oo=50;function ro(e,t,n){const o=arguments.length>=3,r=e[Z];if(!r)return void Zn(e);if(t.once&&to(e))return void Zn(e);const s=e[y]??0;if(s>=oo){const t=e.tagName?e.tagName.toLowerCase():"element";return console.error(`snice: maximum render depth (${oo}) exceeded for <${t}>. render() is mutating an observed property, causing an infinite render loop.`),void Zn(e)}e[y]=s+1;try{const s=o?n:r.call(e),i=an(e);if(!1===t.differential){if("string"!=typeof s)return void console.warn("Render method with differential: false must return a string");const t=document.createElement("template");t.innerHTML=s;const n=e[te];n?.clear();const o=Array.from(i.childNodes).filter(e=>!(e.nodeType===Node.ELEMENT_NODE&&"STYLE"===e.tagName&&e.hasAttribute("data-snice-style")));for(const e of o)e.remove();return i.appendChild(t.content),e[te]=null,no(e),void Qn(e)}if(!Jt(s))return void console.warn("Render method must return html`` template result");let a=e[te];if(a&&a.isSameTemplate(s.strings))return a.update(s.values),no(e),void Qn(e);const c=new Sn(s),l=c.renderFragment();try{c.update(s.values)}catch(e){throw c.clear(),e}const h=document.createDocumentFragment();for(const e of Array.from(i.childNodes))e.nodeType===Node.ELEMENT_NODE&&"STYLE"===e.tagName&&e.hasAttribute("data-snice-style")||h.appendChild(e);i.appendChild(l);try{e.isConnected&&c.reconnected()}catch(e){try{c.clear()}catch(e){console.error("snice: failed to clean up a rejected render tree:",e)}for(const e of Array.from(i.childNodes))e.nodeType===Node.ELEMENT_NODE&&"STYLE"===e.tagName&&e.hasAttribute("data-snice-style")||e.remove();throw i.appendChild(h),e}let u;e[te]=c;try{a?.clear()}catch(e){u=e}if(no(e),Qn(e),u)throw u}catch(t){const n=function(e,t){const n=e.tagName?.toLowerCase()||"element",o=t instanceof Error?t.message:String(t),r=new Error(`snice: render failed for <${n}>: ${o}`,{cause:t});return t instanceof Error&&(r.name=t.name),r}(e,t);if(Jn)throw n;console.error("Error rendering element:",n)}finally{e[y]=s,Zn(e)}}function so(e,t=!1){const n=e[ee]||{};if(n.once&&to(e))e.isConnected&&io(e);else if(Yn(e),t)ro(e,n);else{if(void 0!==n.debounce&&n.debounce>0)return e[ne]||(e[ne]={}),clearTimeout(e[ne].debounce),void(e[ne].debounce=setTimeout(()=>{e[ne].debounce=null,eo.schedule(e,n)},n.debounce));if(void 0!==n.throttle&&n.throttle>0){e[ne]||(e[ne]={lastThrottle:0});const t=e[ne],o=Date.now();return 0===t.lastThrottle||o-t.lastThrottle>=n.throttle?(t.lastThrottle=o,void eo.schedule(e,n)):void(t.throttleTimer||(t.throttleTimer=setTimeout(()=>{t.throttleTimer=null,t.lastThrottle=Date.now(),eo.schedule(e,n)},n.throttle-(o-t.lastThrottle))))}eo.schedule(e,n)}}function io(e){const t=e[te];t?.reconnected()}function ao(e={}){return function(t,n){return n.addInitializer(function(){this[Z]=t,this[ee]=e}),function(...n){const o=t.apply(this,n);return ro(this,{...this[ee]||e,once:!1},o),o}}}function co(){return function(e,t){return t.addInitializer(function(){this[re]&&!this[ie]?this[ie]=[this[re]]:this[re]&&this[ie]&&this[ie].push(this[re]),this[re]=e}),e}}function lo(e,t){return function(n,o){return function(...r){this[Y]||(this[Y]=new Map);const s=`${e}_${o.name}`;this[Y].has(s)||this[Y].set(s,{debounceTimeout:null,throttleLastCall:0,throttleTimeout:null});const i=this[Y].get(s),a=n.apply(this,r),c=n=>{if(void 0===n&&!1===t?.dispatchOnUndefined)return;const o=new CustomEvent(e,{bubbles:t?.bubbles??!0,cancelable:t?.cancelable??!1,composed:t?.composed??!0,detail:n});if(void 0!==t?.scope&&void 0!==t?.daemon)throw new TypeError(`@dispatch('${e}') cannot use both scope and daemon.`);if(void 0!==t?.daemon)return void mt(this,t.daemon).dispatchEvent(o);if(void 0!==t?.scope){const n=Ye(this,t.scope);return n?void n.dispatchEvent(o):void console.warn(`[snice/@dispatch] scope did not resolve for "${e}" — event not dispatched.`)}const r=pt(this);if(!r)throw new TypeError(`@dispatch('${e}') requires an element, attached controller, or provided @daemon instance.`);r.dispatchEvent(o)},l=e=>{if(t?.debounce)return clearTimeout(i.debounceTimeout),void(i.debounceTimeout=setTimeout(()=>c(e),t.debounce));if(!t?.throttle)return void c(e);const n=Date.now(),o=t.throttle-(n-i.throttleLastCall);if(o<=0)return clearTimeout(i.throttleTimeout),i.throttleLastCall=n,void c(e);i.latestDetail=e,i.throttleTimeout||(i.throttleTimeout=setTimeout(()=>{i.throttleLastCall=Date.now(),i.throttleTimeout=null;const e=i.latestDetail;i.latestDetail=void 0,c(e)},o))};return a instanceof Promise?a.then(e=>(l(e),e)):(l(a),a)}}}function ho(e){const t=e[Y];if(t)for(const e of t.values())e.debounceTimeout&&clearTimeout(e.debounceTimeout),e.throttleTimeout&&clearTimeout(e.throttleTimeout),e.debounceTimeout=null,e.throttleTimeout=null,e.throttleLastCall=0,e.latestDetail=void 0}const uo=t("debounce-timers"),fo=t("throttle-timers"),mo=t("once-called"),po=t("memoize-cache");function yo(e=300,t={}){const{leading:n=!1,trailing:o=!0,maxWait:r}=t;return function(t,s){const i=s.name;return function(...s){this[uo]||(this[uo]={});const a=this[uo],c=i;a[c]&&clearTimeout(a[c].timeout);const l=Date.now(),h=!a[c],u=h?l:a[c].startTime,d=void 0!==r&&l-u>=r;if(n&&h){const e=t.apply(this,s);return a[c]={timeout:null,startTime:u,lastArgs:s},e}const f=setTimeout(()=>{(o||d)&&t.apply(this,a[c].lastArgs),delete a[c]},d?0:e);a[c]={timeout:f,startTime:u,lastArgs:s}}}}function go(e=300,t={}){const{leading:n=!0,trailing:o=!0}=t;return function(t,r){const s=r.name;return function(...r){this[fo]||(this[fo]={});const i=this[fo],a=s,c=Date.now();if(!i[a])return n&&t.apply(this,r),i[a]={lastInvoke:c,timeout:null,lastArgs:r},void(o&&!n&&(i[a].timeout=setTimeout(()=>{t.apply(this,i[a].lastArgs),delete i[a]},e)));const l=c-i[a].lastInvoke;if(i[a].lastArgs=r,i[a].timeout&&clearTimeout(i[a].timeout),l>=e)return t.apply(this,r),void(i[a].lastInvoke=c);o&&(i[a].timeout=setTimeout(()=>{t.apply(this,i[a].lastArgs),i[a].lastInvoke=Date.now(),i[a].timeout=null},e-l))}}}function bo(e=!0){let t,n=!1;return function(o,r){const s=r.name;return function(...r){return e?(this[mo]||(this[mo]={}),this[mo][s]||(this[mo][s]={called:!0,result:o.apply(this,r)}),this[mo][s].result):(n||(n=!0,t=o.apply(this,r)),t)}}}function vo(e={}){const{keyGenerator:t=(...e)=>JSON.stringify(e),maxSize:n=100,ttl:o}=e;return function(e,r){const s=r.name;return function(...r){this[po]||(this[po]={}),this[po][s]||(this[po][s]=new Map);const i=this[po][s],a=t(...r);if(i.has(a)){const e=i.get(a);if(!(void 0!==o&&Date.now()-e.timestamp>o))return e.value;i.delete(a)}const c=e.apply(this,r);if(i.set(a,{value:c,timestamp:Date.now()}),i.size>n){const e=i.keys().next().value;i.delete(e)}return c}}}function wo(e){if(e[uo]){for(const t in e[uo])e[uo][t]?.timeout&&clearTimeout(e[uo][t].timeout);e[uo]={}}}function Eo(e){if(e[fo]){for(const t in e[fo])e[fo][t]?.timeout&&clearTimeout(e[fo][t].timeout);e[fo]={}}}function No(e,t){e[po]&&(t?delete e[po][t]:e[po]={})}function Ao(e,t){e[mo]&&(t?delete e[mo][t]:e[mo]={})}function So(e,t){const n=Reflect.getOwnPropertyDescriptor(e,t);return!n||n.configurable?{locked:!1,value:void 0}:"value"in n&&!1===n.writable?{locked:!0,value:n.value}:"value"in n||void 0!==n.get?{locked:!1,value:void 0}:{locked:!0,value:void 0}}function To(e){e.prototype[i]=!0;const t=e.prototype.connectedCallback,n=e.prototype.disconnectedCallback,o=e.prototype.attributeChangedCallback,r=e.observedAttributes||[];r.includes("controller")||r.push("controller"),r.includes("autofocus")||r.push("autofocus");const s=e[k];if(s)for(const[e,t]of s){if(!1===t.attribute)continue;const n=Fe(t,e);r.includes(n)||r.push(n)}Object.defineProperty(e,"observedAttributes",{get:()=>r,configurable:!0}),Object.defineProperty(e.prototype,"ready",{get(){return this[l]||(this[l]=new Promise((e,t)=>{this[h]=e,this[u]=t}),this[l].catch(()=>{})),this[l]},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rendered",{get(){return this[m]?this[f]:Promise.resolve()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"controller",{get(){return this[v]},set(e){const t=this[v];if(this[v]=e,e!==t){if(e){const t="string"==typeof e?e:e.name||"(anonymous controller class)";return void It(this,e).catch(n=>{"ControllerAttachAborted"!==n?.name?"string"!=typeof e||n?.message!==`Controller "${e}" not found in registry`?console.error(`Failed to attach controller "${t}":`,n):Pt(this,e):console.debug(`Controller "${t}" attach aborted (element detached before ready)`)})}t&&Dt(this).catch(e=>{console.error("Failed to detach controller:",e)})}},enumerable:!0,configurable:!0}),e.prototype.connectedCallback=async function(){if(this[l]||(this[l]=new Promise((e,t)=>{this[h]=e,this[u]=t}),this[l].catch(()=>{})),this[w]){try{io(this)}catch(e){console.error(`Error reconnecting the render tree for ${this.tagName}:`,e)}Ot(this,this),bt(this,this),Wt(this);try{ot(this,this)}catch(e){console.error(`Error setting up observers for ${this.tagName} on reconnection:`,e)}t&&t.call(this);const n=e[U];if(n)for(const e of n)try{const t=e.method.call(this);t&&"function"==typeof t.then&&t.catch(t=>{console.error(`Error in @reconnect handler ${e.methodName}:`,t)})}catch(t){console.error(`Error in @reconnect handler ${e.methodName}:`,t)}return this[Z]&&this[p]&&(this[p]=!1,so(this)),void Qn(this)}this[I]=!0;const n=e[k];if(n)for(const[e,t]of n){if(!1===t.attribute)continue;const n=Fe(t,e);if(!this.hasAttribute(n))continue;const o=this.getAttribute(n);Ke(this,V).add(e),t.type===Boolean&&""===o&&this.setAttribute(n,"true"),this[e]=qe(o,t)}if(this[M]){for(const[e,t]of Array.from(this[M].entries())){const o=n?.get(e),r=Fe(o||{},e);this[M].delete(e),this.hasAttribute(r)||(this[e]=t)}delete this[M]}if(void 0!==this[O]){const e=this[O];if(delete this[O],!this[v]){this[v]=e;const t=e?.name||"(anonymous controller class)";It(this,e).catch(e=>{"ControllerAttachAborted"!==e?.name?console.error(`Failed to attach controller "${t}":`,e):console.debug(`Controller "${t}" attach aborted (element detached before ready)`)})}}if(this.hasAttribute("controller")&&!this[v]){const e=this.getAttribute("controller");e&&(this.controller=e)}if(function(e){const t=e[re],n=[],o=[];let r=e.constructor;for(;r&&r!==HTMLElement&&r!==Function.prototype;)o.unshift(r),r=Object.getPrototypeOf(r);for(const e of o){if(!Object.prototype.hasOwnProperty.call(e,"styles"))continue;const t=e.styles,o=Array.isArray(t)?t:[t];for(const e of o)Xt(e)?n.push(e):console.warn("Static styles must be a css`` result or an array of css`` results")}if((t||0!==n.length)&&!e[se]){e[se]=!0;try{const o=[...n],r=e[ie];if(r)for(const t of r){const n=t.call(e);Xt(n)&&o.push(n)}if(t){const n=t.call(e);if(!Xt(n))return void console.warn("Styles method must return css`` template result");o.push(n)}const s=an(e),i=Array.from(s.childNodes).filter(e=>e.nodeType===Node.ELEMENT_NODE&&"STYLE"===e.tagName&&e.hasAttribute("data-snice-style"));if(i.length===o.length&&i.every((e,t)=>e.textContent===o[t].cssText))return;for(const e of i)e.remove();if(s instanceof ShadowRoot&&o.every(e=>!!e.styleSheet)&&"adoptedStyleSheets"in s)try{return void(s.adoptedStyleSheets=o.map(e=>e.styleSheet))}catch{}for(const e of o){const t=document.createElement("style");t.setAttribute("data-snice-style",""),t.textContent=e.cssText,s.appendChild(t)}}catch(e){console.error("Error applying styles:",e)}}}(this),this[Z])try{an(this)}catch{}Ot(this,this),bt(this,this),Wt(this),this[w]=!0,function(e,t){if(et.has(t))return;et.add(t);const n=t[D];if(!n||0===n.size)return;const o=t[k],r=new Set(["*"]);if(o)for(const[e,t]of o)r.add(e),"string"==typeof t?.attribute&&r.add(t.attribute);for(const t of n.keys()){if(r.has(t))continue;const n=e.tagName?e.tagName.toLowerCase():"element",s=o?[...o.keys()].join(", "):"(none)";console.warn(`@watch('${t}') on <${n}> matches no @property — it will never fire. Known properties: ${s}.`)}}(this,e),function(e,t){const n=t[D],o=t[k];if(n&&o)for(const[t,r]of o){const o=[t],s=r&&"string"==typeof r.attribute?r.attribute:null;s&&s!==t&&o.push(s),o.push("*");for(const r of o)if(n.has(r))for(const o of n.get(r))if(o.immediate)try{o.method.call(e,void 0,e[t],t)}catch(e){console.error(`Error in @watch('${r}') method ${o.methodName}:`,e)}}}(this,e),t&&t.call(this);const o=e[W];if(await new Promise(e=>queueMicrotask(e)),!this.isConnected)return void(this[h]&&(this[h](),this[h]=null,this[u]=null));this[Z]&&so(this,!0);try{ot(this,this)}catch(e){console.error(`Error setting up observers for ${this.tagName}:`,e)}if(await new Promise(e=>queueMicrotask(e)),!this.isConnected)return void(this[h]&&(this[h](),this[h]=null,this[u]=null));let r,s=!1;if(o){this[d]=!0;try{for(const e of o)try{await e.method.call(this)}catch(t){console.error(`Error in @ready handler ${e.methodName}:`,t),s||(s=!0,r=t)}}finally{delete this[d]}}s&&this[u]?(this[u](r),this[h]=null,this[u]=null):this[h]&&(this[h](),this[h]=null,this[u]=null),Qn(this)},e.prototype.disconnectedCallback=async function(){try{!function(e){const t=e[te];t?.disconnected(!0)}(this)}catch(e){console.error(`Error disconnecting the render tree for ${this.tagName}:`,e)}const t=e[z];if(t)for(const e of t)try{await e.method.call(this)}catch(t){console.error(`Error in @dispose handler ${e.methodName}:`,t)}n&&n.call(this),this[v]&&Dt(this).catch(e=>{console.error("Failed to detach controller:",e)}),$t(this),vt(this),function(e){const t=e.constructor[Bt];if(!t||!Array.isArray(t)||0===t.length)return;const n=e[pe];if(n&&"object"==typeof n){for(const e of Object.keys(n))n[e]?.timeout&&clearTimeout(n[e].timeout);delete e[pe]}for(const n of t)delete e[`__wrapped_${n.methodName}`];const o=e[le];o&&"function"==typeof o[fe]&&o[fe](e),delete e[le],delete e[ye]}(this),ct(this),wo(this),Eo(this),function(e){const t=e[ne];if(!t)return!1;let n=!1;return t.debounce&&(clearTimeout(t.debounce),t.debounce=null,n=!0),t.throttleTimer&&(clearTimeout(t.throttleTimer),t.throttleTimer=null,n=!0),n}(this)&&(this[p]=!0),ho(this),Fo(this,J),Fo(this,X)},e.prototype.attributeChangedCallback=function(t,n,r){if(o?.call(this,t,n,r),"controller"===t){if(this[C])return;return this[x]?void Rt(this):void(this.controller=r)}"autofocus"===t&&(null===r?zn.delete(this):this[w]&&Qn(this));const s=e[k];if(s)for(const[n,o]of s){if(Fe(o,n).toLowerCase()!==t.toLowerCase())continue;if(this[Q]?.has(t.toLowerCase()))break;const s=this[L]?.[n],i=this[P]?.[n];let a=null===r?o.type!==Boolean&&i:qe(r,o,s,i);const c=this[j]?.[n];if(c&&(a=c(a)),!(o?.hasChanged?o.hasChanged(a,s):Be(a,s)))break;Ke(this,V).add(n),Ge(this,L)[n]=a,this[w]&&Qe(this,e,n,s,a),this[Z]&&this[w]&&so(this);break}},e.prototype.connectedMoveCallback=async function(){const t=e[H];if(t)for(const e of t)try{await this[e.methodName]()}catch(t){console.error(`Error in @moved handler ${e.methodName}:`,t)}},e.prototype.adoptedCallback=async function(){const t=e[K];if(t)for(const e of t)try{await this[e.methodName]()}catch(t){console.error(`Error in @adopted handler ${e.methodName}:`,t)}}}function _o(e,t,n,o){if(function(e){let t=Object.getPrototypeOf(e);const n=[];for(;t&&t!==HTMLElement&&t!==Function.prototype;)n.push(t),t=Object.getPrototypeOf(t);n.reverse();for(const t of n){if(t[k]){e[k]||(e[k]=new Map);for(const[n,o]of t[k])e[k].has(n)||e[k].set(n,o)}t.formAssociated&&!e.formAssociated&&(e.formAssociated=!0)}}(t),n.metadata&&n.metadata[k]){t[k]||(t[k]=new Map);for(const[e,o]of n.metadata[k])t[k].set(e,o)}else if(Oo.length>0){t[k]||(t[k]=new Map);const e=Oo.pop();for(const[n,o]of e)t[k].set(n,o)}o?.formAssociated&&(t.formAssociated=!0);const r={...Object.getPrototypeOf(t)?.[b]||{}},s=o||{};if("light"===s.renderRoot&&"string"==typeof s.shadow||"shadow"===s.renderRoot&&!1===s.shadow)throw new TypeError("snice: @element renderRoot and shadow options select conflicting render roots.");const i={...r,...s};return Object.prototype.hasOwnProperty.call(s,"shadow")?i.renderRoot=!1===s.shadow?"light":"shadow":Object.prototype.hasOwnProperty.call(s,"renderRoot")&&("light"===s.renderRoot?i.shadow=!1:!1===i.shadow&&(i.shadow="open")),t[b]=i,!0===t.prototype[ae]&&Object.prototype.hasOwnProperty.call(t.prototype,"render")&&!Object.prototype.hasOwnProperty.call(t.prototype,Z)&&"function"==typeof t.prototype.render&&(t.prototype[Z]=t.prototype.render,t.prototype[ee]=t.renderOptions||{}),To(t),customElements.get(e)?(globalThis.SNICE_DEBUG&&console.warn(`[snice] "${e}" is already registered. Skipping.`),t):(customElements.define(e,t),t)}function xo(e,t){if(void 0!==t?.renderRoot&&"shadow"!==t.renderRoot&&"light"!==t.renderRoot)throw new TypeError('snice: @element renderRoot must be "shadow" or "light".');if(void 0!==t?.shadow&&!1!==t.shadow&&"open"!==t.shadow&&"closed"!==t.shadow)throw new TypeError('snice: @element shadow must be "open", "closed", or false.');return function(n,o){return _o(e,n,o,t)}}function Co(e){return function(t,n){return _o(e,t,n)}}const Oo=[],$o=new WeakMap;function ko(e){return function(t,n){const o=n.name;return n.metadata?(n.metadata[k]||(n.metadata[k]=new Map),n.metadata[k].set(o,e||{})):(0===Oo.length&&Oo.push(new Map),Oo[Oo.length-1].set(o,e||{})),function(t){const n=this[R],r=!0===n?.delete(o);0===n?.size&&delete this[R];const s=Object.prototype.hasOwnProperty.call(this,o),i=s&&(r||!function(e,t,n){const o=e?.ownerDocument;if(!o?.createElement)return!1;let r=$o.get(o);if(!r){const e=o.createElement("div");r=new Map;for(const t of Reflect.ownKeys(e))r.set(t,e[t]);$o.set(o,r)}return r.has(t)&&Object.is(r.get(t),n)}(this,o,this[o])),a=i?this[o]:t;s&&delete this[o];const c=this.constructor;c[k]||(c[k]=new Map);const l={...e};l.type||void 0===t||(l.type=Ve(t)),l.attributeNaming||"kebab"!==c.propertyAttributeNaming||(l.attributeNaming="kebab"),c[k].set(o,l),Ge(this,P)[o]=t;const h=()=>{if(!this[I])return;const e=this[L]?.[o];if(!1!==l.attribute&&!1!==l.reflect){const n=Fe(l,o),r=Ze(e,l,t),s=n.toLowerCase();Ke(this,Q).add(s);try{null===r?this.removeAttribute?.(n):this.setAttribute?.(n,r)}finally{this[Q].delete(s)}}this[w]&&(Qe(this,this.constructor,o,e,e),this[Z]&&so(this))},u=e=>{if(!l.deep)return e;let t;return t=function(e,t){if(!e||"object"!=typeof e)return e;const n=new WeakMap,o=new WeakMap,r=e=>e&&"object"==typeof e&&o.get(e)||e,s=e=>{if(!e||"object"!=typeof e)return e;if(n.has(e))return n.get(e);if(e instanceof Map){let i;const a=new Map;return i=new Proxy(e,{get(e,n){const o=So(e,n);if(o.locked)return o.value;if(a.has(n))return a.get(n);let c;if("set"===n)c=(n,o)=>{n=r(n),o=r(o);const s=e.has(n),a=e.get(n);return e.set(n,o),s&&Object.is(a,o)||t(),i};else if("delete"===n)c=n=>{n=r(n);const o=e.delete(n);return o&&t(),o};else if("clear"===n)c=()=>{0!==e.size&&(e.clear(),t())};else if("get"===n)c=t=>s(e.get(r(t)));else if("has"===n)c=t=>e.has(r(t));else if("forEach"===n)c=(t,n)=>e.forEach((e,o)=>t.call(n,s(e),s(o),i));else if("values"===n)c=function*(){for(const t of e.values())yield s(t)};else if("keys"===n)c=function*(){for(const t of e.keys())yield s(t)};else if("entries"===n||n===Symbol.iterator)c=function*(){for(const[t,n]of e.entries())yield[s(t),s(n)]};else{const t=Reflect.get(e,n,e);if("function"!=typeof t)return t;if("constructor"===n)return t;c=t.bind(e)}return a.set(n,c),c}}),n.set(e,i),o.set(i,e),i}if(e instanceof Set){let i;const a=new Map;return i=new Proxy(e,{get(e,n){const o=So(e,n);if(o.locked)return o.value;if(a.has(n))return a.get(n);let c;if("add"===n)c=n=>{n=r(n);const o=e.has(n);return e.add(n),o||t(),i};else if("delete"===n)c=n=>{n=r(n);const o=e.delete(n);return o&&t(),o};else if("clear"===n)c=()=>{0!==e.size&&(e.clear(),t())};else if("has"===n)c=t=>e.has(r(t));else if("forEach"===n)c=(t,n)=>e.forEach(e=>{const o=s(e);t.call(n,o,o,i)});else if("values"===n||"keys"===n||n===Symbol.iterator)c=function*(){for(const t of e.values())yield s(t)};else if("entries"===n)c=function*(){for(const t of e.values()){const e=s(t);yield[e,e]}};else{const t=Reflect.get(e,n,e);if("function"!=typeof t)return t;if("constructor"===n)return t;c=t.bind(e)}return a.set(n,c),c}}),n.set(e,i),o.set(i,e),i}if(!Array.isArray(e)&&!function(e){const t=Object.getPrototypeOf(e);return t===Object.prototype||null===t}(e))return e;const i=new Proxy(e,{get(e,t,n){const o=So(e,t);return o.locked?o.value:s(Reflect.get(e,t,n))},set(e,n,o,s){const i=Reflect.get(e,n,s);o=r(o);const a=Reflect.set(e,n,o);return a&&!Object.is(i,o)&&t(),a},deleteProperty(e,n){const o=Object.prototype.hasOwnProperty.call(e,n),r=Reflect.deleteProperty(e,n);return r&&o&&t(),r},defineProperty(e,n,o){const s=Reflect.getOwnPropertyDescriptor(e,n),i="value"in o?{...o,value:r(o.value)}:o,a=Reflect.defineProperty(e,n,i),c=a?Reflect.getOwnPropertyDescriptor(e,n):s;return a&&!function(e,t){if(!e||!t)return e===t;const n="value"in e||"writable"in e;return n===("value"in t||"writable"in t)&&e.configurable===t.configurable&&e.enumerable===t.enumerable&&(!n||e.writable===t.writable&&Object.is(e.value,t.value))&&(n||e.get===t.get&&e.set===t.set)}(s,c)&&t(),a}});return n.set(e,i),o.set(i,e),i};return s(e)}(e,()=>{this[L]?.[o]===t&&h()}),t};Ge(this,j)[o]=u;const d=this.constructor.prototype;let f=d[$e];f&&Object.prototype.hasOwnProperty.call(d,$e)||(f=new Map(f),d[$e]=f);const m=f.get(o);m&&m===e||(f.set(o,e),Object.defineProperty(this.constructor.prototype,o,{get(){return this[M]?.has(o)?this[M].get(o):this[L]&&o in this[L]?this[L][o]:t},set(e){const t=this[o];if(!(l.hasChanged?l.hasChanged(e,t):Be(e,t)))return;const n=(this[j]?.[o]||(e=>e))(e);if(!this[I])return this[M]||(this[M]=new Map),void this[M].set(o,n);if(Ge(this,L)[o]=n,!1!==l.attribute&&!1!==l.reflect){const e=Fe(l,o),t=Ze(n,l,this[P]?.[o]);Ke(this,V).add(o);const r=e.toLowerCase();Ke(this,Q).add(r);try{null===t?this.removeAttribute?.(e):this.setAttribute?.(e,t)}finally{this[Q].delete(r)}}this[w]&&(Qe(this,this.constructor,o,t,n),this[Z]&&so(this))},configurable:!0,enumerable:!0}));const p=u(t);return Ge(this,L)[o]=p,Ge(this,P)[o]=p,i?a:p}}}function Lo(e={}){return ko({...e,attribute:!1,reflect:!1})}function Po(e){return!0===e[o]&&e.element?e.element:e}function jo(e,t={}){return function(n,o){const{light:r=!1,shadow:s=!0}=t,i=o.name;return function(t){return Object.hasOwn(this.constructor.prototype,i)||Object.defineProperty(this.constructor.prototype,i,{get(){const t=Po(this);let n=null;const o=t instanceof HTMLElement?sn(t):null;return s&&o?n=o.querySelector(e):s&&t.shadowRoot&&(n=t.shadowRoot.querySelector(e)),!n&&r&&(n=t.querySelector(e)),n||null},set(){},configurable:!0,enumerable:!0}),t}}}function Mo(e,t={}){return function(n,o){const{light:r=!1,shadow:s=!0}=t,i=o.name;return function(t){return Object.hasOwn(this.constructor.prototype,i)||Object.defineProperty(this.constructor.prototype,i,{get(){const t=Po(this),n=new Set,o=t instanceof HTMLElement?sn(t):null;if(s&&o)for(const t of o.querySelectorAll(e))n.add(t);else if(s&&t.shadowRoot)for(const o of t.shadowRoot.querySelectorAll(e))n.add(o);if(r)for(const o of t.querySelectorAll(e))n.add(o);return[...n]},set(){},configurable:!0,enumerable:!0}),t}}}function Ro(...e){const t=e.filter(e=>"string"==typeof e),n=e.find(e=>"object"==typeof e&&null!==e),o=!1!==n?.immediate;return function(e,n){const r=n.name;n.addInitializer(function(){const n=this.constructor;Object.prototype.hasOwnProperty.call(n,ve)||(n[ve]=new Map);let s=n[ve].get(e);if(s||(s=new Set,n[ve].set(e,s)),!Object.prototype.hasOwnProperty.call(n,D)){const e=n[D],t=new Map;if(e)for(const[n,o]of e)t.set(n,[...o]);n[D]=t}for(const i of t)s.has(i)||(s.add(i),n[D].has(i)||n[D].set(i,[]),n[D].get(i).push({methodName:r,method:e,immediate:o}))})}}function Io(){return function(e,t){const n=t.name;return function(e){return Object.hasOwn(this.constructor.prototype,n)||Object.defineProperty(this.constructor.prototype,n,{get(){if(void 0!==this[q])return this[q];const e=ut(this);return void 0!==e?e:void 0},set(){},configurable:!0,enumerable:!0}),e}}}function Do(e,t,n,o,r){const s=o.name;o.addInitializer(function(){const o=this.constructor;if(Object.prototype.hasOwnProperty.call(o,t)||(o[t]=new Set),!o[t].has(n)){if(o[t].add(n),!Object.prototype.hasOwnProperty.call(o,e)){const t=o[e];o[e]=t?[...t]:[]}o[e].push({methodName:s,method:n,...r})}})}function Vo(){return function(e,t){Do(W,Ae,e,t)}}function qo(){return function(e,t){Do(z,Se,e,t)}}function Bo(){return function(e,t){Do(U,Te,e,t)}}function Fo(e,t){const n=e[t];if(n)for(const e of n.values())e.debounceTimer&&clearTimeout(e.debounceTimer),e.throttleTimer&&clearTimeout(e.throttleTimer),e.debounceTimer=null,e.throttleTimer=null,e.lastThrottleCall=0}function Wo(e,t,n){return function(o={}){return function(r,s){Do(e,n,r,s,{options:o});const i=s.name;return function(...e){this[t]||(this[t]=new Map),this[t].has(i)||this[t].set(i,{throttleTimer:null,debounceTimer:null,lastThrottleCall:0});const n=this[t].get(i),s=(...e)=>r.apply(this,e),a=(...e)=>{try{const t=r.apply(this,e);t&&"function"==typeof t.then&&t.catch(e=>console.error(`Error in deferred lifecycle handler ${i}:`,e))}catch(e){console.error(`Error in deferred lifecycle handler ${i}:`,e)}};if(o.debounce>0)return clearTimeout(n.debounceTimer),void(n.debounceTimer=setTimeout(()=>a(...e),o.debounce));if(o.throttle>0){const t=Date.now();return 0===n.lastThrottleCall||t-n.lastThrottleCall>=o.throttle?(n.lastThrottleCall=t,s(...e)):void(n.throttleTimer||(n.throttleTimer=setTimeout(()=>{n.throttleTimer=null,n.lastThrottleCall=Date.now(),a(...e)},o.throttle-(t-n.lastThrottleCall))))}return s(...e)}}}}const zo=Wo(H,J,_e),Uo=Wo(K,X,xe);class Ho extends HTMLElement{static{this.propertyAttributeNaming="kebab"}createRenderRoot(){const e=this.constructor[b];return this.attachShadow({mode:"string"==typeof e?.shadow?e.shadow:"open",delegatesFocus:e?.delegatesFocus})}invalidate(){return so(this),this.rendered}renderNow(){return function(e){Yn(e),ro(e,{...e[ee]||{},once:!1})}(this),this.rendered}}Object.defineProperty(Ho.prototype,ae,{value:!0});class Ko{constructor(e){this.parsed=this.parsePattern(e)}get spec(){return this.parsed.template}parsePattern(e){let t=e,n="",o=!1;const r=e.indexOf("?");return-1!==r&&(t=e.slice(0,r),n=e.slice(r+1),t.endsWith("(")&&n.endsWith(")")&&(o=!0,t=t.slice(0,-1),n=n.slice(0,-1))),{pathSegments:this.parseSegments(t),querySegments:n?this.parseQuerySegments(n):[],queryOptional:o,template:e}}parseSegments(e){const t=[];let n=0;for(;n<e.length;)switch(e[n]){case"(":const{segments:o,endIndex:r}=this.parseOptionalGroup(e,n);t.push({type:"optional",segments:o}),n=r+1;break;case":":const{name:s,endIndex:i}=this.parseIdentifier(e,n+1);t.push({type:"param",name:s}),n=i;break;case"*":const{name:a,endIndex:c}=this.parseIdentifier(e,n+1);t.push({type:"splat",name:a}),n=c;break;default:const{value:l,endIndex:h}=this.parseLiteral(e,n);l&&t.push({type:"literal",value:l}),n=h}return t}parseOptionalGroup(e,t){let n=1,o=t+1;for(;o<e.length&&n>0;)"("===e[o]&&n++,")"===e[o]&&n--,o++;const r=e.slice(t+1,o-1);return{segments:this.parseSegments(r),endIndex:o-1}}parseIdentifier(e,t){let n=t;for(;n<e.length&&/[\w-]/.test(e[n]);)n++;return{name:e.slice(t,n),endIndex:n}}parseLiteral(e,t){let n=t;for(;n<e.length&&!"(:*(".includes(e[n]);)n++;return{value:e.slice(t,n),endIndex:n}}parseQuerySegments(e){let t=e;t.startsWith("(")&&t.endsWith(")")&&(t=t.slice(1,-1));const n=[];let o=0;for(;o<t.length;)if(":"===t[o]){const{name:e,endIndex:r}=this.parseIdentifier(t,o+1);n.push({type:"param",name:e}),o=r}else{const{value:e,endIndex:r}=this.parseQueryLiteral(t,o);e&&n.push({type:"literal",value:e}),o=r}return n}parseQueryLiteral(e,t){let n=t;for(;n<e.length&&":"!==e[n];)n++;return{value:e.slice(t,n),endIndex:n}}getAllParamNames(){const e=new Set,t=n=>{for(const o of n)switch(o.type){case"param":case"splat":e.add(o.name);break;case"optional":t(o.segments)}};return t(this.parsed.pathSegments),t(this.parsed.querySegments),Array.from(e)}canMatchRemainingSegments(e,t,n){let o=t;for(const t of n)if("literal"===t.type){const n=e.indexOf(t.value,o);if(-1===n)return!1;o=n+t.value.length}return!0}match(e){const[t,n]=e.split("?"),o=this.matchPath(t,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 e of s)i[e]=void 0;return Object.assign(i,o,r),i}matchPath(e,t){const n={};let o=0;for(let r=0;r<t.length;r++){const s=t[r],i=t.slice(r+1),a=this.matchSegment(e,o,s,i);if(!1===a)return!1;Object.assign(n,a.params),o=a.nextIndex}return!(o<e.length)&&n}matchSegment(e,t,n,o=[]){switch(n.type){case"literal":return e.slice(t,t+n.value.length)===n.value&&{params:{},nextIndex:t+n.value.length};case"param":{let r=t;const s=o[0];let i,a=["/","?"];if(s&&"literal"===s.type){const n=e.indexOf(s.value,t);if(-1===n)return!1;r=n}else for(;r<e.length&&!a.includes(e[r]);)r++;if(r===t)return!1;try{i=decodeURIComponent(e.slice(t,r))}catch(n){i=e.slice(t,r)}return!(r<e.length&&"?"===e[r]&&o.length>0)&&{params:{[n.name]:i},nextIndex:r}}case"splat":{let r=e.length;const s=o[0];if(s)switch(s.type){case"literal":if("."===s.value){const n=e.indexOf(".",t);-1!==n&&(r=n)}else{const n=e.lastIndexOf(s.value);-1!==n&&n>=t&&(r=n)}break;case"param":let n=-1;for(let o=e.length-1;o>=t;o--)if("/"===e[o]){n=o;break}-1!==n&&(r=n);break;case"splat":let o=-1;for(let n=e.length-1;n>t;n--)if("/"===e[n]){o=n+1;break}if(-1!==o)r=o;else{const n=e.slice(t).split("/").filter(e=>e);r=n.length>1?t+n.slice(0,-1).join("/").length+1:t}break;case"optional":const i=e=>{for(const t of e){if("literal"===t.type)return t.value;if("optional"===t.type){const e=i(t.segments);if(e)return e}}return null},a=i(s.segments);if(a){const n=e.lastIndexOf(a);-1!==n&&n>=t&&(r=n)}}const i=e.indexOf("?",t);let a;-1!==i&&i<r&&(r=i);try{a=decodeURIComponent(e.slice(t,r))}catch(n){a=e.slice(t,r)}return{params:{[n.name]:a},nextIndex:r}}case"optional":{let r=t,s={},i=!0;for(let t=0;t<n.segments.length;t++){const o=n.segments[t],a=n.segments.slice(t+1),c=this.matchSegment(e,r,o,a);if(!1===c){i=!1;break}Object.assign(s,c.params),r=c.nextIndex}return i&&this.canMatchRemainingSegments(e,r,o)?{params:s,nextIndex:r}:{params:{},nextIndex:t}}default:return!1}}findNextLiteral(e){for(const t of e){if("literal"===t.type)return t;if("optional"===t.type){const e=this.findNextLiteral(t.segments);if(e)return e}}return null}matchQuery(e,t){if(0===t.length)return{};const n={};let o=0;for(const r of t)switch(r.type){case"literal":if(e.slice(o,o+r.value.length)!==r.value)return!1;o+=r.value.length;break;case"param":{let t,s=o;for(;s<e.length&&"&"!==e[s];)s++;if(s===o)return!1;try{t=decodeURIComponent(e.slice(o,s))}catch(n){t=e.slice(o,s)}n[r.name]=t,o=s;break}}return n}reverse(e={}){const t=this.reverseSegments(this.parsed.pathSegments,e);if(!1===t)return!1;let n=t;if(this.parsed.querySegments.length>0){const t=this.reverseSegments(this.parsed.querySegments,e);if(!this.parsed.queryOptional&&!1===t)return!1;t&&""!==t&&(n+="?"+t)}return n}reverseSegments(e,t,n=!1){let o="";for(let r=0;r<e.length;r++){const s=e[r],i=e.slice(r+1);switch(s.type){case"literal":o+=s.value;break;case"param":case"splat":if(!(s.name in t))return!1;o+=String(t[s.name]);break;case"optional":if(this.hasAllParams(s.segments,t,n)||this.hasLaterOptionalGroupNeedingParams(i,t,s.segments)){const e=this.reverseSegments(s.segments,t,!0);if(!1===e)return!1;o+=e}}}return o}hasLaterOptionalGroupNeedingParams(e,t,n){for(const o of e)if("optional"===o.type&&this.hasAnyParamInSegments(o.segments,t))return this.hasOnlyLiteralsAndOptionals(n);return!1}hasOnlyLiteralsAndOptionals(e){for(const t of e)if("param"===t.type||"splat"===t.type)return!1;return!0}hasAllParams(e,t,n=!1){let o=!1,r=!1,s=!1,i=!0;for(const n of e)switch(n.type){case"param":case"splat":i=!1,n.name in t&&void 0!==t[n.name]?o=!0:s=!0}const a=n||o&&!s;for(const n of e)"optional"===n.type&&this.hasAllParams(n.segments,t,a)&&(r=!0);return!(!o||s)||!(!r||s)||!(!i||!n)}hasOnlyOptionalMissingParams(e,t){for(const n of e)switch(n.type){case"param":case"splat":if(!(n.name in t))return!1}return!0}hasAnyParamInSegments(e,t){for(const n of e)switch(n.type){case"param":case"splat":if(n.name in t)return!0;break;case"optional":if(this.hasAnyParamInSegments(n.segments,t))return!0}return!1}}function Go(e){const t=e.split("/").filter(Boolean);let n=t.length;for(const e of t)e.startsWith("*")?n+=-2:e.startsWith(":")?n+=3:n+=10;return n}function Qo(e){const t={};return e.split(";").forEach(e=>{const n=e.indexOf(":");if(-1===n)return;const o=e.slice(0,n).trim(),r=e.slice(n+1).trim();o&&r&&(t[o]=r)}),t}function Jo(e,t,n,o){if(e.style.position="absolute",e.style.width="100%",t)return e.style.height="100%",void(e.style.transition=`opacity ${n}ms ease-in-out`);e.style.top="0",e.style.left="0",e.style.transition=`${o} ${n}ms ease-in-out`}function Xo(e,t){Object.defineProperty(e.prototype,r,{value:!0,configurable:!0})}function Yo(e){if(!dt(e))throw new TypeError("Application contexts may provide only instances of @daemon classes.");const t=ft(e);if(0===t.bindings){t.active=!0;try{Ot(e,t.target),bt(e,t.target)}catch(n){throw vt(e),$t(e),t.active=!1,n}}t.bindings+=1;let n=!1;return()=>{n||(n=!0,t.bindings=Math.max(0,t.bindings-1),0===t.bindings&&(vt(e),$t(e),ho(e),t.active=!1,t.target=new EventTarget))}}function Zo(e,t){const n=function(e,t){if(!e||"function"!=typeof e.addEventListener||"function"!=typeof e.removeEventListener)throw new TypeError("provideContext() requires an EventTarget root.");if(!t||"object"!=typeof t)throw new TypeError("provideContext() requires an application context object.");if(ht.has(e))throw new Error("This root already provides an application context. Release it before providing another.");const n=e=>{const n=e;n.detail&&void 0===n.detail.context&&(n.detail.context=t,n.preventDefault(),n.stopPropagation())};e.addEventListener(lt,n),ht.set(e,{listener:n});let o=!1;return()=>{if(o)return;o=!0;const t=ht.get(e);t?.listener===n&&(e.removeEventListener(lt,n),ht.delete(e))}}(e,t);let o;try{o=function(e){const t=e.daemons;if(void 0===t)return()=>{};if(!t||"object"!=typeof t||Array.isArray(t))throw new TypeError("AppContext.daemons must be a readonly record of named @daemon instances.");const n=[],o=new Set;try{for(const[e,r]of Object.entries(t)){if(!e.trim())throw new TypeError("AppContext.daemons keys must be non-empty strings.");if(!r||"object"!=typeof r)throw new TypeError(`AppContext.daemons["${e}"] must be an instance of an @daemon class.`);o.has(r)||(o.add(r),n.push(Yo(r)))}}catch(e){for(const e of n.reverse())e();throw e}return()=>{for(const e of n.reverse())e()}}(t)}catch(e){throw n(),e}let r=!1;return()=>{r||(r=!0,n(),o?.())}}const er=new WeakMap;var tr;function nr(e){const t=e.window??window,n=e.document??document,o=[];let r,s,i,a=!1,c=[],l=null,h=null;const u=e.context||{};let d=null,f=null;const m=new De(u,[],"",{},e.fetcher);function p(e){if(d===e&&f&&er.get(e)===f)return;f?.(),er.get(e)?.();const t=Zo(e,u);let n=!1;const o=()=>{n||(n=!0,t(),er.get(e)===o&&er.delete(e))};f=o,d=e,er.set(e,o)}function y(e){if(!l||!h)return null;const t=e.querySelectorAll(l);for(const e of t)if(e[F]===h)return e;return null}function g(e,t,n,c,l,h){switch(o.push({route:new Ko(e),tag:t,transition:n,guards:c,layout:l,placard:h}),a=!1,e){case"/404":r=t;break;case"/403":s=t;break;case"/":i=t}}function b(){const e=new Set;c=o.filter(e=>e.placard).map(e=>{const t=e.placard;return"function"==typeof t?t(u):t}).filter(t=>!e.has(t.name)&&(e.add(t.name),!0))}function v(e,t,n){m[ge](u,c,t,n)}function w(){switch(e.type){case"hash":return t.location.hash.slice(1);case"pushstate":return`${t.location.pathname}${t.location.search}`}}function E(e){let t;if(s)t=n.createElement(s),t[q]=u;else{const e=n.createElement("div");e.className="default-403",e.innerHTML="<h1>403</h1><p>Unauthorized</p>",t=e}e.innerHTML="",e.appendChild(t),l=null,h=null}async function N(e,t,o,r){if(!e)return!0;const s=Array.isArray(e)?e:[e];let i=null,a=null;a=setTimeout(()=>{r&&r()||(i=function(){const e=n.createElement("div");return e.setAttribute("data-snice-loading",""),e.innerHTML='\n <style>@keyframes snice-spin{to{transform:rotate(360deg)}}</style>\n <div style="display:flex;align-items:center;justify-content:center;height:100%;min-height:200px">\n <div style="width:32px;height:32px;border:3px solid rgba(128,128,128,0.3);border-top-color:rgba(128,128,128,0.8);border-radius:50%;animation:snice-spin 0.6s linear infinite"></div>\n </div>',e}(),o.appendChild(i))},50);try{for(const e of s)if(!await e(u,t))return r&&r()||E(o),!1;return!0}finally{a&&clearTimeout(a),i&&i.remove()}}async function A(t,o,r,s,i,a,d){const f=!1===(m=s)?null:m||(e.layout?e.layout:null);var m;const{element:p,needsNewLayout:g}=function(e){if(e===l)return{element:null,needsNewLayout:!1};if(l=e,e){const t=Date.now();h=t;const o=n.createElement(e);return o[q]=u,o[F]=t,{element:o,needsNewLayout:!0}}return h=null,{element:null,needsNewLayout:!0}}(f),b=r||e.transition;if(null!==p||null!==y(t)){if(await async function(e,t,n,o,r,s,i,a){const l=o||y(e);if(!l)return;!function(e,t,n){"function"==typeof e.update&&e.update(u,c,t,n)}(l,s,i);const h=l.querySelector('[slot="page"]');if(n&&h){if(t.setAttribute("slot","page"),await _(l,h,t,n),a&&a())return;r&&(e.innerHTML="",e.appendChild(l))}else a&&a()||(l.querySelectorAll('[slot="page"]').forEach(e=>e.remove()),t.setAttribute("slot","page"),l.appendChild(t),r&&(e.innerHTML="",e.appendChild(l)))}(t,o,b,p,g,i,a,d),d&&d())return;v(0,i,a)}else await async function(e,t,n,o){const r=e.children[0];n&&r?await _(e,r,t,n):o&&o()||(e.innerHTML="",e.appendChild(t))}(t,o,b,d),d&&d()||v(0,i,a)}let S=0;async function T(s){const a=n.querySelector(e.target);if(!a)throw new Error(`Target element not found: ${e.target}`);p(a);const c=++S,l=()=>c!==S;if(b(),t.scrollTo(0,0),(""===s?.trim()||"/"===s)&&i){const e=o.find(e=>e.route.match("/"));if(!await N(e?.guards,{},a,l))return;if(l())return;const{element:r,transition:c,layout:h}=function(){const e=n.createElement(i);e[q]=u;const r=t.customElements.get(i),s=r?.[B],a=o.find(e=>e.route.match("/"));return{element:e,transition:s,layout:a?.layout}}();return void await A(a,r,c,h,s,{},l)}if(!s)return;const h=await async function(e,t,r){for(const s of o){const o=s.route.match(e);if(!1===o)continue;if(!await N(s.guards,o,t,r))return{result:tr.GUARDS_FAILED};const i=n.createElement(s.tag);i[q]=u,i[ce]=m;const a=o;return Object.keys(a).forEach(e=>i.setAttribute(e,a[e])),{result:tr.SUCCESS,element:i,transition:s.transition,layout:s.layout,routeParams:a}}return{result:tr.NOT_FOUND}}(s,a,l);if(l())return;if(h.result===tr.GUARDS_FAILED)return;if(h.result===tr.SUCCESS){const{element:e,transition:t,layout:n,routeParams:o={}}=h;return void await A(a,e,t,n,s,o,l)}const{element:d,transition:f,layout:y}=function(){if(r){const e=n.createElement(r);e[q]=u;const o=t.customElements.get(r),s=o?.[B];return{element:e,transition:s,layout:void 0}}const e=n.createElement("div");return e.className="default-404",e.innerHTML="<h1>404</h1><p>Page not found</p>",{element:e,transition:void 0,layout:void 0}}();await A(a,d,f,y,s,{},l)}async function _(e,t,n,o,r=S){return async function(e,t,n,o={},r=()=>!1){const s=o.outDuration??300,i=o.inDuration??300,a=o.mode||"sequential",c=o.out?Qo(o.out):{opacity:"0"},l={opacity:"0"},h=o.in?Qo(o.in):{opacity:"1"},u=e.style,d=e.tagName.includes("-")&&e.shadowRoot,f=Symbol.for("snice:transition-original-position"),m=Symbol.for("snice:transition-count"),p=e;d||(f in p||(p[f]=u.position,p[m]=0),p[m]++,u.position="relative");const y=()=>{d||(p[m]--,p[m]<=0&&(u.position=p[f],delete p[f],delete p[m]))},g=t.hasAttribute("slot")||n.hasAttribute("slot");switch(Jo(t,g,s,"all"),Jo(n,g,i,"all"),Object.assign(n.style,l),e.appendChild(n),a){case Le.SIMULTANEOUS:Object.assign(t.style,c),Object.assign(n.style,h),await new Promise(e=>setTimeout(e,Math.max(s,i)));break;case Le.SEQUENTIAL:if(Object.assign(t.style,c),await new Promise(e=>setTimeout(e,s)),r())return n.parentNode===e&&n.remove(),void y();Object.assign(n.style,h),await new Promise(e=>setTimeout(e,i))}if(r())return n.parentNode===e&&n.remove(),void y();t.remove(),function(e,t){e.style.position="",e.style.width="",e.style.transition="",t?e.style.height="":(e.style.top="",e.style.left="")}(n,g),Object.keys({...l,...h}).forEach(e=>{n.style[e]=""}),y()}(e,t,n,o,()=>r!==S)}return{page:function(e){return function(n,o){if(o?.metadata&&o.metadata[k]){n[k]||(n[k]=new Map);for(const[e,t]of o.metadata[k])n[k].set(e,t)}To(n),n[B]=e.transition;const r=n.prototype.connectedCallback;n.prototype.connectedCallback=function(){this[ce]=m,r?.call(this)};const s=n.prototype.disconnectedCallback;return n.prototype.disconnectedCallback=function(){s?.call(this),delete this[q],delete this[ce]},t.customElements.get(e.tag)||t.customElements.define(e.tag,n),e.routes.forEach(t=>g(t,e.tag,e.transition,e.guards,e.layout,e.placard)),n}},initialize:function(){const r=n.querySelector(e.target);if(!r)throw new Error(`Target element not found: ${e.target}`);p(r),!a&&(o.sort((e,t)=>Go(t.route.spec)-Go(e.route.spec)),a=!0),b(),function(){const o=()=>{const t=n.querySelector(e.target);if(t&&(d!==t||!f||er.get(t)===f))return d!==t&&ht.has(t)?(f?.(),f=null,void(d=null)):void T(w())};switch(e.type){case"hash":t.addEventListener("hashchange",o);break;case"pushstate":t.addEventListener("popstate",o)}}(),T(w())},navigate:async function(n){const o=function(e){const t=e.trim().replace(/^#/,"");return t?t.startsWith("/")?t:`/${t}`:"/"}(n);!function(n){switch(e.type){case"hash":{const e=`#${n}`;t.location.hash!==e&&t.history.pushState(null,"",e);break}case"pushstate":`${t.location.pathname}${t.location.search}`!==n&&t.history.pushState(null,"",n)}}(o),await T(o)},register:g}}function or(e,t,n){const o=[];for(const[r,s]of Object.entries(t)){const t=`@request/${r}`,i=e=>{const t=e,{discovery:o,data:i,payload:a}=t.detail;n?.passive||(t.preventDefault(),t.stopImmediatePropagation(),t.stopPropagation()),o.resolve(),Promise.resolve().then(()=>s(a)).then(e=>i.resolve(e)).catch(e=>{i.reject(e),console.error(`createRequestHandler: error in "${r}" handler:`,e)})};e.addEventListener(t,i),o.push(()=>e.removeEventListener(t,i))}return()=>{for(const e of o)e();o.length=0}}function rr(e){let t="";for(const n of Object.keys(e))e[n]&&(t+=(t?" ":"")+n);return t}function sr(e){const t=[];for(const n of Object.keys(e)){const o=e[n];if(null==o||!1===o)continue;const r=n.startsWith("--")?n:n.replace(/[A-Z]/g,e=>"-"+e.toLowerCase());t.push(`${r}: ${o}`)}return t.join("; ")}!function(e){e.SUCCESS="success",e.GUARDS_FAILED="guards-failed",e.NOT_FOUND="not-found"}(tr||(tr={}));let ir=!1;function ar(e){ir=e}async function cr(e,t=500){if(customElements.get(e))return;let n=null;ir||(n=setTimeout(()=>{console.warn(`Custom element <${e}> is taking longer than ${t}ms to register. This may indicate a missing import or circular dependency. Set DISABLE_ELEMENT_READY_WARNINGS=true to disable this warning.`)},t));try{await customElements.whenDefined(e)}finally{n&&clearTimeout(n)}}async function lr(e,t=500){const n=e.tagName.toLowerCase();await cr(n,t),"ready"in e&&"function"==typeof e.ready?.then&&await e.ready}async function hr(e,t=500){const n=[];e instanceof Element&&(e.tagName.includes("-")&&n.push(e),e.shadowRoot)&&e.shadowRoot.querySelectorAll("*").forEach(e=>{e.tagName.includes("-")&&n.push(e)}),e instanceof DocumentFragment&&e.querySelectorAll("*").forEach(e=>{e.tagName.includes("-")&&n.push(e)}),await Promise.all(n.map(e=>lr(e,t)))}async function*ur(e){for(;;)await new Promise(t=>{e[oe]||(e[oe]=[]),e[oe].push(t)}),yield}let dr=0,fr=null;const mr=Symbol.for("snice:body-scroll-lock");function pr(){0===dr&&(fr=document.body.style.overflow,document.body.style.overflow="hidden"),dr++}function yr(){0!==dr&&(dr--,0===dr&&(document.body.style.overflow=fr??"",fr=null))}function gr(){return dr}globalThis[mr]={clear(){dr=0,fr=null}};class br{constructor(){this.requestMiddlewares=[],this.responseMiddlewares=[]}use(e,t){"request"!==e?this.responseMiddlewares.push(t):this.requestMiddlewares.push(t)}create(e){const t=this.requestMiddlewares,n=this.responseMiddlewares;return async function(e,o){const r=new Request(e,o);let s=0;const i=async()=>{if(s<t.length)return t[s++].call(this,r,i);const e=await fetch(r);let o=0;const a=async()=>o<n.length?n[o++].call(this,e,a):e;return a()};return i()}.bind(e)}}var vr;"undefined"!=typeof document&&qt(),globalThis.snice||(globalThis.snice={controllerRegistry:new Map,pendingControllerAttachments:new Map,controllerIdCounter:0}),globalThis.snice.pendingControllerAttachments??=new Map,function(e){e.SEQUENTIAL="sequential",e.SIMULTANEOUS="simultaneous"}(vr||(vr={}));export{De as Context,br as ContextAwareFetcher,o as IS_CONTROLLER_INSTANCE,nr as Router,ke as SimpleArray,Ho as SniceElement,Le as TransitionMode,Uo as adopted,To as applyElementFunctionality,It as attachController,rr as classMap,wo as clearDebounceTimers,No as clearMemoizeCache,Eo as clearThrottleTimers,Ft as context,Io as contextProperty,Lt as controller,or as createRequestHandler,Qt as css,Xo as daemon,yo as debounce,Dt as detachController,lo as dispatch,qo as dispose,xo as element,ze as escapeAttr,We as escapeHtml,gr as getBodyScrollLockCount,ut as getContext,Vt as getController,t as getSymbol,Kt as html,Ue as isSafeUrl,Co as layout,bn as live,pr as lockBodyScroll,vo as memoize,zo as moved,yn as noChange,Yt as nothing,nt as observe,_t as on,bo as once,He as parseDuration,ko as property,Zo as provideContext,jo as query,Mo as queryAll,Vo as ready,Bo as reconnect,ao as render,on as repeat,yt as request,Ao as resetOnce,gt as respond,ar as setDisableElementReadyWarnings,Xn as setStrictRenderErrors,Lo as state,sr as styleMap,co as styles,Gt as svg,go as throttle,ur as trackRenders,yr as unlockBodyScroll,en as unsafeHTML,qt as useNativeElementControllers,hr as waitForAllCustomElements,cr as waitForElementDefined,lr as waitForElementReady,Ro as watch};
|
|
1
|
+
globalThis.snice||(globalThis.snice={controllerRegistry:new Map,pendingControllerAttachments:new Map,controllerIdCounter:0}),globalThis.snice.pendingControllerAttachments??=new Map;const e=globalThis.snice;function t(e){return Symbol.for(`snice:${e}`)}const n=t("is-controller-class"),o=t("is-controller-instance"),r=t("is-daemon-class"),s=t("is-daemon-instance"),i=t("is-element-class"),a=t("channel-handlers"),c=t("daemon-state"),l=t("ready-promise"),h=t("ready-resolve"),u=t("ready-reject"),d=t("ready-handlers-running"),f=t("rendered-promise"),m=t("rendered-resolve"),p=t("pending-reconnect-render"),y=t("render-depth"),g=t("render-root"),b=t("element-options"),v=t("controller"),w=t("initialized"),E=t("controller-key"),N=t("controller-name"),A=t("controller-id"),S=t("controller-operations"),T=t("native-controller"),_=t("controller-registry-name"),x=t("direct-controller"),C=t("controller-attribute-sync"),O=t("pending-controller-binding"),k=t("cleanup"),$=t("properties"),L=t("property-values"),P=t("property-defaults"),j=t("property-wrappers"),M=t("pre-init-property-values"),R=t("pre-upgrade-property-bindings"),I=t("properties-initialized"),D=t("property-watchers"),V=t("explicitly-set-properties"),q=t("router-context"),B=t("page-transition"),F=t("created-at"),W=t("ready-handlers"),z=t("dispose-handlers"),U=t("reconnect-handlers"),H=t("moved-handlers"),K=t("adopted-handlers"),G=t("observers"),Q=t("setting-from-property"),J=t("moved-timers"),X=t("adopted-timers"),Y=t("dispatch-timers"),Z=t("render-method"),ee=t("render-options"),te=t("render-instance"),ne=t("render-timers"),oe=t("render-callbacks"),re=t("styles-method"),se=t("styles-applied"),ie=t("parent-styles-methods"),ae=t("snice-element-base"),ce=t("context-handler"),le=t("navigation-context-instance"),he=t("registered-elements"),ue=t("is-updating"),de=t("context-register"),fe=t("context-unregister"),me=t("context-notify-element"),pe=t("context-timer"),ye=t("context-called"),ge=t("context-update"),be=t("context-methods"),ve=t("watch-methods"),we=t("observe-methods"),Ee=t("on-methods"),Ne=t("respond-methods"),Ae=t("ready-methods"),Se=t("dispose-methods"),Te=t("reconnect-methods"),_e=t("moved-methods"),xe=t("adopted-methods"),Ce=t("controller-abort"),Oe=t("controller-attached"),ke=t("property-definers");class $e{static{this.SEPARATOR=","}static serialize(e){return Array.isArray(e)?e.map(e=>{if("string"==typeof e){if(e.includes($e.SEPARATOR))throw new Error(`SimpleArray strings cannot contain the character "${$e.SEPARATOR}" (U+FF0C)`);return e}if("number"==typeof e||"boolean"==typeof e)return String(e);throw new Error("SimpleArray only supports string, number, and boolean types. Got: "+typeof e)}).join($e.SEPARATOR):""}static parse(e){return null==e||""===e?[]:e.split($e.SEPARATOR).map(e=>{if(/^-?\d+\.?\d*$/.test(e)){const t=Number(e);if(!isNaN(t))return t}return"true"===e||"false"!==e&&e})}}var Le,Pe,je,Me;!function(e){e.SEQUENTIAL="sequential",e.SIMULTANEOUS="simultaneous"}(Le||(Le={}));const Re=Symbol.for("snice:registered-elements-set");let Ie=0;class De{constructor(e={},t=[],n="",o={},r){if(this[Pe]=new WeakMap,this[je]=new Set,this[Me]=!1,this.id=Ie++,this.application=e,this.navigation={placards:t,route:n,params:o},r&&"function"==typeof r.create)this.fetch=r.create(this);else{if("function"!=typeof fetch)throw new Error("No fetch implementation available");this.fetch=fetch.bind(this)}}[(Pe=he,je=Re,Me=ue,de)](e,t){const n=this[he];let o=n.get(e);o||(o=new Set,n.set(e,o)),o.add(t),this[Re].add(e)}[fe](e,t){const n=this[he];if(void 0!==t){const o=n.get(e);if(!o)return;if(o.delete(t),o.size>0)return}n.delete(e),this[Re].delete(e)}[ge](e,t,n,o){this.application=e,this.navigation.placards=t,this.navigation.route=n,this.navigation.params=o,this.notify()}update(){this.notify()}notify(){if(this[ue])return;this[ue]=!0;const e=this[Re],t=this[he];for(const n of e){const e=t.get(n);if(e)for(const t of e)if("function"==typeof n[t])try{n[t](this)}catch(e){console.error(`Error calling @context method ${t}:`,e)}}this[ue]=!1}[me](e){const t=this[he].get(e);if(t)for(const n of t)if("function"==typeof e[n])try{e[n](this)}catch(e){console.error(`Error calling @context method ${n}:`,e)}}}function Ve(e){if(null!=e)return"string"==typeof e?String:"number"==typeof e?Number:"boolean"==typeof e?Boolean:e instanceof Date?Date:"bigint"==typeof e?BigInt:Array.isArray(e)?Array:void 0}function qe(e,t,n,o){const r=t.type||Ve(o);if(t.converter?.fromAttribute)return t.converter.fromAttribute(e,r);switch(r){case Boolean:return null!==e&&"false"!==e;case Number:return null!==e?Number(e):null;case String:return e;case Date:return e?new Date(e):null;case BigInt:return e&&e.endsWith("n")?BigInt(e.slice(0,-1)):e?BigInt(e):null;case $e:return $e.parse(e);case Array:try{return e?JSON.parse(e):[]}catch{return[]}case Object:try{return e?JSON.parse(e):{}}catch{return{}}default:return"number"==typeof n&&null!==e?Number(e):e}}function Be(e,t){return e!==t&&(e==e||t==t)}function Fe(e,t){return"string"==typeof e.attribute?e.attribute.toLowerCase():!0===e.attribute||"kebab"===e.attributeNaming?t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase():t.toLowerCase()}function We(e){return String(e??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function ze(e){return String(e??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function Ue(e,t={}){let n;try{n=String(e??"")}catch{return!1}if(!n||/[\u0000-\u001f\u007f]/.test(n))return!1;const o=n.trim();if(!o)return!1;const r=t.allowed??["http:","https:","mailto:","tel:"];try{const e=new URL(o,"http://__snice-relative.invalid/"),t=/^[a-z][a-z\d+.-]*:/i.test(o),n=/^[\\/]{2}/.test(o);return!t&&!n||r.some(t=>"string"==typeof t&&t.toLowerCase()===e.protocol)}catch{return!1}}function He(e){const t=String(e).trim(),n=parseFloat(t);let o;return o=isNaN(n)?0:/ms$/i.test(t)?n:/s$/i.test(t)?1e3*n:/m$/i.test(t)?6e4*n:/h$/i.test(t)?36e5*n:n,{milliseconds:()=>o,seconds:()=>o/1e3,minutes:()=>o/6e4}}function Ke(e,t){return e[t]||(e[t]=new Set),e[t]}function Ge(e,t){return e[t]||(e[t]={}),e[t]}function Qe(e,t,n,o,r){const s=t[D];if(!s)return;const i=[n],a=t[$]?.get(n),c=a&&"string"==typeof a.attribute?a.attribute:null;c&&c!==n&&i.push(c);for(const t of i)if(s.has(t))for(const i of s.get(t))try{i.method.call(e,o,r,n)}catch(e){console.error(`Error in @watch('${t}') method ${i.methodName}:`,e)}if(s.has("*"))for(const t of s.get("*"))try{t.method.call(e,o,r,n)}catch(e){console.error(`Error in @watch('*') method ${t.methodName}:`,e)}}function Je(e,t){let n=null;const o=function(...o){null!==n&&clearTimeout(n),n=setTimeout(()=>{e.apply(this,o),n=null},t)};return o.cancel=()=>{null!==n&&clearTimeout(n),n=null},o}function Xe(e,t){let n=0,o=null;return function(...r){const s=Date.now(),i=t-(s-n);if(i<=0)return o&&(clearTimeout(o),o=null),n=s,e.apply(this,r);o||(o=setTimeout(()=>{n=Date.now(),o=null,e.apply(this,r)},i))}}function Ye(e,t){if(null==t)return e;if("global"===t)return"undefined"!=typeof document?document:null;if("function"==typeof t)try{return t.call(e)||null}catch{return null}return"string"==typeof t?e.closest?.(t)||null:t&&"function"==typeof t.addEventListener?t:null}function Ze(e,t,n){if(null==e||!1===e||t?.type===$e&&Array.isArray(e)&&0===e.length)return null;if(t.converter?.toAttribute)return t.converter.toAttribute(e,t.type);switch(t.type||Ve(n)){case Boolean:return"true";case Date:return e instanceof Date?e.toISOString():String(e);case BigInt:return"bigint"==typeof e?e.toString()+"n":String(e);case $e:return Array.isArray(e)?$e.serialize(e):String(e);case Array:return Array.isArray(e)?JSON.stringify(e):String(e);case Object:return"object"==typeof e&&null!==e?JSON.stringify(e):String(e);default:return String(e)}}const et=new WeakSet,tt=new Map;function nt(e,t,n){let o,r;return"string"==typeof t?(o=t,r=n):(o=void 0,r=t),function(t,n){const s=n.name;n.addInitializer(function(){const n=this.constructor;if(Object.prototype.hasOwnProperty.call(n,we)||(n[we]=new Set),n[we].has(t))return;if(n[we].add(t),!Object.prototype.hasOwnProperty.call(n,G)){const e=n[G];n[G]=e?[...e]:[]}const i=Array.isArray(e)?e:[e];for(const e of i){const[i,...a]=e.split(":"),c=a.join(":");n[G].push({type:i,target:c,selector:o,methodName:s,method:t,options:r})}})}}function ot(e,t){const n=e.constructor[G];if(n&&Array.isArray(n)&&0!==n.length){e[k]?e[k].observers||(e[k].observers=[]):e[k]={events:[],channels:[],observers:[]};for(const o of n){const n=o.method.bind(e),r=o.options?.throttle?Xe(n,o.options.throttle):n;switch(o.type){case"intersection":rt(e,t,o,r);break;case"resize":st(e,t,o,r);break;case"media":it(e,0,o,r);break;case"mutation":at(e,t,o,r);break;default:console.warn(`Unknown observer type: ${o.type}`)}}}}function rt(e,t,n,o){const r={threshold:n.options?.threshold??0,rootMargin:n.options?.rootMargin??"0px",root:n.options?.root??null};if("undefined"==typeof IntersectionObserver)return void console.warn("IntersectionObserver is not available in this environment");const s=new IntersectionObserver(e=>{for(const t of e)try{!1===o(t)&&s&&s.unobserve(t.target)}catch(e){console.error(`Error in intersection observer ${n.methodName}:`,e)}},r),i=n.selector?Array.from(t.shadowRoot?.querySelectorAll(n.selector)||[]):[t];i.forEach(e=>s.observe(e)),e[k].observers.push(()=>{i.forEach(e=>s.unobserve(e)),0===s.takeRecords().length&&s.disconnect()})}function st(e,t,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(e=>{for(const t of e)try{o(t)}catch(e){console.error(`Error in resize observer ${n.methodName}:`,e)}});(n.selector?Array.from(t.shadowRoot?.querySelectorAll(n.selector)||[]):[t]).forEach(e=>{s.observe(e,{box:r})}),e[k].observers.push(()=>{s.disconnect()})}function it(e,t,n,o){const r=n.target;if(!r)return void console.warn("Media query observer requires a query string");let s=tt.get(r);if(!s)try{s=window.matchMedia(r),tt.set(r,s)}catch(e){return void console.error(`Invalid media query: ${r}`,e)}const i=e=>{try{o(e.matches)}catch(e){console.error(`Error in media query observer ${n.methodName}:`,e)}};i(s);const a=e=>i(e);s.addEventListener?(s.addEventListener("change",a),e[k].observers.push(()=>{s.removeEventListener("change",a)})):(s.addListener(a),e[k].observers.push(()=>{s.removeListener(a)}))}function at(e,t,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(/^[.#[]/.test(i)?console.warn(`@observe: "mutation:${i}" — "${i}" looks like a selector. Selectors are the second argument — did you mean @observe('mutation:childList', '${i}')?`):console.warn(`Unknown mutation type: ${i} (expected childList or attributes)`))}n.options?.subtree&&(c.subtree=!0,n.options.maxDepth&&console.warn("maxDepth is set but requires custom implementation"));const l=!(!n.options?.maxDepth||!n.options.subtree),h=new MutationObserver(e=>{try{if(!l)return void r(e);const o=n.options.maxDepth,s=t.shadowRoot||t,i=e.filter(e=>{let t=0,n=e.target;for(;n&&n!==s&&t<o;)n=n.parentNode,t++;return t<o});i.length>0&&r(i)}catch(e){console.error(`Error in mutation observer ${n.methodName}:`,e)}}),u=!0===e[o];(n.selector?Array.from(t.shadowRoot?.querySelectorAll(n.selector)||[]):u&&t.shadowRoot?[t.shadowRoot]:[t]).forEach(e=>{h.observe(e,c)}),e[k].observers.push(()=>{h.disconnect()})}function ct(e){if(e[k]?.observers){for(const t of e[k].observers)t();e[k].observers=[]}}const lt="@context/request",ht=new WeakMap;function ut(e){return!e||"object"!=typeof e&&"function"!=typeof e?null:!0===e[o]?e.element&&"function"==typeof e.element.dispatchEvent?e.element:null:"function"==typeof e.dispatchEvent?e:null}function dt(e){if(!e||"object"!=typeof e&&"function"!=typeof e)return;const t=ut(e);if(t){const e={kind:"application"};if(t.dispatchEvent(new CustomEvent(lt,{bubbles:!0,composed:!0,cancelable:!0,detail:e})),void 0!==e.context)return e.context}const n=e;return void 0!==n[q]?n[q]:!0===n[o]&&void 0!==n.element?.[q]?n.element[q]:void 0}function ft(e){const t=ut(e);if(!t)return;const n={kind:"fetch"};return t.dispatchEvent(new CustomEvent(lt,{bubbles:!0,composed:!0,cancelable:!0,detail:n})),n.fetch}function mt(e){return!!e&&("object"==typeof e||"function"==typeof e)&&!0===e[r]}function pt(e){if(!mt(e))throw new TypeError("Application contexts may provide only instances of @daemon classes.");let t=e[c];if(!t){t={target:new EventTarget,bindings:0,active:!1};try{Object.defineProperty(e,c,{value:t,configurable:!0}),Object.defineProperty(e,s,{value:!0,configurable:!0})}catch{throw new TypeError("@daemon instances must remain extensible until they are provided to an app context.")}}return t}function yt(e,t){if("string"!=typeof t||!t.trim())throw new TypeError("Daemon addresses must be non-empty strings.");const n=dt(e);if(!n)throw new Error(`[snice] ${function(e){const t=e;return!0===t?.[o]?"controller":mt(t)?"@daemon instance":"element"}(e)} cannot resolve daemon "${t}" because no app context is provided.`);const r=n.daemons?.[t];if(!r)throw new Error(`[snice] app context does not provide daemon "${t}".`);if(!mt(r))throw new TypeError(`[snice] app context entry "${t}" is not an instance of an @daemon class.`);const s=pt(r);if(!s.active)throw new Error(`[snice] daemon "${t}" is not active because its app context has not been provided.`);return s.target}function gt(e){return mt(e)?function(e){return pt(e).target}(e):!0===e?.[o]?e.element&&"function"==typeof e.element.dispatchEvent?e.element:null:e&&"function"==typeof e.dispatchEvent?e:null}function bt(e,t){return function(n,o){let r,s,i=0;const a=[];return async function(...o){const c=async()=>{const r=t?.timeout??12e4,s=t?.discoveryTimeout??50,i=void 0!==t?.daemon?yt(this,t.daemon):gt(this);if(!i)throw new TypeError(`@request('${e}') requires an element, attached controller, or provided @daemon instance.`);const a=n.apply(this,o),{value:c,done:l}=await a.next();if(l)return c;let h,u;const d=new Promise((e,t)=>{h=e,u=t});let f,m,p,y=!1;const g=new Promise((t,n)=>{f=t,m=n,p=setTimeout(()=>{n(new Error(`Request "${e}" found no @respond('${e}') handler within ${s}ms — attach a responding controller/element, or pass { optional: true } to resolve undefined when unhandled.`))},s)}),b=new CustomEvent(`@request/${e}`,{bubbles:void 0===t?.bubbles||t.bubbles,cancelable:t?.cancelable||!1,composed:!0,detail:{payload:c,discovery:{resolve:()=>{y=!0,clearTimeout(p),f()},reject:m},data:{resolve:h,reject:u}}});i.dispatchEvent(b);try{await g;const t=setTimeout(()=>{u(new Error(`Request "${e}" timed out after ${r}ms`))},r),n=await d;clearTimeout(t);const{value:o}=await a.next(n);return o}catch(e){if(t?.optional&&!y){const{value:e}=await a.next(void 0);return e}const{value:n}=await a.throw(e);return n}};if(t?.debounce)return new Promise((e,n)=>{clearTimeout(r),r=setTimeout(async()=>{try{e(await c())}catch(e){n(e)}},t.debounce)});if(!t?.throttle)return c();const l=Date.now(),h=t.throttle-(l-i);if(h<=0){clearTimeout(s),s=null,i=l;const e=a.splice(0),t=c();return e.length&&t.then(t=>{for(const n of e)n.resolve(t)},t=>{for(const n of e)n.reject(t)}),t}return new Promise(s?(e,t)=>{a.push({resolve:e,reject:t})}:(e,t)=>{a.push({resolve:e,reject:t}),s=setTimeout(async()=>{i=Date.now(),s=null;const e=a.splice(0);try{const t=await c();for(const n of e)n.resolve(t)}catch(t){for(const n of e)n.reject(t)}},h)})}}}function vt(e,t){return function(n,o){const r=o.name;o.addInitializer(function(){const o=this.constructor;if(Object.prototype.hasOwnProperty.call(o,Ne)||(o[Ne]=new Set),!o[Ne].has(n)){if(o[Ne].add(n),!Object.prototype.hasOwnProperty.call(o,a)){const e=o[a];o[a]=e?[...e]:[]}o[a].push({channelName:e,methodName:r,method:n,options:t})}})}}function wt(e,t){const n=e.constructor[a];if(n){e[k]||(e[k]={events:[],channels:[]});for(const o of n){const n=o.method.bind(e),r=`@request/${o.channelName}`;let s,i,a=0;const c=[];let l=null;const h=(e=>o.options?.debounce?(...t)=>new Promise((n,r)=>{clearTimeout(s),s=setTimeout(async()=>{try{n(await e(...t))}catch(e){r(e)}},o.options.debounce)}):o.options?.throttle?(...t)=>{const n=Date.now(),r=o.options.throttle-(n-a);if(r<=0){clearTimeout(i),i=null,a=n;const o=c.splice(0);l=null;const r=e(...t);return o.length&&Promise.resolve(r).then(e=>{for(const t of o)t.resolve(e)},e=>{for(const t of o)t.reject(e)}),r}return l=t,new Promise((n,o)=>{c.push({resolve:n,reject:o}),i||(i=setTimeout(async()=>{a=Date.now(),i=null;const n=c.splice(0),o=l??t;l=null;try{const t=await e(...o);for(const e of n)e.resolve(t)}catch(e){for(const t of n)t.reject(e)}},r))})}:e)(n),u=e=>{const{data:t,discovery:n,payload:r}=e.detail;e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation(),n.resolve(),Promise.resolve(h(r)).then(e=>{t.resolve(e)}).catch(e=>{t.reject(e),console.error(`Error in response handler ${o.methodName}:`,e)})};let d=t;if(void 0!==o.options?.daemon)try{d=yt(e,o.options.daemon)}catch(e){console.warn(`[snice/@respond] ${e.message} Responder "${o.channelName}" skipped.`);continue}d.addEventListener(r,u),e[k].channels.push(()=>{d.removeEventListener(r,u)})}}}function Et(e){if(e[k]?.channels){for(const t of e[k].channels)t();e[k].channels=[]}}const Nt=new Set(["once","prevent","preventdefault","stop","stoppropagation","capture","passive"]);function At(e){const t=e.lastIndexOf(".");if(t<0)return;const n=e.slice(t+1).toLowerCase();Nt.has(n)&&console.warn(`snice: "@${e}" is not a valid modifier — once/preventDefault/stopPropagation/capture are @on() options, not template modifiers. This registers a listener for event "${e}", which never fires.`)}function St(e){const t=e.startsWith("~");t&&(e=e.substring(1));const n=e.split("+"),o={key:"",anyModifiers:t};for(const e of n){const t=e.toLowerCase();"ctrl"===t||"control"===t?o.ctrl=!0:"alt"===t?o.alt=!0:"shift"===t?o.shift=!0:"meta"===t||"cmd"===t||"command"===t?o.meta=!0:o.key=Tt(e)}return o}function Tt(e){return{esc:"Escape",escape:"Escape",enter:"Enter",return:"Enter",space:" ",spacebar:" ",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight",arrowup:"ArrowUp",arrowdown:"ArrowDown",arrowleft:"ArrowLeft",arrowright:"ArrowRight",delete:"Delete",del:"Delete",backspace:"Backspace",tab:"Tab",home:"Home",end:"End",pageup:"PageUp",pagedown:"PageDown"}[e.toLowerCase()]||e}function _t(e,t){return e.key===t.key&&(!!t.anyModifiers||(t.ctrl?e.ctrlKey:!e.ctrlKey)&&(t.alt?e.altKey:!e.altKey)&&(t.shift?e.shiftKey:!e.shiftKey)&&(t.meta?e.metaKey:!e.metaKey))}const xt=t("on-handlers");function Ct(e,t,n){let o=null,r={};return"string"==typeof t?(o=t,r=n||{}):t&&"object"==typeof t?r=t:null===t&&n&&(r=n),function(t,n){const s=n.name;return n.addInitializer(function(){const n=this.constructor,i=Array.isArray(e)?e:[e],a=`${s}::${i.join(",")}::${o??""}::daemon:${r.daemon??""}`;if(Object.prototype.hasOwnProperty.call(n,Ee)||(n[Ee]=new Set),!n[Ee].has(a)){if(n[Ee].add(a),!Object.prototype.hasOwnProperty.call(n,xt)){const e=n[xt];n[xt]=e?[...e]:[]}for(const e of i)n[xt].push({eventName:e,selector:o,methodName:s,method:t,options:r})}}),t}}function Ot(e,t){let n=0;return function(...o){const r=Date.now();r-n>=t&&(n=r,e.apply(this,o))}}const kt=new Set(["scroll","focus","blur","load","unload","error","resize","abort","mouseenter","mouseleave","pointerenter","pointerleave"]);function $t(e,t){const n=e.constructor[xt];if(n&&Array.isArray(n)&&0!==n.length){e[k]||(e[k]={events:[],eventCancels:[],channels:[],observers:[]}),e[k].events||(e[k].events=[]),e[k].eventCancels||(e[k].eventCancels=[]),(e[k].events.length>0||e[k].eventCancels.length>0)&&Lt(e);for(const o of n){const n=e[o.methodName];let r=n?n.bind(e):o.method.bind(e);const s=o.options||{},i=["keydown","keyup","keypress"].includes(o.eventName.split(".")[0].split(":")[0]),a=i?o.eventName.indexOf("."):-1,c=i?o.eventName.indexOf(":"):-1,l=a>0&&c>0?Math.min(a,c):Math.max(a,c),h=l>0?o.eventName.substring(0,l):o.eventName,u=l>0?o.eventName.substring(l+1):null;if(l<=0&&At(o.eventName),s.debounce&&s.debounce>0){const t=Je(r,s.debounce);e[k].eventCancels.push(()=>t.cancel()),r=t}else s.throttle&&s.throttle>0&&(r=Ot(r,s.throttle));let d=null;u&&["keydown","keyup","keypress"].includes(h)&&(d=St(u));const f=(e=>d?t=>{_t(t,d)&&e(t)}:e)(r),m=void 0!==s.scope,p=void 0!==s.daemon;if(m&&p){console.warn(`[snice/@on] "${o.eventName}" cannot use both scope and daemon — listener skipped.`);continue}if((p||mt(e))&&o.selector){console.warn(`[snice/@on] "${o.eventName}" cannot delegate "${o.selector}" on a daemon target — listener skipped.`);continue}const y=m||p;let g=null;if(p)try{g=yt(e,s.daemon)}catch(e){console.warn(`[snice/@on] ${e.message} Listener "${o.eventName}" skipped.`);continue}else if(m&&(g=Ye(t,s.scope),!g)){console.warn(`[snice/@on] scope did not resolve for "${o.eventName}" on ${o.methodName} — listener skipped.`);continue}if(o.selector){const n=y?g:t.shadowRoot||t,r=e=>{const t=e.target;if(t.matches&&t.matches(o.selector)&&t||t.closest&&t.closest(o.selector)){s.preventDefault&&e.preventDefault(),s.stopPropagation&&(e.stopPropagation(),e.stopImmediatePropagation());try{f(e)}catch(e){console.error(`Error in event handler ${o.methodName}:`,e)}}},i=kt.has(h),a={capture:void 0!==s.capture?s.capture:i,once:s.once||!1,passive:s.passive||!1};n.addEventListener(h,r,a),e[k].events.push({target:n,eventName:h,handler:r,options:a})}else{const n=y?null:t.shadowRoot,r=Symbol(),i=e=>{if(!e[r]){e[r]=!0,s.preventDefault&&e.preventDefault(),s.stopPropagation&&e.stopPropagation();try{f(e)}catch(e){console.error(`Error in event handler ${o.methodName}:`,e)}}},a={capture:s.capture||!1,once:s.once||!1,passive:s.passive||!1};if(y){g.addEventListener(h,i,a),e[k].events.push({target:g,eventName:h,handler:i,options:a});continue}n&&(n.addEventListener(h,i,a),e[k].events.push({target:n,eventName:h,handler:i,options:a})),t.addEventListener(h,i,a),e[k].events.push({target:t,eventName:h,handler:i,options:a})}}}}function Lt(e){if(e[k]?.events){for(const t of e[k].eventCancels??[])t();e[k].eventCancels=[];for(const{target:t,eventName:n,handler:o,options:r}of e[k].events)t.removeEventListener(n,o,r);e[k].events=[]}}const Pt=t("context-handlers");function jt(e={}){return function(t,n){const o=n.name;return n.addInitializer(function(){const n=this.constructor;if(Object.prototype.hasOwnProperty.call(n,be)||(n[be]=new Set),!n[be].has(t)){if(n[be].add(t),!Object.prototype.hasOwnProperty.call(n,Pt)){const e=n[Pt];n[Pt]=e?[...e]:[]}n[Pt].push({methodName:o,method:t,options:e})}}),t}}function Mt(e,t=!1){const n=e.constructor[Pt];if(!n||!Array.isArray(n)||0===n.length)return;const o=e[ce]??function(e){const t=ut(e);if(!t)return;const n={kind:"navigation"};return t.dispatchEvent(new CustomEvent(lt,{bubbles:!0,composed:!0,cancelable:!0,detail:n})),n.navigation}(e);if(!o)return;e[le]=o;let r=!1;for(const t of n){const{methodName:n,method:s,options:i}=t,a=`__wrapped_${n}`;e[a]=function(t){r=!0;const o=e[ye]||(e[ye]=new Set);if(i.once&&o.has(n))return;const c=()=>{if(s.call(e,t),i.once){o.add(n);const t=e[le];t&&"function"==typeof t[fe]&&t[fe](e,a)}},l=e[pe]||(e[pe]={}),h=n;if(i.debounce)return clearTimeout(l[h]?.timeout),void(l[h]={timeout:setTimeout(c,i.debounce)});if(i.throttle){const e=Date.now();return void(e-(l[h]?.lastCall||0)>=i.throttle&&(l[h]={lastCall:e},c()))}c()},"function"==typeof o[de]&&o[de](e,a)}return t&&"function"==typeof o[me]?new Promise(n=>{const s=()=>{try{r||e[le]!==o||o[me](e)}finally{n()}};"task"===t?setTimeout(s,0):queueMicrotask(s)}):void 0}function Rt(e){const t=e.constructor[Pt];if(!t||!Array.isArray(t)||0===t.length)return;const n=e[pe];if(n&&"object"==typeof n){for(const e of Object.keys(n))n[e]?.timeout&&clearTimeout(n[e].timeout);delete e[pe]}for(const n of t)delete e[`__wrapped_${n.methodName}`];const o=e[le];o&&"function"==typeof o[fe]&&o[fe](e),delete e[le],delete e[ye]}class It{constructor(){this.cleanupFns=new Map,this.pendingOperations=new Set}register(e,t){this.cleanupFns.set(e,t)}unregister(e){this.cleanupFns.delete(e)}async cleanup(){await Promise.all(this.pendingOperations);for(const e of this.cleanupFns.values())try{await e()}catch(e){console.error("Error during cleanup:",e)}this.cleanupFns.clear()}async runOperation(e){const t=e(),n=t.then(()=>{},()=>{});this.pendingOperations.add(n);try{const e=await t;return this.pendingOperations.delete(n),e}catch(e){throw this.pendingOperations.delete(n),e}}}function Dt(t){return function(o,r){const s=globalThis.snice?.controllerRegistry;if(!s)throw new Error("Snice global registry not initialized");s.set(t,o),o.prototype[n]=!0,Object.defineProperty(o,_,{value:t,configurable:!0});const i=e.pendingControllerAttachments.get(t);return i&&(e.pendingControllerAttachments.delete(t),queueMicrotask(()=>{for(const e of i){const n=e[T];(void 0===n?e[v]:n)===t&&Wt(e,t).catch(e=>{"ControllerAttachAborted"!==e?.name&&console.error(`Failed to attach controller "${t}":`,e)})}})),o}}function Vt(t,n){if(e.controllerRegistry.has(n))return void queueMicrotask(()=>{const e=t[T];(void 0===e?t[v]:e)===n&&Wt(t,n).catch(e=>{"ControllerAttachAborted"!==e?.name&&console.error(`Failed to attach controller "${n}":`,e)})});let o=e.pendingControllerAttachments.get(n);o||(o=new Set,e.pendingControllerAttachments.set(n,o)),o.add(t),queueMicrotask(()=>{e.pendingControllerAttachments.get(n)?.has(t)&&console.error(`Failed to attach controller "${n}":`,new Error(`Controller "${n}" not found in registry`))})}function qt(e){return"string"==typeof e?e:e?.name||"(anonymous controller class)"}function Bt(e,t){if(null===t){if(!e.hasAttribute("controller"))return}else if(e.getAttribute("controller")===t)return;e[C]=!0;try{null===t?e.removeAttribute("controller"):e.setAttribute("controller",t)}finally{delete e[C]}}function Ft(e){if(!e[x])return!1;const t=e[N];return"function"==typeof t&&(Bt(e,function(e){const t=Object.prototype.hasOwnProperty.call(e,_)?e[_]:void 0;return"string"==typeof t?t:qt(e)}(t)),!0)}async function Wt(t,r){if("string"!=typeof r){if("function"!=typeof r)throw new Error(`attachController: expected a controller name or a controller class, got ${typeof r}. Controller instances are not supported — pass the class itself.`);if("function"!=typeof(s=r)||!0!==s.prototype?.[n])throw new Error(`Controller class "${qt(r)}" must be decorated with @controller('name') before it can be attached.`)}var s;const i=qt(r),a=t[E],c=t[T];if("string"==typeof r&&void 0!==c&&c!==r)return;if(t[N]===r&&a)return void("string"!=typeof r&&Ft(t));if(a&&(await zt(t),t[E]&&t[N]===r))return void("string"!=typeof r&&Ft(t));let l;if("string"==typeof r){const e=globalThis.snice?.controllerRegistry;if(!e)throw new Error("Snice global registry not initialized");if(l=e.get(r),!l)throw new Error(`Controller "${r}" not found in registry`)}else l=r;const h=new l;"string"!=typeof r&&(t[x]=!0,delete t[T]),e.controllerIdCounter+=1;const u=e.controllerIdCounter,f=new It;h[o]=!0,h[A]=u,h.element=t;const m=t[q];if(void 0!==m&&(h[q]=m),t[E]=h,t[N]=r,t[S]=f,"string"!=typeof r&&Ft(t),!t[d]){const e=new AbortController;t[Ce]=e;const n=3e4;try{await Promise.race([t.ready,new Promise((t,o)=>{const r=()=>{const e=new Error(`attachController("${i}"): aborted before element was ready (likely detached or never connected)`);e.name="ControllerAttachAborted",o(e)};if(e.signal.aborted)return r();e.signal.addEventListener("abort",r,{once:!0});const s=setTimeout(()=>o(new Error(`attachController("${i}"): element did not become ready within ${n}ms (did you forget to appendChild it?)`)),n);e.signal.addEventListener("abort",()=>clearTimeout(s),{once:!0})})])}catch(e){throw t[E]===h&&("string"!=typeof r&&Bt(t,null),delete t[E],delete t[N],delete t[S],"string"!=typeof r&&delete t[x]),e}finally{t[Ce]===e&&delete t[Ce]}}h[Oe]=!0,await f.runOperation(async()=>{await h.attach(t)}),await Mt(h,"microtask"),ot(h,t),wt(h,t),$t(h,t),t.dispatchEvent(new CustomEvent("controller-attached",{detail:{name:i,controller:h}}))}async function zt(e){const t=e[Ce];t&&t.abort();const n=e[E],o=e[N],r=e[S];n&&("function"==typeof o&&Bt(e,null),delete e[E],delete e[N],delete e[S],"function"==typeof o&&delete e[x],n[Oe]&&(r?await r.runOperation(async()=>{await n.detach(e)}):await n.detach(e),n.element=null,ct(n),Et(n),Lt(n),Rt(n),r&&await r.cleanup(),delete n[q],e.dispatchEvent(new CustomEvent("controller-detached",{detail:{name:void 0===o?void 0:qt(o),controller:n}}))))}function Ut(e){return e[E]}function Ht(){if(globalThis.sniceNativeControllersInitialized)return;function e(e){if(!(e instanceof HTMLElement))return;if(!e.tagName||e.tagName.includes("-"))return;if(e[i])return;if(e[x])return void Ft(e);const t=e.getAttribute("controller"),n=e[T];if(t!==n&&(t||void 0!==n)){if(!t)return delete e[T],delete e[N],void zt(e).catch(e=>{console.error("Failed to detach controller from native element:",e)});e[T]=t,e.ready||(e.ready=Promise.resolve()),n&&zt(e).catch(e=>{console.error("Failed to detach old controller from native element:",e)}),Wt(e,t).catch(n=>{"ControllerAttachAborted"!==n?.name?n?.message!==`Controller "${t}" not found in registry`?console.error(`Failed to attach controller "${t}" to native element:`,n):Vt(e,t):console.debug(`Controller "${t}" attach aborted (element detached before ready)`)})}}globalThis.sniceNativeControllersInitialized=!0;const t=new MutationObserver(t=>{for(const n of t)"attributes"===n.type&&"controller"===n.attributeName?e(n.target):"childList"===n.type&&n.addedNodes.forEach(t=>{t instanceof HTMLElement&&(e(t),t.querySelectorAll("[controller]").forEach(e))})});function n(){document.querySelectorAll("[controller]").forEach(e),t.observe(document.body,{attributes:!0,attributeFilter:["controller"],childList:!0,subtree:!0})}"loading"===document.readyState?document.addEventListener("DOMContentLoaded",n):n(),globalThis.sniceNativeControllerObserver=t}const Kt=Symbol.for("snice:html-result"),Gt=Symbol.for("snice:css-result"),Qt=new WeakMap;function Jt(e,...t){return{_$litType$:Kt,strings:e,values:t}}function Xt(e,...t){return{_$litType$:Kt,strings:e,values:t,svg:!0}}function Yt(e,...t){const n=0===t.length?Qt.get(e):void 0;if(n)return n;let o=e[0];for(let n=0;n<t.length;n++){const r=t[n];o+=(en(r)?r.cssText:String(r))+e[n+1]}const r={_$litType$:Gt,cssText:o};if("undefined"!=typeof CSSStyleSheet&&"undefined"!=typeof Document&&"adoptedStyleSheets"in Document.prototype)try{const e=new CSSStyleSheet;e.replaceSync(o),r.styleSheet=e}catch(e){}return 0===t.length&&Qt.set(e,r),r}function Zt(e){return e&&e._$litType$===Kt}function en(e){return e&&e._$litType$===Gt}const tn=Symbol.for("snice:nothing"),nn=Symbol.for("snice:unsafe-html");function on(e){return{_$litType$:nn,html:e}}function rn(e){return e&&e._$litType$===nn}const sn=Symbol.for("snice:repeat-result");function an(e,t){if(!t||"function"!=typeof t.key||"function"!=typeof t.render)throw new TypeError("snice: repeat() requires { key, render }.");const n=null==e?[]:Array.from(e),o=n.map(t.key),r=new Set;for(const e of o){if(r.has(e))throw new Error(`snice: repeat() received duplicate key ${String(e)}.`);r.add(e)}return{_$repeat$:sn,items:n,keys:o,values:n.map(t.render),empty:0===n.length?"function"==typeof t.empty?t.empty():t.empty:void 0}}const cn=new WeakSet;function ln(e){return e[g]||e.shadowRoot||null}function hn(e){const t=ln(e);if(t)return t;const n=e.constructor[b];let o;if(o="light"===n?.renderRoot||!1===n?.shadow?e:"function"==typeof e.createRenderRoot?e.createRenderRoot():e.attachShadow({mode:"string"==typeof n?.shadow?n.shadow:"open",delegatesFocus:n?.delegatesFocus}),o!==e&&!(o instanceof ShadowRoot))throw new TypeError("snice: createRenderRoot() must return the host element or a ShadowRoot.");return e[g]=o,cn.add(e),o}function un(e){const t=e.getRootNode();if(t instanceof ShadowRoot)return t.host;let n=e;for(;n;){if(n instanceof HTMLElement&&cn.has(n))return n;n=n.parentNode}return null}const dn=`snice$${Math.random().toFixed(9).slice(2)}$`,fn="?"+dn,mn=`\x3c!--${fn}--\x3e`,pn=new RegExp(dn.replace(/\$/g,"\\$"),"g"),yn=new WeakMap,gn=Symbol("not-committed");function bn(e,t,n){!function(e,t){const n=e.localName;if(!n?.includes("-"))return!1;const o=e.ownerDocument?.defaultView?.customElements??globalThis.customElements;if(o?.get(n))return!1;const r=e;return r[R]||(r[R]=new Set),r[R].add(t),!0}(e,t)?e[t]=n:Object.defineProperty(e,t,{configurable:!0,enumerable:!0,writable:!0,value:n})}const vn=Symbol.for("snice:no-change"),wn=Symbol.for("snice:live");function En(e){return{_$liveMarker$:wn,value:e}}const Nn=e=>null===e||"object"!=typeof e&&"function"!=typeof e,An=e=>!!e&&"function"==typeof e[Symbol.asyncIterator];class Sn{constructor(e,t,n){this.parts=[],this.keyIndex=-1,this.element=t;const o=document.createTreeWalker(t.content,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT|NodeFilter.SHOW_TEXT);let r=0;const s=[];let i;for(;null!==(i=o.nextNode());)if(i.nodeType===Node.ELEMENT_NODE){const e=i,t=e.tagName.toLowerCase(),o=e.parentElement?.tagName.toLowerCase();if(("else"===t||"else-if"===t)&&"if"!==o)throw new Error(`snice: <${t}> must be a direct child of <if>.`);if(("when"===t||"default"===t)&&"case"!==o)throw new Error(`snice: <${t}> must be a direct child of <case>.`);if("if"===t){const t=e.getAttribute("value");if(!t||!t.includes(dn))throw new Error("snice: <if> requires a condition expression.");e.removeAttribute("value"),this.parts.push({type:"conditional-if",index:r++,element:e});continue}if("case"===t){const t=e.getAttribute("value");if(!t||!t.includes(dn))throw new Error("snice: <case> requires a value expression.");for(const t of Array.from(e.childNodes))if(t.nodeType===Node.ELEMENT_NODE){const e=t.tagName.toLowerCase();if("when"!==e&&"default"!==e)throw new Error("snice: <case> may contain only direct <when> and <default> branches.")}else if(t.nodeType===Node.TEXT_NODE&&t.textContent?.trim()||t.nodeType===Node.COMMENT_NODE&&t.data.includes(dn))throw new Error("snice: content inside <case> must be nested in a <when> or <default> branch.");e.removeAttribute("value"),this.parts.push({type:"conditional-case",index:r++,element:e});continue}if("else-if"===t){const t=e.getAttribute("value");if(!t||!t.includes(dn))throw new Error("snice: <else-if> requires a condition expression.");e.removeAttribute("value"),this.parts.push({type:"conditional-else-if",index:r++,element:e});continue}if("when"===t){const t=e.getAttribute("value");t&&t.includes(dn)&&(e.removeAttribute("value"),this.parts.push({type:"conditional-when",index:r++,element:e}));continue}if(e.hasAttributes()){const t=e.attributes,o=[];for(let s=0;s<t.length;s++){const i=t[s],a=i.value;if(a.includes(dn)){o.push(i);const t=n[r]||i.name,s=a.split(dn),c=s.length-1;if(/^@@?|^[.?]/.test(t)||t.startsWith("...")||t.startsWith("class:")||t.startsWith("style:")){const e=s.some(e=>""!==e);(c>1||e)&&console.warn(`snice: binding "${t}" takes a single expression; static text and extra interpolations are ignored. Use a plain attribute for string interpolation.`)}if(t.startsWith("...")){const n=t.slice(3).toLowerCase();if(!["props","properties","attrs","attributes","events"].includes(n))throw new Error(`snice: unknown spread binding "${t}". Use ...props, ...attrs, or ...events.`);this.parts.push({type:"spread",index:r,name:n,element:e}),r+=c}else if(t.startsWith("class:")){if(!t.slice(6))throw new Error("snice: class: binding requires a class name.");this.parts.push({type:"class",index:r,name:t.slice(6),element:e}),r+=c}else if(t.startsWith("style:")){if(!t.slice(6))throw new Error("snice: style: binding requires a CSS property name.");this.parts.push({type:"style",index:r,name:t.slice(6),element:e}),r+=c}else if(t.startsWith("@@")){if(!t.slice(2).split("|")[0])throw new Error("snice: event binding requires an event name.");this.parts.push({type:"event",index:r,name:t.slice(1),element:e}),r+=c}else if(t.startsWith("@")){if(!t.slice(1).split("|")[0])throw new Error("snice: event binding requires an event name.");this.parts.push({type:"event",index:r,name:t.slice(1),element:e}),r+=c}else if(t.startsWith(".")){if(!t.slice(1))throw new Error("snice: property binding requires a property name.");this.parts.push({type:"property",index:r,name:t.slice(1),element:e}),r+=c}else if(t.startsWith("?")){if(!t.slice(1))throw new Error("snice: boolean binding requires an attribute name.");this.parts.push({type:"boolean-attribute",index:r,name:t.slice(1),element:e}),r+=c}else"controller"===i.name&&2===s.length&&""===s[0]&&""===s[1]?(this.parts.push({type:"controller",index:r,element:e}),r+=c):(this.parts.push({type:"attribute",index:r,name:i.name,element:e,attrStrings:s}),r+=c)}}for(const t of o)e.removeAttribute(t.name)}}else if(i.nodeType===Node.COMMENT_NODE){const e=i;if(e.data===fn){const t=e.parentNode,n=document.createComment("");t.insertBefore(n,e.nextSibling),this.parts.push({type:"node",index:r++,startNode:e,endNode:n})}else if(e.data.includes(dn)){const t=e.data.split(pn);this.parts.push({type:"comment",index:r,startNode:e,attrStrings:t}),r+=t.length-1}}else if(i.nodeType===Node.TEXT_NODE){const e=i,t=e.data;if(t.includes(dn)){const n=e.parentNode,o=t.split(pn),i=o.length-1;for(let t=0;t<i;t++){n.insertBefore(document.createTextNode(o[t]),e);const s=document.createComment(""),i=document.createComment("");n.insertBefore(s,e),n.insertBefore(i,e),this.parts.push({type:"node",index:r++,startNode:s,endNode:i})}""!==o[i]?e.data=o[i]:s.push(e)}}for(const e of s)e.parentNode?.removeChild(e);for(const e of this.parts)if("attribute"===e.type&&"key"===e.name){this.keyIndex=e.index;break}}}function Tn(e){const{strings:t}=e,n=yn.get(t);if(n)return n;const o=[],r=[];let s=!1,i=!1,a=!1,c="",l="";for(let e=0;e<t.length;e++){const n=t[e];if(o.push(n),e<t.length-1){for(let e=0;e<n.length;e++){const t=n[e];if(a)"-"===t&&n.startsWith("--\x3e",e)&&(a=!1,e+=2);else if(s){if(i)t===c&&(i=!1,c="");else if(">"===t)s=!1;else if('"'===t||"'"===t)i=!0,c=t;else if("="===t){let t=e-1;for(;t>=0&&/[\w\-\.@\?/:\+~|]/.test(n[t]);)t--;l=n.substring(t+1,e).trim()}}else"<"===t&&(n.startsWith("\x3c!--",e)?(a=!0,e+=3):/[A-Za-z!/?]/.test(n[e+1]||"")&&(s=!0))}if(a)r.push(""),o.push(dn);else if(i)r.push(l),o.push(dn);else if(s){const s=n.trimEnd();if(s.endsWith("=")){let e=s.length-2;for(;e>=0&&/[\w\-\.@\?\/:\+~|]/.test(s[e]);)e--;l=s.substring(e+1,s.length-1).trim(),r.push(l),o.push(dn)}else{if(!n.match(/<(if|else-if|case|when)\s*$/)){const o=(n.slice(-40)+"${…}"+(t[e+1]??"").slice(0,40)).replace(/\s+/g," ").trim();throw new Error(`snice: expressions directly in opening tags are not supported; use an explicit attribute, property, event, class, style, or named spread binding. Near "${o}".`)}l="value",r.push("value"),o.push(`value="${dn}"`)}}else r.push(""),o.push(mn)}}const h=o.join(""),u=document.createElement("template");if(e.svg){u.innerHTML=`<svg>${h}</svg>`;const e=u.content.firstElementChild;for(;e.firstChild;)u.content.insertBefore(e.firstChild,e);u.content.removeChild(e)}else u.innerHTML=h;let d;try{d=new Sn(e,u,r)}catch(e){throw function(e,t){if(e instanceof Error&&/\bNear "[\s\S]*"\.$/.test(e.message))return e;const n=e instanceof Error?e.message:String(e),o=Array.from(t).join("${…}").replace(/\s+/g," ").trim(),r=/<([a-z][a-z0-9-]*)>/i.exec(n)?.[1],s=/binding "([^"]+)"/i.exec(n)?.[1],i=r?`<${r}`:s??"",a=i?o.indexOf(i):-1,c=a>=0?a:0,l=Math.max(0,c-40),h=Math.min(o.length,c+80),u=h<o.length?"…":"";return new Error(`${n} Near "${l>0?"…":""}${o.slice(l,h)}${u}".`,{cause:e})}(e,t)}return yn.set(t,d),d}function _n(e){if(!Zt(e))return;const t=Tn(e);return-1===t.keyIndex?void 0:e.values[t.keyIndex]}class xn{constructor(e){this.parts=[],this.fragment=null,this.conditionalParts=[],this.regularParts=[],this.template=Tn(e),this.strings=e.strings}isSameTemplate(e){return this.strings===e}renderFragment(){if(!this.fragment){this.fragment=this.template.element.content.cloneNode(!0);const e=document.createTreeWalker(this.template.element.content,NodeFilter.SHOW_ALL),t=document.createTreeWalker(this.fragment,NodeFilter.SHOW_ALL),n=new Map;let o=e.currentNode,r=t.currentNode;for(;o&&r;)n.set(o,r),o=e.nextNode(),r=t.nextNode();const s=new Set;for(const e of this.template.parts)"conditional-when"===e.type&&s.add(n.get(e.element));for(let e=0;e<this.template.parts.length;e++){const t=this.template.parts[e];let o;switch(t.type){case"node":const e=n.get(t.startNode),r=n.get(t.endNode);o=new On(e,r);break;case"attribute":const i=n.get(t.element);o=new kn(i,t.name,t.attrStrings);break;case"property":const a=n.get(t.element);o=new Mn(a,t.name);break;case"boolean-attribute":const c=n.get(t.element);o=new In(c,t.name);break;case"event":const l=n.get(t.element);o=new Dn(l,t.name);break;case"class":const h=n.get(t.element);o=new Ln(h,t.name);break;case"style":const u=n.get(t.element);o=new Pn(u,t.name);break;case"spread":const d=n.get(t.element);o=new jn(d,t.name);break;case"controller":const f=n.get(t.element);o=new Rn(f);break;case"conditional-if":const m=n.get(t.element);o=new qn(m);break;case"conditional-else-if":const p=n.get(t.element);o=new Fn(p);break;case"conditional-case":const y=n.get(t.element);o=new Wn(y,s);break;case"conditional-when":const g=n.get(t.element);o=new Un(g);break;case"comment":const b=n.get(t.startNode);o=new $n(b,t.attrStrings);break;default:throw new Error(`Unknown part type: ${t.type}`)}this.parts.push(o),o instanceof qn||o instanceof Fn||o instanceof Wn||o instanceof Un?this.conditionalParts.push({part:o,index:t.index}):this.regularParts.push({part:o,index:t.index})}}return this.fragment}render(e){const t=this.renderFragment();return this.update(e),t}update(e){for(const{part:t,index:n}of this.conditionalParts)t.commit(e[n]);const t=new Set;for(const{part:e}of this.conditionalParts){const n=e instanceof Fn||e instanceof Un?e.coordinator:e;t.has(n)||(t.add(n),(n instanceof qn||n instanceof Wn)&&n.flush())}for(const{part:t,index:n}of this.regularParts)t instanceof kn&&void 0!==t.strings||t instanceof $n?t.commit(e,n):t.commit(e[n]);let n;for(const e of this.parts)try{e.isConnected?e.reconnected():e.disconnected()}catch(e){n??=e}if(n)throw n}clear(){let e;for(const t of this.parts)try{t.destroy()}catch(t){e??=t}if(e)throw e}disconnected(e=!1){let t;for(const n of this.parts)try{n.disconnected(e)}catch(e){t??=e}if(t)throw t}reconnected(){let e;for(const t of this.parts)try{t.reconnected()}catch(t){e??=t}if(e)throw e}}class Cn{get isConnected(){return this.element?.isConnected??!1}disconnected(e=!1){}reconnected(){}destroy(){let e;try{this.clear()}catch(t){e=t}if(e)throw e}}class On extends Cn{constructor(e,t){super(),this.type="node",this._committedValue=gn,this._itemKeys=null,this._asyncSource=null,this._asyncVersion=0,this._asyncIterator=null,this._asyncRunning=!1,this._asyncStarted=!1,this._asyncCompleted=!1,this._asyncPaused=!1,this._committingAsyncValue=!1,this.startNode=e,this.endNode=t}commit(e){if(e!==vn)if((e=>!!e&&"function"==typeof e.then)(e)||An(e))this._commitAsync(e);else if(!this._committingAsyncValue&&this._asyncSource&&this._cancelAsync(!0),e!==tn&&null!=e&&""!==e)Nn(e)?e!==this._committedValue&&this._commitText(e):Zt(e)?this._commitTemplateResult(e):function(e){return!!e&&e._$repeat$===sn}(e)?0===e.values.length?this.commit(e.empty??tn):this._commitIterable(e.values,e.keys):rn(e)?this._commitUnsafeHTML(e):void 0===e.nodeType?(e=>Array.isArray(e)||"function"==typeof e?.[Symbol.iterator])(e)?this._commitIterable(e):this._commitText(e):this._commitNode(e);else{if(this._committedValue!==tn){const e=this._clear();if(this._committedValue=tn,e)throw e}this._committedValue=tn}}_commitText(e){if(this._committedValue!==gn&&this._committedValue!==tn&&Nn(this._committedValue)&&!Array.isArray(this._committedValue)){const t=this.startNode.nextSibling;if(t&&t.nodeType===Node.TEXT_NODE)return t.data=String(e),void(this._committedValue=e)}const t=this._clear();if(this._insertBefore(document.createTextNode(String(e))),this._committedValue=e,t)throw t}_commitTemplateResult(e){const t=this._committedValue;if(t instanceof xn){const n=yn.get(e.strings);if(n&&t.template===n)return void t.update(e.values)}const n=new xn(e),o=n.renderFragment();try{n.update(e.values)}catch(e){throw n.clear(),e}const r=this._committedValue,s=this._itemKeys,i=this.endNode.ownerDocument.createDocumentFragment();let a=this.startNode.nextSibling;for(;a&&a!==this.endNode;){const e=a.nextSibling;i.appendChild(a),a=e}this._insertBefore(o),this._committedValue=n,this._itemKeys=null;try{this.isConnected&&n.reconnected()}catch(e){try{n.clear()}catch(e){console.error("snice: failed to clean up a rejected nested template:",e)}let t=this.startNode.nextSibling;for(;t&&t!==this.endNode;){const e=t.nextSibling;t.remove(),t=e}throw this._insertBefore(i),this._committedValue=r,this._itemKeys=s,e}this._disposeCommitted(r)}_commitIterable(e,t){const n=Array.isArray(e)?e:Array.from(e),o=t?Array.from(t):n.map(_n);if(o.length!==n.length)throw new Error("snice: keyed iterable produced a different number of keys and values.");const r=o.filter(e=>void 0!==e);if(r.length>0&&r.length!==o.length&&console.warn("snice: a list mixes keyed and unkeyed items. Identity falls back to position; use repeat(items, { key, render }) for deterministic updates."),r.length>0&&new Set(r).size!==r.length)throw new Error("snice: a keyed list contains duplicate keys.");let s;Array.isArray(this._committedValue)&&this._committedValue[0]instanceof On||(s=this._clear(),this._committedValue=[],this._itemKeys=null);const i=n.length>0&&o.every(e=>void 0!==e),a=this._itemKeys;if(i&&a&&this._committedValue.length>0&&(a.length!==o.length||!o.every((e,t)=>e===a[t]))){if(s??=this._reconcileKeyed(n,o,this._committedValue,a),this._itemKeys=o,s)throw s;return}const c=this._committedValue;let l=0;for(const e of n){let t;if(l>=c.length){const e=document.createComment(""),n=document.createComment("");this._insertBefore(e),this._insertBefore(n),t=new On(e,n),c.push(t)}else t=c[l];t.commit(e),l++}if(l<c.length){for(let e=l;e<c.length;e++){const t=c[e];try{t.destroy()}catch(e){s??=e}t.startNode.remove(),t.endNode.remove()}c.length=l}if(this._itemKeys=i?o:null,s)throw s}_reconcileKeyed(e,t,n,o){const r=this.endNode.parentNode;let s;const i=new Map;for(let e=0;e<n.length;e++)i.has(o[e])||i.set(o[e],n[e]);const a=new Set,c=new Array(e.length).fill(null);for(let n=0;n<e.length;n++){const e=i.get(t[n]);e&&!a.has(e)&&(a.add(e),c[n]=e)}for(const e of n)if(!a.has(e)){try{e.destroy()}catch(e){s??=e}e.startNode.remove(),e.endNode.remove()}let l=this.startNode.nextSibling;for(let t=0;t<c.length;t++){let n=c[t];if(n)if(n.startNode===l)l=n.endNode.nextSibling;else{const e=document.createDocumentFragment();let t=n.startNode;const o=n.endNode.nextSibling;for(;t&&t!==o;){const n=t.nextSibling;e.appendChild(t),t=n}r.insertBefore(e,l)}else{const e=document.createComment(""),o=document.createComment("");r.insertBefore(e,l),r.insertBefore(o,l),n=new On(e,o),c[t]=n}n.commit(e[t])}return this._committedValue=c,s}_commitNode(e){if(this._committedValue!==e){const t=this._clear();if(this._insertBefore(e),this._committedValue=e,t)throw t}}_commitUnsafeHTML(e){const t=this._committedValue;if(rn(t)&&t.html===e.html)return;const n=this._clear(),o=document.createElement("template");if(o.innerHTML=e.html,this._insertBefore(o.content),this._committedValue=e,n)throw n}_commitAsync(e){if(e===this._asyncSource)return;this._cancelAsync(!1),this._asyncSource=e,this._asyncStarted=!1,this._asyncCompleted=!1,this._asyncPaused=!1;const t=this._clear();if(this._committedValue=tn,this._startAsyncSource(),t)throw t}_startAsyncSource(e=!1){const t=this._asyncSource;if(!t||this._asyncRunning||this._asyncCompleted||!e&&!this.isConnected)return;this._asyncRunning=!0,this._asyncStarted=!0,this._asyncPaused=!1;const n=++this._asyncVersion;if(An(t)){try{this._asyncIterator=t[Symbol.asyncIterator]()}catch(e){return this._asyncRunning=!1,this._asyncCompleted=!0,void console.error("snice: async iterable template value failed:",e)}(async()=>{try{for(;this._asyncIterator;){const e=await this._asyncIterator.next();if(e.done||n!==this._asyncVersion)break;this._commitAsyncValue(e.value)}}catch(e){n===this._asyncVersion&&console.error("snice: async iterable template value failed:",e)}finally{n===this._asyncVersion&&(this._asyncIterator=null,this._asyncRunning=!1,this._asyncCompleted=!0)}})()}else Promise.resolve(t).then(e=>{if(n===this._asyncVersion){this._asyncRunning=!1,this._asyncCompleted=!0;try{this._commitAsyncValue(e)}catch(e){console.error("snice: promise template value failed:",e)}}},e=>{n===this._asyncVersion&&(this._asyncRunning=!1,this._asyncCompleted=!0,console.error("snice: promise template value failed:",e))})}_commitAsyncValue(e){this._committingAsyncValue=!0;try{this.commit(e)}finally{this._committingAsyncValue=!1}}_cancelAsync(e){this._asyncVersion++;const t=this._asyncIterator;if(this._asyncIterator=null,this._asyncRunning=!1,e&&(this._asyncSource=null,this._asyncStarted=!1,this._asyncCompleted=!1,this._asyncPaused=!1),t?.return)try{Promise.resolve(t.return()).catch(()=>{})}catch{}}_insertBefore(e){this.endNode.parentNode?.insertBefore(e,this.endNode)}_clear(){const e=this.startNode.parentNode,t=this._committedValue;let n;try{this._disposeCommitted(t)}catch(e){n=e}if(!e)return this._committedValue=tn,n;let o=this.startNode.nextSibling;for(;o&&o!==this.endNode;){const t=o.nextSibling;e.removeChild(o),o=t}return this._committedValue=tn,n}_disposeCommitted(e){let t;if(e instanceof xn)try{e.clear()}catch(e){t=e}else if(Array.isArray(e))for(const n of e)if(n instanceof On)try{n.destroy()}catch(e){t??=e}if(t)throw t}clear(){this._cancelAsync(!0);const e=this._clear();if(e)throw e}get isConnected(){return this.startNode.isConnected}disconnected(e=!1){let t;if(this._committedValue instanceof xn)try{this._committedValue.disconnected(e)}catch(e){t??=e}else if(Array.isArray(this._committedValue))for(const n of this._committedValue)if(n instanceof On)try{n.disconnected(e)}catch(e){t??=e}if(this._asyncSource&&this._asyncRunning&&(this._cancelAsync(!1),this._asyncPaused=!0),t)throw t}reconnected(){let e;if(this._committedValue instanceof xn)try{this._committedValue.reconnected()}catch(t){e??=t}else if(Array.isArray(this._committedValue))for(const t of this._committedValue)if(t instanceof On)try{t.reconnected()}catch(t){e??=t}if(!this._asyncSource||this._asyncStarted&&!this._asyncPaused||this._startAsyncSource(!0),e)throw e}}class kn extends Cn{constructor(e,t,n){super(),this.type="attribute",this._committedValue=gn,this.lastValues=null,this.lastValueIndex=0,this.element=e,this.name=t,n&&(n.length>2||""!==n[0]||""!==n[1])?(this._committedValue=new Array(n.length-1).fill(gn),this.strings=n):this._committedValue=gn}commit(e,t=0){let n,o=!1;if(void 0===this.strings){if(e===vn)return;if(o=!Nn(e)||e!==this._committedValue&&e!==vn,!o)return;this._committedValue=e,n=e}else{const r=e;this.lastValues=[...r],this.lastValueIndex=t;const s=this._committedValue;n=this.strings[0];for(let e=0;e<this.strings.length-1;e++){let i=r[t+e];i===vn&&(i=s[e],i===gn&&(i="")),o=o||!Nn(i)||i!==s[e],i===tn?n=tn:n!==tn&&(n=n+(i??"")+this.strings[e+1]),s[e]=i}if(!o)return}this._commitValue(n)}_commitValue(e){e===tn?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,String(e??""))}clear(){this.element.removeAttribute(this.name)}}class $n extends Cn{constructor(e,t){super(),this.type="node",this.lastValues=null,this.lastValueIndex=0,this.node=e,this.strings=t,this._committedValues=new Array(t.length-1).fill(gn)}commit(e,t=0){const n=e;this.lastValues=[...n],this.lastValueIndex=t;let o=!1,r=this.strings[0];for(let e=0;e<this.strings.length-1;e++){let s=n[t+e];s===vn&&(s=this._committedValues[e],s===gn&&(s="")),o=o||!Nn(s)||s!==this._committedValues[e],this._committedValues[e]=s,r+=String(s===tn?"":s??"")+this.strings[e+1]}if(o){if(r.includes("--")||r.endsWith("-"))throw new Error('snice: comment expressions cannot produce "--" or end with "-".');this.node.data=r}}clear(){}}class Ln extends Cn{constructor(e,t){super(),this.type="class",this.committed=gn,this.element=e,this.name=t}commit(e){if(e===vn)return;const t=e!==tn&&Boolean(e);t!==this.committed&&(this.committed=t,this.element.classList.toggle(this.name,t))}clear(){this.element.classList.remove(this.name),this.committed=gn}}class Pn extends Cn{constructor(e,t){super(),this.type="style",this.committed=gn,this.element=e,this.name=t}commit(e){if(e===vn||Object.is(e,this.committed))return;this.committed=e;const t=this.element.style;e===tn||null==e||!1===e?t.removeProperty(this.name):t.setProperty(this.name,String(e))}clear(){this.element.style.removeProperty(this.name),this.committed=gn}}class jn extends Cn{constructor(e,t){super(),this.type="spread",this.committed={},this.listeners=new Map,this.consumedOnce=new Map,this.element=e,this.name=t}commit(e){if(e===vn)return;if(e!==tn&&null!=e||(e={}),"object"!=typeof e||Array.isArray(e))throw new TypeError(`snice: ...${this.name} expects an object.`);const t=e;"events"===this.name?this.commitEvents(t):"props"===this.name||"properties"===this.name?this.commitProperties(t):this.commitAttributes(t),this.committed={...t}}commitProperties(e){for(const t of Object.keys(this.committed))Object.prototype.hasOwnProperty.call(e,t)||bn(this.element,t,void 0);for(const[t,n]of Object.entries(e))Object.is(this.committed[t],n)||bn(this.element,t,n===tn?void 0:n)}commitAttributes(e){for(const t of Object.keys(this.committed))Object.prototype.hasOwnProperty.call(e,t)||this.element.removeAttribute(t);for(const[t,n]of Object.entries(e))Object.is(this.committed[t],n)||(n===tn||null==n||!1===n?this.element.removeAttribute(t):this.element.setAttribute(t,!0===n?"":String(n)))}commitEvents(e){!function(e,t){const n=new Set;for(const[o,r]of Object.entries(e)){const e=o.startsWith("@")?o.slice(1):o;if(!e)throw new TypeError(`snice: ${t} contains an empty event name.`);if(n.has(e))throw new TypeError(`snice: ${t} contains duplicate event name "${e}".`);if(n.add(e),r!==tn&&null!=r&&!1!==r&&"function"!=typeof r&&(!r||"object"!=typeof r||"function"!=typeof r.handleEvent))throw new TypeError(`snice: ${t} event "${e}" expects a function, EventListenerObject, or null.`)}}(e,`...${this.name}`);for(const[t,n]of this.consumedOnce){const o=Object.keys(e).find(e=>this.eventName(e)===t);o&&Object.is(e[o],n)||this.consumedOnce.delete(t)}for(const[t,n]of this.listeners){const o=Object.keys(e).find(e=>this.eventName(e)===t);o&&Object.is(e[o],n.value)||(this.element.removeEventListener(t,n.listener,n.options),this.listeners.delete(t))}for(const[t,n]of Object.entries(e)){const e=this.eventName(t);if(this.listeners.has(e))continue;const o=!!n&&"object"==typeof n&&"function"==typeof n.handleEvent;if(n===tn||null==n||!1===n)continue;if(this.consumedOnce.has(e)&&Object.is(this.consumedOnce.get(e),n))continue;this.consumedOnce.delete(e);const r=o?n:void 0,s=t=>{r?.once&&this.consumedOnce.set(e,n),o?n.handleEvent(t):n.call(this.resolveHost(),t)};this.element.addEventListener(e,s,r),this.listeners.set(e,{value:n,listener:s,options:r})}}eventName(e){return e.startsWith("@")?e.slice(1):e}resolveHost(){return un(this.element)||this.element}clear(){if("events"===this.name){for(const[e,t]of this.listeners)this.element.removeEventListener(e,t.listener,t.options);this.listeners.clear(),this.consumedOnce.clear()}else if("props"!==this.name&&"properties"!==this.name)for(const e of Object.keys(this.committed))this.element.removeAttribute(e);this.committed={}}disconnected(e=!1){"events"!==this.name||e||this.detachListeners()}reconnected(){"events"===this.name&&0===this.listeners.size&&this.commitEvents(this.committed)}detachListeners(){for(const[e,t]of this.listeners)this.element.removeEventListener(e,t.listener,t.options);this.listeners.clear()}}class Mn extends Cn{constructor(e,t){super(),this.type="property",this._committedValue=gn,this.element=e,this.name=t}commit(e){if(e!==vn){if(function(e){return e&&e._$liveMarker$===wn}(e)){if((e=e.value)===vn)return;if(e===this.element[this.name])return void(this._committedValue=e)}else if(e===this._committedValue)return;this._committedValue=e,bn(this.element,this.name,e===tn?void 0:e)}}clear(){this._committedValue=gn}}class Rn extends Cn{constructor(e){super(),this.type="controller",this._committedValue=gn,this.element=e}commit(e){if(e===vn)return;const t=null==e||!1===e||""===e||e===tn?null:e,n=this._committedValue===gn,o=n?null:this._committedValue;if(!n&&t===o)return;this._committedValue=t;const r=this.element;"function"==typeof o&&"function"!=typeof t&&(void 0!==r[O]?delete r[O]:r[i]?r.controller=null:this._detach()),"function"==typeof t?this.isConnected?this._apply(t):this.element.localName.includes("-")&&!r[i]&&(r[O]=t):"string"==typeof t?this.element.setAttribute("controller",t):"string"==typeof o&&this.element.removeAttribute("controller")}_apply(e){const t=this.element;t[i]?t.controller!==e?t.controller=e:this._attach(e):this.element.localName.includes("-")?t[O]=e:(t.ready||(t.ready=Promise.resolve()),this._attach(e))}_attach(e){Wt(this.element,e).catch(t=>{"ControllerAttachAborted"!==t?.name&&console.error(`Failed to attach controller "${e?.name||e}":`,t)})}_detach(){zt(this.element).catch(e=>{console.error("Failed to detach controller:",e)})}disconnected(e=!1){if("function"!=typeof this._committedValue)return;const t=this.element;void 0===t[O]&&(t[i]||this._detach())}reconnected(){const e=this._committedValue;"function"==typeof e&&this._apply(e)}clear(){const e=this.element;void 0!==e[O]&&delete e[O];const t=this._committedValue;this._committedValue=gn,"function"==typeof t&&(e[i]||this._detach())}}class In extends Cn{constructor(e,t){super(),this.type="boolean-attribute",this._committedValue=gn,this.element=e,this.name=t}commit(e){if(e===vn)return;const t=!!e&&e!==tn;t!==this._committedValue&&(this._committedValue=t,t?this.element.setAttribute(this.name,""):this.element.removeAttribute(this.name))}clear(){this.element.removeAttribute(this.name),this._committedValue=gn}}class Dn extends Cn{constructor(e,t){super(),this.type="event",this.listener=null,this.listenerOptions=void 0,this.value=void 0,this.keyFilter=null,this.host=null,this.modifiers=new Set,this.once=!1,this.onceConsumed=!1,this.element=e;const[n,...o]=t.split("|"),r={preventdefault:"prevent",stoppropagation:"stop",stopimmediatepropagation:"immediate"},s=new Set(["prevent","stop","immediate","once","capture","passive","self"]);for(const e of o){const n=r[e.toLowerCase()]||e.toLowerCase();if(!s.has(n))throw new Error(`snice: unknown event modifier "${e}" in @${t}. Supported modifiers: prevent, stop, immediate, once, capture, passive, self.`);this.modifiers.add(n)}if(this.modifiers.has("passive")&&this.modifiers.has("prevent"))throw new Error(`snice: @${t} cannot combine passive and prevent.`);const i=["keydown","keyup","keypress"].includes(n.split(".")[0].split(":")[0]),a=i?n.indexOf("."):-1,c=i?n.indexOf(":"):-1,l=a>0&&c>0?Math.min(a,c):Math.max(a,c);if(l>0){const e=n.substring(0,l),t=n.substring(l+1);this.eventName=e,this.keyFilter=St(t)}else this.eventName=n,At(n)}commit(e){if(e===vn)return;e===tn&&(e=null);const t=!!e&&"object"==typeof e&&"function"==typeof e.handleEvent;if(null!=e&&!1!==e&&"function"!=typeof e&&!t)throw new TypeError(`snice: @${this.eventName} expects a function, EventListenerObject, or null.`);if(t&&this.modifiers.has("prevent")&&e.passive)throw new Error(`snice: @${this.eventName} cannot combine a passive listener object with prevent.`);if(e!==this.value||null==e){if(this.listener&&(this.element.removeEventListener(this.eventName,this.listener,this.listenerOptions),this.listener=null,this.listenerOptions=void 0),null==e||!1===e)return this.value=e,void(this.onceConsumed=!1);this.onceConsumed=!1;try{this.attachListener(e,t),this.value=e}catch(e){throw this.value=void 0,e}}}attachListener(e,t){const n=this.keyFilter,o=r=>{this.modifiers.has("self")&&r.target!==this.element||n&&!_t(r,n)||(this.once&&(this.onceConsumed=!0,this.element.removeEventListener(this.eventName,o,s),this.listener=null,this.listenerOptions=void 0),this.modifiers.has("prevent")&&r.preventDefault(),this.modifiers.has("immediate")?r.stopImmediatePropagation():this.modifiers.has("stop")&&r.stopPropagation(),t?e.handleEvent(r):(this.host||(this.host=un(this.element)),e.call(this.host||this.element,r)))},r=t?e:{};this.once=this.modifiers.has("once")||!!r.once;const s={capture:this.modifiers.has("capture")||r.capture,passive:this.modifiers.has("passive")||r.passive,signal:r.signal};this.element.addEventListener(this.eventName,o,s),this.listener=o,this.listenerOptions=s}clear(){this.detachListener(),this.value=void 0,this.host=null,this.onceConsumed=!1}detachListener(){this.listener&&(this.element.removeEventListener(this.eventName,this.listener,this.listenerOptions),this.listener=null,this.listenerOptions=void 0)}disconnected(e=!1){e||this.detachListener(),this.host=null}reconnected(){this.listener||this.onceConsumed||null==this.value||!1===this.value||this.attachListener(this.value,"object"==typeof this.value)}}const Vn=Symbol("not-set");class qn extends Cn{constructor(e){super(),this.type="node",this.conditions=[Vn],this.branches=[],this.defaultBranch=-1,this.currentBranch=-1;const t=e.parentNode;this.startNode=document.createComment("if"),this.endNode=document.createComment("/if"),t.insertBefore(this.startNode,e),t.insertBefore(this.endNode,e.nextSibling);const n=document.createDocumentFragment();this.branches.push(n);let o=!1,r=n;for(const t of Array.from(e.childNodes)){const e=t.nodeType===Node.ELEMENT_NODE?t.tagName.toLowerCase():"";if("else-if"===e||"else"===e){o=!0;const n=t,s=document.createDocumentFragment();for(;n.firstChild;)s.appendChild(n.firstChild);const i=this.branches.push(s)-1;if(r=s,"else-if"===e){if(-1!==this.defaultBranch)throw new Error("snice: <else> must be the final branch inside <if>.");this.conditions[i]=Vn,Bn.set(n,{coordinator:this,index:i})}else{if(-1!==this.defaultBranch)throw new Error("snice: <if> may contain only one <else> branch.");this.defaultBranch=i}n.remove();continue}o?t.nodeType!==Node.TEXT_NODE||t.textContent?.trim()?r.appendChild(t):t.remove():n.appendChild(t)}t.removeChild(e)}commit(e){e!==vn&&(this.conditions[0]=e)}setAlternative(e,t){t!==vn&&(this.conditions[e]=t)}flush(){let e=-1;for(let t=0;t<this.conditions.length;t++)if(this.conditions[t]!==Vn&&this.conditions[t]!==tn&&Boolean(this.conditions[t])){e=t;break}-1===e&&(e=this.defaultBranch),e!==this.currentBranch&&(this.collectCurrent(),this.currentBranch=e,-1!==e&&this.branches[e].hasChildNodes()&&this.startNode.parentNode?.insertBefore(this.branches[e],this.endNode))}collectCurrent(){if(-1===this.currentBranch)return;const e=this.branches[this.currentBranch];let t=this.startNode.nextSibling;for(;t&&t!==this.endNode;){const n=t.nextSibling;e.appendChild(t),t=n}}clear(){this.collectCurrent(),this.currentBranch=-1}get isConnected(){return this.startNode.isConnected}}const Bn=new WeakMap;class Fn extends Cn{constructor(e){super(),this.type="node";const t=Bn.get(e);if(!t)throw new Error("snice: <else-if> must be a direct child of <if>.");this.coordinator=t.coordinator,this.index=t.index}commit(e){this.coordinator.setAlternative(this.index,e)}clear(){}get isConnected(){return this.coordinator.isConnected}}class Wn extends Cn{constructor(e,t){super(),this.type="node",this.value=Vn,this.branches=[],this.defaultBranch=-1,this.currentBranch=-1;const n=e.parentNode;this.startNode=document.createComment("case"),this.endNode=document.createComment("/case"),n.insertBefore(this.startNode,e),n.insertBefore(this.endNode,e.nextSibling);for(const n of Array.from(e.children)){const e=n.tagName.toLowerCase();if("when"===e){const e=document.createDocumentFragment();for(;n.firstChild;)e.appendChild(n.firstChild);const o=t.has(n),r=this.branches.push({fragment:e,dynamic:o,expected:o?Vn:n.getAttribute("value")??""})-1;o&&zn.set(n,{coordinator:this,index:r})}else if("default"===e){if(-1!==this.defaultBranch)throw new Error("snice: <case> may contain only one <default> branch.");const e=document.createDocumentFragment();for(;n.firstChild;)e.appendChild(n.firstChild);this.defaultBranch=this.branches.push({fragment:e,dynamic:!1,expected:Vn})-1}}n.removeChild(e)}commit(e){e!==vn&&(this.value=e)}setExpected(e,t){t!==vn&&(this.branches[e].expected=t)}flush(){let e=this.branches.findIndex((e,t)=>t!==this.defaultBranch&&(e.dynamic?Object.is(this.value,e.expected):String(this.value)===e.expected));-1===e&&(e=this.defaultBranch),e!==this.currentBranch&&(this.collectCurrent(),this.currentBranch=e,-1!==e&&this.branches[e].fragment.hasChildNodes()&&this.startNode.parentNode?.insertBefore(this.branches[e].fragment,this.endNode))}collectCurrent(){if(-1===this.currentBranch)return;const e=this.branches[this.currentBranch].fragment;let t=this.startNode.nextSibling;for(;t&&t!==this.endNode;){const n=t.nextSibling;e.appendChild(t),t=n}}clear(){this.collectCurrent(),this.currentBranch=-1}get isConnected(){return this.startNode.isConnected}}const zn=new WeakMap;class Un extends Cn{constructor(e){super(),this.type="node";const t=zn.get(e);if(!t)throw new Error("snice: dynamic <when> must be a direct child of <case>.");this.coordinator=t.coordinator,this.index=t.index}commit(e){this.coordinator.setExpected(this.index,e)}clear(){}get isConnected(){return this.coordinator.isConnected}}const Hn=new WeakSet,Kn=new WeakSet,Gn=["a[href]","area[href]","button:not([disabled])",'input:not([disabled]):not([type="hidden"])',"select:not([disabled])","textarea:not([disabled])","iframe","object","embed","summary","audio[controls]","video[controls]",'[contenteditable]:not([contenteditable="false"])','[tabindex]:not([tabindex="-1"])'].join(",");function Qn(e){try{e.focus()}catch{return!1}return function(e){const t=e.getRootNode().activeElement;return t===e||Boolean(t&&e.contains(t))}(e)}function Jn(e){return e?Array.from(e.querySelectorAll("[autofocus]")).filter(e=>!Kn.has(e)):[]}function Xn(e){return e?Array.from(e.querySelectorAll(Gn)):[]}function Yn(e){if(Hn.has(e)||!function(e){return!(!e.hasAttribute("autofocus")||Kn.has(e))||Jn(ln(e)).length>0}(e))return;Hn.add(e);const t=()=>{const t=e.ownerDocument.defaultView,n=()=>{Hn.delete(e),function(e){if(!e.isConnected)return;const t=ln(e),n=[];if(e.hasAttribute("autofocus")&&!Kn.has(e)&&n.push(e),n.push(...Jn(t)),0!==n.length)if(function(e){const t=e.activeElement;return Boolean(t&&t!==e.body&&t!==e.documentElement)}(e.ownerDocument))for(const e of n)Kn.add(e);else for(const o of n){if(Kn.add(o),Qn(o))return;if(o===e)for(const e of Xn(t))if(Qn(e))return}}(e)};t?.requestAnimationFrame?t.requestAnimationFrame(n):queueMicrotask(n)};Promise.resolve(e.ready).then(t,t)}let Zn=!1;function eo(e){Zn=e}function to(e){e[m]||(e[f]=new Promise(t=>{e[m]=t}))}function no(e){const t=e[m];t&&(e[m]=null,t())}const oo=new class{constructor(){this.pending=new Set,this.scheduled=!1}schedule(e,t){t.sync?ao(e,t):(this.pending.add(e),this.scheduled||(this.scheduled=!0,queueMicrotask(()=>this.flush())))}flush(){const e=Array.from(this.pending);this.pending.clear(),this.scheduled=!1;for(const t of e)t.isConnected?ao(t,t[ee]||{}):t[p]=!0}remove(e){this.pending.delete(e)}};function ro(e){return Object.prototype.hasOwnProperty.call(e,te)}function so(e){const t=e[oe];if(!t||0===t.length)return;const n=[...t];e[oe]=[],n.forEach(e=>e())}const io=50;function ao(e,t,n){const o=arguments.length>=3,r=e[Z];if(!r)return void no(e);if(t.once&&ro(e))return void no(e);const s=e[y]??0;if(s>=io){const t=e.tagName?e.tagName.toLowerCase():"element";return console.error(`snice: maximum render depth (${io}) exceeded for <${t}>. render() is mutating an observed property, causing an infinite render loop.`),void no(e)}e[y]=s+1;try{const s=o?n:r.call(e),i=hn(e);if(!1===t.differential){if("string"!=typeof s)return void console.warn("Render method with differential: false must return a string");const t=document.createElement("template");t.innerHTML=s;const n=e[te];n?.clear();const o=Array.from(i.childNodes).filter(e=>!(e.nodeType===Node.ELEMENT_NODE&&"STYLE"===e.tagName&&e.hasAttribute("data-snice-style")));for(const e of o)e.remove();return i.appendChild(t.content),e[te]=null,so(e),void Yn(e)}if(!Zt(s))return void console.warn("Render method must return html`` template result");let a=e[te];if(a&&a.isSameTemplate(s.strings))return a.update(s.values),so(e),void Yn(e);const c=new xn(s),l=c.renderFragment();try{c.update(s.values)}catch(e){throw c.clear(),e}const h=document.createDocumentFragment();for(const e of Array.from(i.childNodes))e.nodeType===Node.ELEMENT_NODE&&"STYLE"===e.tagName&&e.hasAttribute("data-snice-style")||h.appendChild(e);i.appendChild(l);try{e.isConnected&&c.reconnected()}catch(e){try{c.clear()}catch(e){console.error("snice: failed to clean up a rejected render tree:",e)}for(const e of Array.from(i.childNodes))e.nodeType===Node.ELEMENT_NODE&&"STYLE"===e.tagName&&e.hasAttribute("data-snice-style")||e.remove();throw i.appendChild(h),e}let u;e[te]=c;try{a?.clear()}catch(e){u=e}if(so(e),Yn(e),u)throw u}catch(t){const n=function(e,t){const n=e.tagName?.toLowerCase()||"element",o=t instanceof Error?t.message:String(t),r=new Error(`snice: render failed for <${n}>: ${o}`,{cause:t});return t instanceof Error&&(r.name=t.name),r}(e,t);if(Zn)throw n;console.error("Error rendering element:",n)}finally{e[y]=s,no(e)}}function co(e,t=!1){const n=e[ee]||{};if(n.once&&ro(e))e.isConnected&&lo(e);else if(to(e),t)ao(e,n);else{if(void 0!==n.debounce&&n.debounce>0)return e[ne]||(e[ne]={}),clearTimeout(e[ne].debounce),void(e[ne].debounce=setTimeout(()=>{e[ne].debounce=null,oo.schedule(e,n)},n.debounce));if(void 0!==n.throttle&&n.throttle>0){e[ne]||(e[ne]={lastThrottle:0});const t=e[ne],o=Date.now();return 0===t.lastThrottle||o-t.lastThrottle>=n.throttle?(t.lastThrottle=o,void oo.schedule(e,n)):void(t.throttleTimer||(t.throttleTimer=setTimeout(()=>{t.throttleTimer=null,t.lastThrottle=Date.now(),oo.schedule(e,n)},n.throttle-(o-t.lastThrottle))))}oo.schedule(e,n)}}function lo(e){const t=e[te];t?.reconnected()}function ho(e={}){return function(t,n){return n.addInitializer(function(){this[Z]=t,this[ee]=e}),function(...n){const o=t.apply(this,n);return ao(this,{...this[ee]||e,once:!1},o),o}}}function uo(){return function(e,t){return t.addInitializer(function(){this[re]&&!this[ie]?this[ie]=[this[re]]:this[re]&&this[ie]&&this[ie].push(this[re]),this[re]=e}),e}}function fo(e,t){return function(n,o){return function(...r){this[Y]||(this[Y]=new Map);const s=`${e}_${o.name}`;this[Y].has(s)||this[Y].set(s,{debounceTimeout:null,throttleLastCall:0,throttleTimeout:null});const i=this[Y].get(s),a=n.apply(this,r),c=n=>{if(void 0===n&&!1===t?.dispatchOnUndefined)return;const o=new CustomEvent(e,{bubbles:t?.bubbles??!0,cancelable:t?.cancelable??!1,composed:t?.composed??!0,detail:n});if(void 0!==t?.scope&&void 0!==t?.daemon)throw new TypeError(`@dispatch('${e}') cannot use both scope and daemon.`);if(void 0!==t?.daemon)return void yt(this,t.daemon).dispatchEvent(o);if(void 0!==t?.scope){const n=Ye(this,t.scope);return n?void n.dispatchEvent(o):void console.warn(`[snice/@dispatch] scope did not resolve for "${e}" — event not dispatched.`)}const r=gt(this);if(!r)throw new TypeError(`@dispatch('${e}') requires an element, attached controller, or provided @daemon instance.`);r.dispatchEvent(o)},l=e=>{if(t?.debounce)return clearTimeout(i.debounceTimeout),void(i.debounceTimeout=setTimeout(()=>c(e),t.debounce));if(!t?.throttle)return void c(e);const n=Date.now(),o=t.throttle-(n-i.throttleLastCall);if(o<=0)return clearTimeout(i.throttleTimeout),i.throttleLastCall=n,void c(e);i.latestDetail=e,i.throttleTimeout||(i.throttleTimeout=setTimeout(()=>{i.throttleLastCall=Date.now(),i.throttleTimeout=null;const e=i.latestDetail;i.latestDetail=void 0,c(e)},o))};return a instanceof Promise?a.then(e=>(l(e),e)):(l(a),a)}}}function mo(e){const t=e[Y];if(t)for(const e of t.values())e.debounceTimeout&&clearTimeout(e.debounceTimeout),e.throttleTimeout&&clearTimeout(e.throttleTimeout),e.debounceTimeout=null,e.throttleTimeout=null,e.throttleLastCall=0,e.latestDetail=void 0}const po=t("debounce-timers"),yo=t("throttle-timers"),go=t("once-called"),bo=t("memoize-cache");function vo(e=300,t={}){const{leading:n=!1,trailing:o=!0,maxWait:r}=t;return function(t,s){const i=s.name;return function(...s){this[po]||(this[po]={});const a=this[po],c=i;a[c]&&clearTimeout(a[c].timeout);const l=Date.now(),h=!a[c],u=h?l:a[c].startTime,d=void 0!==r&&l-u>=r;if(n&&h){const e=t.apply(this,s);return a[c]={timeout:null,startTime:u,lastArgs:s},e}const f=setTimeout(()=>{(o||d)&&t.apply(this,a[c].lastArgs),delete a[c]},d?0:e);a[c]={timeout:f,startTime:u,lastArgs:s}}}}function wo(e=300,t={}){const{leading:n=!0,trailing:o=!0}=t;return function(t,r){const s=r.name;return function(...r){this[yo]||(this[yo]={});const i=this[yo],a=s,c=Date.now();if(!i[a])return n&&t.apply(this,r),i[a]={lastInvoke:c,timeout:null,lastArgs:r},void(o&&!n&&(i[a].timeout=setTimeout(()=>{t.apply(this,i[a].lastArgs),delete i[a]},e)));const l=c-i[a].lastInvoke;if(i[a].lastArgs=r,i[a].timeout&&clearTimeout(i[a].timeout),l>=e)return t.apply(this,r),void(i[a].lastInvoke=c);o&&(i[a].timeout=setTimeout(()=>{t.apply(this,i[a].lastArgs),i[a].lastInvoke=Date.now(),i[a].timeout=null},e-l))}}}function Eo(e=!0){let t,n=!1;return function(o,r){const s=r.name;return function(...r){return e?(this[go]||(this[go]={}),this[go][s]||(this[go][s]={called:!0,result:o.apply(this,r)}),this[go][s].result):(n||(n=!0,t=o.apply(this,r)),t)}}}function No(e={}){const{keyGenerator:t=(...e)=>JSON.stringify(e),maxSize:n=100,ttl:o}=e;return function(e,r){const s=r.name;return function(...r){this[bo]||(this[bo]={}),this[bo][s]||(this[bo][s]=new Map);const i=this[bo][s],a=t(...r);if(i.has(a)){const e=i.get(a);if(!(void 0!==o&&Date.now()-e.timestamp>o))return e.value;i.delete(a)}const c=e.apply(this,r);if(i.set(a,{value:c,timestamp:Date.now()}),i.size>n){const e=i.keys().next().value;i.delete(e)}return c}}}function Ao(e){if(e[po]){for(const t in e[po])e[po][t]?.timeout&&clearTimeout(e[po][t].timeout);e[po]={}}}function So(e){if(e[yo]){for(const t in e[yo])e[yo][t]?.timeout&&clearTimeout(e[yo][t].timeout);e[yo]={}}}function To(e,t){e[bo]&&(t?delete e[bo][t]:e[bo]={})}function _o(e,t){e[go]&&(t?delete e[go][t]:e[go]={})}function xo(e,t){const n=Reflect.getOwnPropertyDescriptor(e,t);return!n||n.configurable?{locked:!1,value:void 0}:"value"in n&&!1===n.writable?{locked:!0,value:n.value}:"value"in n||void 0!==n.get?{locked:!1,value:void 0}:{locked:!0,value:void 0}}function Co(e){e.prototype[i]=!0;const t=e.prototype.connectedCallback,n=e.prototype.disconnectedCallback,o=e.prototype.attributeChangedCallback,r=e.observedAttributes||[];r.includes("controller")||r.push("controller"),r.includes("autofocus")||r.push("autofocus");const s=e[$];if(s)for(const[e,t]of s){if(!1===t.attribute)continue;const n=Fe(t,e);r.includes(n)||r.push(n)}Object.defineProperty(e,"observedAttributes",{get:()=>r,configurable:!0}),Object.defineProperty(e.prototype,"ready",{get(){return this[l]||(this[l]=new Promise((e,t)=>{this[h]=e,this[u]=t}),this[l].catch(()=>{})),this[l]},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rendered",{get(){return this[m]?this[f]:Promise.resolve()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"controller",{get(){return this[v]},set(e){const t=this[v];if(this[v]=e,e!==t){if(e){const t="string"==typeof e?e:e.name||"(anonymous controller class)";return void Wt(this,e).catch(n=>{"ControllerAttachAborted"!==n?.name?"string"!=typeof e||n?.message!==`Controller "${e}" not found in registry`?console.error(`Failed to attach controller "${t}":`,n):Vt(this,e):console.debug(`Controller "${t}" attach aborted (element detached before ready)`)})}t&&zt(this).catch(e=>{console.error("Failed to detach controller:",e)})}},enumerable:!0,configurable:!0}),e.prototype.connectedCallback=async function(){if(this[l]||(this[l]=new Promise((e,t)=>{this[h]=e,this[u]=t}),this[l].catch(()=>{})),this[w]){try{lo(this)}catch(e){console.error(`Error reconnecting the render tree for ${this.tagName}:`,e)}$t(this,this),wt(this,this),Mt(this,"task");try{ot(this,this)}catch(e){console.error(`Error setting up observers for ${this.tagName} on reconnection:`,e)}t&&t.call(this);const n=e[U];if(n)for(const e of n)try{const t=e.method.call(this);t&&"function"==typeof t.then&&t.catch(t=>{console.error(`Error in @reconnect handler ${e.methodName}:`,t)})}catch(t){console.error(`Error in @reconnect handler ${e.methodName}:`,t)}return this[Z]&&this[p]&&(this[p]=!1,co(this)),void Yn(this)}this[I]=!0;const n=e[$];if(n)for(const[e,t]of n){if(!1===t.attribute)continue;const n=Fe(t,e);if(!this.hasAttribute(n))continue;const o=this.getAttribute(n);Ke(this,V).add(e),t.type===Boolean&&""===o&&this.setAttribute(n,"true"),this[e]=qe(o,t)}if(this[M]){for(const[e,t]of Array.from(this[M].entries())){const o=n?.get(e),r=Fe(o||{},e);this[M].delete(e),this.hasAttribute(r)||(this[e]=t)}delete this[M]}if(void 0!==this[O]){const e=this[O];if(delete this[O],!this[v]){this[v]=e;const t=e?.name||"(anonymous controller class)";Wt(this,e).catch(e=>{"ControllerAttachAborted"!==e?.name?console.error(`Failed to attach controller "${t}":`,e):console.debug(`Controller "${t}" attach aborted (element detached before ready)`)})}}if(this.hasAttribute("controller")&&!this[v]){const e=this.getAttribute("controller");e&&(this.controller=e)}if(function(e){const t=e[re],n=[],o=[];let r=e.constructor;for(;r&&r!==HTMLElement&&r!==Function.prototype;)o.unshift(r),r=Object.getPrototypeOf(r);for(const e of o){if(!Object.prototype.hasOwnProperty.call(e,"styles"))continue;const t=e.styles,o=Array.isArray(t)?t:[t];for(const e of o)en(e)?n.push(e):console.warn("Static styles must be a css`` result or an array of css`` results")}if((t||0!==n.length)&&!e[se]){e[se]=!0;try{const o=[...n],r=e[ie];if(r)for(const t of r){const n=t.call(e);en(n)&&o.push(n)}if(t){const n=t.call(e);if(!en(n))return void console.warn("Styles method must return css`` template result");o.push(n)}const s=hn(e),i=Array.from(s.childNodes).filter(e=>e.nodeType===Node.ELEMENT_NODE&&"STYLE"===e.tagName&&e.hasAttribute("data-snice-style"));if(i.length===o.length&&i.every((e,t)=>e.textContent===o[t].cssText))return;for(const e of i)e.remove();if(s instanceof ShadowRoot&&o.every(e=>!!e.styleSheet)&&"adoptedStyleSheets"in s)try{return void(s.adoptedStyleSheets=o.map(e=>e.styleSheet))}catch{}for(const e of o){const t=document.createElement("style");t.setAttribute("data-snice-style",""),t.textContent=e.cssText,s.appendChild(t)}}catch(e){console.error("Error applying styles:",e)}}}(this),this[Z])try{hn(this)}catch{}$t(this,this),wt(this,this),Mt(this,"task"),this[w]=!0,function(e,t){if(et.has(t))return;et.add(t);const n=t[D];if(!n||0===n.size)return;const o=t[$],r=new Set(["*"]);if(o)for(const[e,t]of o)r.add(e),"string"==typeof t?.attribute&&r.add(t.attribute);for(const t of n.keys()){if(r.has(t))continue;const n=e.tagName?e.tagName.toLowerCase():"element",s=o?[...o.keys()].join(", "):"(none)";console.warn(`@watch('${t}') on <${n}> matches no @property — it will never fire. Known properties: ${s}.`)}}(this,e),function(e,t){const n=t[D],o=t[$];if(n&&o)for(const[t,r]of o){const o=[t],s=r&&"string"==typeof r.attribute?r.attribute:null;s&&s!==t&&o.push(s),o.push("*");for(const r of o)if(n.has(r))for(const o of n.get(r))if(o.immediate)try{o.method.call(e,void 0,e[t],t)}catch(e){console.error(`Error in @watch('${r}') method ${o.methodName}:`,e)}}}(this,e),t&&t.call(this);const o=e[W];if(await new Promise(e=>queueMicrotask(e)),!this.isConnected)return void(this[h]&&(this[h](),this[h]=null,this[u]=null));this[Z]&&co(this,!0);try{ot(this,this)}catch(e){console.error(`Error setting up observers for ${this.tagName}:`,e)}if(await new Promise(e=>queueMicrotask(e)),!this.isConnected)return void(this[h]&&(this[h](),this[h]=null,this[u]=null));let r,s=!1;if(o){this[d]=!0;try{for(const e of o)try{await e.method.call(this)}catch(t){console.error(`Error in @ready handler ${e.methodName}:`,t),s||(s=!0,r=t)}}finally{delete this[d]}}s&&this[u]?(this[u](r),this[h]=null,this[u]=null):this[h]&&(this[h](),this[h]=null,this[u]=null),Yn(this)},e.prototype.disconnectedCallback=async function(){try{!function(e){const t=e[te];t?.disconnected(!0)}(this)}catch(e){console.error(`Error disconnecting the render tree for ${this.tagName}:`,e)}const t=e[z];if(t)for(const e of t)try{await e.method.call(this)}catch(t){console.error(`Error in @dispose handler ${e.methodName}:`,t)}n&&n.call(this),this[v]&&zt(this).catch(e=>{console.error("Failed to detach controller:",e)}),Lt(this),Et(this),Rt(this),ct(this),Ao(this),So(this),function(e){const t=e[ne];if(!t)return!1;let n=!1;return t.debounce&&(clearTimeout(t.debounce),t.debounce=null,n=!0),t.throttleTimer&&(clearTimeout(t.throttleTimer),t.throttleTimer=null,n=!0),n}(this)&&(this[p]=!0),mo(this),Uo(this,J),Uo(this,X)},e.prototype.attributeChangedCallback=function(t,n,r){if(o?.call(this,t,n,r),"controller"===t){if(this[C])return;return this[x]?void Ft(this):void(this.controller=r)}"autofocus"===t&&(null===r?Kn.delete(this):this[w]&&Yn(this));const s=e[$];if(s)for(const[n,o]of s){if(Fe(o,n).toLowerCase()!==t.toLowerCase())continue;if(this[Q]?.has(t.toLowerCase()))break;const s=this[L]?.[n],i=this[P]?.[n];let a=null===r?o.type!==Boolean&&i:qe(r,o,s,i);const c=this[j]?.[n];if(c&&(a=c(a)),!(o?.hasChanged?o.hasChanged(a,s):Be(a,s)))break;Ke(this,V).add(n),Ge(this,L)[n]=a,this[w]&&Qe(this,e,n,s,a),this[Z]&&this[w]&&co(this);break}},e.prototype.connectedMoveCallback=async function(){const t=e[H];if(t)for(const e of t)try{await this[e.methodName]()}catch(t){console.error(`Error in @moved handler ${e.methodName}:`,t)}},e.prototype.adoptedCallback=async function(){const t=e[K];if(t)for(const e of t)try{await this[e.methodName]()}catch(t){console.error(`Error in @adopted handler ${e.methodName}:`,t)}}}function Oo(e,t,n,o){if(function(e){let t=Object.getPrototypeOf(e);const n=[];for(;t&&t!==HTMLElement&&t!==Function.prototype;)n.push(t),t=Object.getPrototypeOf(t);n.reverse();for(const t of n){if(t[$]){e[$]||(e[$]=new Map);for(const[n,o]of t[$])e[$].has(n)||e[$].set(n,o)}t.formAssociated&&!e.formAssociated&&(e.formAssociated=!0)}}(t),n.metadata&&n.metadata[$]){t[$]||(t[$]=new Map);for(const[e,o]of n.metadata[$])t[$].set(e,o)}else if(Lo.length>0){t[$]||(t[$]=new Map);const e=Lo.pop();for(const[n,o]of e)t[$].set(n,o)}o?.formAssociated&&(t.formAssociated=!0);const r={...Object.getPrototypeOf(t)?.[b]||{}},s=o||{};if("light"===s.renderRoot&&"string"==typeof s.shadow||"shadow"===s.renderRoot&&!1===s.shadow)throw new TypeError("snice: @element renderRoot and shadow options select conflicting render roots.");const i={...r,...s};return Object.prototype.hasOwnProperty.call(s,"shadow")?i.renderRoot=!1===s.shadow?"light":"shadow":Object.prototype.hasOwnProperty.call(s,"renderRoot")&&("light"===s.renderRoot?i.shadow=!1:!1===i.shadow&&(i.shadow="open")),t[b]=i,!0===t.prototype[ae]&&Object.prototype.hasOwnProperty.call(t.prototype,"render")&&!Object.prototype.hasOwnProperty.call(t.prototype,Z)&&"function"==typeof t.prototype.render&&(t.prototype[Z]=t.prototype.render,t.prototype[ee]=t.renderOptions||{}),Co(t),customElements.get(e)?(globalThis.SNICE_DEBUG&&console.warn(`[snice] "${e}" is already registered. Skipping.`),t):(customElements.define(e,t),t)}function ko(e,t){if(void 0!==t?.renderRoot&&"shadow"!==t.renderRoot&&"light"!==t.renderRoot)throw new TypeError('snice: @element renderRoot must be "shadow" or "light".');if(void 0!==t?.shadow&&!1!==t.shadow&&"open"!==t.shadow&&"closed"!==t.shadow)throw new TypeError('snice: @element shadow must be "open", "closed", or false.');return function(n,o){return Oo(e,n,o,t)}}function $o(e){return function(t,n){return Oo(e,t,n)}}const Lo=[],Po=new WeakMap;function jo(e){return function(t,n){const o=n.name;return n.metadata?(n.metadata[$]||(n.metadata[$]=new Map),n.metadata[$].set(o,e||{})):(0===Lo.length&&Lo.push(new Map),Lo[Lo.length-1].set(o,e||{})),function(t){const n=this[R],r=!0===n?.delete(o);0===n?.size&&delete this[R];const s=Object.prototype.hasOwnProperty.call(this,o),i=s&&(r||!function(e,t,n){const o=e?.ownerDocument;if(!o?.createElement)return!1;let r=Po.get(o);if(!r){const e=o.createElement("div");r=new Map;for(const t of Reflect.ownKeys(e))r.set(t,e[t]);Po.set(o,r)}return r.has(t)&&Object.is(r.get(t),n)}(this,o,this[o])),a=i?this[o]:t;s&&delete this[o];const c=this.constructor;c[$]||(c[$]=new Map);const l={...e};l.type||void 0===t||(l.type=Ve(t)),l.attributeNaming||"kebab"!==c.propertyAttributeNaming||(l.attributeNaming="kebab"),c[$].set(o,l),Ge(this,P)[o]=t;const h=()=>{if(!this[I])return;const e=this[L]?.[o];if(!1!==l.attribute&&!1!==l.reflect){const n=Fe(l,o),r=Ze(e,l,t),s=n.toLowerCase();Ke(this,Q).add(s);try{null===r?this.removeAttribute?.(n):this.setAttribute?.(n,r)}finally{this[Q].delete(s)}}this[w]&&(Qe(this,this.constructor,o,e,e),this[Z]&&co(this))},u=e=>{if(!l.deep)return e;let t;return t=function(e,t){if(!e||"object"!=typeof e)return e;const n=new WeakMap,o=new WeakMap,r=e=>e&&"object"==typeof e&&o.get(e)||e,s=e=>{if(!e||"object"!=typeof e)return e;if(n.has(e))return n.get(e);if(e instanceof Map){let i;const a=new Map;return i=new Proxy(e,{get(e,n){const o=xo(e,n);if(o.locked)return o.value;if(a.has(n))return a.get(n);let c;if("set"===n)c=(n,o)=>{n=r(n),o=r(o);const s=e.has(n),a=e.get(n);return e.set(n,o),s&&Object.is(a,o)||t(),i};else if("delete"===n)c=n=>{n=r(n);const o=e.delete(n);return o&&t(),o};else if("clear"===n)c=()=>{0!==e.size&&(e.clear(),t())};else if("get"===n)c=t=>s(e.get(r(t)));else if("has"===n)c=t=>e.has(r(t));else if("forEach"===n)c=(t,n)=>e.forEach((e,o)=>t.call(n,s(e),s(o),i));else if("values"===n)c=function*(){for(const t of e.values())yield s(t)};else if("keys"===n)c=function*(){for(const t of e.keys())yield s(t)};else if("entries"===n||n===Symbol.iterator)c=function*(){for(const[t,n]of e.entries())yield[s(t),s(n)]};else{const t=Reflect.get(e,n,e);if("function"!=typeof t)return t;if("constructor"===n)return t;c=t.bind(e)}return a.set(n,c),c}}),n.set(e,i),o.set(i,e),i}if(e instanceof Set){let i;const a=new Map;return i=new Proxy(e,{get(e,n){const o=xo(e,n);if(o.locked)return o.value;if(a.has(n))return a.get(n);let c;if("add"===n)c=n=>{n=r(n);const o=e.has(n);return e.add(n),o||t(),i};else if("delete"===n)c=n=>{n=r(n);const o=e.delete(n);return o&&t(),o};else if("clear"===n)c=()=>{0!==e.size&&(e.clear(),t())};else if("has"===n)c=t=>e.has(r(t));else if("forEach"===n)c=(t,n)=>e.forEach(e=>{const o=s(e);t.call(n,o,o,i)});else if("values"===n||"keys"===n||n===Symbol.iterator)c=function*(){for(const t of e.values())yield s(t)};else if("entries"===n)c=function*(){for(const t of e.values()){const e=s(t);yield[e,e]}};else{const t=Reflect.get(e,n,e);if("function"!=typeof t)return t;if("constructor"===n)return t;c=t.bind(e)}return a.set(n,c),c}}),n.set(e,i),o.set(i,e),i}if(!Array.isArray(e)&&!function(e){const t=Object.getPrototypeOf(e);return t===Object.prototype||null===t}(e))return e;const i=new Proxy(e,{get(e,t,n){const o=xo(e,t);return o.locked?o.value:s(Reflect.get(e,t,n))},set(e,n,o,s){const i=Reflect.get(e,n,s);o=r(o);const a=Reflect.set(e,n,o);return a&&!Object.is(i,o)&&t(),a},deleteProperty(e,n){const o=Object.prototype.hasOwnProperty.call(e,n),r=Reflect.deleteProperty(e,n);return r&&o&&t(),r},defineProperty(e,n,o){const s=Reflect.getOwnPropertyDescriptor(e,n),i="value"in o?{...o,value:r(o.value)}:o,a=Reflect.defineProperty(e,n,i),c=a?Reflect.getOwnPropertyDescriptor(e,n):s;return a&&!function(e,t){if(!e||!t)return e===t;const n="value"in e||"writable"in e;return n===("value"in t||"writable"in t)&&e.configurable===t.configurable&&e.enumerable===t.enumerable&&(!n||e.writable===t.writable&&Object.is(e.value,t.value))&&(n||e.get===t.get&&e.set===t.set)}(s,c)&&t(),a}});return n.set(e,i),o.set(i,e),i};return s(e)}(e,()=>{this[L]?.[o]===t&&h()}),t};Ge(this,j)[o]=u;const d=this.constructor.prototype;let f=d[ke];f&&Object.prototype.hasOwnProperty.call(d,ke)||(f=new Map(f),d[ke]=f);const m=f.get(o);m&&m===e||(f.set(o,e),Object.defineProperty(this.constructor.prototype,o,{get(){return this[M]?.has(o)?this[M].get(o):this[L]&&o in this[L]?this[L][o]:t},set(e){const t=this[o];if(!(l.hasChanged?l.hasChanged(e,t):Be(e,t)))return;const n=(this[j]?.[o]||(e=>e))(e);if(!this[I])return this[M]||(this[M]=new Map),void this[M].set(o,n);if(Ge(this,L)[o]=n,!1!==l.attribute&&!1!==l.reflect){const e=Fe(l,o),t=Ze(n,l,this[P]?.[o]);Ke(this,V).add(o);const r=e.toLowerCase();Ke(this,Q).add(r);try{null===t?this.removeAttribute?.(e):this.setAttribute?.(e,t)}finally{this[Q].delete(r)}}this[w]&&(Qe(this,this.constructor,o,t,n),this[Z]&&co(this))},configurable:!0,enumerable:!0}));const p=u(t);return Ge(this,L)[o]=p,Ge(this,P)[o]=p,i?a:p}}}function Mo(e={}){return jo({...e,attribute:!1,reflect:!1})}function Ro(e){return!0===e[o]&&e.element?e.element:e}function Io(e,t={}){return function(n,o){const{light:r=!1,shadow:s=!0}=t,i=o.name;return function(t){return Object.hasOwn(this.constructor.prototype,i)||Object.defineProperty(this.constructor.prototype,i,{get(){const t=Ro(this);let n=null;const o=t instanceof HTMLElement?ln(t):null;return s&&o?n=o.querySelector(e):s&&t.shadowRoot&&(n=t.shadowRoot.querySelector(e)),!n&&r&&(n=t.querySelector(e)),n||null},set(){},configurable:!0,enumerable:!0}),t}}}function Do(e,t={}){return function(n,o){const{light:r=!1,shadow:s=!0}=t,i=o.name;return function(t){return Object.hasOwn(this.constructor.prototype,i)||Object.defineProperty(this.constructor.prototype,i,{get(){const t=Ro(this),n=new Set,o=t instanceof HTMLElement?ln(t):null;if(s&&o)for(const t of o.querySelectorAll(e))n.add(t);else if(s&&t.shadowRoot)for(const o of t.shadowRoot.querySelectorAll(e))n.add(o);if(r)for(const o of t.querySelectorAll(e))n.add(o);return[...n]},set(){},configurable:!0,enumerable:!0}),t}}}function Vo(...e){const t=e.filter(e=>"string"==typeof e),n=e.find(e=>"object"==typeof e&&null!==e),o=!1!==n?.immediate;return function(e,n){const r=n.name;n.addInitializer(function(){const n=this.constructor;Object.prototype.hasOwnProperty.call(n,ve)||(n[ve]=new Map);let s=n[ve].get(e);if(s||(s=new Set,n[ve].set(e,s)),!Object.prototype.hasOwnProperty.call(n,D)){const e=n[D],t=new Map;if(e)for(const[n,o]of e)t.set(n,[...o]);n[D]=t}for(const i of t)s.has(i)||(s.add(i),n[D].has(i)||n[D].set(i,[]),n[D].get(i).push({methodName:r,method:e,immediate:o}))})}}function qo(){return function(e,t){const n=t.name;return function(e){return Object.hasOwn(this.constructor.prototype,n)||Object.defineProperty(this.constructor.prototype,n,{get(){if(void 0!==this[q])return this[q];const e=dt(this);return void 0!==e?e:void 0},set(){},configurable:!0,enumerable:!0}),e}}}function Bo(e,t,n,o,r){const s=o.name;o.addInitializer(function(){const o=this.constructor;if(Object.prototype.hasOwnProperty.call(o,t)||(o[t]=new Set),!o[t].has(n)){if(o[t].add(n),!Object.prototype.hasOwnProperty.call(o,e)){const t=o[e];o[e]=t?[...t]:[]}o[e].push({methodName:s,method:n,...r})}})}function Fo(){return function(e,t){Bo(W,Ae,e,t)}}function Wo(){return function(e,t){Bo(z,Se,e,t)}}function zo(){return function(e,t){Bo(U,Te,e,t)}}function Uo(e,t){const n=e[t];if(n)for(const e of n.values())e.debounceTimer&&clearTimeout(e.debounceTimer),e.throttleTimer&&clearTimeout(e.throttleTimer),e.debounceTimer=null,e.throttleTimer=null,e.lastThrottleCall=0}function Ho(e,t,n){return function(o={}){return function(r,s){Bo(e,n,r,s,{options:o});const i=s.name;return function(...e){this[t]||(this[t]=new Map),this[t].has(i)||this[t].set(i,{throttleTimer:null,debounceTimer:null,lastThrottleCall:0});const n=this[t].get(i),s=(...e)=>r.apply(this,e),a=(...e)=>{try{const t=r.apply(this,e);t&&"function"==typeof t.then&&t.catch(e=>console.error(`Error in deferred lifecycle handler ${i}:`,e))}catch(e){console.error(`Error in deferred lifecycle handler ${i}:`,e)}};if(o.debounce>0)return clearTimeout(n.debounceTimer),void(n.debounceTimer=setTimeout(()=>a(...e),o.debounce));if(o.throttle>0){const t=Date.now();return 0===n.lastThrottleCall||t-n.lastThrottleCall>=o.throttle?(n.lastThrottleCall=t,s(...e)):void(n.throttleTimer||(n.throttleTimer=setTimeout(()=>{n.throttleTimer=null,n.lastThrottleCall=Date.now(),a(...e)},o.throttle-(t-n.lastThrottleCall))))}return s(...e)}}}}const Ko=Ho(H,J,_e),Go=Ho(K,X,xe);class Qo extends HTMLElement{static{this.propertyAttributeNaming="kebab"}createRenderRoot(){const e=this.constructor[b];return this.attachShadow({mode:"string"==typeof e?.shadow?e.shadow:"open",delegatesFocus:e?.delegatesFocus})}invalidate(){return co(this),this.rendered}renderNow(){return function(e){to(e),ao(e,{...e[ee]||{},once:!1})}(this),this.rendered}}Object.defineProperty(Qo.prototype,ae,{value:!0});class Jo{constructor(e){this.parsed=this.parsePattern(e)}get spec(){return this.parsed.template}parsePattern(e){let t=e,n="",o=!1;const r=e.indexOf("?");return-1!==r&&(t=e.slice(0,r),n=e.slice(r+1),t.endsWith("(")&&n.endsWith(")")&&(o=!0,t=t.slice(0,-1),n=n.slice(0,-1))),{pathSegments:this.parseSegments(t),querySegments:n?this.parseQuerySegments(n):[],queryOptional:o,template:e}}parseSegments(e){const t=[];let n=0;for(;n<e.length;)switch(e[n]){case"(":const{segments:o,endIndex:r}=this.parseOptionalGroup(e,n);t.push({type:"optional",segments:o}),n=r+1;break;case":":const{name:s,endIndex:i}=this.parseIdentifier(e,n+1);t.push({type:"param",name:s}),n=i;break;case"*":const{name:a,endIndex:c}=this.parseIdentifier(e,n+1);t.push({type:"splat",name:a}),n=c;break;default:const{value:l,endIndex:h}=this.parseLiteral(e,n);l&&t.push({type:"literal",value:l}),n=h}return t}parseOptionalGroup(e,t){let n=1,o=t+1;for(;o<e.length&&n>0;)"("===e[o]&&n++,")"===e[o]&&n--,o++;const r=e.slice(t+1,o-1);return{segments:this.parseSegments(r),endIndex:o-1}}parseIdentifier(e,t){let n=t;for(;n<e.length&&/[\w-]/.test(e[n]);)n++;return{name:e.slice(t,n),endIndex:n}}parseLiteral(e,t){let n=t;for(;n<e.length&&!"(:*(".includes(e[n]);)n++;return{value:e.slice(t,n),endIndex:n}}parseQuerySegments(e){let t=e;t.startsWith("(")&&t.endsWith(")")&&(t=t.slice(1,-1));const n=[];let o=0;for(;o<t.length;)if(":"===t[o]){const{name:e,endIndex:r}=this.parseIdentifier(t,o+1);n.push({type:"param",name:e}),o=r}else{const{value:e,endIndex:r}=this.parseQueryLiteral(t,o);e&&n.push({type:"literal",value:e}),o=r}return n}parseQueryLiteral(e,t){let n=t;for(;n<e.length&&":"!==e[n];)n++;return{value:e.slice(t,n),endIndex:n}}getAllParamNames(){const e=new Set,t=n=>{for(const o of n)switch(o.type){case"param":case"splat":e.add(o.name);break;case"optional":t(o.segments)}};return t(this.parsed.pathSegments),t(this.parsed.querySegments),Array.from(e)}canMatchRemainingSegments(e,t,n){let o=t;for(const t of n)if("literal"===t.type){const n=e.indexOf(t.value,o);if(-1===n)return!1;o=n+t.value.length}return!0}match(e){const[t,n]=e.split("?"),o=this.matchPath(t,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 e of s)i[e]=void 0;return Object.assign(i,o,r),i}matchPath(e,t){const n={};let o=0;for(let r=0;r<t.length;r++){const s=t[r],i=t.slice(r+1),a=this.matchSegment(e,o,s,i);if(!1===a)return!1;Object.assign(n,a.params),o=a.nextIndex}return!(o<e.length)&&n}matchSegment(e,t,n,o=[]){switch(n.type){case"literal":return e.slice(t,t+n.value.length)===n.value&&{params:{},nextIndex:t+n.value.length};case"param":{let r=t;const s=o[0];let i,a=["/","?"];if(s&&"literal"===s.type){const n=e.indexOf(s.value,t);if(-1===n)return!1;r=n}else for(;r<e.length&&!a.includes(e[r]);)r++;if(r===t)return!1;try{i=decodeURIComponent(e.slice(t,r))}catch(n){i=e.slice(t,r)}return!(r<e.length&&"?"===e[r]&&o.length>0)&&{params:{[n.name]:i},nextIndex:r}}case"splat":{let r=e.length;const s=o[0];if(s)switch(s.type){case"literal":if("."===s.value){const n=e.indexOf(".",t);-1!==n&&(r=n)}else{const n=e.lastIndexOf(s.value);-1!==n&&n>=t&&(r=n)}break;case"param":let n=-1;for(let o=e.length-1;o>=t;o--)if("/"===e[o]){n=o;break}-1!==n&&(r=n);break;case"splat":let o=-1;for(let n=e.length-1;n>t;n--)if("/"===e[n]){o=n+1;break}if(-1!==o)r=o;else{const n=e.slice(t).split("/").filter(e=>e);r=n.length>1?t+n.slice(0,-1).join("/").length+1:t}break;case"optional":const i=e=>{for(const t of e){if("literal"===t.type)return t.value;if("optional"===t.type){const e=i(t.segments);if(e)return e}}return null},a=i(s.segments);if(a){const n=e.lastIndexOf(a);-1!==n&&n>=t&&(r=n)}}const i=e.indexOf("?",t);let a;-1!==i&&i<r&&(r=i);try{a=decodeURIComponent(e.slice(t,r))}catch(n){a=e.slice(t,r)}return{params:{[n.name]:a},nextIndex:r}}case"optional":{let r=t,s={},i=!0;for(let t=0;t<n.segments.length;t++){const o=n.segments[t],a=n.segments.slice(t+1),c=this.matchSegment(e,r,o,a);if(!1===c){i=!1;break}Object.assign(s,c.params),r=c.nextIndex}return i&&this.canMatchRemainingSegments(e,r,o)?{params:s,nextIndex:r}:{params:{},nextIndex:t}}default:return!1}}findNextLiteral(e){for(const t of e){if("literal"===t.type)return t;if("optional"===t.type){const e=this.findNextLiteral(t.segments);if(e)return e}}return null}matchQuery(e,t){if(0===t.length)return{};const n={};let o=0;for(const r of t)switch(r.type){case"literal":if(e.slice(o,o+r.value.length)!==r.value)return!1;o+=r.value.length;break;case"param":{let t,s=o;for(;s<e.length&&"&"!==e[s];)s++;if(s===o)return!1;try{t=decodeURIComponent(e.slice(o,s))}catch(n){t=e.slice(o,s)}n[r.name]=t,o=s;break}}return n}reverse(e={}){const t=this.reverseSegments(this.parsed.pathSegments,e);if(!1===t)return!1;let n=t;if(this.parsed.querySegments.length>0){const t=this.reverseSegments(this.parsed.querySegments,e);if(!this.parsed.queryOptional&&!1===t)return!1;t&&""!==t&&(n+="?"+t)}return n}reverseSegments(e,t,n=!1){let o="";for(let r=0;r<e.length;r++){const s=e[r],i=e.slice(r+1);switch(s.type){case"literal":o+=s.value;break;case"param":case"splat":if(!(s.name in t))return!1;o+=String(t[s.name]);break;case"optional":if(this.hasAllParams(s.segments,t,n)||this.hasLaterOptionalGroupNeedingParams(i,t,s.segments)){const e=this.reverseSegments(s.segments,t,!0);if(!1===e)return!1;o+=e}}}return o}hasLaterOptionalGroupNeedingParams(e,t,n){for(const o of e)if("optional"===o.type&&this.hasAnyParamInSegments(o.segments,t))return this.hasOnlyLiteralsAndOptionals(n);return!1}hasOnlyLiteralsAndOptionals(e){for(const t of e)if("param"===t.type||"splat"===t.type)return!1;return!0}hasAllParams(e,t,n=!1){let o=!1,r=!1,s=!1,i=!0;for(const n of e)switch(n.type){case"param":case"splat":i=!1,n.name in t&&void 0!==t[n.name]?o=!0:s=!0}const a=n||o&&!s;for(const n of e)"optional"===n.type&&this.hasAllParams(n.segments,t,a)&&(r=!0);return!(!o||s)||!(!r||s)||!(!i||!n)}hasOnlyOptionalMissingParams(e,t){for(const n of e)switch(n.type){case"param":case"splat":if(!(n.name in t))return!1}return!0}hasAnyParamInSegments(e,t){for(const n of e)switch(n.type){case"param":case"splat":if(n.name in t)return!0;break;case"optional":if(this.hasAnyParamInSegments(n.segments,t))return!0}return!1}}function Xo(e){const t=e.split("/").filter(Boolean);let n=t.length;for(const e of t)e.startsWith("*")?n+=-2:e.startsWith(":")?n+=3:n+=10;return n}function Yo(e){const t={};return e.split(";").forEach(e=>{const n=e.indexOf(":");if(-1===n)return;const o=e.slice(0,n).trim(),r=e.slice(n+1).trim();o&&r&&(t[o]=r)}),t}function Zo(e,t,n,o){if(e.style.position="absolute",e.style.width="100%",t)return e.style.height="100%",void(e.style.transition=`opacity ${n}ms ease-in-out`);e.style.top="0",e.style.left="0",e.style.transition=`${o} ${n}ms ease-in-out`}function er(e,t){Object.defineProperty(e.prototype,r,{value:!0,configurable:!0})}function tr(e){if(!mt(e))throw new TypeError("Application contexts may provide only instances of @daemon classes.");const t=pt(e);if(0===t.bindings){t.active=!0;try{$t(e,t.target),wt(e,t.target)}catch(n){throw Et(e),Lt(e),t.active=!1,n}}t.bindings+=1;let n=!1;return()=>{n||(n=!0,t.bindings=Math.max(0,t.bindings-1),0===t.bindings&&(Et(e),Lt(e),mo(e),t.active=!1,t.target=new EventTarget))}}function nr(e,t,n,o){const r=function(e,t,n,o){if(!e||"function"!=typeof e.addEventListener||"function"!=typeof e.removeEventListener)throw new TypeError("provideContext() requires an EventTarget root.");if(!t||"object"!=typeof t)throw new TypeError("provideContext() requires an application context object.");if(ht.has(e))throw new Error("This root already provides an application context. Release it before providing another.");const r=e=>{const r=e;if(r.detail){if("application"===r.detail.kind){if(void 0!==r.detail.context)return;r.detail.context=t}else if("fetch"===r.detail.kind){if(!n||void 0!==r.detail.fetch)return;r.detail.fetch=n}else{if("navigation"!==r.detail.kind)return;if(!o||void 0!==r.detail.navigation)return;r.detail.navigation=o}r.preventDefault(),r.stopPropagation()}};e.addEventListener(lt,r),ht.set(e,{listener:r});let s=!1;return()=>{if(s)return;s=!0;const t=ht.get(e);t?.listener===r&&(e.removeEventListener(lt,r),ht.delete(e))}}(e,t,n.fetch,o);let s;try{s=function(e){const t=e.daemons;if(void 0===t)return()=>{};if(!t||"object"!=typeof t||Array.isArray(t))throw new TypeError("AppContext.daemons must be a readonly record of named @daemon instances.");const n=[],o=new Set;try{for(const[e,r]of Object.entries(t)){if(!e.trim())throw new TypeError("AppContext.daemons keys must be non-empty strings.");if(!r||"object"!=typeof r)throw new TypeError(`AppContext.daemons["${e}"] must be an instance of an @daemon class.`);o.has(r)||(o.add(r),n.push(tr(r)))}}catch(e){for(const e of n.reverse())e();throw e}return()=>{for(const e of n.reverse())e()}}(t)}catch(e){throw r(),e}let i=!1;return()=>{i||(i=!0,r(),s?.())}}function or(e,t,n={}){return nr(e,t,n)}const rr=new WeakMap;var sr;function ir(e){const t=e.window??window,n=e.document??document,o=[];let r,s,i,a=0,c=!1,l=[],h=null,u=null;const d=e.context||{};let f=null,m=null;const p=new De(d,[],"",{},e.fetcher);function y(e){if(f===e&&m&&rr.get(e)===m)return;m?.(),rr.get(e)?.();const t=nr(e,(n=p).application,{fetch:n.fetch},n);var n;let o=!1;const r=()=>{o||(o=!0,t(),rr.get(e)===r&&rr.delete(e))};m=r,f=e,rr.set(e,r)}function g(e){if(!h||!u)return null;const t=e.querySelectorAll(h);for(const e of t)if(e[F]===u)return e;return null}function b(e,t,n,l,h,u,d=0){if(!Number.isFinite(d))throw new TypeError(`Route order for "${e}" must be a finite number.`);switch(o.push({route:new Jo(e),tag:t,transition:n,guards:l,layout:h,placard:u,order:d,registrationOrder:a++}),c=!1,e){case"/404":r=t;break;case"/403":s=t;break;case"/":i=t}}function v(){const e=new Set;l=o.filter(e=>e.placard).map(e=>{const t=e.placard;return"function"==typeof t?t(d):t}).filter(t=>!e.has(t.name)&&(e.add(t.name),!0))}function w(e,t,n){p[ge](d,l,t,n)}function E(){switch(e.type){case"hash":return t.location.hash.slice(1);case"pushstate":return`${t.location.pathname}${t.location.search}`}}function N(e){let t;if(s)t=n.createElement(s),t[q]=d;else{const e=n.createElement("div");e.className="default-403",e.innerHTML="<h1>403</h1><p>Unauthorized</p>",t=e}e.innerHTML="",e.appendChild(t),h=null,u=null}async function A(e,t,o,r){if(!e)return!0;const s=Array.isArray(e)?e:[e];let i=null,a=null;a=setTimeout(()=>{r&&r()||(i=function(){const e=n.createElement("div");return e.setAttribute("data-snice-loading",""),e.innerHTML='\n <style>@keyframes snice-spin{to{transform:rotate(360deg)}}</style>\n <div style="display:flex;align-items:center;justify-content:center;height:100%;min-height:200px">\n <div style="width:32px;height:32px;border:3px solid rgba(128,128,128,0.3);border-top-color:rgba(128,128,128,0.8);border-radius:50%;animation:snice-spin 0.6s linear infinite"></div>\n </div>',e}(),o.appendChild(i))},50);try{for(const e of s)if(!await e(d,t))return r&&r()||N(o),!1;return!0}finally{a&&clearTimeout(a),i&&i.remove()}}async function S(t,o,r,s,i,a,c){const f=!1===(m=s)?null:m||(e.layout?e.layout:null);var m;const{element:p,needsNewLayout:y}=function(e){if(e===h)return{element:null,needsNewLayout:!1};if(h=e,e){const t=Date.now();u=t;const o=n.createElement(e);return o[q]=d,o[F]=t,{element:o,needsNewLayout:!0}}return u=null,{element:null,needsNewLayout:!0}}(f),b=r||e.transition;if(null!==p||null!==g(t)){if(await async function(e,t,n,o,r,s,i,a){const c=o||g(e);if(!c)return;!function(e,t,n){"function"==typeof e.update&&e.update(d,l,t,n)}(c,s,i);const h=c.querySelector('[slot="page"]');if(n&&h){if(t.setAttribute("slot","page"),await x(c,h,t,n),a&&a())return;r&&(e.innerHTML="",e.appendChild(c))}else a&&a()||(c.querySelectorAll('[slot="page"]').forEach(e=>e.remove()),t.setAttribute("slot","page"),c.appendChild(t),r&&(e.innerHTML="",e.appendChild(c)))}(t,o,b,p,y,i,a,c),c&&c())return;w(0,i,a)}else await async function(e,t,n,o){const r=e.children[0];n&&r?await x(e,r,t,n):o&&o()||(e.innerHTML="",e.appendChild(t))}(t,o,b,c),c&&c()||w(0,i,a)}let T=0;async function _(s){const a=n.querySelector(e.target);if(!a)throw new Error(`Target element not found: ${e.target}`);y(a);const c=++T,l=()=>c!==T;if(v(),t.scrollTo(0,0),(""===s?.trim()||"/"===s)&&i){const e=o.find(e=>e.route.match("/"));if(!await A(e?.guards,{},a,l))return;if(l())return;const{element:r,transition:c,layout:h}=function(){const e=n.createElement(i);e[q]=d;const r=t.customElements.get(i),s=r?.[B],a=o.find(e=>e.route.match("/"));return{element:e,transition:s,layout:a?.layout}}();return void await S(a,r,c,h,s,{},l)}if(!s)return;const h=await async function(e,t,r){for(const s of o){const o=s.route.match(e);if(!1===o)continue;if(!await A(s.guards,o,t,r))return{result:sr.GUARDS_FAILED};const i=n.createElement(s.tag);i[q]=d,i[ce]=p;const a=o;return Object.keys(a).forEach(e=>i.setAttribute(e,a[e])),{result:sr.SUCCESS,element:i,transition:s.transition,layout:s.layout,routeParams:a}}return{result:sr.NOT_FOUND}}(s,a,l);if(l())return;if(h.result===sr.GUARDS_FAILED)return;if(h.result===sr.SUCCESS){const{element:e,transition:t,layout:n,routeParams:o={}}=h;return void await S(a,e,t,n,s,o,l)}const{element:u,transition:f,layout:m}=function(){if(r){const e=n.createElement(r);e[q]=d;const o=t.customElements.get(r),s=o?.[B];return{element:e,transition:s,layout:void 0}}const e=n.createElement("div");return e.className="default-404",e.innerHTML="<h1>404</h1><p>Page not found</p>",{element:e,transition:void 0,layout:void 0}}();await S(a,u,f,m,s,{},l)}async function x(e,t,n,o,r=T){return async function(e,t,n,o={},r=()=>!1){const s=o.outDuration??300,i=o.inDuration??300,a=o.mode||"sequential",c=o.out?Yo(o.out):{opacity:"0"},l={opacity:"0"},h=o.in?Yo(o.in):{opacity:"1"},u=e.style,d=e.tagName.includes("-")&&e.shadowRoot,f=Symbol.for("snice:transition-original-position"),m=Symbol.for("snice:transition-count"),p=e;d||(f in p||(p[f]=u.position,p[m]=0),p[m]++,u.position="relative");const y=()=>{d||(p[m]--,p[m]<=0&&(u.position=p[f],delete p[f],delete p[m]))},g=t.hasAttribute("slot")||n.hasAttribute("slot");switch(Zo(t,g,s,"all"),Zo(n,g,i,"all"),Object.assign(n.style,l),e.appendChild(n),a){case Le.SIMULTANEOUS:Object.assign(t.style,c),Object.assign(n.style,h),await new Promise(e=>setTimeout(e,Math.max(s,i)));break;case Le.SEQUENTIAL:if(Object.assign(t.style,c),await new Promise(e=>setTimeout(e,s)),r())return n.parentNode===e&&n.remove(),void y();Object.assign(n.style,h),await new Promise(e=>setTimeout(e,i))}if(r())return n.parentNode===e&&n.remove(),void y();t.remove(),function(e,t){e.style.position="",e.style.width="",e.style.transition="",t?e.style.height="":(e.style.top="",e.style.left="")}(n,g),Object.keys({...l,...h}).forEach(e=>{n.style[e]=""}),y()}(e,t,n,o,()=>r!==T)}return{page:function(e){return function(n,o){if(o?.metadata&&o.metadata[$]){n[$]||(n[$]=new Map);for(const[e,t]of o.metadata[$])n[$].set(e,t)}Co(n),n[B]=e.transition;const r=n.prototype.connectedCallback;n.prototype.connectedCallback=function(){this[ce]=p,r?.call(this)};const s=n.prototype.disconnectedCallback;return n.prototype.disconnectedCallback=function(){s?.call(this),delete this[q],delete this[ce]},t.customElements.get(e.tag)||t.customElements.define(e.tag,n),e.routes.forEach(t=>{b("string"==typeof t?t:t.path,e.tag,e.transition,e.guards,e.layout,e.placard,"string"==typeof t?void 0:t.order)}),n}},initialize:function(){const r=n.querySelector(e.target);if(!r)throw new Error(`Target element not found: ${e.target}`);y(r),!c&&(o.sort((e,t)=>Xo(t.route.spec)-Xo(e.route.spec)||e.order-t.order||e.registrationOrder-t.registrationOrder),c=!0),v(),function(){const o=()=>{const t=n.querySelector(e.target);if(t&&(f!==t||!m||rr.get(t)===m))return f!==t&&ht.has(t)?(m?.(),m=null,void(f=null)):void _(E())};switch(e.type){case"hash":t.addEventListener("hashchange",o);break;case"pushstate":t.addEventListener("popstate",o)}}(),_(E())},navigate:async function(n){const o=function(e){const t=e.trim().replace(/^#/,"");return t?t.startsWith("/")?t:`/${t}`:"/"}(n);!function(n){switch(e.type){case"hash":{const e=`#${n}`;t.location.hash!==e&&t.history.pushState(null,"",e);break}case"pushstate":`${t.location.pathname}${t.location.search}`!==n&&t.history.pushState(null,"",n)}}(o),await _(o)},register:b}}function ar(e,t,n){const o=[];for(const[r,s]of Object.entries(t)){const t=`@request/${r}`,i=e=>{const t=e,{discovery:o,data:i,payload:a}=t.detail;n?.passive||(t.preventDefault(),t.stopImmediatePropagation(),t.stopPropagation()),o.resolve(),Promise.resolve().then(()=>s(a)).then(e=>i.resolve(e)).catch(e=>{i.reject(e),console.error(`createRequestHandler: error in "${r}" handler:`,e)})};e.addEventListener(t,i),o.push(()=>e.removeEventListener(t,i))}return()=>{for(const e of o)e();o.length=0}}function cr(e){let t="";for(const n of Object.keys(e))e[n]&&(t+=(t?" ":"")+n);return t}function lr(e){const t=[];for(const n of Object.keys(e)){const o=e[n];if(null==o||!1===o)continue;const r=n.startsWith("--")?n:n.replace(/[A-Z]/g,e=>"-"+e.toLowerCase());t.push(`${r}: ${o}`)}return t.join("; ")}!function(e){e.SUCCESS="success",e.GUARDS_FAILED="guards-failed",e.NOT_FOUND="not-found"}(sr||(sr={}));let hr=!1;function ur(e){hr=e}async function dr(e,t=500){if(customElements.get(e))return;let n=null;hr||(n=setTimeout(()=>{console.warn(`Custom element <${e}> is taking longer than ${t}ms to register. This may indicate a missing import or circular dependency. Set DISABLE_ELEMENT_READY_WARNINGS=true to disable this warning.`)},t));try{await customElements.whenDefined(e)}finally{n&&clearTimeout(n)}}async function fr(e,t=500){const n=e.tagName.toLowerCase();await dr(n,t),"ready"in e&&"function"==typeof e.ready?.then&&await e.ready}async function mr(e,t=500){const n=[];e instanceof Element&&(e.tagName.includes("-")&&n.push(e),e.shadowRoot)&&e.shadowRoot.querySelectorAll("*").forEach(e=>{e.tagName.includes("-")&&n.push(e)}),e instanceof DocumentFragment&&e.querySelectorAll("*").forEach(e=>{e.tagName.includes("-")&&n.push(e)}),await Promise.all(n.map(e=>fr(e,t)))}async function*pr(e){for(;;)await new Promise(t=>{e[oe]||(e[oe]=[]),e[oe].push(t)}),yield}let yr=0,gr=null;const br=Symbol.for("snice:body-scroll-lock");function vr(){0===yr&&(gr=document.body.style.overflow,document.body.style.overflow="hidden"),yr++}function wr(){0!==yr&&(yr--,0===yr&&(document.body.style.overflow=gr??"",gr=null))}function Er(){return yr}globalThis[br]={clear(){yr=0,gr=null}};class Nr{constructor(){this.requestMiddlewares=[],this.responseMiddlewares=[]}use(e,t){"request"!==e?this.responseMiddlewares.push(t):this.requestMiddlewares.push(t)}create(e){const t=this.requestMiddlewares,n=this.responseMiddlewares;return async function(e,o){const r=new Request(e,o);let s=0;const i=async()=>{if(s<t.length)return t[s++].call(this,r,i);const e=await fetch(r);let o=0;const a=async()=>o<n.length?n[o++].call(this,e,a):e;return a()};return i()}.bind(e)}}var Ar;"undefined"!=typeof document&&Ht(),globalThis.snice||(globalThis.snice={controllerRegistry:new Map,pendingControllerAttachments:new Map,controllerIdCounter:0}),globalThis.snice.pendingControllerAttachments??=new Map,function(e){e.SEQUENTIAL="sequential",e.SIMULTANEOUS="simultaneous"}(Ar||(Ar={}));export{De as Context,Nr as ContextAwareFetcher,o as IS_CONTROLLER_INSTANCE,ir as Router,$e as SimpleArray,Qo as SniceElement,Le as TransitionMode,Go as adopted,Co as applyElementFunctionality,Wt as attachController,cr as classMap,Ao as clearDebounceTimers,To as clearMemoizeCache,So as clearThrottleTimers,jt as context,qo as contextProperty,Dt as controller,ar as createRequestHandler,Yt as css,er as daemon,vo as debounce,zt as detachController,fo as dispatch,Wo as dispose,ko as element,ze as escapeAttr,We as escapeHtml,Er as getBodyScrollLockCount,dt as getContext,ft as getContextFetch,Ut as getController,t as getSymbol,Jt as html,Ue as isSafeUrl,$o as layout,En as live,vr as lockBodyScroll,No as memoize,Ko as moved,vn as noChange,tn as nothing,nt as observe,Ct as on,Eo as once,He as parseDuration,jo as property,or as provideContext,Io as query,Do as queryAll,Fo as ready,zo as reconnect,ho as render,an as repeat,bt as request,_o as resetOnce,vt as respond,ur as setDisableElementReadyWarnings,eo as setStrictRenderErrors,Mo as state,lr as styleMap,uo as styles,Xt as svg,wo as throttle,pr as trackRenders,wr as unlockBodyScroll,on as unsafeHTML,Ht as useNativeElementControllers,mr as waitForAllCustomElements,dr as waitForElementDefined,fr as waitForElementReady,Vo as watch};
|
|
2
2
|
//# sourceMappingURL=snice-runtime.esm.min.js.map
|