function videoStart(){const a=document.getElementById("player");navigator.mediaDevices.getUserMedia({video:!0,audio:!1}).then(b=>a.srcObject=b).catch(b=>alert(`${b.name} ${b.message}`))}
function capture(){const a=document.getElementById("snapshot");if("visible"==a.style.visibility)a.style.visibility="hidden";else{a.style.visibility="visible";var b=document.getElementById("player");const c=a.getContext("2d");a.width=b.videoWidth;a.height=b.videoHeight;c.drawImage(b,0,0);if(b=document.getElementById("outdata"))b.value="",ocr(a,b)}}
function readOCR(a){a=a.files[0];const b=document.getElementById("preview");if(b){var c=new FileReader;c.onload=function(d){b.src=d.target.result};c.readAsDataURL(a)}c=document.getElementById("outdata");ocr(a,c)}function ocr(a,b){const c=document.getElementById("progressbar");Tesseract.recognize(a,"jpn",{logger:d=>{c.value=d.progress}}).then(({data:{text:d}})=>{b.value=d})}
function qrParse(a){const b=new OffscreenCanvas(240,320),c=b.getContext("2d");return new Promise(d=>{const f=setInterval(()=>{c.drawImage(a,0,0,b.width,b.height);var e=c.getImageData(0,0,b.width,b.height);if(e=jsQR(e.data,e.width,e.height))return clearInterval(f),d(e.data)},100)})}async function qrScan(){const a=document.getElementById("player");document.getElementById("outdata").value=await qrParse(a);setTimeout(qrScan(),5E3)}
function qrGenerate(a){const b=new OffscreenCanvas(1,1);return new Promise((c,d)=>QRCode.toCanvas(b,a,{},f=>f?d(f):c(b)))}async function qrView(a){const b=document.getElementById("div"+a),c=document.getElementById("can"+a);a=document.getElementById("img"+a);c.getContext("bitmaprenderer").transferFromImageBitmap((await qrGenerate(b.textContent)).transferToImageBitmap());a.src=c.toDataURL()}
function upload(a){var b=document.getElementById("snapshot").toDataURL();b=b.replace("data:image/png;base64,","");b="img="+b;a.dir&&(b+="&dir="+encodeURIComponent(a.dir));a.file&&(b+="&file="+encodeURIComponent(a.file));a.debug&&(b+="&debug="+encodeURIComponent(a.debug));a=new XMLHttpRequest;a.open("POST","/gf/jsp/imageSave");a.setRequestHeader("content-type","application/x-www-form-urlencoded");a.send(b)}
function barcodeStart(){var a=document.createElement("video");a.setAttribute("autoplay","");a.setAttribute("muted","");a.setAttribute("playsinline","");a.onloadedmetadata=function(b){a.play()};navigator.mediaDevices.getUserMedia({audio:!1,video:{facingMode:"environment",width:{ideal:640},height:{ideal:480}}}).then(function(b){a.srcObject=b;setTimeout(Scan,500,a)}).catch(function(b){alert(b)})}
function Scan(a){var b=document.getElementById("preview"),c=b.getContext("2d"),d=document.createElement("canvas"),f=d.getContext("2d"),e=a.videoWidth,k=a.videoHeight;b.style.width=e/2+"px";b.style.height=k/2+"px";b.setAttribute("width",e);b.setAttribute("height",k);var g=.5*e,h=.2*e,n=(e-g)/2,p=(k-h)/2;setInterval(()=>{c.drawImage(a,0,0,e,k);c.beginPath();c.strokeStyle="rgb(255,0,0)";c.lineWidth=2;c.rect(n,p,g,h);c.stroke();d.setAttribute("width",g);d.setAttribute("height",h);f.drawImage(b,n,p,g,
h,0,0,g,h);d.toBlob(function(l){let m=new FileReader;m.onload=function(){Quagga.decodeSingle({decoder:{readers:["code_39_reader"],multiple:!1},locator:{patchSize:"large",halfSample:!1},locate:!1,src:m.result},function(){})};m.readAsDataURL(l)})},50);Quagga.onDetected(function(l){document.getElementById("outdata").value=l.codeResult.code})}function barView(a,b){const c=document.getElementById("div"+a);a=document.getElementById("img"+a);JsBarcode(a,c.textContent,{format:"code39",displayValue:b})};
