Vanessa 2025-03-10 12:34:05 +08:00
parent 0fa0b16e3b
commit a4df630b77
2 changed files with 21 additions and 11 deletions

View file

@ -10,7 +10,7 @@ import {isMobile} from "../../util/functions";
import {Constants} from "../../constants"; import {Constants} from "../../constants";
import {highlightRender} from "../render/highlightRender"; import {highlightRender} from "../render/highlightRender";
import {processRender} from "../util/processCode"; import {processRender} from "../util/processCode";
import {openByMobile, setStorageVal} from "../util/compatibility"; import {isIPhone, isSafari, openByMobile, setStorageVal} from "../util/compatibility";
import {showFileInFolder} from "../../util/pathName"; import {showFileInFolder} from "../../util/pathName";
import {isPaidUser} from "../../util/needSubscribe"; import {isPaidUser} from "../../util/needSubscribe";
@ -64,8 +64,14 @@ export const exportImage = (id: string) => {
(exportDialog.element.querySelector(".b3-dialog__container") as HTMLElement).style.height = ""; (exportDialog.element.querySelector(".b3-dialog__container") as HTMLElement).style.height = "";
setStorageVal(Constants.LOCAL_EXPORTIMG, window.siyuan.storage[Constants.LOCAL_EXPORTIMG]); setStorageVal(Constants.LOCAL_EXPORTIMG, window.siyuan.storage[Constants.LOCAL_EXPORTIMG]);
setTimeout(() => { setTimeout(() => {
addScript("/stage/protyle/js/html-to-image.min.js?v=1.11.13", "protyleHtml2image").then(() => { addScript("/stage/protyle/js/html-to-image.min.js?v=1.11.13", "protyleHtml2image").then(async () => {
window.htmlToImage.toBlob(exportDialog.element.querySelector(".b3-dialog__content")).then((blob) => { let blob = await window.htmlToImage.toBlob(exportDialog.element.querySelector(".b3-dialog__content"))
if (isIPhone() || isSafari()) {
await window.htmlToImage.toBlob(exportDialog.element.querySelector(".b3-dialog__content"))
await window.htmlToImage.toBlob(exportDialog.element.querySelector(".b3-dialog__content"))
await window.htmlToImage.toBlob(exportDialog.element.querySelector(".b3-dialog__content"))
blob = await window.htmlToImage.toBlob(exportDialog.element.querySelector(".b3-dialog__content"))
}
const formData = new FormData(); const formData = new FormData();
formData.append("file", blob, btnsElement[1].getAttribute("data-title")); formData.append("file", blob, btnsElement[1].getAttribute("data-title"));
formData.append("type", "image/png"); formData.append("type", "image/png");
@ -75,7 +81,6 @@ export const exportImage = (id: string) => {
hideMessage(msgId); hideMessage(msgId);
exportDialog.destroy(); exportDialog.destroy();
}); });
});
}, Constants.TIMEOUT_LOAD); }, Constants.TIMEOUT_LOAD);
}); });
const previewElement = exportDialog.element.querySelector(".protyle-wysiwyg") as HTMLElement; const previewElement = exportDialog.element.querySelector(".protyle-wysiwyg") as HTMLElement;

View file

@ -180,6 +180,11 @@ export const isIPhone = () => {
return navigator.userAgent.indexOf("iPhone") > -1; return navigator.userAgent.indexOf("iPhone") > -1;
}; };
export const isSafari = () => {
const userAgent = navigator.userAgent;
return userAgent.includes("Safari") && !userAgent.includes("Chrome") && !userAgent.includes("Chromium");
};
export const isIPad = () => { export const isIPad = () => {
return navigator.userAgent.indexOf("iPad") > -1; return navigator.userAgent.indexOf("iPad") > -1;
}; };