@wevu/web-apis 1.3.4 → 1.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/abort.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as RequestGlobalsEventTarget } from "./shared-85INNxXV.mjs";
1
+ import { t as RequestGlobalsEventTarget } from "./shared-BI8xrWqd.mjs";
2
2
  //#region src/abort.ts
3
3
  function createAbortError(reason) {
4
4
  if (reason instanceof Error) return reason;
package/dist/fetch.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { d as normalizeHeaderName, h as isUrlSearchParamsInstance, l as isArrayBufferLike, m as isUrlInstance, n as cloneArrayBuffer, r as cloneArrayBufferView, u as isBlobLike } from "./shared-85INNxXV.mjs";
2
- import { a as encodeMultipartFormData, i as consumeBodyValue, n as RequestPolyfill, o as HeadersPolyfill, t as ResponsePolyfill } from "./http-mcdF3N9S.mjs";
3
- import { t as FormDataPolyfill } from "./web-uZ-hezcd.mjs";
1
+ import { d as normalizeHeaderName, h as isUrlSearchParamsInstance, l as isArrayBufferLike, m as isUrlInstance, n as cloneArrayBuffer, r as cloneArrayBufferView, u as isBlobLike } from "./shared-BI8xrWqd.mjs";
2
+ import { a as encodeMultipartFormData, i as consumeBodyValue, n as RequestPolyfill, o as HeadersPolyfill, t as ResponsePolyfill } from "./http-DFOOhYXD.mjs";
3
+ import { t as FormDataPolyfill } from "./web-DRnPgdkX.mjs";
4
4
  import { resolveRequestMiniProgramOptions } from "./networkDefaults.mjs";
5
5
  import { wpi } from "@wevu/api";
6
6
  //#region src/fetch.ts
@@ -1,5 +1,5 @@
1
- import { d as normalizeHeaderName, h as isUrlSearchParamsInstance, i as decodeText, l as isArrayBufferLike, m as isUrlInstance, n as cloneArrayBuffer, o as encodeText, r as cloneArrayBufferView, u as isBlobLike } from "./shared-85INNxXV.mjs";
2
- import { r as BlobPolyfill, t as FormDataPolyfill } from "./web-uZ-hezcd.mjs";
1
+ import { d as normalizeHeaderName, h as isUrlSearchParamsInstance, i as decodeText, l as isArrayBufferLike, m as isUrlInstance, n as cloneArrayBuffer, o as encodeText, r as cloneArrayBufferView, u as isBlobLike } from "./shared-BI8xrWqd.mjs";
2
+ import { r as BlobPolyfill, t as FormDataPolyfill } from "./web-DRnPgdkX.mjs";
3
3
  //#region src/http/headers.ts
4
4
  const SET_COOKIE_HEADER_NAME = "set-cookie";
5
5
  function isIterableHeaders(input) {
package/dist/http.mjs CHANGED
@@ -1,2 +1 @@
1
- import { n as RequestPolyfill, o as HeadersPolyfill, r as getRequestBodyValue, s as headersToObject, t as ResponsePolyfill } from "./http-mcdF3N9S.mjs";
2
- export { HeadersPolyfill, RequestPolyfill, ResponsePolyfill, getRequestBodyValue, headersToObject };
1
+ export { o as HeadersPolyfill, n as RequestPolyfill, t as ResponsePolyfill, r as getRequestBodyValue, s as headersToObject } from "./http-DFOOhYXD.mjs";
package/dist/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
- import { a as decodeTextFallback, c as installRequestGlobalBinding, f as resolveRequestGlobalsHost, l as isArrayBufferLike, n as cloneArrayBuffer, p as resolveRequestGlobalsHosts, r as cloneArrayBufferView, s as encodeTextFallback, t as RequestGlobalsEventTarget, v as getMiniProgramRuntimeGlobalKeys } from "./shared-85INNxXV.mjs";
2
- import { URLPolyfill, URLSearchParamsPolyfill } from "./url.mjs";
1
+ import { a as decodeTextFallback, c as installRequestGlobalBinding, f as resolveRequestGlobalsHost, l as isArrayBufferLike, n as cloneArrayBuffer, p as resolveRequestGlobalsHosts, r as cloneArrayBufferView, s as encodeTextFallback, t as RequestGlobalsEventTarget, v as getMiniProgramRuntimeGlobalKeys } from "./shared-BI8xrWqd.mjs";
2
+ import { n as URLSearchParamsPolyfill, t as URLPolyfill } from "./url-CBepYY5Q.mjs";
3
3
  import { AbortControllerPolyfill, AbortSignalPolyfill } from "./abort.mjs";
4
- import { n as RequestPolyfill, o as HeadersPolyfill, t as ResponsePolyfill } from "./http-mcdF3N9S.mjs";
5
- import { n as FilePolyfill, r as BlobPolyfill, t as FormDataPolyfill } from "./web-uZ-hezcd.mjs";
4
+ import { n as RequestPolyfill, o as HeadersPolyfill, t as ResponsePolyfill } from "./http-DFOOhYXD.mjs";
5
+ import { n as FilePolyfill, r as BlobPolyfill, t as FormDataPolyfill } from "./web-DRnPgdkX.mjs";
6
6
  import { getMiniProgramNetworkDefaults, resetMiniProgramNetworkDefaults, setMiniProgramNetworkDefaults } from "./networkDefaults.mjs";
7
7
  import { fetch } from "./fetch.mjs";
8
8
  import { WebSocketPolyfill } from "./websocket.mjs";
@@ -1,11 +1,7 @@
1
- import { WeapiMiniProgramConnectSocketOption, WeapiMiniProgramRequestOption } from "@wevu/api";
1
+ import { WeapiMiniProgramRequestDefaults, WeapiMiniProgramSocketDefaults } from "@weapp-core/api/network-options";
2
2
  //#region src/networkDefaults.d.ts
3
- declare const MINI_PROGRAM_REQUEST_OPTION_KEYS: readonly ["enableCache", "enableChunked", "enableHttp2", "enableHttpDNS", "enableProfile", "enableQuic", "forceCellularNetwork", "httpDNSServiceId", "httpDNSTimeout", "redirect", "timeout", "useHighPerformanceMode"];
4
- declare const MINI_PROGRAM_SOCKET_OPTION_KEYS: readonly ["forceCellularNetwork", "header", "perMessageDeflate", "timeout"];
5
- type RequestGlobalsMiniProgramOptionKey = typeof MINI_PROGRAM_REQUEST_OPTION_KEYS[number];
6
- type WebSocketMiniProgramOptionKey = typeof MINI_PROGRAM_SOCKET_OPTION_KEYS[number];
7
- export type RequestGlobalsMiniProgramOptions = Pick<Partial<WeapiMiniProgramRequestOption>, RequestGlobalsMiniProgramOptionKey>;
8
- export type WebSocketMiniProgramOptions = Pick<Partial<WeapiMiniProgramConnectSocketOption>, WebSocketMiniProgramOptionKey>;
3
+ export type RequestGlobalsMiniProgramOptions = WeapiMiniProgramRequestDefaults;
4
+ export type WebSocketMiniProgramOptions = WeapiMiniProgramSocketDefaults;
9
5
  export interface MiniProgramNetworkDefaults {
10
6
  request?: RequestGlobalsMiniProgramOptions;
11
7
  socket?: WebSocketMiniProgramOptions;
@@ -15,6 +11,6 @@ export declare function normalizeWebSocketMiniProgramOptions(...sources: unknown
15
11
  export declare function getMiniProgramNetworkDefaults(): MiniProgramNetworkDefaults;
16
12
  export declare function setMiniProgramNetworkDefaults(defaults?: MiniProgramNetworkDefaults): MiniProgramNetworkDefaults;
17
13
  export declare function resetMiniProgramNetworkDefaults(): MiniProgramNetworkDefaults;
18
- export declare function resolveRequestMiniProgramOptions(...sources: unknown[]): RequestGlobalsMiniProgramOptions;
19
- export declare function resolveWebSocketMiniProgramOptions(...sources: unknown[]): WebSocketMiniProgramOptions;
14
+ export declare function resolveRequestMiniProgramOptions(...sources: unknown[]): WeapiMiniProgramRequestDefaults;
15
+ export declare function resolveWebSocketMiniProgramOptions(...sources: unknown[]): WeapiMiniProgramSocketDefaults;
20
16
  //#endregion
@@ -1,4 +1,4 @@
1
- import { URLPolyfill, URLSearchParamsPolyfill } from "./url.mjs";
1
+ import { n as URLSearchParamsPolyfill, t as URLPolyfill } from "./url-CBepYY5Q.mjs";
2
2
  //#region ../../@weapp-core/shared/dist/platforms/runtime/descriptors.js
3
3
  const DEFAULT_RUNTIME_HOST_CONFIG_KEY = "__wxConfig";
4
4
  const DEFAULT_RUNTIME_CAPABILITIES = Object.freeze({
package/dist/shared.mjs CHANGED
@@ -1,2 +1 @@
1
- import { a as decodeTextFallback, c as installRequestGlobalBinding, d as normalizeHeaderName, f as resolveRequestGlobalsHost, i as decodeText, l as isArrayBufferLike, n as cloneArrayBuffer, o as encodeText, p as resolveRequestGlobalsHosts, r as cloneArrayBufferView, s as encodeTextFallback, t as RequestGlobalsEventTarget, u as isBlobLike } from "./shared-85INNxXV.mjs";
2
- export { RequestGlobalsEventTarget, cloneArrayBuffer, cloneArrayBufferView, decodeText, decodeTextFallback, encodeText, encodeTextFallback, installRequestGlobalBinding, isArrayBufferLike, isBlobLike, normalizeHeaderName, resolveRequestGlobalsHost, resolveRequestGlobalsHosts };
1
+ export { t as RequestGlobalsEventTarget, n as cloneArrayBuffer, r as cloneArrayBufferView, i as decodeText, a as decodeTextFallback, o as encodeText, s as encodeTextFallback, c as installRequestGlobalBinding, l as isArrayBufferLike, u as isBlobLike, d as normalizeHeaderName, f as resolveRequestGlobalsHost, p as resolveRequestGlobalsHosts } from "./shared-BI8xrWqd.mjs";
@@ -0,0 +1,287 @@
1
+ //#region src/url/decodeSearchParam.ts
2
+ const PLUS_REGEXP = /\+/g;
3
+ const ENCODED_BYTES_REGEXP = /(?:%[\da-f]{2})+/gi;
4
+ function decodePercentBytes(encoded) {
5
+ const bytes = [];
6
+ for (let index = 0; index < encoded.length; index += 3) bytes.push(Number.parseInt(encoded.slice(index + 1, index + 3), 16));
7
+ let result = "";
8
+ let index = 0;
9
+ while (index < bytes.length) {
10
+ const first = bytes[index++];
11
+ if (first < 128) {
12
+ result += String.fromCharCode(first);
13
+ continue;
14
+ }
15
+ let remaining;
16
+ let point;
17
+ let lower = 128;
18
+ let upper = 191;
19
+ if (first >= 194 && first <= 223) {
20
+ remaining = 1;
21
+ point = first & 31;
22
+ } else if (first >= 224 && first <= 239) {
23
+ remaining = 2;
24
+ point = first & 15;
25
+ if (first === 224) lower = 160;
26
+ if (first === 237) upper = 159;
27
+ } else if (first >= 240 && first <= 244) {
28
+ remaining = 3;
29
+ point = first & 7;
30
+ if (first === 240) lower = 144;
31
+ if (first === 244) upper = 143;
32
+ } else {
33
+ result += "�";
34
+ continue;
35
+ }
36
+ while (remaining > 0 && index < bytes.length) {
37
+ const next = bytes[index];
38
+ if (next < lower || next > upper) break;
39
+ point = point << 6 | next & 63;
40
+ index++;
41
+ remaining--;
42
+ lower = 128;
43
+ upper = 191;
44
+ }
45
+ if (remaining > 0) result += "�";
46
+ else if (point <= 65535) result += String.fromCharCode(point);
47
+ else {
48
+ point -= 65536;
49
+ result += String.fromCharCode(55296 + (point >> 10), 56320 + (point & 1023));
50
+ }
51
+ }
52
+ return result;
53
+ }
54
+ function decodeSearchParam(value) {
55
+ const source = value.replace(PLUS_REGEXP, " ");
56
+ try {
57
+ return decodeURIComponent(source);
58
+ } catch {
59
+ return source.replace(ENCODED_BYTES_REGEXP, decodePercentBytes);
60
+ }
61
+ }
62
+ //#endregion
63
+ //#region src/url.ts
64
+ const LEADING_QUERY_REGEXP = /^\?/;
65
+ const ABSOLUTE_URL_REGEXP = /^([a-z][a-z\d+.-]*:)?\/\/([^/?#]+)(\/[^?#]*)?(\?[^#]*)?(#.*)?$/i;
66
+ const ABSOLUTE_URL_PREFIX_REGEXP = /^[a-z][a-z\d+.-]*:\/\//i;
67
+ const ENCODED_SPACE_REGEXP = /%20/g;
68
+ const HOST_WITH_PORT_REGEXP = /^([^:]*)(?::(.*))?$/;
69
+ function encodeSearchParam(value) {
70
+ return encodeURIComponent(value).replace(ENCODED_SPACE_REGEXP, "+");
71
+ }
72
+ function normalizeSearchSource(input) {
73
+ return input.replace(LEADING_QUERY_REGEXP, "");
74
+ }
75
+ function parseSearchEntries(input) {
76
+ if (!input) return [];
77
+ return normalizeSearchSource(input).split("&").filter(Boolean).map((segment) => {
78
+ const separatorIndex = segment.indexOf("=");
79
+ if (separatorIndex === -1) return [decodeSearchParam(segment), ""];
80
+ return [decodeSearchParam(segment.slice(0, separatorIndex)), decodeSearchParam(segment.slice(separatorIndex + 1))];
81
+ });
82
+ }
83
+ function serializeSearchEntries(entries) {
84
+ return entries.map(([key, value]) => `${encodeSearchParam(key)}=${encodeSearchParam(value)}`).join("&");
85
+ }
86
+ function parseAbsoluteUrl(input) {
87
+ const match = input.match(ABSOLUTE_URL_REGEXP);
88
+ if (!match) return null;
89
+ const protocol = match[1] ?? "";
90
+ const host = match[2];
91
+ const pathname = match[3] || "/";
92
+ const search = match[4] ?? "";
93
+ const hash = match[5] ?? "";
94
+ const hostnameMatch = host.match(HOST_WITH_PORT_REGEXP);
95
+ return {
96
+ protocol,
97
+ host,
98
+ hostname: hostnameMatch[1],
99
+ port: hostnameMatch?.[2] ?? "",
100
+ pathname,
101
+ search,
102
+ hash,
103
+ origin: protocol && host ? `${protocol}//${host}` : "",
104
+ href: `${protocol}//${host}${pathname}${search}${hash}`
105
+ };
106
+ }
107
+ function resolveRelativeUrl(input, base) {
108
+ const parsedBase = parseAbsoluteUrl(base);
109
+ if (!parsedBase) throw new TypeError(`Failed to construct URL from base ${base}`);
110
+ if (input.startsWith("//")) return `${parsedBase.protocol}${input}`;
111
+ if (input.startsWith("/")) return `${parsedBase.origin}${input}`;
112
+ if (input.startsWith("?") || input.startsWith("#")) return `${`${parsedBase.origin}${parsedBase.pathname}`}${input}`;
113
+ const basePathSegments = parsedBase.pathname.split("/").slice(0, -1);
114
+ for (const segment of input.split("/")) {
115
+ if (!segment || segment === ".") continue;
116
+ if (segment === "..") {
117
+ basePathSegments.pop();
118
+ continue;
119
+ }
120
+ basePathSegments.push(segment);
121
+ }
122
+ return `${parsedBase.origin}${basePathSegments.join("/")}`;
123
+ }
124
+ var URLSearchParamsPolyfill = class {
125
+ onChange;
126
+ entriesStore = [];
127
+ constructor(init, onChange) {
128
+ this.onChange = onChange;
129
+ if (init == null) return;
130
+ if (typeof init === "string") {
131
+ this.entriesStore.push(...parseSearchEntries(init));
132
+ return;
133
+ }
134
+ if (typeof init[Symbol.iterator] === "function") {
135
+ for (const [key, value] of init) this.append(key, value);
136
+ return;
137
+ }
138
+ for (const [key, value] of Object.entries(init)) {
139
+ if (Array.isArray(value)) {
140
+ for (const item of value) this.append(key, item);
141
+ continue;
142
+ }
143
+ this.append(key, value);
144
+ }
145
+ }
146
+ append(key, value) {
147
+ this.entriesStore.push([String(key), String(value)]);
148
+ this.onChange?.();
149
+ }
150
+ delete(key) {
151
+ const normalizedKey = String(key);
152
+ let changed = false;
153
+ for (let i = this.entriesStore.length - 1; i >= 0; i--) if (this.entriesStore[i]?.[0] === normalizedKey) {
154
+ this.entriesStore.splice(i, 1);
155
+ changed = true;
156
+ }
157
+ if (changed) this.onChange?.();
158
+ }
159
+ get(key) {
160
+ const normalizedKey = String(key);
161
+ const found = this.entriesStore.find(([entryKey]) => entryKey === normalizedKey);
162
+ return found ? found[1] : null;
163
+ }
164
+ getAll(key) {
165
+ const normalizedKey = String(key);
166
+ return this.entriesStore.filter(([entryKey]) => entryKey === normalizedKey).map(([, value]) => value);
167
+ }
168
+ has(key) {
169
+ return this.entriesStore.some(([entryKey]) => entryKey === String(key));
170
+ }
171
+ get size() {
172
+ return this.entriesStore.length;
173
+ }
174
+ set(key, value) {
175
+ this.delete(key);
176
+ this.append(key, value);
177
+ }
178
+ sort() {
179
+ this.entriesStore.sort(([leftKey], [rightKey]) => {
180
+ if (leftKey < rightKey) return -1;
181
+ if (leftKey > rightKey) return 1;
182
+ return 0;
183
+ });
184
+ this.onChange?.();
185
+ }
186
+ forEach(callback) {
187
+ for (const [key, value] of this.entriesStore) callback(value, key);
188
+ }
189
+ entries() {
190
+ return this.entriesStore[Symbol.iterator]();
191
+ }
192
+ keys() {
193
+ return this.entriesStore.map(([key]) => key)[Symbol.iterator]();
194
+ }
195
+ values() {
196
+ return this.entriesStore.map(([, value]) => value)[Symbol.iterator]();
197
+ }
198
+ toString() {
199
+ return serializeSearchEntries(this.entriesStore);
200
+ }
201
+ [Symbol.iterator]() {
202
+ return this.entries();
203
+ }
204
+ };
205
+ var URLPolyfill = class URLPolyfill {
206
+ hashValue = "";
207
+ hrefValue = "";
208
+ searchValue = "";
209
+ host = "";
210
+ hostname = "";
211
+ origin = "";
212
+ password = "";
213
+ pathname = "/";
214
+ port = "";
215
+ protocol = "";
216
+ username = "";
217
+ searchParams;
218
+ static canParse(input, base) {
219
+ return URLPolyfill.parse(input, base) !== null;
220
+ }
221
+ static parse(input, base) {
222
+ try {
223
+ return new URLPolyfill(input, base);
224
+ } catch {
225
+ return null;
226
+ }
227
+ }
228
+ constructor(input, base) {
229
+ const inputString = typeof input === "string" ? input : input.toString();
230
+ const baseString = typeof base === "string" ? base : base ? base.toString() : void 0;
231
+ const parsed = parseAbsoluteUrl(ABSOLUTE_URL_PREFIX_REGEXP.test(inputString) ? inputString : baseString ? resolveRelativeUrl(inputString, baseString) : inputString);
232
+ if (!parsed) throw new TypeError(`Failed to construct URL from ${inputString}`);
233
+ this.protocol = parsed.protocol;
234
+ this.host = parsed.host;
235
+ this.hostname = parsed.hostname;
236
+ this.port = parsed.port;
237
+ this.pathname = parsed.pathname;
238
+ this.searchValue = parsed.search;
239
+ this.hashValue = parsed.hash;
240
+ this.origin = parsed.origin;
241
+ this.searchParams = new URLSearchParamsPolyfill(parsed.search, () => {
242
+ this.syncSearchFromParams();
243
+ });
244
+ this.updateHref();
245
+ }
246
+ get hash() {
247
+ return this.hashValue;
248
+ }
249
+ set hash(value) {
250
+ this.hashValue = value ? value.startsWith("#") ? value : `#${value}` : "";
251
+ this.updateHref();
252
+ }
253
+ get href() {
254
+ return this.hrefValue;
255
+ }
256
+ get search() {
257
+ return this.searchValue;
258
+ }
259
+ set search(value) {
260
+ this.searchValue = value ? value.startsWith("?") ? value : `?${value}` : "";
261
+ this.resetSearchParams(this.searchValue);
262
+ this.updateHref();
263
+ }
264
+ toString() {
265
+ return this.hrefValue;
266
+ }
267
+ toJSON() {
268
+ return this.toString();
269
+ }
270
+ resetSearchParams(value) {
271
+ const nextParams = new URLSearchParamsPolyfill(value);
272
+ this.searchParams.entriesStore.splice(0, this.searchParams.entriesStore.length);
273
+ nextParams.forEach((entryValue, entryKey) => {
274
+ this.searchParams.entriesStore.push([entryKey, entryValue]);
275
+ });
276
+ }
277
+ updateHref() {
278
+ this.hrefValue = `${this.protocol}//${this.host}${this.pathname}${this.searchValue}${this.hashValue}`;
279
+ }
280
+ syncSearchFromParams() {
281
+ const search = this.searchParams.toString();
282
+ this.searchValue = search ? `?${search}` : "";
283
+ this.updateHref();
284
+ }
285
+ };
286
+ //#endregion
287
+ export { URLSearchParamsPolyfill as n, URLPolyfill as t };
package/dist/url.mjs CHANGED
@@ -1,229 +1 @@
1
- //#region src/url.ts
2
- const PLUS_REGEXP = /\+/g;
3
- const LEADING_QUERY_REGEXP = /^\?/;
4
- const ABSOLUTE_URL_REGEXP = /^([a-z][a-z\d+.-]*:)?\/\/([^/?#]+)(\/[^?#]*)?(\?[^#]*)?(#.*)?$/i;
5
- const ABSOLUTE_URL_PREFIX_REGEXP = /^[a-z][a-z\d+.-]*:\/\//i;
6
- const ENCODED_SPACE_REGEXP = /%20/g;
7
- const HOST_WITH_PORT_REGEXP = /^([^:]*)(?::(.*))?$/;
8
- function encodeSearchParam(value) {
9
- return encodeURIComponent(value).replace(ENCODED_SPACE_REGEXP, "+");
10
- }
11
- function decodeSearchParam(value) {
12
- return decodeURIComponent(value.replace(PLUS_REGEXP, " "));
13
- }
14
- function normalizeSearchSource(input) {
15
- return input.replace(LEADING_QUERY_REGEXP, "");
16
- }
17
- function parseSearchEntries(input) {
18
- if (!input) return [];
19
- return normalizeSearchSource(input).split("&").filter(Boolean).map((segment) => {
20
- const separatorIndex = segment.indexOf("=");
21
- if (separatorIndex === -1) return [decodeSearchParam(segment), ""];
22
- return [decodeSearchParam(segment.slice(0, separatorIndex)), decodeSearchParam(segment.slice(separatorIndex + 1))];
23
- });
24
- }
25
- function serializeSearchEntries(entries) {
26
- return entries.map(([key, value]) => `${encodeSearchParam(key)}=${encodeSearchParam(value)}`).join("&");
27
- }
28
- function parseAbsoluteUrl(input) {
29
- const match = input.match(ABSOLUTE_URL_REGEXP);
30
- if (!match) return null;
31
- const protocol = match[1] ?? "";
32
- const host = match[2];
33
- const pathname = match[3] || "/";
34
- const search = match[4] ?? "";
35
- const hash = match[5] ?? "";
36
- const hostnameMatch = host.match(HOST_WITH_PORT_REGEXP);
37
- return {
38
- protocol,
39
- host,
40
- hostname: hostnameMatch[1],
41
- port: hostnameMatch?.[2] ?? "",
42
- pathname,
43
- search,
44
- hash,
45
- origin: protocol && host ? `${protocol}//${host}` : "",
46
- href: `${protocol}//${host}${pathname}${search}${hash}`
47
- };
48
- }
49
- function resolveRelativeUrl(input, base) {
50
- const parsedBase = parseAbsoluteUrl(base);
51
- if (!parsedBase) throw new TypeError(`Failed to construct URL from base ${base}`);
52
- if (input.startsWith("//")) return `${parsedBase.protocol}${input}`;
53
- if (input.startsWith("/")) return `${parsedBase.origin}${input}`;
54
- if (input.startsWith("?") || input.startsWith("#")) return `${`${parsedBase.origin}${parsedBase.pathname}`}${input}`;
55
- const basePathSegments = parsedBase.pathname.split("/").slice(0, -1);
56
- for (const segment of input.split("/")) {
57
- if (!segment || segment === ".") continue;
58
- if (segment === "..") {
59
- basePathSegments.pop();
60
- continue;
61
- }
62
- basePathSegments.push(segment);
63
- }
64
- return `${parsedBase.origin}${basePathSegments.join("/")}`;
65
- }
66
- var URLSearchParamsPolyfill = class {
67
- onChange;
68
- entriesStore = [];
69
- constructor(init, onChange) {
70
- this.onChange = onChange;
71
- if (init == null) return;
72
- if (typeof init === "string") {
73
- this.entriesStore.push(...parseSearchEntries(init));
74
- return;
75
- }
76
- if (typeof init[Symbol.iterator] === "function") {
77
- for (const [key, value] of init) this.append(key, value);
78
- return;
79
- }
80
- for (const [key, value] of Object.entries(init)) {
81
- if (Array.isArray(value)) {
82
- for (const item of value) this.append(key, item);
83
- continue;
84
- }
85
- this.append(key, value);
86
- }
87
- }
88
- append(key, value) {
89
- this.entriesStore.push([String(key), String(value)]);
90
- this.onChange?.();
91
- }
92
- delete(key) {
93
- const normalizedKey = String(key);
94
- let changed = false;
95
- for (let i = this.entriesStore.length - 1; i >= 0; i--) if (this.entriesStore[i]?.[0] === normalizedKey) {
96
- this.entriesStore.splice(i, 1);
97
- changed = true;
98
- }
99
- if (changed) this.onChange?.();
100
- }
101
- get(key) {
102
- const normalizedKey = String(key);
103
- const found = this.entriesStore.find(([entryKey]) => entryKey === normalizedKey);
104
- return found ? found[1] : null;
105
- }
106
- getAll(key) {
107
- const normalizedKey = String(key);
108
- return this.entriesStore.filter(([entryKey]) => entryKey === normalizedKey).map(([, value]) => value);
109
- }
110
- has(key) {
111
- return this.entriesStore.some(([entryKey]) => entryKey === String(key));
112
- }
113
- get size() {
114
- return this.entriesStore.length;
115
- }
116
- set(key, value) {
117
- this.delete(key);
118
- this.append(key, value);
119
- }
120
- sort() {
121
- this.entriesStore.sort(([leftKey], [rightKey]) => {
122
- if (leftKey < rightKey) return -1;
123
- if (leftKey > rightKey) return 1;
124
- return 0;
125
- });
126
- this.onChange?.();
127
- }
128
- forEach(callback) {
129
- for (const [key, value] of this.entriesStore) callback(value, key);
130
- }
131
- entries() {
132
- return this.entriesStore[Symbol.iterator]();
133
- }
134
- keys() {
135
- return this.entriesStore.map(([key]) => key)[Symbol.iterator]();
136
- }
137
- values() {
138
- return this.entriesStore.map(([, value]) => value)[Symbol.iterator]();
139
- }
140
- toString() {
141
- return serializeSearchEntries(this.entriesStore);
142
- }
143
- [Symbol.iterator]() {
144
- return this.entries();
145
- }
146
- };
147
- var URLPolyfill = class URLPolyfill {
148
- hashValue = "";
149
- hrefValue = "";
150
- searchValue = "";
151
- host = "";
152
- hostname = "";
153
- origin = "";
154
- password = "";
155
- pathname = "/";
156
- port = "";
157
- protocol = "";
158
- username = "";
159
- searchParams;
160
- static canParse(input, base) {
161
- return URLPolyfill.parse(input, base) !== null;
162
- }
163
- static parse(input, base) {
164
- try {
165
- return new URLPolyfill(input, base);
166
- } catch {
167
- return null;
168
- }
169
- }
170
- constructor(input, base) {
171
- const inputString = typeof input === "string" ? input : input.toString();
172
- const baseString = typeof base === "string" ? base : base ? base.toString() : void 0;
173
- const parsed = parseAbsoluteUrl(ABSOLUTE_URL_PREFIX_REGEXP.test(inputString) ? inputString : baseString ? resolveRelativeUrl(inputString, baseString) : inputString);
174
- if (!parsed) throw new TypeError(`Failed to construct URL from ${inputString}`);
175
- this.protocol = parsed.protocol;
176
- this.host = parsed.host;
177
- this.hostname = parsed.hostname;
178
- this.port = parsed.port;
179
- this.pathname = parsed.pathname;
180
- this.searchValue = parsed.search;
181
- this.hashValue = parsed.hash;
182
- this.origin = parsed.origin;
183
- this.searchParams = new URLSearchParamsPolyfill(parsed.search, () => {
184
- this.syncSearchFromParams();
185
- });
186
- this.updateHref();
187
- }
188
- get hash() {
189
- return this.hashValue;
190
- }
191
- set hash(value) {
192
- this.hashValue = value ? value.startsWith("#") ? value : `#${value}` : "";
193
- this.updateHref();
194
- }
195
- get href() {
196
- return this.hrefValue;
197
- }
198
- get search() {
199
- return this.searchValue;
200
- }
201
- set search(value) {
202
- this.searchValue = value ? value.startsWith("?") ? value : `?${value}` : "";
203
- this.resetSearchParams(this.searchValue);
204
- this.updateHref();
205
- }
206
- toString() {
207
- return this.hrefValue;
208
- }
209
- toJSON() {
210
- return this.toString();
211
- }
212
- resetSearchParams(value) {
213
- const nextParams = new URLSearchParamsPolyfill(value);
214
- this.searchParams.entriesStore.splice(0, this.searchParams.entriesStore.length);
215
- nextParams.forEach((entryValue, entryKey) => {
216
- this.searchParams.entriesStore.push([entryKey, entryValue]);
217
- });
218
- }
219
- updateHref() {
220
- this.hrefValue = `${this.protocol}//${this.host}${this.pathname}${this.searchValue}${this.hashValue}`;
221
- }
222
- syncSearchFromParams() {
223
- const search = this.searchParams.toString();
224
- this.searchValue = search ? `?${search}` : "";
225
- this.updateHref();
226
- }
227
- };
228
- //#endregion
229
- export { URLPolyfill, URLSearchParamsPolyfill };
1
+ export { t as URLPolyfill, n as URLSearchParamsPolyfill } from "./url-CBepYY5Q.mjs";
@@ -1,4 +1,4 @@
1
- import { i as decodeText, l as isArrayBufferLike, n as cloneArrayBuffer, o as encodeText, r as cloneArrayBufferView, u as isBlobLike } from "./shared-85INNxXV.mjs";
1
+ import { i as decodeText, l as isArrayBufferLike, n as cloneArrayBuffer, o as encodeText, r as cloneArrayBufferView, u as isBlobLike } from "./shared-BI8xrWqd.mjs";
2
2
  //#region src/web/blob.ts
3
3
  const segments = /* @__PURE__ */ new WeakMap();
4
4
  /** Blob 的 MIME 类型只接受可打印 ASCII,并按标准转换成小写。 */
package/dist/web.mjs CHANGED
@@ -1,2 +1 @@
1
- import { n as FilePolyfill, r as BlobPolyfill, t as FormDataPolyfill } from "./web-uZ-hezcd.mjs";
2
- export { BlobPolyfill, FilePolyfill, FormDataPolyfill };
1
+ export { r as BlobPolyfill, n as FilePolyfill, t as FormDataPolyfill } from "./web-DRnPgdkX.mjs";
@@ -54,4 +54,5 @@ export declare class WebSocketPolyfill extends RequestGlobalsEventTarget {
54
54
  private closeFromRuntime;
55
55
  private emitError;
56
56
  }
57
- //#endregion
57
+ //#endregion
58
+ export {};
@@ -1,6 +1,6 @@
1
- import { _ as resolveUrlConstructor$1, g as resolveTextEncoderConstructor, l as isArrayBufferLike, n as cloneArrayBuffer, r as cloneArrayBufferView, t as RequestGlobalsEventTarget, u as isBlobLike } from "./shared-85INNxXV.mjs";
2
- import { URLPolyfill } from "./url.mjs";
3
- import { r as BlobPolyfill } from "./web-uZ-hezcd.mjs";
1
+ import { _ as resolveUrlConstructor$1, g as resolveTextEncoderConstructor, l as isArrayBufferLike, n as cloneArrayBuffer, r as cloneArrayBufferView, t as RequestGlobalsEventTarget, u as isBlobLike } from "./shared-BI8xrWqd.mjs";
2
+ import { t as URLPolyfill } from "./url-CBepYY5Q.mjs";
3
+ import { r as BlobPolyfill } from "./web-DRnPgdkX.mjs";
4
4
  import { resolveWebSocketMiniProgramOptions } from "./networkDefaults.mjs";
5
5
  import { wpi } from "@wevu/api";
6
6
  //#region src/websocket.ts
package/dist/xhr.d.mts CHANGED
@@ -65,4 +65,5 @@ export declare class XMLHttpRequestPolyfill extends RequestGlobalsEventTarget {
65
65
  private finish;
66
66
  private transitionTo;
67
67
  }
68
- //#endregion
68
+ //#endregion
69
+ export {};
package/dist/xhr.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { f as resolveRequestGlobalsHost, t as RequestGlobalsEventTarget } from "./shared-85INNxXV.mjs";
1
+ import { f as resolveRequestGlobalsHost, t as RequestGlobalsEventTarget } from "./shared-BI8xrWqd.mjs";
2
2
  import { AbortControllerPolyfill } from "./abort.mjs";
3
- import { o as HeadersPolyfill, s as headersToObject } from "./http-mcdF3N9S.mjs";
3
+ import { o as HeadersPolyfill, s as headersToObject } from "./http-DFOOhYXD.mjs";
4
4
  import { fetch } from "./fetch.mjs";
5
5
  //#region src/xhr.ts
6
6
  function createProgressEvent(type) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wevu/web-apis",
3
3
  "type": "module",
4
- "version": "1.3.4",
4
+ "version": "1.3.6",
5
5
  "description": "Web API polyfills and global installers for mini-program runtimes",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -79,13 +79,21 @@
79
79
  "node": "^20.19.0 || >=22.12.0"
80
80
  },
81
81
  "dependencies": {
82
- "@weapp-core/constants": "0.3.0",
83
- "@wevu/api": "0.3.7"
82
+ "@weapp-core/api": "0.3.9",
83
+ "@weapp-core/constants": "0.4.0",
84
+ "@wevu/api": "0.3.9"
84
85
  },
85
86
  "publishConfig": {
86
87
  "access": "public",
87
88
  "registry": "https://registry.npmjs.org"
88
89
  },
90
+ "tsd": {
91
+ "compilerOptions": {
92
+ "module": "NodeNext",
93
+ "moduleResolution": "NodeNext",
94
+ "paths": {}
95
+ }
96
+ },
89
97
  "scripts": {
90
98
  "dev": "tsdown -w --sourcemap",
91
99
  "build": "tsdown",
@@ -93,7 +101,9 @@
93
101
  "test:coverage": "cross-env WEAPP_VITE_WEB_COVERAGE_STRICT=1 vitest run --coverage",
94
102
  "test:dev": "vitest",
95
103
  "pretest:types": "pnpm build",
96
- "test:types": "tsd",
97
- "typecheck": "tsc --noEmit"
104
+ "test:types": "pnpm run test:types:check",
105
+ "test:types:check": "tsd --files \"test-d/**/*.test-d.ts\" && pnpm run test:types:pure",
106
+ "typecheck": "tsc --noEmit",
107
+ "test:types:pure": "cd test-d-pure && tsd --files \"**/*.test-d.ts\""
98
108
  }
99
109
  }