@manuscripts/transform 3.0.66 → 3.0.68-LEAN-4574.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 (44) hide show
  1. package/dist/cjs/index.js +2 -3
  2. package/dist/cjs/jats/exporter/citeproc.js +164 -0
  3. package/dist/cjs/jats/exporter/jats-exporter.js +85 -196
  4. package/dist/cjs/jats/importer/jats-dom-parser.js +50 -63
  5. package/dist/cjs/lib/citeproc.js +13 -0
  6. package/dist/cjs/lib/credit-roles.js +76 -0
  7. package/dist/cjs/lib/utils.js +17 -1
  8. package/dist/cjs/schema/index.js +1 -0
  9. package/dist/cjs/schema/nodes/bibliography_element.js +3 -1
  10. package/dist/cjs/schema/nodes/bibliography_item.js +3 -7
  11. package/dist/cjs/schema/nodes/comment.js +3 -1
  12. package/dist/cjs/schema/nodes/contributor.js +1 -0
  13. package/dist/cjs/schema/nodes/list.js +3 -45
  14. package/dist/cjs/version.js +1 -1
  15. package/dist/es/index.js +1 -1
  16. package/dist/es/jats/exporter/citeproc.js +156 -0
  17. package/dist/es/jats/exporter/jats-exporter.js +63 -196
  18. package/dist/es/jats/importer/jats-dom-parser.js +52 -65
  19. package/dist/es/lib/citeproc.js +9 -0
  20. package/dist/es/lib/credit-roles.js +73 -0
  21. package/dist/es/lib/utils.js +15 -0
  22. package/dist/es/schema/index.js +1 -0
  23. package/dist/es/schema/nodes/bibliography_element.js +1 -0
  24. package/dist/es/schema/nodes/bibliography_item.js +1 -6
  25. package/dist/es/schema/nodes/comment.js +1 -0
  26. package/dist/es/schema/nodes/contributor.js +1 -0
  27. package/dist/es/schema/nodes/list.js +2 -42
  28. package/dist/es/version.js +1 -1
  29. package/dist/types/index.d.ts +1 -1
  30. package/dist/types/jats/exporter/citeproc.d.ts +18 -0
  31. package/dist/types/jats/exporter/jats-exporter.d.ts +5 -29
  32. package/dist/types/jats/importer/jats-dom-parser.d.ts +2 -2
  33. package/dist/types/lib/citeproc.d.ts +3 -0
  34. package/dist/types/lib/credit-roles.d.ts +32 -0
  35. package/dist/types/lib/utils.d.ts +2 -1
  36. package/dist/types/schema/index.d.ts +1 -0
  37. package/dist/types/schema/nodes/bibliography_element.d.ts +1 -0
  38. package/dist/types/schema/nodes/bibliography_item.d.ts +9 -9
  39. package/dist/types/schema/nodes/citation.d.ts +3 -4
  40. package/dist/types/schema/nodes/comment.d.ts +3 -3
  41. package/dist/types/schema/nodes/contributor.d.ts +6 -0
  42. package/dist/types/schema/nodes/list.d.ts +5 -11
  43. package/dist/types/version.d.ts +1 -1
  44. package/package.json +5 -7
package/dist/cjs/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.isSectionLabelNode = exports.migrateFor = exports.getVersion = void 0;
17
+ exports.migrateFor = exports.getVersion = void 0;
18
18
  __exportStar(require("./errors"), exports);
19
19
  var getVersion_1 = require("./getVersion");
20
20
  Object.defineProperty(exports, "getVersion", { enumerable: true, get: function () { return getVersion_1.getVersion; } });
@@ -23,10 +23,9 @@ __exportStar(require("./jats/types"), exports);
23
23
  __exportStar(require("./lib/footnotes"), exports);
24
24
  __exportStar(require("./lib/utils"), exports);
25
25
  __exportStar(require("./lib/section-categories"), exports);
26
+ __exportStar(require("./lib/citeproc"), exports);
26
27
  __exportStar(require("./schema"), exports);
