Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![CI](https://github.com/p10node/office-engine/actions/workflows/ci.yml/badge.svg)](https://github.com/p10node/office-engine/actions/workflows/ci.yml)
[![License: MIT](https://img.shields.io/npm/l/@p10node/office-engine)](LICENSE)

View + edit **DOCX / XLSX / PPTX** directly in the browser, open and edit **DOC / XLS / PPT** (Office 97-2003), **RTF** and **OpenDocument** (ODT / ODS / ODP), view Apple **Pages**, **Keynote** and **Numbers** files, Microsoft **Visio** drawings and **PDF** files (with your pdf.js), open **CSV**, text, Markdown, HTML and SVG as editable sheets / documents and source code with syntax colors, and draw **Mermaid**, **PlantUML** and **Graphviz** diagrams (no server, no extra library). Loads progressively like Google Docs, handles heavy files, one-line React embed, saves back to the original format.
View + edit **DOCX / XLSX / PPTX** directly in the browser, open and edit **DOC / XLS / PPT** (Office 97-2003), **RTF** and **OpenDocument** (ODT / ODS / ODP), view Apple **Pages**, **Keynote** and **Numbers** files, Microsoft **Visio** drawings, **e-mail** messages (`.eml`, Outlook `.msg`) and **PDF** files (with your pdf.js), open **CSV**, text, Markdown, HTML and SVG as editable sheets / documents and source code with syntax colors, and draw **Mermaid**, **PlantUML** and **Graphviz** diagrams (no server, no extra library). Loads progressively like Google Docs, handles heavy files, one-line React embed, saves back to the original format.

**Zero runtime dependencies, zero servers.** Parsing, layout, formulas, diagrams and ZIP are all in the library, running in a Web Worker: nothing leaves the browser.

Expand Down Expand Up @@ -73,12 +73,13 @@ Also online at [p10node.github.io/office-engine](https://p10node.github.io/offic
- **Apple Pages, Keynote and Numbers (view only)**: `.pages` / `.key` / `.numbers` files open read-only, converted to Word / PowerPoint / Excel in the worker (styles, lists, tables, images, shapes, header/footer, footnotes, master slides, typed and formatted cells); *Download as* Word / PowerPoint / Excel saves the converted file
- **Microsoft Visio (view only)**: `.vsdx` drawings (also `.vsdm`, templates and stencils) open read-only, a slide per page: shapes with their geometry (lines, arcs, ellipses, Béziers, NURBS), masters, groups, connectors with line ends, fills, gradients, themes, text, pictures, background pages and layers; *Download as* PowerPoint saves the converted file
- **PDF (view only)**: `.pdf` files are shown as they are, drawn by [pdf.js](https://mozilla.github.io/pdf.js/) that the host passes in (`pdfjs`: optional, the library still ships no dependency): the text over each page is selected with the mouse, copied and found; links are followed, bookmarks are the outline, pages zoom and only those near the view are drawn; the bytes are read as pdf.js asks, so a large file served with ranges is not downloaded whole first. *Download as* gives the file itself and its text; Print prints the file ([API](docs/api.md#pdf-files))
- **E-mail messages (view only)**: `.eml` (also Apple Mail's `.emlx`) and Outlook `.msg` / `.oft` files open read-only as a document: subject, sender, recipients, date, the HTML (tables, the pictures the message carries), rich-text (Outlook's compressed RTF) or plain-text body, attached messages; attachments are listed and saved from the File menu. Pictures from the web are never fetched
- **CSV, text, Markdown, HTML, SVG**: `.csv` / `.tsv` open as a workbook (streamed: a million rows in about 2 s; past 12 million cells the rows are read from the file as they are shown, so there is no row limit), `.txt` / `.md` / `.html` as a document, `.svg` / `.svgz` as a picture (`.gz` files are unpacked first), from any `src` (file, Blob, URL); format from the extension, MIME type or content; UTF-8 / UTF-16 / Windows-1252; editable. Markdown, HTML and SVG are saved back in their own format (CSV and text as `.xlsx` / `.docx`)
- **Diagrams as code**: `.mmd` (Mermaid), `.puml` (PlantUML), `.dot` / `.gv` (Graphviz) open as a document with the drawing; ` ```mermaid ` / ` ```plantuml ` / ` ```dot ` blocks in Markdown and `<pre class="mermaid">` in HTML are drawn too. Drawn by a built-in layout engine in the worker: no server, no network, no dependency
- **Math in Markdown**: `$…$` and `$$…$$` TeX formulas are drawn as equations (the browser's own MathML: selectable, read by screen readers, printed); the document stays editable around them and saves each formula back exactly as it was written. Currency (`$5 and $10`), `\$` and code are left alone; a formula that cannot be read shows its source. *Download as* Word gives real Word equations
- **Code side by side**: Markdown, HTML, SVG and diagram files show their source next to the document (**Code** button); edit it and the document is rebuilt as you type; edit the document and the Markdown / HTML is built again from it
- **Syntax highlighting**: Markdown code blocks are colored by their fence's language (JavaScript / TypeScript / JSX, JSON, Python, CSS, HTML / XML, YAML, shell, SQL, Go, Rust, Java, C / C++ / C#, and more), stay editable, and are saved back with their language and exact code; the colors are only drawn, never stored. Source files (`main.ts`, `script.py`, `config.json`…, or any text with the `language` prop) open in a **code view** with line numbers, in light and dark, editable and saved as plain text. One built-in tokenizer, no dependency ([Features](docs/features.md#syntax-highlighting))
- **File menu**: new, open (also DOC / XLS / PPT / RTF / OpenDocument / Pages / Keynote / Numbers / Visio / PDF / CSV / text / Markdown / HTML / SVG / diagrams / source code), import CSV, rename, download as PDF / HTML / text / CSV, document details, print
- **File menu**: new, open (also DOC / XLS / PPT / RTF / OpenDocument / Pages / Keynote / Numbers / Visio / e-mail / PDF / CSV / text / Markdown / HTML / SVG / diagrams / source code), import CSV, rename, download as PDF / HTML / text / CSV, document details, print
- **Comments**: threads with replies, resolve, edit / delete, @mentions; on DOCX text, XLSX cells and PPTX slides, stored in the file the way Word, Excel and PowerPoint store them
- **Real-time collaboration**: live edits, avatars, collaborators' cursors, offline edits sync on reconnect
- **Fonts**: hand the viewer font files (the OFL fallbacks Carlito, Caladea, Liberation, or the originals) and documents are laid out once they are loaded, so lines and pages break as with the fonts the document names ([API](docs/api.md#fonts))
Expand Down
12 changes: 8 additions & 4 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ CSS is auto-injected, no import needed (or import `@p10node/office-engine/styles

| Prop | Type | Default | Notes |
|--------------------|--------------------------------------------------------------|-----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `src` | `File \| Blob \| ArrayBuffer \| Uint8Array \| string \| URL` | – | Office (also 97-2003); OpenDocument; RTF; Pages/Keynote/Numbers; Visio; CSV/TSV, text, code, Markdown, HTML, diagrams; PDF (with `pdfjs`) |
| `src` | `File \| Blob \| ArrayBuffer \| Uint8Array \| string \| URL` | – | Office (also 97-2003); OpenDocument; RTF; Pages/Keynote/Numbers; Visio; e-mail; CSV/TSV, text, code, Markdown, HTML, diagrams; PDF (with `pdfjs`) |
| `name` | `string` | auto | Display name; its extension also tells the format of a `Blob` / `ArrayBuffer` |
| `language` | `string` | – | Source code in this language (`'typescript'`, `'ts'`, `'python'`, `'c++'`…): the code view, whatever the name says |
| `toolbar` | `boolean` | `true` | Top bar (name, status, progress) |
Expand All @@ -71,7 +71,7 @@ CSS is auto-injected, no import needed (or import `@p10node/office-engine/styles
| `theme` | `'light' \| 'dark' \| 'auto' \| ThemeOptions` | `'light'` | Color scheme of the chrome; `'auto'` follows `prefers-color-scheme`; an object adds token overrides ([Theming](theming.md)). Documents keep their own colors |
| `locale` | `string` | inherited | BCP 47 tag for number/date display and numeric input. See [UI texts](#ui-texts) and [input](#numbers-typed-in-a-locale) |
| `strings` | `StringsOverride` | – | Texts merged over the enclosing provider or English, key by key; may include a formatting `locale` |
| `editable` | `boolean` | `false` | Open in edit mode (Pages, Keynote, Numbers and Visio files stay view only) |
| `editable` | `boolean` | `false` | Open in edit mode (Pages, Keynote, Numbers, Visio files and e-mail stay view only) |
| `allowEdit` | `boolean` | `true` | Show Edit/View button |
| `allowSave` | `boolean` | `true` | Show Save/Download button, enable Ctrl+S |
| `allowDownload` | `boolean` | `true` | Allow downloads to device (save without `onSave`, images) |
Expand Down Expand Up @@ -562,8 +562,12 @@ const pdfjs = async () => {
import { DocumentClient } from '@p10node/office-engine/core'

const doc = await DocumentClient.open(fileOrUrl, { onProgress: console.log })
doc.kind // 'docx' | 'xlsx' | 'pptx'
doc.info.from // 'pages' / 'keynote' / 'numbers' / 'visio': an Apple or Visio file, converted to docx / pptx / xlsx / pptx (view only)
doc.kind // 'docx' | 'xlsx' | 'pptx' | 'pdf' (a PDF file, read with 'pdf.read')
doc.info.from // 'pages' / 'keynote' / 'numbers' / 'visio' / 'eml' / 'msg': an Apple or Visio file, converted to docx / pptx / xlsx / pptx,
// or a mail message (.eml / .emlx, .msg / .oft) as docx (view only)
doc.info.mail // a mail message: { subject, attachments: [{ name, type, size }] }
await doc.call('mail.attachment', 0) // an attachment's file (a Blob of its type)
// open(src, { mail: { texts: { from: 'Von', … }, locale: 'de-DE' } }): the words of a message's header and the locale of its dates
doc.info.imported // 'csv' / 'tsv' / 'text' / 'markdown' / 'html' / 'svg' / 'mermaid' / 'plantuml' / 'graphviz' / 'code': a plain file, built as xlsx / docx (editable)
doc.info.language // 'code' (a source file): its language, 'typescript' / 'python' / 'json'… (the hint's own word when it is not one the highlighter knows)
doc.info.converted // 'doc' / 'xls' / 'ppt' / 'rtf' / 'odt' / 'ods' / 'odp': converted to docx / xlsx / pptx (editable, saved as such)
Expand Down
2 changes: 2 additions & 0 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ python3 -m venv .venv && .venv/bin/pip install python-docx openpyxl python-pptx
bun scripts/iwork-samples.ts # sample.pages / .key / .numbers (built by test/iwork-builder.ts)
bun scripts/visio-samples.ts # sample.vsdx (built by test/visio-builder.ts)
bun scripts/pdf-sample.ts # sample.pdf (built by test/pdf-builder.ts)
bun scripts/mail-samples.ts # sample.eml / sample.msg (built by test/mail-builder.ts)
bun scripts/legacy-samples/doc.ts # .doc / .ppt / .rtf test fixtures and samples (also ppt.ts, rtf.ts; .xls / .odt / .ods / .odp from the *.py scripts: see scripts/legacy-samples/*.md)
bun run screenshots # README screenshots -> docs/screenshots/ (headless Chromium)
bun run gifs # README GIFs (300k-row sheet opening, collaboration) -> docs/screenshots/*.gif (headless Chromium + ffmpeg)
Expand All @@ -35,6 +36,7 @@ src/core parsers, DOM-free (runs in worker / Bun)
legacy .doc / .xls / .ppt (compound file reader + converters), .rtf, OpenDocument → DOCX / XLSX / PPTX
iwork Pages / Keynote / Numbers → DOCX / PPTX / XLSX
visio Visio drawings (.vsdx) → PPTX
mail e-mail messages (.eml, .emlx, .msg, .oft) → DOCX (MIME, Outlook's MAPI properties, compressed RTF)
math TeX math: `$…$` / `$$…$$` in Markdown, TeX → MathML (views, web pages) and → OMML (Word file)
font font files read for layout: glyph widths, kerning, ligatures, line metrics, subsets (no DOM)
src/react view components
Expand Down
21 changes: 20 additions & 1 deletion docs/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,24 @@ A PDF file is shown as it is, drawn by [pdf.js](https://mozilla.github.io/pdf.js
- **File menu**: *Download as* the file itself and its text; *Document details*: title, author, subject, pages, page size, PDF version, application, producer; Print (`Ctrl/⌘+P`) prints the file itself
- **Not yet**: a find bar over the whole file, page thumbnails, filling forms, annotations other than links (drawn on the page), rotating pages; `@p10node/convert` refuses a PDF file

### E-mail messages (view only)

Mail messages open read-only as a document: the worker reads the message and builds a DOCX file of it in memory, and the document view shows it (pages, zoom, find, print, *Download as* **Word** / PDF / web page / text). The bar shows an `EML` or `MSG` badge and no Edit button, even with `editable`. The format is told by the file's bytes: an Outlook item is a compound file, an Internet message starts with mail headers (a file with no name, or served as `message/rfc822`, is recognised by them too).

| Format | Read |
|------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `.eml` (RFC 5322 / MIME) | headers (encoded words, RFC 2231 parameters, 8-bit UTF-8), nested multiparts (`alternative`: the HTML, `related`: its pictures, `mixed`, `signed`, `report`), base64 / quoted-printable, any charset the browser decodes, `format=flowed`, forwarded messages (`message/rfc822`) |
| `.emlx` (Apple Mail) | the message inside it (the length line and the property list after it are left out) |
| `.msg` / `.oft` (Outlook) | MAPI properties (MS-OXMSG): sender, recipients (To / Cc / Bcc), sent time, importance, message class; the HTML body, else the HTML or text Outlook wraps in compressed RTF (MS-OXRTFCP, MS-OXRTFEX), else the RTF itself (converted as `.rtf` files are), else the plain text; attachments and attached Outlook items |

The document holds, in order: the subject, the item's kind when it is not a plain message (meeting request, appointment, contact, task, delivery report) and its importance, a table of *From*, *Sent*, *To*, *Cc*, *Bcc* and *Attachments* (names and sizes), then the body, then each attached message the same way. An HTML body keeps its headings, lists, links, text formatting, tables (spans, borders, cell colors) and the pictures the message carries (`cid:` pictures and `data:` URLs, PNG / JPEG / GIF / BMP / WebP); a plain-text body has a paragraph per line, its web addresses as links and quoted lines (`>`) in grey. Addresses are `mailto:` links.

- **Attachments**: listed in the header and in the File menu under **Attachments**, each saved as it is from there (`mail.attachment` in the core API). Pictures the body shows and Outlook's hidden attachments are not listed
- **Privacy**: nothing is downloaded. Pictures an HTML body loads from the web (tracking pixels included) are left out, and the document says so; scripts, styles and forms of the HTML are not read, and links that would run script are not links
- **Language**: the header's words are the viewer's (`strings.mail`, German in the optional `de` table); dates are written in the viewer's locale and the browser's time zone
- **Not yet**: Outlook archives (`.pst`, `.ost`, `.olm`) and mailboxes (`.mbox`), the calendar details of meeting items (time, place: shown as a message), contact and task fields, `winmail.dat` (TNEF) unpacked, attachments opened in the viewer, CSS of the HTML body (layout from `<style>`, background images), nested tables in an HTML body (their text is kept, as lines)
- **Not supported**: encrypted messages (S/MIME, PGP), which say so in place of their body

### CSV, text, Markdown, HTML and SVG

A `src` (file, Blob, buffer or URL) that is not an Office package opens too, converted in the worker and **editable**:
Expand Down Expand Up @@ -325,7 +343,8 @@ Comment text is plain (lines kept); formatting inside comments read from a file
## File menu

- **New**: blank document, spreadsheet or presentation (16:9, Office theme, title / content / blank layouts)
- **Open** (`Ctrl/⌘+O`): `.docx` `.xlsx` `.pptx` open as they are; `.doc` `.xls` `.ppt` `.rtf` and OpenDocument `.odt` `.ods` `.odp` are converted (editable, saved as `.docx` / `.xlsx` / `.pptx`); `.csv` / `.tsv` become a workbook (numbers and booleans typed, codes like `007` kept as text); `.txt` / `.md` / `.html` become a document (headings, lists, bold / italic / strike, links, code); `.svg` / `.mmd` / `.puml` / `.dot` become a document with the picture; `.pdf` opens as it is (view only)
- **Open** (`Ctrl/⌘+O`): `.docx` `.xlsx` `.pptx` open as they are, mail messages (`.eml` `.emlx` `.msg` `.oft`) read-only; `.doc` `.xls` `.ppt` `.rtf` and OpenDocument `.odt` `.ods` `.odp` are converted (editable, saved as `.docx` / `.xlsx` / `.pptx`); `.csv` / `.tsv` become a workbook (numbers and booleans typed, codes like `007` kept as text); `.txt` / `.md` / `.html` become a document (headings, lists, bold / italic / strike, links, code); `.svg` / `.mmd` / `.puml` / `.dot` become a document with the picture; `.pdf` opens as it is (view only)
- **Attachments** (a mail message): each attachment, saved as it is
- **Download as**: the native format, PDF, web page (`.html`, images embedded), plain text / Markdown (DOCX), CSV / TSV of the current sheet (XLSX), slide text with notes (PPTX); a PDF file as itself and its plain text
- **Import CSV into new sheet** (XLSX): adds a sheet after the current one with the file's rows, streamed in the same way (in a shared session the rows go to everyone as cell edits)
- **Save** (`Ctrl/⌘+S`), **Rename** (shown name and the name used for saving), **Document details** (file, core properties, page / word / slide counts)
Expand Down
Loading