@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.js CHANGED
@@ -28,10 +28,68 @@ __export(engine_native_exports, {
28
28
  });
29
29
  module.exports = __toCommonJS(engine_native_exports);
30
30
  var import_react_native = require("react-native");
31
- var import_NativeViewManagerAdapter = require("expo-modules-core/src/NativeViewManagerAdapter");
32
- var import_requireNativeModule = require("expo-modules-core/src/requireNativeModule");
33
31
  var import_core = require("@papyrus-sdk/core");
34
32
  var import_types = require("@papyrus-sdk/types");
33
+
34
+ // documentType.ts
35
+ var parseDataUri = (value) => {
36
+ const match = /^data:([^;,]+)?(;base64)?,(.*)$/.exec(value);
37
+ if (!match) return null;
38
+ return {
39
+ mime: match[1] ?? "",
40
+ isBase64: Boolean(match[2]),
41
+ data: match[3] ?? ""
42
+ };
43
+ };
44
+ var typeFromExtension = (value) => {
45
+ const clean = value.split("?")[0].split("#")[0].toLowerCase();
46
+ const extension = clean.includes(".") ? clean.split(".").pop() : void 0;
47
+ if (extension === "epub") return "epub";
48
+ if (extension === "txt") return "text";
49
+ if (extension === "pdf") return "pdf";
50
+ if (extension === "cbz" || extension === "cbr") return "comic";
51
+ return null;
52
+ };
53
+ var inferComicFormat = (source) => {
54
+ const candidate = typeof source === "string" ? source : typeof source === "object" && source !== null && "uri" in source ? source.uri : "";
55
+ const dataUri = parseDataUri(candidate);
56
+ const mime = dataUri?.mime.toLowerCase() ?? "";
57
+ if (mime.includes("rar") || /\.cbr(?:$|[?#])/i.test(candidate)) {
58
+ return "cbr";
59
+ }
60
+ return "cbz";
61
+ };
62
+ var resolveComicFormat = (source, explicitFormat) => explicitFormat ?? inferComicFormat(source);
63
+ var inferDocumentType = (source) => {
64
+ if (typeof source === "string") {
65
+ const dataUri = parseDataUri(source);
66
+ if (dataUri?.mime) {
67
+ const mime = dataUri.mime.toLowerCase();
68
+ if (mime.includes("epub")) return "epub";
69
+ if (mime.includes("comicbook") || mime.includes("zip") || mime.includes("rar")) {
70
+ return "comic";
71
+ }
72
+ if (mime.includes("text")) return "text";
73
+ if (mime.includes("pdf")) return "pdf";
74
+ }
75
+ return typeFromExtension(source) ?? "pdf";
76
+ }
77
+ if (typeof source === "object" && source !== null && "uri" in source) {
78
+ return typeFromExtension(source.uri) ?? "pdf";
79
+ }
80
+ return "pdf";
81
+ };
82
+
83
+ // nativeModuleResolution.ts
84
+ var resolvePapyrusNativeModule = (registries) => {
85
+ const turboModule = registries.turboModuleRegistry.get(
86
+ "PapyrusNativeEngine"
87
+ );
88
+ if (turboModule) return turboModule;
89
+ return registries.nativeModules.PapyrusNativeEngine ?? null;
90
+ };
91
+
92
+ // index.ts
35
93
  var MODULE_NAME = "PapyrusNativeEngine";
36
94
  var BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
37
95
  var BASE64_LOOKUP = (() => {
@@ -42,7 +100,7 @@ var BASE64_LOOKUP = (() => {
42
100
  }
43
101
  return table;
44
102
  })();
45
- var parseDataUri = (value) => {
103
+ var parseDataUri2 = (value) => {
46
104
  const match = /^data:([^;,]+)?(;base64)?,(.*)$/.exec(value);
47
105
  if (!match) return null;
48
106
  return {
@@ -51,7 +109,7 @@ var parseDataUri = (value) => {
51
109
  data: match[3] ?? ""
52
110
  };
53
111
  };
54
- var looksLikeUri = (value) => value.startsWith("http://") || value.startsWith("https://") || value.startsWith("/") || value.startsWith("./") || value.startsWith("../") || value.startsWith("file://");
112
+ 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://");
55
113
  var isLikelyBase64 = (value) => {
56
114
  if (looksLikeUri(value)) return false;
57
115
  if (value.includes(".")) return false;
@@ -59,6 +117,15 @@ var isLikelyBase64 = (value) => {
59
117
  return /^[A-Za-z0-9+/=]+$/.test(value);
60
118
  };
61
119
  var isHttpUri = (value) => value.startsWith("http://") || value.startsWith("https://");
120
+ var isMetroAssetUri = (value) => {
121
+ try {
122
+ const url = new URL(value);
123
+ return (url.protocol === "http:" || url.protocol === "https:") && url.pathname.startsWith("/assets/") && url.searchParams.has("platform") && url.searchParams.has("hash");
124
+ } catch {
125
+ return false;
126
+ }
127
+ };
128
+ var isLocalUri = (value) => value.startsWith("content://") || value.startsWith("file://") || value.startsWith("android.resource://");
62
129
  var decodeBase64 = (value) => {
63
130
  const clean = value.replace(/[^A-Za-z0-9+/=]/g, "");
64
131
  const padding = clean.endsWith("==") ? 2 : clean.endsWith("=") ? 1 : 0;
@@ -102,33 +169,7 @@ var encodeBase64 = (bytes) => {
102
169
  return output;
103
170
  };
104
171
  var isLoadRequest = (input) => typeof input === "object" && input !== null && "source" in input && "type" in input;
105
- var normalizeLoadInput = (input) => isLoadRequest(input) ? { source: input.source, type: input.type } : { source: input };
106
- var inferDocumentType = (source) => {
107
- if (typeof source === "string") {
108
- const dataUri = parseDataUri(source);
109
- if (dataUri?.mime) {
110
- const mime = dataUri.mime.toLowerCase();
111
- if (mime.includes("epub")) return "epub";
112
- if (mime.includes("text")) return "text";
113
- if (mime.includes("pdf")) return "pdf";
114
- }
115
- const clean = source.split("?")[0].split("#")[0];
116
- const ext = clean.includes(".") ? clean.split(".").pop()?.toLowerCase() : void 0;
117
- if (ext === "epub") return "epub";
118
- if (ext === "txt") return "text";
119
- if (ext === "pdf") return "pdf";
120
- return "pdf";
121
- }
122
- if (typeof source === "object" && source !== null && "uri" in source) {
123
- const uri = source.uri;
124
- const clean = uri.split("?")[0].split("#")[0];
125
- const ext = clean.includes(".") ? clean.split(".").pop()?.toLowerCase() : void 0;
126
- if (ext === "epub") return "epub";
127
- if (ext === "txt") return "text";
128
- if (ext === "pdf") return "pdf";
129
- }
130
- return "pdf";
131
- };
172
+ var normalizeLoadInput = (input) => isLoadRequest(input) ? { source: input.source, type: input.type, format: input.format } : { source: input };
132
173
  var normalizeNativeDestination = (dest) => {
133
174
  if (!dest) return null;
134
175
  if (typeof dest === "string") {
@@ -140,14 +181,10 @@ var normalizeNativeDestination = (dest) => {
140
181
  return null;
141
182
  };
142
183
  var resolveNativeModule = () => {
143
- const expoModule = (0, import_requireNativeModule.requireOptionalNativeModule)(MODULE_NAME);
144
- if (expoModule) return expoModule;
145
- const turboModule = import_react_native.TurboModuleRegistry.get(
146
- MODULE_NAME
147
- );
148
- if (turboModule) return turboModule;
149
- const rnModule = import_react_native.NativeModules[MODULE_NAME];
150
- return rnModule ?? null;
184
+ return resolvePapyrusNativeModule({
185
+ nativeModules: import_react_native.NativeModules,
186
+ turboModuleRegistry: import_react_native.TurboModuleRegistry
187
+ });
151
188
  };
152
189
  var resolvePapyrusPageView = () => {
153
190
  try {
@@ -155,13 +192,7 @@ var resolvePapyrusPageView = () => {
155
192
  "PapyrusPageView"
156
193
  );
157
194
  } catch {
158
- try {
159
- return (0, import_NativeViewManagerAdapter.requireNativeViewManager)(
160
- "PapyrusPageView"
161
- );
162
- } catch {
163
- return import_react_native.View;
164
- }
195
+ return import_react_native.View;
165
196
  }
166
197
  };
167
198
  var resolvePapyrusPdfViewerView = () => {
@@ -171,13 +202,7 @@ var resolvePapyrusPdfViewerView = () => {
171
202
  componentName
172
203
  );
173
204
  } catch {
174
- try {
175
- return (0, import_NativeViewManagerAdapter.requireNativeViewManager)(
176
- componentName
177
- );
178
- } catch {
179
- return import_react_native.View;
180
- }
205
+ return import_react_native.View;
181
206
  }
182
207
  };
183
208
  var PapyrusPageView = resolvePapyrusPageView();
@@ -192,6 +217,7 @@ var NativeDocumentEngine = class extends import_core.BaseDocumentEngine {
192
217
  this.currentPage = 1;
193
218
  this.zoom = 1;
194
219
  this.rotation = 0;
220
+ this.renderRequestCounter = 0;
195
221
  this.nativeModule = resolveNativeModule();
196
222
  this.engineId = this.nativeModule?.createEngine ? this.nativeModule.createEngine() : "default";
197
223
  }
@@ -204,7 +230,17 @@ var NativeDocumentEngine = class extends import_core.BaseDocumentEngine {
204
230
  }
205
231
  const native = this.assertNativeModule();
206
232
  const normalized = await this.normalizeSource(source);
207
- const result = native.load ? await native.load(this.engineId, normalized) : void 0;
233
+ let result;
234
+ try {
235
+ result = native.load ? await native.load(this.engineId, normalized) : void 0;
236
+ } catch (error) {
237
+ const message = error instanceof Error ? error.message : String(error);
238
+ if (!/engine not found|papyrus_no_engine/i.test(message) || !native.createEngine) {
239
+ throw error;
240
+ }
241
+ this.engineId = native.createEngine();
242
+ result = native.load ? await native.load(this.engineId, normalized) : void 0;
243
+ }
208
244
  if (result && typeof result.pageCount === "number") {
209
245
  this.pageCount = result.pageCount;
210
246
  } else if (native.getPageCount) {
@@ -217,6 +253,9 @@ var NativeDocumentEngine = class extends import_core.BaseDocumentEngine {
217
253
  getPageCount() {
218
254
  return this.pageCount;
219
255
  }
256
+ getLifecycleStats() {
257
+ return this.nativeModule?.getLifecycleStats?.() ?? {};
258
+ }
220
259
  getCurrentPage() {
221
260
  return this.currentPage;
222
261
  }
@@ -245,18 +284,21 @@ var NativeDocumentEngine = class extends import_core.BaseDocumentEngine {
245
284
  getNativeEngineId() {
246
285
  return this.engineId;
247
286
  }
248
- async renderPage(pageIndex, target, scale) {
287
+ async renderPage(pageIndex, target, scale, telemetry) {
249
288
  const native = this.assertNativeModule();
250
289
  if (!native.renderPage) return;
251
290
  const viewTag = this.toNativeViewTag(target);
252
291
  if (viewTag === null) return;
253
- native.renderPage(
292
+ const requestId = `native-render-${++this.renderRequestCounter}`;
293
+ return native.renderPage(
254
294
  this.engineId,
255
295
  pageIndex,
256
296
  viewTag,
257
297
  scale,
258
298
  this.zoom,
259
- this.rotation
299
+ this.rotation,
300
+ requestId,
301
+ telemetry
260
302
  );
261
303
  }
262
304
  async renderTextLayer(pageIndex, target, scale) {
@@ -333,7 +375,7 @@ var NativeDocumentEngine = class extends import_core.BaseDocumentEngine {
333
375
  }
334
376
  async normalizeSource(source) {
335
377
  if (typeof source === "string") {
336
- const dataUri = parseDataUri(source);
378
+ const dataUri = parseDataUri2(source);
337
379
  if (dataUri?.isBase64) {
338
380
  return { data: decodeBase64(dataUri.data) };
339
381
  }
@@ -371,8 +413,8 @@ var NativeDocumentEngine = class extends import_core.BaseDocumentEngine {
371
413
  }
372
414
  };
373
415
  var WebViewDocumentEngine = class extends import_core.BaseDocumentEngine {
374
- constructor() {
375
- super(...arguments);
416
+ constructor(options = {}) {
417
+ super();
376
418
  this.bridge = null;
377
419
  this.ready = false;
378
420
  this.requestId = 0;
@@ -384,14 +426,40 @@ var WebViewDocumentEngine = class extends import_core.BaseDocumentEngine {
384
426
  this.zoom = 1;
385
427
  this.rotation = 0;
386
428
  this.outline = [];
429
+ this.webViewRuntimeSource = options.webViewRuntimeSource;
430
+ this.webViewRuntimeConfig = options.webViewRuntimeConfig;
431
+ }
432
+ getWebViewRuntimeSource() {
433
+ return this.webViewRuntimeSource;
434
+ }
435
+ getWebViewRuntimeConfig() {
436
+ return this.webViewRuntimeConfig;
387
437
  }
388
438
  getRenderTargetType() {
389
439
  return "webview";
390
440
  }
441
+ getLifecycleStats() {
442
+ return {
443
+ webViewCount: this.bridge ? 1 : 0,
444
+ pendingBridgeRequests: this.pending.size
445
+ };
446
+ }
391
447
  attachBridge(bridge) {
392
448
  this.bridge = bridge;
393
- this.bridgeResolvers.forEach((resolve) => resolve(bridge));
449
+ this.ready = false;
450
+ this.bridgeResolvers.forEach(({ resolve }) => resolve(bridge));
451
+ this.bridgeResolvers = [];
452
+ }
453
+ detachBridge() {
454
+ const error = new Error("[Papyrus] WebView detached");
455
+ this.pending.forEach(({ reject }) => reject(error));
456
+ this.pending.clear();
457
+ this.bridgeResolvers.forEach(({ reject }) => reject(error));
458
+ this.readyResolvers.forEach(({ reject }) => reject(error));
394
459
  this.bridgeResolvers = [];
460
+ this.readyResolvers = [];
461
+ this.bridge = null;
462
+ this.ready = false;
395
463
  }
396
464
  handleMessage(raw) {
397
465
  let message = null;
@@ -401,9 +469,17 @@ var WebViewDocumentEngine = class extends import_core.BaseDocumentEngine {
401
469
  return;
402
470
  }
403
471
  if (!message) return;
472
+ if (message.type === "asset-request") {
473
+ void this.handleAssetRequest(message);
474
+ return;
475
+ }
476
+ if (message.type === "file-chunk-request") {
477
+ void this.handleFileChunkRequest(message);
478
+ return;
479
+ }
404
480
  if (message.type === "ready") {
405
481
  this.ready = true;
406
- this.readyResolvers.forEach((resolve) => resolve());
482
+ this.readyResolvers.forEach(({ resolve }) => resolve());
407
483
  this.readyResolvers = [];
408
484
  return;
409
485
  }
@@ -466,8 +542,73 @@ var WebViewDocumentEngine = class extends import_core.BaseDocumentEngine {
466
542
  console.warn("[Papyrus WebView] Unknown message", message);
467
543
  }
468
544
  }
545
+ async handleAssetRequest(message) {
546
+ const bridge = this.bridge;
547
+ if (!bridge) return;
548
+ try {
549
+ const response = await fetch(message.url);
550
+ if (!response.ok) {
551
+ throw new Error(`status ${response.status}`);
552
+ }
553
+ const data = message.encoding === "text" ? await response.text() : `data:application/wasm;base64,${encodeBase64(
554
+ new Uint8Array(await response.arrayBuffer())
555
+ )}`;
556
+ bridge.postMessage(
557
+ JSON.stringify({
558
+ type: "asset-response",
559
+ id: message.id,
560
+ ok: true,
561
+ data
562
+ })
563
+ );
564
+ } catch (error) {
565
+ const reason = error instanceof Error ? error.message : String(error);
566
+ bridge.postMessage(
567
+ JSON.stringify({
568
+ type: "asset-response",
569
+ id: message.id,
570
+ ok: false,
571
+ error: reason
572
+ })
573
+ );
574
+ }
575
+ }
576
+ async handleFileChunkRequest(message) {
577
+ const bridge = this.bridge;
578
+ if (!bridge) return;
579
+ try {
580
+ const nativeModule = resolveNativeModule();
581
+ if (!nativeModule?.readFileChunk) {
582
+ throw new Error("Leitura nativa de arquivos n\xE3o est\xE1 dispon\xEDvel");
583
+ }
584
+ const result = await nativeModule.readFileChunk(
585
+ message.uri,
586
+ message.offset,
587
+ message.length
588
+ );
589
+ bridge.postMessage(
590
+ JSON.stringify({
591
+ type: "file-chunk-response",
592
+ id: message.id,
593
+ ok: true,
594
+ data: result.data,
595
+ done: result.done
596
+ })
597
+ );
598
+ } catch (error) {
599
+ const reason = error instanceof Error ? error.message : String(error);
600
+ bridge.postMessage(
601
+ JSON.stringify({
602
+ type: "file-chunk-response",
603
+ id: message.id,
604
+ ok: false,
605
+ error: reason
606
+ })
607
+ );
608
+ }
609
+ }
469
610
  async load(input) {
470
- const { source, type } = normalizeLoadInput(input);
611
+ const { source, type, format } = normalizeLoadInput(input);
471
612
  const resolvedType = type ?? inferDocumentType(source);
472
613
  if (resolvedType === "pdf") {
473
614
  throw new Error(
@@ -480,7 +621,8 @@ var WebViewDocumentEngine = class extends import_core.BaseDocumentEngine {
480
621
  );
481
622
  const response = await this.request("load", {
482
623
  type: resolvedType,
483
- source: payloadSource
624
+ source: payloadSource,
625
+ ...resolvedType === "comic" ? { format: resolveComicFormat(source, format) } : {}
484
626
  });
485
627
  if (typeof response?.pageCount === "number")
486
628
  this.pageCount = response.pageCount;
@@ -517,7 +659,7 @@ var WebViewDocumentEngine = class extends import_core.BaseDocumentEngine {
517
659
  getRotation() {
518
660
  return this.rotation;
519
661
  }
520
- async renderPage(pageIndex, target, scale) {
662
+ async renderPage(pageIndex, target, scale, _telemetry) {
521
663
  }
522
664
  async renderTextLayer(pageIndex, container, scale) {
523
665
  }
@@ -530,6 +672,11 @@ var WebViewDocumentEngine = class extends import_core.BaseDocumentEngine {
530
672
  { pageIndex }
531
673
  );
532
674
  }
675
+ async getPagePreview(pageIndex) {
676
+ return await this.request("get-page-preview", {
677
+ pageIndex
678
+ });
679
+ }
533
680
  async searchText(query) {
534
681
  return await this.request("search-text", { query });
535
682
  }
@@ -558,23 +705,18 @@ var WebViewDocumentEngine = class extends import_core.BaseDocumentEngine {
558
705
  return await this.request("get-page-index", { dest });
559
706
  }
560
707
  destroy() {
561
- this.pending.forEach(
562
- ({ reject }) => reject(new Error("[Papyrus] WebView engine destroyed"))
563
- );
564
- this.pending.clear();
565
- this.bridge = null;
566
- this.ready = false;
708
+ this.detachBridge();
567
709
  }
568
710
  async ensureBridge() {
569
711
  if (this.bridge) return this.bridge;
570
- return new Promise((resolve) => {
571
- this.bridgeResolvers.push(resolve);
712
+ return new Promise((resolve, reject) => {
713
+ this.bridgeResolvers.push({ resolve, reject });
572
714
  });
573
715
  }
574
716
  async ensureReady() {
575
717
  if (this.ready) return;
576
- return new Promise((resolve) => {
577
- this.readyResolvers.push(resolve);
718
+ return new Promise((resolve, reject) => {
719
+ this.readyResolvers.push({ resolve, reject });
578
720
  });
579
721
  }
580
722
  async request(kind, payload) {
@@ -582,7 +724,7 @@ var WebViewDocumentEngine = class extends import_core.BaseDocumentEngine {
582
724
  await this.ensureReady();
583
725
  const id = `${Date.now()}-${this.requestId++}`;
584
726
  return new Promise((resolve, reject) => {
585
- const timeoutMs = kind === "load" ? 18e4 : 8e3;
727
+ const timeoutMs = kind === "load" ? 18e4 : kind === "get-page-preview" ? 3e4 : 8e3;
586
728
  const timeoutId = setTimeout(() => {
587
729
  this.pending.delete(id);
588
730
  reject(new Error(`[Papyrus] WebView response timeout: ${kind}`));
@@ -602,7 +744,7 @@ var WebViewDocumentEngine = class extends import_core.BaseDocumentEngine {
602
744
  }
603
745
  async normalizeRuntimeSource(type, source) {
604
746
  if (typeof source === "string") {
605
- const dataUri = parseDataUri(source);
747
+ const dataUri = parseDataUri2(source);
606
748
  if (dataUri) {
607
749
  if (dataUri.isBase64) {
608
750
  return {
@@ -615,10 +757,16 @@ var WebViewDocumentEngine = class extends import_core.BaseDocumentEngine {
615
757
  return { kind: "text", text };
616
758
  }
617
759
  if (looksLikeUri(source)) {
760
+ if (isMetroAssetUri(source)) {
761
+ return { kind: "uri", uri: source };
762
+ }
618
763
  if (isHttpUri(source)) {
619
764
  const fetched = await this.fetchRemoteSource(type, source);
620
765
  if (fetched) return fetched;
621
766
  }
767
+ if (isLocalUri(source)) {
768
+ return await this.fetchLocalSource(type, source);
769
+ }
622
770
  return { kind: "uri", uri: source };
623
771
  }
624
772
  if (isLikelyBase64(source)) {
@@ -631,10 +779,27 @@ var WebViewDocumentEngine = class extends import_core.BaseDocumentEngine {
631
779
  }
632
780
  if (this.isUriSource(source)) {
633
781
  const uri = source.uri;
782
+ const dataUri = parseDataUri2(uri);
783
+ if (dataUri) {
784
+ if (dataUri.isBase64) {
785
+ return {
786
+ kind: "base64",
787
+ data: dataUri.data,
788
+ mime: dataUri.mime || void 0
789
+ };
790
+ }
791
+ return { kind: "text", text: decodeURIComponent(dataUri.data) };
792
+ }
793
+ if (isMetroAssetUri(uri)) {
794
+ return { kind: "uri", uri };
795
+ }
634
796
  if (isHttpUri(uri)) {
635
797
  const fetched = await this.fetchRemoteSource(type, uri);
636
798
  if (fetched) return fetched;
637
799
  }
800
+ if (isLocalUri(uri)) {
801
+ return await this.fetchLocalSource(type, uri);
802
+ }
638
803
  return { kind: "uri", uri };
639
804
  }
640
805
  if (this.isDataSource(source)) {
@@ -666,11 +831,35 @@ var WebViewDocumentEngine = class extends import_core.BaseDocumentEngine {
666
831
  const buffer = await this.readResponseBuffer(response);
667
832
  return { kind: "base64", data: encodeBase64(new Uint8Array(buffer)) };
668
833
  }
834
+ if (type === "comic") {
835
+ const buffer = await this.readResponseBuffer(response);
836
+ return { kind: "base64", data: encodeBase64(new Uint8Array(buffer)) };
837
+ }
669
838
  return null;
670
839
  } catch {
671
840
  return null;
672
841
  }
673
842
  }
843
+ async fetchLocalSource(type, uri) {
844
+ if (type === "epub" || type === "comic") {
845
+ return { kind: "uri", uri };
846
+ }
847
+ try {
848
+ const response = await fetch(uri);
849
+ if (!response.ok && response.status !== 0) {
850
+ throw new Error(`status ${response.status}`);
851
+ }
852
+ if (type === "text") {
853
+ return { kind: "text", text: await response.text() };
854
+ }
855
+ throw new Error(`tipo n\xE3o suportado: ${type}`);
856
+ } catch (error) {
857
+ const reason = error instanceof Error ? `: ${error.message}` : "";
858
+ throw new Error(
859
+ `[WebViewDocumentEngine] N\xE3o foi poss\xEDvel ler o arquivo local ${uri}${reason}`
860
+ );
861
+ }
862
+ }
674
863
  async readResponseBuffer(response) {
675
864
  try {
676
865
  return await response.arrayBuffer();
@@ -695,29 +884,48 @@ var WebViewDocumentEngine = class extends import_core.BaseDocumentEngine {
695
884
  }
696
885
  };
697
886
  var MobileDocumentEngine = class extends import_core.BaseDocumentEngine {
698
- constructor() {
887
+ constructor(options = {}) {
699
888
  super();
700
889
  this.pdfEngine = new NativeDocumentEngine();
701
- this.webEngine = new WebViewDocumentEngine();
890
+ this.webEngine = new WebViewDocumentEngine(options);
702
891
  this.activeEngine = this.pdfEngine;
703
892
  }
893
+ getWebViewRuntimeSource() {
894
+ return this.webEngine.getWebViewRuntimeSource();
895
+ }
896
+ getWebViewRuntimeConfig() {
897
+ return this.webEngine.getWebViewRuntimeConfig();
898
+ }
704
899
  getRenderTargetType() {
705
900
  return this.activeEngine.getRenderTargetType?.() ?? "canvas";
706
901
  }
707
902
  getNativeEngineId() {
708
903
  return this.activeEngine === this.pdfEngine ? this.pdfEngine.getNativeEngineId() : null;
709
904
  }
905
+ getLifecycleStats() {
906
+ return {
907
+ ...this.pdfEngine.getLifecycleStats(),
908
+ ...this.webEngine.getLifecycleStats()
909
+ };
910
+ }
710
911
  attachWebView(bridge) {
711
912
  this.webEngine.attachBridge(bridge);
712
913
  }
914
+ detachWebView() {
915
+ this.webEngine.detachBridge();
916
+ }
713
917
  handleWebViewMessage(data) {
714
918
  this.webEngine.handleMessage(data);
715
919
  }
716
920
  async load(input) {
717
- const { source, type } = normalizeLoadInput(input);
921
+ const { source, type, format } = normalizeLoadInput(input);
718
922
  const resolvedType = type ?? inferDocumentType(source);
719
923
  this.activeEngine = resolvedType === "pdf" ? this.pdfEngine : this.webEngine;
720
- await this.activeEngine.load({ type: resolvedType, source });
924
+ await this.activeEngine.load({
925
+ type: resolvedType,
926
+ source,
927
+ ...resolvedType === "comic" && format ? { format } : {}
928
+ });
721
929
  }
722
930
  getPageCount() {
723
931
  return this.activeEngine.getPageCount();
@@ -740,8 +948,8 @@ var MobileDocumentEngine = class extends import_core.BaseDocumentEngine {
740
948
  getRotation() {
741
949
  return this.activeEngine.getRotation();
742
950
  }
743
- async renderPage(pageIndex, target, scale) {
744
- await this.activeEngine.renderPage(pageIndex, target, scale);
951
+ async renderPage(pageIndex, target, scale, telemetry) {
952
+ await this.activeEngine.renderPage(pageIndex, target, scale, telemetry);
745
953
  }
746
954
  async renderTextLayer(pageIndex, container, scale) {
747
955
  await this.activeEngine.renderTextLayer(pageIndex, container, scale);
@@ -752,6 +960,10 @@ var MobileDocumentEngine = class extends import_core.BaseDocumentEngine {
752
960
  async getPageDimensions(pageIndex) {
753
961
  return await this.activeEngine.getPageDimensions(pageIndex);
754
962
  }
963
+ async getPagePreview(pageIndex) {
964
+ const engine = this.activeEngine;
965
+ return await engine.getPagePreview?.(pageIndex) ?? null;
966
+ }
755
967
  async searchText(query) {
756
968
  if (typeof this.activeEngine.searchText === "function") {
757
969
  return await this.activeEngine.searchText(query);