@papyrus-sdk/engine-native 0.1.1 → 0.1.2

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.
Files changed (26) hide show
  1. package/LICENSE +21 -0
  2. package/android/build.gradle +40 -40
  3. package/android/src/main/AndroidManifest.xml +3 -3
  4. package/android/src/main/java/com/papyrus/engine/PapyrusEngineStore.java +71 -71
  5. package/android/src/main/java/com/papyrus/engine/PapyrusNativeEngineModule.java +529 -529
  6. package/android/src/main/java/com/papyrus/engine/PapyrusNativeEngineModule.kt +540 -0
  7. package/android/src/main/java/com/papyrus/engine/PapyrusOutline.java +20 -20
  8. package/android/src/main/java/com/papyrus/engine/PapyrusOutlineItem.java +13 -13
  9. package/android/src/main/java/com/papyrus/engine/PapyrusPackage.java +24 -24
  10. package/android/src/main/java/com/papyrus/engine/PapyrusPageView.java +86 -86
  11. package/android/src/main/java/com/papyrus/engine/PapyrusPageViewManager.java +16 -16
  12. package/android/src/main/java/com/papyrus/engine/PapyrusPageViewModule.kt +12 -0
  13. package/android/src/main/java/com/papyrus/engine/PapyrusTextHit.java +15 -15
  14. package/android/src/main/java/com/papyrus/engine/PapyrusTextSearch.java +20 -20
  15. package/android/src/main/java/com/papyrus/engine/PapyrusTextSelect.java +20 -20
  16. package/android/src/main/java/com/papyrus/engine/PapyrusTextSelection.java +11 -11
  17. package/dist/index.d.mts +8 -7
  18. package/dist/index.d.ts +8 -7
  19. package/dist/index.js +200 -8
  20. package/dist/index.js.map +1 -1
  21. package/dist/index.mjs +201 -9
  22. package/dist/index.mjs.map +1 -1
  23. package/ios/PapyrusNativeEngine.podspec +1 -1
  24. package/ios/PapyrusPageViewManager.m +19 -19
  25. package/package.json +30 -30
  26. package/react-native.config.js +10 -10
