This commit is contained in:
Vanessa 2023-05-11 09:55:33 +08:00
parent a52cf1eb29
commit 8a53c82a27
12 changed files with 119 additions and 35 deletions

View file

@ -1,5 +1,11 @@
document.body.insertAdjacentHTML('afterBegin', `<svg style="position: absolute; width: 0; height: 0; overflow: hidden;" xmlns="http://www.w3.org/2000/svg">
<defs>
<symbol id="iconZoomIn" viewBox="0 0 32 32">
<path d="M20.561 13.482h-4.306v-4.889c0-0.161-0.131-0.292-0.292-0.292h-2.189c-0.161 0-0.292 0.131-0.292 0.292v4.889h-4.306c-0.161 0-0.292 0.131-0.292 0.292v2.189c0 0.161 0.131 0.292 0.292 0.292h4.306v4.889c0 0.161 0.131 0.292 0.292 0.292h2.189c0.161 0 0.292-0.131 0.292-0.292v-4.889h4.306c0.161 0 0.292-0.131 0.292-0.292v-2.189c0-0.161-0.131-0.292-0.292-0.292zM30.923 28.953l-5.327-5.327c4.455-5.433 4.145-13.483-0.949-18.573-5.4-5.404-14.172-5.404-19.594 0-5.404 5.422-5.404 14.194 0 19.594 5.090 5.094 13.14 5.404 18.573 0.949l5.327 5.327c0.117 0.102 0.303 0.102 0.401 0l1.569-1.569c0.102-0.099 0.102-0.285 0-0.401zM22.713 22.713c-4.335 4.331-11.355 4.331-15.69 0-4.331-4.335-4.331-11.355 0-15.69 4.335-4.331 11.355-4.331 15.69 0 4.331 4.335 4.331 11.355 0 15.69z"></path>
</symbol>
<symbol id="iconZoomOut" viewBox="0 0 32 32">
<path d="M20.561 13.482h-11.384c-0.161 0-0.292 0.131-0.292 0.292v2.189c0 0.161 0.131 0.292 0.292 0.292h11.384c0.161 0 0.292-0.131 0.292-0.292v-2.189c0-0.161-0.131-0.292-0.292-0.292zM30.923 28.953l-5.327-5.327c4.455-5.433 4.145-13.483-0.949-18.573-5.4-5.404-14.172-5.404-19.594 0-5.404 5.422-5.404 14.194 0 19.594 5.090 5.094 13.14 5.404 18.573 0.949l5.327 5.327c0.117 0.102 0.303 0.102 0.401 0l1.569-1.569c0.102-0.099 0.102-0.285 0-0.401zM22.713 22.713c-4.335 4.331-11.355 4.331-15.69 0-4.331-4.335-4.331-11.355 0-15.69 4.335-4.331 11.355-4.331 15.69 0 4.331 4.335 4.331 11.355 0 15.69z"></path>
</symbol>
<symbol id="iconFeedback" viewBox="0 0 32 32">
<path d="M18.030 13.171c-0.769 0-1.365 0.596-1.365 1.332s0.596 1.332 1.365 1.332c0.703 0 1.298-0.596 1.298-1.332s-0.596-1.332-1.298-1.332zM8.707 13.171c-0.769 0-1.365 0.596-1.365 1.332s0.596 1.332 1.365 1.332c0.703 0 1.298-0.596 1.298-1.332s-0.596-1.332-1.298-1.332z"></path>
<path d="M28.717 10.641c-1.526-2.083-3.695-3.615-6.212-4.309l-0.080-0.019v0.003c-0.569-0.633-1.212-1.215-1.931-1.735-5.45-3.962-13.101-2.753-17.079 2.697-3.206 4.428-3.070 10.384 0.2 14.616l0.027 4.415c0 0.107 0.017 0.213 0.050 0.313 0.14 0.435 0.541 0.745 1.015 0.745 0.114 0 0.224-0.018 0.328-0.051l-0.008 0.002 4.215-1.328c1.115 0.396 2.267 0.623 3.413 0.686l-0.017 0.013c2.966 2.161 6.855 2.81 10.421 1.631l4.232 1.378c0.107 0.033 0.216 0.053 0.33 0.053 0.589 0 1.065-0.476 1.065-1.065v-4.461c2.933-3.982 3.010-9.485 0.033-13.584zM9.706 23.625l-0.399-0.166-3.296 1.032-0.033-3.462-0.266-0.3c-2.817-3.436-3.003-8.387-0.366-12.019 3.209-4.401 9.362-5.374 13.75-2.197 4.401 3.199 5.377 9.342 2.197 13.717-2.667 3.659-7.441 5.011-11.586 3.396zM26.519 23.059l-0.266 0.333 0.033 3.462-3.263-1.099-0.399 0.166c-1.864 0.692-3.852 0.749-5.693 0.233l-0.007-0.003c2.594-0.812 4.753-2.386 6.275-4.457l0.024-0.034c2.544-3.506 2.956-7.91 1.478-11.666l0.020 0.013c0.766 0.549 1.468 1.235 2.064 2.064 2.417 3.316 2.281 7.831-0.266 10.987z"></path>

View file

@ -2,5 +2,5 @@
"name": "ant",
"author": "Vanessa",
"url": "https://github.com/Vanessa219",
"version": "1.18.0"
"version": "1.19.0"
}

View file

@ -28,6 +28,18 @@
<body>
<h2>SiYuan</h2>
<div class="fn__clear">
<div>
<svg>
<use xlink:href="#iconZoomIn"></use>
</svg>
iconZoomIn
</div>
<div>
<svg>
<use xlink:href="#iconZoomOut"></use>
</svg>
iconZoomOut
</div>
<div>
<svg>
<use xlink:href="#iconFeedback"></use>

View file

@ -1,5 +1,11 @@
document.body.insertAdjacentHTML('afterbegin', `<svg style="position: absolute; width: 0; height: 0; overflow: hidden;" xmlns="http://www.w3.org/2000/svg">
<defs>
<symbol id="iconZoomIn" viewBox="0 0 32 32">
<path d="M22.441 19.868h-1.355l-0.48-0.463c1.681-1.955 2.693-4.494 2.693-7.256 0-6.158-4.991-11.149-11.149-11.149s-11.149 4.991-11.149 11.149 4.991 11.149 11.149 11.149c2.762 0 5.3-1.012 7.256-2.693l0.463 0.48v1.355l8.576 8.559 2.556-2.556-8.559-8.576zM12.149 19.868c-4.271 0-7.719-3.448-7.719-7.719s3.448-7.719 7.719-7.719 7.719 3.448 7.719 7.719-3.448 7.719-7.719 7.719zM13.007 7.861h-1.715v3.431h-3.431v1.715h3.431v3.431h1.715v-3.431h3.431v-1.715h-3.431z"></path>
</symbol>
<symbol id="iconZoomOut" viewBox="0 0 32 32">
<path d="M22.441 19.868h-1.355l-0.48-0.463c1.681-1.955 2.693-4.494 2.693-7.256 0-6.158-4.991-11.149-11.149-11.149s-11.149 4.991-11.149 11.149 4.991 11.149 11.149 11.149c2.762 0 5.3-1.012 7.256-2.693l0.463 0.48v1.355l8.576 8.559 2.556-2.556-8.559-8.576zM12.149 19.868c-4.271 0-7.719-3.448-7.719-7.719s3.448-7.719 7.719-7.719 7.719 3.448 7.719 7.719-3.448 7.719-7.719 7.719zM7.861 11.292h8.576v1.715h-8.576z"></path>
</symbol>
<symbol id="iconFeedback" viewBox="0 0 32 32">
<path d="M28 1h-24c-1.65 0-2.985 1.35-2.985 3l-0.015 27 6-6h21c1.65 0 3-1.35 3-3v-18c0-1.65-1.35-3-3-3zM28 22h-22.245l-1.755 1.755v-19.755h24v18zM13.75 19h11.25v-3h-8.25zM19.54 10.195c0.3-0.3 0.3-0.765 0-1.065l-2.655-2.655c-0.3-0.3-0.765-0.3-1.065 0l-8.82 8.82v3.705h3.705l8.835-8.805z"></path>
</symbol>

View file

@ -2,5 +2,5 @@
"name": "material",
"author": "Vanessa",
"url": "https://github.com/Vanessa219",
"version": "1.18.0"
"version": "1.19.0"
}

