@rfkit/spectrum-analyzer 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -1 +1 @@
1
- let t={DEFAULT_CACHE_TIME:15e3,DEFAULT_GRANULARITY:10,DEFAULT_RANGE:[-20,100]},e={cacheTime:t.DEFAULT_CACHE_TIME,granularity:t.DEFAULT_GRANULARITY,range:t.DEFAULT_RANGE,maxPoints:void 0,onLevelStreamUpdate:t=>{}};class a{config;spectrumData=[];probabilityData=new Map;count=0;constructor(t){this.config={...e,...t}}reset(){this.spectrumData=[],this.probabilityData=new Map,this.count=0}setConfig(t){let a=void 0!==t.cacheTime&&this.config.cacheTime!==t.cacheTime||void 0!==t.granularity&&this.config.granularity!==t.granularity||void 0!==t.maxPoints&&this.config.maxPoints!==t.maxPoints;this.config={...e,...this.config,...t},a&&this.reset(),t.range&&this.outputData()}process(t,e){this.removeExpiredData(),this.addNewData(t,e),this.updateProbability(t),this.outputData()}updateProbability(t){let{granularity:e}=this.config;this.count++;let a=Math.round(t/e)*e,s=this.probabilityData.get(a)||0;s++,this.probabilityData.set(a,s)}getAll(){return this.probabilityData}removeExpiredData(){let{cacheTime:t,maxPoints:e}=this.config;if(0===this.spectrumData.length)return;if(void 0!==e&&e>0){this.spectrumData.length>e&&(this.spectrumData=this.spectrumData.slice(-e));return}let a=Date.now();if(t<=0){this.spectrumData=[];return}let s=0,i=this.spectrumData.length-1;for(;s<=i;){let e=Math.floor((s+i)/2);a-this.spectrumData[e].timestamp>=t?s=e+1:i=e-1}this.spectrumData=this.spectrumData.slice(s)}addNewData(t,e){this.spectrumData.push({value:t,timestamp:e})}outputData(){let{range:t,granularity:e,onLevelStreamUpdate:a}=this.config,s=t[0],i=t[1],r=Array(Math.round((i-s)/e)+1).fill(0);for(let[t,a]of this.probabilityData)if(t>=s&&t<=i){let s=Math.round((i-t)/e);this.count>0&&(r[s]=a/this.count*100)}a?.({probabilityRangeData:new Float32Array(r),spectrumData:new Float32Array(this.spectrumData.map(t=>t.value)),timestampData:new Float64Array(this.spectrumData.map(t=>t.timestamp))})}}let s={INITIAL_VALUE:0/0,WATERFALL_MAX_FRAMES:100,OUTPUT_POINTS:1001},i={MAX_PEAKS:2},r=null,n={UPDATE_INTERVAL:1,LEVEL_MIN:-20,LEVEL_MAX:140,LEVEL_RANGE:161},l={maxPoints:s.OUTPUT_POINTS,waterfallMaxFrames:s.WATERFALL_MAX_FRAMES,initialValue:s.INITIAL_VALUE,processing:{enableWaterfall:!1,enableMetrics:!1,enableFluorescence:!1,enablePeakStats:!1,fluorescenceUpdateInterval:n.UPDATE_INTERVAL},peakDetection:{maxPeaks:i.MAX_PEAKS},outputPoints:s.OUTPUT_POINTS,outputRange:{start:0,end:s.OUTPUT_POINTS},templateTolerance:0},h={EMPTY_SEGMENTS:"频段配置不能为空",INVALID_CONFIG:"必须且只能配置 segments 或 bandwidthConfig 其中之一",EMPTY_BANDWIDTH:"bandwidthConfig 不能为空",INVALID_SEGMENT:t=>`无效的段索引: ${t}`,INDEX_OUT_OF_BOUNDS:t=>`索引超出范围: ${t}`,INVALID_ANTENNA_FACTOR_LENGTH:t=>`天线因子数据长度必须等于实时数据长度 (${t})`,INVALID_ANTENNA_FACTOR:"天线因子数据必须是有效的正数",INVALID_SAMPLING_RANGE:"采样范围无效",INVALID_MAX_POINTS:"点数必须大于0",INVALID_LENGTH:t=>`频率占用度数据长度不匹配,期望长度为 ${t}`};class o extends Error{code;details;constructor(t,e,a){super(t),this.code=e,this.details=a,this.name="SpectrumError"}}class u extends o{constructor(t,e){super(t,"DATA_VALIDATION_ERROR",e)}}class c extends o{index;constructor(t,e,a){super(t,"INDEX_OUT_OF_BOUNDS_ERROR",{index:e,...a||{}}),this.index=e}}let p=(t,e)=>{void 0!==t.max&&(e.max=t.max),void 0!==t.maxIndex&&(e.maxIndex=t.maxIndex),void 0!==t.timestamp&&(e.timestamp=t.timestamp),void 0!==t.progress&&(e.progress=t.progress)},g=(t,e,a)=>t<=e?e:t>=a?a:t,f=(t,e)=>e<=1?0:Math.max(0,Math.min(e-1,Math.ceil(e*g(t,0,100)/100)-1)),D=(t,e,a)=>{if(!Number.isFinite(t)||e<=0||a<=0)return;let s=g(Number(t),0,100);return{left:s,sampledIndex:f(s,e),globalIndex:f(s,a)}},m=({realData:t,antennaFactorData:e,antennaFactorSwitch:a=!1,outputPoints:s})=>{let i=t.length,r=i<=s,n=r?i:s,l=new Uint32Array(n),h=new Float32Array(n);if(h.timestamp=t.timestamp,r){if(!a){for(let t=0;t<i;t++)l[t]=t;return h.set(t),{realOutputData:h,srcIndexCache:l}}for(let a=0;a<i;a++)l[a]=a,h[a]=t[a]+e[a];return{realOutputData:h,srcIndexCache:l}}let o=i/s,u=o/2;for(let s=0;s<n;s++){let r=Math.floor(u),n=Math.min(Math.floor(u+o),i),c=t[r],p=r;for(let e=r+1;e<n;e++)t[e]>c&&(c=t[e],p=e);h[s]=a?c+e[p]:c,l[s]=p,u+=o}return{realOutputData:h,srcIndexCache:l}},d=({antennaFactorData:t,antennaFactorSwitch:e=!1,outputPoints:a,realData:s,maxData:i,minData:r,avgData:n,templateData:l,backgroundNoiseData:h,thresholdData:o,fluorescenceData:u,occupancyData:c,enablePeakStats:p=!1,maxPeaks:g=2,outputRangeStart:f=0})=>{let D=s.length,m=D<=a,d=m?D:a,x=i&&i.length>0,A=r&&r.length>0,w=n&&n.length>0,y=l&&l.length>0,F=c&&c.length>0,S=h&&h.length>0,b=o&&o.length>0,E=u&&u.length>0,O=[],I=e?(e,a)=>e+t[a]:t=>t,N=new Float32Array(d);N.timestamp=s.timestamp;let M=new Float32Array(x?d:0),P=new Float32Array(A?d:0),T=new Float32Array(w?d:0),v=new Float32Array(y?d:0),L=new Float32Array(F?d:0),_=new Float32Array(S?d:0),U=new Float32Array(b?d:0),R=Array(E?d:0).fill(null),k=new Uint32Array(d);if(m){for(let t=0;t<D;t++)k[t]=t;if(e)for(let e=0;e<D;e++){let a=t[e];if(N[e]=s[e]+a,x&&(M[e]=i[e]+a),A&&(P[e]=r[e]+a),w&&(T[e]=n[e]+a),y&&(v[e]=l[e]+a),F&&(L[e]=c[e]),S&&(_[e]=h[e]+a),b&&(U[e]=o[e]+a),E){let t=u[e],s=new Map;for(let[e,i]of t)s.set(e+a,i);R[e]=s}}else N.set(s),x&&M.set(i),A&&P.set(r),w&&T.set(n),y&&v.set(l),F&&L.set(c),S&&_.set(h),b&&U.set(o),E&&(R=u);if(p)for(let t=0;t<D;t++){let e=N[t];Number.isFinite(e)&&O.push({index:t,srcIndex:t+f,value:e})}}else{let t=D/a,e=t/2;for(let a=0;a<d;a++){let g=Math.floor(e),m=Math.min(Math.floor(e+t),D),d=s[g],C=g,V=x?i[g]:0,W=g,G=A?r[g]:0,H=g,B=F?c[g]:0;for(let t=g+1;t<m;t++)s[t]>d&&(d=s[t],C=t),x&&i[t]>V&&(V=i[t],W=t),A&&r[t]<G&&(G=r[t],H=t),F&&c[t]>B&&(B=c[t]);let z=I(d,C);if(N[a]=z,k[a]=C,p&&Number.isFinite(z)&&O.push({index:a,srcIndex:C+f,value:z}),x&&(M[a]=I(V,W)),A&&(P[a]=I(G,H)),w){let t=n[C];T[a]=I(t,C)}if(y){let t=l[C];v[a]=I(t,C)}if(F&&(L[a]=B),S){let t=h[C];_[a]=I(t,C)}if(b){let t=o[C];U[a]=I(t,C)}if(E){let t=u[C],e=new Map;for(let[a,s]of t)e.set(I(a,C),s);R[a]=e}e+=t}}return p&&O.length>0&&(O.sort((t,e)=>e.value-t.value),N.peaks={peaks:O.slice(0,g),timestamp:s.timestamp}),{realOutputData:N,maxOutputData:M,minOutputData:P,avgOutputData:T,templateOutputData:v,occupancyOutputData:L,backgroundNoiseOutputData:_,thresholdOutputData:U,srcIndexCache:k,fluorescenceOutputData:R}},x=(t,e,a,s,i)=>{if(!t||0===Object.keys(t).length)return{};let r={},n=Object.keys(t),l=s.length;for(let t=0;t<n.length;t++)r[n[t]]=new Float32Array(l);for(let h=0;h<n.length;h++){let o=n[h],u=i(t[o]),c=r[o];if(a)for(let t=0;t<l;t++){let a=s[t];c[t]=u[a]+e[a]}else for(let t=0;t<l;t++){let e=s[t];c[t]=u[e]}}return r},A=({realData:t,maxData:e,minData:a,templateData:s,tolerance:i=0,startIndex:r=0,endIndex:n,usePreallocation:l=!1})=>{let{timestamp:h}=t,o=n??t.length,u=[],c=-1,p=0,g=0;if(l&&0===r&&o===t.length){let r=new Uint8Array(t.length);for(let e=0;e<t.length;e++)r[e]=+(t[e]>s[e]+i);for(let s=0;s<t.length;s++)if(r[s])-1===c?(c=s,p=t[s],g=1):(p+=t[s],g++);else if(-1!==c){let t=s-1;if(t-c+1>=2){let s=p/g,i=c+(t-c>>1);u.push({maxValue:e[i],minValue:a[i],avgValue:s,timestamp:h,startIndex:c,endIndex:t})}c=-1}}else for(let n=r;n<Math.min(o,t.length);n++)if(t[n]>s[n]+i)-1===c?(c=n,p=t[n],g=1):(p+=t[n],g++);else if(-1!==c){let t=n-1;if(t-c+1>=2){let s=p/g,i=c+(t-c>>1);u.push({maxValue:e[i],minValue:a[i],avgValue:s,timestamp:h,startIndex:c,endIndex:t})}c=-1}if(-1!==c){let t=o-1;if(t-c+1>=2){let s=p/g,i=c+(t-c>>1);u.push({maxValue:e[i],minValue:a[i],avgValue:s,timestamp:h,startIndex:c,endIndex:t})}}return u},w=({realData:t,maxData:e,minData:a,templateData:s,tolerance:i=0})=>s&&0!==s.length?A({realData:t,maxData:e,minData:a,templateData:s,tolerance:i,usePreallocation:!0}):[],y=({realData:t,maxData:e,minData:a,templateData:s,tolerance:i=0,startIndex:r,endIndex:n,previousSegments:l=[]})=>!s||0===s.length||r>=n?l:[...l,...A({realData:t,maxData:e,minData:a,templateData:s,tolerance:i,startIndex:r,endIndex:n})];function F(t){for(let e=0;e<t.length;e++)if(!Number.isFinite(t[e]))return!1;return!0}var S=/*#__PURE__*/function(t){return t.REPLACE="replace",t.MERGE="merge",t.CLEAR="clear",t}({}),b=/*#__PURE__*/null;class E{config=l;segments=[];antennaFactorData;antennaFactorSwitch;realData;maxData;minData;avgData;templateData;occupancyData;backgroundNoiseData;thresholdData;waterfallData;srcIndexCache;realOutputData;maxOutputData;minOutputData;avgOutputData;templateOutputData;occupancyOutputData;backgroundNoiseOutputData;thresholdOutputData;waterfallOutputData;scanProgress;lastIndex;processTimes;lastProcessTime;cachedExceedingDatas=[];waterfallHead=0;waterfallCount=0;waterfallSink;fluorescenceData;fluorescenceMaxCount=0;fluorescenceUpdateCounter=0;extraData={};extraOutputData={};pendingDataFlags={occupancy:!1,template:!1,backgroundNoise:!1,threshold:!1,extra:!1};hasPendingData=!1;hasProcessedData=!1;isProcessing=!1;onSpectrumUpdate;constructor(t){let{onSpectrumUpdate:e,maxPoints:a}=t;this.onSpectrumUpdate=e,this.config={...l,...t,processing:{...l.processing,...t.processing},peakDetection:{...l.peakDetection,...t.peakDetection},outputRange:{start:t.outputRange?.start??0,end:t.outputRange?.end??a??s.OUTPUT_POINTS}},this.reset()}setWaterfallSink(t){let e=void 0!==this.waterfallSink;if(this.waterfallSink=t??void 0,!t||((e||this.waterfallCount>0)&&t.reset(),!this.config.processing.enableWaterfall||0===this.waterfallCount))return;let a=this.getOrderedWaterfallData(this.waterfallOutputData);t.replace(a,this.config.waterfallMaxFrames)}getWaterfallTimestamps(t){let e=Number.isFinite(t)?Math.max(0,Math.floor(t)):0,a=this.waterfallOutputData.length;if(0===e||0===a)return[];let s=Array(e),i=a-1,r=Math.max(1,e-1);for(let t=0;t<e;t++){let a=1===e?i:Math.floor(i*t/r);s[t]=this.getWaterfallFrameAt(this.waterfallOutputData,a)?.timestamp}return s}process({data:t,timestamp:e,segmentOffset:a=0,offset:s=0,fluorescenceData:i,fluorescenceMaxCount:r}){let n=performance.now();try{if(!t?.length)return;this.isProcessing=!0,this.hasProcessedData=!0;let n=this.resolveGlobalIndex(a,s);this.segments.length?this.scanProgress=(n+t.length)/this.config.maxPoints:t.length!==this.config.maxPoints&&this.updateMaxPoints(t.length),i&&void 0!==r&&(this.fluorescenceData=i,this.fluorescenceMaxCount=r),this.validateInput(t,n);let{maxPoints:l}=this.config,h=n+t.length;this.lastIndex=h;let o=h>=l||h<this.lastIndex;this.realData.set(t,n),this.realData.timestamp=e,this.processDataPoints(t,n,o);let u=this.resampleDataSeries();o&&u.realData&&this.updateWaterfallData(this.realData,u.realData);let c=this.updateTemplateOverData(o,o?void 0:{startIndex:n,endIndex:n+t.length}),p=this.processPendingData();this.notifySpectrumUpdate({...u,...p||{},extraData:this.extraOutputData,waterfallData:this.waterfallOutputData,scanProgress:this.scanProgress,processTimes:this.processTimes,...c&&{templateOverData:c}})}catch(t){throw t instanceof Error?t:Error(String(t))}finally{this.isProcessing=!1,this.lastProcessTime=performance.now()-n}}initializeSegments(t){if(!t?.length)throw new u(h.EMPTY_SEGMENTS);let e=this.config.maxPoints,a=0;this.segments=t.map(t=>{let{startFrequency:e,stopFrequency:s,stepFrequency:i}=t,r=Math.round(1e3*(s-e)/i)+1,n=a;return a+=r,{startFrequency:e,stopFrequency:s,stepFrequency:i,pointCount:r,startIndex:n}}),this.updateMaxPoints(a,!1),e===a&&(this.config={...this.config,outputRange:{start:0,end:a}},this.reset(!1))}setAntennaFactor(t){let{antennaFactorData:e,config:{maxPoints:a}}=this,s=new Float32Array(t);s.length!==a&&(s=new Float32Array(s).subarray(0,a),console.warn(h.INVALID_ANTENNA_FACTOR_LENGTH(a)));let i=!1;for(let t=0;t<s.length;t++){let a=s[t],r=Number.isFinite(a)&&a>0;r||(i=!0),e[t]=r?a:0}i&&console.warn(h.INVALID_ANTENNA_FACTOR),this.antennaFactorSwitch&&this.setAntennaFactorSwitch(this.antennaFactorSwitch)}setAntennaFactorSwitch(t){let e=this.antennaFactorSwitch!==t;if(this.antennaFactorSwitch=t,e){let t=this.resampleDataSeries();this.resampleWaterfallOutputData(),this.notifyWaterfallReplace(),this.notifySpectrumUpdate({...t,waterfallData:this.waterfallOutputData})}}updateProcessing(t){let{processing:e}=this.config,a={...e,...void 0!==t.enableMetrics&&{enableMetrics:t.enableMetrics},...void 0!==t.enableFluorescence&&{enableFluorescence:t.enableFluorescence},...void 0!==t.enablePeakStats&&{enablePeakStats:t.enablePeakStats},...void 0!==t.fluorescenceUpdateInterval&&{fluorescenceUpdateInterval:t.fluorescenceUpdateInterval}};if(a.enableMetrics===e.enableMetrics&&a.enableFluorescence===e.enableFluorescence&&a.enablePeakStats===e.enablePeakStats&&a.fluorescenceUpdateInterval===e.fluorescenceUpdateInterval)return;this.config={...this.config,processing:a},a.enableMetrics&&!e.enableMetrics&&(0===this.maxData.length||0===this.minData.length||0===this.avgData.length)&&(this.allocateMetricsBuffers(),this.clearMetricsBuffers()),a.enableFluorescence&&!e.enableFluorescence&&0===this.fluorescenceData.length&&(this.fluorescenceData=new Uint32Array(this.config.maxPoints*n.LEVEL_RANGE));let s=this.resampleDataSeries();this.extraOutputData=x(this.extraData,this.antennaFactorData,this.antennaFactorSwitch,this.srcIndexCache,this.getOutputData.bind(this)),this.notifySpectrumUpdate({...s,extraData:this.extraOutputData})}clearMetricsData(){let t=0===this.maxData.length||0===this.minData.length||0===this.avgData.length||0===this.maxOutputData.length||0===this.minOutputData.length||0===this.avgOutputData.length;if(this.config.processing.enableMetrics&&t){let t=this.realOutputData?.length??this.config.outputPoints;this.allocateMetricsBuffers(t)}this.clearMetricsBuffers(),this.processTimes=0,this.notifySpectrumUpdate({maxData:this.maxOutputData,minData:this.minOutputData,avgData:this.avgOutputData,processTimes:0})}allocateMetricsBuffers(t){let{maxPoints:e,outputPoints:a,processing:{enableMetrics:s}}=this.config,i=s?e:0,r=0;s&&(r=Math.min(r=Math.max(0,Math.floor(t??a)),a)),this.maxData=new Float32Array(i),this.minData=new Float32Array(i),this.avgData=new Float32Array(i),this.maxOutputData=new Float32Array(r),this.minOutputData=new Float32Array(r),this.avgOutputData=new Float32Array(r)}clearMetricsBuffers(){this.maxData.fill(s.INITIAL_VALUE),this.minData.fill(s.INITIAL_VALUE),this.avgData.fill(s.INITIAL_VALUE),this.maxData.allValid=!1,this.minData.allValid=!1,this.avgData.allValid=!1,this.maxOutputData.fill(s.INITIAL_VALUE),this.minOutputData.fill(s.INITIAL_VALUE),this.avgOutputData.fill(s.INITIAL_VALUE)}setWaterfallData(t){if(!(t?.[0]?.length>0))return;let{processing:e}=this.config,{waterfallMaxFrames:a}=this.config;e.enableWaterfall&&(a=t.length,this.config={...this.config,waterfallMaxFrames:a},this.waterfallData=t.slice(),this.waterfallHead=0,this.waterfallCount=this.waterfallData.length,this.resampleWaterfallOutputData(),this.notifyWaterfallReplace(),this.notifySpectrumUpdate({waterfallData:this.waterfallOutputData}))}setFluorescenceData(t,e){if(!this.config.processing.enableFluorescence||!t||0===t.length)return;let a=this.config.maxPoints*n.LEVEL_RANGE;if(t.length!==a)return;this.fluorescenceData=t,this.fluorescenceMaxCount=e;let s=this.config.outputRange.end-this.config.outputRange.start,i=this.getFluorescenceOutputData(s);this.notifySpectrumUpdate({fluorescenceData:i,fluorescenceMaxCount:this.fluorescenceMaxCount})}setRealData(t){if(!(t?.length>0)||t.length!==this.config.maxPoints)return;let e=new Float32Array(t.length);e.set(t),e.timestamp=t.timestamp,this.realData=e;let a=this.resampleDataSeries();this.notifySpectrumUpdate(a)}setMaxData(t){if(!(t?.length>0)||t.length!==this.config.maxPoints)return;let e=new Float32Array(t.length);e.set(t),this.maxData=e,this.maxData.allValid=F(this.maxData);let a=this.resampleDataSeries();this.notifySpectrumUpdate(a)}setMinData(t){if(!(t?.length>0)||t.length!==this.config.maxPoints)return;let e=new Float32Array(t.length);e.set(t),this.minData=e,this.minData.allValid=F(this.minData);let a=this.resampleDataSeries();this.notifySpectrumUpdate(a)}setAvgData(t){if(!(t?.length>0)||t.length!==this.config.maxPoints)return;let e=new Float32Array(t.length);e.set(t),this.avgData=e,this.avgData.allValid=F(this.avgData);let a=this.resampleDataSeries();this.notifySpectrumUpdate(a)}setOccupancyData(t){if(!t||0===t.length){this.occupancyData=new Float32Array(0),this.setPendingFlag("occupancy",!1);return}if(this.occupancyData=new Float32Array(t),!this.hasProcessedData||this.isProcessing)return void this.setPendingFlag("occupancy",!0);let e=this.resampleDataSeries();this.notifySpectrumUpdate({occupancyData:e.occupancyData}),this.setPendingFlag("occupancy",!1)}setExtraData(t,e=S.MERGE,a){if(e===S.CLEAR){this.extraData={},this.extraOutputData={},this.setPendingFlag("extra",!1);return}if(!t){e===S.REPLACE&&(this.extraData={},this.extraOutputData={},this.setPendingFlag("extra",!1));return}let i=Object.entries(t).map(([t,e])=>[t,e?.length?new Float32Array(e):null]),r=a?this.resolveGlobalIndex(a.segmentOffset??0,a.offset??0):0;if(a)for(let[,t]of i)t&&this.validateInput(t,r);for(let[t,n]of(e===S.REPLACE&&(this.extraData={},this.extraOutputData={},this.setPendingFlag("extra",!1)),i)){if(!n){delete this.extraData[t];continue}if(!a){this.extraData[t]=n;continue}let e=this.extraData[t];if(e?.length!==this.config.maxPoints){let a=new Float32Array(this.config.maxPoints);a.fill(s.INITIAL_VALUE),e?.length&&a.set(e.subarray(0,this.config.maxPoints)),e=a,this.extraData[t]=e}e.set(n,r)}!this.hasProcessedData||this.isProcessing?this.setPendingFlag("extra",!0):(this.extraOutputData=x(this.extraData,this.antennaFactorData,this.antennaFactorSwitch,this.srcIndexCache,this.getOutputData.bind(this)),this.notifySpectrumUpdate({extraData:this.extraOutputData}),this.setPendingFlag("extra",!1))}reset(t=!1){let{maxPoints:e,waterfallMaxFrames:a,processing:{enableFluorescence:i}}=this.config;this.antennaFactorData=new Float32Array(e);let r=new Float32Array(e);r.timestamp="",r.fill(s.INITIAL_VALUE),this.realData=r,this.allocateMetricsBuffers(),this.clearMetricsBuffers(),this.templateData=new Float32Array,this.occupancyData=new Float32Array,this.backgroundNoiseData=new Float32Array,this.clearThresholdDataState(),this.waterfallData=Array.from({length:a},()=>{let t=new Float32Array;return t.timestamp="",t.fill(s.INITIAL_VALUE),t}),this.waterfallOutputData=Array.from({length:a},()=>{let t=new Float32Array;return t.timestamp="",t.fill(s.INITIAL_VALUE),t}),this.waterfallHead=0,this.waterfallCount=0,this.waterfallSink?.reset();let l=this.config.outputPoints;this.realOutputData=new Float32Array(l).fill(s.INITIAL_VALUE),this.templateOutputData=new Float32Array,this.occupancyOutputData=new Float32Array,this.backgroundNoiseOutputData=new Float32Array,this.fluorescenceData=new Uint32Array(i?e*n.LEVEL_RANGE:0),this.fluorescenceMaxCount=0,this.fluorescenceUpdateCounter=0,this.extraData={},this.extraOutputData={},this.srcIndexCache=new Uint32Array(e),this.scanProgress=0,this.lastIndex=0,this.processTimes=0,this.lastProcessTime=0,this.cachedExceedingDatas=[],this.pendingDataFlags={occupancy:!1,template:!1,backgroundNoise:!1,threshold:!1,extra:!1},this.hasPendingData=!1,t||(this.hasProcessedData=!1),this.notifySpectrumUpdate({realData:this.realData,maxData:this.maxData,minData:this.minData,avgData:this.avgData,templateData:this.templateData,backgroundNoiseData:this.backgroundNoiseData,thresholdData:this.thresholdData,extraData:this.extraData,srcIndexCache:this.srcIndexCache,processTimes:0,scanProgress:0})}getPerformanceMetrics(){return{lastProcessTime:this.lastProcessTime,dataPoints:this.config.maxPoints,waterfallFrames:this.waterfallData.length,isInitialized:this.realData.length>0,memoryUsage:this.calculateMemoryUsage()}}getPeakStats(){if(!this.config.processing.enablePeakStats)return;let{realData:t}=this.resampleDataSeries();if(t)return t.peaks}updateSamplingRange(t,e){if(t<0||t>=e)throw new u(h.INVALID_SAMPLING_RANGE);this.config={...this.config,outputRange:{start:Math.floor(t),end:Math.ceil(e)}};let a=this.resampleDataSeries();return this.resampleWaterfallOutputData(),this.notifyWaterfallReplace(),this.extraOutputData=x(this.extraData,this.antennaFactorData,this.antennaFactorSwitch,this.srcIndexCache,this.getOutputData.bind(this)),this.notifySpectrumUpdate({...a,extraData:this.extraOutputData,waterfallData:this.waterfallOutputData}),this.srcIndexCache}setTemplateData(t,e){if(!t||0===t.length){this.templateData=new Float32Array(0),this.setPendingFlag("template",!1);return}(void 0!==e&&(this.config.templateTolerance=e),this.templateData=new Float32Array(t),!this.hasProcessedData||this.isProcessing)?this.setPendingFlag("template",!0):(this.notifySpectrumUpdate({templateData:this.resampleSingleData(this.templateData),templateOverData:this.updateTemplateOverData(!0)}),this.setPendingFlag("template",!1))}setBackgroundNoiseData(t){if(!t||0===t.length){this.backgroundNoiseData=new Float32Array(0),this.setPendingFlag("backgroundNoise",!1);return}(this.backgroundNoiseData=new Float32Array(t),!this.hasProcessedData||this.isProcessing)?this.setPendingFlag("backgroundNoise",!0):(this.notifySpectrumUpdate({backgroundNoiseData:this.resampleSingleData(this.backgroundNoiseData)}),this.setPendingFlag("backgroundNoise",!1))}setThresholdData(t,e){if(!t||0===t.length)return void this.clearThresholdDataState();let a=t instanceof Float32Array?t:new Float32Array(t);if(e){let t=this.resolveGlobalIndex(e.segmentOffset??0,e.offset??0);if(this.validateInput(a,t),this.thresholdData.length!==this.config.maxPoints){let t=new Float32Array(this.config.maxPoints);t.fill(s.INITIAL_VALUE),this.thresholdData.length>0&&t.set(this.thresholdData.subarray(0,this.config.maxPoints)),this.thresholdData=t}this.thresholdData.set(a,t)}else{let t=new Float32Array(this.config.maxPoints);t.fill(s.INITIAL_VALUE),t.set(a.subarray(0,this.config.maxPoints)),this.thresholdData=t}if(!this.hasProcessedData||this.isProcessing)return void this.setPendingFlag("threshold",!0);let i=this.resampleSingleData(this.thresholdData);this.thresholdOutputData=i,this.notifySpectrumUpdate({thresholdData:i}),this.setPendingFlag("threshold",!1)}updateTemplateOverData(t=!1,e){let a;return this.templateData&&0!==this.templateData.length?(t||!e?(a=w({realData:this.realData,maxData:this.maxData,minData:this.minData,templateData:this.templateData,tolerance:this.config.templateTolerance}),this.cachedExceedingDatas=a):(this.cachedExceedingDatas=y({realData:this.realData,maxData:this.maxData,minData:this.minData,templateData:this.templateData,tolerance:this.config.templateTolerance,startIndex:e.startIndex,endIndex:e.endIndex,previousSegments:this.cachedExceedingDatas}),a=this.cachedExceedingDatas),a):(this.cachedExceedingDatas=[],[])}resolveGlobalIndex(t=0,e=0){if(this.segments.length){let a=this.segments[t];if(!a)throw new u(h.INVALID_SEGMENT(t));return a.startIndex+e}return e}clearThresholdDataState(){this.thresholdData=new Float32Array(0),this.thresholdOutputData=new Float32Array(0),this.setPendingFlag("threshold",!1)}resampleDataSeries(){let{antennaFactorData:t,antennaFactorSwitch:e,maxData:a,minData:s,avgData:i,templateData:r,occupancyData:n,backgroundNoiseData:l,thresholdData:h,config:{maxPoints:o,outputPoints:u}}=this,{realOutputData:c,srcIndexCache:p,maxOutputData:g,minOutputData:f,avgOutputData:D,templateOutputData:m,occupancyOutputData:x,backgroundNoiseOutputData:A,thresholdOutputData:w}=d({antennaFactorData:e?t:new Float32Array(o),antennaFactorSwitch:e,outputPoints:u,realData:this.getOutputData(),maxData:a?.length>0?this.getOutputData(a):void 0,minData:s?.length>0?this.getOutputData(s):void 0,avgData:i&&i.length>0?this.getOutputData(i):void 0,templateData:r&&r.length>0?this.getOutputData(r):void 0,occupancyData:n&&n.length>0?this.getOutputData(n):void 0,backgroundNoiseData:l&&l.length>0?this.getOutputData(l):void 0,thresholdData:h&&h.length>0?this.getOutputData(h):void 0,enablePeakStats:this.config.processing.enablePeakStats,maxPeaks:this.config.peakDetection.maxPeaks,outputRangeStart:this.config.outputRange.start});this.srcIndexCache=p,this.realOutputData=c,this.maxOutputData=g||new Float32Array,this.minOutputData=f||new Float32Array,this.avgOutputData=D||new Float32Array,this.templateOutputData=m||new Float32Array,this.occupancyOutputData=x||new Float32Array,this.backgroundNoiseOutputData=A||new Float32Array,this.thresholdOutputData=w||new Float32Array;let y=this.getFluorescenceOutputData(c.length);return{realData:c,maxData:g,minData:f,avgData:D,templateData:m,occupancyData:x,backgroundNoiseData:A,thresholdData:w,fluorescenceData:y,fluorescenceMaxCount:this.fluorescenceMaxCount,extraData:this.extraOutputData,srcIndexCache:p}}resampleWaterfallOutputData(){let{antennaFactorData:t,antennaFactorSwitch:e,waterfallData:a,config:{maxPoints:s,processing:{enableWaterfall:i},outputPoints:r}}=this;if(!i)return;let n=e?t:new Float32Array(s);this.waterfallOutputData=a.map(t=>{let{realOutputData:a}=d({realData:this.getOutputData(t),antennaFactorData:n,antennaFactorSwitch:e,outputPoints:r});return a})}getOrderedWaterfallData(t){let e=t.length;if(0===e)return[];let a=Math.min(this.waterfallCount,e);if(0===a||a===e&&0===this.waterfallHead)return t;let s=e-a,i=Array(e);for(let r=0;r<s;r++){let s=(this.waterfallHead+a+r)%e;i[r]=t[s]}for(let r=0;r<a;r++){let a=(this.waterfallHead+r)%e;i[s+r]=t[a]}return i}getWaterfallFrameAt(t,e){let a=t.length,s=Math.min(this.waterfallCount,a),i=a-s;return t[e<i?(this.waterfallHead+s+e)%a:(this.waterfallHead+e-i)%a]}notifyWaterfallAppend(t){this.waterfallSink?.append(t,this.config.waterfallMaxFrames)}notifyWaterfallReplace(){if(!this.waterfallSink||0===this.waterfallCount)return;let t=this.getOrderedWaterfallData(this.waterfallOutputData);this.waterfallSink.replace(t,this.config.waterfallMaxFrames)}updateWaterfallData(t,e){let{waterfallMaxFrames:a,processing:s}=this.config;if(!s.enableWaterfall||a<=0)return;let i=new Float32Array(t.length);i.set(t),i.timestamp=t.timestamp;let r=this.waterfallCount<a?(this.waterfallHead+this.waterfallCount)%a:this.waterfallHead;this.waterfallData[r]=i,this.waterfallOutputData[r]=e,this.waterfallCount<a?this.waterfallCount+=1:this.waterfallHead=(this.waterfallHead+1)%a,this.notifyWaterfallAppend(e)}updateMaxPoints(t,e=!0){this.config.maxPoints!==t&&(this.config={...this.config,maxPoints:t,outputRange:{start:0,end:t}},this.reset(e))}validateInput(t,e){if(e<0||e+t.length>this.config.maxPoints)throw new c(h.INDEX_OUT_OF_BOUNDS(e),e)}processDataPoints(t,e,a){let{maxData:s,minData:i,avgData:r,config:{processing:{enableMetrics:n}}}=this;n&&a&&(this.processTimes+=1,s.allValid||(s.allValid=F(s)),i.allValid||(i.allValid=F(i)),r.allValid||(r.allValid=F(r)));let l=t.length;if(this.config.processing.enableFluorescence)for(let a=0;a<l;a++)this.updateFluorescenceStats(e+a,t[a]);if(!n)return;let h=!0;for(let e=0;e<l;e++)if(!Number.isFinite(t[e])){h=!1;break}for(let a=0;a<l;a++){let n=e+a,l=t[a];if(!h&&!Number.isFinite(l))continue;let o=s[n];(l>o||!s.allValid&&Number.isNaN(o))&&(s[n]=l);let u=i[n];(l<u||!i.allValid&&Number.isNaN(u))&&(i[n]=l);let c=r[n];0===this.processTimes||Number.isNaN(c)?r[n]=l:r[n]=c+(l-c)/(this.processTimes+1)}}updateFluorescenceStats(t,e){if(!this.config.processing.enableFluorescence||!this.fluorescenceData||!Number.isFinite(e))return;let a=Math.round(e);if(a<n.LEVEL_MIN||a>n.LEVEL_MAX)return;let s=t*n.LEVEL_RANGE+(a-n.LEVEL_MIN),i=++this.fluorescenceData[s];i>this.fluorescenceMaxCount&&(this.fluorescenceMaxCount=i)}setPendingFlag(t,e){this.pendingDataFlags[t]=e,this.hasPendingData=this.pendingDataFlags.occupancy||this.pendingDataFlags.template||this.pendingDataFlags.backgroundNoise||this.pendingDataFlags.threshold||this.pendingDataFlags.extra}resampleSingleData(t){let{srcIndexCache:e}=this,{outputRange:{start:a,end:s}}=this.config,i=t.subarray(a,s),r=e.length,n=new Float32Array(r);for(let t=0;t<r;t++)n[t]=i[e[t]];return n}processPendingData(){if(!this.hasPendingData)return null;let t={};if(this.pendingDataFlags.occupancy&&this.occupancyData.length>0&&(t.occupancyData=this.resampleDataSeries().occupancyData,this.setPendingFlag("occupancy",!1)),this.pendingDataFlags.template&&this.templateData.length>0&&(t.templateData=this.resampleSingleData(this.templateData),t.templateOverData=this.updateTemplateOverData(!0),this.setPendingFlag("template",!1)),this.pendingDataFlags.backgroundNoise&&this.backgroundNoiseData.length>0&&(t.backgroundNoiseData=this.resampleSingleData(this.backgroundNoiseData),this.setPendingFlag("backgroundNoise",!1)),this.pendingDataFlags.threshold&&this.thresholdData.length>0){let e=this.resampleSingleData(this.thresholdData);this.thresholdOutputData=e,t.thresholdData=e,this.setPendingFlag("threshold",!1)}return this.pendingDataFlags.extra&&Object.keys(this.extraData).length>0&&(this.extraOutputData=x(this.extraData,this.antennaFactorData,this.antennaFactorSwitch,this.srcIndexCache,this.getOutputData.bind(this)),t.extraData=this.extraOutputData,this.setPendingFlag("extra",!1)),t}notifySpectrumUpdate(t){if(this.onSpectrumUpdate){if(!Object.hasOwn(t,"waterfallData"))return void this.onSpectrumUpdate(t);if(this.waterfallSink){delete t.waterfallData,this.onSpectrumUpdate(t);return}t.waterfallData=this.getOrderedWaterfallData(this.waterfallOutputData),this.onSpectrumUpdate(t)}}calculateMemoryUsage(){return 4*(this.config.maxPoints*Float32Array.BYTES_PER_ELEMENT)+this.waterfallData.reduce((t,e)=>t+e.length*Float32Array.BYTES_PER_ELEMENT,0)+this.waterfallOutputData.reduce((t,e)=>t+e.length*Float32Array.BYTES_PER_ELEMENT,0)}getOutputData(t){let{outputRange:{start:e,end:a}}=this.config,s=t??this.realData,i=s.subarray(e,a);return i.timestamp=s.timestamp,i}getFluorescenceOutputData(t){let{processing:{enableFluorescence:e},outputRange:{start:a,end:s}}=this.config;if(!e||0===this.fluorescenceData.length||t<=0)return;let i=new Uint32Array(t*n.LEVEL_RANGE),r=(s-a)/t;for(let e=0;e<t;e++){let t=Math.floor(a+(e+.5)*r)*n.LEVEL_RANGE,s=e*n.LEVEL_RANGE;for(let e=0;e<n.LEVEL_RANGE;e++)i[s+e]=this.fluorescenceData[t+e]}return i}getAllRawData(t){let{realOutputData:e,maxOutputData:a,minOutputData:s,avgOutputData:i,templateOutputData:r,occupancyOutputData:n,backgroundNoiseOutputData:l,thresholdOutputData:h,waterfallOutputData:o,extraOutputData:u,srcIndexCache:c}=this;e.timestamp=this.realData.timestamp;let p={realData:this.realData,maxData:this.maxData,minData:this.minData,avgData:this.avgData,templateData:this.templateData,occupancyData:this.occupancyData,backgroundNoiseData:this.backgroundNoiseData,thresholdData:this.thresholdData,waterfallData:this.getOrderedWaterfallData(this.waterfallData),extraData:this.extraData},g=D(t,e.length,this.config.maxPoints);return{realData:e,maxData:a,minData:s,avgData:i,templateData:r,occupancyData:n,backgroundNoiseData:l,thresholdData:h,fluorescenceData:this.getFluorescenceOutputData(e.length),waterfallData:this.getOrderedWaterfallData(o),extraData:u,srcIndexCache:c,rawData:p,cursorIndex:g}}}let O=()=>({data:[],rawData:[],range:{x:[0,0],y:[0,0]},sourceSize:{width:0,height:0},columnIndices:new Uint32Array(0),rowIndices:new Uint32Array(0)}),I=t=>{let e=new Float32Array(t);return e.timestamp=t.timestamp,void 0!==t.allValid&&(e.allValid=t.allValid),t.peaks&&(e.peaks={...t.peaks,peaks:t.peaks.peaks.map(t=>({...t}))}),e},N=(t,e)=>{if(!Number.isInteger(t)||t<=0)throw new u(`${e} 必须是正整数`)},M=(t,e,a)=>{let[s,i]=t;if(!Number.isFinite(s)||!Number.isFinite(i)||s>=i)throw new u(`${a} 采样范围无效`);let r=Math.max(0,Math.min(e,Math.floor(s))),n=Math.max(0,Math.min(e,Math.ceil(i)));if(r>=n)throw new u(`${a} 采样范围超出数据边界`);return[r,n]},P=(t,e,a)=>{if(0===t[0]&&t[1]===e)return[0,a];let s=Math.min(t[0],a-1),i=Math.max(s+1,Math.min(t[1],a));return[s,i]},T=(t,e,a)=>{if(0===t[0]&&t[1]===e)return[0,a];if(t[1]===e){let e=Math.min(t[1]-t[0],a);return[a-e,a]}return P(t,e,a)},v=(t,e,a,s)=>{if(0===t[0]&&t[1]===e)return[0,a];let i=Math.min(t[1]-t[0],a);if(t[1]===e)return[a-i,a];let r=Math.max(0,Math.min(t[0]-s,a-i));return[r,r+i]},L=(t,e)=>{let[a,s]=t,i=s-a,r=Math.min(i,e),n=new Uint32Array(r);if(i<=e){for(let t=0;t<r;t++)n[t]=a+t;return n}for(let t=0;t<r;t++){let e=Math.floor(t*i/r),s=Math.floor((t+1)*i/r);n[t]=a+Math.min(s-1,Math.floor((e+s)/2))}return n},_=(t,e)=>t[0]===e[0]&&t[1]===e[1],U=(t,e)=>{if(t.length!==e.length)return!1;for(let a=0;a<t.length;a++)if(t[a]!==e[a])return!1;return!0},R=(t,e,a)=>{let s=t.subarray(e[0],e[1]),i=s.length,r=Math.min(i,a);if(i<=a)return 0===e[0]&&e[1]===t.length?t:(s.timestamp=t.timestamp,s);let n=new Float32Array(r);n.timestamp=t.timestamp;for(let t=0;t<r;t++){let e=Math.floor(t*i/r),a=Math.floor((t+1)*i/r),l=0/0;for(let t=e;t<a;t++){let e=s[t];Number.isFinite(e)&&(!Number.isFinite(l)||e>l)&&(l=e)}n[t]=l}return n};class k{maxFrames;onWaterfallUpdate;sourceData=[];samplingOptions;snapshot=O();constructor(t={}){if(void 0!==t.maxFrames&&(!Number.isInteger(t.maxFrames)||t.maxFrames<=0))throw new u("maxFrames 必须是正整数");this.maxFrames=t.maxFrames,this.onWaterfallUpdate=t.onWaterfallUpdate}setData(t){if(0===t.length)return this.sourceData=[],this.samplingOptions=void 0,this.publishSnapshot(O());let e=t[0].length;if(0===e)throw new u("瀑布图帧不能为空");for(let a of t)if(a.length!==e)throw new u("瀑布图数据必须是等宽矩阵");let a=this.snapshot.sourceSize,s=[...t];void 0!==this.maxFrames&&s.length>this.maxFrames&&(s=s.slice(-this.maxFrames));let i=this.samplingOptions;i&&a.width>0&&a.height>0&&(i={...i,x:P(i.x,a.width,e),y:T(i.y,a.height,s.length)});let r=this.createSnapshot(s,i);return this.sourceData=s,this.samplingOptions=i,this.publishSnapshot(r)}appendFrame(t){if(0===t.length)throw new u("瀑布图帧不能为空");let e=this.sourceData[0]?.length;if(void 0!==e&&t.length!==e)throw new u("追加帧宽度必须与现有瀑布图一致");let a=this.sourceData.length,s=[...this.sourceData,I(t)],i=0;void 0!==this.maxFrames&&s.length>this.maxFrames&&(i=s.length-this.maxFrames,s.splice(0,i));let r=this.samplingOptions;r&&a>0&&(r={...r,y:v(r.y,a,s.length,i)});let n=this.createSnapshot(s,r);return this.sourceData=s,this.samplingOptions=r,this.publishSnapshot(n)}updateSamplingRange(t){let e=this.getSourceSize(this.sourceData);if(0===e.width||0===e.height)throw new u("设置采样范围前必须先设置瀑布图数据");N(t.outputWidth,"outputWidth"),N(t.outputHeight,"outputHeight");let a={x:M(t.x,e.width,"X"),y:M(t.y,e.height,"Y"),outputWidth:t.outputWidth,outputHeight:t.outputHeight},s=this.createSnapshot(this.sourceData,a);return this.samplingOptions=a,this.publishSnapshot(s)}getSnapshot(){return this.snapshot}createSnapshot(t,e){let a=this.getSourceSize(t);if(0===a.width||0===a.height)return O();let s=e?.x??[0,a.width],i=e?.y??[0,a.height],r=e?.outputWidth??s[1]-s[0],n=e?.outputHeight??i[1]-i[0],l=L(s,r),h=L(i,n),o=this.createReusableRows(s,l);return{data:Array.from(h,e=>{let a=t[e];return o.get(a)??R(a,s,r)}),rawData:t,range:{x:s,y:i},sourceSize:a,columnIndices:l,rowIndices:h}}createReusableRows(t,e){let a=this.snapshot;if(!_(a.range.x,t)||!U(a.columnIndices,e))return new Map;let s=new Map;for(let t=0;t<a.rowIndices.length;t++){let e=a.rawData[a.rowIndices[t]],i=a.data[t];e&&i&&s.set(e,i)}return s}getSourceSize(t){return{width:t[0]?.length??0,height:t.length}}publishSnapshot(t){return this.snapshot=t,this.onWaterfallUpdate?.(t),t}}var C=/*#__PURE__*/function(t){return t.Horizontal="horizontal",t.Vertical="vertical",t}({}),V=/*#__PURE__*/function(t){return t.Circle="circle",t.Rect="rect",t.Line="line",t.Stepline="stepline",t.Bar="bar",t.Area="area",t}({}),W=/*#__PURE__*/function(t){return t.PropertyChanged="propertyChanged",t.SeriesAdded="seriesAdded",t.SeriesRemoved="seriesRemoved",t.SeriesCleared="seriesCleared",t}({});let G={thickness:1,orientation:C.Horizontal,display:!0,type:V.Line,color:"#00000000",label:""};class H{seriesMap=new Map;changeCallbacks=[];subscribers=new Map;constructor(t=[]){this.initializeSeries(t)}initializeSeries(t){for(let e of t)this.addSeries(e)}addSeries(t){let e={...G,...t};this.seriesMap.set(t.name,e),this.emitEvent({type:W.SeriesAdded,name:t.name,series:e})}getSeries(t){return this.seriesMap.get(t)}getAllSeries(){return Array.from(this.seriesMap.values())}getAllConfigs(){let t={};for(let[e,a]of this.seriesMap)t[e]={...a};return t}setSeriesProperty(t,e,a){let s=this.seriesMap.get(t);if(!s||"name"===e)return!1;let i=s[e],r={...s,[e]:a};return this.seriesMap.set(t,r),this.notifyChange(t,e,a),this.emitEvent({type:W.PropertyChanged,name:t,property:e,value:a,oldValue:i,series:r}),!0}removeSeries(t){let e=this.seriesMap.get(t);if(!e)return!1;let a=this.seriesMap.delete(t);return a&&this.emitEvent({type:W.SeriesRemoved,name:t,series:e}),a}hasSeries(t){return this.seriesMap.has(t)}onChange(t){this.changeCallbacks.push(t)}offChange(t){let e=this.changeCallbacks.indexOf(t);e>-1&&this.changeCallbacks.splice(e,1)}notifyChange(t,e,a){for(let s of this.changeCallbacks)s(t,e,a)}clear(){this.seriesMap.clear(),this.emitEvent({type:W.SeriesCleared})}size(){return this.seriesMap.size}subscribe(t,e={}){if(this.subscribers.set(t,e),e.immediate)for(let e of this.seriesMap.values())this.shouldNotifySubscriber(t,{type:W.SeriesAdded,name:e.name,series:e})&&t({type:W.SeriesAdded,name:e.name,series:e});return()=>{this.subscribers.delete(t)}}unsubscribe(t){this.subscribers.delete(t)}emitEvent(t){for(let[e]of this.subscribers)this.shouldNotifySubscriber(e,t)&&e(t)}shouldNotifySubscriber(t,e){let a=this.subscribers.get(t);return!!a&&(!a.eventTypes||!!a.eventTypes.includes(e.type))&&(!a.seriesNames||!e.name||!!a.seriesNames.includes(e.name))}}export{u as DataValidationError,h as ERROR_MESSAGES,c as IndexOutOfBoundsError,a as LevelStreamAnalyzer,s as SPECTRUM,H as SeriesManager,E as SpectrumAnalyzer,o as SpectrumError,k as WaterfallAnalyzer,S as ExtraDataMode,V as GraphicType,C as OrientationType,W as SeriesEventType};
1
+ let t={DEFAULT_CACHE_TIME:15e3,DEFAULT_GRANULARITY:10,DEFAULT_RANGE:[-20,100]},e={cacheTime:t.DEFAULT_CACHE_TIME,granularity:t.DEFAULT_GRANULARITY,range:t.DEFAULT_RANGE,maxPoints:void 0,onLevelStreamUpdate:t=>{}};class a{config;spectrumData=[];probabilityData=new Map;count=0;constructor(t){this.config={...e,...t}}reset(){this.spectrumData=[],this.probabilityData=new Map,this.count=0}setConfig(t){let a=void 0!==t.cacheTime&&this.config.cacheTime!==t.cacheTime||void 0!==t.granularity&&this.config.granularity!==t.granularity||void 0!==t.maxPoints&&this.config.maxPoints!==t.maxPoints;this.config={...e,...this.config,...t},a&&this.reset(),t.range&&this.outputData()}process(t,e){this.removeExpiredData(),this.addNewData(t,e),this.updateProbability(t),this.outputData()}updateProbability(t){let{granularity:e}=this.config;this.count++;let a=Math.round(t/e)*e,s=this.probabilityData.get(a)||0;s++,this.probabilityData.set(a,s)}getAll(){return this.probabilityData}removeExpiredData(){let{cacheTime:t,maxPoints:e}=this.config;if(0===this.spectrumData.length)return;if(void 0!==e&&e>0){this.spectrumData.length>e&&(this.spectrumData=this.spectrumData.slice(-e));return}let a=Date.now();if(t<=0){this.spectrumData=[];return}let s=0,i=this.spectrumData.length-1;for(;s<=i;){let e=Math.floor((s+i)/2);a-this.spectrumData[e].timestamp>=t?s=e+1:i=e-1}this.spectrumData=this.spectrumData.slice(s)}addNewData(t,e){this.spectrumData.push({value:t,timestamp:e})}outputData(){let{range:t,granularity:e,onLevelStreamUpdate:a}=this.config,s=t[0],i=t[1],r=Array(Math.round((i-s)/e)+1).fill(0);for(let[t,a]of this.probabilityData)if(t>=s&&t<=i){let s=Math.round((i-t)/e);this.count>0&&(r[s]=a/this.count*100)}a?.({probabilityRangeData:new Float32Array(r),spectrumData:new Float32Array(this.spectrumData.map(t=>t.value)),timestampData:new Float64Array(this.spectrumData.map(t=>t.timestamp))})}}let s={INITIAL_VALUE:0/0,WATERFALL_MAX_FRAMES:100,OUTPUT_POINTS:1001},i={MAX_PEAKS:2},r=null,n={UPDATE_INTERVAL:1,LEVEL_MIN:-20,LEVEL_MAX:140,LEVEL_RANGE:161},l={maxPoints:s.OUTPUT_POINTS,waterfallMaxFrames:s.WATERFALL_MAX_FRAMES,initialValue:s.INITIAL_VALUE,processing:{enableWaterfall:!1,enableMetrics:!1,enableFluorescence:!1,enablePeakStats:!1,fluorescenceUpdateInterval:n.UPDATE_INTERVAL},peakDetection:{maxPeaks:i.MAX_PEAKS},outputPoints:s.OUTPUT_POINTS,outputRange:{start:0,end:s.OUTPUT_POINTS},templateTolerance:0},h={EMPTY_SEGMENTS:"频段配置不能为空",INVALID_CONFIG:"必须且只能配置 segments 或 bandwidthConfig 其中之一",EMPTY_BANDWIDTH:"bandwidthConfig 不能为空",INVALID_SEGMENT:t=>`无效的段索引: ${t}`,INDEX_OUT_OF_BOUNDS:t=>`索引超出范围: ${t}`,INVALID_ANTENNA_FACTOR_LENGTH:t=>`天线因子数据长度必须等于实时数据长度 (${t})`,INVALID_ANTENNA_FACTOR:"天线因子数据必须是有效的正数",INVALID_SAMPLING_RANGE:"采样范围无效",INVALID_MAX_POINTS:"点数必须大于0",INVALID_LENGTH:t=>`频率占用度数据长度不匹配,期望长度为 ${t}`};class o extends Error{code;details;constructor(t,e,a){super(t),this.code=e,this.details=a,this.name="SpectrumError"}}class u extends o{constructor(t,e){super(t,"DATA_VALIDATION_ERROR",e)}}class c extends o{index;constructor(t,e,a){super(t,"INDEX_OUT_OF_BOUNDS_ERROR",{index:e,...a||{}}),this.index=e}}let p=(t,e)=>{void 0!==t.max&&(e.max=t.max),void 0!==t.maxIndex&&(e.maxIndex=t.maxIndex),void 0!==t.timestamp&&(e.timestamp=t.timestamp),void 0!==t.progress&&(e.progress=t.progress)},g=(t,e,a)=>t<=e?e:t>=a?a:t,f=(t,e)=>e<=1?0:Math.max(0,Math.min(e-1,Math.ceil(e*g(t,0,100)/100)-1)),D=(t,e,a)=>{if(!Number.isFinite(t)||e<=0||a<=0)return;let s=g(Number(t),0,100);return{left:s,sampledIndex:f(s,e),globalIndex:f(s,a)}},m=({realData:t,antennaFactorData:e,antennaFactorSwitch:a=!1,outputPoints:s})=>{let i=t.length,r=i<=s,n=r?i:s,l=new Uint32Array(n),h=new Float32Array(n);if(h.timestamp=t.timestamp,r){if(!a){for(let t=0;t<i;t++)l[t]=t;return h.set(t),{realOutputData:h,srcIndexCache:l}}for(let a=0;a<i;a++)l[a]=a,h[a]=t[a]+e[a];return{realOutputData:h,srcIndexCache:l}}let o=i/s,u=o/2;for(let s=0;s<n;s++){let r=Math.floor(u),n=Math.min(Math.floor(u+o),i),c=t[r],p=r;for(let e=r+1;e<n;e++)t[e]>c&&(c=t[e],p=e);h[s]=a?c+e[p]:c,l[s]=p,u+=o}return{realOutputData:h,srcIndexCache:l}},d=({antennaFactorData:t,antennaFactorSwitch:e=!1,outputPoints:a,realData:s,maxData:i,minData:r,avgData:n,templateData:l,backgroundNoiseData:h,thresholdData:o,fluorescenceData:u,occupancyData:c,enablePeakStats:p=!1,maxPeaks:g=2,outputRangeStart:f=0})=>{let D=s.length,m=D<=a,d=m?D:a,x=i&&i.length>0,A=r&&r.length>0,w=n&&n.length>0,y=l&&l.length>0,F=c&&c.length>0,S=h&&h.length>0,b=o&&o.length>0,E=u&&u.length>0,O=[],I=e?(e,a)=>e+t[a]:t=>t,N=new Float32Array(d);N.timestamp=s.timestamp;let M=new Float32Array(x?d:0),P=new Float32Array(A?d:0),T=new Float32Array(w?d:0),v=new Float32Array(y?d:0),L=new Float32Array(F?d:0),_=new Float32Array(S?d:0),U=new Float32Array(b?d:0),R=Array(E?d:0).fill(null),k=new Uint32Array(d);if(m){for(let t=0;t<D;t++)k[t]=t;if(e)for(let e=0;e<D;e++){let a=t[e];if(N[e]=s[e]+a,x&&(M[e]=i[e]+a),A&&(P[e]=r[e]+a),w&&(T[e]=n[e]+a),y&&(v[e]=l[e]+a),F&&(L[e]=c[e]),S&&(_[e]=h[e]+a),b&&(U[e]=o[e]+a),E){let t=u[e],s=new Map;for(let[e,i]of t)s.set(e+a,i);R[e]=s}}else N.set(s),x&&M.set(i),A&&P.set(r),w&&T.set(n),y&&v.set(l),F&&L.set(c),S&&_.set(h),b&&U.set(o),E&&(R=u);if(p)for(let t=0;t<D;t++){let e=N[t];Number.isFinite(e)&&O.push({index:t,srcIndex:t+f,value:e})}}else{let t=D/a,e=t/2;for(let a=0;a<d;a++){let g=Math.floor(e),m=Math.min(Math.floor(e+t),D),d=s[g],C=g,V=x?i[g]:0,W=g,G=A?r[g]:0,H=g,B=F?c[g]:0;for(let t=g+1;t<m;t++)s[t]>d&&(d=s[t],C=t),x&&i[t]>V&&(V=i[t],W=t),A&&r[t]<G&&(G=r[t],H=t),F&&c[t]>B&&(B=c[t]);let z=I(d,C);if(N[a]=z,k[a]=C,p&&Number.isFinite(z)&&O.push({index:a,srcIndex:C+f,value:z}),x&&(M[a]=I(V,W)),A&&(P[a]=I(G,H)),w){let t=n[C];T[a]=I(t,C)}if(y){let t=l[C];v[a]=I(t,C)}if(F&&(L[a]=B),S){let t=h[C];_[a]=I(t,C)}if(b){let t=o[C];U[a]=I(t,C)}if(E){let t=u[C],e=new Map;for(let[a,s]of t)e.set(I(a,C),s);R[a]=e}e+=t}}return p&&O.length>0&&(O.sort((t,e)=>e.value-t.value),N.peaks={peaks:O.slice(0,g),timestamp:s.timestamp}),{realOutputData:N,maxOutputData:M,minOutputData:P,avgOutputData:T,templateOutputData:v,occupancyOutputData:L,backgroundNoiseOutputData:_,thresholdOutputData:U,srcIndexCache:k,fluorescenceOutputData:R}},x=(t,e,a,s,i)=>{if(!t||0===Object.keys(t).length)return{};let r={},n=Object.keys(t),l=s.length;for(let t=0;t<n.length;t++)r[n[t]]=new Float32Array(l);for(let h=0;h<n.length;h++){let o=n[h],u=i(t[o]),c=r[o];if(a)for(let t=0;t<l;t++){let a=s[t];c[t]=u[a]+e[a]}else for(let t=0;t<l;t++){let e=s[t];c[t]=u[e]}}return r},A=({realData:t,maxData:e,minData:a,templateData:s,tolerance:i=0,startIndex:r=0,endIndex:n,usePreallocation:l=!1})=>{let{timestamp:h}=t,o=n??t.length,u=[],c=-1,p=0,g=0;if(l&&0===r&&o===t.length){let r=new Uint8Array(t.length);for(let e=0;e<t.length;e++)r[e]=+(t[e]>s[e]+i);for(let s=0;s<t.length;s++)if(r[s])-1===c?(c=s,p=t[s],g=1):(p+=t[s],g++);else if(-1!==c){let t=s-1;if(t-c+1>=2){let s=p/g,i=c+(t-c>>1);u.push({maxValue:e[i],minValue:a[i],avgValue:s,timestamp:h,startIndex:c,endIndex:t})}c=-1}}else for(let n=r;n<Math.min(o,t.length);n++)if(t[n]>s[n]+i)-1===c?(c=n,p=t[n],g=1):(p+=t[n],g++);else if(-1!==c){let t=n-1;if(t-c+1>=2){let s=p/g,i=c+(t-c>>1);u.push({maxValue:e[i],minValue:a[i],avgValue:s,timestamp:h,startIndex:c,endIndex:t})}c=-1}if(-1!==c){let t=o-1;if(t-c+1>=2){let s=p/g,i=c+(t-c>>1);u.push({maxValue:e[i],minValue:a[i],avgValue:s,timestamp:h,startIndex:c,endIndex:t})}}return u},w=({realData:t,maxData:e,minData:a,templateData:s,tolerance:i=0})=>s&&0!==s.length?A({realData:t,maxData:e,minData:a,templateData:s,tolerance:i,usePreallocation:!0}):[],y=({realData:t,maxData:e,minData:a,templateData:s,tolerance:i=0,startIndex:r,endIndex:n,previousSegments:l=[]})=>!s||0===s.length||r>=n?l:[...l,...A({realData:t,maxData:e,minData:a,templateData:s,tolerance:i,startIndex:r,endIndex:n})];function F(t){for(let e=0;e<t.length;e++)if(!Number.isFinite(t[e]))return!1;return!0}var S=/*#__PURE__*/function(t){return t.REPLACE="replace",t.MERGE="merge",t.CLEAR="clear",t}({}),b=/*#__PURE__*/null;class E{config=l;segments=[];antennaFactorData;antennaFactorSwitch;realData;maxData;minData;avgData;templateData;occupancyData;backgroundNoiseData;thresholdData;waterfallData;srcIndexCache;realOutputData;maxOutputData;minOutputData;avgOutputData;templateOutputData;occupancyOutputData;backgroundNoiseOutputData;thresholdOutputData;waterfallOutputData;scanProgress;lastIndex;processTimes;lastProcessTime;cachedExceedingDatas=[];waterfallHead=0;waterfallCount=0;waterfallSink;fluorescenceData;fluorescenceMaxCount=0;fluorescenceUpdateCounter=0;extraData={};extraOutputData={};pendingDataFlags={occupancy:!1,template:!1,backgroundNoise:!1,threshold:!1,extra:!1};hasPendingData=!1;hasProcessedData=!1;isProcessing=!1;onSpectrumUpdate;constructor(t){let{onSpectrumUpdate:e,maxPoints:a}=t;this.onSpectrumUpdate=e,this.config={...l,...t,processing:{...l.processing,...t.processing},peakDetection:{...l.peakDetection,...t.peakDetection},outputRange:{start:t.outputRange?.start??0,end:t.outputRange?.end??a??s.OUTPUT_POINTS}},this.reset()}setWaterfallSink(t){let e=void 0!==this.waterfallSink;if(this.waterfallSink=t??void 0,!t||((e||this.waterfallCount>0)&&t.reset(),!this.config.processing.enableWaterfall||0===this.waterfallCount))return;let a=this.getOrderedWaterfallData(this.waterfallOutputData);t.replace(a,this.config.waterfallMaxFrames)}getWaterfallTimestamps(t){let e=Number.isFinite(t)?Math.max(0,Math.floor(t)):0,a=this.waterfallOutputData.length;if(0===e||0===a)return[];let s=Array(e),i=a-1,r=Math.max(1,e-1);for(let t=0;t<e;t++){let a=1===e?i:Math.floor(i*t/r);s[t]=this.getWaterfallFrameAt(this.waterfallOutputData,a)?.timestamp}return s}process({data:t,timestamp:e,segmentOffset:a=0,offset:s=0,fluorescenceData:i,fluorescenceMaxCount:r}){let n=performance.now();try{if(!t?.length)return;this.isProcessing=!0,this.hasProcessedData=!0;let n=this.resolveGlobalIndex(a,s);this.segments.length?this.scanProgress=(n+t.length)/this.config.maxPoints:t.length!==this.config.maxPoints&&this.updateMaxPoints(t.length),i&&void 0!==r&&(this.fluorescenceData=i,this.fluorescenceMaxCount=r),this.validateInput(t,n);let{maxPoints:l}=this.config,h=n+t.length;this.lastIndex=h;let o=h>=l||h<this.lastIndex;this.realData.set(t,n),this.realData.timestamp=e,this.processDataPoints(t,n,o);let u=this.resampleDataSeries();o&&u.realData&&this.updateWaterfallData(this.realData,u.realData);let c=this.updateTemplateOverData(o,o?void 0:{startIndex:n,endIndex:n+t.length}),p=this.processPendingData();this.notifySpectrumUpdate({...u,...p||{},extraData:this.extraOutputData,waterfallData:this.waterfallOutputData,scanProgress:this.scanProgress,processTimes:this.processTimes,...c&&{templateOverData:c}})}catch(t){throw t instanceof Error?t:Error(String(t))}finally{this.isProcessing=!1,this.lastProcessTime=performance.now()-n}}initializeSegments(t){if(!t?.length)throw new u(h.EMPTY_SEGMENTS);let e=this.config.maxPoints,a=0;this.segments=t.map(t=>{let{startFrequency:e,stopFrequency:s,stepFrequency:i}=t,r=Math.round(1e3*(s-e)/i)+1,n=a;return a+=r,{startFrequency:e,stopFrequency:s,stepFrequency:i,pointCount:r,startIndex:n}}),this.updateMaxPoints(a,!1),e===a&&(this.config={...this.config,outputRange:{start:0,end:a}},this.reset(!1))}setAntennaFactor(t){let{antennaFactorData:e,config:{maxPoints:a}}=this,s=new Float32Array(t);s.length!==a&&(s=new Float32Array(s).subarray(0,a),console.warn(h.INVALID_ANTENNA_FACTOR_LENGTH(a)));let i=!1;for(let t=0;t<s.length;t++){let a=s[t],r=Number.isFinite(a)&&a>0;r||(i=!0),e[t]=r?a:0}i&&console.warn(h.INVALID_ANTENNA_FACTOR),this.antennaFactorSwitch&&this.setAntennaFactorSwitch(this.antennaFactorSwitch)}setAntennaFactorSwitch(t){let e=this.antennaFactorSwitch!==t;if(this.antennaFactorSwitch=t,e){let t=this.resampleDataSeries();this.resampleWaterfallOutputData(),this.notifyWaterfallReplace(),this.notifySpectrumUpdate({...t,waterfallData:this.waterfallOutputData})}}updateProcessing(t){let{processing:e}=this.config,a={...e,...void 0!==t.enableMetrics&&{enableMetrics:t.enableMetrics},...void 0!==t.enableFluorescence&&{enableFluorescence:t.enableFluorescence},...void 0!==t.enablePeakStats&&{enablePeakStats:t.enablePeakStats},...void 0!==t.fluorescenceUpdateInterval&&{fluorescenceUpdateInterval:t.fluorescenceUpdateInterval}};if(a.enableMetrics===e.enableMetrics&&a.enableFluorescence===e.enableFluorescence&&a.enablePeakStats===e.enablePeakStats&&a.fluorescenceUpdateInterval===e.fluorescenceUpdateInterval)return;this.config={...this.config,processing:a},a.enableMetrics&&!e.enableMetrics&&(0===this.maxData.length||0===this.minData.length||0===this.avgData.length)&&(this.allocateMetricsBuffers(),this.clearMetricsBuffers()),a.enableFluorescence&&!e.enableFluorescence&&0===this.fluorescenceData.length&&(this.fluorescenceData=new Uint32Array(this.config.maxPoints*n.LEVEL_RANGE));let s=this.resampleDataSeries();this.extraOutputData=x(this.extraData,this.antennaFactorData,this.antennaFactorSwitch,this.srcIndexCache,this.getOutputData.bind(this)),this.notifySpectrumUpdate({...s,extraData:this.extraOutputData})}clearMetricsData(){let t=0===this.maxData.length||0===this.minData.length||0===this.avgData.length||0===this.maxOutputData.length||0===this.minOutputData.length||0===this.avgOutputData.length;if(this.config.processing.enableMetrics&&t){let t=this.realOutputData?.length??this.config.outputPoints;this.allocateMetricsBuffers(t)}this.clearMetricsBuffers(),this.processTimes=0,this.notifySpectrumUpdate({maxData:this.maxOutputData,minData:this.minOutputData,avgData:this.avgOutputData,processTimes:0})}allocateMetricsBuffers(t){let{maxPoints:e,outputPoints:a,processing:{enableMetrics:s}}=this.config,i=s?e:0,r=0;s&&(r=Math.min(r=Math.max(0,Math.floor(t??a)),a)),this.maxData=new Float32Array(i),this.minData=new Float32Array(i),this.avgData=new Float32Array(i),this.maxOutputData=new Float32Array(r),this.minOutputData=new Float32Array(r),this.avgOutputData=new Float32Array(r)}clearMetricsBuffers(){this.maxData.fill(s.INITIAL_VALUE),this.minData.fill(s.INITIAL_VALUE),this.avgData.fill(s.INITIAL_VALUE),this.maxData.allValid=!1,this.minData.allValid=!1,this.avgData.allValid=!1,this.maxOutputData.fill(s.INITIAL_VALUE),this.minOutputData.fill(s.INITIAL_VALUE),this.avgOutputData.fill(s.INITIAL_VALUE)}setWaterfallData(t){if(!(t?.[0]?.length>0))return;let{processing:e}=this.config,{waterfallMaxFrames:a}=this.config;e.enableWaterfall&&(a=t.length,this.config={...this.config,waterfallMaxFrames:a},this.waterfallData=t.slice(),this.waterfallHead=0,this.waterfallCount=this.waterfallData.length,this.resampleWaterfallOutputData(),this.notifyWaterfallReplace(),this.notifySpectrumUpdate({waterfallData:this.waterfallOutputData}))}setFluorescenceData(t,e){if(!this.config.processing.enableFluorescence||!t||0===t.length)return;let a=this.config.maxPoints*n.LEVEL_RANGE;if(t.length!==a)return;this.fluorescenceData=t,this.fluorescenceMaxCount=e;let s=this.config.outputRange.end-this.config.outputRange.start,i=this.realOutputData.length||Math.min(this.config.outputPoints,s),r=this.getFluorescenceOutputData(i);this.notifySpectrumUpdate({fluorescenceData:r,fluorescenceMaxCount:this.fluorescenceMaxCount})}setRealData(t){if(!(t?.length>0)||t.length!==this.config.maxPoints)return;let e=new Float32Array(t.length);e.set(t),e.timestamp=t.timestamp,this.realData=e;let a=this.resampleDataSeries();this.notifySpectrumUpdate(a)}setMaxData(t){if(!(t?.length>0)||t.length!==this.config.maxPoints)return;let e=new Float32Array(t.length);e.set(t),this.maxData=e,this.maxData.allValid=F(this.maxData);let a=this.resampleDataSeries();this.notifySpectrumUpdate(a)}setMinData(t){if(!(t?.length>0)||t.length!==this.config.maxPoints)return;let e=new Float32Array(t.length);e.set(t),this.minData=e,this.minData.allValid=F(this.minData);let a=this.resampleDataSeries();this.notifySpectrumUpdate(a)}setAvgData(t){if(!(t?.length>0)||t.length!==this.config.maxPoints)return;let e=new Float32Array(t.length);e.set(t),this.avgData=e,this.avgData.allValid=F(this.avgData);let a=this.resampleDataSeries();this.notifySpectrumUpdate(a)}setOccupancyData(t){if(!t||0===t.length){this.occupancyData=new Float32Array(0),this.setPendingFlag("occupancy",!1);return}if(this.occupancyData=new Float32Array(t),!this.hasProcessedData||this.isProcessing)return void this.setPendingFlag("occupancy",!0);let e=this.resampleDataSeries();this.notifySpectrumUpdate({occupancyData:e.occupancyData}),this.setPendingFlag("occupancy",!1)}setExtraData(t,e=S.MERGE,a){if(e===S.CLEAR){this.extraData={},this.extraOutputData={},this.setPendingFlag("extra",!1);return}if(!t){e===S.REPLACE&&(this.extraData={},this.extraOutputData={},this.setPendingFlag("extra",!1));return}let i=Object.entries(t).map(([t,e])=>[t,e?.length?new Float32Array(e):null]),r=a?this.resolveGlobalIndex(a.segmentOffset??0,a.offset??0):0;if(a)for(let[,t]of i)t&&this.validateInput(t,r);for(let[t,n]of(e===S.REPLACE&&(this.extraData={},this.extraOutputData={},this.setPendingFlag("extra",!1)),i)){if(!n){delete this.extraData[t];continue}if(!a){this.extraData[t]=n;continue}let e=this.extraData[t];if(e?.length!==this.config.maxPoints){let a=new Float32Array(this.config.maxPoints);a.fill(s.INITIAL_VALUE),e?.length&&a.set(e.subarray(0,this.config.maxPoints)),e=a,this.extraData[t]=e}e.set(n,r)}!this.hasProcessedData||this.isProcessing?this.setPendingFlag("extra",!0):(this.extraOutputData=x(this.extraData,this.antennaFactorData,this.antennaFactorSwitch,this.srcIndexCache,this.getOutputData.bind(this)),this.notifySpectrumUpdate({extraData:this.extraOutputData}),this.setPendingFlag("extra",!1))}reset(t=!1){let{maxPoints:e,waterfallMaxFrames:a,processing:{enableFluorescence:i}}=this.config;this.antennaFactorData=new Float32Array(e);let r=new Float32Array(e);r.timestamp="",r.fill(s.INITIAL_VALUE),this.realData=r,this.allocateMetricsBuffers(),this.clearMetricsBuffers(),this.templateData=new Float32Array,this.occupancyData=new Float32Array,this.backgroundNoiseData=new Float32Array,this.clearThresholdDataState(),this.waterfallData=Array.from({length:a},()=>{let t=new Float32Array;return t.timestamp="",t.fill(s.INITIAL_VALUE),t}),this.waterfallOutputData=Array.from({length:a},()=>{let t=new Float32Array;return t.timestamp="",t.fill(s.INITIAL_VALUE),t}),this.waterfallHead=0,this.waterfallCount=0,this.waterfallSink?.reset();let l=this.config.outputPoints;this.realOutputData=new Float32Array(l).fill(s.INITIAL_VALUE),this.templateOutputData=new Float32Array,this.occupancyOutputData=new Float32Array,this.backgroundNoiseOutputData=new Float32Array,this.fluorescenceData=new Uint32Array(i?e*n.LEVEL_RANGE:0),this.fluorescenceMaxCount=0,this.fluorescenceUpdateCounter=0,this.extraData={},this.extraOutputData={},this.srcIndexCache=new Uint32Array(e),this.scanProgress=0,this.lastIndex=0,this.processTimes=0,this.lastProcessTime=0,this.cachedExceedingDatas=[],this.pendingDataFlags={occupancy:!1,template:!1,backgroundNoise:!1,threshold:!1,extra:!1},this.hasPendingData=!1,t||(this.hasProcessedData=!1),this.notifySpectrumUpdate({realData:this.realData,maxData:this.maxData,minData:this.minData,avgData:this.avgData,templateData:this.templateData,backgroundNoiseData:this.backgroundNoiseData,thresholdData:this.thresholdData,extraData:this.extraData,srcIndexCache:this.srcIndexCache,processTimes:0,scanProgress:0})}getPerformanceMetrics(){return{lastProcessTime:this.lastProcessTime,dataPoints:this.config.maxPoints,waterfallFrames:this.waterfallData.length,isInitialized:this.realData.length>0,memoryUsage:this.calculateMemoryUsage()}}getPeakStats(){if(!this.config.processing.enablePeakStats)return;let{realData:t}=this.resampleDataSeries();if(t)return t.peaks}updateSamplingRange(t,e){if(t<0||t>=e)throw new u(h.INVALID_SAMPLING_RANGE);this.config={...this.config,outputRange:{start:Math.floor(t),end:Math.ceil(e)}};let a=this.resampleDataSeries();return this.resampleWaterfallOutputData(),this.notifyWaterfallReplace(),this.extraOutputData=x(this.extraData,this.antennaFactorData,this.antennaFactorSwitch,this.srcIndexCache,this.getOutputData.bind(this)),this.notifySpectrumUpdate({...a,extraData:this.extraOutputData,waterfallData:this.waterfallOutputData}),this.srcIndexCache}setTemplateData(t,e){if(!t||0===t.length){this.templateData=new Float32Array(0),this.setPendingFlag("template",!1);return}(void 0!==e&&(this.config.templateTolerance=e),this.templateData=new Float32Array(t),!this.hasProcessedData||this.isProcessing)?this.setPendingFlag("template",!0):(this.notifySpectrumUpdate({templateData:this.resampleSingleData(this.templateData),templateOverData:this.updateTemplateOverData(!0)}),this.setPendingFlag("template",!1))}setBackgroundNoiseData(t){if(!t||0===t.length){this.backgroundNoiseData=new Float32Array(0),this.setPendingFlag("backgroundNoise",!1);return}(this.backgroundNoiseData=new Float32Array(t),!this.hasProcessedData||this.isProcessing)?this.setPendingFlag("backgroundNoise",!0):(this.notifySpectrumUpdate({backgroundNoiseData:this.resampleSingleData(this.backgroundNoiseData)}),this.setPendingFlag("backgroundNoise",!1))}setThresholdData(t,e){if(!t||0===t.length)return void this.clearThresholdDataState();let a=t instanceof Float32Array?t:new Float32Array(t);if(e){let t=this.resolveGlobalIndex(e.segmentOffset??0,e.offset??0);if(this.validateInput(a,t),this.thresholdData.length!==this.config.maxPoints){let t=new Float32Array(this.config.maxPoints);t.fill(s.INITIAL_VALUE),this.thresholdData.length>0&&t.set(this.thresholdData.subarray(0,this.config.maxPoints)),this.thresholdData=t}this.thresholdData.set(a,t)}else{let t=new Float32Array(this.config.maxPoints);t.fill(s.INITIAL_VALUE),t.set(a.subarray(0,this.config.maxPoints)),this.thresholdData=t}if(!this.hasProcessedData||this.isProcessing)return void this.setPendingFlag("threshold",!0);let i=this.resampleSingleData(this.thresholdData);this.thresholdOutputData=i,this.notifySpectrumUpdate({thresholdData:i}),this.setPendingFlag("threshold",!1)}updateTemplateOverData(t=!1,e){let a;return this.templateData&&0!==this.templateData.length?(t||!e?(a=w({realData:this.realData,maxData:this.maxData,minData:this.minData,templateData:this.templateData,tolerance:this.config.templateTolerance}),this.cachedExceedingDatas=a):(this.cachedExceedingDatas=y({realData:this.realData,maxData:this.maxData,minData:this.minData,templateData:this.templateData,tolerance:this.config.templateTolerance,startIndex:e.startIndex,endIndex:e.endIndex,previousSegments:this.cachedExceedingDatas}),a=this.cachedExceedingDatas),a):(this.cachedExceedingDatas=[],[])}resolveGlobalIndex(t=0,e=0){if(this.segments.length){let a=this.segments[t];if(!a)throw new u(h.INVALID_SEGMENT(t));return a.startIndex+e}return e}clearThresholdDataState(){this.thresholdData=new Float32Array(0),this.thresholdOutputData=new Float32Array(0),this.setPendingFlag("threshold",!1)}resampleDataSeries(){let{antennaFactorData:t,antennaFactorSwitch:e,maxData:a,minData:s,avgData:i,templateData:r,occupancyData:n,backgroundNoiseData:l,thresholdData:h,config:{maxPoints:o,outputPoints:u}}=this,{realOutputData:c,srcIndexCache:p,maxOutputData:g,minOutputData:f,avgOutputData:D,templateOutputData:m,occupancyOutputData:x,backgroundNoiseOutputData:A,thresholdOutputData:w}=d({antennaFactorData:e?t:new Float32Array(o),antennaFactorSwitch:e,outputPoints:u,realData:this.getOutputData(),maxData:a?.length>0?this.getOutputData(a):void 0,minData:s?.length>0?this.getOutputData(s):void 0,avgData:i&&i.length>0?this.getOutputData(i):void 0,templateData:r&&r.length>0?this.getOutputData(r):void 0,occupancyData:n&&n.length>0?this.getOutputData(n):void 0,backgroundNoiseData:l&&l.length>0?this.getOutputData(l):void 0,thresholdData:h&&h.length>0?this.getOutputData(h):void 0,enablePeakStats:this.config.processing.enablePeakStats,maxPeaks:this.config.peakDetection.maxPeaks,outputRangeStart:this.config.outputRange.start});this.srcIndexCache=p,this.realOutputData=c,this.maxOutputData=g||new Float32Array,this.minOutputData=f||new Float32Array,this.avgOutputData=D||new Float32Array,this.templateOutputData=m||new Float32Array,this.occupancyOutputData=x||new Float32Array,this.backgroundNoiseOutputData=A||new Float32Array,this.thresholdOutputData=w||new Float32Array;let y=this.getFluorescenceOutputData(c.length);return{realData:c,maxData:g,minData:f,avgData:D,templateData:m,occupancyData:x,backgroundNoiseData:A,thresholdData:w,fluorescenceData:y,fluorescenceMaxCount:this.fluorescenceMaxCount,extraData:this.extraOutputData,srcIndexCache:p}}resampleWaterfallOutputData(){let{antennaFactorData:t,antennaFactorSwitch:e,waterfallData:a,config:{maxPoints:s,processing:{enableWaterfall:i},outputPoints:r}}=this;if(!i)return;let n=e?t:new Float32Array(s);this.waterfallOutputData=a.map(t=>{let{realOutputData:a}=d({realData:this.getOutputData(t),antennaFactorData:n,antennaFactorSwitch:e,outputPoints:r});return a})}getOrderedWaterfallData(t){let e=t.length;if(0===e)return[];let a=Math.min(this.waterfallCount,e);if(0===a||a===e&&0===this.waterfallHead)return t;let s=e-a,i=Array(e);for(let r=0;r<s;r++){let s=(this.waterfallHead+a+r)%e;i[r]=t[s]}for(let r=0;r<a;r++){let a=(this.waterfallHead+r)%e;i[s+r]=t[a]}return i}getWaterfallFrameAt(t,e){let a=t.length,s=Math.min(this.waterfallCount,a),i=a-s;return t[e<i?(this.waterfallHead+s+e)%a:(this.waterfallHead+e-i)%a]}notifyWaterfallAppend(t){this.waterfallSink?.append(t,this.config.waterfallMaxFrames)}notifyWaterfallReplace(){if(!this.waterfallSink||0===this.waterfallCount)return;let t=this.getOrderedWaterfallData(this.waterfallOutputData);this.waterfallSink.replace(t,this.config.waterfallMaxFrames)}updateWaterfallData(t,e){let{waterfallMaxFrames:a,processing:s}=this.config;if(!s.enableWaterfall||a<=0)return;let i=new Float32Array(t.length);i.set(t),i.timestamp=t.timestamp;let r=this.waterfallCount<a?(this.waterfallHead+this.waterfallCount)%a:this.waterfallHead;this.waterfallData[r]=i,this.waterfallOutputData[r]=e,this.waterfallCount<a?this.waterfallCount+=1:this.waterfallHead=(this.waterfallHead+1)%a,this.notifyWaterfallAppend(e)}updateMaxPoints(t,e=!0){this.config.maxPoints!==t&&(this.config={...this.config,maxPoints:t,outputRange:{start:0,end:t}},this.reset(e))}validateInput(t,e){if(e<0||e+t.length>this.config.maxPoints)throw new c(h.INDEX_OUT_OF_BOUNDS(e),e)}processDataPoints(t,e,a){let{maxData:s,minData:i,avgData:r,config:{processing:{enableMetrics:n}}}=this;n&&a&&(this.processTimes+=1,s.allValid||(s.allValid=F(s)),i.allValid||(i.allValid=F(i)),r.allValid||(r.allValid=F(r)));let l=t.length;if(this.config.processing.enableFluorescence)for(let a=0;a<l;a++)this.updateFluorescenceStats(e+a,t[a]);if(!n)return;let h=!0;for(let e=0;e<l;e++)if(!Number.isFinite(t[e])){h=!1;break}for(let a=0;a<l;a++){let n=e+a,l=t[a];if(!h&&!Number.isFinite(l))continue;let o=s[n];(l>o||!s.allValid&&Number.isNaN(o))&&(s[n]=l);let u=i[n];(l<u||!i.allValid&&Number.isNaN(u))&&(i[n]=l);let c=r[n];0===this.processTimes||Number.isNaN(c)?r[n]=l:r[n]=c+(l-c)/(this.processTimes+1)}}updateFluorescenceStats(t,e){if(!this.config.processing.enableFluorescence||!this.fluorescenceData||!Number.isFinite(e))return;let a=Math.round(e);if(a<n.LEVEL_MIN||a>n.LEVEL_MAX)return;let s=t*n.LEVEL_RANGE+(a-n.LEVEL_MIN),i=++this.fluorescenceData[s];i>this.fluorescenceMaxCount&&(this.fluorescenceMaxCount=i)}setPendingFlag(t,e){this.pendingDataFlags[t]=e,this.hasPendingData=this.pendingDataFlags.occupancy||this.pendingDataFlags.template||this.pendingDataFlags.backgroundNoise||this.pendingDataFlags.threshold||this.pendingDataFlags.extra}resampleSingleData(t){let{srcIndexCache:e}=this,{outputRange:{start:a,end:s}}=this.config,i=t.subarray(a,s),r=e.length,n=new Float32Array(r);for(let t=0;t<r;t++)n[t]=i[e[t]];return n}processPendingData(){if(!this.hasPendingData)return null;let t={};if(this.pendingDataFlags.occupancy&&this.occupancyData.length>0&&(t.occupancyData=this.resampleDataSeries().occupancyData,this.setPendingFlag("occupancy",!1)),this.pendingDataFlags.template&&this.templateData.length>0&&(t.templateData=this.resampleSingleData(this.templateData),t.templateOverData=this.updateTemplateOverData(!0),this.setPendingFlag("template",!1)),this.pendingDataFlags.backgroundNoise&&this.backgroundNoiseData.length>0&&(t.backgroundNoiseData=this.resampleSingleData(this.backgroundNoiseData),this.setPendingFlag("backgroundNoise",!1)),this.pendingDataFlags.threshold&&this.thresholdData.length>0){let e=this.resampleSingleData(this.thresholdData);this.thresholdOutputData=e,t.thresholdData=e,this.setPendingFlag("threshold",!1)}return this.pendingDataFlags.extra&&Object.keys(this.extraData).length>0&&(this.extraOutputData=x(this.extraData,this.antennaFactorData,this.antennaFactorSwitch,this.srcIndexCache,this.getOutputData.bind(this)),t.extraData=this.extraOutputData,this.setPendingFlag("extra",!1)),t}notifySpectrumUpdate(t){if(this.onSpectrumUpdate){if(!Object.hasOwn(t,"waterfallData"))return void this.onSpectrumUpdate(t);if(this.waterfallSink){delete t.waterfallData,this.onSpectrumUpdate(t);return}t.waterfallData=this.getOrderedWaterfallData(this.waterfallOutputData),this.onSpectrumUpdate(t)}}calculateMemoryUsage(){return 4*(this.config.maxPoints*Float32Array.BYTES_PER_ELEMENT)+this.waterfallData.reduce((t,e)=>t+e.length*Float32Array.BYTES_PER_ELEMENT,0)+this.waterfallOutputData.reduce((t,e)=>t+e.length*Float32Array.BYTES_PER_ELEMENT,0)}getOutputData(t){let{outputRange:{start:e,end:a}}=this.config,s=t??this.realData,i=s.subarray(e,a);return i.timestamp=s.timestamp,i}getFluorescenceOutputData(t){let{processing:{enableFluorescence:e},outputRange:{start:a,end:s}}=this.config;if(!e||0===this.fluorescenceData.length||t<=0)return;let i=new Uint32Array(t*n.LEVEL_RANGE),r=(s-a)/t;for(let e=0;e<t;e++){let t=Math.floor(a+(e+.5)*r)*n.LEVEL_RANGE,s=e*n.LEVEL_RANGE;for(let e=0;e<n.LEVEL_RANGE;e++)i[s+e]=this.fluorescenceData[t+e]}return i}getAllRawData(t){let{realOutputData:e,maxOutputData:a,minOutputData:s,avgOutputData:i,templateOutputData:r,occupancyOutputData:n,backgroundNoiseOutputData:l,thresholdOutputData:h,waterfallOutputData:o,extraOutputData:u,srcIndexCache:c}=this;e.timestamp=this.realData.timestamp;let p={realData:this.realData,maxData:this.maxData,minData:this.minData,avgData:this.avgData,templateData:this.templateData,occupancyData:this.occupancyData,backgroundNoiseData:this.backgroundNoiseData,thresholdData:this.thresholdData,waterfallData:this.getOrderedWaterfallData(this.waterfallData),extraData:this.extraData},g=D(t,e.length,this.config.maxPoints);return{realData:e,maxData:a,minData:s,avgData:i,templateData:r,occupancyData:n,backgroundNoiseData:l,thresholdData:h,fluorescenceData:this.getFluorescenceOutputData(e.length),waterfallData:this.getOrderedWaterfallData(o),extraData:u,srcIndexCache:c,rawData:p,cursorIndex:g}}}let O=()=>({data:[],rawData:[],range:{x:[0,0],y:[0,0]},sourceSize:{width:0,height:0},columnIndices:new Uint32Array(0),rowIndices:new Uint32Array(0)}),I=t=>{let e=new Float32Array(t);return e.timestamp=t.timestamp,void 0!==t.allValid&&(e.allValid=t.allValid),t.peaks&&(e.peaks={...t.peaks,peaks:t.peaks.peaks.map(t=>({...t}))}),e},N=(t,e)=>{if(!Number.isInteger(t)||t<=0)throw new u(`${e} 必须是正整数`)},M=(t,e,a)=>{let[s,i]=t;if(!Number.isFinite(s)||!Number.isFinite(i)||s>=i)throw new u(`${a} 采样范围无效`);let r=Math.max(0,Math.min(e,Math.floor(s))),n=Math.max(0,Math.min(e,Math.ceil(i)));if(r>=n)throw new u(`${a} 采样范围超出数据边界`);return[r,n]},P=(t,e,a)=>{if(0===t[0]&&t[1]===e)return[0,a];let s=Math.min(t[0],a-1),i=Math.max(s+1,Math.min(t[1],a));return[s,i]},T=(t,e,a)=>{if(0===t[0]&&t[1]===e)return[0,a];if(t[1]===e){let e=Math.min(t[1]-t[0],a);return[a-e,a]}return P(t,e,a)},v=(t,e,a,s)=>{if(0===t[0]&&t[1]===e)return[0,a];let i=Math.min(t[1]-t[0],a);if(t[1]===e)return[a-i,a];let r=Math.max(0,Math.min(t[0]-s,a-i));return[r,r+i]},L=(t,e)=>{let[a,s]=t,i=s-a,r=Math.min(i,e),n=new Uint32Array(r);if(i<=e){for(let t=0;t<r;t++)n[t]=a+t;return n}for(let t=0;t<r;t++){let e=Math.floor(t*i/r),s=Math.floor((t+1)*i/r);n[t]=a+Math.min(s-1,Math.floor((e+s)/2))}return n},_=(t,e)=>t[0]===e[0]&&t[1]===e[1],U=(t,e)=>{if(t.length!==e.length)return!1;for(let a=0;a<t.length;a++)if(t[a]!==e[a])return!1;return!0},R=(t,e,a)=>{let s=t.subarray(e[0],e[1]),i=s.length,r=Math.min(i,a);if(i<=a)return 0===e[0]&&e[1]===t.length?t:(s.timestamp=t.timestamp,s);let n=new Float32Array(r);n.timestamp=t.timestamp;for(let t=0;t<r;t++){let e=Math.floor(t*i/r),a=Math.floor((t+1)*i/r),l=0/0;for(let t=e;t<a;t++){let e=s[t];Number.isFinite(e)&&(!Number.isFinite(l)||e>l)&&(l=e)}n[t]=l}return n};class k{maxFrames;onWaterfallUpdate;sourceData=[];samplingOptions;snapshot=O();constructor(t={}){if(void 0!==t.maxFrames&&(!Number.isInteger(t.maxFrames)||t.maxFrames<=0))throw new u("maxFrames 必须是正整数");this.maxFrames=t.maxFrames,this.onWaterfallUpdate=t.onWaterfallUpdate}setData(t){if(0===t.length)return this.sourceData=[],this.samplingOptions=void 0,this.publishSnapshot(O());let e=t[0].length;if(0===e)throw new u("瀑布图帧不能为空");for(let a of t)if(a.length!==e)throw new u("瀑布图数据必须是等宽矩阵");let a=this.snapshot.sourceSize,s=[...t];void 0!==this.maxFrames&&s.length>this.maxFrames&&(s=s.slice(-this.maxFrames));let i=this.samplingOptions;i&&a.width>0&&a.height>0&&(i={...i,x:P(i.x,a.width,e),y:T(i.y,a.height,s.length)});let r=this.createSnapshot(s,i);return this.sourceData=s,this.samplingOptions=i,this.publishSnapshot(r)}appendFrame(t){if(0===t.length)throw new u("瀑布图帧不能为空");let e=this.sourceData[0]?.length;if(void 0!==e&&t.length!==e)throw new u("追加帧宽度必须与现有瀑布图一致");let a=this.sourceData.length,s=[...this.sourceData,I(t)],i=0;void 0!==this.maxFrames&&s.length>this.maxFrames&&(i=s.length-this.maxFrames,s.splice(0,i));let r=this.samplingOptions;r&&a>0&&(r={...r,y:v(r.y,a,s.length,i)});let n=this.createSnapshot(s,r);return this.sourceData=s,this.samplingOptions=r,this.publishSnapshot(n)}updateSamplingRange(t){let e=this.getSourceSize(this.sourceData);if(0===e.width||0===e.height)throw new u("设置采样范围前必须先设置瀑布图数据");N(t.outputWidth,"outputWidth"),N(t.outputHeight,"outputHeight");let a={x:M(t.x,e.width,"X"),y:M(t.y,e.height,"Y"),outputWidth:t.outputWidth,outputHeight:t.outputHeight},s=this.createSnapshot(this.sourceData,a);return this.samplingOptions=a,this.publishSnapshot(s)}getSnapshot(){return this.snapshot}createSnapshot(t,e){let a=this.getSourceSize(t);if(0===a.width||0===a.height)return O();let s=e?.x??[0,a.width],i=e?.y??[0,a.height],r=e?.outputWidth??s[1]-s[0],n=e?.outputHeight??i[1]-i[0],l=L(s,r),h=L(i,n),o=this.createReusableRows(s,l);return{data:Array.from(h,e=>{let a=t[e];return o.get(a)??R(a,s,r)}),rawData:t,range:{x:s,y:i},sourceSize:a,columnIndices:l,rowIndices:h}}createReusableRows(t,e){let a=this.snapshot;if(!_(a.range.x,t)||!U(a.columnIndices,e))return new Map;let s=new Map;for(let t=0;t<a.rowIndices.length;t++){let e=a.rawData[a.rowIndices[t]],i=a.data[t];e&&i&&s.set(e,i)}return s}getSourceSize(t){return{width:t[0]?.length??0,height:t.length}}publishSnapshot(t){return this.snapshot=t,this.onWaterfallUpdate?.(t),t}}var C=/*#__PURE__*/function(t){return t.Horizontal="horizontal",t.Vertical="vertical",t}({}),V=/*#__PURE__*/function(t){return t.Circle="circle",t.Rect="rect",t.Line="line",t.Stepline="stepline",t.Bar="bar",t.Area="area",t}({}),W=/*#__PURE__*/function(t){return t.PropertyChanged="propertyChanged",t.SeriesAdded="seriesAdded",t.SeriesRemoved="seriesRemoved",t.SeriesCleared="seriesCleared",t}({});let G={thickness:1,orientation:C.Horizontal,display:!0,type:V.Line,color:"#00000000",label:""};class H{seriesMap=new Map;changeCallbacks=[];subscribers=new Map;constructor(t=[]){this.initializeSeries(t)}initializeSeries(t){for(let e of t)this.addSeries(e)}addSeries(t){let e={...G,...t};this.seriesMap.set(t.name,e),this.emitEvent({type:W.SeriesAdded,name:t.name,series:e})}getSeries(t){return this.seriesMap.get(t)}getAllSeries(){return Array.from(this.seriesMap.values())}getAllConfigs(){let t={};for(let[e,a]of this.seriesMap)t[e]={...a};return t}setSeriesProperty(t,e,a){let s=this.seriesMap.get(t);if(!s||"name"===e)return!1;let i=s[e],r={...s,[e]:a};return this.seriesMap.set(t,r),this.notifyChange(t,e,a),this.emitEvent({type:W.PropertyChanged,name:t,property:e,value:a,oldValue:i,series:r}),!0}removeSeries(t){let e=this.seriesMap.get(t);if(!e)return!1;let a=this.seriesMap.delete(t);return a&&this.emitEvent({type:W.SeriesRemoved,name:t,series:e}),a}hasSeries(t){return this.seriesMap.has(t)}onChange(t){this.changeCallbacks.push(t)}offChange(t){let e=this.changeCallbacks.indexOf(t);e>-1&&this.changeCallbacks.splice(e,1)}notifyChange(t,e,a){for(let s of this.changeCallbacks)s(t,e,a)}clear(){this.seriesMap.clear(),this.emitEvent({type:W.SeriesCleared})}size(){return this.seriesMap.size}subscribe(t,e={}){if(this.subscribers.set(t,e),e.immediate)for(let e of this.seriesMap.values())this.shouldNotifySubscriber(t,{type:W.SeriesAdded,name:e.name,series:e})&&t({type:W.SeriesAdded,name:e.name,series:e});return()=>{this.subscribers.delete(t)}}unsubscribe(t){this.subscribers.delete(t)}emitEvent(t){for(let[e]of this.subscribers)this.shouldNotifySubscriber(e,t)&&e(t)}shouldNotifySubscriber(t,e){let a=this.subscribers.get(t);return!!a&&(!a.eventTypes||!!a.eventTypes.includes(e.type))&&(!a.seriesNames||!e.name||!!a.seriesNames.includes(e.name))}}export{u as DataValidationError,h as ERROR_MESSAGES,c as IndexOutOfBoundsError,a as LevelStreamAnalyzer,s as SPECTRUM,H as SeriesManager,E as SpectrumAnalyzer,o as SpectrumError,k as WaterfallAnalyzer,S as ExtraDataMode,V as GraphicType,C as OrientationType,W as SeriesEventType};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rfkit/spectrum-analyzer",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "type": "module",
5
5
  "description": "A high-performance spectrum analyzer library for RF signal processing, supporting real-time spectrum analysis, waterfall display, and multi-segment frequency scanning",
