@wevu/web-apis 1.2.7 → 1.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/abort.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as RequestGlobalsEventTarget } from "./shared-ChAdqo6n.mjs";
1
+ import { t as RequestGlobalsEventTarget } from "./shared-BB491DgN.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,4 @@
1
+ import { RequestGlobalsMiniProgramOptions } from "./networkDefaults.mjs";
1
2
  import { URLPolyfill } from "./url.mjs";
2
3
 
3
4
  //#region src/fetch.d.ts
@@ -17,12 +18,20 @@ interface RequestGlobalsFetchInit {
17
18
  headers?: unknown;
18
19
  body?: unknown;
19
20
  signal?: AbortSignal | null;
21
+ miniProgram?: RequestGlobalsMiniProgramOptions;
22
+ miniprogram?: RequestGlobalsMiniProgramOptions;
20
23
  [key: string]: unknown;
21
24
  }
25
+ declare global {
26
+ interface RequestInit {
27
+ miniProgram?: RequestGlobalsMiniProgramOptions;
28
+ miniprogram?: RequestGlobalsMiniProgramOptions;
29
+ }
30
+ }
22
31
  type RequestGlobalsFetchInput = string | URL | URLPolyfill | RequestLikeInput;
23
32
  /**
24
33
  * @description 使用 @wevu/api 的 request 能力实现 fetch 语义对齐。
25
34
  */
26
35
  declare function fetch(input: RequestGlobalsFetchInput, init?: RequestGlobalsFetchInit): Promise<Response>;
27
36
  //#endregion
28
- export { RequestGlobalsFetchInit, fetch };
37
+ export { RequestGlobalsFetchInit, type RequestGlobalsMiniProgramOptions, fetch };
package/dist/fetch.mjs CHANGED
@@ -1,5 +1,6 @@
1
- import { f as isUrlInstance, l as normalizeHeaderName, n as cloneArrayBuffer, p as isUrlSearchParamsInstance, r as cloneArrayBufferView } from "./shared-ChAdqo6n.mjs";
1
+ import { f as isUrlInstance, l as normalizeHeaderName, n as cloneArrayBuffer, p as isUrlSearchParamsInstance, r as cloneArrayBufferView } from "./shared-BB491DgN.mjs";
2
2
  import { HeadersPolyfill, ResponsePolyfill } from "./http.mjs";
3
+ import { resolveRequestMiniProgramOptions } from "./networkDefaults.mjs";
3
4
  import { wpi } from "@wevu/api";
4
5
  //#region src/fetch.ts
