@papyrus-sdk/engine-native 0.2.22-beta.2 → 0.2.22-beta.4
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/build.gradle +1 -0
- package/android/src/main/cpp/CMakeLists.txt +137 -0
- package/android/src/main/cpp/PapyrusComicArchiveJni.cpp +68 -0
- package/android/src/main/cpp/PapyrusComicArchiveTest.cpp +55 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusComicArchiveNative.java +14 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusComicDocumentView.java +353 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusComicDocumentViewManager.java +32 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusComicPageLayout.java +17 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusNativeEngineModule.java +298 -34
- package/android/src/main/java/com/papyrus/engine/PapyrusNativeTextModel.java +195 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusPackage.java +3 -1
- package/android/src/main/java/com/papyrus/engine/PapyrusPdfViewerView.java +24 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusRenderMath.java +9 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusTextDocumentView.java +439 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusTextDocumentViewManager.java +43 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusTextStore.java +43 -0
- package/dist/index.d.mts +439 -3
- package/dist/index.d.ts +439 -3
- package/dist/index.js +412 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +404 -3
- package/dist/index.mjs.map +1 -1
- package/ios/PapyrusComicDocumentView.h +21 -0
- package/ios/PapyrusComicDocumentView.m +374 -0
- package/ios/PapyrusComicDocumentViewManager.m +23 -0
- package/ios/PapyrusEngineStore.m +4 -0
- package/ios/PapyrusNativeEngine.m +664 -0
- package/ios/PapyrusNativeEngine.podspec +26 -1
- package/ios/PapyrusPageRotationRegistry.h +29 -0
- package/ios/PapyrusPageRotationRegistry.m +179 -0
- package/ios/PapyrusPageView.m +38 -11
- package/ios/PapyrusPdfDocumentView.h +2 -0
- package/ios/PapyrusPdfDocumentView.m +116 -9
- package/ios/PapyrusPdfDocumentViewManager.m +2 -0
- package/ios/PapyrusPdfPageTheme.h +15 -0
- package/ios/PapyrusPdfPageTheme.m +218 -0
- package/ios/PapyrusTextDocumentView.h +27 -0
- package/ios/PapyrusTextDocumentView.m +299 -0
- package/ios/PapyrusTextDocumentViewManager.m +29 -0
- package/ios/PapyrusTextStore.h +13 -0
- package/ios/PapyrusTextStore.m +73 -0
- package/package.json +5 -3
- package/third_party_licenses/BLAKE2-NOTICE.txt +11 -0
- package/third_party_licenses/libarchive-COPYING +65 -0
- package/vendor/libarchive/PapyrusComicArchive.cpp +376 -0
- package/vendor/libarchive/PapyrusComicArchive.h +30 -0
- package/vendor/libarchive/README.papyrus.md +15 -0
- package/vendor/libarchive/android.h +192 -0
- package/vendor/libarchive/config/PapyrusArchiveConfig.h +65 -0
- package/vendor/libarchive/libarchive/CMakeLists.txt +293 -0
- package/vendor/libarchive/libarchive/android_lf.h +36 -0
- package/vendor/libarchive/libarchive/archive.h +1266 -0
- package/vendor/libarchive/libarchive/archive_acl.c +2025 -0
- package/vendor/libarchive/libarchive/archive_acl_private.h +85 -0
- package/vendor/libarchive/libarchive/archive_blake2.h +197 -0
- package/vendor/libarchive/libarchive/archive_blake2_impl.h +161 -0
- package/vendor/libarchive/libarchive/archive_blake2s_ref.c +369 -0
- package/vendor/libarchive/libarchive/archive_blake2sp_ref.c +361 -0
- package/vendor/libarchive/libarchive/archive_check_magic.c +183 -0
- package/vendor/libarchive/libarchive/archive_cmdline.c +211 -0
- package/vendor/libarchive/libarchive/archive_cmdline_private.h +45 -0
- package/vendor/libarchive/libarchive/archive_crc32.h +123 -0
- package/vendor/libarchive/libarchive/archive_cryptor.c +534 -0
- package/vendor/libarchive/libarchive/archive_cryptor_private.h +199 -0
- package/vendor/libarchive/libarchive/archive_digest.c +1584 -0
- package/vendor/libarchive/libarchive/archive_digest_private.h +431 -0
- package/vendor/libarchive/libarchive/archive_disk_acl_darwin.c +558 -0
- package/vendor/libarchive/libarchive/archive_disk_acl_freebsd.c +712 -0
- package/vendor/libarchive/libarchive/archive_disk_acl_linux.c +760 -0
- package/vendor/libarchive/libarchive/archive_disk_acl_sunos.c +824 -0
- package/vendor/libarchive/libarchive/archive_endian.h +234 -0
- package/vendor/libarchive/libarchive/archive_entry.3 +147 -0
- package/vendor/libarchive/libarchive/archive_entry.c +2297 -0
- package/vendor/libarchive/libarchive/archive_entry.h +763 -0
- package/vendor/libarchive/libarchive/archive_entry_acl.3 +458 -0
- package/vendor/libarchive/libarchive/archive_entry_copy_bhfi.c +55 -0
- package/vendor/libarchive/libarchive/archive_entry_copy_stat.c +82 -0
- package/vendor/libarchive/libarchive/archive_entry_link_resolver.c +472 -0
- package/vendor/libarchive/libarchive/archive_entry_linkify.3 +224 -0
- package/vendor/libarchive/libarchive/archive_entry_locale.h +90 -0
- package/vendor/libarchive/libarchive/archive_entry_misc.3 +63 -0
- package/vendor/libarchive/libarchive/archive_entry_paths.3 +153 -0
- package/vendor/libarchive/libarchive/archive_entry_perms.3 +210 -0
- package/vendor/libarchive/libarchive/archive_entry_private.h +205 -0
- package/vendor/libarchive/libarchive/archive_entry_sparse.c +156 -0
- package/vendor/libarchive/libarchive/archive_entry_stat.3 +274 -0
- package/vendor/libarchive/libarchive/archive_entry_stat.c +121 -0
- package/vendor/libarchive/libarchive/archive_entry_strmode.c +69 -0
- package/vendor/libarchive/libarchive/archive_entry_time.3 +127 -0
- package/vendor/libarchive/libarchive/archive_entry_xattr.c +155 -0
- package/vendor/libarchive/libarchive/archive_hmac.c +345 -0
- package/vendor/libarchive/libarchive/archive_hmac_private.h +119 -0
- package/vendor/libarchive/libarchive/archive_integer.h +267 -0
- package/vendor/libarchive/libarchive/archive_match.c +1869 -0
- package/vendor/libarchive/libarchive/archive_openssl_evp_private.h +54 -0
- package/vendor/libarchive/libarchive/archive_openssl_hmac_private.h +54 -0
- package/vendor/libarchive/libarchive/archive_options.c +219 -0
- package/vendor/libarchive/libarchive/archive_options_private.h +49 -0
- package/vendor/libarchive/libarchive/archive_pack_dev.c +330 -0
- package/vendor/libarchive/libarchive/archive_pack_dev.h +49 -0
- package/vendor/libarchive/libarchive/archive_parse_date.c +1173 -0
- package/vendor/libarchive/libarchive/archive_pathmatch.c +480 -0
- package/vendor/libarchive/libarchive/archive_pathmatch.h +50 -0
- package/vendor/libarchive/libarchive/archive_platform.h +213 -0
- package/vendor/libarchive/libarchive/archive_platform_acl.h +53 -0
- package/vendor/libarchive/libarchive/archive_platform_stat.h +45 -0
- package/vendor/libarchive/libarchive/archive_platform_xattr.h +45 -0
- package/vendor/libarchive/libarchive/archive_ppmd7.c +1173 -0
- package/vendor/libarchive/libarchive/archive_ppmd7_private.h +119 -0
- package/vendor/libarchive/libarchive/archive_ppmd8.c +1293 -0
- package/vendor/libarchive/libarchive/archive_ppmd8_private.h +123 -0
- package/vendor/libarchive/libarchive/archive_ppmd_private.h +159 -0
- package/vendor/libarchive/libarchive/archive_private.h +209 -0
- package/vendor/libarchive/libarchive/archive_random.c +274 -0
- package/vendor/libarchive/libarchive/archive_random_private.h +36 -0
- package/vendor/libarchive/libarchive/archive_rb.c +709 -0
- package/vendor/libarchive/libarchive/archive_rb.h +113 -0
- package/vendor/libarchive/libarchive/archive_read.3 +250 -0
- package/vendor/libarchive/libarchive/archive_read.c +1814 -0
- package/vendor/libarchive/libarchive/archive_read_add_passphrase.3 +72 -0
- package/vendor/libarchive/libarchive/archive_read_add_passphrase.c +189 -0
- package/vendor/libarchive/libarchive/archive_read_append_filter.c +209 -0
- package/vendor/libarchive/libarchive/archive_read_data.3 +128 -0
- package/vendor/libarchive/libarchive/archive_read_data_into_fd.c +207 -0
- package/vendor/libarchive/libarchive/archive_read_disk.3 +422 -0
- package/vendor/libarchive/libarchive/archive_read_disk_entry_from_file.c +1086 -0
- package/vendor/libarchive/libarchive/archive_read_disk_posix.c +2639 -0
- package/vendor/libarchive/libarchive/archive_read_disk_private.h +97 -0
- package/vendor/libarchive/libarchive/archive_read_disk_set_standard_lookup.c +315 -0
- package/vendor/libarchive/libarchive/archive_read_disk_windows.c +2603 -0
- package/vendor/libarchive/libarchive/archive_read_extract.3 +135 -0
- package/vendor/libarchive/libarchive/archive_read_extract.c +59 -0
- package/vendor/libarchive/libarchive/archive_read_extract2.c +154 -0
- package/vendor/libarchive/libarchive/archive_read_filter.3 +163 -0
- package/vendor/libarchive/libarchive/archive_read_format.3 +190 -0
- package/vendor/libarchive/libarchive/archive_read_free.3 +91 -0
- package/vendor/libarchive/libarchive/archive_read_header.3 +89 -0
- package/vendor/libarchive/libarchive/archive_read_new.3 +57 -0
- package/vendor/libarchive/libarchive/archive_read_open.3 +247 -0
- package/vendor/libarchive/libarchive/archive_read_open_fd.c +236 -0
- package/vendor/libarchive/libarchive/archive_read_open_file.c +257 -0
- package/vendor/libarchive/libarchive/archive_read_open_filename.c +652 -0
- package/vendor/libarchive/libarchive/archive_read_open_memory.c +188 -0
- package/vendor/libarchive/libarchive/archive_read_private.h +274 -0
- package/vendor/libarchive/libarchive/archive_read_set_format.c +116 -0
- package/vendor/libarchive/libarchive/archive_read_set_options.3 +290 -0
- package/vendor/libarchive/libarchive/archive_read_set_options.c +132 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_all.c +84 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_by_code.c +68 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_bzip2.c +360 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_compress.c +457 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_grzip.c +108 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_gzip.c +538 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_lrzip.c +119 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_lz4.c +829 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_lzop.c +493 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_none.c +51 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_program.c +497 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_rpm.c +249 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_uu.c +739 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_xz.c +792 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_zstd.c +356 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_7zip.c +4650 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_all.c +88 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_ar.c +597 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_by_code.c +76 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_cab.c +3410 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_cpio.c +1152 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_empty.c +95 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_iso9660.c +3516 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_lha.c +2931 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_mtree.c +2113 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_rar.c +3932 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_rar5.c +4501 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_raw.c +194 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_tar.c +3785 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_warc.c +875 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_xar.c +3770 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_zip.c +4710 -0
- package/vendor/libarchive/libarchive/archive_string.c +4391 -0
- package/vendor/libarchive/libarchive/archive_string.h +244 -0
- package/vendor/libarchive/libarchive/archive_string_composition.h +2289 -0
- package/vendor/libarchive/libarchive/archive_string_sprintf.c +200 -0
- package/vendor/libarchive/libarchive/archive_time.c +168 -0
- package/vendor/libarchive/libarchive/archive_time_private.h +47 -0
- package/vendor/libarchive/libarchive/archive_util.3 +239 -0
- package/vendor/libarchive/libarchive/archive_util.c +668 -0
- package/vendor/libarchive/libarchive/archive_version_details.c +516 -0
- package/vendor/libarchive/libarchive/archive_virtual.c +162 -0
- package/vendor/libarchive/libarchive/archive_windows.c +1035 -0
- package/vendor/libarchive/libarchive/archive_windows.h +332 -0
- package/vendor/libarchive/libarchive/archive_write.3 +266 -0
- package/vendor/libarchive/libarchive/archive_write.c +896 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter.c +71 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter_b64encode.c +329 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter_by_name.c +76 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter_bzip2.c +411 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter_compress.c +459 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter_grzip.c +143 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter_gzip.c +493 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter_lrzip.c +214 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter_lz4.c +710 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter_lzop.c +500 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter_none.c +42 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter_program.c +398 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter_uuencode.c +320 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter_xz.c +547 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter_zstd.c +608 -0
- package/vendor/libarchive/libarchive/archive_write_blocksize.3 +112 -0
- package/vendor/libarchive/libarchive/archive_write_data.3 +88 -0
- package/vendor/libarchive/libarchive/archive_write_disk.3 +360 -0
- package/vendor/libarchive/libarchive/archive_write_disk_posix.c +4789 -0
- package/vendor/libarchive/libarchive/archive_write_disk_private.h +43 -0
- package/vendor/libarchive/libarchive/archive_write_disk_set_standard_lookup.c +265 -0
- package/vendor/libarchive/libarchive/archive_write_disk_windows.c +2952 -0
- package/vendor/libarchive/libarchive/archive_write_filter.3 +140 -0
- package/vendor/libarchive/libarchive/archive_write_finish_entry.3 +77 -0
- package/vendor/libarchive/libarchive/archive_write_format.3 +187 -0
- package/vendor/libarchive/libarchive/archive_write_free.3 +94 -0
- package/vendor/libarchive/libarchive/archive_write_header.3 +71 -0
- package/vendor/libarchive/libarchive/archive_write_new.3 +56 -0
- package/vendor/libarchive/libarchive/archive_write_open.3 +270 -0
- package/vendor/libarchive/libarchive/archive_write_open_fd.c +141 -0
- package/vendor/libarchive/libarchive/archive_write_open_file.c +102 -0
- package/vendor/libarchive/libarchive/archive_write_open_filename.c +272 -0
- package/vendor/libarchive/libarchive/archive_write_open_memory.c +110 -0
- package/vendor/libarchive/libarchive/archive_write_private.h +166 -0
- package/vendor/libarchive/libarchive/archive_write_set_format.c +124 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_7zip.c +2571 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_ar.c +540 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_by_name.c +93 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_cpio.c +11 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_cpio_binary.c +618 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_cpio_newc.c +457 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_cpio_odc.c +508 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_filter_by_ext.c +141 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_gnutar.c +790 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_iso9660.c +8216 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_mtree.c +2307 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_pax.c +2249 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_private.h +40 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_raw.c +123 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_shar.c +650 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_ustar.c +768 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_v7tar.c +648 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_warc.c +491 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_xar.c +3799 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_zip.c +2548 -0
- package/vendor/libarchive/libarchive/archive_write_set_options.3 +779 -0
- package/vendor/libarchive/libarchive/archive_write_set_options.c +129 -0
- package/vendor/libarchive/libarchive/archive_write_set_passphrase.3 +72 -0
- package/vendor/libarchive/libarchive/archive_write_set_passphrase.c +95 -0
- package/vendor/libarchive/libarchive/archive_xxhash.h +48 -0
- package/vendor/libarchive/libarchive/config_freebsd.h +275 -0
- package/vendor/libarchive/libarchive/cpio.5 +389 -0
- package/vendor/libarchive/libarchive/filter_fork.h +44 -0
- package/vendor/libarchive/libarchive/filter_fork_posix.c +269 -0
- package/vendor/libarchive/libarchive/filter_fork_windows.c +270 -0
- package/vendor/libarchive/libarchive/libarchive-formats.5 +478 -0
- package/vendor/libarchive/libarchive/libarchive.3 +297 -0
- package/vendor/libarchive/libarchive/libarchive_changes.3 +339 -0
- package/vendor/libarchive/libarchive/libarchive_internals.3 +363 -0
- package/vendor/libarchive/libarchive/module.modulemap +34 -0
- package/vendor/libarchive/libarchive/mtree.5 +323 -0
- package/vendor/libarchive/libarchive/tar.5 +947 -0
- package/vendor/libarchive/libarchive/xxhash.c +531 -0
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
#import "PapyrusPdfPageTheme.h"
|
|
2
|
+
|
|
3
|
+
#import <UIKit/UIKit.h>
|
|
4
|
+
#import <objc/runtime.h>
|
|
5
|
+
|
|
6
|
+
@class PapyrusThemedPdfPage;
|
|
7
|
+
|
|
8
|
+
@interface PapyrusPdfPageThemeDelegate : NSObject <PDFDocumentDelegate>
|
|
9
|
+
@property (nonatomic, strong) NSMutableDictionary<NSString *, NSString *> *themesByLease;
|
|
10
|
+
@property (nonatomic, strong) NSMutableDictionary<NSString *, NSNumber *> *sequenceByLease;
|
|
11
|
+
@property (nonatomic, assign) NSUInteger nextSequence;
|
|
12
|
+
- (void)setTheme:(NSString *)theme forLease:(NSString *)leaseToken;
|
|
13
|
+
- (void)removeLease:(NSString *)leaseToken;
|
|
14
|
+
- (nullable NSString *)activeTheme;
|
|
15
|
+
@end
|
|
16
|
+
|
|
17
|
+
@interface PapyrusThemedPdfPage : PDFPage
|
|
18
|
+
@end
|
|
19
|
+
|
|
20
|
+
static const void *PapyrusPdfPageThemeDelegateAssociationKey =
|
|
21
|
+
&PapyrusPdfPageThemeDelegateAssociationKey;
|
|
22
|
+
|
|
23
|
+
static NSSet<NSString *> *PapyrusSupportedPdfPageThemes(void) {
|
|
24
|
+
static NSSet<NSString *> *themes;
|
|
25
|
+
static dispatch_once_t onceToken;
|
|
26
|
+
dispatch_once(&onceToken, ^{
|
|
27
|
+
themes = [NSSet setWithArray:@[@"normal", @"sepia", @"dark", @"high-contrast"]];
|
|
28
|
+
});
|
|
29
|
+
return themes;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static PapyrusPdfPageThemeDelegate *PapyrusThemeDelegateForDocument(
|
|
33
|
+
PDFDocument *document,
|
|
34
|
+
BOOL createIfMissing) {
|
|
35
|
+
if (!document) return nil;
|
|
36
|
+
|
|
37
|
+
@synchronized(document) {
|
|
38
|
+
PapyrusPdfPageThemeDelegate *delegate =
|
|
39
|
+
objc_getAssociatedObject(document, PapyrusPdfPageThemeDelegateAssociationKey);
|
|
40
|
+
if (!delegate && createIfMissing) {
|
|
41
|
+
delegate = [[PapyrusPdfPageThemeDelegate alloc] init];
|
|
42
|
+
objc_setAssociatedObject(document,
|
|
43
|
+
PapyrusPdfPageThemeDelegateAssociationKey,
|
|
44
|
+
delegate,
|
|
45
|
+
OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
46
|
+
}
|
|
47
|
+
if (delegate && document.delegate != delegate) {
|
|
48
|
+
document.delegate = delegate;
|
|
49
|
+
}
|
|
50
|
+
return delegate;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static UIColor *PapyrusThemeTintColor(NSString *theme) {
|
|
55
|
+
if ([theme isEqualToString:@"sepia"]) {
|
|
56
|
+
return [UIColor colorWithRed:0.96 green:0.88 blue:0.73 alpha:1.0];
|
|
57
|
+
}
|
|
58
|
+
return UIColor.whiteColor;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
static void PapyrusCompositeColor(CGContextRef context,
|
|
62
|
+
CGRect bounds,
|
|
63
|
+
UIColor *color,
|
|
64
|
+
CGBlendMode blendMode,
|
|
65
|
+
CGFloat alpha) {
|
|
66
|
+
CGContextSaveGState(context);
|
|
67
|
+
CGContextSetBlendMode(context, blendMode);
|
|
68
|
+
CGContextSetAlpha(context, alpha);
|
|
69
|
+
CGContextSetFillColorWithColor(context, color.CGColor);
|
|
70
|
+
CGContextFillRect(context, bounds);
|
|
71
|
+
CGContextRestoreGState(context);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
static void PapyrusApplyPageTheme(NSString *theme,
|
|
75
|
+
CGRect pageBounds,
|
|
76
|
+
CGContextRef context) {
|
|
77
|
+
if ([theme isEqualToString:@"sepia"]) {
|
|
78
|
+
PapyrusCompositeColor(context,
|
|
79
|
+
pageBounds,
|
|
80
|
+
PapyrusThemeTintColor(theme),
|
|
81
|
+
kCGBlendModeMultiply,
|
|
82
|
+
0.42);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if ([theme isEqualToString:@"dark"] ||
|
|
87
|
+
[theme isEqualToString:@"high-contrast"]) {
|
|
88
|
+
PapyrusCompositeColor(context,
|
|
89
|
+
pageBounds,
|
|
90
|
+
[UIColor colorWithWhite:0.5 alpha:1.0],
|
|
91
|
+
kCGBlendModeSaturation,
|
|
92
|
+
1.0);
|
|
93
|
+
PapyrusCompositeColor(context,
|
|
94
|
+
pageBounds,
|
|
95
|
+
UIColor.whiteColor,
|
|
96
|
+
kCGBlendModeDifference,
|
|
97
|
+
1.0);
|
|
98
|
+
if ([theme isEqualToString:@"high-contrast"]) {
|
|
99
|
+
PapyrusCompositeColor(context,
|
|
100
|
+
pageBounds,
|
|
101
|
+
UIColor.whiteColor,
|
|
102
|
+
kCGBlendModeColorDodge,
|
|
103
|
+
0.24);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
@implementation PapyrusPdfPageThemeDelegate
|
|
109
|
+
|
|
110
|
+
- (instancetype)init {
|
|
111
|
+
self = [super init];
|
|
112
|
+
if (self) {
|
|
113
|
+
_themesByLease = [NSMutableDictionary dictionary];
|
|
114
|
+
_sequenceByLease = [NSMutableDictionary dictionary];
|
|
115
|
+
}
|
|
116
|
+
return self;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
- (Class)classForPage {
|
|
120
|
+
return PapyrusThemedPdfPage.class;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
- (void)setTheme:(NSString *)theme forLease:(NSString *)leaseToken {
|
|
124
|
+
if (leaseToken.length == 0 || theme.length == 0) return;
|
|
125
|
+
@synchronized(self) {
|
|
126
|
+
self.themesByLease[leaseToken] = [theme copy];
|
|
127
|
+
self.sequenceByLease[leaseToken] = @(++self.nextSequence);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
- (void)removeLease:(NSString *)leaseToken {
|
|
132
|
+
if (leaseToken.length == 0) return;
|
|
133
|
+
@synchronized(self) {
|
|
134
|
+
[self.themesByLease removeObjectForKey:leaseToken];
|
|
135
|
+
[self.sequenceByLease removeObjectForKey:leaseToken];
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
- (NSString *)activeTheme {
|
|
140
|
+
@synchronized(self) {
|
|
141
|
+
NSString *activeLease = nil;
|
|
142
|
+
NSUInteger activeSequence = 0;
|
|
143
|
+
for (NSString *lease in self.sequenceByLease) {
|
|
144
|
+
NSUInteger sequence = self.sequenceByLease[lease].unsignedIntegerValue;
|
|
145
|
+
if (!activeLease || sequence > activeSequence) {
|
|
146
|
+
activeLease = lease;
|
|
147
|
+
activeSequence = sequence;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return activeLease ? [self.themesByLease[activeLease] copy] : nil;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
@end
|
|
155
|
+
|
|
156
|
+
@implementation PapyrusThemedPdfPage
|
|
157
|
+
|
|
158
|
+
- (void)drawWithBox:(PDFDisplayBox)box toContext:(CGContextRef)context {
|
|
159
|
+
NSString *theme =
|
|
160
|
+
[PapyrusThemeDelegateForDocument(self.document, NO) activeTheme];
|
|
161
|
+
if (!context) return;
|
|
162
|
+
if (!theme || ![PapyrusSupportedPdfPageThemes() containsObject:theme] ||
|
|
163
|
+
[theme isEqualToString:@"normal"] || !self.pageRef) {
|
|
164
|
+
[super drawWithBox:box toContext:context];
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
CGRect pageBounds = [self boundsForBox:box];
|
|
169
|
+
if (CGRectIsNull(pageBounds) || CGRectIsEmpty(pageBounds)) {
|
|
170
|
+
[super drawWithBox:box toContext:context];
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
CGContextSaveGState(context);
|
|
175
|
+
[self transformContext:context forBox:box];
|
|
176
|
+
CGContextClipToRect(context, pageBounds);
|
|
177
|
+
|
|
178
|
+
CGContextSetBlendMode(context, kCGBlendModeNormal);
|
|
179
|
+
CGContextSetAlpha(context, 1.0);
|
|
180
|
+
CGContextSetFillColorWithColor(context, UIColor.whiteColor.CGColor);
|
|
181
|
+
CGContextFillRect(context, pageBounds);
|
|
182
|
+
CGContextDrawPDFPage(context, self.pageRef);
|
|
183
|
+
|
|
184
|
+
PapyrusApplyPageTheme(theme, pageBounds, context);
|
|
185
|
+
|
|
186
|
+
if (self.displaysAnnotations) {
|
|
187
|
+
for (PDFAnnotation *annotation in self.annotations) {
|
|
188
|
+
if (!annotation.shouldDisplay) continue;
|
|
189
|
+
[annotation drawWithBox:box inContext:context];
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
CGContextRestoreGState(context);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
@end
|
|
197
|
+
|
|
198
|
+
void PapyrusInstallPdfPageThemeDelegate(PDFDocument *document) {
|
|
199
|
+
(void)PapyrusThemeDelegateForDocument(document, YES);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
NSString *PapyrusAcquirePdfPageThemeLease(PDFDocument *document, NSString *theme) {
|
|
203
|
+
PapyrusPdfPageThemeDelegate *delegate =
|
|
204
|
+
PapyrusThemeDelegateForDocument(document, YES);
|
|
205
|
+
NSString *leaseToken = [[NSUUID UUID] UUIDString];
|
|
206
|
+
[delegate setTheme:theme forLease:leaseToken];
|
|
207
|
+
return leaseToken;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
void PapyrusUpdatePdfPageThemeLease(PDFDocument *document,
|
|
211
|
+
NSString *leaseToken,
|
|
212
|
+
NSString *theme) {
|
|
213
|
+
[PapyrusThemeDelegateForDocument(document, NO) setTheme:theme forLease:leaseToken];
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
void PapyrusReleasePdfPageThemeLease(PDFDocument *document, NSString *leaseToken) {
|
|
217
|
+
[PapyrusThemeDelegateForDocument(document, NO) removeLease:leaseToken];
|
|
218
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#import <UIKit/UIKit.h>
|
|
2
|
+
#import <React/RCTComponent.h>
|
|
3
|
+
#import <PDFKit/PDFKit.h>
|
|
4
|
+
|
|
5
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
6
|
+
|
|
7
|
+
@interface PapyrusTextDocumentView : UIView <UITextViewDelegate, UIEditMenuInteractionDelegate>
|
|
8
|
+
@property (nonatomic, copy, nullable) NSString *engineId;
|
|
9
|
+
@property (nonatomic, assign) NSInteger documentGeneration;
|
|
10
|
+
@property (nonatomic, assign) NSInteger textLength;
|
|
11
|
+
@property (nonatomic, assign) NSInteger currentTextOffset;
|
|
12
|
+
@property (nonatomic, strong, nullable) NSNumber *scrollToTextOffsetSignal;
|
|
13
|
+
@property (nonatomic, copy) NSArray<NSDictionary *> *searchResults;
|
|
14
|
+
@property (nonatomic, assign) NSInteger activeSearchIndex;
|
|
15
|
+
@property (nonatomic, copy) NSString *pageTheme;
|
|
16
|
+
@property (nonatomic, copy) NSString *uiTheme;
|
|
17
|
+
@property (nonatomic, assign) CGFloat fontSize;
|
|
18
|
+
@property (nonatomic, assign) CGFloat lineHeight;
|
|
19
|
+
@property (nonatomic, assign) CGFloat pageMargin;
|
|
20
|
+
@property (nonatomic, copy) NSString *defineLabel;
|
|
21
|
+
@property (nonatomic, copy) NSString *defineSelectionMode;
|
|
22
|
+
@property (nonatomic, copy, nullable) RCTBubblingEventBlock onTextOffsetChange;
|
|
23
|
+
@property (nonatomic, copy, nullable) RCTBubblingEventBlock onTextRangeSelected;
|
|
24
|
+
@property (nonatomic, copy, nullable) RCTBubblingEventBlock onDefineSelection;
|
|
25
|
+
@end
|
|
26
|
+
|
|
27
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
#import "PapyrusTextDocumentView.h"
|
|
2
|
+
#import "PapyrusTextStore.h"
|
|
3
|
+
|
|
4
|
+
static NSUInteger const PapyrusMaximumTextSearchHighlights = 2000;
|
|
5
|
+
|
|
6
|
+
@interface PapyrusTextDocumentView () <UITextViewDelegate>
|
|
7
|
+
@property (nonatomic, strong) UITextView *textView;
|
|
8
|
+
@property (nonatomic, assign) NSInteger lastReportedStart;
|
|
9
|
+
@property (nonatomic, assign) NSInteger lastReportedEnd;
|
|
10
|
+
@property (nonatomic, assign) NSInteger lastReportedOffset;
|
|
11
|
+
@property (nonatomic, assign) CFAbsoluteTime lastOffsetEventTime;
|
|
12
|
+
@property (nonatomic, assign) BOOL hasLoadedDocument;
|
|
13
|
+
@property (nonatomic, assign) BOOL suppressOffsetEvents;
|
|
14
|
+
@end
|
|
15
|
+
|
|
16
|
+
@implementation PapyrusTextDocumentView
|
|
17
|
+
|
|
18
|
+
- (instancetype)initWithFrame:(CGRect)frame {
|
|
19
|
+
self = [super initWithFrame:frame];
|
|
20
|
+
if (self) {
|
|
21
|
+
self.backgroundColor = UIColor.whiteColor;
|
|
22
|
+
_searchResults = @[];
|
|
23
|
+
_activeSearchIndex = -1;
|
|
24
|
+
_pageTheme = @"normal";
|
|
25
|
+
_uiTheme = @"light";
|
|
26
|
+
_fontSize = 18;
|
|
27
|
+
_lineHeight = 28;
|
|
28
|
+
_pageMargin = 20;
|
|
29
|
+
_defineLabel = @"Define";
|
|
30
|
+
_defineSelectionMode = @"selection";
|
|
31
|
+
_lastReportedOffset = -1;
|
|
32
|
+
_textView = [[UITextView alloc] initWithFrame:self.bounds];
|
|
33
|
+
_textView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
|
34
|
+
_textView.delegate = self;
|
|
35
|
+
_textView.editable = NO;
|
|
36
|
+
_textView.selectable = YES;
|
|
37
|
+
_textView.alwaysBounceVertical = YES;
|
|
38
|
+
_textView.scrollsToTop = YES;
|
|
39
|
+
_textView.textContainerInset = UIEdgeInsetsMake(_pageMargin, _pageMargin, _pageMargin, _pageMargin);
|
|
40
|
+
_textView.backgroundColor = UIColor.whiteColor;
|
|
41
|
+
_textView.textColor = UIColor.blackColor;
|
|
42
|
+
[self addSubview:_textView];
|
|
43
|
+
|
|
44
|
+
if (@available(iOS 16.0, *)) {
|
|
45
|
+
// UITextViewDelegate supplies the custom action to the native selection menu.
|
|
46
|
+
} else {
|
|
47
|
+
UIMenuController.sharedMenuController.menuItems = @[
|
|
48
|
+
[[UIMenuItem alloc] initWithTitle:_defineLabel action:@selector(defineCurrentSelection:)]
|
|
49
|
+
];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return self;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
- (void)didMoveToWindow {
|
|
56
|
+
[super didMoveToWindow];
|
|
57
|
+
[self reloadTextIfAvailable];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
- (void)layoutSubviews {
|
|
61
|
+
[super layoutSubviews];
|
|
62
|
+
[self reloadTextIfAvailable];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
- (void)setEngineId:(NSString *)engineId {
|
|
66
|
+
if ([_engineId isEqualToString:engineId]) return;
|
|
67
|
+
_engineId = [engineId copy];
|
|
68
|
+
self.hasLoadedDocument = NO;
|
|
69
|
+
[self reloadTextIfAvailable];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
- (void)setDocumentGeneration:(NSInteger)documentGeneration {
|
|
73
|
+
if (_documentGeneration == documentGeneration) return;
|
|
74
|
+
_documentGeneration = documentGeneration;
|
|
75
|
+
self.hasLoadedDocument = NO;
|
|
76
|
+
[self reloadTextIfAvailable];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
- (void)setCurrentTextOffset:(NSInteger)currentTextOffset {
|
|
80
|
+
NSInteger nextOffset = MAX(0, currentTextOffset);
|
|
81
|
+
BOOL changed = _currentTextOffset != nextOffset;
|
|
82
|
+
_currentTextOffset = nextOffset;
|
|
83
|
+
if (changed) [self scrollToTextOffset:_currentTextOffset];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
- (void)setScrollToTextOffsetSignal:(NSNumber *)scrollToTextOffsetSignal {
|
|
87
|
+
if ((_scrollToTextOffsetSignal == scrollToTextOffsetSignal) ||
|
|
88
|
+
[_scrollToTextOffsetSignal isEqualToNumber:scrollToTextOffsetSignal]) return;
|
|
89
|
+
_scrollToTextOffsetSignal = [scrollToTextOffsetSignal copy];
|
|
90
|
+
[self scrollToTextOffset:scrollToTextOffsetSignal.integerValue];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
- (void)setSearchResults:(NSArray<NSDictionary *> *)searchResults {
|
|
94
|
+
_searchResults = [searchResults copy] ?: @[];
|
|
95
|
+
[self applySearchHighlights];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
- (void)setActiveSearchIndex:(NSInteger)activeSearchIndex {
|
|
99
|
+
_activeSearchIndex = activeSearchIndex;
|
|
100
|
+
[self applySearchHighlights];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
- (void)setPageTheme:(NSString *)pageTheme {
|
|
104
|
+
_pageTheme = [pageTheme copy] ?: @"normal";
|
|
105
|
+
[self applyThemeAndTypography];
|
|
106
|
+
[self applySearchHighlights];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
- (void)setUiTheme:(NSString *)uiTheme {
|
|
110
|
+
_uiTheme = [uiTheme copy] ?: @"light";
|
|
111
|
+
[self applyThemeAndTypography];
|
|
112
|
+
[self applySearchHighlights];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
- (void)setFontSize:(CGFloat)fontSize {
|
|
116
|
+
_fontSize = MAX(10, MIN(48, fontSize));
|
|
117
|
+
[self applyThemeAndTypography];
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
- (void)setLineHeight:(CGFloat)lineHeight {
|
|
121
|
+
_lineHeight = MAX(_fontSize, MIN(72, lineHeight));
|
|
122
|
+
[self applyThemeAndTypography];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
- (void)setPageMargin:(CGFloat)pageMargin {
|
|
126
|
+
_pageMargin = MAX(8, MIN(64, pageMargin));
|
|
127
|
+
self.textView.textContainerInset = UIEdgeInsetsMake(_pageMargin, _pageMargin, _pageMargin, _pageMargin);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
- (void)setDefineLabel:(NSString *)defineLabel {
|
|
131
|
+
_defineLabel = [defineLabel copy] ?: @"Define";
|
|
132
|
+
if (@available(iOS 16.0, *)) return;
|
|
133
|
+
UIMenuController.sharedMenuController.menuItems = @[
|
|
134
|
+
[[UIMenuItem alloc] initWithTitle:_defineLabel action:@selector(defineCurrentSelection:)]
|
|
135
|
+
];
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
- (void)setDefineSelectionMode:(NSString *)defineSelectionMode {
|
|
139
|
+
_defineSelectionMode = [defineSelectionMode copy] ?: @"selection";
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
- (void)reloadTextIfAvailable {
|
|
143
|
+
if (self.hasLoadedDocument || self.engineId.length == 0 || self.documentGeneration <= 0) return;
|
|
144
|
+
NSString *text = [[PapyrusTextStore shared] textForEngineId:self.engineId generation:self.documentGeneration];
|
|
145
|
+
if (!text) return;
|
|
146
|
+
self.hasLoadedDocument = YES;
|
|
147
|
+
self.suppressOffsetEvents = YES;
|
|
148
|
+
[self applyThemeAndTypography];
|
|
149
|
+
self.textView.text = text;
|
|
150
|
+
[self applyThemeAndTypography];
|
|
151
|
+
self.suppressOffsetEvents = NO;
|
|
152
|
+
[self applySearchHighlights];
|
|
153
|
+
[self scrollToTextOffset:self.currentTextOffset];
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
- (void)applyThemeAndTypography {
|
|
157
|
+
UIColor *paper = UIColor.whiteColor;
|
|
158
|
+
UIColor *foreground = UIColor.blackColor;
|
|
159
|
+
if ([self.pageTheme isEqualToString:@"sepia"]) {
|
|
160
|
+
paper = [UIColor colorWithRed:0.957 green:0.922 blue:0.843 alpha:1];
|
|
161
|
+
foreground = [UIColor colorWithRed:0.20 green:0.17 blue:0.12 alpha:1];
|
|
162
|
+
} else if ([self.pageTheme isEqualToString:@"dark"]) {
|
|
163
|
+
paper = [UIColor colorWithRed:0.12 green:0.12 blue:0.13 alpha:1];
|
|
164
|
+
foreground = [UIColor colorWithRed:0.92 green:0.92 blue:0.92 alpha:1];
|
|
165
|
+
} else if ([self.pageTheme isEqualToString:@"high-contrast"]) {
|
|
166
|
+
paper = UIColor.blackColor;
|
|
167
|
+
foreground = UIColor.whiteColor;
|
|
168
|
+
} else if ([self.uiTheme isEqualToString:@"dark"]) {
|
|
169
|
+
paper = [UIColor colorWithRed:0.12 green:0.12 blue:0.13 alpha:1];
|
|
170
|
+
foreground = [UIColor colorWithRed:0.92 green:0.92 blue:0.92 alpha:1];
|
|
171
|
+
}
|
|
172
|
+
self.backgroundColor = paper;
|
|
173
|
+
self.textView.backgroundColor = paper;
|
|
174
|
+
self.textView.textColor = foreground;
|
|
175
|
+
self.textView.font = [UIFont systemFontOfSize:self.fontSize];
|
|
176
|
+
self.textView.textContainerInset = UIEdgeInsetsMake(_pageMargin, _pageMargin, _pageMargin, _pageMargin);
|
|
177
|
+
if (self.textView.text.length > 0) {
|
|
178
|
+
NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
|
|
179
|
+
paragraph.minimumLineHeight = self.lineHeight;
|
|
180
|
+
paragraph.maximumLineHeight = self.lineHeight;
|
|
181
|
+
paragraph.lineBreakMode = NSLineBreakByWordWrapping;
|
|
182
|
+
[self.textView.textStorage addAttribute:NSParagraphStyleAttributeName
|
|
183
|
+
value:paragraph
|
|
184
|
+
range:NSMakeRange(0, self.textView.textStorage.length)];
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
- (void)applySearchHighlights {
|
|
189
|
+
if (!self.hasLoadedDocument || self.textView.text.length == 0) return;
|
|
190
|
+
NSTextStorage *storage = self.textView.textStorage;
|
|
191
|
+
[storage removeAttribute:NSBackgroundColorAttributeName range:NSMakeRange(0, storage.length)];
|
|
192
|
+
NSUInteger count = MIN(self.searchResults.count, PapyrusMaximumTextSearchHighlights);
|
|
193
|
+
CGFloat normalAlpha = [self.pageTheme isEqualToString:@"dark"] ? 0.35 : 0.42;
|
|
194
|
+
UIColor *normal = [UIColor colorWithRed:1.0 green:0.79 blue:0.16 alpha:normalAlpha];
|
|
195
|
+
UIColor *active = [UIColor colorWithRed:0.10 green:0.48 blue:0.98 alpha:0.55];
|
|
196
|
+
for (NSUInteger index = 0; index < count; index++) {
|
|
197
|
+
NSDictionary *location = self.searchResults[index][@"location"];
|
|
198
|
+
if (![location isKindOfClass:[NSDictionary class]]) continue;
|
|
199
|
+
NSInteger start = [location[@"start"] integerValue];
|
|
200
|
+
NSInteger end = [location[@"end"] integerValue];
|
|
201
|
+
if (start < 0 || end <= start || end > storage.length) continue;
|
|
202
|
+
[storage addAttribute:NSBackgroundColorAttributeName
|
|
203
|
+
value:(NSInteger)index == self.activeSearchIndex ? active : normal
|
|
204
|
+
range:NSMakeRange((NSUInteger)start, (NSUInteger)(end - start))];
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
- (void)scrollToTextOffset:(NSInteger)offset {
|
|
209
|
+
if (!self.hasLoadedDocument || self.textView.text.length == 0) return;
|
|
210
|
+
NSInteger safeOffset = MAX(0, MIN((NSInteger)self.textView.text.length, offset));
|
|
211
|
+
UITextPosition *position = [self.textView positionFromPosition:self.textView.beginningOfDocument offset:safeOffset];
|
|
212
|
+
if (!position) return;
|
|
213
|
+
CGRect caret = [self.textView caretRectForPosition:position];
|
|
214
|
+
if (!CGRectIsNull(caret)) {
|
|
215
|
+
self.suppressOffsetEvents = YES;
|
|
216
|
+
[self.textView scrollRectToVisible:CGRectInset(caret, 0, -self.fontSize * 2) animated:NO];
|
|
217
|
+
self.suppressOffsetEvents = NO;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
- (NSDictionary *)selectedRangePayload {
|
|
222
|
+
NSRange range = self.textView.selectedRange;
|
|
223
|
+
if (range.location == NSNotFound || range.length == 0 || NSMaxRange(range) > self.textView.text.length) return nil;
|
|
224
|
+
NSString *text = [self.textView.text substringWithRange:range];
|
|
225
|
+
return @{ @"text": text, @"start": @(range.location), @"end": @(NSMaxRange(range)) };
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
- (void)textViewDidChangeSelection:(UITextView *)textView {
|
|
229
|
+
NSDictionary *payload = [self selectedRangePayload];
|
|
230
|
+
if (!payload) {
|
|
231
|
+
self.lastReportedStart = -1;
|
|
232
|
+
self.lastReportedEnd = -1;
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
NSInteger start = [payload[@"start"] integerValue];
|
|
236
|
+
NSInteger end = [payload[@"end"] integerValue];
|
|
237
|
+
if (start == self.lastReportedStart && end == self.lastReportedEnd) return;
|
|
238
|
+
self.lastReportedStart = start;
|
|
239
|
+
self.lastReportedEnd = end;
|
|
240
|
+
if (self.onTextRangeSelected) self.onTextRangeSelected(@{ @"nativeEvent": payload });
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
- (BOOL)isSingleWordSelection {
|
|
244
|
+
NSDictionary *payload = [self selectedRangePayload];
|
|
245
|
+
NSString *text = payload[@"text"];
|
|
246
|
+
if (text.length == 0 || text.length > 64) return NO;
|
|
247
|
+
NSCharacterSet *spaces = NSCharacterSet.whitespaceAndNewlineCharacterSet;
|
|
248
|
+
return [text rangeOfCharacterFromSet:spaces].location == NSNotFound;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
|
|
252
|
+
if (self.suppressOffsetEvents || !self.onTextOffsetChange || !self.hasLoadedDocument) return;
|
|
253
|
+
CGPoint point = CGPointMake(2, MAX(0, scrollView.contentOffset.y) + self.textView.textContainerInset.top + 2);
|
|
254
|
+
UITextPosition *position = [self.textView closestPositionToPoint:point];
|
|
255
|
+
if (!position) return;
|
|
256
|
+
NSInteger offset = [self.textView offsetFromPosition:self.textView.beginningOfDocument toPosition:position];
|
|
257
|
+
offset = MAX(0, MIN((NSInteger)self.textView.text.length, offset));
|
|
258
|
+
CFAbsoluteTime now = CFAbsoluteTimeGetCurrent();
|
|
259
|
+
if (offset == self.lastReportedOffset || now - self.lastOffsetEventTime < 0.06) return;
|
|
260
|
+
self.lastReportedOffset = offset;
|
|
261
|
+
self.lastOffsetEventTime = now;
|
|
262
|
+
_currentTextOffset = offset;
|
|
263
|
+
self.onTextOffsetChange(@{ @"nativeEvent": @{ @"offset": @(offset) } });
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
- (void)defineCurrentSelection:(id)sender {
|
|
267
|
+
#pragma unused(sender)
|
|
268
|
+
if ([self.defineSelectionMode isEqualToString:@"single-word"] && ![self isSingleWordSelection]) return;
|
|
269
|
+
NSDictionary *payload = [self selectedRangePayload];
|
|
270
|
+
if (payload && self.onDefineSelection) self.onDefineSelection(@{ @"nativeEvent": payload });
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
|
|
274
|
+
if (action == @selector(defineCurrentSelection:)) {
|
|
275
|
+
return [self selectedRangePayload] != nil &&
|
|
276
|
+
(![self.defineSelectionMode isEqualToString:@"single-word"] || [self isSingleWordSelection]);
|
|
277
|
+
}
|
|
278
|
+
return [super canPerformAction:action withSender:sender];
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
- (UIMenu *)textView:(UITextView *)textView
|
|
282
|
+
editMenuForTextInRange:(NSRange)range
|
|
283
|
+
suggestedActions:(NSArray<UIMenuElement *> *)suggestedActions API_AVAILABLE(ios(16.0)) {
|
|
284
|
+
if (range.location != NSNotFound && range.length > 0 && NSMaxRange(range) <= textView.text.length) {
|
|
285
|
+
textView.selectedRange = range;
|
|
286
|
+
}
|
|
287
|
+
NSMutableArray<UIMenuElement *> *actions = [suggestedActions mutableCopy] ?: [NSMutableArray array];
|
|
288
|
+
if ([self selectedRangePayload] &&
|
|
289
|
+
(![self.defineSelectionMode isEqualToString:@"single-word"] || [self isSingleWordSelection])) {
|
|
290
|
+
UIAction *define = [UIAction actionWithTitle:self.defineLabel image:nil identifier:nil handler:^(__kindof UIAction *action) {
|
|
291
|
+
#pragma unused(action)
|
|
292
|
+
[self defineCurrentSelection:nil];
|
|
293
|
+
}];
|
|
294
|
+
[actions insertObject:define atIndex:0];
|
|
295
|
+
}
|
|
296
|
+
return [UIMenu menuWithChildren:actions];
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
@end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#import <React/RCTViewManager.h>
|
|
2
|
+
#import "PapyrusTextDocumentView.h"
|
|
3
|
+
|
|
4
|
+
@interface PapyrusTextDocumentViewManager : RCTViewManager
|
|
5
|
+
@end
|
|
6
|
+
|
|
7
|
+
@implementation PapyrusTextDocumentViewManager
|
|
8
|
+
RCT_EXPORT_MODULE(PapyrusTextDocumentView)
|
|
9
|
+
RCT_EXPORT_VIEW_PROPERTY(engineId, NSString)
|
|
10
|
+
RCT_EXPORT_VIEW_PROPERTY(documentGeneration, NSInteger)
|
|
11
|
+
RCT_EXPORT_VIEW_PROPERTY(textLength, NSInteger)
|
|
12
|
+
RCT_EXPORT_VIEW_PROPERTY(currentTextOffset, NSInteger)
|
|
13
|
+
RCT_EXPORT_VIEW_PROPERTY(scrollToTextOffsetSignal, NSNumber)
|
|
14
|
+
RCT_EXPORT_VIEW_PROPERTY(searchResults, NSArray)
|
|
15
|
+
RCT_EXPORT_VIEW_PROPERTY(activeSearchIndex, NSInteger)
|
|
16
|
+
RCT_EXPORT_VIEW_PROPERTY(pageTheme, NSString)
|
|
17
|
+
RCT_EXPORT_VIEW_PROPERTY(uiTheme, NSString)
|
|
18
|
+
RCT_EXPORT_VIEW_PROPERTY(fontSize, CGFloat)
|
|
19
|
+
RCT_EXPORT_VIEW_PROPERTY(lineHeight, CGFloat)
|
|
20
|
+
RCT_EXPORT_VIEW_PROPERTY(pageMargin, CGFloat)
|
|
21
|
+
RCT_EXPORT_VIEW_PROPERTY(defineLabel, NSString)
|
|
22
|
+
RCT_EXPORT_VIEW_PROPERTY(defineSelectionMode, NSString)
|
|
23
|
+
RCT_EXPORT_VIEW_PROPERTY(onTextOffsetChange, RCTBubblingEventBlock)
|
|
24
|
+
RCT_EXPORT_VIEW_PROPERTY(onTextRangeSelected, RCTBubblingEventBlock)
|
|
25
|
+
RCT_EXPORT_VIEW_PROPERTY(onDefineSelection, RCTBubblingEventBlock)
|
|
26
|
+
|
|
27
|
+
+ (BOOL)requiresMainQueueSetup { return YES; }
|
|
28
|
+
- (UIView *)view { return [[PapyrusTextDocumentView alloc] initWithFrame:CGRectZero]; }
|
|
29
|
+
@end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#import <Foundation/Foundation.h>
|
|
2
|
+
|
|
3
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
4
|
+
|
|
5
|
+
@interface PapyrusTextStore : NSObject
|
|
6
|
+
+ (instancetype)shared;
|
|
7
|
+
- (void)setText:(NSString *)text engineId:(NSString *)engineId generation:(NSInteger)generation;
|
|
8
|
+
- (nullable NSString *)textForEngineId:(NSString *)engineId generation:(NSInteger)generation;
|
|
9
|
+
- (void)closeEngineId:(NSString *)engineId generation:(NSInteger)generation;
|
|
10
|
+
- (void)closeEngineId:(NSString *)engineId;
|
|
11
|
+
@end
|
|
12
|
+
|
|
13
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
#import "PapyrusTextStore.h"
|
|
2
|
+
|
|
3
|
+
@interface PapyrusTextStore ()
|
|
4
|
+
@property (nonatomic, strong) NSMutableDictionary<NSString *, NSDictionary *> *documents;
|
|
5
|
+
@property (nonatomic, strong) NSMutableSet<NSString *> *destroyedEngineIds;
|
|
6
|
+
@property (nonatomic, strong) NSMutableDictionary<NSString *, NSNumber *> *closedGenerations;
|
|
7
|
+
@property (nonatomic, strong) NSLock *lock;
|
|
8
|
+
@end
|
|
9
|
+
|
|
10
|
+
@implementation PapyrusTextStore
|
|
11
|
+
|
|
12
|
+
+ (instancetype)shared {
|
|
13
|
+
static PapyrusTextStore *store;
|
|
14
|
+
static dispatch_once_t onceToken;
|
|
15
|
+
dispatch_once(&onceToken, ^{
|
|
16
|
+
store = [[PapyrusTextStore alloc] init];
|
|
17
|
+
});
|
|
18
|
+
return store;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
- (instancetype)init {
|
|
22
|
+
self = [super init];
|
|
23
|
+
if (self) {
|
|
24
|
+
_documents = [NSMutableDictionary dictionary];
|
|
25
|
+
_destroyedEngineIds = [NSMutableSet set];
|
|
26
|
+
_closedGenerations = [NSMutableDictionary dictionary];
|
|
27
|
+
_lock = [[NSLock alloc] init];
|
|
28
|
+
}
|
|
29
|
+
return self;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
- (void)setText:(NSString *)text engineId:(NSString *)engineId generation:(NSInteger)generation {
|
|
33
|
+
if (engineId.length == 0 || !text) return;
|
|
34
|
+
[self.lock lock];
|
|
35
|
+
NSDictionary *previous = self.documents[engineId];
|
|
36
|
+
NSNumber *closed = self.closedGenerations[engineId];
|
|
37
|
+
NSInteger closedGeneration = closed ? closed.integerValue : -1;
|
|
38
|
+
if (![self.destroyedEngineIds containsObject:engineId] && generation > closedGeneration && [previous[@"generation"] integerValue] <= generation) {
|
|
39
|
+
self.documents[engineId] = @{ @"generation": @(generation), @"text": [text copy] };
|
|
40
|
+
}
|
|
41
|
+
[self.lock unlock];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
- (NSString *)textForEngineId:(NSString *)engineId generation:(NSInteger)generation {
|
|
45
|
+
[self.lock lock];
|
|
46
|
+
NSDictionary *entry = self.documents[engineId];
|
|
47
|
+
NSString *text = [entry[@"generation"] integerValue] == generation ? entry[@"text"] : nil;
|
|
48
|
+
[self.lock unlock];
|
|
49
|
+
return text;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
- (void)closeEngineId:(NSString *)engineId generation:(NSInteger)generation {
|
|
53
|
+
[self.lock lock];
|
|
54
|
+
NSNumber *closed = self.closedGenerations[engineId];
|
|
55
|
+
NSInteger closedGeneration = closed ? closed.integerValue : -1;
|
|
56
|
+
if (generation > closedGeneration) self.closedGenerations[engineId] = @(generation);
|
|
57
|
+
NSDictionary *entry = self.documents[engineId];
|
|
58
|
+
if ([entry[@"generation"] integerValue] <= generation) {
|
|
59
|
+
[self.documents removeObjectForKey:engineId];
|
|
60
|
+
}
|
|
61
|
+
[self.lock unlock];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
- (void)closeEngineId:(NSString *)engineId {
|
|
65
|
+
if (engineId.length == 0) return;
|
|
66
|
+
[self.lock lock];
|
|
67
|
+
[self.documents removeObjectForKey:engineId];
|
|
68
|
+
[self.destroyedEngineIds addObject:engineId];
|
|
69
|
+
[self.closedGenerations removeObjectForKey:engineId];
|
|
70
|
+
[self.lock unlock];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@end
|
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.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"papyrus",
|
|
@@ -33,6 +33,8 @@
|
|
|
33
33
|
"ios/*.h",
|
|
34
34
|
"ios/*.m",
|
|
35
35
|
"ios/*.podspec",
|
|
36
|
+
"vendor/libarchive",
|
|
37
|
+
"third_party_licenses",
|
|
36
38
|
"react-native.config.js"
|
|
37
39
|
],
|
|
38
40
|
"publishConfig": {
|
|
@@ -50,8 +52,8 @@
|
|
|
50
52
|
"build": "tsup"
|
|
51
53
|
},
|
|
52
54
|
"peerDependencies": {
|
|
53
|
-
"@papyrus-sdk/core": ">=0.2.18 || 0.2.23-beta.
|
|
54
|
-
"@papyrus-sdk/types": ">=0.2.11 || 0.2.16-beta.
|
|
55
|
+
"@papyrus-sdk/core": ">=0.2.18 || 0.2.23-beta.2",
|
|
56
|
+
"@papyrus-sdk/types": ">=0.2.11 || 0.2.16-beta.2",
|
|
55
57
|
"react-native": ">=0.81.0"
|
|
56
58
|
},
|
|
57
59
|
"devDependencies": {
|