image-pii-redactor 0.1.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/LICENSE ADDED
@@ -0,0 +1,361 @@
1
+ Mozilla Public License Version 2.0
2
+ ==================================
3
+
4
+ 1. Definitions
5
+ --------------
6
+
7
+ 1.1. "Contributor"
8
+ means each individual or legal entity that creates, contributes to
9
+ the creation of, or owns Covered Software.
10
+
11
+ 1.2. "Contributor Version"
12
+ means the combination of the Contributions of others (if any) used
13
+ by a Contributor and that particular Contributor's Contribution.
14
+
15
+ 1.3. "Contribution"
16
+ means Covered Software of a particular Contributor.
17
+
18
+ 1.4. "Covered Software"
19
+ means Source Code Form to which the initial Contributor has attached
20
+ the notice in Exhibit A, the Executable Form of such Source Code
21
+ Form, and Modifications of such Source Code Form, in each case
22
+ including portions thereof.
23
+
24
+ 1.5. "Incompatible With Secondary Licenses"
25
+ means
26
+
27
+ (a) that the initial Contributor has attached the notice described
28
+ in Exhibit B to the Covered Software; or
29
+
30
+ (b) that the Covered Software was made available under the terms of
31
+ version 1.1 or earlier of the License, but not also under the
32
+ terms of a Secondary License.
33
+
34
+ 1.6. "Executable Form"
35
+ means any form of the work other than Source Code Form.
36
+
37
+ 1.7. "Larger Work"
38
+ means a work that combines Covered Software with other material, in
39
+ a separate file or files, that is not Covered Software.
40
+
41
+ 1.8. "License"
42
+ means this document.
43
+
44
+ 1.9. "Licensable"
45
+ means having the right to grant, to the maximum extent possible,
46
+ whether at the time of the initial grant or subsequently, any and
47
+ all of the rights conveyed by this License.
48
+
49
+ 1.10. "Modifications"
50
+ means any of the following:
51
+
52
+ (a) any file in Source Code Form that results from an addition to,
53
+ deletion from, or modification of the contents of Covered
54
+ Software; or
55
+
56
+ (b) any new file in Source Code Form that contains any Covered
57
+ Software.
58
+
59
+ 1.11. "Patent Claims" of a Contributor
60
+ means any patent claim(s), including without limitation, method,
61
+ process, and apparatus claims, in any patent Licensable by such
62
+ Contributor that would be infringed, but for the grant of the
63
+ License, by the making, using, selling, offering for sale, having
64
+ made, importation, or transfer of either its Contributions or its
65
+ Contributor Version.
66
+
67
+ 1.12. "Secondary License"
68
+ means either the GNU General Public License, Version 2.0, the GNU
69
+ Lesser General Public License, Version 2.1, the GNU Affero General
70
+ Public License, Version 3.0, or any later versions of those
71
+ licenses.
72
+
73
+ 1.13. "Source Code Form"
74
+ means the form of the work preferred for making modifications.
75
+
76
+ 1.14. "You" (or "Your")
77
+ means an individual or a legal entity exercising rights under this
78
+ License. For legal entities, "You" includes any entity that
79
+ controls, is controlled by, or is under common control with You.
80
+ For purposes of this definition, "control" means (a) the power,
81
+ direct or indirect, to cause the direction or management of such
82
+ entity, whether by contract or otherwise, or (b) ownership of more
83
+ than fifty percent (50%) of the outstanding shares or voting
84
+ securities entitled to vote for the election of directors or other
85
+ governing board of such entity.
86
+
87
+ 2. License Grants and Conditions
88
+ ---------------------------------
89
+
90
+ 2.1. Grants
91
+
92
+ Each Contributor hereby grants You a world-wide, royalty-free,
93
+ non-exclusive license:
94
+
95
+ (a) under intellectual property rights (other than patent or trademark)
96
+ Licensable by such Contributor to use, reproduce, make available,
97
+ prepare derivative works of, display, run, copy, sell, transfer,
98
+ and otherwise distribute, in each case with or without fee, for any
99
+ purpose;
100
+
101
+ (b) under Patent Claims of such Contributor to make, use, sell, offer
102
+ for sale, have made, import, and otherwise transfer either its
103
+ Contributions or its Contributor Version.
104
+
105
+ 2.2. Effective Date
106
+
107
+ The licenses granted in Section 2.1 with respect to any Contribution
108
+ become effective for each Contribution on the date the Contributor first
109
+ distributes such Contribution.
110
+
111
+ 2.3. Limitations on Grant Scope
112
+
113
+ The licenses granted in this Section 2 are the only rights granted under
114
+ this License. No additional rights or licenses will be implied from the
115
+ distribution or making available of the Covered Software. Notwithstanding
116
+ Section 2.1(b) above, no patent license is granted by a Contributor:
117
+
118
+ (a) for any code that a Contributor has removed from Covered Software;
119
+ or
120
+
121
+ (b) for infringements caused by: (i) Your and any other third party's
122
+ modifications of Covered Software, or (ii) the combination of its
123
+ Contributions with other software (except as part of its Contributor
124
+ Version); or
125
+
126
+ (c) under Patent Claims infringed by Covered Software in the absence of
127
+ its Contributions.
128
+
129
+ This License does not grant any rights in the trademarks, service marks,
130
+ or logos of any Contributor (except as may be necessary to comply with
131
+ the notice requirements in Section 3.4).
132
+
133
+ 2.4. Subsequent Licenses
134
+
135
+ No Contributor makes additional grants as a result of Your choice to
136
+ distribute the Covered Software under a subsequent version of this
137
+ License (see Section 10.2) or under the terms of a Secondary License (if
138
+ permitted under the terms of Section 3.3).
139
+
140
+ 2.5. Representation
141
+
142
+ Each Contributor represents that the Contributor believes its
143
+ Contributions are its original creation(s) or it has sufficient rights
144
+ to grant the rights to its Contributions conveyed by this License.
145
+
146
+ 2.6. Fair Use
147
+
148
+ This License is not intended to limit any rights You have under
149
+ applicable copyright doctrines of fair use, fair dealing, or other
150
+ equivalents.
151
+
152
+ 2.7. Conditions
153
+
154
+ Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
155
+ in Section 2.1.
156
+
157
+ 3. Responsibilities
158
+ -------------------
159
+
160
+ 3.1. Distribution of Source Form
161
+
162
+ All distribution of Covered Software in Source Code Form, including any
163
+ Modifications that You create or to which You contribute, must be under
164
+ the terms of this License. You must inform recipients that the Source
165
+ Code Form of the Covered Software is governed by the terms of this
166
+ License, and how they can obtain a copy of this License. You may not
167
+ attempt to alter or restrict the recipients' rights in the Source Code
168
+ Form.
169
+
170
+ 3.2. Distribution of Executable Form
171
+
172
+ If You distribute Covered Software in Executable Form then:
173
+
174
+ (a) such Covered Software must also be made available in Source Code
175
+ Form, as described in Section 3.1, and You must inform recipients of
176
+ the Executable Form how they can obtain a copy of such Source Code
177
+ Form by reasonable means in a timely manner, at a charge no more
178
+ than the cost of distribution to the recipient; and
179
+
180
+ (b) You may distribute such Executable Form under the terms of this
181
+ License, or sublicense it under different terms, provided that the
182
+ license for the Executable Form does not attempt to limit or alter
183
+ the recipients' rights in the Source Code Form under this License.
184
+
185
+ 3.3. Distribution of a Larger Work
186
+
187
+ You may create and distribute a Larger Work under terms of Your choice,
188
+ provided that You also comply with the requirements of this License for
189
+ the Covered Software. If the Larger Work is a combination of Covered
190
+ Software with a work governed by one or more Secondary Licenses, and the
191
+ Covered Software is not Incompatible With Secondary Licenses, this
192
+ License permits You to additionally distribute such Covered Software
193
+ under the terms of such Secondary License(s), so that the recipient of
194
+ the Larger Work may, at their option, further distribute the Covered
195
+ Software under the terms of either this License or such Secondary
196
+ License(s).
197
+
198
+ 3.4. Notices
199
+
200
+ You may not remove or alter the substance of any license notices
201
+ (including copyright notices, patent notices, disclaimers of warranty,
202
+ or limitations of liability) contained within the Source Code Form of
203
+ the Covered Software, except that You may alter any license notices to
204
+ the extent required to remedy known factual inaccuracies.
205
+
206
+ 3.5. Application of Additional Terms
207
+
208
+ You may choose to offer, and to charge a fee for, warranty, support,
209
+ indemnity or other liability obligations and/or rights consistent with
210
+ this License. However, in accepting such obligations, You may offer only
211
+ obligations that are consistent with this License. If You take on
212
+ additional obligations, You must not place You under obligations that are
213
+ inconsistent with Your own acceptance of this License. You may not offer
214
+ or accept terms in conflict with this License.
215
+
216
+ 4. Inability to Comply Due to Statute or Regulation
217
+ ---------------------------------------------------
218
+
219
+ If it is impossible for You to comply with any of the terms of this
220
+ License with respect to some or all of the Covered Software due to
221
+ statute, judicial order, or regulation then You must: (a) comply with
222
+ the terms of this License to the maximum extent possible; and (b)
223
+ describe the limitations and the part of this License that cannot be
224
+ complied with. Such description must be placed in a text file included
225
+ with all distributions of the Covered Software. Except to the extent
226
+ prohibited by statute or regulation, such description must be
227
+ sufficiently detailed for a recipient of ordinary skill to be able to
228
+ understand it.
229
+
230
+ 5. Termination
231
+ --------------
232
+
233
+ 5.1. The rights granted under this License will terminate automatically
234
+ if You fail to comply with any of its terms. However, if You become
235
+ compliant, then the rights granted under a specific Contributor pursuant
236
+ to Section 2.1 of this License are reinstated (a) provisionally, unless
237
+ and until such Contributor explicitly and finally terminates Your grants,
238
+ and (b) on an ongoing basis, if such Contributor fails to notify You of
239
+ the non-compliance by some reasonable means prior to 60 days after You
240
+ have come into compliance. Moreover, Your grants from a particular
241
+ Contributor are reinstated on an ongoing basis if such Contributor
242
+ notifies You of the non-compliance by some reasonable means, this is the
243
+ first time You have received notice of non-compliance with this License
244
+ from such Contributor, and You become compliant prior to 30 days after
245
+ Your receipt of the notice.
246
+
247
+ 5.2. If You initiate litigation against any entity by asserting a patent
248
+ infringement claim (excluding declaratory judgment actions,
249
+ counter-claims, and cross-claims) alleging that a Contributor Version
250
+ directly or indirectly infringes any patent, then the rights granted to
251
+ You by any and all Contributors for the Covered Software under Section
252
+ 2.1 of this License shall terminate.
253
+
254
+ 5.3. In the event of termination under Sections 5.1 or 5.2 above, all
255
+ end user license agreements (excluding distributors and resellers) which
256
+ have been validly granted by You or Your distributors under this License
257
+ prior to termination shall survive termination.
258
+
259
+ 6. Disclaimer of Warranty
260
+ --------------------------
261
+
262
+ Covered Software is provided under this License on an "as is" basis,
263
+ without warranty of any kind, either expressed, implied, or statutory,
264
+ including, without limitation, warranties that the Covered Software is
265
+ free of defects, merchantable, fit for a particular purpose or
266
+ non-infringing. The entire risk as to the quality and performance of the
267
+ Covered Software is with You. Should any Covered Software prove
268
+ defective in any respect, You (not any Contributor) assume the cost of
269
+ any necessary servicing, repair, or correction. This disclaimer of
270
+ warranty constitutes an essential part of this License. No use of any
271
+ Covered Software is authorized under this License except under this
272
+ disclaimer.
273
+
274
+ 7. Limitation of Liability
275
+ ---------------------------
276
+
277
+ Under no circumstances and under no legal theory, whether tort
278
+ (including negligence), contract, or otherwise, shall any Contributor,
279
+ or anyone who distributes Covered Software as permitted above, be liable
280
+ to You for any direct, indirect, special, incidental, or consequential
281
+ damages of any nature including, without limitation, damages for lost
282
+ profits, loss of goodwill, work stoppage, computer failure or
283
+ malfunction, or any and all other commercial damages or losses, even if
284
+ such Contributor has been advised of the possibility of such damages.
285
+ This limitation of liability shall not apply to liability for death or
286
+ personal injury resulting from such Contributor's negligence to the
287
+ extent applicable law prohibits such limitation. Some jurisdictions do
288
+ not allow the exclusion or limitation of incidental or consequential
289
+ damages, so this limitation and exclusion may not apply to You.
290
+
291
+ 8. Litigation
292
+ -------------
293
+
294
+ Any litigation relating to this License may be brought only in the
295
+ courts of a jurisdiction where the defendant maintains its principal
296
+ place of business and such litigation shall be governed by laws of that
297
+ jurisdiction, without reference to its conflict-of-law provisions.
298
+ Nothing in this Section shall prevent a party's ability to bring
299
+ cross-claims or counter-claims.
300
+
301
+ 9. Miscellaneous
302
+ ----------------
303
+
304
+ This License represents the complete agreement concerning the subject
305
+ matter hereof. If any provision of this License is held to be
306
+ unenforceable, such provision shall be reformed only to the extent
307
+ necessary to make it enforceable. Any law or regulation which provides
308
+ that the language of a contract shall be construed against the drafter
309
+ shall not be used to construe this License against a Contributor.
310
+
311
+ 10. Versions of the License
312
+ ----------------------------
313
+
314
+ 10.1. New Versions
315
+
316
+ Mozilla Foundation is the license steward. Except as provided in Section
317
+ 10.3, no one other than the license steward has the right to modify or
318
+ publish new versions of this License. Each version will be given a
319
+ distinguishing version number.
320
+
321
+ 10.2. Effect of New Versions
322
+
323
+ You may distribute the Covered Software under the terms of the version
324
+ of the License under which You originally received the Covered Software,
325
+ or under the terms of any subsequent version published by the license
326
+ steward.
327
+
328
+ 10.3. Modified Versions
329
+
330
+ If you create software not governed by this License, and you want to
331
+ create a new license for such software, you may create and use a
332
+ modified version of this License if you rename the license and remove
333
+ any references to the name of the license steward (except to note that
334
+ such modified license differs from this License).
335
+
336
+ 10.4. Distributing Source Code Form that is Incompatible With Secondary
337
+ Licenses
338
+
339
+ If You choose to distribute Source Code Form that is Incompatible With
340
+ Secondary Licenses under the terms of this version of the License, the
341
+ notice described in Exhibit B of this License must be attached.
342
+
343
+ Exhibit A - Source Code Form License Notice
344
+ -------------------------------------------
345
+
346
+ This Source Code Form is subject to the terms of the Mozilla Public
347
+ License, v. 2.0. If a copy of the MPL was not distributed with this
348
+ file, You can obtain one at https://mozilla.org/MPL/2.0/.
349
+
350
+ If it is not possible or desirable to put the notice in a particular
351
+ file, then You may include the notice in a location (such as a LICENSE
352
+ file in a relevant directory) where a recipient would be likely to look
353
+ for such a notice.
354
+
355
+ You may add additional accurate notices of copyright ownership.
356
+
357
+ Exhibit B - "Incompatible With Secondary Licenses" Notice
358
+ ---------------------------------------------------------
359
+
360
+ This Source Code Form is "Incompatible With Secondary Licenses", as
361
+ defined by the Mozilla Public License, v. 2.0.
package/README.md ADDED
@@ -0,0 +1,162 @@
1
+ # image-pii-redactor
2
+
3
+ A Web Component that redacts personal information from AI chat screenshots entirely in the browser. No data ever leaves your device.
4
+
5
+ ```html
6
+ <pii-redactor></pii-redactor>
7
+ ```
8
+
9
+ Upload a screenshot → PII is detected and highlighted → review and adjust → export a redacted PNG.
10
+
11
+ ## How it works
12
+
13
+ 1. **OCR** — [Tesseract.js](https://github.com/naptha/tesseract.js) extracts text and word-level bounding boxes from the image
14
+ 2. **PII detection** — A multilingual NER model ([`onnx-community/multilang-pii-ner-ONNX`](https://huggingface.co/onnx-community/multilang-pii-ner-ONNX)) via [Transformers.js](https://github.com/xenova/transformers.js) identifies names, addresses, phone numbers, etc. Regex patterns cover structured PII (SSN, credit card, email, IP address) as a fallback
15
+ 3. **Review** — An SVG overlay lets you toggle, add, or remove redaction boxes before exporting
16
+ 4. **Export** — The final redacted PNG is rendered on a Canvas and returned as a `Blob`
17
+
18
+ Everything runs in the browser. The OCR engine, NER model, and image processing use WebAssembly and WebGPU — no server, no API call, no telemetry.
19
+
20
+ ## Install
21
+
22
+ ```sh
23
+ npm install image-pii-redactor
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ ### As a Web Component
29
+
30
+ ```html
31
+ <script type="module">
32
+ import 'image-pii-redactor';
33
+ </script>
34
+
35
+ <pii-redactor></pii-redactor>
36
+ ```
37
+
38
+ The component self-registers as `<pii-redactor>`. Drop it anywhere — it works in plain HTML, React, Vue, Svelte, or any framework.
39
+
40
+ ### Listening for the result
41
+
42
+ ```js
43
+ const redactor = document.querySelector('pii-redactor');
44
+
45
+ redactor.addEventListener('redaction-confirm', (e) => {
46
+ const { blob, entities, width, height } = e.detail;
47
+ // blob: PNG Blob with redactions burned in
48
+ // entities: array of { label, bbox, source } — no PII, just metadata
49
+ });
50
+
51
+ redactor.addEventListener('redaction-cancel', () => {
52
+ console.log('User cancelled');
53
+ });
54
+ ```
55
+
56
+ ### Configuration
57
+
58
+ ```html
59
+ <pii-redactor
60
+ lang="eng"
61
+ min-confidence="0.7"
62
+ use-regex="true"
63
+ max-file-size="20971520"
64
+ ></pii-redactor>
65
+ ```
66
+
67
+ Or via JavaScript:
68
+
69
+ ```js
70
+ redactor.config = {
71
+ lang: 'eng', // Tesseract language code
72
+ nerModel: 'onnx-community/multilang-pii-ner-ONNX', // HuggingFace model ID
73
+ minConfidence: 0.7, // NER confidence threshold
74
+ useRegex: true, // also run regex patterns
75
+ maxFileSize: 20 * 1024 * 1024, // 20 MB
76
+ memoryMode: 'auto', // 'auto' | 'low' | 'normal'
77
+ };
78
+ ```
79
+
80
+ `memoryMode: 'auto'` detects `navigator.deviceMemory` and uses sequential model loading (OCR → terminate → NER) on devices with less than 4 GB RAM.
81
+
82
+ ### Programmatic pipeline
83
+
84
+ Use the pipeline directly without the UI component:
85
+
86
+ ```js
87
+ import { analyzeImage, renderRedactedImage } from 'image-pii-redactor';
88
+
89
+ const result = await analyzeImage(imageBlob, {
90
+ lang: 'eng',
91
+ nerModel: 'onnx-community/multilang-pii-ner-ONNX',
92
+ minConfidence: 0.7,
93
+ }, (progress) => console.log(progress.message));
94
+
95
+ // result.ocr — full OCR text + word bboxes
96
+ // result.entities — detected PII entities with char offsets
97
+ // result.redactions — proposed redaction boxes in pixel coords
98
+
99
+ const redactedBlob = await renderRedactedImage(imageBlob, result.redactions);
100
+ ```
101
+
102
+ ### Service Worker (offline + privacy firewall)
103
+
104
+ After the first load, the component works fully offline. Register the included Service Worker to cache model files and optionally block all outbound network requests:
105
+
106
+ 1. Copy `node_modules/image-pii-redactor/public/pii-redactor-sw.js` to your web root
107
+ 2. Register it on page load:
108
+
109
+ ```js
110
+ import { registerServiceWorker } from 'image-pii-redactor';
111
+
112
+ await registerServiceWorker();
113
+ ```
114
+
115
+ Once registered, the SW intercepts HuggingFace model downloads and caches them. After models are warm, you can enable the network firewall to block all external requests — verifiable proof that no image data leaves the browser:
116
+
117
+ ```js
118
+ navigator.serviceWorker.controller.postMessage({ type: 'ENABLE_FIREWALL' });
119
+ ```
120
+
121
+ ## Privacy model
122
+
123
+ - **All processing is local.** OCR, NER inference, and image rendering run entirely in the browser using WebAssembly (WASM) and optionally WebGPU.
124
+ - **Models are cached after the first download.** Transformers.js and Tesseract.js both use the browser's Cache API and IndexedDB. Subsequent runs are instant and offline.
125
+ - **Airplane mode works.** After the first run, disconnect from the internet and reload — the tool continues to function. This is the user-facing proof that nothing is server-dependent.
126
+ - **The Service Worker provides a hard network fence.** When enabled, the SW blocks all non-cached outbound requests at the browser level, making it impossible for image data to be exfiltrated even by a compromised dependency.
127
+
128
+ ## Browser support
129
+
130
+ | Feature | Requirement |
131
+ |---------|------------|
132
+ | OCR (Tesseract.js WASM) | Chrome 89+, Firefox 89+, Safari 15+ |
133
+ | NER (Transformers.js WASM) | Same as above |
134
+ | NER (WebGPU acceleration) | Chrome 113+, Edge 113+ |
135
+ | OffscreenCanvas (image pre-processing) | Chrome 69+, Firefox 105+ |
136
+ | Web Components | All modern browsers |
137
+
138
+ Safari is supported but WebGPU acceleration is not available — inference falls back to WASM automatically.
139
+
140
+ ## Development
141
+
142
+ ```sh
143
+ git clone https://github.com/athal7/image-pii-redactor
144
+ cd image-pii-redactor
145
+ npm install
146
+
147
+ npm run dev # start demo at http://localhost:5173
148
+ npm test # unit tests (Vitest, ~250ms)
149
+ npm run test:e2e:fast # fast e2e tests, no model download needed
150
+ npm run build # production library build
151
+ ```
152
+
153
+ E2e tests that exercise the full model pipeline require the dev server to be running:
154
+
155
+ ```sh
156
+ npm run dev &
157
+ npm run test:e2e
158
+ ```
159
+
160
+ ## License
161
+
162
+ [MPL-2.0](LICENSE) — Mozilla Public License 2.0. Modifications to library files must be published under the same license; combining with proprietary code in a larger work is permitted.
@@ -0,0 +1,27 @@
1
+ function n(e) {
2
+ return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
3
+ }
4
+ function c(e) {
5
+ if (Object.prototype.hasOwnProperty.call(e, "__esModule")) return e;
6
+ var o = e.default;
7
+ if (typeof o == "function") {
8
+ var t = function r() {
9
+ return this instanceof r ? Reflect.construct(o, arguments, this.constructor) : o.apply(this, arguments);
10
+ };
11
+ t.prototype = o.prototype;
12
+ } else t = {};
13
+ return Object.defineProperty(t, "__esModule", { value: !0 }), Object.keys(e).forEach(function(r) {
14
+ var u = Object.getOwnPropertyDescriptor(e, r);
15
+ Object.defineProperty(t, r, u.get ? u : {
16
+ enumerable: !0,
17
+ get: function() {
18
+ return e[r];
19
+ }
20
+ });
21
+ }), t;
22
+ }
23
+ export {
24
+ n as a,
25
+ c as g
26
+ };
27
+ //# sourceMappingURL=_commonjsHelpers-MdHo5S7N.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_commonjsHelpers-MdHo5S7N.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;"}