@osdk/react-components 0.2.0-beta.21 → 0.2.0-beta.23

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 (510) hide show
  1. package/AGENTS.md +14 -97
  2. package/CHANGELOG.md +35 -0
  3. package/README.md +23 -7
  4. package/build/browser/action-form/ActionFormApi.js.map +1 -1
  5. package/build/browser/action-form/BaseForm.js +18 -5
  6. package/build/browser/action-form/BaseForm.js.map +1 -1
  7. package/build/browser/action-form/BaseForm.module.css +38 -0
  8. package/build/browser/action-form/BaseForm.module.css.js +8 -0
  9. package/build/browser/action-form/FormField.js +42 -0
  10. package/build/browser/action-form/FormField.js.map +1 -0
  11. package/build/browser/action-form/FormField.module.css +41 -0
  12. package/build/browser/action-form/FormField.module.css.js +10 -0
  13. package/build/browser/action-form/FormFieldApi.js.map +1 -1
  14. package/build/browser/action-form/FormHeader.js +26 -0
  15. package/build/browser/action-form/FormHeader.js.map +1 -0
  16. package/build/browser/action-form/FormHeader.module.css +26 -0
  17. package/build/browser/action-form/FormHeader.module.css.js +6 -0
  18. package/build/browser/action-form/fields/DateCalendar.js +70 -0
  19. package/build/browser/action-form/fields/DateCalendar.js.map +1 -0
  20. package/build/browser/action-form/fields/DateCalendar.module.css +136 -0
  21. package/build/browser/action-form/fields/DateCalendar.module.css.js +22 -0
  22. package/build/browser/action-form/fields/DatetimePickerField.js +98 -0
  23. package/build/browser/action-form/fields/DatetimePickerField.js.map +1 -0
  24. package/build/browser/action-form/fields/DatetimePickerField.module.css +66 -0
  25. package/build/browser/action-form/fields/DatetimePickerField.module.css.js +10 -0
  26. package/build/browser/action-form/fields/FormFieldRenderer.js +17 -6
  27. package/build/browser/action-form/fields/FormFieldRenderer.js.map +1 -1
  28. package/build/browser/action-form/fields/LazyDateCalendar.js +27 -0
  29. package/build/browser/action-form/fields/LazyDateCalendar.js.map +1 -0
  30. package/build/browser/action-form/fields/TextInputField.js +2 -0
  31. package/build/browser/action-form/fields/TextInputField.js.map +1 -1
  32. package/build/browser/action-form/fields/TextInputField.module.css +56 -0
  33. package/build/browser/action-form/fields/TextInputField.module.css.js +6 -0
  34. package/build/browser/base-components/checkbox/Checkbox.js +2 -2
  35. package/build/browser/base-components/checkbox/Checkbox.js.map +1 -1
  36. package/build/browser/base-components/checkbox/Checkbox.module.css +0 -4
  37. package/build/browser/base-components/combobox/Combobox.js +3 -8
  38. package/build/browser/base-components/combobox/Combobox.js.map +1 -1
  39. package/build/browser/base-components/combobox/Combobox.module.css +0 -3
  40. package/build/browser/base-components/draggable-list/DraggableList.js +2 -4
  41. package/build/browser/base-components/draggable-list/DraggableList.js.map +1 -1
  42. package/build/browser/base-components/search-bar/SearchBar.module.css +2 -2
  43. package/build/browser/base-components/select/Select.js +1 -3
  44. package/build/browser/base-components/select/Select.js.map +1 -1
  45. package/build/browser/base-components/select/Select.module.css +0 -2
  46. package/build/browser/base-components/switch/Switch.module.css +0 -1
  47. package/build/browser/filter-list/FilterInput.js +14 -5
  48. package/build/browser/filter-list/FilterInput.js.map +1 -1
  49. package/build/browser/filter-list/FilterList.js +22 -10
  50. package/build/browser/filter-list/FilterList.js.map +1 -1
  51. package/build/browser/filter-list/FilterListApi.js.map +1 -1
  52. package/build/browser/filter-list/base/AddFilterPopover.js +4 -3
  53. package/build/browser/filter-list/base/AddFilterPopover.js.map +1 -1
  54. package/build/browser/filter-list/base/BaseFilterList.js +3 -1
  55. package/build/browser/filter-list/base/BaseFilterList.js.map +1 -1
  56. package/build/browser/filter-list/base/BaseFilterListApi.js.map +1 -1
  57. package/build/browser/filter-list/base/ExcludeDropdown.js +61 -0
  58. package/build/browser/filter-list/base/ExcludeDropdown.js.map +1 -0
  59. package/build/browser/filter-list/base/ExcludeDropdown.module.css +94 -0
  60. package/build/browser/filter-list/base/ExcludeDropdown.module.css.js +12 -0
  61. package/build/browser/filter-list/base/FilterIcons.js +0 -39
  62. package/build/browser/filter-list/base/FilterIcons.js.map +1 -1
  63. package/build/browser/filter-list/base/FilterInputExcludeRow.js +55 -0
  64. package/build/browser/filter-list/base/FilterInputExcludeRow.js.map +1 -0
  65. package/build/browser/filter-list/base/FilterListHeader.js +3 -2
  66. package/build/browser/filter-list/base/FilterListHeader.js.map +1 -1
  67. package/build/browser/filter-list/base/FilterListItem.js +72 -23
  68. package/build/browser/filter-list/base/FilterListItem.js.map +1 -1
  69. package/build/browser/filter-list/base/FilterListItem.module.css +96 -20
  70. package/build/browser/filter-list/base/FilterListItem.module.css.js +7 -2
  71. package/build/browser/filter-list/base/inputs/CheckboxListInput.js +2 -2
  72. package/build/browser/filter-list/base/inputs/CheckboxListInput.js.map +1 -1
  73. package/build/browser/filter-list/base/inputs/ContainsTextInput.js +2 -6
  74. package/build/browser/filter-list/base/inputs/ContainsTextInput.js.map +1 -1
  75. package/build/browser/filter-list/base/inputs/DateRangeInput.js +1 -1
  76. package/build/browser/filter-list/base/inputs/DateRangeInput.js.map +1 -1
  77. package/build/browser/filter-list/base/inputs/ListogramInput.js +2 -2
  78. package/build/browser/filter-list/base/inputs/ListogramInput.js.map +1 -1
  79. package/build/browser/filter-list/base/inputs/MultiDateInput.js +1 -1
  80. package/build/browser/filter-list/base/inputs/MultiDateInput.js.map +1 -1
  81. package/build/browser/filter-list/base/inputs/RangeInput.js +2 -2
  82. package/build/browser/filter-list/base/inputs/RangeInput.js.map +1 -1
  83. package/build/browser/filter-list/base/inputs/SingleDateInput.js +1 -1
  84. package/build/browser/filter-list/base/inputs/SingleDateInput.js.map +1 -1
  85. package/build/browser/filter-list/base/inputs/SingleSelectInput.js +1 -3
  86. package/build/browser/filter-list/base/inputs/SingleSelectInput.js.map +1 -1
  87. package/build/browser/filter-list/base/inputs/TimelineInput.js +1 -1
  88. package/build/browser/filter-list/base/inputs/TimelineInput.js.map +1 -1
  89. package/build/browser/filter-list/base/inputs/index.js +1 -1
  90. package/build/browser/filter-list/base/inputs/index.js.map +1 -1
  91. package/build/{esm/filter-list/base/inputs/useStaleData.js → browser/filter-list/base/inputs/useStableData.js} +5 -5
  92. package/build/browser/filter-list/base/inputs/useStableData.js.map +1 -0
  93. package/build/browser/filter-list/hooks/useFilterListState.js +3 -0
  94. package/build/browser/filter-list/hooks/useFilterListState.js.map +1 -1
  95. package/build/browser/filter-list/hooks/useFilterVisibility.js +7 -1
  96. package/build/browser/filter-list/hooks/useFilterVisibility.js.map +1 -1
  97. package/build/browser/filter-list/hooks/usePropertyAggregation.js +3 -2
  98. package/build/browser/filter-list/hooks/usePropertyAggregation.js.map +1 -1
  99. package/build/browser/filter-list/inputs/CheckboxListFilterInput.js +15 -5
  100. package/build/browser/filter-list/inputs/CheckboxListFilterInput.js.map +1 -1
  101. package/build/browser/filter-list/inputs/DateRangeFilterInput.js +10 -6
  102. package/build/browser/filter-list/inputs/DateRangeFilterInput.js.map +1 -1
  103. package/build/browser/filter-list/inputs/LinkedPropertyInput.js +41 -18
  104. package/build/browser/filter-list/inputs/LinkedPropertyInput.js.map +1 -1
  105. package/build/browser/filter-list/inputs/ListogramFilterInput.js +15 -5
  106. package/build/browser/filter-list/inputs/ListogramFilterInput.js.map +1 -1
  107. package/build/browser/filter-list/inputs/MultiSelectFilterInput.js +12 -4
  108. package/build/browser/filter-list/inputs/MultiSelectFilterInput.js.map +1 -1
  109. package/build/browser/filter-list/inputs/NumberRangeFilterInput.js +10 -6
  110. package/build/browser/filter-list/inputs/NumberRangeFilterInput.js.map +1 -1
  111. package/build/browser/filter-list/inputs/PropertyFilterInput.js +36 -10
  112. package/build/browser/filter-list/inputs/PropertyFilterInput.js.map +1 -1
  113. package/build/browser/filter-list/inputs/SingleSelectFilterInput.js +12 -4
  114. package/build/browser/filter-list/inputs/SingleSelectFilterInput.js.map +1 -1
  115. package/build/browser/filter-list/inputs/TextTagsFilterInput.js +12 -4
  116. package/build/browser/filter-list/inputs/TextTagsFilterInput.js.map +1 -1
  117. package/build/browser/filter-list/utils/filterStateToWhereClause.js +1 -1
  118. package/build/browser/filter-list/utils/filterStateToWhereClause.js.map +1 -1
  119. package/build/browser/filter-list/utils/filterValues.js +29 -1
  120. package/build/browser/filter-list/utils/filterValues.js.map +1 -1
  121. package/build/browser/object-table/LoadingCell.js +2 -1
  122. package/build/browser/object-table/LoadingCell.js.map +1 -1
  123. package/build/browser/object-table/LoadingCell.module.css +3 -21
  124. package/build/browser/object-table/LoadingCell.module.css.js +1 -2
  125. package/build/browser/object-table/LoadingStateTable.js +2 -1
  126. package/build/browser/object-table/LoadingStateTable.js.map +1 -1
  127. package/build/browser/object-table/MultiColumnSortDialog.js +1 -3
  128. package/build/browser/object-table/MultiColumnSortDialog.js.map +1 -1
  129. package/build/browser/object-table/MultiColumnSortDialog.module.css +0 -1
  130. package/build/browser/object-table/TableCell.module.css +1 -1
  131. package/build/browser/object-table/TableHeader.module.css +2 -2
  132. package/build/browser/object-table/TableHeaderWithPopover.js +2 -4
  133. package/build/browser/object-table/TableHeaderWithPopover.js.map +1 -1
  134. package/build/browser/object-table/TableHeaderWithPopover.module.css +1 -0
  135. package/build/browser/pdf-viewer/PdfRenderer.js +1 -1
  136. package/build/browser/pdf-viewer/PdfRenderer.js.map +1 -1
  137. package/build/browser/pdf-viewer/PdfViewer.js +59 -118
  138. package/build/browser/pdf-viewer/PdfViewer.js.map +1 -1
  139. package/build/browser/pdf-viewer/components/PdfViewerAnnotationLayer.js.map +1 -0
  140. package/build/{esm/pdf-viewer → browser/pdf-viewer/components}/PdfViewerAnnotationLayer.module.css +0 -1
  141. package/build/browser/pdf-viewer/components/PdfViewerAnnotationLayer.module.css.js +11 -0
  142. package/build/browser/pdf-viewer/components/PdfViewerContent.js +113 -0
  143. package/build/browser/pdf-viewer/components/PdfViewerContent.js.map +1 -0
  144. package/build/browser/pdf-viewer/components/PdfViewerOutlineSidebar.js +98 -0
  145. package/build/browser/pdf-viewer/components/PdfViewerOutlineSidebar.js.map +1 -0
  146. package/build/browser/pdf-viewer/components/PdfViewerOutlineSidebar.module.css +89 -0
  147. package/build/browser/pdf-viewer/components/PdfViewerOutlineSidebar.module.css.js +15 -0
  148. package/build/browser/pdf-viewer/components/PdfViewerSearchBar.js.map +1 -0
  149. package/build/browser/pdf-viewer/components/PdfViewerSearchBar.module.css.js +10 -0
  150. package/build/browser/pdf-viewer/{PdfViewerSidebar.js → components/PdfViewerSidebar.js} +9 -5
  151. package/build/browser/pdf-viewer/components/PdfViewerSidebar.js.map +1 -0
  152. package/build/{esm/pdf-viewer → browser/pdf-viewer/components}/PdfViewerSidebar.module.css +0 -9
  153. package/build/browser/pdf-viewer/{PdfViewerSidebar.module.css.js → components/PdfViewerSidebar.module.css.js} +5 -6
  154. package/build/browser/pdf-viewer/components/PdfViewerSidebarHeader.js +54 -0
  155. package/build/browser/pdf-viewer/components/PdfViewerSidebarHeader.js.map +1 -0
  156. package/build/browser/pdf-viewer/components/PdfViewerSidebarHeader.module.css +70 -0
  157. package/build/browser/pdf-viewer/components/PdfViewerSidebarHeader.module.css.js +8 -0
  158. package/build/browser/pdf-viewer/{PdfViewerThumbnail.js → components/PdfViewerThumbnail.js} +1 -1
  159. package/build/browser/pdf-viewer/components/PdfViewerThumbnail.js.map +1 -0
  160. package/build/browser/pdf-viewer/{PdfViewerThumbnail.module.css.js → components/PdfViewerThumbnail.module.css.js} +3 -3
  161. package/build/browser/pdf-viewer/{PdfViewerToolbar.js → components/PdfViewerToolbar.js} +39 -12
  162. package/build/browser/pdf-viewer/components/PdfViewerToolbar.js.map +1 -0
  163. package/build/browser/pdf-viewer/{PdfViewerToolbar.module.css → components/PdfViewerToolbar.module.css} +2 -2
  164. package/build/browser/pdf-viewer/components/PdfViewerToolbar.module.css.js +12 -0
  165. package/build/browser/pdf-viewer/constants.js +7 -5
  166. package/build/browser/pdf-viewer/constants.js.map +1 -1
  167. package/build/browser/pdf-viewer/hooks/usePdfDocument.js +2 -3
  168. package/build/browser/pdf-viewer/hooks/usePdfDocument.js.map +1 -1
  169. package/build/browser/pdf-viewer/hooks/usePdfOutline.js +268 -0
  170. package/build/browser/pdf-viewer/hooks/usePdfOutline.js.map +1 -0
  171. package/build/browser/pdf-viewer/hooks/usePdfViewer.js +12 -1
  172. package/build/browser/pdf-viewer/hooks/usePdfViewer.js.map +1 -1
  173. package/build/browser/pdf-viewer/hooks/usePdfViewerCore.js +80 -0
  174. package/build/browser/pdf-viewer/hooks/usePdfViewerCore.js.map +1 -0
  175. package/build/browser/pdf-viewer/hooks/usePdfViewerState.js +135 -0
  176. package/build/browser/pdf-viewer/hooks/usePdfViewerState.js.map +1 -0
  177. package/build/browser/pdf-viewer/types.js.map +1 -1
  178. package/build/browser/public/experimental.js +23 -2
  179. package/build/browser/public/experimental.js.map +1 -1
  180. package/build/browser/public/primitives.js +20 -0
  181. package/build/browser/public/primitives.js.map +1 -0
  182. package/build/browser/{filter-list/base/inputs → shared}/dateUtils.js +38 -2
  183. package/build/browser/shared/dateUtils.js.map +1 -0
  184. package/build/browser/styles.css +817 -136
  185. package/build/cjs/DateCalendar-QWGFKD6J.css +113 -0
  186. package/build/cjs/DateCalendar-QWGFKD6J.css.map +1 -0
  187. package/build/cjs/DateCalendar-R44GMN3O.cjs +67 -0
  188. package/build/cjs/DateCalendar-R44GMN3O.cjs.map +1 -0
  189. package/build/cjs/chunk-GT6IV6LV.cjs +163 -0
  190. package/build/cjs/chunk-GT6IV6LV.cjs.map +1 -0
  191. package/build/cjs/chunk-HMQTYQEX.cjs +9 -0
  192. package/build/cjs/chunk-HMQTYQEX.cjs.map +1 -0
  193. package/build/cjs/chunk-UZ2E5NRX.cjs +8 -0
  194. package/build/cjs/chunk-UZ2E5NRX.cjs.map +1 -0
  195. package/build/cjs/index.cjs +2 -0
  196. package/build/cjs/public/experimental.cjs +3227 -1848
  197. package/build/cjs/public/experimental.cjs.map +1 -1
  198. package/build/cjs/public/experimental.css +650 -172
  199. package/build/cjs/public/experimental.css.map +1 -1
  200. package/build/cjs/public/experimental.d.cts +685 -17
  201. package/build/cjs/public/primitives.cjs +25 -0
  202. package/build/cjs/public/primitives.cjs.map +1 -0
  203. package/build/cjs/public/primitives.css +154 -0
  204. package/build/cjs/public/primitives.css.map +1 -0
  205. package/build/cjs/public/primitives.d.cts +49 -0
  206. package/build/esm/action-form/ActionFormApi.js.map +1 -1
  207. package/build/esm/action-form/BaseForm.js +18 -5
  208. package/build/esm/action-form/BaseForm.js.map +1 -1
  209. package/build/esm/action-form/BaseForm.module.css +38 -0
  210. package/build/esm/action-form/FormField.js +42 -0
  211. package/build/esm/action-form/FormField.js.map +1 -0
  212. package/build/esm/action-form/FormField.module.css +41 -0
  213. package/build/esm/action-form/FormFieldApi.js.map +1 -1
  214. package/build/esm/action-form/FormHeader.js +26 -0
  215. package/build/esm/action-form/FormHeader.js.map +1 -0
  216. package/build/esm/action-form/FormHeader.module.css +26 -0
  217. package/build/esm/action-form/fields/DateCalendar.js +70 -0
  218. package/build/esm/action-form/fields/DateCalendar.js.map +1 -0
  219. package/build/esm/action-form/fields/DateCalendar.module.css +136 -0
  220. package/build/esm/action-form/fields/DatetimePickerField.js +98 -0
  221. package/build/esm/action-form/fields/DatetimePickerField.js.map +1 -0
  222. package/build/esm/action-form/fields/DatetimePickerField.module.css +66 -0
  223. package/build/esm/action-form/fields/FormFieldRenderer.js +17 -6
  224. package/build/esm/action-form/fields/FormFieldRenderer.js.map +1 -1
  225. package/build/esm/action-form/fields/LazyDateCalendar.js +27 -0
  226. package/build/esm/action-form/fields/LazyDateCalendar.js.map +1 -0
  227. package/build/esm/action-form/fields/TextInputField.js +2 -0
  228. package/build/esm/action-form/fields/TextInputField.js.map +1 -1
  229. package/build/esm/action-form/fields/TextInputField.module.css +56 -0
  230. package/build/esm/base-components/checkbox/Checkbox.js +2 -2
  231. package/build/esm/base-components/checkbox/Checkbox.js.map +1 -1
  232. package/build/esm/base-components/checkbox/Checkbox.module.css +0 -4
  233. package/build/esm/base-components/combobox/Combobox.js +3 -8
  234. package/build/esm/base-components/combobox/Combobox.js.map +1 -1
  235. package/build/esm/base-components/combobox/Combobox.module.css +0 -3
  236. package/build/esm/base-components/draggable-list/DraggableList.js +2 -4
  237. package/build/esm/base-components/draggable-list/DraggableList.js.map +1 -1
  238. package/build/esm/base-components/search-bar/SearchBar.module.css +2 -2
  239. package/build/esm/base-components/select/Select.js +1 -3
  240. package/build/esm/base-components/select/Select.js.map +1 -1
  241. package/build/esm/base-components/select/Select.module.css +0 -2
  242. package/build/esm/base-components/switch/Switch.module.css +0 -1
  243. package/build/esm/filter-list/FilterInput.js +14 -5
  244. package/build/esm/filter-list/FilterInput.js.map +1 -1
  245. package/build/esm/filter-list/FilterList.js +22 -10
  246. package/build/esm/filter-list/FilterList.js.map +1 -1
  247. package/build/esm/filter-list/FilterListApi.js.map +1 -1
  248. package/build/esm/filter-list/base/AddFilterPopover.js +4 -3
  249. package/build/esm/filter-list/base/AddFilterPopover.js.map +1 -1
  250. package/build/esm/filter-list/base/BaseFilterList.js +3 -1
  251. package/build/esm/filter-list/base/BaseFilterList.js.map +1 -1
  252. package/build/esm/filter-list/base/BaseFilterListApi.js.map +1 -1
  253. package/build/esm/filter-list/base/ExcludeDropdown.js +61 -0
  254. package/build/esm/filter-list/base/ExcludeDropdown.js.map +1 -0
  255. package/build/esm/filter-list/base/ExcludeDropdown.module.css +94 -0
  256. package/build/esm/filter-list/base/FilterIcons.js +0 -39
  257. package/build/esm/filter-list/base/FilterIcons.js.map +1 -1
  258. package/build/esm/filter-list/base/FilterInputExcludeRow.js +55 -0
  259. package/build/esm/filter-list/base/FilterInputExcludeRow.js.map +1 -0
  260. package/build/esm/filter-list/base/FilterListHeader.js +3 -2
  261. package/build/esm/filter-list/base/FilterListHeader.js.map +1 -1
  262. package/build/esm/filter-list/base/FilterListItem.js +72 -23
  263. package/build/esm/filter-list/base/FilterListItem.js.map +1 -1
  264. package/build/esm/filter-list/base/FilterListItem.module.css +96 -20
  265. package/build/esm/filter-list/base/inputs/CheckboxListInput.js +2 -2
  266. package/build/esm/filter-list/base/inputs/CheckboxListInput.js.map +1 -1
  267. package/build/esm/filter-list/base/inputs/ContainsTextInput.js +2 -6
  268. package/build/esm/filter-list/base/inputs/ContainsTextInput.js.map +1 -1
  269. package/build/esm/filter-list/base/inputs/DateRangeInput.js +1 -1
  270. package/build/esm/filter-list/base/inputs/DateRangeInput.js.map +1 -1
  271. package/build/esm/filter-list/base/inputs/ListogramInput.js +2 -2
  272. package/build/esm/filter-list/base/inputs/ListogramInput.js.map +1 -1
  273. package/build/esm/filter-list/base/inputs/MultiDateInput.js +1 -1
  274. package/build/esm/filter-list/base/inputs/MultiDateInput.js.map +1 -1
  275. package/build/esm/filter-list/base/inputs/RangeInput.js +2 -2
  276. package/build/esm/filter-list/base/inputs/RangeInput.js.map +1 -1
  277. package/build/esm/filter-list/base/inputs/SingleDateInput.js +1 -1
  278. package/build/esm/filter-list/base/inputs/SingleDateInput.js.map +1 -1
  279. package/build/esm/filter-list/base/inputs/SingleSelectInput.js +1 -3
  280. package/build/esm/filter-list/base/inputs/SingleSelectInput.js.map +1 -1
  281. package/build/esm/filter-list/base/inputs/TimelineInput.js +1 -1
  282. package/build/esm/filter-list/base/inputs/TimelineInput.js.map +1 -1
  283. package/build/esm/filter-list/base/inputs/index.js +1 -1
  284. package/build/esm/filter-list/base/inputs/index.js.map +1 -1
  285. package/build/{browser/filter-list/base/inputs/useStaleData.js → esm/filter-list/base/inputs/useStableData.js} +5 -5
  286. package/build/esm/filter-list/base/inputs/useStableData.js.map +1 -0
  287. package/build/esm/filter-list/hooks/useFilterListState.js +3 -0
  288. package/build/esm/filter-list/hooks/useFilterListState.js.map +1 -1
  289. package/build/esm/filter-list/hooks/useFilterVisibility.js +7 -1
  290. package/build/esm/filter-list/hooks/useFilterVisibility.js.map +1 -1
  291. package/build/esm/filter-list/hooks/usePropertyAggregation.js +3 -2
  292. package/build/esm/filter-list/hooks/usePropertyAggregation.js.map +1 -1
  293. package/build/esm/filter-list/inputs/CheckboxListFilterInput.js +15 -5
  294. package/build/esm/filter-list/inputs/CheckboxListFilterInput.js.map +1 -1
  295. package/build/esm/filter-list/inputs/DateRangeFilterInput.js +10 -6
  296. package/build/esm/filter-list/inputs/DateRangeFilterInput.js.map +1 -1
  297. package/build/esm/filter-list/inputs/LinkedPropertyInput.js +41 -18
  298. package/build/esm/filter-list/inputs/LinkedPropertyInput.js.map +1 -1
  299. package/build/esm/filter-list/inputs/ListogramFilterInput.js +15 -5
  300. package/build/esm/filter-list/inputs/ListogramFilterInput.js.map +1 -1
  301. package/build/esm/filter-list/inputs/MultiSelectFilterInput.js +12 -4
  302. package/build/esm/filter-list/inputs/MultiSelectFilterInput.js.map +1 -1
  303. package/build/esm/filter-list/inputs/NumberRangeFilterInput.js +10 -6
  304. package/build/esm/filter-list/inputs/NumberRangeFilterInput.js.map +1 -1
  305. package/build/esm/filter-list/inputs/PropertyFilterInput.js +36 -10
  306. package/build/esm/filter-list/inputs/PropertyFilterInput.js.map +1 -1
  307. package/build/esm/filter-list/inputs/SingleSelectFilterInput.js +12 -4
  308. package/build/esm/filter-list/inputs/SingleSelectFilterInput.js.map +1 -1
  309. package/build/esm/filter-list/inputs/TextTagsFilterInput.js +12 -4
  310. package/build/esm/filter-list/inputs/TextTagsFilterInput.js.map +1 -1
  311. package/build/esm/filter-list/utils/filterStateToWhereClause.js +1 -1
  312. package/build/esm/filter-list/utils/filterStateToWhereClause.js.map +1 -1
  313. package/build/esm/filter-list/utils/filterValues.js +29 -1
  314. package/build/esm/filter-list/utils/filterValues.js.map +1 -1
  315. package/build/esm/object-table/LoadingCell.js +2 -1
  316. package/build/esm/object-table/LoadingCell.js.map +1 -1
  317. package/build/esm/object-table/LoadingCell.module.css +3 -21
  318. package/build/esm/object-table/LoadingStateTable.js +2 -1
  319. package/build/esm/object-table/LoadingStateTable.js.map +1 -1
  320. package/build/esm/object-table/MultiColumnSortDialog.js +1 -3
  321. package/build/esm/object-table/MultiColumnSortDialog.js.map +1 -1
  322. package/build/esm/object-table/MultiColumnSortDialog.module.css +0 -1
  323. package/build/esm/object-table/TableCell.module.css +1 -1
  324. package/build/esm/object-table/TableHeader.module.css +2 -2
  325. package/build/esm/object-table/TableHeaderWithPopover.js +2 -4
  326. package/build/esm/object-table/TableHeaderWithPopover.js.map +1 -1
  327. package/build/esm/object-table/TableHeaderWithPopover.module.css +1 -0
  328. package/build/esm/pdf-viewer/PdfRenderer.js +1 -1
  329. package/build/esm/pdf-viewer/PdfRenderer.js.map +1 -1
  330. package/build/esm/pdf-viewer/PdfViewer.js +59 -118
  331. package/build/esm/pdf-viewer/PdfViewer.js.map +1 -1
  332. package/build/esm/pdf-viewer/components/PdfViewerAnnotationLayer.js.map +1 -0
  333. package/build/{browser/pdf-viewer → esm/pdf-viewer/components}/PdfViewerAnnotationLayer.module.css +0 -1
  334. package/build/esm/pdf-viewer/components/PdfViewerContent.js +113 -0
  335. package/build/esm/pdf-viewer/components/PdfViewerContent.js.map +1 -0
  336. package/build/esm/pdf-viewer/components/PdfViewerOutlineSidebar.js +98 -0
  337. package/build/esm/pdf-viewer/components/PdfViewerOutlineSidebar.js.map +1 -0
  338. package/build/esm/pdf-viewer/components/PdfViewerOutlineSidebar.module.css +89 -0
  339. package/build/esm/pdf-viewer/components/PdfViewerSearchBar.js.map +1 -0
  340. package/build/esm/pdf-viewer/{PdfViewerSidebar.js → components/PdfViewerSidebar.js} +9 -5
  341. package/build/esm/pdf-viewer/components/PdfViewerSidebar.js.map +1 -0
  342. package/build/{browser/pdf-viewer → esm/pdf-viewer/components}/PdfViewerSidebar.module.css +0 -9
  343. package/build/esm/pdf-viewer/components/PdfViewerSidebarHeader.js +54 -0
  344. package/build/esm/pdf-viewer/components/PdfViewerSidebarHeader.js.map +1 -0
  345. package/build/esm/pdf-viewer/components/PdfViewerSidebarHeader.module.css +70 -0
  346. package/build/esm/pdf-viewer/{PdfViewerThumbnail.js → components/PdfViewerThumbnail.js} +1 -1
  347. package/build/esm/pdf-viewer/components/PdfViewerThumbnail.js.map +1 -0
  348. package/build/esm/pdf-viewer/{PdfViewerToolbar.js → components/PdfViewerToolbar.js} +39 -12
  349. package/build/esm/pdf-viewer/components/PdfViewerToolbar.js.map +1 -0
  350. package/build/esm/pdf-viewer/{PdfViewerToolbar.module.css → components/PdfViewerToolbar.module.css} +2 -2
  351. package/build/esm/pdf-viewer/constants.js +7 -5
  352. package/build/esm/pdf-viewer/constants.js.map +1 -1
  353. package/build/esm/pdf-viewer/hooks/usePdfDocument.js +2 -3
  354. package/build/esm/pdf-viewer/hooks/usePdfDocument.js.map +1 -1
  355. package/build/esm/pdf-viewer/hooks/usePdfOutline.js +268 -0
  356. package/build/esm/pdf-viewer/hooks/usePdfOutline.js.map +1 -0
  357. package/build/esm/pdf-viewer/hooks/usePdfViewer.js +12 -1
  358. package/build/esm/pdf-viewer/hooks/usePdfViewer.js.map +1 -1
  359. package/build/esm/pdf-viewer/hooks/usePdfViewerCore.js +80 -0
  360. package/build/esm/pdf-viewer/hooks/usePdfViewerCore.js.map +1 -0
  361. package/build/esm/pdf-viewer/hooks/usePdfViewerState.js +135 -0
  362. package/build/esm/pdf-viewer/hooks/usePdfViewerState.js.map +1 -0
  363. package/build/esm/pdf-viewer/types.js.map +1 -1
  364. package/build/esm/public/experimental.js +23 -2
  365. package/build/esm/public/experimental.js.map +1 -1
  366. package/build/esm/public/primitives.js +20 -0
  367. package/build/esm/public/primitives.js.map +1 -0
  368. package/build/esm/{filter-list/base/inputs → shared}/dateUtils.js +38 -2
  369. package/build/esm/shared/dateUtils.js.map +1 -0
  370. package/build/types/action-form/ActionFormApi.d.ts +1 -0
  371. package/build/types/action-form/ActionFormApi.d.ts.map +1 -1
  372. package/build/types/action-form/BaseForm.d.ts.map +1 -1
  373. package/build/types/action-form/FormField.d.ts +11 -0
  374. package/build/types/action-form/FormField.d.ts.map +1 -0
  375. package/build/types/action-form/FormFieldApi.d.ts +22 -8
  376. package/build/types/action-form/FormFieldApi.d.ts.map +1 -1
  377. package/build/types/action-form/FormHeader.d.ts +6 -0
  378. package/build/types/action-form/FormHeader.d.ts.map +1 -0
  379. package/build/types/action-form/fields/DateCalendar.d.ts +9 -0
  380. package/build/types/action-form/fields/DateCalendar.d.ts.map +1 -0
  381. package/build/types/action-form/fields/DatetimePickerField.d.ts +3 -0
  382. package/build/types/action-form/fields/DatetimePickerField.d.ts.map +1 -0
  383. package/build/types/action-form/fields/FormFieldRenderer.d.ts.map +1 -1
  384. package/build/types/action-form/fields/LazyDateCalendar.d.ts +3 -0
  385. package/build/types/action-form/fields/LazyDateCalendar.d.ts.map +1 -0
  386. package/build/types/action-form/fields/TextInputField.d.ts.map +1 -1
  387. package/build/types/filter-list/FilterInput.d.ts +3 -1
  388. package/build/types/filter-list/FilterInput.d.ts.map +1 -1
  389. package/build/types/filter-list/FilterListApi.d.ts +14 -10
  390. package/build/types/filter-list/FilterListApi.d.ts.map +1 -1
  391. package/build/types/filter-list/base/AddFilterPopover.d.ts +2 -1
  392. package/build/types/filter-list/base/AddFilterPopover.d.ts.map +1 -1
  393. package/build/types/filter-list/base/BaseFilterListApi.d.ts +4 -1
  394. package/build/types/filter-list/base/BaseFilterListApi.d.ts.map +1 -1
  395. package/build/types/filter-list/base/ExcludeDropdown.d.ts +8 -0
  396. package/build/types/filter-list/base/ExcludeDropdown.d.ts.map +1 -0
  397. package/build/types/filter-list/base/FilterIcons.d.ts +0 -2
  398. package/build/types/filter-list/base/FilterIcons.d.ts.map +1 -1
  399. package/build/types/filter-list/base/FilterInputExcludeRow.d.ts +12 -0
  400. package/build/types/filter-list/base/FilterInputExcludeRow.d.ts.map +1 -0
  401. package/build/types/filter-list/base/FilterListHeader.d.ts +3 -2
  402. package/build/types/filter-list/base/FilterListHeader.d.ts.map +1 -1
  403. package/build/types/filter-list/base/FilterListItem.d.ts.map +1 -1
  404. package/build/types/filter-list/base/inputs/DateRangeInput.d.ts.map +1 -1
  405. package/build/types/filter-list/base/inputs/SingleDateInput.d.ts.map +1 -1
  406. package/build/types/filter-list/base/inputs/index.d.ts +1 -1
  407. package/build/types/filter-list/base/inputs/index.d.ts.map +1 -1
  408. package/build/types/filter-list/base/inputs/useStableData.d.ts +1 -0
  409. package/build/types/filter-list/base/inputs/useStableData.d.ts.map +1 -0
  410. package/build/types/filter-list/hooks/useFilterVisibility.d.ts +2 -0
  411. package/build/types/filter-list/hooks/useFilterVisibility.d.ts.map +1 -1
  412. package/build/types/filter-list/hooks/usePropertyAggregation.d.ts +2 -2
  413. package/build/types/filter-list/hooks/usePropertyAggregation.d.ts.map +1 -1
  414. package/build/types/filter-list/inputs/CheckboxListFilterInput.d.ts +5 -2
  415. package/build/types/filter-list/inputs/CheckboxListFilterInput.d.ts.map +1 -1
  416. package/build/types/filter-list/inputs/DateRangeFilterInput.d.ts +3 -2
  417. package/build/types/filter-list/inputs/DateRangeFilterInput.d.ts.map +1 -1
  418. package/build/types/filter-list/inputs/LinkedPropertyInput.d.ts +2 -1
  419. package/build/types/filter-list/inputs/LinkedPropertyInput.d.ts.map +1 -1
  420. package/build/types/filter-list/inputs/ListogramFilterInput.d.ts +5 -2
  421. package/build/types/filter-list/inputs/ListogramFilterInput.d.ts.map +1 -1
  422. package/build/types/filter-list/inputs/MultiSelectFilterInput.d.ts +4 -2
  423. package/build/types/filter-list/inputs/MultiSelectFilterInput.d.ts.map +1 -1
  424. package/build/types/filter-list/inputs/NumberRangeFilterInput.d.ts +3 -2
  425. package/build/types/filter-list/inputs/NumberRangeFilterInput.d.ts.map +1 -1
  426. package/build/types/filter-list/inputs/PropertyFilterInput.d.ts +3 -1
  427. package/build/types/filter-list/inputs/PropertyFilterInput.d.ts.map +1 -1
  428. package/build/types/filter-list/inputs/SingleSelectFilterInput.d.ts +4 -2
  429. package/build/types/filter-list/inputs/SingleSelectFilterInput.d.ts.map +1 -1
  430. package/build/types/filter-list/inputs/TextTagsFilterInput.d.ts +4 -2
  431. package/build/types/filter-list/inputs/TextTagsFilterInput.d.ts.map +1 -1
  432. package/build/types/filter-list/utils/filterValues.d.ts +2 -0
  433. package/build/types/filter-list/utils/filterValues.d.ts.map +1 -1
  434. package/build/types/object-table/LoadingCell.d.ts.map +1 -1
  435. package/build/types/object-table/LoadingStateTable.d.ts.map +1 -1
  436. package/build/types/pdf-viewer/PdfRenderer.d.ts +2 -2
  437. package/build/types/pdf-viewer/PdfRenderer.d.ts.map +1 -1
  438. package/build/types/pdf-viewer/PdfViewer.d.ts +1 -1
  439. package/build/types/pdf-viewer/PdfViewer.d.ts.map +1 -1
  440. package/build/types/pdf-viewer/{PdfViewerAnnotationLayer.d.ts → components/PdfViewerAnnotationLayer.d.ts} +2 -3
  441. package/build/types/pdf-viewer/components/PdfViewerAnnotationLayer.d.ts.map +1 -0
  442. package/build/types/pdf-viewer/components/PdfViewerContent.d.ts +22 -0
  443. package/build/types/pdf-viewer/components/PdfViewerContent.d.ts.map +1 -0
  444. package/build/types/pdf-viewer/components/PdfViewerOutlineSidebar.d.ts +11 -0
  445. package/build/types/pdf-viewer/components/PdfViewerOutlineSidebar.d.ts.map +1 -0
  446. package/build/types/pdf-viewer/{PdfViewerSearchBar.d.ts → components/PdfViewerSearchBar.d.ts} +1 -2
  447. package/build/types/pdf-viewer/components/PdfViewerSearchBar.d.ts.map +1 -0
  448. package/build/types/pdf-viewer/components/PdfViewerSidebar.d.ts +12 -0
  449. package/build/types/pdf-viewer/components/PdfViewerSidebar.d.ts.map +1 -0
  450. package/build/types/pdf-viewer/components/PdfViewerSidebarHeader.d.ts +7 -0
  451. package/build/types/pdf-viewer/components/PdfViewerSidebarHeader.d.ts.map +1 -0
  452. package/build/types/pdf-viewer/{PdfViewerThumbnail.d.ts.map → components/PdfViewerThumbnail.d.ts.map} +1 -1
  453. package/build/types/pdf-viewer/{PdfViewerToolbar.d.ts → components/PdfViewerToolbar.d.ts} +5 -3
  454. package/build/types/pdf-viewer/components/PdfViewerToolbar.d.ts.map +1 -0
  455. package/build/types/pdf-viewer/constants.d.ts +5 -0
  456. package/build/types/pdf-viewer/constants.d.ts.map +1 -1
  457. package/build/types/pdf-viewer/hooks/usePdfDocument.d.ts.map +1 -1
  458. package/build/types/pdf-viewer/hooks/usePdfOutline.d.ts +3 -0
  459. package/build/types/pdf-viewer/hooks/usePdfOutline.d.ts.map +1 -0
  460. package/build/types/pdf-viewer/hooks/usePdfViewer.d.ts +1 -1
  461. package/build/types/pdf-viewer/hooks/usePdfViewer.d.ts.map +1 -1
  462. package/build/types/pdf-viewer/hooks/usePdfViewerCore.d.ts +43 -0
  463. package/build/types/pdf-viewer/hooks/usePdfViewerCore.d.ts.map +1 -0
  464. package/build/types/pdf-viewer/hooks/usePdfViewerState.d.ts +39 -0
  465. package/build/types/pdf-viewer/hooks/usePdfViewerState.d.ts.map +1 -0
  466. package/build/types/pdf-viewer/types.d.ts +42 -0
  467. package/build/types/pdf-viewer/types.d.ts.map +1 -1
  468. package/build/types/public/experimental.d.ts +21 -2
  469. package/build/types/public/experimental.d.ts.map +1 -1
  470. package/build/types/public/primitives.d.ts +3 -0
  471. package/build/types/public/primitives.d.ts.map +1 -0
  472. package/build/types/shared/dateUtils.d.ts +31 -0
  473. package/build/types/shared/dateUtils.d.ts.map +1 -0
  474. package/package.json +14 -4
  475. package/primitives.d.ts +17 -0
  476. package/build/browser/filter-list/base/inputs/dateUtils.js.map +0 -1
  477. package/build/browser/filter-list/base/inputs/useStaleData.js.map +0 -1
  478. package/build/browser/pdf-viewer/PdfViewerAnnotationLayer.js.map +0 -1
  479. package/build/browser/pdf-viewer/PdfViewerAnnotationLayer.module.css.js +0 -11
  480. package/build/browser/pdf-viewer/PdfViewerSearchBar.js.map +0 -1
  481. package/build/browser/pdf-viewer/PdfViewerSearchBar.module.css.js +0 -10
  482. package/build/browser/pdf-viewer/PdfViewerSidebar.js.map +0 -1
  483. package/build/browser/pdf-viewer/PdfViewerThumbnail.js.map +0 -1
  484. package/build/browser/pdf-viewer/PdfViewerToolbar.js.map +0 -1
  485. package/build/browser/pdf-viewer/PdfViewerToolbar.module.css.js +0 -12
  486. package/build/esm/filter-list/base/inputs/dateUtils.js.map +0 -1
  487. package/build/esm/filter-list/base/inputs/useStaleData.js.map +0 -1
  488. package/build/esm/pdf-viewer/PdfViewerAnnotationLayer.js.map +0 -1
  489. package/build/esm/pdf-viewer/PdfViewerSearchBar.js.map +0 -1
  490. package/build/esm/pdf-viewer/PdfViewerSidebar.js.map +0 -1
  491. package/build/esm/pdf-viewer/PdfViewerThumbnail.js.map +0 -1
  492. package/build/esm/pdf-viewer/PdfViewerToolbar.js.map +0 -1
  493. package/build/types/filter-list/base/inputs/dateUtils.d.ts +0 -17
  494. package/build/types/filter-list/base/inputs/dateUtils.d.ts.map +0 -1
  495. package/build/types/filter-list/base/inputs/useStaleData.d.ts +0 -1
  496. package/build/types/filter-list/base/inputs/useStaleData.d.ts.map +0 -1
  497. package/build/types/pdf-viewer/PdfViewerAnnotationLayer.d.ts.map +0 -1
  498. package/build/types/pdf-viewer/PdfViewerSearchBar.d.ts.map +0 -1
  499. package/build/types/pdf-viewer/PdfViewerSidebar.d.ts +0 -10
  500. package/build/types/pdf-viewer/PdfViewerSidebar.d.ts.map +0 -1
  501. package/build/types/pdf-viewer/PdfViewerToolbar.d.ts.map +0 -1
  502. /package/build/browser/pdf-viewer/{PdfViewerAnnotationLayer.js → components/PdfViewerAnnotationLayer.js} +0 -0
  503. /package/build/browser/pdf-viewer/{PdfViewerSearchBar.js → components/PdfViewerSearchBar.js} +0 -0
  504. /package/build/browser/pdf-viewer/{PdfViewerSearchBar.module.css → components/PdfViewerSearchBar.module.css} +0 -0
  505. /package/build/browser/pdf-viewer/{PdfViewerThumbnail.module.css → components/PdfViewerThumbnail.module.css} +0 -0
  506. /package/build/esm/pdf-viewer/{PdfViewerAnnotationLayer.js → components/PdfViewerAnnotationLayer.js} +0 -0
  507. /package/build/esm/pdf-viewer/{PdfViewerSearchBar.js → components/PdfViewerSearchBar.js} +0 -0
  508. /package/build/esm/pdf-viewer/{PdfViewerSearchBar.module.css → components/PdfViewerSearchBar.module.css} +0 -0
  509. /package/build/esm/pdf-viewer/{PdfViewerThumbnail.module.css → components/PdfViewerThumbnail.module.css} +0 -0
  510. /package/build/types/pdf-viewer/{PdfViewerThumbnail.d.ts → components/PdfViewerThumbnail.d.ts} +0 -0
