Skip to content

Commit 4e550fb

Browse files
committed
init
1 parent f67aeeb commit 4e550fb

3 files changed

Lines changed: 19 additions & 9 deletions

File tree

app/src/protyle/export/util.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {isMobile} from "../../util/functions";
1010
import {Constants} from "../../constants";
1111
import {highlightRender, lineNumberRender} from "../render/highlightRender";
1212
import {processRender} from "../util/processCode";
13-
import {isIPhone, isSafari, saveExportFile, setStorageVal} from "../util/compatibility";
13+
import {saveExportFile, setStorageVal} from "../util/compatibility";
1414
import {useShell} from "../../util/pathName";
1515

1616
export const afterExport = (exportPath: string, msgId: string) => {
@@ -90,14 +90,13 @@ export const exportImage = (id: string) => {
9090
item.textContent = (index + 1).toString();
9191
});
9292
setTimeout(() => {
93-
addScript(`${Constants.PROTYLE_CDN}/js/html-to-image.min.js?v=1.11.13`, "protyleHtml2image").then(async () => {
94-
let blob = await window.htmlToImage.toBlob(exportDialog.element.querySelector(".b3-dialog__content"));
95-
if (isIPhone() || isSafari()) {
96-
await window.htmlToImage.toBlob(contentElement);
97-
await window.htmlToImage.toBlob(contentElement);
98-
await window.htmlToImage.toBlob(contentElement);
99-
blob = await window.htmlToImage.toBlob(contentElement);
100-
}
93+
// modern-screenshot is used instead of html-to-image because the latter clones every
94+
// node and copies its full computed style one property at a time, which is O(nodes) with
95+
// a huge constant on WebKit/WKWebView (~15s for a mid-size doc on iOS vs ~3s on desktop).
96+
// modern-screenshot caches default styles per tag and only writes differing properties,
97+
// and it renders correctly in a single pass, so the old 3x Safari re-render hack is gone.
98+
addScript(`${Constants.PROTYLE_CDN}/js/modern-screenshot.min.js`, "protyleModernScreenshot").then(async () => {
99+
const blob = await window.modernScreenshot.domToBlob(contentElement, {type: "image/png"});
101100
const formData = new FormData();
102101
formData.append("file", blob, btnsElement[1].getAttribute("data-title"));
103102
formData.append("type", "image/png");

app/src/types/index.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,9 @@ interface Window {
270270
toCanvas: (element: Element, options?: Partial<IObject>) => Promise<HTMLCanvasElement>
271271
toBlob: (element: Element, options?: Partial<IObject>) => Promise<Blob>
272272
};
273+
modernScreenshot: {
274+
domToBlob: (element: Element, options?: Partial<IObject>) => Promise<Blob>
275+
};
273276
siyuan: ISiyuan;
274277
JSAndroid: {
275278
returnDesktop(): void

0 commit comments

Comments
 (0)