Load barcode detection library

This commit is contained in:
Claudio Ortolina
2025-02-13 14:25:47 +00:00
parent ffc55b2147
commit 50a98284c9
4 changed files with 74 additions and 0 deletions
+1
View File
@@ -21,6 +21,7 @@ import "phoenix_html"
import { Socket } from "phoenix"
import { LiveSocket } from "phoenix_live_view"
import topbar from "../vendor/topbar"
import "./barcode-scanner"
let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content")
let liveSocket = new LiveSocket("/live", Socket, {
+20
View File
@@ -0,0 +1,20 @@
import { BarcodeDetector } from "barcode-detector/ponyfill";
const run = async function () {
// check supported formats
const supportedFormats = await BarcodeDetector.getSupportedFormats();
console.log(supportedFormats);
const barcodeDetector = new BarcodeDetector({
// make sure the formats are supported
formats: ["qr_code"],
});
const imageFile = await fetch(
"https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=Hello%20world!",
).then((resp) => resp.blob());
barcodeDetector.detect(imageFile).then(console.log);
}
run();