Changement du code pour une nouvelle version en test

This commit is contained in:
serveur
2026-10-17 19:20:00 +02:00
parent 9dba07bc54
commit 044cd54f36
8 changed files with 909 additions and 264 deletions
+608
View File
@@ -0,0 +1,608 @@
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
<meta name="theme-color" content="#8c2f2f" />
<title>Calculateur d'épices</title>
<link rel="stylesheet" href="assets/menu.css" />
<style>
:root {
--bg: #f6f1ea;
--card: #ffffff;
--ink: #2b2420;
--muted: #7a6e65;
--line: #e6ddd2;
--accent: #8c2f2f;
--accent-dark: #742626;
--accent-soft: #f7e8e5;
--warn: #b35a00;
--warn-soft: #fff1e0;
--radius: 16px;
--shadow: 0 1px 2px rgba(43, 36, 32, 0.06), 0 6px 18px rgba(43, 36, 32, 0.06);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
body {
margin: 0;
background: var(--bg);
color: var(--ink);
font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
line-height: 1.35;
padding-bottom: env(safe-area-inset-bottom);
}
/* ---------- Récapitulatif dans la barre du haut (le reste : assets/menu.css) ---------- */
.summary { display: flex; gap: 16px; text-align: right; }
.summary .lbl { display: block; font-size: 0.68rem; opacity: 0.8; text-transform: uppercase; letter-spacing: 0.06em; }
.summary b { font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.wrap { max-width: 760px; margin: 0 auto; padding: 14px 14px 40px; }
/* ---------- Cartes génériques ---------- */
.card {
background: var(--card);
border-radius: var(--radius);
box-shadow: var(--shadow);
padding: 16px;
margin-bottom: 14px;
}
.card h2 {
margin: 0 0 12px;
font-size: 0.78rem;
text-transform: uppercase;
letter-spacing: 0.08em;
color: var(--muted);
}
.field label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 5px; }
/* 16px minimum : évite le zoom automatique d'iOS au focus */
input[type="text"], input[type="number"] {
width: 100%;
height: 48px;
font: inherit;
font-size: 1.1rem;
font-variant-numeric: tabular-nums;
padding: 0 12px;
border: 1.5px solid var(--line);
border-radius: 12px;
background: #fffdfa;
color: var(--ink);
}
input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(140, 47, 47, 0.18); }
/* ---------- Rendement ---------- */
.yield { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.yield .field { grid-column: 1 / -1; }
.stat { background: #fbf7f1; border-radius: 12px; padding: 10px 12px; }
.stat .label { font-size: 0.75rem; color: var(--muted); }
.stat .value { font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat.big .value { color: var(--accent); }
/* ---------- Réglages repliables ---------- */
details.card { padding: 0; }
details summary {
list-style: none;
display: flex;
align-items: center;
justify-content: space-between;
min-height: 52px;
padding: 0 16px;
font-weight: 600;
cursor: pointer;
}
details summary::-webkit-details-marker { display: none; }
details summary::after { content: "▾"; color: var(--muted); transition: transform 0.15s; }
details[open] summary::after { transform: rotate(180deg); }
details .settings { padding: 0 16px 16px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
details .hint { grid-column: 1 / -1; margin: 0; font-size: 0.8rem; color: var(--muted); }
/* ---------- Interrupteurs (couenne, filtre) ---------- */
.switch {
position: relative;
display: inline-flex;
align-items: center;
gap: 8px;
min-height: 44px;
padding: 0 14px 0 10px;
border: 1.5px solid var(--line);
border-radius: 999px;
background: #fff;
font-weight: 600;
font-size: 0.92rem;
cursor: pointer;
user-select: none;
}
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 38px; height: 22px; border-radius: 999px; background: #d9cfc3; position: relative; transition: background 0.15s; flex: none; }
.switch .track::after {
content: "";
position: absolute;
top: 2px; left: 2px;
width: 18px; height: 18px;
border-radius: 50%;
background: #fff;
transition: transform 0.15s;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}
.switch:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch:has(input:focus-visible) { box-shadow: 0 0 0 3px rgba(140, 47, 47, 0.25); }
.filterbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 4px 0 12px; flex-wrap: wrap; }
.count { font-size: 0.9rem; color: var(--muted); }
.count b { color: var(--accent); }
/* ---------- Cartes bassines ---------- */
.bassines { display: grid; gap: 12px; }
.bassine {
background: var(--card);
border-radius: var(--radius);
box-shadow: var(--shadow);
border: 2px solid transparent;
padding: 14px;
}
.bassine.filled { border-color: var(--accent); background: #fffaf9; }
.bassine.warn { border-color: var(--warn); background: var(--warn-soft); }
.b-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.b-name { font-weight: 700; font-size: 1.05rem; }
.b-tare { font-size: 0.8rem; color: var(--muted); }
.b-input label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 4px; }
.input-wrap { position: relative; }
.input-wrap input { height: 56px; font-size: 1.5rem; font-weight: 600; padding-right: 52px; }
.clear {
position: absolute;
right: 6px; top: 6px;
width: 44px; height: 44px;
border: none;
border-radius: 10px;
background: transparent;
color: var(--muted);
font-size: 1.1rem;
cursor: pointer;
}
.clear:active { background: var(--line); }
.input-wrap input:placeholder-shown + .clear { display: none; }
.b-results { margin-top: 12px; }
.b-net { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8px; }
.b-net .lbl { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.b-net .val { font-size: 1.7rem; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
.b-net .unit { font-size: 0.9rem; font-weight: 600; color: var(--muted); margin-left: 3px; }
.warn .b-net .val { color: var(--warn); }
.tiles { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.tile { grid-column: span 2; background: #fbf7f1; border-radius: 10px; padding: 8px 6px; text-align: center; }
.tile:nth-child(n+4) { grid-column: span 3; }
.tile .t-lbl { display: block; font-size: 0.7rem; color: var(--muted); }
.tile .t-val { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 1rem; }
.b-warn { margin: 10px 0 0; font-size: 0.85rem; color: var(--warn); font-weight: 600; }
/* ---------- Totaux ---------- */
.totals { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.totals .stat:first-child { grid-column: 1 / -1; background: var(--accent-soft); }
.totals .unit { font-size: 0.8rem; font-weight: 400; color: var(--muted); }
/* ---------- Actions ---------- */
.actions { display: grid; gap: 10px; }
.btn {
font: inherit;
font-weight: 700;
min-height: 52px;
border-radius: 14px;
border: 1.5px solid var(--line);
background: var(--card);
color: var(--ink);
cursor: pointer;
}
.btn:active { transform: scale(0.99); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:active { background: var(--accent-dark); }
/* ---------- Grands écrans : deux colonnes ---------- */
@media (min-width: 900px) {
.wrap { max-width: 1000px; }
.bassines { grid-template-columns: 1fr 1fr; }
.actions { grid-template-columns: 1fr 1fr; }
}
/* ---------- Impression : uniquement ce qui a été pesé ---------- */
@media print {
body { background: #fff; }
.topbar, .no-print, .clear { display: none !important; }
.card, .bassine { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
.bassine:not(.filled) { display: none; }
.bassines { grid-template-columns: 1fr 1fr; }
input { border: none; background: none; }
details { display: none; }
}
</style>
</head>
<body>
<header class="topbar">
<div class="topbar-row">
<h1>Calcul des épices</h1>
<div class="summary" aria-live="polite">
<div><span class="lbl">Viande nette</span><b id="Resume_Net">0.000</b> kg</div>
<div><span class="lbl">Rendement</span><b id="Resume_Rendement">0 %</b></div>
</div>
</div>
<nav class="menu" aria-label="Menu principal">
<a href="index.html" aria-current="page">Calculateur</a>
<a href="todo.html">To-do</a>
</nav>
</header>
<main class="wrap">
<section class="card">
<h2>Rendement</h2>
<div class="yield">
<div class="field">
<label for="Total_Achete">Total acheté (kg)</label>
<input type="number" id="Total_Achete" step="any" inputmode="decimal" placeholder="0" />
</div>
<div class="stat">
<div class="label">Total assaisonné (kg)</div>
<div class="value" id="Total_Assaisonne">0.000</div>
</div>
<div class="stat big">
<div class="label">Rendement</div>
<div class="value" id="Rendement">0 %</div>
</div>
</div>
</section>
<details class="card no-print">
<summary>Réglages (planche et proportions)</summary>
<div class="settings" id="settings"></div>
</details>
<div class="filterbar no-print">
<label class="switch">
<input type="checkbox" id="Filtre_pesees" />
<span class="track"></span>
<span>Seulement les pesées</span>
</label>
<span class="count"><b id="Compteur">0</b> / <span id="CompteurMax">0</span> pesées</span>
</div>
<section class="bassines" id="bassines"></section>
<section class="card" style="margin-top: 14px">
<h2>Totaux</h2>
<div class="totals" id="totals"></div>
</section>
<div class="actions no-print">
<button type="button" class="btn primary" id="btnPrint">Imprimer la page</button>
<button type="button" class="btn" id="btnReset">Vider les pesées</button>
</div>
</main>
<script>
// ---------- Données ----------
const bassines = [
{ nom: "Niagara", tare: 6.5 },
{ nom: "Manu Chao", tare: 2.7 },
{ nom: "Kamini", tare: 2.7 },
{ nom: "Tina", tare: 2.7 },
{ nom: "Garou", tare: 6.0 },
{ nom: "Johnny", tare: 2.7 },
{ nom: "Vanessa", tare: 1.7 },
{ nom: "Joséphine", tare: 4.9 },
{ nom: "Céline", tare: 6.0 },
{ nom: "Dalida", tare: 2.5 },
{ nom: "Florent", tare: 2.7 },
{ nom: "Petite bassine ronde verte (JM)", tare: 1.7 },
{ nom: "Grande bassine verte", tare: 2.7 },
{ nom: "Caisse grise", tare: 2.45 },
{ nom: "Caisse verte", tare: 2.6 },
];
const reglages = [
{ id: "Poids_planche", label: "Poids de la planche (kg)", defaut: 4.4 },
{ id: "Prop_sel", label: "Sel (kg)", defaut: 0.028 },
{ id: "Prop_poivre", label: "Poivre (g)", defaut: 2 },
{ id: "Prop_muscade", label: "Muscade (g)", defaut: 1 },
{ id: "Prop_ail", label: "Ail (g)", defaut: 2 },
];
// Colonnes calculées : clé, libellé, unité des totaux
const colonnes = [
{ cle: "net", titre: "Viande nette", unite: "kg", totalId: "Total_Net" },
{ cle: "sel", titre: "Sel", unite: "kg", totalId: "Total_Sel" },
{ cle: "poivre", titre: "Poivre", unite: "g", totalId: "Total_Poivre" },
{ cle: "concasse", titre: "Poivre concassé", unite: "g", totalId: "Total_Poivre_Concasse" },
{ cle: "muscade", titre: "Muscade", unite: "g", totalId: "Total_Muscade" },
{ cle: "ail", titre: "Ail", unite: "g", totalId: "Total_Ail" },
];
// ---------- Utilitaires ----------
const $ = (id) => document.getElementById(id);
// Accepte la virgule comme séparateur décimal
const nombre = (valeur) => parseFloat(String(valeur).replace(",", ".")) || 0;
const valeurChamp = (id) => nombre($(id).value);
// ---------- Construction de l'interface ----------
function construireReglages() {
$("settings").innerHTML =
reglages
.map(
(r) => `
<div class="field">
<label for="${r.id}">${r.label}</label>
<input type="text" id="${r.id}" inputmode="decimal" value="${r.defaut}" />
</div>`,
)
.join("") + `<p class="hint">Les proportions s'appliquent par kg de viande nette.</p>`;
}
function construireTotaux() {
$("totals").innerHTML = colonnes
.map(
(c) => `
<div class="stat">
<div class="label">${c.titre} <span class="unit">(${c.unite})</span></div>
<div class="value" id="${c.totalId}">0.000</div>
</div>`,
)
.join("");
}
function construireBassines() {
const tuiles = [
["sel", "Sel (kg)"],
["poivre", "Poivre (g)"],
["concasse", "Concassé (g)"],
["muscade", "Muscade (g)"],
["ail", "Ail (g)"],
];
$("bassines").innerHTML = bassines
.map((b, i) => {
const n = i + 1;
return `
<article class="bassine" id="Bassine_${n}">
<div class="b-head">
<div>
<div class="b-name">${b.nom}</div>
<div class="b-tare">Tare ${b.tare.toFixed(3)} kg</div>
</div>
<label class="switch">
<input type="checkbox" id="isCouenne${n}" />
<span class="track"></span>
<span>Couenne</span>
</label>
</div>
<div class="b-input">
<label for="Poids_bassine_${n}">Poids brut (kg)</label>
<div class="input-wrap">
<input type="text" class="brut" id="Poids_bassine_${n}" inputmode="decimal"
enterkeyhint="next" autocomplete="off" placeholder="0.0" />
<button type="button" class="clear" aria-label="Effacer ${b.nom}">✕</button>
</div>
</div>
<div class="b-results" data-zone="resultats" hidden>
<div class="b-net">
<span class="lbl">Viande nette</span>
<span><span class="val" data-cle="net"></span><span class="unit">kg</span></span>
</div>
<div class="tiles">
${tuiles
.map(
([cle, label]) => `
<div class="tile"><span class="t-lbl">${label}</span><span class="t-val" data-cle="${cle}"></span></div>`,
)
.join("")}
</div>
</div>
<p class="b-warn" data-zone="alerte" hidden>Net négatif ou nul : vérifie la pesée.</p>
</article>`;
})
.join("");
}
// ---------- Calculs ----------
function calculer() {
const planche = valeurChamp("Poids_planche");
const propSel = valeurChamp("Prop_sel");
const propPoivre = valeurChamp("Prop_poivre");
const propMuscade = valeurChamp("Prop_muscade");
const propAil = valeurChamp("Prop_ail");
const filtre = $("Filtre_pesees").checked;
const totaux = { net: 0, sel: 0, poivre: 0, concasse: 0, muscade: 0, ail: 0 };
let nbPesees = 0;
bassines.forEach((b, i) => {
const n = i + 1;
const carte = $("Bassine_" + n);
const brut = valeurChamp("Poids_bassine_" + n);
const cellule = (cle) => carte.querySelector(`[data-cle="${cle}"]`);
const zone = (nom) => carte.querySelector(`[data-zone="${nom}"]`);
carte.classList.toggle("filled", !!brut);
zone("resultats").hidden = !brut;
// En mode « seulement les pesées », on garde visible la carte en cours de saisie
const enSaisie = carte.contains(document.activeElement);
carte.hidden = filtre && !brut && !enSaisie;
if (!brut) {
Object.keys(totaux).forEach((cle) => (cellule(cle).textContent = ""));
carte.classList.remove("warn");
zone("alerte").hidden = true;
return;
}
nbPesees++;
// Valeurs arrondies à 3 décimales, comme avant
const net = parseFloat((brut - b.tare - planche).toFixed(3));
const couenne = $("isCouenne" + n).checked;
const resultats = {
net,
sel: parseFloat((net * (couenne ? propSel / 2 : propSel)).toFixed(3)),
poivre: parseFloat((net * propPoivre * 0.6).toFixed(3)),
concasse: parseFloat((net * propPoivre * 0.4).toFixed(3)),
muscade: parseFloat((net * propMuscade).toFixed(3)),
ail: parseFloat((net * propAil).toFixed(3)),
};
Object.entries(resultats).forEach(([cle, v]) => {
cellule(cle).textContent = v.toFixed(3);
totaux[cle] += v;
});
const negatif = net <= 0;
carte.classList.toggle("warn", negatif);
zone("alerte").hidden = !negatif;
});
colonnes.forEach((c) => ($(c.totalId).textContent = totaux[c.cle].toFixed(3)));
$("Compteur").textContent = nbPesees;
calculerTotalAssaisonne(totaux);
// Récapitulatif de la barre du haut
$("Resume_Net").textContent = $("Total_Net").textContent;
$("Resume_Rendement").textContent = $("Rendement").textContent;
}
// Rendement : formule inchangée (net total / total acheté × 100)
function calculerTotalAssaisonne(totaux) {
const totalNet = parseFloat(totaux.net.toFixed(3));
const totalSel = parseFloat(totaux.sel.toFixed(3));
const totalPoivre = parseFloat(totaux.poivre.toFixed(3));
const totalPoivreConcasse = parseFloat(totaux.concasse.toFixed(3));
const totalMuscade = parseFloat(totaux.muscade.toFixed(3));
const totalAil = parseFloat(totaux.ail.toFixed(3));
const totalAssaisonne =
totalNet +
totalSel +
totalPoivre / 1000 +
totalPoivreConcasse / 1000 +
totalMuscade / 1000 +
totalAil / 1000;
$("Total_Assaisonne").textContent = totalAssaisonne.toFixed(3);
const totalAchete = valeurChamp("Total_Achete");
if (totalAchete > 0) {
const rendement = (totalNet / totalAchete) * 100;
$("Rendement").textContent = rendement.toFixed(3) + " %";
} else {
$("Rendement").textContent = "0 %";
}
}
// ---------- Sauvegarde locale (48 h) ----------
const STORAGE_KEY = "calculateurEpices";
const MAX_AGE = 48 * 60 * 60 * 1000; // 48 h
function sauvegarder() {
try {
const values = {};
document.querySelectorAll("input").forEach((input) => {
values[input.id] = input.type === "checkbox" ? input.checked : input.value;
});
localStorage.setItem(STORAGE_KEY, JSON.stringify({ timestamp: Date.now(), values }));
} catch (e) {
/* stockage indisponible : on ignore */
}
}
function restaurer() {
try {
const saved = JSON.parse(localStorage.getItem(STORAGE_KEY));
if (saved && Date.now() - saved.timestamp < MAX_AGE) {
for (const [id, value] of Object.entries(saved.values)) {
const input = $(id);
if (!input) continue;
if (input.type === "checkbox") input.checked = value;
else input.value = value;
}
} else {
localStorage.removeItem(STORAGE_KEY);
}
} catch (e) {
/* données illisibles : on repart de zéro */
}
}
// ---------- Démarrage ----------
function demarrer() {
construireReglages();
construireTotaux();
construireBassines();
$("CompteurMax").textContent = bassines.length;
restaurer();
calculer();
const maj = () => {
calculer();
sauvegarder();
};
document.body.addEventListener("input", maj);
document.body.addEventListener("change", maj);
// Sélectionne le contenu au focus : on remplace une valeur d'un seul geste
document.body.addEventListener("focusin", (e) => {
if (e.target.matches('input[type="text"], input[type="number"]')) {
setTimeout(() => e.target.select(), 0);
}
});
// « Entrée / Suivant » passe à la bassine suivante
document.body.addEventListener("keydown", (e) => {
if (e.key !== "Enter" || !e.target.matches(".brut")) return;
e.preventDefault();
const champs = [...document.querySelectorAll(".brut")].filter((c) => !c.closest("[hidden]"));
const suivant = champs[champs.indexOf(e.target) + 1];
if (suivant) {
suivant.focus();
suivant.scrollIntoView({ block: "center", behavior: "smooth" });
} else {
e.target.blur();
}
});
// Bouton ✕ : efface la pesée de la bassine
document.body.addEventListener("click", (e) => {
const bouton = e.target.closest(".clear");
if (!bouton) return;
const champ = bouton.previousElementSibling;
champ.value = "";
champ.dispatchEvent(new Event("input", { bubbles: true }));
champ.focus();
});
$("btnPrint").addEventListener("click", () => window.print());
$("btnReset").addEventListener("click", () => {
if (!confirm("Vider toutes les pesées et le total acheté ? (les réglages sont conservés)")) return;
bassines.forEach((_, i) => {
$("Poids_bassine_" + (i + 1)).value = "";
$("isCouenne" + (i + 1)).checked = false;
});
$("Total_Achete").value = "";
maj();
window.scrollTo({ top: 0, behavior: "smooth" });
});
}
demarrer();
</script>
</body>
</html>