c13848ed3b61773cb8decf24a42c6c95c84c9638c1cd554bd5cff223a6ab6a13e5029b8c136da4d48b0a2e992c76585ef2455be92c288e647f61a1dc0ae358 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. 'use strict';
  2. const n = /[^\0-\x7E]/;
  3. const t = /[\x2E\u3002\uFF0E\uFF61]/g;
  4. const o = {
  5. overflow: "Overflow Error",
  6. "not-basic": "Illegal Input",
  7. "invalid-input": "Invalid Input"
  8. };
  9. const e = Math.floor;
  10. const r = String.fromCharCode;
  11. function s(n2) {
  12. throw new RangeError(o[n2]);
  13. }
  14. const c = function(n2, t2) {
  15. return n2 + 22 + 75 * (n2 < 26) - ((t2 != 0) << 5);
  16. };
  17. const u = function(n2, t2, o2) {
  18. let r2 = 0;
  19. for (n2 = o2 ? e(n2 / 700) : n2 >> 1, n2 += e(n2 / t2); n2 > 455; r2 += 36) {
  20. n2 = e(n2 / 35);
  21. }
  22. return e(r2 + 36 * n2 / (n2 + 38));
  23. };
  24. function toASCII(o2) {
  25. return function(n2, o3) {
  26. const e2 = n2.split("@");
  27. let r2 = "";
  28. e2.length > 1 && (r2 = e2[0] + "@", n2 = e2[1]);
  29. const s2 = function(n3, t2) {
  30. const o4 = [];
  31. let e3 = n3.length;
  32. for (; e3--; ) {
  33. o4[e3] = t2(n3[e3]);
  34. }
  35. return o4;
  36. }((n2 = n2.replace(t, ".")).split("."), o3).join(".");
  37. return r2 + s2;
  38. }(o2, function(t2) {
  39. return n.test(t2) ? "xn--" + function(n2) {
  40. const t3 = [];
  41. const o3 = (n2 = function(n3) {
  42. const t4 = [];
  43. let o4 = 0;
  44. const e2 = n3.length;
  45. for (; o4 < e2; ) {
  46. const r2 = n3.charCodeAt(o4++);
  47. if (r2 >= 55296 && r2 <= 56319 && o4 < e2) {
  48. const e3 = n3.charCodeAt(o4++);
  49. (64512 & e3) == 56320 ? t4.push(((1023 & r2) << 10) + (1023 & e3) + 65536) : (t4.push(r2), o4--);
  50. } else {
  51. t4.push(r2);
  52. }
  53. }
  54. return t4;
  55. }(n2)).length;
  56. let f = 128;
  57. let i = 0;
  58. let l = 72;
  59. for (const o4 of n2) {
  60. o4 < 128 && t3.push(r(o4));
  61. }
  62. const h = t3.length;
  63. let p = h;
  64. for (h && t3.push("-"); p < o3; ) {
  65. let o4 = 2147483647;
  66. for (const t4 of n2) {
  67. t4 >= f && t4 < o4 && (o4 = t4);
  68. }
  69. const a = p + 1;
  70. o4 - f > e((2147483647 - i) / a) && s("overflow"), i += (o4 - f) * a, f = o4;
  71. for (const o5 of n2) {
  72. if (o5 < f && ++i > 2147483647 && s("overflow"), o5 == f) {
  73. let n3 = i;
  74. for (let o6 = 36; ; o6 += 36) {
  75. const s2 = o6 <= l ? 1 : o6 >= l + 26 ? 26 : o6 - l;
  76. if (n3 < s2) {
  77. break;
  78. }
  79. const u2 = n3 - s2;
  80. const f2 = 36 - s2;
  81. t3.push(r(c(s2 + u2 % f2, 0))), n3 = e(u2 / f2);
  82. }
  83. t3.push(r(c(n3, 0))), l = u(i, a, p == h), i = 0, ++p;
  84. }
  85. }
  86. ++i, ++f;
  87. }
  88. return t3.join("");
  89. }(t2) : t2;
  90. });
  91. }
  92. const HASH_RE = /#/g;
  93. const AMPERSAND_RE = /&/g;
  94. const SLASH_RE = /\//g;
  95. const EQUAL_RE = /=/g;
  96. const IM_RE = /\?/g;
  97. const PLUS_RE = /\+/g;
  98. const ENC_CARET_RE = /%5e/gi;
  99. const ENC_BACKTICK_RE = /%60/gi;
  100. const ENC_CURLY_OPEN_RE = /%7b/gi;
  101. const ENC_PIPE_RE = /%7c/gi;
  102. const ENC_CURLY_CLOSE_RE = /%7d/gi;
  103. const ENC_SPACE_RE = /%20/gi;
  104. const ENC_SLASH_RE = /%2f/gi;
  105. const ENC_ENC_SLASH_RE = /%252f/gi;
  106. function encode(text) {
  107. return encodeURI("" + text).replace(ENC_PIPE_RE, "|");
  108. }
  109. function encodeHash(text) {
  110. return encode(text).replace(ENC_CURLY_OPEN_RE, "{").replace(ENC_CURLY_CLOSE_RE, "}").replace(ENC_CARET_RE, "^");
  111. }
  112. function encodeQueryValue(input) {
  113. return encode(typeof input === "string" ? input : JSON.stringify(input)).replace(PLUS_RE, "%2B").replace(ENC_SPACE_RE, "+").replace(HASH_RE, "%23").replace(AMPERSAND_RE, "%26").replace(ENC_BACKTICK_RE, "`").replace(ENC_CARET_RE, "^").replace(SLASH_RE, "%2F");
  114. }
  115. function encodeQueryKey(text) {
  116. return encodeQueryValue(text).replace(EQUAL_RE, "%3D");
  117. }
  118. function encodePath(text) {
  119. return encode(text).replace(HASH_RE, "%23").replace(IM_RE, "%3F").replace(ENC_ENC_SLASH_RE, "%2F").replace(AMPERSAND_RE, "%26").replace(PLUS_RE, "%2B");
  120. }
  121. function encodeParam(text) {
  122. return encodePath(text).replace(SLASH_RE, "%2F");
  123. }
  124. function decode(text = "") {
  125. try {
  126. return decodeURIComponent("" + text);
  127. } catch {
  128. return "" + text;
  129. }
  130. }
  131. function decodePath(text) {
  132. return decode(text.replace(ENC_SLASH_RE, "%252F"));
  133. }
  134. function decodeQueryKey(text) {
  135. return decode(text.replace(PLUS_RE, " "));
  136. }
  137. function decodeQueryValue(text) {
  138. return decode(text.replace(PLUS_RE, " "));
  139. }
  140. function encodeHost(name = "") {
  141. return toASCII(name);
  142. }
  143. function parseQuery(parametersString = "") {
  144. const object = /* @__PURE__ */ Object.create(null);
  145. if (parametersString[0] === "?") {
  146. parametersString = parametersString.slice(1);
  147. }
  148. for (const parameter of parametersString.split("&")) {
  149. const s = parameter.match(/([^=]+)=?(.*)/) || [];
  150. if (s.length < 2) {
  151. continue;
  152. }
  153. const key = decodeQueryKey(s[1]);
  154. if (key === "__proto__" || key === "constructor") {
  155. continue;
  156. }
  157. const value = decodeQueryValue(s[2] || "");
  158. if (object[key] === void 0) {
  159. object[key] = value;
  160. } else if (Array.isArray(object[key])) {
  161. object[key].push(value);
  162. } else {
  163. object[key] = [object[key], value];
  164. }
  165. }
  166. return object;
  167. }
  168. function encodeQueryItem(key, value) {
  169. if (typeof value === "number" || typeof value === "boolean") {
  170. value = String(value);
  171. }
  172. if (!value) {
  173. return encodeQueryKey(key);
  174. }
  175. if (Array.isArray(value)) {
  176. return value.map(
  177. (_value) => `${encodeQueryKey(key)}=${encodeQueryValue(_value)}`
  178. ).join("&");
  179. }
  180. return `${encodeQueryKey(key)}=${encodeQueryValue(value)}`;
  181. }
  182. function stringifyQuery(query) {
  183. return Object.keys(query).filter((k) => query[k] !== void 0).map((k) => encodeQueryItem(k, query[k])).filter(Boolean).join("&");
  184. }
  185. const PROTOCOL_STRICT_REGEX = /^[\s\w\0+.-]{2,}:([/\\]{1,2})/;
  186. const PROTOCOL_REGEX = /^[\s\w\0+.-]{2,}:([/\\]{2})?/;
  187. const PROTOCOL_RELATIVE_REGEX = /^([/\\]\s*){2,}[^/\\]/;
  188. const PROTOCOL_SCRIPT_RE = /^[\s\0]*(blob|data|javascript|vbscript):$/i;
  189. const TRAILING_SLASH_RE = /\/$|\/\?|\/#/;
  190. const JOIN_LEADING_SLASH_RE = /^\.?\//;
  191. function isRelative(inputString) {
  192. return ["./", "../"].some((string_) => inputString.startsWith(string_));
  193. }
  194. function hasProtocol(inputString, opts = {}) {
  195. if (typeof opts === "boolean") {
  196. opts = { acceptRelative: opts };
  197. }
  198. if (opts.strict) {
  199. return PROTOCOL_STRICT_REGEX.test(inputString);
  200. }
  201. return PROTOCOL_REGEX.test(inputString) || (opts.acceptRelative ? PROTOCOL_RELATIVE_REGEX.test(inputString) : false);
  202. }
  203. function isScriptProtocol(protocol) {
  204. return !!protocol && PROTOCOL_SCRIPT_RE.test(protocol);
  205. }
  206. function hasTrailingSlash(input = "", respectQueryAndFragment) {
  207. if (!respectQueryAndFragment) {
  208. return input.endsWith("/");
  209. }
  210. return TRAILING_SLASH_RE.test(input);
  211. }
  212. function withoutTrailingSlash(input = "", respectQueryAndFragment) {
  213. if (!respectQueryAndFragment) {
  214. return (hasTrailingSlash(input) ? input.slice(0, -1) : input) || "/";
  215. }
  216. if (!hasTrailingSlash(input, true)) {
  217. return input || "/";
  218. }
  219. let path = input;
  220. let fragment = "";
  221. const fragmentIndex = input.indexOf("#");
  222. if (fragmentIndex !== -1) {
  223. path = input.slice(0, fragmentIndex);
  224. fragment = input.slice(fragmentIndex);
  225. }
  226. const [s0, ...s] = path.split("?");
  227. const cleanPath = s0.endsWith("/") ? s0.slice(0, -1) : s0;
  228. return (cleanPath || "/") + (s.length > 0 ? `?${s.join("?")}` : "") + fragment;
  229. }
  230. function withTrailingSlash(input = "", respectQueryAndFragment) {
  231. if (!respectQueryAndFragment) {
  232. return input.endsWith("/") ? input : input + "/";
  233. }
  234. if (hasTrailingSlash(input, true)) {
  235. return input || "/";
  236. }
  237. let path = input;
  238. let fragment = "";
  239. const fragmentIndex = input.indexOf("#");
  240. if (fragmentIndex !== -1) {
  241. path = input.slice(0, fragmentIndex);
  242. fragment = input.slice(fragmentIndex);
  243. if (!path) {
  244. return fragment;
  245. }
  246. }
  247. const [s0, ...s] = path.split("?");
  248. return s0 + "/" + (s.length > 0 ? `?${s.join("?")}` : "") + fragment;
  249. }
  250. function hasLeadingSlash(input = "") {
  251. return input.startsWith("/");
  252. }
  253. function withoutLeadingSlash(input = "") {
  254. return (hasLeadingSlash(input) ? input.slice(1) : input) || "/";
  255. }
  256. function withLeadingSlash(input = "") {
  257. return hasLeadingSlash(input) ? input : "/" + input;
  258. }
  259. function cleanDoubleSlashes(input = "") {
  260. return input.split("://").map((string_) => string_.replace(/\/{2,}/g, "/")).join("://");
  261. }
  262. function withBase(input, base) {
  263. if (isEmptyURL(base) || hasProtocol(input)) {
  264. return input;
  265. }
  266. const _base = withoutTrailingSlash(base);
  267. if (input.startsWith(_base)) {
  268. return input;
  269. }
  270. return joinURL(_base, input);
  271. }
  272. function withoutBase(input, base) {
  273. if (isEmptyURL(base)) {
  274. return input;
  275. }
  276. const _base = withoutTrailingSlash(base);
  277. if (!input.startsWith(_base)) {
  278. return input;
  279. }
  280. const trimmed = input.slice(_base.length);
  281. return trimmed[0] === "/" ? trimmed : "/" + trimmed;
  282. }
  283. function withQuery(input, query) {
  284. const parsed = parseURL(input);
  285. const mergedQuery = { ...parseQuery(parsed.search), ...query };
  286. parsed.search = stringifyQuery(mergedQuery);
  287. return stringifyParsedURL(parsed);
  288. }
  289. function filterQuery(input, predicate) {
  290. if (!input.includes("?")) {
  291. return input;
  292. }
  293. const parsed = parseURL(input);
  294. const query = parseQuery(parsed.search);
  295. const filteredQuery = Object.fromEntries(
  296. Object.entries(query).filter(([key, value]) => predicate(key, value))
  297. );
  298. parsed.search = stringifyQuery(filteredQuery);
  299. return stringifyParsedURL(parsed);
  300. }
  301. function getQuery(input) {
  302. return parseQuery(parseURL(input).search);
  303. }
  304. function isEmptyURL(url) {
  305. return !url || url === "/";
  306. }
  307. function isNonEmptyURL(url) {
  308. return url && url !== "/";
  309. }
  310. function joinURL(base, ...input) {
  311. let url = base || "";
  312. for (const segment of input.filter((url2) => isNonEmptyURL(url2))) {
  313. if (url) {
  314. const _segment = segment.replace(JOIN_LEADING_SLASH_RE, "");
  315. url = withTrailingSlash(url) + _segment;
  316. } else {
  317. url = segment;
  318. }
  319. }
  320. return url;
  321. }
  322. function joinRelativeURL(..._input) {
  323. const JOIN_SEGMENT_SPLIT_RE = /\/(?!\/)/;
  324. const input = _input.filter(Boolean);
  325. const segments = [];
  326. let segmentsDepth = 0;
  327. for (const i of input) {
  328. if (!i || i === "/") {
  329. continue;
  330. }
  331. for (const [sindex, s] of i.split(JOIN_SEGMENT_SPLIT_RE).entries()) {
  332. if (!s || s === ".") {
  333. continue;
  334. }
  335. if (s === "..") {
  336. if (segments.length === 1 && hasProtocol(segments[0])) {
  337. continue;
  338. }
  339. segments.pop();
  340. segmentsDepth--;
  341. continue;
  342. }
  343. if (sindex === 1 && segments[segments.length - 1]?.endsWith(":/")) {
  344. segments[segments.length - 1] += "/" + s;
  345. continue;
  346. }
  347. segments.push(s);
  348. segmentsDepth++;
  349. }
  350. }
  351. let url = segments.join("/");
  352. if (segmentsDepth >= 0) {
  353. if (input[0]?.startsWith("/") && !url.startsWith("/")) {
  354. url = "/" + url;
  355. } else if (input[0]?.startsWith("./") && !url.startsWith("./")) {
  356. url = "./" + url;
  357. }
  358. } else {
  359. url = "../".repeat(-1 * segmentsDepth) + url;
  360. }
  361. if (input[input.length - 1]?.endsWith("/") && !url.endsWith("/")) {
  362. url += "/";
  363. }
  364. return url;
  365. }
  366. function withHttp(input) {
  367. return withProtocol(input, "http://");
  368. }
  369. function withHttps(input) {
  370. return withProtocol(input, "https://");
  371. }
  372. function withoutProtocol(input) {
  373. return withProtocol(input, "");
  374. }
  375. function withProtocol(input, protocol) {
  376. let match = input.match(PROTOCOL_REGEX);
  377. if (!match) {
  378. match = input.match(/^\/{2,}/);
  379. }
  380. if (!match) {
  381. return protocol + input;
  382. }
  383. return protocol + input.slice(match[0].length);
  384. }
  385. function normalizeURL(input) {
  386. const parsed = parseURL(input);
  387. parsed.pathname = encodePath(decodePath(parsed.pathname));
  388. parsed.hash = encodeHash(decode(parsed.hash));
  389. parsed.host = encodeHost(decode(parsed.host));
  390. parsed.search = stringifyQuery(parseQuery(parsed.search));
  391. return stringifyParsedURL(parsed);
  392. }
  393. function resolveURL(base = "", ...inputs) {
  394. if (typeof base !== "string") {
  395. throw new TypeError(
  396. `URL input should be string received ${typeof base} (${base})`
  397. );
  398. }
  399. const filteredInputs = inputs.filter((input) => isNonEmptyURL(input));
  400. if (filteredInputs.length === 0) {
  401. return base;
  402. }
  403. const url = parseURL(base);
  404. for (const inputSegment of filteredInputs) {
  405. const urlSegment = parseURL(inputSegment);
  406. if (urlSegment.pathname) {
  407. url.pathname = withTrailingSlash(url.pathname) + withoutLeadingSlash(urlSegment.pathname);
  408. }
  409. if (urlSegment.hash && urlSegment.hash !== "#") {
  410. url.hash = urlSegment.hash;
  411. }
  412. if (urlSegment.search && urlSegment.search !== "?") {
  413. if (url.search && url.search !== "?") {
  414. const queryString = stringifyQuery({
  415. ...parseQuery(url.search),
  416. ...parseQuery(urlSegment.search)
  417. });
  418. url.search = queryString.length > 0 ? "?" + queryString : "";
  419. } else {
  420. url.search = urlSegment.search;
  421. }
  422. }
  423. }
  424. return stringifyParsedURL(url);
  425. }
  426. function isSamePath(p1, p2) {
  427. return decode(withoutTrailingSlash(p1)) === decode(withoutTrailingSlash(p2));
  428. }
  429. function isEqual(a, b, options = {}) {
  430. if (!options.trailingSlash) {
  431. a = withTrailingSlash(a);
  432. b = withTrailingSlash(b);
  433. }
  434. if (!options.leadingSlash) {
  435. a = withLeadingSlash(a);
  436. b = withLeadingSlash(b);
  437. }
  438. if (!options.encoding) {
  439. a = decode(a);
  440. b = decode(b);
  441. }
  442. return a === b;
  443. }
  444. function withFragment(input, hash) {
  445. if (!hash || hash === "#") {
  446. return input;
  447. }
  448. const parsed = parseURL(input);
  449. parsed.hash = hash === "" ? "" : "#" + encodeHash(hash);
  450. return stringifyParsedURL(parsed);
  451. }
  452. function withoutFragment(input) {
  453. return stringifyParsedURL({ ...parseURL(input), hash: "" });
  454. }
  455. function withoutHost(input) {
  456. const parsed = parseURL(input);
  457. return (parsed.pathname || "/") + parsed.search + parsed.hash;
  458. }
  459. const protocolRelative = Symbol.for("ufo:protocolRelative");
  460. function parseURL(input = "", defaultProto) {
  461. const _specialProtoMatch = input.match(
  462. /^[\s\0]*(blob:|data:|javascript:|vbscript:)(.*)/i
  463. );
  464. if (_specialProtoMatch) {
  465. const [, _proto, _pathname = ""] = _specialProtoMatch;
  466. return {
  467. protocol: _proto.toLowerCase(),
  468. pathname: _pathname,
  469. href: _proto + _pathname,
  470. auth: "",
  471. host: "",
  472. search: "",
  473. hash: ""
  474. };
  475. }
  476. if (!hasProtocol(input, { acceptRelative: true })) {
  477. return defaultProto ? parseURL(defaultProto + input) : parsePath(input);
  478. }
  479. const [, protocol = "", auth, hostAndPath = ""] = input.replace(/\\/g, "/").match(/^[\s\0]*([\w+.-]{2,}:)?\/\/([^/@]+@)?(.*)/) || [];
  480. let [, host = "", path = ""] = hostAndPath.match(/([^#/?]*)(.*)?/) || [];
  481. if (protocol === "file:") {
  482. path = path.replace(/\/(?=[A-Za-z]:)/, "");
  483. }
  484. const { pathname, search, hash } = parsePath(path);
  485. return {
  486. protocol: protocol.toLowerCase(),
  487. auth: auth ? auth.slice(0, Math.max(0, auth.length - 1)) : "",
  488. host,
  489. pathname,
  490. search,
  491. hash,
  492. [protocolRelative]: !protocol
  493. };
  494. }
  495. function parsePath(input = "") {
  496. const [pathname = "", search = "", hash = ""] = (input.match(/([^#?]*)(\?[^#]*)?(#.*)?/) || []).splice(1);
  497. return {
  498. pathname,
  499. search,
  500. hash
  501. };
  502. }
  503. function parseAuth(input = "") {
  504. const [username, password] = input.split(":");
  505. return {
  506. username: decode(username),
  507. password: decode(password)
  508. };
  509. }
  510. function parseHost(input = "") {
  511. const [hostname, port] = (input.match(/([^/:]*):?(\d+)?/) || []).splice(1);
  512. return {
  513. hostname: decode(hostname),
  514. port
  515. };
  516. }
  517. function stringifyParsedURL(parsed) {
  518. const pathname = parsed.pathname || "";
  519. const search = parsed.search ? (parsed.search.startsWith("?") ? "" : "?") + parsed.search : "";
  520. const hash = parsed.hash || "";
  521. const auth = parsed.auth ? parsed.auth + "@" : "";
  522. const host = parsed.host || "";
  523. const proto = parsed.protocol || parsed[protocolRelative] ? (parsed.protocol || "") + "//" : "";
  524. return proto + auth + host + pathname + search + hash;
  525. }
  526. const FILENAME_STRICT_REGEX = /\/([^/]+\.[^/]+)$/;
  527. const FILENAME_REGEX = /\/([^/]+)$/;
  528. function parseFilename(input = "", opts) {
  529. const { pathname } = parseURL(input);
  530. const matches = opts?.strict ? pathname.match(FILENAME_STRICT_REGEX) : pathname.match(FILENAME_REGEX);
  531. return matches ? matches[1] : void 0;
  532. }
  533. class $URL {
  534. protocol;
  535. host;
  536. auth;
  537. pathname;
  538. query = {};
  539. hash;
  540. constructor(input = "") {
  541. if (typeof input !== "string") {
  542. throw new TypeError(
  543. `URL input should be string received ${typeof input} (${input})`
  544. );
  545. }
  546. const parsed = parseURL(input);
  547. this.protocol = decode(parsed.protocol);
  548. this.host = decode(parsed.host);
  549. this.auth = decode(parsed.auth);
  550. this.pathname = decodePath(parsed.pathname);
  551. this.query = parseQuery(parsed.search);
  552. this.hash = decode(parsed.hash);
  553. }
  554. get hostname() {
  555. return parseHost(this.host).hostname;
  556. }
  557. get port() {
  558. return parseHost(this.host).port || "";
  559. }
  560. get username() {
  561. return parseAuth(this.auth).username;
  562. }
  563. get password() {
  564. return parseAuth(this.auth).password || "";
  565. }
  566. get hasProtocol() {
  567. return this.protocol.length;
  568. }
  569. get isAbsolute() {
  570. return this.hasProtocol || this.pathname[0] === "/";
  571. }
  572. get search() {
  573. const q = stringifyQuery(this.query);
  574. return q.length > 0 ? "?" + q : "";
  575. }
  576. get searchParams() {
  577. const p = new URLSearchParams();
  578. for (const name in this.query) {
  579. const value = this.query[name];
  580. if (Array.isArray(value)) {
  581. for (const v of value) {
  582. p.append(name, v);
  583. }
  584. } else {
  585. p.append(
  586. name,
  587. typeof value === "string" ? value : JSON.stringify(value)
  588. );
  589. }
  590. }
  591. return p;
  592. }
  593. get origin() {
  594. return (this.protocol ? this.protocol + "//" : "") + encodeHost(this.host);
  595. }
  596. get fullpath() {
  597. return encodePath(this.pathname) + this.search + encodeHash(this.hash);
  598. }
  599. get encodedAuth() {
  600. if (!this.auth) {
  601. return "";
  602. }
  603. const { username, password } = parseAuth(this.auth);
  604. return encodeURIComponent(username) + (password ? ":" + encodeURIComponent(password) : "");
  605. }
  606. get href() {
  607. const auth = this.encodedAuth;
  608. const originWithAuth = (this.protocol ? this.protocol + "//" : "") + (auth ? auth + "@" : "") + encodeHost(this.host);
  609. return this.hasProtocol && this.isAbsolute ? originWithAuth + this.fullpath : this.fullpath;
  610. }
  611. append(url) {
  612. if (url.hasProtocol) {
  613. throw new Error("Cannot append a URL with protocol");
  614. }
  615. Object.assign(this.query, url.query);
  616. if (url.pathname) {
  617. this.pathname = withTrailingSlash(this.pathname) + withoutLeadingSlash(url.pathname);
  618. }
  619. if (url.hash) {
  620. this.hash = url.hash;
  621. }
  622. }
  623. toJSON() {
  624. return this.href;
  625. }
  626. toString() {
  627. return this.href;
  628. }
  629. }
  630. function createURL(input) {
  631. return new $URL(input);
  632. }
  633. exports.$URL = $URL;
  634. exports.cleanDoubleSlashes = cleanDoubleSlashes;
  635. exports.createURL = createURL;
  636. exports.decode = decode;
  637. exports.decodePath = decodePath;
  638. exports.decodeQueryKey = decodeQueryKey;
  639. exports.decodeQueryValue = decodeQueryValue;
  640. exports.encode = encode;
  641. exports.encodeHash = encodeHash;
  642. exports.encodeHost = encodeHost;
  643. exports.encodeParam = encodeParam;
  644. exports.encodePath = encodePath;
  645. exports.encodeQueryItem = encodeQueryItem;
  646. exports.encodeQueryKey = encodeQueryKey;
  647. exports.encodeQueryValue = encodeQueryValue;
  648. exports.filterQuery = filterQuery;
  649. exports.getQuery = getQuery;
  650. exports.hasLeadingSlash = hasLeadingSlash;
  651. exports.hasProtocol = hasProtocol;
  652. exports.hasTrailingSlash = hasTrailingSlash;
  653. exports.isEmptyURL = isEmptyURL;
  654. exports.isEqual = isEqual;
  655. exports.isNonEmptyURL = isNonEmptyURL;
  656. exports.isRelative = isRelative;
  657. exports.isSamePath = isSamePath;
  658. exports.isScriptProtocol = isScriptProtocol;
  659. exports.joinRelativeURL = joinRelativeURL;
  660. exports.joinURL = joinURL;
  661. exports.normalizeURL = normalizeURL;
  662. exports.parseAuth = parseAuth;
  663. exports.parseFilename = parseFilename;
  664. exports.parseHost = parseHost;
  665. exports.parsePath = parsePath;
  666. exports.parseQuery = parseQuery;
  667. exports.parseURL = parseURL;
  668. exports.resolveURL = resolveURL;
  669. exports.stringifyParsedURL = stringifyParsedURL;
  670. exports.stringifyQuery = stringifyQuery;
  671. exports.withBase = withBase;
  672. exports.withFragment = withFragment;
  673. exports.withHttp = withHttp;
  674. exports.withHttps = withHttps;
  675. exports.withLeadingSlash = withLeadingSlash;
  676. exports.withProtocol = withProtocol;
  677. exports.withQuery = withQuery;
  678. exports.withTrailingSlash = withTrailingSlash;
  679. exports.withoutBase = withoutBase;
  680. exports.withoutFragment = withoutFragment;
  681. exports.withoutHost = withoutHost;
  682. exports.withoutLeadingSlash = withoutLeadingSlash;
  683. exports.withoutProtocol = withoutProtocol;
  684. exports.withoutTrailingSlash = withoutTrailingSlash;