@weapp-core/shared 3.2.5 → 3.2.6
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/_virtual/_rolldown/runtime.js +24 -0
- package/dist/index.d.ts +10 -96
- package/dist/index.js +11 -390
- package/dist/layoutHostRegistry.d.ts +22 -0
- package/dist/layoutHostRegistry.js +79 -0
- package/dist/node_modules/.pnpm/defu@6.1.7/node_modules/defu/dist/defu.d.ts +19 -0
- package/dist/node_modules/.pnpm/defu@6.1.7/node_modules/defu/dist/defu.js +29 -0
- package/dist/node_modules/.pnpm/get-value@4.1.0/node_modules/get-value/dist/index.js +75 -0
- package/dist/node_modules/.pnpm/is-plain-object@2.0.4/node_modules/is-plain-object/index.js +28 -0
- package/dist/node_modules/.pnpm/is-primitive@3.0.1/node_modules/is-primitive/index.js +17 -0
- package/dist/node_modules/.pnpm/isobject@3.0.1/node_modules/isobject/index.js +16 -0
- package/dist/node_modules/.pnpm/set-value@4.1.0/node_modules/set-value/index.js +118 -0
- package/dist/platforms/descriptors.d.ts +7 -0
- package/dist/platforms/descriptors.js +204 -0
- package/dist/platforms/helpers.d.ts +26 -0
- package/dist/platforms/helpers.js +42 -0
- package/dist/platforms/index.d.ts +5 -1
- package/dist/platforms/index.js +4 -1
- package/dist/platforms/runtime/descriptors.d.ts +13 -0
- package/dist/platforms/runtime/descriptors.js +141 -0
- package/dist/platforms/runtime/helpers.d.ts +65 -0
- package/dist/platforms/runtime/helpers.js +169 -0
- package/dist/platforms/runtime/index.d.ts +5 -0
- package/dist/platforms/runtime/index.js +4 -0
- package/dist/platforms/runtime/template.d.ts +7 -0
- package/dist/platforms/runtime/template.js +22 -0
- package/dist/{index-BxC5D0Iz.d.ts → platforms/types.d.ts} +9 -103
- package/dist/runtimeProviders.d.ts +44 -0
- package/dist/wxml.d.ts +10 -0
- package/dist/wxml.js +26 -0
- package/package.json +16 -1
- package/dist/platforms-DeV7WlYI.js +0 -509
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
20
|
+
value: mod,
|
|
21
|
+
enumerable: true
|
|
22
|
+
}) : target, mod));
|
|
23
|
+
//#endregion
|
|
24
|
+
export { __commonJSMin, __toESM };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,100 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import defu, { DefuFn } from "./node_modules/.pnpm/defu@6.1.7/node_modules/defu/dist/defu.js";
|
|
2
|
+
import { MiniProgramLayoutHostResolver, MiniProgramLayoutHostWaitOptions, createMiniProgramLayoutHostRegistry, normalizeMiniProgramLayoutHostKeys } from "./layoutHostRegistry.js";
|
|
3
|
+
import { MiniProgramPageIdentityRule, MiniProgramPlatformDescriptor, MiniProgramPlatformFamily, MiniProgramRuntimeCapabilities, MiniProgramRuntimeCapabilityName, MiniProgramTemplatePreset, MpPlatform, OutputExtensions } from "./platforms/types.js";
|
|
4
|
+
import { MINI_PROGRAM_PLATFORM_DESCRIPTORS } from "./platforms/descriptors.js";
|
|
5
|
+
import { MINI_PROGRAM_PLATFORM_ALIASES, getDefaultMiniProgramPlatform, getDefaultMiniProgramRuntimeGlobalKey, getMiniProgramPlatformByRuntimeGlobalKey, getMiniProgramRouteRuntimeGlobalKeys, getMiniProgramRuntimeCapabilities, getMiniProgramRuntimeGlobalKey, getMiniProgramRuntimeGlobalKeys, getMiniProgramRuntimeGlobalKeysByResolvePriority, getMiniProgramRuntimeHostConfigKey, getSupportedMiniProgramPlatforms, normalizeMiniProgramPlatform, resolveMiniProgramPageKeys, resolveMiniProgramPlatform, supportsMiniProgramRuntimeCapability } from "./platforms/runtime/helpers.js";
|
|
6
|
+
import { getMiniProgramDirectivePrefix, getSupportedMiniProgramDirectivePrefixes } from "./platforms/runtime/template.js";
|
|
7
|
+
import { getMiniProgramAppTypesPackage, getMiniProgramDefaultBuildTarget, getMiniProgramPlatformDescriptor, getMiniProgramTemplatePreset, supportsMiniProgramAutoTouchAppStyle } from "./platforms/helpers.js";
|
|
8
|
+
import { RuntimeProviderBackend, RuntimeProviderCapabilities, RuntimeProviderCompilation, RuntimeProviderDescriptorContract, RuntimeProviderEntry, RuntimeProviderHmrDescriptor, RuntimeProviderHmrMode, RuntimeProviderInjectionMode, RuntimeProviderModuleKind, RuntimeProviderVariant } from "./runtimeProviders.js";
|
|
9
|
+
import { escapeWxmlAttribute, escapeWxmlText } from "./wxml.js";
|
|
2
10
|
import get from "get-value";
|
|
3
11
|
import set from "set-value";
|
|
4
|
-
//#region ../../node_modules/.pnpm/defu@6.1.7/node_modules/defu/dist/defu.d.mts
|
|
5
|
-
type Input = Record<string | number | symbol, any>;
|
|
6
|
-
type IgnoredInput = boolean | number | null | any[] | Record<never, any> | undefined;
|
|
7
|
-
type Merger = <T extends Input, K extends keyof T>(object: T, key: keyof T, value: T[K], namespace: string) => any;
|
|
8
|
-
type nullish = null | undefined | void;
|
|
9
|
-
type MergeObjects<Destination extends Input, Defaults extends Input> = Destination extends Defaults ? Destination : Omit<Destination, keyof Destination & keyof Defaults> & Omit<Defaults, keyof Destination & keyof Defaults> & { -readonly [Key in keyof Destination & keyof Defaults]: Destination[Key] extends nullish ? Defaults[Key] extends nullish ? nullish : Defaults[Key] : Defaults[Key] extends nullish ? Destination[Key] : Merge<Destination[Key], Defaults[Key]>; };
|
|
10
|
-
type Defu<S extends Input, D extends Array<Input | IgnoredInput>> = D extends [infer F, ...infer Rest] ? F extends Input ? Rest extends Array<Input | IgnoredInput> ? Defu<MergeObjects<S, F>, Rest> : MergeObjects<S, F> : F extends IgnoredInput ? Rest extends Array<Input | IgnoredInput> ? Defu<S, Rest> : S : S : S;
|
|
11
|
-
type DefuFn = <Source extends Input, Defaults extends Array<Input | IgnoredInput>>(source: Source, ...defaults: Defaults) => Defu<Source, Defaults>;
|
|
12
|
-
interface DefuInstance {
|
|
13
|
-
<Source extends Input, Defaults extends Array<Input | IgnoredInput>>(source: Source | IgnoredInput, ...defaults: Defaults): Defu<Source, Defaults>;
|
|
14
|
-
fn: DefuFn;
|
|
15
|
-
arrayFn: DefuFn;
|
|
16
|
-
extend(merger?: Merger): DefuFn;
|
|
17
|
-
}
|
|
18
|
-
type MergeArrays<Destination, Source> = Destination extends Array<infer DestinationType> ? Source extends Array<infer SourceType> ? Array<DestinationType | SourceType> : Source | Array<DestinationType> : Source | Destination;
|
|
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;
|
|
20
|
-
declare const defu: DefuInstance;
|
|
21
|
-
//#endregion
|
|
22
|
-
//#region src/layoutHostRegistry.d.ts
|
|
23
|
-
export interface MiniProgramLayoutHostWaitOptions {
|
|
24
|
-
interval?: number;
|
|
25
|
-
retries?: number;
|
|
26
|
-
}
|
|
27
|
-
export type MiniProgramLayoutHostResolver<TBridge, THost = unknown> = (bridge: TBridge, key: string) => THost | null | undefined;
|
|
28
|
-
/**
|
|
29
|
-
* @description 对 layout host key 去重并过滤空字符串。
|
|
30
|
-
*/
|
|
31
|
-
export declare function normalizeMiniProgramLayoutHostKeys(keys: string | string[]): string[];
|
|
32
|
-
/**
|
|
33
|
-
* @description 创建小程序 layout host 注册表。
|
|
34
|
-
*/
|
|
35
|
-
export 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
|
|
44
|
-
//#region src/runtimeProviders.d.ts
|
|
45
|
-
export type RuntimeProviderBackend = 'miniprogram' | 'web';
|
|
46
|
-
export type RuntimeProviderCompilation = 'native' | 'vue' | 'web';
|
|
47
|
-
export type RuntimeProviderModuleKind = 'runtime' | 'reactivity' | 'template';
|
|
48
|
-
export type RuntimeProviderVariant = 'development' | 'production';
|
|
49
|
-
export type RuntimeProviderInjectionMode = 'none' | 'virtual-module';
|
|
50
|
-
export type RuntimeProviderHmrMode = 'none' | 'host-reload' | 'module-accept';
|
|
51
|
-
/**
|
|
52
|
-
* 运行时 provider 的开发与生产入口。
|
|
53
|
-
*/
|
|
54
|
-
export interface RuntimeProviderEntry {
|
|
55
|
-
development: string;
|
|
56
|
-
production: string;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* 运行时 provider 的声明式能力。
|
|
60
|
-
*/
|
|
61
|
-
export interface RuntimeProviderCapabilities {
|
|
62
|
-
framework: boolean;
|
|
63
|
-
hmr: boolean;
|
|
64
|
-
nativeHost: boolean;
|
|
65
|
-
webHost: boolean;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* 运行时 provider 的 HMR 契约。
|
|
69
|
-
*/
|
|
70
|
-
export interface RuntimeProviderHmrDescriptor {
|
|
71
|
-
mode: RuntimeProviderHmrMode;
|
|
72
|
-
acceptCode?: string;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* 跨包共享的运行时 provider 描述契约。
|
|
76
|
-
*/
|
|
77
|
-
export interface RuntimeProviderDescriptorContract {
|
|
78
|
-
id: string;
|
|
79
|
-
backend: RuntimeProviderBackend;
|
|
80
|
-
compilation: RuntimeProviderCompilation;
|
|
81
|
-
injection: RuntimeProviderInjectionMode;
|
|
82
|
-
entries: Readonly<Partial<Record<RuntimeProviderModuleKind, RuntimeProviderEntry>>>;
|
|
83
|
-
capabilities: Readonly<RuntimeProviderCapabilities>;
|
|
84
|
-
hmr: Readonly<RuntimeProviderHmrDescriptor>;
|
|
85
|
-
contractVersion: number;
|
|
86
|
-
}
|
|
87
|
-
//#endregion
|
|
88
|
-
//#region src/wxml.d.ts
|
|
89
|
-
/**
|
|
90
|
-
* @description 按 exparser 与 glass-easel 的共同规则序列化 WXML 静态文本。
|
|
91
|
-
*/
|
|
92
|
-
export declare function escapeWxmlText(value: string): string;
|
|
93
|
-
/**
|
|
94
|
-
* @description 按 exparser 与 glass-easel 的共同规则序列化双引号 WXML 属性值。
|
|
95
|
-
*/
|
|
96
|
-
export declare function escapeWxmlAttribute(value: string): string;
|
|
97
|
-
//#endregion
|
|
98
12
|
//#region src/index.d.ts
|
|
99
13
|
/**
|
|
100
14
|
* @description 转义字符串中的正则特殊字符
|
|
@@ -129,4 +43,4 @@ export declare function isObject(x: unknown): x is Record<string | symbol | numb
|
|
|
129
43
|
*/
|
|
130
44
|
export declare function isEmptyObject(obj: unknown): boolean;
|
|
131
45
|
//#endregion
|
|
132
|
-
export { MINI_PROGRAM_PLATFORM_ALIASES, MINI_PROGRAM_PLATFORM_DESCRIPTORS, type MiniProgramPageIdentityRule, type MiniProgramPlatformDescriptor, type MiniProgramPlatformFamily, type MiniProgramRuntimeCapabilities, type MiniProgramRuntimeCapabilityName, type MiniProgramTemplatePreset, type MpPlatform, type OutputExtensions, defu, get, getDefaultMiniProgramPlatform, getDefaultMiniProgramRuntimeGlobalKey, getMiniProgramAppTypesPackage, getMiniProgramDefaultBuildTarget, getMiniProgramDirectivePrefix, getMiniProgramPlatformByRuntimeGlobalKey, getMiniProgramPlatformDescriptor, getMiniProgramRouteRuntimeGlobalKeys, getMiniProgramRuntimeCapabilities, getMiniProgramRuntimeGlobalKey, getMiniProgramRuntimeGlobalKeys, getMiniProgramRuntimeGlobalKeysByResolvePriority, getMiniProgramRuntimeHostConfigKey, getMiniProgramTemplatePreset, getSupportedMiniProgramDirectivePrefixes, getSupportedMiniProgramPlatforms, normalizeMiniProgramPlatform, resolveMiniProgramPageKeys, resolveMiniProgramPlatform, set, supportsMiniProgramAutoTouchAppStyle, supportsMiniProgramRuntimeCapability };
|
|
46
|
+
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, RuntimeProviderBackend, RuntimeProviderCapabilities, RuntimeProviderCompilation, RuntimeProviderDescriptorContract, RuntimeProviderEntry, RuntimeProviderHmrDescriptor, RuntimeProviderHmrMode, RuntimeProviderInjectionMode, RuntimeProviderModuleKind, RuntimeProviderVariant, createMiniProgramLayoutHostRegistry, defu, escapeWxmlAttribute, escapeWxmlText, get, getDefaultMiniProgramPlatform, getDefaultMiniProgramRuntimeGlobalKey, getMiniProgramAppTypesPackage, getMiniProgramDefaultBuildTarget, getMiniProgramDirectivePrefix, getMiniProgramPlatformByRuntimeGlobalKey, getMiniProgramPlatformDescriptor, getMiniProgramRouteRuntimeGlobalKeys, getMiniProgramRuntimeCapabilities, getMiniProgramRuntimeGlobalKey, getMiniProgramRuntimeGlobalKeys, getMiniProgramRuntimeGlobalKeysByResolvePriority, getMiniProgramRuntimeHostConfigKey, getMiniProgramTemplatePreset, getSupportedMiniProgramDirectivePrefixes, getSupportedMiniProgramPlatforms, normalizeMiniProgramLayoutHostKeys, normalizeMiniProgramPlatform, resolveMiniProgramPageKeys, resolveMiniProgramPlatform, set, supportsMiniProgramAutoTouchAppStyle, supportsMiniProgramRuntimeCapability };
|
package/dist/index.js
CHANGED
|
@@ -1,394 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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 || !__hasOwnProp.call(mod, "default") ? __defProp$1(target, "default", {
|
|
21
|
-
value: mod,
|
|
22
|
-
enumerable: true
|
|
23
|
-
}) : target, mod));
|
|
24
|
-
//#endregion
|
|
25
|
-
//#region ../../node_modules/.pnpm/defu@6.1.7/node_modules/defu/dist/defu.mjs
|
|
26
|
-
function isPlainObject(value) {
|
|
27
|
-
if (value === null || typeof value !== "object") return false;
|
|
28
|
-
const prototype = Object.getPrototypeOf(value);
|
|
29
|
-
if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) return false;
|
|
30
|
-
if (Symbol.iterator in value) return false;
|
|
31
|
-
if (Symbol.toStringTag in value) return Object.prototype.toString.call(value) === "[object Module]";
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
function _defu(baseObject, defaults, namespace = ".", merger) {
|
|
35
|
-
if (!isPlainObject(defaults)) return _defu(baseObject, {}, namespace, merger);
|
|
36
|
-
const object = { ...defaults };
|
|
37
|
-
for (const key of Object.keys(baseObject)) {
|
|
38
|
-
if (key === "__proto__" || key === "constructor") continue;
|
|
39
|
-
const value = baseObject[key];
|
|
40
|
-
if (value === null || value === void 0) continue;
|
|
41
|
-
if (merger && merger(object, key, value, namespace)) continue;
|
|
42
|
-
if (Array.isArray(value) && Array.isArray(object[key])) object[key] = [...value, ...object[key]];
|
|
43
|
-
else if (isPlainObject(value) && isPlainObject(object[key])) object[key] = _defu(value, object[key], (namespace ? `${namespace}.` : "") + key.toString(), merger);
|
|
44
|
-
else object[key] = value;
|
|
45
|
-
}
|
|
46
|
-
return object;
|
|
47
|
-
}
|
|
48
|
-
function createDefu(merger) {
|
|
49
|
-
return (...arguments_) => arguments_.reduce((p, c) => _defu(p, c, "", merger), {});
|
|
50
|
-
}
|
|
51
|
-
const defu = createDefu();
|
|
52
|
-
//#endregion
|
|
53
|
-
//#region src/layoutHostRegistry.ts
|
|
54
|
-
/**
|
|
55
|
-
* @description 对 layout host key 去重并过滤空字符串。
|
|
56
|
-
*/
|
|
57
|
-
function normalizeMiniProgramLayoutHostKeys(keys) {
|
|
58
|
-
return Array.from(new Set(Array.isArray(keys) ? keys : [keys])).filter((key) => typeof key === "string" && key.length > 0);
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* @description 创建小程序 layout host 注册表。
|
|
62
|
-
*/
|
|
63
|
-
function createMiniProgramLayoutHostRegistry() {
|
|
64
|
-
const registries = /* @__PURE__ */ new Map();
|
|
65
|
-
function register(keys, bridge, pageKeys) {
|
|
66
|
-
const normalizedKeys = normalizeMiniProgramLayoutHostKeys(keys);
|
|
67
|
-
if (normalizedKeys.length === 0 || pageKeys.length === 0) return null;
|
|
68
|
-
for (const pageKey of pageKeys) {
|
|
69
|
-
const registry = registries.get(pageKey) ?? /* @__PURE__ */ new Map();
|
|
70
|
-
for (const key of normalizedKeys) registry.set(key, bridge);
|
|
71
|
-
registries.set(pageKey, registry);
|
|
72
|
-
}
|
|
73
|
-
return normalizedKeys;
|
|
74
|
-
}
|
|
75
|
-
function unregister(keys, bridge, pageKeys) {
|
|
76
|
-
const normalizedKeys = normalizeMiniProgramLayoutHostKeys(keys);
|
|
77
|
-
if (normalizedKeys.length === 0 || pageKeys.length === 0) return false;
|
|
78
|
-
let removed = false;
|
|
79
|
-
for (const pageKey of pageKeys) {
|
|
80
|
-
const registry = registries.get(pageKey);
|
|
81
|
-
if (!registry) continue;
|
|
82
|
-
for (const key of normalizedKeys) if (registry.get(key) === bridge) {
|
|
83
|
-
registry.delete(key);
|
|
84
|
-
removed = true;
|
|
85
|
-
}
|
|
86
|
-
if (registry.size === 0) registries.delete(pageKey);
|
|
87
|
-
}
|
|
88
|
-
return removed;
|
|
89
|
-
}
|
|
90
|
-
function unregisterBridge(bridge) {
|
|
91
|
-
let removed = false;
|
|
92
|
-
for (const registry of registries.values()) for (const [key, currentBridge] of registry) if (currentBridge === bridge) {
|
|
93
|
-
registry.delete(key);
|
|
94
|
-
removed = true;
|
|
95
|
-
}
|
|
96
|
-
for (const [pageKey, registry] of registries) if (registry.size === 0) registries.delete(pageKey);
|
|
97
|
-
return removed;
|
|
98
|
-
}
|
|
99
|
-
function resolveBridge(key, pageKeys) {
|
|
100
|
-
return pageKeys.map((pageKey) => registries.get(pageKey)?.get(key)).find(Boolean);
|
|
101
|
-
}
|
|
102
|
-
function resolveHost(key, pageKeys, resolver) {
|
|
103
|
-
const bridge = resolveBridge(key, pageKeys);
|
|
104
|
-
if (!bridge) return null;
|
|
105
|
-
return resolver(bridge, key) ?? null;
|
|
106
|
-
}
|
|
107
|
-
function waitForHost(key, resolvePageKeys, resolver, options = {}) {
|
|
108
|
-
const retries = options.retries ?? 20;
|
|
109
|
-
const interval = options.interval ?? 16;
|
|
110
|
-
const host = resolveHost(key, resolvePageKeys(), resolver);
|
|
111
|
-
if (host || retries <= 0) return Promise.resolve(host);
|
|
112
|
-
return new Promise((resolve) => {
|
|
113
|
-
setTimeout(() => {
|
|
114
|
-
resolve(waitForHost(key, resolvePageKeys, resolver, {
|
|
115
|
-
...options,
|
|
116
|
-
retries: retries - 1
|
|
117
|
-
}));
|
|
118
|
-
}, interval);
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
return {
|
|
122
|
-
register,
|
|
123
|
-
resolveBridge,
|
|
124
|
-
resolveHost,
|
|
125
|
-
unregister,
|
|
126
|
-
unregisterBridge,
|
|
127
|
-
waitForHost
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
//#endregion
|
|
131
|
-
//#region src/wxml.ts
|
|
132
|
-
const WXML_TEXT_ESCAPE_RE = /[&<>]/g;
|
|
133
|
-
const WXML_ATTRIBUTE_ESCAPE_RE = /[&"<]/g;
|
|
134
|
-
const WXML_TEXT_ESCAPE_MAP = {
|
|
135
|
-
"&": "&",
|
|
136
|
-
"<": "<",
|
|
137
|
-
">": ">"
|
|
138
|
-
};
|
|
139
|
-
const WXML_ATTRIBUTE_ESCAPE_MAP = {
|
|
140
|
-
...WXML_TEXT_ESCAPE_MAP,
|
|
141
|
-
"\"": """
|
|
142
|
-
};
|
|
143
|
-
/**
|
|
144
|
-
* @description 按 exparser 与 glass-easel 的共同规则序列化 WXML 静态文本。
|
|
145
|
-
*/
|
|
146
|
-
function escapeWxmlText(value) {
|
|
147
|
-
return value.replace(WXML_TEXT_ESCAPE_RE, (char) => WXML_TEXT_ESCAPE_MAP[char] ?? char);
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* @description 按 exparser 与 glass-easel 的共同规则序列化双引号 WXML 属性值。
|
|
151
|
-
*/
|
|
152
|
-
function escapeWxmlAttribute(value) {
|
|
153
|
-
return value.replace(WXML_ATTRIBUTE_ESCAPE_RE, (char) => WXML_ATTRIBUTE_ESCAPE_MAP[char] ?? char);
|
|
154
|
-
}
|
|
155
|
-
//#endregion
|
|
156
|
-
//#region ../../node_modules/.pnpm/get-value@4.1.0/node_modules/get-value/dist/index.mjs
|
|
157
|
-
var __defProp = Object.defineProperty;
|
|
158
|
-
var __name = (target, value) => __defProp(target, "name", {
|
|
159
|
-
value,
|
|
160
|
-
configurable: true
|
|
161
|
-
});
|
|
162
|
-
var isObject$1 = /* @__PURE__ */ __name((v) => v !== null && typeof v === "object", "isObject");
|
|
163
|
-
var join = /* @__PURE__ */ __name((segs, joinChar, options) => {
|
|
164
|
-
if (typeof options.join === "function") return options.join(segs);
|
|
165
|
-
return segs[0] + joinChar + segs[1];
|
|
166
|
-
}, "join");
|
|
167
|
-
var split = /* @__PURE__ */ __name((path, splitChar, options) => {
|
|
168
|
-
if (typeof options.split === "function") return options.split(path);
|
|
169
|
-
return path.split(splitChar);
|
|
170
|
-
}, "split");
|
|
171
|
-
var isValid = /* @__PURE__ */ __name((key, target = {}, options) => {
|
|
172
|
-
if (typeof options?.isValid === "function") return options.isValid(key, target);
|
|
173
|
-
return true;
|
|
174
|
-
}, "isValid");
|
|
175
|
-
var isValidObject = /* @__PURE__ */ __name((v) => {
|
|
176
|
-
return isObject$1(v) || typeof v === "function";
|
|
177
|
-
}, "isValidObject");
|
|
178
|
-
var index_default = /* @__PURE__ */ __name((target, path, options = {}) => {
|
|
179
|
-
if (!isObject$1(options)) options = { default: options };
|
|
180
|
-
if (!isValidObject(target)) return typeof options.default !== "undefined" ? options.default : target;
|
|
181
|
-
if (typeof path === "number") path = String(path);
|
|
182
|
-
const pathIsArray = Array.isArray(path);
|
|
183
|
-
const pathIsString = typeof path === "string";
|
|
184
|
-
const splitChar = options.separator || ".";
|
|
185
|
-
const joinChar = options.joinChar || (typeof splitChar === "string" ? splitChar : ".");
|
|
186
|
-
if (!pathIsString && !pathIsArray) return target;
|
|
187
|
-
let value = target[path];
|
|
188
|
-
if (value === void 0 && typeof target.get === "function") value = target.get(path);
|
|
189
|
-
if (value !== void 0) return isValid(path, target, options) ? value : options.default;
|
|
190
|
-
const segs = pathIsArray ? path : split(path, splitChar, options);
|
|
191
|
-
const len = segs.length;
|
|
192
|
-
let idx = 0;
|
|
193
|
-
do {
|
|
194
|
-
let prop = segs[idx];
|
|
195
|
-
if (typeof prop !== "string") prop = String(prop);
|
|
196
|
-
while (prop && prop.slice(-1) === "\\") prop = join([prop.slice(0, -1), segs[++idx] || ""], joinChar, options);
|
|
197
|
-
value = target[prop];
|
|
198
|
-
if (value === void 0 && typeof target.get === "function") value = target.get(prop);
|
|
199
|
-
if (value !== void 0) {
|
|
200
|
-
if (!isValid(prop, target, options)) return options.default;
|
|
201
|
-
target = value;
|
|
202
|
-
} else {
|
|
203
|
-
let hasProp = false;
|
|
204
|
-
let n = idx + 1;
|
|
205
|
-
while (n < len) {
|
|
206
|
-
prop = join([prop, segs[n++]], joinChar, options);
|
|
207
|
-
value = target[prop];
|
|
208
|
-
if (value === void 0 && typeof target.get === "function") value = target.get(prop);
|
|
209
|
-
if (hasProp = value !== void 0) {
|
|
210
|
-
if (!isValid(prop, target, options)) return options.default;
|
|
211
|
-
target = value;
|
|
212
|
-
idx = n - 1;
|
|
213
|
-
break;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
if (!hasProp) return options.default;
|
|
217
|
-
}
|
|
218
|
-
} while (++idx < len && isValidObject(target));
|
|
219
|
-
if (idx === len) return target;
|
|
220
|
-
return options.default;
|
|
221
|
-
}, "getValue");
|
|
222
|
-
/*!
|
|
223
|
-
* get-value <https://github.com/jonschlinkert/get-value>
|
|
224
|
-
*
|
|
225
|
-
* Copyright (c) 2014-present, Jon Schlinkert.
|
|
226
|
-
* Released under the MIT License.
|
|
227
|
-
*/
|
|
228
|
-
//#endregion
|
|
229
|
-
//#region ../../node_modules/.pnpm/is-primitive@3.0.1/node_modules/is-primitive/index.js
|
|
230
|
-
/*!
|
|
231
|
-
* is-primitive <https://github.com/jonschlinkert/is-primitive>
|
|
232
|
-
*
|
|
233
|
-
* Copyright (c) 2014-present, Jon Schlinkert.
|
|
234
|
-
* Released under the MIT License.
|
|
235
|
-
*/
|
|
236
|
-
var require_is_primitive = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
237
|
-
module.exports = function isPrimitive(val) {
|
|
238
|
-
if (typeof val === "object") return val === null;
|
|
239
|
-
return typeof val !== "function";
|
|
240
|
-
};
|
|
241
|
-
}));
|
|
242
|
-
//#endregion
|
|
243
|
-
//#region ../../node_modules/.pnpm/isobject@3.0.1/node_modules/isobject/index.js
|
|
244
|
-
/*!
|
|
245
|
-
* isobject <https://github.com/jonschlinkert/isobject>
|
|
246
|
-
*
|
|
247
|
-
* Copyright (c) 2014-2017, Jon Schlinkert.
|
|
248
|
-
* Released under the MIT License.
|
|
249
|
-
*/
|
|
250
|
-
var require_isobject = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
251
|
-
module.exports = function isObject(val) {
|
|
252
|
-
return val != null && typeof val === "object" && Array.isArray(val) === false;
|
|
253
|
-
};
|
|
254
|
-
}));
|
|
255
|
-
//#endregion
|
|
256
|
-
//#region ../../node_modules/.pnpm/is-plain-object@2.0.4/node_modules/is-plain-object/index.js
|
|
257
|
-
/*!
|
|
258
|
-
* is-plain-object <https://github.com/jonschlinkert/is-plain-object>
|
|
259
|
-
*
|
|
260
|
-
* Copyright (c) 2014-2017, Jon Schlinkert.
|
|
261
|
-
* Released under the MIT License.
|
|
262
|
-
*/
|
|
263
|
-
var require_is_plain_object = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
264
|
-
var isObject = require_isobject();
|
|
265
|
-
function isObjectObject(o) {
|
|
266
|
-
return isObject(o) === true && Object.prototype.toString.call(o) === "[object Object]";
|
|
267
|
-
}
|
|
268
|
-
module.exports = function isPlainObject(o) {
|
|
269
|
-
var ctor, prot;
|
|
270
|
-
if (isObjectObject(o) === false) return false;
|
|
271
|
-
ctor = o.constructor;
|
|
272
|
-
if (typeof ctor !== "function") return false;
|
|
273
|
-
prot = ctor.prototype;
|
|
274
|
-
if (isObjectObject(prot) === false) return false;
|
|
275
|
-
if (prot.hasOwnProperty("isPrototypeOf") === false) return false;
|
|
276
|
-
return true;
|
|
277
|
-
};
|
|
278
|
-
}));
|
|
279
|
-
/*!
|
|
280
|
-
* set-value <https://github.com/jonschlinkert/set-value>
|
|
281
|
-
*
|
|
282
|
-
* Copyright (c) Jon Schlinkert (https://github.com/jonschlinkert).
|
|
283
|
-
* Released under the MIT License.
|
|
284
|
-
*/
|
|
285
|
-
//#endregion
|
|
1
|
+
import { __toESM } from "./_virtual/_rolldown/runtime.js";
|
|
2
|
+
import defu, { createDefu } from "./node_modules/.pnpm/defu@6.1.7/node_modules/defu/dist/defu.js";
|
|
3
|
+
import { createMiniProgramLayoutHostRegistry, normalizeMiniProgramLayoutHostKeys } from "./layoutHostRegistry.js";
|
|
4
|
+
import { getMiniProgramDirectivePrefix, getSupportedMiniProgramDirectivePrefixes } from "./platforms/runtime/template.js";
|
|
5
|
+
import { MINI_PROGRAM_PLATFORM_DESCRIPTORS } from "./platforms/descriptors.js";
|
|
6
|
+
import { MINI_PROGRAM_PLATFORM_ALIASES, getDefaultMiniProgramPlatform, getDefaultMiniProgramRuntimeGlobalKey, getMiniProgramPlatformByRuntimeGlobalKey, getMiniProgramRouteRuntimeGlobalKeys, getMiniProgramRuntimeCapabilities, getMiniProgramRuntimeGlobalKey, getMiniProgramRuntimeGlobalKeys, getMiniProgramRuntimeGlobalKeysByResolvePriority, getMiniProgramRuntimeHostConfigKey, getSupportedMiniProgramPlatforms, normalizeMiniProgramPlatform, resolveMiniProgramPageKeys, resolveMiniProgramPlatform, supportsMiniProgramRuntimeCapability } from "./platforms/runtime/helpers.js";
|
|
7
|
+
import { getMiniProgramAppTypesPackage, getMiniProgramDefaultBuildTarget, getMiniProgramPlatformDescriptor, getMiniProgramTemplatePreset, supportsMiniProgramAutoTouchAppStyle } from "./platforms/helpers.js";
|
|
8
|
+
import { escapeWxmlAttribute, escapeWxmlText } from "./wxml.js";
|
|
9
|
+
import index_default from "./node_modules/.pnpm/get-value@4.1.0/node_modules/get-value/dist/index.js";
|
|
10
|
+
import { require_set_value } from "./node_modules/.pnpm/set-value@4.1.0/node_modules/set-value/index.js";
|
|
286
11
|
//#region src/index.ts
|
|
287
|
-
var import_set_value = /* @__PURE__ */ __toESM((
|
|
288
|
-
const { deleteProperty } = Reflect;
|
|
289
|
-
const isPrimitive = require_is_primitive();
|
|
290
|
-
const isPlainObject = require_is_plain_object();
|
|
291
|
-
const isObject = (value) => {
|
|
292
|
-
return typeof value === "object" && value !== null || typeof value === "function";
|
|
293
|
-
};
|
|
294
|
-
const isUnsafeKey = (key) => {
|
|
295
|
-
return key === "__proto__" || key === "constructor" || key === "prototype";
|
|
296
|
-
};
|
|
297
|
-
const validateKey = (key) => {
|
|
298
|
-
if (!isPrimitive(key)) throw new TypeError("Object keys must be strings or symbols");
|
|
299
|
-
if (isUnsafeKey(key)) throw new Error(`Cannot set unsafe key: "${key}"`);
|
|
300
|
-
};
|
|
301
|
-
const toStringKey = (input) => {
|
|
302
|
-
return Array.isArray(input) ? input.flat().map(String).join(",") : input;
|
|
303
|
-
};
|
|
304
|
-
const createMemoKey = (input, options) => {
|
|
305
|
-
if (typeof input !== "string" || !options) return input;
|
|
306
|
-
let key = input + ";";
|
|
307
|
-
if (options.arrays !== void 0) key += `arrays=${options.arrays};`;
|
|
308
|
-
if (options.separator !== void 0) key += `separator=${options.separator};`;
|
|
309
|
-
if (options.split !== void 0) key += `split=${options.split};`;
|
|
310
|
-
if (options.merge !== void 0) key += `merge=${options.merge};`;
|
|
311
|
-
if (options.preservePaths !== void 0) key += `preservePaths=${options.preservePaths};`;
|
|
312
|
-
return key;
|
|
313
|
-
};
|
|
314
|
-
const memoize = (input, options, fn) => {
|
|
315
|
-
const key = toStringKey(options ? createMemoKey(input, options) : input);
|
|
316
|
-
validateKey(key);
|
|
317
|
-
const value = setValue.cache.get(key) || fn();
|
|
318
|
-
setValue.cache.set(key, value);
|
|
319
|
-
return value;
|
|
320
|
-
};
|
|
321
|
-
const splitString = (input, options = {}) => {
|
|
322
|
-
const sep = options.separator || ".";
|
|
323
|
-
const preserve = sep === "/" ? false : options.preservePaths;
|
|
324
|
-
if (typeof input === "string" && preserve !== false && /\//.test(input)) return [input];
|
|
325
|
-
const parts = [];
|
|
326
|
-
let part = "";
|
|
327
|
-
const push = (part) => {
|
|
328
|
-
let number;
|
|
329
|
-
if (part.trim() !== "" && Number.isInteger(number = Number(part))) parts.push(number);
|
|
330
|
-
else parts.push(part);
|
|
331
|
-
};
|
|
332
|
-
for (let i = 0; i < input.length; i++) {
|
|
333
|
-
const value = input[i];
|
|
334
|
-
if (value === "\\") {
|
|
335
|
-
part += input[++i];
|
|
336
|
-
continue;
|
|
337
|
-
}
|
|
338
|
-
if (value === sep) {
|
|
339
|
-
push(part);
|
|
340
|
-
part = "";
|
|
341
|
-
continue;
|
|
342
|
-
}
|
|
343
|
-
part += value;
|
|
344
|
-
}
|
|
345
|
-
if (part) push(part);
|
|
346
|
-
return parts;
|
|
347
|
-
};
|
|
348
|
-
const split = (input, options) => {
|
|
349
|
-
if (options && typeof options.split === "function") return options.split(input);
|
|
350
|
-
if (typeof input === "symbol") return [input];
|
|
351
|
-
if (Array.isArray(input)) return input;
|
|
352
|
-
return memoize(input, options, () => splitString(input, options));
|
|
353
|
-
};
|
|
354
|
-
const assignProp = (obj, prop, value, options) => {
|
|
355
|
-
validateKey(prop);
|
|
356
|
-
if (value === void 0) deleteProperty(obj, prop);
|
|
357
|
-
else if (options && options.merge) {
|
|
358
|
-
const merge = options.merge === "function" ? options.merge : Object.assign;
|
|
359
|
-
if (merge && isPlainObject(obj[prop]) && isPlainObject(value)) obj[prop] = merge(obj[prop], value);
|
|
360
|
-
else obj[prop] = value;
|
|
361
|
-
} else obj[prop] = value;
|
|
362
|
-
return obj;
|
|
363
|
-
};
|
|
364
|
-
const setValue = (target, path, value, options) => {
|
|
365
|
-
if (!path || !isObject(target)) return target;
|
|
366
|
-
const keys = split(path, options);
|
|
367
|
-
let obj = target;
|
|
368
|
-
for (let i = 0; i < keys.length; i++) {
|
|
369
|
-
const key = keys[i];
|
|
370
|
-
const next = keys[i + 1];
|
|
371
|
-
validateKey(key);
|
|
372
|
-
if (next === void 0) {
|
|
373
|
-
assignProp(obj, key, value, options);
|
|
374
|
-
break;
|
|
375
|
-
}
|
|
376
|
-
if (typeof next === "number" && !Array.isArray(obj[key])) {
|
|
377
|
-
obj = obj[key] = [];
|
|
378
|
-
continue;
|
|
379
|
-
}
|
|
380
|
-
if (!isObject(obj[key])) obj[key] = {};
|
|
381
|
-
obj = obj[key];
|
|
382
|
-
}
|
|
383
|
-
return target;
|
|
384
|
-
};
|
|
385
|
-
setValue.split = split;
|
|
386
|
-
setValue.cache = /* @__PURE__ */ new Map();
|
|
387
|
-
setValue.clear = () => {
|
|
388
|
-
setValue.cache = /* @__PURE__ */ new Map();
|
|
389
|
-
};
|
|
390
|
-
module.exports = setValue;
|
|
391
|
-
})))(), 1);
|
|
12
|
+
var import_set_value = /* @__PURE__ */ __toESM(require_set_value(), 1);
|
|
392
13
|
const SPECIAL_CHARS_RE = /[|\\{}()[\]^$+*?.]/g;
|
|
393
14
|
const HYPHEN_RE = /-/g;
|
|
394
15
|
const LAST_EXT_RE = /\.[^/.]+$/;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//#region src/layoutHostRegistry.d.ts
|
|
2
|
+
export interface MiniProgramLayoutHostWaitOptions {
|
|
3
|
+
interval?: number;
|
|
4
|
+
retries?: number;
|
|
5
|
+
}
|
|
6
|
+
export type MiniProgramLayoutHostResolver<TBridge, THost = unknown> = (bridge: TBridge, key: string) => THost | null | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* @description 对 layout host key 去重并过滤空字符串。
|
|
9
|
+
*/
|
|
10
|
+
export declare function normalizeMiniProgramLayoutHostKeys(keys: string | string[]): string[];
|
|
11
|
+
/**
|
|
12
|
+
* @description 创建小程序 layout host 注册表。
|
|
13
|
+
*/
|
|
14
|
+
export declare function createMiniProgramLayoutHostRegistry<TBridge>(): {
|
|
15
|
+
register: (keys: string | string[], bridge: TBridge, pageKeys: string[]) => string[] | null;
|
|
16
|
+
resolveBridge: (key: string, pageKeys: string[]) => TBridge | undefined;
|
|
17
|
+
resolveHost: <THost>(key: string, pageKeys: string[], resolver: MiniProgramLayoutHostResolver<TBridge, THost>) => NonNullable<THost> | null;
|
|
18
|
+
unregister: (keys: string | string[], bridge: TBridge, pageKeys: string[]) => boolean;
|
|
19
|
+
unregisterBridge: (bridge: TBridge) => boolean;
|
|
20
|
+
waitForHost: <THost>(key: string, resolvePageKeys: () => string[], resolver: MiniProgramLayoutHostResolver<TBridge, THost>, options?: MiniProgramLayoutHostWaitOptions) => Promise<THost | null>;
|
|
21
|
+
};
|
|
22
|
+
//#endregion
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
//#region src/layoutHostRegistry.ts
|
|
2
|
+
/**
|
|
3
|
+
* @description 对 layout host key 去重并过滤空字符串。
|
|
4
|
+
*/
|
|
5
|
+
function normalizeMiniProgramLayoutHostKeys(keys) {
|
|
6
|
+
return Array.from(new Set(Array.isArray(keys) ? keys : [keys])).filter((key) => typeof key === "string" && key.length > 0);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* @description 创建小程序 layout host 注册表。
|
|
10
|
+
*/
|
|
11
|
+
function createMiniProgramLayoutHostRegistry() {
|
|
12
|
+
const registries = /* @__PURE__ */ new Map();
|
|
13
|
+
function register(keys, bridge, pageKeys) {
|
|
14
|
+
const normalizedKeys = normalizeMiniProgramLayoutHostKeys(keys);
|
|
15
|
+
if (normalizedKeys.length === 0 || pageKeys.length === 0) return null;
|
|
16
|
+
for (const pageKey of pageKeys) {
|
|
17
|
+
const registry = registries.get(pageKey) ?? /* @__PURE__ */ new Map();
|
|
18
|
+
for (const key of normalizedKeys) registry.set(key, bridge);
|
|
19
|
+
registries.set(pageKey, registry);
|
|
20
|
+
}
|
|
21
|
+
return normalizedKeys;
|
|
22
|
+
}
|
|
23
|
+
function unregister(keys, bridge, pageKeys) {
|
|
24
|
+
const normalizedKeys = normalizeMiniProgramLayoutHostKeys(keys);
|
|
25
|
+
if (normalizedKeys.length === 0 || pageKeys.length === 0) return false;
|
|
26
|
+
let removed = false;
|
|
27
|
+
for (const pageKey of pageKeys) {
|
|
28
|
+
const registry = registries.get(pageKey);
|
|
29
|
+
if (!registry) continue;
|
|
30
|
+
for (const key of normalizedKeys) if (registry.get(key) === bridge) {
|
|
31
|
+
registry.delete(key);
|
|
32
|
+
removed = true;
|
|
33
|
+
}
|
|
34
|
+
if (registry.size === 0) registries.delete(pageKey);
|
|
35
|
+
}
|
|
36
|
+
return removed;
|
|
37
|
+
}
|
|
38
|
+
function unregisterBridge(bridge) {
|
|
39
|
+
let removed = false;
|
|
40
|
+
for (const registry of registries.values()) for (const [key, currentBridge] of registry) if (currentBridge === bridge) {
|
|
41
|
+
registry.delete(key);
|
|
42
|
+
removed = true;
|
|
43
|
+
}
|
|
44
|
+
for (const [pageKey, registry] of registries) if (registry.size === 0) registries.delete(pageKey);
|
|
45
|
+
return removed;
|
|
46
|
+
}
|
|
47
|
+
function resolveBridge(key, pageKeys) {
|
|
48
|
+
return pageKeys.map((pageKey) => registries.get(pageKey)?.get(key)).find(Boolean);
|
|
49
|
+
}
|
|
50
|
+
function resolveHost(key, pageKeys, resolver) {
|
|
51
|
+
const bridge = resolveBridge(key, pageKeys);
|
|
52
|
+
if (!bridge) return null;
|
|
53
|
+
return resolver(bridge, key) ?? null;
|
|
54
|
+
}
|
|
55
|
+
function waitForHost(key, resolvePageKeys, resolver, options = {}) {
|
|
56
|
+
const retries = options.retries ?? 20;
|
|
57
|
+
const interval = options.interval ?? 16;
|
|
58
|
+
const host = resolveHost(key, resolvePageKeys(), resolver);
|
|
59
|
+
if (host || retries <= 0) return Promise.resolve(host);
|
|
60
|
+
return new Promise((resolve) => {
|
|
61
|
+
setTimeout(() => {
|
|
62
|
+
resolve(waitForHost(key, resolvePageKeys, resolver, {
|
|
63
|
+
...options,
|
|
64
|
+
retries: retries - 1
|
|
65
|
+
}));
|
|
66
|
+
}, interval);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
register,
|
|
71
|
+
resolveBridge,
|
|
72
|
+
resolveHost,
|
|
73
|
+
unregister,
|
|
74
|
+
unregisterBridge,
|
|
75
|
+
waitForHost
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
79
|
+
export { createMiniProgramLayoutHostRegistry, normalizeMiniProgramLayoutHostKeys };
|