27
28
  var migrate_1 = require("./schema/migration/migrate");
28
29
  Object.defineProperty(exports, "migrateFor", { enumerable: true, get: function () { return migrate_1.migrateFor; } });
29
- var section_label_1 = require("./schema/nodes/section_label");
30
- Object.defineProperty(exports, "isSectionLabelNode", { enumerable: true, get: function () { return section_label_1.isSectionLabelNode; } });
31
30
  __exportStar(require("./transformer"), exports);
32
31
  __exportStar(require("./types"), exports);
@@ -0,0 +1,164 @@
1
+ "use strict";
2
+ /*!
3
+ * © 2025 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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
18
+ return (mod && mod.__esModule) ? mod : { "default": mod };
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.jatsVariableWrapper = exports.initJats = void 0;
22
+ const citeproc_1 = __importDefault(require("citeproc"));
23
+ const normalizeID = (id) => id.replace(/:/g, '_');
24
+ const labelOnly = /^<label>.+<\/label>$/;
25
+ const initJats = () => {
26
+ if (citeproc_1.default.Output.Formats.jats) {
27
+ return;
28
+ }
29
+ citeproc_1.default.Output.Formats.jats = Object.assign(Object.assign({}, citeproc_1.default.Output.Formats.html), { text_escape: function (text) {
30
+ return text !== null && text !== void 0 ? text : '';
31
+ }, bibstart: '<ref-list>', bibend: '</ref-list>', '@font-style/italic': '<italic>%%STRING%%</italic>', '@font-style/oblique': '<italic>%%STRING%%</italic>', '@font-style/normal': false, '@font-variant/small-caps': '<smallcaps>%%STRING%%</smallcaps>', '@font-variant/normal': false, '@font-weight/bold': '<bold>%%STRING%%</bold>', '@font-weight/normal': false, '@font-weight/light': false, '@text-decoration/none': false, '@text-decoration/underline': '<underline>%%STRING%%</underline>', '@vertical-align/sup': '<sup>%%STRING%%</sup>', '@vertical-align/sub': '<sub>%%STRING%%</sub>', '@vertical-align/baseline': false, '@bibliography/entry': function (state, str) {
32
+ const id = this.system_id;
33
+ const item = state.registry.registry[id].ref;
34
+ const type = getPublicationType(item);
35
+ str = str.trim();
36
+ if (labelOnly.test(str)) {
37
+ return `<ref id="${normalizeID(id)}">${str}<mixed-citation publication-type="${type}">${item.literal}</mixed-citation></ref>`;
38
+ }
39
+ else if (str.includes('mixed-citation')) {
40
+ return `<ref id="${normalizeID(id)}">${str.replace('%%TYPE%%', type)}</ref>`;
41
+ }
42
+ else {
43
+ return `<ref id="${normalizeID(id)}"><mixed-citation publication-type="${type}">${str}</mixed-citation></ref>`;
44
+ }
45
+ }, '@display/block': false, '@display/left-margin': function (state, str) {
46
+ return `<label>${str}</label>`;
47
+ }, '@display/right-inline': function (state, str) {
48
+ return `<mixed-citation publication-type="%%TYPE%%">${str}</mixed-citation>`;
49
+ }, '@display/indent': false, '@URL/true': false, '@DOI/true': false });
50
+ const name = citeproc_1.default.NameOutput.prototype._renderOnePersonalName;
51
+ citeproc_1.default.NameOutput.prototype._renderOnePersonalName = function (...args) {
52
+ const area = this.state.tmp.area;
53
+ const blob = name.call(this, ...args);
54
+ if (blob && area === 'bibliography') {
55
+ blob.strings.prefix = '<string-name>';
56
+ blob.strings.suffix = '</string-name>';
57
+ }
58
+ return blob;
59
+ };
60
+ const given = citeproc_1.default.NameOutput.prototype._givenName;
61
+ citeproc_1.default.NameOutput.prototype._givenName = function (...args) {
62
+ const area = this.state.tmp.area;
63
+ const info = given.call(this, ...args);
64
+ if (info.blob && area === 'bibliography') {
65
+ info.blob.strings.prefix = '<given-names>';
66
+ info.blob.strings.suffix = '</given-names>';
67
+ }
68
+ return info;
69
+ };
70
+ const family = citeproc_1.default.NameOutput.prototype._familyName;
71
+ citeproc_1.default.NameOutput.prototype._familyName = function (...args) {
72
+ const area = this.state.tmp.area;
73
+ const blob = family.call(this, ...args);
74
+ if (blob && area === 'bibliography') {
75
+ blob.strings.prefix = '<surname>';
76
+ blob.strings.suffix = '</surname>';
77
+ }
78
+ return blob;
79
+ };
80
+ };
81
+ exports.initJats = initJats;
82
+ const namesWrapper = (type) => (str) => `<person-group person-group-type="${type}">${str}</person-group>`;
83
+ const formatDate = (date) => {
84
+ let output = date.year;
85
+ if (date.month) {
86
+ output += '-' + String(date.month).padStart(2, '0');
87
+ if (date.day) {
88
+ output += '-' + String(date.day).padStart(2, '0');
89
+ }
90
+ }
91
+ return output;
92
+ };
93
+ const getPublicationType = (item) => {
94
+ switch (item.type) {
95
+ case 'article-journal':
96
+ return 'journal';
97
+ case 'webpage':
98
+ return 'page';
99
+ case 'dataset':
100
+ return 'data';
101
+ default:
102
+ return item.type;
103
+ }
104
+ };
105
+ const wrappers = {
106
+ author: namesWrapper('author'),
107
+ issued: (str, item) => str.replace(item.issued.year, `<year>${item.issued.year}</year>`),
108
+ 'container-title': (str) => `<source>${str}</source>`,
109
+ volume: (str) => `<volume>${str}</volume>`,
110
+ issue: (str) => `<issue>${str}</issue>`,
111
+ supplement: (str) => `<supplement>${str}</supplement>`,
112
+ page: (str) => {
113
+ let fpage = str;
114
+ let lpage;
115
+ const parts = str.split('-');
116
+ if (parts.length === 2) {
117
+ fpage = parts[0];
118
+ lpage = parts[1];
119
+ }
120
+ str = str.replace(fpage, `<fpage>${fpage}</fpage>`);
121
+ if (lpage) {
122
+ str = str.replace(lpage, `<lpage>${lpage}</lpage>`);
123
+ }
124
+ return str;
125
+ },
126
+ title: (str, item) => {
127
+ const type = item.type;
128
+ switch (type) {
129
+ case 'dataset':
130
+ return `<data-title>${str}</data-title>`;
131
+ case 'article-journal':
132
+ case 'preprint':
133
+ return `<article-title>${str}</article-title>`;
134
+ default:
135
+ return `<part-title>${str}</part-title>`;
136
+ }
137
+ },
138
+ std: (str) => `<pub-id pub-id-type="std-designation">${str}</pub-id>`,
139
+ 'collection-title': (str) => `<series>${str}</series>`,
140
+ edition: (str) => `<edition>${str}</edition>`,
141
+ publisher: (str) => `<publisher-name>${str}</publisher-name>`,
142
+ 'publisher-place': (str) => `<publisher-loc>${str}</publisher-loc>`,
143
+ event: (str) => `<conf-name>${str}</conf-name>`,
144
+ 'event-place': (str) => `<conf-loc>${str}</conf-loc>`,
145
+ 'number-of-pages': (str) => `<size units="pages">${str}</size>`,
146
+ institution: (str) => `<institution>${str}</institution>`,
147
+ locator: (str) => `<elocation-id>${str}</elocation-id>`,
148
+ editor: namesWrapper('editor'),
149
+ accessed: (str, item) => `<date-in-citation content-type="access-date" iso-8601-date="${formatDate(item.accessed)}">${str}</date-in-citation>`,
150
+ 'event-date': (str, item) => `<conf-date iso-8601-date="${formatDate(item['event-date'])}">${str}</conf-date>`,
151
+ DOI: (str) => `<pub-id pub-id-type="doi">${str}</pub-id>`,
152
+ URL: (str) => `<ext-link ext-link-type="uri" xlink:href="${str}">${str}</ext-link>`,
153
+ };
154
+ const jatsVariableWrapper = (params, pre, str, post) => {
155
+ if (str && params.context === 'bibliography') {
156
+ const name = params.variableNames[0];
157
+ const fn = wrappers[name];
158
+ if (fn) {
159
+ str = fn(str, params.itemData);
160
+ }
161
+ }
162
+ return `${pre}${str !== null && str !== void 0 ? str : ''}${post}`;
163
+ };
164
+ exports.jatsVariableWrapper = jatsVariableWrapper;
@@ -14,30 +14,47 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ var desc = Object.getOwnPropertyDescriptor(m, k);
20
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
21
+ desc = { enumerable: true, get: function() { return m[k]; } };
22
+ }
23
+ Object.defineProperty(o, k2, desc);
24
+ }) : (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ o[k2] = m[k];
27
+ }));
28
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
29
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
30
+ }) : function(o, v) {
31
+ o["default"] = v;
32
+ });
33
+ var __importStar = (this && this.__importStar) || function (mod) {
34
+ if (mod && mod.__esModule) return mod;
35
+ var result = {};
36
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
37
+ __setModuleDefault(result, mod);
38
+ return result;
39
+ };
17
40
  var __importDefault = (this && this.__importDefault) || function (mod) {
18
41
  return (mod && mod.__esModule) ? mod : { "default": mod };
19
42
  };
20
43
  Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.JATSExporter = exports.buildCitations = exports.createCounter = void 0;
22
- const json_schema_1 = require("@manuscripts/json-schema");
23
- const library_1 = require("@manuscripts/library");
24
- const debug_1 = __importDefault(require("debug"));
44
+ exports.JATSExporter = exports.createCounter = void 0;
45
+ const Citeproc = __importStar(require("citeproc"));
25
46
  const prosemirror_model_1 = require("prosemirror-model");
26
47
  const prosemirror_utils_1 = require("prosemirror-utils");
27
48
  const w3c_xmlserializer_1 = __importDefault(require("w3c-xmlserializer"));
49
+ const citeproc_1 = require("../../lib/citeproc");
50
+ const credit_roles_1 = require("../../lib/credit-roles");
28
51
  const footnotes_1 = require("../../lib/footnotes");
29
52
  const html_1 = require("../../lib/html");
30
53
  const schema_1 = require("../../schema");
31
54
  const transformer_1 = require("../../transformer");
55
+ const citeproc_2 = require("./citeproc");
32
56
  const jats_versions_1 = require("./jats-versions");
33
57
  const labels_1 = require("./labels");
34
- const publicationTypeToJats = {
35
- article: 'journal',
36
- 'article-journal': 'journal',
37
- webpage: 'web',
38
- dataset: 'data',
39
- };
40
- const warn = (0, debug_1.default)('manuscripts-transform');
41
58
  const XLINK_NAMESPACE = 'http://www.w3.org/1999/xlink';
42
59
  const normalizeID = (id) => id.replace(/:/g, '_');
43
60
  const parser = prosemirror_model_1.DOMParser.fromSchema(schema_1.schema);
@@ -96,28 +113,8 @@ const chooseRefType = (type) => {
96
113
  }
97
114
  };
98
115
  const sortContributors = (a, b) => Number(a.attrs.priority) - Number(b.attrs.priority);
99
- const buildCitations = (citations) => citations.map((citation) => ({
100
- citationID: citation.attrs.id,
101
- citationItems: citation.attrs.rids.map((rid) => ({
102
- id: rid,
103
- })),
104
- properties: {
105
- noteIndex: 0,
106
- },
107
- }));
108
- exports.buildCitations = buildCitations;
109
116
  class JATSExporter {
110
117
  constructor() {
111
- this.getLibraryItem = (manuscriptID) => {
112
- return (id) => {
113
- var _a;
114
- const node = (_a = (0, prosemirror_utils_1.findChildrenByAttr)(this.manuscriptNode, (attrs) => attrs.id === id)[0]) === null || _a === void 0 ? void 0 : _a.node;
115
- if (!node) {
116
- return undefined;
117
- }
118
- return Object.assign(Object.assign({}, node.attrs), { _id: node.attrs.id, manuscriptID, objectType: json_schema_1.ObjectTypes.BibliographyItem });
119
- };
120
- };
121
118
  this.nodesMap = new Map();
122
119
  this.populateNodesMap = () => {
123
120
  this.manuscriptNode.descendants((node) => {
@@ -132,7 +129,7 @@ class JATSExporter {
132
129
  var _a;
133
130
  this.manuscriptNode = manuscriptNode;
134
131
  this.populateNodesMap();
135
- this.generateCitationTexts(options.csl, manuscriptNode.attrs.id);
132
+ this.initCiteprocEngine(options.csl);
136
133
  this.createSerializer();
137
134
  const versionIds = (0, jats_versions_1.selectVersionIds)((_a = options.version) !== null && _a !== void 0 ? _a : '1.2');
138
135
  this.document = document.implementation.createDocument(null, 'article', document.implementation.createDocumentType('article', versionIds.publicId, versionIds.systemId));
@@ -159,6 +156,34 @@ class JATSExporter {
159
156
  await this.rewriteIDs();
160
157
  return (0, w3c_xmlserializer_1.default)(this.document);
161
158
  };
159
+ this.initCiteprocEngine = (csl) => {
160
+ const bibitems = new Map();
161
+ const citations = new Map();
162
+ this.manuscriptNode.descendants((n) => {
163
+ if ((0, schema_1.isBibliographyItemNode)(n)) {
164
+ bibitems.set(n.attrs.id, n.attrs);
165
+ }
166
+ if ((0, schema_1.isCitationNode)(n)) {
167
+ citations.set(n.attrs.id, (0, citeproc_1.buildCiteprocCitation)(n.attrs));
168
+ }
169
+ });
170
+ (0, citeproc_2.initJats)();
171
+ const engine = new Citeproc.Engine({
172
+ retrieveLocale: () => csl.locale,
173
+ retrieveItem: (id) => {
174
+ const item = bibitems.get(id);
175
+ if (!item) {
176
+ throw Error(`Missing bibliography item with id ${id}`);
177
+ }
178
+ return item;
179
+ },
180
+ variableWrapper: citeproc_2.jatsVariableWrapper,
181
+ }, csl.style);
182
+ engine.setOutputFormat('jats');
183
+ const output = engine.rebuildProcessorState([...citations.values()]);
184
+ this.engine = engine;
185
+ this.renderedCitations = new Map(output.map((i) => [i[0], i[2]]));
186
+ };
162
187
  this.nodeFromJATS = (JATSFragment) => {
163
188
  JATSFragment = JATSFragment.trim();
164
189
  JATSFragment = JATSFragment.replace('&nbsp;', ' ');
@@ -413,139 +438,20 @@ class JATSExporter {
413
438
  }
414
439
  let refList = this.document.querySelector('ref-list');
415
440
  if (!refList) {
416
- warn('No bibliography element, creating a ref-list anyway');
417
441
  refList = this.createElement('ref-list');
418
442
  }
419
443
  back.appendChild(refList);
420
- const bibliographyItems = this.getChildrenOfType(schema_1.schema.nodes.bibliography_item);
421
- const [meta] = this.citationProvider.makeBibliography();
422
- for (const [id] of meta.entry_ids) {
423
- const bibliographyItem = bibliographyItems.find((n) => n.attrs.id === id);
424
- if (!bibliographyItem) {
425
- continue;
444
+ const parser = new DOMParser();
445
+ const [_, bibliography] = this.engine.makeBibliography();
446
+ for (let i = 0; i < bibliography.length; i++) {
447
+ const item = `<template xmlns:xlink="${XLINK_NAMESPACE}">${bibliography[i]}</template>`;
448
+ const ref = parser.parseFromString(item, 'text/xml').querySelector('ref');
449
+ if (ref) {
450
+ refList.appendChild(ref);
426
451
  }
427
- const ref = this.createElement('ref');
428
- ref.setAttribute('id', normalizeID(id));
429
- const getPublicationType = (pubType) => publicationTypeToJats[pubType !== null && pubType !== void 0 ? pubType : ''] || pubType || 'journal';
430
- if (bibliographyItem.attrs.literal) {
431
- this.appendElement(ref, 'mixed-citation', bibliographyItem.attrs.literal, {
432
- 'publication-type': getPublicationType(bibliographyItem.attrs.type),
433
- });
434
- }
435
- else {
436
- const citation = this.appendElement(ref, 'element-citation', undefined, {
437
- 'publication-type': getPublicationType(bibliographyItem.attrs.type),
438
- });
439
- const attributeHandlers = {
440
- author: (v) => this.processRefPersonGroup(citation, 'author', v),
441
- editor: (v) => this.processRefPersonGroup(citation, 'editor', v),
442
- title: (v) => this.setTitleContent(this.appendElement(citation, 'article-title'), v),
443
- comment: (v) => this.appendElement(citation, 'comment', v),
444
- 'container-title': (v) => this.setTitleContent(this.appendElement(citation, 'source'), v),
445
- issued: ({ 'date-parts': parts }) => this.processDateParts(citation, parts),
446
- volume: (v) => this.appendElement(citation, 'volume', v),
447
- issue: (v) => this.appendElement(citation, 'issue', v),
448
- supplement: (v) => this.appendElement(citation, 'supplement', v),
449
- page: (v) => this.processPageString(citation, String(v)),
450
- DOI: (v) => this.appendElement(citation, 'pub-id', v, { 'pub-id-type': 'doi' }),
451
- std: (v) => this.appendElement(citation, 'pub-id', v, {
452
- 'pub-id-type': 'std-designation',
453
- }),
454
- 'collection-title': (v) => this.appendElement(citation, 'series', v),
455
- edition: (v) => this.appendElement(citation, 'edition', v),
456
- 'publisher-place': (v) => this.appendElement(citation, 'publisher-loc', v),
457
- publisher: (v) => this.appendElement(citation, 'publisher-name', v),
458
- event: (v) => this.appendElement(citation, 'conf-name', v),
459
- 'event-place': (v) => this.appendElement(citation, 'conf-loc', v),
460
- 'number-of-pages': (v) => this.appendElement(citation, 'size', v, { units: 'pages' }),
461
- institution: (v) => this.appendElement(citation, 'institution', v),
462
- locator: (v) => this.appendElement(citation, 'elocation-id', v),
463
- URL: (v) => this.appendElement(citation, 'ext-link', v, {
464
- 'ext-link-type': 'uri',
465
- }),
466
- 'event-date': (v) => this.processDate(citation, 'conf-date', v),
467
- accessed: (v) => this.processDate(citation, 'date-in-citation', v),
468
- };
469
- Object.entries(attributeHandlers).forEach(([key, handler]) => {
470
- const value = bibliographyItem.attrs[key];
471
- if (value) {
472
- handler(value);
473
- }
474
- });
475
- }
476
- refList.appendChild(ref);
477
452
  }
478
453
  return back;
479
454
  };
480
- this.processDateParts = (parent, dateParts) => {
481
- const [[year, month, day]] = dateParts;
482
- if (year) {
483
- this.appendElement(parent, 'year', String(year));
484
- }
485
- if (month) {
486
- this.appendElement(parent, 'month', String(month));
487
- }
488
- if (day) {
489
- this.appendElement(parent, 'day', String(day));
490
- }
491
- };
492
- this.processPageString = (parent, page) => {
493
- const numPattern = /^\d+$/;
494
- const rangePattern = /^(\d+)-(\d+)$/;
495
- if (numPattern.test(page)) {
496
- this.appendElement(parent, 'fpage', page);
497
- }
498
- else if (rangePattern.test(page)) {
499
- const [fpage, lpage] = page.split('-');
500
- this.appendElement(parent, 'fpage', fpage);
501
- this.appendElement(parent, 'lpage', lpage);
502
- }
503
- else {
504
- this.appendElement(parent, 'page-range', page);
505
- }
506
- };
507
- this.processDate = (parent, tag, date) => {
508
- const buildISODate = (date) => {
509
- const dateParts = date['date-parts'];
510
- if (dateParts && dateParts.length) {
511
- const [[year, month, day]] = dateParts;
512
- if (year && month && day) {
513
- return new Date(Date.UTC(Number(year), Number(month) - 1, Number(day)));
514
- }
515
- }
516
- };
517
- const isoDate = buildISODate(date);
518
- if (!isoDate) {
519
- return;
520
- }
521
- return this.appendElement(parent, tag, isoDate.toDateString(), {
522
- 'iso-8601-date': isoDate.toISOString(),
523
- });
524
- };
525
- this.processRefPersonGroup = (citation, type, people) => {
526
- if (!(people === null || people === void 0 ? void 0 : people.length)) {
527
- return;
528
- }
529
- const group = this.appendElement(citation, 'person-group', undefined, {
530
- 'person-group-type': type,
531
- });
532
- people.forEach((person) => {
533
- if (person.literal) {
534
- this.appendElement(group, 'collab', person.literal);
535
- return;
536
- }
537
- const name = this.createElement('string-name');
538
- if (person.family) {
539
- this.appendElement(name, 'surname', person.family);
540
- }
541
- if (person.given) {
542
- this.appendElement(name, 'given-names', person.given);
543
- }
544
- if (name.childNodes.length) {
545
- group.appendChild(name);
546
- }
547
- });
548
- };
549
455
  this.createElement = (tag, content, attrs) => {
550
456
  const el = this.document.createElement(tag);
551
457
  if (content) {
@@ -667,35 +573,30 @@ class JATSExporter {
667
573
  const xref = this.createElement('xref');
668
574
  xref.setAttribute('ref-type', 'bibr');
669
575
  xref.setAttribute('rid', normalizeID(rids.join(' ')));
670
- const citationTextContent = this.citationTexts.get(node.attrs.id);
671
- if (!citationTextContent) {
672
- throw new Error(`No citation text found for ${node.attrs.id}`);
576
+ const fragment = this.renderedCitations.get(node.attrs.id);
577
+ if (fragment) {
578
+ xref.innerHTML = fragment;
673
579
  }
674
- xref.textContent = (0, html_1.textFromHTML)(citationTextContent);
675
580
  return xref;
676
581
  },
677
582
  cross_reference: (node) => {
678
- var _a, _b, _c;
583
+ var _a, _b, _c, _d;
679
584
  const cross = node;
680
585
  const rids = cross.attrs.rids;
681
586
  if (!rids.length) {
682
587
  return (_a = cross.attrs.label) !== null && _a !== void 0 ? _a : '';
683
588
  }
684
589
  const rid = rids[0];
685
- const text = cross.attrs.label || ((_b = this.labelTargets.get(rid)) === null || _b === void 0 ? void 0 : _b.label);
686
- const target = (_c = (0, prosemirror_utils_1.findChildrenByAttr)(this.manuscriptNode, (attrs) => attrs.id === rid)[0]) === null || _c === void 0 ? void 0 : _c.node;
590
+ const text = (_b = cross.attrs.label) !== null && _b !== void 0 ? _b : (_c = this.labelTargets.get(rid)) === null || _c === void 0 ? void 0 : _c.label;
591
+ const target = (_d = (0, prosemirror_utils_1.findChildrenByAttr)(this.manuscriptNode, (attrs) => attrs.id === rid)[0]) === null || _d === void 0 ? void 0 : _d.node;
687
592
  if (!target) {
688
- warn('');
689
- return text || '';
593
+ return text !== null && text !== void 0 ? text : '';
690
594
  }
691
595
  const xref = this.createElement('xref');
692
596
  const type = chooseRefType(target.type);
693
597
  if (type) {
694
598
  xref.setAttribute('ref-type', type);
695
599
  }
696
- else {
697
- warn(`Unset ref-type for schema type ${target.type.name}`);
698
- }
699
600
  xref.setAttribute('rid', normalizeID(rids.join(' ')));
700
601
  xref.textContent = text !== null && text !== void 0 ? text : '';
701
602
  return xref;
@@ -1085,7 +986,6 @@ class JATSExporter {
1085
986
  this.validateContributor(contributor);
1086
987
  }
1087
988
  catch (error) {
1088
- warn(error.message);
1089
989
  return;
1090
990
  }
1091
991
  const contrib = this.createElement('contrib');
@@ -1135,6 +1035,20 @@ class JATSExporter {
1135
1035
  contrib.appendChild(xref);
1136
1036
  });
1137
1037
  }
1038
+ if (contributor.attrs.CRediTRoles) {
1039
+ contributor.attrs.CRediTRoles.forEach((cr) => {
1040
+ const role = this.createElement('role');
1041
+ const creditUrl = credit_roles_1.CRediTRoleUrls.get(cr.vocabTerm);
1042
+ if (creditUrl) {
1043
+ role.setAttribute('vocab-identifier', 'http://credit.niso.org/');
1044
+ role.setAttribute('vocab', 'CRediT');
1045
+ role.setAttribute('vocab-term', cr.vocabTerm);
1046
+ role.setAttribute('vocab-term-identifier', creditUrl);
1047
+ role.innerHTML = cr.vocabTerm;
1048
+ }
1049
+ contrib.appendChild(role);
1050
+ });
1051
+ }
1138
1052
  contribGroup.appendChild(contrib);
1139
1053
  });
1140
1054
  const affiliationRIDs = [];
@@ -1348,10 +1262,6 @@ class JATSExporter {
1348
1262
  if (!container) {
1349
1263
  return;
1350
1264
  }
1351
- const isContainerEmpty = container.children.length === 0;
1352
- if (!isContainerEmpty) {
1353
- warn('Backmatter section is not empty.');
1354
- }
1355
1265
  body.removeChild(container);
1356
1266
  };
1357
1267
  this.moveAwards = (front, body) => {
@@ -1497,27 +1407,6 @@ class JATSExporter {
1497
1407
  return name;
1498
1408
  };
1499
1409
  }
1500
- generateCitations() {
1501
- const nodes = [];
1502
- this.manuscriptNode.descendants((node) => {
1503
- if ((0, schema_1.isCitationNode)(node)) {
1504
- nodes.push(node);
1505
- }
1506
- });
1507
- return (0, exports.buildCitations)(nodes);
1508
- }
1509
- generateCitationTexts(csl, manuscriptID) {
1510
- this.citationTexts = new Map();
1511
- this.citationProvider = new library_1.CitationProvider({
1512
- getLibraryItem: this.getLibraryItem(manuscriptID),
1513
- locale: csl.locale,
1514
- citationStyle: csl.style,
1515
- });
1516
- const citations = this.generateCitations();
1517
- this.citationProvider.rebuildState(citations).forEach(([id, , output]) => {
1518
- this.citationTexts.set(id, output);
1519
- });
1520
- }
1521
1410
  getFirstChildOfType(type, node) {
1522
1411
  return this.getChildrenOfType(type, node)[0];
1523
1412
  }