@manuscripts/transform 2.3.36 → 2.3.37-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 (113) hide show
  1. package/dist/cjs/jats/importer/create-article-node.js +31 -0
  2. package/dist/cjs/jats/importer/index.js +3 -3
  3. package/dist/cjs/jats/importer/jats-body-transformations.js +70 -0
  4. package/dist/cjs/jats/importer/jats-comments.js +27 -104
  5. package/dist/cjs/jats/importer/{jats-body-dom-parser.js → jats-dom-parser.js} +229 -9
  6. package/dist/cjs/jats/importer/jats-front-transformations.js +262 -0
  7. package/dist/cjs/jats/importer/jats-journal-meta-parser.js +8 -1
  8. package/dist/cjs/jats/importer/jats-parser-utils.js +39 -5
  9. package/dist/cjs/jats/importer/jats-reference-parser.js +16 -27
  10. package/dist/cjs/jats/importer/jats-references.js +18 -18
  11. package/dist/cjs/jats/importer/parse-jats-article.js +42 -78
  12. package/dist/cjs/jats/index.js +4 -3
  13. package/dist/cjs/jats/jats-exporter.js +251 -354
  14. package/dist/cjs/{transformer → jats}/labels.js +3 -3
  15. package/dist/cjs/lib/utils.js +9 -1
  16. package/dist/cjs/transformer/id.js +10 -5
  17. package/dist/cjs/transformer/index.js +0 -18
  18. package/dist/cjs/version.js +1 -1
  19. package/dist/{cjs/transformer/serializer.js → es/jats/importer/create-article-node.js} +12 -8
  20. package/dist/es/jats/importer/index.js +2 -1
  21. package/dist/es/jats/importer/jats-body-transformations.js +70 -0
  22. package/dist/es/jats/importer/jats-comments.js +26 -101
  23. package/dist/es/jats/importer/{jats-body-dom-parser.js → jats-dom-parser.js} +230 -10
  24. package/dist/es/jats/importer/jats-front-transformations.js +259 -0
  25. package/dist/es/jats/importer/jats-journal-meta-parser.js +6 -0
  26. package/dist/es/jats/importer/jats-parser-utils.js +40 -6
  27. package/dist/es/jats/importer/jats-reference-parser.js +16 -27
  28. package/dist/es/jats/importer/jats-references.js +18 -18
  29. package/dist/es/jats/importer/parse-jats-article.js +43 -77
  30. package/dist/es/jats/index.js +3 -1
  31. package/dist/es/jats/jats-exporter.js +253 -356
  32. package/dist/es/{transformer → jats}/labels.js +3 -3
  33. package/dist/es/lib/utils.js +7 -0
  34. package/dist/es/transformer/id.js +8 -3
  35. package/dist/es/transformer/index.js +0 -16
  36. package/dist/es/version.js +1 -1
  37. package/dist/{cjs/transformer/models.js → types/jats/importer/create-article-node.d.ts} +3 -3
  38. package/dist/types/jats/importer/index.d.ts +2 -1
  39. package/dist/types/jats/importer/jats-body-transformations.d.ts +5 -0
  40. package/dist/types/jats/importer/jats-comments.d.ts +4 -10
  41. package/dist/types/jats/importer/{jats-body-dom-parser.d.ts → jats-dom-parser.d.ts} +1 -1
  42. package/dist/types/jats/importer/jats-front-transformations.d.ts +38 -0
  43. package/dist/types/jats/importer/jats-journal-meta-parser.d.ts +10 -0
  44. package/dist/types/jats/importer/jats-references.d.ts +19 -8
  45. package/dist/types/jats/importer/parse-jats-article.d.ts +12 -5
  46. package/dist/types/jats/index.d.ts +3 -1
  47. package/dist/types/jats/jats-exporter.d.ts +10 -29
  48. package/dist/types/{transformer → jats}/labels.d.ts +2 -1
  49. package/dist/types/lib/utils.d.ts +3 -0
  50. package/dist/types/schema/nodes/bibliography_item.d.ts +28 -5
  51. package/dist/types/schema/nodes/contributor.d.ts +10 -0
  52. package/dist/types/schema/nodes/keyword_group.d.ts +1 -0
  53. package/dist/types/transformer/id.d.ts +5 -2
  54. package/dist/types/transformer/index.d.ts +0 -16
  55. package/dist/types/version.d.ts +1 -1
  56. package/package.json +3 -2
  57. package/dist/cjs/__tests__/data/project-dump.json +0 -825
  58. package/dist/cjs/jats/importer/jats-front-parser.js +0 -321
  59. package/dist/cjs/transformer/__tests__/__helpers__/doc.js +0 -37
  60. package/dist/cjs/transformer/builders.js +0 -219
  61. package/dist/cjs/transformer/decode.js +0 -874
  62. package/dist/cjs/transformer/document-object-types.js +0 -31
  63. package/dist/cjs/transformer/encode.js +0 -664
  64. package/dist/cjs/transformer/footnote-category.js +0 -20
  65. package/dist/cjs/transformer/footnotes-order.js +0 -60
  66. package/dist/cjs/transformer/highlight-markers.js +0 -138
  67. package/dist/cjs/transformer/html.js +0 -400
  68. package/dist/cjs/transformer/manuscript-dependencies.js +0 -21
  69. package/dist/cjs/transformer/model-map.js +0 -26
  70. package/dist/cjs/transformer/object-types.js +0 -57
  71. package/dist/cjs/transformer/project-bundle.js +0 -94
  72. package/dist/cjs/transformer/update-identifiers.js +0 -93
  73. package/dist/es/__tests__/data/project-dump.json +0 -825
  74. package/dist/es/jats/importer/jats-front-parser.js +0 -315
  75. package/dist/es/transformer/__tests__/__helpers__/doc.js +0 -29
  76. package/dist/es/transformer/builders.js +0 -186
  77. package/dist/es/transformer/decode.js +0 -864
  78. package/dist/es/transformer/document-object-types.js +0 -28
  79. package/dist/es/transformer/encode.js +0 -654
  80. package/dist/es/transformer/footnote-category.js +0 -16
  81. package/dist/es/transformer/footnotes-order.js +0 -55
  82. package/dist/es/transformer/highlight-markers.js +0 -132
  83. package/dist/es/transformer/html.js +0 -393
  84. package/dist/es/transformer/manuscript-dependencies.js +0 -17
  85. package/dist/es/transformer/model-map.js +0 -22
  86. package/dist/es/transformer/models.js +0 -16
  87. package/dist/es/transformer/object-types.js +0 -52
  88. package/dist/es/transformer/project-bundle.js +0 -85
  89. package/dist/es/transformer/serializer.js +0 -17
  90. package/dist/es/transformer/update-identifiers.js +0 -87
  91. package/dist/types/jats/importer/jats-front-parser.d.ts +0 -84
  92. package/dist/types/transformer/__tests__/__helpers__/doc.d.ts +0 -18
  93. package/dist/types/transformer/builders.d.ts +0 -61
  94. package/dist/types/transformer/decode.d.ts +0 -51
  95. package/dist/types/transformer/document-object-types.d.ts +0 -17
  96. package/dist/types/transformer/encode.d.ts +0 -29
  97. package/dist/types/transformer/footnote-category.d.ts +0 -17
  98. package/dist/types/transformer/footnotes-order.d.ts +0 -22
  99. package/dist/types/transformer/highlight-markers.d.ts +0 -31
  100. package/dist/types/transformer/html.d.ts +0 -36
  101. package/dist/types/transformer/manuscript-dependencies.d.ts +0 -4
  102. package/dist/types/transformer/model-map.d.ts +0 -19
  103. package/dist/types/transformer/models.d.ts +0 -48
  104. package/dist/types/transformer/object-types.d.ts +0 -30
  105. package/dist/types/transformer/project-bundle.d.ts +0 -30
  106. package/dist/types/transformer/serializer.d.ts +0 -19
  107. package/dist/types/transformer/update-identifiers.d.ts +0 -23
  108. /package/dist/cjs/{transformer → jats}/filename.js +0 -0
  109. /package/dist/cjs/{transformer → jats}/timestamp.js +0 -0
  110. /package/dist/es/{transformer → jats}/filename.js +0 -0
  111. /package/dist/es/{transformer → jats}/timestamp.js +0 -0
  112. /package/dist/types/{transformer → jats}/filename.d.ts +0 -0
  113. /package/dist/types/{transformer → jats}/timestamp.d.ts +0 -0
