@xiwawell/litha-espresso-loader 0.0.0-stage → 1.0.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.
- package/README.md +131 -2
- package/dist/litha-loader.js +247 -0
- package/dist/litha-loader.mjs +248 -0
- package/package.json +29 -5
package/README.md
CHANGED
|
@@ -1,3 +1,132 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Litha Espresso Loader
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Un indicateur de chargement en fenêtre modale : une machine à café remplit un verre pendant que la page charge.
|
|
4
|
+
|
|
5
|
+
JavaScript, SVG et CSS, sans dépendance ni framework.
|
|
6
|
+
|
|
7
|
+
## Installer
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
npm install @xiwawell/litha-espresso-loader
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
import LithaLoader from "@xiwawell/litha-espresso-loader";
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Sans outil de build, avec une simple balise (le style et le dessin sont inclus) :
|
|
18
|
+
|
|
19
|
+
```html
|
|
20
|
+
<script src="https://unpkg.com/@xiwawell/litha-espresso-loader"></script>
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
La variable `LithaLoader` est alors disponible dans la page. Le composant s'utilise dans un navigateur : importé côté serveur, il ne fait rien.
|
|
24
|
+
|
|
25
|
+
## Utiliser
|
|
26
|
+
|
|
27
|
+
Chargement de durée inconnue : le verre monte lentement, la barre va et vient, aucun pourcentage n'est affiché.
|
|
28
|
+
|
|
29
|
+
```js
|
|
30
|
+
const cafe = LithaLoader.open();
|
|
31
|
+
await chargerLesDonnees();
|
|
32
|
+
cafe.finish(); // remplit le verre, affiche « prêt », puis ferme
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Progression réelle, de 0 à 100 :
|
|
36
|
+
|
|
37
|
+
```js
|
|
38
|
+
const cafe = LithaLoader.open();
|
|
39
|
+
cafe.setProgress(0);
|
|
40
|
+
cafe.setProgress(40);
|
|
41
|
+
cafe.setProgress(100); // équivaut à finish()
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Arrêter avant la fin, par exemple après une erreur :
|
|
45
|
+
|
|
46
|
+
```js
|
|
47
|
+
cafe.close();
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## API
|
|
51
|
+
|
|
52
|
+
`LithaLoader.open(options)` ouvre la popup et rend un objet. Si une popup est déjà ouverte, il rend celle-ci et ignore les options.
|
|
53
|
+
|
|
54
|
+
| Membre | Effet |
|
|
55
|
+
|---|---|
|
|
56
|
+
| `setProgress(n)` | donne la progression réelle, de 0 à 100 |
|
|
57
|
+
| `finish()` | indique que le chargement est terminé |
|
|
58
|
+
| `close()` | ferme tout de suite |
|
|
59
|
+
| `closed` | promesse : `true` si le café était prêt, `false` si la popup a été fermée avant |
|
|
60
|
+
|
|
61
|
+
## Personnaliser
|
|
62
|
+
|
|
63
|
+
### Options
|
|
64
|
+
|
|
65
|
+
| Option | Par défaut | Effet |
|
|
66
|
+
|---|---|---|
|
|
67
|
+
| `titre` | `"Litha Espresso"` | titre de la fenêtre |
|
|
68
|
+
| `messages` | voir ci-dessous | textes affichés ; seuls ceux donnés sont remplacés |
|
|
69
|
+
| `fermable` | `true` | `false` retire la croix et ignore la touche Échap |
|
|
70
|
+
| `delaiFermeture` | `1600` | durée en millisecondes de l'écran « prêt » |
|
|
71
|
+
|
|
72
|
+
Les clés de `messages` sont `chauffe`, `coule`, `remplit`, `presque` et `pret`.
|
|
73
|
+
|
|
74
|
+
```js
|
|
75
|
+
LithaLoader.open({
|
|
76
|
+
titre: "Votre commande",
|
|
77
|
+
messages: { pret: "Servez-vous !" },
|
|
78
|
+
fermable: false,
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Couleurs
|
|
83
|
+
|
|
84
|
+
Des variables CSS, à poser sur `:root` ou sur un parent de la page :
|
|
85
|
+
|
|
86
|
+
| Variable | Rôle |
|
|
87
|
+
|---|---|
|
|
88
|
+
| `--litha-fond` | fond de la fenêtre |
|
|
89
|
+
| `--litha-texte` | couleur du texte |
|
|
90
|
+
| `--litha-accent` | barre de progression |
|
|
91
|
+
| `--litha-piste` | fond de la barre |
|
|
92
|
+
| `--litha-voile` | voile derrière la fenêtre |
|
|
93
|
+
| `--litha-rayon` | arrondi de la fenêtre |
|
|
94
|
+
| `--litha-police` | police |
|
|
95
|
+
| `--litha-cafe` | couleur du café |
|
|
96
|
+
| `--litha-mousse` | couleur de la mousse |
|
|
97
|
+
|
|
98
|
+
```css
|
|
99
|
+
:root {
|
|
100
|
+
--litha-accent: #2e7d5b;
|
|
101
|
+
--litha-cafe: #6b3f22;
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Accessibilité
|
|
106
|
+
|
|
107
|
+
- Fenêtre modale native (`<dialog>`), fermable au clavier avec Échap.
|
|
108
|
+
- Barre de progression annoncée comme telle, sans valeur quand la durée est inconnue.
|
|
109
|
+
- Changements de message annoncés aux lecteurs d'écran.
|
|
110
|
+
- `prefers-reduced-motion` : les animations sont coupées, le verre continue de se remplir.
|
|
111
|
+
- La fenêtre s'adapte aux petits écrans.
|
|
112
|
+
|
|
113
|
+
## Développer
|
|
114
|
+
|
|
115
|
+
La démo est dans `index.html` : ouvrez-le dans un navigateur, aucun serveur n'est nécessaire.
|
|
116
|
+
|
|
117
|
+
Pour construire le paquet (`dist/`) et voir son contenu, depuis le dossier `litha-loader/` :
|
|
118
|
+
|
|
119
|
+
```
|
|
120
|
+
npm pack --dry-run
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
| Fichier | Rôle |
|
|
124
|
+
|---|---|
|
|
125
|
+
| `loader/litha-loader.js` | la popup et la progression |
|
|
126
|
+
| `loader/popup.css` | l'apparence de la fenêtre et les couleurs réglables |
|
|
127
|
+
| `loader/machine.js` | le dessin SVG (`window.LithaMachine`) |
|
|
128
|
+
| `loader/machine.css` | les animations du dessin |
|
|
129
|
+
| `build.js` | rassemble ces quatre fichiers dans `dist/` |
|
|
130
|
+
| `index.html`, `demo.js` | la démo |
|
|
131
|
+
|
|
132
|
+
La logique et le dessin communiquent par deux valeurs posées sur la popup (`.litha`) : `data-etat` (`chauffe`, `extraction`, `pret`) et `--progress` (de 0 à 1).
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
if (typeof window !== "undefined") {
|
|
2
|
+
const lithaStyle = document.createElement("style");
|
|
3
|
+
lithaStyle.textContent = "\n.litha {\n --progress: 0;\n box-sizing: border-box;\n width: min(360px, calc(100vw - 32px));\n max-height: calc(100vh - 32px);\n max-height: calc(100dvh - 32px);\n padding: 20px 24px 24px;\n border: 0;\n border-radius: var(--litha-rayon, 16px);\n background: var(--litha-fond, #fbf6ef);\n color: var(--litha-texte, #2b1d14);\n font-family: var(--litha-police, system-ui, sans-serif);\n text-align: center;\n box-shadow: 0 20px 60px rgb(0 0 0 / 0.35);\n}\n\n.litha::backdrop {\n background: var(--litha-voile, rgb(30 18 10 / 0.65));\n}\n\n.litha[open] {\n animation: litha-entree 0.25s ease-out;\n}\n\n@keyframes litha-entree {\n from { opacity: 0; transform: translateY(12px); }\n}\n\n.litha-entete {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: 12px;\n}\n\n.litha-entete h2 {\n margin: 0;\n font-size: 1.25rem;\n}\n\n.litha-fermer {\n width: 40px;\n height: 40px;\n border: 0;\n border-radius: 8px;\n background: transparent;\n color: inherit;\n font-size: 1.5rem;\n cursor: pointer;\n}\n\n.litha-fermer:hover {\n background: color-mix(in srgb, currentColor 10%, transparent);\n}\n\n.litha-scene svg {\n display: block;\n width: 100%;\n height: auto;\n max-height: 40vh;\n margin: 12px 0;\n}\n\n.litha-jauge {\n height: 10px;\n overflow: hidden;\n border-radius: 5px;\n background: var(--litha-piste, #e8dccd);\n}\n\n.litha-jauge span {\n display: block;\n height: 100%;\n background: var(--litha-accent, #8a5a35);\n transform-origin: left;\n transform: scaleX(var(--progress));\n}\n\n.litha[data-mode=\"indetermine\"]:not([data-etat=\"pret\"]) .litha-jauge span {\n width: 40%;\n animation: litha-va-et-vient 1.4s ease-in-out infinite;\n}\n\n@keyframes litha-va-et-vient {\n from { transform: translateX(-100%); }\n to { transform: translateX(250%); }\n}\n\n.litha-pourcent {\n min-height: 1.5em;\n margin: 10px 0 0;\n font-size: 1.5rem;\n line-height: 1.5;\n font-weight: 700;\n font-variant-numeric: tabular-nums;\n}\n\n.litha-message {\n min-height: 1.4em;\n margin: 4px 0 0;\n}\n\n/* Couleurs du café réglables, par-dessus celles de machine.css. */\n.litha .litha-machine .cafe { fill: var(--litha-cafe, #3b1f12); }\n.litha .litha-machine .mousse { fill: var(--litha-mousse, #d49b54); }\n.litha .litha-machine .filet-jet { stroke: var(--litha-cafe, #4b2816); }\n.litha .litha-machine .filet-reflet { stroke: var(--litha-mousse, #d49b54); }\n\n.litha .provisoire .cafe {\n fill: var(--litha-cafe, #6f4e37);\n transform-box: fill-box;\n transform-origin: bottom;\n transform: scaleY(var(--progress));\n}\n\n.litha .provisoire .filet {\n fill: var(--litha-cafe, #6f4e37);\n opacity: 0;\n}\n\n.litha[data-etat=\"extraction\"] .provisoire .filet {\n opacity: 1;\n}\n\n.litha .provisoire .verre {\n fill: none;\n stroke: currentColor;\n stroke-width: 4;\n}\n\n@media (prefers-reduced-motion: reduce) {\n .litha[open] { animation: none; }\n\n .litha[data-mode=\"indetermine\"]:not([data-etat=\"pret\"]) .litha-jauge span {\n width: 100%;\n transform: none;\n opacity: 0.4;\n animation: none;\n }\n}\n/* Animations et styles du dessin SVG Litha Espresso (machine.js). */\r\n\r\n.litha-machine {\r\n overflow: visible;\r\n filter: drop-shadow(0 8px 16px rgb(43 29 20 / 0.18));\r\n}\r\n\r\n/* Voyant d'état */\r\n.litha-machine .voyant {\r\n fill: #e09f3e;\r\n transition: fill 0.25s ease;\r\n}\r\n\r\n.litha[data-etat=\"chauffe\"] .litha-machine .voyant {\r\n fill: #e09f3e;\r\n animation: litha-voyant-clignote 0.7s ease-in-out infinite alternate;\r\n}\r\n\r\n.litha[data-etat=\"extraction\"] .litha-machine .voyant {\r\n fill: #3ea377;\r\n}\r\n\r\n.litha[data-etat=\"pret\"] .litha-machine .voyant {\r\n fill: #5ce0a0;\r\n}\r\n\r\n/* Filet d'écoulement */\r\n.litha-machine .filet {\r\n opacity: 0;\r\n transition: opacity 0.2s ease;\r\n}\r\n\r\n.litha[data-etat=\"extraction\"] .litha-machine .filet {\r\n opacity: 1;\r\n}\r\n\r\n.litha-machine .filet-jet {\r\n stroke: #4b2816;\r\n stroke-width: 3.5;\r\n stroke-linecap: round;\r\n stroke-dasharray: 8 5;\r\n animation: litha-ecoulement 0.45s linear infinite;\r\n}\r\n\r\n.litha-machine .filet-reflet {\r\n stroke: #d49b54;\r\n stroke-width: 1.4;\r\n stroke-linecap: round;\r\n stroke-dasharray: 6 6;\r\n animation: litha-ecoulement 0.35s linear infinite;\r\n}\r\n\r\n/* Remplissage progressif du verre selon --progress (0 à 1) */\r\n.litha-machine .liquide {\r\n transform: translateY(calc((1 - var(--progress)) * 54px));\r\n}\r\n\r\n.litha-machine .cafe {\r\n fill: #3b1f12;\r\n}\r\n\r\n.litha-machine .mousse {\r\n fill: #d49b54;\r\n opacity: 0;\r\n transition: opacity 0.25s ease;\r\n}\r\n\r\n.litha[data-etat=\"extraction\"] .litha-machine .mousse,\r\n.litha[data-etat=\"pret\"] .litha-machine .mousse {\r\n opacity: 1;\r\n}\r\n\r\n/* Vapeur */\r\n.litha-machine .vapeur {\r\n opacity: 0;\r\n transition: opacity 0.35s ease;\r\n}\r\n\r\n.litha[data-etat=\"extraction\"] .litha-machine .vapeur,\r\n.litha[data-etat=\"pret\"] .litha-machine .vapeur {\r\n opacity: 1;\r\n}\r\n\r\n.litha-machine .vapeur-brin {\r\n fill: none;\r\n stroke: rgb(138 90 53 / 0.55);\r\n stroke-width: 2;\r\n stroke-linecap: round;\r\n animation: litha-vapeur-monte 2.2s ease-in-out infinite;\r\n}\r\n\r\n.litha-machine .vapeur-2 {\r\n animation-delay: 0.65s;\r\n}\r\n\r\n.litha-machine .vapeur-3 {\r\n animation-delay: 1.3s;\r\n}\r\n\r\n/* Grains décoratifs */\r\n.litha-machine .grain {\r\n fill: #8a5a35;\r\n opacity: 0.35;\r\n animation: litha-grain-flotte 3.6s ease-in-out infinite;\r\n}\r\n\r\n.litha-machine .grain-2 {\r\n animation-delay: 1.4s;\r\n}\r\n\r\n/* Animations */\r\n@keyframes litha-voyant-clignote {\r\n from { opacity: 0.35; }\r\n to { opacity: 1; }\r\n}\r\n\r\n@keyframes litha-ecoulement {\r\n from { stroke-dashoffset: 0; }\r\n to { stroke-dashoffset: -26; }\r\n}\r\n\r\n@keyframes litha-vapeur-monte {\r\n 0% {\r\n opacity: 0;\r\n transform: translateY(5px);\r\n }\r\n 45% {\r\n opacity: 0.85;\r\n }\r\n 100% {\r\n opacity: 0;\r\n transform: translateY(-12px);\r\n }\r\n}\r\n\r\n@keyframes litha-grain-flotte {\r\n 0%, 100% {\r\n transform: translateY(0);\r\n }\r\n 50% {\r\n transform: translateY(-5px);\r\n }\r\n}\r\n\r\n/* Accessibilité : réduction des animations */\r\n@media (prefers-reduced-motion: reduce) {\r\n .litha-machine,\r\n .litha-machine * {\r\n animation: none !important;\r\n transition: none !important;\r\n }\r\n\r\n .litha-machine .filet-jet,\r\n .litha-machine .filet-reflet {\r\n stroke-dasharray: none;\r\n }\r\n}\r\n";
|
|
4
|
+
document.head.prepend(lithaStyle);
|
|
5
|
+
// Dessin SVG de la machine à café Litha Espresso.
|
|
6
|
+
// Utilisé par litha-loader.js via window.LithaMachine et animé par machine.css.
|
|
7
|
+
window.LithaMachine = `
|
|
8
|
+
<svg class="litha-machine" viewBox="0 0 240 220" xmlns="http://www.w3.org/2000/svg">
|
|
9
|
+
<defs>
|
|
10
|
+
<clipPath id="litha-verre-clip">
|
|
11
|
+
<path d="M93 136 L147 136 L141 188 Q140 190 137 190 L103 190 Q100 190 99 188 Z" />
|
|
12
|
+
</clipPath>
|
|
13
|
+
<linearGradient id="litha-corps" x1="0" y1="0" x2="1" y2="1">
|
|
14
|
+
<stop offset="0%" stop-color="#3c3733" />
|
|
15
|
+
<stop offset="100%" stop-color="#1f1c1a" />
|
|
16
|
+
</linearGradient>
|
|
17
|
+
<linearGradient id="litha-metal" x1="0" y1="0" x2="1" y2="0">
|
|
18
|
+
<stop offset="0%" stop-color="#9e958c" />
|
|
19
|
+
<stop offset="50%" stop-color="#e5ded5" />
|
|
20
|
+
<stop offset="100%" stop-color="#8c837a" />
|
|
21
|
+
</linearGradient>
|
|
22
|
+
</defs>
|
|
23
|
+
|
|
24
|
+
<!-- Grains de café décoratifs -->
|
|
25
|
+
<ellipse class="grain grain-1" cx="30" cy="148" rx="6" ry="4" transform="rotate(-25 30 148)" />
|
|
26
|
+
<ellipse class="grain grain-2" cx="210" cy="136" rx="6" ry="4" transform="rotate(20 210 136)" />
|
|
27
|
+
|
|
28
|
+
<!-- Châssis arrière de la machine -->
|
|
29
|
+
<rect x="52" y="64" width="136" height="132" rx="10" fill="#171513" />
|
|
30
|
+
<rect x="64" y="74" width="112" height="118" rx="6" fill="#231f1d" />
|
|
31
|
+
|
|
32
|
+
<!-- Tête de la machine -->
|
|
33
|
+
<rect x="38" y="14" width="164" height="60" rx="14" fill="url(#litha-corps)" stroke="rgba(255,255,255,0.12)" stroke-width="1" />
|
|
34
|
+
<rect x="48" y="10" width="144" height="8" rx="4" fill="url(#litha-metal)" />
|
|
35
|
+
|
|
36
|
+
<!-- Bandeau vert Litha Espresso + manomètre + voyant -->
|
|
37
|
+
<rect x="56" y="44" width="128" height="4" rx="2" fill="#2e7d5b" />
|
|
38
|
+
<circle cx="120" cy="30" r="9" fill="#141211" stroke="#c89b6e" stroke-width="1.8" />
|
|
39
|
+
<line class="aiguille" x1="120" y1="30" x2="125" y2="25" stroke="#3ea377" stroke-width="1.6" stroke-linecap="round" />
|
|
40
|
+
<circle class="voyant" cx="172" cy="30" r="4.5" />
|
|
41
|
+
|
|
42
|
+
<!-- Porte-filtre et double bec -->
|
|
43
|
+
<rect x="96" y="74" width="48" height="14" rx="4" fill="url(#litha-metal)" />
|
|
44
|
+
<rect x="142" y="77" width="44" height="7" rx="3.5" fill="#12100f" stroke="#c89b6e" stroke-width="1" />
|
|
45
|
+
<path d="M113 88 L113 99 Q113 103 116 104 L116 108 M127 88 L127 99 Q127 103 124 104 L124 108" stroke="url(#litha-metal)" stroke-width="3" fill="none" stroke-linecap="round" />
|
|
46
|
+
|
|
47
|
+
<!-- Filet d'écoulement du café -->
|
|
48
|
+
<g class="filet">
|
|
49
|
+
<line class="filet-jet" x1="116" y1="109" x2="116" y2="188" />
|
|
50
|
+
<line class="filet-jet" x1="124" y1="109" x2="124" y2="188" />
|
|
51
|
+
<line class="filet-reflet" x1="116" y1="109" x2="116" y2="188" />
|
|
52
|
+
<line class="filet-reflet" x1="124" y1="109" x2="124" y2="188" />
|
|
53
|
+
</g>
|
|
54
|
+
|
|
55
|
+
<!-- Vapeur au-dessus du verre -->
|
|
56
|
+
<g class="vapeur">
|
|
57
|
+
<path class="vapeur-brin vapeur-1" d="M104 128 Q100 120 105 113" />
|
|
58
|
+
<path class="vapeur-brin vapeur-2" d="M120 126 Q125 118 119 110" />
|
|
59
|
+
<path class="vapeur-brin vapeur-3" d="M136 128 Q140 120 135 113" />
|
|
60
|
+
</g>
|
|
61
|
+
|
|
62
|
+
<!-- Café et mousse (crema) dans le verre -->
|
|
63
|
+
<g clip-path="url(#litha-verre-clip)">
|
|
64
|
+
<g class="liquide">
|
|
65
|
+
<rect class="cafe" x="88" y="138" width="64" height="54" />
|
|
66
|
+
<rect class="mousse" x="88" y="134" width="64" height="6" rx="2" />
|
|
67
|
+
</g>
|
|
68
|
+
</g>
|
|
69
|
+
|
|
70
|
+
<!-- Contour du verre et reflet -->
|
|
71
|
+
<path d="M90 134 L150 134 L143 189 Q142 192 138 192 L102 192 Q98 192 97 189 Z" fill="rgba(255,255,255,0.08)" stroke="rgba(43,29,20,0.45)" stroke-width="2" stroke-linejoin="round" />
|
|
72
|
+
<path d="M97 141 L101 184" stroke="rgba(255,255,255,0.45)" stroke-width="2" stroke-linecap="round" />
|
|
73
|
+
|
|
74
|
+
<!-- Bac d'égouttage -->
|
|
75
|
+
<rect x="54" y="193" width="132" height="11" rx="4" fill="url(#litha-metal)" />
|
|
76
|
+
<rect x="66" y="193" width="108" height="3" fill="#2a2623" />
|
|
77
|
+
</svg>
|
|
78
|
+
`;
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
(function () {
|
|
82
|
+
"use strict";
|
|
83
|
+
|
|
84
|
+
const DUREE_CHAUFFE = 1200;
|
|
85
|
+
const DUREE_PRET = 1600;
|
|
86
|
+
const VITESSE_MAX = 55;
|
|
87
|
+
const PLAFOND_AUTO = 90;
|
|
88
|
+
|
|
89
|
+
const MESSAGES = {
|
|
90
|
+
chauffe: "La machine chauffe…",
|
|
91
|
+
coule: "Le café coule…",
|
|
92
|
+
remplit: "Le verre se remplit…",
|
|
93
|
+
presque: "Encore quelques gouttes…",
|
|
94
|
+
pret: "Votre café est prêt !",
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// Affiché tant que machine.js n'existe pas.
|
|
98
|
+
const DESSIN_PROVISOIRE = `
|
|
99
|
+
<svg class="provisoire" viewBox="0 0 200 200">
|
|
100
|
+
<rect class="filet" x="97" y="20" width="6" height="156"/>
|
|
101
|
+
<rect class="cafe" x="62" y="82" width="76" height="96"/>
|
|
102
|
+
<path class="verre" d="M60 70 V180 H140 V70"/>
|
|
103
|
+
</svg>`;
|
|
104
|
+
|
|
105
|
+
const GABARIT = `
|
|
106
|
+
<div class="litha-entete">
|
|
107
|
+
<h2 id="litha-titre"></h2>
|
|
108
|
+
<button type="button" class="litha-fermer" aria-label="Fermer">×</button>
|
|
109
|
+
</div>
|
|
110
|
+
<div class="litha-scene" aria-hidden="true"></div>
|
|
111
|
+
<div class="litha-jauge" role="progressbar" aria-label="Préparation du café"
|
|
112
|
+
aria-valuemin="0" aria-valuemax="100"><span></span></div>
|
|
113
|
+
<p class="litha-pourcent" aria-hidden="true"></p>
|
|
114
|
+
<p class="litha-message" id="litha-message" aria-live="polite"></p>`;
|
|
115
|
+
|
|
116
|
+
let enCours = null;
|
|
117
|
+
|
|
118
|
+
function cleMessage(etat, pourcent) {
|
|
119
|
+
if (etat !== "extraction") return etat;
|
|
120
|
+
if (pourcent < 50) return "coule";
|
|
121
|
+
if (pourcent < 90) return "remplit";
|
|
122
|
+
return "presque";
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function open(options = {}) {
|
|
126
|
+
if (enCours) return enCours;
|
|
127
|
+
|
|
128
|
+
const messages = { ...MESSAGES, ...options.messages };
|
|
129
|
+
const fermable = options.fermable !== false;
|
|
130
|
+
const delaiFermeture = Number.isFinite(options.delaiFermeture)
|
|
131
|
+
? Math.max(0, options.delaiFermeture)
|
|
132
|
+
: DUREE_PRET;
|
|
133
|
+
|
|
134
|
+
const popup = document.createElement("dialog");
|
|
135
|
+
popup.className = "litha";
|
|
136
|
+
popup.setAttribute("aria-labelledby", "litha-titre");
|
|
137
|
+
popup.setAttribute("aria-describedby", "litha-message");
|
|
138
|
+
popup.innerHTML = GABARIT;
|
|
139
|
+
popup.querySelector("h2").textContent = options.titre ?? "Litha Espresso";
|
|
140
|
+
popup.querySelector(".litha-scene").innerHTML = window.LithaMachine || DESSIN_PROVISOIRE;
|
|
141
|
+
|
|
142
|
+
const bouton = popup.querySelector(".litha-fermer");
|
|
143
|
+
const jauge = popup.querySelector(".litha-jauge");
|
|
144
|
+
const texte = popup.querySelector(".litha-pourcent");
|
|
145
|
+
const message = popup.querySelector(".litha-message");
|
|
146
|
+
|
|
147
|
+
let etat = "chauffe";
|
|
148
|
+
let mesure = false; // true dès que la page donne une vraie progression
|
|
149
|
+
let cible = null;
|
|
150
|
+
let affiche = 0;
|
|
151
|
+
let ferme = false;
|
|
152
|
+
let image = 0;
|
|
153
|
+
let minuterie = 0;
|
|
154
|
+
let resoudre;
|
|
155
|
+
const closed = new Promise((resolve) => { resoudre = resolve; });
|
|
156
|
+
|
|
157
|
+
const debut = performance.now();
|
|
158
|
+
let precedent = debut;
|
|
159
|
+
|
|
160
|
+
function dessiner() {
|
|
161
|
+
const pourcent = Math.floor(affiche);
|
|
162
|
+
popup.dataset.etat = etat;
|
|
163
|
+
popup.dataset.mode = mesure ? "mesure" : "indetermine";
|
|
164
|
+
popup.style.setProperty("--progress", (affiche / 100).toFixed(4));
|
|
165
|
+
// Durée inconnue : pas de valeur à annoncer tant que ce n'est pas prêt.
|
|
166
|
+
if (mesure || etat === "pret") jauge.setAttribute("aria-valuenow", pourcent);
|
|
167
|
+
else jauge.removeAttribute("aria-valuenow");
|
|
168
|
+
texte.textContent = mesure ? pourcent + " %" : "";
|
|
169
|
+
const nouveau = messages[cleMessage(etat, pourcent)];
|
|
170
|
+
if (message.textContent !== nouveau) message.textContent = nouveau;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function avancer() {
|
|
174
|
+
const maintenant = performance.now();
|
|
175
|
+
const dt = Math.min((maintenant - precedent) / 1000, 0.1);
|
|
176
|
+
precedent = maintenant;
|
|
177
|
+
|
|
178
|
+
if (etat === "chauffe" && maintenant - debut >= DUREE_CHAUFFE) etat = "extraction";
|
|
179
|
+
|
|
180
|
+
if (etat === "extraction") {
|
|
181
|
+
if (cible === null) {
|
|
182
|
+
affiche += (PLAFOND_AUTO - affiche) * 0.35 * dt;
|
|
183
|
+
} else {
|
|
184
|
+
affiche = Math.max(affiche, Math.min(cible, affiche + VITESSE_MAX * dt));
|
|
185
|
+
}
|
|
186
|
+
if (affiche >= 100) {
|
|
187
|
+
affiche = 100;
|
|
188
|
+
etat = "pret";
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
dessiner();
|
|
193
|
+
|
|
194
|
+
if (etat === "pret") minuterie = setTimeout(close, delaiFermeture);
|
|
195
|
+
else image = requestAnimationFrame(avancer);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function setProgress(pourcentage) {
|
|
199
|
+
const valeur = Number(pourcentage);
|
|
200
|
+
if (!Number.isFinite(valeur) || cible === 100) return;
|
|
201
|
+
cible = Math.min(100, Math.max(0, valeur));
|
|
202
|
+
if (!mesure) {
|
|
203
|
+
mesure = true;
|
|
204
|
+
affiche = Math.min(affiche, cible);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function finish() {
|
|
209
|
+
cible = 100;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function close() {
|
|
213
|
+
if (ferme) return;
|
|
214
|
+
ferme = true;
|
|
215
|
+
cancelAnimationFrame(image);
|
|
216
|
+
clearTimeout(minuterie);
|
|
217
|
+
if (popup.open) popup.close();
|
|
218
|
+
popup.remove();
|
|
219
|
+
enCours = null;
|
|
220
|
+
resoudre(etat === "pret");
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (fermable) {
|
|
224
|
+
bouton.addEventListener("click", close);
|
|
225
|
+
} else {
|
|
226
|
+
bouton.remove();
|
|
227
|
+
popup.setAttribute("closedby", "none");
|
|
228
|
+
popup.addEventListener("cancel", (e) => e.preventDefault());
|
|
229
|
+
popup.addEventListener("keydown", (e) => {
|
|
230
|
+
if (e.key === "Escape") e.preventDefault();
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
popup.addEventListener("close", close);
|
|
234
|
+
|
|
235
|
+
document.body.append(popup);
|
|
236
|
+
dessiner();
|
|
237
|
+
popup.showModal();
|
|
238
|
+
image = requestAnimationFrame(avancer);
|
|
239
|
+
|
|
240
|
+
enCours = { setProgress, finish, close, closed };
|
|
241
|
+
return enCours;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
window.LithaLoader = { open };
|
|
245
|
+
})();
|
|
246
|
+
|
|
247
|
+
}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
if (typeof window !== "undefined") {
|
|
2
|
+
const lithaStyle = document.createElement("style");
|
|
3
|
+
lithaStyle.textContent = "\n.litha {\n --progress: 0;\n box-sizing: border-box;\n width: min(360px, calc(100vw - 32px));\n max-height: calc(100vh - 32px);\n max-height: calc(100dvh - 32px);\n padding: 20px 24px 24px;\n border: 0;\n border-radius: var(--litha-rayon, 16px);\n background: var(--litha-fond, #fbf6ef);\n color: var(--litha-texte, #2b1d14);\n font-family: var(--litha-police, system-ui, sans-serif);\n text-align: center;\n box-shadow: 0 20px 60px rgb(0 0 0 / 0.35);\n}\n\n.litha::backdrop {\n background: var(--litha-voile, rgb(30 18 10 / 0.65));\n}\n\n.litha[open] {\n animation: litha-entree 0.25s ease-out;\n}\n\n@keyframes litha-entree {\n from { opacity: 0; transform: translateY(12px); }\n}\n\n.litha-entete {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: 12px;\n}\n\n.litha-entete h2 {\n margin: 0;\n font-size: 1.25rem;\n}\n\n.litha-fermer {\n width: 40px;\n height: 40px;\n border: 0;\n border-radius: 8px;\n background: transparent;\n color: inherit;\n font-size: 1.5rem;\n cursor: pointer;\n}\n\n.litha-fermer:hover {\n background: color-mix(in srgb, currentColor 10%, transparent);\n}\n\n.litha-scene svg {\n display: block;\n width: 100%;\n height: auto;\n max-height: 40vh;\n margin: 12px 0;\n}\n\n.litha-jauge {\n height: 10px;\n overflow: hidden;\n border-radius: 5px;\n background: var(--litha-piste, #e8dccd);\n}\n\n.litha-jauge span {\n display: block;\n height: 100%;\n background: var(--litha-accent, #8a5a35);\n transform-origin: left;\n transform: scaleX(var(--progress));\n}\n\n.litha[data-mode=\"indetermine\"]:not([data-etat=\"pret\"]) .litha-jauge span {\n width: 40%;\n animation: litha-va-et-vient 1.4s ease-in-out infinite;\n}\n\n@keyframes litha-va-et-vient {\n from { transform: translateX(-100%); }\n to { transform: translateX(250%); }\n}\n\n.litha-pourcent {\n min-height: 1.5em;\n margin: 10px 0 0;\n font-size: 1.5rem;\n line-height: 1.5;\n font-weight: 700;\n font-variant-numeric: tabular-nums;\n}\n\n.litha-message {\n min-height: 1.4em;\n margin: 4px 0 0;\n}\n\n/* Couleurs du café réglables, par-dessus celles de machine.css. */\n.litha .litha-machine .cafe { fill: var(--litha-cafe, #3b1f12); }\n.litha .litha-machine .mousse { fill: var(--litha-mousse, #d49b54); }\n.litha .litha-machine .filet-jet { stroke: var(--litha-cafe, #4b2816); }\n.litha .litha-machine .filet-reflet { stroke: var(--litha-mousse, #d49b54); }\n\n.litha .provisoire .cafe {\n fill: var(--litha-cafe, #6f4e37);\n transform-box: fill-box;\n transform-origin: bottom;\n transform: scaleY(var(--progress));\n}\n\n.litha .provisoire .filet {\n fill: var(--litha-cafe, #6f4e37);\n opacity: 0;\n}\n\n.litha[data-etat=\"extraction\"] .provisoire .filet {\n opacity: 1;\n}\n\n.litha .provisoire .verre {\n fill: none;\n stroke: currentColor;\n stroke-width: 4;\n}\n\n@media (prefers-reduced-motion: reduce) {\n .litha[open] { animation: none; }\n\n .litha[data-mode=\"indetermine\"]:not([data-etat=\"pret\"]) .litha-jauge span {\n width: 100%;\n transform: none;\n opacity: 0.4;\n animation: none;\n }\n}\n/* Animations et styles du dessin SVG Litha Espresso (machine.js). */\r\n\r\n.litha-machine {\r\n overflow: visible;\r\n filter: drop-shadow(0 8px 16px rgb(43 29 20 / 0.18));\r\n}\r\n\r\n/* Voyant d'état */\r\n.litha-machine .voyant {\r\n fill: #e09f3e;\r\n transition: fill 0.25s ease;\r\n}\r\n\r\n.litha[data-etat=\"chauffe\"] .litha-machine .voyant {\r\n fill: #e09f3e;\r\n animation: litha-voyant-clignote 0.7s ease-in-out infinite alternate;\r\n}\r\n\r\n.litha[data-etat=\"extraction\"] .litha-machine .voyant {\r\n fill: #3ea377;\r\n}\r\n\r\n.litha[data-etat=\"pret\"] .litha-machine .voyant {\r\n fill: #5ce0a0;\r\n}\r\n\r\n/* Filet d'écoulement */\r\n.litha-machine .filet {\r\n opacity: 0;\r\n transition: opacity 0.2s ease;\r\n}\r\n\r\n.litha[data-etat=\"extraction\"] .litha-machine .filet {\r\n opacity: 1;\r\n}\r\n\r\n.litha-machine .filet-jet {\r\n stroke: #4b2816;\r\n stroke-width: 3.5;\r\n stroke-linecap: round;\r\n stroke-dasharray: 8 5;\r\n animation: litha-ecoulement 0.45s linear infinite;\r\n}\r\n\r\n.litha-machine .filet-reflet {\r\n stroke: #d49b54;\r\n stroke-width: 1.4;\r\n stroke-linecap: round;\r\n stroke-dasharray: 6 6;\r\n animation: litha-ecoulement 0.35s linear infinite;\r\n}\r\n\r\n/* Remplissage progressif du verre selon --progress (0 à 1) */\r\n.litha-machine .liquide {\r\n transform: translateY(calc((1 - var(--progress)) * 54px));\r\n}\r\n\r\n.litha-machine .cafe {\r\n fill: #3b1f12;\r\n}\r\n\r\n.litha-machine .mousse {\r\n fill: #d49b54;\r\n opacity: 0;\r\n transition: opacity 0.25s ease;\r\n}\r\n\r\n.litha[data-etat=\"extraction\"] .litha-machine .mousse,\r\n.litha[data-etat=\"pret\"] .litha-machine .mousse {\r\n opacity: 1;\r\n}\r\n\r\n/* Vapeur */\r\n.litha-machine .vapeur {\r\n opacity: 0;\r\n transition: opacity 0.35s ease;\r\n}\r\n\r\n.litha[data-etat=\"extraction\"] .litha-machine .vapeur,\r\n.litha[data-etat=\"pret\"] .litha-machine .vapeur {\r\n opacity: 1;\r\n}\r\n\r\n.litha-machine .vapeur-brin {\r\n fill: none;\r\n stroke: rgb(138 90 53 / 0.55);\r\n stroke-width: 2;\r\n stroke-linecap: round;\r\n animation: litha-vapeur-monte 2.2s ease-in-out infinite;\r\n}\r\n\r\n.litha-machine .vapeur-2 {\r\n animation-delay: 0.65s;\r\n}\r\n\r\n.litha-machine .vapeur-3 {\r\n animation-delay: 1.3s;\r\n}\r\n\r\n/* Grains décoratifs */\r\n.litha-machine .grain {\r\n fill: #8a5a35;\r\n opacity: 0.35;\r\n animation: litha-grain-flotte 3.6s ease-in-out infinite;\r\n}\r\n\r\n.litha-machine .grain-2 {\r\n animation-delay: 1.4s;\r\n}\r\n\r\n/* Animations */\r\n@keyframes litha-voyant-clignote {\r\n from { opacity: 0.35; }\r\n to { opacity: 1; }\r\n}\r\n\r\n@keyframes litha-ecoulement {\r\n from { stroke-dashoffset: 0; }\r\n to { stroke-dashoffset: -26; }\r\n}\r\n\r\n@keyframes litha-vapeur-monte {\r\n 0% {\r\n opacity: 0;\r\n transform: translateY(5px);\r\n }\r\n 45% {\r\n opacity: 0.85;\r\n }\r\n 100% {\r\n opacity: 0;\r\n transform: translateY(-12px);\r\n }\r\n}\r\n\r\n@keyframes litha-grain-flotte {\r\n 0%, 100% {\r\n transform: translateY(0);\r\n }\r\n 50% {\r\n transform: translateY(-5px);\r\n }\r\n}\r\n\r\n/* Accessibilité : réduction des animations */\r\n@media (prefers-reduced-motion: reduce) {\r\n .litha-machine,\r\n .litha-machine * {\r\n animation: none !important;\r\n transition: none !important;\r\n }\r\n\r\n .litha-machine .filet-jet,\r\n .litha-machine .filet-reflet {\r\n stroke-dasharray: none;\r\n }\r\n}\r\n";
|
|
4
|
+
document.head.prepend(lithaStyle);
|
|
5
|
+
// Dessin SVG de la machine à café Litha Espresso.
|
|
6
|
+
// Utilisé par litha-loader.js via window.LithaMachine et animé par machine.css.
|
|
7
|
+
window.LithaMachine = `
|
|
8
|
+
<svg class="litha-machine" viewBox="0 0 240 220" xmlns="http://www.w3.org/2000/svg">
|
|
9
|
+
<defs>
|
|
10
|
+
<clipPath id="litha-verre-clip">
|
|
11
|
+
<path d="M93 136 L147 136 L141 188 Q140 190 137 190 L103 190 Q100 190 99 188 Z" />
|
|
12
|
+
</clipPath>
|
|
13
|
+
<linearGradient id="litha-corps" x1="0" y1="0" x2="1" y2="1">
|
|
14
|
+
<stop offset="0%" stop-color="#3c3733" />
|
|
15
|
+
<stop offset="100%" stop-color="#1f1c1a" />
|
|
16
|
+
</linearGradient>
|
|
17
|
+
<linearGradient id="litha-metal" x1="0" y1="0" x2="1" y2="0">
|
|
18
|
+
<stop offset="0%" stop-color="#9e958c" />
|
|
19
|
+
<stop offset="50%" stop-color="#e5ded5" />
|
|
20
|
+
<stop offset="100%" stop-color="#8c837a" />
|
|
21
|
+
</linearGradient>
|
|
22
|
+
</defs>
|
|
23
|
+
|
|
24
|
+
<!-- Grains de café décoratifs -->
|
|
25
|
+
<ellipse class="grain grain-1" cx="30" cy="148" rx="6" ry="4" transform="rotate(-25 30 148)" />
|
|
26
|
+
<ellipse class="grain grain-2" cx="210" cy="136" rx="6" ry="4" transform="rotate(20 210 136)" />
|
|
27
|
+
|
|
28
|
+
<!-- Châssis arrière de la machine -->
|
|
29
|
+
<rect x="52" y="64" width="136" height="132" rx="10" fill="#171513" />
|
|
30
|
+
<rect x="64" y="74" width="112" height="118" rx="6" fill="#231f1d" />
|
|
31
|
+
|
|
32
|
+
<!-- Tête de la machine -->
|
|
33
|
+
<rect x="38" y="14" width="164" height="60" rx="14" fill="url(#litha-corps)" stroke="rgba(255,255,255,0.12)" stroke-width="1" />
|
|
34
|
+
<rect x="48" y="10" width="144" height="8" rx="4" fill="url(#litha-metal)" />
|
|
35
|
+
|
|
36
|
+
<!-- Bandeau vert Litha Espresso + manomètre + voyant -->
|
|
37
|
+
<rect x="56" y="44" width="128" height="4" rx="2" fill="#2e7d5b" />
|
|
38
|
+
<circle cx="120" cy="30" r="9" fill="#141211" stroke="#c89b6e" stroke-width="1.8" />
|
|
39
|
+
<line class="aiguille" x1="120" y1="30" x2="125" y2="25" stroke="#3ea377" stroke-width="1.6" stroke-linecap="round" />
|
|
40
|
+
<circle class="voyant" cx="172" cy="30" r="4.5" />
|
|
41
|
+
|
|
42
|
+
<!-- Porte-filtre et double bec -->
|
|
43
|
+
<rect x="96" y="74" width="48" height="14" rx="4" fill="url(#litha-metal)" />
|
|
44
|
+
<rect x="142" y="77" width="44" height="7" rx="3.5" fill="#12100f" stroke="#c89b6e" stroke-width="1" />
|
|
45
|
+
<path d="M113 88 L113 99 Q113 103 116 104 L116 108 M127 88 L127 99 Q127 103 124 104 L124 108" stroke="url(#litha-metal)" stroke-width="3" fill="none" stroke-linecap="round" />
|
|
46
|
+
|
|
47
|
+
<!-- Filet d'écoulement du café -->
|
|
48
|
+
<g class="filet">
|
|
49
|
+
<line class="filet-jet" x1="116" y1="109" x2="116" y2="188" />
|
|
50
|
+
<line class="filet-jet" x1="124" y1="109" x2="124" y2="188" />
|
|
51
|
+
<line class="filet-reflet" x1="116" y1="109" x2="116" y2="188" />
|
|
52
|
+
<line class="filet-reflet" x1="124" y1="109" x2="124" y2="188" />
|
|
53
|
+
</g>
|
|
54
|
+
|
|
55
|
+
<!-- Vapeur au-dessus du verre -->
|
|
56
|
+
<g class="vapeur">
|
|
57
|
+
<path class="vapeur-brin vapeur-1" d="M104 128 Q100 120 105 113" />
|
|
58
|
+
<path class="vapeur-brin vapeur-2" d="M120 126 Q125 118 119 110" />
|
|
59
|
+
<path class="vapeur-brin vapeur-3" d="M136 128 Q140 120 135 113" />
|
|
60
|
+
</g>
|
|
61
|
+
|
|
62
|
+
<!-- Café et mousse (crema) dans le verre -->
|
|
63
|
+
<g clip-path="url(#litha-verre-clip)">
|
|
64
|
+
<g class="liquide">
|
|
65
|
+
<rect class="cafe" x="88" y="138" width="64" height="54" />
|
|
66
|
+
<rect class="mousse" x="88" y="134" width="64" height="6" rx="2" />
|
|
67
|
+
</g>
|
|
68
|
+
</g>
|
|
69
|
+
|
|
70
|
+
<!-- Contour du verre et reflet -->
|
|
71
|
+
<path d="M90 134 L150 134 L143 189 Q142 192 138 192 L102 192 Q98 192 97 189 Z" fill="rgba(255,255,255,0.08)" stroke="rgba(43,29,20,0.45)" stroke-width="2" stroke-linejoin="round" />
|
|
72
|
+
<path d="M97 141 L101 184" stroke="rgba(255,255,255,0.45)" stroke-width="2" stroke-linecap="round" />
|
|
73
|
+
|
|
74
|
+
<!-- Bac d'égouttage -->
|
|
75
|
+
<rect x="54" y="193" width="132" height="11" rx="4" fill="url(#litha-metal)" />
|
|
76
|
+
<rect x="66" y="193" width="108" height="3" fill="#2a2623" />
|
|
77
|
+
</svg>
|
|
78
|
+
`;
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
(function () {
|
|
82
|
+
"use strict";
|
|
83
|
+
|
|
84
|
+
const DUREE_CHAUFFE = 1200;
|
|
85
|
+
const DUREE_PRET = 1600;
|
|
86
|
+
const VITESSE_MAX = 55;
|
|
87
|
+
const PLAFOND_AUTO = 90;
|
|
88
|
+
|
|
89
|
+
const MESSAGES = {
|
|
90
|
+
chauffe: "La machine chauffe…",
|
|
91
|
+
coule: "Le café coule…",
|
|
92
|
+
remplit: "Le verre se remplit…",
|
|
93
|
+
presque: "Encore quelques gouttes…",
|
|
94
|
+
pret: "Votre café est prêt !",
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// Affiché tant que machine.js n'existe pas.
|
|
98
|
+
const DESSIN_PROVISOIRE = `
|
|
99
|
+
<svg class="provisoire" viewBox="0 0 200 200">
|
|
100
|
+
<rect class="filet" x="97" y="20" width="6" height="156"/>
|
|
101
|
+
<rect class="cafe" x="62" y="82" width="76" height="96"/>
|
|
102
|
+
<path class="verre" d="M60 70 V180 H140 V70"/>
|
|
103
|
+
</svg>`;
|
|
104
|
+
|
|
105
|
+
const GABARIT = `
|
|
106
|
+
<div class="litha-entete">
|
|
107
|
+
<h2 id="litha-titre"></h2>
|
|
108
|
+
<button type="button" class="litha-fermer" aria-label="Fermer">×</button>
|
|
109
|
+
</div>
|
|
110
|
+
<div class="litha-scene" aria-hidden="true"></div>
|
|
111
|
+
<div class="litha-jauge" role="progressbar" aria-label="Préparation du café"
|
|
112
|
+
aria-valuemin="0" aria-valuemax="100"><span></span></div>
|
|
113
|
+
<p class="litha-pourcent" aria-hidden="true"></p>
|
|
114
|
+
<p class="litha-message" id="litha-message" aria-live="polite"></p>`;
|
|
115
|
+
|
|
116
|
+
let enCours = null;
|
|
117
|
+
|
|
118
|
+
function cleMessage(etat, pourcent) {
|
|
119
|
+
if (etat !== "extraction") return etat;
|
|
120
|
+
if (pourcent < 50) return "coule";
|
|
121
|
+
if (pourcent < 90) return "remplit";
|
|
122
|
+
return "presque";
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function open(options = {}) {
|
|
126
|
+
if (enCours) return enCours;
|
|
127
|
+
|
|
128
|
+
const messages = { ...MESSAGES, ...options.messages };
|
|
129
|
+
const fermable = options.fermable !== false;
|
|
130
|
+
const delaiFermeture = Number.isFinite(options.delaiFermeture)
|
|
131
|
+
? Math.max(0, options.delaiFermeture)
|
|
132
|
+
: DUREE_PRET;
|
|
133
|
+
|
|
134
|
+
const popup = document.createElement("dialog");
|
|
135
|
+
popup.className = "litha";
|
|
136
|
+
popup.setAttribute("aria-labelledby", "litha-titre");
|
|
137
|
+
popup.setAttribute("aria-describedby", "litha-message");
|
|
138
|
+
popup.innerHTML = GABARIT;
|
|
139
|
+
popup.querySelector("h2").textContent = options.titre ?? "Litha Espresso";
|
|
140
|
+
popup.querySelector(".litha-scene").innerHTML = window.LithaMachine || DESSIN_PROVISOIRE;
|
|
141
|
+
|
|
142
|
+
const bouton = popup.querySelector(".litha-fermer");
|
|
143
|
+
const jauge = popup.querySelector(".litha-jauge");
|
|
144
|
+
const texte = popup.querySelector(".litha-pourcent");
|
|
145
|
+
const message = popup.querySelector(".litha-message");
|
|
146
|
+
|
|
147
|
+
let etat = "chauffe";
|
|
148
|
+
let mesure = false; // true dès que la page donne une vraie progression
|
|
149
|
+
let cible = null;
|
|
150
|
+
let affiche = 0;
|
|
151
|
+
let ferme = false;
|
|
152
|
+
let image = 0;
|
|
153
|
+
let minuterie = 0;
|
|
154
|
+
let resoudre;
|
|
155
|
+
const closed = new Promise((resolve) => { resoudre = resolve; });
|
|
156
|
+
|
|
157
|
+
const debut = performance.now();
|
|
158
|
+
let precedent = debut;
|
|
159
|
+
|
|
160
|
+
function dessiner() {
|
|
161
|
+
const pourcent = Math.floor(affiche);
|
|
162
|
+
popup.dataset.etat = etat;
|
|
163
|
+
popup.dataset.mode = mesure ? "mesure" : "indetermine";
|
|
164
|
+
popup.style.setProperty("--progress", (affiche / 100).toFixed(4));
|
|
165
|
+
// Durée inconnue : pas de valeur à annoncer tant que ce n'est pas prêt.
|
|
166
|
+
if (mesure || etat === "pret") jauge.setAttribute("aria-valuenow", pourcent);
|
|
167
|
+
else jauge.removeAttribute("aria-valuenow");
|
|
168
|
+
texte.textContent = mesure ? pourcent + " %" : "";
|
|
169
|
+
const nouveau = messages[cleMessage(etat, pourcent)];
|
|
170
|
+
if (message.textContent !== nouveau) message.textContent = nouveau;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function avancer() {
|
|
174
|
+
const maintenant = performance.now();
|
|
175
|
+
const dt = Math.min((maintenant - precedent) / 1000, 0.1);
|
|
176
|
+
precedent = maintenant;
|
|
177
|
+
|
|
178
|
+
if (etat === "chauffe" && maintenant - debut >= DUREE_CHAUFFE) etat = "extraction";
|
|
179
|
+
|
|
180
|
+
if (etat === "extraction") {
|
|
181
|
+
if (cible === null) {
|
|
182
|
+
affiche += (PLAFOND_AUTO - affiche) * 0.35 * dt;
|
|
183
|
+
} else {
|
|
184
|
+
affiche = Math.max(affiche, Math.min(cible, affiche + VITESSE_MAX * dt));
|
|
185
|
+
}
|
|
186
|
+
if (affiche >= 100) {
|
|
187
|
+
affiche = 100;
|
|
188
|
+
etat = "pret";
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
dessiner();
|
|
193
|
+
|
|
194
|
+
if (etat === "pret") minuterie = setTimeout(close, delaiFermeture);
|
|
195
|
+
else image = requestAnimationFrame(avancer);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function setProgress(pourcentage) {
|
|
199
|
+
const valeur = Number(pourcentage);
|
|
200
|
+
if (!Number.isFinite(valeur) || cible === 100) return;
|
|
201
|
+
cible = Math.min(100, Math.max(0, valeur));
|
|
202
|
+
if (!mesure) {
|
|
203
|
+
mesure = true;
|
|
204
|
+
affiche = Math.min(affiche, cible);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function finish() {
|
|
209
|
+
cible = 100;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function close() {
|
|
213
|
+
if (ferme) return;
|
|
214
|
+
ferme = true;
|
|
215
|
+
cancelAnimationFrame(image);
|
|
216
|
+
clearTimeout(minuterie);
|
|
217
|
+
if (popup.open) popup.close();
|
|
218
|
+
popup.remove();
|
|
219
|
+
enCours = null;
|
|
220
|
+
resoudre(etat === "pret");
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (fermable) {
|
|
224
|
+
bouton.addEventListener("click", close);
|
|
225
|
+
} else {
|
|
226
|
+
bouton.remove();
|
|
227
|
+
popup.setAttribute("closedby", "none");
|
|
228
|
+
popup.addEventListener("cancel", (e) => e.preventDefault());
|
|
229
|
+
popup.addEventListener("keydown", (e) => {
|
|
230
|
+
if (e.key === "Escape") e.preventDefault();
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
popup.addEventListener("close", close);
|
|
234
|
+
|
|
235
|
+
document.body.append(popup);
|
|
236
|
+
dessiner();
|
|
237
|
+
popup.showModal();
|
|
238
|
+
image = requestAnimationFrame(avancer);
|
|
239
|
+
|
|
240
|
+
enCours = { setProgress, finish, close, closed };
|
|
241
|
+
return enCours;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
window.LithaLoader = { open };
|
|
245
|
+
})();
|
|
246
|
+
|
|
247
|
+
}
|
|
248
|
+
export default globalThis.LithaLoader;
|
package/package.json
CHANGED
|
@@ -1,6 +1,30 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@xiwawell/litha-espresso-loader",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Loader Litha Espresso : une popup où une machine à café animée remplit un verre",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"loader",
|
|
7
|
+
"spinner",
|
|
8
|
+
"modal",
|
|
9
|
+
"coffee",
|
|
10
|
+
"accessibility"
|
|
11
|
+
],
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/Bouncii/NDI_2026.git",
|
|
15
|
+
"directory": "litha-loader"
|
|
16
|
+
},
|
|
17
|
+
"exports": {
|
|
18
|
+
".": "./dist/litha-loader.mjs",
|
|
19
|
+
"./global": "./dist/litha-loader.js"
|
|
20
|
+
},
|
|
21
|
+
"unpkg": "dist/litha-loader.js",
|
|
22
|
+
"jsdelivr": "dist/litha-loader.js",
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"prepack": "node build.js"
|
|
28
|
+
},
|
|
29
|
+
"license": "MIT"
|
|
30
|
+
}
|