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

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 (550) hide show
  1. package/dist/bibliography/common.d.ts +9 -91
  2. package/dist/bibliography/common.d.ts.map +1 -1
  3. package/dist/bibliography/common.js +3 -2
  4. package/dist/bibliography/common.js.map +1 -1
  5. package/dist/bibliography/csl_bib.d.ts +1 -1
  6. package/dist/bibliography/csl_bib.d.ts.map +1 -1
  7. package/dist/bibliography/csl_bib.js +7 -7
  8. package/dist/bibliography/csl_bib.js.map +1 -1
  9. package/dist/citations/citeproc_sys.d.ts +9 -10
  10. package/dist/citations/citeproc_sys.d.ts.map +1 -1
  11. package/dist/citations/citeproc_sys.js +6 -1
  12. package/dist/citations/citeproc_sys.js.map +1 -1
  13. package/dist/citations/format.d.ts +33 -16
  14. package/dist/citations/format.d.ts.map +1 -1
  15. package/dist/citations/format.js +29 -4
  16. package/dist/citations/format.js.map +1 -1
  17. package/dist/editor/e2ee/encryptor.d.ts +35 -35
  18. package/dist/editor/e2ee/encryptor.d.ts.map +1 -1
  19. package/dist/editor/e2ee/encryptor.js +31 -31
  20. package/dist/editor/e2ee/encryptor.js.map +1 -1
  21. package/dist/exporter/docx/citations.d.ts +27 -17
  22. package/dist/exporter/docx/citations.d.ts.map +1 -1
  23. package/dist/exporter/docx/citations.js +24 -7
  24. package/dist/exporter/docx/citations.js.map +1 -1
  25. package/dist/exporter/docx/comments.d.ts +15 -11
  26. package/dist/exporter/docx/comments.d.ts.map +1 -1
  27. package/dist/exporter/docx/comments.js +47 -14
  28. package/dist/exporter/docx/comments.js.map +1 -1
  29. package/dist/exporter/docx/footnotes.d.ts +36 -31
  30. package/dist/exporter/docx/footnotes.d.ts.map +1 -1
  31. package/dist/exporter/docx/footnotes.js +46 -12
  32. package/dist/exporter/docx/footnotes.js.map +1 -1
  33. package/dist/exporter/docx/images.d.ts +23 -12
  34. package/dist/exporter/docx/images.d.ts.map +1 -1
  35. package/dist/exporter/docx/images.js +35 -20
  36. package/dist/exporter/docx/images.js.map +1 -1
  37. package/dist/exporter/docx/index.d.ts +11 -17
  38. package/dist/exporter/docx/index.d.ts.map +1 -1
  39. package/dist/exporter/docx/index.js +15 -7
  40. package/dist/exporter/docx/index.js.map +1 -1
  41. package/dist/exporter/docx/lists.d.ts +27 -22
  42. package/dist/exporter/docx/lists.d.ts.map +1 -1
  43. package/dist/exporter/docx/lists.js +77 -30
  44. package/dist/exporter/docx/lists.js.map +1 -1
  45. package/dist/exporter/docx/math.d.ts +9 -9
  46. package/dist/exporter/docx/math.d.ts.map +1 -1
  47. package/dist/exporter/docx/math.js +22 -5
  48. package/dist/exporter/docx/math.js.map +1 -1
  49. package/dist/exporter/docx/metadata.d.ts +12 -9
  50. package/dist/exporter/docx/metadata.d.ts.map +1 -1
  51. package/dist/exporter/docx/metadata.js +59 -26
  52. package/dist/exporter/docx/metadata.js.map +1 -1
  53. package/dist/exporter/docx/rels.d.ts +14 -12
  54. package/dist/exporter/docx/rels.d.ts.map +1 -1
  55. package/dist/exporter/docx/rels.js +37 -22
  56. package/dist/exporter/docx/rels.js.map +1 -1
  57. package/dist/exporter/docx/render.d.ts +17 -15
  58. package/dist/exporter/docx/render.d.ts.map +1 -1
  59. package/dist/exporter/docx/render.js +37 -31
  60. package/dist/exporter/docx/render.js.map +1 -1
  61. package/dist/exporter/docx/richtext.d.ts +8 -8
  62. package/dist/exporter/docx/richtext.d.ts.map +1 -1
  63. package/dist/exporter/docx/richtext.js +61 -43
  64. package/dist/exporter/docx/richtext.js.map +1 -1
  65. package/dist/exporter/docx/tables.d.ts +11 -9
  66. package/dist/exporter/docx/tables.d.ts.map +1 -1
  67. package/dist/exporter/docx/tables.js +16 -10
  68. package/dist/exporter/docx/tables.js.map +1 -1
  69. package/dist/exporter/docx/tools.d.ts +3 -2
  70. package/dist/exporter/docx/tools.d.ts.map +1 -1
  71. package/dist/exporter/docx/tools.js +3 -3
  72. package/dist/exporter/docx/tools.js.map +1 -1
  73. package/dist/exporter/epub/index.d.ts +11 -3
  74. package/dist/exporter/epub/index.d.ts.map +1 -1
  75. package/dist/exporter/epub/index.js +10 -3
  76. package/dist/exporter/epub/index.js.map +1 -1
  77. package/dist/exporter/epub/templates.d.ts +62 -31
  78. package/dist/exporter/epub/templates.d.ts.map +1 -1
  79. package/dist/exporter/epub/templates.js +1 -1
  80. package/dist/exporter/epub/templates.js.map +1 -1
  81. package/dist/exporter/epub/tools.d.ts +12 -4
  82. package/dist/exporter/epub/tools.d.ts.map +1 -1
  83. package/dist/exporter/epub/tools.js +14 -13
  84. package/dist/exporter/epub/tools.js.map +1 -1
  85. package/dist/exporter/html/citations.d.ts +17 -15
  86. package/dist/exporter/html/citations.d.ts.map +1 -1
  87. package/dist/exporter/html/citations.js +37 -18
  88. package/dist/exporter/html/citations.js.map +1 -1
  89. package/dist/exporter/html/convert.d.ts +20 -70
  90. package/dist/exporter/html/convert.d.ts.map +1 -1
  91. package/dist/exporter/html/convert.js +74 -42
  92. package/dist/exporter/html/convert.js.map +1 -1
  93. package/dist/exporter/html/index.d.ts +55 -52
  94. package/dist/exporter/html/index.d.ts.map +1 -1
  95. package/dist/exporter/html/index.js +23 -3
  96. package/dist/exporter/html/index.js.map +1 -1
  97. package/dist/exporter/html/templates.d.ts +23 -9
  98. package/dist/exporter/html/templates.d.ts.map +1 -1
  99. package/dist/exporter/html/templates.js +1 -1
  100. package/dist/exporter/html/templates.js.map +1 -1
  101. package/dist/exporter/html/tools.d.ts +1 -1
  102. package/dist/exporter/html/tools.d.ts.map +1 -1
  103. package/dist/exporter/html/tools.js +2 -2
  104. package/dist/exporter/html/tools.js.map +1 -1
  105. package/dist/exporter/jats/bibliography.d.ts +2 -1
  106. package/dist/exporter/jats/bibliography.d.ts.map +1 -1
  107. package/dist/exporter/jats/bibliography.js +57 -52
  108. package/dist/exporter/jats/bibliography.js.map +1 -1
  109. package/dist/exporter/jats/citations.d.ts +13 -11
  110. package/dist/exporter/jats/citations.d.ts.map +1 -1
  111. package/dist/exporter/jats/citations.js +28 -6
  112. package/dist/exporter/jats/citations.js.map +1 -1
  113. package/dist/exporter/jats/convert.d.ts +24 -28
  114. package/dist/exporter/jats/convert.d.ts.map +1 -1
  115. package/dist/exporter/jats/convert.js +53 -36
  116. package/dist/exporter/jats/convert.js.map +1 -1
  117. package/dist/exporter/jats/index.d.ts +21 -15
  118. package/dist/exporter/jats/index.d.ts.map +1 -1
  119. package/dist/exporter/jats/index.js +21 -5
  120. package/dist/exporter/jats/index.js.map +1 -1
  121. package/dist/exporter/jats/templates.d.ts +17 -15
  122. package/dist/exporter/jats/templates.d.ts.map +1 -1
  123. package/dist/exporter/jats/templates.js.map +1 -1
  124. package/dist/exporter/jats/text.d.ts +3 -2
  125. package/dist/exporter/jats/text.d.ts.map +1 -1
  126. package/dist/exporter/jats/text.js +4 -4
  127. package/dist/exporter/jats/text.js.map +1 -1
  128. package/dist/exporter/latex/convert.d.ts +12 -15
  129. package/dist/exporter/latex/convert.d.ts.map +1 -1
  130. package/dist/exporter/latex/convert.js +70 -54
  131. package/dist/exporter/latex/convert.js.map +1 -1
  132. package/dist/exporter/latex/escape_latex.d.ts +1 -1
  133. package/dist/exporter/latex/escape_latex.d.ts.map +1 -1
  134. package/dist/exporter/latex/escape_latex.js +1 -1
  135. package/dist/exporter/latex/escape_latex.js.map +1 -1
  136. package/dist/exporter/latex/index.d.ts +20 -19
  137. package/dist/exporter/latex/index.d.ts.map +1 -1
  138. package/dist/exporter/latex/index.js +15 -5
  139. package/dist/exporter/latex/index.js.map +1 -1
  140. package/dist/exporter/latex/readme.d.ts +1 -1
  141. package/dist/exporter/latex/readme.d.ts.map +1 -1
  142. package/dist/exporter/latex/readme.js +2 -2
  143. package/dist/exporter/latex/readme.js.map +1 -1
  144. package/dist/exporter/native/copy.d.ts +30 -0
  145. package/dist/exporter/native/copy.d.ts.map +1 -0
  146. package/dist/exporter/native/copy.js +151 -0
  147. package/dist/exporter/native/copy.js.map +1 -0
  148. package/dist/exporter/native/file.d.ts +12 -0
  149. package/dist/exporter/native/file.d.ts.map +1 -0
  150. package/dist/exporter/native/file.js +38 -0
  151. package/dist/exporter/native/file.js.map +1 -0
  152. package/dist/exporter/native/index.d.ts +5 -0
  153. package/dist/exporter/native/index.d.ts.map +1 -0
  154. package/dist/exporter/native/index.js +5 -0
  155. package/dist/exporter/native/index.js.map +1 -0
  156. package/dist/exporter/native/revision.d.ts +18 -0
  157. package/dist/exporter/native/revision.d.ts.map +1 -0
  158. package/dist/exporter/native/revision.js +39 -0
  159. package/dist/exporter/native/revision.js.map +1 -0
  160. package/dist/exporter/native/shrink.d.ts +29 -14
  161. package/dist/exporter/native/shrink.d.ts.map +1 -1
  162. package/dist/exporter/native/shrink.js +27 -18
  163. package/dist/exporter/native/shrink.js.map +1 -1
  164. package/dist/exporter/native/zip.d.ts +25 -0
  165. package/dist/exporter/native/zip.d.ts.map +1 -0
  166. package/dist/exporter/native/zip.js +56 -0
  167. package/dist/exporter/native/zip.js.map +1 -0
  168. package/dist/exporter/odt/citations.d.ts +18 -15
  169. package/dist/exporter/odt/citations.d.ts.map +1 -1
  170. package/dist/exporter/odt/citations.js +21 -4
  171. package/dist/exporter/odt/citations.js.map +1 -1
  172. package/dist/exporter/odt/footnotes.d.ts +25 -19
  173. package/dist/exporter/odt/footnotes.d.ts.map +1 -1
  174. package/dist/exporter/odt/footnotes.js +23 -6
  175. package/dist/exporter/odt/footnotes.js.map +1 -1
  176. package/dist/exporter/odt/images.d.ts +23 -11
  177. package/dist/exporter/odt/images.d.ts.map +1 -1
  178. package/dist/exporter/odt/images.js +34 -26
  179. package/dist/exporter/odt/images.js.map +1 -1
  180. package/dist/exporter/odt/index.d.ts +12 -18
  181. package/dist/exporter/odt/index.d.ts.map +1 -1
  182. package/dist/exporter/odt/index.js +16 -7
  183. package/dist/exporter/odt/index.js.map +1 -1
  184. package/dist/exporter/odt/math.d.ts +10 -8
  185. package/dist/exporter/odt/math.d.ts.map +1 -1
  186. package/dist/exporter/odt/math.js +27 -4
  187. package/dist/exporter/odt/math.js.map +1 -1
  188. package/dist/exporter/odt/metadata.d.ts +13 -9
  189. package/dist/exporter/odt/metadata.d.ts.map +1 -1
  190. package/dist/exporter/odt/metadata.js +36 -15
  191. package/dist/exporter/odt/metadata.js.map +1 -1
  192. package/dist/exporter/odt/render.d.ts +17 -15
  193. package/dist/exporter/odt/render.d.ts.map +1 -1
  194. package/dist/exporter/odt/render.js +25 -18
  195. package/dist/exporter/odt/render.js.map +1 -1
  196. package/dist/exporter/odt/richtext.d.ts +9 -9
  197. package/dist/exporter/odt/richtext.d.ts.map +1 -1
  198. package/dist/exporter/odt/richtext.js +55 -40
  199. package/dist/exporter/odt/richtext.js.map +1 -1
  200. package/dist/exporter/odt/styles.d.ts +29 -21
  201. package/dist/exporter/odt/styles.d.ts.map +1 -1
  202. package/dist/exporter/odt/styles.js +44 -22
  203. package/dist/exporter/odt/styles.js.map +1 -1
  204. package/dist/exporter/odt/track.d.ts +14 -7
  205. package/dist/exporter/odt/track.d.ts.map +1 -1
  206. package/dist/exporter/odt/track.js +7 -0
  207. package/dist/exporter/odt/track.js.map +1 -1
  208. package/dist/exporter/pandoc/citations.d.ts +20 -14
  209. package/dist/exporter/pandoc/citations.d.ts.map +1 -1
  210. package/dist/exporter/pandoc/citations.js +18 -4
  211. package/dist/exporter/pandoc/citations.js.map +1 -1
  212. package/dist/exporter/pandoc/convert.d.ts +10 -29
  213. package/dist/exporter/pandoc/convert.d.ts.map +1 -1
  214. package/dist/exporter/pandoc/convert.js +45 -40
  215. package/dist/exporter/pandoc/convert.js.map +1 -1
  216. package/dist/exporter/pandoc/index.d.ts +20 -33
  217. package/dist/exporter/pandoc/index.d.ts.map +1 -1
  218. package/dist/exporter/pandoc/index.js +20 -8
  219. package/dist/exporter/pandoc/index.js.map +1 -1
  220. package/dist/exporter/pandoc/readme.d.ts +1 -1
  221. package/dist/exporter/pandoc/readme.d.ts.map +1 -1
  222. package/dist/exporter/pandoc/readme.js +0 -1
  223. package/dist/exporter/pandoc/readme.js.map +1 -1
  224. package/dist/exporter/pandoc/tools.d.ts +21 -5
  225. package/dist/exporter/pandoc/tools.d.ts.map +1 -1
  226. package/dist/exporter/pandoc/tools.js +2 -2
  227. package/dist/exporter/pandoc/tools.js.map +1 -1
  228. package/dist/exporter/print/index.d.ts +18 -7
  229. package/dist/exporter/print/index.d.ts.map +1 -1
  230. package/dist/exporter/print/index.js +12 -10
  231. package/dist/exporter/print/index.js.map +1 -1
  232. package/dist/exporter/tools/doc_content.d.ts +5 -6
  233. package/dist/exporter/tools/doc_content.d.ts.map +1 -1
  234. package/dist/exporter/tools/doc_content.js +17 -16
  235. package/dist/exporter/tools/doc_content.js.map +1 -1
  236. package/dist/exporter/tools/svg.d.ts +7 -1
  237. package/dist/exporter/tools/svg.d.ts.map +1 -1
  238. package/dist/exporter/tools/svg.js.map +1 -1
  239. package/dist/exporter/tools/xml.d.ts +39 -38
  240. package/dist/exporter/tools/xml.d.ts.map +1 -1
  241. package/dist/exporter/tools/xml.js +82 -55
  242. package/dist/exporter/tools/xml.js.map +1 -1
  243. package/dist/exporter/tools/xml_zip.d.ts +15 -14
  244. package/dist/exporter/tools/xml_zip.d.ts.map +1 -1
  245. package/dist/exporter/tools/xml_zip.js +8 -2
  246. package/dist/exporter/tools/xml_zip.js.map +1 -1
  247. package/dist/exporter/tools/zip.d.ts +28 -14
  248. package/dist/exporter/tools/zip.d.ts.map +1 -1
  249. package/dist/exporter/tools/zip.js +13 -6
  250. package/dist/exporter/tools/zip.js.map +1 -1
  251. package/dist/exporter/tools/zotero_csl.d.ts +19 -6
  252. package/dist/exporter/tools/zotero_csl.d.ts.map +1 -1
  253. package/dist/exporter/tools/zotero_csl.js +9 -9
  254. package/dist/exporter/tools/zotero_csl.js.map +1 -1
  255. package/dist/importer/citations.d.ts +25 -22
  256. package/dist/importer/citations.d.ts.map +1 -1
  257. package/dist/importer/citations.js +1 -49
  258. package/dist/importer/citations.js.map +1 -1
  259. package/dist/importer/docx/citations.d.ts +8 -30
  260. package/dist/importer/docx/citations.d.ts.map +1 -1
  261. package/dist/importer/docx/citations.js +1 -26
  262. package/dist/importer/docx/citations.js.map +1 -1
  263. package/dist/importer/docx/convert.d.ts +38 -116
  264. package/dist/importer/docx/convert.d.ts.map +1 -1
  265. package/dist/importer/docx/convert.js +99 -82
  266. package/dist/importer/docx/convert.js.map +1 -1
  267. package/dist/importer/docx/helpers.d.ts +1 -1
  268. package/dist/importer/docx/helpers.d.ts.map +1 -1
  269. package/dist/importer/docx/helpers.js +1 -1
  270. package/dist/importer/docx/helpers.js.map +1 -1
  271. package/dist/importer/docx/index.d.ts +27 -0
  272. package/dist/importer/docx/index.d.ts.map +1 -0
  273. package/dist/importer/docx/index.js +77 -0
  274. package/dist/importer/docx/index.js.map +1 -0
  275. package/dist/importer/docx/omml2mathml.d.ts +2 -3
  276. package/dist/importer/docx/omml2mathml.d.ts.map +1 -1
  277. package/dist/importer/docx/omml2mathml.js +23 -116
  278. package/dist/importer/docx/omml2mathml.js.map +1 -1
  279. package/dist/importer/docx/parse.d.ts +22 -131
  280. package/dist/importer/docx/parse.d.ts.map +1 -1
  281. package/dist/importer/docx/parse.js +73 -55
  282. package/dist/importer/docx/parse.js.map +1 -1
  283. package/dist/importer/native/extract_template.d.ts +6 -0
  284. package/dist/importer/native/extract_template.d.ts.map +1 -0
  285. package/dist/importer/native/extract_template.js +80 -0
  286. package/dist/importer/native/extract_template.js.map +1 -0
  287. package/dist/importer/native/file.d.ts +37 -0
  288. package/dist/importer/native/file.d.ts.map +1 -0
  289. package/dist/importer/native/file.js +162 -0
  290. package/dist/importer/native/file.js.map +1 -0
  291. package/dist/importer/native/get_images.d.ts +18 -8
  292. package/dist/importer/native/get_images.d.ts.map +1 -1
  293. package/dist/importer/native/get_images.js +39 -45
  294. package/dist/importer/native/get_images.js.map +1 -1
  295. package/dist/importer/native/importer.d.ts +41 -0
  296. package/dist/importer/native/importer.d.ts.map +1 -0
  297. package/dist/importer/native/importer.js +170 -0
  298. package/dist/importer/native/importer.js.map +1 -0
  299. package/dist/importer/native/index.d.ts +7 -0
  300. package/dist/importer/native/index.d.ts.map +1 -0
  301. package/dist/importer/native/index.js +7 -0
  302. package/dist/importer/native/index.js.map +1 -0
  303. package/dist/importer/native/update.d.ts +5 -4
  304. package/dist/importer/native/update.d.ts.map +1 -1
  305. package/dist/importer/native/update.js +4 -3
  306. package/dist/importer/native/update.js.map +1 -1
  307. package/dist/importer/native/update_template.d.ts +12 -0
  308. package/dist/importer/native/update_template.d.ts.map +1 -0
  309. package/dist/importer/native/update_template.js +19 -0
  310. package/dist/importer/native/update_template.js.map +1 -0
  311. package/dist/importer/odt/citations.d.ts +7 -27
  312. package/dist/importer/odt/citations.d.ts.map +1 -1
  313. package/dist/importer/odt/citations.js +0 -22
  314. package/dist/importer/odt/citations.js.map +1 -1
  315. package/dist/importer/odt/convert.d.ts +53 -237
  316. package/dist/importer/odt/convert.d.ts.map +1 -1
  317. package/dist/importer/odt/convert.js +162 -138
  318. package/dist/importer/odt/convert.js.map +1 -1
  319. package/dist/importer/odt/index.d.ts +30 -0
  320. package/dist/importer/odt/index.d.ts.map +1 -0
  321. package/dist/importer/odt/index.js +124 -0
  322. package/dist/importer/odt/index.js.map +1 -0
  323. package/dist/importer/pandoc/convert.d.ts +25 -77
  324. package/dist/importer/pandoc/convert.d.ts.map +1 -1
  325. package/dist/importer/pandoc/convert.js +65 -52
  326. package/dist/importer/pandoc/convert.js.map +1 -1
  327. package/dist/importer/pandoc/helpers.d.ts +4 -3
  328. package/dist/importer/pandoc/helpers.d.ts.map +1 -1
  329. package/dist/importer/pandoc/helpers.js +24 -26
  330. package/dist/importer/pandoc/helpers.js.map +1 -1
  331. package/dist/importer/pandoc/index.d.ts +31 -0
  332. package/dist/importer/pandoc/index.d.ts.map +1 -0
  333. package/dist/importer/pandoc/index.js +114 -0
  334. package/dist/importer/pandoc/index.js.map +1 -0
  335. package/dist/importer/registry.d.ts +21 -0
  336. package/dist/importer/registry.d.ts.map +1 -0
  337. package/dist/importer/registry.js +41 -0
  338. package/dist/importer/registry.js.map +1 -0
  339. package/dist/importer/zip_analyzer.d.ts +27 -21
  340. package/dist/importer/zip_analyzer.d.ts.map +1 -1
  341. package/dist/importer/zip_analyzer.js +10 -5
  342. package/dist/importer/zip_analyzer.js.map +1 -1
  343. package/dist/mathlive/opf_includes.d.ts +1 -1
  344. package/dist/mathlive/opf_includes.d.ts.map +1 -1
  345. package/dist/mathlive/opf_includes.js.map +1 -1
  346. package/dist/schema/common/annotate.d.ts +37 -49
  347. package/dist/schema/common/annotate.d.ts.map +1 -1
  348. package/dist/schema/common/annotate.js +2 -2
  349. package/dist/schema/common/annotate.js.map +1 -1
  350. package/dist/schema/common/base.d.ts +63 -81
  351. package/dist/schema/common/base.d.ts.map +1 -1
  352. package/dist/schema/common/base.js.map +1 -1
  353. package/dist/schema/common/citation.d.ts +23 -22
  354. package/dist/schema/common/citation.d.ts.map +1 -1
  355. package/dist/schema/common/citation.js +4 -5
  356. package/dist/schema/common/citation.js.map +1 -1
  357. package/dist/schema/common/equation.d.ts +13 -14
  358. package/dist/schema/common/equation.d.ts.map +1 -1
  359. package/dist/schema/common/equation.js +1 -1
  360. package/dist/schema/common/equation.js.map +1 -1
  361. package/dist/schema/common/figure.d.ts +72 -93
  362. package/dist/schema/common/figure.d.ts.map +1 -1
  363. package/dist/schema/common/figure.js +11 -9
  364. package/dist/schema/common/figure.js.map +1 -1
  365. package/dist/schema/common/heading.d.ts +8 -32
  366. package/dist/schema/common/heading.d.ts.map +1 -1
  367. package/dist/schema/common/heading.js +2 -2
  368. package/dist/schema/common/heading.js.map +1 -1
  369. package/dist/schema/common/index.d.ts +2 -2
  370. package/dist/schema/common/index.d.ts.map +1 -1
  371. package/dist/schema/common/index.js.map +1 -1
  372. package/dist/schema/common/list.d.ts +52 -72
  373. package/dist/schema/common/list.d.ts.map +1 -1
  374. package/dist/schema/common/list.js +3 -3
  375. package/dist/schema/common/list.js.map +1 -1
  376. package/dist/schema/common/reference.d.ts +51 -59
  377. package/dist/schema/common/reference.d.ts.map +1 -1
  378. package/dist/schema/common/reference.js +5 -5
  379. package/dist/schema/common/reference.js.map +1 -1
  380. package/dist/schema/common/table.d.ts +59 -75
  381. package/dist/schema/common/table.d.ts.map +1 -1
  382. package/dist/schema/common/table.js +3 -2
  383. package/dist/schema/common/table.js.map +1 -1
  384. package/dist/schema/common/track.d.ts +83 -97
  385. package/dist/schema/common/track.d.ts.map +1 -1
  386. package/dist/schema/common/track.js +18 -17
  387. package/dist/schema/common/track.js.map +1 -1
  388. package/dist/schema/convert.d.ts +2 -2
  389. package/dist/schema/convert.d.ts.map +1 -1
  390. package/dist/schema/convert.js +2 -2
  391. package/dist/schema/convert.js.map +1 -1
  392. package/dist/schema/document/content.d.ts +95 -122
  393. package/dist/schema/document/content.d.ts.map +1 -1
  394. package/dist/schema/document/content.js +9 -9
  395. package/dist/schema/document/content.js.map +1 -1
  396. package/dist/schema/document/index.d.ts +173 -257
  397. package/dist/schema/document/index.d.ts.map +1 -1
  398. package/dist/schema/document/index.js.map +1 -1
  399. package/dist/schema/document/structure.d.ts +149 -258
  400. package/dist/schema/document/structure.d.ts.map +1 -1
  401. package/dist/schema/document/structure.js +2 -2
  402. package/dist/schema/document/structure.js.map +1 -1
  403. package/dist/schema/export.d.ts +4 -877
  404. package/dist/schema/export.d.ts.map +1 -1
  405. package/dist/schema/export.js +1 -0
  406. package/dist/schema/export.js.map +1 -1
  407. package/dist/schema/footnotes.d.ts +110 -155
  408. package/dist/schema/footnotes.d.ts.map +1 -1
  409. package/dist/schema/footnotes.js +4 -2
  410. package/dist/schema/footnotes.js.map +1 -1
  411. package/dist/schema/footnotes_convert.d.ts +3 -3
  412. package/dist/schema/footnotes_convert.d.ts.map +1 -1
  413. package/dist/schema/footnotes_convert.js +10 -6
  414. package/dist/schema/footnotes_convert.js.map +1 -1
  415. package/dist/schema/i18n.d.ts +3 -534
  416. package/dist/schema/i18n.d.ts.map +1 -1
  417. package/dist/schema/i18n.js +1 -0
  418. package/dist/schema/i18n.js.map +1 -1
  419. package/dist/schema/index.d.ts +1 -1
  420. package/dist/schema/index.d.ts.map +1 -1
  421. package/dist/schema/index.js.map +1 -1
  422. package/dist/schema/mini_json.d.ts +3 -4
  423. package/dist/schema/mini_json.d.ts.map +1 -1
  424. package/dist/schema/mini_json.js +2 -0
  425. package/dist/schema/mini_json.js.map +1 -1
  426. package/dist/schema/text.d.ts +2 -1
  427. package/dist/schema/text.d.ts.map +1 -1
  428. package/dist/schema/text.js +1 -1
  429. package/dist/schema/text.js.map +1 -1
  430. package/dist/types.d.ts +167 -8
  431. package/dist/types.d.ts.map +1 -1
  432. package/package.json +4 -1
  433. package/src/bibliography/{common.js → common.ts} +15 -12
  434. package/src/bibliography/{csl_bib.js → csl_bib.ts} +16 -15
  435. package/src/citations/{citeproc_sys.js → citeproc_sys.ts} +26 -6
  436. package/src/citations/{format.js → format.ts} +80 -24
  437. package/src/editor/e2ee/{encryptor.js → encryptor.ts} +76 -44
  438. package/src/exporter/docx/{citations.js → citations.ts} +51 -23
  439. package/src/exporter/docx/{comments.js → comments.ts} +69 -26
  440. package/src/exporter/docx/{footnotes.js → footnotes.ts} +81 -42
  441. package/src/exporter/docx/images.ts +128 -0
  442. package/src/exporter/docx/{index.js → index.ts} +48 -25
  443. package/src/exporter/docx/{lists.js → lists.ts} +89 -46
  444. package/src/exporter/docx/{math.js → math.ts} +29 -9
  445. package/src/exporter/docx/{metadata.js → metadata.ts} +78 -42
  446. package/src/exporter/docx/{rels.js → rels.ts} +71 -50
  447. package/src/exporter/docx/{render.js → render.ts} +124 -87
  448. package/src/exporter/docx/{richtext.js → richtext.ts} +107 -84
  449. package/src/exporter/docx/{tables.js → tables.ts} +33 -23
  450. package/src/exporter/docx/{tools.js → tools.ts} +4 -3
  451. package/src/exporter/epub/{index.js → index.ts} +44 -15
  452. package/src/exporter/epub/{templates.js → templates.ts} +71 -7
  453. package/src/exporter/epub/{tools.js → tools.ts} +31 -25
  454. package/src/exporter/html/{citations.js → citations.ts} +79 -31
  455. package/src/exporter/html/{convert.js → convert.ts} +118 -71
  456. package/src/exporter/html/{index.js → index.ts} +63 -29
  457. package/src/exporter/html/{templates.js → templates.ts} +22 -2
  458. package/src/exporter/html/{tools.js → tools.ts} +9 -6
  459. package/src/exporter/jats/bibliography.ts +199 -0
  460. package/src/exporter/jats/{citations.js → citations.ts} +56 -20
  461. package/src/exporter/jats/{convert.js → convert.ts} +72 -53
  462. package/src/exporter/jats/index.ts +132 -0
  463. package/src/exporter/jats/{templates.js → templates.ts} +19 -3
  464. package/src/exporter/jats/{text.js → text.ts} +8 -6
  465. package/src/exporter/latex/{convert.js → convert.ts} +160 -125
  466. package/src/exporter/latex/{escape_latex.js → escape_latex.ts} +1 -1
  467. package/src/exporter/latex/{index.js → index.ts} +27 -12
  468. package/src/exporter/latex/{readme.js → readme.ts} +2 -2
  469. package/src/exporter/native/copy.ts +231 -0
  470. package/src/exporter/native/file.ts +65 -0
  471. package/src/exporter/native/index.ts +4 -0
  472. package/src/exporter/native/revision.ts +76 -0
  473. package/src/exporter/native/{shrink.js → shrink.ts} +64 -29
  474. package/src/exporter/native/zip.ts +85 -0
  475. package/src/exporter/odt/{citations.js → citations.ts} +35 -15
  476. package/src/exporter/odt/{footnotes.js → footnotes.ts} +53 -30
  477. package/src/exporter/odt/images.ts +135 -0
  478. package/src/exporter/odt/{index.js → index.ts} +49 -27
  479. package/src/exporter/odt/{math.js → math.ts} +38 -9
  480. package/src/exporter/odt/{metadata.js → metadata.ts} +54 -29
  481. package/src/exporter/odt/{render.js → render.ts} +89 -60
  482. package/src/exporter/odt/{richtext.js → richtext.ts} +102 -72
  483. package/src/exporter/odt/{styles.js → styles.ts} +98 -66
  484. package/src/exporter/odt/{track.js → track.ts} +22 -6
  485. package/src/exporter/pandoc/{citations.js → citations.ts} +31 -15
  486. package/src/exporter/pandoc/{convert.js → convert.ts} +98 -79
  487. package/src/exporter/pandoc/{index.js → index.ts} +36 -13
  488. package/src/exporter/pandoc/{readme.js → readme.ts} +0 -1
  489. package/src/exporter/pandoc/{tools.js → tools.ts} +28 -5
  490. package/src/exporter/print/{index.js → index.ts} +38 -19
  491. package/src/exporter/tools/{doc_content.js → doc_content.ts} +34 -24
  492. package/src/exporter/tools/{svg.js → svg.ts} +9 -3
  493. package/src/exporter/tools/{xml.js → xml.ts} +187 -138
  494. package/src/exporter/tools/{xml_zip.js → xml_zip.ts} +19 -11
  495. package/src/exporter/tools/{zip.js → zip.ts} +35 -11
  496. package/src/exporter/tools/{zotero_csl.js → zotero_csl.ts} +35 -18
  497. package/src/global.d.ts +2 -0
  498. package/src/importer/citations.ts +116 -0
  499. package/src/importer/docx/{citations.js → citations.ts} +22 -37
  500. package/src/importer/docx/{convert.js → convert.ts} +176 -141
  501. package/src/importer/docx/{helpers.js → helpers.ts} +1 -1
  502. package/src/importer/docx/index.ts +124 -0
  503. package/src/importer/docx/{omml2mathml.js → omml2mathml.ts} +154 -176
  504. package/src/importer/docx/{parse.js → parse.ts} +103 -81
  505. package/src/importer/native/extract_template.ts +83 -0
  506. package/src/importer/native/file.ts +282 -0
  507. package/src/importer/native/get_images.ts +82 -0
  508. package/src/importer/native/importer.ts +244 -0
  509. package/src/importer/native/index.ts +6 -0
  510. package/src/importer/native/{update.js → update.ts} +13 -5
  511. package/src/importer/native/update_template.ts +32 -0
  512. package/src/importer/odt/{citations.js → citations.ts} +17 -29
  513. package/src/importer/odt/{convert.js → convert.ts} +261 -237
  514. package/src/importer/odt/index.ts +202 -0
  515. package/src/importer/pandoc/{convert.js → convert.ts} +116 -94
  516. package/src/importer/pandoc/{helpers.js → helpers.ts} +24 -12
  517. package/src/importer/pandoc/index.ts +171 -0
  518. package/src/importer/registry.ts +69 -0
  519. package/src/importer/{zip_analyzer.js → zip_analyzer.ts} +44 -18
  520. package/src/mathlive/{opf_includes.js → opf_includes.ts} +1 -1
  521. package/src/modules.d.ts +40 -0
  522. package/src/schema/common/{annotate.js → annotate.ts} +10 -8
  523. package/src/schema/common/{base.js → base.ts} +12 -10
  524. package/src/schema/common/{citation.js → citation.ts} +17 -8
  525. package/src/schema/common/{equation.js → equation.ts} +6 -4
  526. package/src/schema/common/{figure.js → figure.ts} +43 -23
  527. package/src/schema/common/{heading.js → heading.ts} +7 -5
  528. package/src/schema/common/{list.js → list.ts} +15 -13
  529. package/src/schema/common/{reference.js → reference.ts} +14 -12
  530. package/src/schema/common/{table.js → table.ts} +16 -14
  531. package/src/schema/common/{track.js → track.ts} +42 -31
  532. package/src/schema/{convert.js → convert.ts} +6 -2
  533. package/src/schema/document/{content.js → content.ts} +22 -20
  534. package/src/schema/document/{structure.js → structure.ts} +15 -9
  535. package/src/schema/{export.js → export.ts} +4 -2
  536. package/src/schema/{footnotes.js → footnotes.ts} +11 -8
  537. package/src/schema/{footnotes_convert.js → footnotes_convert.ts} +11 -8
  538. package/src/schema/{i18n.js → i18n.ts} +7 -1
  539. package/src/schema/{mini_json.js → mini_json.ts} +11 -12
  540. package/src/schema/{text.js → text.ts} +6 -2
  541. package/src/types.ts +185 -7
  542. package/src/exporter/docx/images.js +0 -101
  543. package/src/exporter/jats/bibliography.js +0 -183
  544. package/src/exporter/jats/index.js +0 -92
  545. package/src/exporter/odt/images.js +0 -115
  546. package/src/importer/citations.js +0 -129
  547. package/src/importer/native/get_images.js +0 -76
  548. /package/src/schema/common/{index.js → index.ts} +0 -0
  549. /package/src/schema/document/{index.js → index.ts} +0 -0
  550. /package/src/schema/{index.js → index.ts} +0 -0
