Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions app/src/protyle/export/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {isMobile} from "../../util/functions";
import {Constants} from "../../constants";
import {highlightRender, lineNumberRender} from "../render/highlightRender";
import {processRender} from "../util/processCode";
import {isIPhone, isSafari, saveExportFile, setStorageVal} from "../util/compatibility";
import {saveExportFile, setStorageVal} from "../util/compatibility";
import {useShell} from "../../util/pathName";

export const afterExport = (exportPath: string, msgId: string) => {
Expand Down Expand Up @@ -90,14 +90,13 @@ export const exportImage = (id: string) => {
item.textContent = (index + 1).toString();
});
setTimeout(() => {
addScript(`${Constants.PROTYLE_CDN}/js/html-to-image.min.js?v=1.11.13`, "protyleHtml2image").then(async () => {
let blob = await window.htmlToImage.toBlob(exportDialog.element.querySelector(".b3-dialog__content"));
if (isIPhone() || isSafari()) {
await window.htmlToImage.toBlob(contentElement);
await window.htmlToImage.toBlob(contentElement);
await window.htmlToImage.toBlob(contentElement);
blob = await window.htmlToImage.toBlob(contentElement);
}
// modern-screenshot is used instead of html-to-image because the latter clones every
// node and copies its full computed style one property at a time, which is O(nodes) with
// a huge constant on WebKit/WKWebView (~15s for a mid-size doc on iOS vs ~3s on desktop).
// modern-screenshot caches default styles per tag and only writes differing properties,
// and it renders correctly in a single pass, so the old 3x Safari re-render hack is gone.
addScript(`${Constants.PROTYLE_CDN}/js/modern-screenshot.min.js`, "protyleModernScreenshot").then(async () => {
const blob = await window.modernScreenshot.domToBlob(contentElement, {type: "image/png"});
const formData = new FormData();
formData.append("file", blob, btnsElement[1].getAttribute("data-title"));
formData.append("type", "image/png");
Expand Down
3 changes: 3 additions & 0 deletions app/src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ interface Window {
toCanvas: (element: Element, options?: Partial<IObject>) => Promise<HTMLCanvasElement>
toBlob: (element: Element, options?: Partial<IObject>) => Promise<Blob>
};
modernScreenshot: {
domToBlob: (element: Element, options?: Partial<IObject>) => Promise<Blob>
};
siyuan: ISiyuan;
JSAndroid: {
returnDesktop(): void
Expand Down
Loading
Loading