@novaprose/core 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -2
- package/dist/a11y.cjs +314 -0
- package/dist/a11y.cjs.map +1 -0
- package/dist/a11y.d.cts +51 -0
- package/dist/a11y.d.ts +51 -0
- package/dist/a11y.js +11 -0
- package/dist/a11y.js.map +1 -0
- package/dist/a11ychecker-7KQU7DD3.js +449 -0
- package/dist/a11ychecker-7KQU7DD3.js.map +1 -0
- package/dist/accordion-ui-FGN3I5UF.js +201 -0
- package/dist/accordion-ui-FGN3I5UF.js.map +1 -0
- package/dist/advcode-65Z2ELUB.js +51 -0
- package/dist/advcode-65Z2ELUB.js.map +1 -0
- package/dist/advcode-editor-WIOCY552.js +257 -0
- package/dist/advcode-editor-WIOCY552.js.map +1 -0
- package/dist/{advlist-5FNKPLUX.js → advlist-CEHE6YXS.js} +10 -7
- package/dist/advlist-CEHE6YXS.js.map +1 -0
- package/dist/advtable-ui-5CBOPTHW.js +364 -0
- package/dist/advtable-ui-5CBOPTHW.js.map +1 -0
- package/dist/ai-IRQYZHRK.js +1485 -0
- package/dist/ai-IRQYZHRK.js.map +1 -0
- package/dist/anchor-ui-NWIIRKGY.js +81 -0
- package/dist/anchor-ui-NWIIRKGY.js.map +1 -0
- package/dist/autocorrect-6GFLVDPC.js +851 -0
- package/dist/autocorrect-6GFLVDPC.js.map +1 -0
- package/dist/{autolink-45LTODWB.js → autolink-N427KVQO.js} +11 -8
- package/dist/autolink-N427KVQO.js.map +1 -0
- package/dist/{autoresize-UB3GOA6D.js → autoresize-YRZAVCNO.js} +2 -2
- package/dist/autoresize-YRZAVCNO.js.map +1 -0
- package/dist/{autosave-GMWJ5BPE.js → autosave-L7OZ3KLK.js} +7 -7
- package/dist/autosave-L7OZ3KLK.js.map +1 -0
- package/dist/casechange-5G6RAJ7K.js +201 -0
- package/dist/casechange-5G6RAJ7K.js.map +1 -0
- package/dist/{charmap-2GC7LF7G.js → charmap-5CBBDWOP.js} +7 -7
- package/dist/charmap-5CBBDWOP.js.map +1 -0
- package/dist/checklist-HM4VXZKY.js +189 -0
- package/dist/checklist-HM4VXZKY.js.map +1 -0
- package/dist/chunk-23ZLVT5D.js +163 -0
- package/dist/chunk-23ZLVT5D.js.map +1 -0
- package/dist/{chunk-ND2CWNVG.js → chunk-3BOK3S3T.js} +2 -27
- package/dist/chunk-3BOK3S3T.js.map +1 -0
- package/dist/chunk-4I4AYH2K.js +101 -0
- package/dist/chunk-4I4AYH2K.js.map +1 -0
- package/dist/{chunk-PVFKXRID.js → chunk-4VPDY3LF.js} +1 -1
- package/dist/chunk-4VPDY3LF.js.map +1 -0
- package/dist/chunk-53AY5NAF.js +214 -0
- package/dist/chunk-53AY5NAF.js.map +1 -0
- package/dist/chunk-5VCESSQB.js +137 -0
- package/dist/chunk-5VCESSQB.js.map +1 -0
- package/dist/chunk-66INZHZ2.js +79 -0
- package/dist/chunk-66INZHZ2.js.map +1 -0
- package/dist/chunk-6LQM7G4V.js +159 -0
- package/dist/chunk-6LQM7G4V.js.map +1 -0
- package/dist/chunk-6YSQGFV7.js +893 -0
- package/dist/chunk-6YSQGFV7.js.map +1 -0
- package/dist/{chunk-T3GY6IVK.js → chunk-AC3YCAX4.js} +71 -9
- package/dist/chunk-AC3YCAX4.js.map +1 -0
- package/dist/{chunk-5AW2HHG6.js → chunk-ADRPQLZ2.js} +47 -3
- package/dist/chunk-ADRPQLZ2.js.map +1 -0
- package/dist/chunk-ANE5ASXG.js +26 -0
- package/dist/chunk-ANE5ASXG.js.map +1 -0
- package/dist/{chunk-Z3ELZ77W.js → chunk-AP2PJFLB.js} +5 -2
- package/dist/chunk-AP2PJFLB.js.map +1 -0
- package/dist/chunk-AQV6FIKK.js +259 -0
- package/dist/chunk-AQV6FIKK.js.map +1 -0
- package/dist/chunk-AUQSATWL.js +322 -0
- package/dist/chunk-AUQSATWL.js.map +1 -0
- package/dist/chunk-C326LHHU.js +143 -0
- package/dist/chunk-C326LHHU.js.map +1 -0
- package/dist/{chunk-R2UMUCVI.js → chunk-DEYYVZ7O.js} +50 -8
- package/dist/chunk-DEYYVZ7O.js.map +1 -0
- package/dist/chunk-EOJ5XHKA.js +160 -0
- package/dist/chunk-EOJ5XHKA.js.map +1 -0
- package/dist/chunk-EXX2S352.js +3642 -0
- package/dist/chunk-EXX2S352.js.map +1 -0
- package/dist/chunk-FTEA6L2Q.js +47 -0
- package/dist/chunk-FTEA6L2Q.js.map +1 -0
- package/dist/chunk-G74HNSB6.js +9 -0
- package/dist/chunk-G74HNSB6.js.map +1 -0
- package/dist/{chunk-KWXFL4WS.js → chunk-GHVB6SV4.js} +8 -5
- package/dist/chunk-GHVB6SV4.js.map +1 -0
- package/dist/chunk-GTLE2HEW.js +108 -0
- package/dist/chunk-GTLE2HEW.js.map +1 -0
- package/dist/chunk-GXXXLPDQ.js +67 -0
- package/dist/chunk-GXXXLPDQ.js.map +1 -0
- package/dist/chunk-HC6RMBAD.js +163 -0
- package/dist/chunk-HC6RMBAD.js.map +1 -0
- package/dist/chunk-HNEAVVBC.js +98 -0
- package/dist/chunk-HNEAVVBC.js.map +1 -0
- package/dist/chunk-I7Y4KSM2.js +165 -0
- package/dist/chunk-I7Y4KSM2.js.map +1 -0
- package/dist/chunk-IG2BL4ON.js +127 -0
- package/dist/chunk-IG2BL4ON.js.map +1 -0
- package/dist/{chunk-KPE3QRPB.js → chunk-J6W2CDRF.js} +16 -315
- package/dist/chunk-J6W2CDRF.js.map +1 -0
- package/dist/chunk-LVEQBNLX.js +207 -0
- package/dist/chunk-LVEQBNLX.js.map +1 -0
- package/dist/chunk-MZGNOHSY.js +176 -0
- package/dist/chunk-MZGNOHSY.js.map +1 -0
- package/dist/chunk-N32H37AJ.js +373 -0
- package/dist/chunk-N32H37AJ.js.map +1 -0
- package/dist/chunk-NTGEKGXU.js +263 -0
- package/dist/chunk-NTGEKGXU.js.map +1 -0
- package/dist/chunk-OFHGXYG3.js +140 -0
- package/dist/chunk-OFHGXYG3.js.map +1 -0
- package/dist/chunk-OOVNE6MB.js +28 -0
- package/dist/chunk-OOVNE6MB.js.map +1 -0
- package/dist/chunk-OQMMHWMZ.js +7 -0
- package/dist/chunk-OQMMHWMZ.js.map +1 -0
- package/dist/chunk-P2UU2NLT.js +1149 -0
- package/dist/chunk-P2UU2NLT.js.map +1 -0
- package/dist/{chunk-JPJVTB45.js → chunk-QU3KXMYT.js} +8 -2
- package/dist/chunk-QU3KXMYT.js.map +1 -0
- package/dist/chunk-S2XZRKHA.js +29 -0
- package/dist/chunk-S2XZRKHA.js.map +1 -0
- package/dist/chunk-SCIRO4XK.js +144 -0
- package/dist/chunk-SCIRO4XK.js.map +1 -0
- package/dist/chunk-T3IRLTKK.js +158 -0
- package/dist/chunk-T3IRLTKK.js.map +1 -0
- package/dist/chunk-TABIUD2L.js +66 -0
- package/dist/chunk-TABIUD2L.js.map +1 -0
- package/dist/{chunk-FCMZ7TUQ.js → chunk-TAM2FHKG.js} +172 -43
- package/dist/chunk-TAM2FHKG.js.map +1 -0
- package/dist/chunk-UTMS2P2K.js +288 -0
- package/dist/chunk-UTMS2P2K.js.map +1 -0
- package/dist/{chunk-HPLT3XRZ.js → chunk-V7WUHUHM.js} +13 -1
- package/dist/chunk-V7WUHUHM.js.map +1 -0
- package/dist/{table-SSNABG5W.js → chunk-VK6YF2AA.js} +119 -61
- package/dist/chunk-VK6YF2AA.js.map +1 -0
- package/dist/chunk-WAOU5NGN.js +430 -0
- package/dist/chunk-WAOU5NGN.js.map +1 -0
- package/dist/chunk-XIH4SCO6.js +112 -0
- package/dist/chunk-XIH4SCO6.js.map +1 -0
- package/dist/chunk-XR7CY4NI.js +11 -0
- package/dist/chunk-XR7CY4NI.js.map +1 -0
- package/dist/chunk-YDF55N6Z.js +164 -0
- package/dist/chunk-YDF55N6Z.js.map +1 -0
- package/dist/chunk-YDPZCVXS.js +923 -0
- package/dist/chunk-YDPZCVXS.js.map +1 -0
- package/dist/chunk-YG5V7POU.js +137 -0
- package/dist/chunk-YG5V7POU.js.map +1 -0
- package/dist/chunk-YVSUR7E5.js +151 -0
- package/dist/chunk-YVSUR7E5.js.map +1 -0
- package/dist/codesample-GHWIC7PT.js +546 -0
- package/dist/codesample-GHWIC7PT.js.map +1 -0
- package/dist/{comments-panel-HXMWSRAW.js → comments-panel-SOLBZ46Q.js} +9 -5
- package/dist/comments-panel-SOLBZ46Q.js.map +1 -0
- package/dist/{directionality-5JLWQGP2.js → directionality-EGQKGDZA.js} +13 -10
- package/dist/directionality-EGQKGDZA.js.map +1 -0
- package/dist/document-0ft41E6d.d.ts +39 -0
- package/dist/document-IQqDDT4v.d.cts +39 -0
- package/dist/docx.cjs +23518 -0
- package/dist/docx.cjs.map +1 -0
- package/dist/docx.d.cts +83 -0
- package/dist/docx.d.ts +83 -0
- package/dist/docx.js +1821 -0
- package/dist/docx.js.map +1 -0
- package/dist/draghandle-U6CYZHPA.js +389 -0
- package/dist/draghandle-U6CYZHPA.js.map +1 -0
- package/dist/editimage-5EWPSM22.js +683 -0
- package/dist/editimage-5EWPSM22.js.map +1 -0
- package/dist/editor-BCMxe1M4.d.cts +2888 -0
- package/dist/editor-Dmtwjw2u.d.ts +2888 -0
- package/dist/email-ELNMEQ6E.js +177 -0
- package/dist/email-ELNMEQ6E.js.map +1 -0
- package/dist/email.cjs +588 -0
- package/dist/email.cjs.map +1 -0
- package/dist/email.d.cts +7 -0
- package/dist/email.d.ts +7 -0
- package/dist/email.js +21 -0
- package/dist/email.js.map +1 -0
- package/dist/{emoticons-ZD6ZRIWG.js → emoticons-EGHNZKSA.js} +7 -7
- package/dist/emoticons-EGHNZKSA.js.map +1 -0
- package/dist/exportpdf-4P7X3NY2.js +91 -0
- package/dist/exportpdf-4P7X3NY2.js.map +1 -0
- package/dist/exportword-JFJ3KTYZ.js +16 -0
- package/dist/exportword-JFJ3KTYZ.js.map +1 -0
- package/dist/footnotes-ui-FV6QRGDA.js +449 -0
- package/dist/footnotes-ui-FV6QRGDA.js.map +1 -0
- package/dist/form-dialog-SNWFPM2K.js +379 -0
- package/dist/form-dialog-SNWFPM2K.js.map +1 -0
- package/dist/formatpainter-IEXX27OJ.js +209 -0
- package/dist/formatpainter-IEXX27OJ.js.map +1 -0
- package/dist/fullpagehtml-ui-RE4C2NO5.js +220 -0
- package/dist/fullpagehtml-ui-RE4C2NO5.js.map +1 -0
- package/dist/html-rules-api-BLDDW9MO.d.cts +42 -0
- package/dist/html-rules-api-BLDDW9MO.d.ts +42 -0
- package/dist/html-rules.cjs +19 -17
- package/dist/html-rules.cjs.map +1 -1
- package/dist/html-rules.d.cts +37 -35
- package/dist/html-rules.d.ts +37 -35
- package/dist/html-rules.js +24 -20
- package/dist/html-rules.js.map +1 -1
- package/dist/i18n/de.cjs +346 -0
- package/dist/i18n/de.cjs.map +1 -1
- package/dist/i18n/de.d.cts +1 -1
- package/dist/i18n/de.d.ts +1 -1
- package/dist/i18n/de.js +346 -0
- package/dist/i18n/de.js.map +1 -1
- package/dist/i18n/es.cjs +346 -0
- package/dist/i18n/es.cjs.map +1 -1
- package/dist/i18n/es.d.cts +1 -1
- package/dist/i18n/es.d.ts +1 -1
- package/dist/i18n/es.js +346 -0
- package/dist/i18n/es.js.map +1 -1
- package/dist/i18n/fr.cjs +346 -0
- package/dist/i18n/fr.cjs.map +1 -1
- package/dist/i18n/fr.d.cts +1 -1
- package/dist/i18n/fr.d.ts +1 -1
- package/dist/i18n/fr.js +346 -0
- package/dist/i18n/fr.js.map +1 -1
- package/dist/i18n/it.cjs +346 -0
- package/dist/i18n/it.cjs.map +1 -1
- package/dist/i18n/it.d.cts +1 -1
- package/dist/i18n/it.d.ts +1 -1
- package/dist/i18n/it.js +346 -0
- package/dist/i18n/it.js.map +1 -1
- package/dist/i18n/pt-BR.cjs +346 -0
- package/dist/i18n/pt-BR.cjs.map +1 -1
- package/dist/i18n/pt-BR.d.cts +1 -1
- package/dist/i18n/pt-BR.d.ts +1 -1
- package/dist/i18n/pt-BR.js +346 -0
- package/dist/i18n/pt-BR.js.map +1 -1
- package/dist/i18n/ru.cjs +346 -0
- package/dist/i18n/ru.cjs.map +1 -1
- package/dist/i18n/ru.d.cts +3 -3
- package/dist/i18n/ru.d.ts +3 -3
- package/dist/i18n/ru.js +346 -0
- package/dist/i18n/ru.js.map +1 -1
- package/dist/importcss-JLNIRKGH.js +127 -0
- package/dist/importcss-JLNIRKGH.js.map +1 -0
- package/dist/importword-D7Z6RXGQ.js +73 -0
- package/dist/importword-D7Z6RXGQ.js.map +1 -0
- package/dist/{index-C603bU6r.d.ts → index-CZ9yDvmQ.d.cts} +36 -17
- package/dist/{index-C603bU6r.d.cts → index-CZ9yDvmQ.d.ts} +36 -17
- package/dist/index.cjs +28858 -10442
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +138 -64
- package/dist/index.d.ts +138 -64
- package/dist/index.js +199 -1411
- package/dist/index.js.map +1 -1
- package/dist/{insertdatetime-CRO7TJAQ.js → insertdatetime-YW2VHYZH.js} +7 -7
- package/dist/insertdatetime-YW2VHYZH.js.map +1 -0
- package/dist/linkchecker-3S3MCPOS.js +287 -0
- package/dist/linkchecker-3S3MCPOS.js.map +1 -0
- package/dist/markdown-26O3N3T2.js +136 -0
- package/dist/markdown-26O3N3T2.js.map +1 -0
- package/dist/markdown.cjs +94 -11
- package/dist/markdown.cjs.map +1 -1
- package/dist/markdown.d.cts +12 -10
- package/dist/markdown.d.ts +12 -10
- package/dist/markdown.js +4 -235
- package/dist/markdown.js.map +1 -1
- package/dist/math-ui-RUTCHTRY.js +157 -0
- package/dist/math-ui-RUTCHTRY.js.map +1 -0
- package/dist/media-ui-36TE3CJD.js +123 -0
- package/dist/media-ui-36TE3CJD.js.map +1 -0
- package/dist/mediaembed-ui-ZNTGZ2SQ.js +207 -0
- package/dist/mediaembed-ui-ZNTGZ2SQ.js.map +1 -0
- package/dist/mentions-ui-O4IPWQT4.js +58 -0
- package/dist/mentions-ui-O4IPWQT4.js.map +1 -0
- package/dist/mergetags-ui-HS3Q2R36.js +73 -0
- package/dist/mergetags-ui-HS3Q2R36.js.map +1 -0
- package/dist/{nonbreaking-66LFZV2W.js → nonbreaking-GYRUH4UO.js} +7 -7
- package/dist/nonbreaking-GYRUH4UO.js.map +1 -0
- package/dist/pagebreak-ui-I4ZPYK3U.js +50 -0
- package/dist/pagebreak-ui-I4ZPYK3U.js.map +1 -0
- package/dist/pageembed-ui-WOY6VWRJ.js +172 -0
- package/dist/pageembed-ui-WOY6VWRJ.js.map +1 -0
- package/dist/pagelayout-ui-Y2IM7FJQ.js +236 -0
- package/dist/pagelayout-ui-Y2IM7FJQ.js.map +1 -0
- package/dist/{paste-office-F3QW4WWO.js → paste-office-3A6KWKCV.js} +82 -2
- package/dist/paste-office-3A6KWKCV.js.map +1 -0
- package/dist/permanentpen-6D5LLKFX.js +206 -0
- package/dist/permanentpen-6D5LLKFX.js.map +1 -0
- package/dist/print-MZMLQIQX.js +178 -0
- package/dist/print-MZMLQIQX.js.map +1 -0
- package/dist/{quickbars-7E2QRS7J.js → quickbars-UZ2Q67TX.js} +20 -12
- package/dist/quickbars-UZ2Q67TX.js.map +1 -0
- package/dist/{revisionhistory-DXE7KU4R.js → revisionhistory-ACRB23HL.js} +42 -153
- package/dist/revisionhistory-ACRB23HL.js.map +1 -0
- package/dist/save-72ZLF6AO.js +120 -0
- package/dist/save-72ZLF6AO.js.map +1 -0
- package/dist/search-bar-HTZQNPD3.js +212 -0
- package/dist/search-bar-HTZQNPD3.js.map +1 -0
- package/dist/spellchecker-DJ7SP5JY.js +474 -0
- package/dist/spellchecker-DJ7SP5JY.js.map +1 -0
- package/dist/suggestions-panel-RJXC4LCM.js +596 -0
- package/dist/suggestions-panel-RJXC4LCM.js.map +1 -0
- package/dist/suggestions-ui-PODMNH7D.js +395 -0
- package/dist/suggestions-ui-PODMNH7D.js.map +1 -0
- package/dist/table-OBHE465Y.js +54 -0
- package/dist/table-OBHE465Y.js.map +1 -0
- package/dist/table-dialogs-UMIIZQYE.js +119 -0
- package/dist/table-dialogs-UMIIZQYE.js.map +1 -0
- package/dist/tableofcontents-ui-U2PYNPX6.js +167 -0
- package/dist/tableofcontents-ui-U2PYNPX6.js.map +1 -0
- package/dist/template-YYC2MGVH.js +278 -0
- package/dist/template-YYC2MGVH.js.map +1 -0
- package/dist/typography-EQUXUXIN.js +399 -0
- package/dist/typography-EQUXUXIN.js.map +1 -0
- package/dist/upload.cjs +160 -0
- package/dist/upload.cjs.map +1 -0
- package/dist/upload.d.cts +72 -0
- package/dist/upload.d.ts +72 -0
- package/dist/upload.js +132 -0
- package/dist/upload.js.map +1 -0
- package/dist/{visualblocks-6DLBXYOA.js → visualblocks-O5QW7ZDT.js} +7 -7
- package/dist/visualblocks-O5QW7ZDT.js.map +1 -0
- package/dist/visualchars-UQFRWQPE.js +134 -0
- package/dist/visualchars-UQFRWQPE.js.map +1 -0
- package/package.json +53 -3
- package/src/style.css +320 -544
- package/dist/advlist-5FNKPLUX.js.map +0 -1
- package/dist/autolink-45LTODWB.js.map +0 -1
- package/dist/autoresize-UB3GOA6D.js.map +0 -1
- package/dist/autosave-GMWJ5BPE.js.map +0 -1
- package/dist/charmap-2GC7LF7G.js.map +0 -1
- package/dist/chunk-5AW2HHG6.js.map +0 -1
- package/dist/chunk-DWZLSZDG.js +0 -5664
- package/dist/chunk-DWZLSZDG.js.map +0 -1
- package/dist/chunk-FCMZ7TUQ.js.map +0 -1
- package/dist/chunk-HPLT3XRZ.js.map +0 -1
- package/dist/chunk-JPJVTB45.js.map +0 -1
- package/dist/chunk-KPE3QRPB.js.map +0 -1
- package/dist/chunk-KWXFL4WS.js.map +0 -1
- package/dist/chunk-ND2CWNVG.js.map +0 -1
- package/dist/chunk-PVFKXRID.js.map +0 -1
- package/dist/chunk-R2UMUCVI.js.map +0 -1
- package/dist/chunk-T3GY6IVK.js.map +0 -1
- package/dist/chunk-Z3ELZ77W.js.map +0 -1
- package/dist/comments-panel-HXMWSRAW.js.map +0 -1
- package/dist/directionality-5JLWQGP2.js.map +0 -1
- package/dist/editor-CXkltf1R.d.ts +0 -1886
- package/dist/editor-CgSBFTke.d.cts +0 -1886
- package/dist/emoticons-ZD6ZRIWG.js.map +0 -1
- package/dist/form-dialog-QH6KAERD.js +0 -180
- package/dist/form-dialog-QH6KAERD.js.map +0 -1
- package/dist/html-rules-api-D3fKQi-R.d.cts +0 -40
- package/dist/html-rules-api-D3fKQi-R.d.ts +0 -40
- package/dist/insertdatetime-CRO7TJAQ.js.map +0 -1
- package/dist/nonbreaking-66LFZV2W.js.map +0 -1
- package/dist/paste-office-F3QW4WWO.js.map +0 -1
- package/dist/quickbars-7E2QRS7J.js.map +0 -1
- package/dist/revisionhistory-DXE7KU4R.js.map +0 -1
- package/dist/table-SSNABG5W.js.map +0 -1
- package/dist/visualblocks-6DLBXYOA.js.map +0 -1
package/dist/docx.js
ADDED
|
@@ -0,0 +1,1821 @@
|
|
|
1
|
+
import "./chunk-I7Y4KSM2.js";
|
|
2
|
+
import "./chunk-T3IRLTKK.js";
|
|
3
|
+
import {
|
|
4
|
+
createRenderer
|
|
5
|
+
} from "./chunk-YDPZCVXS.js";
|
|
6
|
+
import "./chunk-S2XZRKHA.js";
|
|
7
|
+
import "./chunk-LVEQBNLX.js";
|
|
8
|
+
import "./chunk-AQV6FIKK.js";
|
|
9
|
+
import "./chunk-53AY5NAF.js";
|
|
10
|
+
import {
|
|
11
|
+
PAGE_SIZES,
|
|
12
|
+
pageLayout,
|
|
13
|
+
resolvePageLayout
|
|
14
|
+
} from "./chunk-OFHGXYG3.js";
|
|
15
|
+
import "./chunk-YG5V7POU.js";
|
|
16
|
+
import "./chunk-C326LHHU.js";
|
|
17
|
+
import "./chunk-N32H37AJ.js";
|
|
18
|
+
import {
|
|
19
|
+
blockSuggestion,
|
|
20
|
+
formatMarks
|
|
21
|
+
} from "./chunk-P2UU2NLT.js";
|
|
22
|
+
import "./chunk-OQMMHWMZ.js";
|
|
23
|
+
import "./chunk-GXXXLPDQ.js";
|
|
24
|
+
import "./chunk-AP2PJFLB.js";
|
|
25
|
+
import "./chunk-5VCESSQB.js";
|
|
26
|
+
import "./chunk-NTGEKGXU.js";
|
|
27
|
+
import "./chunk-HC6RMBAD.js";
|
|
28
|
+
import "./chunk-EOJ5XHKA.js";
|
|
29
|
+
import "./chunk-AC3YCAX4.js";
|
|
30
|
+
import "./chunk-HNEAVVBC.js";
|
|
31
|
+
import "./chunk-TAM2FHKG.js";
|
|
32
|
+
import "./chunk-XR7CY4NI.js";
|
|
33
|
+
import "./chunk-ADRPQLZ2.js";
|
|
34
|
+
import "./chunk-DEYYVZ7O.js";
|
|
35
|
+
import "./chunk-V7WUHUHM.js";
|
|
36
|
+
import "./chunk-QU3KXMYT.js";
|
|
37
|
+
import "./chunk-G74HNSB6.js";
|
|
38
|
+
import "./chunk-OOVNE6MB.js";
|
|
39
|
+
import "./chunk-3BOK3S3T.js";
|
|
40
|
+
import {
|
|
41
|
+
isSafeLinkUrl
|
|
42
|
+
} from "./chunk-4VPDY3LF.js";
|
|
43
|
+
|
|
44
|
+
// src/docx/index.ts
|
|
45
|
+
import { Node as PMNode } from "prosemirror-model";
|
|
46
|
+
|
|
47
|
+
// src/docx/xml.ts
|
|
48
|
+
var ENTITIES = { lt: "<", gt: ">", amp: "&", quot: '"', apos: "'" };
|
|
49
|
+
function decodeEntities(text) {
|
|
50
|
+
return text.replace(/&(#x[0-9a-f]+|#\d+|[a-z]+);/gi, (match, entity) => {
|
|
51
|
+
if (entity[0] === "#") {
|
|
52
|
+
const code = entity[1] === "x" || entity[1] === "X" ? parseInt(entity.slice(2), 16) : parseInt(entity.slice(1), 10);
|
|
53
|
+
return Number.isFinite(code) && code > 0 && code <= 1114111 ? String.fromCodePoint(code) : match;
|
|
54
|
+
}
|
|
55
|
+
return ENTITIES[entity.toLowerCase()] ?? match;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function forbidden(code) {
|
|
59
|
+
return code < 32 && code !== 9 && code !== 10 && code !== 13 || code > 65533;
|
|
60
|
+
}
|
|
61
|
+
function escapeXml(text) {
|
|
62
|
+
let clean = "";
|
|
63
|
+
for (let i = 0; i < text.length; i++) if (!forbidden(text.charCodeAt(i))) clean += text[i];
|
|
64
|
+
return clean.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
65
|
+
}
|
|
66
|
+
var ATTR_RE = /([^\s=/]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g;
|
|
67
|
+
function parseXml(source) {
|
|
68
|
+
const text = source.charCodeAt(0) === 65279 ? source.slice(1) : source;
|
|
69
|
+
const root = { name: "#document", attrs: {}, children: [] };
|
|
70
|
+
const stack = [root];
|
|
71
|
+
let i = 0;
|
|
72
|
+
while (i < text.length) {
|
|
73
|
+
const lt = text.indexOf("<", i);
|
|
74
|
+
const top = stack[stack.length - 1];
|
|
75
|
+
if (lt < 0) {
|
|
76
|
+
if (i < text.length) top.children.push(decodeEntities(text.slice(i)));
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
if (lt > i) top.children.push(decodeEntities(text.slice(i, lt)));
|
|
80
|
+
if (text.startsWith("<!--", lt)) {
|
|
81
|
+
const end = text.indexOf("-->", lt + 4);
|
|
82
|
+
i = end < 0 ? text.length : end + 3;
|
|
83
|
+
} else if (text.startsWith("<![CDATA[", lt)) {
|
|
84
|
+
const end = text.indexOf("]]>", lt + 9);
|
|
85
|
+
top.children.push(text.slice(lt + 9, end < 0 ? text.length : end));
|
|
86
|
+
i = end < 0 ? text.length : end + 3;
|
|
87
|
+
} else if (text.startsWith("<?", lt) || text.startsWith("<!", lt)) {
|
|
88
|
+
const end = text.indexOf(">", lt);
|
|
89
|
+
i = end < 0 ? text.length : end + 1;
|
|
90
|
+
} else if (text[lt + 1] === "/") {
|
|
91
|
+
const end = text.indexOf(">", lt);
|
|
92
|
+
const name = text.slice(lt + 2, end < 0 ? text.length : end).trim();
|
|
93
|
+
const index = stack.map((el) => el.name).lastIndexOf(name);
|
|
94
|
+
if (index > 0) stack.length = index;
|
|
95
|
+
i = end < 0 ? text.length : end + 1;
|
|
96
|
+
} else {
|
|
97
|
+
let end = lt + 1;
|
|
98
|
+
let quote = "";
|
|
99
|
+
for (; end < text.length; end++) {
|
|
100
|
+
const ch = text[end];
|
|
101
|
+
if (quote) {
|
|
102
|
+
if (ch === quote) quote = "";
|
|
103
|
+
} else if (ch === '"' || ch === "'") quote = ch;
|
|
104
|
+
else if (ch === ">") break;
|
|
105
|
+
}
|
|
106
|
+
let inner = text.slice(lt + 1, end);
|
|
107
|
+
const selfClosing = inner.endsWith("/");
|
|
108
|
+
if (selfClosing) inner = inner.slice(0, -1);
|
|
109
|
+
const space = inner.search(/[\s]/);
|
|
110
|
+
const name = space < 0 ? inner : inner.slice(0, space);
|
|
111
|
+
const attrs = {};
|
|
112
|
+
if (space >= 0) {
|
|
113
|
+
for (const match of inner.slice(space).matchAll(ATTR_RE))
|
|
114
|
+
attrs[match[1]] = decodeEntities(match[2] ?? match[3] ?? "");
|
|
115
|
+
}
|
|
116
|
+
const element2 = { name, attrs, children: [] };
|
|
117
|
+
top.children.push(element2);
|
|
118
|
+
if (!selfClosing) stack.push(element2);
|
|
119
|
+
i = end + 1;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return root;
|
|
123
|
+
}
|
|
124
|
+
function elements(parent, name) {
|
|
125
|
+
if (!parent) return [];
|
|
126
|
+
return parent.children.filter(
|
|
127
|
+
(child) => typeof child !== "string" && (!name || child.name === name)
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
function element(parent, name) {
|
|
131
|
+
return parent?.children.find(
|
|
132
|
+
(child) => typeof child !== "string" && child.name === name
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
function path(parent, ...names) {
|
|
136
|
+
let current = parent;
|
|
137
|
+
for (const name of names) current = element(current, name);
|
|
138
|
+
return current;
|
|
139
|
+
}
|
|
140
|
+
function textContent(node) {
|
|
141
|
+
return typeof node === "string" ? node : node.children.map(textContent).join("");
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// src/docx/zip.ts
|
|
145
|
+
var encoder = new TextEncoder();
|
|
146
|
+
var crcTable = null;
|
|
147
|
+
function crc32(data) {
|
|
148
|
+
if (!crcTable) {
|
|
149
|
+
crcTable = new Uint32Array(256);
|
|
150
|
+
for (let n = 0; n < 256; n++) {
|
|
151
|
+
let c = n;
|
|
152
|
+
for (let k = 0; k < 8; k++) c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1;
|
|
153
|
+
crcTable[n] = c >>> 0;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
let crc = 4294967295;
|
|
157
|
+
for (const byte of data) crc = crcTable[(crc ^ byte) & 255] ^ crc >>> 8;
|
|
158
|
+
return (crc ^ 4294967295) >>> 0;
|
|
159
|
+
}
|
|
160
|
+
async function through(data, transform) {
|
|
161
|
+
const stream = new ReadableStream({
|
|
162
|
+
start(controller) {
|
|
163
|
+
controller.enqueue(data);
|
|
164
|
+
controller.close();
|
|
165
|
+
}
|
|
166
|
+
}).pipeThrough(transform);
|
|
167
|
+
const reader = stream.getReader();
|
|
168
|
+
const chunks = [];
|
|
169
|
+
let length = 0;
|
|
170
|
+
for (; ; ) {
|
|
171
|
+
const { done, value } = await reader.read();
|
|
172
|
+
if (done) break;
|
|
173
|
+
chunks.push(value);
|
|
174
|
+
length += value.length;
|
|
175
|
+
}
|
|
176
|
+
const out = new Uint8Array(length);
|
|
177
|
+
let offset = 0;
|
|
178
|
+
for (const chunk of chunks) {
|
|
179
|
+
out.set(chunk, offset);
|
|
180
|
+
offset += chunk.length;
|
|
181
|
+
}
|
|
182
|
+
return out;
|
|
183
|
+
}
|
|
184
|
+
var canCompress = () => typeof CompressionStream !== "undefined";
|
|
185
|
+
async function zip(entries) {
|
|
186
|
+
const locals = [];
|
|
187
|
+
const central = [];
|
|
188
|
+
let offset = 0;
|
|
189
|
+
for (const entry of entries) {
|
|
190
|
+
const name = encoder.encode(entry.name);
|
|
191
|
+
const crc = crc32(entry.data);
|
|
192
|
+
const deflate = canCompress() && entry.data.length > 64;
|
|
193
|
+
const body = deflate ? await through(
|
|
194
|
+
entry.data,
|
|
195
|
+
new CompressionStream("deflate-raw")
|
|
196
|
+
) : entry.data;
|
|
197
|
+
const method = deflate ? 8 : 0;
|
|
198
|
+
const local = new DataView(new ArrayBuffer(30));
|
|
199
|
+
local.setUint32(0, 67324752, true);
|
|
200
|
+
local.setUint16(4, 20, true);
|
|
201
|
+
local.setUint16(6, 2048, true);
|
|
202
|
+
local.setUint16(8, method, true);
|
|
203
|
+
local.setUint16(10, 0, true);
|
|
204
|
+
local.setUint16(12, 33, true);
|
|
205
|
+
local.setUint32(14, crc, true);
|
|
206
|
+
local.setUint32(18, body.length, true);
|
|
207
|
+
local.setUint32(22, entry.data.length, true);
|
|
208
|
+
local.setUint16(26, name.length, true);
|
|
209
|
+
local.setUint16(28, 0, true);
|
|
210
|
+
locals.push(new Uint8Array(local.buffer), name, body);
|
|
211
|
+
const record = new DataView(new ArrayBuffer(46));
|
|
212
|
+
record.setUint32(0, 33639248, true);
|
|
213
|
+
record.setUint16(4, 20, true);
|
|
214
|
+
record.setUint16(6, 20, true);
|
|
215
|
+
record.setUint16(8, 2048, true);
|
|
216
|
+
record.setUint16(10, method, true);
|
|
217
|
+
record.setUint16(12, 0, true);
|
|
218
|
+
record.setUint16(14, 33, true);
|
|
219
|
+
record.setUint32(16, crc, true);
|
|
220
|
+
record.setUint32(20, body.length, true);
|
|
221
|
+
record.setUint32(24, entry.data.length, true);
|
|
222
|
+
record.setUint16(28, name.length, true);
|
|
223
|
+
record.setUint32(42, offset, true);
|
|
224
|
+
central.push(new Uint8Array(record.buffer), name);
|
|
225
|
+
offset += 30 + name.length + body.length;
|
|
226
|
+
}
|
|
227
|
+
const centralSize = central.reduce((sum, part) => sum + part.length, 0);
|
|
228
|
+
const end = new DataView(new ArrayBuffer(22));
|
|
229
|
+
end.setUint32(0, 101010256, true);
|
|
230
|
+
end.setUint16(8, entries.length, true);
|
|
231
|
+
end.setUint16(10, entries.length, true);
|
|
232
|
+
end.setUint32(12, centralSize, true);
|
|
233
|
+
end.setUint32(16, offset, true);
|
|
234
|
+
const parts = [...locals, ...central, new Uint8Array(end.buffer)];
|
|
235
|
+
const out = new Uint8Array(parts.reduce((sum, part) => sum + part.length, 0));
|
|
236
|
+
let at = 0;
|
|
237
|
+
for (const part of parts) {
|
|
238
|
+
out.set(part, at);
|
|
239
|
+
at += part.length;
|
|
240
|
+
}
|
|
241
|
+
return out;
|
|
242
|
+
}
|
|
243
|
+
async function unzip(bytes) {
|
|
244
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
245
|
+
let end = -1;
|
|
246
|
+
for (let i = bytes.length - 22; i >= Math.max(0, bytes.length - 22 - 65535); i--) {
|
|
247
|
+
if (view.getUint32(i, true) === 101010256) {
|
|
248
|
+
end = i;
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
if (end < 0) throw new Error("Not a ZIP file");
|
|
253
|
+
const count = view.getUint16(end + 10, true);
|
|
254
|
+
let at = view.getUint32(end + 16, true);
|
|
255
|
+
const decoder = new TextDecoder();
|
|
256
|
+
const files = /* @__PURE__ */ new Map();
|
|
257
|
+
for (let i = 0; i < count; i++) {
|
|
258
|
+
if (view.getUint32(at, true) !== 33639248) throw new Error("Damaged ZIP file");
|
|
259
|
+
const flags = view.getUint16(at + 8, true);
|
|
260
|
+
const method = view.getUint16(at + 10, true);
|
|
261
|
+
const size = view.getUint32(at + 20, true);
|
|
262
|
+
const nameLength = view.getUint16(at + 28, true);
|
|
263
|
+
const extraLength = view.getUint16(at + 30, true);
|
|
264
|
+
const commentLength = view.getUint16(at + 32, true);
|
|
265
|
+
const offset = view.getUint32(at + 42, true);
|
|
266
|
+
const name = decoder.decode(bytes.subarray(at + 46, at + 46 + nameLength));
|
|
267
|
+
at += 46 + nameLength + extraLength + commentLength;
|
|
268
|
+
if (flags & 1) throw new Error("Encrypted documents are not supported");
|
|
269
|
+
const start = offset + 30 + view.getUint16(offset + 26, true) + view.getUint16(offset + 28, true);
|
|
270
|
+
const raw = bytes.subarray(start, start + size);
|
|
271
|
+
if (method === 0) files.set(name, raw);
|
|
272
|
+
else if (method === 8) {
|
|
273
|
+
if (typeof DecompressionStream === "undefined")
|
|
274
|
+
throw new Error("This browser cannot unpack compressed files");
|
|
275
|
+
files.set(
|
|
276
|
+
name,
|
|
277
|
+
await through(
|
|
278
|
+
raw,
|
|
279
|
+
new DecompressionStream("deflate-raw")
|
|
280
|
+
)
|
|
281
|
+
);
|
|
282
|
+
} else throw new Error(`Unsupported compression in ${name}`);
|
|
283
|
+
}
|
|
284
|
+
return files;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// src/docx/export.ts
|
|
288
|
+
var NS = {
|
|
289
|
+
w: "http://schemas.openxmlformats.org/wordprocessingml/2006/main",
|
|
290
|
+
r: "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
|
|
291
|
+
wp: "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing",
|
|
292
|
+
a: "http://schemas.openxmlformats.org/drawingml/2006/main",
|
|
293
|
+
pic: "http://schemas.openxmlformats.org/drawingml/2006/picture",
|
|
294
|
+
rel: "http://schemas.openxmlformats.org/officeDocument/2006/relationships"
|
|
295
|
+
};
|
|
296
|
+
var XML = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n';
|
|
297
|
+
var TWIPS_PER_MM = 1440 / 25.4;
|
|
298
|
+
var EMU_PER_PX = 9525;
|
|
299
|
+
var INDENT_TWIPS = 600;
|
|
300
|
+
var twips = (mm) => Math.round(mm * TWIPS_PER_MM);
|
|
301
|
+
function sniff(bytes) {
|
|
302
|
+
if (bytes[0] === 137 && bytes[1] === 80 && bytes[2] === 78 && bytes[3] === 71)
|
|
303
|
+
return "png";
|
|
304
|
+
if (bytes[0] === 255 && bytes[1] === 216 && bytes[2] === 255) return "jpeg";
|
|
305
|
+
if (bytes[0] === 71 && bytes[1] === 73 && bytes[2] === 70) return "gif";
|
|
306
|
+
return null;
|
|
307
|
+
}
|
|
308
|
+
function imageSize(bytes, type) {
|
|
309
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
310
|
+
try {
|
|
311
|
+
if (type === "png") return { width: view.getUint32(16), height: view.getUint32(20) };
|
|
312
|
+
if (type === "gif") return { width: view.getUint16(6, true), height: view.getUint16(8, true) };
|
|
313
|
+
for (let i = 2; i + 9 < bytes.length; ) {
|
|
314
|
+
if (bytes[i] !== 255) break;
|
|
315
|
+
const marker = bytes[i + 1];
|
|
316
|
+
const length = view.getUint16(i + 2);
|
|
317
|
+
if (marker >= 192 && marker <= 207 && ![196, 200, 204].includes(marker))
|
|
318
|
+
return { height: view.getUint16(i + 5), width: view.getUint16(i + 7) };
|
|
319
|
+
i += 2 + length;
|
|
320
|
+
}
|
|
321
|
+
} catch {
|
|
322
|
+
}
|
|
323
|
+
return {};
|
|
324
|
+
}
|
|
325
|
+
function base64(text) {
|
|
326
|
+
const binary = atob(text.replace(/\s+/g, ""));
|
|
327
|
+
const out = new Uint8Array(binary.length);
|
|
328
|
+
for (let i = 0; i < binary.length; i++) out[i] = binary.charCodeAt(i);
|
|
329
|
+
return out;
|
|
330
|
+
}
|
|
331
|
+
async function loadImage(src) {
|
|
332
|
+
let bytes;
|
|
333
|
+
const data = /^data:[^,;]*(;base64)?,([\s\S]*)$/i.exec(src);
|
|
334
|
+
if (data) {
|
|
335
|
+
bytes = data[1] ? base64(data[2]) : new TextEncoder().encode(decodeURIComponent(data[2]));
|
|
336
|
+
} else if (typeof fetch === "function" && !/^(javascript|vbscript):/i.test(src)) {
|
|
337
|
+
const response = await fetch(src);
|
|
338
|
+
if (!response.ok) return null;
|
|
339
|
+
bytes = new Uint8Array(await response.arrayBuffer());
|
|
340
|
+
} else return null;
|
|
341
|
+
const type = sniff(bytes);
|
|
342
|
+
return type ? { data: bytes, type, ...imageSize(bytes, type) } : null;
|
|
343
|
+
}
|
|
344
|
+
var NAMED = {
|
|
345
|
+
black: "000000",
|
|
346
|
+
white: "FFFFFF",
|
|
347
|
+
red: "FF0000",
|
|
348
|
+
green: "008000",
|
|
349
|
+
blue: "0000FF",
|
|
350
|
+
yellow: "FFFF00",
|
|
351
|
+
orange: "FFA500",
|
|
352
|
+
purple: "800080",
|
|
353
|
+
gray: "808080",
|
|
354
|
+
grey: "808080"
|
|
355
|
+
};
|
|
356
|
+
function hexColor(value) {
|
|
357
|
+
if (typeof value !== "string") return null;
|
|
358
|
+
const css = value.trim().toLowerCase();
|
|
359
|
+
const hex = /^#([0-9a-f]{3,8})$/.exec(css)?.[1];
|
|
360
|
+
if (hex) {
|
|
361
|
+
if (hex.length === 3 || hex.length === 4)
|
|
362
|
+
return [...hex.slice(0, 3)].map((ch) => ch + ch).join("").toUpperCase();
|
|
363
|
+
if (hex.length === 6 || hex.length === 8) return hex.slice(0, 6).toUpperCase();
|
|
364
|
+
return null;
|
|
365
|
+
}
|
|
366
|
+
const rgb = /^rgba?\(([^)]+)\)$/.exec(css)?.[1];
|
|
367
|
+
if (rgb) {
|
|
368
|
+
const parts = rgb.split(/[\s,/]+/).filter(Boolean);
|
|
369
|
+
if (parts.length >= 4 && Number(parts[3]) === 0) return null;
|
|
370
|
+
const channels = parts.slice(0, 3).map((part) => part.endsWith("%") ? parseFloat(part) * 255 / 100 : parseFloat(part));
|
|
371
|
+
if (channels.length < 3 || channels.some((n) => !Number.isFinite(n))) return null;
|
|
372
|
+
return channels.map(
|
|
373
|
+
(n) => Math.round(Math.min(255, Math.max(0, n))).toString(16).padStart(2, "0")
|
|
374
|
+
).join("").toUpperCase();
|
|
375
|
+
}
|
|
376
|
+
return NAMED[css] ?? null;
|
|
377
|
+
}
|
|
378
|
+
var GENERIC_FONTS = {
|
|
379
|
+
serif: "Times New Roman",
|
|
380
|
+
"sans-serif": "Arial",
|
|
381
|
+
monospace: "Consolas",
|
|
382
|
+
"system-ui": "Calibri",
|
|
383
|
+
cursive: "Comic Sans MS"
|
|
384
|
+
};
|
|
385
|
+
function fontName(value) {
|
|
386
|
+
if (typeof value !== "string") return null;
|
|
387
|
+
const first = value.split(",")[0].trim().replace(/^['"]|['"]$/g, "");
|
|
388
|
+
if (!first) return null;
|
|
389
|
+
return GENERIC_FONTS[first.toLowerCase()] ?? first.slice(0, 64);
|
|
390
|
+
}
|
|
391
|
+
function halfPoints(value) {
|
|
392
|
+
const m = typeof value === "string" ? /^(\d+(?:\.\d+)?)(px|pt)$/.exec(value.trim()) : null;
|
|
393
|
+
if (!m) return null;
|
|
394
|
+
const pt = m[2] === "px" ? Number(m[1]) * 0.75 : Number(m[1]);
|
|
395
|
+
return pt > 0 && pt < 1e3 ? Math.round(pt * 2) : null;
|
|
396
|
+
}
|
|
397
|
+
function bookmarkName(id) {
|
|
398
|
+
const name = id.replace(/[^\p{L}\p{N}_]/gu, "_");
|
|
399
|
+
return (/^\p{L}/u.test(name) ? name : `b_${name}`).slice(0, 40);
|
|
400
|
+
}
|
|
401
|
+
function dateOf(ms) {
|
|
402
|
+
const time = Number(ms);
|
|
403
|
+
return new Date(Number.isFinite(time) && time > 0 ? time : 0).toISOString().replace(/\.\d+Z$/, "Z");
|
|
404
|
+
}
|
|
405
|
+
var MATH = { font: "Cambria Math", italic: true };
|
|
406
|
+
function nodeRevision(node) {
|
|
407
|
+
const s = blockSuggestion(node.attrs.suggestion);
|
|
408
|
+
if (s?.change !== "insert" && s?.change !== "delete") return null;
|
|
409
|
+
return {
|
|
410
|
+
tag: s.change === "insert" ? "w:ins" : "w:del",
|
|
411
|
+
author: (s.name || s.author || "NovaProse").slice(0, 80),
|
|
412
|
+
time: s.time
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
var BULLETS = ["\u2022", "\u25E6", "\u25AA"];
|
|
416
|
+
var ORDERED_FORMATS = ["decimal", "lowerLetter", "lowerRoman"];
|
|
417
|
+
var LIST_STYLES = {
|
|
418
|
+
decimal: "decimal",
|
|
419
|
+
"lower-alpha": "lowerLetter",
|
|
420
|
+
"lower-latin": "lowerLetter",
|
|
421
|
+
"upper-alpha": "upperLetter",
|
|
422
|
+
"upper-latin": "upperLetter",
|
|
423
|
+
"lower-roman": "lowerRoman",
|
|
424
|
+
"upper-roman": "upperRoman",
|
|
425
|
+
"lower-greek": "lowerLetter"
|
|
426
|
+
};
|
|
427
|
+
var BULLET_STYLES = { disc: "\u2022", circle: "\u25E6", square: "\u25AA" };
|
|
428
|
+
var DocxWriter = class {
|
|
429
|
+
constructor(layout, images) {
|
|
430
|
+
this.layout = layout;
|
|
431
|
+
this.images = images;
|
|
432
|
+
this.textWidthPx = (layout.width - layout.margins.left - layout.margins.right) * 96 / 25.4;
|
|
433
|
+
}
|
|
434
|
+
layout;
|
|
435
|
+
images;
|
|
436
|
+
rels = [];
|
|
437
|
+
relCount = 2;
|
|
438
|
+
// rId1 is the styles, rId2 the numbering
|
|
439
|
+
media = [];
|
|
440
|
+
imageRels = /* @__PURE__ */ new Map();
|
|
441
|
+
abstracts = /* @__PURE__ */ new Map();
|
|
442
|
+
abstractXml = [];
|
|
443
|
+
numXml = [];
|
|
444
|
+
numCount = 0;
|
|
445
|
+
drawingCount = 0;
|
|
446
|
+
bookmarkCount = 0;
|
|
447
|
+
changeCount = 0;
|
|
448
|
+
textWidthPx;
|
|
449
|
+
rel(type, target, external = false) {
|
|
450
|
+
const id = `rId${++this.relCount}`;
|
|
451
|
+
this.rels.push(
|
|
452
|
+
`<Relationship Id="${id}" Type="${NS.rel}/${type}" Target="${escapeXml(target)}"${external ? ' TargetMode="External"' : ""}/>`
|
|
453
|
+
);
|
|
454
|
+
return id;
|
|
455
|
+
}
|
|
456
|
+
// ----- text -----
|
|
457
|
+
/**
|
|
458
|
+
* A run's w:rPr. A suggested format becomes a tracked formatting change: w:rPrChange holds the
|
|
459
|
+
* formatting the text had before it (Word shows "Formatted" and can accept or reject it).
|
|
460
|
+
*/
|
|
461
|
+
runProps(marks, ctx, own = {}) {
|
|
462
|
+
const props = this.props(marks, ctx, own);
|
|
463
|
+
const format = marks.find((m) => m.type.name === "suggestion_format");
|
|
464
|
+
if (!format) return props ? `<w:rPr>${props}</w:rPr>` : "";
|
|
465
|
+
const before = this.props(formatMarks(format.type.schema, format.attrs.before), ctx, own);
|
|
466
|
+
const author = String(format.attrs.name || format.attrs.author || "NovaProse").slice(0, 80);
|
|
467
|
+
const change = `<w:rPrChange w:id="${++this.changeCount}" w:author="${escapeXml(author)}" w:date="${dateOf(format.attrs.time)}"><w:rPr>${before}</w:rPr></w:rPrChange>`;
|
|
468
|
+
return `<w:rPr>${props}${change}</w:rPr>`;
|
|
469
|
+
}
|
|
470
|
+
/** The run properties of a set of marks (the content of w:rPr). */
|
|
471
|
+
props(marks, ctx, own = {}) {
|
|
472
|
+
let style = own.style ?? "";
|
|
473
|
+
let fonts = own.font ?? "";
|
|
474
|
+
let bold = !!ctx.bold;
|
|
475
|
+
let italic = !!own.italic;
|
|
476
|
+
let strike = false;
|
|
477
|
+
let color = "";
|
|
478
|
+
let size = "";
|
|
479
|
+
let underline = false;
|
|
480
|
+
let shade = "";
|
|
481
|
+
let vertical = "";
|
|
482
|
+
for (const mark of marks) {
|
|
483
|
+
const name = mark.type.name;
|
|
484
|
+
if (name === "link") style = "Hyperlink";
|
|
485
|
+
else if (name === "bold") bold = true;
|
|
486
|
+
else if (name === "italic") italic = true;
|
|
487
|
+
else if (name === "underline") underline = true;
|
|
488
|
+
else if (name === "strike") strike = true;
|
|
489
|
+
else if (name === "subscript") vertical = "subscript";
|
|
490
|
+
else if (name === "superscript") vertical = "superscript";
|
|
491
|
+
else if (name === "code") {
|
|
492
|
+
fonts = "Consolas";
|
|
493
|
+
shade ||= "F3F4F6";
|
|
494
|
+
} else if (name === "color") color = hexColor(mark.attrs.value) ?? color;
|
|
495
|
+
else if (name === "background") shade = hexColor(mark.attrs.value) ?? shade;
|
|
496
|
+
else if (name === "font_family") fonts = fontName(mark.attrs.value) ?? fonts;
|
|
497
|
+
else if (name === "font_size") {
|
|
498
|
+
const sz = halfPoints(mark.attrs.value);
|
|
499
|
+
if (sz) size = `<w:sz w:val="${sz}"/><w:szCs w:val="${sz}"/>`;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
const props = (style ? `<w:rStyle w:val="${style}"/>` : "") + (fonts ? `<w:rFonts w:ascii="${escapeXml(fonts)}" w:hAnsi="${escapeXml(fonts)}" w:cs="${escapeXml(fonts)}" w:eastAsia="${escapeXml(fonts)}"/>` : "") + (bold ? "<w:b/><w:bCs/>" : "") + (italic ? "<w:i/><w:iCs/>" : "") + (strike ? "<w:strike/>" : "") + (color ? `<w:color w:val="${color}"/>` : "") + size + (underline ? '<w:u w:val="single"/>' : "") + (shade ? `<w:shd w:val="clear" w:color="auto" w:fill="${shade}"/>` : "") + (vertical ? `<w:vertAlign w:val="${vertical}"/>` : "");
|
|
503
|
+
return props;
|
|
504
|
+
}
|
|
505
|
+
/** Text as runs: a line break is w:br, a tab is w:tab. */
|
|
506
|
+
text(value, tag = "w:t") {
|
|
507
|
+
let out = "";
|
|
508
|
+
value.split("\n").forEach((line, index) => {
|
|
509
|
+
if (index) out += "<w:br/>";
|
|
510
|
+
line.split(" ").forEach((part, i) => {
|
|
511
|
+
if (i) out += "<w:tab/>";
|
|
512
|
+
if (part) out += `<${tag} xml:space="preserve">${escapeXml(part)}</${tag}>`;
|
|
513
|
+
});
|
|
514
|
+
});
|
|
515
|
+
return out;
|
|
516
|
+
}
|
|
517
|
+
run(value, marks, ctx, own = {}) {
|
|
518
|
+
const deleted = this.revisionOf(marks, ctx)?.tag === "w:del";
|
|
519
|
+
const body = `<w:r>${this.runProps(marks, ctx, own)}${this.text(value, deleted ? "w:delText" : "w:t")}</w:r>`;
|
|
520
|
+
return this.tracked(body, marks, ctx);
|
|
521
|
+
}
|
|
522
|
+
/**
|
|
523
|
+
* The revision of a run: its own suggested edit, or the node's it is in (a deleted node wins:
|
|
524
|
+
* the whole of it goes).
|
|
525
|
+
*/
|
|
526
|
+
revisionOf(marks, ctx) {
|
|
527
|
+
if (ctx?.change?.tag === "w:del") return ctx.change;
|
|
528
|
+
const change = marks.find(
|
|
529
|
+
(m) => m.type.name === "suggestion_insert" || m.type.name === "suggestion_delete"
|
|
530
|
+
);
|
|
531
|
+
if (!change) return ctx?.change ?? null;
|
|
532
|
+
return {
|
|
533
|
+
tag: change.type.name === "suggestion_insert" ? "w:ins" : "w:del",
|
|
534
|
+
author: String(change.attrs.name || change.attrs.author || "NovaProse").slice(0, 80),
|
|
535
|
+
time: change.attrs.time
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
/** A revision's attributes: a new id, the author, the date. */
|
|
539
|
+
revisionAttrs(revision) {
|
|
540
|
+
return `w:id="${++this.changeCount}" w:author="${escapeXml(revision.author)}" w:date="${dateOf(revision.time)}"`;
|
|
541
|
+
}
|
|
542
|
+
/** A suggested edit becomes a Word revision (w:ins / w:del with author and time). */
|
|
543
|
+
tracked(body, marks, ctx) {
|
|
544
|
+
const revision = this.revisionOf(marks, ctx);
|
|
545
|
+
if (!revision) return body;
|
|
546
|
+
return `<${revision.tag} ${this.revisionAttrs(revision)}>${body}</${revision.tag}>`;
|
|
547
|
+
}
|
|
548
|
+
bookmark(id, inner = "") {
|
|
549
|
+
if (typeof id !== "string" || !id) return inner;
|
|
550
|
+
const n = ++this.bookmarkCount;
|
|
551
|
+
return `<w:bookmarkStart w:id="${n}" w:name="${escapeXml(bookmarkName(id))}"/>${inner}<w:bookmarkEnd w:id="${n}"/>`;
|
|
552
|
+
}
|
|
553
|
+
drawing(src, alt, width, height) {
|
|
554
|
+
const image = typeof src === "string" ? this.images.get(src) : null;
|
|
555
|
+
const label = typeof alt === "string" ? alt : "";
|
|
556
|
+
if (!image || typeof src !== "string") return label ? this.text(`[${label}]`) : "";
|
|
557
|
+
let rel = this.imageRels.get(src);
|
|
558
|
+
if (!rel) {
|
|
559
|
+
const name = `image${this.media.length + 1}.${image.type}`;
|
|
560
|
+
this.media.push({ name: `word/media/${name}`, data: image.data });
|
|
561
|
+
rel = this.rel("image", `media/${name}`);
|
|
562
|
+
this.imageRels.set(src, rel);
|
|
563
|
+
}
|
|
564
|
+
let w = Number(width) || image.width || 300;
|
|
565
|
+
const ratio = image.width && image.height ? image.height / image.width : 0.75;
|
|
566
|
+
let h = Number(height) || w * ratio;
|
|
567
|
+
if (w > this.textWidthPx) {
|
|
568
|
+
h *= this.textWidthPx / w;
|
|
569
|
+
w = this.textWidthPx;
|
|
570
|
+
}
|
|
571
|
+
const cx = Math.round(w * EMU_PER_PX);
|
|
572
|
+
const cy = Math.round(h * EMU_PER_PX);
|
|
573
|
+
const id = ++this.drawingCount;
|
|
574
|
+
return `<w:drawing><wp:inline distT="0" distB="0" distL="0" distR="0"><wp:extent cx="${cx}" cy="${cy}"/><wp:docPr id="${id}" name="Picture ${id}" descr="${escapeXml(label)}"/><wp:cNvGraphicFramePr><a:graphicFrameLocks noChangeAspect="1"/></wp:cNvGraphicFramePr><a:graphic><a:graphicData uri="${NS.pic}"><pic:pic><pic:nvPicPr><pic:cNvPr id="${id}" name="Picture ${id}"/><pic:cNvPicPr/></pic:nvPicPr><pic:blipFill><a:blip r:embed="${rel}"/><a:stretch><a:fillRect/></a:stretch></pic:blipFill><pic:spPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="${cx}" cy="${cy}"/></a:xfrm><a:prstGeom prst="rect"><a:avLst/></a:prstGeom></pic:spPr></pic:pic></a:graphicData></a:graphic></wp:inline></w:drawing>`;
|
|
575
|
+
}
|
|
576
|
+
inlineNode(node, ctx) {
|
|
577
|
+
const name = node.type.name;
|
|
578
|
+
if (node.isText) return this.run(node.text ?? "", node.marks, ctx);
|
|
579
|
+
if (name === "hard_break") return this.tracked("<w:r><w:br/></w:r>", node.marks, ctx);
|
|
580
|
+
if (name === "image")
|
|
581
|
+
return this.tracked(
|
|
582
|
+
`<w:r>${this.drawing(node.attrs.src, node.attrs.alt, node.attrs.width, node.attrs.height)}</w:r>`,
|
|
583
|
+
node.marks,
|
|
584
|
+
ctx
|
|
585
|
+
);
|
|
586
|
+
if (name === "anchor") return this.bookmark(node.attrs.id);
|
|
587
|
+
if (name === "math_inline")
|
|
588
|
+
return this.run(String(node.attrs.latex ?? ""), node.marks, ctx, MATH);
|
|
589
|
+
if (name === "mergetag")
|
|
590
|
+
return this.run(
|
|
591
|
+
String(node.attrs.label || `{{${String(node.attrs.key ?? "")}}}`),
|
|
592
|
+
node.marks,
|
|
593
|
+
ctx
|
|
594
|
+
);
|
|
595
|
+
const text = node.type.spec.leafText?.(node) ?? node.textContent;
|
|
596
|
+
return text ? this.run(text, node.marks, ctx) : "";
|
|
597
|
+
}
|
|
598
|
+
/** Paragraph content; adjacent runs of the same link become one w:hyperlink. */
|
|
599
|
+
inline(node, ctx) {
|
|
600
|
+
let out = "";
|
|
601
|
+
let open = null;
|
|
602
|
+
node.forEach((child) => {
|
|
603
|
+
const link = child.marks.find((m) => m.type.name === "link");
|
|
604
|
+
const href = link && isSafeLinkUrl(link.attrs.href) ? String(link.attrs.href) : null;
|
|
605
|
+
if (href !== open) {
|
|
606
|
+
if (open !== null) out += "</w:hyperlink>";
|
|
607
|
+
if (href !== null)
|
|
608
|
+
out += href.startsWith("#") ? `<w:hyperlink w:anchor="${escapeXml(bookmarkName(href.slice(1)))}">` : `<w:hyperlink r:id="${this.rel("hyperlink", href, true)}">`;
|
|
609
|
+
open = href;
|
|
610
|
+
}
|
|
611
|
+
out += this.inlineNode(child, ctx);
|
|
612
|
+
});
|
|
613
|
+
if (open !== null) out += "</w:hyperlink>";
|
|
614
|
+
return out;
|
|
615
|
+
}
|
|
616
|
+
paragraph(node, ctx, options = {}) {
|
|
617
|
+
const attrs = node?.attrs ?? {};
|
|
618
|
+
const rtl = attrs.dir === "rtl";
|
|
619
|
+
const style = options.style ?? ctx.style;
|
|
620
|
+
const align = options.jc ?? (typeof attrs.align === "string" ? attrs.align : "");
|
|
621
|
+
const jc = align === "justify" ? "both" : align === "center" || align === "right" || align === "left" ? align : "";
|
|
622
|
+
const level = Number(attrs.indent) || 0;
|
|
623
|
+
const left = options.indent ?? (ctx.continuation ?? 0) + Math.max(0, level) * INDENT_TWIPS;
|
|
624
|
+
let spacing = "";
|
|
625
|
+
const lineHeight = typeof attrs.lineHeight === "string" ? attrs.lineHeight : "";
|
|
626
|
+
if (/^\d+(\.\d+)?$/.test(lineHeight))
|
|
627
|
+
spacing = `<w:spacing w:line="${Math.round(Number(lineHeight) * 240)}" w:lineRule="auto"/>`;
|
|
628
|
+
else {
|
|
629
|
+
const sz = halfPoints(lineHeight);
|
|
630
|
+
if (sz) spacing = `<w:spacing w:line="${sz * 10}" w:lineRule="exact"/>`;
|
|
631
|
+
}
|
|
632
|
+
const pPr = (style ? `<w:pStyle w:val="${style}"/>` : "") + (options.numPr ?? "") + (options.border ?? "") + (rtl ? "<w:bidi/>" : "") + spacing + (left && !options.numPr ? `<w:ind w:${rtl ? "right" : "left"}="${left}"/>` : "") + (jc ? `<w:jc w:val="${jc}"/>` : "") + (ctx.change ? `<w:rPr><${ctx.change.tag} ${this.revisionAttrs(ctx.change)}/></w:rPr>` : "");
|
|
633
|
+
const content = options.content ?? (node ? this.inline(node, ctx) : "");
|
|
634
|
+
return `<w:p>${pPr ? `<w:pPr>${pPr}</w:pPr>` : ""}${options.prefix ?? ""}${content}</w:p>`;
|
|
635
|
+
}
|
|
636
|
+
// ----- lists -----
|
|
637
|
+
numbering(ordered, style, start) {
|
|
638
|
+
const key = `${ordered ? "o" : "b"}:${typeof style === "string" ? style : ""}`;
|
|
639
|
+
let abstract = this.abstracts.get(key);
|
|
640
|
+
if (abstract === void 0) {
|
|
641
|
+
abstract = this.abstracts.size;
|
|
642
|
+
this.abstracts.set(key, abstract);
|
|
643
|
+
const first = typeof style === "string" ? ordered ? LIST_STYLES[style] : BULLET_STYLES[style] : void 0;
|
|
644
|
+
const levels = Array.from({ length: 9 }, (_, level) => {
|
|
645
|
+
const indent = `<w:pPr><w:ind w:left="${720 * (level + 1)}" w:hanging="360"/></w:pPr>`;
|
|
646
|
+
if (ordered) {
|
|
647
|
+
const format = level === 0 && first || ORDERED_FORMATS[level % 3];
|
|
648
|
+
return `<w:lvl w:ilvl="${level}"><w:start w:val="1"/><w:numFmt w:val="${format}"/><w:lvlText w:val="%${level + 1}."/><w:lvlJc w:val="left"/>${indent}</w:lvl>`;
|
|
649
|
+
}
|
|
650
|
+
const bullet = level === 0 && first || BULLETS[level % 3];
|
|
651
|
+
return `<w:lvl w:ilvl="${level}"><w:start w:val="1"/><w:numFmt w:val="bullet"/><w:lvlText w:val="${bullet}"/><w:lvlJc w:val="left"/>${indent}</w:lvl>`;
|
|
652
|
+
});
|
|
653
|
+
this.abstractXml.push(
|
|
654
|
+
`<w:abstractNum w:abstractNumId="${abstract}"><w:multiLevelType w:val="hybridMultilevel"/>${levels.join("")}</w:abstractNum>`
|
|
655
|
+
);
|
|
656
|
+
}
|
|
657
|
+
const id = ++this.numCount;
|
|
658
|
+
const restart = ordered ? `<w:lvlOverride w:ilvl="0"><w:startOverride w:val="${Math.max(0, start)}"/></w:lvlOverride>` : "";
|
|
659
|
+
this.numXml.push(
|
|
660
|
+
`<w:num w:numId="${id}"><w:abstractNumId w:val="${abstract}"/>${restart}</w:num>`
|
|
661
|
+
);
|
|
662
|
+
return id;
|
|
663
|
+
}
|
|
664
|
+
list(node, ctx) {
|
|
665
|
+
const ordered = node.type.name === "ordered_list";
|
|
666
|
+
const checklist = node.attrs.checklist === true;
|
|
667
|
+
const level = Math.min(8, ctx.listLevel + 1);
|
|
668
|
+
const numId = checklist ? 0 : this.numbering(ordered, node.attrs.listStyle, Number(node.attrs.start) || 1);
|
|
669
|
+
const inner = { ...ctx, listLevel: level, continuation: 720 * (level + 1) };
|
|
670
|
+
let out = "";
|
|
671
|
+
node.forEach((item) => {
|
|
672
|
+
let first = true;
|
|
673
|
+
item.forEach((child) => {
|
|
674
|
+
const name = child.type.name;
|
|
675
|
+
if (first && child.isTextblock) {
|
|
676
|
+
first = false;
|
|
677
|
+
out += this.paragraph(child, inner, {
|
|
678
|
+
numPr: numId ? `<w:numPr><w:ilvl w:val="${level}"/><w:numId w:val="${numId}"/></w:numPr>` : void 0,
|
|
679
|
+
prefix: checklist ? this.run(item.attrs.checked ? "\u2612 " : "\u2610 ", [], inner) : ""
|
|
680
|
+
});
|
|
681
|
+
} else if (name === "bullet_list" || name === "ordered_list") {
|
|
682
|
+
out += this.list(child, { ...ctx, listLevel: level });
|
|
683
|
+
} else {
|
|
684
|
+
first = false;
|
|
685
|
+
out += this.block(child, inner);
|
|
686
|
+
}
|
|
687
|
+
});
|
|
688
|
+
});
|
|
689
|
+
return out;
|
|
690
|
+
}
|
|
691
|
+
// ----- tables -----
|
|
692
|
+
table(node, ctx) {
|
|
693
|
+
const rows = [];
|
|
694
|
+
node.forEach((row) => rows.push(row));
|
|
695
|
+
const cover = /* @__PURE__ */ new Map();
|
|
696
|
+
const starts = /* @__PURE__ */ new Map();
|
|
697
|
+
let columns = 0;
|
|
698
|
+
rows.forEach((row, r) => {
|
|
699
|
+
let c = 0;
|
|
700
|
+
row.forEach((cell) => {
|
|
701
|
+
while (cover.has(`${r}:${c}`)) c++;
|
|
702
|
+
const placed = {
|
|
703
|
+
row: r,
|
|
704
|
+
col: c,
|
|
705
|
+
colspan: Math.max(1, Number(cell.attrs.colspan) || 1),
|
|
706
|
+
rowspan: Math.max(1, Math.min(rows.length - r, Number(cell.attrs.rowspan) || 1)),
|
|
707
|
+
cell
|
|
708
|
+
};
|
|
709
|
+
starts.set(`${r}:${c}`, placed);
|
|
710
|
+
for (let dr = 0; dr < placed.rowspan; dr++)
|
|
711
|
+
for (let dc = 0; dc < placed.colspan; dc++) cover.set(`${r + dr}:${c + dc}`, placed);
|
|
712
|
+
c += placed.colspan;
|
|
713
|
+
columns = Math.max(columns, c);
|
|
714
|
+
});
|
|
715
|
+
});
|
|
716
|
+
if (!columns) return "";
|
|
717
|
+
const widths = Array.from({ length: columns }, () => null);
|
|
718
|
+
for (const placed of starts.values()) {
|
|
719
|
+
const colwidth = placed.cell.attrs.colwidth;
|
|
720
|
+
if (Array.isArray(colwidth))
|
|
721
|
+
colwidth.forEach((w, i) => {
|
|
722
|
+
if (typeof w === "number" && w > 0 && widths[placed.col + i] == null)
|
|
723
|
+
widths[placed.col + i] = w;
|
|
724
|
+
});
|
|
725
|
+
}
|
|
726
|
+
const known = widths.reduce((sum, w) => sum + (w ?? 0), 0);
|
|
727
|
+
const unknown = widths.filter((w) => w == null).length;
|
|
728
|
+
const rest = unknown ? Math.max(40, (this.textWidthPx - known) / unknown) : 0;
|
|
729
|
+
const grid = widths.map((w) => Math.round((w ?? rest) * 15));
|
|
730
|
+
const align = node.attrs.align === "center" || node.attrs.align === "right" ? node.attrs.align : "";
|
|
731
|
+
const border = (side) => `<w:${side} w:val="single" w:sz="4" w:space="0" w:color="auto"/>`;
|
|
732
|
+
const tblPr = `<w:tblPr><w:tblW w:w="${grid.reduce((a, b) => a + b, 0)}" w:type="dxa"/>` + (align ? `<w:jc w:val="${align}"/>` : "") + `<w:tblBorders>${["top", "left", "bottom", "right", "insideH", "insideV"].map(border).join("")}</w:tblBorders><w:tblLayout w:type="fixed"/><w:tblCellMar><w:left w:w="108" w:type="dxa"/><w:right w:w="108" w:type="dxa"/></w:tblCellMar></w:tblPr>`;
|
|
733
|
+
const tblGrid = `<w:tblGrid>${grid.map((w) => `<w:gridCol w:w="${w}"/>`).join("")}</w:tblGrid>`;
|
|
734
|
+
const span = (col, colspan) => grid.slice(col, col + colspan).reduce((a, b) => a + b, 0);
|
|
735
|
+
let body = "";
|
|
736
|
+
rows.forEach((row, r) => {
|
|
737
|
+
const rowRevision = nodeRevision(row) ?? ctx.change ?? null;
|
|
738
|
+
const rowCtx = rowRevision ? { ...ctx, change: rowRevision } : ctx;
|
|
739
|
+
let header = row.childCount > 0;
|
|
740
|
+
row.forEach((cell) => {
|
|
741
|
+
if (cell.type.name !== "table_header") header = false;
|
|
742
|
+
});
|
|
743
|
+
let cells = "";
|
|
744
|
+
for (let c = 0; c < columns; ) {
|
|
745
|
+
const placed = cover.get(`${r}:${c}`);
|
|
746
|
+
if (!placed) {
|
|
747
|
+
cells += `<w:tc><w:tcPr><w:tcW w:w="${grid[c]}" w:type="dxa"/></w:tcPr><w:p/></w:tc>`;
|
|
748
|
+
c++;
|
|
749
|
+
continue;
|
|
750
|
+
}
|
|
751
|
+
const width = `<w:tcW w:w="${span(placed.col, placed.colspan)}" w:type="dxa"/>`;
|
|
752
|
+
const gridSpan = placed.colspan > 1 ? `<w:gridSpan w:val="${placed.colspan}"/>` : "";
|
|
753
|
+
if (placed.row !== r) {
|
|
754
|
+
cells += `<w:tc><w:tcPr>${width}${gridSpan}<w:vMerge/></w:tcPr><w:p/></w:tc>`;
|
|
755
|
+
} else {
|
|
756
|
+
const { cell } = placed;
|
|
757
|
+
const cellRevision = nodeRevision(cell);
|
|
758
|
+
const cellCtx = cellRevision ? { ...rowCtx, change: cellRevision } : rowCtx;
|
|
759
|
+
const fill = hexColor(cell.attrs.background);
|
|
760
|
+
const valign = cell.attrs.valign === "middle" ? "center" : cell.attrs.valign;
|
|
761
|
+
const tcPr = width + gridSpan + (placed.rowspan > 1 ? '<w:vMerge w:val="restart"/>' : "") + (fill ? `<w:shd w:val="clear" w:color="auto" w:fill="${fill}"/>` : "") + (valign === "top" || valign === "center" || valign === "bottom" ? `<w:vAlign w:val="${valign}"/>` : "") + (cellRevision ? `<w:${cellRevision.tag === "w:ins" ? "cellIns" : "cellDel"} ${this.revisionAttrs(cellRevision)}/>` : "");
|
|
762
|
+
let content = this.blocks(cell, {
|
|
763
|
+
...cellCtx,
|
|
764
|
+
listLevel: -1,
|
|
765
|
+
continuation: void 0,
|
|
766
|
+
style: void 0,
|
|
767
|
+
bold: ctx.bold || cell.type.name === "table_header"
|
|
768
|
+
});
|
|
769
|
+
if (!content.endsWith("</w:p>")) content += "<w:p/>";
|
|
770
|
+
cells += `<w:tc><w:tcPr>${tcPr}</w:tcPr>${content}</w:tc>`;
|
|
771
|
+
}
|
|
772
|
+
c += placed.colspan;
|
|
773
|
+
}
|
|
774
|
+
const trPr = (header ? "<w:tblHeader/>" : "") + (rowRevision ? `<${rowRevision.tag} ${this.revisionAttrs(rowRevision)}/>` : "");
|
|
775
|
+
body += `<w:tr>${trPr ? `<w:trPr>${trPr}</w:trPr>` : ""}${cells}</w:tr>`;
|
|
776
|
+
});
|
|
777
|
+
return `<w:tbl>${tblPr}${tblGrid}${body}</w:tbl>`;
|
|
778
|
+
}
|
|
779
|
+
// ----- blocks -----
|
|
780
|
+
blocks(parent, ctx) {
|
|
781
|
+
let out = "";
|
|
782
|
+
parent.forEach((child) => out += this.block(child, ctx));
|
|
783
|
+
return out;
|
|
784
|
+
}
|
|
785
|
+
block(node, outer) {
|
|
786
|
+
const name = node.type.name;
|
|
787
|
+
const own = nodeRevision(node);
|
|
788
|
+
const ctx = own ? { ...outer, change: own } : outer;
|
|
789
|
+
switch (name) {
|
|
790
|
+
case "paragraph":
|
|
791
|
+
return this.paragraph(node, ctx);
|
|
792
|
+
case "heading": {
|
|
793
|
+
const level = Math.min(6, Math.max(1, Number(node.attrs.level) || 1));
|
|
794
|
+
return this.paragraph(node, ctx, {
|
|
795
|
+
style: `Heading${level}`,
|
|
796
|
+
content: this.bookmark(node.attrs.id, this.inline(node, ctx))
|
|
797
|
+
});
|
|
798
|
+
}
|
|
799
|
+
case "blockquote":
|
|
800
|
+
return this.blocks(node, { ...ctx, style: "Quote" });
|
|
801
|
+
case "code_block":
|
|
802
|
+
return this.paragraph(null, ctx, {
|
|
803
|
+
style: "Code",
|
|
804
|
+
content: this.run(node.textContent, [], { ...ctx, bold: false })
|
|
805
|
+
});
|
|
806
|
+
case "bullet_list":
|
|
807
|
+
case "ordered_list":
|
|
808
|
+
return this.list(node, ctx);
|
|
809
|
+
case "table":
|
|
810
|
+
return this.table(node, ctx);
|
|
811
|
+
case "horizontal_rule":
|
|
812
|
+
return this.paragraph(null, ctx, {
|
|
813
|
+
border: '<w:pBdr><w:bottom w:val="single" w:sz="6" w:space="1" w:color="auto"/></w:pBdr>',
|
|
814
|
+
content: ""
|
|
815
|
+
});
|
|
816
|
+
case "pagebreak":
|
|
817
|
+
return '<w:p><w:r><w:br w:type="page"/></w:r></w:p>';
|
|
818
|
+
case "figure": {
|
|
819
|
+
let image = "";
|
|
820
|
+
let caption = "";
|
|
821
|
+
node.forEach((child) => {
|
|
822
|
+
if (child.type.name === "figure_image")
|
|
823
|
+
image = this.drawing(
|
|
824
|
+
child.attrs.src,
|
|
825
|
+
child.attrs.alt,
|
|
826
|
+
child.attrs.width,
|
|
827
|
+
child.attrs.height
|
|
828
|
+
);
|
|
829
|
+
else if (child.type.name === "figcaption")
|
|
830
|
+
caption = this.paragraph(child, ctx, { style: "Caption" });
|
|
831
|
+
});
|
|
832
|
+
const jc = node.attrs.align === "center" || node.attrs.align === "right" ? node.attrs.align : "";
|
|
833
|
+
return this.paragraph(null, ctx, {
|
|
834
|
+
jc,
|
|
835
|
+
content: image ? this.tracked(`<w:r>${image}</w:r>`, [], ctx) : ""
|
|
836
|
+
}) + caption;
|
|
837
|
+
}
|
|
838
|
+
case "math_block":
|
|
839
|
+
return this.paragraph(null, ctx, {
|
|
840
|
+
jc: "center",
|
|
841
|
+
content: this.run(String(node.attrs.latex ?? ""), [], ctx, MATH)
|
|
842
|
+
});
|
|
843
|
+
case "details":
|
|
844
|
+
return this.blocks(node, ctx);
|
|
845
|
+
case "details_summary":
|
|
846
|
+
return this.paragraph(node, { ...ctx, bold: true });
|
|
847
|
+
case "toc": {
|
|
848
|
+
const entries = Array.isArray(node.attrs.entries) ? node.attrs.entries : [];
|
|
849
|
+
const title = typeof node.attrs.title === "string" && node.attrs.title ? this.paragraph(null, ctx, {
|
|
850
|
+
content: this.run(node.attrs.title, [], { ...ctx, bold: true })
|
|
851
|
+
}) : "";
|
|
852
|
+
return title + entries.filter(
|
|
853
|
+
(e) => !!e && typeof e.id === "string"
|
|
854
|
+
).map(
|
|
855
|
+
(entry) => this.paragraph(null, ctx, {
|
|
856
|
+
indent: Math.max(0, (Number(entry.level) || 1) - 1) * 360,
|
|
857
|
+
content: `<w:hyperlink w:anchor="${escapeXml(bookmarkName(entry.id))}">${this.run(String(entry.text ?? ""), [], ctx, { style: "Hyperlink" })}</w:hyperlink>`
|
|
858
|
+
})
|
|
859
|
+
).join("");
|
|
860
|
+
}
|
|
861
|
+
// Word has no frames: a video or an embedded page is a link to it.
|
|
862
|
+
case "media":
|
|
863
|
+
case "pageembed":
|
|
864
|
+
case "link_card": {
|
|
865
|
+
const src = String(node.attrs.src ?? node.attrs.href ?? "");
|
|
866
|
+
if (!isSafeLinkUrl(src)) return "";
|
|
867
|
+
return this.paragraph(null, ctx, {
|
|
868
|
+
content: `<w:hyperlink r:id="${this.rel("hyperlink", src, true)}">${this.run(String(node.attrs.title || src), [], ctx)}</w:hyperlink>`
|
|
869
|
+
});
|
|
870
|
+
}
|
|
871
|
+
default:
|
|
872
|
+
if (node.isTextblock) return this.paragraph(node, ctx);
|
|
873
|
+
if (node.isBlock && node.childCount) return this.blocks(node, ctx);
|
|
874
|
+
return "";
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
// ----- header and footer -----
|
|
878
|
+
/** The header and footer parts written so far: word/header1.xml, word/footer1.xml. */
|
|
879
|
+
bands = [];
|
|
880
|
+
/**
|
|
881
|
+
* A header or footer part: one paragraph with the left part, a centre tab, the centre part, a right tab
|
|
882
|
+
* and the right part, in small grey text as in print. {page} and {pages} become PAGE and NUMPAGES fields,
|
|
883
|
+
* which Word fills in on every page.
|
|
884
|
+
*/
|
|
885
|
+
bandXml(kind, parts) {
|
|
886
|
+
const { layout } = this;
|
|
887
|
+
const width = twips(layout.width - layout.margins.left - layout.margins.right);
|
|
888
|
+
const rPr = '<w:rPr><w:color w:val="595959"/><w:sz w:val="18"/><w:szCs w:val="18"/></w:rPr>';
|
|
889
|
+
const field = (instr) => `<w:fldSimple w:instr=" ${instr} "><w:r>${rPr}<w:t>1</w:t></w:r></w:fldSimple>`;
|
|
890
|
+
const runs = (text) => text.split(/(\{pages?\})/).filter((part) => part !== "").map(
|
|
891
|
+
(part) => part === "{page}" ? field("PAGE") : part === "{pages}" ? field("NUMPAGES") : `<w:r>${rPr}<w:t xml:space="preserve">${escapeXml(part)}</w:t></w:r>`
|
|
892
|
+
).join("");
|
|
893
|
+
const tab = `<w:r>${rPr}<w:tab/></w:r>`;
|
|
894
|
+
return `${XML}<w:${kind} xmlns:w="${NS.w}" xmlns:r="${NS.r}"><w:p><w:pPr><w:tabs><w:tab w:val="center" w:pos="${Math.round(width / 2)}"/><w:tab w:val="right" w:pos="${width}"/></w:tabs><w:spacing w:before="0" w:after="0"/></w:pPr>${runs(parts.left)}${tab}${runs(parts.center)}${tab}${runs(parts.right)}</w:p></w:${kind}>`;
|
|
895
|
+
}
|
|
896
|
+
/** The header or footer part and its reference for the section ('' when there is none). */
|
|
897
|
+
bandReference(kind, parts) {
|
|
898
|
+
if (!parts) return "";
|
|
899
|
+
const name = `${kind}1.xml`;
|
|
900
|
+
const id = this.rel(kind, name);
|
|
901
|
+
this.bands.push({
|
|
902
|
+
name: `word/${name}`,
|
|
903
|
+
xml: this.bandXml(kind === "header" ? "hdr" : "ftr", parts),
|
|
904
|
+
contentType: `application/vnd.openxmlformats-officedocument.wordprocessingml.${kind}+xml`
|
|
905
|
+
});
|
|
906
|
+
return `<w:${kind}Reference w:type="default" r:id="${id}"/>`;
|
|
907
|
+
}
|
|
908
|
+
/** The header and footer parts, after document(). */
|
|
909
|
+
bandFiles() {
|
|
910
|
+
const encode = (text) => new TextEncoder().encode(text);
|
|
911
|
+
return {
|
|
912
|
+
entries: this.bands.map((band) => ({ name: band.name, data: encode(band.xml) })),
|
|
913
|
+
overrides: this.bands.map((band) => `<Override PartName="/${band.name}" ContentType="${band.contentType}"/>`).join("")
|
|
914
|
+
};
|
|
915
|
+
}
|
|
916
|
+
// ----- parts of the file -----
|
|
917
|
+
document(doc) {
|
|
918
|
+
let body = this.blocks(doc, { listLevel: -1 });
|
|
919
|
+
if (!body.endsWith("</w:p>")) body += "<w:p/>";
|
|
920
|
+
const { layout } = this;
|
|
921
|
+
const m = layout.margins;
|
|
922
|
+
const landscape = layout.width > layout.height ? ' w:orient="landscape"' : "";
|
|
923
|
+
const references = this.bandReference("header", layout.header) + this.bandReference("footer", layout.footer);
|
|
924
|
+
const distance = (margin) => twips(Math.min(12.5, Math.max(3, margin / 2)));
|
|
925
|
+
const titlePage = references && layout.differentFirstPage ? "<w:titlePg/>" : "";
|
|
926
|
+
const sectPr = `<w:sectPr>${references}<w:pgSz w:w="${twips(layout.width)}" w:h="${twips(layout.height)}"${landscape}/><w:pgMar w:top="${twips(m.top)}" w:right="${twips(m.right)}" w:bottom="${twips(m.bottom)}" w:left="${twips(m.left)}" w:header="${distance(m.top)}" w:footer="${distance(m.bottom)}" w:gutter="0"/>${titlePage}</w:sectPr>`;
|
|
927
|
+
return XML + `<w:document xmlns:w="${NS.w}" xmlns:r="${NS.r}" xmlns:wp="${NS.wp}" xmlns:a="${NS.a}" xmlns:pic="${NS.pic}"><w:body>${body}${sectPr}</w:body></w:document>`;
|
|
928
|
+
}
|
|
929
|
+
numberingXml() {
|
|
930
|
+
return `${XML}<w:numbering xmlns:w="${NS.w}">${this.abstractXml.join("")}${this.numXml.join("")}</w:numbering>`;
|
|
931
|
+
}
|
|
932
|
+
relsXml() {
|
|
933
|
+
return `${XML}<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="${NS.rel}/styles" Target="styles.xml"/><Relationship Id="rId2" Type="${NS.rel}/numbering" Target="numbering.xml"/>${this.rels.join("")}</Relationships>`;
|
|
934
|
+
}
|
|
935
|
+
mediaFiles() {
|
|
936
|
+
return this.media;
|
|
937
|
+
}
|
|
938
|
+
};
|
|
939
|
+
function stylesXml(font, size) {
|
|
940
|
+
const f = escapeXml(font);
|
|
941
|
+
const sz = Math.round(size * 2);
|
|
942
|
+
const heading = (level, pt) => `<w:style w:type="paragraph" w:styleId="Heading${level}"><w:name w:val="heading ${level}"/><w:basedOn w:val="Normal"/><w:next w:val="Normal"/><w:uiPriority w:val="9"/><w:qFormat/><w:pPr><w:keepNext/><w:spacing w:before="${Math.round(pt * 20 * 1.2)}" w:after="${Math.round(pt * 10)}"/><w:outlineLvl w:val="${level - 1}"/></w:pPr><w:rPr><w:b/><w:bCs/><w:sz w:val="${Math.round(pt * 2)}"/><w:szCs w:val="${Math.round(pt * 2)}"/></w:rPr></w:style>`;
|
|
943
|
+
const headingSizes = [2, 1.5, 1.25, 1, 0.875, 0.85];
|
|
944
|
+
return `${XML}<w:styles xmlns:w="${NS.w}"><w:docDefaults><w:rPrDefault><w:rPr><w:rFonts w:ascii="${f}" w:hAnsi="${f}" w:cs="${f}" w:eastAsia="${f}"/><w:sz w:val="${sz}"/><w:szCs w:val="${sz}"/></w:rPr></w:rPrDefault><w:pPrDefault><w:pPr><w:spacing w:after="${Math.round(size * 20 * 0.75)}" w:line="384" w:lineRule="auto"/></w:pPr></w:pPrDefault></w:docDefaults><w:style w:type="paragraph" w:default="1" w:styleId="Normal"><w:name w:val="Normal"/><w:qFormat/></w:style>` + headingSizes.map((k, i) => heading(i + 1, size * k)).join("") + `<w:style w:type="paragraph" w:styleId="Quote"><w:name w:val="Quote"/><w:basedOn w:val="Normal"/><w:qFormat/><w:pPr><w:pBdr><w:left w:val="single" w:sz="18" w:space="8" w:color="D0D7DE"/></w:pBdr><w:ind w:left="360"/></w:pPr><w:rPr><w:color w:val="59636E"/></w:rPr></w:style><w:style w:type="paragraph" w:styleId="Code"><w:name w:val="Code"/><w:basedOn w:val="Normal"/><w:pPr><w:shd w:val="clear" w:color="auto" w:fill="F6F8FA"/><w:spacing w:line="276" w:lineRule="auto"/></w:pPr><w:rPr><w:rFonts w:ascii="Consolas" w:hAnsi="Consolas" w:cs="Consolas"/><w:sz w:val="${Math.round(sz * 0.85)}"/></w:rPr></w:style><w:style w:type="paragraph" w:styleId="Caption"><w:name w:val="caption"/><w:basedOn w:val="Normal"/><w:qFormat/><w:rPr><w:i/><w:color w:val="59636E"/><w:sz w:val="${Math.round(sz * 0.85)}"/></w:rPr></w:style><w:style w:type="character" w:styleId="Hyperlink"><w:name w:val="Hyperlink"/><w:rPr><w:color w:val="0969DA"/><w:u w:val="single"/></w:rPr></w:style></w:styles>`;
|
|
945
|
+
}
|
|
946
|
+
function imageSources(doc) {
|
|
947
|
+
const sources = /* @__PURE__ */ new Set();
|
|
948
|
+
doc.descendants((node) => {
|
|
949
|
+
if ((node.type.name === "image" || node.type.name === "figure_image") && node.attrs.src)
|
|
950
|
+
sources.add(String(node.attrs.src));
|
|
951
|
+
});
|
|
952
|
+
return [...sources];
|
|
953
|
+
}
|
|
954
|
+
async function toDocx(doc, options = {}) {
|
|
955
|
+
const layout = options.page && "width" in options.page && typeof options.page.width === "number" ? options.page : resolvePageLayout(options.page ?? {});
|
|
956
|
+
const load = options.loadImage ?? loadImage;
|
|
957
|
+
const images = /* @__PURE__ */ new Map();
|
|
958
|
+
await Promise.all(
|
|
959
|
+
imageSources(doc).map(async (src) => {
|
|
960
|
+
images.set(src, await load(src).catch(() => null));
|
|
961
|
+
})
|
|
962
|
+
);
|
|
963
|
+
const writer = new DocxWriter(layout, images);
|
|
964
|
+
const documentXml = writer.document(doc);
|
|
965
|
+
const bands = writer.bandFiles();
|
|
966
|
+
const encode = (text) => new TextEncoder().encode(text);
|
|
967
|
+
const title = options.title ? `<dc:title>${escapeXml(options.title)}</dc:title>` : "";
|
|
968
|
+
const files = [
|
|
969
|
+
{
|
|
970
|
+
name: "[Content_Types].xml",
|
|
971
|
+
data: encode(
|
|
972
|
+
`${XML}<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Default Extension="png" ContentType="image/png"/><Default Extension="jpeg" ContentType="image/jpeg"/><Default Extension="gif" ContentType="image/gif"/><Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/><Override PartName="/word/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"/><Override PartName="/word/numbering.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml"/><Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"/><Override PartName="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml"/>` + bands.overrides + `</Types>`
|
|
973
|
+
)
|
|
974
|
+
},
|
|
975
|
+
{
|
|
976
|
+
name: "_rels/.rels",
|
|
977
|
+
data: encode(
|
|
978
|
+
`${XML}<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="${NS.rel}/officeDocument" Target="word/document.xml"/><Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/><Relationship Id="rId3" Type="${NS.rel}/extended-properties" Target="docProps/app.xml"/></Relationships>`
|
|
979
|
+
)
|
|
980
|
+
},
|
|
981
|
+
{ name: "word/document.xml", data: encode(documentXml) },
|
|
982
|
+
{
|
|
983
|
+
name: "word/styles.xml",
|
|
984
|
+
data: encode(stylesXml(options.font ?? "Calibri", options.fontSize ?? 12))
|
|
985
|
+
},
|
|
986
|
+
{ name: "word/numbering.xml", data: encode(writer.numberingXml()) },
|
|
987
|
+
{ name: "word/_rels/document.xml.rels", data: encode(writer.relsXml()) },
|
|
988
|
+
{
|
|
989
|
+
name: "docProps/core.xml",
|
|
990
|
+
data: encode(
|
|
991
|
+
`${XML}<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/">${title}</cp:coreProperties>`
|
|
992
|
+
)
|
|
993
|
+
},
|
|
994
|
+
{
|
|
995
|
+
name: "docProps/app.xml",
|
|
996
|
+
data: encode(
|
|
997
|
+
`${XML}<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"><Application>NovaProse</Application></Properties>`
|
|
998
|
+
)
|
|
999
|
+
},
|
|
1000
|
+
...bands.entries,
|
|
1001
|
+
...writer.mediaFiles()
|
|
1002
|
+
];
|
|
1003
|
+
return zip(files);
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
// src/docx/import.ts
|
|
1007
|
+
var HIGHLIGHT = {
|
|
1008
|
+
yellow: "#ffff00",
|
|
1009
|
+
green: "#00ff00",
|
|
1010
|
+
cyan: "#00ffff",
|
|
1011
|
+
magenta: "#ff00ff",
|
|
1012
|
+
blue: "#0000ff",
|
|
1013
|
+
red: "#ff0000",
|
|
1014
|
+
darkBlue: "#000080",
|
|
1015
|
+
darkCyan: "#008080",
|
|
1016
|
+
darkGreen: "#008000",
|
|
1017
|
+
darkMagenta: "#800080",
|
|
1018
|
+
darkRed: "#800000",
|
|
1019
|
+
darkYellow: "#808000",
|
|
1020
|
+
darkGray: "#808080",
|
|
1021
|
+
lightGray: "#c0c0c0",
|
|
1022
|
+
black: "#000000",
|
|
1023
|
+
white: "#ffffff"
|
|
1024
|
+
};
|
|
1025
|
+
var LIST_STYLE = {
|
|
1026
|
+
lowerLetter: "lower-alpha",
|
|
1027
|
+
upperLetter: "upper-alpha",
|
|
1028
|
+
lowerRoman: "lower-roman",
|
|
1029
|
+
upperRoman: "upper-roman"
|
|
1030
|
+
};
|
|
1031
|
+
var MIME = {
|
|
1032
|
+
png: "image/png",
|
|
1033
|
+
jpg: "image/jpeg",
|
|
1034
|
+
jpeg: "image/jpeg",
|
|
1035
|
+
gif: "image/gif",
|
|
1036
|
+
bmp: "image/bmp",
|
|
1037
|
+
webp: "image/webp"
|
|
1038
|
+
};
|
|
1039
|
+
var escape = (text) => text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
1040
|
+
var on = (el) => !!el && !["0", "false", "off", "none"].includes(el.attrs["w:val"] ?? "");
|
|
1041
|
+
var val = (el) => el?.attrs["w:val"];
|
|
1042
|
+
function bytesToBase64(bytes) {
|
|
1043
|
+
let binary = "";
|
|
1044
|
+
for (let i = 0; i < bytes.length; i += 32768)
|
|
1045
|
+
binary += String.fromCharCode(...bytes.subarray(i, i + 32768));
|
|
1046
|
+
return btoa(binary);
|
|
1047
|
+
}
|
|
1048
|
+
function resolvePart(base, target) {
|
|
1049
|
+
if (target.startsWith("/")) return target.slice(1);
|
|
1050
|
+
const parts = base.split("/").slice(0, -1);
|
|
1051
|
+
for (const piece of target.split("/")) {
|
|
1052
|
+
if (piece === "..") parts.pop();
|
|
1053
|
+
else if (piece !== ".") parts.push(piece);
|
|
1054
|
+
}
|
|
1055
|
+
return parts.join("/");
|
|
1056
|
+
}
|
|
1057
|
+
function revisionKey(node, kind) {
|
|
1058
|
+
return `${kind}|${(node.attrs["w:author"] ?? "").slice(0, 80)}|${Date.parse(node.attrs["w:date"] ?? "")}`;
|
|
1059
|
+
}
|
|
1060
|
+
function wholeChange(props, insert, remove) {
|
|
1061
|
+
const deleted = element(props, remove);
|
|
1062
|
+
if (deleted) return { node: deleted, kind: "del", change: "delete" };
|
|
1063
|
+
const inserted = element(props, insert);
|
|
1064
|
+
return inserted ? { node: inserted, kind: "ins", change: "insert" } : null;
|
|
1065
|
+
}
|
|
1066
|
+
var DocxReader = class {
|
|
1067
|
+
constructor(files, revisions = "accept") {
|
|
1068
|
+
this.files = files;
|
|
1069
|
+
this.revisions = revisions;
|
|
1070
|
+
}
|
|
1071
|
+
files;
|
|
1072
|
+
revisions;
|
|
1073
|
+
warnings = /* @__PURE__ */ new Set();
|
|
1074
|
+
styles = /* @__PURE__ */ new Map();
|
|
1075
|
+
levels = /* @__PURE__ */ new Map();
|
|
1076
|
+
// numId → levels
|
|
1077
|
+
starts = /* @__PURE__ */ new Map();
|
|
1078
|
+
// numId:ilvl → startOverride
|
|
1079
|
+
footnotes = /* @__PURE__ */ new Map();
|
|
1080
|
+
notes = [];
|
|
1081
|
+
rels = /* @__PURE__ */ new Map();
|
|
1082
|
+
part = "word/document.xml";
|
|
1083
|
+
images = 0;
|
|
1084
|
+
/** Inside a table header row: th is bold anyway, so text boldness isn't carried over. */
|
|
1085
|
+
inHeader = false;
|
|
1086
|
+
/** Tracked changes without an id get one from this count. */
|
|
1087
|
+
revisionCount = 0;
|
|
1088
|
+
/**
|
|
1089
|
+
* Inside a row or cell inserted or deleted as a whole (kept as a suggestion): the text revisions
|
|
1090
|
+
* of the same kind, author and date in it are part of that one, not suggestions of their own.
|
|
1091
|
+
*/
|
|
1092
|
+
wholeRevision = null;
|
|
1093
|
+
xml(name) {
|
|
1094
|
+
const bytes = this.files.get(name);
|
|
1095
|
+
return bytes ? parseXml(new TextDecoder().decode(bytes)) : void 0;
|
|
1096
|
+
}
|
|
1097
|
+
relsOf(part) {
|
|
1098
|
+
const map = /* @__PURE__ */ new Map();
|
|
1099
|
+
const dir = part.split("/").slice(0, -1).join("/");
|
|
1100
|
+
const name = part.split("/").pop();
|
|
1101
|
+
const rels = this.xml(`${dir ? `${dir}/` : ""}_rels/${name}.rels`);
|
|
1102
|
+
for (const rel of elements(path(rels, "Relationships"), "Relationship")) {
|
|
1103
|
+
const external = rel.attrs.TargetMode === "External";
|
|
1104
|
+
map.set(rel.attrs.Id ?? "", {
|
|
1105
|
+
type: (rel.attrs.Type ?? "").split("/").pop() ?? "",
|
|
1106
|
+
target: external ? rel.attrs.Target ?? "" : resolvePart(part, rel.attrs.Target ?? ""),
|
|
1107
|
+
external
|
|
1108
|
+
});
|
|
1109
|
+
}
|
|
1110
|
+
return map;
|
|
1111
|
+
}
|
|
1112
|
+
load() {
|
|
1113
|
+
const root = this.relsOf("_rels/.rels");
|
|
1114
|
+
const rootRels = this.xml("_rels/.rels");
|
|
1115
|
+
for (const rel of elements(path(rootRels, "Relationships"), "Relationship"))
|
|
1116
|
+
if ((rel.attrs.Type ?? "").endsWith("/officeDocument"))
|
|
1117
|
+
this.part = resolvePart("", rel.attrs.Target ?? "word/document.xml");
|
|
1118
|
+
void root;
|
|
1119
|
+
this.rels = this.relsOf(this.part);
|
|
1120
|
+
const target = (type) => [...this.rels.values()].find((r) => r.type === type)?.target;
|
|
1121
|
+
for (const style of elements(path(this.xml(target("styles") ?? ""), "w:styles"), "w:style")) {
|
|
1122
|
+
const pPr = element(style, "w:pPr");
|
|
1123
|
+
const outline = val(element(pPr, "w:outlineLvl"));
|
|
1124
|
+
this.styles.set(style.attrs["w:styleId"] ?? "", {
|
|
1125
|
+
name: (val(element(style, "w:name")) ?? "").toLowerCase(),
|
|
1126
|
+
basedOn: val(element(style, "w:basedOn")),
|
|
1127
|
+
outline: outline !== void 0 ? Number(outline) : void 0,
|
|
1128
|
+
numPr: element(pPr, "w:numPr"),
|
|
1129
|
+
jc: val(element(pPr, "w:jc")),
|
|
1130
|
+
rPr: element(style, "w:rPr")
|
|
1131
|
+
});
|
|
1132
|
+
}
|
|
1133
|
+
const numbering = path(this.xml(target("numbering") ?? ""), "w:numbering");
|
|
1134
|
+
const abstracts = /* @__PURE__ */ new Map();
|
|
1135
|
+
for (const abstract of elements(numbering, "w:abstractNum")) {
|
|
1136
|
+
const levels = [];
|
|
1137
|
+
for (const lvl of elements(abstract, "w:lvl"))
|
|
1138
|
+
levels[Number(lvl.attrs["w:ilvl"]) || 0] = {
|
|
1139
|
+
format: val(element(lvl, "w:numFmt")) ?? "decimal",
|
|
1140
|
+
text: val(element(lvl, "w:lvlText")) ?? "",
|
|
1141
|
+
start: Number(val(element(lvl, "w:start")) ?? 1)
|
|
1142
|
+
};
|
|
1143
|
+
abstracts.set(abstract.attrs["w:abstractNumId"] ?? "", levels);
|
|
1144
|
+
}
|
|
1145
|
+
for (const num of elements(numbering, "w:num")) {
|
|
1146
|
+
const id = num.attrs["w:numId"] ?? "";
|
|
1147
|
+
this.levels.set(id, abstracts.get(val(element(num, "w:abstractNumId")) ?? "") ?? []);
|
|
1148
|
+
for (const override of elements(num, "w:lvlOverride")) {
|
|
1149
|
+
const start = val(element(override, "w:startOverride"));
|
|
1150
|
+
if (start !== void 0)
|
|
1151
|
+
this.starts.set(`${id}:${override.attrs["w:ilvl"]}`, Number(start));
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
for (const note of elements(
|
|
1155
|
+
path(this.xml(target("footnotes") ?? ""), "w:footnotes"),
|
|
1156
|
+
"w:footnote"
|
|
1157
|
+
))
|
|
1158
|
+
this.footnotes.set(note.attrs["w:id"] ?? "", note);
|
|
1159
|
+
return path(this.xml(this.part), "w:document", "w:body");
|
|
1160
|
+
}
|
|
1161
|
+
/** A style and its ancestors (basedOn), without cycles. */
|
|
1162
|
+
styleChain(id) {
|
|
1163
|
+
const chain = [];
|
|
1164
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1165
|
+
while (id && !seen.has(id)) {
|
|
1166
|
+
seen.add(id);
|
|
1167
|
+
const style = this.styles.get(id);
|
|
1168
|
+
if (!style) break;
|
|
1169
|
+
chain.push(style);
|
|
1170
|
+
id = style.basedOn;
|
|
1171
|
+
}
|
|
1172
|
+
return chain;
|
|
1173
|
+
}
|
|
1174
|
+
headingLevel(styleId, pPr) {
|
|
1175
|
+
const own = val(element(pPr, "w:outlineLvl"));
|
|
1176
|
+
if (own !== void 0 && Number(own) < 6) return Number(own) + 1;
|
|
1177
|
+
for (const style of this.styleChain(styleId)) {
|
|
1178
|
+
const named = /^heading (\d)$/.exec(style.name);
|
|
1179
|
+
if (named) return Math.min(6, Number(named[1]));
|
|
1180
|
+
if (style.name === "title") return 1;
|
|
1181
|
+
if (style.outline !== void 0 && style.outline < 6) return style.outline + 1;
|
|
1182
|
+
}
|
|
1183
|
+
return 0;
|
|
1184
|
+
}
|
|
1185
|
+
styleKind(styleId) {
|
|
1186
|
+
for (const style of this.styleChain(styleId)) {
|
|
1187
|
+
if (/quote/.test(style.name)) return "quote";
|
|
1188
|
+
if (/^(html preformatted|code|source code|macro text)/.test(style.name)) return "code";
|
|
1189
|
+
}
|
|
1190
|
+
return null;
|
|
1191
|
+
}
|
|
1192
|
+
// ---------- text ----------
|
|
1193
|
+
/** A run's formatting as HTML tags around its text. */
|
|
1194
|
+
runStyle(rPr, inLink = false) {
|
|
1195
|
+
const { bold, italic, underline, strike, vertical, color, background, font, size } = this.runFormat(rPr, inLink);
|
|
1196
|
+
const code = MONOSPACE.test(font);
|
|
1197
|
+
const css = [];
|
|
1198
|
+
if (color) css.push(`color: ${color}`);
|
|
1199
|
+
if (background && !(code && CODE_SHADES.has(background)))
|
|
1200
|
+
css.push(`background-color: ${background}`);
|
|
1201
|
+
if (font && !code) css.push(`font-family: ${font}`);
|
|
1202
|
+
if (size) css.push(`font-size: ${size}`);
|
|
1203
|
+
const tags = [];
|
|
1204
|
+
if (bold) tags.push("strong");
|
|
1205
|
+
if (italic) tags.push("em");
|
|
1206
|
+
if (underline) tags.push("u");
|
|
1207
|
+
if (strike) tags.push("s");
|
|
1208
|
+
if (vertical === "superscript") tags.push("sup");
|
|
1209
|
+
if (vertical === "subscript") tags.push("sub");
|
|
1210
|
+
if (code) tags.push("code");
|
|
1211
|
+
let open = tags.map((t) => `<${t}>`).join("");
|
|
1212
|
+
let close = tags.reverse().map((t) => `</${t}>`).join("");
|
|
1213
|
+
if (css.length) {
|
|
1214
|
+
open = `<span style="${escape(css.join("; "))}">${open}`;
|
|
1215
|
+
close = `${close}</span>`;
|
|
1216
|
+
}
|
|
1217
|
+
return { open, close };
|
|
1218
|
+
}
|
|
1219
|
+
/**
|
|
1220
|
+
* A run's formatting as the editor's marks (JSON): what a suggested format remembers as the text's
|
|
1221
|
+
* formatting before a tracked formatting change (w:rPrChange).
|
|
1222
|
+
*/
|
|
1223
|
+
formatMarks(rPr, inLink = false) {
|
|
1224
|
+
const { bold, italic, underline, strike, vertical, color, background, font, size } = this.runFormat(rPr, inLink);
|
|
1225
|
+
const code = MONOSPACE.test(font);
|
|
1226
|
+
const marks = [];
|
|
1227
|
+
if (bold) marks.push({ type: "bold" });
|
|
1228
|
+
if (italic) marks.push({ type: "italic" });
|
|
1229
|
+
if (underline) marks.push({ type: "underline" });
|
|
1230
|
+
if (strike) marks.push({ type: "strike" });
|
|
1231
|
+
if (code) marks.push({ type: "code" });
|
|
1232
|
+
if (vertical === "superscript") marks.push({ type: "superscript" });
|
|
1233
|
+
if (vertical === "subscript") marks.push({ type: "subscript" });
|
|
1234
|
+
if (color) marks.push({ type: "color", attrs: { value: color } });
|
|
1235
|
+
if (background && !(code && CODE_SHADES.has(background)))
|
|
1236
|
+
marks.push({ type: "background", attrs: { value: background } });
|
|
1237
|
+
if (font && !code)
|
|
1238
|
+
marks.push({ type: "font_family", attrs: { value: /\s/.test(font) ? `"${font}"` : font } });
|
|
1239
|
+
if (size) marks.push({ type: "font_size", attrs: { value: size } });
|
|
1240
|
+
return JSON.stringify(marks);
|
|
1241
|
+
}
|
|
1242
|
+
/** A run's formatting. Inside a link, color and underline belong to the link itself and aren't carried over. */
|
|
1243
|
+
runFormat(rPr, inLink) {
|
|
1244
|
+
const props = [];
|
|
1245
|
+
for (const style of this.styleChain(val(element(rPr, "w:rStyle"))).reverse())
|
|
1246
|
+
if (style.rPr && !(inLink && style.name === "hyperlink")) props.push(style.rPr);
|
|
1247
|
+
if (rPr) props.push(rPr);
|
|
1248
|
+
let bold = false;
|
|
1249
|
+
let italic = false;
|
|
1250
|
+
let underline = false;
|
|
1251
|
+
let strike = false;
|
|
1252
|
+
let vertical = "";
|
|
1253
|
+
let color = "";
|
|
1254
|
+
let background = "";
|
|
1255
|
+
let font = "";
|
|
1256
|
+
let size = "";
|
|
1257
|
+
for (const p of props) {
|
|
1258
|
+
if (element(p, "w:b") && !this.inHeader) bold = on(element(p, "w:b"));
|
|
1259
|
+
if (element(p, "w:i")) italic = on(element(p, "w:i"));
|
|
1260
|
+
if (element(p, "w:u") && !inLink) underline = on(element(p, "w:u"));
|
|
1261
|
+
if (element(p, "w:strike") || element(p, "w:dstrike"))
|
|
1262
|
+
strike = on(element(p, "w:strike") ?? element(p, "w:dstrike"));
|
|
1263
|
+
const align = val(element(p, "w:vertAlign"));
|
|
1264
|
+
if (align) vertical = align;
|
|
1265
|
+
const ownColor = val(element(p, "w:color"));
|
|
1266
|
+
if (ownColor && !inLink && /^[0-9a-f]{6}$/i.test(ownColor))
|
|
1267
|
+
color = `#${ownColor.toLowerCase()}`;
|
|
1268
|
+
const highlight = HIGHLIGHT[val(element(p, "w:highlight")) ?? ""];
|
|
1269
|
+
const fill = element(p, "w:shd")?.attrs["w:fill"];
|
|
1270
|
+
if (highlight) background = highlight;
|
|
1271
|
+
else if (fill && /^[0-9a-f]{6}$/i.test(fill)) background = `#${fill.toLowerCase()}`;
|
|
1272
|
+
const ownFont = element(p, "w:rFonts")?.attrs["w:ascii"];
|
|
1273
|
+
if (ownFont) font = ownFont.replace(/[;"<>{}]/g, "");
|
|
1274
|
+
const sz = Number(val(element(p, "w:sz")));
|
|
1275
|
+
if (sz > 0) size = `${sz / 2}pt`;
|
|
1276
|
+
}
|
|
1277
|
+
return { bold, italic, underline, strike, vertical, color, background, font, size };
|
|
1278
|
+
}
|
|
1279
|
+
image(rid, width, height, alt = "") {
|
|
1280
|
+
const rel = rid ? this.rels.get(rid) : void 0;
|
|
1281
|
+
if (!rel) return "";
|
|
1282
|
+
if (rel.external) {
|
|
1283
|
+
return /^https?:/i.test(rel.target) ? `<img src="${escape(rel.target)}" alt="${escape(alt)}"${width ? ` width="${width}"` : ""}${height ? ` height="${height}"` : ""}>` : "";
|
|
1284
|
+
}
|
|
1285
|
+
const bytes = this.files.get(rel.target);
|
|
1286
|
+
const ext = rel.target.split(".").pop()?.toLowerCase() ?? "";
|
|
1287
|
+
const mime = MIME[ext];
|
|
1288
|
+
if (!bytes || !mime) {
|
|
1289
|
+
this.warnings.add(`image format .${ext || "?"}`);
|
|
1290
|
+
return "";
|
|
1291
|
+
}
|
|
1292
|
+
this.images++;
|
|
1293
|
+
return `<img src="data:${mime};base64,${bytesToBase64(bytes)}" alt="${escape(alt)}"${width ? ` width="${width}"` : ""}${height ? ` height="${height}"` : ""}>`;
|
|
1294
|
+
}
|
|
1295
|
+
drawing(drawing) {
|
|
1296
|
+
const holder = element(drawing, "wp:inline") ?? element(drawing, "wp:anchor");
|
|
1297
|
+
const extent = element(holder, "wp:extent");
|
|
1298
|
+
const px = (emu) => emu ? Math.round(Number(emu) / 9525) : void 0;
|
|
1299
|
+
const docPr = element(holder, "wp:docPr");
|
|
1300
|
+
let blip;
|
|
1301
|
+
const find = (el) => {
|
|
1302
|
+
for (const child of elements(el)) {
|
|
1303
|
+
if (blip) return;
|
|
1304
|
+
if (child.name === "a:blip") blip = child;
|
|
1305
|
+
else find(child);
|
|
1306
|
+
}
|
|
1307
|
+
};
|
|
1308
|
+
if (holder) find(holder);
|
|
1309
|
+
return this.image(
|
|
1310
|
+
blip?.attrs["r:embed"] ?? blip?.attrs["r:link"],
|
|
1311
|
+
px(extent?.attrs.cx),
|
|
1312
|
+
px(extent?.attrs.cy),
|
|
1313
|
+
docPr?.attrs.descr ?? docPr?.attrs.title ?? ""
|
|
1314
|
+
);
|
|
1315
|
+
}
|
|
1316
|
+
/** Old images (VML): v:imagedata inside w:pict / w:object. */
|
|
1317
|
+
vml(pict) {
|
|
1318
|
+
let data;
|
|
1319
|
+
let shape;
|
|
1320
|
+
const find = (el) => {
|
|
1321
|
+
for (const child of elements(el)) {
|
|
1322
|
+
if (child.name === "v:shape") shape = child;
|
|
1323
|
+
if (child.name === "v:imagedata") data = child;
|
|
1324
|
+
else find(child);
|
|
1325
|
+
}
|
|
1326
|
+
};
|
|
1327
|
+
find(pict);
|
|
1328
|
+
if (!data) return "";
|
|
1329
|
+
const style = shape?.attrs.style ?? "";
|
|
1330
|
+
const size = (prop) => {
|
|
1331
|
+
const m = new RegExp(`${prop}:\\s*([\\d.]+)(pt|px|in)`).exec(style);
|
|
1332
|
+
if (!m) return void 0;
|
|
1333
|
+
const n = Number(m[1]);
|
|
1334
|
+
return Math.round(m[2] === "pt" ? n * (4 / 3) : m[2] === "in" ? n * 96 : n);
|
|
1335
|
+
};
|
|
1336
|
+
return this.image(
|
|
1337
|
+
data.attrs["r:id"],
|
|
1338
|
+
size("width"),
|
|
1339
|
+
size("height"),
|
|
1340
|
+
data.attrs["o:title"] ?? ""
|
|
1341
|
+
);
|
|
1342
|
+
}
|
|
1343
|
+
/**
|
|
1344
|
+
* Paragraph content as HTML. Returns pieces separated by page breaks.
|
|
1345
|
+
* Fields (fldChar): between begin and separate is the code (not text), after separate the result.
|
|
1346
|
+
*/
|
|
1347
|
+
inline(parent, state) {
|
|
1348
|
+
for (const node of elements(parent)) {
|
|
1349
|
+
switch (node.name) {
|
|
1350
|
+
case "w:r":
|
|
1351
|
+
this.run(node, state);
|
|
1352
|
+
break;
|
|
1353
|
+
case "w:hyperlink": {
|
|
1354
|
+
const rel = node.attrs["r:id"] ? this.rels.get(node.attrs["r:id"]) : void 0;
|
|
1355
|
+
const anchor = node.attrs["w:anchor"];
|
|
1356
|
+
const href = rel?.external ? rel.target : anchor ? `#${anchor}` : "";
|
|
1357
|
+
if (href) state.push(`<a href="${escape(href)}">`);
|
|
1358
|
+
state.links++;
|
|
1359
|
+
this.inline(node, state);
|
|
1360
|
+
state.links--;
|
|
1361
|
+
if (href) state.push("</a>");
|
|
1362
|
+
break;
|
|
1363
|
+
}
|
|
1364
|
+
case "w:ins":
|
|
1365
|
+
case "w:moveTo":
|
|
1366
|
+
if (this.revisions === "suggestions") this.revision(node, "ins", state);
|
|
1367
|
+
else this.inline(node, state);
|
|
1368
|
+
break;
|
|
1369
|
+
case "w:del":
|
|
1370
|
+
case "w:moveFrom":
|
|
1371
|
+
if (this.revisions === "suggestions") this.revision(node, "del", state);
|
|
1372
|
+
break;
|
|
1373
|
+
case "w:smartTag":
|
|
1374
|
+
case "w:customXml":
|
|
1375
|
+
case "w:fldSimple":
|
|
1376
|
+
case "w:dir":
|
|
1377
|
+
case "w:bdo":
|
|
1378
|
+
this.inline(node, state);
|
|
1379
|
+
break;
|
|
1380
|
+
case "w:sdt":
|
|
1381
|
+
this.inline(element(node, "w:sdtContent") ?? node, state);
|
|
1382
|
+
break;
|
|
1383
|
+
case "m:oMath":
|
|
1384
|
+
case "m:oMathPara":
|
|
1385
|
+
state.push(`<em>${escape(textContent(node))}</em>`);
|
|
1386
|
+
this.warnings.add("equations");
|
|
1387
|
+
break;
|
|
1388
|
+
default:
|
|
1389
|
+
break;
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
/**
|
|
1394
|
+
* A tracked change kept as a suggestion: <ins>/<del> with Word's author name and date (Word has no
|
|
1395
|
+
* user ids). Word cuts one change into several elements (a run each): an element right after one
|
|
1396
|
+
* of the same kind, author and date continues it under the same id.
|
|
1397
|
+
*/
|
|
1398
|
+
revision(node, tag, state) {
|
|
1399
|
+
if (this.wholeRevision === revisionKey(node, tag)) {
|
|
1400
|
+
const deleted2 = state.deleted;
|
|
1401
|
+
state.deleted = deleted2 || tag === "del";
|
|
1402
|
+
this.inline(node, state);
|
|
1403
|
+
state.deleted = deleted2;
|
|
1404
|
+
return;
|
|
1405
|
+
}
|
|
1406
|
+
const { key, id, attrs } = this.revisionAttrs(node, tag, state);
|
|
1407
|
+
state.push(`<${tag}${attrs}>`);
|
|
1408
|
+
const deleted = state.deleted;
|
|
1409
|
+
state.deleted = deleted || tag === "del";
|
|
1410
|
+
this.inline(node, state);
|
|
1411
|
+
state.deleted = deleted;
|
|
1412
|
+
state.push(`</${tag}>`);
|
|
1413
|
+
state.revision = { key, id, end: state.pushed };
|
|
1414
|
+
}
|
|
1415
|
+
/** The HTML attributes of a row or cell inserted or deleted as a whole. */
|
|
1416
|
+
wholeAttrs({ node, change }) {
|
|
1417
|
+
const author = (node.attrs["w:author"] ?? "").slice(0, 80);
|
|
1418
|
+
const time = Date.parse(node.attrs["w:date"] ?? "");
|
|
1419
|
+
const id = `w${(node.attrs["w:id"] ?? "").replace(/[^\w-]/g, "").slice(0, 60) || `r${++this.revisionCount}`}`;
|
|
1420
|
+
return ` data-suggestion="${escape(id)}" data-change="${change}"` + (author ? ` data-name="${escape(author)}"` : "") + (Number.isFinite(time) ? ` data-time="${time}"` : "");
|
|
1421
|
+
}
|
|
1422
|
+
/** A tracked change's suggestion id (continuing the one right before it) and HTML attributes. */
|
|
1423
|
+
revisionAttrs(node, kind, state) {
|
|
1424
|
+
const author = (node.attrs["w:author"] ?? "").slice(0, 80);
|
|
1425
|
+
const time = Date.parse(node.attrs["w:date"] ?? "");
|
|
1426
|
+
const key = revisionKey(node, kind);
|
|
1427
|
+
const last = state.revision;
|
|
1428
|
+
const id = last && last.key === key && last.end === state.pushed ? last.id : `w${(node.attrs["w:id"] ?? "").replace(/[^\w-]/g, "").slice(0, 60) || `r${++this.revisionCount}`}`;
|
|
1429
|
+
const attrs = ` data-suggestion="${escape(id)}"` + (author ? ` data-name="${escape(author)}"` : "") + (Number.isFinite(time) ? ` data-time="${time}"` : "");
|
|
1430
|
+
return { key, id, attrs };
|
|
1431
|
+
}
|
|
1432
|
+
run(run, state) {
|
|
1433
|
+
const rPr = element(run, "w:rPr");
|
|
1434
|
+
if (element(rPr, "w:rFonts")?.attrs["w:ascii"] === "Cambria Math" && state.field !== "code") {
|
|
1435
|
+
const latex = elements(run, "w:t").map(textContent).join("");
|
|
1436
|
+
if (latex)
|
|
1437
|
+
state.push(
|
|
1438
|
+
`<span data-type="inline-math" data-latex="${escape(latex)}">${escape(latex)}</span>`
|
|
1439
|
+
);
|
|
1440
|
+
return;
|
|
1441
|
+
}
|
|
1442
|
+
let { open, close } = this.runStyle(rPr, state.links > 0);
|
|
1443
|
+
const change = this.revisions === "suggestions" ? element(rPr, "w:rPrChange") : void 0;
|
|
1444
|
+
const format = change ? this.revisionAttrs(change, "format", state) : null;
|
|
1445
|
+
if (change && format) {
|
|
1446
|
+
const before = this.formatMarks(element(change, "w:rPr"), state.links > 0);
|
|
1447
|
+
open = `<span${format.attrs} data-format="${escape(before)}">${open}`;
|
|
1448
|
+
close = `${close}</span>`;
|
|
1449
|
+
}
|
|
1450
|
+
let text = "";
|
|
1451
|
+
const flush = () => {
|
|
1452
|
+
if (text && state.field !== "code") state.push(`${open}${text}${close}`);
|
|
1453
|
+
text = "";
|
|
1454
|
+
};
|
|
1455
|
+
for (const node of elements(run)) {
|
|
1456
|
+
switch (node.name) {
|
|
1457
|
+
case "w:t":
|
|
1458
|
+
text += escape(textContent(node));
|
|
1459
|
+
break;
|
|
1460
|
+
case "w:delText":
|
|
1461
|
+
if (state.deleted) text += escape(textContent(node));
|
|
1462
|
+
break;
|
|
1463
|
+
case "w:tab":
|
|
1464
|
+
case "w:ptab":
|
|
1465
|
+
text += " ";
|
|
1466
|
+
break;
|
|
1467
|
+
case "w:noBreakHyphen":
|
|
1468
|
+
text += "-";
|
|
1469
|
+
break;
|
|
1470
|
+
case "w:sym": {
|
|
1471
|
+
const code = parseInt(node.attrs["w:char"] ?? "", 16);
|
|
1472
|
+
if (Number.isFinite(code) && code < 57344) text += escape(String.fromCodePoint(code));
|
|
1473
|
+
break;
|
|
1474
|
+
}
|
|
1475
|
+
case "w:br":
|
|
1476
|
+
case "w:cr":
|
|
1477
|
+
flush();
|
|
1478
|
+
if (node.attrs["w:type"] === "page") state.pageBreak();
|
|
1479
|
+
else if (node.attrs["w:type"] !== "column" && state.field !== "code") state.push("<br>");
|
|
1480
|
+
break;
|
|
1481
|
+
case "w:drawing":
|
|
1482
|
+
flush();
|
|
1483
|
+
if (state.field !== "code") state.push(this.drawing(node));
|
|
1484
|
+
break;
|
|
1485
|
+
case "w:pict":
|
|
1486
|
+
case "w:object":
|
|
1487
|
+
flush();
|
|
1488
|
+
if (state.field !== "code") state.push(this.vml(node));
|
|
1489
|
+
break;
|
|
1490
|
+
case "w:fldChar": {
|
|
1491
|
+
flush();
|
|
1492
|
+
const type = node.attrs["w:fldCharType"];
|
|
1493
|
+
if (type === "begin") {
|
|
1494
|
+
state.fields.push({ code: "", link: false });
|
|
1495
|
+
state.field = "code";
|
|
1496
|
+
} else if (type === "separate") {
|
|
1497
|
+
const field = state.fields[state.fields.length - 1];
|
|
1498
|
+
state.field = "result";
|
|
1499
|
+
const link = field && /^\s*HYPERLINK\s+(?:\\l\s+)?"([^"]+)"/.exec(field.code);
|
|
1500
|
+
if (field && link) {
|
|
1501
|
+
const local = /\\l/.test(field.code.split('"')[0] ?? "");
|
|
1502
|
+
state.push(`<a href="${escape(local ? `#${link[1]}` : link[1])}">`);
|
|
1503
|
+
field.link = true;
|
|
1504
|
+
state.links++;
|
|
1505
|
+
}
|
|
1506
|
+
} else if (type === "end") {
|
|
1507
|
+
const field = state.fields.pop();
|
|
1508
|
+
if (field?.link) {
|
|
1509
|
+
state.push("</a>");
|
|
1510
|
+
state.links--;
|
|
1511
|
+
}
|
|
1512
|
+
state.field = state.fields.length ? "result" : null;
|
|
1513
|
+
}
|
|
1514
|
+
break;
|
|
1515
|
+
}
|
|
1516
|
+
case "w:instrText": {
|
|
1517
|
+
const field = state.fields[state.fields.length - 1];
|
|
1518
|
+
if (field) field.code += textContent(node);
|
|
1519
|
+
break;
|
|
1520
|
+
}
|
|
1521
|
+
case "w:footnoteReference": {
|
|
1522
|
+
flush();
|
|
1523
|
+
const note = this.footnotes.get(node.attrs["w:id"] ?? "");
|
|
1524
|
+
if (note) {
|
|
1525
|
+
const n = this.notes.length + 1;
|
|
1526
|
+
this.notes.push(`<p><sup>${n}</sup> ${this.noteText(note)}</p>`);
|
|
1527
|
+
state.push(`<sup>${n}</sup>`);
|
|
1528
|
+
}
|
|
1529
|
+
break;
|
|
1530
|
+
}
|
|
1531
|
+
default:
|
|
1532
|
+
break;
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
flush();
|
|
1536
|
+
if (format) state.revision = { key: format.key, id: format.id, end: state.pushed };
|
|
1537
|
+
}
|
|
1538
|
+
noteText(note) {
|
|
1539
|
+
return elements(note, "w:p").map((p) => {
|
|
1540
|
+
const state = new InlineState();
|
|
1541
|
+
this.inline(p, state);
|
|
1542
|
+
return state.parts().join(" ");
|
|
1543
|
+
}).join(" ").trim();
|
|
1544
|
+
}
|
|
1545
|
+
// ---------- blocks ----------
|
|
1546
|
+
paragraph(p, list, out) {
|
|
1547
|
+
const pPr = element(p, "w:pPr");
|
|
1548
|
+
const styleId = val(element(pPr, "w:pStyle"));
|
|
1549
|
+
const level = this.headingLevel(styleId, pPr);
|
|
1550
|
+
const kind = level ? null : this.styleKind(styleId);
|
|
1551
|
+
const state = new InlineState();
|
|
1552
|
+
this.inline(p, state);
|
|
1553
|
+
const parts = state.parts();
|
|
1554
|
+
const styles = this.styleChain(styleId);
|
|
1555
|
+
const jc = val(element(pPr, "w:jc")) ?? styles.find((s) => s.jc)?.jc;
|
|
1556
|
+
const css = [];
|
|
1557
|
+
if (jc === "center") css.push("text-align: center");
|
|
1558
|
+
else if (jc === "right" || jc === "end") css.push("text-align: right");
|
|
1559
|
+
else if (jc === "both" || jc === "distribute") css.push("text-align: justify");
|
|
1560
|
+
const ind = element(pPr, "w:ind");
|
|
1561
|
+
const left = Number(ind?.attrs["w:left"] ?? ind?.attrs["w:start"] ?? 0);
|
|
1562
|
+
const numPr = element(pPr, "w:numPr") ?? styles.find((s) => s.numPr)?.numPr;
|
|
1563
|
+
const numId = val(element(numPr, "w:numId"));
|
|
1564
|
+
if (left > 0 && !numId) css.push(`margin-left: ${Math.round(left / 15)}px`);
|
|
1565
|
+
const spacing = element(pPr, "w:spacing");
|
|
1566
|
+
const line = Number(spacing?.attrs["w:line"]);
|
|
1567
|
+
if (line && (spacing?.attrs["w:lineRule"] ?? "auto") === "auto" && line !== 240)
|
|
1568
|
+
css.push(`line-height: ${Math.round(line / 240 * 100) / 100}`);
|
|
1569
|
+
const rtl = on(element(pPr, "w:bidi"));
|
|
1570
|
+
const attrs = `${css.length ? ` style="${css.join("; ")}"` : ""}${rtl ? ' dir="rtl"' : ""}`;
|
|
1571
|
+
const mark = elements(p, "w:bookmarkStart").find((b) => b.attrs["w:name"] !== "_GoBack");
|
|
1572
|
+
const id = level && mark ? ` id="${escape(mark.attrs["w:name"] ?? "")}"` : "";
|
|
1573
|
+
if (on(element(pPr, "w:pageBreakBefore"))) {
|
|
1574
|
+
list.close(out);
|
|
1575
|
+
out.push(PAGE_BREAK);
|
|
1576
|
+
}
|
|
1577
|
+
if (parts.length === 1 && !parts[0] && !level && element(element(pPr, "w:pBdr"), "w:bottom")) {
|
|
1578
|
+
list.close(out);
|
|
1579
|
+
out.push("<hr>");
|
|
1580
|
+
return;
|
|
1581
|
+
}
|
|
1582
|
+
const check = !level && !numId ? /^([☐☒☑]) /.exec(parts[0] ?? "") : null;
|
|
1583
|
+
if (check && parts.length === 1) {
|
|
1584
|
+
list.item(out, "checklist", 0, false, "", 1, check[1] !== "\u2610");
|
|
1585
|
+
const plain = css.filter((rule) => !rule.startsWith("margin-left"));
|
|
1586
|
+
out.push(
|
|
1587
|
+
`<p${plain.length ? ` style="${plain.join("; ")}"` : ""}${rtl ? ' dir="rtl"' : ""}>${parts[0].slice(2)}</p>`
|
|
1588
|
+
);
|
|
1589
|
+
return;
|
|
1590
|
+
}
|
|
1591
|
+
parts.forEach((html, index) => {
|
|
1592
|
+
if (index > 0) {
|
|
1593
|
+
list.close(out);
|
|
1594
|
+
out.push(PAGE_BREAK);
|
|
1595
|
+
}
|
|
1596
|
+
if (!html && parts.length > 1) return;
|
|
1597
|
+
if (numId && numId !== "0" && index === 0) {
|
|
1598
|
+
const ilvl = Number(val(element(numPr, "w:ilvl")) ?? 0);
|
|
1599
|
+
const lvl = this.levels.get(numId)?.[ilvl];
|
|
1600
|
+
if (lvl && lvl.format !== "none") {
|
|
1601
|
+
const ordered = lvl.format !== "bullet";
|
|
1602
|
+
const start = this.starts.get(`${numId}:${ilvl}`) ?? lvl.start;
|
|
1603
|
+
list.item(
|
|
1604
|
+
out,
|
|
1605
|
+
numId,
|
|
1606
|
+
ilvl,
|
|
1607
|
+
ordered,
|
|
1608
|
+
ordered ? LIST_STYLE[lvl.format] ?? "" : "",
|
|
1609
|
+
start
|
|
1610
|
+
);
|
|
1611
|
+
out.push(`<p${attrs}>${html}</p>`);
|
|
1612
|
+
return;
|
|
1613
|
+
}
|
|
1614
|
+
}
|
|
1615
|
+
list.close(out);
|
|
1616
|
+
if (level) out.push(`<h${level}${id}${attrs}>${html}</h${level}>`);
|
|
1617
|
+
else if (kind === "quote") out.push(`<blockquote><p${attrs}>${html}</p></blockquote>`);
|
|
1618
|
+
else if (kind === "code") out.push(`<pre><code>${html.replace(/<br>/g, "\n")}</code></pre>`);
|
|
1619
|
+
else out.push(`<p${attrs}>${html}</p>`);
|
|
1620
|
+
});
|
|
1621
|
+
}
|
|
1622
|
+
table(tbl, out) {
|
|
1623
|
+
const grid = elements(element(tbl, "w:tblGrid"), "w:gridCol").map(
|
|
1624
|
+
(col) => Math.round(Number(col.attrs["w:w"] ?? 0) / 15)
|
|
1625
|
+
);
|
|
1626
|
+
const rows = elements(tbl, "w:tr").map((tr) => {
|
|
1627
|
+
let col = Number(val(element(element(tr, "w:trPr"), "w:gridBefore")) ?? 0);
|
|
1628
|
+
const cells = [];
|
|
1629
|
+
for (const tc of elements(tr, "w:tc")) {
|
|
1630
|
+
const tcPr = element(tc, "w:tcPr");
|
|
1631
|
+
const span = Math.max(1, Number(val(element(tcPr, "w:gridSpan")) ?? 1));
|
|
1632
|
+
const vMerge = element(tcPr, "w:vMerge");
|
|
1633
|
+
const merge = vMerge ? val(vMerge) === "restart" ? "restart" : "continue" : null;
|
|
1634
|
+
cells.push({ tc, col, span, merge, rowspan: 1 });
|
|
1635
|
+
col += span;
|
|
1636
|
+
}
|
|
1637
|
+
return { tr, cells };
|
|
1638
|
+
});
|
|
1639
|
+
rows.forEach((row, r) => {
|
|
1640
|
+
for (const cell of row.cells) {
|
|
1641
|
+
if (cell.merge !== "restart") continue;
|
|
1642
|
+
for (let below = r + 1; below < rows.length; below++) {
|
|
1643
|
+
const next = rows[below].cells.find((c) => c.col === cell.col);
|
|
1644
|
+
if (next?.merge !== "continue") break;
|
|
1645
|
+
cell.rowspan++;
|
|
1646
|
+
}
|
|
1647
|
+
}
|
|
1648
|
+
});
|
|
1649
|
+
out.push("<table><tbody>");
|
|
1650
|
+
const suggestions = this.revisions === "suggestions";
|
|
1651
|
+
for (const { tr, cells } of rows) {
|
|
1652
|
+
const trPr = element(tr, "w:trPr");
|
|
1653
|
+
const header = on(element(trPr, "w:tblHeader"));
|
|
1654
|
+
const rowChange = wholeChange(trPr, "w:ins", "w:del");
|
|
1655
|
+
if (rowChange?.change === "delete" && !suggestions) continue;
|
|
1656
|
+
const rowKey = suggestions && rowChange ? revisionKey(rowChange.node, rowChange.kind) : null;
|
|
1657
|
+
out.push(suggestions && rowChange ? `<tr${this.wholeAttrs(rowChange)}>` : "<tr>");
|
|
1658
|
+
for (const cell of cells) {
|
|
1659
|
+
if (cell.merge === "continue") continue;
|
|
1660
|
+
const tcPr = element(cell.tc, "w:tcPr");
|
|
1661
|
+
const cellChange = wholeChange(tcPr, "w:cellIns", "w:cellDel");
|
|
1662
|
+
if (cellChange?.change === "delete" && !suggestions) continue;
|
|
1663
|
+
const cellAttrs = suggestions && cellChange ? this.wholeAttrs(cellChange) : "";
|
|
1664
|
+
this.wholeRevision = suggestions && cellChange ? revisionKey(cellChange.node, cellChange.kind) : rowKey;
|
|
1665
|
+
const tag = header ? "th" : "td";
|
|
1666
|
+
const css = [];
|
|
1667
|
+
const fill = element(tcPr, "w:shd")?.attrs["w:fill"];
|
|
1668
|
+
if (fill && /^[0-9a-f]{6}$/i.test(fill))
|
|
1669
|
+
css.push(`background-color: #${fill.toLowerCase()}`);
|
|
1670
|
+
const valign = val(element(tcPr, "w:vAlign"));
|
|
1671
|
+
if (valign === "center") css.push("vertical-align: middle");
|
|
1672
|
+
else if (valign === "bottom") css.push("vertical-align: bottom");
|
|
1673
|
+
const widths = grid.slice(cell.col, cell.col + cell.span);
|
|
1674
|
+
const colwidth = widths.length === cell.span && widths.every((w) => w > 0) ? ` data-colwidth="${widths.join(",")}"` : "";
|
|
1675
|
+
out.push(
|
|
1676
|
+
`<${tag}${cell.span > 1 ? ` colspan="${cell.span}"` : ""}${cell.rowspan > 1 ? ` rowspan="${cell.rowspan}"` : ""}${colwidth}${css.length ? ` style="${css.join("; ")}"` : ""}${cellAttrs}>`
|
|
1677
|
+
);
|
|
1678
|
+
this.inHeader = header;
|
|
1679
|
+
this.blocks(cell.tc, out);
|
|
1680
|
+
this.inHeader = false;
|
|
1681
|
+
this.wholeRevision = null;
|
|
1682
|
+
out.push(`</${tag}>`);
|
|
1683
|
+
}
|
|
1684
|
+
out.push("</tr>");
|
|
1685
|
+
}
|
|
1686
|
+
out.push("</tbody></table>");
|
|
1687
|
+
}
|
|
1688
|
+
blocks(parent, out) {
|
|
1689
|
+
const list = new ListState();
|
|
1690
|
+
const before = out.length;
|
|
1691
|
+
for (const node of elements(parent)) {
|
|
1692
|
+
if (node.name === "w:p") this.paragraph(node, list, out);
|
|
1693
|
+
else if (node.name === "w:tbl") {
|
|
1694
|
+
list.close(out);
|
|
1695
|
+
this.table(node, out);
|
|
1696
|
+
} else if (node.name === "w:sdt") {
|
|
1697
|
+
list.close(out);
|
|
1698
|
+
this.blocks(element(node, "w:sdtContent") ?? node, out);
|
|
1699
|
+
} else if (node.name === "w:altChunk") this.warnings.add("embedded content (altChunk)");
|
|
1700
|
+
}
|
|
1701
|
+
list.close(out);
|
|
1702
|
+
if (parent.name === "w:body" && this.notes.length) out.push("<hr>", ...this.notes.splice(0));
|
|
1703
|
+
if (out.length === before && parent.name === "w:tc") out.push("<p></p>");
|
|
1704
|
+
}
|
|
1705
|
+
page(body) {
|
|
1706
|
+
const sect = element(body, "w:sectPr");
|
|
1707
|
+
const size = element(sect, "w:pgSz");
|
|
1708
|
+
const margin = element(sect, "w:pgMar");
|
|
1709
|
+
if (!size) return void 0;
|
|
1710
|
+
const mm = (tw) => Math.round(Number(tw) / 1440 * 25.4 * 10) / 10;
|
|
1711
|
+
let width = mm(size.attrs["w:w"]);
|
|
1712
|
+
let height = mm(size.attrs["w:h"]);
|
|
1713
|
+
if (!(width > 0 && height > 0)) return void 0;
|
|
1714
|
+
if (size.attrs["w:orient"] === "landscape" && width < height) [width, height] = [height, width];
|
|
1715
|
+
const margins = {};
|
|
1716
|
+
for (const side of ["top", "right", "bottom", "left"]) {
|
|
1717
|
+
const value = margin?.attrs[`w:${side}`];
|
|
1718
|
+
if (value !== void 0) margins[side] = Math.abs(mm(value));
|
|
1719
|
+
}
|
|
1720
|
+
const [short, long] = width < height ? [width, height] : [height, width];
|
|
1721
|
+
const named = Object.keys(PAGE_SIZES).find(
|
|
1722
|
+
(name) => Math.abs(PAGE_SIZES[name][0] - short) < 1.5 && Math.abs(PAGE_SIZES[name][1] - long) < 1.5
|
|
1723
|
+
);
|
|
1724
|
+
return {
|
|
1725
|
+
size: named ?? { width, height },
|
|
1726
|
+
orientation: width > height ? "landscape" : "portrait",
|
|
1727
|
+
margins
|
|
1728
|
+
};
|
|
1729
|
+
}
|
|
1730
|
+
};
|
|
1731
|
+
var PAGE_BREAK = '<div class="nova-pagebreak" style="break-after: page;"></div>';
|
|
1732
|
+
var MONOSPACE = /^(consolas|courier( new)?|menlo|monaco|lucida console|source code pro|fira (code|mono)|jetbrains mono|cascadia (code|mono)|monospace)$/i;
|
|
1733
|
+
var CODE_SHADES = /* @__PURE__ */ new Set(["#f3f4f6", "#f6f8fa"]);
|
|
1734
|
+
var InlineState = class {
|
|
1735
|
+
current = [];
|
|
1736
|
+
done = [];
|
|
1737
|
+
/** Inside a field: code is the field code (not text), result is its result. */
|
|
1738
|
+
field = null;
|
|
1739
|
+
fields = [];
|
|
1740
|
+
/** Link depth (w:hyperlink, the HYPERLINK field). */
|
|
1741
|
+
links = 0;
|
|
1742
|
+
/** Inside a deletion kept as a suggestion: w:delText is text. */
|
|
1743
|
+
deleted = false;
|
|
1744
|
+
/** How many pieces were pushed: a change continues the last one if nothing came between. */
|
|
1745
|
+
pushed = 0;
|
|
1746
|
+
/** The last tracked change: its kind, author and date, its id, and where it ended. */
|
|
1747
|
+
revision = null;
|
|
1748
|
+
push(html) {
|
|
1749
|
+
this.current.push(html);
|
|
1750
|
+
this.pushed++;
|
|
1751
|
+
}
|
|
1752
|
+
pageBreak() {
|
|
1753
|
+
this.done.push(this.current.join(""));
|
|
1754
|
+
this.current = [];
|
|
1755
|
+
}
|
|
1756
|
+
parts() {
|
|
1757
|
+
return [...this.done, this.current.join("")];
|
|
1758
|
+
}
|
|
1759
|
+
};
|
|
1760
|
+
var ListState = class {
|
|
1761
|
+
stack = [];
|
|
1762
|
+
item(out, numId, level, ordered, style, start, checked) {
|
|
1763
|
+
const tag = ordered ? "ol" : "ul";
|
|
1764
|
+
const li = checked === void 0 ? "<li>" : `<li data-checked="${checked}">`;
|
|
1765
|
+
while (this.stack.length && this.stack[this.stack.length - 1].level > level) {
|
|
1766
|
+
out.push(`</li></${this.stack.pop().tag}>`);
|
|
1767
|
+
}
|
|
1768
|
+
const top = this.stack[this.stack.length - 1];
|
|
1769
|
+
if (top && top.level === level) {
|
|
1770
|
+
if (top.numId === numId && top.tag === tag) {
|
|
1771
|
+
out.push(`</li>${li}`);
|
|
1772
|
+
return;
|
|
1773
|
+
}
|
|
1774
|
+
out.push(`</li></${this.stack.pop().tag}>`);
|
|
1775
|
+
}
|
|
1776
|
+
const attrs = (ordered && start !== 1 ? ` start="${start}"` : "") + (style ? ` style="list-style-type: ${style}"` : "") + (checked === void 0 ? "" : ' data-type="checklist"');
|
|
1777
|
+
out.push(`<${tag}${attrs}>${li}`);
|
|
1778
|
+
this.stack.push({ numId, level, tag });
|
|
1779
|
+
}
|
|
1780
|
+
close(out) {
|
|
1781
|
+
while (this.stack.length) out.push(`</li></${this.stack.pop().tag}>`);
|
|
1782
|
+
}
|
|
1783
|
+
};
|
|
1784
|
+
async function fromDocx(input, options = {}) {
|
|
1785
|
+
const bytes = input instanceof Uint8Array ? input : new Uint8Array(input);
|
|
1786
|
+
const files = await unzip(bytes);
|
|
1787
|
+
const reader = new DocxReader(files, options.revisions);
|
|
1788
|
+
const body = reader.load();
|
|
1789
|
+
if (!body) throw new Error("Not a Word document (.docx)");
|
|
1790
|
+
const out = [];
|
|
1791
|
+
reader.blocks(body, out);
|
|
1792
|
+
return { html: out.join(""), page: reader.page(body), warnings: [...reader.warnings] };
|
|
1793
|
+
}
|
|
1794
|
+
|
|
1795
|
+
// src/docx/index.ts
|
|
1796
|
+
function isEditor(source) {
|
|
1797
|
+
return !!source && typeof source === "object" && "view" in source && "getHTML" in source;
|
|
1798
|
+
}
|
|
1799
|
+
function exportDocx(source, options = {}) {
|
|
1800
|
+
if (isEditor(source))
|
|
1801
|
+
return toDocx(source.view.state.doc, { page: pageLayout(source)?.layout, ...options });
|
|
1802
|
+
if (source instanceof PMNode) return toDocx(source, options);
|
|
1803
|
+
return toDocx(createRenderer(options).doc(source), options);
|
|
1804
|
+
}
|
|
1805
|
+
async function importDocx(editor, file, options = {}) {
|
|
1806
|
+
const bytes = file instanceof Uint8Array ? file : new Uint8Array(file instanceof ArrayBuffer ? file : await file.arrayBuffer());
|
|
1807
|
+
const result = await fromDocx(bytes, {
|
|
1808
|
+
revisions: options.revisions ?? (editor.hasPlugin("suggestions") ? "suggestions" : "accept")
|
|
1809
|
+
});
|
|
1810
|
+
if (options.mode === "insert") editor.insertContent(result.html);
|
|
1811
|
+
else editor.setContent(result.html);
|
|
1812
|
+
if (result.page) pageLayout(editor)?.set(result.page);
|
|
1813
|
+
return result;
|
|
1814
|
+
}
|
|
1815
|
+
export {
|
|
1816
|
+
exportDocx,
|
|
1817
|
+
fromDocx,
|
|
1818
|
+
importDocx,
|
|
1819
|
+
toDocx
|
|
1820
|
+
};
|
|
1821
|
+
//# sourceMappingURL=docx.js.map
|