momentum-trail
Version:
Fully typed frontend route helper for Laravel apps
631 lines (630 loc) • 24.3 kB
JavaScript
var ae = String.prototype.replace, ue = /%20/g, D = {
RFC1738: "RFC1738",
RFC3986: "RFC3986"
}, H = {
default: D.RFC3986,
formatters: {
RFC1738: function(a) {
return ae.call(a, ue, "+");
},
RFC3986: function(a) {
return String(a);
}
},
RFC1738: D.RFC1738,
RFC3986: D.RFC3986
}, oe = H, $ = Object.prototype.hasOwnProperty, O = Array.isArray, b = function() {
for (var a = [], e = 0; e < 256; ++e)
a.push("%" + ((e < 16 ? "0" : "") + e.toString(16)).toUpperCase());
return a;
}(), le = function(e) {
for (; e.length > 1; ) {
var r = e.pop(), t = r.obj[r.prop];
if (O(t)) {
for (var f = [], n = 0; n < t.length; ++n)
typeof t[n] < "u" && f.push(t[n]);
r.obj[r.prop] = f;
}
}
}, Y = function(e, r) {
for (var t = r && r.plainObjects ? /* @__PURE__ */ Object.create(null) : {}, f = 0; f < e.length; ++f)
typeof e[f] < "u" && (t[f] = e[f]);
return t;
}, fe = function a(e, r, t) {
if (!r)
return e;
if (typeof r != "object") {
if (O(e))
e.push(r);
else if (e && typeof e == "object")
(t && (t.plainObjects || t.allowPrototypes) || !$.call(Object.prototype, r)) && (e[r] = !0);
else
return [e, r];
return e;
}
if (!e || typeof e != "object")
return [e].concat(r);
var f = e;
return O(e) && !O(r) && (f = Y(e, t)), O(e) && O(r) ? (r.forEach(function(n, i) {
if ($.call(e, i)) {
var u = e[i];
u && typeof u == "object" && n && typeof n == "object" ? e[i] = a(u, n, t) : e.push(n);
} else
e[i] = n;
}), e) : Object.keys(r).reduce(function(n, i) {
var u = r[i];
return $.call(n, i) ? n[i] = a(n[i], u, t) : n[i] = u, n;
}, f);
}, ce = function(e, r) {
return Object.keys(r).reduce(function(t, f) {
return t[f] = r[f], t;
}, e);
}, se = function(a, e, r) {
var t = a.replace(/\+/g, " ");
if (r === "iso-8859-1")
return t.replace(/%[0-9a-f]{2}/gi, unescape);
try {
return decodeURIComponent(t);
} catch {
return t;
}
}, de = function(e, r, t, f, n) {
if (e.length === 0)
return e;
var i = e;
if (typeof e == "symbol" ? i = Symbol.prototype.toString.call(e) : typeof e != "string" && (i = String(e)), t === "iso-8859-1")
return escape(i).replace(/%u[0-9a-f]{4}/gi, function(c) {
return "%26%23" + parseInt(c.slice(2), 16) + "%3B";
});
for (var u = "", l = 0; l < i.length; ++l) {
var o = i.charCodeAt(l);
if (o === 45 || o === 46 || o === 95 || o === 126 || o >= 48 && o <= 57 || o >= 65 && o <= 90 || o >= 97 && o <= 122 || n === oe.RFC1738 && (o === 40 || o === 41)) {
u += i.charAt(l);
continue;
}
if (o < 128) {
u = u + b[o];
continue;
}
if (o < 2048) {
u = u + (b[192 | o >> 6] + b[128 | o & 63]);
continue;
}
if (o < 55296 || o >= 57344) {
u = u + (b[224 | o >> 12] + b[128 | o >> 6 & 63] + b[128 | o & 63]);
continue;
}
l += 1, o = 65536 + ((o & 1023) << 10 | i.charCodeAt(l) & 1023), u += b[240 | o >> 18] + b[128 | o >> 12 & 63] + b[128 | o >> 6 & 63] + b[128 | o & 63];
}
return u;
}, he = function(e) {
for (var r = [{ obj: { o: e }, prop: "o" }], t = [], f = 0; f < r.length; ++f)
for (var n = r[f], i = n.obj[n.prop], u = Object.keys(i), l = 0; l < u.length; ++l) {
var o = u[l], c = i[o];
typeof c == "object" && c !== null && t.indexOf(c) === -1 && (r.push({ obj: i, prop: o }), t.push(c));
}
return le(r), e;
}, pe = function(e) {
return Object.prototype.toString.call(e) === "[object RegExp]";
}, ye = function(e) {
return !e || typeof e != "object" ? !1 : !!(e.constructor && e.constructor.isBuffer && e.constructor.isBuffer(e));
}, ve = function(e, r) {
return [].concat(e, r);
}, me = function(e, r) {
if (O(e)) {
for (var t = [], f = 0; f < e.length; f += 1)
t.push(r(e[f]));
return t;
}
return r(e);
}, J = {
arrayToObject: Y,
assign: ce,
combine: ve,
compact: he,
decode: se,
encode: de,
isBuffer: ye,
isRegExp: pe,
maybeMap: me,
merge: fe
}, L = J, E = H, ge = Object.prototype.hasOwnProperty, Z = {
brackets: function(e) {
return e + "[]";
},
comma: "comma",
indices: function(e, r) {
return e + "[" + r + "]";
},
repeat: function(e) {
return e;
}
}, j = Array.isArray, be = String.prototype.split, we = Array.prototype.push, ee = function(a, e) {
we.apply(a, j(e) ? e : [e]);
}, Oe = Date.prototype.toISOString, V = E.default, m = {
addQueryPrefix: !1,
allowDots: !1,
charset: "utf-8",
charsetSentinel: !1,
delimiter: "&",
encode: !0,
encoder: L.encode,
encodeValuesOnly: !1,
format: V,
formatter: E.formatters[V],
indices: !1,
serializeDate: function(e) {
return Oe.call(e);
},
skipNulls: !1,
strictNullHandling: !1
}, je = function(e) {
return typeof e == "string" || typeof e == "number" || typeof e == "boolean" || typeof e == "symbol" || typeof e == "bigint";
}, xe = function a(e, r, t, f, n, i, u, l, o, c, d, y, p, s) {
var h = e;
if (typeof u == "function" ? h = u(r, h) : h instanceof Date ? h = c(h) : t === "comma" && j(h) && (h = L.maybeMap(h, function(C) {
return C instanceof Date ? c(C) : C;
})), h === null) {
if (f)
return i && !p ? i(r, m.encoder, s, "key", d) : r;
h = "";
}
if (je(h) || L.isBuffer(h)) {
if (i) {
var z = p ? r : i(r, m.encoder, s, "key", d);
if (t === "comma" && p) {
for (var I = be.call(String(h), ","), U = "", N = 0; N < I.length; ++N)
U += (N === 0 ? "" : ",") + y(i(I[N], m.encoder, s, "value", d));
return [y(z) + "=" + U];
}
return [y(z) + "=" + y(i(h, m.encoder, s, "value", d))];
}
return [y(r) + "=" + y(String(h))];
}
var R = [];
if (typeof h > "u")
return R;
var P;
if (t === "comma" && j(h))
P = [{ value: h.length > 0 ? h.join(",") || null : void 0 }];
else if (j(u))
P = u;
else {
var q = Object.keys(h);
P = l ? q.sort(l) : q;
}
for (var A = 0; A < P.length; ++A) {
var w = P[A], M = typeof w == "object" && typeof w.value < "u" ? w.value : h[w];
if (!(n && M === null)) {
var ie = j(h) ? typeof t == "function" ? t(r, w) : r : r + (o ? "." + w : "[" + w + "]");
ee(R, a(
M,
ie,
t,
f,
n,
i,
u,
l,
o,
c,
d,
y,
p,
s
));
}
}
return R;
}, Se = function(e) {
if (!e)
return m;
if (e.encoder !== null && typeof e.encoder < "u" && typeof e.encoder != "function")
throw new TypeError("Encoder has to be a function.");
var r = e.charset || m.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 t = E.default;
if (typeof e.format < "u") {
if (!ge.call(E.formatters, e.format))
throw new TypeError("Unknown format option provided.");
t = e.format;
}
var f = E.formatters[t], n = m.filter;
return (typeof e.filter == "function" || j(e.filter)) && (n = e.filter), {
addQueryPrefix: typeof e.addQueryPrefix == "boolean" ? e.addQueryPrefix : m.addQueryPrefix,
allowDots: typeof e.allowDots > "u" ? m.allowDots : !!e.allowDots,
charset: r,
charsetSentinel: typeof e.charsetSentinel == "boolean" ? e.charsetSentinel : m.charsetSentinel,
delimiter: typeof e.delimiter > "u" ? m.delimiter : e.delimiter,
encode: typeof e.encode == "boolean" ? e.encode : m.encode,
encoder: typeof e.encoder == "function" ? e.encoder : m.encoder,
encodeValuesOnly: typeof e.encodeValuesOnly == "boolean" ? e.encodeValuesOnly : m.encodeValuesOnly,
filter: n,
format: t,
formatter: f,
serializeDate: typeof e.serializeDate == "function" ? e.serializeDate : m.serializeDate,
skipNulls: typeof e.skipNulls == "boolean" ? e.skipNulls : m.skipNulls,
sort: typeof e.sort == "function" ? e.sort : null,
strictNullHandling: typeof e.strictNullHandling == "boolean" ? e.strictNullHandling : m.strictNullHandling
};
}, Pe = function(a, e) {
var r = a, t = Se(e), f, n;
typeof t.filter == "function" ? (n = t.filter, r = n("", r)) : j(t.filter) && (n = t.filter, f = n);
var i = [];
if (typeof r != "object" || r === null)
return "";
var u;
e && e.arrayFormat in Z ? u = e.arrayFormat : e && "indices" in e ? u = e.indices ? "indices" : "repeat" : u = "indices";
var l = Z[u];
f || (f = Object.keys(r)), t.sort && f.sort(t.sort);
for (var o = 0; o < f.length; ++o) {
var c = f[o];
t.skipNulls && r[c] === null || ee(i, xe(
r[c],
c,
l,
t.strictNullHandling,
t.skipNulls,
t.encode ? t.encoder : null,
t.filter,
t.sort,
t.allowDots,
t.serializeDate,
t.format,
t.formatter,
t.encodeValuesOnly,
t.charset
));
}
var d = i.join(t.delimiter), y = t.addQueryPrefix === !0 ? "?" : "";
return t.charsetSentinel && (t.charset === "iso-8859-1" ? y += "utf8=%26%2310003%3B&" : y += "utf8=%E2%9C%93&"), d.length > 0 ? y + d : "";
}, S = J, Q = Object.prototype.hasOwnProperty, Ee = Array.isArray, v = {
allowDots: !1,
allowPrototypes: !1,
arrayLimit: 20,
charset: "utf-8",
charsetSentinel: !1,
comma: !1,
decoder: S.decode,
delimiter: "&",
depth: 5,
ignoreQueryPrefix: !1,
interpretNumericEntities: !1,
parameterLimit: 1e3,
parseArrays: !0,
plainObjects: !1,
strictNullHandling: !1
}, Fe = function(a) {
return a.replace(/&#(\d+);/g, function(e, r) {
return String.fromCharCode(parseInt(r, 10));
});
}, re = function(a, e) {
return a && typeof a == "string" && e.comma && a.indexOf(",") > -1 ? a.split(",") : a;
}, Ne = "utf8=%26%2310003%3B", Re = "utf8=%E2%9C%93", Ae = function(e, r) {
var t = {}, f = r.ignoreQueryPrefix ? e.replace(/^\?/, "") : e, n = r.parameterLimit === 1 / 0 ? void 0 : r.parameterLimit, i = f.split(r.delimiter, n), u = -1, l, o = r.charset;
if (r.charsetSentinel)
for (l = 0; l < i.length; ++l)
i[l].indexOf("utf8=") === 0 && (i[l] === Re ? o = "utf-8" : i[l] === Ne && (o = "iso-8859-1"), u = l, l = i.length);
for (l = 0; l < i.length; ++l)
if (l !== u) {
var c = i[l], d = c.indexOf("]="), y = d === -1 ? c.indexOf("=") : d + 1, p, s;
y === -1 ? (p = r.decoder(c, v.decoder, o, "key"), s = r.strictNullHandling ? null : "") : (p = r.decoder(c.slice(0, y), v.decoder, o, "key"), s = S.maybeMap(
re(c.slice(y + 1), r),
function(h) {
return r.decoder(h, v.decoder, o, "value");
}
)), s && r.interpretNumericEntities && o === "iso-8859-1" && (s = Fe(s)), c.indexOf("[]=") > -1 && (s = Ee(s) ? [s] : s), Q.call(t, p) ? t[p] = S.combine(t[p], s) : t[p] = s;
}
return t;
}, Ce = function(a, e, r, t) {
for (var f = t ? e : re(e, r), n = a.length - 1; n >= 0; --n) {
var i, u = a[n];
if (u === "[]" && r.parseArrays)
i = [].concat(f);
else {
i = r.plainObjects ? /* @__PURE__ */ Object.create(null) : {};
var l = u.charAt(0) === "[" && u.charAt(u.length - 1) === "]" ? u.slice(1, -1) : u, o = parseInt(l, 10);
!r.parseArrays && l === "" ? i = { 0: f } : !isNaN(o) && u !== l && String(o) === l && o >= 0 && r.parseArrays && o <= r.arrayLimit ? (i = [], i[o] = f) : l !== "__proto__" && (i[l] = f);
}
f = i;
}
return f;
}, De = function(e, r, t, f) {
if (!!e) {
var n = t.allowDots ? e.replace(/\.([^.[]+)/g, "[$1]") : e, i = /(\[[^[\]]*])/, u = /(\[[^[\]]*])/g, l = t.depth > 0 && i.exec(n), o = l ? n.slice(0, l.index) : n, c = [];
if (o) {
if (!t.plainObjects && Q.call(Object.prototype, o) && !t.allowPrototypes)
return;
c.push(o);
}
for (var d = 0; t.depth > 0 && (l = u.exec(n)) !== null && d < t.depth; ) {
if (d += 1, !t.plainObjects && Q.call(Object.prototype, l[1].slice(1, -1)) && !t.allowPrototypes)
return;
c.push(l[1]);
}
return l && c.push("[" + n.slice(l.index) + "]"), Ce(c, r, t, f);
}
}, $e = 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 r = 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: r,
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" || S.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
};
}, Te = function(a, e) {
var r = $e(e);
if (a === "" || a === null || typeof a > "u")
return r.plainObjects ? /* @__PURE__ */ Object.create(null) : {};
for (var t = typeof a == "string" ? Ae(a, r) : a, f = r.plainObjects ? /* @__PURE__ */ Object.create(null) : {}, n = Object.keys(t), i = 0; i < n.length; ++i) {
var u = n[i], l = De(u, t[u], r, typeof a == "string");
f = S.merge(f, l, r);
}
return S.compact(f);
}, Le = Pe, Qe = Te, _e = H, te = {
formats: _e,
parse: Qe,
stringify: Le
};
function G(a, e) {
for (var r = 0; r < e.length; r++) {
var t = e[r];
t.enumerable = t.enumerable || !1, t.configurable = !0, "value" in t && (t.writable = !0), Object.defineProperty(a, t.key, t);
}
}
function ne(a, e, r) {
return e && G(a.prototype, e), r && G(a, r), Object.defineProperty(a, "prototype", { writable: !1 }), a;
}
function g() {
return g = Object.assign ? Object.assign.bind() : function(a) {
for (var e = 1; e < arguments.length; e++) {
var r = arguments[e];
for (var t in r)
Object.prototype.hasOwnProperty.call(r, t) && (a[t] = r[t]);
}
return a;
}, g.apply(this, arguments);
}
function _(a) {
return _ = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function(e) {
return e.__proto__ || Object.getPrototypeOf(e);
}, _(a);
}
function F(a, e) {
return F = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function(r, t) {
return r.__proto__ = t, r;
}, F(a, e);
}
function ke() {
if (typeof Reflect > "u" || !Reflect.construct || Reflect.construct.sham)
return !1;
if (typeof Proxy == "function")
return !0;
try {
return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {
})), !0;
} catch {
return !1;
}
}
function k(a, e, r) {
return k = ke() ? Reflect.construct.bind() : function(t, f, n) {
var i = [null];
i.push.apply(i, f);
var u = new (Function.bind.apply(t, i))();
return n && F(u, n.prototype), u;
}, k.apply(null, arguments);
}
function B(a) {
var e = typeof Map == "function" ? /* @__PURE__ */ new Map() : void 0;
return B = function(r) {
if (r === null || Function.toString.call(r).indexOf("[native code]") === -1)
return r;
if (typeof r != "function")
throw new TypeError("Super expression must either be null or a function");
if (e !== void 0) {
if (e.has(r))
return e.get(r);
e.set(r, t);
}
function t() {
return k(r, arguments, _(this).constructor);
}
return t.prototype = Object.create(r.prototype, { constructor: { value: t, enumerable: !1, writable: !0, configurable: !0 } }), F(t, r);
}, B(a);
}
var T = /* @__PURE__ */ function() {
function a(r, t, f) {
var n, i;
this.name = r, this.definition = t, this.bindings = (n = t.bindings) != null ? n : {}, this.wheres = (i = t.wheres) != null ? i : {}, this.config = f;
}
var e = a.prototype;
return e.matchesUrl = function(r) {
var t = this;
if (!this.definition.methods.includes("GET"))
return !1;
var f = this.template.replace(/(\/?){([^}?]*)(\??)}/g, function(o, c, d, y) {
var p, s = "(?<" + d + ">" + (((p = t.wheres[d]) == null ? void 0 : p.replace(/(^\^)|(\$$)/g, "")) || "[^/?]+") + ")";
return y ? "(" + c + s + ")?" : "" + c + s;
}).replace(/^\w+:\/\//, ""), n = r.replace(/^\w+:\/\//, "").split("?"), i = n[0], u = n[1], l = new RegExp("^" + f + "/?$").exec(i);
return !!l && { params: l.groups, query: te.parse(u) };
}, e.compile = function(r) {
var t = this, f = this.parameterSegments;
return f.length ? this.template.replace(/{([^}?]+)(\??)}/g, function(n, i, u) {
var l, o, c;
if (!u && [null, void 0].includes(r[i]))
throw new Error("Ziggy error: '" + i + "' parameter is required for route '" + t.name + "'.");
if (f[f.length - 1].name === i && t.wheres[i] === ".*")
return encodeURIComponent((c = r[i]) != null ? c : "").replace(/%2F/g, "/");
if (t.wheres[i] && !new RegExp("^" + (u ? "(" + t.wheres[i] + ")?" : t.wheres[i]) + "$").test((l = r[i]) != null ? l : ""))
throw new Error("Ziggy error: '" + i + "' parameter does not match required format '" + t.wheres[i] + "' for route '" + t.name + "'.");
return encodeURIComponent((o = r[i]) != null ? o : "");
}).replace(/\/+$/, "") : this.template;
}, ne(a, [{ 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 r, t;
return (r = (t = this.template.match(/{[^}?]+\??}/g)) == null ? void 0 : t.map(function(f) {
return { name: f.replace(/{|\??}/g, ""), required: !/\?}$/.test(f) };
})) != null ? r : [];
} }]), a;
}(), Be = /* @__PURE__ */ function(a) {
var e, r;
function t(n, i, u, l) {
var o;
if (u === void 0 && (u = !0), (o = a.call(this) || this).t = l != null ? l : typeof Ziggy < "u" ? Ziggy : globalThis == null ? void 0 : globalThis.Ziggy, o.t = g({}, o.t, { absolute: u }), n) {
if (!o.t.routes[n])
throw new Error("Ziggy error: route '" + n + "' is not in the route list.");
o.i = new T(n, o.t.routes[n], o.t), o.u = o.o(i);
}
return o;
}
r = a, (e = t).prototype = Object.create(r.prototype), e.prototype.constructor = e, F(e, r);
var f = t.prototype;
return f.toString = function() {
var n = this, i = Object.keys(this.u).filter(function(u) {
return !n.i.parameterSegments.some(function(l) {
return l.name === u;
});
}).filter(function(u) {
return u !== "_query";
}).reduce(function(u, l) {
var o;
return g({}, u, ((o = {})[l] = n.u[l], o));
}, {});
return this.i.compile(this.u) + te.stringify(g({}, i, this.u._query), { addQueryPrefix: !0, arrayFormat: "indices", encodeValuesOnly: !0, skipNulls: !0, encoder: function(u, l) {
return typeof u == "boolean" ? Number(u) : l(u);
} });
}, f.l = function(n) {
var i = this;
n ? this.t.absolute && n.startsWith("/") && (n = this.h().host + n) : n = this.v();
var u = {}, l = Object.entries(this.t.routes).find(function(o) {
return u = new T(o[0], o[1], i.t).matchesUrl(n);
}) || [void 0, void 0];
return g({ name: l[0] }, u, { route: l[1] });
}, f.v = function() {
var n = this.h(), i = n.pathname, u = n.search;
return (this.t.absolute ? n.host + i : i.replace(this.t.url.replace(/^\w*:\/\/[^/]+/, ""), "").replace(/^\/+/, "/")) + u;
}, f.current = function(n, i) {
var u = this.l(), l = u.name, o = u.params, c = u.query, d = u.route;
if (!n)
return l;
var y = new RegExp("^" + n.replace(/\./g, "\\.").replace(/\*/g, ".*") + "$").test(l);
if ([null, void 0].includes(i) || !y)
return y;
var p = new T(l, d, this.t);
i = this.o(i, p);
var s = g({}, o, c);
return !(!Object.values(i).every(function(h) {
return !h;
}) || Object.values(s).some(function(h) {
return h !== void 0;
})) || Object.entries(i).every(function(h) {
return s[h[0]] == h[1];
});
}, f.h = function() {
var n, i, u, l, o, c, d = typeof window < "u" ? window.location : {}, y = d.host, p = d.pathname, s = d.search;
return { host: (n = (i = this.t.location) == null ? void 0 : i.host) != null ? n : y === void 0 ? "" : y, pathname: (u = (l = this.t.location) == null ? void 0 : l.pathname) != null ? u : p === void 0 ? "" : p, search: (o = (c = this.t.location) == null ? void 0 : c.search) != null ? o : s === void 0 ? "" : s };
}, f.has = function(n) {
return Object.keys(this.t.routes).includes(n);
}, f.o = function(n, i) {
var u = this;
n === void 0 && (n = {}), i === void 0 && (i = this.i), n != null || (n = {}), n = ["string", "number"].includes(typeof n) ? [n] : n;
var l = i.parameterSegments.filter(function(c) {
return !u.t.defaults[c.name];
});
if (Array.isArray(n))
n = n.reduce(function(c, d, y) {
var p, s;
return g({}, c, l[y] ? ((p = {})[l[y].name] = d, p) : typeof d == "object" ? d : ((s = {})[d] = "", s));
}, {});
else if (l.length === 1 && !n[l[0].name] && (n.hasOwnProperty(Object.values(i.bindings)[0]) || n.hasOwnProperty("id"))) {
var o;
(o = {})[l[0].name] = n, n = o;
}
return g({}, this.g(i), this.p(n, i));
}, f.g = function(n) {
var i = this;
return n.parameterSegments.filter(function(u) {
return i.t.defaults[u.name];
}).reduce(function(u, l, o) {
var c, d = l.name;
return g({}, u, ((c = {})[d] = i.t.defaults[d], c));
}, {});
}, f.p = function(n, i) {
var u = i.bindings, l = i.parameterSegments;
return Object.entries(n).reduce(function(o, c) {
var d, y, p = c[0], s = c[1];
if (!s || typeof s != "object" || Array.isArray(s) || !l.some(function(h) {
return h.name === p;
}))
return g({}, o, ((y = {})[p] = s, y));
if (!s.hasOwnProperty(u[p])) {
if (!s.hasOwnProperty("id"))
throw new Error("Ziggy error: object passed as '" + p + "' parameter is missing route model binding key '" + u[p] + "'.");
u[p] = "id";
}
return g({}, o, ((d = {})[p] = s[u[p]], d));
}, {});
}, f.valueOf = function() {
return this.toString();
}, f.check = function(n) {
return this.has(n);
}, ne(t, [{ key: "params", get: function() {
var n = this.l();
return g({}, n.params, n.query);
} }]), t;
}(/* @__PURE__ */ B(String));
function He(a, e, r, t) {
var f = new Be(a, e, r, t);
return a ? f.toString() : f;
}
let K, W, X = !0;
const x = {
setRoutes: (a) => K = a,
getRoutes: () => typeof window < "u" && window.trail ? window.trail : K,
setLocation: (a, e) => {
W = e ? new URL(e, a) : void 0;
},
getLocation: () => W,
getAbsolute: () => X,
setAbsolute: (a) => X = a
};
function ze(a, e) {
const { url: r, routes: t, defaults: f } = x.getRoutes(), n = x.getAbsolute();
return He(a, e, n, { url: r, routes: t, defaults: f });
}
function Ie(a, e) {
return ze().current(a, e);
}
function Ue(a) {
x.setRoutes(a);
}
const qe = (a, e) => {
e != null && e.routes && x.setRoutes(e.routes), e != null && e.url && x.setLocation(e.routes.url, e.url), (e == null ? void 0 : e.absolute) !== void 0 && x.setAbsolute(e.absolute);
};
export {
Ie as current,
Ue as defineRoutes,
ze as route,
x as store,
qe as trail
};