@@ -1,86 +1,86 @@
1
- package com.papyrus.engine;
2
-
3
- import android.content.Context;
4
- import android.graphics.Bitmap;
5
- import android.graphics.Canvas;
6
- import android.graphics.Paint;
7
- import android.graphics.Rect;
8
- import android.util.AttributeSet;
9
- import android.view.View;
10
-
11
- import com.shockwave.pdfium.PdfDocument;
12
-
13
- import java.util.concurrent.ExecutorService;
14
- import java.util.concurrent.Executors;
15
-
16
- class PapyrusPageView extends View {
17
- private static final ExecutorService RENDER_EXECUTOR = Executors.newSingleThreadExecutor();
18
-
19
- private final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
20
- private Bitmap bitmap;
21
-
22
- PapyrusPageView(Context context) {
23
- super(context);
24
- }
25
-
26
- PapyrusPageView(Context context, AttributeSet attrs) {
27
- super(context, attrs);
28
- }
29
-
30
- void render(final PapyrusEngineStore.EngineState state,
31
- final int pageIndex,
32
- final float scale,
33
- final float zoom,
34
- final int rotation) {
35
- if (state == null || state.document == null) return;
36
- if (state.isSearching) return;
37
- if (getWidth() == 0 || getHeight() == 0) {
38
- post(() -> render(state, pageIndex, scale, zoom, rotation));
39
- return;
40
- }
41
-
42
- final int viewWidth = getWidth();
43
- final int viewHeight = getHeight();
44
- final float clampedZoom = Math.max(0.1f, Math.min(5.0f, zoom));
45
- final float targetScale = Math.max(0.1f, scale) * clampedZoom;
46
- final int renderWidth = Math.max(1, (int) (viewWidth * targetScale));
47
- final int renderHeight = Math.max(1, (int) (viewHeight * targetScale));
48
-
49
- RENDER_EXECUTOR.execute(() -> {
50
- PdfDocument doc = state.document;
51
- if (doc == null) return;
52
-
53
- try {
54
- Bitmap rendered = null;
55
- synchronized (state.pdfiumLock) {
56
- if (doc != state.document) return;
57
- int pageCount = state.pdfium.getPageCount(doc);
58
- if (pageIndex < 0 || pageIndex >= pageCount) return;
59
- state.pdfium.openPage(doc, pageIndex);
60
- rendered = Bitmap.createBitmap(renderWidth, renderHeight, Bitmap.Config.ARGB_8888);
61
- state.pdfium.renderPageBitmap(doc, rendered, pageIndex, 0, 0, renderWidth, renderHeight, true);
62
- }
63
-
64
- if (rendered == null) return;
65
- final Bitmap renderedBitmap = rendered;
66
-
67
- post(() -> {
68
- if (bitmap != null && !bitmap.isRecycled()) {
69
- bitmap.recycle();
70
- }
71
- bitmap = renderedBitmap;
72
- invalidate();
73
- });
74
- } catch (Throwable ignored) {
75
- }
76
- });
77
- }
78
-
79
- @Override
80
- protected void onDraw(Canvas canvas) {
81
- super.onDraw(canvas);
82
- if (bitmap == null) return;
83
- Rect dest = new Rect(0, 0, getWidth(), getHeight());
84
- canvas.drawBitmap(bitmap, null, dest, paint);
85
- }
86
- }
1
+ package com.papyrus.engine;
2
+
3
+ import android.content.Context;
4
+ import android.graphics.Bitmap;
5
+ import android.graphics.Canvas;
6
+ import android.graphics.Paint;
7
+ import android.graphics.Rect;
8
+ import android.util.AttributeSet;
9
+ import android.view.View;
10
+
11
+ import com.shockwave.pdfium.PdfDocument;
12
+
13
+ import java.util.concurrent.ExecutorService;
14
+ import java.util.concurrent.Executors;
15
+
16
+ public class PapyrusPageView extends View {
17
+ private static final ExecutorService RENDER_EXECUTOR = Executors.newSingleThreadExecutor();
18
+
19
+ private final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
20
+ private Bitmap bitmap;
21
+
22
+ public PapyrusPageView(Context context) {
23
+ super(context);
24
+ }
25
+
26
+ public PapyrusPageView(Context context, AttributeSet attrs) {
27
+ super(context, attrs);
28
+ }
29
+
30
+ void render(final PapyrusEngineStore.EngineState state,
31
+ final int pageIndex,
32
+ final float scale,
33
+ final float zoom,
34
+ final int rotation) {
35
+ if (state == null || state.document == null) return;
36
+ if (state.isSearching) return;
37
+ if (getWidth() == 0 || getHeight() == 0) {
38
+ post(() -> render(state, pageIndex, scale, zoom, rotation));
39
+ return;
40
+ }
41
+
42
+ final int viewWidth = getWidth();
43
+ final int viewHeight = getHeight();
44
+ final float clampedZoom = Math.max(0.1f, Math.min(5.0f, zoom));
45
+ final float targetScale = Math.max(0.1f, scale) * clampedZoom;
46
+ final int renderWidth = Math.max(1, (int) (viewWidth * targetScale));
47
+ final int renderHeight = Math.max(1, (int) (viewHeight * targetScale));
48
+
49
+ RENDER_EXECUTOR.execute(() -> {
50
+ PdfDocument doc = state.document;
51
+ if (doc == null) return;
52
+
53
+ try {
54
+ Bitmap rendered = null;
55
+ synchronized (state.pdfiumLock) {
56
+ if (doc != state.document) return;
57
+ int pageCount = state.pdfium.getPageCount(doc);
58
+ if (pageIndex < 0 || pageIndex >= pageCount) return;
59
+ state.pdfium.openPage(doc, pageIndex);
60
+ rendered = Bitmap.createBitmap(renderWidth, renderHeight, Bitmap.Config.ARGB_8888);
61
+ state.pdfium.renderPageBitmap(doc, rendered, pageIndex, 0, 0, renderWidth, renderHeight, true);
62
+ }
63
+
64
+ if (rendered == null) return;
65
+ final Bitmap renderedBitmap = rendered;
66
+
67
+ post(() -> {
68
+ if (bitmap != null && !bitmap.isRecycled()) {
69
+ bitmap.recycle();
70
+ }
71
+ bitmap = renderedBitmap;
72
+ invalidate();
73
+ });
74
+ } catch (Throwable ignored) {
75
+ }
76
+ });
77
+ }
78
+
79
+ @Override
80
+ protected void onDraw(Canvas canvas) {
81
+ super.onDraw(canvas);
82
+ if (bitmap == null) return;
83
+ Rect dest = new Rect(0, 0, getWidth(), getHeight());
84
+ canvas.drawBitmap(bitmap, null, dest, paint);
85
+ }
86
+ }
@@ -1,16 +1,16 @@
1
- package com.papyrus.engine;
2
-
3
- import com.facebook.react.uimanager.SimpleViewManager;
4
- import com.facebook.react.uimanager.ThemedReactContext;
5
-
6
- public class PapyrusPageViewManager extends SimpleViewManager<PapyrusPageView> {
7
- @Override
8
- public String getName() {
9
- return "PapyrusPageView";
10
- }
11
-
12
- @Override
13
- protected PapyrusPageView createViewInstance(ThemedReactContext reactContext) {
14
- return new PapyrusPageView(reactContext);
15
- }
16
- }
1
+ package com.papyrus.engine;
2
+
3
+ import com.facebook.react.uimanager.SimpleViewManager;
4
+ import com.facebook.react.uimanager.ThemedReactContext;
5
+
6
+ public class PapyrusPageViewManager extends SimpleViewManager<PapyrusPageView> {
7
+ @Override
8
+ public String getName() {
9
+ return "PapyrusPageView";
10
+ }
11
+
12
+ @Override
13
+ protected PapyrusPageView createViewInstance(ThemedReactContext reactContext) {
14
+ return new PapyrusPageView(reactContext);
15
+ }
16
+ }
@@ -0,0 +1,12 @@
1
+ package com.papyrus.engine
2
+
3
+ import expo.modules.kotlin.modules.Module
4
+ import expo.modules.kotlin.modules.ModuleDefinition
5
+
6
+ class PapyrusPageViewModule : Module() {
7
+ override fun definition() = ModuleDefinition {
8
+ Name("PapyrusPageView")
9
+ View(PapyrusPageView::class) {
10
+ }
11
+ }
12
+ }
@@ -1,15 +1,15 @@
1
- package com.papyrus.engine;
2
-
3
- final class PapyrusTextHit {
4
- final int pageIndex;
5
- final int matchIndex;
6
- final String text;
7
- final float[] rects;
8
-
9
- PapyrusTextHit(int pageIndex, int matchIndex, String text, float[] rects) {
10
- this.pageIndex = pageIndex;
11
- this.matchIndex = matchIndex;
12
- this.text = text;
13
- this.rects = rects;
14
- }
15
- }
1
+ package com.papyrus.engine;
2
+
3
+ final class PapyrusTextHit {
4
+ final int pageIndex;
5
+ final int matchIndex;
6
+ final String text;
7
+ final float[] rects;
8
+
9
+ PapyrusTextHit(int pageIndex, int matchIndex, String text, float[] rects) {
10
+ this.pageIndex = pageIndex;
11
+ this.matchIndex = matchIndex;
12
+ this.text = text;
13
+ this.rects = rects;
14
+ }
15
+ }
@@ -1,20 +1,20 @@
1
- package com.papyrus.engine;
2
-
3
- final class PapyrusTextSearch {
4
- static final boolean AVAILABLE;
5
-
6
- static {
7
- boolean available = false;
8
- try {
9
- System.loadLibrary("papyrus_text");
10
- available = true;
11
- } catch (Throwable ignored) {
12
- available = false;
13
- }
14
- AVAILABLE = available;
15
- }
16
-
17
- static native PapyrusTextHit[] nativeSearch(long docPtr, int pageCount, String query);
18
-
19
- static native PapyrusTextHit[] nativeSearchFile(String filePath, String query);
20
- }
1
+ package com.papyrus.engine;
2
+
3
+ final class PapyrusTextSearch {
4
+ static final boolean AVAILABLE;
5
+
6
+ static {
7
+ boolean available = false;
8
+ try {
9
+ System.loadLibrary("papyrus_text");
10
+ available = true;
11
+ } catch (Throwable ignored) {
12
+ available = false;
13
+ }
14
+ AVAILABLE = available;
15
+ }
16
+
17
+ static native PapyrusTextHit[] nativeSearch(long docPtr, int pageCount, String query);
18
+
19
+ static native PapyrusTextHit[] nativeSearchFile(String filePath, String query);
20
+ }
@@ -1,20 +1,20 @@
1
- package com.papyrus.engine;
2
-
3
- final class PapyrusTextSelect {
4
- static final boolean AVAILABLE;
5
-
6
- static {
7
- boolean available = false;
8
- try {
9
- System.loadLibrary("papyrus_text");
10
- available = true;
11
- } catch (Throwable ignored) {
12
- available = false;
13
- }
14
- AVAILABLE = available;
15
- }
16
-
17
- static native PapyrusTextSelection nativeSelectText(long docPtr, int pageIndex, float x, float y, float width, float height);
18
-
19
- static native PapyrusTextSelection nativeSelectTextFile(String filePath, int pageIndex, float x, float y, float width, float height);
20
- }
1
+ package com.papyrus.engine;
2
+
3
+ final class PapyrusTextSelect {
4
+ static final boolean AVAILABLE;
5
+
6
+ static {
7
+ boolean available = false;
8
+ try {
9
+ System.loadLibrary("papyrus_text");
10
+ available = true;
11
+ } catch (Throwable ignored) {
12
+ available = false;
13
+ }
14
+ AVAILABLE = available;
15
+ }
16
+
17
+ static native PapyrusTextSelection nativeSelectText(long docPtr, int pageIndex, float x, float y, float width, float height);
18
+
19
+ static native PapyrusTextSelection nativeSelectTextFile(String filePath, int pageIndex, float x, float y, float width, float height);
20
+ }
@@ -1,11 +1,11 @@
1
- package com.papyrus.engine;
2
-
3
- final class PapyrusTextSelection {
4
- final String text;
5
- final float[] rects;
6
-
7
- PapyrusTextSelection(String text, float[] rects) {
8
- this.text = text != null ? text : "";
9
- this.rects = rects;
10
- }
11
- }
1
+ package com.papyrus.engine;
2
+
3
+ final class PapyrusTextSelection {
4
+ final String text;
5
+ final float[] rects;
6
+
7
+ PapyrusTextSelection(String text, float[] rects) {
8
+ this.text = text != null ? text : "";
9
+ this.rects = rects;
10
+ }
11
+ }
package/dist/index.d.mts CHANGED
@@ -1,12 +1,13 @@
1
- import * as react_native from 'react-native';
2
- import { ViewProps } from 'react-native';
1
+ import { ComponentType, RefAttributes } from 'react';
2
+ import { ViewProps, View } from 'react-native';
3
3
  import { BaseDocumentEngine } from '@papyrus-sdk/core';
