@zakodium/nmrium-core 0.1.4 → 0.1.5
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/dist/nmrium-core.d.ts +91 -0
- package/dist/nmrium-core.js +2 -2
- package/package.json +3 -2
package/dist/nmrium-core.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ import type { NmrData1D } from 'cheminfo-types';
|
|
|
15
15
|
import type { NmrData2D } from 'cheminfo-types';
|
|
16
16
|
import type { Peaks } from '@zakodium/nmr-types';
|
|
17
17
|
import type { Ranges } from '@zakodium/nmr-types';
|
|
18
|
+
import type { ReactNode } from 'react';
|
|
18
19
|
import { SerializedNmriumState } from './core_serialize.js';
|
|
19
20
|
import type { Source } from 'file-collection';
|
|
20
21
|
import type { Zones } from '@zakodium/nmr-types';
|
|
@@ -32,6 +33,13 @@ export declare interface AdvanceExportSettings extends BaseExportSettings {
|
|
|
32
33
|
unit: Unit;
|
|
33
34
|
}
|
|
34
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Used by plugins to register UI slots.
|
|
38
|
+
*/
|
|
39
|
+
export declare const ALLOWED_UI_SLOTS: readonly ["topbar.right"];
|
|
40
|
+
|
|
41
|
+
export declare type AllowedUISlot = (typeof ALLOWED_UI_SLOTS)[number];
|
|
42
|
+
|
|
35
43
|
export declare const ANALYSIS_COLUMN_TYPES: {
|
|
36
44
|
NORMAL: string;
|
|
37
45
|
FORMULA: string;
|
|
@@ -199,6 +207,18 @@ export declare type DeepPartial<T> = {
|
|
|
199
207
|
[P in keyof T]?: DeepPartial<T[P]>;
|
|
200
208
|
};
|
|
201
209
|
|
|
210
|
+
/**
|
|
211
|
+
* Used by core to mark a slot as deprecated.
|
|
212
|
+
*/
|
|
213
|
+
export declare const DEPRECATED_UI_SLOTS: readonly [];
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Used by core to map deprecated UI slots to supported UI slots.
|
|
217
|
+
*/
|
|
218
|
+
export declare const DEPRECATED_UI_TO_SUPPORTED_UI_SLOTS: Record<DeprecatedUISlot, SupportedUISlot>;
|
|
219
|
+
|
|
220
|
+
export declare type DeprecatedUISlot = (typeof DEPRECATED_UI_SLOTS)[number];
|
|
221
|
+
|
|
202
222
|
declare interface Display {
|
|
203
223
|
isVisible: boolean;
|
|
204
224
|
}
|
|
@@ -424,6 +444,7 @@ export declare class NMRiumCore {
|
|
|
424
444
|
readNMRiumObject(nmriumObjectInput: object, options?: ParsingOptions): Promise<Partial<NmriumState>>;
|
|
425
445
|
readFromWebSource(source: Source, options?: ParsingOptions): Promise<Partial<NmriumState>>;
|
|
426
446
|
serializeNmriumState(nmriumState: NmriumState, options?: SerializeNmriumStateOptions): SerializedNmriumState;
|
|
447
|
+
slot(slot: SupportedUISlot): IteratorObject<[pluginId: string, Component: PluginUIComponent], void>;
|
|
427
448
|
}
|
|
428
449
|
|
|
429
450
|
export declare interface NmriumData extends BaseNmriumData {
|
|
@@ -470,6 +491,49 @@ export declare interface NMRiumPlugin {
|
|
|
470
491
|
version: number;
|
|
471
492
|
migrations: NMRiumPluginMigration[];
|
|
472
493
|
onReadProcess?: NMRiumPluginOnReadProcess;
|
|
494
|
+
/**
|
|
495
|
+
* UI components to render in nmrium components
|
|
496
|
+
*
|
|
497
|
+
* @example
|
|
498
|
+
* ```tsx
|
|
499
|
+
* const MyPluginContext = createContext();
|
|
500
|
+
*
|
|
501
|
+
* function MyPluginProvider({children}) {
|
|
502
|
+
* const api = useMemo(() => ({ saveAction: () => console.log('save') }), []);
|
|
503
|
+
*
|
|
504
|
+
* return (
|
|
505
|
+
* <MyPluginContext.Provider value={api}>
|
|
506
|
+
* {children}
|
|
507
|
+
* </MyPluginContext.Provider>
|
|
508
|
+
* )
|
|
509
|
+
* }
|
|
510
|
+
*
|
|
511
|
+
* function MyPluginTopBar() {
|
|
512
|
+
* const ctx = useContext(MyPluginContext);
|
|
513
|
+
*
|
|
514
|
+
* return (
|
|
515
|
+
* <Button onClick={ctx.saveAction}>Save (My Plugin)</Button>
|
|
516
|
+
* )
|
|
517
|
+
* }
|
|
518
|
+
*
|
|
519
|
+
* const core = init();
|
|
520
|
+
* core.registerPlugin({
|
|
521
|
+
* id: 'my-plugin',
|
|
522
|
+
* version: 1,
|
|
523
|
+
* migrations: [],
|
|
524
|
+
* ui: {
|
|
525
|
+
* 'topbar.right': MyPluginTopBar,
|
|
526
|
+
* },
|
|
527
|
+
* });
|
|
528
|
+
*
|
|
529
|
+
* createRoot(document.getElementById('root')).render(
|
|
530
|
+
* <MyPluginProvider>
|
|
531
|
+
* <NMRium core={core} />
|
|
532
|
+
* </MyPluginProvider>
|
|
533
|
+
* );
|
|
534
|
+
* ```
|
|
535
|
+
* */
|
|
536
|
+
ui?: PluginUIComponentRegistry;
|
|
473
537
|
}
|
|
474
538
|
|
|
475
539
|
export declare interface NMRiumPluginMigration {
|
|
@@ -671,6 +735,18 @@ export declare interface PeaksViewState {
|
|
|
671
735
|
displayingMode: 'spread' | 'single';
|
|
672
736
|
}
|
|
673
737
|
|
|
738
|
+
export declare type PluginUIComponent = (props: PluginUIComponentProps) => ReactNode;
|
|
739
|
+
|
|
740
|
+
export declare type PluginUIComponentProps = PluginUIComponentTopBarRightProps;
|
|
741
|
+
|
|
742
|
+
export declare type PluginUIComponentRegistry = Partial<Record<AllowedUISlot, PluginUIComponent>>;
|
|
743
|
+
|
|
744
|
+
export declare interface PluginUIComponentSlotProps<Slot extends AllowedUISlot> {
|
|
745
|
+
slot: Slot;
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
export declare type PluginUIComponentTopBarRightProps = PluginUIComponentSlotProps<'topbar.right'>;
|
|
749
|
+
|
|
674
750
|
declare type PosibleInput = string | number | boolean;
|
|
675
751
|
|
|
676
752
|
declare type PredefinedLegend = 'intensity' | 'name';
|
|
@@ -944,6 +1020,21 @@ export declare interface SumOptions {
|
|
|
944
1020
|
moleculeId?: string;
|
|
945
1021
|
}
|
|
946
1022
|
|
|
1023
|
+
/**
|
|
1024
|
+
* Used by nmrium components to render plugin ui components
|
|
1025
|
+
* Naming convention is `snake_case.scope.slot_name`.
|
|
1026
|
+
* Constraint to doesn't break camelCase when declaring slot in plugin ui props:
|
|
1027
|
+
* do not use single `top_level_scope` (no dot, no underscore).
|
|
1028
|
+
*/
|
|
1029
|
+
export declare const SUPPORTED_UI_SLOTS: readonly ["topbar.right"];
|
|
1030
|
+
|
|
1031
|
+
/**
|
|
1032
|
+
* Cache inverted relationship between deprecated and supported.
|
|
1033
|
+
*/
|
|
1034
|
+
export declare const SUPPORTED_UI_TO_DEPRECATED_UI_SLOTS: Partial<Record<SupportedUISlot, DeprecatedUISlot[]>>;
|
|
1035
|
+
|
|
1036
|
+
export declare type SupportedUISlot = (typeof SUPPORTED_UI_SLOTS)[number];
|
|
1037
|
+
|
|
947
1038
|
export declare type Unit = UnitElement['unit'];
|
|
948
1039
|
|
|
949
1040
|
declare type UnitElement = (typeof units)[number];
|
package/dist/nmrium-core.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
1
|
+
var ce={NORMAL:"NORMAL",FORMULA:"FORMULA"};var ue={RELATIVE:"relative",ABSOLUTE:"absolute",MIN:"min",MAX:"max"};var me=[{name:"pixels",unit:"px"},{name:"inches",unit:"in"},{name:"feet",unit:"ft"},{name:"yards",unit:"yd"},{name:"centimeters",unit:"cm"},{name:"millimeters",unit:"mm"},{name:"meters",unit:"m"},{name:"points",unit:"pt"},{name:"picas",unit:"pc"}];var P=9;var fe=[{key:"CT",description:"CT from NMR Solutions"}];import{isAnyArray as de}from"is-any-array";import{xMultiply as k}from"ml-spectra-processing";var ge=crypto.randomUUID.bind(crypto),b=ge;function N(e){let{id:t=b(),meta:o,peaks:r={},filters:n=[],info:s={},ranges:c={},integrals:i={},selector:a,dependentVariables:l=[],...u}=e,p={id:t,meta:o,filters:n},{data:d=Se(l[0].components)}=e;if(Array.isArray(s.nucleus)&&(s.nucleus=s.nucleus[0]),p.data={x:[],re:[],im:[],...d},"scaleFactor"in s){let{scaleFactor:m}=s,{re:g,im:S}=p.data;k(g,m,{output:g}),S&&k(S,m,{output:S})}a&&(p.selector=a);let f=de(d.im);if(p.info={phc0:0,phc1:0,nucleus:"1H",isFid:!1,isComplex:f,dimension:1,name:s?.name||t,...s},s.isFid&&s.reverse&&f){let{im:m}=p.data;k(m,-1,{output:m}),p.info.reverse=!1}return p.display={isVisible:!0,isPeaksMarkersVisible:!0,isRealSpectrumVisible:!0,isVisibleInDomain:!0,...e.display},p.peaks={values:[],options:{},...r},p.ranges={values:[],options:{sum:null,isSumConstant:!0,sumAuto:!0},...c},p.integrals={values:[],options:{},...i},{...u,...p}}function Se(e){let t=e[0]?.data?.x||[],o=e[0]?.data?.re||e[0]?.data?.y||[],r=e[0]?.data?.im||e[1]?.data?.y||null;return t.length>0&&t[0]>t[1]&&(t.reverse(),o.reverse(),r&&r.reverse()),{x:t,re:o,im:r}}import{matrixToArray as ye,xMinMaxValues as Pe,xNoiseSanPlot as xe}from"ml-spectra-processing";var j={z:[[]],minX:0,minY:0,maxX:0,maxY:0},be={re:j,im:j},Ne={rr:j};function O(e){let{id:t=b(),meta:o={},dependentVariables:r=[],info:n={},filters:s=[],zones:c=[],...i}=e,a={id:t,meta:o,filters:s};a.info={nucleus:["1H","1H"],isFid:!1,isComplex:!1,name:n?.name||b(),...n},a.originalInfo=structuredClone(a.info),a.display={isPositiveVisible:!0,isNegativeVisible:!0,isVisible:!0,dimension:2,...e.display,...e.display};let{data:l=r[0].components}=e;if(a.data={...a.info.isFid?be:Ne,...l},a.originalData=structuredClone(a.data),!("spectrumSize"in n)){let u=n.isFid?"re":"rr",p=a.data[u].z.length,d=p>0?a.data[u].z[0].length:0;a.info.spectrumSize=[d,p]}if(!n.isFid){let u=a.data.rr,p=ye(u.z),{positive:d,negative:f}=xe(p),{min:m,max:g}=Pe(p);a.data.rr={...u,minZ:m,maxZ:g},a.info.noise={positive:d,negative:f}}return a.zones={values:[],options:{},...c},{...i,...a}}import{xSequentialFillFromTo as De}from"ml-spectra-processing";import{isAnyArray as he}from"is-any-array";function L(e,t=0){if(he(e)){let o=e.at(t);if(o!==void 0)return o;throw new RangeError("An array with a index out of boundaries")}return e}var Oe=new Set(["t1ir","T1"]);function q(e){let t=[];for(let o of e){let{info:{pulseSequence:r,isFid:n}}=o,{data:s,info:c,meta:{vdlistValues:i=[]}}=o;if(!(r&&Oe.has(r))||i.length===0){t.push(o);continue}let l=n?"re":"rr",u={};for(let y in c)u[y]=L(c[y]);let{z:p,maxX:d,minX:f}=s[l],m=De({from:f,to:d,size:p[0].length}),[g,S]=Ie(o);for(let y=0;y<i.length;y++){let h={re:m,x:m};for(let D in s)h[Re(D)]=s[D].z.at(g*(y+S));t.push(N({data:h,info:{...u,name:`${u.name}_${i[y]}`,dimension:1,vd:i[y]}}))}}return t}function Re(e){return["rr","re"].includes(e)?"re":["im","ri","ir","ii"].includes(e)?"im":"x"}function Ie(e){let{meta:{PAGE:t}}=e,o=!0;if(t){let r=n=>Number.parseFloat(n.replace(/[F|T]1=/,""));o=r(t[0])>r(t[2])}return o?[-1,1]:[1,0]}var Ce=2,ve=1;function we(e){let{spectra:t=[],molecules:o}=e,r=[];for(let n of t){let{info:s}=n;switch(s.dimension){case ve:r.push(N(n));break;case Ce:r.push(O(n));break;default:throw new Error("dimension does not supported")}}return{molecules:o,spectra:q(r)}}function x(e,t){return JSON.parse(JSON.stringify(e),function(r,n){if(r in t){this[t[r]]=n;return}return n})}function U(e){if(e?.version===1)return e;let t={...e,version:1},o={j:"js",signal:"signals",integral:"integration",peak:"peaks",diaID:"diaIDs"};for(let r of t.spectra){if(r.ranges){let n=x(r.ranges,o);r.ranges=Array.isArray(n)?{values:n}:n}else if(r.zones){let n=x(r.zones,o);r.zones=Array.isArray(n)?{values:n}:n}r.peaks&&(r.peaks=Array.isArray(r.peaks)?{values:r.peaks}:r.peaks),r.integrals&&(r.integrals=Array.isArray(r.integrals)?{values:r.integrals}:r.integrals)}return t}function V(e){if(e?.version===2)return e;let t={...e,version:2},o={peaks:{delta:"x",originDelta:"originalX",intensity:"y"},ranges:{atomIDs:"atoms",intensity:"y"}};for(let r of t.spectra)r.peaks?r.peaks=x(r.peaks,o.peaks):r.ranges?r.ranges=x(r.ranges,o.ranges):r.zones&&(r.zones.values=Te(r.zones.values));return t}function Te(e){return e.map(t=>(t.signals&&(t.signals=t.signals.map(o=>{if(o.x&&o.y){let{x:{fromTo:r,...n},y:{fromTo:s,...c}}=o;o={...o,x:{...n,...r},y:{...c,...s}}}else{let{fromTo:r,deltaX:n,resolutionX:s,nucleusX:c,deltaY:i,resolutionY:a,nucleusY:l,shiftX:u,shiftY:p,...d}=o;o={...d,x:{from:r[0].from,to:r[0].to,delta:n,resolution:s,nucleus:c},y:{from:r[1].from,to:r[1].to,delta:i,resolution:a,nucleus:l}}}return o},[])),t),[])}var Ae={name:"apodization",label:"Apodization",value:{lineBroadening:1,gaussBroadening:0,lineBroadeningCenter:0}};function _(e){if(e?.version===3)return e;let t={...e,version:3};for(let o of t.spectra)if(Array.isArray(o?.filters)&&o?.filters.length>0){let r=o.filters.findIndex(n=>n.name==="lineBroadening");if(r!==-1){let n={...o.filters[r],...Ae};o.filters[r]=o.filters[r-1],o.filters[r-1]=n}}return t}function z(e){if(e?.version===4)return e;let{version:t,...o}=e,r=[],n={};for(let{source:i,...a}of o.spectra){let l={},{info:u={},display:p={}}=a;if(u?.dimension===2&&!i?.jcampURL)if(u.isFt)l.data={rr:a.data};else continue;if(i?.jcampURL){let{jcampURL:m,jcampSpectrumIndex:g}=i,S=m.match(/(?<baseURL>^\w+:\/{2}\w+\/)(?<relativePath>.*)/);n[m]||(n[m]={baseURL:S?.groups.baseURL||"",relativePath:S?.groups.relativePath||m.replace(/^\.\//,"")}),l.sourceSelector={files:[n[m].relativePath]},g!==void 0&&(l.sourceSelector.jcamp={index:g})}l.filters=Fe(a.filters);let{name:d,...f}=p;d&&(l.info={...u,name:d}),l.display=f,r.push({...a,...l})}let s={data:{...o,spectra:r},version:4},c={entries:Object.values(n)};return c.entries.length>0&&(s.data.source=c),s}function Fe(e=[]){let t=[];for(let o of e){let{name:r,value:n}=o;switch(r){case"zeroFilling":t.push({...o,value:{nbPoints:n}});break;case"shiftX":case"shift2DX":case"shift2DY":t.push({...o,value:{shift:n}});break;default:t.push({...o})}}return t}function B(e){if(e?.version===5)return e;let t={...e,version:5},o={originFrom:"originalFrom",originTo:"originalTo",originDelta:"originalDelta",originX:"originalX",originY:"originalY",originZ:"originalZ"};for(let r of t?.data?.spectra||[])for(let n of["peaks","ranges","zones"])r?.[n]&&(r[n]=x(r[n],o));return t}function K(e){if(e?.version===6)return e;let t={...e,version:6};for(let o of t?.data?.spectra||[]){let{digitalFilter:r,fft:n,phaseCorrection:s}=Ee(o);n?.flag&&r?.flag&&s&&Math.floor(r.value.digitalFilterValue)%2>0&&(s.value.ph0-=180)}return t}function Ee(e,t=["phaseCorrection","fft","digitalFilter"]){let{filters:o=[]}=e,r={};for(let n of t)r[n]=o.find(s=>s.name===n);return r}function R(e,t="localStorage"){if(e?.version===7)return e;if(t==="nmrium")return J(e);let o={...e,version:7};for(let r in e.workspaces)o.workspaces[r]=J(o.workspaces[r]);return o}function J(e){let{formatting:{nuclei:t,panels:o}={nuclei:null,panels:null},version:r,...n}=e,s={...n};return t&&(s.nuclei=Me(t)),o&&(s.panels=o),s}function Me(e){let t=[],o={name:"nucleus",ppm:"ppmFormat",hz:"hzFormat"};for(let r in e)t.push(x(e[r],o));return t}function X(e){if(e?.version===7)return e;let t={...e,version:7};return t?.settings&&(t.settings=R(t.settings,"nmrium")),t}function I(e,t="localStorage"){if(e?.version===8)return e;if(t==="nmrium")return H(e);let o={...e,version:8};for(let r in e.workspaces)o.workspaces[r]=H(o.workspaces[r]);return o}function H(e){let{version:t,...o}=e,r={...o};return r.display.panels=ke(e),r}function ke(e){let t={},o=e.display.panels;for(let r of Object.keys(o)){let{display:n,open:s}=o[r];t[r]={display:n,visible:n,open:s}}return t}function Y(e){if(e?.version===8)return e;let t={...e,version:8};t?.settings&&(t.settings=I(t.settings,"nmrium"));for(let o of t?.data?.spectra||[]){let{filters:r=[]}=o;for(let i=0;i<r.length;i++){let{flag:a,isDeleteAllow:l,label:u,...p}=r[i];r[i]={...p,enabled:a}}let n=r.findIndex(i=>i.name==="apodization");if(n!==-1){let i=r[n],{lineBroadening:a,gaussBroadening:l,lineBroadeningCenter:u}=i.value;i.value={exponential:{apply:!0,options:{lineBroadening:l>0?-a:a}}},l>0&&(i.value.gaussian={apply:!0,options:{lineBroadening:.6*l,lineBroadeningCenter:u}}),r[n]=i}let s=r.findIndex(i=>i.name==="apodizationDimension1"),c=r.findIndex(i=>i.name==="apodizationDimension2");if(s!==-1){let i=r[s],{shapes:a}=i.value.compose;i.value=Q(a)}if(c!==-1){let i=r[c],{shapes:a}=i.value.compose;i.value=Q(a)}}return t}function Q(e){let t={};for(let{shape:o}of e){let{kind:r,options:n}=o;if(r==="sineBell"){let{exponent:s,offset:c}=n,i=s===2?"sineSquare":"sineBell";t[i]={apply:!0,options:{offset:c}}}}return t}function W(e){let{version:t,plugins:o,...r}=e;return t===9?e:{version:9,plugins:{},...r}}var je=[U,V,_,z,B,K,X,Y,W];function ee(e,t,o){let r=structuredClone(e),n=Object.entries(e?.plugins??{});for(let[i,{version:a}]of n){let l=o.get(i);if(!(l&&l.version>=a)){if(l){console.warn(`Plugin "${l.id}" is loaded with a version older (${l.version}) than the one used to save the state (${a}).
|
|
2
2
|
NMRium may fail to load the state.
|
|
3
3
|
Please update the plugin to the latest version.`);continue}console.warn(`Plugin "${i}@${a}" is not registered. NMRium may fail to load the state.
|
|
4
|
-
Please consider open this file with the plugin installed.`)}}let s=new Set,
|
|
4
|
+
Please consider open this file with the plugin installed.`)}}let s=new Set,c=()=>{let i=r.version;for(let a of o.values())for(let l of a.migrations){if(s.has(l)||i<l.minCore||l.maxCore&&i>l.maxCore)continue;if((r.plugins?.[a.id]?.version||0)===a.version)break;r=l.up(r),s.add(l)}};for(let i=e?.version||0;i<t;i++){let a=je[i];r=a(r),c()}c(),r.plugins||(r.plugins={});for(let i of o.values())r.plugins?.[i.id]||(r.plugins[i.id]={id:i.id,version:i.version}),r.plugins[i.id].id=i.id,r.plugins[i.id].version=i.version;return r}import{FileCollection as Ye}from"file-collection";var te={SDF:"sdf",MOL:"mol",NMRIUM:"nmrium",JSON:"json",JCAMP:"jcamp",DX:"dx",JDX:"jdx",JDF:"jdf",NMREDATA:"nmredata",SMILES:"smiles",SMI:"smi"};function C(e){return e.includes(".")?e.replace(/^.*\./,"").toLowerCase():""}function w(e,t={},o){let{data:r,...n}=e;if(!r)return e;let{spectra:s=[]}=r,{keep1D:c=!0,keep2D:i=!0,onlyReal:a}=t,l=a?"ft":t.dataSelection||"both",u=[];for(let p of s){if(!p.info){u.push(p);continue}let{isFid:d,dimension:f,name:m}=p.info;if(!v(f===1&&!c,m,o)&&!v(f===2&&!i,m,o)&&!v(d&&l==="ft",m,o)&&!v(!d&&l==="fid",m,o))if(a&&!d)if(p.info.isComplex=!1,Le(p)){let{rr:g}=p.data;u.push({...p,data:{rr:g}})}else{let{re:g,x:S}=p.data;u.push({...p,data:{re:g,x:S}})}else u.push(p)}return{data:{...r,spectra:u},...n}}function v(e,t,o){return e?(o?.warn(`Skipping ${t} because it didn't match the import filters.`),!0):!1}function Le(e){let{info:t}=e;return t?.dimension===2}function T(e){let{nmriumState:t,plugins:o,options:r}=e;for(let n of o.values()){let s=n.onReadProcess?.onProcessing;s&&s(t,r)}}async function A(e,t,o={}){let{sourceSelector:r,converter:n,keepSource:s,logger:c}=o,i=[],a=[];for(let f of t.values()){let{onReadProcess:m}=f;m&&(m?.onFiles&&i.push(f),m?.supportedExtensions?.length&&m?.onFile&&a.push(f))}let l=await Promise.allSettled(i.map(f=>f.onReadProcess.onFiles(e,o))),u=[],p=await Promise.allSettled(e.files.flatMap(f=>{let m=C(f.name).toLowerCase();return a.flatMap(g=>{let{supportedExtensions:S,onFile:y}=g.onReadProcess;return S.includes(m)?(u.push({file:f,plugin:g}),y(f,{logger:c,sourceSelector:r,converter:n,keepSource:s})):[]})})),d={spectra:[],molecules:[]};for(let f=0;f<l.length;f++){let m=l[f];switch(m.status){case"fulfilled":{let{spectra:g=[],molecules:S=[]}=m.value||{};d.spectra.push(...g),d.molecules.push(...S);break}case"rejected":{let g=m.reason,S=i[f];o.logger?.error(`Load file collection with plugin ${S.id}@${S.version} fails with: ${g}`);break}}}for(let f=0;f<p.length;f++){let m=p[f];switch(m.status){case"fulfilled":{let{spectra:g=[],molecules:S=[]}=m.value||{};d.spectra.push(...g),d.molecules.push(...S);break}case"rejected":{let g=m.reason,{file:S,plugin:y}=u[f];o.logger?.error(`Load file ${S.relativePath} with plugin ${y.id}@${y.version} fails with: ${g}`);break}}}return d}import{FileCollection as Be}from"file-collection";import{FileCollection as Ue}from"file-collection";import re from"lodash.merge";import{xIsEquallySpaced as Ve}from"ml-spectra-processing";async function F(e){let{nmriumObjectInput:t,options:o={},migrator:r,plugins:n}=e,s=r(t),{data:c,...i}=s;if(!c)return{...i};let a={data:{...c,spectra:[]},...i},l=a.data,{source:u,spectra:p,molecules:d}=l,f;u&&(f=await Ue.fromSource(u,{unzip:{zipExtensions:["zip","nmredata"]}}));let m=[];for(let g of c.spectra)if(f){let{sourceSelector:S}=g,y=E({input:f,migrator:r,plugins:n,options:{...o,sourceSelector:S}}).then(h=>{let{nmriumState:{data:D}}=h,{spectra:le=[],molecules:Z=[]}=D||{};Z.length>0&&d.length===0&&d.push(...Z);for(let pe of le)p.push(_e(g,ze(pe)))});m.push(y)}else{let{dimension:S}=g.info;if(S===1){if(!Ve(g.data)){o.logger?.error('The ".nmrium" file is corrupted; the X-axis values are not equally distant.');continue}p.push(N(g))}else S===2&&p.push(O(g))}return await Promise.allSettled(m),a}function _e(e,t){let{data:o,...r}=e;if("ranges"in t){let{data:n,...s}=t;return{...re(s,r),data:n}}else if("zones"in t){let{data:n,...s}=t;return{...re(s,r),data:n}}else return t}function ze(e){return{...e,id:b()}}async function oe(e){let{file:t,options:o={},migrator:r,plugins:n}=e,s=await t.arrayBuffer(),c=await(Xe(s)?Ke(s):t.text());return F({nmriumObjectInput:JSON.parse(c),plugins:n,migrator:r,options:o})}async function Ke(e){let t=await Be.fromZip(e);if(t.files.length===0)throw new Error("compressed nmrium file is corrupted");return t.files[0].text()}function Xe(e){if(e.byteLength<4)return!1;let t=new Uint8Array(e);return t[0]===80&&t[1]===75&&(t[2]===3||t[2]===5||t[2]===7)&&(t[3]===4||t[3]===6||t[3]===8)}async function E(e){let{options:t={},input:o,migrator:r,plugins:n}=e,s=Ge(await We(o),t.sourceSelector?.files),c=Ze(s);if(c)return{nmriumState:await oe({file:c,migrator:r,plugins:n,options:t}),containsNmrium:!0};let i=await A(s,n,t),a=w({version:9,data:i},t?.sourceSelector?.general,t.logger),{onLoadProcessing:l,experimentalFeatures:u}=t,p={...l,autoProcessing:l?.autoProcessing??!1,experimentalFeatures:u};return T({nmriumState:a,plugins:n,options:p}),{nmriumState:a,containsNmrium:!1}}function We(e){return Array.isArray(e)?Promise.reject(new Error("For a set of fileCollectionItems pass a FileCollection instance")):$e(e)?Promise.resolve(e):new Ye().appendExtendedSource({...e,uuid:crypto.randomUUID()})}function $e(e){return typeof e=="object"&&"files"in e}function Ge(e,t){if(!t)return e;let o=new Set(t);return e.filter(r=>o.has(r.relativePath))}function Ze(e){return e.files.find(t=>C(t.name).toLowerCase()===te.NMRIUM)}function M(e,t){let o={};for(let r in e)t.includes(r)||(o[r]=e[r]);return o}var qe=["data","originalData","info","originalInfo","meta","customInfo"],Je=["sourceSelector","originalData","originalInfo"];function ne(e,t={}){let{version:o,data:r}=e;if(r.actionType)return e;let n={version:o,plugins:e.plugins},{includeData:s}=t;s!=="noData"&&(n.data=He({...r},s));let{includeSettings:c,includeView:i}=t;return c&&(n.settings=e.settings),i&&(n.view=e.view),n}function He(e,t="rawData"){let{spectra:o}=e;switch(t){case"dataSource":return Qe(e);case"rawData":return{...M(e,["source"]),spectra:o.map(tt)};default:return e}}function Qe(e){let{spectra:t}=e;if(!e.source)throw new Error("source property should exists for dataSource serialization");return{...e,spectra:t.map(et)}}function et(e){return M(e,qe)}function tt(e){let{data:t,info:o,originalData:r,originalInfo:n}=e,s=M(e,Je);return s.data=r||t,s.info=n||o,s}var rt=["topbar.right"],ot=[],Xr=[...rt,...ot],nt={},$={};{let e=nt,t=$;for(let[o,r]of Object.entries(e))t[r]||(t[r]=[]),t[r]?.push(o)}function*ie(e){let{slot:t,plugins:o,supportedToDeprecatedSlots:r=$}=e,n=r[t];for(let[s,c]of o.entries()){let i=c.ui;if(!i)continue;let a=i[t];if(a){yield[s,a];continue}if(n)for(let l of n){let u=c.ui?.[l];if(u){yield[s,u],console.warn(`Plugin ${c.id} used deprecated slot "${l}". Please update this plugin to use "${t}" instead.`);break}}}}import{FileCollection as it}from"file-collection";async function se(e){let{source:t,plugins:o,options:r={}}=e,{keepSource:n=!0,converter:s,...c}=r,i={source:t,spectra:[],molecules:[]},a=await it.fromSource(t,{unzip:{zipExtensions:["zip","nmredata"]}}),{spectra:l=[],molecules:u=[]}=await A(a,o,{keepSource:n,converter:{...s,bruker:{keepFiles:!0,...Reflect.get(s??{},"bruker")}},...c});i.spectra.push(...l),i.molecules.push(...u);let p=w({version:9,data:i},r?.sourceSelector?.general),{onLoadProcessing:d}=c,f={filters:d?.filters,autoProcessing:d?.autoProcessing??!1,experimentalFeatures:r.experimentalFeatures};return T({nmriumState:p,plugins:o,options:f}),p}var G=class{version=9;plugins=new Map;registerPlugin(t){if(this.plugins.has(t.id)){console.warn(`Plugin ${t.id} is already registered. skip.`),console.debug("Plugin already registered:",this.plugins.get(t.id)),console.debug("Plugin to register:",t);return}this.plugins.set(t.id,t)}registerPlugins(t){for(let o of t)this.registerPlugin(o)}migrate(t){return ee(t,this.version,this.plugins)}read(t,o={}){return E({input:t,migrator:this.migrate.bind(this),plugins:this.plugins,options:o})}readNMRiumObject(t,o){return F({nmriumObjectInput:t,options:o,plugins:this.plugins,migrator:this.migrate.bind(this)})}readFromWebSource(t,o){return se({source:t,options:o,plugins:this.plugins})}serializeNmriumState(t,o){return ne(t,o)}slot(t){return ie({slot:t,plugins:this.plugins})}};function st(e,t){if(t>9)return 0;let o=-1;for(let r=0;r<e.length;r++)if(e[r].version>t){o=r;break}return o}var ae=[{version:6,fun:R},{version:7,fun:I}];function at(e){let{version:t}=e||{},o=st(ae,t);if(o===-1)return{...e,version:9};let r=ae.slice(o);for(let n of r)e=n.fun(e);return e}export{ce as ANALYSIS_COLUMN_TYPES,ue as ANALYSIS_COLUMN_VALUES_KEYS,P as CURRENT_EXPORT_VERSION,fe as EXTERNAL_API_KEYS,G as NMRiumCore,we as formatSpectra,b as generateID,L as getOneIfArray,at as migrateSettings,me as units};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zakodium/nmrium-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "The core of NMRium: types, state, state migration and plugin system.",
|
|
5
5
|
"author": "Zakodium Sàrl",
|
|
6
6
|
"license": "CC-BY-NC-SA-4.0",
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@types/lodash.merge": "^4.6.9",
|
|
27
27
|
"@types/node": "^24.0.14",
|
|
28
|
+
"@types/react": "^18.3.13",
|
|
28
29
|
"@zakodium/nmr-types": "^0.1.0",
|
|
29
30
|
"esbuild": "^0.25.5",
|
|
30
31
|
"jest-matcher-deep-close-to": "^3.0.2",
|
|
@@ -34,7 +35,7 @@
|
|
|
34
35
|
"dependencies": {
|
|
35
36
|
"cheminfo-types": "^1.8.1",
|
|
36
37
|
"fifo-logger": "^2.0.0",
|
|
37
|
-
"file-collection": "^5.
|
|
38
|
+
"file-collection": "^5.1.0",
|
|
38
39
|
"is-any-array": "^2.0.1",
|
|
39
40
|
"lodash.merge": "^4.6.2",
|
|
40
41
|
"ml-spectra-processing": "^14.12.0",
|