Sync snapshot (2026-08-10) (#80)

- Improve DOCX rendering fidelity, pagination, image handling, and Markdown paste
- Expand PDF text editing with paragraph reflow, style preservation, and more reliable text matching
- Harden XLSX sheet deletion, localized date formats, multi-row autofit, charts, and system font support
- Add inline AI turn rollback and sent-attachment visibility across editors
- Add Office-style ScreenTips and refine ribbons, dialogs, menus, and themes
- Improve Slides cropping, rotate and flip tools, printing, animations, and editing workflows
- Add shell settings, configurable save locations, account credits, and update recovery guidance
- Add Intel macOS and RPM download support and refresh public documentation

Co-authored-by: GenOffice <merrick-2002@users.noreply.github.com>
This commit is contained in:
merrick-2002
2026-08-10 23:17:11 +08:00
committed by GitHub
co-authored by GenOffice
parent fd33934dab
commit 7023e635bd
168 changed files with 9855 additions and 2799 deletions
+2 -1
View File
@@ -17,7 +17,8 @@
},
"dependencies": {
"fast-xml-parser": "^5.3.4",
"jszip": "^3.10.1"
"jszip": "^3.10.1",
"utif2": "^4.1.0"
},
"devDependencies": {
"@types/node": "^24.10.1",
+119
View File
@@ -32,6 +32,7 @@ const CHART_KINDS: Record<string, ChartDisplay['kind']> = {
*/
export function parseChartPartXml(xml: string, partPath: string): ChartDisplay | null {
const parsed = xmlParser.parse(xml) as XNode[]
if (xml.includes('<cx:chartSpace')) return parseChartexPartXml(parsed, partPath)
const space = parsed.find((n) => nameOf(n) === 'c:chartSpace')
const chart = space ? findChild(space, 'c:chart') : undefined
const plotArea = chart ? findChild(chart, 'c:plotArea') : undefined
@@ -56,6 +57,11 @@ export function parseChartPartXml(xml: string, partPath: string): ChartDisplay |
const cat = findChild(ser, 'c:cat')
if (cat && categories.length === 0) {
categories = cachePoints(cat).map((v) => v ?? '')
// date-formatted numeric caches hold Excel serials; display them as dates
const fmt = catFormatCode(cat)
if (fmt && /[yd]/i.test(fmt)) {
categories = categories.map((v) => serialDateText(v) ?? v)
}
}
const name = seriesName(ser)
series.push({ ...(name !== undefined ? { name } : {}), values })
@@ -72,6 +78,119 @@ export function parseChartPartXml(xml: string, partPath: string): ChartDisplay |
}
}
/** cx layoutId → closest classic display kind (degrade: shapes differ, data/labels/title survive) */
const CHARTEX_KINDS: Record<string, ChartDisplay['kind']> = {
clusteredColumn: 'bar',
boxWhisker: 'bar',
waterfall: 'bar',
funnel: 'bar',
paretoLine: 'line',
sunburst: 'pie',
treemap: 'pie',
}
/**
* Chartex (cx: 2014 chart extension: sunburst/treemap/boxWhisker/waterfall…)
* degrade: read cx:chartData dimensions + series names + title into the
* classic ChartDisplay model so the existing chart pipeline renders the data
* with the nearest classic shape (title and cached texts/numbers survive).
*/
function parseChartexPartXml(parsed: XNode[], partPath: string): ChartDisplay | null {
const space = parsed.find((n) => nameOf(n) === 'cx:chartSpace')
if (!space) return null
const chartData = findChild(space, 'cx:chartData')
// data id → {cats, vals}: strDim/numDim carry cx:lvl point caches (the first
// strDim level holds the leaf labels of hierarchical charts)
const dataById = new Map<string, { cats: string[]; vals: (number | null)[] }>()
for (const data of chartData ? findChildren(chartData, 'cx:data') : []) {
const id = attrsOf(data)['id'] ?? ''
const entry: { cats: string[]; vals: (number | null)[] } = { cats: [], vals: [] }
const ptsOf = (dim: XNode): (string | null)[] => {
const lvl = findChild(dim, 'cx:lvl')
if (!lvl) return []
const out: (string | null)[] = []
for (const pt of findChildren(lvl, 'cx:pt')) {
const idx = parseInt(attrsOf(pt)['idx'] ?? '', 10)
if (Number.isFinite(idx) && idx >= 0) out[idx] = textOf(pt)
}
return out
}
for (const dim of childrenOf(data)) {
const dimName = nameOf(dim)
if (dimName === 'cx:strDim') {
entry.cats = ptsOf(dim).map((v) => v ?? '')
} else if (dimName === 'cx:numDim') {
entry.vals = ptsOf(dim).map((v) => {
if (v === null || v.trim() === '') return null
const n = Number(v)
return Number.isFinite(n) ? n : null
})
}
}
dataById.set(id, entry)
}
const chart = findChild(space, 'cx:chart')
const plotRegion = chart
? findChild(findChild(chart, 'cx:plotArea') ?? {}, 'cx:plotAreaRegion')
: undefined
let kind: ChartDisplay['kind'] = 'other'
let categories: string[] = []
const series: ChartSeries[] = []
for (const ser of plotRegion ? findChildren(plotRegion, 'cx:series') : []) {
const layout = attrsOf(ser)['layoutId'] ?? ''
if (kind === 'other' && CHARTEX_KINDS[layout]) kind = CHARTEX_KINDS[layout]
const dataId = attrsOf(findChild(ser, 'cx:dataId') ?? {})['val'] ?? ''
const data = dataById.get(dataId)
if (!data || data.vals.length === 0) continue
if (categories.length === 0) categories = data.cats
const name = textOf(
findChild(findChild(findChild(ser, 'cx:tx') ?? {}, 'cx:txData') ?? {}, 'cx:v') ?? {},
)
series.push({ ...(name ? { name } : {}), values: data.vals })
}
if (series.length === 0) return null
// cx:title holds a full a:t rich body like classic charts
const title = chart ? chartexTitle(chart) : undefined
return {
partPath,
kind,
...(title !== undefined ? { title } : {}),
categories,
series,
}
}
function chartexTitle(chart: XNode): string | undefined {
const title = findChild(chart, 'cx:title')
if (!title) return undefined
const texts: string[] = []
const walk = (node: XNode) => {
for (const child of childrenOf(node)) {
if (nameOf(child) === 'a:t') texts.push(textOf(child))
else walk(child)
}
}
walk(title)
const joined = texts.join('')
return joined !== '' ? joined : undefined
}
/** c:formatCode of a category cache (numCache/numLit), if any */
function catFormatCode(container: XNode): string | undefined {
const ref = findChild(container, 'c:numRef')
const cache = ref ? findChild(ref, 'c:numCache') : findChild(container, 'c:numLit')
const code = cache ? findChild(cache, 'c:formatCode') : undefined
return code ? textOf(code) : undefined
}
/** Excel date serial → "m/d/yyyy" display (Word/LO render category dates, not serials) */
function serialDateText(v: string | null): string | null {
const n = Number(v)
if (!Number.isFinite(n) || n <= 0 || n > 80000) return null
const d = new Date(Date.UTC(1899, 11, 30) + Math.round(n) * 86400000)
return `${d.getUTCMonth() + 1}/${d.getUTCDate()}/${d.getUTCFullYear()}`
}
/** cached point texts of a c:cat / c:val / c:tx container, in idx order */
function cachePoints(container: XNode): (string | null)[] {
const ref = findChild(container, 'c:strRef') ?? findChild(container, 'c:numRef')
File diff suppressed because it is too large Load Diff
+63
View File
@@ -0,0 +1,63 @@
/**
* TIFF → PNG transcoding. Chromium cannot decode image/tiff, so pictures
* embedded as word/media/*.tif(f) would render as blank frames. Decode with
* UTIF (pure JS) and re-encode as PNG via canvas for display; the original
* TIFF bytes stay untouched in the package so saving preserves them.
*/
import UTIF from 'utif2'
const TIFF_MIMES = new Set(['image/tiff', 'image/tif', 'image/x-tiff'])
export function isTiffMime(mime: string | undefined): mime is string {
return mime !== undefined && TIFF_MIMES.has(mime)
}
// the engine compiles without DOM libs (it also runs under node); the canvas
// re-encode is reached only in renderer environments, typed structurally here
interface CanvasLike {
width: number
height: number
getContext(id: '2d'): { putImageData(data: unknown, x: number, y: number): void } | null
toDataURL(type: string): string
}
interface DomGlobals {
document?: { createElement(tag: 'canvas'): CanvasLike }
ImageData?: new (data: Uint8ClampedArray, w: number, h: number) => unknown
}
/**
* Render TIFF bytes to a PNG data URL. Returns null on parse failure or when
* no canvas API exists (non-renderer environments), so callers keep their
* existing empty-frame degrade.
*/
export function tiffToDataUrl(bytes: ArrayBuffer | Uint8Array): string | null {
const dom = globalThis as DomGlobals
if (!dom.document || !dom.ImageData) return null
try {
// copy into a fresh ArrayBuffer (a Uint8Array view may sit on a
// SharedArrayBuffer, which UTIF's signature rejects)
const buf = bytes instanceof Uint8Array ? new Uint8Array(bytes).buffer : bytes
const ifds = UTIF.decode(buf)
if (!ifds.length) return null
// multi-page/multi-resolution TIFFs: pick the largest page
let page = ifds[0]
for (const ifd of ifds) {
UTIF.decodeImage(buf, ifd)
if ((ifd.width || 0) * (ifd.height || 0) > (page.width || 0) * (page.height || 0)) page = ifd
}
const width = page.width
const height = page.height
if (!width || !height) return null
const rgba = UTIF.toRGBA8(page)
const canvas = dom.document.createElement('canvas')
canvas.width = width
canvas.height = height
const ctx2d = canvas.getContext('2d')
if (!ctx2d) return null
const pixels = new Uint8ClampedArray(rgba.buffer, rgba.byteOffset, width * height * 4)
ctx2d.putImageData(new dom.ImageData(pixels, width, height), 0, 0)
return canvas.toDataURL('image/png')
} catch {
return null
}
}
+80 -1
View File
@@ -29,6 +29,9 @@ export interface Run {
sizeHalfPoints?: number
/** primary font family (w:rFonts, eastAsia ?? ascii ?? hAnsi) */
font?: string
/** `font` is a backfill for an empty EA theme slot (<a:ea typeface=""/>), not a document choice
* (display keeps the Word-look face; line metrics follow the theme's Latin face like LO) */
eaSlotEmpty?: boolean
/** Latin-slot font (w:rFonts ascii/hAnsi) when the run declares one; may equal `font`.
* Kept separate so editing one script's font never flattens the other slot. */
fontAscii?: string
@@ -216,6 +219,8 @@ export interface ParaFormat {
keepLines?: boolean
/** widow/orphan control (w:widowControl; Word default=true) */
widowControl?: boolean
/** snap lines to the section docGrid (w:snapToGrid; default on) — false only when explicitly off */
snapToGrid?: boolean
/** CJK-Latin/digit auto spacing (w:autoSpaceDE/DN; Word default=true); false when both are explicitly off */
autoSpace?: boolean
/** ignore space-after when followed by same-style para (w:contextualSpacing) */
@@ -366,8 +371,16 @@ export interface HfImage {
dataUrl: string
widthPx?: number
heightPx?: number
/** wp:anchor floating (otherwise inline) */
/** wp:anchor floating / VML position:absolute (otherwise inline) */
floating?: boolean
/** behind body text (negative VML z-index): picture watermarks */
behind?: boolean
/** VML mso-position-horizontal (margin/page relative) */
posH?: 'left' | 'center' | 'right'
/** VML mso-position-vertical (margin/page relative) */
posV?: 'top' | 'center' | 'bottom'
/** v:imagedata gain/blacklevel present (Word watermark washout preset) */
washout?: boolean
}
/** Parsed content of one header/footer part (any w:type variant). */
@@ -455,6 +468,43 @@ export interface ChartDisplay {
heightPx?: number
}
/** One SmartArt shape from the precomputed diagram drawing part (dsp:sp), in px */
export interface DiagramShape {
xPx: number
yPx: number
wPx: number
hPx: number
/** a:prstGeom preset (roundRect/ellipse/...); rendering approximates by radius */
prst?: string
/** solid fill (hex without '#') */
fillHex?: string
/** picture fill (a:blipFill) */
imageDataUrl?: string
/** a:stretch/a:fillRect fractions of the picture fill (negative = bleed) */
fillRect?: { l: number; t: number; r: number; b: number }
/** paragraph texts of the shape's txBody */
texts?: string[]
fontSizePt?: number
textColorHex?: string
/** rotation in degrees (a:xfrm rot / 60000) */
rotDeg?: number
}
/** SmartArt display-only degrade from diagrams/drawingN.xml (Word's resolved layout) */
export interface DiagramDisplay {
widthPx: number
heightPx: number
shapes: DiagramShape[]
/** anchored-drawing offset of the diagram's own wp:anchor (EMU) */
offsetXEmu?: number
offsetYEmu?: number
/** wrapNone/behind/front anchor (or sharing a paragraph with other drawings): leaves the flow like Word */
floating?: boolean
/** drawing-canvas display (lockedCanvas): text renders at its raw font size
* and overflows the scaled child geometry instead of clipping (LO behavior) */
canvas?: boolean
}
/** A new chart to embed at save time (becomes word/charts/chartN.xml + relationship). */
export interface NewChart {
kind: 'bar' | 'line' | 'pie'
@@ -690,6 +740,10 @@ export interface Block {
/** display size from wp:extent in CSS px (type === 'image') */
imageWidthPx?: number
imageHeightPx?: number
/** source crop (a:srcRect) as fractions of the source picture (display-only) */
imageCrop?: { l: number; t: number; r: number; b: number }
/** fill placement (a:stretch/a:fillRect) as fractions of the shape box; negative = bleed (display-only) */
imageFillRect?: { l: number; t: number; r: number; b: number }
/** paragraph alignment of the image (w:jc) */
imageAlign?: 'left' | 'center' | 'right'
/** text wrapping of a floating image (wp:anchor); absent = inline (in line with text) */
@@ -736,6 +790,8 @@ export interface Block {
formulaDisplay?: FormulaDisplay
/** display/edit model of an embedded chart (set on chart-labeled blocks) */
chartDisplay?: ChartDisplay
/** display-only SmartArt degrade from the precomputed diagram drawing part */
diagramDisplay?: DiagramDisplay
/**
* When this block was wrapped in a w:sdt (structured document tag), the
* original sdtPr + shell bytes are stored here for save-time re-wrapping.
@@ -817,6 +873,25 @@ export interface TextboxDisplay {
*/
readOnly?: boolean
paras: TextboxParaDisplay[]
/** this box's own wp:anchor offset (EMU); with `floating`, the box positions
* absolutely at the offset from the paragraph's flow origin */
offsetXEmu?: number
offsetYEmu?: number
/** wrapNone/behind/front anchors — or any anchored shape sharing its
* paragraph with other drawings — leave the flow like Word (absolute
* position, no flow height) instead of stacking as blocks */
floating?: boolean
/** rotation in degrees clockwise (a:xfrm rot / 60000) */
rotDeg?: number
/** border width in CSS px (a:ln w) */
borderWidthPx?: number
/** dashed/dotted border (a:prstDash) */
borderDash?: 'dashed' | 'dotted'
/** picture fill (a:blipFill in the shape properties, or a pic:pic photo
* sharing a multi-drawing paragraph), as a data URL */
fillImageDataUrl?: string
/** tile the picture fill (a:tile) instead of stretching it */
fillTile?: boolean
}
/** Final body content decided by the editor at save time. */
@@ -868,6 +943,8 @@ export interface StyleDisplay {
font?: string
/** latin-slot font when it differs from the east-asian one (w:ascii/w:hAnsi) */
fontAscii?: string
/** the EA face is a backfill for an empty theme slot (<a:ea typeface=""/>), not a document choice */
eaSlotEmpty?: boolean
/** complex-script font (w:rFonts cs/cstheme) */
csFont?: string
/** character spacing (rPr w:spacing, twips, may be negative) */
@@ -955,6 +1032,8 @@ export interface DocDefaults {
asciiFont?: string
/** default Chinese font (rPrDefault w:rFonts w:eastAsia) — determines the CJK line-height factor */
eastAsiaFont?: string
/** eastAsiaFont is a lang-based backfill for an empty theme slot, not a document choice */
eaSlotEmpty?: boolean
/** bold/italic/color from rPrDefault (display-layer defaults, used by canvas CSS) */
bold?: boolean
italic?: boolean