@cherrystudio/file-preview 0.1.2 → 0.2.0

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
@@ -80,9 +80,9 @@ outline navigation, emit diagnostics while the rest of the document remains usab
80
80
  `onRequestOpen` delegates external opening to the host only after the user activates
81
81
  an open button. Its reason is `unsupported` for unrecognized formats or `too_large`
82
82
  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
83
+ another application automatically. DOCX/PPTX above 25 MiB, XLSX above 20 MiB,
84
+ RTF above 10 MiB and images above 64 MiB show their limits. PDF has a 16 MiB
85
+ assembled-range cap, without a whole-document size limit. These states offer an external-open button when the
86
86
  host supplies the callback.
87
87
  `resources.baseUrl` optionally overrides the bundled worker/font/CMap directory;
88
88
  include a trailing slash. Relative URLs resolve against the host page.
@@ -214,6 +214,24 @@ Root overrides win over the packaged values, and PDF observes this same root for
214
214
  | `--file-preview-toolbar-button-size` | Toolbar button size, default `1.75rem` |
215
215
  | `--file-preview-bottom-inset` | Bottom space; content mode adds document scroll space or protects the fixed XLSX footer |
216
216
 
217
+ ## RTF documents
218
+
219
+ RTF previews render formatted text, Unicode and legacy code pages, links, and embedded
220
+ images using rtf.js. Documents use a white canvas in both themes to retain authored
221
+ foreground and highlight colors. HTTP, HTTPS and mail links open only on user action;
222
+ other links remain plain text. External image imports are not loaded.
223
+
224
+ Rendering is a flowing document preview, not a page-faithful Word layout. RTF does not
225
+ provide structural selection references. Parsing runs synchronously within the lazy
226
+ format module, subject to the 10 MiB source limit. The bundled rtf.js patch rejects
227
+ truncated documents, consumes binary image payloads, and restores the default font
228
+ on character resets. Literal bytes, hexadecimal escapes and escaped symbols share
229
+ one code-page decoder; Unicode controls remain decoded text. Raw double-byte trail
230
+ bytes are consumed before interpreting RTF syntax. Incomplete or unmapped byte
231
+ sequences fail the preview instead of inserting `undefined` into document content.
232
+ Regression cases cover Windows-1252, GBK, Big5 and Shift-JIS, including mixed byte
233
+ representations, font changes, group boundaries and Unicode fallback skipping.
234
+
217
235
  ## Building
218
236
 
219
237
  ```sh
@@ -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) {