2022-11-14 17:50:54 +08:00
|
|
|
/// #if !BROWSER
|
|
|
|
|
import {escapeHtml} from "../../util/escape";
|
|
|
|
|
import {shell} from "electron";
|
|
|
|
|
import * as path from "path";
|
|
|
|
|
/// #endif
|
2022-05-26 15:18:53 +08:00
|
|
|
import {hideMessage, showMessage} from "../../dialog/message";
|
2022-11-13 23:34:26 +08:00
|
|
|
import {fetchPost} from "../../util/fetch";
|
|
|
|
|
import {Dialog} from "../../dialog";
|
|
|
|
|
import {addScript} from "../util/addScript";
|
|
|
|
|
import {isMobile} from "../../util/functions";
|
|
|
|
|
import {Constants} from "../../constants";
|
|
|
|
|
import {highlightRender} from "../markdown/highlightRender";
|
2022-11-14 19:00:56 +08:00
|
|
|
import {processRender} from "../util/processCode";
|
2022-11-14 22:09:00 +08:00
|
|
|
import {openByMobile} from "../util/compatibility";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
2022-06-06 23:04:56 +08:00
|
|
|
export const afterExport = (exportPath: string, msgId: string) => {
|
2022-11-14 17:50:54 +08:00
|
|
|
/// #if !BROWSER
|
2022-12-11 11:51:04 +08:00
|
|
|
showMessage(`${window.siyuan.languages.exported} ${escapeHtml(exportPath)}
|
2022-06-06 23:04:56 +08:00
|
|
|
<div class="fn__space"></div>
|
|
|
|
|
<button class="b3-button b3-button--white">${window.siyuan.languages.showInFolder}</button>`, 6000, "info", msgId);
|
|
|
|
|
document.querySelector(`#message [data-id="${msgId}"] button`).addEventListener("click", () => {
|
2022-05-26 15:18:53 +08:00
|
|
|
shell.showItemInFolder(path.join(exportPath));
|
2022-06-06 23:04:56 +08:00
|
|
|
hideMessage(msgId);
|
2022-05-26 15:18:53 +08:00
|
|
|
});
|
2022-11-14 17:50:54 +08:00
|
|
|
/// #endif
|
2022-05-26 15:18:53 +08:00
|
|
|
};
|
2022-11-13 23:34:26 +08:00
|
|
|
|
|
|
|
|
export const exportImage = (id: string) => {
|
|
|
|
|
const exportDialog = new Dialog({
|
2022-11-14 11:25:11 +08:00
|
|
|
title: window.siyuan.languages.exportAsImage,
|
2022-11-16 15:58:36 +08:00
|
|
|
content: `<div class="b3-dialog__content" style="max-height: 70vh;overflow: auto;${isMobile() ? "padding:8px;" : ""};background-color: var(--b3-theme-background)">
|
2022-11-14 19:00:56 +08:00
|
|
|
<div style="${isMobile() ? "padding: 16px;margin: 16px 0" : "padding: 48px;margin: 8px 0 24px"};border: 1px solid var(--b3-border-color);border-radius: 10px;" class="protyle-wysiwyg${window.siyuan.config.editor.displayBookmarkIcon ? " protyle-wysiwyg--attr" : ""}" id="preview">
|
2022-11-14 17:50:54 +08:00
|
|
|
<div class="fn__loading" style="left:0"><img height="128px" width="128px" src="stage/loading-pure.svg"></div>
|
2022-11-13 23:34:26 +08:00
|
|
|
</div>
|
2022-11-14 11:22:39 +08:00
|
|
|
<div class="ft__smaller ft__on-surface fn__flex"><img style="height: 18px;margin: 0 8px" src="stage/icon.png">${window.siyuan.languages.exportBySiYuan}</div>
|
2022-11-13 23:34:26 +08:00
|
|
|
<div class="fn__hr--b"></div>
|
|
|
|
|
<div class="fn__hr--b"></div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="b3-dialog__action">
|
|
|
|
|
<button class="b3-button b3-button--cancel">${window.siyuan.languages.cancel}</button><div class="fn__space"></div>
|
|
|
|
|
<button class="b3-button b3-button--text">${window.siyuan.languages.confirm}</button>
|
|
|
|
|
</div>`,
|
|
|
|
|
width: isMobile() ? "90vw" : "990px",
|
|
|
|
|
});
|
|
|
|
|
fetchPost("/api/export/exportPreviewHTML", {
|
|
|
|
|
id,
|
|
|
|
|
keepFold: false,
|
2022-12-26 11:42:41 +08:00
|
|
|
image: true,
|
2022-11-13 23:34:26 +08:00
|
|
|
}, (response) => {
|
2022-11-14 19:02:56 +08:00
|
|
|
const previewElement = exportDialog.element.querySelector("#preview");
|
2022-11-13 23:34:26 +08:00
|
|
|
previewElement.innerHTML = response.data.content;
|
2022-11-14 19:00:56 +08:00
|
|
|
processRender(previewElement);
|
2022-11-13 23:34:26 +08:00
|
|
|
highlightRender(previewElement);
|
|
|
|
|
previewElement.querySelectorAll("table").forEach((item: HTMLElement) => {
|
|
|
|
|
if (item.clientWidth > item.parentElement.clientWidth) {
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
item.style.zoom = item.parentElement.clientWidth / item.clientWidth;
|
|
|
|
|
}
|
|
|
|
|
});
|
2022-11-16 19:57:18 +08:00
|
|
|
previewElement.querySelectorAll(".li > .protyle-action > svg").forEach(item => {
|
2022-11-19 10:49:43 +08:00
|
|
|
const id = item.firstElementChild.getAttribute("xlink:href");
|
|
|
|
|
const symbolElements = document.querySelectorAll(id);
|
2022-11-16 19:57:18 +08:00
|
|
|
let viewBox = "0 0 32 32";
|
|
|
|
|
if (id === "#iconDot") {
|
|
|
|
|
viewBox = "0 0 20 20";
|
|
|
|
|
}
|
|
|
|
|
item.setAttribute("viewBox", viewBox);
|
|
|
|
|
item.innerHTML = symbolElements[symbolElements.length - 1].innerHTML;
|
|
|
|
|
});
|
2022-11-13 23:34:26 +08:00
|
|
|
const btnsElement = exportDialog.element.querySelectorAll(".b3-button");
|
|
|
|
|
btnsElement[0].addEventListener("click", () => {
|
|
|
|
|
exportDialog.destroy();
|
|
|
|
|
});
|
|
|
|
|
btnsElement[1].addEventListener("click", () => {
|
|
|
|
|
const msgId = showMessage(window.siyuan.languages.exporting, 0);
|
|
|
|
|
previewElement.parentElement.style.maxHeight = "none";
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
addScript("stage/protyle/js/html2canvas.min.js?v=1.4.1", "protyleHtml2canvas").then(() => {
|
2022-12-06 23:19:35 +08:00
|
|
|
window.html2canvas(previewElement.parentElement).then((canvas) => {
|
2022-11-14 19:00:56 +08:00
|
|
|
canvas.toBlob((blob: Blob) => {
|
|
|
|
|
const formData = new FormData();
|
|
|
|
|
formData.append("file", blob, response.data.name + ".png");
|
|
|
|
|
formData.append("type", "image/png");
|
2022-11-14 22:09:00 +08:00
|
|
|
fetchPost("/api/export/exportAsFile", formData, (response) => {
|
|
|
|
|
openByMobile(response.data.file);
|
|
|
|
|
});
|
2022-11-14 19:02:56 +08:00
|
|
|
hideMessage(msgId);
|
|
|
|
|
exportDialog.destroy();
|
2022-11-14 19:00:56 +08:00
|
|
|
});
|
2022-11-13 23:34:26 +08:00
|
|
|
});
|
|
|
|
|
});
|
2022-11-14 19:02:56 +08:00
|
|
|
}, Constants.TIMEOUT_TRANSITION);
|
2022-11-13 23:34:26 +08:00
|
|
|
});
|
|
|
|
|
});
|
2022-11-14 19:02:56 +08:00
|
|
|
};
|