privacy-redact 1.0.3 → 1.2.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.
@@ -4,6 +4,7 @@
4
4
  */
5
5
  import { reviewTemplate } from './template.js';
6
6
  import { attachController } from './controller.js';
7
+ import { normalizeActions } from './actions.js';
7
8
  import reviewCss from './review.css?inline';
8
9
 
9
10
  export const REVIEW_TAG = 'privacy-redact-review';
@@ -61,6 +62,18 @@ class PiiRedactReview extends HTMLElement {
61
62
  this._api?.setStrength(this._strength);
62
63
  }
63
64
 
65
+ /** The release buttons, as a list of actions. Set it before or after the file opens. */
66
+ get actions() {
67
+ return this._api?.getActions() ?? this._actions ?? null;
68
+ }
69
+
70
+ /** A list that breaks the rules throws a TypeError, and the screen keeps its previous list. */
71
+ set actions(value) {
72
+ normalizeActions(value);
73
+ this._actions = value;
74
+ this._api?.setActions(value);
75
+ }
76
+
64
77
  /** A file assigned here opens in the review flow. */
65
78
  get file() {
66
79
  return this._pendingFile ?? null;
@@ -70,6 +83,26 @@ class PiiRedactReview extends HTMLElement {
70
83
  this.open(value);
71
84
  }
72
85
 
86
+ /** Language pack ids or pack objects for detection and OCR. */
87
+ get languages() {
88
+ return this._api?.getScope()?.languages ?? this._languages;
89
+ }
90
+
91
+ set languages(value) {
92
+ this._languages = value;
93
+ this._api?.setScope({ languages: value, regions: this._regions });
94
+ }
95
+
96
+ /** Region pack ids for detection (US, CA, GB, IN). */
97
+ get regions() {
98
+ return this._api?.getScope()?.regions ?? this._regions;
99
+ }
100
+
101
+ set regions(value) {
102
+ this._regions = value;
103
+ this._api?.setScope({ languages: this._languages, regions: value });
104
+ }
105
+
73
106
  connectedCallback() {
74
107
  if (this._api) return;
75
108
  if (!this.shadowRoot) this.attachShadow({ mode: 'open' });
@@ -79,9 +112,15 @@ class PiiRedactReview extends HTMLElement {
79
112
  markup.innerHTML = reviewTemplate;
80
113
  this.shadowRoot.replaceChildren(style, markup.content.cloneNode(true));
81
114
  const strengthAttr = this.getAttribute('strength');
115
+ const langAttr = this.getAttribute('languages');
116
+ const regionAttr = this.getAttribute('regions');
117
+ const parseIds = (raw) => (raw == null || raw === '' ? undefined : raw.trim().split(/\s+/).filter(Boolean));
82
118
  this._api = attachController(this, {
83
119
  style: this._redactStyle || this.getAttribute('redact-style') || undefined,
84
120
  strength: this._strength ?? (strengthAttr != null && strengthAttr !== '' ? Number(strengthAttr) : undefined),
121
+ actions: this._actions,
122
+ languages: this._languages ?? parseIds(langAttr),
123
+ regions: this._regions ?? parseIds(regionAttr),
85
124
  });
86
125
  if (this._pendingFile) this._api.open(this._pendingFile);
87
126
  }
@@ -5,8 +5,12 @@ import { createElement, useEffect, useRef } from 'react';
5
5
  import './element.js';
6
6
 
7
7
  /** Drop-in review screen. `onResult` runs when the person saves, and only then. */
8
- export function PrivacyRedactReview({ file, style, strength, onResult }) {
8
+ export function PrivacyRedactReview({ file, style, strength, actions, languages, regions, onResult }) {
9
9
  const ref = useRef(null);
10
+ // Compare the action list by value, so an inline array does not reset the screen on every render.
11
+ const actionsKey = actions ? JSON.stringify(actions) : '';
12
+ const languagesKey = languages ? JSON.stringify(languages) : '';
13
+ const regionsKey = regions ? JSON.stringify(regions) : '';
10
14
 
11
15
  useEffect(() => {
12
16
  const el = ref.current;
@@ -34,5 +38,23 @@ export function PrivacyRedactReview({ file, style, strength, onResult }) {
34
38
  el.open(file);
35
39
  }, [file]);
36
40
 
41
+ useEffect(() => {
42
+ const el = ref.current;
43
+ if (!el || !actions) return;
44
+ el.actions = actions;
45
+ }, [actionsKey]);
46
+
47
+ useEffect(() => {
48
+ const el = ref.current;
49
+ if (!el || languages == null) return;
50
+ el.languages = languages;
51
+ }, [languagesKey]);
52
+
53
+ useEffect(() => {
54
+ const el = ref.current;
55
+ if (!el || regions == null) return;
56
+ el.regions = regions;
57
+ }, [regionsKey]);
58
+
37
59
  return createElement('privacy-redact-review', { ref });
38
60
  }
@@ -130,7 +130,6 @@
130
130
  .seg button:focus-visible,
131
131
  .fmt select:focus-visible,
132
132
  .slider input:focus-visible,
133
- .transcript-toggle:focus-visible,
134
133
  .transcript-redact:focus-visible,
135
134
  .cat:focus-visible {
136
135
  outline: none;
@@ -180,6 +179,49 @@
180
179
  }
181
180
  .dz-sub { color: var(--on-surface-muted); margin-top: 0.5rem; font-size: 14px; line-height: 1.6; }
182
181
  .dz-formats { color: var(--on-surface-muted); font-size: 13px; font-weight: 400; margin-top: 1rem; letter-spacing: 0.04em; }
182
+ .lang-chips {
183
+ list-style: none;
184
+ margin: 0;
185
+ padding: 0;
186
+ display: flex;
187
+ flex-wrap: wrap;
188
+ gap: 0.4rem;
189
+ }
190
+ .landing-langs {
191
+ justify-content: center;
192
+ margin: 0.85rem auto 0;
193
+ max-width: 38rem;
194
+ }
195
+ .lang-chips .lang-chip {
196
+ display: inline-flex;
197
+ align-items: center;
198
+ gap: 0.3rem;
199
+ margin: 0;
200
+ padding: 0.35rem 0.65rem;
201
+ border: 1px solid color-mix(in srgb, var(--on-surface) 14%, transparent);
202
+ border-radius: var(--radius-md);
203
+ background: var(--surface);
204
+ color: var(--on-surface);
205
+ font: inherit;
206
+ font-size: 13px;
207
+ line-height: 1.3;
208
+ cursor: pointer;
209
+ transition: background var(--ease), border-color var(--ease);
210
+ }
211
+ .lang-chips .lang-chip:hover {
212
+ border-color: color-mix(in srgb, var(--accent) 45%, transparent);
213
+ }
214
+ .lang-chips .lang-chip.on {
215
+ background: color-mix(in srgb, var(--accent) 14%, var(--surface));
216
+ border-color: color-mix(in srgb, var(--accent) 55%, transparent);
217
+ }
218
+ .lang-chips .lang-chip[aria-disabled="true"] {
219
+ cursor: default;
220
+ }
221
+ .lang-chips .lang-chip .mark {
222
+ font-size: 12px;
223
+ line-height: 1;
224
+ }
183
225
  .settings-cue { margin-top: 1rem; }
184
226
  .error {
185
227
  margin: 1rem auto 0;
@@ -351,17 +393,15 @@
351
393
  #scan-card.done .scan-steps { margin-bottom: 0; }
352
394
  #scan-card.done .scan-steps li:not(.done) { display: none; }
353
395
 
354
- .transcript-head { display: flex; align-items: center; flex-wrap: wrap; gap: 0.75rem; min-width: 0; max-width: 100%; }
396
+ .panel-langs { margin: 0; }
355
397
  .transcript-actions {
356
398
  display: flex;
357
399
  align-items: center;
358
400
  flex-wrap: wrap;
359
401
  gap: 0.5rem;
360
- margin-left: auto;
361
- min-width: 0;
362
- max-width: 100%;
402
+ justify-content: flex-start;
403
+ margin: -0.25rem 0 0;
363
404
  }
364
- .transcript-actions > * { flex: none; max-width: 100%; }
365
405
  .transcript-redact {
366
406
  font-family: var(--font-ui);
367
407
  font-size: 13px;
@@ -376,44 +416,9 @@
376
416
  box-shadow: var(--shadow-sm);
377
417
  }
378
418
  .transcript-redact.on { color: var(--on-surface); background: var(--surface-sunken); }
379
- #transcript-empty:not([hidden]) + #transcript-text:not([hidden]) { margin-top: 0.75rem; }
380
- .transcript-toggle {
381
- flex: 1 1 auto;
382
- display: flex;
383
- align-items: center;
384
- gap: 0.75rem;
385
- min-width: 0;
386
- max-width: 100%;
387
- margin: 0;
388
- padding: 0;
389
- border: 0;
390
- background: transparent;
391
- box-shadow: none;
392
- cursor: pointer;
393
- text-align: left;
394
- font-family: var(--font-display);
395
- font-size: 1.25rem;
396
- font-weight: 300;
397
- line-height: 1.4;
398
- letter-spacing: -0.02em;
399
- color: var(--on-surface);
400
- }
401
- .transcript-toggle:hover { background: transparent; transform: none; box-shadow: none; }
402
- .transcript-toggle #transcript-label { min-width: 0; overflow-wrap: anywhere; }
403
- .twist {
404
- width: 0.45rem;
405
- height: 0.45rem;
406
- border-right: 1.5px solid var(--on-surface-muted);
407
- border-bottom: 1.5px solid var(--on-surface-muted);
408
- transform: rotate(-45deg);
409
- transition: transform var(--ease);
410
- flex: none;
411
- }
412
- .transcript.open .twist { transform: rotate(45deg); }
413
- #transcript-panel { margin-top: 1rem; }
414
- #transcript-empty { text-align: left; }
419
+ #transcript-empty { text-align: left; margin: 0.75rem 0 0; }
415
420
  #transcript-text {
416
- margin: 0;
421
+ margin: 0.75rem 0 0;
417
422
  max-height: 16rem;
418
423
  overflow: auto;
419
424
  padding: 1rem;
@@ -427,7 +432,27 @@
427
432
  overflow-wrap: anywhere;
428
433
  user-select: text;
429
434
  color: var(--on-surface);
435
+ scrollbar-width: thin;
436
+ scrollbar-color: transparent transparent;
437
+ }
438
+ #transcript-text.is-scrolling {
439
+ scrollbar-color: color-mix(in srgb, var(--on-surface) 28%, transparent) transparent;
440
+ }
441
+ #transcript-text::-webkit-scrollbar {
442
+ width: 3px;
443
+ height: 3px;
444
+ }
445
+ #transcript-text::-webkit-scrollbar-track {
446
+ background: transparent;
447
+ }
448
+ #transcript-text::-webkit-scrollbar-thumb {
449
+ background: transparent;
450
+ border-radius: 99px;
451
+ }
452
+ #transcript-text.is-scrolling::-webkit-scrollbar-thumb {
453
+ background: color-mix(in srgb, var(--on-surface) 28%, transparent);
430
454
  }
