@papyrus-sdk/engine-native 0.2.11 → 0.2.12-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.
Files changed (36) hide show
  1. package/android/build.gradle +42 -42
  2. package/android/src/main/AndroidManifest.xml +1 -1
  3. package/android/src/main/cpp/CMakeLists.txt +45 -45
  4. package/android/src/main/cpp/papyrus_outline.cpp +173 -173
  5. package/android/src/main/cpp/papyrus_outline_loader.cpp +125 -125
  6. package/android/src/main/cpp/papyrus_outline_loader.h +48 -48
  7. package/android/src/main/cpp/papyrus_outline_loader_test.cpp +240 -240
  8. package/android/src/main/java/com/papyrus/engine/PapyrusEngineStore.java +71 -71
  9. package/android/src/main/java/com/papyrus/engine/PapyrusNativeEngineModule.java +520 -516
  10. package/android/src/main/java/com/papyrus/engine/PapyrusNativeEngineModule.kt +527 -527
  11. package/android/src/main/java/com/papyrus/engine/PapyrusOutline.java +34 -34
  12. package/android/src/main/java/com/papyrus/engine/PapyrusOutlineItem.java +13 -13
  13. package/android/src/main/java/com/papyrus/engine/PapyrusPackage.java +24 -24
  14. package/android/src/main/java/com/papyrus/engine/PapyrusPageView.java +197 -128
  15. package/android/src/main/java/com/papyrus/engine/PapyrusPageViewManager.java +22 -16
  16. package/android/src/main/java/com/papyrus/engine/PapyrusPageViewModule.kt +15 -12
  17. package/android/src/main/java/com/papyrus/engine/PapyrusTextHit.java +15 -15
  18. package/android/src/main/java/com/papyrus/engine/PapyrusTextSearch.java +20 -20
  19. package/android/src/main/java/com/papyrus/engine/PapyrusTextSelect.java +20 -20
  20. package/android/src/main/java/com/papyrus/engine/PapyrusTextSelection.java +11 -11
  21. package/android/src/test/java/com/papyrus/engine/PapyrusOutlineTest.java +40 -40
  22. package/android/src/test/java/com/papyrus/engine/PapyrusPageViewTest.java +30 -30
  23. package/dist/index.d.mts +2 -1
  24. package/dist/index.d.ts +2 -1
  25. package/dist/index.js +32 -44
  26. package/dist/index.js.map +1 -1
  27. package/dist/index.mjs +30 -41
  28. package/dist/index.mjs.map +1 -1
  29. package/ios/PapyrusNativeEngine.m +447 -447
  30. package/ios/PapyrusNativeEngine.podspec +15 -15
  31. package/ios/PapyrusPageView.h +21 -19
  32. package/ios/PapyrusPageView.m +194 -63
  33. package/ios/PapyrusPageViewManager.m +20 -19
  34. package/package.json +14 -11
  35. package/react-native.config.js +10 -10
  36. package/LICENSE +0 -21
