@fiduswriter/books 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +87 -2
  3. package/css/book.css +219 -0
  4. package/dist/exporter/bits/index.d.ts +42 -0
  5. package/dist/exporter/bits/index.d.ts.map +1 -0
  6. package/dist/exporter/bits/index.js +113 -0
  7. package/dist/exporter/bits/index.js.map +1 -0
  8. package/dist/exporter/bits/templates.d.ts +7 -0
  9. package/dist/exporter/bits/templates.d.ts.map +1 -0
  10. package/dist/exporter/bits/templates.js +78 -0
  11. package/dist/exporter/bits/templates.js.map +1 -0
  12. package/dist/exporter/docx/index.d.ts +33 -0
  13. package/dist/exporter/docx/index.d.ts.map +1 -0
  14. package/dist/exporter/docx/index.js +139 -0
  15. package/dist/exporter/docx/index.js.map +1 -0
  16. package/dist/exporter/docx/render.d.ts +19 -0
  17. package/dist/exporter/docx/render.d.ts.map +1 -0
  18. package/dist/exporter/docx/render.js +123 -0
  19. package/dist/exporter/docx/render.js.map +1 -0
  20. package/dist/exporter/epub/index.d.ts +70 -0
  21. package/dist/exporter/epub/index.d.ts.map +1 -0
  22. package/dist/exporter/epub/index.js +310 -0
  23. package/dist/exporter/epub/index.js.map +1 -0
  24. package/dist/exporter/epub/templates.d.ts +65 -0
  25. package/dist/exporter/epub/templates.d.ts.map +1 -0
  26. package/dist/exporter/epub/templates.js +224 -0
  27. package/dist/exporter/epub/templates.js.map +1 -0
  28. package/dist/exporter/epub/tools.d.ts +5 -0
  29. package/dist/exporter/epub/tools.d.ts.map +1 -0
  30. package/dist/exporter/epub/tools.js +59 -0
  31. package/dist/exporter/epub/tools.js.map +1 -0
  32. package/dist/exporter/html/index.d.ts +70 -0
  33. package/dist/exporter/html/index.d.ts.map +1 -0
  34. package/dist/exporter/html/index.js +320 -0
  35. package/dist/exporter/html/index.js.map +1 -0
  36. package/dist/exporter/html/templates.d.ts +40 -0
  37. package/dist/exporter/html/templates.d.ts.map +1 -0
  38. package/dist/exporter/html/templates.js +225 -0
  39. package/dist/exporter/html/templates.js.map +1 -0
  40. package/dist/exporter/html/tools.d.ts +2 -0
  41. package/dist/exporter/html/tools.d.ts.map +1 -0
  42. package/dist/exporter/html/tools.js +23 -0
  43. package/dist/exporter/html/tools.js.map +1 -0
  44. package/dist/exporter/latex/index.d.ts +36 -0
  45. package/dist/exporter/latex/index.d.ts.map +1 -0
  46. package/dist/exporter/latex/index.js +116 -0
  47. package/dist/exporter/latex/index.js.map +1 -0
  48. package/dist/exporter/latex/templates.d.ts +4 -0
  49. package/dist/exporter/latex/templates.d.ts.map +1 -0
  50. package/dist/exporter/latex/templates.js +26 -0
  51. package/dist/exporter/latex/templates.js.map +1 -0
  52. package/dist/exporter/native/index.d.ts +22 -0
  53. package/dist/exporter/native/index.d.ts.map +1 -0
  54. package/dist/exporter/native/index.js +141 -0
  55. package/dist/exporter/native/index.js.map +1 -0
  56. package/dist/exporter/odt/index.d.ts +33 -0
  57. package/dist/exporter/odt/index.d.ts.map +1 -0
  58. package/dist/exporter/odt/index.js +133 -0
  59. package/dist/exporter/odt/index.js.map +1 -0
  60. package/dist/exporter/odt/render.d.ts +21 -0
  61. package/dist/exporter/odt/render.d.ts.map +1 -0
  62. package/dist/exporter/odt/render.js +126 -0
  63. package/dist/exporter/odt/render.js.map +1 -0
  64. package/dist/exporter/pretty.d.ts +17 -0
  65. package/dist/exporter/pretty.d.ts.map +1 -0
  66. package/dist/exporter/pretty.js +55 -0
  67. package/dist/exporter/pretty.js.map +1 -0
  68. package/dist/exporter/print/index.d.ts +25 -0
  69. package/dist/exporter/print/index.d.ts.map +1 -0
  70. package/dist/exporter/print/index.js +46 -0
  71. package/dist/exporter/print/index.js.map +1 -0
  72. package/dist/exporter/print/templates.d.ts +2 -0
  73. package/dist/exporter/print/templates.d.ts.map +1 -0
  74. package/dist/exporter/print/templates.js +5 -0
  75. package/dist/exporter/print/templates.js.map +1 -0
  76. package/dist/exporter/tools.d.ts +31 -0
  77. package/dist/exporter/tools.d.ts.map +1 -0
  78. package/dist/exporter/tools.js +177 -0
  79. package/dist/exporter/tools.js.map +1 -0
  80. package/dist/i18n.d.ts +7 -0
  81. package/dist/i18n.d.ts.map +1 -0
  82. package/dist/i18n.js +918 -0
  83. package/dist/i18n.js.map +1 -0
  84. package/dist/ids.d.ts +19 -0
  85. package/dist/ids.d.ts.map +1 -0
  86. package/dist/ids.js +27 -0
  87. package/dist/ids.js.map +1 -0
  88. package/dist/importer/native/index.d.ts +45 -0
  89. package/dist/importer/native/index.d.ts.map +1 -0
  90. package/dist/importer/native/index.js +166 -0
  91. package/dist/importer/native/index.js.map +1 -0
  92. package/dist/importer/native/reader.d.ts +32 -0
  93. package/dist/importer/native/reader.d.ts.map +1 -0
  94. package/dist/importer/native/reader.js +170 -0
  95. package/dist/importer/native/reader.js.map +1 -0
  96. package/dist/index.d.ts +4 -0
  97. package/dist/index.d.ts.map +1 -0
  98. package/dist/index.js +3 -0
  99. package/dist/index.js.map +1 -0
  100. package/dist/schema/index.d.ts +7 -0
  101. package/dist/schema/index.d.ts.map +1 -0
  102. package/dist/schema/index.js +8 -0
  103. package/dist/schema/index.js.map +1 -0
  104. package/dist/types.d.ts +171 -0
  105. package/dist/types.d.ts.map +1 -0
  106. package/dist/types.js +5 -0
  107. package/dist/types.js.map +1 -0
  108. package/dist/ui/book_dialog/dialog.d.ts +161 -0
  109. package/dist/ui/book_dialog/dialog.d.ts.map +1 -0
  110. package/dist/ui/book_dialog/dialog.js +750 -0
  111. package/dist/ui/book_dialog/dialog.js.map +1 -0
  112. package/dist/ui/book_dialog/export.d.ts +95 -0
  113. package/dist/ui/book_dialog/export.d.ts.map +1 -0
  114. package/dist/ui/book_dialog/export.js +217 -0
  115. package/dist/ui/book_dialog/export.js.map +1 -0
  116. package/dist/ui/book_dialog/index.d.ts +38 -0
  117. package/dist/ui/book_dialog/index.d.ts.map +1 -0
  118. package/dist/ui/book_dialog/index.js +36 -0
  119. package/dist/ui/book_dialog/index.js.map +1 -0
  120. package/dist/ui/book_dialog/sanity_check.d.ts +22 -0
  121. package/dist/ui/book_dialog/sanity_check.d.ts.map +1 -0
  122. package/dist/ui/book_dialog/sanity_check.js +109 -0
  123. package/dist/ui/book_dialog/sanity_check.js.map +1 -0
  124. package/dist/ui/book_dialog/templates.d.ts +76 -0
  125. package/dist/ui/book_dialog/templates.d.ts.map +1 -0
  126. package/dist/ui/book_dialog/templates.js +542 -0
  127. package/dist/ui/book_dialog/templates.js.map +1 -0
  128. package/dist/ui/book_dialog/types.d.ts +258 -0
  129. package/dist/ui/book_dialog/types.d.ts.map +1 -0
  130. package/dist/ui/book_dialog/types.js +15 -0
  131. package/dist/ui/book_dialog/types.js.map +1 -0
  132. package/locale/ar/messages.json +49 -0
  133. package/locale/bg/messages.json +49 -0
  134. package/locale/cs/messages.json +49 -0
  135. package/locale/da/messages.json +49 -0
  136. package/locale/de/messages.json +49 -0
  137. package/locale/en/messages.json +49 -0
  138. package/locale/en_US/messages.json +49 -0
  139. package/locale/es/messages.json +49 -0
  140. package/locale/fr/messages.json +49 -0
  141. package/locale/it/messages.json +49 -0
  142. package/locale/ja/messages.json +49 -0
  143. package/locale/ko/messages.json +49 -0
  144. package/locale/nb/messages.json +49 -0
  145. package/locale/nl/messages.json +49 -0
  146. package/locale/pl/messages.json +49 -0
  147. package/locale/pt_BR/messages.json +49 -0
  148. package/locale/pt_PT/messages.json +49 -0
  149. package/locale/ru/messages.json +49 -0
  150. package/locale/sv/messages.json +49 -0
  151. package/locale/tr/messages.json +49 -0
  152. package/locale/zh_Hans/messages.json +49 -0
  153. package/logo.svg +10 -0
  154. package/package.json +150 -5
  155. package/src/exporter/bits/index.ts +184 -0
  156. package/src/exporter/bits/templates.ts +107 -0
  157. package/src/exporter/docx/index.ts +258 -0
  158. package/src/exporter/docx/render.ts +177 -0
  159. package/src/exporter/epub/index.ts +496 -0
  160. package/src/exporter/epub/templates.ts +403 -0
  161. package/src/exporter/epub/tools.ts +68 -0
  162. package/src/exporter/html/index.ts +479 -0
  163. package/src/exporter/html/templates.ts +362 -0
  164. package/src/exporter/html/tools.ts +26 -0
  165. package/src/exporter/latex/index.ts +190 -0
  166. package/src/exporter/latex/templates.ts +35 -0
  167. package/src/exporter/native/index.ts +238 -0
  168. package/src/exporter/odt/index.ts +230 -0
  169. package/src/exporter/odt/render.ts +181 -0
  170. package/src/exporter/pretty.ts +75 -0
  171. package/src/exporter/print/index.ts +76 -0
  172. package/src/exporter/print/templates.ts +8 -0
  173. package/src/exporter/tools.ts +270 -0
  174. package/src/global.d.ts +2 -0
  175. package/src/i18n.ts +936 -0
  176. package/src/ids.ts +27 -0
  177. package/src/importer/native/index.ts +269 -0
  178. package/src/importer/native/reader.ts +247 -0
  179. package/src/index.ts +20 -0
  180. package/src/modules.d.ts +7 -0
  181. package/src/schema/index.ts +8 -0
  182. package/src/types.ts +208 -0
  183. package/src/ui/book_dialog/dialog.ts +940 -0
  184. package/src/ui/book_dialog/export.ts +449 -0
  185. package/src/ui/book_dialog/index.ts +84 -0
  186. package/src/ui/book_dialog/sanity_check.ts +208 -0
  187. package/src/ui/book_dialog/templates.ts +736 -0
  188. package/src/ui/book_dialog/types.ts +283 -0
