// ─────────────────────────────────────────────────────────────────────────────
// Field-targeted scanner overlay (Gemini single-value extraction).
// Opt-in: pages include this when ui.page({ includeScanner: true }).
//
// Usage from page code:
// scanner.open('serial_number', 'Numéro de série', function (value) {
// // value is confirmed by the tech; write it into the target input.
// }, { equipment_type, brand, model })
//
// The page must also include
markup, which shell.js injects
// automatically when includeScanner is on.
// ─────────────────────────────────────────────────────────────────────────────
(function () {
var stream = null
var field = ''
var fieldLabel = ''
var ctx = {}
var callback = null
function $ (id) { return document.getElementById(id) }
function esc (s) { return window._esc(s) }
function open (fieldKey, label, cb, context) {
field = fieldKey; fieldLabel = label; callback = cb; ctx = context || {}
$('fsLabel').textContent = 'Scanner : ' + label
$('fsResult').innerHTML = '
Cadrez l\'étiquette puis appuyez sur Capturer
'
$('fsOv').classList.add('open')
startCam()
}
function close () {
$('fsOv').classList.remove('open')
stopCam()
callback = null
}
function startCam () {
var v = $('fsVid')
if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) {
v.style.display = 'none'
$('fsResult').innerHTML = '
'
})
}
function confirm (value) {
if (callback) callback(value)
close()
}
// Bind close button + ESC
window.addEventListener('load', function () {
var x = document.querySelector('#fsOv .fs-close')
if (x) x.addEventListener('click', close)
var cap = document.querySelector('#fsOv .fs-capture')
if (cap) cap.addEventListener('click', capture)
var can = document.querySelector('#fsOv .fs-cancel')
if (can) can.addEventListener('click', close)
})
window.scanner = { open: open, close: close, capture: capture, confirm: confirm }
})()