4
- import { DocumentLoadInput, TextItem, TextSelection, OutlineItem, SearchResult, RenderTargetType } from '@papyrus-sdk/types';
4
+ import { DocumentLoadInput, TextItem, TextSelection, OutlineItem, SearchResult, PageDestination, RenderTargetType } from '@papyrus-sdk/types';
5
5
 
6
6
  type PapyrusPageViewProps = ViewProps & {
7
7
  engineId?: string;
8
8
  };
9
- declare const PapyrusPageView: react_native.HostComponent<PapyrusPageViewProps>;
9
+ type PapyrusPageViewComponent = ComponentType<PapyrusPageViewProps & RefAttributes<View>>;
10
+ declare const PapyrusPageView: PapyrusPageViewComponent;
10
11
  declare class NativeDocumentEngine extends BaseDocumentEngine {
11
12
  private nativeModule;
12
13
  private engineId;
@@ -38,7 +39,7 @@ declare class NativeDocumentEngine extends BaseDocumentEngine {
38
39
  }): Promise<TextSelection | null>;
39
40
  getOutline(): Promise<OutlineItem[]>;
40
41
  searchText(query: string): Promise<SearchResult[]>;
41
- getPageIndex(dest: any): Promise<number | null>;
42
+ getPageIndex(dest: PageDestination): Promise<number | null>;
42
43
  destroy(): void;
