react-cheminfo 0.70.0 → 0.71.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 (213) hide show
  1. package/README.md +57 -2
  2. package/lib/about/core/providers.d.ts +6 -0
  3. package/lib/about/core/providers.d.ts.map +1 -1
  4. package/lib/about/core/providers.js +7 -0
  5. package/lib/about/core/providers.js.map +1 -1
  6. package/lib/about/ui/AboutProvidedBy.js +34 -0
  7. package/lib/about/ui/AboutProvidedBy.js.map +1 -1
  8. package/lib/download/core/figurePng.d.ts +14 -0
  9. package/lib/download/core/figurePng.d.ts.map +1 -1
  10. package/lib/download/core/figurePng.js +21 -6
  11. package/lib/download/core/figurePng.js.map +1 -1
  12. package/lib/download/core/svgToPng.d.ts.map +1 -1
  13. package/lib/download/core/svgToPng.js +4 -2
  14. package/lib/download/core/svgToPng.js.map +1 -1
  15. package/lib/format/core/relativeTime.d.ts +8 -3
  16. package/lib/format/core/relativeTime.d.ts.map +1 -1
  17. package/lib/format/core/relativeTime.js +19 -7
  18. package/lib/format/core/relativeTime.js.map +1 -1
  19. package/lib/host/core/connectHost.d.ts +25 -34
  20. package/lib/host/core/connectHost.d.ts.map +1 -1
  21. package/lib/host/core/connectHost.js +43 -89
  22. package/lib/host/core/connectHost.js.map +1 -1
  23. package/lib/host/core/hostOutputs.d.ts +58 -0
  24. package/lib/host/core/hostOutputs.d.ts.map +1 -0
  25. package/lib/host/core/hostOutputs.js +151 -0
  26. package/lib/host/core/hostOutputs.js.map +1 -0
  27. package/lib/host/core/index.d.ts +9 -3
  28. package/lib/host/core/index.d.ts.map +1 -1
  29. package/lib/host/core/index.js +4 -1
  30. package/lib/host/core/index.js.map +1 -1
  31. package/lib/host/core/irKinds.d.ts +124 -0
  32. package/lib/host/core/irKinds.d.ts.map +1 -0
  33. package/lib/host/core/irKinds.js +46 -0
  34. package/lib/host/core/irKinds.js.map +1 -0
  35. package/lib/host/core/kinds.d.ts +13 -5
  36. package/lib/host/core/kinds.d.ts.map +1 -1
  37. package/lib/host/core/kinds.js +11 -5
  38. package/lib/host/core/kinds.js.map +1 -1
  39. package/lib/host/core/protocol.d.ts +50 -7
  40. package/lib/host/core/protocol.d.ts.map +1 -1
  41. package/lib/host/core/protocol.js +10 -6
  42. package/lib/host/core/protocol.js.map +1 -1
  43. package/lib/host/core/selectInputs.d.ts +37 -0
  44. package/lib/host/core/selectInputs.d.ts.map +1 -0
  45. package/lib/host/core/selectInputs.js +110 -0
  46. package/lib/host/core/selectInputs.js.map +1 -0
  47. package/lib/host/testing/sciPeaks.d.ts +31 -0
  48. package/lib/host/testing/sciPeaks.d.ts.map +1 -1
  49. package/lib/host/testing/sciPeaks.js +73 -0
  50. package/lib/host/testing/sciPeaks.js.map +1 -1
  51. package/lib/host/testing/standInHost.d.ts +9 -1
  52. package/lib/host/testing/standInHost.d.ts.map +1 -1
  53. package/lib/host/testing/standInHost.js +19 -1
  54. package/lib/host/testing/standInHost.js.map +1 -1
  55. package/lib/host/ui/useHostConnection.d.ts +13 -5
  56. package/lib/host/ui/useHostConnection.d.ts.map +1 -1
  57. package/lib/host/ui/useHostConnection.js +4 -3
  58. package/lib/host/ui/useHostConnection.js.map +1 -1
  59. package/lib/host-testing.d.ts +2 -2
  60. package/lib/host-testing.d.ts.map +1 -1
  61. package/lib/host-testing.js +2 -2
  62. package/lib/host-testing.js.map +1 -1
  63. package/lib/i18n/core/chromeCatalog.d.ts +1 -1
  64. package/lib/i18n/core/chromeCatalog.d.ts.map +1 -1
  65. package/lib/ir/core/handPicking.d.ts +58 -0
  66. package/lib/ir/core/handPicking.d.ts.map +1 -0
  67. package/lib/ir/core/handPicking.js +130 -0
  68. package/lib/ir/core/handPicking.js.map +1 -0
  69. package/lib/ir/core/index.d.ts +3 -0
  70. package/lib/ir/core/index.d.ts.map +1 -1
  71. package/lib/ir/core/index.js +3 -0
  72. package/lib/ir/core/index.js.map +1 -1
  73. package/lib/ir/core/irBandState.d.ts +57 -0
  74. package/lib/ir/core/irBandState.d.ts.map +1 -0
  75. package/lib/ir/core/irBandState.js +119 -0
  76. package/lib/ir/core/irBandState.js.map +1 -0
  77. package/lib/ir/core/irCommands.d.ts +11 -0
  78. package/lib/ir/core/irCommands.d.ts.map +1 -1
  79. package/lib/ir/core/irCommands.js +6 -0
  80. package/lib/ir/core/irCommands.js.map +1 -1
  81. package/lib/ir/core/irPeaks.d.ts +28 -0
  82. package/lib/ir/core/irPeaks.d.ts.map +1 -0
  83. package/lib/ir/core/irPeaks.js +66 -0
  84. package/lib/ir/core/irPeaks.js.map +1 -0
  85. package/lib/ir/core/irReducer.d.ts +8 -0
  86. package/lib/ir/core/irReducer.d.ts.map +1 -1
  87. package/lib/ir/core/irReducer.js +15 -32
  88. package/lib/ir/core/irReducer.js.map +1 -1
  89. package/lib/ir/core/irSpectrum.d.ts +15 -0
  90. package/lib/ir/core/irSpectrum.d.ts.map +1 -1
  91. package/lib/ir/core/irSpectrum.js.map +1 -1
  92. package/lib/ir/core/irState.d.ts +9 -6
  93. package/lib/ir/core/irState.d.ts.map +1 -1
  94. package/lib/ir/core/irState.js +10 -6
  95. package/lib/ir/core/irState.js.map +1 -1
  96. package/lib/ir/core/pickBands.d.ts +14 -0
  97. package/lib/ir/core/pickBands.d.ts.map +1 -1
  98. package/lib/ir/core/pickBands.js +39 -33
  99. package/lib/ir/core/pickBands.js.map +1 -1
  100. package/lib/ir/core/ramanBands.d.ts +9 -1
  101. package/lib/ir/core/ramanBands.d.ts.map +1 -1
  102. package/lib/ir/core/ramanBands.js +2 -2
  103. package/lib/ir/core/ramanBands.js.map +1 -1
  104. package/lib/ir/core/spectrumBands.d.ts +46 -0
  105. package/lib/ir/core/spectrumBands.d.ts.map +1 -0
  106. package/lib/ir/core/spectrumBands.js +98 -0
  107. package/lib/ir/core/spectrumBands.js.map +1 -0
  108. package/lib/ir/ui/BandRow.d.ts +5 -0
  109. package/lib/ir/ui/BandRow.d.ts.map +1 -1
  110. package/lib/ir/ui/BandRow.js +4 -3
  111. package/lib/ir/ui/BandRow.js.map +1 -1
  112. package/lib/ir/ui/BandsPanel.d.ts +5 -0
  113. package/lib/ir/ui/BandsPanel.d.ts.map +1 -1
  114. package/lib/ir/ui/BandsPanel.js +36 -16
  115. package/lib/ir/ui/BandsPanel.js.map +1 -1
  116. package/lib/ir/ui/BandsToolbar.d.ts +9 -0
  117. package/lib/ir/ui/BandsToolbar.d.ts.map +1 -0
  118. package/lib/ir/ui/BandsToolbar.js +61 -0
  119. package/lib/ir/ui/BandsToolbar.js.map +1 -0
  120. package/lib/ir/ui/IrCanvas.d.ts +2 -1
  121. package/lib/ir/ui/IrCanvas.d.ts.map +1 -1
  122. package/lib/ir/ui/IrCanvas.js +19 -5
  123. package/lib/ir/ui/IrCanvas.js.map +1 -1
  124. package/lib/ir/ui/IrChart.d.ts.map +1 -1
  125. package/lib/ir/ui/IrChart.js +8 -1
  126. package/lib/ir/ui/IrChart.js.map +1 -1
  127. package/lib/ir/ui/IrDocumentationDialog.js +1 -1
  128. package/lib/ir/ui/IrDocumentationDialog.js.map +1 -1
  129. package/lib/ir/ui/IrEditor.d.ts +4 -2
  130. package/lib/ir/ui/IrEditor.d.ts.map +1 -1
  131. package/lib/ir/ui/IrEditor.js.map +1 -1
  132. package/lib/ir/ui/IrShell.d.ts.map +1 -1
  133. package/lib/ir/ui/IrShell.js +6 -0
  134. package/lib/ir/ui/IrShell.js.map +1 -1
  135. package/lib/ir/ui/IrStatusBar.d.ts.map +1 -1
  136. package/lib/ir/ui/IrStatusBar.js +1 -1
  137. package/lib/ir/ui/IrStatusBar.js.map +1 -1
  138. package/lib/ir/ui/IrToolbar.d.ts +4 -3
  139. package/lib/ir/ui/IrToolbar.d.ts.map +1 -1
  140. package/lib/ir/ui/IrToolbar.js +5 -4
  141. package/lib/ir/ui/IrToolbar.js.map +1 -1
  142. package/lib/ir/ui/VibrationalEditor.d.ts +2 -1
  143. package/lib/ir/ui/VibrationalEditor.d.ts.map +1 -1
  144. package/lib/ir/ui/VibrationalEditor.js.map +1 -1
  145. package/lib/ir/ui/irActions.d.ts +5 -0
  146. package/lib/ir/ui/irActions.d.ts.map +1 -1
  147. package/lib/ir/ui/irActions.js +6 -0
  148. package/lib/ir/ui/irActions.js.map +1 -1
  149. package/lib/ir/ui/irChartProps.d.ts +4 -1
  150. package/lib/ir/ui/irChartProps.d.ts.map +1 -1
  151. package/lib/ir/ui/useIrEditor.d.ts +5 -11
  152. package/lib/ir/ui/useIrEditor.d.ts.map +1 -1
  153. package/lib/ir/ui/useIrEditor.js +17 -18
  154. package/lib/ir/ui/useIrEditor.js.map +1 -1
  155. package/lib/locales/de.json +63 -0
  156. package/lib/locales/en.json +63 -0
  157. package/lib/locales/es.json +63 -0
  158. package/lib/locales/fr.json +63 -0
  159. package/lib/locales/it.json +63 -0
  160. package/lib/slides/ui/slideSanitizeSchema.d.ts +3 -2
  161. package/lib/slides/ui/slideSanitizeSchema.d.ts.map +1 -1
  162. package/lib/slides/ui/slideSanitizeSchema.js +82 -2
  163. package/lib/slides/ui/slideSanitizeSchema.js.map +1 -1
  164. package/package.json +1 -1
  165. package/src/about/core/providers.ts +7 -0
  166. package/src/about/ui/AboutProvidedBy.tsx +49 -0
  167. package/src/download/core/figurePng.ts +21 -8
  168. package/src/download/core/svgToPng.ts +3 -4
  169. package/src/format/core/relativeTime.ts +29 -7
  170. package/src/host/core/connectHost.ts +77 -120
  171. package/src/host/core/hostOutputs.ts +197 -0
  172. package/src/host/core/index.ts +13 -7
  173. package/src/host/core/irKinds.ts +92 -0
  174. package/src/host/core/kinds.ts +16 -6
  175. package/src/host/core/protocol.ts +50 -8
  176. package/src/host/core/selectInputs.ts +145 -0
  177. package/src/host/testing/sciPeaks.ts +140 -0
  178. package/src/host/testing/standInHost.ts +30 -5
  179. package/src/host/ui/useHostConnection.ts +17 -8
  180. package/src/host-testing.ts +4 -0
  181. package/src/ir/core/handPicking.ts +154 -0
  182. package/src/ir/core/index.ts +14 -0
  183. package/src/ir/core/irBandState.ts +155 -0
  184. package/src/ir/core/irCommands.ts +7 -0
  185. package/src/ir/core/irPeaks.ts +79 -0
  186. package/src/ir/core/irReducer.ts +27 -34
  187. package/src/ir/core/irSpectrum.ts +16 -0
  188. package/src/ir/core/irState.ts +15 -8
  189. package/src/ir/core/pickBands.ts +46 -39
  190. package/src/ir/core/ramanBands.ts +2 -2
  191. package/src/ir/core/spectrumBands.ts +113 -0
  192. package/src/ir/ui/BandRow.tsx +20 -2
  193. package/src/ir/ui/BandsPanel.tsx +46 -88
  194. package/src/ir/ui/BandsToolbar.tsx +152 -0
  195. package/src/ir/ui/IrCanvas.tsx +22 -11
  196. package/src/ir/ui/IrChart.tsx +10 -1
  197. package/src/ir/ui/IrDocumentationDialog.tsx +7 -0
  198. package/src/ir/ui/IrEditor.tsx +4 -2
  199. package/src/ir/ui/IrShell.tsx +5 -0
  200. package/src/ir/ui/IrStatusBar.tsx +4 -1
  201. package/src/ir/ui/IrToolbar.tsx +14 -5
  202. package/src/ir/ui/VibrationalEditor.tsx +2 -1
  203. package/src/ir/ui/irActions.ts +11 -0
  204. package/src/ir/ui/irChartProps.ts +4 -1
  205. package/src/ir/ui/useIrEditor.ts +21 -21
  206. package/src/locales/de.json +63 -0
  207. package/src/locales/en.json +63 -0
  208. package/src/locales/es.json +63 -0
  209. package/src/locales/fr.json +63 -0
  210. package/src/locales/it.json +63 -0
  211. package/src/slides/ui/slideSanitizeSchema.ts +86 -2
  212. package/styles/chrome.css +7 -0
  213. package/styles/slides.css +47 -0
