mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-22 17:40:13 +01:00
This commit is contained in:
parent
cb85bb8080
commit
a708969984
2 changed files with 24 additions and 40 deletions
|
|
@ -2,7 +2,7 @@ import {fetchPost} from "../util/fetch";
|
|||
import {setPosition} from "../util/setPosition";
|
||||
import {hasClosestByAttribute, hasClosestByClassName} from "../protyle/util/hasClosest";
|
||||
import * as dayjs from "dayjs";
|
||||
import {writeText} from "../protyle/util/compatibility";
|
||||
import {setStorageVal, writeText} from "../protyle/util/compatibility";
|
||||
import {getAllModels} from "../layout/getAll";
|
||||
/// #if !BROWSER
|
||||
import {NativeImage} from "electron";
|
||||
|
|
@ -109,14 +109,22 @@ export const initAnno = (file: string, element: HTMLElement, annoId: string, pdf
|
|||
documentSelf.onselect = null;
|
||||
rectAnnoElement.classList.remove("toggled");
|
||||
pdfConfig.mainContainer.classList.remove("rect-to-annotation");
|
||||
rectResizeElement.setAttribute("data-render", "true");
|
||||
const utilElement = element.querySelector(".pdf__util") as HTMLElement;
|
||||
utilElement.classList.remove("pdf__util--hide", "fn__none");
|
||||
const targetRect = rectResizeElement.getBoundingClientRect();
|
||||
setPosition(utilElement, targetRect.left,
|
||||
targetRect.top + targetRect.height + 4);
|
||||
|
||||
const coords = getHightlightCoordsByRect(pdf, window.siyuan.storage[Constants.LOCAL_PDFTHEME].annoColor || "var(--b3-pdf-background1)", rectResizeElement,
|
||||
rectResizeElement.style.backgroundColor ? "text" : "border");
|
||||
rectResizeElement.classList.add("fn__none");
|
||||
if (coords) {
|
||||
coords.forEach((item, index) => {
|
||||
const newElement = showHighlight(item, pdf);
|
||||
if (index === 0) {
|
||||
rectElement = newElement;
|
||||
copyAnno(`${pdf.appConfig.file.replace(location.origin, "").substr(1)}/${rectElement.getAttribute("data-node-id")}`,
|
||||
pdf.appConfig.file.replace(location.origin, "").substr(8).replace(/-\d{14}-\w{7}.pdf$/, ""));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
rectElement = null;
|
||||
utilElement.classList.add("pdf__util--hide");
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
|
|
@ -127,6 +135,8 @@ export const initAnno = (file: string, element: HTMLElement, annoId: string, pdf
|
|||
const type = target.getAttribute("data-type");
|
||||
if (target.classList.contains("color__square")) {
|
||||
const color = target.style.backgroundColor;
|
||||
window.siyuan.storage[Constants.LOCAL_PDFTHEME].annoColor = color;
|
||||
setStorageVal(Constants.LOCAL_PDFTHEME, window.siyuan.storage[Constants.LOCAL_PDFTHEME]);
|
||||
if (rectElement) {
|
||||
const config = getConfig(pdf);
|
||||
const annoItem = config[rectElement.getAttribute("data-node-id")];
|
||||
|
|
@ -144,14 +154,7 @@ export const initAnno = (file: string, element: HTMLElement, annoId: string, pdf
|
|||
data: JSON.stringify(config),
|
||||
});
|
||||
} else {
|
||||
let coords;
|
||||
if (pdfConfig.mainContainer.lastElementChild.classList.contains("fn__none")) {
|
||||
coords = getHightlightCoordsByRange(pdf, color);
|
||||
} else {
|
||||
coords = getHightlightCoordsByRect(pdf, color, pdfConfig.mainContainer.lastElementChild,
|
||||
pdfConfig.mainContainer.lastElementChild.style.backgroundColor ? "text" : "border");
|
||||
pdfConfig.mainContainer.lastElementChild.classList.add("fn__none");
|
||||
}
|
||||
const coords = getHightlightCoordsByRange(pdf, color);
|
||||
if (coords) {
|
||||
coords.forEach((item, index) => {
|
||||
const newElement = showHighlight(item, pdf);
|
||||
|
|
@ -170,7 +173,6 @@ export const initAnno = (file: string, element: HTMLElement, annoId: string, pdf
|
|||
break;
|
||||
} else if (target.classList.contains("pdf__rect")) {
|
||||
showToolbar(element, undefined, target);
|
||||
pdfConfig.mainContainer.lastElementChild.classList.add("fn__none");
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
processed = true;
|
||||
|
|
@ -230,36 +232,18 @@ export const initAnno = (file: string, element: HTMLElement, annoId: string, pdf
|
|||
}
|
||||
|
||||
setTimeout(() => {
|
||||
const rectIsResize = !pdfConfig.mainContainer.lastElementChild.classList.contains(
|
||||
"fn__none");
|
||||
let isShow = false;
|
||||
const selection = window.getSelection();
|
||||
if (selection.rangeCount > 0) {
|
||||
const range = selection.getRangeAt(0);
|
||||
if (range.toString() !== "" &&
|
||||
hasClosestByClassName(range.commonAncestorContainer, "pdfViewer")) {
|
||||
if (rectIsResize) {
|
||||
range.collapse(true);
|
||||
} else {
|
||||
showToolbar(element, range);
|
||||
isShow = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!isShow) {
|
||||
if (rectIsResize) {
|
||||
if (!hasClosestByClassName(event.target as HTMLElement, "pdf__util") &&
|
||||
!hasClosestByClassName(event.target as HTMLElement, "pdf__resize") &&
|
||||
pdfConfig.mainContainer.lastElementChild.getAttribute(
|
||||
"data-render") !== "true") {
|
||||
hideToolbar(element);
|
||||
pdfConfig.mainContainer.lastElementChild.classList.add("fn__none");
|
||||
}
|
||||
pdfConfig.mainContainer.lastElementChild.removeAttribute("data-render");
|
||||
} else {
|
||||
hideToolbar(element);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -154,7 +154,7 @@ export const getLocalStorage = (cb: () => void) => {
|
|||
rowTab: "",
|
||||
layoutTab: 0
|
||||
};
|
||||
defaultStorage[Constants.LOCAL_PDFTHEME] = {light: "light", dark: "dark"};
|
||||
defaultStorage[Constants.LOCAL_PDFTHEME] = {light: "light", dark: "dark", annoColor: "var(--b3-pdf-background1)"};
|
||||
defaultStorage[Constants.LOCAL_BAZAAR] = {
|
||||
theme: "0",
|
||||
template: "0",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue