react-cheminfo 0.122.0 → 0.123.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 (88) hide show
  1. package/lib/ecosystem/core/index.d.ts +2 -2
  2. package/lib/ecosystem/core/index.d.ts.map +1 -1
  3. package/lib/ecosystem/core/index.js +1 -1
  4. package/lib/ecosystem/core/index.js.map +1 -1
  5. package/lib/ecosystem/core/lookup.d.ts +6 -0
  6. package/lib/ecosystem/core/lookup.d.ts.map +1 -1
  7. package/lib/ecosystem/core/lookup.js +8 -0
  8. package/lib/ecosystem/core/lookup.js.map +1 -1
  9. package/lib/ecosystem/core/sites.d.ts +1 -1
  10. package/lib/ecosystem/core/sites.d.ts.map +1 -1
  11. package/lib/ecosystem/core/sites.js.map +1 -1
  12. package/lib/ecosystem/core/types.d.ts +23 -1
  13. package/lib/ecosystem/core/types.d.ts.map +1 -1
  14. package/lib/ecosystem/core/unlistedSites.d.ts.map +1 -1
  15. package/lib/ecosystem/core/unlistedSites.js +19 -0
  16. package/lib/ecosystem/core/unlistedSites.js.map +1 -1
  17. package/lib/ecosystem/ui/glyphs.d.ts.map +1 -1
  18. package/lib/ecosystem/ui/glyphs.js +3 -0
  19. package/lib/ecosystem/ui/glyphs.js.map +1 -1
  20. package/lib/host/core/answerGet.js +1 -1
  21. package/lib/host/core/answerGet.js.map +1 -1
  22. package/lib/host/core/datasetKinds.d.ts +246 -0
  23. package/lib/host/core/datasetKinds.d.ts.map +1 -0
  24. package/lib/host/core/datasetKinds.js +97 -0
  25. package/lib/host/core/datasetKinds.js.map +1 -0
  26. package/lib/host/core/hostOutputs.js +1 -1
  27. package/lib/host/core/hostOutputs.js.map +1 -1
  28. package/lib/host/core/index.d.ts +6 -1
  29. package/lib/host/core/index.d.ts.map +1 -1
  30. package/lib/host/core/index.js +4 -1
  31. package/lib/host/core/index.js.map +1 -1
  32. package/lib/host/core/kindAccepts.d.ts +15 -0
  33. package/lib/host/core/kindAccepts.d.ts.map +1 -0
  34. package/lib/host/core/kindAccepts.js +22 -0
  35. package/lib/host/core/kindAccepts.js.map +1 -0
  36. package/lib/host/core/kinds.d.ts +7 -10
  37. package/lib/host/core/kinds.d.ts.map +1 -1
  38. package/lib/host/core/kinds.js +7 -17
  39. package/lib/host/core/kinds.js.map +1 -1
  40. package/lib/host/core/selectInputs.d.ts.map +1 -1
  41. package/lib/host/core/selectInputs.js +2 -1
  42. package/lib/host/core/selectInputs.js.map +1 -1
  43. package/lib/host/core/sendTargets.d.ts +32 -0
  44. package/lib/host/core/sendTargets.d.ts.map +1 -0
  45. package/lib/host/core/sendTargets.js +40 -0
  46. package/lib/host/core/sendTargets.js.map +1 -0
  47. package/lib/host/ui/SendToButton.d.ts +38 -0
  48. package/lib/host/ui/SendToButton.d.ts.map +1 -0
  49. package/lib/host/ui/SendToButton.js +61 -0
  50. package/lib/host/ui/SendToButton.js.map +1 -0
  51. package/lib/host/ui/index.d.ts +2 -0
  52. package/lib/host/ui/index.d.ts.map +1 -1
  53. package/lib/host/ui/index.js +1 -0
  54. package/lib/host/ui/index.js.map +1 -1
  55. package/lib/host/ui/openTool.d.ts +16 -8
  56. package/lib/host/ui/openTool.d.ts.map +1 -1
  57. package/lib/host/ui/openTool.js +36 -11
  58. package/lib/host/ui/openTool.js.map +1 -1
  59. package/lib/i18n/core/chromeCatalog.d.ts +1 -1
  60. package/lib/i18n/core/chromeCatalog.d.ts.map +1 -1
  61. package/lib/locales/de.json +6 -1
  62. package/lib/locales/en.json +6 -1
  63. package/lib/locales/es.json +6 -1
  64. package/lib/locales/fr.json +6 -1
  65. package/lib/locales/it.json +6 -1
  66. package/package.json +1 -1
  67. package/src/ecosystem/core/index.ts +2 -0
  68. package/src/ecosystem/core/lookup.ts +9 -0
  69. package/src/ecosystem/core/sites.ts +1 -0
  70. package/src/ecosystem/core/types.ts +24 -0
  71. package/src/ecosystem/core/unlistedSites.ts +19 -0
  72. package/src/ecosystem/ui/glyphs.tsx +16 -0
  73. package/src/host/core/answerGet.ts +1 -1
  74. package/src/host/core/datasetKinds.ts +202 -0
  75. package/src/host/core/hostOutputs.ts +1 -1
  76. package/src/host/core/index.ts +12 -1
  77. package/src/host/core/kindAccepts.ts +21 -0
  78. package/src/host/core/kinds.ts +14 -18
  79. package/src/host/core/selectInputs.ts +2 -1
  80. package/src/host/core/sendTargets.ts +67 -0
  81. package/src/host/ui/SendToButton.tsx +147 -0
  82. package/src/host/ui/index.ts +2 -0
  83. package/src/host/ui/openTool.ts +57 -16
  84. package/src/locales/de.json +6 -1
  85. package/src/locales/en.json +6 -1
  86. package/src/locales/es.json +6 -1
  87. package/src/locales/fr.json +6 -1
  88. package/src/locales/it.json +6 -1