455
+ .transcript-stats { margin: 0.5rem 0 0; text-align: left; }
431
456
 
432
457
  .cats { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.25rem; }
433
458
  .cat {
@@ -498,6 +523,7 @@
498
523
  .meta .empty { color: var(--on-surface-muted); }
499
524
 
500
525
  .export { position: sticky; bottom: 1rem; display: grid; gap: 0.75rem; }
526
+ .actions-list { display: grid; gap: 0.6rem; }
501
527
  .row { display: flex; gap: 0.75rem; }
502
528
  .fmt { display: flex; align-items: center; gap: 0.75rem; color: var(--on-surface-muted); font-size: 15px; font-weight: 400; width: 100%; }
503
529
  .fmt select {
@@ -10,8 +10,9 @@ export const reviewTemplate = `
10
10
  <div class="dz-sub">or <u>browse</u> · or paste with <kbd>Ctrl</kbd>/<kbd>⌘</kbd>+<kbd>V</kbd></div>
11
11
  <div class="dz-formats">PNG · JPG · WebP · GIF · PDF</div>
12
12
  </label>
13
+ <ul id="landing-lang-prefs" class="lang-chips landing-langs" data-lang-prefs role="group" aria-label="Document languages"></ul>
13
14
  <div class="settings-cue">
14
- <button id="btn-settings-landing" class="btn ghost sm" type="button">Choose fields to scan</button>
15
+ <button id="btn-settings-landing" class="btn ghost sm" type="button">Choose what to scan</button>
15
16
  </div>
16
17
  <div id="landing-error" class="error" role="alert" hidden></div>
17
18
  </div>
@@ -59,6 +60,8 @@ export const reviewTemplate = `
59
60
  </div>
60
61
 
61
62
  <aside class="panel">
63
+ <ul id="panel-lang-prefs" class="lang-chips panel-langs" data-lang-prefs role="group" aria-label="Document languages"></ul>
64
+
62
65
  <div class="card" id="scan-card">
63
66
  <div class="card-head"><h2 id="scan-title">Scanning…</h2><span id="scan-count" class="count-badge"></span></div>
64
67
  <ul id="steps" class="scan-steps"></ul>
@@ -67,21 +70,16 @@ export const reviewTemplate = `
67
70
  </div>
68
71
 
69
72
  <div class="card transcript" id="transcript-card">
70
- <div class="transcript-head">
71
- <button type="button" id="transcript-toggle" class="transcript-toggle" aria-expanded="false" aria-controls="transcript-panel">
72
- <span class="twist" aria-hidden="true"></span>
73
- <span id="transcript-label">What the scanner read</span>
74
- </button>
75
- <span class="transcript-actions">
76
- <button type="button" id="transcript-redact" class="transcript-redact on" role="switch" aria-checked="true" title="Hide the words the scanner would cover">Redacted</button>
77
- <span id="transcript-count" class="count-badge"></span>
78
- <button id="btn-transcript-copy" class="btn ghost sm" type="button" disabled>Copy text</button>
79
- </span>
73
+ <div class="card-head">
74
+ <h2 id="transcript-label">What the scanner read</h2>
80
75
  </div>
81
- <div id="transcript-panel" hidden>
82
- <p id="transcript-empty" class="fine" hidden></p>
83
- <pre id="transcript-text"></pre>
76
+ <div class="transcript-actions">
77
+ <button type="button" id="transcript-redact" class="transcript-redact on" role="switch" aria-checked="true" title="Hide the words the scanner would cover">Redacted</button>
78
+ <button id="btn-transcript-copy" class="btn ghost sm" type="button" disabled>Copy text</button>
84
79
  </div>
80
+ <p id="transcript-empty" class="fine" hidden></p>
81
+ <pre id="transcript-text" hidden></pre>
82
+ <p id="transcript-stats" class="fine transcript-stats" hidden></p>
85
83
  </div>
86
84
 
87
85
  <div class="card">
@@ -110,8 +108,15 @@ export const reviewTemplate = `
110
108
  <select id="format"><option value="png">PNG (lossless)</option><option value="jpeg">JPG (smaller)</option></select>
111
109
  </label>
112
110
  </div>
113
- <button id="btn-save" class="btn primary big">Save sanitized file</button>
114
- <button id="btn-copy" class="btn ghost wide">Copy to clipboard</button>
111
+ <div id="send-as" class="seg" role="radiogroup" aria-label="Send as" part="send-as" hidden>
112
+ <button type="button" id="send-as-file" data-send="file" role="radio" aria-checked="false">Image</button>
113
+ <button type="button" data-send="text" role="radio" aria-checked="false">Text</button>
114
+ <button type="button" data-send="both" role="radio" aria-checked="true" class="on">Both</button>
115
+ </div>
116
+ <div id="actions" class="actions-list" part="actions">
117
+ <button id="btn-save" class="btn primary big" data-action-id="download">Save sanitized file</button>
118
+ <button id="btn-copy" class="btn ghost wide">Copy to clipboard</button>
119
+ </div>
115
120
  <div id="save-note" class="save-note" hidden></div>
116
121
  <p class="fine">Auto-detection is good, not perfect. Give the preview a quick look before you share.</p>
117
122
  </div>