@manuscripts/transform 2.3.37 → 2.3.38-LEAN-3911.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 (123) hide show
  1. package/dist/cjs/index.js +6 -6
  2. package/dist/cjs/jats/{jats-exporter.js → exporter/jats-exporter.js} +263 -390
  3. package/dist/cjs/jats/{jats-versions.js → exporter/jats-versions.js} +1 -3
  4. package/dist/cjs/{transformer → jats/exporter}/labels.js +4 -4
  5. package/dist/cjs/{transformer/filename.js → jats/importer/create-article-node.js} +10 -9
  6. package/dist/cjs/jats/importer/jats-body-transformations.js +73 -0
  7. package/dist/cjs/jats/importer/jats-comments.js +27 -104
  8. package/dist/cjs/jats/importer/{jats-body-dom-parser.js → jats-dom-parser.js} +281 -10
  9. package/dist/cjs/jats/importer/jats-front-transformations.js +79 -0
  10. package/dist/cjs/jats/importer/jats-journal-meta-parser.js +8 -1
  11. package/dist/cjs/jats/importer/jats-parser-utils.js +43 -5
  12. package/dist/cjs/jats/importer/jats-reference-parser.js +16 -23
  13. package/dist/cjs/jats/importer/jats-references.js +18 -18
  14. package/dist/cjs/jats/importer/parse-jats-article.js +40 -78
  15. package/dist/cjs/jats/index.js +7 -7
  16. package/dist/cjs/{transformer/models.js → lib/deafults.js} +3 -1
  17. package/dist/cjs/lib/utils.js +12 -1
  18. package/dist/cjs/transformer/id.js +10 -5
  19. package/dist/cjs/transformer/index.js +0 -18
  20. package/dist/cjs/version.js +1 -1
  21. package/dist/es/index.js +5 -5
  22. package/dist/es/jats/{jats-exporter.js → exporter/jats-exporter.js} +257 -384
  23. package/dist/es/jats/{jats-versions.js → exporter/jats-versions.js} +0 -1
  24. package/dist/es/{transformer → jats/exporter}/labels.js +4 -4
  25. package/dist/es/{transformer/filename.js → jats/importer/create-article-node.js} +8 -7
  26. package/dist/es/jats/importer/jats-body-transformations.js +73 -0
  27. package/dist/es/jats/importer/jats-comments.js +26 -101
  28. package/dist/es/jats/importer/{jats-body-dom-parser.js → jats-dom-parser.js} +282 -11
  29. package/dist/es/jats/importer/jats-front-transformations.js +76 -0
  30. package/dist/es/jats/importer/jats-journal-meta-parser.js +6 -0
  31. package/dist/es/jats/importer/jats-parser-utils.js +44 -6
  32. package/dist/es/jats/importer/jats-reference-parser.js +16 -23
  33. package/dist/es/jats/importer/jats-references.js +18 -18
  34. package/dist/es/jats/importer/parse-jats-article.js +41 -77
  35. package/dist/es/jats/index.js +5 -3
  36. package/dist/{types/transformer/timestamp.d.ts → es/lib/deafults.js} +2 -2
  37. package/dist/es/lib/utils.js +9 -0
  38. package/dist/es/transformer/id.js +8 -3
  39. package/dist/es/transformer/index.js +0 -16
  40. package/dist/es/version.js +1 -1
  41. package/dist/types/index.d.ts +6 -6
  42. package/dist/types/jats/{jats-exporter.d.ts → exporter/jats-exporter.d.ts} +15 -29
  43. package/dist/types/jats/{jats-versions.d.ts → exporter/jats-versions.d.ts} +0 -1
  44. package/dist/types/{transformer → jats/exporter}/labels.d.ts +2 -2
  45. package/dist/{es/transformer/footnote-category.js → types/jats/importer/create-article-node.d.ts} +3 -2
  46. package/dist/types/jats/importer/jats-body-transformations.d.ts +5 -0
  47. package/dist/types/jats/importer/jats-comments.d.ts +4 -10
  48. package/dist/types/jats/importer/{jats-body-dom-parser.d.ts → jats-dom-parser.d.ts} +1 -1
  49. package/dist/{cjs/transformer/serializer.js → types/jats/importer/jats-front-transformations.d.ts} +7 -8
  50. package/dist/types/jats/importer/jats-journal-meta-parser.d.ts +10 -0
  51. package/dist/types/jats/importer/jats-references.d.ts +19 -8
  52. package/dist/types/jats/importer/parse-jats-article.d.ts +12 -5
  53. package/dist/types/jats/index.d.ts +5 -3
  54. package/dist/types/jats/types.d.ts +1 -0
  55. package/dist/{es/transformer/models.js → types/lib/deafults.d.ts} +2 -2
  56. package/dist/types/lib/utils.d.ts +2 -0
  57. package/dist/types/schema/nodes/bibliography_item.d.ts +3 -3
  58. package/dist/types/schema/nodes/contributor.d.ts +10 -0
  59. package/dist/types/schema/nodes/keyword_group.d.ts +1 -0
  60. package/dist/types/schema/nodes/manuscript.d.ts +8 -7
  61. package/dist/types/schema/nodes/title.d.ts +0 -3
  62. package/dist/types/transformer/id.d.ts +5 -2
  63. package/dist/types/transformer/index.d.ts +0 -16
  64. package/dist/types/version.d.ts +1 -1
  65. package/package.json +2 -1
  66. package/dist/cjs/__tests__/data/project-dump.json +0 -825
  67. package/dist/cjs/jats/importer/index.js +0 -22
  68. package/dist/cjs/jats/importer/jats-front-parser.js +0 -321
  69. package/dist/cjs/transformer/__tests__/__helpers__/doc.js +0 -37
  70. package/dist/cjs/transformer/builders.js +0 -219
  71. package/dist/cjs/transformer/decode.js +0 -874
  72. package/dist/cjs/transformer/document-object-types.js +0 -31
  73. package/dist/cjs/transformer/encode.js +0 -664
  74. package/dist/cjs/transformer/footnote-category.js +0 -20
  75. package/dist/cjs/transformer/footnotes-order.js +0 -60
  76. package/dist/cjs/transformer/highlight-markers.js +0 -138
  77. package/dist/cjs/transformer/html.js +0 -400
  78. package/dist/cjs/transformer/manuscript-dependencies.js +0 -21
  79. package/dist/cjs/transformer/model-map.js +0 -26
  80. package/dist/cjs/transformer/object-types.js +0 -57
  81. package/dist/cjs/transformer/project-bundle.js +0 -94
  82. package/dist/cjs/transformer/timestamp.js +0 -20
  83. package/dist/cjs/transformer/update-identifiers.js +0 -93
  84. package/dist/es/__tests__/data/project-dump.json +0 -825
  85. package/dist/es/jats/importer/index.js +0 -16
  86. package/dist/es/jats/importer/jats-front-parser.js +0 -315
  87. package/dist/es/transformer/__tests__/__helpers__/doc.js +0 -29
  88. package/dist/es/transformer/builders.js +0 -186
  89. package/dist/es/transformer/decode.js +0 -864
  90. package/dist/es/transformer/document-object-types.js +0 -28
  91. package/dist/es/transformer/encode.js +0 -654
  92. package/dist/es/transformer/footnotes-order.js +0 -55
  93. package/dist/es/transformer/highlight-markers.js +0 -132
  94. package/dist/es/transformer/html.js +0 -393
  95. package/dist/es/transformer/manuscript-dependencies.js +0 -17
  96. package/dist/es/transformer/model-map.js +0 -22
  97. package/dist/es/transformer/object-types.js +0 -52
  98. package/dist/es/transformer/project-bundle.js +0 -85
  99. package/dist/es/transformer/serializer.js +0 -17
  100. package/dist/es/transformer/timestamp.js +0 -16
  101. package/dist/es/transformer/update-identifiers.js +0 -87
  102. package/dist/types/jats/importer/index.d.ts +0 -16
  103. package/dist/types/jats/importer/jats-front-parser.d.ts +0 -84
  104. package/dist/types/transformer/__tests__/__helpers__/doc.d.ts +0 -18
  105. package/dist/types/transformer/builders.d.ts +0 -61
  106. package/dist/types/transformer/decode.d.ts +0 -51
  107. package/dist/types/transformer/document-object-types.d.ts +0 -17
  108. package/dist/types/transformer/encode.d.ts +0 -29
  109. package/dist/types/transformer/filename.d.ts +0 -16
  110. package/dist/types/transformer/footnote-category.d.ts +0 -17
  111. package/dist/types/transformer/footnotes-order.d.ts +0 -22
  112. package/dist/types/transformer/highlight-markers.d.ts +0 -31
  113. package/dist/types/transformer/html.d.ts +0 -36
  114. package/dist/types/transformer/manuscript-dependencies.d.ts +0 -4
  115. package/dist/types/transformer/model-map.d.ts +0 -19
  116. package/dist/types/transformer/models.d.ts +0 -48
  117. package/dist/types/transformer/object-types.d.ts +0 -30
  118. package/dist/types/transformer/project-bundle.d.ts +0 -30
  119. package/dist/types/transformer/serializer.d.ts +0 -19
  120. package/dist/types/transformer/update-identifiers.d.ts +0 -23
  121. package/dist/types/types.d.ts +0 -2
  122. /package/dist/cjs/{types.js → jats/types.js} +0 -0
  123. /package/dist/es/{types.js → jats/types.js} +0 -0
