Sync snapshot (2026-08-19) (#110)

- Improve Docs pagination, anchored-object fidelity, password protection, recovery safety, and multilingual font fallback
- Scale Sheets editing and saves for large workbooks with safer AI bulk operations, aggregation, undo, recovery, and richer visual fidelity
- Expand Slides fidelity with 3D rendering, SmartArt and WordArt improvements, pattern and texture fills, and resource cleanup
- Add AI PDF creation, text insertion, reading-position restore, safer atomic saves, and improved comments and page workflows
- Add Markdown math rendering and protect linked assets across save, conversion, and document lifecycle operations
- Read legacy DOC and PPT attachments locally and strengthen document package resource cleanup
- Document default-on usage analytics with a persistent Settings opt-out and a dedicated, tested privacy page

Co-authored-by: GenOffice <merrick-2002@users.noreply.github.com>
This commit is contained in:
merrick-2002
2026-08-19 20:14:50 +08:00
committed by GitHub
co-authored by GenOffice
parent 04a994b9e9
commit fe2e17403c
372 changed files with 40308 additions and 4357 deletions
+5 -2
View File
@@ -4,7 +4,7 @@
"license": "Apache-2.0",
"private": true,
"type": "module",
"description": "shared attachment parsing: pdf/docx/pptx/xlsx and plain-text formats to text; images flagged for multimodal input",
"description": "shared attachment parsing: PDF, Office and plain-text formats to text; images flagged for multimodal input",
"exports": {
".": "./src/index.ts"
},
@@ -15,9 +15,12 @@
},
"dependencies": {
"@genoffice/docx-engine": "*",
"cfb": "^1.2.2",
"fast-xml-parser": "^5.3.4",
"jszip": "^3.10.1",
"pdfjs-dist": "^6.2.108"
"pdfjs-dist": "^6.2.108",
"ppt-to-text": "^1.0.1",
"word-extractor": "^1.0.4"
},
"devDependencies": {
"@types/node": "^24.10.1",
+17
View File
@@ -0,0 +1,17 @@
import WordExtractor from 'word-extractor'
import './vendor'
function normalizeText(text: string): string {
return text.replace(/\r\n?/g, '\n').trim()
}
/** Extract readable body and text-box content from a legacy Word 97-2003 file. */
export async function docToText(bytes: Uint8Array): Promise<string> {
const document = await new WordExtractor().extract(Buffer.from(bytes))
const body = document.getBody({ filterUnicode: false })
const textboxes = document.getTextboxes({
filterUnicode: false,
includeHeadersAndFooters: false,
})
return normalizeText([body, textboxes].filter((part) => part.trim()).join('\n'))
}
+2
View File
@@ -1,5 +1,7 @@
export { parseFileToText, type ParsedFile, type ParsedFileKind } from './parse'
export { docToText } from './doc'
export { docxToText } from './docx'
export { pptToText } from './ppt'
export { pptxToText } from './pptx'
export { xlsxToText } from './xlsx'
export { pdfToText } from './pdf'
+7
View File
@@ -1,7 +1,9 @@
import { readFile } from 'node:fs/promises'
import { extname } from 'node:path'
import { docToText } from './doc'
import { docxToText } from './docx'
import { pdfToText } from './pdf'
import { pptToText } from './ppt'
import { pptxToText } from './pptx'
import { xlsxToText } from './xlsx'
@@ -35,6 +37,7 @@ const TEXT_EXTS = new Set([
'html',
'htm',
'log',
'py',
])
/** parse an attachment into plain text (or flag it as image / unsupported) */
@@ -47,8 +50,12 @@ export async function parseFileToText(filePath: string): Promise<ParsedFile> {
return { ok: true, kind: 'text', text: await readFile(filePath, 'utf-8') }
}
switch (ext) {
case 'doc':
return { ok: true, kind: 'text', text: await docToText(await readFile(filePath)) }
case 'docx':
return { ok: true, kind: 'text', text: await docxToText(await readFile(filePath)) }
case 'ppt':
return { ok: true, kind: 'text', text: await pptToText(await readFile(filePath)) }
case 'pptx':
return { ok: true, kind: 'text', text: await pptxToText(await readFile(filePath)) }
case 'xlsx':
+41
View File
@@ -0,0 +1,41 @@
import * as CFB from 'cfb'
import './vendor'
type LegacyPptGlobals = typeof globalThis & {
CFB?: typeof CFB
cptable?: {
utils: {
decode(codepage: number, bytes: Uint8Array): string
}
}
}
// ppt-to-text hides these dependencies behind concatenated CommonJS requires,
// which Rollup cannot bundle. Provide them before loading the parser lazily.
const legacyGlobals = globalThis as LegacyPptGlobals
legacyGlobals.CFB ??= CFB
legacyGlobals.cptable ??= {
utils: {
decode(codepage, bytes) {
if (codepage !== 1200) throw new Error(`Unsupported legacy PPT codepage: ${codepage}`)
return Buffer.from(bytes).toString('utf16le')
},
},
}
function normalizeText(text: string): string {
return text.replace(/\r\n?/g, '\n').trim()
}
/** Extract one readable text section per slide from a legacy PowerPoint 97-2003 file. */
export async function pptToText(bytes: Uint8Array): Promise<string> {
const pptParser = (await import('ppt-to-text')).default
const presentation = pptParser.readBuffer(Buffer.from(bytes))
const slides = pptParser.utils.to_text(presentation)
return slides
.map((text, index) => {
const content = normalizeText(text)
return content ? `## Slide ${index + 1}\n${content}` : `## Slide ${index + 1}`
})
.join('\n\n')
}
+36
View File
@@ -0,0 +1,36 @@
declare module 'word-extractor' {
interface WordExtractOptions {
filterUnicode?: boolean
}
interface WordTextboxOptions extends WordExtractOptions {
includeHeadersAndFooters?: boolean
includeBody?: boolean
}
export interface ExtractedWordDocument {
getBody(options?: WordExtractOptions): string
getTextboxes(options?: WordTextboxOptions): string
}
export default class WordExtractor {
extract(source: string | Buffer): Promise<ExtractedWordDocument>
}
}
declare module 'ppt-to-text' {
interface ParsedPresentation {
readonly slides?: readonly unknown[]
readonly docs?: readonly unknown[]
}
interface PptToText {
readBuffer(buffer: Buffer, options?: Record<string, unknown>): ParsedPresentation
utils: {
to_text(presentation: ParsedPresentation): string[]
}
}
const pptToText: PptToText
export default pptToText
}
Binary file not shown.
Binary file not shown.
@@ -1,3 +1,4 @@
import { fileURLToPath } from 'node:url'
import { describe, expect, it } from 'vitest'
import { parseFileToText } from '../src/index'
import {
@@ -7,6 +8,21 @@ import {
writeFixture,
} from './helpers/fixtures'
function legacyFixture(name: string): string {
return fileURLToPath(new URL(`fixtures/${name}`, import.meta.url))
}
describe('parseFileToText: doc', () => {
it('extracts body text from a Word 97-2003 document', async () => {
const result = await parseFileToText(legacyFixture('legacy-sample.doc'))
expect(result.ok).toBe(true)
expect(result.kind).toBe('text')
expect(result.text).toContain('Legacy Report')
expect(result.text).toContain('Legacy DOC body text')
expect(result.text).toContain('Second paragraph from Word 97-2003.')
})
})
describe('parseFileToText: docx', () => {
it('extracts headings, paragraphs and tables', async () => {
const path = writeFixture('report.docx', await buildDocxFixture())
@@ -20,6 +36,19 @@ describe('parseFileToText: docx', () => {
})
})
describe('parseFileToText: ppt', () => {
it('extracts one text section per slide from a PowerPoint 97-2003 presentation', async () => {
const result = await parseFileToText(legacyFixture('legacy-sample.ppt'))
expect(result.ok).toBe(true)
expect(result.kind).toBe('text')
expect(result.text).toContain('## Slide 1')
expect(result.text).toContain('Legacy PPT title')
expect(result.text).toContain('First slide body')
expect(result.text).toContain('## Slide 2')
expect(result.text).toContain('Second legacy slide')
})
})
describe('parseFileToText: pptx', () => {
it('extracts one section per slide in numeric order', async () => {
const path = writeFixture('deck.pptx', await buildPptxFixture())
@@ -11,6 +11,7 @@ describe('parseFileToText: plain-text formats', () => {
['sample.json', '{"key":"value"}'],
['sample.xml', '<root><item>value</item></root>'],
['sample.html', '<html><body><p>page</p></body></html>'],
['sample.py', 'def hello():\n return "world"'],
]
for (const [name, content] of cases) {