@scandit/web-datacapture-core
Version:
Scandit Data Capture SDK for the Web
1 lines • 2.97 kB
JavaScript
import {f}from'./chunk-3D2HNEVH.js';var n=class{constructor(){this.type="torch";this.customImage={on:{idle:"",pressed:""},off:{idle:"",pressed:""}};this.torchSwitchIconButton=void 0;this.TorchSwitchIconButtonClass=void 0;this.view=void 0;this.onTorchToggled=this.handleTorchToggled.bind(this);}get currentCamera(){var e,o;let t=(o=(e=this.view)==null?void 0:e.getContext())==null?void 0:o.frameSource;return f(t)?t:null}get torchOffImage(){return this.customImage.off.idle}set torchOffImage(t){this.customImage.off.idle=t,this.applyCustomImagesToButton();}get torchOffPressedImage(){return this.customImage.off.pressed}set torchOffPressedImage(t){this.customImage.off.pressed=t,this.applyCustomImagesToButton();}get torchOnImage(){return this.customImage.on.idle}set torchOnImage(t){this.customImage.on.idle=t,this.applyCustomImagesToButton();}get torchOnPressedImage(){return this.customImage.on.pressed}set torchOnPressedImage(t){this.customImage.on.pressed=t,this.applyCustomImagesToButton();}toJSONObject(){return {type:this.type}}async install(t){var i;this.TorchSwitchIconButtonClass||(this.TorchSwitchIconButtonClass=await import('../private/ui/molecules/TorchSwitchIconButton.js').then(r=>r.TorchSwitchIconButton),(i=this.TorchSwitchIconButtonClass)==null||i.register()),this.view=t,this.torchSwitchIconButton=this.TorchSwitchIconButtonClass.create(),this.torchSwitchIconButton.slot="topLeft",this.torchSwitchIconButton.state="off",this.torchSwitchIconButton.hidden=true,this.torchSwitchIconButton.addEventListener("torch-toggled",this.onTorchToggled);let e=t.controlsElement;e&&e.append(this.torchSwitchIconButton),this.applyCustomImagesToButton();let o=await this.canShow();return this.updateButtonState(o),true}remove(t){t&&this.torchSwitchIconButton&&(this.torchSwitchIconButton.removeEventListener("torch-toggled",this.onTorchToggled),this.torchSwitchIconButton.remove(),this.torchSwitchIconButton=null,this.view=void 0);}async update(t){this.view=t;let e=await this.canShow();this.updateButtonState(e);}applyCustomImagesToButton(){if(!this.torchSwitchIconButton)return;this.customImage.on.idle||this.customImage.on.pressed||this.customImage.off.idle||this.customImage.off.pressed?this.torchSwitchIconButton.setCustomImages(this.customImage):this.torchSwitchIconButton.useCustomImages=false;}updateButtonState(t){var e,o;this.torchSwitchIconButton&&(this.torchSwitchIconButton.state=(o=(e=this.currentCamera)==null?void 0:e.getDesiredTorchState())!=null?o:"off",this.torchSwitchIconButton.hidden=!t);}async handleTorchToggled(t){var i,r;let e=(r=(i=this.view)==null?void 0:i.getContext())==null?void 0:r.frameSource,o=e?e.getDesiredTorchState()==="on"?"off":"on":"off";await this.setTorchState(o),this.torchSwitchIconButton.state=o;}async canShow(){var t,e;return (e=(t=this.currentCamera)==null?void 0:t.isTorchAvailable())!=null?e:false}async setTorchState(t){var e;await((e=this.currentCamera)==null?void 0:e.setDesiredTorchState(t));}};export{n as a};