@@ -13,48 +13,22 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { getModelsByType, ObjectTypes, } from '@manuscripts/json-schema';
16
+ import { ObjectTypes, } from '@manuscripts/json-schema';
17
17
  import { CitationProvider } from '@manuscripts/library';
18
18
  import debug from 'debug';
19
19
  import { DOMParser as ProsemirrorDOMParser, DOMSerializer, } from 'prosemirror-model';
20
+ import { findChildrenByAttr, findChildrenByType } from 'prosemirror-utils';
20
21
  import serializeToXML from 'w3c-xmlserializer';
21
- import { nodeFromHTML, textFromHTML } from '../lib/html';
22
- import { normalizeStyleName } from '../lib/styled-content';
23
- import { iterateChildren } from '../lib/utils';
24
- import { isCitationNode, schema, } from '../schema';
25
- import { generateAttachmentFilename } from '../transformer/filename';
26
- import { buildTargets } from '../transformer/labels';
27
- import { isExecutableNodeType, isNodeType } from '../transformer/node-types';
28
- import { hasObjectType } from '../transformer/object-types';
29
- import { findManuscript, findManuscriptById, findTitles, } from '../transformer/project-bundle';
30
- import { chooseJatsFnType, chooseSecType, } from '../transformer/section-category';
22
+ import { nodeFromHTML, textFromHTML } from '../../lib/html';
23
+ import { generateAttachmentFilename } from '../../lib/utils';
24
+ import { isCitationNode, schema, } from '../../schema';
25
+ import { chooseJatsFnType, chooseSecType, isExecutableNodeType, isNodeType, } from '../../transformer';
31
26
  import { selectVersionIds } from './jats-versions';
27
+ import { buildTargets } from './labels';
32
28
  const warn = debug('manuscripts-transform');
33
29
  const XLINK_NAMESPACE = 'http://www.w3.org/1999/xlink';
34
30
  const normalizeID = (id) => id.replace(/:/g, '_');
35
31
  const parser = ProsemirrorDOMParser.fromSchema(schema);
