@fiduswriter/document 0.1.0-alpha.2 → 0.1.0-alpha.4

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.
Files changed (410) hide show
  1. package/README.md +22 -1
  2. package/dist/bibliography/common.d.ts +92 -0
  3. package/dist/bibliography/common.d.ts.map +1 -0
  4. package/dist/bibliography/common.js +85 -0
  5. package/dist/bibliography/common.js.map +1 -0
  6. package/dist/bibliography/csl_bib.d.ts +3 -0
  7. package/dist/bibliography/csl_bib.d.ts.map +1 -0
  8. package/dist/bibliography/csl_bib.js +131 -0
  9. package/dist/bibliography/csl_bib.js.map +1 -0
  10. package/dist/citations/citeproc_sys.d.ts +13 -0
  11. package/dist/citations/citeproc_sys.d.ts.map +1 -0
  12. package/dist/citations/citeproc_sys.js +43 -0
  13. package/dist/citations/citeproc_sys.js.map +1 -0
  14. package/dist/citations/format.d.ts +23 -0
  15. package/dist/citations/format.d.ts.map +1 -0
  16. package/dist/citations/format.js +161 -0
  17. package/dist/citations/format.js.map +1 -0
  18. package/dist/editor/e2ee/encryptor.d.ts +123 -0
  19. package/dist/editor/e2ee/encryptor.d.ts.map +1 -0
  20. package/dist/editor/e2ee/encryptor.js +201 -0
  21. package/dist/editor/e2ee/encryptor.js.map +1 -0
  22. package/dist/exporter/docx/citations.d.ts +21 -0
  23. package/dist/exporter/docx/citations.d.ts.map +1 -0
  24. package/dist/exporter/docx/citations.js +154 -0
  25. package/dist/exporter/docx/citations.js.map +1 -0
  26. package/dist/exporter/docx/comments.d.ts +18 -0
  27. package/dist/exporter/docx/comments.d.ts.map +1 -0
  28. package/dist/exporter/docx/comments.js +137 -0
  29. package/dist/exporter/docx/comments.js.map +1 -0
  30. package/dist/exporter/docx/footnotes.d.ts +42 -0
  31. package/dist/exporter/docx/footnotes.d.ts.map +1 -0
  32. package/dist/exporter/docx/footnotes.js +182 -0
  33. package/dist/exporter/docx/footnotes.js.map +1 -0
  34. package/dist/exporter/docx/images.d.ts +14 -0
  35. package/dist/exporter/docx/images.d.ts.map +1 -0
  36. package/dist/exporter/docx/images.js +86 -0
  37. package/dist/exporter/docx/images.js.map +1 -0
  38. package/dist/exporter/docx/index.d.ts +22 -0
  39. package/dist/exporter/docx/index.d.ts.map +1 -0
  40. package/dist/exporter/docx/index.js +107 -0
  41. package/dist/exporter/docx/index.js.map +1 -0
  42. package/dist/exporter/docx/lists.d.ts +33 -0
  43. package/dist/exporter/docx/lists.d.ts.map +1 -0
  44. package/dist/exporter/docx/lists.js +229 -0
  45. package/dist/exporter/docx/lists.js.map +1 -0
  46. package/dist/exporter/docx/math.d.ts +13 -0
  47. package/dist/exporter/docx/math.d.ts.map +1 -0
  48. package/dist/exporter/docx/math.js +42 -0
  49. package/dist/exporter/docx/math.js.map +1 -0
  50. package/dist/exporter/docx/metadata.d.ts +14 -0
  51. package/dist/exporter/docx/metadata.d.ts.map +1 -0
  52. package/dist/exporter/docx/metadata.js +239 -0
  53. package/dist/exporter/docx/metadata.js.map +1 -0
  54. package/dist/exporter/docx/rels.d.ts +25 -0
  55. package/dist/exporter/docx/rels.d.ts.map +1 -0
  56. package/dist/exporter/docx/rels.js +168 -0
  57. package/dist/exporter/docx/rels.js.map +1 -0
  58. package/dist/exporter/docx/render.d.ts +20 -0
  59. package/dist/exporter/docx/render.d.ts.map +1 -0
  60. package/dist/exporter/docx/render.js +774 -0
  61. package/dist/exporter/docx/render.js.map +1 -0
  62. package/dist/exporter/docx/richtext.d.ts +25 -0
  63. package/dist/exporter/docx/richtext.d.ts.map +1 -0
  64. package/dist/exporter/docx/richtext.js +1052 -0
  65. package/dist/exporter/docx/richtext.js.map +1 -0
  66. package/dist/exporter/docx/tables.d.ts +14 -0
  67. package/dist/exporter/docx/tables.d.ts.map +1 -0
  68. package/dist/exporter/docx/tables.js +109 -0
  69. package/dist/exporter/docx/tables.js.map +1 -0
  70. package/dist/exporter/docx/tools.d.ts +3 -0
  71. package/dist/exporter/docx/tools.d.ts.map +1 -0
  72. package/dist/exporter/docx/tools.js +48 -0
  73. package/dist/exporter/docx/tools.js.map +1 -0
  74. package/dist/exporter/epub/index.d.ts +11 -0
  75. package/dist/exporter/epub/index.d.ts.map +1 -0
  76. package/dist/exporter/epub/index.js +102 -0
  77. package/dist/exporter/epub/index.js.map +1 -0
  78. package/dist/exporter/epub/templates.d.ts +32 -0
  79. package/dist/exporter/epub/templates.d.ts.map +1 -0
  80. package/dist/exporter/epub/templates.js +95 -0
  81. package/dist/exporter/epub/templates.js.map +1 -0
  82. package/dist/exporter/epub/tools.d.ts +5 -0
  83. package/dist/exporter/epub/tools.d.ts.map +1 -0
  84. package/dist/exporter/epub/tools.js +81 -0
  85. package/dist/exporter/epub/tools.js.map +1 -0
  86. package/dist/exporter/html/citations.d.ts +27 -0
  87. package/dist/exporter/html/citations.d.ts.map +1 -0
  88. package/dist/exporter/html/citations.js +91 -0
  89. package/dist/exporter/html/citations.js.map +1 -0
  90. package/dist/exporter/html/convert.d.ts +100 -0
  91. package/dist/exporter/html/convert.d.ts.map +1 -0
  92. package/dist/exporter/html/convert.js +718 -0
  93. package/dist/exporter/html/convert.js.map +1 -0
  94. package/dist/exporter/html/index.d.ts +61 -0
  95. package/dist/exporter/html/index.d.ts.map +1 -0
  96. package/dist/exporter/html/index.js +134 -0
  97. package/dist/exporter/html/index.js.map +1 -0
  98. package/dist/exporter/html/templates.d.ts +10 -0
  99. package/dist/exporter/html/templates.d.ts.map +1 -0
  100. package/dist/exporter/html/templates.js +21 -0
  101. package/dist/exporter/html/templates.js.map +1 -0
  102. package/dist/exporter/html/tools.d.ts +2 -0
  103. package/dist/exporter/html/tools.d.ts.map +1 -0
  104. package/dist/exporter/html/tools.js +49 -0
  105. package/dist/exporter/html/tools.js.map +1 -0
  106. package/dist/exporter/jats/bibliography.d.ts +2 -0
  107. package/dist/exporter/jats/bibliography.d.ts.map +1 -0
  108. package/dist/exporter/jats/bibliography.js +153 -0
  109. package/dist/exporter/jats/bibliography.js.map +1 -0
  110. package/dist/exporter/jats/citations.d.ts +14 -0
  111. package/dist/exporter/jats/citations.d.ts.map +1 -0
  112. package/dist/exporter/jats/citations.js +83 -0
  113. package/dist/exporter/jats/citations.js.map +1 -0
  114. package/dist/exporter/jats/convert.d.ts +45 -0
  115. package/dist/exporter/jats/convert.d.ts.map +1 -0
  116. package/dist/exporter/jats/convert.js +799 -0
  117. package/dist/exporter/jats/convert.js.map +1 -0
  118. package/dist/exporter/jats/index.d.ts +19 -0
  119. package/dist/exporter/jats/index.d.ts.map +1 -0
  120. package/dist/exporter/jats/index.js +66 -0
  121. package/dist/exporter/jats/index.js.map +1 -0
  122. package/dist/exporter/jats/templates.d.ts +16 -0
  123. package/dist/exporter/jats/templates.d.ts.map +1 -0
  124. package/dist/exporter/jats/templates.js +25 -0
  125. package/dist/exporter/jats/templates.js.map +1 -0
  126. package/dist/exporter/jats/text.d.ts +3 -0
  127. package/dist/exporter/jats/text.d.ts.map +1 -0
  128. package/dist/exporter/jats/text.js +72 -0
  129. package/dist/exporter/jats/text.js.map +1 -0
  130. package/dist/exporter/latex/convert.d.ts +27 -0
  131. package/dist/exporter/latex/convert.d.ts.map +1 -0
  132. package/dist/exporter/latex/convert.js +865 -0
  133. package/dist/exporter/latex/convert.js.map +1 -0
  134. package/dist/exporter/latex/escape_latex.d.ts +2 -0
  135. package/dist/exporter/latex/escape_latex.d.ts.map +1 -0
  136. package/dist/exporter/latex/escape_latex.js +20 -0
  137. package/dist/exporter/latex/escape_latex.js.map +1 -0
  138. package/dist/exporter/latex/index.d.ts +23 -0
  139. package/dist/exporter/latex/index.d.ts.map +1 -0
  140. package/dist/exporter/latex/index.js +57 -0
  141. package/dist/exporter/latex/index.js.map +1 -0
  142. package/dist/exporter/latex/readme.d.ts +2 -0
  143. package/dist/exporter/latex/readme.d.ts.map +1 -0
  144. package/dist/exporter/latex/readme.js +23 -0
  145. package/dist/exporter/latex/readme.js.map +1 -0
  146. package/dist/exporter/native/shrink.d.ts +21 -0
  147. package/dist/exporter/native/shrink.d.ts.map +1 -0
  148. package/dist/exporter/native/shrink.js +115 -0
  149. package/dist/exporter/native/shrink.js.map +1 -0
  150. package/dist/exporter/odt/citations.d.ts +18 -0
  151. package/dist/exporter/odt/citations.d.ts.map +1 -0
  152. package/dist/exporter/odt/citations.js +87 -0
  153. package/dist/exporter/odt/citations.js.map +1 -0
  154. package/dist/exporter/odt/footnotes.d.ts +25 -0
  155. package/dist/exporter/odt/footnotes.d.ts.map +1 -0
  156. package/dist/exporter/odt/footnotes.js +112 -0
  157. package/dist/exporter/odt/footnotes.js.map +1 -0
  158. package/dist/exporter/odt/images.d.ts +13 -0
  159. package/dist/exporter/odt/images.d.ts.map +1 -0
  160. package/dist/exporter/odt/images.js +98 -0
  161. package/dist/exporter/odt/images.js.map +1 -0
  162. package/dist/exporter/odt/index.d.ts +23 -0
  163. package/dist/exporter/odt/index.d.ts.map +1 -0
  164. package/dist/exporter/odt/index.js +99 -0
  165. package/dist/exporter/odt/index.js.map +1 -0
  166. package/dist/exporter/odt/math.d.ts +13 -0
  167. package/dist/exporter/odt/math.d.ts.map +1 -0
  168. package/dist/exporter/odt/math.js +48 -0
  169. package/dist/exporter/odt/math.js.map +1 -0
  170. package/dist/exporter/odt/metadata.d.ts +14 -0
  171. package/dist/exporter/odt/metadata.d.ts.map +1 -0
  172. package/dist/exporter/odt/metadata.js +203 -0
  173. package/dist/exporter/odt/metadata.js.map +1 -0
  174. package/dist/exporter/odt/render.d.ts +24 -0
  175. package/dist/exporter/odt/render.d.ts.map +1 -0
  176. package/dist/exporter/odt/render.js +644 -0
  177. package/dist/exporter/odt/render.js.map +1 -0
  178. package/dist/exporter/odt/richtext.d.ts +22 -0
  179. package/dist/exporter/odt/richtext.d.ts.map +1 -0
  180. package/dist/exporter/odt/richtext.js +728 -0
  181. package/dist/exporter/odt/richtext.js.map +1 -0
  182. package/dist/exporter/odt/styles.d.ts +33 -0
  183. package/dist/exporter/odt/styles.d.ts.map +1 -0
  184. package/dist/exporter/odt/styles.js +348 -0
  185. package/dist/exporter/odt/styles.js.map +1 -0
  186. package/dist/exporter/odt/track.d.ts +11 -0
  187. package/dist/exporter/odt/track.d.ts.map +1 -0
  188. package/dist/exporter/odt/track.js +59 -0
  189. package/dist/exporter/odt/track.js.map +1 -0
  190. package/dist/exporter/pandoc/citations.d.ts +17 -0
  191. package/dist/exporter/pandoc/citations.d.ts.map +1 -0
  192. package/dist/exporter/pandoc/citations.js +85 -0
  193. package/dist/exporter/pandoc/citations.js.map +1 -0
  194. package/dist/exporter/pandoc/convert.d.ts +38 -0
  195. package/dist/exporter/pandoc/convert.d.ts.map +1 -0
  196. package/dist/exporter/pandoc/convert.js +881 -0
  197. package/dist/exporter/pandoc/convert.js.map +1 -0
  198. package/dist/exporter/pandoc/index.d.ts +38 -0
  199. package/dist/exporter/pandoc/index.d.ts.map +1 -0
  200. package/dist/exporter/pandoc/index.js +67 -0
  201. package/dist/exporter/pandoc/index.js.map +1 -0
  202. package/dist/exporter/pandoc/readme.d.ts +2 -0
  203. package/dist/exporter/pandoc/readme.d.ts.map +1 -0
  204. package/dist/exporter/pandoc/readme.js +9 -0
  205. package/dist/exporter/pandoc/readme.js.map +1 -0
  206. package/dist/exporter/pandoc/tools.d.ts +6 -0
  207. package/dist/exporter/pandoc/tools.d.ts.map +1 -0
  208. package/dist/exporter/pandoc/tools.js +52 -0
  209. package/dist/exporter/pandoc/tools.js.map +1 -0
  210. package/dist/exporter/print/index.d.ts +9 -0
  211. package/dist/exporter/print/index.d.ts.map +1 -0
  212. package/dist/exporter/print/index.js +140 -0
  213. package/dist/exporter/print/index.js.map +1 -0
  214. package/dist/exporter/tools/doc_content.d.ts +7 -0
  215. package/dist/exporter/tools/doc_content.d.ts.map +1 -0
  216. package/dist/exporter/tools/doc_content.js +129 -0
  217. package/dist/exporter/tools/doc_content.js.map +1 -0
  218. package/dist/exporter/tools/file.d.ts +2 -0
  219. package/dist/exporter/tools/file.d.ts.map +1 -0
  220. package/dist/exporter/tools/file.js +10 -0
  221. package/dist/exporter/tools/file.js.map +1 -0
  222. package/dist/exporter/tools/json.d.ts +7 -0
  223. package/dist/exporter/tools/json.d.ts.map +1 -0
  224. package/dist/exporter/tools/json.js +82 -0
  225. package/dist/exporter/tools/json.js.map +1 -0
  226. package/dist/exporter/tools/svg.d.ts +2 -0
  227. package/dist/exporter/tools/svg.d.ts.map +1 -0
  228. package/dist/exporter/tools/svg.js +26 -0
  229. package/dist/exporter/tools/svg.js.map +1 -0
  230. package/dist/exporter/tools/xml.d.ts +41 -0
  231. package/dist/exporter/tools/xml.d.ts.map +1 -0
  232. package/dist/exporter/tools/xml.js +440 -0
  233. package/dist/exporter/tools/xml.js.map +1 -0
  234. package/dist/exporter/tools/xml_zip.d.ts +20 -0
  235. package/dist/exporter/tools/xml_zip.d.ts.map +1 -0
  236. package/dist/exporter/tools/xml_zip.js +86 -0
  237. package/dist/exporter/tools/xml_zip.js.map +1 -0
  238. package/dist/exporter/tools/zip.d.ts +21 -0
  239. package/dist/exporter/tools/zip.d.ts.map +1 -0
  240. package/dist/exporter/tools/zip.js +71 -0
  241. package/dist/exporter/tools/zip.js.map +1 -0
  242. package/dist/exporter/tools/zotero_csl.d.ts +10 -0
  243. package/dist/exporter/tools/zotero_csl.d.ts.map +1 -0
  244. package/dist/exporter/tools/zotero_csl.js +78 -0
  245. package/dist/exporter/tools/zotero_csl.js.map +1 -0
  246. package/dist/importer/citations.d.ts +25 -0
  247. package/dist/importer/citations.d.ts.map +1 -0
  248. package/dist/importer/citations.js +116 -0
  249. package/dist/importer/citations.js.map +1 -0
  250. package/dist/importer/docx/citations.d.ts +65 -0
  251. package/dist/importer/docx/citations.d.ts.map +1 -0
  252. package/dist/importer/docx/citations.js +106 -0
  253. package/dist/importer/docx/citations.js.map +1 -0
  254. package/dist/importer/docx/convert.d.ts +228 -0
  255. package/dist/importer/docx/convert.d.ts.map +1 -0
  256. package/dist/importer/docx/convert.js +1226 -0
  257. package/dist/importer/docx/convert.js.map +1 -0
  258. package/dist/importer/docx/helpers.d.ts +2 -0
  259. package/dist/importer/docx/helpers.d.ts.map +1 -0
  260. package/dist/importer/docx/helpers.js +10 -0
  261. package/dist/importer/docx/helpers.js.map +1 -0
  262. package/dist/importer/docx/omml2mathml.d.ts +7 -0
  263. package/dist/importer/docx/omml2mathml.d.ts.map +1 -0
  264. package/dist/importer/docx/omml2mathml.js +1239 -0
  265. package/dist/importer/docx/omml2mathml.js.map +1 -0
  266. package/dist/importer/docx/parse.d.ts +205 -0
  267. package/dist/importer/docx/parse.d.ts.map +1 -0
  268. package/dist/importer/docx/parse.js +663 -0
  269. package/dist/importer/docx/parse.js.map +1 -0
  270. package/dist/importer/native/get_images.d.ts +11 -0
  271. package/dist/importer/native/get_images.d.ts.map +1 -0
  272. package/dist/importer/native/get_images.js +64 -0
  273. package/dist/importer/native/get_images.js.map +1 -0
  274. package/dist/importer/native/update.d.ts +6 -0
  275. package/dist/importer/native/update.d.ts.map +1 -0
  276. package/dist/importer/native/update.js +26 -0
  277. package/dist/importer/native/update.js.map +1 -0
  278. package/dist/importer/odt/citations.d.ts +47 -0
  279. package/dist/importer/odt/citations.d.ts.map +1 -0
  280. package/dist/importer/odt/citations.js +79 -0
  281. package/dist/importer/odt/citations.js.map +1 -0
  282. package/dist/importer/odt/convert.d.ts +330 -0
  283. package/dist/importer/odt/convert.d.ts.map +1 -0
  284. package/dist/importer/odt/convert.js +1506 -0
  285. package/dist/importer/odt/convert.js.map +1 -0
  286. package/dist/importer/pandoc/convert.d.ts +84 -0
  287. package/dist/importer/pandoc/convert.d.ts.map +1 -0
  288. package/dist/importer/pandoc/convert.js +777 -0
  289. package/dist/importer/pandoc/convert.js.map +1 -0
  290. package/dist/importer/pandoc/helpers.d.ts +4 -0
  291. package/dist/importer/pandoc/helpers.d.ts.map +1 -0
  292. package/dist/importer/pandoc/helpers.js +75 -0
  293. package/dist/importer/pandoc/helpers.js.map +1 -0
  294. package/dist/importer/zip_analyzer.d.ts +25 -0
  295. package/dist/importer/zip_analyzer.d.ts.map +1 -0
  296. package/dist/importer/zip_analyzer.js +84 -0
  297. package/dist/importer/zip_analyzer.js.map +1 -0
  298. package/dist/index.d.ts +2 -0
  299. package/dist/index.d.ts.map +1 -0
  300. package/dist/index.js +2 -0
  301. package/dist/index.js.map +1 -0
  302. package/dist/mathlive/opf_includes.d.ts +2 -0
  303. package/dist/mathlive/opf_includes.d.ts.map +1 -0
  304. package/dist/mathlive/opf_includes.js +25 -0
  305. package/dist/mathlive/opf_includes.js.map +1 -0
  306. package/dist/schema/common/annotate.d.ts +59 -0
  307. package/dist/schema/common/annotate.d.ts.map +1 -0
  308. package/dist/schema/common/annotate.js +75 -0
  309. package/dist/schema/common/annotate.js.map +1 -0
  310. package/dist/schema/common/base.d.ts +109 -0
  311. package/dist/schema/common/base.d.ts.map +1 -0
  312. package/dist/schema/common/base.js +109 -0
  313. package/dist/schema/common/base.js.map +1 -0
  314. package/dist/schema/common/citation.d.ts +29 -0
  315. package/dist/schema/common/citation.d.ts.map +1 -0
  316. package/dist/schema/common/citation.js +62 -0
  317. package/dist/schema/common/citation.js.map +1 -0
  318. package/dist/schema/common/equation.d.ts +18 -0
  319. package/dist/schema/common/equation.d.ts.map +1 -0
  320. package/dist/schema/common/equation.js +32 -0
  321. package/dist/schema/common/equation.js.map +1 -0
  322. package/dist/schema/common/figure.d.ts +108 -0
  323. package/dist/schema/common/figure.d.ts.map +1 -0
  324. package/dist/schema/common/figure.js +176 -0
  325. package/dist/schema/common/figure.js.map +1 -0
  326. package/dist/schema/common/heading.d.ts +33 -0
  327. package/dist/schema/common/heading.d.ts.map +1 -0
  328. package/dist/schema/common/heading.js +41 -0
  329. package/dist/schema/common/heading.js.map +1 -0
  330. package/dist/schema/common/index.d.ts +11 -0
  331. package/dist/schema/common/index.d.ts.map +1 -0
  332. package/dist/schema/common/index.js +11 -0
  333. package/dist/schema/common/index.js.map +1 -0
  334. package/dist/schema/common/list.d.ts +83 -0
  335. package/dist/schema/common/list.d.ts.map +1 -0
  336. package/dist/schema/common/list.js +92 -0
  337. package/dist/schema/common/list.js.map +1 -0
  338. package/dist/schema/common/reference.d.ts +78 -0
  339. package/dist/schema/common/reference.d.ts.map +1 -0
  340. package/dist/schema/common/reference.js +97 -0
  341. package/dist/schema/common/reference.js.map +1 -0
  342. package/dist/schema/common/table.d.ts +92 -0
  343. package/dist/schema/common/table.d.ts.map +1 -0
  344. package/dist/schema/common/table.js +85 -0
  345. package/dist/schema/common/table.js.map +1 -0
  346. package/dist/schema/common/track.d.ts +131 -0
  347. package/dist/schema/common/track.d.ts.map +1 -0
  348. package/dist/schema/common/track.js +184 -0
  349. package/dist/schema/common/track.js.map +1 -0
  350. package/dist/schema/const.d.ts +3 -0
  351. package/dist/schema/const.d.ts.map +1 -0
  352. package/{src → dist}/schema/const.js +3 -3
  353. package/dist/schema/const.js.map +1 -0
  354. package/dist/schema/convert.d.ts +3 -0
  355. package/dist/schema/convert.d.ts.map +1 -0
  356. package/dist/schema/convert.js +1215 -0
  357. package/dist/schema/convert.js.map +1 -0
  358. package/dist/schema/document/content.d.ts +137 -0
  359. package/dist/schema/document/content.d.ts.map +1 -0
  360. package/dist/schema/document/content.js +177 -0
  361. package/dist/schema/document/content.js.map +1 -0
  362. package/dist/schema/document/index.d.ts +879 -0
  363. package/dist/schema/document/index.d.ts.map +1 -0
  364. package/dist/schema/document/index.js +68 -0
  365. package/dist/schema/document/index.js.map +1 -0
  366. package/dist/schema/document/structure.d.ts +273 -0
  367. package/dist/schema/document/structure.d.ts.map +1 -0
  368. package/dist/schema/document/structure.js +445 -0
  369. package/dist/schema/document/structure.js.map +1 -0
  370. package/dist/schema/export.d.ts +880 -0
  371. package/dist/schema/export.d.ts.map +1 -0
  372. package/dist/schema/export.js +16 -0
  373. package/dist/schema/export.js.map +1 -0
  374. package/dist/schema/footnotes.d.ts +499 -0
  375. package/dist/schema/footnotes.d.ts.map +1 -0
  376. package/dist/schema/footnotes.js +88 -0
  377. package/dist/schema/footnotes.js.map +1 -0
  378. package/dist/schema/footnotes_convert.d.ts +5 -0
  379. package/dist/schema/footnotes_convert.d.ts.map +1 -0
  380. package/dist/schema/footnotes_convert.js +26 -0
  381. package/dist/schema/footnotes_convert.js.map +1 -0
  382. package/dist/schema/i18n.d.ts +586 -0
  383. package/dist/schema/i18n.d.ts.map +1 -0
  384. package/dist/schema/i18n.js +585 -0
  385. package/dist/schema/i18n.js.map +1 -0
  386. package/dist/schema/index.d.ts +6 -0
  387. package/dist/schema/index.d.ts.map +1 -0
  388. package/dist/schema/index.js +6 -0
  389. package/dist/schema/index.js.map +1 -0
  390. package/dist/schema/mini_json.d.ts +5 -0
  391. package/dist/schema/mini_json.d.ts.map +1 -0
  392. package/dist/schema/mini_json.js +50 -0
  393. package/dist/schema/mini_json.js.map +1 -0
  394. package/dist/schema/text.d.ts +2 -0
  395. package/dist/schema/text.d.ts.map +1 -0
  396. package/dist/schema/text.js +23 -0
  397. package/dist/schema/text.js.map +1 -0
  398. package/dist/types.d.ts +122 -0
  399. package/dist/types.d.ts.map +1 -0
  400. package/dist/types.js +9 -0
  401. package/dist/types.js.map +1 -0
  402. package/package.json +48 -16
  403. package/scripts/export-schema.js +1 -1
  404. package/src/exporter/tools/{file.js → file.ts} +1 -1
  405. package/src/exporter/tools/{json.js → json.ts} +30 -19
  406. package/src/global.d.ts +11 -0
  407. package/src/schema/const.ts +58 -0
  408. package/src/types.ts +136 -0
  409. package/jest.config.js +0 -24
  410. /package/src/{index.js → index.ts} +0 -0
