@weapp-core/shared 3.0.4 → 3.0.5
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/index.d.ts +24 -47
- package/dist/index.js +96 -18
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import get from "get-value";
|
|
1
2
|
import set from "set-value";
|
|
2
3
|
|
|
3
4
|
//#region ../../node_modules/.pnpm/defu@6.1.7/node_modules/defu/dist/defu.d.mts
|
|
@@ -18,6 +19,28 @@ type MergeArrays<Destination, Source> = Destination extends Array<infer Destinat
|
|
|
18
19
|
type Merge<Destination extends Input, Defaults extends Input> = Destination extends nullish ? Defaults extends nullish ? nullish : Defaults : Defaults extends nullish ? Destination : Destination extends Array<any> ? Defaults extends Array<any> ? MergeArrays<Destination, Defaults> : Destination | Defaults : Destination extends Function ? Destination | Defaults : Destination extends RegExp ? Destination | Defaults : Destination extends Promise<any> ? Destination | Defaults : Defaults extends Function ? Destination | Defaults : Defaults extends RegExp ? Destination | Defaults : Defaults extends Promise<any> ? Destination | Defaults : Destination extends Input ? Defaults extends Input ? MergeObjects<Destination, Defaults> : Destination | Defaults : Destination | Defaults;
|
|
19
20
|
declare const defu: DefuInstance;
|
|
20
21
|
//#endregion
|
|
22
|
+
//#region src/layoutHostRegistry.d.ts
|
|
23
|
+
interface MiniProgramLayoutHostWaitOptions {
|
|
24
|
+
interval?: number;
|
|
25
|
+
retries?: number;
|
|
26
|
+
}
|
|
27
|
+
type MiniProgramLayoutHostResolver<TBridge, THost = unknown> = (bridge: TBridge, key: string) => THost | null | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* @description 对 layout host key 去重并过滤空字符串。
|
|
30
|
+
*/
|
|
31
|
+
declare function normalizeMiniProgramLayoutHostKeys(keys: string | string[]): string[];
|
|
32
|
+
/**
|
|
33
|
+
* @description 创建小程序 layout host 注册表。
|
|
34
|
+
*/
|
|
35
|
+
declare function createMiniProgramLayoutHostRegistry<TBridge>(): {
|
|
36
|
+
register: (keys: string | string[], bridge: TBridge, pageKeys: string[]) => string[] | null;
|
|
37
|
+
resolveBridge: (key: string, pageKeys: string[]) => TBridge | undefined;
|
|
38
|
+
resolveHost: <THost>(key: string, pageKeys: string[], resolver: MiniProgramLayoutHostResolver<TBridge, THost>) => NonNullable<THost> | null;
|
|
39
|
+
unregister: (keys: string | string[], bridge: TBridge, pageKeys: string[]) => boolean;
|
|
40
|
+
unregisterBridge: (bridge: TBridge) => boolean;
|
|
41
|
+
waitForHost: <THost>(key: string, resolvePageKeys: () => string[], resolver: MiniProgramLayoutHostResolver<TBridge, THost>, options?: MiniProgramLayoutHostWaitOptions) => Promise<THost | null>;
|
|
42
|
+
};
|
|
43
|
+
//#endregion
|
|
21
44
|
//#region src/platforms/types.d.ts
|
|
22
45
|
type MpPlatform = 'weapp' | 'alipay' | 'tt' | 'swan' | 'jd' | 'xhs';
|
|
23
46
|
type MiniProgramTemplatePreset = 'wechat' | 'alipay' | 'tt' | 'swan';
|
|
@@ -327,52 +350,6 @@ declare function supportsMiniProgramRuntimeCapability(platform: MpPlatform | und
|
|
|
327
350
|
*/
|
|
328
351
|
declare function resolveMiniProgramPageKeys(page?: Record<string, any>, platform?: MpPlatform): string[];
|
|
329
352
|
//#endregion
|
|
330
|
-
//#region ../../node_modules/.pnpm/get-value@4.0.1/node_modules/get-value/index.d.ts
|
|
331
|
-
declare function get<T>(obj: T): T;
|
|
332
|
-
declare function get(obj: object, key: string | string[], options?: get.Options): any;
|
|
333
|
-
declare namespace get {
|
|
334
|
-
interface Options {
|
|
335
|
-
/**
|
|
336
|
-
* The default value to return when get-value cannot result a value from the given object.
|
|
337
|
-
*
|
|
338
|
-
* default: `undefined`
|
|
339
|
-
*/
|
|
340
|
-
default?: any;
|
|
341
|
-
/**
|
|
342
|
-
* If defined, this function is called on each resolved value.
|
|
343
|
-
* Useful if you want to do `.hasOwnProperty` or `Object.prototype.propertyIsEnumerable`.
|
|
344
|
-
*/
|
|
345
|
-
isValid?: (<K extends string>(key: K, object: Record<K, any>) => boolean) | undefined;
|
|
346
|
-
/**
|
|
347
|
-
* Custom function to use for splitting the string into object path segments.
|
|
348
|
-
*
|
|
349
|
-
* default: `String.split`
|
|
350
|
-
*/
|
|
351
|
-
split?: ((s: string) => string[]) | undefined;
|
|
352
|
-
/**
|
|
353
|
-
* The separator to use for spliting the string.
|
|
354
|
-
* (this is probably not needed when `options.split` is used).
|
|
355
|
-
*
|
|
356
|
-
* default: `"."`
|
|
357
|
-
*/
|
|
358
|
-
separator?: string | RegExp | undefined;
|
|
359
|
-
/**
|
|
360
|
-
* Customize how the object path is created when iterating over path segments.
|
|
361
|
-
*
|
|
362
|
-
* default: `Array.join`
|
|
363
|
-
*/
|
|
364
|
-
join?: ((segs: string[]) => string) | undefined;
|
|
365
|
-
/**
|
|
366
|
-
* The character to use when re-joining the string to check for keys
|
|
367
|
-
* with dots in them (this is probably not needed when `options.join` is used).
|
|
368
|
-
* This can be a different value than the separator, since the separator can be a string or regex.
|
|
369
|
-
*
|
|
370
|
-
* default: `"."`
|
|
371
|
-
*/
|
|
372
|
-
joinChar?: string | undefined;
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
//#endregion
|
|
376
353
|
//#region src/index.d.ts
|
|
377
354
|
/**
|
|
378
355
|
* @description 转义字符串中的正则特殊字符
|
|
@@ -407,4 +384,4 @@ declare function isObject(x: unknown): x is Record<string | symbol | number, unk
|
|
|
407
384
|
*/
|
|
408
385
|
declare function isEmptyObject(obj: unknown): boolean;
|
|
409
386
|
//#endregion
|
|
410
|
-
export { MINI_PROGRAM_PLATFORM_ALIASES, MINI_PROGRAM_PLATFORM_DESCRIPTORS, MiniProgramPageIdentityRule, MiniProgramPlatformDescriptor, MiniProgramPlatformFamily, MiniProgramRuntimeCapabilities, MiniProgramRuntimeCapabilityName, MiniProgramTemplatePreset, MpPlatform, OutputExtensions, addExtension, arrify, defu, defuOverrideArray, escapeStringRegexp, get, getDefaultMiniProgramPlatform, getDefaultMiniProgramRuntimeGlobalKey, getMiniProgramAppTypesPackage, getMiniProgramDefaultBuildTarget, getMiniProgramDirectivePrefix, getMiniProgramPlatformByRuntimeGlobalKey, getMiniProgramPlatformDescriptor, getMiniProgramRouteRuntimeGlobalKeys, getMiniProgramRuntimeCapabilities, getMiniProgramRuntimeGlobalKey, getMiniProgramRuntimeGlobalKeys, getMiniProgramRuntimeGlobalKeysByResolvePriority, getMiniProgramRuntimeHostConfigKey, getMiniProgramTemplatePreset, getSupportedMiniProgramDirectivePrefixes, getSupportedMiniProgramPlatforms, isEmptyObject, isObject, normalizeMiniProgramPlatform, removeExtension, removeExtensionDeep, resolveMiniProgramPageKeys, resolveMiniProgramPlatform, set, supportsMiniProgramAutoTouchAppStyle, supportsMiniProgramRuntimeCapability };
|
|
387
|
+
export { MINI_PROGRAM_PLATFORM_ALIASES, MINI_PROGRAM_PLATFORM_DESCRIPTORS, MiniProgramLayoutHostResolver, MiniProgramLayoutHostWaitOptions, type MiniProgramPageIdentityRule, type MiniProgramPlatformDescriptor, type MiniProgramPlatformFamily, type MiniProgramRuntimeCapabilities, type MiniProgramRuntimeCapabilityName, type MiniProgramTemplatePreset, type MpPlatform, type OutputExtensions, addExtension, arrify, createMiniProgramLayoutHostRegistry, defu, defuOverrideArray, escapeStringRegexp, get, getDefaultMiniProgramPlatform, getDefaultMiniProgramRuntimeGlobalKey, getMiniProgramAppTypesPackage, getMiniProgramDefaultBuildTarget, getMiniProgramDirectivePrefix, getMiniProgramPlatformByRuntimeGlobalKey, getMiniProgramPlatformDescriptor, getMiniProgramRouteRuntimeGlobalKeys, getMiniProgramRuntimeCapabilities, getMiniProgramRuntimeGlobalKey, getMiniProgramRuntimeGlobalKeys, getMiniProgramRuntimeGlobalKeysByResolvePriority, getMiniProgramRuntimeHostConfigKey, getMiniProgramTemplatePreset, getSupportedMiniProgramDirectivePrefixes, getSupportedMiniProgramPlatforms, isEmptyObject, isObject, normalizeMiniProgramLayoutHostKeys, normalizeMiniProgramPlatform, removeExtension, removeExtensionDeep, resolveMiniProgramPageKeys, resolveMiniProgramPlatform, set, supportsMiniProgramAutoTouchAppStyle, supportsMiniProgramRuntimeCapability };
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
8
|
+
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
9
9
|
var __copyProps = (to, from, except, desc) => {
|
|
10
10
|
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
11
|
key = keys[i];
|
|
@@ -48,18 +48,84 @@ function createDefu(merger) {
|
|
|
48
48
|
return (...arguments_) => arguments_.reduce((p, c) => _defu(p, c, "", merger), {});
|
|
49
49
|
}
|
|
50
50
|
const defu = createDefu();
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/layoutHostRegistry.ts
|
|
53
|
+
/**
|
|
54
|
+
* @description 对 layout host key 去重并过滤空字符串。
|
|
55
|
+
*/
|
|
56
|
+
function normalizeMiniProgramLayoutHostKeys(keys) {
|
|
57
|
+
return Array.from(new Set(Array.isArray(keys) ? keys : [keys])).filter((key) => typeof key === "string" && key.length > 0);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* @description 创建小程序 layout host 注册表。
|
|
61
|
+
*/
|
|
62
|
+
function createMiniProgramLayoutHostRegistry() {
|
|
63
|
+
const registries = /* @__PURE__ */ new Map();
|
|
64
|
+
function register(keys, bridge, pageKeys) {
|
|
65
|
+
const normalizedKeys = normalizeMiniProgramLayoutHostKeys(keys);
|
|
66
|
+
if (normalizedKeys.length === 0 || pageKeys.length === 0) return null;
|
|
67
|
+
for (const pageKey of pageKeys) {
|
|
68
|
+
const registry = registries.get(pageKey) ?? /* @__PURE__ */ new Map();
|
|
69
|
+
for (const key of normalizedKeys) registry.set(key, bridge);
|
|
70
|
+
registries.set(pageKey, registry);
|
|
71
|
+
}
|
|
72
|
+
return normalizedKeys;
|
|
55
73
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
74
|
+
function unregister(keys, bridge, pageKeys) {
|
|
75
|
+
const normalizedKeys = normalizeMiniProgramLayoutHostKeys(keys);
|
|
76
|
+
if (normalizedKeys.length === 0 || pageKeys.length === 0) return false;
|
|
77
|
+
let removed = false;
|
|
78
|
+
for (const pageKey of pageKeys) {
|
|
79
|
+
const registry = registries.get(pageKey);
|
|
80
|
+
if (!registry) continue;
|
|
81
|
+
for (const key of normalizedKeys) if (registry.get(key) === bridge) {
|
|
82
|
+
registry.delete(key);
|
|
83
|
+
removed = true;
|
|
84
|
+
}
|
|
85
|
+
if (registry.size === 0) registries.delete(pageKey);
|
|
86
|
+
}
|
|
87
|
+
return removed;
|
|
61
88
|
}
|
|
62
|
-
|
|
89
|
+
function unregisterBridge(bridge) {
|
|
90
|
+
let removed = false;
|
|
91
|
+
for (const registry of registries.values()) for (const [key, currentBridge] of registry) if (currentBridge === bridge) {
|
|
92
|
+
registry.delete(key);
|
|
93
|
+
removed = true;
|
|
94
|
+
}
|
|
95
|
+
for (const [pageKey, registry] of registries) if (registry.size === 0) registries.delete(pageKey);
|
|
96
|
+
return removed;
|
|
97
|
+
}
|
|
98
|
+
function resolveBridge(key, pageKeys) {
|
|
99
|
+
return pageKeys.map((pageKey) => registries.get(pageKey)?.get(key)).find(Boolean);
|
|
100
|
+
}
|
|
101
|
+
function resolveHost(key, pageKeys, resolver) {
|
|
102
|
+
const bridge = resolveBridge(key, pageKeys);
|
|
103
|
+
if (!bridge) return null;
|
|
104
|
+
return resolver(bridge, key) ?? null;
|
|
105
|
+
}
|
|
106
|
+
function waitForHost(key, resolvePageKeys, resolver, options = {}) {
|
|
107
|
+
const retries = options.retries ?? 20;
|
|
108
|
+
const interval = options.interval ?? 16;
|
|
109
|
+
const host = resolveHost(key, resolvePageKeys(), resolver);
|
|
110
|
+
if (host || retries <= 0) return Promise.resolve(host);
|
|
111
|
+
return new Promise((resolve) => {
|
|
112
|
+
setTimeout(() => {
|
|
113
|
+
resolve(waitForHost(key, resolvePageKeys, resolver, {
|
|
114
|
+
...options,
|
|
115
|
+
retries: retries - 1
|
|
116
|
+
}));
|
|
117
|
+
}, interval);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
register,
|
|
122
|
+
resolveBridge,
|
|
123
|
+
resolveHost,
|
|
124
|
+
unregister,
|
|
125
|
+
unregisterBridge,
|
|
126
|
+
waitForHost
|
|
127
|
+
};
|
|
128
|
+
}
|
|
63
129
|
//#endregion
|
|
64
130
|
//#region src/platforms/descriptors.ts
|
|
65
131
|
const DEFAULT_PROJECT_CONFIG_ROOT_KEYS = ["miniprogramRoot", "srcMiniprogramRoot"];
|
|
@@ -560,7 +626,7 @@ function resolveMiniProgramPageKeys(page, platform) {
|
|
|
560
626
|
return Array.from(new Set(keys));
|
|
561
627
|
}
|
|
562
628
|
//#endregion
|
|
563
|
-
//#region ../../node_modules/.pnpm/get-value@4.0
|
|
629
|
+
//#region ../../node_modules/.pnpm/get-value@4.1.0/node_modules/get-value/dist/index.mjs
|
|
564
630
|
var __defProp = Object.defineProperty;
|
|
565
631
|
var __name = (target, value) => __defProp(target, "name", {
|
|
566
632
|
value,
|
|
@@ -591,7 +657,9 @@ var index_default = /* @__PURE__ */ __name((target, path, options = {}) => {
|
|
|
591
657
|
const splitChar = options.separator || ".";
|
|
592
658
|
const joinChar = options.joinChar || (typeof splitChar === "string" ? splitChar : ".");
|
|
593
659
|
if (!pathIsString && !pathIsArray) return target;
|
|
594
|
-
|
|
660
|
+
let value = target[path];
|
|
661
|
+
if (value === void 0 && typeof target.get === "function") value = target.get(path);
|
|
662
|
+
if (value !== void 0) return isValid(path, target, options) ? value : options.default;
|
|
595
663
|
const segs = pathIsArray ? path : split(path, splitChar, options);
|
|
596
664
|
const len = segs.length;
|
|
597
665
|
let idx = 0;
|
|
@@ -599,17 +667,21 @@ var index_default = /* @__PURE__ */ __name((target, path, options = {}) => {
|
|
|
599
667
|
let prop = segs[idx];
|
|
600
668
|
if (typeof prop !== "string") prop = String(prop);
|
|
601
669
|
while (prop && prop.slice(-1) === "\\") prop = join([prop.slice(0, -1), segs[++idx] || ""], joinChar, options);
|
|
602
|
-
|
|
670
|
+
value = target[prop];
|
|
671
|
+
if (value === void 0 && typeof target.get === "function") value = target.get(prop);
|
|
672
|
+
if (value !== void 0) {
|
|
603
673
|
if (!isValid(prop, target, options)) return options.default;
|
|
604
|
-
target =
|
|
674
|
+
target = value;
|
|
605
675
|
} else {
|
|
606
676
|
let hasProp = false;
|
|
607
677
|
let n = idx + 1;
|
|
608
678
|
while (n < len) {
|
|
609
679
|
prop = join([prop, segs[n++]], joinChar, options);
|
|
610
|
-
|
|
680
|
+
value = target[prop];
|
|
681
|
+
if (value === void 0 && typeof target.get === "function") value = target.get(prop);
|
|
682
|
+
if (hasProp = value !== void 0) {
|
|
611
683
|
if (!isValid(prop, target, options)) return options.default;
|
|
612
|
-
target =
|
|
684
|
+
target = value;
|
|
613
685
|
idx = n - 1;
|
|
614
686
|
break;
|
|
615
687
|
}
|
|
@@ -677,6 +749,12 @@ var require_is_plain_object = /* @__PURE__ */ __commonJSMin(((exports, module) =
|
|
|
677
749
|
return true;
|
|
678
750
|
};
|
|
679
751
|
}));
|
|
752
|
+
/*!
|
|
753
|
+
* set-value <https://github.com/jonschlinkert/set-value>
|
|
754
|
+
*
|
|
755
|
+
* Copyright (c) Jon Schlinkert (https://github.com/jonschlinkert).
|
|
756
|
+
* Released under the MIT License.
|
|
757
|
+
*/
|
|
680
758
|
//#endregion
|
|
681
759
|
//#region src/index.ts
|
|
682
760
|
var import_set_value = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
@@ -853,4 +931,4 @@ function isEmptyObject(obj) {
|
|
|
853
931
|
}
|
|
854
932
|
//#endregion
|
|
855
933
|
var set = import_set_value.default;
|
|
856
|
-
export { MINI_PROGRAM_PLATFORM_ALIASES, MINI_PROGRAM_PLATFORM_DESCRIPTORS, addExtension, arrify, defu, defuOverrideArray, escapeStringRegexp, index_default as get, getDefaultMiniProgramPlatform, getDefaultMiniProgramRuntimeGlobalKey, getMiniProgramAppTypesPackage, getMiniProgramDefaultBuildTarget, getMiniProgramDirectivePrefix, getMiniProgramPlatformByRuntimeGlobalKey, getMiniProgramPlatformDescriptor, getMiniProgramRouteRuntimeGlobalKeys, getMiniProgramRuntimeCapabilities, getMiniProgramRuntimeGlobalKey, getMiniProgramRuntimeGlobalKeys, getMiniProgramRuntimeGlobalKeysByResolvePriority, getMiniProgramRuntimeHostConfigKey, getMiniProgramTemplatePreset, getSupportedMiniProgramDirectivePrefixes, getSupportedMiniProgramPlatforms, isEmptyObject, isObject, normalizeMiniProgramPlatform, removeExtension, removeExtensionDeep, resolveMiniProgramPageKeys, resolveMiniProgramPlatform, set, supportsMiniProgramAutoTouchAppStyle, supportsMiniProgramRuntimeCapability };
|
|
934
|
+
export { MINI_PROGRAM_PLATFORM_ALIASES, MINI_PROGRAM_PLATFORM_DESCRIPTORS, addExtension, arrify, createMiniProgramLayoutHostRegistry, defu, defuOverrideArray, escapeStringRegexp, index_default as get, getDefaultMiniProgramPlatform, getDefaultMiniProgramRuntimeGlobalKey, getMiniProgramAppTypesPackage, getMiniProgramDefaultBuildTarget, getMiniProgramDirectivePrefix, getMiniProgramPlatformByRuntimeGlobalKey, getMiniProgramPlatformDescriptor, getMiniProgramRouteRuntimeGlobalKeys, getMiniProgramRuntimeCapabilities, getMiniProgramRuntimeGlobalKey, getMiniProgramRuntimeGlobalKeys, getMiniProgramRuntimeGlobalKeysByResolvePriority, getMiniProgramRuntimeHostConfigKey, getMiniProgramTemplatePreset, getSupportedMiniProgramDirectivePrefixes, getSupportedMiniProgramPlatforms, isEmptyObject, isObject, normalizeMiniProgramLayoutHostKeys, normalizeMiniProgramPlatform, removeExtension, removeExtensionDeep, resolveMiniProgramPageKeys, resolveMiniProgramPlatform, set, supportsMiniProgramAutoTouchAppStyle, supportsMiniProgramRuntimeCapability };
|