@@ -0,0 +1,282 @@
1
+ import {escapeText, gettext} from "fwtoolkit"
2
+
3
+ import {FW_DOCUMENT_VERSION} from "../../schema/index.js"
4
+ import {updateFile} from "./update.js"
5
+ import {updateTemplateFile} from "./update_template.js"
6
+ import {NativeImporter} from "./importer.js"
7
+
8
+ import type {
9
+ E2EEOptions,
10
+ FidusDoc,
11
+ FidusNode,
12
+ ImageDBEntries,
13
+ NativeImporterBackend,
14
+ Template,
15
+ User
16
+ } from "../../types.js"
17
+
18
+ export const MIN_FW_DOCUMENT_VERSION = 1.6
19
+ export const MAX_FW_DOCUMENT_VERSION = Number.parseFloat(FW_DOCUMENT_VERSION)
20
+
21
+ const TEXT_FILENAMES = [
22
+ "mimetype",
23
+ "filetype-version",
24
+ "document.json",
25
+ "images.json",
26
+ "bibliography.json"
27
+ ]
28
+
29
+ export interface FidusFileImporterOptions {
30
+ check?: boolean
31
+ contacts?: Array<Record<string, unknown>>
32
+ e2eeOptions?: E2EEOptions | null
33
+ checkDocUsers?: (
34
+ doc: Record<string, unknown>,
35
+ user: User,
36
+ contacts: Array<Record<string, unknown>>
37
+ ) => Record<string, unknown>
38
+ }
39
+
40
+ export class FidusFileImporter {
41
+ file: Blob
42
+ user: User
43
+ path: string
44
+ check: boolean
45
+ contacts: Array<Record<string, unknown>>
46
+ e2eeOptions: E2EEOptions | null
47
+ checkDocUsers?: (
48
+ doc: Record<string, unknown>,
49
+ user: User,
50
+ contacts: Array<Record<string, unknown>>
51
+ ) => Record<string, unknown>
52
+
53
+ textFiles: Array<{filename: string; content: string}> = []
54
+ otherFiles: Array<{filename: string; content: Blob | ArrayBuffer | string}> = []
55
+ ok = false
56
+ statusText = ""
57
+ doc: Record<string, unknown> | null = null
58
+ docInfo: Record<string, unknown> | null = null
59
+ template: Template | null = null
60
+
61
+ backend: NativeImporterBackend
62
+
63
+ constructor(
64
+ file: Blob,
65
+ user: User,
66
+ path: string,
67
+ backend: NativeImporterBackend,
68
+ options: FidusFileImporterOptions = {}
69
+ ) {
70
+ this.file = file
71
+ this.user = user
72
+ this.path = path
73
+ this.check = options.check ?? false
74
+ this.contacts = options.contacts || []
75
+ this.e2eeOptions = options.e2eeOptions ?? null
76
+ this.checkDocUsers = options.checkDocUsers
77
+ this.backend = backend
78
+ }
79
+
80
+ init(): Promise<this> {
81
+ if (!this.check) {
82
+ return this.initZipFileRead()
83
+ }
84
+ return new Promise(resolve => {
85
+ const reader = new FileReader()
86
+ reader.onloadend = () => {
87
+ const result = reader.result as string
88
+ if (
89
+ result.length > 60 &&
90
+ result.substring(0, 2) === "PK"
91
+ ) {
92
+ this.initZipFileRead().then(() => resolve(this))
93
+ } else {
94
+ this.statusText = gettext(
95
+ "The uploaded file does not appear to be a Fidus Writer file."
96
+ )
97
+ resolve(this)
98
+ }
99
+ }
100
+ reader.readAsText(this.file)
101
+ })
102
+ }
103
+
104
+ initZipFileRead(): Promise<this> {
105
+ return import("jszip")
106
+ .then(({default: JSZip}) => new JSZip())
107
+ .then(zipfs => zipfs.loadAsync(this.file))
108
+ .then(zipfs => {
109
+ const filenames: string[] = []
110
+ const p: Array<Promise<void>> = []
111
+ let validFile = true
112
+
113
+ zipfs.forEach(filename => filenames.push(filename))
114
+
115
+ TEXT_FILENAMES.forEach(filename => {
116
+ if (filenames.indexOf(filename) === -1) {
117
+ validFile = false
118
+ }
119
+ })
120
+ if (!validFile) {
121
+ this.statusText = gettext(
122
+ "The uploaded file does not appear to be a Fidus Writer file."
123
+ )
124
+ return this
125
+ }
126
+
127
+ filenames
128
+ .filter(filename => !filename.endsWith("/"))
129
+ .forEach(filename => {
130
+ p.push(
131
+ new Promise(resolve => {
132
+ const isText =
133
+ ["mimetype", "filetype-version"].includes(
134
+ filename
135
+ ) || filename.endsWith(".json")
136
+ zipfs.files[filename]
137
+ .async(isText ? "string" : "blob")
138
+ .then(content => {
139
+ if (isText) {
140
+ this.textFiles.push({
141
+ filename,
142
+ content: content as string
143
+ })
144
+ } else {
145
+ this.otherFiles.push({
146
+ filename,
147
+ content: content as Blob
148
+ })
149
+ }
150
+ resolve()
151
+ })
152
+ })
153
+ )
154
+ })
155
+ return Promise.all(p).then(() => this.processFidusFile())
156
+ })
157
+ }
158
+
159
+ processFidusFile(): Promise<this> {
160
+ const filetypeVersionFile = this.textFiles.find(
161
+ file => file.filename === "filetype-version"
162
+ ),
163
+ mimeTypeFile = this.textFiles.find(
164
+ file => file.filename === "mimetype"
165
+ )
166
+
167
+ if (!filetypeVersionFile || !mimeTypeFile) {
168
+ this.statusText = gettext(
169
+ "The uploaded file does not appear to be a Fidus Writer file."
170
+ )
171
+ return Promise.resolve(this)
172
+ }
173
+
174
+ const filetypeVersion = Number.parseFloat(filetypeVersionFile.content),
175
+ mimeType = mimeTypeFile.content
176
+
177
+ if (
178
+ mimeType === "application/fidus+zip" &&
179
+ filetypeVersion >= MIN_FW_DOCUMENT_VERSION &&
180
+ filetypeVersion <= MAX_FW_DOCUMENT_VERSION
181
+ ) {
182
+ const documentFile = this.textFiles.find(
183
+ file => file.filename === "document.json"
184
+ ),
185
+ bibliographyFile = this.textFiles.find(
186
+ file => file.filename === "bibliography.json"
187
+ ),
188
+ imagesFile = this.textFiles.find(
189
+ file => file.filename === "images.json"
190
+ )
191
+
192
+ if (!documentFile || !bibliographyFile || !imagesFile) {
193
+ this.statusText = gettext(
194
+ "The uploaded file does not appear to be a Fidus Writer file."
195
+ )
196
+ return Promise.resolve(this)
197
+ }
198
+
199
+ const updatedFile = updateFile(
200
+ JSON.parse(documentFile.content) as FidusDoc,
201
+ filetypeVersion,
202
+ JSON.parse(bibliographyFile.content),
203
+ JSON.parse(imagesFile.content) as ImageDBEntries
204
+ ),
205
+ bibliography = updatedFile.bibliography,
206
+ images = updatedFile.images
207
+ let doc = updatedFile.doc as unknown as Record<string, unknown>
208
+ if (this.check && this.checkDocUsers) {
209
+ doc = this.checkDocUsers(doc, this.user, this.contacts)
210
+ }
211
+
212
+ const templateFiles = this.otherFiles.filter(
213
+ file =>
214
+ file.filename.startsWith("exporttemplates/") ||
215
+ file.filename.startsWith("documentstyles/")
216
+ )
217
+ this.otherFiles = this.otherFiles.filter(
218
+ file =>
219
+ !file.filename.startsWith("exporttemplates/") &&
220
+ !file.filename.startsWith("documentstyles/")
221
+ )
222
+
223
+ const templateFile = this.textFiles.find(
224
+ file => file.filename === "template.json"
225
+ )
226
+ if (templateFile) {
227
+ const exporttemplatesFile = this.textFiles.find(
228
+ file => file.filename === "exporttemplates.json"
229
+ ),
230
+ documentstylesFile = this.textFiles.find(
231
+ file => file.filename === "documentstyles.json"
232
+ )
233
+ if (!exporttemplatesFile || !documentstylesFile) {
234
+ this.statusText = gettext(
235
+ "The uploaded file does not appear to be a Fidus Writer file."
236
+ )
237
+ return Promise.resolve(this)
238
+ }
239
+ const templateDef = JSON.parse(templateFile.content)
240
+ this.template = updateTemplateFile(
241
+ templateDef.attrs.template,
242
+ templateDef,
243
+ JSON.parse(exporttemplatesFile.content),
244
+ JSON.parse(documentstylesFile.content),
245
+ filetypeVersion
246
+ ) as Template
247
+ this.template.files = templateFiles
248
+ }
249
+
250
+ const importer = new NativeImporter(
251
+ doc,
252
+ bibliography,
253
+ {db: images},
254
+ this.otherFiles,
255
+ this.user,
256
+ this.backend,
257
+ {
258
+ importId: null,
259
+ requestedPath: this.path.endsWith("/")
260
+ ? this.path + (doc.title as string)
261
+ : this.path,
262
+ template: this.template,
263
+ e2eeOptions: this.e2eeOptions
264
+ }
265
+ )
266
+ return importer.init().then(({doc: importedDoc, docInfo}) => {
267
+ this.ok = true
268
+ this.doc = importedDoc
269
+ this.docInfo = docInfo
270
+ this.statusText = `${escapeText(
271
+ importedDoc.title as string
272
+ )} ${gettext("successfully imported.")}`
273
+ return this
274
+ })
275
+ }
276
+ this.statusText =
277
+ gettext(
278
+ "The uploaded file does not appear to be of the version used on this server: "
279
+ ) + FW_DOCUMENT_VERSION
280
+ return Promise.resolve(this)
281
+ }
282
+ }
@@ -0,0 +1,82 @@
1
+ import {get} from "fwtoolkit"
2
+
3
+ import type {ImageDB, ImageDBEntry} from "../../types.js"
4
+
5
+ interface ZipEntry {
6
+ filename: string
7
+ content: Blob | ArrayBuffer | string
8
+ }
9
+
10
+ interface UrlEntry {
11
+ filename: string
12
+ url: string
13
+ }
14
+
15
+ export class GetImages {
16
+ images: ImageDB
17
+ imageEntries: ImageDBEntry[]
18
+ entries: Array<ZipEntry | UrlEntry>
19
+ counter: number
20
+
21
+ constructor(images: ImageDB, entries: Array<ZipEntry | UrlEntry>) {
22
+ this.images = images
23
+ this.imageEntries = Object.values(this.images.db)
24
+ this.entries = entries
25
+ this.counter = 0
26
+ }
27
+
28
+ async init(): Promise<void> {
29
+ if (this.entries.length === 0) {
30
+ return
31
+ }
32
+ if (this.entries[0].hasOwnProperty("url")) {
33
+ await this.getImageUrlEntry()
34
+ } else {
35
+ await this.getImageZipEntry()
36
+ }
37
+ }
38
+
39
+ async getImageZipEntry(): Promise<void> {
40
+ if (this.counter >= this.imageEntries.length) {
41
+ return
42
+ }
43
+ const imageEntry = this.imageEntries[this.counter]
44
+ const f = (this.entries as ZipEntry[]).find(
45
+ e => e.filename === imageEntry.image
46
+ )
47
+ if (!f) {
48
+ console.warn(
49
+ `Image ${imageEntry.image} not found`,
50
+ this.imageEntries,
51
+ this.entries
52
+ )
53
+ this.counter++
54
+ await this.getImageZipEntry()
55
+ return
56
+ }
57
+ this.imageEntries[this.counter]["file"] = new window.Blob([f.content], {
58
+ type: imageEntry.file_type
59
+ })
60
+ this.counter++
61
+ await this.getImageZipEntry()
62
+ }
63
+
64
+ async getImageUrlEntry(): Promise<void> {
65
+ if (this.counter >= this.imageEntries.length) {
66
+ return
67
+ }
68
+ const imageEntry = this.imageEntries[this.counter]
69
+ const entry = (this.entries as UrlEntry[]).find(
70
+ e =>
71
+ e.filename ===
72
+ `images/${String(imageEntry.image).split("/").pop()}`
73
+ )
74
+ if (!entry) {
75
+ return
76
+ }
77
+ const response = await get(entry.url)
78
+ this.imageEntries[this.counter]["file"] = await response.blob()
79
+ this.counter++
80
+ await this.getImageUrlEntry()
81
+ }
82
+ }
@@ -0,0 +1,244 @@
1
+ import {GetImages} from "./get_images.js"
2
+ import {extractTemplate} from "./extract_template.js"
3
+
4
+ import type {
5
+ BibDB,
6
+ E2EEOptions,
7
+ FidusNode,
8
+ ImageDB,
9
+ NativeImporterBackend,
10
+ Template,
11
+ User
12
+ } from "../../types.js"
13
+
14
+ interface NativeImporterOptions {
15
+ importId?: string | number | null
16
+ requestedPath?: string
17
+ template?: Template | null
18
+ e2eeOptions?: E2EEOptions | null
19
+ }
20
+
21
+ interface SaveDocumentResult {
22
+ added: number
23
+ updated: number
24
+ }
25
+
26
+ export class NativeImporter {
27
+ doc: Record<string, unknown>
28
+ docId: number
29
+ path: string
30
+ bibliography: Record<string, unknown>
31
+ images: ImageDB
32
+ otherFiles: Array<{filename: string; content: Blob | ArrayBuffer | string}>
33
+ user: User
34
+ importId: string | number | null
35
+ requestedPath: string
36
+ template: Template | null
37
+ e2eeOptions: E2EEOptions | null
38
+ backend: NativeImporterBackend
39
+
40
+ constructor(
41
+ doc: Record<string, unknown>,
42
+ bibliography: Record<string, unknown>,
43
+ images: ImageDB,
44
+ otherFiles: Array<{filename: string; content: Blob | ArrayBuffer | string}>,
45
+ user: User,
46
+ backend: NativeImporterBackend,
47
+ options: NativeImporterOptions = {}
48
+ ) {
49
+ this.doc = doc
50
+ this.docId = 0
51
+ this.path = ""
52
+ this.bibliography = bibliography
53
+ this.images = images
54
+ this.otherFiles = otherFiles
55
+ this.user = user
56
+ this.importId = options.importId ?? null
57
+ this.requestedPath = options.requestedPath || ""
58
+ this.template = options.template ?? null
59
+ this.e2eeOptions = options.e2eeOptions ?? null
60
+ this.backend = backend
61
+ }
62
+
63
+ init(): Promise<{doc: Record<string, unknown>; docInfo: Record<string, unknown>}> {
64
+ const imageGetter = new GetImages(this.images, this.otherFiles)
65
+ return imageGetter
66
+ .init()
67
+ .then(() => {
68
+ const missingImage = Object.values(this.images.db).find(
69
+ imageEntry => !imageEntry.file
70
+ )
71
+ if (missingImage) {
72
+ throw new Error(
73
+ `Could not create document. Missing image file: ${String(
74
+ missingImage.image
75
+ )}`
76
+ )
77
+ }
78
+ })
79
+ .then(() => this.createDoc())
80
+ .then(() => {
81
+ if (!this.docId) {
82
+ return Promise.reject(new Error("document not created"))
83
+ }
84
+ return this.saveImages()
85
+ })
86
+ .then((imageTranslationTable: Record<number | string, number>) => {
87
+ this.translateReferenceIds(imageTranslationTable)
88
+ return this.saveDocument()
89
+ })
90
+ }
91
+
92
+ createDoc(): Promise<void> {
93
+ const template = this.template
94
+ ? this.template
95
+ : (this.backend.extractTemplate || extractTemplate)(
96
+ this.doc.content as FidusNode
97
+ )
98
+
99
+ const jsonData: Record<string, unknown> = {
100
+ template: template.content,
101
+ export_templates: template.exportTemplates,
102
+ document_styles: template.documentStyles,
103
+ import_id: this.importId
104
+ ? this.importId
105
+ : (template.content.attrs as Record<string, unknown>)?.import_id,
106
+ template_title: (template.content.attrs as Record<string, unknown>)
107
+ ?.template,
108
+ path: this.requestedPath
109
+ }
110
+
111
+ if (this.e2eeOptions?.enabled) {
112
+ jsonData.e2ee = true
113
+ if (this.e2eeOptions.salt) {
114
+ jsonData.e2ee_salt = this.e2eeOptions.salt
115
+ }
116
+ if (this.e2eeOptions.iterations) {
117
+ jsonData.e2ee_iterations = this.e2eeOptions.iterations
118
+ }
119
+ }
120
+
121
+ const files: Record<string, File[]> = {}
122
+ if (template.files?.length) {
123
+ files.files = template.files.map(
124
+ ({filename, content}) => new File([content as BlobPart], filename)
125
+ )
126
+ }
127
+
128
+ return this.backend
129
+ .createDoc(
130
+ template,
131
+ this.importId,
132
+ this.requestedPath,
133
+ this.e2eeOptions,
134
+ files
135
+ )
136
+ .then(({id, path, e2ee}) => {
137
+ this.docId = id
138
+ this.path = path
139
+ this.doc.e2ee = e2ee || false
140
+ })
141
+ }
142
+
143
+ saveImages(): Promise<Record<number | string, number>> {
144
+ return this.backend.saveImages(
145
+ this.images,
146
+ this.docId,
147
+ this.e2eeOptions
148
+ )
149
+ }
150
+
151
+ translateReferenceIds(imageTranslationTable: Record<number | string, number>): void {
152
+ const walkTree = (node: FidusNode): void => {
153
+ switch (node.type) {
154
+ case "image":
155
+ if (node.attrs && node.attrs.image !== false) {
156
+ node.attrs.image =
157
+ imageTranslationTable[node.attrs.image as number | string]
158
+ }
159
+ break
160
+ case "footnote":
161
+ if (node.attrs?.footnote) {
162
+ ;(node.attrs.footnote as FidusNode[]).forEach(childNode =>
163
+ walkTree(childNode)
164
+ )
165
+ }
166
+ break
167
+ }
168
+ if (node.content) {
169
+ node.content.forEach(childNode => walkTree(childNode))
170
+ }
171
+ }
172
+ walkTree(this.doc.content as FidusNode)
173
+ }
174
+
175
+ async saveDocument(): Promise<{doc: Record<string, unknown>; docInfo: Record<string, unknown>}> {
176
+ let saveData: Record<string, unknown>
177
+ if (this.e2eeOptions?.enabled && this.e2eeOptions.key) {
178
+ const encryptedContent = await this.backend.encryptObject!(
179
+ this.doc.content,
180
+ this.e2eeOptions.key
181
+ )
182
+ const encryptedComments = await this.backend.encryptObject!(
183
+ this.doc.comments || {},
184
+ this.e2eeOptions.key
185
+ )
186
+ const encryptedBibliography = await this.backend.encryptObject!(
187
+ this.bibliography,
188
+ this.e2eeOptions.key
189
+ )
190
+ const encryptedTitle = await this.backend.encrypt!(
191
+ this.doc.title as string,
192
+ this.e2eeOptions.key
193
+ )
194
+ saveData = {
195
+ id: this.docId,
196
+ title: encryptedTitle,
197
+ content: encryptedContent,
198
+ comments: encryptedComments,
199
+ bibliography: encryptedBibliography
200
+ }
201
+ } else {
202
+ saveData = {
203
+ id: this.docId,
204
+ title: this.doc.title,
205
+ content: this.doc.content,
206
+ comments: this.doc.comments,
207
+ bibliography: this.bibliography
208
+ }
209
+ }
210
+ return this.backend
211
+ .saveDocument(saveData, this.e2eeOptions)
212
+ .then(({added, updated}: SaveDocumentResult) => {
213
+ const docInfo: Record<string, unknown> = {
214
+ is_owner: true,
215
+ access_rights: "write",
216
+ id: this.docId
217
+ }
218
+ this.doc.owner = {
219
+ id: this.user.id,
220
+ name: this.user.name,
221
+ avatar: this.user.avatar
222
+ }
223
+ this.doc.is_owner = true
224
+ this.doc.version = 0
225
+ this.doc.comment_version = 0
226
+ this.doc.id = this.docId
227
+ this.doc.added = added
228
+ this.doc.updated = updated
229
+ this.doc.revisions = []
230
+ this.doc.rights = "write"
231
+ this.doc.path = this.path
232
+ this.doc.e2ee = this.doc.e2ee || false
233
+ if (
234
+ this.e2eeOptions?.enabled &&
235
+ this.e2eeOptions.key &&
236
+ this.docId &&
237
+ this.backend.storeKeyInSession
238
+ ) {
239
+ this.backend.storeKeyInSession(this.docId, this.e2eeOptions.key)
240
+ }
241
+ return {doc: this.doc, docInfo}
242
+ })
243
+ }
244
+ }
@@ -0,0 +1,6 @@
1
+ export {GetImages} from "./get_images.js"
2
+ export {updateFile} from "./update.js"
3
+ export {updateTemplateFile} from "./update_template.js"
4
+ export {extractTemplate} from "./extract_template.js"
5
+ export {NativeImporter} from "./importer.js"
6
+ export {FidusFileImporter} from "./file.js"
@@ -1,6 +1,13 @@
1
1
  import {updateDoc} from "../../schema/convert.js"
