@manuscripts/transform 2.3.37 → 2.3.38-LEAN-3911.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/dist/cjs/index.js +6 -6
  2. package/dist/cjs/jats/{jats-exporter.js → exporter/jats-exporter.js} +263 -390
  3. package/dist/cjs/jats/{jats-versions.js → exporter/jats-versions.js} +1 -3
  4. package/dist/cjs/{transformer → jats/exporter}/labels.js +4 -4
  5. package/dist/cjs/{transformer/filename.js → jats/importer/create-article-node.js} +10 -9
  6. package/dist/cjs/jats/importer/jats-body-transformations.js +73 -0
  7. package/dist/cjs/jats/importer/jats-comments.js +27 -104
  8. package/dist/cjs/jats/importer/{jats-body-dom-parser.js → jats-dom-parser.js} +281 -10
  9. package/dist/cjs/jats/importer/jats-front-transformations.js +79 -0
  10. package/dist/cjs/jats/importer/jats-journal-meta-parser.js +8 -1
  11. package/dist/cjs/jats/importer/jats-parser-utils.js +43 -5
  12. package/dist/cjs/jats/importer/jats-reference-parser.js +16 -23
  13. package/dist/cjs/jats/importer/jats-references.js +18 -18
  14. package/dist/cjs/jats/importer/parse-jats-article.js +40 -78
  15. package/dist/cjs/jats/index.js +7 -7
  16. package/dist/cjs/{transformer/models.js → lib/deafults.js} +3 -1
  17. package/dist/cjs/lib/utils.js +12 -1
  18. package/dist/cjs/transformer/id.js +10 -5
  19. package/dist/cjs/transformer/index.js +0 -18
  20. package/dist/cjs/version.js +1 -1
  21. package/dist/es/index.js +5 -5
  22. package/dist/es/jats/{jats-exporter.js → exporter/jats-exporter.js} +257 -384
  23. package/dist/es/jats/{jats-versions.js → exporter/jats-versions.js} +0 -1
  24. package/dist/es/{transformer → jats/exporter}/labels.js +4 -4
  25. package/dist/es/{transformer/filename.js → jats/importer/create-article-node.js} +8 -7
  26. package/dist/es/jats/importer/jats-body-transformations.js +73 -0
  27. package/dist/es/jats/importer/jats-comments.js +26 -101
  28. package/dist/es/jats/importer/{jats-body-dom-parser.js → jats-dom-parser.js} +282 -11
  29. package/dist/es/jats/importer/jats-front-transformations.js +76 -0
  30. package/dist/es/jats/importer/jats-journal-meta-parser.js +6 -0
  31. package/dist/es/jats/importer/jats-parser-utils.js +44 -6
  32. package/dist/es/jats/importer/jats-reference-parser.js +16 -23
  33. package/dist/es/jats/importer/jats-references.js +18 -18
  34. package/dist/es/jats/importer/parse-jats-article.js +41 -77
  35. package/dist/es/jats/index.js +5 -3
  36. package/dist/{types/transformer/timestamp.d.ts → es/lib/deafults.js} +2 -2
  37. package/dist/es/lib/utils.js +9 -0
  38. package/dist/es/transformer/id.js +8 -3
  39. package/dist/es/transformer/index.js +0 -16
  40. package/dist/es/version.js +1 -1
  41. package/dist/types/index.d.ts +6 -6
  42. package/dist/types/jats/{jats-exporter.d.ts → exporter/jats-exporter.d.ts} +15 -29
  43. package/dist/types/jats/{jats-versions.d.ts → exporter/jats-versions.d.ts} +0 -1
  44. package/dist/types/{transformer → jats/exporter}/labels.d.ts +2 -2
  45. package/dist/{es/transformer/footnote-category.js → types/jats/importer/create-article-node.d.ts} +3 -2
  46. package/dist/types/jats/importer/jats-body-transformations.d.ts +5 -0
  47. package/dist/types/jats/importer/jats-comments.d.ts +4 -10
  48. package/dist/types/jats/importer/{jats-body-dom-parser.d.ts → jats-dom-parser.d.ts} +1 -1
  49. package/dist/{cjs/transformer/serializer.js → types/jats/importer/jats-front-transformations.d.ts} +7 -8
  50. package/dist/types/jats/importer/jats-journal-meta-parser.d.ts +10 -0
  51. package/dist/types/jats/importer/jats-references.d.ts +19 -8
  52. package/dist/types/jats/importer/parse-jats-article.d.ts +12 -5
  53. package/dist/types/jats/index.d.ts +5 -3
  54. package/dist/types/jats/types.d.ts +1 -0
  55. package/dist/{es/transformer/models.js → types/lib/deafults.d.ts} +2 -2
  56. package/dist/types/lib/utils.d.ts +2 -0
  57. package/dist/types/schema/nodes/bibliography_item.d.ts +3 -3
  58. package/dist/types/schema/nodes/contributor.d.ts +10 -0
  59. package/dist/types/schema/nodes/keyword_group.d.ts +1 -0
  60. package/dist/types/schema/nodes/manuscript.d.ts +8 -7
  61. package/dist/types/schema/nodes/title.d.ts +0 -3
  62. package/dist/types/transformer/id.d.ts +5 -2
  63. package/dist/types/transformer/index.d.ts +0 -16
  64. package/dist/types/version.d.ts +1 -1
  65. package/package.json +2 -1
  66. package/dist/cjs/__tests__/data/project-dump.json +0 -825
  67. package/dist/cjs/jats/importer/index.js +0 -22
  68. package/dist/cjs/jats/importer/jats-front-parser.js +0 -321
  69. package/dist/cjs/transformer/__tests__/__helpers__/doc.js +0 -37
  70. package/dist/cjs/transformer/builders.js +0 -219
  71. package/dist/cjs/transformer/decode.js +0 -874
  72. package/dist/cjs/transformer/document-object-types.js +0 -31
  73. package/dist/cjs/transformer/encode.js +0 -664
  74. package/dist/cjs/transformer/footnote-category.js +0 -20
  75. package/dist/cjs/transformer/footnotes-order.js +0 -60
  76. package/dist/cjs/transformer/highlight-markers.js +0 -138
  77. package/dist/cjs/transformer/html.js +0 -400
  78. package/dist/cjs/transformer/manuscript-dependencies.js +0 -21
  79. package/dist/cjs/transformer/model-map.js +0 -26
  80. package/dist/cjs/transformer/object-types.js +0 -57
  81. package/dist/cjs/transformer/project-bundle.js +0 -94
  82. package/dist/cjs/transformer/timestamp.js +0 -20
  83. package/dist/cjs/transformer/update-identifiers.js +0 -93
  84. package/dist/es/__tests__/data/project-dump.json +0 -825
  85. package/dist/es/jats/importer/index.js +0 -16
  86. package/dist/es/jats/importer/jats-front-parser.js +0 -315
  87. package/dist/es/transformer/__tests__/__helpers__/doc.js +0 -29
  88. package/dist/es/transformer/builders.js +0 -186
  89. package/dist/es/transformer/decode.js +0 -864
  90. package/dist/es/transformer/document-object-types.js +0 -28
  91. package/dist/es/transformer/encode.js +0 -654
  92. package/dist/es/transformer/footnotes-order.js +0 -55
  93. package/dist/es/transformer/highlight-markers.js +0 -132
  94. package/dist/es/transformer/html.js +0 -393
  95. package/dist/es/transformer/manuscript-dependencies.js +0 -17
  96. package/dist/es/transformer/model-map.js +0 -22
  97. package/dist/es/transformer/object-types.js +0 -52
  98. package/dist/es/transformer/project-bundle.js +0 -85
  99. package/dist/es/transformer/serializer.js +0 -17
  100. package/dist/es/transformer/timestamp.js +0 -16
  101. package/dist/es/transformer/update-identifiers.js +0 -87
  102. package/dist/types/jats/importer/index.d.ts +0 -16
  103. package/dist/types/jats/importer/jats-front-parser.d.ts +0 -84
  104. package/dist/types/transformer/__tests__/__helpers__/doc.d.ts +0 -18
  105. package/dist/types/transformer/builders.d.ts +0 -61
  106. package/dist/types/transformer/decode.d.ts +0 -51
  107. package/dist/types/transformer/document-object-types.d.ts +0 -17
  108. package/dist/types/transformer/encode.d.ts +0 -29
  109. package/dist/types/transformer/filename.d.ts +0 -16
  110. package/dist/types/transformer/footnote-category.d.ts +0 -17
  111. package/dist/types/transformer/footnotes-order.d.ts +0 -22
  112. package/dist/types/transformer/highlight-markers.d.ts +0 -31
  113. package/dist/types/transformer/html.d.ts +0 -36
  114. package/dist/types/transformer/manuscript-dependencies.d.ts +0 -4
  115. package/dist/types/transformer/model-map.d.ts +0 -19
  116. package/dist/types/transformer/models.d.ts +0 -48
  117. package/dist/types/transformer/object-types.d.ts +0 -30
  118. package/dist/types/transformer/project-bundle.d.ts +0 -30
  119. package/dist/types/transformer/serializer.d.ts +0 -19
  120. package/dist/types/transformer/update-identifiers.d.ts +0 -23
  121. package/dist/types/types.d.ts +0 -2
  122. /package/dist/cjs/{types.js → jats/types.js} +0 -0
  123. /package/dist/es/{types.js → jats/types.js} +0 -0
