@p10node/office-engine 0.2.0 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,32 +1,27 @@
1
1
  # @p10node/office-engine
2
2
 
3
+ [![npm version](https://img.shields.io/npm/v/@p10node/office-engine)](https://www.npmjs.com/package/@p10node/office-engine)
4
+ [![npm downloads](https://img.shields.io/npm/dm/@p10node/office-engine)](https://www.npmjs.com/package/@p10node/office-engine)
5
+ [![CI](https://github.com/p10node/office-engine/actions/workflows/ci.yml/badge.svg)](https://github.com/p10node/office-engine/actions/workflows/ci.yml)
6
+ [![License: MIT](https://img.shields.io/npm/l/@p10node/office-engine)](LICENSE)
7
+
3
8
  View + edit **DOCX / XLSX / PPTX** directly in the browser. Loads progressively like Google Docs, handles heavy files, one-line React embed, saves back to the original format.
4
9
 
5
- **[Live demo](https://p10node.github.io/office-engine/demo/)**: samples, heavy files (300k-row sheet, 305-slide deck), drag & drop your own file, edit and download.
10
+ **[npm](https://www.npmjs.com/package/@p10node/office-engine)** · **[Live demo](https://p10node.github.io/office-engine/demo/)** · **[Docs](https://p10node.github.io/office-engine/)**
6
11
 
7
- | DOCX | XLSX | PPTX |
8
- |-------------------------------------------|-------------------------------------------|-------------------------------------------|
9
- | ![DOCX editor](docs/screenshots/docx.png) | ![XLSX editor](docs/screenshots/xlsx.png) | ![PPTX editor](docs/screenshots/pptx.png) |
12
+ The demo has samples, heavy files (300k-row sheet, 305-slide deck), drag & drop your own file, edit and download.
10
13
 
11
- ## Features
14
+ **Real-time collaboration**
12
15
 
13
- - **Progressive loading**: lazy ZIP, HTTP Range requests, streaming XML parser in a Web Worker → UI never blocks
14
- - **Virtualized views**: only visible pages, cells and slides render
15
- - **Editing** with a Google Docs-style toolbar: DOCX text, styles, lists, images, tables; XLSX cells, formulas (134 functions), formats, borders, rows/columns, sheets; PPTX text, shapes, images, slides, slideshow
16
- - **Fast save**: only edited parts are regenerated, everything else keeps its original bytes
17
- - **File menu**: new, open (also CSV / text / Markdown / HTML), import CSV, rename, download as PDF / HTML / text / CSV, document details, print
18
- - **Real-time collaboration**: live edits, avatars, collaborators' cursors, offline edits sync on reconnect
19
- - **Embed anywhere**: React component, hook, vanilla `mount()`, `<office-viewer>` web component, single `<script>` file
16
+ ![Real-time collaboration: Ann and Bob edit one sheet side by side, Cara joins from a third browser](docs/screenshots/collab.gif)
20
17
 
21
- Full list, format coverage and limitations: [Features](docs/features.md).
18
+ **300k-row XLSX open in the browser**
22
19
 
23
- | File | Size | First paint | Fully loaded |
24
- |--------------------------|---------|-------------|-------------------|
25
- | DOCX 20k paragraphs | 1.2 MB | ~180 ms | 2073 pages in ~2s |
26
- | XLSX 300k rows × 12 cols | 24.8 MB | ~330 ms | ~2s |
27
- | PPTX 305 slides | 0.3 MB | ~110 ms | on-demand |
20
+ ![300k-row XLSX opening in the browser: rows stream in, then a jump to the last row](docs/screenshots/xlsx-300k.gif)
28
21
 
29
- Measured in headless Chromium on Apple M-series.
22
+ | DOCX editor | PPTX editor |
23
+ |-------------------------------------------|-------------------------------------------|
24
+ | ![DOCX editor](docs/screenshots/docx.png) | ![PPTX editor](docs/screenshots/pptx.png) |
30
25
 
31
26
  ## Install
32
27
 
@@ -62,6 +57,26 @@ Also online at [p10node.github.io/office-engine](https://p10node.github.io/offic
62
57
  - [Real-time collaboration](docs/collaboration.md)
63
58
  - [Development](docs/development.md): playground, architecture, demo deploy, release
64
59
 
60
+ ## Features
61
+
62
+ - **Progressive loading**: lazy ZIP, HTTP Range requests, streaming XML parser in a Web Worker → UI never blocks
63
+ - **Virtualized views**: only visible pages, cells and slides render
64
+ - **Editing** with a Google Docs-style toolbar: DOCX text, styles, lists, images, tables; XLSX cells, formulas (134 functions), formats, borders, rows/columns, sheets; PPTX text, shapes, images, slides, slideshow
65
+ - **Fast save**: only edited parts are regenerated, everything else keeps its original bytes
66
+ - **File menu**: new, open (also CSV / text / Markdown / HTML), import CSV, rename, download as PDF / HTML / text / CSV, document details, print
67
+ - **Real-time collaboration**: live edits, avatars, collaborators' cursors, offline edits sync on reconnect
68
+ - **Embed anywhere**: React component, hook, vanilla `mount()`, `<office-viewer>` web component, single `<script>` file
69
+
70
+ Full list, format coverage and limitations: [Features](docs/features.md).
71
+
72
+ | File | Size | First paint | Fully loaded |
73
+ |--------------------------|---------|-------------|-------------------|
74
+ | DOCX 20k paragraphs | 1.2 MB | ~180 ms | 2073 pages in ~2s |
75
+ | XLSX 300k rows × 12 cols | 24.8 MB | ~330 ms | ~2s |
76
+ | PPTX 305 slides | 0.3 MB | ~110 ms | on-demand |
77
+
78
+ Measured in headless Chromium on Apple M-series.
79
+
65
80
  ## License
66
81
 
67
82
  [MIT](LICENSE) © p10node
@@ -1,6 +1,6 @@
1
1
 
2
- import { C as e, E as t, N as n, P as r, S as i, d as a, f as o, h as s, j as c, m as l, o as u, p as d, t as f, u as p, w as m } from "./default-worker-DfpaJUjf.js";
3
- import { C as h, D as g, E as _, O as v, S as y, T as b, _ as ee, b as x, d as S, f as C, g as w, h as te, k as ne, m as re, p as ie, t as ae, v as T, w as E, x as oe, y as se } from "./collab-BvjXvfJ9.js";
2
+ import { C as e, E as t, N as n, P as r, S as i, d as a, f as o, h as s, j as c, m as l, o as u, p as d, t as f, u as p, w as m } from "./default-worker-BDj6MNRA.js";
3
+ import { C as h, D as g, E as _, O as v, S as y, T as b, _ as ee, b as x, d as S, f as C, g as w, h as te, k as ne, m as re, p as ie, t as ae, v as T, w as E, x as oe, y as se } from "./collab-Dx00zqXR.js";
4
4
  import { Children as D, Fragment as ce, createContext as le, isValidElement as O, memo as ue, useCallback as de, useContext as fe, useEffect as k, useId as pe, useInsertionEffect as me, useLayoutEffect as A, useMemo as he, useReducer as ge, useRef as j, useState as M, useSyncExternalStore as _e } from "react";
5
5
  import { createPortal as N } from "react-dom";
6
6
  import { Fragment as P, jsx as F, jsxs as I } from "react/jsx-runtime";
@@ -304,22 +304,23 @@ function ke(e) {
304
304
  let [t, n] = M({
305
305
  x: 0,
306
306
  y: 0
307
- });
308
- return k(() => {
309
- let t = e.current;
310
- if (!t) return;
311
- let r = 0, i = () => {
312
- r ||= requestAnimationFrame(() => {
313
- r = 0, n({
314
- x: t.scrollLeft,
315
- y: t.scrollTop
316
- });
307
+ }), [r, i] = M(null);
308
+ return Ee(() => {
309
+ e.current !== r && i(e.current);
310
+ }), k(() => {
311
+ if (!r) return;
312
+ let e = 0, t = () => n((e) => e.x === r.scrollLeft && e.y === r.scrollTop ? e : {
313
+ x: r.scrollLeft,
314
+ y: r.scrollTop
315
+ }), i = () => {
316
+ e ||= requestAnimationFrame(() => {
317
+ e = 0, t();
317
318
  });
318
319
  };
319
- return t.addEventListener("scroll", i, { passive: !0 }), () => {
320
- t.removeEventListener("scroll", i), cancelAnimationFrame(r);
320
+ return t(), r.addEventListener("scroll", i, { passive: !0 }), () => {
321
+ r.removeEventListener("scroll", i), cancelAnimationFrame(e);
321
322
  };
322
- }, [e]), t;
323
+ }, [r]), t;
323
324
  }
324
325
  function U(e, n, r = !0) {
325
326
  let [i, a] = M(null);
@@ -1834,6 +1835,37 @@ var Pt = class {
1834
1835
  for (let e = 0; e < Math.min(n.length, r.length); e++) if (n[e] !== r[e]) return n[e] - r[e];
1835
1836
  return n.length - r.length;
1836
1837
  }
1838
+ all() {
1839
+ let e = -1, t = -1;
1840
+ return this.st.blocks.forEach((n, r) => {
1841
+ this.para(String(r)) && (e < 0 && (e = r), t = r);
1842
+ }), e < 0 ? null : {
1843
+ a: {
1844
+ pa: String(e),
1845
+ o: 0
1846
+ },
1847
+ f: {
1848
+ pa: String(t),
1849
+ o: oe(this.para(String(t)).runs)
1850
+ }
1851
+ };
1852
+ }
1853
+ selectAll() {
1854
+ this.input.selectAll();
1855
+ }
1856
+ deleteAcross(e, t) {
1857
+ let n = Mt(e.pa), r = Mt(t.pa);
1858
+ if (n.length !== 1 || r.length !== 1 || n[0] >= r[0]) return null;
1859
+ let i = this.para(e.pa), a = this.para(t.pa);
1860
+ if (!i || !a) return null;
1861
+ let o = (e, t) => this.st.blocks[e]?.t === "p" && this.st.blocks[e].pid === t.pid;
1862
+ if (o(n[0] - 1, i) || o(r[0] + 1, a)) return null;
1863
+ let s = x([...b(i.runs, e.o)[0], ...b(a.runs, t.o)[1]]), c = this.st.blocks.slice(n[0] + 1, r[0]).filter((e) => e.t === "sect");
1864
+ return this.replaceBlocks(n[0], r[0] - n[0] + 1, [this.join(i, a, s), ...c], {
1865
+ a: e,
1866
+ f: e
1867
+ }), e;
1868
+ }
1837
1869
  withRuns(e, t) {
1838
1870
  return {
1839
1871
  ...e,
@@ -2327,7 +2359,12 @@ var Pt = class {
2327
2359
  item: e.item,
2328
2360
  spec: null
2329
2361
  });
2330
- if (n.forEach((t, n) => t.t === "tbl" && t.tid !== void 0 && this.commitTable(e + n)), this.onCommit?.({
2362
+ if (n.forEach((t, n) => {
2363
+ t.t === "tbl" && (t.tid === void 0 && !c.has(o(t)) && (this.st.blocks[e + n] = {
2364
+ ...t,
2365
+ tid: this.nextPid++
2366
+ }), this.commitTable(e + n));
2367
+ }), this.onCommit?.({
2331
2368
  kind: "blocks",
2332
2369
  bi: e,
2333
2370
  before: a,
@@ -4226,7 +4263,7 @@ function bn({ client: e, onStatus: t, initialZoom: n = "fit" }) {
4226
4263
  label: "Select all",
4227
4264
  icon: "selectAll",
4228
4265
  hint: `${Z}A`,
4229
- run: () => document.execCommand("selectAll")
4266
+ run: () => b.selectAll()
4230
4267
  }), r;
4231
4268
  }, $e = c?.styles?.find((e) => e.canon === "title")?.id, et = he(() => se ? vn(a.blocks, $e) : [], [
4232
4269
  se,
@@ -4261,10 +4298,11 @@ function bn({ client: e, onStatus: t, initialZoom: n = "fit" }) {
4261
4298
  className: "de-scroll",
4262
4299
  tabIndex: -1,
4263
4300
  onKeyDown: (e) => {
4264
- (e.metaKey || e.ctrlKey) && e.key.toLowerCase() === "f" && (e.preventDefault(), w((e) => ({
4301
+ let t = (e.metaKey || e.ctrlKey) && !e.altKey, n = e.key.toLowerCase();
4302
+ t && n === "f" ? (e.preventDefault(), w((e) => ({
4265
4303
  ...e,
4266
4304
  open: !0
4267
- })));
4305
+ }))) : t && n === "a" && !e.shiftKey && !x && y.current && (e.preventDefault(), ie(y.current)?.selectAllChildren(y.current));
4268
4306
  },
4269
4307
  children: [
4270
4308
  c && z.length > 0 && /* @__PURE__ */ F("div", {
@@ -9296,6 +9334,15 @@ function ua({ store: e, sheet: t, meta: n, client: r, edit: i, setEdit: a, hold:
9296
9334
  e.preventDefault(), d.save();
9297
9335
  return;
9298
9336
  }
9337
+ if (t && n === "a" && !e.altKey && !e.shiftKey) {
9338
+ e.preventDefault(), Ye({
9339
+ ar: 0,
9340
+ ac: 0,
9341
+ fr: Math.max(0, p.rows - 1),
9342
+ fc: Math.max(0, p.cols - 1)
9343
+ });
9344
+ return;
9345
+ }
9299
9346
  if (f && t && !e.altKey) {
9300
9347
  if (n === "z") {
9301
9348
  e.preventDefault(), e.shiftKey ? Wt() : Ut();
@@ -10566,4 +10613,4 @@ function Ca(e) {
10566
10613
  }
10567
10614
  export { ea as a, li as c, bn as d, ma as i, dr as l, _a as n, Ci as o, va as r, Si as s, Ca as t, lr as u };
10568
10615
 
10569
- //# sourceMappingURL=DocViewer-PJieqbIR.js.map
10616
+ //# sourceMappingURL=DocViewer-CT8VAa1L.js.map