prunelle 0.1.1 → 0.6.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.
Files changed (120) hide show
  1. package/llms.txt +130 -38
  2. package/package.json +8 -2
  3. package/src/a11y/declaration.ts +335 -0
  4. package/src/a11y/index.ts +446 -0
  5. package/src/a11y/rgaa-map.ts +184 -0
  6. package/src/attrs.ts +11 -3
  7. package/src/build/bundle.ts +80 -36
  8. package/src/build/client-entries.ts +3 -2
  9. package/src/build/client-plugin.ts +8 -4
  10. package/src/build/client-prune.ts +56 -6
  11. package/src/build/compile.ts +11 -9
  12. package/src/build/ecoindex.ts +229 -0
  13. package/src/build/index.ts +174 -108
  14. package/src/build/islands.ts +2 -2
  15. package/src/build/manifest.ts +66 -5
  16. package/src/build/output.ts +2 -2
  17. package/src/build/plugin-host.ts +92 -33
  18. package/src/build/precompress.ts +15 -2
  19. package/src/build/prerender.ts +128 -46
  20. package/src/build/report.ts +23 -2
  21. package/src/build/resolve.ts +8 -6
  22. package/src/build/routes.ts +175 -10
  23. package/src/build/static.ts +137 -39
  24. package/src/build/status-pages.ts +127 -0
  25. package/src/build/style-bundles.ts +526 -0
  26. package/src/cli/check-forms.ts +561 -0
  27. package/src/cli/check-links.ts +632 -0
  28. package/src/cli/check.ts +75 -20
  29. package/src/cli/commands.ts +85 -4
  30. package/src/cli/docs.ts +402 -0
  31. package/src/cli/inspect.ts +103 -14
  32. package/src/cli/mcp-tools.ts +490 -0
  33. package/src/cli/mcp.ts +205 -0
  34. package/src/cli/new.ts +2 -2
  35. package/src/cli/render.ts +421 -0
  36. package/src/cli/upgrade-names.ts +73 -13
  37. package/src/cli/upgrade.ts +137 -16
  38. package/src/compiler/analyze.ts +42 -9
  39. package/src/compiler/browser-globals.ts +140 -17
  40. package/src/compiler/cacheability.ts +636 -0
  41. package/src/compiler/compliance-rgaa.ts +508 -0
  42. package/src/compiler/compliance.ts +241 -289
  43. package/src/compiler/data-keys.ts +199 -192
  44. package/src/compiler/dev-source.ts +87 -0
  45. package/src/compiler/dom-attrs.ts +138 -65
  46. package/src/compiler/dom.ts +517 -442
  47. package/src/compiler/expr-context.ts +167 -57
  48. package/src/compiler/mistakes.ts +4 -1
  49. package/src/compiler/props.ts +87 -36
  50. package/src/compiler/scope.ts +400 -333
  51. package/src/compiler/server-only.ts +190 -151
  52. package/src/compiler/shared.ts +40 -12
  53. package/src/compiler/signal-reads.ts +6 -2
  54. package/src/compiler/ssr-prunelle-tags.ts +27 -14
  55. package/src/compiler/ssr.ts +218 -87
  56. package/src/dev/error-log.ts +151 -0
  57. package/src/dev/index.ts +84 -34
  58. package/src/dev/open-editor.ts +204 -0
  59. package/src/dev/protocol.ts +1 -0
  60. package/src/dev/reload.ts +5 -3
  61. package/src/dev/supervisor.ts +42 -25
  62. package/src/dev/watchers.ts +47 -11
  63. package/src/dom/action.ts +43 -20
  64. package/src/dom/attrs.ts +15 -3
  65. package/src/dom/extras.ts +28 -12
  66. package/src/dom/index.ts +26 -8
  67. package/src/dom/island.ts +35 -28
  68. package/src/dom/loop.ts +10 -9
  69. package/src/plugins/config.ts +8 -7
  70. package/src/plugins/index.ts +2 -2
  71. package/src/plugins/load.ts +26 -7
  72. package/src/plugins/order.ts +38 -1
  73. package/src/plugins/public.ts +5 -2
  74. package/src/plugins/services.ts +81 -0
  75. package/src/plugins/types.ts +34 -0
  76. package/src/reactivity/graph.ts +10 -0
  77. package/src/reactivity/index.ts +24 -16
  78. package/src/reactivity/selector.ts +31 -4
  79. package/src/reactivity/store.ts +45 -13
  80. package/src/server/action-protect.ts +198 -0
  81. package/src/server/action-registry.ts +1 -1
  82. package/src/server/action.ts +82 -27
  83. package/src/server/assets.ts +34 -2
  84. package/src/server/compress.ts +91 -9
  85. package/src/server/document.ts +25 -10
  86. package/src/server/errors.ts +303 -65
  87. package/src/server/form-schema.ts +343 -0
  88. package/src/server/health.ts +244 -0
  89. package/src/server/http.ts +131 -32
  90. package/src/server/index.ts +231 -261
  91. package/src/server/loader.ts +5 -0
  92. package/src/server/param-matchers.ts +112 -0
  93. package/src/server/plugin-host.ts +123 -88
  94. package/src/server/public.ts +3 -3
  95. package/src/server/rate-limit.ts +58 -35
  96. package/src/server/request-body.ts +1 -1
  97. package/src/server/route-cache.ts +423 -0
  98. package/src/server/route-table.ts +339 -8
  99. package/src/server/router.ts +125 -40
  100. package/src/server/routing.ts +196 -63
  101. package/src/server/security.ts +208 -32
  102. package/src/server/serve-handlers.ts +21 -7
  103. package/src/server/start.ts +60 -16
  104. package/src/server/static-dir.ts +61 -8
  105. package/src/server/stream.ts +41 -22
  106. package/src/ssr/context.ts +85 -3
  107. package/src/ssr/index.ts +130 -3
  108. package/src/ssr/region.ts +31 -19
  109. package/src/test/browser.ts +28 -13
  110. package/src/test/index.ts +97 -12
  111. package/src/ts-plugin/diagnostics.ts +505 -0
  112. package/src/ts-plugin/fixes.ts +364 -0
  113. package/src/ts-plugin/index.ts +194 -0
  114. package/templates/_shared/AGENTS.md +2 -2
  115. package/templates/_shared/mcp.json +11 -0
  116. package/templates/_shared/src/routes/legal.tsx +5 -0
  117. package/templates/_shared/tsconfig.json +5 -0
  118. package/templates/blog/prunelle.config.ts +1 -1
  119. package/templates/blog/src/routes/index.tsx +4 -0
  120. package/ts-plugin.cjs +4277 -0
