@papyrus-sdk/engine-native 0.2.20 → 0.2.22-beta.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/LICENSE +21 -0
- package/android/src/main/cpp/CMakeLists.txt +12 -1
- package/android/src/main/cpp/papyrus_outline_loader_test.cpp +240 -0
- package/android/src/main/cpp/papyrus_text_search.cpp +162 -24
- package/android/src/main/cpp/papyrus_text_word.cpp +33 -0
- package/android/src/main/cpp/papyrus_text_word.h +19 -0
- package/android/src/main/cpp/papyrus_text_word_test.cpp +72 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusNativeEngineModule.java +3 -3
- package/android/src/main/java/com/papyrus/engine/PapyrusNativeEngineModule.kt +11 -3
- package/android/src/main/java/com/papyrus/engine/PapyrusPdfViewerView.java +279 -138
- package/android/src/main/java/com/papyrus/engine/PapyrusPdfViewerViewManager.java +9 -7
- package/android/src/main/java/com/papyrus/engine/PapyrusTextSelect.java +2 -2
- package/android/src/main/java/com/papyrus/engine/PapyrusTextSelectionGesture.java +44 -2
- package/dist/index.d.mts +6 -5
- package/dist/index.d.ts +6 -5
- package/dist/index.js +43 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +42 -11
- package/dist/index.mjs.map +1 -1
- package/ios/PapyrusEngineStore.h +3 -0
- package/ios/PapyrusEngineStore.m +29 -7
- package/ios/PapyrusNativeEngine.m +184 -0
- package/ios/PapyrusPdfDocumentView.h +24 -0
- package/ios/PapyrusPdfDocumentView.m +658 -0
- package/ios/PapyrusPdfDocumentViewManager.m +32 -0
- package/package.json +5 -5
|
@@ -93,16 +93,18 @@ public class PapyrusPdfViewerViewManager extends SimpleViewManager<PapyrusPdfVie
|
|
|
93
93
|
com.facebook.react.common.MapBuilder.of("bubbled", "onTextSelected")
|
|
94
94
|
)
|
|
95
95
|
)
|
|
96
|
-
.put(
|
|
97
|
-
"onScroll",
|
|
98
|
-
com.facebook.react.common.MapBuilder.of(
|
|
99
|
-
"phasedRegistrationNames",
|
|
100
|
-
com.facebook.react.common.MapBuilder.of("bubbled", "onScroll")
|
|
101
|
-
)
|
|
102
|
-
)
|
|
103
96
|
.build();
|
|
104
97
|
}
|
|
105
98
|
|
|
99
|
+
@Nullable
|
|
100
|
+
@Override
|
|
101
|
+
public Map<String, Object> getExportedCustomDirectEventTypeConstants() {
|
|
102
|
+
return com.facebook.react.common.MapBuilder.of(
|
|
103
|
+
"topScroll",
|
|
104
|
+
com.facebook.react.common.MapBuilder.of("registrationName", "onScroll")
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
106
108
|
@ReactProp(name = "engineId")
|
|
107
109
|
public void setEngineId(PapyrusPdfViewerView view, String engineId) {
|
|
108
110
|
view.setEngineId(engineId);
|
|
@@ -14,7 +14,7 @@ final class PapyrusTextSelect {
|
|
|
14
14
|
AVAILABLE = available;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
static native PapyrusTextSelection nativeSelectText(long docPtr, int pageIndex, float x, float y, float width, float height);
|
|
17
|
+
static native PapyrusTextSelection nativeSelectText(long docPtr, int pageIndex, float x, float y, float width, float height, float startX, float startY, float endX, float endY);
|
|
18
18
|
|
|
19
|
-
static native PapyrusTextSelection nativeSelectTextFile(String filePath, int pageIndex, float x, float y, float width, float height);
|
|
19
|
+
static native PapyrusTextSelection nativeSelectTextFile(String filePath, int pageIndex, float x, float y, float width, float height, float startX, float startY, float endX, float endY);
|
|
20
20
|
}
|
|
@@ -12,12 +12,54 @@ final class PapyrusTextSelectionGesture {
|
|
|
12
12
|
return !isDoubleTap;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
/** A touch that starts on a handle or inside the selection keeps it. */
|
|
16
|
+
static boolean shouldDismissSelectionOnTouch(
|
|
17
|
+
boolean hasSelection,
|
|
18
|
+
boolean hitHandle,
|
|
19
|
+
boolean insideSelection
|
|
20
|
+
) {
|
|
21
|
+
return hasSelection && !hitHandle && !insideSelection;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** A touch that starts with a painted selection never becomes a page tap. */
|
|
25
|
+
static boolean shouldSuppressPageTap(boolean hadSelectionAtDown) {
|
|
26
|
+
return hadSelectionAtDown;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Dragging inside the selection past the threshold dismisses it and scrolls. */
|
|
30
|
+
static boolean shouldStartScrollFromSelection(
|
|
31
|
+
boolean insideSelection,
|
|
32
|
+
float distance,
|
|
33
|
+
float thresholdPx
|
|
34
|
+
) {
|
|
35
|
+
return insideSelection && distance > thresholdPx;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static boolean resolveDoubleTap(
|
|
39
|
+
long now,
|
|
40
|
+
long lastTapTime,
|
|
41
|
+
float dx,
|
|
42
|
+
float dy,
|
|
43
|
+
long timeoutMs,
|
|
44
|
+
float maxDistancePx
|
|
45
|
+
) {
|
|
46
|
+
if (lastTapTime <= 0) return false;
|
|
47
|
+
if (now - lastTapTime >= timeoutMs) return false;
|
|
48
|
+
return Math.hypot(dx, dy) <= maxDistancePx;
|
|
17
49
|
}
|
|
18
50
|
|
|
19
51
|
/** Keep the selection endpoint where the user's finger actually landed. */
|
|
20
52
|
static float resolveSelectionEndpoint(float normalizedX) {
|
|
21
53
|
return Math.max(0f, Math.min(1f, normalizedX));
|
|
22
54
|
}
|
|
55
|
+
|
|
56
|
+
/** Complete the line crossed by a selection endpoint. */
|
|
57
|
+
static float resolveSelectionEndpoint(
|
|
58
|
+
float normalizedX,
|
|
59
|
+
boolean crossedLine,
|
|
60
|
+
boolean isStartHandle
|
|
61
|
+
) {
|
|
62
|
+
if (crossedLine) return isStartHandle ? 0f : 1f;
|
|
63
|
+
return resolveSelectionEndpoint(normalizedX);
|
|
64
|
+
}
|
|
23
65
|
}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ComponentType, RefAttributes } from 'react';
|
|
2
2
|
import { ViewProps, View } from 'react-native';
|
|
3
3
|
import { BaseDocumentEngine } from '@papyrus-sdk/core';
|
|
4
|
-
import { RenderTargetType, DocumentLoadInput, RenderPageTelemetryContext, TextItem, SearchResult, TextSelection, OutlineItem, PageDestination, RenderPageResult, PageTheme, Annotation, PdfVisiblePage } from '@papyrus-sdk/types';
|
|
4
|
+
import { RenderTargetType, DocumentLoadInput, RenderPageTelemetryContext, TextItem, SearchResult, TextSelectionEndpoints, TextSelection, OutlineItem, PageDestination, RenderPageResult, PageTheme, Annotation, PdfVisiblePage } from '@papyrus-sdk/types';
|
|
5
5
|
|
|
6
6
|
type PapyrusPageViewProps = ViewProps & {
|
|
7
7
|
engineId?: string;
|
|
@@ -83,6 +83,7 @@ type PapyrusPdfViewerViewProps = ViewProps & {
|
|
|
83
83
|
};
|
|
84
84
|
type PapyrusPageViewComponent = ComponentType<PapyrusPageViewProps & RefAttributes<View>>;
|
|
85
85
|
type PapyrusPdfViewerViewComponent = ComponentType<PapyrusPdfViewerViewProps & RefAttributes<View>>;
|
|
86
|
+
declare const isPapyrusPdfDocumentViewAvailable: () => boolean;
|
|
86
87
|
declare const PapyrusPageView: PapyrusPageViewComponent;
|
|
87
88
|
declare const PapyrusPdfViewerView: PapyrusPdfViewerViewComponent;
|
|
88
89
|
declare const PapyrusPdfDocumentView: PapyrusPdfViewerViewComponent;
|
|
@@ -117,7 +118,7 @@ declare class NativeDocumentEngine extends BaseDocumentEngine {
|
|
|
117
118
|
y: number;
|
|
118
119
|
width: number;
|
|
119
120
|
height: number;
|
|
120
|
-
}): Promise<TextSelection | null>;
|
|
121
|
+
}, endpoints?: TextSelectionEndpoints): Promise<TextSelection | null>;
|
|
121
122
|
getOutline(): Promise<OutlineItem[]>;
|
|
122
123
|
searchText(query: string): Promise<SearchResult[]>;
|
|
123
124
|
getPageIndex(dest: PageDestination): Promise<number | null>;
|
|
@@ -187,7 +188,7 @@ declare class WebViewDocumentEngine extends BaseDocumentEngine {
|
|
|
187
188
|
y: number;
|
|
188
189
|
width: number;
|
|
189
190
|
height: number;
|
|
190
|
-
}): Promise<TextSelection | null>;
|
|
191
|
+
}, endpoints?: TextSelectionEndpoints): Promise<TextSelection | null>;
|
|
191
192
|
getOutline(): Promise<OutlineItem[]>;
|
|
192
193
|
getPageIndex(dest: PageDestination): Promise<number | null>;
|
|
193
194
|
destroy(): void;
|
|
@@ -237,10 +238,10 @@ declare class MobileDocumentEngine extends BaseDocumentEngine {
|
|
|
237
238
|
y: number;
|
|
238
239
|
width: number;
|
|
239
240
|
height: number;
|
|
240
|
-
}): Promise<TextSelection | null>;
|
|
241
|
+
}, endpoints?: TextSelectionEndpoints): Promise<TextSelection | null>;
|
|
241
242
|
getOutline(): Promise<OutlineItem[]>;
|
|
242
243
|
getPageIndex(dest: PageDestination): Promise<number | null>;
|
|
243
244
|
destroy(): void;
|
|
244
245
|
}
|
|
245
246
|
|
|
246
|
-
export { MobileDocumentEngine, type MobileDocumentEngineOptions, NativeDocumentEngine, PapyrusPageView, type PapyrusPageViewProps, PapyrusPdfDocumentView, PapyrusPdfViewerView, type PapyrusPdfViewerViewProps, WebViewDocumentEngine, type WebViewRuntimeConfig, type WebViewRuntimeSource };
|
|
247
|
+
export { MobileDocumentEngine, type MobileDocumentEngineOptions, NativeDocumentEngine, PapyrusPageView, type PapyrusPageViewProps, PapyrusPdfDocumentView, PapyrusPdfViewerView, type PapyrusPdfViewerViewProps, WebViewDocumentEngine, type WebViewRuntimeConfig, type WebViewRuntimeSource, isPapyrusPdfDocumentViewAvailable };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ComponentType, RefAttributes } from 'react';
|
|
2
2
|
import { ViewProps, View } from 'react-native';
|
|
3
3
|
import { BaseDocumentEngine } from '@papyrus-sdk/core';
|
|
4
|
-
import { RenderTargetType, DocumentLoadInput, RenderPageTelemetryContext, TextItem, SearchResult, TextSelection, OutlineItem, PageDestination, RenderPageResult, PageTheme, Annotation, PdfVisiblePage } from '@papyrus-sdk/types';
|
|
4
|
+
import { RenderTargetType, DocumentLoadInput, RenderPageTelemetryContext, TextItem, SearchResult, TextSelectionEndpoints, TextSelection, OutlineItem, PageDestination, RenderPageResult, PageTheme, Annotation, PdfVisiblePage } from '@papyrus-sdk/types';
|
|
5
5
|
|
|
6
6
|
type PapyrusPageViewProps = ViewProps & {
|
|
7
7
|
engineId?: string;
|
|
@@ -83,6 +83,7 @@ type PapyrusPdfViewerViewProps = ViewProps & {
|
|
|
83
83
|
};
|
|
84
84
|
type PapyrusPageViewComponent = ComponentType<PapyrusPageViewProps & RefAttributes<View>>;
|
|
85
85
|
type PapyrusPdfViewerViewComponent = ComponentType<PapyrusPdfViewerViewProps & RefAttributes<View>>;
|
|
86
|
+
declare const isPapyrusPdfDocumentViewAvailable: () => boolean;
|
|
86
87
|
declare const PapyrusPageView: PapyrusPageViewComponent;
|
|
87
88
|
declare const PapyrusPdfViewerView: PapyrusPdfViewerViewComponent;
|
|
88
89
|
declare const PapyrusPdfDocumentView: PapyrusPdfViewerViewComponent;
|
|
@@ -117,7 +118,7 @@ declare class NativeDocumentEngine extends BaseDocumentEngine {
|
|
|
117
118
|
y: number;
|
|
118
119
|
width: number;
|
|
119
120
|
height: number;
|
|
120
|
-
}): Promise<TextSelection | null>;
|
|
121
|
+
}, endpoints?: TextSelectionEndpoints): Promise<TextSelection | null>;
|
|
121
122
|
getOutline(): Promise<OutlineItem[]>;
|
|
122
123
|
searchText(query: string): Promise<SearchResult[]>;
|
|
123
124
|
getPageIndex(dest: PageDestination): Promise<number | null>;
|
|
@@ -187,7 +188,7 @@ declare class WebViewDocumentEngine extends BaseDocumentEngine {
|
|
|
187
188
|
y: number;
|
|
188
189
|
width: number;
|
|
189
190
|
height: number;
|
|
190
|
-
}): Promise<TextSelection | null>;
|
|
191
|
+
}, endpoints?: TextSelectionEndpoints): Promise<TextSelection | null>;
|
|
191
192
|
getOutline(): Promise<OutlineItem[]>;
|
|
192
193
|
getPageIndex(dest: PageDestination): Promise<number | null>;
|
|
193
194
|
destroy(): void;
|
|
@@ -237,10 +238,10 @@ declare class MobileDocumentEngine extends BaseDocumentEngine {
|
|
|
237
238
|
y: number;
|
|
238
239
|
width: number;
|
|
239
240
|
height: number;
|
|
240
|
-
}): Promise<TextSelection | null>;
|
|
241
|
+
}, endpoints?: TextSelectionEndpoints): Promise<TextSelection | null>;
|
|
241
242
|
getOutline(): Promise<OutlineItem[]>;
|
|
242
243
|
getPageIndex(dest: PageDestination): Promise<number | null>;
|
|
243
244
|
destroy(): void;
|
|
244
245
|
}
|
|
245
246
|
|
|
246
|
-
export { MobileDocumentEngine, type MobileDocumentEngineOptions, NativeDocumentEngine, PapyrusPageView, type PapyrusPageViewProps, PapyrusPdfDocumentView, PapyrusPdfViewerView, type PapyrusPdfViewerViewProps, WebViewDocumentEngine, type WebViewRuntimeConfig, type WebViewRuntimeSource };
|
|
247
|
+
export { MobileDocumentEngine, type MobileDocumentEngineOptions, NativeDocumentEngine, PapyrusPageView, type PapyrusPageViewProps, PapyrusPdfDocumentView, PapyrusPdfViewerView, type PapyrusPdfViewerViewProps, WebViewDocumentEngine, type WebViewRuntimeConfig, type WebViewRuntimeSource, isPapyrusPdfDocumentViewAvailable };
|
package/dist/index.js
CHANGED
|
@@ -24,7 +24,8 @@ __export(engine_native_exports, {
|
|
|
24
24
|
PapyrusPageView: () => PapyrusPageView,
|
|
25
25
|
PapyrusPdfDocumentView: () => PapyrusPdfDocumentView,
|
|
26
26
|
PapyrusPdfViewerView: () => PapyrusPdfViewerView,
|
|
27
|
-
WebViewDocumentEngine: () => WebViewDocumentEngine
|
|
27
|
+
WebViewDocumentEngine: () => WebViewDocumentEngine,
|
|
28
|
+
isPapyrusPdfDocumentViewAvailable: () => isPapyrusPdfDocumentViewAvailable
|
|
28
29
|
});
|
|
29
30
|
module.exports = __toCommonJS(engine_native_exports);
|
|
30
31
|
var import_react_native = require("react-native");
|
|
@@ -89,6 +90,16 @@ var resolvePapyrusNativeModule = (registries) => {
|
|
|
89
90
|
return registries.nativeModules.PapyrusNativeEngine ?? null;
|
|
90
91
|
};
|
|
91
92
|
|
|
93
|
+
// nativeViewAvailability.ts
|
|
94
|
+
var isNativeViewManagerRegistered = (registry, managerName) => {
|
|
95
|
+
if (typeof registry.hasViewManagerConfig !== "function") return false;
|
|
96
|
+
try {
|
|
97
|
+
return registry.hasViewManagerConfig(managerName);
|
|
98
|
+
} catch {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
92
103
|
// index.ts
|
|
93
104
|
var MODULE_NAME = "PapyrusNativeEngine";
|
|
94
105
|
var BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
@@ -195,18 +206,32 @@ var resolvePapyrusPageView = () => {
|
|
|
195
206
|
return import_react_native.View;
|
|
196
207
|
}
|
|
197
208
|
};
|
|
198
|
-
var
|
|
199
|
-
|
|
209
|
+
var PAPYRUS_PDF_DOCUMENT_VIEW_NAME = "PapyrusPdfDocumentView";
|
|
210
|
+
var hasPapyrusPdfDocumentViewManager = () => import_react_native.Platform.OS === "ios" && isNativeViewManagerRegistered(import_react_native.UIManager, PAPYRUS_PDF_DOCUMENT_VIEW_NAME);
|
|
211
|
+
var unavailablePapyrusPdfDocumentView = () => null;
|
|
212
|
+
var resolvePapyrusPdfDocumentView = () => {
|
|
213
|
+
if (!hasPapyrusPdfDocumentViewManager()) return null;
|
|
214
|
+
try {
|
|
215
|
+
return (0, import_react_native.requireNativeComponent)(
|
|
216
|
+
PAPYRUS_PDF_DOCUMENT_VIEW_NAME
|
|
217
|
+
);
|
|
218
|
+
} catch {
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
var resolvePapyrusAndroidPdfViewerView = () => {
|
|
200
223
|
try {
|
|
201
224
|
return (0, import_react_native.requireNativeComponent)(
|
|
202
|
-
|
|
225
|
+
"PapyrusPdfViewerView"
|
|
203
226
|
);
|
|
204
227
|
} catch {
|
|
205
228
|
return import_react_native.View;
|
|
206
229
|
}
|
|
207
230
|
};
|
|
231
|
+
var papyrusPdfDocumentView = resolvePapyrusPdfDocumentView();
|
|
232
|
+
var isPapyrusPdfDocumentViewAvailable = () => papyrusPdfDocumentView !== null && hasPapyrusPdfDocumentViewManager();
|
|
208
233
|
var PapyrusPageView = resolvePapyrusPageView();
|
|
209
|
-
var PapyrusPdfViewerView =
|
|
234
|
+
var PapyrusPdfViewerView = import_react_native.Platform.OS === "ios" ? papyrusPdfDocumentView ?? unavailablePapyrusPdfDocumentView : resolvePapyrusAndroidPdfViewerView();
|
|
210
235
|
var PapyrusPdfDocumentView = PapyrusPdfViewerView;
|
|
211
236
|
var NativeDocumentEngine = class extends import_core.BaseDocumentEngine {
|
|
212
237
|
constructor() {
|
|
@@ -325,7 +350,7 @@ var NativeDocumentEngine = class extends import_core.BaseDocumentEngine {
|
|
|
325
350
|
if (!native.getPageDimensions) return { width: 0, height: 0 };
|
|
326
351
|
return native.getPageDimensions(this.engineId, pageIndex);
|
|
327
352
|
}
|
|
328
|
-
async selectText(pageIndex, rect) {
|
|
353
|
+
async selectText(pageIndex, rect, endpoints) {
|
|
329
354
|
const native = this.assertNativeModule();
|
|
330
355
|
if (!native.selectText) return null;
|
|
331
356
|
return native.selectText(
|
|
@@ -334,7 +359,11 @@ var NativeDocumentEngine = class extends import_core.BaseDocumentEngine {
|
|
|
334
359
|
rect.x,
|
|
335
360
|
rect.y,
|
|
336
361
|
rect.width,
|
|
337
|
-
rect.height
|
|
362
|
+
rect.height,
|
|
363
|
+
endpoints?.start.x ?? -1,
|
|
364
|
+
endpoints?.start.y ?? -1,
|
|
365
|
+
endpoints?.end.x ?? -1,
|
|
366
|
+
endpoints?.end.y ?? -1
|
|
338
367
|
);
|
|
339
368
|
}
|
|
340
369
|
async getOutline() {
|
|
@@ -680,10 +709,11 @@ var WebViewDocumentEngine = class extends import_core.BaseDocumentEngine {
|
|
|
680
709
|
async searchText(query) {
|
|
681
710
|
return await this.request("search-text", { query });
|
|
682
711
|
}
|
|
683
|
-
async selectText(pageIndex, rect) {
|
|
712
|
+
async selectText(pageIndex, rect, endpoints) {
|
|
684
713
|
return await this.request("select-text", {
|
|
685
714
|
pageIndex,
|
|
686
|
-
rect
|
|
715
|
+
rect,
|
|
716
|
+
endpoints
|
|
687
717
|
});
|
|
688
718
|
}
|
|
689
719
|
async getOutline() {
|
|
@@ -970,9 +1000,9 @@ var MobileDocumentEngine = class extends import_core.BaseDocumentEngine {
|
|
|
970
1000
|
}
|
|
971
1001
|
return [];
|
|
972
1002
|
}
|
|
973
|
-
async selectText(pageIndex, rect) {
|
|
1003
|
+
async selectText(pageIndex, rect, endpoints) {
|
|
974
1004
|
if (typeof this.activeEngine.selectText === "function") {
|
|
975
|
-
return await this.activeEngine.selectText(pageIndex, rect);
|
|
1005
|
+
return await this.activeEngine.selectText(pageIndex, rect, endpoints);
|
|
976
1006
|
}
|
|
977
1007
|
return null;
|
|
978
1008
|
}
|
|
@@ -994,6 +1024,7 @@ var MobileDocumentEngine = class extends import_core.BaseDocumentEngine {
|
|
|
994
1024
|
PapyrusPageView,
|
|
995
1025
|
PapyrusPdfDocumentView,
|
|
996
1026
|
PapyrusPdfViewerView,
|
|
997
|
-
WebViewDocumentEngine
|
|
1027
|
+
WebViewDocumentEngine,
|
|
1028
|
+
isPapyrusPdfDocumentViewAvailable
|
|
998
1029
|
});
|
|
999
1030
|
//# sourceMappingURL=index.js.map
|