@papyrus-sdk/engine-native 0.2.26 → 0.2.27

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.
@@ -0,0 +1,227 @@
1
+ package com.papyrus.engine;
2
+
3
+ import android.content.Context;
4
+ import android.graphics.Bitmap;
5
+ import android.graphics.BitmapFactory;
6
+ import android.graphics.Color;
7
+ import android.graphics.pdf.PdfRenderer;
8
+ import android.net.Uri;
9
+ import android.os.ParcelFileDescriptor;
10
+
11
+ import java.io.BufferedReader;
12
+ import java.io.File;
13
+ import java.io.FileOutputStream;
14
+ import java.io.IOException;
15
+ import java.io.InputStream;
16
+ import java.io.InputStreamReader;
17
+ import java.nio.charset.StandardCharsets;
18
+ import java.util.ArrayList;
19
+ import java.util.List;
20
+ import java.util.regex.Matcher;
21
+ import java.util.regex.Pattern;
22
+ import java.util.zip.ZipEntry;
23
+ import java.util.zip.ZipFile;
24
+
25
+ /**
26
+ * Draws one page of a PDF, or the cover image of an EPUB, into an image file.
27
+ *
28
+ * It opens the document, renders, and closes everything before returning: no
29
+ * engine, view or cache outlives the call. PDFs go through the platform's
30
+ * PdfRenderer, so a thumbnail never touches the reader's pdfium document.
31
+ * Only local sources are accepted: a thumbnail must not trigger a download.
32
+ */
33
+ final class PapyrusThumbnail {
34
+ static final class Result {
35
+ final String path;
36
+ final int width;
37
+ final int height;
38
+
39
+ Result(String path, int width, int height) {
40
+ this.path = path;
41
+ this.width = width;
42
+ this.height = height;
43
+ }
44
+ }
45
+
46
+ private PapyrusThumbnail() {}
47
+
48
+ static Result generate(Context context, String sourceUri, String type, int pageIndex, int maxWidth, String format, int quality, String outputPath) throws IOException {
49
+ if (sourceUri == null || sourceUri.isEmpty()) throw new IllegalArgumentException("uri is required");
50
+ int width = Math.max(32, Math.min(maxWidth <= 0 ? 480 : maxWidth, 2048));
51
+ boolean png = "png".equalsIgnoreCase(format);
52
+ String kind = kindOf(sourceUri, type);
53
+ Bitmap bitmap = null;
54
+ try {
55
+ if ("pdf".equals(kind)) bitmap = renderPdf(context, sourceUri, Math.max(0, pageIndex), width);
56
+ else if ("epub".equals(kind)) bitmap = renderEpubCover(sourceUri, width);
57
+ else throw new IllegalArgumentException("unsupported document type");
58
+
59
+ File destination = outputPath != null && !outputPath.isEmpty()
60
+ ? new File(stripFileScheme(outputPath))
61
+ : File.createTempFile("thumbnail-", png ? ".png" : ".jpg", ensureDirectory(new File(context.getCacheDir(), "papyrus-thumbnails")));
62
+ File parent = destination.getParentFile();
63
+ if (parent != null) ensureDirectory(parent);
64
+ // Written aside and renamed: a half-written file is never read as an image.
65
+ File partial = new File(destination.getPath() + ".part");
66
+ try (FileOutputStream out = new FileOutputStream(partial)) {
67
+ Bitmap.CompressFormat encoder = png ? Bitmap.CompressFormat.PNG : Bitmap.CompressFormat.JPEG;
68
+ if (!bitmap.compress(encoder, Math.max(1, Math.min(quality <= 0 ? 85 : quality, 100)), out)) {
69
+ throw new IOException("could not encode the thumbnail");
70
+ }
71
+ }
72
+ if (!partial.renameTo(destination)) {
73
+ partial.delete();
74
+ throw new IOException("could not store the thumbnail");
75
+ }
76
+ return new Result(destination.getAbsolutePath(), bitmap.getWidth(), bitmap.getHeight());
77
+ } finally {
78
+ if (bitmap != null) bitmap.recycle();
79
+ }
80
+ }
81
+
82
+ private static File ensureDirectory(File directory) throws IOException {
83
+ if (!directory.isDirectory() && !directory.mkdirs() && !directory.isDirectory()) {
84
+ throw new IOException("could not create " + directory);
85
+ }
86
+ return directory;
87
+ }
88
+
89
+ private static String stripFileScheme(String value) {
90
+ return value.startsWith("file://") ? Uri.parse(value).getPath() : value;
91
+ }
92
+
93
+ static String kindOf(String sourceUri, String type) {
94
+ String declared = type == null ? "" : type.toLowerCase();
95
+ String path = sourceUri.toLowerCase();
96
+ int query = path.indexOf('?');
97
+ if (query >= 0) path = path.substring(0, query);
98
+ if (declared.contains("pdf") || path.endsWith(".pdf")) return "pdf";
99
+ if (declared.contains("epub") || path.endsWith(".epub")) return "epub";
100
+ return "unknown";
101
+ }
102
+
103
+ private static ParcelFileDescriptor openDescriptor(Context context, String sourceUri) throws IOException {
104
+ if (sourceUri.startsWith("content://")) {
105
+ ParcelFileDescriptor descriptor = context.getContentResolver().openFileDescriptor(Uri.parse(sourceUri), "r");
106
+ if (descriptor == null) throw new IOException("could not open the document");
107
+ return descriptor;
108
+ }
109
+ if (sourceUri.startsWith("file://") || sourceUri.startsWith("/")) {
110
+ return ParcelFileDescriptor.open(new File(stripFileScheme(sourceUri)), ParcelFileDescriptor.MODE_READ_ONLY);
111
+ }
112
+ throw new IllegalArgumentException("the document must be a local file");
113
+ }
114
+
115
+ private static Bitmap renderPdf(Context context, String sourceUri, int pageIndex, int maxWidth) throws IOException {
116
+ try (ParcelFileDescriptor descriptor = openDescriptor(context, sourceUri);
117
+ PdfRenderer renderer = new PdfRenderer(descriptor)) {
118
+ if (renderer.getPageCount() < 1) throw new IOException("the document has no pages");
119
+ try (PdfRenderer.Page page = renderer.openPage(Math.min(pageIndex, renderer.getPageCount() - 1))) {
120
+ float scale = maxWidth / (float) Math.max(1, page.getWidth());
121
+ int width = Math.max(1, Math.round(page.getWidth() * scale));
122
+ int height = Math.max(1, Math.round(page.getHeight() * scale));
123
+ Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
124
+ // PDF pages are transparent where nothing is drawn.
125
+ bitmap.eraseColor(Color.WHITE);
126
+ page.render(bitmap, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY);
127
+ return bitmap;
128
+ }
129
+ }
130
+ }
131
+
132
+ private static String readEntry(ZipFile zip, String name) throws IOException {
133
+ ZipEntry entry = zip.getEntry(name);
134
+ if (entry == null) return null;
135
+ StringBuilder text = new StringBuilder();
136
+ try (BufferedReader reader = new BufferedReader(new InputStreamReader(zip.getInputStream(entry), StandardCharsets.UTF_8))) {
137
+ char[] buffer = new char[8192];
138
+ int read;
139
+ while ((read = reader.read(buffer)) > 0) text.append(buffer, 0, read);
140
+ }
141
+ return text.toString();
142
+ }
143
+
144
+ private static String attribute(String tag, String name) {
145
+ Matcher matcher = Pattern.compile("\\b" + name + "\\s*=\\s*[\"']([^\"']*)[\"']").matcher(tag);
146
+ return matcher.find() ? matcher.group(1) : null;
147
+ }
148
+
149
+ private static List<String> tags(String xml, String name) {
150
+ List<String> found = new ArrayList<>();
151
+ Matcher matcher = Pattern.compile("<" + name + "\\b[^>]*>").matcher(xml);
152
+ while (matcher.find()) found.add(matcher.group());
153
+ return found;
154
+ }
155
+
156
+ /** The cover image named by the EPUB package (EPUB 3 `cover-image`, EPUB 2 `meta name="cover"`). */
157
+ static String epubCoverEntry(String opfPath, String opf) {
158
+ String coverId = null;
159
+ for (String meta : tags(opf, "meta")) {
160
+ if ("cover".equals(attribute(meta, "name"))) coverId = attribute(meta, "content");
161
+ }
162
+ String href = null;
163
+ List<String> items = tags(opf, "item");
164
+ for (String item : items) {
165
+ String properties = attribute(item, "properties");
166
+ if (properties != null && (" " + properties + " ").contains(" cover-image ")) href = attribute(item, "href");
167
+ }
168
+ if (href == null && coverId != null) {
169
+ for (String item : items) {
170
+ if (coverId.equals(attribute(item, "id"))) href = attribute(item, "href");
171
+ }
172
+ }
173
+ if (href == null) {
174
+ for (String item : items) {
175
+ String mediaType = attribute(item, "media-type");
176
+ String id = attribute(item, "id");
177
+ if (mediaType != null && mediaType.startsWith("image/") && id != null && id.toLowerCase().contains("cover")) {
178
+ href = attribute(item, "href");
179
+ break;
180
+ }
181
+ }
182
+ }
183
+ if (href == null) return null;
184
+ int slash = opfPath.lastIndexOf('/');
185
+ String base = slash >= 0 ? opfPath.substring(0, slash + 1) : "";
186
+ String normalized = new File("/" + base + Uri.decode(href)).toURI().normalize().getPath();
187
+ return normalized.startsWith("/") ? normalized.substring(1) : normalized;
188
+ }
189
+
190
+ private static Bitmap renderEpubCover(String sourceUri, int maxWidth) throws IOException {
191
+ if (!(sourceUri.startsWith("file://") || sourceUri.startsWith("/"))) {
192
+ throw new IllegalArgumentException("the document must be a local file");
193
+ }
194
+ try (ZipFile zip = new ZipFile(new File(stripFileScheme(sourceUri)))) {
195
+ String container = readEntry(zip, "META-INF/container.xml");
196
+ if (container == null) throw new IOException("not an EPUB");
197
+ Matcher rootfile = Pattern.compile("full-path\\s*=\\s*[\"']([^\"']+)[\"']").matcher(container);
198
+ if (!rootfile.find()) throw new IOException("EPUB without a package file");
199
+ String opfPath = rootfile.group(1);
200
+ String opf = readEntry(zip, opfPath);
201
+ if (opf == null) throw new IOException("EPUB without a package file");
202
+ String coverName = epubCoverEntry(opfPath, opf);
203
+ ZipEntry cover = coverName == null ? null : zip.getEntry(coverName);
204
+ if (cover == null) throw new IOException("EPUB without a cover image");
205
+
206
+ BitmapFactory.Options bounds = new BitmapFactory.Options();
207
+ bounds.inJustDecodeBounds = true;
208
+ try (InputStream stream = zip.getInputStream(cover)) {
209
+ BitmapFactory.decodeStream(stream, null, bounds);
210
+ }
211
+ if (bounds.outWidth <= 0 || bounds.outHeight <= 0) throw new IOException("EPUB cover image is not readable");
212
+ BitmapFactory.Options options = new BitmapFactory.Options();
213
+ options.inSampleSize = 1;
214
+ while (bounds.outWidth / (options.inSampleSize * 2) >= maxWidth) options.inSampleSize *= 2;
215
+ Bitmap decoded;
216
+ try (InputStream stream = zip.getInputStream(cover)) {
217
+ decoded = BitmapFactory.decodeStream(stream, null, options);
218
+ }
219
+ if (decoded == null) throw new IOException("EPUB cover image is not readable");
220
+ if (decoded.getWidth() <= maxWidth) return decoded;
221
+ float scale = maxWidth / (float) decoded.getWidth();
222
+ Bitmap scaled = Bitmap.createScaledBitmap(decoded, maxWidth, Math.max(1, Math.round(decoded.getHeight() * scale)), true);
223
+ if (scaled != decoded) decoded.recycle();
224
+ return scaled;
225
+ }
226
+ }
227
+ }
package/dist/index.d.mts CHANGED
@@ -233,6 +233,40 @@ type PapyrusComicDocumentViewProps = ViewProps & {
233
233
  };