@@ -0,0 +1,49 @@
1
+ {
2
+ "": "tr",
3
+ "A personal passphrase is required to work with books that contain encrypted chapters. Please set up or unlock your personal passphrase in your profile settings.": "",
4
+ "Assembling BITS book...": "",
5
+ "Assembling Epub book...": "",
6
+ "Assembling HTML book...": "",
7
+ "BITS book export complete.": "",
8
+ "BITS book export has been initiated.": "",
9
+ "Book cannot be exported due to lack of chapters.": "",
10
+ "Cannot produce book as you lack access rights to its chapters.": "",
11
+ "Chapter data loaded.": "",
12
+ "Could not decrypt chapter:": "",
13
+ "Could not import chapter ": "",
14
+ "DOCX book export complete.": "",
15
+ "DOCX book export has been initiated.": "",
16
+ "Epub book export complete.": "",
17
+ "Epub book export has been initiated.": "",
18
+ "Exporting book chapters...": "",
19
+ "Exporting chapter %s of %s...": "",
20
+ "Fidusbook export complete.": "",
21
+ "Fidusbook export failed.": "",
22
+ "Fidusbook export has been initiated.": "",
23
+ "Fidusbook file is missing data for chapter ": "",
24
+ "Finalizing BITS book...": "",
25
+ "Finalizing DOCX book...": "",
26
+ "Finalizing Epub book...": "",
27
+ "Finalizing HTML book...": "",
28
+ "Finalizing LaTeX book...": "",
29
+ "Finalizing ODT book...": "",
30
+ "HTML book export complete.": "",
31
+ "HTML book export has been initiated.": "",
32
+ "LaTeX book export complete.": "",
33
+ "LaTeX book export has been initiated.": "",
34
+ "Loading chapter data...": "",
35
+ "No encryption key found for chapter:": "",
36
+ "ODT book export complete.": "",
37
+ "ODT book export has been initiated.": "",
38
+ "Preparing BITS book...": "",
39
+ "Preparing DOCX book...": "",
40
+ "Preparing Epub book...": "",
41
+ "Preparing LaTeX book...": "",
42
+ "Preparing ODT book...": "",
43
+ "successfully imported.": "başarıyla içe aktarıldı.",
44
+ "The document may have been re-encrypted with a different password.": "",
45
+ "The Fidusbook file version is not supported by this server: ": "",
46
+ "The key may not have been shared with you.": "",
47
+ "The uploaded file does not appear to be a Fidusbook file.": "",
48
+ "Untitled": "İsimsiz"
49
+ }
@@ -0,0 +1,49 @@
1
+ {
2
+ "": "zh_Hans",
3
+ "A personal passphrase is required to work with books that contain encrypted chapters. Please set up or unlock your personal passphrase in your profile settings.": "",
4
+ "Assembling BITS book...": "",
5
+ "Assembling Epub book...": "",
6
+ "Assembling HTML book...": "",
7
+ "BITS book export complete.": "",
8
+ "BITS book export has been initiated.": "",
9
+ "Book cannot be exported due to lack of chapters.": "",
10
+ "Cannot produce book as you lack access rights to its chapters.": "",
11
+ "Chapter data loaded.": "",
12
+ "Could not decrypt chapter:": "",
13
+ "Could not import chapter ": "",
14
+ "DOCX book export complete.": "",
15
+ "DOCX book export has been initiated.": "",
16
+ "Epub book export complete.": "",
17
+ "Epub book export has been initiated.": "",
18
+ "Exporting book chapters...": "",
19
+ "Exporting chapter %s of %s...": "",
20
+ "Fidusbook export complete.": "",
21
+ "Fidusbook export failed.": "",
22
+ "Fidusbook export has been initiated.": "",
23
+ "Fidusbook file is missing data for chapter ": "",
24
+ "Finalizing BITS book...": "",
25
+ "Finalizing DOCX book...": "",
26
+ "Finalizing Epub book...": "",
27
+ "Finalizing HTML book...": "",
28
+ "Finalizing LaTeX book...": "",
29
+ "Finalizing ODT book...": "",
30
+ "HTML book export complete.": "",
31
+ "HTML book export has been initiated.": "",
32
+ "LaTeX book export complete.": "",
33
+ "LaTeX book export has been initiated.": "",
34
+ "Loading chapter data...": "",
35
+ "No encryption key found for chapter:": "",
36
+ "ODT book export complete.": "",
37
+ "ODT book export has been initiated.": "",
38
+ "Preparing BITS book...": "",
39
+ "Preparing DOCX book...": "",
40
+ "Preparing Epub book...": "",
41
+ "Preparing LaTeX book...": "",
42
+ "Preparing ODT book...": "",
43
+ "successfully imported.": "成功导入。",
44
+ "The document may have been re-encrypted with a different password.": "",
45
+ "The Fidusbook file version is not supported by this server: ": "",
46
+ "The key may not have been shared with you.": "",
47
+ "The uploaded file does not appear to be a Fidusbook file.": "",
48
+ "Untitled": "无题"
49
+ }
package/logo.svg ADDED
@@ -0,0 +1,10 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" width="100" height="100">
2
+ <defs>
3
+ <linearGradient id="logo-bg" x1="0%" y1="0%" x2="0%" y2="100%">
4
+ <stop offset="0%" stop-color="#e67e22"/>
5
+ <stop offset="100%" stop-color="#d35400"/>
6
+ </linearGradient>
7
+ </defs>
8
+ <rect x="5" y="5" width="90" height="90" rx="18" ry="18" fill="url(#logo-bg)" stroke="#a04000" stroke-width="2"/>
9
+ <text x="50" y="70" font-family="Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="54" font-weight="bold" text-anchor="middle" fill="#ffffff">fb</text>
10
+ </svg>
package/package.json CHANGED
@@ -1,6 +1,151 @@
1
1
  {
2
- "name": "@fiduswriter/books",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@fiduswriter/books",
3
+ "version": "0.2.0",
4
+ "description": "Fidus Writer book importers and exporters",
5
+ "keywords": [
6
+ "fiduswriter",
7
+ "books",
8
+ "document",
9
+ "epub",
10
+ "docx",
11
+ "odt",
12
+ "latex",
13
+ "html",
14
+ "bits",
15
+ "export",
16
+ "import"
17
+ ],
18
+ "homepage": "https://git.fiduswriter.org/fiduswriter/fiduswriter-books-ts",
19
+ "bugs": {
20
+ "url": "https://git.fiduswriter.org/fiduswriter/fiduswriter-books-ts/issues"
21
+ },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "https://git.fiduswriter.org/fiduswriter/fiduswriter-books-ts.git"
25
+ },
26
+ "license": "AGPL-3.0",
27
+ "author": "Johannes Wilm",
28
+ "type": "module",
29
+ "main": "./dist/index.js",
30
+ "types": "./dist/index.d.ts",
31
+ "exports": {
32
+ ".": {
33
+ "types": "./dist/index.d.ts",
34
+ "default": "./dist/index.js"
35
+ },
36
+ "./schema": {
37
+ "types": "./dist/schema/index.d.ts",
38
+ "default": "./dist/schema/index.js"
39
+ },
40
+ "./importer/native": {
41
+ "types": "./dist/importer/native/index.d.ts",
42
+ "default": "./dist/importer/native/index.js"
43
+ },
44
+ "./exporter/native": {
45
+ "types": "./dist/exporter/native/index.d.ts",
46
+ "default": "./dist/exporter/native/index.js"
47
+ },
48
+ "./exporter/html": {
49
+ "types": "./dist/exporter/html/index.d.ts",
50
+ "default": "./dist/exporter/html/index.js"
51
+ },
52
+ "./exporter/epub": {
53
+ "types": "./dist/exporter/epub/index.d.ts",
54
+ "default": "./dist/exporter/epub/index.js"
55
+ },
56
+ "./exporter/latex": {
57
+ "types": "./dist/exporter/latex/index.d.ts",
58
+ "default": "./dist/exporter/latex/index.js"
59
+ },
60
+ "./exporter/docx": {
61
+ "types": "./dist/exporter/docx/index.d.ts",
62
+ "default": "./dist/exporter/docx/index.js"
63
+ },
64
+ "./exporter/odt": {
65
+ "types": "./dist/exporter/odt/index.d.ts",
66
+ "default": "./dist/exporter/odt/index.js"
67
+ },
68
+ "./exporter/print": {
69
+ "types": "./dist/exporter/print/index.d.ts",
70
+ "default": "./dist/exporter/print/index.js"
71
+ },
72
+ "./exporter/bits": {
73
+ "types": "./dist/exporter/bits/index.d.ts",
74
+ "default": "./dist/exporter/bits/index.js"
75
+ },
76
+ "./exporter/tools": {
77
+ "types": "./dist/exporter/tools.d.ts",
78
+ "default": "./dist/exporter/tools.js"
79
+ },
80
+ "./i18n": {
81
+ "types": "./dist/i18n.d.ts",
82
+ "default": "./dist/i18n.js"
83
+ },
84
+ "./ui/book_dialog": {
85
+ "types": "./dist/ui/book_dialog/index.d.ts",
86
+ "default": "./dist/ui/book_dialog/index.js"
87
+ }
88
+ },
89
+ "directories": {
90
+ "test": "test"
91
+ },
92
+ "files": [
93
+ "dist/",
94
+ "css/",
95
+ "src/",
96
+ "README.md",
97
+ "LICENSE",
98
+ "logo.svg",
99
+ "locale/*/messages.json"
100
+ ],
101
+ "scripts": {
102
+ "build": "tsc",
103
+ "prepare": "husky",
104
+ "prepublishOnly": "npm run build",
105
+ "typecheck": "tsc --noEmit",
106
+ "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --config jest.config.js",
107
+ "lint": "eslint src test",
108
+ "lint:fix": "eslint src test --fix",
109
+ "format": "prettier --write .",
110
+ "format:check": "prettier --check .",
111
+ "install-hooks": "husky",
112
+ "compile-i18n": "node scripts/compile-i18n.js",
113
+ "extract-i18n": "node scripts/extract-i18n.js"
114
+ },
115
+ "dependencies": {
116
+ "@fiduswriter/document": "^0.3.37",
117
+ "bibliojson": "^4.1.0",
118
+ "downloadjs": "^1.4.7",
119
+ "fast-deep-equal": "^3.1.3",
120
+ "fwtoolkit": "^0.2.28",
121
+ "js-beautify": "^2.0.3",
122
+ "jszip": "^3.10.2"
123
+ },
124
+ "devDependencies": {
125
+ "@eslint/js": "^10.0.1",
126
+ "@swc/core": "^1.16.18",
127
+ "@swc/jest": "^0.2.39",
128
+ "@types/node": "^26.6.5",
129
+ "@typescript/native": "npm:typescript@^7.0.2",
130
+ "eslint": "^10.12.0",
131
+ "gettext-parser": "^9.1.1",
132
+ "globals": "^17.13.0",
133
+ "husky": "^9.1.7",
134
+ "jest": "^30.5.2",
135
+ "jest-environment-jsdom": "^30.5.2",
136
+ "lint-staged": "^17.6.0",
137
+ "prettier": "^3.9.10",
138
+ "prosemirror-model": "^1.25.12",
139
+ "typescript": "npm:@typescript/typescript6@^6.0.2",
140
+ "typescript-eslint": "^8.71.2"
141
+ },
142
+ "lint-staged": {
143
+ "*.{ts,js,mjs,css,md,json,html}": [
144
+ "prettier --write"
145
+ ],
146
+ "*.{ts,js,mjs}": [
147
+ "eslint --fix",
148
+ "sh -c 'npm run typecheck'"
149
+ ]
150
+ }
151
+ }
@@ -0,0 +1,184 @@
1
+ /**
2
+ * BITS (Book Interchange Tag Suite) book exporter.
3
+ */
4
+
5
+ import type {Schema} from "prosemirror-model"
6
+ import pretty from "../pretty.js"
7
+ import {JATSExporterConverter} from "@fiduswriter/document/exporter/jats/convert"
8
+ import {darManifest} from "@fiduswriter/document/exporter/jats/templates"
9
+ import type {ProgressCallback} from "@fiduswriter/document/exporter/tools/progress"
10
+ import {
11
+ createSlug,
12
+ getImageDBEntryFilename
13
+ } from "@fiduswriter/document/exporter/tools/file"
14
+ import type {ImageDBEntry} from "@fiduswriter/document"
15
+ import {ZipFileCreator} from "fwtoolkit/file/zip"
16
+ import {gettext} from "fwtoolkit"
17
+
18
+ import type {Book, CSL, DocumentListEntry, User} from "../../types.js"
19
+ import {getMissingChapterData} from "../tools.js"
20
+ import {bitsTemplate} from "./templates.js"
21
+
22
+ interface TextFile {
23
+ filename: string
24
+ contents: string
25
+ }
26
+
27
+ interface HttpFile {
28
+ filename: string
29
+ url: string
30
+ title?: string
31
+ }
32
+
33
+ export class BITSBookExporter {
34
+ schema: Schema
35
+ csl: CSL
36
+ book: Book
37
+ user: User
38
+ docList: DocumentListEntry[]
39
+ updated: number
40
+ type: string
41
+ textFiles: TextFile[]
42
+ httpFiles: HttpFile[]
43
+ zipFileName: string
44
+ progressCallback?: ProgressCallback
45
+
46
+ constructor(
47
+ schema: Schema,
48
+ csl: CSL,
49
+ book: Book,
50
+ user: User,
51
+ docList: DocumentListEntry[],
52
+ updated: number
53
+ ) {
54
+ this.schema = schema
55
+ this.csl = csl
56
+ this.book = book
57
+ this.user = user
58
+ this.docList = docList
59
+ this.updated = updated
60
+ this.type = "book"
61
+ this.textFiles = []
62
+ this.httpFiles = []
63
+ this.zipFileName = ""
64
+ }
65
+
66
+ init(progressCallback?: ProgressCallback): Promise<Blob> | false {
67
+ this.progressCallback = progressCallback
68
+ this.progressCallback?.(
69
+ gettext("BITS book export has been initiated."),
70
+ 0
71
+ )
72
+ if (this.book.chapters.length === 0) {
73
+ throw new Error(
74
+ gettext("Book cannot be exported due to lack of chapters.")
75
+ )
76
+ }
77
+ return getMissingChapterData(this.book, this.docList, this.schema, {
78
+ progressCallback: this.progressCallback
79
+ }).then(() => this.export())
80
+ }
81
+
82
+ export(): Promise<Blob> {
83
+ this.progressCallback?.(gettext("Preparing BITS book..."), 10)
84
+ this.book.chapters.sort((a, b) => (a.number > b.number ? 1 : -1))
85
+
86
+ const imageDict: Record<string, ImageDBEntry> = {}
87
+ return Promise.all(
88
+ this.book.chapters.map(chapter => {
89
+ const doc = this.docList.find(d => d.id === chapter.text)
90
+ if (!doc) {
91
+ return Promise.resolve({front: "", body: "", back: ""})
92
+ }
93
+ const converter = new JATSExporterConverter(
94
+ this.type,
95
+ doc,
96
+ this.csl,
97
+ {db: doc.images || {}},
98
+ {db: doc.bibliography || {}}
99
+ )
100
+ return converter.init().then(({front, body, back, imageIds}) => {
101
+ imageIds.forEach(
102
+ (imageId: string | number) =>
103
+ (imageDict[imageId] = doc.images?.[
104
+ imageId
105
+ ] as ImageDBEntry)
106
+ )
107
+ return {front, body, back}
108
+ })
109
+ })
110
+ ).then(chapters => this.createFiles(chapters, imageDict))
111
+ }
112
+
113
+ createFiles(
114
+ chapters: Array<{front: string; body: string; back: string}>,
115
+ imageDict: Record<string, ImageDBEntry>
116
+ ): Promise<Blob> {
117
+ this.progressCallback?.(gettext("Assembling BITS book..."), 80)
118
+ const images = Object.entries(imageDict)
119
+ .filter((entry): entry is [string, ImageDBEntry] =>
120
+ Boolean(entry[1]?.image)
121
+ )
122
+ .map(([id, image]) => ({
123
+ // Data URL images (the desktop stores them that way) have no
124
+ // usable last path segment: the base64 payload can contain
125
+ // "/" and a random tail became the file name.
126
+ filename: getImageDBEntryFilename(image, id),
127
+ url: (image.image as string).split("?")[0],
128
+ title: image.title || ""
129
+ }))
130
+
131
+ this.zipFileName = `${createSlug(this.book.title)}.bits.zip`
132
+
133
+ this.textFiles = [
134
+ {
135
+ filename: "manuscript.xml",
136
+ contents: pretty(bitsTemplate(this.book, chapters), {ocd: true})
137
+ },
138
+ {
139
+ filename: "manifest.xml",
140
+ contents: pretty(
141
+ darManifest({
142
+ title: this.book.title,
143
+ type: this.type,
144
+ images
145
+ }),
146
+ {ocd: true}
147
+ )
148
+ }
149
+ ]
150
+
151
+ images.forEach(image => {
152
+ this.httpFiles.push({
153
+ filename: image.filename,
154
+ url: image.url,
155
+ title: image.title
156
+ })
157
+ })
158
+
159
+ return this.createZip()
160
+ }
161
+
162
+ createZip(): Promise<Blob> {
163
+ this.progressCallback?.(gettext("Finalizing BITS book..."), 90)
164
+ const zipper = new ZipFileCreator(
165
+ this.textFiles,
166
+ this.httpFiles,
167
+ undefined,
168
+ undefined,
169
+ new Date(this.updated * 1000)
170
+ )
171
+ return zipper.init().then(blob => {
172
+ this.progressCallback?.(gettext("BITS book export complete."), 100)
173
+ return this.download(blob)
174
+ })
175
+ }
176
+
177
+ download(blob: Blob): Blob {
178
+ return blob
179
+ }
180
+
181
+ get defaultFilename(): string {
182
+ return this.zipFileName
183
+ }
184
+ }
@@ -0,0 +1,107 @@
1
+ import {escapeText} from "fwtoolkit"
2
+
3
+ import type {Book, BitsTemplateParams} from "../../types.js"
4
+
5
+ const bookPartTemplate = ({front, body, back}: BitsTemplateParams) =>
6
+ `<book-part book-part-type="chapter" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ali="http://www.niso.org/schemas/ali/1.0/" xmlns:mml="http://www.w3.org/1998/Math/MathML">${front}${body}${back}</book-part>`
7
+
8
+ export const bitsTemplate = (
9
+ book: Book,
10
+ chapters: Array<{front: string; body: string; back: string}>
11
+ ) => {
12
+ const updated = new Date((book.updated || 0) * 1000)
13
+ return `<?xml version="1.0" encoding="UTF-8"?>
14
+ <!DOCTYPE book PUBLIC "-//NLM//DTD BITS Book Interchange DTD v2.1 20220202//EN" "https://jats.nlm.nih.gov/extensions/bits/2.1/BITS-book2-1.dtd">
15
+ <book dtd-version="2.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ali="http://www.niso.org/schemas/ali/1.0/">
16
+ <processing-meta tagset-family="bits" table-model="xhtml" math-representation="tex mathml"></processing-meta>
17
+ <book-meta>
18
+ <book-title-group>
19
+ <book-title>${escapeText(book.title)}</book-title>
20
+ ${book.metadata.subtitle?.length ? `<subtitle>${escapeText(book.metadata.subtitle)}</subtitle>` : ""}
21
+ </book-title-group>
22
+ ${
23
+ book.metadata.version?.length
24
+ ? `<content-version>${escapeText(book.metadata.version)}</content-version>`
25
+ : ""
26
+ }
27
+ <content-language>${(book.settings.language || "en-US").split("-")[0]}</content-language>
28
+ ${
29
+ book.metadata.description?.length
30
+ ? `<abstract>
31
+ <p>${escapeText(book.metadata.description)}</p>
32
+ </abstract>`
33
+ : ""
34
+ }
35
+ ${
36
+ book.metadata.author?.length
37
+ ? `<contrib-group>
38
+ <contrib contrib-type="author">
39
+ <name>
40
+ <surname>${escapeText(book.metadata.author.split(" ").slice(1).join(" "))}</surname>
41
+ <given-names>${escapeText(book.metadata.author.split(" ").pop() || "")}</given-names>
42
+ </name>
43
+ </contrib>
44
+ </contrib-group>`
45
+ : ""
46
+ }
47
+ <pub-date>
48
+ <year>${updated.getFullYear()}</year>
49
+ <month>${updated.getMonth() + 1}</month>
50
+ <day>${updated.getDate()}</day>
51
+ </pub-date>
52
+ ${
53
+ book.metadata.publication_date?.length
54
+ ? `<pub-date date-type="pub" publication-format="electronic">
55
+ <string-date>${escapeText(book.metadata.publication_date)}</string-date>
56
+ </pub-date>`
57
+ : ""
58
+ }
59
+ ${
60
+ book.metadata.isbn?.length
61
+ ? `<isbn>${escapeText(book.metadata.isbn)}</isbn>`
62
+ : ""
63
+ }
64
+ ${
65
+ book.metadata.publisher?.length
66
+ ? `<publisher>
67
+ <publisher-name>${escapeText(book.metadata.publisher)}</publisher-name>
68
+ </publisher>`
69
+ : ""
70
+ }
71
+ ${
72
+ book.metadata.series_title?.length
73
+ ? `<series>
74
+ <series-title>${escapeText(book.metadata.series_title)}</series-title>
75
+ ${
76
+ book.metadata.series_position?.length
77
+ ? `<series-text>${escapeText(book.metadata.series_position)}</series-text>`
78
+ : ""
79
+ }
80
+ </series>`
81
+ : ""
82
+ }
83
+ ${
84
+ book.metadata.copyright?.length
85
+ ? `<permissions>
86
+ <copyright-holder>
87
+ <name>${escapeText(book.metadata.copyright)}</name>
88
+ </copyright-holder>
89
+ </permissions>`
90
+ : ""
91
+ }
92
+ ${
93
+ book.metadata.keywords?.length
94
+ ? `<kwd-group>${book.metadata.keywords
95
+ .split(",")
96
+ .map(
97
+ keyword => `<kwd>${escapeText(keyword.trim())}</kwd>`
98
+ )
99
+ .join("")}</kwd-group>`
100
+ : ""
101
+ }
102
+ </book-meta>
103
+ <book-body>
104
+ ${chapters.map(chapter => bookPartTemplate(chapter)).join("\n")}
105
+ </book-body>
106
+ </book>`
107
+ }