/**
 * @license
 * Copyright 2021 Google LLC
 * SPDX-License-Identifier: BSD-3-Clause
 */
const t=new WeakMap,s=s=>{if((t=>void 0!==t.pattern)(s))return s.pattern;let i=t.get(s);return void 0===i&&t.set(s,i=new URLPattern({pathname:s.path})),i};class i{constructor(t,s,i){this.routes=[],this.o=[],this.t={},this.i=t=>{if(t.routes===this)return;const s=t.routes;this.o.push(s),s.h=this,t.stopImmediatePropagation(),t.onDisconnect=()=>{this.o?.splice(this.o.indexOf(s)>>>0,1)};const i=o(this.t);void 0!==i&&s.goto(i)},(this.l=t).addController(this),this.routes=[...s],this.fallback=i?.fallback}link(t){if(t?.startsWith("/"))return t;if(t?.startsWith("."))throw Error("Not implemented");return t??=this.u,(this.h?.link()??"")+t}async goto(t){let i;if(0===this.routes.length&&void 0===this.fallback)i=t,this.u="",this.t={0:i};else{const e=this.p(t);if(void 0===e)throw Error("No route found for "+t);const h=s(e).exec({pathname:t}),n=h?.pathname.groups??{};if(i=o(n),"function"==typeof e.enter&&!1===await e.enter(n))return;this.v=e,this.t=n,this.u=void 0===i?t:t.substring(0,t.length-i.length)}if(void 0!==i)for(const t of this.o)t.goto(i);this.l.requestUpdate()}outlet(){return this.v?.render?.(this.t)}get params(){return this.t}p(t){const i=this.routes.find((i=>s(i).test({pathname:t})));return i||void 0===this.fallback?i:this.fallback?{...this.fallback,path:"/*"}:void 0}hostConnected(){this.l.addEventListener(e.eventName,this.i);const t=new e(this);this.l.dispatchEvent(t),this._=t.onDisconnect}hostDisconnected(){this._?.(),this.h=void 0}}const o=t=>{let s;for(const i of Object.keys(t))/\d+/.test(i)&&(void 0===s||i>s)&&(s=i);return s&&t[s]};class e extends Event{constructor(t){super(e.eventName,{bubbles:!0,composed:!0,cancelable:!1}),this.routes=t}}e.eventName="lit-routes-connected";export{i as Routes,e as RoutesConnectedEvent};
//# sourceMappingURL=routes.js.map
