@docmentis/udoc-viewer 0.7.20 → 0.8.1
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
|
@@ -1,1383 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Low-level client for communicating with the UDoc worker.
|
|
3
|
-
*
|
|
4
|
-
* Provides a Promise-based API for document operations.
|
|
5
|
-
* Also handles render queue, cache, and priority management.
|
|
6
|
-
* This is an internal API - use UDocClient for the public SDK.
|
|
7
|
-
*/
|
|
8
|
-
import { WORKER_INLINE } from "./worker-inline.js";
|
|
9
|
-
function makeWorkKey(item) {
|
|
10
|
-
if (item.kind === "render") {
|
|
11
|
-
return `render:${makeRenderKey(item.docId, item.page, item.type, item.scale)}`;
|
|
12
|
-
}
|
|
13
|
-
if (item.kind === "fontUsageCheck") {
|
|
14
|
-
return `fontUsageCheck:${item.docId}`;
|
|
15
|
-
}
|
|
16
|
-
return `${item.kind}:${item.docId}:${item.page}`;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Generate a cache key for render requests.
|
|
20
|
-
* Uses toFixed(4) for scale to normalize floating-point variations.
|
|
21
|
-
* Exported so Spread component can use the same key format.
|
|
22
|
-
*/
|
|
23
|
-
export function makeRenderKey(docId, page, type, scale) {
|
|
24
|
-
return `${docId}:${page}:${type}:${scale.toFixed(4)}`;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Heuristic detection of allocation/OOM-style errors, covering:
|
|
28
|
-
* - JS-side: `RangeError: Array buffer allocation failed`, ImageBitmap OOM.
|
|
29
|
-
* - WASM-side: Rust allocator aborts surface as `RuntimeError`/"memory access out of bounds"
|
|
30
|
-
* or "unreachable executed" after a failed `memory.grow`.
|
|
31
|
-
*/
|
|
32
|
-
function isOOMError(err) {
|
|
33
|
-
if (!err)
|
|
34
|
-
return false;
|
|
35
|
-
if (err instanceof RangeError)
|
|
36
|
-
return true;
|
|
37
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
38
|
-
return /out of memory|allocation failed|memory access out of bounds|unreachable executed|RuntimeError/i.test(msg);
|
|
39
|
-
}
|
|
40
|
-
export class WorkerClient {
|
|
41
|
-
worker;
|
|
42
|
-
requestId = 0;
|
|
43
|
-
pending = new Map();
|
|
44
|
-
// Render management state - separate caches for page, thumbnail, and preview; single queue
|
|
45
|
-
pageRenderCache = new Map();
|
|
46
|
-
thumbnailRenderCache = new Map();
|
|
47
|
-
previewRenderCache = new Map();
|
|
48
|
-
workQueue = [];
|
|
49
|
-
currentWork = null;
|
|
50
|
-
// Page bitmaps grow with zoom and DPR (a single 4096² bitmap is 64 MB), so
|
|
51
|
-
// the page cache is sized by bytes rather than entry count. Thumbnail and
|
|
52
|
-
// preview bitmaps are small, so they stay count-based.
|
|
53
|
-
maxPageCacheBytes = 256 * 1024 * 1024;
|
|
54
|
-
maxThumbnailCacheSize = 500;
|
|
55
|
-
maxPreviewCacheSize = 50;
|
|
56
|
-
// Separate focus tracking for page and thumbnail boost
|
|
57
|
-
pageFocus = null;
|
|
58
|
-
thumbnailFocus = null;
|
|
59
|
-
// Callbacks notified when render cache is invalidated
|
|
60
|
-
renderInvalidatedCallbacks = new Set();
|
|
61
|
-
// Callbacks notified when an OOM error is detected during render
|
|
62
|
-
oomCallbacks = new Set();
|
|
63
|
-
lastOOMClearAt = 0;
|
|
64
|
-
// Font usage change detection
|
|
65
|
-
fontUsageChangedCallbacks = new Set();
|
|
66
|
-
lastFontUsageLength = new Map();
|
|
67
|
-
// Performance counter per document (for tracking operations)
|
|
68
|
-
performanceCounters = new Map();
|
|
69
|
-
// Page info cache per document (populated by getAllPageInfo, used by getPageInfo)
|
|
70
|
-
pageInfoCache = new Map();
|
|
71
|
-
// Page group cache per document (populated by getPageGroups)
|
|
72
|
-
pageGroupsCache = new Map();
|
|
73
|
-
constructor(worker) {
|
|
74
|
-
this.worker = worker;
|
|
75
|
-
this.worker.onmessage = this.handleMessage.bind(this);
|
|
76
|
-
this.worker.onerror = this.handleError.bind(this);
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Create a WorkerClient using the inline bundled worker.
|
|
80
|
-
* Creates a blob worker from the build-time inlined source code,
|
|
81
|
-
* avoiding "about:blank" for universal bundler compatibility.
|
|
82
|
-
*
|
|
83
|
-
* Falls back to module worker via "about:blank" when WORKER_INLINE
|
|
84
|
-
* is empty (e.g. running from TypeScript source in Vite dev mode).
|
|
85
|
-
*/
|
|
86
|
-
static create() {
|
|
87
|
-
if (WORKER_INLINE) {
|
|
88
|
-
const blob = new Blob([WORKER_INLINE], { type: "text/javascript" });
|
|
89
|
-
const url = URL.createObjectURL(blob);
|
|
90
|
-
const worker = new Worker(url);
|
|
91
|
-
return new WorkerClient(worker);
|
|
92
|
-
}
|
|
93
|
-
// Dev mode fallback: Vite/bundlers can resolve the worker from source
|
|
94
|
-
const worker = new Worker(new URL("./worker.js", "about:blank"), { type: "module" });
|
|
95
|
-
return new WorkerClient(worker);
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Create a WorkerClient with a custom worker URL.
|
|
99
|
-
* Use this when hosting worker files at a custom location.
|
|
100
|
-
*/
|
|
101
|
-
static createWithUrl(workerUrl) {
|
|
102
|
-
const worker = new Worker(workerUrl, { type: "module" });
|
|
103
|
-
return new WorkerClient(worker);
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Initialize the WASM module.
|
|
107
|
-
*/
|
|
108
|
-
async init(wasmUrl, gpu, domain, viewerVersion) {
|
|
109
|
-
await this.send({ type: "init", wasmUrl, gpu, domain, viewerVersion });
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Set the anonymous distinct ID for telemetry tracking.
|
|
113
|
-
*/
|
|
114
|
-
async setupTelemetry(distinctId) {
|
|
115
|
-
await this.send({ type: "setupTelemetry", distinctId });
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Disable telemetry reporting. Requires a license with the "no_telemetry" feature.
|
|
119
|
-
* @returns true if telemetry was disabled, false if the license does not permit it.
|
|
120
|
-
*/
|
|
121
|
-
async disableTelemetry() {
|
|
122
|
-
const response = (await this.send({ type: "disableTelemetry" }));
|
|
123
|
-
return response.disabled;
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Set the license key.
|
|
127
|
-
* @param license - The license key string
|
|
128
|
-
* @param domain - The current domain (from window.location.hostname)
|
|
129
|
-
* @returns License validation result
|
|
130
|
-
*/
|
|
131
|
-
async setLicense(license, domain) {
|
|
132
|
-
const response = (await this.send({ type: "setLicense", license, domain }));
|
|
133
|
-
return response.result;
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Get current license status.
|
|
137
|
-
*/
|
|
138
|
-
async getLicenseStatus() {
|
|
139
|
-
const response = (await this.send({ type: "getLicenseStatus" }));
|
|
140
|
-
return response.result;
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Load a PDF document.
|
|
144
|
-
* @returns The document ID.
|
|
145
|
-
*/
|
|
146
|
-
/**
|
|
147
|
-
* Load a document, optionally with an explicit format hint.
|
|
148
|
-
* When `format` is omitted, the WASM engine inspects the file contents to
|
|
149
|
-
* determine the format. An explicit `format` is authoritative and is
|
|
150
|
-
* required for formats without magic bytes (e.g. CSV).
|
|
151
|
-
* @returns The document ID.
|
|
152
|
-
*/
|
|
153
|
-
async loadDocument(bytes, format) {
|
|
154
|
-
const response = (await this.send({
|
|
155
|
-
type: "load",
|
|
156
|
-
id: "",
|
|
157
|
-
bytes,
|
|
158
|
-
format,
|
|
159
|
-
}));
|
|
160
|
-
return response.documentId;
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Get the detected format of a loaded document.
|
|
164
|
-
* @returns The format string: "pdf", "docx", "pptx", "xlsx", "csv", or "image".
|
|
165
|
-
*/
|
|
166
|
-
async getDocumentFormat(documentId) {
|
|
167
|
-
const response = (await this.send({
|
|
168
|
-
type: "getDocumentFormat",
|
|
169
|
-
documentId,
|
|
170
|
-
}));
|
|
171
|
-
return response.format;
|
|
172
|
-
}
|
|
173
|
-
async loadPdf(bytes) {
|
|
174
|
-
const response = (await this.send({
|
|
175
|
-
type: "loadPdf",
|
|
176
|
-
id: "", // Not used, will be assigned by worker
|
|
177
|
-
bytes,
|
|
178
|
-
}));
|
|
179
|
-
return response.documentId;
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Load an image file.
|
|
183
|
-
* Supports various formats: JPEG, PNG, GIF, BMP, TIFF, WebP, etc.
|
|
184
|
-
* Multi-page TIFF files will create a document with multiple pages.
|
|
185
|
-
* @returns The document ID.
|
|
186
|
-
*/
|
|
187
|
-
async loadImage(bytes) {
|
|
188
|
-
const response = (await this.send({
|
|
189
|
-
type: "loadImage",
|
|
190
|
-
id: "", // Not used, will be assigned by worker
|
|
191
|
-
bytes,
|
|
192
|
-
}));
|
|
193
|
-
return response.documentId;
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* Load a PPTX (PowerPoint) document.
|
|
197
|
-
* @returns The document ID.
|
|
198
|
-
*/
|
|
199
|
-
async loadPptx(bytes) {
|
|
200
|
-
const response = (await this.send({
|
|
201
|
-
type: "loadPptx",
|
|
202
|
-
id: "", // Not used, will be assigned by worker
|
|
203
|
-
bytes,
|
|
204
|
-
}));
|
|
205
|
-
return response.documentId;
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Load a DOCX (Word) document.
|
|
209
|
-
* @returns The document ID.
|
|
210
|
-
*/
|
|
211
|
-
async loadDocx(bytes) {
|
|
212
|
-
const response = (await this.send({
|
|
213
|
-
type: "loadDocx",
|
|
214
|
-
id: "", // Not used, will be assigned by worker
|
|
215
|
-
bytes,
|
|
216
|
-
}));
|
|
217
|
-
return response.documentId;
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Unload a PDF document.
|
|
221
|
-
* @returns True if the document was removed.
|
|
222
|
-
*/
|
|
223
|
-
async unloadPdf(documentId) {
|
|
224
|
-
this.pageInfoCache.delete(documentId);
|
|
225
|
-
this.pageGroupsCache.delete(documentId);
|
|
226
|
-
this.performanceCounters.delete(documentId);
|
|
227
|
-
this.cancelRenders(documentId);
|
|
228
|
-
const response = (await this.send({ type: "unloadPdf", documentId }));
|
|
229
|
-
return response.removed;
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* Check if a document requires a password to open.
|
|
233
|
-
* @returns True if the document needs authentication.
|
|
234
|
-
*/
|
|
235
|
-
async needsPassword(documentId) {
|
|
236
|
-
const response = (await this.send({ type: "needsPassword", documentId }));
|
|
237
|
-
return response.needsPassword;
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* Authenticate with a password to unlock an encrypted document.
|
|
241
|
-
* @param documentId - The document ID
|
|
242
|
-
* @param password - The password to try
|
|
243
|
-
* @returns True if authentication succeeded, false if the password was incorrect.
|
|
244
|
-
*/
|
|
245
|
-
async authenticate(documentId, password) {
|
|
246
|
-
const response = (await this.send({ type: "authenticate", documentId, password }));
|
|
247
|
-
return response.authenticated;
|
|
248
|
-
}
|
|
249
|
-
/**
|
|
250
|
-
* Get the page count of a document.
|
|
251
|
-
* Returns from cache if available.
|
|
252
|
-
*/
|
|
253
|
-
async getPageCount(documentId) {
|
|
254
|
-
// Check cache first
|
|
255
|
-
const cached = this.pageInfoCache.get(documentId);
|
|
256
|
-
if (cached) {
|
|
257
|
-
return cached.length;
|
|
258
|
-
}
|
|
259
|
-
// Fall back to worker call
|
|
260
|
-
const counter = this.getCounter(documentId);
|
|
261
|
-
const eventId = counter?.markStart("getPageCount");
|
|
262
|
-
try {
|
|
263
|
-
const response = (await this.send({ type: "getPageCount", documentId }));
|
|
264
|
-
if (eventId)
|
|
265
|
-
counter?.markEnd(eventId);
|
|
266
|
-
return response.pageCount;
|
|
267
|
-
}
|
|
268
|
-
catch (error) {
|
|
269
|
-
if (eventId)
|
|
270
|
-
counter?.markEnd(eventId, false, error.message);
|
|
271
|
-
throw error;
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
/**
|
|
275
|
-
* Get info for a single page.
|
|
276
|
-
* Returns from cache if available (populated by getAllPageInfo).
|
|
277
|
-
*/
|
|
278
|
-
async getPageInfo(documentId, pageIndex) {
|
|
279
|
-
// Check cache first
|
|
280
|
-
const cached = this.pageInfoCache.get(documentId);
|
|
281
|
-
if (cached && pageIndex < cached.length) {
|
|
282
|
-
return cached[pageIndex];
|
|
283
|
-
}
|
|
284
|
-
// Fall back to worker call
|
|
285
|
-
const counter = this.getCounter(documentId);
|
|
286
|
-
const eventId = counter?.markStart("getPageInfo", { pageIndex });
|
|
287
|
-
try {
|
|
288
|
-
const response = (await this.send({ type: "getPageInfo", documentId, pageIndex }));
|
|
289
|
-
if (eventId)
|
|
290
|
-
counter?.markEnd(eventId);
|
|
291
|
-
return {
|
|
292
|
-
width: response.width,
|
|
293
|
-
height: response.height,
|
|
294
|
-
rotation: response.rotation ?? 0,
|
|
295
|
-
transition: response.transition,
|
|
296
|
-
};
|
|
297
|
-
}
|
|
298
|
-
catch (error) {
|
|
299
|
-
if (eventId)
|
|
300
|
-
counter?.markEnd(eventId, false, error.message);
|
|
301
|
-
throw error;
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
/**
|
|
305
|
-
* Get info for all pages in one call.
|
|
306
|
-
* Results are cached for subsequent calls.
|
|
307
|
-
*/
|
|
308
|
-
async getAllPageInfo(documentId) {
|
|
309
|
-
// Check cache first
|
|
310
|
-
const cached = this.pageInfoCache.get(documentId);
|
|
311
|
-
if (cached) {
|
|
312
|
-
return cached;
|
|
313
|
-
}
|
|
314
|
-
// Fall back to worker call
|
|
315
|
-
const counter = this.getCounter(documentId);
|
|
316
|
-
const eventId = counter?.markStart("getAllPageInfo");
|
|
317
|
-
try {
|
|
318
|
-
const response = (await this.send({ type: "getAllPageInfo", documentId }));
|
|
319
|
-
if (eventId)
|
|
320
|
-
counter?.markEnd(eventId);
|
|
321
|
-
// Cache for subsequent calls
|
|
322
|
-
this.pageInfoCache.set(documentId, response.pages);
|
|
323
|
-
return response.pages;
|
|
324
|
-
}
|
|
325
|
-
catch (error) {
|
|
326
|
-
if (eventId)
|
|
327
|
-
counter?.markEnd(eventId, false, error.message);
|
|
328
|
-
throw error;
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
/**
|
|
332
|
-
* Get stitching groups for a document (one `linear` group for PDF/DOCX/PPTX,
|
|
333
|
-
* one `tiled` group per sheet for XLSX). Results are cached.
|
|
334
|
-
*/
|
|
335
|
-
async getPageGroups(documentId) {
|
|
336
|
-
const cached = this.pageGroupsCache.get(documentId);
|
|
337
|
-
if (cached) {
|
|
338
|
-
return cached;
|
|
339
|
-
}
|
|
340
|
-
const response = (await this.send({ type: "getPageGroups", documentId }));
|
|
341
|
-
this.pageGroupsCache.set(documentId, response.groups);
|
|
342
|
-
return response.groups;
|
|
343
|
-
}
|
|
344
|
-
/**
|
|
345
|
-
* Get the document outline.
|
|
346
|
-
*/
|
|
347
|
-
async getOutline(documentId) {
|
|
348
|
-
const counter = this.getCounter(documentId);
|
|
349
|
-
const eventId = counter?.markStart("getOutline");
|
|
350
|
-
try {
|
|
351
|
-
const response = (await this.send({ type: "getOutline", documentId }));
|
|
352
|
-
if (eventId)
|
|
353
|
-
counter?.markEnd(eventId);
|
|
354
|
-
return response.outline;
|
|
355
|
-
}
|
|
356
|
-
catch (error) {
|
|
357
|
-
if (eventId)
|
|
358
|
-
counter?.markEnd(eventId, false, error.message);
|
|
359
|
-
throw error;
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
/**
|
|
363
|
-
* Get font usage information for a document.
|
|
364
|
-
*/
|
|
365
|
-
async getFontUsage(documentId) {
|
|
366
|
-
const counter = this.getCounter(documentId);
|
|
367
|
-
const eventId = counter?.markStart("getFontUsage");
|
|
368
|
-
try {
|
|
369
|
-
const response = (await this.send({ type: "getFontUsage", documentId }));
|
|
370
|
-
if (eventId)
|
|
371
|
-
counter?.markEnd(eventId);
|
|
372
|
-
return response.entries;
|
|
373
|
-
}
|
|
374
|
-
catch (error) {
|
|
375
|
-
if (eventId)
|
|
376
|
-
counter?.markEnd(eventId, false, error.message);
|
|
377
|
-
throw error;
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
/**
|
|
381
|
-
* Get annotations for a specific page.
|
|
382
|
-
* Routed through the unified work queue so renders take priority.
|
|
383
|
-
*/
|
|
384
|
-
async getPageAnnotations(documentId, pageIndex) {
|
|
385
|
-
return this.requestAnnotations(documentId, pageIndex);
|
|
386
|
-
}
|
|
387
|
-
/**
|
|
388
|
-
* Get the layout model for a specific page (for text selection/search).
|
|
389
|
-
* Routed through the unified work queue so renders take priority.
|
|
390
|
-
*/
|
|
391
|
-
async getLayoutPage(documentId, pageIndex) {
|
|
392
|
-
return this.requestText(documentId, pageIndex);
|
|
393
|
-
}
|
|
394
|
-
/**
|
|
395
|
-
* Get the build sequence of a slide, or `undefined` if it has none.
|
|
396
|
-
*
|
|
397
|
-
* Sent directly rather than through the work queue: the timeline is small
|
|
398
|
-
* metadata and the viewer needs it before it can decide whether the page
|
|
399
|
-
* even requires layered rendering.
|
|
400
|
-
*/
|
|
401
|
-
async getSlideAnimation(documentId, pageIndex) {
|
|
402
|
-
const response = (await this.send({ type: "getSlideAnimation", documentId, pageIndex }));
|
|
403
|
-
return response.animation;
|
|
404
|
-
}
|
|
405
|
-
/**
|
|
406
|
-
* Render a page as independently animatable layers, back-to-front.
|
|
407
|
-
*
|
|
408
|
-
* Returns `undefined` when the page has no animations, in which case the
|
|
409
|
-
* caller should fall back to a normal full-page render.
|
|
410
|
-
*/
|
|
411
|
-
async renderPageLayers(documentId, pageIndex, width, height) {
|
|
412
|
-
const response = (await this.send({
|
|
413
|
-
type: "renderPageLayers",
|
|
414
|
-
documentId,
|
|
415
|
-
pageIndex,
|
|
416
|
-
width,
|
|
417
|
-
height,
|
|
418
|
-
}));
|
|
419
|
-
return response.layers;
|
|
420
|
-
}
|
|
421
|
-
/**
|
|
422
|
-
* Request annotations via the unified work queue.
|
|
423
|
-
* Lower priority than renders — waits for pending renders to complete first.
|
|
424
|
-
*/
|
|
425
|
-
requestAnnotations(docId, pageIndex) {
|
|
426
|
-
const page = pageIndex + 1; // Convert 0-based to 1-based
|
|
427
|
-
const key = `annotation:${docId}:${page}`;
|
|
428
|
-
// Check if already in-flight
|
|
429
|
-
if (this.currentWork?.key === key) {
|
|
430
|
-
return this.currentWork.promise;
|
|
431
|
-
}
|
|
432
|
-
// Check if already queued (dedup)
|
|
433
|
-
const queued = this.workQueue.find((q) => q.kind === "annotation" && q.docId === docId && q.page === page);
|
|
434
|
-
if (queued) {
|
|
435
|
-
return new Promise((resolve, reject) => {
|
|
436
|
-
const originalResolve = queued.resolve;
|
|
437
|
-
const originalReject = queued.reject;
|
|
438
|
-
queued.resolve = (result) => {
|
|
439
|
-
originalResolve(result);
|
|
440
|
-
resolve(result);
|
|
441
|
-
};
|
|
442
|
-
queued.reject = (error) => {
|
|
443
|
-
originalReject(error);
|
|
444
|
-
reject(error);
|
|
445
|
-
};
|
|
446
|
-
});
|
|
447
|
-
}
|
|
448
|
-
return new Promise((resolve, reject) => {
|
|
449
|
-
this.workQueue.push({
|
|
450
|
-
kind: "annotation",
|
|
451
|
-
docId,
|
|
452
|
-
page,
|
|
453
|
-
priority: 0,
|
|
454
|
-
resolve,
|
|
455
|
-
reject,
|
|
456
|
-
});
|
|
457
|
-
this.sortQueue();
|
|
458
|
-
this.processWorkQueue();
|
|
459
|
-
});
|
|
460
|
-
}
|
|
461
|
-
/**
|
|
462
|
-
* Request text content via the unified work queue.
|
|
463
|
-
* Lowest priority — waits for pending renders and annotations to complete first.
|
|
464
|
-
*/
|
|
465
|
-
requestText(docId, pageIndex) {
|
|
466
|
-
const page = pageIndex + 1; // Convert 0-based to 1-based
|
|
467
|
-
const key = `text:${docId}:${page}`;
|
|
468
|
-
// Check if already in-flight
|
|
469
|
-
if (this.currentWork?.key === key) {
|
|
470
|
-
return this.currentWork.promise;
|
|
471
|
-
}
|
|
472
|
-
// Check if already queued (dedup)
|
|
473
|
-
const queued = this.workQueue.find((q) => q.kind === "text" && q.docId === docId && q.page === page);
|
|
474
|
-
if (queued) {
|
|
475
|
-
return new Promise((resolve, reject) => {
|
|
476
|
-
const originalResolve = queued.resolve;
|
|
477
|
-
const originalReject = queued.reject;
|
|
478
|
-
queued.resolve = (result) => {
|
|
479
|
-
originalResolve(result);
|
|
480
|
-
resolve(result);
|
|
481
|
-
};
|
|
482
|
-
queued.reject = (error) => {
|
|
483
|
-
originalReject(error);
|
|
484
|
-
reject(error);
|
|
485
|
-
};
|
|
486
|
-
});
|
|
487
|
-
}
|
|
488
|
-
return new Promise((resolve, reject) => {
|
|
489
|
-
this.workQueue.push({
|
|
490
|
-
kind: "text",
|
|
491
|
-
docId,
|
|
492
|
-
page,
|
|
493
|
-
priority: 0,
|
|
494
|
-
resolve,
|
|
495
|
-
reject,
|
|
496
|
-
});
|
|
497
|
-
this.sortQueue();
|
|
498
|
-
this.processWorkQueue();
|
|
499
|
-
});
|
|
500
|
-
}
|
|
501
|
-
/**
|
|
502
|
-
* Get all annotations grouped by page.
|
|
503
|
-
*/
|
|
504
|
-
async getAllAnnotations(documentId) {
|
|
505
|
-
const counter = this.getCounter(documentId);
|
|
506
|
-
const eventId = counter?.markStart("getAllAnnotations");
|
|
507
|
-
try {
|
|
508
|
-
const response = (await this.send({ type: "getAllAnnotations", documentId }));
|
|
509
|
-
if (eventId)
|
|
510
|
-
counter?.markEnd(eventId);
|
|
511
|
-
return response.annotations;
|
|
512
|
-
}
|
|
513
|
-
catch (error) {
|
|
514
|
-
if (eventId)
|
|
515
|
-
counter?.markEnd(eventId, false, error.message);
|
|
516
|
-
throw error;
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
/**
|
|
520
|
-
* Save annotations to a PDF document.
|
|
521
|
-
* Returns the modified PDF bytes with annotations applied.
|
|
522
|
-
*/
|
|
523
|
-
async pdfSaveAnnotations(documentId, annotationsByPage) {
|
|
524
|
-
const response = (await this.send({ type: "pdfSaveAnnotations", documentId, annotationsByPage }));
|
|
525
|
-
return response.bytes;
|
|
526
|
-
}
|
|
527
|
-
/**
|
|
528
|
-
* Compose new PDF documents by cherry-picking pages from source documents.
|
|
529
|
-
*
|
|
530
|
-
* @param compositions - Array of compositions. Each composition is an array of picks
|
|
531
|
-
* that will form one output document.
|
|
532
|
-
* @param docIds - Array of document IDs to use as sources (order matters for doc indices)
|
|
533
|
-
* @returns Array of new document IDs (one per composition)
|
|
534
|
-
*/
|
|
535
|
-
async pdfCompose(compositions, docIds) {
|
|
536
|
-
const response = (await this.send({ type: "pdfCompose", compositions, docIds }));
|
|
537
|
-
return response.documentIds;
|
|
538
|
-
}
|
|
539
|
-
/**
|
|
540
|
-
* Split a PDF document by its outline (bookmarks) structure.
|
|
541
|
-
*
|
|
542
|
-
* @param documentId - Document ID to split
|
|
543
|
-
* @param maxLevel - Maximum outline level to consider (1 = top level only)
|
|
544
|
-
* @param splitMidPage - When true, filters page content when sections share a page
|
|
545
|
-
* @returns Object with documentIds and sections
|
|
546
|
-
*/
|
|
547
|
-
async pdfSplitByOutline(documentId, maxLevel, splitMidPage = false) {
|
|
548
|
-
const response = (await this.send({ type: "pdfSplitByOutline", documentId, maxLevel, splitMidPage }));
|
|
549
|
-
return response.result;
|
|
550
|
-
}
|
|
551
|
-
/**
|
|
552
|
-
* Extract all embedded images from a PDF document.
|
|
553
|
-
*
|
|
554
|
-
* @param documentId - Document ID to extract images from
|
|
555
|
-
* @param convertRawToPng - When true, converts raw pixel data to PNG format
|
|
556
|
-
* @returns Array of extracted images with metadata and data
|
|
557
|
-
*/
|
|
558
|
-
async pdfExtractImages(documentId, convertRawToPng = false) {
|
|
559
|
-
const response = (await this.send({ type: "pdfExtractImages", documentId, convertRawToPng }));
|
|
560
|
-
return response.images;
|
|
561
|
-
}
|
|
562
|
-
/**
|
|
563
|
-
* Extract all embedded fonts from a PDF document.
|
|
564
|
-
*
|
|
565
|
-
* @param documentId - Document ID to extract fonts from
|
|
566
|
-
* @returns Array of extracted fonts with metadata and data
|
|
567
|
-
*/
|
|
568
|
-
/**
|
|
569
|
-
* Parse font information from raw font binary data.
|
|
570
|
-
*
|
|
571
|
-
* @param data - Raw font binary data (e.g., .ttf, .otf, .woff2)
|
|
572
|
-
* @returns Font information including typeface, bold, and italic
|
|
573
|
-
*/
|
|
574
|
-
async parseFontInfo(data) {
|
|
575
|
-
const response = (await this.send({ type: "parseFontInfo", data }));
|
|
576
|
-
return response.info;
|
|
577
|
-
}
|
|
578
|
-
async pdfExtractFonts(documentId) {
|
|
579
|
-
const response = (await this.send({ type: "pdfExtractFonts", documentId }));
|
|
580
|
-
return response.fonts;
|
|
581
|
-
}
|
|
582
|
-
/**
|
|
583
|
-
* Compress a PDF document.
|
|
584
|
-
*
|
|
585
|
-
* Saves the document with full compression options enabled.
|
|
586
|
-
*
|
|
587
|
-
* @param documentId - Document ID to compress
|
|
588
|
-
* @returns Compressed PDF data
|
|
589
|
-
*/
|
|
590
|
-
async pdfCompress(documentId) {
|
|
591
|
-
const response = (await this.send({ type: "pdfCompress", documentId }));
|
|
592
|
-
return response.bytes;
|
|
593
|
-
}
|
|
594
|
-
/**
|
|
595
|
-
* Decompress a PDF document.
|
|
596
|
-
*
|
|
597
|
-
* Removes all filter encodings from streams, resulting in raw,
|
|
598
|
-
* uncompressed stream data.
|
|
599
|
-
*
|
|
600
|
-
* @param documentId - Document ID to decompress
|
|
601
|
-
* @returns Decompressed PDF data
|
|
602
|
-
*/
|
|
603
|
-
async pdfDecompress(documentId) {
|
|
604
|
-
const response = (await this.send({ type: "pdfDecompress", documentId }));
|
|
605
|
-
return response.bytes;
|
|
606
|
-
}
|
|
607
|
-
/**
|
|
608
|
-
* Get the raw PDF bytes of a document.
|
|
609
|
-
*/
|
|
610
|
-
async getBytes(documentId) {
|
|
611
|
-
const response = (await this.send({ type: "getBytes", documentId }));
|
|
612
|
-
return response.bytes;
|
|
613
|
-
}
|
|
614
|
-
// ===========================================================================
|
|
615
|
-
// Font Management
|
|
616
|
-
// ===========================================================================
|
|
617
|
-
/**
|
|
618
|
-
* Register font URLs.
|
|
619
|
-
*
|
|
620
|
-
* The engine fetches fonts on-demand during layout from the provided URLs.
|
|
621
|
-
* Call this before loading documents. Registered fonts take priority over
|
|
622
|
-
* Google Fonts.
|
|
623
|
-
*
|
|
624
|
-
* @param fonts - Array of font entries with typeface, style, and URL
|
|
625
|
-
*/
|
|
626
|
-
async registerFonts(fonts) {
|
|
627
|
-
await this.send({ type: "registerFonts", fonts });
|
|
628
|
-
}
|
|
629
|
-
/**
|
|
630
|
-
* Enable Google Fonts.
|
|
631
|
-
*
|
|
632
|
-
* When enabled, fonts not embedded in the document are fetched from
|
|
633
|
-
* Google Fonts on-demand during rendering. Google Fonts are resolved
|
|
634
|
-
* after any URL fonts registered via `registerFonts`.
|
|
635
|
-
*
|
|
636
|
-
* Call this before loading documents.
|
|
637
|
-
*/
|
|
638
|
-
async enableGoogleFonts() {
|
|
639
|
-
await this.send({ type: "enableGoogleFonts" });
|
|
640
|
-
}
|
|
641
|
-
// ===========================================================================
|
|
642
|
-
// Visibility Groups
|
|
643
|
-
// ===========================================================================
|
|
644
|
-
/**
|
|
645
|
-
* Get visibility groups for a document.
|
|
646
|
-
*/
|
|
647
|
-
async getVisibilityGroups(documentId) {
|
|
648
|
-
const response = (await this.send({ type: "getVisibilityGroups", documentId }));
|
|
649
|
-
return response.groups;
|
|
650
|
-
}
|
|
651
|
-
/**
|
|
652
|
-
* Set visibility of a specific group.
|
|
653
|
-
*
|
|
654
|
-
* @returns true if the group was found and updated
|
|
655
|
-
*/
|
|
656
|
-
async setVisibilityGroupVisible(documentId, groupId, visible) {
|
|
657
|
-
const response = (await this.send({ type: "setVisibilityGroupVisible", documentId, groupId, visible }));
|
|
658
|
-
return response.updated;
|
|
659
|
-
}
|
|
660
|
-
// ===========================================================================
|
|
661
|
-
// Performance Counter Integration
|
|
662
|
-
// ===========================================================================
|
|
663
|
-
/**
|
|
664
|
-
* Set the performance counter for a document.
|
|
665
|
-
* All operations for this document will be tracked.
|
|
666
|
-
*/
|
|
667
|
-
setPerformanceCounter(docId, counter) {
|
|
668
|
-
this.performanceCounters.set(docId, counter);
|
|
669
|
-
}
|
|
670
|
-
/**
|
|
671
|
-
* Remove the performance counter for a document.
|
|
672
|
-
*/
|
|
673
|
-
removePerformanceCounter(docId) {
|
|
674
|
-
this.performanceCounters.delete(docId);
|
|
675
|
-
}
|
|
676
|
-
getCounter(docId) {
|
|
677
|
-
return this.performanceCounters.get(docId);
|
|
678
|
-
}
|
|
679
|
-
// ===========================================================================
|
|
680
|
-
// Render Management Methods
|
|
681
|
-
// ===========================================================================
|
|
682
|
-
getCache(type) {
|
|
683
|
-
if (type === "page")
|
|
684
|
-
return this.pageRenderCache;
|
|
685
|
-
if (type === "preview")
|
|
686
|
-
return this.previewRenderCache;
|
|
687
|
-
return this.thumbnailRenderCache;
|
|
688
|
-
}
|
|
689
|
-
getMaxCacheSize(type) {
|
|
690
|
-
if (type === "preview")
|
|
691
|
-
return this.maxPreviewCacheSize;
|
|
692
|
-
return this.maxThumbnailCacheSize;
|
|
693
|
-
}
|
|
694
|
-
cacheTotalBytes(cache) {
|
|
695
|
-
let bytes = 0;
|
|
696
|
-
for (const entry of cache.values()) {
|
|
697
|
-
bytes += entry.result.width * entry.result.height * 4;
|
|
698
|
-
}
|
|
699
|
-
return bytes;
|
|
700
|
-
}
|
|
701
|
-
/**
|
|
702
|
-
* Request a render. Returns cached result if available,
|
|
703
|
-
* otherwise queues the request.
|
|
704
|
-
*
|
|
705
|
-
* When a new request is queued, it cancels any existing queued requests
|
|
706
|
-
* for the same page index and render type (but not in-flight requests).
|
|
707
|
-
*/
|
|
708
|
-
requestRender(req) {
|
|
709
|
-
const key = makeRenderKey(req.docId, req.page, req.type, req.scale);
|
|
710
|
-
const cache = this.getCache(req.type);
|
|
711
|
-
// Check cache first
|
|
712
|
-
const cached = cache.get(key);
|
|
713
|
-
if (cached) {
|
|
714
|
-
cached.lastAccess = Date.now();
|
|
715
|
-
return Promise.resolve(cached.result);
|
|
716
|
-
}
|
|
717
|
-
// Check if already in-flight
|
|
718
|
-
if (this.currentWork?.key === key) {
|
|
719
|
-
return this.currentWork.promise;
|
|
720
|
-
}
|
|
721
|
-
// Check if already queued with same parameters
|
|
722
|
-
const queued = this.workQueue.find((q) => q.kind === "render" &&
|
|
723
|
-
q.docId === req.docId &&
|
|
724
|
-
q.page === req.page &&
|
|
725
|
-
q.type === req.type &&
|
|
726
|
-
q.scale === req.scale);
|
|
727
|
-
if (queued) {
|
|
728
|
-
return new Promise((resolve, reject) => {
|
|
729
|
-
const originalResolve = queued.resolve;
|
|
730
|
-
const originalReject = queued.reject;
|
|
731
|
-
queued.resolve = (result) => {
|
|
732
|
-
originalResolve(result);
|
|
733
|
-
resolve(result);
|
|
734
|
-
};
|
|
735
|
-
queued.reject = (error) => {
|
|
736
|
-
originalReject(error);
|
|
737
|
-
reject(error);
|
|
738
|
-
};
|
|
739
|
-
});
|
|
740
|
-
}
|
|
741
|
-
// Cancel any existing queued requests for the same page and type (different scale)
|
|
742
|
-
// This ensures we only render the most recent scale for each page
|
|
743
|
-
this.cancelQueuedRequestsForPage(req.docId, req.page, req.type);
|
|
744
|
-
// Queue the request
|
|
745
|
-
return new Promise((resolve, reject) => {
|
|
746
|
-
const queuedReq = {
|
|
747
|
-
kind: "render",
|
|
748
|
-
...req,
|
|
749
|
-
priority: 0, // Priority is now determined by distance-based sorting
|
|
750
|
-
resolve,
|
|
751
|
-
reject,
|
|
752
|
-
};
|
|
753
|
-
this.workQueue.push(queuedReq);
|
|
754
|
-
this.sortQueue(); // Sort to place request in correct position based on current focus
|
|
755
|
-
this.processWorkQueue();
|
|
756
|
-
});
|
|
757
|
-
}
|
|
758
|
-
/**
|
|
759
|
-
* Cancel queued requests for a specific page (within the same render type).
|
|
760
|
-
* Does not cancel in-flight requests.
|
|
761
|
-
*/
|
|
762
|
-
cancelQueuedRequestsForPage(docId, page, type) {
|
|
763
|
-
this.workQueue = this.workQueue.filter((item) => {
|
|
764
|
-
if (item.kind !== "render")
|
|
765
|
-
return true;
|
|
766
|
-
const shouldCancel = item.docId === docId && item.page === page && item.type === type;
|
|
767
|
-
if (shouldCancel) {
|
|
768
|
-
item.reject(new Error("Request cancelled"));
|
|
769
|
-
}
|
|
770
|
-
return !shouldCancel;
|
|
771
|
-
});
|
|
772
|
-
}
|
|
773
|
-
/**
|
|
774
|
-
* Get a cached result without queuing a render.
|
|
775
|
-
*/
|
|
776
|
-
getCachedRender(docId, page, type, scale) {
|
|
777
|
-
const key = makeRenderKey(docId, page, type, scale);
|
|
778
|
-
const cache = this.getCache(type);
|
|
779
|
-
const cached = cache.get(key);
|
|
780
|
-
if (cached) {
|
|
781
|
-
cached.lastAccess = Date.now();
|
|
782
|
-
return cached.result;
|
|
783
|
-
}
|
|
784
|
-
return null;
|
|
785
|
-
}
|
|
786
|
-
/**
|
|
787
|
-
* Cancel pending render requests matching criteria.
|
|
788
|
-
* Does not cancel in-flight requests.
|
|
789
|
-
*/
|
|
790
|
-
cancelRenders(docId, page, type) {
|
|
791
|
-
this.workQueue = this.workQueue.filter((item) => {
|
|
792
|
-
if (item.kind !== "render")
|
|
793
|
-
return true;
|
|
794
|
-
const match = (docId === undefined || item.docId === docId) &&
|
|
795
|
-
(page === undefined || item.page === page) &&
|
|
796
|
-
(type === undefined || item.type === type);
|
|
797
|
-
if (match) {
|
|
798
|
-
item.reject(new Error("Request cancelled"));
|
|
799
|
-
}
|
|
800
|
-
return !match;
|
|
801
|
-
});
|
|
802
|
-
}
|
|
803
|
-
/**
|
|
804
|
-
* Invalidate cache entries. Call when document or zoom changes.
|
|
805
|
-
*/
|
|
806
|
-
/**
|
|
807
|
-
* Clear cached bitmaps without notifying UI callbacks.
|
|
808
|
-
* Use during document close to avoid triggering re-renders.
|
|
809
|
-
*/
|
|
810
|
-
clearRenderCache(docId) {
|
|
811
|
-
const clear = (cache) => {
|
|
812
|
-
if (docId === undefined) {
|
|
813
|
-
for (const entry of cache.values()) {
|
|
814
|
-
entry.result.bitmap.close();
|
|
815
|
-
}
|
|
816
|
-
cache.clear();
|
|
817
|
-
}
|
|
818
|
-
else {
|
|
819
|
-
for (const [key, entry] of cache) {
|
|
820
|
-
if (key.startsWith(docId + ":")) {
|
|
821
|
-
entry.result.bitmap.close();
|
|
822
|
-
cache.delete(key);
|
|
823
|
-
}
|
|
824
|
-
}
|
|
825
|
-
}
|
|
826
|
-
};
|
|
827
|
-
clear(this.pageRenderCache);
|
|
828
|
-
clear(this.thumbnailRenderCache);
|
|
829
|
-
clear(this.previewRenderCache);
|
|
830
|
-
}
|
|
831
|
-
invalidateRenderCache(docId, type) {
|
|
832
|
-
const invalidateCache = (cache) => {
|
|
833
|
-
if (docId === undefined) {
|
|
834
|
-
for (const entry of cache.values()) {
|
|
835
|
-
entry.result.bitmap.close();
|
|
836
|
-
}
|
|
837
|
-
cache.clear();
|
|
838
|
-
}
|
|
839
|
-
else {
|
|
840
|
-
for (const [key, entry] of cache) {
|
|
841
|
-
if (key.startsWith(docId + ":")) {
|
|
842
|
-
entry.result.bitmap.close();
|
|
843
|
-
cache.delete(key);
|
|
844
|
-
}
|
|
845
|
-
}
|
|
846
|
-
}
|
|
847
|
-
};
|
|
848
|
-
if (type === undefined || type === "page") {
|
|
849
|
-
invalidateCache(this.pageRenderCache);
|
|
850
|
-
}
|
|
851
|
-
if (type === undefined || type === "thumbnail") {
|
|
852
|
-
invalidateCache(this.thumbnailRenderCache);
|
|
853
|
-
}
|
|
854
|
-
if (type === undefined || type === "preview") {
|
|
855
|
-
invalidateCache(this.previewRenderCache);
|
|
856
|
-
}
|
|
857
|
-
for (const cb of this.renderInvalidatedCallbacks) {
|
|
858
|
-
cb();
|
|
859
|
-
}
|
|
860
|
-
}
|
|
861
|
-
/**
|
|
862
|
-
* Subscribe to render cache invalidation events.
|
|
863
|
-
* Returns an unsubscribe function.
|
|
864
|
-
*/
|
|
865
|
-
onRenderInvalidated(callback) {
|
|
866
|
-
this.renderInvalidatedCallbacks.add(callback);
|
|
867
|
-
return () => this.renderInvalidatedCallbacks.delete(callback);
|
|
868
|
-
}
|
|
869
|
-
/**
|
|
870
|
-
* Subscribe to render OOM events. Fired after caches are cleared so UIs
|
|
871
|
-
* can surface a warning or trigger quality degradation.
|
|
872
|
-
*/
|
|
873
|
-
onOOM(callback) {
|
|
874
|
-
this.oomCallbacks.add(callback);
|
|
875
|
-
return () => this.oomCallbacks.delete(callback);
|
|
876
|
-
}
|
|
877
|
-
/**
|
|
878
|
-
* Current WASM linear-memory size in bytes (reflects every `memory.grow`).
|
|
879
|
-
* Returns 0 if the worker has not finished initializing yet.
|
|
880
|
-
*/
|
|
881
|
-
async getWasmMemoryBytes() {
|
|
882
|
-
const response = (await this.send({ type: "getWasmMemoryBytes" }));
|
|
883
|
-
return response.bytes;
|
|
884
|
-
}
|
|
885
|
-
/**
|
|
886
|
-
* Return a snapshot of cached bitmap counts and estimated memory (bytes).
|
|
887
|
-
* Estimated as width * height * 4 (RGBA) per ImageBitmap.
|
|
888
|
-
*/
|
|
889
|
-
getRenderCacheStats() {
|
|
890
|
-
const measure = (cache) => {
|
|
891
|
-
let bytes = 0;
|
|
892
|
-
for (const entry of cache.values()) {
|
|
893
|
-
bytes += entry.result.width * entry.result.height * 4;
|
|
894
|
-
}
|
|
895
|
-
return { count: cache.size, bytes };
|
|
896
|
-
};
|
|
897
|
-
const page = measure(this.pageRenderCache);
|
|
898
|
-
const thumbnail = measure(this.thumbnailRenderCache);
|
|
899
|
-
const preview = measure(this.previewRenderCache);
|
|
900
|
-
return {
|
|
901
|
-
page,
|
|
902
|
-
thumbnail,
|
|
903
|
-
preview,
|
|
904
|
-
total: {
|
|
905
|
-
count: page.count + thumbnail.count + preview.count,
|
|
906
|
-
bytes: page.bytes + thumbnail.bytes + preview.bytes,
|
|
907
|
-
},
|
|
908
|
-
};
|
|
909
|
-
}
|
|
910
|
-
/**
|
|
911
|
-
* Drop every cached ImageBitmap to free memory, then notify OOM subscribers.
|
|
912
|
-
* Throttled so a burst of failures doesn't produce a cache-clear storm.
|
|
913
|
-
*/
|
|
914
|
-
handleOOM(error) {
|
|
915
|
-
const now = Date.now();
|
|
916
|
-
if (now - this.lastOOMClearAt > 500) {
|
|
917
|
-
this.lastOOMClearAt = now;
|
|
918
|
-
this.clearRenderCache();
|
|
919
|
-
}
|
|
920
|
-
const err = error instanceof Error ? error : new Error(String(error));
|
|
921
|
-
for (const cb of this.oomCallbacks)
|
|
922
|
-
cb(err);
|
|
923
|
-
}
|
|
924
|
-
/**
|
|
925
|
-
* Subscribe to font usage change events.
|
|
926
|
-
* Called when font usage changes after a page render.
|
|
927
|
-
* Returns an unsubscribe function.
|
|
928
|
-
*/
|
|
929
|
-
onFontUsageChanged(callback) {
|
|
930
|
-
this.fontUsageChangedCallbacks.add(callback);
|
|
931
|
-
return () => this.fontUsageChangedCallbacks.delete(callback);
|
|
932
|
-
}
|
|
933
|
-
/**
|
|
934
|
-
* Enqueue a font usage check at the end of the work queue.
|
|
935
|
-
* Deduplicates: only one check per docId is queued at a time.
|
|
936
|
-
*/
|
|
937
|
-
scheduleFontUsageCheck(docId) {
|
|
938
|
-
if (this.fontUsageChangedCallbacks.size === 0)
|
|
939
|
-
return;
|
|
940
|
-
// Already queued for this doc — skip
|
|
941
|
-
const key = `fontUsageCheck:${docId}`;
|
|
942
|
-
if (this.workQueue.some((item) => makeWorkKey(item) === key))
|
|
943
|
-
return;
|
|
944
|
-
this.workQueue.push({
|
|
945
|
-
kind: "fontUsageCheck",
|
|
946
|
-
docId,
|
|
947
|
-
page: 0,
|
|
948
|
-
priority: Infinity,
|
|
949
|
-
resolve: () => { },
|
|
950
|
-
reject: () => { },
|
|
951
|
-
});
|
|
952
|
-
// Don't re-sort or kick processWorkQueue here —
|
|
953
|
-
// it will be picked up naturally after the current work finishes.
|
|
954
|
-
}
|
|
955
|
-
async doFontUsageCheck(item) {
|
|
956
|
-
try {
|
|
957
|
-
const entries = await this.getFontUsage(item.docId);
|
|
958
|
-
const length = Array.isArray(entries) ? entries.length : 0;
|
|
959
|
-
const previous = this.lastFontUsageLength.get(item.docId);
|
|
960
|
-
if (previous !== length) {
|
|
961
|
-
this.lastFontUsageLength.set(item.docId, length);
|
|
962
|
-
for (const cb of this.fontUsageChangedCallbacks) {
|
|
963
|
-
cb(item.docId);
|
|
964
|
-
}
|
|
965
|
-
}
|
|
966
|
-
item.resolve(undefined);
|
|
967
|
-
}
|
|
968
|
-
catch {
|
|
969
|
-
// Font usage query failed (e.g. document unloaded) — ignore
|
|
970
|
-
item.resolve(undefined);
|
|
971
|
-
}
|
|
972
|
-
}
|
|
973
|
-
/**
|
|
974
|
-
* Sort page render requests in the queue by distance to the focused page.
|
|
975
|
-
* Updates the page focus and re-sorts the queue.
|
|
976
|
-
*/
|
|
977
|
-
boostPageRenderPriority(docId, focusPage) {
|
|
978
|
-
this.pageFocus = { docId, page: focusPage };
|
|
979
|
-
this.sortQueue();
|
|
980
|
-
this.processWorkQueue();
|
|
981
|
-
}
|
|
982
|
-
/**
|
|
983
|
-
* Sort thumbnail render requests in the queue by distance to the focused thumbnail.
|
|
984
|
-
* Updates the thumbnail focus and re-sorts the queue.
|
|
985
|
-
*/
|
|
986
|
-
boostThumbnailRenderPriority(docId, focusPage) {
|
|
987
|
-
this.thumbnailFocus = { docId, page: focusPage };
|
|
988
|
-
this.sortQueue();
|
|
989
|
-
this.processWorkQueue();
|
|
990
|
-
}
|
|
991
|
-
static PRERENDER_RANGE = 2; // Prerender pages within ±2 of current
|
|
992
|
-
/**
|
|
993
|
-
* Prerender adjacent pages for smooth page flipping in single spread mode.
|
|
994
|
-
* Queues renders for pages before and after the current page (fire and forget).
|
|
995
|
-
* Boosts current page priority so it renders first during rapid flipping.
|
|
996
|
-
*/
|
|
997
|
-
prerenderAdjacentPages(docId, currentPage, scale, totalPages) {
|
|
998
|
-
// Boost current page priority - ensures it renders first even during rapid flipping
|
|
999
|
-
this.boostPageRenderPriority(docId, currentPage);
|
|
1000
|
-
// Queue adjacent pages for prerendering
|
|
1001
|
-
for (let offset = 1; offset <= WorkerClient.PRERENDER_RANGE; offset++) {
|
|
1002
|
-
// Prerender next pages
|
|
1003
|
-
const nextPage = currentPage + offset;
|
|
1004
|
-
if (nextPage >= 1 && nextPage <= totalPages) {
|
|
1005
|
-
this.requestRender({
|
|
1006
|
-
docId,
|
|
1007
|
-
page: nextPage,
|
|
1008
|
-
type: "page",
|
|
1009
|
-
scale,
|
|
1010
|
-
}).catch(() => {
|
|
1011
|
-
// Ignore errors - prerendering is best-effort
|
|
1012
|
-
});
|
|
1013
|
-
}
|
|
1014
|
-
// Prerender previous pages
|
|
1015
|
-
const prevPage = currentPage - offset;
|
|
1016
|
-
if (prevPage >= 1 && prevPage <= totalPages) {
|
|
1017
|
-
this.requestRender({
|
|
1018
|
-
docId,
|
|
1019
|
-
page: prevPage,
|
|
1020
|
-
type: "page",
|
|
1021
|
-
scale,
|
|
1022
|
-
}).catch(() => {
|
|
1023
|
-
// Ignore errors - prerendering is best-effort
|
|
1024
|
-
});
|
|
1025
|
-
}
|
|
1026
|
-
}
|
|
1027
|
-
}
|
|
1028
|
-
/**
|
|
1029
|
-
* Render a page directly, bypassing the cache and queue.
|
|
1030
|
-
* Useful for one-off renders that shouldn't affect the normal render flow.
|
|
1031
|
-
*/
|
|
1032
|
-
async forceRender(req) {
|
|
1033
|
-
const counter = this.getCounter(req.docId);
|
|
1034
|
-
const eventType = req.type === "thumbnail" ? "renderThumbnail" : "renderPage";
|
|
1035
|
-
const pageIndex = req.page - 1;
|
|
1036
|
-
const eventId = counter?.markStart(eventType, { pageIndex, scale: req.scale });
|
|
1037
|
-
try {
|
|
1038
|
-
const pageInfo = await this.getPageInfo(req.docId, pageIndex);
|
|
1039
|
-
const width = Math.round(pageInfo.width * req.scale);
|
|
1040
|
-
const height = Math.round(pageInfo.height * req.scale);
|
|
1041
|
-
// Send render request directly to worker
|
|
1042
|
-
const rendered = (await this.send({
|
|
1043
|
-
type: "renderPage",
|
|
1044
|
-
documentId: req.docId,
|
|
1045
|
-
pageIndex,
|
|
1046
|
-
width,
|
|
1047
|
-
height,
|
|
1048
|
-
}));
|
|
1049
|
-
const source = rendered.rgba;
|
|
1050
|
-
const clamped = source.buffer instanceof ArrayBuffer
|
|
1051
|
-
? new Uint8ClampedArray(source.buffer, source.byteOffset, source.byteLength)
|
|
1052
|
-
: new Uint8ClampedArray(source);
|
|
1053
|
-
const imageData = new ImageData(clamped, rendered.width, rendered.height);
|
|
1054
|
-
const bitmap = await createImageBitmap(imageData);
|
|
1055
|
-
const result = {
|
|
1056
|
-
bitmap,
|
|
1057
|
-
width: bitmap.width,
|
|
1058
|
-
height: bitmap.height,
|
|
1059
|
-
};
|
|
1060
|
-
// Note: We intentionally don't add to cache for force renders
|
|
1061
|
-
if (eventId)
|
|
1062
|
-
counter?.markEnd(eventId);
|
|
1063
|
-
return result;
|
|
1064
|
-
}
|
|
1065
|
-
catch (error) {
|
|
1066
|
-
if (eventId)
|
|
1067
|
-
counter?.markEnd(eventId, false, error.message);
|
|
1068
|
-
if (isOOMError(error))
|
|
1069
|
-
this.handleOOM(error);
|
|
1070
|
-
throw error instanceof Error ? error : new Error(String(error));
|
|
1071
|
-
}
|
|
1072
|
-
}
|
|
1073
|
-
static BOOST_RANGE = 5; // Boost pages within ±5 of focus (11 pages total)
|
|
1074
|
-
/**
|
|
1075
|
-
* Sort work queue by priority: page-proximity first, then type within each page.
|
|
1076
|
-
*
|
|
1077
|
-
* For page-focused items (pages, previews, annotations, text):
|
|
1078
|
-
* Grouped by distance to pageFocus, closest first. Within each page,
|
|
1079
|
-
* ordered: preview → page render → annotation → text.
|
|
1080
|
-
* Boosted pages (within BOOST_RANGE) come before all non-boosted pages.
|
|
1081
|
-
*
|
|
1082
|
-
* Thumbnails use thumbnailFocus independently and come after all page items.
|
|
1083
|
-
*/
|
|
1084
|
-
sortQueue() {
|
|
1085
|
-
if (this.workQueue.length === 0)
|
|
1086
|
-
return;
|
|
1087
|
-
const pageFocus = this.pageFocus;
|
|
1088
|
-
const thumbnailFocus = this.thumbnailFocus;
|
|
1089
|
-
const pageItems = [];
|
|
1090
|
-
const thumbnailItems = [];
|
|
1091
|
-
for (const item of this.workQueue) {
|
|
1092
|
-
if (item.kind === "render" && item.type === "thumbnail") {
|
|
1093
|
-
thumbnailItems.push(item);
|
|
1094
|
-
}
|
|
1095
|
-
else {
|
|
1096
|
-
pageItems.push(item);
|
|
1097
|
-
}
|
|
1098
|
-
}
|
|
1099
|
-
// Sort page items: by distance to focus, then by type within same page
|
|
1100
|
-
const typeOrder = (item) => {
|
|
1101
|
-
if (item.kind === "render" && item.type === "preview")
|
|
1102
|
-
return 0;
|
|
1103
|
-
if (item.kind === "render" && item.type === "page")
|
|
1104
|
-
return 1;
|
|
1105
|
-
if (item.kind === "annotation")
|
|
1106
|
-
return 2;
|
|
1107
|
-
if (item.kind === "text")
|
|
1108
|
-
return 3;
|
|
1109
|
-
// fontUsageCheck — always last
|
|
1110
|
-
return 4;
|
|
1111
|
-
};
|
|
1112
|
-
pageItems.sort((a, b) => {
|
|
1113
|
-
// fontUsageCheck always sorts last among page items
|
|
1114
|
-
const aIsCheck = a.kind === "fontUsageCheck" ? 1 : 0;
|
|
1115
|
-
const bIsCheck = b.kind === "fontUsageCheck" ? 1 : 0;
|
|
1116
|
-
if (aIsCheck !== bIsCheck)
|
|
1117
|
-
return aIsCheck - bIsCheck;
|
|
1118
|
-
const ad = pageFocus && a.docId === pageFocus.docId ? Math.abs(a.page - pageFocus.page) : Infinity;
|
|
1119
|
-
const bd = pageFocus && b.docId === pageFocus.docId ? Math.abs(b.page - pageFocus.page) : Infinity;
|
|
1120
|
-
// Boosted vs non-boosted
|
|
1121
|
-
const aBoosted = ad <= WorkerClient.BOOST_RANGE;
|
|
1122
|
-
const bBoosted = bd <= WorkerClient.BOOST_RANGE;
|
|
1123
|
-
if (aBoosted !== bBoosted)
|
|
1124
|
-
return aBoosted ? -1 : 1;
|
|
1125
|
-
// Same distance → order by type; different distance → closer first
|
|
1126
|
-
if (ad !== bd)
|
|
1127
|
-
return ad - bd;
|
|
1128
|
-
return typeOrder(a) - typeOrder(b);
|
|
1129
|
-
});
|
|
1130
|
-
// Sort thumbnails by distance to thumbnail focus
|
|
1131
|
-
thumbnailItems.sort((a, b) => {
|
|
1132
|
-
const ad = thumbnailFocus && a.docId === thumbnailFocus.docId ? Math.abs(a.page - thumbnailFocus.page) : Infinity;
|
|
1133
|
-
const bd = thumbnailFocus && b.docId === thumbnailFocus.docId ? Math.abs(b.page - thumbnailFocus.page) : Infinity;
|
|
1134
|
-
return ad - bd;
|
|
1135
|
-
});
|
|
1136
|
-
// Page items first, then thumbnails
|
|
1137
|
-
this.workQueue = [...pageItems, ...thumbnailItems];
|
|
1138
|
-
}
|
|
1139
|
-
/**
|
|
1140
|
-
* Clean up render resources.
|
|
1141
|
-
*/
|
|
1142
|
-
destroyRenderResources() {
|
|
1143
|
-
// Cancel all pending renders
|
|
1144
|
-
for (const req of this.workQueue) {
|
|
1145
|
-
req.reject(new Error("WorkerClient destroyed"));
|
|
1146
|
-
}
|
|
1147
|
-
this.workQueue = [];
|
|
1148
|
-
// Close all cached page bitmaps
|
|
1149
|
-
for (const entry of this.pageRenderCache.values()) {
|
|
1150
|
-
entry.result.bitmap.close();
|
|
1151
|
-
}
|
|
1152
|
-
this.pageRenderCache.clear();
|
|
1153
|
-
// Close all cached thumbnail bitmaps
|
|
1154
|
-
for (const entry of this.thumbnailRenderCache.values()) {
|
|
1155
|
-
entry.result.bitmap.close();
|
|
1156
|
-
}
|
|
1157
|
-
this.thumbnailRenderCache.clear();
|
|
1158
|
-
// Close all cached preview bitmaps
|
|
1159
|
-
for (const entry of this.previewRenderCache.values()) {
|
|
1160
|
-
entry.result.bitmap.close();
|
|
1161
|
-
}
|
|
1162
|
-
this.previewRenderCache.clear();
|
|
1163
|
-
}
|
|
1164
|
-
processWorkQueue() {
|
|
1165
|
-
// Only one request at a time (WASM is single-threaded)
|
|
1166
|
-
if (this.currentWork)
|
|
1167
|
-
return;
|
|
1168
|
-
if (this.workQueue.length === 0)
|
|
1169
|
-
return;
|
|
1170
|
-
const item = this.workQueue.shift();
|
|
1171
|
-
const key = makeWorkKey(item);
|
|
1172
|
-
let promise;
|
|
1173
|
-
if (item.kind === "render") {
|
|
1174
|
-
const renderKey = makeRenderKey(item.docId, item.page, item.type, item.scale);
|
|
1175
|
-
const cache = this.getCache(item.type);
|
|
1176
|
-
// Double-check cache (might have been filled while queued)
|
|
1177
|
-
const cached = cache.get(renderKey);
|
|
1178
|
-
if (cached) {
|
|
1179
|
-
cached.lastAccess = Date.now();
|
|
1180
|
-
item.resolve(cached.result);
|
|
1181
|
-
// Continue processing queue
|
|
1182
|
-
this.processWorkQueue();
|
|
1183
|
-
return;
|
|
1184
|
-
}
|
|
1185
|
-
promise = this.doRender(item, renderKey);
|
|
1186
|
-
}
|
|
1187
|
-
else if (item.kind === "annotation") {
|
|
1188
|
-
promise = this.doAnnotation(item);
|
|
1189
|
-
}
|
|
1190
|
-
else if (item.kind === "text") {
|
|
1191
|
-
promise = this.doText(item);
|
|
1192
|
-
}
|
|
1193
|
-
else {
|
|
1194
|
-
promise = this.doFontUsageCheck(item);
|
|
1195
|
-
}
|
|
1196
|
-
this.currentWork = { key, promise };
|
|
1197
|
-
// Run the same cleanup whether the work resolved or rejected. Rejections
|
|
1198
|
-
// are already forwarded to the requester via req.reject inside doRender /
|
|
1199
|
-
// doAnnotation / doText, so consuming them here in onRejected is what
|
|
1200
|
-
// prevents an "unhandled promise" warning. If cleanup itself ever throws,
|
|
1201
|
-
// that still surfaces — only the already-handled work rejection is hidden.
|
|
1202
|
-
const onSettled = () => {
|
|
1203
|
-
this.currentWork = null;
|
|
1204
|
-
this.processWorkQueue();
|
|
1205
|
-
};
|
|
1206
|
-
promise.then(onSettled, onSettled);
|
|
1207
|
-
}
|
|
1208
|
-
async doRender(req, key) {
|
|
1209
|
-
const counter = this.getCounter(req.docId);
|
|
1210
|
-
const eventType = req.type === "thumbnail"
|
|
1211
|
-
? "renderThumbnail"
|
|
1212
|
-
: req.type === "preview"
|
|
1213
|
-
? "renderPreview"
|
|
1214
|
-
: "renderPage";
|
|
1215
|
-
const pageIndex = req.page - 1;
|
|
1216
|
-
const eventId = counter?.markStart(eventType, { pageIndex, scale: req.scale });
|
|
1217
|
-
try {
|
|
1218
|
-
const pageInfo = await this.getPageInfo(req.docId, pageIndex);
|
|
1219
|
-
const width = Math.round(pageInfo.width * req.scale);
|
|
1220
|
-
const height = Math.round(pageInfo.height * req.scale);
|
|
1221
|
-
// Send render request directly to worker
|
|
1222
|
-
const rendered = (await this.send({
|
|
1223
|
-
type: "renderPage",
|
|
1224
|
-
documentId: req.docId,
|
|
1225
|
-
pageIndex,
|
|
1226
|
-
width,
|
|
1227
|
-
height,
|
|
1228
|
-
}));
|
|
1229
|
-
const source = rendered.rgba;
|
|
1230
|
-
const clamped = source.buffer instanceof ArrayBuffer
|
|
1231
|
-
? new Uint8ClampedArray(source.buffer, source.byteOffset, source.byteLength)
|
|
1232
|
-
: new Uint8ClampedArray(source);
|
|
1233
|
-
const imageData = new ImageData(clamped, rendered.width, rendered.height);
|
|
1234
|
-
const bitmap = await createImageBitmap(imageData);
|
|
1235
|
-
const result = {
|
|
1236
|
-
bitmap,
|
|
1237
|
-
width: bitmap.width,
|
|
1238
|
-
height: bitmap.height,
|
|
1239
|
-
};
|
|
1240
|
-
// Add to cache
|
|
1241
|
-
this.addToRenderCache(req.type, key, result);
|
|
1242
|
-
if (eventId)
|
|
1243
|
-
counter?.markEnd(eventId);
|
|
1244
|
-
req.resolve(result);
|
|
1245
|
-
// Check for font usage changes after successful page render (debounced)
|
|
1246
|
-
if (req.type === "page") {
|
|
1247
|
-
this.scheduleFontUsageCheck(req.docId);
|
|
1248
|
-
}
|
|
1249
|
-
return result;
|
|
1250
|
-
}
|
|
1251
|
-
catch (error) {
|
|
1252
|
-
if (eventId)
|
|
1253
|
-
counter?.markEnd(eventId, false, error.message);
|
|
1254
|
-
if (isOOMError(error))
|
|
1255
|
-
this.handleOOM(error);
|
|
1256
|
-
req.reject(error instanceof Error ? error : new Error(String(error)));
|
|
1257
|
-
throw error;
|
|
1258
|
-
}
|
|
1259
|
-
}
|
|
1260
|
-
async doAnnotation(item) {
|
|
1261
|
-
const pageIndex = item.page - 1;
|
|
1262
|
-
const counter = this.getCounter(item.docId);
|
|
1263
|
-
const eventId = counter?.markStart("getPageAnnotations", { pageIndex });
|
|
1264
|
-
try {
|
|
1265
|
-
const response = (await this.send({
|
|
1266
|
-
type: "getPageAnnotations",
|
|
1267
|
-
documentId: item.docId,
|
|
1268
|
-
pageIndex,
|
|
1269
|
-
}));
|
|
1270
|
-
if (eventId)
|
|
1271
|
-
counter?.markEnd(eventId);
|
|
1272
|
-
item.resolve(response.annotations);
|
|
1273
|
-
return response.annotations;
|
|
1274
|
-
}
|
|
1275
|
-
catch (error) {
|
|
1276
|
-
if (eventId)
|
|
1277
|
-
counter?.markEnd(eventId, false, error.message);
|
|
1278
|
-
item.reject(error instanceof Error ? error : new Error(String(error)));
|
|
1279
|
-
throw error;
|
|
1280
|
-
}
|
|
1281
|
-
}
|
|
1282
|
-
async doText(item) {
|
|
1283
|
-
const pageIndex = item.page - 1;
|
|
1284
|
-
const counter = this.getCounter(item.docId);
|
|
1285
|
-
const eventId = counter?.markStart("getLayoutPage", { pageIndex });
|
|
1286
|
-
try {
|
|
1287
|
-
const response = (await this.send({
|
|
1288
|
-
type: "getLayoutPage",
|
|
1289
|
-
documentId: item.docId,
|
|
1290
|
-
pageIndex,
|
|
1291
|
-
}));
|
|
1292
|
-
if (eventId)
|
|
1293
|
-
counter?.markEnd(eventId);
|
|
1294
|
-
item.resolve(response.layout);
|
|
1295
|
-
return response.layout;
|
|
1296
|
-
}
|
|
1297
|
-
catch (error) {
|
|
1298
|
-
if (eventId)
|
|
1299
|
-
counter?.markEnd(eventId, false, error.message);
|
|
1300
|
-
item.reject(error instanceof Error ? error : new Error(String(error)));
|
|
1301
|
-
throw error;
|
|
1302
|
-
}
|
|
1303
|
-
}
|
|
1304
|
-
addToRenderCache(type, key, result) {
|
|
1305
|
-
const cache = this.getCache(type);
|
|
1306
|
-
if (type === "page") {
|
|
1307
|
-
const incoming = result.width * result.height * 4;
|
|
1308
|
-
// Evict oldest entries until the new bitmap fits in the byte budget.
|
|
1309
|
-
// Keep at least one entry so a single huge page still gets cached.
|
|
1310
|
-
while (cache.size > 0 && this.cacheTotalBytes(cache) + incoming > this.maxPageCacheBytes) {
|
|
1311
|
-
if (!this.evictLRU(cache))
|
|
1312
|
-
break;
|
|
1313
|
-
}
|
|
1314
|
-
}
|
|
1315
|
-
else {
|
|
1316
|
-
const maxSize = this.getMaxCacheSize(type);
|
|
1317
|
-
while (cache.size >= maxSize) {
|
|
1318
|
-
if (!this.evictLRU(cache))
|
|
1319
|
-
break;
|
|
1320
|
-
}
|
|
1321
|
-
}
|
|
1322
|
-
cache.set(key, {
|
|
1323
|
-
result,
|
|
1324
|
-
lastAccess: Date.now(),
|
|
1325
|
-
});
|
|
1326
|
-
}
|
|
1327
|
-
evictLRU(cache) {
|
|
1328
|
-
let oldest = null;
|
|
1329
|
-
let oldestTime = Infinity;
|
|
1330
|
-
for (const [key, entry] of cache) {
|
|
1331
|
-
if (entry.lastAccess < oldestTime) {
|
|
1332
|
-
oldestTime = entry.lastAccess;
|
|
1333
|
-
oldest = key;
|
|
1334
|
-
}
|
|
1335
|
-
}
|
|
1336
|
-
if (oldest) {
|
|
1337
|
-
const entry = cache.get(oldest);
|
|
1338
|
-
if (entry) {
|
|
1339
|
-
entry.result.bitmap.close();
|
|
1340
|
-
}
|
|
1341
|
-
cache.delete(oldest);
|
|
1342
|
-
return true;
|
|
1343
|
-
}
|
|
1344
|
-
return false;
|
|
1345
|
-
}
|
|
1346
|
-
/**
|
|
1347
|
-
* Terminate the worker.
|
|
1348
|
-
*/
|
|
1349
|
-
terminate() {
|
|
1350
|
-
this.destroyRenderResources();
|
|
1351
|
-
this.worker.terminate();
|
|
1352
|
-
for (const { reject } of this.pending.values()) {
|
|
1353
|
-
reject(new Error("Worker terminated"));
|
|
1354
|
-
}
|
|
1355
|
-
this.pending.clear();
|
|
1356
|
-
}
|
|
1357
|
-
send(request) {
|
|
1358
|
-
return new Promise((resolve, reject) => {
|
|
1359
|
-
const id = this.requestId++;
|
|
1360
|
-
this.pending.set(id, { resolve, reject });
|
|
1361
|
-
this.worker.postMessage({ ...request, _id: id });
|
|
1362
|
-
});
|
|
1363
|
-
}
|
|
1364
|
-
handleMessage(event) {
|
|
1365
|
-
const { _id, ...response } = event.data;
|
|
1366
|
-
if (_id === undefined)
|
|
1367
|
-
return;
|
|
1368
|
-
const pending = this.pending.get(_id);
|
|
1369
|
-
if (!pending)
|
|
1370
|
-
return;
|
|
1371
|
-
this.pending.delete(_id);
|
|
1372
|
-
if (response.success) {
|
|
1373
|
-
pending.resolve(response);
|
|
1374
|
-
}
|
|
1375
|
-
else {
|
|
1376
|
-
pending.reject(new Error(response.error));
|
|
1377
|
-
}
|
|
1378
|
-
}
|
|
1379
|
-
handleError(event) {
|
|
1380
|
-
console.error("Worker error:", event.message);
|
|
1381
|
-
}
|
|
1382
|
-
}
|
|
1383
|
-
//# sourceMappingURL=WorkerClient.js.map
|