@wevu/web-apis 1.2.7 → 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/dist/abort.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as RequestGlobalsEventTarget } from "./shared-ChAdqo6n.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.mjs CHANGED
@@ -1,4 +1,4 @@
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-1FH7Skf_.mjs";
2
2
  import { HeadersPolyfill, ResponsePolyfill } from "./http.mjs";
3
3
  import { wpi } from "@wevu/api";
4
4
  //#region src/fetch.ts
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-1FH7Skf_.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.mjs CHANGED
@@ -1,5 +1,5 @@
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";
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
5
  import { fetch } from "./fetch.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 {
@@ -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,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-1FH7Skf_.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-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,5 +1,5 @@
1
+ import { h as resolveUrlConstructor$1, m as resolveTextEncoderConstructor, n as cloneArrayBuffer, r as cloneArrayBufferView, t as RequestGlobalsEventTarget } from "./shared-1FH7Skf_.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
3
  import { BlobPolyfill } from "./web.mjs";
4
4
  import { wpi } from "@wevu/api";
5
5
  //#region src/websocket.ts
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-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.7",
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",
@@ -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 };