feat: ajoute le thème interactif Commodore 64 (prompt mC:>)
This commit is contained in:
1 parent
720070bee8
commit
579ad8b15d
7 files changed
+802
-3
No files matched your search
@@ -24,6 +24,7 @@
|
||||
|
||||
import { initThemeManager } from "./modules/theme-manager.js";
|
||||
import { initThemeSwitcher } from "./modules/theme-switcher.js";
|
||||
import { initC64Terminal } from "./modules/c64-terminal.js";
|
||||
import { initMotion } from "./modules/motion.js";
|
||||
import { initNavigation } from "./modules/navigation.js";
|
||||
import { initScrollSpy } from "./modules/scroll-spy.js";
|
||||
@@ -43,6 +44,7 @@ function init() {
|
||||
|
||||
initThemeManager();
|
||||
initThemeSwitcher({ status: statusRegion });
|
||||
initC64Terminal({ status: statusRegion });
|
||||
|
||||
const motion = initMotion({
|
||||
progressBar: document.querySelector("[data-reading-progress]"),
|
||||
|
||||
@@ -0,0 +1,275 @@
|
||||
/**
|
||||
* c64-terminal.js — Console interactive Commodore 64 (prompt mC:>)
|
||||
* =============================================================================
|
||||
* Actif uniquement lorsque data-theme="c64-basic".
|
||||
* Injecte la console C64 juste après .masthead et permet de révéler les 7
|
||||
* sections du CV existant (sans dupliquer aucun contenu HTML) soit :
|
||||
* - en tapant une commande au prompt « mC:> » (ex. PROFIL, ENSEIGNEMENT,
|
||||
* PROJETS, ALL, RUN, CLR, HELP — ou LOAD "PROFIL",8,1 en clin d'œil)
|
||||
* - en cliquant sur une commande dans l'aide
|
||||
* - en cliquant sur un lien de la barre de navigation
|
||||
*/
|
||||
|
||||
import { getActiveThemeId, onThemeChange } from "./theme-manager.js";
|
||||
|
||||
const C64_THEME_ID = "c64-basic";
|
||||
|
||||
const COMMAND_MAP = [
|
||||
{ cmd: "PROFIL", sectionId: "profil", label: "PROFIL" },
|
||||
{ cmd: "ENSEIGNEMENT", sectionId: "enseignement", label: "ENSEIGNEMENT" },
|
||||
{ cmd: "COORDINATION", sectionId: "coordination", label: "COORDINATION" },
|
||||
{ cmd: "PROJETS", sectionId: "projets", label: "PROJETS" },
|
||||
{ cmd: "COMPETENCES", sectionId: "competences", label: "COMPETENCES" },
|
||||
{ cmd: "FORMATION", sectionId: "formation", label: "FORMATION" },
|
||||
{ cmd: "CONTACT", sectionId: "contact", label: "CONTACT" },
|
||||
];
|
||||
|
||||
/**
|
||||
* Normalise une commande saisie (majuscules, sans accents, accepte LOAD "X",8,1).
|
||||
* @param {string} raw
|
||||
* @returns {string}
|
||||
*/
|
||||
function normalizeCommand(raw) {
|
||||
let clean = raw
|
||||
.trim()
|
||||
.normalize("NFD")
|
||||
.replace(/[\u0300-\u036f]/g, "")
|
||||
.toUpperCase();
|
||||
|
||||
// Accepte la syntaxe BASIC complète : LOAD "PROFIL",8,1 -> PROFIL
|
||||
const loadMatch = clean.match(/^LOAD\s+"([^"]+)"(?:\s*,\s*8(?:\s*,\s*1)?)?$/);
|
||||
if (loadMatch) clean = loadMatch[1].trim();
|
||||
|
||||
return clean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construit le bloc DOM de la console C64.
|
||||
* @returns {HTMLElement}
|
||||
*/
|
||||
function buildTerminalElement() {
|
||||
const wrapper = document.createElement("section");
|
||||
wrapper.className = "c64-terminal screen-only";
|
||||
wrapper.setAttribute("aria-label", "Console interactive Commodore 64");
|
||||
|
||||
const cmdButtons = COMMAND_MAP.map(
|
||||
({ cmd }) =>
|
||||
`<li><button type="button" class="c64-cmd-btn" data-c64-cmd="${cmd}">${cmd}</button></li>`
|
||||
).join("");
|
||||
|
||||
wrapper.innerHTML = `
|
||||
<div class="c64-boot" aria-hidden="true">
|
||||
<div>**** COMMODORE 64 BASIC V2 ****</div>
|
||||
<div class="c64-boot__ram">64K RAM SYSTEM 38911 BASIC BYTES FREE</div>
|
||||
</div>
|
||||
|
||||
<div class="c64-ready">READY. <span class="c64-cursor" aria-hidden="true"></span></div>
|
||||
|
||||
<div class="c64-help">
|
||||
<div class="c64-help__title">COMMANDES DISPONIBLES (TAPEZ OU CLIQUEZ) :</div>
|
||||
<ul class="c64-commands" role="list">
|
||||
${cmdButtons}
|
||||
<li><button type="button" class="c64-cmd-btn c64-cmd-btn--util" data-c64-cmd="ALL">ALL / RUN</button></li>
|
||||
<li><button type="button" class="c64-cmd-btn c64-cmd-btn--util" data-c64-cmd="CLR">CLR</button></li>
|
||||
<li><button type="button" class="c64-cmd-btn c64-cmd-btn--util" data-c64-cmd="HELP">HELP</button></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="c64-log" data-c64-log aria-live="polite"></div>
|
||||
|
||||
<form class="c64-prompt-form" data-c64-form autocomplete="off">
|
||||
<label class="c64-prompt-label" for="c64-input">mC:></label>
|
||||
<input
|
||||
id="c64-input"
|
||||
class="c64-prompt-input"
|
||||
type="text"
|
||||
name="command"
|
||||
placeholder="TAPEZ PROFIL, PROJETS, ALL..."
|
||||
spellcheck="false"
|
||||
autocapitalize="characters"
|
||||
data-c64-input
|
||||
>
|
||||
<button type="submit" class="c64-prompt-submit">RUN</button>
|
||||
</form>
|
||||
`;
|
||||
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise la console Commodore 64.
|
||||
*
|
||||
* @param {object} [options]
|
||||
* @param {HTMLElement | null} [options.status] - Région aria-live globale.
|
||||
* @returns {void}
|
||||
*/
|
||||
export function initC64Terminal({ status } = {}) {
|
||||
const masthead = document.querySelector(".masthead");
|
||||
if (!masthead) return;
|
||||
|
||||
const terminal = buildTerminalElement();
|
||||
masthead.insertAdjacentElement("afterend", terminal);
|
||||
|
||||
const form = terminal.querySelector("[data-c64-form]");
|
||||
const input = terminal.querySelector("[data-c64-input]");
|
||||
const logEl = terminal.querySelector("[data-c64-log]");
|
||||
const cmdButtons = terminal.querySelectorAll("[data-c64-cmd]");
|
||||
const sections = [...document.querySelectorAll("[data-section]")];
|
||||
const navLinks = document.querySelectorAll("[data-nav-link]");
|
||||
|
||||
/** Historique des commandes saisies (flèches Haut/Bas). */
|
||||
const history = [];
|
||||
let historyIndex = -1;
|
||||
|
||||
const syncCommandButtons = () => {
|
||||
cmdButtons.forEach((btn) => {
|
||||
const entry = COMMAND_MAP.find((item) => item.cmd === btn.dataset.c64Cmd);
|
||||
if (!entry) return;
|
||||
const section = document.getElementById(entry.sectionId);
|
||||
btn.dataset.loaded = String(section?.dataset.c64Visible === "true");
|
||||
});
|
||||
};
|
||||
|
||||
const setLog = (lines) => {
|
||||
if (logEl) logEl.textContent = lines.join("\n");
|
||||
};
|
||||
|
||||
const announce = (message) => {
|
||||
if (!status) return;
|
||||
status.textContent = "";
|
||||
requestAnimationFrame(() => {
|
||||
status.textContent = message;
|
||||
});
|
||||
};
|
||||
|
||||
const hideAllSections = () => {
|
||||
sections.forEach((sec) => {
|
||||
sec.dataset.c64Visible = "false";
|
||||
});
|
||||
syncCommandButtons();
|
||||
};
|
||||
|
||||
const showSection = (sectionId, { scroll = true } = {}) => {
|
||||
const target = document.getElementById(sectionId);
|
||||
if (!target) return;
|
||||
target.dataset.c64Visible = "true";
|
||||
target.dataset.revealed = "true";
|
||||
syncCommandButtons();
|
||||
|
||||
if (scroll) {
|
||||
const reduced = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
||||
target.scrollIntoView({ behavior: reduced ? "auto" : "smooth", block: "start" });
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Exécute une commande saisie ou cliquée.
|
||||
* @param {string} rawCommand
|
||||
* @param {{ scroll?: boolean }} [options]
|
||||
*/
|
||||
const runCommand = (rawCommand, { scroll = true } = {}) => {
|
||||
const cmd = normalizeCommand(rawCommand);
|
||||
if (!cmd) return;
|
||||
|
||||
history.push(cmd);
|
||||
historyIndex = history.length;
|
||||
|
||||
if (cmd === "CLR" || cmd === "CLS" || cmd === "CLEAR") {
|
||||
hideAllSections();
|
||||
setLog([`mC:> ${cmd}`, "SCREEN CLEARED.", "READY."]);
|
||||
announce("Sections masquées, retour à l'invite Commodore 64.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (cmd === "ALL" || cmd === "RUN" || cmd === "LIST") {
|
||||
sections.forEach((sec) => {
|
||||
sec.dataset.c64Visible = "true";
|
||||
sec.dataset.revealed = "true";
|
||||
});
|
||||
syncCommandButtons();
|
||||
setLog([`mC:> ${cmd}`, "LOADING ALL MODULES...", "READY."]);
|
||||
announce("Toutes les sections du CV sont affichées.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (cmd === "HELP" || cmd === "?") {
|
||||
setLog([
|
||||
`mC:> ${cmd}`,
|
||||
"COMMANDES : PROFIL, ENSEIGNEMENT, COORDINATION, PROJETS, COMPETENCES, FORMATION, CONTACT",
|
||||
"UTILITAIRES : ALL (OU RUN) = TOUT AFFICHER | CLR = EFFACER",
|
||||
"READY.",
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
const match = COMMAND_MAP.find((item) => item.cmd === cmd);
|
||||
if (match) {
|
||||
showSection(match.sectionId, { scroll });
|
||||
setLog([
|
||||
`mC:> ${cmd}`,
|
||||
`SEARCHING FOR ${match.cmd}`,
|
||||
"LOADING",
|
||||
"READY.",
|
||||
]);
|
||||
announce(`Section ${match.label} affichée.`);
|
||||
return;
|
||||
}
|
||||
|
||||
setLog([
|
||||
`mC:> ${cmd}`,
|
||||
"?SYNTAX ERROR",
|
||||
"TAPEZ HELP POUR VOIR LES COMMANDES.",
|
||||
"READY.",
|
||||
]);
|
||||
};
|
||||
|
||||
// Soumission du prompt mC:>
|
||||
form?.addEventListener("submit", (event) => {
|
||||
event.preventDefault();
|
||||
if (!input) return;
|
||||
runCommand(input.value);
|
||||
input.value = "";
|
||||
});
|
||||
|
||||
// Navigation dans l'historique clavier (Flèche Haut / Bas)
|
||||
input?.addEventListener("keydown", (event) => {
|
||||
if (event.key === "ArrowUp" && history.length > 0) {
|
||||
event.preventDefault();
|
||||
historyIndex = Math.max(0, historyIndex - 1);
|
||||
input.value = history[historyIndex] ?? "";
|
||||
} else if (event.key === "ArrowDown" && history.length > 0) {
|
||||
event.preventDefault();
|
||||
historyIndex = Math.min(history.length, historyIndex + 1);
|
||||
input.value = history[historyIndex] ?? "";
|
||||
}
|
||||
});
|
||||
|
||||
// Clic sur les boutons de commande affichés dans la présentation
|
||||
terminal.addEventListener("click", (event) => {
|
||||
const btn = event.target.closest("[data-c64-cmd]");
|
||||
if (!btn) return;
|
||||
runCommand(btn.dataset.c64Cmd);
|
||||
input?.focus({ preventScroll: true });
|
||||
});
|
||||
|
||||
// Clic sur un lien de la barre de navigation en mode C64 : charge la section
|
||||
navLinks.forEach((link) => {
|
||||
link.addEventListener("click", () => {
|
||||
if (getActiveThemeId() !== C64_THEME_ID) return;
|
||||
const targetId = link.getAttribute("href")?.replace("#", "");
|
||||
const match = COMMAND_MAP.find((item) => item.sectionId === targetId);
|
||||
if (match) runCommand(match.cmd, { scroll: false });
|
||||
});
|
||||
});
|
||||
|
||||
// À l'activation du thème C64, on réinitialise sur l'écran propre (en-tête + commandes + mC:>)
|
||||
const syncThemeState = (themeId) => {
|
||||
if (themeId === C64_THEME_ID) {
|
||||
hideAllSections();
|
||||
setLog([]);
|
||||
}
|
||||
};
|
||||
|
||||
syncThemeState(getActiveThemeId());
|
||||
onThemeChange((theme) => syncThemeState(theme.id));
|
||||
}
|
||||
@@ -106,6 +106,20 @@ export const THEMES = Object.freeze([
|
||||
"https://fonts.googleapis.com/css2?family=Instrument+Serif:ital@0;1&display=swap",
|
||||
],
|
||||
}),
|
||||
Object.freeze({
|
||||
id: "c64-basic",
|
||||
name: "Commodore 64",
|
||||
subtitle: "Ligne de commande BASIC V2",
|
||||
description:
|
||||
"Écran bleu Commodore 64, commandes interactives (PROFIL, PROJETS, ALL…) et prompt mC:> pour charger les sections du CV au clavier ou au clic.",
|
||||
tags: ["Rétro 8-bit", "CLI", "Interactif"],
|
||||
palette: ["#352879", "#6c5eb5", "#7ef7d4"],
|
||||
colorScheme: "dark",
|
||||
metaThemeColor: "#352879",
|
||||
fonts: [
|
||||
"https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap",
|
||||
],
|
||||
}),
|
||||
]);
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user