@papyrus-sdk/engine-native 0.2.22-beta.6 → 0.2.22-beta.8
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/android/src/main/java/com/papyrus/engine/PapyrusComicDocumentView.java +164 -26
- package/android/src/main/java/com/papyrus/engine/PapyrusComicPageLayout.java +21 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusNativeEngineModule.java +12 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusPdfViewerView.java +195 -5
- package/android/src/main/java/com/papyrus/engine/PapyrusPdfViewerViewManager.java +20 -1
- package/android/src/main/java/com/papyrus/engine/PapyrusSelectionMenuIcon.java +48 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusTextAnnotationModel.java +22 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusTextDocumentView.java +239 -17
- package/android/src/main/java/com/papyrus/engine/PapyrusTextDocumentViewManager.java +6 -0
- package/dist/index.d.mts +137 -1
- package/dist/index.d.ts +137 -1
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +37 -0
- package/dist/index.mjs.map +1 -1
- package/ios/PapyrusComicDocumentView.m +200 -27
- package/ios/PapyrusNativeEngine.m +12 -0
- package/ios/PapyrusPdfDocumentView.h +5 -0
- package/ios/PapyrusPdfDocumentView.m +96 -11
- package/ios/PapyrusPdfDocumentViewManager.m +3 -0
- package/ios/PapyrusSelectionMenu.h +27 -0
- package/ios/PapyrusTextAnnotationRange.h +2 -0
- package/ios/PapyrusTextAnnotationRange.m +29 -0
- package/ios/PapyrusTextDocumentView.h +5 -0
- package/ios/PapyrusTextDocumentView.m +233 -14
- package/ios/PapyrusTextDocumentViewManager.m +5 -0
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -2,13 +2,30 @@ import * as react from 'react';
|
|
|
2
2
|
import { RefAttributes, ComponentType } from 'react';
|
|
3
3
|
import { ViewProps, View } from 'react-native';
|
|
4
4
|
import { BaseDocumentEngine } from '@papyrus-sdk/core';
|
|
5
|
-
import { RenderTargetType, DocumentLoadInput, RenderPageTelemetryContext, TextItem, SearchResult, TextSearchResult, TextSelectionEndpoints, TextSelection, OutlineItem, PageDestination, ComicFormat, RenderPageResult, PageTheme,
|
|
5
|
+
import { RenderTargetType, Annotation, DocumentLoadInput, RenderPageTelemetryContext, TextItem, SearchResult, TextSearchResult, TextSelectionEndpoints, TextSelection, OutlineItem, PageDestination, ComicFormat, RenderPageResult, PageTheme, PdfVisiblePage, InkStrokeCommit, ComicLayoutMode, ComicFitMode, ComicReadingDirection, TextRangeSelection } from '@papyrus-sdk/types';
|
|
6
6
|
|
|
7
7
|
type PapyrusPageViewProps = ViewProps & {
|
|
8
8
|
engineId?: string;
|
|
9
9
|
pageTheme?: PageTheme;
|
|
10
10
|
};
|
|
11
11
|
type PapyrusPdfViewerViewProps = ViewProps & {
|
|
12
|
+
annotationLabels?: Record<string, string>;
|
|
13
|
+
defineEnabled?: boolean;
|
|
14
|
+
copyLabel?: string;
|
|
15
|
+
selectAllLabel?: string;
|
|
16
|
+
onAnnotateSelection?: (event: {
|
|
17
|
+
nativeEvent: {
|
|
18
|
+
text: string;
|
|
19
|
+
pageIndex: number;
|
|
20
|
+
rects: {
|
|
21
|
+
x: number;
|
|
22
|
+
y: number;
|
|
23
|
+
width: number;
|
|
24
|
+
height: number;
|
|
25
|
+
}[];
|
|
26
|
+
style: "highlight" | "underline" | "strikeout" | "comment";
|
|
27
|
+
};
|
|
28
|
+
}) => void;
|
|
12
29
|
engineId?: string;
|
|
13
30
|
pageTheme?: PageTheme;
|
|
14
31
|
zoom?: number;
|
|
@@ -22,6 +39,16 @@ type PapyrusPdfViewerViewProps = ViewProps & {
|
|
|
22
39
|
searchResults?: SearchResult[];
|
|
23
40
|
activeSearchIndex?: number;
|
|
24
41
|
annotations?: Annotation[];
|
|
42
|
+
annotationNavigationRequest?: {
|
|
43
|
+
pageIndex: number;
|
|
44
|
+
rect: {
|
|
45
|
+
x: number;
|
|
46
|
+
y: number;
|
|
47
|
+
width: number;
|
|
48
|
+
height: number;
|
|
49
|
+
};
|
|
50
|
+
nonce: number;
|
|
51
|
+
} | null;
|
|
25
52
|
selectedAnnotationId?: string | null;
|
|
26
53
|
onPageChanged?: (event: {
|
|
27
54
|
nativeEvent: {
|
|
@@ -121,11 +148,29 @@ type PapyrusPdfViewerViewProps = ViewProps & {
|
|
|
121
148
|
viewMode?: "continuous" | "single";
|
|
122
149
|
};
|
|
123
150
|
type PapyrusTextDocumentViewProps = ViewProps & {
|
|
151
|
+
annotations?: Annotation[];
|
|
152
|
+
annotationLabels?: Record<string, string>;
|
|
153
|
+
onAnnotateSelection?: (event: {
|
|
154
|
+
nativeEvent: TextRangeSelection & {
|
|
155
|
+
style: "highlight" | "underline" | "strikeout" | "comment";
|
|
156
|
+
prefix?: string;
|
|
157
|
+
suffix?: string;
|
|
158
|
+
};
|
|
159
|
+
}) => void;
|
|
160
|
+
onAnnotationTap?: (event: {
|
|
161
|
+
nativeEvent: {
|
|
162
|
+
id: string;
|
|
163
|
+
};
|
|
164
|
+
}) => void;
|
|
124
165
|
engineId?: string;
|
|
125
166
|
documentGeneration?: number;
|
|
126
167
|
textLength?: number;
|
|
127
168
|
currentTextOffset?: number;
|
|
128
169
|
scrollToTextOffsetSignal?: number | null;
|
|
170
|
+
textNavigationRequest?: {
|
|
171
|
+
offset: number;
|
|
172
|
+
nonce: number;
|
|
173
|
+
} | null;
|
|
129
174
|
searchResults?: TextSearchResult[];
|
|
130
175
|
activeSearchIndex?: number;
|
|
131
176
|
pageTheme?: PageTheme;
|
|
@@ -191,6 +236,23 @@ declare const PapyrusPdfDocumentView: PapyrusPdfViewerViewComponent;
|
|
|
191
236
|
declare const isPapyrusTextDocumentViewAvailable: () => boolean;
|
|
192
237
|
declare const isPapyrusComicDocumentViewAvailable: () => boolean;
|
|
193
238
|
declare const PapyrusTextDocumentView: react.FunctionComponent<ViewProps & {
|
|
239
|
+
annotationLabels?: Record<string, string>;
|
|
240
|
+
defineEnabled?: boolean;
|
|
241
|
+
copyLabel?: string;
|
|
242
|
+
selectAllLabel?: string;
|
|
243
|
+
onAnnotateSelection?: (event: {
|
|
244
|
+
nativeEvent: {
|
|
245
|
+
text: string;
|
|
246
|
+
pageIndex: number;
|
|
247
|
+
rects: {
|
|
248
|
+
x: number;
|
|
249
|
+
y: number;
|
|
250
|
+
width: number;
|
|
251
|
+
height: number;
|
|
252
|
+
}[];
|
|
253
|
+
style: "highlight" | "underline" | "strikeout" | "comment";
|
|
254
|
+
};
|
|
255
|
+
}) => void;
|
|
194
256
|
engineId?: string;
|
|
195
257
|
pageTheme?: PageTheme;
|
|
196
258
|
zoom?: number;
|
|
@@ -204,6 +266,16 @@ declare const PapyrusTextDocumentView: react.FunctionComponent<ViewProps & {
|
|
|
204
266
|
searchResults?: SearchResult[];
|
|
205
267
|
activeSearchIndex?: number;
|
|
206
268
|
annotations?: Annotation[];
|
|
269
|
+
annotationNavigationRequest?: {
|
|
270
|
+
pageIndex: number;
|
|
271
|
+
rect: {
|
|
272
|
+
x: number;
|
|
273
|
+
y: number;
|
|
274
|
+
width: number;
|
|
275
|
+
height: number;
|
|
276
|
+
};
|
|
277
|
+
nonce: number;
|
|
278
|
+
} | null;
|
|
207
279
|
selectedAnnotationId?: string | null;
|
|
208
280
|
onPageChanged?: (event: {
|
|
209
281
|
nativeEvent: {
|
|
@@ -302,11 +374,29 @@ declare const PapyrusTextDocumentView: react.FunctionComponent<ViewProps & {
|
|
|
302
374
|
annotationDeleteLabel?: string;
|
|
303
375
|
viewMode?: "continuous" | "single";
|
|
304
376
|
} & RefAttributes<View>> | ComponentType<ViewProps & {
|
|
377
|
+
annotations?: Annotation[];
|
|
378
|
+
annotationLabels?: Record<string, string>;
|
|
379
|
+
onAnnotateSelection?: (event: {
|
|
380
|
+
nativeEvent: TextRangeSelection & {
|
|
381
|
+
style: "highlight" | "underline" | "strikeout" | "comment";
|
|
382
|
+
prefix?: string;
|
|
383
|
+
suffix?: string;
|
|
384
|
+
};
|
|
385
|
+
}) => void;
|
|
386
|
+
onAnnotationTap?: (event: {
|
|
387
|
+
nativeEvent: {
|
|
388
|
+
id: string;
|
|
389
|
+
};
|
|
390
|
+
}) => void;
|
|
305
391
|
engineId?: string;
|
|
306
392
|
documentGeneration?: number;
|
|
307
393
|
textLength?: number;
|
|
308
394
|
currentTextOffset?: number;
|
|
309
395
|
scrollToTextOffsetSignal?: number | null;
|
|
396
|
+
textNavigationRequest?: {
|
|
397
|
+
offset: number;
|
|
398
|
+
nonce: number;
|
|
399
|
+
} | null;
|
|
310
400
|
searchResults?: TextSearchResult[];
|
|
311
401
|
activeSearchIndex?: number;
|
|
312
402
|
pageTheme?: PageTheme;
|
|
@@ -337,6 +427,23 @@ declare const PapyrusTextDocumentView: react.FunctionComponent<ViewProps & {
|
|
|
337
427
|
}) => void;
|
|
338
428
|
} & RefAttributes<unknown>>;
|
|
339
429
|
declare const PapyrusComicDocumentView: react.FunctionComponent<ViewProps & {
|
|
430
|
+
annotationLabels?: Record<string, string>;
|
|
431
|
+
defineEnabled?: boolean;
|
|
432
|
+
copyLabel?: string;
|
|
433
|
+
selectAllLabel?: string;
|
|
434
|
+
onAnnotateSelection?: (event: {
|
|
435
|
+
nativeEvent: {
|
|
436
|
+
text: string;
|
|
437
|
+
pageIndex: number;
|
|
438
|
+
rects: {
|
|
439
|
+
x: number;
|
|
440
|
+
y: number;
|
|
441
|
+
width: number;
|
|
442
|
+
height: number;
|
|
443
|
+
}[];
|
|
444
|
+
style: "highlight" | "underline" | "strikeout" | "comment";
|
|
445
|
+
};
|
|
446
|
+
}) => void;
|
|
340
447
|
engineId?: string;
|
|
341
448
|
pageTheme?: PageTheme;
|
|
342
449
|
zoom?: number;
|
|
@@ -350,6 +457,16 @@ declare const PapyrusComicDocumentView: react.FunctionComponent<ViewProps & {
|
|
|
350
457
|
searchResults?: SearchResult[];
|
|
351
458
|
activeSearchIndex?: number;
|
|
352
459
|
annotations?: Annotation[];
|
|
460
|
+
annotationNavigationRequest?: {
|
|
461
|
+
pageIndex: number;
|
|
462
|
+
rect: {
|
|
463
|
+
x: number;
|
|
464
|
+
y: number;
|
|
465
|
+
width: number;
|
|
466
|
+
height: number;
|
|
467
|
+
};
|
|
468
|
+
nonce: number;
|
|
469
|
+
} | null;
|
|
353
470
|
selectedAnnotationId?: string | null;
|
|
354
471
|
onPageChanged?: (event: {
|
|
355
472
|
nativeEvent: {
|
|
@@ -529,6 +646,10 @@ declare class NativeTextDocumentEngine extends BaseDocumentEngine {
|
|
|
529
646
|
getTextLength(): number;
|
|
530
647
|
getCurrentTextOffset(): number;
|
|
531
648
|
goToTextOffset(offset: number): void;
|
|
649
|
+
resolveAnnotationTextRange(annotation: Annotation): Promise<{
|
|
650
|
+
start: number;
|
|
651
|
+
end: number;
|
|
652
|
+
} | null>;
|
|
532
653
|
getTextRange(start: number, end: number): Promise<string>;
|
|
533
654
|
searchTextRanges(query: string): Promise<TextSearchResult[]>;
|
|
534
655
|
getRenderTargetType(): RenderTargetType;
|
|
@@ -600,6 +721,12 @@ type MobileDocumentEngineOptions = {
|
|
|
600
721
|
webViewRuntimeConfig?: WebViewRuntimeConfig;
|
|
601
722
|
};
|
|
602
723
|
declare class WebViewDocumentEngine extends BaseDocumentEngine {
|
|
724
|
+
private documentSessionId;
|
|
725
|
+
getWebViewDocumentSessionId(): string;
|
|
726
|
+
syncEpubAnnotations(annotations: Annotation[], documentId?: string, labels?: {
|
|
727
|
+
comment: string;
|
|
728
|
+
}): Promise<void>;
|
|
729
|
+
goToAnnotation(annotation: Annotation): Promise<void>;
|
|
603
730
|
private readonly webViewRuntimeSource?;
|
|
604
731
|
private readonly webViewRuntimeConfig?;
|
|
605
732
|
private bridge;
|
|
@@ -680,6 +807,15 @@ declare class MobileDocumentEngine extends BaseDocumentEngine {
|
|
|
680
807
|
getCurrentTextOffset(): number;
|
|
681
808
|
goToTextOffset(offset: number): void;
|
|
682
809
|
getLifecycleStats(): Record<string, number>;
|
|
810
|
+
resolveAnnotationTextRange(annotation: Annotation): Promise<{
|
|
811
|
+
start: number;
|
|
812
|
+
end: number;
|
|
813
|
+
} | null>;
|
|
814
|
+
getWebViewDocumentSessionId(): string;
|
|
815
|
+
syncEpubAnnotations(annotations: Annotation[], documentId?: string, labels?: {
|
|
816
|
+
comment: string;
|
|
817
|
+
}): Promise<void>;
|
|
818
|
+
goToAnnotation(annotation: Annotation): void | Promise<void>;
|
|
683
819
|
attachWebView(bridge: WebViewBridge): void;
|
|
684
820
|
detachWebView(): void;
|
|
685
821
|
handleWebViewMessage(data: string): void;
|
package/dist/index.js
CHANGED
|
@@ -587,6 +587,12 @@ var NativeTextDocumentEngine = class extends import_core.BaseDocumentEngine {
|
|
|
587
587
|
goToTextOffset(offset) {
|
|
588
588
|
this.currentOffset = clampTextOffset(offset, this.textLength);
|
|
589
589
|
}
|
|
590
|
+
async resolveAnnotationTextRange(annotation) {
|
|
591
|
+
if (annotation.anchor?.kind !== "text-range") return annotation.textRange ?? null;
|
|
592
|
+
const generation = this.documentGeneration;
|
|
593
|
+
const range = await this.assertNativeModule().resolveTextAnnotationRange?.(this.engineId, generation, annotation.anchor);
|
|
594
|
+
return generation === this.documentGeneration ? range ?? null : null;
|
|
595
|
+
}
|
|
590
596
|
async getTextRange(start, end) {
|
|
591
597
|
const native = this.assertNativeModule();
|
|
592
598
|
if (!native.getTextRange) return "";
|
|
@@ -799,6 +805,7 @@ var NativeComicDocumentEngine = class extends import_core.BaseDocumentEngine {
|
|
|
799
805
|
var WebViewDocumentEngine = class extends import_core.BaseDocumentEngine {
|
|
800
806
|
constructor(options = {}) {
|
|
801
807
|
super();
|
|
808
|
+
this.documentSessionId = "";
|
|
802
809
|
this.bridge = null;
|
|
803
810
|
this.ready = false;
|
|
804
811
|
this.requestId = 0;
|
|
@@ -813,6 +820,17 @@ var WebViewDocumentEngine = class extends import_core.BaseDocumentEngine {
|
|
|
813
820
|
this.webViewRuntimeSource = options.webViewRuntimeSource;
|
|
814
821
|
this.webViewRuntimeConfig = options.webViewRuntimeConfig;
|
|
815
822
|
}
|
|
823
|
+
getWebViewDocumentSessionId() {
|
|
824
|
+
return this.documentSessionId;
|
|
825
|
+
}
|
|
826
|
+
async syncEpubAnnotations(annotations, documentId, labels) {
|
|
827
|
+
if (!this.documentSessionId) return;
|
|
828
|
+
await this.request("epub-annotations", { documentSessionId: this.documentSessionId, annotations, documentId, labels });
|
|
829
|
+
}
|
|
830
|
+
async goToAnnotation(annotation) {
|
|
831
|
+
if (annotation.anchor?.kind !== "epub-cfi") return;
|
|
832
|
+
await this.request("epub-annotation-navigate", { documentSessionId: this.documentSessionId, annotationId: annotation.id });
|
|
833
|
+
}
|
|
816
834
|
getWebViewRuntimeSource() {
|
|
817
835
|
return this.webViewRuntimeSource;
|
|
818
836
|
}
|
|
@@ -999,15 +1017,20 @@ var WebViewDocumentEngine = class extends import_core.BaseDocumentEngine {
|
|
|
999
1017
|
"[WebViewDocumentEngine] Use o NativeDocumentEngine para PDFs no mobile."
|
|
1000
1018
|
);
|
|
1001
1019
|
}
|
|
1020
|
+
const session = `epub-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
1021
|
+
this.documentSessionId = session;
|
|
1002
1022
|
const payloadSource = await this.normalizeRuntimeSource(
|
|
1003
1023
|
resolvedType,
|
|
1004
1024
|
source
|
|
1005
1025
|
);
|
|
1026
|
+
if (session !== this.documentSessionId) throw new Error("Stale document load");
|
|
1006
1027
|
const response = await this.request("load", {
|
|
1007
1028
|
type: resolvedType,
|
|
1029
|
+
documentSessionId: session,
|
|
1008
1030
|
source: payloadSource,
|
|
1009
1031
|
...resolvedType === "comic" ? { format: resolveComicFormat(source, format) } : {}
|
|
1010
1032
|
});
|
|
1033
|
+
if (session !== this.documentSessionId) throw new Error("Stale document load");
|
|
1011
1034
|
if (typeof response?.pageCount === "number")
|
|
1012
1035
|
this.pageCount = response.pageCount;
|
|
1013
1036
|
if (Array.isArray(response?.outline)) this.outline = response.outline;
|
|
@@ -1317,6 +1340,20 @@ var MobileDocumentEngine = class extends import_core.BaseDocumentEngine {
|
|
|
1317
1340
|
...this.webEngine.getLifecycleStats()
|
|
1318
1341
|
};
|
|
1319
1342
|
}
|
|
1343
|
+
resolveAnnotationTextRange(annotation) {
|
|
1344
|
+
return this.textEngine.resolveAnnotationTextRange(annotation);
|
|
1345
|
+
}
|
|
1346
|
+
getWebViewDocumentSessionId() {
|
|
1347
|
+
return this.webEngine.getWebViewDocumentSessionId();
|
|
1348
|
+
}
|
|
1349
|
+
syncEpubAnnotations(annotations, documentId, labels) {
|
|
1350
|
+
return this.webEngine.syncEpubAnnotations(annotations, documentId, labels);
|
|
1351
|
+
}
|
|
1352
|
+
goToAnnotation(annotation) {
|
|
1353
|
+
if (annotation.anchor?.kind === "epub-cfi") return this.webEngine.goToAnnotation(annotation);
|
|
1354
|
+
if (annotation.anchor?.kind === "text-range") return this.textEngine.goToTextOffset(annotation.anchor.start);
|
|
1355
|
+
this.activeEngine.goToPage((annotation.anchor?.kind === "pdf-geometry" ? annotation.anchor.pageIndex : annotation.pageIndex) + 1);
|
|
1356
|
+
}
|
|
1320
1357
|
attachWebView(bridge) {
|
|
1321
1358
|
this.webEngine.attachBridge(bridge);
|
|
1322
1359
|
}
|