@weapp-vite/web 1.3.0 → 1.3.1

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.
@@ -2887,7 +2887,22 @@ function resolveOpenDocumentUrl(filePath) {
2887
2887
  return filePath;
2888
2888
  }
2889
2889
 
2890
- // src/runtime/polyfill/network.ts
2890
+ // src/runtime/polyfill/network/request.ts
2891
+ function resolveTimeoutSignal(timeout) {
2892
+ const controller = typeof AbortController === "function" ? new AbortController() : void 0;
2893
+ let timeoutTimer;
2894
+ if (timeout > 0 && controller) {
2895
+ timeoutTimer = setTimeout(() => controller.abort(), timeout);
2896
+ }
2897
+ return {
2898
+ signal: controller?.signal,
2899
+ clear: () => {
2900
+ if (timeoutTimer) {
2901
+ clearTimeout(timeoutTimer);
2902
+ }
2903
+ }
2904
+ };
2905
+ }
2891
2906
  function getRuntimeFetch() {
2892
2907
  const runtime = globalThis;
2893
2908
  const maybeFetch = runtime.fetch;
@@ -2994,21 +3009,6 @@ function stripUploadContentType(headers) {
2994
3009
  }
2995
3010
  return normalized;
2996
3011
  }
2997
- function resolveTimeoutSignal(timeout) {
2998
- const controller = typeof AbortController === "function" ? new AbortController() : void 0;
2999
- let timeoutTimer;
3000
- if (timeout > 0 && controller) {
3001
- timeoutTimer = setTimeout(() => controller.abort(), timeout);
3002
- }
3003
- return {
3004
- signal: controller?.signal,
3005
- clear: () => {
3006
- if (timeoutTimer) {
3007
- clearTimeout(timeoutTimer);
3008
- }
3009
- }
3010
- };
3011
- }
3012
3012
  async function performRequestByFetch(options) {
3013
3013
  const url = options?.url?.trim() ?? "";
3014
3014
  if (!url) {
@@ -3111,53 +3111,51 @@ async function performUploadByFetch(options) {
3111
3111
  timeoutControl.clear();
3112
3112
  }
3113
3113
  }
3114
+
3115
+ // src/runtime/polyfill/network/requestBridge.ts
3114
3116
  async function requestByFetchBridge(options) {
3115
3117
  try {
3116
3118
  const response = await performRequestByFetch(options);
3117
- const result = callWxAsyncSuccess(options, {
3119
+ return callWxAsyncSuccess(options, {
3118
3120
  errMsg: "request:ok",
3119
3121
  data: response.data,
3120
3122
  statusCode: response.statusCode,
3121
3123
  header: response.header
3122
3124
  });
3123
- return result;
3124
3125
  } catch (error) {
3125
3126
  const message = error instanceof Error ? error.message : String(error);
3126
- const failure = callWxAsyncFailure(options, `request:fail ${message}`);
3127
- return Promise.reject(failure);
3127
+ return Promise.reject(callWxAsyncFailure(options, `request:fail ${message}`));
3128
3128
  }
3129
3129
  }
3130
3130
  async function downloadFileByFetchBridge(options) {
3131
3131
  try {
3132
3132
  const response = await performDownloadByFetch(options);
3133
- const result = callWxAsyncSuccess(options, {
3133
+ return callWxAsyncSuccess(options, {
3134
3134
  errMsg: "downloadFile:ok",
3135
3135
  tempFilePath: response.tempFilePath,
3136
3136
  statusCode: response.statusCode
3137
3137
  });
3138
- return result;
3139
3138
  } catch (error) {
3140
3139
  const message = error instanceof Error ? error.message : String(error);
3141
- const failure = callWxAsyncFailure(options, `downloadFile:fail ${message}`);
3142
- return Promise.reject(failure);
3140
+ return Promise.reject(callWxAsyncFailure(options, `downloadFile:fail ${message}`));
3143
3141
  }
3144
3142
  }
3145
3143
  async function uploadFileByFetchBridge(options) {
3146
3144
  try {
3147
3145
  const response = await performUploadByFetch(options);
3148
- const result = callWxAsyncSuccess(options, {
3146
+ return callWxAsyncSuccess(options, {
3149
3147
  errMsg: "uploadFile:ok",
3150
3148
  data: response.data,
3151
3149
  statusCode: response.statusCode,
3152
3150
  header: response.header
3153
3151
  });
3154
- return result;
3155
3152
  } catch (error) {
3156
3153
  const message = error instanceof Error ? error.message : String(error);
3157
- const failure = callWxAsyncFailure(options, `uploadFile:fail ${message}`);
3158
- return Promise.reject(failure);
3154
+ return Promise.reject(callWxAsyncFailure(options, `uploadFile:fail ${message}`));
3159
3155
  }
3160
3156
  }
3157
+
3158
+ // src/runtime/polyfill/network/status.ts
3161
3159
  function getNavigatorConnection() {
3162
3160
  const runtimeNavigator = typeof navigator !== "undefined" ? navigator : void 0;
3163
3161
  return runtimeNavigator?.connection ?? runtimeNavigator?.mozConnection ?? runtimeNavigator?.webkitConnection;
@@ -3432,7 +3430,7 @@ function resolveSystemName(userAgent) {
3432
3430
  }
3433
3431
  function resolvePlatformName(userAgent, runtimeNavigator) {
3434
3432
  const navigatorWithUAData = runtimeNavigator;
3435
- const raw = navigatorWithUAData.userAgentData?.platform ?? runtimeNavigator?.platform ?? resolveSystemName(userAgent);
3433
+ const raw = navigatorWithUAData?.userAgentData?.platform ?? runtimeNavigator?.platform ?? resolveSystemName(userAgent);
3436
3434
  const normalized = raw.toLowerCase();
3437
3435
  if (normalized.includes("android")) {
3438
3436
  return "android";
@@ -5923,160 +5921,456 @@ async function getClipboardDataBridge(options) {
5923
5921
  }
5924
5922
  }
5925
5923
 
5926
- // src/runtime/polyfill/mediaPicker.ts
5927
- function normalizeChooseImageCount(count) {
5928
- if (typeof count !== "number" || Number.isNaN(count)) {
5929
- return 9;
5924
+ // src/runtime/polyfill/mediaApi/file.ts
5925
+ function saveImageToPhotosAlbumBridge(options) {
5926
+ const filePath = typeof options?.filePath === "string" ? options.filePath.trim() : "";
5927
+ if (!filePath) {
5928
+ const failure = callWxAsyncFailure(options, "saveImageToPhotosAlbum:fail invalid filePath");
5929
+ return Promise.reject(failure);
5930
5930
  }
5931
- return Math.max(1, Math.floor(count));
5931
+ triggerDownload(filePath);
5932
+ return Promise.resolve(callWxAsyncSuccess(options, { errMsg: "saveImageToPhotosAlbum:ok" }));
5932
5933
  }
5933
- function createTempFilePath(file) {
5934
- const runtimeUrl = globalThis.URL;
5935
- if (runtimeUrl && typeof runtimeUrl.createObjectURL === "function") {
5936
- const result = runtimeUrl.createObjectURL(file);
5937
- if (result) {
5938
- return result;
5939
- }
5934
+ function saveVideoToPhotosAlbumBridge(options) {
5935
+ const filePath = typeof options?.filePath === "string" ? options.filePath.trim() : "";
5936
+ if (!filePath) {
5937
+ const failure = callWxAsyncFailure(options, "saveVideoToPhotosAlbum:fail invalid filePath");
5938
+ return Promise.reject(failure);
5940
5939
  }
5941
- return file.name ?? "";
5940
+ triggerDownload(filePath);
5941
+ return Promise.resolve(callWxAsyncSuccess(options, { errMsg: "saveVideoToPhotosAlbum:ok" }));
5942
5942
  }
5943
- function normalizeChooseImageFile(file) {
5944
- return {
5945
- path: createTempFilePath(file),
5946
- size: typeof file.size === "number" ? file.size : 0,
5947
- type: typeof file.type === "string" ? file.type : "",
5948
- name: typeof file.name === "string" ? file.name : ""
5949
- };
5943
+ function saveFileBridge(options) {
5944
+ const tempFilePath = typeof options?.tempFilePath === "string" ? options.tempFilePath.trim() : "";
5945
+ if (!tempFilePath) {
5946
+ const failure = callWxAsyncFailure(options, "saveFile:fail invalid tempFilePath");
5947
+ return Promise.reject(failure);
5948
+ }
5949
+ const savedFilePath = resolveSaveFilePath(tempFilePath, options?.filePath);
5950
+ saveMemoryFile(tempFilePath, savedFilePath);
5951
+ return Promise.resolve(callWxAsyncSuccess(options, {
5952
+ errMsg: "saveFile:ok",
5953
+ savedFilePath
5954
+ }));
5950
5955
  }
5951
- async function pickImageFilesByOpenPicker(count) {
5952
- const picker = globalThis.showOpenFilePicker;
5953
- if (typeof picker !== "function") {
5954
- return null;
5956
+ function saveFileToDiskBridge(options) {
5957
+ const filePath = typeof options?.filePath === "string" ? options.filePath.trim() : "";
5958
+ if (!filePath) {
5959
+ const failure = callWxAsyncFailure(options, "saveFileToDisk:fail invalid filePath");
5960
+ return Promise.reject(failure);
5955
5961
  }
5956
- const handles = await picker({
5957
- multiple: count > 1,
5958
- types: [{
5959
- description: "Images",
5960
- accept: {
5961
- "image/*": [".png", ".jpg", ".jpeg", ".gif", ".webp", ".bmp", ".svg", ".avif"]
5962
- }
5963
- }]
5964
- });
5965
- const files = [];
5966
- for (const handle of handles ?? []) {
5967
- const file = await handle?.getFile?.();
5968
- if (file) {
5969
- files.push(file);
5970
- }
5971
- if (files.length >= count) {
5972
- break;
5973
- }
5962
+ const fileName = typeof options?.fileName === "string" ? options.fileName.trim() : "";
5963
+ triggerDownload(filePath, fileName);
5964
+ return Promise.resolve(callWxAsyncSuccess(options, { errMsg: "saveFileToDisk:ok" }));
5965
+ }
5966
+ function openDocumentBridge(options) {
5967
+ const filePath = normalizeFilePath(options?.filePath);
5968
+ if (!filePath) {
5969
+ const failure = callWxAsyncFailure(options, "openDocument:fail invalid filePath");
5970
+ return Promise.reject(failure);
5974
5971
  }
5975
- return files;
5972
+ const target = resolveOpenDocumentUrl(filePath);
5973
+ if (!target) {
5974
+ const failure = callWxAsyncFailure(options, "openDocument:fail document url is unavailable");
5975
+ return Promise.reject(failure);
5976
+ }
5977
+ openTargetInNewWindow(target);
5978
+ return Promise.resolve(callWxAsyncSuccess(options, { errMsg: "openDocument:ok" }));
5976
5979
  }
5977
- async function pickImageFilesByInput(count) {
5978
- if (typeof document === "undefined" || typeof document.createElement !== "function") {
5979
- return null;
5980
+
5981
+ // src/runtime/polyfill/mediaInfo.ts
5982
+ function inferImageTypeFromPath(path) {
5983
+ const lower = path.toLowerCase();
5984
+ if (lower.includes(".png")) {
5985
+ return "png";
5980
5986
  }
5981
- const input = document.createElement("input");
5982
- if (!input || typeof input !== "object") {
5983
- return null;
5987
+ if (lower.includes(".jpg") || lower.includes(".jpeg")) {
5988
+ return "jpg";
5984
5989
  }
5985
- input.setAttribute("type", "file");
5986
- input.setAttribute("accept", "image/*");
5987
- if (count > 1) {
5988
- input.setAttribute("multiple", "true");
5990
+ if (lower.includes(".gif")) {
5991
+ return "gif";
5989
5992
  }
5990
- input.setAttribute("style", "position: fixed; left: -9999px; top: -9999px; opacity: 0;");
5991
- if (document.body) {
5992
- document.body.append(input);
5993
+ if (lower.includes(".webp")) {
5994
+ return "webp";
5993
5995
  }
5994
- try {
5995
- const files = await new Promise((resolve, reject) => {
5996
- const onChange = () => {
5997
- const selected = input.files ? Array.from(input.files) : [];
5998
- if (selected.length) {
5999
- resolve(selected.slice(0, count));
6000
- return;
6001
- }
6002
- reject(new Error("no file selected"));
6003
- };
6004
- input.addEventListener("change", onChange, { once: true });
6005
- if (typeof input.click === "function") {
6006
- input.click();
6007
- return;
6008
- }
6009
- reject(new Error("file input click is unavailable"));
6010
- });
6011
- return files;
6012
- } finally {
6013
- if (input.parentNode) {
6014
- input.parentNode.removeChild(input);
6015
- }
5996
+ if (lower.includes(".bmp")) {
5997
+ return "bmp";
6016
5998
  }
6017
- }
6018
- async function pickChooseImageFiles(count) {
6019
- const viaPicker = await pickImageFilesByOpenPicker(count);
6020
- if (Array.isArray(viaPicker)) {
6021
- return viaPicker;
5999
+ if (lower.includes(".svg")) {
6000
+ return "svg";
6022
6001
  }
6023
- const viaInput = await pickImageFilesByInput(count);
6024
- if (Array.isArray(viaInput)) {
6025
- return viaInput;
6002
+ if (lower.includes(".avif")) {
6003
+ return "avif";
6026
6004
  }
6027
- throw new TypeError("Image picker is unavailable in current environment.");
6005
+ return "unknown";
6028
6006
  }
6029
- function normalizeChooseMediaCount(count) {
6030
- if (typeof count !== "number" || Number.isNaN(count)) {
6031
- return 1;
6007
+ function inferVideoTypeFromPath(path) {
6008
+ const lower = path.toLowerCase();
6009
+ if (lower.includes(".mp4")) {
6010
+ return "mp4";
6032
6011
  }
6033
- return Math.max(1, Math.floor(count));
6034
- }
6035
- function normalizeChooseMediaTypes(mediaType) {
6036
- const normalized = /* @__PURE__ */ new Set();
6037
- for (const item of mediaType ?? []) {
6038
- if (item === "image") {
6039
- normalized.add("image");
6040
- continue;
6041
- }
6042
- if (item === "video") {
6043
- normalized.add("video");
6044
- continue;
6045
- }
6046
- if (item === "mix") {
6047
- normalized.add("image");
6048
- normalized.add("video");
6049
- }
6012
+ if (lower.includes(".mov")) {
6013
+ return "mov";
6050
6014
  }
6051
- if (normalized.size === 0) {
6052
- normalized.add("image");
6053
- normalized.add("video");
6015
+ if (lower.includes(".m4v")) {
6016
+ return "m4v";
6054
6017
  }
6055
- return normalized;
6056
- }
6057
- function buildChooseMediaOpenPickerAccept(types) {
6058
- const accept = {};
6059
- if (types.has("image")) {
6060
- accept["image/*"] = [".png", ".jpg", ".jpeg", ".gif", ".webp", ".bmp", ".svg", ".avif"];
6018
+ if (lower.includes(".webm")) {
6019
+ return "webm";
6061
6020
  }
6062
- if (types.has("video")) {
6063
- accept["video/*"] = [".mp4", ".mov", ".m4v", ".webm"];
6021
+ if (lower.includes(".avi")) {
6022
+ return "avi";
6064
6023
  }
6065
- return accept;
6066
- }
6067
- function buildChooseMediaInputAccept(types) {
6068
- if (types.size === 2) {
6069
- return "image/*,video/*";
6024
+ if (lower.includes(".mkv")) {
6025
+ return "mkv";
6070
6026
  }
6071
- return types.has("video") ? "video/*" : "image/*";
6027
+ return "unknown";
6072
6028
  }
6073
- function inferChooseMediaFileType(file) {
6074
- const mimeType = typeof file.type === "string" ? file.type.toLowerCase() : "";
6075
- if (mimeType.startsWith("video/")) {
6076
- return "video";
6077
- }
6078
- if (mimeType.startsWith("image/")) {
6079
- return "image";
6029
+ function normalizeVideoInfoNumber(value) {
6030
+ if (typeof value !== "number" || Number.isNaN(value) || value < 0) {
6031
+ return 0;
6032
+ }
6033
+ return value;
6034
+ }
6035
+ function normalizeVideoInfoPreset(value, src) {
6036
+ if (!value || typeof value !== "object") {
6037
+ return null;
6038
+ }
6039
+ const info = value;
6040
+ return {
6041
+ size: normalizeVideoInfoNumber(info.size),
6042
+ duration: normalizeVideoInfoNumber(info.duration),
6043
+ width: normalizeVideoInfoNumber(info.width),
6044
+ height: normalizeVideoInfoNumber(info.height),
6045
+ fps: normalizeVideoInfoNumber(info.fps),
6046
+ bitrate: normalizeVideoInfoNumber(info.bitrate),
6047
+ type: typeof info.type === "string" ? info.type : inferVideoTypeFromPath(src),
6048
+ orientation: "up"
6049
+ };
6050
+ }
6051
+ function readPresetVideoInfo(src) {
6052
+ const runtimeGlobal = globalThis;
6053
+ const preset = runtimeGlobal.__weappViteWebVideoInfo;
6054
+ if (typeof preset === "function") {
6055
+ return normalizeVideoInfoPreset(preset(src), src);
6056
+ }
6057
+ if (preset && typeof preset === "object") {
6058
+ const sourcePreset = preset[src];
6059
+ if (sourcePreset && typeof sourcePreset === "object") {
6060
+ return normalizeVideoInfoPreset(sourcePreset, src);
6061
+ }
6062
+ return normalizeVideoInfoPreset(preset, src);
6063
+ }
6064
+ return null;
6065
+ }
6066
+ function normalizeCompressVideoResult(value, src) {
6067
+ if (!value || typeof value !== "object") {
6068
+ return null;
6069
+ }
6070
+ const info = value;
6071
+ const tempFilePath = typeof info.tempFilePath === "string" && info.tempFilePath.trim() ? info.tempFilePath.trim() : src;
6072
+ return {
6073
+ tempFilePath,
6074
+ size: normalizeVideoInfoNumber(info.size),
6075
+ duration: normalizeVideoInfoNumber(info.duration),
6076
+ width: normalizeVideoInfoNumber(info.width),
6077
+ height: normalizeVideoInfoNumber(info.height),
6078
+ bitrate: normalizeVideoInfoNumber(info.bitrate),
6079
+ fps: normalizeVideoInfoNumber(info.fps)
6080
+ };
6081
+ }
6082
+ function readPresetCompressVideo(src) {
6083
+ const runtimeGlobal = globalThis;
6084
+ const preset = runtimeGlobal.__weappViteWebCompressVideo;
6085
+ if (typeof preset === "function") {
6086
+ return normalizeCompressVideoResult(preset(src), src);
6087
+ }
6088
+ if (preset && typeof preset === "object") {
6089
+ const sourcePreset = preset[src];
6090
+ if (sourcePreset && typeof sourcePreset === "object") {
6091
+ return normalizeCompressVideoResult(sourcePreset, src);
6092
+ }
6093
+ return normalizeCompressVideoResult(preset, src);
6094
+ }
6095
+ if (typeof preset === "string" && preset.trim()) {
6096
+ return {
6097
+ tempFilePath: preset.trim(),
6098
+ size: 0,
6099
+ duration: 0,
6100
+ width: 0,
6101
+ height: 0,
6102
+ bitrate: 0,
6103
+ fps: 0
6104
+ };
6105
+ }
6106
+ return null;
6107
+ }
6108
+ async function readImageInfoFromSource(src) {
6109
+ const ImageCtor = globalThis.Image;
6110
+ if (typeof ImageCtor !== "function") {
6111
+ throw new TypeError("Image is unavailable");
6112
+ }
6113
+ return new Promise((resolve, reject) => {
6114
+ const image = new ImageCtor();
6115
+ image.onload = () => {
6116
+ const width = Number(image.naturalWidth ?? image.width ?? 0);
6117
+ const height = Number(image.naturalHeight ?? image.height ?? 0);
6118
+ resolve({
6119
+ width: Number.isFinite(width) ? width : 0,
6120
+ height: Number.isFinite(height) ? height : 0
6121
+ });
6122
+ };
6123
+ image.onerror = () => {
6124
+ reject(new Error("image load error"));
6125
+ };
6126
+ image.src = src;
6127
+ });
6128
+ }
6129
+ async function readVideoInfoFromSource(src) {
6130
+ if (typeof document === "undefined" || typeof document.createElement !== "function") {
6131
+ throw new TypeError("video element is unavailable");
6132
+ }
6133
+ const video = document.createElement("video");
6134
+ if (!video || typeof video.addEventListener !== "function") {
6135
+ throw new Error("video element is unavailable");
6136
+ }
6137
+ return new Promise((resolve, reject) => {
6138
+ const cleanup = () => {
6139
+ if (typeof video.removeEventListener === "function") {
6140
+ video.removeEventListener("loadedmetadata", onLoadedMetadata);
6141
+ video.removeEventListener("error", onError);
6142
+ }
6143
+ };
6144
+ const onLoadedMetadata = () => {
6145
+ cleanup();
6146
+ resolve({
6147
+ duration: normalizeVideoInfoNumber(video.duration),
6148
+ width: normalizeVideoInfoNumber(video.videoWidth),
6149
+ height: normalizeVideoInfoNumber(video.videoHeight)
6150
+ });
6151
+ };
6152
+ const onError = () => {
6153
+ cleanup();
6154
+ reject(new Error("video load error"));
6155
+ };
6156
+ video.addEventListener("loadedmetadata", onLoadedMetadata, { once: true });
6157
+ video.addEventListener("error", onError, { once: true });
6158
+ video.src = src;
6159
+ video.load?.();
6160
+ });
6161
+ }
6162
+
6163
+ // src/runtime/polyfill/mediaApi/info.ts
6164
+ function getImageInfoBridge(options) {
6165
+ const src = typeof options?.src === "string" ? options.src.trim() : "";
6166
+ if (!src) {
6167
+ const failure = callWxAsyncFailure(options, "getImageInfo:fail invalid src");
6168
+ return Promise.reject(failure);
6169
+ }
6170
+ return readImageInfoFromSource(src).then(({ width, height }) => callWxAsyncSuccess(options, {
6171
+ errMsg: "getImageInfo:ok",
6172
+ width,
6173
+ height,
6174
+ path: src,
6175
+ type: inferImageTypeFromPath(src),
6176
+ orientation: "up"
6177
+ })).catch((error) => {
6178
+ const message = error instanceof Error ? error.message : String(error);
6179
+ const failure = callWxAsyncFailure(options, `getImageInfo:fail ${message}`);
6180
+ return Promise.reject(failure);
6181
+ });
6182
+ }
6183
+ function getVideoInfoBridge(options) {
6184
+ const src = typeof options?.src === "string" ? options.src.trim() : "";
6185
+ if (!src) {
6186
+ const failure = callWxAsyncFailure(options, "getVideoInfo:fail invalid src");
6187
+ return Promise.reject(failure);
6188
+ }
6189
+ const preset = readPresetVideoInfo(src);
6190
+ const resolveResult = async () => {
6191
+ if (preset) {
6192
+ return preset;
6193
+ }
6194
+ return readVideoInfoFromSource(src);
6195
+ };
6196
+ return resolveResult().then((result) => {
6197
+ const duration = normalizeVideoInfoNumber(result.duration);
6198
+ const width = normalizeVideoInfoNumber(result.width);
6199
+ const height = normalizeVideoInfoNumber(result.height);
6200
+ const bitrate = normalizeVideoInfoNumber(result.bitrate);
6201
+ const fps = normalizeVideoInfoNumber(result.fps);
6202
+ return callWxAsyncSuccess(options, {
6203
+ errMsg: "getVideoInfo:ok",
6204
+ orientation: "up",
6205
+ type: inferVideoTypeFromPath(src),
6206
+ duration,
6207
+ size: normalizeVideoInfoNumber(result.size),
6208
+ width,
6209
+ height,
6210
+ bitrate,
6211
+ fps
6212
+ });
6213
+ }).catch((error) => {
6214
+ const message = error instanceof Error ? error.message : String(error);
6215
+ const failure = callWxAsyncFailure(options, `getVideoInfo:fail ${message}`);
6216
+ return Promise.reject(failure);
6217
+ });
6218
+ }
6219
+
6220
+ // src/runtime/polyfill/mediaPicker.ts
6221
+ function normalizeChooseImageCount(count) {
6222
+ if (typeof count !== "number" || Number.isNaN(count)) {
6223
+ return 9;
6224
+ }
6225
+ return Math.max(1, Math.floor(count));
6226
+ }
6227
+ function createTempFilePath(file) {
6228
+ const runtimeUrl = globalThis.URL;
6229
+ if (runtimeUrl && typeof runtimeUrl.createObjectURL === "function") {
6230
+ const result = runtimeUrl.createObjectURL(file);
6231
+ if (result) {
6232
+ return result;
6233
+ }
6234
+ }
6235
+ return file.name ?? "";
6236
+ }
6237
+ function normalizeChooseImageFile(file) {
6238
+ return {
6239
+ path: createTempFilePath(file),
6240
+ size: typeof file.size === "number" ? file.size : 0,
6241
+ type: typeof file.type === "string" ? file.type : "",
6242
+ name: typeof file.name === "string" ? file.name : ""
6243
+ };
6244
+ }
6245
+ async function pickImageFilesByOpenPicker(count) {
6246
+ const picker = globalThis.showOpenFilePicker;
6247
+ if (typeof picker !== "function") {
6248
+ return null;
6249
+ }
6250
+ const handles = await picker({
6251
+ multiple: count > 1,
6252
+ types: [{
6253
+ description: "Images",
6254
+ accept: {
6255
+ "image/*": [".png", ".jpg", ".jpeg", ".gif", ".webp", ".bmp", ".svg", ".avif"]
6256
+ }
6257
+ }]
6258
+ });
6259
+ const files = [];
6260
+ for (const handle of handles ?? []) {
6261
+ const file = await handle?.getFile?.();
6262
+ if (file) {
6263
+ files.push(file);
6264
+ }
6265
+ if (files.length >= count) {
6266
+ break;
6267
+ }
6268
+ }
6269
+ return files;
6270
+ }
6271
+ async function pickImageFilesByInput(count) {
6272
+ if (typeof document === "undefined" || typeof document.createElement !== "function") {
6273
+ return null;
6274
+ }
6275
+ const input = document.createElement("input");
6276
+ if (!input || typeof input !== "object") {
6277
+ return null;
6278
+ }
6279
+ input.setAttribute("type", "file");
6280
+ input.setAttribute("accept", "image/*");
6281
+ if (count > 1) {
6282
+ input.setAttribute("multiple", "true");
6283
+ }
6284
+ input.setAttribute("style", "position: fixed; left: -9999px; top: -9999px; opacity: 0;");
6285
+ if (document.body) {
6286
+ document.body.append(input);
6287
+ }
6288
+ try {
6289
+ const files = await new Promise((resolve, reject) => {
6290
+ const onChange = () => {
6291
+ const selected = input.files ? Array.from(input.files) : [];
6292
+ if (selected.length) {
6293
+ resolve(selected.slice(0, count));
6294
+ return;
6295
+ }
6296
+ reject(new Error("no file selected"));
6297
+ };
6298
+ input.addEventListener("change", onChange, { once: true });
6299
+ if (typeof input.click === "function") {
6300
+ input.click();
6301
+ return;
6302
+ }
6303
+ reject(new Error("file input click is unavailable"));
6304
+ });
6305
+ return files;
6306
+ } finally {
6307
+ if (input.parentNode) {
6308
+ input.parentNode.removeChild(input);
6309
+ }
6310
+ }
6311
+ }
6312
+ async function pickChooseImageFiles(count) {
6313
+ const viaPicker = await pickImageFilesByOpenPicker(count);
6314
+ if (Array.isArray(viaPicker)) {
6315
+ return viaPicker;
6316
+ }
6317
+ const viaInput = await pickImageFilesByInput(count);
6318
+ if (Array.isArray(viaInput)) {
6319
+ return viaInput;
6320
+ }
6321
+ throw new TypeError("Image picker is unavailable in current environment.");
6322
+ }
6323
+ function normalizeChooseMediaCount(count) {
6324
+ if (typeof count !== "number" || Number.isNaN(count)) {
6325
+ return 1;
6326
+ }
6327
+ return Math.max(1, Math.floor(count));
6328
+ }
6329
+ function normalizeChooseMediaTypes(mediaType) {
6330
+ const normalized = /* @__PURE__ */ new Set();
6331
+ for (const item of mediaType ?? []) {
6332
+ if (item === "image") {
6333
+ normalized.add("image");
6334
+ continue;
6335
+ }
6336
+ if (item === "video") {
6337
+ normalized.add("video");
6338
+ continue;
6339
+ }
6340
+ if (item === "mix") {
6341
+ normalized.add("image");
6342
+ normalized.add("video");
6343
+ }
6344
+ }
6345
+ if (normalized.size === 0) {
6346
+ normalized.add("image");
6347
+ normalized.add("video");
6348
+ }
6349
+ return normalized;
6350
+ }
6351
+ function buildChooseMediaOpenPickerAccept(types) {
6352
+ const accept = {};
6353
+ if (types.has("image")) {
6354
+ accept["image/*"] = [".png", ".jpg", ".jpeg", ".gif", ".webp", ".bmp", ".svg", ".avif"];
6355
+ }
6356
+ if (types.has("video")) {
6357
+ accept["video/*"] = [".mp4", ".mov", ".m4v", ".webm"];
6358
+ }
6359
+ return accept;
6360
+ }
6361
+ function buildChooseMediaInputAccept(types) {
6362
+ if (types.size === 2) {
6363
+ return "image/*,video/*";
6364
+ }
6365
+ return types.has("video") ? "video/*" : "image/*";
6366
+ }
6367
+ function inferChooseMediaFileType(file) {
6368
+ const mimeType = typeof file.type === "string" ? file.type.toLowerCase() : "";
6369
+ if (mimeType.startsWith("video/")) {
6370
+ return "video";
6371
+ }
6372
+ if (mimeType.startsWith("image/")) {
6373
+ return "image";
6080
6374
  }
6081
6375
  const fileName = typeof file.name === "string" ? file.name.toLowerCase() : "";
6082
6376
  if (/\.(?:mp4|mov|m4v|webm)$/i.test(fileName)) {
@@ -6326,249 +6620,67 @@ async function pickChooseFileByOpenPicker(count, type, extensions) {
6326
6620
  });
6327
6621
  const files = [];
6328
6622
  for (const handle of handles ?? []) {
6329
- const file = await handle?.getFile?.();
6330
- if (file) {
6331
- files.push(file);
6332
- }
6333
- if (files.length >= count) {
6334
- break;
6335
- }
6336
- }
6337
- return files;
6338
- }
6339
- async function pickChooseFileByInput(count, type, extensions) {
6340
- if (typeof document === "undefined" || typeof document.createElement !== "function") {
6341
- return null;
6342
- }
6343
- const input = document.createElement("input");
6344
- if (!input || typeof input !== "object") {
6345
- return null;
6346
- }
6347
- input.setAttribute("type", "file");
6348
- input.setAttribute("accept", buildChooseFileInputAccept(type, extensions));
6349
- if (count > 1) {
6350
- input.setAttribute("multiple", "true");
6351
- }
6352
- input.setAttribute("style", "position: fixed; left: -9999px; top: -9999px; opacity: 0;");
6353
- if (document.body) {
6354
- document.body.append(input);
6355
- }
6356
- try {
6357
- const files = await new Promise((resolve, reject) => {
6358
- const onChange = () => {
6359
- const selected = input.files ? Array.from(input.files) : [];
6360
- if (selected.length) {
6361
- resolve(selected.slice(0, count));
6362
- return;
6363
- }
6364
- reject(new Error("no file selected"));
6365
- };
6366
- input.addEventListener("change", onChange, { once: true });
6367
- if (typeof input.click === "function") {
6368
- input.click();
6369
- return;
6370
- }
6371
- reject(new Error("file input click is unavailable"));
6372
- });
6373
- return files;
6374
- } finally {
6375
- if (input.parentNode) {
6376
- input.parentNode.removeChild(input);
6377
- }
6378
- }
6379
- }
6380
- async function pickChooseFileFiles(count, type, extensions) {
6381
- const viaPicker = await pickChooseFileByOpenPicker(count, type, extensions);
6382
- if (Array.isArray(viaPicker)) {
6383
- return viaPicker;
6384
- }
6385
- const viaInput = await pickChooseFileByInput(count, type, extensions);
6386
- if (Array.isArray(viaInput)) {
6387
- return viaInput;
6388
- }
6389
- throw new TypeError("File picker is unavailable in current environment.");
6390
- }
6391
-
6392
- // src/runtime/polyfill/mediaInfo.ts
6393
- function inferImageTypeFromPath(path) {
6394
- const lower = path.toLowerCase();
6395
- if (lower.includes(".png")) {
6396
- return "png";
6397
- }
6398
- if (lower.includes(".jpg") || lower.includes(".jpeg")) {
6399
- return "jpg";
6400
- }
6401
- if (lower.includes(".gif")) {
6402
- return "gif";
6403
- }
6404
- if (lower.includes(".webp")) {
6405
- return "webp";
6406
- }
6407
- if (lower.includes(".bmp")) {
6408
- return "bmp";
6409
- }
6410
- if (lower.includes(".svg")) {
6411
- return "svg";
6412
- }
6413
- if (lower.includes(".avif")) {
6414
- return "avif";
6415
- }
6416
- return "unknown";
6417
- }
6418
- function inferVideoTypeFromPath(path) {
6419
- const lower = path.toLowerCase();
6420
- if (lower.includes(".mp4")) {
6421
- return "mp4";
6422
- }
6423
- if (lower.includes(".mov")) {
6424
- return "mov";
6425
- }
6426
- if (lower.includes(".m4v")) {
6427
- return "m4v";
6428
- }
6429
- if (lower.includes(".webm")) {
6430
- return "webm";
6431
- }
6432
- if (lower.includes(".avi")) {
6433
- return "avi";
6434
- }
6435
- if (lower.includes(".mkv")) {
6436
- return "mkv";
6437
- }
6438
- return "unknown";
6439
- }
6440
- function normalizeVideoInfoNumber(value) {
6441
- if (typeof value !== "number" || Number.isNaN(value) || value < 0) {
6442
- return 0;
6443
- }
6444
- return value;
6445
- }
6446
- function normalizeVideoInfoPreset(value, src) {
6447
- if (!value || typeof value !== "object") {
6448
- return null;
6449
- }
6450
- const info = value;
6451
- return {
6452
- size: normalizeVideoInfoNumber(info.size),
6453
- duration: normalizeVideoInfoNumber(info.duration),
6454
- width: normalizeVideoInfoNumber(info.width),
6455
- height: normalizeVideoInfoNumber(info.height),
6456
- fps: normalizeVideoInfoNumber(info.fps),
6457
- bitrate: normalizeVideoInfoNumber(info.bitrate),
6458
- type: typeof info.type === "string" ? info.type : inferVideoTypeFromPath(src),
6459
- orientation: "up"
6460
- };
6461
- }
6462
- function readPresetVideoInfo(src) {
6463
- const runtimeGlobal = globalThis;
6464
- const preset = runtimeGlobal.__weappViteWebVideoInfo;
6465
- if (typeof preset === "function") {
6466
- return normalizeVideoInfoPreset(preset(src), src);
6467
- }
6468
- if (preset && typeof preset === "object") {
6469
- const sourcePreset = preset[src];
6470
- if (sourcePreset && typeof sourcePreset === "object") {
6471
- return normalizeVideoInfoPreset(sourcePreset, src);
6472
- }
6473
- return normalizeVideoInfoPreset(preset, src);
6474
- }
6475
- return null;
6476
- }
6477
- function normalizeCompressVideoResult(value, src) {
6478
- if (!value || typeof value !== "object") {
6479
- return null;
6480
- }
6481
- const info = value;
6482
- const tempFilePath = typeof info.tempFilePath === "string" && info.tempFilePath.trim() ? info.tempFilePath.trim() : src;
6483
- return {
6484
- tempFilePath,
6485
- size: normalizeVideoInfoNumber(info.size),
6486
- duration: normalizeVideoInfoNumber(info.duration),
6487
- width: normalizeVideoInfoNumber(info.width),
6488
- height: normalizeVideoInfoNumber(info.height),
6489
- bitrate: normalizeVideoInfoNumber(info.bitrate),
6490
- fps: normalizeVideoInfoNumber(info.fps)
6491
- };
6492
- }
6493
- function readPresetCompressVideo(src) {
6494
- const runtimeGlobal = globalThis;
6495
- const preset = runtimeGlobal.__weappViteWebCompressVideo;
6496
- if (typeof preset === "function") {
6497
- return normalizeCompressVideoResult(preset(src), src);
6498
- }
6499
- if (preset && typeof preset === "object") {
6500
- const sourcePreset = preset[src];
6501
- if (sourcePreset && typeof sourcePreset === "object") {
6502
- return normalizeCompressVideoResult(sourcePreset, src);
6503
- }
6504
- return normalizeCompressVideoResult(preset, src);
6505
- }
6506
- if (typeof preset === "string" && preset.trim()) {
6507
- return {
6508
- tempFilePath: preset.trim(),
6509
- size: 0,
6510
- duration: 0,
6511
- width: 0,
6512
- height: 0,
6513
- bitrate: 0,
6514
- fps: 0
6515
- };
6516
- }
6517
- return null;
6518
- }
6519
- async function readImageInfoFromSource(src) {
6520
- const ImageCtor = globalThis.Image;
6521
- if (typeof ImageCtor !== "function") {
6522
- throw new TypeError("Image is unavailable");
6523
- }
6524
- return new Promise((resolve, reject) => {
6525
- const image = new ImageCtor();
6526
- image.onload = () => {
6527
- const width = Number(image.naturalWidth ?? image.width ?? 0);
6528
- const height = Number(image.naturalHeight ?? image.height ?? 0);
6529
- resolve({
6530
- width: Number.isFinite(width) ? width : 0,
6531
- height: Number.isFinite(height) ? height : 0
6532
- });
6533
- };
6534
- image.onerror = () => {
6535
- reject(new Error("image load error"));
6536
- };
6537
- image.src = src;
6538
- });
6623
+ const file = await handle?.getFile?.();
6624
+ if (file) {
6625
+ files.push(file);
6626
+ }
6627
+ if (files.length >= count) {
6628
+ break;
6629
+ }
6630
+ }
6631
+ return files;
6539
6632
  }
6540
- async function readVideoInfoFromSource(src) {
6633
+ async function pickChooseFileByInput(count, type, extensions) {
6541
6634
  if (typeof document === "undefined" || typeof document.createElement !== "function") {
6542
- throw new TypeError("video element is unavailable");
6635
+ return null;
6543
6636
  }
6544
- const video = document.createElement("video");
6545
- if (!video || typeof video.addEventListener !== "function") {
6546
- throw new Error("video element is unavailable");
6637
+ const input = document.createElement("input");
6638
+ if (!input || typeof input !== "object") {
6639
+ return null;
6547
6640
  }
6548
- return new Promise((resolve, reject) => {
6549
- const cleanup = () => {
6550
- if (typeof video.removeEventListener === "function") {
6551
- video.removeEventListener("loadedmetadata", onLoadedMetadata);
6552
- video.removeEventListener("error", onError);
6641
+ input.setAttribute("type", "file");
6642
+ input.setAttribute("accept", buildChooseFileInputAccept(type, extensions));
6643
+ if (count > 1) {
6644
+ input.setAttribute("multiple", "true");
6645
+ }
6646
+ input.setAttribute("style", "position: fixed; left: -9999px; top: -9999px; opacity: 0;");
6647
+ if (document.body) {
6648
+ document.body.append(input);
6649
+ }
6650
+ try {
6651
+ const files = await new Promise((resolve, reject) => {
6652
+ const onChange = () => {
6653
+ const selected = input.files ? Array.from(input.files) : [];
6654
+ if (selected.length) {
6655
+ resolve(selected.slice(0, count));
6656
+ return;
6657
+ }
6658
+ reject(new Error("no file selected"));
6659
+ };
6660
+ input.addEventListener("change", onChange, { once: true });
6661
+ if (typeof input.click === "function") {
6662
+ input.click();
6663
+ return;
6553
6664
  }
6554
- };
6555
- const onLoadedMetadata = () => {
6556
- cleanup();
6557
- resolve({
6558
- duration: normalizeVideoInfoNumber(video.duration),
6559
- width: normalizeVideoInfoNumber(video.videoWidth),
6560
- height: normalizeVideoInfoNumber(video.videoHeight)
6561
- });
6562
- };
6563
- const onError = () => {
6564
- cleanup();
6565
- reject(new Error("video load error"));
6566
- };
6567
- video.addEventListener("loadedmetadata", onLoadedMetadata, { once: true });
6568
- video.addEventListener("error", onError, { once: true });
6569
- video.src = src;
6570
- video.load?.();
6571
- });
6665
+ reject(new Error("file input click is unavailable"));
6666
+ });
6667
+ return files;
6668
+ } finally {
6669
+ if (input.parentNode) {
6670
+ input.parentNode.removeChild(input);
6671
+ }
6672
+ }
6673
+ }
6674
+ async function pickChooseFileFiles(count, type, extensions) {
6675
+ const viaPicker = await pickChooseFileByOpenPicker(count, type, extensions);
6676
+ if (Array.isArray(viaPicker)) {
6677
+ return viaPicker;
6678
+ }
6679
+ const viaInput = await pickChooseFileByInput(count, type, extensions);
6680
+ if (Array.isArray(viaInput)) {
6681
+ return viaInput;
6682
+ }
6683
+ throw new TypeError("File picker is unavailable in current environment.");
6572
6684
  }
6573
6685
 
6574
6686
  // src/runtime/polyfill/mediaProcess.ts
@@ -6647,62 +6759,7 @@ async function pickChooseVideoFile() {
6647
6759
  return files[0] ?? null;
6648
6760
  }
6649
6761
 
6650
- // src/runtime/polyfill/mediaApi.ts
6651
- function getImageInfoBridge(options) {
6652
- const src = typeof options?.src === "string" ? options.src.trim() : "";
6653
- if (!src) {
6654
- const failure = callWxAsyncFailure(options, "getImageInfo:fail invalid src");
6655
- return Promise.reject(failure);
6656
- }
6657
- return readImageInfoFromSource(src).then(({ width, height }) => callWxAsyncSuccess(options, {
6658
- errMsg: "getImageInfo:ok",
6659
- width,
6660
- height,
6661
- path: src,
6662
- type: inferImageTypeFromPath(src),
6663
- orientation: "up"
6664
- })).catch((error) => {
6665
- const message = error instanceof Error ? error.message : String(error);
6666
- const failure = callWxAsyncFailure(options, `getImageInfo:fail ${message}`);
6667
- return Promise.reject(failure);
6668
- });
6669
- }
6670
- function getVideoInfoBridge(options) {
6671
- const src = typeof options?.src === "string" ? options.src.trim() : "";
6672
- if (!src) {
6673
- const failure = callWxAsyncFailure(options, "getVideoInfo:fail invalid src");
6674
- return Promise.reject(failure);
6675
- }
6676
- const preset = readPresetVideoInfo(src);
6677
- const resolveResult = async () => {
6678
- if (preset) {
6679
- return preset;
6680
- }
6681
- return readVideoInfoFromSource(src);
6682
- };
6683
- return resolveResult().then((result) => {
6684
- const duration = normalizeVideoInfoNumber(result.duration);
6685
- const width = normalizeVideoInfoNumber(result.width);
6686
- const height = normalizeVideoInfoNumber(result.height);
6687
- const bitrate = normalizeVideoInfoNumber(result.bitrate);
6688
- const fps = normalizeVideoInfoNumber(result.fps);
6689
- return callWxAsyncSuccess(options, {
6690
- errMsg: "getVideoInfo:ok",
6691
- orientation: "up",
6692
- type: inferVideoTypeFromPath(src),
6693
- duration,
6694
- size: normalizeVideoInfoNumber(result.size),
6695
- width,
6696
- height,
6697
- bitrate,
6698
- fps
6699
- });
6700
- }).catch((error) => {
6701
- const message = error instanceof Error ? error.message : String(error);
6702
- const failure = callWxAsyncFailure(options, `getVideoInfo:fail ${message}`);
6703
- return Promise.reject(failure);
6704
- });
6705
- }
6762
+ // src/runtime/polyfill/mediaApi/picker.ts
6706
6763
  async function chooseImageBridge(options) {
6707
6764
  const count = normalizeChooseImageCount(options?.count);
6708
6765
  try {
@@ -6738,46 +6795,6 @@ async function chooseMediaBridge(options) {
6738
6795
  return Promise.reject(failure);
6739
6796
  }
6740
6797
  }
6741
- async function compressImageBridge(options) {
6742
- const src = typeof options?.src === "string" ? options.src.trim() : "";
6743
- if (!src) {
6744
- const failure = callWxAsyncFailure(options, "compressImage:fail invalid src");
6745
- return Promise.reject(failure);
6746
- }
6747
- const quality = normalizeCompressImageQuality(options?.quality);
6748
- try {
6749
- const tempFilePath = await compressImageByCanvas(src, quality);
6750
- return callWxAsyncSuccess(options, {
6751
- errMsg: "compressImage:ok",
6752
- tempFilePath
6753
- });
6754
- } catch (error) {
6755
- const message = error instanceof Error ? error.message : String(error);
6756
- const failure = callWxAsyncFailure(options, `compressImage:fail ${message}`);
6757
- return Promise.reject(failure);
6758
- }
6759
- }
6760
- function compressVideoBridge(options) {
6761
- const src = typeof options?.src === "string" ? options.src.trim() : "";
6762
- if (!src) {
6763
- const failure = callWxAsyncFailure(options, "compressVideo:fail invalid src");
6764
- return Promise.reject(failure);
6765
- }
6766
- const preset = readPresetCompressVideo(src);
6767
- const result = preset ?? {
6768
- tempFilePath: src,
6769
- size: 0,
6770
- duration: 0,
6771
- width: 0,
6772
- height: 0,
6773
- bitrate: 0,
6774
- fps: 0
6775
- };
6776
- return Promise.resolve(callWxAsyncSuccess(options, {
6777
- errMsg: "compressVideo:ok",
6778
- ...result
6779
- }));
6780
- }
6781
6798
  async function chooseVideoBridge(options) {
6782
6799
  try {
6783
6800
  const file = await pickChooseVideoFile();
@@ -6831,6 +6848,8 @@ async function chooseFileBridge(options) {
6831
6848
  return Promise.reject(failure);
6832
6849
  }
6833
6850
  }
6851
+
6852
+ // src/runtime/polyfill/mediaApi/preview.ts
6834
6853
  function previewImageBridge(options) {
6835
6854
  const urls = Array.isArray(options?.urls) ? options.urls.map((url) => String(url).trim()).filter(Boolean) : [];
6836
6855
  if (!urls.length) {
@@ -6865,61 +6884,48 @@ function openVideoEditorBridge(options) {
6865
6884
  tempFilePath
6866
6885
  }));
6867
6886
  }
6868
- function saveImageToPhotosAlbumBridge(options) {
6869
- const filePath = typeof options?.filePath === "string" ? options.filePath.trim() : "";
6870
- if (!filePath) {
6871
- const failure = callWxAsyncFailure(options, "saveImageToPhotosAlbum:fail invalid filePath");
6887
+
6888
+ // src/runtime/polyfill/mediaApi/process.ts
6889
+ async function compressImageBridge(options) {
6890
+ const src = typeof options?.src === "string" ? options.src.trim() : "";
6891
+ if (!src) {
6892
+ const failure = callWxAsyncFailure(options, "compressImage:fail invalid src");
6872
6893
  return Promise.reject(failure);
6873
6894
  }
6874
- triggerDownload(filePath);
6875
- return Promise.resolve(callWxAsyncSuccess(options, { errMsg: "saveImageToPhotosAlbum:ok" }));
6876
- }
6877
- function saveVideoToPhotosAlbumBridge(options) {
6878
- const filePath = typeof options?.filePath === "string" ? options.filePath.trim() : "";
6879
- if (!filePath) {
6880
- const failure = callWxAsyncFailure(options, "saveVideoToPhotosAlbum:fail invalid filePath");
6895
+ const quality = normalizeCompressImageQuality(options?.quality);
6896
+ try {
6897
+ const tempFilePath = await compressImageByCanvas(src, quality);
6898
+ return callWxAsyncSuccess(options, {
6899
+ errMsg: "compressImage:ok",
6900
+ tempFilePath
6901
+ });
6902
+ } catch (error) {
6903
+ const message = error instanceof Error ? error.message : String(error);
6904
+ const failure = callWxAsyncFailure(options, `compressImage:fail ${message}`);
6881
6905
  return Promise.reject(failure);
6882
6906
  }
6883
- triggerDownload(filePath);
6884
- return Promise.resolve(callWxAsyncSuccess(options, { errMsg: "saveVideoToPhotosAlbum:ok" }));
6885
6907
  }
6886
- function saveFileBridge(options) {
6887
- const tempFilePath = typeof options?.tempFilePath === "string" ? options.tempFilePath.trim() : "";
6888
- if (!tempFilePath) {
6889
- const failure = callWxAsyncFailure(options, "saveFile:fail invalid tempFilePath");
6908
+ function compressVideoBridge(options) {
6909
+ const src = typeof options?.src === "string" ? options.src.trim() : "";
6910
+ if (!src) {
6911
+ const failure = callWxAsyncFailure(options, "compressVideo:fail invalid src");
6890
6912
  return Promise.reject(failure);
6891
6913
  }
6892
- const savedFilePath = resolveSaveFilePath(tempFilePath, options?.filePath);
6893
- saveMemoryFile(tempFilePath, savedFilePath);
6914
+ const preset = readPresetCompressVideo(src);
6915
+ const result = preset ?? {
6916
+ tempFilePath: src,
6917
+ size: 0,
6918
+ duration: 0,
6919
+ width: 0,
6920
+ height: 0,
6921
+ bitrate: 0,
6922
+ fps: 0
6923
+ };
6894
6924
  return Promise.resolve(callWxAsyncSuccess(options, {
6895
- errMsg: "saveFile:ok",
6896
- savedFilePath
6925
+ errMsg: "compressVideo:ok",
6926
+ ...result
6897
6927
  }));
6898
6928
  }
6899
- function saveFileToDiskBridge(options) {
6900
- const filePath = typeof options?.filePath === "string" ? options.filePath.trim() : "";
6901
- if (!filePath) {
6902
- const failure = callWxAsyncFailure(options, "saveFileToDisk:fail invalid filePath");
6903
- return Promise.reject(failure);
6904
- }
6905
- const fileName = typeof options?.fileName === "string" ? options.fileName.trim() : "";
6906
- triggerDownload(filePath, fileName);
6907
- return Promise.resolve(callWxAsyncSuccess(options, { errMsg: "saveFileToDisk:ok" }));
6908
- }
6909
- function openDocumentBridge(options) {
6910
- const filePath = normalizeFilePath(options?.filePath);
6911
- if (!filePath) {
6912
- const failure = callWxAsyncFailure(options, "openDocument:fail invalid filePath");
6913
- return Promise.reject(failure);
6914
- }
6915
- const target = resolveOpenDocumentUrl(filePath);
6916
- if (!target) {
6917
- const failure = callWxAsyncFailure(options, "openDocument:fail document url is unavailable");
6918
- return Promise.reject(failure);
6919
- }
6920
- openTargetInNewWindow(target);
6921
- return Promise.resolve(callWxAsyncSuccess(options, { errMsg: "openDocument:ok" }));
6922
- }
6923
6929
 
6924
6930
  // src/runtime/polyfill/uiFeedback.ts
6925
6931
  var toastHideTimer;