@rzl-zone/ziggy-route
Version:
Typed Laravel route generator for any frontend — works with React, Vue, Vanilla JS, and other JavaScript-based stacks.
2 lines (1 loc) • 24.9 kB
JavaScript
;(()=>{var Re=Object.create;var oe=Object.defineProperty;var Ae=Object.getOwnPropertyDescriptor;var Te=Object.getOwnPropertyNames;var $e=Object.getPrototypeOf,Pe=Object.prototype.hasOwnProperty;var M=(a,e)=>()=>(e||a((e={exports:{}}).exports,e),e.exports);var Ce=(a,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Te(e))!Pe.call(a,n)&&n!==t&&oe(a,n,{get:()=>e[n],enumerable:!(r=Ae(e,n))||r.enumerable});return a};var se=(a,e,t)=>(t=a!=null?Re($e(a)):{},Ce(e||!a||!a.__esModule?oe(t,"default",{value:a,enumerable:!0}):t,a));var q=M((dt,ce)=>{"use strict";var Ie=String.prototype.replace,ke=/%20/g,H={RFC1738:"RFC1738",RFC3986:"RFC3986"};ce.exports={default:H.RFC3986,formatters:{RFC1738:function(a){return Ie.call(a,ke,"+")},RFC3986:function(a){return String(a)}},RFC1738:H.RFC1738,RFC3986:H.RFC3986}});var J=M((gt,me)=>{"use strict";var Fe=q(),Y=Object.prototype.hasOwnProperty,A=Array.isArray,N=function(){for(var a=[],e=0;e<256;++e)a.push("%"+((e<16?"0":"")+e.toString(16)).toUpperCase());return a}(),Me=function(e){for(;e.length>1;){var t=e.pop(),r=t.obj[t.prop];if(A(r)){for(var n=[],i=0;i<r.length;++i)typeof r[i]<"u"&&n.push(r[i]);t.obj[t.prop]=n}}},pe=function(e,t){for(var r=t&&t.plainObjects?Object.create(null):{},n=0;n<e.length;++n)typeof e[n]<"u"&&(r[n]=e[n]);return r},De=function a(e,t,r){if(!t)return e;if(typeof t!="object"){if(A(e))e.push(t);else if(e&&typeof e=="object")(r&&(r.plainObjects||r.allowPrototypes)||!Y.call(Object.prototype,t))&&(e[t]=!0);else return[e,t];return e}if(!e||typeof e!="object")return[e].concat(t);var n=e;return A(e)&&!A(t)&&(n=pe(e,r)),A(e)&&A(t)?(t.forEach(function(i,o){if(Y.call(e,o)){var l=e[o];l&&typeof l=="object"&&i&&typeof i=="object"?e[o]=a(l,i,r):e.push(i)}else e[o]=i}),e):Object.keys(t).reduce(function(i,o){var l=t[o];return Y.call(i,o)?i[o]=a(i[o],l,r):i[o]=l,i},n)},Le=function(e,t){return Object.keys(t).reduce(function(r,n){return r[n]=t[n],r},e)},ze=function(a,e,t){var r=a.replace(/\+/g," ");if(t==="iso-8859-1")return r.replace(/%[0-9a-f]{2}/gi,unescape);try{return decodeURIComponent(r)}catch{return r}},Ue=function(e,t,r,n,i){if(e.length===0)return e;var o=e;if(typeof e=="symbol"?o=Symbol.prototype.toString.call(e):typeof e!="string"&&(o=String(e)),r==="iso-8859-1")return escape(o).replace(/%u[0-9a-f]{4}/gi,function(f){return"%26%23"+parseInt(f.slice(2),16)+"%3B"});for(var l="",u=0;u<o.length;++u){var s=o.charCodeAt(u);if(s===45||s===46||s===95||s===126||s>=48&&s<=57||s>=65&&s<=90||s>=97&&s<=122||i===Fe.RFC1738&&(s===40||s===41)){l+=o.charAt(u);continue}if(s<128){l=l+N[s];continue}if(s<2048){l=l+(N[192|s>>6]+N[128|s&63]);continue}if(s<55296||s>=57344){l=l+(N[224|s>>12]+N[128|s>>6&63]+N[128|s&63]);continue}u+=1,s=65536+((s&1023)<<10|o.charCodeAt(u)&1023),l+=N[240|s>>18]+N[128|s>>12&63]+N[128|s>>6&63]+N[128|s&63]}return l},_e=function(e){for(var t=[{obj:{o:e},prop:"o"}],r=[],n=0;n<t.length;++n)for(var i=t[n],o=i.obj[i.prop],l=Object.keys(o),u=0;u<l.length;++u){var s=l[u],f=o[s];typeof f=="object"&&f!==null&&r.indexOf(f)===-1&&(t.push({obj:o,prop:s}),r.push(f))}return Me(t),e},Be=function(e){return Object.prototype.toString.call(e)==="[object RegExp]"},qe=function(e){return!e||typeof e!="object"?!1:!!(e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer(e))},Ve=function(e,t){return[].concat(e,t)},Ke=function(e,t){if(A(e)){for(var r=[],n=0;n<e.length;n+=1)r.push(t(e[n]));return r}return t(e)};me.exports={arrayToObject:pe,assign:Le,combine:Ve,compact:_e,decode:ze,encode:Ue,isBuffer:qe,isRegExp:Be,maybeMap:Ke,merge:De}});var be=M((ht,ye)=>{"use strict";var X=J(),L=q(),We=Object.prototype.hasOwnProperty,de={brackets:function(e){return e+"[]"},comma:"comma",indices:function(e,t){return e+"["+t+"]"},repeat:function(e){return e}},T=Array.isArray,Ge=String.prototype.split,Qe=Array.prototype.push,he=function(a,e){Qe.apply(a,T(e)?e:[e])},Ze=Date.prototype.toISOString,ge=L.default,w={addQueryPrefix:!1,allowDots:!1,charset:"utf-8",charsetSentinel:!1,delimiter:"&",encode:!0,encoder:X.encode,encodeValuesOnly:!1,format:ge,formatter:L.formatters[ge],indices:!1,serializeDate:function(e){return Ze.call(e)},skipNulls:!1,strictNullHandling:!1},He=function(e){return typeof e=="string"||typeof e=="number"||typeof e=="boolean"||typeof e=="symbol"||typeof e=="bigint"},Ye=function a(e,t,r,n,i,o,l,u,s,f,d,m,b,p){var c=e;if(typeof l=="function"?c=l(t,c):c instanceof Date?c=f(c):r==="comma"&&T(c)&&(c=X.maybeMap(c,function(Q){return Q instanceof Date?f(Q):Q})),c===null){if(n)return o&&!b?o(t,w.encoder,p,"key",d):t;c=""}if(He(c)||X.isBuffer(c)){if(o){var z=b?t:o(t,w.encoder,p,"key",d);if(r==="comma"&&b){for(var re=Ge.call(String(c),","),ne="",U=0;U<re.length;++U)ne+=(U===0?"":",")+m(o(re[U],w.encoder,p,"value",d));return[m(z)+"="+ne]}return[m(z)+"="+m(o(c,w.encoder,p,"value",d))]}return[m(t)+"="+m(String(c))]}var W=[];if(typeof c>"u")return W;var F;if(r==="comma"&&T(c))F=[{value:c.length>0?c.join(",")||null:void 0}];else if(T(l))F=l;else{var ae=Object.keys(c);F=u?ae.sort(u):ae}for(var G=0;G<F.length;++G){var R=F[G],ie=typeof R=="object"&&typeof R.value<"u"?R.value:c[R];if(!(i&&ie===null)){var Oe=T(c)?typeof r=="function"?r(t,R):t:t+(s?"."+R:"["+R+"]");he(W,a(ie,Oe,r,n,i,o,l,u,s,f,d,m,b,p))}}return W},Je=function(e){if(!e)return w;if(e.encoder!==null&&typeof e.encoder<"u"&&typeof e.encoder!="function")throw new TypeError("Encoder has to be a function.");var t=e.charset||w.charset;if(typeof e.charset<"u"&&e.charset!=="utf-8"&&e.charset!=="iso-8859-1")throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var r=L.default;if(typeof e.format<"u"){if(!We.call(L.formatters,e.format))throw new TypeError("Unknown format option provided.");r=e.format}var n=L.formatters[r],i=w.filter;return(typeof e.filter=="function"||T(e.filter))&&(i=e.filter),{addQueryPrefix:typeof e.addQueryPrefix=="boolean"?e.addQueryPrefix:w.addQueryPrefix,allowDots:typeof e.allowDots>"u"?w.allowDots:!!e.allowDots,charset:t,charsetSentinel:typeof e.charsetSentinel=="boolean"?e.charsetSentinel:w.charsetSentinel,delimiter:typeof e.delimiter>"u"?w.delimiter:e.delimiter,encode:typeof e.encode=="boolean"?e.encode:w.encode,encoder:typeof e.encoder=="function"?e.encoder:w.encoder,encodeValuesOnly:typeof e.encodeValuesOnly=="boolean"?e.encodeValuesOnly:w.encodeValuesOnly,filter:i,format:r,formatter:n,serializeDate:typeof e.serializeDate=="function"?e.serializeDate:w.serializeDate,skipNulls:typeof e.skipNulls=="boolean"?e.skipNulls:w.skipNulls,sort:typeof e.sort=="function"?e.sort:null,strictNullHandling:typeof e.strictNullHandling=="boolean"?e.strictNullHandling:w.strictNullHandling}};ye.exports=function(a,e){var t=a,r=Je(e),n,i;typeof r.filter=="function"?(i=r.filter,t=i("",t)):T(r.filter)&&(i=r.filter,n=i);var o=[];if(typeof t!="object"||t===null)return"";var l;e&&e.arrayFormat in de?l=e.arrayFormat:e&&"indices"in e?l=e.indices?"indices":"repeat":l="indices";var u=de[l];n||(n=Object.keys(t)),r.sort&&n.sort(r.sort);for(var s=0;s<n.length;++s){var f=n[s];r.skipNulls&&t[f]===null||he(o,Ye(t[f],f,u,r.strictNullHandling,r.skipNulls,r.encode?r.encoder:null,r.filter,r.sort,r.allowDots,r.serializeDate,r.format,r.formatter,r.encodeValuesOnly,r.charset))}var d=o.join(r.delimiter),m=r.addQueryPrefix===!0?"?":"";return r.charsetSentinel&&(r.charset==="iso-8859-1"?m+="utf8=%26%2310003%3B&":m+="utf8=%E2%9C%93&"),d.length>0?m+d:""}});var Ee=M((yt,ve)=>{"use strict";var k=J(),ee=Object.prototype.hasOwnProperty,Xe=Array.isArray,v={allowDots:!1,allowPrototypes:!1,arrayLimit:20,charset:"utf-8",charsetSentinel:!1,comma:!1,decoder:k.decode,delimiter:"&",depth:5,ignoreQueryPrefix:!1,interpretNumericEntities:!1,parameterLimit:1e3,parseArrays:!0,plainObjects:!1,strictNullHandling:!1},et=function(a){return a.replace(/&#(\d+);/g,function(e,t){return String.fromCharCode(parseInt(t,10))})},we=function(a,e){return a&&typeof a=="string"&&e.comma&&a.indexOf(",")>-1?a.split(","):a},tt="utf8=%26%2310003%3B",rt="utf8=%E2%9C%93",nt=function(e,t){var r={},n=t.ignoreQueryPrefix?e.replace(/^\?/,""):e,i=t.parameterLimit===1/0?void 0:t.parameterLimit,o=n.split(t.delimiter,i),l=-1,u,s=t.charset;if(t.charsetSentinel)for(u=0;u<o.length;++u)o[u].indexOf("utf8=")===0&&(o[u]===rt?s="utf-8":o[u]===tt&&(s="iso-8859-1"),l=u,u=o.length);for(u=0;u<o.length;++u)if(u!==l){var f=o[u],d=f.indexOf("]="),m=d===-1?f.indexOf("="):d+1,b,p;m===-1?(b=t.decoder(f,v.decoder,s,"key"),p=t.strictNullHandling?null:""):(b=t.decoder(f.slice(0,m),v.decoder,s,"key"),p=k.maybeMap(we(f.slice(m+1),t),function(c){return t.decoder(c,v.decoder,s,"value")})),p&&t.interpretNumericEntities&&s==="iso-8859-1"&&(p=et(p)),f.indexOf("[]=")>-1&&(p=Xe(p)?[p]:p),ee.call(r,b)?r[b]=k.combine(r[b],p):r[b]=p}return r},at=function(a,e,t,r){for(var n=r?e:we(e,t),i=a.length-1;i>=0;--i){var o,l=a[i];if(l==="[]"&&t.parseArrays)o=[].concat(n);else{o=t.plainObjects?Object.create(null):{};var u=l.charAt(0)==="["&&l.charAt(l.length-1)==="]"?l.slice(1,-1):l,s=parseInt(u,10);!t.parseArrays&&u===""?o={0:n}:!isNaN(s)&&l!==u&&String(s)===u&&s>=0&&t.parseArrays&&s<=t.arrayLimit?(o=[],o[s]=n):u!=="__proto__"&&(o[u]=n)}n=o}return n},it=function(e,t,r,n){if(e){var i=r.allowDots?e.replace(/\.([^.[]+)/g,"[$1]"):e,o=/(\[[^[\]]*])/,l=/(\[[^[\]]*])/g,u=r.depth>0&&o.exec(i),s=u?i.slice(0,u.index):i,f=[];if(s){if(!r.plainObjects&&ee.call(Object.prototype,s)&&!r.allowPrototypes)return;f.push(s)}for(var d=0;r.depth>0&&(u=l.exec(i))!==null&&d<r.depth;){if(d+=1,!r.plainObjects&&ee.call(Object.prototype,u[1].slice(1,-1))&&!r.allowPrototypes)return;f.push(u[1])}return u&&f.push("["+i.slice(u.index)+"]"),at(f,t,r,n)}},ot=function(e){if(!e)return v;if(e.decoder!==null&&e.decoder!==void 0&&typeof e.decoder!="function")throw new TypeError("Decoder has to be a function.");if(typeof e.charset<"u"&&e.charset!=="utf-8"&&e.charset!=="iso-8859-1")throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var t=typeof e.charset>"u"?v.charset:e.charset;return{allowDots:typeof e.allowDots>"u"?v.allowDots:!!e.allowDots,allowPrototypes:typeof e.allowPrototypes=="boolean"?e.allowPrototypes:v.allowPrototypes,arrayLimit:typeof e.arrayLimit=="number"?e.arrayLimit:v.arrayLimit,charset:t,charsetSentinel:typeof e.charsetSentinel=="boolean"?e.charsetSentinel:v.charsetSentinel,comma:typeof e.comma=="boolean"?e.comma:v.comma,decoder:typeof e.decoder=="function"?e.decoder:v.decoder,delimiter:typeof e.delimiter=="string"||k.isRegExp(e.delimiter)?e.delimiter:v.delimiter,depth:typeof e.depth=="number"||e.depth===!1?+e.depth:v.depth,ignoreQueryPrefix:e.ignoreQueryPrefix===!0,interpretNumericEntities:typeof e.interpretNumericEntities=="boolean"?e.interpretNumericEntities:v.interpretNumericEntities,parameterLimit:typeof e.parameterLimit=="number"?e.parameterLimit:v.parameterLimit,parseArrays:e.parseArrays!==!1,plainObjects:typeof e.plainObjects=="boolean"?e.plainObjects:v.plainObjects,strictNullHandling:typeof e.strictNullHandling=="boolean"?e.strictNullHandling:v.strictNullHandling}};ve.exports=function(a,e){var t=ot(e);if(a===""||a===null||typeof a>"u")return t.plainObjects?Object.create(null):{};for(var r=typeof a=="string"?nt(a,t):a,n=t.plainObjects?Object.create(null):{},i=Object.keys(r),o=0;o<i.length;++o){var l=i[o],u=it(l,r[l],t,typeof a=="string");n=k.merge(n,u,t)}return k.compact(n)}});var te=M((bt,je)=>{"use strict";var st=be(),lt=Ee(),ut=q();je.exports={formats:ut,parse:lt,stringify:st}});function j(a){return Array.isArray(a)}var ue=a=>typeof a=="number"&&!Number.isNaN(a),h=a=>typeof a=="string";var _=(a,e)=>{if(!h(a))return!0;S(e)||(e={});let{trim:t=!0}=e;return t&&(a=a.trim()),a===""};var Z=a=>typeof a=="boolean";var B=a=>a instanceof Error;function S(a){return typeof a=="object"&&!O(a)&&!j(a)}var D=a=>a===null,x=a=>typeof a>"u";var le=a=>a.replace(/([a-z])([A-Z])/g,"$1 $2").replace(/([a-zA-Z])(\d)/g,"$1 $2").replace(/(\d)([a-zA-Z])/g,"$1 $2").replace(/\s+/g," ").trim().replace(/\w\S*/g,e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()),y=a=>{let e={string:"String",number:"Number",boolean:"Boolean",bigint:"BigInt",symbol:"Symbol",undefined:"Undefined",null:"Null",object:"Object",array:"Array",function:"Function",regexp:"RegExp",date:"Date",error:"Error",int8array:"Int8Array",uint8array:"Uint8Array",uint8clampedarray:"Uint8ClampedArray",int16array:"Int16Array",uint16array:"Uint16Array",int32array:"Int32Array",uint32array:"Uint32Array",float32array:"Float32Array",float64array:"Float64Array",bigint64array:"BigInt64Array",biguint64array:"BigUint64Array",arraybuffer:"ArrayBuffer",sharedarraybuffer:"SharedArrayBuffer",dataview:"DataView",map:"Map",set:"Set",weakmap:"WeakMap",weakset:"WeakSet",promise:"Promise",generator:"Generator",generatorfunction:"GeneratorFunction",asyncfunction:"AsyncFunction",finalizationregistry:"FinalizationRegistry",weakref:"WeakRef"};if(a===null)return e.null;let t=typeof a;if(t!=="object"&&t!=="function")return le(e[t]??t);let r=Object.prototype.toString.call(a).slice(8,-1),n=e[r.toLowerCase()];return n&&(r=n),le(r)};function I(a){return typeof a=="object"&&!O(a)}var pt=Function.prototype.toString;function O(a){return a==null}var fe=()=>typeof window>"u"||typeof document>"u";var xe=se(te(),1);var $={PACKAGE:{NPM_NAME:"@rzl-zone/ziggy-route",PACKAGIST_NAME:"rzl-zone/ziggy-route",PREFIX:{NAME:"RZL ZIGGY"}},REPO:{LINK:"https://github.com/rzl-zone/ziggy-route"}};var Se=se(te(),1);var g=class extends Error{constructor(t,r,n){let i=n?.trim()||$.PACKAGE.PREFIX.NAME,o=t.trim();super(`${i} - ${o}`);this.originalError=r;this.name="RouterConfigError",Error.captureStackTrace&&Error.captureStackTrace(this,E)}},E=class a extends Error{constructor(t,r,n){let i=n?.trim()||$.PACKAGE.PREFIX.NAME,o=t.trim();super(`${i} - ${o}`);this.originalError=r;this.name="RoutePropsError",Error.captureStackTrace&&Error.captureStackTrace(this,a)}};var P=class{name;definition;config;wheres;bindings={};constructor(e,t,r){this.name=e,this.definition=t,this.bindings=t?.bindings??{},this.wheres=t?.wheres??{},this.config=r}get template(){let e=`${this.origin}/${this.definition?.uri}`.replace(/\/+$/,"");return _(e)?"/":e}get origin(){if(!this.config?.absolute)return"";if(this.definition?.domain){let e=this.config.url.match(/^\w+:\/\//);if(!e)throw new g("Invalid `config.url` missing protocol (e.g., http:// or https://)");return`${e[0]}${this.definition.domain}${this.config.port?`:${this.config.port}`:""}`}return this.config.url}get parameterSegments(){return this.template.match(/{[^}?]+\??}/g)?.map(e=>({name:e.replace(/{|\??}/g,""),required:!/\?}$/.test(e)}))??[]}matchesUrl(e){if(!this.definition?.methods.includes("GET"))return!1;let t=this.template.replace(/[.*+$()[\]]/g,"\\$&").replace(/(\/?){([^}?]*)(\??)}/g,(o,l,u,s)=>{let f=`(?<${u}>${this.wheres[u]?.replace(/(^\^)|(\$$)/g,"")||"[^/?]+"})`;return s?`(${l}${f})?`:`${l}${f}`}).replace(/^\w+:\/\//,""),[r,n]=e.replace(/^\w+:\/\//,"").split("?"),i=new RegExp(`^${t}/?$`).exec(r)??new RegExp(`^${t}/?$`).exec(decodeURI(r));if(i){for(let o in i.groups)i.groups[o]=h(i.groups[o])?decodeURIComponent(i.groups[o]):i.groups[o];return{params:i.groups,query:(0,Se.parse)(n)}}return!1}compile(e={}){let t=this.template.replace(/{([^}?]+)(\??)}/g,(n,i,o)=>{let l=e[i];if(!o&&O(l))throw new E(`Invalid \`${i}\` parameter is required for route \`${this.name}\`.`);if(this.wheres[i]){let u=new RegExp(`^${this.wheres[i]}$`);if(h(l)&&!u.test(l))throw new E(`Invalid \`${i}\` parameter \`${l}\` does not match required format \`${this.wheres[i]}\` for route \`${this.name}\`.`)}return encodeURI(h(l)?l:"").replace(/%7C/g,"|").replace(/%25/g,"%").replace(/\$/g,"%24")}),r=t;if(this.config?.absolute&&t.includes("://")){let[n,i]=t.split("://");r=n+"://"+i.replace(/\/{2,}/g,"/")}else r=t.replace(/\/{2,}/g,"/");return r==="/"?"/":r.replace(/\/+$/,"")}};var V=class a{absolute;url;port;defaults;routes;location;constructor(e){this.absolute=e.absolute,this.url=e.url,this.port=e.port,this.defaults=e.defaults,this.routes=e.routes,this.location=e.location}static isRouterConfigRaw(e){if(O(e))return!1;let t=e;if(!S(t))throw new g(`Invalid \`route()\` \`config\` properties detected. Ensure that \`appRoutes\` is defined globally or passed as a valid config object, \`config\` need object type but you passing as \`${y(t)}\`.`);if(!h(t.url))throw new g(`Invalid \`route()\` \`config.url\` properties detected. Ensure that \`appRoutes\` is defined globally or passed as a valid \`config.url\`, \`config.url\` need string or null type but you passing as \`${y(t.url)}\`.`);if(!D(t.port)&&!ue(t.port))throw new g(`Invalid \`route()\` \`config.port\` properties detected. Ensure that \`appRoutes\` is defined globally or passed as a valid \`config.port\`, \`config.port\` need number or null type but you passing as \`${y(t.port)}\`.`);if(!I(t.defaults))throw new g(`Invalid \`route()\` \`config.defaults\` properties detected. Ensure that \`appRoutes\` is defined globally or passed as a valid \`config.defaults\`, \`config.defaults\` need array or object type but you passing as \`${y(t.defaults)}\`.`);if(!S(t.routes))throw new g(`Invalid \`route()\` \`config.routes\` properties detected. Ensure that \`appRoutes\` is defined globally or passed as a valid \`config.routes\`, \`config.routes\` need object type but you passing as \`${j(t.routes)?"Array":y(t.routes)}\`.`);if("location"in t){let r=t.location;if(h(r))throw new g(`Invalid \`route()\` \`config.location\` properties detected. Ensure that \`appRoutes\` is defined globally or passed as a valid config object, \`config.location\` need object type\`{ host?: string | undefined; pathname?: string | undefined ;search?: string | undefined; }\` but you passing as \`${y(r)}\`.`);if(!S(r))throw new g(`Invalid \`route()\` \`config.location\` properties detected. Ensure that \`appRoutes\` is defined globally or passed as a valid \`config.location\`, \`config.location\` need object type but you passing as \`${y(r)}\`.`);let n=r;if("host"in n&&!h(n.host)&&!x(n.host))throw new g(`Invalid \`route()\` \`config.location.host\` properties detected. Ensure that \`appRoutes\` is defined globally or passed as a valid \`config.location.host\`, \`config.location.host\` need string or undefined type but you passing as \`${y(n.host)}\`.`);if("pathname"in n&&!h(n.pathname)&&!x(n.pathname))throw new g(`Invalid \`route()\` \`config.location.pathname\` properties detected. Ensure that \`appRoutes\` is defined globally or passed as a valid \`config.location.pathname\`, \`config.location.pathname\` need string or undefined type but you passing as \`${y(n.pathname)}\`.`);if("search"in n&&!h(n.search)&&!x(n.search))throw new g(`Invalid \`route()\` \`config.location.search\` properties detected. Ensure that \`appRoutes\` is defined globally or passed as a valid \`config.location.search\`, \`config.location.search\` need string or undefined type but you passing as \`${y(n.search)}\`.`)}return!0}static validateAndWrap(e){try{if(e instanceof a)return e;if(!this.isRouterConfigRaw(e))throw new g("Invalid `route()` config properties detected. Ensure that `appRoutes` is defined globally or passed as a valid config object.");return new a(e)}catch(t){throw t instanceof g?t:new g("Invalid `route()` config properties detected. Ensure that `appRoutes` is defined globally or passed as a valid config object.",B(t)?t:new Error(String(t)))}}};var{REPO:C,PACKAGE:ft}=$,K=class extends String{_config;_route;_params={};constructor(e,t,r=!1,n){if(super(),_(e))throw new E(`Invalid \`route()\` "name" value it cannot be an empty string. Use \`undefined\` if you don't want to provide a name. Make sure to call a valid \`Router\` instance method, or you'll encounter an error. Learn more: ${C.LINK}#%EF%B8%8F-warning-calling-route-without-arguments.`);if(!D(r)&&!Z(r))throw new E(`Invalid \`route()\` option "absolute" must be a boolean or undefined, but received type "${y(r)}". Learn more: ${C.LINK}#absolute-url.`);r=!!r;let i=this.safeValidateRouterConfig(n||(x(appRoutes)?globalThis.appRoutes:appRoutes));if(this._config={...i,absolute:r},e){if(!this._config.routes[e])throw new E(`Route name '${e}' is not in the route list.`);this._route=new P(e,this._config.routes[e],this._config),this._params=this._parse(t)}}safeValidateRouterConfig(e){try{return V.validateAndWrap(e)}catch(t){throw t instanceof g?t:new Error(`${ft.PREFIX.NAME} - Unknown error while validating \`route()\` config`,{cause:B(t)?t:void 0})}}_unresolve(e){e?this._config.absolute&&e.startsWith("/")&&(e=this._location().host+e):e=this._currentUrl();let t={},[r,n]=Object.entries(this._config.routes).find(([i,o])=>t=new P(i,o,this._config).matchesUrl(e))||[void 0,void 0];return{name:r,...t,route:n}}_currentUrl(){let{host:e,pathname:t,search:r}=this._location();return(this._config.absolute?e+t:t.replace(this._config.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"))+r}_location(){let{host:e="",pathname:t="",search:r=""}=fe()?{}:window.location;return{host:this._config.location?.host??e,pathname:this._config.location?.pathname??t,search:this._config.location?.search??r}}_parse(e={},t=this._route){if(!I(e))throw new E(`Invalid \`route()\` \`params\` property detected. Value \`params\` need object or array type but you passing as \`${y(e)}\`. More info \u2192 ${C.LINK}#parameters`);e??={},e=["string","number"].includes(typeof e)?[e]:e;let r=t?.parameterSegments.filter(({name:n})=>!this._config.defaults[n]);return j(e)?e=e.reduce((n,i,o)=>r?.[o]?{...n,[r[o].name]:i}:I(i)?{...n,...i}:{...n,...h(i)?{[i]:""}:{}},{}):r?.length===1&&!e[r?.[0].name]&&(t&&e.hasOwnProperty(Object.values(t.bindings)[0])||e.hasOwnProperty("id"))&&(e={[r?.[0].name]:e}),{...this._defaults(t),...this._substituteBindings(e,t)}}_defaults(e){return e?.parameterSegments.filter(({name:t})=>this._config.defaults[t]).reduce((t,{name:r},n)=>({...t,[r]:this._config.defaults[r]}),{})}_substituteBindings(e,t=this._route){return Object.entries(e).reduce((r,[n,i])=>{if(!i||typeof i!="object"||j(i)||!t?.parameterSegments.some(({name:o})=>o===n))return{...r,[n]:i};if(!i.hasOwnProperty(t.bindings[n]))if(i.hasOwnProperty("id"))t.bindings[n]="id";else throw new E(`Object passed as '${n}' parameter is missing route model binding key '${t.bindings[n]}'. More info \u2192 ${C.LINK}#parameters`);return{...r,[n]:i[t.bindings[n]]}},{})}get params(){let{params:e,query:t}=this._unresolve(),r={};for(let n in t){let i=t[n];h(i)?r[n]=i:j(i)?r[n]=i.filter(h).join(","):i&&S(i)&&(r[n]=JSON.stringify(i))}return{...e,...r}}get routeParams(){return this._unresolve().params||{}}get queryParams(){return this._unresolve().query||{}}has(e){if(!h(e))throw new E(`Invalid \`route().has(...)\` the \`name\` parameter must be a string, but received \`${y(e)}\`.`);return this._config.routes.hasOwnProperty(e)}current(e,t={}){if(e&&!h(e))throw new E(`Invalid \`route().current(...)\` \`name\` property detected. Value \`name\` need string type but you passing as \`${y(e)}\`.`);if(t&&!I(t))throw new E(`Invalid \`params\` value passed to \`route().current(...)\`, expected a object or array (e.g., { foo: "bar" } or [{"foo": "bar"}]), but received \`${y(t)}\`. Learn more: ${C.LINK}#routecurrent-optionally-accepts-parameters-as-its-second-argument-and-will-check-that-their-values-also-match-in-the-current-url.`);t??={};let{name:r,params:n,query:i,route:o}=this._unresolve();if(!e)return r;let l=h(r)&&new RegExp(`^${e.replace(/\./g,"\\.").replace(/\*/g,".*")}$`).test(r);if(O(t)||!l)return l;let u=new P(r,o,this._config);t=this._parse(t,u);let s={...n,...i};if(Object.values(t).every(d=>!d)&&!Object.values(s).some(d=>!x(d)))return!0;let f=(d,m)=>Object.entries(d).every(([b,p])=>{if(j(p)&&j(m[b])){let c=m[b];return p.every(z=>c.includes(z))}return S(p)&&S(m[b])?f(p,m[b]):m[b]==p});return f(t,s)}toString(){let e=this._route,t=this._params??={};if(!e)throw new E(`Function route() was called without a name but used as a string. Pass a valid route name, or use route().current() to get the current route name \u2014 or route().current('dashboard') to check if it matches. More info \u2192 ${C.LINK}#%EF%B8%8F-warning-calling-route-without-arguments`);let r=Object.keys(t).filter(i=>!e.parameterSegments.some(({name:o})=>o===i)).filter(i=>i!=="_query").reduce((i,o)=>({...i,[o]:t[o]}),{}),n=t._query;if(!x(n)&&(!S(n)||D(n)||j(n)))throw new E(`Invalid \`params._query\` value passed to \`route()\`, expected a plain object (e.g., { foo: "bar" }), but received \`${y(n)}\`. More info \u2192 ${C.LINK}#query-parameters`);return e.compile(t)+(0,xe.stringify)({...r,...n},{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:(i,o)=>Z(i)?String(+i):o(i)})}valueOf(){return this.toString()}};function Ne(a,e,t=!1,r){let n=new K(a,e,t,r);return a?n.toString():n}if(!x(globalThis.route)){let{PACKAGE:a}=$;console.warn(`[${a.PREFIX.NAME}]: \u26A0\uFE0F Detected existing global \`route\`. It will be overridden by '${a.NPM_NAME}' route implementation.`)}globalThis.route=Ne;})();