@haitang-hub/lingyu-island 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,8 +4,6 @@
4
4
 
5
5
  > 隐私设计原则:**性别、年龄、出生日期等依法用于判断的信息不作为敏感信息,不会屏蔽**;身份证号属于个人身份标识,仍会屏蔽(屏蔽后保留首尾特征,可判断内容类型)。
6
6
 
7
- ![图标](assets/icon.png)
8
-
9
7
  ## 功能
10
8
 
11
9
  | 功能 | 说明 |
@@ -24,6 +22,7 @@
24
22
  - ✅ 中文姓名(**语境驱动**:角色标签「原告/被告/第三人/代理人/负责人/审判长…」、称呼、`,男|女` 结构、职业前缀「村医/村委/米婆…」、强敏感信息邻近)
25
23
  - ✅ 姓名传播:同一文档内首次锚定后,后文只出现名字也会命中;同一批次(如整套卷宗)内跨文件传播
26
24
  - ✅ 家庭住址(保守组合模式)、护照号、车牌号
25
+ - 🔲 **可选检测项(默认关闭,在「设置 → 检测项」中勾选开启)**:固定电话/传真(含 400 热线)、微信号/QQ 号(关键词引导)、港澳台证件(回乡证/台胞证)、统一社会信用代码(GB 32100 校验码验算)
27
26
  - ❌ **不屏蔽**:性别、年龄、出生日期、民族(依法判断需要的数据)
28
27
  - ❌ **不按姓名屏蔽**:机构名与地名(「广东雷阳律师事务所」「雷州市北和镇…村民委员会」「广东省雷州市」),避免把 `雷州市` 误切成 `雷*市`
29
28
  - ❌ 误报控制:无语境的姓名(如"今天上午和张伟开会")不会误屏蔽;姓名后必须是标点/连词/常见谓语,`安排于`、`关于主体`、`文字经` 这类普通词不再被当成名字
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@haitang-hub/lingyu-island",
3
3
  "productName": "灵屿岛",
4
- "version": "1.2.0",
4
+ "version": "1.3.0",
5
5
  "description": "灵动岛式文件屏蔽与恢复工具:拖入文件即可屏蔽个人敏感信息,随时还原",
6
6
  "main": "src/main/main.js",
7
7
  "author": "Haitang-Hub",
