privacy-redact 0.0.0-stage → 1.0.1

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/LICENSE ADDED
@@ -0,0 +1,195 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 privacy-redact contributors
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
191
+
192
+ ----------------------------------------------------------------------
193
+
194
+ The first approach came from Hushshot (https://github.com/SYasJ/hushshot)
195
+ by SYasJ, copyright HushShot contributors, under the MIT license.
package/README.md CHANGED
@@ -1,3 +1,280 @@
1
- # Temporary Holding Version
1
+ <div align="center">
2
+
3
+ <img src="public/favicon.svg" width="84" alt="privacy-redact logo" />
4
+
5
+ # privacy-redact
6
+
7
+ ### One-click privacy shield for screenshots & documents
8
+
9
+ **Drop an image or PDF → sensitive info is auto-blurred → click Save.**
10
+
11
+ Cards, emails, phones, addresses, faces, barcodes — gone. Hidden metadata — gone. Nothing ever leaves your device.
12
+
13
+ ![Runs offline](https://img.shields.io/badge/network-none-34d399)
14
+ ![No uploads](https://img.shields.io/badge/uploads-0-22d3ee)
15
+
16
+ <img src="docs/before-after.png" alt="Before and after: a fictional pay stub with the SSN, address, email, phone, card, account numbers, face, QR code and barcode blurred" width="100%" />
17
+
18
+ </div>
19
+
20
+ ---
21
+
22
+ ## Why
23
+
24
+ We paste screenshots into **ChatGPT, Claude, Slack, Discord, GitHub issues and social media** all day. Every one of them can quietly contain a home address, a card number, a face that isn't yours, or a QR code that logs someone in. And the "fix" — drawing black boxes by hand in Paint or Photoshop — is tedious, easy to get wrong, and usually leaves the **EXIF/GPS/camera-serial metadata** untouched.
25
+
26
+ privacy-redact makes the safe thing the *easy* thing:
27
+
28
+ 1. **Drop** any image or PDF (or paste a screenshot with <kbd>Ctrl</kbd>/<kbd>⌘</kbd>+<kbd>V</kbd>).
29
+ 2. **Auto-blur** — sensitive items are found and hidden for you. Click any box to un-hide it, drag to hide something we missed.
30
+ 3. **Save** (or **Copy to clipboard**) — a clean file with zero metadata, verified before you share it.
31
+
32
+ > This repository is the library: detection, redaction, and document handling, plus browser components for OCR, faces, barcodes, and PDFs. The page in this repo is a harness for those components, not a brand. A small host that shows each call is in [examples/](examples/README.md).
33
+
34
+ ## Screenshots
35
+
36
+ | Landing | Workspace |
37
+ | --- | --- |
38
+ | <img src="docs/landing.png" alt="privacy-redact landing page with drop zone" /> | <img src="docs/screenshot-app.png" alt="privacy-redact workspace showing detected items with per-category toggles" /> |
39
+
40
+ ## Before & after gallery
41
+
42
+ Three redaction styles, seven document types — all produced by the real app. **[See the full gallery →](docs/EXAMPLES.md)**
43
+
44
+ | Document | Blur · Pixelate · Blackout |
45
+ | --- | --- |
46
+ | 🧾 Pay stub (photo, QR, barcode) | <a href="docs/EXAMPLES.md#1--pay-stub--image-with-photo-qr-code-and-barcode"><img src="docs/examples/paystub-comparison.png" width="420" alt="Pay stub before/after"></a> |
47
+ | 💬 Dark-mode Slack chat (keys, password) | <a href="docs/EXAMPLES.md#2--dark-mode-slack-chat--screenshot-with-secrets"><img src="docs/examples/chat-dark-mode-comparison.png" width="420" alt="Chat before/after"></a> |
48
+ | 🪪 Driver's license | <a href="docs/EXAMPLES.md#3--drivers-license--id-card-with-photo-and-barcode"><img src="docs/examples/id-card-comparison.png" width="420" alt="ID card before/after"></a> |
49
+ | 🏥 Medical intake form | <a href="docs/EXAMPLES.md#4--medical-intake-form--labelled-fields-wrapped-lines"><img src="docs/examples/medical-form-comparison.png" width="420" alt="Medical form before/after"></a> |
50
+ | 💳 Checkout page | <a href="docs/EXAMPLES.md#5--checkout-page--card-billing-details-qr"><img src="docs/examples/checkout-comparison.png" width="420" alt="Checkout before/after"></a> |
51
+ | 👨‍👩‍👧 Group photo (faces) | <a href="docs/EXAMPLES.md#6--group-photo--faces-only"><img src="docs/examples/group-photo-comparison.png" width="420" alt="Group photo before/after"></a> |
52
+ | 📄 Lease PDF | <a href="docs/EXAMPLES.md#7--lease-pdf-page-2--pdf-with-a-real-text-layer"><img src="docs/examples/lease-pdf-page2-comparison.png" width="420" alt="Lease PDF before/after"></a> |
53
+
54
+ ## Features
55
+
56
+ ### 🔍 Detects
57
+
58
+ | Category | Examples | How |
59
+ | --- | --- | --- |
60
+ | 💳 **Credit cards** | `4242 4242 4242 4242`, Amex `3782 822463 10005`, masked `**** 4242` | Regex + **Luhn checksum** (tolerates OCR slips on well-formed 4-4-4-4 groups) |
61
+ | 🪪 **SSN / national ID** | `123-45-6789`, `SSN: 123456789`, `TIN`, `EIN` | Pattern + invalid-range filtering (`000`, `666`, `9xx`) |
62
+ | ✉️ **Emails** | `jane.doe+work@example.co.uk` | RFC-ish regex |
63
+ | 📞 **Phone numbers** | `(415) 555-2671`, `+1 415 555 2671`, `+44 20 7946 0958` | US + international patterns |
64
+ | 🏠 **Home addresses** | `742 Evergreen Terrace, Apt 4B`, `Springfield, IL 62704`, `PO Box 12`, Canadian & UK postcodes | Street/suffix, City-State-ZIP, PO box rules |
65
+ | 🏦 **Account numbers** | `Account No: 00123456789`, `Routing # 021000021`, `MRN`, `Policy`, IBANs | Label-aware: redacts the *value*, not the label |
66
+ | 🎂 **Dates of birth** | `DOB: 04/12/1988`, `Date of Birth March 3, 1990` | Only when labelled – ordinary dates are left alone |
67
+ | 🔑 **API keys & tokens** | `sk-…`, `AKIA…`, `ghp_…`, `xoxb-…`, JWTs, `password: …` | Vendor prefixes + `key=value` |
68
+ | 🙂 **Faces** | Photos, ID pictures, group shots | SSD-MobileNet via TensorFlow.js (tiled scan for small faces) |
69
+ | ▦ **Barcodes & QR** | QR, Code 128/39, EAN/UPC, PDF417, Data Matrix, Aztec | Native `BarcodeDetector` if present, else ZXing with multi-scale retry |
70
+
71
+ ### 🧼 Strips hidden data
72
+
73
+ Before you save, privacy-redact shows exactly what's hiding in your file — and what's about to disappear:
74
+
75
+ - 📍 GPS coordinates & altitude
76
+ - 📷 Camera / phone model, 🔢 body & lens **serial numbers**
77
+ - 🕒 Original capture & edit dates
78
+ - 👤 Owner / author / copyright, 🛠️ editing software
79
+ - 📄 PDF title, author, producer, keywords, dates
80
+ - XMP / IPTC blocks, embedded thumbnails, ICC profiles
81
+
82
+ After export it **re-opens the file it just wrote** and checks that no metadata is left ("re-checked: 0 metadata fields in the output").
83
+
84
+ ### 🎨 Aesthetic, adjustable redaction
85
+
86
+ - **Blur** (default) – soft, pretty, and irreversible (see [How redaction stays irreversible](#-how-redaction-stays-irreversible))
87
+ - **Pixelate** – classic mosaic
88
+ - **Blackout** – maximum-paranoia solid fill
89
+ - **Strength slider**, per-category switches, click-to-toggle on any box, drag-to-add manual boxes
90
+ - **Hold to compare** with the original · multi-page PDFs with page navigation
91
+
92
+ ### 🔒 Private by design
93
+
94
+ - **Everything runs in your browser tab** — OCR (Tesseract), face detection (TensorFlow.js), barcode decoding (ZXing), PDF rendering (PDF.js).
95
+ - Models, WASM and fonts are **bundled** – no CDN calls at runtime. Works fully offline after first load.
96
+ - Production builds ship a strict **Content-Security-Policy** (`connect-src 'self'`, `form-action 'none'`, `object-src 'none'`) so the page is *technically unable* to send your file anywhere.
97
+ - The end-to-end test fails if the app makes even one request to another origin.
98
+ - No analytics, no cookies, no accounts, no telemetry.
99
+
100
+ ## Quick start
101
+
102
+ ### Run it locally
103
+
104
+ ```bash
105
+ npm install # also copies the OCR / face / PDF assets into public/vendor
106
+ npm run dev # → http://localhost:5173
107
+ ```
108
+
109
+ Production build (static files, host anywhere — S3, Netlify, `python -m http.server`, a USB stick):
110
+
111
+ ```bash
112
+ npm run build # → dist/
113
+ npm run preview # serve dist/ at http://localhost:4173
114
+ ```
115
+
116
+ Requires Node 18+ and a modern browser (Chrome/Edge 119+, Firefox 121+, Safari 17.4+).
117
+
118
+ ### Desktop app (experimental)
119
+
120
+ A tiny Electron shell is included. It serves the built app from a loopback-only server and **blocks every non-local network request**.
121
+
122
+ ```bash
123
+ npm run desktop # build + launch
124
+ npm run desktop:pack # installers via electron-builder (dmg / nsis / AppImage) → release/
125
+ ```
126
+
127
+ > The desktop wrapper hasn't had the same test coverage as the web app yet — PRs and bug reports welcome.
128
+
129
+ ## How it works
130
+
131
+ ```mermaid
132
+ flowchart LR
133
+ A[Drop image / PDF] --> B[Decode to canvas<br/>EXIF-orientation applied<br/>PDF pages rasterised]
134
+ B --> C1[OCR<br/>Tesseract.js]
135
+ B --> C2[Faces<br/>SSD-MobileNet]
136
+ B --> C3[Barcodes / QR<br/>ZXing]
137
+ C1 --> D[Pattern engine<br/>regex + Luhn + labels]
138
+ D --> E[Word boxes → pixel rects]
139
+ C2 --> F[Regions]
140
+ C3 --> F
141
+ E --> F
142
+ F --> G[Live preview<br/>blur / pixelate / blackout]
143
+ G --> H[Export from raw pixels<br/>PNG · JPG · flattened PDF]
144
+ H --> I[Re-open & verify<br/>0 metadata fields]
145
+ ```
146
+
147
+ 1. **Decode.** Images become a canvas (transparency flattened, EXIF orientation baked in). PDFs are rendered page-by-page at 144 dpi.
148
+ 2. **Detect.** OCR yields words with bounding boxes. Screenshots are upscaled and dark themes inverted first to help the OCR. Each line is scanned with the rule set in [`src/detect/patterns.js`](src/detect/patterns.js); matches are mapped back to pixels — even partial words like `Email:jane@x.com` are trimmed to just the address.
149
+ 3. **Review.** Every detection is a box you can toggle. Categories can be switched off wholesale.
150
+ 4. **Export.** The redacted canvas is re-encoded from scratch and re-checked.
151
+
152
+ ## 💥 How redaction stays irreversible
153
+
154
+ Bad redaction is worse than none, so:
155
+
156
+ - **Blur and pixelate average pixels into blocks first** (only ~1–2.4 cells across a line of text, ~5–11 across a face), add random per-block noise, and only *then* smooth. The original detail is discarded, not merely obscured — there is nothing to "un-blur". Text cells are deliberately coarser than a glyph because fine mosaics of a known font can be brute-forced back into text ([Depix](https://github.com/spipm/Depix)-style attacks); the jitter stops exact colour matching.
157
+ - **Nothing is layered.** The output image is a new set of pixels. There is no hidden original underneath a box, unlike PDF "highlight" annotations that can be deleted.
158
+ - **PDFs are flattened.** Each page is rasterised, redacted and re-embedded as an image, so the text layer beneath a redaction no longer exists. (The trade-off: exported PDFs aren't text-selectable.)
159
+ - **Nothing is copied byte-for-byte from your source file**, so EXIF, XMP, IPTC, thumbnails and PDF info dictionaries can't tag along. PDFs are written with metadata auto-stamping disabled (no `Producer`, no dates).
160
+ - The e2e suite **OCRs the exported file** and asserts that the SSN, email, phone, card, address and account numbers of the sample document are no longer readable.
161
+
162
+ > Want zero doubt for something extremely sensitive? Pick **Blackout** and drag the strength up.
163
+
164
+ ## Limitations — please read
165
+
166
+ privacy-redact is a safety net, not a guarantee. **Always glance at the preview before sharing.**
167
+
168
+ - **Names aren't detected.** Names are context-dependent and would cause a lot of false positives with regex-only detection. Use the drag-to-hide tool (a local NER model is on the [roadmap](#roadmap)).
169
+ - **OCR isn't perfect.** Tiny fonts, low contrast, unusual fonts, handwriting, rotated or curved text can be missed. A digit misread by OCR can still leave a card *pattern* undetected if it's badly broken up.
170
+ - **English-first.** Address rules are US/Canada/UK oriented; phone rules include international formats; OCR uses the English model.
171
+ - **Faces:** heavily rotated, occluded or tiny faces can be missed; non-faces occasionally trigger. Wide images are scanned in overlapping tiles so small faces are found, at the cost of speed. Toggle boxes to correct.
172
+ - **Barcodes:** without the native `BarcodeDetector` API (Chrome on Windows/Linux, Firefox), 1D codes are located via scan-line heuristics and a structure check that rejects text mistaken for bars. Damaged or very small codes can be missed.
173
+ - **Not detected by design:** license plates, signatures, logos, company names, free-form medical text.
174
+ - **HEIC** photos aren't decodable by browsers – convert to JPG/PNG first.
175
+ - **PDFs** are limited to 60 pages and become image-only.
176
+ - **Performance:** first scan loads ~15 MB of models. Face detection uses WebGL when available; on machines without GPU acceleration it falls back to CPU and can take a while on big images.
177
+ - Filenames aren't scrubbed beyond adding `-redacted`. If your filename contains your name, rename it.
178
+
179
+ ## Project structure
180
+
181
+ ```
182
+ privacy-redact/
183
+ ├── index.html # app shell
184
+ ├── src/
185
+ │ ├── main.js # UI controller (state, scanning pipeline, export)
186
+ │ ├── style.css
187
+ │ ├── detect/
188
+ │ │ ├── patterns.js # 🧠 the rule engine (pure JS, unit-tested)
189
+ │ │ ├── textRegions.js # OCR words ↔ character ranges ↔ pixel rects, wrapped-line + neighbour merging (pure, unit-tested)
190
+ │ │ ├── ocr.js # Tesseract.js worker wrapper (+ pre-processing)
191
+ │ │ ├── faces.js # TensorFlow.js face detection with tiling + NMS
192
+ │ │ └── barcodes.js # BarcodeDetector / ZXing multi-scale fallback
193
+ │ ├── render/effects.js # blur · pixelate · blackout
194
+ │ └── io/
195
+ │ ├── loader.js # image + PDF → canvases
196
+ │ ├── metadata.js # what's hidden in the file + post-export verification
197
+ │ └── exporter.js # PNG / JPG / flattened PDF writers
198
+ ├── scripts/
199
+ │ ├── copy-assets.mjs # vendors OCR/face/PDF assets into public/vendor (postinstall)
200
+ │ ├── make-samples.mjs # generates the fictional sample docs
201
+ │ └── make-before-after.mjs # README hero image
202
+ ├── public/samples/ # fictional pay stub, chat, ID, medical form, checkout, group photo, GPS JPG, lease PDF
203
+ ├── docs/EXAMPLES.md # before/after gallery (docs/examples/*)
204
+ ├── test/ # node --test unit tests (*.test.js)
205
+ │ └── smoke.e2e.test.js # Playwright end-to-end test incl. OCR-of-output check (npm run test:e2e)
206
+ ├── desktop/ # optional Electron wrapper
207
+ └── .github/workflows/ # CI + GitHub Pages deploy
208
+ ```
209
+
210
+ ## Testing
211
+
212
+ ```bash
213
+ npm test # unit tests (rules, box mapping, metadata, redaction cell size) — under a second
214
+ npm run test:e2e:setup # one-time: download Chromium for Playwright
215
+ npm run build && npm run preview & # then:
216
+ npm run test:e2e -- http://localhost:4173/ # full pipeline in headless Chromium
217
+ npm run test:e2e:ci # all of the above in one go: install Chromium, build, serve, test (used by the manual E2E workflow)
218
+ ```
219
+
220
+ The e2e test drives the real UI against the **production build** (so the CSP is enforced) and asserts:
221
+
222
+ - every category is detected on the sample pay stub (email, phones, SSN, addresses, card, account/routing, DOB, face, QR + barcode)
223
+ - the exported PNG can no longer be OCR'd for any secret, while normal text remains readable
224
+ - a JPEG with **GPS + camera model** comes out with no EXIF segment
225
+ - a 2-page PDF with a real text layer and author metadata comes out with **no selectable secret text and an empty info dictionary**
226
+ - **zero** requests to external origins and zero console errors / CSP violations
227
+
228
+ All sample data is fictional (`4242 4242 4242 4242` is a public test card number; the portrait is AI-generated). Regenerate with `npm run samples`.
229
+
230
+ ## Roadmap
231
+
232
+ - [ ] Optional local **name / organisation detection** (small on-device NER model)
233
+ - [ ] Batch mode – drop a folder, get a folder
234
+ - [ ] Watch-folder / clipboard-monitor mode for the desktop app
235
+ - [ ] More locales (EU addresses & national IDs, IBAN validation, non-Latin OCR packs)
236
+ - [ ] License-plate & signature detectors
237
+ - [ ] "Keep text selectable" PDF mode using true content-stream redaction
238
+ - [ ] Browser extension: right-click any image → privacy-redact
239
+ - [ ] Installable PWA (a web manifest ships already; offline service worker still to do)
240
+ - [ ] Custom rules (bring your own regex / keywords, e.g. an employee-ID format)
241
+
242
+ ## FAQ
243
+
244
+ **Does anything get uploaded?** No. There is no backend. Open your browser's Network tab and see for yourself — after the page loads, dropping a file causes zero requests.
245
+
246
+ **Why not just blur it in Preview / Paint?** You can, but you have to spot every item yourself, get the boxes right, and remember that the file's EXIF/GPS data is still there. privacy-redact does the spotting and the scrubbing.
247
+
248
+ **Is PNG/JPG export lossless / does it change my image?** PNG is lossless. JPG is re-encoded at quality 93. Colour profiles are dropped (part of metadata stripping), which may shift colours very slightly on wide-gamut photos.
249
+
250
+ **Can I add my own patterns?** Yes — see [CONTRIBUTING.md](CONTRIBUTING.md#adding-a-detection-rule). It's one object in `patterns.js`.
251
+
252
+ **Why is the first scan slow?** The OCR engine and face model load on first use, then get reused for the rest of the session.
253
+
254
+ ## Security
255
+
256
+ Found a way to recover redacted content or leak data? Please see [SECURITY.md](SECURITY.md) — use a private report, and only ever share fictional documents.
257
+
258
+ ## Credits
259
+
260
+ This repository started from [Hushshot](https://github.com/SYasJ/hushshot) by [SYasJ](https://github.com/SYasJ). That project is the offline browser tool that finds private content in a screenshot or PDF, redacts it, and strips metadata. Its license is MIT. This repository borrowed that first approach and aligned it as a library a host can call, including before a document goes to an AI.
261
+
262
+ This repository runs them through the JavaScript projects listed with each one. Those projects keep their own licenses.
263
+
264
+ | Project | What it does here | License |
265
+ | --- | --- | --- |
266
+ | [Tesseract OCR](https://github.com/tesseract-ocr/tesseract) | Recognizes text. The English traineddata vendored with the page is Tesseract language data. | Apache-2.0 |
267
+ | [Tesseract.js](https://github.com/naptha/tesseract.js) and [tesseract.js-core](https://github.com/naptha/tesseract.js-core) | Runs that engine in the browser and in Node, from the vendored worker and WASM. | Apache-2.0 |
268
+ | [TensorFlow](https://github.com/tensorflow/tensorflow) and [TensorFlow.js](https://github.com/tensorflow/tfjs) | Runs the face model. TensorFlow.js is bundled inside face-api and is not loaded from the network. | Apache-2.0 |
269
+ | [face-api.js](https://github.com/justadudewhohacks/face-api.js), continued as [@vladmandic/face-api](https://github.com/vladmandic/face-api) | Finds faces with the SSD MobileNet v1 model shipped in that package. | MIT |
270
+ | [ZXing](https://github.com/zxing/zxing) and [@zxing/library](https://github.com/zxing-js/library) | Decodes barcodes and QR codes when the browser has no `BarcodeDetector`. | Apache-2.0, MIT for the JavaScript port |
271
+ | [PDF.js](https://github.com/mozilla/pdf.js) | Reads and rasterizes PDFs. | Apache-2.0 |
272
+ | [pdf-lib](https://github.com/Hopding/pdf-lib) | Writes the flattened PDF. | MIT |
273
+ | [exifr](https://github.com/MikeKovarik/exifr) | Reads image metadata so the export can be checked. | MIT |
274
+
275
+ The page is built with [Vite](https://vitejs.dev/) (MIT). End-to-end tests use [Playwright](https://playwright.dev/) (Apache-2.0). [Crimson Pro](https://github.com/Fonthausen/CrimsonPro) and [IBM Plex Sans](https://github.com/IBM/plex) are used under the SIL Open Font License.
276
+
277
+ ## License
278
+
279
+ All rights reserved. See [LICENSE](LICENSE). See [CONTRIBUTING.md](CONTRIBUTING.md) to get involved.
2
280
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
package/package.json CHANGED
@@ -1,6 +1,97 @@
1
1
  {
2
2
  "name": "privacy-redact",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.1",
4
+ "type": "module",
5
+ "description": "Library for detecting private content, redacting it, and handling document metadata. Browser components cover OCR, faces, barcodes, and PDF pages.",
6
+ "exports": {
7
+ ".": "./src/index.js",
8
+ "./ui": "./src/review/element.js",
9
+ "./react": "./src/review/react.js",
10
+ "./vite": "./src/host/assets.js",
11
+ "./detect/ocr": "./src/detect/ocr.js",
12
+ "./detect/faces": "./src/detect/faces.js",
13
+ "./detect/barcodes": "./src/detect/barcodes.js",
14
+ "./render/effects": "./src/render/effects.js",
15
+ "./io/loader": "./src/io/loader.js",
16
+ "./io/exporter": "./src/io/exporter.js",
17
+ "./io/metadata": "./src/io/metadata.js"
18
+ },
19
+ "license": "Apache-2.0",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/gitcommitshow/privacy-redact.git"
23
+ },
24
+ "homepage": "https://github.com/gitcommitshow/privacy-redact#readme",
25
+ "bugs": {
26
+ "url": "https://github.com/gitcommitshow/privacy-redact/issues"
27
+ },
28
+ "files": [
29
+ "src",
30
+ "scripts/copy-assets.mjs",
31
+ "README.md"
32
+ ],
33
+ "peerDependencies": {
34
+ "react": ">=18",
35
+ "react-dom": ">=18"
36
+ },
37
+ "peerDependenciesMeta": {
38
+ "react": {
39
+ "optional": true
40
+ },
41
+ "react-dom": {
42
+ "optional": true
43
+ }
44
+ },
45
+ "scripts": {
46
+ "postinstall": "node scripts/copy-assets.mjs",
47
+ "dev": "vite",
48
+ "playground": "npm run dev --prefix examples/playground",
49
+ "build": "node scripts/copy-assets.mjs && vite build",
50
+ "preview": "vite preview",
51
+ "test": "node --test \"test/!(*.e2e).test.js\"",
52
+ "test:e2e": "node test/smoke.e2e.test.js",
53
+ "test:e2e:setup": "playwright install chromium",
54
+ "test:e2e:ci": "node scripts/run-e2e.mjs",
55
+ "samples": "node scripts/make-samples.mjs",
56
+ "desktop": "npm run build && npx electron desktop/main.cjs",
57
+ "desktop:pack": "npm run build && npx electron-builder --config desktop/electron-builder.yml",
58
+ "examples": "node scripts/make-examples.mjs",
59
+ "examples:inputs": "node scripts/make-example-inputs.mjs"
60
+ },
61
+ "devDependencies": {
62
+ "jsbarcode": "^3.12.3",
63
+ "playwright": "^1.63.0",
64
+ "qrcode": "^1.5.4",
65
+ "vite": "^8.3.2",
66
+ "wait-on": "^9.4.0"
67
+ },
68
+ "dependencies": {
69
+ "@tesseract.js-data/eng": "^1.0.0",
70
+ "@vladmandic/face-api": "^1.7.15",
71
+ "@zxing/library": "^0.23.0",
72
+ "exifr": "^7.1.3",
73
+ "pdf-lib": "^1.17.1",
74
+ "pdfjs-dist": "^6.3.289",
75
+ "tesseract.js": "^7.0.0"
76
+ },
77
+ "keywords": [
78
+ "privacy",
79
+ "redaction",
80
+ "redact",
81
+ "screenshot",
82
+ "pdf",
83
+ "ocr",
84
+ "pii",
85
+ "exif",
86
+ "gps",
87
+ "metadata",
88
+ "blur",
89
+ "face-blur",
90
+ "anonymize",
91
+ "local-first",
92
+ "offline"
93
+ ],
94
+ "engines": {
95
+ "node": ">=24"
96
+ }
97
+ }
@@ -0,0 +1,59 @@
1
+ // Copies the OCR engine, language data, face model and PDF.js fonts out of node_modules into
2
+ // public/vendor so the app is fully self-contained and never touches a CDN at runtime.
3
+ import { cpSync, mkdirSync, existsSync, readdirSync } from 'node:fs';
4
+ import { dirname, join } from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+
7
+ const root = join(dirname(fileURLToPath(import.meta.url)), '..');
8
+ /**
9
+ * Resolves `p` inside the closest node_modules, walking up from the package root.
10
+ * When this package is installed in another project, its dependencies are hoisted
11
+ * to the host's node_modules instead of living under the package itself.
12
+ * Falls back to the package-local path so the "missing" warning stays meaningful.
13
+ */
14
+ function nm(p) {
15
+ let dir = root;
16
+ for (;;) {
17
+ const candidate = join(dir, 'node_modules', p);
18
+ if (existsSync(candidate)) return candidate;
19
+ const parent = dirname(dir);
20
+ if (parent === dir) return join(root, 'node_modules', p);
21
+ dir = parent;
22
+ }
23
+ }
24
+ const out = (p) => join(root, 'public', 'vendor', p);
25
+
26
+ function copy(src, dest) {
27
+ if (!existsSync(src)) { console.warn(`[assets] missing ${src} – did you run npm install?`); return; }
28
+ mkdirSync(dirname(dest), { recursive: true });
29
+ cpSync(src, dest, { recursive: true });
30
+ }
31
+
32
+ // Tesseract OCR: worker + LSTM-only WASM cores (plain + SIMD) + English model
33
+ copy(nm('tesseract.js/dist/worker.min.js'), out('tesseract/worker.min.js'));
34
+ for (const f of ['tesseract-core-lstm.wasm.js', 'tesseract-core-simd-lstm.wasm.js']) {
35
+ copy(nm(`tesseract.js-core/${f}`), out(`tesseract/${f}`));
36
+ }
37
+ copy(nm('@tesseract.js-data/eng/4.0.0_best_int/eng.traineddata.gz'), out('tesseract/eng.traineddata.gz'));
38
+
39
+ // Face detection model (SSD MobileNet v1)
40
+ const faceModelDir = nm('@vladmandic/face-api/model');
41
+ if (existsSync(faceModelDir)) {
42
+ for (const f of readdirSync(faceModelDir).filter((n) => n.startsWith('ssd_mobilenetv1'))) {
43
+ copy(join(faceModelDir, f), out(`face-models/${f}`));
44
+ }
45
+ } else {
46
+ console.warn(`[assets] missing ${faceModelDir} - did you run npm install?`);
47
+ }
48
+
49
+ // PDF.js fonts + CMaps (needed for PDFs that don't embed their fonts)
50
+ copy(nm('pdfjs-dist/standard_fonts'), out('pdfjs/standard_fonts'));
51
+ copy(nm('pdfjs-dist/cmaps'), out('pdfjs/cmaps'));
52
+
53
+ // Blend fonts (Crimson Pro, IBM Plex Sans) for static pages under public/ such as the wiki,
54
+ // which Vite does not process and so cannot resolve the font imports in src/style.css.
55
+ for (const f of ['crimson-pro-300.woff2', 'ibm-plex-sans-300.woff2', 'ibm-plex-sans-400.woff2']) {
56
+ copy(join(root, 'src', 'fonts', f), out(`fonts/${f}`));
57
+ }
58
+
59
+ console.log('[assets] vendored offline assets ready in public/vendor');