@@ -127,6 +127,7 @@
127
127
  "site.wikidata.tagline": "Die Chemie der Wikipedia-Infoboxen, nach Struktur durchsuchbar.",
128
128
  "site.mz.tagline": "Massenspektren, danach geordnet, wie sie gemessen wurden.",
129
129
  "site.plot.tagline": "Tabellen und Spektren als Diagramme zeichnen, in Größe und Stil einer Zeitschrift.",
130
+ "site.ml.tagline": "Maschinelles Lernen auf Spektren, im Browser.",
130
131
  "site.uv-vis.tagline": "UV-Vis-Spektren überlagern und jedes λmax ablesen.",
131
132
  "site.xps.tagline": "Röntgenphotoelektronenspektren lesen, anpassen und vorhersagen.",
132
133
  "site.biodraw.tagline": "Zellen und Membranen zeichnen und Proteine darin verankern.",
@@ -1058,5 +1059,9 @@
1058
1059
  "folder.create": "Erstellen",
1059
1060
  "folder.folderTaken": "Hier heißt bereits ein Ordner {name}: Wählen Sie einen anderen Namen.",
1060
1061
  "folder.openFolder": "Den Ordner {folder} öffnen",
1061
- "folder.found": "In {path}"
1062
+ "folder.found": "In {path}",
1063
+ "send.label": "Senden an",
1064
+ "send.heading": "{what} senden an",
1065
+ "send.none": "Von dieser Seite lässt sich noch nichts an ein anderes Werkzeug senden.",
1066
+ "send.blocked": "Der Browser hat den neuen Tab blockiert: Pop-ups für diese Seite erlauben, dann erneut senden."
1062
1067
  }
@@ -127,6 +127,7 @@
127
127
  "site.wikidata.tagline": "The chemistry of Wikipedia’s infoboxes, searchable by structure.",
128
128
  "site.mz.tagline": "Mass spectra, classified by how they were measured.",
129
129
  "site.plot.tagline": "Plot tables and spectra as charts sized and styled for a journal.",
130
+ "site.ml.tagline": "Machine learning on spectra, in the browser.",
130
131
  "site.uv-vis.tagline": "Overlay UV-vis spectra and read off every λmax.",
131
132
  "site.xps.tagline": "Read, fit and predict X-ray photoelectron spectra.",
132
133
  "site.biodraw.tagline": "Draw cells and membranes, and snap proteins into them.",
@@ -1058,5 +1059,9 @@
1058
1059
  "folder.create": "Create",
1059
1060
  "folder.folderTaken": "A folder is already named {name} here: choose another name.",
1060
1061
  "folder.openFolder": "Open the folder {folder}",
1061
- "folder.found": "In {path}"
1062
+ "folder.found": "In {path}",
1063
+ "send.label": "Send to",
1064
+ "send.heading": "Send {what} to",
1065
+ "send.none": "Nothing on this page can be sent to another tool yet.",
1066
+ "send.blocked": "The browser blocked the new tab: allow pop-ups for this site, then send again."
1062
1067
  }
@@ -127,6 +127,7 @@
127
127
  "site.wikidata.tagline": "La química de las fichas de Wikipedia, con búsqueda por estructura.",
128
128
  "site.mz.tagline": "Espectros de masas, clasificados según cómo se midieron.",
129
129
  "site.plot.tagline": "Trazar tablas y espectros como gráficos con el tamaño y el estilo de una revista.",
130
+ "site.ml.tagline": "Aprendizaje automático sobre espectros, en el navegador.",
130
131
  "site.uv-vis.tagline": "Superponer espectros UV-vis y leer cada λmax.",
