@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
package/README.md CHANGED
@@ -1,1249 +1,52 @@
1
1
  # @docmentis/udoc-viewer
2
2
 
3
- Universal document viewer for the web.
3
+ **A full-featured, embeddable document viewer for the web.**
4
4
 
5
- Open-source, framework-agnostic viewer powered by a built-from-scratch WebAssembly engine for high-fidelity rendering across PDF, DOCX, PPTX, XLSX, CSV, SVG, and images.
5
+ Bring PDF, Word, PowerPoint, Excel, SVG, images, and other documents directly into your application with a consistent viewing experience. Built on the docMentis document engine, udoc-viewer combines high-fidelity rendering with the tools people expect from a modern document viewer.
6
6
 
7
7
  [![npm version](https://img.shields.io/npm/v/@docmentis/udoc-viewer)](https://www.npmjs.com/package/@docmentis/udoc-viewer)
8
- [![license](https://img.shields.io/npm/l/@docmentis/udoc-viewer)](./LICENSE)
8
+ [![license](https://img.shields.io/npm/l/@docmentis/udoc-viewer)](https://github.com/docMentis/docmentis-udoc#open-source-packages-shared-runtime)
9
9
 
10
- **[Live Demo](https://docmentis.com/viewer/demo)** · **[Guide](https://docmentis.com/viewer/guide)** · **[Changelog](https://github.com/docmentis/docmentis-udoc-viewer/blob/main/CHANGELOG.md)** · **[Report Issue](https://github.com/docmentis/docmentis-udoc-viewer/issues)**
10
+ **[Live Demo](https://www.docmentis.com/viewer/demo)** · **[Docs](https://www.docmentis.com/docs)** · **[API Reference](https://www.docmentis.com/docs/api/udoc-viewer)** · **[Changelog](https://github.com/docMentis/docmentis-udoc/blob/main/CHANGELOG.md)** · **[Report Issue](https://github.com/docMentis/docmentis-udoc/issues)**
11
11
 
12
12
  ---
13
13
 
14
14
  ## Why udoc-viewer?
15
15
 
16
- Most web document viewers only handle PDF, rely on server-side rendering, or require expensive commercial licenses. udoc-viewer is different:
16
+ - **One viewer for many formats.** Display PDF, DOCX, PPTX, XLSX, and other supported document and image formats without switching components.
17
+ - **Complete viewing experience.** Navigation, zoom, thumbnails, outlines, search, printing, and downloading, with annotation and comment capabilities.
18
+ - **Embeddable and customizable.** Integrate with your framework of choice, or with plain JavaScript, and customize the interface to fit your application.
19
+ - **Client-side document rendering.** View documents in the browser without requiring server-side document conversion.
17
20
 
18
- - **Truly universal** — PDF, Word, PowerPoint, Excel, CSV, SVG, and images in a single viewer, with more formats coming
19
- - **High fidelity** — powered by a custom Rust/WebAssembly rendering engine, not PDF.js
20
- - **Client-side only** — everything runs in the browser, no server round-trips
21
- - **Framework agnostic** — works with React, Vue, Angular, Svelte, or plain HTML
22
- - **Free for commercial use** — MIT-licensed wrapper, free WASM engine
21
+ ## Quick start
23
22
 
24
- ## Supported Formats
25
-
26
- | Format | Extensions |
27
- | ------ | ------------------------------------------------------------------------------------------------- |
28
- | PDF | .pdf |
29
- | DOCX | .docx |
30
- | PPTX | .pptx |
31
- | XLSX | .xlsx |
32
- | CSV | .csv |
33
- | Vector | .svg, .wmf, .emf |
34
- | Images | .png, .jpg, .jpeg, .gif, .webp, .bmp, .tif, .tiff, .ico, .tga, .ppm, .pgm, .pbm, .hdr, .exr, .qoi |
35
-
36
- ## Quick Start
37
-
38
- ### Install
39
-
40
- ```bash
23
+ ```sh
41
24
  npm install @docmentis/udoc-viewer
42
25
  ```
43
26
 
44
- ### Basic Usage
45
-
46
- ```js
47
- import { UDocClient } from "@docmentis/udoc-viewer";
48
-
49
- // Create a client (loads the WASM engine)
50
- const client = await UDocClient.create();
51
-
52
- // Create a viewer attached to a container element
53
- const viewer = await client.createViewer({
54
- container: "#viewer",
55
- });
56
-
57
- // Load a document
58
- await viewer.load("https://example.com/document.pdf");
59
-
60
- // Clean up when done
61
- viewer.destroy();
62
- client.destroy();
63
- ```
64
-
65
- ### HTML
27
+ Give the viewer a container with a height:
66
28
 
67
29
  ```html
68
- <div id="viewer" style="width: 100%; height: 600px;"></div>
69
-
70
- <script type="module">
71
- import { UDocClient } from "@docmentis/udoc-viewer";
72
-
73
- const client = await UDocClient.create();
74
- const viewer = await client.createViewer({ container: "#viewer" });
75
- await viewer.load("/path/to/document.pdf");
76
- </script>
77
- ```
78
-
79
- ### React
80
-
81
- ```jsx
82
- import { useEffect, useRef } from "react";
83
- import { UDocClient } from "@docmentis/udoc-viewer";
84
-
85
- function DocumentViewer({ src }) {
86
- const containerRef = useRef(null);
87
-
88
- useEffect(() => {
89
- let client, viewer;
90
-
91
- (async () => {
92
- client = await UDocClient.create();
93
- viewer = await client.createViewer({
94
- container: containerRef.current,
95
- });
96
- await viewer.load(src);
97
- })();
98
-
99
- return () => {
100
- viewer?.destroy();
101
- client?.destroy();
102
- };
103
- }, [src]);
104
-
105
- return <div ref={containerRef} style={{ width: "100%", height: "600px" }} />;
106
- }
107
- ```
108
-
109
- ## Examples
110
-
111
- Full working examples for every major framework are in the [`examples/`](../../examples/) directory:
112
-
113
- | Example | Stack |
114
- | ---------------------------------------------------- | ------------------- |
115
- | [vanilla](../../examples/vanilla/) | TypeScript + Vite |
116
- | [react-vite](../../examples/react-vite/) | React + Vite |
117
- | [vue-vite](../../examples/vue-vite/) | Vue + Vite |
118
- | [svelte-vite](../../examples/svelte-vite/) | Svelte 5 + Vite |
119
- | [angular](../../examples/angular/) | Angular 19 |
120
- | [nextjs-webpack](../../examples/nextjs-webpack/) | Next.js + Webpack |
121
- | [nextjs-turbopack](../../examples/nextjs-turbopack/) | Next.js + Turbopack |
122
- | [nuxt](../../examples/nuxt/) | Nuxt 3 |
123
-
124
- ## Features
125
-
126
- - 📄 **Multi-format rendering** — PDF, DOCX, PPTX, XLSX, CSV, SVG, and images in one unified viewer
127
- - 🎯 **High-fidelity output** — custom Rust rendering engine compiled to WebAssembly
128
- - 🔍 **Zoom & navigation** — toolbar with zoom controls, page thumbnails, and keyboard navigation
129
- - 🔎 **Full-text search** — search with match highlighting, navigation, and fuzzy matching for AI citations
130
- - 🌓 **Dark mode** — built-in light/dark theme with system preference support
131
- - 🎨 **Customizable** — override colors and styles via CSS variables
132
- - 📱 **Responsive** — works on desktop and mobile browsers
133
- - 🌊 **Streaming** — pages render progressively as the document loads
134
- - 🔒 **Private** — documents never leave the browser; no server upload required
135
-
136
- ## API Reference
137
-
138
- ### Client Options
139
-
140
- ```typescript
141
- const client = await UDocClient.create({
142
- // License key for commercial use (optional)
143
- // Enables licensed features such as hiding the attribution link
144
- license: "eyJ2Ijox...",
145
-
146
- // Custom base URL for worker and WASM files (optional)
147
- // Expected files: {baseUrl}/worker.js and {baseUrl}/udoc_bg.wasm
148
- baseUrl: "https://cdn.example.com/udoc/",
149
-
150
- // Disable anonymous telemetry reporting (default: false)
151
- // Requires a valid license with the "no_telemetry" feature
152
- disableTelemetry: false,
153
-
154
- // Disable checking npm registry for a newer version on startup (default: false)
155
- // When enabled (default), a background check logs a console reminder if a newer version is available
156
- // Never blocks initialization
157
- disableUpdateCheck: false,
158
-
159
- // Enable Google Fonts for automatic font fetching (default: true)
160
- // When enabled, missing fonts are fetched from Google Fonts on-demand during rendering
161
- googleFonts: true,
162
-
163
- // Register custom font URLs for on-demand fetching during layout (optional)
164
- // Supports OTF, TTF, WOFF, and WOFF2 formats
165
- // Registered fonts take priority over Google Fonts
166
- fonts: [
167
- { typeface: "Roboto", bold: false, italic: false, url: "https://cdn.example.com/Roboto-Regular.woff2" },
168
- { typeface: "Roboto", bold: true, italic: false, url: "https://cdn.example.com/Roboto-Bold.woff2" },
169
- { typeface: "Roboto", bold: false, italic: true, url: "https://cdn.example.com/Roboto-Italic.woff2" },
170
- { typeface: "Roboto", bold: true, italic: true, url: "https://cdn.example.com/Roboto-BoldItalic.woff2" },
171
- ],
172
- });
173
- ```
174
-
175
- ### Viewer Options
176
-
177
- ```typescript
178
- const viewer = await client.createViewer({
179
- // Container element or CSS selector (required for UI mode, omit for headless)
180
- container: "#viewer",
181
-
182
- // --- View modes ---
183
-
184
- // Scroll mode: 'continuous' or 'spread' (default: 'continuous')
185
- scrollMode: "continuous",
186
-
187
- // Layout mode: 'single-page', 'double-page', 'double-page-odd-right', 'double-page-odd-left'
188
- // (default: 'single-page')
189
- layoutMode: "single-page",
190
-
191
- // Initial page rotation: 0, 90, 180, or 270 (default: 0)
192
- pageRotation: 0,
193
-
194
- // Spacing mode: 'all', 'none', 'spread-only', 'page-only' (default: 'all')
195
- spacingMode: "all",
196
-
197
- // --- Zoom ---
198
-
199
- // Zoom mode: 'fit-spread-width', 'fit-spread-width-max', 'fit-spread-height', 'fit-spread', 'custom'
200
- // (default: 'fit-spread-width')
201
- zoomMode: "fit-spread-width",
202
-
203
- // Initial zoom level (when zoomMode is 'custom', default: 1)
204
- zoom: 1,
205
-
206
- // Custom zoom steps for zoom in/out
207
- // (default: [0.1, 0.25, 0.5, 0.75, 1, 1.25, 1.5, 2, 3, 4, 5])
208
- zoomSteps: [0.1, 0.25, 0.5, 0.75, 1, 1.25, 1.5, 2, 3, 4, 5],
209
-
210
- // Zoom range limits (default: 0.1 and 5)
211
- minZoom: 0.1,
212
- maxZoom: 5,
213
-
214
- // --- Scroll alignment ---
215
-
216
- // Default scroll alignment for navigation (outline, links, goToDestination)
217
- // 'top' | 'center' | 'bottom' | 'nearest' (default: 'top')
218
- navigationScrollAlignment: "top",
219
-
220
- // Default scroll alignment for search result navigation
221
- // 'top' | 'center' | 'bottom' | 'nearest' (default: 'center')
222
- searchScrollAlignment: "center",
223
-
224
- // --- Spacing & layout ---
225
-
226
- // Spacing between pages in pixels (default: 10)
227
- pageSpacing: 10,
228
-
229
- // Spacing between spreads in pixels (default: 20)
230
- spreadSpacing: 20,
231
-
232
- // Width of thumbnail images in pixels (default: 150)
233
- // Height is derived automatically from the page aspect ratio
234
- thumbnailWidth: 150,
235
-
236
- // Target display DPI (default: 96)
237
- dpi: 96,
238
-
239
- // --- Theme ---
240
-
241
- // Color theme: 'light', 'dark', or 'system' (default: 'light')
242
- theme: "light",
243
-
244
- // Hide the theme toggle button (default: false)
245
- disableThemeSwitching: false,
246
-
247
- // --- Features ---
248
-
249
- // Disable text selection and copying (default: false)
250
- disableTextSelection: false,
251
-
252
- // --- Panels ---
253
-
254
- // Initially active panel, or null for no panel (default: null)
255
- // Left panels: 'thumbnail', 'outline', 'bookmarks', 'layers', 'attachments'
256
- // Right panels: 'search', 'comments'
257
- activePanel: null,
258
-
259
- // Disable individual panel tabs (all default to false)
260
- disableLeftPanel: false, // Disable the entire left panel area
261
- disableRightPanel: false, // Disable the entire right panel area
262
- disableThumbnails: false, // Disable the thumbnails tab
263
- disableOutline: false, // Disable the outline tab
264
- disableBookmarks: false, // Disable the bookmarks tab
265
- disableLayers: false, // Disable the layers tab
266
- disableAttachments: false, // Disable the attachments tab
267
- disableSearch: false, // Disable the search panel
268
- disableComments: false, // Disable the comments panel
269
-
270
- // --- UI visibility ---
271
-
272
- // Hide the top toolbar (default: false)
273
- hideToolbar: false,
274
-
275
- // Hide the floating toolbar (page nav, zoom, view mode) (default: false)
276
- hideFloatingToolbar: false,
277
-
278
- // Remove the fullscreen button (default: false)
279
- disableFullscreen: false,
280
-
281
- // --- Advanced ---
282
-
283
- // Enable performance tracking (default: false)
284
- enablePerformanceCounter: false,
285
-
286
- // Callback for performance log entries (called when enablePerformanceCounter is true)
287
- onPerformanceLog: (entry) => console.log(entry),
288
-
289
- // Hide the "Powered by docMentis" attribution link (default: false)
290
- // Requires a valid license with the "no_attribution" feature
291
- hideAttribution: true,
292
-
293
- // Hide the loading overlay shown during document download and processing (default: false)
294
- // Requires a valid license with the "no_attribution" feature
295
- hideLoadingOverlay: true,
296
-
297
- // --- Custom UI extension ---
298
-
299
- // Render host UI (buttons, floating toolbars, badges) on top of each page.
300
- // Called once per page slot; return an optional cleanup. See "Custom Page Overlay" below.
301
- // `scale` is CSS pixels per PDF point at the current zoom.
302
- customPageOverlay: (pageIndex, container, scale) => {
303
- // append elements with pointer-events: auto to receive input
304
- return () => {
305
- /* cleanup on slot destroy */
306
- };
307
- },
308
- });
309
- ```
310
-
311
- ### Loading Documents
312
-
313
- The viewer accepts multiple document sources:
314
-
315
- ```typescript
316
- // From URL
317
- await viewer.load("https://example.com/document.pdf");
318
-
319
- // From File object (e.g., from file input)
320
- await viewer.load(file);
321
-
322
- // From raw bytes
323
- await viewer.load(new Uint8Array(buffer));
324
-
325
- // Close current document
326
- viewer.close();
327
- ```
328
-
329
- The format of PDF, Word, PowerPoint, Excel and image files is detected from their contents. CSV has no signature to detect, so the viewer recognises it from the file name or URL ending in `.csv`, the `filename` option, a `text/csv` file type or `Content-Type` response header, or the file name in a `Content-Disposition` response header. When none of those apply (for example raw bytes, or a download link without an extension), name the format explicitly:
330
-
331
- ```typescript
332
- await viewer.load(bytes, { format: "csv" });
333
-
334
- // or give it a name, which is also the default for download()
335
- await viewer.load(bytes, { filename: "export.csv" });
336
- ```
337
-
338
- ### Navigation
339
-
340
- ```typescript
341
- // Get current page (1-based)
342
- const page = viewer.currentPage;
343
-
344
- // Go to a specific page (1-based)
345
- viewer.goToPage(5);
346
-
347
- // Navigate to next/previous page
348
- viewer.nextPage();
349
- viewer.previousPage();
350
-
351
- // Navigate to a destination (from outline)
352
- viewer.goToDestination(destination);
353
-
354
- // Navigate with scroll alignment override
355
- viewer.goToDestination(destination, { scrollAlignment: "center" });
356
-
357
- // Change default scroll alignment at runtime
358
- viewer.setNavigationScrollAlignment("center"); // 'top' | 'center' | 'bottom' | 'nearest'
359
- viewer.setSearchScrollAlignment("top");
360
- ```
361
-
362
- ### Document Information
363
-
364
- ```typescript
365
- // Check if document is loaded
366
- if (viewer.isLoaded) {
367
- // Get page count
368
- const total = viewer.pageCount;
369
-
370
- // Get document metadata
371
- const meta = viewer.metadata;
372
- console.log(meta?.title, meta?.author);
373
-
374
- // Get page dimensions (0-based index)
375
- const info = await viewer.getPageInfo(0);
376
- console.log(`Page 1: ${info.width} x ${info.height} points`);
377
-
378
- // Get document outline (table of contents)
379
- const outline = await viewer.getOutline();
380
-
381
- // Get annotations on a page (0-based index)
382
- const annotations = await viewer.getPageAnnotations(0);
383
-
384
- // Get plain text of a page (matches what search indexes)
385
- const text = await viewer.getPageText(0);
386
- }
387
- ```
388
-
389
- ### Extracting Page Text
390
-
391
- `getPageText(page)` returns the flat text of a page exactly as the search
392
- engine sees it. Glyph runs are concatenated in visual order; spaces and tabs
393
- become `" "`, line breaks and paragraph ends become `"\n"`, and inline
394
- drawings become `"\uFFFC"` (object replacement character). Works uniformly
395
- across PDF, DOCX, PPTX, XLSX, and CSV.
396
-
397
- ```typescript
398
- // Extract text from a single page (0-based index)
399
- const pageText = await viewer.getPageText(0);
400
-
401
- // Extract the full document
402
- const pages: string[] = [];
403
- for (let i = 0; i < viewer.pageCount; i++) {
404
- pages.push(await viewer.getPageText(i));
405
- }
406
- const fullText = pages.join("\n\n");
407
- ```
408
-
409
- ### Annotations
410
-
411
- Read, create, modify, and delete annotations on PDF documents. Each annotation has a stable `name` (the PDF NM identifier) that survives save/reload, so you can use it as a foreign key from your own data store.
412
-
413
- **Read.** `getPageAnnotations` returns every annotation on a page — including any in-memory edits and ephemeral overlays — so a single call always reflects what the user is currently seeing.
414
-
415
- ```typescript
416
- const annotations = await viewer.getPageAnnotations(0); // 0-based page index
417
-
418
- for (const a of annotations) {
419
- console.log(a.type, a.name, a.bounds, a.metadata?.author);
420
- }
421
- ```
422
-
423
- **Add.** Pass any `Annotation` shape (highlight, underline, ink, freeText, square, etc.) along with a `bounds` rectangle in PDF points. If `name` is omitted the viewer assigns a UUID and returns it on the resolved annotation, so you can keep referencing the new annotation immediately.
424
-
425
- ```typescript
426
- const created = await viewer.addPageAnnotation(0, {
427
- type: "highlight",
428
- bounds: { x: 100, y: 700, width: 200, height: 20 },
429
- quads: [
430
- {
431
- points: [
432
- { x: 100, y: 700 },
433
- { x: 300, y: 700 },
434
- { x: 300, y: 720 },
435
- { x: 100, y: 720 },
436
- ],
437
- },
438
- ],
439
- color: { r: 1, g: 1, b: 0 },
440
- metadata: { author: "Alice", contents: "Important" },
441
- });
442
-
443
- console.log(created.name); // generated UUID, stable across save/reload
444
- ```
445
-
446
- **Add many at once.** `addPageAnnotations` inserts a batch on a single page in one store update — one render and one dirty-page flip instead of N. Use it when importing or restoring annotations. The `annotation:add` event still fires once per annotation in input order, so existing listeners just work.
447
-
448
- ```typescript
449
- const inserted = await viewer.addPageAnnotations(0, [
450
- { type: "highlight", bounds: { x: 100, y: 700, width: 200, height: 20 }, color: { r: 1, g: 1, b: 0 } },
451
- { type: "underline", bounds: { x: 100, y: 680, width: 200, height: 2 }, color: { r: 0, g: 0, b: 1 } },
452
- ]);
453
-
454
- console.log(inserted.map((a) => a.name)); // generated UUIDs
455
- ```
456
-
457
- **Update / remove.** Both are keyed by `name`. `updatePageAnnotation` replaces the whole annotation but preserves the `name` even if you accidentally pass a different one in the body.
458
-
459
- ```typescript
460
- await viewer.updatePageAnnotation(0, created.name, {
461
- ...created,
462
- color: { r: 0, g: 1, b: 0 },
463
- metadata: { ...created.metadata, contents: "Reviewed" },
464
- });
465
-
466
- await viewer.removePageAnnotation(0, created.name);
467
- ```
468
-
469
- **Patch.** When you only want to change a few fields (a highlight's color, a markup's contents), `patchPageAnnotation` merges the patch into the existing annotation — everything you don't mention stays untouched. `type` and `name` in the patch are ignored, `metadata` is shallow-merged one level, and `undefined` values are skipped (use `updatePageAnnotation` if you need to clear a field by omission).
470
-
471
- ```typescript
472
- await viewer.patchPageAnnotation(0, created.name, {
473
- color: { r: 0, g: 1, b: 0 },
474
- metadata: { contents: "Reviewed" }, // keeps existing author/subject
475
- });
476
- ```
477
-
478
- **Batch update / patch.** `updatePageAnnotations` and `patchPageAnnotations` apply many changes to one page in a single store update — one render and one dirty-page flip instead of N. `annotation:update` still fires once per entry in input order. Validation is atomic: if any `name` is missing on the page the call throws before any change is applied.
479
-
480
- ```typescript
481
- await viewer.patchPageAnnotations(0, [
482
- { name: a.name, patch: { color: { r: 1, g: 0, b: 0 } } },
483
- { name: b.name, patch: { opacity: 0.5 } },
484
- ]);
485
- ```
486
-
487
- **Save.** PDF write-back happens automatically on `toBytes()` and `download()` whenever there are pending edits — there is no separate save call.
488
-
489
- ```typescript
490
- const bytes = await viewer.toBytes(); // pending edits flushed into the returned PDF
491
- await viewer.download("annotated.pdf");
492
- ```
493
-
494
- **Ephemeral annotations.** Pass `ephemeral: true` to create a viewer-only annotation. Ephemeral annotations render in the canvas like any other, but are excluded from saved PDF bytes and from print output. Use them for live cursors, preview shapes, or transient review markers that shouldn't survive a reload.
495
-
496
- ```typescript
497
- const cursor = await viewer.addPageAnnotation(0, {
498
- type: "square",
499
- bounds: { x: 50, y: 50, width: 30, height: 30 },
500
- color: { r: 1, g: 0, b: 0 },
501
- ephemeral: true, // not written on save, not printed
502
- });
503
-
504
- // Promote an ephemeral preview into a saved annotation:
505
- await viewer.updatePageAnnotation(0, cursor.name, { ...cursor, ephemeral: false });
506
- ```
507
-
508
- **Events.** The four lifecycle events (`add` / `update` / `remove` / `select`) fire for both UI-driven changes (drawing/markup tools) and API-driven changes, so a single listener covers both. `hover` and `click` are pointer-driven and fire in any tool mode, including normal viewing.
509
-
510
- ```typescript
511
- viewer.on("annotation:add", ({ pageIndex, annotation }) => {
512
- if (annotation.ephemeral) return;
513
- syncToBackend({ kind: "create", pageIndex, annotation });
514
- });
515
-
516
- viewer.on("annotation:update", ({ pageIndex, annotation }) => {
517
- syncToBackend({ kind: "update", pageIndex, annotation });
518
- });
519
-
520
- viewer.on("annotation:remove", ({ pageIndex, annotation }) => {
521
- syncToBackend({ kind: "delete", pageIndex, name: annotation.name });
522
- });
523
-
524
- viewer.on("annotation:select", (selection) => {
525
- if (!selection) return; // null = deselect
526
- showInspector(selection.annotation);
527
- });
528
-
529
- // Pointer hover — fires when the pointer enters/leaves an annotation in any
530
- // tool mode. Deduped to only fire on actual hover changes. Payload is null
531
- // when the pointer leaves the currently hovered annotation. `clientX`/
532
- // `clientY` are browser-viewport coordinates at the moment of the hover
533
- // change (rotation- and zoom-invariant; use directly for screen-space
534
- // tooltip placement).
535
- viewer.on("annotation:hover", (hover) => {
536
- if (!hover) return hideTooltip();
537
- showTooltip(hover.annotation, { x: hover.clientX, y: hover.clientY });
538
- });
539
-
540
- // Pointer click — fires for any annotation click, regardless of active tool,
541
- // and before built-in handling (link navigation, sticky-note popups). `clientX`/
542
- // `clientY` are browser-viewport coordinates at the click (use directly to
543
- // anchor a context menu or popover in screen space).
544
- viewer.on("annotation:click", ({ pageIndex, annotation, clientX, clientY }) => {
545
- console.log("clicked", annotation.subtype, "on page", pageIndex, "at", clientX, clientY);
546
- });
547
- ```
548
-
549
- > Annotation editing currently requires UI mode (a `container` was passed to `createViewer`) and is supported on PDF documents only.
550
-
551
- ### Programmatic Viewer Control
552
-
553
- Control zoom, view modes, and fullscreen programmatically — useful when toolbars are hidden:
554
-
555
- ```typescript
556
- // Zoom
557
- viewer.zoomIn();
558
- viewer.zoomOut();
559
- viewer.setZoom(1.5); // 150%
560
- viewer.setZoomMode("fit-spread-width");
561
- viewer.setMinZoom(0.5); // clamp minimum to 50%
562
- viewer.setMaxZoom(3); // clamp maximum to 300%
563
- console.log(viewer.zoom); // current zoom level
564
- console.log(viewer.zoomMode); // current zoom mode
565
-
566
- // View modes
567
- viewer.setScrollMode("continuous"); // 'continuous' | 'spread'
568
- viewer.setLayoutMode("double-page"); // 'single-page' | 'double-page' | ...
569
- viewer.setPageRotation(90); // 0 | 90 | 180 | 270
570
- viewer.setSpacingMode("none"); // 'all' | 'none' | 'spread-only' | 'page-only'
571
-
572
- // Theme
573
- viewer.setTheme("dark"); // 'light' | 'dark' | 'system'
574
- viewer.setThemeSwitchingEnabled(false); // hide theme toggle button
575
- console.log(viewer.theme); // current theme
576
-
577
- // Text selection
578
- viewer.setTextSelectionEnabled(false); // disable text selection
579
-
580
- // Fullscreen
581
- viewer.setFullscreen(true);
582
- console.log(viewer.isFullscreen);
583
- ```
584
-
585
- ### Tools
586
-
587
- Switch the active tool programmatically. The active tool is a tagged union: simple tools (`pointer`, `hand`, `zoom`) carry no sub-tool, while tool sets (`annotate`, `markup`) carry a `sub` for the active sub-tool.
588
-
589
- ```typescript
590
- // Simple tools
591
- viewer.setActiveTool({ kind: "pointer" });
592
- viewer.setActiveTool({ kind: "hand" });
593
- viewer.setActiveTool({ kind: "zoom" });
594
-
595
- // Tool sets — sub-tool is required
596
- viewer.setActiveTool({ kind: "annotate", sub: "freehand" });
597
- viewer.setActiveTool({ kind: "annotate", sub: "rectangle" });
598
- viewer.setActiveTool({ kind: "markup", sub: "highlight" });
599
-
600
- // Calling with the same tool-set kind that's already active toggles back to pointer
601
-
602
- // Read current tool
603
- const t = viewer.activeTool;
604
- if (t.kind === "annotate") {
605
- console.log("annotating with", t.sub); // "freehand" | "rectangle" | ...
606
- }
607
- ```
608
-
609
- `AnnotateSubTool`: `select`, `freehand`, `line`, `arrow`, `rectangle`, `ellipse`, `polygon`, `polyline`.
610
- `MarkupSubTool`: `select`, `highlight`, `underline`, `strikethrough`, `squiggly`.
611
-
612
- ### UI Visibility Control
613
-
614
- Show, hide, or disable UI components at runtime:
615
-
616
- ```typescript
617
- // Toolbar visibility
618
- viewer.setToolbarVisible(false);
619
- viewer.setFloatingToolbarVisible(false);
620
-
621
- // Fullscreen button
622
- viewer.setFullscreenEnabled(false);
623
-
624
- // Disable entire panel areas
625
- viewer.setLeftPanelEnabled(false);
626
- viewer.setRightPanelEnabled(false);
627
-
628
- // Disable individual panel tabs
629
- // Panels: 'thumbnail', 'outline', 'bookmarks', 'layers', 'attachments', 'search', 'comments'
630
- viewer.setPanelEnabled("thumbnail", false);
631
- viewer.setPanelEnabled("search", false);
632
-
633
- // Open/close panels programmatically
634
- viewer.openPanel("outline");
635
- viewer.closePanel();
636
- ```
637
-
638
- ### Programmatic Search
639
-
640
- Search document text programmatically. Works with or without the built-in search panel — ideal for building custom search UIs. Highlight overlays are rendered automatically on matching pages.
641
-
642
- ```typescript
643
- // Search and await results (returns Promise<SearchMatch[]>)
644
- const matches = await viewer.search("hello world");
645
- console.log(`Found ${matches.length} matches`);
646
-
647
- // Search with options
648
- const matches = await viewer.search("hello", { caseSensitive: true });
649
-
650
- // Fuzzy matching — strips all whitespace, control characters, pipes (|),
651
- // and zero-width characters from both the query and document text before
652
- // comparison. Designed for AI-generated citations where spacing or
653
- // separators may differ from the original document text.
654
- const matches = await viewer.search("cell A | cell B", { fuzzy: true });
655
-
656
- // Restrict search to a page range (inclusive, 0-based).
657
- // Both text loading and match collection are limited to the range —
658
- // useful for large documents when only a subset is of interest.
659
- const matches = await viewer.search("invoice", { pageRange: [10, 20] });
660
-
661
- // Each search() call is self-contained: the range is reset unless
662
- // explicitly provided, so a prior scoped search can't leak into a
663
- // later broad one.
664
- await viewer.search("invoice", { pageRange: [10, 20] }); // pages 10-20
665
- await viewer.search("payment"); // whole doc
666
-
667
- // Note: the built-in search panel always searches the entire document.
668
- // pageRange is only honored when calling the API directly.
669
-
670
- // Each match contains location, highlight rects, and context snippet
671
- for (const match of matches) {
672
- console.log(`Page ${match.pageIndex + 1}: "${match.context[1]}"`);
673
- console.log(` Before: "${match.context[0]}", After: "${match.context[2]}"`);
674
- console.log(` Rects:`, match.rects); // bounding boxes in PDF points
675
- }
676
-
677
- // Navigate between matches (scrolls viewport to match)
678
- viewer.searchNext();
679
- viewer.searchPrev();
680
-
681
- // Navigate with a per-call scroll alignment override
682
- viewer.searchNext({ scrollAlignment: "center" });
683
- viewer.searchPrev({ scrollAlignment: "top" });
684
-
685
- // Jump to a specific match by index
686
- viewer.setSearchActiveIndex(5);
687
- viewer.setSearchActiveIndex(5, { scrollAlignment: "center" });
688
-
689
- // Read current state
690
- console.log(viewer.searchMatches); // SearchMatch[]
691
- console.log(viewer.searchActiveIndex); // number (-1 if none)
692
-
693
- // Listen for incremental updates (fires as pages load and on navigation)
694
- viewer.on("search:change", ({ matches, activeIndex }) => {
695
- updateMySearchUI(matches, activeIndex);
696
- });
697
-
698
- // Clear search
699
- viewer.clearSearch();
700
- ```
701
-
702
- #### Custom Search UI Example
703
-
704
- Disable the built-in search panel and build your own:
705
-
706
- ```typescript
707
- const viewer = await client.createViewer({
708
- container: "#viewer",
709
- disableSearch: true, // hide built-in search panel
710
- });
711
-
712
- await viewer.load("document.pdf");
713
-
714
- // Wire up your own search input
715
- searchInput.addEventListener("input", async () => {
716
- const matches = await viewer.search(searchInput.value);
717
- renderResultsList(matches); // your custom UI
718
- });
719
-
720
- // Wire up next/prev buttons
721
- nextBtn.addEventListener("click", () => viewer.searchNext());
722
- prevBtn.addEventListener("click", () => viewer.searchPrev());
723
- ```
724
-
725
- ### CSS Customization
726
-
727
- The viewer uses CSS custom properties (variables) for all colors, shadows, and borders. Since no Shadow DOM is used, you can override any variable from your own stylesheet:
728
-
729
- ```css
730
- /* Override the primary color */
731
- .udoc-viewer-root {
732
- --udoc-primary: #e91e63;
733
- --udoc-primary-hover: #c2185b;
734
- }
735
-
736
- /* Override dark theme colors */
737
- .udoc-viewer-root.udoc-viewer-dark {
738
- --udoc-primary: #f48fb1;
739
- --udoc-primary-hover: #f06292;
740
- }
741
- ```
742
-
743
- #### Available CSS Variables
744
-
745
- | Variable | Description | Light Default | Dark Default |
746
- | -------------------------------- | ---------------------- | ----------------------------- | ---------------------------- |
747
- | **Backgrounds** | | | |
748
- | `--udoc-bg-viewport` | Viewport background | `#e0e0e0` | `#1a1a1a` |
749
- | `--udoc-bg-surface` | Page / card surface | `#fff` | `#2d2d2d` |
750
- | `--udoc-bg-panel` | Side panel background | `#f5f5f5` | `#252525` |
751
- | `--udoc-bg-panel-tabs` | Panel tab bar | `#e8e8e8` | `#1e1e1e` |
752
- | `--udoc-bg-input` | Input fields | `#fff` | `#3a3a3a` |
753
- | `--udoc-bg-overlay` | Modal overlay | `rgba(0,0,0,0.5)` | `rgba(0,0,0,0.7)` |
754
- | **Text** | | | |
755
- | `--udoc-text-primary` | Primary text | `rgba(0,0,0,0.8)` | `rgba(255,255,255,0.87)` |
756
- | `--udoc-text-secondary` | Secondary text | `rgba(0,0,0,0.7)` | `rgba(255,255,255,0.7)` |
757
- | `--udoc-text-muted` | Muted text | `rgba(0,0,0,0.5)` | `rgba(255,255,255,0.5)` |
758
- | `--udoc-text-disabled` | Disabled text | `rgba(0,0,0,0.25)` | `rgba(255,255,255,0.25)` |
759
- | `--udoc-text-placeholder` | Placeholder text | `#999` | `#777` |
760
- | `--udoc-text-on-primary` | Text on primary color | `#fff` | `#fff` |
761
- | **Primary color** | | | |
762
- | `--udoc-primary` | Primary / accent color | `#0066cc` | `#4da6ff` |
763
- | `--udoc-primary-hover` | Primary hover state | `#0052a3` | `#80bfff` |
764
- | `--udoc-primary-focus-ring` | Focus ring color | `rgba(0,102,204,0.2)` | `rgba(77,166,255,0.25)` |
765
- | **Borders** | | | |
766
- | `--udoc-border` | Default border | `#ddd` | `#444` |
767
- | `--udoc-border-input` | Input border | `#ccc` | `#555` |
768
- | `--udoc-border-light` | Light border | `#eee` | `#3a3a3a` |
769
- | **Shadows** | | | |
770
- | `--udoc-shadow-page` | Page shadow | `0 2px 8px rgba(0,0,0,0.15)` | `0 2px 8px rgba(0,0,0,0.4)` |
771
- | `--udoc-shadow-toolbar` | Toolbar shadow | `0 2px 12px rgba(0,0,0,0.15)` | `0 2px 12px rgba(0,0,0,0.4)` |
772
- | `--udoc-shadow-dropdown` | Dropdown shadow | `0 4px 16px rgba(0,0,0,0.2)` | `0 4px 16px rgba(0,0,0,0.5)` |
773
- | **Search** | | | |
774
- | `--udoc-search-highlight` | Search match highlight | `rgba(255,200,0,0.35)` | `rgba(255,200,0,0.4)` |
775
- | `--udoc-search-highlight-active` | Active match highlight | `rgba(255,140,0,0.6)` | `rgba(255,140,0,0.65)` |
776
- | **Selection** | | | |
777
- | `--udoc-text-selection` | Text selection color | `rgba(0,120,215,0.3)` | `rgba(77,166,255,0.35)` |
778
- | **Scrollbar** | | | |
779
- | `--udoc-scrollbar-thumb` | Scrollbar thumb | `rgba(0,0,0,0.3)` | `rgba(255,255,255,0.3)` |
780
- | `--udoc-scrollbar-thumb-hover` | Scrollbar thumb hover | `rgba(0,0,0,0.5)` | `rgba(255,255,255,0.5)` |
781
- | **Errors** | | | |
782
- | `--udoc-error-bg` | Error background | `#fef2f2` | `#3a1c1c` |
783
- | `--udoc-error-border` | Error border | `#fecaca` | `#6b2c2c` |
784
- | `--udoc-error-text` | Error text | `#dc2626` | `#f87171` |
785
- | **Progress** | | | |
786
- | `--udoc-progress-track` | Progress bar track | `#e5e7eb` | `#404040` |
787
- | `--udoc-progress-fill` | Progress bar fill | `#0066cc` | `#4da6ff` |
788
-
789
- > The full list of variables is defined in `src/ui/viewer/styles.css`. All viewer styles are scoped under `.udoc-viewer-root`, so your overrides won't leak into the rest of the page.
790
-
791
- ### Custom Page Overlay
792
-
793
- The viewer renders each page with a stack of layers: page canvas → text → annotations → search highlights. The **Custom Page Overlay** sits on top of all of them, giving you a dedicated, page-aligned surface for your own UI — comment buttons, side toolbars, status badges, signature placeholders, anything that should follow the page as it scrolls, zooms, and rotates.
794
-
795
- Provide a `customPageOverlay` renderer when creating the viewer. It is invoked once per page slot when the slot mounts (lazily, only for pages near the viewport in continuous mode) and may return a cleanup function that runs when the slot is destroyed.
796
-
797
- ```typescript
798
- const viewer = await client.createViewer({
799
- container: "#viewer",
800
- customPageOverlay: (pageIndex, container, scale) => {
801
- const btn = document.createElement("button");
802
- btn.textContent = "💬";
803
- btn.style.cssText = "position:absolute;top:8px;right:-40px;pointer-events:auto;cursor:pointer;";
804
- btn.onclick = () => openCommentDialog(pageIndex);
805
- container.appendChild(btn);
806
-
807
- // Optional: cleanup runs when the page scrolls out of view
808
- return () => btn.remove();
809
- },
810
- });
30
+ <div id="viewer" style="height: 600px"></div>
811
31
  ```
812
32
 
813
- **Arguments**
814
-
815
- | Argument | Type | Description |
816
- | ----------- | ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
817
- | `pageIndex` | `number` | 0-based page index (matches `getPageAnnotations`, `getPageText`, etc.). |
818
- | `container` | `HTMLElement` | The overlay layer. Sized to the page bounds, rotated with the page, positioned absolutely inside the page slot. Append your DOM here. |
819
- | `scale` | `number` | CSS pixels per PDF point at the current zoom. Use it to place elements at PDF-point coordinates: `pixelX = pointX * scale`. Ignore it for page-bounds-relative layout. |
820
-
821
- **Return value**
822
-
823
- Return a cleanup function (or `void` if you don't need cleanup). The cleanup runs when the slot is destroyed — for example when the page scrolls far out of view in continuous mode, when the document is closed, or when the viewer is destroyed. Use it to detach listeners, tear down React/Vue/Svelte roots, or remove externally-tracked state.
824
-
825
- **Positioning**
826
-
827
- - `container` is a child of `.udoc-spread__slot` and sized to the page's CSS bounds. Plain CSS (`position: absolute; top/right/bottom/left`) anchors elements relative to the page.
828
- - Elements placed _outside_ the container's bounds (e.g. `right: -40px` for a tab sticking out the right edge of the page) are clipped by `.udoc-spread__slot`'s `overflow: hidden`. If you need overflow, render into a sibling layer or use a portal at the viewport level.
829
- - The container rotates with the page. If your overlay should stay screen-aligned regardless of `pageRotation`, apply an inverse rotation to your children.
830
-
831
- **Pointer events**
832
-
833
- The container is `pointer-events: none` by default so it never blocks text selection or annotation clicks beneath it. Opt individual elements into input with `pointer-events: auto`.
834
-
835
- **Lifecycle notes**
836
-
837
- - The renderer is invoked **once** per slot mount. Subsequent zoom/rotation/scroll updates do not re-invoke it — the layer's CSS transform handles those automatically, so your buttons follow the page without effort.
838
- - If you need to react to zoom changes (e.g. to keep a button screen-sized while the page scales), attach a `ResizeObserver` to `container` inside the renderer.
839
- - For state that depends on the document (annotation counts, comment threads), subscribe to the relevant `viewer.on(...)` events from inside the renderer and unsubscribe in the cleanup.
840
-
841
- **Targeting the layer in CSS**
842
-
843
- The layer carries the class `udoc-spread__custom-page-overlay-layer` if you want to style your overlay container directly (e.g. set a `font-family`).
844
-
845
- ### Events
846
-
847
- ```typescript
848
- // Document loaded
849
- const unsubscribe = viewer.on("document:load", ({ pageCount }) => {
850
- console.log(`Loaded ${pageCount} pages`);
851
- });
852
-
853
- // Document closed
854
- viewer.on("document:close", () => {
855
- console.log("Document closed");
856
- });
857
-
858
- // Page changed
859
- viewer.on("page:change", ({ page, previousPage }) => {
860
- console.log(`Page ${previousPage} -> ${page}`);
861
- });
862
-
863
- // Viewport changed (scroll, zoom, layout, or scroll-mode change).
864
- // Throttled to one fire per animation frame and de-duped — adjacent
865
- // identical payloads are coalesced. Page indices are 0-based.
866
- viewer.on("viewport:change", ({ firstVisiblePage, lastVisiblePage, zoom, scrollTop }) => {
867
- console.log(`Visible: ${firstVisiblePage}–${lastVisiblePage} @ ${zoom}x, scrollTop=${scrollTop}`);
868
- });
869
-
870
- // Panel opened/closed
871
- viewer.on("panel:change", ({ panel, previousPanel }) => {
872
- console.log(`Panel: ${previousPanel} -> ${panel}`);
873
- });
874
-
875
- // UI component visibility changed
876
- viewer.on("ui:visibilityChange", ({ component, visible }) => {
877
- console.log(`${component} is now ${visible ? "visible" : "hidden"}`);
878
- });
879
-
880
- // Document loading progress (fetching/parsing the document for display)
881
- viewer.on("document:loading", ({ loaded, total, percent }) => {
882
- console.log(`Loaded ${loaded}/${total} bytes (${percent}%)`);
883
- });
884
-
885
- // Search results changed (matches found or active match navigated)
886
- viewer.on("search:change", ({ matches, activeIndex }) => {
887
- console.log(`${matches.length} matches, active: ${activeIndex}`);
888
- });
889
-
890
- // Annotation lifecycle (fired for both UI- and API-driven changes; see the
891
- // Annotations section above for full payloads)
892
- viewer.on("annotation:add", ({ pageIndex, annotation }) => {});
893
- viewer.on("annotation:update", ({ pageIndex, annotation }) => {});
894
- viewer.on("annotation:remove", ({ pageIndex, annotation }) => {});
895
- viewer.on("annotation:select", (selection) => {
896
- // null when the selection is cleared
897
- });
898
- viewer.on("annotation:hover", (hover) => {
899
- // null when the pointer leaves without entering another annotation;
900
- // otherwise `{ pageIndex, annotation, clientX, clientY }` — clientX/Y are
901
- // viewport coords for tooltip placement
902
- });
903
- viewer.on("annotation:click", ({ pageIndex, annotation, clientX, clientY }) => {
904
- // clientX/Y are viewport coords for context-menu / popover anchoring
905
- });
906
-
907
- // Error occurred. `phase` is "fetch" | "parse" | "render" | "permit".
908
- // "permit" = free-tier verification was blocked or unavailable
909
- // (see "Free-tier usage & verification").
910
- viewer.on("error", ({ error, phase }) => {
911
- console.error(`Error during ${phase}:`, error);
912
- });
913
-
914
- // Unsubscribe
915
- unsubscribe();
916
- ```
917
-
918
- ### Document Export
919
-
920
- ```typescript
921
- // Export document as raw bytes
922
- const bytes = await viewer.toBytes();
923
-
924
- // Download document as a file
925
- await viewer.download("document.pdf");
926
- ```
927
-
928
- ### Document Composition
929
-
930
- Compose new documents by cherry-picking and rotating pages:
931
-
932
- ```typescript
933
- // Create a new document from pages of existing documents
934
- const [newDoc] = await client.compose([
935
- [
936
- { doc: viewerA, pages: "1-3" },
937
- { doc: viewerB, pages: "5", rotation: 90 },
938
- ],
939
- ]);
940
-
941
- // Export the composed document
942
- const bytes = await newDoc.toBytes();
943
- await newDoc.download("composed.pdf");
944
- ```
945
-
946
- ### Document Utilities
947
-
948
- ```typescript
949
- // Split a document by its outline (table of contents)
950
- const { viewers, sections } = await client.splitByOutline(source, {
951
- maxLevel: 2,
952
- splitMidPage: false,
953
- });
954
-
955
- // Extract images from a document
956
- const images = await client.extractImages(source, {
957
- convertRawToPng: true,
958
- });
959
-
960
- // Extract fonts from a document
961
- const fonts = await client.extractFonts(source);
33
+ ```ts
34
+ import { UDocViewer } from "@docmentis/udoc-viewer";
962
35
 
963
- // Compress a document
964
- const compressed = await client.compress(source);
36
+ const viewer = await UDocViewer.create(document.getElementById("viewer")!);
37
+ await viewer.open("/example.pdf");
965
38
 
966
- // Decompress a document
967
- const decompressed = await client.decompress(source);
39
+ // Call viewer.destroy() when the viewer is no longer needed.
968
40
  ```
969
41
 
970
- ### Font Management
971
-
972
- udoc-viewer automatically handles fonts for document rendering. By default, missing fonts are fetched from Google Fonts on-demand. You can also register custom fonts for full control.
973
-
974
- **Font resolution order:** Custom registered fonts are resolved first, then Google Fonts (if enabled). Supported font formats: OTF, TTF, WOFF, and WOFF2.
975
-
976
- ```typescript
977
- // Option 1: Register fonts declaratively at client creation
978
- const client = await UDocClient.create({
979
- googleFonts: true, // default, enable Google Fonts fallback
980
- fonts: [
981
- { typeface: "CustomFont", bold: false, italic: false, url: "https://cdn.example.com/CustomFont-Regular.woff2" },
982
- { typeface: "CustomFont", bold: true, italic: false, url: "https://cdn.example.com/CustomFont-Bold.woff2" },
983
- ],
984
- });
985
-
986
- // Option 2: Register fonts programmatically (before loading documents)
987
- await client.registerFonts([
988
- { typeface: "CustomFont", bold: false, italic: false, url: "https://cdn.example.com/CustomFont-Regular.woff2" },
989
- ]);
990
-
991
- // Option 3: Disable Google Fonts entirely (only use registered fonts)
992
- const client = await UDocClient.create({ googleFonts: false });
993
- ```
994
-
995
- #### Parsing Font Info
996
-
997
- When users upload custom font files, you typically don't know the typeface name or whether a file is the bold/italic variant. `parseFontInfo` extracts that metadata from the raw font binary, so you can store it in your own database alongside the font file. Later, when initializing the viewer, you retrieve that metadata and pass it to `registerFonts`.
998
-
999
- **Step 1: At upload time** — parse the font and store the metadata + file in your database/storage.
1000
-
1001
- ```typescript
1002
- // User uploads a font file
1003
- const fontBytes = new Uint8Array(await fontFile.arrayBuffer());
1004
- const info = await client.parseFontInfo(fontBytes);
1005
- // info = { typeface: "Roboto", bold: true, italic: false }
1006
-
1007
- // Store font file to your storage (e.g., S3, GCS) and save metadata to your database
1008
- await storage.upload(`fonts/${fontFile.name}`, fontBytes);
1009
- await db.fonts.insert({
1010
- typeface: info.typeface,
1011
- bold: info.bold,
1012
- italic: info.italic,
1013
- url: `https://cdn.example.com/fonts/${fontFile.name}`,
1014
- });
1015
- ```
1016
-
1017
- **Step 2: At viewing time** — retrieve stored metadata and register fonts before loading a document.
1018
-
1019
- ```typescript
1020
- // Fetch font entries from your database
1021
- const fonts = await db.fonts.list();
1022
-
1023
- // Register all fonts with the viewer
1024
- await client.registerFonts(fonts.map((f) => ({ typeface: f.typeface, bold: f.bold, italic: f.italic, url: f.url })));
1025
-
1026
- // Now load the document — registered fonts will be used during rendering
1027
- await viewer.load(documentSource);
1028
- ```
1029
-
1030
- Supported font formats: OTF, TTF, WOFF, and WOFF2.
1031
-
1032
- #### Font Usage
1033
-
1034
- After rendering, you can inspect how each font request in the document was resolved — which font was matched, its source, and any glyph-fallback fonts used during text shaping.
1035
-
1036
- ```typescript
1037
- // Query font usage after at least one page has been rendered
1038
- const fontUsage = await viewer.getFontUsage();
1039
-
1040
- for (const entry of fontUsage) {
1041
- // What the document requested
1042
- const spec =
1043
- "typeface" in entry.spec
1044
- ? `${entry.spec.typeface} (bold=${entry.spec.bold}, italic=${entry.spec.italic})`
1045
- : `fontId=${entry.spec.fontId}`;
1046
-
1047
- // How it was resolved
1048
- const resolved = entry.resolved;
1049
- console.log(`${spec} → ${resolved.familyName} [${resolved.source}]`);
1050
-
1051
- // Any additional fonts used via glyph fallback
1052
- for (const fb of entry.fallbacks) {
1053
- console.log(` fallback: ${fb.familyName} [${fb.source}]`);
1054
- }
1055
- }
1056
- ```
1057
-
1058
- Font usage is populated incrementally as pages are rendered. To react to changes, listen to the `font:usageChange` event:
1059
-
1060
- ```typescript
1061
- viewer.on("font:usageChange", ({ entries }) => {
1062
- console.log(`Font usage updated: ${entries.length} font specs resolved`);
1063
- });
1064
- ```
1065
-
1066
- The `source` field on each resolved font indicates where it came from: `"embedded"` (bundled in the document), `"standard"` (built-in standard font), `"googleFonts"`, `"url"`, `"local"`, or `{ custom: string }` for registered custom fonts.
1067
-
1068
- ### Headless Rendering
1069
-
1070
- Render pages to images without UI:
1071
-
1072
- ```typescript
1073
- // Create headless viewer (no container)
1074
- const viewer = await client.createViewer();
1075
- await viewer.load(pdfBytes);
1076
-
1077
- // Render page to ImageData (0-based page index)
1078
- const imageData = await viewer.renderPage(0, { scale: 2 });
1079
-
1080
- // Render to Blob
1081
- const blob = await viewer.renderPage(0, {
1082
- format: "blob",
1083
- imageType: "image/png",
1084
- });
1085
-
1086
- // Render to data URL
1087
- const dataUrl = await viewer.renderPage(0, {
1088
- format: "data-url",
1089
- imageType: "image/jpeg",
1090
- quality: 0.9,
1091
- });
1092
-
1093
- // Render thumbnail
1094
- const thumb = await viewer.renderThumbnail(0, { scale: 1 });
1095
-
1096
- // Render a sub-region of a page.
1097
- // rect is in page points (1pt = 1/72 inch), top-left origin — same coordinate
1098
- // space as getPageInfo(page).width / .height. Output pixel size is
1099
- // rect.width * scale × rect.height * scale.
1100
- const { width, height } = await viewer.getPageInfo(0);
1101
- const regionImageData = await viewer.renderRegion(
1102
- 0,
1103
- { x: 0, y: 0, width: width / 2, height: height / 2 },
1104
- { scale: 2 },
1105
- );
1106
-
1107
- // Same crop as a PNG blob
1108
- const regionBlob = await viewer.renderRegion(
1109
- 0,
1110
- { x: 100, y: 100, width: 200, height: 150 },
1111
- { format: "blob", imageType: "image/png", scale: 2 },
1112
- );
1113
- ```
1114
-
1115
- ### Password-Protected Documents
1116
-
1117
- When a password-protected document is loaded in UI mode, the viewer automatically prompts the user to enter the password. For headless mode, you can handle it programmatically:
1118
-
1119
- ```typescript
1120
- await viewer.load(source);
1121
-
1122
- if (await viewer.needsPassword()) {
1123
- const success = await viewer.authenticate("my-password");
1124
- if (!success) {
1125
- console.error("Incorrect password");
1126
- }
1127
- }
1128
- ```
1129
-
1130
- ## How It Works
1131
-
1132
- udoc-viewer uses a custom document processing engine written in Rust, compiled to WebAssembly. Documents are parsed and rendered entirely in the browser with near-native performance — no PDF.js, no iframe hacks, no server-side conversion.
1133
-
1134
- The JavaScript wrapper (`@docmentis/udoc-viewer`) is MIT-licensed and open source. The WASM rendering engine is free to use, including in commercial applications. See [LICENSE](./LICENSE) for details. Free/unlicensed use is subject to online verification — see [Free-tier usage & verification](#free-tier-usage--verification).
1135
-
1136
- ## Browser Support
1137
-
1138
- | Browser | Supported |
1139
- | ------------- | --------- |
1140
- | Chrome / Edge | ✅ 80+ |
1141
- | Firefox | ✅ 80+ |
1142
- | Safari | ✅ 15+ |
1143
-
1144
- Requires WebAssembly support.
1145
-
1146
- ## Free-tier usage & verification
1147
-
1148
- udoc-viewer is free to use, but **free/unlicensed usage requires online verification**. Before opening each document, the WebAssembly runtime requests a short-lived, signed permit from the docMentis permit service and verifies it cryptographically — inside WASM — before rendering. This caps free usage at a set number of document opens per domain, and per IP address, per rolling 24 hours.
1149
-
1150
- **A commercial license removes this entirely.** Licensed usage skips the permit check, never contacts docMentis servers, and renders fully offline with no usage limit. To obtain a license, contact [licensing@docmentis.com](mailto:licensing@docmentis.com).
1151
-
1152
- ```typescript
1153
- // Free tier: each document open is verified online (limited per domain and per IP)
1154
- const client = await UDocClient.create();
1155
-
1156
- // Licensed: unlimited, fully offline, no permit check
1157
- const client = await UDocClient.create({ license: "eyJ2Ijox..." });
1158
- ```
1159
-
1160
- Notes for free-tier usage:
1161
-
1162
- - **Network is required.** If the permit service can't be reached, free/unlicensed documents won't render. (Licensed usage is always offline.)
1163
- - **Local development in a browser is unmetered.** `localhost`, `*.localhost` and loopback/private IP ranges are not counted against either limit, as long as the browser identifies the origin.
1164
- - **Server-side usage is metered by IP.** Running the viewer outside a browser (for example under Node) has no page origin to report — the viewer reports the host as `unknown` — so those opens count against the per-IP limit rather than a domain limit. A commercial license still validates there: `unknown` is accepted by domain matching, exactly as `localhost` is.
1165
- - **No document data is sent.** The permit request contains only a random per-open nonce, the embedding hostname, the SDK version, and an anonymous install id — never document content, filenames, or URLs. Your IP address is used to enforce the per-IP limit; it is not stored in raw form.
1166
- - **The decision is enforced in WASM**, not JavaScript, so it cannot be bypassed by editing client code.
1167
-
1168
- When either limit is exceeded — or a permit can't be obtained — the document does not render: the viewer shows an in-area notice, and an `error` event fires with `phase: "permit"`:
1169
-
1170
- ```typescript
1171
- viewer.on("error", ({ error, phase }) => {
1172
- if (phase === "permit") {
1173
- // A free-tier limit was reached, or verification was unavailable.
1174
- // Prompt the user to retry, or upgrade to a commercial license.
1175
- }
1176
- });
1177
- ```
1178
-
1179
- ## Telemetry
1180
-
1181
- udoc-viewer collects anonymous, non-personally-identifiable usage data to help us understand SDK adoption and prioritize format support. Telemetry fires once per document open.
1182
-
1183
- **What we collect:**
1184
-
1185
- | Field | Description | Example |
1186
- | ---------------- | ------------------------------------------------------ | -------------- |
1187
- | `domain` | Hostname of the embedding website | `example.com` |
1188
- | `format` | Document format | `pdf` |
1189
- | `size_bucket` | File size in units of 100 KB (`floor(bytes / 100000)`) | `3` |
1190
- | `viewer_version` | SDK version string | `0.5.19` |
1191
- | `license_hash` | SHA-256 hash of the license key (empty if none) | `a1b2c3...` |
1192
- | `license_info` | Non-sensitive license metadata (identifier, validity) | — |
1193
- | `distinct_id` | Anonymous random UUID stored in localStorage | `f47ac10b-...` |
1194
-
1195
- ### Opting out
1196
-
1197
- Telemetry can be disabled with a license that includes the `no_telemetry` feature:
1198
-
1199
- ```typescript
1200
- const client = await UDocClient.create({
1201
- license: "eyJ2Ijox...",
1202
- disableTelemetry: true,
1203
- });
1204
- ```
1205
-
1206
- Without a qualifying license the flag is silently ignored and a warning is logged to the console. To obtain a license, contact [licensing@docmentis.com](mailto:licensing@docmentis.com).
1207
-
1208
- **What we do NOT collect:**
1209
-
1210
- - Document content, filenames, or URLs
1211
- - User identity, cookies, or session data (the UUID above is random and not linked to any account)
1212
- - IP addresses (disabled at the collection endpoint)
1213
- - Any other personally identifiable information
1214
-
1215
- ## Branding & Attribution
1216
-
1217
- udoc-viewer is free to use, including in commercial applications. A "Powered by docMentis" attribution link is shown by default.
1218
-
1219
- To remove the attribution, contact [licensing@docmentis.com](mailto:licensing@docmentis.com) to obtain a license key, then pass it when creating the client:
1220
-
1221
- ```typescript
1222
- const client = await UDocClient.create({ license: "eyJ2Ijox..." });
1223
- const viewer = await client.createViewer({
1224
- container: "#viewer",
1225
- hideAttribution: true,
1226
- });
1227
- ```
1228
-
1229
- The `hideAttribution` option is only honored when the license includes the `no_attribution` feature. Without a valid license, the attribution link will remain visible.
1230
-
1231
- ## Contributing
1232
-
1233
- We welcome bug reports, feature requests, and pull requests.
1234
-
1235
- - **Issues**: [github.com/docmentis/docmentis-udoc-viewer/issues](https://github.com/docmentis/docmentis-udoc-viewer/issues)
1236
- - **Discussions**: [github.com/docmentis/docmentis-udoc-viewer/discussions](https://github.com/docmentis/docmentis-udoc-viewer/discussions)
42
+ `open` also accepts local files and document bytes. See the package's API documentation for configuration and available methods.
1237
43
 
1238
- ## License
44
+ ## Viewer or editor?
1239
45
 
1240
- The JavaScript/TypeScript source code is licensed under the [MIT License](../../LICENSE).
46
+ Use **udoc-viewer** when your application needs document viewing, navigation, search, comments, or annotations without content editing. For content editing and collaborative authoring, use [`@docmentis/udoc-editor`](https://www.npmjs.com/package/@docmentis/udoc-editor).
1241
47
 
1242
- The WebAssembly binary (`src/wasm/udoc_bg.wasm`) is distributed under the [docMentis WASM Runtime License](src/wasm/LICENSE) -- free to use with the docMentis Viewer in commercial and non-commercial applications.
48
+ ## Licensing
1243
49
 
1244
- ## Links
50
+ The viewer's source code is open source under **MIT OR Apache-2.0**. It uses the separately licensed, proprietary [`@docmentis/udoc-wasm`](https://www.npmjs.com/package/@docmentis/udoc-wasm) runtime. Free runtime use requires online authorization; commercial licensing is available for offline use and applicable licensed options.
1245
51
 
1246
- - 🌐 [docmentis.com](https://docmentis.com)
1247
- - 📦 [npm package](https://www.npmjs.com/package/@docmentis/udoc-viewer)
1248
- - 📂 [GitHub](https://github.com/docmentis/docmentis-udoc-viewer)
1249
- - 💬 [Report an issue](https://github.com/docmentis/docmentis-udoc-viewer/issues)
52
+ [Source and documentation](https://github.com/docMentis/docmentis-udoc) · [docMentis](https://www.docmentis.com/)