@weapp-vite/web 1.3.16 → 1.3.17
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/README.md +2 -2
- package/dist/compiler/wxml/attributes.mjs +6 -6
- package/dist/compiler/wxml/attributes.mjs.map +1 -1
- package/dist/compiler/wxml/renderer.mjs +6 -6
- package/dist/compiler/wxml/renderer.mjs.map +1 -1
- package/dist/compiler/wxml/specialNodes.mjs +6 -5
- package/dist/compiler/wxml/specialNodes.mjs.map +1 -1
- package/dist/plugin/files.mjs +1 -1
- package/dist/plugin/files.mjs.map +1 -1
- package/dist/runtime/component/constants.mjs +7 -2
- package/dist/runtime/component/constants.mjs.map +1 -1
- package/dist/runtime/component/dom.mjs +9 -3
- package/dist/runtime/component/dom.mjs.map +1 -1
- package/dist/runtime/component/events.mjs +5 -4
- package/dist/runtime/component/events.mjs.map +1 -1
- package/dist/runtime/legacyTemplate/dom.mjs +10 -65
- package/dist/runtime/legacyTemplate/dom.mjs.map +1 -1
- package/dist/runtime/legacyTemplate/index.mjs +7 -6
- package/dist/runtime/legacyTemplate/index.mjs.map +1 -1
- package/dist/runtime/polyfill/async.mjs +3 -3
- package/dist/runtime/polyfill/async.mjs.map +1 -1
- package/dist/runtime/polyfill/authApi.mjs +16 -16
- package/dist/runtime/polyfill/authApi.mjs.map +1 -1
- package/dist/runtime/polyfill/background.mjs +4 -4
- package/dist/runtime/polyfill/background.mjs.map +1 -1
- package/dist/runtime/polyfill/capability.mjs +6 -3
- package/dist/runtime/polyfill/capability.mjs.map +1 -1
- package/dist/runtime/polyfill/cloud.mjs +3 -3
- package/dist/runtime/polyfill/cloud.mjs.map +1 -1
- package/dist/runtime/polyfill/deviceApi.mjs +5 -5
- package/dist/runtime/polyfill/deviceApi.mjs.map +1 -1
- package/dist/runtime/polyfill/deviceAuthSystemApi.d.mts +2 -2
- package/dist/runtime/polyfill/deviceAuthSystemApi.mjs.map +1 -1
- package/dist/runtime/polyfill/fileSystemManager.mjs +7 -7
- package/dist/runtime/polyfill/fileSystemManager.mjs.map +1 -1
- package/dist/runtime/polyfill/index.mjs +21 -10
- package/dist/runtime/polyfill/index.mjs.map +1 -1
- package/dist/runtime/polyfill/interactionApi.mjs +8 -8
- package/dist/runtime/polyfill/interactionApi.mjs.map +1 -1
- package/dist/runtime/polyfill/locationApi.mjs +21 -21
- package/dist/runtime/polyfill/locationApi.mjs.map +1 -1
- package/dist/runtime/polyfill/mediaApi/file.mjs +12 -12
- package/dist/runtime/polyfill/mediaApi/file.mjs.map +1 -1
- package/dist/runtime/polyfill/mediaApi/info.mjs +7 -7
- package/dist/runtime/polyfill/mediaApi/info.mjs.map +1 -1
- package/dist/runtime/polyfill/mediaApi/picker.mjs +11 -11
- package/dist/runtime/polyfill/mediaApi/picker.mjs.map +1 -1
- package/dist/runtime/polyfill/mediaApi/preview.mjs +7 -7
- package/dist/runtime/polyfill/mediaApi/preview.mjs.map +1 -1
- package/dist/runtime/polyfill/mediaApi/process.mjs +6 -6
- package/dist/runtime/polyfill/mediaApi/process.mjs.map +1 -1
- package/dist/runtime/polyfill/menuApi.mjs +13 -13
- package/dist/runtime/polyfill/menuApi.mjs.map +1 -1
- package/dist/runtime/polyfill/navigationBarRuntime.mjs +5 -4
- package/dist/runtime/polyfill/navigationBarRuntime.mjs.map +1 -1
- package/dist/runtime/polyfill/network/requestBridge.mjs +7 -7
- package/dist/runtime/polyfill/network/requestBridge.mjs.map +1 -1
- package/dist/runtime/polyfill/platformApi.mjs +2 -2
- package/dist/runtime/polyfill/platformApi.mjs.map +1 -1
- package/dist/runtime/polyfill/runtimeCapabilityApi.mjs +2 -2
- package/dist/runtime/polyfill/runtimeCapabilityApi.mjs.map +1 -1
- package/dist/runtime/polyfill/runtimeDataApi.d.mts +7 -7
- package/dist/runtime/polyfill/runtimeDataApi.mjs +5 -5
- package/dist/runtime/polyfill/runtimeDataApi.mjs.map +1 -1
- package/dist/runtime/polyfill/runtimeOps.mjs +10 -10
- package/dist/runtime/polyfill/runtimeOps.mjs.map +1 -1
- package/dist/runtime/polyfill/storageAsync.mjs +12 -12
- package/dist/runtime/polyfill/storageAsync.mjs.map +1 -1
- package/dist/runtime/polyfill/systemApi.mjs +3 -3
- package/dist/runtime/polyfill/systemApi.mjs.map +1 -1
- package/dist/runtime/polyfill/types/base.d.mts +5 -5
- package/dist/runtime/polyfill/types/common.d.mts +22 -22
- package/dist/runtime/polyfill/types/locationRuntime.d.mts +27 -27
- package/dist/runtime/polyfill/types/mediaAuth.d.mts +30 -30
- package/dist/runtime/polyfill/types/platformRuntime.d.mts +13 -13
- package/dist/runtime/polyfill/types/systemAuth.d.mts +11 -11
- package/dist/runtime/polyfill/uiFeedback.mjs +4 -4
- package/dist/runtime/polyfill/uiFeedback.mjs.map +1 -1
- package/dist/runtime/polyfill/uiMediaApi.d.mts +2 -2
- package/dist/runtime/polyfill/uiMediaApi.mjs.map +1 -1
- package/dist/shared/wxml.mjs +29 -10
- package/dist/shared/wxml.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/runtime/legacyTemplate/index.ts"],"sourcesContent":["import type { ChildNode, DataNode, Element, Node } from 'domhandler'\nimport type {\n LegacyTemplateRenderer,\n LegacyTemplateScope,\n RenderOptions,\n} from './types'\nimport { parseDocument } from 'htmlparser2'\nimport {\n
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/runtime/legacyTemplate/index.ts"],"sourcesContent":["import type { ChildNode, DataNode, Element, Node } from 'domhandler'\nimport type {\n LegacyTemplateRenderer,\n LegacyTemplateScope,\n RenderOptions,\n} from './types'\nimport { parseDocument } from 'htmlparser2'\nimport {\n hasControlAttribute,\n normalizeTagName,\n resolveControlAttributeValue,\n SELF_CLOSING_TAGS,\n} from '../../shared/wxml'\nimport {\n buildAttributeString,\n extractFor,\n isConditionalElement,\n stripControlAttributes,\n} from './dom'\nimport {\n createChildScope,\n createScope,\n evaluateExpression,\n interpolateText,\n normalizeList,\n} from './expression'\n\nconst templateCache = new Map<string, ChildNode[]>()\n\nfunction filterRenderableNode(node: Node) {\n if (node.type === 'directive' || node.type === 'comment') {\n return false\n }\n if (node.type === 'text') {\n const data = (node as DataNode).data ?? ''\n return data.trim().length > 0\n }\n return true\n}\n\nfunction getOrParseTemplate(source: string) {\n let cached = templateCache.get(source)\n if (!cached) {\n const document = parseDocument(source, {\n xmlMode: true,\n decodeEntities: true,\n recognizeSelfClosing: true,\n })\n cached = (document.children ?? []).filter(filterRenderableNode)\n templateCache.set(source, cached)\n }\n return cached\n}\n\nfunction renderConditionalSequence(\n nodes: ChildNode[],\n startIndex: number,\n scope: LegacyTemplateScope,\n renderChildren: (input: ChildNode[] | ChildNode | undefined, scope: LegacyTemplateScope) => string,\n) {\n const branches: Array<{ node: Element, attribs: Record<string, string> }> = []\n let cursor = startIndex\n\n while (cursor < nodes.length) {\n const candidate = nodes[cursor]\n if (!isConditionalElement(candidate)) {\n break\n }\n const element = candidate as Element\n const attribs = element.attribs ?? {}\n if (branches.length === 0 && !hasControlAttribute(attribs, 'if')) {\n break\n }\n if (branches.length > 0 && !hasControlAttribute(attribs, 'elif') && !hasControlAttribute(attribs, 'else')) {\n break\n }\n branches.push({ node: element, attribs })\n cursor += 1\n if (hasControlAttribute(attribs, 'else')) {\n break\n }\n }\n\n if (!branches.length) {\n const node = nodes[startIndex]\n return {\n rendered: renderChildren(node, scope),\n endIndex: startIndex,\n }\n }\n\n for (const { node, attribs } of branches) {\n if (hasControlAttribute(attribs, 'else')) {\n return {\n // eslint-disable-next-line ts/no-use-before-define -- 条件分支与普通节点复用同一元素渲染逻辑。\n rendered: renderElement(\n node,\n scope,\n renderChildren,\n { overrideAttribs: stripControlAttributes(attribs) },\n ),\n endIndex: startIndex + branches.length - 1,\n }\n }\n const conditionExpr = resolveControlAttributeValue(attribs, 'if')\n ?? resolveControlAttributeValue(attribs, 'elif')\n if (!conditionExpr) {\n continue\n }\n const condition = evaluateExpression(conditionExpr, scope)\n if (condition) {\n return {\n // eslint-disable-next-line ts/no-use-before-define -- 条件分支与普通节点复用同一元素渲染逻辑。\n rendered: renderElement(\n node,\n scope,\n renderChildren,\n { overrideAttribs: stripControlAttributes(attribs) },\n ),\n endIndex: startIndex + branches.length - 1,\n }\n }\n }\n\n return {\n rendered: '',\n endIndex: startIndex + branches.length - 1,\n }\n}\n\nfunction renderElement(\n node: Element,\n scope: LegacyTemplateScope,\n renderChildren: (nodes: ChildNode[] | undefined, scope: LegacyTemplateScope) => string,\n options: RenderOptions = {},\n) {\n const attribs = node.attribs ?? {}\n if (!options.skipFor) {\n const forExtract = extractFor(attribs)\n if (forExtract.expr) {\n const list = normalizeList(evaluateExpression(forExtract.expr, scope))\n if (!list.length) {\n return ''\n }\n let buffer = ''\n for (let idx = 0; idx < list.length; idx++) {\n const item = list[idx]\n const childScope = createChildScope(scope)\n childScope[forExtract.itemName] = item\n childScope[forExtract.indexName] = idx\n buffer += renderElement(node, childScope, renderChildren, {\n skipFor: true,\n overrideAttribs: forExtract.restAttribs,\n })\n }\n return buffer\n }\n }\n\n const effectiveAttribs = options.overrideAttribs ?? attribs\n const normalizedTag = normalizeTagName(node.name)\n if (normalizedTag === '#fragment') {\n return renderChildren(node.children, scope)\n }\n\n const attrs = buildAttributeString(effectiveAttribs, scope)\n const children = renderChildren(node.children, scope)\n\n if (SELF_CLOSING_TAGS.has(normalizedTag) && !children) {\n return `<${normalizedTag}${attrs} />`\n }\n\n return `<${normalizedTag}${attrs}>${children}</${normalizedTag}>`\n}\n\nfunction renderTextNode(node: DataNode, scope: LegacyTemplateScope) {\n const value = node.data ?? ''\n if (!value.trim()) {\n return ''\n }\n return interpolateText(value, scope, true)\n}\n\nfunction renderTree(\n input: ChildNode[] | ChildNode | undefined,\n scope: LegacyTemplateScope,\n): string {\n if (!input) {\n return ''\n }\n\n if (Array.isArray(input)) {\n let buffer = ''\n for (let index = 0; index < input.length; index++) {\n const node = input[index]\n if (isConditionalElement(node)) {\n const { rendered, endIndex } = renderConditionalSequence(input, index, scope, renderTree)\n buffer += rendered\n index = endIndex\n continue\n }\n buffer += renderTree(node, scope)\n }\n return buffer\n }\n\n const node = input\n if (node.type === 'text') {\n return renderTextNode(node as DataNode, scope)\n }\n if (node.type === 'tag' || node.type === 'script' || node.type === 'style') {\n return renderElement(node as Element, scope, renderTree)\n }\n if ('children' in node && node.children?.length) {\n return renderTree(node.children, scope)\n }\n return ''\n}\n\nexport function renderTemplate(nodes: ChildNode[], scope?: LegacyTemplateScope) {\n const renderScope = createScope(scope)\n return renderTree(nodes, renderScope)\n}\n\nexport function createTemplate(source: string): LegacyTemplateRenderer {\n const nodes = getOrParseTemplate(source)\n return (scope?: LegacyTemplateScope) => renderTemplate(nodes, scope)\n}\n\nexport type { LegacyTemplateRenderer, LegacyTemplateScope } from './types'\n"],"mappings":";;;;;;AA2BA,MAAM,gCAAgB,IAAI,KAA0B;AAEpD,SAAS,qBAAqB,MAAY;AACxC,KAAI,KAAK,SAAS,eAAe,KAAK,SAAS,UAC7C,QAAO;AAET,KAAI,KAAK,SAAS,OAEhB,SADc,KAAkB,QAAQ,IAC5B,MAAM,CAAC,SAAS;AAE9B,QAAO;;AAGT,SAAS,mBAAmB,QAAgB;CAC1C,IAAI,SAAS,cAAc,IAAI,OAAO;AACtC,KAAI,CAAC,QAAQ;AAMX,YALiB,cAAc,QAAQ;GACrC,SAAS;GACT,gBAAgB;GAChB,sBAAsB;GACvB,CAAC,CACiB,YAAY,EAAE,EAAE,OAAO,qBAAqB;AAC/D,gBAAc,IAAI,QAAQ,OAAO;;AAEnC,QAAO;;AAGT,SAAS,0BACP,OACA,YACA,OACA,gBACA;CACA,MAAM,WAAsE,EAAE;CAC9E,IAAI,SAAS;AAEb,QAAO,SAAS,MAAM,QAAQ;EAC5B,MAAM,YAAY,MAAM;AACxB,MAAI,CAAC,qBAAqB,UAAU,CAClC;EAEF,MAAM,UAAU;EAChB,MAAM,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Ac,MAAiB,OAAO,WAAW;AAE1D,KAAI,cAAc,QAAQ,KAAK,UAAU,OACvC,QAAO,WAAW,KAAK,UAAU,MAAM;AAEzC,QAAO;;AAGT,SAAgB,eAAe,OAAoB,OAA6B;AAE9E,QAAO,WAAW,OADE,YAAY,MAAM,CACD;;AAGvC,SAAgB,eAAe,QAAwC;CACrE,MAAM,QAAQ,mBAAmB,OAAO;AACxC,SAAQ,UAAgC,eAAe,OAAO,MAAM"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
//#region src/runtime/polyfill/async.ts
|
|
2
|
-
function
|
|
2
|
+
function callMiniProgramAsyncSuccess(options, result) {
|
|
3
3
|
options?.success?.(result);
|
|
4
4
|
options?.complete?.(result);
|
|
5
5
|
return result;
|
|
6
6
|
}
|
|
7
|
-
function
|
|
7
|
+
function callMiniProgramAsyncFailure(options, errMsg) {
|
|
8
8
|
const result = { errMsg };
|
|
9
9
|
options?.fail?.(result);
|
|
10
10
|
options?.complete?.(result);
|
|
@@ -27,5 +27,5 @@ function scheduleMicrotask(task) {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
//#endregion
|
|
30
|
-
export {
|
|
30
|
+
export { callMiniProgramAsyncFailure, callMiniProgramAsyncSuccess, normalizeDuration, scheduleMicrotask };
|
|
31
31
|
//# sourceMappingURL=async.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async.mjs","names":[],"sources":["../../../src/runtime/polyfill/async.ts"],"sourcesContent":["interface
|
|
1
|
+
{"version":3,"file":"async.mjs","names":[],"sources":["../../../src/runtime/polyfill/async.ts"],"sourcesContent":["interface MiniProgramBaseResultLike {\n errMsg: string\n}\n\ninterface MiniProgramAsyncOptionsLike<SuccessResult extends MiniProgramBaseResultLike> {\n success?: (result: SuccessResult) => void\n fail?: (result: MiniProgramBaseResultLike) => void\n complete?: (result: SuccessResult | MiniProgramBaseResultLike) => void\n}\n\nexport function callMiniProgramAsyncSuccess<SuccessResult extends MiniProgramBaseResultLike>(\n options: MiniProgramAsyncOptionsLike<SuccessResult> | undefined,\n result: SuccessResult,\n) {\n options?.success?.(result)\n options?.complete?.(result)\n return result\n}\n\nexport function callMiniProgramAsyncFailure<SuccessResult extends MiniProgramBaseResultLike>(\n options: MiniProgramAsyncOptionsLike<SuccessResult> | undefined,\n errMsg: string,\n) {\n const result: MiniProgramBaseResultLike = { errMsg }\n options?.fail?.(result)\n options?.complete?.(result)\n return result\n}\n\nexport const callWxAsyncSuccess = callMiniProgramAsyncSuccess\nexport const callWxAsyncFailure = callMiniProgramAsyncFailure\n\nexport function normalizeDuration(duration: number | undefined, fallback: number) {\n if (typeof duration !== 'number' || Number.isNaN(duration)) {\n return fallback\n }\n return Math.max(0, duration)\n}\n\nexport function scheduleMicrotask(task: () => void) {\n if (typeof queueMicrotask === 'function') {\n queueMicrotask(task)\n return\n }\n Promise.resolve()\n .then(task)\n .catch((error) => {\n setTimeout(() => {\n throw error\n }, 0)\n })\n}\n"],"mappings":";AAUA,SAAgB,4BACd,SACA,QACA;AACA,UAAS,UAAU,OAAO;AAC1B,UAAS,WAAW,OAAO;AAC3B,QAAO;;AAGT,SAAgB,4BACd,SACA,QACA;CACA,MAAM,SAAoC,EAAE,QAAQ;AACpD,UAAS,OAAO,OAAO;AACvB,UAAS,WAAW,OAAO;AAC3B,QAAO;;AAMT,SAAgB,kBAAkB,UAA8B,UAAkB;AAChF,KAAI,OAAO,aAAa,YAAY,OAAO,MAAM,SAAS,CACxD,QAAO;AAET,QAAO,KAAK,IAAI,GAAG,SAAS;;AAG9B,SAAgB,kBAAkB,MAAkB;AAClD,KAAI,OAAO,mBAAmB,YAAY;AACxC,iBAAe,KAAK;AACpB;;AAEF,SAAQ,SAAS,CACd,KAAK,KAAK,CACV,OAAO,UAAU;AAChB,mBAAiB;AACf,SAAM;KACL,EAAE;GACL"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { callMiniProgramAsyncFailure, callMiniProgramAsyncSuccess } from "./async.mjs";
|
|
2
2
|
import { buildAuthSettingSnapshot, buildUserProfilePayload, generateLoginCode, normalizeAuthScope, resolveAuthorizeDecision, resolveCheckSessionState, resolveUserProfileDecision, syncOpenAppAuthorizeSettingPreset, syncOpenSettingPreset } from "./auth.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/runtime/polyfill/authApi.ts
|
|
5
5
|
function getSettingBridge(options, authState) {
|
|
6
|
-
return Promise.resolve(
|
|
6
|
+
return Promise.resolve(callMiniProgramAsyncSuccess(options, {
|
|
7
7
|
errMsg: "getSetting:ok",
|
|
8
8
|
authSetting: buildAuthSettingSnapshot(authState)
|
|
9
9
|
}));
|
|
@@ -11,31 +11,31 @@ function getSettingBridge(options, authState) {
|
|
|
11
11
|
function authorizeBridge(options, authState, supportedScopes) {
|
|
12
12
|
const scope = normalizeAuthScope(options?.scope);
|
|
13
13
|
if (!scope) {
|
|
14
|
-
const failure =
|
|
14
|
+
const failure = callMiniProgramAsyncFailure(options, "authorize:fail invalid scope");
|
|
15
15
|
return Promise.reject(failure);
|
|
16
16
|
}
|
|
17
17
|
if (!supportedScopes.has(scope)) {
|
|
18
|
-
const failure =
|
|
18
|
+
const failure = callMiniProgramAsyncFailure(options, "authorize:fail unsupported scope");
|
|
19
19
|
return Promise.reject(failure);
|
|
20
20
|
}
|
|
21
21
|
const decision = resolveAuthorizeDecision(scope);
|
|
22
22
|
authState.set(scope, decision);
|
|
23
23
|
if (decision !== "authorized") {
|
|
24
|
-
const failure =
|
|
24
|
+
const failure = callMiniProgramAsyncFailure(options, `authorize:fail ${decision === "denied" ? "auth deny" : "auth canceled"}`);
|
|
25
25
|
return Promise.reject(failure);
|
|
26
26
|
}
|
|
27
|
-
return Promise.resolve(
|
|
27
|
+
return Promise.resolve(callMiniProgramAsyncSuccess(options, { errMsg: "authorize:ok" }));
|
|
28
28
|
}
|
|
29
29
|
function openSettingBridge(options, authState, supportedScopes) {
|
|
30
30
|
syncOpenSettingPreset(authState, supportedScopes);
|
|
31
|
-
return Promise.resolve(
|
|
31
|
+
return Promise.resolve(callMiniProgramAsyncSuccess(options, {
|
|
32
32
|
errMsg: "openSetting:ok",
|
|
33
33
|
authSetting: buildAuthSettingSnapshot(authState)
|
|
34
34
|
}));
|
|
35
35
|
}
|
|
36
36
|
function openAppAuthorizeSettingBridge(options, authState, scopeMap, resolveAppAuthorizeSetting) {
|
|
37
37
|
syncOpenAppAuthorizeSettingPreset(authState, scopeMap);
|
|
38
|
-
return Promise.resolve(
|
|
38
|
+
return Promise.resolve(callMiniProgramAsyncSuccess(options, {
|
|
39
39
|
errMsg: "openAppAuthorizeSetting:ok",
|
|
40
40
|
...resolveAppAuthorizeSetting()
|
|
41
41
|
}));
|
|
@@ -62,38 +62,38 @@ function getAppAuthorizeSettingBridge(authState) {
|
|
|
62
62
|
};
|
|
63
63
|
}
|
|
64
64
|
function loginBridge(options) {
|
|
65
|
-
return Promise.resolve(
|
|
65
|
+
return Promise.resolve(callMiniProgramAsyncSuccess(options, {
|
|
66
66
|
errMsg: "login:ok",
|
|
67
67
|
code: generateLoginCode()
|
|
68
68
|
}));
|
|
69
69
|
}
|
|
70
70
|
function checkSessionBridge(options) {
|
|
71
71
|
if (!resolveCheckSessionState()) {
|
|
72
|
-
const failure =
|
|
72
|
+
const failure = callMiniProgramAsyncFailure(options, "checkSession:fail session expired");
|
|
73
73
|
return Promise.reject(failure);
|
|
74
74
|
}
|
|
75
|
-
return Promise.resolve(
|
|
75
|
+
return Promise.resolve(callMiniProgramAsyncSuccess(options, { errMsg: "checkSession:ok" }));
|
|
76
76
|
}
|
|
77
77
|
function getUserInfoBridge(options, authState) {
|
|
78
78
|
if (authState.get("scope.userInfo") === "denied") {
|
|
79
|
-
const failure =
|
|
79
|
+
const failure = callMiniProgramAsyncFailure(options, "getUserInfo:fail auth deny");
|
|
80
80
|
return Promise.reject(failure);
|
|
81
81
|
}
|
|
82
82
|
authState.set("scope.userInfo", "authorized");
|
|
83
|
-
return Promise.resolve(
|
|
83
|
+
return Promise.resolve(callMiniProgramAsyncSuccess(options, buildUserProfilePayload("getUserInfo:ok", options?.lang)));
|
|
84
84
|
}
|
|
85
85
|
function getUserProfileBridge(options, authState) {
|
|
86
86
|
if (!(typeof options?.desc === "string" ? options.desc.trim() : "")) {
|
|
87
|
-
const failure =
|
|
87
|
+
const failure = callMiniProgramAsyncFailure(options, "getUserProfile:fail invalid desc");
|
|
88
88
|
return Promise.reject(failure);
|
|
89
89
|
}
|
|
90
90
|
const decision = resolveUserProfileDecision();
|
|
91
91
|
authState.set("scope.userInfo", decision);
|
|
92
92
|
if (decision !== "authorized") {
|
|
93
|
-
const failure =
|
|
93
|
+
const failure = callMiniProgramAsyncFailure(options, `getUserProfile:fail ${decision === "denied" ? "auth deny" : "auth canceled"}`);
|
|
94
94
|
return Promise.reject(failure);
|
|
95
95
|
}
|
|
96
|
-
return Promise.resolve(
|
|
96
|
+
return Promise.resolve(callMiniProgramAsyncSuccess(options, buildUserProfilePayload("getUserProfile:ok", options?.lang)));
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authApi.mjs","names":[],"sources":["../../../src/runtime/polyfill/authApi.ts"],"sourcesContent":["import type { AppAuthorizeStatusLike } from './auth'\nimport {\n
|
|
1
|
+
{"version":3,"file":"authApi.mjs","names":[],"sources":["../../../src/runtime/polyfill/authApi.ts"],"sourcesContent":["import type { AppAuthorizeStatusLike } from './auth'\nimport {\n callMiniProgramAsyncFailure,\n callMiniProgramAsyncSuccess,\n} from './async'\nimport {\n buildAuthSettingSnapshot,\n buildUserProfilePayload,\n generateLoginCode,\n normalizeAuthScope,\n resolveAuthorizeDecision,\n resolveCheckSessionState,\n resolveUserProfileDecision,\n syncOpenAppAuthorizeSettingPreset,\n syncOpenSettingPreset,\n} from './auth'\n\ntype AuthState = Map<string, AppAuthorizeStatusLike>\n\nexport function getSettingBridge(options: any, authState: AuthState) {\n return Promise.resolve(callMiniProgramAsyncSuccess(options, {\n errMsg: 'getSetting:ok',\n authSetting: buildAuthSettingSnapshot(authState),\n }))\n}\n\nexport function authorizeBridge(options: any, authState: AuthState, supportedScopes: Set<string>) {\n const scope = normalizeAuthScope(options?.scope)\n if (!scope) {\n const failure = callMiniProgramAsyncFailure(options, 'authorize:fail invalid scope')\n return Promise.reject(failure)\n }\n if (!supportedScopes.has(scope)) {\n const failure = callMiniProgramAsyncFailure(options, 'authorize:fail unsupported scope')\n return Promise.reject(failure)\n }\n const decision = resolveAuthorizeDecision(scope)\n authState.set(scope, decision)\n if (decision !== 'authorized') {\n const reason = decision === 'denied' ? 'auth deny' : 'auth canceled'\n const failure = callMiniProgramAsyncFailure(options, `authorize:fail ${reason}`)\n return Promise.reject(failure)\n }\n return Promise.resolve(callMiniProgramAsyncSuccess(options, { errMsg: 'authorize:ok' }))\n}\n\nexport function openSettingBridge(options: any, authState: AuthState, supportedScopes: Set<string>) {\n syncOpenSettingPreset(authState, supportedScopes)\n return Promise.resolve(callMiniProgramAsyncSuccess(options, {\n errMsg: 'openSetting:ok',\n authSetting: buildAuthSettingSnapshot(authState),\n }))\n}\n\nexport function openAppAuthorizeSettingBridge(\n options: any,\n authState: AuthState,\n scopeMap: Record<string, string>,\n resolveAppAuthorizeSetting: () => object,\n) {\n syncOpenAppAuthorizeSettingPreset(authState, scopeMap)\n return Promise.resolve(callMiniProgramAsyncSuccess(options, {\n errMsg: 'openAppAuthorizeSetting:ok',\n ...resolveAppAuthorizeSetting(),\n }))\n}\n\nexport function getSystemSettingBridge(authState: AuthState, resolveOrientation: () => 'portrait' | 'landscape') {\n const locationAuthorized = authState.get('scope.userLocation') === 'authorized'\n return {\n bluetoothEnabled: false,\n wifiEnabled: true,\n locationEnabled: locationAuthorized,\n locationReducedAccuracy: false,\n deviceOrientation: resolveOrientation(),\n }\n}\n\nexport function getAppAuthorizeSettingBridge(authState: AuthState) {\n const resolveStatus = (scope: string) => authState.get(scope) ?? 'not determined'\n return {\n albumAuthorized: resolveStatus('scope.writePhotosAlbum'),\n bluetoothAuthorized: 'not determined',\n cameraAuthorized: resolveStatus('scope.camera'),\n locationAuthorized: resolveStatus('scope.userLocation'),\n microphoneAuthorized: resolveStatus('scope.record'),\n notificationAuthorized: 'not determined',\n phoneCalendarAuthorized: 'not determined',\n }\n}\n\nexport function loginBridge(options: any) {\n return Promise.resolve(callMiniProgramAsyncSuccess(options, {\n errMsg: 'login:ok',\n code: generateLoginCode(),\n }))\n}\n\nexport function checkSessionBridge(options: any) {\n if (!resolveCheckSessionState()) {\n const failure = callMiniProgramAsyncFailure(options, 'checkSession:fail session expired')\n return Promise.reject(failure)\n }\n return Promise.resolve(callMiniProgramAsyncSuccess(options, { errMsg: 'checkSession:ok' }))\n}\n\nexport function getUserInfoBridge(options: any, authState: AuthState) {\n if (authState.get('scope.userInfo') === 'denied') {\n const failure = callMiniProgramAsyncFailure(options, 'getUserInfo:fail auth deny')\n return Promise.reject(failure)\n }\n authState.set('scope.userInfo', 'authorized')\n return Promise.resolve(callMiniProgramAsyncSuccess(options, buildUserProfilePayload('getUserInfo:ok', options?.lang)))\n}\n\nexport function getUserProfileBridge(options: any, authState: AuthState) {\n const desc = typeof options?.desc === 'string' ? options.desc.trim() : ''\n if (!desc) {\n const failure = callMiniProgramAsyncFailure(options, 'getUserProfile:fail invalid desc')\n return Promise.reject(failure)\n }\n const decision = resolveUserProfileDecision()\n authState.set('scope.userInfo', decision)\n if (decision !== 'authorized') {\n const reason = decision === 'denied' ? 'auth deny' : 'auth canceled'\n const failure = callMiniProgramAsyncFailure(options, `getUserProfile:fail ${reason}`)\n return Promise.reject(failure)\n }\n return Promise.resolve(callMiniProgramAsyncSuccess(options, buildUserProfilePayload('getUserProfile:ok', options?.lang)))\n}\n"],"mappings":";;;;AAmBA,SAAgB,iBAAiB,SAAc,WAAsB;AACnE,QAAO,QAAQ,QAAQ,4BAA4B,SAAS;EAC1D,QAAQ;EACR,aAAa,yBAAyB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MiniProgramAsyncFailure, callMiniProgramAsyncSuccess } from "./async.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/runtime/polyfill/background.ts
|
|
4
4
|
function normalizeBackgroundColorValue(color) {
|
|
@@ -14,16 +14,16 @@ function setBackgroundColorBridge(options) {
|
|
|
14
14
|
const body = runtimeDocument?.body;
|
|
15
15
|
if (body && backgroundColor) body.style.backgroundColor = backgroundColor;
|
|
16
16
|
if (rootElement && backgroundColorTop && backgroundColorBottom) rootElement.style.setProperty("--weapp-web-background-gradient", `linear-gradient(${backgroundColorTop}, ${backgroundColorBottom})`);
|
|
17
|
-
return Promise.resolve(
|
|
17
|
+
return Promise.resolve(callMiniProgramAsyncSuccess(options, { errMsg: "setBackgroundColor:ok" }));
|
|
18
18
|
}
|
|
19
19
|
function setBackgroundTextStyleBridge(options) {
|
|
20
20
|
const textStyle = options?.textStyle;
|
|
21
21
|
if (textStyle !== void 0 && textStyle !== "dark" && textStyle !== "light") {
|
|
22
|
-
const failure =
|
|
22
|
+
const failure = callMiniProgramAsyncFailure(options, "setBackgroundTextStyle:fail invalid textStyle");
|
|
23
23
|
return Promise.reject(failure);
|
|
24
24
|
}
|
|
25
25
|
if (typeof document !== "undefined" && document.documentElement && textStyle) document.documentElement.setAttribute("data-weapp-background-text-style", textStyle);
|
|
26
|
-
return Promise.resolve(
|
|
26
|
+
return Promise.resolve(callMiniProgramAsyncSuccess(options, { errMsg: "setBackgroundTextStyle:ok" }));
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"background.mjs","names":[],"sources":["../../../src/runtime/polyfill/background.ts"],"sourcesContent":["import type { SetBackgroundColorOptions, SetBackgroundTextStyleOptions } from './types/locationRuntime'\nimport {\n
|
|
1
|
+
{"version":3,"file":"background.mjs","names":[],"sources":["../../../src/runtime/polyfill/background.ts"],"sourcesContent":["import type { SetBackgroundColorOptions, SetBackgroundTextStyleOptions } from './types/locationRuntime'\nimport {\n callMiniProgramAsyncFailure,\n callMiniProgramAsyncSuccess,\n} from './async'\n\nfunction normalizeBackgroundColorValue(color: unknown) {\n if (typeof color !== 'string') {\n return ''\n }\n return color.trim()\n}\n\nexport function setBackgroundColorBridge(options?: SetBackgroundColorOptions) {\n const backgroundColor = normalizeBackgroundColorValue(options?.backgroundColor)\n const backgroundColorTop = normalizeBackgroundColorValue(options?.backgroundColorTop)\n const backgroundColorBottom = normalizeBackgroundColorValue(options?.backgroundColorBottom)\n const runtimeDocument = typeof document !== 'undefined' ? document : undefined\n const rootElement = runtimeDocument?.documentElement\n const body = runtimeDocument?.body\n\n if (body && backgroundColor) {\n body.style.backgroundColor = backgroundColor\n }\n if (rootElement && backgroundColorTop && backgroundColorBottom) {\n rootElement.style.setProperty(\n '--weapp-web-background-gradient',\n `linear-gradient(${backgroundColorTop}, ${backgroundColorBottom})`,\n )\n }\n return Promise.resolve(callMiniProgramAsyncSuccess(options, { errMsg: 'setBackgroundColor:ok' }))\n}\n\nexport function setBackgroundTextStyleBridge(options?: SetBackgroundTextStyleOptions) {\n const textStyle = options?.textStyle\n if (textStyle !== undefined && textStyle !== 'dark' && textStyle !== 'light') {\n const failure = callMiniProgramAsyncFailure(options, 'setBackgroundTextStyle:fail invalid textStyle')\n return Promise.reject(failure)\n }\n if (typeof document !== 'undefined' && document.documentElement && textStyle) {\n document.documentElement.setAttribute('data-weapp-background-text-style', textStyle)\n }\n return Promise.resolve(callMiniProgramAsyncSuccess(options, { errMsg: 'setBackgroundTextStyle:ok' }))\n}\n"],"mappings":";;;AAMA,SAAS,8BAA8B,OAAgB;AACrD,KAAI,OAAO,UAAU,SACnB,QAAO;AAET,QAAO,MAAM,MAAM;;AAGrB,SAAgB,yBAAyB,SAAqC;CAC5E,MAAM,kBAAkB,8BAA8B,SAAS,gBAAgB;CAC/E,MAAM,qBAAqB,8BAA8B,SAAS,mBAAmB;CACrF,MAAM,wBAAwB,8BAA8B,SAAS,sBAAsB;CAC3F,MAAM,kBAAkB,OAAO,aAAa,cAAc,WAAW;CACrE,MAAM,cAAc,iBAAiB;CACrC,MAAM,OAAO,iBAAiB;AAE9B,KAAI,QAAQ,gBACV,MAAK,MAAM,kBAAkB;AAE/B,KAAI,eAAe,sBAAsB,sBACvC,aAAY,MAAM,YAChB,mCACA,mBAAmB,mBAAmB,IAAI,sBAAsB,GACjE;AAEH,QAAO,QAAQ,QAAQ,4BAA4B,SAAS,EAAE,QAAQ,yBAAyB,CAAC,CAAC;;AAGnG,SAAgB,6BAA6B,SAAyC;CACpF,MAAM,YAAY,SAAS;AAC3B,KAAI,cAAc,UAAa,cAAc,UAAU,cAAc,SAAS;EAC5E,MAAM,UAAU,4BAA4B,SAAS,gDAAgD;AACrG,SAAO,QAAQ,OAAO,QAAQ;;AAEhC,KAAI,OAAO,aAAa,eAAe,SAAS,mBAAmB,UACjE,UAAS,gBAAgB,aAAa,oCAAoC,UAAU;AAEtF,QAAO,QAAQ,QAAQ,4BAA4B,SAAS,EAAE,QAAQ,6BAA6B,CAAC,CAAC"}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
import { getMiniProgramRuntimeGlobalKeys } from "@weapp-core/shared";
|
|
2
|
+
|
|
1
3
|
//#region src/runtime/polyfill/capability.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
+
const MINI_PROGRAM_CAPABILITY_SCHEMA_PREFIX_RE = new RegExp(`^(?:${getMiniProgramRuntimeGlobalKeys().join("|")})\\.`);
|
|
5
|
+
function checkRuntimeCapability(miniProgramBridge, schema) {
|
|
6
|
+
const normalized = String(schema ?? "").trim().replace(MINI_PROGRAM_CAPABILITY_SCHEMA_PREFIX_RE, "");
|
|
4
7
|
if (!normalized) return false;
|
|
5
8
|
const path = normalized.split(/[.[\]]/g).filter(Boolean);
|
|
6
9
|
if (!path.length) return false;
|
|
7
|
-
let cursor =
|
|
10
|
+
let cursor = miniProgramBridge;
|
|
8
11
|
for (const segment of path) {
|
|
9
12
|
if (!cursor || typeof cursor !== "object") return false;
|
|
10
13
|
cursor = cursor[segment];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capability.mjs","names":[],"sources":["../../../src/runtime/polyfill/capability.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"capability.mjs","names":[],"sources":["../../../src/runtime/polyfill/capability.ts"],"sourcesContent":["import { getMiniProgramRuntimeGlobalKeys } from '@weapp-core/shared'\n\nconst MINI_PROGRAM_CAPABILITY_SCHEMA_PREFIX_RE = new RegExp(`^(?:${getMiniProgramRuntimeGlobalKeys().join('|')})\\\\.`)\n\nexport function checkRuntimeCapability(\n miniProgramBridge: Record<string, unknown> | undefined,\n schema: string,\n) {\n const normalized = String(schema ?? '').trim().replace(MINI_PROGRAM_CAPABILITY_SCHEMA_PREFIX_RE, '')\n if (!normalized) {\n return false\n }\n const path = normalized.split(/[.[\\]]/g).filter(Boolean)\n if (!path.length) {\n return false\n }\n let cursor: unknown = miniProgramBridge\n for (const segment of path) {\n if (!cursor || typeof cursor !== 'object') {\n return false\n }\n cursor = (cursor as Record<string, unknown>)[segment]\n }\n return typeof cursor === 'function' || (typeof cursor === 'object' && cursor !== null)\n}\n"],"mappings":";;;AAEA,MAAM,2CAA2C,IAAI,OAAO,OAAO,iCAAiC,CAAC,KAAK,IAAI,CAAC,MAAM;AAErH,SAAgB,uBACd,mBACA,QACA;CACA,MAAM,aAAa,OAAO,UAAU,GAAG,CAAC,MAAM,CAAC,QAAQ,0CAA0C,GAAG;AACpG,KAAI,CAAC,WACH,QAAO;CAET,MAAM,OAAO,WAAW,MAAM,UAAU,CAAC,OAAO,QAAQ;AACxD,KAAI,CAAC,KAAK,OACR,QAAO;CAET,IAAI,SAAkB;AACtB,MAAK,MAAM,WAAW,MAAM;AAC1B,MAAI,CAAC,UAAU,OAAO,WAAW,SAC/B,QAAO;AAET,WAAU,OAAmC;;AAE/C,QAAO,OAAO,WAAW,cAAe,OAAO,WAAW,YAAY,WAAW"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
function createCloudRequestId() {
|
|
3
3
|
return `web_cloud_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`;
|
|
4
4
|
}
|
|
5
|
-
function createCloudBridge(
|
|
5
|
+
function createCloudBridge(callMiniProgramAsyncSuccess, callMiniProgramAsyncFailure) {
|
|
6
6
|
const cloudRuntimeState = {
|
|
7
7
|
env: "",
|
|
8
8
|
traceUser: false
|
|
@@ -15,10 +15,10 @@ function createCloudBridge(callWxAsyncSuccess, callWxAsyncFailure) {
|
|
|
15
15
|
callFunction(options) {
|
|
16
16
|
const name = typeof options?.name === "string" ? options.name.trim() : "";
|
|
17
17
|
if (!name) {
|
|
18
|
-
const failure =
|
|
18
|
+
const failure = callMiniProgramAsyncFailure(options, "cloud.callFunction:fail invalid function name");
|
|
19
19
|
return Promise.reject(failure);
|
|
20
20
|
}
|
|
21
|
-
const result =
|
|
21
|
+
const result = callMiniProgramAsyncSuccess(options, {
|
|
22
22
|
errMsg: "cloud.callFunction:ok",
|
|
23
23
|
result: {
|
|
24
24
|
name,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cloud.mjs","names":[],"sources":["../../../src/runtime/polyfill/cloud.ts"],"sourcesContent":["interface
|
|
1
|
+
{"version":3,"file":"cloud.mjs","names":[],"sources":["../../../src/runtime/polyfill/cloud.ts"],"sourcesContent":["interface MiniProgramBaseResult {\n errMsg: string\n}\n\ninterface CloudInitOptions {\n env?: string\n traceUser?: boolean\n}\n\ninterface CloudCallFunctionOptions {\n name?: string\n data?: Record<string, unknown>\n}\n\ninterface CloudBridge {\n init: (options?: CloudInitOptions) => void\n callFunction: (options?: CloudCallFunctionOptions) => Promise<unknown>\n}\n\ntype CallMiniProgramAsyncSuccess = (options: unknown, result: Record<string, unknown> & MiniProgramBaseResult) => unknown\ntype CallMiniProgramAsyncFailure = (options: unknown, errMsg: string) => MiniProgramBaseResult\n\nfunction createCloudRequestId() {\n return `web_cloud_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`\n}\n\nexport function createCloudBridge(\n callMiniProgramAsyncSuccess: CallMiniProgramAsyncSuccess,\n callMiniProgramAsyncFailure: CallMiniProgramAsyncFailure,\n): CloudBridge {\n const cloudRuntimeState = {\n env: '',\n traceUser: false,\n }\n return {\n init(options?: CloudInitOptions) {\n cloudRuntimeState.env = typeof options?.env === 'string' ? options.env : ''\n cloudRuntimeState.traceUser = Boolean(options?.traceUser)\n },\n callFunction(options?: CloudCallFunctionOptions) {\n const name = typeof options?.name === 'string' ? options.name.trim() : ''\n if (!name) {\n const failure = callMiniProgramAsyncFailure(options, 'cloud.callFunction:fail invalid function name')\n return Promise.reject(failure)\n }\n const result = callMiniProgramAsyncSuccess(options, {\n errMsg: 'cloud.callFunction:ok',\n result: {\n name,\n data: { ...(options?.data ?? {}) },\n env: cloudRuntimeState.env,\n traceUser: cloudRuntimeState.traceUser,\n mock: true,\n },\n requestID: createCloudRequestId(),\n })\n return Promise.resolve(result)\n },\n }\n}\n"],"mappings":";AAsBA,SAAS,uBAAuB;AAC9B,QAAO,aAAa,KAAK,KAAK,CAAC,SAAS,GAAG,CAAC,GAAG,KAAK,QAAQ,CAAC,SAAS,GAAG,CAAC,MAAM,GAAG,GAAG;;AAGxF,SAAgB,kBACd,6BACA,6BACa;CACb,MAAM,oBAAoB;EACxB,KAAK;EACL,WAAW;EACZ;AACD,QAAO;EACL,KAAK,SAA4B;AAC/B,qBAAkB,MAAM,OAAO,SAAS,QAAQ,WAAW,QAAQ,MAAM;AACzE,qBAAkB,YAAY,QAAQ,SAAS,UAAU;;EAE3D,aAAa,SAAoC;GAC/C,MAAM,OAAO,OAAO,SAAS,SAAS,WAAW,QAAQ,KAAK,MAAM,GAAG;AACvE,OAAI,CAAC,MAAM;IACT,MAAM,UAAU,4BAA4B,SAAS,gDAAgD;AACrG,WAAO,QAAQ,OAAO,QAAQ;;GAEhC,MAAM,SAAS,4BAA4B,SAAS;IAClD,QAAQ;IACR,QAAQ;KACN;KACA,MAAM,EAAE,GAAI,SAAS,QAAQ,EAAE,EAAG;KAClC,KAAK,kBAAkB;KACvB,WAAW,kBAAkB;KAC7B,MAAM;KACP;IACD,WAAW,sBAAsB;IAClC,CAAC;AACF,UAAO,QAAQ,QAAQ,OAAO;;EAEjC"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { callMiniProgramAsyncFailure, callMiniProgramAsyncSuccess } from "./async.mjs";
|
|
2
2
|
import { readBatteryInfoSnapshot, readBatteryInfoSyncSnapshot, vibrateDevice } from "./device.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/runtime/polyfill/deviceApi.ts
|
|
5
5
|
function vibrateShortBridge(options) {
|
|
6
6
|
try {
|
|
7
7
|
vibrateDevice(options?.type);
|
|
8
|
-
return Promise.resolve(
|
|
8
|
+
return Promise.resolve(callMiniProgramAsyncSuccess(options, { errMsg: "vibrateShort:ok" }));
|
|
9
9
|
} catch (error) {
|
|
10
|
-
const failure =
|
|
10
|
+
const failure = callMiniProgramAsyncFailure(options, `vibrateShort:fail ${error instanceof Error ? error.message : String(error)}`);
|
|
11
11
|
return Promise.reject(failure);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
@@ -16,12 +16,12 @@ function getBatteryInfoSyncBridge() {
|
|
|
16
16
|
}
|
|
17
17
|
async function getBatteryInfoBridge(options) {
|
|
18
18
|
try {
|
|
19
|
-
return
|
|
19
|
+
return callMiniProgramAsyncSuccess(options, {
|
|
20
20
|
errMsg: "getBatteryInfo:ok",
|
|
21
21
|
...await readBatteryInfoSnapshot()
|
|
22
22
|
});
|
|
23
23
|
} catch (error) {
|
|
24
|
-
const failure =
|
|
24
|
+
const failure = callMiniProgramAsyncFailure(options, `getBatteryInfo:fail ${error instanceof Error ? error.message : String(error)}`);
|
|
25
25
|
return Promise.reject(failure);
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deviceApi.mjs","names":[],"sources":["../../../src/runtime/polyfill/deviceApi.ts"],"sourcesContent":["import {\n
|
|
1
|
+
{"version":3,"file":"deviceApi.mjs","names":[],"sources":["../../../src/runtime/polyfill/deviceApi.ts"],"sourcesContent":["import {\n callMiniProgramAsyncFailure,\n callMiniProgramAsyncSuccess,\n} from './async'\nimport {\n readBatteryInfoSnapshot,\n readBatteryInfoSyncSnapshot,\n vibrateDevice,\n} from './device'\n\nexport function vibrateShortBridge(options?: any) {\n try {\n vibrateDevice(options?.type)\n return Promise.resolve(callMiniProgramAsyncSuccess(options, { errMsg: 'vibrateShort:ok' }))\n }\n catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n const failure = callMiniProgramAsyncFailure(options, `vibrateShort:fail ${message}`)\n return Promise.reject(failure)\n }\n}\n\nexport function getBatteryInfoSyncBridge() {\n return readBatteryInfoSyncSnapshot()\n}\n\nexport async function getBatteryInfoBridge(options?: any) {\n try {\n const batteryInfo = await readBatteryInfoSnapshot()\n return callMiniProgramAsyncSuccess(options, {\n errMsg: 'getBatteryInfo:ok',\n ...batteryInfo,\n })\n }\n catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n const failure = callMiniProgramAsyncFailure(options, `getBatteryInfo:fail ${message}`)\n return Promise.reject(failure)\n }\n}\n"],"mappings":";;;;AAUA,SAAgB,mBAAmB,SAAe;AAChD,KAAI;AACF,gBAAc,SAAS,KAAK;AAC5B,SAAO,QAAQ,QAAQ,4BAA4B,SAAS,EAAE,QAAQ,mBAAmB,CAAC,CAAC;UAEtF,OAAO;EAEZ,MAAM,UAAU,4BAA4B,SAAS,qBADrC,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,GACc;AACpF,SAAO,QAAQ,OAAO,QAAQ;;;AAIlC,SAAgB,2BAA2B;AACzC,QAAO,6BAA6B;;AAGtC,eAAsB,qBAAqB,SAAe;AACxD,KAAI;AAEF,SAAO,4BAA4B,SAAS;GAC1C,QAAQ;GACR,GAHkB,MAAM,yBAAyB;GAIlD,CAAC;UAEG,OAAO;EAEZ,MAAM,UAAU,4BAA4B,SAAS,uBADrC,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,GACgB;AACtF,SAAO,QAAQ,OAAO,QAAQ"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MiniProgramAsyncOptions } from "./types/base.mjs";
|
|
2
2
|
import { GetFuzzyLocationOptions, GetLocationOptions, GetNetworkTypeOptions, NetworkStatusChangeCallback, WindowResizeCallback } from "./types/locationRuntime.mjs";
|
|
3
3
|
import { AuthorizeOptions, GetSettingOptions, OpenSettingOptions } from "./types/mediaAuth.mjs";
|
|
4
4
|
import { BatteryInfo, GetBatteryInfoSuccessResult, VibrateShortOptions } from "./types/platformRuntime.mjs";
|
|
@@ -9,7 +9,7 @@ declare function vibrateShort(options?: VibrateShortOptions): Promise<{
|
|
|
9
9
|
errMsg: string;
|
|
10
10
|
}>;
|
|
11
11
|
declare function getBatteryInfoSync(): BatteryInfo;
|
|
12
|
-
declare function getBatteryInfo(options?:
|
|
12
|
+
declare function getBatteryInfo(options?: MiniProgramAsyncOptions<GetBatteryInfoSuccessResult>): Promise<{
|
|
13
13
|
level: number;
|
|
14
14
|
isCharging: boolean;
|
|
15
15
|
errMsg: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deviceAuthSystemApi.mjs","names":[],"sources":["../../../src/runtime/polyfill/deviceAuthSystemApi.ts"],"sourcesContent":["import type {\n AccountInfoSync,\n AppAuthorizeSetting,\n AppAuthorizeStatus,\n AppBaseInfo,\n AuthorizeOptions,\n BatteryInfo,\n CheckSessionOptions,\n DeviceInfo,\n GetBatteryInfoSuccessResult,\n GetFuzzyLocationOptions,\n GetLocationOptions,\n GetNetworkTypeOptions,\n GetSettingOptions,\n GetSystemInfoOptions,\n GetUserInfoOptions,\n GetUserProfileOptions,\n LoginOptions,\n MenuButtonBoundingClientRect,\n NetworkStatusChangeCallback,\n OpenAppAuthorizeSettingOptions,\n OpenSettingOptions,\n SystemInfo,\n SystemSetting,\n VibrateShortOptions,\n WindowInfo,\n WindowResizeCallback,\n
|
|
1
|
+
{"version":3,"file":"deviceAuthSystemApi.mjs","names":[],"sources":["../../../src/runtime/polyfill/deviceAuthSystemApi.ts"],"sourcesContent":["import type {\n AccountInfoSync,\n AppAuthorizeSetting,\n AppAuthorizeStatus,\n AppBaseInfo,\n AuthorizeOptions,\n BatteryInfo,\n CheckSessionOptions,\n DeviceInfo,\n GetBatteryInfoSuccessResult,\n GetFuzzyLocationOptions,\n GetLocationOptions,\n GetNetworkTypeOptions,\n GetSettingOptions,\n GetSystemInfoOptions,\n GetUserInfoOptions,\n GetUserProfileOptions,\n LoginOptions,\n MenuButtonBoundingClientRect,\n MiniProgramAsyncOptions,\n NetworkStatusChangeCallback,\n OpenAppAuthorizeSettingOptions,\n OpenSettingOptions,\n SystemInfo,\n SystemSetting,\n VibrateShortOptions,\n WindowInfo,\n WindowResizeCallback,\n} from './types'\nimport {\n authorizeBridge,\n checkSessionBridge,\n getAppAuthorizeSettingBridge,\n getSettingBridge,\n getSystemSettingBridge,\n getUserInfoBridge,\n getUserProfileBridge,\n loginBridge,\n openAppAuthorizeSettingBridge,\n openSettingBridge,\n} from './authApi'\nimport {\n getBatteryInfoBridge,\n getBatteryInfoSyncBridge,\n vibrateShortBridge,\n} from './deviceApi'\nimport {\n getFuzzyLocationBridge,\n getLocationBridge,\n} from './locationApi'\nimport { getNetworkTypeBridge } from './menuApi'\nimport {\n offNetworkStatusChangeBridge,\n offWindowResizeBridge,\n onNetworkStatusChangeBridge,\n onWindowResizeBridge,\n} from './runtimeCapabilityApi'\nimport { resolveDeviceOrientation } from './system'\nimport {\n getAccountInfoSyncBridge,\n getAppBaseInfoBridge,\n getDeviceInfoBridge,\n getMenuButtonBoundingClientRectBridge,\n getSystemInfoBridge,\n getSystemInfoSyncBridge,\n getWindowInfoBridge,\n} from './systemApi'\n\nconst WEB_SUPPORTED_AUTH_SCOPES = new Set([\n 'scope.userInfo',\n 'scope.userLocation',\n 'scope.userLocationBackground',\n 'scope.address',\n 'scope.invoiceTitle',\n 'scope.invoice',\n 'scope.werun',\n 'scope.record',\n 'scope.writePhotosAlbum',\n 'scope.camera',\n])\nconst APP_AUTHORIZE_SCOPE_MAP: Partial<Record<keyof AppAuthorizeSetting, string>> = {\n albumAuthorized: 'scope.writePhotosAlbum',\n cameraAuthorized: 'scope.camera',\n locationAuthorized: 'scope.userLocation',\n microphoneAuthorized: 'scope.record',\n}\nconst webAuthorizeState = new Map<string, AppAuthorizeStatus>()\nfor (const scope of WEB_SUPPORTED_AUTH_SCOPES) {\n webAuthorizeState.set(scope, 'not determined')\n}\n\nexport function vibrateShort(options?: VibrateShortOptions) {\n return vibrateShortBridge(options)\n}\n\nexport function getBatteryInfoSync(): BatteryInfo {\n return getBatteryInfoSyncBridge()\n}\n\nexport async function getBatteryInfo(options?: MiniProgramAsyncOptions<GetBatteryInfoSuccessResult>) {\n return getBatteryInfoBridge(options)\n}\n\nexport function getLocation(options?: GetLocationOptions) {\n return getLocationBridge(options)\n}\n\nexport async function getFuzzyLocation(options?: GetFuzzyLocationOptions) {\n return getFuzzyLocationBridge(options)\n}\n\nexport function getSetting(options?: GetSettingOptions) {\n return getSettingBridge(options, webAuthorizeState)\n}\n\nexport function authorize(options?: AuthorizeOptions) {\n return authorizeBridge(options, webAuthorizeState, WEB_SUPPORTED_AUTH_SCOPES)\n}\n\nexport function openSetting(options?: OpenSettingOptions) {\n return openSettingBridge(options, webAuthorizeState, WEB_SUPPORTED_AUTH_SCOPES)\n}\n\nexport function getAppAuthorizeSetting(): AppAuthorizeSetting {\n return getAppAuthorizeSettingBridge(webAuthorizeState) as AppAuthorizeSetting\n}\n\nexport function openAppAuthorizeSetting(options?: OpenAppAuthorizeSettingOptions) {\n return openAppAuthorizeSettingBridge(\n options,\n webAuthorizeState,\n APP_AUTHORIZE_SCOPE_MAP as Record<string, string>,\n getAppAuthorizeSetting,\n )\n}\n\nexport function getNetworkType(options?: GetNetworkTypeOptions) {\n return getNetworkTypeBridge(options)\n}\n\nexport function onNetworkStatusChange(callback: NetworkStatusChangeCallback) {\n return onNetworkStatusChangeBridge(callback)\n}\n\nexport function offNetworkStatusChange(callback?: NetworkStatusChangeCallback) {\n return offNetworkStatusChangeBridge(callback)\n}\n\nexport function getWindowInfo(): WindowInfo {\n return getWindowInfoBridge()\n}\n\nexport function onWindowResize(callback: WindowResizeCallback) {\n return onWindowResizeBridge(callback, getWindowInfo)\n}\n\nexport function offWindowResize(callback?: WindowResizeCallback) {\n return offWindowResizeBridge(callback)\n}\n\nexport function getSystemInfoSync(): SystemInfo {\n return getSystemInfoSyncBridge()\n}\n\nexport function getSystemInfo(options?: GetSystemInfoOptions) {\n return getSystemInfoBridge(options)\n}\n\nexport function getDeviceInfo(): DeviceInfo {\n return getDeviceInfoBridge() as DeviceInfo\n}\n\nexport function getSystemSetting(): SystemSetting {\n return getSystemSettingBridge(webAuthorizeState, resolveDeviceOrientation)\n}\n\nexport function login(options?: LoginOptions) {\n return loginBridge(options)\n}\n\nexport function checkSession(options?: CheckSessionOptions) {\n return checkSessionBridge(options)\n}\n\nexport function getUserInfo(options?: GetUserInfoOptions) {\n return getUserInfoBridge(options, webAuthorizeState)\n}\n\nexport function getUserProfile(options?: GetUserProfileOptions) {\n return getUserProfileBridge(options, webAuthorizeState)\n}\n\nexport function getAccountInfoSync(): AccountInfoSync {\n return getAccountInfoSyncBridge() as AccountInfoSync\n}\n\nexport function getAppBaseInfo(): AppBaseInfo {\n return getAppBaseInfoBridge() as AppBaseInfo\n}\n\nexport function getMenuButtonBoundingClientRect(): MenuButtonBoundingClientRect {\n return getMenuButtonBoundingClientRectBridge() as MenuButtonBoundingClientRect\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoEA,MAAM,4BAA4B,IAAI,IAAI;CACxC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAC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oBAAoB,QAAQ;;AAGrC,SAAgB,gBAA4B;AAC1C,QAAO,qBAAqB;;AAG9B,SAAgB,mBAAkC;AAChD,QAAO,uBAAuB,mBAAmB,yBAAyB;;AAG5E,SAAgB,MAAM,SAAwB;AAC5C,QAAO,YAAY,QAAQ;;AAG7B,SAAgB,aAAa,SAA+B;AAC1D,QAAO,mBAAmB,QAAQ;;AAGpC,SAAgB,YAAY,SAA8B;AACxD,QAAO,kBAAkB,SAAS,kBAAkB;;AAGtD,SAAgB,eAAe,SAAiC;AAC9D,QAAO,qBAAqB,SAAS,kBAAkB;;AAGzD,SAAgB,qBAAsC;AACpD,QAAO,0BAA0B;;AAGnC,SAAgB,iBAA8B;AAC5C,QAAO,sBAAsB;;AAG/B,SAAgB,kCAAgE;AAC9E,QAAO,uCAAuC"}
|
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
import { normalizeFilePath, readFileSyncInternal, writeFileSyncInternal } from "./files.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/runtime/polyfill/fileSystemManager.ts
|
|
4
|
-
function createFileSystemManagerBridge(
|
|
4
|
+
function createFileSystemManagerBridge(callMiniProgramAsyncSuccess, callMiniProgramAsyncFailure) {
|
|
5
5
|
return {
|
|
6
6
|
writeFile(options) {
|
|
7
7
|
const filePath = normalizeFilePath(options?.filePath);
|
|
8
8
|
if (!filePath) {
|
|
9
|
-
|
|
9
|
+
callMiniProgramAsyncFailure(options, "writeFile:fail invalid filePath");
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
12
12
|
try {
|
|
13
13
|
writeFileSyncInternal(filePath, options?.data ?? "");
|
|
14
|
-
|
|
14
|
+
callMiniProgramAsyncSuccess(options, { errMsg: "writeFile:ok" });
|
|
15
15
|
} catch (error) {
|
|
16
|
-
|
|
16
|
+
callMiniProgramAsyncFailure(options, `writeFile:fail ${error instanceof Error ? error.message : String(error)}`);
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
19
|
readFile(options) {
|
|
20
20
|
const filePath = normalizeFilePath(options?.filePath);
|
|
21
21
|
if (!filePath) {
|
|
22
|
-
|
|
22
|
+
callMiniProgramAsyncFailure(options, "readFile:fail invalid filePath");
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
25
25
|
try {
|
|
26
|
-
|
|
26
|
+
callMiniProgramAsyncSuccess(options, {
|
|
27
27
|
errMsg: "readFile:ok",
|
|
28
28
|
data: readFileSyncInternal(filePath, options?.encoding)
|
|
29
29
|
});
|
|
30
30
|
} catch (error) {
|
|
31
|
-
|
|
31
|
+
callMiniProgramAsyncFailure(options, `readFile:fail ${error instanceof Error ? error.message : String(error)}`);
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
writeFileSync(filePath, data, _encoding) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileSystemManager.mjs","names":[],"sources":["../../../src/runtime/polyfill/fileSystemManager.ts"],"sourcesContent":["import {\n normalizeFilePath,\n readFileSyncInternal,\n writeFileSyncInternal,\n} from './files'\n\ntype AsyncSuccess = (options: unknown, result: { errMsg: string, [key: string]: unknown }) => unknown\ntype AsyncFailure = (options: unknown, errMsg: string) => unknown\n\ninterface FileWriteOptionsLike {\n filePath?: string\n data?: unknown\n}\n\ninterface FileReadOptionsLike {\n filePath?: string\n encoding?: string\n}\n\nexport function createFileSystemManagerBridge(\n
|
|
1
|
+
{"version":3,"file":"fileSystemManager.mjs","names":[],"sources":["../../../src/runtime/polyfill/fileSystemManager.ts"],"sourcesContent":["import {\n normalizeFilePath,\n readFileSyncInternal,\n writeFileSyncInternal,\n} from './files'\n\ntype AsyncSuccess = (options: unknown, result: { errMsg: string, [key: string]: unknown }) => unknown\ntype AsyncFailure = (options: unknown, errMsg: string) => unknown\n\ninterface FileWriteOptionsLike {\n filePath?: string\n data?: unknown\n}\n\ninterface FileReadOptionsLike {\n filePath?: string\n encoding?: string\n}\n\nexport function createFileSystemManagerBridge(\n callMiniProgramAsyncSuccess: AsyncSuccess,\n callMiniProgramAsyncFailure: AsyncFailure,\n) {\n return {\n writeFile(options?: FileWriteOptionsLike) {\n const filePath = normalizeFilePath(options?.filePath)\n if (!filePath) {\n callMiniProgramAsyncFailure(options, 'writeFile:fail invalid filePath')\n return\n }\n try {\n writeFileSyncInternal(filePath, (options?.data ?? '') as string | ArrayBuffer | ArrayBufferView)\n callMiniProgramAsyncSuccess(options, { errMsg: 'writeFile:ok' })\n }\n catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n callMiniProgramAsyncFailure(options, `writeFile:fail ${message}`)\n }\n },\n readFile(options?: FileReadOptionsLike) {\n const filePath = normalizeFilePath(options?.filePath)\n if (!filePath) {\n callMiniProgramAsyncFailure(options, 'readFile:fail invalid filePath')\n return\n }\n try {\n const data = readFileSyncInternal(filePath, options?.encoding)\n callMiniProgramAsyncSuccess(options, { errMsg: 'readFile:ok', data })\n }\n catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n callMiniProgramAsyncFailure(options, `readFile:fail ${message}`)\n }\n },\n writeFileSync(filePath: string, data: string | ArrayBuffer | ArrayBufferView, _encoding?: string) {\n writeFileSyncInternal(filePath, data)\n },\n readFileSync(filePath: string, encoding?: string) {\n return readFileSyncInternal(filePath, encoding)\n },\n }\n}\n"],"mappings":";;;AAmBA,SAAgB,8BACd,6BACA,6BACA;AACA,QAAO;EACL,UAAU,SAAgC;GACxC,MAAM,WAAW,kBAAkB,SAAS,SAAS;AACrD,OAAI,CAAC,UAAU;AACb,gCAA4B,SAAS,kCAAkC;AACvE;;AAEF,OAAI;AACF,0BAAsB,UAAW,SAAS,QAAQ,GAA8C;AAChG,gCAA4B,SAAS,EAAE,QAAQ,gBAAgB,CAAC;YAE3D,OAAO;AAEZ,gCAA4B,SAAS,kBADrB,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,GACL;;;EAGrE,SAAS,SAA+B;GACtC,MAAM,WAAW,kBAAkB,SAAS,SAAS;AACrD,OAAI,CAAC,UAAU;AACb,gCAA4B,SAAS,iCAAiC;AACtE;;AAEF,OAAI;AAEF,gCAA4B,SAAS;KAAE,QAAQ;KAAe,MADjD,qBAAqB,UAAU,SAAS,SAAS;KACM,CAAC;YAEhE,OAAO;AAEZ,gCAA4B,SAAS,iBADrB,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,GACN;;;EAGpE,cAAc,UAAkB,MAA8C,WAAoB;AAChG,yBAAsB,UAAU,KAAK;;EAEvC,aAAa,UAAkB,UAAmB;AAChD,UAAO,qBAAqB,UAAU,SAAS;;EAElD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { emitRuntimeWarning } from "../warning.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { callMiniProgramAsyncFailure, callMiniProgramAsyncSuccess } from "./async.mjs";
|
|
3
3
|
import { setBackgroundColorBridge, setBackgroundTextStyleBridge } from "./background.mjs";
|
|
4
4
|
import { createCloudBridge } from "./cloud.mjs";
|
|
5
5
|
import { WEB_USER_DATA_PATH } from "./files.mjs";
|
|
@@ -10,8 +10,20 @@ import { createInterstitialAdBridge, createRewardedVideoAdBridge, getExtConfigBr
|
|
|
10
10
|
import { getAppInstance, getCurrentPagesInternal, getEnterOptionsSync, getLaunchOptionsSync, initializePageRoutes, navigateBack, navigateTo, reLaunch, redirectTo, registerApp, registerComponent, registerPage, switchTab } from "./routeRuntime.mjs";
|
|
11
11
|
import { clearStorage, clearStorageSync, createCanvasContext, createSelectorQuery, createVKSession, createVideoContext, createWorker, downloadFile, exitMiniProgram, getFileSystemManager, getStorage, getStorageInfo, getStorageInfoSync, getStorageSync, hideKeyboard, loadSubPackage, navigateToMiniProgram, nextTick, pageScrollTo, preloadSubpackage, removeStorage, removeStorageSync, request, runtimeDataApi_exports, setStorage, setStorageSync, startPullDownRefresh, stopPullDownRefresh, uploadFile } from "./runtimeDataApi.mjs";
|
|
12
12
|
import { chooseAddress, chooseFile, chooseImage, chooseLocation, chooseMedia, chooseMessageFile, chooseVideo, compressImage, compressVideo, getClipboardData, getImageInfo, getVideoInfo, hideLoading, hideTabBar, makePhoneCall, openCustomerServiceChat, openDocument, openLocation, openVideoEditor, previewImage, previewMedia, requestPayment, requestSubscribeMessage, saveFile, saveFileToDisk, saveImageToPhotosAlbum, saveVideoToPhotosAlbum, scanCode, setClipboardData, showActionSheet, showLoading, showModal, showShareMenu, showTabBar, showToast, uiMediaApi_exports, updateShareMenu } from "./uiMediaApi.mjs";
|
|
13
|
+
import { getDefaultMiniProgramRuntimeGlobalKey, getMiniProgramRuntimeGlobalKeys } from "@weapp-core/shared";
|
|
13
14
|
|
|
14
15
|
//#region src/runtime/polyfill/index.ts
|
|
16
|
+
const MINI_PROGRAM_GLOBAL_KEYS = getMiniProgramRuntimeGlobalKeys();
|
|
17
|
+
const DEFAULT_MINI_PROGRAM_GLOBAL_KEY = getDefaultMiniProgramRuntimeGlobalKey();
|
|
18
|
+
const globalTarget = typeof globalThis !== "undefined" ? globalThis : {};
|
|
19
|
+
function resolveMiniProgramBridge() {
|
|
20
|
+
for (const runtimeGlobalKey of MINI_PROGRAM_GLOBAL_KEYS) {
|
|
21
|
+
const candidate = globalTarget[runtimeGlobalKey];
|
|
22
|
+
if (candidate && typeof candidate === "object") return candidate;
|
|
23
|
+
}
|
|
24
|
+
const fallback = globalTarget[DEFAULT_MINI_PROGRAM_GLOBAL_KEY];
|
|
25
|
+
if (fallback && typeof fallback === "object") return fallback;
|
|
26
|
+
}
|
|
15
27
|
const navigationBarRuntimeBridge = createNavigationBarRuntimeBridge(() => getCurrentPagesInternal(), emitRuntimeWarning);
|
|
16
28
|
function setNavigationBarTitle(options) {
|
|
17
29
|
return navigationBarRuntimeBridge.setNavigationBarTitle(options);
|
|
@@ -32,9 +44,9 @@ function setBackgroundTextStyle(options) {
|
|
|
32
44
|
return setBackgroundTextStyleBridge(options);
|
|
33
45
|
}
|
|
34
46
|
function canIUse(schema) {
|
|
35
|
-
return canIUseBridge(
|
|
47
|
+
return canIUseBridge(resolveMiniProgramBridge(), schema);
|
|
36
48
|
}
|
|
37
|
-
const cloudBridge = createCloudBridge((options, result) =>
|
|
49
|
+
const cloudBridge = createCloudBridge((options, result) => callMiniProgramAsyncSuccess(options, result), (options, errMsg) => callMiniProgramAsyncFailure(options, errMsg));
|
|
38
50
|
function createRewardedVideoAd(options) {
|
|
39
51
|
return createRewardedVideoAdBridge(options);
|
|
40
52
|
}
|
|
@@ -56,10 +68,9 @@ function getLogManager(options) {
|
|
|
56
68
|
function reportAnalytics(eventName, data) {
|
|
57
69
|
reportAnalyticsBridge(eventName, data);
|
|
58
70
|
}
|
|
59
|
-
const globalTarget = typeof globalThis !== "undefined" ? globalThis : {};
|
|
60
71
|
if (globalTarget) {
|
|
61
|
-
const
|
|
62
|
-
Object.assign(
|
|
72
|
+
const miniProgramBridge = globalTarget[DEFAULT_MINI_PROGRAM_GLOBAL_KEY] ?? {};
|
|
73
|
+
Object.assign(miniProgramBridge, {
|
|
63
74
|
navigateTo,
|
|
64
75
|
navigateBack,
|
|
65
76
|
redirectTo,
|
|
@@ -86,10 +97,10 @@ if (globalTarget) {
|
|
|
86
97
|
canIUse,
|
|
87
98
|
cloud: cloudBridge
|
|
88
99
|
});
|
|
89
|
-
const
|
|
90
|
-
if (typeof
|
|
91
|
-
|
|
92
|
-
globalTarget
|
|
100
|
+
const miniProgramEnv = miniProgramBridge.env ?? {};
|
|
101
|
+
if (typeof miniProgramEnv.USER_DATA_PATH !== "string" || !miniProgramEnv.USER_DATA_PATH.trim()) miniProgramEnv.USER_DATA_PATH = WEB_USER_DATA_PATH;
|
|
102
|
+
miniProgramBridge.env = miniProgramEnv;
|
|
103
|
+
for (const runtimeGlobalKey of MINI_PROGRAM_GLOBAL_KEYS) globalTarget[runtimeGlobalKey] = miniProgramBridge;
|
|
93
104
|
if (typeof globalTarget.getApp !== "function") globalTarget.getApp = getAppInstance;
|
|
94
105
|
if (typeof globalTarget.getCurrentPages !== "function") globalTarget.getCurrentPages = getCurrentPagesInternal;
|
|
95
106
|
}
|