234
234
  type PapyrusPageViewComponent = ComponentType<PapyrusPageViewProps & RefAttributes<View>>;
235
235
  type PapyrusPdfViewerViewComponent = ComponentType<PapyrusPdfViewerViewProps & RefAttributes<View>>;
236
+ type PapyrusThumbnailOptions = {
237
+ /** A local document: `file://`, an absolute path or (PDF only) `content://`. Remote URLs are refused. */
238
+ uri: string;
239
+ /** "pdf" | "epub" or a MIME type, when the file name does not say. */
240
+ type?: string;
241
+ /** PDF page to draw. EPUB always yields its cover image. */
242
+ pageIndex?: number;
243
+ maxWidth?: number;
244
+ format?: "jpeg" | "png";
245
+ /** 1–100, JPEG only. */
246
+ quality?: number;
247
+ /** Where to write the image. Defaults to a new file in the app's cache. */
248
+ outputPath?: string;
249
+ };
250
+ type PapyrusThumbnail = {
251
+ uri: string;
252
+ width: number;
253
+ height: number;
254
+ };
255
+ /**
256
+ * Whether `generateThumbnail` works on this build. Android only for now: the
257
+ * iOS implementation ships disabled until it has been validated on a device.
258
+ */
259
+ declare const isThumbnailGenerationSupported: () => boolean;
260
+ /**
261
+ * Draws one page of a PDF, or the cover image of an EPUB, into an image file
262
+ * and returns it. The document is opened, rendered and closed inside the
263
+ * call: no engine, view or WebView is involved and nothing stays in memory.
264
+ * Calls are served one at a time on a background-priority thread.
265
+ *
266
+ * The host owns the policy around it: when to ask, where to keep the files
267
+ * and how to show them.
268
+ */
269
+ declare function generateThumbnail(options: PapyrusThumbnailOptions): Promise<PapyrusThumbnail>;
236
270
  declare const isPapyrusTablet: () => boolean;
