mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-03 07:18:49 +01:00
🚨
This commit is contained in:
parent
f28ce5a3b7
commit
5d6c71e35a
8 changed files with 40 additions and 46 deletions
|
|
@ -644,60 +644,60 @@ const getPage = (element: Element): Element | null => {
|
|||
return element;
|
||||
}
|
||||
return getPage(element.parentElement);
|
||||
}
|
||||
};
|
||||
|
||||
const getCaptureCanvas = async (page: any, captureScale: number) => {
|
||||
const viewport = page.getViewport({scale: captureScale * window.pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS});
|
||||
// Support HiDPI-screens.
|
||||
const outputScale = window.devicePixelRatio || 1;
|
||||
|
||||
const canvas = document.createElement("canvas")
|
||||
const canvas = document.createElement("canvas");
|
||||
canvas.width = Math.floor(viewport.width * outputScale);
|
||||
canvas.height = Math.floor(viewport.height * outputScale);
|
||||
canvas.style.width = Math.floor(viewport.width) + "px";
|
||||
canvas.style.height = Math.floor(viewport.height) + "px";
|
||||
|
||||
await page.render({
|
||||
canvasContext: canvas.getContext('2d'),
|
||||
canvasContext: canvas.getContext("2d"),
|
||||
transform: outputScale !== 1
|
||||
? [outputScale, 0, 0, outputScale, 0, 0]
|
||||
: null,
|
||||
viewport: viewport
|
||||
}).promise;
|
||||
|
||||
return canvas
|
||||
}
|
||||
return canvas;
|
||||
};
|
||||
|
||||
async function getRectImgData(pdfObj: any) {
|
||||
const pageElement = getPage(rectElement.firstElementChild)
|
||||
const pageElement = getPage(rectElement.firstElementChild);
|
||||
if (!pageElement) {
|
||||
return
|
||||
return;
|
||||
}
|
||||
const cavasElement = pageElement.querySelector(".canvasWrapper canvas") as HTMLCanvasElement
|
||||
const cavasElement = pageElement.querySelector(".canvasWrapper canvas") as HTMLCanvasElement;
|
||||
let scale;
|
||||
const trueWith = cavasElement.getBoundingClientRect().width
|
||||
const trueWith = cavasElement.getBoundingClientRect().width;
|
||||
if (trueWith <= 0) {
|
||||
scale = window.devicePixelRatio || 1;
|
||||
} else {
|
||||
scale = cavasElement.width / trueWith
|
||||
scale = cavasElement.width / trueWith;
|
||||
}
|
||||
const rectStyle = (rectElement.firstElementChild as HTMLElement).style
|
||||
const rectStyle = (rectElement.firstElementChild as HTMLElement).style;
|
||||
const captureLocation = {
|
||||
width: scale * parseFloat(rectStyle.width),
|
||||
height: scale * parseFloat(rectStyle.height),
|
||||
top: scale * parseFloat(rectStyle.top),
|
||||
left: scale * parseFloat(rectStyle.left),
|
||||
}
|
||||
};
|
||||
|
||||
const pdfPage = await pdfObj.pdfDocument.getPage(parseInt(pageElement.getAttribute("data-page-number")))
|
||||
const pdfPage = await pdfObj.pdfDocument.getPage(parseInt(pageElement.getAttribute("data-page-number")));
|
||||
const captureCanvas = await getCaptureCanvas(pdfPage, pdfObj.pdfViewer.currentScale);
|
||||
const captureImageData = captureCanvas.getContext("2d").getImageData(captureLocation.left, captureLocation.top, captureLocation.width, captureLocation.height)
|
||||
const captureImageData = captureCanvas.getContext("2d").getImageData(captureLocation.left, captureLocation.top, captureLocation.width, captureLocation.height);
|
||||
|
||||
const tempCanvas = document.createElement("canvas")
|
||||
tempCanvas.width = captureImageData.width
|
||||
tempCanvas.height = captureImageData.height
|
||||
const ctx = tempCanvas.getContext("2d")
|
||||
ctx.putImageData(captureImageData, 0, 0)
|
||||
const tempCanvas = document.createElement("canvas");
|
||||
tempCanvas.width = captureImageData.width;
|
||||
tempCanvas.height = captureImageData.height;
|
||||
const ctx = tempCanvas.getContext("2d");
|
||||
ctx.putImageData(captureImageData, 0, 0);
|
||||
return tempCanvas.toDataURL();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -549,7 +549,7 @@ export const enterBack = (protyle: IProtyle, id: string) => {
|
|||
} else {
|
||||
zoomOut({protyle, id: protyle.block.parent2ID, focusId: id});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const zoomOut = (options: {
|
||||
protyle: IProtyle,
|
||||
|
|
@ -1015,11 +1015,11 @@ export const linkMenu = (protyle: IProtyle, linkElement: HTMLElement, focusText
|
|||
}).element);
|
||||
}
|
||||
if (linkAddress) {
|
||||
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element)
|
||||
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
||||
openMenu(protyle.app, linkAddress, false, true);
|
||||
/// #if !BROWSER
|
||||
if (linkAddress?.startsWith("assets/")) {
|
||||
window.siyuan.menus.menu.append(new MenuItem(exportAsset(linkAddress)).element)
|
||||
window.siyuan.menus.menu.append(new MenuItem(exportAsset(linkAddress)).element);
|
||||
}
|
||||
/// #endif
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,9 +21,7 @@ import {
|
|||
assetMethodMenu, assetMoreMenu,
|
||||
renderNextAssetMark,
|
||||
renderPreview,
|
||||
toggleAssetHistory
|
||||
} from "../../search/assets";
|
||||
import {getQueryTip} from "../../search/util";
|
||||
|
||||
const replace = (element: Element, config: ISearchOption, isAll: boolean) => {
|
||||
if (config.method === 1 || config.method === 2) {
|
||||
|
|
@ -288,7 +286,7 @@ const initSearchEvent = (app: App, element: Element, config: ISearchOption) => {
|
|||
const criteriaData: ISearchOption[] = [];
|
||||
initCriteriaMenu(element.querySelector("#criteria"), criteriaData, config);
|
||||
|
||||
const assetsElement = document.querySelector("#searchAssetsPanel")
|
||||
const assetsElement = document.querySelector("#searchAssetsPanel");
|
||||
const searchListElement = element.querySelector("#searchList") as HTMLElement;
|
||||
const localSearch = window.siyuan.storage[Constants.LOCAL_SEARCHASSET] as ISearchAssetOption;
|
||||
element.addEventListener("click", (event: MouseEvent) => {
|
||||
|
|
@ -679,14 +677,14 @@ export const popSearch = (app: App, config = window.siyuan.storage[Constants.LOC
|
|||
};
|
||||
|
||||
const goAsset = () => {
|
||||
const assetsElement = document.querySelector("#searchAssetsPanel")
|
||||
assetsElement.classList.remove("fn__none")
|
||||
const listElement = assetsElement.querySelector("#searchAssetList")
|
||||
const assetsElement = document.querySelector("#searchAssetsPanel");
|
||||
assetsElement.classList.remove("fn__none");
|
||||
const listElement = assetsElement.querySelector("#searchAssetList");
|
||||
if (listElement.innerHTML) {
|
||||
return
|
||||
return;
|
||||
}
|
||||
const localSearch = window.siyuan.storage[Constants.LOCAL_SEARCHASSET] as ISearchAssetOption;
|
||||
const inputElement = assetsElement.querySelector("input")
|
||||
const inputElement = assetsElement.querySelector("input");
|
||||
inputElement.value = localSearch.k;
|
||||
inputElement.addEventListener("compositionend", (event: InputEvent) => {
|
||||
if (event.isComposing) {
|
||||
|
|
@ -701,4 +699,4 @@ const goAsset = () => {
|
|||
assetInputEvent(assetsElement, localSearch);
|
||||
});
|
||||
assetInputEvent(assetsElement, localSearch);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -23,11 +23,7 @@ import * as dayjs from "dayjs";
|
|||
import {fetchPost, fetchSyncPost} from "../../util/fetch";
|
||||
import {cancelSB, insertEmptyBlock, jumpToParentNext} from "../../block/util";
|
||||
import {countBlockWord} from "../../layout/status";
|
||||
/// #if !MOBILE
|
||||
import {openFileById} from "../../editor/util";
|
||||
/// #endif
|
||||
import {Constants} from "../../constants";
|
||||
import {openMobileFileById} from "../../mobile/editor";
|
||||
import {mathRender} from "../render/mathRender";
|
||||
import {duplicateBlock} from "../wysiwyg/commonHotkey";
|
||||
import {movePathTo} from "../../util/pathName";
|
||||
|
|
|
|||
|
|
@ -1935,7 +1935,7 @@ export class WYSIWYG {
|
|||
clientY: event.clientY
|
||||
});
|
||||
} else if (actionElement.parentElement.classList.contains("li")) {
|
||||
const actionId = actionElement.parentElement.getAttribute("data-node-id")
|
||||
const actionId = actionElement.parentElement.getAttribute("data-node-id");
|
||||
if (event.altKey && !protyle.disabled) {
|
||||
// 展开/折叠当前层级的所有列表项
|
||||
if (actionElement.parentElement.parentElement.classList.contains("protyle-wysiwyg")) {
|
||||
|
|
|
|||
|
|
@ -331,7 +331,7 @@ const deleteBlock = (updateElements: Element[], id: string, protyle: IProtyle) =
|
|||
blockRender(protyle, item);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const updateBlock = (updateElements: Element[], protyle: IProtyle, operation: IOperation, focus: boolean) => {
|
||||
updateElements.forEach(item => {
|
||||
|
|
@ -363,7 +363,7 @@ const updateBlock = (updateElements: Element[], protyle: IProtyle, operation: IO
|
|||
updateEmbed(protyle, operation);
|
||||
// 更新 ws 引用块
|
||||
updateRef(protyle, operation.id);
|
||||
}
|
||||
};
|
||||
|
||||
// 用于推送和撤销
|
||||
export const onTransaction = (protyle: IProtyle, operation: IOperation, focus: boolean) => {
|
||||
|
|
|
|||
|
|
@ -385,8 +385,8 @@ export const assetMethodMenu = (target: HTMLElement, cb: () => void) => {
|
|||
}
|
||||
}).element);
|
||||
/// #if MOBILE
|
||||
window.siyuan.menus.menu.element.style.zIndex = "221"
|
||||
window.siyuan.menus.menu.fullscreen()
|
||||
window.siyuan.menus.menu.element.style.zIndex = "221";
|
||||
window.siyuan.menus.menu.fullscreen();
|
||||
/// #else
|
||||
const rect = target.getBoundingClientRect();
|
||||
window.siyuan.menus.menu.popup({x: rect.right, y: rect.bottom}, true);
|
||||
|
|
@ -536,8 +536,8 @@ export const assetMoreMenu = (target: Element, element: Element, cb: () => void)
|
|||
},
|
||||
}).element);
|
||||
/// #if MOBILE
|
||||
window.siyuan.menus.menu.element.style.zIndex = "221"
|
||||
window.siyuan.menus.menu.fullscreen()
|
||||
window.siyuan.menus.menu.element.style.zIndex = "221";
|
||||
window.siyuan.menus.menu.fullscreen();
|
||||
/// #else
|
||||
const rect = target.getBoundingClientRect();
|
||||
window.siyuan.menus.menu.popup({x: rect.right, y: rect.bottom}, true);
|
||||
|
|
|
|||
|
|
@ -286,7 +286,7 @@ export const saveCriterion = (config: ISearchOption,
|
|||
}
|
||||
});
|
||||
saveCriterionData(config, criteriaData, element, value, saveDialog);
|
||||
})
|
||||
});
|
||||
}
|
||||
} else if (!hasSameName && hasSameConfig) {
|
||||
confirmDialog(window.siyuan.languages.confirm, window.siyuan.languages.searchUpdateName.replace("${x}", hasSameConfig).replace("${y}", value), () => {
|
||||
|
|
@ -458,10 +458,10 @@ const configIsSame = (config: ISearchOption, config2: ISearchOption) => {
|
|||
if (config2.group === config.group && config2.hPath === config.hPath && config2.hasReplace === config.hasReplace &&
|
||||
config2.k === config.k && config2.method === config.method && config2.r === config.r &&
|
||||
config2.sort === config.sort && objEquals(config2.types, config.types) && objEquals(config2.idPath, config.idPath)) {
|
||||
return true
|
||||
return true;
|
||||
}
|
||||
return false
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
export const initCriteriaMenu = (element: HTMLElement, data: ISearchOption[], config: ISearchOption) => {
|
||||
fetchPost("/api/storage/getCriteria", {}, (response) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue