@weapp-core/shared 3.2.5 → 3.2.7

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.
Files changed (32) hide show
  1. package/dist/_virtual/_rolldown/runtime.js +24 -0
  2. package/dist/index.d.ts +10 -96
  3. package/dist/index.js +11 -390
  4. package/dist/layoutHostRegistry.d.ts +22 -0
  5. package/dist/layoutHostRegistry.js +79 -0
  6. package/dist/node_modules/.pnpm/defu@6.1.7/node_modules/defu/dist/defu.d.ts +19 -0
  7. package/dist/node_modules/.pnpm/defu@6.1.7/node_modules/defu/dist/defu.js +29 -0
  8. package/dist/node_modules/.pnpm/get-value@4.1.0/node_modules/get-value/dist/index.js +75 -0
  9. package/dist/node_modules/.pnpm/is-plain-object@2.0.4/node_modules/is-plain-object/index.js +28 -0
  10. package/dist/node_modules/.pnpm/is-primitive@3.0.1/node_modules/is-primitive/index.js +17 -0
  11. package/dist/node_modules/.pnpm/isobject@3.0.1/node_modules/isobject/index.js +16 -0
  12. package/dist/node_modules/.pnpm/set-value@4.1.0/node_modules/set-value/index.js +118 -0
  13. package/dist/platforms/descriptors.d.ts +7 -0
  14. package/dist/platforms/descriptors.js +204 -0
  15. package/dist/platforms/helpers.d.ts +26 -0
  16. package/dist/platforms/helpers.js +42 -0
  17. package/dist/platforms/index.d.ts +5 -1
  18. package/dist/platforms/index.js +4 -1
  19. package/dist/platforms/runtime/descriptors.d.ts +13 -0
  20. package/dist/platforms/runtime/descriptors.js +141 -0
  21. package/dist/platforms/runtime/helpers.d.ts +65 -0
  22. package/dist/platforms/runtime/helpers.js +169 -0
  23. package/dist/platforms/runtime/index.d.ts +5 -0
  24. package/dist/platforms/runtime/index.js +4 -0
  25. package/dist/platforms/runtime/template.d.ts +7 -0
  26. package/dist/platforms/runtime/template.js +22 -0
  27. package/dist/{index-BxC5D0Iz.d.ts → platforms/types.d.ts} +9 -103
  28. package/dist/runtimeProviders.d.ts +44 -0
  29. package/dist/wxml.d.ts +10 -0
  30. package/dist/wxml.js +26 -0
  31. package/package.json +16 -1
  32. package/dist/platforms-DeV7WlYI.js +0 -509
