Files
genoffice/apps/docs/tests/doc-style-css-indent.test.ts
T
merrick-2002andGenOffice 69b4ce0560 Sync snapshot (2026-09-06) (#243)
- Docs: Word-style dark page, phased fast open for long documents, fonts embedded in the DOCX, spellcheck toggle, hyperlink editing, and ~80 Word fidelity fixes (CJK/JP metrics, header/footer, tables, anchored pictures)
- Sheets: hold formula recalculation while file data streams in, large-workbook scroll/load performance, combo charts, duplicate/unique conditional formatting by display text, RTL frozen-pane fix, workbooks whose ZIP entries carry a leading slash
- Slides: MTX-compressed embedded font support, CJK/Latin face selection and PowerPoint script fallbacks, theme colors kept on paragraph defaults and bullets, more reliable AI edits with a layout audit after each batch
- PDF: AI page ops, text block move/align, notes and markup editing, watermark and header/footer, form check boxes, metadata; the cloud Export as Word fallback is removed, conversion is always on-device
- AI: Gemini tool schema translation, OpenCode Zen/Go providers, markdown tables and code blocks in chat, current date in the system prompt
- Shell: Office-style ribbon collapse across all editors, native Windows ARM64 installer, BUILD_DIR override for packaging

Co-authored-by: GenOffice <merrick-2002@users.noreply.github.com>
2026-09-07 00:18:14 +08:00

46 lines
2.1 KiB
TypeScript

/**
* Style-level first-line indent must not reach list items: .doc-li expresses
* hanging via the ::before marker box (--li-hang chain), so a style text-indent
* would double-shift the first line and inherit into the marker box, dragging
* its glyphs out of the hanging area (prod-sas 037: "1." clipped to "l.").
*/
import { describe, expect, it } from 'vitest'
import type { ParsedDocFull, StyleDisplay, StyleInfo } from '@genoffice/docx-engine'
import { docStyleCss } from '../src/renderer/doc-style-css'
;(globalThis as { CSS?: unknown }).CSS ??= { escape: (s: string) => s }
function parsedWith(styleId: string, display: StyleDisplay): ParsedDocFull {
const styles = new Map<string, StyleInfo>()
styles.set(styleId, { styleId, name: styleId, type: 'paragraph', display } as StyleInfo)
return { styles, docDefaults: {}, blocks: [] } as unknown as ParsedDocFull
}
describe('docStyleCss first-line indent', () => {
it('emits style hanging as text-indent for non-list paragraphs and --style-li-hang for list items', () => {
const css = docStyleCss(
parsedWith('ListParagraph', { indentLeftTwips: 493, indentFirstLineTwips: -185 }),
)
expect(css).toContain(
'.doc-page [data-style="ListParagraph"]:not(.doc-li, .doc-li-stray) { text-indent:-9.3pt }',
)
expect(css).toContain(
'.doc-page :is(.doc-li, .doc-li-stray)[data-style="ListParagraph"] { --style-li-hang:9.3pt }',
)
// the shared style rule must not carry text-indent (it would hit .doc-li too)
expect(css).not.toMatch(/\[data-style="ListParagraph"\] \{[^}]*text-indent/)
// left indent keeps feeding the --li-left fallback chain
expect(css).toContain(
'.doc-page :is(.doc-li, .doc-li-stray)[data-style="ListParagraph"] { --style-li-left:24.6pt }',
)
})
it('keeps a positive first-line indent off list items without a hang fallback', () => {
const css = docStyleCss(parsedWith('Body', { indentFirstLineTwips: 400 }))
expect(css).toContain(
'.doc-page [data-style="Body"]:not(.doc-li, .doc-li-stray) { text-indent:20.0pt }',
)
expect(css).not.toContain('--style-li-hang')
})
})