From 174aa5e9242f64703f61915da1d34b42fef394c9 Mon Sep 17 00:00:00 2001 From: Caio Pizzol Date: Thu, 14 May 2026 09:55:48 -0300 Subject: [PATCH 1/2] refactor(painter-dom): rename rtl-paragraph feature to inline-direction (SD-2779) The painter-dom feature module previously called `features/rtl-paragraph/` handles two related but distinct OOXML elements: w:pPr/w:bidi (paragraph inline direction) and w:rPr/w:rtl (run inline direction). Both belong to the inline-direction axis. Table visual direction (w:bidiVisual) and writing mode (w:textDirection) are separate orthogonal axes owned elsewhere. Rename the folder + import path + feature-registry entry to `inline-direction` so the module name matches the axis, and add an explicit note (registry comment + index.ts JSDoc) calling out the two orthogonal axes the module does NOT own. Internal file (`rtl-styles.ts`) and exported function names (`applyRtlStyles`, `shouldUseSegmentPositioning`, `isRtlParagraph`, `resolveTextAlign`) keep their RTL framing because they describe RTL detection and styling specifically. Only the feature folder name changes. Tests: painter-dom 1070 pass. Build sweep (`pnpm --filter @superdoc/painter-dom... build`) clean. --- .../dom/src/features/feature-registry.ts | 8 ++++--- .../src/features/inline-direction/index.ts | 22 +++++++++++++++++++ .../rtl-styles.ts | 0 .../dom/src/features/rtl-paragraph/index.ts | 15 ------------- .../painters/dom/src/renderer.ts | 2 +- 5 files changed, 28 insertions(+), 19 deletions(-) create mode 100644 packages/layout-engine/painters/dom/src/features/inline-direction/index.ts rename packages/layout-engine/painters/dom/src/features/{rtl-paragraph => inline-direction}/rtl-styles.ts (100%) delete mode 100644 packages/layout-engine/painters/dom/src/features/rtl-paragraph/index.ts diff --git a/packages/layout-engine/painters/dom/src/features/feature-registry.ts b/packages/layout-engine/painters/dom/src/features/feature-registry.ts index 05cab44146..5f74b03d80 100644 --- a/packages/layout-engine/painters/dom/src/features/feature-registry.ts +++ b/packages/layout-engine/painters/dom/src/features/feature-registry.ts @@ -32,11 +32,13 @@ export const RENDERING_FEATURES = { spec: '§17.3.1.31', }, - // ─── RTL Paragraph ───────────────────────────────────────────── + // ─── Inline Direction ────────────────────────────────────────── + // Paragraph + run inline-direction axis. NOT table visual direction + // (w:bidiVisual, §17.4.1), NOT writing mode (w:textDirection, §17.18.93). // @spec ECMA-376 §17.3.1.1 (bidi), §17.3.2.30 (rtl) 'w:bidi': { - feature: 'rtl-paragraph', - module: './rtl-paragraph', + feature: 'inline-direction', + module: './inline-direction', handles: ['w:pPr/w:bidi', 'w:rPr/w:rtl'], spec: '§17.3.1.1', }, diff --git a/packages/layout-engine/painters/dom/src/features/inline-direction/index.ts b/packages/layout-engine/painters/dom/src/features/inline-direction/index.ts new file mode 100644 index 0000000000..c489ed90e7 --- /dev/null +++ b/packages/layout-engine/painters/dom/src/features/inline-direction/index.ts @@ -0,0 +1,22 @@ +/** + * Inline Direction - rendering feature module + * + * Centralises paragraph- and run-level inline-direction (RTL/LTR) logic + * used by DomPainter: + * - Detecting whether a paragraph is RTL + * - Applying dir="rtl" and the correct text-align to an element + * - Resolving text-align for RTL vs LTR (justify -> right/left) + * - Deciding whether segment-based (absolute) positioning is safe + * + * Scope is the **inline-direction axis only** (paragraph w:bidi + + * run w:rtl). Table visual direction (w:bidiVisual, ECMA-376 §17.4.1) + * is a separate orthogonal axis and is owned by the painter's table + * rendering path, not by this module. Writing mode (w:textDirection, + * §17.18.93) is another separate axis. + * + * @ooxml w:pPr/w:bidi - paragraph bidirectional flag + * @ooxml w:rPr/w:rtl - run-level right-to-left flag + * @spec ECMA-376 §17.3.1.1 (bidi), §17.3.2.30 (rtl) + */ + +export { applyRtlStyles, shouldUseSegmentPositioning } from './rtl-styles.js'; diff --git a/packages/layout-engine/painters/dom/src/features/rtl-paragraph/rtl-styles.ts b/packages/layout-engine/painters/dom/src/features/inline-direction/rtl-styles.ts similarity index 100% rename from packages/layout-engine/painters/dom/src/features/rtl-paragraph/rtl-styles.ts rename to packages/layout-engine/painters/dom/src/features/inline-direction/rtl-styles.ts diff --git a/packages/layout-engine/painters/dom/src/features/rtl-paragraph/index.ts b/packages/layout-engine/painters/dom/src/features/rtl-paragraph/index.ts deleted file mode 100644 index 6407b5c1b2..0000000000 --- a/packages/layout-engine/painters/dom/src/features/rtl-paragraph/index.ts +++ /dev/null @@ -1,15 +0,0 @@ -/** - * RTL Paragraph — rendering feature module - * - * Centralises all right-to-left paragraph logic used by DomPainter: - * - Detecting whether a paragraph is RTL - * - Applying dir="rtl" and the correct text-align to an element - * - Resolving text-align for RTL vs LTR (justify → right/left) - * - Deciding whether segment-based (absolute) positioning is safe - * - * @ooxml w:pPr/w:bidi — paragraph bidirectional flag - * @ooxml w:rPr/w:rtl — run-level right-to-left flag - * @spec ECMA-376 §17.3.1.1 (bidi), §17.3.2.30 (rtl) - */ - -export { applyRtlStyles, shouldUseSegmentPositioning } from './rtl-styles.js'; diff --git a/packages/layout-engine/painters/dom/src/renderer.ts b/packages/layout-engine/painters/dom/src/renderer.ts index a9903dde5e..1275d329a7 100644 --- a/packages/layout-engine/painters/dom/src/renderer.ts +++ b/packages/layout-engine/painters/dom/src/renderer.ts @@ -125,7 +125,7 @@ import { stampBetweenBorderDataset, type BetweenBorderInfo, } from './features/paragraph-borders/index.js'; -import { applyRtlStyles, shouldUseSegmentPositioning } from './features/rtl-paragraph/index.js'; +import { applyRtlStyles, shouldUseSegmentPositioning } from './features/inline-direction/index.js'; import { convertOmmlToMathml } from './features/math/index.js'; /** From 1076280cfceb305120f8483c136401c706743785 Mon Sep 17 00:00:00 2001 From: Caio Pizzol Date: Thu, 14 May 2026 14:29:06 -0300 Subject: [PATCH 2/2] docs(direction): correct OOXML spec citations on the orthogonal-axis note MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit §17.18.93 is ST_TextDirection (the enum values), not the element location. w:textDirection lives at §17.3.1.41 (paragraph) and §17.4.72 (cell). Also soften the "inline direction" framing to "paragraph/run inline bidi handling": w:rPr/w:rtl is a run-level bidi/RTL/CS trigger, not strictly a paragraph base-direction signal. Comment-only; no code change. --- .../painters/dom/src/features/feature-registry.ts | 5 +++-- .../dom/src/features/inline-direction/index.ts | 12 ++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/layout-engine/painters/dom/src/features/feature-registry.ts b/packages/layout-engine/painters/dom/src/features/feature-registry.ts index 5f74b03d80..831c2e3eaf 100644 --- a/packages/layout-engine/painters/dom/src/features/feature-registry.ts +++ b/packages/layout-engine/painters/dom/src/features/feature-registry.ts @@ -33,8 +33,9 @@ export const RENDERING_FEATURES = { }, // ─── Inline Direction ────────────────────────────────────────── - // Paragraph + run inline-direction axis. NOT table visual direction - // (w:bidiVisual, §17.4.1), NOT writing mode (w:textDirection, §17.18.93). + // Paragraph/run inline bidi handling. NOT table visual direction + // (w:bidiVisual, §17.4.1), NOT writing mode (w:textDirection, + // §17.3.1.41 paragraph / §17.4.72 cell; values in §17.18.93). // @spec ECMA-376 §17.3.1.1 (bidi), §17.3.2.30 (rtl) 'w:bidi': { feature: 'inline-direction', diff --git a/packages/layout-engine/painters/dom/src/features/inline-direction/index.ts b/packages/layout-engine/painters/dom/src/features/inline-direction/index.ts index c489ed90e7..14ab684072 100644 --- a/packages/layout-engine/painters/dom/src/features/inline-direction/index.ts +++ b/packages/layout-engine/painters/dom/src/features/inline-direction/index.ts @@ -1,18 +1,18 @@ /** * Inline Direction - rendering feature module * - * Centralises paragraph- and run-level inline-direction (RTL/LTR) logic + * Centralises paragraph base-direction and run-level RTL/bidi handling * used by DomPainter: * - Detecting whether a paragraph is RTL * - Applying dir="rtl" and the correct text-align to an element * - Resolving text-align for RTL vs LTR (justify -> right/left) * - Deciding whether segment-based (absolute) positioning is safe * - * Scope is the **inline-direction axis only** (paragraph w:bidi + - * run w:rtl). Table visual direction (w:bidiVisual, ECMA-376 §17.4.1) - * is a separate orthogonal axis and is owned by the painter's table - * rendering path, not by this module. Writing mode (w:textDirection, - * §17.18.93) is another separate axis. + * Scope is paragraph/run inline bidi handling only. Table visual + * direction (w:bidiVisual, ECMA-376 §17.4.1) is a separate orthogonal + * axis owned by the painter's table rendering path. Writing mode + * (w:textDirection, ECMA-376 §17.3.1.41 paragraph / §17.4.72 cell; + * values in §17.18.93 ST_TextDirection) is another separate axis. * * @ooxml w:pPr/w:bidi - paragraph bidirectional flag * @ooxml w:rPr/w:rtl - run-level right-to-left flag