@docmentis/udoc-viewer 0.7.19 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/API-COMPARISON.md +441 -0
- package/LICENSE-APACHE +202 -0
- package/LICENSE-MIT +21 -0
- package/README.md +23 -1220
- package/dist/index.d.ts +40 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +52 -0
- package/dist/index.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +7 -0
- package/dist/version.js.map +1 -0
- package/dist/worker/worker-source.d.ts +3 -0
- package/dist/worker/worker-source.d.ts.map +1 -0
- package/dist/worker/worker-source.js +11 -0
- package/dist/worker/worker.d.ts +2 -0
- package/dist/worker/worker.d.ts.map +1 -0
- package/dist/worker/worker.js +5 -0
- package/dist/worker/worker.js.map +1 -0
- package/package.json +48 -59
- package/dist/package.json +0 -79
- package/dist/src/UDocClient.d.ts +0 -730
- package/dist/src/UDocClient.d.ts.map +0 -1
- package/dist/src/UDocClient.js +0 -649
- package/dist/src/UDocClient.js.map +0 -1
- package/dist/src/UDocViewer.d.ts +0 -883
- package/dist/src/UDocViewer.d.ts.map +0 -1
- package/dist/src/UDocViewer.js +0 -2180
- package/dist/src/UDocViewer.js.map +0 -1
- package/dist/src/fonts.d.ts +0 -47
- package/dist/src/fonts.d.ts.map +0 -1
- package/dist/src/fonts.js +0 -49
- package/dist/src/fonts.js.map +0 -1
- package/dist/src/index.d.ts +0 -13
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js +0 -5
- package/dist/src/index.js.map +0 -1
- package/dist/src/meta-url.d.ts +0 -2
- package/dist/src/meta-url.d.ts.map +0 -1
- package/dist/src/meta-url.js +0 -10
- package/dist/src/meta-url.js.map +0 -1
- package/dist/src/performance/PerformanceCounter.d.ts +0 -132
- package/dist/src/performance/PerformanceCounter.d.ts.map +0 -1
- package/dist/src/performance/PerformanceCounter.js +0 -129
- package/dist/src/performance/PerformanceCounter.js.map +0 -1
- package/dist/src/performance/index.d.ts +0 -2
- package/dist/src/performance/index.d.ts.map +0 -1
- package/dist/src/performance/index.js +0 -2
- package/dist/src/performance/index.js.map +0 -1
- package/dist/src/ui/framework/component.d.ts +0 -68
- package/dist/src/ui/framework/component.d.ts.map +0 -1
- package/dist/src/ui/framework/component.js +0 -97
- package/dist/src/ui/framework/component.js.map +0 -1
- package/dist/src/ui/framework/dom.d.ts +0 -19
- package/dist/src/ui/framework/dom.d.ts.map +0 -1
- package/dist/src/ui/framework/dom.js +0 -29
- package/dist/src/ui/framework/dom.js.map +0 -1
- package/dist/src/ui/framework/events.d.ts +0 -18
- package/dist/src/ui/framework/events.d.ts.map +0 -1
- package/dist/src/ui/framework/events.js +0 -23
- package/dist/src/ui/framework/events.js.map +0 -1
- package/dist/src/ui/framework/index.d.ts +0 -15
- package/dist/src/ui/framework/index.d.ts.map +0 -1
- package/dist/src/ui/framework/index.js +0 -15
- package/dist/src/ui/framework/index.js.map +0 -1
- package/dist/src/ui/framework/selectors.d.ts +0 -51
- package/dist/src/ui/framework/selectors.d.ts.map +0 -1
- package/dist/src/ui/framework/selectors.js +0 -28
- package/dist/src/ui/framework/selectors.js.map +0 -1
- package/dist/src/ui/framework/store.d.ts +0 -44
- package/dist/src/ui/framework/store.d.ts.map +0 -1
- package/dist/src/ui/framework/store.js +0 -79
- package/dist/src/ui/framework/store.js.map +0 -1
- package/dist/src/ui/viewer/a11y.d.ts +0 -26
- package/dist/src/ui/viewer/a11y.d.ts.map +0 -1
- package/dist/src/ui/viewer/a11y.js +0 -116
- package/dist/src/ui/viewer/a11y.js.map +0 -1
- package/dist/src/ui/viewer/actions.d.ts +0 -308
- package/dist/src/ui/viewer/actions.d.ts.map +0 -1
- package/dist/src/ui/viewer/actions.js +0 -2
- package/dist/src/ui/viewer/actions.js.map +0 -1
- package/dist/src/ui/viewer/animation-presets.d.ts +0 -37
- package/dist/src/ui/viewer/animation-presets.d.ts.map +0 -1
- package/dist/src/ui/viewer/animation-presets.js +0 -123
- package/dist/src/ui/viewer/animation-presets.js.map +0 -1
- package/dist/src/ui/viewer/animation.d.ts +0 -162
- package/dist/src/ui/viewer/animation.d.ts.map +0 -1
- package/dist/src/ui/viewer/animation.js +0 -506
- package/dist/src/ui/viewer/animation.js.map +0 -1
- package/dist/src/ui/viewer/annotation/LinkRenderer.d.ts +0 -9
- package/dist/src/ui/viewer/annotation/LinkRenderer.d.ts.map +0 -1
- package/dist/src/ui/viewer/annotation/LinkRenderer.js +0 -17
- package/dist/src/ui/viewer/annotation/LinkRenderer.js.map +0 -1
- package/dist/src/ui/viewer/annotation/MarkupRenderer.d.ts +0 -21
- package/dist/src/ui/viewer/annotation/MarkupRenderer.d.ts.map +0 -1
- package/dist/src/ui/viewer/annotation/MarkupRenderer.js +0 -136
- package/dist/src/ui/viewer/annotation/MarkupRenderer.js.map +0 -1
- package/dist/src/ui/viewer/annotation/ShapeRenderer.d.ts +0 -33
- package/dist/src/ui/viewer/annotation/ShapeRenderer.d.ts.map +0 -1
- package/dist/src/ui/viewer/annotation/ShapeRenderer.js +0 -379
- package/dist/src/ui/viewer/annotation/ShapeRenderer.js.map +0 -1
- package/dist/src/ui/viewer/annotation/TextRenderer.d.ts +0 -23
- package/dist/src/ui/viewer/annotation/TextRenderer.d.ts.map +0 -1
- package/dist/src/ui/viewer/annotation/TextRenderer.js +0 -196
- package/dist/src/ui/viewer/annotation/TextRenderer.js.map +0 -1
- package/dist/src/ui/viewer/annotation/index.d.ts +0 -9
- package/dist/src/ui/viewer/annotation/index.d.ts.map +0 -1
- package/dist/src/ui/viewer/annotation/index.js +0 -10
- package/dist/src/ui/viewer/annotation/index.js.map +0 -1
- package/dist/src/ui/viewer/annotation/propertyUtils.d.ts +0 -29
- package/dist/src/ui/viewer/annotation/propertyUtils.d.ts.map +0 -1
- package/dist/src/ui/viewer/annotation/propertyUtils.js +0 -151
- package/dist/src/ui/viewer/annotation/propertyUtils.js.map +0 -1
- package/dist/src/ui/viewer/annotation/render.d.ts +0 -24
- package/dist/src/ui/viewer/annotation/render.d.ts.map +0 -1
- package/dist/src/ui/viewer/annotation/render.js +0 -191
- package/dist/src/ui/viewer/annotation/render.js.map +0 -1
- package/dist/src/ui/viewer/annotation/types.d.ts +0 -309
- package/dist/src/ui/viewer/annotation/types.d.ts.map +0 -1
- package/dist/src/ui/viewer/annotation/types.js +0 -7
- package/dist/src/ui/viewer/annotation/types.js.map +0 -1
- package/dist/src/ui/viewer/annotation/utils.d.ts +0 -75
- package/dist/src/ui/viewer/annotation/utils.d.ts.map +0 -1
- package/dist/src/ui/viewer/annotation/utils.js +0 -250
- package/dist/src/ui/viewer/annotation/utils.js.map +0 -1
- package/dist/src/ui/viewer/components/AnnotationPanel.d.ts +0 -20
- package/dist/src/ui/viewer/components/AnnotationPanel.d.ts.map +0 -1
- package/dist/src/ui/viewer/components/AnnotationPanel.js +0 -276
- package/dist/src/ui/viewer/components/AnnotationPanel.js.map +0 -1
- package/dist/src/ui/viewer/components/AttachmentsPanel.d.ts +0 -8
- package/dist/src/ui/viewer/components/AttachmentsPanel.d.ts.map +0 -1
- package/dist/src/ui/viewer/components/AttachmentsPanel.js +0 -16
- package/dist/src/ui/viewer/components/AttachmentsPanel.js.map +0 -1
- package/dist/src/ui/viewer/components/BookmarksPanel.d.ts +0 -8
- package/dist/src/ui/viewer/components/BookmarksPanel.d.ts.map +0 -1
- package/dist/src/ui/viewer/components/BookmarksPanel.js +0 -16
- package/dist/src/ui/viewer/components/BookmarksPanel.js.map +0 -1
- package/dist/src/ui/viewer/components/Branding.d.ts +0 -49
- package/dist/src/ui/viewer/components/Branding.d.ts.map +0 -1
- package/dist/src/ui/viewer/components/Branding.js +0 -334
- package/dist/src/ui/viewer/components/Branding.js.map +0 -1
- package/dist/src/ui/viewer/components/ColorSelect.d.ts +0 -26
- package/dist/src/ui/viewer/components/ColorSelect.d.ts.map +0 -1
- package/dist/src/ui/viewer/components/ColorSelect.js +0 -120
- package/dist/src/ui/viewer/components/ColorSelect.js.map +0 -1
- package/dist/src/ui/viewer/components/FloatingToolbar.d.ts +0 -10
- package/dist/src/ui/viewer/components/FloatingToolbar.d.ts.map +0 -1
- package/dist/src/ui/viewer/components/FloatingToolbar.js +0 -396
- package/dist/src/ui/viewer/components/FloatingToolbar.js.map +0 -1
- package/dist/src/ui/viewer/components/FontsPanel.d.ts +0 -12
- package/dist/src/ui/viewer/components/FontsPanel.d.ts.map +0 -1
- package/dist/src/ui/viewer/components/FontsPanel.js +0 -141
- package/dist/src/ui/viewer/components/FontsPanel.js.map +0 -1
- package/dist/src/ui/viewer/components/LayersPanel.d.ts +0 -12
- package/dist/src/ui/viewer/components/LayersPanel.d.ts.map +0 -1
- package/dist/src/ui/viewer/components/LayersPanel.js +0 -139
- package/dist/src/ui/viewer/components/LayersPanel.js.map +0 -1
- package/dist/src/ui/viewer/components/LeftPanel.d.ts +0 -11
- package/dist/src/ui/viewer/components/LeftPanel.d.ts.map +0 -1
- package/dist/src/ui/viewer/components/LeftPanel.js +0 -296
- package/dist/src/ui/viewer/components/LeftPanel.js.map +0 -1
- package/dist/src/ui/viewer/components/LoadingOverlay.d.ts +0 -13
- package/dist/src/ui/viewer/components/LoadingOverlay.d.ts.map +0 -1
- package/dist/src/ui/viewer/components/LoadingOverlay.js +0 -146
- package/dist/src/ui/viewer/components/LoadingOverlay.js.map +0 -1
- package/dist/src/ui/viewer/components/NumberInput.d.ts +0 -32
- package/dist/src/ui/viewer/components/NumberInput.d.ts.map +0 -1
- package/dist/src/ui/viewer/components/NumberInput.js +0 -101
- package/dist/src/ui/viewer/components/NumberInput.js.map +0 -1
- package/dist/src/ui/viewer/components/OutlinePanel.d.ts +0 -11
- package/dist/src/ui/viewer/components/OutlinePanel.d.ts.map +0 -1
- package/dist/src/ui/viewer/components/OutlinePanel.js +0 -307
- package/dist/src/ui/viewer/components/OutlinePanel.js.map +0 -1
- package/dist/src/ui/viewer/components/PasswordDialog.d.ts +0 -16
- package/dist/src/ui/viewer/components/PasswordDialog.d.ts.map +0 -1
- package/dist/src/ui/viewer/components/PasswordDialog.js +0 -179
- package/dist/src/ui/viewer/components/PasswordDialog.js.map +0 -1
- package/dist/src/ui/viewer/components/PermitNoticeOverlay.d.ts +0 -27
- package/dist/src/ui/viewer/components/PermitNoticeOverlay.d.ts.map +0 -1
- package/dist/src/ui/viewer/components/PermitNoticeOverlay.js +0 -79
- package/dist/src/ui/viewer/components/PermitNoticeOverlay.js.map +0 -1
- package/dist/src/ui/viewer/components/PrintDialog.d.ts +0 -34
- package/dist/src/ui/viewer/components/PrintDialog.d.ts.map +0 -1
- package/dist/src/ui/viewer/components/PrintDialog.js +0 -317
- package/dist/src/ui/viewer/components/PrintDialog.js.map +0 -1
- package/dist/src/ui/viewer/components/RightPanel.d.ts +0 -10
- package/dist/src/ui/viewer/components/RightPanel.d.ts.map +0 -1
- package/dist/src/ui/viewer/components/RightPanel.js +0 -154
- package/dist/src/ui/viewer/components/RightPanel.js.map +0 -1
- package/dist/src/ui/viewer/components/SearchPanel.d.ts +0 -21
- package/dist/src/ui/viewer/components/SearchPanel.d.ts.map +0 -1
- package/dist/src/ui/viewer/components/SearchPanel.js +0 -323
- package/dist/src/ui/viewer/components/SearchPanel.js.map +0 -1
- package/dist/src/ui/viewer/components/SheetTabBar.d.ts +0 -9
- package/dist/src/ui/viewer/components/SheetTabBar.d.ts.map +0 -1
- package/dist/src/ui/viewer/components/SheetTabBar.js +0 -57
- package/dist/src/ui/viewer/components/SheetTabBar.js.map +0 -1
- package/dist/src/ui/viewer/components/Spread.d.ts +0 -85
- package/dist/src/ui/viewer/components/Spread.d.ts.map +0 -1
- package/dist/src/ui/viewer/components/Spread.js +0 -749
- package/dist/src/ui/viewer/components/Spread.js.map +0 -1
- package/dist/src/ui/viewer/components/SubToolbar.d.ts +0 -11
- package/dist/src/ui/viewer/components/SubToolbar.d.ts.map +0 -1
- package/dist/src/ui/viewer/components/SubToolbar.js +0 -722
- package/dist/src/ui/viewer/components/SubToolbar.js.map +0 -1
- package/dist/src/ui/viewer/components/ThumbnailPanel.d.ts +0 -12
- package/dist/src/ui/viewer/components/ThumbnailPanel.d.ts.map +0 -1
- package/dist/src/ui/viewer/components/ThumbnailPanel.js +0 -290
- package/dist/src/ui/viewer/components/ThumbnailPanel.js.map +0 -1
- package/dist/src/ui/viewer/components/Toolbar.d.ts +0 -12
- package/dist/src/ui/viewer/components/Toolbar.d.ts.map +0 -1
- package/dist/src/ui/viewer/components/Toolbar.js +0 -761
- package/dist/src/ui/viewer/components/Toolbar.js.map +0 -1
- package/dist/src/ui/viewer/components/ViewModeMenu.d.ts +0 -10
- package/dist/src/ui/viewer/components/ViewModeMenu.d.ts.map +0 -1
- package/dist/src/ui/viewer/components/ViewModeMenu.js +0 -206
- package/dist/src/ui/viewer/components/ViewModeMenu.js.map +0 -1
- package/dist/src/ui/viewer/components/Viewport.d.ts +0 -28
- package/dist/src/ui/viewer/components/Viewport.d.ts.map +0 -1
- package/dist/src/ui/viewer/components/Viewport.js +0 -1721
- package/dist/src/ui/viewer/components/Viewport.js.map +0 -1
- package/dist/src/ui/viewer/effects.d.ts +0 -8
- package/dist/src/ui/viewer/effects.d.ts.map +0 -1
- package/dist/src/ui/viewer/effects.js +0 -452
- package/dist/src/ui/viewer/effects.js.map +0 -1
- package/dist/src/ui/viewer/i18n/ar.d.ts +0 -3
- package/dist/src/ui/viewer/i18n/ar.d.ts.map +0 -1
- package/dist/src/ui/viewer/i18n/ar.js +0 -198
- package/dist/src/ui/viewer/i18n/ar.js.map +0 -1
- package/dist/src/ui/viewer/i18n/de.d.ts +0 -3
- package/dist/src/ui/viewer/i18n/de.d.ts.map +0 -1
- package/dist/src/ui/viewer/i18n/de.js +0 -198
- package/dist/src/ui/viewer/i18n/de.js.map +0 -1
- package/dist/src/ui/viewer/i18n/en.d.ts +0 -3
- package/dist/src/ui/viewer/i18n/en.d.ts.map +0 -1
- package/dist/src/ui/viewer/i18n/en.js +0 -200
- package/dist/src/ui/viewer/i18n/en.js.map +0 -1
- package/dist/src/ui/viewer/i18n/es.d.ts +0 -3
- package/dist/src/ui/viewer/i18n/es.d.ts.map +0 -1
- package/dist/src/ui/viewer/i18n/es.js +0 -198
- package/dist/src/ui/viewer/i18n/es.js.map +0 -1
- package/dist/src/ui/viewer/i18n/fr.d.ts +0 -3
- package/dist/src/ui/viewer/i18n/fr.d.ts.map +0 -1
- package/dist/src/ui/viewer/i18n/fr.js +0 -198
- package/dist/src/ui/viewer/i18n/fr.js.map +0 -1
- package/dist/src/ui/viewer/i18n/index.d.ts +0 -27
- package/dist/src/ui/viewer/i18n/index.d.ts.map +0 -1
- package/dist/src/ui/viewer/i18n/index.js +0 -88
- package/dist/src/ui/viewer/i18n/index.js.map +0 -1
- package/dist/src/ui/viewer/i18n/ja.d.ts +0 -3
- package/dist/src/ui/viewer/i18n/ja.d.ts.map +0 -1
- package/dist/src/ui/viewer/i18n/ja.js +0 -198
- package/dist/src/ui/viewer/i18n/ja.js.map +0 -1
- package/dist/src/ui/viewer/i18n/ko.d.ts +0 -3
- package/dist/src/ui/viewer/i18n/ko.d.ts.map +0 -1
- package/dist/src/ui/viewer/i18n/ko.js +0 -198
- package/dist/src/ui/viewer/i18n/ko.js.map +0 -1
- package/dist/src/ui/viewer/i18n/pt-BR.d.ts +0 -3
- package/dist/src/ui/viewer/i18n/pt-BR.d.ts.map +0 -1
- package/dist/src/ui/viewer/i18n/pt-BR.js +0 -198
- package/dist/src/ui/viewer/i18n/pt-BR.js.map +0 -1
- package/dist/src/ui/viewer/i18n/ru.d.ts +0 -3
- package/dist/src/ui/viewer/i18n/ru.d.ts.map +0 -1
- package/dist/src/ui/viewer/i18n/ru.js +0 -198
- package/dist/src/ui/viewer/i18n/ru.js.map +0 -1
- package/dist/src/ui/viewer/i18n/types.d.ts +0 -176
- package/dist/src/ui/viewer/i18n/types.d.ts.map +0 -1
- package/dist/src/ui/viewer/i18n/types.js +0 -2
- package/dist/src/ui/viewer/i18n/types.js.map +0 -1
- package/dist/src/ui/viewer/i18n/zh-CN.d.ts +0 -3
- package/dist/src/ui/viewer/i18n/zh-CN.d.ts.map +0 -1
- package/dist/src/ui/viewer/i18n/zh-CN.js +0 -198
- package/dist/src/ui/viewer/i18n/zh-CN.js.map +0 -1
- package/dist/src/ui/viewer/i18n/zh-TW.d.ts +0 -3
- package/dist/src/ui/viewer/i18n/zh-TW.d.ts.map +0 -1
- package/dist/src/ui/viewer/i18n/zh-TW.js +0 -198
- package/dist/src/ui/viewer/i18n/zh-TW.js.map +0 -1
- package/dist/src/ui/viewer/icons.d.ts +0 -77
- package/dist/src/ui/viewer/icons.d.ts.map +0 -1
- package/dist/src/ui/viewer/icons.js +0 -109
- package/dist/src/ui/viewer/icons.js.map +0 -1
- package/dist/src/ui/viewer/index.d.ts +0 -6
- package/dist/src/ui/viewer/index.d.ts.map +0 -1
- package/dist/src/ui/viewer/index.js +0 -6
- package/dist/src/ui/viewer/index.js.map +0 -1
- package/dist/src/ui/viewer/layout/index.d.ts +0 -3
- package/dist/src/ui/viewer/layout/index.d.ts.map +0 -1
- package/dist/src/ui/viewer/layout/index.js +0 -3
- package/dist/src/ui/viewer/layout/index.js.map +0 -1
- package/dist/src/ui/viewer/layout/pixelAlign.d.ts +0 -8
- package/dist/src/ui/viewer/layout/pixelAlign.d.ts.map +0 -1
- package/dist/src/ui/viewer/layout/pixelAlign.js +0 -42
- package/dist/src/ui/viewer/layout/pixelAlign.js.map +0 -1
- package/dist/src/ui/viewer/layout/spreadLayout.d.ts +0 -155
- package/dist/src/ui/viewer/layout/spreadLayout.d.ts.map +0 -1
- package/dist/src/ui/viewer/layout/spreadLayout.js +0 -574
- package/dist/src/ui/viewer/layout/spreadLayout.js.map +0 -1
- package/dist/src/ui/viewer/navigation.d.ts +0 -91
- package/dist/src/ui/viewer/navigation.d.ts.map +0 -1
- package/dist/src/ui/viewer/navigation.js +0 -59
- package/dist/src/ui/viewer/navigation.js.map +0 -1
- package/dist/src/ui/viewer/reducer.d.ts +0 -4
- package/dist/src/ui/viewer/reducer.d.ts.map +0 -1
- package/dist/src/ui/viewer/reducer.js +0 -841
- package/dist/src/ui/viewer/reducer.js.map +0 -1
- package/dist/src/ui/viewer/search/index.d.ts +0 -2
- package/dist/src/ui/viewer/search/index.d.ts.map +0 -1
- package/dist/src/ui/viewer/search/index.js +0 -2
- package/dist/src/ui/viewer/search/index.js.map +0 -1
- package/dist/src/ui/viewer/search/search.d.ts +0 -31
- package/dist/src/ui/viewer/search/search.d.ts.map +0 -1
- package/dist/src/ui/viewer/search/search.js +0 -446
- package/dist/src/ui/viewer/search/search.js.map +0 -1
- package/dist/src/ui/viewer/shell.d.ts +0 -65
- package/dist/src/ui/viewer/shell.d.ts.map +0 -1
- package/dist/src/ui/viewer/shell.js +0 -366
- package/dist/src/ui/viewer/shell.js.map +0 -1
- package/dist/src/ui/viewer/state.d.ts +0 -313
- package/dist/src/ui/viewer/state.d.ts.map +0 -1
- package/dist/src/ui/viewer/state.js +0 -157
- package/dist/src/ui/viewer/state.js.map +0 -1
- package/dist/src/ui/viewer/styles-inline.d.ts +0 -2
- package/dist/src/ui/viewer/styles-inline.d.ts.map +0 -1
- package/dist/src/ui/viewer/styles-inline.js +0 -3526
- package/dist/src/ui/viewer/styles-inline.js.map +0 -1
- package/dist/src/ui/viewer/text/index.d.ts +0 -6
- package/dist/src/ui/viewer/text/index.d.ts.map +0 -1
- package/dist/src/ui/viewer/text/index.js +0 -6
- package/dist/src/ui/viewer/text/index.js.map +0 -1
- package/dist/src/ui/viewer/text/render.d.ts +0 -18
- package/dist/src/ui/viewer/text/render.d.ts.map +0 -1
- package/dist/src/ui/viewer/text/render.js +0 -480
- package/dist/src/ui/viewer/text/render.js.map +0 -1
- package/dist/src/ui/viewer/text/selection.d.ts +0 -12
- package/dist/src/ui/viewer/text/selection.d.ts.map +0 -1
- package/dist/src/ui/viewer/text/selection.js +0 -69
- package/dist/src/ui/viewer/text/selection.js.map +0 -1
- package/dist/src/ui/viewer/tools/AnnotationDrawController.d.ts +0 -21
- package/dist/src/ui/viewer/tools/AnnotationDrawController.d.ts.map +0 -1
- package/dist/src/ui/viewer/tools/AnnotationDrawController.js +0 -410
- package/dist/src/ui/viewer/tools/AnnotationDrawController.js.map +0 -1
- package/dist/src/ui/viewer/tools/AnnotationSelectController.d.ts +0 -22
- package/dist/src/ui/viewer/tools/AnnotationSelectController.d.ts.map +0 -1
- package/dist/src/ui/viewer/tools/AnnotationSelectController.js +0 -378
- package/dist/src/ui/viewer/tools/AnnotationSelectController.js.map +0 -1
- package/dist/src/ui/viewer/tools/AnnotationUndoManager.d.ts +0 -29
- package/dist/src/ui/viewer/tools/AnnotationUndoManager.d.ts.map +0 -1
- package/dist/src/ui/viewer/tools/AnnotationUndoManager.js +0 -144
- package/dist/src/ui/viewer/tools/AnnotationUndoManager.js.map +0 -1
- package/dist/src/ui/viewer/tools/ViewToolController.d.ts +0 -20
- package/dist/src/ui/viewer/tools/ViewToolController.d.ts.map +0 -1
- package/dist/src/ui/viewer/tools/ViewToolController.js +0 -179
- package/dist/src/ui/viewer/tools/ViewToolController.js.map +0 -1
- package/dist/src/ui/viewer/transition-gl.d.ts +0 -25
- package/dist/src/ui/viewer/transition-gl.d.ts.map +0 -1
- package/dist/src/ui/viewer/transition-gl.js +0 -823
- package/dist/src/ui/viewer/transition-gl.js.map +0 -1
- package/dist/src/ui/viewer/transition.d.ts +0 -26
- package/dist/src/ui/viewer/transition.d.ts.map +0 -1
- package/dist/src/ui/viewer/transition.js +0 -1383
- package/dist/src/ui/viewer/transition.js.map +0 -1
- package/dist/src/wasm/LICENSE +0 -112
- package/dist/src/wasm/udoc.d.ts +0 -1338
- package/dist/src/wasm/udoc.js +0 -2645
- package/dist/src/wasm/udoc_bg.wasm +0 -0
- package/dist/src/wasm/udoc_bg.wasm.d.ts +0 -58
- package/dist/src/worker/WorkerClient.d.ts +0 -489
- package/dist/src/worker/WorkerClient.d.ts.map +0 -1
- package/dist/src/worker/WorkerClient.js +0 -1383
- package/dist/src/worker/WorkerClient.js.map +0 -1
- package/dist/src/worker/index.d.ts +0 -4
- package/dist/src/worker/index.d.ts.map +0 -1
- package/dist/src/worker/index.js +0 -2
- package/dist/src/worker/index.js.map +0 -1
- package/dist/src/worker/wasmError.d.ts +0 -17
- package/dist/src/worker/wasmError.d.ts.map +0 -1
- package/dist/src/worker/wasmError.js +0 -28
- package/dist/src/worker/wasmError.js.map +0 -1
- package/dist/src/worker/worker-inline.d.ts +0 -2
- package/dist/src/worker/worker-inline.d.ts.map +0 -1
- package/dist/src/worker/worker-inline.js +0 -2
- package/dist/src/worker/worker-inline.js.map +0 -1
- package/dist/src/worker/worker.d.ts +0 -530
- package/dist/src/worker/worker.d.ts.map +0 -1
- package/dist/src/worker/worker.js +0 -2935
- package/dist/src/worker/worker.js.map +0 -1
package/dist/src/UDocViewer.js
DELETED
|
@@ -1,2180 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* UDocViewer - Document viewer component.
|
|
3
|
-
*
|
|
4
|
-
* Binds to a loaded document and optionally provides UI.
|
|
5
|
-
* Created via `client.createViewer()`.
|
|
6
|
-
*/
|
|
7
|
-
import { mountViewerShell } from "./ui/viewer/shell.js";
|
|
8
|
-
import { PERMIT_BLOCKED_NOTICE, PERMIT_UNAVAILABLE_NOTICE } from "./ui/viewer/components/PermitNoticeOverlay.js";
|
|
9
|
-
import { renderAnnotationsToLayer, applyAnnotationPatch, } from "./ui/viewer/annotation/index.js";
|
|
10
|
-
import { extractPageText } from "./ui/viewer/search/index.js";
|
|
11
|
-
import { getFormatDefaults, } from "./ui/viewer/state.js";
|
|
12
|
-
import { PerformanceCounter, NoOpPerformanceCounter } from "./performance/index.js";
|
|
13
|
-
/**
|
|
14
|
-
* Generate a unique annotation identifier suitable for the PDF NM entry.
|
|
15
|
-
* Uses crypto.randomUUID() when available, falling back to a Math.random
|
|
16
|
-
* shim for environments (older Safari, Node < 19) without it.
|
|
17
|
-
*/
|
|
18
|
-
function generateAnnotationId() {
|
|
19
|
-
const cryptoObj = globalThis.crypto;
|
|
20
|
-
if (cryptoObj?.randomUUID)
|
|
21
|
-
return cryptoObj.randomUUID();
|
|
22
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
23
|
-
const r = (Math.random() * 16) | 0;
|
|
24
|
-
const v = c === "x" ? r : (r & 0x3) | 0x8;
|
|
25
|
-
return v.toString(16);
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* MIME types that name CSV. `text/csv` is the registered type (RFC 4180); the
|
|
30
|
-
* others are aliases some servers send instead.
|
|
31
|
-
*/
|
|
32
|
-
const CSV_MIME_TYPES = new Set([
|
|
33
|
-
"text/csv",
|
|
34
|
-
"application/csv",
|
|
35
|
-
"text/comma-separated-values",
|
|
36
|
-
"text/x-csv",
|
|
37
|
-
"application/x-csv",
|
|
38
|
-
]);
|
|
39
|
-
/**
|
|
40
|
-
* Derive an explicit format hint from what the source says about itself.
|
|
41
|
-
*
|
|
42
|
-
* WASM auto-detects most formats from magic bytes, so a hint is only needed
|
|
43
|
-
* for formats that have none — currently CSV. The source's own name (File name
|
|
44
|
-
* or URL), the caller's `filename` option, the MIME type and the
|
|
45
|
-
* Content-Disposition file name are consulted in that order; the first that
|
|
46
|
-
* names a format wins. Returning `undefined` lets WASM fall back to
|
|
47
|
-
* content-based detection.
|
|
48
|
-
*/
|
|
49
|
-
function detectFormatHint(source, filename) {
|
|
50
|
-
return (formatHintFromFilename(source.filename) ??
|
|
51
|
-
formatHintFromFilename(filename) ??
|
|
52
|
-
formatHintFromMimeType(source.mimeType) ??
|
|
53
|
-
formatHintFromFilename(source.dispositionFilename));
|
|
54
|
-
}
|
|
55
|
-
function formatHintFromFilename(filename) {
|
|
56
|
-
if (!filename)
|
|
57
|
-
return undefined;
|
|
58
|
-
const ext = filename.split(/[?#]/)[0].split(".").pop()?.toLowerCase();
|
|
59
|
-
return ext === "csv" ? "csv" : undefined;
|
|
60
|
-
}
|
|
61
|
-
function formatHintFromMimeType(mimeType) {
|
|
62
|
-
if (!mimeType)
|
|
63
|
-
return undefined;
|
|
64
|
-
// Drop parameters such as `; charset=utf-8`.
|
|
65
|
-
const essence = mimeType.split(";")[0].trim().toLowerCase();
|
|
66
|
-
return CSV_MIME_TYPES.has(essence) ? "csv" : undefined;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Extract the file name from a `Content-Disposition` header (RFC 6266),
|
|
70
|
-
* preferring the RFC 5987 `filename*=charset'lang'value` form over `filename=`.
|
|
71
|
-
*/
|
|
72
|
-
function filenameFromContentDisposition(header) {
|
|
73
|
-
if (!header)
|
|
74
|
-
return undefined;
|
|
75
|
-
const extended = /(?:^|;)\s*filename\*\s*=\s*[^']*'[^']*'([^;]+)/i.exec(header);
|
|
76
|
-
if (extended) {
|
|
77
|
-
try {
|
|
78
|
-
return decodeURIComponent(extended[1].trim());
|
|
79
|
-
}
|
|
80
|
-
catch {
|
|
81
|
-
// Malformed percent-encoding — fall back to the plain parameter.
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
const plain = /(?:^|;)\s*filename\s*=\s*(?:"((?:[^"\\]|\\.)*)"|([^;]*))/i.exec(header);
|
|
85
|
-
if (!plain)
|
|
86
|
-
return undefined;
|
|
87
|
-
const name = plain[1] !== undefined ? plain[1].replace(/\\(.)/g, "$1") : plain[2].trim();
|
|
88
|
-
return name || undefined;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Document viewer component.
|
|
92
|
-
*
|
|
93
|
-
* Supports both UI mode (with container) and headless mode (without container).
|
|
94
|
-
* Use `client.createViewer()` to create instances.
|
|
95
|
-
*/
|
|
96
|
-
export class UDocViewer {
|
|
97
|
-
workerClient;
|
|
98
|
-
container = null;
|
|
99
|
-
uiShell = null;
|
|
100
|
-
documentId = null;
|
|
101
|
-
_pageCount = 0;
|
|
102
|
-
_pageInfo = [];
|
|
103
|
-
destroyed = false;
|
|
104
|
-
eventHandlers = new Map();
|
|
105
|
-
_performanceCounter;
|
|
106
|
-
viewOverrides;
|
|
107
|
-
currentFormat = null;
|
|
108
|
-
sourceFilename = null;
|
|
109
|
-
documentDefaultFilename = null;
|
|
110
|
-
storeUnsub = null;
|
|
111
|
-
actionUnsub = null;
|
|
112
|
-
fontUsageUnsub = null;
|
|
113
|
-
sdkVersion;
|
|
114
|
-
/**
|
|
115
|
-
* @internal
|
|
116
|
-
* Use `client.createViewer()` instead.
|
|
117
|
-
*/
|
|
118
|
-
constructor(workerClient, options = {}, showAttribution = true, showLoadingOverlay = true, sdkVersion = "0.7.19") {
|
|
119
|
-
this.workerClient = workerClient;
|
|
120
|
-
this.sdkVersion = sdkVersion;
|
|
121
|
-
this.viewOverrides = this.buildViewModeOverrides(options);
|
|
122
|
-
// Initialize performance counter
|
|
123
|
-
if (options.enablePerformanceCounter) {
|
|
124
|
-
const counter = new PerformanceCounter();
|
|
125
|
-
this._performanceCounter = counter;
|
|
126
|
-
if (options.onPerformanceLog) {
|
|
127
|
-
counter.onLog(options.onPerformanceLog);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
this._performanceCounter = new NoOpPerformanceCounter();
|
|
132
|
-
}
|
|
133
|
-
// Subscribe to font usage changes from the worker
|
|
134
|
-
this.fontUsageUnsub = this.workerClient.onFontUsageChanged(async (docId) => {
|
|
135
|
-
if (this.documentId !== docId)
|
|
136
|
-
return;
|
|
137
|
-
try {
|
|
138
|
-
const entries = await this.workerClient.getFontUsage(docId);
|
|
139
|
-
if (this.destroyed || this.documentId !== docId)
|
|
140
|
-
return;
|
|
141
|
-
this.emit("font:usageChange", { entries: entries });
|
|
142
|
-
}
|
|
143
|
-
catch {
|
|
144
|
-
// Worker terminated or document closed mid-flight — ignore
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
if (options.container) {
|
|
148
|
-
this.container = this.resolveContainer(options.container);
|
|
149
|
-
const overrides = this.buildStateOverrides(options);
|
|
150
|
-
this.uiShell = mountViewerShell(this.container, this.createEngineAdapter(), this.workerClient, overrides, showAttribution, showLoadingOverlay, options.locale, options.translations, options.customPageOverlay);
|
|
151
|
-
// Set up callbacks for shell events
|
|
152
|
-
this.uiShell.setCallbacks({
|
|
153
|
-
onPasswordSubmit: (password) => this.handlePasswordSubmit(password),
|
|
154
|
-
onDownload: () => this.download(),
|
|
155
|
-
onPrint: (options) => this.print(options),
|
|
156
|
-
onViewportChange: (payload) => this.emit("viewport:change", payload),
|
|
157
|
-
onAnnotationHover: (payload) => this.emit("annotation:hover", payload),
|
|
158
|
-
onAnnotationClick: (payload) => this.emit("annotation:click", payload),
|
|
159
|
-
});
|
|
160
|
-
// Subscribe to store state changes to emit public events
|
|
161
|
-
this.storeUnsub = this.uiShell.store.subscribeEffect((prev, next) => {
|
|
162
|
-
if (prev.page !== next.page) {
|
|
163
|
-
this.emit("page:change", { page: next.page, previousPage: prev.page });
|
|
164
|
-
}
|
|
165
|
-
if (prev.activePanel !== next.activePanel) {
|
|
166
|
-
this.emit("panel:change", { panel: next.activePanel, previousPanel: prev.activePanel });
|
|
167
|
-
}
|
|
168
|
-
if (prev.toolbarVisible !== next.toolbarVisible) {
|
|
169
|
-
this.emit("ui:visibilityChange", { component: "toolbar", visible: next.toolbarVisible });
|
|
170
|
-
}
|
|
171
|
-
if (prev.floatingToolbarVisible !== next.floatingToolbarVisible) {
|
|
172
|
-
this.emit("ui:visibilityChange", {
|
|
173
|
-
component: "floatingToolbar",
|
|
174
|
-
visible: next.floatingToolbarVisible,
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
if (prev.leftPanelVisible !== next.leftPanelVisible) {
|
|
178
|
-
this.emit("ui:visibilityChange", {
|
|
179
|
-
component: "leftPanel",
|
|
180
|
-
visible: next.leftPanelVisible,
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
if (prev.rightPanelVisible !== next.rightPanelVisible) {
|
|
184
|
-
this.emit("ui:visibilityChange", {
|
|
185
|
-
component: "rightPanel",
|
|
186
|
-
visible: next.rightPanelVisible,
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
if (prev.fullscreenButtonVisible !== next.fullscreenButtonVisible) {
|
|
190
|
-
this.emit("ui:visibilityChange", {
|
|
191
|
-
component: "fullscreen",
|
|
192
|
-
visible: next.fullscreenButtonVisible,
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
if (prev.downloadButtonVisible !== next.downloadButtonVisible) {
|
|
196
|
-
this.emit("ui:visibilityChange", {
|
|
197
|
-
component: "download",
|
|
198
|
-
visible: next.downloadButtonVisible,
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
if (prev.printButtonVisible !== next.printButtonVisible) {
|
|
202
|
-
this.emit("ui:visibilityChange", {
|
|
203
|
-
component: "print",
|
|
204
|
-
visible: next.printButtonVisible,
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
if (prev.searchMatches !== next.searchMatches || prev.searchActiveIndex !== next.searchActiveIndex) {
|
|
208
|
-
this.emit("search:change", {
|
|
209
|
-
matches: next.searchMatches,
|
|
210
|
-
activeIndex: next.searchActiveIndex,
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
if (prev.disabledPanels !== next.disabledPanels) {
|
|
214
|
-
// Emit events for panels whose disabled state changed
|
|
215
|
-
const allPanels = [
|
|
216
|
-
"thumbnail",
|
|
217
|
-
"outline",
|
|
218
|
-
"bookmarks",
|
|
219
|
-
"layers",
|
|
220
|
-
"attachments",
|
|
221
|
-
"fonts",
|
|
222
|
-
"search",
|
|
223
|
-
"comments",
|
|
224
|
-
];
|
|
225
|
-
for (const panel of allPanels) {
|
|
226
|
-
const wasDisabled = prev.disabledPanels.has(panel);
|
|
227
|
-
const isDisabled = next.disabledPanels.has(panel);
|
|
228
|
-
if (wasDisabled !== isDisabled) {
|
|
229
|
-
this.emit("ui:visibilityChange", { component: panel, visible: !isDisabled });
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
});
|
|
234
|
-
// Forward annotation mutations as public events. Subscribing at the
|
|
235
|
-
// action layer (rather than diffing state) lets us include the
|
|
236
|
-
// exact affected annotation in the payload — including the removed
|
|
237
|
-
// one, which we look up in `prev` before the reducer dropped it.
|
|
238
|
-
this.actionUnsub = this.uiShell.store.subscribeAction((action, prev, next) => {
|
|
239
|
-
switch (action.type) {
|
|
240
|
-
case "ADD_ANNOTATION":
|
|
241
|
-
this.emit("annotation:add", {
|
|
242
|
-
pageIndex: action.pageIndex,
|
|
243
|
-
annotation: action.annotation,
|
|
244
|
-
});
|
|
245
|
-
break;
|
|
246
|
-
case "ADD_ANNOTATIONS":
|
|
247
|
-
for (const annotation of action.annotations) {
|
|
248
|
-
this.emit("annotation:add", {
|
|
249
|
-
pageIndex: action.pageIndex,
|
|
250
|
-
annotation,
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
break;
|
|
254
|
-
case "UPDATE_ANNOTATION":
|
|
255
|
-
this.emit("annotation:update", {
|
|
256
|
-
pageIndex: action.pageIndex,
|
|
257
|
-
annotation: action.annotation,
|
|
258
|
-
});
|
|
259
|
-
break;
|
|
260
|
-
case "UPDATE_ANNOTATIONS":
|
|
261
|
-
for (const { annotation } of action.updates) {
|
|
262
|
-
this.emit("annotation:update", {
|
|
263
|
-
pageIndex: action.pageIndex,
|
|
264
|
-
annotation,
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
break;
|
|
268
|
-
case "REMOVE_ANNOTATION": {
|
|
269
|
-
const removed = prev.pageAnnotations.get(action.pageIndex)?.[action.annotationIndex];
|
|
270
|
-
if (removed) {
|
|
271
|
-
this.emit("annotation:remove", {
|
|
272
|
-
pageIndex: action.pageIndex,
|
|
273
|
-
annotation: removed,
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
break;
|
|
277
|
-
}
|
|
278
|
-
case "SELECT_ANNOTATION": {
|
|
279
|
-
const ann = next.pageAnnotations.get(action.pageIndex)?.[action.annotationIndex];
|
|
280
|
-
if (ann) {
|
|
281
|
-
this.emit("annotation:select", {
|
|
282
|
-
pageIndex: action.pageIndex,
|
|
283
|
-
annotation: ann,
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
break;
|
|
287
|
-
}
|
|
288
|
-
case "DESELECT_ANNOTATION":
|
|
289
|
-
this.emit("annotation:select", null);
|
|
290
|
-
break;
|
|
291
|
-
}
|
|
292
|
-
});
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
/**
|
|
296
|
-
* Performance counter for tracking operation timings.
|
|
297
|
-
* Only records data when `enablePerformanceCounter` is true.
|
|
298
|
-
*/
|
|
299
|
-
get performanceCounter() {
|
|
300
|
-
return this._performanceCounter;
|
|
301
|
-
}
|
|
302
|
-
buildStateOverrides(options) {
|
|
303
|
-
const overrides = {};
|
|
304
|
-
if (options.scrollMode !== undefined)
|
|
305
|
-
overrides.scrollMode = options.scrollMode;
|
|
306
|
-
if (options.layoutMode !== undefined)
|
|
307
|
-
overrides.layoutMode = options.layoutMode;
|
|
308
|
-
if (options.zoomMode !== undefined)
|
|
309
|
-
overrides.zoomMode = options.zoomMode;
|
|
310
|
-
if (options.zoom !== undefined)
|
|
311
|
-
overrides.zoom = options.zoom;
|
|
312
|
-
if (options.zoomSteps !== undefined)
|
|
313
|
-
overrides.zoomSteps = options.zoomSteps;
|
|
314
|
-
if (options.dpi !== undefined)
|
|
315
|
-
overrides.dpi = options.dpi;
|
|
316
|
-
if (options.pageSpacing !== undefined)
|
|
317
|
-
overrides.pageSpacing = options.pageSpacing;
|
|
318
|
-
if (options.spreadSpacing !== undefined)
|
|
319
|
-
overrides.spreadSpacing = options.spreadSpacing;
|
|
320
|
-
if (options.thumbnailWidth !== undefined)
|
|
321
|
-
overrides.thumbnailWidth = options.thumbnailWidth;
|
|
322
|
-
if (options.navigationScrollAlignment !== undefined)
|
|
323
|
-
overrides.navigationScrollAlignment = options.navigationScrollAlignment;
|
|
324
|
-
if (options.searchScrollAlignment !== undefined)
|
|
325
|
-
overrides.searchScrollAlignment = options.searchScrollAlignment;
|
|
326
|
-
if (options.activePanel !== undefined)
|
|
327
|
-
overrides.activePanel = options.activePanel;
|
|
328
|
-
if (options.hideToolbar)
|
|
329
|
-
overrides.toolbarVisible = false;
|
|
330
|
-
if (options.hideFloatingToolbar)
|
|
331
|
-
overrides.floatingToolbarVisible = false;
|
|
332
|
-
if (options.disableFullscreen)
|
|
333
|
-
overrides.fullscreenButtonVisible = false;
|
|
334
|
-
if (options.disableDownload)
|
|
335
|
-
overrides.downloadButtonVisible = false;
|
|
336
|
-
if (options.disablePrint)
|
|
337
|
-
overrides.printButtonVisible = false;
|
|
338
|
-
if (options.disableLeftPanel)
|
|
339
|
-
overrides.leftPanelVisible = false;
|
|
340
|
-
if (options.disableRightPanel)
|
|
341
|
-
overrides.rightPanelVisible = false;
|
|
342
|
-
if (options.theme !== undefined)
|
|
343
|
-
overrides.theme = options.theme;
|
|
344
|
-
if (options.disableThemeSwitching)
|
|
345
|
-
overrides.themeSwitchingDisabled = true;
|
|
346
|
-
if (options.disableTextSelection)
|
|
347
|
-
overrides.textSelectionDisabled = true;
|
|
348
|
-
if (options.pageRotation !== undefined)
|
|
349
|
-
overrides.pageRotation = options.pageRotation;
|
|
350
|
-
if (options.spacingMode !== undefined)
|
|
351
|
-
overrides.spacingMode = options.spacingMode;
|
|
352
|
-
if (options.minZoom !== undefined)
|
|
353
|
-
overrides.minZoom = options.minZoom;
|
|
354
|
-
if (options.maxZoom !== undefined)
|
|
355
|
-
overrides.maxZoom = options.maxZoom;
|
|
356
|
-
if (options.enableTransitions)
|
|
357
|
-
overrides.transitionsEnabled = true;
|
|
358
|
-
if (options.enableAnimations)
|
|
359
|
-
overrides.animationsEnabled = true;
|
|
360
|
-
// Collect individually disabled panels into the internal Set
|
|
361
|
-
const disabled = [];
|
|
362
|
-
if (options.disableThumbnails)
|
|
363
|
-
disabled.push("thumbnail");
|
|
364
|
-
if (options.disableOutline)
|
|
365
|
-
disabled.push("outline");
|
|
366
|
-
if (options.disableBookmarks)
|
|
367
|
-
disabled.push("bookmarks");
|
|
368
|
-
if (options.disableLayers)
|
|
369
|
-
disabled.push("layers");
|
|
370
|
-
if (options.disableAttachments)
|
|
371
|
-
disabled.push("attachments");
|
|
372
|
-
if (options.disableFonts)
|
|
373
|
-
disabled.push("fonts");
|
|
374
|
-
if (options.disableSearch)
|
|
375
|
-
disabled.push("search");
|
|
376
|
-
if (options.disableComments)
|
|
377
|
-
disabled.push("comments");
|
|
378
|
-
if (disabled.length > 0) {
|
|
379
|
-
overrides.disabledPanels = new Set(disabled);
|
|
380
|
-
}
|
|
381
|
-
// Collect disabled tools into the internal Set
|
|
382
|
-
// Default: all disabled. Only remove from the set when explicitly not disabled (false).
|
|
383
|
-
const disabledTools = [];
|
|
384
|
-
if (options.disableViewTools) {
|
|
385
|
-
disabledTools.push("pointer", "hand", "zoom");
|
|
386
|
-
}
|
|
387
|
-
if (options.disableAnnotateTools) {
|
|
388
|
-
disabledTools.push("annotate");
|
|
389
|
-
}
|
|
390
|
-
if (options.__experimentalDisableMarkupTools !== false) {
|
|
391
|
-
disabledTools.push("markup");
|
|
392
|
-
}
|
|
393
|
-
overrides.disabledTools = new Set(disabledTools);
|
|
394
|
-
return overrides;
|
|
395
|
-
}
|
|
396
|
-
buildViewModeOverrides(options) {
|
|
397
|
-
const overrides = {};
|
|
398
|
-
if (options.scrollMode !== undefined)
|
|
399
|
-
overrides.scrollMode = options.scrollMode;
|
|
400
|
-
if (options.layoutMode !== undefined)
|
|
401
|
-
overrides.layoutMode = options.layoutMode;
|
|
402
|
-
if (options.zoomMode !== undefined)
|
|
403
|
-
overrides.zoomMode = options.zoomMode;
|
|
404
|
-
if (options.zoom !== undefined)
|
|
405
|
-
overrides.zoom = options.zoom;
|
|
406
|
-
if (options.pageSpacing !== undefined)
|
|
407
|
-
overrides.pageSpacing = options.pageSpacing;
|
|
408
|
-
if (options.spreadSpacing !== undefined)
|
|
409
|
-
overrides.spreadSpacing = options.spreadSpacing;
|
|
410
|
-
if (options.pageRotation !== undefined)
|
|
411
|
-
overrides.pageRotation = options.pageRotation;
|
|
412
|
-
if (options.spacingMode !== undefined)
|
|
413
|
-
overrides.spacingMode = options.spacingMode;
|
|
414
|
-
return overrides;
|
|
415
|
-
}
|
|
416
|
-
computeViewDefaults(format) {
|
|
417
|
-
return { ...getFormatDefaults(format), ...this.viewOverrides };
|
|
418
|
-
}
|
|
419
|
-
// ===========================================================================
|
|
420
|
-
// Document Loading
|
|
421
|
-
// ===========================================================================
|
|
422
|
-
/**
|
|
423
|
-
* Load a document.
|
|
424
|
-
*
|
|
425
|
-
* @param source - URL string, File object, or raw bytes
|
|
426
|
-
* @param options - See {@link LoadOptions}.
|
|
427
|
-
*/
|
|
428
|
-
async load(source, options) {
|
|
429
|
-
this.ensureNotDestroyed();
|
|
430
|
-
// Reset performance counter and start timing
|
|
431
|
-
this._performanceCounter.reset();
|
|
432
|
-
this._performanceCounter.setLoadStartTime();
|
|
433
|
-
// Close any existing document
|
|
434
|
-
if (this.documentId) {
|
|
435
|
-
this.close();
|
|
436
|
-
}
|
|
437
|
-
// Clear any prior permit notice before attempting a new open.
|
|
438
|
-
this.uiShell?.dispatch({ type: "SET_PERMIT_NOTICE", notice: null });
|
|
439
|
-
try {
|
|
440
|
-
// Track download phase
|
|
441
|
-
const downloadId = this._performanceCounter.markStart("download");
|
|
442
|
-
const resolved = await this.resolveSourceWithFilename(source);
|
|
443
|
-
this.sourceFilename = resolved.filename ?? null;
|
|
444
|
-
this.documentDefaultFilename = options?.filename ?? null;
|
|
445
|
-
this._performanceCounter.markEnd(downloadId);
|
|
446
|
-
// Show processing state while WASM loads and extracts page info
|
|
447
|
-
this.uiShell?.dispatch({ type: "SET_PROCESSING", processing: true });
|
|
448
|
-
// Load document — WASM auto-detects format from file contents, but
|
|
449
|
-
// formats without magic bytes (e.g. CSV) need an explicit hint:
|
|
450
|
-
// the caller's `format`, else one derived from the source's name,
|
|
451
|
-
// `filename`, MIME type or Content-Disposition.
|
|
452
|
-
const loadId = this._performanceCounter.markStart("load");
|
|
453
|
-
const formatHint = options?.format ?? detectFormatHint(resolved, options?.filename);
|
|
454
|
-
this.documentId = await this.workerClient.loadDocument(resolved.bytes, formatHint);
|
|
455
|
-
this._performanceCounter.markEnd(loadId);
|
|
456
|
-
// Get the detected format from WASM for UI defaults
|
|
457
|
-
const format = (await this.workerClient.getDocumentFormat(this.documentId));
|
|
458
|
-
this.currentFormat = format;
|
|
459
|
-
// Register performance counter with WorkerClient for this document
|
|
460
|
-
// This enables tracking of all subsequent operations (getPageInfo, render, etc.)
|
|
461
|
-
if (this._performanceCounter.enabled) {
|
|
462
|
-
this.workerClient.setPerformanceCounter(this.documentId, this._performanceCounter);
|
|
463
|
-
}
|
|
464
|
-
// Check if document needs password
|
|
465
|
-
const passwordRequired = await this.workerClient.needsPassword(this.documentId);
|
|
466
|
-
if (passwordRequired) {
|
|
467
|
-
// Document needs password - show dialog and wait for authentication
|
|
468
|
-
if (this.uiShell) {
|
|
469
|
-
this.uiShell.dispatch({
|
|
470
|
-
type: "SET_DOC",
|
|
471
|
-
doc: { id: this.documentId },
|
|
472
|
-
documentFormat: format,
|
|
473
|
-
pageCount: 0,
|
|
474
|
-
pageInfos: [],
|
|
475
|
-
pageGroups: [],
|
|
476
|
-
viewDefaults: this.computeViewDefaults(format),
|
|
477
|
-
});
|
|
478
|
-
this.uiShell.dispatch({ type: "SET_PROCESSING", processing: false });
|
|
479
|
-
this.uiShell.dispatch({ type: "SET_NEEDS_PASSWORD", needsPassword: true });
|
|
480
|
-
}
|
|
481
|
-
// Don't emit document:load yet - wait for successful authentication
|
|
482
|
-
return;
|
|
483
|
-
}
|
|
484
|
-
// Load all page info upfront (fast operation)
|
|
485
|
-
this._pageInfo = await this.workerClient.getAllPageInfo(this.documentId);
|
|
486
|
-
this._pageCount = this._pageInfo.length;
|
|
487
|
-
const pageGroups = await this.workerClient.getPageGroups(this.documentId);
|
|
488
|
-
if (this.uiShell) {
|
|
489
|
-
const initUiId = this._performanceCounter.markStart("initUiShell");
|
|
490
|
-
this.uiShell.dispatch({
|
|
491
|
-
type: "SET_DOC",
|
|
492
|
-
doc: { id: this.documentId },
|
|
493
|
-
documentFormat: format,
|
|
494
|
-
pageCount: this._pageCount,
|
|
495
|
-
pageInfos: this._pageInfo,
|
|
496
|
-
pageGroups,
|
|
497
|
-
viewDefaults: this.computeViewDefaults(format),
|
|
498
|
-
});
|
|
499
|
-
this._performanceCounter.markEnd(initUiId);
|
|
500
|
-
this.uiShell.dispatch({ type: "SET_PROCESSING", processing: false });
|
|
501
|
-
}
|
|
502
|
-
this.emit("document:load", { pageCount: this._pageCount });
|
|
503
|
-
}
|
|
504
|
-
catch (error) {
|
|
505
|
-
this.uiShell?.dispatch({ type: "SET_PROCESSING", processing: false });
|
|
506
|
-
// Free-tier permit failures are surfaced via a dedicated phase and an
|
|
507
|
-
// explicit in-viewer overlay (no blank screen). Markers come from the
|
|
508
|
-
// WASM runtime (the single trust point), not from JS.
|
|
509
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
510
|
-
if (message.includes("[@docMentis/udoc-viewer] permit blocked")) {
|
|
511
|
-
this.uiShell?.dispatch({ type: "SET_PERMIT_NOTICE", notice: PERMIT_BLOCKED_NOTICE });
|
|
512
|
-
this.emit("error", { error: error, phase: "permit" });
|
|
513
|
-
throw error;
|
|
514
|
-
}
|
|
515
|
-
if (message.includes("[@docMentis/udoc-viewer] permit unavailable")) {
|
|
516
|
-
this.uiShell?.dispatch({ type: "SET_PERMIT_NOTICE", notice: PERMIT_UNAVAILABLE_NOTICE });
|
|
517
|
-
this.emit("error", { error: error, phase: "permit" });
|
|
518
|
-
throw error;
|
|
519
|
-
}
|
|
520
|
-
const phase = error instanceof TypeError ? "fetch" : "parse";
|
|
521
|
-
this.emit("error", { error: error, phase });
|
|
522
|
-
throw error;
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
/**
|
|
526
|
-
* Close the current document.
|
|
527
|
-
* Viewer returns to empty state.
|
|
528
|
-
*/
|
|
529
|
-
close() {
|
|
530
|
-
if (this.documentId) {
|
|
531
|
-
const docId = this.documentId;
|
|
532
|
-
// Clear document state first so UI callbacks from invalidateRenderCache
|
|
533
|
-
// see no active document and skip re-rendering.
|
|
534
|
-
this.documentId = null;
|
|
535
|
-
this._pageCount = 0;
|
|
536
|
-
this._pageInfo = [];
|
|
537
|
-
this.sourceFilename = null;
|
|
538
|
-
this.documentDefaultFilename = null;
|
|
539
|
-
// Remove performance counter for this document
|
|
540
|
-
this.workerClient.removePerformanceCounter(docId);
|
|
541
|
-
// Cancel pending renders, clear cached bitmaps, then unload from worker.
|
|
542
|
-
// Use clearRenderCache (no callbacks) instead of invalidateRenderCache
|
|
543
|
-
// to avoid triggering UI re-renders for a document being removed.
|
|
544
|
-
this.workerClient.cancelRenders(docId);
|
|
545
|
-
this.workerClient.clearRenderCache(docId);
|
|
546
|
-
this.workerClient.unloadPdf(docId).catch(() => {
|
|
547
|
-
// Ignore errors during close
|
|
548
|
-
});
|
|
549
|
-
if (this.uiShell) {
|
|
550
|
-
this.uiShell.dispatch({ type: "CLEAR_DOC" });
|
|
551
|
-
}
|
|
552
|
-
this.emit("document:close", {});
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
/**
|
|
556
|
-
* Whether a document is currently loaded.
|
|
557
|
-
*/
|
|
558
|
-
get isLoaded() {
|
|
559
|
-
return this.documentId !== null;
|
|
560
|
-
}
|
|
561
|
-
/**
|
|
562
|
-
* Check if the loaded document requires a password to open.
|
|
563
|
-
* @returns True if the document needs authentication before pages can be accessed.
|
|
564
|
-
*/
|
|
565
|
-
async needsPassword() {
|
|
566
|
-
this.ensureLoaded();
|
|
567
|
-
return this.workerClient.needsPassword(this.documentId);
|
|
568
|
-
}
|
|
569
|
-
/**
|
|
570
|
-
* Authenticate with a password to unlock an encrypted document.
|
|
571
|
-
*
|
|
572
|
-
* After successful authentication, page info is reloaded and the document
|
|
573
|
-
* becomes fully accessible.
|
|
574
|
-
*
|
|
575
|
-
* @param password - The password to try
|
|
576
|
-
* @returns True if authentication succeeded, false if the password was incorrect.
|
|
577
|
-
*/
|
|
578
|
-
async authenticate(password) {
|
|
579
|
-
this.ensureLoaded();
|
|
580
|
-
// Dispatch authenticating state for UI
|
|
581
|
-
if (this.uiShell) {
|
|
582
|
-
this.uiShell.dispatch({ type: "AUTHENTICATE_START" });
|
|
583
|
-
}
|
|
584
|
-
try {
|
|
585
|
-
const success = await this.workerClient.authenticate(this.documentId, password);
|
|
586
|
-
if (success) {
|
|
587
|
-
// Clear any cached renders from before authentication (they would be invalid)
|
|
588
|
-
this.workerClient.cancelRenders(this.documentId);
|
|
589
|
-
this.workerClient.invalidateRenderCache(this.documentId);
|
|
590
|
-
// Reload page info after successful authentication
|
|
591
|
-
this._pageInfo = await this.workerClient.getAllPageInfo(this.documentId);
|
|
592
|
-
this._pageCount = this._pageInfo.length;
|
|
593
|
-
const pageGroups = await this.workerClient.getPageGroups(this.documentId);
|
|
594
|
-
if (this.uiShell) {
|
|
595
|
-
this.uiShell.dispatch({ type: "AUTHENTICATE_SUCCESS" });
|
|
596
|
-
this.uiShell.dispatch({
|
|
597
|
-
type: "SET_DOC",
|
|
598
|
-
doc: { id: this.documentId },
|
|
599
|
-
documentFormat: this.currentFormat ?? "pdf",
|
|
600
|
-
pageCount: this._pageCount,
|
|
601
|
-
pageInfos: this._pageInfo,
|
|
602
|
-
pageGroups,
|
|
603
|
-
viewDefaults: this.currentFormat ? this.computeViewDefaults(this.currentFormat) : undefined,
|
|
604
|
-
});
|
|
605
|
-
}
|
|
606
|
-
this.emit("document:load", { pageCount: this._pageCount });
|
|
607
|
-
}
|
|
608
|
-
else {
|
|
609
|
-
if (this.uiShell) {
|
|
610
|
-
this.uiShell.dispatch({ type: "AUTHENTICATE_FAILURE", error: "Incorrect password" });
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
return success;
|
|
614
|
-
}
|
|
615
|
-
catch (error) {
|
|
616
|
-
if (this.uiShell) {
|
|
617
|
-
this.uiShell.dispatch({
|
|
618
|
-
type: "AUTHENTICATE_FAILURE",
|
|
619
|
-
error: error instanceof Error ? error.message : "Authentication failed",
|
|
620
|
-
});
|
|
621
|
-
}
|
|
622
|
-
throw error;
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
/**
|
|
626
|
-
* Handle password submission from the UI dialog.
|
|
627
|
-
* @internal
|
|
628
|
-
*/
|
|
629
|
-
async handlePasswordSubmit(password) {
|
|
630
|
-
try {
|
|
631
|
-
await this.authenticate(password);
|
|
632
|
-
}
|
|
633
|
-
catch {
|
|
634
|
-
// Error is already dispatched to UI in authenticate()
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
// ===========================================================================
|
|
638
|
-
// Document Information
|
|
639
|
-
// ===========================================================================
|
|
640
|
-
/**
|
|
641
|
-
* Total number of pages.
|
|
642
|
-
* Returns 0 if no document is loaded.
|
|
643
|
-
*/
|
|
644
|
-
get pageCount() {
|
|
645
|
-
return this._pageCount;
|
|
646
|
-
}
|
|
647
|
-
/**
|
|
648
|
-
* Document metadata (title, author, etc.).
|
|
649
|
-
* Returns null if no document is loaded.
|
|
650
|
-
*/
|
|
651
|
-
get metadata() {
|
|
652
|
-
// TODO: Implement metadata retrieval from WASM
|
|
653
|
-
if (!this.documentId)
|
|
654
|
-
return null;
|
|
655
|
-
return {};
|
|
656
|
-
}
|
|
657
|
-
/**
|
|
658
|
-
* Get document outline (table of contents / bookmarks).
|
|
659
|
-
*/
|
|
660
|
-
async getOutline() {
|
|
661
|
-
this.ensureLoaded();
|
|
662
|
-
const raw = await this.workerClient.getOutline(this.documentId);
|
|
663
|
-
return raw;
|
|
664
|
-
}
|
|
665
|
-
/**
|
|
666
|
-
* Get font usage information for the loaded document.
|
|
667
|
-
*
|
|
668
|
-
* Returns how each font spec in the document was resolved,
|
|
669
|
-
* including primary resolution and any glyph-fallback fonts.
|
|
670
|
-
* This information is populated during rendering — call after
|
|
671
|
-
* at least one page has been rendered for results.
|
|
672
|
-
*/
|
|
673
|
-
async getFontUsage() {
|
|
674
|
-
this.ensureLoaded();
|
|
675
|
-
const raw = await this.workerClient.getFontUsage(this.documentId);
|
|
676
|
-
return raw;
|
|
677
|
-
}
|
|
678
|
-
/**
|
|
679
|
-
* Get page dimensions in points (1 point = 1/72 inch).
|
|
680
|
-
* @param page - Page index (0-based)
|
|
681
|
-
*/
|
|
682
|
-
async getPageInfo(page) {
|
|
683
|
-
this.ensureLoaded();
|
|
684
|
-
if (page < 0 || page >= this._pageCount) {
|
|
685
|
-
throw new Error(`Page index ${page} out of bounds (0-${this._pageCount - 1})`);
|
|
686
|
-
}
|
|
687
|
-
// Return cached info if available
|
|
688
|
-
if (this._pageInfo[page]) {
|
|
689
|
-
return this._pageInfo[page];
|
|
690
|
-
}
|
|
691
|
-
// Fetch from worker if not loaded yet
|
|
692
|
-
const info = await this.workerClient.getPageInfo(this.documentId, page);
|
|
693
|
-
this._pageInfo[page] = info;
|
|
694
|
-
return info;
|
|
695
|
-
}
|
|
696
|
-
/**
|
|
697
|
-
* Get annotations on a specific page.
|
|
698
|
-
*
|
|
699
|
-
* Returns the in-memory state if the page has been edited in this
|
|
700
|
-
* session; otherwise reads from the worker.
|
|
701
|
-
*
|
|
702
|
-
* Returned `bounds` (and every other geometry field) are in the page's
|
|
703
|
-
* unrotated MediaBox coordinate space — origin top-left, units in PDF
|
|
704
|
-
* points, +y downward — regardless of the page's `/Rotate` value.
|
|
705
|
-
* See {@link Rect} for the full coordinate convention.
|
|
706
|
-
*
|
|
707
|
-
* @param page - Page index (0-based)
|
|
708
|
-
*/
|
|
709
|
-
async getPageAnnotations(page) {
|
|
710
|
-
this.ensureLoaded();
|
|
711
|
-
const fromState = this.uiShell?.store.getState().pageAnnotations.get(page);
|
|
712
|
-
if (fromState)
|
|
713
|
-
return fromState;
|
|
714
|
-
const raw = await this.workerClient.getPageAnnotations(this.documentId, page);
|
|
715
|
-
return raw;
|
|
716
|
-
}
|
|
717
|
-
/**
|
|
718
|
-
* Add a new annotation to a page.
|
|
719
|
-
*
|
|
720
|
-
* If `annotation.name` is omitted, a UUID is generated and assigned. The
|
|
721
|
-
* returned value is the annotation as inserted (with `name` populated),
|
|
722
|
-
* which is the same identifier the engine will write to the PDF's NM
|
|
723
|
-
* entry on save.
|
|
724
|
-
*
|
|
725
|
-
* Pass `ephemeral: true` to create a viewer-only annotation that renders
|
|
726
|
-
* but is excluded from saved PDF bytes and from print output. The same
|
|
727
|
-
* `updatePageAnnotation` / `removePageAnnotation` calls work for both kinds, and
|
|
728
|
-
* `updatePageAnnotation` can flip the `ephemeral` flag to promote a preview
|
|
729
|
-
* into a saved annotation (or demote a saved one to viewer-only).
|
|
730
|
-
*
|
|
731
|
-
* **Coordinate space:** `annotation.bounds` and all per-type geometry
|
|
732
|
-
* (line endpoints, polygon vertices, ink strokes, quads, callout lines,
|
|
733
|
-
* …) must be in the page's **unrotated MediaBox** coordinate space —
|
|
734
|
-
* origin top-left, PDF points, +y downward — *not* the displayed/rotated
|
|
735
|
-
* orientation. The viewer applies `/Rotate` (and the user's rotation
|
|
736
|
-
* toggle) as a display transform on top of MediaBox-space bounds. See
|
|
737
|
-
* {@link Rect} for the full convention. The {@link getPageAnnotations}
|
|
738
|
-
* round-trip uses the same space, so a value read out and added back is
|
|
739
|
-
* always in the right frame.
|
|
740
|
-
*
|
|
741
|
-
* Annotation editing currently requires UI mode (a `container` was passed
|
|
742
|
-
* to `client.createViewer`) and is supported on PDF documents only.
|
|
743
|
-
*
|
|
744
|
-
* @param page - Page index (0-based)
|
|
745
|
-
* @returns The inserted annotation (with `name` populated).
|
|
746
|
-
*/
|
|
747
|
-
async addPageAnnotation(page, annotation) {
|
|
748
|
-
this.ensureLoaded();
|
|
749
|
-
this.ensureUiMode();
|
|
750
|
-
await this.ensurePageAnnotationsLoaded(page);
|
|
751
|
-
const withId = annotation.name ? annotation : { ...annotation, name: generateAnnotationId() };
|
|
752
|
-
this.uiShell.dispatch({ type: "ADD_ANNOTATION", pageIndex: page, annotation: withId });
|
|
753
|
-
return withId;
|
|
754
|
-
}
|
|
755
|
-
/**
|
|
756
|
-
* Add multiple annotations to a page in a single batch.
|
|
757
|
-
*
|
|
758
|
-
* Equivalent to calling {@link addPageAnnotation} once per item, but
|
|
759
|
-
* applied as a single store update — one render and one dirty-flag flip
|
|
760
|
-
* per page instead of N. Use this when importing or restoring many
|
|
761
|
-
* annotations on the same page.
|
|
762
|
-
*
|
|
763
|
-
* Each annotation gets a generated `name` (UUID) if one is not provided.
|
|
764
|
-
* The returned array preserves input order with `name` populated.
|
|
765
|
-
*
|
|
766
|
-
* `annotation:add` still fires once per annotation, in input order, so
|
|
767
|
-
* existing single-event listeners just work.
|
|
768
|
-
*
|
|
769
|
-
* Geometry coordinate space matches {@link addPageAnnotation} — unrotated
|
|
770
|
-
* MediaBox, origin top-left, PDF points, +y downward. See {@link Rect}.
|
|
771
|
-
*
|
|
772
|
-
* @param page - Page index (0-based)
|
|
773
|
-
* @param annotations - Annotations to insert (may mix ephemeral and saved)
|
|
774
|
-
* @returns The inserted annotations (each with `name` populated).
|
|
775
|
-
*/
|
|
776
|
-
async addPageAnnotations(page, annotations) {
|
|
777
|
-
this.ensureLoaded();
|
|
778
|
-
this.ensureUiMode();
|
|
779
|
-
if (annotations.length === 0)
|
|
780
|
-
return [];
|
|
781
|
-
await this.ensurePageAnnotationsLoaded(page);
|
|
782
|
-
const withIds = annotations.map((a) => (a.name ? a : { ...a, name: generateAnnotationId() }));
|
|
783
|
-
this.uiShell.dispatch({ type: "ADD_ANNOTATIONS", pageIndex: page, annotations: withIds });
|
|
784
|
-
return withIds;
|
|
785
|
-
}
|
|
786
|
-
/**
|
|
787
|
-
* Update an existing annotation, identified by its `name` (NM).
|
|
788
|
-
*
|
|
789
|
-
* Looks up the annotation on the given page by `name` and replaces it
|
|
790
|
-
* with the supplied value. The replacement keeps the same `name` even
|
|
791
|
-
* if a different one is passed in `annotation.name`.
|
|
792
|
-
*
|
|
793
|
-
* Geometry on the replacement must be in unrotated MediaBox coordinates
|
|
794
|
-
* — see {@link Rect}.
|
|
795
|
-
*
|
|
796
|
-
* @param page - Page index (0-based)
|
|
797
|
-
* @param name - The annotation's `name` (NM).
|
|
798
|
-
* @param annotation - The replacement annotation.
|
|
799
|
-
* @returns The updated annotation.
|
|
800
|
-
* @throws If no annotation with the given `name` is found on the page.
|
|
801
|
-
*/
|
|
802
|
-
async updatePageAnnotation(page, name, annotation) {
|
|
803
|
-
this.ensureLoaded();
|
|
804
|
-
this.ensureUiMode();
|
|
805
|
-
const index = await this.findAnnotationIndex(page, name);
|
|
806
|
-
const updated = { ...annotation, name };
|
|
807
|
-
this.uiShell.dispatch({
|
|
808
|
-
type: "UPDATE_ANNOTATION",
|
|
809
|
-
pageIndex: page,
|
|
810
|
-
annotationIndex: index,
|
|
811
|
-
annotation: updated,
|
|
812
|
-
});
|
|
813
|
-
return updated;
|
|
814
|
-
}
|
|
815
|
-
/**
|
|
816
|
-
* Update multiple annotations on a page in a single batch.
|
|
817
|
-
*
|
|
818
|
-
* Equivalent to calling {@link updatePageAnnotation} once per item, but
|
|
819
|
-
* applied as a single store update — one render and one dirty-flag flip
|
|
820
|
-
* per page instead of N. Each entry's existing `name` is preserved even
|
|
821
|
-
* if a different one is set on its `annotation`.
|
|
822
|
-
*
|
|
823
|
-
* `annotation:update` still fires once per entry, in input order.
|
|
824
|
-
*
|
|
825
|
-
* Validation is atomic: if any `name` cannot be found on the page, the
|
|
826
|
-
* call throws *before* any annotation is updated.
|
|
827
|
-
*
|
|
828
|
-
* @param page - Page index (0-based)
|
|
829
|
-
* @param updates - Pairs of `{ name, annotation }` to replace.
|
|
830
|
-
* @returns The updated annotations, in input order.
|
|
831
|
-
* @throws If any `name` is not found on the page.
|
|
832
|
-
*/
|
|
833
|
-
async updatePageAnnotations(page, updates) {
|
|
834
|
-
this.ensureLoaded();
|
|
835
|
-
this.ensureUiMode();
|
|
836
|
-
if (updates.length === 0)
|
|
837
|
-
return [];
|
|
838
|
-
await this.ensurePageAnnotationsLoaded(page);
|
|
839
|
-
const resolved = updates.map(({ name, annotation }) => ({
|
|
840
|
-
annotationIndex: this.requireAnnotationIndex(page, name),
|
|
841
|
-
annotation: { ...annotation, name },
|
|
842
|
-
}));
|
|
843
|
-
this.uiShell.dispatch({ type: "UPDATE_ANNOTATIONS", pageIndex: page, updates: resolved });
|
|
844
|
-
return resolved.map((r) => r.annotation);
|
|
845
|
-
}
|
|
846
|
-
/**
|
|
847
|
-
* Patch an existing annotation, identified by its `name` (NM).
|
|
848
|
-
*
|
|
849
|
-
* Unlike {@link updatePageAnnotation}, which replaces the entire
|
|
850
|
-
* annotation, this only overwrites the fields present in `patch`.
|
|
851
|
-
* Everything else (geometry, other style fields, contents, etc.) is
|
|
852
|
-
* preserved. Use this when you want to tweak one or two properties —
|
|
853
|
-
* for example, change a highlight's color — without round-tripping the
|
|
854
|
-
* full annotation.
|
|
855
|
-
*
|
|
856
|
-
* Semantics:
|
|
857
|
-
* - `type` and `name` in the patch are silently ignored.
|
|
858
|
-
* - `metadata` is shallow-merged one level deep, so patching
|
|
859
|
-
* `{ metadata: { contents } }` keeps the existing `author`/`subject`.
|
|
860
|
-
* - `undefined` values are skipped, not treated as "clear this field".
|
|
861
|
-
* Use `updatePageAnnotation` for full replacement when you need to
|
|
862
|
-
* clear fields by omission.
|
|
863
|
-
*
|
|
864
|
-
* @param page - Page index (0-based)
|
|
865
|
-
* @param name - The annotation's `name` (NM).
|
|
866
|
-
* @param patch - Fields to merge into the existing annotation.
|
|
867
|
-
* @returns The patched annotation.
|
|
868
|
-
* @throws If no annotation with the given `name` is found on the page.
|
|
869
|
-
*/
|
|
870
|
-
async patchPageAnnotation(page, name, patch) {
|
|
871
|
-
this.ensureLoaded();
|
|
872
|
-
this.ensureUiMode();
|
|
873
|
-
const index = await this.findAnnotationIndex(page, name);
|
|
874
|
-
const existing = this.uiShell.store.getState().pageAnnotations.get(page)[index];
|
|
875
|
-
const updated = applyAnnotationPatch(existing, patch);
|
|
876
|
-
this.uiShell.dispatch({
|
|
877
|
-
type: "UPDATE_ANNOTATION",
|
|
878
|
-
pageIndex: page,
|
|
879
|
-
annotationIndex: index,
|
|
880
|
-
annotation: updated,
|
|
881
|
-
});
|
|
882
|
-
return updated;
|
|
883
|
-
}
|
|
884
|
-
/**
|
|
885
|
-
* Patch multiple annotations on a page in a single batch.
|
|
886
|
-
*
|
|
887
|
-
* Equivalent to calling {@link patchPageAnnotation} once per item, but
|
|
888
|
-
* applied as a single store update — one render and one dirty-flag flip
|
|
889
|
-
* per page instead of N. Patches are resolved against the *current*
|
|
890
|
-
* annotation state (not against each other in sequence); patching the
|
|
891
|
-
* same `name` twice in one call applies both, with the second winning.
|
|
892
|
-
*
|
|
893
|
-
* `annotation:update` still fires once per entry, in input order.
|
|
894
|
-
*
|
|
895
|
-
* Validation is atomic: if any `name` cannot be found on the page, the
|
|
896
|
-
* call throws *before* any annotation is patched.
|
|
897
|
-
*
|
|
898
|
-
* @param page - Page index (0-based)
|
|
899
|
-
* @param patches - Pairs of `{ name, patch }` to apply.
|
|
900
|
-
* @returns The patched annotations, in input order.
|
|
901
|
-
* @throws If any `name` is not found on the page.
|
|
902
|
-
*/
|
|
903
|
-
async patchPageAnnotations(page, patches) {
|
|
904
|
-
this.ensureLoaded();
|
|
905
|
-
this.ensureUiMode();
|
|
906
|
-
if (patches.length === 0)
|
|
907
|
-
return [];
|
|
908
|
-
await this.ensurePageAnnotationsLoaded(page);
|
|
909
|
-
const list = this.uiShell.store.getState().pageAnnotations.get(page);
|
|
910
|
-
const resolved = patches.map(({ name, patch }) => {
|
|
911
|
-
const annotationIndex = this.requireAnnotationIndex(page, name);
|
|
912
|
-
const merged = applyAnnotationPatch(list[annotationIndex], patch);
|
|
913
|
-
const annotation = { ...merged, name };
|
|
914
|
-
return { annotationIndex, annotation };
|
|
915
|
-
});
|
|
916
|
-
this.uiShell.dispatch({ type: "UPDATE_ANNOTATIONS", pageIndex: page, updates: resolved });
|
|
917
|
-
return resolved.map((r) => r.annotation);
|
|
918
|
-
}
|
|
919
|
-
/**
|
|
920
|
-
* Remove an annotation, identified by its `name` (NM).
|
|
921
|
-
*
|
|
922
|
-
* @param page - Page index (0-based)
|
|
923
|
-
* @param name - The annotation's `name` (NM).
|
|
924
|
-
* @throws If no annotation with the given `name` is found on the page.
|
|
925
|
-
*/
|
|
926
|
-
async removePageAnnotation(page, name) {
|
|
927
|
-
this.ensureLoaded();
|
|
928
|
-
this.ensureUiMode();
|
|
929
|
-
const index = await this.findAnnotationIndex(page, name);
|
|
930
|
-
this.uiShell.dispatch({ type: "REMOVE_ANNOTATION", pageIndex: page, annotationIndex: index });
|
|
931
|
-
}
|
|
932
|
-
/**
|
|
933
|
-
* Ensure pageAnnotations is populated for a page so that mutator actions
|
|
934
|
-
* have a baseline list to operate on. The reducer's ADD path tolerates a
|
|
935
|
-
* missing page, but UPDATE/REMOVE need the existing annotations loaded
|
|
936
|
-
* so we don't silently lose what the worker has.
|
|
937
|
-
*/
|
|
938
|
-
async ensurePageAnnotationsLoaded(page) {
|
|
939
|
-
const state = this.uiShell.store.getState();
|
|
940
|
-
if (state.pageAnnotations.has(page))
|
|
941
|
-
return;
|
|
942
|
-
const raw = (await this.workerClient.getPageAnnotations(this.documentId, page));
|
|
943
|
-
this.uiShell.dispatch({ type: "SET_PAGE_ANNOTATIONS", pageIndex: page, annotations: raw });
|
|
944
|
-
}
|
|
945
|
-
async findAnnotationIndex(page, name) {
|
|
946
|
-
await this.ensurePageAnnotationsLoaded(page);
|
|
947
|
-
return this.requireAnnotationIndex(page, name);
|
|
948
|
-
}
|
|
949
|
-
/**
|
|
950
|
-
* Synchronous variant of `findAnnotationIndex` for callers that have
|
|
951
|
-
* already awaited `ensurePageAnnotationsLoaded` — used by the batch
|
|
952
|
-
* mutators so all per-item lookups happen against a stable, loaded list.
|
|
953
|
-
*/
|
|
954
|
-
requireAnnotationIndex(page, name) {
|
|
955
|
-
const list = this.uiShell.store.getState().pageAnnotations.get(page) ?? [];
|
|
956
|
-
const index = list.findIndex((a) => a.name === name);
|
|
957
|
-
if (index < 0) {
|
|
958
|
-
throw new Error(`No annotation with name "${name}" on page ${page}`);
|
|
959
|
-
}
|
|
960
|
-
return index;
|
|
961
|
-
}
|
|
962
|
-
/**
|
|
963
|
-
* Get the layout structure for a specific page.
|
|
964
|
-
* Returns frames, parcels, lines, runs, glyphs, tables, and grids
|
|
965
|
-
* without building the full display list.
|
|
966
|
-
* All coordinates are in points (1/72 inch).
|
|
967
|
-
* @param page - Page index (0-based)
|
|
968
|
-
*/
|
|
969
|
-
async getLayoutPage(page) {
|
|
970
|
-
this.ensureLoaded();
|
|
971
|
-
if (page < 0 || page >= this._pageCount) {
|
|
972
|
-
throw new Error(`Page index ${page} out of bounds (0-${this._pageCount - 1})`);
|
|
973
|
-
}
|
|
974
|
-
return (await this.workerClient.getLayoutPage(this.documentId, page));
|
|
975
|
-
}
|
|
976
|
-
/**
|
|
977
|
-
* Get the plain text of a page, matching exactly what the search engine sees.
|
|
978
|
-
*
|
|
979
|
-
* Text is extracted from the layout model: glyph runs are concatenated in
|
|
980
|
-
* visual order, with spaces/tabs rendered as " ", paragraph ends and line
|
|
981
|
-
* breaks as "\n", and inline drawings as U+FFFC (object replacement char).
|
|
982
|
-
*
|
|
983
|
-
* @param page - Page index (0-based)
|
|
984
|
-
*/
|
|
985
|
-
async getPageText(page) {
|
|
986
|
-
const layout = await this.getLayoutPage(page);
|
|
987
|
-
return extractPageText(layout);
|
|
988
|
-
}
|
|
989
|
-
// ===========================================================================
|
|
990
|
-
// Navigation
|
|
991
|
-
// ===========================================================================
|
|
992
|
-
/**
|
|
993
|
-
* Get the current page number (1-based).
|
|
994
|
-
*/
|
|
995
|
-
get currentPage() {
|
|
996
|
-
if (this.uiShell) {
|
|
997
|
-
return this.uiShell.getState().page;
|
|
998
|
-
}
|
|
999
|
-
return 1;
|
|
1000
|
-
}
|
|
1001
|
-
/**
|
|
1002
|
-
* Navigate to a specific page.
|
|
1003
|
-
* @param page - Page number (1-based)
|
|
1004
|
-
*/
|
|
1005
|
-
goToPage(page) {
|
|
1006
|
-
this.ensureNotDestroyed();
|
|
1007
|
-
if (!this.uiShell) {
|
|
1008
|
-
throw new Error("Navigation requires UI mode (container must be provided)");
|
|
1009
|
-
}
|
|
1010
|
-
this.uiShell.dispatch({ type: "NAVIGATE_TO_PAGE", page });
|
|
1011
|
-
}
|
|
1012
|
-
/**
|
|
1013
|
-
* Navigate to a destination (page + position + zoom).
|
|
1014
|
-
* @param destination - Full destination object with page index and display mode
|
|
1015
|
-
* @param options - Optional navigation options
|
|
1016
|
-
* @param options.scrollAlignment - How to align the target in the viewport:
|
|
1017
|
-
* "top" (default), "center", "bottom", or "nearest" (minimal scroll to fit in view)
|
|
1018
|
-
*/
|
|
1019
|
-
goToDestination(destination, options) {
|
|
1020
|
-
this.ensureNotDestroyed();
|
|
1021
|
-
if (!this.uiShell) {
|
|
1022
|
-
throw new Error("Navigation requires UI mode (container must be provided)");
|
|
1023
|
-
}
|
|
1024
|
-
this.uiShell.dispatch({
|
|
1025
|
-
type: "NAVIGATE_TO_DESTINATION",
|
|
1026
|
-
destination,
|
|
1027
|
-
scrollAlignment: options?.scrollAlignment,
|
|
1028
|
-
});
|
|
1029
|
-
}
|
|
1030
|
-
/**
|
|
1031
|
-
* Navigate to the next page.
|
|
1032
|
-
*/
|
|
1033
|
-
nextPage() {
|
|
1034
|
-
this.ensureNotDestroyed();
|
|
1035
|
-
this.ensureUiMode();
|
|
1036
|
-
const state = this.uiShell.getState();
|
|
1037
|
-
if (state.page < state.pageCount) {
|
|
1038
|
-
this.uiShell.dispatch({ type: "NAVIGATE_TO_PAGE", page: state.page + 1 });
|
|
1039
|
-
}
|
|
1040
|
-
}
|
|
1041
|
-
/**
|
|
1042
|
-
* Navigate to the previous page.
|
|
1043
|
-
*/
|
|
1044
|
-
previousPage() {
|
|
1045
|
-
this.ensureNotDestroyed();
|
|
1046
|
-
this.ensureUiMode();
|
|
1047
|
-
const state = this.uiShell.getState();
|
|
1048
|
-
if (state.page > 1) {
|
|
1049
|
-
this.uiShell.dispatch({ type: "NAVIGATE_TO_PAGE", page: state.page - 1 });
|
|
1050
|
-
}
|
|
1051
|
-
}
|
|
1052
|
-
// ===========================================================================
|
|
1053
|
-
// Zoom
|
|
1054
|
-
// ===========================================================================
|
|
1055
|
-
/**
|
|
1056
|
-
* Current zoom level (1 = 100%).
|
|
1057
|
-
*/
|
|
1058
|
-
get zoom() {
|
|
1059
|
-
if (this.uiShell) {
|
|
1060
|
-
const state = this.uiShell.getState();
|
|
1061
|
-
return state.zoomMode === "custom" ? state.zoom : (state.effectiveZoom ?? state.zoom);
|
|
1062
|
-
}
|
|
1063
|
-
return 1;
|
|
1064
|
-
}
|
|
1065
|
-
/**
|
|
1066
|
-
* Current zoom mode.
|
|
1067
|
-
*/
|
|
1068
|
-
get zoomMode() {
|
|
1069
|
-
if (this.uiShell) {
|
|
1070
|
-
return this.uiShell.getState().zoomMode;
|
|
1071
|
-
}
|
|
1072
|
-
return "fit-spread-width";
|
|
1073
|
-
}
|
|
1074
|
-
/**
|
|
1075
|
-
* Zoom in to the next zoom step.
|
|
1076
|
-
*/
|
|
1077
|
-
zoomIn() {
|
|
1078
|
-
this.ensureNotDestroyed();
|
|
1079
|
-
this.ensureUiMode();
|
|
1080
|
-
this.uiShell.dispatch({ type: "ZOOM_IN" });
|
|
1081
|
-
}
|
|
1082
|
-
/**
|
|
1083
|
-
* Zoom out to the previous zoom step.
|
|
1084
|
-
*/
|
|
1085
|
-
zoomOut() {
|
|
1086
|
-
this.ensureNotDestroyed();
|
|
1087
|
-
this.ensureUiMode();
|
|
1088
|
-
this.uiShell.dispatch({ type: "ZOOM_OUT" });
|
|
1089
|
-
}
|
|
1090
|
-
/**
|
|
1091
|
-
* Set zoom to a specific level (1 = 100%). Switches to custom zoom mode.
|
|
1092
|
-
*/
|
|
1093
|
-
setZoom(zoom) {
|
|
1094
|
-
this.ensureNotDestroyed();
|
|
1095
|
-
this.ensureUiMode();
|
|
1096
|
-
this.uiShell.dispatch({ type: "SET_ZOOM", zoom });
|
|
1097
|
-
}
|
|
1098
|
-
/**
|
|
1099
|
-
* Set zoom mode.
|
|
1100
|
-
*/
|
|
1101
|
-
setZoomMode(mode) {
|
|
1102
|
-
this.ensureNotDestroyed();
|
|
1103
|
-
this.ensureUiMode();
|
|
1104
|
-
this.uiShell.dispatch({ type: "SET_ZOOM_MODE", mode });
|
|
1105
|
-
}
|
|
1106
|
-
// ===========================================================================
|
|
1107
|
-
// View Modes
|
|
1108
|
-
// ===========================================================================
|
|
1109
|
-
/** Current scroll mode. */
|
|
1110
|
-
get scrollMode() {
|
|
1111
|
-
return this.uiShell?.getState().scrollMode ?? "continuous";
|
|
1112
|
-
}
|
|
1113
|
-
/** Current layout mode. */
|
|
1114
|
-
get layoutMode() {
|
|
1115
|
-
return this.uiShell?.getState().layoutMode ?? "single-page";
|
|
1116
|
-
}
|
|
1117
|
-
/** Current page rotation in degrees. */
|
|
1118
|
-
get pageRotation() {
|
|
1119
|
-
return this.uiShell?.getState().pageRotation ?? 0;
|
|
1120
|
-
}
|
|
1121
|
-
/** Current spacing mode. */
|
|
1122
|
-
get spacingMode() {
|
|
1123
|
-
return this.uiShell?.getState().spacingMode ?? "all";
|
|
1124
|
-
}
|
|
1125
|
-
/** Whether the viewer is in fullscreen mode. */
|
|
1126
|
-
get isFullscreen() {
|
|
1127
|
-
return this.uiShell?.getState().isFullscreen ?? false;
|
|
1128
|
-
}
|
|
1129
|
-
/** Current view mode. */
|
|
1130
|
-
get viewMode() {
|
|
1131
|
-
return this.uiShell?.getState().viewMode ?? "paged";
|
|
1132
|
-
}
|
|
1133
|
-
/**
|
|
1134
|
-
* Set view mode (paged or continuous).
|
|
1135
|
-
*/
|
|
1136
|
-
setViewMode(mode) {
|
|
1137
|
-
this.ensureNotDestroyed();
|
|
1138
|
-
this.ensureUiMode();
|
|
1139
|
-
this.uiShell.dispatch({ type: "SET_VIEW_MODE", mode });
|
|
1140
|
-
}
|
|
1141
|
-
/**
|
|
1142
|
-
* Get the current view mode.
|
|
1143
|
-
*/
|
|
1144
|
-
getViewMode() {
|
|
1145
|
-
return this.viewMode;
|
|
1146
|
-
}
|
|
1147
|
-
/**
|
|
1148
|
-
* Set scroll mode.
|
|
1149
|
-
*/
|
|
1150
|
-
setScrollMode(mode) {
|
|
1151
|
-
this.ensureNotDestroyed();
|
|
1152
|
-
this.ensureUiMode();
|
|
1153
|
-
this.uiShell.dispatch({ type: "SET_SCROLL_MODE", mode });
|
|
1154
|
-
}
|
|
1155
|
-
/** Default scroll alignment for navigation (outline, links, goToDestination). */
|
|
1156
|
-
get navigationScrollAlignment() {
|
|
1157
|
-
return this.uiShell?.getState().navigationScrollAlignment ?? "top";
|
|
1158
|
-
}
|
|
1159
|
-
/** Default scroll alignment for search result navigation. */
|
|
1160
|
-
get searchScrollAlignment() {
|
|
1161
|
-
return this.uiShell?.getState().searchScrollAlignment ?? "center";
|
|
1162
|
-
}
|
|
1163
|
-
/**
|
|
1164
|
-
* Set the default scroll alignment for navigation (outline, links, goToDestination).
|
|
1165
|
-
*/
|
|
1166
|
-
setNavigationScrollAlignment(alignment) {
|
|
1167
|
-
this.ensureNotDestroyed();
|
|
1168
|
-
this.ensureUiMode();
|
|
1169
|
-
this.uiShell.dispatch({ type: "SET_NAVIGATION_SCROLL_ALIGNMENT", alignment });
|
|
1170
|
-
}
|
|
1171
|
-
/**
|
|
1172
|
-
* Set the default scroll alignment for search result navigation.
|
|
1173
|
-
*/
|
|
1174
|
-
setSearchScrollAlignment(alignment) {
|
|
1175
|
-
this.ensureNotDestroyed();
|
|
1176
|
-
this.ensureUiMode();
|
|
1177
|
-
this.uiShell.dispatch({ type: "SET_SEARCH_SCROLL_ALIGNMENT", alignment });
|
|
1178
|
-
}
|
|
1179
|
-
/**
|
|
1180
|
-
* Set page layout mode.
|
|
1181
|
-
*/
|
|
1182
|
-
setLayoutMode(mode) {
|
|
1183
|
-
this.ensureNotDestroyed();
|
|
1184
|
-
this.ensureUiMode();
|
|
1185
|
-
this.uiShell.dispatch({ type: "SET_LAYOUT_MODE", mode });
|
|
1186
|
-
}
|
|
1187
|
-
/**
|
|
1188
|
-
* Set page rotation.
|
|
1189
|
-
*/
|
|
1190
|
-
setPageRotation(rotation) {
|
|
1191
|
-
this.ensureNotDestroyed();
|
|
1192
|
-
this.ensureUiMode();
|
|
1193
|
-
this.uiShell.dispatch({ type: "SET_PAGE_ROTATION", rotation });
|
|
1194
|
-
}
|
|
1195
|
-
/**
|
|
1196
|
-
* Set spacing mode.
|
|
1197
|
-
*/
|
|
1198
|
-
setSpacingMode(mode) {
|
|
1199
|
-
this.ensureNotDestroyed();
|
|
1200
|
-
this.ensureUiMode();
|
|
1201
|
-
this.uiShell.dispatch({ type: "SET_SPACING_MODE", mode });
|
|
1202
|
-
}
|
|
1203
|
-
/**
|
|
1204
|
-
* Enter or exit fullscreen mode.
|
|
1205
|
-
*/
|
|
1206
|
-
setFullscreen(fullscreen) {
|
|
1207
|
-
this.ensureNotDestroyed();
|
|
1208
|
-
this.ensureUiMode();
|
|
1209
|
-
this.uiShell.dispatch({ type: "SET_FULLSCREEN", isFullscreen: fullscreen });
|
|
1210
|
-
// Also toggle the actual browser fullscreen
|
|
1211
|
-
const root = this.container?.querySelector(".udoc-viewer-root");
|
|
1212
|
-
if (root) {
|
|
1213
|
-
if (fullscreen && !document.fullscreenElement) {
|
|
1214
|
-
root.requestFullscreen().catch(() => { });
|
|
1215
|
-
}
|
|
1216
|
-
else if (!fullscreen && document.fullscreenElement) {
|
|
1217
|
-
document.exitFullscreen().catch(() => { });
|
|
1218
|
-
}
|
|
1219
|
-
}
|
|
1220
|
-
}
|
|
1221
|
-
// ===========================================================================
|
|
1222
|
-
// UI Component Visibility
|
|
1223
|
-
// ===========================================================================
|
|
1224
|
-
/**
|
|
1225
|
-
* Show or hide the top toolbar.
|
|
1226
|
-
*/
|
|
1227
|
-
setToolbarVisible(visible) {
|
|
1228
|
-
this.ensureNotDestroyed();
|
|
1229
|
-
this.ensureUiMode();
|
|
1230
|
-
this.uiShell.dispatch({ type: "SET_TOOLBAR_VISIBLE", visible });
|
|
1231
|
-
}
|
|
1232
|
-
/**
|
|
1233
|
-
* Show or hide the floating toolbar (page navigation, zoom, view mode controls).
|
|
1234
|
-
*/
|
|
1235
|
-
setFloatingToolbarVisible(visible) {
|
|
1236
|
-
this.ensureNotDestroyed();
|
|
1237
|
-
this.ensureUiMode();
|
|
1238
|
-
this.uiShell.dispatch({ type: "SET_FLOATING_TOOLBAR_VISIBLE", visible });
|
|
1239
|
-
}
|
|
1240
|
-
/**
|
|
1241
|
-
* Currently active tool, as a tagged union. The `kind` is one of `"pointer"`,
|
|
1242
|
-
* `"hand"`, `"zoom"`, `"annotate"`, `"markup"`; for `"annotate"` and `"markup"`
|
|
1243
|
-
* a `sub` field carries the active sub-tool (`"freehand"`, `"highlight"`, etc.).
|
|
1244
|
-
*/
|
|
1245
|
-
get activeTool() {
|
|
1246
|
-
return this.uiShell?.getState().activeTool ?? { kind: "pointer" };
|
|
1247
|
-
}
|
|
1248
|
-
/**
|
|
1249
|
-
* Switch the currently active tool. Tool-set kinds (`"annotate"`, `"markup"`)
|
|
1250
|
-
* require a `sub`, e.g. `{ kind: "annotate", sub: "freehand" }`. Calling
|
|
1251
|
-
* this with the same tool-set kind that's already active toggles back to
|
|
1252
|
-
* the pointer tool, matching the toolbar UI.
|
|
1253
|
-
*/
|
|
1254
|
-
setActiveTool(tool) {
|
|
1255
|
-
this.ensureNotDestroyed();
|
|
1256
|
-
this.ensureUiMode();
|
|
1257
|
-
this.uiShell.dispatch({ type: "SET_ACTIVE_TOOL", tool });
|
|
1258
|
-
}
|
|
1259
|
-
/**
|
|
1260
|
-
* Enable or disable the fullscreen button.
|
|
1261
|
-
*/
|
|
1262
|
-
setFullscreenEnabled(enabled) {
|
|
1263
|
-
this.ensureNotDestroyed();
|
|
1264
|
-
this.ensureUiMode();
|
|
1265
|
-
this.uiShell.dispatch({ type: "SET_FULLSCREEN_BUTTON_VISIBLE", visible: enabled });
|
|
1266
|
-
}
|
|
1267
|
-
/**
|
|
1268
|
-
* Enable or disable the download button.
|
|
1269
|
-
*/
|
|
1270
|
-
setDownloadEnabled(enabled) {
|
|
1271
|
-
this.ensureNotDestroyed();
|
|
1272
|
-
this.ensureUiMode();
|
|
1273
|
-
this.uiShell.dispatch({ type: "SET_DOWNLOAD_BUTTON_VISIBLE", visible: enabled });
|
|
1274
|
-
}
|
|
1275
|
-
/**
|
|
1276
|
-
* Enable or disable the print button.
|
|
1277
|
-
*/
|
|
1278
|
-
setPrintEnabled(enabled) {
|
|
1279
|
-
this.ensureNotDestroyed();
|
|
1280
|
-
this.ensureUiMode();
|
|
1281
|
-
this.uiShell.dispatch({ type: "SET_PRINT_BUTTON_VISIBLE", visible: enabled });
|
|
1282
|
-
}
|
|
1283
|
-
/** Current theme mode. */
|
|
1284
|
-
get theme() {
|
|
1285
|
-
return this.uiShell?.getState().theme ?? "light";
|
|
1286
|
-
}
|
|
1287
|
-
/**
|
|
1288
|
-
* Set the viewer color theme.
|
|
1289
|
-
* @param theme - 'light', 'dark', or 'system'
|
|
1290
|
-
*/
|
|
1291
|
-
setTheme(theme) {
|
|
1292
|
-
this.ensureNotDestroyed();
|
|
1293
|
-
this.ensureUiMode();
|
|
1294
|
-
this.uiShell.dispatch({ type: "SET_THEME", theme });
|
|
1295
|
-
}
|
|
1296
|
-
/**
|
|
1297
|
-
* Enable or disable the theme toggle button in the toolbar.
|
|
1298
|
-
*/
|
|
1299
|
-
setThemeSwitchingEnabled(enabled) {
|
|
1300
|
-
this.ensureNotDestroyed();
|
|
1301
|
-
this.ensureUiMode();
|
|
1302
|
-
this.uiShell.dispatch({ type: "SET_THEME_SWITCHING_DISABLED", disabled: !enabled });
|
|
1303
|
-
}
|
|
1304
|
-
/**
|
|
1305
|
-
* Enable or disable text selection in the viewer.
|
|
1306
|
-
*/
|
|
1307
|
-
setTextSelectionEnabled(enabled) {
|
|
1308
|
-
this.ensureNotDestroyed();
|
|
1309
|
-
this.ensureUiMode();
|
|
1310
|
-
this.uiShell.dispatch({ type: "SET_TEXT_SELECTION_DISABLED", disabled: !enabled });
|
|
1311
|
-
}
|
|
1312
|
-
/**
|
|
1313
|
-
* Set the minimum zoom level.
|
|
1314
|
-
*/
|
|
1315
|
-
setMinZoom(zoom) {
|
|
1316
|
-
this.ensureNotDestroyed();
|
|
1317
|
-
this.ensureUiMode();
|
|
1318
|
-
this.uiShell.dispatch({ type: "SET_MIN_ZOOM", zoom });
|
|
1319
|
-
}
|
|
1320
|
-
/**
|
|
1321
|
-
* Set the maximum zoom level.
|
|
1322
|
-
*/
|
|
1323
|
-
setMaxZoom(zoom) {
|
|
1324
|
-
this.ensureNotDestroyed();
|
|
1325
|
-
this.ensureUiMode();
|
|
1326
|
-
this.uiShell.dispatch({ type: "SET_MAX_ZOOM", zoom });
|
|
1327
|
-
}
|
|
1328
|
-
/**
|
|
1329
|
-
* Enable or disable the entire left panel area.
|
|
1330
|
-
* When disabled, the left panel is hidden and all left panel tabs are inaccessible.
|
|
1331
|
-
*/
|
|
1332
|
-
setLeftPanelEnabled(enabled) {
|
|
1333
|
-
this.ensureNotDestroyed();
|
|
1334
|
-
this.ensureUiMode();
|
|
1335
|
-
this.uiShell.dispatch({ type: "SET_LEFT_PANEL_VISIBLE", visible: enabled });
|
|
1336
|
-
}
|
|
1337
|
-
/**
|
|
1338
|
-
* Enable or disable the entire right panel area.
|
|
1339
|
-
* When disabled, the right panel is hidden and all right panel tabs are inaccessible.
|
|
1340
|
-
*/
|
|
1341
|
-
setRightPanelEnabled(enabled) {
|
|
1342
|
-
this.ensureNotDestroyed();
|
|
1343
|
-
this.ensureUiMode();
|
|
1344
|
-
this.uiShell.dispatch({ type: "SET_RIGHT_PANEL_VISIBLE", visible: enabled });
|
|
1345
|
-
}
|
|
1346
|
-
/**
|
|
1347
|
-
* Enable or disable a specific panel tab.
|
|
1348
|
-
* Disabled panels are removed from the UI and cannot be opened.
|
|
1349
|
-
* If the panel is currently open and being disabled, it will be closed.
|
|
1350
|
-
*/
|
|
1351
|
-
setPanelEnabled(panel, enabled) {
|
|
1352
|
-
this.ensureNotDestroyed();
|
|
1353
|
-
this.ensureUiMode();
|
|
1354
|
-
this.uiShell.dispatch({ type: "SET_PANEL_DISABLED", panel, disabled: !enabled });
|
|
1355
|
-
}
|
|
1356
|
-
/**
|
|
1357
|
-
* Open a specific panel.
|
|
1358
|
-
* Has no effect if the panel is disabled via `setPanelEnabled()` or a `disable*` option.
|
|
1359
|
-
*/
|
|
1360
|
-
openPanel(panel) {
|
|
1361
|
-
this.ensureNotDestroyed();
|
|
1362
|
-
this.ensureUiMode();
|
|
1363
|
-
this.uiShell.dispatch({ type: "TOGGLE_PANEL", panel });
|
|
1364
|
-
// If it was already open, TOGGLE_PANEL closed it. Re-open.
|
|
1365
|
-
if (this.uiShell.getState().activePanel !== panel) {
|
|
1366
|
-
this.uiShell.dispatch({ type: "TOGGLE_PANEL", panel });
|
|
1367
|
-
}
|
|
1368
|
-
}
|
|
1369
|
-
/**
|
|
1370
|
-
* Close the currently open panel.
|
|
1371
|
-
*/
|
|
1372
|
-
closePanel() {
|
|
1373
|
-
this.ensureNotDestroyed();
|
|
1374
|
-
this.ensureUiMode();
|
|
1375
|
-
this.uiShell.dispatch({ type: "CLOSE_PANEL" });
|
|
1376
|
-
}
|
|
1377
|
-
// ===========================================================================
|
|
1378
|
-
// Search
|
|
1379
|
-
// ===========================================================================
|
|
1380
|
-
/**
|
|
1381
|
-
* Search for text in the document.
|
|
1382
|
-
* Returns a promise that resolves with the final search matches once all page text
|
|
1383
|
-
* has been loaded and the search completes. Highlight overlays are rendered automatically.
|
|
1384
|
-
*
|
|
1385
|
-
* Results are also available via the `search:change` event (fires for intermediate
|
|
1386
|
-
* results as pages load) and the `searchMatches` getter.
|
|
1387
|
-
*
|
|
1388
|
-
* @param query - The text to search for
|
|
1389
|
-
* @param options - Search options
|
|
1390
|
-
* @param options.caseSensitive - Whether to match case (overrides current default)
|
|
1391
|
-
* @param options.fuzzy - Enable fuzzy matching. When true, all whitespace, control
|
|
1392
|
-
* characters, pipes (`|`), and zero-width characters are stripped from both the
|
|
1393
|
-
* query and the document text before comparison. This allows AI-generated citations
|
|
1394
|
-
* to match even when spacing or separators differ from the original document
|
|
1395
|
-
* (e.g. `"cell A | cell B"` will match `"cell A\ncell B"`).
|
|
1396
|
-
* @param options.pageRange - Inclusive 0-based page range `[start, end]` to restrict
|
|
1397
|
-
* search to. Both text loading and match collection are limited to this range.
|
|
1398
|
-
* Omit to search the entire document. Each `search()` call is self-contained —
|
|
1399
|
-
* the range is reset to "all pages" unless explicitly provided.
|
|
1400
|
-
* @returns Promise resolving with the search matches
|
|
1401
|
-
*/
|
|
1402
|
-
search(query, options) {
|
|
1403
|
-
this.ensureNotDestroyed();
|
|
1404
|
-
this.ensureUiMode();
|
|
1405
|
-
const stateBefore = this.uiShell.getState();
|
|
1406
|
-
if (options?.caseSensitive !== undefined) {
|
|
1407
|
-
this.uiShell.dispatch({ type: "SET_SEARCH_CASE_SENSITIVE", caseSensitive: options.caseSensitive });
|
|
1408
|
-
}
|
|
1409
|
-
if (options?.fuzzy !== undefined) {
|
|
1410
|
-
this.uiShell.dispatch({ type: "SET_SEARCH_FUZZY", fuzzy: options.fuzzy });
|
|
1411
|
-
}
|
|
1412
|
-
const range = options?.pageRange ? { start: options.pageRange[0], end: options.pageRange[1] } : null;
|
|
1413
|
-
this.uiShell.dispatch({ type: "SET_SEARCH_PAGE_RANGE", range });
|
|
1414
|
-
this.uiShell.dispatch({ type: "SET_SEARCH_QUERY", query });
|
|
1415
|
-
// Empty/whitespace query — resolve immediately
|
|
1416
|
-
if (!query.trim()) {
|
|
1417
|
-
return Promise.resolve([]);
|
|
1418
|
-
}
|
|
1419
|
-
// Nothing changed (same query and options) — return current results
|
|
1420
|
-
const stateAfter = this.uiShell.getState();
|
|
1421
|
-
if (stateBefore === stateAfter) {
|
|
1422
|
-
return Promise.resolve(stateAfter.searchMatches);
|
|
1423
|
-
}
|
|
1424
|
-
return new Promise((resolve) => {
|
|
1425
|
-
const unsub = this.uiShell.store.subscribeEffect((prev, next) => {
|
|
1426
|
-
// Query was superseded by another search() call — resolve empty
|
|
1427
|
-
if (next.searchQuery !== query) {
|
|
1428
|
-
unsub();
|
|
1429
|
-
resolve([]);
|
|
1430
|
-
return;
|
|
1431
|
-
}
|
|
1432
|
-
// Resolve when text is fully loaded and search results have been computed
|
|
1433
|
-
// (skip the initial matches clear from SET_SEARCH_QUERY by checking query is stable)
|
|
1434
|
-
if (next.searchTextLoaded &&
|
|
1435
|
-
prev.searchQuery === next.searchQuery &&
|
|
1436
|
-
prev.searchMatches !== next.searchMatches) {
|
|
1437
|
-
unsub();
|
|
1438
|
-
resolve(next.searchMatches);
|
|
1439
|
-
}
|
|
1440
|
-
});
|
|
1441
|
-
});
|
|
1442
|
-
}
|
|
1443
|
-
/**
|
|
1444
|
-
* Navigate to the next search match.
|
|
1445
|
-
* @param options - Optional overrides for this navigation
|
|
1446
|
-
* @param options.scrollAlignment - Override scroll alignment for this call only
|
|
1447
|
-
*/
|
|
1448
|
-
searchNext(options) {
|
|
1449
|
-
this.ensureNotDestroyed();
|
|
1450
|
-
this.ensureUiMode();
|
|
1451
|
-
this.uiShell.dispatch({ type: "SEARCH_NEXT", scrollAlignment: options?.scrollAlignment });
|
|
1452
|
-
}
|
|
1453
|
-
/**
|
|
1454
|
-
* Navigate to the previous search match.
|
|
1455
|
-
* @param options - Optional overrides for this navigation
|
|
1456
|
-
* @param options.scrollAlignment - Override scroll alignment for this call only
|
|
1457
|
-
*/
|
|
1458
|
-
searchPrev(options) {
|
|
1459
|
-
this.ensureNotDestroyed();
|
|
1460
|
-
this.ensureUiMode();
|
|
1461
|
-
this.uiShell.dispatch({ type: "SEARCH_PREV", scrollAlignment: options?.scrollAlignment });
|
|
1462
|
-
}
|
|
1463
|
-
/**
|
|
1464
|
-
* Clear the current search query and results.
|
|
1465
|
-
*/
|
|
1466
|
-
clearSearch() {
|
|
1467
|
-
this.ensureNotDestroyed();
|
|
1468
|
-
this.ensureUiMode();
|
|
1469
|
-
this.uiShell.dispatch({ type: "CLEAR_SEARCH" });
|
|
1470
|
-
}
|
|
1471
|
-
/**
|
|
1472
|
-
* Get the current search matches.
|
|
1473
|
-
*/
|
|
1474
|
-
get searchMatches() {
|
|
1475
|
-
this.ensureNotDestroyed();
|
|
1476
|
-
this.ensureUiMode();
|
|
1477
|
-
return this.uiShell.getState().searchMatches;
|
|
1478
|
-
}
|
|
1479
|
-
/**
|
|
1480
|
-
* Get the index of the currently active search match (-1 if none).
|
|
1481
|
-
*/
|
|
1482
|
-
get searchActiveIndex() {
|
|
1483
|
-
this.ensureNotDestroyed();
|
|
1484
|
-
this.ensureUiMode();
|
|
1485
|
-
return this.uiShell.getState().searchActiveIndex;
|
|
1486
|
-
}
|
|
1487
|
-
/**
|
|
1488
|
-
* Set the active search match by index. Navigates the viewport to the match.
|
|
1489
|
-
*
|
|
1490
|
-
* @param index - 0-based index into `searchMatches`
|
|
1491
|
-
* @param options - Optional overrides for this navigation
|
|
1492
|
-
* @param options.scrollAlignment - Override scroll alignment for this call only
|
|
1493
|
-
*/
|
|
1494
|
-
setSearchActiveIndex(index, options) {
|
|
1495
|
-
this.ensureNotDestroyed();
|
|
1496
|
-
this.ensureUiMode();
|
|
1497
|
-
this.uiShell.dispatch({ type: "SET_SEARCH_ACTIVE_INDEX", index, scrollAlignment: options?.scrollAlignment });
|
|
1498
|
-
}
|
|
1499
|
-
// ===========================================================================
|
|
1500
|
-
// Page Rendering
|
|
1501
|
-
// ===========================================================================
|
|
1502
|
-
/**
|
|
1503
|
-
* Render a page to an image.
|
|
1504
|
-
*
|
|
1505
|
-
* @param page - Page index (0-based)
|
|
1506
|
-
* @param options - Render options (scale, format, etc.)
|
|
1507
|
-
*/
|
|
1508
|
-
async renderPage(page, options = {}) {
|
|
1509
|
-
return this.renderWithType(page, "page", options);
|
|
1510
|
-
}
|
|
1511
|
-
/**
|
|
1512
|
-
* Render a thumbnail of a page.
|
|
1513
|
-
*
|
|
1514
|
-
* Similar to renderPage but uses lower priority in the render queue,
|
|
1515
|
-
* making it suitable for generating thumbnails without blocking main page renders.
|
|
1516
|
-
*
|
|
1517
|
-
* @param page - Page index (0-based)
|
|
1518
|
-
* @param options - Render options (scale, format, etc.)
|
|
1519
|
-
*/
|
|
1520
|
-
async renderThumbnail(page, options = {}) {
|
|
1521
|
-
return this.renderWithType(page, "thumbnail", options);
|
|
1522
|
-
}
|
|
1523
|
-
/**
|
|
1524
|
-
* Render a rectangular sub-region of a page.
|
|
1525
|
-
*
|
|
1526
|
-
* The rect is expressed in **page points** (1 point = 1/72 inch), with the
|
|
1527
|
-
* origin at the top-left of the page — the same coordinate space as
|
|
1528
|
-
* `getPageInfo(page).width` / `.height`.
|
|
1529
|
-
*
|
|
1530
|
-
* Output pixel size is `rect.width * scale` × `rect.height * scale`.
|
|
1531
|
-
*
|
|
1532
|
-
* Internally this renders the full page at the requested scale (sharing the
|
|
1533
|
-
* render cache with `renderPage`) and crops the result, so the underlying
|
|
1534
|
-
* full-page render is bounded by the engine's max-render limits.
|
|
1535
|
-
*
|
|
1536
|
-
* @param page - Page index (0-based)
|
|
1537
|
-
* @param rect - Region to render, in page points (top-left origin)
|
|
1538
|
-
* @param options - Render options. `scale` controls resolution; `format`,
|
|
1539
|
-
* `imageType`, `quality`, `force`, and `boost` behave as in `renderPage`.
|
|
1540
|
-
*/
|
|
1541
|
-
async renderRegion(page, rect, options = {}) {
|
|
1542
|
-
this.ensureLoaded();
|
|
1543
|
-
if (!(rect.width > 0) || !(rect.height > 0)) {
|
|
1544
|
-
throw new Error("renderRegion: rect width and height must be positive");
|
|
1545
|
-
}
|
|
1546
|
-
const scale = options.scale ?? 1;
|
|
1547
|
-
const format = options.format ?? "image-data";
|
|
1548
|
-
const force = options.force ?? false;
|
|
1549
|
-
const boost = options.boost ?? false;
|
|
1550
|
-
const renderRequest = {
|
|
1551
|
-
docId: this.documentId,
|
|
1552
|
-
page: page + 1,
|
|
1553
|
-
type: "page",
|
|
1554
|
-
scale,
|
|
1555
|
-
};
|
|
1556
|
-
let result;
|
|
1557
|
-
if (force) {
|
|
1558
|
-
result = await this.workerClient.forceRender(renderRequest);
|
|
1559
|
-
}
|
|
1560
|
-
else {
|
|
1561
|
-
if (boost) {
|
|
1562
|
-
this.workerClient.boostPageRenderPriority(this.documentId, page + 1);
|
|
1563
|
-
}
|
|
1564
|
-
result = await this.workerClient.requestRender(renderRequest);
|
|
1565
|
-
}
|
|
1566
|
-
const fullBitmap = result.bitmap;
|
|
1567
|
-
let sx = Math.round(rect.x * scale);
|
|
1568
|
-
let sy = Math.round(rect.y * scale);
|
|
1569
|
-
let sw = Math.round(rect.width * scale);
|
|
1570
|
-
let sh = Math.round(rect.height * scale);
|
|
1571
|
-
// Clamp to the rendered bitmap so a rect that spills past the page edge
|
|
1572
|
-
// returns the visible portion instead of failing.
|
|
1573
|
-
if (sx < 0) {
|
|
1574
|
-
sw += sx;
|
|
1575
|
-
sx = 0;
|
|
1576
|
-
}
|
|
1577
|
-
if (sy < 0) {
|
|
1578
|
-
sh += sy;
|
|
1579
|
-
sy = 0;
|
|
1580
|
-
}
|
|
1581
|
-
sw = Math.min(sw, fullBitmap.width - sx);
|
|
1582
|
-
sh = Math.min(sh, fullBitmap.height - sy);
|
|
1583
|
-
if (sw <= 0 || sh <= 0) {
|
|
1584
|
-
throw new Error("renderRegion: rect is outside the page bounds");
|
|
1585
|
-
}
|
|
1586
|
-
const regionBitmap = await createImageBitmap(fullBitmap, sx, sy, sw, sh);
|
|
1587
|
-
return this.convertBitmapToFormat(regionBitmap, format, options);
|
|
1588
|
-
}
|
|
1589
|
-
/**
|
|
1590
|
-
* Internal method to render a page with a specific render type.
|
|
1591
|
-
*/
|
|
1592
|
-
async renderWithType(page, type, options = {}) {
|
|
1593
|
-
this.ensureLoaded();
|
|
1594
|
-
const scale = options.scale ?? 1;
|
|
1595
|
-
const format = options.format ?? "image-data";
|
|
1596
|
-
const force = options.force ?? false;
|
|
1597
|
-
const boost = options.boost ?? false;
|
|
1598
|
-
const renderRequest = {
|
|
1599
|
-
docId: this.documentId,
|
|
1600
|
-
page: page + 1, // Uses 1-based page numbers
|
|
1601
|
-
type,
|
|
1602
|
-
scale,
|
|
1603
|
-
};
|
|
1604
|
-
let result;
|
|
1605
|
-
if (force) {
|
|
1606
|
-
// Bypass cache and queue, call worker directly
|
|
1607
|
-
result = await this.workerClient.forceRender(renderRequest);
|
|
1608
|
-
}
|
|
1609
|
-
else {
|
|
1610
|
-
// Boost priority if requested (before queueing the render)
|
|
1611
|
-
if (boost) {
|
|
1612
|
-
if (type === "page") {
|
|
1613
|
-
this.workerClient.boostPageRenderPriority(this.documentId, page + 1);
|
|
1614
|
-
}
|
|
1615
|
-
else {
|
|
1616
|
-
this.workerClient.boostThumbnailRenderPriority(this.documentId, page + 1);
|
|
1617
|
-
}
|
|
1618
|
-
}
|
|
1619
|
-
// Request render through WorkerClient
|
|
1620
|
-
// Performance tracking is handled by WorkerClient.doRender()
|
|
1621
|
-
result = await this.workerClient.requestRender(renderRequest);
|
|
1622
|
-
}
|
|
1623
|
-
// Convert ImageBitmap to the requested format
|
|
1624
|
-
return this.convertBitmapToFormat(result.bitmap, format, options);
|
|
1625
|
-
}
|
|
1626
|
-
/**
|
|
1627
|
-
* Convert an ImageBitmap to the requested output format.
|
|
1628
|
-
*/
|
|
1629
|
-
async convertBitmapToFormat(bitmap, format, options) {
|
|
1630
|
-
if (format === "image-bitmap") {
|
|
1631
|
-
return bitmap;
|
|
1632
|
-
}
|
|
1633
|
-
const canvas = document.createElement("canvas");
|
|
1634
|
-
canvas.width = bitmap.width;
|
|
1635
|
-
canvas.height = bitmap.height;
|
|
1636
|
-
const ctx = canvas.getContext("2d");
|
|
1637
|
-
ctx.drawImage(bitmap, 0, 0);
|
|
1638
|
-
if (format === "image-data") {
|
|
1639
|
-
return ctx.getImageData(0, 0, bitmap.width, bitmap.height);
|
|
1640
|
-
}
|
|
1641
|
-
const imageType = options.imageType ?? "image/png";
|
|
1642
|
-
const quality = options.quality ?? 0.92;
|
|
1643
|
-
if (format === "blob") {
|
|
1644
|
-
return new Promise((resolve, reject) => {
|
|
1645
|
-
canvas.toBlob((blob) => {
|
|
1646
|
-
if (blob)
|
|
1647
|
-
resolve(blob);
|
|
1648
|
-
else
|
|
1649
|
-
reject(new Error("Failed to create blob"));
|
|
1650
|
-
}, imageType, quality);
|
|
1651
|
-
});
|
|
1652
|
-
}
|
|
1653
|
-
// data-url
|
|
1654
|
-
return canvas.toDataURL(imageType, quality);
|
|
1655
|
-
}
|
|
1656
|
-
// ===========================================================================
|
|
1657
|
-
// Export
|
|
1658
|
-
// ===========================================================================
|
|
1659
|
-
/**
|
|
1660
|
-
* Export document as bytes.
|
|
1661
|
-
* If annotations have been edited, saves them into the PDF before returning.
|
|
1662
|
-
*/
|
|
1663
|
-
async toBytes() {
|
|
1664
|
-
this.ensureLoaded();
|
|
1665
|
-
// If there are dirty annotation pages, save them into the PDF first.
|
|
1666
|
-
// Ephemeral annotations are excluded — they're viewer-only and never persist.
|
|
1667
|
-
const state = this.uiShell?.store.getState();
|
|
1668
|
-
if (state && state.annotationsDirtyPages.size > 0 && this.currentFormat === "pdf") {
|
|
1669
|
-
const annotationsByPage = {};
|
|
1670
|
-
for (const [pageIndex, annotations] of state.pageAnnotations) {
|
|
1671
|
-
const persistable = annotations.filter((a) => !a.ephemeral);
|
|
1672
|
-
annotationsByPage[String(pageIndex)] = persistable;
|
|
1673
|
-
}
|
|
1674
|
-
return this.workerClient.pdfSaveAnnotations(this.documentId, annotationsByPage);
|
|
1675
|
-
}
|
|
1676
|
-
return this.workerClient.getBytes(this.documentId);
|
|
1677
|
-
}
|
|
1678
|
-
/**
|
|
1679
|
-
* Download document to user's device.
|
|
1680
|
-
* @param filename - Filename for download (defaults to original source filename)
|
|
1681
|
-
*/
|
|
1682
|
-
async download(filename) {
|
|
1683
|
-
const bytes = await this.toBytes();
|
|
1684
|
-
const mimeType = this.getMimeType();
|
|
1685
|
-
const blob = new Blob([bytes.buffer], { type: mimeType });
|
|
1686
|
-
const url = URL.createObjectURL(blob);
|
|
1687
|
-
const resolvedFilename = filename ?? this.getDefaultFilename();
|
|
1688
|
-
const a = document.createElement("a");
|
|
1689
|
-
a.href = url;
|
|
1690
|
-
a.download = resolvedFilename;
|
|
1691
|
-
a.click();
|
|
1692
|
-
URL.revokeObjectURL(url);
|
|
1693
|
-
this.emit("download", { filename: resolvedFilename });
|
|
1694
|
-
}
|
|
1695
|
-
/**
|
|
1696
|
-
* Print the document.
|
|
1697
|
-
* Shows the print dialog when called without options (from public API).
|
|
1698
|
-
* When called with options (from the dialog), renders selected pages and opens the browser print dialog.
|
|
1699
|
-
*/
|
|
1700
|
-
async print(options) {
|
|
1701
|
-
this.ensureLoaded();
|
|
1702
|
-
// If no options provided, show the print dialog
|
|
1703
|
-
if (!options) {
|
|
1704
|
-
this.uiShell?.dispatch({ type: "SHOW_PRINT_DIALOG" });
|
|
1705
|
-
return;
|
|
1706
|
-
}
|
|
1707
|
-
const pageIndices = this.resolvePageIndices(options.pageRange);
|
|
1708
|
-
const isAllPages = pageIndices.length === this._pageCount;
|
|
1709
|
-
this.emit("print", { pageCount: pageIndices.length });
|
|
1710
|
-
// For PDF with all pages and standard quality, use native PDF printing (vector quality)
|
|
1711
|
-
if (this.currentFormat === "pdf" && isAllPages && options.quality === "standard") {
|
|
1712
|
-
await this.printPdfNative();
|
|
1713
|
-
}
|
|
1714
|
-
else {
|
|
1715
|
-
await this.printRendered(pageIndices, options.quality);
|
|
1716
|
-
}
|
|
1717
|
-
}
|
|
1718
|
-
/**
|
|
1719
|
-
* Resolve a PrintPageRange into an array of 0-based page indices.
|
|
1720
|
-
* @internal
|
|
1721
|
-
*/
|
|
1722
|
-
resolvePageIndices(range) {
|
|
1723
|
-
switch (range.kind) {
|
|
1724
|
-
case "all":
|
|
1725
|
-
return Array.from({ length: this._pageCount }, (_, i) => i);
|
|
1726
|
-
case "current":
|
|
1727
|
-
return [this.currentPage - 1];
|
|
1728
|
-
case "fromTo": {
|
|
1729
|
-
const indices = [];
|
|
1730
|
-
for (let i = range.from - 1; i < range.to; i++)
|
|
1731
|
-
indices.push(i);
|
|
1732
|
-
return indices;
|
|
1733
|
-
}
|
|
1734
|
-
case "custom":
|
|
1735
|
-
return range.pages.map((p) => p - 1);
|
|
1736
|
-
}
|
|
1737
|
-
}
|
|
1738
|
-
/**
|
|
1739
|
-
* Print PDF by loading original bytes into an iframe — vector quality, no rendering needed.
|
|
1740
|
-
* @internal
|
|
1741
|
-
*/
|
|
1742
|
-
async printPdfNative() {
|
|
1743
|
-
const bytes = await this.toBytes();
|
|
1744
|
-
const blob = new Blob([bytes.buffer], { type: "application/pdf" });
|
|
1745
|
-
const blobUrl = URL.createObjectURL(blob);
|
|
1746
|
-
const title = this.getDefaultFilename().replace(/\.[^.]+$/, "");
|
|
1747
|
-
const iframe = document.createElement("iframe");
|
|
1748
|
-
iframe.style.position = "fixed";
|
|
1749
|
-
iframe.style.left = "-9999px";
|
|
1750
|
-
iframe.style.top = "-9999px";
|
|
1751
|
-
iframe.style.width = "0";
|
|
1752
|
-
iframe.style.height = "0";
|
|
1753
|
-
document.body.appendChild(iframe);
|
|
1754
|
-
iframe.src = blobUrl;
|
|
1755
|
-
// Wait for the PDF to load in the iframe
|
|
1756
|
-
await new Promise((resolve) => {
|
|
1757
|
-
iframe.onload = () => resolve();
|
|
1758
|
-
});
|
|
1759
|
-
const originalTitle = document.title;
|
|
1760
|
-
document.title = title;
|
|
1761
|
-
iframe.contentWindow?.print();
|
|
1762
|
-
setTimeout(() => {
|
|
1763
|
-
document.title = originalTitle;
|
|
1764
|
-
URL.revokeObjectURL(blobUrl);
|
|
1765
|
-
iframe.remove();
|
|
1766
|
-
}, 1000);
|
|
1767
|
-
}
|
|
1768
|
-
/** Map quality preset to DPI scale factor. */
|
|
1769
|
-
static qualityToDpiScale(quality) {
|
|
1770
|
-
switch (quality) {
|
|
1771
|
-
case "draft":
|
|
1772
|
-
return 150 / 72;
|
|
1773
|
-
case "standard":
|
|
1774
|
-
return 300 / 72;
|
|
1775
|
-
case "high":
|
|
1776
|
-
return 600 / 72;
|
|
1777
|
-
}
|
|
1778
|
-
}
|
|
1779
|
-
/**
|
|
1780
|
-
* Print by rendering selected pages to images.
|
|
1781
|
-
* @internal
|
|
1782
|
-
*/
|
|
1783
|
-
async printRendered(pageIndices, quality) {
|
|
1784
|
-
const totalPages = pageIndices.length;
|
|
1785
|
-
// Show progress via store-driven loading overlay
|
|
1786
|
-
this.uiShell?.dispatch({ type: "SET_PRINT_PROGRESS", currentPage: 0, totalPages });
|
|
1787
|
-
const blobUrls = [];
|
|
1788
|
-
try {
|
|
1789
|
-
const scale = UDocViewer.qualityToDpiScale(quality);
|
|
1790
|
-
for (let idx = 0; idx < totalPages; idx++) {
|
|
1791
|
-
const pageIndex = pageIndices[idx];
|
|
1792
|
-
this.uiShell?.dispatch({ type: "SET_PRINT_PROGRESS", currentPage: idx + 1, totalPages });
|
|
1793
|
-
const blob = await this.renderPage(pageIndex, {
|
|
1794
|
-
scale,
|
|
1795
|
-
format: "blob",
|
|
1796
|
-
force: true,
|
|
1797
|
-
});
|
|
1798
|
-
blobUrls.push(URL.createObjectURL(blob));
|
|
1799
|
-
}
|
|
1800
|
-
const firstInfo = this._pageInfo[pageIndices[0]];
|
|
1801
|
-
const pageWidthIn = (firstInfo.width / 72).toFixed(4);
|
|
1802
|
-
const pageHeightIn = (firstInfo.height / 72).toFixed(4);
|
|
1803
|
-
let pagesHtml = "";
|
|
1804
|
-
for (let idx = 0; idx < totalPages; idx++) {
|
|
1805
|
-
const pageIndex = pageIndices[idx];
|
|
1806
|
-
const info = this._pageInfo[pageIndex];
|
|
1807
|
-
const widthIn = (info.width / 72).toFixed(4);
|
|
1808
|
-
const heightIn = (info.height / 72).toFixed(4);
|
|
1809
|
-
// Render annotations at scale=1 (1 PDF point = 1px). The page container
|
|
1810
|
-
// is sized in inches (1in = 96 CSS px), so we scale by 96/72 to convert
|
|
1811
|
-
// PDF points to CSS pixels.
|
|
1812
|
-
const state = this.uiShell?.store.getState();
|
|
1813
|
-
// Exclude ephemeral annotations from print output — they're
|
|
1814
|
-
// viewer-only overlays.
|
|
1815
|
-
const pageAnnotations = state?.pageAnnotations.get(pageIndex)?.filter((a) => !a.ephemeral);
|
|
1816
|
-
let annotationLayer = "";
|
|
1817
|
-
if (pageAnnotations && pageAnnotations.length > 0) {
|
|
1818
|
-
const tempLayer = document.createElement("div");
|
|
1819
|
-
renderAnnotationsToLayer(tempLayer, pageAnnotations, 1);
|
|
1820
|
-
const ptToCss = 96 / 72; // 1.333...
|
|
1821
|
-
annotationLayer =
|
|
1822
|
-
`<div style="position:absolute;top:0;left:0;width:${info.width}px;height:${info.height}px;` +
|
|
1823
|
-
`transform-origin:top left;transform:scale(${ptToCss});` +
|
|
1824
|
-
`pointer-events:none;">${tempLayer.innerHTML}</div>`;
|
|
1825
|
-
}
|
|
1826
|
-
pagesHtml +=
|
|
1827
|
-
`<div class="page" style="position:relative;width:${widthIn}in;height:${heightIn}in;">` +
|
|
1828
|
-
`<img src="${blobUrls[idx]}" style="width:100%;height:100%;">` +
|
|
1829
|
-
annotationLayer +
|
|
1830
|
-
`</div>`;
|
|
1831
|
-
}
|
|
1832
|
-
const title = this.getDefaultFilename().replace(/\.[^.]+$/, "");
|
|
1833
|
-
const html = `<!DOCTYPE html>
|
|
1834
|
-
<html><head><title>${title}</title><style>
|
|
1835
|
-
@page { size: ${pageWidthIn}in ${pageHeightIn}in; margin: 0; }
|
|
1836
|
-
* { margin: 0; padding: 0; }
|
|
1837
|
-
.page { page-break-after: always; overflow: hidden; }
|
|
1838
|
-
.page:last-child { page-break-after: auto; }
|
|
1839
|
-
img { display: block; }
|
|
1840
|
-
</style></head><body>${pagesHtml}</body></html>`;
|
|
1841
|
-
const iframe = document.createElement("iframe");
|
|
1842
|
-
iframe.style.position = "fixed";
|
|
1843
|
-
iframe.style.left = "-9999px";
|
|
1844
|
-
iframe.style.top = "-9999px";
|
|
1845
|
-
iframe.style.width = "0";
|
|
1846
|
-
iframe.style.height = "0";
|
|
1847
|
-
document.body.appendChild(iframe);
|
|
1848
|
-
const iframeDoc = iframe.contentDocument ?? iframe.contentWindow?.document;
|
|
1849
|
-
if (!iframeDoc) {
|
|
1850
|
-
iframe.remove();
|
|
1851
|
-
throw new Error("Failed to create print iframe");
|
|
1852
|
-
}
|
|
1853
|
-
iframeDoc.open();
|
|
1854
|
-
iframeDoc.write(html);
|
|
1855
|
-
iframeDoc.close();
|
|
1856
|
-
const images = iframeDoc.querySelectorAll("img");
|
|
1857
|
-
await Promise.all(Array.from(images).map((img) => new Promise((resolve) => {
|
|
1858
|
-
if (img.complete) {
|
|
1859
|
-
resolve();
|
|
1860
|
-
}
|
|
1861
|
-
else {
|
|
1862
|
-
img.onload = () => resolve();
|
|
1863
|
-
img.onerror = () => resolve();
|
|
1864
|
-
}
|
|
1865
|
-
})));
|
|
1866
|
-
this.uiShell?.dispatch({ type: "CLEAR_PRINT_PROGRESS" });
|
|
1867
|
-
const originalTitle = document.title;
|
|
1868
|
-
document.title = title;
|
|
1869
|
-
iframe.contentWindow?.print();
|
|
1870
|
-
setTimeout(() => {
|
|
1871
|
-
document.title = originalTitle;
|
|
1872
|
-
for (const url of blobUrls)
|
|
1873
|
-
URL.revokeObjectURL(url);
|
|
1874
|
-
iframe.remove();
|
|
1875
|
-
}, 1000);
|
|
1876
|
-
}
|
|
1877
|
-
catch (error) {
|
|
1878
|
-
this.uiShell?.dispatch({ type: "CLEAR_PRINT_PROGRESS" });
|
|
1879
|
-
for (const url of blobUrls)
|
|
1880
|
-
URL.revokeObjectURL(url);
|
|
1881
|
-
throw error;
|
|
1882
|
-
}
|
|
1883
|
-
}
|
|
1884
|
-
/** Returns the MIME type for the current document format. */
|
|
1885
|
-
getMimeType() {
|
|
1886
|
-
switch (this.currentFormat) {
|
|
1887
|
-
case "docx":
|
|
1888
|
-
return "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
|
1889
|
-
case "pptx":
|
|
1890
|
-
return "application/vnd.openxmlformats-officedocument.presentationml.presentation";
|
|
1891
|
-
case "xlsx":
|
|
1892
|
-
return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
1893
|
-
case "csv":
|
|
1894
|
-
return "text/csv";
|
|
1895
|
-
case "image":
|
|
1896
|
-
return "application/octet-stream";
|
|
1897
|
-
case "pdf":
|
|
1898
|
-
default:
|
|
1899
|
-
return "application/pdf";
|
|
1900
|
-
}
|
|
1901
|
-
}
|
|
1902
|
-
/** Returns a default filename based on the source or format. */
|
|
1903
|
-
getDefaultFilename() {
|
|
1904
|
-
if (this.documentDefaultFilename) {
|
|
1905
|
-
return this.documentDefaultFilename;
|
|
1906
|
-
}
|
|
1907
|
-
if (this.sourceFilename) {
|
|
1908
|
-
// Extract filename from URL or File.name
|
|
1909
|
-
try {
|
|
1910
|
-
const url = new URL(this.sourceFilename);
|
|
1911
|
-
const path = url.pathname;
|
|
1912
|
-
const name = path.substring(path.lastIndexOf("/") + 1);
|
|
1913
|
-
if (name)
|
|
1914
|
-
return decodeURIComponent(name);
|
|
1915
|
-
}
|
|
1916
|
-
catch {
|
|
1917
|
-
// Not a full URL (e.g. relative path or File.name) — extract filename
|
|
1918
|
-
const lastSlash = this.sourceFilename.lastIndexOf("/");
|
|
1919
|
-
return lastSlash >= 0 ? this.sourceFilename.substring(lastSlash + 1) : this.sourceFilename;
|
|
1920
|
-
}
|
|
1921
|
-
}
|
|
1922
|
-
// Fallback based on format
|
|
1923
|
-
switch (this.currentFormat) {
|
|
1924
|
-
case "docx":
|
|
1925
|
-
return "document.docx";
|
|
1926
|
-
case "pptx":
|
|
1927
|
-
return "document.pptx";
|
|
1928
|
-
case "xlsx":
|
|
1929
|
-
return "document.xlsx";
|
|
1930
|
-
case "csv":
|
|
1931
|
-
return "document.csv";
|
|
1932
|
-
case "image":
|
|
1933
|
-
return "image.png";
|
|
1934
|
-
case "pdf":
|
|
1935
|
-
default:
|
|
1936
|
-
return "document.pdf";
|
|
1937
|
-
}
|
|
1938
|
-
}
|
|
1939
|
-
// ===========================================================================
|
|
1940
|
-
// Events
|
|
1941
|
-
// ===========================================================================
|
|
1942
|
-
/**
|
|
1943
|
-
* Subscribe to an event.
|
|
1944
|
-
* @returns Unsubscribe function
|
|
1945
|
-
*/
|
|
1946
|
-
on(event, handler) {
|
|
1947
|
-
if (!this.eventHandlers.has(event)) {
|
|
1948
|
-
this.eventHandlers.set(event, new Set());
|
|
1949
|
-
}
|
|
1950
|
-
this.eventHandlers.get(event).add(handler);
|
|
1951
|
-
return () => this.off(event, handler);
|
|
1952
|
-
}
|
|
1953
|
-
/**
|
|
1954
|
-
* Unsubscribe from an event.
|
|
1955
|
-
*/
|
|
1956
|
-
off(event, handler) {
|
|
1957
|
-
this.eventHandlers.get(event)?.delete(handler);
|
|
1958
|
-
}
|
|
1959
|
-
// ===========================================================================
|
|
1960
|
-
// Lifecycle
|
|
1961
|
-
// ===========================================================================
|
|
1962
|
-
/**
|
|
1963
|
-
* Destroy the viewer and release resources.
|
|
1964
|
-
*/
|
|
1965
|
-
destroy() {
|
|
1966
|
-
if (this.destroyed)
|
|
1967
|
-
return;
|
|
1968
|
-
this.destroyed = true;
|
|
1969
|
-
if (this.storeUnsub) {
|
|
1970
|
-
this.storeUnsub();
|
|
1971
|
-
this.storeUnsub = null;
|
|
1972
|
-
}
|
|
1973
|
-
if (this.actionUnsub) {
|
|
1974
|
-
this.actionUnsub();
|
|
1975
|
-
this.actionUnsub = null;
|
|
1976
|
-
}
|
|
1977
|
-
if (this.fontUsageUnsub) {
|
|
1978
|
-
this.fontUsageUnsub();
|
|
1979
|
-
this.fontUsageUnsub = null;
|
|
1980
|
-
}
|
|
1981
|
-
if (this.uiShell) {
|
|
1982
|
-
this.uiShell.destroy();
|
|
1983
|
-
this.uiShell = null;
|
|
1984
|
-
}
|
|
1985
|
-
this.close();
|
|
1986
|
-
this.eventHandlers.clear();
|
|
1987
|
-
}
|
|
1988
|
-
// ===========================================================================
|
|
1989
|
-
// Internal Helpers
|
|
1990
|
-
// ===========================================================================
|
|
1991
|
-
/**
|
|
1992
|
-
* Get the document ID (for internal use).
|
|
1993
|
-
* @internal
|
|
1994
|
-
*/
|
|
1995
|
-
getDocumentId() {
|
|
1996
|
-
return this.documentId;
|
|
1997
|
-
}
|
|
1998
|
-
/**
|
|
1999
|
-
* Initialize the viewer with an already-loaded document ID.
|
|
2000
|
-
* Used by UDocClient.compose() to create viewers for composed documents.
|
|
2001
|
-
* @internal
|
|
2002
|
-
*/
|
|
2003
|
-
async initializeFromDocId(docId) {
|
|
2004
|
-
this.ensureNotDestroyed();
|
|
2005
|
-
if (this.documentId) {
|
|
2006
|
-
this.close();
|
|
2007
|
-
}
|
|
2008
|
-
this.documentId = docId;
|
|
2009
|
-
// Load all page info upfront (fast operation)
|
|
2010
|
-
this._pageInfo = await this.workerClient.getAllPageInfo(docId);
|
|
2011
|
-
this._pageCount = this._pageInfo.length;
|
|
2012
|
-
const format = (await this.workerClient.getDocumentFormat(docId));
|
|
2013
|
-
this.currentFormat = format;
|
|
2014
|
-
const pageGroups = await this.workerClient.getPageGroups(docId);
|
|
2015
|
-
if (this.uiShell) {
|
|
2016
|
-
this.uiShell.dispatch({
|
|
2017
|
-
type: "SET_DOC",
|
|
2018
|
-
doc: { id: docId },
|
|
2019
|
-
documentFormat: format,
|
|
2020
|
-
pageCount: this._pageCount,
|
|
2021
|
-
pageInfos: this._pageInfo,
|
|
2022
|
-
pageGroups,
|
|
2023
|
-
});
|
|
2024
|
-
}
|
|
2025
|
-
this.emit("document:load", { pageCount: this._pageCount });
|
|
2026
|
-
}
|
|
2027
|
-
resolveContainer(container) {
|
|
2028
|
-
if (typeof container === "string") {
|
|
2029
|
-
const element = document.querySelector(container);
|
|
2030
|
-
if (!element) {
|
|
2031
|
-
throw new Error(`Container not found: ${container}`);
|
|
2032
|
-
}
|
|
2033
|
-
return element;
|
|
2034
|
-
}
|
|
2035
|
-
return container;
|
|
2036
|
-
}
|
|
2037
|
-
async resolveSourceWithFilename(source) {
|
|
2038
|
-
if (source instanceof Uint8Array) {
|
|
2039
|
-
return { bytes: source };
|
|
2040
|
-
}
|
|
2041
|
-
if (source instanceof File) {
|
|
2042
|
-
const buffer = await source.arrayBuffer();
|
|
2043
|
-
return { bytes: new Uint8Array(buffer), filename: source.name, mimeType: source.type || undefined };
|
|
2044
|
-
}
|
|
2045
|
-
// URL string - use streaming to report progress
|
|
2046
|
-
const { bytes, headers } = await this.fetchWithProgress(source);
|
|
2047
|
-
return {
|
|
2048
|
-
bytes,
|
|
2049
|
-
filename: source,
|
|
2050
|
-
mimeType: headers.get("Content-Type") ?? undefined,
|
|
2051
|
-
// Cross-origin responses expose this only when the server lists it
|
|
2052
|
-
// in Access-Control-Expose-Headers; otherwise it reads as null.
|
|
2053
|
-
dispositionFilename: filenameFromContentDisposition(headers.get("Content-Disposition")),
|
|
2054
|
-
};
|
|
2055
|
-
}
|
|
2056
|
-
async fetchWithProgress(url) {
|
|
2057
|
-
// Show progress bar immediately before sending the request
|
|
2058
|
-
if (this.uiShell) {
|
|
2059
|
-
this.uiShell.dispatch({
|
|
2060
|
-
type: "SET_DOWNLOAD_PROGRESS",
|
|
2061
|
-
loaded: 0,
|
|
2062
|
-
total: 0,
|
|
2063
|
-
});
|
|
2064
|
-
}
|
|
2065
|
-
this.emit("document:loading", { loaded: 0, total: 0, percent: null });
|
|
2066
|
-
const response = await fetch(url);
|
|
2067
|
-
if (!response.ok) {
|
|
2068
|
-
throw new Error(`Failed to fetch document: ${response.statusText}`);
|
|
2069
|
-
}
|
|
2070
|
-
const contentLength = response.headers.get("Content-Length");
|
|
2071
|
-
const total = contentLength ? parseInt(contentLength, 10) : 0;
|
|
2072
|
-
// If no body or no streaming support, fall back to simple approach
|
|
2073
|
-
if (!response.body) {
|
|
2074
|
-
const buffer = await response.arrayBuffer();
|
|
2075
|
-
// Clear download progress from UI
|
|
2076
|
-
if (this.uiShell) {
|
|
2077
|
-
this.uiShell.dispatch({ type: "CLEAR_DOWNLOAD_PROGRESS" });
|
|
2078
|
-
}
|
|
2079
|
-
return { bytes: new Uint8Array(buffer), headers: response.headers };
|
|
2080
|
-
}
|
|
2081
|
-
const reader = response.body.getReader();
|
|
2082
|
-
const chunks = [];
|
|
2083
|
-
let loaded = 0;
|
|
2084
|
-
// Helper to report progress to both event listeners and UI shell
|
|
2085
|
-
const reportProgress = (currentLoaded) => {
|
|
2086
|
-
const progress = {
|
|
2087
|
-
loaded: currentLoaded,
|
|
2088
|
-
total,
|
|
2089
|
-
percent: total > 0 ? Math.round((currentLoaded / total) * 100) : null,
|
|
2090
|
-
};
|
|
2091
|
-
this.emit("document:loading", progress);
|
|
2092
|
-
// Dispatch to UI shell for the loading overlay
|
|
2093
|
-
if (this.uiShell) {
|
|
2094
|
-
this.uiShell.dispatch({
|
|
2095
|
-
type: "SET_DOWNLOAD_PROGRESS",
|
|
2096
|
-
loaded: currentLoaded,
|
|
2097
|
-
total,
|
|
2098
|
-
});
|
|
2099
|
-
}
|
|
2100
|
-
};
|
|
2101
|
-
// Report initial progress with known total (transitions from indeterminate to 0%)
|
|
2102
|
-
reportProgress(0);
|
|
2103
|
-
while (true) {
|
|
2104
|
-
const { done, value } = await reader.read();
|
|
2105
|
-
if (done)
|
|
2106
|
-
break;
|
|
2107
|
-
chunks.push(value);
|
|
2108
|
-
loaded += value.length;
|
|
2109
|
-
reportProgress(loaded);
|
|
2110
|
-
}
|
|
2111
|
-
// Clear download progress from UI
|
|
2112
|
-
if (this.uiShell) {
|
|
2113
|
-
this.uiShell.dispatch({ type: "CLEAR_DOWNLOAD_PROGRESS" });
|
|
2114
|
-
}
|
|
2115
|
-
// Combine chunks into single array
|
|
2116
|
-
const result = new Uint8Array(loaded);
|
|
2117
|
-
let offset = 0;
|
|
2118
|
-
for (const chunk of chunks) {
|
|
2119
|
-
result.set(chunk, offset);
|
|
2120
|
-
offset += chunk.length;
|
|
2121
|
-
}
|
|
2122
|
-
return { bytes: result, headers: response.headers };
|
|
2123
|
-
}
|
|
2124
|
-
emit(event, payload) {
|
|
2125
|
-
const handlers = this.eventHandlers.get(event);
|
|
2126
|
-
if (handlers) {
|
|
2127
|
-
for (const handler of handlers) {
|
|
2128
|
-
try {
|
|
2129
|
-
handler(payload);
|
|
2130
|
-
}
|
|
2131
|
-
catch (error) {
|
|
2132
|
-
console.error(`Error in event handler for ${event}:`, error);
|
|
2133
|
-
}
|
|
2134
|
-
}
|
|
2135
|
-
}
|
|
2136
|
-
}
|
|
2137
|
-
createEngineAdapter() {
|
|
2138
|
-
return {
|
|
2139
|
-
getPageInfo: async (_doc, page) => {
|
|
2140
|
-
const pageIndex = Math.max(0, page - 1);
|
|
2141
|
-
return this._pageInfo[pageIndex] ?? { width: 0, height: 0 };
|
|
2142
|
-
},
|
|
2143
|
-
getOutline: async (doc) => {
|
|
2144
|
-
const raw = await this.workerClient.getOutline(doc.id);
|
|
2145
|
-
return raw;
|
|
2146
|
-
},
|
|
2147
|
-
getPageAnnotations: async (doc, pageIndex) => {
|
|
2148
|
-
const raw = await this.workerClient.getPageAnnotations(doc.id, pageIndex);
|
|
2149
|
-
return raw;
|
|
2150
|
-
},
|
|
2151
|
-
getLayoutPage: async (doc, pageIndex) => {
|
|
2152
|
-
return (await this.workerClient.getLayoutPage(doc.id, pageIndex));
|
|
2153
|
-
},
|
|
2154
|
-
getVisibilityGroups: async (doc) => {
|
|
2155
|
-
const raw = await this.workerClient.getVisibilityGroups(doc.id);
|
|
2156
|
-
return raw;
|
|
2157
|
-
},
|
|
2158
|
-
setVisibilityGroupVisible: async (doc, groupId, visible) => {
|
|
2159
|
-
return await this.workerClient.setVisibilityGroupVisible(doc.id, groupId, visible);
|
|
2160
|
-
},
|
|
2161
|
-
};
|
|
2162
|
-
}
|
|
2163
|
-
ensureNotDestroyed() {
|
|
2164
|
-
if (this.destroyed) {
|
|
2165
|
-
throw new Error("UDocViewer has been destroyed");
|
|
2166
|
-
}
|
|
2167
|
-
}
|
|
2168
|
-
ensureLoaded() {
|
|
2169
|
-
this.ensureNotDestroyed();
|
|
2170
|
-
if (!this.documentId) {
|
|
2171
|
-
throw new Error("No document loaded");
|
|
2172
|
-
}
|
|
2173
|
-
}
|
|
2174
|
-
ensureUiMode() {
|
|
2175
|
-
if (!this.uiShell) {
|
|
2176
|
-
throw new Error("This method requires UI mode (container must be provided)");
|
|
2177
|
-
}
|
|
2178
|
-
}
|
|
2179
|
-
}
|
|
2180
|
-
//# sourceMappingURL=UDocViewer.js.map
|