Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Sec-ant committed Dec 15, 2024
1 parent b3b0254 commit 049a97f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ Demo source: https://github.com/Sec-ant/zxing-wasm-demo -->

## Usage

This package exports three subpaths: `full`, `reader`, and `writer`. You can choose the one that fits your needs. If you use TypeScript, you should set [`moduleResolution`](https://www.typescriptlang.org/docs/handbook/modules/theory.html#module-resolution) to [`bundler`](https://www.typescriptlang.org/docs/handbook/modules/reference.html#bundler), [`node16`], or [`nodenext`](https://www.typescriptlang.org/docs/handbook/modules/reference.html#node16-nodenext-1) in your `tsconfig.json` file to properly resolve the exported module.
This package exports three subpaths: `full`, `reader`, and `writer`. You can choose the one that fits your needs. If you use TypeScript, you should set [`moduleResolution`](https://www.typescriptlang.org/docs/handbook/modules/theory.html#module-resolution) to [`bundler`](https://www.typescriptlang.org/docs/handbook/modules/reference.html#bundler), [`node16`, or `nodenext`](https://www.typescriptlang.org/docs/handbook/modules/reference.html#node16-nodenext-1) in your `tsconfig.json` file to properly resolve the exported module.

### `zxing-wasm` or `zxing-wasm/full`

These two subpaths provide functions to read and write barcodes. The wasm binary size is approximately 1.30 MB.
These two subpaths provide functions to read and write barcodes. The wasm binary size is ~1.30 MB.

```ts
import { readBarcodes, writeBarcode } from "zxing-wasm";
Expand All @@ -59,15 +59,15 @@ import { readBarcodes, writeBarcode } from "zxing-wasm/full";

### `zxing-wasm/reader`

This subpath only provides a function to read barcodes. The wasm binary size is approximately 906 KB.
This subpath only provides a function to read barcodes. The wasm binary size is ~906 KB.

```ts
import { readBarcodes } from "zxing-wasm/reader";
```

### `zxing-wasm/writer`

This subpath only provides a function to write barcodes. The wasm binary size is approximately 1.17 MB.
This subpath only provides a function to write barcodes. The wasm binary size is ~1.17 MB.

```ts
import { writeBarcode } from "zxing-wasm/writer";
Expand Down Expand Up @@ -160,7 +160,7 @@ console.log(writeOutput.image); // A PNG image blob.

When using this package, the `.wasm` binary needs to be served along with the JS glue code. In order to provide a smooth development experience, the serve path is automatically assigned the [jsDelivr CDN](https://fastly.jsdelivr.net/npm/zxing-wasm/) URL upon build.

If you would like to change the serve path (to one of your local network hosts, other CDNs, or just Base64-encoded data URIs), please use [`setZXingModuleOverrides`](https://zxing-wasm.deno.dev/functions/full.setZXingModuleOverrides.html) to override the [`locateFile`](https://emscripten.org/docs/api_reference/module.html#Module.locateFile) function in advance. `locateFile` is one of the [Emscripten `Module` attribute hooks](https://emscripten.org/docs/api_reference/module.html#affecting-execution) that can affect the code execution of the `Module` object during its lifecycle.
If you would like to change the serve path (to one of your local network hosts, other CDNs, or just Base64-encoded data URIs), please use [`setZXingModuleOverrides`](https://zxing-wasm.deno.dev/functions/full.setZXingModuleOverrides.html) to override the [`locateFile`](https://emscripten.org/docs/api_reference/module.html?highlight=locatefile#Module.locateFile) function in advance. `locateFile` is one of the [Emscripten `Module` attribute hooks](https://emscripten.org/docs/api_reference/module.html#affecting-execution) that can affect the code execution of the `Module` object during its lifecycle.

e.g.

Expand Down
22 changes: 17 additions & 5 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,26 @@ export function purgeZXingModule() {
zxingWeakMap = new WeakMap();
}

// export function setZXingModuleOverridesWithFactory<T extends ZXingModuleType>(
// zxingModuleFactory: ZXingModuleFactory<T>,
// zxingModuleOverrides: ZXingModuleOverrides,
// ) {
// zxingWeakMap.set(zxingModuleFactory, {
// moduleOverrides: zxingModuleOverrides,
// });
// }

export function setZXingModuleOverridesWithFactory<T extends ZXingModuleType>(
zxingModuleFactory: ZXingModuleFactory<T>,
zxingModuleOverrides: ZXingModuleOverrides,
) {
zxingWeakMap.set(zxingModuleFactory, {
moduleOverrides: zxingModuleOverrides,
});
}
options?: {
fireImmediately?: boolean;
equalityFn?: (
prevOverrides: ZXingModuleOverrides,
currOverrides: ZXingModuleOverrides,
) => boolean;
},
) {}

export async function readBarcodesWithFactory<T extends "reader" | "full">(
zxingModuleFactory: ZXingModuleFactory<T>,
Expand Down

0 comments on commit 049a97f

Please sign in to comment.