@weapp-vite/web 1.3.15 → 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/_virtual/_rolldown/runtime.mjs +18 -0
- package/dist/compiler/wxml/attributes.mjs +93 -0
- package/dist/compiler/wxml/attributes.mjs.map +1 -0
- package/dist/compiler/wxml/compile.mjs +158 -0
- package/dist/compiler/wxml/compile.mjs.map +1 -0
- package/dist/compiler/wxml/dependency.mjs +31 -0
- package/dist/compiler/wxml/dependency.mjs.map +1 -0
- package/dist/compiler/wxml/interpolation.mjs +142 -0
- package/dist/compiler/wxml/interpolation.mjs.map +1 -0
- package/dist/compiler/wxml/navigation.mjs +85 -0
- package/dist/compiler/wxml/navigation.mjs.map +1 -0
- package/dist/compiler/wxml/parser.mjs +41 -0
- package/dist/compiler/wxml/parser.mjs.map +1 -0
- package/dist/compiler/wxml/renderer.mjs +114 -0
- package/dist/compiler/wxml/renderer.mjs.map +1 -0
- package/dist/compiler/wxml/specialNodes.mjs +85 -0
- package/dist/compiler/wxml/specialNodes.mjs.map +1 -0
- package/dist/compiler/wxs.mjs +83 -0
- package/dist/compiler/wxs.mjs.map +1 -0
- package/dist/css/wxss.d.mts +25 -0
- package/dist/css/wxss.mjs +17 -0
- package/dist/css/wxss.mjs.map +1 -0
- package/dist/index.d.mts +18 -2
- package/dist/index.mjs +18 -3
- package/dist/plugin/constants.mjs +43 -0
- package/dist/plugin/constants.mjs.map +1 -0
- package/dist/plugin/entry.mjs +29 -0
- package/dist/plugin/entry.mjs.map +1 -0
- package/dist/plugin/files.mjs +58 -0
- package/dist/plugin/files.mjs.map +1 -0
- package/dist/plugin/index.d.mts +33 -0
- package/dist/plugin/index.mjs +188 -0
- package/dist/plugin/index.mjs.map +1 -0
- package/dist/plugin/navigation.mjs +20 -0
- package/dist/plugin/navigation.mjs.map +1 -0
- package/dist/plugin/path.mjs +85 -0
- package/dist/plugin/path.mjs.map +1 -0
- package/dist/plugin/register.mjs +83 -0
- package/dist/plugin/register.mjs.map +1 -0
- package/dist/plugin/scan.mjs +195 -0
- package/dist/plugin/scan.mjs.map +1 -0
- package/dist/plugin/scanConfig.mjs +45 -0
- package/dist/plugin/scanConfig.mjs.map +1 -0
- package/dist/plugin/state.mjs +22 -0
- package/dist/plugin/state.mjs.map +1 -0
- package/dist/plugin/types.d.mts +46 -0
- package/dist/plugin.d.mts +3 -2
- package/dist/plugin.mjs +3 -2
- package/dist/runtime/button/helpers.mjs +92 -0
- package/dist/runtime/button/helpers.mjs.map +1 -0
- package/dist/runtime/button/index.d.mts +9 -0
- package/dist/runtime/button/index.mjs +198 -0
- package/dist/runtime/button/index.mjs.map +1 -0
- package/dist/runtime/button/style.mjs +168 -0
- package/dist/runtime/button/style.mjs.map +1 -0
- package/dist/runtime/component/behavior.mjs +98 -0
- package/dist/runtime/component/behavior.mjs.map +1 -0
- package/dist/runtime/component/constants.mjs +13 -0
- package/dist/runtime/component/constants.mjs.map +1 -0
- package/dist/runtime/component/dom.mjs +32 -0
- package/dist/runtime/component/dom.mjs.map +1 -0
- package/dist/runtime/component/element.mjs +208 -0
- package/dist/runtime/component/element.mjs.map +1 -0
- package/dist/runtime/component/events.mjs +49 -0
- package/dist/runtime/component/events.mjs.map +1 -0
- package/dist/runtime/component/index.d.mts +7 -0
- package/dist/runtime/component/index.mjs +44 -0
- package/dist/runtime/component/index.mjs.map +1 -0
- package/dist/runtime/component/state.mjs +63 -0
- package/dist/runtime/component/state.mjs.map +1 -0
- package/dist/runtime/component/types.d.mts +49 -0
- package/dist/runtime/component/utils.mjs +39 -0
- package/dist/runtime/component/utils.mjs.map +1 -0
- package/dist/runtime/execution.d.mts +7 -0
- package/dist/runtime/execution.mjs +37 -0
- package/dist/runtime/execution.mjs.map +1 -0
- package/dist/runtime/index.d.mts +16 -2
- package/dist/runtime/index.mjs +16 -2
- package/dist/runtime/legacyTemplate/dom.mjs +76 -0
- package/dist/runtime/legacyTemplate/dom.mjs.map +1 -0
- package/dist/runtime/legacyTemplate/expression.mjs +113 -0
- package/dist/runtime/legacyTemplate/expression.mjs.map +1 -0
- package/dist/runtime/legacyTemplate/index.d.mts +9 -0
- package/dist/runtime/legacyTemplate/index.mjs +132 -0
- package/dist/runtime/legacyTemplate/index.mjs.map +1 -0
- package/dist/runtime/legacyTemplate/types.d.mts +6 -0
- package/dist/runtime/navigationBar/index.d.mts +10 -0
- package/dist/runtime/navigationBar/index.mjs +162 -0
- package/dist/runtime/navigationBar/index.mjs.map +1 -0
- package/dist/runtime/navigationBar/style.mjs +108 -0
- package/dist/runtime/navigationBar/style.mjs.map +1 -0
- package/dist/runtime/polyfill/ad.mjs +150 -0
- package/dist/runtime/polyfill/ad.mjs.map +1 -0
- package/dist/runtime/polyfill/appState.mjs +31 -0
- package/dist/runtime/polyfill/appState.mjs.map +1 -0
- package/dist/runtime/polyfill/async.mjs +31 -0
- package/dist/runtime/polyfill/async.mjs.map +1 -0
- package/dist/runtime/polyfill/auth.mjs +120 -0
- package/dist/runtime/polyfill/auth.mjs.map +1 -0
- package/dist/runtime/polyfill/authApi.mjs +101 -0
- package/dist/runtime/polyfill/authApi.mjs.map +1 -0
- package/dist/runtime/polyfill/background.mjs +31 -0
- package/dist/runtime/polyfill/background.mjs.map +1 -0
- package/dist/runtime/polyfill/canvasContext.mjs +115 -0
- package/dist/runtime/polyfill/canvasContext.mjs.map +1 -0
- package/dist/runtime/polyfill/capability.mjs +20 -0
- package/dist/runtime/polyfill/capability.mjs.map +1 -0
- package/dist/runtime/polyfill/cloud.mjs +39 -0
- package/dist/runtime/polyfill/cloud.mjs.map +1 -0
- package/dist/runtime/polyfill/device.mjs +44 -0
- package/dist/runtime/polyfill/device.mjs.map +1 -0
- package/dist/runtime/polyfill/deviceApi.mjs +31 -0
- package/dist/runtime/polyfill/deviceApi.mjs.map +1 -0
- package/dist/runtime/polyfill/deviceAuthSystemApi.d.mts +102 -0
- package/dist/runtime/polyfill/deviceAuthSystemApi.mjs +144 -0
- package/dist/runtime/polyfill/deviceAuthSystemApi.mjs.map +1 -0
- package/dist/runtime/polyfill/filePicker.mjs +158 -0
- package/dist/runtime/polyfill/filePicker.mjs.map +1 -0
- package/dist/runtime/polyfill/fileSystemManager.mjs +45 -0
- package/dist/runtime/polyfill/fileSystemManager.mjs.map +1 -0
- package/dist/runtime/polyfill/files.mjs +118 -0
- package/dist/runtime/polyfill/files.mjs.map +1 -0
- package/dist/runtime/polyfill/index.d.mts +40 -0
- package/dist/runtime/polyfill/index.mjs +110 -0
- package/dist/runtime/polyfill/index.mjs.map +1 -0
- package/dist/runtime/polyfill/interaction.mjs +38 -0
- package/dist/runtime/polyfill/interaction.mjs.map +1 -0
- package/dist/runtime/polyfill/interactionApi.mjs +54 -0
- package/dist/runtime/polyfill/interactionApi.mjs.map +1 -0
- package/dist/runtime/polyfill/location.mjs +106 -0
- package/dist/runtime/polyfill/location.mjs.map +1 -0
- package/dist/runtime/polyfill/locationApi.mjs +120 -0
- package/dist/runtime/polyfill/locationApi.mjs.map +1 -0
- package/dist/runtime/polyfill/mediaActions.mjs +52 -0
- package/dist/runtime/polyfill/mediaActions.mjs.map +1 -0
- package/dist/runtime/polyfill/mediaApi/file.mjs +63 -0
- package/dist/runtime/polyfill/mediaApi/file.mjs.map +1 -0
- package/dist/runtime/polyfill/mediaApi/info.mjs +59 -0
- package/dist/runtime/polyfill/mediaApi/info.mjs.map +1 -0
- package/dist/runtime/polyfill/mediaApi/picker.mjs +82 -0
- package/dist/runtime/polyfill/mediaApi/picker.mjs.map +1 -0
- package/dist/runtime/polyfill/mediaApi/preview.mjs +39 -0
- package/dist/runtime/polyfill/mediaApi/preview.mjs.map +1 -0
- package/dist/runtime/polyfill/mediaApi/process.mjs +46 -0
- package/dist/runtime/polyfill/mediaApi/process.mjs.map +1 -0
- package/dist/runtime/polyfill/mediaInfo.mjs +136 -0
- package/dist/runtime/polyfill/mediaInfo.mjs.map +1 -0
- package/dist/runtime/polyfill/mediaPicker.mjs +213 -0
- package/dist/runtime/polyfill/mediaPicker.mjs.map +1 -0
- package/dist/runtime/polyfill/mediaProcess.mjs +65 -0
- package/dist/runtime/polyfill/mediaProcess.mjs.map +1 -0
- package/dist/runtime/polyfill/menuApi.mjs +70 -0
- package/dist/runtime/polyfill/menuApi.mjs.map +1 -0
- package/dist/runtime/polyfill/navigationBarRuntime.mjs +66 -0
- package/dist/runtime/polyfill/navigationBarRuntime.mjs.map +1 -0
- package/dist/runtime/polyfill/network/request.mjs +162 -0
- package/dist/runtime/polyfill/network/request.mjs.map +1 -0
- package/dist/runtime/polyfill/network/requestBridge.mjs +49 -0
- package/dist/runtime/polyfill/network/requestBridge.mjs.map +1 -0
- package/dist/runtime/polyfill/network/status.mjs +55 -0
- package/dist/runtime/polyfill/network/status.mjs.map +1 -0
- package/dist/runtime/polyfill/platformApi.mjs +33 -0
- package/dist/runtime/polyfill/platformApi.mjs.map +1 -0
- package/dist/runtime/polyfill/platformRuntime.mjs +120 -0
- package/dist/runtime/polyfill/platformRuntime.mjs.map +1 -0
- package/dist/runtime/polyfill/routeRuntime/dom.mjs +36 -0
- package/dist/runtime/polyfill/routeRuntime/dom.mjs.map +1 -0
- package/dist/runtime/polyfill/routeRuntime/lifecycle.mjs +83 -0
- package/dist/runtime/polyfill/routeRuntime/lifecycle.mjs.map +1 -0
- package/dist/runtime/polyfill/routeRuntime/options.d.mts +33 -0
- package/dist/runtime/polyfill/routeRuntime/options.mjs +76 -0
- package/dist/runtime/polyfill/routeRuntime/options.mjs.map +1 -0
- package/dist/runtime/polyfill/routeRuntime/url.mjs +35 -0
- package/dist/runtime/polyfill/routeRuntime/url.mjs.map +1 -0
- package/dist/runtime/polyfill/routeRuntime.d.mts +43 -0
- package/dist/runtime/polyfill/routeRuntime.mjs +202 -0
- package/dist/runtime/polyfill/routeRuntime.mjs.map +1 -0
- package/dist/runtime/polyfill/runtimeCapabilityApi.mjs +26 -0
- package/dist/runtime/polyfill/runtimeCapabilityApi.mjs.map +1 -0
- package/dist/runtime/polyfill/runtimeDataApi.d.mts +79 -0
- package/dist/runtime/polyfill/runtimeDataApi.mjs +134 -0
- package/dist/runtime/polyfill/runtimeDataApi.mjs.map +1 -0
- package/dist/runtime/polyfill/runtimeInfra.mjs +40 -0
- package/dist/runtime/polyfill/runtimeInfra.mjs.map +1 -0
- package/dist/runtime/polyfill/runtimeOps.mjs +62 -0
- package/dist/runtime/polyfill/runtimeOps.mjs.map +1 -0
- package/dist/runtime/polyfill/selectorQuery.mjs +204 -0
- package/dist/runtime/polyfill/selectorQuery.mjs.map +1 -0
- package/dist/runtime/polyfill/storage.mjs +103 -0
- package/dist/runtime/polyfill/storage.mjs.map +1 -0
- package/dist/runtime/polyfill/storageAsync.mjs +62 -0
- package/dist/runtime/polyfill/storageAsync.mjs.map +1 -0
- package/dist/runtime/polyfill/subscribe.mjs +30 -0
- package/dist/runtime/polyfill/subscribe.mjs.map +1 -0
- package/dist/runtime/polyfill/system.mjs +111 -0
- package/dist/runtime/polyfill/system.mjs.map +1 -0
- package/dist/runtime/polyfill/systemApi.mjs +65 -0
- package/dist/runtime/polyfill/systemApi.mjs.map +1 -0
- package/dist/runtime/polyfill/types/base.d.mts +12 -0
- package/dist/runtime/polyfill/types/common.d.mts +126 -0
- package/dist/runtime/polyfill/types/locationRuntime.d.mts +151 -0
- package/dist/runtime/polyfill/types/mediaAuth.d.mts +152 -0
- package/dist/runtime/polyfill/types/platformRuntime.d.mts +141 -0
- package/dist/runtime/polyfill/types/systemAuth.d.mts +122 -0
- package/dist/runtime/polyfill/ui.mjs +135 -0
- package/dist/runtime/polyfill/ui.mjs.map +1 -0
- package/dist/runtime/polyfill/uiFeedback.mjs +35 -0
- package/dist/runtime/polyfill/uiFeedback.mjs.map +1 -0
- package/dist/runtime/polyfill/uiMediaApi.d.mts +172 -0
- package/dist/runtime/polyfill/uiMediaApi.mjs +162 -0
- package/dist/runtime/polyfill/uiMediaApi.mjs.map +1 -0
- package/dist/runtime/polyfill/videoContext.mjs +56 -0
- package/dist/runtime/polyfill/videoContext.mjs.map +1 -0
- package/dist/runtime/polyfill/vkSession.mjs +58 -0
- package/dist/runtime/polyfill/vkSession.mjs.map +1 -0
- package/dist/runtime/polyfill/windowResize.mjs +39 -0
- package/dist/runtime/polyfill/windowResize.mjs.map +1 -0
- package/dist/runtime/polyfill/worker.mjs +77 -0
- package/dist/runtime/polyfill/worker.mjs.map +1 -0
- package/dist/runtime/polyfill.d.mts +5 -0
- package/dist/runtime/renderContext.d.mts +21 -0
- package/dist/runtime/renderContext.mjs +147 -0
- package/dist/runtime/renderContext.mjs.map +1 -0
- package/dist/runtime/rpx.d.mts +9 -0
- package/dist/runtime/rpx.mjs +27 -0
- package/dist/runtime/rpx.mjs.map +1 -0
- package/dist/runtime/style.d.mts +6 -0
- package/dist/runtime/style.mjs +37 -0
- package/dist/runtime/style.mjs.map +1 -0
- package/dist/runtime/template.d.mts +10 -0
- package/dist/runtime/warning.d.mts +10 -0
- package/dist/runtime/warning.mjs +43 -0
- package/dist/runtime/warning.mjs.map +1 -0
- package/dist/{slugify-B4l45KNs.mjs → shared/slugify.mjs} +3 -1
- package/dist/shared/slugify.mjs.map +1 -0
- package/dist/shared/wxml.mjs +83 -0
- package/dist/shared/wxml.mjs.map +1 -0
- package/package.json +2 -2
- package/dist/index-w9xxIH-l.d.mts +0 -1229
- package/dist/plugin-BARxSPO8.mjs +0 -1567
- package/dist/plugin-DP2iPVmw.d.mts +0 -96
- package/dist/runtime-D6j2_x_N.mjs +0 -6251
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { createTempFilePath } from "./mediaPicker.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/runtime/polyfill/filePicker.ts
|
|
4
|
+
function normalizeChooseMessageFileCount(count) {
|
|
5
|
+
if (typeof count !== "number" || Number.isNaN(count)) return 1;
|
|
6
|
+
return Math.max(1, Math.floor(count));
|
|
7
|
+
}
|
|
8
|
+
function normalizeChooseMessageFileType(type) {
|
|
9
|
+
if (type === "video" || type === "image" || type === "file" || type === "all") return type;
|
|
10
|
+
return "all";
|
|
11
|
+
}
|
|
12
|
+
function buildChooseMessageAccept(type) {
|
|
13
|
+
if (type === "video") return "video/*";
|
|
14
|
+
if (type === "image") return "image/*";
|
|
15
|
+
if (type === "file") return "*/*";
|
|
16
|
+
return "*/*";
|
|
17
|
+
}
|
|
18
|
+
function normalizeChooseMessageFile(file) {
|
|
19
|
+
return {
|
|
20
|
+
path: createTempFilePath(file),
|
|
21
|
+
size: typeof file.size === "number" ? file.size : 0,
|
|
22
|
+
type: typeof file.type === "string" ? file.type : "",
|
|
23
|
+
name: typeof file.name === "string" ? file.name : "",
|
|
24
|
+
time: typeof file.lastModified === "number" ? file.lastModified : Date.now()
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
async function pickMessageFilesByOpenPicker(count, type) {
|
|
28
|
+
const picker = globalThis.showOpenFilePicker;
|
|
29
|
+
if (typeof picker !== "function") return null;
|
|
30
|
+
const accept = buildChooseMessageAccept(type);
|
|
31
|
+
const handles = await picker({
|
|
32
|
+
multiple: count > 1,
|
|
33
|
+
types: [{
|
|
34
|
+
description: "Message Files",
|
|
35
|
+
accept: { [accept]: [] }
|
|
36
|
+
}]
|
|
37
|
+
});
|
|
38
|
+
const files = [];
|
|
39
|
+
for (const handle of handles ?? []) {
|
|
40
|
+
const file = await handle?.getFile?.();
|
|
41
|
+
if (file) files.push(file);
|
|
42
|
+
if (files.length >= count) break;
|
|
43
|
+
}
|
|
44
|
+
return files;
|
|
45
|
+
}
|
|
46
|
+
async function pickMessageFilesByInput(count, type) {
|
|
47
|
+
if (typeof document === "undefined" || typeof document.createElement !== "function") return null;
|
|
48
|
+
const input = document.createElement("input");
|
|
49
|
+
input.setAttribute("type", "file");
|
|
50
|
+
input.setAttribute("accept", buildChooseMessageAccept(type));
|
|
51
|
+
if (count > 1) input.setAttribute("multiple", "true");
|
|
52
|
+
input.setAttribute("style", "position: fixed; left: -9999px; top: -9999px; opacity: 0;");
|
|
53
|
+
if (document.body) document.body.append(input);
|
|
54
|
+
try {
|
|
55
|
+
return await new Promise((resolve, reject) => {
|
|
56
|
+
const onChange = () => {
|
|
57
|
+
const selected = input.files ? Array.from(input.files) : [];
|
|
58
|
+
if (selected.length) {
|
|
59
|
+
resolve(selected.slice(0, count));
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
reject(/* @__PURE__ */ new Error("no file selected"));
|
|
63
|
+
};
|
|
64
|
+
input.addEventListener("change", onChange, { once: true });
|
|
65
|
+
if (typeof input.click === "function") {
|
|
66
|
+
input.click();
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
reject(/* @__PURE__ */ new Error("file input click is unavailable"));
|
|
70
|
+
});
|
|
71
|
+
} finally {
|
|
72
|
+
if (input.parentNode) input.parentNode.removeChild(input);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async function pickChooseMessageFiles(count, type) {
|
|
76
|
+
const viaPicker = await pickMessageFilesByOpenPicker(count, type);
|
|
77
|
+
if (Array.isArray(viaPicker)) return viaPicker;
|
|
78
|
+
const viaInput = await pickMessageFilesByInput(count, type);
|
|
79
|
+
if (Array.isArray(viaInput)) return viaInput;
|
|
80
|
+
throw new TypeError("Message file picker is unavailable in current environment.");
|
|
81
|
+
}
|
|
82
|
+
function normalizeChooseFileExtensions(extension) {
|
|
83
|
+
const set = /* @__PURE__ */ new Set();
|
|
84
|
+
for (const item of extension ?? []) {
|
|
85
|
+
if (typeof item !== "string") continue;
|
|
86
|
+
const normalized = item.trim().toLowerCase();
|
|
87
|
+
if (!normalized) continue;
|
|
88
|
+
set.add(normalized.startsWith(".") ? normalized : `.${normalized}`);
|
|
89
|
+
}
|
|
90
|
+
return Array.from(set);
|
|
91
|
+
}
|
|
92
|
+
function buildChooseFilePickerAccept(type, extensions) {
|
|
93
|
+
if (extensions.length) return { "*/*": extensions };
|
|
94
|
+
return { [buildChooseMessageAccept(type)]: [] };
|
|
95
|
+
}
|
|
96
|
+
function buildChooseFileInputAccept(type, extensions) {
|
|
97
|
+
if (extensions.length) return extensions.join(",");
|
|
98
|
+
return buildChooseMessageAccept(type);
|
|
99
|
+
}
|
|
100
|
+
async function pickChooseFileByOpenPicker(count, type, extensions) {
|
|
101
|
+
const picker = globalThis.showOpenFilePicker;
|
|
102
|
+
if (typeof picker !== "function") return null;
|
|
103
|
+
const handles = await picker({
|
|
104
|
+
multiple: count > 1,
|
|
105
|
+
types: [{
|
|
106
|
+
description: "Files",
|
|
107
|
+
accept: buildChooseFilePickerAccept(type, extensions)
|
|
108
|
+
}]
|
|
109
|
+
});
|
|
110
|
+
const files = [];
|
|
111
|
+
for (const handle of handles ?? []) {
|
|
112
|
+
const file = await handle?.getFile?.();
|
|
113
|
+
if (file) files.push(file);
|
|
114
|
+
if (files.length >= count) break;
|
|
115
|
+
}
|
|
116
|
+
return files;
|
|
117
|
+
}
|
|
118
|
+
async function pickChooseFileByInput(count, type, extensions) {
|
|
119
|
+
if (typeof document === "undefined" || typeof document.createElement !== "function") return null;
|
|
120
|
+
const input = document.createElement("input");
|
|
121
|
+
if (!input || typeof input !== "object") return null;
|
|
122
|
+
input.setAttribute("type", "file");
|
|
123
|
+
input.setAttribute("accept", buildChooseFileInputAccept(type, extensions));
|
|
124
|
+
if (count > 1) input.setAttribute("multiple", "true");
|
|
125
|
+
input.setAttribute("style", "position: fixed; left: -9999px; top: -9999px; opacity: 0;");
|
|
126
|
+
if (document.body) document.body.append(input);
|
|
127
|
+
try {
|
|
128
|
+
return await new Promise((resolve, reject) => {
|
|
129
|
+
const onChange = () => {
|
|
130
|
+
const selected = input.files ? Array.from(input.files) : [];
|
|
131
|
+
if (selected.length) {
|
|
132
|
+
resolve(selected.slice(0, count));
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
reject(/* @__PURE__ */ new Error("no file selected"));
|
|
136
|
+
};
|
|
137
|
+
input.addEventListener("change", onChange, { once: true });
|
|
138
|
+
if (typeof input.click === "function") {
|
|
139
|
+
input.click();
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
reject(/* @__PURE__ */ new Error("file input click is unavailable"));
|
|
143
|
+
});
|
|
144
|
+
} finally {
|
|
145
|
+
if (input.parentNode) input.parentNode.removeChild(input);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
async function pickChooseFileFiles(count, type, extensions) {
|
|
149
|
+
const viaPicker = await pickChooseFileByOpenPicker(count, type, extensions);
|
|
150
|
+
if (Array.isArray(viaPicker)) return viaPicker;
|
|
151
|
+
const viaInput = await pickChooseFileByInput(count, type, extensions);
|
|
152
|
+
if (Array.isArray(viaInput)) return viaInput;
|
|
153
|
+
throw new TypeError("File picker is unavailable in current environment.");
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
//#endregion
|
|
157
|
+
export { normalizeChooseFileExtensions, normalizeChooseMessageFile, normalizeChooseMessageFileCount, normalizeChooseMessageFileType, pickChooseFileFiles, pickChooseMessageFiles };
|
|
158
|
+
//# sourceMappingURL=filePicker.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filePicker.mjs","names":[],"sources":["../../../src/runtime/polyfill/filePicker.ts"],"sourcesContent":["import { createTempFilePath } from './mediaPicker'\n\ntype ChooseMessageFileType = 'all' | 'video' | 'image' | 'file'\n\nexport function normalizeChooseMessageFileCount(count: number | undefined) {\n if (typeof count !== 'number' || Number.isNaN(count)) {\n return 1\n }\n return Math.max(1, Math.floor(count))\n}\n\nexport function normalizeChooseMessageFileType(type: unknown): ChooseMessageFileType {\n if (type === 'video' || type === 'image' || type === 'file' || type === 'all') {\n return type\n }\n return 'all'\n}\n\nfunction buildChooseMessageAccept(type: ChooseMessageFileType) {\n if (type === 'video') {\n return 'video/*'\n }\n if (type === 'image') {\n return 'image/*'\n }\n if (type === 'file') {\n return '*/*'\n }\n return '*/*'\n}\n\nexport function normalizeChooseMessageFile(file: {\n size?: number\n type?: string\n name?: string\n lastModified?: number\n}) {\n return {\n path: createTempFilePath(file),\n size: typeof file.size === 'number' ? file.size : 0,\n type: typeof file.type === 'string' ? file.type : '',\n name: typeof file.name === 'string' ? file.name : '',\n time: typeof file.lastModified === 'number' ? file.lastModified : Date.now(),\n }\n}\n\nasync function pickMessageFilesByOpenPicker(count: number, type: ChooseMessageFileType) {\n const picker = (globalThis as {\n showOpenFilePicker?: (options: {\n multiple?: boolean\n types?: Array<{\n description?: string\n accept?: Record<string, string[]>\n }>\n }) => Promise<Array<{ getFile?: () => Promise<any> }>>\n }).showOpenFilePicker\n if (typeof picker !== 'function') {\n return null\n }\n const accept = buildChooseMessageAccept(type)\n const handles = await picker({\n multiple: count > 1,\n types: [{\n description: 'Message Files',\n accept: {\n [accept]: [],\n },\n }],\n })\n const files: any[] = []\n for (const handle of handles ?? []) {\n const file = await handle?.getFile?.()\n if (file) {\n files.push(file)\n }\n if (files.length >= count) {\n break\n }\n }\n return files\n}\n\nasync function pickMessageFilesByInput(count: number, type: ChooseMessageFileType) {\n if (typeof document === 'undefined' || typeof document.createElement !== 'function') {\n return null\n }\n const input = document.createElement('input') as HTMLInputElement\n input.setAttribute('type', 'file')\n input.setAttribute('accept', buildChooseMessageAccept(type))\n if (count > 1) {\n input.setAttribute('multiple', 'true')\n }\n input.setAttribute('style', 'position: fixed; left: -9999px; top: -9999px; opacity: 0;')\n if (document.body) {\n document.body.append(input)\n }\n try {\n const files = await new Promise<any[]>((resolve, reject) => {\n const onChange = () => {\n const selected = input.files ? Array.from(input.files) : []\n if (selected.length) {\n resolve(selected.slice(0, count))\n return\n }\n reject(new Error('no file selected'))\n }\n input.addEventListener('change', onChange, { once: true })\n if (typeof input.click === 'function') {\n input.click()\n return\n }\n reject(new Error('file input click is unavailable'))\n })\n return files\n }\n finally {\n if (input.parentNode) {\n input.parentNode.removeChild(input)\n }\n }\n}\n\nexport async function pickChooseMessageFiles(count: number, type: ChooseMessageFileType) {\n const viaPicker = await pickMessageFilesByOpenPicker(count, type)\n if (Array.isArray(viaPicker)) {\n return viaPicker\n }\n const viaInput = await pickMessageFilesByInput(count, type)\n if (Array.isArray(viaInput)) {\n return viaInput\n }\n throw new TypeError('Message file picker is unavailable in current environment.')\n}\n\nexport function normalizeChooseFileExtensions(extension: readonly string[] | undefined) {\n const set = new Set<string>()\n for (const item of extension ?? []) {\n if (typeof item !== 'string') {\n continue\n }\n const normalized = item.trim().toLowerCase()\n if (!normalized) {\n continue\n }\n set.add(normalized.startsWith('.') ? normalized : `.${normalized}`)\n }\n return Array.from(set)\n}\n\nfunction buildChooseFilePickerAccept(type: ChooseMessageFileType, extensions: string[]) {\n if (extensions.length) {\n return {\n '*/*': extensions,\n }\n }\n return {\n [buildChooseMessageAccept(type)]: [],\n }\n}\n\nfunction buildChooseFileInputAccept(type: ChooseMessageFileType, extensions: string[]) {\n if (extensions.length) {\n return extensions.join(',')\n }\n return buildChooseMessageAccept(type)\n}\n\nasync function pickChooseFileByOpenPicker(\n count: number,\n type: ChooseMessageFileType,\n extensions: string[],\n) {\n const picker = (globalThis as {\n showOpenFilePicker?: (options: {\n multiple?: boolean\n types?: Array<{\n description?: string\n accept?: Record<string, string[]>\n }>\n }) => Promise<Array<{ getFile?: () => Promise<any> }>>\n }).showOpenFilePicker\n if (typeof picker !== 'function') {\n return null\n }\n const handles = await picker({\n multiple: count > 1,\n types: [{\n description: 'Files',\n accept: buildChooseFilePickerAccept(type, extensions),\n }],\n })\n const files: any[] = []\n for (const handle of handles ?? []) {\n const file = await handle?.getFile?.()\n if (file) {\n files.push(file)\n }\n if (files.length >= count) {\n break\n }\n }\n return files\n}\n\nasync function pickChooseFileByInput(\n count: number,\n type: ChooseMessageFileType,\n extensions: string[],\n) {\n if (typeof document === 'undefined' || typeof document.createElement !== 'function') {\n return null\n }\n const input = document.createElement('input') as HTMLInputElement\n if (!input || typeof input !== 'object') {\n return null\n }\n input.setAttribute('type', 'file')\n input.setAttribute('accept', buildChooseFileInputAccept(type, extensions))\n if (count > 1) {\n input.setAttribute('multiple', 'true')\n }\n input.setAttribute('style', 'position: fixed; left: -9999px; top: -9999px; opacity: 0;')\n if (document.body) {\n document.body.append(input)\n }\n try {\n const files = await new Promise<any[]>((resolve, reject) => {\n const onChange = () => {\n const selected = input.files ? Array.from(input.files) : []\n if (selected.length) {\n resolve(selected.slice(0, count))\n return\n }\n reject(new Error('no file selected'))\n }\n input.addEventListener('change', onChange, { once: true })\n if (typeof input.click === 'function') {\n input.click()\n return\n }\n reject(new Error('file input click is unavailable'))\n })\n return files\n }\n finally {\n if (input.parentNode) {\n input.parentNode.removeChild(input)\n }\n }\n}\n\nexport async function pickChooseFileFiles(\n count: number,\n type: ChooseMessageFileType,\n extensions: string[],\n) {\n const viaPicker = await pickChooseFileByOpenPicker(count, type, extensions)\n if (Array.isArray(viaPicker)) {\n return viaPicker\n }\n const viaInput = await pickChooseFileByInput(count, type, extensions)\n if (Array.isArray(viaInput)) {\n return viaInput\n }\n throw new TypeError('File picker is unavailable in current environment.')\n}\n"],"mappings":";;;AAIA,SAAgB,gCAAgC,OAA2B;AACzE,KAAI,OAAO,UAAU,YAAY,OAAO,MAAM,MAAM,CAClD,QAAO;AAET,QAAO,KAAK,IAAI,GAAG,KAAK,MAAM,MAAM,CAAC;;AAGvC,SAAgB,+BAA+B,MAAsC;AACnF,KAAI,SAAS,WAAW,SAAS,WAAW,SAAS,UAAU,SAAS,MACtE,QAAO;AAET,QAAO;;AAGT,SAAS,yBAAyB,MAA6B;AAC7D,KAAI,SAAS,QACX,QAAO;AAET,KAAI,SAAS,QACX,QAAO;AAET,KAAI,SAAS,OACX,QAAO;AAET,QAAO;;AAGT,SAAgB,2BAA2B,MAKxC;AACD,QAAO;EACL,MAAM,mBAAmB,KAAK;EAC9B,MAAM,OAAO,KAAK,SAAS,WAAW,KAAK,OAAO;EAClD,MAAM,OAAO,KAAK,SAAS,WAAW,KAAK,OAAO;EAClD,MAAM,OAAO,KAAK,SAAS,WAAW,KAAK,OAAO;EAClD,MAAM,OAAO,KAAK,iBAAi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writeFileSyncInternal } from "./files.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/runtime/polyfill/fileSystemManager.ts
|
|
4
|
+
function createFileSystemManagerBridge(callMiniProgramAsyncSuccess, callMiniProgramAsyncFailure) {
|
|
5
|
+
return {
|
|
6
|
+
writeFile(options) {
|
|
7
|
+
const filePath = normalizeFilePath(options?.filePath);
|
|
8
|
+
if (!filePath) {
|
|
9
|
+
callMiniProgramAsyncFailure(options, "writeFile:fail invalid filePath");
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
writeFileSyncInternal(filePath, options?.data ?? "");
|
|
14
|
+
callMiniProgramAsyncSuccess(options, { errMsg: "writeFile:ok" });
|
|
15
|
+
} catch (error) {
|
|
16
|
+
callMiniProgramAsyncFailure(options, `writeFile:fail ${error instanceof Error ? error.message : String(error)}`);
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
readFile(options) {
|
|
20
|
+
const filePath = normalizeFilePath(options?.filePath);
|
|
21
|
+
if (!filePath) {
|
|
22
|
+
callMiniProgramAsyncFailure(options, "readFile:fail invalid filePath");
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
callMiniProgramAsyncSuccess(options, {
|
|
27
|
+
errMsg: "readFile:ok",
|
|
28
|
+
data: readFileSyncInternal(filePath, options?.encoding)
|
|
29
|
+
});
|
|
30
|
+
} catch (error) {
|
|
31
|
+
callMiniProgramAsyncFailure(options, `readFile:fail ${error instanceof Error ? error.message : String(error)}`);
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
writeFileSync(filePath, data, _encoding) {
|
|
35
|
+
writeFileSyncInternal(filePath, data);
|
|
36
|
+
},
|
|
37
|
+
readFileSync(filePath, encoding) {
|
|
38
|
+
return readFileSyncInternal(filePath, encoding);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
export { createFileSystemManagerBridge };
|
|
45
|
+
//# sourceMappingURL=fileSystemManager.mjs.map
|
|
@@ -0,0 +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 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"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
//#region src/runtime/polyfill/files.ts
|
|
2
|
+
const WEB_USER_DATA_PATH = "/__weapp_vite_web_user_data__";
|
|
3
|
+
const memoryFileStorage = /* @__PURE__ */ new Map();
|
|
4
|
+
function normalizeFilePath(filePath) {
|
|
5
|
+
if (typeof filePath !== "string") return "";
|
|
6
|
+
return filePath.trim();
|
|
7
|
+
}
|
|
8
|
+
function normalizeFileEncoding(encoding) {
|
|
9
|
+
if (typeof encoding !== "string") return "";
|
|
10
|
+
return encoding.trim().toLowerCase();
|
|
11
|
+
}
|
|
12
|
+
function cloneArrayBuffer(buffer) {
|
|
13
|
+
return buffer.slice(0);
|
|
14
|
+
}
|
|
15
|
+
function toArrayBuffer(data) {
|
|
16
|
+
if (data instanceof ArrayBuffer) return cloneArrayBuffer(data);
|
|
17
|
+
const view = data;
|
|
18
|
+
return new Uint8Array(view.buffer, view.byteOffset, view.byteLength).slice().buffer;
|
|
19
|
+
}
|
|
20
|
+
function decodeArrayBufferToText(buffer, encoding) {
|
|
21
|
+
if (typeof TextDecoder === "function") try {
|
|
22
|
+
return new TextDecoder(encoding || "utf-8").decode(new Uint8Array(buffer));
|
|
23
|
+
} catch {
|
|
24
|
+
return new TextDecoder().decode(new Uint8Array(buffer));
|
|
25
|
+
}
|
|
26
|
+
return Array.from(new Uint8Array(buffer)).map((byte) => String.fromCharCode(byte)).join("");
|
|
27
|
+
}
|
|
28
|
+
function writeFileSyncInternal(filePath, data) {
|
|
29
|
+
const normalizedPath = normalizeFilePath(filePath);
|
|
30
|
+
if (!normalizedPath) throw new TypeError("writeFileSync:fail invalid filePath");
|
|
31
|
+
if (typeof data === "string") {
|
|
32
|
+
memoryFileStorage.set(normalizedPath, {
|
|
33
|
+
kind: "text",
|
|
34
|
+
text: data
|
|
35
|
+
});
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
memoryFileStorage.set(normalizedPath, {
|
|
39
|
+
kind: "binary",
|
|
40
|
+
bytes: toArrayBuffer(data)
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function readFileSyncInternal(filePath, encoding) {
|
|
44
|
+
const normalizedPath = normalizeFilePath(filePath);
|
|
45
|
+
if (!normalizedPath) throw new TypeError("readFileSync:fail invalid filePath");
|
|
46
|
+
const record = memoryFileStorage.get(normalizedPath);
|
|
47
|
+
if (!record) throw new TypeError(`readFileSync:fail no such file ${normalizedPath}`);
|
|
48
|
+
const normalizedEncoding = normalizeFileEncoding(encoding);
|
|
49
|
+
if (record.kind === "text") return record.text ?? "";
|
|
50
|
+
const bytes = record.bytes ? cloneArrayBuffer(record.bytes) : /* @__PURE__ */ new ArrayBuffer(0);
|
|
51
|
+
if (normalizedEncoding) return decodeArrayBufferToText(bytes, normalizedEncoding);
|
|
52
|
+
return bytes;
|
|
53
|
+
}
|
|
54
|
+
function resolveUploadFileName(filePath) {
|
|
55
|
+
const segments = (filePath.split(/[?#]/)[0] ?? "").split("/");
|
|
56
|
+
return segments[segments.length - 1] || "file";
|
|
57
|
+
}
|
|
58
|
+
async function resolveUploadFileBlob(filePath, runtimeFetch) {
|
|
59
|
+
const record = memoryFileStorage.get(filePath);
|
|
60
|
+
if (record) {
|
|
61
|
+
if (record.kind === "text") return new Blob([record.text ?? ""], { type: "text/plain;charset=utf-8" });
|
|
62
|
+
return new Blob([record.bytes ?? /* @__PURE__ */ new ArrayBuffer(0)]);
|
|
63
|
+
}
|
|
64
|
+
if (/^(?:https?:|blob:|data:)/i.test(filePath) && runtimeFetch) try {
|
|
65
|
+
return await (await runtimeFetch(filePath, { method: "GET" })).blob();
|
|
66
|
+
} catch {}
|
|
67
|
+
return new Blob([filePath], { type: "text/plain;charset=utf-8" });
|
|
68
|
+
}
|
|
69
|
+
function cloneMemoryFileRecord(record) {
|
|
70
|
+
if (record.kind === "text") return {
|
|
71
|
+
kind: "text",
|
|
72
|
+
text: record.text ?? ""
|
|
73
|
+
};
|
|
74
|
+
return {
|
|
75
|
+
kind: "binary",
|
|
76
|
+
bytes: record.bytes ? cloneArrayBuffer(record.bytes) : /* @__PURE__ */ new ArrayBuffer(0)
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function resolveSaveFilePath(tempFilePath, customPath) {
|
|
80
|
+
const targetPath = typeof customPath === "string" ? customPath.trim() : "";
|
|
81
|
+
if (targetPath) return targetPath;
|
|
82
|
+
return `${WEB_USER_DATA_PATH}/${resolveUploadFileName(tempFilePath)}`;
|
|
83
|
+
}
|
|
84
|
+
function saveMemoryFile(tempFilePath, savedFilePath) {
|
|
85
|
+
const sourceRecord = memoryFileStorage.get(tempFilePath);
|
|
86
|
+
if (sourceRecord) {
|
|
87
|
+
memoryFileStorage.set(savedFilePath, cloneMemoryFileRecord(sourceRecord));
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
memoryFileStorage.set(savedFilePath, {
|
|
91
|
+
kind: "text",
|
|
92
|
+
text: tempFilePath
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
function resolveOpenDocumentUrl(filePath) {
|
|
96
|
+
const record = memoryFileStorage.get(filePath);
|
|
97
|
+
const runtimeUrl = globalThis.URL;
|
|
98
|
+
if (record) {
|
|
99
|
+
if (record.kind === "text") {
|
|
100
|
+
const text = record.text ?? "";
|
|
101
|
+
if (typeof Blob === "function" && runtimeUrl?.createObjectURL) return runtimeUrl.createObjectURL(new Blob([text], { type: "text/plain;charset=utf-8" }));
|
|
102
|
+
return `data:text/plain;charset=utf-8,${encodeURIComponent(text)}`;
|
|
103
|
+
}
|
|
104
|
+
const bytes = record.bytes ?? /* @__PURE__ */ new ArrayBuffer(0);
|
|
105
|
+
if (typeof Blob === "function" && runtimeUrl?.createObjectURL) return runtimeUrl.createObjectURL(new Blob([bytes]));
|
|
106
|
+
return "";
|
|
107
|
+
}
|
|
108
|
+
if (/^(?:https?:|blob:|data:)/i.test(filePath)) return filePath;
|
|
109
|
+
try {
|
|
110
|
+
const runtimeLocation = typeof location !== "undefined" ? location : void 0;
|
|
111
|
+
if (runtimeLocation?.href) return new URL(filePath, runtimeLocation.href).toString();
|
|
112
|
+
} catch {}
|
|
113
|
+
return filePath;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
//#endregion
|
|
117
|
+
export { WEB_USER_DATA_PATH, normalizeFilePath, readFileSyncInternal, resolveOpenDocumentUrl, resolveSaveFilePath, resolveUploadFileBlob, resolveUploadFileName, saveMemoryFile, writeFileSyncInternal };
|
|
118
|
+
//# sourceMappingURL=files.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.mjs","names":[],"sources":["../../../src/runtime/polyfill/files.ts"],"sourcesContent":["export const WEB_USER_DATA_PATH = '/__weapp_vite_web_user_data__'\n\ninterface MemoryFileRecord {\n kind: 'text' | 'binary'\n text?: string\n bytes?: ArrayBuffer\n}\n\nconst memoryFileStorage = new Map<string, MemoryFileRecord>()\n\nexport function normalizeFilePath(filePath: unknown) {\n if (typeof filePath !== 'string') {\n return ''\n }\n return filePath.trim()\n}\n\nfunction normalizeFileEncoding(encoding?: string) {\n if (typeof encoding !== 'string') {\n return ''\n }\n return encoding.trim().toLowerCase()\n}\n\nfunction cloneArrayBuffer(buffer: ArrayBuffer) {\n return buffer.slice(0)\n}\n\nfunction toArrayBuffer(data: ArrayBuffer | ArrayBufferView) {\n if (data instanceof ArrayBuffer) {\n return cloneArrayBuffer(data)\n }\n const view = data as ArrayBufferView\n return new Uint8Array(view.buffer, view.byteOffset, view.byteLength).slice().buffer\n}\n\nfunction decodeArrayBufferToText(buffer: ArrayBuffer, encoding?: string) {\n if (typeof TextDecoder === 'function') {\n try {\n return new TextDecoder(encoding || 'utf-8').decode(new Uint8Array(buffer))\n }\n catch {\n return new TextDecoder().decode(new Uint8Array(buffer))\n }\n }\n return Array.from(new Uint8Array(buffer))\n .map(byte => String.fromCharCode(byte))\n .join('')\n}\n\nexport function writeFileSyncInternal(\n filePath: string,\n data: string | ArrayBuffer | ArrayBufferView,\n) {\n const normalizedPath = normalizeFilePath(filePath)\n if (!normalizedPath) {\n throw new TypeError('writeFileSync:fail invalid filePath')\n }\n if (typeof data === 'string') {\n memoryFileStorage.set(normalizedPath, {\n kind: 'text',\n text: data,\n })\n return\n }\n memoryFileStorage.set(normalizedPath, {\n kind: 'binary',\n bytes: toArrayBuffer(data),\n })\n}\n\nexport function readFileSyncInternal(filePath: string, encoding?: string) {\n const normalizedPath = normalizeFilePath(filePath)\n if (!normalizedPath) {\n throw new TypeError('readFileSync:fail invalid filePath')\n }\n const record = memoryFileStorage.get(normalizedPath)\n if (!record) {\n throw new TypeError(`readFileSync:fail no such file ${normalizedPath}`)\n }\n const normalizedEncoding = normalizeFileEncoding(encoding)\n if (record.kind === 'text') {\n return record.text ?? ''\n }\n const bytes = record.bytes ? cloneArrayBuffer(record.bytes) : new ArrayBuffer(0)\n if (normalizedEncoding) {\n return decodeArrayBufferToText(bytes, normalizedEncoding)\n }\n return bytes\n}\n\nexport function resolveUploadFileName(filePath: string) {\n const normalized = filePath.split(/[?#]/)[0] ?? ''\n const segments = normalized.split('/')\n return segments[segments.length - 1] || 'file'\n}\n\nexport async function resolveUploadFileBlob(\n filePath: string,\n runtimeFetch: typeof fetch | undefined,\n) {\n const record = memoryFileStorage.get(filePath)\n if (record) {\n if (record.kind === 'text') {\n return new Blob([record.text ?? ''], { type: 'text/plain;charset=utf-8' })\n }\n return new Blob([record.bytes ?? new ArrayBuffer(0)])\n }\n if (/^(?:https?:|blob:|data:)/i.test(filePath) && runtimeFetch) {\n try {\n const response = await runtimeFetch(filePath, { method: 'GET' })\n return await response.blob()\n }\n catch {\n // fallback to plain text payload\n }\n }\n return new Blob([filePath], { type: 'text/plain;charset=utf-8' })\n}\n\nfunction cloneMemoryFileRecord(record: MemoryFileRecord): MemoryFileRecord {\n if (record.kind === 'text') {\n return {\n kind: 'text',\n text: record.text ?? '',\n }\n }\n return {\n kind: 'binary',\n bytes: record.bytes ? cloneArrayBuffer(record.bytes) : new ArrayBuffer(0),\n }\n}\n\nexport function resolveSaveFilePath(tempFilePath: string, customPath?: string) {\n const targetPath = typeof customPath === 'string' ? customPath.trim() : ''\n if (targetPath) {\n return targetPath\n }\n return `${WEB_USER_DATA_PATH}/${resolveUploadFileName(tempFilePath)}`\n}\n\nexport function saveMemoryFile(tempFilePath: string, savedFilePath: string) {\n const sourceRecord = memoryFileStorage.get(tempFilePath)\n if (sourceRecord) {\n memoryFileStorage.set(savedFilePath, cloneMemoryFileRecord(sourceRecord))\n return\n }\n memoryFileStorage.set(savedFilePath, {\n kind: 'text',\n text: tempFilePath,\n })\n}\n\nexport function resolveOpenDocumentUrl(filePath: string) {\n const record = memoryFileStorage.get(filePath)\n const runtimeUrl = (globalThis as {\n URL?: {\n createObjectURL?: (value: unknown) => string\n }\n }).URL\n\n if (record) {\n if (record.kind === 'text') {\n const text = record.text ?? ''\n if (typeof Blob === 'function' && runtimeUrl?.createObjectURL) {\n return runtimeUrl.createObjectURL(new Blob([text], { type: 'text/plain;charset=utf-8' }))\n }\n return `data:text/plain;charset=utf-8,${encodeURIComponent(text)}`\n }\n const bytes = record.bytes ?? new ArrayBuffer(0)\n if (typeof Blob === 'function' && runtimeUrl?.createObjectURL) {\n return runtimeUrl.createObjectURL(new Blob([bytes]))\n }\n return ''\n }\n\n if (/^(?:https?:|blob:|data:)/i.test(filePath)) {\n return filePath\n }\n try {\n const runtimeLocation = (typeof location !== 'undefined' ? location : undefined) as { href?: string } | undefined\n if (runtimeLocation?.href) {\n return new URL(filePath, runtimeLocation.href).toString()\n }\n }\n catch {\n // fallback to raw filePath\n }\n return filePath\n}\n"],"mappings":";AAAA,MAAa,qBAAqB;AAQlC,MAAM,oCAAoB,IAAI,KAA+B;AAE7D,SAAgB,kBAAkB,UAAmB;AACnD,KAAI,OAAO,aAAa,SACtB,QAAO;AAET,QAAO,SAAS,MAAM;;AAGxB,SAAS,sBAAsB,UAAmB;AAChD,KAAI,OAAO,aAAa,SACtB,QAAO;AAET,QAAO,SAAS,MAAM,CAAC,aAAa;;AAGtC,SAAS,iBAAiB,QAAqB;AAC7C,QAAO,OAAO,MAAM,EAAE;;AAGxB,SAAS,cAAc,MAAqC;AAC1D,KAAI,gBAAgB,YAClB,QAAO,iBAAiB,KAAK;CAE/B,MAAM,OAAO;AACb,QAAO,IAAI,WAAW,KAAK,QAAQ,KAAK,YAAY,KAAK,WAAW,CAAC,OAAO,CAAC;;AAG/E,SAAS,wBAAwB,QAAqB,UAAmB;AACvE,KAAI,OAAO,gBAAgB,WACzB,KAAI;AACF,SAAO,IAAI,YAAY,YAAY,QAAQ,CAAC,OAAO,IAAI,WAAW,OAAO,CAAC;SAEtE;AACJ,SAAO,IAAI,aAAa,C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AAI,OAAO,SAAS,cAAc,YAAY,gBAC5C,QAAO,WAAW,gBAAgB,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC;AAEtD,SAAO;;AAGT,KAAI,4BAA4B,KAAK,SAAS,CAC5C,QAAO;AAET,KAAI;EACF,MAAM,kBAAmB,OAAO,aAAa,cAAc,WAAW;AACtE,MAAI,iBAAiB,KACnB,QAAO,IAAI,IAAI,UAAU,gBAAgB,KAAK,CAAC,UAAU;SAGvD;AAGN,QAAO"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { LogManager, LogManagerOptions, SetBackgroundColorOptions, SetBackgroundTextStyleOptions, UpdateManager } from "./types/locationRuntime.mjs";
|
|
2
|
+
import { AdBaseOptions, GetExtConfigOptions, InterstitialAd, RewardedVideoAd } from "./types/platformRuntime.mjs";
|
|
3
|
+
import { authorize, checkSession, getAccountInfoSync, getAppAuthorizeSetting, getAppBaseInfo, getBatteryInfo, getBatteryInfoSync, getDeviceInfo, getFuzzyLocation, getLocation, getMenuButtonBoundingClientRect, getNetworkType, getSetting, getSystemInfo, getSystemInfoSync, getSystemSetting, getUserInfo, getUserProfile, getWindowInfo, login, offNetworkStatusChange, offWindowResize, onNetworkStatusChange, onWindowResize, openAppAuthorizeSetting, openSetting, vibrateShort } from "./deviceAuthSystemApi.mjs";
|
|
4
|
+
import { getEnterOptionsSync, getLaunchOptionsSync, initializePageRoutes, navigateBack, navigateTo, reLaunch, redirectTo, registerApp, registerComponent, registerPage, switchTab } from "./routeRuntime.mjs";
|
|
5
|
+
import { clearStorage, clearStorageSync, createCanvasContext, createSelectorQuery, createVKSession, createVideoContext, createWorker, downloadFile, exitMiniProgram, getFileSystemManager, getStorage, getStorageInfo, getStorageInfoSync, getStorageSync, hideKeyboard, loadSubPackage, navigateToMiniProgram, nextTick, pageScrollTo, preloadSubpackage, removeStorage, removeStorageSync, request, setStorage, setStorageSync, startPullDownRefresh, stopPullDownRefresh, uploadFile } from "./runtimeDataApi.mjs";
|
|
6
|
+
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, updateShareMenu } from "./uiMediaApi.mjs";
|
|
7
|
+
|
|
8
|
+
//#region src/runtime/polyfill/index.d.ts
|
|
9
|
+
declare function setNavigationBarTitle(options: {
|
|
10
|
+
title: string;
|
|
11
|
+
}): Promise<void>;
|
|
12
|
+
declare function setNavigationBarColor(options: {
|
|
13
|
+
frontColor?: string;
|
|
14
|
+
backgroundColor?: string;
|
|
15
|
+
animation?: {
|
|
16
|
+
duration?: number;
|
|
17
|
+
timingFunction?: string;
|
|
18
|
+
};
|
|
19
|
+
}): Promise<void>;
|
|
20
|
+
declare function showNavigationBarLoading(): Promise<void>;
|
|
21
|
+
declare function hideNavigationBarLoading(): Promise<void>;
|
|
22
|
+
declare function setBackgroundColor(options?: SetBackgroundColorOptions): Promise<{
|
|
23
|
+
errMsg: string;
|
|
24
|
+
}>;
|
|
25
|
+
declare function setBackgroundTextStyle(options?: SetBackgroundTextStyleOptions): Promise<{
|
|
26
|
+
errMsg: string;
|
|
27
|
+
}>;
|
|
28
|
+
declare function canIUse(schema: string): boolean;
|
|
29
|
+
declare function createRewardedVideoAd(options?: AdBaseOptions): RewardedVideoAd;
|
|
30
|
+
declare function createInterstitialAd(options?: AdBaseOptions): InterstitialAd;
|
|
31
|
+
declare function getExtConfigSync(): {
|
|
32
|
+
[x: string]: unknown;
|
|
33
|
+
};
|
|
34
|
+
declare function getExtConfig(options?: GetExtConfigOptions): Promise<any>;
|
|
35
|
+
declare function getUpdateManager(): UpdateManager;
|
|
36
|
+
declare function getLogManager(options?: LogManagerOptions): LogManager;
|
|
37
|
+
declare function reportAnalytics(eventName: string, data?: Record<string, unknown>): void;
|
|
38
|
+
//#endregion
|
|
39
|
+
export { canIUse, createInterstitialAd, createRewardedVideoAd, getExtConfig, getExtConfigSync, getLogManager, getUpdateManager, hideNavigationBarLoading, reportAnalytics, setBackgroundColor, setBackgroundTextStyle, setNavigationBarColor, setNavigationBarTitle, showNavigationBarLoading };
|
|
40
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { emitRuntimeWarning } from "../warning.mjs";
|
|
2
|
+
import { callMiniProgramAsyncFailure, callMiniProgramAsyncSuccess } from "./async.mjs";
|
|
3
|
+
import { setBackgroundColorBridge, setBackgroundTextStyleBridge } from "./background.mjs";
|
|
4
|
+
import { createCloudBridge } from "./cloud.mjs";
|
|
5
|
+
import { WEB_USER_DATA_PATH } from "./files.mjs";
|
|
6
|
+
import { canIUseBridge } from "./runtimeCapabilityApi.mjs";
|
|
7
|
+
import { authorize, checkSession, deviceAuthSystemApi_exports, getAccountInfoSync, getAppAuthorizeSetting, getAppBaseInfo, getBatteryInfo, getBatteryInfoSync, getDeviceInfo, getFuzzyLocation, getLocation, getMenuButtonBoundingClientRect, getNetworkType, getSetting, getSystemInfo, getSystemInfoSync, getSystemSetting, getUserInfo, getUserProfile, getWindowInfo, login, offNetworkStatusChange, offWindowResize, onNetworkStatusChange, onWindowResize, openAppAuthorizeSetting, openSetting, vibrateShort } from "./deviceAuthSystemApi.mjs";
|
|
8
|
+
import { createNavigationBarRuntimeBridge } from "./navigationBarRuntime.mjs";
|
|
9
|
+
import { createInterstitialAdBridge, createRewardedVideoAdBridge, getExtConfigBridge, getExtConfigSyncBridge, getLogManagerBridge, getUpdateManagerBridge, reportAnalyticsBridge } from "./platformApi.mjs";
|
|
10
|
+
import { getAppInstance, getCurrentPagesInternal, getEnterOptionsSync, getLaunchOptionsSync, initializePageRoutes, navigateBack, navigateTo, reLaunch, redirectTo, registerApp, registerComponent, registerPage, switchTab } from "./routeRuntime.mjs";
|
|
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
|
+
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";
|
|
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
|
+
}
|
|
27
|
+
const navigationBarRuntimeBridge = createNavigationBarRuntimeBridge(() => getCurrentPagesInternal(), emitRuntimeWarning);
|
|
28
|
+
function setNavigationBarTitle(options) {
|
|
29
|
+
return navigationBarRuntimeBridge.setNavigationBarTitle(options);
|
|
30
|
+
}
|
|
31
|
+
function setNavigationBarColor(options) {
|
|
32
|
+
return navigationBarRuntimeBridge.setNavigationBarColor(options);
|
|
33
|
+
}
|
|
34
|
+
function showNavigationBarLoading() {
|
|
35
|
+
return navigationBarRuntimeBridge.showNavigationBarLoading();
|
|
36
|
+
}
|
|
37
|
+
function hideNavigationBarLoading() {
|
|
38
|
+
return navigationBarRuntimeBridge.hideNavigationBarLoading();
|
|
39
|
+
}
|
|
40
|
+
function setBackgroundColor(options) {
|
|
41
|
+
return setBackgroundColorBridge(options);
|
|
42
|
+
}
|
|
43
|
+
function setBackgroundTextStyle(options) {
|
|
44
|
+
return setBackgroundTextStyleBridge(options);
|
|
45
|
+
}
|
|
46
|
+
function canIUse(schema) {
|
|
47
|
+
return canIUseBridge(resolveMiniProgramBridge(), schema);
|
|
48
|
+
}
|
|
49
|
+
const cloudBridge = createCloudBridge((options, result) => callMiniProgramAsyncSuccess(options, result), (options, errMsg) => callMiniProgramAsyncFailure(options, errMsg));
|
|
50
|
+
function createRewardedVideoAd(options) {
|
|
51
|
+
return createRewardedVideoAdBridge(options);
|
|
52
|
+
}
|
|
53
|
+
function createInterstitialAd(options) {
|
|
54
|
+
return createInterstitialAdBridge(options);
|
|
55
|
+
}
|
|
56
|
+
function getExtConfigSync() {
|
|
57
|
+
return getExtConfigSyncBridge();
|
|
58
|
+
}
|
|
59
|
+
function getExtConfig(options) {
|
|
60
|
+
return getExtConfigBridge(options);
|
|
61
|
+
}
|
|
62
|
+
function getUpdateManager() {
|
|
63
|
+
return getUpdateManagerBridge();
|
|
64
|
+
}
|
|
65
|
+
function getLogManager(options) {
|
|
66
|
+
return getLogManagerBridge(options);
|
|
67
|
+
}
|
|
68
|
+
function reportAnalytics(eventName, data) {
|
|
69
|
+
reportAnalyticsBridge(eventName, data);
|
|
70
|
+
}
|
|
71
|
+
if (globalTarget) {
|
|
72
|
+
const miniProgramBridge = globalTarget[DEFAULT_MINI_PROGRAM_GLOBAL_KEY] ?? {};
|
|
73
|
+
Object.assign(miniProgramBridge, {
|
|
74
|
+
navigateTo,
|
|
75
|
+
navigateBack,
|
|
76
|
+
redirectTo,
|
|
77
|
+
switchTab,
|
|
78
|
+
reLaunch,
|
|
79
|
+
getLaunchOptionsSync,
|
|
80
|
+
getEnterOptionsSync,
|
|
81
|
+
...runtimeDataApi_exports,
|
|
82
|
+
setNavigationBarTitle,
|
|
83
|
+
setNavigationBarColor,
|
|
84
|
+
setBackgroundColor,
|
|
85
|
+
setBackgroundTextStyle,
|
|
86
|
+
showNavigationBarLoading,
|
|
87
|
+
hideNavigationBarLoading,
|
|
88
|
+
...uiMediaApi_exports,
|
|
89
|
+
...deviceAuthSystemApi_exports,
|
|
90
|
+
createRewardedVideoAd,
|
|
91
|
+
createInterstitialAd,
|
|
92
|
+
getExtConfigSync,
|
|
93
|
+
getExtConfig,
|
|
94
|
+
getUpdateManager,
|
|
95
|
+
getLogManager,
|
|
96
|
+
reportAnalytics,
|
|
97
|
+
canIUse,
|
|
98
|
+
cloud: cloudBridge
|
|
99
|
+
});
|
|
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;
|
|
104
|
+
if (typeof globalTarget.getApp !== "function") globalTarget.getApp = getAppInstance;
|
|
105
|
+
if (typeof globalTarget.getCurrentPages !== "function") globalTarget.getCurrentPages = getCurrentPagesInternal;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
//#endregion
|
|
109
|
+
export { canIUse, createInterstitialAd, createRewardedVideoAd, getExtConfig, getExtConfigSync, getLogManager, getUpdateManager, hideNavigationBarLoading, reportAnalytics, setBackgroundColor, setBackgroundTextStyle, setNavigationBarColor, setNavigationBarTitle, showNavigationBarLoading };
|
|
110
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["runtimeDataApi","uiMediaApi","deviceAuthSystemApi"],"sources":["../../../src/runtime/polyfill/index.ts"],"sourcesContent":["import type {\n AdBaseOptions,\n CloudBridge,\n GetExtConfigOptions,\n InterstitialAd,\n LogManager,\n LogManagerOptions,\n MiniProgramAsyncOptions,\n MiniProgramBaseResult,\n RewardedVideoAd,\n SetBackgroundColorOptions,\n SetBackgroundTextStyleOptions,\n UpdateManager,\n} from './types'\nimport { getDefaultMiniProgramRuntimeGlobalKey, getMiniProgramRuntimeGlobalKeys } from '@weapp-core/shared'\nimport { emitRuntimeWarning } from '../warning'\nimport {\n callMiniProgramAsyncFailure,\n callMiniProgramAsyncSuccess,\n} from './async'\nimport {\n setBackgroundColorBridge,\n setBackgroundTextStyleBridge,\n} from './background'\nimport { createCloudBridge } from './cloud'\nimport * as deviceAuthSystemApi from './deviceAuthSystemApi'\nimport { WEB_USER_DATA_PATH } from './files'\nimport { createNavigationBarRuntimeBridge } from './navigationBarRuntime'\nimport {\n createInterstitialAdBridge,\n createRewardedVideoAdBridge,\n getExtConfigBridge,\n getExtConfigSyncBridge,\n getLogManagerBridge,\n getUpdateManagerBridge,\n reportAnalyticsBridge,\n} from './platformApi'\nimport {\n getAppInstance,\n getCurrentPagesInternal,\n getEnterOptionsSync,\n getLaunchOptionsSync,\n navigateBack,\n navigateTo,\n redirectTo,\n reLaunch,\n switchTab,\n} from './routeRuntime'\nimport {\n canIUseBridge,\n} from './runtimeCapabilityApi'\nimport * as runtimeDataApi from './runtimeDataApi'\nimport * as uiMediaApi from './uiMediaApi'\n\nexport * from './deviceAuthSystemApi'\n\nexport {\n getEnterOptionsSync,\n getLaunchOptionsSync,\n initializePageRoutes,\n navigateBack,\n navigateTo,\n redirectTo,\n registerApp,\n registerComponent,\n registerPage,\n reLaunch,\n switchTab,\n} from './routeRuntime'\n\nexport * from './runtimeDataApi'\nexport * from './uiMediaApi'\n\nconst MINI_PROGRAM_GLOBAL_KEYS = getMiniProgramRuntimeGlobalKeys()\nconst DEFAULT_MINI_PROGRAM_GLOBAL_KEY = getDefaultMiniProgramRuntimeGlobalKey()\nconst globalTarget = typeof globalThis !== 'undefined' ? (globalThis as Record<string, unknown>) : {}\n\nfunction resolveMiniProgramBridge() {\n for (const runtimeGlobalKey of MINI_PROGRAM_GLOBAL_KEYS) {\n const candidate = globalTarget[runtimeGlobalKey]\n if (candidate && typeof candidate === 'object') {\n return candidate as Record<string, unknown>\n }\n }\n const fallback = globalTarget[DEFAULT_MINI_PROGRAM_GLOBAL_KEY]\n if (fallback && typeof fallback === 'object') {\n return fallback as Record<string, unknown>\n }\n return undefined\n}\n\nconst navigationBarRuntimeBridge = createNavigationBarRuntimeBridge(\n () => getCurrentPagesInternal() as Array<HTMLElement & { renderRoot?: ShadowRoot | HTMLElement }>,\n emitRuntimeWarning,\n)\n\nexport function setNavigationBarTitle(options: { title: string }) {\n return navigationBarRuntimeBridge.setNavigationBarTitle(options)\n}\n\nexport function setNavigationBarColor(options: {\n frontColor?: string\n backgroundColor?: string\n animation?: { duration?: number, timingFunction?: string }\n}) {\n return navigationBarRuntimeBridge.setNavigationBarColor(options)\n}\n\nexport function showNavigationBarLoading() {\n return navigationBarRuntimeBridge.showNavigationBarLoading()\n}\n\nexport function hideNavigationBarLoading() {\n return navigationBarRuntimeBridge.hideNavigationBarLoading()\n}\n\nexport function setBackgroundColor(options?: SetBackgroundColorOptions) {\n return setBackgroundColorBridge(options)\n}\n\nexport function setBackgroundTextStyle(options?: SetBackgroundTextStyleOptions) {\n return setBackgroundTextStyleBridge(options)\n}\n\nexport function canIUse(schema: string) {\n return canIUseBridge(resolveMiniProgramBridge(), schema)\n}\n\nconst cloudBridge: CloudBridge = createCloudBridge(\n (options, result) => callMiniProgramAsyncSuccess(\n options as unknown as MiniProgramAsyncOptions<MiniProgramBaseResult> | undefined,\n result as MiniProgramBaseResult,\n ),\n (options, errMsg) => callMiniProgramAsyncFailure(\n options as unknown as MiniProgramAsyncOptions<MiniProgramBaseResult> | undefined,\n errMsg,\n ),\n) as CloudBridge\n\nexport function createRewardedVideoAd(options?: AdBaseOptions): RewardedVideoAd {\n return createRewardedVideoAdBridge(options)\n}\n\nexport function createInterstitialAd(options?: AdBaseOptions): InterstitialAd {\n return createInterstitialAdBridge(options)\n}\n\nexport function getExtConfigSync() {\n return getExtConfigSyncBridge()\n}\n\nexport function getExtConfig(options?: GetExtConfigOptions) {\n return getExtConfigBridge(options)\n}\n\nexport function getUpdateManager(): UpdateManager {\n return getUpdateManagerBridge()\n}\n\nexport function getLogManager(options?: LogManagerOptions): LogManager {\n return getLogManagerBridge(options)\n}\n\nexport function reportAnalytics(eventName: string, data?: Record<string, unknown>) {\n reportAnalyticsBridge(eventName, data)\n}\n\nif (globalTarget) {\n const miniProgramBridge = (globalTarget[DEFAULT_MINI_PROGRAM_GLOBAL_KEY] as Record<string, unknown> | undefined) ?? {}\n Object.assign(miniProgramBridge, {\n navigateTo,\n navigateBack,\n redirectTo,\n switchTab,\n reLaunch,\n getLaunchOptionsSync,\n getEnterOptionsSync,\n ...runtimeDataApi,\n setNavigationBarTitle,\n setNavigationBarColor,\n setBackgroundColor,\n setBackgroundTextStyle,\n showNavigationBarLoading,\n hideNavigationBarLoading,\n ...uiMediaApi,\n ...deviceAuthSystemApi,\n createRewardedVideoAd,\n createInterstitialAd,\n getExtConfigSync,\n getExtConfig,\n getUpdateManager,\n getLogManager,\n reportAnalytics,\n canIUse,\n cloud: cloudBridge,\n })\n const miniProgramEnv = (miniProgramBridge.env as Record<string, unknown> | undefined) ?? {}\n if (typeof miniProgramEnv.USER_DATA_PATH !== 'string' || !miniProgramEnv.USER_DATA_PATH.trim()) {\n miniProgramEnv.USER_DATA_PATH = WEB_USER_DATA_PATH\n }\n miniProgramBridge.env = miniProgramEnv\n for (const runtimeGlobalKey of MINI_PROGRAM_GLOBAL_KEYS) {\n globalTarget[runtimeGlobalKey] = miniProgramBridge\n }\n if (typeof globalTarget.getApp !== 'function') {\n globalTarget.getApp = getAppInstance\n }\n if (typeof globalTarget.getCurrentPages !== 'function') {\n globalTarget.getCurrentPages = getCurrentPagesInternal\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAyEA,MAAM,2BAA2B,iCAAiC;AAClE,MAAM,kCAAkC,uCAAuC;AAC/E,MAAM,eAAe,OAAO,eAAe,cAAe,aAAyC,EAAE;AAErG,SAAS,2BAA2B;AAClC,MAAK,MAAM,oBAAoB,0BAA0B;EACvD,MAAM,YAAY,aAAa;AAC/B,MAAI,aAAa,OAAO,cAAc,SACpC,QAAO;;CAGX,MAAM,WAAW,aAAa;AAC9B,KAAI,YAAY,OAAO,aAAa,SAClC,QAAO;;AAKX,MAAM,6BAA6B,uCAC3B,yBAAyB,EAC/B,mBACD;AAED,SAAgB,sBAAsB,SAA4B;AAChE,QAAO,2BAA2B,sBAAsB,QAAQ;;AAGlE,SAAgB,sBAAsB,SAInC;AACD,QAAO,2BAA2B,sBAAsB,QAAQ;;AAGlE,SAAgB,2BAA2B;AACzC,QAAO,2BAA2B,0BAA0B;;AAG9D,SAAgB,2BAA2B;AACzC,QAAO,2BAA2B,0BAA0B;;AAG9D,SAAgB,mBAAmB,SAAqC;AACtE,QAAO,yBAAyB,QAAQ;;AAG1C,SAAgB,uBAAuB,SAAyC;AAC9E,QAAO,6BAA6B,QAAQ;;AAG9C,SAAgB,QAAQ,Q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
+
function resolveScanCodeResult(prompt) {
|
|
5
|
+
let rawResult = globalThis[WEAPP_VITE_WEB_SCAN_CODE_RESULT_KEY];
|
|
6
|
+
if (rawResult == null && typeof prompt === "function") rawResult = prompt("请输入二维码/条码内容", "");
|
|
7
|
+
if (rawResult == null) return null;
|
|
8
|
+
if (typeof rawResult === "string") return rawResult;
|
|
9
|
+
return String(rawResult?.result ?? "");
|
|
10
|
+
}
|
|
11
|
+
async function writeClipboardData(data) {
|
|
12
|
+
const runtimeNavigator = typeof navigator !== "undefined" ? navigator : void 0;
|
|
13
|
+
if (runtimeNavigator?.clipboard && typeof runtimeNavigator.clipboard.writeText === "function") {
|
|
14
|
+
await runtimeNavigator.clipboard.writeText(data);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (typeof document === "undefined" || !document.body) throw new Error("Clipboard API is unavailable in current environment.");
|
|
18
|
+
const execCommand = document.execCommand;
|
|
19
|
+
if (typeof execCommand !== "function") throw new TypeError("Clipboard API is unavailable in current environment.");
|
|
20
|
+
const textarea = document.createElement("textarea");
|
|
21
|
+
textarea.value = data;
|
|
22
|
+
textarea.setAttribute("readonly", "true");
|
|
23
|
+
textarea.setAttribute("style", "position: fixed; top: -9999px; left: -9999px; opacity: 0;");
|
|
24
|
+
document.body.append(textarea);
|
|
25
|
+
textarea.select?.();
|
|
26
|
+
const copied = execCommand.call(document, "copy");
|
|
27
|
+
if (textarea.parentNode) textarea.parentNode.removeChild(textarea);
|
|
28
|
+
if (!copied) throw new Error("document.execCommand(\"copy\") returned false.");
|
|
29
|
+
}
|
|
30
|
+
async function readClipboardData() {
|
|
31
|
+
const runtimeNavigator = typeof navigator !== "undefined" ? navigator : void 0;
|
|
32
|
+
if (!runtimeNavigator?.clipboard || typeof runtimeNavigator.clipboard.readText !== "function") throw new Error("Clipboard API is unavailable in current environment.");
|
|
33
|
+
return runtimeNavigator.clipboard.readText();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
export { readClipboardData, resolveScanCodeResult, writeClipboardData };
|
|
38
|
+
//# sourceMappingURL=interaction.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interaction.mjs","names":[],"sources":["../../../src/runtime/polyfill/interaction.ts"],"sourcesContent":["import { WEAPP_VITE_WEB_SCAN_CODE_RESULT_KEY } from '@weapp-core/constants'\n\nexport function resolveScanCodeResult(prompt?: (message: string, defaultValue: string) => unknown) {\n const runtimeGlobal = globalThis as Record<string, unknown>\n let rawResult: unknown = runtimeGlobal[WEAPP_VITE_WEB_SCAN_CODE_RESULT_KEY]\n if (rawResult == null && typeof prompt === 'function') {\n rawResult = prompt('请输入二维码/条码内容', '')\n }\n if (rawResult == null) {\n return null\n }\n if (typeof rawResult === 'string') {\n return rawResult\n }\n return String((rawResult as { result?: unknown })?.result ?? '')\n}\n\nexport async function writeClipboardData(data: string) {\n const runtimeNavigator = typeof navigator !== 'undefined' ? navigator : undefined\n if (runtimeNavigator?.clipboard && typeof runtimeNavigator.clipboard.writeText === 'function') {\n await runtimeNavigator.clipboard.writeText(data)\n return\n }\n\n if (typeof document === 'undefined' || !document.body) {\n throw new Error('Clipboard API is unavailable in current environment.')\n }\n\n const execCommand = (document as Document & { execCommand?: (command: string) => boolean }).execCommand\n if (typeof execCommand !== 'function') {\n throw new TypeError('Clipboard API is unavailable in current environment.')\n }\n\n const textarea = document.createElement('textarea') as HTMLTextAreaElement\n textarea.value = data\n textarea.setAttribute('readonly', 'true')\n textarea.setAttribute('style', 'position: fixed; top: -9999px; left: -9999px; opacity: 0;')\n document.body.append(textarea)\n textarea.select?.()\n const copied = execCommand.call(document, 'copy')\n if (textarea.parentNode) {\n textarea.parentNode.removeChild(textarea)\n }\n if (!copied) {\n throw new Error('document.execCommand(\"copy\") returned false.')\n }\n}\n\nexport async function readClipboardData() {\n const runtimeNavigator = typeof navigator !== 'undefined' ? navigator : undefined\n if (!runtimeNavigator?.clipboard || typeof runtimeNavigator.clipboard.readText !== 'function') {\n throw new Error('Clipboard API is unavailable in current environment.')\n }\n return runtimeNavigator.clipboard.readText()\n}\n"],"mappings":";;;AAEA,SAAgB,sBAAsB,QAA6D;CAEjG,IAAI,YADkB,WACiB;AACvC,KAAI,aAAa,QAAQ,OAAO,WAAW,WACzC,aAAY,OAAO,eAAe,GAAG;AAEvC,KAAI,aAAa,KACf,QAAO;AAET,KAAI,OAAO,cAAc,SACvB,QAAO;AAET,QAAO,OAAQ,WAAoC,UAAU,GAAG;;AAGlE,eAAsB,mBAAmB,MAAc;CACrD,MAAM,mBAAmB,OAAO,cAAc,cAAc,YAAY;AACxE,KAAI,kBAAkB,aAAa,OAAO,iBAAiB,UAAU,cAAc,YAAY;AAC7F,QAAM,iBAAiB,UAAU,UAAU,KAAK;AAChD;;AAGF,KAAI,OAAO,aAAa,eAAe,CAAC,SAAS,KAC/C,OAAM,IAAI,MAAM,uDAAuD;CAGzE,MAAM,cAAe,SAAuE;AAC5F,KAAI,OAAO,gBAAgB,WACzB,OAAM,IAAI,UAAU,uDAAuD;CAG7E,MAAM,WAAW,SAAS,cAAc,WAAW;AACnD,UAAS,QAAQ;AACjB,UAAS,aAAa,YAAY,OAAO;AACzC,UAAS,aAAa,SAAS,4DAA4D;AAC3F,UAAS,KAAK,OAAO,SAAS;AAC9B,UAAS,UAAU;CACnB,MAAM,SAAS,YAAY,KAAK,UAAU,OAAO;AACjD,KAAI,SAAS,WACX,UAAS,WAAW,YAAY,SAAS;AAE3C,KAAI,CAAC,OACH,OAAM,IAAI,MAAM,iDAA+C;;AAInE,eAAsB,oBAAoB;CACxC,MAAM,mBAAmB,OAAO,cAAc,cAAc,YAAY;AACxE,KAAI,CAAC,kBAAkB,aAAa,OAAO,iBAAiB,UAAU,aAAa,WACjF,OAAM,IAAI,MAAM,uDAAuD;AAEzE,QAAO,iBAAiB,UAAU,UAAU"}
|