@@ -0,0 +1,268 @@
1
+ /*
2
+ * Copyright 2025 Palantir Technologies, Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import { useEffect, useState } from "react";
18
+ import { OUTLINE_HEADING_SIZE_RATIO, OUTLINE_MAX_HEADING_LENGTH } from "../constants.js";
19
+ const EMPTY_OUTLINE = [];
20
+ export function usePdfOutline(document) {
21
+ const [outlineItems, setOutlineItems] = useState(EMPTY_OUTLINE);
22
+ useEffect(function () {
23
+ if (document == null) {
24
+ setOutlineItems(EMPTY_OUTLINE);
25
+ return;
26
+ }
27
+ let cancelled = false;
28
+ void (async () => {
29
+ try {
30
+ // Try embedded bookmarks first
31
+ const outline = await document.getOutline();
32
+ if (cancelled) return;
33
+ if (outline != null && outline.length > 0) {
34
+ const items = await resolveBookmarkOutline(document, outline);
35
+ if (!cancelled) {
36
+ setOutlineItems(items);
37
+ }
38
+ return;
39
+ }
40
+
41
+ // Fall back to extracting headings from text content
42
+ const items = await extractHeadingsFromText(document);
43
+ if (!cancelled) {
44
+ setOutlineItems(items.length > 0 ? items : EMPTY_OUTLINE);
45
+ }
46
+ } catch {
47
+ // If extraction fails entirely, leave outline empty
48
+ if (!cancelled) {
49
+ setOutlineItems(EMPTY_OUTLINE);
50
+ }
51
+ }
52
+ })();
53
+ return () => {
54
+ cancelled = true;
55
+ };
56
+ }, [document]);
57
+ return outlineItems;
58
+ }
59
+ async function resolveBookmarkOutline(document, outline) {
60
+ const items = [];
61
+ const resolveItems = async (nodes, depth) => {
62
+ for (const node of nodes) {
63
+ let pageNumber = 1;
64
+ try {
65
+ if (typeof node.dest === "string") {
66
+ const dest = await document.getDestination(node.dest);
67
+ if (dest != null) {
68
+ const pageIndex = await document.getPageIndex(dest[0]);
69
+ pageNumber = pageIndex + 1;
70
+ }
71
+ } else if (Array.isArray(node.dest) && node.dest.length > 0) {
72
+ const pageIndex = await document.getPageIndex(node.dest[0]);
73
+ pageNumber = pageIndex + 1;
74
+ }
75
+ } catch {
76
+ // If destination resolution fails, default to page 1
77
+ }
78
+ items.push({
79
+ title: node.title,
80
+ depth,
81
+ pageNumber,
82
+ bold: node.bold,
83
+ italic: node.italic
84
+ });
85
+ if (node.items.length > 0) {
86
+ await resolveItems(node.items, depth + 1);
87
+ }
88
+ }
89
+ };
90
+ await resolveItems(outline, 0);
91
+ return items;
92
+ }
93
+ function isTextItem(item) {
94
+ return "str" in item && "transform" in item;
95
+ }
96
+ function roundFontSize(size) {
97
+ return Math.round(size * 10) / 10;
98
+ }
99
+
100
+ /**
101
+ * Extract the font size from a pdfjs TextItem.
102
+ * Prefer `height` when available, otherwise derive from the transform matrix.
103
+ * The transform is [scaleX, skewY, skewX, scaleY, translateX, translateY].
104
+ * Font size = sqrt(skewX² + scaleY²), which handles rotated text too.
105
+ */
106
+ function getFontSize(item) {
107
+ if (item.height > 0) {
108
+ return item.height;
109
+ }
110
+ const transform = item.transform;
111
+ if (Array.isArray(transform) && transform.length >= 4) {
112
+ return Math.sqrt(transform[2] * transform[2] + transform[3] * transform[3]);
113
+ }
114
+ return 0;
115
+ }
116
+ async function extractHeadingsFromText(document) {
117
+ const numPages = document.numPages;
118
+
119
+ // Fetch all pages' text content in parallel
120
+ const pageContents = await Promise.all(Array.from({
121
+ length: numPages
122
+ }, (_, i) => document.getPage(i + 1).then(page => page.getTextContent())));
123
+
124
+ // Collect font size frequencies across all pages
125
+ const sizeCounts = new Map();
126
+ for (const textContent of pageContents) {
127
+ for (const rawItem of textContent.items) {
128
+ const item = rawItem;
129
+ if (!isTextItem(item) || item.str.trim().length === 0) {
130
+ continue;
131
+ }
132
+ const fontSize = getFontSize(item);
133
+ if (fontSize > 0) {
134
+ const rounded = roundFontSize(fontSize);
135
+ sizeCounts.set(rounded, (sizeCounts.get(rounded) ?? 0) + 1);
136
+ }
137
+ }
138
+ }
139
+
140
+ // Find the most common font size (body text)
141
+ let bodySize = 0;
142
+ let maxCount = 0;
143
+ for (const [size, count] of sizeCounts) {
144
+ if (count > maxCount) {
145
+ maxCount = count;
146
+ bodySize = size;
147
+ }
148
+ }
149
+ if (bodySize === 0) {
150
+ return [];
151
+ }
152
+
153
+ // Heading threshold: text significantly larger than body text
154
+ const headingThreshold = bodySize * OUTLINE_HEADING_SIZE_RATIO;
155
+
156
+ // Collect all unique heading sizes above threshold
157
+ const headingSizes = new Set();
158
+ for (const [size] of sizeCounts) {
159
+ if (size >= headingThreshold) {
160
+ headingSizes.add(size);
161
+ }
162
+ }
163
+ if (headingSizes.size === 0) {
164
+ return [];
165
+ }
166
+
167
+ // Sort heading sizes descending (largest = depth 0)
168
+ const sortedSizes = [...headingSizes].sort((a, b) => b - a);
169
+ const sizeToDepth = new Map();
170
+ for (let i = 0; i < sortedSizes.length; i++) {
171
+ sizeToDepth.set(sortedSizes[i], i);
172
+ }
173
+
174
+ // Extract headings with page numbers.
175
+ // pdfjs splits visual lines into multiple TextItems (e.g. "1." and
176
+ // "Introduction" are separate items). We accumulate all items on the
177
+ // same visual line and treat the line as a heading if most of its
178
+ // content is at a heading font size.
179
+ const candidateHeadings = [];
180
+ for (let pageIdx = 0; pageIdx < pageContents.length; pageIdx++) {
181
+ const textContent = pageContents[pageIdx];
182
+ const pageNumber = pageIdx + 1;
183
+ let lineItems = [];
184
+ let linePageNumber = pageNumber;
185
+ let lineFontName = "";
186
+ let lineHeadingFontSize = 0;
187
+ let lastFlushWasHeading = false;
188
+ const flushLine = () => {
189
+ if (lineItems.length === 0) return;
190
+
191
+ // Check if the majority of the line's non-whitespace content is heading-sized
192
+ let headingChars = 0;
193
+ let totalChars = 0;
194
+ for (const li of lineItems) {
195
+ const len = li.text.trim().length;
196
+ totalChars += len;
197
+ if (sizeToDepth.has(roundFontSize(li.fontSize))) {
198
+ headingChars += len;
199
+ }
200
+ }
201
+ if (totalChars > 0 && headingChars / totalChars > 0.5) {
202
+ const fullText = lineItems.map(li => li.text).join("").trim();
203
+ if (fullText.length > 0) {
204
+ candidateHeadings.push({
205
+ text: fullText,
206
+ fontSize: lineHeadingFontSize,
207
+ pageNumber: linePageNumber,
208
+ fontName: lineFontName,
209
+ contiguous: lastFlushWasHeading
210
+ });
211
+ }
212
+ lastFlushWasHeading = true;
213
+ } else {
214
+ lastFlushWasHeading = false;
215
+ }
216
+ lineItems = [];
217
+ lineHeadingFontSize = 0;
218
+ };
219
+ for (const rawItem of textContent.items) {
220
+ const item = rawItem;
221
+ if (!isTextItem(item)) {
222
+ continue;
223
+ }
224
+ const fontSize = getFontSize(item);
225
+ const rounded = roundFontSize(fontSize);
226
+ const isHeadingSized = sizeToDepth.has(rounded);
227
+ if (isHeadingSized && lineHeadingFontSize === 0) {
228
+ lineHeadingFontSize = rounded;
229
+ linePageNumber = pageNumber;
230
+ lineFontName = item.fontName;
231
+ }
232
+ if (lineHeadingFontSize > 0) {
233
+ lineItems.push({
234
+ text: item.str,
235
+ fontSize
236
+ });
237
+ }
238
+ if (item.hasEOL) {
239
+ flushLine();
240
+ }
241
+ }
242
+
243
+ // Flush remaining items at end of page
244
+ flushLine();
245
+ }
246
+
247
+ // Merge consecutive heading lines that were contiguous (no body text between them)
248
+ // and at the same font size. This joins multi-line titles that wrap in the PDF.
249
+ const mergedHeadings = [];
250
+ for (const heading of candidateHeadings) {
251
+ const prev = mergedHeadings[mergedHeadings.length - 1];
252
+ if (prev != null && heading.contiguous && Math.abs(prev.fontSize - heading.fontSize) < 0.1) {
253
+ prev.text += " " + heading.text;
254
+ } else {
255
+ mergedHeadings.push({
256
+ ...heading
257
+ });
258
+ }
259
+ }
260
+ return mergedHeadings.filter(heading => heading.text.trim().length <= OUTLINE_MAX_HEADING_LENGTH).map(heading => ({
261
+ title: heading.text.trim(),
262
+ depth: sizeToDepth.get(heading.fontSize) ?? 0,
263
+ pageNumber: heading.pageNumber,
264
+ bold: false,
265
+ italic: false
266
+ }));
267
+ }
268
+ //# sourceMappingURL=usePdfOutline.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePdfOutline.js","names":["useEffect","useState","OUTLINE_HEADING_SIZE_RATIO","OUTLINE_MAX_HEADING_LENGTH","EMPTY_OUTLINE","usePdfOutline","document","outlineItems","setOutlineItems","cancelled","outline","getOutline","length","items","resolveBookmarkOutline","extractHeadingsFromText","resolveItems","nodes","depth","node","pageNumber","dest","getDestination","pageIndex","getPageIndex","Array","isArray","push","title","bold","italic","isTextItem","item","roundFontSize","size","Math","round","getFontSize","height","transform","sqrt","numPages","pageContents","Promise","all","from","_","i","getPage","then","page","getTextContent","sizeCounts","Map","textContent","rawItem","str","trim","fontSize","rounded","set","get","bodySize","maxCount","count","headingThreshold","headingSizes","Set","add","sortedSizes","sort","a","b","sizeToDepth","candidateHeadings","pageIdx","lineItems","linePageNumber","lineFontName","lineHeadingFontSize","lastFlushWasHeading","flushLine","headingChars","totalChars","li","len","text","has","fullText","map","join","fontName","contiguous","isHeadingSized","hasEOL","mergedHeadings","heading","prev","abs","filter"],"sources":["usePdfOutline.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { PDFDocumentProxy } from \"pdfjs-dist\";\nimport { useEffect, useState } from \"react\";\nimport {\n OUTLINE_HEADING_SIZE_RATIO,\n OUTLINE_MAX_HEADING_LENGTH,\n} from \"../constants.js\";\nimport type { OutlineItem } from \"../types.js\";\n\nconst EMPTY_OUTLINE: OutlineItem[] = [];\n\nexport function usePdfOutline(\n document: PDFDocumentProxy | undefined,\n): OutlineItem[] {\n const [outlineItems, setOutlineItems] = useState<OutlineItem[]>(\n EMPTY_OUTLINE,\n );\n\n useEffect(\n function loadOutline() {\n if (document == null) {\n setOutlineItems(EMPTY_OUTLINE);\n return;\n }\n\n let cancelled = false;\n\n void (async () => {\n try {\n // Try embedded bookmarks first\n const outline = await document.getOutline();\n if (cancelled) return;\n\n if (outline != null && outline.length > 0) {\n const items = await resolveBookmarkOutline(document, outline);\n if (!cancelled) {\n setOutlineItems(items);\n }\n return;\n }\n\n // Fall back to extracting headings from text content\n const items = await extractHeadingsFromText(document);\n if (!cancelled) {\n setOutlineItems(items.length > 0 ? items : EMPTY_OUTLINE);\n }\n } catch {\n // If extraction fails entirely, leave outline empty\n if (!cancelled) {\n setOutlineItems(EMPTY_OUTLINE);\n }\n }\n })();\n\n return () => {\n cancelled = true;\n };\n },\n [document],\n );\n\n return outlineItems;\n}\n\ntype BookmarkNode = Awaited<ReturnType<PDFDocumentProxy[\"getOutline\"]>>[number];\n\nasync function resolveBookmarkOutline(\n document: PDFDocumentProxy,\n outline: BookmarkNode[],\n): Promise<OutlineItem[]> {\n const items: OutlineItem[] = [];\n\n const resolveItems = async (\n nodes: BookmarkNode[],\n depth: number,\n ): Promise<void> => {\n for (const node of nodes) {\n let pageNumber = 1;\n try {\n if (typeof node.dest === \"string\") {\n const dest = await document.getDestination(node.dest);\n if (dest != null) {\n const pageIndex = await document.getPageIndex(dest[0]);\n pageNumber = pageIndex + 1;\n }\n } else if (Array.isArray(node.dest) && node.dest.length > 0) {\n const pageIndex = await document.getPageIndex(node.dest[0]);\n pageNumber = pageIndex + 1;\n }\n } catch {\n // If destination resolution fails, default to page 1\n }\n\n items.push({\n title: node.title,\n depth,\n pageNumber,\n bold: node.bold,\n italic: node.italic,\n });\n\n if (node.items.length > 0) {\n await resolveItems(node.items, depth + 1);\n }\n }\n };\n\n await resolveItems(outline, 0);\n return items;\n}\n\ninterface RawHeading {\n text: string;\n fontSize: number;\n pageNumber: number;\n fontName: string;\n /** True if this heading line immediately followed another heading line (no body text in between). */\n contiguous: boolean;\n}\n\ninterface TextItemLike {\n str: string;\n height: number;\n fontName: string;\n transform: number[];\n hasEOL: boolean;\n}\n\nfunction isTextItem(\n item: Record<string, unknown>,\n): item is Record<string, unknown> & TextItemLike {\n return \"str\" in item && \"transform\" in item;\n}\n\nfunction roundFontSize(size: number): number {\n return Math.round(size * 10) / 10;\n}\n\n/**\n * Extract the font size from a pdfjs TextItem.\n * Prefer `height` when available, otherwise derive from the transform matrix.\n * The transform is [scaleX, skewY, skewX, scaleY, translateX, translateY].\n * Font size = sqrt(skewX² + scaleY²), which handles rotated text too.\n */\nfunction getFontSize(item: TextItemLike): number {\n if (item.height > 0) {\n return item.height;\n }\n const transform = item.transform;\n if (Array.isArray(transform) && transform.length >= 4) {\n return Math.sqrt(\n (transform[2]) * (transform[2])\n + (transform[3]) * (transform[3]),\n );\n }\n return 0;\n}\n\nasync function extractHeadingsFromText(\n document: PDFDocumentProxy,\n): Promise<OutlineItem[]> {\n const numPages = document.numPages;\n\n // Fetch all pages' text content in parallel\n const pageContents = await Promise.all(\n Array.from(\n { length: numPages },\n (_, i) => document.getPage(i + 1).then(page => page.getTextContent()),\n ),\n );\n\n // Collect font size frequencies across all pages\n const sizeCounts = new Map<number, number>();\n for (const textContent of pageContents) {\n for (const rawItem of textContent.items) {\n const item = rawItem as Record<string, unknown>;\n if (!isTextItem(item) || item.str.trim().length === 0) {\n continue;\n }\n const fontSize = getFontSize(item);\n if (fontSize > 0) {\n const rounded = roundFontSize(fontSize);\n sizeCounts.set(rounded, (sizeCounts.get(rounded) ?? 0) + 1);\n }\n }\n }\n\n // Find the most common font size (body text)\n let bodySize = 0;\n let maxCount = 0;\n for (const [size, count] of sizeCounts) {\n if (count > maxCount) {\n maxCount = count;\n bodySize = size;\n }\n }\n\n if (bodySize === 0) {\n return [];\n }\n\n // Heading threshold: text significantly larger than body text\n const headingThreshold = bodySize * OUTLINE_HEADING_SIZE_RATIO;\n\n // Collect all unique heading sizes above threshold\n const headingSizes = new Set<number>();\n for (const [size] of sizeCounts) {\n if (size >= headingThreshold) {\n headingSizes.add(size);\n }\n }\n\n if (headingSizes.size === 0) {\n return [];\n }\n\n // Sort heading sizes descending (largest = depth 0)\n const sortedSizes = [...headingSizes].sort((a, b) => b - a);\n const sizeToDepth = new Map<number, number>();\n for (let i = 0; i < sortedSizes.length; i++) {\n sizeToDepth.set(sortedSizes[i], i);\n }\n\n // Extract headings with page numbers.\n // pdfjs splits visual lines into multiple TextItems (e.g. \"1.\" and\n // \"Introduction\" are separate items). We accumulate all items on the\n // same visual line and treat the line as a heading if most of its\n // content is at a heading font size.\n const candidateHeadings: RawHeading[] = [];\n\n for (let pageIdx = 0; pageIdx < pageContents.length; pageIdx++) {\n const textContent = pageContents[pageIdx];\n const pageNumber = pageIdx + 1;\n\n let lineItems: Array<{ text: string; fontSize: number }> = [];\n let linePageNumber = pageNumber;\n let lineFontName = \"\";\n let lineHeadingFontSize = 0;\n let lastFlushWasHeading = false;\n\n const flushLine = (): void => {\n if (lineItems.length === 0) return;\n\n // Check if the majority of the line's non-whitespace content is heading-sized\n let headingChars = 0;\n let totalChars = 0;\n for (const li of lineItems) {\n const len = li.text.trim().length;\n totalChars += len;\n if (sizeToDepth.has(roundFontSize(li.fontSize))) {\n headingChars += len;\n }\n }\n\n if (totalChars > 0 && headingChars / totalChars > 0.5) {\n const fullText = lineItems.map((li) => li.text).join(\"\").trim();\n if (fullText.length > 0) {\n candidateHeadings.push({\n text: fullText,\n fontSize: lineHeadingFontSize,\n pageNumber: linePageNumber,\n fontName: lineFontName,\n contiguous: lastFlushWasHeading,\n });\n }\n lastFlushWasHeading = true;\n } else {\n lastFlushWasHeading = false;\n }\n\n lineItems = [];\n lineHeadingFontSize = 0;\n };\n\n for (const rawItem of textContent.items) {\n const item = rawItem as Record<string, unknown>;\n if (!isTextItem(item)) {\n continue;\n }\n\n const fontSize = getFontSize(item);\n const rounded = roundFontSize(fontSize);\n const isHeadingSized = sizeToDepth.has(rounded);\n\n if (isHeadingSized && lineHeadingFontSize === 0) {\n lineHeadingFontSize = rounded;\n linePageNumber = pageNumber;\n lineFontName = item.fontName;\n }\n\n if (lineHeadingFontSize > 0) {\n lineItems.push({ text: item.str, fontSize });\n }\n\n if (item.hasEOL) {\n flushLine();\n }\n }\n\n // Flush remaining items at end of page\n flushLine();\n }\n\n // Merge consecutive heading lines that were contiguous (no body text between them)\n // and at the same font size. This joins multi-line titles that wrap in the PDF.\n const mergedHeadings: RawHeading[] = [];\n for (const heading of candidateHeadings) {\n const prev = mergedHeadings[mergedHeadings.length - 1];\n if (\n prev != null\n && heading.contiguous\n && Math.abs(prev.fontSize - heading.fontSize) < 0.1\n ) {\n prev.text += \" \" + heading.text;\n } else {\n mergedHeadings.push({ ...heading });\n }\n }\n\n return mergedHeadings\n .filter((heading) =>\n heading.text.trim().length <= OUTLINE_MAX_HEADING_LENGTH\n )\n .map((heading) => ({\n title: heading.text.trim(),\n depth: sizeToDepth.get(heading.fontSize) ?? 0,\n pageNumber: heading.pageNumber,\n bold: false,\n italic: false,\n }));\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAC3C,SACEC,0BAA0B,EAC1BC,0BAA0B,QACrB,iBAAiB;AAGxB,MAAMC,aAA4B,GAAG,EAAE;AAEvC,OAAO,SAASC,aAAaA,CAC3BC,QAAsC,EACvB;EACf,MAAM,CAACC,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I,GAAGF,cAAc,CAACA,cAAc,CAACnF,MAAM,GAAG,CAAC,CAAC;IACtD,IACEqF,IAAI,IAAI,IAAI,IACTD,OAAO,CAACJ,UAAU,IAClBzD,IAAI,CAAC+D,GAAG,CAACD,IAAI,CAACvC,QAAQ,GAAGsC,OAAO,CAACtC,QAAQ,CAAC,GAAG,GAAG,EACnD;MACAuC,IAAI,CAACX,IAAI,IAAI,GAAG,GAAGU,OAAO,CAACV,IAAI;IACjC,CAAC,MAAM;MACLS,cAAc,CAACpE,IAAI,CAAC;QAAE,GAAGqE;MAAQ,CAAC,CAAC;IACrC;EACF;EAEA,OAAOD,cAAc,CAClBI,MAAM,CAAEH,OAAO,IACdA,OAAO,CAACV,IAAI,CAAC7B,IAAI,CAAC,CAAC,CAAC7C,MAAM,IAAIT,0BAChC,CAAC,CACAsF,GAAG,CAAEO,OAAO,KAAM;IACjBpE,KAAK,EAAEoE,OAAO,CAACV,IAAI,CAAC7B,IAAI,CAAC,CAAC;IAC1BvC,KAAK,EAAEuD,WAAW,CAACZ,GAAG,CAACmC,OAAO,CAACtC,QAAQ,CAAC,IAAI,CAAC;IAC7CtC,UAAU,EAAE4E,OAAO,CAAC5E,UAAU;IAC9BS,IAAI,EAAE,KAAK;IACXC,MAAM,EAAE;EACV,CAAC,CAAC,CAAC;AACP","ignoreList":[]}
@@ -16,7 +16,8 @@
16
16
 
