@docmentis/udoc-viewer 0.7.19 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (386) hide show
  1. package/API-COMPARISON.md +441 -0
  2. package/LICENSE-APACHE +202 -0
  3. package/LICENSE-MIT +21 -0
  4. package/README.md +23 -1220
  5. package/dist/index.d.ts +40 -0
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js +52 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/version.d.ts +2 -0
  10. package/dist/version.d.ts.map +1 -0
  11. package/dist/version.js +7 -0
  12. package/dist/version.js.map +1 -0
  13. package/dist/worker/worker-source.d.ts +3 -0
  14. package/dist/worker/worker-source.d.ts.map +1 -0
  15. package/dist/worker/worker-source.js +11 -0
  16. package/dist/worker/worker.d.ts +2 -0
  17. package/dist/worker/worker.d.ts.map +1 -0
  18. package/dist/worker/worker.js +5 -0
  19. package/dist/worker/worker.js.map +1 -0
  20. package/package.json +48 -59
  21. package/dist/package.json +0 -79
  22. package/dist/src/UDocClient.d.ts +0 -730
  23. package/dist/src/UDocClient.d.ts.map +0 -1
  24. package/dist/src/UDocClient.js +0 -649
  25. package/dist/src/UDocClient.js.map +0 -1
  26. package/dist/src/UDocViewer.d.ts +0 -883
  27. package/dist/src/UDocViewer.d.ts.map +0 -1
  28. package/dist/src/UDocViewer.js +0 -2180
  29. package/dist/src/UDocViewer.js.map +0 -1
  30. package/dist/src/fonts.d.ts +0 -47
  31. package/dist/src/fonts.d.ts.map +0 -1
  32. package/dist/src/fonts.js +0 -49
  33. package/dist/src/fonts.js.map +0 -1
  34. package/dist/src/index.d.ts +0 -13
  35. package/dist/src/index.d.ts.map +0 -1
  36. package/dist/src/index.js +0 -5
  37. package/dist/src/index.js.map +0 -1
  38. package/dist/src/meta-url.d.ts +0 -2
  39. package/dist/src/meta-url.d.ts.map +0 -1
  40. package/dist/src/meta-url.js +0 -10
  41. package/dist/src/meta-url.js.map +0 -1
  42. package/dist/src/performance/PerformanceCounter.d.ts +0 -132
  43. package/dist/src/performance/PerformanceCounter.d.ts.map +0 -1
  44. package/dist/src/performance/PerformanceCounter.js +0 -129
  45. package/dist/src/performance/PerformanceCounter.js.map +0 -1
  46. package/dist/src/performance/index.d.ts +0 -2
  47. package/dist/src/performance/index.d.ts.map +0 -1
  48. package/dist/src/performance/index.js +0 -2
  49. package/dist/src/performance/index.js.map +0 -1
  50. package/dist/src/ui/framework/component.d.ts +0 -68
  51. package/dist/src/ui/framework/component.d.ts.map +0 -1
  52. package/dist/src/ui/framework/component.js +0 -97
  53. package/dist/src/ui/framework/component.js.map +0 -1
  54. package/dist/src/ui/framework/dom.d.ts +0 -19
  55. package/dist/src/ui/framework/dom.d.ts.map +0 -1
  56. package/dist/src/ui/framework/dom.js +0 -29
  57. package/dist/src/ui/framework/dom.js.map +0 -1
  58. package/dist/src/ui/framework/events.d.ts +0 -18
  59. package/dist/src/ui/framework/events.d.ts.map +0 -1
  60. package/dist/src/ui/framework/events.js +0 -23
  61. package/dist/src/ui/framework/events.js.map +0 -1
  62. package/dist/src/ui/framework/index.d.ts +0 -15
  63. package/dist/src/ui/framework/index.d.ts.map +0 -1
  64. package/dist/src/ui/framework/index.js +0 -15
  65. package/dist/src/ui/framework/index.js.map +0 -1
  66. package/dist/src/ui/framework/selectors.d.ts +0 -51
  67. package/dist/src/ui/framework/selectors.d.ts.map +0 -1
  68. package/dist/src/ui/framework/selectors.js +0 -28
  69. package/dist/src/ui/framework/selectors.js.map +0 -1
  70. package/dist/src/ui/framework/store.d.ts +0 -44
  71. package/dist/src/ui/framework/store.d.ts.map +0 -1
  72. package/dist/src/ui/framework/store.js +0 -79
  73. package/dist/src/ui/framework/store.js.map +0 -1
  74. package/dist/src/ui/viewer/a11y.d.ts +0 -26
  75. package/dist/src/ui/viewer/a11y.d.ts.map +0 -1
  76. package/dist/src/ui/viewer/a11y.js +0 -116
  77. package/dist/src/ui/viewer/a11y.js.map +0 -1
  78. package/dist/src/ui/viewer/actions.d.ts +0 -308
  79. package/dist/src/ui/viewer/actions.d.ts.map +0 -1
  80. package/dist/src/ui/viewer/actions.js +0 -2
  81. package/dist/src/ui/viewer/actions.js.map +0 -1
  82. package/dist/src/ui/viewer/animation-presets.d.ts +0 -37
  83. package/dist/src/ui/viewer/animation-presets.d.ts.map +0 -1
  84. package/dist/src/ui/viewer/animation-presets.js +0 -123
  85. package/dist/src/ui/viewer/animation-presets.js.map +0 -1
  86. package/dist/src/ui/viewer/animation.d.ts +0 -162
  87. package/dist/src/ui/viewer/animation.d.ts.map +0 -1
  88. package/dist/src/ui/viewer/animation.js +0 -506
  89. package/dist/src/ui/viewer/animation.js.map +0 -1
  90. package/dist/src/ui/viewer/annotation/LinkRenderer.d.ts +0 -9
  91. package/dist/src/ui/viewer/annotation/LinkRenderer.d.ts.map +0 -1
  92. package/dist/src/ui/viewer/annotation/LinkRenderer.js +0 -17
  93. package/dist/src/ui/viewer/annotation/LinkRenderer.js.map +0 -1
  94. package/dist/src/ui/viewer/annotation/MarkupRenderer.d.ts +0 -21
  95. package/dist/src/ui/viewer/annotation/MarkupRenderer.d.ts.map +0 -1
  96. package/dist/src/ui/viewer/annotation/MarkupRenderer.js +0 -136
  97. package/dist/src/ui/viewer/annotation/MarkupRenderer.js.map +0 -1
  98. package/dist/src/ui/viewer/annotation/ShapeRenderer.d.ts +0 -33
  99. package/dist/src/ui/viewer/annotation/ShapeRenderer.d.ts.map +0 -1
  100. package/dist/src/ui/viewer/annotation/ShapeRenderer.js +0 -379
  101. package/dist/src/ui/viewer/annotation/ShapeRenderer.js.map +0 -1
  102. package/dist/src/ui/viewer/annotation/TextRenderer.d.ts +0 -23
  103. package/dist/src/ui/viewer/annotation/TextRenderer.d.ts.map +0 -1
  104. package/dist/src/ui/viewer/annotation/TextRenderer.js +0 -196
  105. package/dist/src/ui/viewer/annotation/TextRenderer.js.map +0 -1
  106. package/dist/src/ui/viewer/annotation/index.d.ts +0 -9
  107. package/dist/src/ui/viewer/annotation/index.d.ts.map +0 -1
  108. package/dist/src/ui/viewer/annotation/index.js +0 -10
  109. package/dist/src/ui/viewer/annotation/index.js.map +0 -1
  110. package/dist/src/ui/viewer/annotation/propertyUtils.d.ts +0 -29
  111. package/dist/src/ui/viewer/annotation/propertyUtils.d.ts.map +0 -1
  112. package/dist/src/ui/viewer/annotation/propertyUtils.js +0 -151
  113. package/dist/src/ui/viewer/annotation/propertyUtils.js.map +0 -1
  114. package/dist/src/ui/viewer/annotation/render.d.ts +0 -24
  115. package/dist/src/ui/viewer/annotation/render.d.ts.map +0 -1
  116. package/dist/src/ui/viewer/annotation/render.js +0 -191
  117. package/dist/src/ui/viewer/annotation/render.js.map +0 -1
  118. package/dist/src/ui/viewer/annotation/types.d.ts +0 -309
  119. package/dist/src/ui/viewer/annotation/types.d.ts.map +0 -1
  120. package/dist/src/ui/viewer/annotation/types.js +0 -7
  121. package/dist/src/ui/viewer/annotation/types.js.map +0 -1
  122. package/dist/src/ui/viewer/annotation/utils.d.ts +0 -75
  123. package/dist/src/ui/viewer/annotation/utils.d.ts.map +0 -1
  124. package/dist/src/ui/viewer/annotation/utils.js +0 -250
  125. package/dist/src/ui/viewer/annotation/utils.js.map +0 -1
  126. package/dist/src/ui/viewer/components/AnnotationPanel.d.ts +0 -20
  127. package/dist/src/ui/viewer/components/AnnotationPanel.d.ts.map +0 -1
  128. package/dist/src/ui/viewer/components/AnnotationPanel.js +0 -276
  129. package/dist/src/ui/viewer/components/AnnotationPanel.js.map +0 -1
  130. package/dist/src/ui/viewer/components/AttachmentsPanel.d.ts +0 -8
  131. package/dist/src/ui/viewer/components/AttachmentsPanel.d.ts.map +0 -1
  132. package/dist/src/ui/viewer/components/AttachmentsPanel.js +0 -16
  133. package/dist/src/ui/viewer/components/AttachmentsPanel.js.map +0 -1
  134. package/dist/src/ui/viewer/components/BookmarksPanel.d.ts +0 -8
  135. package/dist/src/ui/viewer/components/BookmarksPanel.d.ts.map +0 -1
  136. package/dist/src/ui/viewer/components/BookmarksPanel.js +0 -16
  137. package/dist/src/ui/viewer/components/BookmarksPanel.js.map +0 -1
  138. package/dist/src/ui/viewer/components/Branding.d.ts +0 -49
  139. package/dist/src/ui/viewer/components/Branding.d.ts.map +0 -1
  140. package/dist/src/ui/viewer/components/Branding.js +0 -334
  141. package/dist/src/ui/viewer/components/Branding.js.map +0 -1
  142. package/dist/src/ui/viewer/components/ColorSelect.d.ts +0 -26
  143. package/dist/src/ui/viewer/components/ColorSelect.d.ts.map +0 -1
  144. package/dist/src/ui/viewer/components/ColorSelect.js +0 -120
  145. package/dist/src/ui/viewer/components/ColorSelect.js.map +0 -1
  146. package/dist/src/ui/viewer/components/FloatingToolbar.d.ts +0 -10
  147. package/dist/src/ui/viewer/components/FloatingToolbar.d.ts.map +0 -1
  148. package/dist/src/ui/viewer/components/FloatingToolbar.js +0 -396
  149. package/dist/src/ui/viewer/components/FloatingToolbar.js.map +0 -1
  150. package/dist/src/ui/viewer/components/FontsPanel.d.ts +0 -12
  151. package/dist/src/ui/viewer/components/FontsPanel.d.ts.map +0 -1
  152. package/dist/src/ui/viewer/components/FontsPanel.js +0 -141
  153. package/dist/src/ui/viewer/components/FontsPanel.js.map +0 -1
  154. package/dist/src/ui/viewer/components/LayersPanel.d.ts +0 -12
  155. package/dist/src/ui/viewer/components/LayersPanel.d.ts.map +0 -1
  156. package/dist/src/ui/viewer/components/LayersPanel.js +0 -139
  157. package/dist/src/ui/viewer/components/LayersPanel.js.map +0 -1
  158. package/dist/src/ui/viewer/components/LeftPanel.d.ts +0 -11
  159. package/dist/src/ui/viewer/components/LeftPanel.d.ts.map +0 -1
  160. package/dist/src/ui/viewer/components/LeftPanel.js +0 -296
  161. package/dist/src/ui/viewer/components/LeftPanel.js.map +0 -1
  162. package/dist/src/ui/viewer/components/LoadingOverlay.d.ts +0 -13
  163. package/dist/src/ui/viewer/components/LoadingOverlay.d.ts.map +0 -1
  164. package/dist/src/ui/viewer/components/LoadingOverlay.js +0 -146
  165. package/dist/src/ui/viewer/components/LoadingOverlay.js.map +0 -1
  166. package/dist/src/ui/viewer/components/NumberInput.d.ts +0 -32
  167. package/dist/src/ui/viewer/components/NumberInput.d.ts.map +0 -1
  168. package/dist/src/ui/viewer/components/NumberInput.js +0 -101
  169. package/dist/src/ui/viewer/components/NumberInput.js.map +0 -1
  170. package/dist/src/ui/viewer/components/OutlinePanel.d.ts +0 -11
  171. package/dist/src/ui/viewer/components/OutlinePanel.d.ts.map +0 -1
  172. package/dist/src/ui/viewer/components/OutlinePanel.js +0 -307
  173. package/dist/src/ui/viewer/components/OutlinePanel.js.map +0 -1
  174. package/dist/src/ui/viewer/components/PasswordDialog.d.ts +0 -16
  175. package/dist/src/ui/viewer/components/PasswordDialog.d.ts.map +0 -1
  176. package/dist/src/ui/viewer/components/PasswordDialog.js +0 -179
  177. package/dist/src/ui/viewer/components/PasswordDialog.js.map +0 -1
  178. package/dist/src/ui/viewer/components/PermitNoticeOverlay.d.ts +0 -27
  179. package/dist/src/ui/viewer/components/PermitNoticeOverlay.d.ts.map +0 -1
  180. package/dist/src/ui/viewer/components/PermitNoticeOverlay.js +0 -79
  181. package/dist/src/ui/viewer/components/PermitNoticeOverlay.js.map +0 -1
  182. package/dist/src/ui/viewer/components/PrintDialog.d.ts +0 -34
  183. package/dist/src/ui/viewer/components/PrintDialog.d.ts.map +0 -1
  184. package/dist/src/ui/viewer/components/PrintDialog.js +0 -317
  185. package/dist/src/ui/viewer/components/PrintDialog.js.map +0 -1
  186. package/dist/src/ui/viewer/components/RightPanel.d.ts +0 -10
  187. package/dist/src/ui/viewer/components/RightPanel.d.ts.map +0 -1
  188. package/dist/src/ui/viewer/components/RightPanel.js +0 -154
  189. package/dist/src/ui/viewer/components/RightPanel.js.map +0 -1
  190. package/dist/src/ui/viewer/components/SearchPanel.d.ts +0 -21
  191. package/dist/src/ui/viewer/components/SearchPanel.d.ts.map +0 -1
  192. package/dist/src/ui/viewer/components/SearchPanel.js +0 -323
  193. package/dist/src/ui/viewer/components/SearchPanel.js.map +0 -1
  194. package/dist/src/ui/viewer/components/SheetTabBar.d.ts +0 -9
  195. package/dist/src/ui/viewer/components/SheetTabBar.d.ts.map +0 -1
  196. package/dist/src/ui/viewer/components/SheetTabBar.js +0 -57
  197. package/dist/src/ui/viewer/components/SheetTabBar.js.map +0 -1
  198. package/dist/src/ui/viewer/components/Spread.d.ts +0 -85
  199. package/dist/src/ui/viewer/components/Spread.d.ts.map +0 -1
  200. package/dist/src/ui/viewer/components/Spread.js +0 -749
  201. package/dist/src/ui/viewer/components/Spread.js.map +0 -1
  202. package/dist/src/ui/viewer/components/SubToolbar.d.ts +0 -11
  203. package/dist/src/ui/viewer/components/SubToolbar.d.ts.map +0 -1
  204. package/dist/src/ui/viewer/components/SubToolbar.js +0 -722
  205. package/dist/src/ui/viewer/components/SubToolbar.js.map +0 -1
  206. package/dist/src/ui/viewer/components/ThumbnailPanel.d.ts +0 -12
  207. package/dist/src/ui/viewer/components/ThumbnailPanel.d.ts.map +0 -1
  208. package/dist/src/ui/viewer/components/ThumbnailPanel.js +0 -290
  209. package/dist/src/ui/viewer/components/ThumbnailPanel.js.map +0 -1
  210. package/dist/src/ui/viewer/components/Toolbar.d.ts +0 -12
  211. package/dist/src/ui/viewer/components/Toolbar.d.ts.map +0 -1
  212. package/dist/src/ui/viewer/components/Toolbar.js +0 -761
  213. package/dist/src/ui/viewer/components/Toolbar.js.map +0 -1
  214. package/dist/src/ui/viewer/components/ViewModeMenu.d.ts +0 -10
  215. package/dist/src/ui/viewer/components/ViewModeMenu.d.ts.map +0 -1
  216. package/dist/src/ui/viewer/components/ViewModeMenu.js +0 -206
  217. package/dist/src/ui/viewer/components/ViewModeMenu.js.map +0 -1
  218. package/dist/src/ui/viewer/components/Viewport.d.ts +0 -28
  219. package/dist/src/ui/viewer/components/Viewport.d.ts.map +0 -1
  220. package/dist/src/ui/viewer/components/Viewport.js +0 -1721
  221. package/dist/src/ui/viewer/components/Viewport.js.map +0 -1
  222. package/dist/src/ui/viewer/effects.d.ts +0 -8
  223. package/dist/src/ui/viewer/effects.d.ts.map +0 -1
  224. package/dist/src/ui/viewer/effects.js +0 -452
  225. package/dist/src/ui/viewer/effects.js.map +0 -1
  226. package/dist/src/ui/viewer/i18n/ar.d.ts +0 -3
  227. package/dist/src/ui/viewer/i18n/ar.d.ts.map +0 -1
  228. package/dist/src/ui/viewer/i18n/ar.js +0 -198
  229. package/dist/src/ui/viewer/i18n/ar.js.map +0 -1
  230. package/dist/src/ui/viewer/i18n/de.d.ts +0 -3
  231. package/dist/src/ui/viewer/i18n/de.d.ts.map +0 -1
  232. package/dist/src/ui/viewer/i18n/de.js +0 -198
  233. package/dist/src/ui/viewer/i18n/de.js.map +0 -1
  234. package/dist/src/ui/viewer/i18n/en.d.ts +0 -3
  235. package/dist/src/ui/viewer/i18n/en.d.ts.map +0 -1
  236. package/dist/src/ui/viewer/i18n/en.js +0 -200
  237. package/dist/src/ui/viewer/i18n/en.js.map +0 -1
  238. package/dist/src/ui/viewer/i18n/es.d.ts +0 -3
  239. package/dist/src/ui/viewer/i18n/es.d.ts.map +0 -1
  240. package/dist/src/ui/viewer/i18n/es.js +0 -198
  241. package/dist/src/ui/viewer/i18n/es.js.map +0 -1
  242. package/dist/src/ui/viewer/i18n/fr.d.ts +0 -3
  243. package/dist/src/ui/viewer/i18n/fr.d.ts.map +0 -1
  244. package/dist/src/ui/viewer/i18n/fr.js +0 -198
  245. package/dist/src/ui/viewer/i18n/fr.js.map +0 -1
  246. package/dist/src/ui/viewer/i18n/index.d.ts +0 -27
  247. package/dist/src/ui/viewer/i18n/index.d.ts.map +0 -1
  248. package/dist/src/ui/viewer/i18n/index.js +0 -88
  249. package/dist/src/ui/viewer/i18n/index.js.map +0 -1
  250. package/dist/src/ui/viewer/i18n/ja.d.ts +0 -3
  251. package/dist/src/ui/viewer/i18n/ja.d.ts.map +0 -1
  252. package/dist/src/ui/viewer/i18n/ja.js +0 -198
  253. package/dist/src/ui/viewer/i18n/ja.js.map +0 -1
  254. package/dist/src/ui/viewer/i18n/ko.d.ts +0 -3
  255. package/dist/src/ui/viewer/i18n/ko.d.ts.map +0 -1
  256. package/dist/src/ui/viewer/i18n/ko.js +0 -198
  257. package/dist/src/ui/viewer/i18n/ko.js.map +0 -1
  258. package/dist/src/ui/viewer/i18n/pt-BR.d.ts +0 -3
  259. package/dist/src/ui/viewer/i18n/pt-BR.d.ts.map +0 -1
  260. package/dist/src/ui/viewer/i18n/pt-BR.js +0 -198
  261. package/dist/src/ui/viewer/i18n/pt-BR.js.map +0 -1
  262. package/dist/src/ui/viewer/i18n/ru.d.ts +0 -3
  263. package/dist/src/ui/viewer/i18n/ru.d.ts.map +0 -1
  264. package/dist/src/ui/viewer/i18n/ru.js +0 -198
  265. package/dist/src/ui/viewer/i18n/ru.js.map +0 -1
  266. package/dist/src/ui/viewer/i18n/types.d.ts +0 -176
  267. package/dist/src/ui/viewer/i18n/types.d.ts.map +0 -1
  268. package/dist/src/ui/viewer/i18n/types.js +0 -2
  269. package/dist/src/ui/viewer/i18n/types.js.map +0 -1
  270. package/dist/src/ui/viewer/i18n/zh-CN.d.ts +0 -3
  271. package/dist/src/ui/viewer/i18n/zh-CN.d.ts.map +0 -1
  272. package/dist/src/ui/viewer/i18n/zh-CN.js +0 -198
  273. package/dist/src/ui/viewer/i18n/zh-CN.js.map +0 -1
  274. package/dist/src/ui/viewer/i18n/zh-TW.d.ts +0 -3
  275. package/dist/src/ui/viewer/i18n/zh-TW.d.ts.map +0 -1
  276. package/dist/src/ui/viewer/i18n/zh-TW.js +0 -198
  277. package/dist/src/ui/viewer/i18n/zh-TW.js.map +0 -1
  278. package/dist/src/ui/viewer/icons.d.ts +0 -77
  279. package/dist/src/ui/viewer/icons.d.ts.map +0 -1
  280. package/dist/src/ui/viewer/icons.js +0 -109
  281. package/dist/src/ui/viewer/icons.js.map +0 -1
  282. package/dist/src/ui/viewer/index.d.ts +0 -6
  283. package/dist/src/ui/viewer/index.d.ts.map +0 -1
  284. package/dist/src/ui/viewer/index.js +0 -6
  285. package/dist/src/ui/viewer/index.js.map +0 -1
  286. package/dist/src/ui/viewer/layout/index.d.ts +0 -3
  287. package/dist/src/ui/viewer/layout/index.d.ts.map +0 -1
  288. package/dist/src/ui/viewer/layout/index.js +0 -3
  289. package/dist/src/ui/viewer/layout/index.js.map +0 -1
  290. package/dist/src/ui/viewer/layout/pixelAlign.d.ts +0 -8
  291. package/dist/src/ui/viewer/layout/pixelAlign.d.ts.map +0 -1
  292. package/dist/src/ui/viewer/layout/pixelAlign.js +0 -42
  293. package/dist/src/ui/viewer/layout/pixelAlign.js.map +0 -1
  294. package/dist/src/ui/viewer/layout/spreadLayout.d.ts +0 -155
  295. package/dist/src/ui/viewer/layout/spreadLayout.d.ts.map +0 -1
  296. package/dist/src/ui/viewer/layout/spreadLayout.js +0 -574
  297. package/dist/src/ui/viewer/layout/spreadLayout.js.map +0 -1
  298. package/dist/src/ui/viewer/navigation.d.ts +0 -91
  299. package/dist/src/ui/viewer/navigation.d.ts.map +0 -1
  300. package/dist/src/ui/viewer/navigation.js +0 -59
  301. package/dist/src/ui/viewer/navigation.js.map +0 -1
  302. package/dist/src/ui/viewer/reducer.d.ts +0 -4
  303. package/dist/src/ui/viewer/reducer.d.ts.map +0 -1
  304. package/dist/src/ui/viewer/reducer.js +0 -841
  305. package/dist/src/ui/viewer/reducer.js.map +0 -1
  306. package/dist/src/ui/viewer/search/index.d.ts +0 -2
  307. package/dist/src/ui/viewer/search/index.d.ts.map +0 -1
  308. package/dist/src/ui/viewer/search/index.js +0 -2
  309. package/dist/src/ui/viewer/search/index.js.map +0 -1
  310. package/dist/src/ui/viewer/search/search.d.ts +0 -31
  311. package/dist/src/ui/viewer/search/search.d.ts.map +0 -1
  312. package/dist/src/ui/viewer/search/search.js +0 -446
  313. package/dist/src/ui/viewer/search/search.js.map +0 -1
  314. package/dist/src/ui/viewer/shell.d.ts +0 -65
  315. package/dist/src/ui/viewer/shell.d.ts.map +0 -1
  316. package/dist/src/ui/viewer/shell.js +0 -366
  317. package/dist/src/ui/viewer/shell.js.map +0 -1
  318. package/dist/src/ui/viewer/state.d.ts +0 -313
  319. package/dist/src/ui/viewer/state.d.ts.map +0 -1
  320. package/dist/src/ui/viewer/state.js +0 -157
  321. package/dist/src/ui/viewer/state.js.map +0 -1
  322. package/dist/src/ui/viewer/styles-inline.d.ts +0 -2
  323. package/dist/src/ui/viewer/styles-inline.d.ts.map +0 -1
  324. package/dist/src/ui/viewer/styles-inline.js +0 -3526
  325. package/dist/src/ui/viewer/styles-inline.js.map +0 -1
  326. package/dist/src/ui/viewer/text/index.d.ts +0 -6
  327. package/dist/src/ui/viewer/text/index.d.ts.map +0 -1
  328. package/dist/src/ui/viewer/text/index.js +0 -6
  329. package/dist/src/ui/viewer/text/index.js.map +0 -1
  330. package/dist/src/ui/viewer/text/render.d.ts +0 -18
  331. package/dist/src/ui/viewer/text/render.d.ts.map +0 -1
  332. package/dist/src/ui/viewer/text/render.js +0 -480
  333. package/dist/src/ui/viewer/text/render.js.map +0 -1
  334. package/dist/src/ui/viewer/text/selection.d.ts +0 -12
  335. package/dist/src/ui/viewer/text/selection.d.ts.map +0 -1
  336. package/dist/src/ui/viewer/text/selection.js +0 -69
  337. package/dist/src/ui/viewer/text/selection.js.map +0 -1
  338. package/dist/src/ui/viewer/tools/AnnotationDrawController.d.ts +0 -21
  339. package/dist/src/ui/viewer/tools/AnnotationDrawController.d.ts.map +0 -1
  340. package/dist/src/ui/viewer/tools/AnnotationDrawController.js +0 -410
  341. package/dist/src/ui/viewer/tools/AnnotationDrawController.js.map +0 -1
  342. package/dist/src/ui/viewer/tools/AnnotationSelectController.d.ts +0 -22
  343. package/dist/src/ui/viewer/tools/AnnotationSelectController.d.ts.map +0 -1
  344. package/dist/src/ui/viewer/tools/AnnotationSelectController.js +0 -378
  345. package/dist/src/ui/viewer/tools/AnnotationSelectController.js.map +0 -1
  346. package/dist/src/ui/viewer/tools/AnnotationUndoManager.d.ts +0 -29
  347. package/dist/src/ui/viewer/tools/AnnotationUndoManager.d.ts.map +0 -1
  348. package/dist/src/ui/viewer/tools/AnnotationUndoManager.js +0 -144
  349. package/dist/src/ui/viewer/tools/AnnotationUndoManager.js.map +0 -1
  350. package/dist/src/ui/viewer/tools/ViewToolController.d.ts +0 -20
  351. package/dist/src/ui/viewer/tools/ViewToolController.d.ts.map +0 -1
  352. package/dist/src/ui/viewer/tools/ViewToolController.js +0 -179
  353. package/dist/src/ui/viewer/tools/ViewToolController.js.map +0 -1
  354. package/dist/src/ui/viewer/transition-gl.d.ts +0 -25
  355. package/dist/src/ui/viewer/transition-gl.d.ts.map +0 -1
  356. package/dist/src/ui/viewer/transition-gl.js +0 -823
  357. package/dist/src/ui/viewer/transition-gl.js.map +0 -1
  358. package/dist/src/ui/viewer/transition.d.ts +0 -26
  359. package/dist/src/ui/viewer/transition.d.ts.map +0 -1
  360. package/dist/src/ui/viewer/transition.js +0 -1383
  361. package/dist/src/ui/viewer/transition.js.map +0 -1
  362. package/dist/src/wasm/LICENSE +0 -112
  363. package/dist/src/wasm/udoc.d.ts +0 -1338
  364. package/dist/src/wasm/udoc.js +0 -2645
  365. package/dist/src/wasm/udoc_bg.wasm +0 -0
  366. package/dist/src/wasm/udoc_bg.wasm.d.ts +0 -58
  367. package/dist/src/worker/WorkerClient.d.ts +0 -489
  368. package/dist/src/worker/WorkerClient.d.ts.map +0 -1
  369. package/dist/src/worker/WorkerClient.js +0 -1383
  370. package/dist/src/worker/WorkerClient.js.map +0 -1
  371. package/dist/src/worker/index.d.ts +0 -4
  372. package/dist/src/worker/index.d.ts.map +0 -1
  373. package/dist/src/worker/index.js +0 -2
  374. package/dist/src/worker/index.js.map +0 -1
  375. package/dist/src/worker/wasmError.d.ts +0 -17
  376. package/dist/src/worker/wasmError.d.ts.map +0 -1
  377. package/dist/src/worker/wasmError.js +0 -28
  378. package/dist/src/worker/wasmError.js.map +0 -1
  379. package/dist/src/worker/worker-inline.d.ts +0 -2
  380. package/dist/src/worker/worker-inline.d.ts.map +0 -1
  381. package/dist/src/worker/worker-inline.js +0 -2
  382. package/dist/src/worker/worker-inline.js.map +0 -1
  383. package/dist/src/worker/worker.d.ts +0 -530
  384. package/dist/src/worker/worker.d.ts.map +0 -1
  385. package/dist/src/worker/worker.js +0 -2935
  386. package/dist/src/worker/worker.js.map +0 -1
