From 615a321a6bc0c509ae8aaa3a1f9be87e3c39424e Mon Sep 17 00:00:00 2001 From: Ze-Zheng Wu Date: Sun, 29 Dec 2024 14:28:03 +0800 Subject: [PATCH] feat: support `DXFilmEdge` writing, with some other fixes --- .changeset/stupid-rules-travel.md | 8 ++++ README.md | 8 ++-- biome.json | 8 ++++ copy-files-from-to.json | 16 +++++++ package.json | 74 +++++++++++++++++++++++++++++-- src/bindings/barcodeFormat.ts | 2 +- src/bindings/writerOptions.ts | 2 +- src/wasm.d.ts | 7 +++ zxing-cpp | 2 +- 9 files changed, 117 insertions(+), 10 deletions(-) create mode 100644 .changeset/stupid-rules-travel.md create mode 100644 src/wasm.d.ts diff --git a/.changeset/stupid-rules-travel.md b/.changeset/stupid-rules-travel.md new file mode 100644 index 00000000..7f54bde5 --- /dev/null +++ b/.changeset/stupid-rules-travel.md @@ -0,0 +1,8 @@ +--- +"zxing-wasm": minor +--- + +- Add `DXFilmEdge` writing support. +- Fix subpath exports TS compatibility with types-versions-wildcards strategy. Check [this](https://github.com/andrewbranch/example-subpath-exports-ts-compat/tree/main/examples/node_modules/types-versions-wildcards) for more information. +- Add types to `.wasm` subpath exports. +- Add `ImageData` ambient type export. diff --git a/README.md b/README.md index 9c8ffedd..85a3719b 100644 --- a/README.md +++ b/README.md @@ -23,11 +23,11 @@ | `DataBarLimited` | ✅ | | ✅ | ✅ | | `DataBarExpanded` | ✅ | | ✅ | ✅ | | `DataMatrix` | | ✅ | ✅ | ✅ | -| `DXFilmEdge` | ✅ | | ✅ | | +| `DXFilmEdge` | ✅ | | ✅ | ✅ | | `EAN-8` | ✅ | | ✅ | ✅ | | `EAN-13` | ✅ | | ✅ | ✅ | | `ITF` | ✅ | | ✅ | ✅ | -| `MaxiCode` | | ✅ | ✅ | ✅ | +| `MaxiCode` | | ✅ |   ✅[^1] | ✅ | | `PDF417` | | ✅ | ✅ | ✅ | | `QRCode` | | ✅ | ✅ | ✅ | | `MicroQRCode` | | ✅ | ✅ | ✅ | @@ -35,6 +35,8 @@ | `UPC-A` | ✅ | | ✅ | ✅ | | `UPC-E` | ✅ | | ✅ | ✅ | +[^1]: Reading support for `MaxiCode` requires a pure monochrome image that contains an unrotated and unskewed code image, along with a sufficient white border surrounding it. + @@ -78,7 +80,7 @@ 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`. ### `zxing-wasm` or `zxing-wasm/full` diff --git a/biome.json b/biome.json index a530760c..4c1ecfc1 100644 --- a/biome.json +++ b/biome.json @@ -25,6 +25,14 @@ "useIgnoreFile": true, "defaultBranch": "main" }, + "json": { + "parser": { + "allowTrailingCommas": true + }, + "formatter": { + "trailingCommas": "none" + } + }, "overrides": [ { "include": [ diff --git a/copy-files-from-to.json b/copy-files-from-to.json index a33a23ac..2fe85ef5 100644 --- a/copy-files-from-to.json +++ b/copy-files-from-to.json @@ -11,6 +11,22 @@ { "from": "./src/full/*.wasm", "to": "./dist/full/" + }, + { + "from": "./src/imageData.d.ts", + "to": "./dist/es/types/" + }, + { + "from": "./src/imageData.d.ts", + "to": "./dist/cjs/types/" + }, + { + "from": "./src/wasm.d.ts", + "to": "./dist/es/types/" + }, + { + "from": "./src/wasm.d.ts", + "to": "./dist/cjs/types/" } ], "copyFilesSettings": { diff --git a/package.json b/package.json index 75cc2a16..66c9ee4f 100644 --- a/package.json +++ b/package.json @@ -30,23 +30,89 @@ "require": "./dist/cjs/writer/index.js", "default": "./dist/es/writer/index.js" }, - "./reader/zxing_reader.wasm": "./dist/reader/zxing_reader.wasm", - "./writer/zxing_writer.wasm": "./dist/writer/zxing_writer.wasm", - "./full/zxing_full.wasm": "./dist/full/zxing_full.wasm" + "./full/zxing_full.wasm": { + "import": { + "types": "./dist/es/types/wasm.d.ts", + "default": "./dist/full/zxing_full.wasm" + }, + "require": { + "types": "./dist/cjs/types/wasm.d.ts", + "default": "./dist/full/zxing_full.wasm" + }, + "default": { + "types": "./dist/es/types/wasm.d.ts", + "default": "./dist/full/zxing_full.wasm" + } + }, + "./reader/zxing_reader.wasm": { + "import": { + "types": "./dist/es/types/wasm.d.ts", + "default": "./dist/reader/zxing_reader.wasm" + }, + "require": { + "types": "./dist/cjs/types/wasm.d.ts", + "default": "./dist/reader/zxing_reader.wasm" + }, + "default": { + "types": "./dist/es/types/wasm.d.ts", + "default": "./dist/reader/zxing_reader.wasm" + } + }, + "./writer/zxing_writer.wasm": { + "import": { + "types": "./dist/es/types/wasm.d.ts", + "default": "./dist/writer/zxing_writer.wasm" + }, + "require": { + "types": "./dist/cjs/types/wasm.d.ts", + "default": "./dist/writer/zxing_writer.wasm" + }, + "default": { + "types": "./dist/es/types/wasm.d.ts", + "default": "./dist/writer/zxing_writer.wasm" + } + }, + "./imageData": { + "import": { + "types": "./dist/es/types/imageData.d.ts" + }, + "require": { + "types": "./dist/cjs/types/imageData.d.ts" + }, + "default": { + "types": "./dist/es/types/imageData.d.ts" + } + } }, "typesVersions": { "*": { + "full/zxing_full.wasm": [ + "./dist/es/types/wasm.d.ts", + "./dist/cjs/types/wasm.d.ts" + ], "full": [ "./dist/es/full/index.d.ts", "./dist/cjs/full/index.d.ts" ], + "reader/zxing_reader.wasm": [ + "./dist/es/types/wasm.d.ts", + "./dist/cjs/types/wasm.d.ts" + ], "reader": [ "./dist/es/reader/index.d.ts", "./dist/cjs/reader/index.d.ts" ], + "writer/zxing_writer.wasm": [ + "./dist/es/types/wasm.d.ts", + "./dist/cjs/types/wasm.d.ts" + ], "writer": [ "./dist/es/writer/index.d.ts", "./dist/cjs/writer/index.d.ts" + ], + "imageData": [ + "./dist/es/types/imageData.d.ts", + "./dist/cjs/types/imageData.d.ts" ] } }, @@ -153,5 +219,5 @@ } } }, - "packageManager": "pnpm@9.15.1+sha512.1acb565e6193efbebda772702950469150cf12bcc764262e7587e71d19dc98a423dff9536e57ea44c49bdf790ff694e83c27be5faa23d67e0c033b583be4bfcf" + "packageManager": "pnpm@9.15.2+sha512.93e57b0126f0df74ce6bff29680394c0ba54ec47246b9cf321f0121d8d9bb03f750a705f24edc3c1180853afd7c2c3b94196d0a3d53d3e069d9e2793ef11f321" } diff --git a/src/bindings/barcodeFormat.ts b/src/bindings/barcodeFormat.ts index 3030596e..059e55cc 100644 --- a/src/bindings/barcodeFormat.ts +++ b/src/bindings/barcodeFormat.ts @@ -17,7 +17,7 @@ const barcodeFormatsWithMeta = [ ["UPC-E", "L"], ["MicroQRCode", "M"], ["rMQRCode", "M"], - ["DXFilmEdge", "L", "W-"], + ["DXFilmEdge", "L"], ["DataBarLimited", "L"], ] as const; diff --git a/src/bindings/writerOptions.ts b/src/bindings/writerOptions.ts index 6c2dd466..a3312e2d 100644 --- a/src/bindings/writerOptions.ts +++ b/src/bindings/writerOptions.ts @@ -75,7 +75,7 @@ export interface WriterOptions * * Supported values are: * `"Aztec"`, `"Codabar"`, `"Code39"`, `"Code93"`, `"Code128"`, - * `"DataBar"`, `"DataBarExpanded"`, `"DataBarLimited"`, `"DataMatrix"`, + * `"DataBar"`, `"DataBarExpanded"`, `"DataBarLimited"`, `"DataMatrix"`, `"DXFilmEdge"`, * `"EAN-8"`, `"EAN-13"`, `"ITF"`, `"MaxiCode"`, `"MicroQRCode"`, `"PDF417"`, * `"QRCode"`, `"rMQRCode"`, `"UPC-A"`, `"UPC-E"` * diff --git a/src/wasm.d.ts b/src/wasm.d.ts new file mode 100644 index 00000000..a0e5f15c --- /dev/null +++ b/src/wasm.d.ts @@ -0,0 +1,7 @@ +/** + * This type is intended to be used with the esbuild file loader for wasm files + * + * see https://esbuild.github.io/content-types/#file + */ +declare const wasmFilePath: string; +export default wasmFilePath; diff --git a/zxing-cpp b/zxing-cpp index 0dfa36bb..d270b3fb 160000 --- a/zxing-cpp +++ b/zxing-cpp @@ -1 +1 @@ -Subproject commit 0dfa36bb9e676bfcf65cd8218ff8429b2d689095 +Subproject commit d270b3fb7e9cde3e860043f1d468e2ecdaabcd9e