Skip to content

qrcode

Latest

Choose a tag to compare

@nuintun nuintun released this 05 Nov 07:35
· 8 commits to main since this release

v5.1.0

中文日志

新增与增强

  • 重写 GIF 导出:新增 GifImage(单帧 GIF89a、固定双色调色板),按二维码矩阵尺寸存储像素,scale 与 margin 在 LZW 压缩阶段展开,不再对已放大的整图逐像素填充。
  • GIF 编码工具模块化:拆分出 GifWriter、LzwWriter、compress、base64 等独立模块,LZW 码宽按调色板深度动态计算,字典表改用 Uint16Array 以降低内存占用。
  • Base64 编码优先使用原生 Uint8Array.prototype.toBase64,不可用时回退到分块拼接实现。
  • Version 新增惰性构建并缓存的 functionMatrix,解码时直接复用,避免每次解析都重建功能图形矩阵。
  • Reed-Solomon 编码器/解码器改为模块级无状态单例,跨数据块与跨次编解码复用,减少对象分配。
  • GB2312 与 Shift-JIS 的 TextDecoder 提升为模块级常量,避免每个汉字/日文分段重复构造。

性能优化

  • 二维码版本自动选择由线性扫描改为二分查找。
  • Encoded.toDataURL() 改为按矩阵尺寸写入像素,边距由压缩阶段批量输出,减少大量冗余像素写入。
  • Base64 编码按 8192 字符分块拼接,避免 String.fromCharCode 参数过长导致的性能与栈风险。

问题修复

  • 修复 BitArray.xor() 以位长度而非底层 word 数组长度作为循环上界,导致末尾 word 未参与异或的问题。
  • 修复解码器读取数据位时对 BitMatrix.get() 的真值判断,统一为 === 1(GridSampler、检测器与扫描线工具同步改为 === 0 / === 1 显式比较)。
  • 修正内部函数名 getSerialEncodinRanges 为 getSerialEncodingRanges,并修正若干注释与文案。

重构

  • 移除 Detected 构造函数中对源矩阵的冗余赋值,matrix 统一为 GridSampler 的采样结果。
  • buildFunctionPattern 由对外工具函数收敛为 Version 内部的 buildFunctionMatrix,功能矩阵构建职责归位到版本对象。

构建与文档

  • 核心库构建脚本与工具(rollup 配置、clean、fix-types)迁移到 TypeScript,测试改用 node --test。
  • 新增 tests/bench.ts 基准测试脚本。
  • 升级 rollup、typescript、prettier、rimraf、dts-paths 等开发依赖。
  • 重写 README,完善纠错级别表格排版与说明,并新增中文版 README.zh-CN.md。

升级说明

  • 对外公共 API 无破坏性变更;GIFImage → GifImage 等改名均为包内部实现,未从 src/index.ts 导出。

完整变更:5.0.3...5.1.0


English Changelog

Features

  • Rewritten GIF export: new GifImage (single-frame GIF89a with a fixed two-color palette) stores pixels at QR matrix resolution and applies scale/margin during LZW compression instead of filling every pixel of an already-scaled canvas.
  • Modularized the GIF encoder into GifWriter, LzwWriter, compress and base64 modules, with LZW code width derived dynamically from the palette depth and a Uint16Array-backed dictionary for lower memory usage.
  • Base64 encoding now prefers native Uint8Array.prototype.toBase64 and falls back to a chunked implementation when unavailable.
  • Version now exposes a lazily built and cached functionMatrix, reused during decoding to avoid rebuilding the function-pattern matrix on every parse.
  • Reed-Solomon encoder/decoder are now module-level stateless singletons, reused across data blocks and across encode/decode calls.
  • GB2312 and Shift-JIS TextDecoder instances are hoisted to module-level constants, avoiding per-segment construction.

Performance

  • QR version auto-selection switched from a linear scan to binary search.
  • Encoded.toDataURL() now writes pixels at matrix resolution and emits margins in bulk during compression, avoiding redundant pixel writes.
  • Base64 encoding builds output in 8192-character chunks, avoiding oversized String.fromCharCode argument lists.

Fixes

  • Fixed BitArray.xor() using the bit length instead of the backing word-array length as its loop bound, which left trailing words unprocessed.
  • Fixed truthiness checks on BitMatrix.get() while reading data bits, now consistently === 1 (GridSampler, detector and scanline utilities now use explicit === 0 / === 1 comparisons).
  • Corrected the internal function name getSerialEncodinRanges to getSerialEncodingRanges, along with several comment and wording fixes.

Refactoring

  • Removed the redundant source-matrix assignment in the Detected constructor; matrix is now always the GridSampler result.
  • buildFunctionPattern was narrowed into the internal buildFunctionMatrix used by Version, moving function-matrix construction responsibility to the version object.

Build & docs

  • Migrated core build scripts and tooling (rollup configs, clean, fix-types) to TypeScript; tests now run via node --test.
  • Added a tests/bench.ts benchmark script.
  • Updated development dependencies including rollup, typescript, prettier, rimraf and dts-paths.
  • Rewrote the README with improved error-correction-level table formatting and added a Chinese version (README.zh-CN.md).

Upgrade notes

  • No breaking changes to the public API. Renames such as GIFImage → GifImage are internal and not exported from src/index.ts.

Full Changelog: 5.0.3...5.1.0