const w=/^(\[)?(\.\.\.)?(\w+)(?:=(\w+))?(\])?$/;function v(t){const i=[];return{pattern:t==="/"?/^\/$/:new RegExp(`^${m(t).map(a=>{const s=/^\[\.\.\.(\w+)(?:=(\w+))?\]$/.exec(a);if(s)return i.push({name:s[1],matcher:s[2],optional:!1,rest:!0,chained:!0}),"(?:/([^]*))?";const c=/^\[\[(\w+)(?:=(\w+))?\]\]$/.exec(a);if(c)return i.push({name:c[1],matcher:c[2],optional:!0,rest:!1,chained:!0}),"(?:/([^/]+))?";if(!a)return;const n=a.split(/\[(.+?)\](?!\])/);return"/"+n.map((e,u)=>{if(u%2){if(e.startsWith("x+"))return h(String.fromCharCode(parseInt(e.slice(2),16)));if(e.startsWith("u+"))return h(String.fromCharCode(...e.slice(2).split("-").map(g=>parseInt(g,16))));const o=w.exec(e),[,l,p,_,d]=o;return i.push({name:_,matcher:d,optional:!!l,rest:!!p,chained:p?u===1&&n[0]==="":!1}),p?"([^]*?)":l?"([^/]*)?":"([^/]+?)"}return h(e)}).join("")}).join("")}/?$`),params:i}}function $(t){return t!==""&&!/^\([^)]+\)$/.test(t)}function m(t){return t.slice(1).split("/").filter($)}function j(t,i,f){const a={},s=t.slice(1),c=s.filter(r=>r!==void 0);let n=0;for(let r=0;r<i.length;r+=1){const e=i[r];let u=s[r-n];if(e.chained&&e.rest&&n&&(u=s.slice(r-n,r+1).filter(o=>o).join("/"),n=0),u===void 0){e.rest&&(a[e.name]="");continue}if(!e.matcher||f[e.matcher](u)){a[e.name]=u;const o=i[r+1],l=s[r+1];o&&!o.rest&&o.optional&&l&&e.chained&&(n=0),!o&&!l&&Object.keys(a).length===c.length&&(n=0);continue}if(e.optional&&e.chained){n++;continue}return}if(!n)return a}function h(t){return t.normalize().replace(/[[\]]/g,"\\$&").replace(/%/g,"%25").replace(/\//g,"%2[Ff]").replace(/\?/g,"%3[Ff]").replace(/#/g,"%23").replace(/[.*+?^${}()|\\]/g,"\\$&")}const x=/\[(\[)?(\.\.\.)?(\w+?)(?:=(\w+))?\]\]?/g;function b(t,i){return"/"+m(t).map(a=>a.replace(x,(s,c,n,r)=>{const e=i[r];if(!e){if(c||n&&e!==void 0)return"";throw new Error(`Missing parameter '${r}' in route ${t}`)}if(e.startsWith("/")||e.endsWith("/"))throw new Error(`Parameter '${r}' in route ${t} cannot start or end with a slash -- this would cause an invalid route like foo//bar`);return e})).filter(Boolean).join("/")}export{j as e,v as p,b as r};
