@zakodium/nmrium-core 0.0.2 → 0.1.1
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 +5 -3
- package/dist/nmrium-core.d.ts +1 -2
- package/package.json +16 -41
- package/dist/nmrium-core.cjs +0 -4
- /package/dist/{nmrium-core.mjs → nmrium-core.js} +0 -0
package/README.md
CHANGED
|
@@ -19,6 +19,7 @@ Provide state and migrate it for different version of NMRium.
|
|
|
19
19
|
Delegate loading and processing state to plugins.
|
|
20
20
|
|
|
21
21
|
It contains the following features:
|
|
22
|
+
|
|
22
23
|
- **read**: read a file and return a data structure with the spectra and molecules for `.nmrium` files
|
|
23
24
|
- **plugin system**: allow to register plugins to handle different file formats
|
|
24
25
|
- **serialize**: Serialize the state
|
|
@@ -48,7 +49,7 @@ console.log(result);
|
|
|
48
49
|
// molecules: [],
|
|
49
50
|
// }
|
|
50
51
|
|
|
51
|
-
// readSource function accept a partial FileCollectionItems and a baseURL to generate a
|
|
52
|
+
// readSource function accept a partial FileCollectionItems and a baseURL to generate a
|
|
52
53
|
// data structure with a source object inside with { files, filter, baseURL }
|
|
53
54
|
|
|
54
55
|
const nmriumObject = await core.readFromWebSource(
|
|
@@ -63,7 +64,6 @@ const nmriumObject = await core.readFromWebSource(
|
|
|
63
64
|
},
|
|
64
65
|
{},
|
|
65
66
|
);
|
|
66
|
-
|
|
67
67
|
```
|
|
68
68
|
|
|
69
69
|
## License
|
|
@@ -77,5 +77,7 @@ This package is based on MIT-licensed code that can be found here: https://doi.o
|
|
|
77
77
|
[download-image]: https://img.shields.io/npm/dm/@zakodium/nmrium-core.svg
|
|
78
78
|
[download-url]: https://www.npmjs.com/package/@zakodium/nmrium-core
|
|
79
79
|
[doi-image]: https://zenodo.org/badge/DOI/10.5281/zenodo.7101438.svg
|
|
80
|
+
|
|
80
81
|
<!-- TODO: fix doi-url for nmrium-core package -->
|
|
81
|
-
|
|
82
|
+
|
|
83
|
+
[doi-url]: https://doi.org/10.5281/zenodo.7101438
|
package/dist/nmrium-core.d.ts
CHANGED
|
@@ -16,7 +16,6 @@ import type { NmrData2D } from 'cheminfo-types';
|
|
|
16
16
|
import type { Peaks } from 'nmr-processing';
|
|
17
17
|
import type { Ranges } from 'nmr-processing';
|
|
18
18
|
import { SerializedNmriumState } from './core_serialize.js';
|
|
19
|
-
import { UUID } from 'crypto';
|
|
20
19
|
import type { WebSource } from 'filelist-utils';
|
|
21
20
|
import type { Zones } from 'nmr-processing';
|
|
22
21
|
|
|
@@ -295,7 +294,7 @@ declare interface GeneralPreferences {
|
|
|
295
294
|
invertScroll: boolean;
|
|
296
295
|
}
|
|
297
296
|
|
|
298
|
-
export declare const generateID: () =>
|
|
297
|
+
export declare const generateID: () => `${string}-${string}-${string}-${string}-${string}`;
|
|
299
298
|
|
|
300
299
|
/**
|
|
301
300
|
* It returns an element if the input is an array otherwise it returns the input.
|
package/package.json
CHANGED
|
@@ -1,68 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zakodium/nmrium-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "The core of NMRium: types, state, state migration and plugin system.",
|
|
5
|
+
"author": "Zakodium Sàrl",
|
|
6
|
+
"license": "CC-BY-NC-SA-4.0",
|
|
5
7
|
"type": "module",
|
|
6
|
-
"exports":
|
|
7
|
-
".": {
|
|
8
|
-
"types": "./dist/nmrium-core.d.ts",
|
|
9
|
-
"require": "./dist/nmrium-core.cjs",
|
|
10
|
-
"default": "./dist/nmrium-core.mjs"
|
|
11
|
-
}
|
|
12
|
-
},
|
|
8
|
+
"exports": "./dist/nmrium-core.js",
|
|
13
9
|
"files": [
|
|
14
|
-
"dist
|
|
15
|
-
"dist/nmrium-core.cjs",
|
|
16
|
-
"dist/nmrium-core.mjs"
|
|
10
|
+
"dist"
|
|
17
11
|
],
|
|
18
12
|
"scripts": {
|
|
19
13
|
"api-extractor": "api-extractor run --local",
|
|
20
|
-
"bundle": "
|
|
21
|
-
"bundle-common": "esbuild src/index.ts --bundle --packages=external --minify",
|
|
22
|
-
"bundle-cjs": "npm run bundle-common -- --format=cjs --outfile=./dist/nmrium-core.cjs",
|
|
23
|
-
"bundle-esm": "npm run bundle-common -- --format=esm --outfile=./dist/nmrium-core.mjs",
|
|
14
|
+
"bundle": "node scripts/esbuild.js && npm run bundle-types",
|
|
24
15
|
"bundle-types": "npm run tsc && npm run api-extractor",
|
|
25
|
-
"
|
|
26
|
-
"clean": "rimraf types",
|
|
27
|
-
"eslint": "eslint src --cache",
|
|
28
|
-
"eslint-fix": "npm run eslint -- --fix",
|
|
16
|
+
"clean": "rimraf types dist coverage",
|
|
29
17
|
"dev:eslint-fix": "eslint --cache --fix $(git diff --name-only --relative) --quiet",
|
|
30
|
-
"prepack": "npm run bundle",
|
|
31
|
-
"prettier": "prettier --check src",
|
|
32
|
-
"prettier-write": "prettier --write src",
|
|
18
|
+
"prepack": "npm run clean && npm run bundle",
|
|
33
19
|
"dev:prettier-write": "prettier --write $(git diff --name-only --relative)",
|
|
34
|
-
"test": "
|
|
35
|
-
"test-only": "vitest run --coverage",
|
|
20
|
+
"test": "yarn g:test-only && yarn g:check-types && yarn g:eslint && yarn g:prettier",
|
|
36
21
|
"tsc": "tsc --project tsconfig.types.json"
|
|
37
22
|
},
|
|
38
|
-
"bugs": {
|
|
39
|
-
"url": "https://github.com/cheminfo/nmrium/issues/new?title=%5Bnmrium-core%5D"
|
|
40
|
-
},
|
|
41
|
-
"author": "",
|
|
42
|
-
"license": "CC-BY-NC-SA-4.0",
|
|
43
23
|
"devDependencies": {
|
|
44
|
-
"@microsoft/api-extractor": "^7.52.
|
|
24
|
+
"@microsoft/api-extractor": "^7.52.7",
|
|
45
25
|
"@types/lodash.merge": "^4.6.9",
|
|
46
|
-
"@types/node": "^22.
|
|
47
|
-
"
|
|
48
|
-
"esbuild": "^0.25.1",
|
|
49
|
-
"eslint": "^9.22.0",
|
|
50
|
-
"eslint-config-cheminfo-typescript": "^18.0.0",
|
|
26
|
+
"@types/node": "^22.15.16",
|
|
27
|
+
"esbuild": "^0.25.4",
|
|
51
28
|
"jest-matcher-deep-close-to": "^3.0.2",
|
|
52
|
-
"prettier": "^3.5.3",
|
|
53
29
|
"rimraf": "^6.0.1",
|
|
54
|
-
"
|
|
55
|
-
"vitest": "^3.0.9"
|
|
30
|
+
"vitest": "^3.1.3"
|
|
56
31
|
},
|
|
57
32
|
"dependencies": {
|
|
58
|
-
"
|
|
33
|
+
"cheminfo-types": "^1.8.1",
|
|
59
34
|
"fifo-logger": "^1.0.0",
|
|
60
35
|
"filelist-utils": "^1.11.3",
|
|
61
36
|
"is-any-array": "^2.0.1",
|
|
62
37
|
"lodash.merge": "^4.6.2",
|
|
63
|
-
"ml-spectra-processing": "^14.
|
|
38
|
+
"ml-spectra-processing": "^14.12.0",
|
|
64
39
|
"nmr-correlation": "^2.3.5",
|
|
65
|
-
"nmr-processing": "^18.0.
|
|
40
|
+
"nmr-processing": "^18.0.2"
|
|
66
41
|
},
|
|
67
42
|
"volta": {
|
|
68
43
|
"extends": "../../../package.json"
|
package/dist/nmrium-core.cjs
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
"use strict";var Re=Object.create;var R=Object.defineProperty;var ve=Object.getOwnPropertyDescriptor;var Ce=Object.getOwnPropertyNames;var we=Object.getPrototypeOf,Fe=Object.prototype.hasOwnProperty;var Ae=(e,t)=>{for(var n in t)R(e,n,{get:t[n],enumerable:!0})},H=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ce(t))!Fe.call(e,o)&&o!==n&&R(e,o,{get:()=>t[o],enumerable:!(r=ve(t,o))||r.enumerable});return e};var Me=(e,t,n)=>(n=e!=null?Re(we(e)):{},H(t||!e||!e.__esModule?R(n,"default",{value:e,enumerable:!0}):n,e)),Te=e=>H(R({},"__esModule",{value:!0}),e);var pt={};Ae(pt,{ANALYSIS_COLUMN_TYPES:()=>Q,ANALYSIS_COLUMN_VALUES_KEYS:()=>ee,CURRENT_EXPORT_VERSION:()=>P,EXTERNAL_API_KEYS:()=>re,NMRiumCore:()=>z,formatSpectra:()=>ae,generateID:()=>b,getOneIfArray:()=>w,migrateSettings:()=>he,units:()=>te});module.exports=Te(pt);var Q={NORMAL:"NORMAL",FORMULA:"FORMULA"};var ee={RELATIVE:"relative",ABSOLUTE:"absolute",MIN:"min",MAX:"max"};var te=[{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 re=[{key:"CT",description:"CT from NMR Solutions"}];var ne=require("is-any-array"),v=require("ml-spectra-processing");var Ee=crypto.randomUUID.bind(crypto),b=Ee;function N(e){let{id:t=b(),meta:n,peaks:r={},filters:o=[],info:s={},ranges:u={},integrals:i={},selector:a,dependentVariables:c=[],...f}=e,l={id:t,meta:n,filters:o},{data:d=Ie(c[0].components)}=e;if(Array.isArray(s.nucleus)&&(s.nucleus=s.nucleus[0]),l.data={x:[],re:[],im:[],...d},"scaleFactor"in s){let{scaleFactor:p}=s,{re:g,im:y}=l.data;(0,v.xMultiply)(g,p,{output:g}),y&&(0,v.xMultiply)(y,p,{output:y})}a&&(l.selector=a);let m=(0,ne.isAnyArray)(d.im);if(l.info={phc0:0,phc1:0,nucleus:"1H",isFid:!1,isComplex:m,dimension:1,name:s?.name||t,...s},s.isFid&&s.reverse&&m){let{im:p}=l.data;(0,v.xMultiply)(p,-1,{output:p}),l.info.reverse=!1}return l.display={isVisible:!0,isPeaksMarkersVisible:!0,isRealSpectrumVisible:!0,isVisibleInDomain:!0,...e.display},l.peaks={values:[],options:{},...r},l.ranges={values:[],options:{sum:null,isSumConstant:!0,sumAuto:!0},...u},l.integrals={values:[],options:{},...i},{...f,...l}}function Ie(e){let t=e[0]?.data?.x||[],n=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(),n.reverse(),r&&r.reverse()),{x:t,re:n,im:r}}var h=require("ml-spectra-processing");var B={z:[[]],minX:0,minY:0,maxX:0,maxY:0},ke={re:B,im:B},je={rr:B};function C(e){let{id:t=b(),meta:n={},dependentVariables:r=[],info:o={},filters:s=[],zones:u=[],...i}=e,a={id:t,meta:n,filters:s};a.info={nucleus:["1H","1H"],isFid:!1,isComplex:!1,name:o?.name||b(),...o},a.originalInfo=structuredClone(a.info),a.display={isPositiveVisible:!0,isNegativeVisible:!0,isVisible:!0,dimension:2,...e.display,...e.display};let{data:c=r[0].components}=e;if(a.data={...a.info.isFid?ke:je,...c},a.originalData=structuredClone(a.data),!("spectrumSize"in o)){let f=o.isFid?"re":"rr",l=a.data[f].z.length,d=l>0?a.data[f].z[0].length:0;a.info.spectrumSize=[d,l]}if(!o.isFid){let f=a.data.rr,l=(0,h.matrixToArray)(f.z),{positive:d,negative:m}=(0,h.xNoiseSanPlot)(l),{min:p,max:g}=(0,h.xMinMaxValues)(l);a.data.rr={...f,minZ:p,maxZ:g},a.info.noise={positive:d,negative:m}}return a.zones={values:[],options:{},...u},{...i,...a}}var ie=require("ml-spectra-processing");var oe=require("is-any-array");function w(e,t=0){if((0,oe.isAnyArray)(e)){let n=e.at(t);if(n!==void 0)return n;throw new RangeError("An array with a index out of boundaries")}return e}var Le=new Set(["t1ir","T1"]);function se(e){let t=[];for(let n of e){let{info:{pulseSequence:r,isFid:o}}=n,{data:s,info:u,meta:{vdlistValues:i=[]}}=n;if(!(r&&Le.has(r))||i.length===0){t.push(n);continue}let c=o?"re":"rr",f={};for(let S in u)f[S]=w(u[S]);let{z:l,maxX:d,minX:m}=s[c],p=(0,ie.xSequentialFillFromTo)({from:m,to:d,size:l[0].length}),[g,y]=ze(n);for(let S=0;S<i.length;S++){let D={re:p,x:p};for(let O in s)D[Ve(O)]=s[O].z.at(g*(S+y));t.push(N({data:D,info:{...f,name:`${f.name}_${i[S]}`,dimension:1,vd:i[S]}}))}}return t}function Ve(e){return["rr","re"].includes(e)?"re":["im","ri","ir","ii"].includes(e)?"im":"x"}function ze(e){let{meta:{PAGE:t}}=e,n=!0;if(t){let r=o=>Number.parseFloat(o.replace(/[F|T]1=/,""));n=r(t[0])>r(t[2])}return n?[-1,1]:[1,0]}var Be=2,_e=1;function ae(e){let{spectra:t=[],molecules:n}=e,r=[];for(let o of t){let{info:s}=o;switch(s.dimension){case _e:r.push(N(o));break;case Be:r.push(C(o));break;default:throw new Error("dimension does not supported")}}return{molecules:n,spectra:se(r)}}function x(e,t){return JSON.parse(JSON.stringify(e),function(r,o){if(r in t){this[t[r]]=o;return}return o})}function _(e){if(e?.version===1)return e;let t={...e,version:1},n={j:"js",signal:"signals",integral:"integration",peak:"peaks",diaID:"diaIDs"};for(let r of t.spectra){if(r.ranges){let o=x(r.ranges,n);r.ranges=Array.isArray(o)?{values:o}:o}else if(r.zones){let o=x(r.zones,n);r.zones=Array.isArray(o)?{values:o}:o}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 U(e){if(e?.version===2)return e;let t={...e,version:2},n={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,n.peaks):r.ranges?r.ranges=x(r.ranges,n.ranges):r.zones&&(r.zones.values=Ue(r.zones.values));return t}function Ue(e){return e.map(t=>(t.signals&&(t.signals=t.signals.map(n=>{if(n.x&&n.y){let{x:{fromTo:r,...o},y:{fromTo:s,...u}}=n;n={...n,x:{...o,...r},y:{...u,...s}}}else{let{fromTo:r,deltaX:o,resolutionX:s,nucleusX:u,deltaY:i,resolutionY:a,nucleusY:c,shiftX:f,shiftY:l,...d}=n;n={...d,x:{from:r[0].from,to:r[0].to,delta:o,resolution:s,nucleus:u},y:{from:r[1].from,to:r[1].to,delta:i,resolution:a,nucleus:c}}}return n},[])),t),[])}var Ke={name:"apodization",label:"Apodization",value:{lineBroadening:1,gaussBroadening:0,lineBroadeningCenter:0}};function K(e){if(e?.version===3)return e;let t={...e,version:3};for(let n of t.spectra)if(Array.isArray(n?.filters)&&n?.filters.length>0){let r=n.filters.findIndex(o=>o.name==="lineBroadening");if(r!==-1){let o={...n.filters[r],...Ke};n.filters[r]=n.filters[r-1],n.filters[r-1]=o}}return t}function W(e){if(e?.version===4)return e;let{version:t,...n}=e,r=[],o={};for(let{source:i,...a}of n.spectra){let c={},{info:f={},display:l={}}=a;if(f?.dimension===2&&!i?.jcampURL)if(f.isFt)c.data={rr:a.data};else continue;if(i?.jcampURL){let{jcampURL:p,jcampSpectrumIndex:g}=i,y=p.match(/(?<baseURL>^\w+:\/{2}\w+\/)(?<relativePath>.*)/);o[p]||(o[p]={baseURL:y?.groups.baseURL||"",relativePath:y?.groups.relativePath||p.replace(/^\.\//,"")}),c.sourceSelector={files:[o[p].relativePath]},g!==void 0&&(c.sourceSelector.jcamp={index:g})}c.filters=We(a.filters);let{name:d,...m}=l;d&&(c.info={...f,name:d}),c.display=m,r.push({...a,...c})}let s={data:{...n,spectra:r},version:4},u={entries:Object.values(o)};return u.entries.length>0&&(s.data.source=u),s}function We(e=[]){let t=[];for(let n of e){let{name:r,value:o}=n;switch(r){case"zeroFilling":t.push({...n,value:{nbPoints:o}});break;case"shiftX":case"shift2DX":case"shift2DY":t.push({...n,value:{shift:o}});break;default:t.push({...n})}}return t}function X(e){if(e?.version===5)return e;let t={...e,version:5},n={originFrom:"originalFrom",originTo:"originalTo",originDelta:"originalDelta",originX:"originalX",originY:"originalY",originZ:"originalZ"};for(let r of t?.data?.spectra||[])for(let o of["peaks","ranges","zones"])r?.[o]&&(r[o]=x(r[o],n));return t}function Y(e){if(e?.version===6)return e;let t={...e,version:6};for(let n of t?.data?.spectra||[]){let{digitalFilter:r,fft:o,phaseCorrection:s}=Xe(n);o?.flag&&r?.flag&&s&&Math.floor(r.value.digitalFilterValue)%2>0&&(s.value.ph0-=180)}return t}function Xe(e,t=["phaseCorrection","fft","digitalFilter"]){let{filters:n=[]}=e,r={};for(let o of t)r[o]=n.find(s=>s.name===o);return r}function F(e,t="localStorage"){if(e?.version===7)return e;if(t==="nmrium")return le(e);let n={...e,version:7};for(let r in e.workspaces)n.workspaces[r]=le(n.workspaces[r]);return n}function le(e){let{formatting:{nuclei:t,panels:n}={nuclei:null,panels:null},version:r,...o}=e,s={...o};return t&&(s.nuclei=Ye(t)),n&&(s.panels=n),s}function Ye(e){let t=[],n={name:"nucleus",ppm:"ppmFormat",hz:"hzFormat"};for(let r in e)t.push(x(e[r],n));return t}function G(e){if(e?.version===7)return e;let t={...e,version:7};return t?.settings&&(t.settings=F(t.settings,"nmrium")),t}function A(e,t="localStorage"){if(e?.version===8)return e;if(t==="nmrium")return ce(e);let n={...e,version:8};for(let r in e.workspaces)n.workspaces[r]=ce(n.workspaces[r]);return n}function ce(e){let{version:t,...n}=e,r={...n};return r.display.panels=Ge(e),r}function Ge(e){let t={},n=e.display.panels;for(let r of Object.keys(n)){let{display:o,open:s}=n[r];t[r]={display:o,visible:o,open:s}}return t}function Z(e){if(e?.version===8)return e;let t={...e,version:8};t?.settings&&(t.settings=A(t.settings,"nmrium"));for(let n of t?.data?.spectra||[]){let{filters:r=[]}=n;for(let i=0;i<r.length;i++){let{flag:a,isDeleteAllow:c,label:f,...l}=r[i];r[i]={...l,enabled:a}}let o=r.findIndex(i=>i.name==="apodization");if(o!==-1){let i=r[o],{lineBroadening:a,gaussBroadening:c,lineBroadeningCenter:f}=i.value;i.value={exponential:{apply:!0,options:{lineBroadening:c>0?-a:a}}},c>0&&(i.value.gaussian={apply:!0,options:{lineBroadening:.6*c,lineBroadeningCenter:f}}),r[o]=i}let s=r.findIndex(i=>i.name==="apodizationDimension1"),u=r.findIndex(i=>i.name==="apodizationDimension2");if(s!==-1){let i=r[s],{shapes:a}=i.value.compose;i.value=ue(a)}if(u!==-1){let i=r[u],{shapes:a}=i.value.compose;i.value=ue(a)}}return t}function ue(e){let t={};for(let{shape:n}of e){let{kind:r,options:o}=n;if(r==="sineBell"){let{exponent:s,offset:u}=o,i=s===2?"sineSquare":"sineBell";t[i]={apply:!0,options:{offset:u}}}}return t}function $(e){let{version:t,plugins:n,...r}=e;return t===9?e:{version:9,plugins:{},...r}}var Ze=[_,U,K,W,X,Y,G,Z,$];function pe(e,t,n){let r=structuredClone(e),o=Object.entries(e?.plugins??{});for(let[i,{version:a}]of o){let c=n.get(i);if(!(c&&c.version>=a)){if(c){console.warn(`Plugin "${c.id}" is loaded with a version older (${c.version}) than the one used to save the state (${a}).
|
|
2
|
-
NMRium may fail to load the state.
|
|
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,u=()=>{let i=r.version;for(let a of n.values())for(let c of a.migrations){if(s.has(c)||i<c.minCore||c.maxCore&&i>c.maxCore)continue;if((r.plugins?.[a.id]?.version||0)===a.version)break;r=c.up(r),s.add(c)}};for(let i=e?.version||0;i<t;i++){let a=Ze[i];r=a(r),u()}u(),r.plugins||(r.plugins={});for(let i of n.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}var Se=require("filelist-utils");var me={SDF:"sdf",MOL:"mol",NMRIUM:"nmrium",JSON:"json",JCAMP:"jcamp",DX:"dx",JDX:"jdx",JDF:"jdf",NMREDATA:"nmredata",SMILES:"smiles",SMI:"smi"};function M(e){return e.includes(".")?e.replace(/^.*\./,"").toLowerCase():""}function E(e,t={},n){let{data:r,...o}=e;if(!r)return e;let{spectra:s=[]}=r,{keep1D:u=!0,keep2D:i=!0,onlyReal:a}=t,c=a?"ft":t.dataSelection||"both",f=[];for(let l of s){if(!l.info){f.push(l);continue}let{isFid:d,dimension:m,name:p}=l.info;if(!T(m===1&&!u,p,n)&&!T(m===2&&!i,p,n)&&!T(d&&c==="ft",p,n)&&!T(!d&&c==="fid",p,n))if(a&&!d)if(l.info.isComplex=!1,$e(l)){let{rr:g}=l.data;f.push({...l,data:{rr:g}})}else{let{re:g,x:y}=l.data;f.push({...l,data:{re:g,x:y}})}else f.push(l)}return{data:{...r,spectra:f},...o}}function T(e,t,n){return e?(n?.warn(`Skipping ${t} because it didn't match the import filters.`),!0):!1}function $e(e){let{info:t}=e;return t?.dimension===2}function I(e){let{nmriumState:t,plugins:n,options:r}=e;for(let o of n.values()){let s=o.onReadProcess?.onProcessing;s&&s(t,r)}}async function k(e,t,n={}){let{sourceSelector:r,converter:o,keepSource:s,logger:u}=n,i=[],a=[];for(let m of t.values()){let{onReadProcess:p}=m;p&&(p?.onFiles&&i.push(m),p?.supportedExtensions?.length&&p?.onFile&&a.push(m))}let c=await Promise.allSettled(i.map(m=>m.onReadProcess.onFiles(e,n))),f=[],l=await Promise.allSettled(e.files.flatMap(m=>{let p=M(m.name).toLowerCase();return a.flatMap(g=>{let{supportedExtensions:y,onFile:S}=g.onReadProcess;return y.includes(p)?(f.push({file:m,plugin:g}),S(m,{logger:u,sourceSelector:r,converter:o,keepSource:s})):[]})})),d={spectra:[],molecules:[]};for(let m=0;m<c.length;m++){let p=c[m];switch(p.status){case"fulfilled":{let{spectra:g=[],molecules:y=[]}=p.value||{};d.spectra.push(...g),d.molecules.push(...y);break}case"rejected":{let g=p.reason,y=i[m];n.logger?.error(`Load file collection with plugin ${y.id}@${y.version} fails with: ${g}`);break}}}for(let m=0;m<l.length;m++){let p=l[m];switch(p.status){case"fulfilled":{let{spectra:g=[],molecules:y=[]}=p.value||{};d.spectra.push(...g),d.molecules.push(...y);break}case"rejected":{let g=p.reason,{file:y,plugin:S}=f[m];n.logger?.error(`Load file ${y.relativePath} with plugin ${S.id}@${S.version} fails with: ${g}`);break}}}return d}var de=require("filelist-utils");var fe=require("filelist-utils"),q=Me(require("lodash.merge"),1),ge=require("ml-spectra-processing");async function j(e){let{nmriumObjectInput:t,options:n={},migrator:r,plugins:o}=e,s=r(t),{data:u,...i}=s;if(!u)return{...i};let a={data:{...u,spectra:[]},...i},c=a.data,{source:f,spectra:l,molecules:d}=c,m;f&&(m=await(0,fe.fileCollectionFromWebSource)(f,{unzip:{zipExtensions:["zip","nmredata"]}}));let p=[];for(let g of u.spectra)if(m){let{sourceSelector:y}=g,S=L({input:m,migrator:r,plugins:o,options:{...n,sourceSelector:y}}).then(D=>{let{nmriumState:{data:O}}=D,{spectra:De=[],molecules:J=[]}=O||{};J.length>0&&d.length===0&&d.push(...J);for(let Oe of De)l.push(qe(g,Je(Oe)))});p.push(S)}else{let{dimension:y}=g.info;if(y===1){if(!(0,ge.xIsEquallySpaced)(g.data)){n.logger?.error('The ".nmrium" file is corrupted; the X-axis values are not equally distant.');continue}l.push(N(g))}else y===2&&l.push(C(g))}return await Promise.allSettled(p),a}function qe(e,t){let{data:n,...r}=e;if("ranges"in t){let{data:o,...s}=t;return{...(0,q.default)(s,r),data:o}}else if("zones"in t){let{data:o,...s}=t;return{...(0,q.default)(s,r),data:o}}else return t}function Je(e){return{...e,id:b()}}async function ye(e){let{file:t,options:n={},migrator:r,plugins:o}=e,s=await t.arrayBuffer(),u=await(Qe(s)?He(s):t.text());return j({nmriumObjectInput:JSON.parse(u),plugins:o,migrator:r,options:n})}async function He(e){let t=await(0,de.fileCollectionFromZip)(e);if(t.files.length===0)throw new Error("compressed nmrium file is corrupted");return t.files[0].text()}function Qe(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 L(e){let{options:t={},input:n,migrator:r,plugins:o}=e,s=rt(et(n),t.sourceSelector?.files),u=nt(s);if(u)return{nmriumState:await ye({file:u,migrator:r,plugins:o,options:t}),containsNmrium:!0};let i=await k(s,o,t),a=E({version:9,data:i},t?.sourceSelector?.general,t.logger),{onLoadProcessing:c,experimentalFeatures:f}=t,l={...c,autoProcessing:c?.autoProcessing??!1,experimentalFeatures:f};return I({nmriumState:a,plugins:o,options:l}),{nmriumState:a,containsNmrium:!1}}function et(e){if(Array.isArray(e))throw new Error("For a set of fileCollectionItems pass a FileCollection instance");return tt(e)?e:new Se.FileCollection([e])}function tt(e){return typeof e=="object"&&"files"in e}function rt(e,t){return t?e.filter(n=>t.includes(n.relativePath)):e}function nt(e){return e.files.find(t=>M(t.name).toLowerCase()===me.NMRIUM)}function V(e,t){let n={};for(let r in e)t.includes(r)||(n[r]=e[r]);return n}var ot=["data","originalData","info","originalInfo","meta","customInfo"],it=["sourceSelector","originalData","originalInfo"];function Pe(e,t={}){let{version:n,data:r}=e;if(r.actionType)return e;let o={version:n,plugins:e.plugins},{includeData:s}=t;s!=="noData"&&(o.data=st({...r},s));let{includeSettings:u,includeView:i}=t;return u&&(o.settings=e.settings),i&&(o.view=e.view),o}function st(e,t="rawData"){let{spectra:n}=e;switch(t){case"dataSource":return at(e);case"rawData":return{...V(e,["source"]),spectra:n.map(ct)};default:return e}}function at(e){let{spectra:t}=e;if(!e.source)throw new Error("source property should exists for dataSource serialization");return{...e,spectra:t.map(lt)}}function lt(e){return V(e,ot)}function ct(e){let{data:t,info:n,originalData:r,originalInfo:o}=e,s=V(e,it);return s.data=r||t,s.info=o||n,s}var xe=require("filelist-utils");async function be(e){let{source:t,plugins:n,options:r={}}=e,{keepSource:o=!0,converter:s,...u}=r,i={source:t,spectra:[],molecules:[]},a=await(0,xe.fileCollectionFromWebSource)(t,{unzip:{zipExtensions:["zip","nmredata"]}}),{spectra:c=[],molecules:f=[]}=await k(a,n,{keepSource:o,converter:{...s,bruker:{keepFiles:!0,...Reflect.get(s??{},"bruker")}},...u});i.spectra.push(...c),i.molecules.push(...f);let l=E({version:9,data:i},r?.sourceSelector?.general),{onLoadProcessing:d}=u,m={filters:d?.filters,autoProcessing:d?.autoProcessing??!1,experimentalFeatures:r.experimentalFeatures};return I({nmriumState:l,plugins:n,options:m}),l}var z=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 n of t)this.registerPlugin(n)}migrate(t){return pe(t,this.version,this.plugins)}read(t,n={}){return L({input:t,migrator:this.migrate.bind(this),plugins:this.plugins,options:n})}readNMRiumObject(t,n){return j({nmriumObjectInput:t,options:n,plugins:this.plugins,migrator:this.migrate.bind(this)})}readFromWebSource(t,n){return be({source:t,options:n,plugins:this.plugins})}serializeNmriumState(t,n){return Pe(t,n)}};function ut(e,t){if(t>9)return 0;let n=-1;for(let r=0;r<e.length;r++)if(e[r].version>t){n=r;break}return n}var Ne=[{version:6,fun:F},{version:7,fun:A}];function he(e){let{version:t}=e||{},n=ut(Ne,t);if(n===-1)return{...e,version:9};let r=Ne.slice(n);for(let o of r)e=o.fun(e);return e}
|
|
File without changes
|