@manuscripts/transform 2.10.0-LEAN-3577 → 3.0.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 (205) hide show
  1. package/dist/cjs/index.js +9 -7
  2. package/dist/cjs/jats/{jats-exporter.js → exporter/jats-exporter.js} +286 -416
  3. package/dist/cjs/jats/{jats-versions.js → exporter/jats-versions.js} +1 -3
  4. package/dist/cjs/{transformer → jats/exporter}/labels.js +7 -19
  5. package/dist/cjs/{transformer/filename.js → jats/importer/create-article-node.js} +12 -9
  6. package/dist/cjs/jats/importer/jats-body-transformations.js +22 -1
  7. package/dist/cjs/jats/importer/jats-comments.js +48 -110
  8. package/dist/cjs/jats/importer/{jats-body-dom-parser.js → jats-dom-parser.js} +364 -11
  9. package/dist/cjs/jats/importer/jats-journal-meta-parser.js +11 -1
  10. package/dist/cjs/jats/importer/jats-parser-utils.js +52 -4
  11. package/dist/cjs/jats/importer/jats-transformations.js +389 -0
  12. package/dist/cjs/jats/importer/parse-jats-article.js +43 -100
  13. package/dist/cjs/jats/index.js +7 -7
  14. package/dist/cjs/{transformer/models.js → lib/deafults.js} +3 -1
  15. package/dist/cjs/lib/utils.js +3 -1
  16. package/dist/cjs/schema/index.js +10 -0
  17. package/dist/cjs/schema/migration/migrate.js +3 -9
  18. package/dist/cjs/schema/migration/migration-script.js +1 -1
  19. package/dist/cjs/schema/migration/migration-scripts/1.2.5.js +2 -2
  20. package/dist/cjs/schema/migration/migration-scripts/2.3.22.js +28 -0
  21. package/dist/cjs/schema/migration/migration-scripts/index.js +3 -2
  22. package/dist/cjs/schema/nodes/author_notes.js +9 -2
  23. package/dist/cjs/schema/nodes/award.js +38 -0
  24. package/dist/cjs/{transformer/serializer.js → schema/nodes/awards.js} +20 -7
  25. package/dist/cjs/schema/nodes/backmatter.js +3 -2
  26. package/dist/cjs/schema/nodes/box_element.js +55 -0
  27. package/dist/cjs/schema/nodes/contributors.js +1 -1
  28. package/dist/cjs/schema/nodes/corresp.js +13 -2
  29. package/dist/cjs/schema/nodes/equation_element.js +0 -1
  30. package/dist/cjs/schema/nodes/figure_element.js +0 -1
  31. package/dist/cjs/schema/nodes/footnote.js +0 -1
  32. package/dist/cjs/schema/nodes/footnotes_section.js +1 -1
  33. package/dist/cjs/schema/nodes/highlight_marker.js +0 -4
  34. package/dist/cjs/schema/nodes/inline_equation.js +0 -1
  35. package/dist/cjs/schema/nodes/inline_footnote.js +1 -0
  36. package/dist/cjs/schema/nodes/keyword.js +0 -1
  37. package/dist/cjs/schema/nodes/listing.js +0 -1
  38. package/dist/cjs/schema/nodes/listing_element.js +0 -1
  39. package/dist/cjs/schema/nodes/manuscript.js +4 -1
  40. package/dist/cjs/schema/nodes/paragraph.js +0 -1
  41. package/dist/cjs/schema/nodes/section.js +0 -1
  42. package/dist/cjs/schema/nodes/table_element.js +1 -2
  43. package/dist/cjs/schema/nodes/title.js +1 -0
  44. package/dist/cjs/transformer/id.js +1 -5
  45. package/dist/cjs/transformer/index.js +0 -18
  46. package/dist/cjs/transformer/node-names.js +1 -0
  47. package/dist/cjs/transformer/node-types.js +1 -0
  48. package/dist/cjs/transformer/section-category.js +8 -0
  49. package/dist/cjs/version.js +1 -1
  50. package/dist/es/index.js +6 -5
  51. package/dist/es/jats/{jats-exporter.js → exporter/jats-exporter.js} +281 -411
  52. package/dist/es/jats/{jats-versions.js → exporter/jats-versions.js} +0 -1
  53. package/dist/es/{transformer → jats/exporter}/labels.js +7 -19
  54. package/dist/{cjs/transformer/model-map.js → es/jats/importer/create-article-node.js} +10 -10
  55. package/dist/es/jats/importer/jats-body-transformations.js +22 -1
  56. package/dist/es/jats/importer/jats-comments.js +49 -107
  57. package/dist/es/jats/importer/{jats-body-dom-parser.js → jats-dom-parser.js} +364 -11
  58. package/dist/es/jats/importer/jats-journal-meta-parser.js +9 -0
  59. package/dist/es/jats/importer/jats-parser-utils.js +54 -6
  60. package/dist/es/jats/importer/jats-transformations.js +370 -0
  61. package/dist/es/jats/importer/parse-jats-article.js +43 -98
  62. package/dist/es/jats/index.js +5 -3
  63. package/dist/{types/transformer/timestamp.d.ts → es/lib/deafults.js} +2 -2
  64. package/dist/es/lib/utils.js +1 -0
  65. package/dist/es/schema/index.js +10 -0
  66. package/dist/es/schema/migration/migrate.js +3 -9
  67. package/dist/es/schema/migration/migration-script.js +1 -1
  68. package/dist/es/schema/migration/migration-scripts/1.2.5.js +2 -2
  69. package/dist/es/schema/migration/migration-scripts/2.3.22.js +26 -0
  70. package/dist/es/schema/migration/migration-scripts/index.js +3 -2
  71. package/dist/es/schema/nodes/author_notes.js +9 -2
  72. package/dist/es/{transformer/__tests__/__helpers__/doc.js → schema/nodes/award.js} +19 -14
  73. package/dist/es/{transformer/model-map.js → schema/nodes/awards.js} +17 -7
  74. package/dist/es/schema/nodes/backmatter.js +3 -2
  75. package/dist/es/schema/nodes/box_element.js +52 -0
  76. package/dist/es/schema/nodes/contributors.js +1 -1
  77. package/dist/es/schema/nodes/corresp.js +11 -1
  78. package/dist/es/schema/nodes/equation_element.js +0 -1
  79. package/dist/es/schema/nodes/figure_element.js +0 -1
  80. package/dist/es/schema/nodes/footnote.js +0 -1
  81. package/dist/es/schema/nodes/footnotes_section.js +1 -1
  82. package/dist/es/schema/nodes/highlight_marker.js +0 -4
  83. package/dist/es/schema/nodes/inline_equation.js +0 -1
  84. package/dist/es/schema/nodes/inline_footnote.js +1 -0
  85. package/dist/es/schema/nodes/keyword.js +0 -1
  86. package/dist/es/schema/nodes/listing.js +0 -1
  87. package/dist/es/schema/nodes/listing_element.js +0 -1
  88. package/dist/es/schema/nodes/manuscript.js +4 -1
  89. package/dist/es/schema/nodes/paragraph.js +0 -1
  90. package/dist/es/schema/nodes/section.js +0 -1
  91. package/dist/es/schema/nodes/table_element.js +1 -2
  92. package/dist/es/schema/nodes/title.js +1 -0
  93. package/dist/es/transformer/id.js +0 -3
  94. package/dist/es/transformer/index.js +0 -16
  95. package/dist/es/transformer/node-names.js +1 -0
  96. package/dist/es/transformer/node-types.js +1 -0
  97. package/dist/es/transformer/section-category.js +8 -0
  98. package/dist/es/version.js +1 -1
  99. package/dist/types/index.d.ts +6 -5
  100. package/dist/types/jats/{jats-exporter.d.ts → exporter/jats-exporter.d.ts} +15 -29
  101. package/dist/types/jats/{jats-versions.d.ts → exporter/jats-versions.d.ts} +0 -1
  102. package/dist/types/{transformer → jats/exporter}/labels.d.ts +2 -3
  103. package/dist/{es/transformer/footnote-category.js → types/jats/importer/create-article-node.d.ts} +3 -2
  104. package/dist/types/jats/importer/jats-body-transformations.d.ts +1 -0
  105. package/dist/types/jats/importer/jats-comments.d.ts +2 -15
  106. package/dist/types/jats/importer/{jats-body-dom-parser.d.ts → jats-dom-parser.d.ts} +1 -1
  107. package/dist/types/jats/importer/jats-journal-meta-parser.d.ts +9 -0
  108. package/dist/types/jats/importer/jats-parser-utils.d.ts +2 -2
  109. package/dist/types/jats/importer/jats-transformations.d.ts +32 -0
  110. package/dist/types/jats/importer/parse-jats-article.d.ts +12 -5
  111. package/dist/types/jats/index.d.ts +5 -3
  112. package/dist/types/jats/types.d.ts +1 -0
  113. package/dist/{es/transformer/models.js → types/lib/deafults.d.ts} +2 -2
  114. package/dist/types/lib/utils.d.ts +1 -0
  115. package/dist/types/schema/index.d.ts +4 -0
  116. package/dist/types/schema/migration/migration-script.d.ts +1 -1
  117. package/dist/types/schema/migration/migration-scripts/1.2.5.d.ts +1 -1
  118. package/dist/types/schema/migration/migration-scripts/2.3.22.d.ts +8 -0
  119. package/dist/types/schema/migration/migration-scripts/index.d.ts +3 -2
  120. package/dist/types/{transformer/footnotes-order.d.ts → schema/nodes/award.d.ts} +14 -7
  121. package/dist/{cjs/transformer/footnote-category.js → types/schema/nodes/awards.d.ts} +12 -6
  122. package/dist/types/schema/nodes/bibliography_item.d.ts +3 -3
  123. package/dist/{es/transformer/filename.js → types/schema/nodes/box_element.d.ts} +11 -8
  124. package/dist/types/schema/nodes/contributor.d.ts +10 -0
  125. package/dist/types/schema/nodes/contributors.d.ts +8 -0
  126. package/dist/types/schema/nodes/corresp.d.ts +1 -0
  127. package/dist/types/schema/nodes/equation_element.d.ts +0 -2
  128. package/dist/types/schema/nodes/figure_element.d.ts +0 -2
  129. package/dist/types/schema/nodes/footnote.d.ts +0 -2
  130. package/dist/types/schema/nodes/highlight_marker.d.ts +0 -2
  131. package/dist/types/schema/nodes/inline_equation.d.ts +0 -2
  132. package/dist/types/schema/nodes/keyword.d.ts +0 -2
  133. package/dist/types/schema/nodes/keyword_group.d.ts +1 -0
  134. package/dist/types/schema/nodes/listing.d.ts +0 -2
  135. package/dist/types/schema/nodes/listing_element.d.ts +0 -2
  136. package/dist/types/schema/nodes/manuscript.d.ts +8 -4
  137. package/dist/types/schema/nodes/paragraph.d.ts +0 -2
  138. package/dist/types/schema/nodes/section.d.ts +0 -2
  139. package/dist/types/schema/nodes/table_element.d.ts +0 -2
  140. package/dist/types/schema/nodes/title.d.ts +1 -3
  141. package/dist/types/schema/types.d.ts +1 -1
  142. package/dist/types/transformer/id.d.ts +0 -3
  143. package/dist/types/transformer/index.d.ts +0 -16
  144. package/dist/types/transformer/section-category.d.ts +2 -2
  145. package/dist/types/version.d.ts +1 -1
  146. package/package.json +7 -8
  147. package/dist/cjs/__tests__/data/project-dump.json +0 -824
  148. package/dist/cjs/jats/importer/index.js +0 -22
  149. package/dist/cjs/jats/importer/jats-front-parser.js +0 -321
  150. package/dist/cjs/jats/importer/jats-reference-parser.js +0 -130
  151. package/dist/cjs/jats/importer/jats-references.js +0 -34
  152. package/dist/cjs/transformer/__tests__/__helpers__/doc.js +0 -37
  153. package/dist/cjs/transformer/builders.js +0 -219
  154. package/dist/cjs/transformer/decode.js +0 -878
  155. package/dist/cjs/transformer/document-object-types.js +0 -31
  156. package/dist/cjs/transformer/encode.js +0 -654
  157. package/dist/cjs/transformer/footnotes-order.js +0 -60
  158. package/dist/cjs/transformer/highlight-markers.js +0 -138
  159. package/dist/cjs/transformer/html.js +0 -401
  160. package/dist/cjs/transformer/manuscript-dependencies.js +0 -21
  161. package/dist/cjs/transformer/object-types.js +0 -57
  162. package/dist/cjs/transformer/project-bundle.js +0 -94
  163. package/dist/cjs/transformer/timestamp.js +0 -20
  164. package/dist/cjs/transformer/update-identifiers.js +0 -93
  165. package/dist/es/__tests__/data/project-dump.json +0 -824
  166. package/dist/es/jats/importer/index.js +0 -16
  167. package/dist/es/jats/importer/jats-front-parser.js +0 -315
  168. package/dist/es/jats/importer/jats-reference-parser.js +0 -127
  169. package/dist/es/jats/importer/jats-references.js +0 -30
  170. package/dist/es/transformer/builders.js +0 -186
  171. package/dist/es/transformer/decode.js +0 -868
  172. package/dist/es/transformer/document-object-types.js +0 -28
  173. package/dist/es/transformer/encode.js +0 -644
  174. package/dist/es/transformer/footnotes-order.js +0 -55
  175. package/dist/es/transformer/highlight-markers.js +0 -132
  176. package/dist/es/transformer/html.js +0 -394
  177. package/dist/es/transformer/manuscript-dependencies.js +0 -17
  178. package/dist/es/transformer/object-types.js +0 -52
  179. package/dist/es/transformer/project-bundle.js +0 -85
  180. package/dist/es/transformer/serializer.js +0 -17
  181. package/dist/es/transformer/timestamp.js +0 -16
  182. package/dist/es/transformer/update-identifiers.js +0 -87
  183. package/dist/types/jats/importer/index.d.ts +0 -16
  184. package/dist/types/jats/importer/jats-front-parser.d.ts +0 -84
  185. package/dist/types/jats/importer/jats-reference-parser.d.ts +0 -19
  186. package/dist/types/jats/importer/jats-references.d.ts +0 -12
  187. package/dist/types/transformer/__tests__/__helpers__/doc.d.ts +0 -18
  188. package/dist/types/transformer/builders.d.ts +0 -61
  189. package/dist/types/transformer/decode.d.ts +0 -50
  190. package/dist/types/transformer/document-object-types.d.ts +0 -17
  191. package/dist/types/transformer/encode.d.ts +0 -29
  192. package/dist/types/transformer/filename.d.ts +0 -16
  193. package/dist/types/transformer/footnote-category.d.ts +0 -17
  194. package/dist/types/transformer/highlight-markers.d.ts +0 -31
  195. package/dist/types/transformer/html.d.ts +0 -36
  196. package/dist/types/transformer/manuscript-dependencies.d.ts +0 -4
  197. package/dist/types/transformer/model-map.d.ts +0 -19
  198. package/dist/types/transformer/models.d.ts +0 -48
  199. package/dist/types/transformer/object-types.d.ts +0 -30
  200. package/dist/types/transformer/project-bundle.d.ts +0 -30
  201. package/dist/types/transformer/serializer.d.ts +0 -19
  202. package/dist/types/transformer/update-identifiers.d.ts +0 -23
  203. package/dist/types/types.d.ts +0 -2
  204. /package/dist/cjs/{types.js → jats/types.js} +0 -0
  205. /package/dist/es/{types.js → jats/types.js} +0 -0
