Files
genoffice/apps/docs/tests/paragraph-strut-size.test.ts
T
merrick-2002andGenOffice e249c3ba81 Sync snapshot (2026-08-09) (#75)
- PDF: in-place text editing — paragraph block selection with reflow, bold/italic and alignment controls, selection-level text color, original-font preservation
- PDF: AI image tools (search/generate, insert, transform, delete) plus image rotation and in-place replacement
- Docs: picture rotation and mirror flips, in-place image byte swap for crop/background removal, and several Word-fidelity rendering fixes
- Docs: fix a renderer hang on tab-heavy forms and a crash when exporting large documents
- Slides: AI picture tools (crop, opacity, replace), picture border controls, in-place picture source swap
- Linux: AppImage and deb packaging with stable/beta auto-update channels
- Refresh the README and clean up internal design-audit artifacts

Co-authored-by: GenOffice <merrick-2002@users.noreply.github.com>
2026-08-10 01:43:24 +08:00

72 lines
2.3 KiB
TypeScript

/**
* Word's line strut follows run sizes: a paragraph whose runs all declare an
* explicit size must carry that size (max of runs) on the block element, or the
* inherited body size inflates every line box (table cells often run smaller
* than Normal). Any run inheriting the body size keeps the inherited strut.
*/
import { Editor } from '@tiptap/core'
import { describe, expect, it } from 'vitest'
import { editorExtensions } from '../src/renderer/editor/extensions'
const sized = (text: string, sizeHalfPoints: number) => ({
type: 'text',
text,
marks: [{ type: 'docTextStyle', attrs: { sizeHalfPoints } }],
})
const editorWith = (content: unknown[]): Editor =>
new Editor({
element: document.createElement('div'),
extensions: editorExtensions,
content: { type: 'doc', content } as never,
})
// jsdom's CSSOM drops the min() font-size, so assert the --doc-strut custom
// property it references (font-size:min(var(--doc-strut), 1em) rides along)
const pFontSize = (editor: Editor, index = 0): string => {
const p = editor.view.dom.querySelectorAll('p')[index] as HTMLElement
return p.style.getPropertyValue('--doc-strut')
}
describe('paragraph strut font-size from run sizes', () => {
it('all runs explicit: the paragraph carries the max run size', () => {
const editor = editorWith([
{ type: 'docParagraph', content: [sized('small ', 17), sized('big', 20)] },
])
expect(pFontSize(editor)).toBe('10pt')
editor.destroy()
})
it('a run inheriting the body size suppresses the strut override', () => {
const editor = editorWith([
{ type: 'docParagraph', content: [sized('sized ', 17), { type: 'text', text: 'plain' }] },
])
expect(pFontSize(editor)).toBe('')
editor.destroy()
})
it('a docTextStyle mark without sizeHalfPoints counts as inherited', () => {
const editor = editorWith([
{
type: 'docParagraph',
content: [
sized('sized ', 17),
{
type: 'text',
text: 'red',
marks: [{ type: 'docTextStyle', attrs: { color: 'FF0000' } }],
},
],
},
])
expect(pFontSize(editor)).toBe('')
editor.destroy()
})
it('an empty paragraph emits no font-size', () => {
const editor = editorWith([{ type: 'docParagraph' }])
expect(pFontSize(editor)).toBe('')
editor.destroy()
})
})