@sec-ant/zxing-wasm
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -146,3 +146,3 @@ var si = (() => { | ||
var V; | ||
u.locateFile ? (V = "zxing_full.wasm", ar(V) || (V = kr(V))) : V = new URL("https://cdn.jsdelivr.net/npm/@sec-ant/zxing-wasm@0.0.4/dist/full/zxing_full.wasm").href; | ||
u.locateFile ? (V = "zxing_full.wasm", ar(V) || (V = kr(V))) : V = new URL("https://cdn.jsdelivr.net/npm/@sec-ant/zxing-wasm@0.0.5/dist/full/zxing_full.wasm").href; | ||
function or(e) { | ||
@@ -149,0 +149,0 @@ try { |
@@ -146,3 +146,3 @@ var ai = (() => { | ||
var Y; | ||
u.locateFile ? (Y = "zxing_reader.wasm", ir(Y) || (Y = Sr(Y))) : Y = new URL("https://cdn.jsdelivr.net/npm/@sec-ant/zxing-wasm@0.0.4/dist/reader/zxing_reader.wasm").href; | ||
u.locateFile ? (Y = "zxing_reader.wasm", ir(Y) || (Y = Sr(Y))) : Y = new URL("https://cdn.jsdelivr.net/npm/@sec-ant/zxing-wasm@0.0.5/dist/reader/zxing_reader.wasm").href; | ||
function ar(e) { | ||
@@ -149,0 +149,0 @@ try { |
@@ -142,3 +142,3 @@ var gn = (() => { | ||
var I; | ||
s.locateFile ? (I = "zxing_writer.wasm", Le(I) || (I = vt(I))) : I = new URL("https://cdn.jsdelivr.net/npm/@sec-ant/zxing-wasm@0.0.4/dist/writer/zxing_writer.wasm").href; | ||
s.locateFile ? (I = "zxing_writer.wasm", Le(I) || (I = vt(I))) : I = new URL("https://cdn.jsdelivr.net/npm/@sec-ant/zxing-wasm@0.0.5/dist/writer/zxing_writer.wasm").href; | ||
function Ne(e) { | ||
@@ -145,0 +145,0 @@ try { |
{ | ||
"name": "@sec-ant/zxing-wasm", | ||
"private": false, | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"type": "module", | ||
@@ -6,0 +6,0 @@ "files": [ |
@@ -34,3 +34,3 @@ # @sec-ant/zxing-wasm | ||
writeBarcodeToImageFile, | ||
} from "@sec-ant/zxing-wasm/full"; | ||
} from "@sec-ant/zxing-wasm"; | ||
``` | ||
@@ -45,3 +45,3 @@ | ||
writeBarcodeToImageFile, | ||
} from "@sec-ant/zxing-wasm"; | ||
} from "@sec-ant/zxing-wasm/full"; | ||
``` | ||
@@ -136,18 +136,49 @@ | ||
e.g.: | ||
e.g. | ||
```ts | ||
import { readBarcodeFromImageFile } from "@sec-ant/zxing-wasm/reader"; | ||
import { | ||
readBarcodeFromImageFile, | ||
readBarcodeFromImageData, | ||
ZXingReadOptions, | ||
} from "@sec-ant/zxing-wasm/reader"; | ||
const imageBlob = await fetch( | ||
const zxingReadOptions: ZXingReadOptions = { | ||
tryHarder: true, | ||
formats: ["QRCode"], | ||
maxNumberOfSymbols: 1, | ||
}; | ||
/** | ||
* Read from image file/blob | ||
*/ | ||
const imageFile = await fetch( | ||
"https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=Hello%20world!" | ||
).then((resp) => resp.blob()); | ||
const readResult = await readBarcodeFromImageFile(imageBlob, { | ||
tryHarder: false, | ||
formats: ["QRCode"], | ||
maxNumberOfSymbols: 1, | ||
const imageFileReadResult = await readBarcodeFromImageFile( | ||
imageFile, | ||
zxingReadOptions | ||
); | ||
console.log(imageFileReadResult[0].text); // Hello world! | ||
/** | ||
* Read from image data | ||
*/ | ||
const imageData = await createImageBitmap(imageFile).then((imageBitmap) => { | ||
const { width, height } = imageBitmap; | ||
const context = new OffscreenCanvas(width, height).getContext( | ||
"2d" | ||
) as OffscreenCanvasRenderingContext2D; | ||
context.drawImage(imageBitmap, 0, 0, width, height); | ||
return context.getImageData(0, 0, width, height); | ||
}); | ||
console.log(readResult[0].text); // Hello world! | ||
const imageDataReadResult = await readBarcodeFromImageData( | ||
imageData, | ||
zxingReadOptions | ||
); | ||
console.log(imageDataReadResult[0].text); // Hello world! | ||
``` | ||
@@ -208,6 +239,18 @@ | ||
The wasm binary won't be downloaded and instantiated unless a read or write function is firstly called, and will only be instantiated once. So there'll be a cold start in the first function call (or several calls if they appear in a very short period). If you want to manully trigger the download and instantiation of the wasm binary prior to any read or write functions, you can call the exported function `getZXingInstance()`. | ||
When using this package, the wasm binary needs to be served along with the JS glue code. In order to provide a smooth dev experience, the wasm binary serve path is automatically replaced with [jsDelivr CDN](https://cdn.jsdelivr.net/npm/@sec-ant/zxing-wasm/) urls after build. Further customization will be considered to provide a more flexible opt-in option. | ||
The wasm binary won't be downloaded and instantiated unless a [read](#readbarcodefromimagefile-and-readbarcodefromimagedata) or [write](#writebarcodetoimagefile) function is firstly called, and will only be instantiated once. So there'll be a cold start in the first function call (or several calls if they appear in a very short period). If you want to manully trigger the download and instantiation of the wasm binary prior to any read or write functions, you can call the exported function `getZXingInstance`, this function will also return a `Promise` that resolves to a `ZXingInstance`, which this wrapper library is built upon. | ||
```ts | ||
import { getZXingInstance } from "@sec-ant/zxing-wasm/reader"; | ||
/** | ||
* This function will trigger the download and | ||
* instantiation of the wasm binary immediately | ||
*/ | ||
getZXingInstance(); | ||
``` | ||
## License | ||
MIT |
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
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
2863244
253