@cherrystudio/file-preview 0.1.3 → 0.2.1

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,6 +1,6 @@
1
1
  # File preview
2
2
 
3
- Portable React DOM previews for PDF, DOCX, PPTX, XLSX and images (including SVG).
3
+ Portable React DOM previews for PDF, DOCX, PPTX, XLSX, RTF and images (including SVG).
4
4
  The package owns rendering, controls, structural selections, workers and translations.
5
5
  Hosts own file access, permissions, navigation, external opening and logging.
6
6
  HTML, Markdown and source-code previews remain in the desktop application.
@@ -30,7 +30,7 @@ The preview closes it after failure, replacement, refresh or unmount, including
30
30
  open that completes after cancellation. A document's size and revision stay fixed;
31
31
  its reader must reject version changes, short reads and reads after close. Close must
32
32
  be idempotent. Range offsets and lengths are safe integers within the document size.
33
- DOCX, PPTX, XLSX and images request the whole document as one `[0, size)` range, so
33
+ DOCX, PPTX, XLSX, RTF and images request the whole document as one `[0, size)` range, so
34
34
  a host can serve it with a single read; PDF requests partial ranges.
35
35
  Readers should honor abort signals where their transport supports cancellation. The
36
36
  package discards a read result after cancellation; it cannot stop host I/O that has
@@ -44,6 +44,15 @@ and file-identity content for the fixed top row; the format toolbar shares that
44
44
  Without a header, format controls render above the document. Give `source` and
45
45
  `resources` stable references so layout, locale and theme updates retain the session.
46
46
 
47
+ Refreshing the same source ID and format retains the mounted format and its valid
48
+ reading state while opening a fresh document. Formats preserve zoom, page, scroll,
49
+ worksheet and image transforms as applicable, and clamp positions to shorter content.
50
+ A different source ID or format starts a new preview. The previous document still
51
+ closes on refresh; obsolete reads and parsing results cannot overwrite retained
52
+ content or publish selections or terminal errors for the replacement session.
53
+ Closing and reopening a preview does not persist reading
54
+ history. Hosts must clear any held selection when requesting a refresh.
55
+
47
56
  `onSelection` reports `{ sourceId, revision, anchor, excerpt }`, or `null` when a
48
57
  pick is cleared. Anchors use worksheet A1 ranges, body paragraph ordinals, PDF pages
49
58
  and PPTX slides. The host owns held selections across refreshes and file switches.
@@ -80,9 +89,9 @@ outline navigation, emit diagnostics while the rest of the document remains usab
80
89
  `onRequestOpen` delegates external opening to the host only after the user activates
81
90
  an open button. Its reason is `unsupported` for unrecognized formats or `too_large`
82
91
  for size-limit fallbacks; rendering or refreshing an unsupported source never opens
83
- another application automatically. DOCX/PPTX above 25 MiB, XLSX above 20 MiB and
84
- images above 64 MiB show their limits. PDF has a 16 MiB assembled-range cap, without
85
- a whole-document size limit. These states offer an external-open button when the
92
+ another application automatically. DOCX/PPTX above 25 MiB, XLSX above 20 MiB,
93
+ RTF above 10 MiB and images above 64 MiB show their limits. PDF has a 16 MiB
94
+ assembled-range cap, without a whole-document size limit. These states offer an external-open button when the
86
95
  host supplies the callback.
87
96
  `resources.baseUrl` optionally overrides the bundled worker/font/CMap directory;
88
97
  include a trailing slash. Relative URLs resolve against the host page.
@@ -214,6 +223,24 @@ Root overrides win over the packaged values, and PDF observes this same root for
214
223
  | `--file-preview-toolbar-button-size` | Toolbar button size, default `1.75rem` |
215
224
  | `--file-preview-bottom-inset` | Bottom space; content mode adds document scroll space or protects the fixed XLSX footer |
216
225
 
226
+ ## RTF documents
227
+
228
+ RTF previews render formatted text, Unicode and legacy code pages, links, and embedded
229
+ images using rtf.js. Documents use a white canvas in both themes to retain authored
230
+ foreground and highlight colors. HTTP, HTTPS and mail links open only on user action;
231
+ other links remain plain text. External image imports are not loaded.
232
+
233
+ Rendering is a flowing document preview, not a page-faithful Word layout. RTF does not
234
+ provide structural selection references. Parsing runs synchronously within the lazy
235
+ format module, subject to the 10 MiB source limit. The bundled rtf.js patch rejects
236
+ truncated documents, consumes binary image payloads, and restores the default font
237
+ on character resets. Literal bytes, hexadecimal escapes and escaped symbols share
238
+ one code-page decoder; Unicode controls remain decoded text. Raw double-byte trail
239
+ bytes are consumed before interpreting RTF syntax. Incomplete or unmapped byte
240
+ sequences fail the preview instead of inserting `undefined` into document content.
241
+ Regression cases cover Windows-1252, GBK, Big5 and Shift-JIS, including mixed byte
242
+ representations, font changes, group boundaries and Unicode fallback skipping.
243
+
217
244
  ## Building
218
245
 
219
246
  ```sh
@@ -228,6 +255,22 @@ is bundled, including UI components and the patched docx-preview and pptx-render
228
255
  dependencies; consumers install only `zod` and the React peers. CSS excludes Tailwind preflight
229
256
  and scopes selectors to `.file-preview-root`.
230
257
 
258
+ ## Browser regression tests
259
+
260
+ From the workspace root, install Playwright's Chromium once, then run the package tests:
261
+
262
+ ```sh
263
+ pnpm exec playwright install chromium
264
+ pnpm exec playwright test --config packages/file-preview/playwright.config.ts
265
+ ```
266
+
267
+ The test configuration builds the package and starts its own Vite server, then stops
268
+ the server after the run. No running Electron instance or renderer development server
269
+ is required. The PDF cases exercise the built public package and actual worker/layout
270
+ for mixed/changed page geometry, reading offsets, refresh, zoom, Activity and shorter documents.
271
+ The PowerPoint case uses the real renderer to retain a slide-relative reading offset
272
+ when the same deck changes its slide proportions, including Activity restoration.
273
+
231
274
  ## Publishing
232
275
 
233
276
  Versioning and npm publishing use the repository's [Changesets workflow](../../.changeset/README.md).
@@ -1,4 +1,5 @@
1
- import { O as useCallbackRef$1, V as useComposedRefs, k as Primitive } from "./useTranslation-DMhY277o.js";
1
+ import { b as useComposedRefs } from "./useTranslation-BJY4EKsz.js";
2
+ import { v as useCallbackRef$1, y as Primitive } from "./FilePreviewToolbarButton-ptqwCTnz.js";
2
3
  import * as React$1 from "react";
3
4
  import { useState } from "react";
4
5
  import { jsx } from "react/jsx-runtime";
@@ -1,4 +1,4 @@
1
- import { L as FileWarning, N as EmptyState, o as usePreviewHost, t as useTranslation } from "./useTranslation-DMhY277o.js";
1
+ import { a as usePreviewHost, d as EmptyState, h as FileWarning, t as useTranslation } from "./useTranslation-BJY4EKsz.js";
2
2
  import { jsx } from "react/jsx-runtime";
3
3
  //#region src/formatFileSize.ts
4
4
  function formatFileSize(size) {