@@ -0,0 +1,141 @@
1
+ //#region src/platforms/runtime/descriptors.ts
2
+ const DEFAULT_RUNTIME_HOST_CONFIG_KEY = "__wxConfig";
3
+ const DEFAULT_RUNTIME_CAPABILITIES = Object.freeze({
4
+ globalPageStack: true,
5
+ globalCreateSelectorQuery: true,
6
+ selectorQueryScopeByIn: true,
7
+ globalCreateIntersectionObserver: true,
8
+ intersectionObserverScopeByParameter: true,
9
+ pageShareMenu: true,
10
+ shareTimelineRequiresShareAppMessage: true,
11
+ pageScrollApi: true,
12
+ pullDownRefreshApi: true,
13
+ globalRouterApi: true,
14
+ appErrorListener: true,
15
+ appPageNotFoundListener: true,
16
+ appUnhandledRejectionListener: true,
17
+ appThemeChangeListener: true,
18
+ appMemoryWarningListener: true
19
+ });
20
+ const DEFAULT_PAGE_IDENTITY_RULES = [{
21
+ prefix: "route",
22
+ source: "route"
23
+ }];
24
+ const WEAPP_RUNTIME_DESCRIPTOR = {
25
+ id: "weapp",
26
+ aliases: [
27
+ "weapp",
28
+ "wechat",
29
+ "weixin",
30
+ "wx"
31
+ ],
32
+ runtime: {
33
+ globalObjectKey: "wx",
34
+ hostConfigKey: DEFAULT_RUNTIME_HOST_CONFIG_KEY,
35
+ globalResolvePriority: 1,
36
+ routeGlobalResolvePriority: 0,
37
+ capabilities: DEFAULT_RUNTIME_CAPABILITIES,
38
+ pageIdentityRules: [
39
+ {
40
+ prefix: "webview",
41
+ source: "field",
42
+ field: "__wxWebviewId__"
43
+ },
44
+ {
45
+ prefix: "exparser",
46
+ source: "field",
47
+ field: "__wxExparserNodeId__"
48
+ },
49
+ ...DEFAULT_PAGE_IDENTITY_RULES
50
+ ]
51
+ }
52
+ };
53
+ const ALIPAY_RUNTIME_DESCRIPTOR = {
54
+ id: "alipay",
55
+ aliases: [
56
+ "alipay",
57
+ "ali",
58
+ "my"
59
+ ],
60
+ runtime: {
61
+ globalObjectKey: "my",
62
+ hostConfigKey: DEFAULT_RUNTIME_HOST_CONFIG_KEY,
63
+ globalResolvePriority: 0,
64
+ routeGlobalResolvePriority: 2,
65
+ capabilities: {
66
+ ...DEFAULT_RUNTIME_CAPABILITIES,
67
+ pageShareMenu: false,
68
+ appThemeChangeListener: false
69
+ },
70
+ pageIdentityRules: DEFAULT_PAGE_IDENTITY_RULES
71
+ }
72
+ };
73
+ const SWAN_RUNTIME_DESCRIPTOR = {
74
+ id: "swan",
75
+ aliases: [
76
+ "swan",
77
+ "baidu",
78
+ "bd"
79
+ ],
80
+ runtime: {
81
+ globalObjectKey: "swan",
82
+ hostConfigKey: DEFAULT_RUNTIME_HOST_CONFIG_KEY,
83
+ capabilities: DEFAULT_RUNTIME_CAPABILITIES,
84
+ pageIdentityRules: DEFAULT_PAGE_IDENTITY_RULES
85
+ }
86
+ };
87
+ const TT_RUNTIME_DESCRIPTOR = {
88
+ id: "tt",
89
+ aliases: [
90
+ "tt",
91
+ "toutiao",
92
+ "bytedance",
93
+ "douyin"
94
+ ],
95
+ runtime: {
96
+ globalObjectKey: "tt",
97
+ hostConfigKey: DEFAULT_RUNTIME_HOST_CONFIG_KEY,
98
+ globalResolvePriority: 2,
99
+ routeGlobalResolvePriority: 1,
100
+ capabilities: {
101
+ ...DEFAULT_RUNTIME_CAPABILITIES,
102
+ appThemeChangeListener: false
103
+ },
104
+ pageIdentityRules: DEFAULT_PAGE_IDENTITY_RULES
105
+ }
106
+ };
107
+ const JD_RUNTIME_DESCRIPTOR = {
108
+ id: "jd",
109
+ aliases: ["jd", "jingdong"],
110
+ runtime: {
111
+ globalObjectKey: "jd",
112
+ hostConfigKey: DEFAULT_RUNTIME_HOST_CONFIG_KEY,
113
+ capabilities: DEFAULT_RUNTIME_CAPABILITIES,
114
+ pageIdentityRules: DEFAULT_PAGE_IDENTITY_RULES
115
+ }
116
+ };
117
+ const XHS_RUNTIME_DESCRIPTOR = {
118
+ id: "xhs",
119
+ aliases: [
120
+ "xhs",
121
+ "xiaohongshu",
122
+ "little-red-book",
123
+ "red"
124
+ ],
125
+ runtime: {
126
+ globalObjectKey: "xhs",
127
+ hostConfigKey: DEFAULT_RUNTIME_HOST_CONFIG_KEY,
128
+ capabilities: DEFAULT_RUNTIME_CAPABILITIES,
129
+ pageIdentityRules: DEFAULT_PAGE_IDENTITY_RULES
130
+ }
131
+ };
132
+ const MINI_PROGRAM_RUNTIME_DESCRIPTORS = [
133
+ WEAPP_RUNTIME_DESCRIPTOR,
134
+ ALIPAY_RUNTIME_DESCRIPTOR,
135
+ SWAN_RUNTIME_DESCRIPTOR,
136
+ TT_RUNTIME_DESCRIPTOR,
137
+ JD_RUNTIME_DESCRIPTOR,
138
+ XHS_RUNTIME_DESCRIPTOR
139
+ ];
140
+ //#endregion
141
+ export { ALIPAY_RUNTIME_DESCRIPTOR, DEFAULT_RUNTIME_CAPABILITIES, DEFAULT_RUNTIME_HOST_CONFIG_KEY, JD_RUNTIME_DESCRIPTOR, MINI_PROGRAM_RUNTIME_DESCRIPTORS, SWAN_RUNTIME_DESCRIPTOR, TT_RUNTIME_DESCRIPTOR, WEAPP_RUNTIME_DESCRIPTOR, XHS_RUNTIME_DESCRIPTOR };
@@ -0,0 +1,65 @@
1
+ import { MiniProgramRuntimeCapabilities, MiniProgramRuntimeCapabilityName, MpPlatform } from "../types.js";
2
+ import { MiniProgramRuntimeDescriptor } from "./descriptors.js";
3
+ //#region src/platforms/runtime/helpers.d.ts
4
+ export declare const MINI_PROGRAM_PLATFORM_ALIASES: Readonly<Record<string, MpPlatform>>;
5
+ /**
6
+ * @description 标准化平台输入。
7
+ */
8
+ export declare function normalizeMiniProgramPlatform(input?: string | null): string | undefined;
9
+ /**
10
+ * @description 解析平台输入到标准平台标识。
11
+ */
12
+ export declare function resolveMiniProgramPlatform(input?: string | null): MpPlatform | undefined;
13
+ /**
14
+ * @description 返回所有受支持的小程序平台。
15
+ */
16
+ export declare function getSupportedMiniProgramPlatforms(): readonly MpPlatform[];
17
+ /**
18
+ * @description 返回默认小程序平台。
19
+ */
20
+ export declare function getDefaultMiniProgramPlatform(): MpPlatform;
21
+ /**
22
+ * @description 获取平台描述。
23
+ */
24
+ export declare function getMiniProgramRuntimeDescriptor(platform: MpPlatform): MiniProgramRuntimeDescriptor;
25
+ /**
26
+ * @description 获取宿主全局对象 key。
27
+ */
28
+ export declare function getMiniProgramRuntimeGlobalKey(platform: MpPlatform): string;
29
+ /**
30
+ * @description 获取默认宿主全局对象 key。
31
+ */
32
+ export declare function getDefaultMiniProgramRuntimeGlobalKey(): string;
33
+ /**
34
+ * @description 解析宿主全局对象 key 对应的平台。
35
+ */
36
+ export declare function getMiniProgramPlatformByRuntimeGlobalKey(globalObjectKey?: string | null): MpPlatform | undefined;
37
+ /**
38
+ * @description 返回 runtime 全局对象 key 的扫描优先级。
39
+ */
40
+ export declare function getMiniProgramRuntimeGlobalKeys(platform?: MpPlatform): readonly string[];
41
+ /**
42
+ * @description 返回按通用解析优先级排序的 runtime 全局对象 key。
43
+ */
44
+ export declare function getMiniProgramRuntimeGlobalKeysByResolvePriority(platform?: MpPlatform): readonly string[];
45
+ /**
46
+ * @description 返回按路由解析优先级排序的 runtime 全局对象 key。
47
+ */
48
+ export declare function getMiniProgramRouteRuntimeGlobalKeys(platform?: MpPlatform): readonly string[];
49
+ /**
50
+ * @description 获取平台 runtime 宿主配置 key。
51
+ */
52
+ export declare function getMiniProgramRuntimeHostConfigKey(platform?: MpPlatform): string;
53
+ /**
54
+ * @description 获取平台 runtime 能力描述。
55
+ */
56
+ export declare function getMiniProgramRuntimeCapabilities(platform?: MpPlatform): MiniProgramRuntimeCapabilities;
57
+ /**
58
+ * @description 判断平台是否支持指定 runtime 能力。
59
+ */
60
+ export declare function supportsMiniProgramRuntimeCapability(platform: MpPlatform | undefined, capabilityName: MiniProgramRuntimeCapabilityName): boolean;
61
+ /**
62
+ * @description 根据平台描述解析页面身份 key。
63
+ */
64
+ export declare function resolveMiniProgramPageKeys(page?: Record<string, any>, platform?: MpPlatform): string[];
65
+ //#endregion
@@ -0,0 +1,169 @@
1
+ import { DEFAULT_RUNTIME_CAPABILITIES, MINI_PROGRAM_RUNTIME_DESCRIPTORS } from "./descriptors.js";
2
+ //#region src/platforms/runtime/helpers.ts
3
+ const LEADING_SLASH_RE = /^\/+/;
4
+ function createMiniProgramPlatformRegistry(descriptors) {
5
+ const descriptorById = /* @__PURE__ */ new Map();
6
+ const aliasToId = /* @__PURE__ */ new Map();
7
+ const runtimeGlobalKeyToId = /* @__PURE__ */ new Map();
8
+ for (const descriptor of descriptors) {
9
+ descriptorById.set(descriptor.id, descriptor);
10
+ runtimeGlobalKeyToId.set(descriptor.runtime.globalObjectKey, descriptor.id);
11
+ aliasToId.set(descriptor.id, descriptor.id);
12
+ for (const alias of descriptor.aliases) {
13
+ const normalized = alias.trim().toLowerCase();
14
+ if (!normalized) continue;
15
+ aliasToId.set(normalized, descriptor.id);
16
+ }
17
+ }
18
+ return {
19
+ aliasToId,
20
+ descriptorById,
21
+ runtimeGlobalKeyToId
22
+ };
23
+ }
24
+ 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_RUNTIME_DESCRIPTORS);
25
+ const SUPPORTED_MINI_PROGRAM_PLATFORMS = Object.freeze(MINI_PROGRAM_RUNTIME_DESCRIPTORS.map((descriptor) => descriptor.id));
26
+ const ORDERED_RUNTIME_GLOBAL_KEYS = Object.freeze(Array.from(new Set(MINI_PROGRAM_RUNTIME_DESCRIPTORS.map((descriptor) => descriptor.runtime.globalObjectKey))));
27
+ const MAX_RUNTIME_RESOLVE_PRIORITY = Number.MAX_SAFE_INTEGER;
28
+ function getOrderedRuntimeGlobalKeysByPriority(priorityKey) {
29
+ const ordered = [...MINI_PROGRAM_RUNTIME_DESCRIPTORS].sort((left, right) => {
30
+ const leftPriority = left.runtime[priorityKey] ?? MAX_RUNTIME_RESOLVE_PRIORITY;
31
+ const rightPriority = right.runtime[priorityKey] ?? MAX_RUNTIME_RESOLVE_PRIORITY;
32
+ if (leftPriority !== rightPriority) return leftPriority - rightPriority;
33
+ return MINI_PROGRAM_RUNTIME_DESCRIPTORS.indexOf(left) - MINI_PROGRAM_RUNTIME_DESCRIPTORS.indexOf(right);
34
+ });
35
+ return Object.freeze(Array.from(new Set(ordered.map((descriptor) => descriptor.runtime.globalObjectKey))));
36
+ }
37
+ const ORDERED_RUNTIME_GLOBAL_KEYS_BY_RESOLVE_PRIORITY = getOrderedRuntimeGlobalKeysByPriority("globalResolvePriority");
38
+ const ORDERED_RUNTIME_GLOBAL_KEYS_BY_ROUTE_PRIORITY = getOrderedRuntimeGlobalKeysByPriority("routeGlobalResolvePriority");
39
+ /**
40
+ * @description 小程序平台别名映射表。
41
+ */
42
+ const MINI_PROGRAM_PLATFORM_ALIAS_RECORD = {};
43
+ for (const [alias, platform] of MINI_PROGRAM_PLATFORM_ALIAS_TO_ID) MINI_PROGRAM_PLATFORM_ALIAS_RECORD[alias] = platform;
44
+ const MINI_PROGRAM_PLATFORM_ALIASES = Object.freeze(MINI_PROGRAM_PLATFORM_ALIAS_RECORD);
45
+ /**
46
+ * @description 标准化平台输入。
47
+ */
48
+ function normalizeMiniProgramPlatform(input) {
49
+ return input?.trim().toLowerCase() || void 0;
50
+ }
51
+ /**
52
+ * @description 解析平台输入到标准平台标识。
53
+ */
54
+ function resolveMiniProgramPlatform(input) {
55
+ const normalized = normalizeMiniProgramPlatform(input);
56
+ if (!normalized) return;
57
+ return MINI_PROGRAM_PLATFORM_ALIAS_TO_ID.get(normalized);
58
+ }
59
+ /**
60
+ * @description 返回所有受支持的小程序平台。
61
+ */
62
+ function getSupportedMiniProgramPlatforms() {
63
+ return SUPPORTED_MINI_PROGRAM_PLATFORMS;
64
+ }
65
+ /**
66
+ * @description 返回默认小程序平台。
67
+ */
68
+ function getDefaultMiniProgramPlatform() {
69
+ return SUPPORTED_MINI_PROGRAM_PLATFORMS[0] ?? "weapp";
70
+ }
71
+ /**
72
+ * @description 获取平台描述。
73
+ */
74
+ function getMiniProgramRuntimeDescriptor(platform) {
75
+ const descriptor = MINI_PROGRAM_PLATFORM_DESCRIPTOR_BY_ID.get(platform);
76
+ if (!descriptor) throw new Error(`不支持的小程序平台 "${platform}"。`);
77
+ return descriptor;
78
+ }
79
+ /**
80
+ * @description 获取宿主全局对象 key。
81
+ */
82
+ function getMiniProgramRuntimeGlobalKey(platform) {
83
+ return getMiniProgramRuntimeDescriptor(platform).runtime.globalObjectKey;
84
+ }
85
+ /**
86
+ * @description 获取默认宿主全局对象 key。
87
+ */
88
+ function getDefaultMiniProgramRuntimeGlobalKey() {
89
+ return ORDERED_RUNTIME_GLOBAL_KEYS[0] ?? "wx";
90
+ }
91
+ /**
92
+ * @description 解析宿主全局对象 key 对应的平台。
93
+ */
94
+ function getMiniProgramPlatformByRuntimeGlobalKey(globalObjectKey) {
95
+ const normalized = globalObjectKey?.trim();
96
+ if (!normalized) return;
97
+ return MINI_PROGRAM_RUNTIME_GLOBAL_KEY_TO_ID.get(normalized);
98
+ }
99
+ /**
100
+ * @description 返回 runtime 全局对象 key 的扫描优先级。
101
+ */
102
+ function getMiniProgramRuntimeGlobalKeys(platform) {
103
+ if (platform) return [getMiniProgramRuntimeGlobalKey(platform)];
104
+ return ORDERED_RUNTIME_GLOBAL_KEYS;
105
+ }
106
+ /**
107
+ * @description 返回按通用解析优先级排序的 runtime 全局对象 key。
108
+ */
109
+ function getMiniProgramRuntimeGlobalKeysByResolvePriority(platform) {
110
+ if (platform) return [getMiniProgramRuntimeGlobalKey(platform)];
111
+ return ORDERED_RUNTIME_GLOBAL_KEYS_BY_RESOLVE_PRIORITY;
112
+ }
113
+ /**
114
+ * @description 返回按路由解析优先级排序的 runtime 全局对象 key。
115
+ */
116
+ function getMiniProgramRouteRuntimeGlobalKeys(platform) {
117
+ if (platform) return [getMiniProgramRuntimeGlobalKey(platform)];
118
+ return ORDERED_RUNTIME_GLOBAL_KEYS_BY_ROUTE_PRIORITY;
119
+ }
120
+ /**
121
+ * @description 获取平台 runtime 宿主配置 key。
122
+ */
123
+ function getMiniProgramRuntimeHostConfigKey(platform) {
124
+ if (!platform) return "__wxConfig";
125
+ return getMiniProgramRuntimeDescriptor(platform).runtime.hostConfigKey;
126
+ }
127
+ /**
128
+ * @description 获取平台 runtime 能力描述。
129
+ */
130
+ function getMiniProgramRuntimeCapabilities(platform) {
131
+ if (!platform) return DEFAULT_RUNTIME_CAPABILITIES;
132
+ return getMiniProgramRuntimeDescriptor(platform).runtime.capabilities;
133
+ }
134
+ /**
135
+ * @description 判断平台是否支持指定 runtime 能力。
136
+ */
137
+ function supportsMiniProgramRuntimeCapability(platform, capabilityName) {
138
+ return getMiniProgramRuntimeCapabilities(platform)[capabilityName] === true;
139
+ }
140
+ function serializeMiniProgramPageIdentityRule(rule) {
141
+ return rule.source === "field" ? `${rule.prefix}:${rule.field ?? ""}` : `${rule.prefix}:route`;
142
+ }
143
+ function getMiniProgramPageIdentityRules(platform) {
144
+ if (platform) return getMiniProgramRuntimeDescriptor(platform).runtime.pageIdentityRules;
145
+ const merged = /* @__PURE__ */ new Map();
146
+ for (const descriptor of MINI_PROGRAM_RUNTIME_DESCRIPTORS) for (const rule of descriptor.runtime.pageIdentityRules) merged.set(serializeMiniProgramPageIdentityRule(rule), rule);
147
+ return [...merged.values()];
148
+ }
149
+ /**
150
+ * @description 根据平台描述解析页面身份 key。
151
+ */
152
+ function resolveMiniProgramPageKeys(page, platform) {
153
+ if (!page || typeof page !== "object") return [];
154
+ const keys = [];
155
+ for (const rule of getMiniProgramPageIdentityRules(platform)) {
156
+ if (rule.source === "route") {
157
+ const route = typeof page.route === "string" ? page.route.replace(LEADING_SLASH_RE, "") : "";
158
+ if (route) keys.push(`${rule.prefix}:${route}`);
159
+ continue;
160
+ }
161
+ const field = rule.field;
162
+ if (!field) continue;
163
+ const value = page[field];
164
+ if (typeof value === "number" || typeof value === "string") keys.push(`${rule.prefix}:${String(value)}`);
165
+ }
166
+ return Array.from(new Set(keys));
167
+ }
168
+ //#endregion
169
+ export { MINI_PROGRAM_PLATFORM_ALIASES, getDefaultMiniProgramPlatform, getDefaultMiniProgramRuntimeGlobalKey, getMiniProgramPlatformByRuntimeGlobalKey, getMiniProgramRouteRuntimeGlobalKeys, getMiniProgramRuntimeCapabilities, getMiniProgramRuntimeDescriptor, getMiniProgramRuntimeGlobalKey, getMiniProgramRuntimeGlobalKeys, getMiniProgramRuntimeGlobalKeysByResolvePriority, getMiniProgramRuntimeHostConfigKey, getSupportedMiniProgramPlatforms, normalizeMiniProgramPlatform, resolveMiniProgramPageKeys, resolveMiniProgramPlatform, supportsMiniProgramRuntimeCapability };
@@ -0,0 +1,5 @@
1
+ import { MiniProgramRuntimeCapabilities, MiniProgramRuntimeCapabilityName, MpPlatform } from "../types.js";
2
+ import { ALIPAY_RUNTIME_DESCRIPTOR, DEFAULT_RUNTIME_CAPABILITIES, DEFAULT_RUNTIME_HOST_CONFIG_KEY, JD_RUNTIME_DESCRIPTOR, MINI_PROGRAM_RUNTIME_DESCRIPTORS, MiniProgramRuntimeDescriptor, SWAN_RUNTIME_DESCRIPTOR, TT_RUNTIME_DESCRIPTOR, WEAPP_RUNTIME_DESCRIPTOR, XHS_RUNTIME_DESCRIPTOR } from "./descriptors.js";
3
+ import { MINI_PROGRAM_PLATFORM_ALIASES, getDefaultMiniProgramPlatform, getDefaultMiniProgramRuntimeGlobalKey, getMiniProgramPlatformByRuntimeGlobalKey, getMiniProgramRouteRuntimeGlobalKeys, getMiniProgramRuntimeCapabilities, getMiniProgramRuntimeDescriptor, getMiniProgramRuntimeGlobalKey, getMiniProgramRuntimeGlobalKeys, getMiniProgramRuntimeGlobalKeysByResolvePriority, getMiniProgramRuntimeHostConfigKey, getSupportedMiniProgramPlatforms, normalizeMiniProgramPlatform, resolveMiniProgramPageKeys, resolveMiniProgramPlatform, supportsMiniProgramRuntimeCapability } from "./helpers.js";
4
+ import { getMiniProgramDirectivePrefix, getSupportedMiniProgramDirectivePrefixes } from "./template.js";
5
+ export { ALIPAY_RUNTIME_DESCRIPTOR, DEFAULT_RUNTIME_CAPABILITIES, DEFAULT_RUNTIME_HOST_CONFIG_KEY, JD_RUNTIME_DESCRIPTOR, MINI_PROGRAM_PLATFORM_ALIASES, MINI_PROGRAM_RUNTIME_DESCRIPTORS, type MiniProgramRuntimeCapabilities, type MiniProgramRuntimeCapabilityName, MiniProgramRuntimeDescriptor, type MpPlatform, SWAN_RUNTIME_DESCRIPTOR, TT_RUNTIME_DESCRIPTOR, WEAPP_RUNTIME_DESCRIPTOR, XHS_RUNTIME_DESCRIPTOR, getDefaultMiniProgramPlatform, getDefaultMiniProgramRuntimeGlobalKey, getMiniProgramDirectivePrefix, getMiniProgramPlatformByRuntimeGlobalKey, getMiniProgramRouteRuntimeGlobalKeys, getMiniProgramRuntimeCapabilities, getMiniProgramRuntimeDescriptor, getMiniProgramRuntimeGlobalKey, getMiniProgramRuntimeGlobalKeys, getMiniProgramRuntimeGlobalKeysByResolvePriority, getMiniProgramRuntimeHostConfigKey, getSupportedMiniProgramDirectivePrefixes, getSupportedMiniProgramPlatforms, normalizeMiniProgramPlatform, resolveMiniProgramPageKeys, resolveMiniProgramPlatform, supportsMiniProgramRuntimeCapability };
@@ -0,0 +1,4 @@
1
+ import { ALIPAY_RUNTIME_DESCRIPTOR, DEFAULT_RUNTIME_CAPABILITIES, DEFAULT_RUNTIME_HOST_CONFIG_KEY, JD_RUNTIME_DESCRIPTOR, MINI_PROGRAM_RUNTIME_DESCRIPTORS, SWAN_RUNTIME_DESCRIPTOR, TT_RUNTIME_DESCRIPTOR, WEAPP_RUNTIME_DESCRIPTOR, XHS_RUNTIME_DESCRIPTOR } from "./descriptors.js";
2
+ import { getMiniProgramDirectivePrefix, getSupportedMiniProgramDirectivePrefixes } from "./template.js";
3
+ import { MINI_PROGRAM_PLATFORM_ALIASES, getDefaultMiniProgramPlatform, getDefaultMiniProgramRuntimeGlobalKey, getMiniProgramPlatformByRuntimeGlobalKey, getMiniProgramRouteRuntimeGlobalKeys, getMiniProgramRuntimeCapabilities, getMiniProgramRuntimeDescriptor, getMiniProgramRuntimeGlobalKey, getMiniProgramRuntimeGlobalKeys, getMiniProgramRuntimeGlobalKeysByResolvePriority, getMiniProgramRuntimeHostConfigKey, getSupportedMiniProgramPlatforms, normalizeMiniProgramPlatform, resolveMiniProgramPageKeys, resolveMiniProgramPlatform, supportsMiniProgramRuntimeCapability } from "./helpers.js";
4
+ export { ALIPAY_RUNTIME_DESCRIPTOR, DEFAULT_RUNTIME_CAPABILITIES, DEFAULT_RUNTIME_HOST_CONFIG_KEY, JD_RUNTIME_DESCRIPTOR, MINI_PROGRAM_PLATFORM_ALIASES, MINI_PROGRAM_RUNTIME_DESCRIPTORS, SWAN_RUNTIME_DESCRIPTOR, TT_RUNTIME_DESCRIPTOR, WEAPP_RUNTIME_DESCRIPTOR, XHS_RUNTIME_DESCRIPTOR, getDefaultMiniProgramPlatform, getDefaultMiniProgramRuntimeGlobalKey, getMiniProgramDirectivePrefix, getMiniProgramPlatformByRuntimeGlobalKey, getMiniProgramRouteRuntimeGlobalKeys, getMiniProgramRuntimeCapabilities, getMiniProgramRuntimeDescriptor, getMiniProgramRuntimeGlobalKey, getMiniProgramRuntimeGlobalKeys, getMiniProgramRuntimeGlobalKeysByResolvePriority, getMiniProgramRuntimeHostConfigKey, getSupportedMiniProgramDirectivePrefixes, getSupportedMiniProgramPlatforms, normalizeMiniProgramPlatform, resolveMiniProgramPageKeys, resolveMiniProgramPlatform, supportsMiniProgramRuntimeCapability };
@@ -0,0 +1,7 @@
1
+ import { MpPlatform } from "../types.js";
2
+ //#region src/platforms/runtime/template.d.ts
3
+ /** 返回所有受支持的小程序模板指令前缀。 */
4
+ export declare function getSupportedMiniProgramDirectivePrefixes(): readonly string[];
5
+ /** 获取平台模板指令前缀,兼容未指定平台时的微信默认值。 */
6
+ export declare function getMiniProgramDirectivePrefix(platform?: MpPlatform): string;
7
+ //#endregion
@@ -0,0 +1,22 @@
1
+ //#region src/platforms/runtime/template.ts
2
+ const MINI_PROGRAM_DIRECTIVE_PREFIXES = Object.freeze({
3
+ weapp: "wx",
4
+ alipay: "a",
5
+ swan: "s",
6
+ tt: "tt",
7
+ jd: "wx",
8
+ xhs: "wx"
9
+ });
10
+ const SUPPORTED_MINI_PROGRAM_DIRECTIVE_PREFIXES = Object.freeze(Array.from(new Set(Object.values(MINI_PROGRAM_DIRECTIVE_PREFIXES))));
11
+ /** 返回所有受支持的小程序模板指令前缀。 */
12
+ function getSupportedMiniProgramDirectivePrefixes() {
13
+ return SUPPORTED_MINI_PROGRAM_DIRECTIVE_PREFIXES;
14
+ }
15
+ /** 获取平台模板指令前缀,兼容未指定平台时的微信默认值。 */
16
+ function getMiniProgramDirectivePrefix(platform) {
17
+ const prefix = MINI_PROGRAM_DIRECTIVE_PREFIXES[platform ?? "weapp"];
18
+ if (!prefix) throw new Error(`不支持的小程序平台 "${platform}"。`);
19
+ return prefix;
20
+ }
21
+ //#endregion
22
+ export { MINI_PROGRAM_DIRECTIVE_PREFIXES, getMiniProgramDirectivePrefix, getSupportedMiniProgramDirectivePrefixes };
@@ -1,15 +1,15 @@
1
1
  //#region src/platforms/types.d.ts
