diff --git a/CHANGELOG.md b/CHANGELOG.md index 663e6970..f32709c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,18 @@ Breaking changes are marked with ⚠️. ## [Unreleased] +## [v1.3.4] - 2021-07-06 + +**Fixed** + +- Fix property mangling and implement ES5 compatibility ([#442](https://github.com/tighten/ziggy/pull/443)) + +## [v1.3.3] - 2021-07-02 + +**Fixed** + +- Revert ([d781b16](https://github.com/tighten/ziggy/commit/d781b164b8f455730fe8a8b0cbf91f0f8cb55a73)) + ## [v1.3.2] - 2021-07-01 **Fixed** @@ -159,7 +171,9 @@ Breaking changes are marked with ⚠️. For previous changes see the [Releases](https://github.com/tighten/ziggy/releases) page. -[Unreleased]: https://github.com/tighten/ziggy/compare/v1.3.2...HEAD +[Unreleased]: https://github.com/tighten/ziggy/compare/v1.3.4...HEAD +[v1.3.4]: https://github.com/tighten/ziggy/compare/v1.3.3...v1.3.4 +[v1.3.3]: https://github.com/tighten/ziggy/compare/v1.3.2...v1.3.3 [v1.3.2]: https://github.com/tighten/ziggy/compare/v1.3.1...v1.3.2 [v1.3.1]: https://github.com/tighten/ziggy/compare/v1.3.0...v1.3.1 [v1.3.0]: https://github.com/tighten/ziggy/compare/v1.2.0...v1.3.0 diff --git a/dist/index.es.js b/dist/index.es.js index 3e2fd816..0428e7d4 100644 --- a/dist/index.es.js +++ b/dist/index.es.js @@ -1 +1 @@ -function t(){return(t=Object.assign||function(t){for(var r=1;r1;){var r=t.pop(),n=r.obj[r.prop];if(e(n)){for(var i=[],o=0;o=48&&s<=57||s>=65&&s<=90||s>=97&&s<=122?o+=i.charAt(u):s<128?o+=n[s]:s<2048?o+=n[192|s>>6]+n[128|63&s]:s<55296||s>=57344?o+=n[224|s>>12]+n[128|s>>6&63]+n[128|63&s]:(s=65536+((1023&s)<<10|1023&i.charCodeAt(u+=1)),o+=n[240|s>>18]+n[128|s>>12&63]+n[128|s>>6&63]+n[128|63&s])}return o},isBuffer:function(t){return!(!t||"object"!=typeof t||!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t)))},isRegExp:function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},maybeMap:function(t,r){if(e(t)){for(var n=[],i=0;i-1?t.split(","):t},E=function(t,r,e,n){if(t){var i=e.allowDots?t.replace(/\.([^.[]+)/g,"[$1]"):t,o=/(\[[^[\]]*])/g,u=e.depth>0&&/(\[[^[\]]*])/.exec(i),s=u?i.slice(0,u.index):i,f=[];if(s){if(!e.plainObjects&&m.call(Object.prototype,s)&&!e.allowPrototypes)return;f.push(s)}for(var a=0;e.depth>0&&null!==(u=o.exec(i))&&a=0;--o){var u,s=t[o];if("[]"===s&&e.parseArrays)u=[].concat(i);else{u=e.plainObjects?Object.create(null):{};var f="["===s.charAt(0)&&"]"===s.charAt(s.length-1)?s.slice(1,-1):s,a=parseInt(f,10);e.parseArrays||""!==f?!isNaN(a)&&s!==f&&String(a)===f&&a>=0&&e.parseArrays&&a<=e.arrayLimit?(u=[])[a]=i:u[f]=i:u={0:i}}i=u}return i}(f,r,e,n)}};class S{constructor(t,r,e){var n;this.name=t,this.definition=r,this.bindings=null!=(n=r.bindings)?n:{},this.config=e}get template(){return`${this.config.absolute?this.definition.domain?`${this.config.url.match(/^\w+:\/\//)[0]}${this.definition.domain}${this.config.port?":"+this.config.port:""}`:this.config.url:""}/${this.definition.uri}`.replace(/\/+$/,"")}get parameterSegments(){var t,r;return null!=(t=null===(r=this.template.match(/{[^}?]+\??}/g))||void 0===r?void 0:r.map(t=>({name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)})))?t:[]}matchesUrl(t){if(!this.definition.methods.includes("GET"))return!1;const r=this.template.replace(/\/{[^}?]*\?}/g,"(/[^/?]+)?").replace(/{[^}]+}/g,"[^/?]+").replace(/^\w+:\/\//,"");return new RegExp(`^${r}$`).test(t.replace(/\/+$/,"").split("?").shift())}compile(t){return this.parameterSegments.length?this.template.replace(/{([^}?]+)\??}/g,(r,e)=>{var n;if([null,void 0].includes(t[e])&&this.parameterSegments.find(({name:t})=>t===e).required)throw new Error(`Ziggy error: '${e}' parameter is required for route '${this.name}'.`);return encodeURIComponent(null!=(n=t[e])?n:"")}).replace(/\/+$/,""):this.template}}class R extends String{constructor(r,e,n=!0,i){var o;if(super(),this.t=null!=(o=null!=i?i:Ziggy)?o:null===globalThis||void 0===globalThis?void 0:globalThis.Ziggy,this.t=t({},this.t,{absolute:n}),r){if(!this.t.routes[r])throw new Error(`Ziggy error: route '${r}' is not in the route list.`);this.i=new S(r,this.t.routes[r],this.t),this.u=this.s(e)}}toString(){const r=Object.keys(this.u).filter(t=>!this.i.parameterSegments.some(({name:r})=>r===t)).filter(t=>"_query"!==t).reduce((r,e)=>t({},r,{[e]:this.u[e]}),{});return this.i.compile(this.u)+function(t,r){var e,n=t,i=function(t){if(!t)return b;if(null!=t.encoder&&"function"!=typeof t.encoder)throw new TypeError("Encoder has to be a function.");var r=t.charset||b.charset;if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var e=a.default;if(void 0!==t.format){if(!c.call(a.formatters,t.format))throw new TypeError("Unknown format option provided.");e=t.format}var n=a.formatters[e],i=b.filter;return("function"==typeof t.filter||h(t.filter))&&(i=t.filter),{addQueryPrefix:"boolean"==typeof t.addQueryPrefix?t.addQueryPrefix:b.addQueryPrefix,allowDots:void 0===t.allowDots?b.allowDots:!!t.allowDots,charset:r,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:b.charsetSentinel,delimiter:void 0===t.delimiter?b.delimiter:t.delimiter,encode:"boolean"==typeof t.encode?t.encode:b.encode,encoder:"function"==typeof t.encoder?t.encoder:b.encoder,encodeValuesOnly:"boolean"==typeof t.encodeValuesOnly?t.encodeValuesOnly:b.encodeValuesOnly,filter:i,formatter:n,serializeDate:"function"==typeof t.serializeDate?t.serializeDate:b.serializeDate,skipNulls:"boolean"==typeof t.skipNulls?t.skipNulls:b.skipNulls,sort:"function"==typeof t.sort?t.sort:null,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:b.strictNullHandling}}(r);"function"==typeof i.filter?n=(0,i.filter)("",n):h(i.filter)&&(e=i.filter);var o=[];if("object"!=typeof n||null===n)return"";var u=l[r&&r.arrayFormat in l?r.arrayFormat:r&&"indices"in r?r.indices?"indices":"repeat":"indices"];e||(e=Object.keys(n)),i.sort&&e.sort(i.sort);for(var s=0;s0?v+d:""}(t({},r,this.u._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:(t,r)=>"boolean"==typeof t?Number(t):r(t)})}current(t,r){const e=this.t.absolute?this.l.host+this.l.pathname:this.l.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"),[n,i]=Object.entries(this.t.routes).find(([r,n])=>new S(t,n,this.t).matchesUrl(e))||[void 0,void 0];if(!t)return n;const o=new RegExp(`^${t.replace(".","\\.").replace("*",".*")}$`).test(n);if([null,void 0].includes(r)||!o)return o;const u=new S(n,i,this.t);r=this.s(r,u);const s=this.h(i);return!(!Object.values(r).every(t=>!t)||Object.values(s).length)||Object.entries(r).every(([t,r])=>s[t]==r)}get l(){var t,r,e,n,i,o;const{host:u="",pathname:s="",search:f=""}="undefined"!=typeof window?window.location:{};return{host:null!=(t=null===(r=this.t.location)||void 0===r?void 0:r.host)?t:u,pathname:null!=(e=null===(n=this.t.location)||void 0===n?void 0:n.pathname)?e:s,search:null!=(i=null===(o=this.t.location)||void 0===o?void 0:o.search)?i:f}}get params(){return this.h(this.t.routes[this.current()])}has(t){return Object.keys(this.t.routes).includes(t)}s(r={},e=this.i){r=["string","number"].includes(typeof r)?[r]:r;const n=e.parameterSegments.filter(({name:t})=>!this.t.defaults[t]);return Array.isArray(r)?r=r.reduce((r,e,i)=>t({},r,n[i]?{[n[i].name]:e}:{[e]:""}),{}):1!==n.length||r[n[0].name]||!r.hasOwnProperty(Object.values(e.bindings)[0])&&!r.hasOwnProperty("id")||(r={[n[0].name]:r}),t({},this.p(e),this.v(r,e.bindings))}p(r){return r.parameterSegments.filter(({name:t})=>this.t.defaults[t]).reduce((r,{name:e},n)=>t({},r,{[e]:this.t.defaults[e]}),{})}v(r,e={}){return Object.entries(r).reduce((r,[n,i])=>{if(!i||"object"!=typeof i||Array.isArray(i)||"_query"===n)return t({},r,{[n]:i});if(!i.hasOwnProperty(e[n])){if(!i.hasOwnProperty("id"))throw new Error(`Ziggy error: object passed as '${n}' parameter is missing route model binding key '${e[n]}'.`);e[n]="id"}return t({},r,{[n]:i[e[n]]})},{})}h(r){var e;let n=this.l.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"");const i=(r,e="",n)=>{const[i,o]=[r,e].map(t=>t.split(n));return o.reduce((r,e,n)=>/^{[^}?]+\??}$/.test(e)&&i[n]?t({},r,{[e.replace(/^{|\??}$/g,"")]:i[n]}):r,{})};return t({},i(this.l.host,r.domain,"."),i(n,r.uri,"/"),function(t,r){var e=O;if(""===t||null==t)return e.plainObjects?Object.create(null):{};for(var n="string"==typeof t?function(t,r){var e,n={},i=(r.ignoreQueryPrefix?t.replace(/^\?/,""):t).split(r.delimiter,Infinity===r.parameterLimit?void 0:r.parameterLimit),u=-1,s=r.charset;if(r.charsetSentinel)for(e=0;e-1&&(a=j(a)?[a]:a),n[f]=m.call(n,f)?o.combine(n[f],a):a}return n}(t,e):t,i=e.plainObjects?Object.create(null):{},u=Object.keys(n),s=0;s1;){var r=t.pop(),n=r.obj[r.prop];if(e(n)){for(var i=[],o=0;o=48&&s<=57||s>=65&&s<=90||s>=97&&s<=122?o+=i.charAt(u):s<128?o+=n[s]:s<2048?o+=n[192|s>>6]+n[128|63&s]:s<55296||s>=57344?o+=n[224|s>>12]+n[128|s>>6&63]+n[128|63&s]:(s=65536+((1023&s)<<10|1023&i.charCodeAt(u+=1)),o+=n[240|s>>18]+n[128|s>>12&63]+n[128|s>>6&63]+n[128|63&s])}return o},isBuffer:function(t){return!(!t||"object"!=typeof t||!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t)))},isRegExp:function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},maybeMap:function(t,r){if(e(t)){for(var n=[],i=0;i-1?t.split(","):t},E=function(t,r,e,n){if(t){var i=e.allowDots?t.replace(/\.([^.[]+)/g,"[$1]"):t,o=/(\[[^[\]]*])/g,u=e.depth>0&&/(\[[^[\]]*])/.exec(i),s=u?i.slice(0,u.index):i,f=[];if(s){if(!e.plainObjects&&m.call(Object.prototype,s)&&!e.allowPrototypes)return;f.push(s)}for(var a=0;e.depth>0&&null!==(u=o.exec(i))&&a=0;--o){var u,s=t[o];if("[]"===s&&e.parseArrays)u=[].concat(i);else{u=e.plainObjects?Object.create(null):{};var f="["===s.charAt(0)&&"]"===s.charAt(s.length-1)?s.slice(1,-1):s,a=parseInt(f,10);e.parseArrays||""!==f?!isNaN(a)&&s!==f&&String(a)===f&&a>=0&&e.parseArrays&&a<=e.arrayLimit?(u=[])[a]=i:u[f]=i:u={0:i}}i=u}return i}(f,r,e,n)}};class S{constructor(t,r,e){var n;this.name=t,this.definition=r,this.bindings=null!=(n=r.bindings)?n:{},this.config=e}get template(){return`${this.config.absolute?this.definition.domain?`${this.config.url.match(/^\w+:\/\//)[0]}${this.definition.domain}${this.config.port?":"+this.config.port:""}`:this.config.url:""}/${this.definition.uri}`.replace(/\/+$/,"")}get parameterSegments(){var t,r;return null!=(t=null===(r=this.template.match(/{[^}?]+\??}/g))||void 0===r?void 0:r.map(t=>({name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)})))?t:[]}matchesUrl(t){if(!this.definition.methods.includes("GET"))return!1;const r=this.template.replace(/\/{[^}?]*\?}/g,"(/[^/?]+)?").replace(/{[^}]+}/g,"[^/?]+").replace(/^\w+:\/\//,"");return new RegExp(`^${r}$`).test(t.replace(/\/+$/,"").split("?").shift())}compile(t){return this.parameterSegments.length?this.template.replace(/{([^}?]+)\??}/g,(r,e)=>{var n;if([null,void 0].includes(t[e])&&this.parameterSegments.find(({name:t})=>t===e).required)throw new Error(`Ziggy error: '${e}' parameter is required for route '${this.name}'.`);return encodeURIComponent(null!=(n=t[e])?n:"")}).replace(/\/+$/,""):this.template}}class R extends String{constructor(r,e,n=!0,i){var o;if(super(),this.t=null!=(o=null!=i?i:Ziggy)?o:null===globalThis||void 0===globalThis?void 0:globalThis.Ziggy,this.t=t({},this.t,{absolute:n}),r){if(!this.t.routes[r])throw new Error(`Ziggy error: route '${r}' is not in the route list.`);this.i=new S(r,this.t.routes[r],this.t),this.u=this.s(e)}}toString(){const r=Object.keys(this.u).filter(t=>!this.i.parameterSegments.some(({name:r})=>r===t)).filter(t=>"_query"!==t).reduce((r,e)=>t({},r,{[e]:this.u[e]}),{});return this.i.compile(this.u)+function(t,r){var e,n=t,i=function(t){if(!t)return b;if(null!=t.encoder&&"function"!=typeof t.encoder)throw new TypeError("Encoder has to be a function.");var r=t.charset||b.charset;if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var e=a.default;if(void 0!==t.format){if(!c.call(a.formatters,t.format))throw new TypeError("Unknown format option provided.");e=t.format}var n=a.formatters[e],i=b.filter;return("function"==typeof t.filter||h(t.filter))&&(i=t.filter),{addQueryPrefix:"boolean"==typeof t.addQueryPrefix?t.addQueryPrefix:b.addQueryPrefix,allowDots:void 0===t.allowDots?b.allowDots:!!t.allowDots,charset:r,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:b.charsetSentinel,delimiter:void 0===t.delimiter?b.delimiter:t.delimiter,encode:"boolean"==typeof t.encode?t.encode:b.encode,encoder:"function"==typeof t.encoder?t.encoder:b.encoder,encodeValuesOnly:"boolean"==typeof t.encodeValuesOnly?t.encodeValuesOnly:b.encodeValuesOnly,filter:i,formatter:n,serializeDate:"function"==typeof t.serializeDate?t.serializeDate:b.serializeDate,skipNulls:"boolean"==typeof t.skipNulls?t.skipNulls:b.skipNulls,sort:"function"==typeof t.sort?t.sort:null,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:b.strictNullHandling}}(r);"function"==typeof i.filter?n=(0,i.filter)("",n):h(i.filter)&&(e=i.filter);var o=[];if("object"!=typeof n||null===n)return"";var u=l[r&&r.arrayFormat in l?r.arrayFormat:r&&"indices"in r?r.indices?"indices":"repeat":"indices"];e||(e=Object.keys(n)),i.sort&&e.sort(i.sort);for(var s=0;s0?v+d:""}(t({},r,this.u._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:(t,r)=>"boolean"==typeof t?Number(t):r(t)})}current(t,r){const e=this.t.absolute?this.l().host+this.l().pathname:this.l().pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"),[n,i]=Object.entries(this.t.routes).find(([r,n])=>new S(t,n,this.t).matchesUrl(e))||[void 0,void 0];if(!t)return n;const o=new RegExp(`^${t.replace(".","\\.").replace("*",".*")}$`).test(n);if([null,void 0].includes(r)||!o)return o;const u=new S(n,i,this.t);r=this.s(r,u);const s=this.h(i);return!(!Object.values(r).every(t=>!t)||Object.values(s).length)||Object.entries(r).every(([t,r])=>s[t]==r)}l(){var t,r,e,n,i,o;const{host:u="",pathname:s="",search:f=""}="undefined"!=typeof window?window.location:{};return{host:null!=(t=null===(r=this.t.location)||void 0===r?void 0:r.host)?t:u,pathname:null!=(e=null===(n=this.t.location)||void 0===n?void 0:n.pathname)?e:s,search:null!=(i=null===(o=this.t.location)||void 0===o?void 0:o.search)?i:f}}get params(){return this.h(this.t.routes[this.current()])}has(t){return Object.keys(this.t.routes).includes(t)}s(r={},e=this.i){r=["string","number"].includes(typeof r)?[r]:r;const n=e.parameterSegments.filter(({name:t})=>!this.t.defaults[t]);return Array.isArray(r)?r=r.reduce((r,e,i)=>t({},r,n[i]?{[n[i].name]:e}:{[e]:""}),{}):1!==n.length||r[n[0].name]||!r.hasOwnProperty(Object.values(e.bindings)[0])&&!r.hasOwnProperty("id")||(r={[n[0].name]:r}),t({},this.p(e),this.v(r,e.bindings))}p(r){return r.parameterSegments.filter(({name:t})=>this.t.defaults[t]).reduce((r,{name:e},n)=>t({},r,{[e]:this.t.defaults[e]}),{})}v(r,e={}){return Object.entries(r).reduce((r,[n,i])=>{if(!i||"object"!=typeof i||Array.isArray(i)||"_query"===n)return t({},r,{[n]:i});if(!i.hasOwnProperty(e[n])){if(!i.hasOwnProperty("id"))throw new Error(`Ziggy error: object passed as '${n}' parameter is missing route model binding key '${e[n]}'.`);e[n]="id"}return t({},r,{[n]:i[e[n]]})},{})}h(r){var e;let n=this.l().pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"");const i=(r,e="",n)=>{const[i,o]=[r,e].map(t=>t.split(n));return o.reduce((r,e,n)=>/^{[^}?]+\??}$/.test(e)&&i[n]?t({},r,{[e.replace(/^{|\??}$/g,"")]:i[n]}):r,{})};return t({},i(this.l().host,r.domain,"."),i(n,r.uri,"/"),function(t,r){var e=O;if(""===t||null==t)return e.plainObjects?Object.create(null):{};for(var n="string"==typeof t?function(t,r){var e,n={},i=(r.ignoreQueryPrefix?t.replace(/^\?/,""):t).split(r.delimiter,Infinity===r.parameterLimit?void 0:r.parameterLimit),u=-1,s=r.charset;if(r.charsetSentinel)for(e=0;e-1&&(a=j(a)?[a]:a),n[f]=m.call(n,f)?o.combine(n[f],a):a}return n}(t,e):t,i=e.plainObjects?Object.create(null):{},u=Object.keys(n),s=0;s1;){var r=t.pop(),n=r.obj[r.prop];if(e(n)){for(var i=[],o=0;o=48&&f<=57||f>=65&&f<=90||f>=97&&f<=122?o+=i.charAt(u):f<128?o+=r[f]:f<2048?o+=r[192|f>>6]+r[128|63&f]:f<55296||f>=57344?o+=r[224|f>>12]+r[128|f>>6&63]+r[128|63&f]:(f=65536+((1023&f)<<10|1023&i.charCodeAt(u+=1)),o+=r[240|f>>18]+r[128|f>>12&63]+r[128|f>>6&63]+r[128|63&f])}return o},isBuffer:function(t){return!(!t||"object"!=typeof t||!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t)))},isRegExp:function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},maybeMap:function(t,r){if(e(t)){for(var n=[],i=0;i-1?t.split(","):t},$=function(t,e,r,n){if(t){var i=r.allowDots?t.replace(/\.([^.[]+)/g,"[$1]"):t,o=/(\[[^[\]]*])/g,u=r.depth>0&&/(\[[^[\]]*])/.exec(i),f=u?i.slice(0,u.index):i,s=[];if(f){if(!r.plainObjects&&m.call(Object.prototype,f)&&!r.allowPrototypes)return;s.push(f)}for(var a=0;r.depth>0&&null!==(u=o.exec(i))&&a=0;--o){var u,f=t[o];if("[]"===f&&r.parseArrays)u=[].concat(i);else{u=r.plainObjects?Object.create(null):{};var s="["===f.charAt(0)&&"]"===f.charAt(f.length-1)?f.slice(1,-1):f,a=parseInt(s,10);r.parseArrays||""!==s?!isNaN(a)&&f!==s&&String(a)===s&&a>=0&&r.parseArrays&&a<=r.arrayLimit?(u=[])[a]=i:u[s]=i:u={0:i}}i=u}return i}(s,e,r,n)}},E=function(t,e){var r=function(t){if(!t)return j;if(null!=t.decoder&&"function"!=typeof t.decoder)throw new TypeError("Decoder has to be a function.");if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");return{allowDots:void 0===t.allowDots?j.allowDots:!!t.allowDots,allowPrototypes:"boolean"==typeof t.allowPrototypes?t.allowPrototypes:j.allowPrototypes,arrayLimit:"number"==typeof t.arrayLimit?t.arrayLimit:j.arrayLimit,charset:void 0===t.charset?j.charset:t.charset,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:j.charsetSentinel,comma:"boolean"==typeof t.comma?t.comma:j.comma,decoder:"function"==typeof t.decoder?t.decoder:j.decoder,delimiter:"string"==typeof t.delimiter||i.isRegExp(t.delimiter)?t.delimiter:j.delimiter,depth:"number"==typeof t.depth||!1===t.depth?+t.depth:j.depth,ignoreQueryPrefix:!0===t.ignoreQueryPrefix,interpretNumericEntities:"boolean"==typeof t.interpretNumericEntities?t.interpretNumericEntities:j.interpretNumericEntities,parameterLimit:"number"==typeof t.parameterLimit?t.parameterLimit:j.parameterLimit,parseArrays:!1!==t.parseArrays,plainObjects:"boolean"==typeof t.plainObjects?t.plainObjects:j.plainObjects,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:j.strictNullHandling}}(e);if(""===t||null==t)return r.plainObjects?Object.create(null):{};for(var n="string"==typeof t?function(t,e){var r,n={},o=(e.ignoreQueryPrefix?t.replace(/^\?/,""):t).split(e.delimiter,Infinity===e.parameterLimit?void 0:e.parameterLimit),u=-1,f=e.charset;if(e.charsetSentinel)for(r=0;r-1&&(a=g(a)?[a]:a),n[s]=m.call(n,s)?i.combine(n[s],a):a}return n}(t,r):t,o=r.plainObjects?Object.create(null):{},u=Object.keys(n),f=0;f({name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)})))??[]}matchesUrl(t){if(!this.definition.methods.includes("GET"))return!1;const e=this.template.replace(/\/{[^}?]*\?}/g,"(/[^/?]+)?").replace(/{[^}]+}/g,"[^/?]+").replace(/^\w+:\/\//,"");return new RegExp(`^${e}$`).test(t.replace(/\/+$/,"").split("?").shift())}compile(t){return this.parameterSegments.length?this.template.replace(/{([^}?]+)\??}/g,(e,r)=>{if([null,void 0].includes(t[r])&&this.parameterSegments.find(({name:t})=>t===r).required)throw new Error(`Ziggy error: '${r}' parameter is required for route '${this.name}'.`);return encodeURIComponent(t[r]??"")}).replace(/\/+$/,""):this.template}}class N extends String{constructor(t,e,r=!0,n){if(super(),this.t=n??Ziggy??(null===globalThis||void 0===globalThis?void 0:globalThis.Ziggy),this.t={...this.t,absolute:r},t){if(!this.t.routes[t])throw new Error(`Ziggy error: route '${t}' is not in the route list.`);this.i=new S(t,this.t.routes[t],this.t),this.u=this.s(e)}}toString(){const t=Object.keys(this.u).filter(t=>!this.i.parameterSegments.some(({name:e})=>e===t)).filter(t=>"_query"!==t).reduce((t,e)=>({...t,[e]:this.u[e]}),{});return this.i.compile(this.u)+function(t,e){var r,n=t,i=function(t){if(!t)return b;if(null!=t.encoder&&"function"!=typeof t.encoder)throw new TypeError("Encoder has to be a function.");var e=t.charset||b.charset;if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var r=s.default;if(void 0!==t.format){if(!a.call(s.formatters,t.format))throw new TypeError("Unknown format option provided.");r=t.format}var n=s.formatters[r],i=b.filter;return("function"==typeof t.filter||l(t.filter))&&(i=t.filter),{addQueryPrefix:"boolean"==typeof t.addQueryPrefix?t.addQueryPrefix:b.addQueryPrefix,allowDots:void 0===t.allowDots?b.allowDots:!!t.allowDots,charset:e,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:b.charsetSentinel,delimiter:void 0===t.delimiter?b.delimiter:t.delimiter,encode:"boolean"==typeof t.encode?t.encode:b.encode,encoder:"function"==typeof t.encoder?t.encoder:b.encoder,encodeValuesOnly:"boolean"==typeof t.encodeValuesOnly?t.encodeValuesOnly:b.encodeValuesOnly,filter:i,formatter:n,serializeDate:"function"==typeof t.serializeDate?t.serializeDate:b.serializeDate,skipNulls:"boolean"==typeof t.skipNulls?t.skipNulls:b.skipNulls,sort:"function"==typeof t.sort?t.sort:null,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:b.strictNullHandling}}(e);"function"==typeof i.filter?n=(0,i.filter)("",n):l(i.filter)&&(r=i.filter);var o=[];if("object"!=typeof n||null===n)return"";var u=c[e&&e.arrayFormat in c?e.arrayFormat:e&&"indices"in e?e.indices?"indices":"repeat":"indices"];r||(r=Object.keys(n)),i.sort&&r.sort(i.sort);for(var f=0;f0?y+d:""}({...t,...this.u._query},{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:(t,e)=>"boolean"==typeof t?Number(t):e(t)})}current(t,e){const r=this.t.absolute?this.l.host+this.l.pathname:this.l.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"),[n,i]=Object.entries(this.t.routes).find(([e,n])=>new S(t,n,this.t).matchesUrl(r))||[void 0,void 0];if(!t)return n;const o=new RegExp(`^${t.replace(".","\\.").replace("*",".*")}$`).test(n);if([null,void 0].includes(e)||!o)return o;const u=new S(n,i,this.t);e=this.s(e,u);const f=this.h(i);return!(!Object.values(e).every(t=>!t)||Object.values(f).length)||Object.entries(e).every(([t,e])=>f[t]==e)}get l(){var t,e,r;const{host:n="",pathname:i="",search:o=""}="undefined"!=typeof window?window.location:{};return{host:(null===(t=this.t.location)||void 0===t?void 0:t.host)??n,pathname:(null===(e=this.t.location)||void 0===e?void 0:e.pathname)??i,search:(null===(r=this.t.location)||void 0===r?void 0:r.search)??o}}get params(){return this.h(this.t.routes[this.current()])}has(t){return Object.keys(this.t.routes).includes(t)}s(t={},e=this.i){t=["string","number"].includes(typeof t)?[t]:t;const r=e.parameterSegments.filter(({name:t})=>!this.t.defaults[t]);return Array.isArray(t)?t=t.reduce((t,e,n)=>r[n]?{...t,[r[n].name]:e}:{...t,[e]:""},{}):1!==r.length||t[r[0].name]||!t.hasOwnProperty(Object.values(e.bindings)[0])&&!t.hasOwnProperty("id")||(t={[r[0].name]:t}),{...this.p(e),...this.v(t,e.bindings)}}p(t){return t.parameterSegments.filter(({name:t})=>this.t.defaults[t]).reduce((t,{name:e},r)=>({...t,[e]:this.t.defaults[e]}),{})}v(t,e={}){return Object.entries(t).reduce((t,[r,n])=>{if(!n||"object"!=typeof n||Array.isArray(n)||"_query"===r)return{...t,[r]:n};if(!n.hasOwnProperty(e[r])){if(!n.hasOwnProperty("id"))throw new Error(`Ziggy error: object passed as '${r}' parameter is missing route model binding key '${e[r]}'.`);e[r]="id"}return{...t,[r]:n[e[r]]}},{})}h(t){var e;let r=this.l.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"");const n=(t,e="",r)=>{const[n,i]=[t,e].map(t=>t.split(r));return i.reduce((t,e,r)=>/^{[^}?]+\??}$/.test(e)&&n[r]?{...t,[e.replace(/^{|\??}$/g,"")]:n[r]}:t,{})};return{...n(this.l.host,t.domain,"."),...n(r,t.uri,"/"),...E(null===(e=this.l.search)||void 0===e?void 0:e.replace(/^\?/,""))}}valueOf(){return this.toString()}check(t){return this.has(t)}}return function(t,e,r,n){const i=new N(t,e,r,n);return t?i.toString():i}}); +!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(t=t||self).route=n()}(this,function(){function t(t,n){for(var r=0;r1;){var n=t.pop(),r=n.obj[n.prop];if(a(r)){for(var e=[],i=0;i=48&&u<=57||u>=65&&u<=90||u>=97&&u<=122?i+=e.charAt(o):u<128?i+=l[u]:u<2048?i+=l[192|u>>6]+l[128|63&u]:u<55296||u>=57344?i+=l[224|u>>12]+l[128|u>>6&63]+l[128|63&u]:(u=65536+((1023&u)<<10|1023&e.charCodeAt(o+=1)),i+=l[240|u>>18]+l[128|u>>12&63]+l[128|u>>6&63]+l[128|63&u])}return i},isBuffer:function(t){return!(!t||"object"!=typeof t||!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t)))},isRegExp:function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},maybeMap:function(t,n){if(a(t)){for(var r=[],e=0;e-1?t.split(","):t},T=function(t,n,r,e){if(t){var i=r.allowDots?t.replace(/\.([^.[]+)/g,"[$1]"):t,o=/(\[[^[\]]*])/g,u=r.depth>0&&/(\[[^[\]]*])/.exec(i),f=u?i.slice(0,u.index):i,c=[];if(f){if(!r.plainObjects&&S.call(Object.prototype,f)&&!r.allowPrototypes)return;c.push(f)}for(var a=0;r.depth>0&&null!==(u=o.exec(i))&&a=0;--o){var u,f=t[o];if("[]"===f&&r.parseArrays)u=[].concat(i);else{u=r.plainObjects?Object.create(null):{};var c="["===f.charAt(0)&&"]"===f.charAt(f.length-1)?f.slice(1,-1):f,a=parseInt(c,10);r.parseArrays||""!==c?!isNaN(a)&&f!==c&&String(a)===c&&a>=0&&r.parseArrays&&a<=r.arrayLimit?(u=[])[a]=i:u[c]=i:u={0:i}}i=u}return i}(c,n,r,e)}},F=function(){function t(t,n,r){var e;this.name=t,this.definition=n,this.bindings=null!=(e=n.bindings)?e:{},this.config=r}var r=t.prototype;return r.matchesUrl=function(t){if(!this.definition.methods.includes("GET"))return!1;var n=this.template.replace(/\/{[^}?]*\?}/g,"(/[^/?]+)?").replace(/{[^}]+}/g,"[^/?]+").replace(/^\w+:\/\//,"");return new RegExp("^"+n+"$").test(t.replace(/\/+$/,"").split("?").shift())},r.compile=function(t){var n=this;return this.parameterSegments.length?this.template.replace(/{([^}?]+)\??}/g,function(r,e){var i;if([null,void 0].includes(t[e])&&n.parameterSegments.find(function(t){return t.name===e}).required)throw new Error("Ziggy error: '"+e+"' parameter is required for route '"+n.name+"'.");return encodeURIComponent(null!=(i=t[e])?i:"")}).replace(/\/+$/,""):this.template},n(t,[{key:"template",get:function(){return((this.config.absolute?this.definition.domain?""+this.config.url.match(/^\w+:\/\//)[0]+this.definition.domain+(this.config.port?":"+this.config.port:""):this.config.url:"")+"/"+this.definition.uri).replace(/\/+$/,"")}},{key:"parameterSegments",get:function(){var t,n;return null!=(t=null===(n=this.template.match(/{[^}?]+\??}/g))||void 0===n?void 0:n.map(function(t){return{name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)}}))?t:[]}}]),t}(),$=function(t){var e,i;function o(n,e,i,o){var u,f;if(void 0===i&&(i=!0),(f=t.call(this)||this).t=null!=(u=null!=o?o:Ziggy)?u:null===globalThis||void 0===globalThis?void 0:globalThis.Ziggy,f.t=r({},f.t,{absolute:i}),n){if(!f.t.routes[n])throw new Error("Ziggy error: route '"+n+"' is not in the route list.");f.i=new F(n,f.t.routes[n],f.t),f.u=f.l(e)}return f}i=t,(e=o).prototype=Object.create(i.prototype),e.prototype.constructor=e,e.__proto__=i;var u=o.prototype;return u.toString=function(){var t=this,n=Object.keys(this.u).filter(function(n){return!t.i.parameterSegments.some(function(t){return t.name===n})}).filter(function(t){return"_query"!==t}).reduce(function(n,e){var i;return r({},n,((i={})[e]=t.u[e],i))},{});return this.i.compile(this.u)+function(t,n){var r,e=t,i=function(t){if(!t)return E;if(null!=t.encoder&&"function"!=typeof t.encoder)throw new TypeError("Encoder has to be a function.");var n=t.charset||E.charset;if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var r=h.default;if(void 0!==t.format){if(!b.call(h.formatters,t.format))throw new TypeError("Unknown format option provided.");r=t.format}var e=h.formatters[r],i=E.filter;return("function"==typeof t.filter||j(t.filter))&&(i=t.filter),{addQueryPrefix:"boolean"==typeof t.addQueryPrefix?t.addQueryPrefix:E.addQueryPrefix,allowDots:void 0===t.allowDots?E.allowDots:!!t.allowDots,charset:n,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:E.charsetSentinel,delimiter:void 0===t.delimiter?E.delimiter:t.delimiter,encode:"boolean"==typeof t.encode?t.encode:E.encode,encoder:"function"==typeof t.encoder?t.encoder:E.encoder,encodeValuesOnly:"boolean"==typeof t.encodeValuesOnly?t.encodeValuesOnly:E.encodeValuesOnly,filter:i,formatter:e,serializeDate:"function"==typeof t.serializeDate?t.serializeDate:E.serializeDate,skipNulls:"boolean"==typeof t.skipNulls?t.skipNulls:E.skipNulls,sort:"function"==typeof t.sort?t.sort:null,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:E.strictNullHandling}}(n);"function"==typeof i.filter?e=(0,i.filter)("",e):j(i.filter)&&(r=i.filter);var o=[];if("object"!=typeof e||null===e)return"";var u=g[n&&n.arrayFormat in g?n.arrayFormat:n&&"indices"in n?n.indices?"indices":"repeat":"indices"];r||(r=Object.keys(e)),i.sort&&r.sort(i.sort);for(var f=0;f0?l+a:""}(r({},n,this.u._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:function(t,n){return"boolean"==typeof t?Number(t):n(t)}})},u.current=function(t,n){var r=this,e=this.t.absolute?this.s().host+this.s().pathname:this.s().pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"),i=Object.entries(this.t.routes).find(function(n){return new F(t,n[1],r.t).matchesUrl(e)})||[void 0,void 0],o=i[0],u=i[1];if(!t)return o;var f=new RegExp("^"+t.replace(".","\\.").replace("*",".*")+"$").test(o);if([null,void 0].includes(n)||!f)return f;var c=new F(o,u,this.t);n=this.l(n,c);var a=this.v(u);return!(!Object.values(n).every(function(t){return!t})||Object.values(a).length)||Object.entries(n).every(function(t){return a[t[0]]==t[1]})},u.s=function(){var t,n,r,e,i,o,u="undefined"!=typeof window?window.location:{},f=u.host,c=u.pathname,a=u.search;return{host:null!=(t=null===(n=this.t.location)||void 0===n?void 0:n.host)?t:void 0===f?"":f,pathname:null!=(r=null===(e=this.t.location)||void 0===e?void 0:e.pathname)?r:void 0===c?"":c,search:null!=(i=null===(o=this.t.location)||void 0===o?void 0:o.search)?i:void 0===a?"":a}},u.has=function(t){return Object.keys(this.t.routes).includes(t)},u.l=function(t,n){var e=this;void 0===t&&(t={}),void 0===n&&(n=this.i),t=["string","number"].includes(typeof t)?[t]:t;var i=n.parameterSegments.filter(function(t){return!e.t.defaults[t.name]});if(Array.isArray(t))t=t.reduce(function(t,n,e){var o,u;return r({},t,i[e]?((o={})[i[e].name]=n,o):((u={})[n]="",u))},{});else if(1===i.length&&!t[i[0].name]&&(t.hasOwnProperty(Object.values(n.bindings)[0])||t.hasOwnProperty("id"))){var o;(o={})[i[0].name]=t,t=o}return r({},this.p(n),this.h(t,n.bindings))},u.p=function(t){var n=this;return t.parameterSegments.filter(function(t){return n.t.defaults[t.name]}).reduce(function(t,e,i){var o,u=e.name;return r({},t,((o={})[u]=n.t.defaults[u],o))},{})},u.h=function(t,n){return void 0===n&&(n={}),Object.entries(t).reduce(function(t,e){var i,o,u=e[0],f=e[1];if(!f||"object"!=typeof f||Array.isArray(f)||"_query"===u)return r({},t,((o={})[u]=f,o));if(!f.hasOwnProperty(n[u])){if(!f.hasOwnProperty("id"))throw new Error("Ziggy error: object passed as '"+u+"' parameter is missing route model binding key '"+n[u]+"'.");n[u]="id"}return r({},t,((i={})[u]=f[n[u]],i))},{})},u.v=function(t){var n,e=this.s().pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,""),i=function(t,n,e){void 0===n&&(n="");var i=[t,n].map(function(t){return t.split(e)}),o=i[0];return i[1].reduce(function(t,n,e){var i;return/^{[^}?]+\??}$/.test(n)&&o[e]?r({},t,((i={})[n.replace(/^{|\??}$/g,"")]=o[e],i)):t},{})};return r({},i(this.s().host,t.domain,"."),i(e,t.uri,"/"),function(t,n){var r=C;if(""===t||null==t)return r.plainObjects?Object.create(null):{};for(var e="string"==typeof t?function(t,n){var r,e={},i=(n.ignoreQueryPrefix?t.replace(/^\?/,""):t).split(n.delimiter,Infinity===n.parameterLimit?void 0:n.parameterLimit),o=-1,u=n.charset;if(n.charsetSentinel)for(r=0;r-1&&(c=x(c)?[c]:c),e[f]=S.call(e,f)?v.combine(e[f],c):c}return e}(t,r):t,i=r.plainObjects?Object.create(null):{},o=Object.keys(e),u=0;u1;){var r=t.pop(),n=r.obj[r.prop];if(e(n)){for(var i=[],o=0;o=48&&f<=57||f>=65&&f<=90||f>=97&&f<=122?o+=i.charAt(u):f<128?o+=r[f]:f<2048?o+=r[192|f>>6]+r[128|63&f]:f<55296||f>=57344?o+=r[224|f>>12]+r[128|f>>6&63]+r[128|63&f]:(f=65536+((1023&f)<<10|1023&i.charCodeAt(u+=1)),o+=r[240|f>>18]+r[128|f>>12&63]+r[128|f>>6&63]+r[128|63&f])}return o},isBuffer:function(t){return!(!t||"object"!=typeof t||!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t)))},isRegExp:function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},maybeMap:function(t,r){if(e(t)){for(var n=[],i=0;i-1?t.split(","):t},$=function(t,e,r,n){if(t){var i=r.allowDots?t.replace(/\.([^.[]+)/g,"[$1]"):t,o=/(\[[^[\]]*])/g,u=r.depth>0&&/(\[[^[\]]*])/.exec(i),f=u?i.slice(0,u.index):i,s=[];if(f){if(!r.plainObjects&&m.call(Object.prototype,f)&&!r.allowPrototypes)return;s.push(f)}for(var a=0;r.depth>0&&null!==(u=o.exec(i))&&a=0;--o){var u,f=t[o];if("[]"===f&&r.parseArrays)u=[].concat(i);else{u=r.plainObjects?Object.create(null):{};var s="["===f.charAt(0)&&"]"===f.charAt(f.length-1)?f.slice(1,-1):f,a=parseInt(s,10);r.parseArrays||""!==s?!isNaN(a)&&f!==s&&String(a)===s&&a>=0&&r.parseArrays&&a<=r.arrayLimit?(u=[])[a]=i:u[s]=i:u={0:i}}i=u}return i}(s,e,r,n)}},E=function(t,e){var r=function(t){if(!t)return j;if(null!=t.decoder&&"function"!=typeof t.decoder)throw new TypeError("Decoder has to be a function.");if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");return{allowDots:void 0===t.allowDots?j.allowDots:!!t.allowDots,allowPrototypes:"boolean"==typeof t.allowPrototypes?t.allowPrototypes:j.allowPrototypes,arrayLimit:"number"==typeof t.arrayLimit?t.arrayLimit:j.arrayLimit,charset:void 0===t.charset?j.charset:t.charset,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:j.charsetSentinel,comma:"boolean"==typeof t.comma?t.comma:j.comma,decoder:"function"==typeof t.decoder?t.decoder:j.decoder,delimiter:"string"==typeof t.delimiter||i.isRegExp(t.delimiter)?t.delimiter:j.delimiter,depth:"number"==typeof t.depth||!1===t.depth?+t.depth:j.depth,ignoreQueryPrefix:!0===t.ignoreQueryPrefix,interpretNumericEntities:"boolean"==typeof t.interpretNumericEntities?t.interpretNumericEntities:j.interpretNumericEntities,parameterLimit:"number"==typeof t.parameterLimit?t.parameterLimit:j.parameterLimit,parseArrays:!1!==t.parseArrays,plainObjects:"boolean"==typeof t.plainObjects?t.plainObjects:j.plainObjects,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:j.strictNullHandling}}(e);if(""===t||null==t)return r.plainObjects?Object.create(null):{};for(var n="string"==typeof t?function(t,e){var r,n={},o=(e.ignoreQueryPrefix?t.replace(/^\?/,""):t).split(e.delimiter,Infinity===e.parameterLimit?void 0:e.parameterLimit),u=-1,f=e.charset;if(e.charsetSentinel)for(r=0;r-1&&(a=g(a)?[a]:a),n[s]=m.call(n,s)?i.combine(n[s],a):a}return n}(t,r):t,o=r.plainObjects?Object.create(null):{},u=Object.keys(n),f=0;f({name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)})))??[]}matchesUrl(t){if(!this.definition.methods.includes("GET"))return!1;const e=this.template.replace(/\/{[^}?]*\?}/g,"(/[^/?]+)?").replace(/{[^}]+}/g,"[^/?]+").replace(/^\w+:\/\//,"");return new RegExp(`^${e}$`).test(t.replace(/\/+$/,"").split("?").shift())}compile(t){return this.parameterSegments.length?this.template.replace(/{([^}?]+)\??}/g,(e,r)=>{if([null,void 0].includes(t[r])&&this.parameterSegments.find(({name:t})=>t===r).required)throw new Error(`Ziggy error: '${r}' parameter is required for route '${this.name}'.`);return encodeURIComponent(t[r]??"")}).replace(/\/+$/,""):this.template}}class N extends String{constructor(t,e,r=!0,n){if(super(),this.t=n??Ziggy??(null===globalThis||void 0===globalThis?void 0:globalThis.Ziggy),this.t={...this.t,absolute:r},t){if(!this.t.routes[t])throw new Error(`Ziggy error: route '${t}' is not in the route list.`);this.i=new S(t,this.t.routes[t],this.t),this.u=this.s(e)}}toString(){const t=Object.keys(this.u).filter(t=>!this.i.parameterSegments.some(({name:e})=>e===t)).filter(t=>"_query"!==t).reduce((t,e)=>({...t,[e]:this.u[e]}),{});return this.i.compile(this.u)+function(t,e){var r,n=t,i=function(t){if(!t)return b;if(null!=t.encoder&&"function"!=typeof t.encoder)throw new TypeError("Encoder has to be a function.");var e=t.charset||b.charset;if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var r=s.default;if(void 0!==t.format){if(!a.call(s.formatters,t.format))throw new TypeError("Unknown format option provided.");r=t.format}var n=s.formatters[r],i=b.filter;return("function"==typeof t.filter||l(t.filter))&&(i=t.filter),{addQueryPrefix:"boolean"==typeof t.addQueryPrefix?t.addQueryPrefix:b.addQueryPrefix,allowDots:void 0===t.allowDots?b.allowDots:!!t.allowDots,charset:e,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:b.charsetSentinel,delimiter:void 0===t.delimiter?b.delimiter:t.delimiter,encode:"boolean"==typeof t.encode?t.encode:b.encode,encoder:"function"==typeof t.encoder?t.encoder:b.encoder,encodeValuesOnly:"boolean"==typeof t.encodeValuesOnly?t.encodeValuesOnly:b.encodeValuesOnly,filter:i,formatter:n,serializeDate:"function"==typeof t.serializeDate?t.serializeDate:b.serializeDate,skipNulls:"boolean"==typeof t.skipNulls?t.skipNulls:b.skipNulls,sort:"function"==typeof t.sort?t.sort:null,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:b.strictNullHandling}}(e);"function"==typeof i.filter?n=(0,i.filter)("",n):l(i.filter)&&(r=i.filter);var o=[];if("object"!=typeof n||null===n)return"";var u=c[e&&e.arrayFormat in c?e.arrayFormat:e&&"indices"in e?e.indices?"indices":"repeat":"indices"];r||(r=Object.keys(n)),i.sort&&r.sort(i.sort);for(var f=0;f0?y+d:""}({...t,...this.u._query},{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:(t,e)=>"boolean"==typeof t?Number(t):e(t)})}current(t,e){const r=this.t.absolute?this.l.host+this.l.pathname:this.l.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"),[n,i]=Object.entries(this.t.routes).find(([e,n])=>new S(t,n,this.t).matchesUrl(r))||[void 0,void 0];if(!t)return n;const o=new RegExp(`^${t.replace(".","\\.").replace("*",".*")}$`).test(n);if([null,void 0].includes(e)||!o)return o;const u=new S(n,i,this.t);e=this.s(e,u);const f=this.h(i);return!(!Object.values(e).every(t=>!t)||Object.values(f).length)||Object.entries(e).every(([t,e])=>f[t]==e)}get l(){var t,e,r;const{host:n="",pathname:i="",search:o=""}="undefined"!=typeof window?window.location:{};return{host:(null===(t=this.t.location)||void 0===t?void 0:t.host)??n,pathname:(null===(e=this.t.location)||void 0===e?void 0:e.pathname)??i,search:(null===(r=this.t.location)||void 0===r?void 0:r.search)??o}}get params(){return this.h(this.t.routes[this.current()])}has(t){return Object.keys(this.t.routes).includes(t)}s(t={},e=this.i){t=["string","number"].includes(typeof t)?[t]:t;const r=e.parameterSegments.filter(({name:t})=>!this.t.defaults[t]);return Array.isArray(t)?t=t.reduce((t,e,n)=>r[n]?{...t,[r[n].name]:e}:{...t,[e]:""},{}):1!==r.length||t[r[0].name]||!t.hasOwnProperty(Object.values(e.bindings)[0])&&!t.hasOwnProperty("id")||(t={[r[0].name]:t}),{...this.p(e),...this.v(t,e.bindings)}}p(t){return t.parameterSegments.filter(({name:t})=>this.t.defaults[t]).reduce((t,{name:e},r)=>({...t,[e]:this.t.defaults[e]}),{})}v(t,e={}){return Object.entries(t).reduce((t,[r,n])=>{if(!n||"object"!=typeof n||Array.isArray(n)||"_query"===r)return{...t,[r]:n};if(!n.hasOwnProperty(e[r])){if(!n.hasOwnProperty("id"))throw new Error(`Ziggy error: object passed as '${r}' parameter is missing route model binding key '${e[r]}'.`);e[r]="id"}return{...t,[r]:n[e[r]]}},{})}h(t){var e;let r=this.l.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"");const n=(t,e="",r)=>{const[n,i]=[t,e].map(t=>t.split(r));return i.reduce((t,e,r)=>/^{[^}?]+\??}$/.test(e)&&n[r]?{...t,[e.replace(/^{|\??}$/g,"")]:n[r]}:t,{})};return{...n(this.l.host,t.domain,"."),...n(r,t.uri,"/"),...E(null===(e=this.l.search)||void 0===e?void 0:e.replace(/^\?/,""))}}valueOf(){return this.toString()}check(t){return this.has(t)}}export default function(t,e,r,n){const i=new N(t,e,r,n);return t?i.toString():i} +function t(t,r){for(var n=0;n1;){var r=t.pop(),n=r.obj[r.prop];if(a(n)){for(var e=[],i=0;i=48&&u<=57||u>=65&&u<=90||u>=97&&u<=122?i+=e.charAt(o):u<128?i+=l[u]:u<2048?i+=l[192|u>>6]+l[128|63&u]:u<55296||u>=57344?i+=l[224|u>>12]+l[128|u>>6&63]+l[128|63&u]:(u=65536+((1023&u)<<10|1023&e.charCodeAt(o+=1)),i+=l[240|u>>18]+l[128|u>>12&63]+l[128|u>>6&63]+l[128|63&u])}return i},isBuffer:function(t){return!(!t||"object"!=typeof t||!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t)))},isRegExp:function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},maybeMap:function(t,r){if(a(t)){for(var n=[],e=0;e-1?t.split(","):t},T=function(t,r,n,e){if(t){var i=n.allowDots?t.replace(/\.([^.[]+)/g,"[$1]"):t,o=/(\[[^[\]]*])/g,u=n.depth>0&&/(\[[^[\]]*])/.exec(i),f=u?i.slice(0,u.index):i,c=[];if(f){if(!n.plainObjects&&S.call(Object.prototype,f)&&!n.allowPrototypes)return;c.push(f)}for(var a=0;n.depth>0&&null!==(u=o.exec(i))&&a=0;--o){var u,f=t[o];if("[]"===f&&n.parseArrays)u=[].concat(i);else{u=n.plainObjects?Object.create(null):{};var c="["===f.charAt(0)&&"]"===f.charAt(f.length-1)?f.slice(1,-1):f,a=parseInt(c,10);n.parseArrays||""!==c?!isNaN(a)&&f!==c&&String(a)===c&&a>=0&&n.parseArrays&&a<=n.arrayLimit?(u=[])[a]=i:u[c]=i:u={0:i}}i=u}return i}(c,r,n,e)}},F=function(){function t(t,r,n){var e;this.name=t,this.definition=r,this.bindings=null!=(e=r.bindings)?e:{},this.config=n}var n=t.prototype;return n.matchesUrl=function(t){if(!this.definition.methods.includes("GET"))return!1;var r=this.template.replace(/\/{[^}?]*\?}/g,"(/[^/?]+)?").replace(/{[^}]+}/g,"[^/?]+").replace(/^\w+:\/\//,"");return new RegExp("^"+r+"$").test(t.replace(/\/+$/,"").split("?").shift())},n.compile=function(t){var r=this;return this.parameterSegments.length?this.template.replace(/{([^}?]+)\??}/g,function(n,e){var i;if([null,void 0].includes(t[e])&&r.parameterSegments.find(function(t){return t.name===e}).required)throw new Error("Ziggy error: '"+e+"' parameter is required for route '"+r.name+"'.");return encodeURIComponent(null!=(i=t[e])?i:"")}).replace(/\/+$/,""):this.template},r(t,[{key:"template",get:function(){return((this.config.absolute?this.definition.domain?""+this.config.url.match(/^\w+:\/\//)[0]+this.definition.domain+(this.config.port?":"+this.config.port:""):this.config.url:"")+"/"+this.definition.uri).replace(/\/+$/,"")}},{key:"parameterSegments",get:function(){var t,r;return null!=(t=null===(r=this.template.match(/{[^}?]+\??}/g))||void 0===r?void 0:r.map(function(t){return{name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)}}))?t:[]}}]),t}(),$=function(t){var e,i;function o(r,e,i,o){var u,f;if(void 0===i&&(i=!0),(f=t.call(this)||this).t=null!=(u=null!=o?o:Ziggy)?u:null===globalThis||void 0===globalThis?void 0:globalThis.Ziggy,f.t=n({},f.t,{absolute:i}),r){if(!f.t.routes[r])throw new Error("Ziggy error: route '"+r+"' is not in the route list.");f.i=new F(r,f.t.routes[r],f.t),f.u=f.l(e)}return f}i=t,(e=o).prototype=Object.create(i.prototype),e.prototype.constructor=e,e.__proto__=i;var u=o.prototype;return u.toString=function(){var t=this,r=Object.keys(this.u).filter(function(r){return!t.i.parameterSegments.some(function(t){return t.name===r})}).filter(function(t){return"_query"!==t}).reduce(function(r,e){var i;return n({},r,((i={})[e]=t.u[e],i))},{});return this.i.compile(this.u)+function(t,r){var n,e=t,i=function(t){if(!t)return E;if(null!=t.encoder&&"function"!=typeof t.encoder)throw new TypeError("Encoder has to be a function.");var r=t.charset||E.charset;if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var n=y.default;if(void 0!==t.format){if(!b.call(y.formatters,t.format))throw new TypeError("Unknown format option provided.");n=t.format}var e=y.formatters[n],i=E.filter;return("function"==typeof t.filter||j(t.filter))&&(i=t.filter),{addQueryPrefix:"boolean"==typeof t.addQueryPrefix?t.addQueryPrefix:E.addQueryPrefix,allowDots:void 0===t.allowDots?E.allowDots:!!t.allowDots,charset:r,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:E.charsetSentinel,delimiter:void 0===t.delimiter?E.delimiter:t.delimiter,encode:"boolean"==typeof t.encode?t.encode:E.encode,encoder:"function"==typeof t.encoder?t.encoder:E.encoder,encodeValuesOnly:"boolean"==typeof t.encodeValuesOnly?t.encodeValuesOnly:E.encodeValuesOnly,filter:i,formatter:e,serializeDate:"function"==typeof t.serializeDate?t.serializeDate:E.serializeDate,skipNulls:"boolean"==typeof t.skipNulls?t.skipNulls:E.skipNulls,sort:"function"==typeof t.sort?t.sort:null,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:E.strictNullHandling}}(r);"function"==typeof i.filter?e=(0,i.filter)("",e):j(i.filter)&&(n=i.filter);var o=[];if("object"!=typeof e||null===e)return"";var u=g[r&&r.arrayFormat in g?r.arrayFormat:r&&"indices"in r?r.indices?"indices":"repeat":"indices"];n||(n=Object.keys(e)),i.sort&&n.sort(i.sort);for(var f=0;f0?l+a:""}(n({},r,this.u._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:function(t,r){return"boolean"==typeof t?Number(t):r(t)}})},u.current=function(t,r){var n=this,e=this.t.absolute?this.s().host+this.s().pathname:this.s().pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"),i=Object.entries(this.t.routes).find(function(r){return new F(t,r[1],n.t).matchesUrl(e)})||[void 0,void 0],o=i[0],u=i[1];if(!t)return o;var f=new RegExp("^"+t.replace(".","\\.").replace("*",".*")+"$").test(o);if([null,void 0].includes(r)||!f)return f;var c=new F(o,u,this.t);r=this.l(r,c);var a=this.v(u);return!(!Object.values(r).every(function(t){return!t})||Object.values(a).length)||Object.entries(r).every(function(t){return a[t[0]]==t[1]})},u.s=function(){var t,r,n,e,i,o,u="undefined"!=typeof window?window.location:{},f=u.host,c=u.pathname,a=u.search;return{host:null!=(t=null===(r=this.t.location)||void 0===r?void 0:r.host)?t:void 0===f?"":f,pathname:null!=(n=null===(e=this.t.location)||void 0===e?void 0:e.pathname)?n:void 0===c?"":c,search:null!=(i=null===(o=this.t.location)||void 0===o?void 0:o.search)?i:void 0===a?"":a}},u.has=function(t){return Object.keys(this.t.routes).includes(t)},u.l=function(t,r){var e=this;void 0===t&&(t={}),void 0===r&&(r=this.i),t=["string","number"].includes(typeof t)?[t]:t;var i=r.parameterSegments.filter(function(t){return!e.t.defaults[t.name]});if(Array.isArray(t))t=t.reduce(function(t,r,e){var o,u;return n({},t,i[e]?((o={})[i[e].name]=r,o):((u={})[r]="",u))},{});else if(1===i.length&&!t[i[0].name]&&(t.hasOwnProperty(Object.values(r.bindings)[0])||t.hasOwnProperty("id"))){var o;(o={})[i[0].name]=t,t=o}return n({},this.p(r),this.h(t,r.bindings))},u.p=function(t){var r=this;return t.parameterSegments.filter(function(t){return r.t.defaults[t.name]}).reduce(function(t,e,i){var o,u=e.name;return n({},t,((o={})[u]=r.t.defaults[u],o))},{})},u.h=function(t,r){return void 0===r&&(r={}),Object.entries(t).reduce(function(t,e){var i,o,u=e[0],f=e[1];if(!f||"object"!=typeof f||Array.isArray(f)||"_query"===u)return n({},t,((o={})[u]=f,o));if(!f.hasOwnProperty(r[u])){if(!f.hasOwnProperty("id"))throw new Error("Ziggy error: object passed as '"+u+"' parameter is missing route model binding key '"+r[u]+"'.");r[u]="id"}return n({},t,((i={})[u]=f[r[u]],i))},{})},u.v=function(t){var r,e=this.s().pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,""),i=function(t,r,e){void 0===r&&(r="");var i=[t,r].map(function(t){return t.split(e)}),o=i[0];return i[1].reduce(function(t,r,e){var i;return/^{[^}?]+\??}$/.test(r)&&o[e]?n({},t,((i={})[r.replace(/^{|\??}$/g,"")]=o[e],i)):t},{})};return n({},i(this.s().host,t.domain,"."),i(e,t.uri,"/"),function(t,r){var n=C;if(""===t||null==t)return n.plainObjects?Object.create(null):{};for(var e="string"==typeof t?function(t,r){var n,e={},i=(r.ignoreQueryPrefix?t.replace(/^\?/,""):t).split(r.delimiter,Infinity===r.parameterLimit?void 0:r.parameterLimit),o=-1,u=r.charset;if(r.charsetSentinel)for(n=0;n-1&&(c=x(c)?[c]:c),e[f]=S.call(e,f)?v.combine(e[f],c):c}return e}(t,n):t,i=n.plainObjects?Object.create(null):{},o=Object.keys(e),u=0;u1;){var r=t.pop(),n=r.obj[r.prop];if(e(n)){for(var i=[],o=0;o=48&&s<=57||s>=65&&s<=90||s>=97&&s<=122?o+=i.charAt(u):s<128?o+=n[s]:s<2048?o+=n[192|s>>6]+n[128|63&s]:s<55296||s>=57344?o+=n[224|s>>12]+n[128|s>>6&63]+n[128|63&s]:(s=65536+((1023&s)<<10|1023&i.charCodeAt(u+=1)),o+=n[240|s>>18]+n[128|s>>12&63]+n[128|s>>6&63]+n[128|63&s])}return o},isBuffer:function(t){return!(!t||"object"!=typeof t||!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t)))},isRegExp:function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},maybeMap:function(t,r){if(e(t)){for(var n=[],i=0;i-1?t.split(","):t},E=function(t,r,e,n){if(t){var i=e.allowDots?t.replace(/\.([^.[]+)/g,"[$1]"):t,o=/(\[[^[\]]*])/g,u=e.depth>0&&/(\[[^[\]]*])/.exec(i),s=u?i.slice(0,u.index):i,f=[];if(s){if(!e.plainObjects&&m.call(Object.prototype,s)&&!e.allowPrototypes)return;f.push(s)}for(var a=0;e.depth>0&&null!==(u=o.exec(i))&&a=0;--o){var u,s=t[o];if("[]"===s&&e.parseArrays)u=[].concat(i);else{u=e.plainObjects?Object.create(null):{};var f="["===s.charAt(0)&&"]"===s.charAt(s.length-1)?s.slice(1,-1):s,a=parseInt(f,10);e.parseArrays||""!==f?!isNaN(a)&&s!==f&&String(a)===f&&a>=0&&e.parseArrays&&a<=e.arrayLimit?(u=[])[a]=i:u[f]=i:u={0:i}}i=u}return i}(f,r,e,n)}};class S{constructor(t,r,e){var n;this.name=t,this.definition=r,this.bindings=null!=(n=r.bindings)?n:{},this.config=e}get template(){return`${this.config.absolute?this.definition.domain?`${this.config.url.match(/^\w+:\/\//)[0]}${this.definition.domain}${this.config.port?":"+this.config.port:""}`:this.config.url:""}/${this.definition.uri}`.replace(/\/+$/,"")}get parameterSegments(){var t,r;return null!=(t=null===(r=this.template.match(/{[^}?]+\??}/g))||void 0===r?void 0:r.map(t=>({name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)})))?t:[]}matchesUrl(t){if(!this.definition.methods.includes("GET"))return!1;const r=this.template.replace(/\/{[^}?]*\?}/g,"(/[^/?]+)?").replace(/{[^}]+}/g,"[^/?]+").replace(/^\w+:\/\//,"");return new RegExp(`^${r}$`).test(t.replace(/\/+$/,"").split("?").shift())}compile(t){return this.parameterSegments.length?this.template.replace(/{([^}?]+)\??}/g,(r,e)=>{var n;if([null,void 0].includes(t[e])&&this.parameterSegments.find(({name:t})=>t===e).required)throw new Error(`Ziggy error: '${e}' parameter is required for route '${this.name}'.`);return encodeURIComponent(null!=(n=t[e])?n:"")}).replace(/\/+$/,""):this.template}}class R extends String{constructor(r,e,n=!0,i){var o;if(super(),this.t=null!=(o=null!=i?i:Ziggy)?o:null===globalThis||void 0===globalThis?void 0:globalThis.Ziggy,this.t=t({},this.t,{absolute:n}),r){if(!this.t.routes[r])throw new Error(`Ziggy error: route '${r}' is not in the route list.`);this.i=new S(r,this.t.routes[r],this.t),this.u=this.s(e)}}toString(){const r=Object.keys(this.u).filter(t=>!this.i.parameterSegments.some(({name:r})=>r===t)).filter(t=>"_query"!==t).reduce((r,e)=>t({},r,{[e]:this.u[e]}),{});return this.i.compile(this.u)+function(t,r){var e,n=t,i=function(t){if(!t)return b;if(null!=t.encoder&&"function"!=typeof t.encoder)throw new TypeError("Encoder has to be a function.");var r=t.charset||b.charset;if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var e=a.default;if(void 0!==t.format){if(!c.call(a.formatters,t.format))throw new TypeError("Unknown format option provided.");e=t.format}var n=a.formatters[e],i=b.filter;return("function"==typeof t.filter||h(t.filter))&&(i=t.filter),{addQueryPrefix:"boolean"==typeof t.addQueryPrefix?t.addQueryPrefix:b.addQueryPrefix,allowDots:void 0===t.allowDots?b.allowDots:!!t.allowDots,charset:r,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:b.charsetSentinel,delimiter:void 0===t.delimiter?b.delimiter:t.delimiter,encode:"boolean"==typeof t.encode?t.encode:b.encode,encoder:"function"==typeof t.encoder?t.encoder:b.encoder,encodeValuesOnly:"boolean"==typeof t.encodeValuesOnly?t.encodeValuesOnly:b.encodeValuesOnly,filter:i,formatter:n,serializeDate:"function"==typeof t.serializeDate?t.serializeDate:b.serializeDate,skipNulls:"boolean"==typeof t.skipNulls?t.skipNulls:b.skipNulls,sort:"function"==typeof t.sort?t.sort:null,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:b.strictNullHandling}}(r);"function"==typeof i.filter?n=(0,i.filter)("",n):h(i.filter)&&(e=i.filter);var o=[];if("object"!=typeof n||null===n)return"";var u=l[r&&r.arrayFormat in l?r.arrayFormat:r&&"indices"in r?r.indices?"indices":"repeat":"indices"];e||(e=Object.keys(n)),i.sort&&e.sort(i.sort);for(var s=0;s0?v+d:""}(t({},r,this.u._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:(t,r)=>"boolean"==typeof t?Number(t):r(t)})}current(t,r){const e=this.t.absolute?this.l.host+this.l.pathname:this.l.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"),[n,i]=Object.entries(this.t.routes).find(([r,n])=>new S(t,n,this.t).matchesUrl(e))||[void 0,void 0];if(!t)return n;const o=new RegExp(`^${t.replace(".","\\.").replace("*",".*")}$`).test(n);if([null,void 0].includes(r)||!o)return o;const u=new S(n,i,this.t);r=this.s(r,u);const s=this.h(i);return!(!Object.values(r).every(t=>!t)||Object.values(s).length)||Object.entries(r).every(([t,r])=>s[t]==r)}get l(){var t,r,e,n,i,o;const{host:u="",pathname:s="",search:f=""}="undefined"!=typeof window?window.location:{};return{host:null!=(t=null===(r=this.t.location)||void 0===r?void 0:r.host)?t:u,pathname:null!=(e=null===(n=this.t.location)||void 0===n?void 0:n.pathname)?e:s,search:null!=(i=null===(o=this.t.location)||void 0===o?void 0:o.search)?i:f}}get params(){return this.h(this.t.routes[this.current()])}has(t){return Object.keys(this.t.routes).includes(t)}s(r={},e=this.i){r=["string","number"].includes(typeof r)?[r]:r;const n=e.parameterSegments.filter(({name:t})=>!this.t.defaults[t]);return Array.isArray(r)?r=r.reduce((r,e,i)=>t({},r,n[i]?{[n[i].name]:e}:{[e]:""}),{}):1!==n.length||r[n[0].name]||!r.hasOwnProperty(Object.values(e.bindings)[0])&&!r.hasOwnProperty("id")||(r={[n[0].name]:r}),t({},this.p(e),this.v(r,e.bindings))}p(r){return r.parameterSegments.filter(({name:t})=>this.t.defaults[t]).reduce((r,{name:e},n)=>t({},r,{[e]:this.t.defaults[e]}),{})}v(r,e={}){return Object.entries(r).reduce((r,[n,i])=>{if(!i||"object"!=typeof i||Array.isArray(i)||"_query"===n)return t({},r,{[n]:i});if(!i.hasOwnProperty(e[n])){if(!i.hasOwnProperty("id"))throw new Error(`Ziggy error: object passed as '${n}' parameter is missing route model binding key '${e[n]}'.`);e[n]="id"}return t({},r,{[n]:i[e[n]]})},{})}h(r){var e;let n=this.l.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"");const i=(r,e="",n)=>{const[i,o]=[r,e].map(t=>t.split(n));return o.reduce((r,e,n)=>/^{[^}?]+\??}$/.test(e)&&i[n]?t({},r,{[e.replace(/^{|\??}$/g,"")]:i[n]}):r,{})};return t({},i(this.l.host,r.domain,"."),i(n,r.uri,"/"),function(t,r){var e=O;if(""===t||null==t)return e.plainObjects?Object.create(null):{};for(var n="string"==typeof t?function(t,r){var e,n={},i=(r.ignoreQueryPrefix?t.replace(/^\?/,""):t).split(r.delimiter,Infinity===r.parameterLimit?void 0:r.parameterLimit),u=-1,s=r.charset;if(r.charsetSentinel)for(e=0;e-1&&(a=j(a)?[a]:a),n[f]=m.call(n,f)?o.combine(n[f],a):a}return n}(t,e):t,i=e.plainObjects?Object.create(null):{},u=Object.keys(n),s=0;st.mixin({methods:{route:(t,e,n,i=r)=>function(t,r,e,n){const i=new R(t,r,e,n);return t?i.toString():i}(t,e,n,i)}})};export{k as ZiggyVue}; +function t(){return(t=Object.assign||function(t){for(var r=1;r1;){var r=t.pop(),n=r.obj[r.prop];if(e(n)){for(var i=[],o=0;o=48&&s<=57||s>=65&&s<=90||s>=97&&s<=122?o+=i.charAt(u):s<128?o+=n[s]:s<2048?o+=n[192|s>>6]+n[128|63&s]:s<55296||s>=57344?o+=n[224|s>>12]+n[128|s>>6&63]+n[128|63&s]:(s=65536+((1023&s)<<10|1023&i.charCodeAt(u+=1)),o+=n[240|s>>18]+n[128|s>>12&63]+n[128|s>>6&63]+n[128|63&s])}return o},isBuffer:function(t){return!(!t||"object"!=typeof t||!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t)))},isRegExp:function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},maybeMap:function(t,r){if(e(t)){for(var n=[],i=0;i-1?t.split(","):t},E=function(t,r,e,n){if(t){var i=e.allowDots?t.replace(/\.([^.[]+)/g,"[$1]"):t,o=/(\[[^[\]]*])/g,u=e.depth>0&&/(\[[^[\]]*])/.exec(i),s=u?i.slice(0,u.index):i,f=[];if(s){if(!e.plainObjects&&m.call(Object.prototype,s)&&!e.allowPrototypes)return;f.push(s)}for(var a=0;e.depth>0&&null!==(u=o.exec(i))&&a=0;--o){var u,s=t[o];if("[]"===s&&e.parseArrays)u=[].concat(i);else{u=e.plainObjects?Object.create(null):{};var f="["===s.charAt(0)&&"]"===s.charAt(s.length-1)?s.slice(1,-1):s,a=parseInt(f,10);e.parseArrays||""!==f?!isNaN(a)&&s!==f&&String(a)===f&&a>=0&&e.parseArrays&&a<=e.arrayLimit?(u=[])[a]=i:u[f]=i:u={0:i}}i=u}return i}(f,r,e,n)}};class S{constructor(t,r,e){var n;this.name=t,this.definition=r,this.bindings=null!=(n=r.bindings)?n:{},this.config=e}get template(){return`${this.config.absolute?this.definition.domain?`${this.config.url.match(/^\w+:\/\//)[0]}${this.definition.domain}${this.config.port?":"+this.config.port:""}`:this.config.url:""}/${this.definition.uri}`.replace(/\/+$/,"")}get parameterSegments(){var t,r;return null!=(t=null===(r=this.template.match(/{[^}?]+\??}/g))||void 0===r?void 0:r.map(t=>({name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)})))?t:[]}matchesUrl(t){if(!this.definition.methods.includes("GET"))return!1;const r=this.template.replace(/\/{[^}?]*\?}/g,"(/[^/?]+)?").replace(/{[^}]+}/g,"[^/?]+").replace(/^\w+:\/\//,"");return new RegExp(`^${r}$`).test(t.replace(/\/+$/,"").split("?").shift())}compile(t){return this.parameterSegments.length?this.template.replace(/{([^}?]+)\??}/g,(r,e)=>{var n;if([null,void 0].includes(t[e])&&this.parameterSegments.find(({name:t})=>t===e).required)throw new Error(`Ziggy error: '${e}' parameter is required for route '${this.name}'.`);return encodeURIComponent(null!=(n=t[e])?n:"")}).replace(/\/+$/,""):this.template}}class R extends String{constructor(r,e,n=!0,i){var o;if(super(),this.t=null!=(o=null!=i?i:Ziggy)?o:null===globalThis||void 0===globalThis?void 0:globalThis.Ziggy,this.t=t({},this.t,{absolute:n}),r){if(!this.t.routes[r])throw new Error(`Ziggy error: route '${r}' is not in the route list.`);this.i=new S(r,this.t.routes[r],this.t),this.u=this.s(e)}}toString(){const r=Object.keys(this.u).filter(t=>!this.i.parameterSegments.some(({name:r})=>r===t)).filter(t=>"_query"!==t).reduce((r,e)=>t({},r,{[e]:this.u[e]}),{});return this.i.compile(this.u)+function(t,r){var e,n=t,i=function(t){if(!t)return b;if(null!=t.encoder&&"function"!=typeof t.encoder)throw new TypeError("Encoder has to be a function.");var r=t.charset||b.charset;if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var e=a.default;if(void 0!==t.format){if(!c.call(a.formatters,t.format))throw new TypeError("Unknown format option provided.");e=t.format}var n=a.formatters[e],i=b.filter;return("function"==typeof t.filter||h(t.filter))&&(i=t.filter),{addQueryPrefix:"boolean"==typeof t.addQueryPrefix?t.addQueryPrefix:b.addQueryPrefix,allowDots:void 0===t.allowDots?b.allowDots:!!t.allowDots,charset:r,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:b.charsetSentinel,delimiter:void 0===t.delimiter?b.delimiter:t.delimiter,encode:"boolean"==typeof t.encode?t.encode:b.encode,encoder:"function"==typeof t.encoder?t.encoder:b.encoder,encodeValuesOnly:"boolean"==typeof t.encodeValuesOnly?t.encodeValuesOnly:b.encodeValuesOnly,filter:i,formatter:n,serializeDate:"function"==typeof t.serializeDate?t.serializeDate:b.serializeDate,skipNulls:"boolean"==typeof t.skipNulls?t.skipNulls:b.skipNulls,sort:"function"==typeof t.sort?t.sort:null,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:b.strictNullHandling}}(r);"function"==typeof i.filter?n=(0,i.filter)("",n):h(i.filter)&&(e=i.filter);var o=[];if("object"!=typeof n||null===n)return"";var u=l[r&&r.arrayFormat in l?r.arrayFormat:r&&"indices"in r?r.indices?"indices":"repeat":"indices"];e||(e=Object.keys(n)),i.sort&&e.sort(i.sort);for(var s=0;s0?v+d:""}(t({},r,this.u._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:(t,r)=>"boolean"==typeof t?Number(t):r(t)})}current(t,r){const e=this.t.absolute?this.l().host+this.l().pathname:this.l().pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"),[n,i]=Object.entries(this.t.routes).find(([r,n])=>new S(t,n,this.t).matchesUrl(e))||[void 0,void 0];if(!t)return n;const o=new RegExp(`^${t.replace(".","\\.").replace("*",".*")}$`).test(n);if([null,void 0].includes(r)||!o)return o;const u=new S(n,i,this.t);r=this.s(r,u);const s=this.h(i);return!(!Object.values(r).every(t=>!t)||Object.values(s).length)||Object.entries(r).every(([t,r])=>s[t]==r)}l(){var t,r,e,n,i,o;const{host:u="",pathname:s="",search:f=""}="undefined"!=typeof window?window.location:{};return{host:null!=(t=null===(r=this.t.location)||void 0===r?void 0:r.host)?t:u,pathname:null!=(e=null===(n=this.t.location)||void 0===n?void 0:n.pathname)?e:s,search:null!=(i=null===(o=this.t.location)||void 0===o?void 0:o.search)?i:f}}get params(){return this.h(this.t.routes[this.current()])}has(t){return Object.keys(this.t.routes).includes(t)}s(r={},e=this.i){r=["string","number"].includes(typeof r)?[r]:r;const n=e.parameterSegments.filter(({name:t})=>!this.t.defaults[t]);return Array.isArray(r)?r=r.reduce((r,e,i)=>t({},r,n[i]?{[n[i].name]:e}:{[e]:""}),{}):1!==n.length||r[n[0].name]||!r.hasOwnProperty(Object.values(e.bindings)[0])&&!r.hasOwnProperty("id")||(r={[n[0].name]:r}),t({},this.p(e),this.v(r,e.bindings))}p(r){return r.parameterSegments.filter(({name:t})=>this.t.defaults[t]).reduce((r,{name:e},n)=>t({},r,{[e]:this.t.defaults[e]}),{})}v(r,e={}){return Object.entries(r).reduce((r,[n,i])=>{if(!i||"object"!=typeof i||Array.isArray(i)||"_query"===n)return t({},r,{[n]:i});if(!i.hasOwnProperty(e[n])){if(!i.hasOwnProperty("id"))throw new Error(`Ziggy error: object passed as '${n}' parameter is missing route model binding key '${e[n]}'.`);e[n]="id"}return t({},r,{[n]:i[e[n]]})},{})}h(r){var e;let n=this.l().pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"");const i=(r,e="",n)=>{const[i,o]=[r,e].map(t=>t.split(n));return o.reduce((r,e,n)=>/^{[^}?]+\??}$/.test(e)&&i[n]?t({},r,{[e.replace(/^{|\??}$/g,"")]:i[n]}):r,{})};return t({},i(this.l().host,r.domain,"."),i(n,r.uri,"/"),function(t,r){var e=O;if(""===t||null==t)return e.plainObjects?Object.create(null):{};for(var n="string"==typeof t?function(t,r){var e,n={},i=(r.ignoreQueryPrefix?t.replace(/^\?/,""):t).split(r.delimiter,Infinity===r.parameterLimit?void 0:r.parameterLimit),u=-1,s=r.charset;if(r.charsetSentinel)for(e=0;e-1&&(a=j(a)?[a]:a),n[f]=m.call(n,f)?o.combine(n[f],a):a}return n}(t,e):t,i=e.plainObjects?Object.create(null):{},u=Object.keys(n),s=0;st.mixin({methods:{route:(t,e,n,i=r)=>function(t,r,e,n){const i=new R(t,r,e,n);return t?i.toString():i}(t,e,n,i)}})};export{k as ZiggyVue}; diff --git a/dist/vue.js b/dist/vue.js index 037df82a..42a43f98 100644 --- a/dist/vue.js +++ b/dist/vue.js @@ -1 +1 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self).ZiggyVue={})}(this,function(t){var e=Object.prototype.hasOwnProperty,r=Array.isArray,n=function(){for(var t=[],e=0;e<256;++e)t.push("%"+((e<16?"0":"")+e.toString(16)).toUpperCase());return t}(),i=function(t,e){for(var r=e&&e.plainObjects?Object.create(null):{},n=0;n1;){var e=t.pop(),n=e.obj[e.prop];if(r(n)){for(var i=[],o=0;o=48&&f<=57||f>=65&&f<=90||f>=97&&f<=122?o+=i.charAt(u):f<128?o+=n[f]:f<2048?o+=n[192|f>>6]+n[128|63&f]:f<55296||f>=57344?o+=n[224|f>>12]+n[128|f>>6&63]+n[128|63&f]:(f=65536+((1023&f)<<10|1023&i.charCodeAt(u+=1)),o+=n[240|f>>18]+n[128|f>>12&63]+n[128|f>>6&63]+n[128|63&f])}return o},isBuffer:function(t){return!(!t||"object"!=typeof t||!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t)))},isRegExp:function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},maybeMap:function(t,e){if(r(t)){for(var n=[],i=0;i-1?t.split(","):t},E=function(t,e,r,n){if(t){var i=r.allowDots?t.replace(/\.([^.[]+)/g,"[$1]"):t,o=/(\[[^[\]]*])/g,u=r.depth>0&&/(\[[^[\]]*])/.exec(i),f=u?i.slice(0,u.index):i,s=[];if(f){if(!r.plainObjects&&g.call(Object.prototype,f)&&!r.allowPrototypes)return;s.push(f)}for(var a=0;r.depth>0&&null!==(u=o.exec(i))&&a=0;--o){var u,f=t[o];if("[]"===f&&r.parseArrays)u=[].concat(i);else{u=r.plainObjects?Object.create(null):{};var s="["===f.charAt(0)&&"]"===f.charAt(f.length-1)?f.slice(1,-1):f,a=parseInt(s,10);r.parseArrays||""!==s?!isNaN(a)&&f!==s&&String(a)===s&&a>=0&&r.parseArrays&&a<=r.arrayLimit?(u=[])[a]=i:u[s]=i:u={0:i}}i=u}return i}(s,e,r,n)}},S=function(t,e){var r=function(t){if(!t)return w;if(null!=t.decoder&&"function"!=typeof t.decoder)throw new TypeError("Decoder has to be a function.");if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");return{allowDots:void 0===t.allowDots?w.allowDots:!!t.allowDots,allowPrototypes:"boolean"==typeof t.allowPrototypes?t.allowPrototypes:w.allowPrototypes,arrayLimit:"number"==typeof t.arrayLimit?t.arrayLimit:w.arrayLimit,charset:void 0===t.charset?w.charset:t.charset,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:w.charsetSentinel,comma:"boolean"==typeof t.comma?t.comma:w.comma,decoder:"function"==typeof t.decoder?t.decoder:w.decoder,delimiter:"string"==typeof t.delimiter||o.isRegExp(t.delimiter)?t.delimiter:w.delimiter,depth:"number"==typeof t.depth||!1===t.depth?+t.depth:w.depth,ignoreQueryPrefix:!0===t.ignoreQueryPrefix,interpretNumericEntities:"boolean"==typeof t.interpretNumericEntities?t.interpretNumericEntities:w.interpretNumericEntities,parameterLimit:"number"==typeof t.parameterLimit?t.parameterLimit:w.parameterLimit,parseArrays:!1!==t.parseArrays,plainObjects:"boolean"==typeof t.plainObjects?t.plainObjects:w.plainObjects,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:w.strictNullHandling}}(e);if(""===t||null==t)return r.plainObjects?Object.create(null):{};for(var n="string"==typeof t?function(t,e){var r,n={},i=(e.ignoreQueryPrefix?t.replace(/^\?/,""):t).split(e.delimiter,Infinity===e.parameterLimit?void 0:e.parameterLimit),u=-1,f=e.charset;if(e.charsetSentinel)for(r=0;r-1&&(a=j(a)?[a]:a),n[s]=g.call(n,s)?o.combine(n[s],a):a}return n}(t,r):t,i=r.plainObjects?Object.create(null):{},u=Object.keys(n),f=0;f({name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)})))??[]}matchesUrl(t){if(!this.definition.methods.includes("GET"))return!1;const e=this.template.replace(/\/{[^}?]*\?}/g,"(/[^/?]+)?").replace(/{[^}]+}/g,"[^/?]+").replace(/^\w+:\/\//,"");return new RegExp(`^${e}$`).test(t.replace(/\/+$/,"").split("?").shift())}compile(t){return this.parameterSegments.length?this.template.replace(/{([^}?]+)\??}/g,(e,r)=>{if([null,void 0].includes(t[r])&&this.parameterSegments.find(({name:t})=>t===r).required)throw new Error(`Ziggy error: '${r}' parameter is required for route '${this.name}'.`);return encodeURIComponent(t[r]??"")}).replace(/\/+$/,""):this.template}}class N extends String{constructor(t,e,r=!0,n){if(super(),this.t=n??Ziggy??(null===globalThis||void 0===globalThis?void 0:globalThis.Ziggy),this.t={...this.t,absolute:r},t){if(!this.t.routes[t])throw new Error(`Ziggy error: route '${t}' is not in the route list.`);this.i=new x(t,this.t.routes[t],this.t),this.u=this.s(e)}}toString(){const t=Object.keys(this.u).filter(t=>!this.i.parameterSegments.some(({name:e})=>e===t)).filter(t=>"_query"!==t).reduce((t,e)=>({...t,[e]:this.u[e]}),{});return this.i.compile(this.u)+function(t,e){var r,n=t,i=function(t){if(!t)return v;if(null!=t.encoder&&"function"!=typeof t.encoder)throw new TypeError("Encoder has to be a function.");var e=t.charset||v.charset;if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var r=a.default;if(void 0!==t.format){if(!c.call(a.formatters,t.format))throw new TypeError("Unknown format option provided.");r=t.format}var n=a.formatters[r],i=v.filter;return("function"==typeof t.filter||h(t.filter))&&(i=t.filter),{addQueryPrefix:"boolean"==typeof t.addQueryPrefix?t.addQueryPrefix:v.addQueryPrefix,allowDots:void 0===t.allowDots?v.allowDots:!!t.allowDots,charset:e,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:v.charsetSentinel,delimiter:void 0===t.delimiter?v.delimiter:t.delimiter,encode:"boolean"==typeof t.encode?t.encode:v.encode,encoder:"function"==typeof t.encoder?t.encoder:v.encoder,encodeValuesOnly:"boolean"==typeof t.encodeValuesOnly?t.encodeValuesOnly:v.encodeValuesOnly,filter:i,formatter:n,serializeDate:"function"==typeof t.serializeDate?t.serializeDate:v.serializeDate,skipNulls:"boolean"==typeof t.skipNulls?t.skipNulls:v.skipNulls,sort:"function"==typeof t.sort?t.sort:null,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:v.strictNullHandling}}(e);"function"==typeof i.filter?n=(0,i.filter)("",n):h(i.filter)&&(r=i.filter);var o=[];if("object"!=typeof n||null===n)return"";var u=l[e&&e.arrayFormat in l?e.arrayFormat:e&&"indices"in e?e.indices?"indices":"repeat":"indices"];r||(r=Object.keys(n)),i.sort&&r.sort(i.sort);for(var f=0;f0?y+p:""}({...t,...this.u._query},{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:(t,e)=>"boolean"==typeof t?Number(t):e(t)})}current(t,e){const r=this.t.absolute?this.l.host+this.l.pathname:this.l.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"),[n,i]=Object.entries(this.t.routes).find(([e,n])=>new x(t,n,this.t).matchesUrl(r))||[void 0,void 0];if(!t)return n;const o=new RegExp(`^${t.replace(".","\\.").replace("*",".*")}$`).test(n);if([null,void 0].includes(e)||!o)return o;const u=new x(n,i,this.t);e=this.s(e,u);const f=this.h(i);return!(!Object.values(e).every(t=>!t)||Object.values(f).length)||Object.entries(e).every(([t,e])=>f[t]==e)}get l(){var t,e,r;const{host:n="",pathname:i="",search:o=""}="undefined"!=typeof window?window.location:{};return{host:(null===(t=this.t.location)||void 0===t?void 0:t.host)??n,pathname:(null===(e=this.t.location)||void 0===e?void 0:e.pathname)??i,search:(null===(r=this.t.location)||void 0===r?void 0:r.search)??o}}get params(){return this.h(this.t.routes[this.current()])}has(t){return Object.keys(this.t.routes).includes(t)}s(t={},e=this.i){t=["string","number"].includes(typeof t)?[t]:t;const r=e.parameterSegments.filter(({name:t})=>!this.t.defaults[t]);return Array.isArray(t)?t=t.reduce((t,e,n)=>r[n]?{...t,[r[n].name]:e}:{...t,[e]:""},{}):1!==r.length||t[r[0].name]||!t.hasOwnProperty(Object.values(e.bindings)[0])&&!t.hasOwnProperty("id")||(t={[r[0].name]:t}),{...this.p(e),...this.v(t,e.bindings)}}p(t){return t.parameterSegments.filter(({name:t})=>this.t.defaults[t]).reduce((t,{name:e},r)=>({...t,[e]:this.t.defaults[e]}),{})}v(t,e={}){return Object.entries(t).reduce((t,[r,n])=>{if(!n||"object"!=typeof n||Array.isArray(n)||"_query"===r)return{...t,[r]:n};if(!n.hasOwnProperty(e[r])){if(!n.hasOwnProperty("id"))throw new Error(`Ziggy error: object passed as '${r}' parameter is missing route model binding key '${e[r]}'.`);e[r]="id"}return{...t,[r]:n[e[r]]}},{})}h(t){var e;let r=this.l.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"");const n=(t,e="",r)=>{const[n,i]=[t,e].map(t=>t.split(r));return i.reduce((t,e,r)=>/^{[^}?]+\??}$/.test(e)&&n[r]?{...t,[e.replace(/^{|\??}$/g,"")]:n[r]}:t,{})};return{...n(this.l.host,t.domain,"."),...n(r,t.uri,"/"),...S(null===(e=this.l.search)||void 0===e?void 0:e.replace(/^\?/,""))}}valueOf(){return this.toString()}check(t){return this.has(t)}}t.ZiggyVue={install:(t,e)=>t.mixin({methods:{route:(t,r,n,i=e)=>function(t,e,r,n){const i=new N(t,e,r,n);return t?i.toString():i}(t,r,n,i)}})}}); +!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t=t||self).ZiggyVue={})}(this,function(t){function n(t,n){for(var r=0;r1;){var n=t.pop(),r=n.obj[n.prop];if(s(r)){for(var e=[],i=0;i=48&&u<=57||u>=65&&u<=90||u>=97&&u<=122?i+=e.charAt(o):u<128?i+=l[u]:u<2048?i+=l[192|u>>6]+l[128|63&u]:u<55296||u>=57344?i+=l[224|u>>12]+l[128|u>>6&63]+l[128|63&u]:(u=65536+((1023&u)<<10|1023&e.charCodeAt(o+=1)),i+=l[240|u>>18]+l[128|u>>12&63]+l[128|u>>6&63]+l[128|63&u])}return i},isBuffer:function(t){return!(!t||"object"!=typeof t||!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t)))},isRegExp:function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},maybeMap:function(t,n){if(s(t)){for(var r=[],e=0;e-1?t.split(","):t},F=function(t,n,r,e){if(t){var i=r.allowDots?t.replace(/\.([^.[]+)/g,"[$1]"):t,o=/(\[[^[\]]*])/g,u=r.depth>0&&/(\[[^[\]]*])/.exec(i),f=u?i.slice(0,u.index):i,c=[];if(f){if(!r.plainObjects&&S.call(Object.prototype,f)&&!r.allowPrototypes)return;c.push(f)}for(var a=0;r.depth>0&&null!==(u=o.exec(i))&&a=0;--o){var u,f=t[o];if("[]"===f&&r.parseArrays)u=[].concat(i);else{u=r.plainObjects?Object.create(null):{};var c="["===f.charAt(0)&&"]"===f.charAt(f.length-1)?f.slice(1,-1):f,a=parseInt(c,10);r.parseArrays||""!==c?!isNaN(a)&&f!==c&&String(a)===c&&a>=0&&r.parseArrays&&a<=r.arrayLimit?(u=[])[a]=i:u[c]=i:u={0:i}}i=u}return i}(c,n,r,e)}},$=function(){function t(t,n,r){var e;this.name=t,this.definition=n,this.bindings=null!=(e=n.bindings)?e:{},this.config=r}var n=t.prototype;return n.matchesUrl=function(t){if(!this.definition.methods.includes("GET"))return!1;var n=this.template.replace(/\/{[^}?]*\?}/g,"(/[^/?]+)?").replace(/{[^}]+}/g,"[^/?]+").replace(/^\w+:\/\//,"");return new RegExp("^"+n+"$").test(t.replace(/\/+$/,"").split("?").shift())},n.compile=function(t){var n=this;return this.parameterSegments.length?this.template.replace(/{([^}?]+)\??}/g,function(r,e){var i;if([null,void 0].includes(t[e])&&n.parameterSegments.find(function(t){return t.name===e}).required)throw new Error("Ziggy error: '"+e+"' parameter is required for route '"+n.name+"'.");return encodeURIComponent(null!=(i=t[e])?i:"")}).replace(/\/+$/,""):this.template},r(t,[{key:"template",get:function(){return((this.config.absolute?this.definition.domain?""+this.config.url.match(/^\w+:\/\//)[0]+this.definition.domain+(this.config.port?":"+this.config.port:""):this.config.url:"")+"/"+this.definition.uri).replace(/\/+$/,"")}},{key:"parameterSegments",get:function(){var t,n;return null!=(t=null===(n=this.template.match(/{[^}?]+\??}/g))||void 0===n?void 0:n.map(function(t){return{name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)}}))?t:[]}}]),t}(),A=function(t){var n,i;function o(n,r,i,o){var u,f;if(void 0===i&&(i=!0),(f=t.call(this)||this).t=null!=(u=null!=o?o:Ziggy)?u:null===globalThis||void 0===globalThis?void 0:globalThis.Ziggy,f.t=e({},f.t,{absolute:i}),n){if(!f.t.routes[n])throw new Error("Ziggy error: route '"+n+"' is not in the route list.");f.i=new $(n,f.t.routes[n],f.t),f.u=f.s(r)}return f}i=t,(n=o).prototype=Object.create(i.prototype),n.prototype.constructor=n,n.__proto__=i;var u=o.prototype;return u.toString=function(){var t=this,n=Object.keys(this.u).filter(function(n){return!t.i.parameterSegments.some(function(t){return t.name===n})}).filter(function(t){return"_query"!==t}).reduce(function(n,r){var i;return e({},n,((i={})[r]=t.u[r],i))},{});return this.i.compile(this.u)+function(t,n){var r,e=t,i=function(t){if(!t)return k;if(null!=t.encoder&&"function"!=typeof t.encoder)throw new TypeError("Encoder has to be a function.");var n=t.charset||k.charset;if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var r=b.default;if(void 0!==t.format){if(!g.call(b.formatters,t.format))throw new TypeError("Unknown format option provided.");r=t.format}var e=b.formatters[r],i=k.filter;return("function"==typeof t.filter||m(t.filter))&&(i=t.filter),{addQueryPrefix:"boolean"==typeof t.addQueryPrefix?t.addQueryPrefix:k.addQueryPrefix,allowDots:void 0===t.allowDots?k.allowDots:!!t.allowDots,charset:n,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:k.charsetSentinel,delimiter:void 0===t.delimiter?k.delimiter:t.delimiter,encode:"boolean"==typeof t.encode?t.encode:k.encode,encoder:"function"==typeof t.encoder?t.encoder:k.encoder,encodeValuesOnly:"boolean"==typeof t.encodeValuesOnly?t.encodeValuesOnly:k.encodeValuesOnly,filter:i,formatter:e,serializeDate:"function"==typeof t.serializeDate?t.serializeDate:k.serializeDate,skipNulls:"boolean"==typeof t.skipNulls?t.skipNulls:k.skipNulls,sort:"function"==typeof t.sort?t.sort:null,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:k.strictNullHandling}}(n);"function"==typeof i.filter?e=(0,i.filter)("",e):m(i.filter)&&(r=i.filter);var o=[];if("object"!=typeof e||null===e)return"";var u=j[n&&n.arrayFormat in j?n.arrayFormat:n&&"indices"in n?n.indices?"indices":"repeat":"indices"];r||(r=Object.keys(e)),i.sort&&r.sort(i.sort);for(var f=0;f0?s+a:""}(e({},n,this.u._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:function(t,n){return"boolean"==typeof t?Number(t):n(t)}})},u.current=function(t,n){var r=this,e=this.t.absolute?this.l().host+this.l().pathname:this.l().pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"),i=Object.entries(this.t.routes).find(function(n){return new $(t,n[1],r.t).matchesUrl(e)})||[void 0,void 0],o=i[0],u=i[1];if(!t)return o;var f=new RegExp("^"+t.replace(".","\\.").replace("*",".*")+"$").test(o);if([null,void 0].includes(n)||!f)return f;var c=new $(o,u,this.t);n=this.s(n,c);var a=this.v(u);return!(!Object.values(n).every(function(t){return!t})||Object.values(a).length)||Object.entries(n).every(function(t){return a[t[0]]==t[1]})},u.l=function(){var t,n,r,e,i,o,u="undefined"!=typeof window?window.location:{},f=u.host,c=u.pathname,a=u.search;return{host:null!=(t=null===(n=this.t.location)||void 0===n?void 0:n.host)?t:void 0===f?"":f,pathname:null!=(r=null===(e=this.t.location)||void 0===e?void 0:e.pathname)?r:void 0===c?"":c,search:null!=(i=null===(o=this.t.location)||void 0===o?void 0:o.search)?i:void 0===a?"":a}},u.has=function(t){return Object.keys(this.t.routes).includes(t)},u.s=function(t,n){var r=this;void 0===t&&(t={}),void 0===n&&(n=this.i),t=["string","number"].includes(typeof t)?[t]:t;var i=n.parameterSegments.filter(function(t){return!r.t.defaults[t.name]});if(Array.isArray(t))t=t.reduce(function(t,n,r){var o,u;return e({},t,i[r]?((o={})[i[r].name]=n,o):((u={})[n]="",u))},{});else if(1===i.length&&!t[i[0].name]&&(t.hasOwnProperty(Object.values(n.bindings)[0])||t.hasOwnProperty("id"))){var o;(o={})[i[0].name]=t,t=o}return e({},this.p(n),this.h(t,n.bindings))},u.p=function(t){var n=this;return t.parameterSegments.filter(function(t){return n.t.defaults[t.name]}).reduce(function(t,r,i){var o,u=r.name;return e({},t,((o={})[u]=n.t.defaults[u],o))},{})},u.h=function(t,n){return void 0===n&&(n={}),Object.entries(t).reduce(function(t,r){var i,o,u=r[0],f=r[1];if(!f||"object"!=typeof f||Array.isArray(f)||"_query"===u)return e({},t,((o={})[u]=f,o));if(!f.hasOwnProperty(n[u])){if(!f.hasOwnProperty("id"))throw new Error("Ziggy error: object passed as '"+u+"' parameter is missing route model binding key '"+n[u]+"'.");n[u]="id"}return e({},t,((i={})[u]=f[n[u]],i))},{})},u.v=function(t){var n,r=this.l().pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,""),i=function(t,n,r){void 0===n&&(n="");var i=[t,n].map(function(t){return t.split(r)}),o=i[0];return i[1].reduce(function(t,n,r){var i;return/^{[^}?]+\??}$/.test(n)&&o[r]?e({},t,((i={})[n.replace(/^{|\??}$/g,"")]=o[r],i)):t},{})};return e({},i(this.l().host,t.domain,"."),i(r,t.uri,"/"),function(t,n){var r=D;if(""===t||null==t)return r.plainObjects?Object.create(null):{};for(var e="string"==typeof t?function(t,n){var r,e={},i=(n.ignoreQueryPrefix?t.replace(/^\?/,""):t).split(n.delimiter,Infinity===n.parameterLimit?void 0:n.parameterLimit),o=-1,u=n.charset;if(n.charsetSentinel)for(r=0;r-1&&(c=C(c)?[c]:c),e[f]=S.call(e,f)?d.combine(e[f],c):c}return e}(t,r):t,i=r.plainObjects?Object.create(null):{},o=Object.keys(e),u=0;u1;){var r=t.pop(),n=r.obj[r.prop];if(e(n)){for(var i=[],o=0;o=48&&s<=57||s>=65&&s<=90||s>=97&&s<=122?o+=i.charAt(u):s<128?o+=r[s]:s<2048?o+=r[192|s>>6]+r[128|63&s]:s<55296||s>=57344?o+=r[224|s>>12]+r[128|s>>6&63]+r[128|63&s]:(s=65536+((1023&s)<<10|1023&i.charCodeAt(u+=1)),o+=r[240|s>>18]+r[128|s>>12&63]+r[128|s>>6&63]+r[128|63&s])}return o},isBuffer:function(t){return!(!t||"object"!=typeof t||!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t)))},isRegExp:function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},maybeMap:function(t,r){if(e(t)){for(var n=[],i=0;i-1?t.split(","):t},$=function(t,e,r,n){if(t){var i=r.allowDots?t.replace(/\.([^.[]+)/g,"[$1]"):t,o=/(\[[^[\]]*])/g,u=r.depth>0&&/(\[[^[\]]*])/.exec(i),s=u?i.slice(0,u.index):i,f=[];if(s){if(!r.plainObjects&&m.call(Object.prototype,s)&&!r.allowPrototypes)return;f.push(s)}for(var a=0;r.depth>0&&null!==(u=o.exec(i))&&a=0;--o){var u,s=t[o];if("[]"===s&&r.parseArrays)u=[].concat(i);else{u=r.plainObjects?Object.create(null):{};var f="["===s.charAt(0)&&"]"===s.charAt(s.length-1)?s.slice(1,-1):s,a=parseInt(f,10);r.parseArrays||""!==f?!isNaN(a)&&s!==f&&String(a)===f&&a>=0&&r.parseArrays&&a<=r.arrayLimit?(u=[])[a]=i:u[f]=i:u={0:i}}i=u}return i}(f,e,r,n)}},E=function(t,e){var r=function(t){if(!t)return j;if(null!=t.decoder&&"function"!=typeof t.decoder)throw new TypeError("Decoder has to be a function.");if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");return{allowDots:void 0===t.allowDots?j.allowDots:!!t.allowDots,allowPrototypes:"boolean"==typeof t.allowPrototypes?t.allowPrototypes:j.allowPrototypes,arrayLimit:"number"==typeof t.arrayLimit?t.arrayLimit:j.arrayLimit,charset:void 0===t.charset?j.charset:t.charset,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:j.charsetSentinel,comma:"boolean"==typeof t.comma?t.comma:j.comma,decoder:"function"==typeof t.decoder?t.decoder:j.decoder,delimiter:"string"==typeof t.delimiter||i.isRegExp(t.delimiter)?t.delimiter:j.delimiter,depth:"number"==typeof t.depth||!1===t.depth?+t.depth:j.depth,ignoreQueryPrefix:!0===t.ignoreQueryPrefix,interpretNumericEntities:"boolean"==typeof t.interpretNumericEntities?t.interpretNumericEntities:j.interpretNumericEntities,parameterLimit:"number"==typeof t.parameterLimit?t.parameterLimit:j.parameterLimit,parseArrays:!1!==t.parseArrays,plainObjects:"boolean"==typeof t.plainObjects?t.plainObjects:j.plainObjects,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:j.strictNullHandling}}(e);if(""===t||null==t)return r.plainObjects?Object.create(null):{};for(var n="string"==typeof t?function(t,e){var r,n={},o=(e.ignoreQueryPrefix?t.replace(/^\?/,""):t).split(e.delimiter,Infinity===e.parameterLimit?void 0:e.parameterLimit),u=-1,s=e.charset;if(e.charsetSentinel)for(r=0;r-1&&(a=g(a)?[a]:a),n[f]=m.call(n,f)?i.combine(n[f],a):a}return n}(t,r):t,o=r.plainObjects?Object.create(null):{},u=Object.keys(n),s=0;s({name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)})))??[]}matchesUrl(t){if(!this.definition.methods.includes("GET"))return!1;const e=this.template.replace(/\/{[^}?]*\?}/g,"(/[^/?]+)?").replace(/{[^}]+}/g,"[^/?]+").replace(/^\w+:\/\//,"");return new RegExp(`^${e}$`).test(t.replace(/\/+$/,"").split("?").shift())}compile(t){return this.parameterSegments.length?this.template.replace(/{([^}?]+)\??}/g,(e,r)=>{if([null,void 0].includes(t[r])&&this.parameterSegments.find(({name:t})=>t===r).required)throw new Error(`Ziggy error: '${r}' parameter is required for route '${this.name}'.`);return encodeURIComponent(t[r]??"")}).replace(/\/+$/,""):this.template}}class N extends String{constructor(t,e,r=!0,n){if(super(),this.t=n??Ziggy??(null===globalThis||void 0===globalThis?void 0:globalThis.Ziggy),this.t={...this.t,absolute:r},t){if(!this.t.routes[t])throw new Error(`Ziggy error: route '${t}' is not in the route list.`);this.i=new S(t,this.t.routes[t],this.t),this.u=this.s(e)}}toString(){const t=Object.keys(this.u).filter(t=>!this.i.parameterSegments.some(({name:e})=>e===t)).filter(t=>"_query"!==t).reduce((t,e)=>({...t,[e]:this.u[e]}),{});return this.i.compile(this.u)+function(t,e){var r,n=t,i=function(t){if(!t)return b;if(null!=t.encoder&&"function"!=typeof t.encoder)throw new TypeError("Encoder has to be a function.");var e=t.charset||b.charset;if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var r=f.default;if(void 0!==t.format){if(!a.call(f.formatters,t.format))throw new TypeError("Unknown format option provided.");r=t.format}var n=f.formatters[r],i=b.filter;return("function"==typeof t.filter||l(t.filter))&&(i=t.filter),{addQueryPrefix:"boolean"==typeof t.addQueryPrefix?t.addQueryPrefix:b.addQueryPrefix,allowDots:void 0===t.allowDots?b.allowDots:!!t.allowDots,charset:e,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:b.charsetSentinel,delimiter:void 0===t.delimiter?b.delimiter:t.delimiter,encode:"boolean"==typeof t.encode?t.encode:b.encode,encoder:"function"==typeof t.encoder?t.encoder:b.encoder,encodeValuesOnly:"boolean"==typeof t.encodeValuesOnly?t.encodeValuesOnly:b.encodeValuesOnly,filter:i,formatter:n,serializeDate:"function"==typeof t.serializeDate?t.serializeDate:b.serializeDate,skipNulls:"boolean"==typeof t.skipNulls?t.skipNulls:b.skipNulls,sort:"function"==typeof t.sort?t.sort:null,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:b.strictNullHandling}}(e);"function"==typeof i.filter?n=(0,i.filter)("",n):l(i.filter)&&(r=i.filter);var o=[];if("object"!=typeof n||null===n)return"";var u=c[e&&e.arrayFormat in c?e.arrayFormat:e&&"indices"in e?e.indices?"indices":"repeat":"indices"];r||(r=Object.keys(n)),i.sort&&r.sort(i.sort);for(var s=0;s0?y+d:""}({...t,...this.u._query},{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:(t,e)=>"boolean"==typeof t?Number(t):e(t)})}current(t,e){const r=this.t.absolute?this.l.host+this.l.pathname:this.l.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"),[n,i]=Object.entries(this.t.routes).find(([e,n])=>new S(t,n,this.t).matchesUrl(r))||[void 0,void 0];if(!t)return n;const o=new RegExp(`^${t.replace(".","\\.").replace("*",".*")}$`).test(n);if([null,void 0].includes(e)||!o)return o;const u=new S(n,i,this.t);e=this.s(e,u);const s=this.h(i);return!(!Object.values(e).every(t=>!t)||Object.values(s).length)||Object.entries(e).every(([t,e])=>s[t]==e)}get l(){var t,e,r;const{host:n="",pathname:i="",search:o=""}="undefined"!=typeof window?window.location:{};return{host:(null===(t=this.t.location)||void 0===t?void 0:t.host)??n,pathname:(null===(e=this.t.location)||void 0===e?void 0:e.pathname)??i,search:(null===(r=this.t.location)||void 0===r?void 0:r.search)??o}}get params(){return this.h(this.t.routes[this.current()])}has(t){return Object.keys(this.t.routes).includes(t)}s(t={},e=this.i){t=["string","number"].includes(typeof t)?[t]:t;const r=e.parameterSegments.filter(({name:t})=>!this.t.defaults[t]);return Array.isArray(t)?t=t.reduce((t,e,n)=>r[n]?{...t,[r[n].name]:e}:{...t,[e]:""},{}):1!==r.length||t[r[0].name]||!t.hasOwnProperty(Object.values(e.bindings)[0])&&!t.hasOwnProperty("id")||(t={[r[0].name]:t}),{...this.p(e),...this.v(t,e.bindings)}}p(t){return t.parameterSegments.filter(({name:t})=>this.t.defaults[t]).reduce((t,{name:e},r)=>({...t,[e]:this.t.defaults[e]}),{})}v(t,e={}){return Object.entries(t).reduce((t,[r,n])=>{if(!n||"object"!=typeof n||Array.isArray(n)||"_query"===r)return{...t,[r]:n};if(!n.hasOwnProperty(e[r])){if(!n.hasOwnProperty("id"))throw new Error(`Ziggy error: object passed as '${r}' parameter is missing route model binding key '${e[r]}'.`);e[r]="id"}return{...t,[r]:n[e[r]]}},{})}h(t){var e;let r=this.l.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"");const n=(t,e="",r)=>{const[n,i]=[t,e].map(t=>t.split(r));return i.reduce((t,e,r)=>/^{[^}?]+\??}$/.test(e)&&n[r]?{...t,[e.replace(/^{|\??}$/g,"")]:n[r]}:t,{})};return{...n(this.l.host,t.domain,"."),...n(r,t.uri,"/"),...E(null===(e=this.l.search)||void 0===e?void 0:e.replace(/^\?/,""))}}valueOf(){return this.toString()}check(t){return this.has(t)}}const R={install:(t,e)=>t.mixin({methods:{route:(t,r,n,i=e)=>function(t,e,r,n){const i=new N(t,e,r,n);return t?i.toString():i}(t,r,n,i)}})};export{R as ZiggyVue}; +function t(t,r){for(var n=0;n1;){var r=t.pop(),n=r.obj[r.prop];if(a(n)){for(var e=[],i=0;i=48&&u<=57||u>=65&&u<=90||u>=97&&u<=122?i+=e.charAt(o):u<128?i+=l[u]:u<2048?i+=l[192|u>>6]+l[128|63&u]:u<55296||u>=57344?i+=l[224|u>>12]+l[128|u>>6&63]+l[128|63&u]:(u=65536+((1023&u)<<10|1023&e.charCodeAt(o+=1)),i+=l[240|u>>18]+l[128|u>>12&63]+l[128|u>>6&63]+l[128|63&u])}return i},isBuffer:function(t){return!(!t||"object"!=typeof t||!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t)))},isRegExp:function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},maybeMap:function(t,r){if(a(t)){for(var n=[],e=0;e-1?t.split(","):t},T=function(t,r,n,e){if(t){var i=n.allowDots?t.replace(/\.([^.[]+)/g,"[$1]"):t,o=/(\[[^[\]]*])/g,u=n.depth>0&&/(\[[^[\]]*])/.exec(i),f=u?i.slice(0,u.index):i,c=[];if(f){if(!n.plainObjects&&S.call(Object.prototype,f)&&!n.allowPrototypes)return;c.push(f)}for(var a=0;n.depth>0&&null!==(u=o.exec(i))&&a=0;--o){var u,f=t[o];if("[]"===f&&n.parseArrays)u=[].concat(i);else{u=n.plainObjects?Object.create(null):{};var c="["===f.charAt(0)&&"]"===f.charAt(f.length-1)?f.slice(1,-1):f,a=parseInt(c,10);n.parseArrays||""!==c?!isNaN(a)&&f!==c&&String(a)===c&&a>=0&&n.parseArrays&&a<=n.arrayLimit?(u=[])[a]=i:u[c]=i:u={0:i}}i=u}return i}(c,r,n,e)}},F=function(){function t(t,r,n){var e;this.name=t,this.definition=r,this.bindings=null!=(e=r.bindings)?e:{},this.config=n}var n=t.prototype;return n.matchesUrl=function(t){if(!this.definition.methods.includes("GET"))return!1;var r=this.template.replace(/\/{[^}?]*\?}/g,"(/[^/?]+)?").replace(/{[^}]+}/g,"[^/?]+").replace(/^\w+:\/\//,"");return new RegExp("^"+r+"$").test(t.replace(/\/+$/,"").split("?").shift())},n.compile=function(t){var r=this;return this.parameterSegments.length?this.template.replace(/{([^}?]+)\??}/g,function(n,e){var i;if([null,void 0].includes(t[e])&&r.parameterSegments.find(function(t){return t.name===e}).required)throw new Error("Ziggy error: '"+e+"' parameter is required for route '"+r.name+"'.");return encodeURIComponent(null!=(i=t[e])?i:"")}).replace(/\/+$/,""):this.template},r(t,[{key:"template",get:function(){return((this.config.absolute?this.definition.domain?""+this.config.url.match(/^\w+:\/\//)[0]+this.definition.domain+(this.config.port?":"+this.config.port:""):this.config.url:"")+"/"+this.definition.uri).replace(/\/+$/,"")}},{key:"parameterSegments",get:function(){var t,r;return null!=(t=null===(r=this.template.match(/{[^}?]+\??}/g))||void 0===r?void 0:r.map(function(t){return{name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)}}))?t:[]}}]),t}(),$=function(t){var e,i;function o(r,e,i,o){var u,f;if(void 0===i&&(i=!0),(f=t.call(this)||this).t=null!=(u=null!=o?o:Ziggy)?u:null===globalThis||void 0===globalThis?void 0:globalThis.Ziggy,f.t=n({},f.t,{absolute:i}),r){if(!f.t.routes[r])throw new Error("Ziggy error: route '"+r+"' is not in the route list.");f.i=new F(r,f.t.routes[r],f.t),f.u=f.l(e)}return f}i=t,(e=o).prototype=Object.create(i.prototype),e.prototype.constructor=e,e.__proto__=i;var u=o.prototype;return u.toString=function(){var t=this,r=Object.keys(this.u).filter(function(r){return!t.i.parameterSegments.some(function(t){return t.name===r})}).filter(function(t){return"_query"!==t}).reduce(function(r,e){var i;return n({},r,((i={})[e]=t.u[e],i))},{});return this.i.compile(this.u)+function(t,r){var n,e=t,i=function(t){if(!t)return E;if(null!=t.encoder&&"function"!=typeof t.encoder)throw new TypeError("Encoder has to be a function.");var r=t.charset||E.charset;if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var n=y.default;if(void 0!==t.format){if(!b.call(y.formatters,t.format))throw new TypeError("Unknown format option provided.");n=t.format}var e=y.formatters[n],i=E.filter;return("function"==typeof t.filter||j(t.filter))&&(i=t.filter),{addQueryPrefix:"boolean"==typeof t.addQueryPrefix?t.addQueryPrefix:E.addQueryPrefix,allowDots:void 0===t.allowDots?E.allowDots:!!t.allowDots,charset:r,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:E.charsetSentinel,delimiter:void 0===t.delimiter?E.delimiter:t.delimiter,encode:"boolean"==typeof t.encode?t.encode:E.encode,encoder:"function"==typeof t.encoder?t.encoder:E.encoder,encodeValuesOnly:"boolean"==typeof t.encodeValuesOnly?t.encodeValuesOnly:E.encodeValuesOnly,filter:i,formatter:e,serializeDate:"function"==typeof t.serializeDate?t.serializeDate:E.serializeDate,skipNulls:"boolean"==typeof t.skipNulls?t.skipNulls:E.skipNulls,sort:"function"==typeof t.sort?t.sort:null,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:E.strictNullHandling}}(r);"function"==typeof i.filter?e=(0,i.filter)("",e):j(i.filter)&&(n=i.filter);var o=[];if("object"!=typeof e||null===e)return"";var u=g[r&&r.arrayFormat in g?r.arrayFormat:r&&"indices"in r?r.indices?"indices":"repeat":"indices"];n||(n=Object.keys(e)),i.sort&&n.sort(i.sort);for(var f=0;f0?l+a:""}(n({},r,this.u._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:function(t,r){return"boolean"==typeof t?Number(t):r(t)}})},u.current=function(t,r){var n=this,e=this.t.absolute?this.s().host+this.s().pathname:this.s().pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"),i=Object.entries(this.t.routes).find(function(r){return new F(t,r[1],n.t).matchesUrl(e)})||[void 0,void 0],o=i[0],u=i[1];if(!t)return o;var f=new RegExp("^"+t.replace(".","\\.").replace("*",".*")+"$").test(o);if([null,void 0].includes(r)||!f)return f;var c=new F(o,u,this.t);r=this.l(r,c);var a=this.v(u);return!(!Object.values(r).every(function(t){return!t})||Object.values(a).length)||Object.entries(r).every(function(t){return a[t[0]]==t[1]})},u.s=function(){var t,r,n,e,i,o,u="undefined"!=typeof window?window.location:{},f=u.host,c=u.pathname,a=u.search;return{host:null!=(t=null===(r=this.t.location)||void 0===r?void 0:r.host)?t:void 0===f?"":f,pathname:null!=(n=null===(e=this.t.location)||void 0===e?void 0:e.pathname)?n:void 0===c?"":c,search:null!=(i=null===(o=this.t.location)||void 0===o?void 0:o.search)?i:void 0===a?"":a}},u.has=function(t){return Object.keys(this.t.routes).includes(t)},u.l=function(t,r){var e=this;void 0===t&&(t={}),void 0===r&&(r=this.i),t=["string","number"].includes(typeof t)?[t]:t;var i=r.parameterSegments.filter(function(t){return!e.t.defaults[t.name]});if(Array.isArray(t))t=t.reduce(function(t,r,e){var o,u;return n({},t,i[e]?((o={})[i[e].name]=r,o):((u={})[r]="",u))},{});else if(1===i.length&&!t[i[0].name]&&(t.hasOwnProperty(Object.values(r.bindings)[0])||t.hasOwnProperty("id"))){var o;(o={})[i[0].name]=t,t=o}return n({},this.p(r),this.h(t,r.bindings))},u.p=function(t){var r=this;return t.parameterSegments.filter(function(t){return r.t.defaults[t.name]}).reduce(function(t,e,i){var o,u=e.name;return n({},t,((o={})[u]=r.t.defaults[u],o))},{})},u.h=function(t,r){return void 0===r&&(r={}),Object.entries(t).reduce(function(t,e){var i,o,u=e[0],f=e[1];if(!f||"object"!=typeof f||Array.isArray(f)||"_query"===u)return n({},t,((o={})[u]=f,o));if(!f.hasOwnProperty(r[u])){if(!f.hasOwnProperty("id"))throw new Error("Ziggy error: object passed as '"+u+"' parameter is missing route model binding key '"+r[u]+"'.");r[u]="id"}return n({},t,((i={})[u]=f[r[u]],i))},{})},u.v=function(t){var r,e=this.s().pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,""),i=function(t,r,e){void 0===r&&(r="");var i=[t,r].map(function(t){return t.split(e)}),o=i[0];return i[1].reduce(function(t,r,e){var i;return/^{[^}?]+\??}$/.test(r)&&o[e]?n({},t,((i={})[r.replace(/^{|\??}$/g,"")]=o[e],i)):t},{})};return n({},i(this.s().host,t.domain,"."),i(e,t.uri,"/"),function(t,r){var n=C;if(""===t||null==t)return n.plainObjects?Object.create(null):{};for(var e="string"==typeof t?function(t,r){var n,e={},i=(r.ignoreQueryPrefix?t.replace(/^\?/,""):t).split(r.delimiter,Infinity===r.parameterLimit?void 0:r.parameterLimit),o=-1,u=r.charset;if(r.charsetSentinel)for(n=0;n-1&&(c=x(c)?[c]:c),e[f]=S.call(e,f)?v.combine(e[f],c):c}return e}(t,n):t,i=n.plainObjects?Object.create(null):{},o=Object.keys(e),u=0;u