@@ -0,0 +1,335 @@
1
+ // Generates an editable French RGAA 4.1.2 accessibility declaration page (Décret n° 2019-768).
2
+
3
+ import type { A11yAuditReport } from './index'
4
+ import { mkdirSync, writeFileSync } from 'node:fs'
5
+ import { dirname, resolve } from 'node:path'
6
+ import { relPosix } from '../build/files'
7
+
8
+ export type ComplianceStatus = 'full' | 'partial' | 'none'
9
+
10
+ export interface AccessibilityDeclarationOptions {
11
+ /** Application root directory. */
12
+ root: string
13
+ /** Destination path relative to `root` (or absolute). Default: `'src/routes/accessibilite.tsx'`. */
14
+ outPath?: string | undefined
15
+ /** Optional audit report from `auditAccessibility()` used to pre-fill test results and non-conformities. */
16
+ report?: A11yAuditReport | undefined
17
+ /** Organization or publisher name (editable placeholder by default). */
18
+ organization?: string | undefined
19
+ /** Public site URL (editable placeholder by default). */
20
+ siteUrl?: string | undefined
21
+ /** Contact email for accessibility feedback (editable placeholder by default). */
22
+ contactEmail?: string | undefined
23
+ /** Explicit compliance level override; inferred from `report` when omitted. */
24
+ status?: ComplianceStatus | undefined
25
+ /** Declaration date (defaults to today). */
26
+ date?: Date | undefined
27
+ /** Write the generated TSX page to disk (default: `true`). */
28
+ write?: boolean | undefined
29
+ }
30
+
31
+ export interface AccessibilityDeclarationResult {
32
+ /** Absolute path of the target declaration file. */
33
+ path: string
34
+ /** Root-relative POSIX path (e.g. `'src/routes/accessibilite.tsx'`). */
35
+ relativePath: string
36
+ /** Compliance status written into the declaration. */
37
+ status: ComplianceStatus
38
+ /** Generated TSX source code. */
39
+ content: string
40
+ }
41
+
42
+ export const DEFAULT_DECLARATION_PATH = 'src/routes/accessibilite.tsx'
43
+
44
+ const STATUS_LABELS: Readonly<Record<ComplianceStatus, string>> = {
45
+ full: 'totalement conforme',
46
+ partial: 'partiellement conforme',
47
+ none: 'non conforme',
48
+ }
49
+
50
+ /** Infers RGAA compliance status from an automated audit report (never claims full compliance without explicit opt-in). */
51
+ export function inferComplianceStatus(
52
+ report: A11yAuditReport | undefined,
53
+ override?: ComplianceStatus | undefined,
54
+ ): ComplianceStatus {
55
+ if (override !== undefined)
56
+ return override
57
+ if (report === undefined)
58
+ return 'none'
59
+ return report.totalViolations === 0 ? 'partial' : 'none'
60
+ }
61
+
62
+ function escapeJsxText(value: string): string {
63
+ return value
64
+ .replaceAll('&', '&amp;')
65
+ .replaceAll('<', '&lt;')
66
+ .replaceAll('>', '&gt;')
67
+ .replaceAll('{', '&#123;')
68
+ .replaceAll('}', '&#125;')
69
+ }
70
+
71
+ function escapeAttr(value: string): string {
72
+ return value
73
+ .replaceAll('&', '&amp;')
74
+ .replaceAll('"', '&quot;')
75
+ .replaceAll('<', '&lt;')
76
+ .replaceAll('>', '&gt;')
77
+ }
78
+
79
+ function formatFrenchDate(date: Date): { iso: string, human: string } {
80
+ const iso = date.toISOString().slice(0, 10)
81
+ const human = new Intl.DateTimeFormat('fr-FR', {
82
+ day: 'numeric',
83
+ month: 'long',
84
+ year: 'numeric',
85
+ timeZone: 'UTC',
86
+ }).format(date)
87
+ return { iso, human }
88
+ }
89
+
90
+ function renderNonConformities(report: A11yAuditReport | undefined): string {
91
+ const routesWithIssues = report?.routes.filter(r => r.violations.length > 0) ?? []
92
+ if (routesWithIssues.length === 0) {
93
+ return [
94
+ ' <p>',
95
+ ' {/* TODO: compléter avec les non-conformités relevées lors de l\'audit manuel RGAA 4.1.2 */}',
96
+ ' 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
+ ' </p>',
99
+ ].join('\n')
100
+ }
101
+
102
+ const items: string[] = []
103
+ for (const route of routesWithIssues) {
104
+ for (const v of route.violations) {
105
+ const rgaaLabel = v.rgaa.length > 0
106
+ ? `RGAA ${v.rgaa.map(c => c.id).join(', ')}`
107
+ : 'WCAG / axe-core'
108
+ const count = v.nodes.length
109
+ const elemWord = count === 1 ? 'élément' : 'éléments'
110
+ const line = `${route.route} — ${rgaaLabel} (${v.id}, impact ${v.impact}, ${count} ${elemWord}) : ${v.help}.`
111
+ items.push(` <li>${escapeJsxText(line)}</li>`)
112
+ }
113
+ }
114
+ return [
115
+ ' <p>Les non-conformités suivantes ont été détectées automatiquement par axe-core :</p>',
116
+ ' <ul>',
117
+ ...items,
118
+ ' </ul>',
119
+ ].join('\n')
120
+ }
121
+
122
+ function renderAuditedRoutes(report: A11yAuditReport | undefined): string {
123
+ const routes = report?.routes ?? []
124
+ if (routes.length === 0) {
125
+ return [
126
+ ' <ul>',
127
+ ' <li><code>/</code> — Page d\'accueil (TODO : lister l\'échantillon complet audité)</li>',
128
+ ' </ul>',
129
+ ].join('\n')
130
+ }
131
+ const items = routes.map((r) => {
132
+ const summary = r.violations.length === 0
133
+ ? '0 violation automatisée'
134
+ : `${r.violations.length} violation${r.violations.length === 1 ? '' : 's'} automatisée${r.violations.length === 1 ? '' : 's'}`
135
+ return ` <li><code>${escapeJsxText(r.route)}</code> (${escapeJsxText(summary)})</li>`
136
+ })
137
+ return [
138
+ ' <ul>',
139
+ ...items,
140
+ ' </ul>',
141
+ ].join('\n')
142
+ }
143
+
144
+ function buildStatusParagraph(status: ComplianceStatus, siteUrl: string, report: A11yAuditReport | undefined): string {
145
+ const statusLabel = STATUS_LABELS[status]
146
+ const safeSite = escapeJsxText(siteUrl)
147
+ if (status === 'full') {
148
+ return [
149
+ ` {/* TODO: ne conserver "totalement conforme" qu'après validation d'un audit manuel RGAA 4.1.2 complet (100 % des critères applicables conformes). */}`,
150
+ ` <p>`,
151
+ ` <strong>${safeSite}</strong> est <strong>${statusLabel}</strong> avec le référentiel général d'amélioration de l'accessibilité (RGAA), version 4.1.2.`,
152
+ ` </p>`,
153
+ ].join('\n')
154
+ }
155
+ if (status === 'partial') {
156
+ const detail = report !== undefined
157
+ ? ` L'audit automatisé axe-core sur ${report.routes.length} page${report.routes.length === 1 ? '' : 's'} n'a relevé aucune violation, mais un audit manuel RGAA 4.1.2 reste nécessaire avant de déclarer une conformité totale.`
158
+ : ' Des non-conformités ou des vérifications manuelles RGAA 4.1.2 restent à compléter ci-dessous.'
159
+ return [
160
+ ` {/* TODO: mettre à jour le niveau de conformité et le taux après réalisation de l'audit manuel RGAA 4.1.2. */}`,
161
+ ` <p>`,
162
+ ` <strong>${safeSite}</strong> est <strong>${statusLabel}</strong> avec le référentiel général d'amélioration de l'accessibilité (RGAA), version 4.1.2.${escapeJsxText(detail)}`,
163
+ ` </p>`,
164
+ ].join('\n')
165
+ }
166
+ const reason = report !== undefined && report.totalViolations > 0
167
+ ? ` en raison des ${report.totalViolations} non-conformité${report.totalViolations === 1 ? '' : 's'} automatisée${report.totalViolations === 1 ? '' : 's'} recensée${report.totalViolations === 1 ? '' : 's'} ci-dessous`
168
+ : ' en l\'absence d\'audit de conformité RGAA 4.1.2 complet'
169
+ return [
170
+ ` {/* TODO: corriger les non-conformités listées puis réaliser un audit manuel RGAA 4.1.2. */}`,
171
+ ` <p>`,
172
+ ` <strong>${safeSite}</strong> est <strong>${statusLabel}</strong> avec le référentiel général d'amélioration de l'accessibilité (RGAA), version 4.1.2${escapeJsxText(reason)}.`,
173
+ ` </p>`,
174
+ ].join('\n')
175
+ }
176
+
177
+ /** Generates (and optionally writes) a draft French RGAA 4.1.2 accessibility declaration page in TSX. */
178
+ export function draftAccessibilityStatement(options: AccessibilityDeclarationOptions): AccessibilityDeclarationResult {
179
+ const root = resolve(options.root)
180
+ const dest = resolve(root, options.outPath ?? DEFAULT_DECLARATION_PATH)
181
+ const relativePath = relPosix(root, dest)
182
+ const status = inferComplianceStatus(options.report, options.status)
183
+ const org = options.organization?.trim() || '[Nom de l\'organisme]'
184
+ const siteUrl = options.siteUrl?.trim() || '[https://exemple.fr]'
185
+ const contactEmail = options.contactEmail?.trim() || 'accessibilite@exemple.fr'
186
+ const { iso, human } = formatFrenchDate(options.date ?? new Date())
187
+ const axeLabel = options.report?.axeVersion ? `axe-core ${options.report.axeVersion}` : 'axe-core'
188
+ const routeCount = options.report?.routes.length ?? 0
189
+ const violationCount = options.report?.totalViolations ?? 0
190
+
191
+ 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
+ // TODO: Les vérifications automatisées axe-core ne couvrent qu'une partie des 106 critères du RGAA 4.1.2.
193
+ // Complétez chaque mention entre crochets ([...]) et renseignez les résultats de votre audit manuel avant publication.
194
+
195
+ import { Head } from 'prunelle'
196
+
197
+ export const prerender = true
198
+
199
+ export default function Accessibilite() {
200
+ return (
201
+ <>
202
+ <Head>
203
+ <title>Déclaration d'accessibilité</title>
204
+ </Head>
205
+ <main>
206
+ <h1>Déclaration d'accessibilité</h1>
207
+ <p>
208
+ <strong>${escapeJsxText(org)}</strong> s'engage à rendre ses sites internet, intranet, extranet et ses progiciels
209
+ accessibles (et ses applications mobiles et mobilier urbain numérique) conformément à l'article 47 de la loi n° 2005-102
210
+ du 11 février 2005.
211
+ </p>
212
+ <p>
213
+ Cette déclaration d'accessibilité s'applique à <strong>${escapeJsxText(siteUrl)}</strong>.
214
+ </p>
215
+
216
+ <section>
217
+ <h2>État de conformité</h2>
218
+ ${buildStatusParagraph(status, siteUrl, options.report)}
219
+ </section>
220
+
221
+ <section>
222
+ <h2>Résultats des tests</h2>
223
+ <p>
224
+ L'audit automatisé réalisé via <code>prunelle a11y</code> (${escapeJsxText(axeLabel)}, règles WCAG 2.0 / 2.1 niveaux A et AA
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>
232
+ </section>
233
+
234
+ <section>
235
+ <h2>Contenus non accessibles</h2>
236
+
237
+ <h3>Non-conformités</h3>
238
+ ${renderNonConformities(options.report)}
239
+
240
+ <h3>Dérogations pour charge disproportionnée</h3>
241
+ <p>
242
+ {/* TODO: lister ici les éventuelles dérogations justifiées */}
243
+ Aucune.
244
+ </p>
245
+
246
+ <h3>Contenus non soumis à l'obligation d'accessibilité</h3>
247
+ <p>
248
+ {/* TODO: lister ici les contenus tiers ou archives hors périmètre */}
249
+ Aucun.
250
+ </p>
251
+ </section>
252
+
253
+ <section>
254
+ <h2>Établissement de cette déclaration d'accessibilité</h2>
255
+ <p>
256
+ Cette déclaration a été établie le <time dateTime="${escapeAttr(iso)}">${escapeJsxText(human)}</time>.
257
+ </p>
258
+
259
+ <h3>Technologies utilisées pour la réalisation du site</h3>
260
+ <ul>
261
+ <li>HTML5</li>
262
+ <li>CSS</li>
263
+ <li>JavaScript</li>
264
+ <li>Prunelle</li>
265
+ </ul>
266
+
267
+ <h3>Environnement de test</h3>
268
+ <p>
269
+ Les vérifications automatisées de restitution de contenus ont été réalisées dans l'environnement suivant :
270
+ </p>
271
+ <ul>
272
+ <li>Navigateur : Chromium (headless via Playwright)</li>
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>
275
+ </ul>
276
+
277
+ <h3>Outils pour évaluer l'accessibilité</h3>
278
+ <ul>
279
+ <li><code>prunelle a11y</code> (${escapeJsxText(axeLabel)})</li>
280
+ <li><code>prunelle check</code> (vérifications statiques RGAA sur le JSX)</li>
281
+ </ul>
282
+
283
+ <h3>Pages du site ayant fait l'objet de la vérification de conformité</h3>
284
+ ${renderAuditedRoutes(options.report)}
285
+ </section>
286
+
287
+ <section>
288
+ <h2>Retour d'information et contact</h2>
289
+ <p>
290
+ Si vous n'arrivez pas à accéder à un contenu ou à un service, vous pouvez contacter le responsable de{' '}
291
+ <strong>${escapeJsxText(siteUrl)}</strong> pour être orienté vers une alternative accessible ou obtenir le contenu sous une autre forme.
292
+ </p>
293
+ <ul>
294
+ <li>Envoyer un courriel : <a href="mailto:${escapeAttr(contactEmail)}">${escapeJsxText(contactEmail)}</a></li>
295
+ <li>Contacter : ${escapeJsxText(org)} — [Adresse postale / lien vers le formulaire de contact]</li>
296
+ </ul>
297
+ </section>
298
+
299
+ <section>
300
+ <h2>Voies de recours</h2>
301
+ <p>
302
+ Cette procédure est à utiliser dans le cas suivant : vous avez signalé au responsable du site internet un défaut
303
+ d'accessibilité qui vous empêche d'accéder à un contenu ou à un des services du portail et vous n'avez pas obtenu
304
+ de réponse satisfaisante.
305
+ </p>
306
+ <ul>
307
+ <li>
308
+ <a href="https://formulaire.defenseurdesdroits.fr/">Écrire un message au Défenseur des droits</a>
309
+ </li>
310
+ <li>
311
+ <a href="https://www.defenseurdesdroits.fr/saisir/delegues">Contacter le délégué du Défenseur des droits dans votre région</a>
312
+ </li>
313
+ <li>
314
+ Envoyer un courrier par la poste (gratuit, ne pas mettre de timbre) : Défenseur des droits, Libre réponse 71120, 75342 Paris CEDEX 07.
315
+ </li>
316
+ </ul>
317
+ </section>
318
+ </main>
319
+ </>
320
+ )
321
+ }
322
+ `
323
+
324
+ if (options.write !== false) {
325
+ mkdirSync(dirname(dest), { recursive: true })
326
+ writeFileSync(dest, content)
327
+ }
328
+
329
+ return {
330
+ path: dest,
331
+ relativePath,
332
+ status,
333
+ content,
334
+ }
335
+ }