feat(阅读编辑): 修复双页编辑横向溢出
build.yaml / build (push) Successful in 45s

This commit is contained in:
xiaoqidun committed 2026-10-19 17:05:07 +08:00
1 parent a882e3e137
commit 5fd3854af8
3 files changed
+30 -72

No files matched your search

-6
View File
@@ -3135,12 +3135,6 @@ button.outline-link:hover {
.grouped-pages .page-list-item.drop-before::before { left: -5px; right: auto; } .grouped-pages .page-list-item.drop-before::before { left: -5px; right: auto; }
.grouped-pages .page-list-item.drop-after::after { right: -5px; left: auto; } .grouped-pages .page-list-item.drop-after::after { right: -5px; left: auto; }
.edit-line::before {
position: absolute;
inset: calc(-4px / var(--surface-scale));
content: "";
}
.edit-object.erasing { .edit-object.erasing {
background: var(--accent-soft); background: var(--accent-soft);
outline-style: dashed; outline-style: dashed;
+30 -63
View File
@@ -12093,31 +12093,37 @@ function fitWidth(updateStatus = true) {
} }
function fitWidthScale(page) { function fitWidthScale(page) {
if (state.pageLayout > 1) { return fitPageScale(page, "width");
const size = pageGroupSize(); }
return Math.min(4, Math.max(1, el.viewerPanel.offsetWidth - pageSpace() * 2 - (state.continuous ? 0 : PAGE_LAYOUT_GAP) - scrollbarWidth()) / (size.width * MM_TO_PX));
function fitPageScale(page, mode) {
const size = state.pageLayout > 1 ? pageGroupSize(page.index) : pageViewSize(page);
const width = Math.max(1, size.width * MM_TO_PX), height = Math.max(1, size.height * MM_TO_PX);
const space = pageSpace(), gap = state.pageLayout > 1 && !state.continuous ? PAGE_LAYOUT_GAP : 0;
let contentWidth = 0, contentHeight = 0, rows = 0;
for (let index = 0; index < state.doc.pages.length; index += state.pageLayout) {
const item = state.pageLayout > 1 ? pageGroupSize(index) : pageViewSize(state.doc.pages[index]);
const factor = mode === "width" && state.pageLayout === 1 ? size.width / item.width : 1;
contentWidth = Math.max(contentWidth, item.width * MM_TO_PX * factor);
contentHeight += item.height * MM_TO_PX * factor;
rows++;
} }
page = pageViewSize(page); const scrollbar = scrollbarWidth();
const space = pageSpace(); let vertical = false, horizontal = false, scale = 1;
const width = Math.max(1, page.width * MM_TO_PX); for (let pass = 0; pass < 3; pass++) {
const frameWidth = Number.parseFloat(getComputedStyle(el.pageFrame).width) || el.viewerPanel.clientWidth; const availableWidth = Math.max(1, el.viewerPanel.offsetWidth - (vertical ? scrollbar : 0));
let available = Math.max(1, frameWidth - space * 2); const availableHeight = Math.max(1, el.viewerPanel.offsetHeight - (horizontal ? scrollbar : 0));
if (!viewerHasVerticalScrollbar()) { scale = Math.min(4, Math.max(1, availableWidth - space * 2 - gap) / width);
const limit = Math.max(1, el.viewerPanel.clientHeight - space * 2); if (mode === "height") scale = Math.min(scale, Math.max(1, availableHeight - space * 2) / height);
let height = Math.max(1, page.height * MM_TO_PX) * (available / width); const blockSpace = state.continuous ? 0 : Math.max(space, (availableHeight - height * scale) / 2);
if (state.continuous) { const rowGap = state.continuous ? 0 : Math.max(gap, blockSpace > space ? blockSpace + 1 : blockSpace);
height = 0; const nextVertical = contentHeight * scale + rowGap * (rows - 1) + blockSpace * 2 > availableHeight + 0.5;
for (const item of state.doc.pages) { const nextHorizontal = contentWidth * scale + gap + space * 2 > availableWidth + 0.5;
const size = pageViewSize(item); if ((!nextVertical || vertical) && (!nextHorizontal || horizontal)) break;
height += available * size.height / size.width; vertical ||= nextVertical;
if (height > limit) break; horizontal ||= nextHorizontal;
}
}
if (height > limit) {
available = Math.max(1, available - scrollbarWidth());
}
} }
return Math.min(4, available / width); return scale;
} }
function fitHeight(updateStatus = true) { function fitHeight(updateStatus = true) {
@@ -12125,42 +12131,7 @@ function fitHeight(updateStatus = true) {
if (!page) { if (!page) {
return; return;
} }
if (state.pageLayout > 1) { setScale(fitPageScale(page, "height"), updateStatus, "height");
const size = pageGroupSize(), space = pageSpace(), gap = state.continuous ? 0 : PAGE_LAYOUT_GAP;
const width = Math.max(1, el.viewerPanel.offsetWidth - space * 2 - gap - scrollbarWidth());
const height = Math.max(1, el.viewerPanel.clientHeight - space * 2);
setScale(Math.min(width / (size.width * MM_TO_PX), height / (size.height * MM_TO_PX)), updateStatus, "height");
if (updateStatus) scrollToPage(state.pageIndex);
return;
}
const space = pageSpace();
let availableWidth = Math.max(1, el.viewerPanel.clientWidth - space * 2);
let availableHeight = Math.max(1, el.viewerPanel.clientHeight - space * 2);
const size = pageViewSize(page);
const width = Math.max(1, size.width * MM_TO_PX);
const height = Math.max(1, size.height * MM_TO_PX);
if (state.continuous) {
availableWidth = Math.max(1, el.viewerPanel.offsetWidth);
availableHeight = Math.max(1, el.viewerPanel.offsetHeight);
const contentWidth = state.doc.pages.reduce((max, item) => Math.max(max, pageViewSize(item).width), 0) * MM_TO_PX;
const contentHeight = state.doc.pages.reduce((total, item) => total + pageViewSize(item).height, 0) * MM_TO_PX;
const scale = Math.min(availableWidth / width, availableHeight / height);
const needsVerticalScrollbar = scale > availableHeight / contentHeight;
const needsHorizontalScrollbar = scale > availableWidth / contentWidth;
if (needsVerticalScrollbar || needsHorizontalScrollbar) {
const scrollbar = scrollbarWidth();
availableWidth = Math.max(1, availableWidth - (needsVerticalScrollbar ? scrollbar : 0));
availableHeight = Math.max(1, availableHeight - (needsHorizontalScrollbar ? scrollbar : 0));
const nextScale = Math.min(availableWidth / width, availableHeight / height);
if (!needsVerticalScrollbar && nextScale > availableHeight / contentHeight) {
availableWidth = Math.max(1, availableWidth - scrollbar);
}
if (!needsHorizontalScrollbar && nextScale > availableWidth / contentWidth) {
availableHeight = Math.max(1, availableHeight - scrollbar);
}
}
}
setScale(Math.min(availableWidth / width, availableHeight / height), updateStatus, "height");
if (updateStatus) { if (updateStatus) {
scrollToPage(state.pageIndex); scrollToPage(state.pageIndex);
} }
@@ -12251,10 +12222,6 @@ function pageBlockSpace() {
return Number.parseFloat(getComputedStyle(el.pageFrame).paddingTop) || pageSpace(); return Number.parseFloat(getComputedStyle(el.pageFrame).paddingTop) || pageSpace();
} }
function viewerHasVerticalScrollbar() {
return el.viewerPanel.scrollHeight > el.viewerPanel.clientHeight;
}
function scrollbarWidth() { function scrollbarWidth() {
const probe = document.createElement("div"); const probe = document.createElement("div");
const content = document.createElement("div"); const content = document.createElement("div");
-3
View File
@@ -607,9 +607,6 @@ export class CanvasEditor {
node.className = "edit-object"; node.className = "edit-object";
node.classList.toggle("read-only", !canEditObject(object, "move")); node.classList.toggle("read-only", !canEditObject(object, "move"));
node.title = objectEditReason(object); node.title = objectEditReason(object);
if (lineShape(object.shape)) {
node.classList.add("edit-line");
}
node.tabIndex = 0; node.tabIndex = 0;
const item = { ...object, index, page: { width: page.width, height: page.height }, node, surface }; const item = { ...object, index, page: { width: page.width, height: page.height }, node, surface };
item.artwork = artwork.get(object.id)?.node; item.artwork = artwork.get(object.id)?.node;