fix(reader): 统一桌面端/移动端页面边距计算,为页边距 UI 做准备 - #679
Open
k6G52m4Dz75W wants to merge 1 commit into
Open
Conversation
Desktop + mobile shared page-margin calculation: - foliate-js: the gap attribute was conflated with margin (case 'gap' set the four --_margin-* vars), so --_gap never updated from the attribute and stayed at its 7% default; the gapPercent computed by callers was dead. Restore upstream semantics: gap -> --_gap, margin -> the four --_margin-*. - desktop (FoliateViewer): derive max-inline-size + gap from renderer.clientWidth (foliate resolves the gap % against it). A double spread is two columns of ONE iframe, so the center gutter = column-gap = effective gap / 2; solving gutter = margin and outer = margin + breathing room (paper = 99% of window, so pages never touch the window edges even at margin 0) yields g = 2M/(0.99H + M), max-inline = (paper - M + g.H)/2 for double and g = M/paper, max-inline = paper - M + g.H for single. No rounding -> exact. - desktop: re-apply layout when pageMargin changes and on window resize. - mobile (reader.template.html): replace the margin/393 heuristic with the same single-page formula via applyMobileReflowMargins (margin-top/bottom, margin-left/right 0, gap + max-inline from renderer.clientWidth); rebuilt reader.html.
Contributor
Author
验证移动端模拟验证(自建自包含测试页,跑在桌面 Chromium/Edge,与移动端 WebView2 同内核):
结论:
桌面端:默认 pageMargin=40 即生效;margin 0/40/80 外距 = 中缝 = margin,四边均匀。
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
阅读器的页边距(page margin)目前是"隐藏能力":设置项
settings.pageMargin早已存在于两端设置仓库中,但没有任何 UI 入口,且两端的计算逻辑都是临时拼凑的,导致这个值实际上无法被正确、统一地应用。gap属性一直是坏的(一个潜伏的回归 bug):attributeChangedCallback里case 'gap'与case 'margin'混在一起,把gap的值写到--_margin-*(四个页边距)上,而真正的列间距变量--_gap从未从属性更新,恒为 7% 默认值。结果是:所有调用方计算出的gapPercent都是死代码——设置了gap要么被忽略,要么把页边距污染成百分比。max-inline-size用硬编码760px+ 固定 gap,完全不随pageMargin变化。margin / 393的粗略启发式,且gapPercent因为上面的 bug 实际不生效。本 PR 把两端的页面边距计算统一为同一套推导,修复潜伏的
gapbug,为后续在阅读器设置面板加入"页边距"滑块铺路——之后 UI 只需写入settings.pageMargin即可生效。改动内容
1. foliate-js/paginator.js:修复
gap属性语义(对齐上游)