43
44
  private assertNativeModule;
44
45
  private normalizeSource;
@@ -88,7 +89,7 @@ declare class WebViewDocumentEngine extends BaseDocumentEngine {
88
89
  height: number;
89
90
  }): Promise<TextSelection | null>;
90
91
  getOutline(): Promise<OutlineItem[]>;
91
- getPageIndex(dest: any): Promise<number | null>;
92
+ getPageIndex(dest: PageDestination): Promise<number | null>;
92
93
  destroy(): void;
93
94
  private ensureBridge;
94
95
  private ensureReady;
@@ -131,7 +132,7 @@ declare class MobileDocumentEngine extends BaseDocumentEngine {
131
132
  height: number;
132
133
  }): Promise<TextSelection | null>;
133
134
  getOutline(): Promise<OutlineItem[]>;
134
- getPageIndex(dest: any): Promise<number | null>;
135
+ getPageIndex(dest: PageDestination): Promise<number | null>;
135
136
  destroy(): void;
136
137
  }
137
138
 
package/dist/index.d.ts CHANGED
@@ -1,12 +1,13 @@
1
- import * as react_native from 'react-native';
2
- import { ViewProps } from 'react-native';
1
+ import { ComponentType, RefAttributes } from 'react';
2
+ import { ViewProps, View } from 'react-native';
3
3
  import { BaseDocumentEngine } from '@papyrus-sdk/core';
