@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.
package/dist/index.mjs CHANGED
@@ -4817,7 +4817,22 @@ function resolveOpenDocumentUrl(filePath) {
4817
4817
  return filePath;
4818
4818
  }
4819
4819
 
4820
- // src/runtime/polyfill/network.ts
4820
+ // src/runtime/polyfill/network/request.ts
4821
+ function resolveTimeoutSignal(timeout) {
4822
+ const controller = typeof AbortController === "function" ? new AbortController() : void 0;
4823
+ let timeoutTimer;
4824
+ if (timeout > 0 && controller) {
4825
+ timeoutTimer = setTimeout(() => controller.abort(), timeout);
4826
+ }
4827
+ return {
4828
+ signal: controller?.signal,
4829
+ clear: () => {
4830
+ if (timeoutTimer) {
4831
+ clearTimeout(timeoutTimer);
4832
+ }
4833
+ }
4834
+ };
4835
+ }
4821
4836
  function getRuntimeFetch() {
4822
4837
  const runtime = globalThis;
4823
4838
  const maybeFetch = runtime.fetch;
@@ -4924,21 +4939,6 @@ function stripUploadContentType(headers) {
4924
4939
  }
4925
4940
  return normalized;
4926
4941
  }
4927
- function resolveTimeoutSignal(timeout) {
4928
- const controller = typeof AbortController === "function" ? new AbortController() : void 0;
4929
- let timeoutTimer;
4930
- if (timeout > 0 && controller) {
4931
- timeoutTimer = setTimeout(() => controller.abort(), timeout);
4932
- }
4933
- return {
4934
- signal: controller?.signal,
4935
- clear: () => {
4936
- if (timeoutTimer) {
4937
- clearTimeout(timeoutTimer);
4938
- }
4939
- }
4940
- };
4941
- }
4942
4942
  async function performRequestByFetch(options) {
4943
4943
  const url = options?.url?.trim() ?? "";
4944
4944
  if (!url) {
@@ -5041,53 +5041,51 @@ async function performUploadByFetch(options) {
5041
5041
  timeoutControl.clear();
5042
5042
  }
5043
5043
  }
5044
+
5045
+ // src/runtime/polyfill/network/requestBridge.ts
5044
5046
  async function requestByFetchBridge(options) {
5045
5047
  try {
5046
5048
  const response = await performRequestByFetch(options);
5047
- const result = callWxAsyncSuccess(options, {
5049
+ return callWxAsyncSuccess(options, {
5048
5050
  errMsg: "request:ok",
5049
5051
  data: response.data,
5050
5052
  statusCode: response.statusCode,
5051
5053
  header: response.header
5052
5054
  });
5053
- return result;
5054
5055
  } catch (error) {
5055
5056
  const message = error instanceof Error ? error.message : String(error);
5056
- const failure = callWxAsyncFailure(options, `request:fail ${message}`);
5057
- return Promise.reject(failure);
5057
+ return Promise.reject(callWxAsyncFailure(options, `request:fail ${message}`));
5058
5058
  }
5059
5059
  }
5060
5060
  async function downloadFileByFetchBridge(options) {
5061
5061
  try {
5062
5062
  const response = await performDownloadByFetch(options);
5063
- const result = callWxAsyncSuccess(options, {
5063
+ return callWxAsyncSuccess(options, {
5064
5064
  errMsg: "downloadFile:ok",
5065
5065
  tempFilePath: response.tempFilePath,
5066
5066
  statusCode: response.statusCode
5067
5067
  });
5068
- return result;
5069
5068
  } catch (error) {
5070
5069
  const message = error instanceof Error ? error.message : String(error);
5071
- const failure = callWxAsyncFailure(options, `downloadFile:fail ${message}`);
5072
- return Promise.reject(failure);
5070
+ return Promise.reject(callWxAsyncFailure(options, `downloadFile:fail ${message}`));
5073
5071
  }
5074
5072
  }
5075
5073
  async function uploadFileByFetchBridge(options) {
5076
5074
  try {
5077
5075
  const response = await performUploadByFetch(options);
5078
- const result = callWxAsyncSuccess(options, {
5076
+ return callWxAsyncSuccess(options, {
5079
5077
  errMsg: "uploadFile:ok",
5080
5078
  data: response.data,
5081
5079
  statusCode: response.statusCode,
5082
5080
  header: response.header
5083
5081
  });
5084
- return result;
5085
5082
  } catch (error) {
5086
5083
  const message = error instanceof Error ? error.message : String(error);
5087
- const failure = callWxAsyncFailure(options, `uploadFile:fail ${message}`);
5088
- return Promise.reject(failure);
5084
+ return Promise.reject(callWxAsyncFailure(options, `uploadFile:fail ${message}`));
5089
5085
  }
5090
5086
  }
5087
+
5088
+ // src/runtime/polyfill/network/status.ts
5091
5089
  function getNavigatorConnection() {
5092
5090
  const runtimeNavigator = typeof navigator !== "undefined" ? navigator : void 0;
5093
5091
  return runtimeNavigator?.connection ?? runtimeNavigator?.mozConnection ?? runtimeNavigator?.webkitConnection;
@@ -5362,7 +5360,7 @@ function resolveSystemName(userAgent) {
5362
5360
  }
5363
5361
  function resolvePlatformName(userAgent, runtimeNavigator) {
5364
5362
  const navigatorWithUAData = runtimeNavigator;
5365
- const raw = navigatorWithUAData.userAgentData?.platform ?? runtimeNavigator?.platform ?? resolveSystemName(userAgent);
5363
+ const raw = navigatorWithUAData?.userAgentData?.platform ?? runtimeNavigator?.platform ?? resolveSystemName(userAgent);
5366
5364
  const normalized = raw.toLowerCase();
5367
5365
  if (normalized.includes("android")) {
5368
5366
  return "android";
@@ -7847,160 +7845,456 @@ async function getClipboardDataBridge(options) {
7847
7845
  }
7848
7846
  }
7849
7847
 
7850
- // src/runtime/polyfill/mediaPicker.ts
7851
- function normalizeChooseImageCount(count) {
7852
- if (typeof count !== "number" || Number.isNaN(count)) {
7853
- return 9;
7848
+ // src/runtime/polyfill/mediaApi/file.ts
7849
+ function saveImageToPhotosAlbumBridge(options) {
7850
+ const filePath = typeof options?.filePath === "string" ? options.filePath.trim() : "";
7851
+ if (!filePath) {
7852
+ const failure = callWxAsyncFailure(options, "saveImageToPhotosAlbum:fail invalid filePath");
7853
+ return Promise.reject(failure);
7854
7854
  }
7855
- return Math.max(1, Math.floor(count));
7855
+ triggerDownload(filePath);
7856
+ return Promise.resolve(callWxAsyncSuccess(options, { errMsg: "saveImageToPhotosAlbum:ok" }));
7856
7857
  }
7857
- function createTempFilePath(file) {
7858
- const runtimeUrl = globalThis.URL;
7859
- if (runtimeUrl && typeof runtimeUrl.createObjectURL === "function") {
7860
- const result = runtimeUrl.createObjectURL(file);
7861
- if (result) {
7862
- return result;
7863
- }
7858
+ function saveVideoToPhotosAlbumBridge(options) {
7859
+ const filePath = typeof options?.filePath === "string" ? options.filePath.trim() : "";
7860
+ if (!filePath) {
7861
+ const failure = callWxAsyncFailure(options, "saveVideoToPhotosAlbum:fail invalid filePath");
7862
+ return Promise.reject(failure);
7864
7863
  }
7865
- return file.name ?? "";
7864
+ triggerDownload(filePath);
7865
+ return Promise.resolve(callWxAsyncSuccess(options, { errMsg: "saveVideoToPhotosAlbum:ok" }));
7866
7866
  }
7867
- function normalizeChooseImageFile(file) {
7868
- return {
7869
- path: createTempFilePath(file),
7870
- size: typeof file.size === "number" ? file.size : 0,
7871
- type: typeof file.type === "string" ? file.type : "",
7872
- name: typeof file.name === "string" ? file.name : ""
7873
- };
7867
+ function saveFileBridge(options) {
7868
+ const tempFilePath = typeof options?.tempFilePath === "string" ? options.tempFilePath.trim() : "";
7869
+ if (!tempFilePath) {
7870
+ const failure = callWxAsyncFailure(options, "saveFile:fail invalid tempFilePath");
7871
+ return Promise.reject(failure);
7872
+ }
7873
+ const savedFilePath = resolveSaveFilePath(tempFilePath, options?.filePath);
7874
+ saveMemoryFile(tempFilePath, savedFilePath);
7875
+ return Promise.resolve(callWxAsyncSuccess(options, {
7876
+ errMsg: "saveFile:ok",
7877
+ savedFilePath
7878
+ }));
7874
7879
  }
7875
- async function pickImageFilesByOpenPicker(count) {
7876
- const picker = globalThis.showOpenFilePicker;
7877
- if (typeof picker !== "function") {
7878
- return null;
7880
+ function saveFileToDiskBridge(options) {
7881
+ const filePath = typeof options?.filePath === "string" ? options.filePath.trim() : "";
7882
+ if (!filePath) {
7883
+ const failure = callWxAsyncFailure(options, "saveFileToDisk:fail invalid filePath");
7884
+ return Promise.reject(failure);
7879
7885
  }
7880
- const handles = await picker({
7881
- multiple: count > 1,
7882
- types: [{
7883
- description: "Images",
7884
- accept: {
7885
- "image/*": [".png", ".jpg", ".jpeg", ".gif", ".webp", ".bmp", ".svg", ".avif"]
7886
- }
7887
- }]
7888
- });
7889
- const files = [];
7890
- for (const handle of handles ?? []) {
7891
- const file = await handle?.getFile?.();
7892
- if (file) {
7893
- files.push(file);
7894
- }
7895
- if (files.length >= count) {
7896
- break;
7897
- }
7886
+ const fileName = typeof options?.fileName === "string" ? options.fileName.trim() : "";
7887
+ triggerDownload(filePath, fileName);
7888
+ return Promise.resolve(callWxAsyncSuccess(options, { errMsg: "saveFileToDisk:ok" }));
7889
+ }
7890
+ function openDocumentBridge(options) {
7891
+ const filePath = normalizeFilePath(options?.filePath);
7892
+ if (!filePath) {
7893
+ const failure = callWxAsyncFailure(options, "openDocument:fail invalid filePath");
7894
+ return Promise.reject(failure);
7898
7895
  }
7899
- return files;
7896
+ const target = resolveOpenDocumentUrl(filePath);
7897
+ if (!target) {
7898
+ const failure = callWxAsyncFailure(options, "openDocument:fail document url is unavailable");
7899
+ return Promise.reject(failure);
7900
+ }
7901
+ openTargetInNewWindow(target);
7902
+ return Promise.resolve(callWxAsyncSuccess(options, { errMsg: "openDocument:ok" }));
7900
7903
  }
7901
- async function pickImageFilesByInput(count) {
7902
- if (typeof document === "undefined" || typeof document.createElement !== "function") {
7903
- return null;
7904
+
7905
+ // src/runtime/polyfill/mediaInfo.ts
7906
+ function inferImageTypeFromPath(path) {
7907
+ const lower = path.toLowerCase();
7908
+ if (lower.includes(".png")) {
7909
+ return "png";
7904
7910
  }
7905
- const input = document.createElement("input");
7906
- if (!input || typeof input !== "object") {
7907
- return null;
7911
+ if (lower.includes(".jpg") || lower.includes(".jpeg")) {
7912
+ return "jpg";
7908
7913
  }
7909
- input.setAttribute("type", "file");
7910
- input.setAttribute("accept", "image/*");
7911
- if (count > 1) {
7912
- input.setAttribute("multiple", "true");
7914
+ if (lower.includes(".gif")) {
7915
+ return "gif";
7913
7916
  }
7914
- input.setAttribute("style", "position: fixed; left: -9999px; top: -9999px; opacity: 0;");
7915
- if (document.body) {
7916
- document.body.append(input);
7917
+ if (lower.includes(".webp")) {
7918
+ return "webp";
7917
7919
  }
7918
- try {
7919
- const files = await new Promise((resolve4, reject) => {
7920
- const onChange = () => {
7921
- const selected = input.files ? Array.from(input.files) : [];
7922
- if (selected.length) {
7923
- resolve4(selected.slice(0, count));
7924
- return;
7925
- }
7926
- reject(new Error("no file selected"));
7927
- };
7928
- input.addEventListener("change", onChange, { once: true });
7929
- if (typeof input.click === "function") {
7930
- input.click();
7931
- return;
7932
- }
7933
- reject(new Error("file input click is unavailable"));
7934
- });
7935
- return files;
7936
- } finally {
7937
- if (input.parentNode) {
7938
- input.parentNode.removeChild(input);
7939
- }
7920
+ if (lower.includes(".bmp")) {
7921
+ return "bmp";
7940
7922
  }
7941
- }
7942
- async function pickChooseImageFiles(count) {
7943
- const viaPicker = await pickImageFilesByOpenPicker(count);
7944
- if (Array.isArray(viaPicker)) {
7945
- return viaPicker;
7923
+ if (lower.includes(".svg")) {
7924
+ return "svg";
7946
7925
  }
7947
- const viaInput = await pickImageFilesByInput(count);
7948
- if (Array.isArray(viaInput)) {
7949
- return viaInput;
7926
+ if (lower.includes(".avif")) {
7927
+ return "avif";
7950
7928
  }
7951
- throw new TypeError("Image picker is unavailable in current environment.");
7929
+ return "unknown";
7952
7930
  }
7953
- function normalizeChooseMediaCount(count) {
7954
- if (typeof count !== "number" || Number.isNaN(count)) {
7955
- return 1;
7931
+ function inferVideoTypeFromPath(path) {
7932
+ const lower = path.toLowerCase();
7933
+ if (lower.includes(".mp4")) {
7934
+ return "mp4";
7956
7935
  }
7957
- return Math.max(1, Math.floor(count));
7958
- }
7959
- function normalizeChooseMediaTypes(mediaType) {
7960
- const normalized = /* @__PURE__ */ new Set();
7961
- for (const item of mediaType ?? []) {
7962
- if (item === "image") {
7963
- normalized.add("image");
7964
- continue;
7965
- }
7966
- if (item === "video") {
7967
- normalized.add("video");
7968
- continue;
7969
- }
7970
- if (item === "mix") {
7971
- normalized.add("image");
7972
- normalized.add("video");
7973
- }
7936
+ if (lower.includes(".mov")) {
7937
+ return "mov";
7974
7938
  }
7975
- if (normalized.size === 0) {
7976
- normalized.add("image");
7977
- normalized.add("video");
7939
+ if (lower.includes(".m4v")) {
7940
+ return "m4v";
7978
7941
  }
7979
- return normalized;
7980
- }
7981
- function buildChooseMediaOpenPickerAccept(types) {
7982
- const accept = {};
7983
- if (types.has("image")) {
7984
- accept["image/*"] = [".png", ".jpg", ".jpeg", ".gif", ".webp", ".bmp", ".svg", ".avif"];
7942
+ if (lower.includes(".webm")) {
7943
+ return "webm";
7985
7944
  }
7986
- if (types.has("video")) {
7987
- accept["video/*"] = [".mp4", ".mov", ".m4v", ".webm"];
7945
+ if (lower.includes(".avi")) {
7946
+ return "avi";
7988
7947
  }
7989
- return accept;
7990
- }
7991
- function buildChooseMediaInputAccept(types) {
7992
- if (types.size === 2) {
7993
- return "image/*,video/*";
7948
+ if (lower.includes(".mkv")) {
7949
+ return "mkv";
7994
7950
  }
7995
- return types.has("video") ? "video/*" : "image/*";
7951
+ return "unknown";
7996
7952
  }
7997
- function inferChooseMediaFileType(file) {
7998
- const mimeType = typeof file.type === "string" ? file.type.toLowerCase() : "";
7999
- if (mimeType.startsWith("video/")) {
8000
- return "video";
8001
- }
8002
- if (mimeType.startsWith("image/")) {
8003
- return "image";
7953
+ function normalizeVideoInfoNumber(value) {
7954
+ if (typeof value !== "number" || Number.isNaN(value) || value < 0) {
7955
+ return 0;
7956
+ }
7957
+ return value;
7958
+ }
7959
+ function normalizeVideoInfoPreset(value, src) {
7960
+ if (!value || typeof value !== "object") {
7961
+ return null;
7962
+ }
7963
+ const info = value;
7964
+ return {
7965
+ size: normalizeVideoInfoNumber(info.size),
7966
+ duration: normalizeVideoInfoNumber(info.duration),
7967
+ width: normalizeVideoInfoNumber(info.width),
7968
+ height: normalizeVideoInfoNumber(info.height),
7969
+ fps: normalizeVideoInfoNumber(info.fps),
7970
+ bitrate: normalizeVideoInfoNumber(info.bitrate),
7971
+ type: typeof info.type === "string" ? info.type : inferVideoTypeFromPath(src),
7972
+ orientation: "up"
7973
+ };
7974
+ }
7975
+ function readPresetVideoInfo(src) {
7976
+ const runtimeGlobal = globalThis;
7977
+ const preset = runtimeGlobal.__weappViteWebVideoInfo;
7978
+ if (typeof preset === "function") {
7979
+ return normalizeVideoInfoPreset(preset(src), src);
7980
+ }
7981
+ if (preset && typeof preset === "object") {
7982
+ const sourcePreset = preset[src];
7983
+ if (sourcePreset && typeof sourcePreset === "object") {
7984
+ return normalizeVideoInfoPreset(sourcePreset, src);
7985
+ }
7986
+ return normalizeVideoInfoPreset(preset, src);
7987
+ }
7988
+ return null;
7989
+ }
7990
+ function normalizeCompressVideoResult(value, src) {
7991
+ if (!value || typeof value !== "object") {
7992
+ return null;
7993
+ }
7994
+ const info = value;
7995
+ const tempFilePath = typeof info.tempFilePath === "string" && info.tempFilePath.trim() ? info.tempFilePath.trim() : src;
7996
+ return {
7997
+ tempFilePath,
7998
+ size: normalizeVideoInfoNumber(info.size),
7999
+ duration: normalizeVideoInfoNumber(info.duration),
8000
+ width: normalizeVideoInfoNumber(info.width),
8001
+ height: normalizeVideoInfoNumber(info.height),
8002
+ bitrate: normalizeVideoInfoNumber(info.bitrate),
8003
+ fps: normalizeVideoInfoNumber(info.fps)
8004
+ };
8005
+ }
8006
+ function readPresetCompressVideo(src) {
8007
+ const runtimeGlobal = globalThis;
8008
+ const preset = runtimeGlobal.__weappViteWebCompressVideo;
8009
+ if (typeof preset === "function") {
8010
+ return normalizeCompressVideoResult(preset(src), src);
8011
+ }
8012
+ if (preset && typeof preset === "object") {
8013
+ const sourcePreset = preset[src];
8014
+ if (sourcePreset && typeof sourcePreset === "object") {
8015
+ return normalizeCompressVideoResult(sourcePreset, src);
8016
+ }
8017
+ return normalizeCompressVideoResult(preset, src);
8018
+ }
8019
+ if (typeof preset === "string" && preset.trim()) {
8020
+ return {
8021
+ tempFilePath: preset.trim(),
8022
+ size: 0,
8023
+ duration: 0,
8024
+ width: 0,
8025
+ height: 0,
8026
+ bitrate: 0,
8027
+ fps: 0
8028
+ };
8029
+ }
8030
+ return null;
8031
+ }
8032
+ async function readImageInfoFromSource(src) {
8033
+ const ImageCtor = globalThis.Image;
8034
+ if (typeof ImageCtor !== "function") {
8035
+ throw new TypeError("Image is unavailable");
8036
+ }
8037
+ return new Promise((resolve4, reject) => {
8038
+ const image = new ImageCtor();
8039
+ image.onload = () => {
8040
+ const width = Number(image.naturalWidth ?? image.width ?? 0);
8041
+ const height = Number(image.naturalHeight ?? image.height ?? 0);
8042
+ resolve4({
8043
+ width: Number.isFinite(width) ? width : 0,
8044
+ height: Number.isFinite(height) ? height : 0
8045
+ });
8046
+ };
8047
+ image.onerror = () => {
8048
+ reject(new Error("image load error"));
8049
+ };
8050
+ image.src = src;
8051
+ });
8052
+ }
8053
+ async function readVideoInfoFromSource(src) {
8054
+ if (typeof document === "undefined" || typeof document.createElement !== "function") {
8055
+ throw new TypeError("video element is unavailable");
8056
+ }
8057
+ const video = document.createElement("video");
8058
+ if (!video || typeof video.addEventListener !== "function") {
8059
+ throw new Error("video element is unavailable");
8060
+ }
8061
+ return new Promise((resolve4, reject) => {
8062
+ const cleanup = () => {
8063
+ if (typeof video.removeEventListener === "function") {
8064
+ video.removeEventListener("loadedmetadata", onLoadedMetadata);
8065
+ video.removeEventListener("error", onError);
8066
+ }
8067
+ };
8068
+ const onLoadedMetadata = () => {
8069
+ cleanup();
8070
+ resolve4({
8071
+ duration: normalizeVideoInfoNumber(video.duration),
8072
+ width: normalizeVideoInfoNumber(video.videoWidth),
8073
+ height: normalizeVideoInfoNumber(video.videoHeight)
8074
+ });
8075
+ };
8076
+ const onError = () => {
8077
+ cleanup();
8078
+ reject(new Error("video load error"));
8079
+ };
8080
+ video.addEventListener("loadedmetadata", onLoadedMetadata, { once: true });
8081
+ video.addEventListener("error", onError, { once: true });
8082
+ video.src = src;
8083
+ video.load?.();
8084
+ });
8085
+ }
8086
+
8087
+ // src/runtime/polyfill/mediaApi/info.ts
8088
+ function getImageInfoBridge(options) {
8089
+ const src = typeof options?.src === "string" ? options.src.trim() : "";
8090
+ if (!src) {
8091
+ const failure = callWxAsyncFailure(options, "getImageInfo:fail invalid src");
8092
+ return Promise.reject(failure);
8093
+ }
8094
+ return readImageInfoFromSource(src).then(({ width, height }) => callWxAsyncSuccess(options, {
8095
+ errMsg: "getImageInfo:ok",
8096
+ width,
8097
+ height,
8098
+ path: src,
8099
+ type: inferImageTypeFromPath(src),
8100
+ orientation: "up"
8101
+ })).catch((error) => {
8102
+ const message = error instanceof Error ? error.message : String(error);
8103
+ const failure = callWxAsyncFailure(options, `getImageInfo:fail ${message}`);
8104
+ return Promise.reject(failure);
8105
+ });
8106
+ }
8107
+ function getVideoInfoBridge(options) {
8108
+ const src = typeof options?.src === "string" ? options.src.trim() : "";
8109
+ if (!src) {
8110
+ const failure = callWxAsyncFailure(options, "getVideoInfo:fail invalid src");
8111
+ return Promise.reject(failure);
8112
+ }
8113
+ const preset = readPresetVideoInfo(src);
8114
+ const resolveResult = async () => {
8115
+ if (preset) {
8116
+ return preset;
8117
+ }
8118
+ return readVideoInfoFromSource(src);
8119
+ };
8120
+ return resolveResult().then((result) => {
8121
+ const duration = normalizeVideoInfoNumber(result.duration);
8122
+ const width = normalizeVideoInfoNumber(result.width);
8123
+ const height = normalizeVideoInfoNumber(result.height);
8124
+ const bitrate = normalizeVideoInfoNumber(result.bitrate);
8125
+ const fps = normalizeVideoInfoNumber(result.fps);
8126
+ return callWxAsyncSuccess(options, {
8127
+ errMsg: "getVideoInfo:ok",
8128
+ orientation: "up",
8129
+ type: inferVideoTypeFromPath(src),
8130
+ duration,
8131
+ size: normalizeVideoInfoNumber(result.size),
8132
+ width,
8133
+ height,
8134
+ bitrate,
8135
+ fps
8136
+ });
8137
+ }).catch((error) => {
8138
+ const message = error instanceof Error ? error.message : String(error);
8139
+ const failure = callWxAsyncFailure(options, `getVideoInfo:fail ${message}`);
8140
+ return Promise.reject(failure);
8141
+ });
8142
+ }
8143
+
8144
+ // src/runtime/polyfill/mediaPicker.ts
8145
+ function normalizeChooseImageCount(count) {
8146
+ if (typeof count !== "number" || Number.isNaN(count)) {
8147
+ return 9;
8148
+ }
8149
+ return Math.max(1, Math.floor(count));
8150
+ }
8151
+ function createTempFilePath(file) {
8152
+ const runtimeUrl = globalThis.URL;
8153
+ if (runtimeUrl && typeof runtimeUrl.createObjectURL === "function") {
8154
+ const result = runtimeUrl.createObjectURL(file);
8155
+ if (result) {
8156
+ return result;
8157
+ }
8158
+ }
8159
+ return file.name ?? "";
8160
+ }
8161
+ function normalizeChooseImageFile(file) {
8162
+ return {
8163
+ path: createTempFilePath(file),
8164
+ size: typeof file.size === "number" ? file.size : 0,
8165
+ type: typeof file.type === "string" ? file.type : "",
8166
+ name: typeof file.name === "string" ? file.name : ""
8167
+ };
8168
+ }
8169
+ async function pickImageFilesByOpenPicker(count) {
8170
+ const picker = globalThis.showOpenFilePicker;
8171
+ if (typeof picker !== "function") {
8172
+ return null;
8173
+ }
8174
+ const handles = await picker({
8175
+ multiple: count > 1,
8176
+ types: [{
8177
+ description: "Images",
8178
+ accept: {
8179
+ "image/*": [".png", ".jpg", ".jpeg", ".gif", ".webp", ".bmp", ".svg", ".avif"]
8180
+ }
8181
+ }]
8182
+ });
8183
+ const files = [];
8184
+ for (const handle of handles ?? []) {
8185
+ const file = await handle?.getFile?.();
8186
+ if (file) {
8187
+ files.push(file);
8188
+ }
8189
+ if (files.length >= count) {
8190
+ break;
8191
+ }
8192
+ }
8193
+ return files;
8194
+ }
8195
+ async function pickImageFilesByInput(count) {
8196
+ if (typeof document === "undefined" || typeof document.createElement !== "function") {
8197
+ return null;
8198
+ }
8199
+ const input = document.createElement("input");
8200
+ if (!input || typeof input !== "object") {
8201
+ return null;
8202
+ }
8203
+ input.setAttribute("type", "file");
8204
+ input.setAttribute("accept", "image/*");
8205
+ if (count > 1) {
8206
+ input.setAttribute("multiple", "true");
8207
+ }
8208
+ input.setAttribute("style", "position: fixed; left: -9999px; top: -9999px; opacity: 0;");
8209
+ if (document.body) {
8210
+ document.body.append(input);
8211
+ }
8212
+ try {
8213
+ const files = await new Promise((resolve4, reject) => {
8214
+ const onChange = () => {
8215
+ const selected = input.files ? Array.from(input.files) : [];
8216
+ if (selected.length) {
8217
+ resolve4(selected.slice(0, count));
8218
+ return;
8219
+ }
8220
+ reject(new Error("no file selected"));
8221
+ };
8222
+ input.addEventListener("change", onChange, { once: true });
8223
+ if (typeof input.click === "function") {
8224
+ input.click();
8225
+ return;
8226
+ }
8227
+ reject(new Error("file input click is unavailable"));
8228
+ });
8229
+ return files;
8230
+ } finally {
8231
+ if (input.parentNode) {
8232
+ input.parentNode.removeChild(input);
8233
+ }
8234
+ }
8235
+ }
8236
+ async function pickChooseImageFiles(count) {
8237
+ const viaPicker = await pickImageFilesByOpenPicker(count);
8238
+ if (Array.isArray(viaPicker)) {
8239
+ return viaPicker;
8240
+ }
8241
+ const viaInput = await pickImageFilesByInput(count);
8242
+ if (Array.isArray(viaInput)) {
8243
+ return viaInput;
8244
+ }
8245
+ throw new TypeError("Image picker is unavailable in current environment.");
8246
+ }
8247
+ function normalizeChooseMediaCount(count) {
8248
+ if (typeof count !== "number" || Number.isNaN(count)) {
8249
+ return 1;
8250
+ }
8251
+ return Math.max(1, Math.floor(count));
8252
+ }
8253
+ function normalizeChooseMediaTypes(mediaType) {
8254
+ const normalized = /* @__PURE__ */ new Set();
8255
+ for (const item of mediaType ?? []) {
8256
+ if (item === "image") {
8257
+ normalized.add("image");
8258
+ continue;
8259
+ }
8260
+ if (item === "video") {
8261
+ normalized.add("video");
8262
+ continue;
8263
+ }
8264
+ if (item === "mix") {
8265
+ normalized.add("image");
8266
+ normalized.add("video");
8267
+ }
8268
+ }
8269
+ if (normalized.size === 0) {
8270
+ normalized.add("image");
8271
+ normalized.add("video");
8272
+ }
8273
+ return normalized;
8274
+ }
8275
+ function buildChooseMediaOpenPickerAccept(types) {
8276
+ const accept = {};
8277
+ if (types.has("image")) {
8278
+ accept["image/*"] = [".png", ".jpg", ".jpeg", ".gif", ".webp", ".bmp", ".svg", ".avif"];
8279
+ }
8280
+ if (types.has("video")) {
8281
+ accept["video/*"] = [".mp4", ".mov", ".m4v", ".webm"];
8282
+ }
8283
+ return accept;
8284
+ }
8285
+ function buildChooseMediaInputAccept(types) {
8286
+ if (types.size === 2) {
8287
+ return "image/*,video/*";
8288
+ }
8289
+ return types.has("video") ? "video/*" : "image/*";
8290
+ }
8291
+ function inferChooseMediaFileType(file) {
8292
+ const mimeType = typeof file.type === "string" ? file.type.toLowerCase() : "";
8293
+ if (mimeType.startsWith("video/")) {
8294
+ return "video";
8295
+ }
8296
+ if (mimeType.startsWith("image/")) {
8297
+ return "image";
8004
8298
  }
8005
8299
  const fileName = typeof file.name === "string" ? file.name.toLowerCase() : "";
8006
8300
  if (/\.(?:mp4|mov|m4v|webm)$/i.test(fileName)) {
@@ -8250,249 +8544,67 @@ async function pickChooseFileByOpenPicker(count, type, extensions) {
8250
8544
  });
8251
8545
  const files = [];
8252
8546
  for (const handle of handles ?? []) {
8253
- const file = await handle?.getFile?.();
8254
- if (file) {
8255
- files.push(file);
8256
- }
8257
- if (files.length >= count) {
8258
- break;
8259
- }
8260
- }
8261
- return files;
8262
- }
8263
- async function pickChooseFileByInput(count, type, extensions) {
8264
- if (typeof document === "undefined" || typeof document.createElement !== "function") {
8265
- return null;
8266
- }
8267
- const input = document.createElement("input");
8268
- if (!input || typeof input !== "object") {
8269
- return null;
8270
- }
8271
- input.setAttribute("type", "file");
8272
- input.setAttribute("accept", buildChooseFileInputAccept(type, extensions));
8273
- if (count > 1) {
8274
- input.setAttribute("multiple", "true");
8275
- }
8276
- input.setAttribute("style", "position: fixed; left: -9999px; top: -9999px; opacity: 0;");
8277
- if (document.body) {
8278
- document.body.append(input);
8279
- }
8280
- try {
8281
- const files = await new Promise((resolve4, reject) => {
8282
- const onChange = () => {
8283
- const selected = input.files ? Array.from(input.files) : [];
8284
- if (selected.length) {
8285
- resolve4(selected.slice(0, count));
8286
- return;
8287
- }
8288
- reject(new Error("no file selected"));
8289
- };
8290
- input.addEventListener("change", onChange, { once: true });
8291
- if (typeof input.click === "function") {
8292
- input.click();
8293
- return;
8294
- }
8295
- reject(new Error("file input click is unavailable"));
8296
- });
8297
- return files;
8298
- } finally {
8299
- if (input.parentNode) {
8300
- input.parentNode.removeChild(input);
8301
- }
8302
- }
8303
- }
8304
- async function pickChooseFileFiles(count, type, extensions) {
8305
- const viaPicker = await pickChooseFileByOpenPicker(count, type, extensions);
8306
- if (Array.isArray(viaPicker)) {
8307
- return viaPicker;
8308
- }
8309
- const viaInput = await pickChooseFileByInput(count, type, extensions);
8310
- if (Array.isArray(viaInput)) {
8311
- return viaInput;
8312
- }
8313
- throw new TypeError("File picker is unavailable in current environment.");
8314
- }
8315
-
8316
- // src/runtime/polyfill/mediaInfo.ts
8317
- function inferImageTypeFromPath(path) {
8318
- const lower = path.toLowerCase();
8319
- if (lower.includes(".png")) {
8320
- return "png";
8321
- }
8322
- if (lower.includes(".jpg") || lower.includes(".jpeg")) {
8323
- return "jpg";
8324
- }
8325
- if (lower.includes(".gif")) {
8326
- return "gif";
8327
- }
8328
- if (lower.includes(".webp")) {
8329
- return "webp";
8330
- }
8331
- if (lower.includes(".bmp")) {
8332
- return "bmp";
8333
- }
8334
- if (lower.includes(".svg")) {
8335
- return "svg";
8336
- }
8337
- if (lower.includes(".avif")) {
8338
- return "avif";
8339
- }
8340
- return "unknown";
8341
- }
8342
- function inferVideoTypeFromPath(path) {
8343
- const lower = path.toLowerCase();
8344
- if (lower.includes(".mp4")) {
8345
- return "mp4";
8346
- }
8347
- if (lower.includes(".mov")) {
8348
- return "mov";
8349
- }
8350
- if (lower.includes(".m4v")) {
8351
- return "m4v";
8352
- }
8353
- if (lower.includes(".webm")) {
8354
- return "webm";
8355
- }
8356
- if (lower.includes(".avi")) {
8357
- return "avi";
8358
- }
8359
- if (lower.includes(".mkv")) {
8360
- return "mkv";
8361
- }
8362
- return "unknown";
8363
- }
8364
- function normalizeVideoInfoNumber(value) {
8365
- if (typeof value !== "number" || Number.isNaN(value) || value < 0) {
8366
- return 0;
8367
- }
8368
- return value;
8369
- }
8370
- function normalizeVideoInfoPreset(value, src) {
8371
- if (!value || typeof value !== "object") {
8372
- return null;
8373
- }
8374
- const info = value;
8375
- return {
8376
- size: normalizeVideoInfoNumber(info.size),
8377
- duration: normalizeVideoInfoNumber(info.duration),
8378
- width: normalizeVideoInfoNumber(info.width),
8379
- height: normalizeVideoInfoNumber(info.height),
8380
- fps: normalizeVideoInfoNumber(info.fps),
8381
- bitrate: normalizeVideoInfoNumber(info.bitrate),
8382
- type: typeof info.type === "string" ? info.type : inferVideoTypeFromPath(src),
8383
- orientation: "up"
8384
- };
8385
- }
8386
- function readPresetVideoInfo(src) {
8387
- const runtimeGlobal = globalThis;
8388
- const preset = runtimeGlobal.__weappViteWebVideoInfo;
8389
- if (typeof preset === "function") {
8390
- return normalizeVideoInfoPreset(preset(src), src);
8391
- }
8392
- if (preset && typeof preset === "object") {
8393
- const sourcePreset = preset[src];
8394
- if (sourcePreset && typeof sourcePreset === "object") {
8395
- return normalizeVideoInfoPreset(sourcePreset, src);
8396
- }
8397
- return normalizeVideoInfoPreset(preset, src);
8398
- }
8399
- return null;
8400
- }
8401
- function normalizeCompressVideoResult(value, src) {
8402
- if (!value || typeof value !== "object") {
8403
- return null;
8404
- }
8405
- const info = value;
8406
- const tempFilePath = typeof info.tempFilePath === "string" && info.tempFilePath.trim() ? info.tempFilePath.trim() : src;
8407
- return {
8408
- tempFilePath,
8409
- size: normalizeVideoInfoNumber(info.size),
8410
- duration: normalizeVideoInfoNumber(info.duration),
8411
- width: normalizeVideoInfoNumber(info.width),
8412
- height: normalizeVideoInfoNumber(info.height),
8413
- bitrate: normalizeVideoInfoNumber(info.bitrate),
8414
- fps: normalizeVideoInfoNumber(info.fps)
8415
- };
8416
- }
8417
- function readPresetCompressVideo(src) {
8418
- const runtimeGlobal = globalThis;
8419
- const preset = runtimeGlobal.__weappViteWebCompressVideo;
8420
- if (typeof preset === "function") {
8421
- return normalizeCompressVideoResult(preset(src), src);
8422
- }
8423
- if (preset && typeof preset === "object") {
8424
- const sourcePreset = preset[src];
8425
- if (sourcePreset && typeof sourcePreset === "object") {
8426
- return normalizeCompressVideoResult(sourcePreset, src);
8427
- }
8428
- return normalizeCompressVideoResult(preset, src);
8429
- }
8430
- if (typeof preset === "string" && preset.trim()) {
8431
- return {
8432
- tempFilePath: preset.trim(),
8433
- size: 0,
8434
- duration: 0,
8435
- width: 0,
8436
- height: 0,
8437
- bitrate: 0,
8438
- fps: 0
8439
- };
8440
- }
8441
- return null;
8442
- }
8443
- async function readImageInfoFromSource(src) {
8444
- const ImageCtor = globalThis.Image;
8445
- if (typeof ImageCtor !== "function") {
8446
- throw new TypeError("Image is unavailable");
8447
- }
8448
- return new Promise((resolve4, reject) => {
8449
- const image = new ImageCtor();
8450
- image.onload = () => {
8451
- const width = Number(image.naturalWidth ?? image.width ?? 0);
8452
- const height = Number(image.naturalHeight ?? image.height ?? 0);
8453
- resolve4({
8454
- width: Number.isFinite(width) ? width : 0,
8455
- height: Number.isFinite(height) ? height : 0
8456
- });
8457
- };
8458
- image.onerror = () => {
8459
- reject(new Error("image load error"));
8460
- };
8461
- image.src = src;
8462
- });
8547
+ const file = await handle?.getFile?.();
8548
+ if (file) {
8549
+ files.push(file);
8550
+ }
8551
+ if (files.length >= count) {
8552
+ break;
8553
+ }
8554
+ }
8555
+ return files;
8463
8556
  }
8464
- async function readVideoInfoFromSource(src) {
8557
+ async function pickChooseFileByInput(count, type, extensions) {
8465
8558
  if (typeof document === "undefined" || typeof document.createElement !== "function") {
8466
- throw new TypeError("video element is unavailable");
8559
+ return null;
8467
8560
  }
8468
- const video = document.createElement("video");
8469
- if (!video || typeof video.addEventListener !== "function") {
8470
- throw new Error("video element is unavailable");
8561
+ const input = document.createElement("input");
8562
+ if (!input || typeof input !== "object") {
8563
+ return null;
8471
8564
  }
8472
- return new Promise((resolve4, reject) => {
8473
- const cleanup = () => {
8474
- if (typeof video.removeEventListener === "function") {
8475
- video.removeEventListener("loadedmetadata", onLoadedMetadata);
8476
- video.removeEventListener("error", onError);
8565
+ input.setAttribute("type", "file");
8566
+ input.setAttribute("accept", buildChooseFileInputAccept(type, extensions));
8567
+ if (count > 1) {
8568
+ input.setAttribute("multiple", "true");
8569
+ }
8570
+ input.setAttribute("style", "position: fixed; left: -9999px; top: -9999px; opacity: 0;");
8571
+ if (document.body) {
8572
+ document.body.append(input);
8573
+ }
8574
+ try {
8575
+ const files = await new Promise((resolve4, reject) => {
8576
+ const onChange = () => {
8577
+ const selected = input.files ? Array.from(input.files) : [];
8578
+ if (selected.length) {
8579
+ resolve4(selected.slice(0, count));
8580
+ return;
8581
+ }
8582
+ reject(new Error("no file selected"));
8583
+ };
8584
+ input.addEventListener("change", onChange, { once: true });
8585
+ if (typeof input.click === "function") {
8586
+ input.click();
8587
+ return;
8477
8588
  }
8478
- };
8479
- const onLoadedMetadata = () => {
8480
- cleanup();
8481
- resolve4({
8482
- duration: normalizeVideoInfoNumber(video.duration),
8483
- width: normalizeVideoInfoNumber(video.videoWidth),
8484
- height: normalizeVideoInfoNumber(video.videoHeight)
8485
- });
8486
- };
8487
- const onError = () => {
8488
- cleanup();
8489
- reject(new Error("video load error"));
8490
- };
8491
- video.addEventListener("loadedmetadata", onLoadedMetadata, { once: true });
8492
- video.addEventListener("error", onError, { once: true });
8493
- video.src = src;
8494
- video.load?.();
8495
- });
8589
+ reject(new Error("file input click is unavailable"));
8590
+ });
8591
+ return files;
8592
+ } finally {
8593
+ if (input.parentNode) {
8594
+ input.parentNode.removeChild(input);
8595
+ }
8596
+ }
8597
+ }
8598
+ async function pickChooseFileFiles(count, type, extensions) {
8599
+ const viaPicker = await pickChooseFileByOpenPicker(count, type, extensions);
8600
+ if (Array.isArray(viaPicker)) {
8601
+ return viaPicker;
8602
+ }
8603
+ const viaInput = await pickChooseFileByInput(count, type, extensions);
8604
+ if (Array.isArray(viaInput)) {
8605
+ return viaInput;
8606
+ }
8607
+ throw new TypeError("File picker is unavailable in current environment.");
8496
8608
  }
8497
8609
 
8498
8610
  // src/runtime/polyfill/mediaProcess.ts
@@ -8571,62 +8683,7 @@ async function pickChooseVideoFile() {
8571
8683
  return files[0] ?? null;
8572
8684
  }
8573
8685
 
8574
- // src/runtime/polyfill/mediaApi.ts
8575
- function getImageInfoBridge(options) {
8576
- const src = typeof options?.src === "string" ? options.src.trim() : "";
8577
- if (!src) {
8578
- const failure = callWxAsyncFailure(options, "getImageInfo:fail invalid src");
8579
- return Promise.reject(failure);
8580
- }
8581
- return readImageInfoFromSource(src).then(({ width, height }) => callWxAsyncSuccess(options, {
8582
- errMsg: "getImageInfo:ok",
8583
- width,
8584
- height,
8585
- path: src,
8586
- type: inferImageTypeFromPath(src),
8587
- orientation: "up"
8588
- })).catch((error) => {
8589
- const message = error instanceof Error ? error.message : String(error);
8590
- const failure = callWxAsyncFailure(options, `getImageInfo:fail ${message}`);
8591
- return Promise.reject(failure);
8592
- });
8593
- }
8594
- function getVideoInfoBridge(options) {
8595
- const src = typeof options?.src === "string" ? options.src.trim() : "";
8596
- if (!src) {
8597
- const failure = callWxAsyncFailure(options, "getVideoInfo:fail invalid src");
8598
- return Promise.reject(failure);
8599
- }
8600
- const preset = readPresetVideoInfo(src);
8601
- const resolveResult = async () => {
8602
- if (preset) {
8603
- return preset;
8604
- }
8605
- return readVideoInfoFromSource(src);
8606
- };
8607
- return resolveResult().then((result) => {
8608
- const duration = normalizeVideoInfoNumber(result.duration);
8609
- const width = normalizeVideoInfoNumber(result.width);
8610
- const height = normalizeVideoInfoNumber(result.height);
8611
- const bitrate = normalizeVideoInfoNumber(result.bitrate);
8612
- const fps = normalizeVideoInfoNumber(result.fps);
8613
- return callWxAsyncSuccess(options, {
8614
- errMsg: "getVideoInfo:ok",
8615
- orientation: "up",
8616
- type: inferVideoTypeFromPath(src),
8617
- duration,
8618
- size: normalizeVideoInfoNumber(result.size),
8619
- width,
8620
- height,
8621
- bitrate,
8622
- fps
8623
- });
8624
- }).catch((error) => {
8625
- const message = error instanceof Error ? error.message : String(error);
8626
- const failure = callWxAsyncFailure(options, `getVideoInfo:fail ${message}`);
8627
- return Promise.reject(failure);
8628
- });
8629
- }
8686
+ // src/runtime/polyfill/mediaApi/picker.ts
8630
8687
  async function chooseImageBridge(options) {
8631
8688
  const count = normalizeChooseImageCount(options?.count);
8632
8689
  try {
@@ -8662,46 +8719,6 @@ async function chooseMediaBridge(options) {
8662
8719
  return Promise.reject(failure);
8663
8720
  }
8664
8721
  }
8665
- async function compressImageBridge(options) {
8666
- const src = typeof options?.src === "string" ? options.src.trim() : "";
8667
- if (!src) {
8668
- const failure = callWxAsyncFailure(options, "compressImage:fail invalid src");
8669
- return Promise.reject(failure);
8670
- }
8671
- const quality = normalizeCompressImageQuality(options?.quality);
8672
- try {
8673
- const tempFilePath = await compressImageByCanvas(src, quality);
8674
- return callWxAsyncSuccess(options, {
8675
- errMsg: "compressImage:ok",
8676
- tempFilePath
8677
- });
8678
- } catch (error) {
8679
- const message = error instanceof Error ? error.message : String(error);
8680
- const failure = callWxAsyncFailure(options, `compressImage:fail ${message}`);
8681
- return Promise.reject(failure);
8682
- }
8683
- }
8684
- function compressVideoBridge(options) {
8685
- const src = typeof options?.src === "string" ? options.src.trim() : "";
8686
- if (!src) {
8687
- const failure = callWxAsyncFailure(options, "compressVideo:fail invalid src");
8688
- return Promise.reject(failure);
8689
- }
8690
- const preset = readPresetCompressVideo(src);
8691
- const result = preset ?? {
8692
- tempFilePath: src,
8693
- size: 0,
8694
- duration: 0,
8695
- width: 0,
8696
- height: 0,
8697
- bitrate: 0,
8698
- fps: 0
8699
- };
8700
- return Promise.resolve(callWxAsyncSuccess(options, {
8701
- errMsg: "compressVideo:ok",
8702
- ...result
8703
- }));
8704
- }
8705
8722
  async function chooseVideoBridge(options) {
8706
8723
  try {
8707
8724
  const file = await pickChooseVideoFile();
@@ -8755,6 +8772,8 @@ async function chooseFileBridge(options) {
8755
8772
  return Promise.reject(failure);
8756
8773
  }
8757
8774
  }
8775
+
8776
+ // src/runtime/polyfill/mediaApi/preview.ts
8758
8777
  function previewImageBridge(options) {
8759
8778
  const urls = Array.isArray(options?.urls) ? options.urls.map((url) => String(url).trim()).filter(Boolean) : [];
8760
8779
  if (!urls.length) {
@@ -8789,61 +8808,48 @@ function openVideoEditorBridge(options) {
8789
8808
  tempFilePath
8790
8809
  }));
8791
8810
  }
8792
- function saveImageToPhotosAlbumBridge(options) {
8793
- const filePath = typeof options?.filePath === "string" ? options.filePath.trim() : "";
8794
- if (!filePath) {
8795
- const failure = callWxAsyncFailure(options, "saveImageToPhotosAlbum:fail invalid filePath");
8811
+
8812
+ // src/runtime/polyfill/mediaApi/process.ts
8813
+ async function compressImageBridge(options) {
8814
+ const src = typeof options?.src === "string" ? options.src.trim() : "";
8815
+ if (!src) {
8816
+ const failure = callWxAsyncFailure(options, "compressImage:fail invalid src");
8796
8817
  return Promise.reject(failure);
8797
8818
  }
8798
- triggerDownload(filePath);
8799
- return Promise.resolve(callWxAsyncSuccess(options, { errMsg: "saveImageToPhotosAlbum:ok" }));
8800
- }
8801
- function saveVideoToPhotosAlbumBridge(options) {
8802
- const filePath = typeof options?.filePath === "string" ? options.filePath.trim() : "";
8803
- if (!filePath) {
8804
- const failure = callWxAsyncFailure(options, "saveVideoToPhotosAlbum:fail invalid filePath");
8819
+ const quality = normalizeCompressImageQuality(options?.quality);
8820
+ try {
8821
+ const tempFilePath = await compressImageByCanvas(src, quality);
8822
+ return callWxAsyncSuccess(options, {
8823
+ errMsg: "compressImage:ok",
8824
+ tempFilePath
8825
+ });
8826
+ } catch (error) {
8827
+ const message = error instanceof Error ? error.message : String(error);
8828
+ const failure = callWxAsyncFailure(options, `compressImage:fail ${message}`);
8805
8829
  return Promise.reject(failure);
8806
8830
  }
8807
- triggerDownload(filePath);
8808
- return Promise.resolve(callWxAsyncSuccess(options, { errMsg: "saveVideoToPhotosAlbum:ok" }));
8809
8831
  }
8810
- function saveFileBridge(options) {
8811
- const tempFilePath = typeof options?.tempFilePath === "string" ? options.tempFilePath.trim() : "";
8812
- if (!tempFilePath) {
8813
- const failure = callWxAsyncFailure(options, "saveFile:fail invalid tempFilePath");
8832
+ function compressVideoBridge(options) {
8833
+ const src = typeof options?.src === "string" ? options.src.trim() : "";
8834
+ if (!src) {
8835
+ const failure = callWxAsyncFailure(options, "compressVideo:fail invalid src");
8814
8836
  return Promise.reject(failure);
8815
8837
  }
8816
- const savedFilePath = resolveSaveFilePath(tempFilePath, options?.filePath);
8817
- saveMemoryFile(tempFilePath, savedFilePath);
8838
+ const preset = readPresetCompressVideo(src);
8839
+ const result = preset ?? {
8840
+ tempFilePath: src,
8841
+ size: 0,
8842
+ duration: 0,
8843
+ width: 0,
8844
+ height: 0,
8845
+ bitrate: 0,
8846
+ fps: 0
8847
+ };
8818
8848
  return Promise.resolve(callWxAsyncSuccess(options, {
8819
- errMsg: "saveFile:ok",
8820
- savedFilePath
8849
+ errMsg: "compressVideo:ok",
8850
+ ...result
8821
8851
  }));
8822
8852
  }
8823
- function saveFileToDiskBridge(options) {
8824
- const filePath = typeof options?.filePath === "string" ? options.filePath.trim() : "";
8825
- if (!filePath) {
8826
- const failure = callWxAsyncFailure(options, "saveFileToDisk:fail invalid filePath");
8827
- return Promise.reject(failure);
8828
- }
8829
- const fileName = typeof options?.fileName === "string" ? options.fileName.trim() : "";
8830
- triggerDownload(filePath, fileName);
8831
- return Promise.resolve(callWxAsyncSuccess(options, { errMsg: "saveFileToDisk:ok" }));
8832
- }
8833
- function openDocumentBridge(options) {
8834
- const filePath = normalizeFilePath(options?.filePath);
8835
- if (!filePath) {
8836
- const failure = callWxAsyncFailure(options, "openDocument:fail invalid filePath");
8837
- return Promise.reject(failure);
8838
- }
8839
- const target = resolveOpenDocumentUrl(filePath);
8840
- if (!target) {
8841
- const failure = callWxAsyncFailure(options, "openDocument:fail document url is unavailable");
8842
- return Promise.reject(failure);
8843
- }
8844
- openTargetInNewWindow(target);
8845
- return Promise.resolve(callWxAsyncSuccess(options, { errMsg: "openDocument:ok" }));
8846
- }
8847
8853
 
8848
8854
  // src/runtime/polyfill/uiFeedback.ts
8849
8855
  var toastHideTimer;