@@ -195,8 +195,8 @@ const OCCUPATIONS = [
195
195
  /* ------------------------------------------------------------------ */
196
196
 
197
197
  const RE = {
198
- // 手机号(13-19 号段;边界断言避免命中更长数字串/身份证片段)
199
- phone: /(?<![\dXx])(?:\+?86[-\s·]?)?1[3-9]\d{9}(?![\d])/g,
198
+ // 手机号(13-19 号段;允许 138-1234-5678 / 138 1234 5678 分隔格式;边界断言避免命中更长数字串/身份证片段)
199
+ phone: /(?<![\dXx])(?:\+?86[-\s·]?)?1[3-9]\d[-\s]?\d{4}[-\s]?\d{4}(?!\d)/g,
200
200
  // 身份证 18 位(结构校验 + 校验码验算在代码中完成)
201
201
  idCard: /(?<!\d)[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|1[0-2])(?:0[1-9]|[12]\d|3[01])\d{3}[\dXx](?!\d)/g,
202
202
  // 银行卡(常见 BIN 前缀 + Luhn 验算在代码中完成)
@@ -207,7 +207,20 @@ const RE = {
207
207
  // 车牌(普通 + 新能源)
208
208
  plate: /(?<![\u4e00-\u9fa5A-Za-z0-9])[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵青藏川宁琼使领][A-HJ-NP-Z][A-HJ-NP-Z0-9]{4,5}[A-HJ-NP-Z0-9挂学警港澳](?![\u4e00-\u9fa5A-Za-z0-9])/g,
209
209
  // 案号:(2020)粤0882民特47号 / (2019)最高法民终1234号(允许文书里的空格)
210
- caseNo: /[((]\s*(?:19|20)\d{2}\s*[))]\s*[\u4e00-\u9fa5]{1,8}\s*\d{0,6}\s*[\u4e00-\u9fa5]{1,6}\s*\d{1,6}\s*号/g,
210
+ caseNo: /[((]\s*(?:19|20)\d{2}\s*[))]\s*[\u4e00-\u9fa5]{1,8}\s*\d{0,6}\s*[\u4e00-\u9fa5]{1,6}\s*\d{1,6}\s*号(?:之[一二三四五六七八九十]+)?/g,
211
+ // 固定电话/传真(0 区号 + 7/8 位;允许分隔符),总长 10-12 位
212
+ landline: /(?<!\d)0\d{2,3}[-—\s]?\d{7,8}(?!\d)/g,
213
+ // 400/800 企业热线
214
+ hotline: /(?<!\d)(?:400|800)[-—\s]?\d{3}[-—\s]?\d{4}(?!\d)/g,
215
+ // 社交账号(关键词引导,仿身份证宽松模式)
216
+ imWechat: /(?:微信号|微信账号|WX号|wx号|vx号|VX号|威信号|WeChat号)\s*[::]?\s*([A-Za-z][-_A-Za-z0-9]{5,19})/g,
217
+ imQQ: /(?:QQ号|QQ账号|QQ)\s*[::]?\s*([1-9]\d{4,10})(?!\d)/g,
218
+ // 港澳居民来往内地通行证(回乡证):H/M + 8 位数字
219
+ hkmtPermit: /(?<![A-Za-z0-9])[HM]\d{8}(?![0-9A-Za-z])/g,
220
+ // 台湾居民来往大陆通行证(台胞证):关键词引导
221
+ hkmtTaiwan: /台胞证\s*[::]?\s*([1-9]\d{7})(?!\d)/g,
222
+ // 统一社会信用代码(18 位,结构 + 校验码验算在代码中完成)
223
+ uscc: /(?<![0-9A-Z])[159Y][1239]\d{6}[0-9A-HJ-NPQRTUWXY]{10}(?![0-9A-Z])/g,
211
224
  };
212
225
 
213
226
  // 执业证号(律师/会计师/公证员…):关键词 + 15~20 位编号,可带字母前缀
@@ -215,11 +228,27 @@ const RE_LICENSE = /(?:律师执业证号|执业证号|执业证书号|执业证
215
228
 
216
229
  // 带关键词前缀的宽松匹配(有语境,可放宽校验;覆盖「公民身份号码」「居民身份号码」等法律文书表述)
217
230
  const RE_IDCARD_LOOSE = /(?:公民身份号码|居民身份号码|身份号码|身份证号码|身份证号|身份证|证件号码|证件号)\s*[::]?\s*([1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|1[0-2])(?:0[1-9]|[12]\d|3[01])\d{3}[\dXx])/g;
218
- const RE_BANK_KEYWORD = /(?:银行卡号|卡号|储蓄卡|借记卡|信用卡)\s*[::]?\s*(\d{13,19})/g;
231
+ const RE_BANK_KEYWORD = /(?:银行卡号|银行账号|卡号|账号|储蓄卡|借记卡|信用卡)\s*[::]?\s*(\d{13,19})/g;
219
232
 
220
233
  const ID_WEIGHTS = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
221
234
  const ID_CHECK = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];
222
235
 
236
+ // 统一社会信用代码校验(GB 32100-2015)
237
+ const USCC_CHARSET = '0123456789ABCDEFGHJKLMNPQRTUWXY';
238
+ const USCC_WEIGHTS = [1, 3, 9, 27, 19, 26, 16, 17, 20, 29, 25, 13, 8, 24, 10, 30, 28];
239
+
240
+ /** 统一社会信用代码校验码验算 */
241
+ function isValidUscc(s) {
242
+ if (!/^[159Y][1239]\d{6}[0-9A-HJ-NPQRTUWXY]{10}$/.test(s)) return false;
243
+ let sum = 0;
244
+ for (let i = 0; i < 17; i++) {
245
+ const ci = USCC_CHARSET.indexOf(s[i]);
246
+ if (ci < 0) return false;
247
+ sum += ci * USCC_WEIGHTS[i];
248
+ }
249
+ return USCC_CHARSET[(31 - (sum % 31)) % 31] === s[17];
250
+ }
251
+
223
252
  function isValidIdCard(s) {
224
253
  if (!s || s.length !== 18) return false;
225
254
  let sum = 0;
@@ -513,6 +542,11 @@ function detectStrong(text, opts) {
513
542
  if (opts.email !== false) scan(RE.email, 'email');
514
543
  if (opts.passport !== false) scan(RE.passport, 'passport');
515
544
  if (opts.plate !== false) scan(RE.plate, 'plate');
545
+ // 以下为默认关闭的可选检测项(settings toggles 显式开启才生效)
546
+ if (opts.landline === true) { scan(RE.landline, 'landline'); scan(RE.hotline, 'landline'); }
547
+ if (opts.im === true) { scanGrouped(RE.imWechat, 'im'); scanGrouped(RE.imQQ, 'im'); }
548
+ if (opts.hkmt === true) { scan(RE.hkmtPermit, 'hkmt'); scanGrouped(RE.hkmtTaiwan, 'hkmt'); }
549
+ if (opts.uscc === true) scan(RE.uscc, 'uscc', isValidUscc);
516
550
  return out;
517
551
  }
518
552
 
@@ -544,6 +578,7 @@ const isContained = (item, ranges) =>
544
578
  const PRIORITY = {
545
579
  caseNo: 0, idCard: 1, license: 2, bank: 3, phone: 4,
546
580
  passport: 5, email: 6, plate: 7, address: 8, org: 9, name: 10,
581
+ landline: 4, im: 6, hkmt: 5, uscc: 2,
547
582
  };
548
583
 
549
584
  function dedupe(items) {
@@ -577,6 +612,8 @@ function detect(text, options = {}) {
577
612
  phone: true, idCard: true, bank: true, email: true,
578
613
  passport: true, name: true, address: true, plate: true,
579
614
  caseNo: true, license: true, org: true,
615
+ // 可选检测项:默认关闭(用户在设置中显式开启)
616
+ landline: false, im: false, hkmt: false, uscc: false,
580
617
  ...(options.toggles || {}),
581
618
  };
582
619
 
@@ -598,5 +635,5 @@ function detect(text, options = {}) {
598
635
  }
599
636
 
600
637
  module.exports = {
601
- detect, isValidIdCard, luhnValid, SURNAMES_1, SURNAMES_2, NAME_BLACKLIST, ORG_SUFFIXES,
638
+ detect, isValidIdCard, isValidUscc, luhnValid, SURNAMES_1, SURNAMES_2, NAME_BLACKLIST, ORG_SUFFIXES,
602
639
  };
@@ -21,6 +21,7 @@ const TYPE_LABEL = {
21
21
  phone: '手机号', idCard: '身份证', bank: '银行卡', email: '邮箱',
22
22
  name: '姓名', address: '住址', passport: '护照', plate: '车牌',
23
23
  caseNo: '案号', license: '执业证号', org: '机构名称',
24
+ landline: '固定电话', im: '社交账号', hkmt: '港澳台证件', uscc: '统一社会信用代码',
24
25
  };
25
26
 
26
27
  /* ------------------------------------------------------------------ */
@@ -127,6 +128,16 @@ function buildMasked(type, value, code) {
127
128
  }
128
129
  case 'license': // 1440……7921〔..〕
129
130
  return `${value.slice(0, 4)}……${value.slice(-4)}〔${code}〕`;
131
+ case 'landline': { // 075****5678〔..〕:按数字位对齐手机号风格
132
+ const digits = value.replace(/\D/g, '');
133
+ return `${digits.slice(0, 3)}****${digits.slice(-4)}〔${code}〕`;
134
+ }
135
+ case 'im': // we***89〔..〕:社交账号保留首尾各 2 字符
136
+ return `${value.slice(0, 2)}***${value.slice(-2)}〔${code}〕`;
137
+ case 'hkmt': // H******8〔..〕:同护照风格
138
+ return `${value[0]}******${value.slice(-1)}〔${code}〕`;
139
+ case 'uscc': // 91……WXYZ〔..〕:统一社会信用代码留首 2 尾 4
140
+ return `${value.slice(0, 2)}……${value.slice(-4)}〔${code}〕`;
130
141
  case 'org': { // 广东……律师事务所〔..〕
131
142
  const suffix = ORG_SUFFIXES.find((s) => value.endsWith(s)) || '';
132
143
  const brand = suffix ? value.slice(0, -suffix.length) : value;
@@ -185,6 +196,10 @@ function restoreText(text, vault) {
185
196
  caseNo: '[((]\\d{4}[))]……号',
186
197
  license: '[A-Za-z0-9]{4}……[A-Za-z0-9]{4}',
187
198
  org: `[\\u4e00-\\u9fa5]{2}……(?:${ORG_SUFFIX_ALT})`,
199
+ landline: '\\d{3}\\*{4}\\d{4}',
200
+ im: '.{2}\\*{3}.{2}',
201
+ hkmt: '[A-Za-z]\\*{6}[0-9A-Za-z]',
202
+ uscc: '[0-9A-HJ-NPQRTUWXY]{2}……[0-9A-HJ-NPQRTUWXY]{4}',
188
203
  };
189
204
 
190
205
  let out = text;
@@ -155,7 +155,7 @@ class Island {
155
155
  }
156
156
 
157
157
  hidePanel() {
158
- if (!this.panel || !this.panel.isVisible() || this.panel.isDestroyed()) return;
158
+ if (!this.panel || !this.panel.isVisible()) return;
159
159
  this._stopFade();
160
160
  // 关闭保持立即隐藏(不淡出):与「点击面板外即收起」的即时语义一致,
161
161
  // 也避免淡出窗口期间 isVisible() 仍为 true 造成交互判断歧义
package/src/main/store.js CHANGED
@@ -40,6 +40,8 @@ const DEFAULT_SETTINGS = {
40
40
  phone: true, idCard: true, bank: true, email: true,
41
41
  name: true, address: true, passport: true, plate: true,
42
42
  caseNo: true, license: true, org: true,
43
+ // 可选检测项:默认关闭,用户在设置中勾选开启
44
+ landline: false, im: false, hkmt: false, uscc: false,
43
45
  },
44
46
  clipboardWatch: true, // 剪贴板自动识别可恢复内容
45
47
  autoCollapse: true, // 灵动岛无操作自动收起为顶部线段
package/src/main/tray.js CHANGED
@@ -52,7 +52,11 @@ function createTray(island, store) {
52
52
  // 收起/展开后重建菜单,刷新「隐藏/显示灵动岛」文案
53
53
  island.onPillStateChange = rebuild;
54
54
 
55
- tray.on('click', () => island.togglePanel());
55
+ tray.on('click', () => {
56
+ // 点托盘 = 唤醒灵动岛(收起为线段/被隐藏时先展开)+ 打开面板
57
+ island.expandPill();
58
+ island.togglePanel();
59
+ });
56
60
  return tray;
57
61
  }
58
62
 
@@ -37,6 +37,7 @@ if (!window.island) {
37
37
  phone: true, idCard: true, bank: true, email: true,
38
38
  name: true, address: true, passport: true, plate: true,
39
39
  caseNo: true, license: true, org: true,
40
+ landline: false, im: false, hkmt: false, uscc: false,
40
41
  },
41
42
  clipboardWatch: true,
42
43
  autoCollapse: true,
@@ -456,8 +456,37 @@ input[type="text"]::placeholder, textarea::placeholder { color: var(--ink-3); }
456
456
  row-gap: 2px;
457
457
  margin-top: 2px;
458
458
  }
459
- .detect-grid .switch-row { padding: 4px 0; }
460
- .detect-grid .switch-row .sw-label { font-size: 11.5px; }
459
+ .detect-grid .check-row {
460
+ display: flex;
461
+ align-items: center;
462
+ gap: 7px;
463
+ padding: 4px 0;
464
+ }
465
+ .detect-grid .checkbox {
466
+ position: relative;
467
+ flex: none;
468
+ width: 15px;
469
+ height: 15px;
470
+ border-radius: 4px;
471
+ background: var(--surface-2);
472
+ border: 1px solid var(--line-strong);
473
+ cursor: pointer;
474
+ transition: background 140ms ease, border-color 140ms ease;
475
+ }
476
+ .detect-grid .checkbox:hover { border-color: var(--green); }
477
+ .detect-grid .checkbox.on { background: var(--green); border-color: var(--green); }
478
+ .detect-grid .checkbox.on::after {
479
+ content: "";
480
+ position: absolute;
481
+ left: 4px;
482
+ top: 1px;
483
+ width: 4px;
484
+ height: 8px;
485
+ border: solid #06220f;
486
+ border-width: 0 2px 2px 0;
487
+ transform: rotate(45deg);
488
+ }
489
+ .detect-grid .check-label { font-size: 11.5px; color: var(--ink); white-space: nowrap; }
461
490
  .detect-grid .policy-note { margin-top: 10px; }
462
491
 
463
492
  /* ---------------- 设置:自定义自动收起时长 ---------------- */
@@ -35,13 +35,13 @@
35
35
 
36
36
  <!-- 概览 -->
37
37
  <section class="view is-active" id="view-home">
38
- <div class="dropzone" id="dropzone" tabindex="0" aria-label="拖入文件屏蔽,或点击选择文件">
38
+ <div class="dropzone" id="dropzone" tabindex="0" aria-label="点击选择文件,自动屏蔽或还原">
39
39
  <svg viewBox="0 0 40 40" width="34" height="34" aria-hidden="true">
40
40
  <rect x="6" y="10" width="28" height="18" rx="5" fill="none" stroke="currentColor" stroke-width="1.8"/>
41
41
  <path d="M20 16v10m0 0l-4-4m4 4l4-4" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" fill="none"/>
42
42
  </svg>
43
- <p class="dz-title">拖入文件,自动屏蔽或还原</p>
44
- <p class="dz-sub">按内容识别:明文 → 「文件名_屏蔽」副本,含屏蔽编码的文件 → 「文件名_还原」副本;根目录只保留结果,不生成原文件副本,原位置的文件也不会被改动</p>
43
+ <p class="dz-title">选择文件,自动屏蔽或还原</p>
44
+ <p class="dz-sub">点击下方按钮选取文件(要把文件拖到屏幕顶部的胶囊上也可以);按内容识别:明文 → 「文件名_屏蔽」副本,含屏蔽编码的文件 → 「文件名_还原」副本,根目录只保留结果,原位置的文件不会被改动</p>
45
45
  <button class="btn btn-ghost" id="pickBtn">选择文件…</button>
46
46
  </div>
47
47
 
@@ -544,6 +544,9 @@ const DETECT_ITEMS = [
544
544
  ['email', '电子邮箱'], ['name', '中文姓名'], ['address', '家庭住址'],
545
545
  ['passport', '护照号'], ['plate', '车牌号'],
546
546
  ['caseNo', '案号'], ['license', '执业证号'], ['org', '机构名称'],
547
+ // 可选检测项:默认关闭
548
+ ['landline', '固定电话/传真'], ['im', '微信/QQ'],
549
+ ['hkmt', '港澳台证件'], ['uscc', '统一社会信用代码'],
547
550
  ];
548
551
  const BEHAVIORS = [
549
552
  ['clipboardWatch', '剪贴板自动识别', '复制了含编码的内容时,胶囊提示一键恢复'],
@@ -572,6 +575,29 @@ function makeSwitch(label, desc, on, onChange) {
572
575
  return row;
573
576
  }
574
577
 
578
+ /** 检测项紧凑勾选框:勾选框在前,label 在后(与 makeSwitch 的开关样式区分) */
579
+ function makeCheck(label, on, onChange) {
580
+ const row = document.createElement('div');
581
+ row.className = 'check-row';
582
+ const box = document.createElement('button');
583
+ box.className = 'checkbox' + (on ? ' on' : '');
584
+ box.setAttribute('role', 'checkbox');
585
+ box.setAttribute('aria-checked', String(on));
586
+ box.setAttribute('aria-label', label);
587
+ box.addEventListener('click', () => {
588
+ const next = !box.classList.contains('on');
589
+ box.classList.toggle('on', next);
590
+ box.setAttribute('aria-checked', String(next));
591
+ onChange(next);
592
+ });
593
+ const lab = document.createElement('span');
594
+ lab.className = 'check-label';
595
+ lab.textContent = label;
596
+ row.appendChild(box);
597
+ row.appendChild(lab);
598
+ return row;
599
+ }
600
+
575
601
  function renderImportSeg(s) {
576
602
  for (const b of els.importSeg.children) {
577
603
  const active = b.dataset.v === (s.importBehavior || 'keep');
@@ -595,10 +621,10 @@ function renderSettings(st) {
595
621
  const s = st.settings;
596
622
  renderImportSeg(s);
597
623
  renderConflictSeg(s);
598
- // 检测项(紧凑网格,折叠在 .detect-head,摘要实时更新)
624
+ // 检测项(紧凑网格,勾选框在前,折叠在 .detect-head,摘要实时更新)
599
625
  els.toggleList.innerHTML = '';
600
626
  for (const [key, label] of DETECT_ITEMS) {
601
- els.toggleList.appendChild(makeSwitch(label, '', s.toggles[key], (v) => {
627
+ els.toggleList.appendChild(makeCheck(label, s.toggles[key], (v) => {
602
628
  window.island.invoke('settings:set', { toggles: { [key]: v } });
603
629
  updateDetectSummary();
604
630
  }));
@@ -733,8 +759,8 @@ function setDetectExpanded(expanded) {
733
759
  }
734
760
 
735
761
  function updateDetectSummary() {
736
- const total = els.toggleList.querySelectorAll('.switch').length;
737
- const on = els.toggleList.querySelectorAll('.switch.on').length;
762
+ const total = els.toggleList.querySelectorAll('.checkbox').length;
763
+ const on = els.toggleList.querySelectorAll('.checkbox.on').length;
738
764
  els.detectSummary.textContent = `已启用 ${on}/${total}`;
739
765
  }
740
766
 
@@ -313,6 +313,11 @@ body { position: relative; display: flex; align-items: center; justify-content:
313
313
  /* 忙碌 */
314
314
  .pill.busy .label-idle { color: #ffb340; }
315
315
  .pill.ok .label-idle { color: var(--green); }
316
+ .pill.warn .label-idle { color: #ff6b6b; }
317
+
318
+ /* 反馈期(忙碌/完成/警示):悬停文案不得覆盖反馈文字 */
319
+ .pill.busy .label-hover, .pill.ok .label-hover, .pill.warn .label-hover { opacity: 0; }
320
+ .pill.busy .label-idle, .pill.ok .label-idle, .pill.warn .label-idle { opacity: 1; }
316
321
 
317
322
  /* ---------------- 收起态:屏幕顶边的细线 ----------------
318
323
  主进程切到收起态时窗口已贴住屏幕顶边并开启点击穿透(悬停自动展开),
@@ -14,7 +14,7 @@ let maskedCount = 0;
14
14
 
15
15
  function setState(next) {
16
16
  mode = next;
17
- pill.classList.remove('clip', 'busy', 'ok');
17
+ pill.classList.remove('clip', 'busy', 'ok', 'warn');
18
18
  if (next === 'clip') pill.classList.add('clip');
19
19
  if (next === 'busy') pill.classList.add('busy');
20
20
  resetIdleTimer(); // 状态变化视为一次活动,空闲计时重新开始
@@ -215,6 +215,12 @@ function pickIdleLine() {
215
215
  function refreshIdleLabel() {
216
216
  if (mode === 'busy') return;
217
217
  if (!clipChip.hidden) return;
218
+ // 反馈文案持有期内:只回显持有内容,绝不让闲聊文案/悬停文案顶掉
219
+ if (holdActive()) {
220
+ if (feedbackHold.cls) pill.classList.add(feedbackHold.cls);
221
+ labelIdle.textContent = feedbackHold.text;
222
+ return;
223
+ }
218
224
  const applyLine = () => {
219
225
  labelIdle.textContent = pickIdleLine();
220
226
  fxOnce('swap', 420); // 轻轻浮入,避免生硬跳变
@@ -236,7 +242,7 @@ function scheduleIdleRotate() {
236
242
  setTimeout(() => {
237
243
  if (mode === 'idle' && clipChip.hidden
238
244
  && !document.body.classList.contains('collapsed')
239
- && Date.now() >= feedbackUntil
245
+ && !holdActive()
240
246
  && !pill.matches(':hover')) {
241
247
  refreshIdleLabel();
242
248
  }
@@ -292,21 +298,28 @@ function setBusy(text) {
292
298
  }
293
299
 
294
300
  // 还原结果展示期间忽略主进程的 cleared 广播,避免反馈文案被立刻覆盖
295
- let feedbackUntil = 0;
296
- function showFeedback(text, ok = false) {
297
- feedbackUntil = Date.now() + 2600;
301
+ let feedbackHold = null; // { text, cls, until, timer } —— 反馈文案持有期:悬停/轮换/广播都不抢
302
+
303
+ function holdActive() { return !!(feedbackHold && Date.now() < feedbackHold.until); }
304
+
305
+ function showHold(text, cls, ms) {
306
+ if (feedbackHold) clearTimeout(feedbackHold.timer);
307
+ feedbackHold = { text, cls, until: Date.now() + ms, timer: 0 };
308
+ pill.classList.remove('ok', 'warn');
309
+ if (cls) pill.classList.add(cls);
298
310
  labelIdle.textContent = text;
299
- if (ok) {
300
- pill.classList.add('ok');
301
- celebrate();
302
- } else {
303
- faceShake(); // 没成功 → 轻轻摇头
304
- }
305
311
  resetIdleTimer();
306
- setTimeout(() => {
307
- pill.classList.remove('ok');
312
+ feedbackHold.timer = setTimeout(() => {
313
+ feedbackHold = null;
314
+ pill.classList.remove('ok', 'warn');
308
315
  refreshIdleLabel();
309
- }, 2600);
316
+ }, ms);
317
+ }
318
+
319
+ function showFeedback(text, ok = false) {
320
+ if (ok) celebrate();
321
+ else faceShake(); // 没成功 → 轻轻摇头
322
+ showHold(text, ok ? 'ok' : '', 6000);
310
323
  }
311
324
 
312
325
  async function restoreClipText() {
@@ -351,7 +364,7 @@ window.island.on('clip:found', (info) => {
351
364
  refreshIdleLabel();
352
365
  return;
353
366
  }
354
- feedbackUntil = 0;
367
+ feedbackHold = null; // 新的剪贴板提示优先于未过期的反馈文案
355
368
  setState('clip');
356
369
  dot.classList.add('clip');
357
370
  clipChip.hidden = false;
@@ -368,7 +381,7 @@ window.island.on('clip:found', (info) => {
368
381
  // 剪贴板换成别的内容 / 监听被关闭 → 旧提示立即失效
369
382
  window.island.on('clip:cleared', () => {
370
383
  leaveClip();
371
- if (Date.now() < feedbackUntil) return;
384
+ if (holdActive()) return;
372
385
  setState('idle');
373
386
  refreshIdleLabel();
374
387
  });
@@ -382,8 +395,10 @@ window.island.on('mask:progress', ({ i, total }) => {
382
395
  window.island.on('mask:done', (done) => {
383
396
  if (done.error === 'no-root') {
384
397
  setState('idle');
385
- labelIdle.textContent = '请先在设置中配置根目录';
386
- setTimeout(refreshIdleLabel, 3000);
398
+ // 未配置根目录是拖入失败的主因:必须让用户明确看见,而不是 3 秒一闪而过
399
+ showHold('未配置根目录,正在为你打开设置…', 'warn', 8000);
400
+ // 直接弹出面板的设置页(面板内同步有 toast 提示),省得用户去找入口
401
+ window.island.invoke('panel:show-tab', 'settings');
387
402
  return;
388
403
  }
389
404
  if (done.masked > 0) maskedCount += done.masked;
@@ -394,13 +409,13 @@ window.island.on('mask:done', (done) => {
394
409
  if (done.restored > 0) parts.push(`还原 ${done.restored} 份`);
395
410
  if (done.overwritten > 0) parts.push(`覆盖同名 ${done.overwritten} 份`);
396
411
  if (parts.length) celebrate(); // 有实际成果 → 弹跳 + 高光
397
- labelIdle.textContent = parts.length
412
+ const line = parts.length
398
413
  ? `已完成:${parts.join(' · ')},副本已生成`
399
414
  : (done.restoreMissing > 0 ? '编码无法识别,未还原'
400
415
  : done.alreadyMasked > 0 ? '未找到可还原编码'
401
416
  : done.noPii > 0 ? '未检出敏感信息' : '处理完成');
402
- pill.classList.add('ok');
403
- setTimeout(() => { pill.classList.remove('ok'); refreshIdleLabel(); }, 3000);
417
+ // 完成/结果提示持有 6 秒:期间悬停、闲聊轮换都不会顶掉它
418
+ showHold(line, 'ok', 6000);
404
419
  } else {
405
420
  refreshIdleLabel();
406
421
  }
@@ -561,5 +576,11 @@ window.addEventListener('drop', async (e) => {
561
576
  .filter(Boolean);
562
577
  if (paths.length === 0) return;
563
578
  setBusy(`正在识别并处理 ${paths.length} 个文件…`);
564
- await window.island.invoke('mask:files', paths);
579
+ try {
580
+ await window.island.invoke('mask:files', paths);
581
+ } catch (err) {
582
+ // invoke 层面的异常(如 IPC 竞态)也不能静默,否则胶囊永远卡在忙碌态
583
+ setState('idle');
584
+ showHold('处理失败:' + String(err && err.message || err).slice(0, 30), '', 6000);
585
+ }
565
586
  });
package/test/e2e.js CHANGED
@@ -399,7 +399,7 @@ async function run({ store, island, indexer, updater }) {
399
399
  })()`);
400
400
  console.log('DBG startup replay:', JSON.stringify(dbg));
401
401
  await sleep(400);
402
- const switchCount = await wc.executeJavaScript(`document.querySelectorAll('.switch').length`);
402
+ const switchCount = await wc.executeJavaScript(`document.querySelectorAll('.switch,.checkbox').length`);
403
403
  check('设置项渲染', () => assert.ok(switchCount >= 11, 'switches=' + switchCount + ' dbg=' + JSON.stringify(dbg)));
404
404
 
405
405
  // 检测项折叠:摘要计数 + 展开/收起(localStorage 可能跨次残留 → 先强制归零到收起态再验证)
@@ -413,7 +413,7 @@ async function run({ store, island, indexer, updater }) {
413
413
  out.btnCollapsed = document.getElementById('detectToggleBtn').textContent;
414
414
  head.click(); // 展开
415
415
  out.expandedVisible = !body.hidden;
416
- out.gridSwitches = document.querySelectorAll('#toggleList .switch').length;
416
+ out.gridSwitches = document.querySelectorAll('#toggleList .checkbox').length;
417
417
  out.btnExpanded = document.getElementById('detectToggleBtn').textContent;
418
418
  out.ariaExpanded = head.getAttribute('aria-expanded');
419
419
  head.click(); // 恢复收起,保持设置页紧凑
@@ -422,10 +422,10 @@ async function run({ store, island, indexer, updater }) {
422
422
  })()`);
423
423
  check('检测项折叠与摘要', () => {
424
424
  assert.strictEqual(detectState.collapsedInit, true, '初始应处于收起态');
425
- assert.ok(/已启用 \d+\/11/.test(detectState.summary), detectState.summary);
425
+ assert.ok(/已启用 \d+\/15/.test(detectState.summary), detectState.summary);
426
426
  assert.strictEqual(detectState.btnCollapsed, '展开');
427
427
  assert.strictEqual(detectState.expandedVisible, true, '点击头部后应展开');
428
- assert.strictEqual(detectState.gridSwitches, 11, '展开后应有 11 个检测项开关');
428
+ assert.strictEqual(detectState.gridSwitches, 15, '展开后应有 15 个检测项开关');
429
429
  assert.strictEqual(detectState.btnExpanded, '收起');
430
430
  assert.strictEqual(detectState.ariaExpanded, 'true');
431
431
  assert.strictEqual(detectState.collapsedAfter, true, '再次点击应恢复收起');
package/test/run-tests.js CHANGED
@@ -5,7 +5,7 @@ const assert = require('assert');
5
5
  const fs = require('fs');
6
6
  const path = require('path');
7
7
  const AdmZip = require('adm-zip');
8
- const { detect, isValidIdCard, luhnValid } = require('../src/core/detector');
8
+ const { detect, isValidIdCard, isValidUscc, luhnValid } = require('../src/core/detector');
9
9
  const { Vault, maskText, restoreText, buildMasked, hasCodes } = require('../src/core/masker');
10
10
  const { maskFile, restoreFile, decodeBuffer, encodeText, maskedPathOf } = require('../src/core/fileproc');
11
11
  const { compareVersions } = require('../src/core/version');
@@ -102,6 +102,75 @@ test('检测:无语境姓名不误报(张伟)', () => {
102
102
  assert.ok(!items.some((i) => i.type === 'name' && i.value.includes('张伟')));
103
103
  });
104
104
 
105
+ /* 可选检测项:默认关闭,显式开启才生效 */
106
+
107
+ test('检测:手机号分隔格式(138-1234-5678 / 138 1234 5678)', () => {
108
+ for (const text of ['联系电话138-1234-5678请查收', '电话138 1234 5678备用', '手机13998765432']) {
109
+ const items = detect(text).items.filter((i) => i.type === 'phone');
110
+ assert.strictEqual(items.length, 1, text + ' → ' + JSON.stringify(items));
111
+ }
112
+ });
113
+
114
+ test('可选检测:固定电话/400 热线(默认关,开启后生效)', () => {
115
+ const text = '联系电话0755-1234567,传真 020-87654321,客服400 123 4567。';
116
+ assert.strictEqual(detect(text).items.filter((i) => i.type === 'landline').length, 0, '默认应关闭');
117
+ const items = detect(text, { toggles: { landline: true } }).items.filter((i) => i.type === 'landline');
118
+ assert.strictEqual(items.length, 3, JSON.stringify(items));
119
+ });
120
+
121
+ test('可选检测:微信号/QQ号(关键词引导)', () => {
122
+ const text = '微信号:Lawyer_001,QQ:123456789。';
123
+ assert.strictEqual(detect(text).items.filter((i) => i.type === 'im').length, 0, '默认应关闭');
124
+ const items = detect(text, { toggles: { im: true } }).items.filter((i) => i.type === 'im');
125
+ assert.deepStrictEqual(items.map((i) => i.value), ['Lawyer_001', '123456789'], JSON.stringify(items));
126
+ });
127
+
128
+ test('可选检测:港澳台证件(回乡证/台胞证)', () => {
129
+ const text = '回乡证H12345678,台胞证:12345678。';
130
+ assert.strictEqual(detect(text).items.filter((i) => i.type === 'hkmt').length, 0, '默认应关闭');
131
+ const items = detect(text, { toggles: { hkmt: true } }).items.filter((i) => i.type === 'hkmt');
132
+ assert.deepStrictEqual(items.map((i) => i.value), ['H12345678', '12345678'], JSON.stringify(items));
133
+ });
134
+
135
+ test('可选检测:统一社会信用代码(校验码验算)', () => {
136
+ // 按 GB 32100-2015 构造校验位合法的代码
137
+ const CS = '0123456789ABCDEFGHJKLMNPQRTUWXY';
138
+ const W = [1, 3, 9, 27, 19, 26, 16, 17, 20, 29, 25, 13, 8, 24, 10, 30, 28];
139
+ const base17 = '91330106MA27W1QX1';
140
+ let sum = 0;
141
+ for (let i = 0; i < 17; i++) sum += CS.indexOf(base17[i]) * W[i];
142
+ const valid = base17 + CS[(31 - (sum % 31)) % 31];
143
+ assert.strictEqual(isValidUscc(valid), true);
144
+ assert.strictEqual(isValidUscc(valid.slice(0, 17) + (valid[17] === 'A' ? 'B' : 'A')), false, '校验码错误应拒绝');
145
+
146
+ const text = `统一社会信用代码:${valid}`;
147
+ assert.strictEqual(detect(text).items.filter((i) => i.type === 'uscc').length, 0, '默认应关闭');
148
+ const items = detect(text, { toggles: { uscc: true } }).items.filter((i) => i.type === 'uscc');
149
+ assert.deepStrictEqual(items.map((i) => i.value), [valid], JSON.stringify(items));
150
+ });
151
+
152
+ test('可选检测:新类型的屏蔽值构造与还原', () => {
153
+ const v = new Vault();
154
+ const text = '电话0755-1234567,微信号:Lawyer_001,回乡证H12345678';
155
+ const { masked, items } = maskText(text, v, { toggles: { landline: true, im: true, hkmt: true } });
156
+ assert.strictEqual(items.filter((i) => i.type === 'landline').length, 1);
157
+ const r = restoreText(masked, v);
158
+ assert.strictEqual(r.text, text, '屏蔽后应可完整还原');
159
+ });
160
+
161
+ test('案号:号之一后缀', () => {
162
+ const { items } = detect('(2020)粤0882民初1234号之一');
163
+ const c = items.filter((i) => i.type === 'caseNo');
164
+ assert.strictEqual(c.length, 1, JSON.stringify(items));
165
+ assert.ok(c[0].value.endsWith('号之一'), c[0].value);
166
+ });
167
+
168
+ test('检测:银行卡关键词补充(银行账号/账号)', () => {
169
+ const text = '银行账号6222020200112233456789';
170
+ const { items } = detect(text);
171
+ assert.ok(items.some((i) => i.type === 'bank' && i.value.startsWith('622202')), JSON.stringify(items));
172
+ });
173
+
105
174
  /* 法律文书语境:角色标签命中、地名/机构名与普通词不误伤 */
106
175
  test('检测:角色标签姓名(原告/被告人/审判长)', () => {
107
176
  const cases = [