4
- import { DocumentLoadInput, TextItem, TextSelection, OutlineItem, SearchResult, RenderTargetType } from '@papyrus-sdk/types';
4
+ import { DocumentLoadInput, TextItem, TextSelection, OutlineItem, SearchResult, PageDestination, RenderTargetType } from '@papyrus-sdk/types';
5
5
 
6
6
  type PapyrusPageViewProps = ViewProps & {
7
7
  engineId?: string;
8
8
  };
9
- declare const PapyrusPageView: react_native.HostComponent<PapyrusPageViewProps>;
9
+ type PapyrusPageViewComponent = ComponentType<PapyrusPageViewProps & RefAttributes<View>>;
10
+ declare const PapyrusPageView: PapyrusPageViewComponent;
10
11
  declare class NativeDocumentEngine extends BaseDocumentEngine {
11
12
  private nativeModule;
12
13
  private engineId;
@@ -38,7 +39,7 @@ declare class NativeDocumentEngine extends BaseDocumentEngine {
38
39
  }): Promise<TextSelection | null>;
39
40
  getOutline(): Promise<OutlineItem[]>;
40
41
  searchText(query: string): Promise<SearchResult[]>;
41
- getPageIndex(dest: any): Promise<number | null>;
42
+ getPageIndex(dest: PageDestination): Promise<number | null>;
42
43
  destroy(): void;
43
44
  private assertNativeModule;
44
45
  private normalizeSource;
@@ -88,7 +89,7 @@ declare class WebViewDocumentEngine extends BaseDocumentEngine {
88
89
  height: number;
89
90
  }): Promise<TextSelection | null>;
90
91
  getOutline(): Promise<OutlineItem[]>;
91
- getPageIndex(dest: any): Promise<number | null>;
92
+ getPageIndex(dest: PageDestination): Promise<number | null>;
92
93
  destroy(): void;
93
94
  private ensureBridge;
94
95
  private ensureReady;
@@ -131,7 +132,7 @@ declare class MobileDocumentEngine extends BaseDocumentEngine {
131
132
  height: number;
132
133
  }): Promise<TextSelection | null>;
133
134
  getOutline(): Promise<OutlineItem[]>;
134
- getPageIndex(dest: any): Promise<number | null>;
135
+ getPageIndex(dest: PageDestination): Promise<number | null>;
135
136
  destroy(): void;
136
137
  }
137
138