refactor: P0-P5 全面架构重构

P1 thiserror 类型化错误:
新增 core/src/error.rs QrError 枚举, 全链 String -> QrError,
包括 EmptyInput/InvalidVersion/DataTooLong/DecodeFail 等 8 种变体

P2 text_builder Tauri 统一:
新增 build_qr_text Tauri command, 删除前端 qrText.ts,
所有 mode 组件改为 invoke 调用 Rust 端构建文本

P3 QrConfig 颜色字段移除:
从 QrConfig/QrCode 移除 fg_color/bg_color,
改为 to_svg/to_image_bytes 参数传递

P4 前端 4 项合并:
Context 拆分为 StateContext+DispatchContext (H10),
新建 useModeForm 通用 hook (M11),
VCardMode grid-cols-2 网格布局 (M13),
persistHistory/loadHistory 迁至 utils/storage.ts (L9)

P5 算法优化:
MaskedView 懒计算替代 8 次 Matrix 克隆 (H9),
encoding_rs 精确 Kanji Shift JIS 映射 (H12)

验证: cargo check+clippy 通过, 81+24+7 全部测试通过
This commit is contained in:
2026-06-21 15:09:10 +08:00
parent 8298cd4c9c
commit cd75141037
46 changed files with 1283 additions and 1028 deletions
+8 -3
View File
@@ -211,8 +211,11 @@ fn estimate_finder_size(gray: &[Vec<bool>], cx: usize, cy: usize) -> usize {
}
/// 从二值化图像中提取 QR 布尔矩阵
pub(crate) fn detect_and_extract(gray: &[Vec<bool>]) -> Result<DetectResult, String> {
let finders = find_finders(gray).ok_or("未找到 QR 码定位图案")?;
pub(crate) fn detect_and_extract(
gray: &[Vec<bool>],
) -> Result<DetectResult, crate::error::QrError> {
let finders =
find_finders(gray).ok_or_else(|| crate::error::QrError::DecodeFail("未找到 QR 码定位图案".into()))?;
let tl = &finders[0]; // top-left
let tr = &finders[1]; // top-right
@@ -222,7 +225,9 @@ pub(crate) fn detect_and_extract(gray: &[Vec<bool>]) -> Result<DetectResult, Str
let module_size = (tl.size + tr.size) / 14; // finder = 7 modules wide
if module_size == 0 {
return Err("模块大小估算为零".into());
return Err(crate::error::QrError::DecodeFail(
"模块大小估算为零".into(),
));
}
// 估算版本