@@ -1,60 +0,0 @@
1
- "use strict";
2
- /*!
3
- * © 2022 Atypon Systems LLC
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.handleFootnotesOrder = exports.createOrderedFootnotesIDs = void 0;
19
- const createOrderedFootnotesIDs = (doc) => {
20
- const footnotesRefs = [...doc.querySelectorAll('xref[ref-type="fn"][rid]')];
21
- const footnotes = [...doc.querySelectorAll('fn:not([fn-type])')];
22
- const authorNotesIDs = [...doc.querySelectorAll('author-notes > fn')].map((an) => an.getAttribute('id'));
23
- const tableElementFooters = [
24
- ...doc.querySelectorAll('table-wrap-foot > fn'),
25
- ].map((footer) => footer.getAttribute('id'));
26
- const orderedFootnotesIDs = [];
27
- footnotesRefs.forEach((ref) => {
28
- const refID = ref.getAttribute('rid');
29
- if (refID) {
30
- orderedFootnotesIDs.push(refID);
31
- }
32
- });
33
- footnotes.forEach((footnote) => {
34
- const id = footnote.getAttribute('id');
35
- if (id &&
36
- !authorNotesIDs.includes(id) &&
37
- !orderedFootnotesIDs.includes(id) &&
38
- !tableElementFooters.includes(id)) {
39
- orderedFootnotesIDs.push(id);
40
- }
41
- });
42
- return orderedFootnotesIDs;
43
- };
44
- exports.createOrderedFootnotesIDs = createOrderedFootnotesIDs;
45
- const handleFootnotesOrder = (orderedFootnotesIDs, replacements, footnotesOrder) => {
46
- const footnotesList = [];
47
- let index = 0;
48
- orderedFootnotesIDs.forEach((refID) => {
49
- const fnID = replacements.get(refID);
50
- if (fnID) {
51
- footnotesList.push({
52
- index,
53
- id: fnID,
54
- });
55
- index++;
56
- }
57
- });
58
- footnotesOrder.footnotesList = footnotesList;
59
- };
60
- exports.handleFootnotesOrder = handleFootnotesOrder;
@@ -1,138 +0,0 @@
1
- "use strict";
2
- /*!
3
- * © 2019 Atypon Systems LLC
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.insertHighlightMarkers = exports.extractCommentMarkers = exports.isHighlightableModel = exports.highlightableFields = void 0;
19
- exports.highlightableFields = [
20
- 'caption',
21
- 'contents',
22
- 'title',
23
- ];
24
- const isHighlightableModel = (model) => {
25
- for (const field of exports.highlightableFields) {
26
- if (field in model) {
27
- return true;
28
- }
29
- }
30
- return false;
31
- };
32
- exports.isHighlightableModel = isHighlightableModel;
33
- const extractCommentMarkers = (model) => {
34
- if (!(0, exports.isHighlightableModel)(model)) {
35
- return [];
36
- }
37
- const comments = new Map();
38
- for (const field of exports.highlightableFields) {
39
- let html = model[field];
40
- if (!html || !html.includes('highlight-marker')) {
41
- continue;
42
- }
43
- const template = document.createElement('template');
44
- template.innerHTML = `<div>${html}</div>`;
45
- const element = template.content.firstChild;
46
- if (!element) {
47
- continue;
48
- }
49
- const markers = element.querySelectorAll('span.highlight-marker');
50
- if (!markers.length) {
51
- continue;
52
- }
53
- for (const marker of markers) {
54
- const markerHTML = marker.outerHTML;
55
- const offset = html.indexOf(markerHTML);
56
- if (offset === -1) {
57
- continue;
58
- }
59
- const id = marker.getAttribute('id');
60
- const target = marker.getAttribute('data-target-id');
61
- if (id && target) {
62
- const position = marker.getAttribute('data-position');
63
- if (position === 'start') {
64
- const comment = {
65
- _id: id,
66
- from: offset,
67
- to: -1,
68
- };
69
- comments.set(id, comment);
70
- }
71
- else if (position === 'end') {
72
- const comment = comments.get(id);
73
- if (comment) {
74
- comment.to = offset;
75
- }
76
- }
77
- else if (position === 'point') {
78
- const comment = {
79
- _id: id,
80
- from: offset,
81
- to: offset,
82
- };
83
- comments.set(id, comment);
84
- }
85
- }
86
- html =
87
- html.substring(0, offset) + html.substring(offset + markerHTML.length);
88
- }
89
- model[field] = html;
90
- }
91
- return Array.from(comments.values());
92
- };
93
- exports.extractCommentMarkers = extractCommentMarkers;
94
- const insertHighlightMarkers = (contents, commentAnnotations) => {
95
- let output = contents;
96
- const sortedComments = commentAnnotations.sort((a, b) => {
97
- if (a.selector && b.selector) {
98
- return b.selector.from - a.selector.from;
99
- }
100
- else {
101
- return 0;
102
- }
103
- });
104
- for (const comment of sortedComments) {
105
- let element;
106
- if (comment.selector) {
107
- if (comment.selector.from === comment.selector.to) {
108
- element = createHighlightElement(comment, 'point');
109
- output = injectHighlightMarker(element, comment.selector.from, output);
110
- }
111
- else {
112
- element = createHighlightElement(comment, 'start');
113
- output = injectHighlightMarker(element, comment.selector.from, output);
114
- const updatedEndOffset = element.outerHTML.length + comment.selector.to;
115
- element = createHighlightElement(comment, 'end');
116
- output = injectHighlightMarker(element, updatedEndOffset, output);
117
- }
118
- }
119
- }
120
- return output;
121
- };
122
- exports.insertHighlightMarkers = insertHighlightMarkers;
123
- function injectHighlightMarker(element, offset, contents) {
124
- const parts = [
125
- contents.substring(0, offset),
126
- element.outerHTML,
127
- contents.substring(offset),
128
- ];
129
- return parts.join('');
130
- }
131
- const createHighlightElement = (comment, position) => {
132
- const element = document.createElement('span');
133
- element.className = 'highlight-marker';
134
- element.setAttribute('id', comment._id);
135
- element.setAttribute('data-target-id', comment.target);
136
- element.setAttribute('data-position', position);
137
- return element;
138
- };
@@ -1,401 +0,0 @@
1
- "use strict";
2
- /*!
3
- * © 2019 Atypon Systems LLC
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- var __importDefault = (this && this.__importDefault) || function (mod) {
18
- return (mod && mod.__esModule) ? mod : { "default": mod };
19
- };
20
- Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.HTMLTransformer = void 0;
22
- const json_schema_1 = require("@manuscripts/json-schema");
23
- const prosemirror_model_1 = require("prosemirror-model");
24
- const w3c_xmlserializer_1 = __importDefault(require("w3c-xmlserializer"));
25
- const jats_exporter_1 = require("../jats/jats-exporter");
26
- const styled_content_1 = require("../lib/styled-content");
27
- const schema_1 = require("../schema");
28
- const filename_1 = require("./filename");
29
- const labels_1 = require("./labels");
30
- const node_types_1 = require("./node-types");
31
- const object_types_1 = require("./object-types");
32
- const project_bundle_1 = require("./project-bundle");
33
- const section_category_1 = require("./section-category");
34
- const chooseNodeName = (element) => {
35
- const nodeName = element.nodeName.toLowerCase();
36
- if (nodeName === 'figure') {
37
- if (element.classList.contains('table')) {
38
- return 'figure-table';
39
- }
40
- if (element.classList.contains('listing')) {
41
- return 'figure-listing';
42
- }
43
- if (element.classList.contains('equation')) {
44
- return 'figure-equation';
45
- }
46
- return 'figure';
47
- }
48
- else if (nodeName === 'section') {
49
- const sectionCategory = element.getAttribute('data-category');
50
- if (sectionCategory) {
51
- const secType = (0, section_category_1.chooseSecType)(sectionCategory);
52
- if (secType) {
53
- return secType;
54
- }
55
- }
56
- }
57
- else if (element.classList.length === 1) {
58
- const className = element.classList.item(0);
59
- if (className && !className.startsWith('MP')) {
60
- return className;
61
- }
62
- }
63
- return nodeName;
64
- };
65
- const createDefaultIdGenerator = () => {
66
- const counter = (0, jats_exporter_1.createCounter)();
67
- return async (element) => {
68
- const nodeName = chooseNodeName(element);
69
- const index = counter.increment(nodeName);
70
- return `${nodeName}-${index}`;
71
- };
72
- };
73
- class HTMLTransformer {
74
- constructor() {
75
- this.serializeToHTML = async (fragment, modelMap, options = {}) => {
76
- const { idGenerator, mediaPathGenerator } = options;
77
- this.modelMap = modelMap;
78
- const manuscript = (0, project_bundle_1.findManuscript)(this.modelMap);
79
- this.labelTargets = (0, labels_1.buildTargets)(fragment, manuscript);
80
- this.document = document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'html', document.implementation.createDocumentType('html', '', ''));
81
- const article = this.document.createElement('article');
82
- this.document.documentElement.appendChild(article);
83
- article.appendChild(this.buildFront());
84
- article.appendChild(this.buildBody(fragment));
85
- this.fixBody(fragment);
86
- await this.rewriteIDs(idGenerator);
87
- if (mediaPathGenerator) {
88
- await this.rewriteMediaPaths(mediaPathGenerator);
89
- }
90
- return (0, w3c_xmlserializer_1.default)(this.document);
91
- };
92
- this.rewriteMediaPaths = async (mediaPathGenerator) => {
93
- for (const image of this.document.querySelectorAll('figure > img')) {
94
- const parentFigure = image.parentNode;
95
- if (parentFigure) {
96
- const parentID = parentFigure.getAttribute('data-uuid');
97
- if (parentID) {
98
- const newSrc = await mediaPathGenerator(image, parentID);
99
- image.setAttribute('src', newSrc);
100
- }
101
- }
102
- }
103
- };
104
- this.rewriteIDs = async (idGenerator = createDefaultIdGenerator()) => {
105
- const idMap = new Map();
106
- for (const element of this.document.querySelectorAll('[id]')) {
107
- const previousID = element.getAttribute('id');
108
- if (previousID && !previousID.match(/^MP[a-z]+:[a-z0-9-]+$/i)) {
109
- continue;
110
- }
111
- const newID = await idGenerator(element);
112
- if (newID) {
113
- element.setAttribute('id', newID);
114
- if (previousID) {
115
- const ancores = [
116
- ...this.document.querySelectorAll(`a[href="#${previousID}"]`),
117
- ];
118
- ancores.map((a) => a.setAttribute('href', `#${newID}`));
119
- element.setAttribute('data-uuid', previousID);
120
- }
121
- }
122
- else {
123
- element.removeAttribute('id');
124
- }
125
- if (previousID) {
126
- idMap.set(previousID, newID);
127
- }
128
- }
129
- for (const node of this.document.querySelectorAll('[data-reference-ids]')) {
130
- const rids = node.getAttribute('data-reference-ids');
131
- if (rids) {
132
- const newRIDs = rids
133
- .split(/\s+/)
134
- .filter(Boolean)
135
- .map((previousRID) => idMap.get(previousRID))
136
- .filter(Boolean);
137
- if (newRIDs.length) {
138
- node.setAttribute('data-reference-ids', newRIDs.join(' '));
139
- }
140
- }
141
- }
142
- for (const node of this.document.querySelectorAll('[data-reference-id]')) {
143
- const rid = node.getAttribute('data-reference-id');
144
- if (rid) {
145
- const newRID = idMap.get(rid);
146
- if (newRID) {
147
- node.setAttribute('data-reference-id', newRID);
148
- }
149
- }
150
- }
151
- };
152
- this.buildFront = () => {
153
- const manuscript = (0, project_bundle_1.findManuscript)(this.modelMap);
154
- const journal = (0, project_bundle_1.findJournal)(this.modelMap);
155
- const titles = (0, project_bundle_1.findTitles)(this.modelMap);
156
- if (!manuscript) {
157
- throw new Error('Manuscript not found in project modelMap');
158
- }
159
- const front = this.document.createElement('header');
160
- if (manuscript.headerFigure) {
161
- const figure = this.modelMap.get(manuscript.headerFigure);
162
- if (figure) {
163
- const headerFigure = document.createElement('figure');
164
- headerFigure.setAttribute('id', figure._id);
165
- front.appendChild(headerFigure);
166
- const filename = (0, filename_1.generateAttachmentFilename)(figure._id, figure.contentType);
167
- const img = this.document.createElement('img');
168
- img.setAttribute('src', filename);
169
- headerFigure.appendChild(img);
170
- }
171
- }
172
- const articleMeta = this.document.createElement('div');
173
- front.appendChild(articleMeta);
174
- const title = this.document.createElement('h1');
175
- if (titles.title) {
176
- title.innerHTML = titles.title;
177
- }
178
- if (journal === null || journal === void 0 ? void 0 : journal.title) {
179
- title.setAttribute('data-journal', journal.title);
180
- }
181
- articleMeta.appendChild(title);
182
- if (manuscript.DOI) {
183
- const articleID = this.document.createElement('article-id');
184
- articleID.setAttribute('pub-id-type', 'doi');
185
- articleID.innerHTML = manuscript.DOI;
186
- articleMeta.append(articleID);
187
- }
188
- this.buildContributors(articleMeta);
189
- return front;
190
- };
191
- this.buildBody = (fragment) => {
192
- const getModel = (id) => id ? this.modelMap.get(id) : undefined;
193
- const nodes = {};
194
- for (const [name, node] of Object.entries(schema_1.schema.nodes)) {
195
- if (node.spec.toDOM) {
196
- nodes[name] = node.spec.toDOM;
197
- }
198
- }
199
- nodes.citation = (node) => {
200
- const citationNode = node;
201
- const element = this.document.createElement('span');
202
- element.setAttribute('class', 'citation');
203
- const rids = citationNode.attrs.rids;
204
- if (rids.length) {
205
- element.setAttribute('data-reference-ids', rids.join(' '));
206
- }
207
- if (citationNode.attrs.contents) {
208
- element.innerHTML = citationNode.attrs.contents;
209
- }
210
- return element;
211
- };
212
- nodes.cross_reference = (node) => {
213
- const xref = node;
214
- const element = this.document.createElement('a');
215
- element.classList.add('cross-reference');
216
- element.setAttribute('data-reference-ids', xref.attrs.rids.join(' '));
217
- element.textContent = xref.attrs.customLabel || xref.attrs.label;
218
- return element;
219
- };
220
- nodes.listing = (node) => {
221
- const listingNode = node;
222
- const pre = this.document.createElement('pre');
223
- if (listingNode.attrs.id) {
224
- pre.setAttribute('id', listingNode.attrs.id);
225
- }
226
- pre.classList.add('listing');
227
- const code = this.document.createElement('code');
228
- if (listingNode.attrs.languageKey) {
229
- code.setAttribute('data-language', listingNode.attrs.languageKey);
230
- }
231
- code.textContent = listingNode.attrs.contents;
232
- pre.appendChild(code);
233
- return pre;
234
- };
235
- nodes.text = (node) => node.text;
236
- const marks = {};
237
- for (const [name, mark] of Object.entries(schema_1.schema.marks)) {
238
- if (mark.spec.toDOM) {
239
- marks[name] = mark.spec.toDOM;
240
- }
241
- }
242
- marks.styled = (mark) => {
243
- const inlineStyle = getModel(mark.attrs.rid);
244
- const attrs = {
245
- class: (0, styled_content_1.buildStyledContentClass)(mark.attrs, inlineStyle),
246
- };
247
- return ['span', attrs];
248
- };
249
- nodes.comments = () => '';
250
- const serializer = new prosemirror_model_1.DOMSerializer(nodes, marks);
251
- return serializer.serializeFragment(fragment, { document });
252
- };
253
- this.idSelector = (id) => '#' + id.replace(/:/g, '\\:');
254
- this.fixFigure = (node) => {
255
- const figure = this.document.querySelector(`[id="${node.attrs.id}"]`);
256
- if (figure) {
257
- const filename = (0, filename_1.generateAttachmentFilename)(node.attrs.id, node.attrs.contentType);
258
- const img = this.document.createElement('img');
259
- img.setAttribute('src', filename);
260
- figure.insertBefore(img, figure.firstChild);
261
- }
262
- };
263
- this.fixBody = (fragment) => {
264
- fragment.descendants((node) => {
265
- if (node.attrs.id) {
266
- const selector = this.idSelector(node.attrs.id);
267
- const element = this.document.querySelector(`${selector}`);
268
- if (element && this.labelTargets) {
269
- const target = this.labelTargets.get(node.attrs.id);
270
- if (target) {
271
- const label = this.document.createElement('label');
272
- label.textContent = target.label;
273
- element.appendChild(label);
274
- }
275
- }
276
- if (node.attrs.titleSuppressed) {
277
- const title = this.document.querySelector(`${selector} > h1`);
278
- if (title && title.parentNode) {
279
- title.parentNode.removeChild(title);
280
- }
281
- }
282
- if (node.attrs.suppressCaption) {
283
- const caption = this.document.querySelector(`${selector} > figcaption`);
284
- if (caption && caption.parentNode) {
285
- caption.parentNode.removeChild(caption);
286
- }
287
- }
288
- if ((0, node_types_1.isNodeType)(node, 'figure')) {
289
- this.fixFigure(node);
290
- }
291
- if ((0, node_types_1.isNodeType)(node, 'figure_element')) {
292
- const figureGroup = this.document.querySelector(`${selector}`);
293
- if (figureGroup) {
294
- const figures = this.document.querySelectorAll(`${selector} > figure`);
295
- const caption = this.document.querySelector(`${selector} > figcaption`);
296
- const listing = this.document.querySelector(`${selector} > pre.listing`);
297
- if (listing && !listing.textContent) {
298
- listing.remove();
299
- }
300
- if (figures.length === 1) {
301
- const [figure] = figures;
302
- figure.setAttribute('data-fig-type', 'figure');
303
- if (caption) {
304
- figure.insertBefore(caption, figure.firstChild);
305
- }
306
- const label = this.document.querySelector(`${selector} > label`);
307
- if (label) {
308
- figure.insertBefore(label, figure.firstChild);
309
- }
310
- if (figureGroup.parentElement) {
311
- figureGroup.parentElement.replaceChild(figure, figureGroup);
312
- }
313
- }
314
- if (figures.length === 0 && !caption) {
315
- figureGroup.remove();
316
- }
317
- }
318
- }
319
- }
320
- });
321
- };
322
- }
323
- buildContributors(articleMeta) {
324
- const contributors = Array.from(this.modelMap.values()).filter((0, object_types_1.hasObjectType)(json_schema_1.ObjectTypes.Contributor));
325
- const affiliationIDs = [];
326
- if (contributors && contributors.length) {
327
- const contribGroup = this.document.createElement('div');
328
- contribGroup.classList.add('contrib-group');
329
- articleMeta.appendChild(contribGroup);
330
- contributors.sort((a, b) => Number(a.priority) - Number(b.priority));
331
- contributors.forEach((contributor) => {
332
- const contrib = this.document.createElement('span');
333
- contrib.classList.add('contrib');
334
- contrib.setAttribute('id', contributor._id);
335
- if (contributor.isCorresponding) {
336
- contrib.setAttribute('data-corresp', 'yes');
337
- }
338
- const name = this.document.createElement('span');
339
- name.classList.add('contrib-name');
340
- contrib.appendChild(name);
341
- const { given, family } = contributor.bibliographicName;
342
- if (given) {
343
- const givenNames = this.document.createElement('span');
344
- givenNames.classList.add('contrib-given-names');
345
- givenNames.textContent = given;
346
- name.appendChild(givenNames);
347
- }
348
- if (family) {
349
- if (given) {
350
- const separator = document.createTextNode(' ');
351
- name.appendChild(separator);
352
- }
353
- const surname = this.document.createElement('span');
354
- surname.classList.add('contrib-surname');
355
- surname.textContent = family;
356
- name.appendChild(surname);
357
- }
358
- if (contributor.email) {
359
- const link = this.document.createElement('a');
360
- link.href = `mailto:${contributor.email}`;
361
- contrib.appendChild(link);
362
- }
363
- if (contributor.affiliations) {
364
- contributor.affiliations.forEach((rid) => {
365
- const link = this.document.createElement('a');
366
- link.setAttribute('data-ref-type', 'aff');
367
- link.setAttribute('href', '#' + rid);
368
- const affiliationIndex = affiliationIDs.indexOf(rid);
369
- if (affiliationIndex > -1) {
370
- link.textContent = String(affiliationIndex + 1);
371
- }
372
- else {
373
- affiliationIDs.push(rid);
374
- link.textContent = String(affiliationIDs.length);
375
- }
376
- contrib.appendChild(link);
377
- });
378
- }
379
- contribGroup.appendChild(contrib);
380
- });
381
- }
382
- if (affiliationIDs.length) {
383
- const affiliationList = this.document.createElement('ol');
384
- affiliationList.classList.add('affiliations-list');
385
- articleMeta.appendChild(affiliationList);
386
- for (const affiliationID of affiliationIDs) {
387
- const affiliation = this.modelMap.get(affiliationID);
388
- if (affiliation) {
389
- const affiliationItem = this.document.createElement('li');
390
- affiliationItem.classList.add('affiliation');
391
- affiliationItem.setAttribute('id', affiliation._id);
392
- if (affiliation.institution) {
393
- affiliationItem.textContent = affiliation.institution;
394
- }
395
- affiliationList.appendChild(affiliationItem);
396
- }
397
- }
398
- }
399
- }
400
- }
401
- exports.HTMLTransformer = HTMLTransformer;
@@ -1,21 +0,0 @@
1
- "use strict";
2
- var __rest = (this && this.__rest) || function (s, e) {
3
- var t = {};
4
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
- t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
- t[p[i]] = s[p[i]];
10
- }
11
- return t;
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.fromPrototype = void 0;
15
- const id_1 = require("./id");
16
- const fromPrototype = (model) => {
17
- const { _id } = model, data = __rest(model, ["_id"]);
18
- const output = Object.assign(Object.assign({}, data), { prototype: _id, _id: (0, id_1.generateID)(model.objectType) });
19
- return output;
20
- };
21
- exports.fromPrototype = fromPrototype;
@@ -1,57 +0,0 @@
1
- "use strict";
2
- /*!
3
- * © 2019 Atypon Systems LLC
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.isKeyword = exports.isCommentAnnotation = exports.isTable = exports.isManuscript = exports.isFigure = exports.hasObjectType = exports.isManuscriptModel = exports.manuscriptObjects = exports.elementObjects = exports.ExtraObjectTypes = void 0;
19
- const json_schema_1 = require("@manuscripts/json-schema");
20
- var ExtraObjectTypes;
21
- (function (ExtraObjectTypes) {
22
- ExtraObjectTypes["PlaceholderElement"] = "MPPlaceholderElement";
23
- ExtraObjectTypes["GeneralTableFootnote"] = "MPGeneralTableFootnote";
24
- })(ExtraObjectTypes = exports.ExtraObjectTypes || (exports.ExtraObjectTypes = {}));
25
- exports.elementObjects = [
26
- json_schema_1.ObjectTypes.BibliographyElement,
27
- json_schema_1.ObjectTypes.EquationElement,
28
- json_schema_1.ObjectTypes.FigureElement,
29
- json_schema_1.ObjectTypes.FootnotesElement,
30
- json_schema_1.ObjectTypes.ListElement,
31
- json_schema_1.ObjectTypes.ListingElement,
32
- json_schema_1.ObjectTypes.ParagraphElement,
33
- json_schema_1.ObjectTypes.TableElement,
34
- json_schema_1.ObjectTypes.TOCElement,
35
- ];
36
- exports.manuscriptObjects = [
37
- json_schema_1.ObjectTypes.Affiliation,
38
- json_schema_1.ObjectTypes.Citation,
39
- json_schema_1.ObjectTypes.CommentAnnotation,
40
- json_schema_1.ObjectTypes.Contributor,
41
- json_schema_1.ObjectTypes.Footnote,
42
- json_schema_1.ObjectTypes.Section,
43
- ].concat(exports.elementObjects);
44
- const isManuscriptModel = (model) => {
45
- if (!model.objectType) {
46
- throw new Error('Model must have objectType');
47
- }
48
- return json_schema_1.manuscriptIDTypes.has(model.objectType);
49
- };
50
- exports.isManuscriptModel = isManuscriptModel;
51
- const hasObjectType = (objectType) => (model) => model.objectType === objectType;
52
- exports.hasObjectType = hasObjectType;
53
- exports.isFigure = (0, exports.hasObjectType)(json_schema_1.ObjectTypes.Figure);
54
- exports.isManuscript = (0, exports.hasObjectType)(json_schema_1.ObjectTypes.Manuscript);
55
- exports.isTable = (0, exports.hasObjectType)(json_schema_1.ObjectTypes.Table);
56
- exports.isCommentAnnotation = (0, exports.hasObjectType)(json_schema_1.ObjectTypes.CommentAnnotation);
57
- exports.isKeyword = (0, exports.hasObjectType)(json_schema_1.ObjectTypes.Keyword);