@@ -0,0 +1,76 @@
1
+ /*!
2
+ * © 2024 Atypon Systems LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { ObjectTypes } from '@manuscripts/json-schema';
17
+ import { defaultTitle } from '../../lib/deafults';
18
+ import { generateID } from '../../transformer';
19
+ import { htmlFromJatsNode } from './jats-parser-utils';
20
+ export const jatsFrontTransformations = {
21
+ setArticleAttrs(doc, template) {
22
+ var _a;
23
+ const doi = (_a = doc.querySelector('article-meta > article-id[pub-id-type="doi"]')) === null || _a === void 0 ? void 0 : _a.textContent;
24
+ const attrs = {
25
+ DOI: doi !== null && doi !== void 0 ? doi : '',
26
+ prototype: template !== null && template !== void 0 ? template : '',
27
+ id: generateID(ObjectTypes.Manuscript),
28
+ };
29
+ const article = doc.querySelector('article');
30
+ if (article) {
31
+ Object.entries(attrs).forEach(([key, value]) => {
32
+ if (value) {
33
+ article.setAttribute(key, value);
34
+ }
35
+ });
36
+ }
37
+ },
38
+ createTitle(front, createElement) {
39
+ var _a;
40
+ let title = front.querySelector('article-meta > title-group > article-title');
41
+ if (title) {
42
+ title.innerHTML = (_a = htmlFromJatsNode(title, createElement)) !== null && _a !== void 0 ? _a : defaultTitle;
43
+ }
44
+ else {
45
+ title = createElement('article-title');
46
+ title.innerHTML = defaultTitle;
47
+ }
48
+ return title;
49
+ },
50
+ createAuthorNotes(document, createElement) {
51
+ const authorNotes = document.querySelector('article-meta > author-notes');
52
+ if (authorNotes) {
53
+ const sectionTitle = createElement('title');
54
+ authorNotes.prepend(sectionTitle);
55
+ }
56
+ return authorNotes;
57
+ },
58
+ createContributors(front, createElement) {
59
+ const contributors = createElement('contributors');
60
+ const contributorsElement = front.querySelectorAll('article-meta > contrib-group > contrib[contrib-type="author"]');
61
+ contributorsElement.forEach((el, priority) => {
62
+ el.setAttribute('priority', priority.toString());
63
+ contributors.appendChild(el);
64
+ });
65
+ return contributors.childNodes.length > 0 ? contributors : null;
66
+ },
67
+ createAffiliations(front, createElement) {
68
+ const affiliations = createElement('affiliations');
69
+ const affiliationsElements = front.querySelectorAll('article-meta > contrib-group > aff');
70
+ affiliationsElements.forEach((el, priority) => {
71
+ el.setAttribute('priority', priority.toString());
72
+ affiliations.appendChild(el);
73
+ });
74
+ return affiliations.childNodes.length > 0 ? affiliations : null;
75
+ },
76
+ };
@@ -13,7 +13,9 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+ import { ObjectTypes } from '@manuscripts/json-schema';
16
17
  import { getTrimmedTextContent } from '../../lib/utils';
18
+ import { generateID } from '../../transformer';
17
19
  export const parseJournalIdentifiers = (element) => {
18
20
  var _a;
19
21
  if (!element) {
@@ -84,3 +86,7 @@ export const parseJournalMeta = (element) => {
84
86
  title: (_b = getTrimmedTextContent(element, 'journal-title-group > journal-title')) !== null && _b !== void 0 ? _b : undefined,
85
87
  };
86
88
  };
89
+ export const parseJournal = (element) => {
90
+ const meta = parseJournalMeta(element);
91
+ return Object.assign(Object.assign({}, meta), { _id: generateID(ObjectTypes.Journal), objectType: ObjectTypes.Journal });
92
+ };
@@ -14,24 +14,38 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import { v4 as uuidv4 } from 'uuid';
17
- import { schema } from '../../schema';
17
+ import { schema, } from '../../schema';
18
18
  import { generateID, nodeTypesMap } from '../../transformer';
19
19
  export const updateDocumentIDs = (node, replacements) => {
20
20
  const warnings = [];
21
- recurseDoc(node, (n) => updateNodeID(n, replacements, warnings));
21
+ const highlightNodes = [];
22
+ recurseDoc(node, (n, parent) => updateNodeID(n, parent, replacements, warnings, highlightNodes));
22
23
  recurseDoc(node, (n) => updateNodeRID(n, replacements, warnings));
23
24
  recurseDoc(node, (n) => updateNodeRIDS(n, replacements, warnings));
25
+ recurseDoc(node, (n) => updateContributorNodesIDS(n, replacements, warnings));
24
26
  return warnings;
25
27
  };
26
- function recurseDoc(node, fn) {
27
- fn(node);
28
- node.descendants((n) => fn(n));
28
+ function recurseDoc(node, fn, parent = null) {
29
+ fn(node, parent);
30
+ node.descendants((n, pos, parent) => fn(n, parent));
29
31
  }
30
- const updateNodeID = (node, replacements, warnings) => {
32
+ const updateNodeID = (node, parent, replacements, warnings, highlightNodes) => {
31
33
  if (node.type === schema.nodes.inline_equation) {
32
34
  node.attrs = Object.assign(Object.assign({}, node.attrs), { id: `InlineMathFragment:${uuidv4()}` });
33
35
  return;
34
36
  }
37
+ if (node.type === schema.nodes.highlight_marker) {
38
+ node.attrs = Object.assign(Object.assign({}, node.attrs), { tid: parent === null || parent === void 0 ? void 0 : parent.attrs.id });
39
+ highlightNodes.push(node);
40
+ return;
41
+ }
42
+ if (node.type === schema.nodes.comment) {
43
+ const highlightNode = highlightNodes.find((n) => n.attrs.id === node.attrs.id);
44
+ if (highlightNode) {
45
+ node.attrs = Object.assign(Object.assign({}, node.attrs), { target: highlightNode.attrs.tid });
46
+ }
47
+ return;
48
+ }
35
49
  if (node.type === schema.nodes.general_table_footnote) {
36
50
  node.attrs = Object.assign(Object.assign({}, node.attrs), { id: `GeneralTableFootnote:${uuidv4()}` });
37
51
  return;
@@ -74,6 +88,30 @@ const updateNodeRIDS = (node, replacements, warnings) => {
74
88
  }
75
89
  node.attrs = Object.assign(Object.assign({}, node.attrs), { rids: previousRIDs.map((r) => replacements.get(r) || r) });
76
90
  };
91
+ const updateContributorNodesIDS = (node, replacements, warnings) => {
92
+ var _a, _b;
93
+ if (node.type === schema.nodes.contributor) {
94
+ const footnote = (_a = node.attrs.footnote) === null || _a === void 0 ? void 0 : _a.map((fn) => {
95
+ return replacements.get(fn.noteID)
96
+ ? Object.assign(Object.assign({}, fn), { noteID: replacements.get(fn.noteID) }) : undefined;
97
+ }).filter(Boolean);
98
+ const corresp = (_b = node.attrs.corresp) === null || _b === void 0 ? void 0 : _b.map((corresp) => {
99
+ return replacements.get(corresp.correspID)
100
+ ? Object.assign(Object.assign({}, corresp), { correspID: replacements.get(corresp.correspID) }) : undefined;
101
+ }).filter(Boolean);
102
+ const affiliations = node.attrs.affiliations
103
+ .map((affiliation) => {
104
+ return replacements.get(affiliation);
105
+ })
106
+ .filter(Boolean);
107
+ node.attrs = Object.assign(Object.assign({}, node.attrs), { footnote,
108
+ corresp,
109
+ affiliations });
110
+ }
111
+ if (node.type !== schema.nodes.contributors) {
112
+ return false;
113
+ }
114
+ };
77
115
  const JATS_TO_HTML_MAPPING = new Map([
78
116
  ['bold', 'b'],
79
117
  ['italic', 'i'],
@@ -13,9 +13,9 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+ import { ObjectTypes } from '@manuscripts/json-schema';
16
17
  import { getTrimmedTextContent } from '../../lib/utils';
17
- import { buildBibliographicDate, buildBibliographicName, buildBibliographyItem, } from '../../transformer/builders';
18
- import { isJATSComment, parseJATSComment } from './jats-comments';
18
+ import { generateID } from '../../transformer';
19
19
  import { htmlFromJatsNode } from './jats-parser-utils';
20
20
  import { References } from './jats-references';
21
21
  const chooseBibliographyItemType = (publicationType) => {
@@ -37,23 +37,15 @@ export const jatsReferenceParser = {
37
37
  const authorNodes = [
38
38
  ...element.querySelectorAll('person-group[person-group-type="author"] > *'),
39
39
  ];
40
- const bibliographyItem = buildBibliographyItem({
40
+ const bibliographyItem = {
41
+ id: generateID(ObjectTypes.BibliographyItem),
41
42
  type: chooseBibliographyItemType(publicationType),
42
- });
43
+ };
43
44
  const titleNode = element.querySelector('article-title');
44
45
  if (titleNode) {
45
46
  bibliographyItem.title = (_a = htmlFromJatsNode(titleNode, createElement)) === null || _a === void 0 ? void 0 : _a.trim();
46
47
  }
47
- const comments = [];
48
48
  const mixedCitation = element.querySelector('mixed-citation');
49
- mixedCitation === null || mixedCitation === void 0 ? void 0 : mixedCitation.childNodes.forEach((item) => {
50
- if (isJATSComment(item)) {
51
- const comment = parseJATSComment(item);
52
- if (comment) {
53
- comments.push(comment);
54
- }
55
- }
56
- });
57
49
  if (authorNodes.length <= 0) {
58
50
  mixedCitation === null || mixedCitation === void 0 ? void 0 : mixedCitation.childNodes.forEach((item) => {
59
51
  var _a, _b, _c;
@@ -66,7 +58,7 @@ export const jatsReferenceParser = {
66
58
  }
67
59
  const source = getTrimmedTextContent(element, 'source');
68
60
  if (source) {
69
- bibliographyItem['container-title'] = source;
61
+ bibliographyItem.containerTitle = source;
70
62
  }
71
63
  const volume = getTrimmedTextContent(element, 'volume');
72
64
  if (volume) {
@@ -87,18 +79,23 @@ export const jatsReferenceParser = {
87
79
  }
88
80
  const year = getTrimmedTextContent(element, 'year');
89
81
  if (year) {
90
- bibliographyItem.issued = buildBibliographicDate({
82
+ bibliographyItem.issued = {
91
83
  'date-parts': [[year]],
92
- });
84
+ _id: generateID(ObjectTypes.BibliographicDate),
85
+ objectType: ObjectTypes.BibliographicDate,
86
+ };
93
87
  }
94
88
  const doi = getTrimmedTextContent(element, 'pub-id[pub-id-type="doi"]');
95
89
  if (doi) {
96
- bibliographyItem.DOI = doi;
90
+ bibliographyItem.doi = doi;
97
91
  }
98
92
  const authors = [];
99
93
  authorNodes.forEach((authorNode) => {
100
94
  var _a;
101
- const name = buildBibliographicName({});
95
+ const name = {
96
+ _id: generateID(ObjectTypes.BibliographicName),
97
+ objectType: ObjectTypes.BibliographicName,
98
+ };
102
99
  const given = getTrimmedTextContent(authorNode, 'given-names');
103
100
  if (given) {
104
101
  name.given = given;
@@ -107,10 +104,6 @@ export const jatsReferenceParser = {
107
104
  if (family) {
108
105
  name.family = family;
109
106
  }
110
- const suffix = getTrimmedTextContent(authorNode, 'suffix');
111
- if (suffix) {
112
- name.suffix = suffix;
113
- }
114
107
  if (authorNode.nodeName === 'collab') {
115
108
  name.literal = (_a = authorNode.textContent) === null || _a === void 0 ? void 0 : _a.trim();
116
109
  }
@@ -120,7 +113,7 @@ export const jatsReferenceParser = {
120
113
  bibliographyItem.author = authors;
121
114
  }
122
115
  const id = element.getAttribute('id');
123
- references.add(bibliographyItem, id, comments);
116
+ references.add(bibliographyItem, id);
124
117
  });
125
118
  return references;
126
119
  },
@@ -1,30 +1,30 @@
1
+ /*!
2
+ * © 2023 Atypon Systems LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
1
16
  export class References {
2
17
  constructor() {
3
18
  this.items = new Map();
4
19
  this.IDs = new Map();
5
- this.comments = new Map();
6
20
  }
7
- add(item, id, comments) {
8
- this.items.set(item._id, item);
9
- this.comments.set(item._id, comments);
21
+ add(item, id) {
22
+ this.items.set(item.id, item);
10
23
  if (id) {
11
- this.IDs.set(id, item._id);
24
+ this.IDs.set(id, item.id);
12
25
  }
13
26
  }
14
27
  getBibliographyItems() {
15
28
  return [...this.items.values()];
16
29
  }
17
- getComments(id) {
18
- return this.getValue(id, this.comments) || [];
19
- }
20
- getValue(id, map) {
21
- const value = map.get(id);
22
- if (value) {
23
- return value;
24
- }
25
- const id2 = this.IDs.get(id);
26
- if (id2) {
27
- return map.get(id2);
28
- }
29
- }
30
30
  }
@@ -14,44 +14,14 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import { InvalidInput } from '../../errors';
17
- import { buildBibliographyElement, buildSection, encode, } from '../../transformer';
18
- import { buildManuscript } from '../../transformer/builders';
19
- import { generateID } from '../../transformer/id';
20
- import { findManuscript } from '../../transformer/project-bundle';
21
- import { jatsBodyDOMParser } from './jats-body-dom-parser';
22
17
  import { jatsBodyTransformations } from './jats-body-transformations';
23
- import { createComments, createReferenceComments, markComments, } from './jats-comments';
24
- import { jatsFrontParser } from './jats-front-parser';
18
+ import { markComments } from './jats-comments';
19
+ import { jatsDOMParser } from './jats-dom-parser';
20
+ import { jatsFrontTransformations } from './jats-front-transformations';
21
+ import { parseJournal } from './jats-journal-meta-parser';
25
22
  import { updateDocumentIDs } from './jats-parser-utils';
26
23
  import { jatsReferenceParser } from './jats-reference-parser';
27
- export const parseJATSFront = (doc, front) => {
28
- const createElement = createElementFn(doc);
29
- const journal = jatsFrontParser.parseJournal(front.querySelector('journal-meta'));
30
- const titles = jatsFrontParser.parseTitles(front.querySelector('article-meta > title-group'), createElement);
31
- const DOI = jatsFrontParser.parseDOI(front);
32
- const { affiliations, affiliationIDs } = jatsFrontParser.parseAffiliations([
33
- ...front.querySelectorAll('article-meta > contrib-group > aff'),
34
- ]);
35
- const { footnotes, footnoteIDs, authorNotes, authorNotesParagraphs, correspondingIDs, correspondingList, } = jatsFrontParser.parseAuthorNotes(front.querySelector('article-meta > author-notes'));
36
- const authors = jatsFrontParser.parseContributors([
37
- ...front.querySelectorAll('article-meta > contrib-group > contrib[contrib-type="author"]'),
38
- ], affiliationIDs, footnoteIDs, correspondingIDs);
39
- const history = jatsFrontParser.parseDates(front.querySelector('article-meta > history'));
40
- const counts = jatsFrontParser.parseCounts(front.querySelector('article-meta counts'));
41
- const manuscript = Object.assign(Object.assign(Object.assign(Object.assign({}, buildManuscript()), counts), history), { DOI });
42
- return generateIDs([
43
- manuscript,
44
- titles,
45
- journal,
46
- ...authorNotesParagraphs,
47
- ...authorNotes,
48
- ...footnotes,
49
- ...authors,
50
- ...affiliations,
51
- ...correspondingList,
52
- ]);
53
- };
54
- export const parseJATSBody = (doc, body, references) => {
24
+ const parseJATSBody = (doc, body, references) => {
55
25
  const createElement = createElementFn(doc);
56
26
  jatsBodyTransformations.ensureSection(body, createElement);
57
27
  jatsBodyTransformations.moveCaptionsToEnd(body);
@@ -62,62 +32,56 @@ export const parseJATSBody = (doc, body, references) => {
62
32
  jatsBodyTransformations.createSuppleMaterials(doc, body, createElement);
63
33
  jatsBodyTransformations.createKeywords(doc, body, createElement);
64
34
  jatsBodyTransformations.orderTableFootnote(doc, body);
65
- const node = jatsBodyDOMParser.parse(body).firstChild;
66
- if (!node) {
67
- throw new Error('No content was parsed from the JATS article body');
68
- }
69
- const replacements = new Map(references === null || references === void 0 ? void 0 : references.IDs);
70
- updateDocumentIDs(node, replacements);
71
- return encode(node).values();
35
+ jatsBodyTransformations.moveReferencesToBackmatter(body, references, createElement);
72
36
  };
73
- const createBibliographyModels = (references) => {
74
- const models = [];
75
- const bibliographyItems = references.getBibliographyItems();
76
- const bibliographyElement = buildBibliographyElement(bibliographyItems);
77
- const bibliographySection = Object.assign(Object.assign({}, buildSection(99)), { category: 'MPSectionCategory:bibliography', elementIDs: [bibliographyElement._id], title: 'References' });
78
- const comments = createReferenceComments(references);
79
- models.push(bibliographySection);
80
- models.push(bibliographyElement);
81
- models.push(...bibliographyItems);
82
- models.push(...comments);
83
- return models;
37
+ const parseJATSFront = (doc, front, template) => {
38
+ const createElement = createElementFn(doc);
39
+ jatsFrontTransformations.setArticleAttrs(doc, template);
40
+ const authorNotes = jatsFrontTransformations.createAuthorNotes(doc, createElement);
41
+ if (authorNotes) {
42
+ doc.documentElement.prepend(authorNotes);
43
+ }
44
+ const affiliations = jatsFrontTransformations.createAffiliations(front, createElement);
45
+ if (affiliations) {
46
+ doc.documentElement.prepend(affiliations);
47
+ }
48
+ const contributors = jatsFrontTransformations.createContributors(front, createElement);
49
+ if (contributors) {
50
+ doc.documentElement.prepend(contributors);
51
+ }
52
+ const title = jatsFrontTransformations.createTitle(front, createElement);
53
+ if (title) {
54
+ doc.documentElement.prepend(title);
55
+ }
84
56
  };
85
57
  const createElementFn = (doc) => (tagName) => doc.createElement(tagName);
86
- const generateIDs = (models) => models.map((m) => m._id ? m : Object.assign(Object.assign({}, m), { _id: generateID(m.objectType) }));
87
- export const parseJATSArticle = (doc) => {
58
+ export const parseJATSArticle = (doc, template) => {
88
59
  const article = doc.querySelector('article');
89
60
  const front = doc.querySelector('front');
90
61
  const body = doc.querySelector('body');
91
62
  const back = doc.querySelector('back');
92
- if (!front) {
93
- throw new InvalidInput('Invalid JATS format! Missing front element');
94
- }
95
- if (!article) {
96
- throw new InvalidInput('Invalid JATS format! Missing article element');
63
+ if (!article || !front) {
64
+ throw new InvalidInput('invalid JATS format');
97
65
  }
98
- const marks = markComments(doc);
66
+ markComments(doc);
67
+ const journal = parseJournal(front.querySelector('journal-meta'));
99
68
  const createElement = createElementFn(doc);
100
- const models = [];
101
69
  let references;
102
70
  if (back) {
103
71
  references = jatsReferenceParser.parseReferences([...back.querySelectorAll('ref-list > ref')], createElement);
104
72
  }
105
- models.push(...parseJATSFront(doc, front));
73
+ const replacements = new Map(references === null || references === void 0 ? void 0 : references.IDs);
74
+ parseJATSFront(doc, front, template);
106
75
  if (body) {
107
- models.push(...parseJATSBody(doc, body, references));
108
- }
109
- const modelMap = new Map(models.map((model) => [model._id, model]));
110
- const manuscript = findManuscript(modelMap);
111
- if (manuscript) {
112
- const type = article.getAttribute('article-type');
113
- manuscript.articleType = type || 'other';
76
+ parseJATSBody(doc, body, references);
114
77
  }
115
- if (references && references.items.size) {
116
- models.push(...createBibliographyModels(references));
117
- }
118
- if (marks.length) {
119
- const comments = createComments(models, marks);
120
- models.push(...comments);
78
+ const node = jatsDOMParser.parse(doc).firstChild;
79
+ if (!node) {
80
+ throw new Error('No content was parsed from the JATS article body');
121
81
  }
122
- return models;
82
+ updateDocumentIDs(node, replacements);
83
+ return {
84
+ node: node,
85
+ journal,
86
+ };
123
87
  };
@@ -13,6 +13,8 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export { parseJATSFront, parseJATSBody, parseJATSArticle } from './importer';
17
- export * from './jats-exporter';
18
- export * from './jats-versions';
16
+ export * from './exporter/jats-exporter';
17
+ export * from './exporter/jats-versions';
18
+ export * from './exporter/labels';
19
+ export * from './importer/create-article-node';
20
+ export { parseJATSArticle } from './importer/parse-jats-article';
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * © 2019 Atypon Systems LLC
2
+ * © 2024 Atypon Systems LLC
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -13,4 +13,4 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export declare const timestamp: () => number;
16
+ export const defaultTitle = 'Untitled Manuscript';
@@ -74,3 +74,12 @@ export const getTrimmedTextContent = (node, querySelector) => {
74
74
  }
75
75
  return (_b = (_a = node.querySelector(querySelector)) === null || _a === void 0 ? void 0 : _a.textContent) === null || _b === void 0 ? void 0 : _b.trim();
76
76
  };
77
+ export const timestamp = () => Math.floor(Date.now() / 1000);
78
+ export const generateAttachmentFilename = (id, contentType) => {
79
+ const basename = id.replace(':', '_');
80
+ if (!contentType) {
81
+ return basename;
82
+ }
83
+ const [, mimeSubType] = contentType.split('/');
84
+ return `${basename}.${mimeSubType}`;
85
+ };
@@ -15,9 +15,14 @@
15
15
  */
