Loading
function(l,t,d){d.d(t,{t:()=>i});var i=class{constructor(l){this._isRunning=!1,this._hasPermission=!0,this.acl=null,this.gyro=null,this.minNumberOfFrames=3,this.maxFrequency=60,this.emptyParams={meanX:0,meanY:0,meanZ:0,m2X:0,m2Y:0,m2Z:0,cumulativeAbsErrorX:0,cumulativeAbsErrorY:0,cumulativeAbsErrorZ:0,ptsNum:0},this.paramsAcc={...this.emptyParams},this.paramsGyro={...this.emptyParams},this.paramsAccGrOld={...this.emptyParams},this.paramsAccOld={...this.emptyParams},this.paramsGyroscopeOld={...this.emptyParams},this.paramsOrientationOld={...this.emptyParams},this.deviceMotionListener=l=>{if(l.accelerationIncludingGravity){let t={x:l.accelerationIncludingGravity.x,y:l.accelerationIncludingGravity.y,z:l.accelerationIncludingGravity.z};this.checkFields(t)&&(this.paramsAccGrOld.ptsNum+=1,this.updateParams(this.paramsAccGrOld,t))}if(l.acceleration){let t={x:l.acceleration.x,y:l.acceleration.y,z:l.acceleration.z};this.checkFields(t)&&(this.paramsAccOld.ptsNum+=1,this.updateParams(this.paramsAccOld,t))}if(l.rotationRate){let t={x:l.rotationRate.alpha,y:l.rotationRate.beta,z:l.rotationRate.gamma};this.checkFields(t)&&(this.paramsGyroscopeOld.ptsNum+=1,this.updateParams(this.paramsGyroscopeOld,t))}},this.deviceOrientationListener=l=>{let t={x:l.alpha,y:l.beta,z:l.gamma};this.checkFields(t)&&(this.paramsOrientationOld.ptsNum+=1,this.updateParams(this.paramsOrientationOld,t))},this.thresholds={accThreshold:l?.accThreshold??.3,gyroThreshold:l?.gyroThreshold??.3,accGrOldThreshold:l?.accGrOldThreshold??.3,accOldThreshold:l?.accOldThreshold??.3,gyroscopeOldThreshold:l?.gyroscopeOldThreshold??10,orientationOldThreshold:l?.orientationOldThreshold??10,maeAccThreshold:l?.maeAccThreshold??.3,maeGyroThreshold:l?.maeGyroThreshold??.3,maeAccGrOldThreshold:l?.maeAccGrOldThreshold??.3,maeAccOldThreshold:l?.maeAccOldThreshold??.3,maeGyroscopeOldThreshold:l?.maeGyroscopeOldThreshold??10,maeOrientationOldThreshold:l?.maeOrientationOldThreshold??10}}get isRunning(){return this._isRunning}get hasPermission(){return this._hasPermission}async requestPermission(){if("u">typeof DeviceMotionEvent&&"function"==typeof DeviceMotionEvent.requestPermission){sessionStorage.setItem("motionSensorsPermissionsRequested",String(!0));try{if(await DeviceMotionEvent.requestPermission()!=="granted")return this._hasPermission=!1,"denied";return"granted"}catch{return this._hasPermission=!1,"denied"}}return"not-required"}initializeAccelerometer(){if("Accelerometer"in window)try{let l=window.Accelerometer;l&&(this.acl=new l({frequency:this.maxFrequency}),this.acl.addEventListener("reading",()=>this.updateAcc()))}catch{}}initializeGyroscope(){if("Gyroscope"in window)try{let l=window.Gyroscope;l&&(this.gyro=new l({frequency:this.maxFrequency}),this.gyro.addEventListener("reading",()=>this.updateGyro()))}catch{}}async start(){if(!this._isRunning&&this._hasPermission){try{this.initializeAccelerometer(),this.acl&&this.acl.start()}catch{}try{this.initializeGyroscope(),this.gyro&&this.gyro.start()}catch{}window.addEventListener("devicemotion",this.deviceMotionListener),window.addEventListener("deviceorientation",this.deviceOrientationListener),this._isRunning=!0}}stop(){this._isRunning=!1,this.acl&&this.acl.stop(),this.gyro&&this.gyro.stop(),window.removeEventListener("devicemotion",this.deviceMotionListener),window.removeEventListener("deviceorientation",this.deviceOrientationListener),this.paramsAcc={...this.emptyParams},this.paramsGyro={...this.emptyParams},this.paramsAccGrOld={...this.emptyParams},this.paramsAccOld={...this.emptyParams},this.paramsGyroscopeOld={...this.emptyParams},this.paramsOrientationOld={...this.emptyParams}}updateAcc(){if(!this._isRunning||!this.acl)return;this.paramsAcc.ptsNum+=1;let l={x:this.acl.x,y:this.acl.y,z:this.acl.z};this.checkFields(l)&&this.updateParams(this.paramsAcc,l)}updateGyro(){if(!this._isRunning||!this.gyro)return;this.paramsGyro.ptsNum+=1;let l={x:this.gyro.x,y:this.gyro.y,z:this.gyro.z};this.checkFields(l)&&this.updateParams(this.paramsGyro,l)}check(){if(!this._hasPermission)return"UNCLEAR";let l=this.checkStability();return null===l?"UNCLEAR":l?"FAIL":"PASS"}checkStability(){if(!this._isRunning)return null;let l=[this.gyro?this.isBelowStdThreshold(this.paramsGyro,this.thresholds.gyroThreshold):null,this.acl?this.isBelowStdThreshold(this.paramsAcc,this.thresholds.accThreshold):null,this.isBelowStdThreshold(this.paramsAccGrOld,this.thresholds.accGrOldThreshold),this.isBelowStdThreshold(this.paramsAccOld,this.thresholds.accOldThreshold),this.isBelowStdThreshold(this.paramsGyroscopeOld,this.thresholds.gyroscopeOldThreshold),this.isBelowStdThreshold(this.paramsOrientationOld,this.thresholds.orientationOldThreshold)].filter(l=>null!==l),t=l.length>0?l.every(l=>l):null,d=[this.gyro?this.isBelowMaeThreshold(this.paramsGyro,this.thresholds.maeGyroThreshold):null,this.acl?this.isBelowMaeThreshold(this.paramsAcc,this.thresholds.maeAccThreshold):null,this.isBelowMaeThreshold(this.paramsAccGrOld,this.thresholds.maeAccGrOldThreshold),this.isBelowMaeThreshold(this.paramsAccOld,this.thresholds.maeAccOldThreshold),this.isBelowMaeThreshold(this.paramsGyroscopeOld,this.thresholds.maeGyroscopeOldThreshold),this.isBelowMaeThreshold(this.paramsOrientationOld,this.thresholds.maeOrientationOldThreshold)].filter(l=>null!==l),i=d.length>0?d.every(l=>l):null;return null===t?null===i?null:i:null!==i?t&&i:t}updateParams(l,t){let d=t.x-l.meanX,i=t.y-l.meanY,c=t.z-l.meanZ;l.meanX+=d/l.ptsNum,l.meanY+=i/l.ptsNum,l.meanZ+=c/l.ptsNum,l.m2X+=d*(t.x-l.meanX),l.m2Y+=i*(t.y-l.meanY),l.m2Z+=c*(t.z-l.meanZ),l.cumulativeAbsErrorX+=Math.abs(t.x-l.meanX),l.cumulativeAbsErrorY+=Math.abs(t.y-l.meanY),l.cumulativeAbsErrorZ+=Math.abs(t.z-l.meanZ)}calculateStd(l){let t={x:l.m2X/l.ptsNum,y:l.m2Y/l.ptsNum,z:l.m2Z/l.ptsNum};return{x:Math.sqrt(t.x),y:Math.sqrt(t.y),z:Math.sqrt(t.z)}}calculateMae(l){return{x:l.cumulativeAbsErrorX/l.ptsNum,y:l.cumulativeAbsErrorY/l.ptsNum,z:l.cumulativeAbsErrorZ/l.ptsNum}}checkFields(l){return null!==l.x&&null!==l.y&&null!==l.z}isBelowStdThreshold(l,t){if(l.ptsNum<this.minNumberOfFrames)return null;let d=this.calculateStd(l);return d.x<t&&d.y<t&&d.z<t}isBelowMaeThreshold(l,t){if(l.ptsNum<this.minNumberOfFrames)return null;let d=this.calculateMae(l);return d.x<t&&d.y<t&&d.z<t}}}