237
271
  declare const isPapyrusPdfDocumentViewAvailable: () => boolean;
238
272
  declare const PapyrusPageView: PapyrusPageViewComponent;
@@ -635,6 +669,15 @@ declare class NativeDocumentEngine extends BaseDocumentEngine {
635
669
  getOutline(): Promise<OutlineItem[]>;
636
670
  searchText(query: string): Promise<SearchResult[]>;
637
671
  getPageIndex(dest: PageDestination): Promise<number | null>;
672
+ /**
673
+ * Releases the native document (file, pages, parser caches) while the
674
+ * reader is not on screen. Position, zoom and everything the app keeps
675
+ * (progress, annotations) are untouched; call `resume()` before using the
676
+ * engine again. Resolves false where the platform has nothing to release.
677
+ */
678
+ suspend(): Promise<boolean>;
679
+ /** Reopens a document released by `suspend()`. Safe to call when it is already open. */
680
+ resume(): Promise<boolean>;
638
681
  destroy(): void;
639
682
  private assertNativeModule;
640
683
  private normalizeSource;
@@ -820,6 +863,13 @@ declare class MobileDocumentEngine extends BaseDocumentEngine {
820
863
  getCurrentTextOffset(): number;
821
864
  goToTextOffset(offset: number): void;
822
865
  getLifecycleStats(): Record<string, number>;
866
+ /**
867
+ * Releases the native PDF document while the reader is not on screen, and
868
+ * reopens it. Only the PDF engine holds a native document; for the other
869
+ * formats both resolve false and nothing changes.
870
+ */
871
+ suspend(): Promise<boolean>;
872
+ resume(): Promise<boolean>;
823
873
  resolveAnnotationTextRange(annotation: Annotation): Promise<{
824
874
  start: number;
825
875
  end: number;
@@ -864,4 +914,4 @@ declare class MobileDocumentEngine extends BaseDocumentEngine {
864
914
  destroy(): void;
865
915
  }
866
916
 
867
- export { MobileDocumentEngine, type MobileDocumentEngineOptions, NativeComicDocumentEngine, NativeDocumentEngine, NativeTextDocumentEngine, PapyrusComicDocumentView, type PapyrusComicDocumentViewProps, PapyrusPageView, type PapyrusPageViewProps, PapyrusPdfDocumentView, PapyrusPdfViewerView, type PapyrusPdfViewerViewProps, PapyrusTextDocumentView, type PapyrusTextDocumentViewProps, WebViewDocumentEngine, type WebViewRuntimeConfig, type WebViewRuntimeSource, isPapyrusComicDocumentViewAvailable, isPapyrusPdfDocumentViewAvailable, isPapyrusTablet, isPapyrusTextDocumentViewAvailable };
917
+ export { MobileDocumentEngine, type MobileDocumentEngineOptions, NativeComicDocumentEngine, NativeDocumentEngine, NativeTextDocumentEngine, PapyrusComicDocumentView, type PapyrusComicDocumentViewProps, PapyrusPageView, type PapyrusPageViewProps, PapyrusPdfDocumentView, PapyrusPdfViewerView, type PapyrusPdfViewerViewProps, PapyrusTextDocumentView, type PapyrusTextDocumentViewProps, type PapyrusThumbnail, type PapyrusThumbnailOptions, WebViewDocumentEngine, type WebViewRuntimeConfig, type WebViewRuntimeSource, generateThumbnail, isPapyrusComicDocumentViewAvailable, isPapyrusPdfDocumentViewAvailable, isPapyrusTablet, isPapyrusTextDocumentViewAvailable, isThumbnailGenerationSupported };
package/dist/index.d.ts CHANGED
@@ -233,6 +233,40 @@ type PapyrusComicDocumentViewProps = ViewProps & {
233
233
  };
234
234
  type PapyrusPageViewComponent = ComponentType<PapyrusPageViewProps & RefAttributes<View>>;
235
235
  type PapyrusPdfViewerViewComponent = ComponentType<PapyrusPdfViewerViewProps & RefAttributes<View>>;
236
+ type PapyrusThumbnailOptions = {
237
+ /** A local document: `file://`, an absolute path or (PDF only) `content://`. Remote URLs are refused. */
238
+ uri: string;
239
+ /** "pdf" | "epub" or a MIME type, when the file name does not say. */
240
+ type?: string;
241
+ /** PDF page to draw. EPUB always yields its cover image. */
242
+ pageIndex?: number;
243
+ maxWidth?: number;
244
+ format?: "jpeg" | "png";
245
+ /** 1–100, JPEG only. */
246
+ quality?: number;
247
+ /** Where to write the image. Defaults to a new file in the app's cache. */
248
+ outputPath?: string;
249
+ };
250
+ type PapyrusThumbnail = {
251
+ uri: string;
252
+ width: number;
253
+ height: number;
254
+ };
255
+ /**
256
+ * Whether `generateThumbnail` works on this build. Android only for now: the
257
+ * iOS implementation ships disabled until it has been validated on a device.
258
+ */
259
+ declare const isThumbnailGenerationSupported: () => boolean;
260
+ /**
261
+ * Draws one page of a PDF, or the cover image of an EPUB, into an image file
262
+ * and returns it. The document is opened, rendered and closed inside the
263
+ * call: no engine, view or WebView is involved and nothing stays in memory.
264
+ * Calls are served one at a time on a background-priority thread.
265
+ *
266
+ * The host owns the policy around it: when to ask, where to keep the files
267
+ * and how to show them.
268
+ */
269
+ declare function generateThumbnail(options: PapyrusThumbnailOptions): Promise<PapyrusThumbnail>;
236
270
  declare const isPapyrusTablet: () => boolean;
237
271
  declare const isPapyrusPdfDocumentViewAvailable: () => boolean;
238
272
  declare const PapyrusPageView: PapyrusPageViewComponent;
@@ -635,6 +669,15 @@ declare class NativeDocumentEngine extends BaseDocumentEngine {
635
669
  getOutline(): Promise<OutlineItem[]>;
636
670
  searchText(query: string): Promise<SearchResult[]>;
637
671
  getPageIndex(dest: PageDestination): Promise<number | null>;
672
+ /**
673
+ * Releases the native document (file, pages, parser caches) while the
674
+ * reader is not on screen. Position, zoom and everything the app keeps
675
+ * (progress, annotations) are untouched; call `resume()` before using the
676
+ * engine again. Resolves false where the platform has nothing to release.
677
+ */
678
+ suspend(): Promise<boolean>;
679
+ /** Reopens a document released by `suspend()`. Safe to call when it is already open. */
680
+ resume(): Promise<boolean>;
638
681
  destroy(): void;
639
682
  private assertNativeModule;
640
683
  private normalizeSource;
@@ -820,6 +863,13 @@ declare class MobileDocumentEngine extends BaseDocumentEngine {
820
863
  getCurrentTextOffset(): number;
821
864
  goToTextOffset(offset: number): void;
822
865
  getLifecycleStats(): Record<string, number>;
866
+ /**
867
+ * Releases the native PDF document while the reader is not on screen, and
868
+ * reopens it. Only the PDF engine holds a native document; for the other
869
+ * formats both resolve false and nothing changes.
870
+ */
871
+ suspend(): Promise<boolean>;
872
+ resume(): Promise<boolean>;
823
873
  resolveAnnotationTextRange(annotation: Annotation): Promise<{
824
874
  start: number;
825
875
  end: number;
@@ -864,4 +914,4 @@ declare class MobileDocumentEngine extends BaseDocumentEngine {
864
914
  destroy(): void;
865
915
  }
866
916
 
867
- export { MobileDocumentEngine, type MobileDocumentEngineOptions, NativeComicDocumentEngine, NativeDocumentEngine, NativeTextDocumentEngine, PapyrusComicDocumentView, type PapyrusComicDocumentViewProps, PapyrusPageView, type PapyrusPageViewProps, PapyrusPdfDocumentView, PapyrusPdfViewerView, type PapyrusPdfViewerViewProps, PapyrusTextDocumentView, type PapyrusTextDocumentViewProps, WebViewDocumentEngine, type WebViewRuntimeConfig, type WebViewRuntimeSource, isPapyrusComicDocumentViewAvailable, isPapyrusPdfDocumentViewAvailable, isPapyrusTablet, isPapyrusTextDocumentViewAvailable };
917
+ export { MobileDocumentEngine, type MobileDocumentEngineOptions, NativeComicDocumentEngine, NativeDocumentEngine, NativeTextDocumentEngine, PapyrusComicDocumentView, type PapyrusComicDocumentViewProps, PapyrusPageView, type PapyrusPageViewProps, PapyrusPdfDocumentView, PapyrusPdfViewerView, type PapyrusPdfViewerViewProps, PapyrusTextDocumentView, type PapyrusTextDocumentViewProps, type PapyrusThumbnail, type PapyrusThumbnailOptions, WebViewDocumentEngine, type WebViewRuntimeConfig, type WebViewRuntimeSource, generateThumbnail, isPapyrusComicDocumentViewAvailable, isPapyrusPdfDocumentViewAvailable, isPapyrusTablet, isPapyrusTextDocumentViewAvailable, isThumbnailGenerationSupported };
package/dist/index.js CHANGED
@@ -29,10 +29,12 @@ __export(engine_native_exports, {
29
29
  PapyrusPdfViewerView: () => PapyrusPdfViewerView,
30
30
  PapyrusTextDocumentView: () => PapyrusTextDocumentView,
31
31
  WebViewDocumentEngine: () => WebViewDocumentEngine,
32
+ generateThumbnail: () => generateThumbnail,
32
33
  isPapyrusComicDocumentViewAvailable: () => isPapyrusComicDocumentViewAvailable,
33
34
  isPapyrusPdfDocumentViewAvailable: () => isPapyrusPdfDocumentViewAvailable,
34
35
  isPapyrusTablet: () => isPapyrusTablet,
35
- isPapyrusTextDocumentViewAvailable: () => isPapyrusTextDocumentViewAvailable
36
+ isPapyrusTextDocumentViewAvailable: () => isPapyrusTextDocumentViewAvailable,
37
+ isThumbnailGenerationSupported: () => isThumbnailGenerationSupported
36
38
  });
37
39
  module.exports = __toCommonJS(engine_native_exports);
38
40
  var import_react_native = require("react-native");
@@ -252,6 +254,22 @@ var resolveNativeModule = () => {
252
254
  });
253
255
  };
254
256
  var cachedAndroidTabletFormFactor;
257
+ var isThumbnailGenerationSupported = () => import_react_native.Platform.OS === "android" && typeof resolveNativeModule()?.generateThumbnail === "function";
258
+ async function generateThumbnail(options) {
259
+ if (!isThumbnailGenerationSupported()) {
260
+ throw new Error("[Papyrus] generateThumbnail is not available on this platform or build.");
261
+ }
262
+ if (/^https?:/i.test(options.uri)) {
263
+ throw new Error("[Papyrus] generateThumbnail needs a local document.");
264
+ }
265
+ return resolveNativeModule().generateThumbnail({
266
+ pageIndex: 0,
267
+ maxWidth: 480,
268
+ format: "jpeg",
269
+ quality: 85,
270
+ ...options
271
+ });
272
+ }
255
273
  var isPapyrusTablet = () => {
256
274
  if (import_react_native.Platform.OS === "ios") return import_react_native.Platform.isPad;
257
275
  if (import_react_native.Platform.OS !== "android") return false;
@@ -478,6 +496,19 @@ var NativeDocumentEngine = class extends import_core.BaseDocumentEngine {
478
496
  if (!normalized || normalized.kind !== "named") return null;
479
497
  return native.getPageIndex(this.engineId, normalized);
480
498
  }
499
+ /**
500
+ * Releases the native document (file, pages, parser caches) while the
501
+ * reader is not on screen. Position, zoom and everything the app keeps
502
+ * (progress, annotations) are untouched; call `resume()` before using the
503
+ * engine again. Resolves false where the platform has nothing to release.
504
+ */
505
+ async suspend() {
506
+ return await this.nativeModule?.suspendDocument?.(this.engineId) ?? false;
507
+ }
508
+ /** Reopens a document released by `suspend()`. Safe to call when it is already open. */
509
+ async resume() {
510
+ return await this.nativeModule?.resumeDocument?.(this.engineId) ?? false;
511
+ }
481
512
  destroy() {
482
513
  this.nativeModule?.destroyEngine?.(this.engineId);
483
514
  }
@@ -1349,6 +1380,17 @@ var MobileDocumentEngine = class extends import_core.BaseDocumentEngine {
1349
1380
  ...this.webEngine.getLifecycleStats()
1350
1381
  };
1351
1382
  }
1383
+ /**
1384
+ * Releases the native PDF document while the reader is not on screen, and
1385
+ * reopens it. Only the PDF engine holds a native document; for the other
1386
+ * formats both resolve false and nothing changes.
1387
+ */
1388
+ async suspend() {
1389
+ return this.activeEngine === this.pdfEngine ? this.pdfEngine.suspend() : false;
1390
+ }
1391
+ async resume() {
1392
+ return this.activeEngine === this.pdfEngine ? this.pdfEngine.resume() : false;
1393
+ }
1352
1394
  resolveAnnotationTextRange(annotation) {
1353
1395
  return this.textEngine.resolveAnnotationTextRange(annotation);
1354
1396
  }
@@ -1488,9 +1530,11 @@ var MobileDocumentEngine = class extends import_core.BaseDocumentEngine {
1488
1530
  PapyrusPdfViewerView,
1489
1531
  PapyrusTextDocumentView,
1490
1532
  WebViewDocumentEngine,
1533
+ generateThumbnail,
1491
1534
  isPapyrusComicDocumentViewAvailable,
1492
1535
  isPapyrusPdfDocumentViewAvailable,
1493
1536
  isPapyrusTablet,
1494
- isPapyrusTextDocumentViewAvailable
1537
+ isPapyrusTextDocumentViewAvailable,
1538
+ isThumbnailGenerationSupported
1495
1539
  });
1496
1540
  //# sourceMappingURL=index.js.map