16
16
  import { v4 as uuid } from 'uuid';
17
17
  import { nodeTypesMap } from './node-types';
18
- export const generateNodeID = (type) => {
19
- return nodeTypesMap.get(type) + ':' + uuid().toUpperCase();
20
- };
18
+ export var ExtraObjectTypes;
19
+ (function (ExtraObjectTypes) {
20
+ ExtraObjectTypes["PlaceholderElement"] = "MPPlaceholderElement";
21
+ ExtraObjectTypes["GeneralTableFootnote"] = "MPGeneralTableFootnote";
22
+ })(ExtraObjectTypes || (ExtraObjectTypes = {}));
21
23
  export const generateID = (objectType) => {
22
24
  return objectType + ':' + uuid().toUpperCase();
23
25
  };
26
+ export const generateNodeID = (type) => {
27
+ return nodeTypesMap.get(type) + ':' + uuid().toUpperCase();
28
+ };
@@ -13,24 +13,8 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export * from './builders';
17
- export * from './decode';
18
- export * from './document-object-types';
19
- export * from './encode';
20
- export * from './filename';
21
- export * from './highlight-markers';
22
- export * from './html';
23
16
  export * from './id';
24
- export * from './labels';
25
- export * from './manuscript-dependencies';
26
- export * from './models';
27
17
  export * from './node-names';
28
18
  export * from './node-title';
29
19
  export * from './node-types';
30
- export * from './object-types';
31
- export * from './project-bundle';
32
20
  export * from './section-category';
33
- export * from './serializer';
34
- export * from './timestamp';
35
- export * from './update-identifiers';
36
- export { createTestDoc } from './__tests__/__helpers__/doc';
@@ -1 +1 @@
1
- export const VERSION = "2.3.37";
1
+ export const VERSION = "2.3.38-LEAN-3911.0";
@@ -1,11 +1,11 @@
1
+ export * from './errors';
2
+ export { getVersion } from './getVersion';
3
+ export * from './jats';
4
+ export * from './jats/types';
1
5
  export * from './lib/section-group-type';
2
6
  export * from './lib/table-cell-styles';
3
7
  export * from './lib/utils';
4
8
  export * from './schema';
5
- export * from './transformer';
6
- export * from './jats';
7
- export * from './types';
8
- export * from './errors';
9
- export { getVersion } from './getVersion';
10
- export { migrateFor, JSONNode } from './schema/migration/migrate';
9
+ export { JSONNode, migrateFor } from './schema/migration/migrate';
11
10
  export { isSectionLabelNode } from './schema/nodes/section_label';
11
+ export * from './transformer';