@@ -1,1721 +0,0 @@
1
- import { subscribeSelector } from "../../framework/selectors";
2
- import { getPointsToPixels, } from "../state";
3
- import { showAnnotationPopup, closeAnnotationPopup } from "../annotation";
4
- import { calculateSpreads, calculateSpreadLayouts, calculateContinuousLayout, findSpreadForPage, findVisibleSpreadRange, getSpreadPrimaryPage, getSpreadDimensions, } from "../layout/spreadLayout";
5
- import { createSpread } from "./Spread";
6
- import { createFloatingToolbar } from "./FloatingToolbar";
7
- import { createBranding } from "./Branding";
8
- import { on } from "../../framework/events";
9
- import { getDevicePixelRatio, getEffectiveDpr, snapToDevice, toCssPixels, toDevicePixels } from "../layout";
10
- import { runTransition } from "../transition";
11
- import { advanceActiveSlideAnimation, clearActiveSlideAnimation, forgetSlideAnimations, knownToAnimate, mountSlideAnimation, prefetchSlideAnimation, } from "../animation";
12
- import { createViewToolController } from "../tools/ViewToolController";
13
- import { createAnnotationDrawController } from "../tools/AnnotationDrawController";
14
- import { createAnnotationSelectController } from "../tools/AnnotationSelectController";
15
- function viewportSliceEqual(a, b) {
16
- return (a.docId === b.docId &&
17
- a.page === b.page &&
18
- a.pageCount === b.pageCount &&
19
- a.pageInfos === b.pageInfos &&
20
- a.pageGroups === b.pageGroups &&
21
- a.activeGroupIndex === b.activeGroupIndex &&
22
- a.viewMode === b.viewMode &&
23
- a.scrollMode === b.scrollMode &&
24
- a.layoutMode === b.layoutMode &&
25
- a.zoomMode === b.zoomMode &&
26
- a.zoom === b.zoom &&
27
- a.dpi === b.dpi &&
28
- a.pageRotation === b.pageRotation &&
29
- a.spacingMode === b.spacingMode &&
30
- a.pageSpacing === b.pageSpacing &&
31
- a.spreadSpacing === b.spreadSpacing &&
32
- a.pageAnnotations === b.pageAnnotations &&
33
- a.highlightedAnnotation === b.highlightedAnnotation &&
34
- a.pageText === b.pageText &&
35
- a.zoomAnchor === b.zoomAnchor);
36
- }
37
- let cachedScrollbarSize = null;
38
- /** Number of spreads to render above/below viewport for smooth scrolling */
39
- const RENDER_BUFFER = 2;
40
- function parsePixel(value) {
41
- const parsed = parseFloat(value);
42
- return Number.isFinite(parsed) ? parsed : 0;
43
- }
44
- function readInsets(style) {
45
- return {
46
- top: parsePixel(style.paddingTop),
47
- right: parsePixel(style.paddingRight),
48
- bottom: parsePixel(style.paddingBottom),
49
- left: parsePixel(style.paddingLeft),
50
- };
51
- }
52
- function addInsets(a, b) {
53
- return {
54
- top: a.top + b.top,
55
- right: a.right + b.right,
56
- bottom: a.bottom + b.bottom,
57
- left: a.left + b.left,
58
- };
59
- }
60
- function readViewportMetrics(scrollArea, container) {
61
- const scrollStyle = getComputedStyle(scrollArea);
62
- const containerStyle = getComputedStyle(container);
63
- const padding = addInsets(readInsets(scrollStyle), readInsets(containerStyle));
64
- const width = scrollArea.clientWidth;
65
- const height = scrollArea.clientHeight;
66
- const innerWidth = Math.max(0, width - padding.left - padding.right);
67
- const innerHeight = Math.max(0, height - padding.top - padding.bottom);
68
- return {
69
- width,
70
- height,
71
- innerWidth,
72
- innerHeight,
73
- padding,
74
- };
75
- }
76
- function metricsEqual(a, b) {
77
- // Use epsilon tolerance to prevent oscillation from 1px fluctuations
78
- const epsilon = 1;
79
- return (Math.abs(a.width - b.width) <= epsilon &&
80
- Math.abs(a.height - b.height) <= epsilon &&
81
- Math.abs(a.innerWidth - b.innerWidth) <= epsilon &&
82
- Math.abs(a.innerHeight - b.innerHeight) <= epsilon &&
83
- a.padding.top === b.padding.top &&
84
- a.padding.right === b.padding.right &&
85
- a.padding.bottom === b.padding.bottom &&
86
- a.padding.left === b.padding.left);
87
- }
88
- function resolveOverflowState(prev, delta, threshold) {
89
- if (prev === null)
90
- return delta > threshold;
91
- if (prev)
92
- return delta >= -threshold;
93
- return delta > threshold;
94
- }
95
- function clamp(value, min, max) {
96
- return Math.min(max, Math.max(min, value));
97
- }
98
- function computePrerenderScale(pageInfos, currentPage, zoom, pointsToPixels, dpr) {
99
- // Match Spread.render's per-page DPR clamp so prerender cache keys align and WASM doesn't
100
- // allocate oversize bitmaps at extreme zoom (iOS Safari / mobile WASM).
101
- let minEffDpr = dpr;
102
- const range = 2;
103
- for (let offset = -range; offset <= range; offset++) {
104
- const p = pageInfos[currentPage - 1 + offset];
105
- if (!p)
106
- continue;
107
- const cssW = p.width * pointsToPixels * zoom;
108
- const cssH = p.height * pointsToPixels * zoom;
109
- const eff = getEffectiveDpr(cssW, cssH, dpr);
110
- if (eff < minEffDpr)
111
- minEffDpr = eff;
112
- }
113
- return pointsToPixels * zoom * minEffDpr;
114
- }
115
- function getCenteredOffset(containerSize, contentSize) {
116
- const dpr = getDevicePixelRatio();
117
- const containerDevice = toDevicePixels(containerSize, dpr);
118
- const contentDevice = toDevicePixels(contentSize, dpr);
119
- const offsetDevice = Math.max(0, Math.floor((containerDevice - contentDevice) / 2));
120
- return toCssPixels(offsetDevice, dpr);
121
- }
122
- function getScrollbarSize() {
123
- if (cachedScrollbarSize)
124
- return cachedScrollbarSize;
125
- if (!document.body) {
126
- cachedScrollbarSize = { width: 0, height: 0 };
127
- return cachedScrollbarSize;
128
- }
129
- const probe = document.createElement("div");
130
- probe.style.width = "100px";
131
- probe.style.height = "100px";
132
- probe.style.overflow = "scroll";
133
- probe.style.position = "absolute";
134
- probe.style.top = "-9999px";
135
- document.body.appendChild(probe);
136
- const width = probe.offsetWidth - probe.clientWidth;
137
- const height = probe.offsetHeight - probe.clientHeight;
138
- probe.remove();
139
- cachedScrollbarSize = { width, height };
140
- return cachedScrollbarSize;
141
- }
142
- /**
143
- * Computes the zoom scale for fit modes.
144
- *
145
- * For fit-spread-width mode, we predict whether a vertical scrollbar will be needed
146
- * and adjust the available width accordingly. This prevents the feedback loop where:
147
- * 1. Scale is calculated based on viewport width
148
- * 2. Content is taller than viewport, scrollbar appears
149
- * 3. Scrollbar reduces viewport width, causing recalculation
150
- *
151
- * @param slice - Viewport state slice
152
- * @param metrics - Current viewport metrics
153
- * @param spreads - Array of spreads to layout
154
- * @param scrollbarVisible - Whether vertical scrollbar is currently visible
155
- */
156
- function computeScale(slice, metrics, spreads, scrollbarVisible) {
157
- if (slice.zoomMode === "custom")
158
- return slice.zoom;
159
- if (metrics.innerWidth <= 0 || metrics.innerHeight <= 0)
160
- return slice.zoom;
161
- if (spreads.length === 0)
162
- return slice.zoom;
163
- let maxWidth = 0;
164
- let maxHeight = 0;
165
- for (const spread of spreads) {
166
- const dims = getSpreadDimensions(spread, slice.pageInfos, 1, slice.pageSpacing, slice.dpi, slice.pageRotation);
167
- maxWidth = Math.max(maxWidth, dims.width);
168
- maxHeight = Math.max(maxHeight, dims.height);
169
- }
170
- if (maxWidth <= 0 || maxHeight <= 0)
171
- return slice.zoom;
172
- // Use snapped values to match layout calculations exactly.
173
- // Round to the nearest device pixel to avoid scrollbar feedback loops.
174
- const snappedSpacing = snapToDevice(slice.spreadSpacing);
175
- const snappedViewportHeight = snapToDevice(metrics.innerHeight);
176
- const scrollbar = getScrollbarSize();
177
- // Calculate the "base" viewport width (without scrollbar).
178
- // If scrollbar is currently visible, metrics.innerWidth already excludes it,
179
- // so we add it back to get the full available width.
180
- const baseViewportWidth = scrollbarVisible
181
- ? snapToDevice(metrics.innerWidth + scrollbar.width)
182
- : snapToDevice(metrics.innerWidth);
183
- const verticalSpacing = snappedSpacing * 2;
184
- // Add 1 pixel buffer to compensate for device pixel rounding in layout calculations.
185
- // Without this, the spread may be slightly smaller than the viewport, allowing
186
- // a thin line of the next page to show at the bottom in continuous scroll mode.
187
- // The same buffer is used in spread mode for consistency when switching modes.
188
- // Scrollbar overflow in spread mode is handled by applySingleLayout using viewport height.
189
- const targetHeight = Math.max(0, snappedViewportHeight - verticalSpacing + 1);
190
- switch (slice.zoomMode) {
191
- case "fit-spread-width-max":
192
- case "fit-spread-width": {
193
- // Calculate scale assuming full viewport width (no scrollbar)
194
- const fullWidthScale = baseViewportWidth / maxWidth;
195
- // Predict if vertical scrollbar will be needed at this scale.
196
- // For continuous mode: check if total content height exceeds viewport.
197
- // For spread mode: check if tallest spread + spacing exceeds viewport.
198
- let needsScrollbar;
199
- if (slice.scrollMode === "continuous") {
200
- // In continuous mode, calculate total content height
201
- // Total height = sum of all spread heights + spacing between spreads
202
- let totalHeight = 0;
203
- for (const spread of spreads) {
204
- const dims = getSpreadDimensions(spread, slice.pageInfos, fullWidthScale, slice.pageSpacing, slice.dpi, slice.pageRotation);
205
- totalHeight += dims.height;
206
- }
207
- totalHeight += snappedSpacing * (spreads.length + 1); // spacing before first, between, and after last
208
- needsScrollbar = totalHeight > snappedViewportHeight;
209
- }
210
- else {
211
- // In spread mode, check if the tallest spread + spacing exceeds viewport
212
- const scaledMaxHeight = maxHeight * fullWidthScale;
213
- needsScrollbar = scaledMaxHeight + verticalSpacing > snappedViewportHeight;
214
- }
215
- let scale;
216
- if (needsScrollbar && scrollbar.width > 0) {
217
- // Scrollbar will be needed, calculate scale with reduced viewport width
218
- const adjustedWidth = baseViewportWidth - scrollbar.width;
219
- scale = adjustedWidth / maxWidth;
220
- }
221
- else {
222
- // No scrollbar needed, use full width
223
- scale = fullWidthScale;
224
- }
225
- // For fit-spread-width-max, cap at 100% (never enlarge beyond natural size)
226
- return slice.zoomMode === "fit-spread-width-max" ? Math.min(scale, 1) : scale;
227
- }
228
- case "fit-spread-height":
229
- // Content fits height by design, no vertical scrollbar needed
230
- return targetHeight / maxHeight;
231
- case "fit-spread":
232
- // Content fits both dimensions by design, no scrollbar needed
233
- return Math.min(baseViewportWidth / maxWidth, targetHeight / maxHeight);
234
- default:
235
- return slice.zoom;
236
- }
237
- }
238
- function buildLayout(slice, metrics, scrollbarVisible) {
239
- const spreads = calculateSpreads(slice.pageCount, slice.layoutMode);
240
- const scale = computeScale(slice, metrics, spreads, scrollbarVisible);
241
- if (slice.viewMode === "continuous") {
242
- const activeGroup = slice.pageGroups[slice.activeGroupIndex] ?? null;
243
- const contLayout = calculateContinuousLayout(spreads, slice.pageInfos, scale, slice.dpi, slice.pageRotation, activeGroup);
244
- return {
245
- spreads,
246
- layouts: contLayout.layouts,
247
- contentWidth: contLayout.contentWidth,
248
- contentHeight: contLayout.contentHeight,
249
- scale,
250
- continuousLayout: contLayout,
251
- };
252
- }
253
- const layout = calculateSpreadLayouts(spreads, slice.pageInfos, scale, slice.pageSpacing, slice.spreadSpacing, slice.dpi, slice.pageRotation);
254
- return {
255
- spreads,
256
- layouts: layout.layouts,
257
- contentWidth: layout.contentWidth,
258
- contentHeight: layout.contentHeight,
259
- scale,
260
- continuousLayout: null,
261
- };
262
- }
263
- function computeViewportUpdate(prevSlice, nextSlice, prevMetrics, nextMetrics) {
264
- const metricsChanged = !prevMetrics || !metricsEqual(prevMetrics, nextMetrics);
265
- const layoutChanged = !prevSlice ||
266
- nextSlice.docId !== prevSlice.docId ||
267
- nextSlice.pageCount !== prevSlice.pageCount ||
268
- nextSlice.pageInfos !== prevSlice.pageInfos ||
269
- nextSlice.pageGroups !== prevSlice.pageGroups ||
270
- nextSlice.activeGroupIndex !== prevSlice.activeGroupIndex ||
271
- nextSlice.viewMode !== prevSlice.viewMode ||
272
- nextSlice.scrollMode !== prevSlice.scrollMode ||
273
- nextSlice.layoutMode !== prevSlice.layoutMode ||
274
- nextSlice.zoomMode !== prevSlice.zoomMode ||
275
- nextSlice.zoom !== prevSlice.zoom ||
276
- nextSlice.dpi !== prevSlice.dpi ||
277
- nextSlice.pageRotation !== prevSlice.pageRotation ||
278
- nextSlice.pageSpacing !== prevSlice.pageSpacing ||
279
- nextSlice.spreadSpacing !== prevSlice.spreadSpacing ||
280
- metricsChanged;
281
- const zoomModeChanged = !prevSlice || nextSlice.zoomMode !== prevSlice.zoomMode;
282
- const spreadsChanged = !prevSlice ||
283
- nextSlice.docId !== prevSlice.docId ||
284
- nextSlice.pageCount !== prevSlice.pageCount ||
285
- nextSlice.pageInfos !== prevSlice.pageInfos ||
286
- nextSlice.pageGroups !== prevSlice.pageGroups ||
287
- nextSlice.activeGroupIndex !== prevSlice.activeGroupIndex ||
288
- nextSlice.viewMode !== prevSlice.viewMode ||
289
- nextSlice.layoutMode !== prevSlice.layoutMode;
290
- const shouldClearSpreads = layoutChanged && spreadsChanged;
291
- // Scroll to page on document change or zoom mode change (explicit user actions)
292
- const shouldScrollToPage = spreadsChanged || zoomModeChanged;
293
- // Restore tracked viewport position when layout changes but document structure is the same
294
- // This maintains scroll position across mode switches, zoom changes, and viewport resizes
295
- const shouldRestorePosition = layoutChanged && !spreadsChanged && !zoomModeChanged;
296
- return {
297
- layoutChanged,
298
- shouldClearSpreads,
299
- shouldRestorePosition,
300
- shouldScrollToPage,
301
- };
302
- }
303
- export function createViewport(showAttribution = true, customPageOverlay) {
304
- const el = document.createElement("div");
305
- el.className = "udoc-viewport";
306
- el.setAttribute("role", "document");
307
- el.setAttribute("aria-label", "Document content");
308
- el.setAttribute("tabindex", "0");
309
- // Content area wraps scroll + attribution so the attribution positions
310
- // relative to the content area, not the full viewport (which includes the
311
- // floating toolbar footer on small screens).
312
- const contentArea = document.createElement("div");
313
- contentArea.className = "udoc-viewport__content";
314
- el.appendChild(contentArea);
315
- const scrollArea = document.createElement("div");
316
- scrollArea.className = "udoc-viewport__scroll";
317
- contentArea.appendChild(scrollArea);
318
- const container = document.createElement("div");
319
- container.className = "udoc-viewport__container";
320
- scrollArea.appendChild(container);
321
- // Attribution branding (skipped for licensed users with the no_attribution feature).
322
- // Visual content lives inside a closed shadow root for CSS-injection resistance;
323
- // a runtime visibility tripwire fires `udoc:branding-suppressed` if anything
324
- // does manage to hide it (host JS reaching across the shadow, etc.) so downstream
325
- // code can engage a fallback such as a rasterized watermark.
326
- let branding = null;
327
- if (showAttribution) {
328
- branding = createBranding({ variant: "viewport-corner" });
329
- contentArea.appendChild(branding.el);
330
- }
331
- const floatingToolbar = createFloatingToolbar();
332
- let viewToolController = null;
333
- let annotationDrawController = null;
334
- let annotationSelectController = null;
335
- let workerClient = null;
336
- let storeRef = null;
337
- let i18nRef = null;
338
- let unsubRender = null;
339
- let unsubScroll = null;
340
- let unsubNavigation = null;
341
- let unsubSearch = null;
342
- let currentSearchMatches = [];
343
- let currentSearchActiveIndex = -1;
344
- let resizeObserver = null;
345
- let currentSlice = null;
346
- let lastSlice = null;
347
- let lastMetrics = null;
348
- let layoutState = null;
349
- const spreadComponents = new Map();
350
- let layoutDirty = false;
351
- let lastVisibleRange = { start: 0, end: -1 };
352
- /** Last viewport:change payload fired, for de-duping. */
353
- let lastEmittedViewport = null;
354
- /** Caller-supplied callback for the public viewport:change event. */
355
- let onViewportChangeCb = null;
356
- /** Caller-supplied callback for the public annotation:hover event. */
357
- let onAnnotationHoverCb = null;
358
- /** Caller-supplied callback for the public annotation:click event. */
359
- let onAnnotationClickCb = null;
360
- /** Currently hovered annotation, used to dedupe pointermove emissions. */
361
- let lastHoveredAnnotation = null;
362
- let containerSize = { width: 0, height: 0 };
363
- let lastOverflowX = null;
364
- let lastOverflowY = null;
365
- // Track the document position at viewport top edge for consistent positioning across mode switches
366
- let viewportTopPosition = null;
367
- // After explicit navigation, remember the target page and scroll position so that
368
- // updateCurrentPageFromScroll doesn't override it (needed when the viewport is at
369
- // max scroll and the target page can't be scrolled to the top).
370
- let navigationPage = null;
371
- let navigationScrollTop = null;
372
- let updateRaf = 0;
373
- let scrollRaf = 0;
374
- let renderDebounceTimer = 0;
375
- let rendersPaused = false;
376
- let resumeRenderAfterResize = false;
377
- const RENDER_DEBOUNCE_MS = 50;
378
- const unsubEvents = [];
379
- // Slide transition state
380
- let activeTransition = null;
381
- let transitionOverlay = null;
382
- let transitionShadow = null;
383
- let previousSpreadIndex = null;
384
- function mount(parent, store, wc, i18n, onViewportChange, onAnnotationHover, onAnnotationClick) {
385
- parent.appendChild(el);
386
- // Start branding protection once the host is in the document so the
387
- // theme MutationObserver can find `.udoc-viewer-root`.
388
- branding?.start();
389
- workerClient = wc;
390
- storeRef = store;
391
- i18nRef = i18n ?? null;
392
- onViewportChangeCb = onViewportChange ?? null;
393
- onAnnotationHoverCb = onAnnotationHover ?? null;
394
- onAnnotationClickCb = onAnnotationClick ?? null;
395
- if (i18n) {
396
- el.setAttribute("aria-label", i18n.t("viewport.documentContent"));
397
- }
398
- floatingToolbar.mount(el, store, i18n);
399
- currentSlice = selectViewport(store.getState());
400
- scheduleUpdate();
401
- unsubRender = subscribeSelector(store, selectViewport, (slice) => {
402
- currentSlice = slice;
403
- scheduleUpdate();
404
- }, {
405
- equality: viewportSliceEqual,
406
- });
407
- // Separate subscription for search state — lightweight update that only
408
- // touches search highlight overlays on already-visible spreads, avoiding
409
- // the full applyState layout/text-layer cycle.
410
- currentSearchMatches = store.getState().searchMatches;
411
- currentSearchActiveIndex = store.getState().searchActiveIndex;
412
- unsubSearch = store.subscribeRender((_prev, next) => {
413
- if (next.searchMatches === currentSearchMatches && next.searchActiveIndex === currentSearchActiveIndex)
414
- return;
415
- currentSearchMatches = next.searchMatches;
416
- currentSearchActiveIndex = next.searchActiveIndex;
417
- updateVisibleSearchHighlights();
418
- });
419
- // Re-render visible spreads when the render cache is invalidated
420
- // (e.g. after a visibility group toggle)
421
- unsubEvents.push(wc.onRenderInvalidated(() => {
422
- for (const spread of spreadComponents.values()) {
423
- spread.resetRenderKeys();
424
- }
425
- if (currentSlice && lastMetrics && layoutState) {
426
- layoutDirty = true;
427
- if (currentSlice.scrollMode === "continuous") {
428
- updateVisibleSpreads(currentSlice, lastMetrics, layoutState);
429
- }
430
- else {
431
- showSingleSpread(currentSlice, lastMetrics, layoutState);
432
- }
433
- }
434
- }));
435
- unsubScroll = on(scrollArea, "scroll", () => {
436
- if (!currentSlice || !layoutState)
437
- return;
438
- if (scrollRaf)
439
- return;
440
- scrollRaf = requestAnimationFrame(() => {
441
- scrollRaf = 0;
442
- if (!currentSlice || !layoutState || !lastMetrics)
443
- return;
444
- if (currentSlice.scrollMode === "continuous") {
445
- updateVisibleSpreads(currentSlice, lastMetrics, layoutState);
446
- }
447
- // Keep viewport position tracking up to date on scroll (both modes)
448
- updateViewportTopPosition(currentSlice, layoutState);
449
- fireViewportChangeIfChanged();
450
- });
451
- });
452
- // Resize handler: layout updates immediately, but renders are only paused
453
- // when resize events keep firing (e.g. dragging panel width). This avoids
454
- // a one-off "flash" when panels are simply toggled.
455
- const handleResize = () => {
456
- const isOngoingResize = renderDebounceTimer !== 0;
457
- if (isOngoingResize) {
458
- rendersPaused = true;
459
- resumeRenderAfterResize = true;
460
- }
461
- // Clear any pending render timer
462
- if (renderDebounceTimer) {
463
- clearTimeout(renderDebounceTimer);
464
- }
465
- // Schedule render after resize settles
466
- renderDebounceTimer = window.setTimeout(() => {
467
- renderDebounceTimer = 0;
468
- if (resumeRenderAfterResize) {
469
- resumeRenderAfterResize = false;
470
- rendersPaused = false;
471
- // Trigger re-render of visible spreads
472
- scheduleUpdate();
473
- }
474
- }, RENDER_DEBOUNCE_MS);
475
- // Layout updates immediately
476
- scheduleUpdate();
477
- };
478
- if (typeof ResizeObserver !== "undefined") {
479
- resizeObserver = new ResizeObserver(handleResize);
480
- resizeObserver.observe(scrollArea);
481
- }
482
- window.addEventListener("resize", handleResize);
483
- unsubEvents.push(() => window.removeEventListener("resize", handleResize));
484
- // Handle annotation clicks (links and sticky notes)
485
- const handleAnnotationClick = (e) => {
486
- const target = e.target;
487
- // Emit annotation:click for any annotation, regardless of type or
488
- // active tool. Runs before the built-in link/sticky handlers below
489
- // so consumers can observe the click even if it triggers
490
- // navigation or a popup.
491
- const annotationEl = target.closest("[data-annotation-index]");
492
- if (annotationEl && onAnnotationClickCb && storeRef) {
493
- const slotEl = annotationEl.closest("[data-page]");
494
- const pageNum = slotEl ? parseInt(slotEl.dataset.page, 10) : NaN;
495
- const annotationIndex = parseInt(annotationEl.getAttribute("data-annotation-index"), 10);
496
- if (!isNaN(pageNum) && !isNaN(annotationIndex)) {
497
- const pageIndex = pageNum - 1;
498
- const annotation = storeRef.getState().pageAnnotations.get(pageIndex)?.[annotationIndex];
499
- if (annotation) {
500
- onAnnotationClickCb({ pageIndex, annotation, clientX: e.clientX, clientY: e.clientY });
501
- }
502
- }
503
- }
504
- // Handle sticky note (text) annotation - show popup
505
- const textEl = target.closest(".udoc-annotation--text");
506
- if (textEl) {
507
- e.stopPropagation();
508
- const annotationData = textEl.dataset.annotation;
509
- if (annotationData) {
510
- try {
511
- const annotation = JSON.parse(annotationData);
512
- showAnnotationPopup(annotation, textEl, container);
513
- }
514
- catch {
515
- // Ignore parse errors
516
- }
517
- }
518
- return;
519
- }
520
- // Handle link annotation - navigate
521
- const linkEl = target.closest(".udoc-annotation--link");
522
- if (linkEl) {
523
- const actionData = linkEl.getAttribute("data-action");
524
- if (!actionData)
525
- return;
526
- try {
527
- const action = JSON.parse(actionData);
528
- if (action.actionType === "goTo" && action.destination) {
529
- store.dispatch({
530
- type: "NAVIGATE_TO_DESTINATION",
531
- destination: action.destination,
532
- });
533
- }
534
- else if (action.actionType === "uri" && action.uri) {
535
- window.open(action.uri, "_blank", "noopener");
536
- }
537
- }
538
- catch {
539
- // Ignore parse errors
540
- }
541
- return;
542
- }
543
- // Click elsewhere closes any open popup
544
- closeAnnotationPopup();
545
- };
546
- container.addEventListener("click", handleAnnotationClick);
547
- unsubEvents.push(() => container.removeEventListener("click", handleAnnotationClick));
548
- // Emit annotation:hover events as the pointer moves over annotation
549
- // elements. Active in all tool modes (not just the select tool) and
550
- // deduped to fire only when the hovered annotation actually changes.
551
- // `coords` carries the pointer's browser-viewport position at the
552
- // moment of the change, for placing tooltips in screen space.
553
- const emitHover = (next, coords) => {
554
- const last = lastHoveredAnnotation;
555
- if (last === next ||
556
- (last !== null &&
557
- next !== null &&
558
- last.pageIndex === next.pageIndex &&
559
- last.annotationIndex === next.annotationIndex)) {
560
- return;
561
- }
562
- lastHoveredAnnotation = next;
563
- if (!onAnnotationHoverCb || !storeRef)
564
- return;
565
- if (next === null) {
566
- onAnnotationHoverCb(null);
567
- return;
568
- }
569
- const annotations = storeRef.getState().pageAnnotations.get(next.pageIndex);
570
- const annotation = annotations?.[next.annotationIndex];
571
- if (!annotation || !coords)
572
- return;
573
- onAnnotationHoverCb({
574
- pageIndex: next.pageIndex,
575
- annotation,
576
- clientX: coords.clientX,
577
- clientY: coords.clientY,
578
- });
579
- };
580
- const handleAnnotationPointerMove = (e) => {
581
- const target = e.target;
582
- const annotationEl = target?.closest("[data-annotation-index]");
583
- if (!annotationEl) {
584
- emitHover(null, null);
585
- return;
586
- }
587
- const slotEl = annotationEl.closest("[data-page]");
588
- const pageNum = slotEl ? parseInt(slotEl.dataset.page, 10) : NaN;
589
- const annotationIndex = parseInt(annotationEl.getAttribute("data-annotation-index"), 10);
590
- if (isNaN(pageNum) || isNaN(annotationIndex)) {
591
- emitHover(null, null);
592
- return;
593
- }
594
- emitHover({ pageIndex: pageNum - 1, annotationIndex }, { clientX: e.clientX, clientY: e.clientY });
595
- };
596
- const handleAnnotationPointerLeave = () => emitHover(null, null);
597
- container.addEventListener("pointermove", handleAnnotationPointerMove);
598
- container.addEventListener("pointerleave", handleAnnotationPointerLeave);
599
- unsubEvents.push(() => container.removeEventListener("pointermove", handleAnnotationPointerMove));
600
- unsubEvents.push(() => container.removeEventListener("pointerleave", handleAnnotationPointerLeave));
601
- // Advance the build by clicking the slide, the way a presentation is
602
- // driven. Only in spread mode, only with the plain pointer tool, and
603
- // never when the click was doing something else — selecting text,
604
- // hitting a link or an annotation, or working with a drawing tool.
605
- const handleAdvanceClick = (e) => {
606
- if (!currentSlice || currentSlice.scrollMode !== "spread")
607
- return;
608
- if (e.button !== 0 || e.detail > 1)
609
- return;
610
- if (!animationsEnabled())
611
- return;
612
- if (!storeRef || storeRef.getState().activeTool.kind !== "pointer")
613
- return;
614
- // A deck can opt out of click advance (PPTX `advClick="0"`).
615
- const pageInfo = currentSlice.pageInfos[currentSlice.page - 1];
616
- if (pageInfo?.transition?.advanceOnClick === false)
617
- return;
618
- const target = e.target;
619
- if (target?.closest(".udoc-spread__annotation-layer, .udoc-spread__custom-page-overlay-layer, a, button")) {
620
- return;
621
- }
622
- if (!window.getSelection()?.isCollapsed)
623
- return;
624
- if (advanceActiveSlideAnimation())
625
- e.preventDefault();
626
- };
627
- scrollArea.addEventListener("click", handleAdvanceClick);
628
- unsubEvents.push(() => scrollArea.removeEventListener("click", handleAdvanceClick));
629
- // Handle mouse wheel for page flip in spread mode
630
- let wheelCooldown = false;
631
- const handleWheel = (e) => {
632
- if (!currentSlice || currentSlice.scrollMode !== "spread")
633
- return;
634
- if (!layoutState || layoutState.spreads.length === 0)
635
- return;
636
- // Prevent default scroll in spread mode
637
- e.preventDefault();
638
- // Debounce rapid wheel events
639
- if (wheelCooldown)
640
- return;
641
- wheelCooldown = true;
642
- setTimeout(() => {
643
- wheelCooldown = false;
644
- }, 150);
645
- const currentSpreadIndex = findSpreadForPage(layoutState.spreads, currentSlice.page);
646
- if (e.deltaY > 0) {
647
- // A slide mid-build consumes the advance before the deck turns.
648
- if (advanceActiveSlideAnimation())
649
- return;
650
- // Scroll down - next spread
651
- const nextSpreadIndex = Math.min(currentSpreadIndex + 1, layoutState.spreads.length - 1);
652
- if (nextSpreadIndex !== currentSpreadIndex) {
653
- const nextPage = getSpreadPrimaryPage(layoutState.spreads[nextSpreadIndex]);
654
- store.dispatch({ type: "SET_PAGE", page: nextPage });
655
- }
656
- }
657
- else if (e.deltaY < 0) {
658
- // Scroll up - previous spread
659
- const prevSpreadIndex = Math.max(currentSpreadIndex - 1, 0);
660
- if (prevSpreadIndex !== currentSpreadIndex) {
661
- const prevPage = getSpreadPrimaryPage(layoutState.spreads[prevSpreadIndex]);
662
- store.dispatch({ type: "SET_PAGE", page: prevPage });
663
- }
664
- }
665
- };
666
- scrollArea.addEventListener("wheel", handleWheel, { passive: false });
667
- unsubEvents.push(() => scrollArea.removeEventListener("wheel", handleWheel));
668
- // View tool controller (pointer/hand/zoom interactions)
669
- const viewerRoot = el.closest(".udoc-viewer-root");
670
- if (viewerRoot) {
671
- viewToolController = createViewToolController({
672
- scrollArea,
673
- viewerRoot,
674
- store,
675
- });
676
- annotationDrawController = createAnnotationDrawController({
677
- scrollArea,
678
- viewerRoot,
679
- store,
680
- });
681
- annotationSelectController = createAnnotationSelectController({
682
- scrollArea,
683
- viewerRoot,
684
- store,
685
- });
686
- }
687
- unsubNavigation = store.subscribeEffect((prev, next) => {
688
- if (prev.navigationTarget === next.navigationTarget)
689
- return;
690
- if (next.navigationTarget === null)
691
- return;
692
- const target = next.navigationTarget;
693
- // Handle zoom change if specified
694
- if (target.zoom !== undefined && target.zoom !== next.zoom) {
695
- store.dispatch({ type: "SET_ZOOM", zoom: target.zoom });
696
- }
697
- if (next.scrollMode === "continuous") {
698
- navigationPage = target.page;
699
- scrollToTarget(target);
700
- navigationScrollTop = scrollArea.scrollTop;
701
- }
702
- store.dispatch({ type: "SET_PAGE", page: target.page });
703
- store.dispatch({ type: "CLEAR_NAVIGATION_TARGET" });
704
- });
705
- }
706
- /**
707
- * Compute the public viewport:change payload from the current visible
708
- * spread range and scroll position, then fire the bound callback when the
709
- * payload differs from the last fire. Cheap — invoked from the scroll rAF
710
- * tick and from the layout/range-update paths.
711
- */
712
- function fireViewportChangeIfChanged() {
713
- if (!onViewportChangeCb || !currentSlice || !layoutState)
714
- return;
715
- if (lastVisibleRange.start > lastVisibleRange.end)
716
- return;
717
- let firstPage = Number.POSITIVE_INFINITY;
718
- let lastPage = Number.NEGATIVE_INFINITY;
719
- for (let i = lastVisibleRange.start; i <= lastVisibleRange.end; i++) {
720
- const layout = layoutState.layouts[i];
721
- if (!layout)
722
- continue;
723
- const spread = layoutState.spreads[layout.index];
724
- if (!spread)
725
- continue;
726
- for (const slot of spread.slots) {
727
- if (slot == null)
728
- continue;
729
- const pageIndex = slot - 1;
730
- if (pageIndex < firstPage)
731
- firstPage = pageIndex;
732
- if (pageIndex > lastPage)
733
- lastPage = pageIndex;
734
- }
735
- }
736
- if (firstPage === Number.POSITIVE_INFINITY)
737
- return;
738
- const payload = {
739
- firstVisiblePage: firstPage,
740
- lastVisiblePage: lastPage,
741
- zoom: currentSlice.zoom,
742
- scrollTop: scrollArea.scrollTop,
743
- };
744
- const last = lastEmittedViewport;
745
- if (last !== null &&
746
- last.firstVisiblePage === payload.firstVisiblePage &&
747
- last.lastVisiblePage === payload.lastVisiblePage &&
748
- last.zoom === payload.zoom &&
749
- last.scrollTop === payload.scrollTop) {
750
- return;
751
- }
752
- lastEmittedViewport = payload;
753
- onViewportChangeCb(payload);
754
- }
755
- function updateVisibleSearchHighlights() {
756
- if (!currentSlice || !layoutState)
757
- return;
758
- const layoutOptions = {
759
- pageInfos: currentSlice.pageInfos,
760
- scale: layoutState.scale,
761
- dpi: currentSlice.dpi,
762
- rotation: currentSlice.pageRotation,
763
- pageSpacing: currentSlice.pageSpacing,
764
- };
765
- for (let i = lastVisibleRange.start; i <= lastVisibleRange.end; i++) {
766
- const spreadComp = spreadComponents.get(i);
767
- if (spreadComp) {
768
- spreadComp.updateSearchHighlights(currentSearchMatches, currentSearchActiveIndex, layoutOptions);
769
- }
770
- }
771
- }
772
- function scheduleUpdate() {
773
- if (!currentSlice)
774
- return;
775
- if (updateRaf)
776
- return;
777
- updateRaf = requestAnimationFrame(() => {
778
- updateRaf = 0;
779
- if (!currentSlice)
780
- return;
781
- applyState(currentSlice);
782
- });
783
- }
784
- function applyState(slice) {
785
- const sidePadding = slice.viewMode === "continuous" ? 0 : slice.pageSpacing;
786
- scrollArea.style.paddingLeft = `${sidePadding}px`;
787
- scrollArea.style.paddingRight = `${sidePadding}px`;
788
- el.classList.toggle("udoc-viewport--seamless", slice.spacingMode === "none" || slice.viewMode === "continuous");
789
- el.classList.toggle("udoc-viewport--continuous", slice.viewMode === "continuous");
790
- const metrics = readViewportMetrics(scrollArea, container);
791
- const hasDoc = !!slice.docId && slice.pageCount > 0 && slice.pageInfos.length > 0;
792
- if (!hasDoc || metrics.innerWidth <= 0 || metrics.innerHeight <= 0) {
793
- clearSpreads();
794
- container.style.height = "";
795
- container.style.width = "";
796
- container.style.minWidth = "";
797
- scrollArea.style.overflowX = "hidden";
798
- scrollArea.style.overflowY = "hidden";
799
- layoutState = null;
800
- lastVisibleRange = { start: 0, end: -1 };
801
- viewportTopPosition = null;
802
- syncEffectiveZoom(slice, null);
803
- lastSlice = slice;
804
- lastMetrics = metrics;
805
- return;
806
- }
807
- const plan = computeViewportUpdate(lastSlice, slice, lastMetrics, metrics);
808
- if (plan.shouldClearSpreads) {
809
- clearSpreads();
810
- lastVisibleRange = { start: 0, end: -1 };
811
- viewportTopPosition = null;
812
- }
813
- if (plan.layoutChanged || !layoutState) {
814
- layoutState = buildLayout(slice, metrics, lastOverflowY ?? false);
815
- layoutDirty = true;
816
- lastMetrics = metrics;
817
- }
818
- syncEffectiveZoom(slice, layoutState);
819
- if (slice.scrollMode === "continuous") {
820
- applyContinuousLayout(metrics, layoutState);
821
- if (!slice.zoomAnchor) {
822
- if (plan.shouldScrollToPage) {
823
- scrollToPage(slice.page, metrics);
824
- }
825
- else if (plan.shouldRestorePosition && viewportTopPosition) {
826
- restoreViewportPosition(viewportTopPosition, metrics, layoutState);
827
- }
828
- }
829
- updateVisibleSpreads(slice, metrics, layoutState);
830
- }
831
- else {
832
- applySingleLayout(slice, metrics, layoutState);
833
- if (!slice.zoomAnchor) {
834
- if (plan.shouldScrollToPage) {
835
- scrollArea.scrollTop = 0;
836
- scrollArea.scrollLeft = 0;
837
- lastOverflowX = null;
838
- lastOverflowY = null;
839
- }
840
- else if (plan.shouldRestorePosition && viewportTopPosition) {
841
- // In spread mode, restore position by showing the correct page
842
- const targetPage = viewportTopPosition.page;
843
- if (slice.page !== targetPage && storeRef) {
844
- storeRef.dispatch({ type: "SET_PAGE", page: targetPage });
845
- }
846
- // Reset scroll and try to restore position within the spread if it's scrollable
847
- scrollArea.scrollLeft = 0;
848
- const spreadIndex = findSpreadForPage(layoutState.spreads, targetPage);
849
- const layout = layoutState.layouts[spreadIndex];
850
- if (layout && layout.height > metrics.innerHeight && !viewportTopPosition.inSpacing) {
851
- // Spread is larger than viewport and we have a content offset
852
- // Calculate scroll position to show the same relative position
853
- const spreadTopInContainer = getCenteredOffset(containerSize.height, layout.height);
854
- const offsetPixels = viewportTopPosition.offset * layout.height;
855
- scrollArea.scrollTop = Math.max(0, spreadTopInContainer + offsetPixels);
856
- }
857
- else {
858
- scrollArea.scrollTop = 0;
859
- }
860
- lastOverflowX = null;
861
- lastOverflowY = null;
862
- }
863
- }
864
- showSingleSpread(slice, metrics, layoutState);
865
- }
866
- updateOverflow(slice, metrics);
867
- // Apply zoom anchor AFTER overflow is resolved, so that setting
868
- // overflow to "hidden" (when content shrinks on zoom-out) doesn't
869
- // reset the scroll position we're about to set.
870
- if (slice.zoomAnchor) {
871
- applyZoomAnchor(slice.zoomAnchor, metrics);
872
- }
873
- // Update tracked viewport position after layout is applied
874
- updateViewportTopPosition(slice, layoutState);
875
- // Clear zoom anchor after it has been consumed
876
- if (slice.zoomAnchor && storeRef) {
877
- storeRef.dispatch({ type: "CLEAR_ZOOM_ANCHOR" });
878
- }
879
- lastSlice = slice;
880
- }
881
- function updateOverflow(_slice, _metrics) {
882
- const epsilon = 1;
883
- const scrollWidth = scrollArea.scrollWidth;
884
- const scrollHeight = scrollArea.scrollHeight;
885
- const clientWidth = scrollArea.clientWidth;
886
- const clientHeight = scrollArea.clientHeight;
887
- const scrollbar = getScrollbarSize();
888
- // Apply hysteresis to avoid scrollbar-induced resize loops near 1px thresholds.
889
- const assumeY = lastOverflowY ?? scrollHeight - clientHeight > epsilon;
890
- const availableWidth = clientWidth + (assumeY ? scrollbar.width : 0);
891
- const deltaX = scrollWidth - availableWidth;
892
- const needsX = resolveOverflowState(lastOverflowX, deltaX, epsilon);
893
- const availableHeight = clientHeight + (needsX ? scrollbar.height : 0);
894
- const deltaY = scrollHeight - availableHeight;
895
- const finalNeedsY = resolveOverflowState(lastOverflowY, deltaY, epsilon);
896
- lastOverflowX = needsX;
897
- lastOverflowY = finalNeedsY;
898
- scrollArea.style.overflowX = needsX ? "auto" : "hidden";
899
- scrollArea.style.overflowY = finalNeedsY ? "auto" : "hidden";
900
- }
901
- function applyContinuousLayout(metrics, state) {
902
- container.style.display = "block";
903
- const height = snapToDevice(Math.max(metrics.innerHeight, state.contentHeight));
904
- container.style.height = `${height}px`;
905
- // Use min-width for horizontal overflow instead of explicit width.
906
- // This lets the container width respond to viewport resize via CSS
907
- // (no flash), while still allowing horizontal scroll when content overflows.
908
- const contentWidth = snapToDevice(state.contentWidth);
909
- if (contentWidth > metrics.innerWidth) {
910
- container.style.minWidth = `${contentWidth}px`;
911
- container.style.width = "";
912
- containerSize = { width: contentWidth, height };
913
- }
914
- else {
915
- container.style.minWidth = "";
916
- container.style.width = "";
917
- containerSize = { width: snapToDevice(metrics.innerWidth), height };
918
- }
919
- }
920
- function applySingleLayout(slice, metrics, state) {
921
- container.style.display = "block";
922
- const spreadIndex = findSpreadForPage(state.spreads, slice.page);
923
- const layout = state.layouts[spreadIndex];
924
- const spreadWidth = layout ? layout.width : 0;
925
- const spreadHeight = layout ? layout.height : 0;
926
- const snappedSpreadSpacing = snapToDevice(slice.spreadSpacing);
927
- const height = snapToDevice(Math.max(metrics.innerHeight, spreadHeight + snappedSpreadSpacing * 2));
928
- container.style.height = `${height}px`;
929
- const contentWidth = snapToDevice(spreadWidth);
930
- if (contentWidth > metrics.innerWidth) {
931
- container.style.minWidth = `${contentWidth}px`;
932
- container.style.width = "";
933
- containerSize = { width: contentWidth, height };
934
- }
935
- else {
936
- container.style.minWidth = "";
937
- container.style.width = "";
938
- containerSize = { width: snapToDevice(metrics.innerWidth), height };
939
- }
940
- }
941
- function syncEffectiveZoom(slice, state) {
942
- if (!storeRef)
943
- return;
944
- const nextZoom = slice.zoomMode === "custom" ? null : (state?.scale ?? null);
945
- const current = storeRef.getState().effectiveZoom;
946
- if (nextZoom === null) {
947
- if (current === null)
948
- return;
949
- storeRef.dispatch({ type: "SET_EFFECTIVE_ZOOM", zoom: null });
950
- return;
951
- }
952
- if (current !== null && Math.abs(nextZoom - current) < 0.001)
953
- return;
954
- storeRef.dispatch({ type: "SET_EFFECTIVE_ZOOM", zoom: nextZoom });
955
- }
956
- /**
957
- * Updates the tracked viewport top position based on current scroll state.
958
- * This captures which page is at the viewport top and how far into it we are.
959
- */
960
- function updateViewportTopPosition(slice, state) {
961
- if (state.layouts.length === 0 || state.spreads.length === 0) {
962
- viewportTopPosition = null;
963
- return;
964
- }
965
- if (slice.scrollMode !== "continuous") {
966
- // In spread mode, we know the current page directly from the slice.
967
- // Track the scroll offset relative to the current spread so we can
968
- // restore the position after layout changes (e.g. viewport resize).
969
- const spreadIndex = findSpreadForPage(state.spreads, slice.page);
970
- const spread = state.spreads[spreadIndex];
971
- const layout = state.layouts[spreadIndex];
972
- if (!layout || !spread) {
973
- viewportTopPosition = null;
974
- return;
975
- }
976
- const spreadTopInContainer = getCenteredOffset(containerSize.height, layout.height);
977
- const offsetInSpread = scrollArea.scrollTop - spreadTopInContainer;
978
- const offsetRatio = layout.height > 0 ? offsetInSpread / layout.height : 0;
979
- viewportTopPosition = {
980
- page: getSpreadPrimaryPage(spread),
981
- offset: offsetRatio,
982
- inSpacing: offsetInSpread < 0,
983
- };
984
- return;
985
- }
986
- // In continuous mode, viewport top position is directly from scrollTop
987
- const viewportTopInLayout = scrollArea.scrollTop;
988
- // Find which spread the viewport top is associated with
989
- for (let i = 0; i < state.layouts.length; i++) {
990
- const layout = state.layouts[i];
991
- const spread = state.spreads[i];
992
- if (!spread)
993
- continue;
994
- const spreadTop = layout.top;
995
- const spreadBottom = layout.top + layout.height;
996
- const offsetFromSpreadTop = viewportTopInLayout - spreadTop;
997
- // Check if viewport is in the spacing area before this spread
998
- if (viewportTopInLayout < spreadTop) {
999
- // We're in the spacing above this spread
1000
- // Store the absolute pixel offset (negative) since spacing doesn't scale
1001
- viewportTopPosition = {
1002
- page: getSpreadPrimaryPage(spread),
1003
- offset: offsetFromSpreadTop, // negative value
1004
- inSpacing: true,
1005
- };
1006
- return;
1007
- }
1008
- // Check if viewport is within this spread's content
1009
- if (viewportTopInLayout < spreadBottom || i === state.layouts.length - 1) {
1010
- // We're within the spread content
1011
- // Store as ratio of spread height so it scales correctly
1012
- const offsetRatio = layout.height > 0 ? offsetFromSpreadTop / layout.height : 0;
1013
- viewportTopPosition = {
1014
- page: getSpreadPrimaryPage(spread),
1015
- offset: offsetRatio,
1016
- inSpacing: false,
1017
- };
1018
- return;
1019
- }
1020
- }
1021
- viewportTopPosition = null;
1022
- }
1023
- /**
1024
- * Restores the viewport to a previously tracked position.
1025
- */
1026
- function restoreViewportPosition(position, metrics, state) {
1027
- const spreadIndex = findSpreadForPage(state.spreads, position.page);
1028
- const layout = state.layouts[spreadIndex];
1029
- if (!layout)
1030
- return;
1031
- let targetScrollTop;
1032
- if (position.inSpacing) {
1033
- // In spacing area: offset is absolute pixels (negative), doesn't scale
1034
- targetScrollTop = layout.top + position.offset;
1035
- }
1036
- else {
1037
- // In spread content: offset is ratio of spread height, scales with zoom
1038
- const offsetPixels = position.offset * layout.height;
1039
- targetScrollTop = layout.top + offsetPixels;
1040
- }
1041
- const maxScrollTop = Math.max(0, containerSize.height - metrics.innerHeight);
1042
- scrollArea.scrollTop = clamp(targetScrollTop, 0, maxScrollTop);
1043
- }
1044
- /**
1045
- * Adjusts scroll position after a zoom-tool click so that the clicked
1046
- * point in the document stays under the cursor.
1047
- */
1048
- function applyZoomAnchor(anchor, metrics) {
1049
- const newScrollWidth = scrollArea.scrollWidth;
1050
- const newScrollHeight = scrollArea.scrollHeight;
1051
- if (anchor.scrollWidth === 0 || anchor.scrollHeight === 0)
1052
- return;
1053
- const scaleX = newScrollWidth / anchor.scrollWidth;
1054
- const scaleY = newScrollHeight / anchor.scrollHeight;
1055
- // The point under the cursor in the old scroll coordinate space
1056
- const pointX = anchor.scrollLeft + anchor.viewX * metrics.innerWidth;
1057
- const pointY = anchor.scrollTop + anchor.viewY * metrics.innerHeight;
1058
- // Where that same point is in the new scroll coordinate space
1059
- const newPointX = pointX * scaleX;
1060
- const newPointY = pointY * scaleY;
1061
- // Adjust scroll so the point stays under the cursor
1062
- scrollArea.scrollLeft = newPointX - anchor.viewX * metrics.innerWidth;
1063
- scrollArea.scrollTop = newPointY - anchor.viewY * metrics.innerHeight;
1064
- }
1065
- function updateVisibleSpreads(slice, metrics, state) {
1066
- if (!workerClient || !slice.docId)
1067
- return;
1068
- if (state.layouts.length === 0)
1069
- return;
1070
- const scrollTop = scrollArea.scrollTop;
1071
- const visibleRange = findVisibleSpreadRange(state.layouts, scrollTop, metrics.innerHeight, RENDER_BUFFER);
1072
- const rangeChanged = visibleRange.start !== lastVisibleRange.start || visibleRange.end !== lastVisibleRange.end;
1073
- const isContinuousView = slice.viewMode === "continuous";
1074
- const contLayout = state.continuousLayout;
1075
- const cropMode = isContinuousView
1076
- ? contLayout?.isGridLayout
1077
- ? "full"
1078
- : "vertical"
1079
- : "none";
1080
- const layoutOptions = {
1081
- pageInfos: slice.pageInfos,
1082
- scale: state.scale,
1083
- dpi: slice.dpi,
1084
- rotation: slice.pageRotation,
1085
- pageSpacing: slice.pageSpacing,
1086
- cropMode,
1087
- };
1088
- if (layoutDirty || rangeChanged) {
1089
- for (const [index, spread] of spreadComponents) {
1090
- if (index < visibleRange.start || index > visibleRange.end) {
1091
- spread.destroy();
1092
- spreadComponents.delete(index);
1093
- }
1094
- }
1095
- const renderOptions = {
1096
- docId: slice.docId,
1097
- scale: state.scale,
1098
- dpi: slice.dpi,
1099
- };
1100
- for (let i = visibleRange.start; i <= visibleRange.end; i++) {
1101
- const layout = state.layouts[i];
1102
- if (!layout)
1103
- continue;
1104
- let spreadComp = spreadComponents.get(i);
1105
- if (!spreadComp) {
1106
- // `layouts` may be filtered (XLSX active group only), so
1107
- // look up the source spread by its global `.index`, not
1108
- // by the filtered array position.
1109
- const spreadData = state.spreads[layout.index];
1110
- spreadComp = createSpread(spreadData, showAttribution, i18nRef ?? undefined, customPageOverlay);
1111
- spreadComp.mount(container);
1112
- spreadComponents.set(i, spreadComp);
1113
- }
1114
- spreadComp.updateLayout(layoutOptions);
1115
- // Set spread position and dimensions from layout.
1116
- const spreadEl = spreadComp.getElement();
1117
- spreadEl.style.position = "absolute";
1118
- spreadEl.style.top = `${layout.top}px`;
1119
- spreadEl.style.height = `${layout.height}px`;
1120
- if (isContinuousView && contLayout?.isGridLayout) {
1121
- // Grid continuous (XLSX): position using left offset from row layout
1122
- const pageIndex = layout.slots[0] ? layout.slots[0] - 1 : i;
1123
- const rowLayout = contLayout.rowLayouts.find((r) => r.pages.some((p) => p.pageIndex === pageIndex));
1124
- const pageDef = rowLayout?.pages.find((p) => p.pageIndex === pageIndex);
1125
- if (pageDef) {
1126
- spreadEl.style.left = `${pageDef.left}px`;
1127
- spreadEl.style.width = `${pageDef.width}px`;
1128
- spreadEl.style.right = "";
1129
- }
1130
- else {
1131
- spreadEl.style.left = "0px";
1132
- spreadEl.style.right = "0px";
1133
- spreadEl.style.width = "";
1134
- }
1135
- // No centering in grid mode — content is flush to left
1136
- spreadEl.style.justifyContent = "flex-start";
1137
- // Mark last-col / last-row for stitch line hiding
1138
- const isLastCol = pageDef ? pageDef.col === contLayout.columnWidths.length - 1 : false;
1139
- const isLastRow = rowLayout
1140
- ? rowLayout.row === contLayout.rowLayouts[contLayout.rowLayouts.length - 1].row
1141
- : false;
1142
- spreadEl.classList.toggle("udoc-spread--last-col", isLastCol);
1143
- spreadEl.classList.toggle("udoc-spread--last-row", isLastRow);
1144
- }
1145
- else if (isContinuousView) {
1146
- // Linear continuous: center, single column = always last col
1147
- spreadEl.style.left = "0px";
1148
- spreadEl.style.right = "0px";
1149
- spreadEl.style.width = "";
1150
- spreadEl.style.justifyContent = "";
1151
- spreadEl.classList.add("udoc-spread--last-col");
1152
- spreadEl.classList.toggle("udoc-spread--last-row", i === state.layouts.length - 1);
1153
- }
1154
- else {
1155
- // Paged mode
1156
- spreadEl.style.left = "0px";
1157
- spreadEl.style.right = "0px";
1158
- spreadEl.style.width = "";
1159
- spreadEl.style.justifyContent = "";
1160
- spreadEl.classList.remove("udoc-spread--last-col", "udoc-spread--last-row");
1161
- }
1162
- spreadEl.style.transform = "none";
1163
- // Skip render during resize animation (renders debounced separately)
1164
- if (!rendersPaused) {
1165
- spreadComp.render(workerClient, renderOptions);
1166
- }
1167
- }
1168
- lastVisibleRange = visibleRange;
1169
- // Only clear layoutDirty if renders actually happened
1170
- // Otherwise keep it dirty so renders happen when rendersPaused becomes false
1171
- if (!rendersPaused) {
1172
- layoutDirty = false;
1173
- }
1174
- }
1175
- // Always update annotations, text, and search highlights on visible spreads (they may load after layout)
1176
- for (let i = visibleRange.start; i <= visibleRange.end; i++) {
1177
- const spreadComp = spreadComponents.get(i);
1178
- if (spreadComp) {
1179
- spreadComp.updateAnnotations(slice.pageAnnotations, layoutOptions, slice.highlightedAnnotation);
1180
- spreadComp.updateTextLayer(slice.pageText, layoutOptions);
1181
- spreadComp.updateSearchHighlights(currentSearchMatches, currentSearchActiveIndex, layoutOptions);
1182
- spreadComp.updateCustomPageOverlay(layoutOptions);
1183
- }
1184
- }
1185
- const viewportCenter = scrollTop + metrics.innerHeight / 2;
1186
- const focusPage = findSpreadAtCenter(viewportCenter, state);
1187
- if (focusPage !== null) {
1188
- workerClient.boostPageRenderPriority(slice.docId, focusPage);
1189
- }
1190
- updateCurrentPageFromScroll(scrollTop, metrics.innerHeight, state);
1191
- fireViewportChangeIfChanged();
1192
- }
1193
- /**
1194
- * Cancel any active transition and remove the snapshot overlay.
1195
- * Safe to call at any time — no-ops when nothing is active.
1196
- */
1197
- function cleanupTransition() {
1198
- if (activeTransition) {
1199
- activeTransition.cancel();
1200
- activeTransition = null;
1201
- }
1202
- if (transitionOverlay) {
1203
- transitionOverlay.remove();
1204
- transitionOverlay = null;
1205
- }
1206
- if (transitionShadow) {
1207
- transitionShadow.remove();
1208
- transitionShadow = null;
1209
- }
1210
- }
1211
- /**
1212
- * Capture a lightweight snapshot of the spread's visible content.
1213
- *
1214
- * Returns a div positioned absolutely at the slot's location in the
1215
- * container, containing a canvas with the rendered bitmap. The div
1216
- * carries the page shadow so the outgoing content retains its framing
1217
- * during transitions. Transition effects that restructure the snapshot
1218
- * (like blinds) can clear the div and rebuild its contents.
1219
- */
1220
- function captureSnapshot(spreadComp) {
1221
- const el = spreadComp.getElement();
1222
- // Find the main rendered canvas (prefer full-res over preview)
1223
- const mainCanvas = el.querySelector(".udoc-spread__canvas") ??
1224
- el.querySelector("canvas");
1225
- if (!mainCanvas || mainCanvas.width === 0 || mainCanvas.height === 0)
1226
- return null;
1227
- // Copy the canvas at its native resolution — no resampling.
1228
- const canvas = document.createElement("canvas");
1229
- canvas.width = mainCanvas.width;
1230
- canvas.height = mainCanvas.height;
1231
- canvas.style.display = "block";
1232
- const ctx = canvas.getContext("2d");
1233
- if (!ctx)
1234
- return null;
1235
- ctx.drawImage(mainCanvas, 0, 0);
1236
- // Size the snapshot so each canvas pixel maps 1:1 to a device pixel.
1237
- // Position is snapped to the device-pixel grid to avoid subpixel
1238
- // interpolation that causes 1-2px misalignment in strip/tile effects.
1239
- const dpr = window.devicePixelRatio || 1;
1240
- const cssW = mainCanvas.width / dpr;
1241
- const cssH = mainCanvas.height / dpr;
1242
- canvas.style.width = `${cssW}px`;
1243
- canvas.style.height = `${cssH}px`;
1244
- const containerRect = container.getBoundingClientRect();
1245
- const canvasRect = mainCanvas.getBoundingClientRect();
1246
- const rawLeft = canvasRect.left - containerRect.left;
1247
- const rawTop = canvasRect.top - containerRect.top;
1248
- const snappedLeft = Math.round(rawLeft * dpr) / dpr;
1249
- const snappedTop = Math.round(rawTop * dpr) / dpr;
1250
- const snapshot = document.createElement("div");
1251
- snapshot.style.position = "absolute";
1252
- snapshot.style.left = `${snappedLeft}px`;
1253
- snapshot.style.top = `${snappedTop}px`;
1254
- snapshot.style.width = `${cssW}px`;
1255
- snapshot.style.height = `${cssH}px`;
1256
- snapshot.style.pointerEvents = "none";
1257
- snapshot.appendChild(canvas);
1258
- return snapshot;
1259
- }
1260
- function showSingleSpread(slice, _metrics, state) {
1261
- if (!workerClient || !slice.docId)
1262
- return;
1263
- const spreadIndex = findSpreadForPage(state.spreads, slice.page);
1264
- const layout = state.layouts[spreadIndex];
1265
- if (!layout)
1266
- return;
1267
- const isNewSpread = previousSpreadIndex !== null && spreadIndex !== previousSpreadIndex;
1268
- // If a transition is playing or waiting for render (transitionOverlay
1269
- // is set) and this is just a state refresh (annotations, text, search),
1270
- // update the spread layers without touching the animation.
1271
- if ((activeTransition || transitionOverlay) && !isNewSpread) {
1272
- const spreadComp = spreadComponents.get(spreadIndex);
1273
- if (spreadComp) {
1274
- const layoutOptions = {
1275
- pageInfos: slice.pageInfos,
1276
- scale: state.scale,
1277
- dpi: slice.dpi,
1278
- rotation: slice.pageRotation,
1279
- pageSpacing: slice.pageSpacing,
1280
- };
1281
- spreadComp.updateAnnotations(slice.pageAnnotations, layoutOptions, slice.highlightedAnnotation);
1282
- spreadComp.updateTextLayer(slice.pageText, layoutOptions);
1283
- spreadComp.updateSearchHighlights(currentSearchMatches, currentSearchActiveIndex, layoutOptions);
1284
- spreadComp.updateCustomPageOverlay(layoutOptions);
1285
- }
1286
- lastVisibleRange = { start: spreadIndex, end: spreadIndex };
1287
- fireViewportChangeIfChanged();
1288
- return;
1289
- }
1290
- const forward = previousSpreadIndex !== null ? spreadIndex > previousSpreadIndex : true;
1291
- // Get transition from target page's PageInfo (0-based index)
1292
- const targetPageIndex = getSpreadPrimaryPage(state.spreads[spreadIndex]) - 1;
1293
- const pageTransition = isNewSpread ? slice.pageInfos[targetPageIndex]?.transition : undefined;
1294
- const wantTransition = isNewSpread &&
1295
- pageTransition != null &&
1296
- pageTransition.effect.type !== "replace" &&
1297
- storeRef !== null &&
1298
- storeRef.getState().transitionsEnabled;
1299
- // Capture a snapshot of the outgoing spread BEFORE destroying it
1300
- let snapshot = null;
1301
- if (wantTransition) {
1302
- const outgoingComp = spreadComponents.get(previousSpreadIndex);
1303
- if (outgoingComp) {
1304
- snapshot = captureSnapshot(outgoingComp);
1305
- }
1306
- }
1307
- // Cancel any prior transition / remove stale overlay
1308
- cleanupTransition();
1309
- // ---- Original spread lifecycle (unchanged) ----
1310
- for (const [index, spread] of spreadComponents) {
1311
- if (index !== spreadIndex) {
1312
- spread.destroy();
1313
- spreadComponents.delete(index);
1314
- }
1315
- }
1316
- let spreadComp = spreadComponents.get(spreadIndex);
1317
- if (!spreadComp) {
1318
- const spreadData = state.spreads[spreadIndex];
1319
- spreadComp = createSpread(spreadData, showAttribution, i18nRef ?? undefined);
1320
- spreadComp.mount(container);
1321
- spreadComponents.set(spreadIndex, spreadComp);
1322
- }
1323
- const layoutOptions = {
1324
- pageInfos: slice.pageInfos,
1325
- scale: state.scale,
1326
- dpi: slice.dpi,
1327
- rotation: slice.pageRotation,
1328
- pageSpacing: slice.pageSpacing,
1329
- };
1330
- spreadComp.updateLayout(layoutOptions);
1331
- spreadComp.updateAnnotations(slice.pageAnnotations, layoutOptions, slice.highlightedAnnotation);
1332
- spreadComp.updateTextLayer(slice.pageText, layoutOptions);
1333
- spreadComp.updateSearchHighlights(currentSearchMatches, currentSearchActiveIndex, layoutOptions);
1334
- spreadComp.updateCustomPageOverlay(layoutOptions);
1335
- // Layout values are pre-snapped
1336
- const top = getCenteredOffset(containerSize.height, layout.height);
1337
- const spreadEl = spreadComp.getElement();
1338
- spreadEl.style.position = "absolute";
1339
- spreadEl.style.top = `${top}px`;
1340
- spreadEl.style.height = `${layout.height}px`;
1341
- spreadEl.style.left = "0px";
1342
- spreadEl.style.right = "0px";
1343
- spreadEl.style.width = "";
1344
- spreadEl.style.transform = "none";
1345
- // ---- Render + Transition ----
1346
- if (snapshot && wantTransition) {
1347
- // Static shadow element — sits behind both snapshot and spread,
1348
- // stays untouched by any transition effect so the page shadow
1349
- // remains consistent regardless of clip-path/opacity/transform.
1350
- const slot = spreadEl.querySelector(".udoc-spread__slot");
1351
- if (slot) {
1352
- const shadowEl = document.createElement("div");
1353
- const containerRect = container.getBoundingClientRect();
1354
- const slotRect = slot.getBoundingClientRect();
1355
- shadowEl.style.position = "absolute";
1356
- shadowEl.style.left = `${slotRect.left - containerRect.left}px`;
1357
- shadowEl.style.top = `${slotRect.top - containerRect.top}px`;
1358
- shadowEl.style.width = `${slotRect.width}px`;
1359
- shadowEl.style.height = `${slotRect.height}px`;
1360
- shadowEl.style.boxShadow = "var(--udoc-shadow-page)";
1361
- shadowEl.style.pointerEvents = "none";
1362
- container.insertBefore(shadowEl, spreadEl);
1363
- transitionShadow = shadowEl;
1364
- // Hide the slot's own shadow so it doesn't double up or
1365
- // get clipped/faded by the transition effect.
1366
- slot.style.boxShadow = "none";
1367
- }
1368
- // Insert snapshot BEFORE the spread. Give it z-index so it fully
1369
- // covers the incoming spread while we wait for the render to finish.
1370
- container.insertBefore(snapshot, spreadEl);
1371
- transitionOverlay = snapshot;
1372
- snapshot.style.zIndex = "1";
1373
- if (!rendersPaused) {
1374
- spreadComp
1375
- .render(workerClient, {
1376
- docId: slice.docId,
1377
- scale: state.scale,
1378
- dpi: slice.dpi,
1379
- })
1380
- .then(async () => {
1381
- // Bail if the transition was cancelled while waiting
1382
- if (transitionOverlay !== snapshot)
1383
- return;
1384
- // Mount the build before revealing the incoming slide.
1385
- // The snapshot still covers it, so an animated slide is
1386
- // never seen finished and then rewound to step 0.
1387
- await mountAnimationForSpread(spreadComp, slice, forward);
1388
- if (transitionOverlay !== snapshot)
1389
- return;
1390
- // Render done — clear the cover z-index and start animating.
1391
- snapshot.style.zIndex = "";
1392
- activeTransition = runTransition(snapshot, spreadEl, pageTransition, forward, () => {
1393
- if (transitionOverlay === snapshot) {
1394
- transitionOverlay.remove();
1395
- transitionOverlay = null;
1396
- }
1397
- // Restore slot shadow and remove static shadow
1398
- if (slot)
1399
- slot.style.boxShadow = "";
1400
- if (transitionShadow) {
1401
- transitionShadow.remove();
1402
- transitionShadow = null;
1403
- }
1404
- activeTransition = null;
1405
- });
1406
- });
1407
- // Prerender adjacent pages for smooth page flipping
1408
- const dpr = getDevicePixelRatio();
1409
- const pointsToPixels = getPointsToPixels(slice.dpi);
1410
- const renderScale = computePrerenderScale(slice.pageInfos, slice.page, state.scale, pointsToPixels, dpr);
1411
- workerClient.prerenderAdjacentPages(slice.docId, slice.page, renderScale, slice.pageInfos.length);
1412
- prefetchNeighbourAnimations(slice);
1413
- }
1414
- }
1415
- else if (!rendersPaused) {
1416
- // No transition — render immediately
1417
- void spreadComp
1418
- .render(workerClient, {
1419
- docId: slice.docId,
1420
- scale: state.scale,
1421
- dpi: slice.dpi,
1422
- })
1423
- .then(() => mountAnimationForSpread(spreadComp, slice, true));
1424
- // Prerender adjacent pages for smooth page flipping
1425
- const dpr = getDevicePixelRatio();
1426
- const pointsToPixels = getPointsToPixels(slice.dpi);
1427
- const renderScale = computePrerenderScale(slice.pageInfos, slice.page, state.scale, pointsToPixels, dpr);
1428
- workerClient.prerenderAdjacentPages(slice.docId, slice.page, renderScale, slice.pageInfos.length);
1429
- prefetchNeighbourAnimations(slice);
1430
- }
1431
- previousSpreadIndex = spreadIndex;
1432
- lastVisibleRange = { start: spreadIndex, end: spreadIndex };
1433
- // Only clear layoutDirty if renders actually happened
1434
- if (!rendersPaused) {
1435
- layoutDirty = false;
1436
- }
1437
- fireViewportChangeIfChanged();
1438
- }
1439
- /** Whether slide build sequences are turned on for this viewer (beta). */
1440
- function animationsEnabled() {
1441
- return storeRef?.getState().animationsEnabled === true;
1442
- }
1443
- /**
1444
- * Warm the build-sequence cache for the slides on either side.
1445
- *
1446
- * Presenting a deck is sequential, so by the time the user advances, the
1447
- * next slide's answer is already known and its canvas can be hidden before
1448
- * it is ever painted.
1449
- */
1450
- function prefetchNeighbourAnimations(slice) {
1451
- if (!animationsEnabled() || slice.scrollMode !== "spread" || !workerClient || !slice.docId)
1452
- return;
1453
- prefetchSlideAnimation(workerClient, slice.docId, slice.page);
1454
- prefetchSlideAnimation(workerClient, slice.docId, slice.page - 2);
1455
- }
1456
- /**
1457
- * Mount the primary page's build sequence over the spread it just rendered.
1458
- *
1459
- * Only slides with animations get a layer stack; everything else keeps the
1460
- * plain page canvas. Navigating backwards lands on the fully built slide,
1461
- * which is what PowerPoint does.
1462
- */
1463
- async function mountAnimationForSpread(spreadComp, slice, forward) {
1464
- if (!animationsEnabled() || slice.scrollMode !== "spread" || !workerClient || !slice.docId) {
1465
- clearActiveSlideAnimation();
1466
- return;
1467
- }
1468
- const client = workerClient;
1469
- const docId = slice.docId;
1470
- const targets = spreadComp.getAnimationTargets(slice.page);
1471
- if (!targets || targets.cssWidth <= 0 || targets.cssHeight <= 0) {
1472
- clearActiveSlideAnimation();
1473
- return;
1474
- }
1475
- // When the answer is already cached, hide the finished slide before
1476
- // yielding — otherwise it is painted for a frame before the build
1477
- // rewinds it. A cold cache falls back to hiding inside the mount, one
1478
- // cheap round trip later.
1479
- if (knownToAnimate(docId, slice.page - 1) === true) {
1480
- targets.canvas.style.visibility = "hidden";
1481
- }
1482
- // Rasterize layers at the same device resolution as the page canvas so
1483
- // they stay crisp at rest and line up pixel for pixel.
1484
- const dpr = getEffectiveDpr(targets.cssWidth, targets.cssHeight, getDevicePixelRatio());
1485
- const renderWidth = Math.max(1, Math.round(targets.cssWidth * dpr));
1486
- const renderHeight = Math.max(1, Math.round(targets.cssHeight * dpr));
1487
- try {
1488
- await mountSlideAnimation({
1489
- workerClient: client,
1490
- docId,
1491
- pageIndex: slice.page - 1,
1492
- host: targets.host,
1493
- pageCanvas: targets.canvas,
1494
- renderWidth,
1495
- renderHeight,
1496
- startComplete: !forward,
1497
- });
1498
- }
1499
- catch {
1500
- // A failed build must never cost the user the slide itself; the
1501
- // plain canvas is already on screen and stays.
1502
- clearActiveSlideAnimation();
1503
- }
1504
- }
1505
- /** Find the spread whose center is closest to a given Y position (used for render priority). */
1506
- function findSpreadAtCenter(y, state) {
1507
- if (state.layouts.length === 0 || state.spreads.length === 0)
1508
- return null;
1509
- let closestIndex = 0;
1510
- let closestDistance = Infinity;
1511
- for (let i = 0; i < state.layouts.length; i++) {
1512
- const layout = state.layouts[i];
1513
- const spreadCenter = layout.top + layout.height / 2;
1514
- const distance = Math.abs(spreadCenter - y);
1515
- if (distance < closestDistance) {
1516
- closestDistance = distance;
1517
- closestIndex = i;
1518
- }
1519
- }
1520
- const spread = state.spreads[closestIndex];
1521
- return spread ? getSpreadPrimaryPage(spread) : null;
1522
- }
1523
- function updateCurrentPageFromScroll(scrollTop, viewportHeight, state) {
1524
- if (!storeRef)
1525
- return;
1526
- let primaryPage;
1527
- if (navigationPage !== null && navigationScrollTop !== null && scrollTop === navigationScrollTop) {
1528
- // Scroll position unchanged since explicit navigation – keep that page.
1529
- primaryPage = navigationPage;
1530
- }
1531
- else {
1532
- // User scrolled – clear override and detect from viewport center.
1533
- navigationPage = null;
1534
- navigationScrollTop = null;
1535
- const viewportCenter = scrollTop + viewportHeight / 2;
1536
- primaryPage = findSpreadAtCenter(viewportCenter, state);
1537
- }
1538
- if (primaryPage === null)
1539
- return;
1540
- const currentState = storeRef.getState();
1541
- if (currentState.page !== primaryPage) {
1542
- storeRef.dispatch({ type: "SET_PAGE", page: primaryPage });
1543
- }
1544
- }
1545
- function scrollToPage(page, metrics, center) {
1546
- if (!layoutState)
1547
- return;
1548
- if (layoutState.layouts.length === 0)
1549
- return;
1550
- const viewport = metrics ?? lastMetrics;
1551
- if (!viewport)
1552
- return;
1553
- const slice = currentSlice ?? lastSlice;
1554
- if (!slice)
1555
- return;
1556
- const spreadIndex = findSpreadForPage(layoutState.spreads, page);
1557
- // layouts may be filtered (XLSX active group only), so look up by .index
1558
- // rather than array position, falling back to the first layout when the
1559
- // target page is outside the active group.
1560
- const layout = layoutState.layouts.find((l) => l.index === spreadIndex) ?? layoutState.layouts[0];
1561
- if (!layout)
1562
- return;
1563
- // Top-align with spacing (default), or center vertically if requested
1564
- const snappedSpreadSpacing = snapToDevice(slice.spreadSpacing);
1565
- const targetScrollTop = center
1566
- ? layout.top - (viewport.innerHeight - layout.height) / 2
1567
- : layout.top - snappedSpreadSpacing;
1568
- const maxScrollTop = Math.max(0, containerSize.height - viewport.innerHeight);
1569
- scrollArea.scrollTop = clamp(targetScrollTop, 0, maxScrollTop);
1570
- }
1571
- function scrollToTarget(target, metrics) {
1572
- if (!layoutState)
1573
- return;
1574
- if (layoutState.layouts.length === 0)
1575
- return;
1576
- const viewport = metrics ?? lastMetrics;
1577
- if (!viewport)
1578
- return;
1579
- const slice = currentSlice ?? lastSlice;
1580
- if (!slice)
1581
- return;
1582
- const spreadIndex = findSpreadForPage(layoutState.spreads, target.page);
1583
- const layout = layoutState.layouts[spreadIndex];
1584
- if (!layout)
1585
- return;
1586
- let targetScrollTop;
1587
- let targetScrollLeft = 0;
1588
- const alignment = target.scrollAlignment ?? "top";
1589
- // Apply scroll offset if specified (convert from PDF points to scaled pixels)
1590
- if (target.scrollTo && target.scrollTo.y !== undefined) {
1591
- // scrollTo.y is in PDF points from top of page (already Y-flipped by WASM)
1592
- // Full conversion: points * (dpi/72) * zoomScale
1593
- const dpiScale = getPointsToPixels(slice.dpi);
1594
- const pointsToPixels = dpiScale * layoutState.scale;
1595
- const yInPixels = target.scrollTo.y * pointsToPixels;
1596
- const targetTop = layout.top + yInPixels;
1597
- const targetHeight = (target.scrollTo.height ?? 0) * pointsToPixels;
1598
- switch (alignment) {
1599
- case "center":
1600
- targetScrollTop = targetTop - (viewport.innerHeight - targetHeight) / 2;
1601
- break;
1602
- case "bottom":
1603
- targetScrollTop = targetTop - viewport.innerHeight + targetHeight;
1604
- break;
1605
- case "nearest": {
1606
- const currentTop = scrollArea.scrollTop;
1607
- const currentBottom = currentTop + viewport.innerHeight;
1608
- const targetBottom = targetTop + targetHeight;
1609
- if (targetTop >= currentTop && targetBottom <= currentBottom) {
1610
- // Already fully visible - don't scroll
1611
- targetScrollTop = currentTop;
1612
- }
1613
- else if (targetTop < currentTop) {
1614
- // Target is above viewport - align to top
1615
- targetScrollTop = targetTop;
1616
- }
1617
- else {
1618
- // Target is below viewport - align to bottom
1619
- targetScrollTop = targetBottom - viewport.innerHeight;
1620
- }
1621
- break;
1622
- }
1623
- case "top":
1624
- default:
1625
- targetScrollTop = targetTop;
1626
- break;
1627
- }
1628
- if (target.scrollTo.x !== undefined) {
1629
- const xInPixels = target.scrollTo.x * pointsToPixels;
1630
- // Center the x position in viewport if possible
1631
- targetScrollLeft = Math.max(0, xInPixels - viewport.innerWidth / 2);
1632
- }
1633
- }
1634
- else {
1635
- // No specific scroll position - scroll to top of spread with spacing
1636
- const snappedSpreadSpacing = snapToDevice(slice.spreadSpacing);
1637
- targetScrollTop = layout.top - snappedSpreadSpacing;
1638
- }
1639
- const maxScrollTop = Math.max(0, containerSize.height - viewport.innerHeight);
1640
- const maxScrollLeft = Math.max(0, containerSize.width - viewport.innerWidth);
1641
- scrollArea.scrollTop = clamp(targetScrollTop, 0, maxScrollTop);
1642
- scrollArea.scrollLeft = clamp(targetScrollLeft, 0, maxScrollLeft);
1643
- }
1644
- function clearSpreads() {
1645
- cleanupTransition();
1646
- for (const spread of spreadComponents.values()) {
1647
- spread.destroy();
1648
- }
1649
- spreadComponents.clear();
1650
- lastOverflowX = null;
1651
- lastOverflowY = null;
1652
- previousSpreadIndex = null;
1653
- }
1654
- function destroy() {
1655
- clearActiveSlideAnimation();
1656
- forgetSlideAnimations();
1657
- if (unsubRender)
1658
- unsubRender();
1659
- if (unsubScroll)
1660
- unsubScroll();
1661
- if (unsubNavigation)
1662
- unsubNavigation();
1663
- if (unsubSearch)
1664
- unsubSearch();
1665
- if (resizeObserver)
1666
- resizeObserver.disconnect();
1667
- for (const off of unsubEvents)
1668
- off();
1669
- if (updateRaf)
1670
- cancelAnimationFrame(updateRaf);
1671
- if (scrollRaf)
1672
- cancelAnimationFrame(scrollRaf);
1673
- if (renderDebounceTimer)
1674
- clearTimeout(renderDebounceTimer);
1675
- if (branding)
1676
- branding.destroy();
1677
- if (viewToolController)
1678
- viewToolController.destroy();
1679
- viewToolController = null;
1680
- if (annotationDrawController)
1681
- annotationDrawController.destroy();
1682
- annotationDrawController = null;
1683
- if (annotationSelectController)
1684
- annotationSelectController.destroy();
1685
- annotationSelectController = null;
1686
- floatingToolbar.destroy();
1687
- clearSpreads();
1688
- workerClient = null;
1689
- storeRef = null;
1690
- currentSlice = null;
1691
- lastSlice = null;
1692
- layoutState = null;
1693
- el.remove();
1694
- }
1695
- return { el, mount, destroy };
1696
- }
1697
- function selectViewport(state) {
1698
- return {
1699
- docId: state.doc?.id ?? null,
1700
- page: state.page,
1701
- pageCount: state.pageCount,
1702
- pageInfos: state.pageInfos,
1703
- pageGroups: state.pageGroups,
1704
- activeGroupIndex: state.activeGroupIndex,
1705
- viewMode: state.viewMode,
1706
- scrollMode: state.scrollMode,
1707
- layoutMode: state.layoutMode,
1708
- zoomMode: state.zoomMode,
1709
- zoom: state.zoom,
1710
- dpi: state.dpi,
1711
- pageRotation: state.pageRotation,
1712
- spacingMode: state.spacingMode,
1713
- pageSpacing: state.pageSpacing,
1714
- spreadSpacing: state.spreadSpacing,
1715
- pageAnnotations: state.pageAnnotations,
1716
- highlightedAnnotation: state.highlightedAnnotation,
1717
- pageText: state.pageText,
1718
- zoomAnchor: state.zoomAnchor,
1719
- };
1720
- }
1721
- //# sourceMappingURL=Viewport.js.map