131
132
  "site.xps.tagline": "Leer, ajustar y predecir espectros de fotoelectrones de rayos X.",
132
133
  "site.biodraw.tagline": "Dibujar células y membranas, y anclar proteínas en ellas.",
@@ -1058,5 +1059,9 @@
1058
1059
  "folder.create": "Crear",
1059
1060
  "folder.folderTaken": "Aquí ya hay una carpeta llamada {name}: elija otro nombre.",
1060
1061
  "folder.openFolder": "Abrir la carpeta {folder}",
1061
- "folder.found": "En {path}"
1062
+ "folder.found": "En {path}",
1063
+ "send.label": "Enviar a",
1064
+ "send.heading": "Enviar {what} a",
1065
+ "send.none": "Nada de esta página puede enviarse todavía a otra herramienta.",
1066
+ "send.blocked": "El navegador bloqueó la nueva pestaña: permita las ventanas emergentes para este sitio y vuelva a enviar."
1062
1067
  }
@@ -127,6 +127,7 @@
127
127
  "site.wikidata.tagline": "La chimie des infobox de Wikipédia, interrogeable par structure.",
128
128
  "site.mz.tagline": "Des spectres de masse, classés selon la façon dont ils ont été mesurés.",
129
129
  "site.plot.tagline": "Tracer des tableaux et des spectres en graphiques aux dimensions et au style d’une revue.",
130
+ "site.ml.tagline": "Apprentissage automatique sur des spectres, dans le navigateur.",
130
131
  "site.uv-vis.tagline": "Superposer des spectres UV-visible et relever chaque λmax.",
131
132
  "site.xps.tagline": "Lire, ajuster et prédire des spectres de photoélectrons X.",
132
133
  "site.biodraw.tagline": "Dessiner cellules et membranes, et y ancrer des protéines.",
@@ -1058,5 +1059,9 @@
1058
1059
  "folder.create": "Créer",
1059
1060
  "folder.folderTaken": "Un dossier s’appelle déjà {name} ici : choisissez un autre nom.",
1060
1061
  "folder.openFolder": "Ouvrir le dossier {folder}",
1061
- "folder.found": "Dans {path}"
1062
+ "folder.found": "Dans {path}",
1063
+ "send.label": "Envoyer vers",
1064
+ "send.heading": "Envoyer {what} vers",
1065
+ "send.none": "Rien sur cette page ne peut encore être envoyé à un autre outil.",
1066
+ "send.blocked": "Le navigateur a bloqué le nouvel onglet : autorisez les fenêtres pour ce site, puis envoyez à nouveau."
1062
1067
  }
@@ -127,6 +127,7 @@
127
127
  "site.wikidata.tagline": "La chimica delle infobox di Wikipedia, ricercabile per struttura.",
128
128
  "site.mz.tagline": "Spettri di massa, classificati in base a come sono stati misurati.",
129
129
  "site.plot.tagline": "Tracciare tabelle e spettri come grafici con le dimensioni e lo stile di una rivista.",
130
+ "site.ml.tagline": "Apprendimento automatico sugli spettri, nel browser.",
130
131
  "site.uv-vis.tagline": "Sovrapporre spettri UV-vis e leggere ogni λmax.",
131
132
  "site.xps.tagline": "Leggere, adattare e prevedere spettri fotoelettronici a raggi X.",
132
133
  "site.biodraw.tagline": "Disegnare cellule e membrane, e ancorarvi delle proteine.",
@@ -1058,5 +1059,9 @@
1058
1059
  "folder.create": "Crea",
1059
1060
  "folder.folderTaken": "Qui c’è già una cartella chiamata {name}: scegli un altro nome.",
1060
1061
  "folder.openFolder": "Apri la cartella {folder}",
