diff --git a/package.json b/package.json index aa708e8c..ff1fa19e 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "@odit/license-exporter": "0.2.0", "@sveltejs/vite-plugin-svelte": "2.1.1", "@types/papaparse": "^5.3.15", + "@types/underscore": "^1.13.0", "auto-changelog": "2.5.0", "prettier": "3.5.3", "prettier-plugin-svelte": "3.3.3", @@ -55,6 +56,7 @@ "svelte-i18n": "4.0.1", "tailwindcss": "^4.1.4", "tinro": "0.6.12", + "underscore": "^1.13.7", "validator": "13.15.0", "xlsx": "0.18.5" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5912946b..e133cde3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -53,6 +53,9 @@ importers: tinro: specifier: 0.6.12 version: 0.6.12 + underscore: + specifier: ^1.13.7 + version: 1.13.7 validator: specifier: 13.15.0 version: 13.15.0 @@ -69,6 +72,9 @@ importers: '@types/papaparse': specifier: ^5.3.15 version: 5.3.15 + '@types/underscore': + specifier: ^1.13.0 + version: 1.13.0 auto-changelog: specifier: 2.5.0 version: 2.5.0 @@ -730,6 +736,9 @@ packages: '@types/papaparse@5.3.15': resolution: {integrity: sha512-JHe6vF6x/8Z85nCX4yFdDslN11d+1pr12E526X8WAfhadOeaOTx5AuIkvDKIBopfvlzpzkdMx4YyvSKCM9oqtw==} + '@types/underscore@1.13.0': + resolution: {integrity: sha512-L6LBgy1f0EFQZ+7uSA57+n2g/s4Qs5r06Vwrwn0/nuK1de+adz00NWaztRQ30aEqw5qOaWbPI8u2cGQ52lj6VA==} + adler-32@1.3.1: resolution: {integrity: sha512-ynZ4w/nUUv5rrsR8UUGoe1VC9hZj6V5hU9Qw1HlMDJGEJw5S7TfTErWTjMys6M7vr0YWcPqs3qAr4ss0nDfP+A==} engines: {node: '>=0.8'} @@ -2000,6 +2009,9 @@ packages: engines: {node: '>=0.8.0'} hasBin: true + underscore@1.13.7: + resolution: {integrity: sha512-GMXzWtsc57XAtguZgaQViUOzs0KTkk8ojr3/xAxXLITqf/3EMwxC0inyETfDFjH/Krbhuep0HNbbjI9i/q3F3g==} + undici-types@6.21.0: resolution: {integrity: sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==} @@ -2604,6 +2616,8 @@ snapshots: dependencies: '@types/node': 22.14.1 + '@types/underscore@1.13.0': {} + adler-32@1.3.1: {} agent-base@7.1.1: @@ -3888,6 +3902,8 @@ snapshots: uglify-js@3.19.3: optional: true + underscore@1.13.7: {} + undici-types@6.21.0: {} unicorn-magic@0.1.0: {} diff --git a/src/components/general/QrCodeScanner.svelte b/src/components/general/QrCodeScanner.svelte index d4671b07..950657c8 100644 --- a/src/components/general/QrCodeScanner.svelte +++ b/src/components/general/QrCodeScanner.svelte @@ -4,8 +4,8 @@ Html5QrcodeScanner, Html5QrcodeScanType, Html5QrcodeSupportedFormats, - Html5QrcodeScannerState, } from "html5-qrcode"; + import { debounce } from "underscore"; export let width; export let height; @@ -13,23 +13,17 @@ const dispatch = createEventDispatcher(); - const debounceFunc = (func, delay) => { - let timer; - return function (...args) { - const context = this; - clearTimeout(timer); - timer = setTimeout(() => { - func.apply(context, args); - }, delay); - }; - }; - - const debouncedDispatch = debounceFunc(function (decodedText) { - console.log("dispatchEvent"); - dispatch("detect", { decodedText }); - }, 500); + const debouncedDispatch = debounce( + function (decodedText) { + // console.log("dispatchEvent"); + dispatch("detect", { decodedText }); + }, + 500, + true + ); function onScanSuccess(decodedText, decodedResult) { + // console.log("onScanSuccess", decodedText); if (!paused) { debouncedDispatch(decodedText); }