@wevu/web-apis 1.2.6 → 1.2.8

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 CHANGED
@@ -108,6 +108,7 @@ socket.onclose = (event) => {
108
108
  | `installAbortGlobals` | 仅安装 `AbortController` / `AbortSignal` |
109
109
  | `fetch` | 基于小程序请求能力适配的 `fetch` 实现 |
110
110
  | `HeadersPolyfill` / `RequestPolyfill` / `ResponsePolyfill` | HTTP 相关兼容类 |
111
+ | `TextEncoderPolyfill` / `TextDecoderPolyfill` | 文本编解码兼容类 |
111
112
  | `URLPolyfill` / `URLSearchParamsPolyfill` | URL 相关兼容类 |
112
113
  | `WebSocketPolyfill` | 基于小程序 `SocketTask` 的 `WebSocket` 兼容实现 |
113
114
  | `XMLHttpRequestPolyfill` | XHR 兼容实现 |
package/dist/abort.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { RequestGlobalsEventTarget } from "./shared.mjs";
1
+ import { t as RequestGlobalsEventTarget } from "./shared-1FH7Skf_.mjs";
2
2
  //#region src/abort.ts
3
3
  function createAbortError(reason) {
4
4
  if (reason instanceof Error) return reason;
package/dist/fetch.d.mts CHANGED
@@ -1,3 +1,5 @@
1
+ import { URLPolyfill } from "./url.mjs";
2
+
1
3
  //#region src/fetch.d.ts
2
4
  interface RequestLikeInput {
3
5
  url: string;
@@ -17,7 +19,7 @@ interface RequestGlobalsFetchInit {
17
19
  signal?: AbortSignal | null;
18
20
  [key: string]: unknown;
19
21
  }
20
- type RequestGlobalsFetchInput = string | URL | RequestLikeInput;
22
+ type RequestGlobalsFetchInput = string | URL | URLPolyfill | RequestLikeInput;
21
23
  /**
22
24
  * @description 使用 @wevu/api 的 request 能力实现 fetch 语义对齐。
23
25
  */
package/dist/fetch.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { cloneArrayBuffer, cloneArrayBufferView, normalizeHeaderName } from "./shared.mjs";
1
+ import { f as isUrlInstance, l as normalizeHeaderName, n as cloneArrayBuffer, p as isUrlSearchParamsInstance, r as cloneArrayBufferView } from "./shared-1FH7Skf_.mjs";
2
2
  import { HeadersPolyfill, ResponsePolyfill } from "./http.mjs";
3
3
  import { wpi } from "@wevu/api";
4
4
  //#region src/fetch.ts
@@ -16,9 +16,6 @@ const hasOwn = Object.prototype.hasOwnProperty;
16
16
  function isObject(value) {
17
17
  return typeof value === "object" && value !== null;
18
18
  }
19
- function isNativeUrlInstance(value) {
20
- return typeof URL !== "undefined" && value instanceof URL;
21
- }
22
19
  function createAbortError() {
23
20
  if (typeof DOMException === "function") return new DOMException("The operation was aborted.", "AbortError");
24
21
  const error = /* @__PURE__ */ new Error("The operation was aborted.");
@@ -86,7 +83,7 @@ async function normalizeRequestBody(body, headers) {
86
83
  if (!hasHeader(headers, "content-type")) headers["content-type"] = "text/plain;charset=UTF-8";
87
84
  return body;
88
85
  }
89
- if (typeof URLSearchParams !== "undefined" && body instanceof URLSearchParams) {
86
+ if (isUrlSearchParamsInstance(body)) {
90
87
  if (!hasHeader(headers, "content-type")) headers["content-type"] = "application/x-www-form-urlencoded;charset=UTF-8";
91
88
  return body.toString();
92
89
  }
@@ -101,7 +98,7 @@ async function normalizeRequestBody(body, headers) {
101
98
  }
102
99
  async function resolveRequestMeta(input, init = {}) {
103
100
  const requestInput = isRequestLikeInput(input) ? input : void 0;
104
- const url = typeof input === "string" ? input : isNativeUrlInstance(input) ? input.toString() : requestInput?.url;
101
+ const url = typeof input === "string" ? input : isUrlInstance(input) ? input.toString() : requestInput?.url;
105
102
  if (!url) throw new TypeError("Failed to execute fetch: invalid request url");
106
103
  const method = normalizeMethod(init.method ?? requestInput?.method);
107
104
  const headers = toHeaderMap(requestInput?.headers);
package/dist/http.d.mts CHANGED
@@ -1,3 +1,5 @@
1
+ import { URLPolyfill } from "./url.mjs";
2
+
1
3
  //#region src/http.d.ts
2
4
  type HeaderRecord = Record<string, string>;
3
5
  declare class HeadersPolyfill {
@@ -21,9 +23,9 @@ declare class RequestPolyfill {
21
23
  readonly headers: HeadersPolyfill;
22
24
  readonly signal: AbortSignal | null;
23
25
  readonly [Symbol.toStringTag] = "Request";
24
- private readonly bodyValue;
25
- bodyUsed: boolean;
26
- constructor(input: string | URL | RequestPolyfill, init?: Record<string, any>);
26
+ constructor(input: string | URL | URLPolyfill | RequestPolyfill, init?: Record<string, any>);
27
+ get body(): ReadableStream<Uint8Array> | null;
28
+ get bodyUsed(): boolean;
27
29
  arrayBuffer(): Promise<ArrayBuffer>;
28
30
  text(): Promise<string>;
29
31
  clone(): RequestPolyfill;
@@ -36,11 +38,10 @@ declare class ResponsePolyfill {
36
38
  readonly url: string;
37
39
  readonly redirected = false;
38
40
  readonly type: ResponseType;
39
- readonly body: ReadableStream<Uint8Array> | null;
40
41
  readonly [Symbol.toStringTag] = "Response";
41
- private readonly bodyValue;
42
- bodyUsed: boolean;
43
42
  constructor(body?: RequestBodyLike, init?: Record<string, any>);
43
+ get body(): ReadableStream<Uint8Array> | null;
44
+ get bodyUsed(): boolean;
44
45
  arrayBuffer(): Promise<ArrayBuffer>;
45
46
  blob(): Promise<Blob>;
46
47
  formData(): Promise<void>;
package/dist/http.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { cloneArrayBuffer, cloneArrayBufferView, decodeText, encodeText, normalizeHeaderName } from "./shared.mjs";
1
+ import { f as isUrlInstance, i as decodeText, l as normalizeHeaderName, n as cloneArrayBuffer, o as encodeText, r as cloneArrayBufferView } from "./shared-1FH7Skf_.mjs";
2
2
  //#region src/http.ts
3
3
  function isIterableHeaders(input) {
4
4
  return Boolean(input) && typeof input[Symbol.iterator] === "function";
@@ -6,9 +6,6 @@ function isIterableHeaders(input) {
6
6
  function isHeaderObject(input) {
7
7
  return typeof input === "object" && input !== null;
8
8
  }
9
- function isNativeUrlInstance(value) {
10
- return typeof URL !== "undefined" && value instanceof URL;
11
- }
12
9
  var HeadersPolyfill = class {
13
10
  store = /* @__PURE__ */ new Map();
14
11
  constructor(init) {
@@ -62,6 +59,10 @@ var HeadersPolyfill = class {
62
59
  return this.entries();
63
60
  }
64
61
  };
62
+ const requestBodyStore = /* @__PURE__ */ new WeakMap();
63
+ const requestBodyUsedStore = /* @__PURE__ */ new WeakMap();
64
+ const responseBodyStore = /* @__PURE__ */ new WeakMap();
65
+ const responseBodyUsedStore = /* @__PURE__ */ new WeakMap();
65
66
  function normalizeBody(body) {
66
67
  if (body == null || typeof body === "string" || body instanceof ArrayBuffer || ArrayBuffer.isView(body)) return body;
67
68
  if (typeof Blob !== "undefined" && body instanceof Blob) return body;
@@ -79,36 +80,47 @@ async function readBodyAsText(body) {
79
80
  if (typeof body === "string") return body;
80
81
  return decodeText(await readBodyAsArrayBuffer(body));
81
82
  }
83
+ function getRequestBodyValue(request) {
84
+ return request ? requestBodyStore.get(request) : void 0;
85
+ }
86
+ function getResponseBodyValue(response) {
87
+ return responseBodyStore.get(response);
88
+ }
82
89
  var RequestPolyfill = class RequestPolyfill {
83
90
  url;
84
91
  method;
85
92
  headers;
86
93
  signal;
87
94
  [Symbol.toStringTag] = "Request";
88
- bodyValue;
89
- bodyUsed = false;
90
95
  constructor(input, init = {}) {
91
96
  const request = input instanceof RequestPolyfill ? input : void 0;
92
- this.url = typeof input === "string" ? input : isNativeUrlInstance(input) ? input.toString() : request?.url ?? "";
97
+ this.url = typeof input === "string" ? input : isUrlInstance(input) ? input.toString() : request?.url ?? "";
93
98
  this.method = String(init.method ?? request?.method ?? "GET").toUpperCase();
94
99
  this.headers = new HeadersPolyfill(init.headers ?? request?.headers);
95
100
  this.signal = init.signal ?? request?.signal ?? null;
96
- this.bodyValue = normalizeBody(init.body ?? request?.bodyValue);
101
+ requestBodyStore.set(this, normalizeBody(init.body ?? getRequestBodyValue(request)));
102
+ requestBodyUsedStore.set(this, false);
103
+ }
104
+ get body() {
105
+ return null;
106
+ }
107
+ get bodyUsed() {
108
+ return requestBodyUsedStore.get(this) === true;
97
109
  }
98
110
  async arrayBuffer() {
99
- this.bodyUsed = true;
100
- return readBodyAsArrayBuffer(this.bodyValue);
111
+ requestBodyUsedStore.set(this, true);
112
+ return readBodyAsArrayBuffer(getRequestBodyValue(this));
101
113
  }
102
114
  async text() {
103
- this.bodyUsed = true;
104
- return readBodyAsText(this.bodyValue);
115
+ requestBodyUsedStore.set(this, true);
116
+ return readBodyAsText(getRequestBodyValue(this));
105
117
  }
106
118
  clone() {
107
119
  return new RequestPolyfill(this.url, {
108
120
  method: this.method,
109
121
  headers: this.headers,
110
122
  signal: this.signal,
111
- body: this.bodyValue
123
+ body: getRequestBodyValue(this)
112
124
  });
113
125
  }
114
126
  };
@@ -120,21 +132,25 @@ var ResponsePolyfill = class ResponsePolyfill {
120
132
  url;
121
133
  redirected = false;
122
134
  type = "basic";
123
- body = null;
124
135
  [Symbol.toStringTag] = "Response";
125
- bodyValue;
126
- bodyUsed = false;
127
136
  constructor(body, init = {}) {
128
- this.bodyValue = normalizeBody(body);
137
+ responseBodyStore.set(this, normalizeBody(body));
138
+ responseBodyUsedStore.set(this, false);
129
139
  this.status = Number.isFinite(init.status) ? init.status : 200;
130
140
  this.statusText = init.statusText ?? "";
131
141
  this.ok = this.status >= 200 && this.status < 300;
132
142
  this.headers = new HeadersPolyfill(init.headers);
133
143
  this.url = init.url ?? "";
134
144
  }
145
+ get body() {
146
+ return null;
147
+ }
148
+ get bodyUsed() {
149
+ return responseBodyUsedStore.get(this) === true;
150
+ }
135
151
  async arrayBuffer() {
136
- this.bodyUsed = true;
137
- return readBodyAsArrayBuffer(this.bodyValue);
152
+ responseBodyUsedStore.set(this, true);
153
+ return readBodyAsArrayBuffer(getResponseBodyValue(this));
138
154
  }
139
155
  async blob() {
140
156
  if (typeof Blob !== "function") throw new TypeError("Blob is unavailable in current runtime");
@@ -147,11 +163,11 @@ var ResponsePolyfill = class ResponsePolyfill {
147
163
  return JSON.parse(await this.text());
148
164
  }
149
165
  async text() {
150
- this.bodyUsed = true;
151
- return readBodyAsText(this.bodyValue);
166
+ responseBodyUsedStore.set(this, true);
167
+ return readBodyAsText(getResponseBodyValue(this));
152
168
  }
153
169
  clone() {
154
- return new ResponsePolyfill(this.bodyValue, {
170
+ return new ResponsePolyfill(getResponseBodyValue(this), {
155
171
  status: this.status,
156
172
  statusText: this.statusText,
157
173
  headers: this.headers,
package/dist/index.d.mts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { RequestGlobalsEventTarget } from "./shared.mjs";
2
2
  import { AbortControllerPolyfill, AbortSignalPolyfill } from "./abort.mjs";
3
+ import { URLPolyfill, URLSearchParamsPolyfill } from "./url.mjs";
3
4
  import { fetch } from "./fetch.mjs";
4
5
  import { HeadersPolyfill, RequestPolyfill, ResponsePolyfill } from "./http.mjs";
5
- import { URLPolyfill, URLSearchParamsPolyfill } from "./url.mjs";
6
6
  import { BlobPolyfill, FormDataPolyfill } from "./web.mjs";
7
7
  import { WebSocketPolyfill } from "./websocket.mjs";
8
8
  import { XMLHttpRequestPolyfill } from "./xhr.mjs";
@@ -59,6 +59,19 @@ declare const performancePolyfill: {
59
59
  //#region src/task.d.ts
60
60
  declare function queueMicrotaskPolyfill(callback: () => void): void;
61
61
  //#endregion
62
+ //#region src/textCodec.d.ts
63
+ type TextDecoderInput = ArrayBuffer | ArrayBufferView | null | undefined;
64
+ declare class TextEncoderPolyfill {
65
+ readonly encoding = "utf-8";
66
+ encode(input?: string): Uint8Array<ArrayBuffer>;
67
+ }
68
+ declare class TextDecoderPolyfill {
69
+ readonly encoding = "utf-8";
70
+ readonly fatal = false;
71
+ readonly ignoreBOM = false;
72
+ decode(input?: TextDecoderInput): string;
73
+ }
74
+ //#endregion
62
75
  //#region src/index.d.ts
63
76
  type WeappInjectWebRuntimeGlobalsTarget = 'fetch' | 'Headers' | 'Request' | 'Response' | 'TextEncoder' | 'TextDecoder' | 'AbortController' | 'AbortSignal' | 'XMLHttpRequest' | 'WebSocket' | 'atob' | 'btoa' | 'queueMicrotask' | 'performance' | 'crypto' | 'Event' | 'CustomEvent';
64
77
  type WeappInjectRequestGlobalsTarget = WeappInjectWebRuntimeGlobalsTarget;
@@ -79,4 +92,4 @@ declare function installRequestGlobals(options?: InstallRequestGlobalsOptions):
79
92
  */
80
93
  declare function installAbortGlobals(): Record<string, any>;
81
94
  //#endregion
82
- export { AbortControllerPolyfill, AbortSignalPolyfill, BlobPolyfill, CustomEventPolyfill, EventPolyfill, FormDataPolyfill, HeadersPolyfill, InstallRequestGlobalsOptions, InstallWebRuntimeGlobalsOptions, RequestGlobalsEventTarget, RequestPolyfill, ResponsePolyfill, URLPolyfill, URLSearchParamsPolyfill, WeappInjectRequestGlobalsTarget, WeappInjectWebRuntimeGlobalsTarget, WebSocketPolyfill, XMLHttpRequestPolyfill, atobPolyfill, btoaPolyfill, cryptoPolyfill, fetch, installAbortGlobals, installRequestGlobals, installWebRuntimeGlobals, performancePolyfill, queueMicrotaskPolyfill };
95
+ export { AbortControllerPolyfill, AbortSignalPolyfill, BlobPolyfill, CustomEventPolyfill, EventPolyfill, FormDataPolyfill, HeadersPolyfill, InstallRequestGlobalsOptions, InstallWebRuntimeGlobalsOptions, RequestGlobalsEventTarget, RequestPolyfill, ResponsePolyfill, TextDecoderPolyfill, TextEncoderPolyfill, URLPolyfill, URLSearchParamsPolyfill, WeappInjectRequestGlobalsTarget, WeappInjectWebRuntimeGlobalsTarget, WebSocketPolyfill, XMLHttpRequestPolyfill, atobPolyfill, btoaPolyfill, cryptoPolyfill, fetch, installAbortGlobals, installRequestGlobals, installWebRuntimeGlobals, performancePolyfill, queueMicrotaskPolyfill };
package/dist/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
- import { RequestGlobalsEventTarget, decodeTextFallback, encodeTextFallback, installRequestGlobalBinding, resolveRequestGlobalsHost, resolveRequestGlobalsHosts } from "./shared.mjs";
1
+ import { a as decodeTextFallback, c as installRequestGlobalBinding, d as resolveRequestGlobalsHosts, g as getMiniProgramRuntimeGlobalKeys, s as encodeTextFallback, t as RequestGlobalsEventTarget, u as resolveRequestGlobalsHost } from "./shared-1FH7Skf_.mjs";
2
+ import { URLPolyfill, URLSearchParamsPolyfill } from "./url.mjs";
2
3
  import { AbortControllerPolyfill, AbortSignalPolyfill } from "./abort.mjs";
3
4
  import { HeadersPolyfill, RequestPolyfill, ResponsePolyfill } from "./http.mjs";
4
5
  import { fetch } from "./fetch.mjs";
5
- import { URLPolyfill, URLSearchParamsPolyfill } from "./url.mjs";
6
6
  import { BlobPolyfill, FormDataPolyfill } from "./web.mjs";
7
7
  import { WebSocketPolyfill } from "./websocket.mjs";
8
8
  import { XMLHttpRequestPolyfill } from "./xhr.mjs";
@@ -69,11 +69,7 @@ function fillArrayWithMathRandom(target) {
69
69
  for (let index = 0; index < bytes.length; index++) bytes[index] = Math.floor(Math.random() * 256);
70
70
  }
71
71
  function fillArrayWithHostRandomValues(target) {
72
- for (const hostKey of [
73
- "wx",
74
- "my",
75
- "tt"
76
- ]) {
72
+ for (const hostKey of getMiniProgramRuntimeGlobalKeys()) {
77
73
  const host = globalThis[hostKey];
78
74
  if (!host || typeof host.getRandomValues !== "function") continue;
79
75
  try {
@@ -138,11 +134,7 @@ const PERFORMANCE_POLYFILL_MARKER = "__weappVitePerformancePolyfill";
138
134
  function resolveNativePerformance() {
139
135
  const candidate = globalThis.performance;
140
136
  if (candidate && candidate?.[PERFORMANCE_POLYFILL_MARKER] !== true && typeof candidate.now === "function") return candidate;
141
- for (const hostKey of [
142
- "wx",
143
- "my",
144
- "tt"
145
- ]) {
137
+ for (const hostKey of getMiniProgramRuntimeGlobalKeys()) {
146
138
  const host = globalThis[hostKey];
147
139
  if (!host || typeof host.getPerformance !== "function") continue;
148
140
  try {
@@ -398,4 +390,4 @@ function installAbortGlobals() {
398
390
  return installWebRuntimeGlobals({ targets: ["AbortController", "AbortSignal"] });
399
391
  }
400
392
  //#endregion
401
- export { AbortControllerPolyfill, AbortSignalPolyfill, BlobPolyfill, CustomEventPolyfill, EventPolyfill, FormDataPolyfill, HeadersPolyfill, RequestGlobalsEventTarget, RequestPolyfill, ResponsePolyfill, URLPolyfill, URLSearchParamsPolyfill, WebSocketPolyfill, XMLHttpRequestPolyfill, atobPolyfill, btoaPolyfill, cryptoPolyfill, fetch, installAbortGlobals, installRequestGlobals, installWebRuntimeGlobals, performancePolyfill, queueMicrotaskPolyfill };
393
+ export { AbortControllerPolyfill, AbortSignalPolyfill, BlobPolyfill, CustomEventPolyfill, EventPolyfill, FormDataPolyfill, HeadersPolyfill, RequestGlobalsEventTarget, RequestPolyfill, ResponsePolyfill, TextDecoderPolyfill, TextEncoderPolyfill, URLPolyfill, URLSearchParamsPolyfill, WebSocketPolyfill, XMLHttpRequestPolyfill, atobPolyfill, btoaPolyfill, cryptoPolyfill, fetch, installAbortGlobals, installRequestGlobals, installWebRuntimeGlobals, performancePolyfill, queueMicrotaskPolyfill };
@@ -0,0 +1,689 @@
1
+ import { URLPolyfill, URLSearchParamsPolyfill } from "./url.mjs";
2
+ //#region ../../@weapp-core/shared/dist/index.js
3
+ var __create = Object.create;
4
+ var __defProp$1 = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
12
+ key = keys[i];
13
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp$1(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp$1(target, "default", {
21
+ value: mod,
22
+ enumerable: true
23
+ }) : target, mod));
24
+ function isPlainObject(value) {
25
+ if (value === null || typeof value !== "object") return false;
26
+ const prototype = Object.getPrototypeOf(value);
27
+ if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) return false;
28
+ if (Symbol.iterator in value) return false;
29
+ if (Symbol.toStringTag in value) return Object.prototype.toString.call(value) === "[object Module]";
30
+ return true;
31
+ }
32
+ function _defu(baseObject, defaults, namespace = ".", merger) {
33
+ if (!isPlainObject(defaults)) return _defu(baseObject, {}, namespace, merger);
34
+ const object = { ...defaults };
35
+ for (const key of Object.keys(baseObject)) {
36
+ if (key === "__proto__" || key === "constructor") continue;
37
+ const value = baseObject[key];
38
+ if (value === null || value === void 0) continue;
39
+ if (merger && merger(object, key, value, namespace)) continue;
40
+ if (Array.isArray(value) && Array.isArray(object[key])) object[key] = [...value, ...object[key]];
41
+ else if (isPlainObject(value) && isPlainObject(object[key])) object[key] = _defu(value, object[key], (namespace ? `${namespace}.` : "") + key.toString(), merger);
42
+ else object[key] = value;
43
+ }
44
+ return object;
45
+ }
46
+ function createDefu(merger) {
47
+ return (...arguments_) => arguments_.reduce((p, c) => _defu(p, c, "", merger), {});
48
+ }
49
+ createDefu();
50
+ createDefu((object, key, currentValue) => {
51
+ if (object[key] !== void 0 && typeof currentValue === "function") {
52
+ object[key] = currentValue(object[key]);
53
+ return true;
54
+ }
55
+ });
56
+ createDefu((object, key, currentValue) => {
57
+ if (Array.isArray(object[key]) && typeof currentValue === "function") {
58
+ object[key] = currentValue(object[key]);
59
+ return true;
60
+ }
61
+ });
62
+ const DEFAULT_PROJECT_CONFIG_ROOT_KEYS = ["miniprogramRoot", "srcMiniprogramRoot"];
63
+ const DEFAULT_RUNTIME_CAPABILITIES = Object.freeze({
64
+ globalPageStack: true,
65
+ globalCreateSelectorQuery: true,
66
+ selectorQueryScopeByIn: true,
67
+ globalCreateIntersectionObserver: true,
68
+ intersectionObserverScopeByParameter: true,
69
+ pageShareMenu: true,
70
+ shareTimelineRequiresShareAppMessage: true,
71
+ pageScrollApi: true,
72
+ pullDownRefreshApi: true,
73
+ globalRouterApi: true,
74
+ appErrorListener: true,
75
+ appPageNotFoundListener: true,
76
+ appUnhandledRejectionListener: true,
77
+ appThemeChangeListener: true,
78
+ appMemoryWarningListener: true
79
+ });
80
+ const DEFAULT_PAGE_IDENTITY_RULES = [{
81
+ prefix: "route",
82
+ source: "route"
83
+ }];
84
+ /**
85
+ * @description 全仓库统一的小程序平台描述表。
86
+ */
87
+ const MINI_PROGRAM_PLATFORM_DESCRIPTORS = [
88
+ {
89
+ id: "weapp",
90
+ displayName: "WeChat Mini Program",
91
+ family: "wechat",
92
+ aliases: [
93
+ "weapp",
94
+ "wechat",
95
+ "weixin",
96
+ "wx"
97
+ ],
98
+ outputExtensions: {
99
+ js: "js",
100
+ json: "json",
101
+ wxml: "wxml",
102
+ wxss: "wxss",
103
+ wxs: "wxs"
104
+ },
105
+ projectConfigFileName: "project.config.json",
106
+ projectConfigRootKeys: DEFAULT_PROJECT_CONFIG_ROOT_KEYS,
107
+ ide: {},
108
+ build: {
109
+ autoTouchAppStyle: true,
110
+ defaultBuildTarget: "es2020"
111
+ },
112
+ resolvePreservedNpmDirNames: () => ["miniprogram_npm"],
113
+ json: {},
114
+ npm: { distDirName: () => "miniprogram_npm" },
115
+ wxml: {
116
+ eventBindingStyle: "default",
117
+ directivePrefix: "wx"
118
+ },
119
+ compiler: { templatePreset: "wechat" },
120
+ typescript: { appTypesPackage: "miniprogram-api-typings" },
121
+ runtime: {
122
+ globalObjectKey: "wx",
123
+ hostConfigKey: "__wxConfig",
124
+ globalResolvePriority: 1,
125
+ routeGlobalResolvePriority: 0,
126
+ capabilities: DEFAULT_RUNTIME_CAPABILITIES,
127
+ pageIdentityRules: [
128
+ {
129
+ prefix: "webview",
130
+ source: "field",
131
+ field: "__wxWebviewId__"
132
+ },
133
+ {
134
+ prefix: "exparser",
135
+ source: "field",
136
+ field: "__wxExparserNodeId__"
137
+ },
138
+ ...DEFAULT_PAGE_IDENTITY_RULES
139
+ ]
140
+ }
141
+ },
142
+ {
143
+ id: "alipay",
144
+ displayName: "Alipay Mini Program",
145
+ family: "alipay",
146
+ aliases: [
147
+ "alipay",
148
+ "ali",
149
+ "my"
150
+ ],
151
+ outputExtensions: {
152
+ js: "js",
153
+ json: "json",
154
+ wxml: "axml",
155
+ wxss: "acss",
156
+ wxs: "sjs"
157
+ },
158
+ projectConfigFileName: "mini.project.json",
159
+ projectConfigRootKeys: DEFAULT_PROJECT_CONFIG_ROOT_KEYS,
160
+ scriptModuleTagByExtension: { sjs: "import-sjs" },
161
+ usesProjectRootNpmDir: true,
162
+ ide: {
163
+ requiresOpenPlatformArg: true,
164
+ defaultProjectRoot: "dist/alipay/dist"
165
+ },
166
+ build: {
167
+ autoTouchAppStyle: false,
168
+ defaultBuildTarget: "es2015"
169
+ },
170
+ resolvePreservedNpmDirNames: (options) => [options?.alipayNpmMode === "miniprogram_npm" ? "miniprogram_npm" : "node_modules"],
171
+ json: {
172
+ normalizeUsingComponents: true,
173
+ fillComponentGenericsDefault: true,
174
+ rewriteBundleNpmImports: true
175
+ },
176
+ npm: {
177
+ distDirName: (options) => options?.alipayNpmMode === "miniprogram_npm" ? "miniprogram_npm" : "node_modules",
178
+ normalizeImportPath: true,
179
+ normalizeMiniprogramPackage: true,
180
+ copyEsModuleDirectory: true,
181
+ hoistNestedDependencies: true,
182
+ shouldRebuildCachedPackage: true
183
+ },
184
+ wxml: {
185
+ eventBindingStyle: "alipay",
186
+ directivePrefix: "a",
187
+ normalizeComponentTagName: true,
188
+ normalizeVueTemplate: true,
189
+ emitGenericPlaceholder: true
190
+ },
191
+ compiler: { templatePreset: "alipay" },
192
+ typescript: { appTypesPackage: "@mini-types/alipay" },
193
+ runtime: {
194
+ globalObjectKey: "my",
195
+ hostConfigKey: "__wxConfig",
196
+ globalResolvePriority: 0,
197
+ routeGlobalResolvePriority: 2,
198
+ capabilities: {
199
+ ...DEFAULT_RUNTIME_CAPABILITIES,
200
+ pageShareMenu: false,
201
+ appThemeChangeListener: false
202
+ },
203
+ pageIdentityRules: DEFAULT_PAGE_IDENTITY_RULES
204
+ }
205
+ },
206
+ {
207
+ id: "swan",
208
+ displayName: "Baidu Smart Program",
209
+ family: "swan",
210
+ aliases: [
211
+ "swan",
212
+ "baidu",
213
+ "bd"
214
+ ],
215
+ outputExtensions: {
216
+ js: "js",
217
+ json: "json",
218
+ wxml: "swan",
219
+ wxss: "css",
220
+ wxs: "sjs"
221
+ },
222
+ projectConfigFileName: "project.swan.json",
223
+ projectConfigRootKeys: ["smartProgramRoot", ...DEFAULT_PROJECT_CONFIG_ROOT_KEYS],
224
+ ide: {},
225
+ build: { autoTouchAppStyle: false },
226
+ resolvePreservedNpmDirNames: () => ["miniprogram_npm"],
227
+ json: {},
228
+ npm: { distDirName: () => "miniprogram_npm" },
229
+ wxml: {
230
+ eventBindingStyle: "default",
231
+ directivePrefix: "s"
232
+ },
233
+ compiler: { templatePreset: "swan" },
234
+ typescript: { appTypesPackage: "miniprogram-api-typings" },
235
+ runtime: {
236
+ globalObjectKey: "swan",
237
+ hostConfigKey: "__wxConfig",
238
+ capabilities: DEFAULT_RUNTIME_CAPABILITIES,
239
+ pageIdentityRules: DEFAULT_PAGE_IDENTITY_RULES
240
+ }
241
+ },
242
+ {
243
+ id: "tt",
244
+ displayName: "ByteDance / Douyin Mini Program",
245
+ family: "tt",
246
+ aliases: [
247
+ "tt",
248
+ "toutiao",
249
+ "bytedance",
250
+ "douyin"
251
+ ],
252
+ outputExtensions: {
253
+ js: "js",
254
+ json: "json",
255
+ wxml: "ttml",
256
+ wxss: "ttss"
257
+ },
258
+ projectConfigFileName: "project.config.json",
259
+ projectConfigRootKeys: DEFAULT_PROJECT_CONFIG_ROOT_KEYS,
260
+ ide: {},
261
+ build: { autoTouchAppStyle: false },
262
+ resolvePreservedNpmDirNames: () => ["miniprogram_npm"],
263
+ json: {},
264
+ npm: { distDirName: () => "miniprogram_npm" },
265
+ wxml: {
266
+ eventBindingStyle: "default",
267
+ directivePrefix: "tt"
268
+ },
269
+ compiler: { templatePreset: "tt" },
270
+ typescript: { appTypesPackage: "@douyin-microapp/typings" },
271
+ runtime: {
272
+ globalObjectKey: "tt",
273
+ hostConfigKey: "__wxConfig",
274
+ globalResolvePriority: 2,
275
+ routeGlobalResolvePriority: 1,
276
+ capabilities: {
277
+ ...DEFAULT_RUNTIME_CAPABILITIES,
278
+ appThemeChangeListener: false
279
+ },
280
+ pageIdentityRules: DEFAULT_PAGE_IDENTITY_RULES
281
+ }
282
+ },
283
+ {
284
+ id: "jd",
285
+ displayName: "JD Mini Program",
286
+ family: "wechat",
287
+ aliases: ["jd", "jingdong"],
288
+ outputExtensions: {
289
+ js: "js",
290
+ json: "json",
291
+ wxml: "jxml",
292
+ wxss: "jxss",
293
+ wxs: "wxs"
294
+ },
295
+ projectConfigFileName: "project.config.json",
296
+ projectConfigRootKeys: DEFAULT_PROJECT_CONFIG_ROOT_KEYS,
297
+ ide: {},
298
+ build: { autoTouchAppStyle: false },
299
+ resolvePreservedNpmDirNames: () => ["miniprogram_npm"],
300
+ json: {},
301
+ npm: { distDirName: () => "miniprogram_npm" },
302
+ wxml: {
303
+ eventBindingStyle: "default",
304
+ directivePrefix: "wx"
305
+ },
306
+ compiler: { templatePreset: "wechat" },
307
+ typescript: { appTypesPackage: "miniprogram-api-typings" },
308
+ runtime: {
309
+ globalObjectKey: "jd",
310
+ hostConfigKey: "__wxConfig",
311
+ capabilities: DEFAULT_RUNTIME_CAPABILITIES,
312
+ pageIdentityRules: DEFAULT_PAGE_IDENTITY_RULES
313
+ }
314
+ },
315
+ {
316
+ id: "xhs",
317
+ displayName: "Xiaohongshu Mini Program",
318
+ family: "wechat",
319
+ aliases: [
320
+ "xhs",
321
+ "xiaohongshu",
322
+ "little-red-book",
323
+ "red"
324
+ ],
325
+ outputExtensions: {
326
+ js: "js",
327
+ json: "json",
328
+ wxml: "xhsml",
329
+ wxss: "css",
330
+ wxs: "wxs"
331
+ },
332
+ projectConfigFileName: "project.config.json",
333
+ projectConfigRootKeys: DEFAULT_PROJECT_CONFIG_ROOT_KEYS,
334
+ ide: {},
335
+ build: { autoTouchAppStyle: false },
336
+ resolvePreservedNpmDirNames: () => ["miniprogram_npm"],
337
+ json: {},
338
+ npm: { distDirName: () => "miniprogram_npm" },
339
+ wxml: {
340
+ eventBindingStyle: "default",
341
+ directivePrefix: "wx"
342
+ },
343
+ compiler: { templatePreset: "wechat" },
344
+ typescript: { appTypesPackage: "miniprogram-api-typings" },
345
+ runtime: {
346
+ globalObjectKey: "xhs",
347
+ hostConfigKey: "__wxConfig",
348
+ capabilities: DEFAULT_RUNTIME_CAPABILITIES,
349
+ pageIdentityRules: DEFAULT_PAGE_IDENTITY_RULES
350
+ }
351
+ }
352
+ ];
353
+ function createMiniProgramPlatformRegistry(descriptors) {
354
+ const descriptorById = /* @__PURE__ */ new Map();
355
+ const aliasToId = /* @__PURE__ */ new Map();
356
+ const runtimeGlobalKeyToId = /* @__PURE__ */ new Map();
357
+ for (const descriptor of descriptors) {
358
+ descriptorById.set(descriptor.id, descriptor);
359
+ runtimeGlobalKeyToId.set(descriptor.runtime.globalObjectKey, descriptor.id);
360
+ aliasToId.set(descriptor.id, descriptor.id);
361
+ for (const alias of descriptor.aliases) {
362
+ const normalized = alias.trim().toLowerCase();
363
+ if (!normalized) continue;
364
+ aliasToId.set(normalized, descriptor.id);
365
+ }
366
+ }
367
+ return {
368
+ aliasToId,
369
+ descriptorById,
370
+ runtimeGlobalKeyToId
371
+ };
372
+ }
373
+ const { aliasToId: MINI_PROGRAM_PLATFORM_ALIAS_TO_ID, descriptorById: MINI_PROGRAM_PLATFORM_DESCRIPTOR_BY_ID, runtimeGlobalKeyToId: MINI_PROGRAM_RUNTIME_GLOBAL_KEY_TO_ID } = createMiniProgramPlatformRegistry(MINI_PROGRAM_PLATFORM_DESCRIPTORS);
374
+ Object.freeze(MINI_PROGRAM_PLATFORM_DESCRIPTORS.map((descriptor) => descriptor.id));
375
+ Object.freeze(Array.from(new Set(MINI_PROGRAM_PLATFORM_DESCRIPTORS.map((descriptor) => descriptor.wxml?.directivePrefix).filter((prefix) => Boolean(prefix)))));
376
+ const ORDERED_RUNTIME_GLOBAL_KEYS = Object.freeze(Array.from(new Set(MINI_PROGRAM_PLATFORM_DESCRIPTORS.map((descriptor) => descriptor.runtime.globalObjectKey))));
377
+ const MAX_RUNTIME_RESOLVE_PRIORITY = Number.MAX_SAFE_INTEGER;
378
+ function getOrderedRuntimeGlobalKeysByPriority(priorityKey) {
379
+ const ordered = [...MINI_PROGRAM_PLATFORM_DESCRIPTORS].sort((left, right) => {
380
+ const leftPriority = left.runtime[priorityKey] ?? MAX_RUNTIME_RESOLVE_PRIORITY;
381
+ const rightPriority = right.runtime[priorityKey] ?? MAX_RUNTIME_RESOLVE_PRIORITY;
382
+ if (leftPriority !== rightPriority) return leftPriority - rightPriority;
383
+ return MINI_PROGRAM_PLATFORM_DESCRIPTORS.indexOf(left) - MINI_PROGRAM_PLATFORM_DESCRIPTORS.indexOf(right);
384
+ });
385
+ return Object.freeze(Array.from(new Set(ordered.map((descriptor) => descriptor.runtime.globalObjectKey))));
386
+ }
387
+ getOrderedRuntimeGlobalKeysByPriority("globalResolvePriority");
388
+ getOrderedRuntimeGlobalKeysByPriority("routeGlobalResolvePriority");
389
+ Object.freeze(Object.fromEntries(MINI_PROGRAM_PLATFORM_ALIAS_TO_ID.entries()));
390
+ /**
391
+ * @description 获取平台描述。
392
+ */
393
+ function getMiniProgramPlatformDescriptor(platform) {
394
+ const descriptor = MINI_PROGRAM_PLATFORM_DESCRIPTOR_BY_ID.get(platform);
395
+ if (!descriptor) throw new Error(`不支持的小程序平台 "${platform}"。`);
396
+ return descriptor;
397
+ }
398
+ /**
399
+ * @description 获取宿主全局对象 key。
400
+ */
401
+ function getMiniProgramRuntimeGlobalKey(platform) {
402
+ return getMiniProgramPlatformDescriptor(platform).runtime.globalObjectKey;
403
+ }
404
+ /**
405
+ * @description 返回 runtime 全局对象 key 的扫描优先级。
406
+ */
407
+ function getMiniProgramRuntimeGlobalKeys(platform) {
408
+ if (platform) return [getMiniProgramRuntimeGlobalKey(platform)];
409
+ return ORDERED_RUNTIME_GLOBAL_KEYS;
410
+ }
411
+ /*!
412
+ * get-value <https://github.com/jonschlinkert/get-value>
413
+ *
414
+ * Copyright (c) 2014-present, Jon Schlinkert.
415
+ * Released under the MIT License.
416
+ */
417
+ /*!
418
+ * is-primitive <https://github.com/jonschlinkert/is-primitive>
419
+ *
420
+ * Copyright (c) 2014-present, Jon Schlinkert.
421
+ * Released under the MIT License.
422
+ */
423
+ var require_is_primitive = /* @__PURE__ */ __commonJSMin(((exports, module) => {
424
+ module.exports = function isPrimitive(val) {
425
+ if (typeof val === "object") return val === null;
426
+ return typeof val !== "function";
427
+ };
428
+ }));
429
+ /*!
430
+ * isobject <https://github.com/jonschlinkert/isobject>
431
+ *
432
+ * Copyright (c) 2014-2017, Jon Schlinkert.
433
+ * Released under the MIT License.
434
+ */
435
+ var require_isobject = /* @__PURE__ */ __commonJSMin(((exports, module) => {
436
+ module.exports = function isObject(val) {
437
+ return val != null && typeof val === "object" && Array.isArray(val) === false;
438
+ };
439
+ }));
440
+ /*!
441
+ * is-plain-object <https://github.com/jonschlinkert/is-plain-object>
442
+ *
443
+ * Copyright (c) 2014-2017, Jon Schlinkert.
444
+ * Released under the MIT License.
445
+ */
446
+ var require_is_plain_object = /* @__PURE__ */ __commonJSMin(((exports, module) => {
447
+ var isObject = require_isobject();
448
+ function isObjectObject(o) {
449
+ return isObject(o) === true && Object.prototype.toString.call(o) === "[object Object]";
450
+ }
451
+ module.exports = function isPlainObject(o) {
452
+ var ctor, prot;
453
+ if (isObjectObject(o) === false) return false;
454
+ ctor = o.constructor;
455
+ if (typeof ctor !== "function") return false;
456
+ prot = ctor.prototype;
457
+ if (isObjectObject(prot) === false) return false;
458
+ if (prot.hasOwnProperty("isPrototypeOf") === false) return false;
459
+ return true;
460
+ };
461
+ }));
462
+ var import_set_value = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
463
+ const { deleteProperty } = Reflect;
464
+ const isPrimitive = require_is_primitive();
465
+ const isPlainObject = require_is_plain_object();
466
+ const isObject = (value) => {
467
+ return typeof value === "object" && value !== null || typeof value === "function";
468
+ };
469
+ const isUnsafeKey = (key) => {
470
+ return key === "__proto__" || key === "constructor" || key === "prototype";
471
+ };
472
+ const validateKey = (key) => {
473
+ if (!isPrimitive(key)) throw new TypeError("Object keys must be strings or symbols");
474
+ if (isUnsafeKey(key)) throw new Error(`Cannot set unsafe key: "${key}"`);
475
+ };
476
+ const toStringKey = (input) => {
477
+ return Array.isArray(input) ? input.flat().map(String).join(",") : input;
478
+ };
479
+ const createMemoKey = (input, options) => {
480
+ if (typeof input !== "string" || !options) return input;
481
+ let key = input + ";";
482
+ if (options.arrays !== void 0) key += `arrays=${options.arrays};`;
483
+ if (options.separator !== void 0) key += `separator=${options.separator};`;
484
+ if (options.split !== void 0) key += `split=${options.split};`;
485
+ if (options.merge !== void 0) key += `merge=${options.merge};`;
486
+ if (options.preservePaths !== void 0) key += `preservePaths=${options.preservePaths};`;
487
+ return key;
488
+ };
489
+ const memoize = (input, options, fn) => {
490
+ const key = toStringKey(options ? createMemoKey(input, options) : input);
491
+ validateKey(key);
492
+ const value = setValue.cache.get(key) || fn();
493
+ setValue.cache.set(key, value);
494
+ return value;
495
+ };
496
+ const splitString = (input, options = {}) => {
497
+ const sep = options.separator || ".";
498
+ const preserve = sep === "/" ? false : options.preservePaths;
499
+ if (typeof input === "string" && preserve !== false && /\//.test(input)) return [input];
500
+ const parts = [];
501
+ let part = "";
502
+ const push = (part) => {
503
+ let number;
504
+ if (part.trim() !== "" && Number.isInteger(number = Number(part))) parts.push(number);
505
+ else parts.push(part);
506
+ };
507
+ for (let i = 0; i < input.length; i++) {
508
+ const value = input[i];
509
+ if (value === "\\") {
510
+ part += input[++i];
511
+ continue;
512
+ }
513
+ if (value === sep) {
514
+ push(part);
515
+ part = "";
516
+ continue;
517
+ }
518
+ part += value;
519
+ }
520
+ if (part) push(part);
521
+ return parts;
522
+ };
523
+ const split = (input, options) => {
524
+ if (options && typeof options.split === "function") return options.split(input);
525
+ if (typeof input === "symbol") return [input];
526
+ if (Array.isArray(input)) return input;
527
+ return memoize(input, options, () => splitString(input, options));
528
+ };
529
+ const assignProp = (obj, prop, value, options) => {
530
+ validateKey(prop);
531
+ if (value === void 0) deleteProperty(obj, prop);
532
+ else if (options && options.merge) {
533
+ const merge = options.merge === "function" ? options.merge : Object.assign;
534
+ if (merge && isPlainObject(obj[prop]) && isPlainObject(value)) obj[prop] = merge(obj[prop], value);
535
+ else obj[prop] = value;
536
+ } else obj[prop] = value;
537
+ return obj;
538
+ };
539
+ const setValue = (target, path, value, options) => {
540
+ if (!path || !isObject(target)) return target;
541
+ const keys = split(path, options);
542
+ let obj = target;
543
+ for (let i = 0; i < keys.length; i++) {
544
+ const key = keys[i];
545
+ const next = keys[i + 1];
546
+ validateKey(key);
547
+ if (next === void 0) {
548
+ assignProp(obj, key, value, options);
549
+ break;
550
+ }
551
+ if (typeof next === "number" && !Array.isArray(obj[key])) {
552
+ obj = obj[key] = [];
553
+ continue;
554
+ }
555
+ if (!isObject(obj[key])) obj[key] = {};
556
+ obj = obj[key];
557
+ }
558
+ return target;
559
+ };
560
+ setValue.split = split;
561
+ setValue.cache = /* @__PURE__ */ new Map();
562
+ setValue.clear = () => {
563
+ setValue.cache = /* @__PURE__ */ new Map();
564
+ };
565
+ module.exports = setValue;
566
+ })))(), 1);
567
+ createDefu((obj, key, value) => {
568
+ if (Array.isArray(obj[key]) && Array.isArray(value)) {
569
+ obj[key] = value;
570
+ return true;
571
+ }
572
+ });
573
+ import_set_value.default;
574
+ //#endregion
575
+ //#region src/constructors.ts
576
+ function resolveUrlConstructor() {
577
+ return typeof globalThis.URL === "function" ? globalThis.URL : void 0;
578
+ }
579
+ function isUrlInstance(value) {
580
+ const HostUrl = resolveUrlConstructor();
581
+ return Boolean(HostUrl && value instanceof HostUrl || value instanceof URLPolyfill);
582
+ }
583
+ function resolveUrlSearchParamsConstructor() {
584
+ return typeof globalThis.URLSearchParams === "function" ? globalThis.URLSearchParams : void 0;
585
+ }
586
+ function isUrlSearchParamsInstance(value) {
587
+ const HostUrlSearchParams = resolveUrlSearchParamsConstructor();
588
+ return Boolean(HostUrlSearchParams && value instanceof HostUrlSearchParams || value instanceof URLSearchParamsPolyfill);
589
+ }
590
+ function resolveTextEncoderConstructor() {
591
+ return typeof globalThis.TextEncoder === "function" ? globalThis.TextEncoder : void 0;
592
+ }
593
+ function resolveTextDecoderConstructor() {
594
+ return typeof globalThis.TextDecoder === "function" ? globalThis.TextDecoder : void 0;
595
+ }
596
+ //#endregion
597
+ //#region src/shared.ts
598
+ var RequestGlobalsEventTarget = class {
599
+ listeners = /* @__PURE__ */ new Map();
600
+ addEventListener(type, listener) {
601
+ const set = this.listeners.get(type) ?? /* @__PURE__ */ new Set();
602
+ set.add(listener);
603
+ this.listeners.set(type, set);
604
+ }
605
+ removeEventListener(type, listener) {
606
+ this.listeners.get(type)?.delete(listener);
607
+ }
608
+ dispatchEvent(event) {
609
+ const payload = {
610
+ ...event,
611
+ target: event.target ?? this,
612
+ currentTarget: event.currentTarget ?? this
613
+ };
614
+ for (const listener of this.listeners.get(event.type) ?? []) listener(payload);
615
+ const handlerKey = `on${event.type}`;
616
+ const handler = this[handlerKey];
617
+ if (typeof handler === "function") handler(payload);
618
+ return true;
619
+ }
620
+ };
621
+ function resolveRequestGlobalsHost() {
622
+ if (typeof globalThis !== "undefined") return globalThis;
623
+ return {};
624
+ }
625
+ function isRequestGlobalsHostCandidate(value) {
626
+ return value != null && (typeof value === "object" || typeof value === "function");
627
+ }
628
+ function pushRequestGlobalsHost(hosts, candidate) {
629
+ if (!isRequestGlobalsHostCandidate(candidate)) return;
630
+ if (!hosts.includes(candidate)) hosts.push(candidate);
631
+ }
632
+ function resolveRequestGlobalsHosts() {
633
+ const hosts = [];
634
+ const primaryHost = resolveRequestGlobalsHost();
635
+ pushRequestGlobalsHost(hosts, primaryHost);
636
+ for (const name of [
637
+ "global",
638
+ "self",
639
+ "window"
640
+ ]) pushRequestGlobalsHost(hosts, primaryHost[name]);
641
+ for (const key of getMiniProgramRuntimeGlobalKeys()) pushRequestGlobalsHost(hosts, primaryHost[key]);
642
+ return hosts;
643
+ }
644
+ function installRequestGlobalBinding(name, value) {
645
+ if (!name) return;
646
+ try {
647
+ const host = resolveRequestGlobalsHost();
648
+ host[name] = value;
649
+ } catch {}
650
+ }
651
+ function cloneArrayBuffer(buffer) {
652
+ return buffer.slice(0);
653
+ }
654
+ function cloneArrayBufferView(view) {
655
+ const copied = new Uint8Array(view.byteLength);
656
+ copied.set(new Uint8Array(view.buffer, view.byteOffset, view.byteLength));
657
+ return copied.buffer;
658
+ }
659
+ function encodeTextFallback(value) {
660
+ const binary = unescape(encodeURIComponent(String(value)));
661
+ const bytes = new Uint8Array(binary.length);
662
+ for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
663
+ return bytes.buffer;
664
+ }
665
+ function encodeText(value) {
666
+ const TextEncoderConstructor = resolveTextEncoderConstructor();
667
+ if (TextEncoderConstructor) return new TextEncoderConstructor().encode(value).buffer;
668
+ return encodeTextFallback(value);
669
+ }
670
+ function decodeTextFallback(value) {
671
+ const bytes = new Uint8Array(value);
672
+ let binary = "";
673
+ for (const byte of bytes) binary += String.fromCharCode(byte);
674
+ try {
675
+ return decodeURIComponent(escape(binary));
676
+ } catch {
677
+ return binary;
678
+ }
679
+ }
680
+ function decodeText(value) {
681
+ const TextDecoderConstructor = resolveTextDecoderConstructor();
682
+ if (TextDecoderConstructor) return new TextDecoderConstructor().decode(value);
683
+ return decodeTextFallback(value);
684
+ }
685
+ function normalizeHeaderName(name) {
686
+ return name.trim().toLowerCase();
687
+ }
688
+ //#endregion
689
+ export { decodeTextFallback as a, installRequestGlobalBinding as c, resolveRequestGlobalsHosts as d, isUrlInstance as f, getMiniProgramRuntimeGlobalKeys as g, resolveUrlConstructor as h, decodeText as i, normalizeHeaderName as l, resolveTextEncoderConstructor as m, cloneArrayBuffer as n, encodeText as o, isUrlSearchParamsInstance as p, cloneArrayBufferView as r, encodeTextFallback as s, RequestGlobalsEventTarget as t, resolveRequestGlobalsHost as u };
package/dist/shared.mjs CHANGED
@@ -1,95 +1,2 @@
1
- //#region src/shared.ts
2
- var RequestGlobalsEventTarget = class {
3
- listeners = /* @__PURE__ */ new Map();
4
- addEventListener(type, listener) {
5
- const set = this.listeners.get(type) ?? /* @__PURE__ */ new Set();
6
- set.add(listener);
7
- this.listeners.set(type, set);
8
- }
9
- removeEventListener(type, listener) {
10
- this.listeners.get(type)?.delete(listener);
11
- }
12
- dispatchEvent(event) {
13
- const payload = {
14
- ...event,
15
- target: event.target ?? this,
16
- currentTarget: event.currentTarget ?? this
17
- };
18
- for (const listener of this.listeners.get(event.type) ?? []) listener(payload);
19
- const handlerKey = `on${event.type}`;
20
- const handler = this[handlerKey];
21
- if (typeof handler === "function") handler(payload);
22
- return true;
23
- }
24
- };
25
- function resolveRequestGlobalsHost() {
26
- if (typeof globalThis !== "undefined") return globalThis;
27
- return {};
28
- }
29
- function isRequestGlobalsHostCandidate(value) {
30
- return value != null && (typeof value === "object" || typeof value === "function");
31
- }
32
- function pushRequestGlobalsHost(hosts, candidate) {
33
- if (!isRequestGlobalsHostCandidate(candidate)) return;
34
- if (!hosts.includes(candidate)) hosts.push(candidate);
35
- }
36
- function resolveRequestGlobalsHosts() {
37
- const hosts = [];
38
- const primaryHost = resolveRequestGlobalsHost();
39
- pushRequestGlobalsHost(hosts, primaryHost);
40
- for (const name of [
41
- "global",
42
- "self",
43
- "window"
44
- ]) pushRequestGlobalsHost(hosts, primaryHost[name]);
45
- for (const key of [
46
- "wx",
47
- "my",
48
- "tt"
49
- ]) pushRequestGlobalsHost(hosts, primaryHost[key]);
50
- return hosts;
51
- }
52
- function installRequestGlobalBinding(name, value) {
53
- if (!name) return;
54
- try {
55
- const host = resolveRequestGlobalsHost();
56
- host[name] = value;
57
- } catch {}
58
- }
59
- function cloneArrayBuffer(buffer) {
60
- return buffer.slice(0);
61
- }
62
- function cloneArrayBufferView(view) {
63
- const copied = new Uint8Array(view.byteLength);
64
- copied.set(new Uint8Array(view.buffer, view.byteOffset, view.byteLength));
65
- return copied.buffer;
66
- }
67
- function encodeTextFallback(value) {
68
- const binary = unescape(encodeURIComponent(String(value)));
69
- const bytes = new Uint8Array(binary.length);
70
- for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
71
- return bytes.buffer;
72
- }
73
- function encodeText(value) {
74
- if (typeof TextEncoder === "function") return new TextEncoder().encode(value).buffer;
75
- return encodeTextFallback(value);
76
- }
77
- function decodeTextFallback(value) {
78
- const bytes = new Uint8Array(value);
79
- let binary = "";
80
- for (const byte of bytes) binary += String.fromCharCode(byte);
81
- try {
82
- return decodeURIComponent(escape(binary));
83
- } catch {
84
- return binary;
85
- }
86
- }
87
- function decodeText(value) {
88
- if (typeof TextDecoder === "function") return new TextDecoder().decode(value);
89
- return decodeTextFallback(value);
90
- }
91
- function normalizeHeaderName(name) {
92
- return name.trim().toLowerCase();
93
- }
94
- //#endregion
1
+ import { a as decodeTextFallback, c as installRequestGlobalBinding, d as resolveRequestGlobalsHosts, i as decodeText, l as normalizeHeaderName, n as cloneArrayBuffer, o as encodeText, r as cloneArrayBufferView, s as encodeTextFallback, t as RequestGlobalsEventTarget, u as resolveRequestGlobalsHost } from "./shared-1FH7Skf_.mjs";
95
2
  export { RequestGlobalsEventTarget, cloneArrayBuffer, cloneArrayBufferView, decodeText, decodeTextFallback, encodeText, encodeTextFallback, installRequestGlobalBinding, normalizeHeaderName, resolveRequestGlobalsHost, resolveRequestGlobalsHosts };
package/dist/web.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { cloneArrayBuffer, cloneArrayBufferView, decodeText, encodeText } from "./shared.mjs";
1
+ import { i as decodeText, n as cloneArrayBuffer, o as encodeText, r as cloneArrayBufferView } from "./shared-1FH7Skf_.mjs";
2
2
  //#region src/web.ts
3
3
  function normalizeBlobPart(part) {
4
4
  if (typeof part === "string") return Promise.resolve(encodeText(part));
@@ -1,4 +1,4 @@
1
- import { RequestGlobalsEventTarget, cloneArrayBuffer, cloneArrayBufferView } from "./shared.mjs";
1
+ import { h as resolveUrlConstructor$1, m as resolveTextEncoderConstructor, n as cloneArrayBuffer, r as cloneArrayBufferView, t as RequestGlobalsEventTarget } from "./shared-1FH7Skf_.mjs";
2
2
  import { URLPolyfill } from "./url.mjs";
3
3
  import { BlobPolyfill } from "./web.mjs";
4
4
  import { wpi } from "@wevu/api";
@@ -17,7 +17,8 @@ function createDomLikeError(name, message) {
17
17
  return error;
18
18
  }
19
19
  function encodeReasonLength(reason) {
20
- if (typeof TextEncoder === "function") return new TextEncoder().encode(reason).byteLength;
20
+ const TextEncoderConstructor = resolveTextEncoderConstructor();
21
+ if (TextEncoderConstructor) return new TextEncoderConstructor().encode(reason).byteLength;
21
22
  return unescape(encodeURIComponent(reason)).length;
22
23
  }
23
24
  function normalizeCloseCode(code) {
@@ -32,7 +33,7 @@ function normalizeCloseReason(reason) {
32
33
  return normalized;
33
34
  }
34
35
  function resolveUrlConstructor() {
35
- return typeof URL === "function" ? URL : URLPolyfill;
36
+ return resolveUrlConstructor$1() ?? URLPolyfill;
36
37
  }
37
38
  function normalizeProtocols(protocols) {
38
39
  if (protocols == null) return;
package/dist/xhr.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { RequestGlobalsEventTarget, resolveRequestGlobalsHost } from "./shared.mjs";
1
+ import { t as RequestGlobalsEventTarget, u as resolveRequestGlobalsHost } from "./shared-1FH7Skf_.mjs";
2
2
  import { AbortControllerPolyfill } from "./abort.mjs";
3
3
  import { HeadersPolyfill, headersToObject } from "./http.mjs";
4
4
  import { fetch } from "./fetch.mjs";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wevu/web-apis",
3
3
  "type": "module",
4
- "version": "1.2.6",
4
+ "version": "1.2.8",
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",
@@ -71,7 +71,7 @@
71
71
  },
72
72
  "dependencies": {
73
73
  "@weapp-core/constants": "^0.1.1",
74
- "@wevu/api": "0.2.3"
74
+ "@wevu/api": "0.2.4"
75
75
  },
76
76
  "publishConfig": {
77
77
  "access": "public",