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