accessibility-plugin-react 2.30.0 → 2.30.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/dist/index.d.mts +12 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.js +234 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +233 -15
- package/dist/index.mjs.map +1 -1
- package/docs/API.md +1 -0
- package/docs/CSP.md +10 -7
- package/docs/TRANSLATION.md +20 -12
- package/package.json +1 -1
package/docs/API.md
CHANGED
|
@@ -295,6 +295,7 @@ Opt-in research prototype controller enabling host application content translati
|
|
|
295
295
|
- `extractTranslatableNodes(root: Element, maxNodes?: number): TranslatableNode[]`: Traverses DOM tree starting from root and collects translatable text nodes, strictly skipping sensitive elements.
|
|
296
296
|
- `sanitizeTranslationOutput(raw: string): string`: Sanitizes translated strings, stripping control characters and null bytes.
|
|
297
297
|
- `applyTranslations(nodes: TranslatableNode[], translations: string[]): () => void`: Safely assigns translated strings to text nodes via `textContent` and returns an idempotent restore callback.
|
|
298
|
+
- `createGoogleTranslateAdapter(options?: GoogleTranslateAdapterOptions): TranslationAdapter`: Default adapter for `<TranslationController />` querying Google Translate (`translate.googleapis.com/translate_a/single`) after explicit consent, with caching and automatic offline fallback.
|
|
298
299
|
- `createOfflineMockTranslationAdapter(options?): TranslationAdapter`: Creates a local offline mock translation adapter operating with zero network requests.
|
|
299
300
|
- `translateHostContent(options): Promise<TranslationSession>`: Coordinates end-to-end translation, enforcing consent, provider language support, sensitive element exclusion, and DOM restoration.
|
|
300
301
|
- `TRANSLATION_DISCLAIMER`: Constant string disclaimer emphasizing prototype status and zero official WCAG compliance claims.
|
package/docs/CSP.md
CHANGED
|
@@ -64,6 +64,7 @@ const cspHeader = `
|
|
|
64
64
|
style-src-attr 'unsafe-inline';
|
|
65
65
|
img-src 'self' data:;
|
|
66
66
|
font-src 'self' data:;
|
|
67
|
+
connect-src 'self' https://translate.googleapis.com;
|
|
67
68
|
object-src 'none';
|
|
68
69
|
base-uri 'self';
|
|
69
70
|
form-action 'self';
|
|
@@ -116,6 +117,7 @@ export function middleware(request: NextRequest) {
|
|
|
116
117
|
style-src-attr 'unsafe-inline';
|
|
117
118
|
img-src 'self' data:;
|
|
118
119
|
font-src 'self' data:;
|
|
120
|
+
connect-src 'self' https://translate.googleapis.com;
|
|
119
121
|
base-uri 'self';
|
|
120
122
|
form-action 'self';
|
|
121
123
|
`
|
|
@@ -169,6 +171,7 @@ For Vite applications, configure CSP headers either through your production web
|
|
|
169
171
|
style-src-attr 'unsafe-inline';
|
|
170
172
|
img-src 'self' data:;
|
|
171
173
|
font-src 'self' data:;
|
|
174
|
+
connect-src 'self' https://translate.googleapis.com;
|
|
172
175
|
"
|
|
173
176
|
/>
|
|
174
177
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
@@ -185,10 +188,10 @@ For Vite applications, configure CSP headers either through your production web
|
|
|
185
188
|
|
|
186
189
|
## 4. Verification Checklist
|
|
187
190
|
|
|
188
|
-
| Requirement | Directive
|
|
189
|
-
| :---------------------------- |
|
|
190
|
-
| **Widget UI Styles** | `style-src 'self'` (with static `style.css` import)
|
|
191
|
-
| **Dynamic Host Effects** | `style-src-attr 'unsafe-inline'`
|
|
192
|
-
| **Big High-Contrast Cursor** | `img-src 'self' data:`
|
|
193
|
-
| **No External Font Requests** | `font-src 'self'`
|
|
194
|
-
| **No Network Calls** | No special `connect-src`
|
|
191
|
+
| Requirement | Directive | Why It Is Needed |
|
|
192
|
+
| :---------------------------- | :-------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
193
|
+
| **Widget UI Styles** | `style-src 'self'` (with static `style.css` import) | Renders the Clean light widget panel, trigger, and control cards |
|
|
194
|
+
| **Dynamic Host Effects** | `style-src-attr 'unsafe-inline'` | Applies runtime font-size, line-height, and filter adjustments to host elements |
|
|
195
|
+
| **Big High-Contrast Cursor** | `img-src 'self' data:` | Allows SVG data URI pointer rendering |
|
|
196
|
+
| **No External Font Requests** | `font-src 'self'` | The plugin does not load external web fonts; all font-legibility features use local and system fallbacks |
|
|
197
|
+
| **No Network Calls** | No special `connect-src` (unless using `TranslationController`) | Core preferences, state persistence, and effects operate 100% locally; opt-in `TranslationController` (`createGoogleTranslateAdapter()`) connects to `https://translate.googleapis.com` only after explicit user consent (`connect-src 'self' https://translate.googleapis.com`), with automatic offline fallback if blocked |
|
package/docs/TRANSLATION.md
CHANGED
|
@@ -8,12 +8,12 @@ The host-content translation adapter (**A11Y-409**) provides a decoupled, privac
|
|
|
8
8
|
|
|
9
9
|
### Strict Distinction from Widget Localization
|
|
10
10
|
|
|
11
|
-
| Dimension | Widget UI Localization (`docs/LOCALES.md`) | Host-Content Translation (`docs/TRANSLATION.md`)
|
|
12
|
-
| :------------------- | :---------------------------------------------- |
|
|
13
|
-
| **Target Scope** | Widget buttons, labels, and dialog strings only | Arbitrary host document content (articles, headings)
|
|
14
|
-
| **Network Requests** | **Zero** — 100% static bundled locale packs | **
|
|
15
|
-
| **Privacy Risk** | None (no host content read) | High (host text transmitted to provider if configured)
|
|
16
|
-
| **User Consent** | Not required (local interface strings) | **Mandatory explicit consent** prior to transmission
|
|
11
|
+
| Dimension | Widget UI Localization (`docs/LOCALES.md`) | Host-Content Translation (`docs/TRANSLATION.md`) |
|
|
12
|
+
| :------------------- | :---------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------- |
|
|
13
|
+
| **Target Scope** | Widget buttons, labels, and dialog strings only | Arbitrary host document content (articles, headings) |
|
|
14
|
+
| **Network Requests** | **Zero** — 100% static bundled locale packs | **Opt-in after consent** — `createGoogleTranslateAdapter()` (default on `<TranslationController />`) or custom/offline adapter |
|
|
15
|
+
| **Privacy Risk** | None (no host content read) | High (host text transmitted to provider if configured) |
|
|
16
|
+
| **User Consent** | Not required (local interface strings) | **Mandatory explicit consent** prior to transmission |
|
|
17
17
|
|
|
18
18
|
---
|
|
19
19
|
|
|
@@ -94,11 +94,11 @@ The engine automatically scans element tags, attributes, and ancestor trees (`is
|
|
|
94
94
|
|
|
95
95
|
### 3. Content Security Policy (CSP)
|
|
96
96
|
|
|
97
|
-
If a host application uses a remote translation API (e.g. Google Cloud, DeepL, LibreTranslate):
|
|
97
|
+
If a host application uses the default Google Translate adapter or a custom remote translation API (e.g. Google Cloud, DeepL, LibreTranslate):
|
|
98
98
|
|
|
99
99
|
- The host's `connect-src` CSP directive must explicitly permit the provider endpoint:
|
|
100
100
|
```http
|
|
101
|
-
Content-Security-Policy: default-src 'self'; connect-src 'self' https://
|
|
101
|
+
Content-Security-Policy: default-src 'self'; connect-src 'self' https://translate.googleapis.com;
|
|
102
102
|
```
|
|
103
103
|
- If an on-device local model (e.g., Transformers.js via WebAssembly or browser native Translation API `ai.translator`) is used, no external `connect-src` is required, though `wasm-unsafe-eval` may be needed for WebAssembly execution.
|
|
104
104
|
|
|
@@ -139,14 +139,22 @@ session.restore();
|
|
|
139
139
|
|
|
140
140
|
## Example Custom Providers
|
|
141
141
|
|
|
142
|
-
### 1.
|
|
142
|
+
### 1. Google Translate Adapter (Default on `<TranslationController />`) & Offline Fallback
|
|
143
143
|
|
|
144
|
-
|
|
144
|
+
`<TranslationController />` defaults to `createGoogleTranslateAdapter()`, which performs client-side Google Translate requests only after explicit user consent and automatically falls back to local offline lexicons if offline or blocked:
|
|
145
145
|
|
|
146
146
|
```typescript
|
|
147
|
-
import {
|
|
147
|
+
import {
|
|
148
|
+
createGoogleTranslateAdapter,
|
|
149
|
+
createOfflineMockTranslationAdapter,
|
|
150
|
+
} from "accessibility-plugin-react";
|
|
151
|
+
|
|
152
|
+
const googleAdapter = createGoogleTranslateAdapter({
|
|
153
|
+
fallbackToOffline: true,
|
|
154
|
+
});
|
|
148
155
|
|
|
149
|
-
|
|
156
|
+
// Zero-network alternative for air-gapped development and testing:
|
|
157
|
+
const offlineAdapter = createOfflineMockTranslationAdapter({
|
|
150
158
|
prefix: "[ES]",
|
|
151
159
|
supportedLanguages: ["es", "fr", "de", "si", "ta"],
|
|
152
160
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "accessibility-plugin-react",
|
|
3
|
-
"version": "2.30.
|
|
3
|
+
"version": "2.30.1",
|
|
4
4
|
"description": "A composable React display-preference widget with a clean light design, persistent settings and movable accessible controls.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|