fix(web): 修復排版邊界與增量生命週期

This commit is contained in:
2026-10-02 19:08:02 +08:00
parent 1c2fb0ed59
commit b1a16c4969
39 changed files with 4763 additions and 673 deletions
+7 -4
View File
@@ -61,13 +61,15 @@ function installLayout(
if (!m) { m = new Map(); owners.set(owner, m); }
const existing = m.get(key);
if (existing) { existing.disconnect(); }
const ro = new ResizeObserver(() => run());
ro.observe(root);
// 字型 Promise/已排隊回調可能晚於 revert 或重裝;只允許目前安裝執行。
const runCurrent = (): void => { if (m!.get(key) === ro) { run(); } };
const ro = new ResizeObserver(runCurrent);
m.set(key, ro);
ro.observe(root);
const fonts = (root.ownerDocument as Document & { fonts?: { ready?: Promise<unknown> } }).fonts;
if (fonts && fonts.ready && typeof fonts.ready.then === "function")
{
fonts.ready.then(run, () => undefined);
fonts.ready.then(runCurrent, () => undefined);
}
}
@@ -331,7 +333,8 @@ function trimGaps(
{
const r = lastRect(g);
const next = r ? edgeRect(g.nextSibling, "next", g, wrapSet) : null;
const atLineEnd = !r || !next || next.top > r.top + EPS;
// 同行小字/下標的 top 亦會較低;須整體落到下一行才算行末。
const atLineEnd = !r || !next || lowerLine(r, next);
if (!atLineEnd) { ctx.setOwnedClass(g, TRIM, false); }
}
}