2
- type MpPlatform = 'weapp' | 'alipay' | 'tt' | 'swan' | 'jd' | 'xhs';
3
- type MiniProgramTemplatePreset = 'wechat' | 'alipay' | 'tt' | 'swan';
4
- type MiniProgramPlatformFamily = 'wechat' | 'alipay' | 'tt' | 'swan';
5
- interface OutputExtensions {
2
+ export type MpPlatform = 'weapp' | 'alipay' | 'tt' | 'swan' | 'jd' | 'xhs';
3
+ export type MiniProgramTemplatePreset = 'wechat' | 'alipay' | 'tt' | 'swan';
4
+ export type MiniProgramPlatformFamily = 'wechat' | 'alipay' | 'tt' | 'swan';
5
+ export interface OutputExtensions {
6
6
  js: string;
7
7
  json: string;
8
8
  wxml: string;
9
9
  wxss: string;
10
10
  wxs?: string;
11
11
  }
12
- interface MiniProgramPageIdentityRule {
12
+ export interface MiniProgramPageIdentityRule {
13
13
  /**
14
14
  * @description 注册 layout bridge 等页面级能力时使用的 key 前缀。
15
15
  */
@@ -23,7 +23,7 @@ interface MiniProgramPageIdentityRule {
23
23
  */
24
24
  field?: string;
25
25
  }
26
- interface MiniProgramRuntimeCapabilities {
26
+ export interface MiniProgramRuntimeCapabilities {
27
27
  /**
28
28
  * @description 宿主是否支持全局 `getCurrentPages()` 页面栈读取。
29
29
  */
@@ -85,8 +85,8 @@ interface MiniProgramRuntimeCapabilities {
85
85
  */
86
86
  appMemoryWarningListener: boolean;
87
87
  }
88
- type MiniProgramRuntimeCapabilityName = keyof MiniProgramRuntimeCapabilities;
89
- interface MiniProgramPlatformDescriptor {
88
+ export type MiniProgramRuntimeCapabilityName = keyof MiniProgramRuntimeCapabilities;
89
+ export interface MiniProgramPlatformDescriptor {
90
90
  /**
91
91
  * @description 构建流程中使用的标准平台标识。
92
92
  */
@@ -210,98 +210,4 @@ interface MiniProgramPlatformDescriptor {
210
210
  capabilities: MiniProgramRuntimeCapabilities;
211
211
  };
212
212
  }
213
- //#endregion
214
- //#region src/platforms/descriptors.d.ts
215
- /**
216
- * @description 全仓库统一的小程序平台描述表。
217
- */
218
- declare const MINI_PROGRAM_PLATFORM_DESCRIPTORS: readonly MiniProgramPlatformDescriptor[];
219
- //#endregion
220
- //#region src/platforms/helpers.d.ts
221
- declare const MINI_PROGRAM_PLATFORM_ALIASES: Readonly<Record<string, MpPlatform>>;
222
- /**
223
- * @description 标准化平台输入。
224
- */
225
- declare function normalizeMiniProgramPlatform(input?: string | null): string | undefined;
226
- /**
227
- * @description 解析平台输入到标准平台标识。
228
- */
229
- declare function resolveMiniProgramPlatform(input?: string | null): MpPlatform | undefined;
230
- /**
231
- * @description 返回所有受支持的小程序平台。
232
- */
233
- declare function getSupportedMiniProgramPlatforms(): readonly MpPlatform[];
234
- /**
235
- * @description 返回所有受支持的小程序模板指令前缀。
236
- */
237
- declare function getSupportedMiniProgramDirectivePrefixes(): readonly string[];
238
- /**
239
- * @description 返回默认小程序平台。
240
- */
241
- declare function getDefaultMiniProgramPlatform(): MpPlatform;
242
- /**
243
- * @description 获取平台描述。
244
- */
245
- declare function getMiniProgramPlatformDescriptor(platform: MpPlatform): MiniProgramPlatformDescriptor;
246
- /**
247
- * @description 获取模板编译预设。
248
- */
249
- declare function getMiniProgramTemplatePreset(platform?: MpPlatform): MiniProgramTemplatePreset;
250
- /**
251
- * @description 判断平台是否允许自动补齐 app 样式入口。
252
- */
253
- declare function supportsMiniProgramAutoTouchAppStyle(platform?: MpPlatform): boolean;
254
- /**
255
- * @description 获取平台默认构建目标。
256
- */
257
- declare function getMiniProgramDefaultBuildTarget(platform?: MpPlatform): string | undefined;
258
- /**
259
- * @description 获取平台默认使用的类型包。
260
- */
261
- declare function getMiniProgramAppTypesPackage(platform?: MpPlatform): string;
262
- /**
263
- * @description 获取平台模板指令前缀。
264
- */
265
- declare function getMiniProgramDirectivePrefix(platform?: MpPlatform): string;
266
- /**
267
- * @description 获取宿主全局对象 key。
268
- */
269
- declare function getMiniProgramRuntimeGlobalKey(platform: MpPlatform): string;
270
- /**
271
- * @description 获取默认宿主全局对象 key。
272
- */
273
- declare function getDefaultMiniProgramRuntimeGlobalKey(): string;
274
- /**
275
- * @description 解析宿主全局对象 key 对应的平台。
276
- */
277
- declare function getMiniProgramPlatformByRuntimeGlobalKey(globalObjectKey?: string | null): MpPlatform | undefined;
278
- /**
279
- * @description 返回 runtime 全局对象 key 的扫描优先级。
280
- */
281
- declare function getMiniProgramRuntimeGlobalKeys(platform?: MpPlatform): readonly string[];
282
- /**
283
- * @description 返回按通用解析优先级排序的 runtime 全局对象 key。
284
- */
285
- declare function getMiniProgramRuntimeGlobalKeysByResolvePriority(platform?: MpPlatform): readonly string[];
286
- /**
287
- * @description 返回按路由解析优先级排序的 runtime 全局对象 key。
288
- */
289
- declare function getMiniProgramRouteRuntimeGlobalKeys(platform?: MpPlatform): readonly string[];
290
- /**
291
- * @description 获取平台 runtime 宿主配置 key。
292
- */
293
- declare function getMiniProgramRuntimeHostConfigKey(platform?: MpPlatform): string;
294
- /**
295
- * @description 获取平台 runtime 能力描述。
296
- */
297
- declare function getMiniProgramRuntimeCapabilities(platform?: MpPlatform): MiniProgramRuntimeCapabilities;
298
- /**
299
- * @description 判断平台是否支持指定 runtime 能力。
300
- */
301
- declare function supportsMiniProgramRuntimeCapability(platform: MpPlatform | undefined, capabilityName: MiniProgramRuntimeCapabilityName): boolean;
302
- /**
303
- * @description 根据平台描述解析页面身份 key。
304
- */
305
- declare function resolveMiniProgramPageKeys(page?: Record<string, any>, platform?: MpPlatform): string[];
306
- //#endregion
307
- export { MpPlatform as A, MINI_PROGRAM_PLATFORM_DESCRIPTORS as C, MiniProgramRuntimeCapabilities as D, MiniProgramPlatformFamily as E, MiniProgramRuntimeCapabilityName as O, supportsMiniProgramRuntimeCapability as S, MiniProgramPlatformDescriptor as T, getSupportedMiniProgramPlatforms as _, getMiniProgramDefaultBuildTarget as a, resolveMiniProgramPlatform as b, getMiniProgramPlatformDescriptor as c, getMiniProgramRuntimeGlobalKey as d, getMiniProgramRuntimeGlobalKeys as f, getSupportedMiniProgramDirectivePrefixes as g, getMiniProgramTemplatePreset as h, getMiniProgramAppTypesPackage as i, OutputExtensions as j, MiniProgramTemplatePreset as k, getMiniProgramRouteRuntimeGlobalKeys as l, getMiniProgramRuntimeHostConfigKey as m, getDefaultMiniProgramPlatform as n, getMiniProgramDirectivePrefix as o, getMiniProgramRuntimeGlobalKeysByResolvePriority as p, getDefaultMiniProgramRuntimeGlobalKey as r, getMiniProgramPlatformByRuntimeGlobalKey as s, MINI_PROGRAM_PLATFORM_ALIASES as t, getMiniProgramRuntimeCapabilities as u, normalizeMiniProgramPlatform as v, MiniProgramPageIdentityRule as w, supportsMiniProgramAutoTouchAppStyle as x, resolveMiniProgramPageKeys as y };
213
+ //#endregion
@@ -0,0 +1,44 @@
1
+ //#region src/runtimeProviders.d.ts
2
+ export type RuntimeProviderBackend = 'miniprogram' | 'web';
3
+ export type RuntimeProviderCompilation = 'native' | 'vue' | 'web';
4
+ export type RuntimeProviderModuleKind = 'runtime' | 'reactivity' | 'template';
5
+ export type RuntimeProviderVariant = 'development' | 'production';
6
+ export type RuntimeProviderInjectionMode = 'none' | 'virtual-module';
7
+ export type RuntimeProviderHmrMode = 'none' | 'host-reload' | 'module-accept';
8
+ /**
9
+ * 运行时 provider 的开发与生产入口。
10
+ */
11
+ export interface RuntimeProviderEntry {
12
+ development: string;
13
+ production: string;
14
+ }
15
+ /**
16
+ * 运行时 provider 的声明式能力。
17
+ */
18
+ export interface RuntimeProviderCapabilities {
19
+ framework: boolean;
20
+ hmr: boolean;
21
+ nativeHost: boolean;
22
+ webHost: boolean;
23
+ }
24
+ /**
25
+ * 运行时 provider 的 HMR 契约。
26
+ */
27
+ export interface RuntimeProviderHmrDescriptor {
28
+ mode: RuntimeProviderHmrMode;
29
+ acceptCode?: string;
30
+ }
31
+ /**
32
+ * 跨包共享的运行时 provider 描述契约。
33
+ */
34
+ export interface RuntimeProviderDescriptorContract {
35
+ id: string;
36
+ backend: RuntimeProviderBackend;
37
+ compilation: RuntimeProviderCompilation;
38
+ injection: RuntimeProviderInjectionMode;
39
+ entries: Readonly<Partial<Record<RuntimeProviderModuleKind, RuntimeProviderEntry>>>;
40
+ capabilities: Readonly<RuntimeProviderCapabilities>;
41
+ hmr: Readonly<RuntimeProviderHmrDescriptor>;
42
+ contractVersion: number;
43
+ }
44
+ //#endregion
package/dist/wxml.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ //#region src/wxml.d.ts
2
+ /**
3
+ * @description 按 exparser 与 glass-easel 的共同规则序列化 WXML 静态文本。
4
+ */
5
+ export declare function escapeWxmlText(value: string): string;
6
+ /**
7
+ * @description 按 exparser 与 glass-easel 的共同规则序列化双引号 WXML 属性值。
8
+ */
9
+ export declare function escapeWxmlAttribute(value: string): string;
10
+ //#endregion
package/dist/wxml.js ADDED
@@ -0,0 +1,26 @@
1
+ //#region src/wxml.ts
2
+ const WXML_TEXT_ESCAPE_RE = /[&<>]/g;
3
+ const WXML_ATTRIBUTE_ESCAPE_RE = /[&"<]/g;
4
+ const WXML_TEXT_ESCAPE_MAP = {
5
+ "&": "&amp;",
6
+ "<": "&lt;",
7
+ ">": "&gt;"
8
+ };
9
+ const WXML_ATTRIBUTE_ESCAPE_MAP = {
10
+ ...WXML_TEXT_ESCAPE_MAP,
11
+ "\"": "&quot;"
12
+ };
13
+ /**
14
+ * @description 按 exparser 与 glass-easel 的共同规则序列化 WXML 静态文本。
15
+ */
16
+ function escapeWxmlText(value) {
17
+ return value.replace(WXML_TEXT_ESCAPE_RE, (char) => WXML_TEXT_ESCAPE_MAP[char] ?? char);
18
+ }
19
+ /**
20
+ * @description 按 exparser 与 glass-easel 的共同规则序列化双引号 WXML 属性值。
21
+ */
22
+ function escapeWxmlAttribute(value) {
23
+ return value.replace(WXML_ATTRIBUTE_ESCAPE_RE, (char) => WXML_ATTRIBUTE_ESCAPE_MAP[char] ?? char);
24
+ }
25
+ //#endregion
26
+ export { escapeWxmlAttribute, escapeWxmlText };