@wevu/web-apis 1.2.42 → 1.3.0
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/README.md +28 -0
- package/dist/abort.d.mts +1 -1
- package/dist/fetch.d.mts +1 -1
- package/dist/fetch.mjs +187 -2
- package/dist/http-C-VyEBss.mjs +303 -0
- package/dist/http-CE8-CIHE.d.mts +66 -0
- package/dist/http.d.mts +2 -58
- package/dist/http.mjs +1 -219
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +3 -3
- package/dist/shared-Dc42USJC.d.mts +39 -0
- package/dist/shared.d.mts +2 -38
- package/dist/url-D0ANYIyk.d.mts +50 -0
- package/dist/url.d.mts +2 -49
- package/dist/web-DNBBg6y9.d.mts +51 -0
- package/dist/web-kSAO_PSD.mjs +178 -0
- package/dist/web.d.mts +2 -43
- package/dist/web.mjs +1 -115
- package/dist/websocket.d.mts +2 -2
- package/dist/websocket.mjs +1 -1
- package/dist/xhr.d.mts +1 -1
- package/dist/xhr.mjs +2 -2
- package/package.json +3 -3
- package/dist/fetch-BPqcYqI3.mjs +0 -243
package/dist/http.mjs
CHANGED
|
@@ -1,220 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { FormDataPolyfill } from "./web.mjs";
|
|
3
|
-
//#region src/http.ts
|
|
4
|
-
const SET_COOKIE_HEADER_NAME = "set-cookie";
|
|
5
|
-
function isIterableHeaders(input) {
|
|
6
|
-
return Boolean(input) && typeof input[Symbol.iterator] === "function";
|
|
7
|
-
}
|
|
8
|
-
function isHeaderObject(input) {
|
|
9
|
-
return typeof input === "object" && input !== null;
|
|
10
|
-
}
|
|
11
|
-
var HeadersPolyfill = class {
|
|
12
|
-
store = /* @__PURE__ */ new Map();
|
|
13
|
-
constructor(init) {
|
|
14
|
-
if (!init) return;
|
|
15
|
-
if (isIterableHeaders(init)) {
|
|
16
|
-
for (const [key, value] of init) this.append(key, value);
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
if (typeof init.forEach === "function") {
|
|
20
|
-
init.forEach((value, key) => {
|
|
21
|
-
this.set(key, value);
|
|
22
|
-
});
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
if (isHeaderObject(init)) for (const [key, value] of Object.entries(init)) this.append(key, Array.isArray(value) ? value.join(", ") : String(value));
|
|
26
|
-
}
|
|
27
|
-
append(key, value) {
|
|
28
|
-
const normalized = normalizeHeaderName(key);
|
|
29
|
-
if (!normalized) return;
|
|
30
|
-
const item = this.store.get(normalized);
|
|
31
|
-
if (item) {
|
|
32
|
-
item.values.push(String(value));
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
this.store.set(normalized, {
|
|
36
|
-
key,
|
|
37
|
-
values: [String(value)]
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
set(key, value) {
|
|
41
|
-
const normalized = normalizeHeaderName(key);
|
|
42
|
-
if (!normalized) return;
|
|
43
|
-
this.store.set(normalized, {
|
|
44
|
-
key,
|
|
45
|
-
values: [String(value)]
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
get(key) {
|
|
49
|
-
return this.store.get(normalizeHeaderName(key))?.values.join(", ") ?? null;
|
|
50
|
-
}
|
|
51
|
-
getSetCookie() {
|
|
52
|
-
return this.store.get(SET_COOKIE_HEADER_NAME)?.values.slice() ?? [];
|
|
53
|
-
}
|
|
54
|
-
has(key) {
|
|
55
|
-
return this.store.has(normalizeHeaderName(key));
|
|
56
|
-
}
|
|
57
|
-
delete(key) {
|
|
58
|
-
this.store.delete(normalizeHeaderName(key));
|
|
59
|
-
}
|
|
60
|
-
forEach(callback) {
|
|
61
|
-
for (const { key, values } of this.store.values()) callback(values.join(", "), key);
|
|
62
|
-
}
|
|
63
|
-
entries() {
|
|
64
|
-
return Array.from(this.store.values(), (item) => [item.key, item.values.join(", ")])[Symbol.iterator]();
|
|
65
|
-
}
|
|
66
|
-
keys() {
|
|
67
|
-
return Array.from(this.store.values(), (item) => item.key)[Symbol.iterator]();
|
|
68
|
-
}
|
|
69
|
-
values() {
|
|
70
|
-
return Array.from(this.store.values(), (item) => item.values.join(", "))[Symbol.iterator]();
|
|
71
|
-
}
|
|
72
|
-
[Symbol.iterator]() {
|
|
73
|
-
return this.entries();
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
const requestBodyStore = /* @__PURE__ */ new WeakMap();
|
|
77
|
-
const requestBodyUsedStore = /* @__PURE__ */ new WeakMap();
|
|
78
|
-
const responseBodyStore = /* @__PURE__ */ new WeakMap();
|
|
79
|
-
const responseBodyUsedStore = /* @__PURE__ */ new WeakMap();
|
|
80
|
-
function normalizeBody(body) {
|
|
81
|
-
if (body == null || typeof body === "string" || isArrayBufferLike(body) || ArrayBuffer.isView(body)) return body;
|
|
82
|
-
if (isBlobLike(body)) return body;
|
|
83
|
-
if (typeof FormData !== "undefined" && body instanceof FormData) return body;
|
|
84
|
-
if (body instanceof FormDataPolyfill) return body;
|
|
85
|
-
return String(body);
|
|
86
|
-
}
|
|
87
|
-
async function readBodyAsArrayBuffer(body) {
|
|
88
|
-
if (body == null) return /* @__PURE__ */ new ArrayBuffer(0);
|
|
89
|
-
if (typeof body === "string") return encodeText(body);
|
|
90
|
-
if (isArrayBufferLike(body)) return cloneArrayBuffer(body);
|
|
91
|
-
if (ArrayBuffer.isView(body)) return cloneArrayBufferView(body);
|
|
92
|
-
if (isBlobLike(body)) return body.arrayBuffer();
|
|
93
|
-
return encodeText(String(body));
|
|
94
|
-
}
|
|
95
|
-
async function readBodyAsText(body) {
|
|
96
|
-
if (typeof body === "string") return body;
|
|
97
|
-
const buffer = await readBodyAsArrayBuffer(body);
|
|
98
|
-
return decodeText(buffer);
|
|
99
|
-
}
|
|
100
|
-
function getRequestBodyValue(request) {
|
|
101
|
-
return request ? requestBodyStore.get(request) : void 0;
|
|
102
|
-
}
|
|
103
|
-
function getResponseBodyValue(response) {
|
|
104
|
-
return responseBodyStore.get(response);
|
|
105
|
-
}
|
|
106
|
-
var RequestPolyfill = class RequestPolyfill {
|
|
107
|
-
url;
|
|
108
|
-
method;
|
|
109
|
-
headers;
|
|
110
|
-
signal;
|
|
111
|
-
[Symbol.toStringTag] = "Request";
|
|
112
|
-
constructor(input, init = {}) {
|
|
113
|
-
const request = input instanceof RequestPolyfill ? input : void 0;
|
|
114
|
-
this.url = typeof input === "string" ? input : isUrlInstance(input) ? input.toString() : request?.url ?? "";
|
|
115
|
-
this.method = String(init.method ?? request?.method ?? "GET").toUpperCase();
|
|
116
|
-
this.headers = new HeadersPolyfill(init.headers ?? request?.headers);
|
|
117
|
-
this.signal = init.signal ?? request?.signal ?? null;
|
|
118
|
-
requestBodyStore.set(this, normalizeBody(init.body ?? getRequestBodyValue(request)));
|
|
119
|
-
requestBodyUsedStore.set(this, false);
|
|
120
|
-
}
|
|
121
|
-
get body() {
|
|
122
|
-
return null;
|
|
123
|
-
}
|
|
124
|
-
get bodyUsed() {
|
|
125
|
-
return requestBodyUsedStore.get(this) === true;
|
|
126
|
-
}
|
|
127
|
-
async arrayBuffer() {
|
|
128
|
-
requestBodyUsedStore.set(this, true);
|
|
129
|
-
return readBodyAsArrayBuffer(getRequestBodyValue(this));
|
|
130
|
-
}
|
|
131
|
-
async text() {
|
|
132
|
-
requestBodyUsedStore.set(this, true);
|
|
133
|
-
return readBodyAsText(getRequestBodyValue(this));
|
|
134
|
-
}
|
|
135
|
-
clone() {
|
|
136
|
-
return new RequestPolyfill(this.url, {
|
|
137
|
-
method: this.method,
|
|
138
|
-
headers: this.headers,
|
|
139
|
-
signal: this.signal,
|
|
140
|
-
body: getRequestBodyValue(this)
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
var ResponsePolyfill = class ResponsePolyfill {
|
|
145
|
-
headers;
|
|
146
|
-
status;
|
|
147
|
-
statusText;
|
|
148
|
-
ok;
|
|
149
|
-
url;
|
|
150
|
-
redirected = false;
|
|
151
|
-
type;
|
|
152
|
-
[Symbol.toStringTag] = "Response";
|
|
153
|
-
constructor(body, init = {}) {
|
|
154
|
-
responseBodyStore.set(this, normalizeBody(body));
|
|
155
|
-
responseBodyUsedStore.set(this, false);
|
|
156
|
-
this.status = Number.isFinite(init.status) ? init.status : 200;
|
|
157
|
-
this.statusText = init.statusText ?? "";
|
|
158
|
-
this.ok = this.status >= 200 && this.status < 300;
|
|
159
|
-
this.headers = new HeadersPolyfill(init.headers);
|
|
160
|
-
this.url = init.url ?? "";
|
|
161
|
-
this.type = init.type ?? "basic";
|
|
162
|
-
}
|
|
163
|
-
static error() {
|
|
164
|
-
return new ResponsePolyfill(null, {
|
|
165
|
-
status: 0,
|
|
166
|
-
type: "error"
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
static json(data, init = {}) {
|
|
170
|
-
const body = JSON.stringify(data);
|
|
171
|
-
if (body === void 0) throw new TypeError("Failed to execute 'json' on 'Response': data is not JSON serializable");
|
|
172
|
-
const headers = new HeadersPolyfill(init.headers);
|
|
173
|
-
if (!headers.has("content-type")) headers.set("content-type", "application/json");
|
|
174
|
-
return new ResponsePolyfill(body, {
|
|
175
|
-
...init,
|
|
176
|
-
headers
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
get body() {
|
|
180
|
-
return null;
|
|
181
|
-
}
|
|
182
|
-
get bodyUsed() {
|
|
183
|
-
return responseBodyUsedStore.get(this) === true;
|
|
184
|
-
}
|
|
185
|
-
async arrayBuffer() {
|
|
186
|
-
responseBodyUsedStore.set(this, true);
|
|
187
|
-
return readBodyAsArrayBuffer(getResponseBodyValue(this));
|
|
188
|
-
}
|
|
189
|
-
async blob() {
|
|
190
|
-
if (typeof Blob !== "function") throw new TypeError("Blob is unavailable in current runtime");
|
|
191
|
-
return new Blob([await this.arrayBuffer()]);
|
|
192
|
-
}
|
|
193
|
-
async formData() {
|
|
194
|
-
throw new TypeError("formData is not supported in Response polyfill");
|
|
195
|
-
}
|
|
196
|
-
async json() {
|
|
197
|
-
return JSON.parse(await this.text());
|
|
198
|
-
}
|
|
199
|
-
async text() {
|
|
200
|
-
responseBodyUsedStore.set(this, true);
|
|
201
|
-
return readBodyAsText(getResponseBodyValue(this));
|
|
202
|
-
}
|
|
203
|
-
clone() {
|
|
204
|
-
return new ResponsePolyfill(getResponseBodyValue(this), {
|
|
205
|
-
status: this.status,
|
|
206
|
-
statusText: this.statusText,
|
|
207
|
-
headers: this.headers,
|
|
208
|
-
url: this.url
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
};
|
|
212
|
-
function headersToObject(headers) {
|
|
213
|
-
const result = {};
|
|
214
|
-
headers.forEach((value, key) => {
|
|
215
|
-
result[key] = value;
|
|
216
|
-
});
|
|
217
|
-
return result;
|
|
218
|
-
}
|
|
219
|
-
//#endregion
|
|
1
|
+
import { n as RequestPolyfill, o as HeadersPolyfill, r as getRequestBodyValue, s as headersToObject, t as ResponsePolyfill } from "./http-C-VyEBss.mjs";
|
|
220
2
|
export { HeadersPolyfill, RequestPolyfill, ResponsePolyfill, getRequestBodyValue, headersToObject };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { RequestGlobalsEventTarget } from "./shared.mjs";
|
|
1
|
+
import { i as RequestGlobalsEventTarget } from "./shared-Dc42USJC.mjs";
|
|
2
2
|
import { AbortControllerPolyfill, AbortSignalPolyfill } from "./abort.mjs";
|
|
3
3
|
import { MiniProgramNetworkDefaults, RequestGlobalsMiniProgramOptions, WebSocketMiniProgramOptions, getMiniProgramNetworkDefaults, resetMiniProgramNetworkDefaults, setMiniProgramNetworkDefaults } from "./networkDefaults.mjs";
|
|
4
|
-
import {
|
|
4
|
+
import { n as URLSearchParamsPolyfill, t as URLPolyfill } from "./url-D0ANYIyk.mjs";
|
|
5
5
|
import { fetch } from "./fetch.mjs";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import { i as HeadersPolyfill, n as RequestPolyfill, t as ResponsePolyfill } from "./http-CE8-CIHE.mjs";
|
|
7
|
+
import { n as FormDataPolyfill, o as BlobPolyfill, r as FilePolyfill } from "./web-DNBBg6y9.mjs";
|
|
8
8
|
import { WebSocketPolyfill } from "./websocket.mjs";
|
|
9
9
|
import { XMLHttpRequestPolyfill } from "./xhr.mjs";
|
|
10
10
|
//#region src/base64.d.ts
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
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-BsJRaiBh.mjs";
|
|
2
2
|
import { URLPolyfill, URLSearchParamsPolyfill } from "./url.mjs";
|
|
3
3
|
import { AbortControllerPolyfill, AbortSignalPolyfill } from "./abort.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { t as fetch } from "./fetch-BPqcYqI3.mjs";
|
|
4
|
+
import { n as RequestPolyfill, o as HeadersPolyfill, t as ResponsePolyfill } from "./http-C-VyEBss.mjs";
|
|
5
|
+
import { n as FilePolyfill, r as BlobPolyfill, t as FormDataPolyfill } from "./web-kSAO_PSD.mjs";
|
|
7
6
|
import { getMiniProgramNetworkDefaults, resetMiniProgramNetworkDefaults, setMiniProgramNetworkDefaults } from "./networkDefaults.mjs";
|
|
7
|
+
import { fetch } from "./fetch.mjs";
|
|
8
8
|
import { WebSocketPolyfill } from "./websocket.mjs";
|
|
9
9
|
import { XMLHttpRequestPolyfill } from "./xhr.mjs";
|
|
10
10
|
import { REQUEST_GLOBAL_ACTUALS_KEY, REQUEST_GLOBAL_PLACEHOLDER_KEY } from "@weapp-core/constants";
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//#region src/shared.d.ts
|
|
2
|
+
interface RequestGlobalsEventLike {
|
|
3
|
+
type: string;
|
|
4
|
+
target?: unknown;
|
|
5
|
+
currentTarget?: unknown;
|
|
6
|
+
}
|
|
7
|
+
type RequestGlobalsEventListener = ((event: RequestGlobalsEventLike) => void) | {
|
|
8
|
+
handleEvent: (event: RequestGlobalsEventLike) => void;
|
|
9
|
+
};
|
|
10
|
+
interface RequestGlobalsEventTargetLike {
|
|
11
|
+
addEventListener: (type: string, listener: RequestGlobalsEventListener) => void;
|
|
12
|
+
removeEventListener: (type: string, listener: RequestGlobalsEventListener) => void;
|
|
13
|
+
dispatchEvent: (event: RequestGlobalsEventLike) => boolean;
|
|
14
|
+
}
|
|
15
|
+
declare class RequestGlobalsEventTarget implements RequestGlobalsEventTargetLike {
|
|
16
|
+
private readonly listeners;
|
|
17
|
+
addEventListener(type: string, listener: RequestGlobalsEventListener): void;
|
|
18
|
+
removeEventListener(type: string, listener: RequestGlobalsEventListener): void;
|
|
19
|
+
dispatchEvent(event: RequestGlobalsEventLike): boolean;
|
|
20
|
+
}
|
|
21
|
+
declare function resolveRequestGlobalsHost(): Record<string, any>;
|
|
22
|
+
declare function resolveRequestGlobalsHosts(): Record<string, any>[];
|
|
23
|
+
declare function installRequestGlobalBinding(name: string, value: unknown): void;
|
|
24
|
+
declare function isArrayBufferLike(value: unknown): value is ArrayBuffer;
|
|
25
|
+
interface RequestGlobalsBlobLike {
|
|
26
|
+
readonly size?: number;
|
|
27
|
+
readonly type?: string;
|
|
28
|
+
arrayBuffer: () => Promise<ArrayBuffer>;
|
|
29
|
+
}
|
|
30
|
+
declare function isBlobLike(value: unknown): value is RequestGlobalsBlobLike;
|
|
31
|
+
declare function cloneArrayBuffer(buffer: ArrayBuffer): ArrayBuffer;
|
|
32
|
+
declare function cloneArrayBufferView(view: ArrayBufferView): ArrayBuffer;
|
|
33
|
+
declare function encodeTextFallback(value: string): ArrayBuffer;
|
|
34
|
+
declare function encodeText(value: string): ArrayBuffer;
|
|
35
|
+
declare function decodeTextFallback(value: ArrayBuffer): string;
|
|
36
|
+
declare function decodeText(value: ArrayBuffer): string;
|
|
37
|
+
declare function normalizeHeaderName(name: string): string;
|
|
38
|
+
//#endregion
|
|
39
|
+
export { resolveRequestGlobalsHosts as _, RequestGlobalsEventTargetLike as a, decodeText as c, encodeTextFallback as d, installRequestGlobalBinding as f, resolveRequestGlobalsHost as g, normalizeHeaderName as h, RequestGlobalsEventTarget as i, decodeTextFallback as l, isBlobLike as m, RequestGlobalsEventLike as n, cloneArrayBuffer as o, isArrayBufferLike as p, RequestGlobalsEventListener as r, cloneArrayBufferView as s, RequestGlobalsBlobLike as t, encodeText as u };
|
package/dist/shared.d.mts
CHANGED
|
@@ -1,38 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
type: string;
|
|
4
|
-
target?: unknown;
|
|
5
|
-
currentTarget?: unknown;
|
|
6
|
-
}
|
|
7
|
-
export type RequestGlobalsEventListener = ((event: RequestGlobalsEventLike) => void) | {
|
|
8
|
-
handleEvent: (event: RequestGlobalsEventLike) => void;
|
|
9
|
-
};
|
|
10
|
-
export interface RequestGlobalsEventTargetLike {
|
|
11
|
-
addEventListener: (type: string, listener: RequestGlobalsEventListener) => void;
|
|
12
|
-
removeEventListener: (type: string, listener: RequestGlobalsEventListener) => void;
|
|
13
|
-
dispatchEvent: (event: RequestGlobalsEventLike) => boolean;
|
|
14
|
-
}
|
|
15
|
-
export declare class RequestGlobalsEventTarget implements RequestGlobalsEventTargetLike {
|
|
16
|
-
private readonly listeners;
|
|
17
|
-
addEventListener(type: string, listener: RequestGlobalsEventListener): void;
|
|
18
|
-
removeEventListener(type: string, listener: RequestGlobalsEventListener): void;
|
|
19
|
-
dispatchEvent(event: RequestGlobalsEventLike): boolean;
|
|
20
|
-
}
|
|
21
|
-
export declare function resolveRequestGlobalsHost(): Record<string, any>;
|
|
22
|
-
export declare function resolveRequestGlobalsHosts(): Record<string, any>[];
|
|
23
|
-
export declare function installRequestGlobalBinding(name: string, value: unknown): void;
|
|
24
|
-
export declare function isArrayBufferLike(value: unknown): value is ArrayBuffer;
|
|
25
|
-
export interface RequestGlobalsBlobLike {
|
|
26
|
-
readonly size?: number;
|
|
27
|
-
readonly type?: string;
|
|
28
|
-
arrayBuffer: () => Promise<ArrayBuffer>;
|
|
29
|
-
}
|
|
30
|
-
export declare function isBlobLike(value: unknown): value is RequestGlobalsBlobLike;
|
|
31
|
-
export declare function cloneArrayBuffer(buffer: ArrayBuffer): ArrayBuffer;
|
|
32
|
-
export declare function cloneArrayBufferView(view: ArrayBufferView): ArrayBuffer;
|
|
33
|
-
export declare function encodeTextFallback(value: string): ArrayBuffer;
|
|
34
|
-
export declare function encodeText(value: string): ArrayBuffer;
|
|
35
|
-
export declare function decodeTextFallback(value: ArrayBuffer): string;
|
|
36
|
-
export declare function decodeText(value: ArrayBuffer): string;
|
|
37
|
-
export declare function normalizeHeaderName(name: string): string;
|
|
38
|
-
//#endregion
|
|
1
|
+
import { _ as resolveRequestGlobalsHosts, a as RequestGlobalsEventTargetLike, c as decodeText, d as encodeTextFallback, f as installRequestGlobalBinding, g as resolveRequestGlobalsHost, h as normalizeHeaderName, i as RequestGlobalsEventTarget, l as decodeTextFallback, m as isBlobLike, n as RequestGlobalsEventLike, o as cloneArrayBuffer, p as isArrayBufferLike, r as RequestGlobalsEventListener, s as cloneArrayBufferView, t as RequestGlobalsBlobLike, u as encodeText } from "./shared-Dc42USJC.mjs";
|
|
2
|
+
export { RequestGlobalsBlobLike, RequestGlobalsEventLike, RequestGlobalsEventListener, RequestGlobalsEventTarget, RequestGlobalsEventTargetLike, cloneArrayBuffer, cloneArrayBufferView, decodeText, decodeTextFallback, encodeText, encodeTextFallback, installRequestGlobalBinding, isArrayBufferLike, isBlobLike, normalizeHeaderName, resolveRequestGlobalsHost, resolveRequestGlobalsHosts };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
//#region src/url.d.ts
|
|
2
|
+
type URLSearchParamValue = string | readonly string[];
|
|
3
|
+
declare class URLSearchParamsPolyfill {
|
|
4
|
+
private readonly onChange?;
|
|
5
|
+
private readonly entriesStore;
|
|
6
|
+
constructor(init?: string | URLSearchParamsPolyfill | Record<string, URLSearchParamValue> | Iterable<[string, string]>, onChange?: (() => void) | undefined);
|
|
7
|
+
append(key: string, value: string): void;
|
|
8
|
+
delete(key: string): void;
|
|
9
|
+
get(key: string): string | null;
|
|
10
|
+
getAll(key: string): string[];
|
|
11
|
+
has(key: string): boolean;
|
|
12
|
+
get size(): number;
|
|
13
|
+
set(key: string, value: string): void;
|
|
14
|
+
sort(): void;
|
|
15
|
+
forEach(callback: (value: string, key: string) => void): void;
|
|
16
|
+
entries(): ArrayIterator<[string, string]>;
|
|
17
|
+
keys(): ArrayIterator<string>;
|
|
18
|
+
values(): ArrayIterator<string>;
|
|
19
|
+
toString(): string;
|
|
20
|
+
[Symbol.iterator](): ArrayIterator<[string, string]>;
|
|
21
|
+
}
|
|
22
|
+
declare class URLPolyfill {
|
|
23
|
+
private hashValue;
|
|
24
|
+
private hrefValue;
|
|
25
|
+
private searchValue;
|
|
26
|
+
host: string;
|
|
27
|
+
hostname: string;
|
|
28
|
+
origin: string;
|
|
29
|
+
password: string;
|
|
30
|
+
pathname: string;
|
|
31
|
+
port: string;
|
|
32
|
+
protocol: string;
|
|
33
|
+
username: string;
|
|
34
|
+
readonly searchParams: URLSearchParamsPolyfill;
|
|
35
|
+
static canParse(input: string | URLPolyfill, base?: string | URLPolyfill): boolean;
|
|
36
|
+
static parse(input: string | URLPolyfill, base?: string | URLPolyfill): URLPolyfill | null;
|
|
37
|
+
constructor(input: string | URLPolyfill, base?: string | URLPolyfill);
|
|
38
|
+
get hash(): string;
|
|
39
|
+
set hash(value: string);
|
|
40
|
+
get href(): string;
|
|
41
|
+
get search(): string;
|
|
42
|
+
set search(value: string);
|
|
43
|
+
toString(): string;
|
|
44
|
+
toJSON(): string;
|
|
45
|
+
private resetSearchParams;
|
|
46
|
+
private updateHref;
|
|
47
|
+
private syncSearchFromParams;
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
export { URLSearchParamsPolyfill as n, URLPolyfill as t };
|
package/dist/url.d.mts
CHANGED
|
@@ -1,49 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export declare class URLSearchParamsPolyfill {
|
|
4
|
-
private readonly onChange?;
|
|
5
|
-
private readonly entriesStore;
|
|
6
|
-
constructor(init?: string | URLSearchParamsPolyfill | Record<string, URLSearchParamValue> | Iterable<[string, string]>, onChange?: (() => void) | undefined);
|
|
7
|
-
append(key: string, value: string): void;
|
|
8
|
-
delete(key: string): void;
|
|
9
|
-
get(key: string): string | null;
|
|
10
|
-
getAll(key: string): string[];
|
|
11
|
-
has(key: string): boolean;
|
|
12
|
-
get size(): number;
|
|
13
|
-
set(key: string, value: string): void;
|
|
14
|
-
sort(): void;
|
|
15
|
-
forEach(callback: (value: string, key: string) => void): void;
|
|
16
|
-
entries(): ArrayIterator<[string, string]>;
|
|
17
|
-
keys(): ArrayIterator<string>;
|
|
18
|
-
values(): ArrayIterator<string>;
|
|
19
|
-
toString(): string;
|
|
20
|
-
[Symbol.iterator](): ArrayIterator<[string, string]>;
|
|
21
|
-
}
|
|
22
|
-
export declare class URLPolyfill {
|
|
23
|
-
private hashValue;
|
|
24
|
-
private hrefValue;
|
|
25
|
-
private searchValue;
|
|
26
|
-
host: string;
|
|
27
|
-
hostname: string;
|
|
28
|
-
origin: string;
|
|
29
|
-
password: string;
|
|
30
|
-
pathname: string;
|
|
31
|
-
port: string;
|
|
32
|
-
protocol: string;
|
|
33
|
-
username: string;
|
|
34
|
-
readonly searchParams: URLSearchParamsPolyfill;
|
|
35
|
-
static canParse(input: string | URLPolyfill, base?: string | URLPolyfill): boolean;
|
|
36
|
-
static parse(input: string | URLPolyfill, base?: string | URLPolyfill): URLPolyfill | null;
|
|
37
|
-
constructor(input: string | URLPolyfill, base?: string | URLPolyfill);
|
|
38
|
-
get hash(): string;
|
|
39
|
-
set hash(value: string);
|
|
40
|
-
get href(): string;
|
|
41
|
-
get search(): string;
|
|
42
|
-
set search(value: string);
|
|
43
|
-
toString(): string;
|
|
44
|
-
toJSON(): string;
|
|
45
|
-
private resetSearchParams;
|
|
46
|
-
private updateHref;
|
|
47
|
-
private syncSearchFromParams;
|
|
48
|
-
}
|
|
49
|
-
//#endregion
|
|
1
|
+
import { n as URLSearchParamsPolyfill, t as URLPolyfill } from "./url-D0ANYIyk.mjs";
|
|
2
|
+
export { URLPolyfill, URLSearchParamsPolyfill };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { t as RequestGlobalsBlobLike } from "./shared-Dc42USJC.mjs";
|
|
2
|
+
//#region src/web/blob.d.ts
|
|
3
|
+
type BlobLikePart = RequestGlobalsBlobLike;
|
|
4
|
+
type BlobPart = ArrayBuffer | ArrayBufferView | BlobLikePart | string;
|
|
5
|
+
interface BlobPropertyBag {
|
|
6
|
+
type?: string;
|
|
7
|
+
}
|
|
8
|
+
declare class BlobPolyfill {
|
|
9
|
+
readonly size: number;
|
|
10
|
+
readonly type: string;
|
|
11
|
+
constructor(parts?: BlobPart[], options?: BlobPropertyBag);
|
|
12
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
13
|
+
bytes(): Promise<Uint8Array<ArrayBuffer>>;
|
|
14
|
+
text(): Promise<string>;
|
|
15
|
+
slice(start?: number, end?: number, contentType?: string): BlobPolyfill;
|
|
16
|
+
get [Symbol.toStringTag](): string;
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/web/file.d.ts
|
|
20
|
+
interface FilePropertyBag extends BlobPropertyBag {
|
|
21
|
+
lastModified?: number;
|
|
22
|
+
}
|
|
23
|
+
declare class FilePolyfill extends BlobPolyfill {
|
|
24
|
+
readonly lastModified: number;
|
|
25
|
+
private readonly fileName;
|
|
26
|
+
constructor(parts: BlobPart[] | undefined, name: string, options?: FilePropertyBag);
|
|
27
|
+
get name(): string;
|
|
28
|
+
get [Symbol.toStringTag](): string;
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/web/formData.d.ts
|
|
32
|
+
type FormDataEntryValue = FilePolyfill | BlobPolyfill | string;
|
|
33
|
+
declare class FormDataPolyfill {
|
|
34
|
+
private readonly entriesList;
|
|
35
|
+
append(name: string, value: string): void;
|
|
36
|
+
append(name: string, value: BlobLikePart, filename?: string): void;
|
|
37
|
+
delete(name: string): void;
|
|
38
|
+
get(name: string): string | BlobPolyfill | null;
|
|
39
|
+
getAll(name: string): FormDataEntryValue[];
|
|
40
|
+
has(name: string): boolean;
|
|
41
|
+
set(name: string, value: string): void;
|
|
42
|
+
set(name: string, value: BlobLikePart, filename?: string): void;
|
|
43
|
+
forEach(callback: (value: FormDataEntryValue, key: string, parent: FormDataPolyfill) => void): void;
|
|
44
|
+
entries(): Generator<[string, FormDataEntryValue], void, unknown>;
|
|
45
|
+
keys(): Generator<string, void, unknown>;
|
|
46
|
+
values(): Generator<FormDataEntryValue, void, unknown>;
|
|
47
|
+
[Symbol.iterator](): Generator<[string, FormDataEntryValue], void, unknown>;
|
|
48
|
+
get [Symbol.toStringTag](): string;
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
export { BlobPart as a, BlobLikePart as i, FormDataPolyfill as n, BlobPolyfill as o, FilePolyfill as r, FormDataEntryValue as t };
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { i as decodeText, l as isArrayBufferLike, n as cloneArrayBuffer, o as encodeText, r as cloneArrayBufferView, u as isBlobLike } from "./shared-BsJRaiBh.mjs";
|
|
2
|
+
//#region src/web/blob.ts
|
|
3
|
+
const segments = /* @__PURE__ */ new WeakMap();
|
|
4
|
+
/** Blob 的 MIME 类型只接受可打印 ASCII,并按标准转换成小写。 */
|
|
5
|
+
function normalizeBlobType(type = "") {
|
|
6
|
+
const value = String(type);
|
|
7
|
+
return /[^\x20-\x7E]/.test(value) ? "" : value.toLowerCase();
|
|
8
|
+
}
|
|
9
|
+
function scalarString(value) {
|
|
10
|
+
return value.replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDFFF]/g, (match) => match.length === 2 ? match : "�");
|
|
11
|
+
}
|
|
12
|
+
function segmentSize(segment) {
|
|
13
|
+
return Math.max(0, (segment.end ?? segment.start) - segment.start);
|
|
14
|
+
}
|
|
15
|
+
function normalizePart(part) {
|
|
16
|
+
if (typeof part === "object" && part !== null && segments.has(part)) return segments.get(part) ?? [];
|
|
17
|
+
if (isBlobLike(part)) return [{
|
|
18
|
+
source: part,
|
|
19
|
+
start: 0,
|
|
20
|
+
end: typeof part.size === "number" && Number.isFinite(part.size) && part.size >= 0 ? Math.trunc(part.size) : void 0
|
|
21
|
+
}];
|
|
22
|
+
const source = isArrayBufferLike(part) ? cloneArrayBuffer(part) : ArrayBuffer.isView(part) ? cloneArrayBufferView(part) : encodeText(scalarString(String(part)));
|
|
23
|
+
return [{
|
|
24
|
+
source,
|
|
25
|
+
start: 0,
|
|
26
|
+
end: source.byteLength
|
|
27
|
+
}];
|
|
28
|
+
}
|
|
29
|
+
function relativeIndex(value, size) {
|
|
30
|
+
const number = Number(value);
|
|
31
|
+
const integer = Number.isNaN(number) ? 0 : Math.trunc(number);
|
|
32
|
+
return integer < 0 ? Math.max(size + integer, 0) : Math.min(integer, size);
|
|
33
|
+
}
|
|
34
|
+
var BlobPolyfill = class BlobPolyfill {
|
|
35
|
+
size;
|
|
36
|
+
type;
|
|
37
|
+
constructor(parts = [], options) {
|
|
38
|
+
const content = [];
|
|
39
|
+
for (const part of parts) content.push(...normalizePart(part));
|
|
40
|
+
segments.set(this, content);
|
|
41
|
+
this.size = content.reduce((total, part) => total + segmentSize(part), 0);
|
|
42
|
+
this.type = normalizeBlobType(options?.type);
|
|
43
|
+
}
|
|
44
|
+
async arrayBuffer() {
|
|
45
|
+
const buffers = await Promise.all((segments.get(this) ?? []).map(async (part) => {
|
|
46
|
+
const buffer = isArrayBufferLike(part.source) ? part.source : await part.source.arrayBuffer();
|
|
47
|
+
const end = Math.min(part.end ?? buffer.byteLength, buffer.byteLength);
|
|
48
|
+
const start = Math.min(part.start, end);
|
|
49
|
+
return new Uint8Array(buffer, start, end - start);
|
|
50
|
+
}));
|
|
51
|
+
const length = buffers.reduce((total, part) => total + part.byteLength, 0);
|
|
52
|
+
const merged = new Uint8Array(length);
|
|
53
|
+
let offset = 0;
|
|
54
|
+
for (const buffer of buffers) {
|
|
55
|
+
merged.set(buffer, offset);
|
|
56
|
+
offset += buffer.byteLength;
|
|
57
|
+
}
|
|
58
|
+
return merged.buffer;
|
|
59
|
+
}
|
|
60
|
+
async bytes() {
|
|
61
|
+
return new Uint8Array(await this.arrayBuffer());
|
|
62
|
+
}
|
|
63
|
+
async text() {
|
|
64
|
+
return decodeText(await this.arrayBuffer());
|
|
65
|
+
}
|
|
66
|
+
slice(start = 0, end = this.size, contentType = "") {
|
|
67
|
+
const first = relativeIndex(start, this.size);
|
|
68
|
+
const last = relativeIndex(end, this.size);
|
|
69
|
+
const sliced = [];
|
|
70
|
+
let offset = 0;
|
|
71
|
+
for (const part of segments.get(this) ?? []) {
|
|
72
|
+
const length = segmentSize(part);
|
|
73
|
+
const from = Math.max(first - offset, 0);
|
|
74
|
+
const to = Math.min(last - offset, length);
|
|
75
|
+
if (from < to) sliced.push({
|
|
76
|
+
source: part.source,
|
|
77
|
+
start: part.start + from,
|
|
78
|
+
end: part.start + to
|
|
79
|
+
});
|
|
80
|
+
offset += length;
|
|
81
|
+
if (offset >= last) break;
|
|
82
|
+
}
|
|
83
|
+
const result = new BlobPolyfill([], { type: contentType });
|
|
84
|
+
segments.set(result, sliced);
|
|
85
|
+
Object.defineProperty(result, "size", {
|
|
86
|
+
value: Math.max(last - first, 0),
|
|
87
|
+
enumerable: true
|
|
88
|
+
});
|
|
89
|
+
return result;
|
|
90
|
+
}
|
|
91
|
+
get [Symbol.toStringTag]() {
|
|
92
|
+
return "Blob";
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/web/file.ts
|
|
97
|
+
var FilePolyfill = class extends BlobPolyfill {
|
|
98
|
+
lastModified;
|
|
99
|
+
fileName;
|
|
100
|
+
constructor(parts = [], name, options) {
|
|
101
|
+
super(parts, options);
|
|
102
|
+
this.fileName = String(name);
|
|
103
|
+
this.lastModified = options?.lastModified ?? Date.now();
|
|
104
|
+
}
|
|
105
|
+
get name() {
|
|
106
|
+
return this.fileName;
|
|
107
|
+
}
|
|
108
|
+
get [Symbol.toStringTag]() {
|
|
109
|
+
return "File";
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
//#endregion
|
|
113
|
+
//#region src/web/formData.ts
|
|
114
|
+
function isFileLikePart(value) {
|
|
115
|
+
return typeof value.name === "string" && typeof value.lastModified === "number";
|
|
116
|
+
}
|
|
117
|
+
function normalizeFormDataValue(value, filename) {
|
|
118
|
+
if (value instanceof FilePolyfill) {
|
|
119
|
+
if (filename === void 0) return value;
|
|
120
|
+
return new FilePolyfill([value], filename, {
|
|
121
|
+
lastModified: value.lastModified,
|
|
122
|
+
type: value.type
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
if (typeof value !== "string") return new FilePolyfill([value], filename ?? (isFileLikePart(value) ? value.name : "blob"), {
|
|
126
|
+
lastModified: isFileLikePart(value) ? value.lastModified : void 0,
|
|
127
|
+
type: value.type
|
|
128
|
+
});
|
|
129
|
+
return String(value);
|
|
130
|
+
}
|
|
131
|
+
var FormDataPolyfill = class {
|
|
132
|
+
entriesList = [];
|
|
133
|
+
append(name, value, filename) {
|
|
134
|
+
this.entriesList.push([String(name), normalizeFormDataValue(value, filename)]);
|
|
135
|
+
}
|
|
136
|
+
delete(name) {
|
|
137
|
+
const normalizedName = String(name);
|
|
138
|
+
let index = this.entriesList.length;
|
|
139
|
+
while (index-- > 0) if (this.entriesList[index]?.[0] === normalizedName) this.entriesList.splice(index, 1);
|
|
140
|
+
}
|
|
141
|
+
get(name) {
|
|
142
|
+
return this.entriesList.find((entry) => entry[0] === String(name))?.[1] ?? null;
|
|
143
|
+
}
|
|
144
|
+
getAll(name) {
|
|
145
|
+
return this.entriesList.filter((entry) => entry[0] === String(name)).map((entry) => entry[1]);
|
|
146
|
+
}
|
|
147
|
+
has(name) {
|
|
148
|
+
return this.entriesList.some((entry) => entry[0] === String(name));
|
|
149
|
+
}
|
|
150
|
+
set(name, value, filename) {
|
|
151
|
+
this.delete(name);
|
|
152
|
+
if (typeof value === "string") {
|
|
153
|
+
this.append(name, value);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
this.append(name, value, filename);
|
|
157
|
+
}
|
|
158
|
+
forEach(callback) {
|
|
159
|
+
for (const [key, value] of this.entriesList) callback(value, key, this);
|
|
160
|
+
}
|
|
161
|
+
*entries() {
|
|
162
|
+
yield* this.entriesList;
|
|
163
|
+
}
|
|
164
|
+
*keys() {
|
|
165
|
+
for (const [key] of this.entriesList) yield key;
|
|
166
|
+
}
|
|
167
|
+
*values() {
|
|
168
|
+
for (const [, value] of this.entriesList) yield value;
|
|
169
|
+
}
|
|
170
|
+
[Symbol.iterator]() {
|
|
171
|
+
return this.entries();
|
|
172
|
+
}
|
|
173
|
+
get [Symbol.toStringTag]() {
|
|
174
|
+
return "FormData";
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
//#endregion
|
|
178
|
+
export { FilePolyfill as n, BlobPolyfill as r, FormDataPolyfill as t };
|