View file

@ -536,7 +536,7 @@
"memo": "Memo",
"name": "Name",
"fold": "Fold/Expand",
"zoom": "Zoom and Position",
"zoom": "Zoom",
"invalid": "Invalid",
"conflict": "Conflict",
"checkToggle": "Check the task list to switch",

View file

@ -536,7 +536,7 @@
"memo": "Memo",
"name": "Nombre",
"fold": "Plegar/Expandir",
"zoom": "Zoom y posición",
"zoom": "Zoom",
"invalid": "Inválido",
"conflict": "Conflicto",
"checkToggle": "Compruebe la lista de tareas para cambiar",

View file

@ -536,7 +536,7 @@
"memo": "Remarques",
"name": "Nom",
"fold": "Pliage/Élargir",
"zoom": "Zoom et position",
"zoom": "Zoom",
"invalid": "Invalide",
"conflict": "Conflit",
"checkToggle": "Vérifiez la liste des tâches pour passer",

View file

@ -536,7 +536,7 @@
"memo": "備註",
"name": "命名",
"fold": "摺疊/展開",
"zoom": "縮放和位置",
"zoom": "縮放",
"invalid": "無效",
"conflict": "衝突",
"checkToggle": "任務列表勾選切換",

View file

@ -536,7 +536,7 @@
"memo": "备注",
"name": "命名",
"fold": "折叠/展开",
"zoom": "缩放和位置",
"zoom": "缩放",
"invalid": "无效",
"conflict": "冲突",
"checkToggle": "任务列表勾选切换",

