barcode-detector
Advanced tools
Comparing version 0.3.0 to 0.4.0
{ | ||
"name": "barcode-detector", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"author": { | ||
"name": "Niklas Gruhn", | ||
"email": "niklas@gruhn.me" | ||
}, | ||
"license": "MIT", | ||
"repository": "github:gruhn/barcode-detector", | ||
"bugs": "https://github.com/gruhn/barcode-detector/issues", | ||
"description": "", | ||
@@ -11,7 +18,5 @@ "source": "src/BarcodeDetector.ts", | ||
"scripts": { | ||
"build": "microbundle", | ||
"build": "./build-worker.sh && microbundle", | ||
"dev": "microbundle watch" | ||
}, | ||
"author": "Niklas Gruhn", | ||
"license": "MIT", | ||
"dependencies": { | ||
@@ -18,0 +23,0 @@ "jsqr": "^1.3.1" |
// spec: https://wicg.github.io/shape-detection-api/#barcode-detection-api | ||
import DetectWorker from "./DetectWorker" | ||
import SleepyWorker from "./SleepyWorker" | ||
import { imageDataFrom } from "./image-data" | ||
import inlineWorkerCode from "./inline-worker-code.js" | ||
@@ -53,3 +53,3 @@ type BarcodeFormatIn | ||
constructor (barcodeDetectorOptions? : BarcodeDetectorOptions) { | ||
this.worker = DetectWorker() | ||
this.worker = new SleepyWorker(inlineWorkerCode) | ||
this.workerBusy = false | ||
@@ -96,2 +96,4 @@ } | ||
return [] | ||
} else if (result.content === "") { | ||
return [] | ||
} else { | ||
@@ -98,0 +100,0 @@ const cornerPoints = Object.freeze([ |
@@ -1,38 +0,19 @@ | ||
import SleepyWorker from "./SleepyWorker"; | ||
import jsQR from "jsqr" | ||
const inlineWorker = func => { | ||
const functionBody = func | ||
.toString() | ||
.trim() | ||
.match(/^function\s*\w*\s*\([\w\s,]*\)\s*{([\w\W]*?)}$/)[1]; | ||
self.addEventListener("message", function(event) { | ||
const imageData = event.data; | ||
return new SleepyWorker( | ||
URL.createObjectURL(new Blob([functionBody], { type: "text/javascript" })) | ||
); | ||
}; | ||
const jsqrWorker = () => { | ||
return inlineWorker(function() { | ||
self.importScripts( | ||
"https://cdn.jsdelivr.net/npm/jsqr@1.3.1/dist/jsQR.min.js" | ||
try { | ||
const result = jsQR( | ||
imageData.data, imageData.width, imageData.height, { | ||
inversionAttempts: "dontInvert" | ||
} | ||
); | ||
self.addEventListener("message", function(event) { | ||
const imageData = event.data; | ||
try { | ||
const result = self.jsQR(imageData.data, imageData.width, imageData.height, { | ||
inversionAttempts: "dontInvert" | ||
}); | ||
self.postMessage(result); | ||
} catch (error) { | ||
if (!(error instanceof RangeError)) { | ||
throw error; | ||
} | ||
} | ||
}); | ||
}); | ||
}; | ||
export default jsqrWorker | ||
self.postMessage(result); | ||
} catch (error) { | ||
if (!(error instanceof RangeError)) { | ||
throw error; | ||
} | ||
} | ||
}); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
3886460
29
5921