prunelle 0.6.0 → 0.7.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 +21 -0
- package/llms.txt +48 -43
- package/package.json +4 -1
- package/src/a11y/declaration.ts +106 -72
- package/src/a11y/index.ts +59 -39
- package/src/a11y/rgaa-map.ts +95 -49
- package/src/build/bundle.ts +8 -4
- package/src/build/byte-size.ts +11 -0
- package/src/build/client-plugin.ts +3 -1
- package/src/build/compile.ts +2 -1
- package/src/build/ecoindex.ts +25 -16
- package/src/build/files.ts +6 -0
- package/src/build/first-load.ts +83 -11
- package/src/build/graph.ts +29 -39
- package/src/build/index.ts +61 -18
- package/src/build/island-promote.ts +250 -0
- package/src/build/islands.ts +12 -201
- package/src/build/manifest.ts +4 -125
- package/src/build/plugin-host.ts +21 -8
- package/src/build/precompress.ts +1 -1
- package/src/build/prerender.ts +97 -44
- package/src/build/reach.ts +136 -0
- package/src/build/render-rules.ts +2 -2
- package/src/build/report.ts +25 -3
- package/src/build/static-headers.ts +93 -0
- package/src/build/static.ts +2 -0
- package/src/cli/check-forms.ts +97 -48
- package/src/cli/check-imports.ts +25 -0
- package/src/cli/check-links.ts +2 -2
- package/src/cli/check-security.ts +64 -0
- package/src/cli/check.ts +37 -7
- package/src/cli/commands.ts +35 -7
- package/src/cli/docs.ts +4 -3
- package/src/cli/inspect.ts +2 -1
- package/src/cli/mcp-tools.ts +7 -5
- package/src/cli/mcp.ts +1 -1
- package/src/cli/new.ts +14 -3
- package/src/cli/render.ts +14 -19
- package/src/cli/upgrade.ts +22 -5
- package/src/compiler/analyze.ts +27 -5
- package/src/compiler/cacheability.ts +2 -2
- package/src/compiler/compliance-eco.ts +71 -0
- package/src/compiler/compliance-rgaa.ts +110 -4
- package/src/compiler/compliance-urls.ts +146 -0
- package/src/compiler/compliance.ts +168 -116
- package/src/compiler/foreign-imports.ts +88 -0
- package/src/compiler/mistakes.ts +19 -1
- package/src/compiler/props-body.ts +60 -0
- package/src/compiler/shared.ts +2 -2
- package/src/compiler/ssr.ts +2 -2
- package/src/context.ts +34 -0
- package/src/dev/error-log.ts +90 -64
- package/src/dev/host-check.ts +32 -0
- package/src/dev/index.ts +17 -7
- package/src/dev/open-editor.ts +36 -12
- package/src/dev/protocol.ts +2 -0
- package/src/dev/supervisor.ts +8 -0
- package/src/dev/watchers.ts +27 -2
- package/src/dom/action.ts +4 -1
- package/src/dom/extras.ts +1 -2
- package/src/dom/index.ts +28 -6
- package/src/dom/island.ts +22 -10
- package/src/dom/loop.ts +60 -27
- package/src/eco/declaration.ts +257 -0
- package/src/eco/index.ts +65 -0
- package/src/index.ts +2 -2
- package/src/jsx-runtime.ts +2 -2
- package/src/plugins/config.ts +1 -1
- package/src/plugins/context.ts +44 -1
- package/src/plugins/load.ts +4 -3
- package/src/plugins/public.ts +2 -2
- package/src/plugins/services.ts +3 -0
- package/src/plugins/types.ts +17 -2
- package/src/server/action-flash.ts +158 -0
- package/src/server/action-protect.ts +38 -37
- package/src/server/action.ts +11 -127
- package/src/server/app-secret.ts +63 -0
- package/src/server/compress.ts +5 -1
- package/src/server/consent.ts +59 -22
- package/src/server/cookies.ts +16 -2
- package/src/server/env.ts +14 -0
- package/src/server/errors.ts +3 -1
- package/src/server/form-schema.ts +1 -1
- package/src/server/health.ts +46 -15
- package/src/server/http.ts +56 -8
- package/src/server/index.ts +59 -30
- package/src/server/loader.ts +10 -2
- package/src/server/plugin-host.ts +3 -1
- package/src/server/public.ts +4 -3
- package/src/server/rate-limit.ts +52 -9
- package/src/server/route-cache.ts +26 -4
- package/src/server/route-table.ts +7 -3
- package/src/server/routing.ts +3 -87
- package/src/server/sanitize-html.ts +309 -0
- package/src/server/security.ts +73 -22
- package/src/server/serve-handlers.ts +14 -4
- package/src/server/start.ts +1 -1
- package/src/server/static-dir.ts +31 -5
- package/src/server/stream.ts +28 -6
- package/src/ssr/consent-banner.ts +58 -0
- package/src/ssr/context.ts +20 -4
- package/src/ssr/index.ts +18 -0
- package/src/ssr/navigation.ts +2 -2
- package/src/style.ts +64 -1
- package/templates/_shared/gitignore +5 -0
- package/templates/_shared/src/routes/legal.tsx +10 -1
- package/templates/app/.env.example +4 -0
- package/templates/app/package.json +2 -1
- package/templates/app/prunelle.config.ts +2 -0
- package/templates/app/src/auth.ts +4 -6
- package/templates/app/src/mail.ts +4 -0
- package/templates/app/src/routes/_layout.tsx +9 -1
- package/templates/app/src/routes/dashboard/index.tsx +42 -8
- package/templates/app/src/routes/login.tsx +49 -30
- package/templates/app/src/routes/privacy.tsx +25 -0
- package/templates/app/src/styles/app.css +8 -1
- package/templates/app/tests/app.test.ts +44 -3
- package/templates/blog/package.json +1 -1
- package/templates/blog/src/routes/_layout.tsx +6 -1
- package/templates/blog/src/routes/index.tsx +1 -1
- package/templates/blog/src/styles/app.css +6 -1
- package/templates/fullstack/package.json +1 -1
- package/templates/fullstack/src/components/GreetForm.tsx +2 -1
- package/templates/fullstack/src/routes/_layout.tsx +4 -0
- package/templates/fullstack/src/styles/app.css +11 -1
- package/templates/minimal/package.json +1 -1
- package/templates/minimal/src/routes/_layout.tsx +4 -0
- package/templates/minimal/src/styles/app.css +11 -1
package/src/a11y/declaration.ts
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
// Generates an editable French RGAA 4.1.2 accessibility declaration page (Décret n° 2019-768).
|
|
2
2
|
|
|
3
3
|
import type { A11yAuditReport } from './index'
|
|
4
|
-
import { mkdirSync, writeFileSync } from 'node:fs'
|
|
5
|
-
import { dirname, resolve } from 'node:path'
|
|
4
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
|
|
5
|
+
import { dirname, join, resolve } from 'node:path'
|
|
6
6
|
import { relPosix } from '../build/files'
|
|
7
7
|
|
|
8
8
|
export type ComplianceStatus = 'full' | 'partial' | 'none'
|
|
9
9
|
|
|
10
|
+
/** The manual RGAA audit a statement reports: the day it ended and the share of applicable criteria met. */
|
|
11
|
+
export interface ManualAudit {
|
|
12
|
+
date: Date
|
|
13
|
+
/** Applicable RGAA criteria met, in percent (0 to 100). */
|
|
14
|
+
rate: number
|
|
15
|
+
}
|
|
16
|
+
|
|
10
17
|
export interface AccessibilityDeclarationOptions {
|
|
11
18
|
/** Application root directory. */
|
|
12
19
|
root: string
|
|
@@ -20,9 +27,9 @@ export interface AccessibilityDeclarationOptions {
|
|
|
20
27
|
siteUrl?: string | undefined
|
|
21
28
|
/** Contact email for accessibility feedback (editable placeholder by default). */
|
|
22
29
|
contactEmail?: string | undefined
|
|
23
|
-
/**
|
|
24
|
-
|
|
25
|
-
/**
|
|
30
|
+
/** The manual RGAA audit behind the compliance level; without one the statement says "non conforme". */
|
|
31
|
+
audit?: ManualAudit | undefined
|
|
32
|
+
/** Day the statement is drawn up (defaults to today). */
|
|
26
33
|
date?: Date | undefined
|
|
27
34
|
/** Write the generated TSX page to disk (default: `true`). */
|
|
28
35
|
write?: boolean | undefined
|
|
@@ -40,6 +47,8 @@ export interface AccessibilityDeclarationResult {
|
|
|
40
47
|
}
|
|
41
48
|
|
|
42
49
|
export const DEFAULT_DECLARATION_PATH = 'src/routes/accessibilite.tsx'
|
|
50
|
+
/** Marks a fact a drafted statement still lacks: `prunelle check` warns while a published statement holds one. */
|
|
51
|
+
export const STATEMENT_PLACEHOLDER = '[à compléter'
|
|
43
52
|
|
|
44
53
|
const STATUS_LABELS: Readonly<Record<ComplianceStatus, string>> = {
|
|
45
54
|
full: 'totalement conforme',
|
|
@@ -47,19 +56,20 @@ const STATUS_LABELS: Readonly<Record<ComplianceStatus, string>> = {
|
|
|
47
56
|
none: 'non conforme',
|
|
48
57
|
}
|
|
49
58
|
|
|
50
|
-
/**
|
|
51
|
-
export function inferComplianceStatus(
|
|
52
|
-
|
|
53
|
-
override?: ComplianceStatus | undefined,
|
|
54
|
-
): ComplianceStatus {
|
|
55
|
-
if (override !== undefined)
|
|
56
|
-
return override
|
|
57
|
-
if (report === undefined)
|
|
59
|
+
/** The RGAA compliance level a manual audit supports: all criteria met, at least half, or less, or no audit at all. Automated checks never raise it. */
|
|
60
|
+
export function inferComplianceStatus(audit: ManualAudit | undefined): ComplianceStatus {
|
|
61
|
+
if (audit === undefined)
|
|
58
62
|
return 'none'
|
|
59
|
-
|
|
63
|
+
if (Number.isNaN(audit.date.getTime()))
|
|
64
|
+
throw new Error('prunelle: the manual audit date is not a valid date: pass the day the audit ended, such as 2026-03-31.')
|
|
65
|
+
if (!(audit.rate >= 0 && audit.rate <= 100))
|
|
66
|
+
throw new Error(`prunelle: the manual audit rate must be a percentage from 0 to 100, got ${audit.rate}.`)
|
|
67
|
+
if (audit.rate === 100)
|
|
68
|
+
return 'full'
|
|
69
|
+
return audit.rate >= 50 ? 'partial' : 'none'
|
|
60
70
|
}
|
|
61
71
|
|
|
62
|
-
function escapeJsxText(value: string): string {
|
|
72
|
+
export function escapeJsxText(value: string): string {
|
|
63
73
|
return value
|
|
64
74
|
.replaceAll('&', '&')
|
|
65
75
|
.replaceAll('<', '<')
|
|
@@ -68,7 +78,7 @@ function escapeJsxText(value: string): string {
|
|
|
68
78
|
.replaceAll('}', '}')
|
|
69
79
|
}
|
|
70
80
|
|
|
71
|
-
function escapeAttr(value: string): string {
|
|
81
|
+
export function escapeAttr(value: string): string {
|
|
72
82
|
return value
|
|
73
83
|
.replaceAll('&', '&')
|
|
74
84
|
.replaceAll('"', '"')
|
|
@@ -76,7 +86,7 @@ function escapeAttr(value: string): string {
|
|
|
76
86
|
.replaceAll('>', '>')
|
|
77
87
|
}
|
|
78
88
|
|
|
79
|
-
function formatFrenchDate(date: Date): { iso: string, human: string } {
|
|
89
|
+
export function formatFrenchDate(date: Date): { iso: string, human: string } {
|
|
80
90
|
const iso = date.toISOString().slice(0, 10)
|
|
81
91
|
const human = new Intl.DateTimeFormat('fr-FR', {
|
|
82
92
|
day: 'numeric',
|
|
@@ -88,13 +98,14 @@ function formatFrenchDate(date: Date): { iso: string, human: string } {
|
|
|
88
98
|
}
|
|
89
99
|
|
|
90
100
|
function renderNonConformities(report: A11yAuditReport | undefined): string {
|
|
101
|
+
if (report === undefined)
|
|
102
|
+
return ' <p>Aucun audit n\'a encore été réalisé : les non-conformités ne sont pas encore connues.</p>'
|
|
91
103
|
const routesWithIssues = report?.routes.filter(r => r.violations.length > 0) ?? []
|
|
92
104
|
if (routesWithIssues.length === 0) {
|
|
93
105
|
return [
|
|
94
106
|
' <p>',
|
|
95
107
|
' {/* TODO: compléter avec les non-conformités relevées lors de l\'audit manuel RGAA 4.1.2 */}',
|
|
96
108
|
' Aucune non-conformité n\'a été détectée par l\'audit automatisé axe-core.',
|
|
97
|
-
' Les résultats d\'un audit manuel RGAA 4.1.2 complet doivent être renseignés ci-dessous.',
|
|
98
109
|
' </p>',
|
|
99
110
|
].join('\n')
|
|
100
111
|
}
|
|
@@ -124,7 +135,7 @@ function renderAuditedRoutes(report: A11yAuditReport | undefined): string {
|
|
|
124
135
|
if (routes.length === 0) {
|
|
125
136
|
return [
|
|
126
137
|
' <ul>',
|
|
127
|
-
|
|
138
|
+
` <li>${STATEMENT_PLACEHOLDER} : pages de l'échantillon audité]</li>`,
|
|
128
139
|
' </ul>',
|
|
129
140
|
].join('\n')
|
|
130
141
|
}
|
|
@@ -141,56 +152,88 @@ function renderAuditedRoutes(report: A11yAuditReport | undefined): string {
|
|
|
141
152
|
].join('\n')
|
|
142
153
|
}
|
|
143
154
|
|
|
144
|
-
function
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
155
|
+
function automatedResultParagraph(report: A11yAuditReport | undefined, axeLabel: string): string {
|
|
156
|
+
if (report === undefined)
|
|
157
|
+
return ' <p>Aucun audit automatisé n\'a encore été réalisé.</p>'
|
|
158
|
+
const routeCount = report.routes.length
|
|
159
|
+
const violationCount = report.totalViolations
|
|
160
|
+
return [
|
|
161
|
+
' <p>',
|
|
162
|
+
` L'audit automatisé réalisé via <code>prunelle a11y</code> (${escapeJsxText(axeLabel)}, règles RGAA 4 d'axe-core et WCAG 2.1`,
|
|
163
|
+
` niveaux A et AA) a porté sur <strong>${routeCount}</strong> page${routeCount === 1 ? '' : 's'} et a relevé{' '}`,
|
|
164
|
+
` <strong>${violationCount}</strong> violation${violationCount === 1 ? '' : 's'} automatisée${violationCount === 1 ? '' : 's'}.`,
|
|
165
|
+
' </p>',
|
|
166
|
+
].join('\n')
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function testEnvironmentItems(report: A11yAuditReport | undefined, axeLabel: string): string {
|
|
170
|
+
if (report === undefined)
|
|
171
|
+
return ` <li>${STATEMENT_PLACEHOLDER} : navigateurs et technologies d'assistance de l'audit]</li>`
|
|
172
|
+
return [
|
|
173
|
+
' <li>Navigateur : Chromium (headless via Playwright)</li>',
|
|
174
|
+
` <li>Moteur d'analyse : ${escapeJsxText(axeLabel)}</li>`,
|
|
175
|
+
' {/* TODO: ajouter les combinaisons navigateur et lecteur d\'écran de l\'audit manuel (ex. Firefox + NVDA, Safari + VoiceOver) */}',
|
|
176
|
+
].join('\n')
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function buildStatusParagraph(status: ComplianceStatus, siteUrl: string, audit: ManualAudit | undefined): string {
|
|
180
|
+
const reason = audit === undefined
|
|
181
|
+
? ' en l\'absence d\'audit de conformité RGAA 4.1.2'
|
|
182
|
+
: status === 'full' ? '' : ' en raison des non-conformités listées ci-dessous'
|
|
169
183
|
return [
|
|
170
|
-
` {/* TODO: corriger les non-conformités listées puis réaliser un audit manuel RGAA 4.1.2. */}`,
|
|
171
184
|
` <p>`,
|
|
172
|
-
` <strong>${
|
|
185
|
+
` <strong>${escapeJsxText(siteUrl)}</strong> est <strong>${STATUS_LABELS[status]}</strong> avec le référentiel général d'amélioration de l'accessibilité (RGAA), version 4.1.2${escapeJsxText(reason)}.`,
|
|
173
186
|
` </p>`,
|
|
174
187
|
].join('\n')
|
|
175
188
|
}
|
|
176
189
|
|
|
190
|
+
function manualAuditParagraph(audit: ManualAudit | undefined, automated: boolean): string {
|
|
191
|
+
if (audit === undefined && !automated)
|
|
192
|
+
return ' <p>Aucun audit de conformité manuel RGAA 4.1.2 n\'a encore été réalisé.</p>'
|
|
193
|
+
if (audit === undefined)
|
|
194
|
+
return ' <p>Aucun audit de conformité manuel RGAA 4.1.2 n\'a encore été réalisé : seules les vérifications automatisées ci-dessus ont été menées.</p>'
|
|
195
|
+
const { iso, human } = formatFrenchDate(audit.date)
|
|
196
|
+
const rate = new Intl.NumberFormat('fr-FR', { maximumFractionDigits: 1 }).format(audit.rate)
|
|
197
|
+
return [
|
|
198
|
+
` <p>`,
|
|
199
|
+
` L'audit de conformité manuel RGAA 4.1.2, achevé le <time dateTime="${escapeAttr(iso)}">${escapeJsxText(human)}</time>, révèle que <strong>${rate} %</strong> des critères du RGAA version 4.1.2 sont respectés.`,
|
|
200
|
+
` </p>`,
|
|
201
|
+
].join('\n')
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function contactLine(contactEmail: string | undefined): string {
|
|
205
|
+
if (contactEmail === undefined)
|
|
206
|
+
return ` <li>Envoyer un courriel : ${STATEMENT_PLACEHOLDER} : adresse de contact accessibilité]</li>`
|
|
207
|
+
return ` <li>Envoyer un courriel : <a href="mailto:${escapeAttr(contactEmail)}">${escapeJsxText(contactEmail)}</a></li>`
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// The layouts above the page, nearest first, up to the app root: one already rendering <main> holds the statement, which must not open a second.
|
|
211
|
+
export function layoutRendersMain(root: string, dest: string): boolean {
|
|
212
|
+
for (let dir = dirname(dest); dir.startsWith(root); dir = dirname(dir)) {
|
|
213
|
+
const layout = join(dir, '_layout.tsx')
|
|
214
|
+
if (existsSync(layout) && /<main[\s>]/.test(readFileSync(layout, 'utf8')))
|
|
215
|
+
return true
|
|
216
|
+
if (dir === root)
|
|
217
|
+
break
|
|
218
|
+
}
|
|
219
|
+
return false
|
|
220
|
+
}
|
|
221
|
+
|
|
177
222
|
/** Generates (and optionally writes) a draft French RGAA 4.1.2 accessibility declaration page in TSX. */
|
|
178
223
|
export function draftAccessibilityStatement(options: AccessibilityDeclarationOptions): AccessibilityDeclarationResult {
|
|
179
224
|
const root = resolve(options.root)
|
|
180
225
|
const dest = resolve(root, options.outPath ?? DEFAULT_DECLARATION_PATH)
|
|
181
226
|
const relativePath = relPosix(root, dest)
|
|
182
|
-
const status = inferComplianceStatus(options.
|
|
183
|
-
const org = options.organization?.trim() ||
|
|
184
|
-
const siteUrl = options.siteUrl?.trim() ||
|
|
185
|
-
const contactEmail = options.contactEmail?.trim() || 'accessibilite@exemple.fr'
|
|
227
|
+
const status = inferComplianceStatus(options.audit)
|
|
228
|
+
const org = options.organization?.trim() || `${STATEMENT_PLACEHOLDER} : nom de l'organisme]`
|
|
229
|
+
const siteUrl = options.siteUrl?.trim() || `${STATEMENT_PLACEHOLDER} : adresse du site]`
|
|
186
230
|
const { iso, human } = formatFrenchDate(options.date ?? new Date())
|
|
187
231
|
const axeLabel = options.report?.axeVersion ? `axe-core ${options.report.axeVersion}` : 'axe-core'
|
|
188
|
-
const
|
|
189
|
-
const violationCount = options.report?.totalViolations ?? 0
|
|
232
|
+
const wrapper = layoutRendersMain(root, dest) ? 'article' : 'main'
|
|
190
233
|
|
|
191
234
|
const content = `// Brouillon de déclaration d'accessibilité RGAA 4.1.2 (Décret n° 2019-768) généré par \`prunelle a11y --draft\`.
|
|
192
|
-
//
|
|
193
|
-
//
|
|
235
|
+
// Les vérifications automatisées axe-core ne couvrent qu'une partie des 106 critères du RGAA 4.1.2 : le niveau de conformité vient de l'audit manuel (\`--audit-date\` et \`--rate\`).
|
|
236
|
+
// Remplacez chaque mention entre crochets avant publication : \`prunelle check\` signale celles qui restent.
|
|
194
237
|
|
|
195
238
|
import { Head } from 'prunelle'
|
|
196
239
|
|
|
@@ -202,7 +245,7 @@ export default function Accessibilite() {
|
|
|
202
245
|
<Head>
|
|
203
246
|
<title>Déclaration d'accessibilité</title>
|
|
204
247
|
</Head>
|
|
205
|
-
|
|
248
|
+
<${wrapper} lang="fr">
|
|
206
249
|
<h1>Déclaration d'accessibilité</h1>
|
|
207
250
|
<p>
|
|
208
251
|
<strong>${escapeJsxText(org)}</strong> s'engage à rendre ses sites internet, intranet, extranet et ses progiciels
|
|
@@ -215,20 +258,13 @@ export default function Accessibilite() {
|
|
|
215
258
|
|
|
216
259
|
<section>
|
|
217
260
|
<h2>État de conformité</h2>
|
|
218
|
-
${buildStatusParagraph(status, siteUrl, options.
|
|
261
|
+
${buildStatusParagraph(status, siteUrl, options.audit)}
|
|
219
262
|
</section>
|
|
220
263
|
|
|
221
264
|
<section>
|
|
222
265
|
<h2>Résultats des tests</h2>
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
mappées au RGAA 4.1) a porté sur <strong>${routeCount}</strong> page${routeCount === 1 ? '' : 's'} et a relevé{' '}
|
|
226
|
-
<strong>${violationCount}</strong> violation${violationCount === 1 ? '' : 's'} automatisée${violationCount === 1 ? '' : 's'}.
|
|
227
|
-
</p>
|
|
228
|
-
<p>
|
|
229
|
-
{/* TODO: remplacer par le taux de conformité issu de votre audit manuel RGAA 4.1.2 */}
|
|
230
|
-
L'audit de conformité manuel RGAA 4.1.2 révèle que <strong>[XX %]</strong> des critères du RGAA version 4.1.2 sont respectés.
|
|
231
|
-
</p>
|
|
266
|
+
${automatedResultParagraph(options.report, axeLabel)}
|
|
267
|
+
${manualAuditParagraph(options.audit, options.report !== undefined)}
|
|
232
268
|
</section>
|
|
233
269
|
|
|
234
270
|
<section>
|
|
@@ -266,12 +302,10 @@ ${renderNonConformities(options.report)}
|
|
|
266
302
|
|
|
267
303
|
<h3>Environnement de test</h3>
|
|
268
304
|
<p>
|
|
269
|
-
Les vérifications
|
|
305
|
+
Les vérifications de restitution de contenus ont été réalisées dans l'environnement suivant :
|
|
270
306
|
</p>
|
|
271
307
|
<ul>
|
|
272
|
-
|
|
273
|
-
<li>Moteur d'analyse : ${escapeJsxText(axeLabel)}</li>
|
|
274
|
-
<li>{/* TODO: ajouter les combinaisons navigateur + lecteur d'écran testées manuellement (ex. Firefox + NVDA, Safari + VoiceOver) */}Lecteurs d'écran (audit manuel) : [À compléter]</li>
|
|
308
|
+
${testEnvironmentItems(options.report, axeLabel)}
|
|
275
309
|
</ul>
|
|
276
310
|
|
|
277
311
|
<h3>Outils pour évaluer l'accessibilité</h3>
|
|
@@ -291,8 +325,8 @@ ${renderAuditedRoutes(options.report)}
|
|
|
291
325
|
<strong>${escapeJsxText(siteUrl)}</strong> pour être orienté vers une alternative accessible ou obtenir le contenu sous une autre forme.
|
|
292
326
|
</p>
|
|
293
327
|
<ul>
|
|
294
|
-
|
|
295
|
-
|
|
328
|
+
${contactLine(options.contactEmail?.trim() || undefined)}
|
|
329
|
+
{/* TODO: ajouter si besoin l'adresse postale ou le lien du formulaire de contact */}
|
|
296
330
|
</ul>
|
|
297
331
|
</section>
|
|
298
332
|
|
|
@@ -315,7 +349,7 @@ ${renderAuditedRoutes(options.report)}
|
|
|
315
349
|
</li>
|
|
316
350
|
</ul>
|
|
317
351
|
</section>
|
|
318
|
-
|
|
352
|
+
</${wrapper}>
|
|
319
353
|
</>
|
|
320
354
|
)
|
|
321
355
|
}
|
package/src/a11y/index.ts
CHANGED
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
import type { RouteManifestEntry } from '../build/manifest'
|
|
4
4
|
import type { PrunellePlugin } from '../plugins/types'
|
|
5
5
|
import type { BrowserTest, BrowserTestOptions } from '../test/browser'
|
|
6
|
-
import type { ComplianceStatus } from './declaration'
|
|
7
6
|
import type { RgaaCriterion } from './rgaa-map'
|
|
8
7
|
import { resolve } from 'node:path'
|
|
9
8
|
import { definePlugin } from '../plugins/config'
|
|
9
|
+
import { loadConfig } from '../plugins/load'
|
|
10
10
|
import { DEFAULT_DECLARATION_PATH, draftAccessibilityStatement } from './declaration'
|
|
11
11
|
import { rgaaCriteriaForAxeRule } from './rgaa-map'
|
|
12
12
|
|
|
13
13
|
export { DEFAULT_DECLARATION_PATH, draftAccessibilityStatement, inferComplianceStatus } from './declaration'
|
|
14
|
-
export type { AccessibilityDeclarationOptions, AccessibilityDeclarationResult, ComplianceStatus } from './declaration'
|
|
14
|
+
export type { AccessibilityDeclarationOptions, AccessibilityDeclarationResult, ComplianceStatus, ManualAudit } from './declaration'
|
|
15
15
|
export { AXE_TO_RGAA, RGAA_CRITERIA, rgaaCriteriaForAxeRule } from './rgaa-map'
|
|
16
16
|
export type { RgaaCriterion } from './rgaa-map'
|
|
17
17
|
|
|
@@ -40,6 +40,8 @@ export interface A11yRouteReport {
|
|
|
40
40
|
violations: A11yViolation[]
|
|
41
41
|
passes: number
|
|
42
42
|
incomplete: number
|
|
43
|
+
/** What axe could not decide (axe's `incomplete`), to check by hand: same shape as a violation. */
|
|
44
|
+
toCheck: A11yViolation[]
|
|
43
45
|
pageErrors: string[]
|
|
44
46
|
}
|
|
45
47
|
|
|
@@ -61,7 +63,7 @@ export interface A11yAuditOptions {
|
|
|
61
63
|
routes?: readonly string[] | undefined
|
|
62
64
|
/** Include static non-dynamic HTML routes even when prerendered routes exist. */
|
|
63
65
|
includeAllStatic?: boolean | undefined
|
|
64
|
-
/** Axe
|
|
66
|
+
/** Axe tags to evaluate (default: `['RGAAv4', 'wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa']`, axe's RGAA rules plus WCAG 2.1 A and AA). */
|
|
65
67
|
tags?: readonly string[] | undefined
|
|
66
68
|
/** Chrome or Chromium executable path (forwarded to `testBrowser`). */
|
|
67
69
|
browserPath?: string | undefined
|
|
@@ -80,7 +82,7 @@ export interface A11yPluginOptions {
|
|
|
80
82
|
routes?: readonly string[] | undefined
|
|
81
83
|
/** Include static non-dynamic HTML routes alongside prerendered routes (default: `false`). */
|
|
82
84
|
includeAllStatic?: boolean | undefined
|
|
83
|
-
/** Axe
|
|
85
|
+
/** Axe tags to evaluate (default: `['RGAAv4', 'wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa']`, axe's RGAA rules plus WCAG 2.1 A and AA). */
|
|
84
86
|
tags?: readonly string[] | undefined
|
|
85
87
|
/** Default destination path for `prunelle a11y --draft` (default: `'src/routes/accessibilite.tsx'`). */
|
|
86
88
|
declarationPath?: string | undefined
|
|
@@ -94,11 +96,10 @@ export interface A11yPluginOptions {
|
|
|
94
96
|
timeout?: number | undefined
|
|
95
97
|
}
|
|
96
98
|
|
|
97
|
-
export const DEFAULT_AXE_TAGS: readonly string[] = ['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa']
|
|
99
|
+
export const DEFAULT_AXE_TAGS: readonly string[] = ['RGAAv4', 'wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa']
|
|
98
100
|
|
|
99
101
|
const AXE_SPECIFIER = 'axe-core'
|
|
100
102
|
const CLI_KIT_SPECIFIER = '@kaynooo/cli-kit'
|
|
101
|
-
const COMPLIANCE_STATUSES = ['full', 'partial', 'none'] as const
|
|
102
103
|
|
|
103
104
|
interface LoadedAxe {
|
|
104
105
|
source: string
|
|
@@ -124,7 +125,7 @@ interface RawAxeViolation {
|
|
|
124
125
|
interface RawAxeRunResult {
|
|
125
126
|
violations: RawAxeViolation[]
|
|
126
127
|
passes: number
|
|
127
|
-
incomplete:
|
|
128
|
+
incomplete: RawAxeViolation[]
|
|
128
129
|
}
|
|
129
130
|
|
|
130
131
|
interface TestBrowserModule {
|
|
@@ -227,7 +228,7 @@ function mapAxeViolations(rawViolations: readonly RawAxeViolation[]): A11yViolat
|
|
|
227
228
|
help: v.help,
|
|
228
229
|
helpUrl: v.helpUrl,
|
|
229
230
|
tags: Array.isArray(v.tags) ? v.tags.map(String) : [],
|
|
230
|
-
rgaa: rgaaCriteriaForAxeRule(v.id),
|
|
231
|
+
rgaa: rgaaCriteriaForAxeRule(v.id, Array.isArray(v.tags) ? v.tags : []),
|
|
231
232
|
nodes: (Array.isArray(v.nodes) ? v.nodes : []).map(n => ({
|
|
232
233
|
target: Array.isArray(n.target) ? n.target.map(String) : [],
|
|
233
234
|
html: typeof n.html === 'string' ? n.html : '',
|
|
@@ -243,22 +244,23 @@ async function auditRoute(browser: BrowserTest, route: string, axeSource: string
|
|
|
243
244
|
const runExpr = `(() => {
|
|
244
245
|
if (!window.axe || typeof window.axe.run !== 'function')
|
|
245
246
|
throw new Error('axe-core failed to initialize in page');
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
failureSummary: n.failureSummary || undefined,
|
|
258
|
-
})),
|
|
247
|
+
const toPlain = (v) => ({
|
|
248
|
+
id: v.id,
|
|
249
|
+
impact: v.impact || 'moderate',
|
|
250
|
+
description: v.description,
|
|
251
|
+
help: v.help,
|
|
252
|
+
helpUrl: v.helpUrl,
|
|
253
|
+
tags: v.tags,
|
|
254
|
+
nodes: v.nodes.map((n) => ({
|
|
255
|
+
target: Array.isArray(n.target) ? n.target.map(String) : [],
|
|
256
|
+
html: n.html || '',
|
|
257
|
+
failureSummary: n.failureSummary || undefined,
|
|
259
258
|
})),
|
|
259
|
+
});
|
|
260
|
+
return window.axe.run(document, ${JSON.stringify({ runOnly: { type: 'tag', values: tags } })}).then((res) => ({
|
|
261
|
+
violations: res.violations.map(toPlain),
|
|
260
262
|
passes: res.passes.length,
|
|
261
|
-
incomplete: res.incomplete.
|
|
263
|
+
incomplete: res.incomplete.map(toPlain),
|
|
262
264
|
}));
|
|
263
265
|
})()`
|
|
264
266
|
const raw = await page.evaluate<RawAxeRunResult>(runExpr)
|
|
@@ -267,7 +269,8 @@ async function auditRoute(browser: BrowserTest, route: string, axeSource: string
|
|
|
267
269
|
url: page.url,
|
|
268
270
|
violations: mapAxeViolations(raw.violations),
|
|
269
271
|
passes: raw.passes,
|
|
270
|
-
incomplete: raw.incomplete,
|
|
272
|
+
incomplete: raw.incomplete.length,
|
|
273
|
+
toCheck: mapAxeViolations(raw.incomplete),
|
|
271
274
|
pageErrors: [...page.errors],
|
|
272
275
|
}
|
|
273
276
|
}
|
|
@@ -333,25 +336,31 @@ export function formatA11yReport(report: A11yAuditReport): string {
|
|
|
333
336
|
return lines.join('\n')
|
|
334
337
|
}
|
|
335
338
|
|
|
339
|
+
const rgaaOf = (v: A11yViolation): string => v.rgaa.length > 0 ? ` (RGAA ${v.rgaa.map(c => c.id).join(', ')})` : ''
|
|
340
|
+
const elements = (count: number): string => `${count} ${count === 1 ? 'element' : 'elements'}`
|
|
341
|
+
const details = (v: A11yViolation): void => {
|
|
342
|
+
lines.push(` ${v.help}`)
|
|
343
|
+
const firstSelector = v.nodes[0]?.target.join(' > ')
|
|
344
|
+
if (firstSelector)
|
|
345
|
+
lines.push(` Selector: ${firstSelector}`)
|
|
346
|
+
lines.push(` Help: ${v.helpUrl}`)
|
|
347
|
+
}
|
|
336
348
|
for (const r of report.routes) {
|
|
337
349
|
if (r.violations.length === 0) {
|
|
338
350
|
lines.push(` ✓ ${r.route} (0 violations, ${r.passes} passes)`)
|
|
339
|
-
continue
|
|
340
351
|
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
352
|
+
else {
|
|
353
|
+
const routeNodes = r.violations.reduce((sum, v) => sum + v.nodes.length, 0)
|
|
354
|
+
lines.push(` ✗ ${r.route} (${r.violations.length} ${r.violations.length === 1 ? 'violation' : 'violations'}, ${elements(routeNodes)})`)
|
|
355
|
+
}
|
|
345
356
|
for (const v of r.violations) {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
lines.push(` Selector: ${firstSelector}`)
|
|
354
|
-
lines.push(` Help: ${v.helpUrl}`)
|
|
357
|
+
lines.push(` [${v.impact}] ${v.id}${rgaaOf(v)} — ${elements(v.nodes.length)}`)
|
|
358
|
+
details(v)
|
|
359
|
+
}
|
|
360
|
+
// axe's `incomplete`: it found the elements but cannot tell whether they pass.
|
|
361
|
+
for (const v of r.toCheck) {
|
|
362
|
+
lines.push(` to check by hand: ${v.id}${rgaaOf(v)}, ${elements(v.nodes.length)}`)
|
|
363
|
+
details(v)
|
|
355
364
|
}
|
|
356
365
|
}
|
|
357
366
|
|
|
@@ -373,7 +382,9 @@ async function runA11yCommand(args: string[], root: string, pluginOptions: A11yP
|
|
|
373
382
|
'json': { type: 'boolean', description: 'print the audit report as JSON on stdout' },
|
|
374
383
|
'draft': { type: 'string', optional: { bare: '' }, description: 'write an editable RGAA 4.1.2 accessibility declaration page (default: src/routes/accessibilite.tsx)' },
|
|
375
384
|
'out': { type: 'string', description: 'destination path for --draft (default: src/routes/accessibilite.tsx)' },
|
|
376
|
-
'
|
|
385
|
+
'audit-date': { type: 'string', description: 'day the manual RGAA audit ended (YYYY-MM-DD), written into --draft with --rate' },
|
|
386
|
+
'rate': { type: 'string', description: 'applicable RGAA criteria the manual audit found met, in percent: 100 is totally, 50 or more partially compliant' },
|
|
387
|
+
'status': { type: 'string', description: 'removed: the level now follows --audit-date and --rate' },
|
|
377
388
|
'org': { type: 'string', description: 'organization name written into --draft' },
|
|
378
389
|
'contact': { type: 'string', description: 'contact email written into --draft' },
|
|
379
390
|
'no-fail': { type: 'boolean', description: 'exit 0 even when accessibility violations are found' },
|
|
@@ -392,6 +403,14 @@ async function runA11yCommand(args: string[], root: string, pluginOptions: A11yP
|
|
|
392
403
|
if (values.routes !== undefined && (rawRoutes === undefined || rawRoutes.length === 0))
|
|
393
404
|
return badUsage('--routes requires at least one route path, e.g. --routes /,/about')
|
|
394
405
|
|
|
406
|
+
if (values.status !== undefined)
|
|
407
|
+
return badUsage('--status is gone: the compliance level follows the manual audit, so pass --audit-date YYYY-MM-DD and --rate <percent> (100 is totally, 50 or more partially compliant)')
|
|
408
|
+
if ((values['audit-date'] === undefined) !== (values.rate === undefined))
|
|
409
|
+
return badUsage('--audit-date and --rate go together: pass the day the manual RGAA audit ended and the percentage of criteria it found met')
|
|
410
|
+
const manualAudit = values['audit-date'] !== undefined && values.rate !== undefined
|
|
411
|
+
? { date: new Date(`${values['audit-date']}T00:00:00Z`), rate: Number(values.rate) }
|
|
412
|
+
: undefined
|
|
413
|
+
|
|
395
414
|
const wantDraft = values.draft !== undefined
|
|
396
415
|
const draftDest = values.out
|
|
397
416
|
?? (values.draft !== undefined && values.draft !== '' ? values.draft : undefined)
|
|
@@ -416,7 +435,8 @@ async function runA11yCommand(args: string[], root: string, pluginOptions: A11yP
|
|
|
416
435
|
report,
|
|
417
436
|
organization: values.org ?? pluginOptions.organization,
|
|
418
437
|
contactEmail: values.contact ?? pluginOptions.contactEmail,
|
|
419
|
-
|
|
438
|
+
siteUrl: (await loadConfig(root)).site,
|
|
439
|
+
audit: manualAudit,
|
|
420
440
|
})
|
|
421
441
|
}
|
|
422
442
|
|