84 lines
3.7 KiB
JavaScript
84 lines
3.7 KiB
JavaScript
// L'échauffement guidé, en tête de séance : un peu de cardio, la mobilité
|
|
// (warmup.MOBILITY), puis les séries d'approche du premier exercice, chiffrées à
|
|
// partir de sa charge de travail (warmup.warmupPlan).
|
|
// Glossaire : docs/glossaire/echauffement.md, docs/glossaire/approche.md
|
|
|
|
import { h } from "./dom.js";
|
|
import { restLabel } from "./format.js";
|
|
import { MOBILITY, warmupPlan } from "../domain/warmup.js";
|
|
|
|
/** @typedef {{title: string, detail: string, seconds: number|null, approach: boolean}} WarmupStep */
|
|
|
|
/** Mise en route, avant la mobilité (reprise d'Atelier). */
|
|
const GENERAL = { title: "Vélo, marche ou corde légère", detail: "Allure tranquille, juste de quoi avoir chaud et le souffle un peu plus court.", seconds: 360 };
|
|
|
|
/**
|
|
* Les étapes de l'échauffement d'une séance.
|
|
* @param {import("../domain/state.js").State} state
|
|
* @param {import("../domain/program.js").ProgramSession} session
|
|
* @returns {{steps: WarmupStep[], exerciseName: string|null, note: string|null}}
|
|
*/
|
|
export function warmupSteps(state, session) {
|
|
const plan = warmupPlan(state, session);
|
|
return {
|
|
steps: [
|
|
{ ...GENERAL, approach: false },
|
|
...MOBILITY.map((m) => ({ ...m, approach: false })),
|
|
...(plan?.lines ?? []).map((l) => ({ title: l.title, detail: l.detail, seconds: null, approach: true })),
|
|
],
|
|
exerciseName: plan?.exerciseName ?? null,
|
|
note: plan?.note ?? null,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* @param {{plan: ReturnType<typeof warmupSteps>, done: boolean[], timer: import("./timer.js").Timer, onChange: () => void, open: boolean}} o
|
|
* done : étapes cochées, modifié sur place
|
|
*/
|
|
export function warmupCard(o) {
|
|
const count = h("span", { class: "exercise__count" });
|
|
const refresh = () => {
|
|
const n = o.done.filter(Boolean).length;
|
|
count.textContent = `${n}/${o.done.length}`;
|
|
count.classList.toggle("exercise__count--done", n === o.done.length);
|
|
};
|
|
|
|
/** @param {WarmupStep} step @param {number} i */
|
|
const row = (step, i) => {
|
|
const tick = h("button", { type: "button", class: "tick", "aria-pressed": String(!!o.done[i]), "aria-label": `Fait : ${step.title}` });
|
|
tick.addEventListener("click", () => {
|
|
o.done[i] = !o.done[i];
|
|
tick.setAttribute("aria-pressed", String(o.done[i]));
|
|
refresh();
|
|
o.onChange();
|
|
});
|
|
return h("li", { class: "step" },
|
|
tick,
|
|
h("div", { class: "step__text" }, h("strong", null, step.title), h("span", null, step.detail)),
|
|
step.seconds && h("button", {
|
|
type: "button", class: "btn btn--sm step__go", "aria-label": `Lancer ${restLabel(step.seconds)} : ${step.title}`,
|
|
on: { click: () => o.timer.startRest(/** @type {number} */ (step.seconds), step.title, "Étape terminée") },
|
|
}, restLabel(step.seconds)));
|
|
};
|
|
|
|
const steps = o.plan.steps;
|
|
const general = steps.filter((s) => !s.approach);
|
|
const approach = steps.filter((s) => s.approach);
|
|
const card = h("details", { class: "exercise exercise--warmup", open: o.open },
|
|
h("summary", { class: "exercise__head" },
|
|
h("span", { class: "badge", "aria-hidden": "true" }, "0"),
|
|
h("span", { class: "exercise__name" },
|
|
h("strong", null, "Échauffement"),
|
|
h("span", { class: "exercise__sub" }, "En premier · environ 10 min")),
|
|
count,
|
|
h("span", { class: "chevron", "aria-hidden": "true" })),
|
|
h("div", { class: "exercise__body" },
|
|
h("ol", { class: "steps" }, general.map((s, i) => row(s, i))),
|
|
approach.length > 0 && [
|
|
h("h3", { class: "mini-label" }, `Séries d'approche · ${o.plan.exerciseName ?? ""}`),
|
|
h("ol", { class: "steps" }, approach.map((s, i) => row(s, general.length + i)))],
|
|
o.plan.note && h("p", { class: "coach-note" }, o.plan.note)));
|
|
refresh();
|
|
return card;
|
|
}
|