@weapp-core/shared 3.0.5 → 3.1.0
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/fs/index.d.ts +0 -1
- package/dist/index-D84ZI2kr.d.ts +310 -0
- package/dist/index.d.ts +40 -305
- package/dist/index.js +1 -499
- package/dist/node.d.ts +0 -1
- package/dist/platforms/index.d.ts +2 -0
- package/dist/platforms/index.js +2 -0
- package/dist/platforms-CoAy6Y88.js +500 -0
- package/package.json +9 -1
|
@@ -0,0 +1,500 @@
|
|
|
1
|
+
//#region src/platforms/descriptors.ts
|
|
2
|
+
const DEFAULT_PROJECT_CONFIG_ROOT_KEYS = ["miniprogramRoot", "srcMiniprogramRoot"];
|
|
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
|
+
/**
|
|
25
|
+
* @description 全仓库统一的小程序平台描述表。
|
|
26
|
+
*/
|
|
27
|
+
const MINI_PROGRAM_PLATFORM_DESCRIPTORS = [
|
|
28
|
+
{
|
|
29
|
+
id: "weapp",
|
|
30
|
+
displayName: "WeChat Mini Program",
|
|
31
|
+
family: "wechat",
|
|
32
|
+
aliases: [
|
|
33
|
+
"weapp",
|
|
34
|
+
"wechat",
|
|
35
|
+
"weixin",
|
|
36
|
+
"wx"
|
|
37
|
+
],
|
|
38
|
+
outputExtensions: {
|
|
39
|
+
js: "js",
|
|
40
|
+
json: "json",
|
|
41
|
+
wxml: "wxml",
|
|
42
|
+
wxss: "wxss",
|
|
43
|
+
wxs: "wxs"
|
|
44
|
+
},
|
|
45
|
+
projectConfigFileName: "project.config.json",
|
|
46
|
+
projectConfigRootKeys: DEFAULT_PROJECT_CONFIG_ROOT_KEYS,
|
|
47
|
+
ide: {},
|
|
48
|
+
build: {
|
|
49
|
+
autoTouchAppStyle: true,
|
|
50
|
+
defaultBuildTarget: "es2020"
|
|
51
|
+
},
|
|
52
|
+
resolvePreservedNpmDirNames: () => ["miniprogram_npm"],
|
|
53
|
+
json: {},
|
|
54
|
+
npm: { distDirName: () => "miniprogram_npm" },
|
|
55
|
+
wxml: {
|
|
56
|
+
eventBindingStyle: "default",
|
|
57
|
+
directivePrefix: "wx"
|
|
58
|
+
},
|
|
59
|
+
compiler: { templatePreset: "wechat" },
|
|
60
|
+
typescript: { appTypesPackage: "miniprogram-api-typings" },
|
|
61
|
+
runtime: {
|
|
62
|
+
globalObjectKey: "wx",
|
|
63
|
+
hostConfigKey: "__wxConfig",
|
|
64
|
+
globalResolvePriority: 1,
|
|
65
|
+
routeGlobalResolvePriority: 0,
|
|
66
|
+
capabilities: DEFAULT_RUNTIME_CAPABILITIES,
|
|
67
|
+
pageIdentityRules: [
|
|
68
|
+
{
|
|
69
|
+
prefix: "webview",
|
|
70
|
+
source: "field",
|
|
71
|
+
field: "__wxWebviewId__"
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
prefix: "exparser",
|
|
75
|
+
source: "field",
|
|
76
|
+
field: "__wxExparserNodeId__"
|
|
77
|
+
},
|
|
78
|
+
...DEFAULT_PAGE_IDENTITY_RULES
|
|
79
|
+
]
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
id: "alipay",
|
|
84
|
+
displayName: "Alipay Mini Program",
|
|
85
|
+
family: "alipay",
|
|
86
|
+
aliases: [
|
|
87
|
+
"alipay",
|
|
88
|
+
"ali",
|
|
89
|
+
"my"
|
|
90
|
+
],
|
|
91
|
+
outputExtensions: {
|
|
92
|
+
js: "js",
|
|
93
|
+
json: "json",
|
|
94
|
+
wxml: "axml",
|
|
95
|
+
wxss: "acss",
|
|
96
|
+
wxs: "sjs"
|
|
97
|
+
},
|
|
98
|
+
projectConfigFileName: "mini.project.json",
|
|
99
|
+
projectConfigRootKeys: DEFAULT_PROJECT_CONFIG_ROOT_KEYS,
|
|
100
|
+
scriptModuleTagByExtension: { sjs: "import-sjs" },
|
|
101
|
+
usesProjectRootNpmDir: true,
|
|
102
|
+
ide: {
|
|
103
|
+
requiresOpenPlatformArg: true,
|
|
104
|
+
defaultProjectRoot: "dist/alipay/dist"
|
|
105
|
+
},
|
|
106
|
+
build: {
|
|
107
|
+
autoTouchAppStyle: false,
|
|
108
|
+
defaultBuildTarget: "es2015"
|
|
109
|
+
},
|
|
110
|
+
resolvePreservedNpmDirNames: (options) => [options?.alipayNpmMode === "miniprogram_npm" ? "miniprogram_npm" : "node_modules"],
|
|
111
|
+
json: {
|
|
112
|
+
normalizeUsingComponents: true,
|
|
113
|
+
fillComponentGenericsDefault: true,
|
|
114
|
+
rewriteBundleNpmImports: true
|
|
115
|
+
},
|
|
116
|
+
npm: {
|
|
117
|
+
distDirName: (options) => options?.alipayNpmMode === "miniprogram_npm" ? "miniprogram_npm" : "node_modules",
|
|
118
|
+
normalizeImportPath: true,
|
|
119
|
+
normalizeMiniprogramPackage: true,
|
|
120
|
+
copyEsModuleDirectory: true,
|
|
121
|
+
hoistNestedDependencies: true,
|
|
122
|
+
shouldRebuildCachedPackage: true
|
|
123
|
+
},
|
|
124
|
+
wxml: {
|
|
125
|
+
eventBindingStyle: "alipay",
|
|
126
|
+
directivePrefix: "a",
|
|
127
|
+
normalizeComponentTagName: true,
|
|
128
|
+
normalizeVueTemplate: true,
|
|
129
|
+
emitGenericPlaceholder: true
|
|
130
|
+
},
|
|
131
|
+
compiler: { templatePreset: "alipay" },
|
|
132
|
+
typescript: { appTypesPackage: "@mini-types/alipay" },
|
|
133
|
+
runtime: {
|
|
134
|
+
globalObjectKey: "my",
|
|
135
|
+
hostConfigKey: "__wxConfig",
|
|
136
|
+
globalResolvePriority: 0,
|
|
137
|
+
routeGlobalResolvePriority: 2,
|
|
138
|
+
capabilities: {
|
|
139
|
+
...DEFAULT_RUNTIME_CAPABILITIES,
|
|
140
|
+
pageShareMenu: false,
|
|
141
|
+
appThemeChangeListener: false
|
|
142
|
+
},
|
|
143
|
+
pageIdentityRules: DEFAULT_PAGE_IDENTITY_RULES
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
id: "swan",
|
|
148
|
+
displayName: "Baidu Smart Program",
|
|
149
|
+
family: "swan",
|
|
150
|
+
aliases: [
|
|
151
|
+
"swan",
|
|
152
|
+
"baidu",
|
|
153
|
+
"bd"
|
|
154
|
+
],
|
|
155
|
+
outputExtensions: {
|
|
156
|
+
js: "js",
|
|
157
|
+
json: "json",
|
|
158
|
+
wxml: "swan",
|
|
159
|
+
wxss: "css",
|
|
160
|
+
wxs: "sjs"
|
|
161
|
+
},
|
|
162
|
+
projectConfigFileName: "project.swan.json",
|
|
163
|
+
projectConfigRootKeys: ["smartProgramRoot", ...DEFAULT_PROJECT_CONFIG_ROOT_KEYS],
|
|
164
|
+
ide: {},
|
|
165
|
+
build: { autoTouchAppStyle: false },
|
|
166
|
+
resolvePreservedNpmDirNames: () => ["miniprogram_npm"],
|
|
167
|
+
json: {},
|
|
168
|
+
npm: { distDirName: () => "miniprogram_npm" },
|
|
169
|
+
wxml: {
|
|
170
|
+
eventBindingStyle: "default",
|
|
171
|
+
directivePrefix: "s"
|
|
172
|
+
},
|
|
173
|
+
compiler: { templatePreset: "swan" },
|
|
174
|
+
typescript: { appTypesPackage: "miniprogram-api-typings" },
|
|
175
|
+
runtime: {
|
|
176
|
+
globalObjectKey: "swan",
|
|
177
|
+
hostConfigKey: "__wxConfig",
|
|
178
|
+
capabilities: DEFAULT_RUNTIME_CAPABILITIES,
|
|
179
|
+
pageIdentityRules: DEFAULT_PAGE_IDENTITY_RULES
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
id: "tt",
|
|
184
|
+
displayName: "ByteDance / Douyin Mini Program",
|
|
185
|
+
family: "tt",
|
|
186
|
+
aliases: [
|
|
187
|
+
"tt",
|
|
188
|
+
"toutiao",
|
|
189
|
+
"bytedance",
|
|
190
|
+
"douyin"
|
|
191
|
+
],
|
|
192
|
+
outputExtensions: {
|
|
193
|
+
js: "js",
|
|
194
|
+
json: "json",
|
|
195
|
+
wxml: "ttml",
|
|
196
|
+
wxss: "ttss"
|
|
197
|
+
},
|
|
198
|
+
projectConfigFileName: "project.config.json",
|
|
199
|
+
projectConfigRootKeys: DEFAULT_PROJECT_CONFIG_ROOT_KEYS,
|
|
200
|
+
ide: {},
|
|
201
|
+
build: { autoTouchAppStyle: false },
|
|
202
|
+
resolvePreservedNpmDirNames: () => ["miniprogram_npm"],
|
|
203
|
+
json: {},
|
|
204
|
+
npm: { distDirName: () => "miniprogram_npm" },
|
|
205
|
+
wxml: {
|
|
206
|
+
eventBindingStyle: "default",
|
|
207
|
+
directivePrefix: "tt"
|
|
208
|
+
},
|
|
209
|
+
compiler: { templatePreset: "tt" },
|
|
210
|
+
typescript: { appTypesPackage: "@douyin-microapp/typings" },
|
|
211
|
+
runtime: {
|
|
212
|
+
globalObjectKey: "tt",
|
|
213
|
+
hostConfigKey: "__wxConfig",
|
|
214
|
+
globalResolvePriority: 2,
|
|
215
|
+
routeGlobalResolvePriority: 1,
|
|
216
|
+
capabilities: {
|
|
217
|
+
...DEFAULT_RUNTIME_CAPABILITIES,
|
|
218
|
+
appThemeChangeListener: false
|
|
219
|
+
},
|
|
220
|
+
pageIdentityRules: DEFAULT_PAGE_IDENTITY_RULES
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
id: "jd",
|
|
225
|
+
displayName: "JD Mini Program",
|
|
226
|
+
family: "wechat",
|
|
227
|
+
aliases: ["jd", "jingdong"],
|
|
228
|
+
outputExtensions: {
|
|
229
|
+
js: "js",
|
|
230
|
+
json: "json",
|
|
231
|
+
wxml: "jxml",
|
|
232
|
+
wxss: "jxss",
|
|
233
|
+
wxs: "wxs"
|
|
234
|
+
},
|
|
235
|
+
projectConfigFileName: "project.config.json",
|
|
236
|
+
projectConfigRootKeys: DEFAULT_PROJECT_CONFIG_ROOT_KEYS,
|
|
237
|
+
ide: {},
|
|
238
|
+
build: { autoTouchAppStyle: false },
|
|
239
|
+
resolvePreservedNpmDirNames: () => ["miniprogram_npm"],
|
|
240
|
+
json: {},
|
|
241
|
+
npm: { distDirName: () => "miniprogram_npm" },
|
|
242
|
+
wxml: {
|
|
243
|
+
eventBindingStyle: "default",
|
|
244
|
+
directivePrefix: "wx"
|
|
245
|
+
},
|
|
246
|
+
compiler: { templatePreset: "wechat" },
|
|
247
|
+
typescript: { appTypesPackage: "miniprogram-api-typings" },
|
|
248
|
+
runtime: {
|
|
249
|
+
globalObjectKey: "jd",
|
|
250
|
+
hostConfigKey: "__wxConfig",
|
|
251
|
+
capabilities: DEFAULT_RUNTIME_CAPABILITIES,
|
|
252
|
+
pageIdentityRules: DEFAULT_PAGE_IDENTITY_RULES
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
id: "xhs",
|
|
257
|
+
displayName: "Xiaohongshu Mini Program",
|
|
258
|
+
family: "wechat",
|
|
259
|
+
aliases: [
|
|
260
|
+
"xhs",
|
|
261
|
+
"xiaohongshu",
|
|
262
|
+
"little-red-book",
|
|
263
|
+
"red"
|
|
264
|
+
],
|
|
265
|
+
outputExtensions: {
|
|
266
|
+
js: "js",
|
|
267
|
+
json: "json",
|
|
268
|
+
wxml: "xhsml",
|
|
269
|
+
wxss: "css",
|
|
270
|
+
wxs: "wxs"
|
|
271
|
+
},
|
|
272
|
+
projectConfigFileName: "project.config.json",
|
|
273
|
+
projectConfigRootKeys: DEFAULT_PROJECT_CONFIG_ROOT_KEYS,
|
|
274
|
+
ide: {},
|
|
275
|
+
build: { autoTouchAppStyle: false },
|
|
276
|
+
resolvePreservedNpmDirNames: () => ["miniprogram_npm"],
|
|
277
|
+
json: {},
|
|
278
|
+
npm: { distDirName: () => "miniprogram_npm" },
|
|
279
|
+
wxml: {
|
|
280
|
+
eventBindingStyle: "default",
|
|
281
|
+
directivePrefix: "wx"
|
|
282
|
+
},
|
|
283
|
+
compiler: { templatePreset: "wechat" },
|
|
284
|
+
typescript: { appTypesPackage: "miniprogram-api-typings" },
|
|
285
|
+
runtime: {
|
|
286
|
+
globalObjectKey: "xhs",
|
|
287
|
+
hostConfigKey: "__wxConfig",
|
|
288
|
+
capabilities: DEFAULT_RUNTIME_CAPABILITIES,
|
|
289
|
+
pageIdentityRules: DEFAULT_PAGE_IDENTITY_RULES
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
];
|
|
293
|
+
//#endregion
|
|
294
|
+
//#region src/platforms/helpers.ts
|
|
295
|
+
const LEADING_SLASH_RE = /^\/+/;
|
|
296
|
+
function createMiniProgramPlatformRegistry(descriptors) {
|
|
297
|
+
const descriptorById = /* @__PURE__ */ new Map();
|
|
298
|
+
const aliasToId = /* @__PURE__ */ new Map();
|
|
299
|
+
const runtimeGlobalKeyToId = /* @__PURE__ */ new Map();
|
|
300
|
+
for (const descriptor of descriptors) {
|
|
301
|
+
descriptorById.set(descriptor.id, descriptor);
|
|
302
|
+
runtimeGlobalKeyToId.set(descriptor.runtime.globalObjectKey, descriptor.id);
|
|
303
|
+
aliasToId.set(descriptor.id, descriptor.id);
|
|
304
|
+
for (const alias of descriptor.aliases) {
|
|
305
|
+
const normalized = alias.trim().toLowerCase();
|
|
306
|
+
if (!normalized) continue;
|
|
307
|
+
aliasToId.set(normalized, descriptor.id);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return {
|
|
311
|
+
aliasToId,
|
|
312
|
+
descriptorById,
|
|
313
|
+
runtimeGlobalKeyToId
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
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);
|
|
317
|
+
const SUPPORTED_MINI_PROGRAM_PLATFORMS = Object.freeze(MINI_PROGRAM_PLATFORM_DESCRIPTORS.map((descriptor) => descriptor.id));
|
|
318
|
+
const SUPPORTED_MINI_PROGRAM_DIRECTIVE_PREFIXES = Object.freeze(Array.from(new Set(MINI_PROGRAM_PLATFORM_DESCRIPTORS.map((descriptor) => descriptor.wxml?.directivePrefix).filter((prefix) => Boolean(prefix)))));
|
|
319
|
+
const ORDERED_RUNTIME_GLOBAL_KEYS = Object.freeze(Array.from(new Set(MINI_PROGRAM_PLATFORM_DESCRIPTORS.map((descriptor) => descriptor.runtime.globalObjectKey))));
|
|
320
|
+
const MAX_RUNTIME_RESOLVE_PRIORITY = Number.MAX_SAFE_INTEGER;
|
|
321
|
+
function getOrderedRuntimeGlobalKeysByPriority(priorityKey) {
|
|
322
|
+
const ordered = [...MINI_PROGRAM_PLATFORM_DESCRIPTORS].sort((left, right) => {
|
|
323
|
+
const leftPriority = left.runtime[priorityKey] ?? MAX_RUNTIME_RESOLVE_PRIORITY;
|
|
324
|
+
const rightPriority = right.runtime[priorityKey] ?? MAX_RUNTIME_RESOLVE_PRIORITY;
|
|
325
|
+
if (leftPriority !== rightPriority) return leftPriority - rightPriority;
|
|
326
|
+
return MINI_PROGRAM_PLATFORM_DESCRIPTORS.indexOf(left) - MINI_PROGRAM_PLATFORM_DESCRIPTORS.indexOf(right);
|
|
327
|
+
});
|
|
328
|
+
return Object.freeze(Array.from(new Set(ordered.map((descriptor) => descriptor.runtime.globalObjectKey))));
|
|
329
|
+
}
|
|
330
|
+
const ORDERED_RUNTIME_GLOBAL_KEYS_BY_RESOLVE_PRIORITY = getOrderedRuntimeGlobalKeysByPriority("globalResolvePriority");
|
|
331
|
+
const ORDERED_RUNTIME_GLOBAL_KEYS_BY_ROUTE_PRIORITY = getOrderedRuntimeGlobalKeysByPriority("routeGlobalResolvePriority");
|
|
332
|
+
/**
|
|
333
|
+
* @description 小程序平台别名映射表。
|
|
334
|
+
*/
|
|
335
|
+
const MINI_PROGRAM_PLATFORM_ALIASES = Object.freeze(Object.fromEntries(MINI_PROGRAM_PLATFORM_ALIAS_TO_ID.entries()));
|
|
336
|
+
/**
|
|
337
|
+
* @description 标准化平台输入。
|
|
338
|
+
*/
|
|
339
|
+
function normalizeMiniProgramPlatform(input) {
|
|
340
|
+
return input?.trim().toLowerCase() || void 0;
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* @description 解析平台输入到标准平台标识。
|
|
344
|
+
*/
|
|
345
|
+
function resolveMiniProgramPlatform(input) {
|
|
346
|
+
const normalized = normalizeMiniProgramPlatform(input);
|
|
347
|
+
if (!normalized) return;
|
|
348
|
+
return MINI_PROGRAM_PLATFORM_ALIAS_TO_ID.get(normalized);
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* @description 返回所有受支持的小程序平台。
|
|
352
|
+
*/
|
|
353
|
+
function getSupportedMiniProgramPlatforms() {
|
|
354
|
+
return SUPPORTED_MINI_PROGRAM_PLATFORMS;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* @description 返回所有受支持的小程序模板指令前缀。
|
|
358
|
+
*/
|
|
359
|
+
function getSupportedMiniProgramDirectivePrefixes() {
|
|
360
|
+
return SUPPORTED_MINI_PROGRAM_DIRECTIVE_PREFIXES;
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* @description 返回默认小程序平台。
|
|
364
|
+
*/
|
|
365
|
+
function getDefaultMiniProgramPlatform() {
|
|
366
|
+
return SUPPORTED_MINI_PROGRAM_PLATFORMS[0] ?? "weapp";
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* @description 获取平台描述。
|
|
370
|
+
*/
|
|
371
|
+
function getMiniProgramPlatformDescriptor(platform) {
|
|
372
|
+
const descriptor = MINI_PROGRAM_PLATFORM_DESCRIPTOR_BY_ID.get(platform);
|
|
373
|
+
if (!descriptor) throw new Error(`不支持的小程序平台 "${platform}"。`);
|
|
374
|
+
return descriptor;
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* @description 获取模板编译预设。
|
|
378
|
+
*/
|
|
379
|
+
function getMiniProgramTemplatePreset(platform) {
|
|
380
|
+
if (!platform) return "wechat";
|
|
381
|
+
return getMiniProgramPlatformDescriptor(platform).compiler?.templatePreset ?? "wechat";
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* @description 判断平台是否允许自动补齐 app 样式入口。
|
|
385
|
+
*/
|
|
386
|
+
function supportsMiniProgramAutoTouchAppStyle(platform) {
|
|
387
|
+
if (!platform) return false;
|
|
388
|
+
return getMiniProgramPlatformDescriptor(platform).build?.autoTouchAppStyle === true;
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* @description 获取平台默认构建目标。
|
|
392
|
+
*/
|
|
393
|
+
function getMiniProgramDefaultBuildTarget(platform) {
|
|
394
|
+
if (!platform) return;
|
|
395
|
+
return getMiniProgramPlatformDescriptor(platform).build?.defaultBuildTarget;
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* @description 获取平台默认使用的类型包。
|
|
399
|
+
*/
|
|
400
|
+
function getMiniProgramAppTypesPackage(platform) {
|
|
401
|
+
return getMiniProgramPlatformDescriptor(platform ?? getDefaultMiniProgramPlatform()).typescript?.appTypesPackage ?? "miniprogram-api-typings";
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* @description 获取平台模板指令前缀。
|
|
405
|
+
*/
|
|
406
|
+
function getMiniProgramDirectivePrefix(platform) {
|
|
407
|
+
if (!platform) return "wx";
|
|
408
|
+
return getMiniProgramPlatformDescriptor(platform).wxml?.directivePrefix ?? "wx";
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* @description 获取宿主全局对象 key。
|
|
412
|
+
*/
|
|
413
|
+
function getMiniProgramRuntimeGlobalKey(platform) {
|
|
414
|
+
return getMiniProgramPlatformDescriptor(platform).runtime.globalObjectKey;
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* @description 获取默认宿主全局对象 key。
|
|
418
|
+
*/
|
|
419
|
+
function getDefaultMiniProgramRuntimeGlobalKey() {
|
|
420
|
+
return ORDERED_RUNTIME_GLOBAL_KEYS[0] ?? "wx";
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* @description 解析宿主全局对象 key 对应的平台。
|
|
424
|
+
*/
|
|
425
|
+
function getMiniProgramPlatformByRuntimeGlobalKey(globalObjectKey) {
|
|
426
|
+
const normalized = globalObjectKey?.trim();
|
|
427
|
+
if (!normalized) return;
|
|
428
|
+
return MINI_PROGRAM_RUNTIME_GLOBAL_KEY_TO_ID.get(normalized);
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* @description 返回 runtime 全局对象 key 的扫描优先级。
|
|
432
|
+
*/
|
|
433
|
+
function getMiniProgramRuntimeGlobalKeys(platform) {
|
|
434
|
+
if (platform) return [getMiniProgramRuntimeGlobalKey(platform)];
|
|
435
|
+
return ORDERED_RUNTIME_GLOBAL_KEYS;
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* @description 返回按通用解析优先级排序的 runtime 全局对象 key。
|
|
439
|
+
*/
|
|
440
|
+
function getMiniProgramRuntimeGlobalKeysByResolvePriority(platform) {
|
|
441
|
+
if (platform) return [getMiniProgramRuntimeGlobalKey(platform)];
|
|
442
|
+
return ORDERED_RUNTIME_GLOBAL_KEYS_BY_RESOLVE_PRIORITY;
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* @description 返回按路由解析优先级排序的 runtime 全局对象 key。
|
|
446
|
+
*/
|
|
447
|
+
function getMiniProgramRouteRuntimeGlobalKeys(platform) {
|
|
448
|
+
if (platform) return [getMiniProgramRuntimeGlobalKey(platform)];
|
|
449
|
+
return ORDERED_RUNTIME_GLOBAL_KEYS_BY_ROUTE_PRIORITY;
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* @description 获取平台 runtime 宿主配置 key。
|
|
453
|
+
*/
|
|
454
|
+
function getMiniProgramRuntimeHostConfigKey(platform) {
|
|
455
|
+
if (!platform) return "__wxConfig";
|
|
456
|
+
return getMiniProgramPlatformDescriptor(platform).runtime.hostConfigKey;
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* @description 获取平台 runtime 能力描述。
|
|
460
|
+
*/
|
|
461
|
+
function getMiniProgramRuntimeCapabilities(platform) {
|
|
462
|
+
if (!platform) return DEFAULT_RUNTIME_CAPABILITIES;
|
|
463
|
+
return getMiniProgramPlatformDescriptor(platform).runtime.capabilities;
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* @description 判断平台是否支持指定 runtime 能力。
|
|
467
|
+
*/
|
|
468
|
+
function supportsMiniProgramRuntimeCapability(platform, capabilityName) {
|
|
469
|
+
return getMiniProgramRuntimeCapabilities(platform)[capabilityName] === true;
|
|
470
|
+
}
|
|
471
|
+
function serializeMiniProgramPageIdentityRule(rule) {
|
|
472
|
+
return rule.source === "field" ? `${rule.prefix}:${rule.field ?? ""}` : `${rule.prefix}:route`;
|
|
473
|
+
}
|
|
474
|
+
function getMiniProgramPageIdentityRules(platform) {
|
|
475
|
+
if (platform) return getMiniProgramPlatformDescriptor(platform).runtime.pageIdentityRules;
|
|
476
|
+
const merged = /* @__PURE__ */ new Map();
|
|
477
|
+
for (const descriptor of MINI_PROGRAM_PLATFORM_DESCRIPTORS) for (const rule of descriptor.runtime.pageIdentityRules) merged.set(serializeMiniProgramPageIdentityRule(rule), rule);
|
|
478
|
+
return [...merged.values()];
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* @description 根据平台描述解析页面身份 key。
|
|
482
|
+
*/
|
|
483
|
+
function resolveMiniProgramPageKeys(page, platform) {
|
|
484
|
+
if (!page || typeof page !== "object") return [];
|
|
485
|
+
const keys = [];
|
|
486
|
+
for (const rule of getMiniProgramPageIdentityRules(platform)) {
|
|
487
|
+
if (rule.source === "route") {
|
|
488
|
+
const route = typeof page.route === "string" ? page.route.replace(LEADING_SLASH_RE, "") : "";
|
|
489
|
+
if (route) keys.push(`${rule.prefix}:${route}`);
|
|
490
|
+
continue;
|
|
491
|
+
}
|
|
492
|
+
const field = rule.field;
|
|
493
|
+
if (!field) continue;
|
|
494
|
+
const value = page[field];
|
|
495
|
+
if (typeof value === "number" || typeof value === "string") keys.push(`${rule.prefix}:${String(value)}`);
|
|
496
|
+
}
|
|
497
|
+
return Array.from(new Set(keys));
|
|
498
|
+
}
|
|
499
|
+
//#endregion
|
|
500
|
+
export { MINI_PROGRAM_PLATFORM_DESCRIPTORS as C, supportsMiniProgramRuntimeCapability as S, 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, 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, supportsMiniProgramAutoTouchAppStyle as x, resolveMiniProgramPageKeys as y };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weapp-core/shared",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.0
|
|
4
|
+
"version": "3.1.0",
|
|
5
5
|
"description": "@weapp-core/shared",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -28,6 +28,10 @@
|
|
|
28
28
|
"./fs": {
|
|
29
29
|
"types": "./src/fs/index.ts",
|
|
30
30
|
"default": "./src/fs/index.ts"
|
|
31
|
+
},
|
|
32
|
+
"./platforms": {
|
|
33
|
+
"types": "./src/platforms/index.ts",
|
|
34
|
+
"default": "./src/platforms/index.ts"
|
|
31
35
|
}
|
|
32
36
|
},
|
|
33
37
|
"main": "./src/index.ts",
|
|
@@ -46,6 +50,10 @@
|
|
|
46
50
|
"./fs": {
|
|
47
51
|
"types": "./dist/fs/index.d.ts",
|
|
48
52
|
"import": "./dist/fs/index.js"
|
|
53
|
+
},
|
|
54
|
+
"./platforms": {
|
|
55
|
+
"types": "./dist/platforms/index.d.ts",
|
|
56
|
+
"import": "./dist/platforms/index.js"
|
|
49
57
|
}
|
|
50
58
|
},
|
|
51
59
|
"main": "./dist/index.js",
|