@papyrus-sdk/engine-native 0.2.22-beta.9.epub.1 → 0.2.22-beta.9.epub.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (276) hide show
  1. package/android/build.gradle +0 -1
  2. package/android/src/main/cpp/CMakeLists.txt +0 -137
  3. package/android/src/main/java/com/papyrus/engine/PapyrusNativeEngineModule.java +35 -305
  4. package/android/src/main/java/com/papyrus/engine/PapyrusPackage.java +1 -3
  5. package/android/src/main/java/com/papyrus/engine/PapyrusPdfViewerView.java +5 -195
  6. package/android/src/main/java/com/papyrus/engine/PapyrusPdfViewerViewManager.java +1 -20
  7. package/dist/index.d.mts +4 -614
  8. package/dist/index.d.ts +4 -614
  9. package/dist/index.js +8 -484
  10. package/dist/index.js.map +1 -1
  11. package/dist/index.mjs +7 -477
  12. package/dist/index.mjs.map +1 -1
  13. package/ios/PapyrusEngineStore.h +0 -3
  14. package/ios/PapyrusEngineStore.m +6 -32
  15. package/ios/PapyrusNativeEngine.m +5 -684
  16. package/ios/PapyrusNativeEngine.podspec +15 -0
  17. package/ios/PapyrusPageView.m +11 -38
  18. package/package.json +8 -10
  19. package/react-native.config.js +1 -1
  20. package/PapyrusNativeEngine.podspec +0 -45
  21. package/android/src/main/cpp/PapyrusComicArchiveJni.cpp +0 -68
  22. package/android/src/main/cpp/PapyrusComicArchiveTest.cpp +0 -55
  23. package/android/src/main/cpp/papyrus_outline_loader_test.cpp +0 -240
  24. package/android/src/main/cpp/papyrus_text_word_test.cpp +0 -72
  25. package/android/src/main/java/com/papyrus/engine/PapyrusComicArchiveNative.java +0 -14
  26. package/android/src/main/java/com/papyrus/engine/PapyrusComicDocumentView.java +0 -491
  27. package/android/src/main/java/com/papyrus/engine/PapyrusComicDocumentViewManager.java +0 -32
  28. package/android/src/main/java/com/papyrus/engine/PapyrusComicPageLayout.java +0 -38
  29. package/android/src/main/java/com/papyrus/engine/PapyrusNativeTextModel.java +0 -195
  30. package/android/src/main/java/com/papyrus/engine/PapyrusSelectionMenuIcon.java +0 -48
  31. package/android/src/main/java/com/papyrus/engine/PapyrusTextAnnotationModel.java +0 -22
  32. package/android/src/main/java/com/papyrus/engine/PapyrusTextDocumentView.java +0 -661
  33. package/android/src/main/java/com/papyrus/engine/PapyrusTextDocumentViewManager.java +0 -49
  34. package/android/src/main/java/com/papyrus/engine/PapyrusTextStore.java +0 -43
  35. package/ios/PapyrusComicDocumentView.h +0 -21
  36. package/ios/PapyrusComicDocumentView.m +0 -554
  37. package/ios/PapyrusComicDocumentViewManager.m +0 -23
  38. package/ios/PapyrusPageRotationRegistry.h +0 -29
  39. package/ios/PapyrusPageRotationRegistry.m +0 -179
  40. package/ios/PapyrusPdfDocumentView.h +0 -55
  41. package/ios/PapyrusPdfDocumentView.m +0 -2339
  42. package/ios/PapyrusPdfDocumentViewManager.m +0 -61
  43. package/ios/PapyrusPdfPageTheme.h +0 -15
  44. package/ios/PapyrusPdfPageTheme.m +0 -218
  45. package/ios/PapyrusSelectionMenu.h +0 -27
  46. package/ios/PapyrusTextAnnotationRange.h +0 -2
  47. package/ios/PapyrusTextAnnotationRange.m +0 -29
  48. package/ios/PapyrusTextDocumentView.h +0 -32
  49. package/ios/PapyrusTextDocumentView.m +0 -518
  50. package/ios/PapyrusTextDocumentViewManager.m +0 -34
  51. package/ios/PapyrusTextStore.h +0 -13
  52. package/ios/PapyrusTextStore.m +0 -73
  53. package/third_party_licenses/BLAKE2-NOTICE.txt +0 -11
  54. package/third_party_licenses/libarchive-COPYING +0 -65
  55. package/vendor/libarchive/PapyrusComicArchive.cpp +0 -376
  56. package/vendor/libarchive/PapyrusComicArchive.h +0 -30
  57. package/vendor/libarchive/README.papyrus.md +0 -15
  58. package/vendor/libarchive/android.h +0 -192
  59. package/vendor/libarchive/config/PapyrusArchiveConfig.h +0 -71
  60. package/vendor/libarchive/libarchive/CMakeLists.txt +0 -293
  61. package/vendor/libarchive/libarchive/android_lf.h +0 -36
  62. package/vendor/libarchive/libarchive/archive.h +0 -1266
  63. package/vendor/libarchive/libarchive/archive_acl.c +0 -2025
  64. package/vendor/libarchive/libarchive/archive_acl_private.h +0 -85
  65. package/vendor/libarchive/libarchive/archive_blake2.h +0 -197
  66. package/vendor/libarchive/libarchive/archive_blake2_impl.h +0 -161
  67. package/vendor/libarchive/libarchive/archive_blake2s_ref.c +0 -369
  68. package/vendor/libarchive/libarchive/archive_blake2sp_ref.c +0 -361
  69. package/vendor/libarchive/libarchive/archive_check_magic.c +0 -183
  70. package/vendor/libarchive/libarchive/archive_cmdline.c +0 -211
  71. package/vendor/libarchive/libarchive/archive_cmdline_private.h +0 -45
  72. package/vendor/libarchive/libarchive/archive_crc32.h +0 -123
  73. package/vendor/libarchive/libarchive/archive_cryptor.c +0 -534
  74. package/vendor/libarchive/libarchive/archive_cryptor_private.h +0 -199
  75. package/vendor/libarchive/libarchive/archive_digest.c +0 -1584
  76. package/vendor/libarchive/libarchive/archive_digest_private.h +0 -431
  77. package/vendor/libarchive/libarchive/archive_disk_acl_darwin.c +0 -558
  78. package/vendor/libarchive/libarchive/archive_disk_acl_freebsd.c +0 -712
  79. package/vendor/libarchive/libarchive/archive_disk_acl_linux.c +0 -760
  80. package/vendor/libarchive/libarchive/archive_disk_acl_sunos.c +0 -824
  81. package/vendor/libarchive/libarchive/archive_endian.h +0 -234
  82. package/vendor/libarchive/libarchive/archive_entry.3 +0 -147
  83. package/vendor/libarchive/libarchive/archive_entry.c +0 -2297
  84. package/vendor/libarchive/libarchive/archive_entry.h +0 -763
  85. package/vendor/libarchive/libarchive/archive_entry_acl.3 +0 -458
  86. package/vendor/libarchive/libarchive/archive_entry_copy_bhfi.c +0 -55
  87. package/vendor/libarchive/libarchive/archive_entry_copy_stat.c +0 -82
  88. package/vendor/libarchive/libarchive/archive_entry_link_resolver.c +0 -472
  89. package/vendor/libarchive/libarchive/archive_entry_linkify.3 +0 -224
  90. package/vendor/libarchive/libarchive/archive_entry_locale.h +0 -90
  91. package/vendor/libarchive/libarchive/archive_entry_misc.3 +0 -63
  92. package/vendor/libarchive/libarchive/archive_entry_paths.3 +0 -153
  93. package/vendor/libarchive/libarchive/archive_entry_perms.3 +0 -210
  94. package/vendor/libarchive/libarchive/archive_entry_private.h +0 -205
  95. package/vendor/libarchive/libarchive/archive_entry_sparse.c +0 -156
  96. package/vendor/libarchive/libarchive/archive_entry_stat.3 +0 -274
  97. package/vendor/libarchive/libarchive/archive_entry_stat.c +0 -121
  98. package/vendor/libarchive/libarchive/archive_entry_strmode.c +0 -69
  99. package/vendor/libarchive/libarchive/archive_entry_time.3 +0 -127
  100. package/vendor/libarchive/libarchive/archive_entry_xattr.c +0 -155
  101. package/vendor/libarchive/libarchive/archive_hmac.c +0 -345
  102. package/vendor/libarchive/libarchive/archive_hmac_private.h +0 -119
  103. package/vendor/libarchive/libarchive/archive_integer.h +0 -267
  104. package/vendor/libarchive/libarchive/archive_match.c +0 -1869
  105. package/vendor/libarchive/libarchive/archive_openssl_evp_private.h +0 -54
  106. package/vendor/libarchive/libarchive/archive_openssl_hmac_private.h +0 -54
  107. package/vendor/libarchive/libarchive/archive_options.c +0 -219
  108. package/vendor/libarchive/libarchive/archive_options_private.h +0 -49
  109. package/vendor/libarchive/libarchive/archive_pack_dev.c +0 -330
  110. package/vendor/libarchive/libarchive/archive_pack_dev.h +0 -49
  111. package/vendor/libarchive/libarchive/archive_parse_date.c +0 -1173
  112. package/vendor/libarchive/libarchive/archive_pathmatch.c +0 -480
  113. package/vendor/libarchive/libarchive/archive_pathmatch.h +0 -50
  114. package/vendor/libarchive/libarchive/archive_platform.h +0 -213
  115. package/vendor/libarchive/libarchive/archive_platform_acl.h +0 -53
  116. package/vendor/libarchive/libarchive/archive_platform_stat.h +0 -45
  117. package/vendor/libarchive/libarchive/archive_platform_xattr.h +0 -45
  118. package/vendor/libarchive/libarchive/archive_ppmd7.c +0 -1173
  119. package/vendor/libarchive/libarchive/archive_ppmd7_private.h +0 -119
  120. package/vendor/libarchive/libarchive/archive_ppmd8.c +0 -1293
  121. package/vendor/libarchive/libarchive/archive_ppmd8_private.h +0 -123
  122. package/vendor/libarchive/libarchive/archive_ppmd_private.h +0 -159
  123. package/vendor/libarchive/libarchive/archive_private.h +0 -209
  124. package/vendor/libarchive/libarchive/archive_random.c +0 -274
  125. package/vendor/libarchive/libarchive/archive_random_private.h +0 -36
  126. package/vendor/libarchive/libarchive/archive_rb.c +0 -709
  127. package/vendor/libarchive/libarchive/archive_rb.h +0 -113
  128. package/vendor/libarchive/libarchive/archive_read.3 +0 -250
  129. package/vendor/libarchive/libarchive/archive_read.c +0 -1814
  130. package/vendor/libarchive/libarchive/archive_read_add_passphrase.3 +0 -72
  131. package/vendor/libarchive/libarchive/archive_read_add_passphrase.c +0 -189
  132. package/vendor/libarchive/libarchive/archive_read_append_filter.c +0 -209
  133. package/vendor/libarchive/libarchive/archive_read_data.3 +0 -128
  134. package/vendor/libarchive/libarchive/archive_read_data_into_fd.c +0 -207
  135. package/vendor/libarchive/libarchive/archive_read_disk.3 +0 -422
  136. package/vendor/libarchive/libarchive/archive_read_disk_entry_from_file.c +0 -1086
  137. package/vendor/libarchive/libarchive/archive_read_disk_posix.c +0 -2639
  138. package/vendor/libarchive/libarchive/archive_read_disk_private.h +0 -97
  139. package/vendor/libarchive/libarchive/archive_read_disk_set_standard_lookup.c +0 -315
  140. package/vendor/libarchive/libarchive/archive_read_disk_windows.c +0 -2603
  141. package/vendor/libarchive/libarchive/archive_read_extract.3 +0 -135
  142. package/vendor/libarchive/libarchive/archive_read_extract.c +0 -59
  143. package/vendor/libarchive/libarchive/archive_read_extract2.c +0 -154
  144. package/vendor/libarchive/libarchive/archive_read_filter.3 +0 -163
  145. package/vendor/libarchive/libarchive/archive_read_format.3 +0 -190
  146. package/vendor/libarchive/libarchive/archive_read_free.3 +0 -91
  147. package/vendor/libarchive/libarchive/archive_read_header.3 +0 -89
  148. package/vendor/libarchive/libarchive/archive_read_new.3 +0 -57
  149. package/vendor/libarchive/libarchive/archive_read_open.3 +0 -247
  150. package/vendor/libarchive/libarchive/archive_read_open_fd.c +0 -236
  151. package/vendor/libarchive/libarchive/archive_read_open_file.c +0 -257
  152. package/vendor/libarchive/libarchive/archive_read_open_filename.c +0 -652
  153. package/vendor/libarchive/libarchive/archive_read_open_memory.c +0 -188
  154. package/vendor/libarchive/libarchive/archive_read_private.h +0 -274
  155. package/vendor/libarchive/libarchive/archive_read_set_format.c +0 -116
  156. package/vendor/libarchive/libarchive/archive_read_set_options.3 +0 -290
  157. package/vendor/libarchive/libarchive/archive_read_set_options.c +0 -132
  158. package/vendor/libarchive/libarchive/archive_read_support_filter_all.c +0 -84
  159. package/vendor/libarchive/libarchive/archive_read_support_filter_by_code.c +0 -68
  160. package/vendor/libarchive/libarchive/archive_read_support_filter_bzip2.c +0 -360
  161. package/vendor/libarchive/libarchive/archive_read_support_filter_compress.c +0 -457
  162. package/vendor/libarchive/libarchive/archive_read_support_filter_grzip.c +0 -108
  163. package/vendor/libarchive/libarchive/archive_read_support_filter_gzip.c +0 -538
  164. package/vendor/libarchive/libarchive/archive_read_support_filter_lrzip.c +0 -119
  165. package/vendor/libarchive/libarchive/archive_read_support_filter_lz4.c +0 -829
  166. package/vendor/libarchive/libarchive/archive_read_support_filter_lzop.c +0 -493
  167. package/vendor/libarchive/libarchive/archive_read_support_filter_none.c +0 -51
  168. package/vendor/libarchive/libarchive/archive_read_support_filter_program.c +0 -497
  169. package/vendor/libarchive/libarchive/archive_read_support_filter_rpm.c +0 -249
  170. package/vendor/libarchive/libarchive/archive_read_support_filter_uu.c +0 -739
  171. package/vendor/libarchive/libarchive/archive_read_support_filter_xz.c +0 -792
  172. package/vendor/libarchive/libarchive/archive_read_support_filter_zstd.c +0 -356
  173. package/vendor/libarchive/libarchive/archive_read_support_format_7zip.c +0 -4650
  174. package/vendor/libarchive/libarchive/archive_read_support_format_all.c +0 -88
  175. package/vendor/libarchive/libarchive/archive_read_support_format_ar.c +0 -597
  176. package/vendor/libarchive/libarchive/archive_read_support_format_by_code.c +0 -76
  177. package/vendor/libarchive/libarchive/archive_read_support_format_cab.c +0 -3410
  178. package/vendor/libarchive/libarchive/archive_read_support_format_cpio.c +0 -1152
  179. package/vendor/libarchive/libarchive/archive_read_support_format_empty.c +0 -95
  180. package/vendor/libarchive/libarchive/archive_read_support_format_iso9660.c +0 -3516
  181. package/vendor/libarchive/libarchive/archive_read_support_format_lha.c +0 -2931
  182. package/vendor/libarchive/libarchive/archive_read_support_format_mtree.c +0 -2113
  183. package/vendor/libarchive/libarchive/archive_read_support_format_rar.c +0 -3932
  184. package/vendor/libarchive/libarchive/archive_read_support_format_rar5.c +0 -4501
  185. package/vendor/libarchive/libarchive/archive_read_support_format_raw.c +0 -194
  186. package/vendor/libarchive/libarchive/archive_read_support_format_tar.c +0 -3785
  187. package/vendor/libarchive/libarchive/archive_read_support_format_warc.c +0 -875
  188. package/vendor/libarchive/libarchive/archive_read_support_format_xar.c +0 -3770
  189. package/vendor/libarchive/libarchive/archive_read_support_format_zip.c +0 -4710
  190. package/vendor/libarchive/libarchive/archive_string.c +0 -4391
  191. package/vendor/libarchive/libarchive/archive_string.h +0 -244
  192. package/vendor/libarchive/libarchive/archive_string_composition.h +0 -2289
  193. package/vendor/libarchive/libarchive/archive_string_sprintf.c +0 -200
  194. package/vendor/libarchive/libarchive/archive_time.c +0 -168
  195. package/vendor/libarchive/libarchive/archive_time_private.h +0 -47
  196. package/vendor/libarchive/libarchive/archive_util.3 +0 -239
  197. package/vendor/libarchive/libarchive/archive_util.c +0 -668
  198. package/vendor/libarchive/libarchive/archive_version_details.c +0 -516
  199. package/vendor/libarchive/libarchive/archive_virtual.c +0 -162
  200. package/vendor/libarchive/libarchive/archive_windows.c +0 -1035
  201. package/vendor/libarchive/libarchive/archive_windows.h +0 -332
  202. package/vendor/libarchive/libarchive/archive_write.3 +0 -266
  203. package/vendor/libarchive/libarchive/archive_write.c +0 -896
  204. package/vendor/libarchive/libarchive/archive_write_add_filter.c +0 -71
  205. package/vendor/libarchive/libarchive/archive_write_add_filter_b64encode.c +0 -329
  206. package/vendor/libarchive/libarchive/archive_write_add_filter_by_name.c +0 -76
  207. package/vendor/libarchive/libarchive/archive_write_add_filter_bzip2.c +0 -411
  208. package/vendor/libarchive/libarchive/archive_write_add_filter_compress.c +0 -459
  209. package/vendor/libarchive/libarchive/archive_write_add_filter_grzip.c +0 -143
  210. package/vendor/libarchive/libarchive/archive_write_add_filter_gzip.c +0 -493
  211. package/vendor/libarchive/libarchive/archive_write_add_filter_lrzip.c +0 -214
  212. package/vendor/libarchive/libarchive/archive_write_add_filter_lz4.c +0 -710
  213. package/vendor/libarchive/libarchive/archive_write_add_filter_lzop.c +0 -500
  214. package/vendor/libarchive/libarchive/archive_write_add_filter_none.c +0 -42
  215. package/vendor/libarchive/libarchive/archive_write_add_filter_program.c +0 -398
  216. package/vendor/libarchive/libarchive/archive_write_add_filter_uuencode.c +0 -320
  217. package/vendor/libarchive/libarchive/archive_write_add_filter_xz.c +0 -547
  218. package/vendor/libarchive/libarchive/archive_write_add_filter_zstd.c +0 -608
  219. package/vendor/libarchive/libarchive/archive_write_blocksize.3 +0 -112
  220. package/vendor/libarchive/libarchive/archive_write_data.3 +0 -88
  221. package/vendor/libarchive/libarchive/archive_write_disk.3 +0 -360
  222. package/vendor/libarchive/libarchive/archive_write_disk_posix.c +0 -4789
  223. package/vendor/libarchive/libarchive/archive_write_disk_private.h +0 -43
  224. package/vendor/libarchive/libarchive/archive_write_disk_set_standard_lookup.c +0 -265
  225. package/vendor/libarchive/libarchive/archive_write_disk_windows.c +0 -2952
  226. package/vendor/libarchive/libarchive/archive_write_filter.3 +0 -140
  227. package/vendor/libarchive/libarchive/archive_write_finish_entry.3 +0 -77
  228. package/vendor/libarchive/libarchive/archive_write_format.3 +0 -187
  229. package/vendor/libarchive/libarchive/archive_write_free.3 +0 -94
  230. package/vendor/libarchive/libarchive/archive_write_header.3 +0 -71
  231. package/vendor/libarchive/libarchive/archive_write_new.3 +0 -56
  232. package/vendor/libarchive/libarchive/archive_write_open.3 +0 -270
  233. package/vendor/libarchive/libarchive/archive_write_open_fd.c +0 -141
  234. package/vendor/libarchive/libarchive/archive_write_open_file.c +0 -102
  235. package/vendor/libarchive/libarchive/archive_write_open_filename.c +0 -272
  236. package/vendor/libarchive/libarchive/archive_write_open_memory.c +0 -110
  237. package/vendor/libarchive/libarchive/archive_write_private.h +0 -166
  238. package/vendor/libarchive/libarchive/archive_write_set_format.c +0 -124
  239. package/vendor/libarchive/libarchive/archive_write_set_format_7zip.c +0 -2571
  240. package/vendor/libarchive/libarchive/archive_write_set_format_ar.c +0 -540
  241. package/vendor/libarchive/libarchive/archive_write_set_format_by_name.c +0 -93
  242. package/vendor/libarchive/libarchive/archive_write_set_format_cpio.c +0 -11
  243. package/vendor/libarchive/libarchive/archive_write_set_format_cpio_binary.c +0 -618
  244. package/vendor/libarchive/libarchive/archive_write_set_format_cpio_newc.c +0 -457
  245. package/vendor/libarchive/libarchive/archive_write_set_format_cpio_odc.c +0 -508
  246. package/vendor/libarchive/libarchive/archive_write_set_format_filter_by_ext.c +0 -141
  247. package/vendor/libarchive/libarchive/archive_write_set_format_gnutar.c +0 -790
  248. package/vendor/libarchive/libarchive/archive_write_set_format_iso9660.c +0 -8216
  249. package/vendor/libarchive/libarchive/archive_write_set_format_mtree.c +0 -2307
  250. package/vendor/libarchive/libarchive/archive_write_set_format_pax.c +0 -2249
  251. package/vendor/libarchive/libarchive/archive_write_set_format_private.h +0 -40
  252. package/vendor/libarchive/libarchive/archive_write_set_format_raw.c +0 -123
  253. package/vendor/libarchive/libarchive/archive_write_set_format_shar.c +0 -650
  254. package/vendor/libarchive/libarchive/archive_write_set_format_ustar.c +0 -768
  255. package/vendor/libarchive/libarchive/archive_write_set_format_v7tar.c +0 -648
  256. package/vendor/libarchive/libarchive/archive_write_set_format_warc.c +0 -491
  257. package/vendor/libarchive/libarchive/archive_write_set_format_xar.c +0 -3799
  258. package/vendor/libarchive/libarchive/archive_write_set_format_zip.c +0 -2548
  259. package/vendor/libarchive/libarchive/archive_write_set_options.3 +0 -779
  260. package/vendor/libarchive/libarchive/archive_write_set_options.c +0 -129
  261. package/vendor/libarchive/libarchive/archive_write_set_passphrase.3 +0 -72
  262. package/vendor/libarchive/libarchive/archive_write_set_passphrase.c +0 -95
  263. package/vendor/libarchive/libarchive/archive_xxhash.h +0 -48
  264. package/vendor/libarchive/libarchive/config_freebsd.h +0 -275
  265. package/vendor/libarchive/libarchive/cpio.5 +0 -389
  266. package/vendor/libarchive/libarchive/filter_fork.h +0 -44
  267. package/vendor/libarchive/libarchive/filter_fork_posix.c +0 -269
  268. package/vendor/libarchive/libarchive/filter_fork_windows.c +0 -270
  269. package/vendor/libarchive/libarchive/libarchive-formats.5 +0 -478
  270. package/vendor/libarchive/libarchive/libarchive.3 +0 -297
  271. package/vendor/libarchive/libarchive/libarchive_changes.3 +0 -339
  272. package/vendor/libarchive/libarchive/libarchive_internals.3 +0 -363
  273. package/vendor/libarchive/libarchive/module.modulemap +0 -34
  274. package/vendor/libarchive/libarchive/mtree.5 +0 -323
  275. package/vendor/libarchive/libarchive/tar.5 +0 -947
  276. package/vendor/libarchive/libarchive/xxhash.c +0 -531