36
- const findChildNodeOfType = (node, nodeType) => {
37
- for (const child of iterateChildren(node)) {
38
- if (child.type === nodeType) {
39
- return child;
40
- }
41
- }
42
- };
43
- const isContributor = hasObjectType(ObjectTypes.Contributor);
44
- const CREDIT_VOCAB_IDENTIFIER = 'https://dictionary.casrai.org/Contributor_Roles';
45
- const chooseRoleVocabAttributes = (role) => {
46
- if (role.uri && role.uri.startsWith(CREDIT_VOCAB_IDENTIFIER)) {
47
- return {
48
- vocab: 'credit',
49
- 'vocab-identifier': CREDIT_VOCAB_IDENTIFIER,
50
- 'vocab-term': role.name,
51
- 'vocab-term-identifier': role.uri,
52
- };
53
- }
54
- return {
55
- vocab: 'uncontrolled',
56
- };
57
- };
58
32
  const insertAbstractNode = (articleMeta, abstractNode) => {
59
33
  const siblings = [
60
34
  'kwd-group',
@@ -91,24 +65,24 @@ const createDefaultIdGenerator = () => {
91
65
  return `${element.localName}-${value}`;
92
66
  };
93
67
  };
94
- const chooseRefType = (objectType) => {
95
- switch (objectType) {
96
- case ObjectTypes.Figure:
97
- case ObjectTypes.FigureElement:
68
+ const chooseRefType = (type) => {
69
+ switch (type) {
70
+ case schema.nodes.figure:
71
+ case schema.nodes.figure_element:
98
72
  return 'fig';
99
- case ObjectTypes.Footnote:
73
+ case schema.nodes.footnote:
100
74
  return 'fn';
101
- case ObjectTypes.Table:
102
- case ObjectTypes.TableElement:
75
+ case schema.nodes.table:
76
+ case schema.nodes.table_element:
103
77
  return 'table';
104
- case ObjectTypes.Section:
78
+ case schema.nodes.section:
105
79
  return 'sec';
106
- case ObjectTypes.Equation:
107
- case ObjectTypes.EquationElement:
80
+ case schema.nodes.equation:
81
+ case schema.nodes.equation_element:
108
82
  return 'disp-formula';
109
83
  }
110
84
  };
111
- const sortContributors = (a, b) => Number(a.priority) - Number(b.priority);
85
+ const sortContributors = (a, b) => Number(a.attrs.priority) - Number(b.attrs.priority);
112
86
  export const buildCitations = (citations) => citations.map((citation) => ({
113
87
  citationID: citation.attrs.id,
114
88
  citationItems: citation.attrs.rids.map((rid) => ({
@@ -120,39 +94,57 @@ export const buildCitations = (citations) => citations.map((citation) => ({
120
94
  }));
121
95
  export class JATSExporter {
122
96
  constructor() {
123
- this.serializeToJATS = async (fragment, modelMap, manuscriptID, options) => {
124
- const { version = '1.2', doi, id, frontMatterOnly = false, links, idGenerator, mediaPathGenerator, csl, } = options;
125
- this.modelMap = modelMap;
126
- this.models = Array.from(this.modelMap.values());
127
- this.generateCitationTexts(fragment, csl);
97
+ this.getLibraryItem = (manuscriptID) => {
98
+ return (id) => {
99
+ var _a;
100
+ const node = (_a = findChildrenByAttr(this.manuscriptNode, (attrs) => attrs.id === id)[0]) === null || _a === void 0 ? void 0 : _a.node;
101
+ if (!node) {
102
+ return undefined;
103
+ }
104
+ return {
105
+ _id: node.attrs.id,
106
+ issued: node.attrs.issued,
107
+ DOI: node.attrs.doi,
108
+ manuscriptID,
109
+ objectType: ObjectTypes.BibliographyItem,
110
+ author: node.attrs.author,
111
+ 'container-title': node.attrs.containerTitle,
112
+ volume: node.attrs.volume,
113
+ issue: node.attrs.issue,
114
+ supplement: node.attrs.supplement,
115
+ page: node.attrs.page,
116
+ title: node.attrs.title,
117
+ literal: node.attrs.literal,
118
+ type: node.attrs.type,
119
+ };
120
+ };
121
+ };
122
+ this.serializeToJATS = async (manuscriptNode, options) => {
123
+ var _a;
124
+ this.manuscriptNode = manuscriptNode;
125
+ this.generateCitationTexts(options.csl, manuscriptNode.attrs.id);
128
126
  this.createSerializer();
129
- const versionIds = selectVersionIds(version);
127
+ const versionIds = selectVersionIds((_a = options.version) !== null && _a !== void 0 ? _a : '1.2');
130
128
  this.document = document.implementation.createDocument(null, 'article', document.implementation.createDocumentType('article', versionIds.publicId, versionIds.systemId));
131
129
  const article = this.document.documentElement;
132
130
  article.setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xlink', XLINK_NAMESPACE);
133
- const front = this.buildFront(doi, id, links);
131
+ const front = this.buildFront(options.journal);
134
132
  article.appendChild(front);
135
- const manuscript = findManuscriptById(this.modelMap, manuscriptID);
136
- article.setAttribute('article-type', manuscript.articleType || 'other');
137
- if (!frontMatterOnly) {
138
- this.labelTargets = buildTargets(fragment);
139
- const body = this.buildBody(fragment);
140
- article.appendChild(body);
141
- const back = this.buildBack(body);
142
- this.moveCoiStatementToAuthorNotes(back, front);
143
- article.appendChild(back);
144
- this.unwrapBody(body);
145
- this.moveAbstracts(front, body);
146
- this.moveFloatsGroup(body, article);
147
- this.removeBackContainer(body);
148
- this.updateFootnoteTypes(front, back);
149
- this.fillEmptyTableFooters(article);
150
- this.fillEmptyFootnotes(article);
151
- }
152
- await this.rewriteIDs(idGenerator);
153
- if (mediaPathGenerator) {
154
- await this.rewriteMediaPaths(mediaPathGenerator);
155
- }
133
+ article.setAttribute('article-type', manuscriptNode.attrs.articleType || 'other');
134
+ this.labelTargets = buildTargets(manuscriptNode);
135
+ const body = this.buildBody();
136
+ article.appendChild(body);
137
+ const back = this.buildBack(body);
138
+ this.moveCoiStatementToAuthorNotes(back, front);
139
+ article.appendChild(back);
140
+ this.unwrapBody(body);
141
+ this.moveAbstracts(front, body);
142
+ this.moveFloatsGroup(body, article);
143
+ this.removeBackContainer(body);
144
+ this.updateFootnoteTypes(front, back);
145
+ this.fillEmptyTableFooters(article);
146
+ this.fillEmptyFootnotes(article);
147
+ await this.rewriteIDs();
156
148
  return serializeToXML(this.document);
157
149
  };
158
150
  this.nodeFromJATS = (JATSFragment) => {
@@ -165,19 +157,6 @@ export class JATSExporter {
165
157
  template.innerHTML = JATSFragment;
166
158
  return template.firstChild;
167
159
  };
168
- this.rewriteMediaPaths = async (generator) => {
169
- const doc = this.document;
170
- for (const fig of doc.querySelectorAll('fig')) {
171
- for (const graphic of fig.querySelectorAll('graphic')) {
172
- const newHref = await generator(graphic, fig.id);
173
- graphic.setAttributeNS(XLINK_NAMESPACE, 'href', newHref);
174
- }
175
- }
176
- for (const suppl of doc.querySelectorAll('supplementary-material')) {
177
- const newHref = await generator(suppl, suppl.id);
178
- suppl.setAttributeNS(XLINK_NAMESPACE, 'href', newHref);
179
- }
180
- };
181
160
  this.rewriteIDs = async (generator = createDefaultIdGenerator()) => {
182
161
  const ids = new Map();
183
162
  for (const element of this.document.querySelectorAll('[id]')) {
@@ -219,16 +198,14 @@ export class JATSExporter {
219
198
  }
220
199
  }
221
200
  };
222
- this.buildFront = (doi, id, links) => {
223
- var _a, _b, _c, _d, _e;
224
- const manuscript = findManuscript(this.modelMap);
225
- const titles = findTitles(this.modelMap);
201
+ this.buildFront = (journal) => {
202
+ var _a;
203
+ const titleNode = (_a = findChildrenByType(this.manuscriptNode, schema.nodes.title)[0]) === null || _a === void 0 ? void 0 : _a.node;
226
204
  const front = this.document.createElement('front');
227
205
  const journalMeta = this.document.createElement('journal-meta');
228
206
  front.appendChild(journalMeta);
229
207
  const articleMeta = this.document.createElement('article-meta');
230
208
  front.appendChild(articleMeta);
231
- const journal = [...this.modelMap.values()].find((model) => model.objectType === ObjectTypes.Journal);
232
209
  if (journal) {
233
210
  if (journal.journalIdentifiers) {
234
211
  for (const item of journal.journalIdentifiers) {
@@ -277,109 +254,47 @@ export class JATSExporter {
277
254
  journalMeta.appendChild(publisher);
278
255
  }
279
256
  }
280
- if (id) {
281
- const articleID = this.document.createElement('article-id');
282
- articleID.setAttribute('pub-id-type', 'publisher-id');
283
- articleID.textContent = id;
284
- articleMeta.appendChild(articleID);
285
- }
286
- if (doi || manuscript.DOI) {
257
+ if (this.manuscriptNode.attrs.doi) {
287
258
  const articleID = this.document.createElement('article-id');
288
259
  articleID.setAttribute('pub-id-type', 'doi');
289
- articleID.textContent = (_a = manuscript.DOI) !== null && _a !== void 0 ? _a : doi;
260
+ articleID.textContent = this.manuscriptNode.attrs.doi;
290
261
  articleMeta.appendChild(articleID);
291
262
  }
292
263
  const titleGroup = this.document.createElement('title-group');
293
264
  articleMeta.appendChild(titleGroup);
294
265
  this.buildContributors(articleMeta);
295
- if (links && links.self) {
296
- for (const [key, value] of Object.entries(links.self)) {
297
- const link = this.document.createElement('self-uri');
298
- link.setAttribute('content-type', key);
299
- link.setAttributeNS(XLINK_NAMESPACE, 'href', value);
300
- articleMeta.appendChild(link);
301
- }
302
- }
303
- if (titles.title) {
266
+ if (titleNode) {
304
267
  const element = this.document.createElement('article-title');
305
- this.setTitleContent(element, titles.title);
268
+ this.setTitleContent(element, titleNode.textContent);
306
269
  titleGroup.appendChild(element);
307
270
  }
308
- if (titles.subtitle) {
309
- const element = this.document.createElement('subtitle');
310
- this.setTitleContent(element, titles.subtitle);
311
- titleGroup.appendChild(element);
312
- }
313
- if (titles.runningTitle) {
314
- const element = this.document.createElement('alt-title');
315
- element.setAttribute('alt-title-type', 'right-running');
316
- this.setTitleContent(element, titles.runningTitle);
317
- titleGroup.appendChild(element);
318
- }
319
- const supplements = [...this.modelMap.values()].filter((model) => model.objectType === ObjectTypes.Supplement);
320
- if (supplements && supplements.length > 0) {
321
- for (const supplement of supplements) {
322
- const supplementaryMaterial = this.document.createElement('supplementary-material');
323
- supplementaryMaterial.setAttribute('id', normalizeID(supplement._id));
324
- supplementaryMaterial.setAttributeNS(XLINK_NAMESPACE, 'href', (_b = supplement.href) !== null && _b !== void 0 ? _b : '');
325
- const mimeType = (_c = supplement.MIME) === null || _c === void 0 ? void 0 : _c.split('/')[0];
326
- const mimeSubType = (_d = supplement.MIME) === null || _d === void 0 ? void 0 : _d.split('/')[1];
327
- supplementaryMaterial.setAttribute('mimetype', mimeType !== null && mimeType !== void 0 ? mimeType : '');
328
- supplementaryMaterial.setAttribute('mime-subtype', mimeSubType !== null && mimeSubType !== void 0 ? mimeSubType : '');
329
- const caption = this.document.createElement('caption');
330
- const title = this.document.createElement('title');
331
- title.textContent = (_e = supplement.title) !== null && _e !== void 0 ? _e : '';
332
- caption.append(title);
333
- supplementaryMaterial.append(caption);
334
- articleMeta.append(supplementaryMaterial);
335
- }
336
- }
337
- const history = articleMeta.querySelector('history') ||
338
- this.document.createElement('history');
339
- if (manuscript.acceptanceDate) {
340
- const date = this.buildDateElement(manuscript.acceptanceDate, 'accepted');
341
- history.appendChild(date);
342
- }
343
- if (manuscript.correctionDate) {
344
- const date = this.buildDateElement(manuscript.correctionDate, 'corrected');
345
- history.appendChild(date);
346
- }
347
- if (manuscript.retractionDate) {
348
- const date = this.buildDateElement(manuscript.retractionDate, 'retracted');
349
- history.appendChild(date);
350
- }
351
- if (manuscript.receiveDate) {
352
- const date = this.buildDateElement(manuscript.receiveDate, 'received');
353
- history.appendChild(date);
354
- }
355
- if (manuscript.revisionReceiveDate) {
356
- const date = this.buildDateElement(manuscript.revisionReceiveDate, 'rev-recd');
357
- history.appendChild(date);
358
- }
359
- if (manuscript.revisionRequestDate) {
360
- const date = this.buildDateElement(manuscript.revisionRequestDate, 'rev-request');
361
- history.appendChild(date);
362
- }
363
- if (history.childElementCount) {
364
- articleMeta.appendChild(history);
365
- }
271
+ const supplementsNodes = findChildrenByType(this.manuscriptNode, schema.nodes.supplement);
272
+ supplementsNodes.forEach(({ node }) => {
273
+ var _a, _b, _c, _d;
274
+ const supplementaryMaterial = this.document.createElement('supplementary-material');
275
+ supplementaryMaterial.setAttribute('id', normalizeID(node.attrs.id));
276
+ supplementaryMaterial.setAttributeNS(XLINK_NAMESPACE, 'href', (_a = node.attrs.href) !== null && _a !== void 0 ? _a : '');
277
+ supplementaryMaterial.setAttribute('mimetype', (_b = node.attrs.mimeType) !== null && _b !== void 0 ? _b : '');
278
+ supplementaryMaterial.setAttribute('mime-subtype', (_c = node.attrs.mimeSubType) !== null && _c !== void 0 ? _c : '');
279
+ const caption = this.document.createElement('caption');
280
+ const title = this.document.createElement('title');
281
+ title.textContent = (_d = node.attrs.title) !== null && _d !== void 0 ? _d : '';
282
+ caption.append(title);
283
+ supplementaryMaterial.append(caption);
284
+ articleMeta.append(supplementaryMaterial);
285
+ });
366
286
  this.buildKeywords(articleMeta);
367
287
  let countingElements = [];
368
- if (manuscript.genericCounts) {
369
- const elements = manuscript.genericCounts.map((el) => {
370
- const countingElement = this.buildCountingElement('count', el.count);
371
- if (countingElement) {
372
- countingElement.setAttribute('count-type', el.countType);
373
- }
374
- return countingElement;
375
- });
376
- countingElements.push(...elements);
377
- }
378
- countingElements.push(this.buildCountingElement('fig-count', manuscript.figureCount));
379
- countingElements.push(this.buildCountingElement('table-count', manuscript.tableCount));
380
- countingElements.push(this.buildCountingElement('equation-count', manuscript.equationCount));
381
- countingElements.push(this.buildCountingElement('ref-count', manuscript.referencesCount));
382
- countingElements.push(this.buildCountingElement('word-count', manuscript.wordCount));
288
+ const figureCount = findChildrenByType(this.manuscriptNode, schema.nodes.figure).length;
289
+ countingElements.push(this.buildCountingElement('fig-count', figureCount));
290
+ const equationCount = findChildrenByType(this.manuscriptNode, schema.nodes.equation_element).length;
291
+ countingElements.push(this.buildCountingElement('equation-count', equationCount));
292
+ const tableCount = findChildrenByType(this.manuscriptNode, schema.nodes.table).length;
293
+ countingElements.push(this.buildCountingElement('table-count', tableCount));
294
+ const referencesCount = findChildrenByType(this.manuscriptNode, schema.nodes.bibliography_item).length;
295
+ countingElements.push(this.buildCountingElement('ref-count', referencesCount));
296
+ const wordCount = this.manuscriptNode.textContent.split(/\s+/).length;
297
+ countingElements.push(this.buildCountingElement('word-count', wordCount));
383
298
  countingElements = countingElements.filter((el) => el);
384
299
  if (countingElements.length > 0) {
385
300
  const counts = this.document.createElement('counts');
@@ -414,16 +329,17 @@ export class JATSExporter {
414
329
  return wordCount;
415
330
  }
416
331
  };
417
- this.buildBody = (fragment) => {
332
+ this.buildBody = () => {
418
333
  const body = this.document.createElement('body');
419
- fragment.forEach((cFragment) => {
334
+ this.manuscriptNode.forEach((cFragment) => {
420
335
  const serializedNode = this.serializeNode(cFragment);
421
336
  body.append(...serializedNode.childNodes);
422
337
  });
423
- this.fixBody(body, fragment);
338
+ this.fixBody(body);
424
339
  return body;
425
340
  };
426
341
  this.buildBack = (body) => {
342
+ var _a;
427
343
  const back = this.document.createElement('back');
428
344
  this.moveSectionsToBack(back, body);
429
345
  const footnotesElements = this.document.querySelectorAll('sec > fn-group');
@@ -448,7 +364,7 @@ export class JATSExporter {
448
364
  back.appendChild(refList);
449
365
  const [meta] = this.citationProvider.makeBibliography();
450
366
  for (const id of meta.entry_ids) {
451
- const bibliographyItem = this.modelMap.get(id[0]);
367
+ const bibliographyNode = (_a = findChildrenByType(this.manuscriptNode, schema.nodes.bibliography_item).find(({ node }) => node.attrs.id === id[0])) === null || _a === void 0 ? void 0 : _a.node;
452
368
  const ref = this.document.createElement('ref');
453
369
  ref.setAttribute('id', normalizeID(id[0]));
454
370
  const updateCitationPubType = (citationEl, pubType) => {
@@ -467,21 +383,21 @@ export class JATSExporter {
467
383
  citationEl.setAttribute('publication-type', 'journal');
468
384
  }
469
385
  };
470
- if (bibliographyItem.literal) {
386
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.literal) {
471
387
  const mixedCitation = this.document.createElement('mixed-citation');
472
- updateCitationPubType(mixedCitation, bibliographyItem.type);
473
- mixedCitation.textContent = bibliographyItem.literal;
388
+ updateCitationPubType(mixedCitation, bibliographyNode.attrs.type);
389
+ mixedCitation.textContent = bibliographyNode.attrs.literal;
474
390
  ref.appendChild(mixedCitation);
475
391
  refList.appendChild(ref);
476
392
  }
477
393
  else {
478
394
  const citation = this.document.createElement('element-citation');
479
- updateCitationPubType(citation, bibliographyItem.type);
480
- if (bibliographyItem.author) {
395
+ updateCitationPubType(citation, bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.type);
396
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.author) {
481
397
  const personGroupNode = this.document.createElement('person-group');
482
398
  personGroupNode.setAttribute('person-group-type', 'author');
483
399
  citation.appendChild(personGroupNode);
484
- bibliographyItem.author.forEach((author) => {
400
+ bibliographyNode.attrs.author.forEach((author) => {
485
401
  const name = this.document.createElement('string-name');
486
402
  if (author.family) {
487
403
  const node = this.document.createElement('surname');
@@ -503,8 +419,8 @@ export class JATSExporter {
503
419
  }
504
420
  });
505
421
  }
506
- if (bibliographyItem.issued) {
507
- const dateParts = bibliographyItem.issued['date-parts'];
422
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.issued) {
423
+ const dateParts = bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.issued['date-parts'];
508
424
  if (dateParts && dateParts.length) {
509
425
  const [[year, month, day]] = dateParts;
510
426
  if (year) {
@@ -524,33 +440,33 @@ export class JATSExporter {
524
440
  }
525
441
  }
526
442
  }
527
- if (bibliographyItem.title) {
443
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.title) {
528
444
  const node = this.document.createElement('article-title');
529
- this.setTitleContent(node, bibliographyItem.title);
445
+ this.setTitleContent(node, bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.title);
530
446
  citation.appendChild(node);
531
447
  }
532
- if (bibliographyItem['container-title']) {
448
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.containerTitle) {
533
449
  const node = this.document.createElement('source');
534
- node.textContent = bibliographyItem['container-title'];
450
+ node.textContent = bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.containerTitle;
535
451
  citation.appendChild(node);
536
452
  }
537
- if (bibliographyItem.volume) {
453
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.volume) {
538
454
  const node = this.document.createElement('volume');
539
- node.textContent = String(bibliographyItem.volume);
455
+ node.textContent = String(bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.volume);
540
456
  citation.appendChild(node);
541
457
  }
542
- if (bibliographyItem.issue) {
458
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.issue) {
543
459
  const node = this.document.createElement('issue');
544
- node.textContent = String(bibliographyItem.issue);
460
+ node.textContent = String(bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.issue);
545
461
  citation.appendChild(node);
546
462
  }
547
- if (bibliographyItem.supplement) {
463
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.supplement) {
548
464
  const node = this.document.createElement('supplement');
549
- node.textContent = bibliographyItem.supplement;
465
+ node.textContent = bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.supplement;
550
466
  citation.appendChild(node);
551
467
  }
552
- if (bibliographyItem.page) {
553
- const pageString = String(bibliographyItem.page);
468
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.page) {
469
+ const pageString = String(bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.page);
554
470
  if (/^\d+$/.test(pageString)) {
555
471
  const node = this.document.createElement('fpage');
556
472
  node.textContent = pageString;
@@ -571,10 +487,10 @@ export class JATSExporter {
571
487
  citation.appendChild(node);
572
488
  }
573
489
  }
574
- if (bibliographyItem.DOI) {
490
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.doi) {
575
491
  const node = this.document.createElement('pub-id');
576
492
  node.setAttribute('pub-id-type', 'doi');
577
- node.textContent = String(bibliographyItem.DOI);
493
+ node.textContent = String(bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.doi);
578
494
  citation.appendChild(node);
579
495
  }
580
496
  ref.appendChild(citation);
@@ -584,7 +500,6 @@ export class JATSExporter {
584
500
  return back;
585
501
  };
586
502
  this.createSerializer = () => {
587
- const getModel = (id) => id ? this.modelMap.get(id) : undefined;
588
503
  const nodes = {
589
504
  award: () => '',
590
505
  awards: () => '',
@@ -649,24 +564,25 @@ export class JATSExporter {
649
564
  return xref;
650
565
  },
651
566
  cross_reference: (node) => {
567
+ var _a;
652
568
  const cross = node;
653
569
  const rids = cross.attrs.rids;
654
570
  if (!rids.length) {
655
571
  return cross.attrs.label;
656
572
  }
657
573
  const text = cross.attrs.customLabel || cross.attrs.label;
658
- const model = getModel(rids[0]);
659
- if (!model) {
574
+ const target = (_a = findChildrenByAttr(this.manuscriptNode, (attrs) => attrs.id === rids[0])[0]) === null || _a === void 0 ? void 0 : _a.node;
575
+ if (!target) {
660
576
  warn('');
661
577
  return text;
662
578
  }
663
579
  const xref = this.document.createElement('xref');
664
- const type = chooseRefType(model.objectType);
580
+ const type = chooseRefType(target.type);
665
581
  if (type) {
666
582
  xref.setAttribute('ref-type', type);
667
583
  }
668
584
  else {
669
- warn(`Unset ref-type for objectType ${model.objectType}`);
585
+ warn(`Unset ref-type for schema type ${target.type.name}`);
670
586
  }
671
587
  xref.setAttribute('rid', normalizeID(rids.join(' ')));
672
588
  xref.textContent = text;
@@ -738,7 +654,10 @@ export class JATSExporter {
738
654
  hard_break: () => '',
739
655
  highlight_marker: () => '',
740
656
  inline_footnote: (node) => {
741
- const rids = node.attrs.rids.filter(getModel);
657
+ const rids = node.attrs.rids.filter((rid) => {
658
+ var _a;
659
+ return (_a = findChildrenByAttr(this.manuscriptNode, (attrs) => attrs.id === rid)[0]) === null || _a === void 0 ? void 0 : _a.node;
660
+ });
742
661
  if (rids.length == 0) {
743
662
  return '';
744
663
  }
@@ -857,14 +776,7 @@ export class JATSExporter {
857
776
  italic: () => ['italic'],
858
777
  smallcaps: () => ['sc'],
859
778
  strikethrough: () => ['strike'],
860
- styled: (mark) => {
861
- const inlineStyle = getModel(mark.attrs.rid);
862
- const attrs = {};
863
- if (inlineStyle && inlineStyle.title) {
864
- attrs.style = normalizeStyleName(inlineStyle.title);
865
- }
866
- return ['styled-content', attrs];
867
- },
779
+ styled: () => ['styled-content'],
868
780
  superscript: () => ['sup'],
869
781
  subscript: () => ['sub'],
870
782
  underline: () => ['underline'],
@@ -915,14 +827,16 @@ export class JATSExporter {
915
827
  }
916
828
  };
917
829
  const appendChildNodeOfType = (element, node, type) => {
918
- const childNode = findChildNodeOfType(node, type);
830
+ var _a;
831
+ const childNode = (_a = findChildrenByType(node, type)[0]) === null || _a === void 0 ? void 0 : _a.node;
919
832
  if (childNode) {
920
833
  element.appendChild(this.serializeNode(childNode));
921
834
  }
922
835
  };
923
836
  const appendTable = (element, node) => {
924
- const tableNode = findChildNodeOfType(node, node.type.schema.nodes.table);
925
- const colGroupNode = findChildNodeOfType(node, node.type.schema.nodes.table_colgroup);
837
+ var _a, _b;
838
+ const tableNode = (_a = findChildrenByType(node, node.type.schema.nodes.table)[0]) === null || _a === void 0 ? void 0 : _a.node;
839
+ const colGroupNode = (_b = findChildrenByType(node, node.type.schema.nodes.table_colgroup)[0]) === null || _b === void 0 ? void 0 : _b.node;
926
840
  if (!tableNode) {
927
841
  return;
928
842
  }
@@ -968,7 +882,8 @@ export class JATSExporter {
968
882
  return element;
969
883
  };
970
884
  const processExecutableNode = (node, element) => {
971
- const listingNode = findChildNodeOfType(node, node.type.schema.nodes.listing);
885
+ var _a;
886
+ const listingNode = (_a = findChildrenByType(node, node.type.schema.nodes.listing)[0]) === null || _a === void 0 ? void 0 : _a.node;
972
887
  if (listingNode) {
973
888
  const { contents, languageKey } = listingNode.attrs;
974
889
  if (contents && languageKey) {
@@ -1002,25 +917,25 @@ export class JATSExporter {
1002
917
  }
1003
918
  };
1004
919
  };
1005
- this.serializeFragment = (fragment) => this.serializer.serializeFragment(fragment, {
1006
- document: this.document,
1007
- });
1008
920
  this.serializeNode = (node) => this.serializer.serializeNode(node, {
1009
921
  document: this.document,
1010
922
  });
1011
923
  this.validateContributor = (contributor) => {
1012
- if (!contributor.bibliographicName) {
1013
- throw new Error(`${contributor._id} has no bibliographicName`);
924
+ if (!contributor.attrs.bibliographicName) {
925
+ throw new Error(`${contributor.attrs.id} has no bibliographicName`);
1014
926
  }
1015
- const { family, given } = contributor.bibliographicName;
927
+ const { family, given } = contributor.attrs.bibliographicName;
1016
928
  if (!family && !given) {
1017
- throw new Error(`${contributor._id} has neither family nor given name`);
929
+ throw new Error(`${contributor.attrs.id} has neither family nor given name`);
1018
930
  }
1019
931
  };
1020
932
  this.buildContributors = (articleMeta) => {
1021
- const contributors = this.models.filter(isContributor);
1022
- const authorContributors = contributors
1023
- .filter((contributor) => contributor.role === 'author')
933
+ const contributorNodes = findChildrenByType(this.manuscriptNode, schema.nodes.contributor).map((result) => result.node);
934
+ const authorContributorNodes = contributorNodes
935
+ .filter((n) => n.attrs.role === 'author')
936
+ .sort(sortContributors);
937
+ const otherContributorsNodes = contributorNodes
938
+ .filter((n) => n.attrs.role !== 'author')
1024
939
  .sort(sortContributors);
1025
940
  const affiliationLabels = new Map();
1026
941
  const creatAffiliationLabel = (rid) => {
@@ -1038,11 +953,11 @@ export class JATSExporter {
1038
953
  sup.textContent = String(content);
1039
954
  return sup;
1040
955
  };
1041
- if (authorContributors.length) {
956
+ if (authorContributorNodes.length) {
1042
957
  const contribGroup = this.document.createElement('contrib-group');
1043
958
  contribGroup.setAttribute('content-type', 'authors');
1044
959
  articleMeta.appendChild(contribGroup);
1045
- authorContributors.forEach((contributor) => {
960
+ authorContributorNodes.forEach((contributor) => {
1046
961
  try {
1047
962
  this.validateContributor(contributor);
1048
963
  }
@@ -1052,39 +967,25 @@ export class JATSExporter {
1052
967
  }
1053
968
  const contrib = this.document.createElement('contrib');
1054
969
  contrib.setAttribute('contrib-type', 'author');
1055
- contrib.setAttribute('id', normalizeID(contributor._id));
1056
- if (contributor.isCorresponding) {
970
+ contrib.setAttribute('id', normalizeID(contributor.attrs.id));
971
+ if (contributor.attrs.isCorresponding) {
1057
972
  contrib.setAttribute('corresp', 'yes');
1058
973
  }
1059
- if (contributor.ORCIDIdentifier) {
974
+ if (contributor.attrs.ORCIDIdentifier) {
1060
975
  const identifier = this.document.createElement('contrib-id');
1061
976
  identifier.setAttribute('contrib-id-type', 'orcid');
1062
- identifier.textContent = contributor.ORCIDIdentifier;
977
+ identifier.textContent = contributor.attrs.ORCIDIdentifier;
1063
978
  contrib.appendChild(identifier);
1064
979
  }
1065
980
  const name = this.buildContributorName(contributor);
1066
981
  contrib.appendChild(name);
1067
- if (contributor.email) {
982
+ if (contributor.attrs.email) {
1068
983
  const email = this.document.createElement('email');
1069
- email.textContent = contributor.email;
984
+ email.textContent = contributor.attrs.email;
1070
985
  contrib.appendChild(email);
1071
986
  }
1072
- if (contributor.roles) {
1073
- contributor.roles.forEach((rid) => {
1074
- const contributorRole = this.modelMap.get(rid);
1075
- if (contributorRole) {
1076
- const role = this.document.createElement('role');
1077
- const attributes = chooseRoleVocabAttributes(contributorRole);
1078
- for (const [key, value] of Object.entries(attributes)) {
1079
- role.setAttribute(key, value);
1080
- }
1081
- role.textContent = contributorRole.name;
1082
- contrib.appendChild(role);
1083
- }
1084
- });
1085
- }
1086
- if (contributor.affiliations) {
1087
- contributor.affiliations.forEach((rid) => {
987
+ if (contributor.attrs.affiliations) {
988
+ contributor.attrs.affiliations.forEach((rid) => {
1088
989
  const xref = this.document.createElement('xref');
1089
990
  xref.setAttribute('ref-type', 'aff');
1090
991
  xref.setAttribute('rid', normalizeID(rid));
@@ -1092,8 +993,8 @@ export class JATSExporter {
1092
993
  contrib.appendChild(xref);
1093
994
  });
1094
995
  }
1095
- if (contributor.footnote) {
1096
- contributor.footnote.map((note) => {
996
+ if (contributor.attrs.footnote) {
997
+ contributor.attrs.footnote.map((note) => {
1097
998
  const xref = this.document.createElement('xref');
1098
999
  xref.setAttribute('ref-type', 'fn');
1099
1000
  xref.setAttribute('rid', normalizeID(note.noteID));
@@ -1101,8 +1002,8 @@ export class JATSExporter {
1101
1002
  contrib.appendChild(xref);
1102
1003
  });
1103
1004
  }
1104
- if (contributor.corresp) {
1105
- contributor.corresp.map((corresp) => {
1005
+ if (contributor.attrs.corresp) {
1006
+ contributor.attrs.corresp.map((corresp) => {
1106
1007
  const xref = this.document.createElement('xref');
1107
1008
  xref.setAttribute('ref-type', 'corresp');
1108
1009
  xref.setAttribute('rid', normalizeID(corresp.correspID));
@@ -1112,13 +1013,10 @@ export class JATSExporter {
1112
1013
  }
1113
1014
  contribGroup.appendChild(contrib);
1114
1015
  });
1115
- const otherContributors = contributors
1116
- .filter((contributor) => contributor.role !== 'author')
1117
- .sort(sortContributors);
1118
- if (otherContributors.length) {
1016
+ if (otherContributorsNodes.length) {
1119
1017
  const contribGroup = this.document.createElement('contrib-group');
1120
1018
  articleMeta.appendChild(contribGroup);
1121
- otherContributors.forEach((contributor) => {
1019
+ otherContributorsNodes.forEach((contributor) => {
1122
1020
  try {
1123
1021
  this.validateContributor(contributor);
1124
1022
  }
@@ -1127,30 +1025,16 @@ export class JATSExporter {
1127
1025
  return;
1128
1026
  }
1129
1027
  const contrib = this.document.createElement('contrib');
1130
- contrib.setAttribute('id', normalizeID(contributor._id));
1028
+ contrib.setAttribute('id', normalizeID(contributor.attrs.id));
1131
1029
  const name = this.buildContributorName(contributor);
1132
1030
  contrib.appendChild(name);
1133
- if (contributor.email) {
1031
+ if (contributor.attrs.email) {
1134
1032
  const email = this.document.createElement('email');
1135
- email.textContent = contributor.email;
1033
+ email.textContent = contributor.attrs.email;
1136
1034
  contrib.appendChild(email);
1137
1035
  }
1138
- if (contributor.roles) {
1139
- contributor.roles.forEach((rid) => {
1140
- const contributorRole = this.modelMap.get(rid);
1141
- if (contributorRole) {
1142
- const role = this.document.createElement('role');
1143
- const attributes = chooseRoleVocabAttributes(contributorRole);
1144
- for (const [key, value] of Object.entries(attributes)) {
1145
- role.setAttribute(key, value);
1146
- }
1147
- role.textContent = contributorRole.name;
1148
- contrib.appendChild(role);
1149
- }
1150
- });
1151
- }
1152
- if (contributor.affiliations) {
1153
- contributor.affiliations.forEach((rid) => {
1036
+ if (contributor.attrs.affiliations) {
1037
+ contributor.attrs.affiliations.forEach((rid) => {
1154
1038
  const xref = this.document.createElement('xref');
1155
1039
  xref.setAttribute('ref-type', 'aff');
1156
1040
  xref.setAttribute('rid', normalizeID(rid));
@@ -1158,8 +1042,8 @@ export class JATSExporter {
1158
1042
  contrib.appendChild(xref);
1159
1043
  });
1160
1044
  }
1161
- if (contributor.footnote) {
1162
- contributor.footnote.map((note) => {
1045
+ if (contributor.attrs.footnote) {
1046
+ contributor.attrs.footnote.map((note) => {
1163
1047
  const xref = this.document.createElement('xref');
1164
1048
  xref.setAttribute('ref-type', 'fn');
1165
1049
  xref.setAttribute('rid', normalizeID(note.noteID));
@@ -1171,64 +1055,68 @@ export class JATSExporter {
1171
1055
  });
1172
1056
  }
1173
1057
  const affiliationRIDs = [];
1174
- const sortedContributors = [...authorContributors, ...otherContributors];
1058
+ const sortedContributors = [
1059
+ ...authorContributorNodes,
1060
+ ...otherContributorsNodes,
1061
+ ];
1175
1062
  for (const contributor of sortedContributors) {
1176
- if (contributor.affiliations) {
1177
- affiliationRIDs.push(...contributor.affiliations);
1063
+ if (contributor.attrs.affiliations) {
1064
+ affiliationRIDs.push(...contributor.attrs.affiliations);
1178
1065
  }
1179
1066
  }
1180
- const affiliations = this.models.filter(hasObjectType(ObjectTypes.Affiliation));
1067
+ const affiliations = findChildrenByType(this.manuscriptNode, schema.nodes.affiliation).map((result) => result.node);
1181
1068
  if (affiliations) {
1182
- const usedAffiliations = affiliations.filter((affiliation) => affiliationRIDs.includes(affiliation._id));
1183
- usedAffiliations.sort((a, b) => affiliationRIDs.indexOf(a._id) - affiliationRIDs.indexOf(b._id));
1069
+ const usedAffiliations = affiliations.filter((affiliation) => affiliationRIDs.includes(affiliation.attrs.id));
1070
+ usedAffiliations.sort((a, b) => affiliationRIDs.indexOf(a.attrs.id) -
1071
+ affiliationRIDs.indexOf(b.attrs.id));
1184
1072
  usedAffiliations.forEach((affiliation) => {
1185
1073
  var _a, _b;
1186
1074
  const aff = this.document.createElement('aff');
1187
- aff.setAttribute('id', normalizeID(affiliation._id));
1075
+ aff.setAttribute('id', normalizeID(affiliation.attrs.id));
1188
1076
  contribGroup.appendChild(aff);
1189
- if (affiliation.department) {
1077
+ if (affiliation.attrs.department) {
1190
1078
  const department = this.document.createElement('institution');
1191
1079
  department.setAttribute('content-type', 'dept');
1192
- department.textContent = affiliation.department;
1080
+ department.textContent = affiliation.attrs.department;
1193
1081
  aff.appendChild(department);
1194
1082
  }
1195
- if (affiliation.institution) {
1083
+ if (affiliation.attrs.institution) {
1196
1084
  const institution = this.document.createElement('institution');
1197
- institution.textContent = affiliation.institution;
1085
+ institution.textContent = affiliation.attrs.institution;
1198
1086
  aff.appendChild(institution);
1199
1087
  }
1200
- if (affiliation.addressLine1) {
1088
+ if (affiliation.attrs.addressLine1) {
1201
1089
  const addressLine = this.document.createElement('addr-line');
1202
- addressLine.textContent = affiliation.addressLine1;
1090
+ addressLine.textContent = affiliation.attrs.addressLine1;
1203
1091
  aff.appendChild(addressLine);
1204
1092
  }
1205
- if (affiliation.addressLine2) {
1093
+ if (affiliation.attrs.addressLine2) {
1206
1094
  const addressLine = this.document.createElement('addr-line');
1207
- addressLine.textContent = affiliation.addressLine2;
1095
+ addressLine.textContent = affiliation.attrs.addressLine2;
1208
1096
  aff.appendChild(addressLine);
1209
1097
  }
1210
- if (affiliation.addressLine3) {
1098
+ if (affiliation.attrs.addressLine3) {
1211
1099
  const addressLine = this.document.createElement('addr-line');
1212
- addressLine.textContent = affiliation.addressLine3;
1100
+ addressLine.textContent = affiliation.attrs.addressLine3;
1213
1101
  aff.appendChild(addressLine);
1214
1102
  }
1215
- if (affiliation.city) {
1103
+ if (affiliation.attrs.city) {
1216
1104
  const city = this.document.createElement('city');
1217
- city.textContent = affiliation.city;
1105
+ city.textContent = affiliation.attrs.city;
1218
1106
  aff.appendChild(city);
1219
1107
  }
1220
- if (affiliation.country) {
1108
+ if (affiliation.attrs.country) {
1221
1109
  const country = this.document.createElement('country');
1222
- country.textContent = affiliation.country;
1110
+ country.textContent = affiliation.attrs.country;
1223
1111
  aff.appendChild(country);
1224
1112
  }
1225
- if (affiliation.email) {
1113
+ if (affiliation.attrs.email) {
1226
1114
  const email = this.document.createElement('email');
1227
- email.setAttributeNS(XLINK_NAMESPACE, 'href', (_a = affiliation.email.href) !== null && _a !== void 0 ? _a : '');
1228
- email.textContent = (_b = affiliation.email.text) !== null && _b !== void 0 ? _b : '';
1115
+ email.setAttributeNS(XLINK_NAMESPACE, 'href', (_a = affiliation.attrs.email.href) !== null && _a !== void 0 ? _a : '');
1116
+ email.textContent = (_b = affiliation.attrs.email.text) !== null && _b !== void 0 ? _b : '';
1229
1117
  aff.appendChild(email);
1230
1118
  }
1231
- const labelNumber = affiliationLabels.get(affiliation._id);
1119
+ const labelNumber = affiliationLabels.get(affiliation.attrs.id);
1232
1120
  if (labelNumber) {
1233
1121
  const label = this.document.createElement('label');
1234
1122
  label.textContent = String(labelNumber);
@@ -1245,41 +1133,48 @@ export class JATSExporter {
1245
1133
  this.createAuthorNotesElement = () => {
1246
1134
  var _a;
1247
1135
  const authorNotesEl = this.document.createElement('author-notes');
1248
- const authorNotes = (_a = getModelsByType(this.modelMap, ObjectTypes.AuthorNotes)) === null || _a === void 0 ? void 0 : _a[0];
1249
- if (authorNotes) {
1250
- this.appendModelsToAuthorNotes(authorNotesEl, authorNotes.containedObjectIDs);
1136
+ const authorNotesNode = (_a = findChildrenByType(this.manuscriptNode, schema.nodes.author_notes)[0]) === null || _a === void 0 ? void 0 : _a.node;
1137
+ if (authorNotesNode) {
1138
+ this.appendModelsToAuthorNotes(authorNotesEl, authorNotesNode);
1251
1139
  }
1252
1140
  return authorNotesEl;
1253
1141
  };
1254
1142
  this.appendCorrespondingToElement = (corresponding, element) => {
1255
1143
  const correspondingEl = this.document.createElement('corresp');
1256
- correspondingEl.setAttribute('id', normalizeID(corresponding._id));
1257
- if (corresponding.label) {
1144
+ correspondingEl.setAttribute('id', normalizeID(corresponding.attrs.id));
1145
+ if (corresponding.attrs.label) {
1258
1146
  const labelEl = this.document.createElement('label');
1259
- labelEl.textContent = corresponding.label;
1147
+ labelEl.textContent = corresponding.attrs.label;
1260
1148
  correspondingEl.appendChild(labelEl);
1261
1149
  }
1262
- correspondingEl.append(corresponding.contents);
1150
+ correspondingEl.append(corresponding.textContent);
1263
1151
  element.appendChild(correspondingEl);
1264
1152
  };
1265
1153
  this.appendParagraphToElement = (paragraph, element) => {
1266
- const parsedDoc = new DOMParser().parseFromString(paragraph.contents, 'text/html');
1154
+ const parsedDoc = new DOMParser().parseFromString(paragraph.textContent, 'text/html');
1267
1155
  const parsedParagraph = parsedDoc.body.querySelector('p');
1268
1156
  if (parsedParagraph) {
1269
1157
  const paragraphEl = this.document.createElement('p');
1270
1158
  paragraphEl.innerHTML = parsedParagraph.innerHTML;
1271
- paragraphEl.setAttribute('id', normalizeID(paragraph._id));
1159
+ paragraphEl.setAttribute('id', normalizeID(paragraph.attrs.id));
1272
1160
  element.appendChild(paragraphEl);
1273
1161
  }
1274
1162
  };
1275
1163
  this.appendFootnoteToElement = (footnote, element) => {
1276
1164
  const footnoteEl = this.document.createElement('fn');
1277
- footnoteEl.setAttribute('id', normalizeID(footnote._id));
1278
- footnoteEl.innerHTML = footnote.contents;
1165
+ footnoteEl.setAttribute('id', normalizeID(footnote.attrs.id));
1166
+ if (!footnote.textContent.includes('<p>')) {
1167
+ const p = this.document.createElement('p');
1168
+ p.innerHTML = footnote.textContent;
1169
+ footnoteEl.appendChild(p);
1170
+ }
1171
+ else {
1172
+ footnoteEl.innerHTML = footnote.textContent;
1173
+ }
1279
1174
  element.appendChild(footnoteEl);
1280
1175
  };
1281
- this.fixBody = (body, fragment) => {
1282
- fragment.descendants((node) => {
1176
+ this.fixBody = (body) => {
1177
+ this.manuscriptNode.descendants((node) => {
1283
1178
  if (node.attrs.id) {
1284
1179
  if (node.attrs.titleSuppressed) {
1285
1180
  const title = body.querySelector(`#${normalizeID(node.attrs.id)} > title`);
@@ -1540,36 +1435,36 @@ export class JATSExporter {
1540
1435
  };
1541
1436
  this.buildContributorName = (contributor) => {
1542
1437
  const name = this.document.createElement('name');
1543
- if (contributor.bibliographicName.family) {
1438
+ if (contributor.attrs.bibliographicName.family) {
1544
1439
  const surname = this.document.createElement('surname');
1545
- surname.textContent = contributor.bibliographicName.family;
1440
+ surname.textContent = contributor.attrs.bibliographicName.family;
1546
1441
  name.appendChild(surname);
1547
1442
  }
1548
- if (contributor.bibliographicName.given) {
1443
+ if (contributor.attrs.bibliographicName.given) {
1549
1444
  const givenNames = this.document.createElement('given-names');
1550
- givenNames.textContent = contributor.bibliographicName.given;
1445
+ givenNames.textContent = contributor.attrs.bibliographicName.given;
1551
1446
  name.appendChild(givenNames);
1552
1447
  }
1553
1448
  return name;
1554
1449
  };
1555
1450
  }
1556
- generateCitations(fragment) {
1451
+ generateCitations() {
1557
1452
  const nodes = [];
1558
- fragment.descendants((node) => {
1453
+ this.manuscriptNode.descendants((node) => {
1559
1454
  if (isCitationNode(node)) {
1560
1455
  nodes.push(node);
1561
1456
  }
1562
1457
  });
1563
1458
  return buildCitations(nodes);
1564
1459
  }
1565
- generateCitationTexts(fragment, csl) {
1460
+ generateCitationTexts(csl, manuscriptID) {
1566
1461
  this.citationTexts = new Map();
1567
1462
  this.citationProvider = new CitationProvider({
1568
- getLibraryItem: (id) => this.modelMap.get(id),
1463
+ getLibraryItem: this.getLibraryItem(manuscriptID),
1569
1464
  locale: csl.locale,
1570
1465
  citationStyle: csl.style,
1571
1466
  });
1572
- const citations = this.generateCitations(fragment);
1467
+ const citations = this.generateCitations();
1573
1468
  this.citationProvider.rebuildState(citations).forEach(([id, , output]) => {
1574
1469
  this.citationTexts.set(id, output);
1575
1470
  });
@@ -1596,72 +1491,50 @@ export class JATSExporter {
1596
1491
  return mathml;
1597
1492
  }
1598
1493
  }
1599
- appendModelsToAuthorNotes(authorNotesEl, containedObjectIDs) {
1600
- const contributors = this.models.filter(isContributor);
1601
- const usedCorrespondings = this.getUsedCorrespondings(contributors);
1602
- containedObjectIDs.forEach((id) => {
1603
- const model = this.modelMap.get(id);
1604
- if (!model) {
1605
- return;
1606
- }
1607
- switch (model.objectType) {
1608
- case ObjectTypes.ParagraphElement:
1609
- this.appendParagraphToElement(model, authorNotesEl);
1494
+ appendModelsToAuthorNotes(authorNotesEl, authorNotesNode) {
1495
+ const contributorsNodes = findChildrenByType(this.manuscriptNode, schema.nodes.contributor).map((result) => result.node);
1496
+ const usedCorrespondings = this.getUsedCorrespondings(contributorsNodes);
1497
+ authorNotesNode.descendants((node) => {
1498
+ switch (node.type) {
1499
+ case schema.nodes.paragraph:
1500
+ this.appendParagraphToElement(node, authorNotesEl);
1610
1501
  break;
1611
- case ObjectTypes.Footnote:
1612
- this.appendFootnoteToElement(model, authorNotesEl);
1502
+ case schema.nodes.footnote:
1503
+ this.appendFootnoteToElement(node, authorNotesEl);
1613
1504
  break;
1614
- case ObjectTypes.Corresponding:
1615
- if (usedCorrespondings.includes(model)) {
1616
- this.appendCorrespondingToElement(model, authorNotesEl);
1505
+ case schema.nodes.corresp:
1506
+ if (usedCorrespondings.includes(node)) {
1507
+ this.appendCorrespondingToElement(node, authorNotesEl);
1617
1508
  }
1618
1509
  break;
1619
1510
  }
1511
+ return false;
1620
1512
  });
1621
1513
  }
1622
1514
  getUsedCorrespondings(contributors) {
1623
1515
  return contributors
1624
- .flatMap((c) => { var _a; return (_a = c.corresp) !== null && _a !== void 0 ? _a : []; })
1625
- .map((corresp) => this.modelMap.get(corresp.correspID))
1516
+ .flatMap((c) => { var _a; return (_a = c.attrs.corresp) !== null && _a !== void 0 ? _a : []; })
1517
+ .map((corresp) => {
1518
+ var _a;
1519
+ return (_a = findChildrenByAttr(this.manuscriptNode, (attr) => attr.id === corresp.correspID)[0]) === null || _a === void 0 ? void 0 : _a.node;
1520
+ })
1626
1521
  .filter((corresp) => !!corresp);
1627
1522
  }
1628
1523
  buildKeywords(articleMeta) {
1629
- const keywords = [...this.modelMap.values()].filter((model) => model.objectType === ObjectTypes.Keyword);
1630
- const keywordGroups = new Map();
1631
- keywords.forEach((keyword) => {
1632
- const containedGroup = keyword.containedGroup || '';
1633
- const group = keywordGroups.get(containedGroup);
1634
- if (group) {
1635
- group.push(keyword);
1636
- }
1637
- else {
1638
- keywordGroups.set(containedGroup, [keyword]);
1639
- }
1640
- });
1641
- for (const [groupID, keywords] of keywordGroups) {
1642
- const keywordGroup = (this.modelMap.get(groupID) || {});
1524
+ const keywordGroups = findChildrenByType(this.manuscriptNode, schema.nodes.keyword_group).map((result) => result.node);
1525
+ keywordGroups.forEach((group) => {
1643
1526
  const kwdGroup = this.document.createElement('kwd-group');
1644
- if (keywordGroup.type) {
1645
- kwdGroup.setAttribute('kwd-group-type', keywordGroup.type);
1646
- }
1647
- if (keywordGroup.label) {
1648
- const label = this.document.createElement('label');
1649
- label.textContent = keywordGroup.label;
1650
- kwdGroup.appendChild(label);
1651
- }
1652
- if (keywordGroup.title) {
1653
- const title = this.document.createElement('title');
1654
- title.textContent = keywordGroup.title;
1655
- kwdGroup.appendChild(title);
1527
+ if (group.attrs.type) {
1528
+ kwdGroup.setAttribute('kwd-group-type', group.attrs.type);
1656
1529
  }
1657
1530
  articleMeta.appendChild(kwdGroup);
1658
- for (const keyword of keywords) {
1531
+ group.content.forEach((keyword) => {
1659
1532
  const kwd = this.document.createElement('kwd');
1660
- kwd.textContent = keyword.name;
1533
+ kwd.textContent = keyword.textContent;
1661
1534
  kwdGroup.appendChild(kwd);
1662
- }
1535
+ });
1663
1536
  articleMeta.appendChild(kwdGroup);
1664
- }
1537
+ });
1665
1538
  }
1666
1539
  moveCoiStatementToAuthorNotes(back, front) {
1667
1540
  const fnGroups = back.querySelectorAll('fn-group');