feat: 功能分級(文本級 vs 段落級)+ data-jz-level 標記(§6.5.0a)

整體計劃 §6.5 之前置基礎設施。把已實作功能切為兩級:
- 文本級(spacing 中西間隙、jiya 標點擠壓/鄰接):任意文本片段皆適用。
- 段落級(jinze 禁則、longWord 斷詞、lineEdge 行端、gapTrim):需行/段布局。

標記 API:
- 預設塊級元素 → 段落級(全功能)。
- 元素屬性 data-jz-level="text"|"paragraph"(最近祖先勝)。
- 選項 level:{ text: "選擇器" }(如標題/按鈕一鍵降為文本級)。

實作:
- 每個 pass 加 level 元數據;Finder.levelFor/levelAllows(含快取)。
- charify 段落級 pass(longWord)於共享走訪受閘;standalone 段落級 pass
  (jinze/lineEdge/gapTrim)逐元素受閘。文本級不受限。
- spacing 補單元素 root 支援:root 為行內/單一非塊元素時亦處理(標題等
  之中西間隙、標點半形生效)。

6 項新單元測試(text-level 跳段落級、選擇器標記、巢狀最近勝、單元素 spacing、
預設段落級回歸)。共 76 測試全綠。
This commit is contained in:
2026-06-09 16:52:00 +08:00
parent a00b35577e
commit c1fbabf5b0
15 changed files with 309 additions and 7 deletions
+5 -1
View File
@@ -122,6 +122,8 @@ function relayout(root: Element, finder: Finder): void
for (const el of chars)
{
// 行端為段落級(§6.5.0a):text-level 子樹(單行標題等)不收行端半形。
if (!finder.levelAllows(el, "paragraph")) { continue; }
if (!finder.featureEnabledFor(el, "jiya")) { continue; }
// 行端僅處理括號引號:開類於行首收左、閉類於行尾收右。
// **不**處理句末/句內點號(。!?,等)——行尾/行首之點號保持全形,
@@ -149,6 +151,7 @@ export const lineEdgePass: StandalonePass = {
name: "jiyaLineEdge",
kind: "standalone",
order: 90,
level: "paragraph",
enabled: (o) => o.features.jiya,
render(ctx: RenderContext): void
{
@@ -174,7 +177,7 @@ const TRIM = "jz-hws-trim";
function trimGaps(root: Element, finder: Finder): void
{
const gaps = Array.from(root.querySelectorAll("jz-hws")).filter(
(g) => finder.inScope(g) && !finder.isAvoided(g),
(g) => finder.inScope(g) && !finder.isAvoided(g) && finder.levelAllows(g, "paragraph"),
);
if (!gaps.length) { return; }
@@ -207,6 +210,7 @@ export const gapTrimPass: StandalonePass = {
name: "spacingGapTrim",
kind: "standalone",
order: 92,
level: "paragraph",
enabled: (o) => o.features.spacing,
render(ctx: RenderContext): void
{