@@ -13,48 +13,23 @@
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
- import { DOMParser as ProsemirrorDOMParser, DOMSerializer, } from 'prosemirror-model';
19
+ import { DOMSerializer, DOMParser as ProsemirrorDOMParser, } from 'prosemirror-model';
20
+ import { findChildrenByAttr, findChildrenByType } from 'prosemirror-utils';
20
21
  import serializeToXML from 'w3c-xmlserializer';
21
22
  import { nodeFromHTML, textFromHTML } from '../lib/html';
22
- import { normalizeStyleName } from '../lib/styled-content';
23
- import { iterateChildren } from '../lib/utils';
24
23
  import { isCitationNode, schema, } from '../schema';
25
- import { generateAttachmentFilename } from '../transformer/filename';
26
- import { buildTargets } from '../transformer/labels';
27
24
  import { isExecutableNodeType, isNodeType } from '../transformer/node-types';
28
- import { hasObjectType } from '../transformer/object-types';
29
- import { findManuscript, findManuscriptById, findTitles, } from '../transformer/project-bundle';
30
25
  import { chooseJatsFnType, chooseSecType, } from '../transformer/section-category';
26
+ import { generateAttachmentFilename } from './filename';
31
27
  import { selectVersionIds } from './jats-versions';
28
+ import { buildTargets } from './labels';
32
29
  const warn = debug('manuscripts-transform');
33
30
  const XLINK_NAMESPACE = 'http://www.w3.org/1999/xlink';
34
31
  const normalizeID = (id) => id.replace(/:/g, '_');
35
32
  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
