Charge par série : pyramide, montée en charge gardée pour la fois suivante (R2)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Pierre MARTIN
2026-11-23 01:45:28 +01:00
co-authored by Claude Opus 5.5
parent 06a00ab3bb
commit 615348fed3
23 changed files with 406 additions and 33 deletions
+62 -7
View File
@@ -11,7 +11,7 @@ import { TRACKING_MODES, EFFORTS } from "../domain/vocabulary.js";
import { resolveExercise, trackingFor } from "../domain/program.js";
import { EFFORT_LABELS, TRACKING_LABELS } from "./labels.js";
import { kg, parseAmount, restLabel } from "./format.js";
import { chronoSteps, doneCount, draftExercise, markSet, proposedReps, targetLabel, targetReps, usesLoad, usesTime } from "./session-draft.js";
import { chronoSteps, doneCount, draftExercise, markSet, perSetLoad, proposedReps, setLoadAt, setPerSetLoad, targetLabel, targetReps, topLoad, usesLoad, usesTime, workingLoadData } from "./session-draft.js";
import { progressionAdvice } from "../domain/progression.js";
/**
@@ -39,6 +39,7 @@ export function exerciseCard(o) {
const sub = h("span", { class: "exercise__sub" });
const count = h("span", { class: "exercise__count" });
const objective = h("span", { class: "objective__value" });
const loadsLine = h("span", { class: "num" });
const work = h("div", { class: "work" });
const tracking = h("div", { class: "segmented", role: "group", "aria-label": "Ce que je suis" });
@@ -54,14 +55,28 @@ export function exerciseCard(o) {
};
const refreshLabels = () => {
const load = usesLoad(ex.tracking) && ex.loadKg !== null ? ` · ${kg(ex.loadKg)} kg` : "";
const load = perSetLoad(ex) ? ` · ${loadsText()} kg` : usesLoad(ex.tracking) && ex.loadKg !== null ? ` · ${kg(ex.loadKg)} kg` : "";
sub.textContent = `${targetLabel(ex)}${load} · repos ${restLabel(ex.rest)}`;
count.textContent = `${doneCount(ex)}/${ex.sets}`;
count.classList.toggle("exercise__count--done", doneCount(ex) === ex.sets);
objective.textContent = targetLabel(ex);
loadsLine.textContent = `${loadsText()} kg`;
paintSwap();
};
/** Les charges des séries, de la première à la dernière : « 40 → 50 → 60 ». */
const loadsText = () => {
const loads = Array.from({ length: ex.sets }, (_, i) => setLoadAt(ex, i));
return loads.every((v) => v === null) ? "—" : loads.map((v) => (v === null ? "—" : kg(v))).join(" → ");
};
/** Garde les charges par série pour la fois suivante (WorkingLoadSet). */
const saveLoads = () => {
const data = workingLoadData(ex);
const saved = store.getState().workingLoads[ex.key];
if (saved?.loadKg !== data.loadKg || JSON.stringify(saved?.setsKg ?? null) !== JSON.stringify(data.setsKg ?? null))
store.dispatch("WorkingLoadSet", data);
};
const changed = () => {
refreshLabels();
o.onChange();
@@ -85,11 +100,13 @@ export function exerciseCard(o) {
b.dataset.effort = s?.effort ?? "";
replace(b,
h("span", { class: "set-btn__n" }, s === null ? String(i + 1) : typeof s.reps === "number" ? String(s.reps) : "✓"),
s?.effort ? h("span", { class: "set-btn__effort" }, EFFORT_LABELS[s.effort].short) : null);
s?.effort ? h("span", { class: "set-btn__effort" }, EFFORT_LABELS[s.effort].short) : null,
perSetLoad(ex) && setLoadAt(ex, i) !== null ? h("span", { class: "set-btn__kg" }, `${kg(/** @type {number} */ (setLoadAt(ex, i)))} kg`) : null);
const what = s === null ? "à faire"
: [typeof s.reps === "number" ? `${s.reps} répétitions` : "faite", s.effort ? EFFORT_LABELS[s.effort].label.toLowerCase() : null]
.filter(Boolean).join(", ");
b.setAttribute("aria-label", `Série ${i + 1} : ${what}`);
const at = perSetLoad(ex) && setLoadAt(ex, i) !== null ? ` à ${kg(/** @type {number} */ (setLoadAt(ex, i)))} kg` : "";
b.setAttribute("aria-label", `Série ${i + 1}${at} : ${what}`);
b.setAttribute("aria-expanded", String(openPanel === i));
});
};
@@ -110,10 +127,31 @@ export function exerciseCard(o) {
const range = targetReps(ex.reps);
const value = h("output", { class: "stepper__value", "aria-live": "polite" }, String(reps));
const step = (/** @type {number} */ d) => { reps = Math.max(0, reps + d); value.textContent = String(reps); };
const ownReps = ex.setReps?.[i] ? targetReps(ex.setReps[i]) : null;
const goal = ownReps ?? range;
// Charge par série : la charge de cette série, à ±2,5 kg ou saisie.
const perSet = perSetLoad(ex);
const first = setLoadAt(ex, i);
const loadField = h("input", {
class: "stepper__value stepper__input", type: "text", inputmode: "decimal", autocomplete: "off",
"aria-label": `Charge de la série ${i + 1} (kg)`, placeholder: "—", value: first === null ? "" : kg(first),
});
loadField.addEventListener("input", () => loadField.setAttribute("aria-invalid", String(parseAmount(loadField.value) === undefined)));
const bump = (/** @type {number} */ d) => {
const v = parseAmount(loadField.value);
loadField.value = kg(Math.max(0, (typeof v === "number" ? v : 0) + d));
loadField.setAttribute("aria-invalid", "false");
};
const panel = h("div", { class: "set-panel", role: "group", "aria-label": `Série ${i + 1}` },
h("p", { class: "set-panel__title" }, `Série ${i + 1}`,
timed ? ` · ${ex.seconds} s${ex.sides ? " par côté" : ""}` : range ? ` · objectif ${range.low === range.high ? range.low : range.low + "–" + range.high} répétitions` : ""),
timed ? ` · ${ex.seconds} s${ex.sides ? " par côté" : ""}` : goal ? ` · objectif ${goal.low === goal.high ? goal.low : goal.low + "–" + goal.high} répétitions` : ""),
perSet && h("div", { class: "stepper" },
h("button", { type: "button", class: "stepper__btn", "aria-label": "2,5 kg de moins", on: { click: () => bump(-2.5) } }, "−"),
loadField,
h("button", { type: "button", class: "stepper__btn", "aria-label": "2,5 kg de plus", on: { click: () => bump(2.5) } }, "+"),
h("span", { class: "stepper__unit" }, "kg sur cette série")),
!timed && h("div", { class: "stepper" },
h("button", { type: "button", class: "stepper__btn", "aria-label": "Une répétition de moins", on: { click: () => step(-1) } }, "−"),
value,
@@ -125,7 +163,13 @@ export function exerciseCard(o) {
type: "button", class: "effort", data: { effort },
"aria-pressed": String(existing?.effort === effort),
on: { click: () => {
markSet(o.draft, ex, i, { reps: timed ? null : reps, effort });
const load = perSet ? parseAmount(loadField.value) : undefined;
if (perSet && typeof load === "number" && ex.setLoads) {
ex.setLoads[i] = load;
ex.loadKg = topLoad(ex);
}
markSet(o.draft, ex, i, { reps: timed ? null : reps, effort, ...(perSet && typeof load === "number" ? { kg: load } : {}) });
if (perSet) saveLoads();
closePanel();
changed();
// Le repos démarre au ressenti.
@@ -207,7 +251,18 @@ export function exerciseCard(o) {
h("button", { type: "button", class: "set-btn", on: { click: () => showPanel(i) } }, String(i + 1)));
const fields = h("div", { class: "work__fields" },
usesTime(ex.tracking) && amountField("seconds"),
usesLoad(ex.tracking) && amountField("loadKg"),
usesLoad(ex.tracking) && !perSetLoad(ex) && amountField("loadKg"),
perSetLoad(ex) && h("p", { class: "work__loads" }, h("span", { class: "mini-label" }, "Charges"), loadsLine),
// Pyramide écrite au programme (setReps) : toujours une charge par série.
usesLoad(ex.tracking) && !(perSetLoad(ex) && ex.setReps?.length) && h("button", {
type: "button", class: "link-btn",
on: { click: () => {
setPerSetLoad(ex, !perSetLoad(ex));
saveLoads();
drawWork();
changed();
} },
}, perSetLoad(ex) ? "Même charge pour toutes les séries" : "Charge différente à chaque série"),
ex.tracking === "none" && h("p", { class: "muted" }, "Poids du corps : rien à saisir."));
if (usesTime(ex.tracking))
chronoBtn = h("button", { type: "button", class: "btn btn--block btn--work", on: { click: startChrono } });