Files
nav-carte/scripts/export-roue-echelles.mjs

144 lines
8.2 KiB
JavaScript

#!/usr/bin/env node
/**
* La roue des échelles S / M / XL en un seul fichier HTML, sans dépendance (B26, demande de Jules du 22/10) :
* à ouvrir tel quel, à poser en <iframe>, ou à copier (le bloc <div class="roue"> et sa <style>).
* Même géométrie (utils/figures.ts) et mêmes textes (utils/echelles.ts) que le schéma de /entree
* (components/entree/SchemaEchelles.vue) et que la figure de la page codev (components/evenements/Cercle.vue) :
* regénérer après toute retouche de ces deux fichiers, jamais éditer le HTML produit.
* Clair et sombre (prefers-color-scheme), bouton pause (WCAG 2.2.2), arrêt sous prefers-reduced-motion.
*
* Usage : node scripts/export-roue-echelles.mjs <sortie.html>
*/
import { createJiti } from 'jiti'
import { fileURLToPath } from 'node:url'
import { dirname, join } from 'node:path'
import { writeFileSync } from 'node:fs'
const racine = join(dirname(fileURLToPath(import.meta.url)), '..')
const jiti = createJiti(import.meta.url)
const { ECHELLES, ORDRE_ECHELLES } = await jiti.import(join(racine, 'utils', 'echelles.ts'))
const F = await jiti.import(join(racine, 'utils', 'figures.ts'))
const sortie = process.argv[2]
if (!sortie) { console.error('Usage : node scripts/export-roue-echelles.mjs <sortie.html>'); process.exit(1) }
const esc = (s) => String(s).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;')
const anneaux = F.anneauxEchelles()
const bandeaux = F.bandeauxAnneaux()
// Cadre carré autour de l'anneau XL, trait compris (comme Cercle.vue)
const xl = anneaux[0]
const COTE = 2 * (xl.r + 4)
const X0 = xl.cx - COTE / 2
const Y0 = xl.cy - COTE / 2
const VB = `${X0} ${Y0} ${COTE} ${COTE}`
const pc = (n) => `${+(n * 100).toFixed(3)}%`
const nomAnneau = (id) => { const t = ECHELLES[id].titre; return t.charAt(0).toLowerCase() + t.slice(1) }
const description = `Trois anneaux imbriqués, S au centre : ${ORDRE_ECHELLES.map((id) => `${id}, ${nomAnneau(id)}`).join(' ; ')}. `
+ ORDRE_ECHELLES.map((id) => `${id}, ${nomAnneau(id)} : ${ECHELLES[id].mots.join(' ; ')}.`).join(' ')
const dessin = `<svg class="roue__dessin" viewBox="${VB}" role="img" aria-label="${esc(description)}" focusable="false">
${anneaux.map((a) => ` <g class="roue__anneau roue__anneau--${a.id}"><path class="roue__zone" d="${a.zone}" fill-rule="evenodd"/><circle class="roue__trait" cx="${a.cx}" cy="${a.cy}" r="${a.r}"/></g>`).join('\n')}
${anneaux.map((a) => ` <text class="roue__lettre" x="${a.cx}" y="${a.yLettre}" font-size="${a.tailleLettre}" text-anchor="middle">${a.id}</text>`).join('\n')}
${anneaux.map((a) => ` <text class="roue__nom" x="${a.cx}" y="${a.yNom}" font-size="${F.CORPS.nom}" text-anchor="middle">${esc(nomAnneau(a.id))}</text>`).join('\n')}
</svg>`
const calques = bandeaux.map((b) => {
const texte = F.texteBandeau(F.motsBandeau(ECHELLES[b.id].mots, b.longueur))
return `<div class="roue__bandeau" aria-hidden="true"><svg class="roue__tour roue__tour--${b.sens}" viewBox="${VB}" focusable="false">`
+ `<defs><path id="roue-bandeau-${b.id}" d="${b.d}"/></defs>`
+ `<text class="roue__mots" font-size="${F.CORPS.mot}" textLength="${b.longueur}" lengthAdjust="spacing"><textPath href="#roue-bandeau-${b.id}">${esc(texte)}</textPath></text></svg></div>`
}).join('\n')
const cadreS = F.cadreMotS()
const motsS = ECHELLES.S.mots
const tour = motsS.length * F.MOUVEMENT_MOTS.cadence
const mots = `<div class="roue__mots-s" aria-hidden="true" style="left:${pc((cadreS.x - X0) / COTE)};top:${pc((cadreS.y - Y0) / COTE)};width:${pc(cadreS.l / COTE)};height:${pc(cadreS.h / COTE)};font-size:calc(100cqw * ${F.CORPS.mot} / ${COTE})">
${motsS.map((m, i) => ` <span class="roue__mot-s${i === 0 ? ' roue__mot-s--premier' : ''}" style="animation-duration:${tour}ms;animation-delay:${i === 0 ? 0 : i * F.MOUVEMENT_MOTS.cadence - tour}ms">${F.lignesMotS(m).map((l) => `<span class="roue__mot-ligne">${esc(l)}</span>`).join('')}</span>`).join('\n')}
</div>`
const html = `<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Les échelles S, M, XL</title>
<!-- Généré par nav-carte/scripts/export-roue-echelles.mjs depuis utils/figures.ts et utils/echelles.ts : ne pas éditer à la main. -->
<style>
:root {
--roue-fond: #f8f6f1;
--roue-encre: #1a2238;
--roue-texte: #1a2238;
--roue-bord: #d8d3c6;
--roue-surface: #ffffff;
--roue-accent: #f5b342;
}
@media (prefers-color-scheme: dark) {
:root { --roue-fond: #12172a; --roue-encre: #c9d2ea; --roue-texte: #eef1f8; --roue-bord: #2e3853; --roue-surface: #1a2238; }
}
html, body { margin: 0; background: var(--roue-fond); }
body { min-height: 100vh; display: grid; place-items: center; font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; }
.roue { --roue-attenue: color-mix(in srgb, var(--roue-texte) 78%, transparent); position: relative; container-type: inline-size; width: min(92vw, 560px); }
.roue__dessin { display: block; width: 100%; height: auto; }
.roue__zone { fill: color-mix(in srgb, var(--roue-encre) 5%, transparent); }
.roue__anneau--M .roue__zone { fill: color-mix(in srgb, var(--roue-encre) 8%, transparent); }
.roue__anneau--S .roue__zone { fill: color-mix(in srgb, var(--roue-encre) 12%, transparent); }
.roue__trait { fill: none; stroke: color-mix(in srgb, var(--roue-encre) 60%, transparent); stroke-width: 2px; vector-effect: non-scaling-stroke; }
.roue__lettre, .roue__nom, .roue__mots { font-family: inherit; }
.roue__lettre { fill: var(--roue-texte); font-weight: 700; }
.roue__nom { fill: var(--roue-attenue); font-weight: 600; }
.roue__mots { fill: var(--roue-attenue); }
.roue__bandeau { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.roue__tour { display: block; width: 100%; height: 100%; overflow: visible; animation: roue-horaire 75s linear infinite; }
.roue__tour--antihoraire { animation-name: roue-antihoraire; }
.roue__mots-s { position: absolute; display: grid; pointer-events: none; }
.roue__mot-s { grid-area: 1 / 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; line-height: 1.2; color: var(--roue-texte); opacity: 0; animation: roue-mot-s 17.5s linear infinite; }
.roue__mot-s--premier { opacity: 1; }
.roue__mot-ligne { white-space: nowrap; }
.roue--fige .roue__tour, .roue--fige .roue__mot-s { animation-play-state: paused; }
.roue__pause { position: absolute; right: 0; bottom: 0; display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border: 1px solid var(--roue-bord); border-radius: 999px; background: var(--roue-surface); color: var(--roue-attenue); cursor: pointer; }
.roue__pause svg { width: 18px; height: 18px; fill: currentColor; }
.roue__pause:hover { color: var(--roue-texte); border-color: var(--roue-accent); }
.roue__pause:focus-visible { outline: 2.5px solid var(--roue-texte); outline-offset: 3px; }
.roue__sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@keyframes roue-horaire { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
@keyframes roue-antihoraire { from { transform: rotate(0deg); } to { transform: rotate(-360deg); } }
@keyframes roue-mot-s { 0%, 12% { opacity: 1; } 14.286%, 97.714% { opacity: 0; } 100% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
.roue__tour, .roue__mot-s { animation: none; }
.roue__pause { display: none; }
}
</style>
</head>
<body>
<div class="roue">
${dessin}
${calques}
${mots}
<button type="button" class="roue__pause" aria-pressed="false">
<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M7 5h3.5v14H7zM13.5 5H17v14h-3.5z"/></svg>
<span class="roue__sr">Mettre les mots en pause</span>
</button>
</div>
<script>
document.querySelectorAll('.roue').forEach(function (r) {
var b = r.querySelector('.roue__pause'), p = b.querySelector('path')
b.addEventListener('click', function () {
var fige = r.classList.toggle('roue--fige')
b.setAttribute('aria-pressed', fige ? 'true' : 'false')
p.setAttribute('d', fige ? 'M8 5.5v13l10.5-6.5z' : 'M7 5h3.5v14H7zM13.5 5H17v14h-3.5z')
})
})
</script>
</body>
</html>
`
writeFileSync(sortie, html)
console.log(`${sortie} : ${Buffer.byteLength(html)} octets`)