function e(e){return e.replace(/([.+*?=^!:${}()[\]|/\\])/g,"\\$1")}function r(e){return e&&e.sensitive?"":"i"}function n(n,i,t){return function(n,i,t){void 0===t&&(t={});for(var f=t.strict,a=void 0!==f&&f,o=t.start,u=void 0===o||o,v=t.end,p=void 0===v||v,E=t.encode,s=void 0===E?function(e){return e}:E,d="["+e(t.endsWith||"")+"]|$",l="["+e(t.delimiter||"/#?")+"]",x=u?"^":"",c=0,y=n;c<y.length;c++){var w=y[c];if("string"==typeof w)x+=e(s(w));else{var A=e(s(w.prefix)),R=e(s(w.suffix));w.pattern?(i&&i.push(w),x+=A||R?"+"===w.modifier||"*"===w.modifier?"(?:"+A+"((?:"+w.pattern+")(?:"+R+A+"(?:"+w.pattern+"))*)"+R+")"+("*"===w.modifier?"?":""):"(?:"+A+"("+w.pattern+")"+R+")"+w.modifier:"("+w.pattern+")"+w.modifier):x+="(?:"+A+R+")"+w.modifier}}if(p)a||(x+=l+"?"),x+=t.endsWith?"(?="+d+")":"$";else{var C=n[n.length-1],T="string"==typeof C?l.indexOf(C[C.length-1])>-1:void 0===C;a||(x+="(?:"+l+"(?="+d+"))?"),T||(x+="(?="+l+"|"+d+")")}return new RegExp(x,r(t))}(function(r,n){void 0===n&&(n={});for(var i=function(e){for(var r=[],n=0;n<e.length;){var i=e[n];if("*"!==i&&"+"!==i&&"?"!==i)if("\\"!==i)if("{"!==i)if("}"!==i)if(":"!==i)if("("!==i)r.push({type:"CHAR",index:n,value:e[n++]});else{var t=1,f="";if("?"===e[o=n+1])throw new TypeError('Pattern cannot start with "?" at '+o);for(;o<e.length;)if("\\"!==e[o]){if(")"===e[o]){if(0==--t){o++;break}}else if("("===e[o]&&(t++,"?"!==e[o+1]))throw new TypeError("Capturing groups are not allowed at "+o);f+=e[o++]}else f+=e[o++]+e[o++];if(t)throw new TypeError("Unbalanced pattern at "+n);if(!f)throw new TypeError("Missing pattern at "+n);r.push({type:"PATTERN",index:n,value:f}),n=o}else{for(var a="",o=n+1;o<e.length;){var u=e.charCodeAt(o);if(!(u>=48&&u<=57||u>=65&&u<=90||u>=97&&u<=122||95===u))break;a+=e[o++]}if(!a)throw new TypeError("Missing parameter name at "+n);r.push({type:"NAME",index:n,value:a}),n=o}else r.push({type:"CLOSE",index:n,value:e[n++]});else r.push({type:"OPEN",index:n,value:e[n++]});else r.push({type:"ESCAPED_CHAR",index:n++,value:e[n++]});else r.push({type:"MODIFIER",index:n,value:e[n++]})}return r.push({type:"END",index:n,value:""}),r}(r),t=n.prefixes,f=void 0===t?"./":t,a="[^"+e(n.delimiter||"/#?")+"]+?",o=[],u=0,v=0,p="",E=function(e){if(v<i.length&&i[v].type===e)return i[v++].value},s=function(e){var r=E(e);if(void 0!==r)return r;var n=i[v];throw new TypeError("Unexpected "+n.type+" at "+n.index+", expected "+e)},d=function(){for(var e,r="";e=E("CHAR")||E("ESCAPED_CHAR");)r+=e;return r};v<i.length;){var l=E("CHAR"),x=E("NAME"),c=E("PATTERN");if(x||c)-1===f.indexOf(w=l||"")&&(p+=w,w=""),p&&(o.push(p),p=""),o.push({name:x||u++,prefix:w,suffix:"",pattern:c||a,modifier:E("MODIFIER")||""});else{var y=l||E("ESCAPED_CHAR");if(y)p+=y;else if(p&&(o.push(p),p=""),E("OPEN")){var w=d(),A=E("NAME")||"",R=E("PATTERN")||"",C=d();s("CLOSE"),o.push({name:A||(R?u++:""),pattern:A&&!R?a:R,prefix:w,suffix:C,modifier:E("MODIFIER")||""})}else s("END")}}return o}(n,t),i,t)}function i(e,t,f){return e instanceof RegExp?function(e,r){if(!r)return e;for(var n=/\((?:\?<(.*?)>)?(?!\?)/g,i=0,t=n.exec(e.source);t;)r.push({name:t[1]||i++,prefix:"",suffix:"",modifier:"",pattern:""}),t=n.exec(e.source);return e}(e,t):Array.isArray(e)?function(e,n,t){var f=e.map((function(e){return i(e,n,t).source}));return new RegExp("(?:"+f.join("|")+")",r(t))}(e,t,f):n(e,t,f)}export{i as p}