6
6
  "exports": {
package/wasm/index.js CHANGED
@@ -1 +1 @@
1
- var t=/*#__PURE__*/function(t){return t.Horizontal="horizontal",t.Vertical="vertical",t}({}),e=/*#__PURE__*/function(t){return t.Circle="circle",t.Rect="rect",t.Line="line",t.Stepline="stepline",t.Bar="bar",t.Area="area",t}({}),a=/*#__PURE__*/function(t){return t.PropertyChanged="propertyChanged",t.SeriesAdded="seriesAdded",t.SeriesRemoved="seriesRemoved",t.SeriesCleared="seriesCleared",t}({});let s={thickness:1,orientation:t.Horizontal,display:!0,type:e.Line,color:"#00000000",label:""};class n{seriesMap=new Map;changeCallbacks=[];subscribers=new Map;constructor(t=[]){this.initializeSeries(t)}initializeSeries(t){for(let e of t)this.addSeries(e)}addSeries(t){let e={...s,...t};this.seriesMap.set(t.name,e),this.emitEvent({type:a.SeriesAdded,name:t.name,series:e})}getSeries(t){return this.seriesMap.get(t)}getAllSeries(){return Array.from(this.seriesMap.values())}getAllConfigs(){let t={};for(let[e,a]of this.seriesMap)t[e]={...a};return t}setSeriesProperty(t,e,s){let n=this.seriesMap.get(t);if(!n||"name"===e)return!1;let i=n[e],r={...n,[e]:s};return this.seriesMap.set(t,r),this.notifyChange(t,e,s),this.emitEvent({type:a.PropertyChanged,name:t,property:e,value:s,oldValue:i,series:r}),!0}removeSeries(t){let e=this.seriesMap.get(t);if(!e)return!1;let s=this.seriesMap.delete(t);return s&&this.emitEvent({type:a.SeriesRemoved,name:t,series:e}),s}hasSeries(t){return this.seriesMap.has(t)}onChange(t){this.changeCallbacks.push(t)}offChange(t){let e=this.changeCallbacks.indexOf(t);e>-1&&this.changeCallbacks.splice(e,1)}notifyChange(t,e,a){for(let s of this.changeCallbacks)s(t,e,a)}clear(){this.seriesMap.clear(),this.emitEvent({type:a.SeriesCleared})}size(){return this.seriesMap.size}subscribe(t,e={}){if(this.subscribers.set(t,e),e.immediate)for(let e of this.seriesMap.values())this.shouldNotifySubscriber(t,{type:a.SeriesAdded,name:e.name,series:e})&&t({type:a.SeriesAdded,name:e.name,series:e});return()=>{this.subscribers.delete(t)}}unsubscribe(t){this.subscribers.delete(t)}emitEvent(t){for(let[e]of this.subscribers)this.shouldNotifySubscriber(e,t)&&e(t)}shouldNotifySubscriber(t,e){let a=this.subscribers.get(t);return!!a&&(!a.eventTypes||!!a.eventTypes.includes(e.type))&&(!a.seriesNames||!e.name||!!a.seriesNames.includes(e.name))}}let i={INITIAL_VALUE:0/0,WATERFALL_MAX_FRAMES:100,OUTPUT_POINTS:1001},r={MAX_PEAKS:2},l=null,o={UPDATE_INTERVAL:1,LEVEL_MIN:-20,LEVEL_MAX:140,LEVEL_RANGE:161},h={maxPoints:i.OUTPUT_POINTS,waterfallMaxFrames:i.WATERFALL_MAX_FRAMES,initialValue:i.INITIAL_VALUE,processing:{enableWaterfall:!1,enableMetrics:!1,enableFluorescence:!1,enablePeakStats:!1,fluorescenceUpdateInterval:o.UPDATE_INTERVAL},peakDetection:{maxPeaks:r.MAX_PEAKS},outputPoints:i.OUTPUT_POINTS,outputRange:{start:0,end:i.OUTPUT_POINTS},templateTolerance:0},c={EMPTY_SEGMENTS:"频段配置不能为空",INVALID_CONFIG:"必须且只能配置 segments 或 bandwidthConfig 其中之一",EMPTY_BANDWIDTH:"bandwidthConfig 不能为空",INVALID_SEGMENT:t=>`无效的段索引: ${t}`,INDEX_OUT_OF_BOUNDS:t=>`索引超出范围: ${t}`,INVALID_ANTENNA_FACTOR_LENGTH:t=>`天线因子数据长度必须等于实时数据长度 (${t})`,INVALID_ANTENNA_FACTOR:"天线因子数据必须是有效的正数",INVALID_SAMPLING_RANGE:"采样范围无效",INVALID_MAX_POINTS:"点数必须大于0",INVALID_LENGTH:t=>`频率占用度数据长度不匹配,期望长度为 ${t}`};class m extends Error{code;details;constructor(t,e,a){super(t),this.code=e,this.details=a,this.name="SpectrumError"}}class u extends m{constructor(t,e){super(t,"DATA_VALIDATION_ERROR",e)}}class p extends m{index;constructor(t,e,a){super(t,"INDEX_OUT_OF_BOUNDS_ERROR",{index:e,...a||{}}),this.index=e}}var d=/*#__PURE__*/function(t){return t.REPLACE="replace",t.MERGE="merge",t.CLEAR="clear",t}({});let g=()=>({data:[],rawData:[],range:{x:[0,0],y:[0,0]},sourceSize:{width:0,height:0},columnIndices:new Uint32Array(0),rowIndices:new Uint32Array(0)}),f=t=>{let e=new Float32Array(t);return e.timestamp=t.timestamp,void 0!==t.allValid&&(e.allValid=t.allValid),t.peaks&&(e.peaks={...t.peaks,peaks:t.peaks.peaks.map(t=>({...t}))}),e},w=(t,e)=>{if(!Number.isInteger(t)||t<=0)throw new u(`${e} 必须是正整数`)},D=(t,e,a)=>{let[s,n]=t;if(!Number.isFinite(s)||!Number.isFinite(n)||s>=n)throw new u(`${a} 采样范围无效`);let i=Math.max(0,Math.min(e,Math.floor(s))),r=Math.max(0,Math.min(e,Math.ceil(n)));if(i>=r)throw new u(`${a} 采样范围超出数据边界`);return[i,r]},_=(t,e,a)=>{if(0===t[0]&&t[1]===e)return[0,a];let s=Math.min(t[0],a-1),n=Math.max(s+1,Math.min(t[1],a));return[s,n]},x=(t,e,a)=>{if(0===t[0]&&t[1]===e)return[0,a];if(t[1]===e){let e=Math.min(t[1]-t[0],a);return[a-e,a]}return _(t,e,a)},I=(t,e,a,s)=>{if(0===t[0]&&t[1]===e)return[0,a];let n=Math.min(t[1]-t[0],a);if(t[1]===e)return[a-n,a];let i=Math.max(0,Math.min(t[0]-s,a-n));return[i,i+n]},A=(t,e)=>{let[a,s]=t,n=s-a,i=Math.min(n,e),r=new Uint32Array(i);if(n<=e){for(let t=0;t<i;t++)r[t]=a+t;return r}for(let t=0;t<i;t++){let e=Math.floor(t*n/i),s=Math.floor((t+1)*n/i);r[t]=a+Math.min(s-1,Math.floor((e+s)/2))}return r},y=(t,e)=>t[0]===e[0]&&t[1]===e[1],S=(t,e)=>{if(t.length!==e.length)return!1;for(let a=0;a<t.length;a++)if(t[a]!==e[a])return!1;return!0},C=(t,e,a)=>{let s=t.subarray(e[0],e[1]),n=s.length,i=Math.min(n,a);if(n<=a)return 0===e[0]&&e[1]===t.length?t:(s.timestamp=t.timestamp,s);let r=new Float32Array(i);r.timestamp=t.timestamp;for(let t=0;t<i;t++){let e=Math.floor(t*n/i),a=Math.floor((t+1)*n/i),l=0/0;for(let t=e;t<a;t++){let e=s[t];Number.isFinite(e)&&(!Number.isFinite(l)||e>l)&&(l=e)}r[t]=l}return r};class b{maxFrames;onWaterfallUpdate;sourceData=[];samplingOptions;snapshot=g();constructor(t={}){if(void 0!==t.maxFrames&&(!Number.isInteger(t.maxFrames)||t.maxFrames<=0))throw new u("maxFrames 必须是正整数");this.maxFrames=t.maxFrames,this.onWaterfallUpdate=t.onWaterfallUpdate}setData(t){if(0===t.length)return this.sourceData=[],this.samplingOptions=void 0,this.publishSnapshot(g());let e=t[0].length;if(0===e)throw new u("瀑布图帧不能为空");for(let a of t)if(a.length!==e)throw new u("瀑布图数据必须是等宽矩阵");let a=this.snapshot.sourceSize,s=[...t];void 0!==this.maxFrames&&s.length>this.maxFrames&&(s=s.slice(-this.maxFrames));let n=this.samplingOptions;n&&a.width>0&&a.height>0&&(n={...n,x:_(n.x,a.width,e),y:x(n.y,a.height,s.length)});let i=this.createSnapshot(s,n);return this.sourceData=s,this.samplingOptions=n,this.publishSnapshot(i)}appendFrame(t){if(0===t.length)throw new u("瀑布图帧不能为空");let e=this.sourceData[0]?.length;if(void 0!==e&&t.length!==e)throw new u("追加帧宽度必须与现有瀑布图一致");let a=this.sourceData.length,s=[...this.sourceData,f(t)],n=0;void 0!==this.maxFrames&&s.length>this.maxFrames&&(n=s.length-this.maxFrames,s.splice(0,n));let i=this.samplingOptions;i&&a>0&&(i={...i,y:I(i.y,a,s.length,n)});let r=this.createSnapshot(s,i);return this.sourceData=s,this.samplingOptions=i,this.publishSnapshot(r)}updateSamplingRange(t){let e=this.getSourceSize(this.sourceData);if(0===e.width||0===e.height)throw new u("设置采样范围前必须先设置瀑布图数据");w(t.outputWidth,"outputWidth"),w(t.outputHeight,"outputHeight");let a={x:D(t.x,e.width,"X"),y:D(t.y,e.height,"Y"),outputWidth:t.outputWidth,outputHeight:t.outputHeight},s=this.createSnapshot(this.sourceData,a);return this.samplingOptions=a,this.publishSnapshot(s)}getSnapshot(){return this.snapshot}createSnapshot(t,e){let a=this.getSourceSize(t);if(0===a.width||0===a.height)return g();let s=e?.x??[0,a.width],n=e?.y??[0,a.height],i=e?.outputWidth??s[1]-s[0],r=e?.outputHeight??n[1]-n[0],l=A(s,i),o=A(n,r),h=this.createReusableRows(s,l);return{data:Array.from(o,e=>{let a=t[e];return h.get(a)??C(a,s,i)}),rawData:t,range:{x:s,y:n},sourceSize:a,columnIndices:l,rowIndices:o}}createReusableRows(t,e){let a=this.snapshot;if(!y(a.range.x,t)||!S(a.columnIndices,e))return new Map;let s=new Map;for(let t=0;t<a.rowIndices.length;t++){let e=a.rawData[a.rowIndices[t]],n=a.data[t];e&&n&&s.set(e,n)}return s}getSourceSize(t){return{width:t[0]?.length??0,height:t.length}}publishSnapshot(t){return this.snapshot=t,this.onWaterfallUpdate?.(t),t}}let E={DEFAULT_CACHE_TIME:15e3,DEFAULT_GRANULARITY:10,DEFAULT_RANGE:[-20,100]},v={cacheTime:E.DEFAULT_CACHE_TIME,granularity:E.DEFAULT_GRANULARITY,range:E.DEFAULT_RANGE,maxPoints:void 0,onLevelStreamUpdate:t=>{}},N=null,M=!1,T=null;function R(){return"u">typeof process&&"object"==typeof process.versions&&!!process.versions?.node}async function F(){M||(T||(T=(async()=>{let t=await import("./src-rust/pkg/rfkit_spectrum_analyzer_wasm.js");if("function"==typeof t.default)if(R()){let e=new URL("./src-rust/pkg/rfkit_spectrum_analyzer_wasm_bg.wasm",import.meta.url);if("file:"===e.protocol){let{readFile:a}=await import("node:fs/promises"),s=await a(e);await t.default({module_or_path:s})}else await t.default()}else await t.default();N=t,M=!0})()),await T)}function k(){return M}function L(){if(!N)throw Error('WASM not initialized. Call `await initWasm()` before using WASM classes.\nExample:\n import { initWasm } from "@rfkit/spectrum-analyzer/wasm";\n await initWasm();');return N}function O(){if(!M)throw Error('WASM not initialized. Call `await initWasm()` before creating WASM instances.\nExample:\n import { initWasm, SpectrumAnalyzer } from "@rfkit/spectrum-analyzer/wasm";\n await initWasm();\n const analyzer = new SpectrumAnalyzer(config);')}class U{wasmInstance;onLevelStreamUpdate;config;constructor(t){O();let e=L();this.onLevelStreamUpdate=t.onLevelStreamUpdate;let{onLevelStreamUpdate:a,...s}=t;this.config={cacheTime:v.cacheTime,granularity:v.granularity,range:[...v.range],maxPoints:v.maxPoints,...s},this.wasmInstance=new e.WasmLevelStreamAnalyzer(this.config),this.onLevelStreamUpdate&&this.wasmInstance.set_callback(t=>{this.onLevelStreamUpdate?.(t)})}process(t,e){this.wasmInstance.process(t,e)}reset(){this.wasmInstance.reset()}setConfig(t){"onLevelStreamUpdate"in t&&(this.onLevelStreamUpdate=t.onLevelStreamUpdate,this.wasmInstance.set_callback(t=>{this.onLevelStreamUpdate?.(t)}));let e=void 0!==t.cacheTime&&this.config.cacheTime!==t.cacheTime||void 0!==t.granularity&&this.config.granularity!==t.granularity||void 0!==t.maxPoints&&this.config.maxPoints!==t.maxPoints,{onLevelStreamUpdate:a,...s}=t,n={...this.config,...s};this.config=n,this.wasmInstance.set_config(n,e,!!t.range)}getAll(){return this.wasmInstance.get_all()}}class P{wasmInstance;onSpectrumUpdate;hasSegments=!1;segments=[];callbackContext=null;templateDataRaw=new Float32Array(0);backgroundNoiseDataRaw=new Float32Array(0);thresholdDataRaw=new Float32Array(0);antennaFactorData;srcIndexCache;extraData={};antennaFactorSwitch=!1;config;constructor(t){O();let e=L();this.onSpectrumUpdate=t.onSpectrumUpdate;let{onSpectrumUpdate:a,...s}=t;this.wasmInstance=new e.WasmSpectrumAnalyzer(s),this.wasmInstance.set_callback(t=>{let e=this.convertOutput(t);e&&(e.srcIndexCache&&(this.srcIndexCache=e.srcIndexCache),this.onSpectrumUpdate?.(e))}),this.antennaFactorData=this.wasmInstance.get_antenna_factor_view(),this.srcIndexCache=this.wasmInstance.get_src_index_cache_view(),this.config=this.readConfig()}readConfig(){let t=this.wasmInstance.get_config();return{initialValue:i.INITIAL_VALUE,...t}}normalizeSeriesData(t){let e=new Float32Array(this.config.maxPoints);return e.fill(i.INITIAL_VALUE),e.set(t.subarray(0,this.config.maxPoints)),e}resampleSingleDataLikeJs(t){let{outputRange:{start:e,end:a}}=this.config,s=t.subarray(e,a),n=this.srcIndexCache.length,i=new Float32Array(n);for(let t=0;t<n;t++)i[t]=s[this.srcIndexCache[t]];return i}normalizeSegments(t){let e=0;return t.map(t=>{let{startFrequency:a,stopFrequency:s,stepFrequency:n}=t,i=Math.round(1e3*(s-a)/n)+1,r=e;return e+=i,{startFrequency:a,stopFrequency:s,stepFrequency:n,pointCount:i,startIndex:r}})}resolveGlobalIndex(t=0,e=0){if(this.segments.length>0){let a=this.segments[t];if(!a)throw new u(c.INVALID_SEGMENT(t));return a.startIndex+e}return e}validateSegmentInput(t,e){if(e<0||e+t.length>this.config.maxPoints)throw new p(c.INDEX_OUT_OF_BOUNDS(e),e)}clearLocalResetMirrors(){this.templateDataRaw=new Float32Array(0),this.backgroundNoiseDataRaw=new Float32Array(0),this.thresholdDataRaw=new Float32Array(0),this.extraData={}}convertOutput(t){let e=this.callbackContext;if(e?.type==="setExtraData"&&e.mode===d.CLEAR)return null;let a={...t};a.realData&&void 0!==a.timestamp&&(a.realData.timestamp=a.timestamp),delete a.timestamp,void 0!==a.peakStats&&a.realData&&(a.realData.peaks=a.peakStats),delete a.peakStats;let s=t=>Object.fromEntries(t.map(t=>[t,a[t]])),n=t=>{"fluorescenceData"in t||(t.fluorescenceData=void 0),"fluorescenceMaxCount"in t||(t.fluorescenceMaxCount=0)},i=!("occupancyData"in a);switch(e?.type){case"process":if(i)return s(["realData","maxData","minData","avgData","templateData","backgroundNoiseData","thresholdData","extraData","srcIndexCache","processTimes","scanProgress"]);return n(a),"templateOverData"in a||(a.templateOverData=[]),s(["realData","maxData","minData","avgData","templateData","occupancyData","backgroundNoiseData","thresholdData","fluorescenceData","fluorescenceMaxCount","extraData","srcIndexCache","waterfallData","scanProgress","processTimes","templateOverData"]);case"setAntennaFactorSwitch":case"updateSamplingRange":return n(a),s(["realData","maxData","minData","avgData","templateData","occupancyData","backgroundNoiseData","thresholdData","fluorescenceData","fluorescenceMaxCount","extraData","srcIndexCache","waterfallData"]);case"updateProcessing":case"setRealData":case"setMaxData":case"setMinData":case"setAvgData":return n(a),s(["realData","maxData","minData","avgData","templateData","occupancyData","backgroundNoiseData","thresholdData","fluorescenceData","fluorescenceMaxCount","extraData","srcIndexCache"]);case"clearMetricsData":return s(["maxData","minData","avgData","processTimes"]);case"setFluorescenceData":return s(["fluorescenceData","fluorescenceMaxCount"]);case"setTemplateData":return{templateData:this.resampleSingleDataLikeJs(this.templateDataRaw),templateOverData:a.templateOverData??[]};case"setOccupancyData":return{occupancyData:a.occupancyData??new Float32Array(0)};case"setBackgroundNoiseData":return{backgroundNoiseData:this.resampleSingleDataLikeJs(this.backgroundNoiseDataRaw)};case"setThresholdData":return{thresholdData:this.resampleSingleDataLikeJs(this.thresholdDataRaw)};case"setExtraData":return{extraData:a.extraData??{}};case"setWaterfallData":return{waterfallData:a.waterfallData??[]};case"reset":case"initializeSegments":return s(["realData","maxData","minData","avgData","templateData","backgroundNoiseData","thresholdData","extraData","srcIndexCache","processTimes","scanProgress"]);default:return a}}withCallbackContext(t,e){let a=this.callbackContext;this.callbackContext=t;try{return e()}finally{this.callbackContext=a}}process(t){let e=this.config.maxPoints;if(t.data?.length){let e=this.resolveGlobalIndex(t.segmentOffset??0,t.offset??0);if(this.segments.length>0)this.validateSegmentInput(t.data,e);else if(e<0||t.data.length===this.config.maxPoints&&e+t.data.length>this.config.maxPoints)throw new p(c.INDEX_OUT_OF_BOUNDS(e),e)}try{this.withCallbackContext({type:"process"},()=>{this.wasmInstance.process(t.data,String(t.timestamp),t.segmentOffset??0,t.offset??0,t.fluorescenceData,t.fluorescenceMaxCount)})}catch(a){let e=String(a instanceof Error?a.message:a??"");if(e.includes("Data exceeds max points")||e.includes("Index out of bounds")){let e=this.resolveGlobalIndex(t.segmentOffset??0,t.offset??0);throw new p(c.INDEX_OUT_OF_BOUNDS(e),e)}throw a instanceof Error?a:Error(e)}finally{this.hasSegments||t.data.length===e||(this.config=this.readConfig(),this.antennaFactorData=this.wasmInstance.get_antenna_factor_view(),this.srcIndexCache=this.wasmInstance.get_src_index_cache_view(),this.clearLocalResetMirrors())}}initializeSegments(t){if(!t?.length)throw new u(c.EMPTY_SEGMENTS);this.withCallbackContext({type:"initializeSegments"},()=>{this.wasmInstance.initialize_segments(t)}),this.hasSegments=!0,this.segments=this.normalizeSegments(t),this.clearLocalResetMirrors(),this.config=this.readConfig(),this.antennaFactorData=this.wasmInstance.get_antenna_factor_view(),this.srcIndexCache=this.wasmInstance.get_src_index_cache_view()}updateSamplingRange(t,e){if(t<0||t>=e)throw new u(c.INVALID_SAMPLING_RANGE);let a=this.withCallbackContext({type:"updateSamplingRange"},()=>this.wasmInstance.update_sampling_range(t,e));return this.srcIndexCache=a,this.config=this.readConfig(),a}reset(t){this.withCallbackContext({type:"reset"},()=>{this.wasmInstance.reset(t??!1)}),this.clearLocalResetMirrors(),this.antennaFactorData=this.wasmInstance.get_antenna_factor_view(),this.srcIndexCache=this.wasmInstance.get_src_index_cache_view(),this.config=this.readConfig()}setAntennaFactor(t){let e=t instanceof Float32Array?t:new Float32Array(t);e.length!==this.config.maxPoints&&console.warn(c.INVALID_ANTENNA_FACTOR_LENGTH(this.config.maxPoints));let a=!1;for(let t=0;t<e.length;t++)if(!(Number.isFinite(e[t])&&e[t]>0)){a=!0;break}a&&console.warn(c.INVALID_ANTENNA_FACTOR),this.wasmInstance.set_antenna_factor(e),this.antennaFactorData=this.wasmInstance.get_antenna_factor_view()}setAntennaFactorSwitch(t){this.withCallbackContext({type:"setAntennaFactorSwitch"},()=>{this.wasmInstance.set_antenna_factor_switch(t)}),this.antennaFactorSwitch=t}setRealData(t){this.withCallbackContext({type:"setRealData"},()=>{this.wasmInstance.set_real_data(t,String(t.timestamp))})}setMaxData(t){this.withCallbackContext({type:"setMaxData"},()=>{this.wasmInstance.set_max_data(t)})}setMinData(t){this.withCallbackContext({type:"setMinData"},()=>{this.wasmInstance.set_min_data(t)})}setAvgData(t){this.withCallbackContext({type:"setAvgData"},()=>{this.wasmInstance.set_avg_data(t)})}setWaterfallData(t){this.withCallbackContext({type:"setWaterfallData"},()=>{this.wasmInstance.set_waterfall_data(t)}),this.config=this.readConfig()}setTemplateData(t,e){if(t&&0!==t.length){let a=t instanceof Float32Array?t:new Float32Array(t);this.templateDataRaw=new Float32Array(a),this.withCallbackContext({type:"setTemplateData"},()=>{this.wasmInstance.set_template_data(a,e)})}else{this.templateDataRaw=new Float32Array(0),this.withCallbackContext({type:"setTemplateData"},()=>{this.wasmInstance.set_template_data(void 0,void 0)});return}void 0!==e&&(this.config=this.readConfig())}setOccupancyData(t){if(t&&0!==t.length){let e=t instanceof Float32Array?t:new Float32Array(t);this.withCallbackContext({type:"setOccupancyData"},()=>{this.wasmInstance.set_occupancy_data(e)})}else this.withCallbackContext({type:"setOccupancyData"},()=>{this.wasmInstance.set_occupancy_data(void 0)})}setBackgroundNoiseData(t){if(t&&0!==t.length){let e=t instanceof Float32Array?t:new Float32Array(t);this.backgroundNoiseDataRaw=new Float32Array(e),this.withCallbackContext({type:"setBackgroundNoiseData"},()=>{this.wasmInstance.set_background_noise_data(e)})}else this.backgroundNoiseDataRaw=new Float32Array(0),this.withCallbackContext({type:"setBackgroundNoiseData"},()=>{this.wasmInstance.set_background_noise_data(void 0)})}setThresholdData(t,e){if(t&&0!==t.length){let a,s,n=t instanceof Float32Array?t:new Float32Array(t),r=0;if(e){let t=this.resolveGlobalIndex(e.segmentOffset??0,e.offset??0);this.validateSegmentInput(n,t),this.thresholdDataRaw.length===this.config.maxPoints?(s=new Float32Array(this.thresholdDataRaw.subarray(t,t+n.length)),r=t):(a=this.thresholdDataRaw,this.thresholdDataRaw=new Float32Array(this.config.maxPoints),this.thresholdDataRaw.fill(i.INITIAL_VALUE),a.length>0&&this.thresholdDataRaw.set(a.subarray(0,this.config.maxPoints))),this.thresholdDataRaw.set(n,t)}else a=this.thresholdDataRaw,this.thresholdDataRaw=new Float32Array(this.config.maxPoints),this.thresholdDataRaw.fill(i.INITIAL_VALUE),this.thresholdDataRaw.set(n.subarray(0,this.config.maxPoints));try{this.withCallbackContext({type:"setThresholdData"},()=>{this.wasmInstance.set_threshold_data(n,e?e.segmentOffset??0:void 0,e?e.offset??0:void 0)})}catch(t){throw a?this.thresholdDataRaw=a:s&&this.thresholdDataRaw.set(s,r),t}}else this.thresholdDataRaw=new Float32Array(0),this.withCallbackContext({type:"setThresholdData"},()=>{this.wasmInstance.set_threshold_data(void 0,void 0,void 0)})}setExtraData(t,e=d.MERGE,a){if(e===d.CLEAR){this.extraData={},this.withCallbackContext({type:"setExtraData",mode:e},()=>{this.wasmInstance.set_extra_data(null,e,void 0,void 0)});return}if(!t){e===d.REPLACE&&(this.extraData={},this.withCallbackContext({type:"setExtraData",mode:e},()=>{this.wasmInstance.set_extra_data(null,e,void 0,void 0)}));return}let s=Object.entries(t).map(([t,e])=>[t,e?.length?new Float32Array(e):null]),n=a?this.resolveGlobalIndex(a.segmentOffset??0,a.offset??0):0;if(a)for(let[,t]of s)t&&this.validateSegmentInput(t,n);for(let[t,r]of(e===d.REPLACE&&(this.extraData={}),s)){if(!r){delete this.extraData[t];continue}if(!a){this.extraData[t]=this.normalizeSeriesData(r);continue}let e=this.extraData[t];if(e?.length!==this.config.maxPoints){let a=new Float32Array(this.config.maxPoints);a.fill(i.INITIAL_VALUE),e?.length&&a.set(e.subarray(0,this.config.maxPoints)),e=a,this.extraData[t]=e}e.set(r,n)}this.withCallbackContext({type:"setExtraData",mode:e},()=>{this.wasmInstance.set_extra_data(t,e,a?.segmentOffset,a?.offset)})}getPerformanceMetrics(){return this.wasmInstance.get_performance_metrics()}updateProcessing(t){this.withCallbackContext({type:"updateProcessing"},()=>{this.wasmInstance.update_processing(t)}),this.config=this.readConfig()}clearMetricsData(){this.withCallbackContext({type:"clearMetricsData"},()=>{this.wasmInstance.clear_metrics_data()})}getPeakStats(){let t=this.wasmInstance.get_peak_stats();if(null!=t)return t}setFluorescenceData(t,e){this.withCallbackContext({type:"setFluorescenceData"},()=>{this.wasmInstance.set_fluorescence_data(t,e)})}getAllRawData(t){return this.wasmInstance.get_all_raw_data(t)}}export{u as DataValidationError,c as ERROR_MESSAGES,p as IndexOutOfBoundsError,U as LevelStreamAnalyzer,i as SPECTRUM,n as SeriesManager,P as SpectrumAnalyzer,m as SpectrumError,b as WaterfallAnalyzer,F as initWasm,k as isWasmReady,d as ExtraDataMode,e as GraphicType,t as OrientationType,a as SeriesEventType};
1
+ var t=/*#__PURE__*/function(t){return t.Horizontal="horizontal",t.Vertical="vertical",t}({}),e=/*#__PURE__*/function(t){return t.Circle="circle",t.Rect="rect",t.Line="line",t.Stepline="stepline",t.Bar="bar",t.Area="area",t}({}),a=/*#__PURE__*/function(t){return t.PropertyChanged="propertyChanged",t.SeriesAdded="seriesAdded",t.SeriesRemoved="seriesRemoved",t.SeriesCleared="seriesCleared",t}({});let s={thickness:1,orientation:t.Horizontal,display:!0,type:e.Line,color:"#00000000",label:""};class i{seriesMap=new Map;changeCallbacks=[];subscribers=new Map;constructor(t=[]){this.initializeSeries(t)}initializeSeries(t){for(let e of t)this.addSeries(e)}addSeries(t){let e={...s,...t};this.seriesMap.set(t.name,e),this.emitEvent({type:a.SeriesAdded,name:t.name,series:e})}getSeries(t){return this.seriesMap.get(t)}getAllSeries(){return Array.from(this.seriesMap.values())}getAllConfigs(){let t={};for(let[e,a]of this.seriesMap)t[e]={...a};return t}setSeriesProperty(t,e,s){let i=this.seriesMap.get(t);if(!i||"name"===e)return!1;let n=i[e],r={...i,[e]:s};return this.seriesMap.set(t,r),this.notifyChange(t,e,s),this.emitEvent({type:a.PropertyChanged,name:t,property:e,value:s,oldValue:n,series:r}),!0}removeSeries(t){let e=this.seriesMap.get(t);if(!e)return!1;let s=this.seriesMap.delete(t);return s&&this.emitEvent({type:a.SeriesRemoved,name:t,series:e}),s}hasSeries(t){return this.seriesMap.has(t)}onChange(t){this.changeCallbacks.push(t)}offChange(t){let e=this.changeCallbacks.indexOf(t);e>-1&&this.changeCallbacks.splice(e,1)}notifyChange(t,e,a){for(let s of this.changeCallbacks)s(t,e,a)}clear(){this.seriesMap.clear(),this.emitEvent({type:a.SeriesCleared})}size(){return this.seriesMap.size}subscribe(t,e={}){if(this.subscribers.set(t,e),e.immediate)for(let e of this.seriesMap.values())this.shouldNotifySubscriber(t,{type:a.SeriesAdded,name:e.name,series:e})&&t({type:a.SeriesAdded,name:e.name,series:e});return()=>{this.subscribers.delete(t)}}unsubscribe(t){this.subscribers.delete(t)}emitEvent(t){for(let[e]of this.subscribers)this.shouldNotifySubscriber(e,t)&&e(t)}shouldNotifySubscriber(t,e){let a=this.subscribers.get(t);return!!a&&(!a.eventTypes||!!a.eventTypes.includes(e.type))&&(!a.seriesNames||!e.name||!!a.seriesNames.includes(e.name))}}let n={INITIAL_VALUE:0/0,WATERFALL_MAX_FRAMES:100,OUTPUT_POINTS:1001},r={MAX_PEAKS:2},l=null,o={UPDATE_INTERVAL:1,LEVEL_MIN:-20,LEVEL_MAX:140,LEVEL_RANGE:161},h={maxPoints:n.OUTPUT_POINTS,waterfallMaxFrames:n.WATERFALL_MAX_FRAMES,initialValue:n.INITIAL_VALUE,processing:{enableWaterfall:!1,enableMetrics:!1,enableFluorescence:!1,enablePeakStats:!1,fluorescenceUpdateInterval:o.UPDATE_INTERVAL},peakDetection:{maxPeaks:r.MAX_PEAKS},outputPoints:n.OUTPUT_POINTS,outputRange:{start:0,end:n.OUTPUT_POINTS},templateTolerance:0},c={EMPTY_SEGMENTS:"频段配置不能为空",INVALID_CONFIG:"必须且只能配置 segments 或 bandwidthConfig 其中之一",EMPTY_BANDWIDTH:"bandwidthConfig 不能为空",INVALID_SEGMENT:t=>`无效的段索引: ${t}`,INDEX_OUT_OF_BOUNDS:t=>`索引超出范围: ${t}`,INVALID_ANTENNA_FACTOR_LENGTH:t=>`天线因子数据长度必须等于实时数据长度 (${t})`,INVALID_ANTENNA_FACTOR:"天线因子数据必须是有效的正数",INVALID_SAMPLING_RANGE:"采样范围无效",INVALID_MAX_POINTS:"点数必须大于0",INVALID_LENGTH:t=>`频率占用度数据长度不匹配,期望长度为 ${t}`};class m extends Error{code;details;constructor(t,e,a){super(t),this.code=e,this.details=a,this.name="SpectrumError"}}class u extends m{constructor(t,e){super(t,"DATA_VALIDATION_ERROR",e)}}class p extends m{index;constructor(t,e,a){super(t,"INDEX_OUT_OF_BOUNDS_ERROR",{index:e,...a||{}}),this.index=e}}var f=/*#__PURE__*/function(t){return t.REPLACE="replace",t.MERGE="merge",t.CLEAR="clear",t}({});let d=()=>({data:[],rawData:[],range:{x:[0,0],y:[0,0]},sourceSize:{width:0,height:0},columnIndices:new Uint32Array(0),rowIndices:new Uint32Array(0)}),g=t=>{let e=new Float32Array(t);return e.timestamp=t.timestamp,void 0!==t.allValid&&(e.allValid=t.allValid),t.peaks&&(e.peaks={...t.peaks,peaks:t.peaks.peaks.map(t=>({...t}))}),e},w=(t,e)=>{if(!Number.isInteger(t)||t<=0)throw new u(`${e} 必须是正整数`)},D=(t,e,a)=>{let[s,i]=t;if(!Number.isFinite(s)||!Number.isFinite(i)||s>=i)throw new u(`${a} 采样范围无效`);let n=Math.max(0,Math.min(e,Math.floor(s))),r=Math.max(0,Math.min(e,Math.ceil(i)));if(n>=r)throw new u(`${a} 采样范围超出数据边界`);return[n,r]},_=(t,e,a)=>{if(0===t[0]&&t[1]===e)return[0,a];let s=Math.min(t[0],a-1),i=Math.max(s+1,Math.min(t[1],a));return[s,i]},x=(t,e,a)=>{if(0===t[0]&&t[1]===e)return[0,a];if(t[1]===e){let e=Math.min(t[1]-t[0],a);return[a-e,a]}return _(t,e,a)},y=(t,e,a,s)=>{if(0===t[0]&&t[1]===e)return[0,a];let i=Math.min(t[1]-t[0],a);if(t[1]===e)return[a-i,a];let n=Math.max(0,Math.min(t[0]-s,a-i));return[n,n+i]},I=(t,e)=>{let[a,s]=t,i=s-a,n=Math.min(i,e),r=new Uint32Array(n);if(i<=e){for(let t=0;t<n;t++)r[t]=a+t;return r}for(let t=0;t<n;t++){let e=Math.floor(t*i/n),s=Math.floor((t+1)*i/n);r[t]=a+Math.min(s-1,Math.floor((e+s)/2))}return r},A=(t,e)=>t[0]===e[0]&&t[1]===e[1],S=(t,e)=>{if(t.length!==e.length)return!1;for(let a=0;a<t.length;a++)if(t[a]!==e[a])return!1;return!0},C=(t,e,a)=>{let s=t.subarray(e[0],e[1]),i=s.length,n=Math.min(i,a);if(i<=a)return 0===e[0]&&e[1]===t.length?t:(s.timestamp=t.timestamp,s);let r=new Float32Array(n);r.timestamp=t.timestamp;for(let t=0;t<n;t++){let e=Math.floor(t*i/n),a=Math.floor((t+1)*i/n),l=0/0;for(let t=e;t<a;t++){let e=s[t];Number.isFinite(e)&&(!Number.isFinite(l)||e>l)&&(l=e)}r[t]=l}return r};class b{maxFrames;onWaterfallUpdate;sourceData=[];samplingOptions;snapshot=d();constructor(t={}){if(void 0!==t.maxFrames&&(!Number.isInteger(t.maxFrames)||t.maxFrames<=0))throw new u("maxFrames 必须是正整数");this.maxFrames=t.maxFrames,this.onWaterfallUpdate=t.onWaterfallUpdate}setData(t){if(0===t.length)return this.sourceData=[],this.samplingOptions=void 0,this.publishSnapshot(d());let e=t[0].length;if(0===e)throw new u("瀑布图帧不能为空");for(let a of t)if(a.length!==e)throw new u("瀑布图数据必须是等宽矩阵");let a=this.snapshot.sourceSize,s=[...t];void 0!==this.maxFrames&&s.length>this.maxFrames&&(s=s.slice(-this.maxFrames));let i=this.samplingOptions;i&&a.width>0&&a.height>0&&(i={...i,x:_(i.x,a.width,e),y:x(i.y,a.height,s.length)});let n=this.createSnapshot(s,i);return this.sourceData=s,this.samplingOptions=i,this.publishSnapshot(n)}appendFrame(t){if(0===t.length)throw new u("瀑布图帧不能为空");let e=this.sourceData[0]?.length;if(void 0!==e&&t.length!==e)throw new u("追加帧宽度必须与现有瀑布图一致");let a=this.sourceData.length,s=[...this.sourceData,g(t)],i=0;void 0!==this.maxFrames&&s.length>this.maxFrames&&(i=s.length-this.maxFrames,s.splice(0,i));let n=this.samplingOptions;n&&a>0&&(n={...n,y:y(n.y,a,s.length,i)});let r=this.createSnapshot(s,n);return this.sourceData=s,this.samplingOptions=n,this.publishSnapshot(r)}updateSamplingRange(t){let e=this.getSourceSize(this.sourceData);if(0===e.width||0===e.height)throw new u("设置采样范围前必须先设置瀑布图数据");w(t.outputWidth,"outputWidth"),w(t.outputHeight,"outputHeight");let a={x:D(t.x,e.width,"X"),y:D(t.y,e.height,"Y"),outputWidth:t.outputWidth,outputHeight:t.outputHeight},s=this.createSnapshot(this.sourceData,a);return this.samplingOptions=a,this.publishSnapshot(s)}getSnapshot(){return this.snapshot}createSnapshot(t,e){let a=this.getSourceSize(t);if(0===a.width||0===a.height)return d();let s=e?.x??[0,a.width],i=e?.y??[0,a.height],n=e?.outputWidth??s[1]-s[0],r=e?.outputHeight??i[1]-i[0],l=I(s,n),o=I(i,r),h=this.createReusableRows(s,l);return{data:Array.from(o,e=>{let a=t[e];return h.get(a)??C(a,s,n)}),rawData:t,range:{x:s,y:i},sourceSize:a,columnIndices:l,rowIndices:o}}createReusableRows(t,e){let a=this.snapshot;if(!A(a.range.x,t)||!S(a.columnIndices,e))return new Map;let s=new Map;for(let t=0;t<a.rowIndices.length;t++){let e=a.rawData[a.rowIndices[t]],i=a.data[t];e&&i&&s.set(e,i)}return s}getSourceSize(t){return{width:t[0]?.length??0,height:t.length}}publishSnapshot(t){return this.snapshot=t,this.onWaterfallUpdate?.(t),t}}let E={DEFAULT_CACHE_TIME:15e3,DEFAULT_GRANULARITY:10,DEFAULT_RANGE:[-20,100]},v={cacheTime:E.DEFAULT_CACHE_TIME,granularity:E.DEFAULT_GRANULARITY,range:E.DEFAULT_RANGE,maxPoints:void 0,onLevelStreamUpdate:t=>{}},M=null,N=!1,R=null;function k(){return"u">typeof process&&"object"==typeof process.versions&&!!process.versions?.node}async function F(){N||(R||(R=(async()=>{let t=await import("./src-rust/pkg/rfkit_spectrum_analyzer_wasm.js");if("function"==typeof t.default)if(k()){let e=new URL("./src-rust/pkg/rfkit_spectrum_analyzer_wasm_bg.wasm",import.meta.url);if("file:"===e.protocol){let{readFile:a}=await import("node:fs/promises"),s=await a(e);await t.default({module_or_path:s})}else await t.default()}else await t.default();M=t,N=!0})()),await R)}function T(){return N}function L(){if(!M)throw Error('WASM not initialized. Call `await initWasm()` before using WASM classes.\nExample:\n import { initWasm } from "@rfkit/spectrum-analyzer/wasm";\n await initWasm();');return M}function O(){if(!N)throw Error('WASM not initialized. Call `await initWasm()` before creating WASM instances.\nExample:\n import { initWasm, SpectrumAnalyzer } from "@rfkit/spectrum-analyzer/wasm";\n await initWasm();\n const analyzer = new SpectrumAnalyzer(config);')}class U{wasmInstance;onLevelStreamUpdate;config;constructor(t){O();let e=L();this.onLevelStreamUpdate=t.onLevelStreamUpdate;let{onLevelStreamUpdate:a,...s}=t;this.config={cacheTime:v.cacheTime,granularity:v.granularity,range:[...v.range],maxPoints:v.maxPoints,...s},this.wasmInstance=new e.WasmLevelStreamAnalyzer(this.config),this.onLevelStreamUpdate&&this.wasmInstance.set_callback(t=>{this.onLevelStreamUpdate?.(t)})}process(t,e){this.wasmInstance.process(t,e)}reset(){this.wasmInstance.reset()}setConfig(t){"onLevelStreamUpdate"in t&&(this.onLevelStreamUpdate=t.onLevelStreamUpdate,this.wasmInstance.set_callback(t=>{this.onLevelStreamUpdate?.(t)}));let e=void 0!==t.cacheTime&&this.config.cacheTime!==t.cacheTime||void 0!==t.granularity&&this.config.granularity!==t.granularity||void 0!==t.maxPoints&&this.config.maxPoints!==t.maxPoints,{onLevelStreamUpdate:a,...s}=t,i={...this.config,...s};this.config=i,this.wasmInstance.set_config(i,e,!!t.range)}getAll(){return this.wasmInstance.get_all()}}class P{wasmInstance;onSpectrumUpdate;hasSegments=!1;segments=[];callbackContext=null;waterfallSink;templateDataRaw=new Float32Array(0);backgroundNoiseDataRaw=new Float32Array(0);thresholdDataRaw=new Float32Array(0);antennaFactorData;srcIndexCache;extraData={};antennaFactorSwitch=!1;config;constructor(t){O();let e=L();this.onSpectrumUpdate=t.onSpectrumUpdate;let{onSpectrumUpdate:a,...s}=t;this.wasmInstance=new e.WasmSpectrumAnalyzer(s),this.wasmInstance.set_callback(t=>{let e=this.convertOutput(t);if(!e)return;let a=this.waterfallSink,s=this.callbackContext,i=!Object.hasOwn(t,"occupancyData");if(a){if(s?.type==="reset"||s?.type==="initializeSegments"||s?.type==="process"&&i)a.reset();else if(s?.waterfallAppend===!0&&e.realData)a.append(e.realData,this.config.waterfallMaxFrames);else if(s?.waterfallReplace===!0&&e.waterfallData?.some(t=>t.length>0)){let t="number"==typeof s.waterfallCapacity?s.waterfallCapacity:this.config.waterfallMaxFrames;a.replace(e.waterfallData,t)}delete e.waterfallData}e.srcIndexCache&&(this.srcIndexCache=e.srcIndexCache),this.onSpectrumUpdate?.(e)}),this.antennaFactorData=this.wasmInstance.get_antenna_factor_view(),this.srcIndexCache=this.wasmInstance.get_src_index_cache_view(),this.config=this.readConfig()}readConfig(){let t=this.wasmInstance.get_config();return{initialValue:n.INITIAL_VALUE,...t}}normalizeSeriesData(t){let e=new Float32Array(this.config.maxPoints);return e.fill(n.INITIAL_VALUE),e.set(t.subarray(0,this.config.maxPoints)),e}resampleSingleDataLikeJs(t){let{outputRange:{start:e,end:a}}=this.config,s=t.subarray(e,a),i=this.srcIndexCache.length,n=new Float32Array(i);for(let t=0;t<i;t++)n[t]=s[this.srcIndexCache[t]];return n}normalizeSegments(t){let e=0;return t.map(t=>{let{startFrequency:a,stopFrequency:s,stepFrequency:i}=t,n=Math.round(1e3*(s-a)/i)+1,r=e;return e+=n,{startFrequency:a,stopFrequency:s,stepFrequency:i,pointCount:n,startIndex:r}})}resolveGlobalIndex(t=0,e=0){if(this.segments.length>0){let a=this.segments[t];if(!a)throw new u(c.INVALID_SEGMENT(t));return a.startIndex+e}return e}validateSegmentInput(t,e){if(e<0||e+t.length>this.config.maxPoints)throw new p(c.INDEX_OUT_OF_BOUNDS(e),e)}clearLocalResetMirrors(){this.templateDataRaw=new Float32Array(0),this.backgroundNoiseDataRaw=new Float32Array(0),this.thresholdDataRaw=new Float32Array(0),this.extraData={}}convertOutput(t){let e=this.callbackContext;if(e?.type==="setExtraData"&&e.mode===f.CLEAR)return null;let a={...t};a.realData&&void 0!==a.timestamp&&(a.realData.timestamp=a.timestamp),delete a.timestamp,void 0!==a.peakStats&&a.realData&&(a.realData.peaks=a.peakStats),delete a.peakStats;let s=t=>Object.fromEntries(t.map(t=>[t,a[t]])),i=t=>{"fluorescenceData"in t||(t.fluorescenceData=void 0),"fluorescenceMaxCount"in t||(t.fluorescenceMaxCount=0)},n=!("occupancyData"in a);switch(e?.type){case"process":if(n)return s(["realData","maxData","minData","avgData","templateData","backgroundNoiseData","thresholdData","extraData","srcIndexCache","processTimes","scanProgress"]);return i(a),"templateOverData"in a||(a.templateOverData=[]),s(["realData","maxData","minData","avgData","templateData","occupancyData","backgroundNoiseData","thresholdData","fluorescenceData","fluorescenceMaxCount","extraData","srcIndexCache","waterfallData","scanProgress","processTimes","templateOverData"]);case"setAntennaFactorSwitch":case"updateSamplingRange":return i(a),s(["realData","maxData","minData","avgData","templateData","occupancyData","backgroundNoiseData","thresholdData","fluorescenceData","fluorescenceMaxCount","extraData","srcIndexCache","waterfallData"]);case"updateProcessing":case"setRealData":case"setMaxData":case"setMinData":case"setAvgData":return i(a),s(["realData","maxData","minData","avgData","templateData","occupancyData","backgroundNoiseData","thresholdData","fluorescenceData","fluorescenceMaxCount","extraData","srcIndexCache"]);case"clearMetricsData":return s(["maxData","minData","avgData","processTimes"]);case"setFluorescenceData":return s(["fluorescenceData","fluorescenceMaxCount"]);case"setTemplateData":return{templateData:this.resampleSingleDataLikeJs(this.templateDataRaw),templateOverData:a.templateOverData??[]};case"setOccupancyData":return{occupancyData:a.occupancyData??new Float32Array(0)};case"setBackgroundNoiseData":return{backgroundNoiseData:this.resampleSingleDataLikeJs(this.backgroundNoiseDataRaw)};case"setThresholdData":return{thresholdData:this.resampleSingleDataLikeJs(this.thresholdDataRaw)};case"setExtraData":return{extraData:a.extraData??{}};case"setWaterfallData":return{waterfallData:a.waterfallData??[]};case"reset":case"initializeSegments":return s(["realData","maxData","minData","avgData","templateData","backgroundNoiseData","thresholdData","extraData","srcIndexCache","processTimes","scanProgress"]);default:return a}}withCallbackContext(t,e){let a=this.callbackContext;this.callbackContext=t;try{return e()}finally{this.callbackContext=a}}withWaterfallReplace(t,e){if(!(void 0!==this.waterfallSink&&this.config.processing.enableWaterfall))return this.withCallbackContext(t,e);this.wasmInstance.set_waterfall_sink_enabled(!1);try{return this.withCallbackContext({...t,waterfallReplace:!0},e)}finally{this.wasmInstance.set_waterfall_sink_enabled(!0)}}setWaterfallSink(t){let e=void 0!==this.waterfallSink;if(this.waterfallSink=t??void 0,this.wasmInstance.set_waterfall_sink_enabled(!!t),!t)return;if(!this.config.processing.enableWaterfall){e&&t.reset();return}let a=this.getAllRawData().waterfallData,s=a.some(t=>t.length>0);(e||s)&&t.reset(),s&&t.replace(a,this.config.waterfallMaxFrames)}getWaterfallTimestamps(t){let e=Number.isFinite(t)?Math.max(0,Math.floor(t)):0;return this.wasmInstance.get_waterfall_timestamps(e)}process(t){let e=this.config.maxPoints,a=!1;if(t.data?.length){let e=this.resolveGlobalIndex(t.segmentOffset??0,t.offset??0);if(this.segments.length>0)this.validateSegmentInput(t.data,e);else if(e<0||t.data.length===this.config.maxPoints&&e+t.data.length>this.config.maxPoints)throw new p(c.INDEX_OUT_OF_BOUNDS(e),e);a=this.config.processing.enableWaterfall&&(0===this.segments.length||e+t.data.length>=this.config.maxPoints)}try{this.withCallbackContext({type:"process",waterfallAppend:a},()=>{this.wasmInstance.process(t.data,String(t.timestamp),t.segmentOffset??0,t.offset??0,t.fluorescenceData,t.fluorescenceMaxCount)})}catch(a){let e=String(a instanceof Error?a.message:a??"");if(e.includes("Data exceeds max points")||e.includes("Index out of bounds")){let e=this.resolveGlobalIndex(t.segmentOffset??0,t.offset??0);throw new p(c.INDEX_OUT_OF_BOUNDS(e),e)}throw a instanceof Error?a:Error(e)}finally{this.hasSegments||t.data.length===e||(this.config=this.readConfig(),this.antennaFactorData=this.wasmInstance.get_antenna_factor_view(),this.srcIndexCache=this.wasmInstance.get_src_index_cache_view(),this.clearLocalResetMirrors())}}initializeSegments(t){if(!t?.length)throw new u(c.EMPTY_SEGMENTS);this.withCallbackContext({type:"initializeSegments"},()=>{this.wasmInstance.initialize_segments(t)}),this.hasSegments=!0,this.segments=this.normalizeSegments(t),this.clearLocalResetMirrors(),this.config=this.readConfig(),this.antennaFactorData=this.wasmInstance.get_antenna_factor_view(),this.srcIndexCache=this.wasmInstance.get_src_index_cache_view()}updateSamplingRange(t,e){if(t<0||t>=e)throw new u(c.INVALID_SAMPLING_RANGE);let a=this.withWaterfallReplace({type:"updateSamplingRange"},()=>this.wasmInstance.update_sampling_range(t,e));return this.srcIndexCache=a,this.config=this.readConfig(),a}reset(t){this.withCallbackContext({type:"reset"},()=>{this.wasmInstance.reset(t??!1)}),this.clearLocalResetMirrors(),this.antennaFactorData=this.wasmInstance.get_antenna_factor_view(),this.srcIndexCache=this.wasmInstance.get_src_index_cache_view(),this.config=this.readConfig()}setAntennaFactor(t){let e=t instanceof Float32Array?t:new Float32Array(t);e.length!==this.config.maxPoints&&console.warn(c.INVALID_ANTENNA_FACTOR_LENGTH(this.config.maxPoints));let a=!1;for(let t=0;t<e.length;t++)if(!(Number.isFinite(e[t])&&e[t]>0)){a=!0;break}a&&console.warn(c.INVALID_ANTENNA_FACTOR),this.wasmInstance.set_antenna_factor(e),this.antennaFactorData=this.wasmInstance.get_antenna_factor_view()}setAntennaFactorSwitch(t){this.withWaterfallReplace({type:"setAntennaFactorSwitch"},()=>{this.wasmInstance.set_antenna_factor_switch(t)}),this.antennaFactorSwitch=t}setRealData(t){this.withCallbackContext({type:"setRealData"},()=>{this.wasmInstance.set_real_data(t,String(t.timestamp))})}setMaxData(t){this.withCallbackContext({type:"setMaxData"},()=>{this.wasmInstance.set_max_data(t)})}setMinData(t){this.withCallbackContext({type:"setMinData"},()=>{this.wasmInstance.set_min_data(t)})}setAvgData(t){this.withCallbackContext({type:"setAvgData"},()=>{this.wasmInstance.set_avg_data(t)})}setWaterfallData(t){this.withWaterfallReplace({type:"setWaterfallData",waterfallCapacity:t.length},()=>{this.wasmInstance.set_waterfall_data(t)}),this.config=this.readConfig()}setTemplateData(t,e){if(t&&0!==t.length){let a=t instanceof Float32Array?t:new Float32Array(t);this.templateDataRaw=new Float32Array(a),this.withCallbackContext({type:"setTemplateData"},()=>{this.wasmInstance.set_template_data(a,e)})}else{this.templateDataRaw=new Float32Array(0),this.withCallbackContext({type:"setTemplateData"},()=>{this.wasmInstance.set_template_data(void 0,void 0)});return}void 0!==e&&(this.config=this.readConfig())}setOccupancyData(t){if(t&&0!==t.length){let e=t instanceof Float32Array?t:new Float32Array(t);this.withCallbackContext({type:"setOccupancyData"},()=>{this.wasmInstance.set_occupancy_data(e)})}else this.withCallbackContext({type:"setOccupancyData"},()=>{this.wasmInstance.set_occupancy_data(void 0)})}setBackgroundNoiseData(t){if(t&&0!==t.length){let e=t instanceof Float32Array?t:new Float32Array(t);this.backgroundNoiseDataRaw=new Float32Array(e),this.withCallbackContext({type:"setBackgroundNoiseData"},()=>{this.wasmInstance.set_background_noise_data(e)})}else this.backgroundNoiseDataRaw=new Float32Array(0),this.withCallbackContext({type:"setBackgroundNoiseData"},()=>{this.wasmInstance.set_background_noise_data(void 0)})}setThresholdData(t,e){if(t&&0!==t.length){let a,s,i=t instanceof Float32Array?t:new Float32Array(t),r=0;if(e){let t=this.resolveGlobalIndex(e.segmentOffset??0,e.offset??0);this.validateSegmentInput(i,t),this.thresholdDataRaw.length===this.config.maxPoints?(s=new Float32Array(this.thresholdDataRaw.subarray(t,t+i.length)),r=t):(a=this.thresholdDataRaw,this.thresholdDataRaw=new Float32Array(this.config.maxPoints),this.thresholdDataRaw.fill(n.INITIAL_VALUE),a.length>0&&this.thresholdDataRaw.set(a.subarray(0,this.config.maxPoints))),this.thresholdDataRaw.set(i,t)}else a=this.thresholdDataRaw,this.thresholdDataRaw=new Float32Array(this.config.maxPoints),this.thresholdDataRaw.fill(n.INITIAL_VALUE),this.thresholdDataRaw.set(i.subarray(0,this.config.maxPoints));try{this.withCallbackContext({type:"setThresholdData"},()=>{this.wasmInstance.set_threshold_data(i,e?e.segmentOffset??0:void 0,e?e.offset??0:void 0)})}catch(t){throw a?this.thresholdDataRaw=a:s&&this.thresholdDataRaw.set(s,r),t}}else this.thresholdDataRaw=new Float32Array(0),this.withCallbackContext({type:"setThresholdData"},()=>{this.wasmInstance.set_threshold_data(void 0,void 0,void 0)})}setExtraData(t,e=f.MERGE,a){if(e===f.CLEAR){this.extraData={},this.withCallbackContext({type:"setExtraData",mode:e},()=>{this.wasmInstance.set_extra_data(null,e,void 0,void 0)});return}if(!t){e===f.REPLACE&&(this.extraData={},this.withCallbackContext({type:"setExtraData",mode:e},()=>{this.wasmInstance.set_extra_data(null,e,void 0,void 0)}));return}let s=Object.entries(t).map(([t,e])=>[t,e?.length?new Float32Array(e):null]),i=a?this.resolveGlobalIndex(a.segmentOffset??0,a.offset??0):0;if(a)for(let[,t]of s)t&&this.validateSegmentInput(t,i);for(let[t,r]of(e===f.REPLACE&&(this.extraData={}),s)){if(!r){delete this.extraData[t];continue}if(!a){this.extraData[t]=this.normalizeSeriesData(r);continue}let e=this.extraData[t];if(e?.length!==this.config.maxPoints){let a=new Float32Array(this.config.maxPoints);a.fill(n.INITIAL_VALUE),e?.length&&a.set(e.subarray(0,this.config.maxPoints)),e=a,this.extraData[t]=e}e.set(r,i)}this.withCallbackContext({type:"setExtraData",mode:e},()=>{this.wasmInstance.set_extra_data(t,e,a?.segmentOffset,a?.offset)})}getPerformanceMetrics(){return this.wasmInstance.get_performance_metrics()}updateProcessing(t){this.withCallbackContext({type:"updateProcessing"},()=>{this.wasmInstance.update_processing(t)}),this.config=this.readConfig()}clearMetricsData(){this.withCallbackContext({type:"clearMetricsData"},()=>{this.wasmInstance.clear_metrics_data()})}getPeakStats(){let t=this.wasmInstance.get_peak_stats();if(null!=t)return t}setFluorescenceData(t,e){this.withCallbackContext({type:"setFluorescenceData"},()=>{this.wasmInstance.set_fluorescence_data(t,e)})}getAllRawData(t){return this.wasmInstance.get_all_raw_data(t)}}export{u as DataValidationError,c as ERROR_MESSAGES,p as IndexOutOfBoundsError,U as LevelStreamAnalyzer,n as SPECTRUM,i as SeriesManager,P as SpectrumAnalyzer,m as SpectrumError,b as WaterfallAnalyzer,F as initWasm,T as isWasmReady,f as ExtraDataMode,e as GraphicType,t as OrientationType,a as SeriesEventType};
@@ -1,2 +1,2 @@
1
1
  let wasm;function addToExternrefTable0(e){let t=wasm.__externref_table_alloc();return wasm.__wbindgen_externrefs.set(t,e),t}function debugString(e){let t,r=typeof e;if("number"==r||"boolean"==r||null==e)return`${e}`;if("string"==r)return`"${e}"`;if("symbol"==r){let t=e.description;return null==t?"Symbol":`Symbol(${t})`}if("function"==r){let t=e.name;return"string"==typeof t&&t.length>0?`Function(${t})`:"Function"}if(Array.isArray(e)){let t=e.length,r="[";t>0&&(r+=debugString(e[0]));for(let a=1;a<t;a++)r+=", "+debugString(e[a]);return r+"]"}let a=/\[object ([^\]]+)\]/.exec(toString.call(e));if(!a||!(a.length>1))return toString.call(e);if("Object"==(t=a[1]))try{return"Object("+JSON.stringify(e)+")"}catch(e){return"Object"}return e instanceof Error?`${e.name}: ${e.message}
2
- ${e.stack}`:t}function getArrayF32FromWasm0(e,t){return e>>>=0,getFloat32ArrayMemory0().subarray(e/4,e/4+t)}function getArrayF64FromWasm0(e,t){return e>>>=0,getFloat64ArrayMemory0().subarray(e/8,e/8+t)}function getArrayJsValueFromWasm0(e,t){e>>>=0;let r=getDataViewMemory0(),a=[];for(let n=e;n<e+4*t;n+=4)a.push(wasm.__wbindgen_externrefs.get(r.getUint32(n,!0)));return wasm.__externref_drop_slice(e,t),a}function getArrayU32FromWasm0(e,t){return e>>>=0,getUint32ArrayMemory0().subarray(e/4,e/4+t)}function getArrayU8FromWasm0(e,t){return e>>>=0,getUint8ArrayMemory0().subarray(e/1,e/1+t)}let cachedDataViewMemory0=null;function getDataViewMemory0(){return(null===cachedDataViewMemory0||!0===cachedDataViewMemory0.buffer.detached||void 0===cachedDataViewMemory0.buffer.detached&&cachedDataViewMemory0.buffer!==wasm.memory.buffer)&&(cachedDataViewMemory0=new DataView(wasm.memory.buffer)),cachedDataViewMemory0}let cachedFloat32ArrayMemory0=null;function getFloat32ArrayMemory0(){return(null===cachedFloat32ArrayMemory0||0===cachedFloat32ArrayMemory0.byteLength)&&(cachedFloat32ArrayMemory0=new Float32Array(wasm.memory.buffer)),cachedFloat32ArrayMemory0}let cachedFloat64ArrayMemory0=null;function getFloat64ArrayMemory0(){return(null===cachedFloat64ArrayMemory0||0===cachedFloat64ArrayMemory0.byteLength)&&(cachedFloat64ArrayMemory0=new Float64Array(wasm.memory.buffer)),cachedFloat64ArrayMemory0}function getStringFromWasm0(e,t){return decodeText(e>>>=0,t)}let cachedUint32ArrayMemory0=null;function getUint32ArrayMemory0(){return(null===cachedUint32ArrayMemory0||0===cachedUint32ArrayMemory0.byteLength)&&(cachedUint32ArrayMemory0=new Uint32Array(wasm.memory.buffer)),cachedUint32ArrayMemory0}let cachedUint8ArrayMemory0=null;function getUint8ArrayMemory0(){return(null===cachedUint8ArrayMemory0||0===cachedUint8ArrayMemory0.byteLength)&&(cachedUint8ArrayMemory0=new Uint8Array(wasm.memory.buffer)),cachedUint8ArrayMemory0}function handleError(e,t){try{return e.apply(this,t)}catch(t){let e=addToExternrefTable0(t);wasm.__wbindgen_exn_store(e)}}function isLikeNone(e){return null==e}function passStringToWasm0(e,t,r){if(void 0===r){let r=cachedTextEncoder.encode(e),a=t(r.length,1)>>>0;return getUint8ArrayMemory0().subarray(a,a+r.length).set(r),WASM_VECTOR_LEN=r.length,a}let a=e.length,n=t(a,1)>>>0,_=getUint8ArrayMemory0(),i=0;for(;i<a;i++){let t=e.charCodeAt(i);if(t>127)break;_[n+i]=t}if(i!==a){0!==i&&(e=e.slice(i)),n=r(n,a,a=i+3*e.length,1)>>>0;let t=getUint8ArrayMemory0().subarray(n+i,n+a);i+=cachedTextEncoder.encodeInto(e,t).written,n=r(n,a,i,1)>>>0}return WASM_VECTOR_LEN=i,n}function takeFromExternrefTable0(e){let t=wasm.__wbindgen_externrefs.get(e);return wasm.__externref_table_dealloc(e),t}let cachedTextDecoder=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});cachedTextDecoder.decode();let MAX_SAFARI_DECODE_BYTES=0x7ff00000,numBytesDecoded=0;function decodeText(e,t){return(numBytesDecoded+=t)>=0x7ff00000&&((cachedTextDecoder=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0})).decode(),numBytesDecoded=t),cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(e,e+t))}let cachedTextEncoder=new TextEncoder;"encodeInto"in cachedTextEncoder||(cachedTextEncoder.encodeInto=function(e,t){let r=cachedTextEncoder.encode(e);return t.set(r),{read:e.length,written:r.length}});let WASM_VECTOR_LEN=0,WasmLevelStreamAnalyzerFinalization="u"<typeof FinalizationRegistry?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>wasm.__wbg_wasmlevelstreamanalyzer_free(e>>>0,1)),WasmSpectrumAnalyzerFinalization="u"<typeof FinalizationRegistry?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>wasm.__wbg_wasmspectrumanalyzer_free(e>>>0,1));export class WasmLevelStreamAnalyzer{__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,WasmLevelStreamAnalyzerFinalization.unregister(this),e}free(){let e=this.__destroy_into_raw();wasm.__wbg_wasmlevelstreamanalyzer_free(e,0)}set_config(e,t,r){let a=wasm.wasmlevelstreamanalyzer_set_config(this.__wbg_ptr,e,t,r);if(a[1])throw takeFromExternrefTable0(a[0])}set_callback(e){wasm.wasmlevelstreamanalyzer_set_callback(this.__wbg_ptr,e)}constructor(e){let t=wasm.wasmlevelstreamanalyzer_new(e);if(t[2])throw takeFromExternrefTable0(t[1]);return this.__wbg_ptr=t[0]>>>0,WasmLevelStreamAnalyzerFinalization.register(this,this.__wbg_ptr,this),this}reset(){wasm.wasmlevelstreamanalyzer_reset(this.__wbg_ptr)}get_all(){return wasm.wasmlevelstreamanalyzer_get_all(this.__wbg_ptr)}process(e,t){wasm.wasmlevelstreamanalyzer_process(this.__wbg_ptr,e,t)}}Symbol.dispose&&(WasmLevelStreamAnalyzer.prototype[Symbol.dispose]=WasmLevelStreamAnalyzer.prototype.free);export class WasmSpectrumAnalyzer{__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,WasmSpectrumAnalyzerFinalization.unregister(this),e}free(){let e=this.__destroy_into_raw();wasm.__wbg_wasmspectrumanalyzer_free(e,0)}get_config(){return wasm.wasmspectrumanalyzer_get_config(this.__wbg_ptr)}set_avg_data(e){wasm.wasmspectrumanalyzer_set_avg_data(this.__wbg_ptr,e)}set_callback(e){wasm.wasmspectrumanalyzer_set_callback(this.__wbg_ptr,e)}set_max_data(e){wasm.wasmspectrumanalyzer_set_max_data(this.__wbg_ptr,e)}set_min_data(e){wasm.wasmspectrumanalyzer_set_min_data(this.__wbg_ptr,e)}set_real_data(e,t){let r=passStringToWasm0(t,wasm.__wbindgen_malloc,wasm.__wbindgen_realloc),a=WASM_VECTOR_LEN;wasm.wasmspectrumanalyzer_set_real_data(this.__wbg_ptr,e,r,a)}get_peak_stats(){return wasm.wasmspectrumanalyzer_get_peak_stats(this.__wbg_ptr)}set_extra_data(e,t,r,a){var n=isLikeNone(t)?0:passStringToWasm0(t,wasm.__wbindgen_malloc,wasm.__wbindgen_realloc),_=WASM_VECTOR_LEN;let i=wasm.wasmspectrumanalyzer_set_extra_data(this.__wbg_ptr,e,n,_,isLikeNone(r)?0x100000001:r>>>0,isLikeNone(a)?0x100000001:a>>>0);if(i[1])throw takeFromExternrefTable0(i[0])}get_all_raw_data(e){let t=wasm.wasmspectrumanalyzer_get_all_raw_data(this.__wbg_ptr,!isLikeNone(e),isLikeNone(e)?0:e);if(t[2])throw takeFromExternrefTable0(t[1]);return takeFromExternrefTable0(t[0])}set_template_data(e,t){wasm.wasmspectrumanalyzer_set_template_data(this.__wbg_ptr,isLikeNone(e)?0:addToExternrefTable0(e),isLikeNone(t)?0x100000001:Math.fround(t))}update_processing(e){let t=wasm.wasmspectrumanalyzer_update_processing(this.__wbg_ptr,e);if(t[1])throw takeFromExternrefTable0(t[0])}clear_metrics_data(){wasm.wasmspectrumanalyzer_clear_metrics_data(this.__wbg_ptr)}set_antenna_factor(e){wasm.wasmspectrumanalyzer_set_antenna_factor(this.__wbg_ptr,e)}set_occupancy_data(e){wasm.wasmspectrumanalyzer_set_occupancy_data(this.__wbg_ptr,isLikeNone(e)?0:addToExternrefTable0(e))}set_threshold_data(e,t,r){let a=wasm.wasmspectrumanalyzer_set_threshold_data(this.__wbg_ptr,isLikeNone(e)?0:addToExternrefTable0(e),isLikeNone(t)?0x100000001:t>>>0,isLikeNone(r)?0x100000001:r>>>0);if(a[1])throw takeFromExternrefTable0(a[0])}set_waterfall_data(e){let t=wasm.wasmspectrumanalyzer_set_waterfall_data(this.__wbg_ptr,e);if(t[1])throw takeFromExternrefTable0(t[0])}get_extra_data_keys(){let e=wasm.wasmspectrumanalyzer_get_extra_data_keys(this.__wbg_ptr);var t=getArrayJsValueFromWasm0(e[0],e[1]).slice();return wasm.__wbindgen_free(e[0],4*e[1],4),t}get_extra_data_view(e){let t=passStringToWasm0(e,wasm.__wbindgen_malloc,wasm.__wbindgen_realloc),r=WASM_VECTOR_LEN;return wasm.wasmspectrumanalyzer_get_extra_data_view(this.__wbg_ptr,t,r)}initialize_segments(e){let t=wasm.wasmspectrumanalyzer_initialize_segments(this.__wbg_ptr,e);if(t[1])throw takeFromExternrefTable0(t[0])}set_fluorescence_data(e,t){wasm.wasmspectrumanalyzer_set_fluorescence_data(this.__wbg_ptr,e,t)}update_sampling_range(e,t){return wasm.wasmspectrumanalyzer_update_sampling_range(this.__wbg_ptr,e,t)}get_antenna_factor_view(){return wasm.wasmspectrumanalyzer_get_antenna_factor_view(this.__wbg_ptr)}get_performance_metrics(){return wasm.wasmspectrumanalyzer_get_performance_metrics(this.__wbg_ptr)}get_src_index_cache_view(){return wasm.wasmspectrumanalyzer_get_src_index_cache_view(this.__wbg_ptr)}set_antenna_factor_switch(e){wasm.wasmspectrumanalyzer_set_antenna_factor_switch(this.__wbg_ptr,e)}set_background_noise_data(e){wasm.wasmspectrumanalyzer_set_background_noise_data(this.__wbg_ptr,isLikeNone(e)?0:addToExternrefTable0(e))}constructor(e){let t=wasm.wasmspectrumanalyzer_new(e);if(t[2])throw takeFromExternrefTable0(t[1]);return this.__wbg_ptr=t[0]>>>0,WasmSpectrumAnalyzerFinalization.register(this,this.__wbg_ptr,this),this}reset(e){wasm.wasmspectrumanalyzer_reset(this.__wbg_ptr,e)}process(e,t,r,a,n,_){let i=passStringToWasm0(t,wasm.__wbindgen_malloc,wasm.__wbindgen_realloc),s=WASM_VECTOR_LEN,o=wasm.wasmspectrumanalyzer_process(this.__wbg_ptr,e,i,s,r,a,isLikeNone(n)?0:addToExternrefTable0(n),isLikeNone(_)?0x100000001:_>>>0);if(o[1])throw takeFromExternrefTable0(o[0])}}Symbol.dispose&&(WasmSpectrumAnalyzer.prototype[Symbol.dispose]=WasmSpectrumAnalyzer.prototype.free);export function init(){wasm.init()}let EXPECTED_RESPONSE_TYPES=new Set(["basic","cors","default"]);async function __wbg_load(e,t){if("function"==typeof Response&&e instanceof Response){if("function"==typeof WebAssembly.instantiateStreaming)try{return await WebAssembly.instantiateStreaming(e,t)}catch(t){if(e.ok&&EXPECTED_RESPONSE_TYPES.has(e.type)&&"application/wasm"!==e.headers.get("Content-Type"))console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",t);else throw t}let r=await e.arrayBuffer();return await WebAssembly.instantiate(r,t)}{let r=await WebAssembly.instantiate(e,t);return r instanceof WebAssembly.Instance?{instance:r,module:e}:r}}function __wbg_get_imports(){let e={};return e.wbg={},e.wbg.__wbg_Error_52673b7de5a0ca89=function(e,t){return Error(getStringFromWasm0(e,t))},e.wbg.__wbg_Number_2d1dcfcf4ec51736=function(e){return Number(e)},e.wbg.__wbg_String_8f0eb39a4a4c2f66=function(e,t){let r=passStringToWasm0(String(t),wasm.__wbindgen_malloc,wasm.__wbindgen_realloc),a=WASM_VECTOR_LEN;getDataViewMemory0().setInt32(e+4,a,!0),getDataViewMemory0().setInt32(e+0,r,!0)},e.wbg.__wbg___wbindgen_bigint_get_as_i64_6e32f5e6aff02e1d=function(e,t){let r="bigint"==typeof t?t:void 0;getDataViewMemory0().setBigInt64(e+8,isLikeNone(r)?BigInt(0):r,!0),getDataViewMemory0().setInt32(e+0,!isLikeNone(r),!0)},e.wbg.__wbg___wbindgen_boolean_get_dea25b33882b895b=function(e){let t="boolean"==typeof e?e:void 0;return isLikeNone(t)?0xffffff:+!!t},e.wbg.__wbg___wbindgen_debug_string_adfb662ae34724b6=function(e,t){let r=passStringToWasm0(debugString(t),wasm.__wbindgen_malloc,wasm.__wbindgen_realloc),a=WASM_VECTOR_LEN;getDataViewMemory0().setInt32(e+4,a,!0),getDataViewMemory0().setInt32(e+0,r,!0)},e.wbg.__wbg___wbindgen_in_0d3e1e8f0c669317=function(e,t){return e in t},e.wbg.__wbg___wbindgen_is_bigint_0e1a2e3f55cfae27=function(e){return"bigint"==typeof e},e.wbg.__wbg___wbindgen_is_function_8d400b8b1af978cd=function(e){return"function"==typeof e},e.wbg.__wbg___wbindgen_is_null_dfda7d66506c95b5=function(e){return null===e},e.wbg.__wbg___wbindgen_is_object_ce774f3490692386=function(e){return"object"==typeof e&&null!==e},e.wbg.__wbg___wbindgen_is_undefined_f6b95eab589e0269=function(e){return void 0===e},e.wbg.__wbg___wbindgen_jsval_eq_b6101cc9cef1fe36=function(e,t){return e===t},e.wbg.__wbg___wbindgen_jsval_loose_eq_766057600fdd1b0d=function(e,t){return e==t},e.wbg.__wbg___wbindgen_number_get_9619185a74197f95=function(e,t){let r="number"==typeof t?t:void 0;getDataViewMemory0().setFloat64(e+8,isLikeNone(r)?0:r,!0),getDataViewMemory0().setInt32(e+0,!isLikeNone(r),!0)},e.wbg.__wbg___wbindgen_string_get_a2a31e16edf96e42=function(e,t){let r="string"==typeof t?t:void 0;var a=isLikeNone(r)?0:passStringToWasm0(r,wasm.__wbindgen_malloc,wasm.__wbindgen_realloc),n=WASM_VECTOR_LEN;getDataViewMemory0().setInt32(e+4,n,!0),getDataViewMemory0().setInt32(e+0,a,!0)},e.wbg.__wbg___wbindgen_throw_dd24417ed36fc46e=function(e,t){throw Error(getStringFromWasm0(e,t))},e.wbg.__wbg_call_3020136f7a2d6e44=function(){return handleError(function(e,t,r){return e.call(t,r)},arguments)},e.wbg.__wbg_call_abb4ff46ce38be40=function(){return handleError(function(e,t){return e.call(t)},arguments)},e.wbg.__wbg_done_62ea16af4ce34b24=function(e){return e.done},e.wbg.__wbg_error_7534b8e9a36f1ab4=function(e,t){let r,a;try{r=e,a=t,console.error(getStringFromWasm0(e,t))}finally{wasm.__wbindgen_free(r,a,1)}},e.wbg.__wbg_from_29a8414a7a7cd19d=function(e){return Array.from(e)},e.wbg.__wbg_get_6b7bd52aca3f9671=function(e,t){return e[t>>>0]},e.wbg.__wbg_get_af9dab7e9603ea93=function(){return handleError(function(e,t){return Reflect.get(e,t)},arguments)},e.wbg.__wbg_get_with_ref_key_1dc361bd10053bfe=function(e,t){return e[t]},e.wbg.__wbg_instanceof_ArrayBuffer_f3320d2419cd0355=function(e){let t;try{t=e instanceof ArrayBuffer}catch(e){t=!1}return t},e.wbg.__wbg_instanceof_Uint8Array_da54ccc9d3e09434=function(e){let t;try{t=e instanceof Uint8Array}catch(e){t=!1}return t},e.wbg.__wbg_isArray_51fd9e6422c0a395=function(e){return Array.isArray(e)},e.wbg.__wbg_isSafeInteger_ae7d3f054d55fa16=function(e){return Number.isSafeInteger(e)},e.wbg.__wbg_iterator_27b7c8b35ab3e86b=function(){return Symbol.iterator},e.wbg.__wbg_keys_f5c6002ff150fc6c=function(e){return Object.keys(e)},e.wbg.__wbg_length_22ac23eaec9d8053=function(e){return e.length},e.wbg.__wbg_length_86ce4877baf913bb=function(e){return e.length},e.wbg.__wbg_length_89c3414ed7f0594d=function(e){return e.length},e.wbg.__wbg_length_d45040a40c570362=function(e){return e.length},e.wbg.__wbg_new_1ba21ce319a06297=function(){return{}},e.wbg.__wbg_new_25f239778d6112b9=function(){return[]},e.wbg.__wbg_new_354204b1383f9085=function(e){return new Float32Array(e)},e.wbg.__wbg_new_6421f6084cc5bc5a=function(e){return new Uint8Array(e)},e.wbg.__wbg_new_8a6f238a6ece86ea=function(){return Error()},e.wbg.__wbg_new_b546ae120718850e=function(){return new Map},e.wbg.__wbg_new_from_slice_41e2764a343e3cb1=function(e,t){return new Float32Array(getArrayF32FromWasm0(e,t))},e.wbg.__wbg_new_from_slice_9a48ef80d2a51f94=function(e,t){return new Float64Array(getArrayF64FromWasm0(e,t))},e.wbg.__wbg_new_from_slice_db0691b69e9d3891=function(e,t){return new Uint32Array(getArrayU32FromWasm0(e,t))},e.wbg.__wbg_next_138a17bbf04e926c=function(e){return e.next},e.wbg.__wbg_next_3cfe5c0fe2a4cc53=function(){return handleError(function(e){return e.next()},arguments)},e.wbg.__wbg_now_69d776cd24f5215b=function(){return Date.now()},e.wbg.__wbg_prototypesetcall_6a0ca140cebe5ef8=function(e,t,r){Uint32Array.prototype.set.call(getArrayU32FromWasm0(e,t),r)},e.wbg.__wbg_prototypesetcall_96cc7097487b926d=function(e,t,r){Float32Array.prototype.set.call(getArrayF32FromWasm0(e,t),r)},e.wbg.__wbg_prototypesetcall_dfe9b766cdc1f1fd=function(e,t,r){Uint8Array.prototype.set.call(getArrayU8FromWasm0(e,t),r)},e.wbg.__wbg_push_7d9be8f38fc13975=function(e,t){return e.push(t)},e.wbg.__wbg_set_3f1d0b984ed272ed=function(e,t,r){e[t]=r},e.wbg.__wbg_set_781438a03c0c3c81=function(){return handleError(function(e,t,r){return Reflect.set(e,t,r)},arguments)},e.wbg.__wbg_set_7df433eea03a5c14=function(e,t,r){e[t>>>0]=r},e.wbg.__wbg_set_efaaf145b9377369=function(e,t,r){return e.set(t,r)},e.wbg.__wbg_stack_0ed75d68575b0f3c=function(e,t){let r=passStringToWasm0(t.stack,wasm.__wbindgen_malloc,wasm.__wbindgen_realloc),a=WASM_VECTOR_LEN;getDataViewMemory0().setInt32(e+4,a,!0),getDataViewMemory0().setInt32(e+0,r,!0)},e.wbg.__wbg_value_57b7b035e117f7ee=function(e){return e.value},e.wbg.__wbindgen_cast_2241b6af4c4b2941=function(e,t){return getStringFromWasm0(e,t)},e.wbg.__wbindgen_cast_4625c577ab2ec9ee=function(e){return BigInt.asUintN(64,e)},e.wbg.__wbindgen_cast_d6cd19b81560fd6e=function(e){return e},e.wbg.__wbindgen_init_externref_table=function(){let e=wasm.__wbindgen_externrefs,t=e.grow(4);e.set(0,void 0),e.set(t+0,void 0),e.set(t+1,null),e.set(t+2,!0),e.set(t+3,!1)},e}function __wbg_finalize_init(e,t){return wasm=e.exports,__wbg_init.__wbindgen_wasm_module=t,cachedDataViewMemory0=null,cachedFloat32ArrayMemory0=null,cachedFloat64ArrayMemory0=null,cachedUint32ArrayMemory0=null,cachedUint8ArrayMemory0=null,wasm.__wbindgen_start(),wasm}function initSync(e){if(void 0!==wasm)return wasm;void 0!==e&&(Object.getPrototypeOf(e)===Object.prototype?{module:e}=e:console.warn("using deprecated parameters for `initSync()`; pass a single object instead"));let t=__wbg_get_imports();return e instanceof WebAssembly.Module||(e=new WebAssembly.Module(e)),__wbg_finalize_init(new WebAssembly.Instance(e,t),e)}async function __wbg_init(e){if(void 0!==wasm)return wasm;void 0!==e&&(Object.getPrototypeOf(e)===Object.prototype?{module_or_path:e}=e:console.warn("using deprecated parameters for the initialization function; pass a single object instead")),void 0===e&&(e=new URL("rfkit_spectrum_analyzer_wasm_bg.wasm",import.meta.url));let t=__wbg_get_imports();("string"==typeof e||"function"==typeof Request&&e instanceof Request||"function"==typeof URL&&e instanceof URL)&&(e=fetch(e));let{instance:r,module:a}=await __wbg_load(await e,t);return __wbg_finalize_init(r,a)}export default __wbg_init;export{initSync};
2
+ ${e.stack}`:t}function getArrayF32FromWasm0(e,t){return e>>>=0,getFloat32ArrayMemory0().subarray(e/4,e/4+t)}function getArrayF64FromWasm0(e,t){return e>>>=0,getFloat64ArrayMemory0().subarray(e/8,e/8+t)}function getArrayJsValueFromWasm0(e,t){e>>>=0;let r=getDataViewMemory0(),a=[];for(let n=e;n<e+4*t;n+=4)a.push(wasm.__wbindgen_externrefs.get(r.getUint32(n,!0)));return wasm.__externref_drop_slice(e,t),a}function getArrayU32FromWasm0(e,t){return e>>>=0,getUint32ArrayMemory0().subarray(e/4,e/4+t)}function getArrayU8FromWasm0(e,t){return e>>>=0,getUint8ArrayMemory0().subarray(e/1,e/1+t)}let cachedDataViewMemory0=null;function getDataViewMemory0(){return(null===cachedDataViewMemory0||!0===cachedDataViewMemory0.buffer.detached||void 0===cachedDataViewMemory0.buffer.detached&&cachedDataViewMemory0.buffer!==wasm.memory.buffer)&&(cachedDataViewMemory0=new DataView(wasm.memory.buffer)),cachedDataViewMemory0}let cachedFloat32ArrayMemory0=null;function getFloat32ArrayMemory0(){return(null===cachedFloat32ArrayMemory0||0===cachedFloat32ArrayMemory0.byteLength)&&(cachedFloat32ArrayMemory0=new Float32Array(wasm.memory.buffer)),cachedFloat32ArrayMemory0}let cachedFloat64ArrayMemory0=null;function getFloat64ArrayMemory0(){return(null===cachedFloat64ArrayMemory0||0===cachedFloat64ArrayMemory0.byteLength)&&(cachedFloat64ArrayMemory0=new Float64Array(wasm.memory.buffer)),cachedFloat64ArrayMemory0}function getStringFromWasm0(e,t){return decodeText(e>>>=0,t)}let cachedUint32ArrayMemory0=null;function getUint32ArrayMemory0(){return(null===cachedUint32ArrayMemory0||0===cachedUint32ArrayMemory0.byteLength)&&(cachedUint32ArrayMemory0=new Uint32Array(wasm.memory.buffer)),cachedUint32ArrayMemory0}let cachedUint8ArrayMemory0=null;function getUint8ArrayMemory0(){return(null===cachedUint8ArrayMemory0||0===cachedUint8ArrayMemory0.byteLength)&&(cachedUint8ArrayMemory0=new Uint8Array(wasm.memory.buffer)),cachedUint8ArrayMemory0}function handleError(e,t){try{return e.apply(this,t)}catch(t){let e=addToExternrefTable0(t);wasm.__wbindgen_exn_store(e)}}function isLikeNone(e){return null==e}function passStringToWasm0(e,t,r){if(void 0===r){let r=cachedTextEncoder.encode(e),a=t(r.length,1)>>>0;return getUint8ArrayMemory0().subarray(a,a+r.length).set(r),WASM_VECTOR_LEN=r.length,a}let a=e.length,n=t(a,1)>>>0,_=getUint8ArrayMemory0(),s=0;for(;s<a;s++){let t=e.charCodeAt(s);if(t>127)break;_[n+s]=t}if(s!==a){0!==s&&(e=e.slice(s)),n=r(n,a,a=s+3*e.length,1)>>>0;let t=getUint8ArrayMemory0().subarray(n+s,n+a);s+=cachedTextEncoder.encodeInto(e,t).written,n=r(n,a,s,1)>>>0}return WASM_VECTOR_LEN=s,n}function takeFromExternrefTable0(e){let t=wasm.__wbindgen_externrefs.get(e);return wasm.__externref_table_dealloc(e),t}let cachedTextDecoder=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});cachedTextDecoder.decode();let MAX_SAFARI_DECODE_BYTES=0x7ff00000,numBytesDecoded=0;function decodeText(e,t){return(numBytesDecoded+=t)>=0x7ff00000&&((cachedTextDecoder=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0})).decode(),numBytesDecoded=t),cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(e,e+t))}let cachedTextEncoder=new TextEncoder;"encodeInto"in cachedTextEncoder||(cachedTextEncoder.encodeInto=function(e,t){let r=cachedTextEncoder.encode(e);return t.set(r),{read:e.length,written:r.length}});let WASM_VECTOR_LEN=0,WasmLevelStreamAnalyzerFinalization="u"<typeof FinalizationRegistry?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>wasm.__wbg_wasmlevelstreamanalyzer_free(e>>>0,1)),WasmSpectrumAnalyzerFinalization="u"<typeof FinalizationRegistry?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>wasm.__wbg_wasmspectrumanalyzer_free(e>>>0,1));export class WasmLevelStreamAnalyzer{__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,WasmLevelStreamAnalyzerFinalization.unregister(this),e}free(){let e=this.__destroy_into_raw();wasm.__wbg_wasmlevelstreamanalyzer_free(e,0)}set_config(e,t,r){let a=wasm.wasmlevelstreamanalyzer_set_config(this.__wbg_ptr,e,t,r);if(a[1])throw takeFromExternrefTable0(a[0])}set_callback(e){wasm.wasmlevelstreamanalyzer_set_callback(this.__wbg_ptr,e)}constructor(e){let t=wasm.wasmlevelstreamanalyzer_new(e);if(t[2])throw takeFromExternrefTable0(t[1]);return this.__wbg_ptr=t[0]>>>0,WasmLevelStreamAnalyzerFinalization.register(this,this.__wbg_ptr,this),this}reset(){wasm.wasmlevelstreamanalyzer_reset(this.__wbg_ptr)}get_all(){return wasm.wasmlevelstreamanalyzer_get_all(this.__wbg_ptr)}process(e,t){wasm.wasmlevelstreamanalyzer_process(this.__wbg_ptr,e,t)}}Symbol.dispose&&(WasmLevelStreamAnalyzer.prototype[Symbol.dispose]=WasmLevelStreamAnalyzer.prototype.free);export class WasmSpectrumAnalyzer{__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,WasmSpectrumAnalyzerFinalization.unregister(this),e}free(){let e=this.__destroy_into_raw();wasm.__wbg_wasmspectrumanalyzer_free(e,0)}get_config(){return wasm.wasmspectrumanalyzer_get_config(this.__wbg_ptr)}set_avg_data(e){wasm.wasmspectrumanalyzer_set_avg_data(this.__wbg_ptr,e)}set_callback(e){wasm.wasmspectrumanalyzer_set_callback(this.__wbg_ptr,e)}set_max_data(e){wasm.wasmspectrumanalyzer_set_max_data(this.__wbg_ptr,e)}set_min_data(e){wasm.wasmspectrumanalyzer_set_min_data(this.__wbg_ptr,e)}set_real_data(e,t){let r=passStringToWasm0(t,wasm.__wbindgen_malloc,wasm.__wbindgen_realloc),a=WASM_VECTOR_LEN;wasm.wasmspectrumanalyzer_set_real_data(this.__wbg_ptr,e,r,a)}get_peak_stats(){return wasm.wasmspectrumanalyzer_get_peak_stats(this.__wbg_ptr)}set_extra_data(e,t,r,a){var n=isLikeNone(t)?0:passStringToWasm0(t,wasm.__wbindgen_malloc,wasm.__wbindgen_realloc),_=WASM_VECTOR_LEN;let s=wasm.wasmspectrumanalyzer_set_extra_data(this.__wbg_ptr,e,n,_,isLikeNone(r)?0x100000001:r>>>0,isLikeNone(a)?0x100000001:a>>>0);if(s[1])throw takeFromExternrefTable0(s[0])}get_all_raw_data(e){let t=wasm.wasmspectrumanalyzer_get_all_raw_data(this.__wbg_ptr,!isLikeNone(e),isLikeNone(e)?0:e);if(t[2])throw takeFromExternrefTable0(t[1]);return takeFromExternrefTable0(t[0])}set_template_data(e,t){wasm.wasmspectrumanalyzer_set_template_data(this.__wbg_ptr,isLikeNone(e)?0:addToExternrefTable0(e),isLikeNone(t)?0x100000001:Math.fround(t))}update_processing(e){let t=wasm.wasmspectrumanalyzer_update_processing(this.__wbg_ptr,e);if(t[1])throw takeFromExternrefTable0(t[0])}clear_metrics_data(){wasm.wasmspectrumanalyzer_clear_metrics_data(this.__wbg_ptr)}set_antenna_factor(e){wasm.wasmspectrumanalyzer_set_antenna_factor(this.__wbg_ptr,e)}set_occupancy_data(e){wasm.wasmspectrumanalyzer_set_occupancy_data(this.__wbg_ptr,isLikeNone(e)?0:addToExternrefTable0(e))}set_threshold_data(e,t,r){let a=wasm.wasmspectrumanalyzer_set_threshold_data(this.__wbg_ptr,isLikeNone(e)?0:addToExternrefTable0(e),isLikeNone(t)?0x100000001:t>>>0,isLikeNone(r)?0x100000001:r>>>0);if(a[1])throw takeFromExternrefTable0(a[0])}set_waterfall_data(e){let t=wasm.wasmspectrumanalyzer_set_waterfall_data(this.__wbg_ptr,e);if(t[1])throw takeFromExternrefTable0(t[0])}get_extra_data_keys(){let e=wasm.wasmspectrumanalyzer_get_extra_data_keys(this.__wbg_ptr);var t=getArrayJsValueFromWasm0(e[0],e[1]).slice();return wasm.__wbindgen_free(e[0],4*e[1],4),t}get_extra_data_view(e){let t=passStringToWasm0(e,wasm.__wbindgen_malloc,wasm.__wbindgen_realloc),r=WASM_VECTOR_LEN;return wasm.wasmspectrumanalyzer_get_extra_data_view(this.__wbg_ptr,t,r)}initialize_segments(e){let t=wasm.wasmspectrumanalyzer_initialize_segments(this.__wbg_ptr,e);if(t[1])throw takeFromExternrefTable0(t[0])}set_fluorescence_data(e,t){wasm.wasmspectrumanalyzer_set_fluorescence_data(this.__wbg_ptr,e,t)}update_sampling_range(e,t){return wasm.wasmspectrumanalyzer_update_sampling_range(this.__wbg_ptr,e,t)}get_antenna_factor_view(){return wasm.wasmspectrumanalyzer_get_antenna_factor_view(this.__wbg_ptr)}get_performance_metrics(){return wasm.wasmspectrumanalyzer_get_performance_metrics(this.__wbg_ptr)}get_src_index_cache_view(){return wasm.wasmspectrumanalyzer_get_src_index_cache_view(this.__wbg_ptr)}get_waterfall_timestamps(e){return wasm.wasmspectrumanalyzer_get_waterfall_timestamps(this.__wbg_ptr,e)}set_antenna_factor_switch(e){wasm.wasmspectrumanalyzer_set_antenna_factor_switch(this.__wbg_ptr,e)}set_background_noise_data(e){wasm.wasmspectrumanalyzer_set_background_noise_data(this.__wbg_ptr,isLikeNone(e)?0:addToExternrefTable0(e))}set_waterfall_sink_enabled(e){wasm.wasmspectrumanalyzer_set_waterfall_sink_enabled(this.__wbg_ptr,e)}constructor(e){let t=wasm.wasmspectrumanalyzer_new(e);if(t[2])throw takeFromExternrefTable0(t[1]);return this.__wbg_ptr=t[0]>>>0,WasmSpectrumAnalyzerFinalization.register(this,this.__wbg_ptr,this),this}reset(e){wasm.wasmspectrumanalyzer_reset(this.__wbg_ptr,e)}process(e,t,r,a,n,_){let s=passStringToWasm0(t,wasm.__wbindgen_malloc,wasm.__wbindgen_realloc),i=WASM_VECTOR_LEN,o=wasm.wasmspectrumanalyzer_process(this.__wbg_ptr,e,s,i,r,a,isLikeNone(n)?0:addToExternrefTable0(n),isLikeNone(_)?0x100000001:_>>>0);if(o[1])throw takeFromExternrefTable0(o[0])}}Symbol.dispose&&(WasmSpectrumAnalyzer.prototype[Symbol.dispose]=WasmSpectrumAnalyzer.prototype.free);export function init(){wasm.init()}let EXPECTED_RESPONSE_TYPES=new Set(["basic","cors","default"]);async function __wbg_load(e,t){if("function"==typeof Response&&e instanceof Response){if("function"==typeof WebAssembly.instantiateStreaming)try{return await WebAssembly.instantiateStreaming(e,t)}catch(t){if(e.ok&&EXPECTED_RESPONSE_TYPES.has(e.type)&&"application/wasm"!==e.headers.get("Content-Type"))console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",t);else throw t}let r=await e.arrayBuffer();return await WebAssembly.instantiate(r,t)}{let r=await WebAssembly.instantiate(e,t);return r instanceof WebAssembly.Instance?{instance:r,module:e}:r}}function __wbg_get_imports(){let e={};return e.wbg={},e.wbg.__wbg_Error_52673b7de5a0ca89=function(e,t){return Error(getStringFromWasm0(e,t))},e.wbg.__wbg_Number_2d1dcfcf4ec51736=function(e){return Number(e)},e.wbg.__wbg_String_8f0eb39a4a4c2f66=function(e,t){let r=passStringToWasm0(String(t),wasm.__wbindgen_malloc,wasm.__wbindgen_realloc),a=WASM_VECTOR_LEN;getDataViewMemory0().setInt32(e+4,a,!0),getDataViewMemory0().setInt32(e+0,r,!0)},e.wbg.__wbg___wbindgen_bigint_get_as_i64_6e32f5e6aff02e1d=function(e,t){let r="bigint"==typeof t?t:void 0;getDataViewMemory0().setBigInt64(e+8,isLikeNone(r)?BigInt(0):r,!0),getDataViewMemory0().setInt32(e+0,!isLikeNone(r),!0)},e.wbg.__wbg___wbindgen_boolean_get_dea25b33882b895b=function(e){let t="boolean"==typeof e?e:void 0;return isLikeNone(t)?0xffffff:+!!t},e.wbg.__wbg___wbindgen_debug_string_adfb662ae34724b6=function(e,t){let r=passStringToWasm0(debugString(t),wasm.__wbindgen_malloc,wasm.__wbindgen_realloc),a=WASM_VECTOR_LEN;getDataViewMemory0().setInt32(e+4,a,!0),getDataViewMemory0().setInt32(e+0,r,!0)},e.wbg.__wbg___wbindgen_in_0d3e1e8f0c669317=function(e,t){return e in t},e.wbg.__wbg___wbindgen_is_bigint_0e1a2e3f55cfae27=function(e){return"bigint"==typeof e},e.wbg.__wbg___wbindgen_is_function_8d400b8b1af978cd=function(e){return"function"==typeof e},e.wbg.__wbg___wbindgen_is_null_dfda7d66506c95b5=function(e){return null===e},e.wbg.__wbg___wbindgen_is_object_ce774f3490692386=function(e){return"object"==typeof e&&null!==e},e.wbg.__wbg___wbindgen_is_undefined_f6b95eab589e0269=function(e){return void 0===e},e.wbg.__wbg___wbindgen_jsval_eq_b6101cc9cef1fe36=function(e,t){return e===t},e.wbg.__wbg___wbindgen_jsval_loose_eq_766057600fdd1b0d=function(e,t){return e==t},e.wbg.__wbg___wbindgen_number_get_9619185a74197f95=function(e,t){let r="number"==typeof t?t:void 0;getDataViewMemory0().setFloat64(e+8,isLikeNone(r)?0:r,!0),getDataViewMemory0().setInt32(e+0,!isLikeNone(r),!0)},e.wbg.__wbg___wbindgen_string_get_a2a31e16edf96e42=function(e,t){let r="string"==typeof t?t:void 0;var a=isLikeNone(r)?0:passStringToWasm0(r,wasm.__wbindgen_malloc,wasm.__wbindgen_realloc),n=WASM_VECTOR_LEN;getDataViewMemory0().setInt32(e+4,n,!0),getDataViewMemory0().setInt32(e+0,a,!0)},e.wbg.__wbg___wbindgen_throw_dd24417ed36fc46e=function(e,t){throw Error(getStringFromWasm0(e,t))},e.wbg.__wbg_call_3020136f7a2d6e44=function(){return handleError(function(e,t,r){return e.call(t,r)},arguments)},e.wbg.__wbg_call_abb4ff46ce38be40=function(){return handleError(function(e,t){return e.call(t)},arguments)},e.wbg.__wbg_done_62ea16af4ce34b24=function(e){return e.done},e.wbg.__wbg_error_7534b8e9a36f1ab4=function(e,t){let r,a;try{r=e,a=t,console.error(getStringFromWasm0(e,t))}finally{wasm.__wbindgen_free(r,a,1)}},e.wbg.__wbg_from_29a8414a7a7cd19d=function(e){return Array.from(e)},e.wbg.__wbg_get_6b7bd52aca3f9671=function(e,t){return e[t>>>0]},e.wbg.__wbg_get_af9dab7e9603ea93=function(){return handleError(function(e,t){return Reflect.get(e,t)},arguments)},e.wbg.__wbg_get_with_ref_key_1dc361bd10053bfe=function(e,t){return e[t]},e.wbg.__wbg_instanceof_ArrayBuffer_f3320d2419cd0355=function(e){let t;try{t=e instanceof ArrayBuffer}catch(e){t=!1}return t},e.wbg.__wbg_instanceof_Uint8Array_da54ccc9d3e09434=function(e){let t;try{t=e instanceof Uint8Array}catch(e){t=!1}return t},e.wbg.__wbg_isArray_51fd9e6422c0a395=function(e){return Array.isArray(e)},e.wbg.__wbg_isSafeInteger_ae7d3f054d55fa16=function(e){return Number.isSafeInteger(e)},e.wbg.__wbg_iterator_27b7c8b35ab3e86b=function(){return Symbol.iterator},e.wbg.__wbg_keys_f5c6002ff150fc6c=function(e){return Object.keys(e)},e.wbg.__wbg_length_22ac23eaec9d8053=function(e){return e.length},e.wbg.__wbg_length_86ce4877baf913bb=function(e){return e.length},e.wbg.__wbg_length_89c3414ed7f0594d=function(e){return e.length},e.wbg.__wbg_length_d45040a40c570362=function(e){return e.length},e.wbg.__wbg_new_1ba21ce319a06297=function(){return{}},e.wbg.__wbg_new_25f239778d6112b9=function(){return[]},e.wbg.__wbg_new_354204b1383f9085=function(e){return new Float32Array(e)},e.wbg.__wbg_new_6421f6084cc5bc5a=function(e){return new Uint8Array(e)},e.wbg.__wbg_new_8a6f238a6ece86ea=function(){return Error()},e.wbg.__wbg_new_b546ae120718850e=function(){return new Map},e.wbg.__wbg_new_from_slice_41e2764a343e3cb1=function(e,t){return new Float32Array(getArrayF32FromWasm0(e,t))},e.wbg.__wbg_new_from_slice_9a48ef80d2a51f94=function(e,t){return new Float64Array(getArrayF64FromWasm0(e,t))},e.wbg.__wbg_new_from_slice_db0691b69e9d3891=function(e,t){return new Uint32Array(getArrayU32FromWasm0(e,t))},e.wbg.__wbg_next_138a17bbf04e926c=function(e){return e.next},e.wbg.__wbg_next_3cfe5c0fe2a4cc53=function(){return handleError(function(e){return e.next()},arguments)},e.wbg.__wbg_now_69d776cd24f5215b=function(){return Date.now()},e.wbg.__wbg_prototypesetcall_6a0ca140cebe5ef8=function(e,t,r){Uint32Array.prototype.set.call(getArrayU32FromWasm0(e,t),r)},e.wbg.__wbg_prototypesetcall_96cc7097487b926d=function(e,t,r){Float32Array.prototype.set.call(getArrayF32FromWasm0(e,t),r)},e.wbg.__wbg_prototypesetcall_dfe9b766cdc1f1fd=function(e,t,r){Uint8Array.prototype.set.call(getArrayU8FromWasm0(e,t),r)},e.wbg.__wbg_push_7d9be8f38fc13975=function(e,t){return e.push(t)},e.wbg.__wbg_set_3f1d0b984ed272ed=function(e,t,r){e[t]=r},e.wbg.__wbg_set_781438a03c0c3c81=function(){return handleError(function(e,t,r){return Reflect.set(e,t,r)},arguments)},e.wbg.__wbg_set_7df433eea03a5c14=function(e,t,r){e[t>>>0]=r},e.wbg.__wbg_set_efaaf145b9377369=function(e,t,r){return e.set(t,r)},e.wbg.__wbg_stack_0ed75d68575b0f3c=function(e,t){let r=passStringToWasm0(t.stack,wasm.__wbindgen_malloc,wasm.__wbindgen_realloc),a=WASM_VECTOR_LEN;getDataViewMemory0().setInt32(e+4,a,!0),getDataViewMemory0().setInt32(e+0,r,!0)},e.wbg.__wbg_value_57b7b035e117f7ee=function(e){return e.value},e.wbg.__wbindgen_cast_2241b6af4c4b2941=function(e,t){return getStringFromWasm0(e,t)},e.wbg.__wbindgen_cast_4625c577ab2ec9ee=function(e){return BigInt.asUintN(64,e)},e.wbg.__wbindgen_cast_d6cd19b81560fd6e=function(e){return e},e.wbg.__wbindgen_init_externref_table=function(){let e=wasm.__wbindgen_externrefs,t=e.grow(4);e.set(0,void 0),e.set(t+0,void 0),e.set(t+1,null),e.set(t+2,!0),e.set(t+3,!1)},e}function __wbg_finalize_init(e,t){return wasm=e.exports,__wbg_init.__wbindgen_wasm_module=t,cachedDataViewMemory0=null,cachedFloat32ArrayMemory0=null,cachedFloat64ArrayMemory0=null,cachedUint32ArrayMemory0=null,cachedUint8ArrayMemory0=null,wasm.__wbindgen_start(),wasm}function initSync(e){if(void 0!==wasm)return wasm;void 0!==e&&(Object.getPrototypeOf(e)===Object.prototype?{module:e}=e:console.warn("using deprecated parameters for `initSync()`; pass a single object instead"));let t=__wbg_get_imports();return e instanceof WebAssembly.Module||(e=new WebAssembly.Module(e)),__wbg_finalize_init(new WebAssembly.Instance(e,t),e)}async function __wbg_init(e){if(void 0!==wasm)return wasm;void 0!==e&&(Object.getPrototypeOf(e)===Object.prototype?{module_or_path:e}=e:console.warn("using deprecated parameters for the initialization function; pass a single object instead")),void 0===e&&(e=new URL("rfkit_spectrum_analyzer_wasm_bg.wasm",import.meta.url));let t=__wbg_get_imports();("string"==typeof e||"function"==typeof Request&&e instanceof Request||"function"==typeof URL&&e instanceof URL)&&(e=fetch(e));let{instance:r,module:a}=await __wbg_load(await e,t);return __wbg_finalize_init(r,a)}export default __wbg_init;export{initSync};