lakutata
Version:
An IoC-based universal application framework.
429 lines (388 loc) • 11.5 kB
JavaScript
/* Build Date: Mon Jan 05 2026 23:52:23 GMT+0800 (China Standard Time) */
import { a as e, c as t } from "../../../vendor/Package.internal.2.mjs";
var s = function e(t, s) {
s = s.split(":")[0];
t = +t;
if (!t) return false;
switch (s) {
case "http":
case "ws":
return t !== 80;
case "https":
case "wss":
return t !== 443;
case "ftp":
return t !== 21;
case "gopher":
return t !== 70;
case "file":
return false;
}
return t !== 0;
};
var o = {};
var r = Object.prototype.hasOwnProperty, n;
function i(e) {
try {
return decodeURIComponent(e.replace(/\+/g, " "));
} catch (e) {
return null;
}
}
function a(e) {
try {
return encodeURIComponent(e);
} catch (e) {
return null;
}
}
function h(e) {
var t = /([^=?#&]+)=?([^&]*)/g, s = {}, o;
while (o = t.exec(e)) {
var r = i(o[1]), n = i(o[2]);
if (r === null || n === null || r in s) continue;
s[r] = n;
}
return s;
}
function l(e, t) {
t = t || "";
var s = [], o, i;
if ("string" !== typeof t) t = "?";
for (i in e) {
if (r.call(e, i)) {
o = e[i];
if (!o && (o === null || o === n || isNaN(o))) {
o = "";
}
i = a(i);
o = a(o);
if (i === null || o === null) continue;
s.push(i + "=" + o);
}
}
return s.length ? t + s.join("&") : "";
}
o.stringify = l;
o.parse = h;
var f = s, c = o, u = /^[\x00-\x20\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]+/, p = /[\n\r\t]/g, d = /^[A-Za-z][A-Za-z0-9+-.]*:\/\//, m = /:\d+$/, w = /^([a-z][a-z0-9.+-]*:)?(\/\/)?([\\/]+)?([\S\s]*)/i, g = /^[a-zA-Z]:/;
function y(e) {
return (e ? e : "").toString().replace(u, "");
}
var b = [ [ "#", "hash" ], [ "?", "query" ], function e(t, s) {
return O(s.protocol) ? t.replace(/\\/g, "/") : t;
}, [ "/", "pathname" ], [ "@", "auth", 1 ], [ NaN, "host", undefined, 1, 1 ], [ /:(\d*)$/, "port", undefined, 1 ], [ NaN, "hostname", undefined, 1, 1 ] ];
var v = {
hash: 1,
query: 1
};
function j(e) {
var s;
if (typeof window !== "undefined") s = window; else if (typeof t !== "undefined") s = t; else if (typeof self !== "undefined") s = self; else s = {};
var o = s.location || {};
e = e || o;
var r = {}, n = typeof e, i;
if ("blob:" === e.protocol) {
r = new U(unescape(e.pathname), {});
} else if ("string" === n) {
r = new U(e, {});
for (i in v) delete r[i];
} else if ("object" === n) {
for (i in e) {
if (i in v) continue;
r[i] = e[i];
}
if (r.slashes === undefined) {
r.slashes = d.test(e.href);
}
}
return r;
}
function O(e) {
return e === "file:" || e === "ftp:" || e === "http:" || e === "https:" || e === "ws:" || e === "wss:";
}
function C(e, t) {
e = y(e);
e = e.replace(p, "");
t = t || {};
var s = w.exec(e);
var o = s[1] ? s[1].toLowerCase() : "";
var r = !!s[2];
var n = !!s[3];
var i = 0;
var a;
if (r) {
if (n) {
a = s[2] + s[3] + s[4];
i = s[2].length + s[3].length;
} else {
a = s[2] + s[4];
i = s[2].length;
}
} else {
if (n) {
a = s[3] + s[4];
i = s[3].length;
} else {
a = s[4];
}
}
if (o === "file:") {
if (i >= 2) {
a = a.slice(2);
}
} else if (O(o)) {
a = s[4];
} else if (o) {
if (r) {
a = a.slice(2);
}
} else if (i >= 2 && O(t.protocol)) {
a = s[4];
}
return {
protocol: o,
slashes: r || O(o),
slashesCount: i,
rest: a
};
}
function R(e, t) {
if (e === "") return t;
var s = (t || "/").split("/").slice(0, -1).concat(e.split("/")), o = s.length, r = s[o - 1], n = false, i = 0;
while (o--) {
if (s[o] === ".") {
s.splice(o, 1);
} else if (s[o] === "..") {
s.splice(o, 1);
i++;
} else if (i) {
if (o === 0) n = true;
s.splice(o, 1);
i--;
}
}
if (n) s.unshift("");
if (r === "." || r === "..") s.push("");
return s.join("/");
}
function U(e, t, s) {
e = y(e);
e = e.replace(p, "");
if (!(this instanceof U)) {
return new U(e, t, s);
}
var o, r, n, i, a, h, l = b.slice(), u = typeof t, d = this, m = 0;
if ("object" !== u && "string" !== u) {
s = t;
t = null;
}
if (s && "function" !== typeof s) s = c.parse;
t = j(t);
r = C(e || "", t);
o = !r.protocol && !r.slashes;
d.slashes = r.slashes || o && t.slashes;
d.protocol = r.protocol || t.protocol || "";
e = r.rest;
if (r.protocol === "file:" && (r.slashesCount !== 2 || g.test(e)) || !r.slashes && (r.protocol || r.slashesCount < 2 || !O(d.protocol))) {
l[3] = [ /(.*)/, "pathname" ];
}
for (;m < l.length; m++) {
i = l[m];
if (typeof i === "function") {
e = i(e, d);
continue;
}
n = i[0];
h = i[1];
if (n !== n) {
d[h] = e;
} else if ("string" === typeof n) {
a = n === "@" ? e.lastIndexOf(n) : e.indexOf(n);
if (~a) {
if ("number" === typeof i[2]) {
d[h] = e.slice(0, a);
e = e.slice(a + i[2]);
} else {
d[h] = e.slice(a);
e = e.slice(0, a);
}
}
} else if (a = n.exec(e)) {
d[h] = a[1];
e = e.slice(0, a.index);
}
d[h] = d[h] || (o && i[3] ? t[h] || "" : "");
if (i[4]) d[h] = d[h].toLowerCase();
}
if (s) d.query = s(d.query);
if (o && t.slashes && d.pathname.charAt(0) !== "/" && (d.pathname !== "" || t.pathname !== "")) {
d.pathname = R(d.pathname, t.pathname);
}
if (d.pathname.charAt(0) !== "/" && O(d.protocol)) {
d.pathname = "/" + d.pathname;
}
if (!f(d.port, d.protocol)) {
d.host = d.hostname;
d.port = "";
}
d.username = d.password = "";
if (d.auth) {
a = d.auth.indexOf(":");
if (~a) {
d.username = d.auth.slice(0, a);
d.username = encodeURIComponent(decodeURIComponent(d.username));
d.password = d.auth.slice(a + 1);
d.password = encodeURIComponent(decodeURIComponent(d.password));
} else {
d.username = encodeURIComponent(decodeURIComponent(d.auth));
}
d.auth = d.password ? d.username + ":" + d.password : d.username;
}
d.origin = d.protocol !== "file:" && O(d.protocol) && d.host ? d.protocol + "//" + d.host : "null";
d.href = d.toString();
}
function I(e, t, s) {
var o = this;
switch (e) {
case "query":
if ("string" === typeof t && t.length) {
t = (s || c.parse)(t);
}
o[e] = t;
break;
case "port":
o[e] = t;
if (!f(t, o.protocol)) {
o.host = o.hostname;
o[e] = "";
} else if (t) {
o.host = o.hostname + ":" + t;
}
break;
case "hostname":
o[e] = t;
if (o.port) t += ":" + o.port;
o.host = t;
break;
case "host":
o[e] = t;
if (m.test(t)) {
t = t.split(":");
o.port = t.pop();
o.hostname = t.join(":");
} else {
o.hostname = t;
o.port = "";
}
break;
case "protocol":
o.protocol = t.toLowerCase();
o.slashes = !s;
break;
case "pathname":
case "hash":
if (t) {
var r = e === "pathname" ? "/" : "#";
o[e] = t.charAt(0) !== r ? r + t : t;
} else {
o[e] = t;
}
break;
case "username":
case "password":
o[e] = encodeURIComponent(t);
break;
case "auth":
var n = t.indexOf(":");
if (~n) {
o.username = t.slice(0, n);
o.username = encodeURIComponent(decodeURIComponent(o.username));
o.password = t.slice(n + 1);
o.password = encodeURIComponent(decodeURIComponent(o.password));
} else {
o.username = encodeURIComponent(decodeURIComponent(t));
}
}
for (var i = 0; i < b.length; i++) {
var a = b[i];
if (a[4]) o[a[1]] = o[a[1]].toLowerCase();
}
o.auth = o.password ? o.username + ":" + o.password : o.username;
o.origin = o.protocol !== "file:" && O(o.protocol) && o.host ? o.protocol + "//" + o.host : "null";
o.href = o.toString();
return o;
}
function q(e) {
if (!e || "function" !== typeof e) e = c.stringify;
var t, s = this, o = s.host, r = s.protocol;
if (r && r.charAt(r.length - 1) !== ":") r += ":";
var n = r + (s.protocol && s.slashes || O(s.protocol) ? "//" : "");
if (s.username) {
n += s.username;
if (s.password) n += ":" + s.password;
n += "@";
} else if (s.password) {
n += ":" + s.password;
n += "@";
} else if (s.protocol !== "file:" && O(s.protocol) && !o && s.pathname !== "/") {
n += "@";
}
if (o[o.length - 1] === ":" || m.test(s.hostname) && !s.port) {
o += ":";
}
n += o + s.pathname;
t = "object" === typeof s.query ? e(s.query) : s.query;
if (t) n += "?" !== t.charAt(0) ? "?" + t : t;
if (s.hash) n += s.hash;
return n;
}
U.prototype = {
set: I,
toString: q
};
U.extractProtocol = C;
U.location = j;
U.trimLeft = y;
U.qs = c;
var x = U;
const S = e(x);
class URLBuilder {
static parse(e) {
return new URLBuilder(JSON.parse(JSON.stringify(S(e, true))));
}
#e;
constructor(e = {}) {
this.#e = S("");
this.auth = e.auth;
this.hash = e.hash;
this.host = e.host;
this.hostname = e.hostname;
this.href = e.href;
this.origin = e.origin;
this.password = e.password;
this.pathname = e.pathname;
this.port = e.port;
this.protocol = e.protocol;
this.query = e.query;
this.slashes = e.slashes;
this.username = e.username;
}
toString() {
if (this.auth) this.#e.set("auth", this.auth);
if (this.hash) this.#e.set("hash", this.hash);
if (this.host) this.#e.set("host", this.host);
if (this.hostname) this.#e.set("hostname", this.hostname);
if (this.href) this.#e.set("href", this.href);
if (this.origin !== undefined) this.#e.set("origin", this.origin.toString());
if (this.password) this.#e.set("password", this.password);
if (this.pathname) this.#e.set("pathname", this.pathname);
if (this.port !== undefined) this.#e.set("port", this.port);
if (this.protocol) this.#e.set("protocol", this.protocol);
if (this.query) this.#e.set("query", this.query);
if (this.slashes !== undefined) this.#e.set("slashes", this.slashes);
if (this.username) this.#e.set("username", this.username);
return this.#e.toString();
}
}
export { URLBuilder };