@manuscripts/transform 2.3.33 → 2.3.34-LEAN-3911.2

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 +6 -6
  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 +5 -4
  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 +16 -6
  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 +4 -3
  54. package/dist/types/transformer/index.d.ts +0 -16
  55. package/dist/types/version.d.ts +1 -1
  56. package/package.json +2 -1
  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
  author_notes: () => '',
590
529
  corresp: () => '',
@@ -646,24 +585,25 @@ export class JATSExporter {
646
585
  return xref;
647
586
  },
648
587
  cross_reference: (node) => {
588
+ var _a;
649
589
  const cross = node;
650
590
  const rids = cross.attrs.rids;
651
591
  if (!rids.length) {
652
592
  return cross.attrs.label;
653
593
  }
654
594
  const text = cross.attrs.customLabel || cross.attrs.label;
655
- const model = getModel(rids[0]);
656
- if (!model) {
595
+ const target = (_a = findChildrenByAttr(this.manuscriptNode, (attrs) => attrs.id === rids[0])[0]) === null || _a === void 0 ? void 0 : _a.node;
596
+ if (!target) {
657
597
  warn('');
658
598
  return text;
659
599
  }
660
600
  const xref = this.document.createElement('xref');
661
- const type = chooseRefType(model.objectType);
601
+ const type = chooseRefType(target.type);
662
602
  if (type) {
663
603
  xref.setAttribute('ref-type', type);
664
604
  }
665
605
  else {
666
- warn(`Unset ref-type for objectType ${model.objectType}`);
606
+ warn(`Unset ref-type for schema type ${target.type.name}`);
667
607
  }
668
608
  xref.setAttribute('rid', normalizeID(rids.join(' ')));
669
609
  xref.textContent = text;
@@ -735,7 +675,10 @@ export class JATSExporter {
735
675
  hard_break: () => '',
736
676
  highlight_marker: () => '',
737
677
  inline_footnote: (node) => {
738
- const rids = node.attrs.rids.filter(getModel);
678
+ const rids = node.attrs.rids.filter((rid) => {
679
+ var _a;
680
+ return (_a = findChildrenByAttr(this.manuscriptNode, (attrs) => attrs.id === rid)[0]) === null || _a === void 0 ? void 0 : _a.node;
681
+ });
739
682
  if (rids.length == 0) {
740
683
  return '';
741
684
  }
@@ -854,14 +797,7 @@ export class JATSExporter {
854
797
  italic: () => ['italic'],
855
798
  smallcaps: () => ['sc'],
856
799
  strikethrough: () => ['strike'],
857
- styled: (mark) => {
858
- const inlineStyle = getModel(mark.attrs.rid);
859
- const attrs = {};
860
- if (inlineStyle && inlineStyle.title) {
861
- attrs.style = normalizeStyleName(inlineStyle.title);
862
- }
863
- return ['styled-content', attrs];
864
- },
800
+ styled: () => ['styled-content'],
865
801
  superscript: () => ['sup'],
866
802
  subscript: () => ['sub'],
867
803
  underline: () => ['underline'],
@@ -912,14 +848,16 @@ export class JATSExporter {
912
848
  }
913
849
  };
914
850
  const appendChildNodeOfType = (element, node, type) => {
915
- const childNode = findChildNodeOfType(node, type);
851
+ var _a;
852
+ const childNode = (_a = findChildrenByType(node, type)[0]) === null || _a === void 0 ? void 0 : _a.node;
916
853
  if (childNode) {
917
854
  element.appendChild(this.serializeNode(childNode));
918
855
  }
919
856
  };
920
857
  const appendTable = (element, node) => {
921
- const tableNode = findChildNodeOfType(node, node.type.schema.nodes.table);
922
- const colGroupNode = findChildNodeOfType(node, node.type.schema.nodes.table_colgroup);
858
+ var _a, _b;
859
+ const tableNode = (_a = findChildrenByType(node, node.type.schema.nodes.table)[0]) === null || _a === void 0 ? void 0 : _a.node;
860
+ const colGroupNode = (_b = findChildrenByType(node, node.type.schema.nodes.table_colgroup)[0]) === null || _b === void 0 ? void 0 : _b.node;
923
861
  if (!tableNode) {
924
862
  return;
925
863
  }
@@ -965,7 +903,8 @@ export class JATSExporter {
965
903
  return element;
966
904
  };
967
905
  const processExecutableNode = (node, element) => {
968
- const listingNode = findChildNodeOfType(node, node.type.schema.nodes.listing);
906
+ var _a;
907
+ const listingNode = (_a = findChildrenByType(node, node.type.schema.nodes.listing)[0]) === null || _a === void 0 ? void 0 : _a.node;
969
908
  if (listingNode) {
970
909
  const { contents, languageKey } = listingNode.attrs;
971
910
  if (contents && languageKey) {
@@ -999,25 +938,25 @@ export class JATSExporter {
999
938
  }
1000
939
  };
1001
940
  };
1002
- this.serializeFragment = (fragment) => this.serializer.serializeFragment(fragment, {
1003
- document: this.document,
1004
- });
1005
941
  this.serializeNode = (node) => this.serializer.serializeNode(node, {
1006
942
  document: this.document,
1007
943
  });
1008
944
  this.validateContributor = (contributor) => {
1009
- if (!contributor.bibliographicName) {
1010
- throw new Error(`${contributor._id} has no bibliographicName`);
945
+ if (!contributor.attrs.bibliographicName) {
946
+ throw new Error(`${contributor.attrs.id} has no bibliographicName`);
1011
947
  }
1012
- const { family, given } = contributor.bibliographicName;
948
+ const { family, given } = contributor.attrs.bibliographicName;
1013
949
  if (!family && !given) {
1014
- throw new Error(`${contributor._id} has neither family nor given name`);
950
+ throw new Error(`${contributor.attrs.id} has neither family nor given name`);
1015
951
  }
1016
952
  };
1017
953
  this.buildContributors = (articleMeta) => {
1018
- const contributors = this.models.filter(isContributor);
1019
- const authorContributors = contributors
1020
- .filter((contributor) => contributor.role === 'author')
954
+ const contributorNodes = findChildrenByType(this.manuscriptNode, schema.nodes.contributor).map((result) => result.node);
955
+ const authorContributorNodes = contributorNodes
956
+ .filter((n) => n.attrs.role === 'author')
957
+ .sort(sortContributors);
958
+ const otherContributorsNodes = contributorNodes
959
+ .filter((n) => n.attrs.role !== 'author')
1021
960
  .sort(sortContributors);
1022
961
  const affiliationLabels = new Map();
1023
962
  const creatAffiliationLabel = (rid) => {
@@ -1035,11 +974,11 @@ export class JATSExporter {
1035
974
  sup.textContent = String(content);
1036
975
  return sup;
1037
976
  };
1038
- if (authorContributors.length) {
977
+ if (authorContributorNodes.length) {
1039
978
  const contribGroup = this.document.createElement('contrib-group');
1040
979
  contribGroup.setAttribute('content-type', 'authors');
1041
980
  articleMeta.appendChild(contribGroup);
1042
- authorContributors.forEach((contributor) => {
981
+ authorContributorNodes.forEach((contributor) => {
1043
982
  try {
1044
983
  this.validateContributor(contributor);
1045
984
  }
@@ -1049,39 +988,25 @@ export class JATSExporter {
1049
988
  }
1050
989
  const contrib = this.document.createElement('contrib');
1051
990
  contrib.setAttribute('contrib-type', 'author');
1052
- contrib.setAttribute('id', normalizeID(contributor._id));
1053
- if (contributor.isCorresponding) {
991
+ contrib.setAttribute('id', normalizeID(contributor.attrs.id));
992
+ if (contributor.attrs.isCorresponding) {
1054
993
  contrib.setAttribute('corresp', 'yes');
1055
994
  }
1056
- if (contributor.ORCIDIdentifier) {
995
+ if (contributor.attrs.ORCIDIdentifier) {
1057
996
  const identifier = this.document.createElement('contrib-id');
1058
997
  identifier.setAttribute('contrib-id-type', 'orcid');
1059
- identifier.textContent = contributor.ORCIDIdentifier;
998
+ identifier.textContent = contributor.attrs.ORCIDIdentifier;
1060
999
  contrib.appendChild(identifier);
1061
1000
  }
1062
1001
  const name = this.buildContributorName(contributor);
1063
1002
  contrib.appendChild(name);
1064
- if (contributor.email) {
1003
+ if (contributor.attrs.email) {
1065
1004
  const email = this.document.createElement('email');
1066
- email.textContent = contributor.email;
1005
+ email.textContent = contributor.attrs.email;
1067
1006
  contrib.appendChild(email);
1068
1007
  }
1069
- if (contributor.roles) {
1070
- contributor.roles.forEach((rid) => {
1071
- const contributorRole = this.modelMap.get(rid);
1072
- if (contributorRole) {
1073
- const role = this.document.createElement('role');
1074
- const attributes = chooseRoleVocabAttributes(contributorRole);
1075
- for (const [key, value] of Object.entries(attributes)) {
1076
- role.setAttribute(key, value);
1077
- }
1078
- role.textContent = contributorRole.name;
1079
- contrib.appendChild(role);
1080
- }
1081
- });
1082
- }
1083
- if (contributor.affiliations) {
1084
- contributor.affiliations.forEach((rid) => {
1008
+ if (contributor.attrs.affiliations) {
1009
+ contributor.attrs.affiliations.forEach((rid) => {
1085
1010
  const xref = this.document.createElement('xref');
1086
1011
  xref.setAttribute('ref-type', 'aff');
1087
1012
  xref.setAttribute('rid', normalizeID(rid));
@@ -1089,8 +1014,8 @@ export class JATSExporter {
1089
1014
  contrib.appendChild(xref);
1090
1015
  });
1091
1016
  }
1092
- if (contributor.footnote) {
1093
- contributor.footnote.map((note) => {
1017
+ if (contributor.attrs.footnote) {
1018
+ contributor.attrs.footnote.map((note) => {
1094
1019
  const xref = this.document.createElement('xref');
1095
1020
  xref.setAttribute('ref-type', 'fn');
1096
1021
  xref.setAttribute('rid', normalizeID(note.noteID));
@@ -1098,8 +1023,8 @@ export class JATSExporter {
1098
1023
  contrib.appendChild(xref);
1099
1024
  });
1100
1025
  }
1101
- if (contributor.corresp) {
1102
- contributor.corresp.map((corresp) => {
1026
+ if (contributor.attrs.corresp) {
1027
+ contributor.attrs.corresp.map((corresp) => {
1103
1028
  const xref = this.document.createElement('xref');
1104
1029
  xref.setAttribute('ref-type', 'corresp');
1105
1030
  xref.setAttribute('rid', normalizeID(corresp.correspID));
@@ -1109,13 +1034,10 @@ export class JATSExporter {
1109
1034
  }
1110
1035
  contribGroup.appendChild(contrib);
1111
1036
  });
1112
- const otherContributors = contributors
1113
- .filter((contributor) => contributor.role !== 'author')
1114
- .sort(sortContributors);
1115
- if (otherContributors.length) {
1037
+ if (otherContributorsNodes.length) {
1116
1038
  const contribGroup = this.document.createElement('contrib-group');
1117
1039
  articleMeta.appendChild(contribGroup);
1118
- otherContributors.forEach((contributor) => {
1040
+ otherContributorsNodes.forEach((contributor) => {
1119
1041
  try {
1120
1042
  this.validateContributor(contributor);
1121
1043
  }
@@ -1124,30 +1046,16 @@ export class JATSExporter {
1124
1046
  return;
1125
1047
  }
1126
1048
  const contrib = this.document.createElement('contrib');
1127
- contrib.setAttribute('id', normalizeID(contributor._id));
1049
+ contrib.setAttribute('id', normalizeID(contributor.attrs.id));
1128
1050
  const name = this.buildContributorName(contributor);
1129
1051
  contrib.appendChild(name);
1130
- if (contributor.email) {
1052
+ if (contributor.attrs.email) {
1131
1053
  const email = this.document.createElement('email');
1132
- email.textContent = contributor.email;
1054
+ email.textContent = contributor.attrs.email;
1133
1055
  contrib.appendChild(email);
1134
1056
  }
1135
- if (contributor.roles) {
1136
- contributor.roles.forEach((rid) => {
1137
- const contributorRole = this.modelMap.get(rid);
1138
- if (contributorRole) {
1139
- const role = this.document.createElement('role');
1140
- const attributes = chooseRoleVocabAttributes(contributorRole);
1141
- for (const [key, value] of Object.entries(attributes)) {
1142
- role.setAttribute(key, value);
1143
- }
1144
- role.textContent = contributorRole.name;
1145
- contrib.appendChild(role);
1146
- }
1147
- });
1148
- }
1149
- if (contributor.affiliations) {
1150
- contributor.affiliations.forEach((rid) => {
1057
+ if (contributor.attrs.affiliations) {
1058
+ contributor.attrs.affiliations.forEach((rid) => {
1151
1059
  const xref = this.document.createElement('xref');
1152
1060
  xref.setAttribute('ref-type', 'aff');
1153
1061
  xref.setAttribute('rid', normalizeID(rid));
@@ -1155,8 +1063,8 @@ export class JATSExporter {
1155
1063
  contrib.appendChild(xref);
1156
1064
  });
1157
1065
  }
1158
- if (contributor.footnote) {
1159
- contributor.footnote.map((note) => {
1066
+ if (contributor.attrs.footnote) {
1067
+ contributor.attrs.footnote.map((note) => {
1160
1068
  const xref = this.document.createElement('xref');
1161
1069
  xref.setAttribute('ref-type', 'fn');
1162
1070
  xref.setAttribute('rid', normalizeID(note.noteID));
@@ -1168,64 +1076,68 @@ export class JATSExporter {
1168
1076
  });
1169
1077
  }
1170
1078
  const affiliationRIDs = [];
1171
- const sortedContributors = [...authorContributors, ...otherContributors];
1079
+ const sortedContributors = [
1080
+ ...authorContributorNodes,
1081
+ ...otherContributorsNodes,
1082
+ ];
1172
1083
  for (const contributor of sortedContributors) {
1173
- if (contributor.affiliations) {
1174
- affiliationRIDs.push(...contributor.affiliations);
1084
+ if (contributor.attrs.affiliations) {
1085
+ affiliationRIDs.push(...contributor.attrs.affiliations);
1175
1086
  }
1176
1087
  }
1177
- const affiliations = this.models.filter(hasObjectType(ObjectTypes.Affiliation));
1088
+ const affiliations = findChildrenByType(this.manuscriptNode, schema.nodes.affiliation).map((result) => result.node);
1178
1089
  if (affiliations) {
1179
- const usedAffiliations = affiliations.filter((affiliation) => affiliationRIDs.includes(affiliation._id));
1180
- usedAffiliations.sort((a, b) => affiliationRIDs.indexOf(a._id) - affiliationRIDs.indexOf(b._id));
1090
+ const usedAffiliations = affiliations.filter((affiliation) => affiliationRIDs.includes(affiliation.attrs.id));
1091
+ usedAffiliations.sort((a, b) => affiliationRIDs.indexOf(a.attrs.id) -
1092
+ affiliationRIDs.indexOf(b.attrs.id));
1181
1093
  usedAffiliations.forEach((affiliation) => {
1182
1094
  var _a, _b;
1183
1095
  const aff = this.document.createElement('aff');
1184
- aff.setAttribute('id', normalizeID(affiliation._id));
1096
+ aff.setAttribute('id', normalizeID(affiliation.attrs.id));
1185
1097
  contribGroup.appendChild(aff);
1186
- if (affiliation.department) {
1098
+ if (affiliation.attrs.department) {
1187
1099
  const department = this.document.createElement('institution');
1188
1100
  department.setAttribute('content-type', 'dept');
1189
- department.textContent = affiliation.department;
1101
+ department.textContent = affiliation.attrs.department;
1190
1102
  aff.appendChild(department);
1191
1103
  }
1192
- if (affiliation.institution) {
1104
+ if (affiliation.attrs.institution) {
1193
1105
  const institution = this.document.createElement('institution');
1194
- institution.textContent = affiliation.institution;
1106
+ institution.textContent = affiliation.attrs.institution;
1195
1107
  aff.appendChild(institution);
1196
1108
  }
1197
- if (affiliation.addressLine1) {
1109
+ if (affiliation.attrs.addressLine1) {
1198
1110
  const addressLine = this.document.createElement('addr-line');
1199
- addressLine.textContent = affiliation.addressLine1;
1111
+ addressLine.textContent = affiliation.attrs.addressLine1;
1200
1112
  aff.appendChild(addressLine);
1201
1113
  }
1202
- if (affiliation.addressLine2) {
1114
+ if (affiliation.attrs.addressLine2) {
1203
1115
  const addressLine = this.document.createElement('addr-line');
1204
- addressLine.textContent = affiliation.addressLine2;
1116
+ addressLine.textContent = affiliation.attrs.addressLine2;
1205
1117
  aff.appendChild(addressLine);
1206
1118
  }
1207
- if (affiliation.addressLine3) {
1119
+ if (affiliation.attrs.addressLine3) {
1208
1120
  const addressLine = this.document.createElement('addr-line');
1209
- addressLine.textContent = affiliation.addressLine3;
1121
+ addressLine.textContent = affiliation.attrs.addressLine3;
1210
1122
  aff.appendChild(addressLine);
1211
1123
  }
1212
- if (affiliation.city) {
1124
+ if (affiliation.attrs.city) {
1213
1125
  const city = this.document.createElement('city');
1214
- city.textContent = affiliation.city;
1126
+ city.textContent = affiliation.attrs.city;
1215
1127
  aff.appendChild(city);
1216
1128
  }
1217
- if (affiliation.country) {
1129
+ if (affiliation.attrs.country) {
1218
1130
  const country = this.document.createElement('country');
1219
- country.textContent = affiliation.country;
1131
+ country.textContent = affiliation.attrs.country;
1220
1132
  aff.appendChild(country);
1221
1133
  }
1222
- if (affiliation.email) {
1134
+ if (affiliation.attrs.email) {
1223
1135
  const email = this.document.createElement('email');
1224
- email.setAttributeNS(XLINK_NAMESPACE, 'href', (_a = affiliation.email.href) !== null && _a !== void 0 ? _a : '');
1225
- email.textContent = (_b = affiliation.email.text) !== null && _b !== void 0 ? _b : '';
1136
+ email.setAttributeNS(XLINK_NAMESPACE, 'href', (_a = affiliation.attrs.email.href) !== null && _a !== void 0 ? _a : '');
1137
+ email.textContent = (_b = affiliation.attrs.email.text) !== null && _b !== void 0 ? _b : '';
1226
1138
  aff.appendChild(email);
1227
1139
  }
1228
- const labelNumber = affiliationLabels.get(affiliation._id);
1140
+ const labelNumber = affiliationLabels.get(affiliation.attrs.id);
1229
1141
  if (labelNumber) {
1230
1142
  const label = this.document.createElement('label');
1231
1143
  label.textContent = String(labelNumber);
@@ -1242,41 +1154,48 @@ export class JATSExporter {
1242
1154
  this.createAuthorNotesElement = () => {
1243
1155
  var _a;
1244
1156
  const authorNotesEl = this.document.createElement('author-notes');
1245
- const authorNotes = (_a = getModelsByType(this.modelMap, ObjectTypes.AuthorNotes)) === null || _a === void 0 ? void 0 : _a[0];
1246
- if (authorNotes) {
1247
- this.appendModelsToAuthorNotes(authorNotesEl, authorNotes.containedObjectIDs);
1157
+ const authorNotesNode = (_a = findChildrenByType(this.manuscriptNode, schema.nodes.author_notes)[0]) === null || _a === void 0 ? void 0 : _a.node;
1158
+ if (authorNotesNode) {
1159
+ this.appendModelsToAuthorNotes(authorNotesEl, authorNotesNode);
1248
1160
  }
1249
1161
  return authorNotesEl;
1250
1162
  };
1251
1163
  this.appendCorrespondingToElement = (corresponding, element) => {
1252
1164
  const correspondingEl = this.document.createElement('corresp');
1253
- correspondingEl.setAttribute('id', normalizeID(corresponding._id));
1254
- if (corresponding.label) {
1165
+ correspondingEl.setAttribute('id', normalizeID(corresponding.attrs.id));
1166
+ if (corresponding.attrs.label) {
1255
1167
  const labelEl = this.document.createElement('label');
1256
- labelEl.textContent = corresponding.label;
1168
+ labelEl.textContent = corresponding.attrs.label;
1257
1169
  correspondingEl.appendChild(labelEl);
1258
1170
  }
1259
- correspondingEl.append(corresponding.contents);
1171
+ correspondingEl.append(corresponding.textContent);
1260
1172
  element.appendChild(correspondingEl);
1261
1173
  };
1262
1174
  this.appendParagraphToElement = (paragraph, element) => {
1263
- const parsedDoc = new DOMParser().parseFromString(paragraph.contents, 'text/html');
1175
+ const parsedDoc = new DOMParser().parseFromString(paragraph.textContent, 'text/html');
1264
1176
  const parsedParagraph = parsedDoc.body.querySelector('p');
1265
1177
  if (parsedParagraph) {
1266
1178
  const paragraphEl = this.document.createElement('p');
1267
1179
  paragraphEl.innerHTML = parsedParagraph.innerHTML;
1268
- paragraphEl.setAttribute('id', normalizeID(paragraph._id));
1180
+ paragraphEl.setAttribute('id', normalizeID(paragraph.attrs.id));
1269
1181
  element.appendChild(paragraphEl);
1270
1182
  }
1271
1183
  };
1272
1184
  this.appendFootnoteToElement = (footnote, element) => {
1273
1185
  const footnoteEl = this.document.createElement('fn');
1274
- footnoteEl.setAttribute('id', normalizeID(footnote._id));
1275
- footnoteEl.innerHTML = footnote.contents;
1186
+ footnoteEl.setAttribute('id', normalizeID(footnote.attrs.id));
1187
+ if (!footnote.textContent.includes('<p>')) {
1188
+ const p = this.document.createElement('p');
1189
+ p.innerHTML = footnote.textContent;
1190
+ footnoteEl.appendChild(p);
1191
+ }
1192
+ else {
1193
+ footnoteEl.innerHTML = footnote.textContent;
1194
+ }
1276
1195
  element.appendChild(footnoteEl);
1277
1196
  };
1278
- this.fixBody = (body, fragment) => {
1279
- fragment.descendants((node) => {
1197
+ this.fixBody = (body) => {
1198
+ this.manuscriptNode.descendants((node) => {
1280
1199
  if (node.attrs.id) {
1281
1200
  if (node.attrs.titleSuppressed) {
1282
1201
  const title = body.querySelector(`#${normalizeID(node.attrs.id)} > title`);
@@ -1537,36 +1456,36 @@ export class JATSExporter {
1537
1456
  };
1538
1457
  this.buildContributorName = (contributor) => {
1539
1458
  const name = this.document.createElement('name');
1540
- if (contributor.bibliographicName.family) {
1459
+ if (contributor.attrs.bibliographicName.family) {
1541
1460
  const surname = this.document.createElement('surname');
1542
- surname.textContent = contributor.bibliographicName.family;
1461
+ surname.textContent = contributor.attrs.bibliographicName.family;
1543
1462
  name.appendChild(surname);
1544
1463
  }
1545
- if (contributor.bibliographicName.given) {
1464
+ if (contributor.attrs.bibliographicName.given) {
1546
1465
  const givenNames = this.document.createElement('given-names');
1547
- givenNames.textContent = contributor.bibliographicName.given;
1466
+ givenNames.textContent = contributor.attrs.bibliographicName.given;
1548
1467
  name.appendChild(givenNames);
1549
1468
  }
1550
1469
  return name;
1551
1470
  };
1552
1471
  }
1553
- generateCitations(fragment) {
1472
+ generateCitations() {
1554
1473
  const nodes = [];
1555
- fragment.descendants((node) => {
1474
+ this.manuscriptNode.descendants((node) => {
1556
1475
  if (isCitationNode(node)) {
1557
1476
  nodes.push(node);
1558
1477
  }
1559
1478
  });
1560
1479
  return buildCitations(nodes);
1561
1480
  }
1562
- generateCitationTexts(fragment, csl) {
1481
+ generateCitationTexts(csl, manuscriptID) {
1563
1482
  this.citationTexts = new Map();
1564
1483
  this.citationProvider = new CitationProvider({
1565
- getLibraryItem: (id) => this.modelMap.get(id),
1484
+ getLibraryItem: this.getLibraryItem(manuscriptID),
1566
1485
  locale: csl.locale,
1567
1486
  citationStyle: csl.style,
1568
1487
  });
1569
- const citations = this.generateCitations(fragment);
1488
+ const citations = this.generateCitations();
1570
1489
  this.citationProvider.rebuildState(citations).forEach(([id, , output]) => {
1571
1490
  this.citationTexts.set(id, output);
1572
1491
  });
@@ -1593,72 +1512,50 @@ export class JATSExporter {
1593
1512
  return mathml;
1594
1513
  }
1595
1514
  }
1596
- appendModelsToAuthorNotes(authorNotesEl, containedObjectIDs) {
1597
- const contributors = this.models.filter(isContributor);
1598
- const usedCorrespondings = this.getUsedCorrespondings(contributors);
1599
- containedObjectIDs.forEach((id) => {
1600
- const model = this.modelMap.get(id);
1601
- if (!model) {
1602
- return;
1603
- }
1604
- switch (model.objectType) {
1605
- case ObjectTypes.ParagraphElement:
1606
- this.appendParagraphToElement(model, authorNotesEl);
1515
+ appendModelsToAuthorNotes(authorNotesEl, authorNotesNode) {
1516
+ const contributorsNodes = findChildrenByType(this.manuscriptNode, schema.nodes.contributor).map((result) => result.node);
1517
+ const usedCorrespondings = this.getUsedCorrespondings(contributorsNodes);
1518
+ authorNotesNode.descendants((node) => {
1519
+ switch (node.type) {
1520
+ case schema.nodes.paragraph:
1521
+ this.appendParagraphToElement(node, authorNotesEl);
1607
1522
  break;
1608
- case ObjectTypes.Footnote:
1609
- this.appendFootnoteToElement(model, authorNotesEl);
1523
+ case schema.nodes.footnote:
1524
+ this.appendFootnoteToElement(node, authorNotesEl);
1610
1525
  break;
1611
- case ObjectTypes.Corresponding:
1612
- if (usedCorrespondings.includes(model)) {
1613
- this.appendCorrespondingToElement(model, authorNotesEl);
1526
+ case schema.nodes.corresp:
1527
+ if (usedCorrespondings.includes(node)) {
1528
+ this.appendCorrespondingToElement(node, authorNotesEl);
1614
1529
  }
1615
1530
  break;
1616
1531
  }
1532
+ return false;
1617
1533
  });
1618
1534
  }
1619
1535
  getUsedCorrespondings(contributors) {
1620
1536
  return contributors
1621
- .flatMap((c) => { var _a; return (_a = c.corresp) !== null && _a !== void 0 ? _a : []; })
1622
- .map((corresp) => this.modelMap.get(corresp.correspID))
1537
+ .flatMap((c) => { var _a; return (_a = c.attrs.corresp) !== null && _a !== void 0 ? _a : []; })
1538
+ .map((corresp) => {
1539
+ var _a;
1540
+ return (_a = findChildrenByAttr(this.manuscriptNode, (attr) => attr.id === corresp.correspID)[0]) === null || _a === void 0 ? void 0 : _a.node;
1541
+ })
1623
1542
  .filter((corresp) => !!corresp);
1624
1543
  }
1625
1544
  buildKeywords(articleMeta) {
1626
- const keywords = [...this.modelMap.values()].filter((model) => model.objectType === ObjectTypes.Keyword);
1627
- const keywordGroups = new Map();
1628
- keywords.forEach((keyword) => {
1629
- const containedGroup = keyword.containedGroup || '';
1630
- const group = keywordGroups.get(containedGroup);
1631
- if (group) {
1632
- group.push(keyword);
1633
- }
1634
- else {
1635
- keywordGroups.set(containedGroup, [keyword]);
1636
- }
1637
- });
1638
- for (const [groupID, keywords] of keywordGroups) {
1639
- const keywordGroup = (this.modelMap.get(groupID) || {});
1545
+ const keywordGroups = findChildrenByType(this.manuscriptNode, schema.nodes.keyword_group).map((result) => result.node);
1546
+ keywordGroups.forEach((group) => {
1640
1547
  const kwdGroup = this.document.createElement('kwd-group');
1641
- if (keywordGroup.type) {
1642
- kwdGroup.setAttribute('kwd-group-type', keywordGroup.type);
1643
- }
1644
- if (keywordGroup.label) {
1645
- const label = this.document.createElement('label');
1646
- label.textContent = keywordGroup.label;
1647
- kwdGroup.appendChild(label);
1648
- }
1649
- if (keywordGroup.title) {
1650
- const title = this.document.createElement('title');
1651
- title.textContent = keywordGroup.title;
1652
- kwdGroup.appendChild(title);
1548
+ if (group.attrs.type) {
1549
+ kwdGroup.setAttribute('kwd-group-type', group.attrs.type);
1653
1550
  }
1654
1551
  articleMeta.appendChild(kwdGroup);
1655
- for (const keyword of keywords) {
1552
+ group.content.forEach((keyword) => {
1656
1553
  const kwd = this.document.createElement('kwd');
1657
- kwd.textContent = keyword.name;
1554
+ kwd.textContent = keyword.textContent;
1658
1555
  kwdGroup.appendChild(kwd);
1659
- }
1556
+ });
1660
1557
  articleMeta.appendChild(kwdGroup);
1661
- }
1558
+ });
1662
1559
  }
1663
1560
  moveCoiStatementToAuthorNotes(back, front) {
1664
1561
  const fnGroups = back.querySelectorAll('fn-group');