@@ -4,12 +4,14 @@
4
4
  * name, a JSON Schema, and ajv.
5
5
  *
6
6
  * The names are pipeline's (`chem.molfile.2d`, `chem.ocl.id`…), plus
7
- * `chem.smiles`, which pipeline lists among its future schemas. A name with
8
- * children is a category whose schema every child satisfies, so `chem.molfile`
9
- * reads `chem.molfile.2d` and `chem.molfile.3d.h.energy` alike; the fields a
10
- * tool does not read are stripped rather than refused, so a host sending more
11
- * than it needs to is never turned away.
7
+ * `chem.smiles`, which pipeline lists among its future schemas, and the two
8
+ * infrared kinds of `./irKinds.ts`. A name with children is a category whose
9
+ * schema every child satisfies, so `chem.molfile` reads `chem.molfile.2d` and
10
+ * `chem.molfile.3d.h.energy` alike; the fields a tool does not read are
11
+ * stripped rather than refused, so a host sending more than it needs to is
12
+ * never turned away.
12
13
  */
14
+ import type { IrJdxValue, IrPeaksValue } from './irKinds.ts';
13
15
  /** A molfile, V2000 or V3000. */
14
16
  export interface MolfileValue {
15
17
  molfile: string;
@@ -33,6 +35,12 @@ export type CheckedValue = {
33
35
  } | {
34
36
  kind: 'chem.smiles';
35
37
  value: SmilesValue;
38
+ } | {
39
+ kind: 'spectra.ir.jdx';
40
+ value: IrJdxValue;
41
+ } | {
42
+ kind: 'spectra.ir.peaks';
43
+ value: IrPeaksValue;
36
44
  };
37
45
  /** The name of a kind a tool can read. */
38
46
  export type KnownKind = CheckedValue['kind'];
@@ -1 +1 @@
1
- {"version":3,"file":"kinds.d.ts","sourceRoot":"","sources":["../../../src/host/core/kinds.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAKH,iCAAiC;AACjC,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,oDAAoD;AACpD,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,gBAAgB;AAChB,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,oEAAoE;AACpE,MAAM,MAAM,YAAY,GACpB;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,KAAK,EAAE,YAAY,CAAA;CAAE,GAC7C;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,KAAK,EAAE,UAAU,CAAA;CAAE,GAC1C;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,KAAK,EAAE,WAAW,CAAA;CAAE,CAAC;AAEhD,0CAA0C;AAC1C,MAAM,MAAM,S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E,IAAI,EAAE,gBAAgB,CAAC;IAAC,KAAK,EAAE,UAAU,CAAA;CAAE,GAC7C;IAAE,IAAI,EAAE,kBAAkB,CAAC;IAAC,KAAK,EAAE,YAAY,CAAA;CAAE,CAAC;AAEtD,0CAA0C;AAC1C,MAAM,MAAM,SAAS,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;AAK7C,kCAAkC;AAClC,MAAM,MAAM,YAAY,GACtB;IAAE,KAAK,EAAE,IAAI,CAAC;IAAC,OAAO,EAAE,YAAY,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAE9E;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAMtE;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,SAAS,CAE3D;AAED;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,GAAG,YAAY,CAWxE"}
@@ -4,13 +4,15 @@
4
4
  * name, a JSON Schema, and ajv.
5
5
  *
6
6
  * The names are pipeline's (`chem.molfile.2d`, `chem.ocl.id`…), plus
7
- * `chem.smiles`, which pipeline lists among its future schemas. A name with
8
- * children is a category whose schema every child satisfies, so `chem.molfile`
9
- * reads `chem.molfile.2d` and `chem.molfile.3d.h.energy` alike; the fields a
10
- * tool does not read are stripped rather than refused, so a host sending more
11
- * than it needs to is never turned away.
7
+ * `chem.smiles`, which pipeline lists among its future schemas, and the two
8
+ * infrared kinds of `./irKinds.ts`. A name with children is a category whose
9
+ * schema every child satisfies, so `chem.molfile` reads `chem.molfile.2d` and
10
+ * `chem.molfile.3d.h.energy` alike; the fields a tool does not read are
11
+ * stripped rather than refused, so a host sending more than it needs to is
12
+ * never turned away.
12
13
  */
13
14
  import { Ajv } from 'ajv';
15
+ import { IR_JDX_SCHEMA, IR_PEAKS_SCHEMA } from "./irKinds.js";
14
16
  /**
15
17
  * Whether a kind falls under another: the same name, or a name under it on a
16
18
  * segment boundary. A list (`…[]`) never stands for one value, nor one value
@@ -84,5 +86,9 @@ const VALIDATORS = {
84
86
  'chem.molfile': ajv.compile(MOLFILE_SCHEMA),
85
87
  'chem.ocl.id': ajv.compile(OCL_ID_SCHEMA),
86
88
  'chem.smiles': ajv.compile(SMILES_SCHEMA),
89
+ // Written as plain schemas rather than `JSONSchemaType`, which would demand
90
+ // `nullable` on every optional field and so let a `null` band through.
91
+ 'spectra.ir.jdx': ajv.compile(IR_JDX_SCHEMA),
92
+ 'spectra.ir.peaks': ajv.compile(IR_PEAKS_SCHEMA),
87
93
  };
88
94
  //# sourceMappingURL=kinds.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"kinds.js","sourceRoot":"","sources":["../../../src/host/core/kinds.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAkC1B;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,QAAgB,EAAE,OAAe;IAC3D,MAAM,IAAI,GAAG,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACrC,IAAI,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IAClD,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;IACrD,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IACnD,OAAO,IAAI,KAAK,IAAI,IAAI,IAAI,CAAC,UAAU,CAAC,GA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AE,aAAa,CAAC;IACnC,oBAAoB,EAAE,KAAK;CAC5B,CAAC;AAEF,MAAM,aAAa,GAAgC;IACjD,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;IAC1C,QAAQ,EAAE,CAAC,QAAQ,CAAC;IACpB,oBAAoB,EAAE,KAAK;CAC5B,CAAC;AAEF,6EAA6E;AAC7E,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,EAAE,gBAAgB,EAAE,IAAI,EAAE,CAAC,CAAC;AAEhD,MAAM,UAAU,GAAuD;IACrE,cAAc,EAAE,GAAG,CAAC,OAAO,CAAC,cAAc,CAAC;IAC3C,aAAa,EAAE,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC;IACzC,aAAa,EAAE,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC;IACzC,4EAA4E;IAC5E,uEAAuE;IACvE,gBAAgB,EAAE,GAAG,CAAC,OAAO,CAAa,aAAa,CAAC;IACxD,kBAAkB,EAAE,GAAG,CAAC,OAAO,CAAe,eAAe,CAAC;CAC/D,CAAC"}
@@ -4,9 +4,10 @@
4
4
  *
5
5
  * Two messages travel between the windows — `hello`, from the tool, and
6
6
  * `connect`, the host's answer carrying a private `MessagePort` — and everything
7
- * else goes through that port: the host's requests (`load`, `get`) and the
8
- * tool's `result` for each. This module only spells the messages, and reads
9
- * what arrives as the untrusted input it is.
7
+ * else goes through that port: the host's requests (`load`, `get`), the tool's
8
+ * `result` for each, and the `output` the tool sends when a value the host
9
+ * takes back changes. This module only spells the messages, and reads what
10
+ * arrives as the untrusted input it is.
10
11
  */
11
12
  /** The version a tool speaks; a `connect` naming another is ignored. */
12
13
  export declare const PROTOCOL_VERSION = 1;
@@ -45,8 +46,23 @@ export interface ToolInput {
45
46
  key: string;
46
47
  /** Kinds in order of preference; a category accepts every kind under it. */
47
48
  kinds: readonly string[];
49
+ /**
50
+ * Whether it takes every item of its kinds, in the host's order, rather than
51
+ * the one it prefers — every spectrum of a sample.
52
+ * @default false
53
+ */
54
+ many?: boolean;
55
+ /**
56
+ * Whether a request may leave it without an item. A request is still
57
+ * refused when no input at all gets one.
58
+ * @default false
59
+ */
60
+ optional?: boolean;
48
61
  }
49
- /** One value the tool can hand back. */
62
+ /**
63
+ * One value the tool can hand back: answered to `get`, and sent as `output`
64
+ * whenever it changes, when the host accepted it.
65
+ */
50
66
  export interface ToolOutput {
51
67
  key: string;
52
68
  kind: string;
@@ -75,6 +91,13 @@ export interface LoadRequest {
75
91
  /** What the data belongs to; the same document twice is applied once. */
76
92
  document: string;
77
93
  items: HostItem[];
94
+ /**
95
+ * The outputs the host takes back for this document, by key or by kind — a
96
+ * kind taking every kind under it: the tool sends an `output` whenever one
97
+ * of their values changes.
98
+ * @default undefined — nothing is sent unasked
99
+ */
100
+ accept?: string[];
78
101
  }
79
102
  /** `get`: the current value of some outputs. */
80
103
  export interface GetRequest {
@@ -102,25 +125,45 @@ export interface UsedItem {
102
125
  key: string;
103
126
  kind: string;
104
127
  }
105
- /** The answer to one request, carrying its `id`. */
128
+ /**
129
+ * The answer to one request, carrying its `id`: which items a `load` used, or
130
+ * the values a `get` asked for.
131
+ */
106
132
  export type ResultMessage = {
107
133
  type: 'result';
108
134
  id: string;
109
135
  ok: true;
110
136
  used: UsedItem[];
137
+ } | {
138
+ type: 'result';
139
+ id: string;
140
+ ok: true;
141
+ items: HostItem[];
111
142
  } | {
112
143
  type: 'result';
113
144
  id: string;
114
145
  ok: false;
115
146
  error: HostError;
116
147
  };
148
+ /**
149
+ * Sent by the tool, unasked, when values the host accepted have changed — the
150
+ * user picked a band. It carries only the items that changed: one missing is
151
+ * unchanged, never deleted.
152
+ */
153
+ export interface OutputMessage {
154
+ type: 'output';
155
+ /** The document the values belong to, as the host's `load` named it. */
156
+ document: string;
157
+ /** Each with its `key`, and the `id` of the item it was made from. */
158
+ items: HostItem[];
159
+ }
117
160
  /**
118
161
  * Read a message that arrived through the port.
119
162
  *
120
163
  * Anything that is not a well-formed `load` or `get` is `null`, and goes
121
164
  * unanswered: an unknown request is a newer host talking, not an error. An item
122
- * without a string `kind` is dropped, and a label is cut to
123
- * {@link MAX_LABEL_LENGTH}.
165
+ * without a string `kind` is dropped, a label is cut to
166
+ * {@link MAX_LABEL_LENGTH}, and a `load` without `accept` takes nothing back.
124
167
  * @param data - What the port delivered.
125
168
  * @returns The request, or `null`.
126
169
  */
@@ -1 +1 @@
1
- {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../../src/host/core/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,wEAAwE;AACxE,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAElC,6EAA6E;AAC7E,eAAO,MAAM,UAAU,mBAAmB,CAAC;AAE3C,6EAA6E;AAC7E,eAAO,MAAM,YAAY,qBAAqB,CAAC;AAE/C,kEAAkE;AAClE,eAAO,MAAM,SAAS,KAAK,CAAC;AAE5B,mEAAmE;AACnE,eAAO,MAAM,gBAAgB,KAAK,CAAC;AAEnC,mDAAmD;AACnD,MAAM,WAAW,QAAQ;IACvB,6CAA6C;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,yDAAyD;IACzD,KAAK,EAAE,OAAO,CAAC;IACf;;;OAGG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,gCAAgC;AAChC,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,4EAA4E;IAC5E,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;CAC1B;AAED,wCAAwC;AACxC,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;CACd;AAED,2DAA2D;AAC3D,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAA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E,MAAM,EAAE,CAAC;CACnB;AAED,gCAAgC;AAChC,MAAM,WAAW,QAAQ;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;GAGG;AACH,MAAM,MAAM,aAAa,GACrB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,QAAQ,EAAE,CAAA;CAAE,GAC1D;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,QAAQ,EAAE,CAAA;CAAE,GAC3D;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,SAAS,CAAA;CAAE,CAAC;AAEhE;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,QAAQ,CAAC;IACf,wEAAwE;IACxE,QAAQ,EAAE,MAAM,CAAC;IACjB,sEAAsE;IACtE,KAAK,EAAE,QAAQ,EAAE,CAAC;CACnB;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,WAAW,GAAG,IAAI,CAmB9D;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAMhD"}
@@ -4,9 +4,10 @@
4
4
  *
5
5
  * Two messages travel between the windows — `hello`, from the tool, and
6
6
  * `connect`, the host's answer carrying a private `MessagePort` — and everything
7
- * else goes through that port: the host's requests (`load`, `get`) and the
8
- * tool's `result` for each. This module only spells the messages, and reads
9
- * what arrives as the untrusted input it is.
7
+ * else goes through that port: the host's requests (`load`, `get`), the tool's
8
+ * `result` for each, and the `output` the tool sends when a value the host
9
+ * takes back changes. This module only spells the messages, and reads what
10
+ * arrives as the untrusted input it is.
10
11
  */
11
12
  /** The version a tool speaks; a `connect` naming another is ignored. */
12
13
  export const PROTOCOL_VERSION = 1;
@@ -23,8 +24,8 @@ export const MAX_LABEL_LENGTH = 80;
23
24
  *
24
25
  * Anything that is not a well-formed `load` or `get` is `null`, and goes
25
26
  * unanswered: an unknown request is a newer host talking, not an error. An item
26
- * without a string `kind` is dropped, and a label is cut to
27
- * {@link MAX_LABEL_LENGTH}.
27
+ * without a string `kind` is dropped, a label is cut to
28
+ * {@link MAX_LABEL_LENGTH}, and a `load` without `accept` takes nothing back.
28
29
  * @param data - What the port delivered.
29
30
  * @returns The request, or `null`.
30
31
  */
@@ -35,12 +36,15 @@ export function parseRequest(data) {
35
36
  if (typeof data.document !== 'string' || !Array.isArray(data.items)) {
36
37
  return null;
37
38
  }
38
- return {
39
+ const load = {
39
40
  type: 'load',
40
41
  id: data.id,
41
42
  document: data.document,
42
43
  items: readItems(data.items),
43
44
  };
45
+ if (Array.isArray(data.accept))
46
+ load.accept = readStrings(data.accept);
47
+ return load;
44
48
  }
45
49
  if (data.type === 'get') {
46
50
  return { type: 'get', id: data.id, keys: readStrings(data.keys) };
@@ -1 +1 @@
1
- {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../../src/host/core/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,wEAAwE;AACxE,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAElC,6EAA6E;AAC7E,MAAM,CAAC,MAAM,UAAU,GAAG,gBAAgB,CAAC;AAE3C,6EAA6E;AAC7E,MAAM,CAAC,MAAM,YAAY,GAAG,kBAAkB,CAAC;AAE/C,kEAAkE;AAClE,MAAM,CAAC,MAAM,SAAS,GAAG,EAAE,CAAC;AAE5B,mEAAmE;AACnE,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAsGnC;;;;;;;;;GASG;AACH,MAAM,UAAU,YAAY,CAAC,IAAa;IACxC,IAAI,CAA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;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,WAAW,CAAC,KAAc;IACjC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IACrC,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE,CAAC;QAC1B,IAAI,OAAO,KAAK,KAAK,QAAQ;YAAE,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACrD,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Which items of a request each input of a tool takes, and the sentence a
3
+ * host is answered with when the request loads nothing.
4
+ */
5
+ import type { CheckedValue } from './kinds.ts';
6
+ import type { HostError, HostItem, ToolInterface } from './protocol.ts';
7
+ /** The item an input took, and its value as the input's kind reads it. */
8
+ export interface LoadedInput {
9
+ key: string;
10
+ item: HostItem;
11
+ checked: CheckedValue;
12
+ }
13
+ /** What choosing the items of a request gave. */
14
+ export type InputSelection = {
15
+ ok: true;
16
+ inputs: LoadedInput[];
17
+ } | {
18
+ ok: false;
19
+ error: HostError;
20
+ };
21
+ /**
22
+ * Give each input of the tool the items of a request it takes.
23
+ *
24
+ * Each input tries its kinds in its own order of preference, and takes the
25
+ * first item that falls under one and passes that kind's schema: the tool
26
+ * knows which notation serves it best, whatever order the host listed them in.
27
+ * An input taking `many` takes every such item instead, in the host's order.
28
+ * An item naming another input's `key` is left to that input.
29
+ *
30
+ * A required input left without an item refuses the request. An optional one
31
+ * is passed over, unless no input got an item at all.
32
+ * @param tool - What the tool takes.
33
+ * @param items - What the host sent.
34
+ * @returns The items the inputs took, or why the request loads nothing.
35
+ */
36
+ export declare function selectInputs(tool: ToolInterface, items: readonly HostItem[]): InputSelection;
37
+ //# sourceMappingURL=selectInputs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selectInputs.d.ts","sourceRoot":"","sources":["../../../src/host/core/selectInputs.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAa,MAAM,YAAY,CAAC;AAE1D,OAAO,KAAK,EACV,SAAS,EACT,QAAQ,EAER,aAAa,EACd,MAAM,eAAe,CAAC;AAEvB,0EAA0E;AAC1E,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,QAAQ,CAAC;IACf,OAAO,EAAE,YAAY,CAAC;CACvB;AAED,iDAAiD;AACjD,MAAM,MAAM,cAAc,GACxB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,WAAW,EAAE,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,SAAS,CAAA;CAAE,CAAC;AAExE;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,aAAa,EACnB,KAAK,EAAE,SAAS,QAAQ,EAAE,GACzB,cAAc,CAoBhB"}
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Which items of a request each input of a tool takes, and the sentence a
3
+ * host is answered with when the request loads nothing.
4
+ */
5
+ import { checkValue, isKnownKind, kindAccepts } from "./kinds.js";
6
+ /**
7
+ * Give each input of the tool the items of a request it takes.
8
+ *
9
+ * Each input tries its kinds in its own order of preference, and takes the
10
+ * first item that falls under one and passes that kind's schema: the tool
11
+ * knows which notation serves it best, whatever order the host listed them in.
12
+ * An input taking `many` takes every such item instead, in the host's order.
13
+ * An item naming another input's `key` is left to that input.
14
+ *
15
+ * A required input left without an item refuses the request. An optional one
16
+ * is passed over, unless no input got an item at all.
17
+ * @param tool - What the tool takes.
18
+ * @param items - What the host sent.
19
+ * @returns The items the inputs took, or why the request loads nothing.
20
+ */
21
+ export function selectInputs(tool, items) {
22
+ const inputs = [];
23
+ const passedOver = [];
24
+ for (const input of tool.inputs) {
25
+ const errors = [];
26
+ const taken = input.many
27
+ ? selectEvery(input, items, errors)
28
+ : selectFirst(input, items, errors);
29
+ if (taken.length > 0) {
30
+ inputs.push(...taken);
31
+ }
32
+ else if (input.optional) {
33
+ passedOver.push(...errors);
34
+ }
35
+ else {
36
+ return { ok: false, error: refusal(tool, [input], errors) };
37
+ }
38
+ }
39
+ if (inputs.length > 0 || tool.inputs.length === 0) {
40
+ return { ok: true, inputs };
41
+ }
42
+ return { ok: false, error: refusal(tool, tool.inputs, passedOver) };
43
+ }
44
+ function selectFirst(input, items, errors) {
45
+ for (const accepted of input.kinds) {
46
+ if (!isKnownKind(accepted))
47
+ continue;
48
+ for (const item of items) {
49
+ if (!isFor(input, accepted, item))
50
+ continue;
51
+ const loaded = checkItem(input.key, accepted, item, errors);
52
+ if (loaded !== null)
53
+ return [loaded];
54
+ }
55
+ }
56
+ return [];
57
+ }
58
+ function selectEvery(input, items, errors) {
59
+ const taken = [];
60
+ for (const item of items) {
61
+ for (const accepted of input.kinds) {
62
+ if (!isKnownKind(accepted) || !isFor(input, accepted, item))
63
+ continue;
64
+ const loaded = checkItem(input.key, accepted, item, errors);
65
+ if (loaded === null)
66
+ continue;
67
+ taken.push(loaded);
68
+ break;
69
+ }
70
+ }
71
+ return taken;
72
+ }
73
+ function isFor(input, accepted, item) {
74
+ if (item.key !== undefined && item.key !== input.key)
75
+ return false;
76
+ return kindAccepts(accepted, item.kind);
77
+ }
78
+ function checkItem(key, accepted, item, errors) {
79
+ const outcome = checkValue(accepted, item.value);
80
+ if (outcome.valid)
81
+ return { key, item, checked: outcome.checked };
82
+ for (const error of outcome.errors)
83
+ errors.push(`${item.kind} ${error}`);
84
+ return null;
85
+ }
86
+ /**
87
+ * Why a request loads nothing: some item had the wrong shape, or no item was
88
+ * of a kind the inputs take.
89
+ * @param tool - What the tool takes.
90
+ * @param inputs - The inputs left without an item.
91
+ * @param errors - What the schemas found.
92
+ * @returns The error the host is answered with.
93
+ */
94
+ function refusal(tool, inputs, errors) {
95
+ if (errors.length > 0) {
96
+ const keys = inputs.map((input) => input.key);
97
+ return {
98
+ code: 'invalid',
99
+ message: `No item for ${LIST.format(keys)} has the shape its kind requires, so ${tool.name} loaded nothing.`,
100
+ errors,
101
+ };
102
+ }
103
+ const kinds = inputs.flatMap((input) => input.kinds);
104
+ return {
105
+ code: 'no-input',
106
+ message: `No item is a ${LIST.format(kinds)}, so ${tool.name} loaded nothing.`,
107
+ };
108
+ }
109
+ const LIST = new Intl.ListFormat('en', { type: 'disjunction' });
110
+ //# sourceMappingURL=selectInputs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selectInputs.js","sourceRoot":"","sources":["../../../src/host/core/selectInputs.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAmBlE;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,YAAY,CAC1B,IAAmB,EACnB,KAA0B;IAE1B,MAAM,MAAM,GAAkB,EAAE,CAAC;IACjC,MAAM,UAAU,GAAa,EAAE,CAAC;IAChC,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;QAChC,MAAM,MAAM,GAAa,EAAE,CAAC;QAC5B,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI;YACtB,CAAC,CAAC,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC;YACnC,CAAC,CAAC,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;QACtC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACrB,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC;QACxB,CAAC;aAAM,IAAI,KAAK,CAAC,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AM,GAAG,CAAC,EAAE,CAAC;QACtB,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC9C,OAAO;YACL,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,eAAe,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,wCAAwC,IAAI,CAAC,IAAI,kBAAkB;YAC5G,MAAM;SACP,CAAC;IACJ,CAAC;IACD,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACrD,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,OAAO,EAAE,gBAAgB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,IAAI,CAAC,IAAI,kBAAkB;KAC/E,CAAC;AACJ,CAAC;AAED,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC,CAAC"}
@@ -8,6 +8,10 @@
8
8
  * The sample is a real one, and so are its quirks: its molfile is V2000 with
9
9
  * every atom at the origin, its title is blank so the label is its first name,
10
10
  * and its formula travels as a kind no structure input reads.
11
+ *
12
+ * Its infrared spectrum is pinned here before the tool tab sends it: the bands
13
+ * are the sample's own, and the message is the one visualizer-helper's `ir`
14
+ * reader has to write.
11
15
  */
12
16
  import type { LoadRequest } from '../core/protocol.ts';
13
17
  /** How SciPeaks' tool tab introduces itself in `connect`. */
@@ -18,4 +22,31 @@ export declare const SCIPEAKS_ETHYLBENZENE_MOLFILE: string;
18
22
  export declare const SCIPEAKS_ETHYLBENZENE_LOAD: LoadRequest & {
19
23
  accept: string[];
20
24
  };
25
+ /** Where SciPeaks keeps that sample's infrared spectrum: its attachment. */
26
+ export declare const SCIPEAKS_ETHYLBENZENE_IR_FILENAME = "spectra/ir/spectra_ir_100-41-4-IR.jdx";
27
+ /**
28
+ * The bands SciPeaks keeps for that spectrum, as stored: out of wavenumber
29
+ * order, a transmittance that is a fraction, and the visualizer's `_highlight`.
30
+ */
31
+ export declare const SCIPEAKS_ETHYLBENZENE_IR_PEAKS: {
32
+ wavenumber: number;
33
+ absorbance: number;
34
+ transmittance: number;
35
+ kind: string;
36
+ _highlight: number;
37
+ }[];
38
+ /**
39
+ * The `load` the tool tab is to send that sample to a site that reads
40
+ * infrared spectra and hands their bands back, once its `ir` reader and its
41
+ * `save` exist: the structure as it is sent today, one `spectra.ir.jdx` item
42
+ * per spectrum — the attachment's text, its name and its bands, under the
43
+ * attachment's name as `id` — and `accept` naming the kind saved back, as
44
+ * the tool tab's `save` names it.
45
+ * @param jdx - The attachment's text, which SciPeaks serves at its `dUrl`.
46
+ * @returns The request, its bands copied so that reading them cannot strip
47
+ * this module's own.
48
+ */
49
+ export declare function sciPeaksEthylbenzeneIrLoad(jdx: string): LoadRequest & {
50
+ accept: string[];
51
+ };
21
52
  //# sourceMappingURL=sciPeaks.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sciPeaks.d.ts","sourceRoot":"","sources":["../../../src/host/testing/sciPeaks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD,6DAA6D;AAC7D,eAAO,MAAM,kBAAkB,aAAa,CAAC;AAE7C,8EAA8E;AAC9E,eAAO,MAAM,6BAA6B,QAuB9B,CAAC;AAEb,0EAA0E;AAC1E,eAAO,MAAM,0BAA0B,EAAE,WAAW,GAAG;IAAE,MAAM,EAAE,MAAM,EAAE,CAAA;CAqBxE,CAAC"}
1
+ {"version":3,"file":"sciPeaks.d.ts","sourceRoot":"","sources":["../../../src/host/testing/sciPeaks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD,6DAA6D;AAC7D,eAAO,MAAM,kBAAkB,aAAa,CAAC;AAE7C,8EAA8E;AAC9E,eAAO,MAAM,6BAA6B,QAuB9B,CAAC;AAEb,0EAA0E;AAC1E,eAAO,MAAM,0BAA0B,EAAE,WAAW,GAAG;IAAE,MAAM,EAAE,MAAM,EAAE,CAAA;CAqBxE,CAAC;AAEF,4EAA4E;AAC5E,eAAO,MAAM,iCAAiC,0CACL,CAAC;AAE1C;;;GAGG;AACH,eAAO,MAAM,8BAA8B;;;;;;GAsE1C,CAAC;AAEF;;;;;;;;;;GAUG;AACH,wBAAgB,0BAA0B,CACxC,GAAG,EAAE,MAAM,GACV,WAAW,GAAG;IAAE,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CAsBpC"}
@@ -8,6 +8,10 @@
8
8
  * The sample is a real one, and so are its quirks: its molfile is V2000 with
9
9
  * every atom at the origin, its title is blank so the label is its first name,
10
10
  * and its formula travels as a kind no structure input reads.
11
+ *
12
+ * Its infrared spectrum is pinned here before the tool tab sends it: the bands
13
+ * are the sample's own, and the message is the one visualizer-helper's `ir`
14
+ * reader has to write.
11
15
  */
12
16
  /** How SciPeaks' tool tab introduces itself in `connect`. */
13
17
  export const SCIPEAKS_HOST_NAME = 'SciPeaks';
@@ -59,4 +63,73 @@ export const SCIPEAKS_ETHYLBENZENE_LOAD = {
59
63
  ],
60
64
  accept: [],
61
65
  };
66
+ /** Where SciPeaks keeps that sample's infrared spectrum: its attachment. */
67
+ export const SCIPEAKS_ETHYLBENZENE_IR_FILENAME = 'spectra/ir/spectra_ir_100-41-4-IR.jdx';
68
+ /**
69
+ * The bands SciPeaks keeps for that spectrum, as stored: out of wavenumber
70
+ * order, a transmittance that is a fraction, and the visualizer's `_highlight`.
71
+ */
72
+ export const SCIPEAKS_ETHYLBENZENE_IR_PEAKS = [
73
+ peak(1613.8583376884494, 0.473660722610156, 0.33599999999999997, 'm', 0.5620600551849647),
74
+ peak(1952.5275809045322, 0.13123804178794973, 0.7392, 'w', 0.5211472441361716),
75
+ peak(2872.4947788943773, 0.4610494379856386, 0.3459, 'm', 0.30496127508514037),
76
+ peak(2887.659073366737, 0.7066374452885544, 0.1965, 'S', 0.6306151483877337),
77
+ peak(2907.878132663217, 0.4962093169428189, 0.319, 'S', 0.7220300834282813),
78
+ peak(2944.9464080400967, 1.0867160982395816, 0.0819, 'S', 0.8391486100817713),
79
+ peak(2978.6448402008964, 1.7958800173440752, 0.016, 'S', 0.6098050482700554),
80
+ peak(3014.028193969736, 0.32975414692587596, 0.468, 'm', 0.39091552830124354),
81
+ peak(3039.302018090336, 1.0969100130080565, 0.08, 'S', 0.502385910408338),
82
+ peak(3076.3702934672156, 0.5831931281770556, 0.2611, 'S', 0.06293920935800923),
83
+ peak(3098.2742743717354, 0.38658105496542694, 0.4106, 'm', 0.4934643842659038),
84
+ peak(3118.493333668215, 0.16557929631846746, 0.6829999999999999, 'w', 0.05290000144269602),
85
+ peak(1875.0211869346824, 0.11935787359571505, 0.7597, 'w', 0.9972320630781272),
86
+ peak(1812.6790874371945, 0.11125903931710739, 0.774, 'w', 0.07102323198933491),
87
+ peak(1753.706831155787, 0.0834934128848443, 0.8251000000000001, 'w', 0.0750629173499594),
88
+ ];
89
+ /**
90
+ * The `load` the tool tab is to send that sample to a site that reads
91
+ * infrared spectra and hands their bands back, once its `ir` reader and its
92
+ * `save` exist: the structure as it is sent today, one `spectra.ir.jdx` item
93
+ * per spectrum — the attachment's text, its name and its bands, under the
94
+ * attachment's name as `id` — and `accept` naming the kind saved back, as
95
+ * the tool tab's `save` names it.
96
+ * @param jdx - The attachment's text, which SciPeaks serves at its `dUrl`.
97
+ * @returns The request, its bands copied so that reading them cannot strip
98
+ * this module's own.
99
+ */
100
+ export function sciPeaksEthylbenzeneIrLoad(jdx) {
101
+ return {
102
+ type: 'load',
103
+ id: 'load-1',
104
+ document: SCIPEAKS_ETHYLBENZENE_LOAD.document,
105
+ items: [
106
+ ...SCIPEAKS_ETHYLBENZENE_LOAD.items,
107
+ {
108
+ kind: 'spectra.ir.jdx',
109
+ id: SCIPEAKS_ETHYLBENZENE_IR_FILENAME,
110
+ label: 'spectra_ir_100-41-4-IR.jdx',
111
+ value: {
112
+ jdx,
113
+ filename: SCIPEAKS_ETHYLBENZENE_IR_FILENAME,
114
+ peaks: SCIPEAKS_ETHYLBENZENE_IR_PEAKS.map((stored) => ({
115
+ ...stored,
116
+ })),
117
+ },
118
+ },
119
+ ],
120
+ accept: ['spectra.ir.peaks'],
121
+ };
122
+ }
123
+ /**
124
+ * One stored band.
125
+ * @param wavenumber - Where it sits, in cm⁻¹.
126
+ * @param absorbance - Its absorbance.
127
+ * @param transmittance - Its transmittance, a fraction.
128
+ * @param kind - Its strength letter.
129
+ * @param highlight - The visualizer's own `_highlight`, stored with it.
130
+ * @returns The band as SciPeaks stores it.
131
+ */
132
+ function peak(wavenumber, absorbance, transmittance, kind, highlight) {
133
+ return { wavenumber, absorbance, transmittance, kind, _highlight: highlight };
134
+ }
62
135
  //# sourceMappingURL=sciPeaks.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sciPeaks.js","sourceRoot":"","sources":["../../../src/host/testing/sciPeaks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,6DAA6D;AAC7D,MAAM,CAAC,MAAM,kBAAkB,GAAG,UAAU,CAAC;AAE7C,8EAA8E;AAC9E,MAAM,CAAC,MAAM,6BAA6B,GAAG;IAC3C,EAAE;IACF,kCAAkC;IAClC,EAAE;IACF,yCAAyC;IACzC,uEAAuE;IACvE,uEAAuE;IACvE,uEAAuE;IACvE,uEAAuE;IACvE,uEAAuE;IACvE,uEAAuE;IACvE,uEAAuE;IACvE,uEAAuE;IACvE,uBAAuB;IACvB,uBAAuB;IACvB,uBAAuB;IACvB,uBAAuB;IACvB,uBAAuB;IACvB,uBAAuB;IACvB,uBAAuB;IACvB,uBAAuB;IACvB,QAAQ;IACR,EAAE;CACH,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEb,0EA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AY,EACZ,SAAiB;IAEjB,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC;AAChF,CAAC"}
@@ -30,7 +30,7 @@ export interface StandInHost {
30
30
  export interface StandInHostLog {
31
31
  /** The tool's `hello`, or `null` before it came. */
32
32
  hello: HelloMessage | null;
33
- /** Every message the tool sent on the port, in order. */
33
+ /** Every message the tool sent on the port, in order: results and outputs. */
34
34
  results: unknown[];
35
35
  }
36
36
  /**
@@ -44,4 +44,12 @@ export declare function startStandInHost(): Promise<StandInHost>;
44
44
  * @returns The log.
45
45
  */
46
46
  export declare function readStandInHostLog(): StandInHostLog;
47
+ /**
48
+ * Send one more request on the port, once the tool has connected — a `get`
49
+ * after the user has worked. Runs in the page, as
50
+ * `page.evaluate(sendStandInHostRequest, request)`.
51
+ * @param request - What to send.
52
+ * @returns Whether there was a port to send it on.
53
+ */
54
+ export declare function sendStandInHostRequest(request: unknown): boolean;
47
55
  //# sourceMappingURL=standInHost.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"standInHost.d.ts","sourceRoot":"","sources":["../../../src/host/testing/standInHost.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAMH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD,+BAA+B;AAC/B,MAAM,WAAW,WAAW;IAC1B,oEAAoE;IACpE,MAAM,EAAE,MAAM,CAAC;IACf;;;;;;OAMG;IACH,OAAO,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,OAAO,EAAE,KAAK,MAAM,CAAC;IACnE,oBAAoB;IACpB,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B;AAED,yEAAyE;AACzE,MAAM,WAAW,cAAc;IAC7B,oDAAoD;IACpD,KAAK,EAAE,YAAY,GAAG,IAAI,CAAC;IAC3B,yDAAyD;IACzD,OAAO,EAAE,OAAO,EAAE,CAAC;CACpB;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,WAAW,CAAC,CAyB7D;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,IAAI,cAAc,CAEnD"}
1
+ {"version":3,"file":"standInHost.d.ts","sourceRoot":"","sources":["../../../src/host/testing/standInHost.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAMH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD,+BAA+B;AAC/B,MAAM,WAAW,WAAW;IAC1B,oEAAoE;IACpE,MAAM,EAAE,MAAM,CAAC;IACf;;;;;;OAMG;IACH,OAAO,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,OAAO,EAAE,KAAK,MAAM,CAAC;IACnE,oBAAoB;IACpB,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B;AAED,yEAAyE;AACzE,MAAM,WAAW,cAAc;IAC7B,oDAAoD;IACpD,KAAK,EAAE,YAAY,GAAG,IAAI,CAAC;IAC3B,8EAA8E;IAC9E,OAAO,EAAE,OAAO,EAAE,CAAC;CACpB;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,WAAW,CAAC,CA8B7D;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,IAAI,cAAc,CAEnD;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAMhE"}
@@ -16,7 +16,9 @@ import { createServer } from 'node:http';
16
16
  * @returns The host; close it when the tests are done.
17
17
  */
18
18
  export async function startStandInHost() {
19
- const server = createServer((_request, response) => {
19
+ // A setup carrying a spectrum is tens of kilobytes of address, past the
20
+ // 16 KiB Node allows a request's head by default.
21
+ const server = createServer({ maxHeaderSize: MAX_SETUP_BYTES }, (_request, response) => {
20
22
  response.writeHead(200, { 'content-type': 'text/html; charset=utf-8' });
21
23
  response.end(HOST_PAGE);
22
24
  });
@@ -49,6 +51,20 @@ export async function startStandInHost() {
49
51
  export function readStandInHostLog() {
50
52
  return globalThis.hostLog;
51
53
  }
54
+ /**
55
+ * Send one more request on the port, once the tool has connected — a `get`
56
+ * after the user has worked. Runs in the page, as
57
+ * `page.evaluate(sendStandInHostRequest, request)`.
58
+ * @param request - What to send.
59
+ * @returns Whether there was a port to send it on.
60
+ */
61
+ export function sendStandInHostRequest(request) {
62
+ const { hostPort } = globalThis;
63
+ hostPort?.postMessage(request);
64
+ return hostPort !== null;
65
+ }
66
+ /** How long the page's address may be, in bytes: Chrome's own limit is 2 MB. */
67
+ const MAX_SETUP_BYTES = 2 * 1024 * 1024;
52
68
  /**
53
69
  * The page. Its setup is its own `?setup=`, so one page serves every test, and
54
70
  * it listens before it frames, so the tool's `hello` cannot be missed.
@@ -63,11 +79,13 @@ const { toolUrl, requests } = JSON.parse(new URLSearchParams(location.search).ge
63
79
  const toolOrigin = new URL(toolUrl).origin;
64
80
  const frame = document.querySelector('#tool');
65
81
  globalThis.hostLog = { hello: null, results: [] };
82
+ globalThis.hostPort = null;
66
83
  globalThis.addEventListener('message', (event) => {
67
84
  if (event.source !== frame.contentWindow || event.origin !== toolOrigin) return;
68
85
  if (event.data?.type !== 'cheminfo:hello') return;
69
86
  globalThis.hostLog.hello = event.data;
70
87
  const channel = new MessageChannel();
88
+ globalThis.hostPort = channel.port1;
71
89
  channel.port1.onmessage = (answer) => {
72
90
  globalThis.hostLog.results.push(answer.data);
73
91
  };