This commit is contained in:
iqudoo
2026-05-02 17:19:14 +08:00
parent 6e91cc0ef4
commit 69b0c4e27c
6 changed files with 41 additions and 10 deletions

View File

@@ -13,7 +13,8 @@ const scanWeb = {
const DEFAULT_SCAN_BEEP_AUDIO = scanBeepAudio;
const ZXING_READER_WASM_PATH = "lib/reader.wasm";
const WEBSCAN_CLOSE_BUTTON_ID = "__webscan_close_button__";
const DEFAULT_WEBSCAN_CLOSE_BUTTON_STYLE = "width: 28px; height: 28px; padding: 0; border: 0; border-radius: 50%; background: rgba(0, 0, 0, 0.55); color: #fff; font-size: 20px; line-height: 28px; text-align: center; cursor: pointer; z-index: 10000;";
const WEBSCAN_CLOSE_ICON_SVG = "<svg viewBox=\"0 0 1024 1024\" xmlns=\"http://www.w3.org/2000/svg\" width=\"14\" height=\"14\" aria-hidden=\"true\" focusable=\"false\"><path d=\"M139.445 1002.491L512.23 629.716l372.775 372.775c28.672 28.672 78.843 28.672 107.52 0 28.703-28.672 28.703-78.842 0-107.52L619.75 522.187l372.775-372.795c28.703-28.672 28.703-78.853 0-107.52-28.677-28.672-78.848-28.672-107.52 0L512.23 414.636 139.445 41.876c-28.677-28.672-78.848-28.672-107.54 0C17.963 55.813 10.95 74.828 10.55 93.972v3.318c0.4 19.148 7.413 38.164 21.355 52.106L404.69 522.19 31.905 894.971c-13.942 13.917-20.956 32.973-21.355 52.096v3.292c0.4 19.16 7.413 38.175 21.355 52.137 28.692 28.662 78.868 28.662 107.54-0.005z\" fill=\"currentColor\"/></svg>";
const DEFAULT_WEBSCAN_CLOSE_BUTTON_STYLE = "width: 28px; height: 28px; padding: 0; border: 0; border-radius: 50%; background: rgba(0, 0, 0, 0.55); color: #fff; display: flex; align-items: center; justify-content: center; cursor: pointer; z-index: 10000;";
const currentScriptSrc = typeof document !== "undefined"
&& document.currentScript
&& document.currentScript.src;
@@ -441,6 +442,7 @@ export function startScanForWeb(canvasStyle, onResult) {
canvasBaseStyle + " display: none;", true);
canvasDisplay = canvasEl.style.display;
canvasEl.style.cssText = canvasBaseStyle;
canvasEl.className = getConfig("webScanCanvasClass") || "";
canvasDisplay = canvasEl.style.display;
let canvasDisplaySize = getCanvasDisplaySize(canvasEl, 300, 240);
canvasEl.style.display = "none";
@@ -448,7 +450,8 @@ export function startScanForWeb(canvasStyle, onResult) {
if (canvasEnabled) {
closeButtonEl = createEl("button", WEBSCAN_CLOSE_BUTTON_ID, "display: none;", true);
closeButtonEl.type = "button";
closeButtonEl.innerHTML = "x";
closeButtonEl.className = getConfig("webScanCloseButtonClass") || "";
closeButtonEl.innerHTML = WEBSCAN_CLOSE_ICON_SVG;
closeButtonEl.setAttribute("aria-label", "close");
closeButtonEl.onclick = event => {
event.preventDefault && event.preventDefault();
@@ -532,7 +535,7 @@ export function startScanForWeb(canvasStyle, onResult) {
displayed = true;
canvasEl.style.display = canvasDisplay || "";
updateWebScanCloseButtonStyle(closeButtonEl, canvasEl);
closeButtonEl && (closeButtonEl.style.display = "block");
closeButtonEl && (closeButtonEl.style.display = "flex");
}
detecting = true;
detector.detect(videoEl).then(barcodes => {