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