@@ -0,0 +1,1052 @@
1
+ import { escapeText } from "fwtoolkit";
2
+ import { CATS } from "../../schema/i18n.js";
3
+ import { xmlDOM } from "../tools/xml.js";
4
+ import { createZoteroCitation } from "../tools/zotero_csl.js";
5
+ import { translateBlockType } from "./tools.js";
6
+ const TEXT_BLOCK_TYPES = [
7
+ "heading1",
8
+ "heading2",
9
+ "heading3",
10
+ "heading4",
11
+ "heading5",
12
+ "heading6",
13
+ "paragraph",
14
+ "code_block"
15
+ ];
16
+ const INLINE_TYPES = [
17
+ "citation",
18
+ "cross_reference",
19
+ "cslbib",
20
+ "cslblock",
21
+ "cslindent",
22
+ "cslinline",
23
+ "cslleftmargin",
24
+ "cslrightinline",
25
+ "equation",
26
+ "footnote",
27
+ "hard_break",
28
+ "image",
29
+ "text"
30
+ ];
31
+ /**
32
+ * Create Zotero citation field instruction for DOCX.
33
+ * @param {Array} references - Array of {id, prefix?, locator?} from citation node
34
+ * @param {Object} bibDB - Bibliography database
35
+ * @param {string} formattedCitation - Pre-formatted citation text from citeproc
36
+ * @param {string} citationId - Optional citation ID (generated if not provided)
37
+ * @returns {string} Field instruction text
38
+ */
39
+ function createZoteroCitationField(references, bibDB, formattedCitation, citationId = null) {
40
+ const zoteroCitation = createZoteroCitation(references, bibDB, formattedCitation, citationId);
41
+ if (!zoteroCitation) {
42
+ return null;
43
+ }
44
+ const jsonStr = JSON.stringify(zoteroCitation);
45
+ return ` ADDIN ZOTERO_ITEM CSL_CITATION${jsonStr} `;
46
+ }
47
+ export class DOCXExporterRichtext {
48
+ constructor(doc, settings, lists, footnotes, math, tables, rels, citations, images) {
49
+ this.doc = doc;
50
+ this.settings = settings;
51
+ this.lists = lists;
52
+ this.footnotes = footnotes;
53
+ this.math = math;
54
+ this.tables = tables;
55
+ this.rels = rels;
56
+ this.citations = citations;
57
+ this.images = images;
58
+ this.comments = {};
59
+ this.commentRangeCounter = -1;
60
+ this.changeCounter = 0;
61
+ this.fnCounter = 1; // footnotes 0 and 1 are occupied by separators by default.
62
+ this.bookmarkCounter = -1;
63
+ this.categoryCounter = {}; // counters for each type of figure (figure/table/photo)
64
+ this.fncategoryCounter = {};
65
+ this.docPrCount = -1;
66
+ this.citationCounter = 0; // Track which citation we're processing
67
+ }
68
+ run(node, options = {}, nextNode = null) {
69
+ options.comments = this.findComments(node); // Data related to comments. We need to mark the first and last occurence of comment
70
+ return this.transformRichtext(node, options, nextNode);
71
+ }
72
+ findComments(node, comments = {}) {
73
+ if (node.marks) {
74
+ node.marks
75
+ .filter(mark => mark.type === "comment")
76
+ .forEach(comment => {
77
+ if (!this.doc.comments[comment.attrs.id]) {
78
+ return;
79
+ }
80
+ if (!comments[comment.attrs.id]) {
81
+ comments[comment.attrs.id] = {
82
+ start: node,
83
+ end: node,
84
+ content: this.doc.comments[comment.attrs.id]
85
+ };
86
+ }
87
+ else {
88
+ comments[comment.attrs.id]["end"] = node;
89
+ }
90
+ });
91
+ }
92
+ if (node.content) {
93
+ for (let i = 0; i < node.content.length; i++) {
94
+ this.findComments(node.content[i], comments);
95
+ }
96
+ }
97
+ return comments;
98
+ }
99
+ transformRichtext(node, options = {}, nextNode = null) {
100
+ let start = "", content = "", end = "";
101
+ if (node.marks && options.comments) {
102
+ // Footnotes don't allow comments in DOCX
103
+ node.marks
104
+ .filter(mark => mark.type === "comment")
105
+ .forEach(comment => {
106
+ const commentData = options.comments[comment.attrs.id];
107
+ if (!commentData) {
108
+ return;
109
+ }
110
+ if (commentData.start === node) {
111
+ let commentId = this.comments[comment.attrs.id];
112
+ start += `<w:commentRangeStart w:id="${commentId}"/>`;
113
+ commentData.content.answers?.forEach(_answer => (start += `<w:commentRangeStart w:id="${++commentId}"/>`));
114
+ }
115
+ if (commentData.end === node) {
116
+ let commentId = this.comments[comment.attrs.id];
117
+ end =
118
+ `<w:commentRangeEnd w:id="${commentId}"/><w:r><w:commentReference w:id="${commentId}"/></w:r>${(commentData.content.answers || [])
119
+ .map(_answer => `<w:commentRangeEnd w:id="${++commentId}"/><w:r><w:commentReference w:id="${commentId}"/></w:r>`)
120
+ .join("")}` + end;
121
+ }
122
+ });
123
+ }
124
+ const inlineType = INLINE_TYPES.includes(node.type);
125
+ let inlineDelete, nextBlockDelete, nextBlockInsert, blockChange, blockDelete, blockInsert;
126
+ if (inlineType) {
127
+ const inlineInsert = inlineType &&
128
+ (node.marks?.find(mark => mark.type === "insertion" &&
129
+ mark.attrs.approved === false)?.attrs ||
130
+ options.blockInsert);
131
+ inlineDelete =
132
+ inlineType &&
133
+ (node.marks?.find(mark => mark.type === "deletion")?.attrs ||
134
+ options.blockDelete);
135
+ if (inlineInsert &&
136
+ inlineDelete &&
137
+ inlineInsert.username === inlineDelete.username) {
138
+ // In DOCX, the same user cannot both have a pending insertion and deletion of the same inline content. We remove it.
139
+ return "";
140
+ }
141
+ else {
142
+ if (inlineInsert) {
143
+ start += `<w:ins w:id="${++this.changeCounter}" w:author="${escapeText(inlineInsert.username)}" w:date="${new Date(inlineInsert.date * 60000).toISOString().split(".")[0]}Z">`;
144
+ end = "</w:ins>" + end;
145
+ }
146
+ if (inlineDelete) {
147
+ start += `<w:del w:id="${++this.changeCounter}" w:author="${escapeText(inlineDelete.username)}" w:date="${new Date(inlineDelete.date * 60000).toISOString().split(".")[0]}Z">`;
148
+ end = "</w:del>" + end;
149
+ }
150
+ }
151
+ }
152
+ else if (TEXT_BLOCK_TYPES.includes(node.type)) {
153
+ blockChange = node.attrs?.track?.find(mark => mark.type === "block_change");
154
+ if (nextNode && TEXT_BLOCK_TYPES.includes(nextNode.type)) {
155
+ nextBlockDelete = nextNode.attrs?.track?.find(mark => mark.type === "deletion");
156
+ nextBlockInsert = nextNode.attrs?.track?.find(mark => mark.type === "insertion");
157
+ }
158
+ }
159
+ else {
160
+ blockDelete = node.attrs?.track?.find(mark => mark.type === "deletion");
161
+ if (blockDelete) {
162
+ options = Object.assign({}, options);
163
+ options.blockDelete = blockDelete;
164
+ }
165
+ blockInsert = node.attrs?.track?.find(mark => mark.type === "insertion");
166
+ if (blockInsert) {
167
+ options = Object.assign({}, options);
168
+ options.blockInsert = blockInsert;
169
+ }
170
+ }
171
+ switch (node.type) {
172
+ case "doc":
173
+ // We handle the contents directly
174
+ break;
175
+ case "paragraph":
176
+ if (!options.section) {
177
+ options.section = "Normal";
178
+ }
179
+ // This should really be something like
180
+ // '<w:p w:rsidR="A437D321" w:rsidRDefault="2B935ADC">'
181
+ // See: https://blogs.msdn.microsoft.com/brian_jones/2006/12/11/whats-up-with-all-those-rsids/
182
+ // But tests with Word 2016/LibreOffice seem to indicate that it
183
+ // doesn't care if the attributes are missing.
184
+ // We may need to add them later, if it turns out this is a problem
185
+ // for other versions of Word. In that case we should also add
186
+ // it to settings.xml as described in above link.
187
+ if (options.section === "Normal" &&
188
+ !options.list_type &&
189
+ !node.content?.length) {
190
+ start += "<w:p/>";
191
+ }
192
+ else {
193
+ start += `
194
+ <w:p${options.paragraphId ? ` w14:paraId="${options.paragraphId}"` : ""}>
195
+ <w:pPr><w:pStyle w:val="${options.section}"/>`;
196
+ if (options.list_type) {
197
+ start += `<w:numPr><w:ilvl w:val="${options.list_depth}"/>`;
198
+ start += `<w:numId w:val="${options.list_type}"/></w:numPr>`;
199
+ }
200
+ else {
201
+ start += `
202
+ <w:rPr>
203
+ ${nextBlockInsert
204
+ ? `<w:ins w:id="${++this.changeCounter}" w:author="${escapeText(nextBlockInsert.username)}" w:date="${new Date(nextBlockInsert.date * 60000).toISOString().split(".")[0]}Z"/>`
205
+ : ""}
206
+ ${nextBlockDelete
207
+ ? `<w:del w:id="${++this.changeCounter}" w:author="${escapeText(nextBlockDelete.username)}" w:date="${new Date(nextBlockDelete.date * 60000).toISOString().split(".")[0]}Z"/>`
208
+ : ""}
209
+ </w:rPr>`;
210
+ }
211
+ if (blockChange) {
212
+ start += `
213
+ <w:pPrChange w:id="${++this.changeCounter}" w:author="${escapeText(blockChange.username)}" w:date="${new Date(blockChange.date * 60000).toISOString().split(".")[0]}Z">
214
+ <w:pPr>
215
+ <w:pStyle w:val="${translateBlockType(blockChange.before.type)}"/>
216
+ </w:pPr>
217
+ </w:pPrChange>`;
218
+ }
219
+ start += "</w:pPr>";
220
+ end = "</w:p>" + end;
221
+ if (!node.content?.length) {
222
+ start += "<w:r><w:rPr></w:rPr></w:r>";
223
+ }
224
+ }
225
+ if (options.commentReference) {
226
+ end =
227
+ '<w:r><w:rPr><w:rStyle w:val="CommentReference"/></w:rPr><w:annotationRef/></w:r>' +
228
+ end;
229
+ options = Object.assign({}, options);
230
+ options.commentReference = false;
231
+ }
232
+ break;
233
+ case "bibliography_heading":
234
+ start += `
235
+ <w:p>
236
+ <w:pPr>
237
+ <w:pStyle w:val="BibliographyHeading"/>
238
+ <w:rPr></w:rPr>
239
+ </w:pPr>`;
240
+ end = "</w:p>" + end;
241
+ break;
242
+ case "heading1":
243
+ case "heading2":
244
+ case "heading3":
245
+ case "heading4":
246
+ case "heading5":
247
+ case "heading6":
248
+ start += `
249
+ <w:p>
250
+ <w:pPr>
251
+ <w:pStyle w:val="${translateBlockType(node.type)}"/>
252
+ <w:rPr>
253
+ ${nextBlockInsert
254
+ ? `<w:ins w:id="${++this.changeCounter}" w:author="${escapeText(nextBlockInsert.username)}" w:date="${new Date(nextBlockInsert.date * 60000).toISOString().split(".")[0]}Z"/>`
255
+ : ""}
256
+ ${nextBlockDelete
257
+ ? `<w:del w:id="${++this.changeCounter}" w:author="${escapeText(nextBlockDelete.username)}" w:date="${new Date(nextBlockDelete.date * 60000).toISOString().split(".")[0]}Z"/>`
258
+ : ""}
259
+ </w:rPr>
260
+ ${blockChange
261
+ ? blockChange.before.type === "paragraph"
262
+ ? `<w:pPrChange w:id="${++this.changeCounter}" w:author="${escapeText(blockChange.username)}" w:date="${new Date(blockChange.date * 60000).toISOString().split(".")[0]}Z"/>`
263
+ : `<w:pPrChange w:id="${++this.changeCounter}" w:author="${escapeText(blockChange.username)}" w:date="${new Date(blockChange.date * 60000).toISOString().split(".")[0]}Z">
264
+ <w:pPr>
265
+ <w:pStyle w:val="${translateBlockType(blockChange.before.type)}"/>
266
+ </w:pPr>
267
+ </w:pPrChange>`
268
+ : ""}
269
+ </w:pPr>
270
+ <w:bookmarkStart w:name="${node.attrs.id}" w:id="${++this.bookmarkCounter}"/>
271
+ <w:bookmarkEnd w:id="${this.bookmarkCounter}"/>`;
272
+ end = "</w:p>" + end;
273
+ break;
274
+ case "blockquote":
275
+ // This is imperfect, but Word doesn't seem to provide section/quotation nesting
276
+ // Also, track information on wrapping into blockquote is not exported.
277
+ options = Object.assign({}, options);
278
+ options.section = "Quote";
279
+ break;
280
+ case "code_block": {
281
+ // Handle code blocks with category support
282
+ const category = node.attrs.category;
283
+ let categoryLabel = "";
284
+ if (category && node.attrs.id) {
285
+ const categoryCounter = options.inFootnote
286
+ ? this.fnCategoryCounter
287
+ : this.categoryCounter;
288
+ if (!categoryCounter[category]) {
289
+ categoryCounter[category] = 1;
290
+ }
291
+ const catCount = categoryCounter[category]++;
292
+ const { CATS } = require("../../schema/i18n");
293
+ const categoryLabelText = CATS[category]?.[this.settings.language] || category;
294
+ const title = node.attrs.title
295
+ ? `: ${escapeText(node.attrs.title)}`
296
+ : "";
297
+ // Create category label paragraph with SEQ field for numbering
298
+ categoryLabel = `
299
+ <w:p>
300
+ <w:pPr><w:pStyle w:val="Caption"/></w:pPr>
301
+ <w:bookmarkStart w:name="${node.attrs.id}" w:id="${++this.bookmarkCounter}"/>
302
+ <w:r>
303
+ <w:t xml:space="preserve">${categoryLabelText} </w:t>
304
+ </w:r>
305
+ <w:fldSimple w:instr=" SEQ ${category} \\* ARABIC ">
306
+ <w:r>
307
+ <w:t>${catCount}${options.inFootnote ? "A" : ""}</w:t>
308
+ </w:r>
309
+ </w:fldSimple>
310
+ <w:r>
311
+ <w:t xml:space="preserve">${title}</w:t>
312
+ </w:r>
313
+ <w:bookmarkEnd w:id="${this.bookmarkCounter}"/>
314
+ </w:p>`;
315
+ }
316
+ if (!node.content?.length) {
317
+ start += categoryLabel + "<w:p/>";
318
+ }
319
+ else {
320
+ options = Object.assign({}, options);
321
+ options.section = "Code";
322
+ start +=
323
+ categoryLabel +
324
+ `
325
+ <w:p${options.paragraphId ? ` w14:paraId="${options.paragraphId}"` : ""}>
326
+ <w:pPr><w:pStyle w:val="${options.section}"/>`;
327
+ if (options.list_type) {
328
+ start += `<w:numPr><w:ilvl w:val="${options.list_depth}"/>`;
329
+ start += `<w:numId w:val="${options.list_type}"/></w:numPr>`;
330
+ }
331
+ else {
332
+ start += `
333
+ <w:rPr>
334
+ ${nextBlockInsert
335
+ ? `<w:ins w:id="${++this.changeCounter}" w:author="${escapeText(nextBlockInsert.username)}" w:date="${new Date(nextBlockInsert.date * 60000).toISOString().split(".")[0]}Z"/>`
336
+ : ""}
337
+ ${nextBlockDelete
338
+ ? `<w:del w:id="${++this.changeCounter}" w:author="${escapeText(nextBlockDelete.username)}" w:date="${new Date(nextBlockDelete.date * 60000).toISOString().split(".")[0]}Z"/>`
339
+ : ""}
340
+ </w:rPr>`;
341
+ }
342
+ if (blockChange) {
343
+ start += `
344
+ <w:pPrChange w:id="${++this.changeCounter}" w:author="${escapeText(blockChange.username)}" w:date="${new Date(blockChange.date * 60000).toISOString().split(".")[0]}Z">
345
+ <w:pPr>
346
+ <w:pStyle w:val="${translateBlockType(blockChange.before.type)}"/>
347
+ </w:pPr>
348
+ </w:pPrChange>`;
349
+ }
350
+ start += "</w:pPr>";
351
+ end = "</w:p>" + end;
352
+ if (!node.content?.length) {
353
+ start += "<w:r><w:rPr></w:rPr></w:r>";
354
+ }
355
+ }
356
+ if (options.commentReference) {
357
+ end =
358
+ '<w:r><w:rPr><w:rStyle w:val="CommentReference"/></w:rPr><w:annotationRef/></w:r>' +
359
+ end;
360
+ options.commentReference = false;
361
+ }
362
+ break;
363
+ }
364
+ case "ordered_list": {
365
+ options = Object.assign({}, options);
366
+ options.section = "ListParagraph";
367
+ if (options.list_depth === undefined) {
368
+ options.list_depth = 0;
369
+ }
370
+ else {
371
+ options.list_depth += 1;
372
+ }
373
+ options.list_type = this.lists.getNumberedType();
374
+ break;
375
+ }
376
+ case "bullet_list":
377
+ options = Object.assign({}, options);
378
+ options.section = "ListParagraph";
379
+ options.list_type = this.lists.getBulletType();
380
+ if (options.list_depth === undefined) {
381
+ options.list_depth = 0;
382
+ }
383
+ else {
384
+ options.list_depth += 1;
385
+ }
386
+ break;
387
+ case "list_item":
388
+ // Word seems to lack complex nesting options. The styling is applied
389
+ // to child paragraphs. This will deliver correct results in most
390
+ // cases.
391
+ break;
392
+ case "footnotecontainer":
393
+ options = Object.assign({}, options);
394
+ options.section = "Footnote";
395
+ options.inFootnote = true;
396
+ start += `<w:footnote w:id="${++this.fnCounter}">`;
397
+ end = "</w:footnote>" + end;
398
+ options.footnoteRefMissing = true;
399
+ break;
400
+ case "footnote":
401
+ content += `
402
+ <w:r>
403
+ <w:rPr>
404
+ <w:rStyle w:val="FootnoteAnchor"/>
405
+ </w:rPr>
406
+ <w:footnoteReference w:id="${++this.fnCounter}"/>
407
+ </w:r>`;
408
+ break;
409
+ case "text": {
410
+ let hyperlink, anchor, em, strong, underline, smallcaps, sup, sub, code, formatChange;
411
+ // Check for hyperlink, anchor, bold/strong and italic/em
412
+ if (node.marks) {
413
+ hyperlink = node.marks.find(mark => mark.type === "link");
414
+ anchor = node.marks.find(mark => mark.type === "anchor");
415
+ em = node.marks.find(mark => mark.type === "em");
416
+ strong = node.marks.find(mark => mark.type === "strong");
417
+ underline = node.marks.find(mark => mark.type === "underline");
418
+ smallcaps = node.marks.find(mark => mark.type === "smallcaps");
419
+ sup = node.marks.find(mark => mark.type === "sup");
420
+ sub = node.marks.find(mark => mark.type === "sub");
421
+ code = node.marks.find(mark => mark.type === "code");
422
+ formatChange = node.marks.find(mark => mark.type === "format_change");
423
+ }
424
+ if (anchor) {
425
+ start += `<w:bookmarkStart w:name="${anchor.attrs.id}" w:id="${++this.bookmarkCounter}"/><w:bookmarkEnd w:id="${this.bookmarkCounter}"/>`;
426
+ end =
427
+ `<w:bookmarkStart w:name="${anchor.attrs.id}" w:id="${++this.bookmarkCounter}"/><w:bookmarkEnd w:id="${this.bookmarkCounter}"/>` +
428
+ end;
429
+ }
430
+ if (hyperlink) {
431
+ const href = hyperlink.attrs.href;
432
+ if (href[0] === "#") {
433
+ // Internal link
434
+ start += `<w:hyperlink w:anchor="${href.slice(1)}">`;
435
+ }
436
+ else {
437
+ // External link
438
+ const refId = this.rels.addLinkRel(href);
439
+ start += `<w:hyperlink r:id="rId${refId}">`;
440
+ }
441
+ start += "<w:r>";
442
+ end = "</w:r></w:hyperlink>" + end;
443
+ }
444
+ else {
445
+ start += "<w:r>";
446
+ end = "</w:r>" + end;
447
+ }
448
+ start += "<w:rPr>";
449
+ if (hyperlink ||
450
+ em ||
451
+ strong ||
452
+ underline ||
453
+ smallcaps ||
454
+ sup ||
455
+ sub ||
456
+ code) {
457
+ if (hyperlink) {
458
+ this.rels.addLinkStyle();
459
+ start += `<w:rStyle w:val="${this.rels.hyperLinkStyle}"/>`;
460
+ }
461
+ if (em) {
462
+ start += "<w:i/><w:iCs/>";
463
+ }
464
+ if (strong) {
465
+ start += "<w:b/><w:bCs/>";
466
+ }
467
+ if (underline) {
468
+ start += '<w:u w:val="single"/>';
469
+ }
470
+ if (smallcaps) {
471
+ start += "<w:smallCaps/>";
472
+ }
473
+ if (sup) {
474
+ start += '<w:vertAlign w:val="superscript"/>';
475
+ }
476
+ else if (sub) {
477
+ start += '<w:vertAlign w:val="subscript"/>';
478
+ }
479
+ if (code) {
480
+ start +=
481
+ '<w:rFonts w:ascii="Courier New" w:hAnsi="Courier New"/>';
482
+ }
483
+ }
484
+ if (formatChange) {
485
+ const beforeStyle = formatChange.attrs.before;
486
+ start += `<w:rPrChange w:id="${++this.changeCounter}" w:author="${escapeText(formatChange.attrs.username)}" w:date="${new Date(formatChange.attrs.date * 60000).toISOString().split(".")[0]}Z"><w:rPr>`;
487
+ if (beforeStyle.includes("em")) {
488
+ start += "<w:i/><w:iCs/>";
489
+ }
490
+ if (beforeStyle.includes("strong")) {
491
+ start += "<w:b/><w:bCs/>";
492
+ }
493
+ if (beforeStyle.includes("underline")) {
494
+ start += '<w:u w:val="single"/>';
495
+ }
496
+ start += "</w:rPr></w:rPrChange>";
497
+ }
498
+ start += "</w:rPr>";
499
+ if (options.footnoteRefMissing) {
500
+ start += "<w:footnoteRef /><w:tab />";
501
+ options.footnoteRefMissing = false;
502
+ }
503
+ let textAttr = "";
504
+ if (node.text[0] === " " ||
505
+ node.text[node.text.length - 1] === " ") {
506
+ textAttr += ' xml:space="preserve"';
507
+ }
508
+ if (inlineDelete) {
509
+ start += `<w:delText${textAttr}>`;
510
+ end = "</w:delText>" + end;
511
+ }
512
+ else {
513
+ start += `<w:t${textAttr}>`;
514
+ end = "</w:t>" + end;
515
+ }
516
+ content += escapeText(node.text);
517
+ break;
518
+ }
519
+ case "cross_reference": {
520
+ const title = node.attrs.title;
521
+ const id = node.attrs.id;
522
+ let marks = node.marks.slice();
523
+ if (title && id) {
524
+ const hyperlink = {
525
+ type: "link",
526
+ attrs: { href: `#${id}`, title }
527
+ };
528
+ marks = marks.filter(mark => mark.type !== "link");
529
+ marks.push(hyperlink);
530
+ }
531
+ content += this.transformRichtext({
532
+ type: "text",
533
+ text: title || "MISSING TARGET",
534
+ marks
535
+ }, options, nextNode);
536
+ break;
537
+ }
538
+ case "citation": {
539
+ // We take the first citation from the stack and remove it.
540
+ const cit = this.citations.pmCits.shift();
541
+ // Get citation info and formatted text for Zotero export
542
+ const citInfo = this.citations.citInfos[this.citationCounter];
543
+ const formattedText = this.citations.citationTexts[this.citationCounter];
544
+ this.citationCounter++;
545
+ // Create Zotero citation data on-the-fly
546
+ const fieldInstruction = citInfo && formattedText
547
+ ? createZoteroCitationField(citInfo.references, this.citations.bibDB, formattedText)
548
+ : null;
549
+ if (options.citationType === "note" && !options.inFootnote) {
550
+ // If the citations are in notes (footnotes), we need to
551
+ // put the content of this citation in a footnote.
552
+ // We then add the footnote to the footnote file and
553
+ // adjust the ids of all subsequent footnotes to be one higher
554
+ // than what they were until now.
555
+ content += `
556
+ <w:r>
557
+ <w:rPr>
558
+ <w:rStyle w:val="FootnoteAnchor"/>
559
+ </w:rPr>
560
+ <w:footnoteReference w:id="${this.fnCounter}"/>
561
+ </w:r>`;
562
+ // Create footnote with Zotero field if available
563
+ let fnXML;
564
+ if (fieldInstruction && formattedText) {
565
+ fnXML = `<w:footnote w:id="${this.fnCounter}">
566
+ <w:p>
567
+ <w:r>
568
+ <w:fldChar w:fldCharType="begin"/>
569
+ </w:r>
570
+ <w:r>
571
+ <w:instrText xml:space="preserve">${fieldInstruction}</w:instrText>
572
+ </w:r>
573
+ <w:r>
574
+ <w:fldChar w:fldCharType="separate"/>
575
+ </w:r>
576
+ <w:r>
577
+ <w:t>${formattedText}</w:t>
578
+ </w:r>
579
+ <w:r>
580
+ <w:fldChar w:fldCharType="end"/>
581
+ </w:r>
582
+ </w:p>
583
+ </w:footnote>`;
584
+ }
585
+ else {
586
+ const fnContents = this.transformRichtext(cit, {
587
+ footnoteRefMissing: true,
588
+ section: "Footnote"
589
+ });
590
+ fnXML = `<w:footnote w:id="${this.fnCounter}">${fnContents}</w:footnote>`;
591
+ }
592
+ const xml = this.footnotes.xml;
593
+ const lastId = this.fnCounter - 1;
594
+ const footnotes = xml.queryAll("w:footnote");
595
+ footnotes.forEach(footnote => {
596
+ const id = Number.parseInt(footnote.getAttribute("w:id"));
597
+ if (id >= this.fnCounter) {
598
+ footnote.setAttribute("w:id", id + 1);
599
+ }
600
+ if (id === lastId) {
601
+ footnote.parentElement.insertBefore(xmlDOM(fnXML), footnote.nextSibling);
602
+ }
603
+ });
604
+ this.fnCounter++;
605
+ }
606
+ else {
607
+ // In-text citation - create Zotero field if available
608
+ if (fieldInstruction && formattedText) {
609
+ content += `
610
+ <w:r>
611
+ <w:fldChar w:fldCharType="begin"/>
612
+ </w:r>
613
+ <w:r>
614
+ <w:instrText xml:space="preserve">${fieldInstruction}</w:instrText>
615
+ </w:r>
616
+ <w:r>
617
+ <w:fldChar w:fldCharType="separate"/>
618
+ </w:r>
619
+ <w:r>
620
+ <w:t>${formattedText}</w:t>
621
+ </w:r>
622
+ <w:r>
623
+ <w:fldChar w:fldCharType="end"/>
624
+ </w:r>`;
625
+ }
626
+ else {
627
+ // Fallback to formatted text only
628
+ for (let i = 0; i < cit.content.length; i++) {
629
+ content += this.transformRichtext(cit.content[i], options, cit.content[i + 1]);
630
+ }
631
+ }
632
+ }
633
+ break;
634
+ }
635
+ case "figure": {
636
+ const category = node.attrs.category;
637
+ let caption = node.attrs.caption
638
+ ? node.content.find(node => node.type === "figure_caption")
639
+ ?.content || []
640
+ : [];
641
+ let catCountXML = "";
642
+ if (category !== "none") {
643
+ const categoryCounter = options.inFootnote
644
+ ? this.fncategoryCounter
645
+ : this.categoryCounter;
646
+ if (!categoryCounter[category]) {
647
+ categoryCounter[category] = 1;
648
+ }
649
+ catCountXML = `<w:r>
650
+ <w:t xml:space="preserve">${CATS[category][this.settings.language]} </w:t>
651
+ </w:r>
652
+ <w:r>
653
+ <w:rPr></w:rPr>
654
+ <w:fldChar w:fldCharType="begin"></w:fldChar>
655
+ </w:r>
656
+ <w:r>
657
+ <w:rPr></w:rPr>
658
+ <w:instrText> SEQ ${category} \\* ARABIC </w:instrText>
659
+ </w:r>
660
+ <w:r>
661
+ <w:rPr></w:rPr>
662
+ <w:fldChar w:fldCharType="separate" />
663
+ </w:r>
664
+ <w:r>
665
+ <w:rPr></w:rPr>
666
+ <w:t>${categoryCounter[category]++}${options.inFootnote ? "A" : ""}</w:t>
667
+ </w:r>
668
+ <w:r>
669
+ <w:rPr></w:rPr>
670
+ <w:fldChar w:fldCharType="end" />
671
+ </w:r>`;
672
+ if (caption.length) {
673
+ caption = [{ type: "text", text: ": " }].concat(caption);
674
+ }
675
+ }
676
+ let cx, cy;
677
+ const image = node.content.find(node => node.type === "image")?.attrs
678
+ .image || false;
679
+ if (image !== false) {
680
+ const imageEntry = this.images.images[image];
681
+ cx = imageEntry.width * 9525; // width in EMU
682
+ cy = imageEntry.height * 9525; // height in EMU
683
+ const imgTitle = imageEntry.title;
684
+ // Shrink image if too large for paper.
685
+ if (options.dimensions) {
686
+ let width = options.dimensions.width;
687
+ if (options.tableSideMargins) {
688
+ width = width - options.tableSideMargins;
689
+ }
690
+ width =
691
+ (width * Number.parseInt(node.attrs.width)) / 100;
692
+ if (cx > width) {
693
+ const rel = cy / cx;
694
+ cx = width;
695
+ cy = cx * rel;
696
+ }
697
+ if (cy > options.dimensions.height) {
698
+ const rel = cx / cy;
699
+ cy = options.dimensions.height;
700
+ cx = cy * rel;
701
+ }
702
+ }
703
+ cy = Math.round(cy);
704
+ cx = Math.round(cx);
705
+ const rId = imageEntry.id;
706
+ content += `<w:r>
707
+ <w:rPr></w:rPr>
708
+ <w:drawing>
709
+ <wp:inline distT="0" distB="0" distL="0" distR="0">
710
+ <wp:extent cx="${cx}" cy="${cy}"/>
711
+ <wp:docPr id="${++this.docPrCount}" name="Picture${this.docPrCount}" descr=""/>
712
+ <a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
713
+ <a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture">
714
+ <pic:pic xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture">
715
+ <pic:nvPicPr>
716
+ <pic:cNvPr id="0" name="${imgTitle}" descr=""/>
717
+ <pic:cNvPicPr>
718
+ <a:picLocks noChangeAspect="1" noChangeArrowheads="1"/>
719
+ </pic:cNvPicPr>
720
+ </pic:nvPicPr>
721
+ <pic:blipFill>
722
+ <a:blip r:embed="rId${rId}"/>
723
+ <a:stretch>
724
+ <a:fillRect/>
725
+ </a:stretch>
726
+ </pic:blipFill>
727
+ <pic:spPr bwMode="auto">
728
+ <a:xfrm>
729
+ <a:off x="0" y="0"/>
730
+ <a:ext cx="${cx}" cy="${cy}"/>
731
+ </a:xfrm>
732
+ <a:prstGeom prst="rect">
733
+ <a:avLst/>
734
+ </a:prstGeom>
735
+ <a:noFill/>
736
+ <a:ln w="9525">
737
+ <a:noFill/>
738
+ <a:miter lim="800000"/>
739
+ <a:headEnd/>
740
+ <a:tailEnd/>
741
+ </a:ln>
742
+ </pic:spPr>
743
+ </pic:pic>
744
+ </a:graphicData>
745
+ </a:graphic>
746
+ </wp:inline>
747
+ </w:drawing>
748
+ </w:r>`;
749
+ }
750
+ else {
751
+ cx = 9525 * 100; // We pick a random size of 100x100. We hope this will fit the formula
752
+ cy = 9525 * 100;
753
+ const latex = node.content.find(node => node.type === "figure_equation")?.attrs.equation || "";
754
+ content += this.math.getOmml(latex);
755
+ }
756
+ const captionSpace = !!(catCountXML.length || caption.length);
757
+ if (node.attrs.aligned === "center") {
758
+ start += `
759
+ <w:p>
760
+ <w:pPr>
761
+ <w:jc w:val="center"/>
762
+ </w:pPr>`;
763
+ content =
764
+ `<w:bookmarkStart w:name="${node.attrs.id}" w:id="${++this.bookmarkCounter}"/><w:bookmarkEnd w:id="${this.bookmarkCounter}"/>` +
765
+ content;
766
+ end =
767
+ `
768
+ </w:p>
769
+ ${captionSpace
770
+ ? `<w:p>
771
+ <w:pPr><w:pStyle w:val="Caption"/><w:rPr></w:rPr></w:pPr>
772
+ ${catCountXML}
773
+ ${caption.map((node, i) => this.transformRichtext(node, options, caption[i + 1])).join("")}
774
+ </w:p>`
775
+ : ""}` + end;
776
+ }
777
+ else {
778
+ start += `
779
+ <w:p>
780
+ <w:pPr>
781
+ <w:jc w:val="center"/>
782
+ </w:pPr>
783
+ <w:r>
784
+ <w:rPr></w:rPr>
785
+ <w:drawing>
786
+ <wp:anchor behindDoc="0" distT="95250" distB="95250" distL="95250" distR="95250" simplePos="0" locked="0" layoutInCell="1" allowOverlap="0" relativeHeight="2">
787
+ <wp:simplePos x="0" y="0" />
788
+ <wp:positionH relativeFrom="column">
789
+ <wp:align>${node.attrs.aligned}</wp:align>
790
+ </wp:positionH>
791
+ <wp:positionV relativeFrom="paragraph">
792
+ <wp:posOffset>0</wp:posOffset>
793
+ </wp:positionV>
794
+ <wp:extent cx="${cx}" cy="${captionSpace ? cy + 350520 : cy}" />
795
+ <wp:effectExtent l="0" t="0" r="0" b="0" />
796
+ <wp:wrapSquare wrapText="largest" />
797
+ <wp:docPr id="${++this.docPrCount}" name="Frame${this.docPrCount}" />
798
+ <a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
799
+ <a:graphicData uri="http://schemas.microsoft.com/office/word/2010/wordprocessingShape">
800
+ <wps:wsp>
801
+ <wps:cNvSpPr txBox="1" />
802
+ <wps:spPr>
803
+ <a:xfrm>
804
+ <a:off x="0" y="0" />
805
+ <a:ext cx="${cx}" cy="${captionSpace ? cy + 350520 : cy}" />
806
+ </a:xfrm>
807
+ <a:prstGeom prst="rect" />
808
+ </wps:spPr>
809
+ <wps:txbx>
810
+ <w:txbxContent>
811
+ <w:p>
812
+ <w:pPr>
813
+ <w:pStyle w:val="Caption" />
814
+ <w:spacing w:before="20" w:after="220" />
815
+ <w:rPr></w:rPr>
816
+ </w:pPr>`;
817
+ content =
818
+ `<w:bookmarkStart w:name="${node.attrs.id}" w:id="${++this.bookmarkCounter}"/><w:bookmarkEnd w:id="${this.bookmarkCounter}"/>` +
819
+ content;
820
+ end =
821
+ `
822
+ ${catCountXML}
823
+ ${caption.map((node, i) => this.transformRichtext(node, options, caption[i + 1])).join("")}
824
+ </w:p>
825
+ </w:txbxContent>
826
+ </wps:txbx>
827
+ <wps:bodyPr anchor="t" lIns="0" tIns="0" rIns="0" bIns="0">
828
+ <a:noAutofit />
829
+ </wps:bodyPr>
830
+ </wps:wsp>
831
+ </a:graphicData>
832
+ </a:graphic>
833
+ <wp14:sizeRelH relativeFrom="margin">
834
+ <wp14:pctWidth>${node.attrs.width}000</wp14:pctWidth>
835
+ </wp14:sizeRelH>
836
+ </wp:anchor>
837
+ </w:drawing>
838
+ </w:r>
839
+ </w:p>` + end;
840
+ }
841
+ if (blockInsert) {
842
+ start += `<w:ins w:id="${++this.changeCounter}" w:author="${escapeText(blockInsert.username)}" w:date="${new Date(blockInsert.date * 60000).toISOString().split(".")[0]}Z">`;
843
+ end = "</w:ins>" + end;
844
+ }
845
+ if (blockDelete) {
846
+ start += `<w:del w:id="${++this.changeCounter}" w:author="${escapeText(blockDelete.username)}" w:date="${new Date(blockDelete.date * 60000).toISOString().split(".")[0]}Z">`;
847
+ end = "</w:del>" + end;
848
+ }
849
+ break;
850
+ }
851
+ case "figure_caption":
852
+ // We are already dealing with this in the figure. Prevent content from being added a second time.
853
+ return "";
854
+ case "figure_equation":
855
+ // We are already dealing with this in the figure.
856
+ break;
857
+ case "image":
858
+ // We are already dealing with this in the figure.
859
+ break;
860
+ case "table": {
861
+ const category = node.attrs.category;
862
+ let caption = node.attrs.caption
863
+ ? node.content[0].content || []
864
+ : [];
865
+ let catCountXML = "";
866
+ if (category !== "none") {
867
+ const categoryCounter = options.inFootnote
868
+ ? this.fncategoryCounter
869
+ : this.categoryCounter;
870
+ if (!categoryCounter[category]) {
871
+ categoryCounter[category] = 1;
872
+ }
873
+ catCountXML = `<w:r>
874
+ <w:t xml:space="preserve">${CATS[category][this.settings.language]} </w:t>
875
+ </w:r>
876
+ <w:r>
877
+ <w:rPr></w:rPr>
878
+ <w:fldChar w:fldCharType="begin"></w:fldChar>
879
+ </w:r>
880
+ <w:r>
881
+ <w:rPr></w:rPr>
882
+ <w:instrText> SEQ ${category} \\* ARABIC </w:instrText>
883
+ </w:r>
884
+ <w:r>
885
+ <w:rPr></w:rPr>
886
+ <w:fldChar w:fldCharType="separate" />
887
+ </w:r>
888
+ <w:r>
889
+ <w:rPr></w:rPr>
890
+ <w:t>${categoryCounter[category]++}${options.inFootnote ? "A" : ""}</w:t>
891
+ </w:r>
892
+ <w:r>
893
+ <w:rPr></w:rPr>
894
+ <w:fldChar w:fldCharType="end" />
895
+ </w:r>`;
896
+ if (caption.length) {
897
+ caption = [{ type: "text", text: ": " }].concat(caption);
898
+ }
899
+ }
900
+ const captionSpace = !!(catCountXML.length || caption.length);
901
+ if (captionSpace) {
902
+ start += `
903
+ <w:p>
904
+ <w:pPr>
905
+ <w:pStyle w:val="Caption"/>
906
+ <w:keepNext/>
907
+ </w:pPr>
908
+ <w:bookmarkStart w:name="${node.attrs.id}" w:id="${++this.bookmarkCounter}"/>
909
+ <w:bookmarkEnd w:id="${this.bookmarkCounter}"/>
910
+ ${catCountXML}
911
+ ${caption.map((node, i) => this.transformRichtext(node, options, caption[i + 1])).join("")}
912
+ </w:p>`;
913
+ }
914
+ this.tables.addTableGridStyle();
915
+ start += `
916
+ <w:tbl>
917
+ <w:tblPr>
918
+ <w:tblStyle w:val="${this.tables.tableGridStyle}" />
919
+ ${node.attrs.width === "100"
920
+ ? '<w:tblW w:w="0" w:type="auto" />'
921
+ : `<w:tblW w:w="${50 * Number.parseInt(node.attrs.width)}" w:type="pct" />
922
+ <w:jc w:val="${node.attrs.aligned}" />`}
923
+ <w:tblLook w:val="04A0" w:firstRow="1" w:lastRow="0" w:firstColumn="1" w:lastColumn="0" w:noHBand="0" w:noVBand="1" />
924
+ </w:tblPr>
925
+ <w:tblGrid>`;
926
+ const columns = node.content[1].content[0].content.length;
927
+ let cellWidth = 63500; // standard width
928
+ options = Object.assign({}, options);
929
+ if (options.dimensions?.width) {
930
+ cellWidth =
931
+ Number.parseInt(options.dimensions.width / columns) -
932
+ 2540; // subtracting for border width
933
+ }
934
+ else if (!options.dimensions) {
935
+ options.dimensions = {};
936
+ }
937
+ options.section = "Normal";
938
+ options.list_type = null;
939
+ options.dimensions = Object.assign({}, options.dimensions);
940
+ options.dimensions.width = cellWidth;
941
+ options.tableSideMargins = this.tables.getSideMargins();
942
+ for (let i = 0; i < columns; i++) {
943
+ start += `<w:gridCol w:w="${Number.parseInt(cellWidth / 635)}" />`;
944
+ }
945
+ start += "</w:tblGrid>";
946
+ end = "</w:tbl>" + end;
947
+ break;
948
+ }
949
+ case "table_body":
950
+ // Pass through to table.
951
+ break;
952
+ case "table_caption":
953
+ // We already deal with this in 'table'.
954
+ return "";
955
+ case "table_row":
956
+ start += "<w:tr>";
957
+ end = "</w:tr>" + end;
958
+ break;
959
+ case "table_cell":
960
+ case "table_header":
961
+ start += `
962
+ <w:tc>
963
+ <w:tcPr>
964
+ ${node.attrs.rowspan && node.attrs.colspan
965
+ ? `<w:tcW w:w="${Number.parseInt((options.dimensions?.width || 0) / 635)}" w:type="dxa" />`
966
+ : '<w:tcW w:w="0" w:type="auto" />'}
967
+ ${node.attrs.rowspan
968
+ ? node.attrs.rowspan > 1
969
+ ? '<w:vMerge w:val="restart" />'
970
+ : ""
971
+ : "<w:vMerge/>"}
972
+ ${node.attrs.colspan
973
+ ? node.attrs.colspan > 1
974
+ ? '<w:hMerge w:val="restart" />'
975
+ : ""
976
+ : "<w:hMerge/>"}
977
+ </w:tcPr>
978
+ ${node.content ? "" : "<w:p/>"}`;
979
+ end = "</w:tc>" + end;
980
+ break;
981
+ case "equation": {
982
+ const latex = node.attrs.equation;
983
+ content += this.math.getOmml(latex);
984
+ break;
985
+ }
986
+ case "hard_break":
987
+ content += "<w:r><w:br/></w:r>";
988
+ break;
989
+ // CSL bib entries
990
+ case "cslbib":
991
+ options = Object.assign({}, options);
992
+ options.section = "Bibliography";
993
+ break;
994
+ case "cslblock":
995
+ end = "<w:r><w:br/></w:r>" + end;
996
+ break;
997
+ case "cslleftmargin":
998
+ end = "<w:r><w:tab/></w:r>" + end;
999
+ break;
1000
+ case "cslindent":
1001
+ start += "<w:r><w:tab/></w:r>";
1002
+ end = "<w:r><w:br/></w:r>" + end;
1003
+ break;
1004
+ case "cslentry":
1005
+ start += `
1006
+ <w:p>
1007
+ <w:pPr>
1008
+ <w:pStyle w:val="${options.section}"/>
1009
+ <w:rPr></w:rPr>
1010
+ </w:pPr>`;
1011
+ // Note - beginning is in same par as first item, whereas end is in its own par
1012
+ if (node.attrs?.first) {
1013
+ start += `<w:r>
1014
+ <w:fldChar w:fldCharType="begin"/>
1015
+ </w:r>
1016
+ <w:r>
1017
+ <w:instrText xml:space="preserve"> ADDIN ZOTERO_BIBL CSL_BIBLIOGRAPHY </w:instrText>
1018
+ </w:r>
1019
+ <w:r>
1020
+ <w:fldChar w:fldCharType="separate"/>
1021
+ </w:r>`;
1022
+ }
1023
+ end = "</w:p>" + end;
1024
+ if (node.attrs?.last) {
1025
+ end =
1026
+ end +
1027
+ `<w:p>
1028
+ <w:pPr>
1029
+ <w:rPr/>
1030
+ </w:pPr>
1031
+ <w:r>
1032
+ <w:fldChar w:fldCharType="end"/>
1033
+ </w:r>
1034
+ </w:p>`;
1035
+ }
1036
+ break;
1037
+ case "cslinline":
1038
+ case "cslrightinline":
1039
+ break;
1040
+ default:
1041
+ console.warn("Unknown node type:", node.type, node);
1042
+ break;
1043
+ }
1044
+ if (node.content) {
1045
+ for (let i = 0; i < node.content.length; i++) {
1046
+ content += this.transformRichtext(node.content[i], options, node.content[i + 1]);
1047
+ }
1048
+ }
1049
+ return start + content + end;
1050
+ }
1051
+ }
1052
+ //# sourceMappingURL=richtext.js.map