2
2
 
3
- export function updateFile(doc, filetypeVersion, bibliography, images) {
3
+ import type {FidusDoc, ImageDBEntries} from "../../types.js"
4
+
5
+ export function updateFile(
6
+ doc: FidusDoc,
7
+ filetypeVersion: number,
8
+ bibliography: Record<string, unknown>,
9
+ images: ImageDBEntries
10
+ ): {doc: FidusDoc; bibliography: Record<string, unknown>; images: ImageDBEntries} {
4
11
  // update bibliography -- currently not needed
5
12
  // bibliography = updateBib(bibliography)
6
13
  if (filetypeVersion < 3.2) {
@@ -14,15 +21,16 @@ export function updateFile(doc, filetypeVersion, bibliography, images) {
14
21
  })
15
22
  )
16
23
  }
24
+ const docRecord = doc as unknown as Record<string, unknown>
17
25
  if (filetypeVersion < 3.3) {
18
- doc.content = doc.contents
19
- delete doc.contents
26
+ docRecord.content = docRecord.contents
27
+ delete docRecord.contents
20
28
  }
21
29
  if (filetypeVersion < 2.0) {
22
30
  // Before 2.0, version numbers of the doc and of the file differed.
23
- doc = updateDoc(doc, doc.settings["doc_version"], bibliography)
31
+ doc = updateDoc(doc, (docRecord.settings as Record<string, unknown>)["doc_version"] as number, bibliography as any) as FidusDoc
24
32
  } else {
25
- doc = updateDoc(doc, filetypeVersion, bibliography)
33
+ doc = updateDoc(doc, filetypeVersion, bibliography as any) as FidusDoc
26
34
  }
27
35
 
28
36
  return {doc, bibliography, images}
@@ -0,0 +1,32 @@
1
+ import {updateDoc} from "../../schema/convert.js"
2
+
3
+ import type {FidusNode, JSONValue} from "../../types.js"
4
+
5
+ /**
6
+ * Update a template definition that has been read from a fidus/template file
7
+ * to the current document schema version.
8
+ */
9
+ export function updateTemplateFile(
10
+ title: string,
11
+ content: FidusNode,
12
+ exportTemplates: Array<Record<string, JSONValue>>,
13
+ documentStyles: Array<Record<string, JSONValue>>,
14
+ filetypeVersion: number
15
+ ): {
16
+ title: string
17
+ content: FidusNode
18
+ exportTemplates: Array<Record<string, JSONValue>>
19
+ documentStyles: Array<Record<string, JSONValue>>
20
+ } {
21
+ const oldDoc = {
22
+ content,
23
+ diffs: [],
24
+ bibliography: {},
25
+ comments: {},
26
+ title,
27
+ version: 1,
28
+ id: 1
29
+ }
30
+ const doc = updateDoc(oldDoc, filetypeVersion)
31
+ return {title, content: doc.content as FidusNode, exportTemplates, documentStyles}
32
+ }