@wevu/web-apis 1.3.5 → 1.4.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 +36 -8
- package/dist/abort.d.mts +2 -4
- package/dist/abort.mjs +2 -3
- package/dist/eventsource-DUCc1iHv.d.mts +82 -0
- package/dist/eventsource-ojngrwBI.mjs +340 -0
- package/dist/eventsource.d.mts +2 -0
- package/dist/eventsource.mjs +2 -0
- package/dist/fetch-CQoQx3mz.mjs +301 -0
- package/dist/fetch-CSESA-oq.d.mts +33 -0
- package/dist/fetch.d.mts +2 -35
- package/dist/fetch.mjs +1 -188
- package/dist/http-DCCqK1QL.mjs +505 -0
- package/dist/{http-CE8-CIHE.d.mts → http-Dd6YCSHK.d.mts} +6 -14
- package/dist/http.d.mts +1 -1
- package/dist/http.mjs +1 -1
- package/dist/index.d.mts +19 -54
- package/dist/index.mjs +35 -104
- package/dist/networkDefaults.d.mts +5 -11
- package/dist/networkDefaults.mjs +1 -2
- package/dist/{shared-85INNxXV.mjs → shared-CARmZrDA.mjs} +5 -9
- package/dist/{shared-Dc42USJC.d.mts → shared-DfU0oEwy.d.mts} +0 -2
- package/dist/shared.d.mts +1 -1
- package/dist/shared.mjs +1 -1
- package/dist/streams-6m8eQfZM.mjs +84 -0
- package/dist/streams.d.mts +31 -0
- package/dist/streams.mjs +1 -0
- package/dist/textCodec-muWByCAW.mjs +132 -0
- package/dist/{url-D0ANYIyk.d.mts → url-CEgyUgm2.d.mts} +0 -2
- package/dist/url-DjMmeEth.mjs +285 -0
- package/dist/url.d.mts +1 -1
- package/dist/url.mjs +1 -229
- package/dist/{web-uZ-hezcd.mjs → web-DDzJNeV3.mjs} +6 -8
- package/dist/{web-DNBBg6y9.d.mts → web-DjLufM4u.d.mts} +1 -7
- package/dist/web.d.mts +1 -1
- package/dist/web.mjs +1 -1
- package/dist/websocket.d.mts +3 -4
- package/dist/websocket.mjs +4 -5
- package/dist/xhr.d.mts +2 -3
- package/dist/xhr.mjs +4 -5
- package/package.json +20 -6
- package/dist/http-mcdF3N9S.mjs +0 -303
package/dist/index.mjs
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { c as installRequestGlobalBinding, f as resolveRequestGlobalsHost, p as resolveRequestGlobalsHosts, t as RequestGlobalsEventTarget, v as getMiniProgramRuntimeGlobalKeys } from "./shared-CARmZrDA.mjs";
|
|
2
|
+
import { n as URLSearchParamsPolyfill, t as URLPolyfill } from "./url-DjMmeEth.mjs";
|
|
3
3
|
import { AbortControllerPolyfill, AbortSignalPolyfill } from "./abort.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import { n as
|
|
4
|
+
import { i as EventPolyfill, r as CustomEventPolyfill, t as EventSourcePolyfill } from "./eventsource-ojngrwBI.mjs";
|
|
5
|
+
import { n as RequestPolyfill, t as ResponsePolyfill, u as HeadersPolyfill } from "./http-DCCqK1QL.mjs";
|
|
6
|
+
import { a as TransformStreamPolyfill, i as TransformStream, n as ReadableStreamPolyfill, o as WritableStream, r as TextDecoderStreamPolyfill, s as WritableStreamPolyfill, t as ReadableStream } from "./streams-6m8eQfZM.mjs";
|
|
7
|
+
import { n as TextEncoderPolyfill, r as hasUsableTextDecoderConstructor, t as TextDecoderPolyfill } from "./textCodec-muWByCAW.mjs";
|
|
8
|
+
import { n as FilePolyfill, r as BlobPolyfill, t as FormDataPolyfill } from "./web-DDzJNeV3.mjs";
|
|
6
9
|
import { getMiniProgramNetworkDefaults, resetMiniProgramNetworkDefaults, setMiniProgramNetworkDefaults } from "./networkDefaults.mjs";
|
|
7
|
-
import { fetch } from "./fetch.mjs";
|
|
10
|
+
import { t as fetch } from "./fetch-CQoQx3mz.mjs";
|
|
8
11
|
import { WebSocketPolyfill } from "./websocket.mjs";
|
|
9
12
|
import { XMLHttpRequestPolyfill } from "./xhr.mjs";
|
|
10
|
-
import { REQUEST_GLOBAL_ACTUALS_KEY, REQUEST_GLOBAL_PLACEHOLDER_KEY } from "@weapp-core/constants";
|
|
11
|
-
|
|
13
|
+
import { REQUEST_GLOBAL_ACTUALS_KEY, REQUEST_GLOBAL_INSTALLER_MARKER, REQUEST_GLOBAL_PLACEHOLDER_KEY, WEB_RUNTIME_GLOBAL_TARGETS, resolveWebRuntimeGlobalTargetDependencies } from "@weapp-core/constants";
|
|
14
|
+
// src/base64.ts
|
|
12
15
|
const BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
13
16
|
const BASE64_LOOKUP = /* @__PURE__ */ new Uint8Array(256);
|
|
14
17
|
const BASE64_INVALID_INPUT_RE = /[^A-Za-z\d+/=]/u;
|
|
@@ -55,8 +58,7 @@ function atobPolyfill(input = "") {
|
|
|
55
58
|
}
|
|
56
59
|
return output;
|
|
57
60
|
}
|
|
58
|
-
|
|
59
|
-
//#region src/crypto.ts
|
|
61
|
+
// src/crypto.ts
|
|
60
62
|
const MAX_RANDOM_VALUES_BYTE_LENGTH = 65536;
|
|
61
63
|
function isIntegerTypedArray(value) {
|
|
62
64
|
return value instanceof Int8Array || value instanceof Uint8Array || value instanceof Uint8ClampedArray || value instanceof Int16Array || value instanceof Uint16Array || value instanceof Int32Array || value instanceof Uint32Array || value instanceof BigInt64Array || value instanceof BigUint64Array;
|
|
@@ -89,47 +91,7 @@ function getRandomValuesPolyfill(typedArray) {
|
|
|
89
91
|
return typedArray;
|
|
90
92
|
}
|
|
91
93
|
const cryptoPolyfill = { getRandomValues: getRandomValuesPolyfill };
|
|
92
|
-
|
|
93
|
-
//#region src/events.ts
|
|
94
|
-
var EventPolyfill = class {
|
|
95
|
-
bubbles;
|
|
96
|
-
cancelable;
|
|
97
|
-
composed;
|
|
98
|
-
isTrusted = false;
|
|
99
|
-
timeStamp = Date.now();
|
|
100
|
-
type;
|
|
101
|
-
currentTarget = null;
|
|
102
|
-
target = null;
|
|
103
|
-
defaultPrevented = false;
|
|
104
|
-
cancelBubble = false;
|
|
105
|
-
constructor(type, init = {}) {
|
|
106
|
-
this.type = String(type);
|
|
107
|
-
this.bubbles = init.bubbles === true;
|
|
108
|
-
this.cancelable = init.cancelable === true;
|
|
109
|
-
this.composed = init.composed === true;
|
|
110
|
-
}
|
|
111
|
-
composedPath() {
|
|
112
|
-
return this.target == null ? [] : [this.target];
|
|
113
|
-
}
|
|
114
|
-
preventDefault() {
|
|
115
|
-
if (this.cancelable) this.defaultPrevented = true;
|
|
116
|
-
}
|
|
117
|
-
stopImmediatePropagation() {
|
|
118
|
-
this.cancelBubble = true;
|
|
119
|
-
}
|
|
120
|
-
stopPropagation() {
|
|
121
|
-
this.cancelBubble = true;
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
var CustomEventPolyfill = class extends EventPolyfill {
|
|
125
|
-
detail;
|
|
126
|
-
constructor(type, init = {}) {
|
|
127
|
-
super(type, init);
|
|
128
|
-
this.detail = init.detail ?? null;
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
//#endregion
|
|
132
|
-
//#region src/performance.ts
|
|
94
|
+
// src/performance.ts
|
|
133
95
|
const performanceTimeOrigin = Date.now();
|
|
134
96
|
const PERFORMANCE_POLYFILL_MARKER = "__weappVitePerformancePolyfill";
|
|
135
97
|
function resolveNativePerformance() {
|
|
@@ -155,8 +117,7 @@ const performancePolyfill = {
|
|
|
155
117
|
},
|
|
156
118
|
timeOrigin: performanceTimeOrigin
|
|
157
119
|
};
|
|
158
|
-
|
|
159
|
-
//#region src/task.ts
|
|
120
|
+
// src/task.ts
|
|
160
121
|
function queueMicrotaskPolyfill(callback) {
|
|
161
122
|
if (typeof callback !== "function") throw new TypeError("Failed to execute 'queueMicrotask': callback must be a function");
|
|
162
123
|
const nativeQueueMicrotask = typeof globalThis !== "undefined" ? globalThis.queueMicrotask : void 0;
|
|
@@ -170,39 +131,10 @@ function queueMicrotaskPolyfill(callback) {
|
|
|
170
131
|
}, 0);
|
|
171
132
|
});
|
|
172
133
|
}
|
|
173
|
-
|
|
174
|
-
//#region src/textCodec.ts
|
|
175
|
-
function normalizeTextDecoderInput(input) {
|
|
176
|
-
if (input == null) return /* @__PURE__ */ new ArrayBuffer(0);
|
|
177
|
-
if (isArrayBufferLike(input)) return cloneArrayBuffer(input);
|
|
178
|
-
if (ArrayBuffer.isView(input)) return cloneArrayBufferView(input);
|
|
179
|
-
return /* @__PURE__ */ new ArrayBuffer(0);
|
|
180
|
-
}
|
|
181
|
-
var TextEncoderPolyfill = class {
|
|
182
|
-
encoding = "utf-8";
|
|
183
|
-
encode(input = "") {
|
|
184
|
-
return new Uint8Array(encodeTextFallback(String(input)));
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
var TextDecoderPolyfill = class {
|
|
188
|
-
encoding = "utf-8";
|
|
189
|
-
fatal = false;
|
|
190
|
-
ignoreBOM = false;
|
|
191
|
-
decode(input) {
|
|
192
|
-
return decodeTextFallback(normalizeTextDecoderInput(input));
|
|
193
|
-
}
|
|
194
|
-
};
|
|
195
|
-
//#endregion
|
|
196
|
-
//#region src/index.ts
|
|
134
|
+
// src/index.ts
|
|
197
135
|
function hasRequestRuntimeBinaryUsage(targets) {
|
|
198
136
|
return targets.some((target) => target === "fetch" || target === "Request" || target === "Response" || target === "XMLHttpRequest" || target === "WebSocket");
|
|
199
137
|
}
|
|
200
|
-
function resolveInstallTargets(targets) {
|
|
201
|
-
const installTargets = [...targets];
|
|
202
|
-
if (hasRequestRuntimeBinaryUsage(targets)) installTargets.push("TextEncoder", "TextDecoder");
|
|
203
|
-
if (targets.includes("CustomEvent")) installTargets.push("Event");
|
|
204
|
-
return [...new Set(installTargets)];
|
|
205
|
-
}
|
|
206
138
|
function resolveActualBindingTargets(targets) {
|
|
207
139
|
const bindingTargets = [...targets];
|
|
208
140
|
if (hasRequestRuntimeBinaryUsage(targets)) {
|
|
@@ -328,6 +260,23 @@ function patchResponseConstructor(host) {
|
|
|
328
260
|
return patched;
|
|
329
261
|
}
|
|
330
262
|
function installSingleTarget(host, target) {
|
|
263
|
+
const streamConstructors = {
|
|
264
|
+
ReadableStream,
|
|
265
|
+
WritableStream,
|
|
266
|
+
TransformStream
|
|
267
|
+
};
|
|
268
|
+
if (target === "ReadableStream" || target === "WritableStream" || target === "TransformStream") {
|
|
269
|
+
assignHostGlobal(host, target, streamConstructors[target]);
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
if (target === "TextDecoderStream") {
|
|
273
|
+
if (ReadableStream === ReadableStreamPolyfill || !hasUsableConstructor(host.TextDecoderStream)) assignHostGlobal(host, target, TextDecoderStreamPolyfill);
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
if (target === "EventSource") {
|
|
277
|
+
if (typeof host.EventSource !== "function" || isPlaceholderRequestGlobal(host.EventSource)) assignHostGlobal(host, target, EventSourcePolyfill);
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
331
280
|
if (target === "fetch") {
|
|
332
281
|
if (typeof host.fetch !== "function" || isPlaceholderRequestGlobal(host.fetch)) assignHostGlobal(host, "fetch", fetch);
|
|
333
282
|
return;
|
|
@@ -349,7 +298,7 @@ function installSingleTarget(host, target) {
|
|
|
349
298
|
return;
|
|
350
299
|
}
|
|
351
300
|
if (target === "TextDecoder") {
|
|
352
|
-
if (
|
|
301
|
+
if (!hasUsableTextDecoderConstructor(host.TextDecoder)) assignHostGlobal(host, "TextDecoder", TextDecoderPolyfill);
|
|
353
302
|
return;
|
|
354
303
|
}
|
|
355
304
|
if (target === "AbortController") {
|
|
@@ -434,25 +383,7 @@ function syncWeappViteRequestGlobalsActuals(host, targets) {
|
|
|
434
383
|
*/
|
|
435
384
|
function installWebRuntimeGlobals(options = {}) {
|
|
436
385
|
if (options.networkDefaults !== void 0) setMiniProgramNetworkDefaults(options.networkDefaults);
|
|
437
|
-
const targets =
|
|
438
|
-
"fetch",
|
|
439
|
-
"Headers",
|
|
440
|
-
"Request",
|
|
441
|
-
"Response",
|
|
442
|
-
"TextEncoder",
|
|
443
|
-
"TextDecoder",
|
|
444
|
-
"AbortController",
|
|
445
|
-
"AbortSignal",
|
|
446
|
-
"XMLHttpRequest",
|
|
447
|
-
"WebSocket",
|
|
448
|
-
"atob",
|
|
449
|
-
"btoa",
|
|
450
|
-
"queueMicrotask",
|
|
451
|
-
"performance",
|
|
452
|
-
"crypto",
|
|
453
|
-
"Event",
|
|
454
|
-
"CustomEvent"
|
|
455
|
-
]);
|
|
386
|
+
const targets = resolveWebRuntimeGlobalTargetDependencies(options.targets ?? WEB_RUNTIME_GLOBAL_TARGETS);
|
|
456
387
|
const hosts = resolveRequestGlobalsHosts();
|
|
457
388
|
const primaryHost = resolveRequestGlobalsHost();
|
|
458
389
|
const needsUrlGlobals = hasRequestRuntimeBinaryUsage(targets);
|
|
@@ -472,6 +403,7 @@ function installWebRuntimeGlobals(options = {}) {
|
|
|
472
403
|
syncWeappViteRequestGlobalsActuals(primaryHost, targets);
|
|
473
404
|
return hosts[0];
|
|
474
405
|
}
|
|
406
|
+
Object.defineProperty(installWebRuntimeGlobals, REQUEST_GLOBAL_INSTALLER_MARKER, { value: true });
|
|
475
407
|
/**
|
|
476
408
|
* @description 已废弃,请迁移到 `installWebRuntimeGlobals`。
|
|
477
409
|
*/
|
|
@@ -484,5 +416,4 @@ function installRequestGlobals(options = {}) {
|
|
|
484
416
|
function installAbortGlobals() {
|
|
485
417
|
return installWebRuntimeGlobals({ targets: ["AbortController", "AbortSignal"] });
|
|
486
418
|
}
|
|
487
|
-
|
|
488
|
-
export { AbortControllerPolyfill, AbortSignalPolyfill, BlobPolyfill, CustomEventPolyfill, EventPolyfill, FilePolyfill, FormDataPolyfill, HeadersPolyfill, RequestGlobalsEventTarget, RequestPolyfill, ResponsePolyfill, TextDecoderPolyfill, TextEncoderPolyfill, URLPolyfill, URLSearchParamsPolyfill, WebSocketPolyfill, XMLHttpRequestPolyfill, atobPolyfill, btoaPolyfill, cryptoPolyfill, fetch, getMiniProgramNetworkDefaults, installAbortGlobals, installRequestGlobals, installWebRuntimeGlobals, performancePolyfill, queueMicrotaskPolyfill, resetMiniProgramNetworkDefaults, setMiniProgramNetworkDefaults };
|
|
419
|
+
export { AbortControllerPolyfill, AbortSignalPolyfill, BlobPolyfill, CustomEventPolyfill, EventPolyfill, EventSourcePolyfill, FilePolyfill, FormDataPolyfill, HeadersPolyfill, ReadableStreamPolyfill, RequestGlobalsEventTarget, RequestPolyfill, ResponsePolyfill, TextDecoderPolyfill, TextDecoderStreamPolyfill, TextEncoderPolyfill, TransformStreamPolyfill, URLPolyfill, URLSearchParamsPolyfill, WebSocketPolyfill, WritableStreamPolyfill, XMLHttpRequestPolyfill, atobPolyfill, btoaPolyfill, cryptoPolyfill, fetch, getMiniProgramNetworkDefaults, installAbortGlobals, installRequestGlobals, installWebRuntimeGlobals, performancePolyfill, queueMicrotaskPolyfill, resetMiniProgramNetworkDefaults, setMiniProgramNetworkDefaults };
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
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>;
|
|
1
|
+
import { WeapiMiniProgramRequestDefaults, WeapiMiniProgramSocketDefaults } from "@weapp-core/api/network-options";
|
|
2
|
+
export type RequestGlobalsMiniProgramOptions = WeapiMiniProgramRequestDefaults;
|
|
3
|
+
export type WebSocketMiniProgramOptions = WeapiMiniProgramSocketDefaults;
|
|
9
4
|
export interface MiniProgramNetworkDefaults {
|
|
10
5
|
request?: RequestGlobalsMiniProgramOptions;
|
|
11
6
|
socket?: WebSocketMiniProgramOptions;
|
|
@@ -15,6 +10,5 @@ export declare function normalizeWebSocketMiniProgramOptions(...sources: unknown
|
|
|
15
10
|
export declare function getMiniProgramNetworkDefaults(): MiniProgramNetworkDefaults;
|
|
16
11
|
export declare function setMiniProgramNetworkDefaults(defaults?: MiniProgramNetworkDefaults): MiniProgramNetworkDefaults;
|
|
17
12
|
export declare function resetMiniProgramNetworkDefaults(): MiniProgramNetworkDefaults;
|
|
18
|
-
export declare function resolveRequestMiniProgramOptions(...sources: unknown[]):
|
|
19
|
-
export declare function resolveWebSocketMiniProgramOptions(...sources: unknown[]):
|
|
20
|
-
//#endregion
|
|
13
|
+
export declare function resolveRequestMiniProgramOptions(...sources: unknown[]): WeapiMiniProgramRequestDefaults;
|
|
14
|
+
export declare function resolveWebSocketMiniProgramOptions(...sources: unknown[]): WeapiMiniProgramSocketDefaults;
|
package/dist/networkDefaults.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { WEVU_WEB_APIS_NETWORK_DEFAULTS_KEY } from "@weapp-core/constants";
|
|
2
|
-
|
|
2
|
+
// src/networkDefaults.ts
|
|
3
3
|
const MINI_PROGRAM_REQUEST_OPTION_KEYS = [
|
|
4
4
|
"enableCache",
|
|
5
5
|
"enableChunked",
|
|
@@ -75,5 +75,4 @@ function resolveRequestMiniProgramOptions(...sources) {
|
|
|
75
75
|
function resolveWebSocketMiniProgramOptions(...sources) {
|
|
76
76
|
return normalizeWebSocketMiniProgramOptions(getMiniProgramNetworkDefaults().socket, ...sources);
|
|
77
77
|
}
|
|
78
|
-
//#endregion
|
|
79
78
|
export { getMiniProgramNetworkDefaults, normalizeRequestMiniProgramOptions, normalizeWebSocketMiniProgramOptions, resetMiniProgramNetworkDefaults, resolveRequestMiniProgramOptions, resolveWebSocketMiniProgramOptions, setMiniProgramNetworkDefaults };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { n as URLSearchParamsPolyfill, t as URLPolyfill } from "./url-DjMmeEth.mjs";
|
|
2
|
+
// ../../@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({
|
|
5
5
|
globalPageStack: true,
|
|
@@ -132,8 +132,7 @@ const MINI_PROGRAM_RUNTIME_DESCRIPTORS = [
|
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
];
|
|
135
|
-
|
|
136
|
-
//#region ../../@weapp-core/shared/dist/platforms/runtime/helpers.js
|
|
135
|
+
// ../../@weapp-core/shared/dist/platforms/runtime/helpers.js
|
|
137
136
|
function createMiniProgramPlatformRegistry(descriptors) {
|
|
138
137
|
const descriptorById = /* @__PURE__ */ new Map();
|
|
139
138
|
const aliasToId = /* @__PURE__ */ new Map();
|
|
@@ -196,8 +195,7 @@ function getMiniProgramRuntimeGlobalKeys(platform) {
|
|
|
196
195
|
if (platform) return [getMiniProgramRuntimeGlobalKey(platform)];
|
|
197
196
|
return ORDERED_RUNTIME_GLOBAL_KEYS;
|
|
198
197
|
}
|
|
199
|
-
|
|
200
|
-
//#region src/constructors.ts
|
|
198
|
+
// src/constructors.ts
|
|
201
199
|
function resolveUrlConstructor() {
|
|
202
200
|
return typeof globalThis.URL === "function" ? globalThis.URL : void 0;
|
|
203
201
|
}
|
|
@@ -218,8 +216,7 @@ function resolveTextEncoderConstructor() {
|
|
|
218
216
|
function resolveTextDecoderConstructor() {
|
|
219
217
|
return typeof globalThis.TextDecoder === "function" ? globalThis.TextDecoder : void 0;
|
|
220
218
|
}
|
|
221
|
-
|
|
222
|
-
//#region src/shared.ts
|
|
219
|
+
// src/shared.ts
|
|
223
220
|
var RequestGlobalsEventTarget = class {
|
|
224
221
|
listeners = /* @__PURE__ */ new Map();
|
|
225
222
|
addEventListener(type, listener) {
|
|
@@ -319,5 +316,4 @@ function decodeText(value) {
|
|
|
319
316
|
function normalizeHeaderName(name) {
|
|
320
317
|
return name.trim().toLowerCase();
|
|
321
318
|
}
|
|
322
|
-
//#endregion
|
|
323
319
|
export { resolveUrlConstructor as _, decodeTextFallback as a, installRequestGlobalBinding as c, normalizeHeaderName as d, resolveRequestGlobalsHost as f, resolveTextEncoderConstructor as g, isUrlSearchParamsInstance as h, decodeText as i, isArrayBufferLike as l, isUrlInstance as m, cloneArrayBuffer as n, encodeText as o, resolveRequestGlobalsHosts as p, cloneArrayBufferView as r, encodeTextFallback as s, RequestGlobalsEventTarget as t, isBlobLike as u, getMiniProgramRuntimeGlobalKeys as v };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/shared.d.ts
|
|
2
1
|
interface RequestGlobalsEventLike {
|
|
3
2
|
type: string;
|
|
4
3
|
target?: unknown;
|
|
@@ -35,5 +34,4 @@ declare function encodeText(value: string): ArrayBuffer;
|
|
|
35
34
|
declare function decodeTextFallback(value: ArrayBuffer): string;
|
|
36
35
|
declare function decodeText(value: ArrayBuffer): string;
|
|
37
36
|
declare function normalizeHeaderName(name: string): string;
|
|
38
|
-
//#endregion
|
|
39
37
|
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,2 +1,2 @@
|
|
|
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-
|
|
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-DfU0oEwy.mjs";
|
|
2
2
|
export { RequestGlobalsBlobLike, RequestGlobalsEventLike, RequestGlobalsEventListener, RequestGlobalsEventTarget, RequestGlobalsEventTargetLike, cloneArrayBuffer, cloneArrayBufferView, decodeText, decodeTextFallback, encodeText, encodeTextFallback, installRequestGlobalBinding, isArrayBufferLike, isBlobLike, normalizeHeaderName, resolveRequestGlobalsHost, resolveRequestGlobalsHosts };
|
package/dist/shared.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
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-
|
|
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-CARmZrDA.mjs";
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { t as TextDecoderPolyfill } from "./textCodec-muWByCAW.mjs";
|
|
2
|
+
import { REQUEST_GLOBAL_PLACEHOLDER_KEY } from "@weapp-core/constants";
|
|
3
|
+
import { ReadableStream, TransformStream, WritableStream } from "web-streams-polyfill";
|
|
4
|
+
// src/streams/native.ts
|
|
5
|
+
function isUsableConstructor(value) {
|
|
6
|
+
return typeof value === "function" && !value[REQUEST_GLOBAL_PLACEHOLDER_KEY];
|
|
7
|
+
}
|
|
8
|
+
/** 安全捕获同一组宿主构造器;缺失全局或惰性属性抛错时整组回退,不重复触发宿主 getter。 */
|
|
9
|
+
function resolveNativeStreams() {
|
|
10
|
+
try {
|
|
11
|
+
if (typeof globalThis === "undefined") return;
|
|
12
|
+
const { ReadableStream, WritableStream, TransformStream } = globalThis;
|
|
13
|
+
if (![
|
|
14
|
+
ReadableStream,
|
|
15
|
+
WritableStream,
|
|
16
|
+
TransformStream
|
|
17
|
+
].every(isUsableConstructor)) return;
|
|
18
|
+
const { Response } = globalThis;
|
|
19
|
+
if (!isUsableConstructor(Response)) return;
|
|
20
|
+
const bodyUsed = Object.getOwnPropertyDescriptor(Response.prototype, "bodyUsed")?.get;
|
|
21
|
+
if (!bodyUsed) return;
|
|
22
|
+
const readable = new ReadableStream({ start(controller) {
|
|
23
|
+
controller.close();
|
|
24
|
+
} });
|
|
25
|
+
const writable = new WritableStream();
|
|
26
|
+
const transform = new TransformStream();
|
|
27
|
+
const response = new Response(readable);
|
|
28
|
+
if (!(typeof readable.getReader === "function" && typeof readable.tee === "function" && typeof readable.pipeThrough === "function" && typeof writable.getWriter === "function" && typeof writable.abort === "function" && transform.readable instanceof ReadableStream && transform.writable instanceof WritableStream && response.body === readable && bodyUsed.call(response) === false)) return;
|
|
29
|
+
const reader = readable.getReader();
|
|
30
|
+
reader.read();
|
|
31
|
+
const disturbed = bodyUsed.call(response) === true;
|
|
32
|
+
reader.releaseLock();
|
|
33
|
+
if (disturbed) return {
|
|
34
|
+
ReadableStream,
|
|
35
|
+
WritableStream,
|
|
36
|
+
TransformStream,
|
|
37
|
+
Response,
|
|
38
|
+
bodyUsed
|
|
39
|
+
};
|
|
40
|
+
} catch {}
|
|
41
|
+
}
|
|
42
|
+
const nativeStreams = resolveNativeStreams();
|
|
43
|
+
// src/streams.ts
|
|
44
|
+
const ReadableStreamPolyfill = ReadableStream;
|
|
45
|
+
const WritableStreamPolyfill = WritableStream;
|
|
46
|
+
const TransformStreamPolyfill = TransformStream;
|
|
47
|
+
const usesNativeStreams = nativeStreams !== void 0;
|
|
48
|
+
/** 三种构造器作为一组选择,防止原生流与兼容流混用时触发品牌检查失败。 */
|
|
49
|
+
const ReadableStream$1 = nativeStreams?.ReadableStream ?? ReadableStreamPolyfill;
|
|
50
|
+
const WritableStream$1 = nativeStreams?.WritableStream ?? WritableStreamPolyfill;
|
|
51
|
+
const TransformStream$1 = nativeStreams?.TransformStream ?? TransformStreamPolyfill;
|
|
52
|
+
var TextDecoderStreamPolyfill = class {
|
|
53
|
+
readable;
|
|
54
|
+
writable;
|
|
55
|
+
decoder;
|
|
56
|
+
constructor(label = "utf-8", options = {}) {
|
|
57
|
+
this.decoder = new TextDecoderPolyfill(label, options);
|
|
58
|
+
const transform = new TransformStream$1({
|
|
59
|
+
transform: (chunk, controller) => {
|
|
60
|
+
const text = this.decoder.decode(chunk, { stream: true });
|
|
61
|
+
if (text) controller.enqueue(text);
|
|
62
|
+
},
|
|
63
|
+
flush: (controller) => {
|
|
64
|
+
const text = this.decoder.decode();
|
|
65
|
+
if (text) controller.enqueue(text);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
this.readable = transform.readable;
|
|
69
|
+
this.writable = transform.writable;
|
|
70
|
+
}
|
|
71
|
+
get encoding() {
|
|
72
|
+
return this.decoder.encoding;
|
|
73
|
+
}
|
|
74
|
+
get fatal() {
|
|
75
|
+
return this.decoder.fatal;
|
|
76
|
+
}
|
|
77
|
+
get ignoreBOM() {
|
|
78
|
+
return this.decoder.ignoreBOM;
|
|
79
|
+
}
|
|
80
|
+
get [Symbol.toStringTag]() {
|
|
81
|
+
return "TextDecoderStream";
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
export { TransformStreamPolyfill as a, usesNativeStreams as c, TransformStream$1 as i, nativeStreams as l, ReadableStreamPolyfill as n, WritableStream$1 as o, TextDecoderStreamPolyfill as r, WritableStreamPolyfill as s, ReadableStream$1 as t };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export declare const ReadableStreamPolyfill: typeof globalThis.ReadableStream;
|
|
2
|
+
export declare const WritableStreamPolyfill: typeof globalThis.WritableStream;
|
|
3
|
+
export declare const TransformStreamPolyfill: typeof globalThis.TransformStream;
|
|
4
|
+
export declare const usesNativeStreams: boolean;
|
|
5
|
+
/** 三种构造器作为一组选择,防止原生流与兼容流混用时触发品牌检查失败。 */
|
|
6
|
+
export declare const ReadableStream: {
|
|
7
|
+
new (underlyingSource: UnderlyingByteSource, strategy?: {
|
|
8
|
+
highWaterMark?: number;
|
|
9
|
+
}): ReadableStream<Uint8Array<ArrayBuffer>>;
|
|
10
|
+
new <R = any>(underlyingSource: UnderlyingDefaultSource<R>, strategy?: QueuingStrategy<R>): ReadableStream<R>;
|
|
11
|
+
new <R = any>(underlyingSource?: UnderlyingSource<R>, strategy?: QueuingStrategy<R>): ReadableStream<R>;
|
|
12
|
+
prototype: ReadableStream;
|
|
13
|
+
};
|
|
14
|
+
export declare const WritableStream: {
|
|
15
|
+
new <W = any>(underlyingSink?: UnderlyingSink<W>, strategy?: QueuingStrategy<W>): WritableStream<W>;
|
|
16
|
+
prototype: WritableStream;
|
|
17
|
+
};
|
|
18
|
+
export declare const TransformStream: {
|
|
19
|
+
new <I = any, O = any>(transformer?: Transformer<I, O>, writableStrategy?: QueuingStrategy<I>, readableStrategy?: QueuingStrategy<O>): TransformStream<I, O>;
|
|
20
|
+
prototype: TransformStream;
|
|
21
|
+
};
|
|
22
|
+
export declare class TextDecoderStreamPolyfill {
|
|
23
|
+
readonly readable: globalThis.ReadableStream<string>;
|
|
24
|
+
readonly writable: globalThis.WritableStream<BufferSource>;
|
|
25
|
+
private readonly decoder;
|
|
26
|
+
constructor(label?: string, options?: TextDecoderOptions);
|
|
27
|
+
get encoding(): string;
|
|
28
|
+
get fatal(): boolean;
|
|
29
|
+
get ignoreBOM(): boolean;
|
|
30
|
+
get [Symbol.toStringTag](): string;
|
|
31
|
+
}
|
package/dist/streams.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as ReadableStream, n as ReadableStreamPolyfill, r as TextDecoderStreamPolyfill, i as TransformStream, a as TransformStreamPolyfill, o as WritableStream, s as WritableStreamPolyfill, c as usesNativeStreams } from "./streams-6m8eQfZM.mjs";
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { l as isArrayBufferLike, s as encodeTextFallback } from "./shared-CARmZrDA.mjs";
|
|
2
|
+
import { REQUEST_GLOBAL_PLACEHOLDER_KEY } from "@weapp-core/constants";
|
|
3
|
+
// src/textCodec/utf8.ts
|
|
4
|
+
/** 保留末尾未完成序列;非法续字节留给下一轮重新解释,遵守 UTF-8 解码的替换规则。 */
|
|
5
|
+
function decodeUtf8(bytes, streaming, fatal) {
|
|
6
|
+
const text = [];
|
|
7
|
+
let index = 0;
|
|
8
|
+
const invalid = () => {
|
|
9
|
+
if (fatal) throw new TypeError("The encoded data is not valid UTF-8");
|
|
10
|
+
text.push("�");
|
|
11
|
+
};
|
|
12
|
+
while (index < bytes.length) {
|
|
13
|
+
const first = bytes[index];
|
|
14
|
+
if (first <= 127) {
|
|
15
|
+
text.push(String.fromCharCode(first));
|
|
16
|
+
index++;
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
const length = first >= 194 && first <= 223 ? 2 : first >= 224 && first <= 239 ? 3 : first >= 240 && first <= 244 ? 4 : 0;
|
|
20
|
+
if (!length) {
|
|
21
|
+
invalid();
|
|
22
|
+
index++;
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
let codePoint = first & 127 >> length;
|
|
26
|
+
let offset = 1;
|
|
27
|
+
for (; offset < length; offset++) {
|
|
28
|
+
const byte = bytes[index + offset];
|
|
29
|
+
if (byte === void 0) {
|
|
30
|
+
if (streaming) return {
|
|
31
|
+
text: text.join(""),
|
|
32
|
+
pending: bytes.slice(index)
|
|
33
|
+
};
|
|
34
|
+
invalid();
|
|
35
|
+
return {
|
|
36
|
+
text: text.join(""),
|
|
37
|
+
pending: /* @__PURE__ */ new Uint8Array(0)
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
if (byte < (offset === 1 && first === 224 ? 160 : offset === 1 && first === 240 ? 144 : 128) || byte > (offset === 1 && first === 237 ? 159 : offset === 1 && first === 244 ? 143 : 191)) {
|
|
41
|
+
invalid();
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
codePoint = codePoint << 6 | byte & 63;
|
|
45
|
+
}
|
|
46
|
+
if (offset === length) text.push(String.fromCodePoint(codePoint));
|
|
47
|
+
index += offset;
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
text: text.join(""),
|
|
51
|
+
pending: /* @__PURE__ */ new Uint8Array(0)
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
// src/textCodec.ts
|
|
55
|
+
/** 仅检测独立实例的增量 UTF-8 行为,不能把占位函数或单次解码器当作完整能力。 */
|
|
56
|
+
function hasUsableTextDecoderConstructor(value) {
|
|
57
|
+
if (typeof value !== "function" || value[REQUEST_GLOBAL_PLACEHOLDER_KEY]) return false;
|
|
58
|
+
try {
|
|
59
|
+
const decoder = new value();
|
|
60
|
+
return decoder.decode(new Uint8Array([228]), { stream: true }) === "" && decoder.decode(new Uint8Array([
|
|
61
|
+
184,
|
|
62
|
+
173,
|
|
63
|
+
240,
|
|
64
|
+
159
|
|
65
|
+
]), { stream: true }) === "中" && decoder.decode(new Uint8Array([153, 130])) === "🙂" && decoder.decode(new Uint8Array([255])) === "�";
|
|
66
|
+
} catch {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function normalizeTextDecoderInput(input) {
|
|
71
|
+
if (input === void 0) return /* @__PURE__ */ new Uint8Array(0);
|
|
72
|
+
if (isArrayBufferLike(input) || Object.prototype.toString.call(input) === "[object SharedArrayBuffer]") return new Uint8Array(input);
|
|
73
|
+
if (ArrayBuffer.isView(input)) return new Uint8Array(input.buffer, input.byteOffset, input.byteLength);
|
|
74
|
+
throw new TypeError("TextDecoder input must be an ArrayBuffer or ArrayBufferView");
|
|
75
|
+
}
|
|
76
|
+
var TextEncoderPolyfill = class {
|
|
77
|
+
encoding = "utf-8";
|
|
78
|
+
encode(input = "") {
|
|
79
|
+
const scalar = String(input).replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDFFF]/g, (value) => value.length === 2 ? value : "�");
|
|
80
|
+
return new Uint8Array(encodeTextFallback(scalar));
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
var TextDecoderPolyfill = class {
|
|
84
|
+
encoding = "utf-8";
|
|
85
|
+
fatal;
|
|
86
|
+
ignoreBOM;
|
|
87
|
+
pending = /* @__PURE__ */ new Uint8Array(0);
|
|
88
|
+
streaming = false;
|
|
89
|
+
bomSeen = false;
|
|
90
|
+
constructor(label = "utf-8", options = {}) {
|
|
91
|
+
const normalized = String(label).trim().toLowerCase();
|
|
92
|
+
if (![
|
|
93
|
+
"unicode-1-1-utf-8",
|
|
94
|
+
"unicode11utf8",
|
|
95
|
+
"unicode20utf8",
|
|
96
|
+
"utf-8",
|
|
97
|
+
"utf8",
|
|
98
|
+
"x-unicode20utf8"
|
|
99
|
+
].includes(normalized)) throw new RangeError(`Unsupported encoding: ${label}`);
|
|
100
|
+
this.fatal = Boolean(options.fatal);
|
|
101
|
+
this.ignoreBOM = Boolean(options.ignoreBOM);
|
|
102
|
+
}
|
|
103
|
+
decode(input, options = {}) {
|
|
104
|
+
const bytes = normalizeTextDecoderInput(input);
|
|
105
|
+
if (!this.streaming) {
|
|
106
|
+
this.pending = /* @__PURE__ */ new Uint8Array(0);
|
|
107
|
+
this.bomSeen = false;
|
|
108
|
+
}
|
|
109
|
+
this.streaming = Boolean(options.stream);
|
|
110
|
+
const combined = new Uint8Array(this.pending.byteLength + bytes.byteLength);
|
|
111
|
+
combined.set(this.pending);
|
|
112
|
+
combined.set(bytes, this.pending.byteLength);
|
|
113
|
+
try {
|
|
114
|
+
const result = decodeUtf8(combined, this.streaming, this.fatal);
|
|
115
|
+
this.pending = result.pending;
|
|
116
|
+
let text = result.text;
|
|
117
|
+
if (!this.bomSeen && text.length > 0) {
|
|
118
|
+
this.bomSeen = true;
|
|
119
|
+
if (!this.ignoreBOM && text.charCodeAt(0) === 65279) text = text.slice(1);
|
|
120
|
+
}
|
|
121
|
+
return text;
|
|
122
|
+
} catch (error) {
|
|
123
|
+
this.pending = /* @__PURE__ */ new Uint8Array(0);
|
|
124
|
+
this.streaming = false;
|
|
125
|
+
throw error;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
get [Symbol.toStringTag]() {
|
|
129
|
+
return "TextDecoder";
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
export { TextEncoderPolyfill as n, hasUsableTextDecoderConstructor as r, TextDecoderPolyfill as t };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/url.d.ts
|
|
2
1
|
type URLSearchParamValue = string | readonly string[];
|
|
3
2
|
declare class URLSearchParamsPolyfill {
|
|
4
3
|
private readonly onChange?;
|
|
@@ -46,5 +45,4 @@ declare class URLPolyfill {
|
|
|
46
45
|
private updateHref;
|
|
47
46
|
private syncSearchFromParams;
|
|
48
47
|
}
|
|
49
|
-
//#endregion
|
|
50
48
|
export { URLSearchParamsPolyfill as n, URLPolyfill as t };
|