anyfile-cli 0.0.0-stage → 0.2.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/LICENSE +177 -0
- package/README.md +55 -2
- package/SKILL.md +101 -0
- package/chunks/browser-probe-5STDX455.mjs +17 -0
- package/chunks/browser-probe-F5RX44T3.mjs +24 -0
- package/chunks/chunk-2C34VMNV.mjs +108 -0
- package/chunks/chunk-3OZ56PUH.mjs +97 -0
- package/chunks/chunk-3YRWCQGV.mjs +38 -0
- package/chunks/chunk-53MJMIN4.mjs +23 -0
- package/chunks/chunk-5LOC7IST.mjs +372 -0
- package/chunks/chunk-5XTYLZF3.mjs +559 -0
- package/chunks/chunk-5ZHDYRGV.mjs +64 -0
- package/chunks/chunk-6CQL4K2K.mjs +21 -0
- package/chunks/chunk-6EVJJFOH.mjs +243 -0
- package/chunks/chunk-6NWSQGYE.mjs +68 -0
- package/chunks/chunk-7O5JLQE7.mjs +1 -0
- package/chunks/chunk-A6AQI6DF.mjs +321 -0
- package/chunks/chunk-AYF63UBE.mjs +79 -0
- package/chunks/chunk-B27PR6Q4.mjs +17 -0
- package/chunks/chunk-BP7LORL4.mjs +13 -0
- package/chunks/chunk-BVCRJLCD.mjs +109 -0
- package/chunks/chunk-CLSEE3VA.mjs +28 -0
- package/chunks/chunk-CO2ZAQIK.mjs +52 -0
- package/chunks/chunk-CQWM5GMU.mjs +167 -0
- package/chunks/chunk-CZFFYCMJ.mjs +136 -0
- package/chunks/chunk-D3CS6TIK.mjs +419 -0
- package/chunks/chunk-DJLFVMDJ.mjs +807 -0
- package/chunks/chunk-DJXVCKIO.mjs +30 -0
- package/chunks/chunk-EMXODK3K.mjs +94 -0
- package/chunks/chunk-EOJ7ZCDK.mjs +227 -0
- package/chunks/chunk-H4TBN22D.mjs +100 -0
- package/chunks/chunk-HI7TURZM.mjs +2256 -0
- package/chunks/chunk-HUSX3ZU3.mjs +58 -0
- package/chunks/chunk-IC3G2XE2.mjs +436 -0
- package/chunks/chunk-IGEGIF35.mjs +2034 -0
- package/chunks/chunk-IZGTVZHE.mjs +90 -0
- package/chunks/chunk-J4G7LUPA.mjs +117 -0
- package/chunks/chunk-JBAJW66L.mjs +4220 -0
- package/chunks/chunk-JKQUF2MM.mjs +438 -0
- package/chunks/chunk-KAMPC5TK.mjs +131 -0
- package/chunks/chunk-KSKEMJVC.mjs +145 -0
- package/chunks/chunk-LRHHRZLE.mjs +29 -0
- package/chunks/chunk-M37ZOAUG.mjs +93 -0
- package/chunks/chunk-MG7LUDXO.mjs +187 -0
- package/chunks/chunk-NGVHHTQD.mjs +125 -0
- package/chunks/chunk-NQ7J2NH6.mjs +50 -0
- package/chunks/chunk-NUMNHVSI.mjs +60 -0
- package/chunks/chunk-ORJ3DN65.mjs +58 -0
- package/chunks/chunk-QOUEBPPL.mjs +15 -0
- package/chunks/chunk-QR3Y3UKM.mjs +194 -0
- package/chunks/chunk-RFKYE7SE.mjs +50 -0
- package/chunks/chunk-SH57XOAV.mjs +33 -0
- package/chunks/chunk-TB5ISPA4.mjs +1 -0
- package/chunks/chunk-UGAU3V4V.mjs +206 -0
- package/chunks/chunk-WDN6NMVU.mjs +36 -0
- package/chunks/chunk-WWTLSPEG.mjs +3999 -0
- package/chunks/chunk-XDW56XVX.mjs +69 -0
- package/chunks/chunk-XRT7TAAY.mjs +27 -0
- package/chunks/chunk-XTW4HNIJ.mjs +418 -0
- package/chunks/chunk-YPLWNGCC.mjs +17 -0
- package/chunks/chunk-ZBR7RQQE.mjs +64 -0
- package/chunks/chunk-ZUHJIGHP.mjs +300 -0
- package/chunks/deflate-IINN6MRE.mjs +19 -0
- package/chunks/jpeg-N3DSYEAQ.mjs +964 -0
- package/chunks/jxl_oxide_wasm-3UN6G3YN.mjs +589 -0
- package/chunks/lerc-5LP7Q554.mjs +2086 -0
- package/chunks/lzw-Z2ZZBEWD.mjs +137 -0
- package/chunks/packbits-3S2JASDB.mjs +34 -0
- package/chunks/pdf.worker-PUGU2NS2.mjs +67416 -0
- package/chunks/probe-22WNVZ3I.mjs +17 -0
- package/chunks/probe-2P4CTFCY.mjs +14 -0
- package/chunks/probe-2QBNDPYK.mjs +18 -0
- package/chunks/probe-34TOVXUI.mjs +11 -0
- package/chunks/probe-3W2HOWBM.mjs +20 -0
- package/chunks/probe-42OBMD35.mjs +23 -0
- package/chunks/probe-43RVHUBG.mjs +17 -0
- package/chunks/probe-4O362IEX.mjs +18 -0
- package/chunks/probe-4WF34ZXS.mjs +11 -0
- package/chunks/probe-5ZITS3T5.mjs +40 -0
- package/chunks/probe-5ZS5DHFP.mjs +21 -0
- package/chunks/probe-62RFYKCP.mjs +14 -0
- package/chunks/probe-64JTFRH4.mjs +41 -0
- package/chunks/probe-6YJQJJ3R.mjs +518 -0
- package/chunks/probe-6YMOOV53.mjs +39 -0
- package/chunks/probe-BYBD2WAK.mjs +239 -0
- package/chunks/probe-CZZNJOHV.mjs +20 -0
- package/chunks/probe-DJMPK6HU.mjs +11 -0
- package/chunks/probe-FMWIF4LX.mjs +33 -0
- package/chunks/probe-FYPH6CYY.mjs +206 -0
- package/chunks/probe-G6PPXKBE.mjs +15 -0
- package/chunks/probe-GJ5OUOQ3.mjs +32 -0
- package/chunks/probe-H6J7TUY2.mjs +95 -0
- package/chunks/probe-IGZ47OE3.mjs +68 -0
- package/chunks/probe-IL5HO3OK.mjs +46 -0
- package/chunks/probe-INYCDZHO.mjs +27 -0
- package/chunks/probe-JFH545GO.mjs +11 -0
- package/chunks/probe-JZYDRITV.mjs +18 -0
- package/chunks/probe-K3WW5O5K.mjs +26 -0
- package/chunks/probe-KB4T466L.mjs +70 -0
- package/chunks/probe-KY7SIIXD.mjs +13 -0
- package/chunks/probe-L2P263WT.mjs +16 -0
- package/chunks/probe-LEP3RQPD.mjs +11 -0
- package/chunks/probe-M2QWULOI.mjs +119 -0
- package/chunks/probe-M7AYZBD3.mjs +35 -0
- package/chunks/probe-MEN3BMBB.mjs +22 -0
- package/chunks/probe-MNIGKDWT.mjs +163 -0
- package/chunks/probe-NFVFWB4M.mjs +56 -0
- package/chunks/probe-NJGSTL6R.mjs +161 -0
- package/chunks/probe-O73EHWT3.mjs +14 -0
- package/chunks/probe-OG2XYCG2.mjs +25 -0
- package/chunks/probe-OTKJKTNS.mjs +10 -0
- package/chunks/probe-OZKO3C2V.mjs +27 -0
- package/chunks/probe-PBL4KITG.mjs +12 -0
- package/chunks/probe-PEFZNH2T.mjs +21 -0
- package/chunks/probe-R4SSEXES.mjs +27 -0
- package/chunks/probe-RCAUVV27.mjs +29 -0
- package/chunks/probe-RPGBKGPI.mjs +20 -0
- package/chunks/probe-S2I46SEO.mjs +10 -0
- package/chunks/probe-SGDD4U4Q.mjs +165 -0
- package/chunks/probe-SPQO5LHI.mjs +9 -0
- package/chunks/probe-TBR6UGRZ.mjs +19 -0
- package/chunks/probe-TNKNILAW.mjs +21 -0
- package/chunks/probe-TVRJBPXH.mjs +48 -0
- package/chunks/probe-UESMTUQ5.mjs +33 -0
- package/chunks/probe-VDXFEZ5Q.mjs +16 -0
- package/chunks/probe-VX7JCDW6.mjs +39 -0
- package/chunks/probe-W7M55OPE.mjs +64 -0
- package/chunks/probe-XUBTIWGE.mjs +13 -0
- package/chunks/probe-ZF7KIRHO.mjs +36 -0
- package/chunks/raw-JJRPYAXO.mjs +16 -0
- package/chunks/tiff-metadata-7MWLNVW2.mjs +2990 -0
- package/chunks/webimage-D6XSCCTJ.mjs +56 -0
- package/chunks/zip-reader-YUGANW4Z.mjs +92 -0
- package/chunks/zstd-AH2S24PU.mjs +121 -0
- package/cli-main.mjs +297 -0
- package/cli.mjs +3 -0
- package/extractors/apple-plist.mjs +145 -0
- package/extractors/archive-metadata-viewer.mjs +1401 -0
- package/extractors/bittorrent-metadata.mjs +369 -0
- package/extractors/calendar-contacts.mjs +328 -0
- package/extractors/camera-raw.mjs +201 -0
- package/extractors/chm-reader.mjs +1842 -0
- package/extractors/comic-book-reader.mjs +307 -0
- package/extractors/design-source.mjs +1801 -0
- package/extractors/dev-array-viewer.mjs +825 -0
- package/extractors/dev-native-binary-viewer.mjs +1661 -0
- package/extractors/dev-source-map-viewer.mjs +416 -0
- package/extractors/dev-wasm-viewer.mjs +506 -0
- package/extractors/dicom.mjs +383 -0
- package/extractors/djvu-reader.mjs +337 -0
- package/extractors/duckdb-data.mjs +49174 -0
- package/extractors/epub-reader.mjs +222 -0
- package/extractors/excel-workbook.mjs +27057 -0
- package/extractors/fictionbook-reader.mjs +362 -0
- package/extractors/font-viewer.mjs +441 -0
- package/extractors/general-raster.mjs +444 -0
- package/extractors/hdr-image.mjs +1685 -0
- package/extractors/http-archive.mjs +306 -0
- package/extractors/ifc.mjs +341 -0
- package/extractors/iwork.mjs +640 -0
- package/extractors/microsoft-project.mjs +174 -0
- package/extractors/mind-map.mjs +607 -0
- package/extractors/ml-weights.mjs +649 -0
- package/extractors/modern-raster.mjs +620 -0
- package/extractors/ofd-reader.mjs +973 -0
- package/extractors/outlook-pst.mjs +997 -0
- package/extractors/pdfjs-pdf.mjs +32056 -0
- package/extractors/photoshop-document.mjs +17448 -0
- package/extractors/safe-svg.mjs +163 -0
- package/extractors/scientific-data.mjs +2041 -0
- package/extractors/sqlite-database.mjs +333 -0
- package/extractors/statistical-data.mjs +297 -0
- package/extractors/visio.mjs +141 -0
- package/extractors/x509-certificate.mjs +588 -0
- package/extractors/xps-reader.mjs +896 -0
- package/index.mjs +83 -0
- package/licenses/dicom-parser/1.8.21/LICENSE +21 -0
- package/licenses/libraw-wasm/1.6.0/COPYRIGHT.LibRaw +27 -0
- package/licenses/libraw-wasm/1.6.0/LICENSE.Emscripten +102 -0
- package/licenses/libraw-wasm/1.6.0/LICENSE.LibRaw-CDDL-1.0 +340 -0
- package/licenses/libraw-wasm/1.6.0/LICENSE.Little-CMS-MIT +22 -0
- package/licenses/libraw-wasm/1.6.0/LICENSE.libpng +134 -0
- package/licenses/libraw-wasm/1.6.0/LICENSE.libraw-wasm-ISC +15 -0
- package/licenses/libraw-wasm/1.6.0/LICENSE.zlib +22 -0
- package/licenses/libraw-wasm/1.6.0/NOTICE.IJG-libjpeg +49 -0
- package/licenses/libraw-wasm/1.6.0/SOURCE.md +25 -0
- package/licenses/libraw-wasm/1.6.0/THIRD_PARTY_NOTICES.md +14 -0
- package/licenses/mediabunny/1.55.3/MPL-2.0.txt +373 -0
- package/licenses/mediabunny/1.55.3/SOURCE.md +16 -0
- package/licenses/openskp/1.3.0/LICENSE +21 -0
- package/package.json +34 -4
- package/renderer-host/assets/ColladaComposer-TCm9fgZa.js +1 -0
- package/renderer-host/assets/ColladaParser-BHTzbhBz.js +3 -0
- package/renderer-host/assets/FBXLoader-D1vDnL3o.js +8 -0
- package/renderer-host/assets/agent-CKvDbj87.js +1 -0
- package/renderer-host/assets/amf-BkE--DNX.js +1 -0
- package/renderer-host/assets/animation-Dt0WW2cB.js +1 -0
- package/renderer-host/assets/archive-client-CL5yOgwH.js +1 -0
- package/renderer-host/assets/archive.worker-CcLnJ9FC.js +1 -0
- package/renderer-host/assets/audio-visualizer-CiyGNhY2.js +1 -0
- package/renderer-host/assets/basedecoder-BuG7fe0q.js +1 -0
- package/renderer-host/assets/book-source-28BQcBKR.js +1 -0
- package/renderer-host/assets/book-worker-DUt14LJO.js +1 -0
- package/renderer-host/assets/browser-C0pGRq_c.js +1 -0
- package/renderer-host/assets/client-CU2ERPtk.js +1 -0
- package/renderer-host/assets/container-inspection-ekEPWWcy.js +1 -0
- package/renderer-host/assets/data-table-OJQe3aN5.js +1 -0
- package/renderer-host/assets/decode-hBroL8C1.js +1 -0
- package/renderer-host/assets/decode-tiff-CP1xdrF_.js +5 -0
- package/renderer-host/assets/decoder-worker-B0sdTVlF.js +1 -0
- package/renderer-host/assets/decoder-worker-CBiHE971.js +3 -0
- package/renderer-host/assets/decoder-worker-Cr5oP97p.js +5 -0
- package/renderer-host/assets/decoder-worker-DIdLFebY.js +11 -0
- package/renderer-host/assets/decoder-worker-DLeuEYxq.js +1 -0
- package/renderer-host/assets/decoder.worker-BXAaF0Qj.js +1 -0
- package/renderer-host/assets/decoder.worker-yaM6uups.js +1 -0
- package/renderer-host/assets/deflate-DPjr4M2G.js +1 -0
- package/renderer-host/assets/deflate-S3QmZI-f.js +1 -0
- package/renderer-host/assets/dual-track-playback-CxjGms-W.js +1 -0
- package/renderer-host/assets/ext-searchbox-BIdon51Z.js +164 -0
- package/renderer-host/assets/ffmpeg-playback-DzCJz9Ny.js +1 -0
- package/renderer-host/assets/gltf-PozNLKNg.js +1 -0
- package/renderer-host/assets/hdf5.worker-BO3TrRup.js +1 -0
- package/renderer-host/assets/heif-worker-CC9DI3ZR.js +1 -0
- package/renderer-host/assets/id3-uzaDmDwy.js +1 -0
- package/renderer-host/assets/ifc.worker-KIbgAIsy.js +1 -0
- package/renderer-host/assets/image-load-SK3ULGWm.js +1 -0
- package/renderer-host/assets/index-DtiyOy_J.js +2 -0
- package/renderer-host/assets/jpeg-AGQ46WDa.js +1 -0
- package/renderer-host/assets/jpeg-Dm0yBuYB.js +1 -0
- package/renderer-host/assets/jszip.min-DCdQ6XWv.js +2 -0
- package/renderer-host/assets/jxl_oxide_wasm-BJKDqoXP.js +1 -0
- package/renderer-host/assets/jxl_oxide_wasm_bg-C5JqlrFv.wasm +0 -0
- package/renderer-host/assets/kernel.worker-B58X9XWu.js +1 -0
- package/renderer-host/assets/kernel.worker-BcQYKb39.js +8 -0
- package/renderer-host/assets/kernel.worker-BdWmPdqg.js +1 -0
- package/renderer-host/assets/kernel.worker-C7qxomuK.js +1 -0
- package/renderer-host/assets/kernel.worker-D88TbQnz.js +1 -0
- package/renderer-host/assets/laz-Lt10LsWd.js +1 -0
- package/renderer-host/assets/lerc-BxVqCKaH.js +3 -0
- package/renderer-host/assets/lerc-Cuor-Zm2.js +1 -0
- package/renderer-host/assets/lzw-D2FslT4L.js +1 -0
- package/renderer-host/assets/lzw-DODNa9l5.js +1 -0
- package/renderer-host/assets/mediabunny-viewer-BniHVEWJ.js +16 -0
- package/renderer-host/assets/model-Drd3vqcF.js +1 -0
- package/renderer-host/assets/obj-B3p81LL2.js +9 -0
- package/renderer-host/assets/off-QQbiKPTX.js +1 -0
- package/renderer-host/assets/ogg-probe-C2TT74FL.js +1 -0
- package/renderer-host/assets/ogg-viewer-Dc8K-tas.js +9 -0
- package/renderer-host/assets/packbits-DCimUQ1T.js +1 -0
- package/renderer-host/assets/paged-C8AQD7sX.js +319 -0
- package/renderer-host/assets/pako.esm-0UYEm1Jg.js +2 -0
- package/renderer-host/assets/pako.esm-CtVA0R7W.js +1 -0
- package/renderer-host/assets/pdf.worker.min-CHFwMXne.mjs +29 -0
- package/renderer-host/assets/ply-C3_RRA7n.js +2 -0
- package/renderer-host/assets/points.worker-CA8v75dl.js +2 -0
- package/renderer-host/assets/probe-asf-C_UpCBly.js +14 -0
- package/renderer-host/assets/range-reader-BMfLhWcp.js +1 -0
- package/renderer-host/assets/raw-A-vJRPpa.js +1 -0
- package/renderer-host/assets/resource-cache-CHocY8K3.js +1 -0
- package/renderer-host/assets/resources-6AmS6O5e.js +1 -0
- package/renderer-host/assets/rolldown-runtime-Dd_uD5pT.js +1 -0
- package/renderer-host/assets/safe-content-CWHf8jex.js +1 -0
- package/renderer-host/assets/sanitize-D56ODnaM.js +1 -0
- package/renderer-host/assets/scene-adapter-CaCLr1am.js +1 -0
- package/renderer-host/assets/scene.worker-CJViWLYo.js +24 -0
- package/renderer-host/assets/scene.worker-D7koFZY8.js +2 -0
- package/renderer-host/assets/skp-adapter-jl6q24fW.js +1 -0
- package/renderer-host/assets/skp.worker-D9ujTXFV.js +1 -0
- package/renderer-host/assets/src-1Won7FxU.js +88 -0
- package/renderer-host/assets/src-3RoHqOkA.js +7 -0
- package/renderer-host/assets/src-4zBOL6Jt.js +1 -0
- package/renderer-host/assets/src-6v8-hoR3.js +24 -0
- package/renderer-host/assets/src-8Jx9gbII.js +1 -0
- package/renderer-host/assets/src-B1WA0dRu.js +64 -0
- package/renderer-host/assets/src-B5ijbemo.js +9 -0
- package/renderer-host/assets/src-B8DH2GJe.js +17 -0
- package/renderer-host/assets/src-B9t_iEO3.js +58 -0
- package/renderer-host/assets/src-BCC58C0X.js +1 -0
- package/renderer-host/assets/src-BCwENs26.js +1 -0
- package/renderer-host/assets/src-BEirBh4c.js +27 -0
- package/renderer-host/assets/src-BHR6n7Fj.js +1 -0
- package/renderer-host/assets/src-BIlLq0QT.js +169 -0
- package/renderer-host/assets/src-BKlK1jcN.js +1 -0
- package/renderer-host/assets/src-BN0FUJhs.js +8 -0
- package/renderer-host/assets/src-BWElAdlq.js +52 -0
- package/renderer-host/assets/src-BXg11IjY.js +4 -0
- package/renderer-host/assets/src-BbBdnTjJ.js +2 -0
- package/renderer-host/assets/src-BbFZbZsL.js +2 -0
- package/renderer-host/assets/src-BdPbFRd-.js +24 -0
- package/renderer-host/assets/src-BpbGaBrT.js +182 -0
- package/renderer-host/assets/src-BwIl76_H.js +7 -0
- package/renderer-host/assets/src-C2e6QJIj.js +10 -0
- package/renderer-host/assets/src-C2gNidHF.js +989 -0
- package/renderer-host/assets/src-C9Uz3C-q.js +432 -0
- package/renderer-host/assets/src-CBUhG6W5.js +7 -0
- package/renderer-host/assets/src-CQDGi3Qa.js +10 -0
- package/renderer-host/assets/src-CRLCRg0N.js +21 -0
- package/renderer-host/assets/src-CS5rqxBy.js +10 -0
- package/renderer-host/assets/src-CWZdSJQw.js +7 -0
- package/renderer-host/assets/src-CXnpsVpU.js +27 -0
- package/renderer-host/assets/src-CnhXvqQY.js +8 -0
- package/renderer-host/assets/src-CpExg0ZA.js +9 -0
- package/renderer-host/assets/src-CrLmL3wU.js +5 -0
- package/renderer-host/assets/src-CrYEJ5uz.js +2 -0
- package/renderer-host/assets/src-D-iIkSqZ.js +222 -0
- package/renderer-host/assets/src-D6sH9uTT.js +23 -0
- package/renderer-host/assets/src-D8zHDJh_.js +10 -0
- package/renderer-host/assets/src-D9OFaPNV.js +1 -0
- package/renderer-host/assets/src-DCI_ff7c.js +1 -0
- package/renderer-host/assets/src-DCrbiTpH.js +18 -0
- package/renderer-host/assets/src-DK8DvtMd.js +115 -0
- package/renderer-host/assets/src-DWGlOVjt.js +17 -0
- package/renderer-host/assets/src-DbvEX_Ct.js +6 -0
- package/renderer-host/assets/src-Dezc2dj1.js +1 -0
- package/renderer-host/assets/src-Dh5VD1lL.js +11 -0
- package/renderer-host/assets/src-DlwABqw5.js +1 -0
- package/renderer-host/assets/src-DlxETlTh.js +44 -0
- package/renderer-host/assets/src-Dmd6BvBh.js +387 -0
- package/renderer-host/assets/src-DpgvaJNJ.js +24 -0
- package/renderer-host/assets/src-DpjRB2sv.js +1 -0
- package/renderer-host/assets/src-Dvn41FR7.js +90 -0
- package/renderer-host/assets/src-DwcPYp7X.js +1 -0
- package/renderer-host/assets/src-HUxhcDlO.js +2 -0
- package/renderer-host/assets/src-Jhqg3J8L.js +2 -0
- package/renderer-host/assets/src-MO5bLsLj.js +4126 -0
- package/renderer-host/assets/src-N8XBQaK4.js +20 -0
- package/renderer-host/assets/src-XZ_0U972.js +1 -0
- package/renderer-host/assets/src-Y6mXl4vh.js +29 -0
- package/renderer-host/assets/src-b9aXVJde.js +100 -0
- package/renderer-host/assets/src-d2U6neq8.js +37 -0
- package/renderer-host/assets/src-hCrza_Lf.js +1 -0
- package/renderer-host/assets/src-jUGjKzOV.js +1 -0
- package/renderer-host/assets/src-rJN_jaC5.js +1 -0
- package/renderer-host/assets/src-vOBd-1zk.js +5 -0
- package/renderer-host/assets/src-wrrVkfrK.js +1 -0
- package/renderer-host/assets/src-yCrAObB-.js +1 -0
- package/renderer-host/assets/src-zrBiCtay.js +7 -0
- package/renderer-host/assets/stl-adapter-CLkWHoOn.js +1 -0
- package/renderer-host/assets/stl.worker-C-anHijM.js +1 -0
- package/renderer-host/assets/three-mf-BSrcsdQD.js +2 -0
- package/renderer-host/assets/webimage-zQMH-_zR.js +1 -0
- package/renderer-host/assets/webm-14HHwfWy.js +1 -0
- package/renderer-host/assets/worker-QK2gViTu.js +1 -0
- package/renderer-host/assets/x6-dng-worker-CNf3zUP-.js +1 -0
- package/renderer-host/assets/xml.browser-CC8-XAyN.js +1 -0
- package/renderer-host/assets/zip-core-base-DD8akpjq.js +1 -0
- package/renderer-host/assets/zip-core-custom-CfPFs1lw.js +1 -0
- package/renderer-host/assets/zip-source-CLF3Hfcg.js +1 -0
- package/renderer-host/assets/zstd-CmwSLjHB.js +1 -0
- package/renderer-host/assets/zstd-i4Jwubnx.js +1 -0
- package/renderer-host/index.html +65 -0
- package/vendor-manifest.json +1433 -0
- package/worker.mjs +262 -0
|
@@ -0,0 +1,896 @@
|
|
|
1
|
+
import { createRequire as __anyfileCreateRequire } from "node:module"; import { dirname as __anyfileDirname } from "node:path"; import { fileURLToPath as __anyfileFileURLToPath } from "node:url"; const require = __anyfileCreateRequire(import.meta.url); const __filename = __anyfileFileURLToPath(import.meta.url); const __dirname = __anyfileDirname(__filename);
|
|
2
|
+
import "../chunks/chunk-D3CS6TIK.mjs";
|
|
3
|
+
import {
|
|
4
|
+
BlobReader,
|
|
5
|
+
BlobWriter,
|
|
6
|
+
Uint8ArrayWriter,
|
|
7
|
+
ZipReader
|
|
8
|
+
} from "../chunks/chunk-WWTLSPEG.mjs";
|
|
9
|
+
import {
|
|
10
|
+
parseXmlDocument
|
|
11
|
+
} from "../chunks/chunk-53MJMIN4.mjs";
|
|
12
|
+
import {
|
|
13
|
+
AgentError,
|
|
14
|
+
abortError,
|
|
15
|
+
isViewerAbortError,
|
|
16
|
+
markdownDocumentHeader,
|
|
17
|
+
readPagedTextDocument
|
|
18
|
+
} from "../chunks/chunk-IC3G2XE2.mjs";
|
|
19
|
+
import "../chunks/chunk-ORJ3DN65.mjs";
|
|
20
|
+
|
|
21
|
+
// ../plugins/xps/src/limits.ts
|
|
22
|
+
var XPS_LIMITS = {
|
|
23
|
+
/** Parts are read lazily from the ZIP, so the whole file is never buffered. */
|
|
24
|
+
maxInputBytes: 512 * 1024 * 1024,
|
|
25
|
+
entries: 5e4,
|
|
26
|
+
pages: 1e4,
|
|
27
|
+
/** One decompressed XML part (FixedPage, FixedDocument, dictionary…). */
|
|
28
|
+
xmlBytes: 64 * 1024 * 1024,
|
|
29
|
+
fontBytes: 32 * 1024 * 1024,
|
|
30
|
+
imageBytes: 64 * 1024 * 1024,
|
|
31
|
+
/** Pixels of one decoded image. */
|
|
32
|
+
imagePixels: 64 * 1024 * 1024,
|
|
33
|
+
/** Elements produced by one FixedPage (paths, glyph runs, canvases). */
|
|
34
|
+
pageNodes: 2e5,
|
|
35
|
+
/** Glyphs of one page. */
|
|
36
|
+
pageGlyphs: 5e5,
|
|
37
|
+
nestingDepth: 64,
|
|
38
|
+
outlineEntries: 1e4,
|
|
39
|
+
/** Decoded fonts / images kept alive across pages. */
|
|
40
|
+
fontCacheBytes: 128 * 1024 * 1024,
|
|
41
|
+
imageCachePixels: 96 * 1024 * 1024,
|
|
42
|
+
maxRenderPixels: 16 * 1024 * 1024,
|
|
43
|
+
maxActiveCanvasPages: 6,
|
|
44
|
+
maxActiveThumbnails: 40
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// ../plugins/xps/src/package.ts
|
|
48
|
+
var XpsLimitError = class extends Error {
|
|
49
|
+
};
|
|
50
|
+
var XpsFormatError = class extends Error {
|
|
51
|
+
};
|
|
52
|
+
var SUPPORTED_METHODS = /* @__PURE__ */ new Set([0, 8]);
|
|
53
|
+
var PIECE = /^(.*)\/\[(\d+)\](\.last)?\.piece$/;
|
|
54
|
+
function partKey(name) {
|
|
55
|
+
let decoded = name;
|
|
56
|
+
try {
|
|
57
|
+
decoded = decodeURIComponent(name);
|
|
58
|
+
} catch {
|
|
59
|
+
}
|
|
60
|
+
return decoded.replace(/^\/+/, "").toLowerCase();
|
|
61
|
+
}
|
|
62
|
+
function resolvePart(base, uri) {
|
|
63
|
+
const target = uri.trim().split("#")[0] ?? "";
|
|
64
|
+
if (/^[a-z][a-z0-9+.-]*:/i.test(target)) return void 0;
|
|
65
|
+
const segments = target.startsWith("/") ? [] : base.replace(/^\/+/, "").split("/").slice(0, -1);
|
|
66
|
+
for (const segment of target.split("/")) {
|
|
67
|
+
if (segment === "" || segment === ".") continue;
|
|
68
|
+
if (segment === "..") segments.pop();
|
|
69
|
+
else segments.push(segment);
|
|
70
|
+
}
|
|
71
|
+
return segments.join("/");
|
|
72
|
+
}
|
|
73
|
+
function uriFragment(uri) {
|
|
74
|
+
const index = uri.indexOf("#");
|
|
75
|
+
return index < 0 ? void 0 : uri.slice(index + 1);
|
|
76
|
+
}
|
|
77
|
+
function decodeXmlText(bytes) {
|
|
78
|
+
if (bytes[0] === 255 && bytes[1] === 254) return new TextDecoder("utf-16le").decode(bytes.subarray(2));
|
|
79
|
+
if (bytes[0] === 254 && bytes[1] === 255) return new TextDecoder("utf-16be").decode(bytes.subarray(2));
|
|
80
|
+
if (bytes[0] === 60 && bytes[1] === 0) return new TextDecoder("utf-16le").decode(bytes);
|
|
81
|
+
if (bytes[0] === 0 && bytes[1] === 60) return new TextDecoder("utf-16be").decode(bytes);
|
|
82
|
+
return new TextDecoder("utf-8").decode(bytes);
|
|
83
|
+
}
|
|
84
|
+
var XpsPackage = class _XpsPackage {
|
|
85
|
+
constructor(reader, signal) {
|
|
86
|
+
this.reader = reader;
|
|
87
|
+
this.signal = signal;
|
|
88
|
+
this.parts = /* @__PURE__ */ new Map();
|
|
89
|
+
this.relCache = /* @__PURE__ */ new Map();
|
|
90
|
+
}
|
|
91
|
+
static async open(file, signal) {
|
|
92
|
+
const reader = new ZipReader(new BlobReader(file), { useWebWorkers: false, useCompressionStream: true });
|
|
93
|
+
const pkg = new _XpsPackage(reader, signal);
|
|
94
|
+
try {
|
|
95
|
+
const pieces = /* @__PURE__ */ new Map();
|
|
96
|
+
let count = 0;
|
|
97
|
+
for await (const entry of reader.getEntriesGenerator()) {
|
|
98
|
+
if (signal.aborted) throw new DOMException("Viewer operation aborted.", "AbortError");
|
|
99
|
+
if (++count > XPS_LIMITS.entries) throw new XpsLimitError("Too many package entries.");
|
|
100
|
+
if (!isFile(entry)) continue;
|
|
101
|
+
const piece = PIECE.exec(entry.filename);
|
|
102
|
+
if (piece) {
|
|
103
|
+
const key = partKey(piece[1]);
|
|
104
|
+
const list = pieces.get(key) ?? [];
|
|
105
|
+
list.push({ index: Number(piece[2]), last: !!piece[3], entry });
|
|
106
|
+
pieces.set(key, list);
|
|
107
|
+
} else {
|
|
108
|
+
pkg.parts.set(partKey(entry.filename), [entry]);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
for (const [key, list] of pieces) {
|
|
112
|
+
list.sort((a, b) => a.index - b.index);
|
|
113
|
+
const complete = list.every((item, index) => item.index === index) && list.at(-1)?.last;
|
|
114
|
+
if (complete && !pkg.parts.has(key)) pkg.parts.set(key, list.map((item) => item.entry));
|
|
115
|
+
}
|
|
116
|
+
return pkg;
|
|
117
|
+
} catch (error) {
|
|
118
|
+
await pkg.close();
|
|
119
|
+
throw error;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
get names() {
|
|
123
|
+
return [...this.parts.keys()];
|
|
124
|
+
}
|
|
125
|
+
has(part) {
|
|
126
|
+
return this.parts.has(partKey(part));
|
|
127
|
+
}
|
|
128
|
+
size(part) {
|
|
129
|
+
return this.parts.get(partKey(part))?.reduce((sum, entry) => sum + entry.uncompressedSize, 0);
|
|
130
|
+
}
|
|
131
|
+
async bytes(part, limit) {
|
|
132
|
+
const entries = this.entries(part, limit);
|
|
133
|
+
if (entries.length === 1) return entries[0].getData(new Uint8ArrayWriter(), { signal: this.signal });
|
|
134
|
+
const chunks = [];
|
|
135
|
+
for (const entry of entries) chunks.push(await entry.getData(new Uint8ArrayWriter(), { signal: this.signal }));
|
|
136
|
+
const out = new Uint8Array(chunks.reduce((sum, chunk) => sum + chunk.length, 0));
|
|
137
|
+
let offset = 0;
|
|
138
|
+
for (const chunk of chunks) {
|
|
139
|
+
out.set(chunk, offset);
|
|
140
|
+
offset += chunk.length;
|
|
141
|
+
}
|
|
142
|
+
return out;
|
|
143
|
+
}
|
|
144
|
+
async blob(part, limit) {
|
|
145
|
+
const entries = this.entries(part, limit);
|
|
146
|
+
const blobs = [];
|
|
147
|
+
for (const entry of entries) blobs.push(await entry.getData(new BlobWriter(), { signal: this.signal }));
|
|
148
|
+
return new Blob(blobs);
|
|
149
|
+
}
|
|
150
|
+
async text(part, limit = XPS_LIMITS.xmlBytes) {
|
|
151
|
+
return decodeXmlText(await this.bytes(part, limit));
|
|
152
|
+
}
|
|
153
|
+
/** Relationships of `part` from its `_rels/<name>.rels` sibling (empty when absent). */
|
|
154
|
+
relationships(part) {
|
|
155
|
+
const normalized = part.replace(/^\/+/, "");
|
|
156
|
+
const cached = this.relCache.get(partKey(normalized));
|
|
157
|
+
if (cached) return cached;
|
|
158
|
+
const slash = normalized.lastIndexOf("/");
|
|
159
|
+
const relsPart = `${normalized.slice(0, slash + 1)}_rels/${normalized.slice(slash + 1)}.rels`;
|
|
160
|
+
const promise = this.readRelationships(normalized, relsPart);
|
|
161
|
+
this.relCache.set(partKey(normalized), promise);
|
|
162
|
+
return promise;
|
|
163
|
+
}
|
|
164
|
+
async close() {
|
|
165
|
+
await this.reader.close().catch(() => void 0);
|
|
166
|
+
}
|
|
167
|
+
async readRelationships(source, relsPart) {
|
|
168
|
+
if (!this.has(relsPart)) return [];
|
|
169
|
+
const doc = parseXmlDocument(await this.text(relsPart), "application/xml");
|
|
170
|
+
const result = [];
|
|
171
|
+
for (const node of descendantsNamed(doc.documentElement, "Relationship")) {
|
|
172
|
+
if (node.getAttribute("TargetMode") === "External") continue;
|
|
173
|
+
const target = resolvePart(source, node.getAttribute("Target") ?? "");
|
|
174
|
+
if (target) result.push({ type: node.getAttribute("Type") ?? "", target });
|
|
175
|
+
}
|
|
176
|
+
return result;
|
|
177
|
+
}
|
|
178
|
+
entries(part, limit) {
|
|
179
|
+
const entries = this.parts.get(partKey(part));
|
|
180
|
+
if (!entries) throw new XpsFormatError(`Missing package part ${part}.`);
|
|
181
|
+
let size = 0;
|
|
182
|
+
for (const entry of entries) {
|
|
183
|
+
if (entry.encrypted || !SUPPORTED_METHODS.has(entry.compressionMethod)) throw new XpsFormatError("Unsupported ZIP entry.");
|
|
184
|
+
size += entry.uncompressedSize;
|
|
185
|
+
}
|
|
186
|
+
if (size > limit) throw new XpsLimitError("Package part exceeds the limit.");
|
|
187
|
+
return entries;
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
function isFile(entry) {
|
|
191
|
+
return !entry.directory;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// ../plugins/xps/src/xml.ts
|
|
195
|
+
function parseXml(text) {
|
|
196
|
+
const doc = parseXmlDocument(text.replace(/^/, ""), "application/xml");
|
|
197
|
+
const root = doc.documentElement;
|
|
198
|
+
if (!root || root.localName === "parsererror" || doc.getElementsByTagName("parsererror").length > 0) {
|
|
199
|
+
throw new XpsFormatError("Malformed XML part.");
|
|
200
|
+
}
|
|
201
|
+
return root;
|
|
202
|
+
}
|
|
203
|
+
function elementChildren(element) {
|
|
204
|
+
const out = [];
|
|
205
|
+
for (const child of Array.from(element.children)) {
|
|
206
|
+
if (child.localName === "AlternateContent") {
|
|
207
|
+
const fallback = Array.from(child.children).find((node) => node.localName === "Fallback");
|
|
208
|
+
if (fallback) out.push(...elementChildren(fallback));
|
|
209
|
+
} else {
|
|
210
|
+
out.push(child);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return out;
|
|
214
|
+
}
|
|
215
|
+
function childNamed(element, localName) {
|
|
216
|
+
return elementChildren(element).find((child) => child.localName === localName);
|
|
217
|
+
}
|
|
218
|
+
function childrenNamed(element, localName) {
|
|
219
|
+
return elementChildren(element).filter((child) => child.localName === localName);
|
|
220
|
+
}
|
|
221
|
+
function propertyValue(element, property) {
|
|
222
|
+
const holder = childNamed(element, `${element.localName}.${property}`);
|
|
223
|
+
return holder ? elementChildren(holder)[0] : void 0;
|
|
224
|
+
}
|
|
225
|
+
function attrLocal(element, localName) {
|
|
226
|
+
for (const attribute of Array.from(element.attributes)) {
|
|
227
|
+
const name = attribute.name;
|
|
228
|
+
if (attribute.localName === localName || name === localName || name.endsWith(`:${localName}`)) return attribute.value;
|
|
229
|
+
}
|
|
230
|
+
return void 0;
|
|
231
|
+
}
|
|
232
|
+
function numberAttr(element, name, fallback) {
|
|
233
|
+
const raw = element.getAttribute(name);
|
|
234
|
+
if (raw === null) return fallback;
|
|
235
|
+
const value = Number.parseFloat(raw);
|
|
236
|
+
return Number.isFinite(value) ? value : fallback;
|
|
237
|
+
}
|
|
238
|
+
function numberList(value) {
|
|
239
|
+
if (!value) return [];
|
|
240
|
+
return value.trim().split(/[\s,]+/).filter(Boolean).map(Number).filter((item) => Number.isFinite(item));
|
|
241
|
+
}
|
|
242
|
+
function descendantsNamed(root, localName) {
|
|
243
|
+
return Array.from(root.getElementsByTagName("*")).filter((node) => node.localName === localName);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// ../plugins/xps/src/geometry.ts
|
|
247
|
+
var IDENTITY = [1, 0, 0, 1, 0, 0];
|
|
248
|
+
function parseMatrix(value) {
|
|
249
|
+
const numbers = numberList(value);
|
|
250
|
+
return numbers.length === 6 ? numbers : void 0;
|
|
251
|
+
}
|
|
252
|
+
function multiply(a, b) {
|
|
253
|
+
return [
|
|
254
|
+
a[0] * b[0] + a[1] * b[2],
|
|
255
|
+
a[0] * b[1] + a[1] * b[3],
|
|
256
|
+
a[2] * b[0] + a[3] * b[2],
|
|
257
|
+
a[2] * b[1] + a[3] * b[3],
|
|
258
|
+
a[4] * b[0] + a[5] * b[2] + b[4],
|
|
259
|
+
a[4] * b[1] + a[5] * b[3] + b[5]
|
|
260
|
+
];
|
|
261
|
+
}
|
|
262
|
+
function applyMatrix(m, x, y) {
|
|
263
|
+
return [m[0] * x + m[2] * y + m[4], m[1] * x + m[3] * y + m[5]];
|
|
264
|
+
}
|
|
265
|
+
function parseAbbreviatedGeometry(data, transform) {
|
|
266
|
+
const match = /^\s*F\s*([01])/i.exec(data);
|
|
267
|
+
const d = match ? data.slice(match[0].length) : data;
|
|
268
|
+
return { d: d.trim(), fillRule: match?.[1] === "1" ? "nonzero" : "evenodd", transform };
|
|
269
|
+
}
|
|
270
|
+
function points(value) {
|
|
271
|
+
const numbers = numberList(value);
|
|
272
|
+
const out = [];
|
|
273
|
+
for (let i = 0; i + 1 < numbers.length; i += 2) out.push(`${numbers[i]},${numbers[i + 1]}`);
|
|
274
|
+
return out;
|
|
275
|
+
}
|
|
276
|
+
function segmentData(segment) {
|
|
277
|
+
const list = points(segment.getAttribute("Points") ?? segment.getAttribute("Point"));
|
|
278
|
+
switch (segment.localName) {
|
|
279
|
+
case "PolyLineSegment":
|
|
280
|
+
return list.length ? `L ${list.join(" ")}` : "";
|
|
281
|
+
case "PolyBezierSegment":
|
|
282
|
+
return list.length >= 3 ? `C ${list.slice(0, list.length - list.length % 3).join(" ")}` : "";
|
|
283
|
+
case "PolyQuadraticBezierSegment":
|
|
284
|
+
return list.length >= 2 ? `Q ${list.slice(0, list.length - list.length % 2).join(" ")}` : "";
|
|
285
|
+
case "ArcSegment": {
|
|
286
|
+
const size = numberList(segment.getAttribute("Size"));
|
|
287
|
+
if (!list[0] || size.length !== 2) return "";
|
|
288
|
+
const large = segment.getAttribute("IsLargeArc") === "true" ? 1 : 0;
|
|
289
|
+
const sweep = segment.getAttribute("SweepDirection") === "Clockwise" ? 1 : 0;
|
|
290
|
+
const rotation = Number.parseFloat(segment.getAttribute("RotationAngle") ?? "0") || 0;
|
|
291
|
+
return `A ${size[0]},${size[1]} ${rotation} ${large} ${sweep} ${list[0]}`;
|
|
292
|
+
}
|
|
293
|
+
default:
|
|
294
|
+
return "";
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
function parsePathGeometry(element, resolveTransform2) {
|
|
298
|
+
const parts = [];
|
|
299
|
+
const figures = attrLocal(element, "Figures");
|
|
300
|
+
let fillRule = element.getAttribute("FillRule") === "NonZero" ? "nonzero" : "evenodd";
|
|
301
|
+
if (figures) {
|
|
302
|
+
const abbreviated = parseAbbreviatedGeometry(figures);
|
|
303
|
+
parts.push(abbreviated.d);
|
|
304
|
+
if (!element.hasAttribute("FillRule")) fillRule = abbreviated.fillRule;
|
|
305
|
+
}
|
|
306
|
+
for (const figure of elementChildren(element).filter((node) => node.localName === "PathFigure")) {
|
|
307
|
+
const start = points(figure.getAttribute("StartPoint"))[0];
|
|
308
|
+
if (!start) continue;
|
|
309
|
+
let d = `M ${start}`;
|
|
310
|
+
for (const segment of elementChildren(figure)) d += ` ${segmentData(segment)}`;
|
|
311
|
+
if (figure.getAttribute("IsClosed") === "true") d += " Z";
|
|
312
|
+
parts.push(d);
|
|
313
|
+
}
|
|
314
|
+
const transformAttr = element.getAttribute("Transform");
|
|
315
|
+
const transformElement = childNamed(element, "PathGeometry.Transform");
|
|
316
|
+
const matrixElement = transformElement ? elementChildren(transformElement)[0] : void 0;
|
|
317
|
+
const transform = transformAttr ? resolveTransform2(transformAttr) : matrixElement ? parseMatrix(matrixElement.getAttribute("Matrix")) : void 0;
|
|
318
|
+
return { d: parts.join(" ").trim(), fillRule, transform };
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// ../plugins/xps/src/color.ts
|
|
322
|
+
function clamp01(value) {
|
|
323
|
+
return Math.max(0, Math.min(1, Number.isFinite(value) ? value : 0));
|
|
324
|
+
}
|
|
325
|
+
function linearToSrgb(value) {
|
|
326
|
+
const v = clamp01(value);
|
|
327
|
+
return v <= 31308e-7 ? v * 12.92 : 1.055 * v ** (1 / 2.4) - 0.055;
|
|
328
|
+
}
|
|
329
|
+
function css(r, g, b, a) {
|
|
330
|
+
const byte = (v) => Math.round(clamp01(v) * 255);
|
|
331
|
+
return `rgba(${byte(r)},${byte(g)},${byte(b)},${Number(clamp01(a).toFixed(4))})`;
|
|
332
|
+
}
|
|
333
|
+
function parseColor(value) {
|
|
334
|
+
if (!value) return void 0;
|
|
335
|
+
const text = value.trim();
|
|
336
|
+
const hex = /^#([0-9a-f]{6}|[0-9a-f]{8})$/i.exec(text);
|
|
337
|
+
if (hex) {
|
|
338
|
+
const digits = hex[1];
|
|
339
|
+
const n = (offset) => Number.parseInt(digits.slice(offset, offset + 2), 16) / 255;
|
|
340
|
+
return digits.length === 8 ? css(n(2), n(4), n(6), n(0)) : css(n(0), n(2), n(4), 1);
|
|
341
|
+
}
|
|
342
|
+
if (/^sc#/i.test(text)) {
|
|
343
|
+
const parts = text.slice(3).split(/[\s,]+/).filter(Boolean).map(Number);
|
|
344
|
+
if (parts.length !== 3 && parts.length !== 4) return void 0;
|
|
345
|
+
const [a, r, g, b] = parts.length === 4 ? parts : [1, ...parts];
|
|
346
|
+
return css(linearToSrgb(r), linearToSrgb(g), linearToSrgb(b), a);
|
|
347
|
+
}
|
|
348
|
+
const context = /^ContextColor\s+\S+\s+(.+)$/i.exec(text);
|
|
349
|
+
if (context) {
|
|
350
|
+
const [a = 1, ...channels] = context[1].split(/[\s,]+/).filter(Boolean).map(Number);
|
|
351
|
+
if (channels.length === 1) return css(channels[0], channels[0], channels[0], a);
|
|
352
|
+
if (channels.length === 3) return css(channels[0], channels[1], channels[2], a);
|
|
353
|
+
if (channels.length >= 4) {
|
|
354
|
+
const [c, m, y, k] = channels.map(clamp01);
|
|
355
|
+
return css((1 - c) * (1 - k), (1 - m) * (1 - k), (1 - y) * (1 - k), a);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
return void 0;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// ../plugins/xps/src/model.ts
|
|
362
|
+
var ResourceScope = class {
|
|
363
|
+
constructor(parent) {
|
|
364
|
+
this.parent = parent;
|
|
365
|
+
this.entries = /* @__PURE__ */ new Map();
|
|
366
|
+
}
|
|
367
|
+
set(key, entry) {
|
|
368
|
+
this.entries.set(key, entry);
|
|
369
|
+
}
|
|
370
|
+
get(key) {
|
|
371
|
+
return this.entries.get(key) ?? this.parent?.get(key);
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
var STATIC_RESOURCE = /^\s*\{\s*StaticResource\s+([^}\s]+)\s*\}\s*$/;
|
|
375
|
+
var ITALIC_SLANT = Math.tan(20 * Math.PI / 180);
|
|
376
|
+
function dictionarySources(root, pagePart) {
|
|
377
|
+
const out = /* @__PURE__ */ new Set();
|
|
378
|
+
for (const dictionary of descendantsNamed(root, "ResourceDictionary")) {
|
|
379
|
+
const source = dictionary.getAttribute("Source");
|
|
380
|
+
const part = source ? resolvePart(pagePart, source) : void 0;
|
|
381
|
+
if (part) out.add(part);
|
|
382
|
+
}
|
|
383
|
+
return [...out];
|
|
384
|
+
}
|
|
385
|
+
function staticKey(value) {
|
|
386
|
+
return value ? STATIC_RESOURCE.exec(value)?.[1] : void 0;
|
|
387
|
+
}
|
|
388
|
+
function addResources(holder, ctx) {
|
|
389
|
+
if (!holder) return ctx.scope;
|
|
390
|
+
const scope = new ResourceScope(ctx.scope);
|
|
391
|
+
for (const dictionary of elementChildren(holder).filter((node) => node.localName === "ResourceDictionary")) {
|
|
392
|
+
const source = dictionary.getAttribute("Source");
|
|
393
|
+
const remotePart = source ? resolvePart(ctx.base, source) : void 0;
|
|
394
|
+
const remote = remotePart ? ctx.dictionaries.get(remotePart) : void 0;
|
|
395
|
+
const [element, base] = remote ? [remote, remotePart] : [dictionary, ctx.base];
|
|
396
|
+
for (const entry of elementChildren(element)) {
|
|
397
|
+
const key = attrLocal(entry, "Key");
|
|
398
|
+
if (key) scope.set(key, { element: entry, base });
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
return scope;
|
|
402
|
+
}
|
|
403
|
+
function withBase(ctx, base) {
|
|
404
|
+
return base === ctx.base ? ctx : { ...ctx, base };
|
|
405
|
+
}
|
|
406
|
+
function resolveTransform(value, ctx) {
|
|
407
|
+
if (!value) return void 0;
|
|
408
|
+
const key = staticKey(value);
|
|
409
|
+
if (!key) return parseMatrix(value);
|
|
410
|
+
const entry = ctx.scope.get(key);
|
|
411
|
+
return entry?.element.localName === "MatrixTransform" ? parseMatrix(entry.element.getAttribute("Matrix")) : void 0;
|
|
412
|
+
}
|
|
413
|
+
function elementTransform(element, attribute, property, ctx) {
|
|
414
|
+
const attr = element.getAttribute(attribute);
|
|
415
|
+
if (attr) return resolveTransform(attr, ctx);
|
|
416
|
+
const value = propertyValue(element, property);
|
|
417
|
+
return value?.localName === "MatrixTransform" ? parseMatrix(value.getAttribute("Matrix")) : void 0;
|
|
418
|
+
}
|
|
419
|
+
function geometryFrom(element, ctx) {
|
|
420
|
+
if (element.localName !== "PathGeometry") return void 0;
|
|
421
|
+
return parsePathGeometry(element, (value) => resolveTransform(value, ctx));
|
|
422
|
+
}
|
|
423
|
+
function resolveGeometry(element, attribute, ctx) {
|
|
424
|
+
const attr = element.getAttribute(attribute);
|
|
425
|
+
if (attr) {
|
|
426
|
+
const key = staticKey(attr);
|
|
427
|
+
if (!key) return parseAbbreviatedGeometry(attr);
|
|
428
|
+
const entry = ctx.scope.get(key);
|
|
429
|
+
return entry ? geometryFrom(entry.element, withBase(ctx, entry.base)) : void 0;
|
|
430
|
+
}
|
|
431
|
+
const value = propertyValue(element, attribute);
|
|
432
|
+
return value ? geometryFrom(value, ctx) : void 0;
|
|
433
|
+
}
|
|
434
|
+
function point(value) {
|
|
435
|
+
const numbers = numberList(value);
|
|
436
|
+
return [numbers[0] ?? 0, numbers[1] ?? 0];
|
|
437
|
+
}
|
|
438
|
+
function rect(value) {
|
|
439
|
+
const [x = 0, y = 0, width = 0, height = 0] = numberList(value);
|
|
440
|
+
return { x, y, width, height };
|
|
441
|
+
}
|
|
442
|
+
function gradientStops(element) {
|
|
443
|
+
const holder = childNamed(element, `${element.localName}.GradientStops`);
|
|
444
|
+
const stops = [];
|
|
445
|
+
for (const stop of holder ? elementChildren(holder) : []) {
|
|
446
|
+
const color = parseColor(stop.getAttribute("Color"));
|
|
447
|
+
if (color) stops.push({ offset: Math.max(0, Math.min(1, numberAttr(stop, "Offset", 0))), color });
|
|
448
|
+
}
|
|
449
|
+
return stops.sort((a, b) => a.offset - b.offset);
|
|
450
|
+
}
|
|
451
|
+
function imageSourcePart(value, base) {
|
|
452
|
+
if (!value) return void 0;
|
|
453
|
+
const converted = /^\s*\{\s*ColorConvertedBitmap\s+(\S+)/.exec(value);
|
|
454
|
+
return resolvePart(base, converted ? converted[1] : value);
|
|
455
|
+
}
|
|
456
|
+
function brushFrom(element, ctx) {
|
|
457
|
+
const opacity = Math.max(0, Math.min(1, numberAttr(element, "Opacity", 1)));
|
|
458
|
+
const transform = elementTransform(element, "Transform", "Transform", ctx);
|
|
459
|
+
switch (element.localName) {
|
|
460
|
+
case "SolidColorBrush": {
|
|
461
|
+
const color = parseColor(element.getAttribute("Color"));
|
|
462
|
+
return color ? { kind: "solid", color, opacity } : void 0;
|
|
463
|
+
}
|
|
464
|
+
case "LinearGradientBrush": {
|
|
465
|
+
const stops = gradientStops(element);
|
|
466
|
+
if (!stops.length) return void 0;
|
|
467
|
+
return { kind: "linear", opacity, transform, stops, start: point(element.getAttribute("StartPoint")), end: point(element.getAttribute("EndPoint")) };
|
|
468
|
+
}
|
|
469
|
+
case "RadialGradientBrush": {
|
|
470
|
+
const stops = gradientStops(element);
|
|
471
|
+
if (!stops.length) return void 0;
|
|
472
|
+
const center = point(element.getAttribute("Center"));
|
|
473
|
+
const origin = element.hasAttribute("GradientOrigin") ? point(element.getAttribute("GradientOrigin")) : center;
|
|
474
|
+
return {
|
|
475
|
+
kind: "radial",
|
|
476
|
+
opacity,
|
|
477
|
+
transform,
|
|
478
|
+
stops,
|
|
479
|
+
center,
|
|
480
|
+
origin,
|
|
481
|
+
radiusX: numberAttr(element, "RadiusX", 0),
|
|
482
|
+
radiusY: numberAttr(element, "RadiusY", 0)
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
case "ImageBrush":
|
|
486
|
+
case "VisualBrush": {
|
|
487
|
+
const tile = element.getAttribute("TileMode") ?? "None";
|
|
488
|
+
const viewbox = rect(element.getAttribute("Viewbox"));
|
|
489
|
+
const viewport = rect(element.getAttribute("Viewport"));
|
|
490
|
+
if (element.localName === "ImageBrush") {
|
|
491
|
+
const image = imageSourcePart(element.getAttribute("ImageSource"), ctx.base);
|
|
492
|
+
if (!image) return void 0;
|
|
493
|
+
ctx.state.images.add(image);
|
|
494
|
+
return { kind: "image", opacity, transform, tile, viewbox, viewport, image };
|
|
495
|
+
}
|
|
496
|
+
const visual = resolveVisual(element, ctx);
|
|
497
|
+
return visual ? { kind: "visual", opacity, transform, tile, viewbox, viewport, visual } : void 0;
|
|
498
|
+
}
|
|
499
|
+
default:
|
|
500
|
+
return void 0;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
function resolveVisual(brush, ctx) {
|
|
504
|
+
const key = staticKey(brush.getAttribute("Visual"));
|
|
505
|
+
if (key) {
|
|
506
|
+
const entry = ctx.scope.get(key);
|
|
507
|
+
return entry ? parseNode(entry.element, { ...withBase(ctx, entry.base), depth: ctx.depth + 1 }) : void 0;
|
|
508
|
+
}
|
|
509
|
+
const value = propertyValue(brush, "Visual");
|
|
510
|
+
return value ? parseNode(value, { ...ctx, depth: ctx.depth + 1 }) : void 0;
|
|
511
|
+
}
|
|
512
|
+
function resolveBrush(element, attribute, ctx) {
|
|
513
|
+
const attr = element.getAttribute(attribute);
|
|
514
|
+
if (attr) {
|
|
515
|
+
const key = staticKey(attr);
|
|
516
|
+
if (key) {
|
|
517
|
+
const entry = ctx.scope.get(key);
|
|
518
|
+
return entry ? brushFrom(entry.element, withBase(ctx, entry.base)) : void 0;
|
|
519
|
+
}
|
|
520
|
+
const color = parseColor(attr);
|
|
521
|
+
return color ? { kind: "solid", color, opacity: 1 } : void 0;
|
|
522
|
+
}
|
|
523
|
+
const value = propertyValue(element, attribute);
|
|
524
|
+
return value ? brushFrom(value, ctx) : void 0;
|
|
525
|
+
}
|
|
526
|
+
function common(element, ctx) {
|
|
527
|
+
return {
|
|
528
|
+
transform: elementTransform(element, "RenderTransform", "RenderTransform", ctx),
|
|
529
|
+
clip: resolveGeometry(element, "Clip", ctx),
|
|
530
|
+
opacity: Math.max(0, Math.min(1, numberAttr(element, "Opacity", 1))),
|
|
531
|
+
opacityMask: resolveBrush(element, "OpacityMask", ctx)
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
var CAPS = { Flat: "butt", Round: "round", Square: "square", Triangle: "round" };
|
|
535
|
+
var JOINS = { Miter: "miter", Bevel: "bevel", Round: "round" };
|
|
536
|
+
function strokeStyle(element) {
|
|
537
|
+
return {
|
|
538
|
+
width: Math.max(0, numberAttr(element, "StrokeThickness", 1)),
|
|
539
|
+
cap: CAPS[element.getAttribute("StrokeStartLineCap") ?? "Flat"] ?? "butt",
|
|
540
|
+
join: JOINS[element.getAttribute("StrokeLineJoin") ?? "Miter"] ?? "miter",
|
|
541
|
+
miterLimit: Math.max(1, numberAttr(element, "StrokeMiterLimit", 10)),
|
|
542
|
+
dash: numberList(element.getAttribute("StrokeDashArray")).filter((value) => value >= 0),
|
|
543
|
+
dashOffset: numberAttr(element, "StrokeDashOffset", 0)
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
function parseGlyphRun(unicode, indices) {
|
|
547
|
+
const text = unicode.startsWith("{}") ? unicode.slice(2) : unicode;
|
|
548
|
+
const out = [];
|
|
549
|
+
let charPos = 0;
|
|
550
|
+
const nextCodePoint = () => {
|
|
551
|
+
if (charPos >= text.length) return void 0;
|
|
552
|
+
const code = text.codePointAt(charPos);
|
|
553
|
+
charPos += code > 65535 ? 2 : 1;
|
|
554
|
+
return code;
|
|
555
|
+
};
|
|
556
|
+
const entries = indices.trim() ? indices.split(";") : [];
|
|
557
|
+
let clusterGlyphsLeft = 0;
|
|
558
|
+
let clusterChars = 0;
|
|
559
|
+
for (const raw of entries) {
|
|
560
|
+
let entry = raw.trim();
|
|
561
|
+
const cluster = /^\((\d+)(?::(\d+))?\)/.exec(entry);
|
|
562
|
+
let codePoint;
|
|
563
|
+
if (cluster) {
|
|
564
|
+
entry = entry.slice(cluster[0].length);
|
|
565
|
+
clusterChars = Number(cluster[1]);
|
|
566
|
+
clusterGlyphsLeft = Number(cluster[2] ?? 1);
|
|
567
|
+
codePoint = text.codePointAt(charPos);
|
|
568
|
+
} else if (clusterGlyphsLeft === 0) {
|
|
569
|
+
codePoint = nextCodePoint();
|
|
570
|
+
}
|
|
571
|
+
const [index, advance, u, v] = entry.split(",").map((field) => field.trim() === "" ? void 0 : Number(field));
|
|
572
|
+
out.push({
|
|
573
|
+
index: index !== void 0 && Number.isInteger(index) && index >= 0 ? index : void 0,
|
|
574
|
+
codePoint,
|
|
575
|
+
advance: advance !== void 0 && Number.isFinite(advance) ? advance : void 0,
|
|
576
|
+
u: u !== void 0 && Number.isFinite(u) ? u : 0,
|
|
577
|
+
v: v !== void 0 && Number.isFinite(v) ? v : 0
|
|
578
|
+
});
|
|
579
|
+
if (clusterGlyphsLeft > 0 && --clusterGlyphsLeft === 0) charPos += clusterChars;
|
|
580
|
+
}
|
|
581
|
+
for (let code = nextCodePoint(); code !== void 0; code = nextCodePoint()) out.push({ codePoint: code, u: 0, v: 0 });
|
|
582
|
+
return out;
|
|
583
|
+
}
|
|
584
|
+
function parseGlyphs(element, ctx) {
|
|
585
|
+
const fontUri = element.getAttribute("FontUri");
|
|
586
|
+
const font = fontUri ? resolvePart(ctx.base, fontUri) : void 0;
|
|
587
|
+
const size = numberAttr(element, "FontRenderingEmSize", 0);
|
|
588
|
+
if (!font || !(size > 0)) return void 0;
|
|
589
|
+
const unicode = element.getAttribute("UnicodeString") ?? "";
|
|
590
|
+
const glyphs = parseGlyphRun(unicode, element.getAttribute("Indices") ?? "");
|
|
591
|
+
ctx.state.glyphs += glyphs.length;
|
|
592
|
+
if (ctx.state.glyphs > XPS_LIMITS.pageGlyphs) throw new XpsLimitError("Too many glyphs on one page.");
|
|
593
|
+
const face = Number.parseInt(uriFragment(fontUri ?? "") ?? "0", 10) || 0;
|
|
594
|
+
ctx.state.fonts.add(`${font}#${face}`);
|
|
595
|
+
const simulations = element.getAttribute("StyleSimulations") ?? "None";
|
|
596
|
+
return {
|
|
597
|
+
kind: "glyphs",
|
|
598
|
+
...common(element, ctx),
|
|
599
|
+
font: `${font}#${face}`,
|
|
600
|
+
size,
|
|
601
|
+
x: numberAttr(element, "OriginX", 0),
|
|
602
|
+
y: numberAttr(element, "OriginY", 0),
|
|
603
|
+
text: unicode.startsWith("{}") ? unicode.slice(2) : unicode,
|
|
604
|
+
glyphs,
|
|
605
|
+
rtl: Number.parseInt(element.getAttribute("BidiLevel") ?? "0", 10) % 2 === 1,
|
|
606
|
+
bold: simulations.includes("Bold"),
|
|
607
|
+
italic: simulations.includes("Italic"),
|
|
608
|
+
fill: resolveBrush(element, "Fill", ctx)
|
|
609
|
+
};
|
|
610
|
+
}
|
|
611
|
+
function parseNode(element, ctx) {
|
|
612
|
+
if (ctx.depth > XPS_LIMITS.nestingDepth) throw new XpsLimitError("FixedPage nesting is too deep.");
|
|
613
|
+
if (++ctx.state.nodes > XPS_LIMITS.pageNodes) throw new XpsLimitError("Too many elements on one page.");
|
|
614
|
+
switch (element.localName) {
|
|
615
|
+
case "Canvas": {
|
|
616
|
+
const scope = addResources(childNamed(element, "Canvas.Resources"), ctx);
|
|
617
|
+
const inner = { ...ctx, scope, depth: ctx.depth + 1 };
|
|
618
|
+
return { kind: "canvas", ...common(element, inner), children: parseChildren(element, inner) };
|
|
619
|
+
}
|
|
620
|
+
case "Path": {
|
|
621
|
+
const geometry = resolveGeometry(element, "Data", ctx);
|
|
622
|
+
if (!geometry?.d) return void 0;
|
|
623
|
+
const fill = resolveBrush(element, "Fill", ctx);
|
|
624
|
+
const stroke = resolveBrush(element, "Stroke", ctx);
|
|
625
|
+
if (!fill && !stroke) return void 0;
|
|
626
|
+
return { kind: "path", ...common(element, ctx), geometry, fill, stroke, strokeStyle: strokeStyle(element) };
|
|
627
|
+
}
|
|
628
|
+
case "Glyphs":
|
|
629
|
+
return parseGlyphs(element, ctx);
|
|
630
|
+
default:
|
|
631
|
+
return void 0;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
function parseChildren(element, ctx) {
|
|
635
|
+
const out = [];
|
|
636
|
+
for (const child of elementChildren(element)) {
|
|
637
|
+
if (child.localName.includes(".")) continue;
|
|
638
|
+
const node = parseNode(child, ctx);
|
|
639
|
+
if (node) out.push(node);
|
|
640
|
+
}
|
|
641
|
+
return out;
|
|
642
|
+
}
|
|
643
|
+
function buildPage(root, pagePart, dictionaries) {
|
|
644
|
+
const state = { nodes: 0, glyphs: 0, fonts: /* @__PURE__ */ new Set(), images: /* @__PURE__ */ new Set() };
|
|
645
|
+
const base = { base: pagePart, scope: new ResourceScope(), depth: 0, state, dictionaries };
|
|
646
|
+
const ctx = { ...base, scope: addResources(childNamed(root, "FixedPage.Resources"), base) };
|
|
647
|
+
const width = numberAttr(root, "Width", 0);
|
|
648
|
+
const height = numberAttr(root, "Height", 0);
|
|
649
|
+
const children = parseChildren(root, ctx);
|
|
650
|
+
return {
|
|
651
|
+
width: width > 0 ? width : 816,
|
|
652
|
+
height: height > 0 ? height : 1056,
|
|
653
|
+
root: { kind: "canvas", opacity: 1, children },
|
|
654
|
+
fonts: state.fonts,
|
|
655
|
+
images: state.images
|
|
656
|
+
};
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
// ../plugins/xps/src/document.ts
|
|
660
|
+
var FIXED_REPRESENTATION = /\/fixedrepresentation$/i;
|
|
661
|
+
var DOCUMENT_STRUCTURE = /\/documentstructure$/i;
|
|
662
|
+
var CORE_PROPERTIES = /\/core-properties$/i;
|
|
663
|
+
var MAX_PROPERTIES = 64;
|
|
664
|
+
function positive(value) {
|
|
665
|
+
const number = value === null ? Number.NaN : Number.parseFloat(value);
|
|
666
|
+
return Number.isFinite(number) && number > 0 ? number : void 0;
|
|
667
|
+
}
|
|
668
|
+
async function findSequencePart(pkg) {
|
|
669
|
+
const rels = await pkg.relationships("");
|
|
670
|
+
const fromRels = rels.find((rel) => FIXED_REPRESENTATION.test(rel.type) && pkg.has(rel.target));
|
|
671
|
+
if (fromRels) return fromRels.target;
|
|
672
|
+
return pkg.names.find((name) => name.endsWith(".fdseq"));
|
|
673
|
+
}
|
|
674
|
+
async function readFixedDocument(pkg, part, out) {
|
|
675
|
+
const root = parseXml(await pkg.text(part));
|
|
676
|
+
if (root.localName !== "FixedDocument") throw new XpsFormatError("Not a FixedDocument.");
|
|
677
|
+
for (const content of childrenNamed(root, "PageContent")) {
|
|
678
|
+
const page = resolvePart(part, content.getAttribute("Source") ?? "");
|
|
679
|
+
if (!page) continue;
|
|
680
|
+
if (out.pages.length >= XPS_LIMITS.pages) throw new XpsLimitError("Too many pages.");
|
|
681
|
+
const index = out.pages.length;
|
|
682
|
+
out.pages.push({ part: page, width: positive(content.getAttribute("Width")), height: positive(content.getAttribute("Height")) });
|
|
683
|
+
out.targets.set(partKey(page), index);
|
|
684
|
+
const holder = childNamed(content, "PageContent.LinkTargets");
|
|
685
|
+
for (const target of holder ? childrenNamed(holder, "LinkTarget") : []) {
|
|
686
|
+
const name = target.getAttribute("Name");
|
|
687
|
+
if (name && !out.targets.has(name)) out.targets.set(name, index);
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
function resolveOutlineTarget(base, target, targets) {
|
|
692
|
+
const fragment = uriFragment(target);
|
|
693
|
+
if (fragment && targets.has(fragment)) return targets.get(fragment);
|
|
694
|
+
const part = resolvePart(base, target);
|
|
695
|
+
return part ? targets.get(partKey(part)) : void 0;
|
|
696
|
+
}
|
|
697
|
+
async function readOutline(pkg, documents, targets) {
|
|
698
|
+
const roots = [];
|
|
699
|
+
const stack = [{ level: 0, children: roots }];
|
|
700
|
+
let count = 0;
|
|
701
|
+
for (const document of documents) {
|
|
702
|
+
const structure = (await pkg.relationships(document)).find((rel) => DOCUMENT_STRUCTURE.test(rel.type));
|
|
703
|
+
if (!structure || !pkg.has(structure.target)) continue;
|
|
704
|
+
let root;
|
|
705
|
+
try {
|
|
706
|
+
root = parseXml(await pkg.text(structure.target));
|
|
707
|
+
} catch (error) {
|
|
708
|
+
if (error instanceof XpsFormatError) continue;
|
|
709
|
+
throw error;
|
|
710
|
+
}
|
|
711
|
+
for (const entry of descendantsNamed(root, "OutlineEntry")) {
|
|
712
|
+
if (++count > XPS_LIMITS.outlineEntries) return roots;
|
|
713
|
+
const page = resolveOutlineTarget(structure.target, entry.getAttribute("OutlineTarget") ?? "", targets);
|
|
714
|
+
const title = (attrLocal(entry, "Description") ?? "").trim();
|
|
715
|
+
if (page === void 0 || !title) continue;
|
|
716
|
+
const level = Math.max(1, Math.min(9, Number.parseInt(entry.getAttribute("OutlineLevel") ?? "1", 10) || 1));
|
|
717
|
+
while (stack.length > 1 && stack.at(-1).level >= level) stack.pop();
|
|
718
|
+
const item = { title, page, children: [] };
|
|
719
|
+
stack.at(-1).children.push(item);
|
|
720
|
+
stack.push({ level, children: item.children });
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
return roots;
|
|
724
|
+
}
|
|
725
|
+
async function loadXpsDocument(pkg) {
|
|
726
|
+
const sequence = await findSequencePart(pkg);
|
|
727
|
+
const out = { pages: [], targets: /* @__PURE__ */ new Map() };
|
|
728
|
+
const documents = [];
|
|
729
|
+
let openXps = false;
|
|
730
|
+
if (sequence) {
|
|
731
|
+
const root = parseXml(await pkg.text(sequence));
|
|
732
|
+
if (root.localName !== "FixedDocumentSequence") throw new XpsFormatError("Not a FixedDocumentSequence.");
|
|
733
|
+
openXps = (root.namespaceURI ?? "").includes("openxps");
|
|
734
|
+
for (const reference of elementChildren(root).filter((node) => node.localName === "DocumentReference")) {
|
|
735
|
+
const part = resolvePart(sequence, reference.getAttribute("Source") ?? "");
|
|
736
|
+
if (part && pkg.has(part)) documents.push(part);
|
|
737
|
+
}
|
|
738
|
+
} else {
|
|
739
|
+
const fdoc = pkg.names.find((name) => name.endsWith(".fdoc"));
|
|
740
|
+
if (fdoc) documents.push(fdoc);
|
|
741
|
+
}
|
|
742
|
+
for (const document of documents) await readFixedDocument(pkg, document, out);
|
|
743
|
+
const pages = out.pages.filter((page) => pkg.has(page.part));
|
|
744
|
+
if (pages.length === 0) throw new XpsFormatError("The package has no fixed pages.");
|
|
745
|
+
const outline = pages.length === out.pages.length ? await readOutline(pkg, documents, out.targets) : [];
|
|
746
|
+
return { pages, outline, openXps, documents };
|
|
747
|
+
}
|
|
748
|
+
async function loadXpsPage(pkg, part) {
|
|
749
|
+
const root = parseXml(await pkg.text(part));
|
|
750
|
+
if (root.localName !== "FixedPage") throw new XpsFormatError("Not a FixedPage.");
|
|
751
|
+
const dictionaries = /* @__PURE__ */ new Map();
|
|
752
|
+
for (const source of dictionarySources(root, part)) {
|
|
753
|
+
if (!pkg.has(source)) continue;
|
|
754
|
+
const dictionary = parseXml(await pkg.text(source));
|
|
755
|
+
if (dictionary.localName === "ResourceDictionary") dictionaries.set(source, dictionary);
|
|
756
|
+
}
|
|
757
|
+
return buildPage(root, part, dictionaries);
|
|
758
|
+
}
|
|
759
|
+
async function loadXpsProperties(pkg) {
|
|
760
|
+
const rel = (await pkg.relationships("")).find((item) => CORE_PROPERTIES.test(item.type) && pkg.has(item.target));
|
|
761
|
+
const properties = {};
|
|
762
|
+
if (!rel) return properties;
|
|
763
|
+
let root;
|
|
764
|
+
try {
|
|
765
|
+
root = parseXml(await pkg.text(rel.target));
|
|
766
|
+
} catch (error) {
|
|
767
|
+
if (error instanceof XpsFormatError) return properties;
|
|
768
|
+
throw error;
|
|
769
|
+
}
|
|
770
|
+
for (const node of elementChildren(root).slice(0, MAX_PROPERTIES)) {
|
|
771
|
+
const value = node.textContent?.trim();
|
|
772
|
+
if (value && !node.children.length) properties[node.localName] = value;
|
|
773
|
+
}
|
|
774
|
+
return properties;
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
// ../plugins/xps/src/text.ts
|
|
778
|
+
var MAX_WORDS = 2e4;
|
|
779
|
+
function runWidth(node, font) {
|
|
780
|
+
let width = 0;
|
|
781
|
+
for (const glyph of node.glyphs) {
|
|
782
|
+
if (glyph.advance !== void 0) width += glyph.advance * node.size / 100;
|
|
783
|
+
else if (font) {
|
|
784
|
+
const id = glyph.index ?? (glyph.codePoint === void 0 ? 0 : font.glyphIndex(glyph.codePoint));
|
|
785
|
+
width += font.advance(id) * node.size / font.unitsPerEm;
|
|
786
|
+
} else width += node.size * 0.5;
|
|
787
|
+
}
|
|
788
|
+
return width;
|
|
789
|
+
}
|
|
790
|
+
function extractPageText(page, fonts) {
|
|
791
|
+
const words = [];
|
|
792
|
+
const visit = (node, parent) => {
|
|
793
|
+
if (words.length >= MAX_WORDS) return;
|
|
794
|
+
const matrix = node.transform ? multiply(node.transform, parent) : parent;
|
|
795
|
+
if (node.kind === "canvas") {
|
|
796
|
+
for (const child of node.children) visit(child, matrix);
|
|
797
|
+
return;
|
|
798
|
+
}
|
|
799
|
+
if (node.kind !== "glyphs" || !node.text.trim()) return;
|
|
800
|
+
const width = runWidth(node, fonts?.get(node.font));
|
|
801
|
+
const left = node.rtl ? node.x - width : node.x;
|
|
802
|
+
const top = node.y - node.size * 0.8;
|
|
803
|
+
const corners = [
|
|
804
|
+
applyMatrix(matrix, left, top),
|
|
805
|
+
applyMatrix(matrix, left + width, top),
|
|
806
|
+
applyMatrix(matrix, left, node.y + node.size * 0.2),
|
|
807
|
+
applyMatrix(matrix, left + width, node.y + node.size * 0.2)
|
|
808
|
+
];
|
|
809
|
+
const xs = corners.map(([x2]) => x2);
|
|
810
|
+
const ys = corners.map(([, y2]) => y2);
|
|
811
|
+
const x = Math.min(...xs);
|
|
812
|
+
const y = Math.min(...ys);
|
|
813
|
+
words.push({
|
|
814
|
+
x: x / page.width,
|
|
815
|
+
y: y / page.height,
|
|
816
|
+
w: (Math.max(...xs) - x) / page.width,
|
|
817
|
+
h: (Math.max(...ys) - y) / page.height,
|
|
818
|
+
text: node.text
|
|
819
|
+
});
|
|
820
|
+
};
|
|
821
|
+
visit(page.root, IDENTITY);
|
|
822
|
+
return words.length ? { scale: 1, words } : null;
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
// ../plugins/xps/src/extract.ts
|
|
826
|
+
var PLUGIN_ID = "xps-reader";
|
|
827
|
+
function mapError(error) {
|
|
828
|
+
if (error instanceof AgentError || isViewerAbortError(error)) throw error;
|
|
829
|
+
if (error instanceof XpsLimitError) {
|
|
830
|
+
throw new AgentError("resource-limit", "The XPS document exceeds safety limits.", { pluginId: PLUGIN_ID, cause: error });
|
|
831
|
+
}
|
|
832
|
+
throw new AgentError("invalid-file", "The file is not a readable XPS document.", { pluginId: PLUGIN_ID, cause: error });
|
|
833
|
+
}
|
|
834
|
+
async function withDocument(context, run) {
|
|
835
|
+
if (context.signal.aborted) throw abortError();
|
|
836
|
+
if (context.file.size > XPS_LIMITS.maxInputBytes) {
|
|
837
|
+
throw new AgentError("resource-limit", "The XPS document exceeds safety limits.", { pluginId: PLUGIN_ID });
|
|
838
|
+
}
|
|
839
|
+
let pkg;
|
|
840
|
+
try {
|
|
841
|
+
pkg = await XpsPackage.open(context.file, context.signal);
|
|
842
|
+
return await run({ pkg, doc: await loadXpsDocument(pkg) });
|
|
843
|
+
} catch (error) {
|
|
844
|
+
return mapError(error);
|
|
845
|
+
} finally {
|
|
846
|
+
await pkg?.close();
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
function textLines(words) {
|
|
850
|
+
const lines = [];
|
|
851
|
+
let previous;
|
|
852
|
+
for (const word of words) {
|
|
853
|
+
const text = word.text.trim();
|
|
854
|
+
const sameLine = previous && Math.abs(word.y + word.h / 2 - (previous.y + previous.h / 2)) < Math.min(word.h, previous.h) / 2;
|
|
855
|
+
if (sameLine && lines.length) lines[lines.length - 1] += ` ${text}`;
|
|
856
|
+
else lines.push(text);
|
|
857
|
+
previous = word;
|
|
858
|
+
}
|
|
859
|
+
return lines;
|
|
860
|
+
}
|
|
861
|
+
async function pageMarkdown({ pkg, doc }, index, signal) {
|
|
862
|
+
if (signal.aborted) throw abortError();
|
|
863
|
+
const lines = textLines(extractPageText(await loadXpsPage(pkg, doc.pages[index].part))?.words ?? []);
|
|
864
|
+
return [`## Page ${index + 1}`, "", ...lines.length ? lines : ["(no text on this page)"]].join("\n");
|
|
865
|
+
}
|
|
866
|
+
var xpsExtractor = {
|
|
867
|
+
inspect(context) {
|
|
868
|
+
return withDocument(context, async ({ pkg, doc }) => ({
|
|
869
|
+
metadata: {
|
|
870
|
+
format: doc.openXps ? "OpenXPS" : "XPS",
|
|
871
|
+
properties: await loadXpsProperties(pkg),
|
|
872
|
+
fixedDocuments: doc.documents.length,
|
|
873
|
+
pageCount: doc.pages.length,
|
|
874
|
+
outlineEntries: doc.outline.length,
|
|
875
|
+
sizeBytes: context.source.size
|
|
876
|
+
},
|
|
877
|
+
targets: doc.pages.map((_, index) => ({ id: `page:${index + 1}`, title: `Page ${index + 1}`, kind: "page" }))
|
|
878
|
+
}));
|
|
879
|
+
},
|
|
880
|
+
read(context, params) {
|
|
881
|
+
return withDocument(context, async (loaded) => {
|
|
882
|
+
return readPagedTextDocument({
|
|
883
|
+
pageCount: loaded.doc.pages.length,
|
|
884
|
+
header: async () => {
|
|
885
|
+
const { title, ...fields } = await loadXpsProperties(loaded.pkg);
|
|
886
|
+
return markdownDocumentHeader(title ?? context.file.name, fields);
|
|
887
|
+
},
|
|
888
|
+
page: (index) => pageMarkdown(loaded, index, context.signal)
|
|
889
|
+
}, params, PLUGIN_ID);
|
|
890
|
+
});
|
|
891
|
+
}
|
|
892
|
+
};
|
|
893
|
+
var extract_default = xpsExtractor;
|
|
894
|
+
export {
|
|
895
|
+
extract_default as default
|
|
896
|
+
};
|