react-cheminfo 0.140.1 → 0.141.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 (195) hide show
  1. package/README.md +14 -8
  2. package/lib/citation/core/citationMarkup.d.ts +14 -0
  3. package/lib/citation/core/citationMarkup.d.ts.map +1 -0
  4. package/lib/citation/core/citationMarkup.js +27 -0
  5. package/lib/citation/core/citationMarkup.js.map +1 -0
  6. package/lib/citation/core/clipboard.d.ts +7 -6
  7. package/lib/citation/core/clipboard.d.ts.map +1 -1
  8. package/lib/citation/core/clipboard.js +19 -14
  9. package/lib/citation/core/clipboard.js.map +1 -1
  10. package/lib/citation/core/download.d.ts +4 -2
  11. package/lib/citation/core/download.d.ts.map +1 -1
  12. package/lib/citation/core/download.js +5 -3
  13. package/lib/citation/core/download.js.map +1 -1
  14. package/lib/citation/core/formats.d.ts +14 -3
  15. package/lib/citation/core/formats.d.ts.map +1 -1
  16. package/lib/citation/core/formats.js +31 -13
  17. package/lib/citation/core/formats.js.map +1 -1
  18. package/lib/citation/core/index.d.ts +3 -3
  19. package/lib/citation/core/index.d.ts.map +1 -1
  20. package/lib/citation/core/index.js +2 -2
  21. package/lib/citation/core/index.js.map +1 -1
  22. package/lib/citation/core/reference.d.ts +15 -0
  23. package/lib/citation/core/reference.d.ts.map +1 -1
  24. package/lib/citation/core/reference.js +24 -0
  25. package/lib/citation/core/reference.js.map +1 -1
  26. package/lib/citation/core/styles.d.ts +35 -0
  27. package/lib/citation/core/styles.d.ts.map +1 -0
  28. package/lib/citation/core/styles.js +21 -0
  29. package/lib/citation/core/styles.js.map +1 -0
  30. package/lib/citation/core/works.d.ts +2 -3
  31. package/lib/citation/core/works.d.ts.map +1 -1
  32. package/lib/citation/core/works.js +5 -6
  33. package/lib/citation/core/works.js.map +1 -1
  34. package/lib/citation/ui/CitationHtml.d.ts +13 -0
  35. package/lib/citation/ui/CitationHtml.d.ts.map +1 -0
  36. package/lib/citation/ui/CitationHtml.js +42 -0
  37. package/lib/citation/ui/CitationHtml.js.map +1 -0
  38. package/lib/citation/ui/CitationPreview.d.ts +7 -4
  39. package/lib/citation/ui/CitationPreview.d.ts.map +1 -1
  40. package/lib/citation/ui/CitationPreview.js +17 -21
  41. package/lib/citation/ui/CitationPreview.js.map +1 -1
  42. package/lib/citation/ui/CopyFormatEntries.js +1 -1
  43. package/lib/citation/ui/CopyFormatEntries.js.map +1 -1
  44. package/lib/citation/ui/entries.d.ts +1 -1
  45. package/lib/citation/ui/entries.d.ts.map +1 -1
  46. package/lib/citation/ui/entries.js +1 -1
  47. package/lib/citation/ui/entries.js.map +1 -1
  48. package/lib/citation/ui/useCopyFeedback.d.ts +1 -2
  49. package/lib/citation/ui/useCopyFeedback.d.ts.map +1 -1
  50. package/lib/citation/ui/useCopyFeedback.js.map +1 -1
  51. package/lib/credits/core/credits.d.ts +13 -0
  52. package/lib/credits/core/credits.d.ts.map +1 -1
  53. package/lib/credits/core/credits.js +17 -0
  54. package/lib/credits/core/credits.js.map +1 -1
  55. package/lib/csl/core/cslItems.d.ts +97 -0
  56. package/lib/csl/core/cslItems.d.ts.map +1 -0
  57. package/lib/csl/core/cslItems.js +166 -0
  58. package/lib/csl/core/cslItems.js.map +1 -0
  59. package/lib/csl/core/cslStyles.d.ts +30 -0
  60. package/lib/csl/core/cslStyles.d.ts.map +1 -0
  61. package/lib/csl/core/cslStyles.js +48 -0
  62. package/lib/csl/core/cslStyles.js.map +1 -0
  63. package/lib/csl/core/formatCsl.d.ts +35 -0
  64. package/lib/csl/core/formatCsl.d.ts.map +1 -0
  65. package/lib/csl/core/formatCsl.js +100 -0
  66. package/lib/csl/core/formatCsl.js.map +1 -0
  67. package/lib/csl/core/referenceItem.d.ts +14 -0
  68. package/lib/csl/core/referenceItem.d.ts.map +1 -0
  69. package/lib/csl/core/referenceItem.js +60 -0
  70. package/lib/csl/core/referenceItem.js.map +1 -0
  71. package/lib/csl/core/styles/americanChemicalSociety.d.ts +8 -0
  72. package/lib/csl/core/styles/americanChemicalSociety.d.ts.map +1 -0
  73. package/lib/csl/core/styles/americanChemicalSociety.js +311 -0
  74. package/lib/csl/core/styles/americanChemicalSociety.js.map +1 -0
  75. package/lib/csl/core/styles/americanInstituteOfPhysics.d.ts +8 -0
  76. package/lib/csl/core/styles/americanInstituteOfPhysics.d.ts.map +1 -0
  77. package/lib/csl/core/styles/americanInstituteOfPhysics.js +172 -0
  78. package/lib/csl/core/styles/americanInstituteOfPhysics.js.map +1 -0
  79. package/lib/csl/core/styles/americanMathematicalSocietyNumeric.d.ts +8 -0
  80. package/lib/csl/core/styles/americanMathematicalSocietyNumeric.d.ts.map +1 -0
  81. package/lib/csl/core/styles/americanMathematicalSocietyNumeric.js +174 -0
  82. package/lib/csl/core/styles/americanMathematicalSocietyNumeric.js.map +1 -0
  83. package/lib/csl/core/styles/americanPhysicsSociety.d.ts +8 -0
  84. package/lib/csl/core/styles/americanPhysicsSociety.d.ts.map +1 -0
  85. package/lib/csl/core/styles/americanPhysicsSociety.js +227 -0
  86. package/lib/csl/core/styles/americanPhysicsSociety.js.map +1 -0
  87. package/lib/csl/core/styles/angewandteChemie.d.ts +8 -0
  88. package/lib/csl/core/styles/angewandteChemie.d.ts.map +1 -0
  89. package/lib/csl/core/styles/angewandteChemie.js +187 -0
  90. package/lib/csl/core/styles/angewandteChemie.js.map +1 -0
  91. package/lib/csl/core/styles/beilsteinJournalOfOrganicChemistry.d.ts +8 -0
  92. package/lib/csl/core/styles/beilsteinJournalOfOrganicChemistry.d.ts.map +1 -0
  93. package/lib/csl/core/styles/beilsteinJournalOfOrganicChemistry.js +280 -0
  94. package/lib/csl/core/styles/beilsteinJournalOfOrganicChemistry.js.map +1 -0
  95. package/lib/csl/core/styles/elsevierWithTitles.d.ts +8 -0
  96. package/lib/csl/core/styles/elsevierWithTitles.d.ts.map +1 -0
  97. package/lib/csl/core/styles/elsevierWithTitles.js +156 -0
  98. package/lib/csl/core/styles/elsevierWithTitles.js.map +1 -0
  99. package/lib/csl/core/styles/helveticaChimicaActa.d.ts +8 -0
  100. package/lib/csl/core/styles/helveticaChimicaActa.d.ts.map +1 -0
  101. package/lib/csl/core/styles/helveticaChimicaActa.js +189 -0
  102. package/lib/csl/core/styles/helveticaChimicaActa.js.map +1 -0
  103. package/lib/csl/core/styles/ieee.d.ts +8 -0
  104. package/lib/csl/core/styles/ieee.d.ts.map +1 -0
  105. package/lib/csl/core/styles/ieee.js +527 -0
  106. package/lib/csl/core/styles/ieee.js.map +1 -0
  107. package/lib/csl/core/styles/instituteOfPhysicsNumeric.d.ts +8 -0
  108. package/lib/csl/core/styles/instituteOfPhysicsNumeric.d.ts.map +1 -0
  109. package/lib/csl/core/styles/instituteOfPhysicsNumeric.js +135 -0
  110. package/lib/csl/core/styles/instituteOfPhysicsNumeric.js.map +1 -0
  111. package/lib/csl/core/styles/localeEnUs.d.ts +8 -0
  112. package/lib/csl/core/styles/localeEnUs.d.ts.map +1 -0
  113. package/lib/csl/core/styles/localeEnUs.js +872 -0
  114. package/lib/csl/core/styles/localeEnUs.js.map +1 -0
  115. package/lib/csl/core/styles/nature.d.ts +8 -0
  116. package/lib/csl/core/styles/nature.d.ts.map +1 -0
  117. package/lib/csl/core/styles/nature.js +197 -0
  118. package/lib/csl/core/styles/nature.js.map +1 -0
  119. package/lib/csl/core/styles/royalSocietyOfChemistry.d.ts +8 -0
  120. package/lib/csl/core/styles/royalSocietyOfChemistry.d.ts.map +1 -0
  121. package/lib/csl/core/styles/royalSocietyOfChemistry.js +267 -0
  122. package/lib/csl/core/styles/royalSocietyOfChemistry.js.map +1 -0
  123. package/lib/csl/core/styles/springerMathphysBrackets.d.ts +8 -0
  124. package/lib/csl/core/styles/springerMathphysBrackets.d.ts.map +1 -0
  125. package/lib/csl/core/styles/springerMathphysBrackets.js +159 -0
  126. package/lib/csl/core/styles/springerMathphysBrackets.js.map +1 -0
  127. package/lib/csl/core/styles/springerPhysicsBrackets.d.ts +8 -0
  128. package/lib/csl/core/styles/springerPhysicsBrackets.d.ts.map +1 -0
  129. package/lib/csl/core/styles/springerPhysicsBrackets.js +166 -0
  130. package/lib/csl/core/styles/springerPhysicsBrackets.js.map +1 -0
  131. package/lib/csl/core/styles/styleLoaders.d.ts +6 -0
  132. package/lib/csl/core/styles/styleLoaders.d.ts.map +1 -0
  133. package/lib/csl/core/styles/styleLoaders.js +23 -0
  134. package/lib/csl/core/styles/styleLoaders.js.map +1 -0
  135. package/lib/csl/core/styles/synthesis.d.ts +8 -0
  136. package/lib/csl/core/styles/synthesis.d.ts.map +1 -0
  137. package/lib/csl/core/styles/synthesis.js +196 -0
  138. package/lib/csl/core/styles/synthesis.js.map +1 -0
  139. package/lib/csl/core/styles/tetrahedron.d.ts +8 -0
  140. package/lib/csl/core/styles/tetrahedron.d.ts.map +1 -0
  141. package/lib/csl/core/styles/tetrahedron.js +22 -0
  142. package/lib/csl/core/styles/tetrahedron.js.map +1 -0
  143. package/lib/csl.d.ts +17 -0
  144. package/lib/csl.d.ts.map +1 -0
  145. package/lib/csl.js +15 -0
  146. package/lib/csl.js.map +1 -0
  147. package/package.json +3 -1
  148. package/src/citation/core/citationMarkup.ts +28 -0
  149. package/src/citation/core/clipboard.ts +26 -17
  150. package/src/citation/core/download.ts +7 -5
  151. package/src/citation/core/formats.ts +41 -16
  152. package/src/citation/core/index.ts +3 -6
  153. package/src/citation/core/reference.ts +25 -0
  154. package/src/citation/core/styles.ts +34 -0
  155. package/src/citation/core/works.ts +7 -9
  156. package/src/citation/ui/CitationHtml.tsx +42 -0
  157. package/src/citation/ui/CitationPreview.tsx +36 -35
  158. package/src/citation/ui/CopyFormatEntries.tsx +1 -1
  159. package/src/citation/ui/entries.tsx +2 -2
  160. package/src/citation/ui/useCopyFeedback.ts +1 -2
  161. package/src/credits/core/credits.ts +17 -0
  162. package/src/csl/core/citeproc.d.ts +43 -0
  163. package/src/csl/core/cslItems.ts +208 -0
  164. package/src/csl/core/cslStyles.ts +52 -0
  165. package/src/csl/core/formatCsl.ts +135 -0
  166. package/src/csl/core/referenceItem.ts +75 -0
  167. package/src/csl/core/styles/americanChemicalSociety.ts +310 -0
  168. package/src/csl/core/styles/americanInstituteOfPhysics.ts +171 -0
  169. package/src/csl/core/styles/americanMathematicalSocietyNumeric.ts +173 -0
  170. package/src/csl/core/styles/americanPhysicsSociety.ts +226 -0
  171. package/src/csl/core/styles/angewandteChemie.ts +186 -0
  172. package/src/csl/core/styles/beilsteinJournalOfOrganicChemistry.ts +279 -0
  173. package/src/csl/core/styles/elsevierWithTitles.ts +155 -0
  174. package/src/csl/core/styles/helveticaChimicaActa.ts +188 -0
  175. package/src/csl/core/styles/ieee.ts +526 -0
  176. package/src/csl/core/styles/instituteOfPhysicsNumeric.ts +134 -0
  177. package/src/csl/core/styles/localeEnUs.ts +871 -0
  178. package/src/csl/core/styles/nature.ts +196 -0
  179. package/src/csl/core/styles/royalSocietyOfChemistry.ts +266 -0
  180. package/src/csl/core/styles/springerMathphysBrackets.ts +158 -0
  181. package/src/csl/core/styles/springerPhysicsBrackets.ts +165 -0
  182. package/src/csl/core/styles/styleLoaders.ts +38 -0
  183. package/src/csl/core/styles/synthesis.ts +195 -0
  184. package/src/csl/core/styles/tetrahedron.ts +21 -0
  185. package/src/csl.ts +31 -0
  186. package/lib/citation/core/render.d.ts +0 -21
  187. package/lib/citation/core/render.d.ts.map +0 -1
  188. package/lib/citation/core/render.js +0 -74
  189. package/lib/citation/core/render.js.map +0 -1
  190. package/lib/citation/core/segments.d.ts +0 -62
  191. package/lib/citation/core/segments.d.ts.map +0 -1
  192. package/lib/citation/core/segments.js +0 -210
  193. package/lib/citation/core/segments.js.map +0 -1
  194. package/src/citation/core/render.ts +0 -78
  195. package/src/citation/core/segments.ts +0 -254
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The CSL style `tetrahedron`, as the Citation Style Language project publishes it
3
+ * (styles repository, commit 15ea57496883). Its `<rights>`
4
+ * element states its licence.
5
+ * Written by scripts/csl-styles.mjs: change the script, not this file.
6
+ */
7
+ export declare const STYLE = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<style xmlns=\"http://purl.org/net/xbiblio/csl\" version=\"1.0\" default-locale=\"en-US\">\n <!-- Elsevier, generated from \"elsevier\" metadata at https://github.com/citation-style-language/journals -->\n <info>\n <title>Tetrahedron</title>\n <id>https://www.zotero.org/styles/tetrahedron</id>\n <link href=\"https://www.zotero.org/styles/tetrahedron\" rel=\"self\"/>\n <link href=\"https://www.zotero.org/styles/elsevier-with-titles\" rel=\"independent-parent\"/>\n <category citation-format=\"numeric\"/>\n <issn>0040-4020</issn>\n <updated>2017-06-04T12:00:00+00:00</updated>\n <rights license=\"https://creativecommons.org/licenses/by-sa/3.0/\">This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 License</rights>\n </info>\n</style>\n";
8
+ //# sourceMappingURL=tetrahedron.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tetrahedron.d.ts","sourceRoot":"","sources":["../../../../src/csl/core/styles/tetrahedron.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,KAAK,s0BAcjB,CAAC"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The CSL style `tetrahedron`, as the Citation Style Language project publishes it
3
+ * (styles repository, commit 15ea57496883). Its `<rights>`
4
+ * element states its licence.
5
+ * Written by scripts/csl-styles.mjs: change the script, not this file.
6
+ */
7
+ export const STYLE = `<?xml version="1.0" encoding="utf-8"?>
8
+ <style xmlns="http://purl.org/net/xbiblio/csl" version="1.0" default-locale="en-US">
9
+ <!-- Elsevier, generated from "elsevier" metadata at https://github.com/citation-style-language/journals -->
10
+ <info>
11
+ <title>Tetrahedron</title>
12
+ <id>https://www.zotero.org/styles/tetrahedron</id>
13
+ <link href="https://www.zotero.org/styles/tetrahedron" rel="self"/>
14
+ <link href="https://www.zotero.org/styles/elsevier-with-titles" rel="independent-parent"/>
15
+ <category citation-format="numeric"/>
16
+ <issn>0040-4020</issn>
17
+ <updated>2017-06-04T12:00:00+00:00</updated>
18
+ <rights license="https://creativecommons.org/licenses/by-sa/3.0/">This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 License</rights>
19
+ </info>
20
+ </style>
21
+ `;
22
+ //# sourceMappingURL=tetrahedron.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tetrahedron.js","sourceRoot":"","sources":["../../../../src/csl/core/styles/tetrahedron.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG;;;;;;;;;;;;;;CAcpB,CAAC"}
package/lib/csl.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ /**
2
+ * References formatted as the journals print them, by citeproc-js — the
3
+ * processor Zotero runs — in the CSL styles of the journals the family writes
4
+ * for: CSL JSON read from Zotero, Mendeley or doi.org, the family's own
5
+ * references turned into it, and citations and reference lists formatted from
6
+ * it.
7
+ *
8
+ * Its own door because the processor and the styles weigh several hundred
9
+ * kilobytes: they load only when something is formatted.
10
+ */
11
+ export type { CslDate, CslItem, CslName } from './csl/core/cslItems.ts';
12
+ export { itemLabel, itemSearchText, itemVenue, itemYear, readCslItem, readCslItems, readCslText, textVariable, } from './csl/core/cslItems.ts';
13
+ export { CSL_STYLE_IDS, hasCslStyle, loadCslLocale, loadCslStyle, } from './csl/core/cslStyles.ts';
14
+ export type { CslOutput, FormattedCslCitations } from './csl/core/formatCsl.ts';
15
+ export { formatCslCitations, formatCslEntries } from './csl/core/formatCsl.ts';
16
+ export { referenceToCsl } from './csl/core/referenceItem.ts';
17
+ //# sourceMappingURL=csl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"csl.d.ts","sourceRoot":"","sources":["../src/csl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,YAAY,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACxE,OAAO,EACL,SAAS,EACT,cAAc,EACd,SAAS,EACT,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,WAAW,EACX,YAAY,GACb,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,aAAa,EACb,WAAW,EACX,aAAa,EACb,YAAY,GACb,MAAM,yBAAyB,CAAC;AACjC,YAAY,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChF,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC/E,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC"}
package/lib/csl.js ADDED
@@ -0,0 +1,15 @@
1
+ /**
2
+ * References formatted as the journals print them, by citeproc-js — the
3
+ * processor Zotero runs — in the CSL styles of the journals the family writes
4
+ * for: CSL JSON read from Zotero, Mendeley or doi.org, the family's own
5
+ * references turned into it, and citations and reference lists formatted from
6
+ * it.
7
+ *
8
+ * Its own door because the processor and the styles weigh several hundred
9
+ * kilobytes: they load only when something is formatted.
10
+ */
11
+ export { itemLabel, itemSearchText, itemVenue, itemYear, readCslItem, readCslItems, readCslText, textVariable, } from "./csl/core/cslItems.js";
12
+ export { CSL_STYLE_IDS, hasCslStyle, loadCslLocale, loadCslStyle, } from "./csl/core/cslStyles.js";
13
+ export { formatCslCitations, formatCslEntries } from "./csl/core/formatCsl.js";
14
+ export { referenceToCsl } from "./csl/core/referenceItem.js";
15
+ //# sourceMappingURL=csl.js.map
package/lib/csl.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"csl.js","sourceRoot":"","sources":["../src/csl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EACL,SAAS,EACT,cAAc,EACd,SAAS,EACT,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,WAAW,EACX,YAAY,GACb,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,aAAa,EACb,WAAW,EACX,aAAa,EACb,YAAY,GACb,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC/E,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-cheminfo",
3
- "version": "0.140.1",
3
+ "version": "0.141.0",
4
4
  "license": "MIT",
5
5
  "description": "React components, hooks and framework-free helpers shared by the cheminfo sites: site chrome, citations, sharing, routing, pedagogy, charts, and the structure, orbital and 3D molecule viewers",
6
6
  "author": "Luc Patiny",
@@ -22,6 +22,7 @@
22
22
  "./core": "./lib/core.js",
23
23
  "./crystal": "./lib/crystal.js",
24
24
  "./crystal3d": "./lib/crystal3d.js",
25
+ "./csl": "./lib/csl.js",
25
26
  "./demo": "./lib/demo.js",
26
27
  "./drawing": "./lib/drawing.js",
27
28
  "./formula": "./lib/formula.js",
@@ -90,6 +91,7 @@
90
91
  "cheminfo-font": "^1.28.0",
91
92
  "cheminfo-types": "^1.16.0",
92
93
  "cif-to-json": "^2.1.0",
94
+ "citeproc": "^2.4.63",
93
95
  "convert-to-jcamp": "^7.0.3",
94
96
  "countries-and-timezones": "^3.11.0",
95
97
  "crc-32": "^1.2.2",
@@ -0,0 +1,28 @@
1
+ /**
2
+ * A reference formatted by citeproc-js, written for the places it is pasted
3
+ * into: Markdown for a README or an issue, keeping the style's italics and
4
+ * bold.
5
+ */
6
+
7
+ import { unescapeXml } from '../../drawing/render/markup.ts';
8
+
9
+ /**
10
+ * A formatted reference as one line of Markdown: italics and bold kept, a
11
+ * raised or lowered run kept as the HTML Markdown allows, every other tag
12
+ * dropped and its text kept.
13
+ * @param html - What citeproc-js wrote.
14
+ * @returns The Markdown.
15
+ */
16
+ export function markdownOfHtml(html: string): string {
17
+ const marked = html.replaceAll(
18
+ /<(?<closing>\/?)(?<tag>[a-z]+)[^>]*>/gi,
19
+ (_, closing: string, tag: string) => {
20
+ const name = tag.toLowerCase();
21
+ if (name === 'i' || name === 'em') return '*';
22
+ if (name === 'b' || name === 'strong') return '**';
23
+ if (name === 'sup' || name === 'sub') return `<${closing}${name}>`;
24
+ return '';
25
+ },
26
+ );
27
+ return unescapeXml(marked);
28
+ }
@@ -1,48 +1,57 @@
1
+ import { writeClipboardItem } from '../../clipboard/core/clipboardItem.ts';
2
+ import { writeToClipboard } from '../../clipboard/core/writeToClipboard.ts';
3
+
1
4
  import type { CitationFormatId } from './formats.ts';
2
5
  import type { Reference } from './reference.ts';
3
- import type { CitationStyleId } from './segments.ts';
4
6
  import { formatCitations } from './works.ts';
5
7
 
6
8
  /**
7
9
  * Put every reference a site asks for on the clipboard, in one value. HTML goes
8
10
  * on in both flavours, so a paste into Word or Google Docs keeps the emphasis of
9
11
  * the style while a plain text editor still receives readable lines rather than
10
- * the markup.
12
+ * the markup. The write starts with the click and the citations follow while
13
+ * they are formatted, which is what Safari asks of a copy.
11
14
  * @param references - References to copy, in reading order.
12
15
  * @param format - Format to copy them in.
13
- * @param style - Journal style, for the formats that have one.
16
+ * @param style - The CSL style of a format written as a journal writes it.
14
17
  * @returns Resolves once the clipboard holds the citations.
18
+ * @throws {Error} When the clipboard took nothing.
15
19
  */
16
- export function copyCitations(
20
+ export async function copyCitations(
17
21
  references: readonly Reference[],
18
22
  format: CitationFormatId,
19
- style?: CitationStyleId,
23
+ style?: string,
20
24
  ): Promise<void> {
21
25
  const value = formatCitations(references, format, style);
22
- if (format !== 'html' || typeof ClipboardItem === 'undefined') {
23
- return navigator.clipboard.writeText(value);
26
+ const text =
27
+ format === 'html' ? formatCitations(references, 'text', style) : value;
28
+ const representations: Record<string, Promise<Blob>> = {
29
+ 'text/plain': text.then(
30
+ (written) => new Blob([written], { type: 'text/plain' }),
31
+ ),
32
+ };
33
+ if (format === 'html') {
34
+ representations['text/html'] = value.then(
35
+ (written) => new Blob([written], { type: 'text/html' }),
36
+ );
37
+ }
38
+ if (await writeClipboardItem(representations)) return;
39
+ if (!(await writeToClipboard(await text))) {
40
+ throw new Error('The clipboard refused the citation');
24
41
  }
25
- return navigator.clipboard.write([
26
- new ClipboardItem({
27
- 'text/html': new Blob([value], { type: 'text/html' }),
28
- 'text/plain': new Blob([formatCitations(references, 'text', style)], {
29
- type: 'text/plain',
30
- }),
31
- }),
32
- ]);
33
42
  }
34
43
 
35
44
  /**
36
45
  * Put one reference on the clipboard.
37
46
  * @param reference - Reference to copy.
38
47
  * @param format - Format to copy it in.
39
- * @param style - Journal style, for the formats that have one.
48
+ * @param style - The CSL style of a format written as a journal writes it.
40
49
  * @returns Resolves once the clipboard holds the citation.
41
50
  */
42
51
  export function copyCitation(
43
52
  reference: Reference,
44
53
  format: CitationFormatId,
45
- style?: CitationStyleId,
54
+ style?: string,
46
55
  ): Promise<void> {
47
56
  return copyCitations([reference], format, style);
48
57
  }
@@ -12,12 +12,13 @@ import { citationsFilename, formatCitations } from './works.ts';
12
12
  * installed.
13
13
  * @param references - References to save, in reading order.
14
14
  * @param download - File to write, from `CITATION_DOWNLOADS`.
15
+ * @returns Resolves once the file is handed to the browser.
15
16
  */
16
- export function downloadCitations(
17
+ export async function downloadCitations(
17
18
  references: readonly Reference[],
18
19
  download: CitationDownload,
19
- ): void {
20
- const content = formatCitations(references, download.format);
20
+ ): Promise<void> {
21
+ const content = await formatCitations(references, download.format);
21
22
  downloadBlob(
22
23
  new Blob([content], { type: download.mimeType }),
23
24
  citationsFilename(references, download.extension),
@@ -28,10 +29,11 @@ export function downloadCitations(
28
29
  * Save one reference as the file a reference manager imports.
29
30
  * @param reference - Reference to save.
30
31
  * @param download - File to write, from `CITATION_DOWNLOADS`.
32
+ * @returns Resolves once the file is handed to the browser.
31
33
  */
32
34
  export function downloadCitation(
33
35
  reference: Reference,
34
36
  download: CitationDownload,
35
- ): void {
36
- downloadCitations([reference], download);
37
+ ): Promise<void> {
38
+ return downloadCitations([reference], download);
37
39
  }
@@ -1,13 +1,15 @@
1
+ import { formatCslEntries } from '../../csl/core/formatCsl.ts';
2
+ import { referenceToCsl } from '../../csl/core/referenceItem.ts';
3
+
4
+ import { markdownOfHtml } from './citationMarkup.ts';
1
5
  import type {
2
6
  ArticleReference,
3
7
  DatasetReference,
4
8
  Reference,
5
9
  ReferenceAuthor,
6
10
  } from './reference.ts';
7
- import { doiUrl } from './reference.ts';
8
- import { renderHtml, renderMarkdown, renderText } from './render.ts';
9
- import type { CitationStyleId } from './segments.ts';
10
- import { citationSegments, nameFamilyFirst, pageRange } from './segments.ts';
11
+ import { doiUrl, nameFamilyFirst, pageRange } from './reference.ts';
12
+ import type { CitationStyleId } from './styles.ts';
11
13
 
12
14
  /** The formats the reference can be copied in. */
13
15
  export type CitationFormatId =
@@ -41,7 +43,8 @@ export const CITATION_FORMATS = [
41
43
  ] as const satisfies readonly CitationFormat[];
42
44
 
43
45
  /** The style a format that has one is written in unless another is picked. */
44
- export const DEFAULT_CITATION_STYLE: CitationStyleId = 'acs';
46
+ export const DEFAULT_CITATION_STYLE: CitationStyleId =
47
+ 'american-chemical-society';
45
48
 
46
49
  /** One entry of the download menu: a file a reference manager imports. */
47
50
  export interface CitationDownload {
@@ -90,27 +93,49 @@ export function citationFilename(
90
93
  * Render a reference in one of the citation formats.
91
94
  * @param reference - Reference to render.
92
95
  * @param format - Format to render it in.
93
- * @param style - Journal style, for the formats that have one.
96
+ * @param style - The CSL style of a format written as a journal writes it.
94
97
  * @returns The citation, ready to be copied to the clipboard.
95
98
  */
96
- export function formatCitation(
99
+ export async function formatCitation(
97
100
  reference: Reference,
98
101
  format: CitationFormatId,
99
- style: CitationStyleId = DEFAULT_CITATION_STYLE,
100
- ): string {
102
+ style: string = DEFAULT_CITATION_STYLE,
103
+ ): Promise<string> {
104
+ const [written] = await formatEach([reference], format, style);
105
+ return written ?? '';
106
+ }
107
+
108
+ /**
109
+ * Render each reference in one of the citation formats: the written ones —
110
+ * text, HTML, Markdown — by citeproc-js in a CSL style, as Zotero writes them,
111
+ * the others as reference managers import them.
112
+ * @param references - References to render, in reading order.
113
+ * @param format - Format to render them in.
114
+ * @param style - The CSL style of a format written as a journal writes it.
115
+ * @returns One citation per reference, in the same order.
116
+ * @throws {Error} For a format or a style there is not.
117
+ */
118
+ export async function formatEach(
119
+ references: readonly Reference[],
120
+ format: CitationFormatId,
121
+ style: string = DEFAULT_CITATION_STYLE,
122
+ ): Promise<string[]> {
101
123
  switch (format) {
102
124
  case 'text':
103
- return renderText(citationSegments(reference, style));
125
+ return formatCslEntries(references.map(referenceToCsl), style, 'text');
104
126
  case 'html':
105
- return renderHtml(citationSegments(reference, style));
106
- case 'markdown':
107
- return renderMarkdown(citationSegments(reference, style));
127
+ return formatCslEntries(references.map(referenceToCsl), style, 'html');
128
+ case 'markdown': {
129
+ const items = references.map(referenceToCsl);
130
+ const entries = await formatCslEntries(items, style, 'html');
131
+ return entries.map(markdownOfHtml);
132
+ }
108
133
  case 'bibtex':
109
- return formatBibTeX(reference);
134
+ return references.map(formatBibTeX);
110
135
  case 'ris':
111
- return formatRis(reference);
136
+ return references.map(formatRis);
112
137
  case 'doi':
113
- return doiUrl(reference);
138
+ return references.map(doiUrl);
114
139
  default:
115
140
  throw new Error(`unknown citation format: ${String(format)}`);
116
141
  }
@@ -11,6 +11,7 @@ export {
11
11
  DEFAULT_CITATION_STYLE,
12
12
  citationFilename,
13
13
  formatCitation,
14
+ formatEach,
14
15
  } from './formats.ts';
15
16
  export { GFN2_XTB_PAPER, GFN2_XTB_WORK } from './gfn2Paper.ts';
16
17
  export {
@@ -27,12 +28,8 @@ export type {
27
28
  ReferenceAuthor,
28
29
  } from './reference.ts';
29
30
  export { doiUrl, referenceVenue } from './reference.ts';
30
- export type {
31
- CitationSegment,
32
- CitationStyle,
33
- CitationStyleId,
34
- } from './segments.ts';
35
- export { CITATION_STYLES, citationSegments } from './segments.ts';
31
+ export type { CitationStyle, CitationStyleId } from './styles.ts';
32
+ export { CITATION_STYLES } from './styles.ts';
36
33
  export { TEACHING_PAPER, TEACHING_WORK } from './teachingPaper.ts';
37
34
  export type { CitedWork } from './works.ts';
38
35
  export {
@@ -75,3 +75,28 @@ export function referenceVenue(reference: Reference): string {
75
75
  ? reference.repository
76
76
  : reference.journalAbbreviation;
77
77
  }
78
+
79
+ /**
80
+ * The pages of an article, as BibTeX and RIS write them.
81
+ * @param reference - The article.
82
+ * @param dash - What joins the two ends.
83
+ * @returns One number for a journal that paginates by article number, the
84
+ * range otherwise.
85
+ */
86
+ export function pageRange(reference: ArticleReference, dash = '–'): string {
87
+ const { firstPage, lastPage } = reference;
88
+ if (firstPage === lastPage) return firstPage;
89
+ return `${firstPage}${dash}${lastPage}`;
90
+ }
91
+
92
+ /**
93
+ * An author with the family name first, `Vanderveen, J. R.`, or the name of an
94
+ * organisation alone.
95
+ * @param author - The author.
96
+ * @returns The name, as a reference list writes it.
97
+ */
98
+ export function nameFamilyFirst(author: ReferenceAuthor): string {
99
+ return author.given === ''
100
+ ? author.family
101
+ : `${author.family}, ${author.given}`;
102
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * The journal styles a Cite menu copies a reference in: each a CSL style
3
+ * formatted by citeproc-js, as Zotero formats it, named by the CSL id that
4
+ * `react-cheminfo/csl` loads, beside journals that ask for it.
5
+ */
6
+
7
+ /** One entry of the style submenu. */
8
+ export interface CitationStyle {
9
+ /** The CSL style, `american-chemical-society`. */
10
+ id: string;
11
+ /** Name of the style. */
12
+ label: string;
13
+ /** Journals that ask for it, shown on the right of the entry. */
14
+ hint: string;
15
+ }
16
+
17
+ /** Every style offered, in the order the menu lists them. */
18
+ export const CITATION_STYLES = [
19
+ { id: 'american-chemical-society', label: 'ACS', hint: 'JACS, Org. Lett.' },
20
+ { id: 'nature', label: 'Nature', hint: 'Nature, Nat. Chem.' },
21
+ {
22
+ id: 'royal-society-of-chemistry',
23
+ label: 'RSC',
24
+ hint: 'Chem. Sci., Green Chem.',
25
+ },
26
+ {
27
+ id: 'angewandte-chemie',
28
+ label: 'Angewandte',
29
+ hint: 'Angew. Chem., ChemMedChem',
30
+ },
31
+ ] as const satisfies readonly CitationStyle[];
32
+
33
+ /** A style of the menu, by its CSL id. */
34
+ export type CitationStyleId = (typeof CITATION_STYLES)[number]['id'];
@@ -1,7 +1,6 @@
1
1
  import type { CitationFormatId } from './formats.ts';
2
- import { citationFilename, formatCitation } from './formats.ts';
2
+ import { citationFilename, formatEach } from './formats.ts';
3
3
  import type { Reference } from './reference.ts';
4
- import type { CitationStyleId } from './segments.ts';
5
4
 
6
5
  /**
7
6
  * One of the works a site asks to be cited, with the words that say which part
@@ -51,17 +50,16 @@ export function citedReferences(works: readonly CitedWork[]): Reference[] {
51
50
  * written citation takes one reference per line.
52
51
  * @param references - References to render, in reading order.
53
52
  * @param format - Format to render them in.
54
- * @param style - Journal style, for the formats that have one.
53
+ * @param style - The CSL style of a format written as a journal writes it.
55
54
  * @returns The citations, ready to be copied to the clipboard or saved.
56
55
  */
57
- export function formatCitations(
56
+ export async function formatCitations(
58
57
  references: readonly Reference[],
59
58
  format: CitationFormatId,
60
- style?: CitationStyleId,
61
- ): string {
62
- return references
63
- .map((reference) => formatCitation(reference, format, style))
64
- .join(SEPARATORS[format]);
59
+ style?: string,
60
+ ): Promise<string> {
61
+ const written = await formatEach(references, format, style);
62
+ return written.join(SEPARATORS[format]);
65
63
  }
66
64
 
67
65
  /**
@@ -0,0 +1,42 @@
1
+ import type { ReactElement, ReactNode } from 'react';
2
+
3
+ /**
4
+ * A reference as citeproc-js wrote it, drawn with the emphasis of its style:
5
+ * italics, bold, raised and lowered runs. Any other element is dropped and its
6
+ * text kept, so nothing a reference holds reaches the page as markup.
7
+ * @param props - The HTML.
8
+ * @param props.html - What citeproc-js wrote.
9
+ * @returns The reference.
10
+ */
11
+ export function CitationHtml(props: { html: string }): ReactElement {
12
+ const template = document.createElement('template');
13
+ template.innerHTML = props.html;
14
+ return <>{nodesOf(template.content)}</>;
15
+ }
16
+
17
+ function nodesOf(parent: ParentNode): ReactNode[] {
18
+ const nodes: ReactNode[] = [];
19
+ let index = 0;
20
+ for (const child of parent.childNodes) {
21
+ nodes.push(nodeOf(child, index++));
22
+ }
23
+ return nodes;
24
+ }
25
+
26
+ function nodeOf(node: ChildNode, key: number): ReactNode {
27
+ if (node.nodeType === Node.TEXT_NODE) return node.textContent;
28
+ if (!(node instanceof Element)) return null;
29
+ const children = nodesOf(node);
30
+ switch (node.tagName.toLowerCase()) {
31
+ case 'i':
32
+ return <em key={key}>{children}</em>;
33
+ case 'b':
34
+ return <strong key={key}>{children}</strong>;
35
+ case 'sup':
36
+ return <sup key={key}>{children}</sup>;
37
+ case 'sub':
38
+ return <sub key={key}>{children}</sub>;
39
+ default:
40
+ return <span key={key}>{children}</span>;
41
+ }
42
+ }
@@ -1,11 +1,15 @@
1
+ import { Spinner } from '@blueprintjs/core';
1
2
  import type { CSSProperties, ReactElement } from 'react';
3
+ import { useCallback, useMemo } from 'react';
2
4
 
5
+ import { useAsync } from '../../hooks/ui/useAsync.ts';
3
6
  import type { CitationFormatId } from '../core/formats.ts';
7
+ import { formatEach } from '../core/formats.ts';
4
8
  import type { Reference } from '../core/reference.ts';
5
- import type { CitationStyleId } from '../core/segments.ts';
6
- import { citationSegments } from '../core/segments.ts';
7
9
  import { formatCitations } from '../core/works.ts';
8
10
 
11
+ import { CitationHtml } from './CitationHtml.tsx';
12
+
9
13
  // A BibTeX entry and a one-line citation share this box, so the text wraps and
10
14
  // the box never grows past what a tooltip can hold. The height is the last
11
15
  // resort, for a window too short to show an entry whole.
@@ -30,65 +34,62 @@ const RICH_STYLE: CSSProperties = {
30
34
  };
31
35
  // Two references pasted as HTML read as two lines, and preview as two.
32
36
  const RICH_LINE_STYLE: CSSProperties = { marginTop: 6 };
33
- const LINK_STYLE: CSSProperties = { color: '#8abbff' };
34
37
 
35
38
  export interface CitationPreviewProps {
36
39
  /** The work, or the works, whose citation is previewed. */
37
40
  reference: Reference | readonly Reference[];
38
41
  format: CitationFormatId;
39
- /** Journal style, for the formats that have one. */
40
- style?: CitationStyleId;
42
+ /**
43
+ * The CSL style of a format written as a journal writes it.
44
+ * @default 'american-chemical-society'
45
+ */
46
+ style?: string;
41
47
  }
42
48
 
43
49
  /**
44
50
  * What a copy of the reference puts on the clipboard, as it will read once
45
51
  * pasted: the emphasis of the style for HTML, the source itself otherwise. A
46
52
  * site asking for several works previews every one of them, in the order it
47
- * names them.
53
+ * names them. The references are formatted by citeproc-js, loaded the first
54
+ * time one is previewed.
48
55
  * @param props - Reference, format and style to preview.
49
56
  * @returns The body of the preview tooltip.
50
57
  */
51
58
  export function CitationPreview(props: CitationPreviewProps): ReactElement {
52
59
  const { reference, format, style } = props;
53
- const references = Array.isArray(reference) ? reference : [reference];
60
+ const references = useMemo(
61
+ () => (Array.isArray(reference) ? reference : [reference]),
62
+ [reference],
63
+ );
64
+ const task = useCallback(
65
+ (): Promise<string[]> =>
66
+ format === 'html'
67
+ ? formatEach(references, format, style)
68
+ : formatCitations(references, format, style).then((all) => [all]),
69
+ [references, format, style],
70
+ );
71
+ const written = useAsync(task);
54
72
 
55
- if (format === 'html' && style !== undefined) {
73
+ if (written.status !== 'success') {
74
+ return <Spinner className="citation-preview" size={16} />;
75
+ }
76
+ if (format === 'html') {
56
77
  return (
57
78
  <div className="citation-preview" style={RICH_STYLE}>
58
- {references.map((one, line) => (
59
- <div key={one.doi} style={line === 0 ? undefined : RICH_LINE_STYLE}>
60
- {citationSegments(one, style).map((segment, index) => (
61
- // The segments of one citation are a fixed list, never reordered.
62
- // eslint-disable-next-line react/no-array-index-key
63
- <Segment key={index} segment={segment} />
64
- ))}
79
+ {written.data.map((html, line) => (
80
+ <div
81
+ key={references[line]?.doi ?? line}
82
+ style={line === 0 ? undefined : RICH_LINE_STYLE}
83
+ >
84
+ <CitationHtml html={html} />
65
85
  </div>
66
86
  ))}
67
87
  </div>
68
88
  );
69
89
  }
70
-
71
90
  return (
72
91
  <pre className="citation-preview" style={PREVIEW_STYLE}>
73
- {formatCitations(references, format, style)}
92
+ {written.data.join('')}
74
93
  </pre>
75
94
  );
76
95
  }
77
-
78
- function Segment(props: {
79
- segment: ReturnType<typeof citationSegments>[number];
80
- }): ReactElement {
81
- const { segment } = props;
82
- switch (segment.kind) {
83
- case 'italic':
84
- return <em>{segment.text}</em>;
85
- case 'bold':
86
- return <strong>{segment.text}</strong>;
87
- case 'link':
88
- return <span style={LINK_STYLE}>{segment.text}</span>;
89
- case 'text':
90
- return <span>{segment.text}</span>;
91
- default:
92
- return <span />;
93
- }
94
- }
@@ -4,7 +4,7 @@ import type { ReactElement } from 'react';
4
4
  import { useChromeT } from '../../i18n/ui/useT.ts';
5
5
  import { CITATION_FORMATS } from '../core/formats.ts';
6
6
  import type { Reference } from '../core/reference.ts';
7
- import { CITATION_STYLES } from '../core/segments.ts';
7
+ import { CITATION_STYLES } from '../core/styles.ts';
8
8
 
9
9
  import { CopyEntry } from './entries.tsx';
10
10
  import type { CopyFeedback } from './useCopyFeedback.ts';
@@ -7,7 +7,7 @@ import { useActionTooltip } from '../../shared/ui/useActionTooltip.ts';
7
7
  import { downloadCitations } from '../core/download.ts';
8
8
  import type { CitationDownload, CitationFormat } from '../core/formats.ts';
9
9
  import type { Reference } from '../core/reference.ts';
10
- import type { CitationStyle } from '../core/segments.ts';
10
+ import type { CitationStyle } from '../core/styles.ts';
11
11
 
12
12
  import { CitationPreview } from './CitationPreview.tsx';
13
13
 
@@ -108,7 +108,7 @@ export function DownloadEntry(props: DownloadEntryProps): ReactElement {
108
108
  text={t.or(`cite.download.${download.format}`, download.label)}
109
109
  labelElement={download.hint}
110
110
  onClick={() => {
111
- downloadCitations(references, download);
111
+ void downloadCitations(references, download);
112
112
  }}
113
113
  />
114
114
  )}