From 4cafc882c7ecdfec85427fc0ee3a3e3649d06bc2 Mon Sep 17 00:00:00 2001 From: Luccas Correa Date: Thu, 22 Jan 2026 17:49:40 -0300 Subject: [PATCH 1/7] refactor: remove unused styleContext parameter --- .../src/converters/paragraph.test.ts | 111 +++++------------- .../pm-adapter/src/converters/paragraph.ts | 5 - .../pm-adapter/src/converters/table.test.ts | 48 -------- .../pm-adapter/src/converters/table.ts | 10 -- .../pm-adapter/src/internal.test.ts | 21 ---- .../layout-engine/pm-adapter/src/internal.ts | 22 ---- .../pm-adapter/src/sdt/document-index.test.ts | 1 - .../pm-adapter/src/sdt/document-index.ts | 2 - .../src/sdt/document-part-object.test.ts | 8 +- .../src/sdt/document-part-object.ts | 3 - .../src/sdt/document-section.test.ts | 45 ------- .../pm-adapter/src/sdt/document-section.ts | 11 +- .../pm-adapter/src/sdt/index.test.ts | 1 - .../src/sdt/structured-content-block.test.ts | 26 ---- .../src/sdt/structured-content-block.ts | 3 - .../pm-adapter/src/sdt/toc.test.ts | 11 -- .../layout-engine/pm-adapter/src/sdt/toc.ts | 5 - .../layout-engine/pm-adapter/src/types.ts | 7 -- 18 files changed, 33 insertions(+), 307 deletions(-) diff --git a/packages/layout-engine/pm-adapter/src/converters/paragraph.test.ts b/packages/layout-engine/pm-adapter/src/converters/paragraph.test.ts index 01dfcd79a..1e8574a8a 100644 --- a/packages/layout-engine/pm-adapter/src/converters/paragraph.test.ts +++ b/packages/layout-engine/pm-adapter/src/converters/paragraph.test.ts @@ -21,7 +21,6 @@ import type { PositionMap, TrackedChangesConfig, HyperlinkConfig, - StyleContext, ThemeColorPalette, NestedConverters, } from '../types.js'; @@ -113,7 +112,6 @@ const paragraphToFlowBlocks = ( positions: PositionMap, defaultFont: string, defaultSize: number, - styleContext: StyleContext, trackedChangesConfig?: TrackedChangesConfig, bookmarks?: Map, hyperlinkConfig?: HyperlinkConfig, @@ -140,7 +138,6 @@ const paragraphToFlowBlocks = ( positions, defaultFont, defaultSize, - styleContext, trackedChangesConfig, bookmarks, hyperlinkConfig: hyperlinkConfig ?? DEFAULT_HYPERLINK_CONFIG, @@ -673,7 +670,6 @@ describe('paragraph converters', () => { describe('paragraphToFlowBlocks', () => { let nextBlockId: BlockIdGenerator; let positions: PositionMap; - let styleContext: StyleContext; let converterContext: ConverterContext; beforeEach(() => { @@ -687,7 +683,6 @@ describe('paragraph converters', () => { positions = new WeakMap(); // Setup style context (mock) - styleContext = {}; converterContext = { translatedNumbering: {}, translatedLinkedStyles: { @@ -739,7 +734,7 @@ describe('paragraph converters', () => { content: [], }; - const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16, styleContext); + const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16); expect(blocks).toHaveLength(1); expect(blocks[0].kind).toBe('paragraph'); @@ -764,7 +759,7 @@ describe('paragraph converters', () => { }, }; - const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16, styleContext); + const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16); expect(blocks).toHaveLength(1); const paraBlock = blocks[0] as ParagraphBlock; @@ -784,7 +779,7 @@ describe('paragraph converters', () => { content: [], }; - const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16, styleContext); + const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16); expect(blocks).toHaveLength(0); }); @@ -802,7 +797,7 @@ describe('paragraph converters', () => { content: [{ type: 'text', text: 'Visible text' }], }; - const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16, styleContext); + const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16); expect(blocks).toHaveLength(1); const paraBlock = blocks[0] as ParagraphBlock; @@ -815,7 +810,7 @@ describe('paragraph converters', () => { type: 'paragraph', }; - const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16, styleContext); + const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16); expect(blocks).toHaveLength(1); expect(blocks[0].kind).toBe('paragraph'); @@ -834,7 +829,7 @@ describe('paragraph converters', () => { fontSize: 16, }); - const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16, styleContext); + const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16); expect(blocks).toHaveLength(1); expect(blocks[0].kind).toBe('paragraph'); @@ -864,7 +859,7 @@ describe('paragraph converters', () => { resolvedParagraphProperties: {}, }); - const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16, styleContext); + const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16); expect(blocks).toHaveLength(2); expect(blocks[0].kind).toBe('pageBreak'); @@ -885,7 +880,7 @@ describe('paragraph converters', () => { ], }; - const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16, styleContext); + const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16); expect(blocks).toHaveLength(1); const paraBlock = blocks[0] as ParagraphBlock; @@ -913,7 +908,6 @@ describe('paragraph converters', () => { positions, 'Arial', 16, - styleContext, undefined, undefined, undefined, @@ -968,7 +962,6 @@ describe('paragraph converters', () => { positions, 'Arial', 16, - styleContext, undefined, undefined, undefined, @@ -1005,7 +998,6 @@ describe('paragraph converters', () => { positions, 'Arial', 16, - styleContext, undefined, undefined, undefined, @@ -1056,7 +1048,7 @@ describe('paragraph converters', () => { }; vi.mocked(tabNodeToRun).mockReturnValue(mockTabRun); - const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16, styleContext); + const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16); expect(vi.mocked(tabNodeToRun)).toHaveBeenCalledWith(tabNode, positions, 0, {}, []); const paraBlock = blocks[0] as ParagraphBlock; @@ -1069,7 +1061,7 @@ describe('paragraph converters', () => { content: [{ type: 'tab' }, { type: 'tab' }, { type: 'tab' }], }; - paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16, styleContext); + paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16); expect(vi.mocked(tabNodeToRun)).toHaveBeenNthCalledWith(1, expect.any(Object), positions, 0, {}, []); expect(vi.mocked(tabNodeToRun)).toHaveBeenNthCalledWith(2, expect.any(Object), positions, 1, {}, []); @@ -1084,7 +1076,7 @@ describe('paragraph converters', () => { vi.mocked(tabNodeToRun).mockReturnValue(null); - const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16, styleContext); + const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16); const paraBlock = blocks[0] as ParagraphBlock; // Empty paragraph created because no runs were added @@ -1109,7 +1101,7 @@ describe('paragraph converters', () => { }; vi.mocked(tokenNodeToRun).mockReturnValue(mockTokenRun); - const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16, styleContext); + const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16); expect(vi.mocked(tokenNodeToRun)).toHaveBeenCalledWith( tokenNode, @@ -1137,7 +1129,6 @@ describe('paragraph converters', () => { positions, 'Arial', 16, - styleContext, ); expect(vi.mocked(tokenNodeToRun)).toHaveBeenCalledWith( @@ -1173,7 +1164,7 @@ describe('paragraph converters', () => { }; vi.mocked(tokenNodeToRun).mockReturnValue(mockTokenRun); - const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16, styleContext); + const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16); const paraBlock = blocks[0] as ParagraphBlock; const tokenRun = paraBlock.runs[0] as TextRun; @@ -1193,7 +1184,7 @@ describe('paragraph converters', () => { ], }; - const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16, styleContext); + const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16); expect(vi.mocked(textNodeToRun)).toHaveBeenCalled(); const paraBlock = blocks[0] as ParagraphBlock; @@ -1219,7 +1210,6 @@ describe('paragraph converters', () => { positions, 'Arial', 16, - styleContext, ); expect(vi.mocked(textNodeToRun)).toHaveBeenCalledWith( @@ -1249,7 +1239,6 @@ describe('paragraph converters', () => { positions, 'Arial', 16, - styleContext, ); expect(blocks).toHaveLength(1); @@ -1279,7 +1268,6 @@ describe('paragraph converters', () => { positions, 'Arial', 16, - styleContext, ); expect(blocks).toHaveLength(1); @@ -1309,7 +1297,6 @@ describe('paragraph converters', () => { positions, 'Arial', 16, - styleContext, ); expect(blocks).toHaveLength(1); @@ -1339,7 +1326,6 @@ describe('paragraph converters', () => { positions, 'Arial', 16, - styleContext, ); expect(blocks).toHaveLength(1); @@ -1376,7 +1362,6 @@ describe('paragraph converters', () => { positions, 'Arial', 16, - styleContext, ); expect(blocks).toHaveLength(1); @@ -1411,7 +1396,6 @@ describe('paragraph converters', () => { positions, 'Arial', 16, - styleContext, undefined, undefined, undefined, @@ -1445,7 +1429,6 @@ describe('paragraph converters', () => { positions, 'Arial', 16, - styleContext, undefined, undefined, undefined, @@ -1477,7 +1460,6 @@ describe('paragraph converters', () => { positions, 'Arial', 16, - styleContext, undefined, undefined, undefined, @@ -1510,7 +1492,6 @@ describe('paragraph converters', () => { positions, 'Arial', 16, - styleContext, undefined, undefined, undefined, @@ -1549,7 +1530,6 @@ describe('paragraph converters', () => { positions, 'Arial', 16, - styleContext, undefined, undefined, undefined, @@ -1589,7 +1569,6 @@ describe('paragraph converters', () => { positions, 'Arial', 16, - styleContext, undefined, undefined, undefined, @@ -1636,7 +1615,7 @@ describe('paragraph converters', () => { positions.set(bookmarkNode, { start: 100, end: 100 }); const bookmarks = new Map(); - paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16, styleContext, undefined, bookmarks); + paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16, undefined, bookmarks); expect(bookmarks.get('MyBookmark')).toBe(100); }); @@ -1654,7 +1633,7 @@ describe('paragraph converters', () => { // Should not throw expect(() => { - paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16, styleContext); + paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16); }).not.toThrow(); }); @@ -1674,7 +1653,6 @@ describe('paragraph converters', () => { positions, 'Arial', 16, - styleContext, ); expect(vi.mocked(textNodeToRun)).toHaveBeenCalled(); @@ -1708,7 +1686,6 @@ describe('paragraph converters', () => { positions, 'Arial', 16, - styleContext, undefined, undefined, undefined, @@ -1757,7 +1734,6 @@ describe('paragraph converters', () => { positions, 'Arial', 16, - styleContext, trackedChanges, undefined, undefined, @@ -1792,7 +1768,6 @@ describe('paragraph converters', () => { positions, 'Arial', 16, - styleContext, { mode: 'final', enabled: true }, undefined, undefined, @@ -1827,7 +1802,6 @@ describe('paragraph converters', () => { positions, 'Arial', 16, - styleContext, undefined, undefined, undefined, @@ -1860,7 +1834,6 @@ describe('paragraph converters', () => { positions, 'Arial', 16, - styleContext, undefined, undefined, undefined, @@ -1892,7 +1865,6 @@ describe('paragraph converters', () => { positions, 'Arial', 16, - styleContext, undefined, undefined, undefined, @@ -1924,7 +1896,6 @@ describe('paragraph converters', () => { positions, 'Arial', 16, - styleContext, undefined, undefined, undefined, @@ -1963,7 +1934,6 @@ describe('paragraph converters', () => { positions, 'Arial', 16, - styleContext, trackedChanges, bookmarks, hyperlinkConfig, @@ -1978,7 +1948,6 @@ describe('paragraph converters', () => { positions, defaultFont: 'Arial', defaultSize: 16, - styleContext, trackedChangesConfig: trackedChanges, bookmarks, hyperlinkConfig, @@ -1997,7 +1966,7 @@ describe('paragraph converters', () => { content: [{ type: 'text', text: 'Before' }, hardBreakNode, { type: 'text', text: 'After' }], }; - const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16, styleContext); + const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16); expect(blocks).toHaveLength(3); expect(blocks[1].kind).toBe('pageBreak'); @@ -2014,7 +1983,7 @@ describe('paragraph converters', () => { content: [lineBreakNode], }; - const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16, styleContext); + const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16); expect(blocks.some((b) => b.kind === 'columnBreak')).toBe(true); }); @@ -2029,7 +1998,7 @@ describe('paragraph converters', () => { content: [{ type: 'text', text: 'Text' }, lineBreakNode], }; - const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16, styleContext); + const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16); expect(blocks).toHaveLength(1); expect(blocks[0].kind).toBe('paragraph'); @@ -2067,7 +2036,6 @@ describe('paragraph converters', () => { positions, 'Arial', 16, - styleContext, trackedChanges, undefined, undefined, @@ -2100,7 +2068,7 @@ describe('paragraph converters', () => { vi.mocked(applyTrackedChangesModeToRuns).mockReturnValue([]); - const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16, styleContext, trackedChanges); + const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16, trackedChanges); expect(blocks).toHaveLength(0); }); @@ -2111,7 +2079,7 @@ describe('paragraph converters', () => { content: [{ type: 'text', text: 'Test' }], }; - paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16, styleContext); + paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16); expect(vi.mocked(applyTrackedChangesModeToRuns)).not.toHaveBeenCalled(); }); @@ -2130,7 +2098,7 @@ describe('paragraph converters', () => { vi.mocked(applyTrackedChangesModeToRuns).mockReturnValue([]); - const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16, styleContext, trackedChanges); + const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16, trackedChanges); expect(blocks.some((b) => b.kind === 'pageBreak')).toBe(true); }); @@ -2164,7 +2132,7 @@ describe('paragraph converters', () => { vi.mocked(trackedChangesCompatible).mockReturnValue(true); - const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16, styleContext); + const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16); const paraBlock = blocks[0] as ParagraphBlock; expect(paraBlock.runs).toHaveLength(1); @@ -2181,7 +2149,7 @@ describe('paragraph converters', () => { content: [{ type: 'hardBreak', attrs: { pageBreakType: 'page' } }], }; - const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16, styleContext); + const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16); expect(blocks.some((b) => b.kind === 'paragraph')).toBe(true); const paraBlock = blocks.find((b) => b.kind === 'paragraph') as ParagraphBlock; @@ -2199,7 +2167,7 @@ describe('paragraph converters', () => { ], }; - const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16, styleContext); + const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16); expect(blocks.length).toBeGreaterThan(1); expect(blocks.some((b) => b.kind === 'pageBreak')).toBe(true); @@ -2216,7 +2184,7 @@ describe('paragraph converters', () => { ], }; - const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16, styleContext); + const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16); const paraBlocks = blocks.filter((b) => b.kind === 'paragraph'); expect(paraBlocks[0].id).not.toBe(paraBlocks[1].id); @@ -2239,7 +2207,6 @@ describe('paragraph converters', () => { positions, 'Arial', 16, - styleContext, undefined, undefined, undefined, @@ -2272,7 +2239,6 @@ describe('paragraph converters', () => { positions, 'Arial', 16, - styleContext, undefined, undefined, undefined, @@ -2292,7 +2258,7 @@ describe('paragraph converters', () => { }; // No converters provided - const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16, styleContext); + const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16); // Should create empty paragraph expect(blocks).toHaveLength(1); @@ -2309,17 +2275,7 @@ describe('paragraph converters', () => { enableRichHyperlinks: true, }; - paragraphToFlowBlocks( - para, - nextBlockId, - positions, - 'Arial', - 16, - styleContext, - undefined, - undefined, - customHyperlinkConfig, - ); + paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16, undefined, undefined, customHyperlinkConfig); expect(vi.mocked(textNodeToRun)).toHaveBeenCalledWith( expect.any(Object), @@ -2345,7 +2301,6 @@ describe('paragraph converters', () => { positions, 'Arial', 16, - styleContext, undefined, undefined, undefined, @@ -2374,7 +2329,7 @@ describe('paragraph converters', () => { }); vi.mocked(deepClone).mockImplementation((attrs) => ({ ...attrs })); - const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16, styleContext); + const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16); const paraBlocks = blocks.filter((b) => b.kind === 'paragraph'); // Should be called once per paragraph block (2 blocks in this case) @@ -2961,7 +2916,6 @@ describe('paragraph converters', () => { describe('Integration: Inline images in paragraphs', () => { let nextBlockId: BlockIdGenerator; let positions: PositionMap; - let styleContext: StyleContext; beforeEach(() => { vi.clearAllMocks(); @@ -2969,7 +2923,6 @@ describe('paragraph converters', () => { let counter = 0; nextBlockId = vi.fn((kind: string) => `${kind}-${counter++}`); positions = new WeakMap(); - styleContext = {}; vi.mocked(computeParagraphAttrs).mockReturnValue({ paragraphAttrs: {}, resolvedParagraphProperties: {} }); vi.mocked(cloneParagraphAttrs).mockReturnValue({}); @@ -3003,7 +2956,6 @@ describe('paragraph converters', () => { positions, 'Arial', 16, - styleContext, undefined, undefined, undefined, @@ -3057,7 +3009,6 @@ describe('paragraph converters', () => { positions, 'Arial', 16, - styleContext, undefined, undefined, undefined, @@ -3097,7 +3048,7 @@ describe('paragraph converters', () => { ], }; - const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16, styleContext); + const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16); expect(blocks).toHaveLength(1); const paraBlock = blocks[0] as ParagraphBlock; @@ -3131,7 +3082,7 @@ describe('paragraph converters', () => { ], }; - const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16, styleContext); + const blocks = paragraphToFlowBlocks(para, nextBlockId, positions, 'Arial', 16); expect(blocks).toHaveLength(1); const paraBlock = blocks[0] as ParagraphBlock; diff --git a/packages/layout-engine/pm-adapter/src/converters/paragraph.ts b/packages/layout-engine/pm-adapter/src/converters/paragraph.ts index 111be4564..60b403be0 100644 --- a/packages/layout-engine/pm-adapter/src/converters/paragraph.ts +++ b/packages/layout-engine/pm-adapter/src/converters/paragraph.ts @@ -511,7 +511,6 @@ const applyInlineRunProperties = ( * @param positions - Position map for PM node tracking * @param defaultFont - Default font family * @param defaultSize - Default font size - * @param styleContext - Style resolution context * @param trackedChanges - Optional tracked changes configuration * @param bookmarks - Optional bookmark position map * @param hyperlinkConfig - Hyperlink configuration @@ -527,7 +526,6 @@ export function paragraphToFlowBlocks({ positions, defaultFont, defaultSize, - styleContext, trackedChangesConfig, bookmarks, hyperlinkConfig = DEFAULT_HYPERLINK_CONFIG, @@ -1104,7 +1102,6 @@ export function paragraphToFlowBlocks({ positions, defaultFont, defaultSize, - styleContext, trackedChangesConfig, bookmarks, hyperlinkConfig, @@ -1250,7 +1247,6 @@ export function handleParagraphNode(node: PMNode, context: NodeHandlerContext): positions, defaultFont, defaultSize, - styleContext, trackedChangesConfig, bookmarks, hyperlinkConfig, @@ -1285,7 +1281,6 @@ export function handleParagraphNode(node: PMNode, context: NodeHandlerContext): positions, defaultFont, defaultSize, - styleContext, trackedChangesConfig, bookmarks, hyperlinkConfig, diff --git a/packages/layout-engine/pm-adapter/src/converters/table.test.ts b/packages/layout-engine/pm-adapter/src/converters/table.test.ts index 8352be2d3..4af56b79a 100644 --- a/packages/layout-engine/pm-adapter/src/converters/table.test.ts +++ b/packages/layout-engine/pm-adapter/src/converters/table.test.ts @@ -8,7 +8,6 @@ import type { PMNode, BlockIdGenerator, PositionMap, - StyleContext, TrackedChangesConfig, HyperlinkConfig, ThemeColorPalette, @@ -34,7 +33,6 @@ const tableNodeToBlock = ( positions: PositionMap, defaultFont: string, defaultSize: number, - styleContext: StyleContext, trackedChangesConfig?: TrackedChangesConfig, bookmarks?: Map, hyperlinkConfig?: HyperlinkConfig, @@ -50,7 +48,6 @@ const tableNodeToBlock = ( positions, defaultFont, defaultSize, - styleContext, trackedChangesConfig, bookmarks, hyperlinkConfig: hyperlinkConfig ?? DEFAULT_HYPERLINK_CONFIG, @@ -62,14 +59,6 @@ const tableNodeToBlock = ( }; describe('table converter', () => { - const mockStyleContext: StyleContext = { - defaults: { - paragraphFont: 'Arial', - fontSize: 12, - decimalSeparator: '.', - }, - }; - describe('tableNodeToBlock', () => { const mockBlockIdGenerator: BlockIdGenerator = vi.fn((kind) => `test-${kind}`); const mockPositionMap: PositionMap = new Map(); @@ -96,7 +85,6 @@ describe('table converter', () => { mockPositionMap, 'Arial', 16, - mockStyleContext, undefined, undefined, undefined, @@ -129,7 +117,6 @@ describe('table converter', () => { mockPositionMap, 'Arial', 16, - mockStyleContext, undefined, undefined, undefined, @@ -162,7 +149,6 @@ describe('table converter', () => { mockPositionMap, 'Arial', 16, - mockStyleContext, undefined, undefined, undefined, @@ -216,7 +202,6 @@ describe('table converter', () => { mockPositionMap, 'Arial', 16, - mockStyleContext, undefined, undefined, undefined, @@ -251,7 +236,6 @@ describe('table converter', () => { mockPositionMap, 'Arial', 16, - mockStyleContext, undefined, undefined, undefined, @@ -292,7 +276,6 @@ describe('table converter', () => { mockPositionMap, 'Arial', 16, - mockStyleContext, undefined, undefined, undefined, @@ -330,7 +313,6 @@ describe('table converter', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 16, - styleContext: mockStyleContext, trackedChangesConfig: undefined, bookmarks: undefined, hyperlinkConfig: DEFAULT_HYPERLINK_CONFIG, @@ -383,7 +365,6 @@ describe('table converter', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 16, - styleContext: mockStyleContext, trackedChangesConfig: undefined, bookmarks: undefined, hyperlinkConfig: DEFAULT_HYPERLINK_CONFIG, @@ -456,7 +437,6 @@ describe('table converter', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 16, - styleContext: mockStyleContext, trackedChangesConfig: undefined, bookmarks: undefined, hyperlinkConfig: DEFAULT_HYPERLINK_CONFIG, @@ -503,7 +483,6 @@ describe('table converter', () => { mockPositionMap, 'Arial', 16, - mockStyleContext, undefined, undefined, undefined, @@ -542,7 +521,6 @@ describe('table converter', () => { mockPositionMap, 'Arial', 16, - mockStyleContext, undefined, undefined, undefined, @@ -585,7 +563,6 @@ describe('table converter', () => { mockPositionMap, 'Arial', 16, - mockStyleContext, undefined, undefined, undefined, @@ -625,7 +602,6 @@ describe('table converter', () => { mockPositionMap, 'Arial', 16, - mockStyleContext, undefined, undefined, undefined, @@ -664,7 +640,6 @@ describe('table converter', () => { mockPositionMap, 'Arial', 16, - mockStyleContext, undefined, undefined, undefined, @@ -705,7 +680,6 @@ describe('table converter', () => { mockPositionMap, 'Arial', 16, - mockStyleContext, undefined, undefined, undefined, @@ -741,7 +715,6 @@ describe('table converter', () => { mockPositionMap, 'Arial', 16, - mockStyleContext, undefined, undefined, undefined, @@ -779,7 +752,6 @@ describe('table converter', () => { mockPositionMap, 'Arial', 16, - mockStyleContext, undefined, undefined, undefined, @@ -818,7 +790,6 @@ describe('table converter', () => { mockPositionMap, 'Arial', 16, - mockStyleContext, undefined, undefined, undefined, @@ -862,7 +833,6 @@ describe('table converter', () => { mockPositionMap, 'Arial', 16, - mockStyleContext, undefined, undefined, undefined, @@ -899,7 +869,6 @@ describe('table converter', () => { mockPositionMap, 'Arial', 16, - mockStyleContext, undefined, undefined, undefined, @@ -935,7 +904,6 @@ describe('table converter', () => { mockPositionMap, 'Arial', 16, - mockStyleContext, undefined, undefined, undefined, @@ -973,7 +941,6 @@ describe('table converter', () => { mockPositionMap, 'Arial', 16, - mockStyleContext, undefined, undefined, undefined, @@ -1011,7 +978,6 @@ describe('table converter', () => { mockPositionMap, 'Arial', 16, - mockStyleContext, undefined, undefined, undefined, @@ -1047,7 +1013,6 @@ describe('table converter', () => { mockPositionMap, 'Arial', 16, - mockStyleContext, undefined, undefined, undefined, @@ -1128,7 +1093,6 @@ describe('table converter', () => { mockPositionMap, 'Arial', 16, - mockStyleContext, undefined, undefined, undefined, @@ -1168,7 +1132,6 @@ describe('table converter', () => { mockPositionMap, 'Arial', 16, - mockStyleContext, undefined, undefined, undefined, @@ -1210,7 +1173,6 @@ describe('table converter', () => { mockPositionMap, 'Arial', 16, - mockStyleContext, trackedChangesConfig, undefined, undefined, @@ -1243,7 +1205,6 @@ describe('table converter', () => { mockPositionMap, 'Arial', 16, - mockStyleContext, undefined, undefined, undefined, @@ -1289,7 +1250,6 @@ describe('table converter', () => { positions: new Map(), defaultFont: 'Arial', defaultSize: 16, - styleContext: mockStyleContext, trackedChangesConfig: undefined, bookmarks: undefined, hyperlinkConfig: undefined, @@ -1321,7 +1281,6 @@ describe('table converter', () => { positions: new Map(), defaultFont: 'Arial', defaultSize: 16, - styleContext: mockStyleContext, trackedChangesConfig: undefined, bookmarks: undefined, hyperlinkConfig: undefined, @@ -1382,7 +1341,6 @@ describe('table converter', () => { mockPositionMap, 'Arial', 12, - mockStyleContext, undefined, undefined, undefined, @@ -1432,7 +1390,6 @@ describe('table converter', () => { mockPositionMap, 'Arial', 12, - mockStyleContext, undefined, undefined, undefined, @@ -1477,7 +1434,6 @@ describe('table converter', () => { mockPositionMap, 'Arial', 12, - mockStyleContext, undefined, undefined, undefined, @@ -1524,7 +1480,6 @@ describe('table converter', () => { mockPositionMap, 'Arial', 12, - mockStyleContext, undefined, undefined, undefined, @@ -1570,7 +1525,6 @@ describe('table converter', () => { mockPositionMap, 'Arial', 12, - mockStyleContext, undefined, undefined, undefined, @@ -1611,7 +1565,6 @@ describe('table converter', () => { mockPositionMap, 'Arial', 12, - mockStyleContext, undefined, undefined, undefined, @@ -1654,7 +1607,6 @@ describe('table converter', () => { mockPositionMap, 'Arial', 12, - mockStyleContext, undefined, undefined, undefined, diff --git a/packages/layout-engine/pm-adapter/src/converters/table.ts b/packages/layout-engine/pm-adapter/src/converters/table.ts index 0c4034f5c..c2c371431 100644 --- a/packages/layout-engine/pm-adapter/src/converters/table.ts +++ b/packages/layout-engine/pm-adapter/src/converters/table.ts @@ -24,7 +24,6 @@ import type { NodeHandlerContext, BlockIdGenerator, PositionMap, - StyleContext, TrackedChangesConfig, HyperlinkConfig, ThemeColorPalette, @@ -49,7 +48,6 @@ type TableParserDependencies = { positions: PositionMap; defaultFont: string; defaultSize: number; - styleContext: StyleContext; trackedChangesConfig?: TrackedChangesConfig; bookmarks?: Map; hyperlinkConfig: HyperlinkConfig; @@ -253,7 +251,6 @@ const parseTableCell = (args: ParseTableCellArgs): TableCell | null => { positions: context.positions, defaultFont: context.defaultFont, defaultSize: context.defaultSize, - styleContext: context.styleContext, trackedChangesConfig: context.trackedChangesConfig, bookmarks: context.bookmarks, hyperlinkConfig: context.hyperlinkConfig, @@ -277,7 +274,6 @@ const parseTableCell = (args: ParseTableCellArgs): TableCell | null => { positions: context.positions, defaultFont: context.defaultFont, defaultSize: context.defaultSize, - styleContext: context.styleContext, trackedChangesConfig: context.trackedChangesConfig, bookmarks: context.bookmarks, hyperlinkConfig: context.hyperlinkConfig, @@ -296,7 +292,6 @@ const parseTableCell = (args: ParseTableCellArgs): TableCell | null => { positions: context.positions, defaultFont: context.defaultFont, defaultSize: context.defaultSize, - styleContext: context.styleContext, trackedChangesConfig: context.trackedChangesConfig, bookmarks: context.bookmarks, hyperlinkConfig: context.hyperlinkConfig, @@ -322,7 +317,6 @@ const parseTableCell = (args: ParseTableCellArgs): TableCell | null => { positions: context.positions, defaultFont: context.defaultFont, defaultSize: context.defaultSize, - styleContext: context.styleContext, trackedChangesConfig: context.trackedChangesConfig, bookmarks: context.bookmarks, hyperlinkConfig: context.hyperlinkConfig, @@ -676,7 +670,6 @@ export function tableNodeToBlock({ positions, defaultFont, defaultSize, - styleContext, trackedChangesConfig, bookmarks, hyperlinkConfig, @@ -694,7 +687,6 @@ export function tableNodeToBlock({ positions, defaultFont, defaultSize, - styleContext, trackedChangesConfig, bookmarks, hyperlinkConfig, @@ -884,7 +876,6 @@ export function handleTableNode(node: PMNode, context: NodeHandlerContext): void positions, defaultFont, defaultSize, - styleContext, trackedChangesConfig, bookmarks, hyperlinkConfig, @@ -899,7 +890,6 @@ export function handleTableNode(node: PMNode, context: NodeHandlerContext): void positions, defaultFont, defaultSize, - styleContext, trackedChangesConfig, bookmarks, hyperlinkConfig, diff --git a/packages/layout-engine/pm-adapter/src/internal.test.ts b/packages/layout-engine/pm-adapter/src/internal.test.ts index 144c14c43..ea932b5c2 100644 --- a/packages/layout-engine/pm-adapter/src/internal.test.ts +++ b/packages/layout-engine/pm-adapter/src/internal.test.ts @@ -637,26 +637,6 @@ describe('internal', () => { }); describe('options handling', () => { - it('should pass custom decimal separator to style context', () => { - const doc: PMNode = { - type: 'doc', - content: [{ type: 'paragraph', content: [] }], - }; - - toFlowBlocks(doc, { locale: { decimalSeparator: ',' } }); - - expect(handleParagraphNode).toHaveBeenCalledWith( - expect.any(Object), - expect.objectContaining({ - styleContext: expect.objectContaining({ - defaults: expect.objectContaining({ - decimalSeparator: ',', - }), - }), - }), - ); - }); - it('should extract lang from document attrs', () => { const doc: PMNode = { type: 'doc', @@ -902,7 +882,6 @@ describe('internal', () => { positions: context.positions, defaultFont: context.defaultFont, defaultSize: context.defaultSize, - styleContext: context.styleContext, trackedChangesConfig: context.trackedChangesConfig, bookmarks: context.bookmarks, hyperlinkConfig: context.hyperlinkConfig, diff --git a/packages/layout-engine/pm-adapter/src/internal.ts b/packages/layout-engine/pm-adapter/src/internal.ts index eeb62a656..c9c278fb2 100644 --- a/packages/layout-engine/pm-adapter/src/internal.ts +++ b/packages/layout-engine/pm-adapter/src/internal.ts @@ -131,27 +131,6 @@ export function toFlowBlocks(pmDoc: PMNode | object, options?: AdapterOptions): const doc = pmDoc as PMNode; - const docAttrs = (typeof doc.attrs === 'object' && doc.attrs !== null ? doc.attrs : {}) as Record; - const docDecimalSeparator = pickDecimalSeparator(doc.attrs?.decimalSeparator); - const docLang = pickLang(docAttrs.lang ?? docAttrs.language ?? docAttrs.locale); - const derivedSeparator = docLang ? defaultDecimalSeparatorFor(docLang) : undefined; - const docTabIntervalTwips = - pickNumber(docAttrs.defaultTabIntervalTwips ?? docAttrs.tabIntervalTwips ?? undefined) ?? - ((): number | undefined => { - const px = pickNumber(docAttrs.defaultTabIntervalPx ?? docAttrs.tabIntervalPx); - return px != null ? Math.round(px * 15) : undefined; - })(); - const optionDecimalSeparator = pickDecimalSeparator(options?.locale?.decimalSeparator); - const decimalSeparator = - optionDecimalSeparator ?? docDecimalSeparator ?? derivedSeparator ?? DEFAULT_DECIMAL_SEPARATOR; - const styleContext: StyleContext = { - defaults: { - paragraphFont: defaultFont, - fontSize: pxToPt(defaultSize) ?? 12, - decimalSeparator, - defaultTabIntervalTwips: docTabIntervalTwips, - }, - }; const trackedChangesMode = isValidTrackedMode(options?.trackedChangesMode) ? options.trackedChangesMode : 'review'; const enableTrackedChanges = options?.enableTrackedChanges ?? true; const trackedChangesConfig: TrackedChangesConfig = { @@ -217,7 +196,6 @@ export function toFlowBlocks(pmDoc: PMNode | object, options?: AdapterOptions): positions, defaultFont, defaultSize, - styleContext, converterContext, trackedChangesConfig, hyperlinkConfig, diff --git a/packages/layout-engine/pm-adapter/src/sdt/document-index.test.ts b/packages/layout-engine/pm-adapter/src/sdt/document-index.test.ts index 7334fbb5f..3aab93174 100644 --- a/packages/layout-engine/pm-adapter/src/sdt/document-index.test.ts +++ b/packages/layout-engine/pm-adapter/src/sdt/document-index.test.ts @@ -28,7 +28,6 @@ describe('document-index', () => { positions: [], defaultFont: 'Arial', defaultSize: 12, - styleContext: {}, listCounterContext: { getListCounter: vi.fn().mockReturnValue(1), incrementListCounter: vi.fn(), diff --git a/packages/layout-engine/pm-adapter/src/sdt/document-index.ts b/packages/layout-engine/pm-adapter/src/sdt/document-index.ts index 71da588d7..c77b509c2 100644 --- a/packages/layout-engine/pm-adapter/src/sdt/document-index.ts +++ b/packages/layout-engine/pm-adapter/src/sdt/document-index.ts @@ -47,7 +47,6 @@ export function handleIndexNode(node: PMNode, context: NodeHandlerContext): void positions, defaultFont, defaultSize, - styleContext, trackedChangesConfig, bookmarks, hyperlinkConfig, @@ -84,7 +83,6 @@ export function handleIndexNode(node: PMNode, context: NodeHandlerContext): void positions, defaultFont, defaultSize, - styleContext, trackedChangesConfig, bookmarks, hyperlinkConfig, diff --git a/packages/layout-engine/pm-adapter/src/sdt/document-part-object.test.ts b/packages/layout-engine/pm-adapter/src/sdt/document-part-object.test.ts index cc0140057..8f0d79f7f 100644 --- a/packages/layout-engine/pm-adapter/src/sdt/document-part-object.test.ts +++ b/packages/layout-engine/pm-adapter/src/sdt/document-part-object.test.ts @@ -30,10 +30,6 @@ describe('document-part-object', () => { describe('handleDocumentPartObjectNode', () => { const mockBlockIdGenerator = vi.fn((kind: string) => `${kind}-test-id`); const mockPositionMap = new Map(); - const mockStyleContext = { - styles: new Map(), - numbering: new Map(), - }; const mockHyperlinkConfig = { enableRichHyperlinks: false, }; @@ -60,7 +56,6 @@ describe('document-part-object', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, bookmarks: new Map(), hyperlinkConfig: mockHyperlinkConfig, enableComments: mockEnableComments, @@ -339,7 +334,7 @@ describe('document-part-object', () => { // ==================== Context Passing Tests ==================== describe('Context passing to processTocChildren', () => { - it('should pass correct style context', () => { + it('should pass correct context parameters', () => { const node: PMNode = { type: 'documentPartObject', content: [{ type: 'paragraph' }], @@ -359,7 +354,6 @@ describe('document-part-object', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, bookmarks: mockContext.bookmarks, hyperlinkConfig: mockHyperlinkConfig, converters: mockContext.converters, diff --git a/packages/layout-engine/pm-adapter/src/sdt/document-part-object.ts b/packages/layout-engine/pm-adapter/src/sdt/document-part-object.ts index c3ea6583e..5c3a49bc5 100644 --- a/packages/layout-engine/pm-adapter/src/sdt/document-part-object.ts +++ b/packages/layout-engine/pm-adapter/src/sdt/document-part-object.ts @@ -27,7 +27,6 @@ export function handleDocumentPartObjectNode(node: PMNode, context: NodeHandlerC positions, defaultFont, defaultSize, - styleContext, bookmarks, hyperlinkConfig, converters, @@ -51,7 +50,6 @@ export function handleDocumentPartObjectNode(node: PMNode, context: NodeHandlerC positions, defaultFont, defaultSize, - styleContext, bookmarks, hyperlinkConfig, enableComments, @@ -71,7 +69,6 @@ export function handleDocumentPartObjectNode(node: PMNode, context: NodeHandlerC positions, defaultFont, defaultSize, - styleContext, trackedChangesConfig, bookmarks, hyperlinkConfig, diff --git a/packages/layout-engine/pm-adapter/src/sdt/document-section.test.ts b/packages/layout-engine/pm-adapter/src/sdt/document-section.test.ts index bed28bda8..12da5dfc7 100644 --- a/packages/layout-engine/pm-adapter/src/sdt/document-section.test.ts +++ b/packages/layout-engine/pm-adapter/src/sdt/document-section.test.ts @@ -32,10 +32,6 @@ describe('document-section', () => { describe('processDocumentSectionChildren', () => { const mockBlockIdGenerator = vi.fn((kind: string) => `${kind}-test-id`); const mockPositionMap = new Map(); - const mockStyleContext = { - styles: new Map(), - numbering: new Map(), - }; const mockHyperlinkConfig = { enableRichHyperlinks: false, }; @@ -65,7 +61,6 @@ describe('document-section', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, hyperlinkConfig: mockHyperlinkConfig, }, { blocks, recordBlockKind }, @@ -107,7 +102,6 @@ describe('document-section', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, hyperlinkConfig: mockHyperlinkConfig, }, { blocks, recordBlockKind }, @@ -153,7 +147,6 @@ describe('document-section', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, hyperlinkConfig: mockHyperlinkConfig, }, { blocks, recordBlockKind }, @@ -191,7 +184,6 @@ describe('document-section', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, hyperlinkConfig: mockHyperlinkConfig, }, { blocks, recordBlockKind }, @@ -224,7 +216,6 @@ describe('document-section', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, hyperlinkConfig: mockHyperlinkConfig, }, { blocks, recordBlockKind }, @@ -258,7 +249,6 @@ describe('document-section', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, hyperlinkConfig: mockHyperlinkConfig, }, { blocks, recordBlockKind }, @@ -276,7 +266,6 @@ describe('document-section', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, hyperlinkConfig: mockHyperlinkConfig, }), ); @@ -302,7 +291,6 @@ describe('document-section', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, hyperlinkConfig: mockHyperlinkConfig, }, { blocks, recordBlockKind }, @@ -336,7 +324,6 @@ describe('document-section', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, hyperlinkConfig: mockHyperlinkConfig, }, { blocks, recordBlockKind }, @@ -369,7 +356,6 @@ describe('document-section', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, hyperlinkConfig: mockHyperlinkConfig, }, { blocks, recordBlockKind }, @@ -404,7 +390,6 @@ describe('document-section', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, hyperlinkConfig: mockHyperlinkConfig, }, { blocks, recordBlockKind }, @@ -453,7 +438,6 @@ describe('document-section', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, hyperlinkConfig: mockHyperlinkConfig, }, { blocks, recordBlockKind }, @@ -471,7 +455,6 @@ describe('document-section', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, hyperlinkConfig: mockHyperlinkConfig, }), ); @@ -496,7 +479,6 @@ describe('document-section', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, hyperlinkConfig: mockHyperlinkConfig, }, { blocks, recordBlockKind }, @@ -528,7 +510,6 @@ describe('document-section', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, hyperlinkConfig: mockHyperlinkConfig, }, { blocks, recordBlockKind }, @@ -563,7 +544,6 @@ describe('document-section', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, hyperlinkConfig: mockHyperlinkConfig, }, { blocks, recordBlockKind }, @@ -596,7 +576,6 @@ describe('document-section', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, hyperlinkConfig: mockHyperlinkConfig, }, { blocks, recordBlockKind }, @@ -627,7 +606,6 @@ describe('document-section', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, hyperlinkConfig: mockHyperlinkConfig, }, { blocks, recordBlockKind }, @@ -675,7 +653,6 @@ describe('document-section', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, hyperlinkConfig: mockHyperlinkConfig, }, { blocks, recordBlockKind }, @@ -722,7 +699,6 @@ describe('document-section', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, hyperlinkConfig: mockHyperlinkConfig, }, { blocks, recordBlockKind }, @@ -768,7 +744,6 @@ describe('document-section', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, hyperlinkConfig: mockHyperlinkConfig, }, { blocks, recordBlockKind }, @@ -810,7 +785,6 @@ describe('document-section', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, hyperlinkConfig: mockHyperlinkConfig, }, { blocks, recordBlockKind }, @@ -844,7 +818,6 @@ describe('document-section', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, hyperlinkConfig: mockHyperlinkConfig, }, { blocks, recordBlockKind }, @@ -890,7 +863,6 @@ describe('document-section', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, hyperlinkConfig: mockHyperlinkConfig, }, { blocks, recordBlockKind }, @@ -937,7 +909,6 @@ describe('document-section', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, hyperlinkConfig: mockHyperlinkConfig, }, { blocks, recordBlockKind }, @@ -989,7 +960,6 @@ describe('document-section', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, hyperlinkConfig: mockHyperlinkConfig, }, { blocks, recordBlockKind }, @@ -1046,7 +1016,6 @@ describe('document-section', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, hyperlinkConfig: mockHyperlinkConfig, }, { blocks, recordBlockKind }, @@ -1102,7 +1071,6 @@ describe('document-section', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, hyperlinkConfig: mockHyperlinkConfig, }, { blocks, recordBlockKind }, @@ -1139,7 +1107,6 @@ describe('document-section', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, hyperlinkConfig: mockHyperlinkConfig, }, { blocks, recordBlockKind }, @@ -1179,7 +1146,6 @@ describe('document-section', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, hyperlinkConfig: mockHyperlinkConfig, }, { blocks, recordBlockKind }, @@ -1220,7 +1186,6 @@ describe('document-section', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, hyperlinkConfig: mockHyperlinkConfig, }, { blocks, recordBlockKind }, @@ -1275,7 +1240,6 @@ describe('document-section', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, hyperlinkConfig: mockHyperlinkConfig, }, { blocks, recordBlockKind }, @@ -1324,7 +1288,6 @@ describe('document-section', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, hyperlinkConfig: mockHyperlinkConfig, }, { blocks, recordBlockKind }, @@ -1373,7 +1336,6 @@ describe('document-section', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, hyperlinkConfig: mockHyperlinkConfig, }, { blocks, recordBlockKind }, @@ -1416,7 +1378,6 @@ describe('document-section', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, hyperlinkConfig: mockHyperlinkConfig, }, { blocks, recordBlockKind }, @@ -1458,7 +1419,6 @@ describe('document-section', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, bookmarks: mockBookmarks, hyperlinkConfig: mockHyperlinkConfig, }, @@ -1477,7 +1437,6 @@ describe('document-section', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, bookmarks: mockBookmarks, hyperlinkConfig: mockHyperlinkConfig, }), @@ -1503,7 +1462,6 @@ describe('document-section', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, hyperlinkConfig: mockHyperlinkConfig, }, { blocks, recordBlockKind }, @@ -1537,7 +1495,6 @@ describe('document-section', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, hyperlinkConfig: mockHyperlinkConfig, }, { blocks, recordBlockKind }, @@ -1577,7 +1534,6 @@ describe('document-section', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, hyperlinkConfig: mockHyperlinkConfig, }, { blocks, recordBlockKind }, @@ -1612,7 +1568,6 @@ describe('document-section', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, hyperlinkConfig: mockHyperlinkConfig, }, { blocks, recordBlockKind }, diff --git a/packages/layout-engine/pm-adapter/src/sdt/document-section.ts b/packages/layout-engine/pm-adapter/src/sdt/document-section.ts index a1ee3960c..ca12f1c49 100644 --- a/packages/layout-engine/pm-adapter/src/sdt/document-section.ts +++ b/packages/layout-engine/pm-adapter/src/sdt/document-section.ts @@ -5,12 +5,11 @@ * Document sections can contain paragraphs, lists, tables, images, and nested SDTs. */ -import type { FlowBlock, ParagraphBlock, SdtMetadata, TrackedChangeMeta } from '@superdoc/contracts'; +import type { FlowBlock, ParagraphBlock, SdtMetadata } from '@superdoc/contracts'; import type { PMNode, BlockIdGenerator, PositionMap, - StyleContext, HyperlinkConfig, NodeHandlerContext, TrackedChangesConfig, @@ -36,7 +35,6 @@ interface ProcessingContext { positions: PositionMap; defaultFont: string; defaultSize: number; - styleContext: StyleContext; trackedChangesConfig?: TrackedChangesConfig; bookmarks?: Map; hyperlinkConfig: HyperlinkConfig; @@ -76,7 +74,6 @@ function processParagraphChild( positions: context.positions, defaultFont: context.defaultFont, defaultSize: context.defaultSize, - styleContext: context.styleContext, trackedChangesConfig: undefined, // trackedChanges bookmarks: context.bookmarks, hyperlinkConfig: context.hyperlinkConfig, @@ -117,7 +114,6 @@ function processTableChild( positions: context.positions, defaultFont: context.defaultFont, defaultSize: context.defaultSize, - styleContext: context.styleContext, trackedChangesConfig: context.trackedChangesConfig, bookmarks: context.bookmarks, hyperlinkConfig: context.hyperlinkConfig, @@ -189,7 +185,6 @@ function processNestedStructuredContent( positions: context.positions, defaultFont: context.defaultFont, defaultSize: context.defaultSize, - styleContext: context.styleContext, trackedChangesConfig: context.trackedChangesConfig, bookmarks: context.bookmarks, hyperlinkConfig: context.hyperlinkConfig, @@ -213,7 +208,6 @@ function processNestedStructuredContent( positions: context.positions, defaultFont: context.defaultFont, defaultSize: context.defaultSize, - styleContext: context.styleContext, trackedChangesConfig: context.trackedChangesConfig, bookmarks: context.bookmarks, hyperlinkConfig: context.hyperlinkConfig, @@ -268,7 +262,6 @@ function processDocumentPartObject( positions: context.positions, defaultFont: context.defaultFont, defaultSize: context.defaultSize, - styleContext: context.styleContext, bookmarks: context.bookmarks, hyperlinkConfig: context.hyperlinkConfig, enableComments: context.enableComments, @@ -355,7 +348,6 @@ export function handleDocumentSectionNode(node: PMNode, context: NodeHandlerCont positions, defaultFont, defaultSize, - styleContext, bookmarks, hyperlinkConfig, converters, @@ -374,7 +366,6 @@ export function handleDocumentSectionNode(node: PMNode, context: NodeHandlerCont positions, defaultFont, defaultSize, - styleContext, bookmarks, trackedChangesConfig, hyperlinkConfig, diff --git a/packages/layout-engine/pm-adapter/src/sdt/index.test.ts b/packages/layout-engine/pm-adapter/src/sdt/index.test.ts index a7a1d489d..43edf6163 100644 --- a/packages/layout-engine/pm-adapter/src/sdt/index.test.ts +++ b/packages/layout-engine/pm-adapter/src/sdt/index.test.ts @@ -176,7 +176,6 @@ describe('sdt module exports', () => { positions: new Map(), defaultFont: 'Arial', defaultSize: 12, - styleContext: { styles: new Map(), numbering: new Map() }, listCounterContext: { getListCounter: () => ({ value: 0, styleId: null }), incrementListCounter: () => undefined, diff --git a/packages/layout-engine/pm-adapter/src/sdt/structured-content-block.test.ts b/packages/layout-engine/pm-adapter/src/sdt/structured-content-block.test.ts index 4b70c4331..80a5466d6 100644 --- a/packages/layout-engine/pm-adapter/src/sdt/structured-content-block.test.ts +++ b/packages/layout-engine/pm-adapter/src/sdt/structured-content-block.test.ts @@ -22,10 +22,6 @@ describe('structured-content-block', () => { describe('handleStructuredContentBlockNode', () => { const mockBlockIdGenerator = vi.fn((kind: string) => `${kind}-test-id`); const mockPositionMap = new Map(); - const mockStyleContext = { - styles: new Map(), - numbering: new Map(), - }; const mockHyperlinkConfig = { enableRichHyperlinks: false, }; @@ -62,7 +58,6 @@ describe('structured-content-block', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, trackedChangesConfig: mockTrackedChangesConfig, bookmarks: mockBookmarks, hyperlinkConfig: mockHyperlinkConfig, @@ -96,7 +91,6 @@ describe('structured-content-block', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, trackedChangesConfig: mockTrackedChangesConfig, bookmarks: mockBookmarks, hyperlinkConfig: mockHyperlinkConfig, @@ -127,7 +121,6 @@ describe('structured-content-block', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, trackedChangesConfig: mockTrackedChangesConfig, bookmarks: mockBookmarks, hyperlinkConfig: mockHyperlinkConfig, @@ -171,7 +164,6 @@ describe('structured-content-block', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, trackedChangesConfig: mockTrackedChangesConfig, bookmarks: mockBookmarks, hyperlinkConfig: mockHyperlinkConfig, @@ -221,7 +213,6 @@ describe('structured-content-block', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, trackedChangesConfig: mockTrackedChangesConfig, bookmarks: mockBookmarks, hyperlinkConfig: mockHyperlinkConfig, @@ -260,7 +251,6 @@ describe('structured-content-block', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, trackedChangesConfig: mockTrackedChangesConfig, bookmarks: mockBookmarks, hyperlinkConfig: mockHyperlinkConfig, @@ -300,7 +290,6 @@ describe('structured-content-block', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, trackedChangesConfig: mockTrackedChangesConfig, bookmarks: mockBookmarks, hyperlinkConfig: mockHyperlinkConfig, @@ -320,7 +309,6 @@ describe('structured-content-block', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, trackedChangesConfig: mockTrackedChangesConfig, bookmarks: mockBookmarks, hyperlinkConfig: mockHyperlinkConfig, @@ -355,7 +343,6 @@ describe('structured-content-block', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, trackedChangesConfig: mockTrackedChangesConfig, bookmarks: mockBookmarks, hyperlinkConfig: mockHyperlinkConfig, @@ -396,7 +383,6 @@ describe('structured-content-block', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, trackedChangesConfig: mockTrackedChangesConfig, bookmarks: mockBookmarks, hyperlinkConfig: mockHyperlinkConfig, @@ -437,7 +423,6 @@ describe('structured-content-block', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, trackedChangesConfig: mockTrackedChangesConfig, bookmarks: mockBookmarks, hyperlinkConfig: mockHyperlinkConfig, @@ -484,7 +469,6 @@ describe('structured-content-block', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, trackedChangesConfig: mockTrackedChangesConfig, bookmarks: mockBookmarks, hyperlinkConfig: mockHyperlinkConfig, @@ -521,7 +505,6 @@ describe('structured-content-block', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, trackedChangesConfig: mockTrackedChangesConfig, bookmarks: mockBookmarks, hyperlinkConfig: mockHyperlinkConfig, @@ -566,7 +549,6 @@ describe('structured-content-block', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, trackedChangesConfig: mockTrackedChangesConfig, bookmarks: mockBookmarks, hyperlinkConfig: mockHyperlinkConfig, @@ -603,7 +585,6 @@ describe('structured-content-block', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, trackedChangesConfig: mockTrackedChangesConfig, bookmarks: mockBookmarks, hyperlinkConfig: mockHyperlinkConfig, @@ -649,7 +630,6 @@ describe('structured-content-block', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, trackedChangesConfig: mockTrackedChangesConfig, bookmarks: mockBookmarks, hyperlinkConfig: mockHyperlinkConfig, @@ -694,7 +674,6 @@ describe('structured-content-block', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, trackedChangesConfig: mockTrackedChangesConfig, bookmarks: mockBookmarks, hyperlinkConfig: mockHyperlinkConfig, @@ -736,7 +715,6 @@ describe('structured-content-block', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, trackedChangesConfig: mockTrackedChangesConfig, bookmarks: mockBookmarks, hyperlinkConfig: mockHyperlinkConfig, @@ -774,7 +752,6 @@ describe('structured-content-block', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, trackedChangesConfig: mockTrackedChangesConfig, bookmarks: mockBookmarks, hyperlinkConfig: mockHyperlinkConfig, @@ -811,7 +788,6 @@ describe('structured-content-block', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, trackedChangesConfig: mockTrackedChangesConfig, bookmarks: mockBookmarks, hyperlinkConfig: mockHyperlinkConfig, @@ -856,7 +832,6 @@ describe('structured-content-block', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, trackedChangesConfig: mockTrackedChangesConfig, bookmarks: mockBookmarks, hyperlinkConfig: mockHyperlinkConfig, @@ -901,7 +876,6 @@ describe('structured-content-block', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, trackedChangesConfig: mockTrackedChangesConfig, bookmarks: mockBookmarks, hyperlinkConfig: mockHyperlinkConfig, diff --git a/packages/layout-engine/pm-adapter/src/sdt/structured-content-block.ts b/packages/layout-engine/pm-adapter/src/sdt/structured-content-block.ts index 9c1f4b952..362efdf40 100644 --- a/packages/layout-engine/pm-adapter/src/sdt/structured-content-block.ts +++ b/packages/layout-engine/pm-adapter/src/sdt/structured-content-block.ts @@ -26,7 +26,6 @@ export function handleStructuredContentBlockNode(node: PMNode, context: NodeHand positions, defaultFont, defaultSize, - styleContext, trackedChangesConfig, bookmarks, hyperlinkConfig, @@ -46,7 +45,6 @@ export function handleStructuredContentBlockNode(node: PMNode, context: NodeHand positions, defaultFont, defaultSize, - styleContext, trackedChangesConfig, bookmarks, hyperlinkConfig, @@ -72,7 +70,6 @@ export function handleStructuredContentBlockNode(node: PMNode, context: NodeHand positions, defaultFont, defaultSize, - styleContext, trackedChangesConfig, bookmarks, hyperlinkConfig, diff --git a/packages/layout-engine/pm-adapter/src/sdt/toc.test.ts b/packages/layout-engine/pm-adapter/src/sdt/toc.test.ts index 9214a45ba..c2ec9257c 100644 --- a/packages/layout-engine/pm-adapter/src/sdt/toc.test.ts +++ b/packages/layout-engine/pm-adapter/src/sdt/toc.test.ts @@ -145,10 +145,6 @@ describe('toc', () => { describe('processTocChildren', () => { const mockBlockIdGenerator = () => 'test-id'; const mockPositionMap = new Map(); - const mockStyleContext = { - styles: new Map(), - numbering: new Map(), - }; const mockHyperlinkConfig = { mode: 'preserve' as const, }; @@ -192,7 +188,6 @@ describe('toc', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, hyperlinkConfig: mockHyperlinkConfig, enableComments: true, converters: { paragraphToFlowBlocks: mockParagraphConverter } as never, @@ -249,7 +244,6 @@ describe('toc', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, hyperlinkConfig: mockHyperlinkConfig, enableComments: true, converters: { paragraphToFlowBlocks: mockParagraphConverter } as never, @@ -304,7 +298,6 @@ describe('toc', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, hyperlinkConfig: mockHyperlinkConfig, enableComments: true, converters: { paragraphToFlowBlocks: mockParagraphConverter } as never, @@ -357,7 +350,6 @@ describe('toc', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, hyperlinkConfig: mockHyperlinkConfig, enableComments: true, converters: { paragraphToFlowBlocks: mockParagraphConverter } as never, @@ -415,7 +407,6 @@ describe('toc', () => { positions: mockPositionMap, defaultFont: 'Arial', defaultSize: 12, - styleContext: mockStyleContext, hyperlinkConfig: mockHyperlinkConfig, enableComments: true, converters: { paragraphToFlowBlocks: mockParagraphConverter } as never, @@ -464,7 +455,6 @@ describe('toc', () => { positions: mockPositionMap, defaultFont: 'Calibri', defaultSize: 14, - styleContext: mockStyleContext, bookmarks: mockBookmarks, trackedChangesConfig: mockTrackedChanges, hyperlinkConfig: mockHyperlinkConfig, @@ -482,7 +472,6 @@ describe('toc', () => { positions: mockPositionMap, defaultFont: 'Calibri', defaultSize: 14, - styleContext: mockStyleContext, trackedChangesConfig: mockTrackedChanges, bookmarks: mockBookmarks, hyperlinkConfig: mockHyperlinkConfig, diff --git a/packages/layout-engine/pm-adapter/src/sdt/toc.ts b/packages/layout-engine/pm-adapter/src/sdt/toc.ts index ecff0c6fb..3d5566fc5 100644 --- a/packages/layout-engine/pm-adapter/src/sdt/toc.ts +++ b/packages/layout-engine/pm-adapter/src/sdt/toc.ts @@ -10,7 +10,6 @@ import type { PMNode, BlockIdGenerator, PositionMap, - StyleContext, HyperlinkConfig, TrackedChangesConfig, NodeHandlerContext, @@ -97,7 +96,6 @@ export function processTocChildren( positions: PositionMap; defaultFont: string; defaultSize: number; - styleContext: StyleContext; bookmarks?: Map; trackedChangesConfig?: TrackedChangesConfig; hyperlinkConfig: HyperlinkConfig; @@ -124,7 +122,6 @@ export function processTocChildren( positions: context.positions, defaultFont: context.defaultFont, defaultSize: context.defaultSize, - styleContext: context.styleContext, trackedChangesConfig: context.trackedChangesConfig, bookmarks: context.bookmarks, hyperlinkConfig: context.hyperlinkConfig, @@ -179,7 +176,6 @@ export function handleTableOfContentsNode(node: PMNode, context: NodeHandlerCont positions, defaultFont, defaultSize, - styleContext, trackedChangesConfig, bookmarks, hyperlinkConfig, @@ -199,7 +195,6 @@ export function handleTableOfContentsNode(node: PMNode, context: NodeHandlerCont positions, defaultFont, defaultSize, - styleContext, trackedChangesConfig, bookmarks, themeColors, diff --git a/packages/layout-engine/pm-adapter/src/types.ts b/packages/layout-engine/pm-adapter/src/types.ts index 2f3cb3d09..cb42358f0 100644 --- a/packages/layout-engine/pm-adapter/src/types.ts +++ b/packages/layout-engine/pm-adapter/src/types.ts @@ -3,7 +3,6 @@ */ import type { TrackedChangesMode, SectionMetadata, FlowBlock } from '@superdoc/contracts'; -import type { StyleContext as StyleEngineContext, ComputedParagraphStyle } from '@superdoc/style-engine'; import type { SectionRange } from './sections/index.js'; import type { ConverterContext } from './converter-context.js'; import type { paragraphToFlowBlocks } from './converters/paragraph.js'; @@ -18,9 +17,6 @@ import type { } from './converters/shapes.js'; export type { ConverterContext } from './converter-context.js'; -export type StyleContext = StyleEngineContext; -export type { ComputedParagraphStyle }; - export type ThemeColorPalette = Record; /** @@ -282,7 +278,6 @@ export interface NodeHandlerContext { // Style & defaults defaultFont: string; defaultSize: number; - styleContext: StyleContext; converterContext: ConverterContext; // Tracked changes & hyperlinks @@ -319,7 +314,6 @@ export type ParagraphToFlowBlocksParams = { positions: PositionMap; defaultFont: string; defaultSize: number; - styleContext: StyleContext; trackedChangesConfig?: TrackedChangesConfig; hyperlinkConfig: HyperlinkConfig; themeColors?: ThemeColorPalette; @@ -335,7 +329,6 @@ export type TableNodeToBlockParams = { positions: PositionMap; defaultFont: string; defaultSize: number; - styleContext: StyleContext; trackedChangesConfig?: TrackedChangesConfig; bookmarks?: Map; hyperlinkConfig: HyperlinkConfig; From d3334815f9565c906c3626f57e0bc215ca876f18 Mon Sep 17 00:00:00 2001 From: Luccas Correa Date: Thu, 22 Jan 2026 19:12:58 -0300 Subject: [PATCH 2/7] fix: extract default font and size from docDefaults --- .../pm-adapter/src/converters/paragraph.ts | 44 +++++++--- .../pm-adapter/src/converters/table.ts | 20 ----- .../layout-engine/pm-adapter/src/internal.ts | 86 ++++++++++++------- .../pm-adapter/src/sdt/document-index.ts | 4 - .../src/sdt/document-part-object.ts | 6 -- .../pm-adapter/src/sdt/document-section.ts | 16 ---- .../src/sdt/structured-content-block.ts | 6 -- .../layout-engine/pm-adapter/src/sdt/toc.ts | 8 -- .../layout-engine/pm-adapter/src/types.ts | 4 - .../style-engine/src/ooxml/styles-types.ts | 2 +- 10 files changed, 89 insertions(+), 107 deletions(-) diff --git a/packages/layout-engine/pm-adapter/src/converters/paragraph.ts b/packages/layout-engine/pm-adapter/src/converters/paragraph.ts index 60b403be0..98a2f1a2a 100644 --- a/packages/layout-engine/pm-adapter/src/converters/paragraph.ts +++ b/packages/layout-engine/pm-adapter/src/converters/paragraph.ts @@ -7,7 +7,7 @@ * - Tracked changes processing */ -import type { ParagraphProperties, RunProperties } from '@superdoc/style-engine/ooxml'; +import type { DocDefaults, ParagraphProperties, RunProperties } from '@superdoc/style-engine/ooxml'; import type { FlowBlock, Run, @@ -31,7 +31,7 @@ import { import { textNodeToRun, tabNodeToRun, tokenNodeToRun } from './text-run.js'; import { contentBlockNodeToDrawingBlock } from './content-block.js'; import { DEFAULT_HYPERLINK_CONFIG, TOKEN_INLINE_TYPES } from '../constants.js'; -import { pickNumber, isPlainObject } from '../utilities.js'; +import { pickNumber, isPlainObject, ptToPx } from '../utilities.js'; import { computeRunAttrs } from '../attributes/paragraph.js'; import { resolveRunProperties } from '@superdoc/style-engine/ooxml'; @@ -496,6 +496,34 @@ const applyInlineRunProperties = ( return { ...run, ...runAttrs }; }; +/** + * Extracts the default font family and size from paragraph properties. + * Used for creating default runs in empty paragraphs. + * @param converterContext - Converter context with document styles + * @param paragraphProperties - Resolved paragraph properties + * @returns Object with defaultFont and defaultSize + */ +function extractDefaultFontProperties( + converterContext: ConverterContext, + paragraphProperties: ParagraphProperties, +): { defaultFont: string; defaultSize: number } { + const defaultRunAttrs = computeRunAttrs( + resolveRunProperties( + converterContext, + paragraphProperties.runProperties, + paragraphProperties, + converterContext.tableInfo, + false, + false, + ), + converterContext, + ); + return { + defaultFont: defaultRunAttrs.fontFamily!, + defaultSize: defaultRunAttrs.fontSize!, + }; +} + /** * Converts a paragraph PM node to an array of FlowBlocks. * @@ -509,8 +537,6 @@ const applyInlineRunProperties = ( * @param para - Paragraph PM node to convert * @param nextBlockId - Block ID generator * @param positions - Position map for PM node tracking - * @param defaultFont - Default font family - * @param defaultSize - Default font size * @param trackedChanges - Optional tracked changes configuration * @param bookmarks - Optional bookmark position map * @param hyperlinkConfig - Hyperlink configuration @@ -524,8 +550,6 @@ export function paragraphToFlowBlocks({ para, nextBlockId, positions, - defaultFont, - defaultSize, trackedChangesConfig, bookmarks, hyperlinkConfig = DEFAULT_HYPERLINK_CONFIG, @@ -549,6 +573,7 @@ export function paragraphToFlowBlocks({ : undefined; const hasSectPr = Boolean(rawParagraphProps?.sectPr); const isSectPrMarker = hasSectPr || paraAttrs.pageBreakSource === 'sectPr'; + const { defaultFont, defaultSize } = extractDefaultFontProperties(converterContext, resolvedParagraphProperties); if (paragraphAttrs.pageBreakBefore) { blocks.push({ @@ -934,6 +959,7 @@ export function paragraphToFlowBlocks({ enableComments, ); } + applyInlineRunProperties(tokenRun as TextRun, activeRunProperties, converterContext); console.debug('[token-debug] paragraph-token-run', { token: (tokenRun as TextRun).token, fontFamily: (tokenRun as TextRun).fontFamily, @@ -1100,8 +1126,6 @@ export function paragraphToFlowBlocks({ node, nextBlockId, positions, - defaultFont, - defaultSize, trackedChangesConfig, bookmarks, hyperlinkConfig, @@ -1245,8 +1269,6 @@ export function handleParagraphNode(node: PMNode, context: NodeHandlerContext): recordBlockKind, nextBlockId, positions, - defaultFont, - defaultSize, trackedChangesConfig, bookmarks, hyperlinkConfig, @@ -1279,8 +1301,6 @@ export function handleParagraphNode(node: PMNode, context: NodeHandlerContext): para: node, nextBlockId, positions, - defaultFont, - defaultSize, trackedChangesConfig, bookmarks, hyperlinkConfig, diff --git a/packages/layout-engine/pm-adapter/src/converters/table.ts b/packages/layout-engine/pm-adapter/src/converters/table.ts index c2c371431..2aa3f7ba9 100644 --- a/packages/layout-engine/pm-adapter/src/converters/table.ts +++ b/packages/layout-engine/pm-adapter/src/converters/table.ts @@ -46,8 +46,6 @@ import { TableProperties } from '@superdoc/style-engine/ooxml'; type TableParserDependencies = { nextBlockId: BlockIdGenerator; positions: PositionMap; - defaultFont: string; - defaultSize: number; trackedChangesConfig?: TrackedChangesConfig; bookmarks?: Map; hyperlinkConfig: HyperlinkConfig; @@ -249,8 +247,6 @@ const parseTableCell = (args: ParseTableCellArgs): TableCell | null => { para: childNode, nextBlockId: context.nextBlockId, positions: context.positions, - defaultFont: context.defaultFont, - defaultSize: context.defaultSize, trackedChangesConfig: context.trackedChangesConfig, bookmarks: context.bookmarks, hyperlinkConfig: context.hyperlinkConfig, @@ -272,8 +268,6 @@ const parseTableCell = (args: ParseTableCellArgs): TableCell | null => { para: nestedNode, nextBlockId: context.nextBlockId, positions: context.positions, - defaultFont: context.defaultFont, - defaultSize: context.defaultSize, trackedChangesConfig: context.trackedChangesConfig, bookmarks: context.bookmarks, hyperlinkConfig: context.hyperlinkConfig, @@ -290,8 +284,6 @@ const parseTableCell = (args: ParseTableCellArgs): TableCell | null => { node: nestedNode, nextBlockId: context.nextBlockId, positions: context.positions, - defaultFont: context.defaultFont, - defaultSize: context.defaultSize, trackedChangesConfig: context.trackedChangesConfig, bookmarks: context.bookmarks, hyperlinkConfig: context.hyperlinkConfig, @@ -315,8 +307,6 @@ const parseTableCell = (args: ParseTableCellArgs): TableCell | null => { node: childNode, nextBlockId: context.nextBlockId, positions: context.positions, - defaultFont: context.defaultFont, - defaultSize: context.defaultSize, trackedChangesConfig: context.trackedChangesConfig, bookmarks: context.bookmarks, hyperlinkConfig: context.hyperlinkConfig, @@ -655,8 +645,6 @@ function extractFloatingTableAnchorWrap(node: PMNode): { anchor?: TableAnchor; w * @param node - Table node to convert * @param nextBlockId - Block ID generator * @param positions - Position map for PM node tracking - * @param defaultFont - Default font family - * @param defaultSize - Default font size * @param _styleContext - Style context (unused in current implementation) * @param trackedChanges - Optional tracked changes configuration * @param bookmarks - Optional bookmark position map @@ -668,8 +656,6 @@ export function tableNodeToBlock({ node, nextBlockId, positions, - defaultFont, - defaultSize, trackedChangesConfig, bookmarks, hyperlinkConfig, @@ -685,8 +671,6 @@ export function tableNodeToBlock({ const parserDeps: TableParserDependencies = { nextBlockId, positions, - defaultFont, - defaultSize, trackedChangesConfig, bookmarks, hyperlinkConfig, @@ -874,8 +858,6 @@ export function handleTableNode(node: PMNode, context: NodeHandlerContext): void recordBlockKind, nextBlockId, positions, - defaultFont, - defaultSize, trackedChangesConfig, bookmarks, hyperlinkConfig, @@ -888,8 +870,6 @@ export function handleTableNode(node: PMNode, context: NodeHandlerContext): void node, nextBlockId, positions, - defaultFont, - defaultSize, trackedChangesConfig, bookmarks, hyperlinkConfig, diff --git a/packages/layout-engine/pm-adapter/src/internal.ts b/packages/layout-engine/pm-adapter/src/internal.ts index c9c278fb2..e347e8a46 100644 --- a/packages/layout-engine/pm-adapter/src/internal.ts +++ b/packages/layout-engine/pm-adapter/src/internal.ts @@ -11,18 +11,9 @@ */ import type { FlowBlock, ParagraphBlock } from '@superdoc/contracts'; -import type { StyleContext } from '@superdoc/style-engine'; import { isValidTrackedMode } from './tracked-changes.js'; import { analyzeSectionRanges, createSectionBreakBlock, publishSectionMetadata } from './sections/index.js'; -import { - pxToPt, - pickNumber, - pickDecimalSeparator, - pickLang, - normalizePrefix, - buildPositionMap, - createBlockIdGenerator, -} from './utilities.js'; +import { normalizePrefix, buildPositionMap, createBlockIdGenerator } from './utilities.js'; import { paragraphToFlowBlocks, contentBlockNodeToDrawingBlock, @@ -59,7 +50,6 @@ import type { NestedConverters, ConverterContext, } from './types.js'; -import { defaultDecimalSeparatorFor } from '@superdoc/locale-utils'; const DEFAULT_FONT = 'Arial'; const DEFAULT_SIZE = 16; @@ -131,6 +121,10 @@ export function toFlowBlocks(pmDoc: PMNode | object, options?: AdapterOptions): const doc = pmDoc as PMNode; + if (!doc.content) { + return { blocks: [], bookmarks: new Map() }; + } + const trackedChangesMode = isValidTrackedMode(options?.trackedChangesMode) ? options.trackedChangesMode : 'review'; const enableTrackedChanges = options?.enableTrackedChanges ?? true; const trackedChangesConfig: TrackedChangesConfig = { @@ -141,25 +135,11 @@ export function toFlowBlocks(pmDoc: PMNode | object, options?: AdapterOptions): enableRichHyperlinks: options?.enableRichHyperlinks ?? false, }; const enableComments = options?.enableComments ?? true; - const converterContext: ConverterContext = options?.converterContext ?? { - translatedNumbering: {}, - translatedLinkedStyles: { - docDefaults: { - runProperties: { - fontFamily: { - ascii: defaultFont, - }, - fontSize: pxToPt(defaultSize) ?? 12, - }, - }, - latentStyles: {}, - styles: {}, - }, - }; - - if (!doc.content) { - return { blocks: [], bookmarks: new Map() }; - } + const converterContext: ConverterContext = normalizeConverterContext( + options?.converterContext, + defaultFont, + defaultSize, + ); const blocks: FlowBlock[] = []; const bookmarks = new Map(); @@ -301,3 +281,49 @@ function mergeDropCapParagraphs(blocks: FlowBlock[]): FlowBlock[] { return result; } + +/** + * Normalize and populate the converter context with defaults. + * + * Ensures that essential properties like default font and size + * are set in the converter context for consistent styling. + * + * @param context - Existing converter context (may be undefined) + * @param defaultFont - Default font family to use + * @param defaultSize - Default font size in pixels + * @returns Normalized converter context + */ +function normalizeConverterContext( + context: ConverterContext | undefined, + defaultFont: string, + defaultSize: number, +): ConverterContext { + if (!context) { + context = { + translatedNumbering: {}, + translatedLinkedStyles: { + docDefaults: {}, + latentStyles: {}, + styles: {}, + }, + }; + } + + if (!context.translatedLinkedStyles.docDefaults) { + context.translatedLinkedStyles.docDefaults = {}; + } + if (!context.translatedLinkedStyles.docDefaults.runProperties) { + context.translatedLinkedStyles.docDefaults.runProperties = {}; + } + if (!context.translatedLinkedStyles.docDefaults.runProperties.fontFamily) { + context.translatedLinkedStyles.docDefaults.runProperties.fontFamily = {}; + } + if (!context.translatedLinkedStyles.docDefaults.runProperties.fontFamily.ascii) { + context.translatedLinkedStyles.docDefaults.runProperties.fontFamily.ascii = defaultFont; + } + if (!context.translatedLinkedStyles.docDefaults.runProperties.fontSize) { + context.translatedLinkedStyles.docDefaults.runProperties.fontSize = defaultSize * 2; // size in half-points + } + + return context; +} diff --git a/packages/layout-engine/pm-adapter/src/sdt/document-index.ts b/packages/layout-engine/pm-adapter/src/sdt/document-index.ts index c77b509c2..4f2f6856d 100644 --- a/packages/layout-engine/pm-adapter/src/sdt/document-index.ts +++ b/packages/layout-engine/pm-adapter/src/sdt/document-index.ts @@ -45,8 +45,6 @@ export function handleIndexNode(node: PMNode, context: NodeHandlerContext): void recordBlockKind, nextBlockId, positions, - defaultFont, - defaultSize, trackedChangesConfig, bookmarks, hyperlinkConfig, @@ -81,8 +79,6 @@ export function handleIndexNode(node: PMNode, context: NodeHandlerContext): void para: child, nextBlockId, positions, - defaultFont, - defaultSize, trackedChangesConfig, bookmarks, hyperlinkConfig, diff --git a/packages/layout-engine/pm-adapter/src/sdt/document-part-object.ts b/packages/layout-engine/pm-adapter/src/sdt/document-part-object.ts index 5c3a49bc5..72b495dc1 100644 --- a/packages/layout-engine/pm-adapter/src/sdt/document-part-object.ts +++ b/packages/layout-engine/pm-adapter/src/sdt/document-part-object.ts @@ -25,8 +25,6 @@ export function handleDocumentPartObjectNode(node: PMNode, context: NodeHandlerC recordBlockKind, nextBlockId, positions, - defaultFont, - defaultSize, bookmarks, hyperlinkConfig, converters, @@ -48,8 +46,6 @@ export function handleDocumentPartObjectNode(node: PMNode, context: NodeHandlerC { nextBlockId, positions, - defaultFont, - defaultSize, bookmarks, hyperlinkConfig, enableComments, @@ -67,8 +63,6 @@ export function handleDocumentPartObjectNode(node: PMNode, context: NodeHandlerC para: child, nextBlockId, positions, - defaultFont, - defaultSize, trackedChangesConfig, bookmarks, hyperlinkConfig, diff --git a/packages/layout-engine/pm-adapter/src/sdt/document-section.ts b/packages/layout-engine/pm-adapter/src/sdt/document-section.ts index ca12f1c49..96da5fcd1 100644 --- a/packages/layout-engine/pm-adapter/src/sdt/document-section.ts +++ b/packages/layout-engine/pm-adapter/src/sdt/document-section.ts @@ -33,8 +33,6 @@ import { processTocChildren } from './toc.js'; interface ProcessingContext { nextBlockId: BlockIdGenerator; positions: PositionMap; - defaultFont: string; - defaultSize: number; trackedChangesConfig?: TrackedChangesConfig; bookmarks?: Map; hyperlinkConfig: HyperlinkConfig; @@ -72,8 +70,6 @@ function processParagraphChild( para: child, nextBlockId: context.nextBlockId, positions: context.positions, - defaultFont: context.defaultFont, - defaultSize: context.defaultSize, trackedChangesConfig: undefined, // trackedChanges bookmarks: context.bookmarks, hyperlinkConfig: context.hyperlinkConfig, @@ -112,8 +108,6 @@ function processTableChild( node: child, nextBlockId: context.nextBlockId, positions: context.positions, - defaultFont: context.defaultFont, - defaultSize: context.defaultSize, trackedChangesConfig: context.trackedChangesConfig, bookmarks: context.bookmarks, hyperlinkConfig: context.hyperlinkConfig, @@ -183,8 +177,6 @@ function processNestedStructuredContent( para: grandchild, nextBlockId: context.nextBlockId, positions: context.positions, - defaultFont: context.defaultFont, - defaultSize: context.defaultSize, trackedChangesConfig: context.trackedChangesConfig, bookmarks: context.bookmarks, hyperlinkConfig: context.hyperlinkConfig, @@ -206,8 +198,6 @@ function processNestedStructuredContent( node: grandchild, nextBlockId: context.nextBlockId, positions: context.positions, - defaultFont: context.defaultFont, - defaultSize: context.defaultSize, trackedChangesConfig: context.trackedChangesConfig, bookmarks: context.bookmarks, hyperlinkConfig: context.hyperlinkConfig, @@ -260,8 +250,6 @@ function processDocumentPartObject( { nextBlockId: context.nextBlockId, positions: context.positions, - defaultFont: context.defaultFont, - defaultSize: context.defaultSize, bookmarks: context.bookmarks, hyperlinkConfig: context.hyperlinkConfig, enableComments: context.enableComments, @@ -346,8 +334,6 @@ export function handleDocumentSectionNode(node: PMNode, context: NodeHandlerCont recordBlockKind, nextBlockId, positions, - defaultFont, - defaultSize, bookmarks, hyperlinkConfig, converters, @@ -364,8 +350,6 @@ export function handleDocumentSectionNode(node: PMNode, context: NodeHandlerCont { nextBlockId, positions, - defaultFont, - defaultSize, bookmarks, trackedChangesConfig, hyperlinkConfig, diff --git a/packages/layout-engine/pm-adapter/src/sdt/structured-content-block.ts b/packages/layout-engine/pm-adapter/src/sdt/structured-content-block.ts index 362efdf40..21f365ee1 100644 --- a/packages/layout-engine/pm-adapter/src/sdt/structured-content-block.ts +++ b/packages/layout-engine/pm-adapter/src/sdt/structured-content-block.ts @@ -24,8 +24,6 @@ export function handleStructuredContentBlockNode(node: PMNode, context: NodeHand recordBlockKind, nextBlockId, positions, - defaultFont, - defaultSize, trackedChangesConfig, bookmarks, hyperlinkConfig, @@ -43,8 +41,6 @@ export function handleStructuredContentBlockNode(node: PMNode, context: NodeHand para: child, nextBlockId, positions, - defaultFont, - defaultSize, trackedChangesConfig, bookmarks, hyperlinkConfig, @@ -68,8 +64,6 @@ export function handleStructuredContentBlockNode(node: PMNode, context: NodeHand node: child, nextBlockId, positions, - defaultFont, - defaultSize, trackedChangesConfig, bookmarks, hyperlinkConfig, diff --git a/packages/layout-engine/pm-adapter/src/sdt/toc.ts b/packages/layout-engine/pm-adapter/src/sdt/toc.ts index 3d5566fc5..7b0d3e447 100644 --- a/packages/layout-engine/pm-adapter/src/sdt/toc.ts +++ b/packages/layout-engine/pm-adapter/src/sdt/toc.ts @@ -94,8 +94,6 @@ export function processTocChildren( context: { nextBlockId: BlockIdGenerator; positions: PositionMap; - defaultFont: string; - defaultSize: number; bookmarks?: Map; trackedChangesConfig?: TrackedChangesConfig; hyperlinkConfig: HyperlinkConfig; @@ -120,8 +118,6 @@ export function processTocChildren( para: child, nextBlockId: context.nextBlockId, positions: context.positions, - defaultFont: context.defaultFont, - defaultSize: context.defaultSize, trackedChangesConfig: context.trackedChangesConfig, bookmarks: context.bookmarks, hyperlinkConfig: context.hyperlinkConfig, @@ -174,8 +170,6 @@ export function handleTableOfContentsNode(node: PMNode, context: NodeHandlerCont recordBlockKind, nextBlockId, positions, - defaultFont, - defaultSize, trackedChangesConfig, bookmarks, hyperlinkConfig, @@ -193,8 +187,6 @@ export function handleTableOfContentsNode(node: PMNode, context: NodeHandlerCont para: child, nextBlockId, positions, - defaultFont, - defaultSize, trackedChangesConfig, bookmarks, themeColors, diff --git a/packages/layout-engine/pm-adapter/src/types.ts b/packages/layout-engine/pm-adapter/src/types.ts index cb42358f0..aabc6c3f5 100644 --- a/packages/layout-engine/pm-adapter/src/types.ts +++ b/packages/layout-engine/pm-adapter/src/types.ts @@ -312,8 +312,6 @@ export type ParagraphToFlowBlocksParams = { para: PMNode; nextBlockId: BlockIdGenerator; positions: PositionMap; - defaultFont: string; - defaultSize: number; trackedChangesConfig?: TrackedChangesConfig; hyperlinkConfig: HyperlinkConfig; themeColors?: ThemeColorPalette; @@ -327,8 +325,6 @@ export type TableNodeToBlockParams = { node: PMNode; nextBlockId: BlockIdGenerator; positions: PositionMap; - defaultFont: string; - defaultSize: number; trackedChangesConfig?: TrackedChangesConfig; bookmarks?: Map; hyperlinkConfig: HyperlinkConfig; diff --git a/packages/layout-engine/style-engine/src/ooxml/styles-types.ts b/packages/layout-engine/style-engine/src/ooxml/styles-types.ts index 9224e99d7..d77844e7b 100644 --- a/packages/layout-engine/style-engine/src/ooxml/styles-types.ts +++ b/packages/layout-engine/style-engine/src/ooxml/styles-types.ts @@ -11,7 +11,7 @@ import type { */ export interface StylesDocumentProperties { /** Default run and paragraph properties for the document. */ - docDefaults: DocDefaults | undefined; + docDefaults: DocDefaults; /** Latent style definitions and defaults. */ latentStyles: LatentStyles; /** Styles keyed by styleId. */ From 62b11069ab160a6a3310ba5e8faa01c4cf59da90 Mon Sep 17 00:00:00 2001 From: Luccas Correa Date: Thu, 22 Jan 2026 19:13:23 -0300 Subject: [PATCH 3/7] fix: adjust default font and size to match word --- packages/layout-engine/pm-adapter/src/internal.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/layout-engine/pm-adapter/src/internal.ts b/packages/layout-engine/pm-adapter/src/internal.ts index e347e8a46..f09c61832 100644 --- a/packages/layout-engine/pm-adapter/src/internal.ts +++ b/packages/layout-engine/pm-adapter/src/internal.ts @@ -51,9 +51,8 @@ import type { ConverterContext, } from './types.js'; -const DEFAULT_FONT = 'Arial'; -const DEFAULT_SIZE = 16; -const DEFAULT_DECIMAL_SEPARATOR = '.'; +const DEFAULT_FONT = 'Times New Roman'; +const DEFAULT_SIZE = 10; /** * Dispatch map for node type handlers. From f431157eefc40fd956317d2ade6447d0a5cccaea Mon Sep 17 00:00:00 2001 From: Luccas Correa Date: Fri, 23 Jan 2026 14:56:33 -0300 Subject: [PATCH 4/7] fix: ordering of document defaults and normal style I ran a bunch of tests in Word and the behavior we were implementing was wrong. The properties from the Normal style are always after the document's defaults, regardless of the value of w:default for the Normal style. Also, the properties from the Normal style are only added to the chain if the element does not have a linked style assigned. --- .../style-engine/src/cascade.test.ts | 43 +------------------ .../layout-engine/style-engine/src/cascade.ts | 25 ----------- .../layout-engine/style-engine/src/index.ts | 8 +--- .../style-engine/src/ooxml/index.ts | 25 ++++++----- 4 files changed, 16 insertions(+), 85 deletions(-) diff --git a/packages/layout-engine/style-engine/src/cascade.test.ts b/packages/layout-engine/style-engine/src/cascade.test.ts index 870f93327..b9940714e 100644 --- a/packages/layout-engine/style-engine/src/cascade.test.ts +++ b/packages/layout-engine/style-engine/src/cascade.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest'; -import { combineProperties, combineRunProperties, orderDefaultsAndNormal, combineIndentProperties } from './cascade.js'; +import { combineProperties, combineRunProperties, combineIndentProperties } from './cascade.js'; describe('cascade - combineProperties', () => { it('returns empty object when propertiesArray is empty', () => { @@ -154,47 +154,6 @@ describe('cascade - combineRunProperties', () => { }); }); -describe('cascade - orderDefaultsAndNormal', () => { - const defaultProps = { fontSize: 22, bold: true }; - const normalProps = { fontSize: 20, italic: true }; - - it('returns [defaults, Normal] when isNormalDefault is true', () => { - const [first, second] = orderDefaultsAndNormal(defaultProps, normalProps, true); - expect(first).toBe(defaultProps); - expect(second).toBe(normalProps); - }); - - it('returns [Normal, defaults] when isNormalDefault is false', () => { - const [first, second] = orderDefaultsAndNormal(defaultProps, normalProps, false); - expect(first).toBe(normalProps); - expect(second).toBe(defaultProps); - }); - - it('preserves object references without cloning', () => { - const [first, second] = orderDefaultsAndNormal(defaultProps, normalProps, true); - expect(first).toBe(defaultProps); // Same reference - expect(second).toBe(normalProps); // Same reference - }); - - it('handles empty objects', () => { - const [first, second] = orderDefaultsAndNormal({}, {}, true); - expect(first).toEqual({}); - expect(second).toEqual({}); - }); - - it('affects cascade order when used with combineProperties', () => { - // When Normal is default (true), Normal should override defaults - const [first, second] = orderDefaultsAndNormal(defaultProps, normalProps, true); - const result = combineProperties([first, second]); - expect(result.fontSize).toBe(20); // normalProps wins - - // When Normal is NOT default (false), defaults should override Normal - const [first2, second2] = orderDefaultsAndNormal(defaultProps, normalProps, false); - const result2 = combineProperties([first2, second2]); - expect(result2.fontSize).toBe(22); // defaultProps wins - }); -}); - describe('cascade - combineIndentProperties', () => { it('extracts and combines indent properties from objects', () => { const result = combineIndentProperties([{ indent: { left: 720 } }, { indent: { left: 1440, hanging: 360 } }]); diff --git a/packages/layout-engine/style-engine/src/cascade.ts b/packages/layout-engine/style-engine/src/cascade.ts index 054eb63db..bc4c1fe77 100644 --- a/packages/layout-engine/style-engine/src/cascade.ts +++ b/packages/layout-engine/style-engine/src/cascade.ts @@ -117,31 +117,6 @@ function isObject(item: unknown): item is PropertyObject { // Style Chain Ordering // --------------------------------------------------------------------------- -/** - * Determines the correct ordering for defaults and Normal style in the cascade. - * - * Per OOXML spec, when Normal style is marked as w:default="1", it should - * come AFTER document defaults in the cascade (so Normal values override defaults). - * When Normal is NOT the default style, defaults should come after Normal. - * - * @param defaultProps - Document default properties. - * @param normalProps - Normal style properties. - * @param isNormalDefault - Whether Normal style has w:default="1". - * @returns Ordered array [first, second] for the cascade. - */ -export function orderDefaultsAndNormal( - defaultProps: T, - normalProps: T, - isNormalDefault: boolean, -): [T, T] { - if (isNormalDefault) { - // Normal is default: [defaults, Normal] - Normal wins when both exist - return [defaultProps, normalProps]; - } else { - // Normal is NOT default: [Normal, defaults] - defaults win when both exist - return [normalProps, defaultProps]; - } -} /** * Combines run property objects while fully overriding certain keys. * This is a convenience wrapper for run properties (w:rPr). diff --git a/packages/layout-engine/style-engine/src/index.ts b/packages/layout-engine/style-engine/src/index.ts index 2cd2c462b..7a801ff31 100644 --- a/packages/layout-engine/style-engine/src/index.ts +++ b/packages/layout-engine/style-engine/src/index.ts @@ -11,13 +11,7 @@ */ // Re-export cascade utilities - these are the SINGLE SOURCE OF TRUTH for property merging -export { - combineProperties, - combineRunProperties, - orderDefaultsAndNormal, - combineIndentProperties, - type PropertyObject, -} from './cascade.js'; +export { combineProperties, combineRunProperties, combineIndentProperties, type PropertyObject } from './cascade.js'; import type { TabStop, FieldAnnotationMetadata, diff --git a/packages/layout-engine/style-engine/src/ooxml/index.ts b/packages/layout-engine/style-engine/src/ooxml/index.ts index ea1f78853..16c6c9724 100644 --- a/packages/layout-engine/style-engine/src/ooxml/index.ts +++ b/packages/layout-engine/style-engine/src/ooxml/index.ts @@ -5,18 +5,13 @@ * This module is format-aware (docx), but translator-agnostic. */ -import { - combineIndentProperties, - combineProperties, - combineRunProperties, - orderDefaultsAndNormal, -} from '../cascade.js'; +import { combineIndentProperties, combineProperties, combineRunProperties } from '../cascade.js'; import type { PropertyObject } from '../cascade.js'; import type { ParagraphProperties, RunProperties } from './types.ts'; import type { NumberingProperties } from './numbering-types.ts'; import type { StylesDocumentProperties, TableStyleType, TableProperties, TableLookProperties } from './styles-types.ts'; -export { combineIndentProperties, combineProperties, combineRunProperties, orderDefaultsAndNormal }; +export { combineIndentProperties, combineProperties, combineRunProperties }; export type { PropertyObject }; export type * from './types.ts'; export type * from './numbering-types.ts'; @@ -57,7 +52,6 @@ export function resolveRunProperties( const defaultProps = params.translatedLinkedStyles.docDefaults?.runProperties ?? {}; const normalStyleDef = params.translatedLinkedStyles.styles['Normal']; const normalProps = (normalStyleDef?.runProperties ?? {}) as RunProperties; - const isNormalDefault = normalStyleDef?.default ?? false; // Getting table style run properties const tableStyleProps = ( @@ -81,7 +75,12 @@ export function resolveRunProperties( ) as RunProperties; } - const defaultsChain = orderDefaultsAndNormal(defaultProps, normalProps, isNormalDefault); + let defaultsChain; + if (!paragraphStyleId) { + defaultsChain = [defaultProps, normalProps]; + } else { + defaultsChain = [defaultProps]; + } let styleChain: RunProperties[]; if (isListNumber) { @@ -136,7 +135,6 @@ export function resolveParagraphProperties( const defaultProps = params.translatedLinkedStyles.docDefaults?.paragraphProperties ?? {}; const normalStyleDef = params.translatedLinkedStyles.styles['Normal']; const normalProps = (normalStyleDef?.paragraphProperties ?? {}) as ParagraphProperties; - const isNormalDefault = normalStyleDef?.default ?? false; // Properties from styles let styleId = inlineProps.styleId as string | undefined; @@ -187,7 +185,12 @@ export function resolveParagraphProperties( // Resolve property chain - regular properties are treated differently from indentation // Chain for regular properties - const defaultsChain = orderDefaultsAndNormal(defaultProps, normalProps, isNormalDefault); + let defaultsChain; + if (!styleId) { + defaultsChain = [defaultProps, normalProps]; + } else { + defaultsChain = [defaultProps]; + } const propsChain = [...defaultsChain, tableProps, ...cellStyleProps, numberingProps, styleProps, inlineProps]; // Chain for indentation properties From 5514d2558255acd16024bf5de3e4a17045750588 Mon Sep 17 00:00:00 2001 From: Luccas Correa Date: Fri, 23 Jan 2026 15:45:01 -0300 Subject: [PATCH 5/7] test: fix existing tests --- .../src/converters/paragraph.test.ts | 76 ++++++++++++------- .../pm-adapter/src/converters/table.test.ts | 24 +++++- .../pm-adapter/src/index.test.ts | 14 ++-- .../pm-adapter/src/integration.test.ts | 8 +- .../pm-adapter/src/internal.test.ts | 4 +- .../src/sdt/document-part-object.test.ts | 3 +- .../src/sdt/document-section.test.ts | 9 +-- .../src/sdt/structured-content-block.test.ts | 4 +- .../pm-adapter/src/sdt/toc.test.ts | 3 +- 9 files changed, 87 insertions(+), 58 deletions(-) diff --git a/packages/layout-engine/pm-adapter/src/converters/paragraph.test.ts b/packages/layout-engine/pm-adapter/src/converters/paragraph.test.ts index 1e8574a8a..77e1c294f 100644 --- a/packages/layout-engine/pm-adapter/src/converters/paragraph.test.ts +++ b/packages/layout-engine/pm-adapter/src/converters/paragraph.test.ts @@ -81,6 +81,10 @@ import { } from '../tracked-changes.js'; const DEFAULT_HYPERLINK_CONFIG: HyperlinkConfig = { enableRichHyperlinks: false }; +const DEFAULT_TEST_FONT_FAMILY = 'Arial, sans-serif'; +const DEFAULT_TEST_FONT_SIZE_PX = (16 * 96) / 72; +const FALLBACK_FONT_FAMILY = 'Times New Roman, sans-serif'; +const FALLBACK_FONT_SIZE_PX = 12; let defaultConverterContext: ConverterContext = { translatedNumbering: {}, translatedLinkedStyles: { @@ -124,6 +128,8 @@ const paragraphToFlowBlocks = ( if (isConverters(maybeConverters)) { converters = maybeConverters; + } else if (maybeConverters) { + converterContext = maybeConverters as ConverterContext; } if (isConverters(converterContextOrConverters)) { @@ -132,18 +138,36 @@ const paragraphToFlowBlocks = ( converterContext = converterContextOrConverters as ConverterContext; } + const effectiveConverterContext = + converterContext ?? + ({ + ...defaultConverterContext, + translatedLinkedStyles: { + ...defaultConverterContext.translatedLinkedStyles, + docDefaults: { + ...defaultConverterContext.translatedLinkedStyles.docDefaults, + runProperties: { + ...(defaultConverterContext.translatedLinkedStyles.docDefaults?.runProperties ?? {}), + fontFamily: { + ...(defaultConverterContext.translatedLinkedStyles.docDefaults?.runProperties?.fontFamily ?? {}), + ascii: defaultFont, + }, + fontSize: defaultSize * 2, + }, + }, + }, + } as ConverterContext); + return baseParagraphToFlowBlocks({ para, nextBlockId, positions, - defaultFont, - defaultSize, trackedChangesConfig, bookmarks, hyperlinkConfig: hyperlinkConfig ?? DEFAULT_HYPERLINK_CONFIG, themeColors, converters: converters as NestedConverters, - converterContext: converterContext ?? defaultConverterContext, + converterContext: effectiveConverterContext, enableComments: true, }); }; @@ -839,8 +863,8 @@ describe('paragraph converters', () => { expect(vi.mocked(textNodeToRun)).toHaveBeenCalledWith( textNode, positions, - 'Arial', - 16, + DEFAULT_TEST_FONT_FAMILY, + DEFAULT_TEST_FONT_SIZE_PX, [], undefined, expect.any(Object), @@ -922,8 +946,8 @@ describe('paragraph converters', () => { expect(vi.mocked(textNodeToRun)).toHaveBeenCalledWith( { type: 'text', text: 'Bold text' }, positions, - 'Arial', - 16, + FALLBACK_FONT_FAMILY, + FALLBACK_FONT_SIZE_PX, [], // Empty marks - marks applied separately after linked styles undefined, expect.any(Object), @@ -1010,8 +1034,8 @@ describe('paragraph converters', () => { expect(vi.mocked(textNodeToRun)).toHaveBeenCalledWith( { type: 'text', text: 'Bold italic' }, positions, - 'Arial', - 16, + FALLBACK_FONT_FAMILY, + FALLBACK_FONT_SIZE_PX, [], // Empty marks - marks applied separately after linked styles undefined, { enableRichHyperlinks: false }, @@ -1106,8 +1130,8 @@ describe('paragraph converters', () => { expect(vi.mocked(tokenNodeToRun)).toHaveBeenCalledWith( tokenNode, positions, - 'Arial', - 16, + DEFAULT_TEST_FONT_FAMILY, + DEFAULT_TEST_FONT_SIZE_PX, [], 'pageNumber', expect.any(Object), @@ -1134,8 +1158,8 @@ describe('paragraph converters', () => { expect(vi.mocked(tokenNodeToRun)).toHaveBeenCalledWith( tokenNode, positions, - 'Arial', - 16, + DEFAULT_TEST_FONT_FAMILY, + DEFAULT_TEST_FONT_SIZE_PX, [], 'totalPageCount', expect.any(Object), @@ -1215,8 +1239,8 @@ describe('paragraph converters', () => { expect(vi.mocked(textNodeToRun)).toHaveBeenCalledWith( expect.any(Object), positions, - 'Arial', - 16, + DEFAULT_TEST_FONT_FAMILY, + DEFAULT_TEST_FONT_SIZE_PX, [], sdtMetadata, expect.any(Object), @@ -1471,8 +1495,8 @@ describe('paragraph converters', () => { expect(vi.mocked(textNodeToRun)).toHaveBeenCalledWith( { type: 'text', text: '42' }, positions, - 'Arial', - 16, + FALLBACK_FONT_FAMILY, + FALLBACK_FONT_SIZE_PX, [], undefined, expect.any(Object), @@ -1503,8 +1527,8 @@ describe('paragraph converters', () => { expect(vi.mocked(textNodeToRun)).toHaveBeenCalledWith( { type: 'text', text: '??' }, positions, - 'Arial', - 16, + FALLBACK_FONT_FAMILY, + FALLBACK_FONT_SIZE_PX, [], undefined, expect.any(Object), @@ -1541,8 +1565,8 @@ describe('paragraph converters', () => { expect(vi.mocked(textNodeToRun)).toHaveBeenCalledWith( { type: 'text', text: 'fallback' }, positions, - 'Arial', - 16, + FALLBACK_FONT_FAMILY, + FALLBACK_FONT_SIZE_PX, [], undefined, expect.any(Object), @@ -1581,8 +1605,8 @@ describe('paragraph converters', () => { expect(vi.mocked(textNodeToRun)).toHaveBeenCalledWith( expect.any(Object), positions, - 'Arial', - 16, + FALLBACK_FONT_FAMILY, + FALLBACK_FONT_SIZE_PX, [], // Empty marks - applied separately to honor enableComments undefined, expect.any(Object), @@ -1946,8 +1970,6 @@ describe('paragraph converters', () => { node: tableNode, nextBlockId, positions, - defaultFont: 'Arial', - defaultSize: 16, trackedChangesConfig: trackedChanges, bookmarks, hyperlinkConfig, @@ -2280,8 +2302,8 @@ describe('paragraph converters', () => { expect(vi.mocked(textNodeToRun)).toHaveBeenCalledWith( expect.any(Object), positions, - 'Arial', - 16, + DEFAULT_TEST_FONT_FAMILY, + DEFAULT_TEST_FONT_SIZE_PX, [], undefined, customHyperlinkConfig, diff --git a/packages/layout-engine/pm-adapter/src/converters/table.test.ts b/packages/layout-engine/pm-adapter/src/converters/table.test.ts index 4af56b79a..761b49e29 100644 --- a/packages/layout-engine/pm-adapter/src/converters/table.test.ts +++ b/packages/layout-engine/pm-adapter/src/converters/table.test.ts @@ -41,18 +41,35 @@ const tableNodeToBlock = ( converterContext?: ConverterContext, ) => { const converters = paragraphToFlowBlocks ? ({ paragraphToFlowBlocks } as NestedConverters) : ({} as NestedConverters); + const effectiveConverterContext = + converterContext ?? + ({ + ...DEFAULT_CONVERTER_CONTEXT, + translatedLinkedStyles: { + ...DEFAULT_CONVERTER_CONTEXT.translatedLinkedStyles, + docDefaults: { + ...DEFAULT_CONVERTER_CONTEXT.translatedLinkedStyles.docDefaults, + runProperties: { + ...(DEFAULT_CONVERTER_CONTEXT.translatedLinkedStyles.docDefaults?.runProperties ?? {}), + fontFamily: { + ...(DEFAULT_CONVERTER_CONTEXT.translatedLinkedStyles.docDefaults?.runProperties?.fontFamily ?? {}), + ascii: defaultFont, + }, + fontSize: defaultSize * 2, + }, + }, + }, + } as ConverterContext); return baseTableNodeToBlock({ node, nextBlockId, positions, - defaultFont, - defaultSize, trackedChangesConfig, bookmarks, hyperlinkConfig: hyperlinkConfig ?? DEFAULT_HYPERLINK_CONFIG, themeColors, - converterContext: converterContext ?? DEFAULT_CONVERTER_CONTEXT, + converterContext: effectiveConverterContext, converters, enableComments: true, }); @@ -1049,7 +1066,6 @@ describe('table converter', () => { mockPositionMap, 'Arial', 16, - mockStyleContext, undefined, undefined, undefined, diff --git a/packages/layout-engine/pm-adapter/src/index.test.ts b/packages/layout-engine/pm-adapter/src/index.test.ts index 1b3b6ccf1..73de1e2d7 100644 --- a/packages/layout-engine/pm-adapter/src/index.test.ts +++ b/packages/layout-engine/pm-adapter/src/index.test.ts @@ -9,7 +9,7 @@ import imageFixture from './fixtures/image-inline-and-block.json'; import hummingbirdFixture from './fixtures/hummingbird.json'; import boldDemoFixture from './fixtures/bold-demo.json'; -const DEFAULT_CONVERTER_CONTEXT = { +const createDefaultConverterContext = () => ({ docx: {}, translatedLinkedStyles: { docDefaults: {}, @@ -20,10 +20,10 @@ const DEFAULT_CONVERTER_CONTEXT = { abstracts: {}, definitions: {}, }, -}; +}); const toFlowBlocks = (pmDoc: PMNode | object, options: AdapterOptions = {}) => - baseToFlowBlocks(pmDoc, { converterContext: DEFAULT_CONVERTER_CONTEXT, ...options }); + baseToFlowBlocks(pmDoc, { converterContext: createDefaultConverterContext(), ...options }); const createTestBodySectPr = () => ({ type: 'element', @@ -70,11 +70,11 @@ describe('toFlowBlocks', () => { runs: [ { text: 'Hello world', - fontFamily: 'Arial', - fontSize: 16, + fontFamily: 'Times New Roman, sans-serif', }, ], }); + expect(blocks[0].runs[0]?.fontSize).toBeCloseTo((10 * 96) / 72, 5); }); it('generates unique BlockIds based on position', () => { @@ -114,9 +114,9 @@ describe('toFlowBlocks', () => { }); expect(blocks[0].runs[0]).toMatchObject({ - fontFamily: 'Times New Roman', - fontSize: 14, + fontFamily: 'Times New Roman, sans-serif', }); + expect(blocks[0].runs[0]?.fontSize).toBeCloseTo((14 * 96) / 72, 5); }); }); diff --git a/packages/layout-engine/pm-adapter/src/integration.test.ts b/packages/layout-engine/pm-adapter/src/integration.test.ts index 112219c6f..4fd038ca3 100644 --- a/packages/layout-engine/pm-adapter/src/integration.test.ts +++ b/packages/layout-engine/pm-adapter/src/integration.test.ts @@ -258,13 +258,13 @@ describe('PM → FlowBlock → Measure integration', () => { // Typography metrics should be reasonable for 20px font size // Note: Exact values depend on font rendering (canvas vs fallback), so we check ranges - expect(measure.lines[0].ascent).toBeGreaterThan(14); // ~70-90% of font size + expect(measure.lines[0].ascent).toBeGreaterThan(10); // ~50-80% of font size expect(measure.lines[0].ascent).toBeLessThan(20); expect(measure.lines[0].descent).toBeGreaterThan(2); // ~10-25% of font size expect(measure.lines[0].descent).toBeLessThan(6); - // Line height should be at least the font size - expect(measure.lines[0].lineHeight).toBeGreaterThanOrEqual(20); - expect(measure.totalHeight).toBeGreaterThanOrEqual(20); + // Line height should be within a reasonable range for the resolved font size + expect(measure.lines[0].lineHeight).toBeGreaterThanOrEqual(14); + expect(measure.totalHeight).toBeGreaterThanOrEqual(14); }); it('propagates tab stops and decimal separators through measurement', async () => { diff --git a/packages/layout-engine/pm-adapter/src/internal.test.ts b/packages/layout-engine/pm-adapter/src/internal.test.ts index ea932b5c2..9792107fb 100644 --- a/packages/layout-engine/pm-adapter/src/internal.test.ts +++ b/packages/layout-engine/pm-adapter/src/internal.test.ts @@ -284,8 +284,8 @@ describe('internal', () => { expect(handleParagraphNode).toHaveBeenCalledWith( expect.any(Object), expect.objectContaining({ - defaultFont: 'Arial', - defaultSize: 16, + defaultFont: 'Times New Roman', + defaultSize: 10, }), ); }); diff --git a/packages/layout-engine/pm-adapter/src/sdt/document-part-object.test.ts b/packages/layout-engine/pm-adapter/src/sdt/document-part-object.test.ts index 8f0d79f7f..767398b0f 100644 --- a/packages/layout-engine/pm-adapter/src/sdt/document-part-object.test.ts +++ b/packages/layout-engine/pm-adapter/src/sdt/document-part-object.test.ts @@ -352,13 +352,12 @@ describe('document-part-object', () => { expect.objectContaining({ nextBlockId: mockBlockIdGenerator, positions: mockPositionMap, - defaultFont: 'Arial', - defaultSize: 12, bookmarks: mockContext.bookmarks, hyperlinkConfig: mockHyperlinkConfig, converters: mockContext.converters, converterContext: mockConverterContext, enableComments: mockEnableComments, + trackedChangesConfig: undefined, }), ); }); diff --git a/packages/layout-engine/pm-adapter/src/sdt/document-section.test.ts b/packages/layout-engine/pm-adapter/src/sdt/document-section.test.ts index 12da5dfc7..688374c6f 100644 --- a/packages/layout-engine/pm-adapter/src/sdt/document-section.test.ts +++ b/packages/layout-engine/pm-adapter/src/sdt/document-section.test.ts @@ -264,8 +264,6 @@ describe('document-section', () => { para: children[0], nextBlockId: mockBlockIdGenerator, positions: mockPositionMap, - defaultFont: 'Arial', - defaultSize: 12, hyperlinkConfig: mockHyperlinkConfig, }), ); @@ -453,8 +451,6 @@ describe('document-section', () => { node: children[0], nextBlockId: mockBlockIdGenerator, positions: mockPositionMap, - defaultFont: 'Arial', - defaultSize: 12, hyperlinkConfig: mockHyperlinkConfig, }), ); @@ -1207,9 +1203,8 @@ describe('document-section', () => { expect.objectContaining({ nextBlockId: mockBlockIdGenerator, positions: mockPositionMap, - defaultFont: 'Arial', - defaultSize: 12, converters: expect.any(Object), + hyperlinkConfig: mockHyperlinkConfig, }), { blocks, recordBlockKind }, ); @@ -1435,8 +1430,6 @@ describe('document-section', () => { para: children[0], nextBlockId: mockBlockIdGenerator, positions: mockPositionMap, - defaultFont: 'Arial', - defaultSize: 12, bookmarks: mockBookmarks, hyperlinkConfig: mockHyperlinkConfig, }), diff --git a/packages/layout-engine/pm-adapter/src/sdt/structured-content-block.test.ts b/packages/layout-engine/pm-adapter/src/sdt/structured-content-block.test.ts index 80a5466d6..eba3677ab 100644 --- a/packages/layout-engine/pm-adapter/src/sdt/structured-content-block.test.ts +++ b/packages/layout-engine/pm-adapter/src/sdt/structured-content-block.test.ts @@ -307,13 +307,13 @@ describe('structured-content-block', () => { para: node.content[0], nextBlockId: mockBlockIdGenerator, positions: mockPositionMap, - defaultFont: 'Arial', - defaultSize: 12, trackedChangesConfig: mockTrackedChangesConfig, bookmarks: mockBookmarks, hyperlinkConfig: mockHyperlinkConfig, enableComments: mockEnableComments, converterContext: mockConverterContext, + converters: { paragraphToFlowBlocks: mockParagraphConverter }, + themeColors: undefined, }), ); }); diff --git a/packages/layout-engine/pm-adapter/src/sdt/toc.test.ts b/packages/layout-engine/pm-adapter/src/sdt/toc.test.ts index c2ec9257c..86a6e2a70 100644 --- a/packages/layout-engine/pm-adapter/src/sdt/toc.test.ts +++ b/packages/layout-engine/pm-adapter/src/sdt/toc.test.ts @@ -470,13 +470,12 @@ describe('toc', () => { para: children[0], nextBlockId: mockBlockIdGenerator, positions: mockPositionMap, - defaultFont: 'Calibri', - defaultSize: 14, trackedChangesConfig: mockTrackedChanges, bookmarks: mockBookmarks, hyperlinkConfig: mockHyperlinkConfig, enableComments: false, converterContext: mockConverterContext, + converters: { paragraphToFlowBlocks: mockParagraphConverter }, }), ); }); From aaed6b64de0cfe9ec388f23a896eb04abc8e4b29 Mon Sep 17 00:00:00 2001 From: Luccas Correa Date: Fri, 23 Jan 2026 16:01:30 -0300 Subject: [PATCH 6/7] chore: remove unused imports --- packages/layout-engine/pm-adapter/src/converters/paragraph.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/layout-engine/pm-adapter/src/converters/paragraph.ts b/packages/layout-engine/pm-adapter/src/converters/paragraph.ts index 98a2f1a2a..4a1e6e088 100644 --- a/packages/layout-engine/pm-adapter/src/converters/paragraph.ts +++ b/packages/layout-engine/pm-adapter/src/converters/paragraph.ts @@ -7,7 +7,7 @@ * - Tracked changes processing */ -import type { DocDefaults, ParagraphProperties, RunProperties } from '@superdoc/style-engine/ooxml'; +import type { ParagraphProperties, RunProperties } from '@superdoc/style-engine/ooxml'; import type { FlowBlock, Run, @@ -31,7 +31,7 @@ import { import { textNodeToRun, tabNodeToRun, tokenNodeToRun } from './text-run.js'; import { contentBlockNodeToDrawingBlock } from './content-block.js'; import { DEFAULT_HYPERLINK_CONFIG, TOKEN_INLINE_TYPES } from '../constants.js'; -import { pickNumber, isPlainObject, ptToPx } from '../utilities.js'; +import { pickNumber, isPlainObject } from '../utilities.js'; import { computeRunAttrs } from '../attributes/paragraph.js'; import { resolveRunProperties } from '@superdoc/style-engine/ooxml'; From 83a515984a538b14fdebae82918e1190503dc2ba Mon Sep 17 00:00:00 2001 From: Luccas Correa Date: Fri, 23 Jan 2026 16:22:24 -0300 Subject: [PATCH 7/7] fix: interpret default font size as pixels instead of points --- packages/layout-engine/pm-adapter/src/index.test.ts | 2 +- packages/layout-engine/pm-adapter/src/internal.test.ts | 2 +- packages/layout-engine/pm-adapter/src/internal.ts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/layout-engine/pm-adapter/src/index.test.ts b/packages/layout-engine/pm-adapter/src/index.test.ts index 73de1e2d7..26e1e8a4d 100644 --- a/packages/layout-engine/pm-adapter/src/index.test.ts +++ b/packages/layout-engine/pm-adapter/src/index.test.ts @@ -116,7 +116,7 @@ describe('toFlowBlocks', () => { expect(blocks[0].runs[0]).toMatchObject({ fontFamily: 'Times New Roman, sans-serif', }); - expect(blocks[0].runs[0]?.fontSize).toBeCloseTo((14 * 96) / 72, 5); + expect(blocks[0].runs[0]?.fontSize).toBeCloseTo(14, 5); }); }); diff --git a/packages/layout-engine/pm-adapter/src/internal.test.ts b/packages/layout-engine/pm-adapter/src/internal.test.ts index 9792107fb..27e9ed570 100644 --- a/packages/layout-engine/pm-adapter/src/internal.test.ts +++ b/packages/layout-engine/pm-adapter/src/internal.test.ts @@ -285,7 +285,7 @@ describe('internal', () => { expect.any(Object), expect.objectContaining({ defaultFont: 'Times New Roman', - defaultSize: 10, + defaultSize: 10 / 0.75, }), ); }); diff --git a/packages/layout-engine/pm-adapter/src/internal.ts b/packages/layout-engine/pm-adapter/src/internal.ts index f09c61832..09a86e199 100644 --- a/packages/layout-engine/pm-adapter/src/internal.ts +++ b/packages/layout-engine/pm-adapter/src/internal.ts @@ -52,7 +52,7 @@ import type { } from './types.js'; const DEFAULT_FONT = 'Times New Roman'; -const DEFAULT_SIZE = 10; +const DEFAULT_SIZE = 10 / 0.75; // 10pt in pixels /** * Dispatch map for node type handlers. @@ -321,7 +321,7 @@ function normalizeConverterContext( context.translatedLinkedStyles.docDefaults.runProperties.fontFamily.ascii = defaultFont; } if (!context.translatedLinkedStyles.docDefaults.runProperties.fontSize) { - context.translatedLinkedStyles.docDefaults.runProperties.fontSize = defaultSize * 2; // size in half-points + context.translatedLinkedStyles.docDefaults.runProperties.fontSize = defaultSize * 0.75 * 2; // size in half-points } return context;