@@ -1,49 +0,0 @@
1
- package com.papyrus.engine;
2
-
3
- import androidx.annotation.NonNull;
4
- import androidx.annotation.Nullable;
5
-
6
- import com.facebook.react.bridge.ReadableArray;
7
- import com.facebook.react.bridge.ReadableMap;
8
- import com.facebook.react.common.MapBuilder;
9
- import com.facebook.react.uimanager.SimpleViewManager;
10
- import com.facebook.react.uimanager.ThemedReactContext;
11
- import com.facebook.react.uimanager.annotations.ReactProp;
12
-
13
- import java.util.Map;
14
-
15
- public final class PapyrusTextDocumentViewManager extends SimpleViewManager<PapyrusTextDocumentView> {
16
- @NonNull @Override public String getName() { return "PapyrusTextDocumentView"; }
17
-
18
- @NonNull @Override protected PapyrusTextDocumentView createViewInstance(@NonNull ThemedReactContext context) {
19
- return new PapyrusTextDocumentView(context);
20
- }
21
-
22
- @Nullable @Override public Map<String, Object> getExportedCustomBubblingEventTypeConstants() {
23
- return MapBuilder.<String, Object>builder()
24
- .put("onTextOffsetChange", MapBuilder.of("phasedRegistrationNames", MapBuilder.of("bubbled", "onTextOffsetChange")))
25
- .put("onTextRangeSelected", MapBuilder.of("phasedRegistrationNames", MapBuilder.of("bubbled", "onTextRangeSelected")))
26
- .put("onDefineSelection", MapBuilder.of("phasedRegistrationNames", MapBuilder.of("bubbled", "onDefineSelection")))
27
- .put("onAnnotateSelection", MapBuilder.of("phasedRegistrationNames", MapBuilder.of("bubbled", "onAnnotateSelection")))
28
- .put("onAnnotationTap", MapBuilder.of("phasedRegistrationNames", MapBuilder.of("bubbled", "onAnnotationTap")))
29
- .build();
30
- }
31
-
32
- @ReactProp(name = "annotations") public void setAnnotations(PapyrusTextDocumentView view, ReadableArray value) { view.setAnnotations(value); }
33
- @ReactProp(name = "annotationLabels") public void setAnnotationLabels(PapyrusTextDocumentView view, ReadableMap value) { view.setAnnotationLabels(value); }
34
- @ReactProp(name = "engineId") public void setEngineId(PapyrusTextDocumentView view, String value) { view.setEngineId(value); }
35
- @ReactProp(name = "documentGeneration", defaultInt = 0) public void setDocumentGeneration(PapyrusTextDocumentView view, int value) { view.setDocumentGeneration(value); }
36
- @ReactProp(name = "textLength", defaultInt = 0) public void setTextLength(PapyrusTextDocumentView view, int value) { view.setTextLength(value); }
37
- @ReactProp(name = "currentTextOffset", defaultInt = 0) public void setCurrentTextOffset(PapyrusTextDocumentView view, int value) { view.setCurrentTextOffset(value); }
38
- @ReactProp(name = "scrollToTextOffsetSignal") public void setScrollToTextOffsetSignal(PapyrusTextDocumentView view, Integer value) { view.setScrollToTextOffsetSignal(value); }
39
- @ReactProp(name = "textNavigationRequest") public void setTextNavigationRequest(PapyrusTextDocumentView view, ReadableMap value) {view.setTextNavigationRequest(value);}
40
- @ReactProp(name = "searchResults") public void setSearchResults(PapyrusTextDocumentView view, ReadableArray value) { view.setSearchResults(value); }
41
- @ReactProp(name = "activeSearchIndex", defaultInt = -1) public void setActiveSearchIndex(PapyrusTextDocumentView view, int value) { view.setActiveSearchIndex(value); }
42
- @ReactProp(name = "pageTheme") public void setPageTheme(PapyrusTextDocumentView view, String value) { view.setPageTheme(value); }
43
- @ReactProp(name = "uiTheme") public void setUiTheme(PapyrusTextDocumentView view, String value) { view.setUiTheme(value); }
44
- @ReactProp(name = "fontSize", defaultFloat = 18f) public void setFontSize(PapyrusTextDocumentView view, float value) { view.setFontSize(value); }
45
- @ReactProp(name = "lineHeight", defaultFloat = 28f) public void setLineHeight(PapyrusTextDocumentView view, float value) { view.setLineHeight(value); }
46
- @ReactProp(name = "pageMargin", defaultFloat = 20f) public void setPageMargin(PapyrusTextDocumentView view, float value) { view.setPageMargin(value); }
47
- @ReactProp(name = "defineLabel") public void setDefineLabel(PapyrusTextDocumentView view, String value) { view.setDefineLabel(value); }
48
- @ReactProp(name = "defineSelectionMode") public void setDefineSelectionMode(PapyrusTextDocumentView view, String value) { view.setDefineSelectionMode(value); }
49
- }
@@ -1,43 +0,0 @@
1
- package com.papyrus.engine;
2
-
3
- import java.util.concurrent.ConcurrentHashMap;
4
-
5
- final class PapyrusTextStore {
6
- private static final class Document {
7
- final int generation;
8
- final String text;
9
- Document(int generation, String text) { this.generation = generation; this.text = text; }
10
- }
11
-
12
- private static final ConcurrentHashMap<String, Document> DOCUMENTS = new ConcurrentHashMap<>();
13
- private static final ConcurrentHashMap<String, Integer> CLOSED_GENERATIONS = new ConcurrentHashMap<>();
14
- private static final java.util.Set<String> DESTROYED = ConcurrentHashMap.newKeySet();
15
-
16
- private PapyrusTextStore() {}
17
-
18
- static synchronized void setText(String engineId, int generation, String text) {
19
- if (engineId == null || engineId.isEmpty() || DESTROYED.contains(engineId)) return;
20
- if (generation <= CLOSED_GENERATIONS.getOrDefault(engineId, -1)) return;
21
- DOCUMENTS.compute(engineId, (key, current) ->
22
- current == null || generation >= current.generation ? new Document(generation, text) : current);
23
- }
24
-
25
- static String getText(String engineId, int generation) {
26
- Document document = DOCUMENTS.get(engineId);
27
- return document != null && document.generation == generation ? document.text : null;
28
- }
29
-
30
- static synchronized void close(String engineId, int generation) {
31
- if (engineId == null || engineId.isEmpty()) return;
32
- CLOSED_GENERATIONS.merge(engineId, generation, Math::max);
33
- DOCUMENTS.computeIfPresent(engineId, (key, current) ->
34
- current.generation <= generation ? null : current);
35
- }
36
-
37
- static synchronized void close(String engineId) {
38
- if (engineId == null || engineId.isEmpty()) return;
39
- DOCUMENTS.remove(engineId);
40
- DESTROYED.add(engineId);
41
- CLOSED_GENERATIONS.remove(engineId);
42
- }
43
- }
@@ -1,21 +0,0 @@
1
- #import <UIKit/UIKit.h>
2
- #import <React/RCTComponent.h>
3
-
4
- NS_ASSUME_NONNULL_BEGIN
5
-
6
- @interface PapyrusComicDocumentView : UIView <UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>
7
- @property (nonatomic, copy, nullable) NSString *engineId;
8
- @property (nonatomic, assign) NSInteger documentGeneration;
9
- @property (nonatomic, assign) NSInteger pageCount;
10
- @property (nonatomic, assign) NSInteger currentPage;
11
- @property (nonatomic, copy) NSString *layoutMode;
12
- @property (nonatomic, copy) NSString *fitMode;
13
- @property (nonatomic, copy) NSString *readingDirection;
14
- @property (nonatomic, assign) CGFloat zoom;
15
- @property (nonatomic, copy) NSString *pageTheme;
16
- @property (nonatomic, copy, nullable) RCTBubblingEventBlock onPageChanged;
17
- @property (nonatomic, copy, nullable) RCTBubblingEventBlock onZoomChanged;
18
- @property (nonatomic, copy, nullable) RCTBubblingEventBlock onError;
19
- @end
20
-
21
- NS_ASSUME_NONNULL_END
@@ -1,554 +0,0 @@
1
- #import "PapyrusComicDocumentView.h"
2
- #import "../vendor/libarchive/PapyrusComicArchive.h"
3
- #import <ImageIO/ImageIO.h>
4
- #import <math.h>
5
-
6
- static NSString * const PapyrusComicCellId = @"PapyrusComicPageCell";
7
- static NSCache<NSString *, UIImage *> *PapyrusComicImageCache(void) {
8
- static NSCache<NSString *, UIImage *> *cache;
9
- static dispatch_once_t once;
10
- dispatch_once(&once, ^{
11
- cache = [[NSCache alloc] init];
12
- cache.totalCostLimit = 64 * 1024 * 1024;
13
- });
14
- return cache;
15
- }
16
-
17
- @interface PapyrusComicPageCell : UICollectionViewCell
18
- @property (nonatomic, strong) UIScrollView *pageScrollView;
19
- @property (nonatomic, strong) UIImageView *imageView;
20
- @property (nonatomic, copy) NSString *representedKey;
21
- @property (nonatomic, assign) BOOL fitWidthInSingleMode;
22
- @end
23
-
24
- @implementation PapyrusComicPageCell
25
- - (instancetype)initWithFrame:(CGRect)frame {
26
- self = [super initWithFrame:frame];
27
- if (self) {
28
- _pageScrollView = [[UIScrollView alloc] initWithFrame:self.contentView.bounds];
29
- _pageScrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
30
- _pageScrollView.alwaysBounceVertical = NO;
31
- _pageScrollView.showsVerticalScrollIndicator = NO;
32
- _pageScrollView.showsHorizontalScrollIndicator = NO;
33
- [self.contentView addSubview:_pageScrollView];
34
- _imageView = [[UIImageView alloc] initWithFrame:_pageScrollView.bounds];
35
- _imageView.contentMode = UIViewContentModeScaleAspectFit;
36
- [_pageScrollView addSubview:_imageView];
37
- }
38
- return self;
39
- }
40
- - (void)layoutSubviews {
41
- [super layoutSubviews];
42
- self.pageScrollView.frame = self.contentView.bounds;
43
- CGAffineTransform transform = self.imageView.transform;
44
- self.imageView.transform = CGAffineTransformIdentity;
45
- CGSize size = self.pageScrollView.bounds.size;
46
- UIImage *image = self.imageView.image;
47
- if (self.fitWidthInSingleMode && image.size.width > 0 && image.size.height > 0) {
48
- size.height = MAX(1, size.width * image.size.height / image.size.width);
49
- }
50
- self.imageView.frame = (CGRect){CGPointZero, size};
51
- self.pageScrollView.contentSize = size;
52
- BOOL canScroll = self.fitWidthInSingleMode && size.height > self.pageScrollView.bounds.size.height;
53
- self.pageScrollView.scrollEnabled = canScroll;
54
- self.pageScrollView.alwaysBounceVertical = canScroll;
55
- self.imageView.transform = transform;
56
- }
57
- - (void)prepareForReuse {
58
- [super prepareForReuse];
59
- self.pageScrollView.contentOffset = CGPointZero;
60
- self.pageScrollView.contentSize = self.pageScrollView.bounds.size;
61
- self.pageScrollView.scrollEnabled = NO;
62
- self.pageScrollView.alwaysBounceVertical = NO;
63
- self.imageView.image = nil;
64
- self.imageView.transform = CGAffineTransformIdentity;
65
- self.fitWidthInSingleMode = NO;
66
- }
67
- @end
68
-
69
- @interface PapyrusComicDocumentView () <UIGestureRecognizerDelegate>
70
- @property (nonatomic, strong) UICollectionView *collectionView;
71
- @property (nonatomic, strong) UICollectionViewFlowLayout *flowLayout;
72
- @property (nonatomic, strong) UIPinchGestureRecognizer *pinchRecognizer;
73
- @property (nonatomic, strong) UITapGestureRecognizer *doubleTapRecognizer;
74
- @property (nonatomic, strong) UIPanGestureRecognizer *pagePanRecognizer;
75
- @property (nonatomic, assign) BOOL applyingProgrammaticPage;
76
- @property (nonatomic, strong) NSMutableSet<NSString *> *reportedErrors;
77
- @property (nonatomic, strong) NSMutableDictionary<NSNumber *, NSValue *> *pageSizes;
78
- @property (nonatomic, strong) NSMutableDictionary<NSNumber *, NSValue *> *pendingPageSizes;
79
- @property (nonatomic, assign) BOOL pendingViewportLayout;
80
- @property (nonatomic, assign) CGSize viewportSize;
81
- @property (nonatomic, assign) NSInteger requestedPage;
82
- @property (nonatomic, assign) BOOL pendingNavigation;
83
- @property (nonatomic, assign) CGPoint panOffset;
84
- @property (nonatomic, assign) CGPoint panGestureStartOffset;
85
- @end
86
-
87
- @implementation PapyrusComicDocumentView
88
-
89
- - (instancetype)initWithFrame:(CGRect)frame {
90
- self = [super initWithFrame:frame];
91
- if (self) {
92
- _pageCount = 0;
93
- _currentPage = 1;
94
- _requestedPage = 1;
95
- _pendingNavigation = YES;
96
- _pageSizes = [NSMutableDictionary dictionary];
97
- _pendingPageSizes = [NSMutableDictionary dictionary];
98
- _layoutMode = @"single";
99
- _fitMode = @"width";
100
- _readingDirection = @"ltr";
101
- _zoom = 1;
102
- _reportedErrors = [NSMutableSet set];
103
- _pageTheme = @"normal";
104
- _flowLayout = [[UICollectionViewFlowLayout alloc] init];
105
- _flowLayout.minimumLineSpacing = 0;
106
- _flowLayout.minimumInteritemSpacing = 0;
107
- _collectionView = [[UICollectionView alloc] initWithFrame:self.bounds collectionViewLayout:_flowLayout];
108
- _collectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
109
- _collectionView.dataSource = self;
110
- _collectionView.delegate = self;
111
- _collectionView.backgroundColor = UIColor.blackColor;
112
- _collectionView.pagingEnabled = YES;
113
- _collectionView.showsVerticalScrollIndicator = YES;
114
- _collectionView.showsHorizontalScrollIndicator = NO;
115
- [_collectionView registerClass:PapyrusComicPageCell.class forCellWithReuseIdentifier:PapyrusComicCellId];
116
- [self addSubview:_collectionView];
117
- _pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinch:)];
118
- _pinchRecognizer.cancelsTouchesInView = NO;
119
- _pinchRecognizer.delegate = self;
120
- [_collectionView addGestureRecognizer:_pinchRecognizer];
121
- _doubleTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)];
122
- _doubleTapRecognizer.numberOfTapsRequired = 2;
123
- _doubleTapRecognizer.numberOfTouchesRequired = 1;
124
- _doubleTapRecognizer.cancelsTouchesInView = YES;
125
- _doubleTapRecognizer.delegate = self;
126
- [_collectionView addGestureRecognizer:_doubleTapRecognizer];
127
- _pagePanRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePagePan:)];
128
- _pagePanRecognizer.minimumNumberOfTouches = 1;
129
- _pagePanRecognizer.maximumNumberOfTouches = 1;
130
- _pagePanRecognizer.cancelsTouchesInView = NO;
131
- _pagePanRecognizer.delegate = self;
132
- [_collectionView addGestureRecognizer:_pagePanRecognizer];
133
- [self applyLayoutMode];
134
- [self applyTheme];
135
- }
136
- return self;
137
- }
138
-
139
- // Anchors reference the page, not an absolute document offset. Heights can change
140
- // above the viewport as images arrive; bitmap eviction must not change geometry.
141
- - (NSDictionary *)captureScrollAnchorForViewport:(CGSize)viewport {
142
- if (self.pendingNavigation || viewport.width <= 0 || viewport.height <= 0) return nil;
143
- CGPoint center = CGPointMake(self.collectionView.contentOffset.x + viewport.width / 2,
144
- self.collectionView.contentOffset.y + viewport.height / 2);
145
- UICollectionViewLayoutAttributes *nearest = nil;
146
- CGFloat distance = CGFLOAT_MAX;
147
- for (NSIndexPath *path in self.collectionView.indexPathsForVisibleItems) {
148
- UICollectionViewLayoutAttributes *attributes = [self.flowLayout layoutAttributesForItemAtIndexPath:path];
149
- if (!attributes) continue;
150
- CGFloat next = ABS(CGRectGetMidY(attributes.frame) - center.y);
151
- if (next < distance) { nearest = attributes; distance = next; }
152
- if (CGRectContainsPoint(attributes.frame, center)) { nearest = attributes; break; }
153
- }
154
- if (!nearest || nearest.frame.size.height <= 0) return nil;
155
- return @{ @"pageIndex": @([self logicalPageForItem:nearest.indexPath.item]),
156
- @"fraction": @(MAX(0, MIN(1, (center.y - nearest.frame.origin.y) / nearest.frame.size.height))) };
157
- }
158
-
159
- - (void)restoreScrollAnchor:(NSDictionary *)anchor {
160
- if (self.collectionView.dragging || self.collectionView.decelerating) return;
161
- if (!anchor || self.pendingNavigation || ![self.layoutMode isEqualToString:@"continuous"]) return;
162
- NSInteger page = [anchor[@"pageIndex"] integerValue];
163
- if (page < 0 || page >= self.pageCount) return;
164
- NSInteger item = [self itemForLogicalPage:page + 1];
165
- UICollectionViewLayoutAttributes *attributes = [self.flowLayout layoutAttributesForItemAtIndexPath:[NSIndexPath indexPathForItem:item inSection:0]];
166
- if (!attributes) return;
167
- CGFloat y = attributes.frame.origin.y + [anchor[@"fraction"] doubleValue] * attributes.frame.size.height - self.collectionView.bounds.size.height / 2;
168
- CGFloat minimum = -self.collectionView.adjustedContentInset.top;
169
- CGFloat maximum = MAX(minimum, self.collectionView.contentSize.height - self.collectionView.bounds.size.height + self.collectionView.adjustedContentInset.bottom);
170
- BOOL wasApplying = self.applyingProgrammaticPage;
171
- self.applyingProgrammaticPage = YES;
172
- [self.collectionView setContentOffset:CGPointMake(self.collectionView.contentOffset.x, MAX(minimum, MIN(maximum, y))) animated:NO];
173
- self.applyingProgrammaticPage = wasApplying;
174
- }
175
-
176
- - (void)layoutSubviews {
177
- NSDictionary *anchor = [self captureScrollAnchorForViewport:self.viewportSize];
178
- [super layoutSubviews];
179
- CGSize size = self.collectionView.bounds.size;
180
- if (CGSizeEqualToSize(size, self.viewportSize)) {
181
- if (self.pendingNavigation) [self scrollToCurrentPageAnimated:NO];
182
- return;
183
- }
184
- if (self.collectionView.dragging || self.collectionView.decelerating) {
185
- self.pendingViewportLayout = YES;
186
- return;
187
- }
188
- self.pendingViewportLayout = NO;
189
- BOOL wasApplying = self.applyingProgrammaticPage;
190
- self.applyingProgrammaticPage = YES;
191
- self.viewportSize = size;
192
- self.flowLayout.itemSize = size;
193
- [self.flowLayout invalidateLayout];
194
- [self.collectionView layoutIfNeeded];
195
- for (PapyrusComicPageCell *cell in self.collectionView.visibleCells) {
196
- [self configureCell:cell withImage:cell.imageView.image];
197
- cell.imageView.transform = [self imageTransform];
198
- }
199
- if (self.pendingNavigation || ![self.layoutMode isEqualToString:@"continuous"]) {
200
- [self scrollToCurrentPageAnimated:NO];
201
- } else {
202
- [self restoreScrollAnchor:anchor];
203
- }
204
- self.applyingProgrammaticPage = wasApplying;
205
- }
206
-
207
- - (void)setEngineId:(NSString *)engineId {
208
- if ([_engineId isEqualToString:engineId]) return;
209
- _engineId = [engineId copy];
210
- [self.pageSizes removeAllObjects];
211
- [self.pendingPageSizes removeAllObjects];
212
- @synchronized (self.reportedErrors) { [self.reportedErrors removeAllObjects]; }
213
- self.pendingNavigation = YES;
214
- [self.collectionView reloadData];
215
- [self scrollToCurrentPageAnimated:NO];
216
- }
217
- - (void)setDocumentGeneration:(NSInteger)value {
218
- if (_documentGeneration == value) return;
219
- _documentGeneration = value;
220
- [self.pageSizes removeAllObjects];
221
- [self.pendingPageSizes removeAllObjects];
222
- @synchronized (self.reportedErrors) { [self.reportedErrors removeAllObjects]; }
223
- self.pendingNavigation = YES;
224
- [self.collectionView reloadData];
225
- [self scrollToCurrentPageAnimated:NO];
226
- }
227
- - (void)setPageCount:(NSInteger)value {
228
- NSInteger count = MAX(0, value);
229
- if (_pageCount == count) return;
230
- _pageCount = count;
231
- _currentPage = count > 0 ? MIN(self.requestedPage, count) : self.requestedPage;
232
- self.pendingNavigation = YES;
233
- [self.collectionView reloadData];
234
- [self scrollToCurrentPageAnimated:NO];
235
- }
236
- - (void)setCurrentPage:(NSInteger)value {
237
- NSInteger requested = MAX(value, 1);
238
- NSInteger safe = self.pageCount > 0 ? MIN(requested, self.pageCount) : requested;
239
- if (_currentPage == safe && self.requestedPage == requested) return;
240
- self.requestedPage = requested;
241
- _currentPage = safe;
242
- self.pendingNavigation = YES;
243
- [self scrollToCurrentPageAnimated:NO];
244
- }
245
- - (void)setLayoutMode:(NSString *)value {
246
- NSString *mode = [value isEqualToString:@"continuous"] ? @"continuous" : @"single";
247
- if ([_layoutMode isEqualToString:mode]) return;
248
- _layoutMode = mode;
249
- [self applyLayoutMode];
250
- self.pendingNavigation = YES;
251
- [self.collectionView reloadData];
252
- [self scrollToCurrentPageAnimated:NO];
253
- }
254
- - (void)setFitMode:(NSString *)value {
255
- NSString *mode = [value isEqualToString:@"page"] ? @"page" : @"width";
256
- if ([_fitMode isEqualToString:mode]) return;
257
- BOOL wasApplying = self.applyingProgrammaticPage;
258
- self.applyingProgrammaticPage = YES;
259
- NSDictionary *anchor = [self captureScrollAnchorForViewport:self.collectionView.bounds.size];
260
- _fitMode = mode;
261
- [self.flowLayout invalidateLayout];
262
- [self.collectionView reloadData];
263
- [self.collectionView layoutIfNeeded];
264
- if ([self.layoutMode isEqualToString:@"continuous"]) [self restoreScrollAnchor:anchor];
265
- else [self scrollToCurrentPageAnimated:NO];
266
- self.applyingProgrammaticPage = wasApplying;
267
- }
268
- - (void)setReadingDirection:(NSString *)value {
269
- NSString *direction = [value isEqualToString:@"rtl"] ? @"rtl" : @"ltr";
270
- if ([_readingDirection isEqualToString:direction]) return;
271
- BOOL wasApplying = self.applyingProgrammaticPage;
272
- self.applyingProgrammaticPage = YES;
273
- NSDictionary *anchor = [self captureScrollAnchorForViewport:self.collectionView.bounds.size];
274
- _readingDirection = direction;
275
- [self applyLayoutMode];
276
- [self.collectionView reloadData];
277
- [self.collectionView layoutIfNeeded];
278
- if ([self.layoutMode isEqualToString:@"continuous"]) [self restoreScrollAnchor:anchor];
279
- else [self scrollToCurrentPageAnimated:NO];
280
- self.applyingProgrammaticPage = wasApplying;
281
- }
282
- - (void)setZoom:(CGFloat)value {
283
- _zoom = MAX(1, MIN(5, value));
284
- self.collectionView.panGestureRecognizer.enabled = _zoom <= 1.0;
285
- self.pagePanRecognizer.enabled = _zoom > 1.0;
286
- if (_zoom <= 1.0) self.panOffset = CGPointZero;
287
- for (PapyrusComicPageCell *cell in self.collectionView.visibleCells) {
288
- cell.imageView.transform = [self imageTransform];
289
- }
290
- }
291
-
292
- - (CGAffineTransform)imageTransform {
293
- CGAffineTransform transform = CGAffineTransformMakeTranslation(self.panOffset.x, self.panOffset.y);
294
- return CGAffineTransformScale(transform, self.zoom, self.zoom);
295
- }
296
- - (void)setPageTheme:(NSString *)value {
297
- _pageTheme = [value copy] ?: @"normal";
298
- [self applyTheme];
299
- }
300
-
301
- - (void)applyLayoutMode {
302
- BOOL continuous = [self.layoutMode isEqualToString:@"continuous"];
303
- self.flowLayout.scrollDirection = continuous ? UICollectionViewScrollDirectionVertical : UICollectionViewScrollDirectionHorizontal;
304
- self.collectionView.pagingEnabled = !continuous;
305
- self.collectionView.semanticContentAttribute = [self.readingDirection isEqualToString:@"rtl"] ? UISemanticContentAttributeForceRightToLeft : UISemanticContentAttributeForceLeftToRight;
306
- [self.flowLayout invalidateLayout];
307
- }
308
-
309
- - (void)applyTheme {
310
- UIColor *background = [self.pageTheme isEqualToString:@"sepia"] ? [UIColor colorWithRed:0.90 green:0.86 blue:0.77 alpha:1] :
311
- [self.pageTheme isEqualToString:@"dark"] ? [UIColor colorWithRed:0.08 green:0.08 blue:0.09 alpha:1] : UIColor.blackColor;
312
- self.backgroundColor = background;
313
- self.collectionView.backgroundColor = background;
314
- }
315
-
316
- - (void)configureCell:(PapyrusComicPageCell *)cell withImage:(UIImage *)image {
317
- cell.fitWidthInSingleMode = [self.layoutMode isEqualToString:@"single"] &&
318
- [self.fitMode isEqualToString:@"width"] && image.size.width > 0 && image.size.height > 0;
319
- [cell setNeedsLayout];
320
- [cell layoutIfNeeded];
321
- }
322
-
323
- - (void)emitErrorForKey:(NSString *)key message:(NSString *)message {
324
- @synchronized (self.reportedErrors) {
325
- if ([self.reportedErrors containsObject:key]) return;
326
- [self.reportedErrors addObject:key];
327
- }
328
- dispatch_async(dispatch_get_main_queue(), ^{
329
- if (self.onError) self.onError(@{@"message": message.length ? message : @"Unsupported or corrupt comic image"});
330
- });
331
- }
332
-
333
- - (NSInteger)logicalPageForItem:(NSInteger)item {
334
- return item;
335
- }
336
- - (NSInteger)itemForLogicalPage:(NSInteger)page {
337
- return MIN(MAX(0, page - 1), MAX(0, self.pageCount - 1));
338
- }
339
- - (void)scrollToCurrentPageAnimated:(BOOL)animated {
340
- if (self.pageCount <= 0 || self.collectionView.bounds.size.width <= 0) return;
341
- [self.collectionView layoutIfNeeded];
342
- NSInteger item = [self itemForLogicalPage:self.currentPage];
343
- if (item >= [self.collectionView numberOfItemsInSection:0]) return;
344
- self.pendingNavigation = NO;
345
- self.applyingProgrammaticPage = YES;
346
- [self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:item inSection:0]
347
- atScrollPosition:[self.layoutMode isEqualToString:@"continuous"] ? UICollectionViewScrollPositionTop : UICollectionViewScrollPositionCenteredHorizontally
348
- animated:animated];
349
- dispatch_async(dispatch_get_main_queue(), ^{ self.applyingProgrammaticPage = NO; });
350
- }
351
-
352
- - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
353
- #pragma unused(collectionView)
354
- return 1;
355
- }
356
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
357
- #pragma unused(collectionView, section)
358
- return self.pageCount;
359
- }
360
-
361
- - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
362
- PapyrusComicPageCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:PapyrusComicCellId forIndexPath:indexPath];
363
- NSInteger pageIndex = [self logicalPageForItem:indexPath.item];
364
- NSString *engineId = self.engineId;
365
- NSInteger generation = self.documentGeneration;
366
- NSString *key = [NSString stringWithFormat:@"%@:%ld:%ld", engineId ?: @"", (long)generation, (long)pageIndex];
367
- cell.representedKey = key;
368
- cell.imageView.image = [PapyrusComicImageCache() objectForKey:key];
369
- [self configureCell:cell withImage:cell.imageView.image];
370
- cell.imageView.transform = [self imageTransform];
371
- if (!cell.imageView.image && engineId.length > 0 && generation > 0) {
372
- NSInteger maximumEdge = MAX(1024, (NSInteger)MAX(self.bounds.size.width, self.bounds.size.height) * 2);
373
- dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{
374
- char path[4096] = {};
375
- char error[512] = {};
376
- if (!papyrus_comic_extract_page(engineId.UTF8String, (int)generation, (int)pageIndex, path, sizeof(path), error, sizeof(error))) {
377
- [self emitErrorForKey:key message:error[0] ? [NSString stringWithUTF8String:error] : nil];
378
- return;
379
- }
380
- NSURL *url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:path]];
381
- CGImageSourceRef source = CGImageSourceCreateWithURL((__bridge CFURLRef)url, NULL);
382
- if (!source) { [self emitErrorForKey:key message:@"Unsupported or corrupt comic image"]; return; }
383
- CFDictionaryRef properties = CGImageSourceCopyPropertiesAtIndex(source, 0, NULL);
384
- NSDictionary *metadata = properties ? CFBridgingRelease(properties) : @{};
385
- NSUInteger width = [metadata[(id)kCGImagePropertyPixelWidth] unsignedIntegerValue];
386
- NSUInteger height = [metadata[(id)kCGImagePropertyPixelHeight] unsignedIntegerValue];
387
- if (width == 0 || height == 0 || width > 20000 || height > 20000 || width * height > 80000000ULL) {
388
- CFRelease(source);
389
- [self emitErrorForKey:key message:@"Comic image exceeds supported dimensions"];
390
- return;
391
- }
392
- CGFloat scale = MIN(1.0, MIN((CGFloat)maximumEdge / (CGFloat)MAX(width, height), sqrt(8000000.0 / ((double)width * (double)height))));
393
- NSInteger boundedMaximumEdge = MAX(1, (NSInteger)ceil((double)MAX(width, height) * scale));
394
- NSDictionary *options = @{
395
- (__bridge NSString *)kCGImageSourceCreateThumbnailFromImageAlways: @YES,
396
- (__bridge NSString *)kCGImageSourceThumbnailMaxPixelSize: @(boundedMaximumEdge),
397
- (__bridge NSString *)kCGImageSourceCreateThumbnailWithTransform: @YES,
398
- };
399
- CGImageRef image = CGImageSourceCreateThumbnailAtIndex(source, 0, (__bridge CFDictionaryRef)options);
400
- CFRelease(source);
401
- if (!image) { [self emitErrorForKey:key message:@"Unsupported or corrupt comic image"]; return; }
402
- UIImage *page = [UIImage imageWithCGImage:image scale:UIScreen.mainScreen.scale orientation:UIImageOrientationUp];
403
- NSUInteger cost = CGImageGetBytesPerRow(image) * CGImageGetHeight(image);
404
- CGImageRelease(image);
405
- [PapyrusComicImageCache() setObject:page forKey:key cost:cost];
406
- dispatch_async(dispatch_get_main_queue(), ^{
407
- if (![self.engineId isEqualToString:engineId] || self.documentGeneration != generation) return;
408
- self.pendingPageSizes[@(pageIndex)] = [NSValue valueWithCGSize:page.size];
409
- [self applyPendingPageSizes];
410
- if ([cell.representedKey isEqualToString:key]) {
411
- cell.imageView.image = page;
412
- [self configureCell:cell withImage:page];
413
- cell.imageView.transform = [self imageTransform];
414
- }
415
- });
416
- });
417
- }
418
- return cell;
419
- }
420
-
421
- // Keep geometry fixed during the native gesture; one compensation happens at idle.
422
- - (void)applyPendingPageSizes {
423
- if (self.collectionView.dragging || self.collectionView.decelerating) return;
424
- if (self.pendingViewportLayout) { [self setNeedsLayout]; [self layoutIfNeeded]; }
425
- if (self.pendingPageSizes.count == 0) return;
426
- NSDictionary *anchor = [self captureScrollAnchorForViewport:self.collectionView.bounds.size];
427
- BOOL wasApplying = self.applyingProgrammaticPage;
428
- self.applyingProgrammaticPage = YES;
429
- [self.pageSizes addEntriesFromDictionary:self.pendingPageSizes];
430
- [self.pendingPageSizes removeAllObjects];
431
- [self.flowLayout invalidateLayout];
432
- [self.collectionView layoutIfNeeded];
433
- [self restoreScrollAnchor:anchor];
434
- self.applyingProgrammaticPage = wasApplying;
435
- }
436
-
437
- - (CGSize)pageSizeAtIndex:(NSInteger)page {
438
- NSValue *known = self.pageSizes[@(page)];
439
- if (known) return known.CGSizeValue;
440
- NSString *key = [NSString stringWithFormat:@"%@:%ld:%ld", self.engineId ?: @"", (long)self.documentGeneration, (long)page];
441
- if (self.pendingPageSizes[@(page)]) return CGSizeZero;
442
- UIImage *cached = [PapyrusComicImageCache() objectForKey:key];
443
- if (cached) self.pageSizes[@(page)] = [NSValue valueWithCGSize:cached.size];
444
- return cached ? cached.size : CGSizeZero;
445
- }
446
-
447
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)layout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
448
- #pragma unused(layout)
449
- if (![self.layoutMode isEqualToString:@"continuous"]) return collectionView.bounds.size;
450
- NSInteger page = [self logicalPageForItem:indexPath.item];
451
- CGSize imageSize = [self pageSizeAtIndex:page];
452
- CGSize viewport = self.pendingViewportLayout && self.viewportSize.width > 0 ? self.viewportSize : collectionView.bounds.size;
453
- if (imageSize.width <= 0 || imageSize.height <= 0) return viewport;
454
- CGFloat width = viewport.width;
455
- CGFloat height = width * imageSize.height / imageSize.width;
456
- if ([self.fitMode isEqualToString:@"page"]) height = MIN(height, viewport.height);
457
- return CGSizeMake(width, MAX(1, height));
458
- }
459
-
460
- - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
461
- #pragma unused(scrollView)
462
- if (!decelerate) [self applyPendingPageSizes];
463
- [self emitVisiblePage];
464
- }
465
-
466
- - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
467
- #pragma unused(scrollView)
468
- [self applyPendingPageSizes];
469
- [self emitVisiblePage];
470
- }
471
- - (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
472
- #pragma unused(scrollView)
473
- [self applyPendingPageSizes];
474
- [self emitVisiblePage];
475
- }
476
- - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
477
- #pragma unused(scrollView)
478
- if (!self.applyingProgrammaticPage) [self emitVisiblePage];
479
- }
480
-
481
- - (void)emitVisiblePage {
482
- if (self.applyingProgrammaticPage || self.pendingNavigation || self.pageCount <= 0) return;
483
- CGPoint center = CGPointMake(self.collectionView.contentOffset.x + self.collectionView.bounds.size.width / 2,
484
- self.collectionView.contentOffset.y + self.collectionView.bounds.size.height / 2);
485
- NSIndexPath *indexPath = [self.collectionView indexPathForItemAtPoint:center];
486
- if (!indexPath) return;
487
- NSInteger page = [self logicalPageForItem:indexPath.item] + 1;
488
- if (page == self.currentPage) return;
489
- _currentPage = page;
490
- self.requestedPage = page;
491
- if (self.onPageChanged) self.onPageChanged(@{ @"page": @(page) });
492
- }
493
-
494
- - (void)handleDoubleTap:(UITapGestureRecognizer *)recognizer {
495
- if (recognizer.state != UIGestureRecognizerStateRecognized ||
496
- self.pinchRecognizer.state == UIGestureRecognizerStateChanged) return;
497
- CGFloat previous = MAX(1, self.zoom);
498
- CGFloat target = previous > 1.05 ? 1.0 : 2.0;
499
- CGPoint focus = [recognizer locationInView:self.collectionView];
500
- CGPoint center = CGPointMake(CGRectGetMidX(self.collectionView.bounds),
501
- CGRectGetMidY(self.collectionView.bounds));
502
- if (target <= 1.0) {
503
- self.panOffset = CGPointZero;
504
- } else {
505
- CGFloat ratio = target / previous;
506
- CGFloat maxX = self.collectionView.bounds.size.width * (target - 1.0) / 2.0;
507
- CGFloat maxY = self.collectionView.bounds.size.height * (target - 1.0) / 2.0;
508
- CGFloat x = ratio * self.panOffset.x + (1 - ratio) * (focus.x - center.x);
509
- CGFloat y = ratio * self.panOffset.y + (1 - ratio) * (focus.y - center.y);
510
- self.panOffset = CGPointMake(MAX(-maxX, MIN(maxX, x)), MAX(-maxY, MIN(maxY, y)));
511
- }
512
- self.zoom = target;
513
- if (self.onZoomChanged) self.onZoomChanged(@{ @"zoom": @(self.zoom) });
514
- }
515
-
516
- - (void)handlePinch:(UIPinchGestureRecognizer *)recognizer {
517
- if (recognizer.state == UIGestureRecognizerStateChanged) {
518
- self.zoom = MAX(1, MIN(5, self.zoom * recognizer.scale));
519
- recognizer.scale = 1;
520
- } else if (recognizer.state == UIGestureRecognizerStateEnded || recognizer.state == UIGestureRecognizerStateCancelled || recognizer.state == UIGestureRecognizerStateFailed) {
521
- [self applyPendingPageSizes];
522
- if (self.onZoomChanged) self.onZoomChanged(@{ @"zoom": @(self.zoom) });
523
- }
524
- }
525
-
526
- - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
527
- return gestureRecognizer == self.pinchRecognizer || otherGestureRecognizer == self.pinchRecognizer;
528
- }
529
-
530
- - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
531
- #pragma unused(touch)
532
- if (gestureRecognizer == self.pagePanRecognizer) return self.zoom > 1.0;
533
- return YES;
534
- }
535
-
536
- - (void)handlePagePan:(UIPanGestureRecognizer *)recognizer {
537
- if (self.zoom <= 1.0) return;
538
- if (recognizer.state == UIGestureRecognizerStateBegan) {
539
- self.panGestureStartOffset = self.panOffset;
540
- } else if (recognizer.state == UIGestureRecognizerStateChanged) {
541
- CGPoint translation = [recognizer translationInView:self.collectionView];
542
- CGFloat maxX = self.collectionView.bounds.size.width * (self.zoom - 1.0) / 2.0;
543
- CGFloat maxY = self.collectionView.bounds.size.height * (self.zoom - 1.0) / 2.0;
544
- self.panOffset = CGPointMake(
545
- MAX(-maxX, MIN(maxX, translation.x + self.panGestureStartOffset.x)),
546
- MAX(-maxY, MIN(maxY, translation.y + self.panGestureStartOffset.y))
547
- );
548
- for (PapyrusComicPageCell *cell in self.collectionView.visibleCells) cell.imageView.transform = [self imageTransform];
549
- } else if (recognizer.state == UIGestureRecognizerStateEnded || recognizer.state == UIGestureRecognizerStateCancelled || recognizer.state == UIGestureRecognizerStateFailed) {
550
- [self applyPendingPageSizes];
551
- }
552
- }
553
-
554
- @end