react-cheminfo 0.51.0 → 0.52.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.
- package/README.md +71 -16
- package/lib/host/core/connectHost.d.ts +75 -0
- package/lib/host/core/connectHost.d.ts.map +1 -0
- package/lib/host/core/connectHost.js +171 -0
- package/lib/host/core/connectHost.js.map +1 -0
- package/lib/host/core/hostStructure.d.ts +52 -0
- package/lib/host/core/hostStructure.d.ts.map +1 -0
- package/lib/host/core/hostStructure.js +106 -0
- package/lib/host/core/hostStructure.js.map +1 -0
- package/lib/host/core/index.d.ts +9 -0
- package/lib/host/core/index.d.ts.map +1 -0
- package/lib/host/core/index.js +5 -0
- package/lib/host/core/index.js.map +1 -0
- package/lib/host/core/kinds.d.ts +73 -0
- package/lib/host/core/kinds.d.ts.map +1 -0
- package/lib/host/core/kinds.js +88 -0
- package/lib/host/core/kinds.js.map +1 -0
- package/lib/host/core/protocol.d.ts +134 -0
- package/lib/host/core/protocol.d.ts.map +1 -0
- package/lib/host/core/protocol.js +92 -0
- package/lib/host/core/protocol.js.map +1 -0
- package/lib/host/testing/sciPeaks.d.ts +21 -0
- package/lib/host/testing/sciPeaks.d.ts.map +1 -0
- package/lib/host/testing/sciPeaks.js +62 -0
- package/lib/host/testing/sciPeaks.js.map +1 -0
- package/lib/host/testing/standInHost.d.ts +47 -0
- package/lib/host/testing/standInHost.d.ts.map +1 -0
- package/lib/host/testing/standInHost.js +85 -0
- package/lib/host/testing/standInHost.js.map +1 -0
- package/lib/host/ui/index.d.ts +3 -0
- package/lib/host/ui/index.d.ts.map +1 -0
- package/lib/host/ui/index.js +2 -0
- package/lib/host/ui/index.js.map +1 -0
- package/lib/host/ui/useHostConnection.d.ts +36 -0
- package/lib/host/ui/useHostConnection.d.ts.map +1 -0
- package/lib/host/ui/useHostConnection.js +62 -0
- package/lib/host/ui/useHostConnection.js.map +1 -0
- package/lib/host-testing.d.ts +8 -0
- package/lib/host-testing.d.ts.map +1 -0
- package/lib/host-testing.js +7 -0
- package/lib/host-testing.js.map +1 -0
- package/lib/host.d.ts +11 -0
- package/lib/host.d.ts.map +1 -0
- package/lib/host.js +11 -0
- package/lib/host.js.map +1 -0
- package/package.json +4 -1
- package/src/host/core/connectHost.ts +240 -0
- package/src/host/core/hostStructure.ts +129 -0
- package/src/host/core/index.ts +46 -0
- package/src/host/core/kinds.ts +128 -0
- package/src/host/core/protocol.ts +197 -0
- package/src/host/testing/sciPeaks.ts +66 -0
- package/src/host/testing/standInHost.ts +116 -0
- package/src/host/ui/index.ts +2 -0
- package/src/host/ui/useHostConnection.ts +85 -0
- package/src/host-testing.ts +18 -0
- package/src/host.ts +11 -0
package/README.md
CHANGED
|
@@ -30,22 +30,24 @@ would mean two Blueprint style trees in one page.
|
|
|
30
30
|
Subpaths are **bundle boundaries, not taxonomy**: a feature gets its own door
|
|
31
31
|
only when it drags a heavy dependency behind it.
|
|
32
32
|
|
|
33
|
-
| Import | Holds
|
|
34
|
-
| ---------------------------------- |
|
|
35
|
-
| `react-cheminfo/core` | every framework-free helper — 140 value exports
|
|
36
|
-
| `react-cheminfo/ui` | every React component and hook — 60 value exports
|
|
37
|
-
| `react-cheminfo/vite` | the prerender plugin and the OG card
|
|
38
|
-
| `react-cheminfo/pages` | the Cloudflare Pages analytics middleware
|
|
39
|
-
| `react-cheminfo/orbital` | the 3D atomic-orbital viewer
|
|
40
|
-
| `react-cheminfo/molecule3d` | the 3D molecule viewer and its toolbar
|
|
41
|
-
| `react-cheminfo/structure` | the structure editor and renderer
|
|
42
|
-
| `react-cheminfo/conformers` | conformer generation, ranking and refinement
|
|
43
|
-
| `react-cheminfo/slides` | the deck format and the slideshow player
|
|
44
|
-
| `react-cheminfo/spectra` | the spectra processing settings editors
|
|
45
|
-
| `react-cheminfo/ir` | the infrared chart, band table and editor
|
|
46
|
-
| `react-cheminfo/xtb` | GFN2-xTB as a geometry relaxer
|
|
47
|
-
| `react-cheminfo/
|
|
48
|
-
| `react-cheminfo/
|
|
33
|
+
| Import | Holds | Costs |
|
|
34
|
+
| ---------------------------------- | ----------------------------------------------------- | ------------------------------------------------ |
|
|
35
|
+
| `react-cheminfo/core` | every framework-free helper — 140 value exports | nothing |
|
|
36
|
+
| `react-cheminfo/ui` | every React component and hook — 60 value exports | React |
|
|
37
|
+
| `react-cheminfo/vite` | the prerender plugin and the OG card | nothing; React on the card |
|
|
38
|
+
| `react-cheminfo/pages` | the Cloudflare Pages analytics middleware | nothing |
|
|
39
|
+
| `react-cheminfo/orbital` | the 3D atomic-orbital viewer | React, molstar |
|
|
40
|
+
| `react-cheminfo/molecule3d` | the 3D molecule viewer and its toolbar | React, molstar |
|
|
41
|
+
| `react-cheminfo/structure` | the structure editor and renderer | React, react-ocl, OCL |
|
|
42
|
+
| `react-cheminfo/conformers` | conformer generation, ranking and refinement | OCL |
|
|
43
|
+
| `react-cheminfo/slides` | the deck format and the slideshow player | React, react-markdown |
|
|
44
|
+
| `react-cheminfo/spectra` | the spectra processing settings editors | React; types only from spectra-processor, ml-pca |
|
|
45
|
+
| `react-cheminfo/ir` | the infrared chart, band table and editor | React, ir-spectrum, convert-to-jcamp |
|
|
46
|
+
| `react-cheminfo/xtb` | GFN2-xTB as a geometry relaxer | nothing on import; xtb-wasm on the first call |
|
|
47
|
+
| `react-cheminfo/host` | data handed over by a page that frames the tool | nothing on import; ajv once the page is framed |
|
|
48
|
+
| `react-cheminfo/host-testing` | a stand-in host and SciPeaks' messages, for e2e tests | nothing; Node only |
|
|
49
|
+
| `react-cheminfo/styles/chrome.css` | the shared tokens and site-header stylesheet | nothing |
|
|
50
|
+
| `react-cheminfo/styles/slides.css` | the deck stylesheet, themed on the site's colours | nothing |
|
|
49
51
|
|
|
50
52
|
A backend serving an RIS endpoint, a prerender script writing a sitemap, and
|
|
51
53
|
every unit test of that logic therefore load no React at all — and a worker
|
|
@@ -116,6 +118,7 @@ through a wildcard subpath exactly as `react-science` serves its own.
|
|
|
116
118
|
| **Parallel coordinates** | `parallelAxisOf`, `parallelAxisLayouts`, `parallelIncludedMask`, `parallelKeptCount`, `parallelNearestRow`, `parallelSegmentAt`, `parallelBandAt`, `parallelRangeOf`, `parallelPalette`, `parallelColorSteps`, `paintParallelLines` | `ParallelCoordinates` |
|
|
117
119
|
| **Periodic table** | `PERIODIC_ELEMENTS`, `elementBySymbol`, `elementByAtomicNumber`, `cellOf`, `placedElements`, `elementByArrowKey`, `EMPTY_BLOCK`, `categorySwatch`, `CATEGORY_LABELS` | `PeriodicTable`, `ElementCell`, `CategoryLegend` |
|
|
118
120
|
| **Taxonomy** | `TAXON_RANKS`, `PRINCIPAL_RANKS`, `rankOrder`, `isPrincipalRank`, `isGenusOrBelow`, `isAboveGenus`, `principalLineage`, `lineageFromNodes`, `lineageFromRanks`, `genusOrBelow`, `ncbiTaxonomyUrl`, `splitOrganismName` | `TaxonLineage`, `OrganismName`, `useRankLabel` |
|
|
121
|
+
| **Framed by a host** | `hostStructureLoader`, `readHostMolecule`, `STRUCTURE_KINDS`, `connectHost`, `selectInputs`, `checkValue`, `kindAccepts`, `parseRequest` (all `/host`); `startStandInHost`, `SCIPEAKS_ETHYLBENZENE_LOAD` (`/host-testing`) | `useHostConnection` (`/host`) |
|
|
119
122
|
|
|
120
123
|
Everything in that table is exported from `./core`, `./ui`, `./slides`,
|
|
121
124
|
`./vite` or `./structure` and nothing else is: the sub-components a component is built
|
|
@@ -836,6 +839,58 @@ const included = useMemo(
|
|
|
836
839
|
subject — a formula through `react-mf`, a structure, a name — and a readout of
|
|
837
840
|
strings cannot hold any of that.
|
|
838
841
|
|
|
842
|
+
## Framed by a notebook
|
|
843
|
+
|
|
844
|
+
A page that frames a tool — an electronic lab notebook such as SciPeaks, a
|
|
845
|
+
course — can hand it typed data instead of writing it into the link. The tool
|
|
846
|
+
says `cheminfo:hello` to its parent, the parent answers `cheminfo:connect` with
|
|
847
|
+
a private `MessageChannel` port, and the data arrives on that port as
|
|
848
|
+
`{ kind, value }` items, each checked against pipeline.cheminfo.org's JSON
|
|
849
|
+
Schema before the tool reads it. A tool taking a structure writes two things:
|
|
850
|
+
|
|
851
|
+
```ts
|
|
852
|
+
// src/tool.ts
|
|
853
|
+
import type { ToolInterface } from 'react-cheminfo/host';
|
|
854
|
+
import { STRUCTURE_KINDS, hostStructureLoader } from 'react-cheminfo/host';
|
|
855
|
+
|
|
856
|
+
export const TOOL: ToolInterface = {
|
|
857
|
+
name: '3d',
|
|
858
|
+
inputs: [{ key: 'structure', kinds: STRUCTURE_KINDS }],
|
|
859
|
+
outputs: [],
|
|
860
|
+
};
|
|
861
|
+
|
|
862
|
+
export const loadFromHost = hostStructureLoader((molecule, label) => {
|
|
863
|
+
loadSmiles(molecule.toIsomericSmiles(), label);
|
|
864
|
+
});
|
|
865
|
+
```
|
|
866
|
+
|
|
867
|
+
```tsx
|
|
868
|
+
// App.tsx, right after the hook that applies the address
|
|
869
|
+
useHostConnection(TOOL, { load: loadFromHost, build: BUILD_INFO });
|
|
870
|
+
```
|
|
871
|
+
|
|
872
|
+
- **Nothing is downloaded unless the page is framed**: the connection and ajv
|
|
873
|
+
are one lazy chunk, fetched once a parent or an opener exists.
|
|
874
|
+
- **A structure that does not read is answered, not shown**: the host gets
|
|
875
|
+
`unreadable` with one sentence it can display, and the screen does not change.
|
|
876
|
+
A molfile whose atoms all sit on one point — SciPeaks stores some that way —
|
|
877
|
+
is laid out again.
|
|
878
|
+
- **The same document twice is applied once**, so a host re-sending a sample
|
|
879
|
+
never overwrites what the visitor did with it.
|
|
880
|
+
|
|
881
|
+
`react-cheminfo/host-testing` serves a stand-in host for Playwright on
|
|
882
|
+
`127.0.0.1`, and exports `SCIPEAKS_ETHYLBENZENE_LOAD`: the message SciPeaks'
|
|
883
|
+
tool tab sends for a sample, byte for byte. visualizer-helper's tests pin the
|
|
884
|
+
same message, so a change on either side fails a test rather than a notebook.
|
|
885
|
+
|
|
886
|
+
```ts
|
|
887
|
+
const host = await startStandInHost();
|
|
888
|
+
await page.goto(
|
|
889
|
+
host.pageUrl(`${origin}/?embed=1`, [SCIPEAKS_ETHYLBENZENE_LOAD]),
|
|
890
|
+
);
|
|
891
|
+
const { results } = await page.evaluate(readStandInHostLog);
|
|
892
|
+
```
|
|
893
|
+
|
|
839
894
|
## Speaking four languages
|
|
840
895
|
|
|
841
896
|
Every word this library puts on a page — the header, the Tools menu, the Cite
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A tool's side of the host protocol: introduce itself to the page that
|
|
3
|
+
* frames it, take the private port that page answers with, and serve what
|
|
4
|
+
* arrives through it.
|
|
5
|
+
*
|
|
6
|
+
* Free of React and of the DOM — the window is handed in — so a test drives the
|
|
7
|
+
* whole exchange with a fake host and a real `MessageChannel`.
|
|
8
|
+
*/
|
|
9
|
+
import type { CheckedValue } from './kinds.ts';
|
|
10
|
+
import type { HostError, HostItem, ToolInterface } from './protocol.ts';
|
|
11
|
+
/** The item an input took, and its value as the input's kind reads it. */
|
|
12
|
+
export interface LoadedInput {
|
|
13
|
+
key: string;
|
|
14
|
+
item: HostItem;
|
|
15
|
+
checked: CheckedValue;
|
|
16
|
+
}
|
|
17
|
+
/** What a window `message` event carries, as far as the protocol reads it. */
|
|
18
|
+
export interface HostMessageEvent {
|
|
19
|
+
data: unknown;
|
|
20
|
+
source: unknown;
|
|
21
|
+
ports: readonly MessagePort[];
|
|
22
|
+
}
|
|
23
|
+
/** Where the connection runs, and what it serves. */
|
|
24
|
+
export interface HostConnectionOptions {
|
|
25
|
+
/** The page to introduce the tool to: the parent frame, or the opener. */
|
|
26
|
+
host: {
|
|
27
|
+
postMessage: (message: unknown, targetOrigin: string) => void;
|
|
28
|
+
};
|
|
29
|
+
/** Subscribe to this window's messages; the returned function unsubscribes. */
|
|
30
|
+
listen: (listener: (event: HostMessageEvent) => void) => () => void;
|
|
31
|
+
/** What the tool takes and gives, as `hello` announces it. */
|
|
32
|
+
tool: ToolInterface;
|
|
33
|
+
/** The tool's origin, as `hello` states it. */
|
|
34
|
+
origin: string;
|
|
35
|
+
/** The build that is running, as the About states it, or `null`. */
|
|
36
|
+
build: unknown;
|
|
37
|
+
/**
|
|
38
|
+
* Show the inputs of a new document. Throwing means they could not be read:
|
|
39
|
+
* the error's message goes back to the host, and the document is not marked
|
|
40
|
+
* as applied.
|
|
41
|
+
*/
|
|
42
|
+
load: (inputs: readonly LoadedInput[]) => void;
|
|
43
|
+
}
|
|
44
|
+
/** What choosing the items of a request gave. */
|
|
45
|
+
export type InputSelection = {
|
|
46
|
+
ok: true;
|
|
47
|
+
inputs: LoadedInput[];
|
|
48
|
+
} | {
|
|
49
|
+
ok: false;
|
|
50
|
+
error: HostError;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Say `hello` to the host, and serve its requests once it connects.
|
|
54
|
+
*
|
|
55
|
+
* A `connect` is accepted only from the window `hello` went to, and a second
|
|
56
|
+
* one replaces the first — a host that reloads its own script connects again.
|
|
57
|
+
* A document is applied once: the same one again is answered as before and
|
|
58
|
+
* changes nothing, so a host re-sending it never overwrites the user's work.
|
|
59
|
+
* @param options - The window, the tool, and its load function.
|
|
60
|
+
* @returns The function that stops listening and closes the port.
|
|
61
|
+
*/
|
|
62
|
+
export declare function connectHost(options: HostConnectionOptions): () => void;
|
|
63
|
+
/**
|
|
64
|
+
* Give each input of the tool one item of a request.
|
|
65
|
+
*
|
|
66
|
+
* Each input tries its kinds in its own order of preference, and takes the
|
|
67
|
+
* first item that falls under one and passes that kind's schema: the tool
|
|
68
|
+
* knows which notation serves it best, whatever order the host listed them in.
|
|
69
|
+
* An item naming another input's `key` is left to that input.
|
|
70
|
+
* @param tool - What the tool takes.
|
|
71
|
+
* @param items - What the host sent.
|
|
72
|
+
* @returns One item per input, or why an input got none.
|
|
73
|
+
*/
|
|
74
|
+
export declare function selectInputs(tool: ToolInterface, items: readonly HostItem[]): InputSelection;
|
|
75
|
+
//# sourceMappingURL=connectHost.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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E;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,qBAAqB,GAAG,MAAM,IAAI,CA0EtE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,aAAa,EACnB,KAAK,EAAE,SAAS,QAAQ,EAAE,GACzB,cAAc,CA4BhB"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A tool's side of the host protocol: introduce itself to the page that
|
|
3
|
+
* frames it, take the private port that page answers with, and serve what
|
|
4
|
+
* arrives through it.
|
|
5
|
+
*
|
|
6
|
+
* Free of React and of the DOM — the window is handed in — so a test drives the
|
|
7
|
+
* whole exchange with a fake host and a real `MessageChannel`.
|
|
8
|
+
*/
|
|
9
|
+
import { checkValue, isKnownKind, kindAccepts } from "./kinds.js";
|
|
10
|
+
import { HELLO_TYPE, PROTOCOL_VERSION, isConnect, parseRequest, } from "./protocol.js";
|
|
11
|
+
/**
|
|
12
|
+
* Say `hello` to the host, and serve its requests once it connects.
|
|
13
|
+
*
|
|
14
|
+
* A `connect` is accepted only from the window `hello` went to, and a second
|
|
15
|
+
* one replaces the first — a host that reloads its own script connects again.
|
|
16
|
+
* A document is applied once: the same one again is answered as before and
|
|
17
|
+
* changes nothing, so a host re-sending it never overwrites the user's work.
|
|
18
|
+
* @param options - The window, the tool, and its load function.
|
|
19
|
+
* @returns The function that stops listening and closes the port.
|
|
20
|
+
*/
|
|
21
|
+
export function connectHost(options) {
|
|
22
|
+
const { host, listen, tool, origin, build, load } = options;
|
|
23
|
+
let port = null;
|
|
24
|
+
let appliedDocument = null;
|
|
25
|
+
let appliedUsed = [];
|
|
26
|
+
function serve(data) {
|
|
27
|
+
const request = parseRequest(data);
|
|
28
|
+
if (request === null)
|
|
29
|
+
return;
|
|
30
|
+
const result = request.type === 'load' ? applyLoad(request) : answerGet(request, tool);
|
|
31
|
+
port?.postMessage(result);
|
|
32
|
+
}
|
|
33
|
+
function applyLoad(request) {
|
|
34
|
+
const { id, document, items } = request;
|
|
35
|
+
if (document === appliedDocument) {
|
|
36
|
+
return { type: 'result', id, ok: true, used: appliedUsed };
|
|
37
|
+
}
|
|
38
|
+
const selection = selectInputs(tool, items);
|
|
39
|
+
if (!selection.ok) {
|
|
40
|
+
return { type: 'result', id, ok: false, error: selection.error };
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
load(selection.inputs);
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
47
|
+
return {
|
|
48
|
+
type: 'result',
|
|
49
|
+
id,
|
|
50
|
+
ok: false,
|
|
51
|
+
error: { code: 'unreadable', message },
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
appliedDocument = document;
|
|
55
|
+
appliedUsed = selection.inputs.map(({ key, item }) => ({
|
|
56
|
+
key,
|
|
57
|
+
kind: item.kind,
|
|
58
|
+
}));
|
|
59
|
+
return { type: 'result', id, ok: true, used: appliedUsed };
|
|
60
|
+
}
|
|
61
|
+
const stopListening = listen((event) => {
|
|
62
|
+
if (event.source !== host || !isConnect(event.data))
|
|
63
|
+
return;
|
|
64
|
+
const received = event.ports[0];
|
|
65
|
+
if (received === undefined)
|
|
66
|
+
return;
|
|
67
|
+
port?.close();
|
|
68
|
+
port = received;
|
|
69
|
+
port.addEventListener('message', (message) => {
|
|
70
|
+
serve(message.data);
|
|
71
|
+
});
|
|
72
|
+
port.start();
|
|
73
|
+
});
|
|
74
|
+
const hello = {
|
|
75
|
+
type: HELLO_TYPE,
|
|
76
|
+
version: PROTOCOL_VERSION,
|
|
77
|
+
tool: {
|
|
78
|
+
name: tool.name,
|
|
79
|
+
origin,
|
|
80
|
+
build,
|
|
81
|
+
inputs: tool.inputs,
|
|
82
|
+
outputs: tool.outputs,
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
// `hello` says nothing a stranger may not read, and the parent's origin is
|
|
86
|
+
// not knowable until it answers.
|
|
87
|
+
host.postMessage(hello, '*');
|
|
88
|
+
return () => {
|
|
89
|
+
stopListening();
|
|
90
|
+
port?.close();
|
|
91
|
+
port = null;
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Give each input of the tool one item of a request.
|
|
96
|
+
*
|
|
97
|
+
* Each input tries its kinds in its own order of preference, and takes the
|
|
98
|
+
* first item that falls under one and passes that kind's schema: the tool
|
|
99
|
+
* knows which notation serves it best, whatever order the host listed them in.
|
|
100
|
+
* An item naming another input's `key` is left to that input.
|
|
101
|
+
* @param tool - What the tool takes.
|
|
102
|
+
* @param items - What the host sent.
|
|
103
|
+
* @returns One item per input, or why an input got none.
|
|
104
|
+
*/
|
|
105
|
+
export function selectInputs(tool, items) {
|
|
106
|
+
const inputs = [];
|
|
107
|
+
for (const input of tool.inputs) {
|
|
108
|
+
const errors = [];
|
|
109
|
+
const loaded = selectInput(input, items, errors);
|
|
110
|
+
if (loaded !== null) {
|
|
111
|
+
inputs.push(loaded);
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
if (errors.length > 0) {
|
|
115
|
+
return {
|
|
116
|
+
ok: false,
|
|
117
|
+
error: {
|
|
118
|
+
code: 'invalid',
|
|
119
|
+
message: `No item for ${input.key} has the shape its kind requires, so ${tool.name} loaded nothing.`,
|
|
120
|
+
errors,
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
ok: false,
|
|
126
|
+
error: {
|
|
127
|
+
code: 'no-input',
|
|
128
|
+
message: `No item is a ${KIND_LIST.format(input.kinds)}, so ${tool.name} loaded nothing.`,
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
return { ok: true, inputs };
|
|
133
|
+
}
|
|
134
|
+
function selectInput(input, items, errors) {
|
|
135
|
+
for (const accepted of input.kinds) {
|
|
136
|
+
if (!isKnownKind(accepted))
|
|
137
|
+
continue;
|
|
138
|
+
for (const item of items) {
|
|
139
|
+
if (item.key !== undefined && item.key !== input.key)
|
|
140
|
+
continue;
|
|
141
|
+
if (!kindAccepts(accepted, item.kind))
|
|
142
|
+
continue;
|
|
143
|
+
const loaded = checkItem(input.key, accepted, item, errors);
|
|
144
|
+
if (loaded !== null)
|
|
145
|
+
return loaded;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
function checkItem(key, accepted, item, errors) {
|
|
151
|
+
const outcome = checkValue(accepted, item.value);
|
|
152
|
+
if (outcome.valid)
|
|
153
|
+
return { key, item, checked: outcome.checked };
|
|
154
|
+
for (const error of outcome.errors)
|
|
155
|
+
errors.push(`${item.kind} ${error}`);
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
function answerGet(request, tool) {
|
|
159
|
+
// Nothing goes back yet: no tool declares an output.
|
|
160
|
+
return {
|
|
161
|
+
type: 'result',
|
|
162
|
+
id: request.id,
|
|
163
|
+
ok: false,
|
|
164
|
+
error: {
|
|
165
|
+
code: 'no-output',
|
|
166
|
+
message: `${tool.name} has nothing to give back yet.`,
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
const KIND_LIST = new Intl.ListFormat('en', { type: 'disjunction' });
|
|
171
|
+
//# sourceMappingURL=connectHost.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connectHost.js","sourceRoot":"","sources":["../../../src/host/core/connectHost.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAYlE,OAAO,EACL,UAAU,EACV,gBAAgB,EAChB,SAAS,EACT,YAAY,GACb,MAAM,eAAe,CAAC;AAwCvB;;;;;;;;;GASG;AACH,MAAM,UAAU,WAAW,CAAC,OAA8B;IACxD,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,K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AE,WAAW;YACjB,OAAO,EAAE,GAAG,IAAI,CAAC,IAAI,gCAAgC;SACtD;KACF,CAAC;AACJ,CAAC;AAED,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A structure a host handed over, read into the molecule a tool works on.
|
|
3
|
+
*
|
|
4
|
+
* Every tool of the family that takes a structure takes it the same way — in
|
|
5
|
+
* the three notations a notebook keeps, the one that says the most first — so
|
|
6
|
+
* the kinds, the parsing and the sentence a host reads when it fails are
|
|
7
|
+
* written once, here.
|
|
8
|
+
*/
|
|
9
|
+
import type { Molecule } from 'openchemlib';
|
|
10
|
+
import type { StructureSource } from '../../structure/core/structureSource.ts';
|
|
11
|
+
import type { LoadedInput } from './connectHost.ts';
|
|
12
|
+
import type { CheckedValue } from './kinds.ts';
|
|
13
|
+
/**
|
|
14
|
+
* The kinds a structure input accepts, in order of preference: a molfile
|
|
15
|
+
* carries the layout its author drew, an idcode the exact structure, a SMILES
|
|
16
|
+
* only the connectivity.
|
|
17
|
+
*/
|
|
18
|
+
export declare const STRUCTURE_KINDS: readonly ["chem.molfile", "chem.ocl.id", "chem.smiles"];
|
|
19
|
+
/** A checked value holding a structure. */
|
|
20
|
+
export type StructureValue = Extract<CheckedValue, {
|
|
21
|
+
kind: (typeof STRUCTURE_KINDS)[number];
|
|
22
|
+
}>;
|
|
23
|
+
/**
|
|
24
|
+
* The function a tool hands `useHostConnection` as `load` when its input is a
|
|
25
|
+
* structure.
|
|
26
|
+
*
|
|
27
|
+
* The structure is parsed before `show` is called, so one that cannot be read
|
|
28
|
+
* is answered `unreadable` with a sentence the host can show, and nothing on
|
|
29
|
+
* the tool's screen changes.
|
|
30
|
+
* @param show - Puts the molecule on screen, under the host's label for it.
|
|
31
|
+
* @param key - The input the structure arrives on.
|
|
32
|
+
* @returns The `load` function.
|
|
33
|
+
*/
|
|
34
|
+
export declare function hostStructureLoader(show: (molecule: Molecule, label: string | undefined) => void, key?: string): (inputs: readonly LoadedInput[]) => void;
|
|
35
|
+
/**
|
|
36
|
+
* Read a structure a host sent.
|
|
37
|
+
*
|
|
38
|
+
* A molfile whose atoms all sit on one point — SciPeaks stores some that way —
|
|
39
|
+
* is laid out again, so a tool that draws it does not draw one dot.
|
|
40
|
+
* @param checked - The value, already checked against its kind.
|
|
41
|
+
* @returns A molecule with at least one atom.
|
|
42
|
+
* @throws {Error} When the notation does not parse or describes no atoms; the
|
|
43
|
+
* message is the sentence the host is answered with.
|
|
44
|
+
*/
|
|
45
|
+
export declare function readHostMolecule(checked: StructureValue): Molecule;
|
|
46
|
+
/**
|
|
47
|
+
* A structure a host sent, as the notation a depiction is drawn from.
|
|
48
|
+
* @param checked - The value, already checked against its kind.
|
|
49
|
+
* @returns The notation and its text; an idcode keeps its coordinates.
|
|
50
|
+
*/
|
|
51
|
+
export declare function hostStructureSource(checked: StructureValue): StructureSource;
|
|
52
|
+
//# sourceMappingURL=hostStructure.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hostStructure.d.ts","sourceRoot":"","sources":["../../../src/host/core/hostStructure.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAI5C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAE/E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C;;;;GAIG;AACH,eAAO,MAAM,eAAe,yDAIlB,CAAC;AAEX,2CAA2C;AAC3C,MAAM,MAAM,cAAc,GAAG,OAAO,CAClC,YAAY,EACZ;IAAE,IAAI,EAAE,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAA;CAAE,CAC3C,CAAC;AAEF;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,KAAK,IAAI,EAC7D,GAAG,SAAc,GAChB,CAAC,MAAM,EAAE,SAAS,WAAW,EAAE,KAAK,IAAI,CAO1C;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,cAAc,GAAG,QAAQ,CAmBlE;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,cAAc,GAAG,eAAe,CAW5E"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A structure a host handed over, read into the molecule a tool works on.
|
|
3
|
+
*
|
|
4
|
+
* Every tool of the family that takes a structure takes it the same way — in
|
|
5
|
+
* the three notations a notebook keeps, the one that says the most first — so
|
|
6
|
+
* the kinds, the parsing and the sentence a host reads when it fails are
|
|
7
|
+
* written once, here.
|
|
8
|
+
*/
|
|
9
|
+
import { sourceMolecule } from "../../structure/core/sourceMolecule.js";
|
|
10
|
+
import { structureError } from "../../structure/core/structureError.js";
|
|
11
|
+
/**
|
|
12
|
+
* The kinds a structure input accepts, in order of preference: a molfile
|
|
13
|
+
* carries the layout its author drew, an idcode the exact structure, a SMILES
|
|
14
|
+
* only the connectivity.
|
|
15
|
+
*/
|
|
16
|
+
export const STRUCTURE_KINDS = [
|
|
17
|
+
'chem.molfile',
|
|
18
|
+
'chem.ocl.id',
|
|
19
|
+
'chem.smiles',
|
|
20
|
+
];
|
|
21
|
+
/**
|
|
22
|
+
* The function a tool hands `useHostConnection` as `load` when its input is a
|
|
23
|
+
* structure.
|
|
24
|
+
*
|
|
25
|
+
* The structure is parsed before `show` is called, so one that cannot be read
|
|
26
|
+
* is answered `unreadable` with a sentence the host can show, and nothing on
|
|
27
|
+
* the tool's screen changes.
|
|
28
|
+
* @param show - Puts the molecule on screen, under the host's label for it.
|
|
29
|
+
* @param key - The input the structure arrives on.
|
|
30
|
+
* @returns The `load` function.
|
|
31
|
+
*/
|
|
32
|
+
export function hostStructureLoader(show, key = 'structure') {
|
|
33
|
+
return (inputs) => {
|
|
34
|
+
for (const { key: inputKey, item, checked } of inputs) {
|
|
35
|
+
if (inputKey !== key || !isStructureValue(checked))
|
|
36
|
+
continue;
|
|
37
|
+
show(readHostMolecule(checked), item.label);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Read a structure a host sent.
|
|
43
|
+
*
|
|
44
|
+
* A molfile whose atoms all sit on one point — SciPeaks stores some that way —
|
|
45
|
+
* is laid out again, so a tool that draws it does not draw one dot.
|
|
46
|
+
* @param checked - The value, already checked against its kind.
|
|
47
|
+
* @returns A molecule with at least one atom.
|
|
48
|
+
* @throws {Error} When the notation does not parse or describes no atoms; the
|
|
49
|
+
* message is the sentence the host is answered with.
|
|
50
|
+
*/
|
|
51
|
+
export function readHostMolecule(checked) {
|
|
52
|
+
const notation = NOTATIONS[checked.kind];
|
|
53
|
+
let molecule;
|
|
54
|
+
try {
|
|
55
|
+
molecule = sourceMolecule(hostStructureSource(checked));
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
const { message } = structureError(error);
|
|
59
|
+
throw new Error(`The ${notation} could not be read, so nothing was loaded: ${message}`, { cause: error });
|
|
60
|
+
}
|
|
61
|
+
if (molecule.getAllAtoms() === 0) {
|
|
62
|
+
throw new Error(`The ${notation} describes no atoms, so nothing was loaded.`);
|
|
63
|
+
}
|
|
64
|
+
if (atomsCoincide(molecule))
|
|
65
|
+
molecule.inventCoordinates();
|
|
66
|
+
return molecule;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* A structure a host sent, as the notation a depiction is drawn from.
|
|
70
|
+
* @param checked - The value, already checked against its kind.
|
|
71
|
+
* @returns The notation and its text; an idcode keeps its coordinates.
|
|
72
|
+
*/
|
|
73
|
+
export function hostStructureSource(checked) {
|
|
74
|
+
if (checked.kind === 'chem.molfile') {
|
|
75
|
+
return { kind: 'molfile', value: checked.value.molfile };
|
|
76
|
+
}
|
|
77
|
+
if (checked.kind === 'chem.ocl.id') {
|
|
78
|
+
const { idCode, coordinates } = checked.value;
|
|
79
|
+
return coordinates === ''
|
|
80
|
+
? { kind: 'idcode', value: idCode }
|
|
81
|
+
: { kind: 'idcode', value: idCode, coordinates };
|
|
82
|
+
}
|
|
83
|
+
return { kind: 'smiles', value: checked.value.smiles.trim() };
|
|
84
|
+
}
|
|
85
|
+
const NOTATIONS = {
|
|
86
|
+
'chem.molfile': 'molfile',
|
|
87
|
+
'chem.ocl.id': 'idcode',
|
|
88
|
+
'chem.smiles': 'SMILES',
|
|
89
|
+
};
|
|
90
|
+
function atomsCoincide(molecule) {
|
|
91
|
+
const atoms = molecule.getAllAtoms();
|
|
92
|
+
if (atoms < 2)
|
|
93
|
+
return false;
|
|
94
|
+
const x = molecule.getAtomX(0);
|
|
95
|
+
const y = molecule.getAtomY(0);
|
|
96
|
+
for (let atom = 1; atom < atoms; atom++) {
|
|
97
|
+
if (molecule.getAtomX(atom) !== x || molecule.getAtomY(atom) !== y) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
function isStructureValue(checked) {
|
|
104
|
+
return Object.hasOwn(NOTATIONS, checked.kind);
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=hostStructure.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hostStructure.js","sourceRoot":"","sources":["../../../src/host/core/hostStructure.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AAMxE;;;;GAIG;AACH,MAAM,CAAC,MAAM,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,CAAC,KAAK,CAAC,EAAE,CAAC;YACnE,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,gBAAgB,CAAC,OAAqB;IAC7C,OAAO,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type { HostConnectionOptions, HostMessageEvent, InputSelection, LoadedInput, } from './connectHost.ts';
|
|
2
|
+
export { connectHost, selectInputs } from './connectHost.ts';
|
|
3
|
+
export type { StructureValue } from './hostStructure.ts';
|
|
4
|
+
export { STRUCTURE_KINDS, hostStructureLoader, hostStructureSource, readHostMolecule, } from './hostStructure.ts';
|
|
5
|
+
export type { CheckOutcome, CheckedValue, KnownKind, MolfileValue, OclIdValue, SmilesValue, } from './kinds.ts';
|
|
6
|
+
export { checkValue, isKnownKind, kindAccepts } from './kinds.ts';
|
|
7
|
+
export type { GetRequest, HelloMessage, HostError, HostErrorCode, HostItem, HostRequest, LoadRequest, ResultMessage, ToolInput, ToolInterface, ToolOutput, UsedItem, } from './protocol.ts';
|
|
8
|
+
export { CONNECT_TYPE, HELLO_TYPE, MAX_ITEMS, MAX_LABEL_LENGTH, PROTOCOL_VERSION, isConnect, parseRequest, } from './protocol.ts';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/host/core/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,qBAAqB,EACrB,gBAAgB,EAChB,cAAc,EACd,WAAW,GACZ,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC7D,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EACV,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,YAAY,EACZ,UAAU,EACV,WAAW,GACZ,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAClE,YAAY,EACV,UAAU,EACV,YAAY,EACZ,SAAS,EACT,aAAa,EACb,QAAQ,EACR,WAAW,EACX,WAAW,EACX,aAAa,EACb,SAAS,EACT,aAAa,EACb,UAAU,EACV,QAAQ,GACT,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,YAAY,EACZ,UAAU,EACV,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EAChB,SAAS,EACT,YAAY,GACb,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { connectHost, selectInputs } from "./connectHost.js";
|
|
2
|
+
export { STRUCTURE_KINDS, hostStructureLoader, hostStructureSource, readHostMolecule, } from "./hostStructure.js";
|
|
3
|
+
export { checkValue, isKnownKind, kindAccepts } from "./kinds.js";
|
|
4
|
+
export { CONNECT_TYPE, HELLO_TYPE, MAX_ITEMS, MAX_LABEL_LENGTH, PROTOCOL_VERSION, isConnect, parseRequest, } from "./protocol.js";
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/host/core/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAE7D,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAS5B,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAelE,OAAO,EACL,YAAY,EACZ,UAAU,EACV,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EAChB,SAAS,EACT,YAAY,GACb,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The kinds of data a tool takes from a host, checked the way
|
|
3
|
+
* pipeline.cheminfo.org checks what its workers pass to each other: a dotted
|
|
4
|
+
* name, a JSON Schema, and ajv.
|
|
5
|
+
*
|
|
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.
|
|
12
|
+
*/
|
|
13
|
+
/** A molfile, V2000 or V3000. */
|
|
14
|
+
export interface MolfileValue {
|
|
15
|
+
molfile: string;
|
|
16
|
+
}
|
|
17
|
+
/** An OpenChemLib idcode and its 2D coordinates. */
|
|
18
|
+
export interface OclIdValue {
|
|
19
|
+
idCode: string;
|
|
20
|
+
coordinates: string;
|
|
21
|
+
}
|
|
22
|
+
/** A SMILES. */
|
|
23
|
+
export interface SmilesValue {
|
|
24
|
+
smiles: string;
|
|
25
|
+
}
|
|
26
|
+
/** A value that passed its kind's schema, tagged with that kind. */
|
|
27
|
+
export type CheckedValue = {
|
|
28
|
+
kind: 'chem.molfile';
|
|
29
|
+
value: MolfileValue;
|
|
30
|
+
} | {
|
|
31
|
+
kind: 'chem.ocl.id';
|
|
32
|
+
value: OclIdValue;
|
|
33
|
+
} | {
|
|
34
|
+
kind: 'chem.smiles';
|
|
35
|
+
value: SmilesValue;
|
|
36
|
+
};
|
|
37
|
+
/** The name of a kind a tool can read. */
|
|
38
|
+
export type KnownKind = CheckedValue['kind'];
|
|
39
|
+
/** What checking a value gave. */
|
|
40
|
+
export type CheckOutcome = {
|
|
41
|
+
valid: true;
|
|
42
|
+
checked: CheckedValue;
|
|
43
|
+
} | {
|
|
44
|
+
valid: false;
|
|
45
|
+
errors: string[];
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Whether a kind falls under another: the same name, or a name under it on a
|
|
49
|
+
* segment boundary. A list (`…[]`) never stands for one value, nor one value
|
|
50
|
+
* for a list.
|
|
51
|
+
* @param accepted - The kind a tool declares, e.g. `'chem.molfile'`.
|
|
52
|
+
* @param offered - The kind an item carries, e.g. `'chem.molfile.2d'`.
|
|
53
|
+
* @returns `true` when an item of `offered` can be read as `accepted`.
|
|
54
|
+
*/
|
|
55
|
+
export declare function kindAccepts(accepted: string, offered: string): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Whether there is a schema for a kind.
|
|
58
|
+
* @param kind - A kind name.
|
|
59
|
+
* @returns `true` for a {@link KnownKind}.
|
|
60
|
+
*/
|
|
61
|
+
export declare function isKnownKind(kind: string): kind is KnownKind;
|
|
62
|
+
/**
|
|
63
|
+
* Check a value against a kind's schema.
|
|
64
|
+
*
|
|
65
|
+
* Fields the schema does not name are removed from `value` itself, so what the
|
|
66
|
+
* site reads afterwards is exactly what the kind promises.
|
|
67
|
+
* @param kind - The kind to read the value as.
|
|
68
|
+
* @param value - The value, as received.
|
|
69
|
+
* @returns The value tagged with its kind, or the errors as pipeline writes
|
|
70
|
+
* them, `'/idCode: must be string'`.
|
|
71
|
+
*/
|
|
72
|
+
export declare function checkValue(kind: KnownKind, value: unknown): CheckOutcome;
|
|
73
|
+
//# sourceMappingURL=kinds.d.ts.map
|
|
@@ -0,0 +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;IACz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