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