@@ -1,15 +1,15 @@
1
- Pod::Spec.new do |s|
2
- s.name = 'PapyrusNativeEngine'
3
- s.version = '0.1.1'
4
- s.summary = 'Papyrus Native Engine (PDFKit)'
5
- s.homepage = 'https://example.com/papyrus'
6
- s.license = { :type => 'MIT' }
7
- s.author = { 'Papyrus' => 'dev@papyrus.local' }
8
- s.platforms = { :ios => '13.0' }
9
- s.source = { :git => 'https://example.com/papyrus.git', :tag => s.version.to_s }
10
- s.source_files = '**/*.{h,m,mm,swift}'
11
- s.requires_arc = true
12
- s.swift_version = '5.0'
13
-
14
- s.dependency 'React-Core'
15
- end
1
+ Pod::Spec.new do |s|
2
+ s.name = 'PapyrusNativeEngine'
3
+ s.version = '0.1.1'
4
+ s.summary = 'Papyrus Native Engine (PDFKit)'
5
+ s.homepage = 'https://example.com/papyrus'
6
+ s.license = { :type => 'MIT' }
7
+ s.author = { 'Papyrus' => 'dev@papyrus.local' }
8
+ s.platforms = { :ios => '13.0' }
9
+ s.source = { :git => 'https://example.com/papyrus.git', :tag => s.version.to_s }
10
+ s.source_files = '**/*.{h,m,mm,swift}'
11
+ s.requires_arc = true
12
+ s.swift_version = '5.0'
13
+
14
+ s.dependency 'React-Core'
15
+ end
@@ -1,19 +1,21 @@
1
- #import <UIKit/UIKit.h>
2
- #import <PDFKit/PDFKit.h>
3
-
4
- NS_ASSUME_NONNULL_BEGIN
5
-
6
- @interface PapyrusPageView : UIView
7
-
8
- - (void)renderWithDocument:(PDFDocument *_Nullable)document
9
- pageIndex:(NSInteger)pageIndex
10
- scale:(CGFloat)scale
11
- zoom:(CGFloat)zoom
12
- rotation:(NSInteger)rotation;
13
-
14
- - (CGRect)convertRectToPage:(CGRect)rect page:(PDFPage *)page;
15
- - (CGRect)convertRectFromPage:(CGRect)rect page:(PDFPage *)page;
16
-
17
- @end
18
-
19
- NS_ASSUME_NONNULL_END
1
+ #import <UIKit/UIKit.h>
2
+ #import <PDFKit/PDFKit.h>
3
+
4
+ NS_ASSUME_NONNULL_BEGIN
5
+
6
+ @interface PapyrusPageView : UIView
7
+
8
+ @property (nonatomic, copy) NSString *pageTheme;
9
+
10
+ - (void)renderWithDocument:(PDFDocument *_Nullable)document
11
+ pageIndex:(NSInteger)pageIndex
12
+ scale:(CGFloat)scale
13
+ zoom:(CGFloat)zoom
14
+ rotation:(NSInteger)rotation;
15
+
16
+ - (CGRect)convertRectToPage:(CGRect)rect page:(PDFPage *)page;
17
+ - (CGRect)convertRectFromPage:(CGRect)rect page:(PDFPage *)page;
18
+
19
+ @end
20
+
21
+ NS_ASSUME_NONNULL_END
@@ -1,63 +1,194 @@
1
- #import "PapyrusPageView.h"
2
-
3
- @interface PapyrusPageView ()
4
- @property (nonatomic, strong) PDFView *pdfView;
5
- @end
6
-
7
- @implementation PapyrusPageView
8
-
9
- - (instancetype)initWithFrame:(CGRect)frame {
10
- self = [super initWithFrame:frame];
11
- if (self) {
12
- _pdfView = [[PDFView alloc] initWithFrame:self.bounds];
13
- _pdfView.displayBox = kPDFDisplayBoxCropBox;
14
- _pdfView.autoScales = NO;
15
- _pdfView.displayMode = kPDFDisplaySinglePage;
16
- _pdfView.displayDirection = kPDFDisplayDirectionVertical;
17
- _pdfView.displaysPageBreaks = NO;
18
- _pdfView.userInteractionEnabled = NO;
19
- [self addSubview:_pdfView];
20
- }
21
- return self;
22
- }
23
-
24
- - (void)layoutSubviews {
25
- [super layoutSubviews];
26
- self.pdfView.frame = self.bounds;
27
- }
28
-
29
- - (void)renderWithDocument:(PDFDocument *_Nullable)document
30
- pageIndex:(NSInteger)pageIndex
31
- scale:(CGFloat)scale
32
- zoom:(CGFloat)zoom
33
- rotation:(NSInteger)rotation {
34
- if (!document) {
35
- self.pdfView.document = nil;
36
- return;
37
- }
38
-
39
- if (self.pdfView.document != document) {
40
- self.pdfView.document = document;
41
- }
42
-
43
- PDFPage *page = [document pageAtIndex:pageIndex];
44
- if (!page) return;
45
-
46
- page.rotation = (int)rotation;
47
- [self.pdfView goToPage:page];
48
-
49
- CGFloat clampedZoom = MAX(0.1, MIN(5.0, zoom));
50
- CGFloat baseScale = self.pdfView.scaleFactorForSizeToFit;
51
- CGFloat targetScale = baseScale * MAX(0.1, scale) * clampedZoom;
52
- self.pdfView.scaleFactor = targetScale;
53
- }
54
-
55
- - (CGRect)convertRectToPage:(CGRect)rect page:(PDFPage *)page {
56
- return [self.pdfView convertRect:rect toPage:page];
57
- }
58
-
59
- - (CGRect)convertRectFromPage:(CGRect)rect page:(PDFPage *)page {
60
- return [self.pdfView convertRect:rect fromPage:page];
61
- }
62
-
63
- @end
1
+ #import "PapyrusPageView.h"
2
+
3
+ #import <CoreImage/CoreImage.h>
4
+
5
+ @interface PapyrusPageView ()
6
+ @property (nonatomic, strong) PDFView *pdfView;
7
+ @property (nonatomic, strong) UIImageView *imageView;
8
+ @property (nonatomic, strong) CIContext *ciContext;
9
+ @property (nonatomic, weak) PDFDocument *currentDocument;
10
+ @property (nonatomic, assign) NSInteger currentPageIndex;
11
+ @property (nonatomic, assign) NSInteger currentRotation;
12
+ @property (nonatomic, assign) CGFloat currentScale;
13
+ @property (nonatomic, assign) CGFloat currentZoom;
14
+ @end
15
+
16
+ @implementation PapyrusPageView
17
+
18
+ - (instancetype)initWithFrame:(CGRect)frame {
19
+ self = [super initWithFrame:frame];
20
+ if (self) {
21
+ _pageTheme = @"normal";
22
+ _currentPageIndex = NSNotFound;
23
+ _currentRotation = 0;
24
+ _currentScale = 1.0;
25
+ _currentZoom = 1.0;
26
+ _ciContext = [CIContext contextWithOptions:nil];
27
+
28
+ _pdfView = [[PDFView alloc] initWithFrame:self.bounds];
29
+ _pdfView.displayBox = kPDFDisplayBoxCropBox;
30
+ _pdfView.autoScales = NO;
31
+ _pdfView.displayMode = kPDFDisplaySinglePage;
32
+ _pdfView.displayDirection = kPDFDisplayDirectionVertical;
33
+ _pdfView.displaysPageBreaks = NO;
34
+ _pdfView.userInteractionEnabled = NO;
35
+ _pdfView.hidden = YES;
36
+ [self addSubview:_pdfView];
37
+
38
+ _imageView = [[UIImageView alloc] initWithFrame:self.bounds];
39
+ _imageView.contentMode = UIViewContentModeScaleAspectFit;
40
+ _imageView.clipsToBounds = YES;
41
+ [self addSubview:_imageView];
42
+ }
43
+ return self;
44
+ }
45
+
46
+ - (void)layoutSubviews {
47
+ [super layoutSubviews];
48
+ self.pdfView.frame = self.bounds;
49
+ self.imageView.frame = self.bounds;
50
+ [self rerenderCurrentPageIfNeeded];
51
+ }
52
+
53
+ - (void)setPageTheme:(NSString *)pageTheme {
54
+ NSString *normalized = pageTheme.length > 0 ? pageTheme : @"normal";
55
+ if ([_pageTheme isEqualToString:normalized]) return;
56
+ _pageTheme = [normalized copy];
57
+ [self rerenderCurrentPageIfNeeded];
58
+ }
59
+
60
+ - (void)renderWithDocument:(PDFDocument *_Nullable)document
61
+ pageIndex:(NSInteger)pageIndex
62
+ scale:(CGFloat)scale
63
+ zoom:(CGFloat)zoom
64
+ rotation:(NSInteger)rotation {
65
+ self.currentDocument = document;
66
+ self.currentPageIndex = pageIndex;
67
+ self.currentRotation = rotation;
68
+ self.currentScale = scale;
69
+ self.currentZoom = zoom;
70
+
71
+ if (!document) {
72
+ self.pdfView.document = nil;
73
+ self.imageView.image = nil;
74
+ return;
75
+ }
76
+
77
+ if (self.pdfView.document != document) {
78
+ self.pdfView.document = document;
79
+ }
80
+
81
+ PDFPage *page = [document pageAtIndex:pageIndex];
82
+ if (!page) return;
83
+
84
+ page.rotation = (int)rotation;
85
+ [self.pdfView goToPage:page];
86
+
87
+ CGFloat clampedZoom = MAX(0.1, MIN(5.0, zoom));
88
+ CGFloat baseScale = self.pdfView.scaleFactorForSizeToFit;
89
+ CGFloat targetScale = baseScale * MAX(0.1, scale) * clampedZoom;
90
+ self.pdfView.scaleFactor = targetScale;
91
+
92
+ [self rerenderCurrentPageIfNeeded];
93
+ }
94
+
95
+ - (CGRect)convertRectToPage:(CGRect)rect page:(PDFPage *)page {
96
+ return [self.pdfView convertRect:rect toPage:page];
97
+ }
98
+
99
+ - (CGRect)convertRectFromPage:(CGRect)rect page:(PDFPage *)page {
100
+ return [self.pdfView convertRect:rect fromPage:page];
101
+ }
102
+
103
+ - (void)rerenderCurrentPageIfNeeded {
104
+ if (!self.currentDocument) return;
105
+ if (self.currentPageIndex == NSNotFound) return;
106
+ if (CGRectGetWidth(self.bounds) <= 0 || CGRectGetHeight(self.bounds) <= 0) {
107
+ return;
108
+ }
109
+
110
+ PDFPage *page = [self.currentDocument pageAtIndex:self.currentPageIndex];
111
+ if (!page) return;
112
+
113
+ UIImage *baseImage = [self renderImageForPage:page];
114
+ self.imageView.image = [self themedImageFromImage:baseImage];
115
+ }
116
+
117
+ - (UIImage *)renderImageForPage:(PDFPage *)page {
118
+ CGSize targetSize = self.bounds.size;
119
+ UIGraphicsImageRendererFormat *format =
120
+ [UIGraphicsImageRendererFormat defaultFormat];
121
+ format.opaque = YES;
122
+ format.scale = UIScreen.mainScreen.scale;
123
+
124
+ UIGraphicsImageRenderer *renderer =
125
+ [[UIGraphicsImageRenderer alloc] initWithSize:targetSize format:format];
126
+
127
+ return [renderer imageWithActions:^(UIGraphicsImageRendererContext *_Nonnull context) {
128
+ CGContextRef cgContext = context.CGContext;
129
+ CGContextSetFillColorWithColor(cgContext, UIColor.whiteColor.CGColor);
130
+ CGContextFillRect(cgContext, (CGRect){CGPointZero, targetSize});
131
+
132
+ CGRect pageBounds = [page boundsForBox:kPDFDisplayBoxCropBox];
133
+ if (CGRectGetWidth(pageBounds) <= 0 || CGRectGetHeight(pageBounds) <= 0) {
134
+ return;
135
+ }
136
+
137
+ CGFloat scaleX = targetSize.width / CGRectGetWidth(pageBounds);
138
+ CGFloat scaleY = targetSize.height / CGRectGetHeight(pageBounds);
139
+ CGFloat fitScale = MIN(scaleX, scaleY);
140
+ CGFloat drawWidth = CGRectGetWidth(pageBounds) * fitScale;
141
+ CGFloat drawHeight = CGRectGetHeight(pageBounds) * fitScale;
142
+ CGFloat offsetX = (targetSize.width - drawWidth) / 2.0;
143
+ CGFloat offsetY = (targetSize.height - drawHeight) / 2.0;
144
+
145
+ CGContextSaveGState(cgContext);
146
+ CGContextTranslateCTM(cgContext, 0, targetSize.height);
147
+ CGContextScaleCTM(cgContext, 1, -1);
148
+ CGContextTranslateCTM(cgContext, offsetX, offsetY);
149
+ CGContextScaleCTM(cgContext, fitScale, fitScale);
150
+ [page drawWithBox:kPDFDisplayBoxCropBox toContext:cgContext];
151
+ CGContextRestoreGState(cgContext);
152
+ }];
153
+ }
154
+
155
+ - (UIImage *)themedImageFromImage:(UIImage *)image {
156
+ if (!image) return nil;
157
+ if ([self.pageTheme isEqualToString:@"normal"]) return image;
158
+
159
+ CIImage *input = [[CIImage alloc] initWithImage:image];
160
+ if (!input) return image;
161
+
162
+ CIImage *output = input;
163
+
164
+ if ([self.pageTheme isEqualToString:@"sepia"]) {
165
+ CIFilter *sepia = [CIFilter filterWithName:@"CISepiaTone"];
166
+ [sepia setValue:output forKey:kCIInputImageKey];
167
+ [sepia setValue:@0.85 forKey:kCIInputIntensityKey];
168
+ output = sepia.outputImage ?: output;
169
+ } else if ([self.pageTheme isEqualToString:@"dark"] ||
170
+ [self.pageTheme isEqualToString:@"high-contrast"]) {
171
+ CIFilter *invert = [CIFilter filterWithName:@"CIColorInvert"];
172
+ [invert setValue:output forKey:kCIInputImageKey];
173
+ output = invert.outputImage ?: output;
174
+
175
+ CIFilter *controls = [CIFilter filterWithName:@"CIColorControls"];
176
+ [controls setValue:output forKey:kCIInputImageKey];
177
+ [controls setValue:@0 forKey:kCIInputSaturationKey];
178
+ [controls setValue:([self.pageTheme isEqualToString:@"high-contrast"] ? @1.25 : @0.9)
179
+ forKey:kCIInputContrastKey];
180
+ [controls setValue:([self.pageTheme isEqualToString:@"high-contrast"] ? @0.02 : @-0.08)
181
+ forKey:kCIInputBrightnessKey];
182
+ output = controls.outputImage ?: output;
183
+ }
184
+
185
+ CGImageRef cgImage = [self.ciContext createCGImage:output fromRect:output.extent];
186
+ if (!cgImage) return image;
187
+ UIImage *result = [UIImage imageWithCGImage:cgImage
188
+ scale:image.scale
189
+ orientation:image.imageOrientation];
190
+ CGImageRelease(cgImage);
191
+ return result;
192
+ }
193
+
194
+ @end
@@ -1,19 +1,20 @@
1
- #import <React/RCTViewManager.h>
2
- #import "PapyrusPageView.h"
3
-
4
- @interface PapyrusPageViewManager : RCTViewManager
5
- @end
6
-
7
- @implementation PapyrusPageViewManager
8
-
9
- RCT_EXPORT_MODULE(PapyrusPageView)
10
-
11
- + (BOOL)requiresMainQueueSetup {
12
- return YES;
13
- }
14
-
15
- - (UIView *)view {
16
- return [[PapyrusPageView alloc] initWithFrame:CGRectZero];
17
- }
18
-
19
- @end
1
+ #import <React/RCTViewManager.h>
2
+ #import "PapyrusPageView.h"
3
+
4
+ @interface PapyrusPageViewManager : RCTViewManager
5
+ @end
6
+
7
+ @implementation PapyrusPageViewManager
8
+
9
+ RCT_EXPORT_MODULE(PapyrusPageView)
10
+ RCT_EXPORT_VIEW_PROPERTY(pageTheme, NSString)
11
+
12
+ + (BOOL)requiresMainQueueSetup {
13
+ return YES;
14
+ }
15
+
16
+ - (UIView *)view {
17
+ return [[PapyrusPageView alloc] initWithFrame:CGRectZero];
18
+ }
19
+
20
+ @end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@papyrus-sdk/engine-native",
3
- "version": "0.2.11",
3
+ "version": "0.2.12-beta.0",
4
4
  "license": "MIT",
