privacy-redact 1.0.1 → 1.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "privacy-redact",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "type": "module",
5
5
  "description": "Library for detecting private content, redacting it, and handling document metadata. Browser components cover OCR, faces, barcodes, and PDF pages.",
6
6
  "exports": {
@@ -46,9 +46,12 @@ if (existsSync(faceModelDir)) {
46
46
  console.warn(`[assets] missing ${faceModelDir} - did you run npm install?`);
47
47
  }
48
48
 
49
- // PDF.js fonts + CMaps (needed for PDFs that don't embed their fonts)
49
+ // PDF.js fonts + CMaps (needed for PDFs that don't embed their fonts).
50
+ // wasm/ (image decoders such as JPEG2000) and iccs/ (colour profiles) exist from pdf.js 5 on.
50
51
  copy(nm('pdfjs-dist/standard_fonts'), out('pdfjs/standard_fonts'));
51
52
  copy(nm('pdfjs-dist/cmaps'), out('pdfjs/cmaps'));
53
+ copy(nm('pdfjs-dist/wasm'), out('pdfjs/wasm'));
54
+ copy(nm('pdfjs-dist/iccs'), out('pdfjs/iccs'));
52
55
 
53
56
  // Blend fonts (Crimson Pro, IBM Plex Sans) for static pages under public/ such as the wiki,
54
57
  // which Vite does not process and so cannot resolve the font imports in src/style.css.
@@ -98,7 +98,7 @@ const RULES = [
98
98
  {
99
99
  // "Mobile No.98765-43210" — the dot is glued on, so a bare number pattern never sees a word boundary.
100
100
  type: 'phone',
101
- re: /\b(?:Mobile|Mob|Phone|Tel|Telephone|Cell|Contact)\s*(?:No|Number|#)?\.?\s*[:#\-]?\s*(\+?\d[\d\s.\-()]{7,16}\d)/gi,
101
+ re: /\b(?:Mobile|Mob|Phone|Ph|Phn|Tel|Telephone|Cell|Whatsapp|WA|Contact)\s*(?:No|Number|#)?\.?\s*[:#\-]?\s*(\+?\d[\d\s.\-()]{7,16}\d)/gi,
102
102
  group: 1,
103
103
  validate(m) {
104
104
  const n = m.replace(/\D/g, '').length;
@@ -111,6 +111,12 @@ const RULES = [
111
111
  re: /(?<![\w@/])(?:\+91[\s.\-]?)?[6-9]\d{4}[\s.\-]\d{5}(?!\d)/g,
112
112
  confidence: 0.88,
113
113
  },
114
+ {
115
+ // Unlabelled bare Indian mobile: 9977343444 (10 digits, starts 6-9, not part of a longer number/decimal/ID).
116
+ type: 'phone',
117
+ re: /(?<![\w@/.\-])[6-9]\d{9}(?![\d\-@/]|\.\d)/g,
118
+ confidence: 0.75,
119
+ },
114
120
  {
115
121
  // 123 Main Street, Apt 4B
116
122
  type: 'address',
package/src/io/loader.js CHANGED
@@ -62,30 +62,39 @@ export async function loadFile(file, onStatus) {
62
62
 
63
63
  const data = new Uint8Array(await file.arrayBuffer());
64
64
  const base = new URL(import.meta.env.BASE_URL + 'vendor/pdfjs/', window.location.href).href;
65
- const pdf = await pdfjs.getDocument({
65
+ // In pdf.js 6 only the loading task can be destroyed (PDFDocumentProxy has no destroy()).
66
+ const loadingTask = pdfjs.getDocument({
66
67
  data,
67
68
  standardFontDataUrl: base + 'standard_fonts/',
68
69
  cMapUrl: base + 'cmaps/',
69
70
  cMapPacked: true,
71
+ wasmUrl: base + 'wasm/',
72
+ iccUrl: base + 'iccs/',
70
73
  isEvalSupported: false,
71
- }).promise;
72
- const meta = await readPdfMetadata(pdf);
73
- const count = Math.min(pdf.numPages, MAX_PDF_PAGES);
74
- const pages = [];
75
- for (let i = 1; i <= count; i++) {
76
- onStatus?.(`Rendering page ${i} of ${count}…`);
77
- const page = await pdf.getPage(i);
78
- const viewport = page.getViewport({ scale: PDF_SCALE });
79
- const canvas = document.createElement('canvas');
80
- canvas.width = Math.floor(viewport.width);
81
- canvas.height = Math.floor(viewport.height);
82
- const ctx = canvas.getContext('2d', { willReadFrequently: true });
83
- ctx.fillStyle = '#fff';
84
- ctx.fillRect(0, 0, canvas.width, canvas.height);
85
- await page.render({ canvasContext: ctx, viewport }).promise;
86
- pages.push(canvas);
87
- page.cleanup();
74
+ });
75
+ try {
76
+ const pdf = await loadingTask.promise;
77
+ const meta = await readPdfMetadata(pdf);
78
+ const numPages = pdf.numPages;
79
+ const count = Math.min(numPages, MAX_PDF_PAGES);
80
+ const pages = [];
81
+ for (let i = 1; i <= count; i++) {
82
+ onStatus?.(`Rendering page ${i} of ${count}…`);
83
+ const page = await pdf.getPage(i);
84
+ const viewport = page.getViewport({ scale: PDF_SCALE });
85
+ const canvas = document.createElement('canvas');
86
+ canvas.width = Math.floor(viewport.width);
87
+ canvas.height = Math.floor(viewport.height);
88
+ const ctx = canvas.getContext('2d', { willReadFrequently: true });
89
+ ctx.fillStyle = '#fff';
90
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
91
+ await page.render({ canvasContext: ctx, viewport }).promise;
92
+ pages.push(canvas);
93
+ page.cleanup();
94
+ }
95
+ return { kind, name, pages, meta, truncated: numPages > MAX_PDF_PAGES };
96
+ } finally {
97
+ // Always release the worker, even if parsing or rendering failed.
98
+ await loadingTask.destroy().catch(() => {});
88
99
  }
89
- pdf.destroy();
90
- return { kind, name, pages, meta, truncated: pdf.numPages > MAX_PDF_PAGES };
91
100
  }