- MCP over HTTP: `genoffice mcp --http` serves the tool set as a Streamable HTTP server for clients on other machines, with file upload, URL inputs and result files handed back; MCP agents can also read PDF text, edit the open document and drive the visible Sheets grid - Docs: picture-heavy documents open lazily with media served from disk (gigabyte files in seconds), files over 512 MB are refused with a message instead of a crash, long documents open and type faster, and many Word-fidelity fixes for tables (autofit width, split rows, header-row keep, page-edge borders), anchored pictures and text boxes, header/footer spacing, chart labels and EMF+ clipping, Japanese font substitution, italic and bidi runs - Markdown: saving keeps unchanged blocks byte-for-byte and re-serializes edited blocks in the document's own conventions (plus an opt-in unchanged-source round trip); ```wavedrom fences render as timing diagrams - Sheets: smooth scrolling, duplicate and large-range copy on big streamed workbooks; context-menu submenus reopen reliably; AI bulk-job economy rules - App: Help → Check for Updates and an About-dialog button; the in-editor Files pane and floating Files / Outline edge tabs are removed from all editors; AI panel can dock on either side - AI providers: DeepSeek V4.1 Flash, gpt-6-astra and Opper added, retired ids dropped, clearer error when a tool call's arguments are too large - PPTX: chart categories honor the 1904 date system, slide text extracts in presentation order, single-quoted attributes and case-insensitive preset colors parse; backports of public PRs #432–#461 Co-authored-by: GenOffice <merrick-2002@users.noreply.github.com>
140 lines
5.4 KiB
TypeScript
140 lines
5.4 KiB
TypeScript
/** Rendering of legacy text effects, glow, w:w compression, distribute and the Hyperlink style. */
|
|
import { Editor } from '@tiptap/core'
|
|
import { DOMSerializer } from '@tiptap/pm/model'
|
|
import { parseDocx } from '@genoffice/docx-engine'
|
|
import type { ParsedDocFull, StyleDisplay, StyleInfo } from '@genoffice/docx-engine'
|
|
import { describe, expect, it } from 'vitest'
|
|
import { buildDocx } from '../../../packages/docx-engine/tests/helpers/build-docx'
|
|
import { docStyleCss } from '../src/renderer/doc-style-css'
|
|
import { blocksToPmDoc } from '../src/renderer/editor/convert'
|
|
import { editorExtensions } from '../src/renderer/editor/extensions'
|
|
import { renderFieldSpec } from '../src/renderer/editor/protected-render'
|
|
import {
|
|
charScaleXDecls,
|
|
glowDecl,
|
|
textAlignDecl,
|
|
textEffectDecls,
|
|
} from '../src/renderer/editor/text-effects'
|
|
|
|
;(globalThis as { CSS?: unknown }).CSS ??= { escape: (s: string) => s }
|
|
|
|
function parsedWith(
|
|
styleId: string,
|
|
type: StyleInfo['type'],
|
|
display: StyleDisplay,
|
|
): ParsedDocFull {
|
|
const styles = new Map<string, StyleInfo>()
|
|
styles.set(styleId, { styleId, name: styleId, type, display } as StyleInfo)
|
|
return { styles, docDefaults: {}, blocks: [] } as unknown as ParsedDocFull
|
|
}
|
|
|
|
async function renderSpans(bodyXml: string): Promise<HTMLElement[]> {
|
|
const parsed = await parseDocx(await buildDocx({ bodyXml }))
|
|
const editor = new Editor({
|
|
element: document.createElement('div'),
|
|
extensions: editorExtensions,
|
|
content: blocksToPmDoc(parsed.blocks) as never,
|
|
})
|
|
const spans = [...editor.view.dom.querySelectorAll('p span')] as HTMLElement[]
|
|
editor.destroy()
|
|
return spans
|
|
}
|
|
|
|
describe('text effect declarations', () => {
|
|
it('hollows outline glyphs and paints engraved glyphs in the paper colour', () => {
|
|
expect(textEffectDecls('outline')).toEqual([
|
|
'-webkit-text-stroke:0.5px currentColor',
|
|
'-webkit-text-fill-color:transparent',
|
|
])
|
|
expect(textEffectDecls('imprint')[0]).toBe('color:var(--docs-paper)')
|
|
expect(textEffectDecls('imprint')[1]).toContain('text-shadow:-1px -1px')
|
|
expect(textEffectDecls('emboss')[1]).toContain('text-shadow:1px 1px')
|
|
})
|
|
|
|
it('maps glow to a blurred shadow with alpha', () => {
|
|
expect(glowDecl({ color: 'FF0000', radiusPt: 8, alpha: 0.6 })).toBe(
|
|
'text-shadow:0 0 4pt rgba(255,0,0,0.6),0 0 8pt rgba(255,0,0,0.6)',
|
|
)
|
|
})
|
|
|
|
it('compresses a whitespace-free run and gives the saved width back', () => {
|
|
expect(charScaleXDecls('{"s":0.33,"gapEm":-0.348}')).toEqual([
|
|
'display:inline-block',
|
|
'transform:scaleX(0.33)',
|
|
'transform-origin:0 50%',
|
|
'margin-right:-0.348em',
|
|
'text-indent:0',
|
|
])
|
|
expect(charScaleXDecls('nope')).toEqual([])
|
|
})
|
|
|
|
it('spreads every line of a distributed paragraph', () => {
|
|
expect(textAlignDecl('distribute')).toBe(
|
|
'text-align:justify;text-align-last:justify;text-justify:distribute',
|
|
)
|
|
expect(textAlignDecl('right')).toBe('text-align:right')
|
|
})
|
|
})
|
|
|
|
describe('editor run rendering', () => {
|
|
it('engraved white text stays visible through its shadow', async () => {
|
|
const spans = await renderSpans(
|
|
'<w:p><w:r><w:rPr><w:imprint/><w:color w:val="FFFFFF"/></w:rPr><w:t>engraved</w:t></w:r></w:p>',
|
|
)
|
|
const span = spans.find((s) => s.textContent === 'engraved')!
|
|
expect(span.style.color).toBe('var(--docs-paper)')
|
|
expect(span.style.textShadow).toBe('-1px -1px 0 var(--docs-paper-ink-mid)')
|
|
expect(span.getAttribute('style')).not.toContain('--dk-c')
|
|
})
|
|
|
|
it('scales a single glyph with w:w instead of letter-spacing it', async () => {
|
|
const spans = await renderSpans(
|
|
'<w:p><w:r><w:rPr><w:w w:val="33"/></w:rPr><w:t>x</w:t></w:r>' +
|
|
'<w:r><w:rPr><w:w w:val="50"/></w:rPr><w:t xml:space="preserve">two words</w:t></w:r></w:p>',
|
|
)
|
|
const single = spans.find((s) => s.textContent === 'x')!
|
|
expect(single.style.transform).toBe('scaleX(0.33)')
|
|
expect(single.style.marginRight).toBe('-0.348em')
|
|
expect(single.style.letterSpacing).toBe('')
|
|
const spaced = spans.find((s) => s.textContent === 'two words')!
|
|
expect(spaced.style.letterSpacing).not.toBe('')
|
|
expect(spaced.style.transform).toBe('')
|
|
})
|
|
|
|
it('lowers a run by its w:position', async () => {
|
|
const spans = await renderSpans(
|
|
'<w:p><w:r><w:rPr><w:position w:val="-8"/></w:rPr><w:t>low</w:t></w:r></w:p>',
|
|
)
|
|
expect(spans.find((s) => s.textContent === 'low')!.style.verticalAlign).toBe('-4pt')
|
|
})
|
|
})
|
|
|
|
describe('Hyperlink style rendering', () => {
|
|
it('lets a defined Hyperlink style beat the default link look', () => {
|
|
const css = docStyleCss(
|
|
parsedWith('Hyperlink', 'character', { color: '008000', underline: false }),
|
|
)
|
|
expect(css).toContain('[data-style="Hyperlink"] { color:#008000 }')
|
|
expect(css).toContain(
|
|
'.doc-link:has([data-style="Hyperlink"]) { color:inherit;text-decoration:none }',
|
|
)
|
|
expect(docStyleCss(parsedWith('Body', 'paragraph', { align: 'distribute' }))).toContain(
|
|
'text-align-last:justify',
|
|
)
|
|
expect(docStyleCss(parsedWith('Body', 'paragraph', {}))).not.toContain('.doc-link:has')
|
|
})
|
|
|
|
it('carries the entry run style onto the TOC title', () => {
|
|
const dom = DOMSerializer.renderSpec(
|
|
document,
|
|
renderFieldSpec({
|
|
kind: 'tocLine',
|
|
left: 'H1',
|
|
right: '1',
|
|
runStyleId: 'Hyperlink',
|
|
}) as never,
|
|
).dom as HTMLElement
|
|
expect(dom.querySelector('.doc-toc-title')?.getAttribute('data-style')).toBe('Hyperlink')
|
|
})
|
|
})
|