@zakodium/nmrium-core-plugins 0.1.5 → 0.1.6
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-plugins.js +17 -9
- package/package.json +2 -2
|
@@ -1,10 +1,18 @@
|
|
|
1
|
-
var Er=Object.defineProperty;var Ft=(e,t)=>{for(var n in t)Er(e,n,{get:t[n],enumerable:!0})};import{NMRiumCore as ns}from"@zakodium/nmrium-core";import{Filters1D as qr,Filters2D as _r}from"nmr-processing";import{getOneIfArray as Tr}from"@zakodium/nmrium-core";function te(e={},t={},n={}){e===null&&(e={}),typeof e=="string"&&(e={pulseSequence:e});let i=Array.isArray(e.pulseSequence)?e.pulseSequence[0]:e.pulseSequence||"";if(typeof i!="string")return e.dimension?`${e.dimension}d`:"";if(i=i.toLowerCase(),i.includes("zg")||i.includes("single_pulse_dec")||i.includes("udeft"))return"1d";if(i.includes("hsqct")||i.includes("invi")&&(i.includes("ml")||i.includes("di")))return"hsqctocsy";if(i.includes("hsqc")||i.includes("invi"))return"hsqc";if(i.includes("hmbc")||i.includes("inv4")&&i.includes("lp"))return"hmbc";if(i.includes("hmqc"))return"hmqc";if(i.includes("cosy"))return"cosy";if(i.includes("jres"))return"jres";if(i.includes("dosy"))return"dosy";if(i.includes("tocsy")||i.includes("mlev")||i.includes("dipsi"))return"tocsy";if(i.includes("noesy"))return"noesy";if(i.includes("roesy"))return"roesy";if(i.includes("dept"))return"dept";if(i.includes("jmod")||i.includes("apt"))return"aptjmod";if(i.includes("inad"))return"inadequate";if(i.includes("adeq"))return"adequate";let{prefix:r=""}=n,o=(Tr(t[`${r}SPECTYP`])||"").replace(/^<(.*)>$/,"$1").toLowerCase();return o.length>0&&o!=="undefined"?o:e.dimension?`${e.dimension}d`:""}import{getOneIfArray as xt}from"@zakodium/nmrium-core";var Or=["no","exponential","modifiedGaussian","sine","qsine","trap","user","sinc","qsinc","traf","trafs"];function Cr(e){return e in Dt}function _e(e,t){let{prefix:n="",index:i=0}=t,r=xt(e[`${n}WDW`],i),o=Or[r?Number(r):0],s={};if(!Cr(o))return s;let a=Dt[o];if(a){let{kind:l,parameters:c}=a,u={};for(let p in c){let g=c[p],{source:d,processor:h}=g;if(d){let f=xt(e[`${n}${d}`],i);if(!f)continue;let b=Number(f);u[p]=h?h(b):b}else g.value!==void 0&&(u[p]=g.value)}s[l]={apply:!0,options:u}}return s}var Dt={exponential:{kind:"exponential",parameters:{lineBroadening:{source:"LB"}}},modifiedGaussian:{kind:"gaussian",parameters:{lineBroadening:{source:"LB"},lineBroadeningCenter:{source:"GB"}}},sine:{kind:"sineBell",parameters:{offset:{source:"SSB",processor:e=>1/e},exponent:{value:1}}},qsine:{kind:"sineSquare",parameters:{offset:{source:"SSB",processor:e=>1/e}}},traf:{kind:"traf",parameters:{lineBroadening:{source:"LB"}}}};var St={sineBell:Nt({offset:0})},Pt={cosy:{...St},hmbc:{...St},hsqc:{sineBell:Nt({offset:.5})}},wr={...Pt};function Be(e="",t=1){let n=vr(e),i={},r=t===1?Pt[n||""]:wr[n||""];return r&&(i=structuredClone(r)),i}function Nt(e){return{apply:!0,options:e}}function vr(e){let n=e.toLowerCase().match(/cosy|hsqc|hmbc/);return n?n[0]:null}function At(e,t={}){let{prefix:n="",experiment:i=te(e)}=t;return e[`${n}WDW`]?{f2:_e(e,{...t,index:0}),f1:_e(e,{...t,index:1})}:{f2:Be(i,1),f1:Be(i,2)}}import{Filters1D as kr}from"nmr-processing";var Ue=["digitalFilter","backwardLinearPrediction","forwardLinearPrediction","apodization","zeroFilling","fft",["shiftX","phaseCorrection","baselineCorrection"]],$={};for(let e=0;e<Ue.length;e++){let t=Ue[e];for(let n of Array.isArray(t)?t:[t])$[n]=e}for(let e of Object.values(kr))e.name in $||($[e.name]=Ue.length);import{Filters2D as Lr}from"nmr-processing";var $e=["digitalFilter2D","blpDimension1","flpDimension1","apodizationDimension1","zeroFillingDimension1","fftDimension1","blpDimension2","flpDimension2","nusDimension2","apodizationDimension2","zeroFillingDimension2","fftDimension2","phaseCorrectionTwoDimensions",["shift2DX","shift2DY","symmetrizeCosyLike"]],j={};for(let e=0;e<$e.length;e++){let t=$e[e];for(let n of Array.isArray(t)?t:[t])j[n]=e}for(let e of Object.values(Lr))e.name in j||(j[e.name]=$e.length);var Br=new Set(["backwardLinearPrediction","forwardLinearPrediction","digitalFilter2D","phaseCorrectionTwoDimensions","blpDimension1","flpDimension1","apodizationDimension1","apodizationDimension2","zeroFillingDimension1","fftDimension1","blpDimension2","flpDimension2","zeroFillingDimension2","fftDimension2","nusDimension2","symmetrizeCosyLike"]);function Ur(e,t){let{filter:n,experimentalFeatures:i=!1}=t,{name:r}=n;({...qr,..._r})[r]&&(e.some(s=>s.name===r)||(i||!Br.has(r))&&e.push({...n,enabled:!0}))}function Mt(e,t={}){let{data:n}=e;if(!n)return;let{autoProcessing:i,experimentalFeatures:r}=t,o=(a,l)=>Ur(a,{...l,experimentalFeatures:r}),{spectra:s}=n;for(let a of s){let{data:l,info:c,meta:u,filters:p}=a,{dimension:g,isFid:d}=c;if(d){if(g===1){let h=l.re.length,{tdOff:f,digitalFilter:b}=c;if(b&&b>0&&o(p,{filter:{name:"digitalFilter",value:{digitalFilterValue:b}}}),!i)continue;f&&Math.abs(f)>0&&o(p,{filter:{name:"backwardLinearPrediction",value:{nbInputs:h/2}}}),o(p,{filter:{name:"apodization",value:{exponential:{apply:!0,options:{lineBroadening:1}}}}}),o(p,{filter:{name:"zeroFilling",value:{nbPoints:2*h}}}),o(p,{filter:{name:"fft",value:{}}}),o(p,{filter:{name:"phaseCorrection",value:$r(c)}}),p.sort((m,y)=>$[m.name]-$[y.name])}else if(g===2){if(!i||!r)continue;let h=l.re.z.length,f=l.re.z[0].length,{tdOff:b,experiment:m=""}=c,y=c.spectrumSize;Array.isArray(y)&&y.length>1?(y[0]<=f&&(y[0]=f*2),y[0]<=h&&(y[0]=h*2)):y=[f*2,2*h];let F=m.toLowerCase().includes("cosy");b&&Math.abs(b[0])>0&&o(p,{filter:{name:"blpDimension1",value:{nbInputs:f/2}}});let D=At(u,{experiment:m});o(p,{filter:{name:"apodizationDimension1",value:D.f2}}),o(p,{filter:{name:"zeroFillingDimension1",value:{nbPoints:y[0]}}}),o(p,{filter:{name:"fftDimension1",value:{}}}),u&&"nuslist"in u&&o(p,{filter:{name:"nusDimension2",value:{}}}),o(p,{filter:{name:"apodizationDimension2",value:D.f1}}),o(p,{filter:{name:"zeroFillingDimension2",value:{nbPoints:y[F?0:1]}}}),F?o(p,{filter:{name:"symmetrizeCosyLike",value:{}}}):o(p,{filter:{name:"phaseCorrectionTwoDimensions",value:{}}}),o(p,{filter:{name:"fftDimension2",value:{}}}),p.sort((N,x)=>j[N.name]-j[x.name])}}}}function $r(e){let{phc0:t=0,phc1:n=0}=e;return It([t,n])?{}:{ph0:t,ph1:n}}function It(e){return Array.isArray(e)?e.every(t=>!t&&t===0):It([e])}var ne=class{id="@zakodium/nmrium-core-plugins#AutoPostProcessingPlugin";version=1;migrations=[];onReadProcess;constructor(){this.onReadProcess={onProcessing:this.onPostProcessing.bind(this)}}onPostProcessing(t,n){Mt(t,n)}};function je(){return new ne}import{FileCollection as Sa}from"file-collection";var Rt=["acqus","acqu2s"],re=["procs","proc2s"];function Et(e){return e.is1D?jr(e):e.is2D?zr(e):{checked:!1,message:"Multi-dimensional n > 2 is not supported"}}function jr(e){let t=e.isFID?["acqus"]:["acqus","procs"],n=t.every(i=>e[i]);return{checked:n,message:n?"":`File: ${e[e.isFID?"fid":"1r"]?.relativePath} is ignored, files: ${t.join(",")} are required.`}}function zr(e){let t=e.isFID?Rt:Rt.concat(re),n=t.every(i=>e[i]);return n&&e.isFID&&re.some(i=>e[i])&&!re.every(i=>e[i])&&(n=!1,t.push(...re)),{checked:n,message:n?"":`File: ${e.name} is ignored, files: ${t.join(",")} are required.`}}function ze(e,t={}){let{logger:n,processingNumbers:i,experimentNumbers:r,dataSelection:o="both",keep1D:s=!0,keep2D:a=!0,onlyFirstProcessedData:l=!0}=t,c={},u=e.files.map(d=>d.relativePath);for(let d of e){let h,f,b,m=d.relativePath.split("/"),y=m.indexOf("pdata");if(y!==-1)h=Number(m[y+1]),f=Number(m[y-1]),b=m.slice(0,-3).join("/");else if(Jr(d,u)){let D=m.indexOf(d.name);f=Number(m[D-1]),b=m.slice(0,-1).join("/")}else continue;if(Number.isNaN(f)&&(f=void 0),Number.isNaN(h)&&(h=void 0),r&&!r.includes(f))continue;c[b]||(c[b]={name:b,expno:f,processedData:{},fileCollectionItems:[]});let F=c[b];if(d.name==="vdlist"&&(F.vdlist=d),d.name==="difflist"&&(F.difflist=d),h){F.processedData||(F.processedData={}),F.processedData[h]||(F.processedData[h]={fileCollectionItems:[],name:b,expno:f,procno:h});let D=F.processedData[h];D.fileCollectionItems.push(d),d.name.match(/^(?:1r|1i|2rr|2ir|2ii|2ri|procs|proc2s|title|integrals.txt)$/)&&(D[d.name]=d),d.name==="2rr"&&(D.is2D=!0,D.isFT=!0),d.name==="1r"&&(D.is1D=!0,D.isFT=!0)}else F.fileCollectionItems.push(d),d.name.match(/^(?:ser|fid|acqus|acqu2s|nuslist)$/)&&(F[d.name]=d),d.name==="ser"&&(F.is2D=!0,F.isFID=!0),d.name==="fid"&&(F.is1D=!0,F.isFID=!0);d.name==="QuantFactorSample.xml"&&(F.quantFactorSample=d)}if(i)for(let d in c){let h=c[d].processedData,f={};for(let b in h)i.includes(Number.parseInt(b,10))&&(f[b]=h[b]);c[d].processedData=f}else if(l)for(let d in c){let h=c[d].processedData,f=Object.keys(h??{}).sort((b,m)=>Number(b)-Number(m))[0];h&&f!==void 0&&(c[d].processedData={firstProcessedNumber:h[f]})}let p=Xr(n),g=[];for(let d in c){let h=c[d],{processedData:f,...b}=h;if(p(h,o)){let y=Object.keys(f??{});if(f&&y.length>0){let F=f[y[0]];F.procs&&(b.fileCollectionItems.push(F.procs),b.procs=F.procs),F.proc2s&&(b.fileCollectionItems.push(F.proc2s),b.proc2s=F.proc2s),F["integrals.txt"]&&(b.integrals=F["integrals.txt"])}g.push(b)}let m="ser"in b||"fid"in b;if(o==="fid"||o==="preferFID"&&m){n?.warn("Skipping FT data because it does not match the import filters");continue}for(let y in f){let F=f[y];(F["1r"]||F["2rr"])&&(b.acqus&&F.fileCollectionItems.push(b.acqus),b.acqu2s&&F.fileCollectionItems.push(b.acqu2s),b.vdlist&&(F.vdlist=b.vdlist),g.push({integrals:F["integrals.txt"],acqus:b.acqus,acqu2s:b.acqu2s,...F}))}}return s||(n?.warn("Skipping 1D data because it does not match the import filters"),g=g.filter(d=>!d.is1D)),a||(n?.warn("Skipping 2D data because it does not match the import filters"),g=g.filter(d=>!d.is2D)),Wr(g,t.logger)}function Wr(e,t){return e.filter(n=>{let{checked:i,message:r}=Et(n);return i||t?.warn(r),i})}function Jr(e,t){return e.name.match(/^(?:ser|acqus|acqu2s|nuslist|vdlist|difflist|QuantFactorSample.xml)$/)||e.name.match(/^fid$/)&&t.includes(e.relativePath.replace(/fid$/,"acqus"))}function Xr(e){return(t,n)=>{let{processedData:i}=t,r=Object.keys(i??{}),o=i&&r.length>0&&["1r","1i","2rr"].some(u=>u in i[r[0]]),s="ser"in t||"fid"in t,c=s&&(n!=="ft"&&n!=="preferFT"||n==="preferFT"&&!o);return s&&!c&&e?.warn("Skipping RAW data because it does not match import filters"),c}}function ie(e){if(e===void 0||Array.isArray(e)&&e.length===0)return{epoch:null,date:""};let t=e[0]*1e3;return{epoch:t,date:new Date(t).toUTCString()}}function oe(e,t){for(let n in t.meta)e.meta[n]===void 0&&(e.meta[n]=t.meta[n]);for(let n in t.info)e.info[n]===void 0&&(e.info[n]=t.info[n]);for(let n in e.meta)Array.isArray(e.meta[n])||(e.meta[n]=[e.meta[n]])}import{convert as Vr}from"jcampconverter";async function k(e,t){if(!e)return Tt();let n=await e.text(),{keepRecordsRegExp:i=/.*/}=t,r=Vr(n,{keepRecordsRegExp:i});return r.flatten.length===0?Tt():r.flatten[0]}function Tt(){return{info:{},meta:{},tmp:{},spectra:[],ntuples:{}}}async function Ot(e){let n=(await e.integrals?.text())?.split(/\r?\n/).slice(3).filter(Boolean)??[],i=[];for(let r=1;r<n.length;r++){let o=n[r].replace(/^\s*/,"").replaceAll(/[\s\t]+/g,";").match(/\d+;(?<from>[0-9.]+);(?<to>[0-9.]+);(?<integration>[0-9.]+)/)?.groups;if(o){let{from:s,to:a,integration:l}=o;i.push({from:Number.parseFloat(s),to:Number.parseFloat(a),integration:Number.parseFloat(l)})}}return i}function We(e,t="utf8"){return new TextDecoder(t).decode(e)}var Hr=new TextEncoder;function Ct(e){return Hr.encode(e)}var Yr=1024*8,Gr=(()=>{let e=new Uint8Array(4),t=new Uint32Array(e.buffer);return!((t[0]=1)&e[0])})(),Je={int8:globalThis.Int8Array,uint8:globalThis.Uint8Array,int16:globalThis.Int16Array,uint16:globalThis.Uint16Array,int32:globalThis.Int32Array,uint32:globalThis.Uint32Array,uint64:globalThis.BigUint64Array,int64:globalThis.BigInt64Array,float32:globalThis.Float32Array,float64:globalThis.Float64Array},O=class e{buffer;byteLength;byteOffset;length;offset;lastWrittenByte;littleEndian;_data;_mark;_marks;constructor(t=Yr,n={}){let i=!1;typeof t=="number"?t=new ArrayBuffer(t):(i=!0,this.lastWrittenByte=t.byteLength);let r=n.offset?n.offset>>>0:0,o=t.byteLength-r,s=r;(ArrayBuffer.isView(t)||t instanceof e)&&(t.byteLength!==t.buffer.byteLength&&(s=t.byteOffset+r),t=t.buffer),i?this.lastWrittenByte=o:this.lastWrittenByte=0,this.buffer=t,this.length=o,this.byteLength=o,this.byteOffset=s,this.offset=0,this.littleEndian=!0,this._data=new DataView(this.buffer,s,o),this._mark=0,this._marks=[]}available(t=1){return this.offset+t<=this.length}isLittleEndian(){return this.littleEndian}setLittleEndian(){return this.littleEndian=!0,this}isBigEndian(){return!this.littleEndian}setBigEndian(){return this.littleEndian=!1,this}skip(t=1){return this.offset+=t,this}back(t=1){return this.offset-=t,this}seek(t){return this.offset=t,this}mark(){return this._mark=this.offset,this}reset(){return this.offset=this._mark,this}pushMark(){return this._marks.push(this.offset),this}popMark(){let t=this._marks.pop();if(t===void 0)throw new Error("Mark stack empty");return this.seek(t),this}rewind(){return this.offset=0,this}ensureAvailable(t=1){if(!this.available(t)){let i=(this.offset+t)*2,r=new Uint8Array(i);r.set(new Uint8Array(this.buffer)),this.buffer=r.buffer,this.length=i,this.byteLength=i,this._data=new DataView(this.buffer)}return this}readBoolean(){return this.readUint8()!==0}readInt8(){return this._data.getInt8(this.offset++)}readUint8(){return this._data.getUint8(this.offset++)}readByte(){return this.readUint8()}readBytes(t=1){return this.readArray(t,"uint8")}readArray(t,n){let i=Je[n].BYTES_PER_ELEMENT*t,r=this.byteOffset+this.offset,o=this.buffer.slice(r,r+i);if(this.littleEndian===Gr&&n!=="uint8"&&n!=="int8"){let a=new Uint8Array(this.buffer.slice(r,r+i));a.reverse();let l=new Je[n](a.buffer);return this.offset+=i,l.reverse(),l}let s=new Je[n](o);return this.offset+=i,s}readInt16(){let t=this._data.getInt16(this.offset,this.littleEndian);return this.offset+=2,t}readUint16(){let t=this._data.getUint16(this.offset,this.littleEndian);return this.offset+=2,t}readInt32(){let t=this._data.getInt32(this.offset,this.littleEndian);return this.offset+=4,t}readUint32(){let t=this._data.getUint32(this.offset,this.littleEndian);return this.offset+=4,t}readFloat32(){let t=this._data.getFloat32(this.offset,this.littleEndian);return this.offset+=4,t}readFloat64(){let t=this._data.getFloat64(this.offset,this.littleEndian);return this.offset+=8,t}readBigInt64(){let t=this._data.getBigInt64(this.offset,this.littleEndian);return this.offset+=8,t}readBigUint64(){let t=this._data.getBigUint64(this.offset,this.littleEndian);return this.offset+=8,t}readChar(){return String.fromCharCode(this.readInt8())}readChars(t=1){let n="";for(let i=0;i<t;i++)n+=this.readChar();return n}readUtf8(t=1){return We(this.readBytes(t))}decodeText(t=1,n="utf8"){return We(this.readBytes(t),n)}writeBoolean(t){return this.writeUint8(t?255:0),this}writeInt8(t){return this.ensureAvailable(1),this._data.setInt8(this.offset++,t),this._updateLastWrittenByte(),this}writeUint8(t){return this.ensureAvailable(1),this._data.setUint8(this.offset++,t),this._updateLastWrittenByte(),this}writeByte(t){return this.writeUint8(t)}writeBytes(t){this.ensureAvailable(t.length);for(let n=0;n<t.length;n++)this._data.setUint8(this.offset++,t[n]);return this._updateLastWrittenByte(),this}writeInt16(t){return this.ensureAvailable(2),this._data.setInt16(this.offset,t,this.littleEndian),this.offset+=2,this._updateLastWrittenByte(),this}writeUint16(t){return this.ensureAvailable(2),this._data.setUint16(this.offset,t,this.littleEndian),this.offset+=2,this._updateLastWrittenByte(),this}writeInt32(t){return this.ensureAvailable(4),this._data.setInt32(this.offset,t,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeUint32(t){return this.ensureAvailable(4),this._data.setUint32(this.offset,t,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeFloat32(t){return this.ensureAvailable(4),this._data.setFloat32(this.offset,t,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeFloat64(t){return this.ensureAvailable(8),this._data.setFloat64(this.offset,t,this.littleEndian),this.offset+=8,this._updateLastWrittenByte(),this}writeBigInt64(t){return this.ensureAvailable(8),this._data.setBigInt64(this.offset,t,this.littleEndian),this.offset+=8,this._updateLastWrittenByte(),this}writeBigUint64(t){return this.ensureAvailable(8),this._data.setBigUint64(this.offset,t,this.littleEndian),this.offset+=8,this._updateLastWrittenByte(),this}writeChar(t){return this.writeUint8(t.charCodeAt(0))}writeChars(t){for(let n=0;n<t.length;n++)this.writeUint8(t.charCodeAt(n));return this}writeUtf8(t){return this.writeBytes(Ct(t))}toArray(){return new Uint8Array(this.buffer,this.byteOffset,this.lastWrittenByte)}getWrittenByteLength(){return this.lastWrittenByte-this.byteOffset}_updateLastWrittenByte(){this.offset>this.lastWrittenByte&&(this.lastWrittenByte=this.offset)}};import{isAnyArray as Zr}from"is-any-array";import{matrixCreateEmpty as Kr,xSequentialFillFromStep as Qr}from"ml-spectra-processing";function wt(e){for(let t in e){let{z:n}=e[t],{minX:i,minY:r,maxX:o,maxY:s}=e[t];if(i>o){[i,o]=[o,i];for(let a of n)a.reverse()}r>s&&(n.reverse(),[r,s]=[s,r]),e[t]={...e[t],z:n,minX:i,minY:r,maxY:s,maxX:o}}}function se(e,t){let{x:n,minMax:i,nbSubSpectra:r,template:o}=t;e.spectra||(e.spectra=[]);for(let s=0;s<r;s++){let a={};for(let l in i)a[l]=i[l].z[s];e.spectra.push({...o,data:{...a,x:n}})}}function ce(e,t,n={}){let i={};for(let h in e)e[h]&&(i[h]=new O(e[h]));let r=ae(t.meta.SI),o=ae(t.meta.SW_p),s=ae(t.meta.SF),a=s,l=ae(t.shiftOffsetVal||t.meta.OFFSET);t.meta.observeFrequency=s,t.meta.brukerReference=a,t.meta.DATATYPE="NMR Spectrum";let c=Number.parseInt(t.meta.BYTORDP,10);c=c?0:1;let u=t.meta.nbSubSpectra||1;if(c)for(let h in i)i[h].setLittleEndian();else for(let h in i)i[h].setBigEndian();let p={dataType:"NMR Spectrum",nbPoints:r,firstX:l,lastX:l-o/s,xUnit:"PPM",yUnit:"Arbitrary",isXYdata:!0,isFT:!0,nucleus:t.meta.NUC1,observeFrequency:s,title:t.meta.TITLE,deltaX:-(o/s)/(r-1)},g=p.deltaX,d=Qr({from:l,step:g,size:r});if(u===1){let h={};for(let f in i){let b=i[f],m=new Float64Array(r);for(let y=0;y<r;++y)m[y]=b.readInt32();h[f]=m}t.spectra.push({...p,data:{...h,x:d}})}else{let{meta:h}=t,f=Number(h.SF[1]),b=Number(h.SW_p[1]||h.SW[1]),m=Number(h.OFFSET[1]),y=m-b/f,F={};for(let D in i)F[D]={minY:m,maxY:y,minX:d[0],maxX:d.at(-1),...ei(h,i[D])};wt(F),n.keepSpectra&&se(t,{minMax:F,x:d,nbSubSpectra:u,template:p}),t.minMax=F}}function ae(e){return Number(Zr(e)?e[0]:e)}function ei(e,t){let n=e.SI.slice().reverse(),i=e.XDIM.slice().reverse(),r=n.map((d,h)=>Number.parseInt(String(d/i[h]),10)),[o,s]=n,[a,l]=i,c=Kr({nbRows:o,nbColumns:s}),[u,p]=[Number.MAX_SAFE_INTEGER,Number.MIN_SAFE_INTEGER],g=[];for(let d=0;d<r[0];d++)for(let h=0;h<r[1];h++){let f=h*l,b=d*a;g.push([b,f])}for(let[d,h]of g)for(let f=0;f<a;f++)for(let b=0;b<l;b++){let m=t.readInt32();u>m&&(u=m),p<m&&(p=m),c[f+d][b+h]=m}return{z:c,minZ:u,maxZ:p}}import{createStepArray as ii,xMinMaxValues as oi}from"ml-spectra-processing";var W={};Ft(W,{DQD:()=>ri,QF:()=>ti,QSEQ:()=>z,QSIM:()=>ni});var ti=0,ni=1,z=2,ri=3;function le(e,t,n){let i=Number.parseInt(t.meta.TD[0],10),r=new O(e),o=t.meta.nbSubSpectra||1,s=t.meta.AQ_mod,l=Number.parseInt(t.meta.DTYPA,10)===2,c=Number.parseFloat(t.meta.SW_h[0]),u=Number.parseFloat(t.meta.SFO1[0]);t.meta.DATATYPE="NMR FID";let p=1/(2*c),g=i*p,d=Number.parseInt(t.meta.BYTORDA,10);d=d?0:1,d?r.setLittleEndian():r.setBigEndian();let h=s===2?p:2*p,f=si({nbSubSpectra:o,isFloat:l,aqMode:s,td:i}),b={dataType:"NMR FID",dataTable:"(X++(R..R))",nbPoints:f,firstX:0,lastX:g,nucleus:t.meta.NUC1,xUnit:"Sec",yUnit:"Arbitrary",isXYdata:!0,isFID:!0,observeFrequency:u,title:t.meta.TITLE,deltaX:h},m=ii({length:f,step:h});if(o<2){let y=kt(r,{nbPoints:f,isFloat:l,aqMode:s});t.spectra=[{data:{x:m,...y},...b}]}else{let y={minX:m[0],maxX:m.at(-1),minY:0,maxY:o,minZ:0,maxZ:0},F=s===2?{re:{z:[],...y}}:{re:{z:[],...y},im:{z:[],...y}},D={re:{min:Number.MAX_SAFE_INTEGER,max:Number.MIN_SAFE_INTEGER},im:{min:Number.MAX_SAFE_INTEGER,max:Number.MIN_SAFE_INTEGER}};for(let N=0;N<o;N++){let x=kt(r,{nbPoints:f,isFloat:l,aqMode:s});D.re=vt(x.re,D.re),D.im=vt(x.im??new Float64Array,D.im),F.re.z.push(x.re),F.im&&x.im&&F.im.z.push(x.im)}F.re={...F.re,minZ:D.re.min,maxZ:D.re.max},F.im={...F.im,minZ:D.im.min,maxZ:D.im.max},n.keepSpectra&&se(t,{minMax:F,x:m,nbSubSpectra:o,template:b}),t.minMax=F}}function vt(e,t){let{min:n,max:i}=oi(e),{min:r,max:o}=t;return{min:Math.min(r,n),max:Math.max(o,i)}}function kt(e,t){let{nbPoints:n,isFloat:i,aqMode:r}=t,o={re:new Float64Array(n),im:null},s=i?"readFloat64":"readInt32";if(r===2)for(let a=0;a<n;a++)o.re[a]=e[s]();else{o.im=new Float64Array(n);for(let a=0;a<n;a++)o.re[a]=e[s](),o.im[a]=e[s]()}return o}function si(e){let{nbSubSpectra:t,isFloat:n,aqMode:i,td:r}=e,o=r;if(t>1){let s=n?128:256;o=Math.trunc(Math.ceil(r/s)*s)}return i===2?o:o/2>>0}async function Lt(e,t){let n={},i=[],r=e["1r"]||e["1i"]?["1r","1i"]:["fid"];function o(a,l){return a.then(c=>{n[l]=c})}for(let a of r){let l=e[a];l&&i.push(o(l.arrayBuffer(),a))}i.push(k(e.procs,t).then(a=>{n.procs=a}),k(e.acqus,t).then(a=>{n.acqus=a})),e.quantFactorSample&&i.push(li(e).then(a=>{n.ereticFactor=a})),e.integrals&&i.push(Ot(e).then(a=>{n.integrals=a}));let s=ai(e);return s&&i.push(s.text().then(a=>{n.titleFile=a})),await Promise.all(i),ci(n)}function ai(e){if("title"in e&&e.title)return e.title}function ci(e){let{procs:t,acqus:n,integrals:i,ereticFactor:r,titleFile:o}=e,s={...t};oe(s,n);let a={...s.info};s.info=a;let l={...s.meta};s.meta=l;let{epoch:c,date:u}=ie(l.DATE);return c!==null&&Object.assign(a,{epoch:c,date:u}),i&&Object.assign(s,{integrals:i}),r&&(a.ereticFactor=r),o&&(l.TITLE_FILE=o),e["1r"]||e["1i"]?ce({re:e["1r"],im:e["1i"]},s):e.fid&&le(e.fid,s),s}async function li(e){let n=(await e.quantFactorSample?.text())?.match(/<Application[\w\W]+<Eretic_Factor>(?<ereticFactor>[\d.]+)/);return Number(n?.groups?.ereticFactor)}function Xe(e,t){for(let n in t.meta)n in e.meta?(Array.isArray(e.meta[n])||(e.meta[n]=[e.meta[n]]),e.meta[n].push(t.meta[n])):e.meta[n]===void 0&&(e.meta[n]=[t.meta[n]]);return e}async function qt(e,t){let n={},i=[],r=["2rr","2ri","2ir","2ii","ser"];function o(s,a){return s.then(l=>{n[a]=l})}for(let s of r){let a=e[s];a&&i.push(o(a.arrayBuffer(),s))}if(i.push(o(k(e.procs,t),"procs"),o(k(e.proc2s,t),"proc2s"),o(k(e.acqus,t),"acqus"),o(k(e.acqu2s,t),"acqu2s")),"nuslist"in e&&e.nuslist){let s=e.nuslist;i.push(o(s.text(),"nuslist"))}return e.vdlist&&i.push(o(e.vdlist.text(),"vdlist")),e.difflist&&i.push(o(e.difflist.text(),"difflist")),await Promise.all(i),mi(n,t)}function mi(e,t){let n=Xe(e.procs,e.proc2s),i=Xe(e.acqus,e.acqu2s);oe(n,i);let{epoch:r,date:o}=ie(n.meta.DATE);if(o.length>0&&(n.info={...n.info,epoch:r,date:o}),e.nuslist&&(n.info.nuslist=e.nuslist.split(/\r?\n/).filter(Boolean).map(Number.parseFloat)),e.vdlist){let f=[];for(let b of e.vdlist.split(`
|
|
2
|
-
`)){if(!b)continue;let[m,y]=b.trim().match(/\s*([\d.]+)\s*([a-zA-Z]+)/)?.slice(1)||[];y&&
|
|
3
|
-
`)){if(!b)continue;let[m]=b.trim().match(/\s*([\d.]+)\s*/)?.slice(1)||[];
|
|
1
|
+
var Yr=Object.defineProperty;var Nt=(e,t)=>{for(var n in t)Yr(e,n,{get:t[n],enumerable:!0})};import{NMRiumCore as _s}from"@zakodium/nmrium-core";import{Filters1D as ii,Filters2D as oi}from"nmr-processing";import{getOneIfArray as Kr}from"@zakodium/nmrium-core";function te(e={},t={},n={}){e===null&&(e={}),typeof e=="string"&&(e={pulseSequence:e});let i=Array.isArray(e.pulseSequence)?e.pulseSequence[0]:e.pulseSequence||"";if(typeof i!="string")return e.dimension?`${e.dimension}d`:"";if(i=i.toLowerCase(),i.includes("zg")||i.includes("single_pulse_dec")||i.includes("udeft"))return"1d";if(i.includes("hsqct")||i.includes("invi")&&(i.includes("ml")||i.includes("di")))return"hsqctocsy";if(i.includes("hsqc")||i.includes("invi"))return"hsqc";if(i.includes("hmbc")||i.includes("inv4")&&i.includes("lp"))return"hmbc";if(i.includes("hmqc"))return"hmqc";if(i.includes("cosy"))return"cosy";if(i.includes("jres"))return"jres";if(i.includes("dosy"))return"dosy";if(i.includes("tocsy")||i.includes("mlev")||i.includes("dipsi"))return"tocsy";if(i.includes("noesy"))return"noesy";if(i.includes("roesy"))return"roesy";if(i.includes("dept"))return"dept";if(i.includes("jmod")||i.includes("apt"))return"aptjmod";if(i.includes("inad"))return"inadequate";if(i.includes("adeq"))return"adequate";let{prefix:r=""}=n,o=(Kr(t[`${r}SPECTYP`])||"").replace(/^<(.*)>$/,"$1").toLowerCase();return o.length>0&&o!=="undefined"?o:e.dimension?`${e.dimension}d`:""}import{getOneIfArray as At}from"@zakodium/nmrium-core";var Zr=["no","exponential","modifiedGaussian","sine","qsine","trap","user","sinc","qsinc","traf","trafs"];function Qr(e){return e in Mt}function Be(e,t){let{prefix:n="",index:i=0}=t,r=At(e[`${n}WDW`],i),o=Zr[r?Number(r):0],s={};if(!Qr(o))return s;let a=Mt[o];if(a){let{kind:l,parameters:c}=a,u={};for(let f in c){let d=c[f],{source:g,processor:h}=d;if(g){let p=At(e[`${n}${g}`],i);if(!p)continue;let b=Number(p);u[f]=h?h(b):b}else d.value!==void 0&&(u[f]=d.value)}s[l]={apply:!0,options:u}}return s}var Mt={exponential:{kind:"exponential",parameters:{lineBroadening:{source:"LB"}}},modifiedGaussian:{kind:"gaussian",parameters:{lineBroadening:{source:"LB"},lineBroadeningCenter:{source:"GB"}}},sine:{kind:"sineBell",parameters:{offset:{source:"SSB",processor:e=>1/e},exponent:{value:1}}},qsine:{kind:"sineSquare",parameters:{offset:{source:"SSB",processor:e=>1/e}}},traf:{kind:"traf",parameters:{lineBroadening:{source:"LB"}}}};var It={sineBell:Et({offset:0})},Rt={cosy:{...It},hmbc:{...It},hsqc:{sineBell:Et({offset:.5})}},ei={...Rt};function Ue(e="",t=1){let n=ti(e),i={},r=t===1?Rt[n||""]:ei[n||""];return r&&(i=structuredClone(r)),i}function Et(e){return{apply:!0,options:e}}function ti(e){let n=e.toLowerCase().match(/cosy|hsqc|hmbc/);return n?n[0]:null}function Tt(e,t={}){let{prefix:n="",experiment:i=te(e)}=t;return e[`${n}WDW`]?{f2:Be(e,{...t,index:0}),f1:Be(e,{...t,index:1})}:{f2:Ue(i,1),f1:Ue(i,2)}}import{Filters1D as ni}from"nmr-processing";var $e=["digitalFilter","backwardLinearPrediction","forwardLinearPrediction","apodization","zeroFilling","fft",["shiftX","phaseCorrection","baselineCorrection"]],U={};for(let e=0;e<$e.length;e++){let t=$e[e];for(let n of Array.isArray(t)?t:[t])U[n]=e}for(let e of Object.values(ni))e.name in U||(U[e.name]=$e.length);import{Filters2D as ri}from"nmr-processing";var ze=["digitalFilter2D","blpDimension1","flpDimension1","apodizationDimension1","zeroFillingDimension1","fftDimension1","blpDimension2","flpDimension2","nusDimension2","apodizationDimension2","zeroFillingDimension2","fftDimension2","phaseCorrectionTwoDimensions",["shift2DX","shift2DY","symmetrizeCosyLike"]],$={};for(let e=0;e<ze.length;e++){let t=ze[e];for(let n of Array.isArray(t)?t:[t])$[n]=e}for(let e of Object.values(ri))e.name in $||($[e.name]=ze.length);var si=new Set(["backwardLinearPrediction","forwardLinearPrediction","digitalFilter2D","phaseCorrectionTwoDimensions","blpDimension1","flpDimension1","apodizationDimension1","apodizationDimension2","zeroFillingDimension1","fftDimension1","blpDimension2","flpDimension2","zeroFillingDimension2","fftDimension2","nusDimension2","symmetrizeCosyLike"]);function ai(e,t){let{filter:n,experimentalFeatures:i=!1}=t,{name:r}=n;({...ii,...oi})[r]&&(e.some(s=>s.name===r)||(i||!si.has(r))&&e.push({...n,enabled:!0}))}function Ot(e,t={}){let{data:n}=e;if(!n)return;let{autoProcessing:i,experimentalFeatures:r}=t,o=(a,l)=>ai(a,{...l,experimentalFeatures:r}),{spectra:s}=n;for(let a of s){let{data:l,info:c,meta:u,filters:f}=a,{dimension:d,isFid:g}=c;if(g){if(d===1){let h=l.re.length,{tdOff:p,digitalFilter:b}=c;if(b&&b>0&&o(f,{filter:{name:"digitalFilter",value:{digitalFilterValue:b}}}),!i)continue;p&&Math.abs(p)>0&&o(f,{filter:{name:"backwardLinearPrediction",value:{nbInputs:h/2}}}),o(f,{filter:{name:"apodization",value:{exponential:{apply:!0,options:{lineBroadening:1}}}}}),o(f,{filter:{name:"zeroFilling",value:{nbPoints:2*h}}}),o(f,{filter:{name:"fft",value:{}}}),o(f,{filter:{name:"phaseCorrection",value:ci(c)}}),f.sort((m,y)=>U[m.name]-U[y.name])}else if(d===2){if(!i||!r)continue;let h=l.re.z.length,p=l.re.z[0].length,{tdOff:b,experiment:m=""}=c,y=c.spectrumSize;Array.isArray(y)&&y.length>1?(y[0]<=p&&(y[0]=p*2),y[0]<=h&&(y[0]=h*2)):y=[p*2,2*h];let F=m.toLowerCase().includes("cosy");b&&Math.abs(b[0])>0&&o(f,{filter:{name:"blpDimension1",value:{nbInputs:p/2}}});let x=Tt(u,{experiment:m});o(f,{filter:{name:"apodizationDimension1",value:x.f2}}),o(f,{filter:{name:"zeroFillingDimension1",value:{nbPoints:y[0]}}}),o(f,{filter:{name:"fftDimension1",value:{}}}),u&&"nuslist"in u&&o(f,{filter:{name:"nusDimension2",value:{}}}),o(f,{filter:{name:"apodizationDimension2",value:x.f1}}),o(f,{filter:{name:"zeroFillingDimension2",value:{nbPoints:y[F?0:1]}}}),F?o(f,{filter:{name:"symmetrizeCosyLike",value:{}}}):o(f,{filter:{name:"phaseCorrectionTwoDimensions",value:{}}}),o(f,{filter:{name:"fftDimension2",value:{}}}),f.sort((N,D)=>$[N.name]-$[D.name])}}}}function ci(e){let{phc0:t=0,phc1:n=0}=e;return Ct([t,n])?{}:{ph0:t,ph1:n}}function Ct(e){return Array.isArray(e)?e.every(t=>!t&&t===0):Ct([e])}var ne=class{id="@zakodium/nmrium-core-plugins#AutoPostProcessingPlugin";version=1;migrations=[];onReadProcess;constructor(){this.onReadProcess={onProcessing:this.onPostProcessing.bind(this)}}onPostProcessing(t,n){Ot(t,n)}};function Je(){return new ne}import{FileCollection as ic}from"file-collection";var wt=["acqus","acqu2s"],re=["procs","proc2s"];function vt(e){return e.is1D?li(e):e.is2D?mi(e):{checked:!1,message:"Multi-dimensional n > 2 is not supported"}}function li(e){let t=e.isFID?["acqus"]:["acqus","procs"],n=t.every(i=>e[i]);return{checked:n,message:n?"":`File: ${e[e.isFID?"fid":"1r"]?.relativePath} is ignored, files: ${t.join(",")} are required.`}}function mi(e){let t=e.isFID?wt:wt.concat(re),n=t.every(i=>e[i]);return n&&e.isFID&&re.some(i=>e[i])&&!re.every(i=>e[i])&&(n=!1,t.push(...re)),{checked:n,message:n?"":`File: ${e.name} is ignored, files: ${t.join(",")} are required.`}}function We(e,t={}){let{logger:n,processingNumbers:i,experimentNumbers:r,dataSelection:o="both",keep1D:s=!0,keep2D:a=!0,onlyFirstProcessedData:l=!0}=t,c={},u=e.files.map(g=>g.relativePath);for(let g of e){let h,p,b,m=g.relativePath.split("/"),y=m.indexOf("pdata");if(y!==-1)h=Number(m[y+1]),p=Number(m[y-1]),b=m.slice(0,-3).join("/");else if(pi(g,u)){let x=m.indexOf(g.name);p=Number(m[x-1]),b=m.slice(0,-1).join("/")}else continue;if(Number.isNaN(p)&&(p=void 0),Number.isNaN(h)&&(h=void 0),r&&!r.includes(p))continue;c[b]||(c[b]={name:b,expno:p,processedData:{},fileCollectionItems:[]});let F=c[b];if(g.name==="vdlist"&&(F.vdlist=g),g.name==="difflist"&&(F.difflist=g),h){F.processedData||(F.processedData={}),F.processedData[h]||(F.processedData[h]={fileCollectionItems:[],name:b,expno:p,procno:h});let x=F.processedData[h];x.fileCollectionItems.push(g),g.name.match(/^(?:1r|1i|2rr|2ir|2ii|2ri|procs|proc2s|title|integrals.txt)$/)&&(x[g.name]=g),g.name==="2rr"&&(x.is2D=!0,x.isFT=!0),g.name==="1r"&&(x.is1D=!0,x.isFT=!0)}else F.fileCollectionItems.push(g),g.name.match(/^(?:ser|fid|acqus|acqu2s|nuslist)$/)&&(F[g.name]=g),g.name==="ser"&&(F.is2D=!0,F.isFID=!0),g.name==="fid"&&(F.is1D=!0,F.isFID=!0);g.name==="QuantFactorSample.xml"&&(F.quantFactorSample=g)}if(i)for(let g in c){let h=c[g].processedData,p={};for(let b in h)i.includes(Number.parseInt(b,10))&&(p[b]=h[b]);c[g].processedData=p}else if(l)for(let g in c){let h=c[g].processedData,p=Object.keys(h??{}).sort((b,m)=>Number(b)-Number(m))[0];h&&p!==void 0&&(c[g].processedData={firstProcessedNumber:h[p]})}let f=fi(n),d=[];for(let g in c){let h=c[g],{processedData:p,...b}=h;if(f(h,o)){let y=Object.keys(p??{});if(p&&y.length>0){let F=p[y[0]];F.procs&&(b.fileCollectionItems.push(F.procs),b.procs=F.procs),F.proc2s&&(b.fileCollectionItems.push(F.proc2s),b.proc2s=F.proc2s),F["integrals.txt"]&&(b.integrals=F["integrals.txt"])}d.push(b)}let m="ser"in b||"fid"in b;if(o==="fid"||o==="preferFID"&&m){n?.warn("Skipping FT data because it does not match the import filters");continue}for(let y in p){let F=p[y];(F["1r"]||F["2rr"])&&(b.acqus&&F.fileCollectionItems.push(b.acqus),b.acqu2s&&F.fileCollectionItems.push(b.acqu2s),b.vdlist&&(F.vdlist=b.vdlist),d.push({integrals:F["integrals.txt"],acqus:b.acqus,acqu2s:b.acqu2s,...F}))}}return s||(n?.warn("Skipping 1D data because it does not match the import filters"),d=d.filter(g=>!g.is1D)),a||(n?.warn("Skipping 2D data because it does not match the import filters"),d=d.filter(g=>!g.is2D)),ui(d,t.logger)}function ui(e,t){return e.filter(n=>{let{checked:i,message:r}=vt(n);return i||t?.warn(r),i})}function pi(e,t){return e.name.match(/^(?:ser|acqus|acqu2s|nuslist|vdlist|difflist|QuantFactorSample.xml)$/)||e.name.match(/^fid$/)&&t.includes(e.relativePath.replace(/fid$/,"acqus"))}function fi(e){return(t,n)=>{let{processedData:i}=t,r=Object.keys(i??{}),o=i&&r.length>0&&["1r","1i","2rr"].some(u=>u in i[r[0]]),s="ser"in t||"fid"in t,c=s&&(n!=="ft"&&n!=="preferFT"||n==="preferFT"&&!o);return s&&!c&&e?.warn("Skipping RAW data because it does not match import filters"),c}}function ie(e){if(e===void 0||Array.isArray(e)&&e.length===0)return{epoch:null,date:""};let t=e[0]*1e3;return{epoch:t,date:new Date(t).toUTCString()}}function oe(e,t){for(let n in t.meta)e.meta[n]===void 0&&(e.meta[n]=t.meta[n]);for(let n in t.info)e.info[n]===void 0&&(e.info[n]=t.info[n]);for(let n in e.meta)Array.isArray(e.meta[n])||(e.meta[n]=[e.meta[n]])}import{convert as di}from"jcampconverter";async function k(e,t){if(!e)return kt();let n=await e.text(),{keepRecordsRegExp:i=/.*/}=t,r=di(n,{keepRecordsRegExp:i});return r.flatten.length===0?kt():r.flatten[0]}function kt(){return{info:{},meta:{},tmp:{},spectra:[],ntuples:{}}}async function Lt(e){let n=(await e.integrals?.text())?.split(/\r?\n/).slice(3).filter(Boolean)??[],i=[];for(let r=1;r<n.length;r++){let o=n[r].replace(/^\s*/,"").replaceAll(/[\s\t]+/g,";").match(/\d+;(?<from>[0-9.]+);(?<to>[0-9.]+);(?<integration>[0-9.]+)/)?.groups;if(o){let{from:s,to:a,integration:l}=o;i.push({from:Number.parseFloat(s),to:Number.parseFloat(a),integration:Number.parseFloat(l)})}}return i}function Ve(e,t="utf8"){return new TextDecoder(t).decode(e)}var gi=new TextEncoder;function qt(e){return gi.encode(e)}var yi=1024*8,hi=(()=>{let e=new Uint8Array(4),t=new Uint32Array(e.buffer);return!((t[0]=1)&e[0])})(),Xe={int8:globalThis.Int8Array,uint8:globalThis.Uint8Array,int16:globalThis.Int16Array,uint16:globalThis.Uint16Array,int32:globalThis.Int32Array,uint32:globalThis.Uint32Array,uint64:globalThis.BigUint64Array,int64:globalThis.BigInt64Array,float32:globalThis.Float32Array,float64:globalThis.Float64Array},O=class e{buffer;byteLength;byteOffset;length;offset;lastWrittenByte;littleEndian;_data;_mark;_marks;constructor(t=yi,n={}){let i=!1;typeof t=="number"?t=new ArrayBuffer(t):(i=!0,this.lastWrittenByte=t.byteLength);let r=n.offset?n.offset>>>0:0,o=t.byteLength-r,s=r;(ArrayBuffer.isView(t)||t instanceof e)&&(t.byteLength!==t.buffer.byteLength&&(s=t.byteOffset+r),t=t.buffer),i?this.lastWrittenByte=o:this.lastWrittenByte=0,this.buffer=t,this.length=o,this.byteLength=o,this.byteOffset=s,this.offset=0,this.littleEndian=!0,this._data=new DataView(this.buffer,s,o),this._mark=0,this._marks=[]}available(t=1){return this.offset+t<=this.length}isLittleEndian(){return this.littleEndian}setLittleEndian(){return this.littleEndian=!0,this}isBigEndian(){return!this.littleEndian}setBigEndian(){return this.littleEndian=!1,this}skip(t=1){return this.offset+=t,this}back(t=1){return this.offset-=t,this}seek(t){return this.offset=t,this}mark(){return this._mark=this.offset,this}reset(){return this.offset=this._mark,this}pushMark(){return this._marks.push(this.offset),this}popMark(){let t=this._marks.pop();if(t===void 0)throw new Error("Mark stack empty");return this.seek(t),this}rewind(){return this.offset=0,this}ensureAvailable(t=1){if(!this.available(t)){let i=(this.offset+t)*2,r=new Uint8Array(i);r.set(new Uint8Array(this.buffer)),this.buffer=r.buffer,this.length=i,this.byteLength=i,this._data=new DataView(this.buffer)}return this}readBoolean(){return this.readUint8()!==0}readInt8(){return this._data.getInt8(this.offset++)}readUint8(){return this._data.getUint8(this.offset++)}readByte(){return this.readUint8()}readBytes(t=1){return this.readArray(t,"uint8")}readArray(t,n){let i=Xe[n].BYTES_PER_ELEMENT*t,r=this.byteOffset+this.offset,o=this.buffer.slice(r,r+i);if(this.littleEndian===hi&&n!=="uint8"&&n!=="int8"){let a=new Uint8Array(this.buffer.slice(r,r+i));a.reverse();let l=new Xe[n](a.buffer);return this.offset+=i,l.reverse(),l}let s=new Xe[n](o);return this.offset+=i,s}readInt16(){let t=this._data.getInt16(this.offset,this.littleEndian);return this.offset+=2,t}readUint16(){let t=this._data.getUint16(this.offset,this.littleEndian);return this.offset+=2,t}readInt32(){let t=this._data.getInt32(this.offset,this.littleEndian);return this.offset+=4,t}readUint32(){let t=this._data.getUint32(this.offset,this.littleEndian);return this.offset+=4,t}readFloat32(){let t=this._data.getFloat32(this.offset,this.littleEndian);return this.offset+=4,t}readFloat64(){let t=this._data.getFloat64(this.offset,this.littleEndian);return this.offset+=8,t}readBigInt64(){let t=this._data.getBigInt64(this.offset,this.littleEndian);return this.offset+=8,t}readBigUint64(){let t=this._data.getBigUint64(this.offset,this.littleEndian);return this.offset+=8,t}readChar(){return String.fromCharCode(this.readInt8())}readChars(t=1){let n="";for(let i=0;i<t;i++)n+=this.readChar();return n}readUtf8(t=1){return Ve(this.readBytes(t))}decodeText(t=1,n="utf8"){return Ve(this.readBytes(t),n)}writeBoolean(t){return this.writeUint8(t?255:0),this}writeInt8(t){return this.ensureAvailable(1),this._data.setInt8(this.offset++,t),this._updateLastWrittenByte(),this}writeUint8(t){return this.ensureAvailable(1),this._data.setUint8(this.offset++,t),this._updateLastWrittenByte(),this}writeByte(t){return this.writeUint8(t)}writeBytes(t){this.ensureAvailable(t.length);for(let n=0;n<t.length;n++)this._data.setUint8(this.offset++,t[n]);return this._updateLastWrittenByte(),this}writeInt16(t){return this.ensureAvailable(2),this._data.setInt16(this.offset,t,this.littleEndian),this.offset+=2,this._updateLastWrittenByte(),this}writeUint16(t){return this.ensureAvailable(2),this._data.setUint16(this.offset,t,this.littleEndian),this.offset+=2,this._updateLastWrittenByte(),this}writeInt32(t){return this.ensureAvailable(4),this._data.setInt32(this.offset,t,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeUint32(t){return this.ensureAvailable(4),this._data.setUint32(this.offset,t,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeFloat32(t){return this.ensureAvailable(4),this._data.setFloat32(this.offset,t,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeFloat64(t){return this.ensureAvailable(8),this._data.setFloat64(this.offset,t,this.littleEndian),this.offset+=8,this._updateLastWrittenByte(),this}writeBigInt64(t){return this.ensureAvailable(8),this._data.setBigInt64(this.offset,t,this.littleEndian),this.offset+=8,this._updateLastWrittenByte(),this}writeBigUint64(t){return this.ensureAvailable(8),this._data.setBigUint64(this.offset,t,this.littleEndian),this.offset+=8,this._updateLastWrittenByte(),this}writeChar(t){return this.writeUint8(t.charCodeAt(0))}writeChars(t){for(let n=0;n<t.length;n++)this.writeUint8(t.charCodeAt(n));return this}writeUtf8(t){return this.writeBytes(qt(t))}toArray(){return new Uint8Array(this.buffer,this.byteOffset,this.lastWrittenByte)}getWrittenByteLength(){return this.lastWrittenByte-this.byteOffset}_updateLastWrittenByte(){this.offset>this.lastWrittenByte&&(this.lastWrittenByte=this.offset)}};import{isAnyArray as bi}from"is-any-array";import{matrixCreateEmpty as Fi,xSequentialFillFromStep as Di}from"ml-spectra-processing";function _t(e){for(let t in e){let{z:n}=e[t],{minX:i,minY:r,maxX:o,maxY:s}=e[t];if(i>o){[i,o]=[o,i];for(let a of n)a.reverse()}r>s&&(n.reverse(),[r,s]=[s,r]),e[t]={...e[t],z:n,minX:i,minY:r,maxY:s,maxX:o}}}function se(e,t){let{x:n,minMax:i,nbSubSpectra:r,template:o}=t;e.spectra||(e.spectra=[]);for(let s=0;s<r;s++){let a={};for(let l in i)a[l]=i[l].z[s];e.spectra.push({...o,data:{...a,x:n}})}}function ce(e,t,n={}){let i={};for(let h in e)e[h]&&(i[h]=new O(e[h]));let r=ae(t.meta.SI),o=ae(t.meta.SW_p),s=ae(t.meta.SF),a=s,l=ae(t.shiftOffsetVal||t.meta.OFFSET);t.meta.observeFrequency=s,t.meta.brukerReference=a,t.meta.DATATYPE="NMR Spectrum";let c=Number.parseInt(t.meta.BYTORDP,10);c=c?0:1;let u=t.meta.nbSubSpectra||1;if(c)for(let h in i)i[h].setLittleEndian();else for(let h in i)i[h].setBigEndian();let f={dataType:"NMR Spectrum",nbPoints:r,firstX:l,lastX:l-o/s,xUnit:"PPM",yUnit:"Arbitrary",isXYdata:!0,isFT:!0,nucleus:t.meta.NUC1,observeFrequency:s,title:t.meta.TITLE,deltaX:-(o/s)/(r-1)},d=f.deltaX,g=Di({from:l,step:d,size:r});if(u===1){let h={};for(let p in i){let b=i[p],m=new Float64Array(r);for(let y=0;y<r;++y)m[y]=b.readInt32();h[p]=m}t.spectra.push({...f,data:{...h,x:g}})}else{let{meta:h}=t,p=Number(h.SF[1]),b=Number(h.SW_p[1]||h.SW[1]),m=Number(h.OFFSET[1]),y=m-b/p,F={};for(let x in i)F[x]={minY:m,maxY:y,minX:g[0],maxX:g.at(-1),...xi(h,i[x])};_t(F),n.keepSpectra&&se(t,{minMax:F,x:g,nbSubSpectra:u,template:f}),t.minMax=F}}function ae(e){return Number(bi(e)?e[0]:e)}function xi(e,t){let n=e.SI.slice().reverse(),i=e.XDIM.slice().reverse(),r=n.map((g,h)=>Number.parseInt(String(g/i[h]),10)),[o,s]=n,[a,l]=i,c=Fi({nbRows:o,nbColumns:s}),[u,f]=[Number.MAX_SAFE_INTEGER,Number.MIN_SAFE_INTEGER],d=[];for(let g=0;g<r[0];g++)for(let h=0;h<r[1];h++){let p=h*l,b=g*a;d.push([b,p])}for(let[g,h]of d)for(let p=0;p<a;p++)for(let b=0;b<l;b++){let m=t.readInt32();u>m&&(u=m),f<m&&(f=m),c[p+g][b+h]=m}return{z:c,minZ:u,maxZ:f}}import{createStepArray as Ai,xMinMaxValues as Mi}from"ml-spectra-processing";var J={};Nt(J,{DQD:()=>Ni,QF:()=>Si,QSEQ:()=>z,QSIM:()=>Pi});var Si=0,Pi=1,z=2,Ni=3;function le(e,t,n){let i=Number.parseInt(t.meta.TD[0],10),r=new O(e),o=t.meta.nbSubSpectra||1,s=t.meta.AQ_mod,l=Number.parseInt(t.meta.DTYPA,10)===2,c=Number.parseFloat(t.meta.SW_h[0]),u=Number.parseFloat(t.meta.SFO1[0]);t.meta.DATATYPE="NMR FID";let f=1/(2*c),d=i*f,g=Number.parseInt(t.meta.BYTORDA,10);g=g?0:1,g?r.setLittleEndian():r.setBigEndian();let h=s===2?f:2*f,p=Ii({nbSubSpectra:o,isFloat:l,aqMode:s,td:i}),b={dataType:"NMR FID",dataTable:"(X++(R..R))",nbPoints:p,firstX:0,lastX:d,nucleus:t.meta.NUC1,xUnit:"Sec",yUnit:"Arbitrary",isXYdata:!0,isFID:!0,observeFrequency:u,title:t.meta.TITLE,deltaX:h},m=Ai({length:p,step:h});if(o<2){let y=Bt(r,{nbPoints:p,isFloat:l,aqMode:s});t.spectra=[{data:{x:m,...y},...b}]}else{let y={minX:m[0],maxX:m.at(-1),minY:0,maxY:o,minZ:0,maxZ:0},F=s===2?{re:{z:[],...y}}:{re:{z:[],...y},im:{z:[],...y}},x={re:{min:Number.MAX_SAFE_INTEGER,max:Number.MIN_SAFE_INTEGER},im:{min:Number.MAX_SAFE_INTEGER,max:Number.MIN_SAFE_INTEGER}};for(let N=0;N<o;N++){let D=Bt(r,{nbPoints:p,isFloat:l,aqMode:s});x.re=jt(D.re,x.re),x.im=jt(D.im??new Float64Array,x.im),F.re.z.push(D.re),F.im&&D.im&&F.im.z.push(D.im)}F.re={...F.re,minZ:x.re.min,maxZ:x.re.max},F.im={...F.im,minZ:x.im.min,maxZ:x.im.max},n.keepSpectra&&se(t,{minMax:F,x:m,nbSubSpectra:o,template:b}),t.minMax=F}}function jt(e,t){let{min:n,max:i}=Mi(e),{min:r,max:o}=t;return{min:Math.min(r,n),max:Math.max(o,i)}}function Bt(e,t){let{nbPoints:n,isFloat:i,aqMode:r}=t,o={re:new Float64Array(n),im:null},s=i?"readFloat64":"readInt32";if(r===2)for(let a=0;a<n;a++)o.re[a]=e[s]();else{o.im=new Float64Array(n);for(let a=0;a<n;a++)o.re[a]=e[s](),o.im[a]=e[s]()}return o}function Ii(e){let{nbSubSpectra:t,isFloat:n,aqMode:i,td:r}=e,o=r;if(t>1){let s=n?128:256;o=Math.trunc(Math.ceil(r/s)*s)}return i===2?o:o/2>>0}async function Ut(e,t){let n={},i=[],r=e["1r"]||e["1i"]?["1r","1i"]:["fid"];function o(a,l){return a.then(c=>{n[l]=c})}for(let a of r){let l=e[a];l&&i.push(o(l.arrayBuffer(),a))}i.push(k(e.procs,t).then(a=>{n.procs=a}),k(e.acqus,t).then(a=>{n.acqus=a})),e.quantFactorSample&&i.push(Ti(e).then(a=>{n.ereticFactor=a})),e.integrals&&i.push(Lt(e).then(a=>{n.integrals=a}));let s=Ri(e);return s&&i.push(s.text().then(a=>{n.titleFile=a})),await Promise.all(i),Ei(n)}function Ri(e){if("title"in e&&e.title)return e.title}function Ei(e){let{procs:t,acqus:n,integrals:i,ereticFactor:r,titleFile:o}=e,s={...t};oe(s,n);let a={...s.info};s.info=a;let l={...s.meta};s.meta=l;let{epoch:c,date:u}=ie(l.DATE);return c!==null&&Object.assign(a,{epoch:c,date:u}),i&&Object.assign(s,{integrals:i}),r&&(a.ereticFactor=r),o&&(l.TITLE_FILE=o),e["1r"]||e["1i"]?ce({re:e["1r"],im:e["1i"]},s):e.fid&&le(e.fid,s),s}async function Ti(e){let n=(await e.quantFactorSample?.text())?.match(/<Application[\w\W]+<Eretic_Factor>(?<ereticFactor>[\d.]+)/);return Number(n?.groups?.ereticFactor)}function He(e,t){for(let n in t.meta)n in e.meta?(Array.isArray(e.meta[n])||(e.meta[n]=[e.meta[n]]),e.meta[n].push(t.meta[n])):e.meta[n]===void 0&&(e.meta[n]=[t.meta[n]]);return e}async function $t(e,t){let n={},i=[],r=["2rr","2ri","2ir","2ii","ser"];function o(s,a){return s.then(l=>{n[a]=l})}for(let s of r){let a=e[s];a&&i.push(o(a.arrayBuffer(),s))}if(i.push(o(k(e.procs,t),"procs"),o(k(e.proc2s,t),"proc2s"),o(k(e.acqus,t),"acqus"),o(k(e.acqu2s,t),"acqu2s")),"nuslist"in e&&e.nuslist){let s=e.nuslist;i.push(o(s.text(),"nuslist"))}return e.vdlist&&i.push(o(e.vdlist.text(),"vdlist")),e.difflist&&i.push(o(e.difflist.text(),"difflist")),await Promise.all(i),Oi(n,t)}function Oi(e,t){let n=He(e.procs,e.proc2s),i=He(e.acqus,e.acqu2s);oe(n,i);let{epoch:r,date:o}=ie(n.meta.DATE);if(o.length>0&&(n.info={...n.info,epoch:r,date:o}),e.nuslist&&(n.info.nuslist=e.nuslist.split(/\r?\n/).filter(Boolean).map(Number.parseFloat)),e.vdlist){let p=[];for(let b of e.vdlist.split(`
|
|
2
|
+
`)){if(!b)continue;let[m,y]=b.trim().match(/\s*([\d.]+)\s*([a-zA-Z]+)/)?.slice(1)||[];y&&p.push(`${m}${y}`)}n.meta.vdlist=p}if(e.difflist){let p=[];for(let b of e.difflist.split(`
|
|
3
|
+
`)){if(!b)continue;let[m]=b.trim().match(/\s*([\d.]+)\s*/)?.slice(1)||[];p.push(m)}n.meta.difflist=p}n.meta.SW_p||(n.meta.SW_p=n.meta.SW_h),n.meta.SF||(n.meta.SF=n.meta.SFO1);let s=["2rr","2ri","2ir","2ii"].some(p=>p in e);n.meta.nbSubSpectra=s?Number.parseInt(n.meta.SI[1],10):Number.parseInt(n.meta.TD[1],10);let a=0,l=0,c=0,u=0;if(s){let p=Number(n.meta.SF[1]),b=Number(n.meta.SW_p[1]||n.meta.SW[1]);u=Number(n.meta.OFFSET[1]),c=Number(n.meta.OFFSET[0]),a=u,l=u-b/p,n.meta.firstY=a,n.meta.lastY=l,ce({rr:e["2rr"],ri:e["2ri"],ir:e["2ir"],ii:e["2ii"]},n,t)}else if(e.ser){a=0,l=n.meta.nbSubSpectra;let p=Number(n.meta.SW[0]),b=Number(n.meta.SW[1]),m=Number(n.meta.SFO1[0]),y=Number(n.meta.SFO1[1]),F=Number(n.meta.O1[0]),x=Number(n.meta.O1[1]);c=F/m+p/2,u=x/y+b/2,le(e.ser,n,t)}if(t.keepSpectra){let{nbSubSpectra:p}=n.meta,b=(l-a)/(p-1),m=a;for(let y=0;y<p;y++)m+=b,n.spectra[y].pageValue=m}let{NUC1:f,AXNUC:d,SF:g}=n.meta,h=d||f||[];return n.info["2D_Y_NUCLEUS"]=h[1],n.info["2D_X_NUCLEUS"]=h[0],n.info["2D_Y_FRECUENCY"]=g[1],n.info["2D_X_FRECUENCY"]=g[0],n.info["2D_Y_OFFSET"]=u,n.info["2D_X_OFFSET"]=c,n.info.twoD=!0,n.twoD=!0,n}async function Ye(e,t={}){let n,i=!1,r=!1;if(["ser","2rr","2ri","2ir","2ii"].some(s=>s in e))i=!0,n=await $t(e,t);else if(e["1r"]||e["1i"]||e.fid)r=!0,n=await Ut(e,t);else throw new RangeError("The current files are invalid");let o={name:e.name,expno:e.expno,isFID:!!e.isFID};for(let s in e){let a=s;(typeof e[a]).match(/number|string|boolean/)&&(o[a]=e[a])}n.source=i?{...o,is2D:i}:{...o,is1D:r},t.keepFiles&&(n.source.files=e.fileCollectionItems),n.meta.DATE=Number(n.meta.DATE),n.meta.GRPDLY&&(Ge(n.meta,"DSPFVS",n.meta.DSPFVS),Ge(n.meta,"GRPDLY",n.meta.GRPDLY),Ge(n.meta,"DECIM",n.meta.DECIM));for(let s in n.meta)Array.isArray(n.meta[s])&&(n.meta[s].length===1||typeof n.meta[s][0]=="string"&&n.meta[s][0].includes("(0.."))&&(n.meta[s]=n.meta[s][0]);return n}function Ge(e,t,n){n!==void 0&&(Array.isArray(n)?e[t]=n.slice():e[t]=[n])}var q={};Nt(q,{ECHO_ANTIECHO:()=>qi,QF:()=>Ci,QSEC:()=>wi,STATES:()=>ki,STATES_TPPI:()=>Li,TTPI:()=>vi});var Ci=1,wi=2,vi=3,ki=4,Li=5,qi=6;import{formatSpectra as Gi}from"@zakodium/nmrium-core";function me(e){let t=[];for(let n of e){if(!n)continue;let{groups:{value:i,unit:r}={}}=n.trim().match(/[$$]*\s*(?<value>[\d.]+)\s*(?<unit>[a-zA-Z]+)/)||{};t.push(_i(i,r))}return t}function _i(e,t){switch(t.toLowerCase()){case"s":return Number.parseFloat(e);case"ms":return Number.parseFloat(e)/1e3;case"m":case"min":return Number.parseFloat(e)*60;default:return Number.NaN}}import{isAnyArray as Jt}from"is-any-array";function _(e){if(ji(e))return Bi(e)?e.map(zt):zt(e);if(typeof e=="object"&&e!==null){let t={};for(let n in e)t[n]=_(e[n]);return t}return e}function ji(e){return Jt(e)}function zt(e){return Float64Array.from(e)}function Bi(e){return Jt(e[0])}import{getOneIfArray as K}from"@zakodium/nmrium-core";import{getGyromagneticRatio as Ji}from"gyromagnetic-ratio";import{isAnyArray as Yt}from"is-any-array";import{getFrequency as Wi}from"nmr-processing";import{isAnyArray as W}from"is-any-array";function ue(e){return typeof e=="number"}function pe(e){let{phc0:t,phc1:n}=e;return!W(t)&&!ue(t)||!W(n)&&!ue(n)||W(t)&&!ue(t[0])||W(n)&&!ue(n[0])?{}:(W(n)?n[0]*=-1:n*=-1,W(t)?t[0]*=-1:t*=-1,{phc0:t,phc1:n})}function Vt(e,t,n){if(e>0)return Number(e);if(t>14||t===0)return 0;if(Wt[t]){let i=Wt[t];if(!i[n])throw new Error(`decim ${n} not in lookup table for dspfvs ${t}`);return i[n]}else throw new Error(`dspfvs ${t} not in lookup table`)}var Wt={10:{2:44.75,3:33.5,4:66.625,6:59.08333333333333,8:68.5625,12:60.375,16:69.53125,24:61.02083333333333,32:70.015625,48:61.34375,64:70.2578125,96:61.50520833333333,128:70.37890625,192:61.5859375,256:70.439453125,384:61.62630208333333,512:70.4697265625,768:61.646484375,1024:70.48486328125,1536:61.65657552083333,2048:70.492431640625},11:{2:46,3:36.5,4:48,6:50.16666666666667,8:53.25,12:69.5,16:72.25,24:70.16666666666667,32:72.75,48:70.5,64:73,96:70.66666666666667,128:72.5,192:71.33333333333333,256:72.25,384:71.66666666666667,512:72.125,768:71.83333333333333,1024:72.0625,1536:71.91666666666667,2048:72.03125},12:{2:46,3:36.5,4:48,6:50.16666666666667,8:53.25,12:69.5,16:71.625,24:70.16666666666667,32:72.125,48:70.5,64:72.375,96:70.66666666666666,128:72.5,192:71.333333333,256:72.25,384:71.66666666666667,512:72.125,768:71.83333333333333,1024:72.0625,1536:71.91666666666667,2048:72.03125},13:{2:2.75,3:2.833333333333333,4:2.875,6:2.916666666666667,8:2.9375,12:2.958333333333333,16:2.96875,24:2.979166666666667,32:2.984375,48:2.989583333333333,64:2.9921875,96:2.994791666666667}};var Ui=new Map([[String(J.QSIM),"notPhaseSensitive"],["notphasesensitive","notPhaseSensitive"],[String(J.QSEQ),"QSEQ"],["qseq","QSEQ"],[String(q.TTPI),"TPPI"],["tppi","TPPI"],[String(q.STATES),"States"],["states","States"],[String(q.STATES_TPPI),"States-TPPI"],["tppi-states","States-TPPI"],[String(q.ECHO_ANTIECHO),"Echo-antiecho"],["echo-antiecho","Echo-antiecho"]]);function Xt(e){let t=String(e).toLowerCase().replaceAll(" ","");return Ui.get(t)}import{normalizeNucleus as $i}from"nmr-processing";function j(e,t=","){if(e&&typeof e=="string")return e.split(t)}function fe(e,t,n){let i=[];if(e[`${n}AXNUC`]&&(i=e[`${n}AXNUC`],Array.isArray(i)||(i=[i]),i=w(i)),i.length===0&&e[`${n}NUC1`]&&(i=e[`${n}NUC1`],Array.isArray(i)||(i=[i]),i=w(i)),i.length===0&&e[".NUCLEUS"]){let r=j(e[".NUCLEUS"]);if(e[`${n}SYMBOL`]){let o=e[`${n}SYMBOL`].split(","),s=o.findIndex(l=>l.includes("2")),a=o.findIndex(l=>l.includes("1"));s!==-1&&a!==-1&&r?i=w([r[s],r[a]]):i=w(r).reverse()}else i=w(r)}return i.length===0&&e[".OBSERVENUCLEUS"]&&(i=w([e[".OBSERVENUCLEUS"]])),i.length===0&&t.experiment&&(i=w(Ht(t.experiment[0]))),zi(e)&&(i=[e["2D_X_NUCLEUS"].replaceAll(/[^A-Za-z0-9]/g,""),e["2D_Y_NUCLEUS"].replaceAll(/[^A-Za-z0-9]/g,"")]),t.experiment&&(t.experiment[0].match("jres")||t.experiment[0].match("dosy"))&&(i=Ht(t.experiment[0])),i.map($i)}function zi(e){return e["2D_X_NUCLEUS"]&&!e["2D_X_NUCLEUS"].includes("off")&&e["2D_Y_NUCLEUS"]&&!e["2D_Y_NUCLEUS"].includes("off")}function Ht(e){return typeof e!="string"?[]:(e=e.toLowerCase(),e.includes("jres")?["1H","Hz"]:e.includes("dosy")?["1H","D"]:e.includes("hmbc")||e.includes("hsqc")?["1H","13C"]:e.includes("cosy")||e.includes("tocsy")?["1H","1H"]:[])}function w(e){if(!e)return[];let t=e.map(i=>String(i).replaceAll(/[^A-Za-z0-9]/g,"").replace("NA","").replace("off","")),n=0;for(let i of t)i||n++;return n===0?t:[]}function S(e,t,n,i=!1){n===void 0||t in e&&!i||(Array.isArray(n)?e[t]=n.map(Gt):e[t]=[Gt(n)])}function Gt(e){return typeof e=="string"&&(e.startsWith("<")&&e.endsWith(">")&&(e=e.slice(1,-1)),e=e.replace(/\$.*/,"").trim()),e}function ge(e,t={}){let{prefix:n="",logger:i}=t,r={dimension:0,nucleus:[],isFid:!1,isFt:!1},o=JSON.stringify(e),s=/\r\n/.exec(o)?`\r
|
|
4
4
|
`:`
|
|
5
|
-
`,{JCAMPDX:a="",ORIGIN:l=""}=e,c=String(a).toLowerCase()+String(l).toLowerCase();"SPECTROMETER/DATASYSTEM"in e&&(c=e["SPECTROMETER/DATASYSTEM"]);let u=(m=[])=>{for(let y of m)if(!(y in r))return!1;return!0};(c.includes("mestre")||c.includes("nova"))&&(c="mnova"),r.creator=c,e.LONGDATE&&
|
|
6
|
-
`}=n;S(e,"spectralWidth",t[`${i}SweepWidth`]/e.originFrequency[0]);let o=t[`${i}.PULSESEQUENCE`].split(r),s=[];t[".OBSERVENUCLEUS"]&&s.push(t[".OBSERVENUCLEUS"]),t.INDIRECTNUCLEUS&&s.push(t.INDIRECTNUCLEUS),e.nucleus=w(s),e.pulseSequence=o[0];let a=o.slice(2,-1);if(s.length>1)if(s[0]===s[1])e.spectralWidth.push(e.spectralWidth[0]);else{let l=JSON.stringify(a).match(/\$\$SW1=\s*(?<sw>[+-]?(?:[0-9]*[.])?[0-9]+)/);if(l?.groups){let{originFrequency:c}=e,u=Number.parseFloat(l.groups.sw);e.spectralWidth.push(u/c[1])}}return e}function
|
|
7
|
-
because it didn't match the import filters`);continue}s.push(u)}let a=[],l=s.some(Yt),c=s.some(Ht);for(let u of s){if(o!=="both"&&u.dataType!=="LINK"){if(Yt(u)&&(o==="ft"||o==="preferFT"&&c)){i?.warn(`Skipping raw data ${n?`in ${n}`:"in the JCAMP-DX"} because it didn't match the import filters`);continue}if(Ht(u)&&(o==="fid"||o==="preferFID"&&l)){i?.warn(`Skipping FFT data ${n?`in ${n}`:"in the JCAMP-DX"} because it didn't match the import filters`);continue}}a.push(u)}return a}function Ht(e){return e.dataType?.toUpperCase().includes("SPECTRUM")&&e.dataClass&&!e.dataClass.toUpperCase().includes("PEAK")}function Yt(e){return e.dataType?.toUpperCase().includes("FID")}function Zt(e,t={}){let{logger:n,name:i=""}=t;for(let r of e){if(r.dataType==="LINK"&&Zt(r.children,t))return!0;let{dataType:o=""}=r,s=o.toLowerCase();if(s.length>0){if(s.includes("spectrum")&&!s.includes("nmr"))return n?.warn(`File ${i} was ignored because it is a ${o}`),!1;if(s.includes("nmr"))return!0}}return!1}import{generateID as en}from"@zakodium/nmrium-core";import{parseJcampCS as $i}from"jcampconverter";import*as ji from"openchemlib";import{isMolfileNotEmpty as ki}from"nmr-processing";import{Molecule as Li}from"openchemlib";async function Kt(e,t={}){let n=await e.text(),i=X(n),r={molecules:i,spectra:[]};return i.length===0&&t.logger?.debug(`${e.name} is an empty molfile`),r}function X(e){let t=[];if(!ki(e))return[];let i=Li.fromMolfile(e).toMolfile();return t.push({molfile:i}),t}import{isMolfileNotEmpty as _i}from"nmr-processing";import*as Bi from"openchemlib";import{getDiastereotopicAtomIDsFromMolfile as Ui}from"openchemlib-utils";var qi=new Set(["ndnmrspectrum","ndnmrfid","nmrspectrum","nmrfid"]);function be(e){let{dataType:t="",dataClass:n=""}=e,i=t.replaceAll(/\s/g,"").toLowerCase(),r=n.replaceAll(/\s/g,"").toLowerCase();return qi.has(i)&&r!=="peaktable"}function Qt(e,t,n={}){let{spectra:i,info:r,meta:o}=e,s=i[0].data,a=[],l={x:"delta",y:"intensity",w:"width",m:"multiplicity",a:"atom"},{logger:c,name:u,spectraData:p}=n,{CROSSREFERENCE:g}=r,d=typeof g!="string"?g:g.split(/\r?\n/).map(x=>x.trim()).filter(Boolean),h=d.find(x=>x?.toLowerCase().includes("structure"));if(h===void 0)return c&&c.warn(`There is not a structure reference for ${u} file, assignment object could not be completed`),null;let f=Number.parseInt(h?.toLowerCase().replace(/_/,"").replace(/structure:\s*blockid\s*=\s*(?<blockId>.*)/,"$<blockId>"),10);if(Number.isNaN(f)||f<1)return c&&c.warn(`Structure block_id not found for ${u} file, assignment object could not be completed`),null;let m=p?.molecules?.find(x=>x.blockId===f)?.molfile??"";if(m===""){let x=t.find(A=>A.info.BLOCKID===f),{MOLFILE:P=""}=x?.meta||{};m=P}if(!_i(m))return c&&c.warn(`Empty molfile for ${u} file with structure block_id = ${f}, assignment object could not be completed`),null;let y=Ui(Bi,m),F=fe({...r,...o},{},"");for(let x=0;x<s.x.length;x++){let P={};for(let A in s){let I=s[A][x];typeof I=="string"&&I.startsWith("<")&&I.endsWith(">")&&(I=I.slice(1,-1)),P[l[A]]=I}if("atom"in P){let A=y.map[P.atom-1];F.includes("1H")?A.nbHydrogens>0?(P.diaIDs=A.hydrogenOCLIDs,P.nbHydrogens=A.nbHydrogens):(P.diaIDs=[A.oclID],P.nbHydrogens=A.nbHydrogens):(P.diaIDs=[A.oclID],P.nbHydrogens=1)}a.push(P)}let D={};for(let x of a){let{delta:P,diaIDs:A}=x,I=`${P}_${A.join("_")}`;if(D[I])D[I].atoms.push(x.atom);else{let{atom:gt,...Le}=x;D[I]={...Le,atoms:[x.atom]}}}let N=[];for(let x of d)x.toLowerCase().includes("spectrum")&&N.push(Number(x.toLowerCase().replace(/_/,"").replace(/.*:\s*blockid=(?<blockId>.*)/,"$<blockId>")));if(N.length===0){for(let x of t)if(be(x)){let{BLOCKID:P}=x.info;N.push(Number(P))}N.length>1&&(N=[],c&&c.warn(`There is not a spectral cross-reference for the peak assignment in the ${u} file`))}return{moleculeBlockID:f,spectraBlockIDs:N,assignments:Object.values(D),molecule:y.molecule}}function tn(e,t,n,i){for(let r of e){let{meta:o,dataClass:s="",dataType:a="",info:l}=r,c=Number.parseInt(String(l.BLOCKID),10);o.MOLFILE?Xi(String(o.MOLFILE),t,c):r.jcampCS&&Ji(r,t,c),zi(s,a)&&Wi(t,r,e,i),be(r)&&n.push(r)}}function zi(e,t){return e?.toLowerCase().includes("assignments")&&t?.toLowerCase().includes("assignments")}function Wi(e,t,n,i){let r=Qt(t,n,{spectraData:e,logger:i.logger,name:i.name});if(e.assignmentsByBlocks||(e.assignmentsByBlocks={}),r){let{spectraBlockIDs:o}=r;for(let s of o)e.assignmentsByBlocks[s]=r}}function Ji(e,t,n){t.molecules||(t.molecules=[]);let i=$i(e,{OCL:ji}),r=X(i?.molfile||"");r.length>0&&t.molecules.push({id:en(),blockId:n,...r[0]})}function Xi(e,t,n){t.molecules||(t.molecules=[]);let i=X(String(e));t.molecules.push({id:en(),blockId:n,...i[0]})}import{generateID as gn}from"@zakodium/nmrium-core";import{matrixMinMaxZ as dn,reimPhaseCorrection as ro}from"ml-spectra-processing";import{xyAutoRangesPicking as io}from"nmr-processing";function V(e){return e.slice(0,Math.max(0,e.lastIndexOf(".")))}function H(e){e.sort((t,n)=>t.from-n.from);for(let t=0;t<e.length-1;t++)e[t].to>e[t+1].from&&(e[t].to=Math.max(e[t+1].to,e[t].to),e[t].signals=e[t].signals.concat(e[t+1].signals),e[t].integration+=e[t+1].integration,e.splice(t+1,1),t--);return e}import{splitPatterns as Zi}from"nmr-processing";import{xMaxValue as Vi}from"ml-spectra-processing";function K(e){return e.trim().slice(1,-1).split(/,\s*/).map(t=>t.trim())}var Hi={I:"id",X:"from",Y:"to",Hs:"delta",An:"integration",H:"nbAtoms",C:"multiplicity",N:"assignment","(J)":"js"},nn=["I","X","Y","Hs","An","H","C","N","(J)"];function rn(e){let t={headersFromParenthesis:[],headersFromComments:[],comments:[],data:[],multiplets:[]},n=e.split(/\r?\n/).filter(i=>i.trim()!=="");if(n.length===0)return t;if(n[0].startsWith("(")&&!n[0].match(/\d/)){let i=n.shift();t.headersFromParenthesis=K(i)}return t.comments=n.filter(i=>i.startsWith("$$")).map(i=>i.replace(/^\$\$\s*/,"")),t.headersFromComments=Gi(t.comments),t.data=n.filter(i=>!i.startsWith("$$")).map(K),t.multiplets=Yi(t),t}function Yi(e,t={}){let{logger:n}=t,i=e.data[0].map((l,c)=>c).filter(l=>e.data.every(c=>Number.isNaN(c[l])||Number.isNaN(Number(c[l]))));if(n?.trace(`Parsing JCAMP-DX assignment: stringColumnIndexes: ${i.join(",")}`),i.length===0)return n?.warn("Parsing JCAMP-DX assignment: No string columns found. Skipping parsing of assignment."),[];let r=i[0],o;if(e.headersFromParenthesis.length>0&&e.headersFromParenthesis[r]==="C")o=e.headersFromParenthesis;else if(e.headersFromComments.length>0&&e.headersFromComments[r]==="C")o=e.headersFromComments;else if(nn[r]==="C")o=nn;else return n?.warn("No header found for multiplicity. Skipping parsing of assignment."),[];return Vi(e.data.map(l=>l.length))>o.length&&n?.warn("Some assignments are containing more values than headers"),e.data.map(l=>{let c={};for(let u=0;u<o.length;u++){let p=o[u];c[Hi[p]||p]=l[u]}return c})}function Gi(e){return e.map(t=>t.split(":")[0].trim()).filter(t=>t.length>0)}function on(e,t={}){let{logger:n}=t,i=rn(e),r={multiplets:[],comments:i.comments};for(let o of i.multiplets){let{id:s,from:a,to:l,delta:c,integration:u,nbAtoms:p,multiplicity:g}=o,d={id:s,js:[],multiplicity:"",...Ki({from:a,to:l,delta:c,integration:u,nbAtoms:p})};if(typeof o.js=="string"){let h=o.js.split(/\s+/).map(Number.parseFloat),f=0,b=Zi(g).map(F=>{let D=(F?.multiplicity||1)-1;return f+=D,{value:F.value,multiplicity:F?.multiplicity,js:h.slice(f-D,f)}}),m=b.reduce((F,D)=>F+(D.multiplicity?D.multiplicity-1:0),0);h.length!==m&&n?.warn(`The number of j values (${h.length}) is not equal to the sum of the multiplicities - 1 (${m})`);let y=[];for(let F of b){if(F.js.every(D=>D===F.js[0])){y.push(F);continue}if(F.multiplicity!==F.js.length+1){y.push(F);continue}for(let D=0;D<F.multiplicity-1;D++)y.push({value:"d",multiplicity:2,js:[F.js[D]]})}y.sort((F,D)=>D.js[0]-F.js[0]),d.js=y.map(F=>({coupling:F.js[0],multiplicity:F.value}))}typeof o.assignment=="string"&&(d.assignment=eo(o.assignment)),typeof o.multiplicity=="string"&&(d.multiplicity=o.multiplicity),r.multiplets.push(d)}return r}function Ki(e){let t={};for(let n in e){let i=e[n],r=typeof i=="number"?i:Number.parseFloat(i);Number.isNaN(r)||(t[n]=r)}return t}var Qi={quot:'"',apos:"'",comma:",",amp:"&",lpar:"(",rpar:")",lt:"<",gt:">",colon:":",semi:";"};function eo(e){return e.replaceAll(/&(\w+);/gi,(t,n)=>Qi[n.toLowerCase()]||t)}function sn(e){let t=e.split(/\r?\n/).filter(i=>i.trim()!==""),n=[];for(let i of t)if(i.startsWith("(")){let[r,o,s]=K(i).map(Number.parseFloat);n.push({id:r,x:o,y:s})}return n}function an(e,t={}){let n={};if(!e["OBSERVED MULTIPLETS"])return[];let i=on(e["OBSERVED MULTIPLETS"],t);if(!i)return[];let{multiplets:r}=i;for(let o of r){let{id:s,from:a,to:l,integration:c=0,...u}=o;n[s]={from:a,to:l,integration:c,signals:[{id:s,...u}]}}if(e["OBSERVED MULTIPLETS PEAKS"]){let o=sn(e["OBSERVED MULTIPLETS PEAKS"]),s={};for(let a of o){let{id:l,x:c,y:u}=a;s[l]||(s[l]=[]),s[l].push({x:c,y:u,width:.05})}for(let a in n)s[a]&&(n[a].signals[0].peaks=s[a])}return H(Object.values(n))}function cn(e,t){let i=[...e.getMolecularFormula().formula.matchAll(/(?<element>[A-Z][a-z]?)(?<count>\d*)/g)].map(o=>({element:o?.groups?.element,count:o?.groups?.count?Number(o.groups.count):1})),r=[...t.nucleus[0].matchAll(/[0-9]*(?<element>[A-Z][a-z]?)/g,"$element")][0].groups.element;return i.find(o=>o.element===r)?.count||100}function ln(e){let t={};return".PHASE0"in e&&(t.ph0=Number.parseFloat(e[".PHASE0"]),t.ph1=Number.parseFloat(e[".PHASE1"])),t}function Qe(e){let{ph0:t,ph1:n}=e;return Number.isFinite(t)&&Number.isFinite(n)}import{generateID as mn}from"@zakodium/nmrium-core";function un(e,t,n){for(let i=0;i<e.length;i++){if(t.includes(i))continue;let{delta:r,multiplicity:o="",diaIDs:s}=e[i],a=Number(r)-.01,l=Number(r)+.01;n.push({from:a,to:l,integration:1,id:mn(),signals:[{id:mn(),delta:r,multiplicity:o,diaIDs:s}]})}}import{linearSumAssignment as to}from"linear-sum-assignment";import{xCostMatrix as no}from"ml-spectra-processing";function pn(e,t){let n=e.map(s=>s.delta),i=t.map(s=>s.delta),r=no(i,n,{fct:(s,a)=>Math.abs(s-a)}),{rowAssignments:o}=to(r,{maximaze:!1});return Array.from(o)}function fn(e,t){let{assignments:n,ranges:i}=t;n?.sort((s,a)=>a.delta-s.delta);let r=[],o=[];for(let s of i){let a=0,{from:l,to:c}=s,u=[];for(let p=a;p<n.length;p++){let{delta:g}=n[p];g<=c&&g>=l?(u.push(n[p]),o.push(p)):g>c&&(a=p)}if(u.length>0){let p=s.signals,g=[],d=u.length>1&&p.length>1?pn(p,u):[0];for(let h=0;h<u.length;h++){let f=d[h],{delta:b,multiplicity:m,diaIDs:y}=u[h];f>-1?g.push({...p[f],diaIDs:y}):g.push({delta:b,multiplicity:m,diaIDs:y})}s.signals=g,r.push(s)}}un(n,o,r),r.sort((s,a)=>s.from-a.from),e.ranges={values:H(r).map(s=>{let{integration:a,...l}=s;return l}),options:{sum:t.integrationSum,isSumConstant:!0,sumAuto:!0}},e.ranges.options.moleculeId=String(t.moleculeId)}function yn(e,t,n,i,r){let{logger:o}=r,s={components:hn(e)?ao(e,n.isFid):so(e)},{name:a=n.title||`jcamp_${gn()}`}=r,l={dependentVariables:[s],meta:t,info:{...n,name:V(a)}};return oo(e)&&co(l,i,t,e,n,{logger:o}),l}function hn(e){return"minMax"in e}function oo(e){return!hn(e)}function so(e){return e.spectra.map(t=>{let n=_(t.data);return{...t,data:n}})}function ao(e,t){let n={...e.minMax,z:_(e.minMax?.z)};return t?lo(n):{rr:n}}function co(e,t,n,i,r,o){let{assignmentsByBlocks:s}=t,a=ln(n);Qe(a)&&mo(e,a);let l=String(i.info.BLOCKID);if(s?.[l]){let{molecule:c,assignments:u,moleculeBlockID:p}=s[l],g=cn(c,r),d=_(i.spectra[0].data);if(d.x[0]>d.x[1])for(let m of i.spectra)m.data.x.reverse(),m.data.y.reverse();if(Qe(a)&&i.spectra.length>1){let{re:m}=uo(i,a);d.y=m}let{x:h,y:f}=d,b=an(n,o)??io({x:h,y:f},{peakPicking:{frequency:r.originFrequency},ranges:{frequency:r.originFrequency,integrationSum:g}});fn(e,{moleculeId:p,ranges:b,assignments:u,integrationSum:g})}}function lo(e){let{z:t,...n}=e,i=[],r=[];for(let a=0;a<t.length;a+=2)i.push(t[a].slice()),r.push(t[a+1].slice());let o=dn(i),s=dn(r);return{re:{...n,z:i,minZ:o.min,maxZ:o.max},im:{...n,z:r,minZ:s.min,maxZ:s.max}}}function mo(e,t){let{ph0:n,ph1:i}=t;e.filters||(e.filters=[]),e.filters.push({id:gn(),name:"phaseCorrection",value:{ph0:n,ph1:i,absolute:!1},enabled:!0})}function uo(e,t){let{ph0:n,ph1:i}=t,{re:r,im:o}=ro({re:e.spectra[0].data.y,im:e.spectra[1].data.y},n*Math.PI/180,i*Math.PI/180);return{re:r,im:o}}function bn(e,t,n){let{logger:i}=n,r=[];for(let o of e)if(o.spectra&&o.spectra.length>0||o.minMax){po(o);let s={...o.info,...o.meta},a=ge(s,{logger:i});if(a.experiment==="wobble_curve")continue;r.push(yn(o,s,a,t,n))}return r}function po(e){let t=e.meta["BRUKER FILE EXP"];if(!t)return;let i=(Array.isArray(t)?t:[t]).find(o=>o.slice(0,10).includes("vdlist"));if(!i)return;let r=i.split(`
|
|
8
|
-
`).slice(1);e.info.vdlistValues=me(r)}async function Fe(e,t={}){let n=await e.text(),i=Fn(n,{name:e.name,...t});return Vt(i,e,t)}function Fn(e,t={}){let n={spectra:[],molecules:[]},{name:i,converter:r={},selector:o={},logger:s}=t,{keepRecordsRegExp:a=/.*/}=r,l={keepSpectra:!0,noContour:!0,noTrimRegExp:/\$MOLFILE/,keepRecordsRegExp:a,logger:s},c=Gt(go(e),{name:i,...o,logger:s});for(let u of c)yo(u,n,l,i);if(ho(n,o),n.spectra.length===0&&c.length>0){let u=n.molecules.length===0?" nor molecule":"";s?.warn(`No spectra${u} data was loaded from file ${i}`)}return fo(n)}function yo(e,t,n,i){let r=[],o=[],s={molecules:[]},{logger:a}=n,l={name:i,logger:a};Ze(e,o,n),tn(o,s,r,l),t.spectra.push(...bn(r,s,l)),t.molecules.push(...s.molecules)}function ho(e,t){t.index!==void 0&&(e.spectra=e.spectra.slice(t.index,t.index+1))}var xe=class{id="@zakodium/nmrium-core-plugins#JCAMPDXLoaderPlugin";version=1;migrations=[];onReadProcess;constructor(){this.onReadProcess={supportedExtensions:["jcamp","jdx","dx"],onFile:this.onReadProcessFile.bind(this)}}onReadProcessFile(t,n={}){let{sourceSelector:i={},converter:r,keepSource:o,logger:s}=n;return s?.debug(`Reading JCAMP-DX file: ${t.name}`),Fe(t,{selector:this.getJCAMPDXSelector(i),converter:r?.jcamp,keepSource:o,logger:s})}getJCAMPDXSelector(t={}){let{jcamp:n={},general:i={}}=t,{dataSelection:r="both"}=i;return{...n,dataSelection:r}}};function et(){return new xe}function xn(e){if(e===void 0)return{epoch:null,date:""};let t=e*1e3;return{epoch:t,date:new Date(t).toUTCString()}}var Dn={0:"bigEndian",1:"littleEndian"},Sn={0:"NONE",1:"GSX",2:"ALPHA",3:"ECLIPSE",4:"MASS_SPEC",5:"COMPILER",6:"OTHER_NMR",7:"UNKNOWN",8:"GEMINI",9:"UNITY",10:"ASPECT",11:"UX",12:"FELIX",13:"LAMBDA",14:"GE_1280",15:"GE_OMEGA",16:"CHEMAGNETICS",17:"CDFF",18:"GALACTIC",19:"TRIAD",20:"GENERIC_NMR",21:"GAMMA",22:"JCAMP_DX",23:"AMX",24:"DMX",25:"ECA",26:"ALICE",27:"NMR_PIPE",28:"SIMPSON"},Pn={0:"64Bit Float",1:"32Bit Float",2:"Reserved",3:"Reserved"},Nn={1:"One_D",2:"Two_D",3:"Three_D",4:"Four_D",5:"Five_D",6:"Six_D",7:"Seven_D",8:"Eight_D",9:"not for NMR data formats",10:"not for NMR data formats",11:"not for NMR data formats",12:"Small_Two_D",13:"Small_Three_D",14:"Small_Four_D"},An={0:"None",1:"Real",2:"TPPI",3:"Complex",4:"Real_Complex",5:"Envelope"},Mn={"-8":"Yotta","-6":"Exa","-7":"Zetta","-5":"Pecta","-4":"Tera","-3":"Giga","-2":"Mega","-1":"Kilo",0:"None",1:"Milli",2:"Micro",3:"Nano",4:"Pico",5:"Femto",6:"Atto",7:"Zepto"},In={Yotta:24,Exa:21,Zetta:18,Pecta:15,Tera:12,Giga:9,Mega:6,Kilo:3,None:0,Milli:-3,Micro:-6,Nano:-9,Pico:-12,Femto:-15,Atto:-18,Zepto:-21},Rn={0:"None",1:"Abundance",2:"Ampere",3:"Candela",4:"Celsius",5:"Coulomb",6:"Degree",7:"Electronvolt",8:"Farad",9:"Sievert",10:"Gram",11:"Gray",12:"Henry",13:"Hertz",14:"Kelvin",15:"Joule",16:"Liter",17:"Lumen",18:"Lux",19:"Meter",20:"Mole",21:"Newton",22:"Ohm",23:"Pascal",24:"Percent",25:"Point",26:"Ppm",27:"Radian",28:"Second",29:"Siemens",30:"Steradian",31:"Tesla",32:"Volt",33:"Watt",34:"Weber",35:"Decibel",36:"Dalton",37:"Thompson",38:"Ugeneric",39:"LPercent ",40:"PPT",41:"PPB ",42:"Index"},tt={0:"Ranged",1:"Listed",2:"Sparse",3:"Listed"};function C(e,t){return e.paramArray.find(n=>n.name===t)}function En(e,t){let n=e.paramArray.find(f=>f.name==="orders"),i=e.paramArray.find(f=>f.name==="factors"),r=e.paramArray.find(f=>f.name==="x_sweep"),o=e.paramArray.find(f=>f.name==="x_acq_time"),s=e.paramArray.find(f=>f.name==="x_points");if(!n||!i||!r||!o||!s){t?.error("There is not all parameters to calculate the number of point of digital filter");return}let a=n.value,l=Number.parseInt(a.slice(0,1),10),c=a.slice(1).length/l,u=0,p=new Int8Array(l),g=1,d=0;for(let f=0;f<l;f++)p[f]=Number.parseInt(i.value.slice(d,d+1),10),d+=1;for(let f=0;f<l;f++){let b=1;for(let m=f;m<l;m++)b*=p[m];u+=(Number.parseInt(a.slice(g,g+c),10)-1)/b,g+=c}return u/=2,u/r.value/o.value*(s.value-1)}function R(e,t){let n=C(e,t);if(n===void 0)return{magnitude:"NA",unit:"NA"};let i=n.unit[0],r=i.base,o=In[i.prefix];return{magnitude:n.value*10**o,unit:r}}function nt(e){let t=e.readBytes(4),n=1990+(t[0]>>1),i=(t[0]<<3&8)+(t[1]>>5),r=t[2]&31;return{year:n,month:i,day:r}}function De(e,t){let n=[];for(let i=0;i<t;i++){let r=e.readByte(),o=r>>4,s=Mn[o],a=r&15,l=e.readInt8(),c=Rn[l];n.push({prefix:s,power:a,base:c})}return n}function U(e,t){let n=[];for(let i=0;i<t;i++){let r=e.readChar();r!=="\0"&&n.push(r)}return n.join("")}function rt(e,t){let n=[];for(let i=0;i<t;i++){let r=e.readChar();r!==" "&&n.push(r)}return n.join("")}function M(e,t,n){let i=[];for(let r=0;r<t;r++)switch(n){case"readUint32":i.push(e.readUint32());break;case"readFloat64":i.push(e.readFloat64());break;case"readFloat32":i.push(e.readFloat32());break;case"readUint8":i.push(e.readUint8());break;default:break}return i}function Tn(e,t){let n=[];for(let i=0;i<t;i++)n.push(e.readBoolean());return n}function On(e,t,n){let i=1,r=0;for(let o of t.dataAxisType)o==="Real_Complex"&&r===0&&(i+=1,r+=1),o==="Complex"&&(i*=2);if(t.dataType!=="32Bit Float"&&t.dataType!=="64Bit Float"){n?.error("Only 32Bit Float and 64Bit Float data types are implemented yet");return}if(t.dataFormat==="One_D"){if(i!==1&&i!==2){n?.error("One_D data must have one or two data sections");return}return Fo(e,t,i)}else if(t.dataFormat==="Two_D"){if(i===2)return xo(e,t);if(i===4)return Do(e,t);n?.error("Two_D data must have two or four data sections");return}else{n?.error("Only One_D and two_D data formats are implemented yet");return}}function Fo(e,t,n){return n===1?{re:it(e,t)}:{re:it(e,t),im:it(e,t)}}function it(e,t){return t.dataType==="32Bit Float"?M(e,t.dataPoints[0],"readFloat32"):M(e,t.dataPoints[0],"readFloat64")}var v=32;function xo(e,t){let n=t.dataPoints[0],r=t.dataPoints[1]/v,o=n/v;return{re:Y(e,t,r,o),im:Y(e,t,r,o)}}function Do(e,t){let n=t.dataPoints[0],r=t.dataPoints[1]/v,o=n/v;return{re:{re:Y(e,t,r,o),im:Y(e,t,r,o)},im:{re:Y(e,t,r,o),im:Y(e,t,r,o)}}}function Y(e,t,n,i){let r=[];for(let o=0;o<n;o++){let s=[];for(let a=0;a<i;a++)for(let l=0;l<v;l++)a===0?t.dataType==="32Bit Float"?s[l]=M(e,v,"readFloat32"):t.dataType==="64Bit Float"&&(s[l]=M(e,v,"readFloat64")):t.dataType==="32Bit Float"?s[l]=s[l].concat(M(e,v,"readFloat32")):t.dataType==="64Bit Float"&&(s[l]=s[l].concat(M(e,v,"readFloat64")));r=r.concat(s)}return r}function Cn(e){let t=e.readChars(8),n=e.readInt8(),i=Dn[n],r=e.readUint8(),o=e.readUint16(),s=e.readUint8(),a=e.readByte().toString(2).split("").map(T=>!!Number(T)),l=e.readByte(),c=l>>6,u=Pn[c],p=l&63,g=Nn[p],d=e.readInt8(),h=Sn[d],f=M(e,8,"readUint8"),b=M(e,8,"readUint8").map(T=>An[T]),m=De(e,8),y=U(e,124),F=[];for(let T of M(e,4,"readUint8")){let ee=T>>4,qe=T&15;F.push(tt[ee],tt[qe])}let D=M(e,8,"readUint32"),N=M(e,8,"readUint32"),x=M(e,8,"readUint32"),P=M(e,8,"readFloat64"),A=M(e,8,"readFloat64"),I=nt(e),gt=nt(e),Le=U(e,16),cr=U(e,128),lr=U(e,128),mr=U(e,128),yt=[];for(let T=0;T<8;T++)yt.push(U(e,32));let ur=M(e,8,"readFloat64"),pr=M(e,8,"readFloat64"),fr=Tn(e,8);e.skip(3);let dr=!!(e.readByte()>>7),gr=e.readUint32(),yr=e.readUint32(),hr=e.readUint32(),br=e.readUint32(),Fr=M(e,8,"readUint32"),xr=M(e,8,"readUint32"),Dr=e.readUint32(),Sr=e.readUint32()<<32|e.readUint32(),Pr=e.readUint32()<<32|e.readUint32(),Nr=e.readUint32(),Ar=e.readUint32()<<32|e.readUint32(),Mr=e.readUint32(),Ir=e.readUint32()<<32|e.readUint32(),Rr=M(e,8,"readUint8"),ht=[];for(let T=0;T<2;T++){let ee=[],qe=e.readInt16();for(let bt=0;bt<5;bt++)ee.push(e.readInt16());ht.push({scaler:qe,unit:ee})}return{fileIdentifier:t,endian:i,majorVersion:r,minorVersion:o,dataDimensionNumber:s,dataDimensionExist:a,dataType:u,dataFormat:g,dataInstrument:h,translate:f,dataAxisType:b,dataUnits:m,title:y,dataAxisRanged:F,dataPoints:D,dataOffsetStart:N,dataOffsetStop:x,dataAxisStart:P,dataAxisStop:A,creationTime:I,revisionTime:gt,nodeName:Le,site:cr,author:lr,comment:mr,dataAxisTitles:yt,baseFreq:ur,zeroPoint:pr,reversed:fr,annotationOK:dr,historyUsed:gr,historyLength:yr,paramStart:hr,paramLength:br,ListStart:Fr,ListLength:xr,dataStart:Dr,dataLength:Sr,contextStart:Pr,contextLength:Nr,annoteStart:Ar,annoteLength:Mr,totalSize:Ir,unitLocation:Rr,compoundUnit:ht}}var So={0:"String",1:"Integer",2:"Float",3:"Complex",4:"Infinity"};function wn(e){let t=e.readUint32(),n=e.readUint32(),i=e.readUint32(),r=e.readUint32(),o=[];for(let s=0;s<i+1;s++){e.skip(4);let a=e.readInt16(),l=De(e,5);e.skip(16);let c=e.readInt32(),u=So[c];e.seek(e.offset-20);let p;switch(u){case"String":p=rt(e,16);break;case"Integer":p=e.readInt32(),e.skip(12);break;case"Float":p=e.readFloat64(),e.skip(8);break;case"Complex":p={Real:e.readFloat64(),Imag:e.readFloat64()};break;case"Infinity":p=e.readInt32(),e.skip(12);break;default:e.skip(16);break}e.skip(4);let g=rt(e,28);o.push({name:g.toLowerCase(),scaler:a,unit:l,value:p,valueType:u})}return{parameterSize:t,lowIndex:n,highIndex:i,totalSize:r,paramArray:o}}function vn(e,t){let n=new O(e);n.setBigEndian();let i=Cn(n);i.endian==="littleEndian"&&n.setLittleEndian(),n.seek(i.paramStart);let r=wn(n);n.seek(i.dataStart);let o=On(n,i,t),s=[],a=[],l=[],c=[],u=[],p=[],g=[],d=[],h=[],f=[];if(i.dataFormat==="One_D"||i.dataFormat==="Two_D"){let m=xn(C(r,"actual_start_time")?.value);m.date&&(a.push(m.date),l.push(m.epoch)),s.push(C(r,"x_domain")?.value),c.push(R(r,"x_acq_time")),u.push(R(r,"x_sweep")),p.push(R(r,"x_sweep_clipped")),g.push(R(r,"x_resolution")),d.push(R(r,"x_freq")),h.push(R(r,"x_offset")),f.push(i.dataUnits[0].base)}return i.dataFormat==="Two_D"&&(s.push(C(r,"y_domain")?.value),c.push(R(r,"y_acq_time")),u.push(R(r,"y_sweep")),g.push(R(r,"y_resolution")),d.push(R(r,"y_freq")),h.push(R(r,"y_offset")),f.push(i.dataUnits[1].base)),{info:{sampleName:C(r,"sample_id")?.value,creationTime:i.creationTime,revisionTime:i.revisionTime,author:i.author,comment:i.comment,solvent:C(r,"solvent")?.value,temperature:R(r,"temp_get"),probeName:C(r,"probe_id")?.value,fieldStrength:R(r,"field_strength"),experiment:C(r,"experiment")?.value,dimension:i.dataDimensionNumber,nucleus:s,date:a,epoch:l,pulseStrength90:R(r,"x90"),numberOfScans:C(r,"scans")?.value,relaxationTime:R(r,"relaxation_delay"),dataPoints:i.dataPoints.slice(0,i.dataDimensionNumber),dataOffsetStart:i.dataOffsetStart,dataOffsetStop:i.dataOffsetStop,dataUnits:f,dataSections:o?Object.keys(o):void 0,originFrequency:d,frequencyOffset:h,acquisitionTime:c,spectralWidth:u,spectralWidthClipped:p,dataAxisStart:i.dataAxisStart,dataAxisStop:i.dataAxisStop,resolution:g,decimationRate:C(r,"decimation_rate")?.value,paramList:JSON.stringify(r.paramArray.map(m=>m.name)),digitalFilter:En(r,t)},headers:i,parameters:r,data:o}}import{formatSpectra as Mo}from"@zakodium/nmrium-core";import{getGyromagneticRatio as Io}from"gyromagnetic-ratio";import{isAnyArray as Ro}from"is-any-array";import Eo from"lodash.merge";import{normalizeNucleus as To}from"nmr-processing";import{isAnyArray as G}from"is-any-array";var kn={0:"uint8",1:"uint16",2:"uint32",3:"uint64",4:"int8",5:"int16",6:"int32",7:"int64",8:"float32",9:"float64",10:"complex64",11:"complex128"},Ln={0:"scalar",1:"vector",2:"matrix",3:"symetricMatrix",4:"pixel"};function qn(e,t,n={}){let{quantityType:i=0,encoding:r="none",name:o="",unit:s="",quantityName:a="",sparseSampling:l={},from:c=[0],to:u=[-1]}=n;if(G(e))throw new Error("JEOL with an array of data is not yet supported");if(!("re"in e&&"im"in e))throw new Error("Only re/im data is supported");let p=st(e,c,u),{componentLabels:g=p.componentLabels}=n;return{type:"internal",quantityType:Ln[i],numericType:kn[t],encoding:r,name:o,unit:s,quantityName:a,componentLabels:g,sparseSampling:l,description:n.description||"",application:n.application||"",components:p.components,dataLength:p.dataLength}}function Po(e){return G(e.re)&&G(e.im)}function No(e){return!G(e.re[0])}function st(e,t,n){let i=[],r=[],o=[];if(Po(e))if(No(e)){i[0]=ot(t[0],n[0],e.re.length);let s=new Float64Array(i[0]);for(let a=0;a<i[0];a+=2){let l=a+t[0]*2;s[a]=e.re[l/2],s[a+1]=e.im[l/2]}o.push(s),r.push("complex")}else if(G(e.re[0])){i[0]=Ao(t[1],n[1],e.re.length),i[1]=ot(t[0],n[0],e.re[0].length);for(let s=0;s<i[0];s++){let a=new Float64Array(i[1]);for(let l=0;l<i[1];l+=2){let c=l+t[0]*2;a[l]=e.re[s][c/2],a[l+1]=e.im[s][c/2]}o.push(a)}}else throw new Error("check your object");else if(G(e.re.re)){i[0]=ot(t[1],n[1],e.re.re.length);let s=st(e.re,t,n).components,a=st(e.im,t,n).components;for(let l=0;l<i[0]/2;l++)o.push(s[l],a[l])}else throw new Error("check the dimension or the type of data in your array");return{dataLength:i,componentLabels:r,components:o}}function Ao(e,t,n){return t-e+1<n?t-e+1:n}function ot(e,t,n){return t-e+1<n?(t-e+1)*2:n*2}async function Bn(e,t={}){let n=await e.arrayBuffer(),{name:i=V(e.name),keepSource:r=!1}=t,o={spectra:[],molecules:[]},a=wo(n)[0],{metadata:l,...c}=a.description,u=0,p=c.dimension===1?"1d":"2d",g="NMR SPECTRUM",d=c.dimension===1?c.nucleus[0]:c.nucleus,h=c.spectralWidthClipped[0],f;a.dependentVariables&&(c.dimension===1?f=Oo(a):c.dimension===2&&(f=Co(a)));for(let m in c)Array.isArray(c[m])&&c[m].length===1&&(c[m]=c[m][0]);let b={data:f,info:{...c,acquisitionMode:u,experiment:p,type:g,nucleus:d,spectralWidthClipped:h,name:i},meta:l};return r&&(b.sourceSelector={files:[e.relativePath]}),o.spectra=[b],Mo(o)}function Oo(e){let t=e.dimensions[0],n=e.dependentVariables,i=t.quantityName,r=t.count,o=t.increment.magnitude,s=t.originOffset.magnitude,a=t.coordinatesOffset.magnitude,l=n[0].components[0],c=new Float64Array(r),u=new Float64Array(r);for(let f=l.length-1,b=0;f>0;f-=2)c[b]=l[f-1],u[b++]=l[f];let p={},[g,d]=[0,0];switch(i){case"frequency":d=0+a/s*1e6,g=o/s*1e6,p.re=c,p.im=u;break;case"time":d=s,g=o,p.re=c.reverse(),p.im=u.reverse().map(f=>-f);break;default:break}let h=[];for(let f=0;f<r;f++)h.push(d+f*g);return p.x=h,p}function Co(e){let t=e.dimensions,n=e.dependentVariables,i=t[0].quantityName,r=[],o=[],s=Number.MIN_SAFE_INTEGER,a=Number.MAX_SAFE_INTEGER,l=Number.MAX_SAFE_INTEGER,c=Number.MIN_SAFE_INTEGER;for(let g of n[0].components){let d=new Float64Array(g.length/2),h=new Float64Array(g.length/2);for(let f=g.length-1,b=0;f>0;f-=2){let m=g[f-1],y=g[f];m>s&&(s=m),m<a&&(a=m),y>c&&(c=y),y<l&&(l=y),d[b]=m,h[b++]=y}if(i==="frequency")r.push(d),o.push(h);else{let f=d.length,b=new Float64Array(h.length);for(let m=0,y=f-1;m<f;m++)b[m]=-h[y--];r.push(d.reverse()),o.push(b)}}let u={re:{z:r,minZ:a,maxZ:s},im:{z:o,minZ:l,maxZ:c}},p=["X","Y"];for(let g=0;g<p.length;g++){let d=t[g].count,h=t[g].increment.magnitude,f=t[g].originOffset.magnitude,b=t[g].coordinatesOffset.magnitude,m=p[g];for(let y of["re","im"])i==="frequency"?(u[y][`min${m}`]=0+b/f*1e6,u[y][`max${m}`]=d*(h/f)*1e6):(u[y][`min${m}`]=f,u[y][`max${m}`]=d*h)}return u}function wo(e){let t=vn(e),n=t.info,i=t.headers,{paramArray:r,...o}=t.parameters,{dimension:s}=n,a={};for(let m of r){let{name:y,value:F}=m;a[y]=Un(F,s)}let l=t.data,c={};c.title=`title: ${i.title} / comment: ${i.comment} / author:${i.author} / site: ${i.site}`,c.nucleus=n.nucleus.map(To),c.sampleName=n.sampleName,c.date=n.date,c.epoch=n.epoch,c.localeDate=new Date(n.epoch[0]).toLocaleString(),c.author=n.author,c.solvent=n.solvent,c.temperature=n.temperature.magnitude,c.probeName=n.probeName||"",c.fieldStrength=n.fieldStrength.magnitude;let u=c.nucleus.map(Io);c.baseFrequency=u.map(m=>n.fieldStrength.magnitude*m/(2*Math.PI*1e6)),c.pulseSequence=n.experiment,c.temperature=n.temperature?.unit?.toLowerCase()==="celsius"?273.15+n.temperature.magnitude:n.temperature.magnitude,c.digitalFilter=n.digitalFilter,c.pulseStrength90=1/(4*n.pulseStrength90.magnitude),c.numberOfScans=n.numberOfScans,c.relaxationTime=n.relaxationTime.magnitude,c.isComplex=n.dataSections?n.dataSections.includes("im"):!1,c.isFid=n.dataUnits[0]==="Second",c.isFt=n.dataUnits[0]==="Ppm",c.dimension=n.dimension,c.originFrequency=n.originFrequency.map(m=>m.magnitude/1e6).slice(0,s),c.numberOfPoints=n.dataPoints.slice(0,1),c.frequencyOffset=n.frequencyOffset.map((m,y)=>m.magnitude*c.baseFrequency[y]).slice(0,s),c.acquisitionTime=n.acquisitionTime.map(m=>m.magnitude).slice(0,s),c.spectralWidth=n.spectralWidth.map((m,y)=>m.magnitude/n.originFrequency[y].magnitude*1e6).slice(0,s),c.spectralWidthClipped=n.spectralWidthClipped.map((m,y)=>m.magnitude/c.baseFrequency[y]*1e6).slice(0,s);let p=[],g={},d;for(let m=0;m<n.dimension;m++){if(d={magnitude:n.acquisitionTime[m].magnitude/(n.dataPoints[m]-1),unit:"s"},n.dataUnits[m]==="Second")g.quantityName="time",g.originOffset={magnitude:0,unit:"s"},m===0?g.coordinatesOffset={magnitude:n.digitalFilter*d.magnitude,unit:"s"}:g.coordinatesOffset={magnitude:0,unit:"s"},g.reciprocal={originOffset:{magnitude:n.originFrequency[m].magnitude,unit:"Hz"},quantityName:"frequency",coordinatesOffset:{magnitude:n.frequencyOffset[m].magnitude*n.originFrequency[m].magnitude/1e6,unit:"Hz"}};else if(n.dataUnits[m]==="Ppm"){g.quantityName="frequency";let y=n.originFrequency[m].magnitude;g.originOffset={magnitude:y,unit:"Hz"};let F=n.dataOffsetStart[m],N=n.dataOffsetStop[m]-F+1;d={magnitude:vo(n,m)/(N-1),unit:"Hz"};let A=n.dataAxisStop[m]*y/1e6;g.coordinatesOffset={magnitude:A,unit:"Hz"},N!==n.dataPoints[m]&&(n.dataPoints[m]=N)}m===0?g.description="direct dimension":g.description="indirect dimension",p.push({label:String(i.dataAxisTitles[m]),count:Number(n.dataPoints[m]),increment:d,type:"linear",description:String(g.description)||"",application:g.application||{},coordinatesOffset:g.coordinatesOffset||0,originOffset:g.originOffset||0,quantityName:String(g.quantityName)||"",reciprocal:g.reciprocal||{},period:g.period||0,complexFFT:g.complexFFT||!1})}let h=[];h.push(qn(l,11,{unit:"none",quantityName:"relative intensity",from:n.dataOffsetStart,to:n.dataOffsetStop}));let f={...c};return delete f.paramList,f.metadata={..._n(i,s),..._n(o,s),...Eo({},a)},[{timeStamp:Date.now(),description:f,dimensions:p,dependentVariables:h}]}function vo(e,t){let{spectralWidth:n,spectralWidthClipped:i}=e;return i[t].magnitude!=="NA"?i[t].magnitude:n[t].magnitude}function _n(e,t){let n={};for(let i in e)n[i]=Un(e[i],t);return n}function Un(e,t){return Ro(e)?t>1?e.slice(0,t):e[0]:e}var Se=class{id="@zakodium/nmrium-core-plugins#JEOLLoaderPlugin";version=1;migrations=[];onReadProcess;constructor(){this.onReadProcess={supportedExtensions:["jdf"],onFile:this.onReadProcessFile.bind(this)}}onReadProcessFile(t,n={}){let{logger:i,keepSource:r}=n;return i?.debug(`Reading JEOL file: ${t.name}`),Bn(t,{name:t.name,keepSource:r,logger:i})}};function at(){return new Se}var Pe=class{id="@zakodium/nmrium-core-plugins#MolfileLoaderPlugin";version=1;migrations=[];onReadProcess;constructor(){this.onReadProcess={supportedExtensions:["mol"],onFile:this.onReadProcessFile.bind(this)}}onReadProcessFile(t,n={}){let{logger:i}=n;return i?.debug(`Reading molfile file: ${t.name}`),Kt(t,{logger:i})}};function ct(){return new Pe}import{getSDF as Uo,nmrRecordToJSON as $o}from"@zakodium/nmredata";import{generateID as zn}from"@zakodium/nmrium-core";import{generateID as $n}from"@zakodium/nmrium-core";import{xyIntegration as ko}from"ml-spectra-processing";function jn(e,t){let{x:n,re:i}=t.data;return e.map(r=>{let o=ko({x:n,y:i},{from:r.from,to:r.to}),s=[];for(let a of r.signals||[]){let{kind:l=null,id:c,js:u=[],diaIDs:p=[],...g}=a;s.push({...g,kind:l||"signal",js:u,id:c||$n(),diaIDs:p})}return{...r,id:r.id||$n(),kind:s?.[0].kind||"signal",absolute:o,signals:s}})}function Wn(e,t){let n=[],{baseFrequency:i=500}=t.info;for(let r of e){let{delta:o,diaIDs:s=[],multiplicity:a="",integration:l=0}=r,c=r.jCoupling||[],u=Lo({delta:o,js:c,frequency:i});if(c&&a&&c.length===a.length){c.sort((p,g)=>g.coupling-p.coupling);for(let p=0;p<c.length;p++)c[p].multiplicity=a[p]}n.push({id:zn(),...u,integration:l,signals:[{id:zn(),js:c,delta:o,diaIDs:s,multiplicity:a}]})}t.ranges.values=jn(H(n),t)}function Lo(e){let{delta:t,js:n=[],frequency:i}=e,r=.5;for(let o of n)r+=o.coupling;return r/=i,{from:t-r,to:t+r}}import{generateID as Jn}from"@zakodium/nmrium-core";var qo=["x","y"],_o={x:0,y:0};function Xn(e,t,n={}){let i=[],{shift:r=_o}=n,{originFrequency:o=[400,400]}=t.info,s={x:o[0],y:o[1]};for(let a of e){let l={x:{},y:{},id:Jn(),kind:"signal"},c={id:Jn(),kind:"signal",peaks:[]},u={x:10,y:10};for(let p of qo){let{coupling:g=[],delta:d,diaIDs:h=[]}=a[p];for(let f of g)u[p]+=f.coupling;if(a.activeCoupling){let{activeCoupling:f=[]}=a;for(let b of f)u[p]+=b.coupling}u[p]/=s[p],l[p]={from:d-u[p],to:d+u[p]},c[p]={delta:d,diaIDs:h,originalDelta:d-r[p]}}i.push({...l,signals:[c]})}t.zones.values=i}function Vn(e){return Bo(e.data)}function Bo(e){return"rr"in e||!("x"in e)&&"re"in e}async function Hn(e,t,n={}){let i={spectra:[],molecules:[]},r=await jo(e,t,n);if(r.spectra.length>0){let{spectra:o,molecules:s,usedFiles:a}=r;i.spectra.push(...o),i.molecules.push(...s);let l=e.files.length;for(let c=l-1;c>=0;c--){let u=e.files[c].relativePath;!u.match(/acqu.*/s)&&a.includes(u)&&e.files.splice(c,1)}}return i}async function jo(e,t,n){let i=[],r=await Uo(e),o={spectra:[],molecules:[]};if(r.length===0)return{...o,usedFiles:i};let s=[];for(let l of r){let c=$o({sdf:l,fileCollection:e}).then(u=>{let{spectra:p,molecules:g=[]}=u;return i.push(l.root+l.filename),o.molecules.push(...g),zo(p,t,n)});s.push(c)}let a=await Promise.allSettled(s);for(let l of a)l.status==="fulfilled"?(o.spectra.push(...l.value.spectra),i.push(...l.value.usedFiles)):l.reason&&n?.logger?.error(l.reason);return{...o,usedFiles:i}}async function zo(e,t,n){let i=[],r=[],o={spectra:[],molecules:[]};for(let s of e){let a=Wo(s.source,t,n).then(l=>{let{spectra:c,files:u}=l;i.push(...u);for(let p of c)Vn(p)?Xn(s.signals,p):Wn(s.signals,p);o.spectra.push(...c)});r.push(a)}return await Promise.allSettled(r),{...o,usedFiles:i}}async function Wo(e,t,n={}){let{file:i,jcampURL:r}=e,{converter:o}=n;if(r){let l=await Jo(r,t,o?.jcamp);if(l)return{...l,files:[]}}let s=[];for(let l of i||[])s.push(Xo(l,n).then(c=>({...c,files:l.fileCollection.files.map(u=>u.relativePath)})));let a=await Promise.allSettled(s);for(let l of a){if(l.status==="fulfilled")return l.value;l.reason&&n?.logger?.error(l.reason)}return{spectra:[],molecules:[],files:[]}}async function Jo(e,t,n={}){let i={entries:[{relativePath:e}]},r={name:V(e||""),xy:!0,noContours:!0,...n},{data:o}=await t.readFromWebSource(i,r);return o}async function Xo(e,t={}){let{converter:n,sourceSelector:i}=t;switch(e.type){case"jcamp":return Fe(e.fileCollection.files[0],{name:e?.fileCollection.files[0].name||"",converter:n?.jcamp,selector:i?.jcamp,logger:t.logger,keepSource:t.keepSource});case"brukerFiles":return ye(e.fileCollection,{converter:n?.bruker,selector:i});default:throw new Error("There is not a supported source")}}var Ne=class{id="@zakodium/nmrium-core-plugins#NMReDATALoaderPlugin";version=1;migrations=[];onReadProcess;#e;constructor(t){this.#e=t,this.onReadProcess={onFiles:this.onReadProcessFiles}}onReadProcessFiles=(t,n)=>Hn(t,this.#e,n)};function lt(e){return new Ne(e)}import{parse as Vo}from"sdf-parser";function Yn(e,t={}){let{mixedEOL:n}=t,{molecules:i}=Vo(e,{mixedEOL:n}),r=[];for(let{molfile:o}of i){let s=X(o);r.push(...s)}return r}async function Gn(e,t={}){let{logger:n,mixedEOL:i}=t,r=await e.text(),o=Yn(r,{mixedEOL:i}),s={molecules:o,spectra:[]};return n&&n[o.length>0?"info":"debug"](`Loaded ${s.molecules.length} molecules from the ${e.name} file`),s}var Ae=class{id="@zakodium/nmrium-core-plugins#SDFLoaderPlugin";version=1;migrations=[];onReadProcess;constructor(){this.onReadProcess={supportedExtensions:["sdf"],onFile:this.onReadProcessFile.bind(this)}}onReadProcessFile(t,n={}){let{logger:i}=n;return i?.debug(`Reading sdf file: ${t.name}`),Gn(t,{logger:i})}};function mt(){return new Ae}import{Molecule as Ho}from"openchemlib";function Zn(e){let t=[],n=e.split(/\r?\n/).filter(Boolean);for(let i of n){let o=Ho.fromSmiles(i).toMolfile();t.push({molfile:o})}return t}async function Kn(e,t={}){let n=await e.text(),i=Zn(n),r={molecules:i,spectra:[]};return t.logger?.info(`Found ${i.length} molecules from the ${e.name} file`),r}var Me=class{id="@zakodium/nmrium-core-plugins#SMILESLoaderPlugin";version=1;migrations=[];onReadProcess;constructor(){this.onReadProcess={supportedExtensions:["smi","smiles"],onFile:this.onReadProcessFile.bind(this)}}onReadProcessFile(t,n={}){let{logger:i}=n;return Kn(t,{logger:i})}};function ut(){return new Me}import{formatSpectra as Qo}from"@zakodium/nmrium-core";import{createFromToArray as Go}from"ml-spectra-processing/utils";function Qn(e){e.setLittleEndian();let t=e.offset,n=32*3;e.offset=n/8;let i=e.readInt32(),r=[2,4],o=[2**25,2**26];if(!r.includes(i))if(o.includes(i))e.setBigEndian();else throw new Error(`Unexpected value of eBytes (${i}). Expect one of
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
`,{JCAMPDX:a="",ORIGIN:l=""}=e,c=String(a).toLowerCase()+String(l).toLowerCase();"SPECTROMETER/DATASYSTEM"in e&&(c=e["SPECTROMETER/DATASYSTEM"]);let u=(m=[])=>{for(let y of m)if(!(y in r))return!1;return!0};(c.includes("mestre")||c.includes("nova"))&&(c="mnova"),r.creator=c,e.LONGDATE&&Ke(r,Date.parse(e.LONGDATE)),S(r,"pulseSequence",e[".PULSESEQUENCE"]||e[".PULPROG"]||e[`${n}PULPROG`]);let f=e[`${n}OWNER`];if(f&&S(r,"owner",f.replaceAll(/\$\$.*/gm,"")),S(r,"aqMod",e[`${n}AQ_mod`]),S(r,"experiment",te(r,e,{prefix:n})),r.nucleus=fe(e,r,n),r.nucleus.length===0)if(i)i?.warn("There is not a nucleus detected, assuming 1H"),r.nucleus=["1H"];else throw new Error("There is not a nucleus detected");r.dimension=r.nucleus.length;let d=e[`${n}.ACQUISITIONSCHEME`]||e[`${n}FnMODE`];if(d&&S(r,"acquisitionScheme",Xt(K(d,1))),S(r,"acquisitionMode",e[`${n}.ACQUISITIONMODE`]),E(r,"lpNumberOfCoefficients",e[`${n}NCOEF`]),E(r,"linearPredictionBin",e[`${n}LPBIN`]),E(r,"tdOff",e[`${n}TDoff`]),S(r,"windowMultiplicationMode",e[`${n}WDW`]),S(r,"title",e.TITLE),S(r,"solvent",e[".SOLVENTNAME"]),S(r,"temperature",e[`${n}TE`]||e[".TE"]),S(r,"type",e.DATATYPE),S(r,"dataClass",e[`${n}DATACLASS`]),S(r,"phc1",e[`${n}PHC1`]),S(r,"phc0",e[`${n}PHC0`]),r.type){let m=r.type[0].toUpperCase();m.includes("FID")?(r.isFid=!0,r.isComplex=!0):m.includes("SPECTRUM")&&(r.isFt=!0)}if(S(r,"firstX",e[`${n}FIRSTX`]),S(r,"lastX",e[`${n}LASTX`]),S(r,"numberOfPoints",e[`${n}NPOINTS`]),S(r,"originFrequency",e[`${n}SFO1`]),r.dimension===1&&E(r,"originFrequency",e[".OBSERVEFREQUENCY"]),"originFrequency"in r&&(r.originFrequency=de(r.originFrequency)),!r.originFrequency&&r.dimension===2&&".OBSERVEFREQUENCY"in e){let{nucleus:m}=r,y=de(e[".OBSERVEFREQUENCY"]);if(Yt(y)&&y.length>1){let F=e[`${n}SYMBOL`].split(","),x=F.findIndex(D=>D.includes("2")),N=F.findIndex(D=>D.includes("1"));x!==-1&&N!==-1?r.originFrequency=[y[x],y[N]]:r.originFrequency=y.slice()}else if(typeof y=="number"){let F=Wi(m[1],{frequency:y,nucleus:m[0]});r.originFrequency=[y,F]}}if((!r.originFrequency||r.originFrequency.some(m=>Number.isNaN(m)||m===0))&&(r.originFrequency||(r.originFrequency=r.dimension>1?[400,400]:[400]),r.originFrequency=r.originFrequency.map(m=>Number.isNaN(m)||m===0?400:m),i?.warn("The frequency could not be determined and was set to 400 MHz")),c.toLocaleLowerCase().includes("oxford instruments")?Xi(r,e,{...t,separator:s}):c.includes("nanalysis")&&Hi(r,e),c!=="mnova"&&c!=="mestre"){let m=r.nucleus[0],y=Ji(m);if(S(r,"probeName",e[`${n}PROBHD`]),S(r,"baseFrequency",e[`${n}BF1`]),S(r,"baseFrequency",e[`${n}SF`]),E(r,"scaleFactor",e[`${n}NC_proc`]),"scaleFactor"in r)for(let D=0;D<r.scaleFactor.length;)r.scaleFactor[D]=2**r.scaleFactor[D++];if(!("baseFrequency"in r)&&"originFrequency"in r?S(r,"baseFrequency",r.originFrequency):r.baseFrequency=de(r.baseFrequency),!["baseFrequency","originFrequency"].some(D=>!r[D])&&y){let{baseFrequency:D}=r,P=2*Math.PI*(D[0]/y)*1e6;S(r,"fieldStrength",P)}E(r,"spectralWidth",e[`${n}SW`]),E(r,"spectralWidth",e[`${n}QM_SPECTRAL_WIDTH`]),r.dimension===1&&e[`${n}SweepWidth`]&&r.originFrequency&&E(r,"spectralWidth",e[`${n}SweepWidth`]/r.originFrequency[0]),S(r,"numberOfPoints",e[`${n}TD`],!0);let F=r.numberOfPoints;if(S(r,"spectrumSize",e[`${n}SI`]??F),S(r,"sampleName",e[`${n}NAME`]),e[`${n}FNTYPE`]!==void 0&&S(r,"acquisitionMode",Number.parseInt(e[`${n}FNTYPE`],10)),(e[`${n}VARNAME`]?e[`${n}VARNAME`].split(",")[0]:"")==="TIME"){let D=typeof e.LAST=="string"?e.LAST.replace(" ","").split(",")[0]:e.LAST;E(r,"acquisitionTime",D)}if(!r.acquisitionTime&&u(["numberOfPoints","spectralWidth"])){let{spectralWidth:D,originFrequency:P}=r;S(r,"acquisitionTime",Number((F[0]-1)/(2*D[0]*P[0])))}if(e[`${n}P`]){let D=1e6/(K(e[`${n}P`]).split(s)[1].split(" ")[1]*4);S(r,"pulseStrength90",D)}if(e[`${n}D`]){let D=K(e[`${n}D`]).split(s)[1].split(" ")[1];E(r,"relaxationTime",D)}if(E(r,"numberOfScans",e[`${n}NS`]),E(r,"numberOfScans",e[`${n}QM_NSCANS`]),S(r,"groupDelay",e[`${n}GRPDLY`]),S(r,"dspfvs",e[`${n}DSPFVS`]),S(r,"decim",e[`${n}DECIM`]),r.isFid&&("groupDelay"in r||u(["dspfvs","decim"]))){let{groupDelay:D,dspfvs:P,decim:A}=r,I=Vt(D?.[0]??0,P?.[0],A?.[0]);S(r,"digitalFilter",I)}let N;if(u(["numberOfPoints","spectralWidth"])){let{spectralWidth:D,numberOfPoints:P}=r;r.isFid?N=P.map(A=>r.acquisitionTime[0]/(A-1)):N=P.map((A,I)=>D[I]/(A-1))}if(S(r,"increment",N),e[`${n}DATE`]){let D=K(e[`${n}DATE`]),P=Number.parseInt(D,10)*1e3;Number.isNaN(P)?Ke(r,Date.parse(D)):Ke(r,P)}r.solvent||S(r,"solvent",K(e[`${n}SOLVENT`]))}!("baseFrequency"in r)&&"originFrequency"in r&&S(r,"baseFrequency",r.originFrequency);let g=r.dimension<2,h="dataClass"in r&&r.dataClass[0].toUpperCase()==="NTUPLES",p=["LAST","FIRST","VARDIM","SYMBOL"].every(m=>`${n}${m}`in e);if(g&&(h||p)&&(S(r,"last",j(e[`${n}LAST`])),S(r,"first",j(e[`${n}FIRST`])),S(r,"varDim",j(e[`${n}VARDIM`])),S(r,"symbols",j(e[`${n}SYMBOL`])),r.symbols&&Array.isArray(r.symbols))){r.symbols.includes("R")&&r.symbols.includes("I")&&(r.isComplex=!0);let m=r.symbols.findIndex(y=>y.toLowerCase()==="x");if(E(r,"firstX",r.first[m]),E(r,"lastX",r.last[m]),E(r,"numberOfPoints",r.varDim[m]),!("spectralWidth"in r)){let{lastX:y,numberOfPoints:F,firstX:x}=r;S(r,"spectralWidth",r.isFid?F/(2*y):Math.abs(y-x)/r.originFrequency)}}if(`${n}REVERSE`in e){let m=e[`${n}REVERSE`];r.reverse=(Array.isArray(m)?m:[m]).map(y=>typeof y=="string"?y.includes("yes"):y)}let b=e[`${n}REFERENCE_POINT`];if(!("frequencyOffset"in r)&&b&&u(["spectralWidth","baseFrequency"])){let m=typeof b=="number"?b:e[`${n}REFERENCE_POINT`].match(/(?<reference>[+-]?\d+(?:\.\d+)?)\s*.*/),y;if(typeof b=="number"?y=b:(b.match(/(?<reference>[+-]?\d+(?:\.\d+)?)\s*.*/),y=Number(m?.groups?.reference)),!Number.isNaN(y)){let{spectralWidth:F,baseFrequency:x}=r;S(r,"frequencyOffset",.5*F*x-y)}}if(!("frequencyOffset"in r)&&u(["baseFrequency","originFrequency"])){let{baseFrequency:m,originFrequency:y}=r,F=m.map((x,N)=>(y[N]-x)*1e6);S(r,"frequencyOffset",F)}for(let m in r)r[m]&&r[m].length===1&&(r[m]=r[m][0]);return!r.frequencyOffset&&".SHIFTREFERENCE"in e&&Vi(e,r),Array.isArray(r.nucleus)||(r.nucleus=[r.nucleus]),r}function E(e,t,n){n!==void 0&&S(e,t,de(n))}function Ke(e,t){if(!Number.isNaN(t)){e.epoch=t;let n=new Date(t);e.date=n.toUTCString(),e.localeDate=n.toLocaleString()}}function Vi(e,t){let n=e[".SHIFTREFERENCE"],i=n.trim().startsWith("(")?/\((?<data>[^)]+)\)/:/(?<data>[^)]+)/,r=n.match(i);if(r.groups.data){let o=r.groups.data.split(",");if(o.length<4)return;let s=Number.parseInt(t.numberOfPoints,10),{spectralWidth:a,baseFrequency:l}=t,c=Number.parseInt(o[2],10),u=Number.parseFloat(o[3]),f;if(t.isFid){if(["baseFrequency","numberOfPoints","spectralWidth"].some(d=>!(d in t)))return;f=u+(s*.5-c)*a/s}else{let d=Number.parseFloat(t.firstX),g=Number.parseFloat(t.lastX),h=(g+d)/2,p=(g-d)/(s+1),b=p<0?d:g+(c-1)*p;f=(h-b)/l+u}f!==void 0&&!Number.isNaN(f)&&(t.frequencyOffset=f*l)}}function de(e){if(Yt(e)){let t=[];for(let n of e)t.push(typeof n=="string"?Number.parseFloat(n):n);return t}return typeof e=="string"?Number.parseFloat(e):e}function Xi(e,t,n={}){let{prefix:i="",separator:r=`
|
|
6
|
+
`}=n;S(e,"spectralWidth",t[`${i}SweepWidth`]/e.originFrequency[0]);let o=t[`${i}.PULSESEQUENCE`].split(r),s=[];t[".OBSERVENUCLEUS"]&&s.push(t[".OBSERVENUCLEUS"]),t.INDIRECTNUCLEUS&&s.push(t.INDIRECTNUCLEUS),e.nucleus=w(s),e.pulseSequence=o[0];let a=o.slice(2,-1);if(s.length>1)if(s[0]===s[1])e.spectralWidth.push(e.spectralWidth[0]);else{let l=JSON.stringify(a).match(/\$\$SW1=\s*(?<sw>[+-]?(?:[0-9]*[.])?[0-9]+)/);if(l?.groups){let{originFrequency:c}=e,u=Number.parseFloat(l.groups.sw);e.spectralWidth.push(u/c[1])}}return e}function Hi(e,t){let{T1NUCLEUS:n,T2NUCLEUS:i,PAGE:r}=t;e.pulseSequence=t.EXPERIMENT||t[".PULSESEQUENCE"];let o=[],{dimension:s,isComplex:a}=e;if(s===2&&e.pulseSequence==="T1"){let u=a?2:1;for(let f=0;f<r.length;f+=u){let d=r[f].replace(/T1=/,"");o.push(Number(d))}t.vdlistValues=o}e.nucleus=s>1?[i,n]:i;let{phc0:l,phc1:c}=e;if(l&&c){let u=pe({phc0:l,phc1:c});e={...e,...u}}}var Yi={keepRecordsRegExp:/.*/,keepFiles:!0};async function ye(e,t={}){let n={spectra:[],molecules:[]},{converter:i={},selector:r={},logger:o}=t,s=We(e,{logger:o,...Zi(r)}),a=[];for(let c of s)a.push(Ye(c,{...Yi,...i}).then(u=>Ki(u,t)));let l=await Promise.allSettled(a);for(let c=0;c<l.length;c++){let u=l[c];if(u.status==="fulfilled"){let f=pe(u.value.info);n.spectra.push({...u.value,info:{...u.value.info,...f}})}else if(u.reason){let f=s[c].name;o?.warn(`Bruker data: ${f}, fails with: ${u.reason}`);continue}}return o&&o[n.spectra.length>0?"info":"debug"](`Loaded ${n.spectra.length} spectra from Bruker files`),Gi(n)}function Ki(e,t={}){let{keepSource:n=!1,logger:i}=t,r={...e.info,...e.meta},o=ge(r,{logger:i}),s={},{isFid:a}=o;if(Qi(e)){let g=e.minMax;for(let h in g){let p=g[h];p&&(p.z=_(p.z))}s.components=e.minMax}else o.dimension===1&&(s.components=e.spectra);let{source:l}=e,{expno:c,name:u,files:f}=l;r.vdlist&&(r.vdlistValues=me(r.vdlist));let d={dependentVariables:[s],meta:r,info:{...o,experimentNumber:c,name:u}};return f&&n&&(d.sourceSelector={files:f.map(g=>g.relativePath)}),eo(d,e),d}function Zi(e){let{general:t={},bruker:n={}}=e,{processingNumbers:i,experimentNumbers:r,...o}=n;return{...t,...o,processingNumbers:Kt(i),experimentNumbers:Kt(r)}}function Kt(e){if(e)return e.split(/[^\d]+/).filter(Boolean).map(t=>Number.parseInt(t,10))}function Qi(e){let{info:t}=e;return t.twoD}function eo(e,t){if(!("integrals"in t))return;let{integrals:n=[]}=t;e.integrals={values:n.map(i=>{let{from:r,to:o,integration:s}=i;return{from:r,to:o,integral:s,kind:"signal"}})}}var he=class{id="@zakodium/nmrium-core-plugins#BrukerLoaderPlugin";version=1;migrations=[];onReadProcess;constructor(){this.onReadProcess={onFiles:this.onReadProcessFiles}}onReadProcessFiles=(t,n)=>{let{sourceSelector:i,converter:r,keepSource:o,logger:s}=n??{};return ye(t,{converter:r?.bruker,selector:i,keepSource:o,logger:s})}};function Ze(){return new he}import{formatSpectra as ko}from"@zakodium/nmrium-core";import{createTree as Lo}from"jcampconverter";function Zt(e,t,n={}){let{selector:i={},keepSource:r=!1}=n;if(!r)return e;for(let o=0;o<e.spectra.length;o++){let s=e.spectra[o];s.sourceSelector={files:[t.relativePath],jcamp:{index:o,...i}}}return e}import{convert as to}from"jcampconverter";function Qe(e,t,n){let{dataType:i,children:r}=e,o=i==="LINK"&&r?r:[e];for(let s of o){if(s.dataType==="LINK"){Qe(s,t,n);continue}let a=to(s.jcamp,n);t.push(...a.flatten)}}function tn(e,t={}){let n=[],i=nn(e,t);for(let s of i?e:[])s.dataType==="LINK"?s.children=et(s.children,t):s=et([s],t)[0],n.push(s);let{name:r,logger:o}=t;return e.length===0&&o?.warn(`There is no data ${r?`in ${r}`:"in the JCAMP-DX"}`),n}function et(e=[],t={}){let{name:n,logger:i,tree:r=[],dataSelection:o="both"}=t,s=[];for(let u of e){let{dataType:f,dataClass:d}=u;if(f==="LINK")u.children=et(u.children,t);else if(r.some(g=>{let{dataClass:h=d,dataType:p=f}=g;return d===h&&f===p})){i?.warn(`Skipping ${d} and ${f} ${n?`in ${n}`:"in the JCAMP-DX"},
|
|
7
|
+
because it didn't match the import filters`);continue}s.push(u)}let a=[],l=s.some(en),c=s.some(Qt);for(let u of s){if(o!=="both"&&u.dataType!=="LINK"){if(en(u)&&(o==="ft"||o==="preferFT"&&c)){i?.warn(`Skipping raw data ${n?`in ${n}`:"in the JCAMP-DX"} because it didn't match the import filters`);continue}if(Qt(u)&&(o==="fid"||o==="preferFID"&&l)){i?.warn(`Skipping FFT data ${n?`in ${n}`:"in the JCAMP-DX"} because it didn't match the import filters`);continue}}a.push(u)}return a}function Qt(e){return e.dataType?.toUpperCase().includes("SPECTRUM")&&e.dataClass&&!e.dataClass.toUpperCase().includes("PEAK")}function en(e){return e.dataType?.toUpperCase().includes("FID")}function nn(e,t={}){let{logger:n,name:i=""}=t;for(let r of e){if(r.dataType==="LINK"&&nn(r.children,t))return!0;let{dataType:o=""}=r,s=o.toLowerCase();if(s.length>0){if(s.includes("spectrum")&&!s.includes("nmr"))return n?.warn(`File ${i} was ignored because it is a ${o}`),!1;if(s.includes("nmr"))return!0}}return!1}import{generateID as sn}from"@zakodium/nmrium-core";import{parseJcampCS as co}from"jcampconverter";import*as lo from"openchemlib";import{isMolfileNotEmpty as no}from"nmr-processing";import{Molecule as ro}from"openchemlib";async function rn(e,t={}){let n=await e.text(),i=V(n),r={molecules:i,spectra:[]};return i.length===0&&t.logger?.debug(`${e.name} is an empty molfile`),r}function V(e){let t=[];if(!no(e))return[];let i=ro.fromMolfile(e).toMolfile();return t.push({molfile:i}),t}import{isMolfileNotEmpty as oo}from"nmr-processing";import*as so from"openchemlib";import{getDiastereotopicAtomIDsFromMolfile as ao}from"openchemlib-utils";var io=new Set(["ndnmrspectrum","ndnmrfid","nmrspectrum","nmrfid"]);function be(e){let{dataType:t="",dataClass:n=""}=e,i=t.replaceAll(/\s/g,"").toLowerCase(),r=n.replaceAll(/\s/g,"").toLowerCase();return io.has(i)&&r!=="peaktable"}function on(e,t,n={}){let{spectra:i,info:r,meta:o}=e,s=i[0].data,a=[],l={x:"delta",y:"intensity",w:"width",m:"multiplicity",a:"atom"},{logger:c,name:u,spectraData:f}=n,{CROSSREFERENCE:d}=r,g=typeof d!="string"?d:d.split(/\r?\n/).map(D=>D.trim()).filter(Boolean),h=g.find(D=>D?.toLowerCase().includes("structure"));if(h===void 0)return c&&c.warn(`There is not a structure reference for ${u} file, assignment object could not be completed`),null;let p=Number.parseInt(h?.toLowerCase().replace(/_/,"").replace(/structure:\s*blockid\s*=\s*(?<blockId>.*)/,"$<blockId>"),10);if(Number.isNaN(p)||p<1)return c&&c.warn(`Structure block_id not found for ${u} file, assignment object could not be completed`),null;let m=f?.molecules?.find(D=>D.blockId===p)?.molfile??"";if(m===""){let D=t.find(A=>A.info.BLOCKID===p),{MOLFILE:P=""}=D?.meta||{};m=P}if(!oo(m))return c&&c.warn(`Empty molfile for ${u} file with structure block_id = ${p}, assignment object could not be completed`),null;let y=ao(so,m),F=fe({...r,...o},{},"");for(let D=0;D<s.x.length;D++){let P={};for(let A in s){let I=s[A][D];typeof I=="string"&&I.startsWith("<")&&I.endsWith(">")&&(I=I.slice(1,-1)),P[l[A]]=I}if("atom"in P){let A=y.map[P.atom-1];F.includes("1H")?A.nbHydrogens>0?(P.diaIDs=A.hydrogenOCLIDs,P.nbHydrogens=A.nbHydrogens):(P.diaIDs=[A.oclID],P.nbHydrogens=A.nbHydrogens):(P.diaIDs=[A.oclID],P.nbHydrogens=1)}a.push(P)}let x={};for(let D of a){let{delta:P,diaIDs:A}=D,I=`${P}_${A.join("_")}`;if(x[I])x[I].atoms.push(D.atom);else{let{atom:Dt,..._e}=D;x[I]={..._e,atoms:[D.atom]}}}let N=[];for(let D of g)D.toLowerCase().includes("spectrum")&&N.push(Number(D.toLowerCase().replace(/_/,"").replace(/.*:\s*blockid=(?<blockId>.*)/,"$<blockId>")));if(N.length===0){for(let D of t)if(be(D)){let{BLOCKID:P}=D.info;N.push(Number(P))}N.length>1&&(N=[],c&&c.warn(`There is not a spectral cross-reference for the peak assignment in the ${u} file`))}return{moleculeBlockID:p,spectraBlockIDs:N,assignments:Object.values(x),molecule:y.molecule}}function an(e,t,n,i){for(let r of e){let{meta:o,dataClass:s="",dataType:a="",info:l}=r,c=Number.parseInt(String(l.BLOCKID),10);o.MOLFILE?fo(String(o.MOLFILE),t,c):r.jcampCS&&po(r,t,c),mo(s,a)&&uo(t,r,e,i),be(r)&&n.push(r)}}function mo(e,t){return e?.toLowerCase().includes("assignments")&&t?.toLowerCase().includes("assignments")}function uo(e,t,n,i){let r=on(t,n,{spectraData:e,logger:i.logger,name:i.name});if(e.assignmentsByBlocks||(e.assignmentsByBlocks={}),r){let{spectraBlockIDs:o}=r;for(let s of o)e.assignmentsByBlocks[s]=r}}function po(e,t,n){t.molecules||(t.molecules=[]);let i=co(e,{OCL:lo}),r=V(i?.molfile||"");r.length>0&&t.molecules.push({id:sn(),blockId:n,...r[0]})}function fo(e,t,n){t.molecules||(t.molecules=[]);let i=V(String(e));t.molecules.push({id:sn(),blockId:n,...i[0]})}import{generateID as Dn}from"@zakodium/nmrium-core";import{matrixMinMaxZ as Fn,reimPhaseCorrection as Ao}from"ml-spectra-processing";import{xyAutoRangesPicking as Mo}from"nmr-processing";function X(e){return e.slice(0,Math.max(0,e.lastIndexOf(".")))}function H(e){e.sort((t,n)=>t.from-n.from);for(let t=0;t<e.length-1;t++)e[t].to>e[t+1].from&&(e[t].to=Math.max(e[t+1].to,e[t].to),e[t].signals=e[t].signals.concat(e[t+1].signals),e[t].integration+=e[t+1].integration,e.splice(t+1,1),t--);return e}import{splitPatterns as Fo}from"nmr-processing";import{xMaxValue as go}from"ml-spectra-processing";function Z(e){return e.trim().slice(1,-1).split(/,\s*/).map(t=>t.trim())}var yo={I:"id",X:"from",Y:"to",Hs:"delta",An:"integration",H:"nbAtoms",C:"multiplicity",N:"assignment","(J)":"js"},cn=["I","X","Y","Hs","An","H","C","N","(J)"];function ln(e){let t={headersFromParenthesis:[],headersFromComments:[],comments:[],data:[],multiplets:[]},n=e.split(/\r?\n/).filter(i=>i.trim()!=="");if(n.length===0)return t;if(n[0].startsWith("(")&&!n[0].match(/\d/)){let i=n.shift();t.headersFromParenthesis=Z(i)}return t.comments=n.filter(i=>i.startsWith("$$")).map(i=>i.replace(/^\$\$\s*/,"")),t.headersFromComments=bo(t.comments),t.data=n.filter(i=>!i.startsWith("$$")).map(Z),t.multiplets=ho(t),t}function ho(e,t={}){let{logger:n}=t,i=e.data[0].map((l,c)=>c).filter(l=>e.data.every(c=>Number.isNaN(c[l])||Number.isNaN(Number(c[l]))));if(n?.trace(`Parsing JCAMP-DX assignment: stringColumnIndexes: ${i.join(",")}`),i.length===0)return n?.warn("Parsing JCAMP-DX assignment: No string columns found. Skipping parsing of assignment."),[];let r=i[0],o;if(e.headersFromParenthesis.length>0&&e.headersFromParenthesis[r]==="C")o=e.headersFromParenthesis;else if(e.headersFromComments.length>0&&e.headersFromComments[r]==="C")o=e.headersFromComments;else if(cn[r]==="C")o=cn;else return n?.warn("No header found for multiplicity. Skipping parsing of assignment."),[];return go(e.data.map(l=>l.length))>o.length&&n?.warn("Some assignments are containing more values than headers"),e.data.map(l=>{let c={};for(let u=0;u<o.length;u++){let f=o[u];c[yo[f]||f]=l[u]}return c})}function bo(e){return e.map(t=>t.split(":")[0].trim()).filter(t=>t.length>0)}function mn(e,t={}){let{logger:n}=t,i=ln(e),r={multiplets:[],comments:i.comments};for(let o of i.multiplets){let{id:s,from:a,to:l,delta:c,integration:u,nbAtoms:f,multiplicity:d}=o,g={id:s,js:[],multiplicity:"",...Do({from:a,to:l,delta:c,integration:u,nbAtoms:f})};if(typeof o.js=="string"){let h=o.js.split(/\s+/).map(Number.parseFloat),p=0,b=Fo(d).map(F=>{let x=(F?.multiplicity||1)-1;return p+=x,{value:F.value,multiplicity:F?.multiplicity,js:h.slice(p-x,p)}}),m=b.reduce((F,x)=>F+(x.multiplicity?x.multiplicity-1:0),0);h.length!==m&&n?.warn(`The number of j values (${h.length}) is not equal to the sum of the multiplicities - 1 (${m})`);let y=[];for(let F of b){if(F.js.every(x=>x===F.js[0])){y.push(F);continue}if(F.multiplicity!==F.js.length+1){y.push(F);continue}for(let x=0;x<F.multiplicity-1;x++)y.push({value:"d",multiplicity:2,js:[F.js[x]]})}y.sort((F,x)=>x.js[0]-F.js[0]),g.js=y.map(F=>({coupling:F.js[0],multiplicity:F.value}))}typeof o.assignment=="string"&&(g.assignment=So(o.assignment)),typeof o.multiplicity=="string"&&(g.multiplicity=o.multiplicity),r.multiplets.push(g)}return r}function Do(e){let t={};for(let n in e){let i=e[n],r=typeof i=="number"?i:Number.parseFloat(i);Number.isNaN(r)||(t[n]=r)}return t}var xo={quot:'"',apos:"'",comma:",",amp:"&",lpar:"(",rpar:")",lt:"<",gt:">",colon:":",semi:";"};function So(e){return e.replaceAll(/&(\w+);/gi,(t,n)=>xo[n.toLowerCase()]||t)}function un(e){let t=e.split(/\r?\n/).filter(i=>i.trim()!==""),n=[];for(let i of t)if(i.startsWith("(")){let[r,o,s]=Z(i).map(Number.parseFloat);n.push({id:r,x:o,y:s})}return n}function pn(e,t={}){let n={};if(!e["OBSERVED MULTIPLETS"])return[];let i=mn(e["OBSERVED MULTIPLETS"],t);if(!i)return[];let{multiplets:r}=i;for(let o of r){let{id:s,from:a,to:l,integration:c=0,...u}=o;n[s]={from:a,to:l,integration:c,signals:[{id:s,...u}]}}if(e["OBSERVED MULTIPLETS PEAKS"]){let o=un(e["OBSERVED MULTIPLETS PEAKS"]),s={};for(let a of o){let{id:l,x:c,y:u}=a;s[l]||(s[l]=[]),s[l].push({x:c,y:u,width:.05})}for(let a in n)s[a]&&(n[a].signals[0].peaks=s[a])}return H(Object.values(n))}function fn(e,t){let i=[...e.getMolecularFormula().formula.matchAll(/(?<element>[A-Z][a-z]?)(?<count>\d*)/g)].map(o=>({element:o?.groups?.element,count:o?.groups?.count?Number(o.groups.count):1})),r=[...t.nucleus[0].matchAll(/[0-9]*(?<element>[A-Z][a-z]?)/g,"$element")][0].groups.element;return i.find(o=>o.element===r)?.count||100}function dn(e){let t={};return".PHASE0"in e&&(t.ph0=Number.parseFloat(e[".PHASE0"]),t.ph1=Number.parseFloat(e[".PHASE1"])),t}function tt(e){let{ph0:t,ph1:n}=e;return Number.isFinite(t)&&Number.isFinite(n)}import{generateID as gn}from"@zakodium/nmrium-core";function yn(e,t,n){for(let i=0;i<e.length;i++){if(t.includes(i))continue;let{delta:r,multiplicity:o="",diaIDs:s}=e[i],a=Number(r)-.01,l=Number(r)+.01;n.push({from:a,to:l,integration:1,id:gn(),signals:[{id:gn(),delta:r,multiplicity:o,diaIDs:s}]})}}import{linearSumAssignment as Po}from"linear-sum-assignment";import{xCostMatrix as No}from"ml-spectra-processing";function hn(e,t){let n=e.map(s=>s.delta),i=t.map(s=>s.delta),r=No(i,n,{fct:(s,a)=>Math.abs(s-a)}),{rowAssignments:o}=Po(r,{maximaze:!1});return Array.from(o)}function bn(e,t){let{assignments:n,ranges:i}=t;n?.sort((s,a)=>a.delta-s.delta);let r=[],o=[];for(let s of i){let a=0,{from:l,to:c}=s,u=[];for(let f=a;f<n.length;f++){let{delta:d}=n[f];d<=c&&d>=l?(u.push(n[f]),o.push(f)):d>c&&(a=f)}if(u.length>0){let f=s.signals,d=[],g=u.length>1&&f.length>1?hn(f,u):[0];for(let h=0;h<u.length;h++){let p=g[h],{delta:b,multiplicity:m,diaIDs:y}=u[h];p>-1?d.push({...f[p],diaIDs:y}):d.push({delta:b,multiplicity:m,diaIDs:y})}s.signals=d,r.push(s)}}yn(n,o,r),r.sort((s,a)=>s.from-a.from),e.ranges={values:H(r).map(s=>{let{integration:a,...l}=s;return l}),options:{sum:t.integrationSum,isSumConstant:!0,sumAuto:!0}},e.ranges.options.moleculeId=String(t.moleculeId)}function xn(e,t,n,i,r){let{logger:o}=r,s={components:Sn(e)?Eo(e,n.isFid):Ro(e)},{name:a=n.title||`jcamp_${Dn()}`}=r,l={dependentVariables:[s],meta:t,info:{...n,name:X(a)}};return Io(e)&&To(l,i,t,e,n,{logger:o}),l}function Sn(e){return"minMax"in e}function Io(e){return!Sn(e)}function Ro(e){return e.spectra.map(t=>{let n=_(t.data);return{...t,data:n}})}function Eo(e,t){let n={...e.minMax,z:_(e.minMax?.z)};return t?Oo(n):{rr:n}}function To(e,t,n,i,r,o){let{assignmentsByBlocks:s}=t,a=dn(n);tt(a)&&Co(e,a);let l=String(i.info.BLOCKID);if(s?.[l]){let{molecule:c,assignments:u,moleculeBlockID:f}=s[l],d=fn(c,r),g=_(i.spectra[0].data);if(g.x[0]>g.x[1])for(let m of i.spectra)m.data.x.reverse(),m.data.y.reverse();if(tt(a)&&i.spectra.length>1){let{re:m}=wo(i,a);g.y=m}let{x:h,y:p}=g,b=pn(n,o)??Mo({x:h,y:p},{peakPicking:{frequency:r.originFrequency},ranges:{frequency:r.originFrequency,integrationSum:d}});bn(e,{moleculeId:f,ranges:b,assignments:u,integrationSum:d})}}function Oo(e){let{z:t,...n}=e,i=[],r=[];for(let a=0;a<t.length;a+=2)i.push(t[a].slice()),r.push(t[a+1].slice());let o=Fn(i),s=Fn(r);return{re:{...n,z:i,minZ:o.min,maxZ:o.max},im:{...n,z:r,minZ:s.min,maxZ:s.max}}}function Co(e,t){let{ph0:n,ph1:i}=t;e.filters||(e.filters=[]),e.filters.push({id:Dn(),name:"phaseCorrection",value:{ph0:n,ph1:i,absolute:!1},enabled:!0})}function wo(e,t){let{ph0:n,ph1:i}=t,{re:r,im:o}=Ao({re:e.spectra[0].data.y,im:e.spectra[1].data.y},n*Math.PI/180,i*Math.PI/180);return{re:r,im:o}}function Pn(e,t,n){let{logger:i}=n,r=[];for(let o of e)if(o.spectra&&o.spectra.length>0||o.minMax){vo(o);let s={...o.info,...o.meta},a=ge(s,{logger:i});if(a.experiment==="wobble_curve")continue;r.push(xn(o,s,a,t,n))}return r}function vo(e){let t=e.meta["BRUKER FILE EXP"];if(!t)return;let i=(Array.isArray(t)?t:[t]).find(o=>o.slice(0,10).includes("vdlist"));if(!i)return;let r=i.split(`
|
|
8
|
+
`).slice(1);e.info.vdlistValues=me(r)}async function Fe(e,t={}){let n=await e.text(),i=Nn(n,{name:e.name,...t});return Zt(i,e,t)}function Nn(e,t={}){let n={spectra:[],molecules:[]},{name:i,converter:r={},selector:o={},logger:s}=t,{keepRecordsRegExp:a=/.*/}=r,l={keepSpectra:!0,noContour:!0,noTrimRegExp:/\$MOLFILE/,keepRecordsRegExp:a,logger:s},c=tn(Lo(e),{name:i,...o,logger:s});for(let u of c)qo(u,n,l,i);if(_o(n,o),n.spectra.length===0&&c.length>0){let u=n.molecules.length===0?" nor molecule":"";s?.warn(`No spectra${u} data was loaded from file ${i}`)}return ko(n)}function qo(e,t,n,i){let r=[],o=[],s={molecules:[]},{logger:a}=n,l={name:i,logger:a};Qe(e,o,n),an(o,s,r,l),t.spectra.push(...Pn(r,s,l)),t.molecules.push(...s.molecules)}function _o(e,t){t.index!==void 0&&(e.spectra=e.spectra.slice(t.index,t.index+1))}var De=class{id="@zakodium/nmrium-core-plugins#JCAMPDXLoaderPlugin";version=1;migrations=[];onReadProcess;constructor(){this.onReadProcess={supportedExtensions:["jcamp","jdx","dx"],onFile:this.onReadProcessFile.bind(this)}}onReadProcessFile(t,n={}){let{sourceSelector:i={},converter:r,keepSource:o,logger:s}=n;return s?.debug(`Reading JCAMP-DX file: ${t.name}`),Fe(t,{selector:this.getJCAMPDXSelector(i),converter:r?.jcamp,keepSource:o,logger:s})}getJCAMPDXSelector(t={}){let{jcamp:n={},general:i={}}=t,{dataSelection:r="both"}=i;return{...n,dataSelection:r}}};function nt(){return new De}function An(e){if(e===void 0)return{epoch:null,date:""};let t=e*1e3;return{epoch:t,date:new Date(t).toUTCString()}}var Mn={0:"bigEndian",1:"littleEndian"},In={0:"NONE",1:"GSX",2:"ALPHA",3:"ECLIPSE",4:"MASS_SPEC",5:"COMPILER",6:"OTHER_NMR",7:"UNKNOWN",8:"GEMINI",9:"UNITY",10:"ASPECT",11:"UX",12:"FELIX",13:"LAMBDA",14:"GE_1280",15:"GE_OMEGA",16:"CHEMAGNETICS",17:"CDFF",18:"GALACTIC",19:"TRIAD",20:"GENERIC_NMR",21:"GAMMA",22:"JCAMP_DX",23:"AMX",24:"DMX",25:"ECA",26:"ALICE",27:"NMR_PIPE",28:"SIMPSON"},Rn={0:"64Bit Float",1:"32Bit Float",2:"Reserved",3:"Reserved"},En={1:"One_D",2:"Two_D",3:"Three_D",4:"Four_D",5:"Five_D",6:"Six_D",7:"Seven_D",8:"Eight_D",9:"not for NMR data formats",10:"not for NMR data formats",11:"not for NMR data formats",12:"Small_Two_D",13:"Small_Three_D",14:"Small_Four_D"},Tn={0:"None",1:"Real",2:"TPPI",3:"Complex",4:"Real_Complex",5:"Envelope"},On={"-8":"Yotta","-6":"Exa","-7":"Zetta","-5":"Pecta","-4":"Tera","-3":"Giga","-2":"Mega","-1":"Kilo",0:"None",1:"Milli",2:"Micro",3:"Nano",4:"Pico",5:"Femto",6:"Atto",7:"Zepto"},Cn={Yotta:24,Exa:21,Zetta:18,Pecta:15,Tera:12,Giga:9,Mega:6,Kilo:3,None:0,Milli:-3,Micro:-6,Nano:-9,Pico:-12,Femto:-15,Atto:-18,Zepto:-21},wn={0:"None",1:"Abundance",2:"Ampere",3:"Candela",4:"Celsius",5:"Coulomb",6:"Degree",7:"Electronvolt",8:"Farad",9:"Sievert",10:"Gram",11:"Gray",12:"Henry",13:"Hertz",14:"Kelvin",15:"Joule",16:"Liter",17:"Lumen",18:"Lux",19:"Meter",20:"Mole",21:"Newton",22:"Ohm",23:"Pascal",24:"Percent",25:"Point",26:"Ppm",27:"Radian",28:"Second",29:"Siemens",30:"Steradian",31:"Tesla",32:"Volt",33:"Watt",34:"Weber",35:"Decibel",36:"Dalton",37:"Thompson",38:"Ugeneric",39:"LPercent ",40:"PPT",41:"PPB ",42:"Index"},rt={0:"Ranged",1:"Listed",2:"Sparse",3:"Listed"};function C(e,t){return e.paramArray.find(n=>n.name===t)}function vn(e,t){let n=e.paramArray.find(p=>p.name==="orders"),i=e.paramArray.find(p=>p.name==="factors"),r=e.paramArray.find(p=>p.name==="x_sweep"),o=e.paramArray.find(p=>p.name==="x_acq_time"),s=e.paramArray.find(p=>p.name==="x_points");if(!n||!i||!r||!o||!s){t?.error("There is not all parameters to calculate the number of point of digital filter");return}let a=n.value,l=Number.parseInt(a.slice(0,1),10),c=a.slice(1).length/l,u=0,f=new Int8Array(l),d=1,g=0;for(let p=0;p<l;p++)f[p]=Number.parseInt(i.value.slice(g,g+1),10),g+=1;for(let p=0;p<l;p++){let b=1;for(let m=p;m<l;m++)b*=f[m];u+=(Number.parseInt(a.slice(d,d+c),10)-1)/b,d+=c}return u/=2,u/r.value/o.value*(s.value-1)}function R(e,t){let n=C(e,t);if(n===void 0)return{magnitude:"NA",unit:"NA"};let i=n.unit[0],r=i.base,o=Cn[i.prefix];return{magnitude:n.value*10**o,unit:r}}function it(e){let t=e.readBytes(4),n=1990+(t[0]>>1),i=(t[0]<<3&8)+(t[1]>>5),r=t[2]&31;return{year:n,month:i,day:r}}function xe(e,t){let n=[];for(let i=0;i<t;i++){let r=e.readByte(),o=r>>4,s=On[o],a=r&15,l=e.readInt8(),c=wn[l];n.push({prefix:s,power:a,base:c})}return n}function B(e,t){let n=[];for(let i=0;i<t;i++){let r=e.readChar();r!=="\0"&&n.push(r)}return n.join("")}function ot(e,t){let n=[];for(let i=0;i<t;i++){let r=e.readChar();r!==" "&&n.push(r)}return n.join("")}function M(e,t,n){let i=[];for(let r=0;r<t;r++)switch(n){case"readUint32":i.push(e.readUint32());break;case"readFloat64":i.push(e.readFloat64());break;case"readFloat32":i.push(e.readFloat32());break;case"readUint8":i.push(e.readUint8());break;default:break}return i}function kn(e,t){let n=[];for(let i=0;i<t;i++)n.push(e.readBoolean());return n}function Ln(e,t,n){let i=1,r=0;for(let o of t.dataAxisType)o==="Real_Complex"&&r===0&&(i+=1,r+=1),o==="Complex"&&(i*=2);if(t.dataType!=="32Bit Float"&&t.dataType!=="64Bit Float"){n?.error("Only 32Bit Float and 64Bit Float data types are implemented yet");return}if(t.dataFormat==="One_D"){if(i!==1&&i!==2){n?.error("One_D data must have one or two data sections");return}return Bo(e,t,i)}else if(t.dataFormat==="Two_D"){if(i===2)return Uo(e,t);if(i===4)return $o(e,t);n?.error("Two_D data must have two or four data sections");return}else{n?.error("Only One_D and two_D data formats are implemented yet");return}}function Bo(e,t,n){return n===1?{re:st(e,t)}:{re:st(e,t),im:st(e,t)}}function st(e,t){return t.dataType==="32Bit Float"?M(e,t.dataPoints[0],"readFloat32"):M(e,t.dataPoints[0],"readFloat64")}var v=32;function Uo(e,t){let n=t.dataPoints[0],r=t.dataPoints[1]/v,o=n/v;return{re:G(e,t,r,o),im:G(e,t,r,o)}}function $o(e,t){let n=t.dataPoints[0],r=t.dataPoints[1]/v,o=n/v;return{re:{re:G(e,t,r,o),im:G(e,t,r,o)},im:{re:G(e,t,r,o),im:G(e,t,r,o)}}}function G(e,t,n,i){let r=[];for(let o=0;o<n;o++){let s=[];for(let a=0;a<i;a++)for(let l=0;l<v;l++)a===0?t.dataType==="32Bit Float"?s[l]=M(e,v,"readFloat32"):t.dataType==="64Bit Float"&&(s[l]=M(e,v,"readFloat64")):t.dataType==="32Bit Float"?s[l]=s[l].concat(M(e,v,"readFloat32")):t.dataType==="64Bit Float"&&(s[l]=s[l].concat(M(e,v,"readFloat64")));r=r.concat(s)}return r}function qn(e){let t=e.readChars(8),n=e.readInt8(),i=Mn[n],r=e.readUint8(),o=e.readUint16(),s=e.readUint8(),a=e.readByte().toString(2).split("").map(T=>!!Number(T)),l=e.readByte(),c=l>>6,u=Rn[c],f=l&63,d=En[f],g=e.readInt8(),h=In[g],p=M(e,8,"readUint8"),b=M(e,8,"readUint8").map(T=>Tn[T]),m=xe(e,8),y=B(e,124),F=[];for(let T of M(e,4,"readUint8")){let ee=T>>4,je=T&15;F.push(rt[ee],rt[je])}let x=M(e,8,"readUint32"),N=M(e,8,"readUint32"),D=M(e,8,"readUint32"),P=M(e,8,"readFloat64"),A=M(e,8,"readFloat64"),I=it(e),Dt=it(e),_e=B(e,16),Er=B(e,128),Tr=B(e,128),Or=B(e,128),xt=[];for(let T=0;T<8;T++)xt.push(B(e,32));let Cr=M(e,8,"readFloat64"),wr=M(e,8,"readFloat64"),vr=kn(e,8);e.skip(3);let kr=!!(e.readByte()>>7),Lr=e.readUint32(),qr=e.readUint32(),_r=e.readUint32(),jr=e.readUint32(),Br=M(e,8,"readUint32"),Ur=M(e,8,"readUint32"),$r=e.readUint32(),zr=e.readUint32()<<32|e.readUint32(),Jr=e.readUint32()<<32|e.readUint32(),Wr=e.readUint32(),Vr=e.readUint32()<<32|e.readUint32(),Xr=e.readUint32(),Hr=e.readUint32()<<32|e.readUint32(),Gr=M(e,8,"readUint8"),St=[];for(let T=0;T<2;T++){let ee=[],je=e.readInt16();for(let Pt=0;Pt<5;Pt++)ee.push(e.readInt16());St.push({scaler:je,unit:ee})}return{fileIdentifier:t,endian:i,majorVersion:r,minorVersion:o,dataDimensionNumber:s,dataDimensionExist:a,dataType:u,dataFormat:d,dataInstrument:h,translate:p,dataAxisType:b,dataUnits:m,title:y,dataAxisRanged:F,dataPoints:x,dataOffsetStart:N,dataOffsetStop:D,dataAxisStart:P,dataAxisStop:A,creationTime:I,revisionTime:Dt,nodeName:_e,site:Er,author:Tr,comment:Or,dataAxisTitles:xt,baseFreq:Cr,zeroPoint:wr,reversed:vr,annotationOK:kr,historyUsed:Lr,historyLength:qr,paramStart:_r,paramLength:jr,ListStart:Br,ListLength:Ur,dataStart:$r,dataLength:zr,contextStart:Jr,contextLength:Wr,annoteStart:Vr,annoteLength:Xr,totalSize:Hr,unitLocation:Gr,compoundUnit:St}}var zo={0:"String",1:"Integer",2:"Float",3:"Complex",4:"Infinity"};function _n(e){let t=e.readUint32(),n=e.readUint32(),i=e.readUint32(),r=e.readUint32(),o=[];for(let s=0;s<i+1;s++){e.skip(4);let a=e.readInt16(),l=xe(e,5);e.skip(16);let c=e.readInt32(),u=zo[c];e.seek(e.offset-20);let f;switch(u){case"String":f=ot(e,16);break;case"Integer":f=e.readInt32(),e.skip(12);break;case"Float":f=e.readFloat64(),e.skip(8);break;case"Complex":f={Real:e.readFloat64(),Imag:e.readFloat64()};break;case"Infinity":f=e.readInt32(),e.skip(12);break;default:e.skip(16);break}e.skip(4);let d=ot(e,28);o.push({name:d.toLowerCase(),scaler:a,unit:l,value:f,valueType:u})}return{parameterSize:t,lowIndex:n,highIndex:i,totalSize:r,paramArray:o}}function jn(e,t){let n=new O(e);n.setBigEndian();let i=qn(n);i.endian==="littleEndian"&&n.setLittleEndian(),n.seek(i.paramStart);let r=_n(n);n.seek(i.dataStart);let o=Ln(n,i,t),s=[],a=[],l=[],c=[],u=[],f=[],d=[],g=[],h=[],p=[];if(i.dataFormat==="One_D"||i.dataFormat==="Two_D"){let m=An(C(r,"actual_start_time")?.value);m.date&&(a.push(m.date),l.push(m.epoch)),s.push(C(r,"x_domain")?.value),c.push(R(r,"x_acq_time")),u.push(R(r,"x_sweep")),f.push(R(r,"x_sweep_clipped")),d.push(R(r,"x_resolution")),g.push(R(r,"x_freq")),h.push(R(r,"x_offset")),p.push(i.dataUnits[0].base)}return i.dataFormat==="Two_D"&&(s.push(C(r,"y_domain")?.value),c.push(R(r,"y_acq_time")),u.push(R(r,"y_sweep")),d.push(R(r,"y_resolution")),g.push(R(r,"y_freq")),h.push(R(r,"y_offset")),p.push(i.dataUnits[1].base)),{info:{sampleName:C(r,"sample_id")?.value,creationTime:i.creationTime,revisionTime:i.revisionTime,author:i.author,comment:i.comment,solvent:C(r,"solvent")?.value,temperature:R(r,"temp_get"),probeName:C(r,"probe_id")?.value,fieldStrength:R(r,"field_strength"),experiment:C(r,"experiment")?.value,dimension:i.dataDimensionNumber,nucleus:s,date:a,epoch:l,pulseStrength90:R(r,"x90"),numberOfScans:C(r,"scans")?.value,relaxationTime:R(r,"relaxation_delay"),dataPoints:i.dataPoints.slice(0,i.dataDimensionNumber),dataOffsetStart:i.dataOffsetStart,dataOffsetStop:i.dataOffsetStop,dataUnits:p,dataSections:o?Object.keys(o):void 0,originFrequency:g,frequencyOffset:h,acquisitionTime:c,spectralWidth:u,spectralWidthClipped:f,dataAxisStart:i.dataAxisStart,dataAxisStop:i.dataAxisStop,resolution:d,decimationRate:C(r,"decimation_rate")?.value,paramList:JSON.stringify(r.paramArray.map(m=>m.name)),digitalFilter:vn(r,t)},headers:i,parameters:r,data:o}}import{formatSpectra as Xo}from"@zakodium/nmrium-core";import{getGyromagneticRatio as Ho}from"gyromagnetic-ratio";import{isAnyArray as Go}from"is-any-array";import Yo from"lodash.merge";import{normalizeNucleus as Ko}from"nmr-processing";import{isAnyArray as Y}from"is-any-array";var Bn={0:"uint8",1:"uint16",2:"uint32",3:"uint64",4:"int8",5:"int16",6:"int32",7:"int64",8:"float32",9:"float64",10:"complex64",11:"complex128"},Un={0:"scalar",1:"vector",2:"matrix",3:"symetricMatrix",4:"pixel"};function $n(e,t,n={}){let{quantityType:i=0,encoding:r="none",name:o="",unit:s="",quantityName:a="",sparseSampling:l={},from:c=[0],to:u=[-1]}=n;if(Y(e))throw new Error("JEOL with an array of data is not yet supported");if(!("re"in e&&"im"in e))throw new Error("Only re/im data is supported");let f=ct(e,c,u),{componentLabels:d=f.componentLabels}=n;return{type:"internal",quantityType:Un[i],numericType:Bn[t],encoding:r,name:o,unit:s,quantityName:a,componentLabels:d,sparseSampling:l,description:n.description||"",application:n.application||"",components:f.components,dataLength:f.dataLength}}function Jo(e){return Y(e.re)&&Y(e.im)}function Wo(e){return!Y(e.re[0])}function ct(e,t,n){let i=[],r=[],o=[];if(Jo(e))if(Wo(e)){i[0]=at(t[0],n[0],e.re.length);let s=new Float64Array(i[0]);for(let a=0;a<i[0];a+=2){let l=a+t[0]*2;s[a]=e.re[l/2],s[a+1]=e.im[l/2]}o.push(s),r.push("complex")}else if(Y(e.re[0])){i[0]=Vo(t[1],n[1],e.re.length),i[1]=at(t[0],n[0],e.re[0].length);for(let s=0;s<i[0];s++){let a=new Float64Array(i[1]);for(let l=0;l<i[1];l+=2){let c=l+t[0]*2;a[l]=e.re[s][c/2],a[l+1]=e.im[s][c/2]}o.push(a)}}else throw new Error("check your object");else if(Y(e.re.re)){i[0]=at(t[1],n[1],e.re.re.length);let s=ct(e.re,t,n).components,a=ct(e.im,t,n).components;for(let l=0;l<i[0]/2;l++)o.push(s[l],a[l])}else throw new Error("check the dimension or the type of data in your array");return{dataLength:i,componentLabels:r,components:o}}function Vo(e,t,n){return t-e+1<n?t-e+1:n}function at(e,t,n){return t-e+1<n?(t-e+1)*2:n*2}async function Jn(e,t={}){let n=await e.arrayBuffer(),{name:i=X(e.name),keepSource:r=!1}=t,o={spectra:[],molecules:[]},a=es(n)[0],{metadata:l,...c}=a.description,u=0,f=c.dimension===1?"1d":"2d",d="NMR SPECTRUM",g=c.dimension===1?c.nucleus[0]:c.nucleus,h=c.spectralWidthClipped[0],p;a.dependentVariables&&(c.dimension===1?p=Zo(a):c.dimension===2&&(p=Qo(a)));for(let m in c)Array.isArray(c[m])&&c[m].length===1&&(c[m]=c[m][0]);let b={data:p,info:{...c,acquisitionMode:u,experiment:f,type:d,nucleus:g,spectralWidthClipped:h,name:i},meta:l};return r&&(b.sourceSelector={files:[e.relativePath]}),o.spectra=[b],Xo(o)}function Zo(e){let t=e.dimensions[0],n=e.dependentVariables,i=t.quantityName,r=t.count,o=t.increment.magnitude,s=t.originOffset.magnitude,a=t.coordinatesOffset.magnitude,l=n[0].components[0],c=new Float64Array(r),u=new Float64Array(r);for(let p=l.length-1,b=0;p>0;p-=2)c[b]=l[p-1],u[b++]=l[p];let f={},[d,g]=[0,0];switch(i){case"frequency":g=0+a/s*1e6,d=o/s*1e6,f.re=c,f.im=u;break;case"time":g=s,d=o,f.re=c.reverse(),f.im=u.reverse().map(p=>-p);break;default:break}let h=[];for(let p=0;p<r;p++)h.push(g+p*d);return f.x=h,f}function Qo(e){let t=e.dimensions,n=e.dependentVariables,i=t[0].quantityName,r=[],o=[],s=Number.MIN_SAFE_INTEGER,a=Number.MAX_SAFE_INTEGER,l=Number.MAX_SAFE_INTEGER,c=Number.MIN_SAFE_INTEGER;for(let d of n[0].components){let g=new Float64Array(d.length/2),h=new Float64Array(d.length/2);for(let p=d.length-1,b=0;p>0;p-=2){let m=d[p-1],y=d[p];m>s&&(s=m),m<a&&(a=m),y>c&&(c=y),y<l&&(l=y),g[b]=m,h[b++]=y}if(i==="frequency")r.push(g),o.push(h);else{let p=g.length,b=new Float64Array(h.length);for(let m=0,y=p-1;m<p;m++)b[m]=-h[y--];r.push(g.reverse()),o.push(b)}}let u={re:{z:r,minZ:a,maxZ:s},im:{z:o,minZ:l,maxZ:c}},f=["X","Y"];for(let d=0;d<f.length;d++){let g=t[d].count,h=t[d].increment.magnitude,p=t[d].originOffset.magnitude,b=t[d].coordinatesOffset.magnitude,m=f[d];for(let y of["re","im"])i==="frequency"?(u[y][`min${m}`]=0+b/p*1e6,u[y][`max${m}`]=g*(h/p)*1e6):(u[y][`min${m}`]=p,u[y][`max${m}`]=g*h)}return u}function es(e){let t=jn(e),n=t.info,i=t.headers,{paramArray:r,...o}=t.parameters,{dimension:s}=n,a={};for(let m of r){let{name:y,value:F}=m;a[y]=Wn(F,s)}let l=t.data,c={};c.title=`title: ${i.title} / comment: ${i.comment} / author:${i.author} / site: ${i.site}`,c.nucleus=n.nucleus.map(Ko),c.sampleName=n.sampleName,c.date=n.date,c.epoch=n.epoch,c.localeDate=new Date(n.epoch[0]).toLocaleString(),c.author=n.author,c.solvent=n.solvent,c.temperature=n.temperature.magnitude,c.probeName=n.probeName||"",c.fieldStrength=n.fieldStrength.magnitude;let u=c.nucleus.map(Ho);c.baseFrequency=u.map(m=>n.fieldStrength.magnitude*m/(2*Math.PI*1e6)),c.pulseSequence=n.experiment,c.temperature=n.temperature?.unit?.toLowerCase()==="celsius"?273.15+n.temperature.magnitude:n.temperature.magnitude,c.digitalFilter=n.digitalFilter,c.pulseStrength90=1/(4*n.pulseStrength90.magnitude),c.numberOfScans=n.numberOfScans,c.relaxationTime=n.relaxationTime.magnitude,c.isComplex=n.dataSections?n.dataSections.includes("im"):!1,c.isFid=n.dataUnits[0]==="Second",c.isFt=n.dataUnits[0]==="Ppm",c.dimension=n.dimension,c.originFrequency=n.originFrequency.map(m=>m.magnitude/1e6).slice(0,s),c.numberOfPoints=n.dataPoints.slice(0,1),c.frequencyOffset=n.frequencyOffset.map((m,y)=>m.magnitude*c.baseFrequency[y]).slice(0,s),c.acquisitionTime=n.acquisitionTime.map(m=>m.magnitude).slice(0,s),c.spectralWidth=n.spectralWidth.map((m,y)=>m.magnitude/n.originFrequency[y].magnitude*1e6).slice(0,s),c.spectralWidthClipped=n.spectralWidthClipped.map((m,y)=>m.magnitude/c.baseFrequency[y]*1e6).slice(0,s);let f=[],d={},g;for(let m=0;m<n.dimension;m++){if(g={magnitude:n.acquisitionTime[m].magnitude/(n.dataPoints[m]-1),unit:"s"},n.dataUnits[m]==="Second")d.quantityName="time",d.originOffset={magnitude:0,unit:"s"},m===0?d.coordinatesOffset={magnitude:n.digitalFilter*g.magnitude,unit:"s"}:d.coordinatesOffset={magnitude:0,unit:"s"},d.reciprocal={originOffset:{magnitude:n.originFrequency[m].magnitude,unit:"Hz"},quantityName:"frequency",coordinatesOffset:{magnitude:n.frequencyOffset[m].magnitude*n.originFrequency[m].magnitude/1e6,unit:"Hz"}};else if(n.dataUnits[m]==="Ppm"){d.quantityName="frequency";let y=n.originFrequency[m].magnitude;d.originOffset={magnitude:y,unit:"Hz"};let F=n.dataOffsetStart[m],N=n.dataOffsetStop[m]-F+1;g={magnitude:ts(n,m)/(N-1),unit:"Hz"};let A=n.dataAxisStop[m]*y/1e6;d.coordinatesOffset={magnitude:A,unit:"Hz"},N!==n.dataPoints[m]&&(n.dataPoints[m]=N)}m===0?d.description="direct dimension":d.description="indirect dimension",f.push({label:String(i.dataAxisTitles[m]),count:Number(n.dataPoints[m]),increment:g,type:"linear",description:String(d.description)||"",application:d.application||{},coordinatesOffset:d.coordinatesOffset||0,originOffset:d.originOffset||0,quantityName:String(d.quantityName)||"",reciprocal:d.reciprocal||{},period:d.period||0,complexFFT:d.complexFFT||!1})}let h=[];h.push($n(l,11,{unit:"none",quantityName:"relative intensity",from:n.dataOffsetStart,to:n.dataOffsetStop}));let p={...c};return delete p.paramList,p.metadata={...zn(i,s),...zn(o,s),...Yo({},a)},[{timeStamp:Date.now(),description:p,dimensions:f,dependentVariables:h}]}function ts(e,t){let{spectralWidth:n,spectralWidthClipped:i}=e;return i[t].magnitude!=="NA"?i[t].magnitude:n[t].magnitude}function zn(e,t){let n={};for(let i in e)n[i]=Wn(e[i],t);return n}function Wn(e,t){return Go(e)?t>1?e.slice(0,t):e[0]:e}var Se=class{id="@zakodium/nmrium-core-plugins#JEOLLoaderPlugin";version=1;migrations=[];onReadProcess;constructor(){this.onReadProcess={supportedExtensions:["jdf"],onFile:this.onReadProcessFile.bind(this)}}onReadProcessFile(t,n={}){let{logger:i,keepSource:r}=n;return i?.debug(`Reading JEOL file: ${t.name}`),Jn(t,{name:t.name,keepSource:r,logger:i})}};function lt(){return new Se}var Pe=class{id="@zakodium/nmrium-core-plugins#MolfileLoaderPlugin";version=1;migrations=[];onReadProcess;constructor(){this.onReadProcess={supportedExtensions:["mol"],onFile:this.onReadProcessFile.bind(this)}}onReadProcessFile(t,n={}){let{logger:i}=n;return i?.debug(`Reading molfile file: ${t.name}`),rn(t,{logger:i})}};function mt(){return new Pe}import{FileCollection as qu}from"file-collection";import{Molecule as sr}from"openchemlib";import{getShortestPaths as ns}from"openchemlib-utils";function Vn(e,t){let{molecule:n,map:i}=t;n.addImplicitHydrogens();let r=ns(n,{toLabel:"H",maxLength:1});for(let s in e){let a=e[s],l=a.atoms;if(l.length!==0){if(a.position=[],l[0].toLowerCase().includes("h")){let c=Number(l[0].toLowerCase().replace("h",""))-1;c=i.indexOf(c);let u=r[c].find(f=>f&&f.length>1);a.position=r[u[0]].filter(f=>f&&f.length>1).map(f=>f.at(-1))}else if(l[0].toLowerCase().match(/\w/s))for(let c of l){let u=i.indexOf(Number(c)-1);a.position.push(u)}}}let o=n.getDiastereotopicAtomIDs();for(let s in e){let a=[];if("position"in e[s])for(let l of e[s].position)a.includes(o[l])||a.push(o[l]);e[s].diaIDs=a}return e}import{FileCollection as rs}from"file-collection";async function Xn(e,t){let{fileCollection:n,root:i}=t,r=e.data.filter(s=>s.value.spectrum_location),o=[];for(let s of r){if(!s){new Error(`There is not spectrum for ${e}`);return}let a=s.value.spectrum_location;if(a.match(/file:/s)){let l=i+a.replace(/file:[./]*/s,""),c=l.match(/[ser|fid]/s)?/([.*/]*\w+\/[0-9]+\/).*/:/(.*\w+\/[0-9]+\/)pdata\/.*/,u=l.replace(c,"$1"),f=l.replace(/.*\/[0-9]+\/pdata\/([0-9]+)\/.*/,"$1"),d=[];for(let g of n){if(g.relativePath.match("pdata")&&f!==g.relativePath.replace(/.*\/[0-9]+\/pdata\/([0-9]+)\/.*/,"$1"))continue;let h=g.relativePath.replace(/([.*/]*\w+\/[0-9]+\/).*/,"$1");u!==h&&!["ser","fid"].some(p=>l===`${h}${p}`)||d.push(g)}o.push({type:"brukerFiles",fileCollection:await rs.fromSource({entries:d})})}else a.match("http")&&o.push({type:"url",value:a})}return o}import{FileCollection as is}from"file-collection";async function Hn(e,t){let{fileCollection:n,root:i}=t,r=e.data.find(l=>l.value.jcamp_location);if(!r){new Error(`There is not spectrum for ${e}`);return}let o=r.value.jcamp_location,s=i+o.replace(/file:/s,""),a=n.files.find(l=>l.relativePath===s);if(!a){new Error(`There is not jcamp with path: ${s}`);return}return[{name:s,type:"jcamp",fileCollection:await is.fromSource({entries:[a]})}]}function Gn(e={}){let t={};for(let n of e.data||[]){let{label:i,atoms:r,shift:o}=n.value;t[i]={shift:o,atoms:r}}return t}function Yn(e){let t=e.match(/([0-9])\w_/s)?.[1];if(t==="1")return e.slice(3).replaceAll(/(?<nucleus>[0-9]+\w+)#\w+/g,"$<nucleus>");if(t==="2"){let n=[],i=e.slice(12).split("_");for(let r=0;r<i.length;r+=2)n.push(i[r].replaceAll(/(?<nucleus>[0-9]+\w+)#\w+/g,"$<nucleus>"))}return[]}var os=["delta","nbAtoms","multiplicity","jCoupling"];function Kn(e,t){let n={};for(let s of os){let a=e[s];a&&(n[s]=a)}let{nbAtoms:i,integration:r}=e;if(n.integration=r?Number(r):i?Number(i):null,e.assignment)for(let s of e.assignment){let a=t[s];n.diaIDs||(n.diaIDs=[]),a?.diaIDs&&n.diaIDs.push(...a.diaIDs)}let o=!1;if(n.jCoupling&&(o=n.jCoupling.some(s=>Object.keys(s).includes("label"))),o){for(let s of n.jCoupling)if(s.label){let a=t[s.label];a?.diaIDs&&(s.diaIDs=a.diaIDs)}}return n.delta&&(n.delta=Number.parseFloat(n.delta)),n}var ss=["intensity","volume","activeCoupling"],as={x:["f1Width","f1Coupling"],y:["f2Width","f2Coupling"]};function Zn(e,t){let n={};for(let i of ss)e[i]&&(n[i]=e[i]);for(let i in e.delta){n[i]||(n[i]={});let r=e.delta[i];for(let o of r)n[i].diaIDs||(n[i].diaIDs=[]),t[o]?(n[i].diaIDs.push(...t[o].diaIDs),n[i].delta=Number.parseFloat(t[o].shift)):n[i].delta=Number.parseFloat(o);for(let o of as[i])if(e[o]){let s=o.toLowerCase().replace(/f\w(\w+)/,"$1");n[i][s]=e[o]}}return n}async function Qn(e,t){let{moleculeAndMap:n}=t,i={molecules:[{molfile:n.molecule.toMolfile()}],spectra:[]},r=i.spectra,o=i.molecules;e.SMILES?.data.length>0&&(o[0].smiles=e.SMILES.data[0].value);let s=Gn(e.ASSIGNMENT);s=Vn(s,n);for(let a in e){let l=a.toLowerCase();if(!l.match(/[1|2]d_/s))continue;let c=e[a].data.find(m=>m.value.larmor),u=e[a].data.find(m=>m.value.pulseprogram),f=Yn(a),d=l.replace(/([1|2]d)_.*/,"$1"),g=d==="2d"?Zn:Kn,h={source:{jcampURL:null},nucleus:f,frequency:c?.value.larmor,experiment:u?u.value.pulseprogram.trim():d,headComment:e[a].headComment},p=e[a].data.filter(m=>m.value.delta);h.signals=p.map(m=>{let y=g(m.value,s);return y.comment=m.comment,y});let b=await cs(e[a],t);if(!b.jcamp&&!b.bruker)r.push(h);else for(let m in b)b[m]&&r.push({...h,source:{...h.source,file:b[m]}})}return i}async function cs(e,t){return{jcamp:await Hn(e,t),bruker:await Xn(e,t)}}function Ne(e,t={}){let{include:n,exclude:i,filter:r,modifiers:o={},forEach:s={},dynamicTyping:a=!0,mixedEOL:l=!1}=t;if(typeof e!="string")throw new TypeError('Parameter "sdf" must be a string');let c=`
|
|
9
|
+
`;if(l)e=e.replaceAll(`\r
|
|
10
|
+
`,`
|
|
11
|
+
`),e=e.replaceAll("\r",`
|
|
12
|
+
`);else{let h=new Set(e.slice(0,1e3));h.has(`\r
|
|
13
|
+
`)?c=`\r
|
|
14
|
+
`:h.has("\r")&&(c="\r")}let u=e.split(new RegExp(`${c}\\$\\$\\$\\$.*${c}`)),f=[],d={},g=Date.now();for(let h of u){let p=h.split(`${c}>`);if(p.length>0&&p[0].length>5){let b={molfile:p[0]+c},m=[];for(let y=1;y<p.length;y++){let F=p[y].split(c),x=F[0].indexOf("<"),N=F[0].indexOf(">"),D=F[0].slice(x+1,N);if(m.push(D),d[D]||(d[D]={label:D,counter:0,nbLines:"",isNumeric:a,keep:!1},!i?.includes(D)&&(!n||n.includes(D))&&(d[D].keep=!0,o[D]&&(d[D].modifier=o[D]),s[D]&&(d[D].forEach=s[D]))),d[D].keep){for(let P=1;P<F.length-1;P++)b[D]?b[D]+=c+F[P]:b[D]=F[P];if(d[D].modifier){let P=d[D].modifier(b[D]);P==null?delete b[D]:b[D]=P}d[D].isNumeric&&(!Number.isFinite(+b[D])||b[D].match(/^0[0-9]/))&&(d[D].isNumeric=!1)}}if(!r||r(b)){f.push(b);for(let y of m)d[y].counter++}}}for(let h in d){let p=d[h];if(p.isNumeric){p.minValue=1/0,p.maxValue=-1/0;for(let b of f)if(b[h]){let m=Number.parseFloat(b[h]);b[h]=m,m>p.maxValue&&(p.maxValue=m),m<p.minValue&&(p.minValue=m)}}}for(let h in d)d[h].always=d[h].counter===f.length;return{time:Date.now()-g,molecules:f,labels:Object.keys(d),statistics:Object.values(d)}}function ut(e){let t={};for(let{key:n,value:i}of e)t[n]=i;return t}function Ae(e){let t=[];e=e.replaceAll(/,([0-9])/g,":$1");for(let n of e.split(":")){let i,r="",o=n.indexOf("(");o===-1?(i=Number(n),t.push({coupling:i})):(i=Number(n.slice(0,o)),r=n.slice(o+1,-1),t.push({coupling:i,label:r}))}return t}function er(e){let t={};e=e.replaceAll(" ",""),e=e.replaceAll(/[l=] /g,""),e=e.replaceAll(/,(\w=)/g,":$1");let n=e.split(":");for(let[i,r]of n.entries()){let o=r.toLowerCase(),s=o.replace(/^.*=/,""),a=o.replace(/[=].*/,"");Number.parseFloat(a)&&i===0?t.delta=s:t[ls(a)]=ms(s,a)}return t}function ls(e){switch(e){case"j":return"jCoupling";case"s":return"multiplicity";case"l":return"assignment";case"n":return"nbAtoms";case"e":case"i":return"integration";default:return""}}function ms(e,t){switch(t){case"l":return us(e);case"j":return Ae(e);default:return e}}function us(e){return e.replaceAll(/\s*/g,"").split(",")}var ps=["y","x"];function tr(e){e=e.replaceAll(" ",""),e=e.replaceAll(/[l=] /g,""),e=e.replaceAll(/,(\w+=)/g,":$1");let t=e.split(":"),n=fs(t[0]);for(let i=1;i<t.length;i++){let{value:r,key:o}=nr(t[i]);n[gs(o)]=ds(r,o)}return n}function fs(e){let{value:t}=nr(e),n={delta:{}},i=t.split("/");for(let r=0;r<i.length;r++){let o=i[r].replaceAll(/[(|)]/g,"").split(",");n.delta[ps[r]]=Array.isArray(o)?o:[o]}return n}function nr(e){let t=e.toLowerCase();return{value:t.replace(/^.*=/,""),key:t.replace(/[=].*/,"")}}function ds(e,t){switch(t){case"ja":case"j1":case"j2":return Ae(e);default:return e}}function gs(e){switch(e){case"ja":return"activeCoupling";case"j1":return"f1Coupling";case"j2":return"f2Coupling";case"i":return"intensity";case"s":return"volume";case"w1":return"f1Width";case"w2":return"f2Width";default:return e}}function ir(e,t){let n=ys(t),i=e.match(/[=]/g);return!i&&!e.match(",")?t.toLowerCase().match(/2d/)?n(e):e:t.toLowerCase().match(/[1|2]d/)&&i&&!e.match(",")?or(e):n(e)}function ys(e){let t=e.toLowerCase();switch(t.match(/1d/)&&(t="1d"),t.match(/2d/)&&(t="2d"),t){case"id":return or;case"1d":return er;case"2d":return tr;case"assignment":case"signals":return rr;case"j":return rr;case"smiles":case"inchi":case"version":case"solvent":case"temperature":case"level":default:return n=>n}}function or(e){let t=e.replace(/^.*=/,""),n=e.replace(/[=].*/,"").toLowerCase();return ut([{key:n,value:t}])}function rr(e){let t=e.replaceAll(" ","").split(",");return ut([{key:"label",value:t[0].toLowerCase()},{key:"shift",value:t.slice(1,2)},{key:"atoms",value:t.slice(2)}])}async function pt(e){let t=[];for(let n of e.files){let i=n.relativePath.split("/");if(/^[^.].+sdf|nmredata$/.exec(n.name)){let r=await n.text();if(!r.match("NMREDATA"))continue;let o=Ne(r,{mixedEOL:!0}),s=i.slice(0,-1).join("/");t.push({...o,filename:n.name,root:s!==""?`${s}/`:""})}}return t}function ar(e){let{sdf:t,fileCollection:n}=e,{molecule:i}=e,r=ft(t);i??=sr.fromMolfile(r.molecules[0].molfile),i.addImplicitHydrogens();let o=sr.fromMolfileWithAtomMap(i.toMolfile()),s=hs(r);return Qn(s,{moleculeAndMap:o,root:r.root,fileCollection:n})}function hs(e){let t=ft(e),n={name:t.filename},i=bs(t);for(let r of Object.keys(i)){n[r]||(n[r]={data:[]});let o=n[r],s=i[r].split(`
|
|
15
|
+
`);for(let a of s){let l=a.replaceAll(/;.*/g,"").replaceAll("\r",""),c=a.match(";")?a.replaceAll(/.*;+(.*)/g,"$1"):"";if(l.length===0){o.headComment||(o.headComment=[]),o.headComment.push(c);continue}let u=ir(l,r);o.data.push({comment:c,value:u})}}return n}function bs(e){let t=ft(e),n=Number.parseFloat(t.molecules[0].NMREDATA_VERSION),i={};for(let r of t.labels)if(r.toLowerCase().match("nmredata")){if(!t.molecules[0]?.[r])continue;let o=r.replace(/NMREDATA_/,""),s=String(t.molecules[0][r]);s=n>1?s.replaceAll(/\n*/g,""):s,s=s.replaceAll(/\\\n*/g,`
|
|
16
|
+
`),i[o]=s}return i}function ft(e,t={}){if(typeof e=="string"){let{filename:n="nmredata.sdf",root:i=""}=t;return{...Ne(e,{mixedEOL:!0}),root:i,filename:n}}return e}import{generateID as mr}from"@zakodium/nmrium-core";import{generateID as cr}from"@zakodium/nmrium-core";import{xyIntegration as Fs}from"ml-spectra-processing";function lr(e,t){let{x:n,re:i}=t.data;return e.map(r=>{let o=Fs({x:n,y:i},{from:r.from,to:r.to}),s=[];for(let a of r.signals||[]){let{kind:l=null,id:c,js:u=[],diaIDs:f=[],...d}=a;s.push({...d,kind:l||"signal",js:u,id:c||cr(),diaIDs:f})}return{...r,id:r.id||cr(),kind:s?.[0].kind||"signal",absolute:o,signals:s}})}function ur(e,t){let n=[],{baseFrequency:i=500}=t.info;for(let r of e){let{delta:o,diaIDs:s=[],multiplicity:a="",integration:l=0}=r,c=r.jCoupling||[],u=Ds({delta:o,js:c,frequency:i});if(c&&a&&c.length===a.length){c.sort((f,d)=>d.coupling-f.coupling);for(let f=0;f<c.length;f++)c[f].multiplicity=a[f]}n.push({id:mr(),...u,integration:l,signals:[{id:mr(),js:c,delta:o,diaIDs:s,multiplicity:a}]})}t.ranges.values=lr(H(n),t)}function Ds(e){let{delta:t,js:n=[],frequency:i}=e,r=.5;for(let o of n)r+=o.coupling;return r/=i,{from:t-r,to:t+r}}import{generateID as pr}from"@zakodium/nmrium-core";var xs=["x","y"],Ss={x:0,y:0};function fr(e,t,n={}){let i=[],{shift:r=Ss}=n,{originFrequency:o=[400,400]}=t.info,s={x:o[0],y:o[1]};for(let a of e){let l={x:{},y:{},id:pr(),kind:"signal"},c={id:pr(),kind:"signal",peaks:[]},u={x:10,y:10};for(let f of xs){let{coupling:d=[],delta:g,diaIDs:h=[]}=a[f];for(let p of d)u[f]+=p.coupling;if(a.activeCoupling){let{activeCoupling:p=[]}=a;for(let b of p)u[f]+=b.coupling}u[f]/=s[f],l[f]={from:g-u[f],to:g+u[f]},c[f]={delta:g,diaIDs:h,originalDelta:g-r[f]}}i.push({...l,signals:[c]})}t.zones.values=i}function dr(e){return Ps(e.data)}function Ps(e){return"rr"in e||!("x"in e)&&"re"in e}async function gr(e,t,n={}){let i={spectra:[],molecules:[]},r=await Ns(e,t,n);if(r.spectra.length>0){let{spectra:o,molecules:s,usedFiles:a}=r;i.spectra.push(...o),i.molecules.push(...s);let l=e.files.length;for(let c=l-1;c>=0;c--){let u=e.files[c].relativePath;!u.match(/acqu.*/s)&&a.includes(u)&&e.files.splice(c,1)}}return i}async function Ns(e,t,n){let i=[],r=await pt(e),o={spectra:[],molecules:[]};if(r.length===0)return{...o,usedFiles:i};let s=[];for(let l of r){let c=ar({sdf:l,fileCollection:e}).then(u=>{let{spectra:f,molecules:d=[]}=u;return i.push(l.root+l.filename),o.molecules.push(...d),As(f,t,n)});s.push(c)}let a=await Promise.allSettled(s);for(let l of a)l.status==="fulfilled"?(o.spectra.push(...l.value.spectra),i.push(...l.value.usedFiles)):l.reason&&n?.logger?.error(l.reason);return{...o,usedFiles:i}}async function As(e,t,n){let i=[],r=[],o={spectra:[],molecules:[]};for(let s of e){let a=Ms(s.source,t,n).then(l=>{let{spectra:c,files:u}=l;i.push(...u);for(let f of c)dr(f)?fr(s.signals,f):ur(s.signals,f);o.spectra.push(...c)});r.push(a)}return await Promise.allSettled(r),{...o,usedFiles:i}}async function Ms(e,t,n={}){let{file:i,jcampURL:r}=e,{converter:o}=n;if(r){let l=await Is(r,t,o?.jcamp);if(l)return{...l,files:[]}}let s=[];for(let l of i||[])s.push(Rs(l,n).then(c=>({...c,files:l.fileCollection.files.map(u=>u.relativePath)})));let a=await Promise.allSettled(s);for(let l of a){if(l.status==="fulfilled")return l.value;l.reason&&n?.logger?.error(l.reason)}return{spectra:[],molecules:[],files:[]}}async function Is(e,t,n={}){let i={entries:[{relativePath:e}]},r={name:X(e||""),xy:!0,noContours:!0,...n},{data:o}=await t.readFromWebSource(i,r);return o}async function Rs(e,t={}){let{converter:n,sourceSelector:i}=t;switch(e.type){case"jcamp":return Fe(e.fileCollection.files[0],{name:e?.fileCollection.files[0].name||"",converter:n?.jcamp,selector:i?.jcamp,logger:t.logger,keepSource:t.keepSource});case"brukerFiles":return ye(e.fileCollection,{converter:n?.bruker,selector:i});default:throw new Error("There is not a supported source")}}var Me=class{id="@zakodium/nmrium-core-plugins#NMReDATALoaderPlugin";version=1;migrations=[];onReadProcess;#e;constructor(t){this.#e=t,this.onReadProcess={onFiles:this.onReadProcessFiles}}onReadProcessFiles=(t,n)=>gr(t,this.#e,n)};function dt(e){return new Me(e)}import{parse as Es}from"sdf-parser";function yr(e,t={}){let{mixedEOL:n}=t,{molecules:i}=Es(e,{mixedEOL:n}),r=[];for(let{molfile:o}of i){let s=V(o);r.push(...s)}return r}async function hr(e,t={}){let{logger:n,mixedEOL:i}=t,r=await e.text(),o=yr(r,{mixedEOL:i}),s={molecules:o,spectra:[]};return n&&n[o.length>0?"info":"debug"](`Loaded ${s.molecules.length} molecules from the ${e.name} file`),s}var Ie=class{id="@zakodium/nmrium-core-plugins#SDFLoaderPlugin";version=1;migrations=[];onReadProcess;constructor(){this.onReadProcess={supportedExtensions:["sdf"],onFile:this.onReadProcessFile.bind(this)}}onReadProcessFile(t,n={}){let{logger:i}=n;return i?.debug(`Reading sdf file: ${t.name}`),hr(t,{logger:i})}};function gt(){return new Ie}import{Molecule as Ts}from"openchemlib";function br(e){let t=[],n=e.split(/\r?\n/).filter(Boolean);for(let i of n){let o=Ts.fromSmiles(i).toMolfile();t.push({molfile:o})}return t}async function Fr(e,t={}){let n=await e.text(),i=br(n),r={molecules:i,spectra:[]};return t.logger?.info(`Found ${i.length} molecules from the ${e.name} file`),r}var Re=class{id="@zakodium/nmrium-core-plugins#SMILESLoaderPlugin";version=1;migrations=[];onReadProcess;constructor(){this.onReadProcess={supportedExtensions:["smi","smiles"],onFile:this.onReadProcessFile.bind(this)}}onReadProcessFile(t,n={}){let{logger:i}=n;return Fr(t,{logger:i})}};function yt(){return new Re}import{formatSpectra as ks}from"@zakodium/nmrium-core";import{createFromToArray as Cs}from"ml-spectra-processing/utils";function Dr(e){e.setLittleEndian();let t=e.offset,n=32*3;e.offset=n/8;let i=e.readInt32(),r=[2,4],o=[2**25,2**26];if(!r.includes(i))if(o.includes(i))e.setBigEndian();else throw new Error(`Unexpected value of eBytes (${i}). Expect one of
|
|
17
|
+
${r.concat(o).join(",")}`);return e.offset=t,e.isBigEndian()?"BE":"LE"}var Ee=class{storesData;isSpectrum;isInt32;isFloat32;isComplex;isHypercomplex;isBaselineCorrected;constructor(t){if(this.storesData=(t&1)!==0,!this.storesData)throw new Error("No data stored in file. Exiting...");if(this.isSpectrum=(t&2)!==0,this.isSpectrum)throw new Error("Script only analyzes FIDs. Found spectrum.");if(this.isInt32=(t&4)!==0,this.isFloat32=(t&8)!==0,this.isComplex=(t&16)!==0,this.isHypercomplex=(t&32)!==0,this.isHypercomplex)throw new Error("Script does not analyze hypercomplex data (yet).");this.isBaselineCorrected=(t&64)!==0}},Te=class extends Ee{moreBlocks;npComplex;nfComplex;niComplex;ni2Complex;constructor(t){super(t),this.moreBlocks=(t&128)!==0,this.npComplex=(t&256)!==0,this.nfComplex=(t&512)!==0,this.niComplex=(t&1024)!==0,this.ni2Complex=(t&2048)!==0}},Oe=class extends Ee{isAcqPar;isSecondFT;isTransformed;is3D;isNp;isNf;isNi;isNi2;constructor(t){super(t),this.isAcqPar=(t&128)!==0,this.isSecondFT=(t&256)!==0,this.isTransformed=(t&512)!==0,this.is3D=(t&1024)!==0,this.isNp=(t&2048)!==0,this.isNf=(t&4096)!==0,this.isNi=(t&8192)!==0,this.isNi2=(t&16384)!==0}},Ce=class{lines;length;index;eol;constructor(t,n={}){let{eol:i=`
|
|
18
|
+
`,index:r=0}=n;this.eol=i,this.index=r,this.lines=t.split(this.eol),this.length=this.lines.length}readLine(){if(this.index>=this.length)throw new Error(`Last index is ${this.length-1}. Current index ${this.index}.`);return this.lines[this.index++]}readLines(t){let n=this.lines.slice(this.index,this.index+t);return this.index+=t,n}},we=class{softwareVersion;typeOfFile;vendorIdStatus;constructor(t){this.softwareVersion=t&2**6-1,this.typeOfFile={fidFile:(t&64)!==0,dataFile:(t&128)!==0,data3DFile:(t&256)!==0},this.vendorIdStatus={isVar:(t&0)!==0,isQOne:(t&2048)!==0,isMakeFid:(t&4096)!==0,isJeol:(t&8192)!==0,isBru:(t&16384)!==0,isMag:(t&6144)!==0,isOx:(t&10240)!==0,ipVers:(t&63)!==0,ipFileId:(t&1984)!==0,ipVendorId:(t&30720)!==0}}},ve=class{npPhMode;npAvMode;npPwrMode;nfPhMode;nfAvMode;nfPwrMode;niPhMode;niAvMode;niPwrMode;ni2PhMode;ni2AvMode;ni2PwrMode;niPaMode;ni2PaMode;constructor(t){this.npPhMode=(t&1)!==0,this.npAvMode=(t&2)!==0,this.npPwrMode=(t&4)!==0,this.nfPhMode=(t&16)!==0,this.nfAvMode=(t&32)!==0,this.nfPwrMode=(t&64)!==0,this.niPhMode=(t&256)!==0,this.niAvMode=(t&512)!==0,this.niPwrMode=(t&1024)!==0,this.ni2PhMode=(t&8)!==0,this.ni2AvMode=(t&256)!==0,this.ni2PwrMode=(t&8192)!==0,this.niPaMode=(t&16384)!==0,this.ni2PaMode=(t&32768)!==0}};var ke=class{scale;status;index;mode;ctCount;lpVal;rpVal;lvl;tlt;data;constructor(t,n,i){i&&(t.offset=i),this.scale=t.readInt16(),this.status=new Te(t.readInt16()),this.index=t.readInt16(),this.mode=new ve(t.readInt16()),this.ctCount=t.readInt32(),this.lpVal=t.readFloat32(),this.rpVal=t.readFloat32(),this.lvl=t.readFloat32(),this.tlt=t.readFloat32(),this.data=Os(t,n)}};function Os(e,t){let{np:n,nTraces:i,status:{isFloat32:r,isInt32:o}}=t;return r?ht(e,i,n,"readFloat32"):o?ht(e,i,n,"readInt32"):ht(e,i,n,"readInt16")}function ht(e,t,n,i){let r=[],o;i==="readFloat32"?o={re:new Float32Array(n/2),im:new Float32Array(n/2)}:i==="readInt32"?o={re:new Int32Array(n/2),im:new Int32Array(n/2)}:o={re:new Int16Array(n/2),im:new Int16Array(n/2)};for(let s=0;s<t;s++){for(let a=0;a<n;a+=2)o.re[a>>>1]=e[i](),o.im[a>>>1]=e[i]();r[s]=o}return r}var Le=class{nBlocks;nTraces;np;eBytes;tBytes;bBytes;version;status;nBlockHeaders;constructor(t){t.offset=0,this.nBlocks=t.readInt32(),this.nTraces=t.readInt32(),this.np=t.readInt32(),this.eBytes=t.readInt32(),this.tBytes=t.readInt32(),this.bBytes=t.readInt32(),this.version=new we(t.readInt16()),this.status=new Oe(t.readInt16()),this.nBlockHeaders=t.readInt32()}};var bt=class{name;subType;basicType;maxValue;minValue;stepSize;gGroup;dGroup;protection;active;intptr;constructor(t){let n=t.split(" ");this.name=n[0],this.subType=Number.parseInt(n[1],10),this.basicType=Number.parseInt(n[2],10),this.maxValue=Number.parseFloat(n[3]),this.minValue=Number.parseFloat(n[4]),this.stepSize=Number.parseFloat(n[5]),this.gGroup=Number.parseInt(n[6],10),this.dGroup=Number.parseInt(n[7],10),this.protection=Number.parseInt(n[8],10),this.active=Number.parseInt(n[9],10),this.intptr=Number.parseInt(n[10],10)}};function xr(e){let t=[],n=new Ce(e.readChars(e.length));for(;n.index<n.length-1;){let i=[],r=[],o=new bt(n.readLine()),s=n.readLine();if(o.basicType!==0){if(o.basicType===1)i=s.split(" ").slice(1).map(u=>Number.parseFloat(u));else if(o.basicType===2){i=s.split('"').slice(1,2);let c=Number.parseInt(s.split(" ")[0],10);for(;c>1;)i.push(n.readLine().split('"')[1]),c--}}let a=n.readLine(),l=Number.parseInt(a.split(" ")[0],10);l!==0&&(o.basicType===1?r=a.split(" ").slice(1):o.basicType===2&&(r=a.split('"').filter((c,u)=>u%2===1))),t.push({...o,values:i,enumerable:l,enumerables:r})}return t}async function Sr(e){let t={};function n(l,c){return l.then(u=>{t[c]=u})}let i=[];for(let l of e)switch(l.name.toLowerCase()){case"fid":{i.push(n(l.arrayBuffer(),"fidB"));break}case"procpar":{i.push(n(l.arrayBuffer(),"procparB"));break}default:break}if(await Promise.all(i),!t.fidB||!t.procparB)throw new RangeError("fid and procpar must exist.");let r=new O(t.fidB);Dr(r);let o=new Le(r);if(o.nBlocks!==1)throw new Error("We currently do not support 2D varian spectra ");let s=xr(new O(t.procparB)),a;for(let l of s)if(l.name==="at"){a=l.values[0];break}if(typeof a!="number")throw new Error("acquisition time parameter must exist and be a number.");{let l=Cs({from:0,to:a,length:o.np/2,distribution:"uniform"}),c=new ke(r,o);return{meta:o,fid:c,procpar:s,x:l}}}import{isAnyArray as Ls}from"is-any-array";import{xMultiply as qs}from"ml-spectra-processing";import{normalizeNucleus as ws}from"nmr-processing";function Pr(e,t){let{meta:n,procpar:i}=e,r={};for(let y of i)r[y.name]=y.values;let o={},s={},{np:a,solvent:l,sfrq:c,reffrq:u,temp:f,rp:d,sw:g,rfl:h,rfp:p}=r;S(o,"numberOfPoints",a&&Number(L(a))/2),S(o,"solvent",L(l)),S(o,"originFrequency",L(c)),S(o,"baseFrequency",L(u)),(Number.isNaN(o.originFrequency)||o.originFrequency===0)&&(o.originFrequency=400,t?.warn("The frequency could not be determined and was set to 400MHz")),S(o,"temperature",L(f)),S(o,"phc0",d&&Number(d[0])),S(s,"rfl",h&&Number(L(h))),S(s,"rfp",p&&Number(L(p))),S(s,"sw",g&&Number(L(g)));for(let y in s){let F=s[y];Array.isArray(F)&&F.length===1&&(s[y]=F[0])}if(!("baseFrequency"in o)&&"originFrequency"in o){let y=Number.parseFloat(o.originFrequency);if(["sw","rfl","rfp"].every(F=>F in s)){let{sw:F=1,rfl:x=1,rfp:N=1}=vs(s,["sw","rfl","rfp"]);S(o,"baseFrequency",y-(F/2-x+N)/1e6)}else S(o,"baseFrequency",y)}let{baseFrequency:b,originFrequency:m}=o;S(o,"frequencyOffset",(m-b)*1e6),S(o,"spectralWidth",g&&Number(g[0])/o.baseFrequency);for(let y in o)o[y].length===1&&(o[y]=o[y][0]);return r.tn&&(o.nucleus=r.tn.map(ws)),o.dimension=1,o.isFid=!n.status.isSpectrum,{info:o,meta:{...s,...Nr(n),...r}}}function L(e){return e&&(Array.isArray(e)?e[0]:e)}function vs(e,t){let n={};for(let i of t){let r=e[i];r&&typeof r=="number"&&(n[i]=r)}return n}function Nr(e){let t={};for(let n of Object.keys(e)){let i=e[n];typeof i=="object"&&i!==null&&i.constructor&&i.constructor!==Object?t[n]=Nr(i):t[n]=i}return t}function Ar(e){let t={},n=new Set(e.files.map(i=>i.relativePath));for(let i of e){let r=i.name.toLowerCase();if(r.match(/^(?:fid|procpar|text|log)$/)){if(r.match(/^(?:fid|text|log)$/)){let a=i.relativePath.replace(/(?:fid|text|log)$/,"procpar");if(!n.has(a))continue}let o=i.relativePath.split("/"),s=o.slice(0,-1).join("/");t[s]||(t[s]={name:o.at(-2),files:[]}),t[s].files.push(i)}}return Object.values(t)}async function Mr(e,t={}){let{keepSource:n,logger:i}=t,r=Ar(e);i&&i.debug(`Found ${Object.keys(r).length} varian experiments`);let o=[],s={spectra:[],molecules:[]};for(let l of r){let{name:c,files:u}=l,f=Sr(u).then(d=>{let{info:g,meta:h}=Pr(d),p=d.fid.data[0],b=Ls(p.im),m={data:{...p,x:d.x},meta:h,info:{isComplex:b,name:c,...g},display:{name:c}};if(g.isFid&&b){let{im:y}=m.data;qs(y,-1,{output:y})}u&&n&&(m.sourceSelector={files:u.map(y=>y.relativePath)}),s.spectra.push(m)});o.push(f)}let a=await Promise.allSettled(o);for(let l=0;l<a.length;l++){let c=a[l];if(c.status==="rejected"&&c.reason){let u=r[l].name;i?.warn(`Varian data: ${u}, fails with: ${c.reason}`)}}return s.spectra.length>0&&i?.info(`Loaded ${s.spectra.length} spectra from Varian files`),ks(s)}var qe=class{id="@zakodium/nmrium-core-plugins#VarianLoaderPlugin";version=1;migrations=[];onReadProcess;constructor(){this.onReadProcess={onFiles:this.onReadProcessFiles}}onReadProcessFiles=(t,n)=>{let{keepSource:i,logger:r}=n??{};return Mr(t,{keepSource:i,logger:r})}};function Ft(){return new qe}function js(e,t=[]){return[dt(e),Ft(),Ze(),nt(),mt(),gt(),yt(),lt(),Je()].concat(t)}function Bs(){let e=new _s;return e.registerPlugins(js(e)),e}import{getOneIfArray as Rr}from"@zakodium/nmrium-core";import{from1DNMRVariables as Us}from"convert-to-jcamp";function Ir(e,t){return e.filters.find(n=>n.name===t)}function $s(e,t={}){let{info:n,meta:i,data:r}=e,{onlyReal:o=!1}=t,{isFid:s,spectralWidth:a}=n,l=Rr(n.baseFrequency||n.originFrequency),{x:c,re:u,im:f}=r,d=new Float64Array(u),g=!o&&f?new Float64Array(f):void 0,h={};Q(h,"SW",a),Q(h,"BF1",l);let p=Ir(e,"fft")?.enabled,b={originFrequency:n.originFrequency,dataType:!n.isFid||p?"NMR SPECTRUM":"NMR FID",dataClass:!o&&f?"NTUPLES":"XYDATA"};if(s){let F=e.filters.find(x=>x.name==="digitalFilter");if(F&&!p){let{value:{digitalFilterValue:x},enabled:N}=F;if(N){let D=Math.floor(x);d.set(u.slice(u.length-D)),d.set(u.slice(0,u.length-D),D),f&&g&&(g.set(f.slice(f.length-D)),g.set(f.slice(0,f.length-D),D))}}Q(b,"decim",n.decim),Q(b,"dspfvs",n.dspfvs),Q(b,"digitalFilter",n.digitalFilter)}let m={xyEncoding:"DIFDUP",info:{...n,...b},meta:{...i,...h}},y={x:{data:c,label:n.isFid?"TIME":"FREQUENCY",units:n.isFid?"second":"HZ",symbol:"X"},r:{data:d,label:`${n.isFid?"FID":"SPECTRUM"}/REAL`,units:"ARBITRARY UNITS",symbol:"R"}};return g&&(y.i={data:g,label:`${n.isFid?"FID":"SPECTRUM"}/IMAG`,units:"ARBITRARY UNITS",symbol:"I"}),Us(y,m)}function Q(e,t,n){n!==void 0&&(e[t]=Rr(n))}export{ne as AutoPostProcessingPlugin,he as BrukerLoaderPlugin,De as JCAMPDXLoaderPlugin,Se as JEOLLoaderPlugin,Pe as MolfileLoaderPlugin,Me as NMReDATALoaderPlugin,Ie as SDFLoaderPlugin,Re as SMILESLoaderPlugin,qe as VarianLoaderPlugin,Je as autoPostProcessing,Ze as brukerLoader,Bs as default,Bs as init,nt as jcampDXLoader,lt as jeolLoader,mt as molfileLoader,dt as nmreDATALoader,Nn as processJCAMPDX,yr as readSDF,br as readSMILES,js as recommended,gt as sdfLoader,yt as smilesLoader,$s as spectrum1DToJCAMPDX,Ft as varianLoader};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zakodium/nmrium-core-plugins",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "Recommended plugins for NMRium, loaders of common formats like bruker or jcamp, and some post-processing plugins",
|
|
5
5
|
"author": "Zakodium Sàrl",
|
|
6
6
|
"license": "CC-BY-NC-SA-4.0",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"@zakodium/bruker-parser": "^0.0.0",
|
|
32
32
|
"@zakodium/jeol-parser": "^0.0.0",
|
|
33
33
|
"@zakodium/nmr-types": "^0.1.0",
|
|
34
|
+
"@zakodium/nmredata": "^0.0.0",
|
|
34
35
|
"@zakodium/varian-parser": "^0.0.0",
|
|
35
36
|
"bruker-data-test": "^1.0.0",
|
|
36
37
|
"esbuild": "^0.25.5",
|
|
@@ -44,7 +45,6 @@
|
|
|
44
45
|
"vitest": "^3.2.4"
|
|
45
46
|
},
|
|
46
47
|
"dependencies": {
|
|
47
|
-
"@zakodium/nmredata": "^0.0.0",
|
|
48
48
|
"@zakodium/nmrium-core": "^0.1.4",
|
|
49
49
|
"cheminfo-types": "^1.8.1",
|
|
50
50
|
"convert-to-jcamp": "^5.4.11",
|