@papyrus-sdk/engine-native 0.2.22-beta.5 → 0.2.22-beta.7
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/{ios/PapyrusNativeEngine.podspec → PapyrusNativeEngine.podspec} +11 -7
- package/android/src/main/cpp/papyrus_outline_loader_test.cpp +240 -0
- package/android/src/main/cpp/papyrus_text_word_test.cpp +72 -0
- 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 +13 -1
- 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 +21 -6
- package/ios/PapyrusPdfDocumentView.h +3 -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 +8 -8
- package/react-native.config.js +1 -1
- package/vendor/libarchive/README.papyrus.md +1 -1
- package/vendor/libarchive/config/PapyrusArchiveConfig.h +6 -0
|
@@ -16,6 +16,7 @@ RCT_EXPORT_VIEW_PROPERTY(viewMode, NSString)
|
|
|
16
16
|
RCT_EXPORT_VIEW_PROPERTY(searchResults, NSArray)
|
|
17
17
|
RCT_EXPORT_VIEW_PROPERTY(activeSearchIndex, NSInteger)
|
|
18
18
|
RCT_EXPORT_VIEW_PROPERTY(annotations, NSArray)
|
|
19
|
+
RCT_EXPORT_VIEW_PROPERTY(annotationNavigationRequest, NSDictionary)
|
|
19
20
|
RCT_EXPORT_VIEW_PROPERTY(activeTool, NSString)
|
|
20
21
|
RCT_EXPORT_VIEW_PROPERTY(activeDrawToolPreset, NSString)
|
|
21
22
|
RCT_EXPORT_VIEW_PROPERTY(inkStrokeWidth, CGFloat)
|
|
@@ -25,6 +26,8 @@ RCT_EXPORT_VIEW_PROPERTY(annotationOpacity, CGFloat)
|
|
|
25
26
|
RCT_EXPORT_VIEW_PROPERTY(selectedAnnotationId, NSString)
|
|
26
27
|
RCT_EXPORT_VIEW_PROPERTY(selectionActive, BOOL)
|
|
27
28
|
RCT_EXPORT_VIEW_PROPERTY(defineLabel, NSString)
|
|
29
|
+
RCT_EXPORT_VIEW_PROPERTY(copyLabel, NSString)
|
|
30
|
+
RCT_EXPORT_VIEW_PROPERTY(selectAllLabel, NSString)
|
|
28
31
|
RCT_EXPORT_VIEW_PROPERTY(defineSelectionMode, NSString)
|
|
29
32
|
RCT_EXPORT_VIEW_PROPERTY(annotateLabel, NSString)
|
|
30
33
|
RCT_EXPORT_VIEW_PROPERTY(annotationHighlightLabel, NSString)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#import <UIKit/UIKit.h>
|
|
2
|
+
|
|
3
|
+
// Keep system submenus and command targets, localizing only standard edit actions.
|
|
4
|
+
static inline NSArray<UIMenuElement *> *PapyrusLocalizedSelectionActions(
|
|
5
|
+
NSArray<UIMenuElement *> *elements, NSString *copyLabel, NSString *selectAllLabel) API_AVAILABLE(ios(13.0)) {
|
|
6
|
+
NSMutableArray<UIMenuElement *> *result = [NSMutableArray array];
|
|
7
|
+
for (UIMenuElement *element in elements) {
|
|
8
|
+
if ([element isKindOfClass:UIMenu.class]) {
|
|
9
|
+
UIMenu *menu = (UIMenu *)element;
|
|
10
|
+
[result addObject:[menu menuByReplacingChildren:
|
|
11
|
+
PapyrusLocalizedSelectionActions(menu.children, copyLabel, selectAllLabel)]];
|
|
12
|
+
} else if ([element isKindOfClass:UICommand.class]) {
|
|
13
|
+
UICommand *command = (UICommand *)element;
|
|
14
|
+
NSString *title = command.action == @selector(copy:) ? copyLabel :
|
|
15
|
+
command.action == @selector(selectAll:) ? selectAllLabel : nil;
|
|
16
|
+
if (title.length) {
|
|
17
|
+
UICommand *translated = [UICommand commandWithTitle:title
|
|
18
|
+
image:command.image ?: [UIImage systemImageNamed:@"doc.on.doc"]
|
|
19
|
+
action:command.action propertyList:command.propertyList];
|
|
20
|
+
translated.attributes = command.attributes;
|
|
21
|
+
translated.state = command.state;
|
|
22
|
+
[result addObject:translated];
|
|
23
|
+
} else [result addObject:element];
|
|
24
|
+
} else [result addObject:element];
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#import "PapyrusTextAnnotationRange.h"
|
|
2
|
+
static BOOL PapyrusTextBoundary(NSString *text, NSUInteger offset) {
|
|
3
|
+
return offset <= text.length && !(offset > 0 && offset < text.length && CFStringIsSurrogateHighCharacter([text characterAtIndex:offset-1]) && CFStringIsSurrogateLowCharacter([text characterAtIndex:offset]));
|
|
4
|
+
}
|
|
5
|
+
NSRange PapyrusResolveTextAnnotationRange(NSString *text, NSDictionary *anchor) {
|
|
6
|
+
if (![anchor isKindOfClass:NSDictionary.class]) return NSMakeRange(NSNotFound,0);
|
|
7
|
+
NSString *quote = [anchor[@"quote"] isKindOfClass:NSString.class] ? anchor[@"quote"] : nil;
|
|
8
|
+
if (![text isKindOfClass:NSString.class] || ![anchor[@"start"] isKindOfClass:NSNumber.class] || ![anchor[@"end"] isKindOfClass:NSNumber.class]) return NSMakeRange(NSNotFound,0);
|
|
9
|
+
NSInteger start = [anchor[@"start"] integerValue], end = [anchor[@"end"] integerValue];
|
|
10
|
+
if (!quote.length) return NSMakeRange(NSNotFound,0);
|
|
11
|
+
if (start >= 0 && end > start && end <= text.length && PapyrusTextBoundary(text,start) && PapyrusTextBoundary(text,end)) {
|
|
12
|
+
NSRange exact = NSMakeRange(start,end-start);
|
|
13
|
+
if ([[text substringWithRange:exact] isEqual:quote]) return exact;
|
|
14
|
+
}
|
|
15
|
+
NSString *prefix = [anchor[@"prefix"] isKindOfClass:NSString.class] ? anchor[@"prefix"] : @"";
|
|
16
|
+
NSString *suffix = [anchor[@"suffix"] isKindOfClass:NSString.class] ? anchor[@"suffix"] : @"";
|
|
17
|
+
NSRange match = NSMakeRange(NSNotFound,0);
|
|
18
|
+
NSUInteger offset = 0;
|
|
19
|
+
while (offset < text.length) {
|
|
20
|
+
NSRange candidate = [text rangeOfString:quote options:NSLiteralSearch range:NSMakeRange(offset,text.length-offset)];
|
|
21
|
+
if (candidate.location == NSNotFound) break;
|
|
22
|
+
NSUInteger endOffset = NSMaxRange(candidate);
|
|
23
|
+
BOOL validPrefix = prefix.length == 0 || (candidate.location >= prefix.length && [[text substringWithRange:NSMakeRange(candidate.location-prefix.length,prefix.length)] isEqual:prefix]);
|
|
24
|
+
BOOL validSuffix = suffix.length == 0 || (endOffset+suffix.length <= text.length && [[text substringWithRange:NSMakeRange(endOffset,suffix.length)] isEqual:suffix]);
|
|
25
|
+
if (validPrefix && validSuffix && PapyrusTextBoundary(text,candidate.location) && PapyrusTextBoundary(text,endOffset)) { if (match.location != NSNotFound) return NSMakeRange(NSNotFound,0); match = candidate; }
|
|
26
|
+
offset = candidate.location+1;
|
|
27
|
+
}
|
|
28
|
+
return match;
|
|
29
|
+
}
|
|
@@ -10,7 +10,12 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
10
10
|
@property (nonatomic, assign) NSInteger textLength;
|
|
11
11
|
@property (nonatomic, assign) NSInteger currentTextOffset;
|
|
12
12
|
@property (nonatomic, strong, nullable) NSNumber *scrollToTextOffsetSignal;
|
|
13
|
+
@property (nonatomic, copy, nullable) NSDictionary *textNavigationRequest;
|
|
13
14
|
@property (nonatomic, copy) NSArray<NSDictionary *> *searchResults;
|
|
15
|
+
@property (nonatomic, copy) NSArray<NSDictionary *> *annotations;
|
|
16
|
+
@property (nonatomic, copy) NSDictionary<NSString *, NSString *> *annotationLabels;
|
|
17
|
+
@property (nonatomic, copy, nullable) RCTBubblingEventBlock onAnnotateSelection;
|
|
18
|
+
@property (nonatomic, copy, nullable) RCTBubblingEventBlock onAnnotationTap;
|
|
14
19
|
@property (nonatomic, assign) NSInteger activeSearchIndex;
|
|
15
20
|
@property (nonatomic, copy) NSString *pageTheme;
|
|
16
21
|
@property (nonatomic, copy) NSString *uiTheme;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
#import "PapyrusSelectionMenu.h"
|
|
1
2
|
#import "PapyrusTextDocumentView.h"
|
|
2
3
|
#import "PapyrusTextStore.h"
|
|
4
|
+
#import "PapyrusTextAnnotationRange.h"
|
|
3
5
|
|
|
4
6
|
static NSUInteger const PapyrusMaximumTextSearchHighlights = 2000;
|
|
5
7
|
|
|
6
|
-
@interface PapyrusTextDocumentView () <UITextViewDelegate>
|
|
8
|
+
@interface PapyrusTextDocumentView () <UITextViewDelegate, UIGestureRecognizerDelegate>
|
|
7
9
|
@property (nonatomic, strong) UITextView *textView;
|
|
8
10
|
@property (nonatomic, assign) NSInteger lastReportedStart;
|
|
9
11
|
@property (nonatomic, assign) NSInteger lastReportedEnd;
|
|
@@ -11,6 +13,10 @@ static NSUInteger const PapyrusMaximumTextSearchHighlights = 2000;
|
|
|
11
13
|
@property (nonatomic, assign) CFAbsoluteTime lastOffsetEventTime;
|
|
12
14
|
@property (nonatomic, assign) BOOL hasLoadedDocument;
|
|
13
15
|
@property (nonatomic, assign) BOOL suppressOffsetEvents;
|
|
16
|
+
@property (nonatomic, strong) NSMutableDictionary<NSString *, UIButton *> *noteButtons;
|
|
17
|
+
@property (nonatomic, strong) NSMutableDictionary<NSString *, NSValue *> *resolvedAnnotationRanges;
|
|
18
|
+
@property (nonatomic, copy) NSString *resolvedAnnotationText;
|
|
19
|
+
@property (nonatomic, strong) NSMutableDictionary<NSString *, NSArray<NSString *> *> *noteGroups;
|
|
14
20
|
@end
|
|
15
21
|
|
|
16
22
|
@implementation PapyrusTextDocumentView
|
|
@@ -20,6 +26,9 @@ static NSUInteger const PapyrusMaximumTextSearchHighlights = 2000;
|
|
|
20
26
|
if (self) {
|
|
21
27
|
self.backgroundColor = UIColor.whiteColor;
|
|
22
28
|
_searchResults = @[];
|
|
29
|
+
_annotations = @[];
|
|
30
|
+
_annotationLabels = @{};
|
|
31
|
+
_noteButtons = [NSMutableDictionary dictionary];
|
|
23
32
|
_activeSearchIndex = -1;
|
|
24
33
|
_pageTheme = @"normal";
|
|
25
34
|
_uiTheme = @"light";
|
|
@@ -32,11 +41,14 @@ static NSUInteger const PapyrusMaximumTextSearchHighlights = 2000;
|
|
|
32
41
|
_textView = [[UITextView alloc] initWithFrame:self.bounds];
|
|
33
42
|
_textView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
|
34
43
|
_textView.delegate = self;
|
|
44
|
+
UITapGestureRecognizer *annotationTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTextAnnotation:)];
|
|
45
|
+
annotationTap.cancelsTouchesInView = NO; annotationTap.delegate = self;
|
|
46
|
+
[_textView addGestureRecognizer:annotationTap];
|
|
35
47
|
_textView.editable = NO;
|
|
36
48
|
_textView.selectable = YES;
|
|
37
49
|
_textView.alwaysBounceVertical = YES;
|
|
38
50
|
_textView.scrollsToTop = YES;
|
|
39
|
-
_textView.textContainerInset = UIEdgeInsetsMake(_pageMargin, _pageMargin, _pageMargin, _pageMargin);
|
|
51
|
+
_textView.textContainerInset = UIEdgeInsetsMake(_pageMargin, MAX(44,_pageMargin), _pageMargin, _pageMargin);
|
|
40
52
|
_textView.backgroundColor = UIColor.whiteColor;
|
|
41
53
|
_textView.textColor = UIColor.blackColor;
|
|
42
54
|
[self addSubview:_textView];
|
|
@@ -60,6 +72,7 @@ static NSUInteger const PapyrusMaximumTextSearchHighlights = 2000;
|
|
|
60
72
|
- (void)layoutSubviews {
|
|
61
73
|
[super layoutSubviews];
|
|
62
74
|
[self reloadTextIfAvailable];
|
|
75
|
+
[self layoutNoteButtons];
|
|
63
76
|
}
|
|
64
77
|
|
|
65
78
|
- (void)setEngineId:(NSString *)engineId {
|
|
@@ -90,6 +103,12 @@ static NSUInteger const PapyrusMaximumTextSearchHighlights = 2000;
|
|
|
90
103
|
[self scrollToTextOffset:scrollToTextOffsetSignal.integerValue];
|
|
91
104
|
}
|
|
92
105
|
|
|
106
|
+
- (void)setTextNavigationRequest:(NSDictionary *)request {
|
|
107
|
+
if (![request isKindOfClass:NSDictionary.class] || [_textNavigationRequest isEqual:request]) return;
|
|
108
|
+
_textNavigationRequest = [request copy];
|
|
109
|
+
[self scrollToTextOffset:MAX(0,[request[@"offset"] integerValue])];
|
|
110
|
+
}
|
|
111
|
+
|
|
93
112
|
- (void)setSearchResults:(NSArray<NSDictionary *> *)searchResults {
|
|
94
113
|
_searchResults = [searchResults copy] ?: @[];
|
|
95
114
|
[self applySearchHighlights];
|
|
@@ -124,15 +143,12 @@ static NSUInteger const PapyrusMaximumTextSearchHighlights = 2000;
|
|
|
124
143
|
|
|
125
144
|
- (void)setPageMargin:(CGFloat)pageMargin {
|
|
126
145
|
_pageMargin = MAX(8, MIN(64, pageMargin));
|
|
127
|
-
self.textView.textContainerInset = UIEdgeInsetsMake(_pageMargin, _pageMargin, _pageMargin, _pageMargin);
|
|
146
|
+
self.textView.textContainerInset = UIEdgeInsetsMake(_pageMargin, MAX(44,_pageMargin), _pageMargin, _pageMargin);
|
|
128
147
|
}
|
|
129
148
|
|
|
130
149
|
- (void)setDefineLabel:(NSString *)defineLabel {
|
|
131
150
|
_defineLabel = [defineLabel copy] ?: @"Define";
|
|
132
|
-
|
|
133
|
-
UIMenuController.sharedMenuController.menuItems = @[
|
|
134
|
-
[[UIMenuItem alloc] initWithTitle:_defineLabel action:@selector(defineCurrentSelection:)]
|
|
135
|
-
];
|
|
151
|
+
[self setAnnotationLabels:self.annotationLabels];
|
|
136
152
|
}
|
|
137
153
|
|
|
138
154
|
- (void)setDefineSelectionMode:(NSString *)defineSelectionMode {
|
|
@@ -173,11 +189,11 @@ static NSUInteger const PapyrusMaximumTextSearchHighlights = 2000;
|
|
|
173
189
|
self.textView.backgroundColor = paper;
|
|
174
190
|
self.textView.textColor = foreground;
|
|
175
191
|
self.textView.font = [UIFont systemFontOfSize:self.fontSize];
|
|
176
|
-
self.textView.textContainerInset = UIEdgeInsetsMake(_pageMargin, _pageMargin, _pageMargin, _pageMargin);
|
|
192
|
+
self.textView.textContainerInset = UIEdgeInsetsMake(_pageMargin, MAX(44,_pageMargin), _pageMargin, _pageMargin);
|
|
177
193
|
if (self.textView.text.length > 0) {
|
|
178
194
|
NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
|
|
179
|
-
paragraph.minimumLineHeight = self.lineHeight;
|
|
180
|
-
paragraph.maximumLineHeight = self.lineHeight;
|
|
195
|
+
paragraph.minimumLineHeight = MAX(self.lineHeight,self.fontSize);
|
|
196
|
+
paragraph.maximumLineHeight = MAX(self.lineHeight,self.fontSize);
|
|
181
197
|
paragraph.lineBreakMode = NSLineBreakByWordWrapping;
|
|
182
198
|
[self.textView.textStorage addAttribute:NSParagraphStyleAttributeName
|
|
183
199
|
value:paragraph
|
|
@@ -188,7 +204,8 @@ static NSUInteger const PapyrusMaximumTextSearchHighlights = 2000;
|
|
|
188
204
|
- (void)applySearchHighlights {
|
|
189
205
|
if (!self.hasLoadedDocument || self.textView.text.length == 0) return;
|
|
190
206
|
NSTextStorage *storage = self.textView.textStorage;
|
|
191
|
-
[storage removeAttribute:
|
|
207
|
+
for (NSAttributedStringKey key in @[NSBackgroundColorAttributeName, NSUnderlineStyleAttributeName, NSUnderlineColorAttributeName, NSStrikethroughStyleAttributeName, NSStrikethroughColorAttributeName, @"PapyrusAnnotationId"]) [storage removeAttribute:key range:NSMakeRange(0, storage.length)];
|
|
208
|
+
[self applyAnnotationAttributes];
|
|
192
209
|
NSUInteger count = MIN(self.searchResults.count, PapyrusMaximumTextSearchHighlights);
|
|
193
210
|
CGFloat normalAlpha = [self.pageTheme isEqualToString:@"dark"] ? 0.35 : 0.42;
|
|
194
211
|
UIColor *normal = [UIColor colorWithRed:1.0 green:0.79 blue:0.16 alpha:normalAlpha];
|
|
@@ -222,7 +239,13 @@ static NSUInteger const PapyrusMaximumTextSearchHighlights = 2000;
|
|
|
222
239
|
NSRange range = self.textView.selectedRange;
|
|
223
240
|
if (range.location == NSNotFound || range.length == 0 || NSMaxRange(range) > self.textView.text.length) return nil;
|
|
224
241
|
NSString *text = [self.textView.text substringWithRange:range];
|
|
225
|
-
|
|
242
|
+
NSUInteger prefixStart = range.location > 48 ? range.location - 48 : 0;
|
|
243
|
+
if (prefixStart > 0 && CFStringIsSurrogateLowCharacter([self.textView.text characterAtIndex:prefixStart])) prefixStart--;
|
|
244
|
+
NSUInteger suffixEnd = MIN(self.textView.text.length, NSMaxRange(range)+48);
|
|
245
|
+
if (suffixEnd < self.textView.text.length && CFStringIsSurrogateLowCharacter([self.textView.text characterAtIndex:suffixEnd])) suffixEnd++;
|
|
246
|
+
return @{ @"text": text, @"start": @(range.location), @"end": @(NSMaxRange(range)),
|
|
247
|
+
@"prefix": [self.textView.text substringWithRange:NSMakeRange(prefixStart, range.location - prefixStart)],
|
|
248
|
+
@"suffix": [self.textView.text substringWithRange:NSMakeRange(NSMaxRange(range), suffixEnd - NSMaxRange(range))] };
|
|
226
249
|
}
|
|
227
250
|
|
|
228
251
|
- (void)textViewDidChangeSelection:(UITextView *)textView {
|
|
@@ -275,6 +298,10 @@ static NSUInteger const PapyrusMaximumTextSearchHighlights = 2000;
|
|
|
275
298
|
return [self selectedRangePayload] != nil &&
|
|
276
299
|
(![self.defineSelectionMode isEqualToString:@"single-word"] || [self isSingleWordSelection]);
|
|
277
300
|
}
|
|
301
|
+
if (action == @selector(highlightSelection:) || action == @selector(underlineSelection:) ||
|
|
302
|
+
action == @selector(strikeoutSelection:) || action == @selector(noteSelection:)) {
|
|
303
|
+
return self.onAnnotateSelection != nil && [self selectedRangePayload] != nil;
|
|
304
|
+
}
|
|
278
305
|
return [super canPerformAction:action withSender:sender];
|
|
279
306
|
}
|
|
280
307
|
|
|
@@ -284,16 +311,208 @@ editMenuForTextInRange:(NSRange)range
|
|
|
284
311
|
if (range.location != NSNotFound && range.length > 0 && NSMaxRange(range) <= textView.text.length) {
|
|
285
312
|
textView.selectedRange = range;
|
|
286
313
|
}
|
|
287
|
-
NSMutableArray<UIMenuElement *> *actions = [suggestedActions mutableCopy] ?: [NSMutableArray array];
|
|
314
|
+
NSMutableArray<UIMenuElement *> *actions = [PapyrusLocalizedSelectionActions(suggestedActions, self.annotationLabels[@"copy"], self.annotationLabels[@"selectAll"]) mutableCopy] ?: [NSMutableArray array];
|
|
288
315
|
if ([self selectedRangePayload] &&
|
|
289
316
|
(![self.defineSelectionMode isEqualToString:@"single-word"] || [self isSingleWordSelection])) {
|
|
290
|
-
UIAction *define = [UIAction actionWithTitle:self.defineLabel image:
|
|
317
|
+
UIAction *define = [UIAction actionWithTitle:self.defineLabel image:[UIImage systemImageNamed:@"text.magnifyingglass"] identifier:nil handler:^(__kindof UIAction *action) {
|
|
291
318
|
#pragma unused(action)
|
|
292
319
|
[self defineCurrentSelection:nil];
|
|
293
320
|
}];
|
|
294
321
|
[actions insertObject:define atIndex:0];
|
|
295
322
|
}
|
|
323
|
+
if ([self selectedRangePayload] && self.onAnnotateSelection) {
|
|
324
|
+
NSMutableArray *marks = [NSMutableArray array];
|
|
325
|
+
for (NSString *style in @[@"highlight", @"underline", @"strikeout", @"comment"]) {
|
|
326
|
+
NSString *label = self.annotationLabels[style];
|
|
327
|
+
if (!label.length) continue;
|
|
328
|
+
NSDictionary *symbols = @{@"highlight":@"highlighter", @"underline":@"underline",
|
|
329
|
+
@"strikeout":@"strikethrough", @"comment":@"note.text"};
|
|
330
|
+
[marks addObject:[UIAction actionWithTitle:label image:[UIImage systemImageNamed:symbols[style]] identifier:nil handler:^(__kindof UIAction *action) {
|
|
331
|
+
[self emitAnnotationIntent:style];
|
|
332
|
+
}]];
|
|
333
|
+
}
|
|
334
|
+
if (marks.count) [actions insertObject:[UIMenu menuWithTitle:self.annotationLabels[@"annotate"] ?: @"" children:marks] atIndex:0];
|
|
335
|
+
}
|
|
296
336
|
return [UIMenu menuWithChildren:actions];
|
|
297
337
|
}
|
|
298
338
|
|
|
339
|
+
|
|
340
|
+
- (void)setAnnotations:(NSArray<NSDictionary *> *)value {
|
|
341
|
+
_annotations = [value copy] ?: @[];
|
|
342
|
+
self.resolvedAnnotationRanges = [NSMutableDictionary dictionary];
|
|
343
|
+
[self applySearchHighlights];
|
|
344
|
+
}
|
|
345
|
+
- (void)setAnnotationLabels:(NSDictionary<NSString *,NSString *> *)value {
|
|
346
|
+
_annotationLabels = [value copy] ?: @{};
|
|
347
|
+
if (@available(iOS 16.0, *)) return;
|
|
348
|
+
NSMutableArray *items = [NSMutableArray array];
|
|
349
|
+
[items addObject:[[UIMenuItem alloc] initWithTitle:self.defineLabel action:@selector(defineCurrentSelection:)]];
|
|
350
|
+
NSArray *styles = @[@"highlight", @"underline", @"strikeout", @"comment"];
|
|
351
|
+
NSArray *selectors = @[@"highlightSelection:", @"underlineSelection:", @"strikeoutSelection:", @"noteSelection:"];
|
|
352
|
+
for (NSUInteger i=0; i<styles.count; i++) if (_annotationLabels[styles[i]].length) [items addObject:[[UIMenuItem alloc] initWithTitle:_annotationLabels[styles[i]] action:NSSelectorFromString(selectors[i])]];
|
|
353
|
+
UIMenuController.sharedMenuController.menuItems = items;
|
|
354
|
+
}
|
|
355
|
+
- (void)highlightSelection:(id)sender { [self emitAnnotationIntent:@"highlight"]; }
|
|
356
|
+
- (void)underlineSelection:(id)sender { [self emitAnnotationIntent:@"underline"]; }
|
|
357
|
+
- (void)strikeoutSelection:(id)sender { [self emitAnnotationIntent:@"strikeout"]; }
|
|
358
|
+
- (void)noteSelection:(id)sender { [self emitAnnotationIntent:@"comment"]; }
|
|
359
|
+
- (void)emitAnnotationIntent:(NSString *)style {
|
|
360
|
+
NSDictionary *selection = [self selectedRangePayload];
|
|
361
|
+
if (!selection || !self.onAnnotateSelection) return;
|
|
362
|
+
NSMutableDictionary *payload = [selection mutableCopy];
|
|
363
|
+
payload[@"style"] = style;
|
|
364
|
+
self.onAnnotateSelection(@{ @"nativeEvent": payload });
|
|
365
|
+
}
|
|
366
|
+
- (NSRange)rangeForAnnotation:(NSDictionary *)annotation {
|
|
367
|
+
if (![annotation isKindOfClass:NSDictionary.class]) return NSMakeRange(NSNotFound,0);
|
|
368
|
+
NSString *identifier = annotation[@"id"];
|
|
369
|
+
if (![identifier isKindOfClass:NSString.class]) return NSMakeRange(NSNotFound,0);
|
|
370
|
+
if (![self.resolvedAnnotationText isEqual:self.textView.text]) {
|
|
371
|
+
self.resolvedAnnotationText = self.textView.text.copy;
|
|
372
|
+
self.resolvedAnnotationRanges = [NSMutableDictionary dictionary];
|
|
373
|
+
}
|
|
374
|
+
NSValue *cached = self.resolvedAnnotationRanges[identifier];
|
|
375
|
+
if (cached) return cached.rangeValue;
|
|
376
|
+
NSRange resolved = [self resolveRangeForAnnotation:annotation];
|
|
377
|
+
self.resolvedAnnotationRanges[identifier] = [NSValue valueWithRange:resolved];
|
|
378
|
+
return resolved;
|
|
379
|
+
}
|
|
380
|
+
- (NSRange)resolveRangeForAnnotation:(NSDictionary *)annotation {
|
|
381
|
+
if (![annotation isKindOfClass:NSDictionary.class]) return NSMakeRange(NSNotFound,0);
|
|
382
|
+
NSDictionary *anchor = [annotation[@"anchor"] isKindOfClass:NSDictionary.class] ? annotation[@"anchor"] : @{};
|
|
383
|
+
NSDictionary *range = [anchor[@"kind"] isEqual:@"text-range"] ? anchor : annotation[@"textRange"];
|
|
384
|
+
if (![range isKindOfClass:NSDictionary.class]) return NSMakeRange(NSNotFound, 0);
|
|
385
|
+
if (![range[@"start"] isKindOfClass:NSNumber.class] || ![range[@"end"] isKindOfClass:NSNumber.class]) return NSMakeRange(NSNotFound,0);
|
|
386
|
+
NSInteger start = [range[@"start"] integerValue], end = [range[@"end"] integerValue];
|
|
387
|
+
if ([anchor[@"kind"] isEqual:@"text-range"]) return PapyrusResolveTextAnnotationRange(self.textView.text,anchor);
|
|
388
|
+
if (start < 0 || end <= start || end > self.textView.text.length) return NSMakeRange(NSNotFound, 0);
|
|
389
|
+
NSRange result = NSMakeRange(start, end-start);
|
|
390
|
+
NSString *quote = anchor[@"quote"];
|
|
391
|
+
if ([quote isKindOfClass:NSString.class] && ![[self.textView.text substringWithRange:result] isEqual:quote]) return NSMakeRange(NSNotFound,0);
|
|
392
|
+
return result;
|
|
393
|
+
}
|
|
394
|
+
- (UIColor *)annotationColor:(NSDictionary *)annotation {
|
|
395
|
+
NSString *hex = annotation[@"color"];
|
|
396
|
+
unsigned int rgb = 0xFFC928;
|
|
397
|
+
if ([hex isKindOfClass:NSString.class]) [[NSScanner scannerWithString:[hex stringByReplacingOccurrencesOfString:@"#" withString:@""]] scanHexInt:&rgb];
|
|
398
|
+
return [UIColor colorWithRed:((rgb>>16)&255)/255.0 green:((rgb>>8)&255)/255.0 blue:(rgb&255)/255.0 alpha:1];
|
|
399
|
+
}
|
|
400
|
+
- (void)applyAnnotationAttributes {
|
|
401
|
+
NSMutableSet *visibleIds = [NSMutableSet set];
|
|
402
|
+
for (NSDictionary *annotation in self.annotations) {
|
|
403
|
+
NSRange range = [self rangeForAnnotation:annotation];
|
|
404
|
+
if (range.location == NSNotFound) continue;
|
|
405
|
+
NSString *style = annotation[@"markupStyle"] ?: annotation[@"type"];
|
|
406
|
+
UIColor *color = [self annotationColor:annotation];
|
|
407
|
+
NSTextStorage *storage = self.textView.textStorage;
|
|
408
|
+
if ([style isEqual:@"highlight"]) [storage addAttribute:NSBackgroundColorAttributeName value:[color colorWithAlphaComponent:annotation[@"opacity"] ? MAX(0,MIN(1,[annotation[@"opacity"] doubleValue])) : 0.35] range:range];
|
|
409
|
+
if ([style isEqual:@"underline"] || [style isEqual:@"squiggly"]) {
|
|
410
|
+
[storage addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:range];
|
|
411
|
+
[storage addAttribute:NSUnderlineColorAttributeName value:color range:range];
|
|
412
|
+
}
|
|
413
|
+
if ([style isEqual:@"strikeout"]) {
|
|
414
|
+
[storage addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlineStyleSingle) range:range];
|
|
415
|
+
[storage addAttribute:NSStrikethroughColorAttributeName value:color range:range];
|
|
416
|
+
}
|
|
417
|
+
NSString *identifier = annotation[@"id"];
|
|
418
|
+
if (![identifier isKindOfClass:NSString.class]) continue;
|
|
419
|
+
[storage addAttribute:@"PapyrusAnnotationId" value:identifier range:range];
|
|
420
|
+
BOOL note = annotation[@"noteContent"] != nil || [annotation[@"type"] isEqual:@"comment"] || [annotation[@"type"] isEqual:@"text"];
|
|
421
|
+
if (note) {
|
|
422
|
+
[visibleIds addObject:identifier];
|
|
423
|
+
UIButton *button = self.noteButtons[identifier];
|
|
424
|
+
BOOL created = button == nil;
|
|
425
|
+
if (created) button = [UIButton buttonWithType:UIButtonTypeSystem];
|
|
426
|
+
[button setTitle:@"●" forState:UIControlStateNormal];
|
|
427
|
+
[button setTitleColor:color forState:UIControlStateNormal];
|
|
428
|
+
button.accessibilityIdentifier = identifier;
|
|
429
|
+
button.accessibilityLabel = self.annotationLabels[@"comment"] ?: @"";
|
|
430
|
+
if (created) [button addTarget:self action:@selector(openAnnotationNote:) forControlEvents:UIControlEventTouchUpInside];
|
|
431
|
+
self.noteButtons[identifier] = button;
|
|
432
|
+
if (created) {
|
|
433
|
+
[self.textView addSubview:button];
|
|
434
|
+
if (!UIAccessibilityIsReduceMotionEnabled()) {button.alpha=0;button.transform=CGAffineTransformMakeScale(0.92,0.92);[UIView animateWithDuration:0.18 animations:^{button.alpha=1;button.transform=CGAffineTransformIdentity;}];}
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
for (NSString *identifier in self.noteButtons.allKeys.copy) if (![visibleIds containsObject:identifier]) {[self.noteButtons[identifier] removeFromSuperview];[self.noteButtons removeObjectForKey:identifier];}
|
|
439
|
+
[self layoutNoteButtons];
|
|
440
|
+
}
|
|
441
|
+
- (void)layoutNoteButtons {
|
|
442
|
+
if (self.noteButtons.count == 0) return;
|
|
443
|
+
[self.textView.layoutManager ensureLayoutForTextContainer:self.textView.textContainer];
|
|
444
|
+
self.noteGroups = [NSMutableDictionary dictionary];
|
|
445
|
+
NSMutableDictionary<NSNumber *, NSMutableArray<UIButton *> *> *groups = [NSMutableDictionary dictionary];
|
|
446
|
+
for (NSDictionary *annotation in self.annotations) {
|
|
447
|
+
UIButton *button = self.noteButtons[annotation[@"id"]];
|
|
448
|
+
NSRange range = [self rangeForAnnotation:annotation];
|
|
449
|
+
if (!button || range.location == NSNotFound) continue;
|
|
450
|
+
NSRange glyph = [self.textView.layoutManager glyphRangeForCharacterRange:NSMakeRange(range.location,1) actualCharacterRange:NULL];
|
|
451
|
+
CGRect bounds = [self.textView.layoutManager boundingRectForGlyphRange:glyph inTextContainer:self.textView.textContainer];
|
|
452
|
+
// Reserved outside the text container; follows UITextView's own content scroll.
|
|
453
|
+
CGFloat y = bounds.origin.y + self.textView.textContainerInset.top - 6;
|
|
454
|
+
button.frame = CGRectMake(0, floor(y/44)*44, 44, 44);
|
|
455
|
+
NSNumber *key = @(floor(y/44));
|
|
456
|
+
if (!groups[key]) groups[key] = [NSMutableArray array];
|
|
457
|
+
[groups[key] addObject:button];
|
|
458
|
+
button.hidden = YES;
|
|
459
|
+
}
|
|
460
|
+
for (NSArray<UIButton *> *buttons in groups.allValues) {
|
|
461
|
+
UIButton *leader = buttons.firstObject;
|
|
462
|
+
leader.hidden = NO;
|
|
463
|
+
NSMutableArray *ids=[NSMutableArray array];for(UIButton *button in buttons)[ids addObject:button.accessibilityIdentifier];
|
|
464
|
+
self.noteGroups[leader.accessibilityIdentifier]=ids;
|
|
465
|
+
[leader setTitle:buttons.count > 1 ? [NSString stringWithFormat:@"%lu",(unsigned long)buttons.count] : @"●" forState:UIControlStateNormal];
|
|
466
|
+
if (@available(iOS 14.0,*)) {
|
|
467
|
+
NSMutableArray *actions = [NSMutableArray array];
|
|
468
|
+
for (UIButton *button in buttons) {
|
|
469
|
+
NSString *identifier = button.accessibilityIdentifier;
|
|
470
|
+
NSString *title = identifier;
|
|
471
|
+
for (NSDictionary *annotation in self.annotations) if ([annotation[@"id"] isEqual:identifier]) { title = annotation[@"noteContent"] ?: annotation[@"content"] ?: identifier; break; }
|
|
472
|
+
__weak typeof(self) weakSelf = self;
|
|
473
|
+
[actions addObject:[UIAction actionWithTitle:title image:nil identifier:nil handler:^(__kindof UIAction *action) {
|
|
474
|
+
if (weakSelf.onAnnotationTap) weakSelf.onAnnotationTap(@{@"nativeEvent":@{@"id":identifier}});
|
|
475
|
+
}]];
|
|
476
|
+
}
|
|
477
|
+
leader.menu = buttons.count > 1 ? [UIMenu menuWithTitle:self.annotationLabels[@"comment"] ?: @"" children:actions] : nil;
|
|
478
|
+
leader.showsMenuAsPrimaryAction = buttons.count > 1;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)recognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)other { return YES; }
|
|
483
|
+
- (void)tapTextAnnotation:(UITapGestureRecognizer *)recognizer {
|
|
484
|
+
if (recognizer.state != UIGestureRecognizerStateEnded || self.textView.selectedRange.length > 0) return;
|
|
485
|
+
if (self.textView.layoutManager.numberOfGlyphs == 0) return;
|
|
486
|
+
CGPoint point = [recognizer locationInView:self.textView];
|
|
487
|
+
point.x -= self.textView.textContainerInset.left; point.y -= self.textView.textContainerInset.top;
|
|
488
|
+
CGFloat fraction = 0;
|
|
489
|
+
NSUInteger glyph = [self.textView.layoutManager glyphIndexForPoint:point inTextContainer:self.textView.textContainer fractionOfDistanceThroughGlyph:&fraction];
|
|
490
|
+
if (glyph >= self.textView.layoutManager.numberOfGlyphs) return;
|
|
491
|
+
CGRect bounds = [self.textView.layoutManager boundingRectForGlyphRange:NSMakeRange(glyph,1) inTextContainer:self.textView.textContainer];
|
|
492
|
+
if (!CGRectContainsPoint(CGRectInset(bounds,-3,-3),point)) return;
|
|
493
|
+
NSUInteger index = [self.textView.layoutManager characterIndexForGlyphAtIndex:glyph];
|
|
494
|
+
for (NSDictionary *annotation in self.annotations) {
|
|
495
|
+
NSRange range = [self rangeForAnnotation:annotation];
|
|
496
|
+
if (range.location != NSNotFound && NSLocationInRange(index,range) && self.onAnnotationTap) {
|
|
497
|
+
self.onAnnotationTap(@{@"nativeEvent":@{@"id":annotation[@"id"] ?: @""}});return;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
- (void)openAnnotationNote:(UIButton *)sender {
|
|
502
|
+
NSArray<NSString *> *ids=self.noteGroups[sender.accessibilityIdentifier];
|
|
503
|
+
if(ids.count>1) {
|
|
504
|
+
UIResponder *responder=self;while(responder && ![responder isKindOfClass:UIViewController.class])responder=responder.nextResponder;
|
|
505
|
+
UIViewController *controller=(UIViewController *)responder;
|
|
506
|
+
if(!controller || controller.presentedViewController)return;
|
|
507
|
+
UIAlertController *menu=[UIAlertController alertControllerWithTitle:self.annotationLabels[@"comment"] message:nil preferredStyle:UIAlertControllerStyleActionSheet];
|
|
508
|
+
__weak typeof(self) weakSelf=self;
|
|
509
|
+
for(NSString *identifier in ids){NSString *title=identifier;for(NSDictionary *a in self.annotations)if([a[@"id"] isEqual:identifier]){title=a[@"noteContent"] ?: a[@"content"] ?: identifier;break;}
|
|
510
|
+
[menu addAction:[UIAlertAction actionWithTitle:title style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){if(weakSelf.onAnnotationTap)weakSelf.onAnnotationTap(@{@"nativeEvent":@{@"id":identifier}});}]];
|
|
511
|
+
}
|
|
512
|
+
menu.popoverPresentationController.sourceView=sender;menu.popoverPresentationController.sourceRect=sender.bounds;
|
|
513
|
+
[controller presentViewController:menu animated:!UIAccessibilityIsReduceMotionEnabled() completion:nil];return;
|
|
514
|
+
}
|
|
515
|
+
if (self.onAnnotationTap) self.onAnnotationTap(@{ @"nativeEvent": @{ @"id": sender.accessibilityIdentifier ?: @"" } });
|
|
516
|
+
}
|
|
517
|
+
|
|
299
518
|
@end
|
|
@@ -11,7 +11,12 @@ RCT_EXPORT_VIEW_PROPERTY(documentGeneration, NSInteger)
|
|
|
11
11
|
RCT_EXPORT_VIEW_PROPERTY(textLength, NSInteger)
|
|
12
12
|
RCT_EXPORT_VIEW_PROPERTY(currentTextOffset, NSInteger)
|
|
13
13
|
RCT_EXPORT_VIEW_PROPERTY(scrollToTextOffsetSignal, NSNumber)
|
|
14
|
+
RCT_EXPORT_VIEW_PROPERTY(textNavigationRequest, NSDictionary)
|
|
14
15
|
RCT_EXPORT_VIEW_PROPERTY(searchResults, NSArray)
|
|
16
|
+
RCT_EXPORT_VIEW_PROPERTY(annotations, NSArray)
|
|
17
|
+
RCT_EXPORT_VIEW_PROPERTY(annotationLabels, NSDictionary)
|
|
18
|
+
RCT_EXPORT_VIEW_PROPERTY(onAnnotateSelection, RCTBubblingEventBlock)
|
|
19
|
+
RCT_EXPORT_VIEW_PROPERTY(onAnnotationTap, RCTBubblingEventBlock)
|
|
15
20
|
RCT_EXPORT_VIEW_PROPERTY(activeSearchIndex, NSInteger)
|
|
16
21
|
RCT_EXPORT_VIEW_PROPERTY(pageTheme, NSString)
|
|
17
22
|
RCT_EXPORT_VIEW_PROPERTY(uiTheme, NSString)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@papyrus-sdk/engine-native",
|
|
3
|
-
"version": "0.2.22-beta.
|
|
3
|
+
"version": "0.2.22-beta.7",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"papyrus",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"android/consumer-rules.pro",
|
|
33
33
|
"ios/*.h",
|
|
34
34
|
"ios/*.m",
|
|
35
|
-
"
|
|
35
|
+
"*.podspec",
|
|
36
36
|
"vendor/libarchive",
|
|
37
37
|
"third_party_licenses",
|
|
38
38
|
"react-native.config.js"
|
|
@@ -48,17 +48,17 @@
|
|
|
48
48
|
"bugs": {
|
|
49
49
|
"url": "https://github.com/solrachix/Papyrus/issues"
|
|
50
50
|
},
|
|
51
|
-
"scripts": {
|
|
52
|
-
"build": "tsup"
|
|
53
|
-
},
|
|
54
51
|
"peerDependencies": {
|
|
55
|
-
"@papyrus-sdk/core": "
|
|
56
|
-
"@papyrus-sdk/types": "
|
|
52
|
+
"@papyrus-sdk/core": "0.2.23-beta.3",
|
|
53
|
+
"@papyrus-sdk/types": "0.2.16-beta.3",
|
|
57
54
|
"react-native": ">=0.81.0"
|
|
58
55
|
},
|
|
59
56
|
"devDependencies": {
|
|
60
57
|
"@papyrus-sdk/core": "0.2.19",
|
|
61
58
|
"@papyrus-sdk/types": "0.2.12",
|
|
62
59
|
"react-native": "^0.81.0"
|
|
60
|
+
},
|
|
61
|
+
"scripts": {
|
|
62
|
+
"build": "tsup"
|
|
63
63
|
}
|
|
64
|
-
}
|
|
64
|
+
}
|
package/react-native.config.js
CHANGED
|
@@ -5,7 +5,7 @@ This source snapshot is libarchive **v3.8.9**, pinned to upstream commit
|
|
|
5
5
|
`https://github.com/libarchive/libarchive`.
|
|
6
6
|
|
|
7
7
|
Papyrus compiles only the read-side source subset listed in both
|
|
8
|
-
`android/src/main/cpp/CMakeLists.txt` and `
|
|
8
|
+
`android/src/main/cpp/CMakeLists.txt` and `PapyrusNativeEngine.podspec`.
|
|
9
9
|
The public C++ adapter in this directory filters comic archive entries,
|
|
10
10
|
orders them naturally, and extracts one selected image at a time to a bounded
|
|
11
11
|
cache. It does not write or modify archives.
|
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
#define PAPYRUS_ARCHIVE_CONFIG_H
|
|
3
3
|
#define __LIBARCHIVE_CONFIG_H_INCLUDED 1
|
|
4
4
|
|
|
5
|
+
/* Import permission macros directly rather than relying on transitive headers. */
|
|
6
|
+
#if defined(__APPLE__)
|
|
7
|
+
#include <sys/types.h>
|
|
8
|
+
#include <sys/stat.h>
|
|
9
|
+
#endif
|
|
10
|
+
|
|
5
11
|
/* Minimal POSIX configuration for the libarchive reader subset used by Papyrus. */
|
|
6
12
|
#define HAVE_INTTYPES_H 1
|
|
7
13
|
#define HAVE_STDINT_H 1
|