17
17
  import { EventBus, PDFFindController, PDFLinkService, PDFViewer } from "pdfjs-dist/web/pdf_viewer.mjs";
18
18
  import { useEffect, useRef } from "react";
19
- export function usePdfViewer(containerRef, viewerRef, document, initialScale) {
19
+ import { PAGES_LOADED_EVENT } from "../constants.js";
20
+ export function usePdfViewer(containerRef, viewerRef, document, initialScale, initialPage) {
20
21
  const pdfViewerRef = useRef(null);
21
22
  const eventBusRef = useRef(null);
22
23
  const findControllerRef = useRef(null);
@@ -50,6 +51,16 @@ export function usePdfViewer(containerRef, viewerRef, document, initialScale) {
50
51
  if (initialScale != null) {
51
52
  pdfViewer.currentScale = initialScale;
52
53
  }
54
+ if (initialPage != null && initialPage > 1) {
55
+ const onPagesLoaded = () => {
56
+ pdfViewer.currentPageNumber = initialPage;
57
+ pdfViewer.scrollPageIntoView({
58
+ pageNumber: initialPage
59
+ });
60
+ eventBus.off(PAGES_LOADED_EVENT, onPagesLoaded);
61
+ };
62
+ eventBus.on(PAGES_LOADED_EVENT, onPagesLoaded);
63
+ }
53
64
  eventBusRef.current = eventBus;
54
65
  findControllerRef.current = findController;
55
66
  pdfViewerRef.current = pdfViewer;
@@ -1 +1 @@
1
- {"version":3,"file":"usePdfViewer.js","names":["EventBus","PDFFindController","PDFLinkService","PDFViewer","useEffect","useRef","usePdfViewer","containerRef","viewerRef","document","initialScale","pdfViewerRef","eventBusRef","findControllerRef","container","current","viewer","eventBus","linkService","findController","updateMatchesCountOnProgress","pdfViewer","removePageBorders","setViewer","setDocument","currentScale","cleanup"],"sources":["usePdfViewer.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { PDFDocumentProxy } from \"pdfjs-dist\";\nimport {\n EventBus,\n PDFFindController,\n PDFLinkService,\n PDFViewer,\n} from \"pdfjs-dist/web/pdf_viewer.mjs\";\nimport type { RefObject } from \"react\";\nimport { useEffect, useRef } from \"react\";\n\nexport interface UsePdfViewerResult {\n pdfViewerRef: RefObject<PDFViewer | null>;\n eventBusRef: RefObject<EventBus | null>;\n findControllerRef: RefObject<PDFFindController | null>;\n}\n\nexport function usePdfViewer(\n containerRef: RefObject<HTMLDivElement | null>,\n viewerRef: RefObject<HTMLDivElement | null>,\n document: PDFDocumentProxy | undefined,\n initialScale?: number,\n): UsePdfViewerResult {\n const pdfViewerRef = useRef<PDFViewer | null>(null);\n const eventBusRef = useRef<EventBus | null>(null);\n const findControllerRef = useRef<PDFFindController | null>(null);\n\n useEffect(function initializePdfViewer() {\n const container = containerRef.current;\n const viewer = viewerRef.current;\n if (container == null || viewer == null || document == null) {\n return;\n }\n\n const eventBus = new EventBus();\n const linkService = new PDFLinkService({ eventBus });\n const findController = new PDFFindController({\n linkService,\n eventBus,\n updateMatchesCountOnProgress: true,\n });\n\n const pdfViewer = new PDFViewer({\n container,\n viewer,\n eventBus,\n linkService,\n findController,\n removePageBorders: true,\n });\n\n linkService.setViewer(pdfViewer);\n linkService.setDocument(document);\n findController.setDocument(document);\n pdfViewer.setDocument(document);\n\n if (initialScale != null) {\n pdfViewer.currentScale = initialScale;\n }\n\n eventBusRef.current = eventBus;\n findControllerRef.current = findController;\n pdfViewerRef.current = pdfViewer;\n\n return () => {\n pdfViewerRef.current = null;\n eventBusRef.current = null;\n findControllerRef.current = null;\n pdfViewer.cleanup();\n };\n }, [containerRef, viewerRef, document]);\n\n return { pdfViewerRef, eventBusRef, findControllerRef };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SACEA,QAAQ,EACRC,iBAAiB,EACjBC,cAAc,EACdC,SAAS,QACJ,+BAA+B;AAEtC,SAASC,SAAS,EAAEC,MAAM,QAAQ,OAAO;AAQzC,OAAO,SAASC,YAAYA,CAC1BC,YAA8C,EAC9CC,SAA2C,EAC3CC,QAAsC,EACtCC,YAAqB,EACD;EACpB,MAAMC,YAAY,GAAGN,MAAM,CAAmB,IAAI,CAAC;EACnD,MAAMO,WAAW,GAAGP,MAAM,CAAkB,IAAI,CAAC;EACjD,MAAMQ,iBAAiB,GAAGR,MAAM,CAA2B,IAAI,CAAC;EAEhED,SAAS,CAAC,YA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AAO;IAAEE,YAAY;IAAEC,WAAW;IAAEC;EAAkB,CAAC;AACzD","ignoreList":[]}
1
+ {"version":3,"file":"usePdfViewer.js","names":["EventBus","PDFFindController","PDFLinkService","PDFViewer","useEffect","useRef","PAGES_LOADED_EVENT","usePdfViewer","containerRef","viewerRef","document","initialScale","initialPage","pdfViewerRef","eventBusRef","findControllerRef","container","current","viewer","eventBus","linkService","findController","updateMatchesCountOnProgress","pdfViewer","removePageBorders","setViewer","setDocument","currentScale","onPagesLoaded","currentPageNumber","scrollPageIntoView","pageNumber","off","on","cleanup"],"sources":["usePdfViewer.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { PDFDocumentProxy } from \"pdfjs-dist\";\nimport {\n EventBus,\n PDFFindController,\n PDFLinkService,\n PDFViewer,\n} from \"pdfjs-dist/web/pdf_viewer.mjs\";\nimport type { RefObject } from \"react\";\nimport { useEffect, useRef } from \"react\";\nimport { PAGES_LOADED_EVENT } from \"../constants.js\";\n\nexport interface UsePdfViewerResult {\n pdfViewerRef: RefObject<PDFViewer | null>;\n eventBusRef: RefObject<EventBus | null>;\n findControllerRef: RefObject<PDFFindController | null>;\n}\n\nexport function usePdfViewer(\n containerRef: RefObject<HTMLDivElement | null>,\n viewerRef: RefObject<HTMLDivElement | null>,\n document: PDFDocumentProxy | undefined,\n initialScale?: number,\n initialPage?: number,\n): UsePdfViewerResult {\n const pdfViewerRef = useRef<PDFViewer | null>(null);\n const eventBusRef = useRef<EventBus | null>(null);\n const findControllerRef = useRef<PDFFindController | null>(null);\n\n useEffect(function initializePdfViewer() {\n const container = containerRef.current;\n const viewer = viewerRef.current;\n if (container == null || viewer == null || document == null) {\n return;\n }\n\n const eventBus = new EventBus();\n const linkService = new PDFLinkService({ eventBus });\n const findController = new PDFFindController({\n linkService,\n eventBus,\n updateMatchesCountOnProgress: true,\n });\n\n const pdfViewer = new PDFViewer({\n container,\n viewer,\n eventBus,\n linkService,\n findController,\n removePageBorders: true,\n });\n\n linkService.setViewer(pdfViewer);\n linkService.setDocument(document);\n findController.setDocument(document);\n pdfViewer.setDocument(document);\n\n if (initialScale != null) {\n pdfViewer.currentScale = initialScale;\n }\n\n if (initialPage != null && initialPage > 1) {\n const onPagesLoaded = () => {\n pdfViewer.currentPageNumber = initialPage;\n pdfViewer.scrollPageIntoView({ pageNumber: initialPage });\n eventBus.off(PAGES_LOADED_EVENT, onPagesLoaded);\n };\n eventBus.on(PAGES_LOADED_EVENT, onPagesLoaded);\n }\n\n eventBusRef.current = eventBus;\n findControllerRef.current = findController;\n pdfViewerRef.current = pdfViewer;\n\n return () => {\n pdfViewerRef.current = null;\n eventBusRef.current = null;\n findControllerRef.current = null;\n pdfViewer.cleanup();\n };\n }, [containerRef, viewerRef, document]);\n\n return { pdfViewerRef, eventBusRef, findControllerRef };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SACEA,QAAQ,EACRC,iBAAiB,EACjBC,cAAc,EACdC,SAAS,QACJ,+BAA+B;AAEtC,SAASC,SAAS,EAAEC,MAAM,QAAQ,OAAO;AACzC,SAASC,kBAAkB,QAAQ,iBAAiB;AAQpD,OAAO,SAASC,YAAYA,CAC1BC,YAA8C,EAC9CC,SAA2C,EAC3CC,QAAsC,EACtCC,YAAqB,EACrBC,WAAoB,EACA;EACpB,MAAMC,YAAY,GAAGR,MAAM,CAAmB,IAAI,CAAC;EACnD,MAAMS,WAAW,GAAGT,MAAM,CAAkB,IAAI,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DT,QAAQ,CAACc,EAAE,CAAC3B,kBAAkB,EAAEsB,aAAa,CAAC;IAChD;IAEAd,WAAW,CAACG,OAAO,GAAGE,QAAQ;IAC9BJ,iBAAiB,CAACE,OAAO,GAAGI,cAAc;IAC1CR,YAAY,CAACI,OAAO,GAAGM,SAAS;IAEhC,OAAO,MAAM;MACXV,YAAY,CAACI,OAAO,GAAG,IAAI;MAC3BH,WAAW,CAACG,OAAO,GAAG,IAAI;MAC1BF,iBAAiB,CAACE,OAAO,GAAG,IAAI;MAChCM,SAAS,CAACW,OAAO,CAAC,CAAC;IACrB,CAAC;EACH,CAAC,EAAE,CAAC1B,YAAY,EAAEC,SAAS,EAAEC,QAAQ,CAAC,CAAC;EAEvC,OAAO;IAAEG,YAAY;IAAEC,WAAW;IAAEC;EAAkB,CAAC;AACzD","ignoreList":[]}
@@ -0,0 +1,80 @@
1
+ /*
2
+ * Copyright 2025 Palantir Technologies, Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import { useCallback, useRef, useState } from "react";
18
+ import { usePdfAnnotationPortals } from "./usePdfAnnotationPortals.js";
19
+ import { usePdfDocument } from "./usePdfDocument.js";
20
+ import { usePdfViewer } from "./usePdfViewer.js";
21
+ import { usePdfViewerSync } from "./usePdfViewerSync.js";
22
+ export function usePdfViewerCore({
23
+ src,
24
+ initialPage = 1,
25
+ initialScale = 1.0
26
+ }) {
27
+ const {
28
+ document,
29
+ numPages,
30
+ loading,
31
+ error
32
+ } = usePdfDocument(src);
33
+ const [scale, setScale] = useState(initialScale);
34
+ const [currentPage, setCurrentPage] = useState(initialPage);
35
+ const containerRef = useRef(null);
36
+ const viewerRef = useRef(null);
37
+ const {
38
+ pdfViewerRef,
39
+ eventBusRef,
40
+ findControllerRef
41
+ } = usePdfViewer(containerRef, viewerRef, document, initialScale, initialPage);
42
+ const handleScaleChange = useCallback(newScale => {
43
+ setScale(newScale);
44
+ }, []);
45
+ const handlePageChange = useCallback(page => {
46
+ setCurrentPage(page);
47
+ }, []);
48
+ const {
49
+ scrollToPage: syncScrollToPage
50
+ } = usePdfViewerSync({
51
+ pdfViewerRef,
52
+ eventBusRef,
53
+ document,
54
+ scale,
55
+ onScaleChange: handleScaleChange,
56
+ onPageChange: handlePageChange
57
+ });
58
+ const scrollToPage = useCallback(page => {
59
+ setCurrentPage(page);
60
+ syncScrollToPage(page);
61
+ }, [syncScrollToPage]);
62
+ const portalTargets = usePdfAnnotationPortals(pdfViewerRef, eventBusRef, document);
63
+ return {
64
+ document,
65
+ numPages,
66
+ loading,
67
+ error,
68
+ containerRef,
69
+ viewerRef,
70
+ currentPage,
71
+ scrollToPage,
72
+ scale,
73
+ setScale,
74
+ portalTargets,
75
+ pdfViewerRef,
76
+ eventBusRef,
77
+ findControllerRef
78
+ };
79
+ }
80
+ //# sourceMappingURL=usePdfViewerCore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePdfViewerCore.js","names":["useCallback","useRef","useState","usePdfAnnotationPortals","usePdfDocument","usePdfViewer","usePdfViewerSync","usePdfViewerCore","src","initialPage","initialScale","document","numPages","loading","error","scale","setScale","currentPage","setCurrentPage","containerRef","viewerRef","pdfViewerRef","eventBusRef","findControllerRef","handleScaleChange","newScale","handlePageChange","page","scrollToPage","syncScrollToPage","onScaleChange","onPageChange","portalTargets"],"sources":["usePdfViewerCore.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { PDFDocumentProxy } from \"pdfjs-dist\";\nimport type {\n EventBus,\n PDFFindController,\n PDFViewer,\n} from \"pdfjs-dist/web/pdf_viewer.mjs\";\nimport type { RefObject } from \"react\";\nimport { useCallback, useRef, useState } from \"react\";\nimport type { AnnotationPortalTarget } from \"./usePdfAnnotationPortals.js\";\nimport { usePdfAnnotationPortals } from \"./usePdfAnnotationPortals.js\";\nimport { usePdfDocument } from \"./usePdfDocument.js\";\nimport { usePdfViewer } from \"./usePdfViewer.js\";\nimport { usePdfViewerSync } from \"./usePdfViewerSync.js\";\n\nexport interface UsePdfViewerCoreOptions {\n /** PDF source — URL string or ArrayBuffer */\n src: string | ArrayBuffer;\n /** Initial page number (1-indexed, default 1) */\n initialPage?: number;\n /** Initial zoom scale (default 1.0) */\n initialScale?: number;\n}\n\nexport interface UsePdfViewerCoreResult {\n /** The loaded PDF document, or undefined while loading */\n document: PDFDocumentProxy | undefined;\n /** Total number of pages in the document */\n numPages: number;\n /** Whether the document is currently loading */\n loading: boolean;\n /** Error encountered while loading the document */\n error: Error | undefined;\n\n /** Ref to attach to the scroll-container div */\n containerRef: RefObject<HTMLDivElement>;\n /** Ref to attach to the inner viewer div (className=\"pdfViewer\") */\n viewerRef: RefObject<HTMLDivElement>;\n\n /** Current page number (1-indexed) */\n currentPage: number;\n /** Navigate to a specific page (updates state and scrolls the viewer) */\n scrollToPage: (page: number) => void;\n\n /** Current zoom scale */\n scale: number;\n /** Set the zoom scale directly */\n setScale: (scale: number) => void;\n\n /** Portal targets for rendering annotation overlays on each page */\n portalTargets: AnnotationPortalTarget[];\n\n /** Ref to the internal pdfjs PDFViewer instance */\n pdfViewerRef: RefObject<PDFViewer | null>;\n /** Ref to the internal pdfjs EventBus instance */\n eventBusRef: RefObject<EventBus | null>;\n /** Ref to the internal pdfjs PDFFindController instance */\n findControllerRef: RefObject<PDFFindController | null>;\n}\n\nexport function usePdfViewerCore({\n src,\n initialPage = 1,\n initialScale = 1.0,\n}: UsePdfViewerCoreOptions): UsePdfViewerCoreResult {\n const { document, numPages, loading, error } = usePdfDocument(src);\n const [scale, setScale] = useState(initialScale);\n const [currentPage, setCurrentPage] = useState(initialPage);\n const containerRef = useRef<HTMLDivElement>(null);\n const viewerRef = useRef<HTMLDivElement>(null);\n\n const { pdfViewerRef, eventBusRef, findControllerRef } = usePdfViewer(\n containerRef,\n viewerRef,\n document,\n initialScale,\n initialPage,\n );\n\n const handleScaleChange = useCallback((newScale: number) => {\n setScale(newScale);\n }, []);\n\n const handlePageChange = useCallback((page: number) => {\n setCurrentPage(page);\n }, []);\n\n const { scrollToPage: syncScrollToPage } = usePdfViewerSync({\n pdfViewerRef,\n eventBusRef,\n document,\n scale,\n onScaleChange: handleScaleChange,\n onPageChange: handlePageChange,\n });\n\n const scrollToPage = useCallback(\n (page: number) => {\n setCurrentPage(page);\n syncScrollToPage(page);\n },\n [syncScrollToPage],\n );\n\n const portalTargets = usePdfAnnotationPortals(\n pdfViewerRef,\n eventBusRef,\n document,\n );\n\n return {\n document,\n numPages,\n loading,\n error,\n containerRef,\n viewerRef,\n currentPage,\n scrollToPage,\n scale,\n setScale,\n portalTargets,\n pdfViewerRef,\n eventBusRef,\n findControllerRef,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AASA,SAASA,WAAW,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAErD,SAASC,uBAAuB,QAAQ,8BAA8B;AACtE,SAASC,cAAc,QAAQ,qBAAqB;AACpD,SAASC,YAAY,QAAQ,mBAAmB;AAChD,SAASC,gBAAgB,QAAQ,uBAAu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AAG7B,uBAAuB,CAC3CkB,YAAY,EACZC,WAAW,EACXX,QACF,CAAC;EAED,OAAO;IACLA,QAAQ;IACRC,QAAQ;IACRC,OAAO;IACPC,KAAK;IACLK,YAAY;IACZC,SAAS;IACTH,WAAW;IACXW,YAAY;IACZb,KAAK;IACLC,QAAQ;IACRgB,aAAa;IACbX,YAAY;IACZC,WAAW;IACXC;EACF,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,135 @@
1
+ /*
2
+ * Copyright 2025 Palantir Technologies, Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import { useCallback, useEffect, useState } from "react";
18
+ import { MAX_SCALE, MIN_SCALE, SCALE_STEP } from "../constants.js";
19
+ import { usePdfOutline } from "./usePdfOutline.js";
20
+ import { usePdfViewerCore } from "./usePdfViewerCore.js";
21
+ import { usePdfViewerSearch } from "./usePdfViewerSearch.js";
22
+ export function usePdfViewerState({
23
+ src,
24
+ initialPage,
25
+ initialScale,
26
+ initialSidebarOpen = false,
27
+ sidebarMode: sidebarModeProp = "thumbnails",
28
+ onDownload
29
+ }) {
30
+ const core = usePdfViewerCore({
31
+ src,
32
+ initialPage,
33
+ initialScale
34
+ });
35
+ const [rotation, setRotation] = useState(0);
36
+ const [sidebarOpen, setSidebarOpen] = useState(initialSidebarOpen);
37
+ const [sidebarMode, setSidebarMode] = useState(sidebarModeProp);
38
+ const search = usePdfViewerSearch(core.eventBusRef, core.findControllerRef, core.document);
39
+ const outlineItems = usePdfOutline(core.document);
40
+
41
+ // Sync sidebarMode prop changes to state
42
+ useEffect(function () {
43
+ setSidebarMode(sidebarModeProp);
44
+ }, [sidebarModeProp]);
45
+
46
+ // Sync rotation → PDFViewer
47
+ useEffect(function () {
48
+ const pdfViewer = core.pdfViewerRef.current;
49
+ if (pdfViewer != null) {
50
+ pdfViewer.pagesRotation = rotation;
51
+ }
52
+ }, [core.pdfViewerRef, rotation]);
53
+
54
+ // Ctrl+F keyboard shortcut
55
+ useEffect(function () {
56
+ const handleKeyDown = e => {
57
+ if ((e.ctrlKey || e.metaKey) && e.key === "f") {
58
+ e.preventDefault();
59
+ search.openSearch();
60
+ }
61
+ };
62
+ window.addEventListener("keydown", handleKeyDown);
63
+ return () => {
64
+ window.removeEventListener("keydown", handleKeyDown);
65
+ };
66
+ }, [search.openSearch]);
67
+ const zoomIn = useCallback(() => {
68
+ core.setScale(Math.min(core.scale + SCALE_STEP, MAX_SCALE));
69
+ }, [core.scale, core.setScale]);
70
+ const zoomOut = useCallback(() => {
71
+ core.setScale(Math.max(core.scale - SCALE_STEP, MIN_SCALE));
72
+ }, [core.scale, core.setScale]);
73
+ const rotateLeft = useCallback(() => {
74
+ setRotation(prev => (prev - 90 + 360) % 360);
75
+ }, []);
76
+ const rotateRight = useCallback(() => {
77
+ setRotation(prev => (prev + 90) % 360);
78
+ }, []);
79
+ const toggleSidebar = useCallback(() => {
80
+ setSidebarOpen(prev => !prev);
81
+ }, []);
82
+ const download = useCallback(filename => {
83
+ if (core.document == null) {
84
+ return;
85
+ }
86
+ void core.document.getData().then(data => {
87
+ const blob = new Blob([data.buffer], {
88
+ type: "application/pdf"
89
+ });
90
+ const url = URL.createObjectURL(blob);
91
+ const resolvedFilename = resolveDownloadFilename(src, filename);
92
+ const a = globalThis.document.createElement("a");
93
+ a.href = url;
94
+ a.download = resolvedFilename;
95
+ a.click();
96
+ URL.revokeObjectURL(url);
97
+ onDownload?.({
98
+ success: true,
99
+ filename: resolvedFilename
100
+ });
101
+ }).catch(err => {
102
+ onDownload?.({
103
+ success: false,
104
+ error: err instanceof Error ? err : new Error("Failed to download PDF")
105
+ });
106
+ });
107
+ }, [core.document, src, onDownload]);
108
+ return {
109
+ ...core,
110
+ zoomIn,
111
+ zoomOut,
112
+ rotation,
113
+ rotateLeft,
114
+ rotateRight,
115
+ sidebarOpen,
116
+ sidebarMode,
117
+ setSidebarMode,
118
+ toggleSidebar,
119
+ search,
120
+ outlineItems,
121
+ download
122
+ };
123
+ }
124
+
125
+ /** Derive a download filename from an explicit name, the src URL, or a fallback. */
126
+ function resolveDownloadFilename(src, filename) {
127
+ if (filename != null) {
128
+ return filename;
129
+ }
130
+ if (typeof src === "string") {
131
+ return src.split("/").pop()?.split("?")[0] || "document.pdf";
132
+ }
133
+ return "document.pdf";
134
+ }
135
+ //# sourceMappingURL=usePdfViewerState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePdfViewerState.js","names":["useCallback","useEffect","useState","MAX_SCALE","MIN_SCALE","SCALE_STEP","usePdfOutline","usePdfViewerCore","usePdfViewerSearch","usePdfViewerState","src","initialPage","initialScale","initialSidebarOpen","sidebarMode","sidebarModeProp","onDownload","core","rotation","setRotation","sidebarOpen","setSidebarOpen","setSidebarMode","search","eventBusRef","findControllerRef","document","outlineItems","pdfViewer","pdfViewerRef","current","pagesRotation","handleKeyDown","e","ctrlKey","metaKey","key","preventDefault","openSearch","window","addEventListener","removeEventListener","zoomIn","setScale","Math","min","scale","zoomOut","max","rotateLeft","prev","rotateRight","toggleSidebar","download","filename","getData","then","data","blob","Blob","buffer","type","url","URL","createObjectURL","resolvedFilename","resolveDownloadFilename","a","globalThis","createElement","href","click","revokeObjectURL","success","catch","err","error","Error","split","pop"],"sources":["usePdfViewerState.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useCallback, useEffect, useState } from \"react\";\nimport { MAX_SCALE, MIN_SCALE, SCALE_STEP } from \"../constants.js\";\nimport type { PdfDownloadResult, SidebarMode } from \"../types.js\";\nimport { usePdfOutline } from \"./usePdfOutline.js\";\nimport type {\n UsePdfViewerCoreOptions,\n UsePdfViewerCoreResult,\n} from \"./usePdfViewerCore.js\";\nimport { usePdfViewerCore } from \"./usePdfViewerCore.js\";\nimport type { UsePdfViewerSearchResult } from \"./usePdfViewerSearch.js\";\nimport { usePdfViewerSearch } from \"./usePdfViewerSearch.js\";\n\nexport interface UsePdfViewerStateOptions extends UsePdfViewerCoreOptions {\n /** Whether the sidebar is initially open (default false) */\n initialSidebarOpen?: boolean;\n /** Which sidebar panel to show (default \"thumbnails\") */\n sidebarMode?: SidebarMode;\n /** Callback fired when a download completes or fails */\n onDownload?: (result: PdfDownloadResult) => void;\n}\n\nexport interface UsePdfViewerStateResult extends UsePdfViewerCoreResult {\n /** Zoom in by one step */\n zoomIn: () => void;\n /** Zoom out by one step */\n zoomOut: () => void;\n\n /** Current rotation in degrees (0, 90, 180, 270) */\n rotation: number;\n /** Rotate 90 degrees counter-clockwise */\n rotateLeft: () => void;\n /** Rotate 90 degrees clockwise */\n rotateRight: () => void;\n\n /** Whether the sidebar panel is open */\n sidebarOpen: boolean;\n /** Which sidebar panel is active */\n sidebarMode: SidebarMode;\n /** Change the active sidebar panel */\n setSidebarMode: (mode: SidebarMode) => void;\n /** Toggle sidebar open/closed */\n toggleSidebar: () => void;\n\n /** Search state and actions */\n search: UsePdfViewerSearchResult;\n\n /** Document outline items (from bookmarks or text extraction) */\n outlineItems: ReturnType<typeof usePdfOutline>;\n\n /** Download the PDF as a file */\n download: (filename?: string) => void;\n}\n\nexport function usePdfViewerState({\n src,\n initialPage,\n initialScale,\n initialSidebarOpen = false,\n sidebarMode: sidebarModeProp = \"thumbnails\",\n onDownload,\n}: UsePdfViewerStateOptions): UsePdfViewerStateResult {\n const core = usePdfViewerCore({ src, initialPage, initialScale });\n\n const [rotation, setRotation] = useState(0);\n const [sidebarOpen, setSidebarOpen] = useState(initialSidebarOpen);\n const [sidebarMode, setSidebarMode] = useState<SidebarMode>(sidebarModeProp);\n\n const search = usePdfViewerSearch(\n core.eventBusRef,\n core.findControllerRef,\n core.document,\n );\n\n const outlineItems = usePdfOutline(core.document);\n\n // Sync sidebarMode prop changes to state\n useEffect(function syncSidebarMode() {\n setSidebarMode(sidebarModeProp);\n }, [sidebarModeProp]);\n\n // Sync rotation → PDFViewer\n useEffect(function syncRotationToViewer() {\n const pdfViewer = core.pdfViewerRef.current;\n if (pdfViewer != null) {\n pdfViewer.pagesRotation = rotation;\n }\n }, [core.pdfViewerRef, rotation]);\n\n // Ctrl+F keyboard shortcut\n useEffect(function registerSearchShortcut() {\n const handleKeyDown = (e: KeyboardEvent) => {\n if ((e.ctrlKey || e.metaKey) && e.key === \"f\") {\n e.preventDefault();\n search.openSearch();\n }\n };\n window.addEventListener(\"keydown\", handleKeyDown);\n return () => {\n window.removeEventListener(\"keydown\", handleKeyDown);\n };\n }, [search.openSearch]);\n\n const zoomIn = useCallback(() => {\n core.setScale(Math.min(core.scale + SCALE_STEP, MAX_SCALE));\n }, [core.scale, core.setScale]);\n\n const zoomOut = useCallback(() => {\n core.setScale(Math.max(core.scale - SCALE_STEP, MIN_SCALE));\n }, [core.scale, core.setScale]);\n\n const rotateLeft = useCallback(() => {\n setRotation((prev) => (prev - 90 + 360) % 360);\n }, []);\n\n const rotateRight = useCallback(() => {\n setRotation((prev) => (prev + 90) % 360);\n }, []);\n\n const toggleSidebar = useCallback(() => {\n setSidebarOpen((prev) => !prev);\n }, []);\n\n const download = useCallback((filename?: string) => {\n if (core.document == null) {\n return;\n }\n void core.document.getData().then((data) => {\n const blob = new Blob([data.buffer as ArrayBuffer], {\n type: \"application/pdf\",\n });\n const url = URL.createObjectURL(blob);\n const resolvedFilename = resolveDownloadFilename(src, filename);\n const a = globalThis.document.createElement(\"a\");\n a.href = url;\n a.download = resolvedFilename;\n a.click();\n URL.revokeObjectURL(url);\n onDownload?.({ success: true, filename: resolvedFilename });\n }).catch((err: unknown) => {\n onDownload?.({\n success: false,\n error: err instanceof Error\n ? err\n : new Error(\"Failed to download PDF\"),\n });\n });\n }, [core.document, src, onDownload]);\n\n return {\n ...core,\n zoomIn,\n zoomOut,\n rotation,\n rotateLeft,\n rotateRight,\n sidebarOpen,\n sidebarMode,\n setSidebarMode,\n toggleSidebar,\n search,\n outlineItems,\n download,\n };\n}\n\n/** Derive a download filename from an explicit name, the src URL, or a fallback. */\nfunction resolveDownloadFilename(\n src: string | ArrayBuffer,\n filename: string | undefined,\n): string {\n if (filename != null) {\n return filename;\n }\n if (typeof src === \"string\") {\n return src.split(\"/\").pop()?.split(\"?\")[0] || \"document.pdf\";\n }\n return \"document.pdf\";\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AACxD,SAASC,SAAS,EAAEC,SAAS,EAAEC,UAAU,QAAQ,iBAAiB;AAElE,SAASC,aAAa,QAAQ,oBAAoB;AAKlD,SAASC,gBAAgB,QAAQ,uBAAuB;AAExD,SAASC,kBAAkB,QAAQ,yBAAyB;AA2C5D,OAAO,SAASC,iBAAiBA,CAAC;EAChCC,GAAG;EACHC,WAAW;EACXC,YAAY;EACZC,kBAAkB,GAAG,KAAK;EAC1BC,WAAW,EAAEC,eAAe,GAAG,YAAY;EAC3CC;AACwB,CAAC,EAA2B;EACpD,MAAMC,IAAI,GAAGV,gBAAgB,CAAC;IAAEG,GAAG;IAAEC,WAAW;IAAEC;EAAa,CAAC,CAAC;EAEjE,MAAM,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AAC,GAAG,CAAC,CAACC,GAAG,CAAC,CAAC,EAAED,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,cAAc;EAC9D;EACA,OAAO,cAAc;AACvB","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["types.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/** The visual style of an annotation rendered on the PDF. */\nexport type AnnotationType = \"highlight\" | \"underline\" | \"comment\" | \"pin\";\n\n/** A single annotation positioned on a specific page of the PDF. */\nexport interface PdfAnnotation {\n /** Unique identifier for this annotation */\n id: string;\n /** The type of annotation to render */\n type: AnnotationType;\n /** Page number (1-indexed) */\n page: number;\n /** Coordinates in PDF points (origin: bottom-left of page) */\n rect: { x: number; y: number; width: number; height: number };\n /** Optional label or tooltip text */\n label?: string;\n /** Optional color override (CSS color string) */\n color?: string;\n}\n\n/** Props for the {@link PdfViewer} component. */\nexport interface PdfViewerProps {\n /** PDF source — URL string or ArrayBuffer */\n src: string | ArrayBuffer;\n /** Annotations to overlay on the PDF, keyed by page number (1-indexed) */\n annotations?: Record<number, PdfAnnotation[]>;\n /**\n * Callback fired when an annotation is clicked.\n *\n * @param annotation - The annotation that was clicked\n * @returns void\n */\n onAnnotationClick?: (annotation: PdfAnnotation) => void;\n /** Initial page number (1-indexed, default 1) */\n initialPage?: number;\n /** Initial zoom scale (default 1.0) */\n initialScale?: number;\n /** Whether the sidebar is initially open (default false) */\n initialSidebarOpen?: boolean;\n /** Additional CSS class name for the root element */\n className?: string;\n}\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"file":"types.js","names":[],"sources":["types.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type React from \"react\";\n\n/** Which sidebar panel to display when the sidebar is open. */\nexport type SidebarMode = \"thumbnails\" | \"outline\";\n\n/** A single item in the PDF document outline (table of contents). */\nexport interface OutlineItem {\n title: string;\n depth: number;\n pageNumber: number;\n bold: boolean;\n italic: boolean;\n}\n\n/** The visual style of an annotation rendered on the PDF. */\nexport type AnnotationType = \"highlight\" | \"underline\" | \"comment\" | \"pin\";\n\n/** A single annotation positioned on a specific page of the PDF. */\nexport interface PdfAnnotation {\n /** Unique identifier for this annotation */\n id: string;\n /** The type of annotation to render */\n type: AnnotationType;\n /** Page number (1-indexed) */\n page: number;\n /** Coordinates in PDF points (origin: bottom-left of page) */\n rect: { x: number; y: number; width: number; height: number };\n /** Optional label or tooltip text */\n label?: string;\n /** Optional color override (CSS color string) */\n color?: string;\n}\n\n/** Result passed to the {@link PdfViewerProps.onDownload} callback. */\nexport type PdfDownloadResult =\n | { success: true; filename: string }\n | { success: false; error: Error };\n\n/** Props for the {@link PdfViewer} component. */\nexport interface PdfViewerProps {\n /** PDF source — URL string or ArrayBuffer */\n src: string | ArrayBuffer;\n /** Annotations to overlay on the PDF, keyed by page number (1-indexed) */\n annotations?: Record<number, PdfAnnotation[]>;\n /**\n * Callback fired when an annotation is clicked.\n *\n * @param annotation - The annotation that was clicked\n * @returns void\n */\n onAnnotationClick?: (annotation: PdfAnnotation) => void;\n /**\n * Callback fired when a download completes or fails.\n *\n * @param result - The download result indicating success with the filename, or failure with an error\n * @returns void\n */\n onDownload?: (result: PdfDownloadResult) => void;\n /** Initial page number (1-indexed, default 1) */\n initialPage?: number;\n /** Initial zoom scale (default 1.0) */\n initialScale?: number;\n /** Whether the sidebar is initially open (default false) */\n initialSidebarOpen?: boolean;\n /**\n * Whether the download button is shown in the toolbar.\n * @default false\n */\n enableDownload?: boolean;\n /**\n * Which sidebar panel to show: thumbnails or document outline.\n * @default \"thumbnails\"\n */\n sidebarMode?: SidebarMode;\n /**\n * Custom icon components for each outline depth level (0-indexed).\n * Key 0 = top-level items, 1 = first nesting level, etc.\n * If omitted, no icons are rendered.\n */\n outlineIcons?: Partial<Record<number, React.ComponentType>>;\n /** Additional CSS class name for the root element */\n className?: string;\n}\n"],"mappings":"","ignoreList":[]}