@zakodium/nmrium-core 0.4.10 → 0.4.12
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 +37 -3
- package/dist/nmrium-core.js +5 -5
- package/package.json +9 -9
package/dist/nmrium-core.d.ts
CHANGED
|
@@ -500,10 +500,38 @@ export declare class NMRiumCore {
|
|
|
500
500
|
readonly version = 12;
|
|
501
501
|
registerPlugin(plugin: NMRiumPlugin): void;
|
|
502
502
|
registerPlugins(plugins: NMRiumPlugin[]): void;
|
|
503
|
-
|
|
504
|
-
|
|
503
|
+
migrate(state: any): any;
|
|
504
|
+
/**
|
|
505
|
+
* Try to read any kind of files to build a NMRiumState
|
|
506
|
+
*
|
|
507
|
+
* @param input
|
|
508
|
+
* @param options
|
|
509
|
+
* @param fromSourceOptions - Is used if `input` contains a NMRium file, as baseURL fallback
|
|
510
|
+
*/
|
|
511
|
+
read(input: FileCollection | FileItem, options?: Partial<ParsingOptions>, fromSourceOptions?: {
|
|
512
|
+
baseURL?: string;
|
|
513
|
+
}): ReturnType<typeof read>;
|
|
505
514
|
readNMRiumArchive(input: ZipFileContent, options?: Partial<ParsingOptions>): ReturnType<typeof readNMRiumArchive>;
|
|
506
|
-
|
|
515
|
+
/**
|
|
516
|
+
* Read a nmrium state, migrate it to the current version,
|
|
517
|
+
* fetch data from sources contained, and format spectra and molecules.
|
|
518
|
+
*
|
|
519
|
+
* @param nmriumObjectInput
|
|
520
|
+
* @param options
|
|
521
|
+
* @param fromSourceOptions - fallback baseURL for sources contained in `nmriumObjectInput`
|
|
522
|
+
*/
|
|
523
|
+
readNMRiumObject(nmriumObjectInput: object, options?: ParsingOptions, fromSourceOptions?: {
|
|
524
|
+
baseURL?: string;
|
|
525
|
+
}): ReturnType<typeof readNMRiumObject>;
|
|
526
|
+
/**
|
|
527
|
+
* Same than `readNMRiumObject` but from a file from `FileCollection`
|
|
528
|
+
* @param file - supports nmrium state file with any extension, compressed or not.
|
|
529
|
+
* @param options
|
|
530
|
+
* @param fromSourceOptions
|
|
531
|
+
*/
|
|
532
|
+
readNMRiumFile(file: FileItem, options?: Partial<ParsingOptions>, fromSourceOptions?: {
|
|
533
|
+
baseURL?: string;
|
|
534
|
+
}): ReturnType<typeof readNMRiumObject>;
|
|
507
535
|
readFromWebSource(source: Source, options?: ParsingOptions): Promise<[state: Partial<NmriumState>, fileCollection: FileCollection, selectorRoot: string]>;
|
|
508
536
|
/**
|
|
509
537
|
* Serialize a state to nmrium object.
|
|
@@ -1081,6 +1109,9 @@ declare interface ReadNMRiumObjectOptions {
|
|
|
1081
1109
|
migrator: (state: object) => any;
|
|
1082
1110
|
plugins: Map<string, NMRiumPlugin>;
|
|
1083
1111
|
options?: ParsingOptions;
|
|
1112
|
+
fromSourceOptions?: {
|
|
1113
|
+
baseURL?: string;
|
|
1114
|
+
};
|
|
1084
1115
|
}
|
|
1085
1116
|
|
|
1086
1117
|
declare type ReadNMRiumObjectReturn = [
|
|
@@ -1100,6 +1131,9 @@ declare interface ReadOptions {
|
|
|
1100
1131
|
migrator: (state: object) => any;
|
|
1101
1132
|
plugins: Map<string, NMRiumPlugin>;
|
|
1102
1133
|
options?: ParsingOptions;
|
|
1134
|
+
fromSourceOptions?: {
|
|
1135
|
+
baseURL?: string;
|
|
1136
|
+
};
|
|
1103
1137
|
}
|
|
1104
1138
|
|
|
1105
1139
|
declare interface ReadReturn {
|
package/dist/nmrium-core.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var Oe={NORMAL:"NORMAL",FORMULA:"FORMULA"};var Ie={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 x=12;var ve=[{key:"CT",description:"CT from NMR Solutions"}];import{isAnyArray as Ce}from"is-any-array";import{xMultiply as V}from"ml-spectra-processing";var De=crypto.randomUUID.bind(crypto),h=De;function b(e){let{id:t=h(),meta:o,peaks:r={},filters:n=[],info:i={},ranges:c={},integrals:s={},selector:l,sourceId:a,dependentVariables:p=[],...m}=e,u={id:t,meta:o,filters:n},{data:f=Ae(p[0].components)}=e;if(Array.isArray(i.nucleus)&&(i.nucleus=i.nucleus[0]),u.data={x:[],re:[],im:[],...f},"scaleFactor"in i){let{scaleFactor:g}=i,{re:y,im:S}=u.data;V(y,g,{output:y}),S&&V(S,g,{output:S})}l&&(u.selector=l),a&&(u.sourceId=a,u.fileCollectionId=a);let d=Ce(f.im);if(u.info={phc0:0,phc1:0,nucleus:"1H",isFid:!1,isComplex:d,dimension:1,name:i?.name||t,...i},i.isFid&&i.reverse&&d){let{im:g}=u.data;V(g,-1,{output:g}),u.info.reverse=!1}return u.display={isVisible:!0,isPeaksMarkersVisible:!0,isRealSpectrumVisible:!0,isVisibleInDomain:!0,...e.display},u.peaks={values:[],options:{},...r},u.ranges={values:[],options:{sum:null,isSumConstant:!0,sumAuto:!0},...c},u.integrals={values:[],options:{},...s},{...m,...u}}function Ae(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 we,xMinMaxValues as Fe,xNoiseSanPlot as Te}from"ml-spectra-processing";var _={z:[[]],minX:0,minY:0,maxX:0,maxY:0},Ee={re:_,im:_},Le={rr:_};function v(e){let{id:t=h(),meta:o={},dependentVariables:r=[],info:n={},filters:i=[],zones:c=[],sourceId:s,...l}=e,a={id:t,meta:o,filters:i};s&&(a.sourceId=s,a.fileCollectionId=s),a.info={nucleus:["1H","1H"],isFid:!1,isComplex:!1,name:n?.name||h(),...n},a.originalInfo=structuredClone(a.info),a.display={isPositiveVisible:!0,isNegativeVisible:!0,isVisible:!0,dimension:2,...e.display,...e.display};let{data:p=r[0].components}=e;if(a.data={...a.info.isFid?Ee:Le,...p},a.originalData=structuredClone(a.data),!("spectrumSize"in n)){let m=n.isFid?"re":"rr",u=a.data[m].z.length,f=u>0?a.data[m].z[0].length:0;a.info.spectrumSize=[f,u]}if(!n.isFid){let m=a.data.rr,u=we(m.z),{positive:f,negative:d}=Te(u),{min:g,max:y}=Fe(u);a.data.rr={...m,minZ:g,maxZ:y},a.info.noise={positive:f,negative:d}}return a.zones={values:[],options:{},...c},{...l,...a}}import{xSequentialFillFromTo as Ue}from"ml-spectra-processing";import{isAnyArray as ke}from"is-any-array";function B(e,t=0){if(ke(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 je=new Set(["t1ir","T1"]);function oe(e){let t=[];for(let o of e){let{info:{pulseSequence:r,isFid:n}}=o,{data:i,info:c,meta:{vdlistValues:s=[]}}=o;if(!(r&&je.has(r))||s.length===0){t.push(o);continue}let a=n?"re":"rr",p={};for(let S in c)p[S]=B(c[S]);let{z:m,maxX:u,minX:f}=i[a],d=Ue({from:f,to:u,size:m[0].length}),[g,y]=Ve(o);for(let S=0;S<s.length;S++){let P={re:d,x:d};for(let O in i)P[ze(O)]=i[O].z.at(g*(S+y));t.push(b({data:P,info:{...p,name:`${p.name}_${s[S]}`,dimension:1,vd:s[S]}}))}}return t}function ze(e){return["rr","re"].includes(e)?"re":["im","ri","ir","ii"].includes(e)?"im":"x"}function Ve(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 _e=2,Be=1;function Ke(e){let{spectra:t=[],molecules:o}=e,r=[];for(let n of t){let{info:i}=n;switch(i.dimension){case Be:r.push(b(n));break;case _e:r.push(v(n));break;default:throw new Error("dimension does not supported")}}return{molecules:o,spectra:oe(r)}}function We(e){return e}function N(e,t){return JSON.parse(JSON.stringify(e),function(r,n){if(r in t){this[t[r]]=n;return}return n})}function K(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=N(r.ranges,o);r.ranges=Array.isArray(n)?{values:n}:n}else if(r.zones){let n=N(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 W(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=N(r.peaks,o.peaks):r.ranges?r.ranges=N(r.ranges,o.ranges):r.zones&&(r.zones.values=Xe(r.zones.values));return t}function Xe(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:i,...c}}=o;o={...o,x:{...n,...r},y:{...c,...i}}}else{let{fromTo:r,deltaX:n,resolutionX:i,nucleusX:c,deltaY:s,resolutionY:l,nucleusY:a,shiftX:p,shiftY:m,...u}=o;o={...u,x:{from:r[0].from,to:r[0].to,delta:n,resolution:i,nucleus:c},y:{from:r[1].from,to:r[1].to,delta:s,resolution:l,nucleus:a}}}return o},[])),t),[])}var Ye={name:"apodization",label:"Apodization",value:{lineBroadening:1,gaussBroadening:0,lineBroadeningCenter:0}};function X(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],...Ye};o.filters[r]=o.filters[r-1],o.filters[r-1]=n}}return t}function Y(e){if(e?.version===4)return e;let{version:t,...o}=e,r=[],n={};for(let{source:s,...l}of o.spectra){let a={},{info:p={},display:m={}}=l;if(p?.dimension===2&&!s?.jcampURL)if(p.isFt)a.data={rr:l.data};else continue;if(s?.jcampURL){let{jcampURL:d,jcampSpectrumIndex:g}=s,y=d.match(/(?<baseURL>^\w+:\/{2}\w+\/)(?<relativePath>.*)/);n[d]||(n[d]={baseURL:y?.groups.baseURL||"",relativePath:y?.groups.relativePath||d.replace(/^\.\//,"")}),a.sourceSelector={files:[n[d].relativePath]},g!==void 0&&(a.sourceSelector.jcamp={index:g})}a.filters=$e(l.filters);let{name:u,...f}=m;u&&(a.info={...p,name:u}),a.display=f,r.push({...l,...a})}let i={data:{...o,spectra:r},version:4},c={entries:Object.values(n)};return c.entries.length>0&&(i.data.source=c),i}function $e(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 $(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]=N(r[n],o));return t}function Z(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:i}=Ze(o);n?.flag&&r?.flag&&i&&Math.floor(r.value.digitalFilterValue)%2>0&&(i.value.ph0-=180)}return t}function Ze(e,t=["phaseCorrection","fft","digitalFilter"]){let{filters:o=[]}=e,r={};for(let n of t)r[n]=o.find(i=>i.name===n);return r}function D(e,t="localStorage"){if(e?.version===7)return e;if(t==="nmrium")return ne(e);let o={...e,version:7};for(let r in e.workspaces)o.workspaces[r]=ne(o.workspaces[r]);return o}function ne(e){let{formatting:{nuclei:t,panels:o}={nuclei:null,panels:null},version:r,...n}=e,i={...n};return t&&(i.nuclei=Ge(t)),o&&(i.panels=o),i}function Ge(e){let t=[],o={name:"nucleus",ppm:"ppmFormat",hz:"hzFormat"};for(let r in e)t.push(N(e[r],o));return t}function G(e){if(e?.version===7)return e;let t={...e,version:7};return t?.settings&&(t.settings=D(t.settings,"nmrium")),t}function C(e,t="localStorage"){if(e?.version===8)return e;if(t==="nmrium")return ie(e);let o={...e,version:8};for(let r in e.workspaces)o.workspaces[r]=ie(o.workspaces[r]);return o}function ie(e){let{version:t,...o}=e,r={...o};return r.display.panels=qe(e),r}function qe(e){let t={},o=e.display.panels;for(let r of Object.keys(o)){let{display:n,open:i}=o[r];t[r]={display:n,visible:n,open:i}}return t}function q(e){if(e?.version===8)return e;let t={...e,version:8};t?.settings&&(t.settings=C(t.settings,"nmrium"));for(let o of t?.data?.spectra||[]){let{filters:r=[]}=o;for(let s=0;s<r.length;s++){let{flag:l,isDeleteAllow:a,label:p,...m}=r[s];r[s]={...m,enabled:l}}let n=r.findIndex(s=>s.name==="apodization");if(n!==-1){let s=r[n],{lineBroadening:l,gaussBroadening:a,lineBroadeningCenter:p}=s.value;s.value={exponential:{apply:!0,options:{lineBroadening:a>0?-l:l}}},a>0&&(s.value.gaussian={apply:!0,options:{lineBroadening:.6*a,lineBroadeningCenter:p}}),r[n]=s}let i=r.findIndex(s=>s.name==="apodizationDimension1"),c=r.findIndex(s=>s.name==="apodizationDimension2");if(i!==-1){let s=r[i],{shapes:l}=s.value.compose;s.value=se(l)}if(c!==-1){let s=r[c],{shapes:l}=s.value.compose;s.value=se(l)}}return t}function se(e){let t={};for(let{shape:o}of e){let{kind:r,options:n}=o;if(r==="sineBell"){let{exponent:i,offset:c}=n,s=i===2?"sineSquare":"sineBell";t[s]={apply:!0,options:{offset:c}}}}return t}function J(e){let{version:t,plugins:o,...r}=e;return t===9?e:{version:9,plugins:{},...r}}function H(e){if(e?.version>=10)return e;let t={...e,version:10};if(e.data){let{source:o,spectra:r,...n}=e.data,i=o?crypto.randomUUID():void 0,c=o?[{...o,id:i}]:[];t.data={...n,sources:c,spectra:o?r?.map(s=>({...s,sourceId:i})):r}}return t}function Q(e){let{version:t}=e;if(t>=11)return e;let o={...e,version:11};return e?.view?.molecules&&(o.view=Je(e.view)),o}function Je(e){let{molecules:t,...o}=e,r={};for(let[n,i]of Object.entries(t)){let{showAtomNumber:c,...s}=i;r[n]={...s,atomAnnotation:"none",showLabel:!1}}return{molecules:r,...o}}function ee(e){if(e?.version>=12)return e;let t={...e,version:12};if(t.data){let o=e.data.spectra??[],r=e.data.molecules??[];for(let n of o){let{sourceId:i,fileCollectionId:c,sourceSelector:s}=n;delete n.sourceId,delete n.fileCollectionId,delete n.sourceSelector,s&&(n.selector={...s,root:c??i})}for(let n of r){let{sourceId:i,fileCollectionId:c,sourceSelector:s}=n;delete n.sourceId,delete n.fileCollectionId,delete n.sourceSelector,s&&(n.selector={...s,root:c??i})}}return t}function R(e,t){e.plugins||(e.plugins={});let o=e.plugins;for(let r of t.values()){if(!r.shouldSerialize){delete o[r.id];continue}o[r.id]||(o[r.id]={id:r.id,version:r.version}),o[r.id].id=r.id,o[r.id].version=r.version}}var He=[K,W,X,Y,$,Z,G,q,J,H,Q,ee];function ae(e,t,o){let r=structuredClone(e),n=Object.entries(e?.plugins??{});for(let[s,{version:l}]of n){let a=o.get(s);if(!(a&&a.version>=l)){if(a){console.warn(`Plugin "${a.id}" is loaded with a version older (${a.version}) than the one used to save the state (${l}).
|
|
1
|
+
var Me={NORMAL:"NORMAL",FORMULA:"FORMULA"};var ve={RELATIVE:"relative",ABSOLUTE:"absolute",MIN:"min",MAX:"max"};var De=[{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 N=12;var Ce=[{key:"CT",description:"CT from NMR Solutions"}];import{isAnyArray as we}from"is-any-array";import{xMultiply as B}from"ml-spectra-processing";var Ae=crypto.randomUUID.bind(crypto),R=Ae;function h(e){let{id:t=R(),meta:o,peaks:r={},filters:i=[],info:s={},ranges:c={},integrals:n={},selector:l,sourceId:a,dependentVariables:p=[],...m}=e,u={id:t,meta:o,filters:i},{data:f=Fe(p[0].components)}=e;if(Array.isArray(s.nucleus)&&(s.nucleus=s.nucleus[0]),u.data={x:[],re:[],im:[],...f},"scaleFactor"in s){let{scaleFactor:d}=s,{re:S,im:P}=u.data;B(S,d,{output:S}),P&&B(P,d,{output:P})}l&&(u.selector=l),a&&(u.sourceId=a,u.fileCollectionId=a);let g=we(f.im);if(u.info={phc0:0,phc1:0,nucleus:"1H",isFid:!1,isComplex:g,dimension:1,name:s?.name||t,...s},s.isFid&&s.reverse&&g){let{im:d}=u.data;B(d,-1,{output:d}),u.info.reverse=!1}return u.display={isVisible:!0,isPeaksMarkersVisible:!0,isRealSpectrumVisible:!0,isVisibleInDomain:!0,...e.display},u.peaks={values:[],options:{},...r},u.ranges={values:[],options:{sum:null,isSumConstant:!0,sumAuto:!0},...c},u.integrals={values:[],options:{},...n},{...m,...u}}function Fe(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 Te,xMinMaxValues as Ee,xNoiseSanPlot as Le}from"ml-spectra-processing";var K={z:[[]],minX:0,minY:0,maxX:0,maxY:0},Ue={re:K,im:K},ke={rr:K};function D(e){let{id:t=R(),meta:o={},dependentVariables:r=[],info:i={},filters:s=[],zones:c=[],sourceId:n,...l}=e,a={id:t,meta:o,filters:s};n&&(a.sourceId=n,a.fileCollectionId=n),a.info={nucleus:["1H","1H"],isFid:!1,isComplex:!1,name:i?.name||R(),...i},a.originalInfo=structuredClone(a.info),a.display={isPositiveVisible:!0,isNegativeVisible:!0,isVisible:!0,dimension:2,...e.display,...e.display};let{data:p=r[0].components}=e;if(a.data={...a.info.isFid?Ue:ke,...p},a.originalData=structuredClone(a.data),!("spectrumSize"in i)){let m=i.isFid?"re":"rr",u=a.data[m].z.length,f=u>0?a.data[m].z[0].length:0;a.info.spectrumSize=[f,u]}if(!i.isFid){let m=a.data.rr,u=Te(m.z),{positive:f,negative:g}=Le(u),{min:d,max:S}=Ee(u);a.data.rr={...m,minZ:d,maxZ:S},a.info.noise={positive:f,negative:g}}return a.zones={values:[],options:{},...c},{...l,...a}}import{xSequentialFillFromTo as ze}from"ml-spectra-processing";import{isAnyArray as je}from"is-any-array";function W(e,t=0){if(je(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 Ve=new Set(["t1ir","T1"]);function ne(e){let t=[];for(let o of e){let{info:{pulseSequence:r,isFid:i}}=o,{data:s,info:c,meta:{vdlistValues:n=[]}}=o;if(!(r&&Ve.has(r))||n.length===0){t.push(o);continue}let a=i?"re":"rr",p={};for(let P in c)p[P]=W(c[P]);let{z:m,maxX:u,minX:f}=s[a],g=ze({from:f,to:u,size:m[0].length}),[d,S]=Be(o);for(let P=0;P<n.length;P++){let y={re:g,x:g};for(let x in s)y[_e(x)]=s[x].z.at(d*(P+S));t.push(h({data:y,info:{...p,name:`${p.name}_${n[P]}`,dimension:1,vd:n[P]}}))}}return t}function _e(e){return["rr","re"].includes(e)?"re":["im","ri","ir","ii"].includes(e)?"im":"x"}function Be(e){let{meta:{PAGE:t}}=e,o=!0;if(t){let r=i=>Number.parseFloat(i.replace(/[F|T]1=/,""));o=r(t[0])>r(t[2])}return o?[-1,1]:[1,0]}var Ke=2,We=1;function Xe(e){let{spectra:t=[],molecules:o}=e,r=[];for(let i of t){let{info:s}=i;switch(s.dimension){case We:r.push(h(i));break;case Ke:r.push(D(i));break;default:throw new Error("dimension does not supported")}}return{molecules:o,spectra:ne(r)}}function Ye(e){return e}function b(e,t){return JSON.parse(JSON.stringify(e),function(r,i){if(r in t){this[t[r]]=i;return}return i})}function X(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 i=b(r.ranges,o);r.ranges=Array.isArray(i)?{values:i}:i}else if(r.zones){let i=b(r.zones,o);r.zones=Array.isArray(i)?{values:i}:i}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 Y(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=b(r.peaks,o.peaks):r.ranges?r.ranges=b(r.ranges,o.ranges):r.zones&&(r.zones.values=$e(r.zones.values));return t}function $e(e){return e.map(t=>(t.signals&&(t.signals=t.signals.map(o=>{if(o.x&&o.y){let{x:{fromTo:r,...i},y:{fromTo:s,...c}}=o;o={...o,x:{...i,...r},y:{...c,...s}}}else{let{fromTo:r,deltaX:i,resolutionX:s,nucleusX:c,deltaY:n,resolutionY:l,nucleusY:a,shiftX:p,shiftY:m,...u}=o;o={...u,x:{from:r[0].from,to:r[0].to,delta:i,resolution:s,nucleus:c},y:{from:r[1].from,to:r[1].to,delta:n,resolution:l,nucleus:a}}}return o},[])),t),[])}var Ze={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(i=>i.name==="lineBroadening");if(r!==-1){let i={...o.filters[r],...Ze};o.filters[r]=o.filters[r-1],o.filters[r-1]=i}}return t}function Z(e){if(e?.version===4)return e;let{version:t,...o}=e,r=[],i={};for(let{source:n,...l}of o.spectra){let a={},{info:p={},display:m={}}=l;if(p?.dimension===2&&!n?.jcampURL)if(p.isFt)a.data={rr:l.data};else continue;if(n?.jcampURL){let{jcampURL:g,jcampSpectrumIndex:d}=n,S=g.match(/(?<baseURL>^\w+:\/{2}\w+\/)(?<relativePath>.*)/);i[g]||(i[g]={baseURL:S?.groups.baseURL||"",relativePath:S?.groups.relativePath||g.replace(/^\.\//,"")}),a.sourceSelector={files:[i[g].relativePath]},d!==void 0&&(a.sourceSelector.jcamp={index:d})}a.filters=Ge(l.filters);let{name:u,...f}=m;u&&(a.info={...p,name:u}),a.display=f,r.push({...l,...a})}let s={data:{...o,spectra:r},version:4},c={entries:Object.values(i)};return c.entries.length>0&&(s.data.source=c),s}function Ge(e=[]){let t=[];for(let o of e){let{name:r,value:i}=o;switch(r){case"zeroFilling":t.push({...o,value:{nbPoints:i}});break;case"shiftX":case"shift2DX":case"shift2DY":t.push({...o,value:{shift:i}});break;default:t.push({...o})}}return t}function G(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 i of["peaks","ranges","zones"])r?.[i]&&(r[i]=b(r[i],o));return t}function q(e){if(e?.version===6)return e;let t={...e,version:6};for(let o of t?.data?.spectra||[]){let{digitalFilter:r,fft:i,phaseCorrection:s}=qe(o);i?.flag&&r?.flag&&s&&Math.floor(r.value.digitalFilterValue)%2>0&&(s.value.ph0-=180)}return t}function qe(e,t=["phaseCorrection","fft","digitalFilter"]){let{filters:o=[]}=e,r={};for(let i of t)r[i]=o.find(s=>s.name===i);return r}function C(e,t="localStorage"){if(e?.version===7)return e;if(t==="nmrium")return se(e);let o={...e,version:7};for(let r in e.workspaces)o.workspaces[r]=se(o.workspaces[r]);return o}function se(e){let{formatting:{nuclei:t,panels:o}={nuclei:null,panels:null},version:r,...i}=e,s={...i};return t&&(s.nuclei=Je(t)),o&&(s.panels=o),s}function Je(e){let t=[],o={name:"nucleus",ppm:"ppmFormat",hz:"hzFormat"};for(let r in e)t.push(b(e[r],o));return t}function J(e){if(e?.version===7)return e;let t={...e,version:7};return t?.settings&&(t.settings=C(t.settings,"nmrium")),t}function A(e,t="localStorage"){if(e?.version===8)return e;if(t==="nmrium")return ae(e);let o={...e,version:8};for(let r in e.workspaces)o.workspaces[r]=ae(o.workspaces[r]);return o}function ae(e){let{version:t,...o}=e,r={...o};return r.display.panels=He(e),r}function He(e){let t={},o=e.display.panels;for(let r of Object.keys(o)){let{display:i,open:s}=o[r];t[r]={display:i,visible:i,open:s}}return t}function H(e){if(e?.version===8)return e;let t={...e,version:8};t?.settings&&(t.settings=A(t.settings,"nmrium"));for(let o of t?.data?.spectra||[]){let{filters:r=[]}=o;for(let n=0;n<r.length;n++){let{flag:l,isDeleteAllow:a,label:p,...m}=r[n];r[n]={...m,enabled:l}}let i=r.findIndex(n=>n.name==="apodization");if(i!==-1){let n=r[i],{lineBroadening:l,gaussBroadening:a,lineBroadeningCenter:p}=n.value;n.value={exponential:{apply:!0,options:{lineBroadening:a>0?-l:l}}},a>0&&(n.value.gaussian={apply:!0,options:{lineBroadening:.6*a,lineBroadeningCenter:p}}),r[i]=n}let s=r.findIndex(n=>n.name==="apodizationDimension1"),c=r.findIndex(n=>n.name==="apodizationDimension2");if(s!==-1){let n=r[s],{shapes:l}=n.value.compose;n.value=le(l)}if(c!==-1){let n=r[c],{shapes:l}=n.value.compose;n.value=le(l)}}return t}function le(e){let t={};for(let{shape:o}of e){let{kind:r,options:i}=o;if(r==="sineBell"){let{exponent:s,offset:c}=i,n=s===2?"sineSquare":"sineBell";t[n]={apply:!0,options:{offset:c}}}}return t}function Q(e){let{version:t,plugins:o,...r}=e;return t===9?e:{version:9,plugins:{},...r}}function ee(e){if(e?.version>=10)return e;let t={...e,version:10};if(e.data){let{source:o,spectra:r,...i}=e.data,s=o?crypto.randomUUID():void 0,c=o?[{...o,id:s}]:[];t.data={...i,sources:c,spectra:o?r?.map(n=>({...n,sourceId:s})):r}}return t}function te(e){let{version:t}=e;if(t>=11)return e;let o={...e,version:11};return e?.view?.molecules&&(o.view=Qe(e.view)),o}function Qe(e){let{molecules:t,...o}=e,r={};for(let[i,s]of Object.entries(t)){let{showAtomNumber:c,...n}=s;r[i]={...n,atomAnnotation:"none",showLabel:!1}}return{molecules:r,...o}}function re(e){if(e?.version>=12)return e;let t={...e,version:12};if(t.data){let o=e.data.spectra??[],r=e.data.molecules??[];for(let i of o){let{sourceId:s,fileCollectionId:c,sourceSelector:n}=i;delete i.sourceId,delete i.fileCollectionId,delete i.sourceSelector,n&&(i.selector={...n,root:c??s})}for(let i of r){let{sourceId:s,fileCollectionId:c,sourceSelector:n}=i;delete i.sourceId,delete i.fileCollectionId,delete i.sourceSelector,n&&(i.selector={...n,root:c??s})}}return t}function O(e,t){e.plugins||(e.plugins={});let o=e.plugins;for(let r of t.values()){if(!r.shouldSerialize){delete o[r.id];continue}o[r.id]||(o[r.id]={id:r.id,version:r.version}),o[r.id].id=r.id,o[r.id].version=r.version}}var et=[X,Y,$,Z,G,q,J,H,Q,ee,te,re];function ce(e,t,o){let r=structuredClone(e),i=Object.entries(e?.plugins??{});for(let[n,{version:l}]of i){let a=o.get(n);if(!(a&&a.version>=l)){if(a){console.warn(`Plugin "${a.id}" is loaded with a version older (${a.version}) than the one used to save the state (${l}).
|
|
2
2
|
NMRium may fail to load the state.
|
|
3
|
-
Please update the plugin to the latest version.`);continue}console.warn(`Plugin "${
|
|
4
|
-
Please consider open this file with the plugin installed.`)}}let i=new Set,c=()=>{let s=r.version;for(let l of o.values())for(let a of l.migrations){if(i.has(a)||s<a.minCore||a.maxCore&&s>a.maxCore)continue;if((r.plugins?.[l.id]?.version||0)===l.version)break;r=a.up(r),i.add(a)}};for(let s=e?.version||0;s<t;s++){let l=He[s];r=l(r),c()}return c(),R(r,o),r}var Qe=["topbar.right","topbar.about_us.modal"],et=[],Zr=[...Qe,...et],tt={},te={};{let e=tt,t=te;for(let[o,r]of Object.entries(e))t[r]||(t[r]=[]),t[r]?.push(o)}function*le(e){let{slot:t,plugins:o,supportedToDeprecatedSlots:r=te}=e,n=r[t];for(let[i,c]of o.entries()){let s=c.ui;if(!s)continue;let l=s[t];if(l){yield[i,l];continue}if(n)for(let a of n){let p=c.ui?.[a];if(p){yield[i,p],console.warn(`Plugin ${c.id} used deprecated slot "${a}". Please update this plugin to use "${t}" instead.`);break}}}}import{FileCollection as lt}from"file-collection";var ce={SDF:"sdf",MOL:"mol",NMRIUM:"nmrium",NMRIUM_ARCHIVE:"nmrium.zip",JSON:"json",JCAMP:"jcamp",DX:"dx",JDX:"jdx",JDF:"jdf",NMREDATA:"nmredata",SMILES:"smiles",SMI:"smi"};function A(e){return e.includes(".")?e.replace(/^.*\./,"").toLowerCase():""}function F(e,t={},o){let{data:r,...n}=e;if(!r)return e;let{spectra:i=[]}=r,{keep1D:c=!0,keep2D:s=!0,onlyReal:l}=t,a=l?"ft":t.dataSelection||"both",p=[];for(let m of i){if(!m.info){p.push(m);continue}let{isFid:u,dimension:f,name:d}=m.info;if(!w(f===1&&!c,d,o)&&!w(f===2&&!s,d,o)&&!w(u&&a==="ft",d,o)&&!w(!u&&a==="fid",d,o))if(l&&!u)if(m.info.isComplex=!1,rt(m)){let{rr:g}=m.data;p.push({...m,data:{rr:g}})}else{let{re:g,x:y}=m.data;p.push({...m,data:{re:g,x:y}})}else p.push(m)}return{data:{...r,spectra:p},...n}}function w(e,t,o){return e?(o?.warn(`Skipping ${t} because it didn't match the import filters.`),!0):!1}function rt(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 i=n.onReadProcess?.onProcessing;i&&i(t,r)}}async function E(e,t,o={}){let{selector:r,converter:n,logger:i}=o,c=[],s=[];for(let u of t.values()){let{onReadProcess:f}=u;f&&(f?.onFiles&&c.push(u),f?.supportedExtensions?.length&&f?.onFile&&s.push(u))}let l=await Promise.allSettled(c.map(u=>u.onReadProcess.onFiles(e,o))),a=[],p=await Promise.allSettled(e.files.flatMap(u=>{let f=A(u.name).toLowerCase();return s.flatMap(d=>{let{supportedExtensions:g,onFile:y}=d.onReadProcess;return g.includes(f)?(a.push({file:u,plugin:d}),y(u,{logger:i,selector:r,converter:n})):[]})})),m={spectra:[],molecules:[]};for(let u=0;u<l.length;u++){let f=l[u];switch(f.status){case"fulfilled":{let{spectra:d=[],molecules:g=[]}=f.value||{};m.spectra.push(...d),m.molecules.push(...g);break}case"rejected":{let d=f.reason,g=c[u];o.logger?.error(`Load file collection with plugin ${g.id}@${g.version} fails with: ${d}`);break}}}for(let u=0;u<p.length;u++){let f=p[u];switch(f.status){case"fulfilled":{let{spectra:d=[],molecules:g=[]}=f.value||{};m.spectra.push(...d),m.molecules.push(...g);break}case"rejected":{let d=f.reason,{file:g,plugin:y}=a[u];o.logger?.error(`Load file ${g.relativePath} with plugin ${y.id}@${y.version} fails with: ${d}`);break}}}return m}import{FileCollection as it}from"file-collection";import{FileCollection as me}from"file-collection";import ue from"lodash.merge";import{xIsEquallySpaced as ot}from"ml-spectra-processing";async function L(e){let{input:t,spectraResult:o,unserializedSpectrum:r,options:n,plugins:i,migrator:c}=e,l=(await I({input:t,migrator:c,plugins:i,options:{...n,selector:r.selector}}))?.nmriumState?.data?.spectra??[],a=l.pop();if(a){o.push(pe(r,a));for(let p of l)o.push(pe(r,nt(p)))}}function pe(e,t){let{data:o,...r}=e;if(!t.selector?.root&&e.selector?.root&&(t.selector??=e.selector,t.selector.root=e.selector.root),"ranges"in t){let{data:n,...i}=t;return{...ue(i,r),data:n}}else if("zones"in t){let{data:n,...i}=t;return{...ue(i,r),data:n}}else return t}function nt(e){return{...e,id:h()}}function k(e){let{spectrum:t,spectraResult:o,logger:r}=e,{dimension:n}=t.info;if(n===1){if(!ot(t.data)){r?.error('The ".nmrium" file is corrupted; the X-axis values are not equally distant.');return}o.push(b(t))}else n===2&&o.push(v(t))}async function U(e){let{input:t,moleculesResult:o,unserializedMolecule:r,options:n,plugins:i,migrator:c}=e,{selector:s}=r,a=(await I({input:t,migrator:c,plugins:i,options:{...n,selector:s}}))?.nmriumState?.data?.molecules??[];for(let p of a)!p.selector?.root&&s?.root&&(p.selector??=s,p.selector.root=s.root),o.push({...r,...p})}function j(e){let{molecule:t,moleculesResult:o}=e;o.push(t)}async function z(e){let{nmriumObjectInput:t,options:o={},migrator:r,plugins:n}=e,i=r(t),{data:c,...s}=i,l=new me;if(!c)return[{...s},l];let a={data:{...c,spectra:[],molecules:[]},...s},p=a.data,{sources:m=[],spectra:u,molecules:f}=p,d=await Promise.all(m.map(async S=>{let P=await me.fromSource(S,{unzip:{zipExtensions:["zip","nmredata"]}});return[S.id,P]})),g=new Map(d),y=[];for(let S of c.spectra){let P=S.selector?.root??"",O=g.get(P);if(!O){k({spectrum:S,spectraResult:u,logger:o.logger});continue}y.push(L({input:O,spectraResult:u,unserializedSpectrum:S,migrator:r,plugins:n,options:o}))}for(let S of c.molecules??[]){let P=g.get(S.sourceId);if(!P){j({molecule:S,moleculesResult:f,logger:o.logger});continue}y.push(U({input:P,unserializedMolecule:S,moleculesResult:f,migrator:r,plugins:n,options:o}))}await Promise.allSettled(y);for(let[S,P]of g.entries())l.appendFileCollection(P,S);return[a,l]}async function fe(e){let{file:t,options:o={},migrator:r,plugins:n}=e,i=await t.arrayBuffer(),c=await(at(i)?st(i):t.text());return z({nmriumObjectInput:JSON.parse(c),plugins:n,migrator:r,options:o})}async function st(e){let t=await it.fromZip(e);if(t.files.length===0)throw new Error("compressed nmrium file is corrupted");return t.files[0].text()}function at(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 I(e){let{options:t={},input:o,migrator:r,plugins:n}=e,{selectorRoot:i=crypto.randomUUID()}=t,c=pt(await ct(o),t.selector?.files),s=mt(c);if(s){let[f]=await fe({file:s,migrator:r,plugins:n,options:t});return ge(f,i),{nmriumState:f,containsNmrium:!0,fileCollection:c,selectorRoot:i}}let l=await E(c,n,t),a=F({version:12,data:l},t?.selector?.general,t.logger),{onLoadProcessing:p,experimentalFeatures:m}=t,u={...p,autoProcessing:p?.autoProcessing??!1,experimentalFeatures:m};return T({nmriumState:a,plugins:n,options:u}),ge(a,i),{nmriumState:a,containsNmrium:!1,fileCollection:c,selectorRoot:i}}function ct(e){return Array.isArray(e)?Promise.reject(new Error("For a set of fileCollectionItems pass a FileCollection instance")):ut(e)?Promise.resolve(e):new lt().appendExtendedSource({...e,uuid:crypto.randomUUID()})}function ut(e){return typeof e=="object"&&"files"in e}function pt(e,t){if(!t)return e;let o=new Set(t);return e.filter(r=>o.has(r.relativePath))}function mt(e){return e.files.find(t=>A(t.name).toLowerCase()===ce.NMRIUM)}function ge(e,t){for(let o of e.data?.spectra??[])o.selector?.root||(o.selector??={root:t},o.selector.root||=t);for(let o of e.data?.molecules??[])o.selector?.root||(o.selector??={root:t},o.selector.root||=t)}import{FileCollection as gt}from"file-collection";async function de(e){let t={},o=[];for(let r of e.sources)switch(r.relativePath){case".META-NMRIUM/NMRIUM_ARCHIVE":t.archive=r;break;case".META-NMRIUM/VERSION":o.push(r.text().then(n=>{t.version=Number.parseInt(n,10)}));break;case"state.json":o.push(r.text().then(n=>{t.state=JSON.parse(n)}));break;default:}return await Promise.all(o),t}function Se(e){if(!e.archive)throw new Error("Not a valid NMRium archive");if(typeof e.version!="number"||Number.isNaN(e.version))throw new Error("Not a valid NMRium archive, no version specified");if(!e.state)throw new Error("NMRium Archive corrupted, state.json is missing")}function ye(e){return e.filter(t=>!ft(t.relativePath))}function ft(e){return e.startsWith(".META-NMRIUM/")||e==="state.json"||e==="index.txt"}async function Pe(e){let{options:t,plugins:o,migrator:r}=e,n=await gt.fromIum(e.input),i=await de(n);Se(i);let c=ye(n),s=r(i.state),l={...s,data:{...s.data,spectra:[],molecules:[]}},a=l.data.spectra,p=l.data.molecules,m=dt(n),u=[];for(let f of s.data.spectra)u.push(St({subRoots:m,unserializedSpectrum:f,spectraResult:a,options:t,plugins:o,migrator:r}));for(let f of s.data.molecules??[])u.push(yt({subRoots:m,unserializedMolecule:f,moleculesResult:p,options:t,plugins:o,migrator:r}));return await Promise.allSettled(u),[l,c]}function dt(e){let t=new Map;return{get(o){let r=t.get(o);return r||(r=e.subroot(o),t.set(o,r)),r},[Symbol("debug")]:{ium:e,views:t}}}async function St(e){let{subRoots:t}=e,{unserializedSpectrum:o,spectraResult:r}=e,{options:n,plugins:i,migrator:c}=e,{selector:s}=o,l=await xe({subRoots:t,selector:s});if(!l)return k({spectrum:o,spectraResult:r,logger:n?.logger});await L({input:l,unserializedSpectrum:o,spectraResult:r,options:n,plugins:i,migrator:c})}async function yt(e){let{subRoots:t}=e,{unserializedMolecule:o,moleculesResult:r}=e,{options:n,plugins:i,migrator:c}=e,{selector:s}=o,l=await xe({subRoots:t,selector:s});if(!l)return j({molecule:o,moleculesResult:r,logger:n?.logger});await U({input:l,unserializedMolecule:o,moleculesResult:r,options:n,plugins:i,migrator:c})}async function xe(e){let{subRoots:t,selector:o}=e;if(!o)return;let{root:r}=o;if(r)return t.get(r)}import{FileCollection as Pt}from"file-collection";async function Ne(e){let{source:t,plugins:o,options:r={},sourceId:n=crypto.randomUUID()}=e,{converter:i,...c}=r,s={...t,id:n},l={spectra:[],molecules:[]},a=await Pt.fromSource(s,{unzip:{zipExtensions:["zip","nmredata"]}}),{spectra:p=[],molecules:m=[]}=await E(a,o,{converter:{...i,bruker:{keepFiles:!0,...Reflect.get(i??{},"bruker")}},...c});l.spectra.push(...p),l.molecules.push(...m);for(let g of l.spectra)g.selector??={root:n},g.selector.root=n;for(let g of l.molecules)g.selector??={root:n},g.selector.root=n;l.sources??=[],l.sources.push(s);let u=F({version:12,data:l},r?.selector?.general),{onLoadProcessing:f}=c,d={filters:f?.filters,autoProcessing:f?.autoProcessing??!1,experimentalFeatures:r.experimentalFeatures};return T({nmriumState:u,plugins:o,options:d}),[u,a,n]}function M(e,t){let o={};for(let r in e)t.includes(r)||(o[r]=e[r]);return o}var xt=["data","originalData","info","originalInfo","meta","customInfo"],Nt=["data","originalData","info","originalInfo","meta","customInfo"],ht=["selector","originalData","originalInfo"];function he(e,t,o={}){let{version:r,data:n}=e;if(n.actionType)return e;let i={version:r,plugins:e.plugins},{includeData:c}=o;c!=="noData"&&(i.data=bt({...n},c));let{includeSettings:s,includeView:l}=o;return s&&(i.settings=e.settings),l&&(i.view=e.view),R(i,t),i}function bt(e,t="rawData"){let{spectra:o}=e;switch(t){case"dataSource":return Rt(e);case"selfContained":case"selfContainedExternalDatasource":return Ot(e);case"rawData":return{...M(e,["sources"]),spectra:o.map(vt)};default:return e}}function Rt(e){let{spectra:t}=e;if(!e.sources)throw new Error("sources property should exists for dataSource serialization");return{...e,spectra:t.map(It)}}function Ot(e){let{spectra:t,sources:o,...r}=e;return{...r,spectra:t.map(Mt)}}function It(e){return M(e,xt)}function Mt(e){return M(e,Nt)}function vt(e){let{data:t,info:o,originalData:r,originalInfo:n}=e,i=M(e,ht);return i.data=r||t,i.info=n||o,i}import{FileCollection as Dt}from"file-collection";async function be(e){let{spectra:t,molecules:o,aggregator:r,serializedState:n,includeData:i=!0}=e;return Dt.fromCollection(r,{filter:{ignoreDotfiles:!1}}).toIum({includeData:i,*getExtraFiles(s){yield{relativePath:".META-NMRIUM/NMRIUM_ARCHIVE",data:""},yield{relativePath:".META-NMRIUM/VERSION",data:"0"},yield{relativePath:"state.json",data:n},yield{relativePath:"index.txt",data:Ct({aggregator:r,spectra:t,molecules:o,index:s})}}})}function Ct(e){let{aggregator:t,spectra:o,molecules:r,index:n}=e,i=new Map,c=new Map(n.sources.map(l=>[l.uuid,l]));for(let l of o){let a=l.selector?.root;a&&(i.has(a)||i.set(a,t.subroot(a)))}for(let l of r){let a=l.selector?.root;a&&(i.has(a)||i.set(a,t.subroot(a)))}let s=[];for(let[l,a]of i.entries()){s.push(`data/${l}/`);for(let p of a.files){let u=c.get(p.sourceUUID)?.baseURL?.startsWith("ium:/")?"embedded":"linked";s.push(` ${p.relativePath} (${u})`)}s.push(`
|
|
5
|
-
`)}return
|
|
6
|
-
`)}var
|
|
3
|
+
Please update the plugin to the latest version.`);continue}console.warn(`Plugin "${n}@${l}" is not registered. NMRium may fail to load the state.
|
|
4
|
+
Please consider open this file with the plugin installed.`)}}let s=new Set,c=()=>{let n=r.version;for(let l of o.values())for(let a of l.migrations){if(s.has(a)||n<a.minCore||a.maxCore&&n>a.maxCore)continue;if((r.plugins?.[l.id]?.version||0)===l.version)break;r=a.up(r),s.add(a)}};for(let n=e?.version||0;n<t;n++){let l=et[n];r=l(r),c()}return c(),O(r,o),r}var tt=["topbar.right","topbar.about_us.modal"],rt=[],Zr=[...tt,...rt],ot={},oe={};{let e=ot,t=oe;for(let[o,r]of Object.entries(e))t[r]||(t[r]=[]),t[r]?.push(o)}function*ue(e){let{slot:t,plugins:o,supportedToDeprecatedSlots:r=oe}=e,i=r[t];for(let[s,c]of o.entries()){let n=c.ui;if(!n)continue;let l=n[t];if(l){yield[s,l];continue}if(i)for(let a of i){let p=c.ui?.[a];if(p){yield[s,p],console.warn(`Plugin ${c.id} used deprecated slot "${a}". Please update this plugin to use "${t}" instead.`);break}}}}import{FileCollection as lt}from"file-collection";var pe={SDF:"sdf",MOL:"mol",NMRIUM:"nmrium",NMRIUM_ARCHIVE:"nmrium.zip",JSON:"json",JCAMP:"jcamp",DX:"dx",JDX:"jdx",JDF:"jdf",NMREDATA:"nmredata",SMILES:"smiles",SMI:"smi"};function w(e){return e.includes(".")?e.replace(/^.*\./,"").toLowerCase():""}function T(e,t={},o){let{data:r,...i}=e;if(!r)return e;let{spectra:s=[]}=r,{keep1D:c=!0,keep2D:n=!0,onlyReal:l}=t,a=l?"ft":t.dataSelection||"both",p=[];for(let m of s){if(!m.info){p.push(m);continue}let{isFid:u,dimension:f,name:g}=m.info;if(!F(f===1&&!c,g,o)&&!F(f===2&&!n,g,o)&&!F(u&&a==="ft",g,o)&&!F(!u&&a==="fid",g,o))if(l&&!u)if(m.info.isComplex=!1,it(m)){let{rr:d}=m.data;p.push({...m,data:{rr:d}})}else{let{re:d,x:S}=m.data;p.push({...m,data:{re:d,x:S}})}else p.push(m)}return{data:{...r,spectra:p},...i}}function F(e,t,o){return e?(o?.warn(`Skipping ${t} because it didn't match the import filters.`),!0):!1}function it(e){let{info:t}=e;return t?.dimension===2}function E(e){let{nmriumState:t,plugins:o,options:r}=e;for(let i of o.values()){let s=i.onReadProcess?.onProcessing;s&&s(t,r)}}async function L(e,t,o={}){let{selector:r,converter:i,logger:s}=o,c=[],n=[];for(let u of t.values()){let{onReadProcess:f}=u;f&&(f?.onFiles&&c.push(u),f?.supportedExtensions?.length&&f?.onFile&&n.push(u))}let l=await Promise.allSettled(c.map(u=>u.onReadProcess.onFiles(e,o))),a=[],p=await Promise.allSettled(e.files.flatMap(u=>{let f=w(u.name).toLowerCase();return n.flatMap(g=>{let{supportedExtensions:d,onFile:S}=g.onReadProcess;return d.includes(f)?(a.push({file:u,plugin:g}),S(u,{logger:s,selector:r,converter:i})):[]})})),m={spectra:[],molecules:[]};for(let u=0;u<l.length;u++){let f=l[u];switch(f.status){case"fulfilled":{let{spectra:g=[],molecules:d=[]}=f.value||{};m.spectra.push(...g),m.molecules.push(...d);break}case"rejected":{let g=f.reason,d=c[u];o.logger?.error(`Load file collection with plugin ${d.id}@${d.version} fails with: ${g}`);break}}}for(let u=0;u<p.length;u++){let f=p[u];switch(f.status){case"fulfilled":{let{spectra:g=[],molecules:d=[]}=f.value||{};m.spectra.push(...g),m.molecules.push(...d);break}case"rejected":{let g=f.reason,{file:d,plugin:S}=a[u];o.logger?.error(`Load file ${d.relativePath} with plugin ${S.id}@${S.version} fails with: ${g}`);break}}}return m}import{FileCollection as de}from"file-collection";import{FileCollection as ge}from"file-collection";import me from"lodash.merge";import{xIsEquallySpaced as nt}from"ml-spectra-processing";async function U(e){let{input:t,spectraResult:o,unserializedSpectrum:r,options:i,plugins:s,migrator:c}=e,l=(await M({input:t,migrator:c,plugins:s,options:{...i,selector:r.selector}}))?.nmriumState?.data?.spectra??[],a=l.pop();if(a){o.push(fe(r,a));for(let p of l)o.push(fe(r,st(p)))}}function fe(e,t){let{data:o,...r}=e;if(!t.selector?.root&&e.selector?.root&&(t.selector??=e.selector,t.selector.root=e.selector.root),"ranges"in t){let{data:i,...s}=t;return{...me(s,r),data:i}}else if("zones"in t){let{data:i,...s}=t;return{...me(s,r),data:i}}else return t}function st(e){return{...e,id:R()}}function k(e){let{spectrum:t,spectraResult:o,logger:r}=e,{dimension:i}=t.info;if(i===1){if(!nt(t.data)){r?.error('The ".nmrium" file is corrupted; the X-axis values are not equally distant.');return}o.push(h(t))}else i===2&&o.push(D(t))}async function j(e){let{input:t,moleculesResult:o,unserializedMolecule:r,options:i,plugins:s,migrator:c}=e,{selector:n}=r,a=(await M({input:t,migrator:c,plugins:s,options:{...i,selector:n}}))?.nmriumState?.data?.molecules??[];for(let p of a)!p.selector?.root&&n?.root&&(p.selector??=n,p.selector.root=n.root),o.push({...r,...p})}function z(e){let{molecule:t,moleculesResult:o}=e;o.push(t)}async function V(e){let{nmriumObjectInput:t,options:o={},migrator:r,plugins:i,fromSourceOptions:s}=e,c=r(t),{data:n,...l}=c,a=new ge;if(!n)return[{...l},a];let p={data:{...n,spectra:[],molecules:[]},...l},m=p.data,{sources:u=[],spectra:f,molecules:g}=m,d=await Promise.all(u.map(async y=>{let x=await ge.fromSource(y,{unzip:{zipExtensions:["zip","nmredata"]}},s);if(!y.baseURL)for(let I of y.entries)I.baseURL||(I.baseURL=s?.baseURL);return[y.id,x]})),S=new Map(d),P=[];for(let y of n.spectra){let x=y.selector?.root??"",I=S.get(x);if(!I){k({spectrum:y,spectraResult:f,logger:o.logger});continue}P.push(U({input:I,spectraResult:f,unserializedSpectrum:y,migrator:r,plugins:i,options:o}))}for(let y of n.molecules??[]){let x=S.get(y.sourceId);if(!x){z({molecule:y,moleculesResult:g,logger:o.logger});continue}P.push(j({input:x,unserializedMolecule:y,moleculesResult:g,migrator:r,plugins:i,options:o}))}await Promise.allSettled(P);for(let[y,x]of S.entries())a.appendFileCollection(x,y);return[p,a]}async function _(e){let{file:t,options:o={},migrator:r,plugins:i,fromSourceOptions:s}=e,c=await t.arrayBuffer(),n=await(de.isZip(c)?at(c):t.text());return V({nmriumObjectInput:JSON.parse(n),plugins:i,migrator:r,options:o,fromSourceOptions:s})}async function at(e){let t=await de.fromZip(e);if(t.files.length===0)throw new Error("compressed nmrium file is corrupted");return t.files[0].text()}async function M(e){let{options:t={},input:o,migrator:r,plugins:i,fromSourceOptions:s}=e,{selectorRoot:c=crypto.randomUUID()}=t,n=pt(await ct(o),t.selector?.files),l=mt(n);if(l){let[g]=await _({file:l,migrator:r,plugins:i,options:t,fromSourceOptions:s});return Se(g,c),{nmriumState:g,containsNmrium:!0,fileCollection:n,selectorRoot:c}}let a=await L(n,i,t),p=T({version:12,data:a},t?.selector?.general,t.logger),{onLoadProcessing:m,experimentalFeatures:u}=t,f={...m,autoProcessing:m?.autoProcessing??!1,experimentalFeatures:u};return E({nmriumState:p,plugins:i,options:f}),Se(p,c),{nmriumState:p,containsNmrium:!1,fileCollection:n,selectorRoot:c}}function ct(e){return Array.isArray(e)?Promise.reject(new Error("For a set of fileCollectionItems pass a FileCollection instance")):ut(e)?Promise.resolve(e):new lt().appendExtendedSource({...e,uuid:crypto.randomUUID()})}function ut(e){return typeof e=="object"&&"files"in e}function pt(e,t){if(!t)return e;let o=new Set(t);return e.filter(r=>o.has(r.relativePath))}function mt(e){return e.files.find(t=>w(t.name).toLowerCase()===pe.NMRIUM)}function Se(e,t){for(let o of e.data?.spectra??[])o.selector?.root||(o.selector??={root:t},o.selector.root||=t);for(let o of e.data?.molecules??[])o.selector?.root||(o.selector??={root:t},o.selector.root||=t)}import{FileCollection as gt}from"file-collection";async function ye(e){let t={},o=[];for(let r of e.sources)switch(r.relativePath){case".META-NMRIUM/NMRIUM_ARCHIVE":t.archive=r;break;case".META-NMRIUM/VERSION":o.push(r.text().then(i=>{t.version=Number.parseInt(i,10)}));break;case"state.json":o.push(r.text().then(i=>{t.state=JSON.parse(i)}));break;default:}return await Promise.all(o),t}function Pe(e){if(!e.archive)throw new Error("Not a valid NMRium archive");if(typeof e.version!="number"||Number.isNaN(e.version))throw new Error("Not a valid NMRium archive, no version specified");if(!e.state)throw new Error("NMRium Archive corrupted, state.json is missing")}function xe(e){return e.filter(t=>!ft(t.relativePath))}function ft(e){return e.startsWith(".META-NMRIUM/")||e==="state.json"||e==="index.txt"}async function Ne(e){let{options:t,plugins:o,migrator:r}=e,i=await gt.fromIum(e.input),s=await ye(i);Pe(s);let c=xe(i),n=r(s.state),l={...n,data:{...n.data,spectra:[],molecules:[]}},a=l.data.spectra,p=l.data.molecules,m=dt(i),u=[];for(let f of n.data.spectra)u.push(St({subRoots:m,unserializedSpectrum:f,spectraResult:a,options:t,plugins:o,migrator:r}));for(let f of n.data.molecules??[])u.push(yt({subRoots:m,unserializedMolecule:f,moleculesResult:p,options:t,plugins:o,migrator:r}));return await Promise.allSettled(u),[l,c]}function dt(e){let t=new Map;return{get(o){let r=t.get(o);return r||(r=e.subroot(o),t.set(o,r)),r},[Symbol("debug")]:{ium:e,views:t}}}async function St(e){let{subRoots:t}=e,{unserializedSpectrum:o,spectraResult:r}=e,{options:i,plugins:s,migrator:c}=e,{selector:n}=o,l=await be({subRoots:t,selector:n});if(!l)return k({spectrum:o,spectraResult:r,logger:i?.logger});await U({input:l,unserializedSpectrum:o,spectraResult:r,options:i,plugins:s,migrator:c})}async function yt(e){let{subRoots:t}=e,{unserializedMolecule:o,moleculesResult:r}=e,{options:i,plugins:s,migrator:c}=e,{selector:n}=o,l=await be({subRoots:t,selector:n});if(!l)return z({molecule:o,moleculesResult:r,logger:i?.logger});await j({input:l,unserializedMolecule:o,moleculesResult:r,options:i,plugins:s,migrator:c})}async function be(e){let{subRoots:t,selector:o}=e;if(!o)return;let{root:r}=o;if(r)return t.get(r)}import{FileCollection as Pt}from"file-collection";async function Re(e){let{source:t,plugins:o,options:r={},sourceId:i=crypto.randomUUID()}=e,{converter:s,...c}=r,n={...t,id:i},l={spectra:[],molecules:[]},a=await Pt.fromSource(n,{unzip:{zipExtensions:["zip","nmredata"]}}),{spectra:p=[],molecules:m=[]}=await L(a,o,{converter:{...s,bruker:{keepFiles:!0,...Reflect.get(s??{},"bruker")}},...c});l.spectra.push(...p),l.molecules.push(...m);for(let d of l.spectra)d.selector??={root:i},d.selector.root=i;for(let d of l.molecules)d.selector??={root:i},d.selector.root=i;l.sources??=[],l.sources.push(n);let u=T({version:12,data:l},r?.selector?.general),{onLoadProcessing:f}=c,g={filters:f?.filters,autoProcessing:f?.autoProcessing??!1,experimentalFeatures:r.experimentalFeatures};return E({nmriumState:u,plugins:o,options:g}),[u,a,i]}function v(e,t){let o={};for(let r in e)t.includes(r)||(o[r]=e[r]);return o}var xt=["data","originalData","info","originalInfo","meta","customInfo"],Nt=["data","originalData","info","originalInfo","meta","customInfo"],bt=["selector","originalData","originalInfo"];function he(e,t,o={}){let{version:r,data:i}=e;if(i.actionType)return e;let s={version:r,plugins:e.plugins},{includeData:c}=o;c!=="noData"&&(s.data=Rt({...i},c));let{includeSettings:n,includeView:l}=o;return n&&(s.settings=e.settings),l&&(s.view=e.view),O(s,t),s}function Rt(e,t="rawData"){let{spectra:o}=e;switch(t){case"dataSource":return ht(e);case"selfContained":case"selfContainedExternalDatasource":return Ot(e);case"rawData":return{...v(e,["sources"]),spectra:o.map(vt)};default:return e}}function ht(e){let{spectra:t}=e;if(!e.sources)throw new Error("sources property should exists for dataSource serialization");return{...e,spectra:t.map(It)}}function Ot(e){let{spectra:t,sources:o,...r}=e;return{...r,spectra:t.map(Mt)}}function It(e){return v(e,xt)}function Mt(e){return v(e,Nt)}function vt(e){let{data:t,info:o,originalData:r,originalInfo:i}=e,s=v(e,bt);return s.data=r||t,s.info=i||o,s}import{FileCollection as Dt}from"file-collection";async function Oe(e){let{spectra:t,molecules:o,aggregator:r,serializedState:i,includeData:s=!0}=e;return Dt.fromCollection(r,{filter:{ignoreDotfiles:!1}}).toIum({includeData:s,*getExtraFiles(n){yield{relativePath:".META-NMRIUM/NMRIUM_ARCHIVE",data:""},yield{relativePath:".META-NMRIUM/VERSION",data:"0"},yield{relativePath:"state.json",data:i},yield{relativePath:"index.txt",data:Ct({aggregator:r,spectra:t,molecules:o,index:n})}}})}function Ct(e){let{aggregator:t,spectra:o,molecules:r,index:i}=e,s=new Map,c=new Map(i.sources.map(l=>[l.uuid,l]));for(let l of o){let a=l.selector?.root;a&&(s.has(a)||s.set(a,t.subroot(a)))}for(let l of r){let a=l.selector?.root;a&&(s.has(a)||s.set(a,t.subroot(a)))}let n=[];for(let[l,a]of s.entries()){n.push(`data/${l}/`);for(let p of a.files){let u=c.get(p.sourceUUID)?.baseURL?.startsWith("ium:/")?"embedded":"linked";n.push(` ${p.relativePath} (${u})`)}n.push(`
|
|
5
|
+
`)}return n.join(`
|
|
6
|
+
`)}var ie=class{version=12;#e=new Map;registerPlugin(t){if(this.#e.has(t.id)){console.warn(`Plugin ${t.id} is already registered. skip.`),console.debug("Plugin already registered:",this.#e.get(t.id)),console.debug("Plugin to register:",t);return}this.#e.set(t.id,t)}registerPlugins(t){for(let o of t)this.registerPlugin(o)}migrate(t){return ce(t,this.version,this.#e)}read(t,o={},r){return M({input:t,options:o,fromSourceOptions:r,migrator:this.migrate.bind(this),plugins:this.#e})}readNMRiumArchive(t,o={}){return Ne({input:t,options:o,plugins:this.#e,migrator:this.migrate.bind(this)})}readNMRiumObject(t,o,r){return V({nmriumObjectInput:t,options:o,fromSourceOptions:r,plugins:this.#e,migrator:this.migrate.bind(this)})}readNMRiumFile(t,o={},r){return _({file:t,options:o,fromSourceOptions:r,plugins:this.#e,migrator:this.migrate.bind(this)})}readFromWebSource(t,o){return Re({source:t,options:o,plugins:this.#e})}serializeNmriumState(t,o){return he(t,this.#e,o)}serializeNmriumArchive(t){return Oe(t)}serializePlugins(){let t={plugins:{}};return O(t,this.#e),t.plugins}slot(t){return ue({slot:t,plugins:this.#e})}};function At(e,t){if(t>12)return 0;let o=-1;for(let r=0;r<e.length;r++)if(e[r].version>t){o=r;break}return o}var Ie=[{version:6,fun:C},{version:7,fun:A}];function wt(e){let{version:t}=e||{},o=At(Ie,t);if(o===-1)return{...e,version:12};let r=Ie.slice(o);for(let i of r)e=i.fun(e);return e}export{Me as ANALYSIS_COLUMN_TYPES,ve as ANALYSIS_COLUMN_VALUES_KEYS,N as CURRENT_EXPORT_VERSION,Ce as EXTERNAL_API_KEYS,ie as NMRiumCore,Ye as defineNMRiumPlugin,Xe as formatSpectra,R as generateID,W as getOneIfArray,wt as migrateSettings,De as units};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zakodium/nmrium-core",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.12",
|
|
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",
|
|
@@ -24,26 +24,26 @@
|
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@types/lodash.merge": "^4.6.9",
|
|
27
|
-
"@types/node": "^24.
|
|
27
|
+
"@types/node": "^24.10.1",
|
|
28
28
|
"@types/react": "^18.3.13",
|
|
29
|
-
"@zakodium/nmr-types": "^0.4.
|
|
30
|
-
"esbuild": "^0.
|
|
29
|
+
"@zakodium/nmr-types": "^0.4.4",
|
|
30
|
+
"esbuild": "^0.27.0",
|
|
31
31
|
"jest-matcher-deep-close-to": "^3.0.2",
|
|
32
|
-
"rimraf": "^6.
|
|
32
|
+
"rimraf": "^6.1.2",
|
|
33
33
|
"typescript": "~5.9.3",
|
|
34
|
-
"vitest": "^4.0.
|
|
34
|
+
"vitest": "^4.0.14"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"cheminfo-types": "^1.8.1",
|
|
38
38
|
"fifo-logger": "^2.0.1",
|
|
39
|
-
"file-collection": "^6.
|
|
39
|
+
"file-collection": "^6.3.0",
|
|
40
40
|
"is-any-array": "^2.0.1",
|
|
41
41
|
"lodash.merge": "^4.6.2",
|
|
42
|
-
"ml-spectra-processing": "^14.18.
|
|
42
|
+
"ml-spectra-processing": "^14.18.1",
|
|
43
43
|
"nmr-correlation": "^2.3.5"
|
|
44
44
|
},
|
|
45
45
|
"volta": {
|
|
46
46
|
"extends": "../../../package.json"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "e3528a28bdd2791e39f17eb2ef7f9d4a756fc812"
|
|
49
49
|
}
|