web-doc 0.3.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/LICENSE-APACHE +201 -0
- package/LICENSE-MIT +21 -0
- package/README.md +148 -0
- package/THIRD_PARTY_NOTICES.md +20 -0
- package/bin/copy-assets.mjs +27 -0
- package/dist/abort.d.ts +1 -0
- package/dist/abort.js +18 -0
- package/dist/adapters/bitmap.d.ts +9 -0
- package/dist/adapters/bitmap.js +63 -0
- package/dist/adapters/csv-parser.d.ts +7 -0
- package/dist/adapters/csv-parser.js +124 -0
- package/dist/adapters/csv.d.ts +26 -0
- package/dist/adapters/csv.js +231 -0
- package/dist/adapters/image.d.ts +41 -0
- package/dist/adapters/image.js +198 -0
- package/dist/adapters/office.d.ts +211 -0
- package/dist/adapters/office.js +672 -0
- package/dist/adapters/pdf.d.ts +32 -0
- package/dist/adapters/pdf.js +429 -0
- package/dist/adapters/svg.d.ts +17 -0
- package/dist/adapters/svg.js +123 -0
- package/dist/assets/image/index.d.ts +75 -0
- package/dist/assets/image/index.js +289 -0
- package/dist/assets/image/index_bg.wasm +0 -0
- package/dist/assets/image/index_bg.wasm.d.ts +12 -0
- package/dist/assets/legacy/index.d.ts +54 -0
- package/dist/assets/legacy/index.js +306 -0
- package/dist/assets/legacy/index_bg.wasm +0 -0
- package/dist/assets/legacy/index_bg.wasm.d.ts +9 -0
- package/dist/assets/pdfjs/cmaps/78-EUC-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/78-EUC-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/78-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/78-RKSJ-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/78-RKSJ-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/78-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/78ms-RKSJ-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/78ms-RKSJ-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/83pv-RKSJ-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/90ms-RKSJ-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/90ms-RKSJ-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/90msp-RKSJ-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/90msp-RKSJ-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/90pv-RKSJ-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/90pv-RKSJ-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/Add-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/Add-RKSJ-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/Add-RKSJ-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/Add-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/Adobe-CNS1-0.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/Adobe-CNS1-1.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/Adobe-CNS1-2.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/Adobe-CNS1-3.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/Adobe-CNS1-4.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/Adobe-CNS1-5.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/Adobe-CNS1-6.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/Adobe-CNS1-UCS2.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/Adobe-GB1-0.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/Adobe-GB1-1.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/Adobe-GB1-2.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/Adobe-GB1-3.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/Adobe-GB1-4.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/Adobe-GB1-5.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/Adobe-GB1-UCS2.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/Adobe-Japan1-0.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/Adobe-Japan1-1.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/Adobe-Japan1-2.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/Adobe-Japan1-3.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/Adobe-Japan1-4.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/Adobe-Japan1-5.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/Adobe-Japan1-6.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/Adobe-Japan1-UCS2.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/Adobe-Korea1-0.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/Adobe-Korea1-1.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/Adobe-Korea1-2.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/Adobe-Korea1-UCS2.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/B5-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/B5-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/B5pc-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/B5pc-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/CNS-EUC-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/CNS-EUC-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/CNS1-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/CNS1-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/CNS2-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/CNS2-V.bcmap +3 -0
- package/dist/assets/pdfjs/cmaps/ETHK-B5-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/ETHK-B5-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/ETen-B5-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/ETen-B5-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/ETenms-B5-H.bcmap +3 -0
- package/dist/assets/pdfjs/cmaps/ETenms-B5-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/EUC-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/EUC-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/Ext-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/Ext-RKSJ-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/Ext-RKSJ-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/Ext-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/GB-EUC-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/GB-EUC-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/GB-H.bcmap +4 -0
- package/dist/assets/pdfjs/cmaps/GB-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/GBK-EUC-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/GBK-EUC-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/GBK2K-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/GBK2K-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/GBKp-EUC-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/GBKp-EUC-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/GBT-EUC-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/GBT-EUC-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/GBT-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/GBT-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/GBTpc-EUC-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/GBTpc-EUC-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/GBpc-EUC-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/GBpc-EUC-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/HKdla-B5-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/HKdla-B5-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/HKdlb-B5-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/HKdlb-B5-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/HKgccs-B5-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/HKgccs-B5-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/HKm314-B5-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/HKm314-B5-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/HKm471-B5-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/HKm471-B5-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/HKscs-B5-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/HKscs-B5-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/Hankaku.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/Hiragana.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/KSC-EUC-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/KSC-EUC-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/KSC-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/KSC-Johab-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/KSC-Johab-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/KSC-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/KSCms-UHC-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/KSCms-UHC-HW-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/KSCms-UHC-HW-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/KSCms-UHC-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/KSCpc-EUC-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/KSCpc-EUC-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/Katakana.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/LICENSE +36 -0
- package/dist/assets/pdfjs/cmaps/NWP-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/NWP-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/RKSJ-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/RKSJ-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/Roman.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniCNS-UCS2-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniCNS-UCS2-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniCNS-UTF16-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniCNS-UTF16-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniCNS-UTF32-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniCNS-UTF32-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniCNS-UTF8-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniCNS-UTF8-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniGB-UCS2-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniGB-UCS2-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniGB-UTF16-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniGB-UTF16-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniGB-UTF32-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniGB-UTF32-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniGB-UTF8-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniGB-UTF8-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniJIS-UCS2-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniJIS-UCS2-HW-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniJIS-UCS2-HW-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniJIS-UCS2-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniJIS-UTF16-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniJIS-UTF16-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniJIS-UTF32-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniJIS-UTF32-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniJIS-UTF8-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniJIS-UTF8-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniJIS2004-UTF16-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniJIS2004-UTF16-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniJIS2004-UTF32-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniJIS2004-UTF32-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniJIS2004-UTF8-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniJIS2004-UTF8-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniJISPro-UCS2-HW-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniJISPro-UCS2-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniJISPro-UTF8-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniJISX0213-UTF32-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniJISX0213-UTF32-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniJISX02132004-UTF32-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniJISX02132004-UTF32-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniKS-UCS2-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniKS-UCS2-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniKS-UTF16-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniKS-UTF16-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniKS-UTF32-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniKS-UTF32-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniKS-UTF8-H.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/UniKS-UTF8-V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/V.bcmap +0 -0
- package/dist/assets/pdfjs/cmaps/WP-Symbol.bcmap +0 -0
- package/dist/assets/pdfjs/iccs/CGATS001Compat-v2-micro.icc +0 -0
- package/dist/assets/pdfjs/iccs/LICENSE +116 -0
- package/dist/assets/pdfjs/standard_fonts/FoxitDingbats.pfb +0 -0
- package/dist/assets/pdfjs/standard_fonts/FoxitFixed.pfb +0 -0
- package/dist/assets/pdfjs/standard_fonts/FoxitFixedBold.pfb +0 -0
- package/dist/assets/pdfjs/standard_fonts/FoxitFixedBoldItalic.pfb +0 -0
- package/dist/assets/pdfjs/standard_fonts/FoxitFixedItalic.pfb +0 -0
- package/dist/assets/pdfjs/standard_fonts/FoxitSerif.pfb +0 -0
- package/dist/assets/pdfjs/standard_fonts/FoxitSerifBold.pfb +0 -0
- package/dist/assets/pdfjs/standard_fonts/FoxitSerifBoldItalic.pfb +0 -0
- package/dist/assets/pdfjs/standard_fonts/FoxitSerifItalic.pfb +0 -0
- package/dist/assets/pdfjs/standard_fonts/FoxitSymbol.pfb +0 -0
- package/dist/assets/pdfjs/standard_fonts/LICENSE_FOXIT +27 -0
- package/dist/assets/pdfjs/standard_fonts/LICENSE_LIBERATION +102 -0
- package/dist/assets/pdfjs/standard_fonts/LiberationSans-Bold.ttf +0 -0
- package/dist/assets/pdfjs/standard_fonts/LiberationSans-BoldItalic.ttf +0 -0
- package/dist/assets/pdfjs/standard_fonts/LiberationSans-Italic.ttf +0 -0
- package/dist/assets/pdfjs/standard_fonts/LiberationSans-Regular.ttf +0 -0
- package/dist/assets/pdfjs/wasm/LICENSE_JBIG2 +196 -0
- package/dist/assets/pdfjs/wasm/LICENSE_OPENJPEG +39 -0
- package/dist/assets/pdfjs/wasm/LICENSE_PDFJS_JBIG2 +13 -0
- package/dist/assets/pdfjs/wasm/LICENSE_PDFJS_OPENJPEG +22 -0
- package/dist/assets/pdfjs/wasm/LICENSE_PDFJS_QCMS +22 -0
- package/dist/assets/pdfjs/wasm/LICENSE_QCMS +21 -0
- package/dist/assets/pdfjs/wasm/jbig2.wasm +0 -0
- package/dist/assets/pdfjs/wasm/jbig2_nowasm_fallback.js +15 -0
- package/dist/assets/pdfjs/wasm/openjpeg.wasm +0 -0
- package/dist/assets/pdfjs/wasm/openjpeg_nowasm_fallback.js +17 -0
- package/dist/assets/pdfjs/wasm/qcms_bg.wasm +0 -0
- package/dist/assets/pdfjs/wasm/quickjs-eval.js +16 -0
- package/dist/assets/pdfjs/wasm/quickjs-eval.wasm +0 -0
- package/dist/client.d.ts +20 -0
- package/dist/client.js +82 -0
- package/dist/contracts.d.ts +379 -0
- package/dist/contracts.js +22 -0
- package/dist/csv-worker.d.ts +1 -0
- package/dist/csv-worker.js +17 -0
- package/dist/detect.d.ts +15 -0
- package/dist/detect.js +290 -0
- package/dist/errors.d.ts +14 -0
- package/dist/errors.js +40 -0
- package/dist/font-manifest.d.ts +11 -0
- package/dist/font-manifest.js +31 -0
- package/dist/fonts/OFL-1.1.txt +88 -0
- package/dist/fonts/THIRD_PARTY_NOTICES.md +10 -0
- package/dist/fonts/manifest.json +83 -0
- package/dist/fonts/noto-sans-arabic.woff2 +0 -0
- package/dist/fonts/noto-sans-bengali.woff2 +0 -0
- package/dist/fonts/noto-sans-cjk.woff2 +0 -0
- package/dist/fonts/noto-sans-devanagari.woff2 +0 -0
- package/dist/fonts/noto-sans-gujarati.woff2 +0 -0
- package/dist/fonts/noto-sans-gurmukhi.woff2 +0 -0
- package/dist/fonts/noto-sans-japanese.woff2 +0 -0
- package/dist/fonts/noto-sans-kannada.woff2 +0 -0
- package/dist/fonts/noto-sans-korean.woff2 +0 -0
- package/dist/fonts/noto-sans-latin-cyrillic.woff2 +0 -0
- package/dist/fonts/noto-sans-malayalam.woff2 +0 -0
- package/dist/fonts/noto-sans-odia.woff2 +0 -0
- package/dist/fonts/noto-sans-tamil.woff2 +0 -0
- package/dist/fonts/noto-sans-telugu.woff2 +0 -0
- package/dist/fonts.d.ts +20 -0
- package/dist/fonts.js +238 -0
- package/dist/format.d.ts +1 -0
- package/dist/format.js +1 -0
- package/dist/headless.d.ts +18 -0
- package/dist/headless.js +18 -0
- package/dist/i18n.d.ts +4 -0
- package/dist/i18n.js +55 -0
- package/dist/image-worker.d.ts +1 -0
- package/dist/image-worker.js +41 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +29 -0
- package/dist/interaction.d.ts +24 -0
- package/dist/interaction.js +183 -0
- package/dist/legacy-converter-worker.d.ts +1 -0
- package/dist/legacy-converter-worker.js +19 -0
- package/dist/limits.d.ts +4 -0
- package/dist/limits.js +162 -0
- package/dist/registry.d.ts +8 -0
- package/dist/registry.js +35 -0
- package/dist/render-scheduler.d.ts +8 -0
- package/dist/render-scheduler.js +63 -0
- package/dist/source.d.ts +14 -0
- package/dist/source.js +116 -0
- package/dist/spreadsheet-viewport.d.ts +34 -0
- package/dist/spreadsheet-viewport.js +1035 -0
- package/dist/styles.css +137 -0
- package/dist/ui-styles.d.ts +1 -0
- package/dist/ui-styles.js +139 -0
- package/dist/ui.d.ts +8 -0
- package/dist/ui.js +390 -0
- package/dist/viewer.d.ts +52 -0
- package/dist/viewer.js +901 -0
- package/dist/viewport.d.ts +54 -0
- package/dist/viewport.js +907 -0
- package/dist/worker-adapter.d.ts +24 -0
- package/dist/worker-adapter.js +97 -0
- package/dist/worker-client.d.ts +23 -0
- package/dist/worker-client.js +105 -0
- package/dist/worker-endpoint.d.ts +13 -0
- package/dist/worker-endpoint.js +57 -0
- package/dist/worker-protocol.d.ts +48 -0
- package/dist/worker-protocol.js +14 -0
- package/dist/worker.d.ts +4 -0
- package/dist/worker.js +4 -0
- package/dist/workers/csv-worker.js +160 -0
- package/dist/workers/image-worker.js +41 -0
- package/dist/workers/legacy-converter-worker.js +19 -0
- package/dist/workers/pdf.worker.min.mjs +28 -0
- package/package.json +74 -0
|
@@ -0,0 +1,672 @@
|
|
|
1
|
+
import { abortError, ViewerError } from "../errors.js";
|
|
2
|
+
import { enforceContainerLimits } from "../limits.js";
|
|
3
|
+
const MODERN_FORMATS = [
|
|
4
|
+
"docx",
|
|
5
|
+
"docm",
|
|
6
|
+
"xlsx",
|
|
7
|
+
"xlsm",
|
|
8
|
+
"pptx",
|
|
9
|
+
"pptm",
|
|
10
|
+
"ppsx",
|
|
11
|
+
];
|
|
12
|
+
const LEGACY_FORMATS = ["doc", "xls", "ppt"];
|
|
13
|
+
const DEFAULT_COLUMN_WIDTH = 64;
|
|
14
|
+
const DEFAULT_ROW_HEIGHT = 20;
|
|
15
|
+
const ROW_HEADER_WIDTH = 50;
|
|
16
|
+
const COLUMN_HEADER_HEIGHT = 22;
|
|
17
|
+
export class OfficeDocumentAdapter {
|
|
18
|
+
id = "office";
|
|
19
|
+
formats = [...MODERN_FORMATS, ...LEGACY_FORMATS];
|
|
20
|
+
#options;
|
|
21
|
+
constructor(options = {}) {
|
|
22
|
+
this.#options = options;
|
|
23
|
+
}
|
|
24
|
+
async open(input, context) {
|
|
25
|
+
throwIfAborted(context.signal);
|
|
26
|
+
let format = context.format;
|
|
27
|
+
let data = input;
|
|
28
|
+
const warnings = [];
|
|
29
|
+
if (isLegacyFormat(format)) {
|
|
30
|
+
context.reportProgress({ phase: "converting", loaded: 0, total: 1 });
|
|
31
|
+
data = await this.#convertLegacy(input, format, context);
|
|
32
|
+
throwIfAborted(context.signal);
|
|
33
|
+
const modern = modernFormatFor(format);
|
|
34
|
+
enforceContainerLimits(data, modern, context.limits);
|
|
35
|
+
warnings.push({
|
|
36
|
+
code: "fidelity-degraded",
|
|
37
|
+
message: `${format.toUpperCase()} was converted in memory to ${modern.toUpperCase()}; unsupported legacy features may differ`,
|
|
38
|
+
details: { sourceFormat: format, normalizedFormat: modern },
|
|
39
|
+
});
|
|
40
|
+
format = modern;
|
|
41
|
+
context.reportProgress({
|
|
42
|
+
phase: "converting",
|
|
43
|
+
loaded: 1,
|
|
44
|
+
total: 1,
|
|
45
|
+
ratio: 1,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
if (isMacroFormat(context.format))
|
|
49
|
+
warnings.push({
|
|
50
|
+
code: "unsupported-feature",
|
|
51
|
+
message: "VBA content is ignored and is never executed",
|
|
52
|
+
details: { feature: "vba", format: context.format },
|
|
53
|
+
});
|
|
54
|
+
context.reportProgress({ phase: "parsing", loaded: 0, total: 1 });
|
|
55
|
+
const engineOptions = {
|
|
56
|
+
useGoogleFonts: false,
|
|
57
|
+
maxZipEntryBytes: context.limits.maxZipEntryBytes,
|
|
58
|
+
mode: "main",
|
|
59
|
+
};
|
|
60
|
+
const buffer = exactArrayBuffer(data);
|
|
61
|
+
try {
|
|
62
|
+
const kind = kindFor(format);
|
|
63
|
+
if (kind === "document") {
|
|
64
|
+
const backend = await this.#loadDocx(buffer, engineOptions);
|
|
65
|
+
throwIfAborted(context.signal, backend);
|
|
66
|
+
context.reportProgress({
|
|
67
|
+
phase: "parsing",
|
|
68
|
+
loaded: 1,
|
|
69
|
+
total: 1,
|
|
70
|
+
ratio: 1,
|
|
71
|
+
});
|
|
72
|
+
return { kind, format: context.format, backend, warnings };
|
|
73
|
+
}
|
|
74
|
+
if (kind === "presentation") {
|
|
75
|
+
const backend = await this.#loadPptx(buffer, engineOptions);
|
|
76
|
+
throwIfAborted(context.signal, backend);
|
|
77
|
+
context.reportProgress({
|
|
78
|
+
phase: "parsing",
|
|
79
|
+
loaded: 1,
|
|
80
|
+
total: 1,
|
|
81
|
+
ratio: 1,
|
|
82
|
+
});
|
|
83
|
+
return { kind, format: context.format, backend, warnings };
|
|
84
|
+
}
|
|
85
|
+
const backend = await this.#loadXlsx(buffer, engineOptions);
|
|
86
|
+
throwIfAborted(context.signal, backend);
|
|
87
|
+
const worksheets = [];
|
|
88
|
+
const sheets = [];
|
|
89
|
+
let missingFormulaCaches = 0;
|
|
90
|
+
for (let sheetIndex = 0; sheetIndex < backend.sheetCount; sheetIndex += 1) {
|
|
91
|
+
throwIfAborted(context.signal, backend);
|
|
92
|
+
const worksheet = await backend.getWorksheet(sheetIndex);
|
|
93
|
+
const normalized = normalizeWorksheet(worksheet);
|
|
94
|
+
missingFormulaCaches += normalized.missingFormulaCaches;
|
|
95
|
+
worksheets.push(worksheet);
|
|
96
|
+
sheets.push(normalized.info);
|
|
97
|
+
if (worksheet.parseError)
|
|
98
|
+
warnings.push({
|
|
99
|
+
code: "fidelity-degraded",
|
|
100
|
+
message: `Sheet ${worksheet.name} was only partially parsed`,
|
|
101
|
+
details: { sheetIndex, reason: worksheet.parseError },
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
if (missingFormulaCaches > 0)
|
|
105
|
+
warnings.push({
|
|
106
|
+
code: "fidelity-degraded",
|
|
107
|
+
message: `${missingFormulaCaches} formula cell(s) had no cached result; formula text is shown without calculation`,
|
|
108
|
+
details: { feature: "formula-cache", count: missingFormulaCaches },
|
|
109
|
+
});
|
|
110
|
+
context.reportProgress({
|
|
111
|
+
phase: "parsing",
|
|
112
|
+
loaded: 1,
|
|
113
|
+
total: 1,
|
|
114
|
+
ratio: 1,
|
|
115
|
+
});
|
|
116
|
+
return {
|
|
117
|
+
kind,
|
|
118
|
+
format: context.format,
|
|
119
|
+
backend,
|
|
120
|
+
warnings,
|
|
121
|
+
worksheets,
|
|
122
|
+
sheets,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
throw normalizeOfficeError(error);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
async getInfo(handle) {
|
|
130
|
+
if (handle.kind === "document")
|
|
131
|
+
return {
|
|
132
|
+
format: handle.format,
|
|
133
|
+
unit: "page",
|
|
134
|
+
pageCount: handle.backend.pageCount,
|
|
135
|
+
pageSizes: Array.from({ length: handle.backend.pageCount }, (_, pageIndex) => {
|
|
136
|
+
const page = handle.backend.pageSize(pageIndex);
|
|
137
|
+
return {
|
|
138
|
+
width: (page.widthPt * 96) / 72,
|
|
139
|
+
height: (page.heightPt * 96) / 72,
|
|
140
|
+
};
|
|
141
|
+
}),
|
|
142
|
+
warnings: handle.warnings,
|
|
143
|
+
};
|
|
144
|
+
if (handle.kind === "presentation")
|
|
145
|
+
return {
|
|
146
|
+
format: handle.format,
|
|
147
|
+
unit: "slide",
|
|
148
|
+
pageCount: handle.backend.slideCount,
|
|
149
|
+
pageSizes: Array.from({ length: handle.backend.slideCount }, () => ({
|
|
150
|
+
width: handle.backend.slideWidth / 9525,
|
|
151
|
+
height: handle.backend.slideHeight / 9525,
|
|
152
|
+
})),
|
|
153
|
+
warnings: handle.warnings,
|
|
154
|
+
};
|
|
155
|
+
return {
|
|
156
|
+
format: handle.format,
|
|
157
|
+
unit: "sheet",
|
|
158
|
+
pageCount: handle.backend.sheetCount,
|
|
159
|
+
sheetNames: handle.backend.sheetNames,
|
|
160
|
+
sheets: handle.sheets,
|
|
161
|
+
warnings: handle.warnings,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
async render(handle, target, viewport, signal) {
|
|
165
|
+
throwIfAborted(signal);
|
|
166
|
+
assertUnitIndex(viewport.pageIndex, await this.getInfo(handle));
|
|
167
|
+
try {
|
|
168
|
+
if (handle.kind === "document") {
|
|
169
|
+
const page = handle.backend.pageSize(viewport.pageIndex);
|
|
170
|
+
await handle.backend.renderPage(target, viewport.pageIndex, {
|
|
171
|
+
width: (page.widthPt * 96 * viewport.zoom) / 72,
|
|
172
|
+
dpr: viewport.devicePixelRatio,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
else if (handle.kind === "presentation") {
|
|
176
|
+
await handle.backend.renderSlide(target, viewport.pageIndex, {
|
|
177
|
+
width: (handle.backend.slideWidth / 9525) * viewport.zoom,
|
|
178
|
+
dpr: viewport.devicePixelRatio,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
const range = normalizeSheetRange(viewport.sheetRange);
|
|
183
|
+
const worksheet = handle.worksheets[viewport.pageIndex];
|
|
184
|
+
applyColumnWidthOverrides(worksheet, viewport.columnWidths);
|
|
185
|
+
await handle.backend.renderViewport(target, viewport.pageIndex, {
|
|
186
|
+
row: range.row,
|
|
187
|
+
col: range.column,
|
|
188
|
+
rows: range.rowCount,
|
|
189
|
+
cols: range.columnCount,
|
|
190
|
+
}, {
|
|
191
|
+
width: viewport.width ??
|
|
192
|
+
canvasCssWidth(target, viewport.devicePixelRatio),
|
|
193
|
+
height: viewport.height ??
|
|
194
|
+
canvasCssHeight(target, viewport.devicePixelRatio),
|
|
195
|
+
dpr: viewport.devicePixelRatio,
|
|
196
|
+
cellScale: viewport.zoom,
|
|
197
|
+
freezeRows: worksheet.freezeRows,
|
|
198
|
+
freezeCols: worksheet.freezeCols,
|
|
199
|
+
...(viewport.scrollOffsetX === undefined
|
|
200
|
+
? {}
|
|
201
|
+
: { scrollOffsetX: viewport.scrollOffsetX }),
|
|
202
|
+
...(viewport.scrollOffsetY === undefined
|
|
203
|
+
? {}
|
|
204
|
+
: { scrollOffsetY: viewport.scrollOffsetY }),
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
throwIfAborted(signal);
|
|
208
|
+
}
|
|
209
|
+
catch (error) {
|
|
210
|
+
if (signal?.aborted)
|
|
211
|
+
throw abortError();
|
|
212
|
+
throw error instanceof ViewerError
|
|
213
|
+
? error
|
|
214
|
+
: new ViewerError("render-failed", "Office rendering failed", {
|
|
215
|
+
cause: error,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
async getTextMap(handle, pageIndex, signal) {
|
|
220
|
+
throwIfAborted(signal);
|
|
221
|
+
assertUnitIndex(pageIndex, await this.getInfo(handle));
|
|
222
|
+
if (handle.kind === "document") {
|
|
223
|
+
const size = handle.backend.pageSize(pageIndex);
|
|
224
|
+
const coordinateWidth = (size.widthPt * 96) / 72;
|
|
225
|
+
const coordinateHeight = (size.heightPt * 96) / 72;
|
|
226
|
+
const runs = await handle.backend.collectPageRuns(pageIndex, {
|
|
227
|
+
width: coordinateWidth,
|
|
228
|
+
dpr: 1,
|
|
229
|
+
});
|
|
230
|
+
let logicalOffset = 0;
|
|
231
|
+
return runs.map((run) => {
|
|
232
|
+
const logicalStart = logicalOffset;
|
|
233
|
+
logicalOffset += run.text.length;
|
|
234
|
+
return {
|
|
235
|
+
text: run.text,
|
|
236
|
+
x: run.x,
|
|
237
|
+
y: run.y,
|
|
238
|
+
width: run.w,
|
|
239
|
+
height: run.h,
|
|
240
|
+
font: run.font,
|
|
241
|
+
fontSize: run.fontSize,
|
|
242
|
+
...(run.letterSpacingPx === undefined
|
|
243
|
+
? {}
|
|
244
|
+
: { letterSpacingPx: run.letterSpacingPx }),
|
|
245
|
+
...(run.transform === undefined ? {} : { transform: run.transform }),
|
|
246
|
+
...(run.eastAsianVert === undefined
|
|
247
|
+
? {}
|
|
248
|
+
: { eastAsianVert: run.eastAsianVert }),
|
|
249
|
+
textLayer: "docx",
|
|
250
|
+
coordinateWidth,
|
|
251
|
+
coordinateHeight,
|
|
252
|
+
logicalStart,
|
|
253
|
+
logicalEnd: logicalOffset,
|
|
254
|
+
...fontProperties(run.font),
|
|
255
|
+
...safeHyperlink(run.hyperlink, (ref) => handle.backend.getBookmarkPage?.(ref)),
|
|
256
|
+
direction: textDirection(run.text),
|
|
257
|
+
};
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
if (handle.kind === "presentation") {
|
|
261
|
+
const width = handle.backend.slideWidth / 9525;
|
|
262
|
+
const runs = await handle.backend.collectSlideRuns(pageIndex, width);
|
|
263
|
+
return runs.map((run) => ({
|
|
264
|
+
text: run.text,
|
|
265
|
+
x: run.shapeX + run.inShapeX,
|
|
266
|
+
y: run.shapeY + run.inShapeY,
|
|
267
|
+
width: run.w,
|
|
268
|
+
height: run.h,
|
|
269
|
+
...safeHyperlink(run.hyperlink, (ref) => handle.backend.resolveInternalTarget?.(ref, pageIndex)),
|
|
270
|
+
direction: textDirection(run.text),
|
|
271
|
+
}));
|
|
272
|
+
}
|
|
273
|
+
const worksheet = handle.worksheets[pageIndex];
|
|
274
|
+
throwIfAborted(signal);
|
|
275
|
+
const info = handle.sheets[pageIndex];
|
|
276
|
+
const hyperlinks = spreadsheetHyperlinks(worksheet);
|
|
277
|
+
const result = [];
|
|
278
|
+
for (const row of worksheet.rows) {
|
|
279
|
+
for (const cell of row.cells) {
|
|
280
|
+
throwIfAborted(signal);
|
|
281
|
+
const text = handle.backend.cellText?.(worksheet, cell) ?? cellText(cell);
|
|
282
|
+
if (!text)
|
|
283
|
+
continue;
|
|
284
|
+
const width = axisSize(cell.col, info.defaultColumnWidth ?? DEFAULT_COLUMN_WIDTH, info.columnWidths);
|
|
285
|
+
const height = axisSize(cell.row, info.defaultRowHeight ?? DEFAULT_ROW_HEIGHT, info.rowHeights);
|
|
286
|
+
result.push({
|
|
287
|
+
text,
|
|
288
|
+
x: (info.rowHeaderWidth ?? ROW_HEADER_WIDTH) +
|
|
289
|
+
axisOffset(cell.col, info.defaultColumnWidth ?? DEFAULT_COLUMN_WIDTH, info.columnWidths) +
|
|
290
|
+
4,
|
|
291
|
+
y: (info.columnHeaderHeight ?? COLUMN_HEADER_HEIGHT) +
|
|
292
|
+
axisOffset(cell.row, info.defaultRowHeight ?? DEFAULT_ROW_HEIGHT, info.rowHeights) +
|
|
293
|
+
2,
|
|
294
|
+
width: Math.max(0, width - 8),
|
|
295
|
+
height: Math.max(0, height - 4),
|
|
296
|
+
row: cell.row,
|
|
297
|
+
column: cell.col,
|
|
298
|
+
...(hyperlinks.get(`${cell.row}:${cell.col}`)
|
|
299
|
+
? { hyperlink: hyperlinks.get(`${cell.row}:${cell.col}`) }
|
|
300
|
+
: {}),
|
|
301
|
+
direction: textDirection(text),
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
return result;
|
|
306
|
+
}
|
|
307
|
+
close(handle) {
|
|
308
|
+
handle.backend.destroy();
|
|
309
|
+
}
|
|
310
|
+
async #convertLegacy(data, format, context) {
|
|
311
|
+
if (this.#options.legacy?.convert)
|
|
312
|
+
return this.#options.legacy.convert(data, format, context);
|
|
313
|
+
if (typeof Worker === "undefined")
|
|
314
|
+
throw new ViewerError("internal", "Legacy Office conversion requires a browser Worker or an injected converter");
|
|
315
|
+
const workerUrl = this.#options.legacy?.workerUrl
|
|
316
|
+
? new URL(this.#options.legacy.workerUrl, context.assetBaseUrl)
|
|
317
|
+
: context.assetBaseUrl
|
|
318
|
+
? new URL("workers/legacy-converter-worker.js", context.assetBaseUrl)
|
|
319
|
+
: new URL("../legacy-converter-worker.js", import.meta.url);
|
|
320
|
+
const moduleUrl = this.#options.legacy?.moduleUrl
|
|
321
|
+
? new URL(this.#options.legacy.moduleUrl, context.assetBaseUrl)
|
|
322
|
+
: context.assetBaseUrl
|
|
323
|
+
? new URL("assets/legacy/index.js", context.assetBaseUrl)
|
|
324
|
+
: new URL("../assets/legacy/index.js", import.meta.url);
|
|
325
|
+
return convertInWorker(data, format, workerUrl, moduleUrl, context.signal, context.limits.maxOperationMs);
|
|
326
|
+
}
|
|
327
|
+
async #loadDocx(data, options) {
|
|
328
|
+
if (this.#options.engines?.docx)
|
|
329
|
+
return this.#options.engines.docx(data, options);
|
|
330
|
+
const { DocxDocument } = await import("@silurus/ooxml/docx");
|
|
331
|
+
return DocxDocument.load(data, options);
|
|
332
|
+
}
|
|
333
|
+
async #loadXlsx(data, options) {
|
|
334
|
+
if (this.#options.engines?.xlsx)
|
|
335
|
+
return this.#options.engines.xlsx(data, options);
|
|
336
|
+
const { XlsxWorkbook } = await import("@silurus/ooxml/xlsx");
|
|
337
|
+
return XlsxWorkbook.load(data, options);
|
|
338
|
+
}
|
|
339
|
+
async #loadPptx(data, options) {
|
|
340
|
+
if (this.#options.engines?.pptx)
|
|
341
|
+
return this.#options.engines.pptx(data, options);
|
|
342
|
+
const { PptxPresentation } = await import("@silurus/ooxml/pptx");
|
|
343
|
+
return PptxPresentation.load(data, options);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
export function createOfficeAdapter(options = {}) {
|
|
347
|
+
return new OfficeDocumentAdapter(options);
|
|
348
|
+
}
|
|
349
|
+
export function sanitizeOfficeHyperlink(target) {
|
|
350
|
+
if (!target)
|
|
351
|
+
return undefined;
|
|
352
|
+
if (target.kind === "internal" && target.ref)
|
|
353
|
+
return {
|
|
354
|
+
kind: "internal",
|
|
355
|
+
ref: target.ref,
|
|
356
|
+
...(target.slideIndex === undefined
|
|
357
|
+
? {}
|
|
358
|
+
: { pageIndex: target.slideIndex }),
|
|
359
|
+
};
|
|
360
|
+
if (target.kind !== "external" || !target.url)
|
|
361
|
+
return undefined;
|
|
362
|
+
try {
|
|
363
|
+
const url = new URL(target.url);
|
|
364
|
+
if (!["http:", "https:", "mailto:", "tel:"].includes(url.protocol))
|
|
365
|
+
return undefined;
|
|
366
|
+
return { kind: "external", url: url.href };
|
|
367
|
+
}
|
|
368
|
+
catch {
|
|
369
|
+
return undefined;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
function safeHyperlink(target, resolveInternal) {
|
|
373
|
+
const sanitized = sanitizeOfficeHyperlink(target);
|
|
374
|
+
if (!sanitized)
|
|
375
|
+
return {};
|
|
376
|
+
if (sanitized.kind === "external")
|
|
377
|
+
return { hyperlink: sanitized };
|
|
378
|
+
const pageIndex = sanitized.pageIndex ?? resolveInternal(sanitized.ref);
|
|
379
|
+
return {
|
|
380
|
+
hyperlink: {
|
|
381
|
+
...sanitized,
|
|
382
|
+
...(pageIndex === undefined ? {} : { pageIndex }),
|
|
383
|
+
},
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
function fontProperties(font) {
|
|
387
|
+
const family = font.match(/\b\d+(?:\.\d+)?px(?:\/[^\s]+)?\s+(.+)$/)?.[1];
|
|
388
|
+
const weight = font.match(/(?:^|\s)([1-9]00|bold)(?=\s)/)?.[1];
|
|
389
|
+
const style = font.match(/(?:^|\s)(italic|oblique)(?=\s)/)?.[1];
|
|
390
|
+
return {
|
|
391
|
+
...(family
|
|
392
|
+
? {
|
|
393
|
+
fontFamily: family
|
|
394
|
+
.split(",", 1)[0]
|
|
395
|
+
.trim()
|
|
396
|
+
.replace(/^['"]|['"]$/g, ""),
|
|
397
|
+
}
|
|
398
|
+
: {}),
|
|
399
|
+
...(weight ? { fontWeight: weight === "bold" ? 700 : Number(weight) } : {}),
|
|
400
|
+
...(style ? { fontStyle: style } : {}),
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
function normalizeWorksheet(worksheet) {
|
|
404
|
+
let missingFormulaCaches = 0;
|
|
405
|
+
let maxRow = 0;
|
|
406
|
+
let maxColumn = 0;
|
|
407
|
+
for (const row of worksheet.rows) {
|
|
408
|
+
maxRow = Math.max(maxRow, row.index);
|
|
409
|
+
for (const cell of row.cells) {
|
|
410
|
+
maxRow = Math.max(maxRow, cell.row);
|
|
411
|
+
maxColumn = Math.max(maxColumn, cell.col);
|
|
412
|
+
if (cell.formula === undefined)
|
|
413
|
+
continue;
|
|
414
|
+
if (cell.value.type === "empty") {
|
|
415
|
+
missingFormulaCaches += 1;
|
|
416
|
+
cell.value = { type: "text", text: `=${cell.formula}` };
|
|
417
|
+
}
|
|
418
|
+
delete cell.formula;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
for (const range of worksheet.mergeCells) {
|
|
422
|
+
maxRow = Math.max(maxRow, range.bottom);
|
|
423
|
+
maxColumn = Math.max(maxColumn, range.right);
|
|
424
|
+
}
|
|
425
|
+
for (const drawing of [
|
|
426
|
+
...(worksheet.images ?? []),
|
|
427
|
+
...(worksheet.charts ?? []),
|
|
428
|
+
]) {
|
|
429
|
+
maxRow = Math.max(maxRow, drawing.fromRow + 1, drawing.toRow + 1);
|
|
430
|
+
maxColumn = Math.max(maxColumn, drawing.fromCol + 1, drawing.toCol + 1);
|
|
431
|
+
}
|
|
432
|
+
const defaultColumnWidth = columnWidthToPixels(worksheet.defaultColWidth ?? 8.43);
|
|
433
|
+
const defaultRowHeight = pointsToPixels(worksheet.defaultRowHeight ?? 15);
|
|
434
|
+
const columnWidths = {};
|
|
435
|
+
for (const [rawIndex, rawWidth] of Object.entries(worksheet.colWidths ?? {})) {
|
|
436
|
+
const index = Number(rawIndex);
|
|
437
|
+
if (!Number.isInteger(index) || index < 1)
|
|
438
|
+
continue;
|
|
439
|
+
columnWidths[index] = worksheet.colHidden?.[index]
|
|
440
|
+
? 0
|
|
441
|
+
: columnWidthToPixels(rawWidth);
|
|
442
|
+
maxColumn = Math.max(maxColumn, index);
|
|
443
|
+
}
|
|
444
|
+
for (const [rawIndex, hidden] of Object.entries(worksheet.colHidden ?? {})) {
|
|
445
|
+
const index = Number(rawIndex);
|
|
446
|
+
if (!hidden || !Number.isInteger(index) || index < 1)
|
|
447
|
+
continue;
|
|
448
|
+
columnWidths[index] = 0;
|
|
449
|
+
maxColumn = Math.max(maxColumn, index);
|
|
450
|
+
}
|
|
451
|
+
const rowHeights = {};
|
|
452
|
+
for (const [rawIndex, rawHeight] of Object.entries(worksheet.rowHeights ?? {})) {
|
|
453
|
+
const index = Number(rawIndex);
|
|
454
|
+
if (!Number.isInteger(index) || index < 1)
|
|
455
|
+
continue;
|
|
456
|
+
rowHeights[index] = pointsToPixels(rawHeight);
|
|
457
|
+
maxRow = Math.max(maxRow, index);
|
|
458
|
+
}
|
|
459
|
+
for (const row of worksheet.rows) {
|
|
460
|
+
if (row.hidden)
|
|
461
|
+
rowHeights[row.index] = 0;
|
|
462
|
+
else if (row.height !== undefined && row.height !== null)
|
|
463
|
+
rowHeights[row.index] = pointsToPixels(row.height);
|
|
464
|
+
}
|
|
465
|
+
return {
|
|
466
|
+
missingFormulaCaches,
|
|
467
|
+
info: {
|
|
468
|
+
name: worksheet.name,
|
|
469
|
+
frozenRows: worksheet.freezeRows,
|
|
470
|
+
frozenColumns: worksheet.freezeCols,
|
|
471
|
+
mergedRanges: worksheet.mergeCells.map((range) => ({
|
|
472
|
+
startRow: range.top,
|
|
473
|
+
startColumn: range.left,
|
|
474
|
+
endRow: range.bottom,
|
|
475
|
+
endColumn: range.right,
|
|
476
|
+
})),
|
|
477
|
+
maxRow,
|
|
478
|
+
maxColumn,
|
|
479
|
+
defaultColumnWidth,
|
|
480
|
+
defaultRowHeight,
|
|
481
|
+
columnWidths,
|
|
482
|
+
rowHeights,
|
|
483
|
+
rowHeaderWidth: ROW_HEADER_WIDTH,
|
|
484
|
+
columnHeaderHeight: COLUMN_HEADER_HEIGHT,
|
|
485
|
+
rightToLeft: worksheet.rightToLeft ?? false,
|
|
486
|
+
},
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
function pointsToPixels(points) {
|
|
490
|
+
return Math.max(0, Math.round(Math.max(0, points) * (4 / 3)));
|
|
491
|
+
}
|
|
492
|
+
function columnWidthToPixels(width) {
|
|
493
|
+
const maximumDigitWidth = 8;
|
|
494
|
+
const safeWidth = Math.max(0, Number.isFinite(width) ? width : 0);
|
|
495
|
+
return Math.max(0, Math.trunc(((256 * safeWidth + Math.trunc(128 / maximumDigitWidth)) / 256) *
|
|
496
|
+
maximumDigitWidth));
|
|
497
|
+
}
|
|
498
|
+
function applyColumnWidthOverrides(worksheet, overrides) {
|
|
499
|
+
if (!overrides)
|
|
500
|
+
return;
|
|
501
|
+
const widths = (worksheet.colWidths ??= {});
|
|
502
|
+
for (const [rawIndex, rawWidth] of Object.entries(overrides)) {
|
|
503
|
+
const index = Number(rawIndex);
|
|
504
|
+
const width = Number(rawWidth);
|
|
505
|
+
if (!Number.isInteger(index) || index < 1 || !Number.isFinite(width))
|
|
506
|
+
continue;
|
|
507
|
+
widths[index] = pixelsToColumnWidth(width);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
function pixelsToColumnWidth(pixels) {
|
|
511
|
+
const maximumDigitWidth = 8;
|
|
512
|
+
return Math.max(0, pixels) / maximumDigitWidth;
|
|
513
|
+
}
|
|
514
|
+
function axisSize(index, defaultSize, overrides) {
|
|
515
|
+
return overrides?.[index] ?? defaultSize;
|
|
516
|
+
}
|
|
517
|
+
function axisOffset(index, defaultSize, overrides) {
|
|
518
|
+
const before = Math.max(0, index - 1);
|
|
519
|
+
let offset = before * defaultSize;
|
|
520
|
+
for (const [rawIndex, size] of Object.entries(overrides ?? {})) {
|
|
521
|
+
const overrideIndex = Number(rawIndex);
|
|
522
|
+
if (overrideIndex >= 1 && overrideIndex < index)
|
|
523
|
+
offset += size - defaultSize;
|
|
524
|
+
}
|
|
525
|
+
return offset;
|
|
526
|
+
}
|
|
527
|
+
function cellText(cell) {
|
|
528
|
+
switch (cell.value.type) {
|
|
529
|
+
case "text":
|
|
530
|
+
return cell.value.text;
|
|
531
|
+
case "number":
|
|
532
|
+
return String(cell.value.number);
|
|
533
|
+
case "bool":
|
|
534
|
+
return cell.value.bool ? "TRUE" : "FALSE";
|
|
535
|
+
case "error":
|
|
536
|
+
return cell.value.error;
|
|
537
|
+
default:
|
|
538
|
+
return "";
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
function spreadsheetHyperlinks(worksheet) {
|
|
542
|
+
const result = new Map();
|
|
543
|
+
for (const link of worksheet.hyperlinks ?? []) {
|
|
544
|
+
const target = link.location
|
|
545
|
+
? { kind: "internal", ref: link.location }
|
|
546
|
+
: link.url
|
|
547
|
+
? { kind: "external", url: link.url }
|
|
548
|
+
: undefined;
|
|
549
|
+
const sanitized = sanitizeOfficeHyperlink(target);
|
|
550
|
+
if (sanitized)
|
|
551
|
+
result.set(`${link.row}:${link.col}`, sanitized);
|
|
552
|
+
}
|
|
553
|
+
return result;
|
|
554
|
+
}
|
|
555
|
+
function convertInWorker(data, format, workerUrl, moduleUrl, signal, timeoutMs) {
|
|
556
|
+
return new Promise((resolve, reject) => {
|
|
557
|
+
const worker = new Worker(workerUrl, {
|
|
558
|
+
type: "module",
|
|
559
|
+
name: "legacy-office",
|
|
560
|
+
});
|
|
561
|
+
const finish = () => {
|
|
562
|
+
clearTimeout(timeout);
|
|
563
|
+
signal.removeEventListener("abort", onAbort);
|
|
564
|
+
worker.terminate();
|
|
565
|
+
};
|
|
566
|
+
const onAbort = () => {
|
|
567
|
+
finish();
|
|
568
|
+
reject(abortError());
|
|
569
|
+
};
|
|
570
|
+
const timeout = setTimeout(() => {
|
|
571
|
+
finish();
|
|
572
|
+
reject(new ViewerError("resource-limit", "Legacy Office conversion exceeded maxOperationMs", { details: { format, timeoutMs } }));
|
|
573
|
+
}, timeoutMs);
|
|
574
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
575
|
+
worker.onerror = (event) => {
|
|
576
|
+
finish();
|
|
577
|
+
reject(new ViewerError("worker-crashed", "Legacy conversion worker crashed", {
|
|
578
|
+
details: { message: event.message },
|
|
579
|
+
}));
|
|
580
|
+
};
|
|
581
|
+
worker.onmessage = (event) => {
|
|
582
|
+
finish();
|
|
583
|
+
if (event.data.ok)
|
|
584
|
+
resolve(new Uint8Array(event.data.data));
|
|
585
|
+
else
|
|
586
|
+
reject(new ViewerError("invalid-file", "Legacy Office conversion failed", {
|
|
587
|
+
details: { reason: event.data.message, format },
|
|
588
|
+
}));
|
|
589
|
+
};
|
|
590
|
+
const copy = data.slice().buffer;
|
|
591
|
+
worker.postMessage({ data: copy, format, moduleUrl: moduleUrl.href }, [
|
|
592
|
+
copy,
|
|
593
|
+
]);
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
function makeTextMapCanvas() {
|
|
597
|
+
if (typeof OffscreenCanvas !== "undefined")
|
|
598
|
+
return new OffscreenCanvas(1, 1);
|
|
599
|
+
if (typeof document !== "undefined")
|
|
600
|
+
return document.createElement("canvas");
|
|
601
|
+
throw new ViewerError("render-failed", "Text-map collection requires OffscreenCanvas or a DOM canvas");
|
|
602
|
+
}
|
|
603
|
+
function canvasCssWidth(target, dpr) {
|
|
604
|
+
return "clientWidth" in target && target.clientWidth > 0
|
|
605
|
+
? target.clientWidth
|
|
606
|
+
: Math.max(1, target.width / Math.max(1, dpr));
|
|
607
|
+
}
|
|
608
|
+
function canvasCssHeight(target, dpr) {
|
|
609
|
+
return "clientHeight" in target && target.clientHeight > 0
|
|
610
|
+
? target.clientHeight
|
|
611
|
+
: Math.max(1, target.height / Math.max(1, dpr));
|
|
612
|
+
}
|
|
613
|
+
function normalizeSheetRange(range) {
|
|
614
|
+
return range
|
|
615
|
+
? {
|
|
616
|
+
row: Math.max(1, Math.trunc(range.row)),
|
|
617
|
+
column: Math.max(1, Math.trunc(range.column)),
|
|
618
|
+
rowCount: Math.max(1, Math.trunc(range.rowCount)),
|
|
619
|
+
columnCount: Math.max(1, Math.trunc(range.columnCount)),
|
|
620
|
+
}
|
|
621
|
+
: { row: 1, column: 1, rowCount: 100, columnCount: 30 };
|
|
622
|
+
}
|
|
623
|
+
function assertUnitIndex(index, info) {
|
|
624
|
+
if (!Number.isInteger(index) || index < 0 || index >= info.pageCount)
|
|
625
|
+
throw new ViewerError("render-failed", "Office unit index is out of range", {
|
|
626
|
+
details: { index, pageCount: info.pageCount, unit: info.unit },
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
function throwIfAborted(signal, backend) {
|
|
630
|
+
if (!signal?.aborted)
|
|
631
|
+
return;
|
|
632
|
+
backend?.destroy();
|
|
633
|
+
throw abortError();
|
|
634
|
+
}
|
|
635
|
+
function exactArrayBuffer(data) {
|
|
636
|
+
return data.slice().buffer;
|
|
637
|
+
}
|
|
638
|
+
function isLegacyFormat(format) {
|
|
639
|
+
return LEGACY_FORMATS.includes(format);
|
|
640
|
+
}
|
|
641
|
+
function isMacroFormat(format) {
|
|
642
|
+
return format === "docm" || format === "xlsm" || format === "pptm";
|
|
643
|
+
}
|
|
644
|
+
function modernFormatFor(format) {
|
|
645
|
+
if (format === "doc")
|
|
646
|
+
return "docx";
|
|
647
|
+
if (format === "xls")
|
|
648
|
+
return "xlsx";
|
|
649
|
+
return "pptx";
|
|
650
|
+
}
|
|
651
|
+
function kindFor(format) {
|
|
652
|
+
if (format === "docx" || format === "docm")
|
|
653
|
+
return "document";
|
|
654
|
+
if (format === "xlsx" || format === "xlsm")
|
|
655
|
+
return "spreadsheet";
|
|
656
|
+
return "presentation";
|
|
657
|
+
}
|
|
658
|
+
function normalizeOfficeError(error) {
|
|
659
|
+
if (error instanceof ViewerError)
|
|
660
|
+
return error;
|
|
661
|
+
const code = typeof error === "object" && error !== null && "code" in error
|
|
662
|
+
? String(error.code)
|
|
663
|
+
: undefined;
|
|
664
|
+
if (code === "encrypted" ||
|
|
665
|
+
code === "invalid-password" ||
|
|
666
|
+
code === "unsupported-encryption")
|
|
667
|
+
return new ViewerError("encrypted-document", "Password-protected Office documents are not supported", { cause: error, details: { backendCode: code } });
|
|
668
|
+
return new ViewerError("invalid-file", error instanceof Error ? error.message : "Invalid Office document", { cause: error, ...(code ? { details: { backendCode: code } } : {}) });
|
|
669
|
+
}
|
|
670
|
+
function textDirection(text) {
|
|
671
|
+
return /[\u0590-\u08ff\ufb1d-\ufefc]/u.test(text) ? "rtl" : "ltr";
|
|
672
|
+
}
|