33
  const insertAbstractNode = (articleMeta, abstractNode) => {
59
34
  const siblings = [
60
35
  'kwd-group',
@@ -91,24 +66,24 @@ const createDefaultIdGenerator = () => {
91
66
  return `${element.localName}-${value}`;
92
67
  };
93
68
  };
94
- const chooseRefType = (objectType) => {
95
- switch (objectType) {
96
- case ObjectTypes.Figure:
97
- case ObjectTypes.FigureElement:
69
+ const chooseRefType = (type) => {
70
+ switch (type) {
71
+ case schema.nodes.figure:
72
+ case schema.nodes.figure_element:
98
73
  return 'fig';
99
- case ObjectTypes.Footnote:
74
+ case schema.nodes.footnote:
100
75
  return 'fn';
101
- case ObjectTypes.Table:
102
- case ObjectTypes.TableElement:
76
+ case schema.nodes.table:
77
+ case schema.nodes.table_element:
103
78
  return 'table';
104
- case ObjectTypes.Section:
79
+ case schema.nodes.section:
105
80
  return 'sec';
106
- case ObjectTypes.Equation:
107
- case ObjectTypes.EquationElement:
81
+ case schema.nodes.equation:
82
+ case schema.nodes.equation_element:
108
83
  return 'disp-formula';
109
84
  }
110
85
  };
111
- const sortContributors = (a, b) => Number(a.priority) - Number(b.priority);
86
+ const sortContributors = (a, b) => Number(a.attrs.priority) - Number(b.attrs.priority);
112
87
  export const buildCitations = (citations) => citations.map((citation) => ({
113
88
  citationID: citation.attrs.id,
114
89
  citationItems: citation.attrs.rids.map((rid) => ({
@@ -120,39 +95,57 @@ export const buildCitations = (citations) => citations.map((citation) => ({
120
95
  }));
121
96
  export class JATSExporter {
122
97
  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);
98
+ this.getLibraryItem = (manuscriptID) => {
99
+ return (id) => {
100
+ var _a;
101
+ const node = (_a = findChildrenByAttr(this.manuscriptNode, (attrs) => attrs.id === id)[0]) === null || _a === void 0 ? void 0 : _a.node;
102
+ if (!node) {
103
+ return undefined;
104
+ }
105
+ return {
106
+ _id: node.attrs.id,
107
+ issued: node.attrs.issued,
108
+ DOI: node.attrs.doi,
109
+ manuscriptID,
110
+ objectType: ObjectTypes.BibliographyItem,
111
+ author: node.attrs.author,
112
+ 'container-title': node.attrs.containerTitle,
113
+ volume: node.attrs.volume,
114
+ issue: node.attrs.issue,
115
+ supplement: node.attrs.supplement,
116
+ page: node.attrs.page,
117
+ title: node.attrs.title,
118
+ literal: node.attrs.literal,
119
+ type: node.attrs.type,
120
+ };
121
+ };
122
+ };
123
+ this.serializeToJATS = async (manuscriptNode, csl, manuscript, jorunal) => {
124
+ const version = '1.2';
125
+ this.manuscriptNode = manuscriptNode;
126
+ this.generateCitationTexts(csl, manuscriptNode.attrs.id);
128
127
  this.createSerializer();
129
128
  const versionIds = selectVersionIds(version);
130
129
  this.document = document.implementation.createDocument(null, 'article', document.implementation.createDocumentType('article', versionIds.publicId, versionIds.systemId));
131
130
  const article = this.document.documentElement;
132
131
  article.setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xlink', XLINK_NAMESPACE);
133
- const front = this.buildFront(doi, id, links);
132
+ const front = this.buildFront(manuscript, jorunal);
134
133
  article.appendChild(front);
135
- const manuscript = findManuscriptById(this.modelMap, manuscriptID);
136
134
  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
- }
135
+ this.labelTargets = buildTargets(manuscriptNode);
136
+ const body = this.buildBody();
137
+ article.appendChild(body);
138
+ const back = this.buildBack(body);
139
+ this.moveCoiStatementToAuthorNotes(back, front);
140
+ article.appendChild(back);
141
+ this.unwrapBody(body);
142
+ this.moveAbstracts(front, body);
143
+ this.moveFloatsGroup(body, article);
144
+ this.removeBackContainer(body);
145
+ this.updateFootnoteTypes(front, back);
146
+ this.fillEmptyTableFooters(article);
147
+ this.fillEmptyFootnotes(article);
148
+ await this.rewriteIDs();
156
149
  return serializeToXML(this.document);
157
150
  };
158
151
  this.nodeFromJATS = (JATSFragment) => {
@@ -219,16 +212,14 @@ export class JATSExporter {
219
212
  }
220
213
  }
221
214
  };
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);
215
+ this.buildFront = (manuscript, journal) => {
216
+ var _a;
217
+ const titleNode = (_a = findChildrenByType(this.manuscriptNode, schema.nodes.title)[0]) === null || _a === void 0 ? void 0 : _a.node;
226
218
  const front = this.document.createElement('front');
227
219
  const journalMeta = this.document.createElement('journal-meta');
228
220
  front.appendChild(journalMeta);
229
221
  const articleMeta = this.document.createElement('article-meta');
230
222
  front.appendChild(articleMeta);
231
- const journal = [...this.modelMap.values()].find((model) => model.objectType === ObjectTypes.Journal);
232
223
  if (journal) {
233
224
  if (journal.journalIdentifiers) {
234
225
  for (const item of journal.journalIdentifiers) {
@@ -277,92 +268,35 @@ export class JATSExporter {
277
268
  journalMeta.appendChild(publisher);
278
269
  }
279
270
  }
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) {
271
+ if (manuscript.DOI) {
287
272
  const articleID = this.document.createElement('article-id');
288
273
  articleID.setAttribute('pub-id-type', 'doi');
289
- articleID.textContent = (_a = manuscript.DOI) !== null && _a !== void 0 ? _a : doi;
274
+ articleID.textContent = manuscript.DOI;
290
275
  articleMeta.appendChild(articleID);
291
276
  }
292
277
  const titleGroup = this.document.createElement('title-group');
293
278
  articleMeta.appendChild(titleGroup);
294
279
  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) {
280
+ if (titleNode) {
304
281
  const element = this.document.createElement('article-title');
305
- this.setTitleContent(element, titles.title);
282
+ this.setTitleContent(element, titleNode.textContent);
306
283
  titleGroup.appendChild(element);
307
284
  }
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
- }
285
+ const supplementsNodes = findChildrenByType(this.manuscriptNode, schema.nodes.supplement);
286
+ supplementsNodes.forEach(({ node }) => {
287
+ var _a, _b, _c, _d;
288
+ const supplementaryMaterial = this.document.createElement('supplementary-material');
289
+ supplementaryMaterial.setAttribute('id', normalizeID(node.attrs.id));
290
+ supplementaryMaterial.setAttributeNS(XLINK_NAMESPACE, 'href', (_a = node.attrs.href) !== null && _a !== void 0 ? _a : '');
291
+ supplementaryMaterial.setAttribute('mimetype', (_b = node.attrs.mimeType) !== null && _b !== void 0 ? _b : '');
292
+ supplementaryMaterial.setAttribute('mime-subtype', (_c = node.attrs.mimeSubType) !== null && _c !== void 0 ? _c : '');
293
+ const caption = this.document.createElement('caption');
294
+ const title = this.document.createElement('title');
295
+ title.textContent = (_d = node.attrs.title) !== null && _d !== void 0 ? _d : '';
296
+ caption.append(title);
297
+ supplementaryMaterial.append(caption);
298
+ articleMeta.append(supplementaryMaterial);
299
+ });
366
300
  this.buildKeywords(articleMeta);
367
301
  let countingElements = [];
368
302
  if (manuscript.genericCounts) {
@@ -375,11 +309,16 @@ export class JATSExporter {
375
309
  });
376
310
  countingElements.push(...elements);
377
311
  }
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));
312
+ const figureCount = findChildrenByType(this.manuscriptNode, schema.nodes.figure).length;
313
+ countingElements.push(this.buildCountingElement('fig-count', figureCount));
314
+ const equationCount = findChildrenByType(this.manuscriptNode, schema.nodes.equation_element).length;
315
+ const tableCount = findChildrenByType(this.manuscriptNode, schema.nodes.table).length;
316
+ const referencesCount = findChildrenByType(this.manuscriptNode, schema.nodes.bibliography_item).length;
317
+ countingElements.push(this.buildCountingElement('table-count', tableCount));
318
+ countingElements.push(this.buildCountingElement('equation-count', equationCount));
319
+ countingElements.push(this.buildCountingElement('ref-count', referencesCount));
320
+ const wordCount = this.manuscriptNode.textContent.split(/\s+/).length;
321
+ countingElements.push(this.buildCountingElement('word-count', wordCount));
383
322
  countingElements = countingElements.filter((el) => el);
384
323
  if (countingElements.length > 0) {
385
324
  const counts = this.document.createElement('counts');
@@ -414,16 +353,17 @@ export class JATSExporter {
414
353
  return wordCount;
415
354
  }
416
355
  };
417
- this.buildBody = (fragment) => {
356
+ this.buildBody = () => {
418
357
  const body = this.document.createElement('body');
419
- fragment.forEach((cFragment) => {
358
+ this.manuscriptNode.forEach((cFragment) => {
420
359
  const serializedNode = this.serializeNode(cFragment);
421
360
  body.append(...serializedNode.childNodes);
422
361
  });
423
- this.fixBody(body, fragment);
362
+ this.fixBody(body);
424
363
  return body;
425
364
  };
426
365
  this.buildBack = (body) => {
366
+ var _a;
427
367
  const back = this.document.createElement('back');
428
368
  this.moveSectionsToBack(back, body);
429
369
  const footnotesElements = this.document.querySelectorAll('sec > fn-group');
@@ -448,7 +388,7 @@ export class JATSExporter {
448
388
  back.appendChild(refList);
449
389
  const [meta] = this.citationProvider.makeBibliography();
450
390
  for (const id of meta.entry_ids) {
451
- const bibliographyItem = this.modelMap.get(id[0]);
391
+ 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
392
  const ref = this.document.createElement('ref');
453
393
  ref.setAttribute('id', normalizeID(id[0]));
454
394
  const updateCitationPubType = (citationEl, pubType) => {
@@ -467,21 +407,21 @@ export class JATSExporter {
467
407
  citationEl.setAttribute('publication-type', 'journal');
468
408
  }
469
409
  };
470
- if (bibliographyItem.literal) {
410
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.literal) {
471
411
  const mixedCitation = this.document.createElement('mixed-citation');
472
- updateCitationPubType(mixedCitation, bibliographyItem.type);
473
- mixedCitation.textContent = bibliographyItem.literal;
412
+ updateCitationPubType(mixedCitation, bibliographyNode.attrs.type);
413
+ mixedCitation.textContent = bibliographyNode.attrs.literal;
474
414
  ref.appendChild(mixedCitation);
475
415
  refList.appendChild(ref);
476
416
  }
477
417
  else {
478
418
  const citation = this.document.createElement('element-citation');
479
- updateCitationPubType(citation, bibliographyItem.type);
480
- if (bibliographyItem.author) {
419
+ updateCitationPubType(citation, bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.type);
420
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.author) {
481
421
  const personGroupNode = this.document.createElement('person-group');
482
422
  personGroupNode.setAttribute('person-group-type', 'author');
483
423
  citation.appendChild(personGroupNode);
484
- bibliographyItem.author.forEach((author) => {
424
+ bibliographyNode.attrs.author.forEach((author) => {
485
425
  const name = this.document.createElement('string-name');
486
426
  if (author.family) {
487
427
  const node = this.document.createElement('surname');
@@ -503,8 +443,8 @@ export class JATSExporter {
503
443
  }
504
444
  });
505
445
  }
506
- if (bibliographyItem.issued) {
507
- const dateParts = bibliographyItem.issued['date-parts'];
446
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.issued) {
447
+ const dateParts = bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.issued['date-parts'];
508
448
  if (dateParts && dateParts.length) {
509
449
  const [[year, month, day]] = dateParts;
510
450
  if (year) {
@@ -524,33 +464,33 @@ export class JATSExporter {
524
464
  }
525
465
  }
526
466
  }
527
- if (bibliographyItem.title) {
467
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.title) {
528
468
  const node = this.document.createElement('article-title');
529
- this.setTitleContent(node, bibliographyItem.title);
469
+ this.setTitleContent(node, bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.title);
530
470
  citation.appendChild(node);
531
471
  }
532
- if (bibliographyItem['container-title']) {
472
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.containerTitle) {
533
473
  const node = this.document.createElement('source');
534
- node.textContent = bibliographyItem['container-title'];
474
+ node.textContent = bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.containerTitle;
535
475
  citation.appendChild(node);
536
476
  }
537
- if (bibliographyItem.volume) {
477
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.volume) {
538
478
  const node = this.document.createElement('volume');
539
- node.textContent = String(bibliographyItem.volume);
479
+ node.textContent = String(bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.volume);
540
480
  citation.appendChild(node);
541
481
  }
542
- if (bibliographyItem.issue) {
482
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.issue) {
543
483
  const node = this.document.createElement('issue');
544
- node.textContent = String(bibliographyItem.issue);
484
+ node.textContent = String(bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.issue);
545
485
  citation.appendChild(node);
546
486
  }
547
- if (bibliographyItem.supplement) {
487
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.supplement) {
548
488
  const node = this.document.createElement('supplement');
549
- node.textContent = bibliographyItem.supplement;
489
+ node.textContent = bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.supplement;
550
490
  citation.appendChild(node);
551
491
  }
552
- if (bibliographyItem.page) {
553
- const pageString = String(bibliographyItem.page);
492
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.page) {
493
+ const pageString = String(bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.page);
554
494
  if (/^\d+$/.test(pageString)) {
555
495
  const node = this.document.createElement('fpage');
556
496
  node.textContent = pageString;
@@ -571,10 +511,10 @@ export class JATSExporter {
571
511
  citation.appendChild(node);
572
512
  }
573
513
  }
574
- if (bibliographyItem.DOI) {
514
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.doi) {
575
515
  const node = this.document.createElement('pub-id');
576
516
  node.setAttribute('pub-id-type', 'doi');
577
- node.textContent = String(bibliographyItem.DOI);
517
+ node.textContent = String(bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.doi);
578
518
  citation.appendChild(node);
579
519
  }
580
520
  ref.appendChild(citation);
@@ -584,7 +524,6 @@ export class JATSExporter {
584
524
  return back;
585
525
  };
586
526
  this.createSerializer = () => {
587
- const getModel = (id) => id ? this.modelMap.get(id) : undefined;
588
527
  const nodes = {
589
528
  box_element: () => ['boxed-text', 0],
590
529
  author_notes: () => '',
@@ -647,24 +586,25 @@ export class JATSExporter {
647
586
  return xref;
648
587
  },
649
588
  cross_reference: (node) => {
589
+ var _a;
650
590
  const cross = node;
651
591
  const rids = cross.attrs.rids;
652
592
  if (!rids.length) {
653
593
  return cross.attrs.label;
654
594
  }
655
595
  const text = cross.attrs.customLabel || cross.attrs.label;
656
- const model = getModel(rids[0]);
657
- if (!model) {
596
+ const target = (_a = findChildrenByAttr(this.manuscriptNode, (attrs) => attrs.id === rids[0])[0]) === null || _a === void 0 ? void 0 : _a.node;
597
+ if (!target) {
658
598
  warn('');
659
599
  return text;
660
600
  }
661
601
  const xref = this.document.createElement('xref');
662
- const type = chooseRefType(model.objectType);
602
+ const type = chooseRefType(target.type);
663
603
  if (type) {
664
604
  xref.setAttribute('ref-type', type);
665
605
  }
666
606
  else {
667
- warn(`Unset ref-type for objectType ${model.objectType}`);
607
+ warn(`Unset ref-type for schema type ${target.type.name}`);
668
608
  }
669
609
  xref.setAttribute('rid', normalizeID(rids.join(' ')));
670
610
  xref.textContent = text;
@@ -736,7 +676,10 @@ export class JATSExporter {
736
676
  hard_break: () => '',
737
677
  highlight_marker: () => '',
738
678
  inline_footnote: (node) => {
739
- const rids = node.attrs.rids.filter(getModel);
679
+ const rids = node.attrs.rids.filter((rid) => {
680
+ var _a;
681
+ return (_a = findChildrenByAttr(this.manuscriptNode, (attrs) => attrs.id === rid)[0]) === null || _a === void 0 ? void 0 : _a.node;
682
+ });
740
683
  if (rids.length == 0) {
741
684
  return '';
742
685
  }
@@ -855,14 +798,7 @@ export class JATSExporter {
855
798
  italic: () => ['italic'],
856
799
  smallcaps: () => ['sc'],
857
800
  strikethrough: () => ['strike'],
858
- styled: (mark) => {
859
- const inlineStyle = getModel(mark.attrs.rid);
860
- const attrs = {};
861
- if (inlineStyle && inlineStyle.title) {
862
- attrs.style = normalizeStyleName(inlineStyle.title);
863
- }
864
- return ['styled-content', attrs];
865
- },
801
+ styled: () => ['styled-content'],
866
802
  superscript: () => ['sup'],
867
803
  subscript: () => ['sub'],
868
804
  underline: () => ['underline'],
@@ -913,14 +849,16 @@ export class JATSExporter {
913
849
  }
914
850
  };
915
851
  const appendChildNodeOfType = (element, node, type) => {
916
- const childNode = findChildNodeOfType(node, type);
852
+ var _a;
853
+ const childNode = (_a = findChildrenByType(node, type)[0]) === null || _a === void 0 ? void 0 : _a.node;
917
854
  if (childNode) {
918
855
  element.appendChild(this.serializeNode(childNode));
919
856
  }
920
857
  };
921
858
  const appendTable = (element, node) => {
922
- const tableNode = findChildNodeOfType(node, node.type.schema.nodes.table);
923
- const colGroupNode = findChildNodeOfType(node, node.type.schema.nodes.table_colgroup);
859
+ var _a, _b;
860
+ const tableNode = (_a = findChildrenByType(node, node.type.schema.nodes.table)[0]) === null || _a === void 0 ? void 0 : _a.node;
861
+ const colGroupNode = (_b = findChildrenByType(node, node.type.schema.nodes.table_colgroup)[0]) === null || _b === void 0 ? void 0 : _b.node;
924
862
  if (!tableNode) {
925
863
  return;
926
864
  }
@@ -966,7 +904,8 @@ export class JATSExporter {
966
904
  return element;
967
905
  };
968
906
  const processExecutableNode = (node, element) => {
969
- const listingNode = findChildNodeOfType(node, node.type.schema.nodes.listing);
907
+ var _a;
908
+ const listingNode = (_a = findChildrenByType(node, node.type.schema.nodes.listing)[0]) === null || _a === void 0 ? void 0 : _a.node;
970
909
  if (listingNode) {
971
910
  const { contents, languageKey } = listingNode.attrs;
972
911
  if (contents && languageKey) {
@@ -1000,25 +939,25 @@ export class JATSExporter {
1000
939
  }
1001
940
  };
1002
941
  };
1003
- this.serializeFragment = (fragment) => this.serializer.serializeFragment(fragment, {
1004
- document: this.document,
1005
- });
1006
942
  this.serializeNode = (node) => this.serializer.serializeNode(node, {
1007
943
  document: this.document,
1008
944
  });
1009
945
  this.validateContributor = (contributor) => {
1010
- if (!contributor.bibliographicName) {
1011
- throw new Error(`${contributor._id} has no bibliographicName`);
946
+ if (!contributor.attrs.bibliographicName) {
947
+ throw new Error(`${contributor.attrs.id} has no bibliographicName`);
1012
948
  }
1013
- const { family, given } = contributor.bibliographicName;
949
+ const { family, given } = contributor.attrs.bibliographicName;
1014
950
  if (!family && !given) {
1015
- throw new Error(`${contributor._id} has neither family nor given name`);
951
+ throw new Error(`${contributor.attrs.id} has neither family nor given name`);
1016
952
  }
1017
953
  };
1018
954
  this.buildContributors = (articleMeta) => {
1019
- const contributors = this.models.filter(isContributor);
1020
- const authorContributors = contributors
1021
- .filter((contributor) => contributor.role === 'author')
955
+ const contributorNodes = findChildrenByType(this.manuscriptNode, schema.nodes.contributor).map((result) => result.node);
956
+ const authorContributorNodes = contributorNodes
957
+ .filter((n) => n.attrs.role === 'author')
958
+ .sort(sortContributors);
959
+ const otherContributorsNodes = contributorNodes
960
+ .filter((n) => n.attrs.role !== 'author')
1022
961
  .sort(sortContributors);
1023
962
  const affiliationLabels = new Map();
1024
963
  const creatAffiliationLabel = (rid) => {
@@ -1036,11 +975,11 @@ export class JATSExporter {
1036
975
  sup.textContent = String(content);
1037
976
  return sup;
1038
977
  };
1039
- if (authorContributors.length) {
978
+ if (authorContributorNodes.length) {
1040
979
  const contribGroup = this.document.createElement('contrib-group');
1041
980
  contribGroup.setAttribute('content-type', 'authors');
1042
981
  articleMeta.appendChild(contribGroup);
1043
- authorContributors.forEach((contributor) => {
982
+ authorContributorNodes.forEach((contributor) => {
1044
983
  try {
1045
984
  this.validateContributor(contributor);
1046
985
  }
@@ -1050,39 +989,25 @@ export class JATSExporter {
1050
989
  }
1051
990
  const contrib = this.document.createElement('contrib');
1052
991
  contrib.setAttribute('contrib-type', 'author');
1053
- contrib.setAttribute('id', normalizeID(contributor._id));
1054
- if (contributor.isCorresponding) {
992
+ contrib.setAttribute('id', normalizeID(contributor.attrs.id));
993
+ if (contributor.attrs.isCorresponding) {
1055
994
  contrib.setAttribute('corresp', 'yes');
1056
995
  }
1057
- if (contributor.ORCIDIdentifier) {
996
+ if (contributor.attrs.ORCIDIdentifier) {
1058
997
  const identifier = this.document.createElement('contrib-id');
1059
998
  identifier.setAttribute('contrib-id-type', 'orcid');
1060
- identifier.textContent = contributor.ORCIDIdentifier;
999
+ identifier.textContent = contributor.attrs.ORCIDIdentifier;
1061
1000
  contrib.appendChild(identifier);
1062
1001
  }
1063
1002
  const name = this.buildContributorName(contributor);
1064
1003
  contrib.appendChild(name);
1065
- if (contributor.email) {
1004
+ if (contributor.attrs.email) {
1066
1005
  const email = this.document.createElement('email');
1067
- email.textContent = contributor.email;
1006
+ email.textContent = contributor.attrs.email;
1068
1007
  contrib.appendChild(email);
1069
1008
  }
1070
- if (contributor.roles) {
1071
- contributor.roles.forEach((rid) => {
1072
- const contributorRole = this.modelMap.get(rid);
1073
- if (contributorRole) {
1074
- const role = this.document.createElement('role');
1075
- const attributes = chooseRoleVocabAttributes(contributorRole);
1076
- for (const [key, value] of Object.entries(attributes)) {
1077
- role.setAttribute(key, value);
1078
- }
1079
- role.textContent = contributorRole.name;
1080
- contrib.appendChild(role);
1081
- }
1082
- });
1083
- }
1084
- if (contributor.affiliations) {
1085
- contributor.affiliations.forEach((rid) => {
1009
+ if (contributor.attrs.affiliations) {
1010
+ contributor.attrs.affiliations.forEach((rid) => {
1086
1011
  const xref = this.document.createElement('xref');
1087
1012
  xref.setAttribute('ref-type', 'aff');
1088
1013
  xref.setAttribute('rid', normalizeID(rid));
@@ -1090,8 +1015,8 @@ export class JATSExporter {
1090
1015
  contrib.appendChild(xref);
1091
1016
  });
1092
1017
  }
1093
- if (contributor.footnote) {
1094
- contributor.footnote.map((note) => {
1018
+ if (contributor.attrs.footnote) {
1019
+ contributor.attrs.footnote.map((note) => {
1095
1020
  const xref = this.document.createElement('xref');
1096
1021
  xref.setAttribute('ref-type', 'fn');
1097
1022
  xref.setAttribute('rid', normalizeID(note.noteID));
@@ -1099,8 +1024,8 @@ export class JATSExporter {
1099
1024
  contrib.appendChild(xref);
1100
1025
  });
1101
1026
  }
1102
- if (contributor.corresp) {
1103
- contributor.corresp.map((corresp) => {
1027
+ if (contributor.attrs.corresp) {
1028
+ contributor.attrs.corresp.map((corresp) => {
1104
1029
  const xref = this.document.createElement('xref');
1105
1030
  xref.setAttribute('ref-type', 'corresp');
1106
1031
  xref.setAttribute('rid', normalizeID(corresp.correspID));
@@ -1110,13 +1035,10 @@ export class JATSExporter {
1110
1035
  }
1111
1036
  contribGroup.appendChild(contrib);
1112
1037
  });
1113
- const otherContributors = contributors
1114
- .filter((contributor) => contributor.role !== 'author')
1115
- .sort(sortContributors);
1116
- if (otherContributors.length) {
1038
+ if (otherContributorsNodes.length) {
1117
1039
  const contribGroup = this.document.createElement('contrib-group');
1118
1040
  articleMeta.appendChild(contribGroup);
1119
- otherContributors.forEach((contributor) => {
1041
+ otherContributorsNodes.forEach((contributor) => {
1120
1042
  try {
1121
1043
  this.validateContributor(contributor);
1122
1044
  }
@@ -1125,30 +1047,16 @@ export class JATSExporter {
1125
1047
  return;
1126
1048
  }
1127
1049
  const contrib = this.document.createElement('contrib');
1128
- contrib.setAttribute('id', normalizeID(contributor._id));
1050
+ contrib.setAttribute('id', normalizeID(contributor.attrs.id));
1129
1051
  const name = this.buildContributorName(contributor);
1130
1052
  contrib.appendChild(name);
1131
- if (contributor.email) {
1053
+ if (contributor.attrs.email) {
1132
1054
  const email = this.document.createElement('email');
1133
- email.textContent = contributor.email;
1055
+ email.textContent = contributor.attrs.email;
1134
1056
  contrib.appendChild(email);
1135
1057
  }
1136
- if (contributor.roles) {
1137
- contributor.roles.forEach((rid) => {
1138
- const contributorRole = this.modelMap.get(rid);
1139
- if (contributorRole) {
1140
- const role = this.document.createElement('role');
1141
- const attributes = chooseRoleVocabAttributes(contributorRole);
1142
- for (const [key, value] of Object.entries(attributes)) {
1143
- role.setAttribute(key, value);
1144
- }
1145
- role.textContent = contributorRole.name;
1146
- contrib.appendChild(role);
1147
- }
1148
- });
1149
- }
1150
- if (contributor.affiliations) {
1151
- contributor.affiliations.forEach((rid) => {
1058
+ if (contributor.attrs.affiliations) {
1059
+ contributor.attrs.affiliations.forEach((rid) => {
1152
1060
  const xref = this.document.createElement('xref');
1153
1061
  xref.setAttribute('ref-type', 'aff');
1154
1062
  xref.setAttribute('rid', normalizeID(rid));
@@ -1156,8 +1064,8 @@ export class JATSExporter {
1156
1064
  contrib.appendChild(xref);
1157
1065
  });
1158
1066
  }
1159
- if (contributor.footnote) {
1160
- contributor.footnote.map((note) => {
1067
+ if (contributor.attrs.footnote) {
1068
+ contributor.attrs.footnote.map((note) => {
1161
1069
  const xref = this.document.createElement('xref');
1162
1070
  xref.setAttribute('ref-type', 'fn');
1163
1071
  xref.setAttribute('rid', normalizeID(note.noteID));
@@ -1169,64 +1077,68 @@ export class JATSExporter {
1169
1077
  });
1170
1078
  }
1171
1079
  const affiliationRIDs = [];
1172
- const sortedContributors = [...authorContributors, ...otherContributors];
1080
+ const sortedContributors = [
1081
+ ...authorContributorNodes,
1082
+ ...otherContributorsNodes,
1083
+ ];
1173
1084
  for (const contributor of sortedContributors) {
1174
- if (contributor.affiliations) {
1175
- affiliationRIDs.push(...contributor.affiliations);
1085
+ if (contributor.attrs.affiliations) {
1086
+ affiliationRIDs.push(...contributor.attrs.affiliations);
1176
1087
  }
1177
1088
  }
1178
- const affiliations = this.models.filter(hasObjectType(ObjectTypes.Affiliation));
1089
+ const affiliations = findChildrenByType(this.manuscriptNode, schema.nodes.affiliation).map((result) => result.node);
1179
1090
  if (affiliations) {
1180
- const usedAffiliations = affiliations.filter((affiliation) => affiliationRIDs.includes(affiliation._id));
1181
- usedAffiliations.sort((a, b) => affiliationRIDs.indexOf(a._id) - affiliationRIDs.indexOf(b._id));
1091
+ const usedAffiliations = affiliations.filter((affiliation) => affiliationRIDs.includes(affiliation.attrs.id));
1092
+ usedAffiliations.sort((a, b) => affiliationRIDs.indexOf(a.attrs.id) -
1093
+ affiliationRIDs.indexOf(b.attrs.id));
1182
1094
  usedAffiliations.forEach((affiliation) => {
1183
1095
  var _a, _b;
1184
1096
  const aff = this.document.createElement('aff');
1185
- aff.setAttribute('id', normalizeID(affiliation._id));
1097
+ aff.setAttribute('id', normalizeID(affiliation.attrs.id));
1186
1098
  contribGroup.appendChild(aff);
1187
- if (affiliation.department) {
1099
+ if (affiliation.attrs.department) {
1188
1100
  const department = this.document.createElement('institution');
1189
1101
  department.setAttribute('content-type', 'dept');
1190
- department.textContent = affiliation.department;
1102
+ department.textContent = affiliation.attrs.department;
1191
1103
  aff.appendChild(department);
1192
1104
  }
1193
- if (affiliation.institution) {
1105
+ if (affiliation.attrs.institution) {
1194
1106
  const institution = this.document.createElement('institution');
1195
- institution.textContent = affiliation.institution;
1107
+ institution.textContent = affiliation.attrs.institution;
1196
1108
  aff.appendChild(institution);
1197
1109
  }
1198
- if (affiliation.addressLine1) {
1110
+ if (affiliation.attrs.addressLine1) {
1199
1111
  const addressLine = this.document.createElement('addr-line');
1200
- addressLine.textContent = affiliation.addressLine1;
1112
+ addressLine.textContent = affiliation.attrs.addressLine1;
1201
1113
  aff.appendChild(addressLine);
1202
1114
  }
1203
- if (affiliation.addressLine2) {
1115
+ if (affiliation.attrs.addressLine2) {
1204
1116
  const addressLine = this.document.createElement('addr-line');
1205
- addressLine.textContent = affiliation.addressLine2;
1117
+ addressLine.textContent = affiliation.attrs.addressLine2;
1206
1118
  aff.appendChild(addressLine);
1207
1119
  }
1208
- if (affiliation.addressLine3) {
1120
+ if (affiliation.attrs.addressLine3) {
1209
1121
  const addressLine = this.document.createElement('addr-line');
1210
- addressLine.textContent = affiliation.addressLine3;
1122
+ addressLine.textContent = affiliation.attrs.addressLine3;
1211
1123
  aff.appendChild(addressLine);
1212
1124
  }
1213
- if (affiliation.city) {
1125
+ if (affiliation.attrs.city) {
1214
1126
  const city = this.document.createElement('city');
1215
- city.textContent = affiliation.city;
1127
+ city.textContent = affiliation.attrs.city;
1216
1128
  aff.appendChild(city);
1217
1129
  }
1218
- if (affiliation.country) {
1130
+ if (affiliation.attrs.country) {
1219
1131
  const country = this.document.createElement('country');
1220
- country.textContent = affiliation.country;
1132
+ country.textContent = affiliation.attrs.country;
1221
1133
  aff.appendChild(country);
1222
1134
  }
1223
- if (affiliation.email) {
1135
+ if (affiliation.attrs.email) {
1224
1136
  const email = this.document.createElement('email');
1225
- email.setAttributeNS(XLINK_NAMESPACE, 'href', (_a = affiliation.email.href) !== null && _a !== void 0 ? _a : '');
1226
- email.textContent = (_b = affiliation.email.text) !== null && _b !== void 0 ? _b : '';
1137
+ email.setAttributeNS(XLINK_NAMESPACE, 'href', (_a = affiliation.attrs.email.href) !== null && _a !== void 0 ? _a : '');
1138
+ email.textContent = (_b = affiliation.attrs.email.text) !== null && _b !== void 0 ? _b : '';
1227
1139
  aff.appendChild(email);
1228
1140
  }
1229
- const labelNumber = affiliationLabels.get(affiliation._id);
1141
+ const labelNumber = affiliationLabels.get(affiliation.attrs.id);
1230
1142
  if (labelNumber) {
1231
1143
  const label = this.document.createElement('label');
1232
1144
  label.textContent = String(labelNumber);
@@ -1243,41 +1155,48 @@ export class JATSExporter {
1243
1155
  this.createAuthorNotesElement = () => {
1244
1156
  var _a;
1245
1157
  const authorNotesEl = this.document.createElement('author-notes');
1246
- const authorNotes = (_a = getModelsByType(this.modelMap, ObjectTypes.AuthorNotes)) === null || _a === void 0 ? void 0 : _a[0];
1247
- if (authorNotes) {
1248
- this.appendModelsToAuthorNotes(authorNotesEl, authorNotes.containedObjectIDs);
1158
+ const authorNotesNode = (_a = findChildrenByType(this.manuscriptNode, schema.nodes.author_notes)[0]) === null || _a === void 0 ? void 0 : _a.node;
1159
+ if (authorNotesNode) {
1160
+ this.appendModelsToAuthorNotes(authorNotesEl, authorNotesNode);
1249
1161
  }
1250
1162
  return authorNotesEl;
1251
1163
  };
1252
1164
  this.appendCorrespondingToElement = (corresponding, element) => {
1253
1165
  const correspondingEl = this.document.createElement('corresp');
1254
- correspondingEl.setAttribute('id', normalizeID(corresponding._id));
1255
- if (corresponding.label) {
1166
+ correspondingEl.setAttribute('id', normalizeID(corresponding.attrs.id));
1167
+ if (corresponding.attrs.label) {
1256
1168
  const labelEl = this.document.createElement('label');
1257
- labelEl.textContent = corresponding.label;
1169
+ labelEl.textContent = corresponding.attrs.label;
1258
1170
  correspondingEl.appendChild(labelEl);
1259
1171
  }
1260
- correspondingEl.append(corresponding.contents);
1172
+ correspondingEl.append(corresponding.textContent);
1261
1173
  element.appendChild(correspondingEl);
1262
1174
  };
1263
1175
  this.appendParagraphToElement = (paragraph, element) => {
1264
- const parsedDoc = new DOMParser().parseFromString(paragraph.contents, 'text/html');
1176
+ const parsedDoc = new DOMParser().parseFromString(paragraph.textContent, 'text/html');
1265
1177
  const parsedParagraph = parsedDoc.body.querySelector('p');
1266
1178
  if (parsedParagraph) {
1267
1179
  const paragraphEl = this.document.createElement('p');
1268
1180
  paragraphEl.innerHTML = parsedParagraph.innerHTML;
1269
- paragraphEl.setAttribute('id', normalizeID(paragraph._id));
1181
+ paragraphEl.setAttribute('id', normalizeID(paragraph.attrs.id));
1270
1182
  element.appendChild(paragraphEl);
1271
1183
  }
1272
1184
  };
1273
1185
  this.appendFootnoteToElement = (footnote, element) => {
1274
1186
  const footnoteEl = this.document.createElement('fn');
1275
- footnoteEl.setAttribute('id', normalizeID(footnote._id));
1276
- footnoteEl.innerHTML = footnote.contents;
1187
+ footnoteEl.setAttribute('id', normalizeID(footnote.attrs.id));
1188
+ if (!footnote.textContent.includes('<p>')) {
1189
+ const p = this.document.createElement('p');
1190
+ p.innerHTML = footnote.textContent;
1191
+ footnoteEl.appendChild(p);
1192
+ }
1193
+ else {
1194
+ footnoteEl.innerHTML = footnote.textContent;
1195
+ }
1277
1196
  element.appendChild(footnoteEl);
1278
1197
  };
1279
- this.fixBody = (body, fragment) => {
1280
- fragment.descendants((node) => {
1198
+ this.fixBody = (body) => {
1199
+ this.manuscriptNode.descendants((node) => {
1281
1200
  if (node.attrs.id) {
1282
1201
  if (node.attrs.titleSuppressed) {
1283
1202
  const title = body.querySelector(`#${normalizeID(node.attrs.id)} > title`);
@@ -1538,36 +1457,36 @@ export class JATSExporter {
1538
1457
  };
1539
1458
  this.buildContributorName = (contributor) => {
1540
1459
  const name = this.document.createElement('name');
1541
- if (contributor.bibliographicName.family) {
1460
+ if (contributor.attrs.bibliographicName.family) {
1542
1461
  const surname = this.document.createElement('surname');
1543
- surname.textContent = contributor.bibliographicName.family;
1462
+ surname.textContent = contributor.attrs.bibliographicName.family;
1544
1463
  name.appendChild(surname);
1545
1464
  }
1546
- if (contributor.bibliographicName.given) {
1465
+ if (contributor.attrs.bibliographicName.given) {
1547
1466
  const givenNames = this.document.createElement('given-names');
1548
- givenNames.textContent = contributor.bibliographicName.given;
1467
+ givenNames.textContent = contributor.attrs.bibliographicName.given;
1549
1468
  name.appendChild(givenNames);
1550
1469
  }
1551
1470
  return name;
1552
1471
  };
1553
1472
  }
1554
- generateCitations(fragment) {
1473
+ generateCitations() {
1555
1474
  const nodes = [];
1556
- fragment.descendants((node) => {
1475
+ this.manuscriptNode.descendants((node) => {
1557
1476
  if (isCitationNode(node)) {
1558
1477
  nodes.push(node);
1559
1478
  }
1560
1479
  });
1561
1480
  return buildCitations(nodes);
1562
1481
  }
1563
- generateCitationTexts(fragment, csl) {
1482
+ generateCitationTexts(csl, manuscriptID) {
1564
1483
  this.citationTexts = new Map();
1565
1484
  this.citationProvider = new CitationProvider({
1566
- getLibraryItem: (id) => this.modelMap.get(id),
1485
+ getLibraryItem: this.getLibraryItem(manuscriptID),
1567
1486
  locale: csl.locale,
1568
1487
  citationStyle: csl.style,
1569
1488
  });
1570
- const citations = this.generateCitations(fragment);
1489
+ const citations = this.generateCitations();
1571
1490
  this.citationProvider.rebuildState(citations).forEach(([id, , output]) => {
1572
1491
  this.citationTexts.set(id, output);
1573
1492
  });
@@ -1594,72 +1513,50 @@ export class JATSExporter {
1594
1513
  return mathml;
1595
1514
  }
1596
1515
  }
1597
- appendModelsToAuthorNotes(authorNotesEl, containedObjectIDs) {
1598
- const contributors = this.models.filter(isContributor);
1599
- const usedCorrespondings = this.getUsedCorrespondings(contributors);
1600
- containedObjectIDs.forEach((id) => {
1601
- const model = this.modelMap.get(id);
1602
- if (!model) {
1603
- return;
1604
- }
1605
- switch (model.objectType) {
1606
- case ObjectTypes.ParagraphElement:
1607
- this.appendParagraphToElement(model, authorNotesEl);
1516
+ appendModelsToAuthorNotes(authorNotesEl, authorNotesNode) {
1517
+ const contributorsNodes = findChildrenByType(this.manuscriptNode, schema.nodes.contributor).map((result) => result.node);
1518
+ const usedCorrespondings = this.getUsedCorrespondings(contributorsNodes);
1519
+ authorNotesNode.descendants((node) => {
1520
+ switch (node.type) {
1521
+ case schema.nodes.paragraph:
1522
+ this.appendParagraphToElement(node, authorNotesEl);
1608
1523
  break;
1609
- case ObjectTypes.Footnote:
1610
- this.appendFootnoteToElement(model, authorNotesEl);
1524
+ case schema.nodes.footnote:
1525
+ this.appendFootnoteToElement(node, authorNotesEl);
1611
1526
  break;
1612
- case ObjectTypes.Corresponding:
1613
- if (usedCorrespondings.includes(model)) {
1614
- this.appendCorrespondingToElement(model, authorNotesEl);
1527
+ case schema.nodes.corresp:
1528
+ if (usedCorrespondings.includes(node)) {
1529
+ this.appendCorrespondingToElement(node, authorNotesEl);
1615
1530
  }
1616
1531
  break;
1617
1532
  }
1533
+ return false;
1618
1534
  });
1619
1535
  }
1620
1536
  getUsedCorrespondings(contributors) {
1621
1537
  return contributors
1622
- .flatMap((c) => { var _a; return (_a = c.corresp) !== null && _a !== void 0 ? _a : []; })
1623
- .map((corresp) => this.modelMap.get(corresp.correspID))
1538
+ .flatMap((c) => { var _a; return (_a = c.attrs.corresp) !== null && _a !== void 0 ? _a : []; })
1539
+ .map((corresp) => {
1540
+ var _a;
1541
+ return (_a = findChildrenByAttr(this.manuscriptNode, (attr) => attr.id === corresp.correspID)[0]) === null || _a === void 0 ? void 0 : _a.node;
1542
+ })
1624
1543
  .filter((corresp) => !!corresp);
1625
1544
  }
1626
1545
  buildKeywords(articleMeta) {
1627
- const keywords = [...this.modelMap.values()].filter((model) => model.objectType === ObjectTypes.Keyword);
1628
- const keywordGroups = new Map();
1629
- keywords.forEach((keyword) => {
1630
- const containedGroup = keyword.containedGroup || '';
1631
- const group = keywordGroups.get(containedGroup);
1632
- if (group) {
1633
- group.push(keyword);
1634
- }
1635
- else {
1636
- keywordGroups.set(containedGroup, [keyword]);
1637
- }
1638
- });
1639
- for (const [groupID, keywords] of keywordGroups) {
1640
- const keywordGroup = (this.modelMap.get(groupID) || {});
1546
+ const keywordGroups = findChildrenByType(this.manuscriptNode, schema.nodes.keyword_group).map((result) => result.node);
1547
+ keywordGroups.forEach((group) => {
1641
1548
  const kwdGroup = this.document.createElement('kwd-group');
1642
- if (keywordGroup.type) {
1643
- kwdGroup.setAttribute('kwd-group-type', keywordGroup.type);
1644
- }
1645
- if (keywordGroup.label) {
1646
- const label = this.document.createElement('label');
1647
- label.textContent = keywordGroup.label;
1648
- kwdGroup.appendChild(label);
1649
- }
1650
- if (keywordGroup.title) {
1651
- const title = this.document.createElement('title');
1652
- title.textContent = keywordGroup.title;
1653
- kwdGroup.appendChild(title);
1549
+ if (group.attrs.type) {
1550
+ kwdGroup.setAttribute('kwd-group-type', group.attrs.type);
1654
1551
  }
1655
1552
  articleMeta.appendChild(kwdGroup);
1656
- for (const keyword of keywords) {
1553
+ group.content.forEach((keyword) => {
1657
1554
  const kwd = this.document.createElement('kwd');
1658
- kwd.textContent = keyword.name;
1555
+ kwd.textContent = keyword.textContent;
1659
1556
  kwdGroup.appendChild(kwd);
1660
- }
1557
+ });
1661
1558
  articleMeta.appendChild(kwdGroup);
1662
- }
1559
+ });
1663
1560
  }
1664
1561
  moveCoiStatementToAuthorNotes(back, front) {
1665
1562
  const fnGroups = back.querySelectorAll('fn-group');