@papyrus-sdk/engine-native 0.2.17 → 0.2.19

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/dist/index.mjs CHANGED
@@ -6,12 +6,70 @@ import {
6
6
  requireNativeComponent,
7
7
  View
8
8
  } from "react-native";
9
- import { requireNativeViewManager } from "expo-modules-core/src/NativeViewManagerAdapter";
10
- import { requireOptionalNativeModule } from "expo-modules-core/src/requireNativeModule";
11
9
  import { BaseDocumentEngine, papyrusEvents } from "@papyrus-sdk/core";
12
10
  import {
13
11
  PapyrusEventType
14
12
  } from "@papyrus-sdk/types";
13
+
14
+ // documentType.ts
15
+ var parseDataUri = (value) => {
16
+ const match = /^data:([^;,]+)?(;base64)?,(.*)$/.exec(value);
17
+ if (!match) return null;
18
+ return {
19
+ mime: match[1] ?? "",
20
+ isBase64: Boolean(match[2]),
21
+ data: match[3] ?? ""
22
+ };
23
+ };
24
+ var typeFromExtension = (value) => {
25
+ const clean = value.split("?")[0].split("#")[0].toLowerCase();
26
+ const extension = clean.includes(".") ? clean.split(".").pop() : void 0;
27
+ if (extension === "epub") return "epub";
28
+ if (extension === "txt") return "text";
29
+ if (extension === "pdf") return "pdf";
30
+ if (extension === "cbz" || extension === "cbr") return "comic";
31
+ return null;
32
+ };
33
+ var inferComicFormat = (source) => {
34
+ const candidate = typeof source === "string" ? source : typeof source === "object" && source !== null && "uri" in source ? source.uri : "";
35
+ const dataUri = parseDataUri(candidate);
36
+ const mime = dataUri?.mime.toLowerCase() ?? "";
37
+ if (mime.includes("rar") || /\.cbr(?:$|[?#])/i.test(candidate)) {
38
+ return "cbr";
39
+ }
40
+ return "cbz";
41
+ };
42
+ var resolveComicFormat = (source, explicitFormat) => explicitFormat ?? inferComicFormat(source);
43
+ var inferDocumentType = (source) => {
44
+ if (typeof source === "string") {
45
+ const dataUri = parseDataUri(source);
46
+ if (dataUri?.mime) {
47
+ const mime = dataUri.mime.toLowerCase();
48
+ if (mime.includes("epub")) return "epub";
49
+ if (mime.includes("comicbook") || mime.includes("zip") || mime.includes("rar")) {
50
+ return "comic";
51
+ }
52
+ if (mime.includes("text")) return "text";
53
+ if (mime.includes("pdf")) return "pdf";
54
+ }
55
+ return typeFromExtension(source) ?? "pdf";
56
+ }
57
+ if (typeof source === "object" && source !== null && "uri" in source) {
58
+ return typeFromExtension(source.uri) ?? "pdf";
59
+ }
60
+ return "pdf";
61
+ };
62
+
63
+ // nativeModuleResolution.ts
64
+ var resolvePapyrusNativeModule = (registries) => {
65
+ const turboModule = registries.turboModuleRegistry.get(
66
+ "PapyrusNativeEngine"
67
+ );
68
+ if (turboModule) return turboModule;
69
+ return registries.nativeModules.PapyrusNativeEngine ?? null;
70
+ };
71
+
72
+ // index.ts
15
73
  var MODULE_NAME = "PapyrusNativeEngine";
16
74
  var BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
17
75
  var BASE64_LOOKUP = (() => {
@@ -22,7 +80,7 @@ var BASE64_LOOKUP = (() => {
22
80
  }
23
81
  return table;
24
82
  })();
25
- var parseDataUri = (value) => {
83
+ var parseDataUri2 = (value) => {
26
84
  const match = /^data:([^;,]+)?(;base64)?,(.*)$/.exec(value);
27
85
  if (!match) return null;
28
86
  return {
@@ -31,7 +89,7 @@ var parseDataUri = (value) => {
31
89
  data: match[3] ?? ""
32
90
  };
33
91
  };
34
- var looksLikeUri = (value) => value.startsWith("http://") || value.startsWith("https://") || value.startsWith("/") || value.startsWith("./") || value.startsWith("../") || value.startsWith("file://");
92
+ var looksLikeUri = (value) => value.startsWith("http://") || value.startsWith("https://") || value.startsWith("/") || value.startsWith("./") || value.startsWith("../") || value.startsWith("file://") || value.startsWith("content://") || value.startsWith("android.resource://");
35
93
  var isLikelyBase64 = (value) => {
36
94
  if (looksLikeUri(value)) return false;
37
95
  if (value.includes(".")) return false;
@@ -39,6 +97,15 @@ var isLikelyBase64 = (value) => {
39
97
  return /^[A-Za-z0-9+/=]+$/.test(value);
40
98
  };
41
99
  var isHttpUri = (value) => value.startsWith("http://") || value.startsWith("https://");
100
+ var isMetroAssetUri = (value) => {
101
+ try {
102
+ const url = new URL(value);
103
+ return (url.protocol === "http:" || url.protocol === "https:") && url.pathname.startsWith("/assets/") && url.searchParams.has("platform") && url.searchParams.has("hash");
104
+ } catch {
105
+ return false;
106
+ }
107
+ };
108
+ var isLocalUri = (value) => value.startsWith("content://") || value.startsWith("file://") || value.startsWith("android.resource://");
42
109
  var decodeBase64 = (value) => {
43
110
  const clean = value.replace(/[^A-Za-z0-9+/=]/g, "");
44
111
  const padding = clean.endsWith("==") ? 2 : clean.endsWith("=") ? 1 : 0;
@@ -82,33 +149,7 @@ var encodeBase64 = (bytes) => {
82
149
  return output;
83
150
  };
84
151
  var isLoadRequest = (input) => typeof input === "object" && input !== null && "source" in input && "type" in input;
85
- var normalizeLoadInput = (input) => isLoadRequest(input) ? { source: input.source, type: input.type } : { source: input };
86
- var inferDocumentType = (source) => {
87
- if (typeof source === "string") {
88
- const dataUri = parseDataUri(source);
89
- if (dataUri?.mime) {
90
- const mime = dataUri.mime.toLowerCase();
91
- if (mime.includes("epub")) return "epub";
92
- if (mime.includes("text")) return "text";
93
- if (mime.includes("pdf")) return "pdf";
94
- }
95
- const clean = source.split("?")[0].split("#")[0];
96
- const ext = clean.includes(".") ? clean.split(".").pop()?.toLowerCase() : void 0;
97
- if (ext === "epub") return "epub";
98
- if (ext === "txt") return "text";
99
- if (ext === "pdf") return "pdf";
100
- return "pdf";
101
- }
102
- if (typeof source === "object" && source !== null && "uri" in source) {
103
- const uri = source.uri;
104
- const clean = uri.split("?")[0].split("#")[0];
105
- const ext = clean.includes(".") ? clean.split(".").pop()?.toLowerCase() : void 0;
106
- if (ext === "epub") return "epub";
107
- if (ext === "txt") return "text";
108
- if (ext === "pdf") return "pdf";
109
- }
110
- return "pdf";
111
- };
152
+ var normalizeLoadInput = (input) => isLoadRequest(input) ? { source: input.source, type: input.type, format: input.format } : { source: input };
112
153
  var normalizeNativeDestination = (dest) => {
113
154
  if (!dest) return null;
114
155
  if (typeof dest === "string") {
@@ -120,14 +161,10 @@ var normalizeNativeDestination = (dest) => {
120
161
  return null;
121
162
  };
122
163
  var resolveNativeModule = () => {
123
- const expoModule = requireOptionalNativeModule(MODULE_NAME);
124
- if (expoModule) return expoModule;
125
- const turboModule = TurboModuleRegistry.get(
126
- MODULE_NAME
127
- );
128
- if (turboModule) return turboModule;
129
- const rnModule = NativeModules[MODULE_NAME];
130
- return rnModule ?? null;
164
+ return resolvePapyrusNativeModule({
165
+ nativeModules: NativeModules,
166
+ turboModuleRegistry: TurboModuleRegistry
167
+ });
131
168
  };
132
169
  var resolvePapyrusPageView = () => {
133
170
  try {
@@ -135,13 +172,7 @@ var resolvePapyrusPageView = () => {
135
172
  "PapyrusPageView"
136
173
  );
137
174
  } catch {
138
- try {
139
- return requireNativeViewManager(
140
- "PapyrusPageView"
141
- );
142
- } catch {
143
- return View;
144
- }
175
+ return View;
145
176
  }
146
177
  };
147
178
  var resolvePapyrusPdfViewerView = () => {
@@ -151,13 +182,7 @@ var resolvePapyrusPdfViewerView = () => {
151
182
  componentName
152
183
  );
153
184
  } catch {
154
- try {
155
- return requireNativeViewManager(
156
- componentName
157
- );
158
- } catch {
159
- return View;
160
- }
185
+ return View;
161
186
  }
162
187
  };
163
188
  var PapyrusPageView = resolvePapyrusPageView();
@@ -172,6 +197,7 @@ var NativeDocumentEngine = class extends BaseDocumentEngine {
172
197
  this.currentPage = 1;
173
198
  this.zoom = 1;
174
199
  this.rotation = 0;
200
+ this.renderRequestCounter = 0;
175
201
  this.nativeModule = resolveNativeModule();
176
202
  this.engineId = this.nativeModule?.createEngine ? this.nativeModule.createEngine() : "default";
177
203
  }
@@ -184,7 +210,17 @@ var NativeDocumentEngine = class extends BaseDocumentEngine {
184
210
  }
185
211
  const native = this.assertNativeModule();
186
212
  const normalized = await this.normalizeSource(source);
187
- const result = native.load ? await native.load(this.engineId, normalized) : void 0;
213
+ let result;
214
+ try {
215
+ result = native.load ? await native.load(this.engineId, normalized) : void 0;
216
+ } catch (error) {
217
+ const message = error instanceof Error ? error.message : String(error);
218
+ if (!/engine not found|papyrus_no_engine/i.test(message) || !native.createEngine) {
219
+ throw error;
220
+ }
221
+ this.engineId = native.createEngine();
222
+ result = native.load ? await native.load(this.engineId, normalized) : void 0;
223
+ }
188
224
  if (result && typeof result.pageCount === "number") {
189
225
  this.pageCount = result.pageCount;
190
226
  } else if (native.getPageCount) {
@@ -197,6 +233,9 @@ var NativeDocumentEngine = class extends BaseDocumentEngine {
197
233
  getPageCount() {
198
234
  return this.pageCount;
199
235
  }
236
+ getLifecycleStats() {
237
+ return this.nativeModule?.getLifecycleStats?.() ?? {};
238
+ }
200
239
  getCurrentPage() {
201
240
  return this.currentPage;
202
241
  }
@@ -225,18 +264,21 @@ var NativeDocumentEngine = class extends BaseDocumentEngine {
225
264
  getNativeEngineId() {
226
265
  return this.engineId;
227
266
  }
228
- async renderPage(pageIndex, target, scale) {
267
+ async renderPage(pageIndex, target, scale, telemetry) {
229
268
  const native = this.assertNativeModule();
230
269
  if (!native.renderPage) return;
231
270
  const viewTag = this.toNativeViewTag(target);
232
271
  if (viewTag === null) return;
233
- native.renderPage(
272
+ const requestId = `native-render-${++this.renderRequestCounter}`;
273
+ return native.renderPage(
234
274
  this.engineId,
235
275
  pageIndex,
236
276
  viewTag,
237
277
  scale,
238
278
  this.zoom,
239
- this.rotation
279
+ this.rotation,
280
+ requestId,
281
+ telemetry
240
282
  );
241
283
  }
242
284
  async renderTextLayer(pageIndex, target, scale) {
@@ -313,7 +355,7 @@ var NativeDocumentEngine = class extends BaseDocumentEngine {
313
355
  }
314
356
  async normalizeSource(source) {
315
357
  if (typeof source === "string") {
316
- const dataUri = parseDataUri(source);
358
+ const dataUri = parseDataUri2(source);
317
359
  if (dataUri?.isBase64) {
318
360
  return { data: decodeBase64(dataUri.data) };
319
361
  }
@@ -351,8 +393,8 @@ var NativeDocumentEngine = class extends BaseDocumentEngine {
351
393
  }
352
394
  };
353
395
  var WebViewDocumentEngine = class extends BaseDocumentEngine {
354
- constructor() {
355
- super(...arguments);
396
+ constructor(options = {}) {
397
+ super();
356
398
  this.bridge = null;
357
399
  this.ready = false;
358
400
  this.requestId = 0;
@@ -364,15 +406,41 @@ var WebViewDocumentEngine = class extends BaseDocumentEngine {
364
406
  this.zoom = 1;
365
407
  this.rotation = 0;
366
408
  this.outline = [];
409
+ this.webViewRuntimeSource = options.webViewRuntimeSource;
410
+ this.webViewRuntimeConfig = options.webViewRuntimeConfig;
411
+ }
412
+ getWebViewRuntimeSource() {
413
+ return this.webViewRuntimeSource;
414
+ }
415
+ getWebViewRuntimeConfig() {
416
+ return this.webViewRuntimeConfig;
367
417
  }
368
418
  getRenderTargetType() {
369
419
  return "webview";
370
420
  }
421
+ getLifecycleStats() {
422
+ return {
423
+ webViewCount: this.bridge ? 1 : 0,
424
+ pendingBridgeRequests: this.pending.size
425
+ };
426
+ }
371
427
  attachBridge(bridge) {
372
428
  this.bridge = bridge;
373
- this.bridgeResolvers.forEach((resolve) => resolve(bridge));
429
+ this.ready = false;
430
+ this.bridgeResolvers.forEach(({ resolve }) => resolve(bridge));
374
431
  this.bridgeResolvers = [];
375
432
  }
433
+ detachBridge() {
434
+ const error = new Error("[Papyrus] WebView detached");
435
+ this.pending.forEach(({ reject }) => reject(error));
436
+ this.pending.clear();
437
+ this.bridgeResolvers.forEach(({ reject }) => reject(error));
438
+ this.readyResolvers.forEach(({ reject }) => reject(error));
439
+ this.bridgeResolvers = [];
440
+ this.readyResolvers = [];
441
+ this.bridge = null;
442
+ this.ready = false;
443
+ }
376
444
  handleMessage(raw) {
377
445
  let message = null;
378
446
  try {
@@ -381,9 +449,17 @@ var WebViewDocumentEngine = class extends BaseDocumentEngine {
381
449
  return;
382
450
  }
383
451
  if (!message) return;
452
+ if (message.type === "asset-request") {
453
+ void this.handleAssetRequest(message);
454
+ return;
455
+ }
456
+ if (message.type === "file-chunk-request") {
457
+ void this.handleFileChunkRequest(message);
458
+ return;
459
+ }
384
460
  if (message.type === "ready") {
385
461
  this.ready = true;
386
- this.readyResolvers.forEach((resolve) => resolve());
462
+ this.readyResolvers.forEach(({ resolve }) => resolve());
387
463
  this.readyResolvers = [];
388
464
  return;
389
465
  }
@@ -446,8 +522,73 @@ var WebViewDocumentEngine = class extends BaseDocumentEngine {
446
522
  console.warn("[Papyrus WebView] Unknown message", message);
447
523
  }
448
524
  }
525
+ async handleAssetRequest(message) {
526
+ const bridge = this.bridge;
527
+ if (!bridge) return;
528
+ try {
529
+ const response = await fetch(message.url);
530
+ if (!response.ok) {
531
+ throw new Error(`status ${response.status}`);
532
+ }
533
+ const data = message.encoding === "text" ? await response.text() : `data:application/wasm;base64,${encodeBase64(
534
+ new Uint8Array(await response.arrayBuffer())
535
+ )}`;
536
+ bridge.postMessage(
537
+ JSON.stringify({
538
+ type: "asset-response",
539
+ id: message.id,
540
+ ok: true,
541
+ data
542
+ })
543
+ );
544
+ } catch (error) {
545
+ const reason = error instanceof Error ? error.message : String(error);
546
+ bridge.postMessage(
547
+ JSON.stringify({
548
+ type: "asset-response",
549
+ id: message.id,
550
+ ok: false,
551
+ error: reason
552
+ })
553
+ );
554
+ }
555
+ }
556
+ async handleFileChunkRequest(message) {
557
+ const bridge = this.bridge;
558
+ if (!bridge) return;
559
+ try {
560
+ const nativeModule = resolveNativeModule();
561
+ if (!nativeModule?.readFileChunk) {
562
+ throw new Error("Leitura nativa de arquivos n\xE3o est\xE1 dispon\xEDvel");
563
+ }
564
+ const result = await nativeModule.readFileChunk(
565
+ message.uri,
566
+ message.offset,
567
+ message.length
568
+ );
569
+ bridge.postMessage(
570
+ JSON.stringify({
571
+ type: "file-chunk-response",
572
+ id: message.id,
573
+ ok: true,
574
+ data: result.data,
575
+ done: result.done
576
+ })
577
+ );
578
+ } catch (error) {
579
+ const reason = error instanceof Error ? error.message : String(error);
580
+ bridge.postMessage(
581
+ JSON.stringify({
582
+ type: "file-chunk-response",
583
+ id: message.id,
584
+ ok: false,
585
+ error: reason
586
+ })
587
+ );
588
+ }
589
+ }
449
590
  async load(input) {
450
- const { source, type } = normalizeLoadInput(input);
591
+ const { source, type, format } = normalizeLoadInput(input);
451
592
  const resolvedType = type ?? inferDocumentType(source);
452
593
  if (resolvedType === "pdf") {
453
594
  throw new Error(
@@ -460,7 +601,8 @@ var WebViewDocumentEngine = class extends BaseDocumentEngine {
460
601
  );
461
602
  const response = await this.request("load", {
462
603
  type: resolvedType,
463
- source: payloadSource
604
+ source: payloadSource,
605
+ ...resolvedType === "comic" ? { format: resolveComicFormat(source, format) } : {}
464
606
  });
465
607
  if (typeof response?.pageCount === "number")
466
608
  this.pageCount = response.pageCount;
@@ -497,7 +639,7 @@ var WebViewDocumentEngine = class extends BaseDocumentEngine {
497
639
  getRotation() {
498
640
  return this.rotation;
499
641
  }
500
- async renderPage(pageIndex, target, scale) {
642
+ async renderPage(pageIndex, target, scale, _telemetry) {
501
643
  }
502
644
  async renderTextLayer(pageIndex, container, scale) {
503
645
  }
@@ -510,6 +652,11 @@ var WebViewDocumentEngine = class extends BaseDocumentEngine {
510
652
  { pageIndex }
511
653
  );
512
654
  }
655
+ async getPagePreview(pageIndex) {
656
+ return await this.request("get-page-preview", {
657
+ pageIndex
658
+ });
659
+ }
513
660
  async searchText(query) {
514
661
  return await this.request("search-text", { query });
515
662
  }
@@ -538,23 +685,18 @@ var WebViewDocumentEngine = class extends BaseDocumentEngine {
538
685
  return await this.request("get-page-index", { dest });
539
686
  }
540
687
  destroy() {
541
- this.pending.forEach(
542
- ({ reject }) => reject(new Error("[Papyrus] WebView engine destroyed"))
543
- );
544
- this.pending.clear();
545
- this.bridge = null;
546
- this.ready = false;
688
+ this.detachBridge();
547
689
  }
548
690
  async ensureBridge() {
549
691
  if (this.bridge) return this.bridge;
550
- return new Promise((resolve) => {
551
- this.bridgeResolvers.push(resolve);
692
+ return new Promise((resolve, reject) => {
693
+ this.bridgeResolvers.push({ resolve, reject });
552
694
  });
553
695
  }
554
696
  async ensureReady() {
555
697
  if (this.ready) return;
556
- return new Promise((resolve) => {
557
- this.readyResolvers.push(resolve);
698
+ return new Promise((resolve, reject) => {
699
+ this.readyResolvers.push({ resolve, reject });
558
700
  });
559
701
  }
560
702
  async request(kind, payload) {
@@ -562,7 +704,7 @@ var WebViewDocumentEngine = class extends BaseDocumentEngine {
562
704
  await this.ensureReady();
563
705
  const id = `${Date.now()}-${this.requestId++}`;
564
706
  return new Promise((resolve, reject) => {
565
- const timeoutMs = kind === "load" ? 18e4 : 8e3;
707
+ const timeoutMs = kind === "load" ? 18e4 : kind === "get-page-preview" ? 3e4 : 8e3;
566
708
  const timeoutId = setTimeout(() => {
567
709
  this.pending.delete(id);
568
710
  reject(new Error(`[Papyrus] WebView response timeout: ${kind}`));
@@ -582,7 +724,7 @@ var WebViewDocumentEngine = class extends BaseDocumentEngine {
582
724
  }
583
725
  async normalizeRuntimeSource(type, source) {
584
726
  if (typeof source === "string") {
585
- const dataUri = parseDataUri(source);
727
+ const dataUri = parseDataUri2(source);
586
728
  if (dataUri) {
587
729
  if (dataUri.isBase64) {
588
730
  return {
@@ -595,10 +737,16 @@ var WebViewDocumentEngine = class extends BaseDocumentEngine {
595
737
  return { kind: "text", text };
596
738
  }
597
739
  if (looksLikeUri(source)) {
740
+ if (isMetroAssetUri(source)) {
741
+ return { kind: "uri", uri: source };
742
+ }
598
743
  if (isHttpUri(source)) {
599
744
  const fetched = await this.fetchRemoteSource(type, source);
600
745
  if (fetched) return fetched;
601
746
  }
747
+ if (isLocalUri(source)) {
748
+ return await this.fetchLocalSource(type, source);
749
+ }
602
750
  return { kind: "uri", uri: source };
603
751
  }
604
752
  if (isLikelyBase64(source)) {
@@ -611,10 +759,27 @@ var WebViewDocumentEngine = class extends BaseDocumentEngine {
611
759
  }
612
760
  if (this.isUriSource(source)) {
613
761
  const uri = source.uri;
762
+ const dataUri = parseDataUri2(uri);
763
+ if (dataUri) {
764
+ if (dataUri.isBase64) {
765
+ return {
766
+ kind: "base64",
767
+ data: dataUri.data,
768
+ mime: dataUri.mime || void 0
769
+ };
770
+ }
771
+ return { kind: "text", text: decodeURIComponent(dataUri.data) };
772
+ }
773
+ if (isMetroAssetUri(uri)) {
774
+ return { kind: "uri", uri };
775
+ }
614
776
  if (isHttpUri(uri)) {
615
777
  const fetched = await this.fetchRemoteSource(type, uri);
616
778
  if (fetched) return fetched;
617
779
  }
780
+ if (isLocalUri(uri)) {
781
+ return await this.fetchLocalSource(type, uri);
782
+ }
618
783
  return { kind: "uri", uri };
619
784
  }
620
785
  if (this.isDataSource(source)) {
@@ -646,11 +811,35 @@ var WebViewDocumentEngine = class extends BaseDocumentEngine {
646
811
  const buffer = await this.readResponseBuffer(response);
647
812
  return { kind: "base64", data: encodeBase64(new Uint8Array(buffer)) };
648
813
  }
814
+ if (type === "comic") {
815
+ const buffer = await this.readResponseBuffer(response);
816
+ return { kind: "base64", data: encodeBase64(new Uint8Array(buffer)) };
817
+ }
649
818
  return null;
650
819
  } catch {
651
820
  return null;
652
821
  }
653
822
  }
823
+ async fetchLocalSource(type, uri) {
824
+ if (type === "epub" || type === "comic") {
825
+ return { kind: "uri", uri };
826
+ }
827
+ try {
828
+ const response = await fetch(uri);
829
+ if (!response.ok && response.status !== 0) {
830
+ throw new Error(`status ${response.status}`);
831
+ }
832
+ if (type === "text") {
833
+ return { kind: "text", text: await response.text() };
834
+ }
835
+ throw new Error(`tipo n\xE3o suportado: ${type}`);
836
+ } catch (error) {
837
+ const reason = error instanceof Error ? `: ${error.message}` : "";
838
+ throw new Error(
839
+ `[WebViewDocumentEngine] N\xE3o foi poss\xEDvel ler o arquivo local ${uri}${reason}`
840
+ );
841
+ }
842
+ }
654
843
  async readResponseBuffer(response) {
655
844
  try {
656
845
  return await response.arrayBuffer();
@@ -675,29 +864,48 @@ var WebViewDocumentEngine = class extends BaseDocumentEngine {
675
864
  }
676
865
  };
677
866
  var MobileDocumentEngine = class extends BaseDocumentEngine {
678
- constructor() {
867
+ constructor(options = {}) {
679
868
  super();
680
869
  this.pdfEngine = new NativeDocumentEngine();
681
- this.webEngine = new WebViewDocumentEngine();
870
+ this.webEngine = new WebViewDocumentEngine(options);
682
871
  this.activeEngine = this.pdfEngine;
683
872
  }
873
+ getWebViewRuntimeSource() {
874
+ return this.webEngine.getWebViewRuntimeSource();
875
+ }
876
+ getWebViewRuntimeConfig() {
877
+ return this.webEngine.getWebViewRuntimeConfig();
878
+ }
684
879
  getRenderTargetType() {
685
880
  return this.activeEngine.getRenderTargetType?.() ?? "canvas";
686
881
  }
687
882
  getNativeEngineId() {
688
883
  return this.activeEngine === this.pdfEngine ? this.pdfEngine.getNativeEngineId() : null;
689
884
  }
885
+ getLifecycleStats() {
886
+ return {
887
+ ...this.pdfEngine.getLifecycleStats(),
888
+ ...this.webEngine.getLifecycleStats()
889
+ };
890
+ }
690
891
  attachWebView(bridge) {
691
892
  this.webEngine.attachBridge(bridge);
692
893
  }
894
+ detachWebView() {
895
+ this.webEngine.detachBridge();
896
+ }
693
897
  handleWebViewMessage(data) {
694
898
  this.webEngine.handleMessage(data);
695
899
  }
696
900
  async load(input) {
697
- const { source, type } = normalizeLoadInput(input);
901
+ const { source, type, format } = normalizeLoadInput(input);
698
902
  const resolvedType = type ?? inferDocumentType(source);
699
903
  this.activeEngine = resolvedType === "pdf" ? this.pdfEngine : this.webEngine;
700
- await this.activeEngine.load({ type: resolvedType, source });
904
+ await this.activeEngine.load({
905
+ type: resolvedType,
906
+ source,
907
+ ...resolvedType === "comic" && format ? { format } : {}
908
+ });
701
909
  }
702
910
  getPageCount() {
703
911
  return this.activeEngine.getPageCount();
@@ -720,8 +928,8 @@ var MobileDocumentEngine = class extends BaseDocumentEngine {
720
928
  getRotation() {
721
929
  return this.activeEngine.getRotation();
722
930
  }
723
- async renderPage(pageIndex, target, scale) {
724
- await this.activeEngine.renderPage(pageIndex, target, scale);
931
+ async renderPage(pageIndex, target, scale, telemetry) {
932
+ await this.activeEngine.renderPage(pageIndex, target, scale, telemetry);
725
933
  }
726
934
  async renderTextLayer(pageIndex, container, scale) {
727
935
  await this.activeEngine.renderTextLayer(pageIndex, container, scale);
@@ -732,6 +940,10 @@ var MobileDocumentEngine = class extends BaseDocumentEngine {
732
940
  async getPageDimensions(pageIndex) {
733
941
  return await this.activeEngine.getPageDimensions(pageIndex);
734
942
  }
943
+ async getPagePreview(pageIndex) {
944
+ const engine = this.activeEngine;
945
+ return await engine.getPagePreview?.(pageIndex) ?? null;
946
+ }
735
947
  async searchText(query) {
736
948
  if (typeof this.activeEngine.searchText === "function") {
737
949
  return await this.activeEngine.searchText(query);