5
5
  "keywords": [
6
6
  "papyrus",
@@ -13,12 +13,14 @@
13
13
  "viewer"
14
14
  ],
15
15
  "main": "dist/index.js",
16
- "module": "dist/index.mjs",
16
+ "react-native": "dist/index.js",
17
+ "module": "dist/index.js",
17
18
  "types": "dist/index.d.ts",
18
19
  "exports": {
19
20
  ".": {
21
+ "react-native": "./dist/index.js",
20
22
  "types": "./dist/index.d.ts",
21
- "import": "./dist/index.mjs",
23
+ "import": "./dist/index.js",
22
24
  "require": "./dist/index.js"
23
25
  }
24
26
  },
@@ -43,17 +45,18 @@
43
45
  "bugs": {
44
46
  "url": "https://github.com/solrachix/Papyrus/issues"
45
47
  },
48
+ "scripts": {
49
+ "build": "tsup index.ts --dts --format cjs,esm --out-dir dist --clean --sourcemap",
50
+ "prepublishOnly": "pnpm build"
51
+ },
46
52
  "peerDependencies": {
47
- "@papyrus-sdk/core": ">=0.2.1",
48
- "@papyrus-sdk/types": ">=0.2.1",
53
+ "@papyrus-sdk/core": ">=0.2.15-beta.0",
54
+ "@papyrus-sdk/types": ">=0.2.8-beta.0",
49
55
  "react-native": ">=0.81.0"
50
56
  },
51
57
  "devDependencies": {
52
- "@papyrus-sdk/core": "0.2.1",
53
- "@papyrus-sdk/types": "0.2.1",
58
+ "@papyrus-sdk/core": "0.2.15-beta.0",
59
+ "@papyrus-sdk/types": "0.2.8-beta.0",
54
60
  "react-native": "^0.81.0"
55
- },
56
- "scripts": {
57
- "build": "tsup index.ts --dts --format cjs,esm --out-dir dist --clean --sourcemap"
58
61
  }
59
- }
62
+ }
@@ -1,10 +1,10 @@
1
- module.exports = {
2
- project: {
3
- ios: {
4
- podspecPath: 'ios/PapyrusNativeEngine.podspec',
5
- },
6
- android: {
7
- sourceDir: 'android',
8
- },
9
- },
10
- };
1
+ module.exports = {
2
+ project: {
3
+ ios: {
4
+ podspecPath: 'ios/PapyrusNativeEngine.podspec',
5
+ },
6
+ android: {
7
+ sourceDir: 'android',
8
+ },
9
+ },
10
+ };
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Papyrus Contributors
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.