Repository navigation
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 appliesscale/marginduring LZW compression instead of filling every pixel of an already-scaled canvas. - Modularized the GIF encoder into
GifWriter,LzwWriter,compressandbase64modules, with LZW code width derived dynamically from the palette depth and aUint16Array-backed dictionary for lower memory usage. - Base64 encoding now prefers native
Uint8Array.prototype.toBase64and falls back to a chunked implementation when unavailable. Versionnow exposes a lazily built and cachedfunctionMatrix, 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
TextDecoderinstances 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.fromCharCodeargument 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/=== 1comparisons). - Corrected the internal function name
getSerialEncodinRangestogetSerialEncodingRanges, along with several comment and wording fixes.
Refactoring
- Removed the redundant source-matrix assignment in the
Detectedconstructor;matrixis now always theGridSamplerresult. buildFunctionPatternwas narrowed into the internalbuildFunctionMatrixused byVersion, 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.tsbenchmark 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→GifImageare internal and not exported fromsrc/index.ts.
Full Changelog: 5.0.3...5.1.0