1061
- "folder.found": "In {path}"
1062
+ "folder.found": "In {path}",
1063
+ "send.label": "Invia a",
1064
+ "send.heading": "Invia {what} a",
1065
+ "send.none": "Nulla di questa pagina può ancora essere inviato a un altro strumento.",
1066
+ "send.blocked": "Il browser ha bloccato la nuova scheda: consenti i pop-up per questo sito, poi invia di nuovo."
1062
1067
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-cheminfo",
3
- "version": "0.122.0",
3
+ "version": "0.123.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",
@@ -6,6 +6,7 @@ export {
6
6
  findSiteById,
7
7
  groupedSites,
8
8
  isSameSite,
9
+ knownSites,
9
10
  presentSiteId,
10
11
  siteById,
11
12
  siteDisplayName,
@@ -17,6 +18,7 @@ export type {
17
18
  SiteId,
18
19
  SiteMarkColors,
19
20
  SiteName,
21
+ SiteReceiver,
20
22
  SiteRecord,
21
23
  SiteUrlOptions,
22
24
  } from './sites.ts';
@@ -10,6 +10,15 @@ const KNOWN_SITES: readonly EcosystemSite[] = [
10
10
  ...UNLISTED_SITES,
11
11
  ];
12
12
 
13
+ /**
14
+ * Every site of the family, listed in the menu or not yet: what a lookup
15
+ * searches, and what a Send menu picks the sites that take its data from.
16
+ * @returns The listed sites, then the unlisted ones, in declaration order.
17
+ */
18
+ export function knownSites(): readonly EcosystemSite[] {
19
+ return KNOWN_SITES;
20
+ }
21
+
13
22
  /** One topic and the sites written under it. */
14
23
  export interface GroupedSites {
15
24
  /** The topic. */
@@ -8,6 +8,7 @@ export type {
8
8
  SiteId,
9
9
  SiteMarkColors,
10
10
  SiteName,
11
+ SiteReceiver,
11
12
  SiteRecord,
12
13
  } from './types.ts';
13
14
 
@@ -35,6 +35,7 @@ export type SiteId =
35
35
  | 'wikidata'
36
36
  | 'mz'
37
37
  | 'plot'
38
+ | 'ml'
38
39
  | 'vibrations'
39
40
  | 'uv-vis'
40
41
  | 'nmrium'
@@ -124,6 +125,29 @@ export interface EcosystemSite extends SiteRecord {
124
125
  * in the menu and in the footer.
125
126
  */
126
127
  group: SiteGroupId;
128
+ /**
129
+ * What the site takes from another site of the family, which is what a Send
130
+ * menu offers to send it.
131
+ * @default undefined — no site sends it anything
132
+ */
133
+ receives?: readonly SiteReceiver[];
134
+ }
135
+
136
+ /**
137
+ * One way a site takes data from another: the kinds its tool's input accepts,
138
+ * and what it does with them. It mirrors one input the site's own `TOOL`
139
+ * announces in its `hello`, which a sender cannot read before opening it.
140
+ */
141
+ export interface SiteReceiver {
142
+ /** The kinds it accepts, in order of preference, as its input names them. */
143
+ kinds: readonly string[];
144
+ /** What it does with them, in a few words, as the Send menu says it. */
145
+ does: string;
146
+ /**
147
+ * The page it is opened on.
148
+ * @default '/'
149
+ */
150
+ page?: string;
127
151
  }
128
152
 
129
153
  /** The colours a site's mark is drawn in. */
@@ -48,6 +48,25 @@ export const UNLISTED_SITES: readonly EcosystemSite[] = [
48
48
  // blue plate at 16 px.
49
49
  mark: { plate: '#0024fc', accent: '#fbbf24' },
50
50
  },
51
+ {
52
+ id: 'ml',
53
+ name: { lead: 'ml', alt: 'cheminfo', dot: true },
54
+ host: 'ml.cheminfo.org',
55
+ tagline: 'Machine learning on spectra, in the browser.',
56
+ group: 'spectra',
57
+ // A purple plate for the statistics, and the teal of the second half
58
+ // answers it at 5.4:1 on white.
59
+ brand: '#6a3d9a',
60
+ brandAlt: '#00796b',
61
+ // The samples at the foot of the clustering tree take an amber.
62
+ mark: { plate: '#6a3d9a', accent: '#ffb000' },
63
+ receives: [
64
+ {
65
+ kinds: ['data.spectra', 'data.table'],
66
+ does: 'Compare the spectra with PCA, OPLS and clustering',
67
+ },
68
+ ],
69
+ },
51
70
  {
52
71
  id: 'uv-vis',
53
72
  name: { lead: 'uv-', alt: 'vis' },
@@ -589,6 +589,22 @@ export const GLYPHS: Record<SiteId, (alt: string) => ReactNode> = {
589
589
  <circle cx="23" cy="9.6" r="2.6" fill="#ffffff" />
590
590
  </>
591
591
  ),
592
+ // A clustering tree, what the site draws, joining three samples, which
593
+ // take the answering colour.
594
+ ml: (alt) => (
595
+ <>
596
+ <path
597
+ d="M8 22V14H16V22M12 14V7.5H24V22"
598
+ fill="none"
599
+ stroke="#ffffff"
600
+ strokeWidth="2.6"
601
+ strokeLinejoin="round"
602
+ />
603
+ <circle cx="8" cy="24" r="2.7" fill={alt} />
604
+ <circle cx="16" cy="24" r="2.7" fill={alt} />
605
+ <circle cx="24" cy="24" r="2.7" fill={alt} />
606
+ </>
607
+ ),
592
608
  // An infobox: the structure at its top, a ring, and two rows of data under
593
609
  // it. The second row carries the answering colour, the blue of a link. Both
594
610
  // rows and the gap between them fall on whole pixels at 16 px.
@@ -13,7 +13,7 @@ import {
13
13
  import type { FigureStates } from '../../download/core/figureState.ts';
14
14
 
15
15
  import type { HostOutputs } from './hostOutputs.ts';
16
- import { kindAccepts } from './kinds.ts';
16
+ import { kindAccepts } from './kindAccepts.ts';
17
17
  import type {
18
18
  GetRequest,
19
19
  HostItem,
@@ -0,0 +1,202 @@
1
+ /**
2
+ * `data.spectra`: a set of spectra already read, with their metadata, in the
3
+ * exchange format of ml.cheminfo.org — what a site that parsed the files hands
4
+ * to one that does the statistics.
5
+ *
6
+ * The points of an axis may be a plain list or a `Float64Array`. A window or a
7
+ * port hands a typed array over as one block, so a sender never converts its
8
+ * spectra into lists only to send them. Whether every value is finite, and
9
+ * whether `x` and `y` are as long, is the reader's to say: it can tell which
10
+ * spectrum is wrong, which a schema cannot.
11
+ */
12
+
13
+ import type { DoubleArray } from 'cheminfo-types';
14
+
15
+ /** A value of one spectrum's metadata. */
16
+ export type MetaValue = string | number | boolean | null;
17
+
18
+ /** One spectrum of a `data.spectra`. */
19
+ export interface DatasetSpectrumValue {
20
+ /**
21
+ * The sender's reference, unique in the set.
22
+ * @default its position, from 1
23
+ */
24
+ id?: string;
25
+ /**
26
+ * What the receiving site shows.
27
+ * @default the id
28
+ */
29
+ label?: string;
30
+ /** The points; `x` may run either way. */
31
+ data: { x: DoubleArray; y: DoubleArray };
32
+ /**
33
+ * The metadata, one value per column key.
34
+ * @default {}
35
+ */
36
+ meta?: Record<string, MetaValue>;
37
+ /**
38
+ * The colour the sender drew it in.
39
+ * @default undefined
40
+ */
41
+ color?: string;
42
+ }
43
+
44
+ /** One metadata column of a `data.spectra`. */
45
+ export interface DatasetColumnValue {
46
+ /** The key every spectrum's `meta` uses. */
47
+ key: string;
48
+ /**
49
+ * What the column is called on screen.
50
+ * @default the key
51
+ */
52
+ label?: string;
53
+ /**
54
+ * What it holds.
55
+ * @default read from the values
56
+ */
57
+ type?: 'category' | 'number' | 'text';
58
+ /**
59
+ * The units of a numeric column.
60
+ * @default undefined
61
+ */
62
+ units?: string;
63
+ }
64
+
65
+ /** How one axis of the spectra is named. */
66
+ export interface DatasetAxisValue {
67
+ /** What the axis is called, e.g. `Wavenumber`. */
68
+ label: string;
69
+ /**
70
+ * Its units, e.g. `cm⁻¹`.
71
+ * @default undefined
72
+ */
73
+ units?: string;
74
+ /**
75
+ * Whether it is drawn decreasing from left to right.
76
+ * @default false
77
+ */
78
+ reversed?: boolean;
79
+ }
80
+
81
+ /** `data.spectra`: a set of spectra and their metadata. */
82
+ export interface SpectraDatasetValue {
83
+ /** The spectra, at least one. */
84
+ spectra: DatasetSpectrumValue[];
85
+ /**
86
+ * What the set is called.
87
+ * @default the item's label
88
+ */
89
+ title?: string;
90
+ /**
91
+ * One paragraph on what it holds.
92
+ * @default undefined
93
+ */
94
+ description?: string;
95
+ /**
96
+ * The site that made it.
97
+ * @default undefined
98
+ */
99
+ source?: { name?: string; url?: string };
100
+ /**
101
+ * How the axes are named.
102
+ * @default undefined — unnamed
103
+ */
104
+ axes?: { x?: DatasetAxisValue; y?: DatasetAxisValue };
105
+ /**
106
+ * The metadata columns, in the order they are shown.
107
+ * @default read from the spectra's `meta`
108
+ */
109
+ columns?: DatasetColumnValue[];
110
+ /**
111
+ * The column whose values are the classes.
112
+ * @default undefined
113
+ */
114
+ classKey?: string;
115
+ }
116
+
117
+ /** The keyword the schema checks an axis with: a list of numbers, or a `Float64Array`. */
118
+ export const NUMBER_ARRAY_KEYWORD = {
119
+ keyword: 'numberArray',
120
+ schemaType: 'boolean',
121
+ errors: false,
122
+ validate: (expected: boolean, data: unknown) =>
123
+ isNumberArray(data) === expected,
124
+ } as const;
125
+
126
+ const AXIS_SCHEMA = {
127
+ type: 'object',
128
+ properties: {
129
+ label: { type: 'string' },
130
+ units: { type: 'string' },
131
+ reversed: { type: 'boolean' },
132
+ },
133
+ required: ['label'],
134
+ } as const;
135
+
136
+ /**
137
+ * The schema of `data.spectra`. Fields it does not name are kept: the
138
+ * exchange format carries a version and the sender's own metadata.
139
+ */
140
+ export const SPECTRA_DATASET_SCHEMA = {
141
+ type: 'object',
142
+ properties: {
143
+ title: { type: 'string' },
144
+ description: { type: 'string' },
145
+ source: {
146
+ type: 'object',
147
+ properties: { name: { type: 'string' }, url: { type: 'string' } },
148
+ },
149
+ axes: {
150
+ type: 'object',
151
+ properties: { x: AXIS_SCHEMA, y: AXIS_SCHEMA },
152
+ },
153
+ columns: {
154
+ type: 'array',
155
+ items: {
156
+ type: 'object',
157
+ properties: {
158
+ key: { type: 'string' },
159
+ label: { type: 'string' },
160
+ type: { enum: ['category', 'number', 'text'] },
161
+ units: { type: 'string' },
162
+ },
163
+ required: ['key'],
164
+ },
165
+ },
166
+ classKey: { type: 'string' },
167
+ spectra: {
168
+ type: 'array',
169
+ minItems: 1,
170
+ items: {
171
+ type: 'object',
172
+ properties: {
173
+ id: { type: 'string' },
174
+ label: { type: 'string' },
175
+ data: {
176
+ type: 'object',
177
+ properties: {
178
+ x: { numberArray: true },
179
+ y: { numberArray: true },
180
+ },
181
+ required: ['x', 'y'],
182
+ },
183
+ // A value of another type is the reader's to leave out with a
184
+ // warning, rather than a reason to refuse the whole set.
185
+ meta: { type: 'object' },
186
+ color: { type: 'string' },
187
+ },
188
+ required: ['data'],
189
+ },
190
+ },
191
+ },
192
+ required: ['spectra'],
193
+ } as const;
194
+
195
+ function isNumberArray(data: unknown): boolean {
196
+ if (data instanceof Float64Array) return true;
197
+ if (!Array.isArray(data)) return false;
198
+ for (let index = 0; index < data.length; index++) {
199
+ if (typeof data[index] !== 'number') return false;
200
+ }
201
+ return true;
202
+ }
@@ -12,7 +12,7 @@
12
12
  * and never sent unasked.
13
13
  */
14
14
 
15
- import { kindAccepts } from './kinds.ts';
15
+ import { kindAccepts } from './kindAccepts.ts';
16
16
  import type { HostItem, OutputMessage } from './protocol.ts';
17
17
 
18
18
  /** Where a tool's outputs are read, and how their changes are heard. */
@@ -33,6 +33,14 @@ export {
33
33
  } from './hostStructure.ts';
34
34
  export type { BandStrength } from './bandStrength.ts';
35
35
  export { BAND_STRENGTHS, BAND_STRENGTH_SCHEMA } from './bandStrength.ts';
36
+ export type {
37
+ DatasetAxisValue,
38
+ DatasetColumnValue,
39
+ DatasetSpectrumValue,
40
+ MetaValue,
41
+ SpectraDatasetValue,
42
+ } from './datasetKinds.ts';
43
+ export { SPECTRA_DATASET_SCHEMA } from './datasetKinds.ts';
36
44
  export type { IrJdxValue, IrPeakValue, IrPeaksValue } from './irKinds.ts';
37
45
  export { IR_JDX_SCHEMA, IR_PEAKS_SCHEMA } from './irKinds.ts';
38
46
  export type {
@@ -44,7 +52,8 @@ export type {
44
52
  OclIdValue,
45
53
  SmilesValue,
46
54
  } from './kinds.ts';
47
- export { checkValue, isKnownKind, kindAccepts, readOutput } from './kinds.ts';
55
+ export { checkValue, isKnownKind, readOutput } from './kinds.ts';
56
+ export { kindAccepts } from './kindAccepts.ts';
48
57
  export type {
49
58
  MsAssignmentValue,
50
59
  MsAssignmentsValue,
@@ -120,3 +129,5 @@ export { toolAboutUrl, toolPageUrl } from './toolPage.ts';
120
129
  export type { ToolHello } from './toolMessages.ts';
121
130
  export { readSettingFields } from './toolSettings.ts';
122
131
  export { readHello, readToolMessage } from './toolMessages.ts';
132
+ export type { SendOffer, SendTarget } from './sendTargets.ts';
133
+ export { sendTargets } from './sendTargets.ts';
@@ -0,0 +1,21 @@
1
+ /**
2
+ * How one kind name falls under another, apart from the schemas of
3
+ * `./kinds.ts`, so a page that only matches kinds — a Send menu — never loads
4
+ * ajv.
5
+ */
6
+
7
+ /**
8
+ * Whether a kind falls under another: the same name, or a name under it on a
9
+ * segment boundary. A list (`…[]`) never stands for one value, nor one value
10
+ * for a list.
11
+ * @param accepted - The kind a tool declares, e.g. `'chem.molfile'`.
12
+ * @param offered - The kind an item carries, e.g. `'chem.molfile.2d'`.
13
+ * @returns `true` when an item of `offered` can be read as `accepted`.
14
+ */
15
+ export function kindAccepts(accepted: string, offered: string): boolean {
16
+ const list = accepted.endsWith('[]');
17
+ if (offered.endsWith('[]') !== list) return false;
18
+ const base = list ? accepted.slice(0, -2) : accepted;
19
+ const name = list ? offered.slice(0, -2) : offered;
20
+ return name === base || name.startsWith(`${base}.`);
21
+ }
@@ -8,7 +8,8 @@
8
8
  * kinds of `./irKinds.ts`, the Raman ones of `./ramanKinds.ts`, the UV-vis
9
9
  * ones of `./uvKinds.ts` and the mass
10
10
  * spectrometry ones of `./msKinds.ts`, the reaction of `./reactionKinds.ts`,
11
- * the peptide of `./peptideKinds.ts`, and
11
+ * the peptide of `./peptideKinds.ts`, the set of spectra of
12
+ * `./datasetKinds.ts`, and
12
13
  * the kinds a tool hands back, of `./resultKinds.ts`. A name with children is a category whose
13
14
  * schema every child satisfies, so `chem.molfile` reads `chem.molfile.2d` and
14
15
  * `chem.molfile.3d.h.energy` alike; the fields a tool does not read are
@@ -19,8 +20,14 @@
19
20
  import type { JSONSchemaType, ValidateFunction } from 'ajv';
20
21
  import { Ajv } from 'ajv';
21
22
 
23
+ import type { SpectraDatasetValue } from './datasetKinds.ts';
24
+ import {
25
+ NUMBER_ARRAY_KEYWORD,
26
+ SPECTRA_DATASET_SCHEMA,
27
+ } from './datasetKinds.ts';
22
28
  import type { IrJdxValue, IrPeaksValue } from './irKinds.ts';
23
29
  import { IR_JDX_SCHEMA, IR_PEAKS_SCHEMA } from './irKinds.ts';
30
+ import { kindAccepts } from './kindAccepts.ts';
24
31
  import type { MsAssignmentsValue, MsIonsValue, MsJdxValue } from './msKinds.ts';
25
32
  import {
26
33
  MS_ASSIGNMENTS_SCHEMA,
@@ -73,7 +80,10 @@ export type CheckedValue =
73
80
  | { kind: 'spectra.ms.assignments'; value: MsAssignmentsValue }
74
81
  | { kind: 'image.svg'; value: SvgImageValue }
75
82
  | { kind: 'chem.name'; value: NameValue }
76
- | { kind: 'data.table'; value: TableValue };
83
+ | { kind: 'data.table'; value: TableValue }
84
+ | { kind: 'data.spectra'; value: SpectraDatasetValue };
85
+
86
+ export { kindAccepts } from './kindAccepts.ts';
77
87
 
78
88
  /** The name of a kind there is a schema for: one a tool reads, or one it hands back. */
79
89
  export type KnownKind = CheckedValue['kind'];
@@ -88,22 +98,6 @@ type ValueOf<K extends KnownKind> = CheckedOf<K>['value'];
88
98
  export type CheckOutcome =
89
99
  { valid: true; checked: CheckedValue } | { valid: false; errors: string[] };
90
100
 
91
- /**
92
- * Whether a kind falls under another: the same name, or a name under it on a
93
- * segment boundary. A list (`…[]`) never stands for one value, nor one value
94
- * for a list.
95
- * @param accepted - The kind a tool declares, e.g. `'chem.molfile'`.
96
- * @param offered - The kind an item carries, e.g. `'chem.molfile.2d'`.
97
- * @returns `true` when an item of `offered` can be read as `accepted`.
98
- */
99
- export function kindAccepts(accepted: string, offered: string): boolean {
100
- const list = accepted.endsWith('[]');
101
- if (offered.endsWith('[]') !== list) return false;
102
- const base = list ? accepted.slice(0, -2) : accepted;
103
- const name = list ? offered.slice(0, -2) : offered;
104
- return name === base || name.startsWith(`${base}.`);
105
- }
106
-
107
101
  /**
108
102
  * Whether there is a schema for a kind.
109
103
  * @param kind - A kind name.
@@ -194,6 +188,7 @@ const SMILES_SCHEMA: JSONSchemaType<SmilesValue> = {
194
188
  // `removeAdditional` strips what `additionalProperties: false` would refuse;
195
189
  // a table's cell is a string, a number or null, which is a union of types.
196
190
  const ajv = new Ajv({ removeAdditional: true, allowUnionTypes: true });
191
+ ajv.addKeyword(NUMBER_ARRAY_KEYWORD);
197
192
 
198
193
  const VALIDATORS: { [K in KnownKind]: ValidateFunction<ValueOf<K>> } = {
199
194
  'chem.molfile': ajv.compile(MOLFILE_SCHEMA),
@@ -217,4 +212,5 @@ const VALIDATORS: { [K in KnownKind]: ValidateFunction<ValueOf<K>> } = {
217
212
  'image.svg': ajv.compile<SvgImageValue>(SVG_IMAGE_SCHEMA),
218
213
  'chem.name': ajv.compile<NameValue>(NAME_SCHEMA),
219
214
  'data.table': ajv.compile<TableValue>(TABLE_SCHEMA),
215
+ 'data.spectra': ajv.compile<SpectraDatasetValue>(SPECTRA_DATASET_SCHEMA),
220
216
  };
@@ -3,8 +3,9 @@
3
3
  * host is answered with when the request loads nothing.
4
4
  */
5
5
 
6
+ import { kindAccepts } from './kindAccepts.ts';
6
7
  import type { CheckedValue, KnownKind } from './kinds.ts';
7
- import { checkValue, isKnownKind, kindAccepts } from './kinds.ts';
8
+ import { checkValue, isKnownKind } from './kinds.ts';
8
9
  import type {
9
10
  HostError,
10
11
  HostItem,
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Which sites of the family can take what a page could send them: matched on
3
+ * the kinds alone, from what the registry says each site receives, before
4
+ * anything is built or any site is opened.
5
+ */
6
+
7
+ import { knownSites } from '../../ecosystem/core/lookup.ts';
8
+ import type {
9
+ EcosystemSite,
10
+ SiteReceiver,
11
+ } from '../../ecosystem/core/types.ts';
12
+
13
+ import { kindAccepts } from './kindAccepts.ts';
14
+
15
+ /** Something a page could send, named before it is built. */
16
+ export interface SendOffer {
17
+ /** The kind it would be sent as, e.g. `'data.spectra'`. */
18
+ kind: string;
19
+ /** What it is, as the menu names it, e.g. `'3 IR spectra'`. */
20
+ label: string;
21
+ }
22
+
23
+ /** A site that can take one of the offers, and how. */
24
+ export interface SendTarget<Offer extends SendOffer = SendOffer> {
25
+ /** The site. */
26
+ site: EcosystemSite;
27
+ /** The way it takes data that matched. */
28
+ receiver: SiteReceiver;
29
+ /** The offer it takes: the first of its kinds that any offer carries. */
30
+ offer: Offer;
31
+ }
32
+
33
+ /**
34
+ * The sites that can take one of the offers, in the order the family declares
35
+ * them. A site whose receiver accepts several offers takes the one its own
36
+ * order of kinds prefers.
37
+ * @param offers - What the page could send, in its own order of preference.
38
+ * @param from - The site sending, which is never offered to itself.
39
+ * @returns One target per site receiver that accepts an offer.
40
+ */
41
+ export function sendTargets<Offer extends SendOffer>(
42
+ offers: readonly Offer[],
43
+ from?: string,
44
+ ): Array<SendTarget<Offer>> {
45
+ const targets: Array<SendTarget<Offer>> = [];
46
+ if (offers.length === 0) return targets;
47
+ for (const site of knownSites()) {
48
+ if (site.id === from) continue;
49
+ for (const receiver of site.receives ?? []) {
50
+ const offer = preferredOffer(receiver, offers);
51
+ if (offer !== undefined) targets.push({ site, receiver, offer });
52
+ }
53
+ }
54
+ return targets;
55
+ }
56
+
57
+ function preferredOffer<Offer extends SendOffer>(
58
+ receiver: SiteReceiver,
59
+ offers: readonly Offer[],
60
+ ): Offer | undefined {
61
+ for (const accepted of receiver.kinds) {
62
+ for (const offer of offers) {
63
+ if (kindAccepts(accepted, offer.kind)) return offer;
64
+ }
65
+ }
66
+ return undefined;
67
+ }