5
6
  const REQUEST_METHODS = [
@@ -108,6 +109,7 @@ async function resolveRequestMeta(input, init = {}) {
108
109
  if (!hasBodyInInit && requestInput && (method === "GET" || method === "HEAD")) rawBody = void 0;
109
110
  if ((method === "GET" || method === "HEAD") && rawBody != null) throw new TypeError("Failed to execute fetch: GET/HEAD request cannot have body");
110
111
  return {
112
+ miniProgram: resolveRequestMiniProgramOptions(init.miniProgram, init.miniprogram),
111
113
  url,
112
114
  method,
113
115
  headers,
@@ -148,6 +150,7 @@ function fetch(input, init) {
148
150
  }
149
151
  if (meta.signal) meta.signal.addEventListener("abort", onAbort, { once: true });
150
152
  const requestResult = wpi.request({
153
+ ...meta.miniProgram,
151
154
  url: meta.url,
152
155
  method: meta.method,
153
156
  header: meta.headers,
package/dist/http.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { f as isUrlInstance, i as decodeText, l as normalizeHeaderName, n as cloneArrayBuffer, o as encodeText, r as cloneArrayBufferView } from "./shared-ChAdqo6n.mjs";
1
+ import { f as isUrlInstance, i as decodeText, l as normalizeHeaderName, n as cloneArrayBuffer, o as encodeText, r as cloneArrayBufferView } from "./shared-BB491DgN.mjs";
2
2
  //#region src/http.ts
3
3
  function isIterableHeaders(input) {
4
4
  return Boolean(input) && typeof input[Symbol.iterator] === "function";
package/dist/index.d.mts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { RequestGlobalsEventTarget } from "./shared.mjs";
2
2
  import { AbortControllerPolyfill, AbortSignalPolyfill } from "./abort.mjs";
3
+ import { MiniProgramNetworkDefaults, RequestGlobalsMiniProgramOptions, WebSocketMiniProgramOptions, getMiniProgramNetworkDefaults, resetMiniProgramNetworkDefaults, setMiniProgramNetworkDefaults } from "./networkDefaults.mjs";
3
4
  import { URLPolyfill, URLSearchParamsPolyfill } from "./url.mjs";
4
5
  import { fetch } from "./fetch.mjs";
5
6
  import { HeadersPolyfill, RequestPolyfill, ResponsePolyfill } from "./http.mjs";
@@ -77,6 +78,7 @@ type WeappInjectWebRuntimeGlobalsTarget = 'fetch' | 'Headers' | 'Request' | 'Res
77
78
  type WeappInjectRequestGlobalsTarget = WeappInjectWebRuntimeGlobalsTarget;
78
79
  interface InstallWebRuntimeGlobalsOptions {
79
80
  targets?: WeappInjectWebRuntimeGlobalsTarget[];
81
+ networkDefaults?: MiniProgramNetworkDefaults;
80
82
  }
81
83
  interface InstallRequestGlobalsOptions extends InstallWebRuntimeGlobalsOptions {}
82
84
  /**
@@ -92,4 +94,4 @@ declare function installRequestGlobals(options?: InstallRequestGlobalsOptions):
92
94
  */
93
95
  declare function installAbortGlobals(): Record<string, any>;
94
96
  //#endregion
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 };
97
+ export { AbortControllerPolyfill, AbortSignalPolyfill, BlobPolyfill, CustomEventPolyfill, EventPolyfill, FormDataPolyfill, HeadersPolyfill, InstallRequestGlobalsOptions, InstallWebRuntimeGlobalsOptions, type MiniProgramNetworkDefaults, RequestGlobalsEventTarget, type RequestGlobalsMiniProgramOptions, RequestPolyfill, ResponsePolyfill, TextDecoderPolyfill, TextEncoderPolyfill, URLPolyfill, URLSearchParamsPolyfill, WeappInjectRequestGlobalsTarget, WeappInjectWebRuntimeGlobalsTarget, type WebSocketMiniProgramOptions, WebSocketPolyfill, XMLHttpRequestPolyfill, atobPolyfill, btoaPolyfill, cryptoPolyfill, fetch, getMiniProgramNetworkDefaults, installAbortGlobals, installRequestGlobals, installWebRuntimeGlobals, performancePolyfill, queueMicrotaskPolyfill, resetMiniProgramNetworkDefaults, setMiniProgramNetworkDefaults };
package/dist/index.mjs CHANGED
@@ -1,7 +1,8 @@
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-BB491DgN.mjs";
1
2
  import { URLPolyfill, URLSearchParamsPolyfill } from "./url.mjs";
2
- import { a as decodeTextFallback, c as installRequestGlobalBinding, d as resolveRequestGlobalsHosts, s as encodeTextFallback, t as RequestGlobalsEventTarget, u as resolveRequestGlobalsHost } from "./shared-ChAdqo6n.mjs";
3
3
  import { AbortControllerPolyfill, AbortSignalPolyfill } from "./abort.mjs";
4
4
  import { HeadersPolyfill, RequestPolyfill, ResponsePolyfill } from "./http.mjs";
5
+ import { getMiniProgramNetworkDefaults, resetMiniProgramNetworkDefaults, setMiniProgramNetworkDefaults } from "./networkDefaults.mjs";
5
6
  import { fetch } from "./fetch.mjs";
6
7
  import { BlobPolyfill, FormDataPolyfill } from "./web.mjs";
7
8
  import { WebSocketPolyfill } from "./websocket.mjs";
@@ -69,11 +70,7 @@ function fillArrayWithMathRandom(target) {
69
70
  for (let index = 0; index < bytes.length; index++) bytes[index] = Math.floor(Math.random() * 256);
70
71
  }
71
72
  function fillArrayWithHostRandomValues(target) {
72
- for (const hostKey of [
73
- "wx",
74
- "my",
75
- "tt"
76
- ]) {
73
+ for (const hostKey of getMiniProgramRuntimeGlobalKeys()) {
77
74
  const host = globalThis[hostKey];
78
75
  if (!host || typeof host.getRandomValues !== "function") continue;
79
76
  try {
@@ -138,11 +135,7 @@ const PERFORMANCE_POLYFILL_MARKER = "__weappVitePerformancePolyfill";
138
135
  function resolveNativePerformance() {
139
136
  const candidate = globalThis.performance;
140
137
  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
- ]) {
138
+ for (const hostKey of getMiniProgramRuntimeGlobalKeys()) {
146
139
  const host = globalThis[hostKey];
147
140
  if (!host || typeof host.getPerformance !== "function") continue;
148
141
  try {
@@ -348,6 +341,7 @@ function syncWeappViteRequestGlobalsActuals(host, targets) {
348
341
  * @description 按需向小程序全局环境注入缺失的 Web Runtime 对象。
349
342
  */
350
343
  function installWebRuntimeGlobals(options = {}) {
344
+ if (options.networkDefaults !== void 0) setMiniProgramNetworkDefaults(options.networkDefaults);
351
345
  const targets = resolveInstallTargets(options.targets ?? [
352
346
  "fetch",
353
347
  "Headers",
@@ -398,4 +392,4 @@ function installAbortGlobals() {
398
392
  return installWebRuntimeGlobals({ targets: ["AbortController", "AbortSignal"] });
399
393
  }
400
394
  //#endregion
401
- 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 };
395
+ export { AbortControllerPolyfill, AbortSignalPolyfill, BlobPolyfill, CustomEventPolyfill, EventPolyfill, FormDataPolyfill, HeadersPolyfill, RequestGlobalsEventTarget, RequestPolyfill, ResponsePolyfill, TextDecoderPolyfill, TextEncoderPolyfill, URLPolyfill, URLSearchParamsPolyfill, WebSocketPolyfill, XMLHttpRequestPolyfill, atobPolyfill, btoaPolyfill, cryptoPolyfill, fetch, getMiniProgramNetworkDefaults, installAbortGlobals, installRequestGlobals, installWebRuntimeGlobals, performancePolyfill, queueMicrotaskPolyfill, resetMiniProgramNetworkDefaults, setMiniProgramNetworkDefaults };
@@ -0,0 +1,22 @@
1
+ import { WeapiMiniProgramConnectSocketOption, WeapiMiniProgramRequestOption } from "@wevu/api";
2
+
3
+ //#region src/networkDefaults.d.ts
4
+ declare const MINI_PROGRAM_REQUEST_OPTION_KEYS: readonly ["enableCache", "enableChunked", "enableHttp2", "enableHttpDNS", "enableProfile", "enableQuic", "forceCellularNetwork", "httpDNSServiceId", "httpDNSTimeout", "redirect", "timeout", "useHighPerformanceMode"];
5
+ declare const MINI_PROGRAM_SOCKET_OPTION_KEYS: readonly ["forceCellularNetwork", "header", "perMessageDeflate", "timeout"];
6
+ type RequestGlobalsMiniProgramOptionKey = typeof MINI_PROGRAM_REQUEST_OPTION_KEYS[number];
7
+ type WebSocketMiniProgramOptionKey = typeof MINI_PROGRAM_SOCKET_OPTION_KEYS[number];
8
+ type RequestGlobalsMiniProgramOptions = Pick<Partial<WeapiMiniProgramRequestOption>, RequestGlobalsMiniProgramOptionKey>;
9
+ type WebSocketMiniProgramOptions = Pick<Partial<WeapiMiniProgramConnectSocketOption>, WebSocketMiniProgramOptionKey>;
10
+ interface MiniProgramNetworkDefaults {
11
+ request?: RequestGlobalsMiniProgramOptions;
12
+ socket?: WebSocketMiniProgramOptions;
13
+ }
14
+ declare function normalizeRequestMiniProgramOptions(...sources: unknown[]): RequestGlobalsMiniProgramOptions;
15
+ declare function normalizeWebSocketMiniProgramOptions(...sources: unknown[]): WebSocketMiniProgramOptions;
16
+ declare function getMiniProgramNetworkDefaults(): MiniProgramNetworkDefaults;
17
+ declare function setMiniProgramNetworkDefaults(defaults?: MiniProgramNetworkDefaults): MiniProgramNetworkDefaults;
18
+ declare function resetMiniProgramNetworkDefaults(): MiniProgramNetworkDefaults;
19
+ declare function resolveRequestMiniProgramOptions(...sources: unknown[]): RequestGlobalsMiniProgramOptions;
20
+ declare function resolveWebSocketMiniProgramOptions(...sources: unknown[]): WebSocketMiniProgramOptions;
21
+ //#endregion
22
+ export { MiniProgramNetworkDefaults, RequestGlobalsMiniProgramOptions, WebSocketMiniProgramOptions, getMiniProgramNetworkDefaults, normalizeRequestMiniProgramOptions, normalizeWebSocketMiniProgramOptions, resetMiniProgramNetworkDefaults, resolveRequestMiniProgramOptions, resolveWebSocketMiniProgramOptions, setMiniProgramNetworkDefaults };
@@ -0,0 +1,72 @@
1
+ //#region src/networkDefaults.ts
2
+ const MINI_PROGRAM_REQUEST_OPTION_KEYS = [
3
+ "enableCache",
4
+ "enableChunked",
5
+ "enableHttp2",
6
+ "enableHttpDNS",
7
+ "enableProfile",
8
+ "enableQuic",
9
+ "forceCellularNetwork",
10
+ "httpDNSServiceId",
11
+ "httpDNSTimeout",
12
+ "redirect",
13
+ "timeout",
14
+ "useHighPerformanceMode"
15
+ ];
16
+ const MINI_PROGRAM_SOCKET_OPTION_KEYS = [
17
+ "forceCellularNetwork",
18
+ "header",
19
+ "perMessageDeflate",
20
+ "timeout"
21
+ ];
22
+ let miniProgramNetworkDefaults = {};
23
+ function hasOwnProperty(source, key) {
24
+ return Object.hasOwn(source, key);
25
+ }
26
+ function isObject(value) {
27
+ return typeof value === "object" && value !== null;
28
+ }
29
+ function normalizeOptions(keys, sources) {
30
+ const options = {};
31
+ for (const source of sources) {
32
+ if (!isObject(source)) continue;
33
+ const candidate = source;
34
+ for (const key of keys) {
35
+ if (!hasOwnProperty(candidate, key)) continue;
36
+ const value = candidate[key];
37
+ if (value !== void 0) options[key] = value;
38
+ }
39
+ }
40
+ return options;
41
+ }
42
+ function normalizeRequestMiniProgramOptions(...sources) {
43
+ return normalizeOptions(MINI_PROGRAM_REQUEST_OPTION_KEYS, sources);
44
+ }
45
+ function normalizeWebSocketMiniProgramOptions(...sources) {
46
+ return normalizeOptions(MINI_PROGRAM_SOCKET_OPTION_KEYS, sources);
47
+ }
48
+ function getMiniProgramNetworkDefaults() {
49
+ return {
50
+ request: normalizeRequestMiniProgramOptions(miniProgramNetworkDefaults.request),
51
+ socket: normalizeWebSocketMiniProgramOptions(miniProgramNetworkDefaults.socket)
52
+ };
53
+ }
54
+ function setMiniProgramNetworkDefaults(defaults = {}) {
55
+ miniProgramNetworkDefaults = {
56
+ request: normalizeRequestMiniProgramOptions(defaults.request),
57
+ socket: normalizeWebSocketMiniProgramOptions(defaults.socket)
58
+ };
59
+ return getMiniProgramNetworkDefaults();
60
+ }
61
+ function resetMiniProgramNetworkDefaults() {
62
+ miniProgramNetworkDefaults = {};
63
+ return getMiniProgramNetworkDefaults();
64
+ }
65
+ function resolveRequestMiniProgramOptions(...sources) {
66
+ return normalizeRequestMiniProgramOptions(getMiniProgramNetworkDefaults().request, ...sources);
67
+ }
68
+ function resolveWebSocketMiniProgramOptions(...sources) {
69
+ return normalizeWebSocketMiniProgramOptions(getMiniProgramNetworkDefaults().socket, ...sources);
70
+ }
71
+ //#endregion
72
+ export { getMiniProgramNetworkDefaults, normalizeRequestMiniProgramOptions, normalizeWebSocketMiniProgramOptions, resetMiniProgramNetworkDefaults, resolveRequestMiniProgramOptions, resolveWebSocketMiniProgramOptions, setMiniProgramNetworkDefaults };
@@ -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), cb = null), 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,2 +1,2 @@
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-ChAdqo6n.mjs";
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-BB491DgN.mjs";
2
2
  export { RequestGlobalsEventTarget, cloneArrayBuffer, cloneArrayBufferView, decodeText, decodeTextFallback, encodeText, encodeTextFallback, installRequestGlobalBinding, normalizeHeaderName, resolveRequestGlobalsHost, resolveRequestGlobalsHosts };
package/dist/web.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { i as decodeText, n as cloneArrayBuffer, o as encodeText, r as cloneArrayBufferView } from "./shared-ChAdqo6n.mjs";
1
+ import { i as decodeText, n as cloneArrayBuffer, o as encodeText, r as cloneArrayBufferView } from "./shared-BB491DgN.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,5 @@
1
1
  import { RequestGlobalsEventTarget } from "./shared.mjs";
2
+ import { WebSocketMiniProgramOptions } from "./networkDefaults.mjs";
2
3
  import { BlobPolyfill } from "./web.mjs";
3
4
 
4
5
  //#region src/websocket.d.ts
@@ -21,6 +22,11 @@ interface WebSocketMessageEventLike {
21
22
  origin: string;
22
23
  type: 'message';
23
24
  }
25
+ interface WebSocketPolyfillInit {
26
+ protocols?: string | string[];
27
+ miniProgram?: WebSocketMiniProgramOptions;
28
+ miniprogram?: WebSocketMiniProgramOptions;
29
+ }
24
30
  declare class WebSocketPolyfill extends RequestGlobalsEventTarget {
25
31
  static readonly CONNECTING = 0;
26
32
  static readonly OPEN = 1;
@@ -43,11 +49,11 @@ declare class WebSocketPolyfill extends RequestGlobalsEventTarget {
43
49
  type: 'open';
44
50
  }) => void) | null;
45
51
  private socketTask?;
46
- constructor(url: string, protocols?: string | string[]);
52
+ constructor(url: string, protocols?: string | string[] | WebSocketPolyfillInit);
47
53
  close(code?: number, reason?: string): void;
48
54
  send(data: WebSocketSendData): void;
49
55
  private closeFromRuntime;
50
56
  private emitError;
51
57
  }
52
58
  //#endregion
53
- export { WebSocketPolyfill };
59
+ export { WebSocketPolyfill, WebSocketPolyfillInit };
@@ -1,5 +1,6 @@
1
+ import { h as resolveUrlConstructor$1, m as resolveTextEncoderConstructor, n as cloneArrayBuffer, r as cloneArrayBufferView, t as RequestGlobalsEventTarget } from "./shared-BB491DgN.mjs";
1
2
  import { URLPolyfill } from "./url.mjs";
2
- import { h as resolveUrlConstructor$1, m as resolveTextEncoderConstructor, n as cloneArrayBuffer, r as cloneArrayBufferView, t as RequestGlobalsEventTarget } from "./shared-ChAdqo6n.mjs";
3
+ import { resolveWebSocketMiniProgramOptions } from "./networkDefaults.mjs";
3
4
  import { BlobPolyfill } from "./web.mjs";
4
5
  import { wpi } from "@wevu/api";
5
6
  //#region src/websocket.ts
@@ -46,6 +47,17 @@ function normalizeProtocols(protocols) {
46
47
  }
47
48
  return normalized;
48
49
  }
50
+ function isWebSocketPolyfillInit(value) {
51
+ return typeof value === "object" && value !== null && !Array.isArray(value);
52
+ }
53
+ function resolveWebSocketProtocols(protocols) {
54
+ if (isWebSocketPolyfillInit(protocols)) return normalizeProtocols(protocols.protocols);
55
+ return normalizeProtocols(protocols);
56
+ }
57
+ function resolveWebSocketMiniProgramConfig(protocols) {
58
+ if (!isWebSocketPolyfillInit(protocols)) return resolveWebSocketMiniProgramOptions();
59
+ return resolveWebSocketMiniProgramOptions(protocols.miniProgram, protocols.miniprogram);
60
+ }
49
61
  function normalizeUrl(url) {
50
62
  const parsed = new (resolveUrlConstructor())(String(url));
51
63
  if (parsed.protocol !== "ws:" && parsed.protocol !== "wss:") throw new SyntaxError(`Failed to construct 'WebSocket': invalid URL "${url}"`);
@@ -116,8 +128,9 @@ var WebSocketPolyfill = class WebSocketPolyfill extends RequestGlobalsEventTarge
116
128
  this.url = normalizeUrl(url);
117
129
  const connectSocket = getRawConnectSocket();
118
130
  if (!connectSocket) throw createDomLikeError("NotSupportedError", "WebSocket is not supported in the current mini-program runtime");
119
- const normalizedProtocols = normalizeProtocols(protocols);
131
+ const normalizedProtocols = resolveWebSocketProtocols(protocols);
120
132
  const task = connectSocket({
133
+ ...resolveWebSocketMiniProgramConfig(protocols),
121
134
  url: this.url,
122
135
  protocols: normalizedProtocols,
123
136
  fail: (error) => {
package/dist/xhr.d.mts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { RequestGlobalsEventTarget } from "./shared.mjs";
2
+ import { RequestGlobalsMiniProgramOptions } from "./networkDefaults.mjs";
2
3
 
3
4
  //#region src/xhr.d.ts
4
5
  type XhrBody = Document | XMLHttpRequestBodyInit | null | undefined;
@@ -24,6 +25,7 @@ declare class XMLHttpRequestPolyfill extends RequestGlobalsEventTarget {
24
25
  statusText: string;
25
26
  timeout: number;
26
27
  withCredentials: boolean;
28
+ miniProgram: RequestGlobalsMiniProgramOptions | null;
27
29
  onreadystatechange: ((event: {
28
30
  type: string;
29
31
  }) => void) | null;
package/dist/xhr.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as RequestGlobalsEventTarget, u as resolveRequestGlobalsHost } from "./shared-ChAdqo6n.mjs";
1
+ import { t as RequestGlobalsEventTarget, u as resolveRequestGlobalsHost } from "./shared-BB491DgN.mjs";
2
2
  import { AbortControllerPolyfill } from "./abort.mjs";
3
3
  import { HeadersPolyfill, headersToObject } from "./http.mjs";
4
4
  import { fetch } from "./fetch.mjs";
@@ -42,6 +42,7 @@ var XMLHttpRequestPolyfill = class XMLHttpRequestPolyfill extends RequestGlobals
42
42
  statusText = "";
43
43
  timeout = 0;
44
44
  withCredentials = false;
45
+ miniProgram = null;
45
46
  onreadystatechange = null;
46
47
  onabort = null;
47
48
  onerror = null;
@@ -104,6 +105,7 @@ var XMLHttpRequestPolyfill = class XMLHttpRequestPolyfill extends RequestGlobals
104
105
  method: this.method,
105
106
  headers: headersToObject(this.requestHeaders),
106
107
  body,
108
+ miniProgram: this.miniProgram ?? void 0,
107
109
  signal: controller.signal
108
110
  });
109
111
  this.responseHeaders = typeof Headers === "function" && response.headers instanceof Headers ? response.headers : new HeadersPolyfill(response.headers);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wevu/web-apis",
3
3
  "type": "module",
4
- "version": "1.2.7",
4
+ "version": "1.2.9",
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",
@@ -39,6 +39,10 @@
39
39
  "types": "./dist/http.d.mts",
40
40
  "import": "./dist/http.mjs"
41
41
  },
42
+ "./network-defaults": {
43
+ "types": "./dist/networkDefaults.d.mts",
44
+ "import": "./dist/networkDefaults.mjs"
45
+ },
42
46
  "./shared": {
43
47
  "types": "./dist/shared.d.mts",
44
48
  "import": "./dist/shared.mjs"
@@ -71,7 +75,7 @@
71
75
  },
72
76
  "dependencies": {
73
77
  "@weapp-core/constants": "^0.1.1",
74
- "@wevu/api": "0.2.3"
78
+ "@wevu/api": "0.2.5"
75
79
  },
76
80
  "publishConfig": {
77
81
  "access": "public",
@@ -1,120 +0,0 @@
1
- import { URLPolyfill, URLSearchParamsPolyfill } from "./url.mjs";
2
- //#region src/constructors.ts
3
- function resolveUrlConstructor() {
4
- return typeof globalThis.URL === "function" ? globalThis.URL : void 0;
5
- }
6
- function isUrlInstance(value) {
7
- const HostUrl = resolveUrlConstructor();
8
- return Boolean(HostUrl && value instanceof HostUrl || value instanceof URLPolyfill);
9
- }
10
- function resolveUrlSearchParamsConstructor() {
11
- return typeof globalThis.URLSearchParams === "function" ? globalThis.URLSearchParams : void 0;
12
- }
13
- function isUrlSearchParamsInstance(value) {
14
- const HostUrlSearchParams = resolveUrlSearchParamsConstructor();
15
- return Boolean(HostUrlSearchParams && value instanceof HostUrlSearchParams || value instanceof URLSearchParamsPolyfill);
16
- }
17
- function resolveTextEncoderConstructor() {
18
- return typeof globalThis.TextEncoder === "function" ? globalThis.TextEncoder : void 0;
19
- }
20
- function resolveTextDecoderConstructor() {
21
- return typeof globalThis.TextDecoder === "function" ? globalThis.TextDecoder : void 0;
22
- }
23
- //#endregion
24
- //#region src/shared.ts
25
- var RequestGlobalsEventTarget = class {
26
- listeners = /* @__PURE__ */ new Map();
27
- addEventListener(type, listener) {
28
- const set = this.listeners.get(type) ?? /* @__PURE__ */ new Set();
29
- set.add(listener);
30
- this.listeners.set(type, set);
31
- }
32
- removeEventListener(type, listener) {
33
- this.listeners.get(type)?.delete(listener);
34
- }
35
- dispatchEvent(event) {
36
- const payload = {
37
- ...event,
38
- target: event.target ?? this,
39
- currentTarget: event.currentTarget ?? this
40
- };
41
- for (const listener of this.listeners.get(event.type) ?? []) listener(payload);
42
- const handlerKey = `on${event.type}`;
43
- const handler = this[handlerKey];
44
- if (typeof handler === "function") handler(payload);
45
- return true;
46
- }
47
- };
48
- function resolveRequestGlobalsHost() {
49
- if (typeof globalThis !== "undefined") return globalThis;
50
- return {};
51
- }
52
- function isRequestGlobalsHostCandidate(value) {
53
- return value != null && (typeof value === "object" || typeof value === "function");
54
- }
55
- function pushRequestGlobalsHost(hosts, candidate) {
56
- if (!isRequestGlobalsHostCandidate(candidate)) return;
57
- if (!hosts.includes(candidate)) hosts.push(candidate);
58
- }
59
- function resolveRequestGlobalsHosts() {
60
- const hosts = [];
61
- const primaryHost = resolveRequestGlobalsHost();
62
- pushRequestGlobalsHost(hosts, primaryHost);
63
- for (const name of [
64
- "global",
65
- "self",
66
- "window"
67
- ]) pushRequestGlobalsHost(hosts, primaryHost[name]);
68
- for (const key of [
69
- "wx",
70
- "my",
71
- "tt"
72
- ]) pushRequestGlobalsHost(hosts, primaryHost[key]);
73
- return hosts;
74
- }
75
- function installRequestGlobalBinding(name, value) {
76
- if (!name) return;
77
- try {
78
- const host = resolveRequestGlobalsHost();
79
- host[name] = value;
80
- } catch {}
81
- }
82
- function cloneArrayBuffer(buffer) {
83
- return buffer.slice(0);
84
- }
85
- function cloneArrayBufferView(view) {
86
- const copied = new Uint8Array(view.byteLength);
87
- copied.set(new Uint8Array(view.buffer, view.byteOffset, view.byteLength));
88
- return copied.buffer;
89
- }
90
- function encodeTextFallback(value) {
91
- const binary = unescape(encodeURIComponent(String(value)));
92
- const bytes = new Uint8Array(binary.length);
93
- for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
94
- return bytes.buffer;
95
- }
96
- function encodeText(value) {
97
- const TextEncoderConstructor = resolveTextEncoderConstructor();
98
- if (TextEncoderConstructor) return new TextEncoderConstructor().encode(value).buffer;
99
- return encodeTextFallback(value);
100
- }
101
- function decodeTextFallback(value) {
102
- const bytes = new Uint8Array(value);
103
- let binary = "";
104
- for (const byte of bytes) binary += String.fromCharCode(byte);
105
- try {
106
- return decodeURIComponent(escape(binary));
107
- } catch {
108
- return binary;
109
- }
110
- }
111
- function decodeText(value) {
112
- const TextDecoderConstructor = resolveTextDecoderConstructor();
113
- if (TextDecoderConstructor) return new TextDecoderConstructor().decode(value);
114
- return decodeTextFallback(value);
115
- }
116
- function normalizeHeaderName(name) {
117
- return name.trim().toLowerCase();
118
- }
119
- //#endregion
120
- export { decodeTextFallback as a, installRequestGlobalBinding as c, resolveRequestGlobalsHosts as d, isUrlInstance as f, 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 };