Files
genoffice/packages/html2docx/src/browser/visual-effects.js
T
merrick-2002andGenOffice d24c964a3e Sync snapshot (2026-09-09) (#271)
- **New app: GenOffice HTML.** Open, edit and generate .html pages: a source pane with a sandboxed live preview, click-to-select elements with a floating toolbar and style panel, device-size preview, image tools and a present mode. AI generates whole pages from a brief with style directions and offers page-wide Restyle, Theme and Summarize. Export to Word runs locally through the built-in html2docx converter (native, editable OOXML; no print-to-PDF detour).
- **AI:** separate BYOK providers for web search, image generation and image/video analysis; new Codex App Server provider; Ask AI quotes the selected text and keeps it highlighted while it runs; custom AI panel text size; blocked requests retry through the Chromium network stack.
- **App:** global AutoSave setting shared by every editor; AI panel text size and chat spellcheck toggles (genoffice#249); Czech (cs) UI locale (genoffice#259); Save As defaults to the document's folder; PDF export no longer aborts on CJK file paths on Windows.
- **Docs:** Export as HTML; comments and replies edit in place from the comments pane; the caret can leave a trailing table (genoffice#266); spellcheck re-marks text as soon as it is re-enabled; AI edits are character-precise on partial selections; zoom keeps the scroll position; pasting a cell from Sheets takes the destination font.
- **Sheets:** Find no longer freezes on wide or streamed grids; Replace searches as you type; cached values of external-workbook formulas are kept instead of #ERROR! (genoffice#235); "number stored as text" is a warning, not an error (genoffice#236); paste repeats into the target range like Excel; filter criteria survive save/reopen; saves retry when Windows locks the file; many Excel-fidelity fixes for column widths, row heights, charts, slicers, number formats and CJK fonts.
- **Slides:** PDF export works for large presentations (genoffice#264); EMF/WMF picture fonts and East Asian theme fonts resolve correctly; decks with missing layouts or embedded styles still open; outline-only pie slices render.
- **PDF:** highlight and underline geometry aligns with the text; Shift+arrows extend the selection instead of paging.
- **Markdown:** Find and replace (Ctrl+F / Ctrl+H) (genoffice#253); mermaid code blocks render as diagrams (genoffice#263); better print quality.
- Thanks to community contributors @GoodScholar, @aniruddhaadak80 and @Sun8854, and to @hanyscz, @qgzln, @zyp997, @bisslot, @krakotay and @Ben03151 for the reports.

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

52 lines
2.6 KiB
JavaScript

(function installVisualEffectClassifier(global) {
function needsScreenshot(el, deps) {
const { bgHex, cs, fullBorderOf } = deps;
// A broken image's rendered box is Chrome's placeholder chrome (icon +
// clipped alt text), never the author's design — even when transformed
// or shadowed, let the IMG branch fall back to alt text instead.
if (el.tagName === 'IMG' && (!el.complete || el.naturalWidth === 0)) return false;
const style = cs(el);
const rect = el.getBoundingClientRect();
if (rect.width < 20 || rect.height < 12 || rect.width > 1000 || rect.height > 1000) {
return false;
}
const transformed = style.transform && style.transform !== 'none';
const shadowed = style.boxShadow && style.boxShadow !== 'none';
const filtered =
(style.filter && style.filter !== 'none') ||
(style.backdropFilter && style.backdropFilter !== 'none');
const radii = [
style.borderTopLeftRadius,
style.borderTopRightRadius,
style.borderBottomRightRadius,
style.borderBottomLeftRadius,
].map((value) => parseFloat(value) || 0);
const complexRadius =
Math.max(...radii) >= 8 &&
(Boolean(bgHex(el)) || Boolean(fullBorderOf(el))) &&
(new Set(radii.map((radius) => Math.round(radius))).size > 1 ||
style.overflow === 'hidden' ||
Math.max(...radii) >= Math.min(rect.width, rect.height) * 0.25);
// Text-heavy cards must stay editable/searchable: soft shadows, filters
// and rounded corners are not worth rasterizing paragraphs of content.
// Transforms still rasterize (flowed text would land in the wrong place).
// CJK counts double: a 60-char Japanese question carries as much content
// as a 120-char English sentence.
const text = (el.innerText || '').trim();
const cjkCount = (text.match(/[\u3000-\u9fff\uf900-\ufaff\uff66-\uff9f]/g) || []).length;
const weightedTextLength = text.length + cjkCount;
// Many short lines (schedule cards, subject lists) are as content-heavy
// as long prose \u2014 a 5-day timetable trapped in pixels is uneditable.
const lineCount = text ? text.split('\n').filter((line) => line.trim()).length : 0;
const textHeavy = weightedTextLength > 80 || (lineCount >= 4 && text.length >= 30);
const compactRoundedCard =
complexRadius && rect.height <= 160 && weightedTextLength <= 200 && lineCount < 4;
return Boolean(
transformed ||
((shadowed || filtered || complexRadius) && (!textHeavy || compactRoundedCard)),
);
}
global.__html2docxVisualEffects = { needsScreenshot };
})(globalThis);