View file

@ -1,4 +1,4 @@
import {isCtrl, isMac, setStorageVal, updateHotkeyTip, writeText} from "../protyle/util/compatibility";
import {isCtrl, isMac, updateHotkeyTip, writeText} from "../protyle/util/compatibility";
import {matchHotKey} from "../protyle/util/hotKey";
import {openSearch} from "../search/spread";
import {
@ -43,7 +43,7 @@ import {editor} from "../config/editor";
import {hintMoveBlock} from "../protyle/hint/extend";
import {Backlink} from "../layout/dock/Backlink";
/// #if !BROWSER
import {webFrame} from "electron";
import {setZoom} from "../layout/topBar";
/// #endif
import {openHistory} from "../history/history";
import {openCard, openCardByData} from "../card/openCard";
@ -575,39 +575,17 @@ export const globalShortcut = (app: App) => {
/// #if !BROWSER
if (matchHotKey("⌘=", event) && !hasClosestByClassName(target, "pdf__outer")) {
Constants.SIZE_ZOOM.find((item, index) => {
if (item === window.siyuan.storage[Constants.LOCAL_ZOOM]) {
window.siyuan.storage[Constants.LOCAL_ZOOM] = Constants.SIZE_ZOOM[index + 1] || 3;
webFrame.setZoomFactor(window.siyuan.storage[Constants.LOCAL_ZOOM]);
if (!isTabWindow) {
setStorageVal(Constants.LOCAL_ZOOM, window.siyuan.storage[Constants.LOCAL_ZOOM]);
}
return true;
}
});
setZoom("zoomIn")
event.preventDefault();
return;
}
if (matchHotKey("⌘0", event)) {
webFrame.setZoomFactor(1);
window.siyuan.storage[Constants.LOCAL_ZOOM] = 1;
if (!isTabWindow) {
setStorageVal(Constants.LOCAL_ZOOM, 1);
}
setZoom("restore")
event.preventDefault();
return;
}
if (matchHotKey("⌘-", event) && !hasClosestByClassName(target, "pdf__outer")) {
Constants.SIZE_ZOOM.find((item, index) => {
if (item === window.siyuan.storage[Constants.LOCAL_ZOOM]) {
window.siyuan.storage[Constants.LOCAL_ZOOM] = Constants.SIZE_ZOOM[index - 1] || 0.25;
webFrame.setZoomFactor(window.siyuan.storage[Constants.LOCAL_ZOOM]);
if (!isTabWindow) {
setStorageVal(Constants.LOCAL_ZOOM, window.siyuan.storage[Constants.LOCAL_ZOOM]);
}
return true;
}
});
setZoom("zoomOut")
event.preventDefault();
return;
}

View file

@ -1,5 +1,5 @@
import {getWorkspaceName} from "../util/noRelyPCFunction";
import {updateHotkeyTip} from "../protyle/util/compatibility";
import {setStorageVal, updateHotkeyTip} from "../protyle/util/compatibility";
import {processSync} from "../dialog/processSystem";
import {goBack, goForward} from "../util/backForward";
import {syncGuide} from "../sync/syncGuide";
@ -10,6 +10,11 @@ import {setMode} from "../util/assets";
import {openSetting} from "../config";
import {openSearch} from "../search/spread";
import {App} from "../index";
/// #if !BROWSER
import {webFrame} from "electron";
/// #endif
import {Constants} from "../constants";
import {isBrowser, isWindow} from "../util/functions";
export const updateEditModeElement = () => {
const target = document.querySelector("#barReadonly");
@ -45,6 +50,9 @@ export const initBar = (app: App) => {
<div id="barSearch" class="toolbar__item b3-tooltips b3-tooltips__sw" aria-label="${window.siyuan.languages.globalSearch} ${updateHotkeyTip(window.siyuan.config.keymap.general.globalSearch.custom)}">
<svg><use xlink:href="#iconSearch"></use></svg>
</div>
<div id="barZoom" class="toolbar__item b3-tooltips b3-tooltips__sw${(window.siyuan.storage[Constants.LOCAL_ZOOM] === 1 || isBrowser()) ? " fn__none" : ""}" aria-label="${window.siyuan.languages.zoom}">
<svg><use xlink:href="#iconZoom${window.siyuan.storage[Constants.LOCAL_ZOOM] > 1 ? "In" : "Out"}"></use></svg>
</div>
<div id="barReadonly" class="toolbar__item b3-tooltips b3-tooltips__sw${window.siyuan.config.readonly ? " fn__none" : ""}${window.siyuan.config.editor.readOnly ? " toolbar__item--active" : ""}" aria-label="${window.siyuan.languages.use} ${window.siyuan.config.editor.readOnly ? window.siyuan.languages.editMode : window.siyuan.languages.editReadonly} ${updateHotkeyTip(window.siyuan.config.keymap.general.editMode.custom)}">
<svg><use xlink:href="#icon${window.siyuan.config.editor.readOnly ? "Preview" : "Edit"}"></use></svg>
</div>
@ -123,8 +131,82 @@ export const initBar = (app: App) => {
openSearch(window.siyuan.config.keymap.general.globalSearch.custom);
event.stopPropagation();
break;
} else if (target.id === "barZoom") {
if (!window.siyuan.menus.menu.element.classList.contains("fn__none") &&
window.siyuan.menus.menu.element.getAttribute("data-name") === "barZoom") {
window.siyuan.menus.menu.remove();
return;
}
window.siyuan.menus.menu.remove();
window.siyuan.menus.menu.element.setAttribute("data-name", "barZoom");
window.siyuan.menus.menu.append(new MenuItem({
label: window.siyuan.languages.zoomIn,
icon: "iconZoomIn",
accelerator: "⌘=",
click: () => {
setZoom("zoomIn")
}
}).element);
window.siyuan.menus.menu.append(new MenuItem({
label: window.siyuan.languages.zoomOut,
accelerator: "⌘-",
icon: "iconZoomOut",
click: () => {
setZoom("zoomOut")
}
}).element);
window.siyuan.menus.menu.append(new MenuItem({
label: window.siyuan.languages.reset,
accelerator: "⌘0",
click: () => {
setZoom("restore")
}
}).element);
const rect = target.getBoundingClientRect();
window.siyuan.menus.menu.popup({x: rect.right, y: rect.bottom}, true);
event.stopPropagation();
break;
}
target = target.parentElement;
}
});
};
export const setZoom = (type: "zoomIn" | "zoomOut" | "restore") => {
/// #if !BROWSER
const isTabWindow = isWindow();
let zoom = 1;
if (type === "zoomIn") {
Constants.SIZE_ZOOM.find((item, index) => {
if (item === window.siyuan.storage[Constants.LOCAL_ZOOM]) {
zoom = Constants.SIZE_ZOOM[index + 1] || 3;
return true;
}
});
} else if (type === "zoomOut") {
Constants.SIZE_ZOOM.find((item, index) => {
if (item === window.siyuan.storage[Constants.LOCAL_ZOOM]) {
zoom = Constants.SIZE_ZOOM[index - 1] || 0.25;
return true;
}
});
}
webFrame.setZoomFactor(zoom);
window.siyuan.storage[Constants.LOCAL_ZOOM] = zoom;
if (!isTabWindow) {
setStorageVal(Constants.LOCAL_ZOOM, zoom);
}
const barZoomElement = document.getElementById("barZoom");
if (zoom === 1) {
barZoomElement.classList.add("fn__none");
} else {
if (zoom > 1) {
barZoomElement.querySelector("use").setAttribute("xlink:href", "#iconZoomIn")
} else {
barZoomElement.querySelector("use").setAttribute("xlink:href", "#iconZoomOut")
}
barZoomElement.classList.remove("fn__none");
}
/// #endif
}