1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113"use client";import { useEffect, useRef, useState } from "react";import "@/styles/demos/zen.css";import { play } from "@/lib/sound";import { PALETTES, ZEN_GOAL, cyclePalette, isComplete, isMatch, newRound, nextRound, type Round } from "@/lib/games/zen";import { useConsoleInput, useStep, type Action } from "../input";import { HowTo, useHowTo } from "../HowTo";import { withBase } from "@/lib/base"; const T = { en: { goal: "Match 5 palettes in a row", count: "Matched", target: "Target", now: "Desktop", hint: "Left/right or Enter / click: change the desktop palette to the one in the floating window", matched: "Matched", prev: "Previous palette", next: "Next palette", doneTitle: "All calm", doneBody: "Five palettes matched. One command recolours the whole desktop, and that is what omarchy-zen does for Omarchy and the Zen browser.", again: "Enter · Try again", names: { lavender: "Lavender", moss: "Moss", ember: "Ember", tide: "Tide", paper: "Paper" } as Record<string, string>, scene: "A misty lavender zen garden with a floating browser window", }, es: { goal: "Empareja 5 paletas seguidas", count: "Emparejadas", target: "Objetivo", now: "Escritorio", hint: "Izq/der o Enter / clic: cambia la paleta del escritorio hasta igualar la de la ventana flotante", matched: "Emparejada", prev: "Paleta anterior", next: "Paleta siguiente", doneTitle: "Todo en calma", doneBody: "Cinco paletas emparejadas. Un solo comando cambia los colores de todo el escritorio, y eso hace omarchy-zen para Omarchy y el navegador Zen.", again: "Enter · Otra vez", names: { lavender: "Lavanda", moss: "Musgo", ember: "Brasa", tide: "Marea", paper: "Papel" } as Record<string, string>, scene: "Un jardín zen de lavanda entre la niebla con una ventana de navegador flotante", },} as const; const reduced = () => typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;const seed = () => Math.floor(Math.random() * 1_000_000); export function ZenDemo({ locale }: { locale: "en" | "es" }) { const t = T[locale]; const step = useStep(); const how = useHowTo("zen"); const [r, setR] = useState<Round>(() => newRound(seed())); const [won, setWon] = useState(false); const timer = useRef<number | undefined>(undefined); const live = useRef({ r, won }); live.current = { r, won }; useEffect(() => () => window.clearTimeout(timer.current), []); const change = (dir: 1 | -1) => { const c = live.current; if (c.won || isComplete(c.r)) return; const next = { ...c.r, current: cyclePalette(c.r.current, dir) }; setR(next); step("change-theme"); if (isMatch(next)) { step("match"); setWon(true); play("confirm"); timer.current = window.setTimeout(() => { const n = nextRound(live.current.r, seed()); setR(n); setWon(false); if (isComplete(n)) { step("finish"); play("epic"); } }, reduced() ? 500 : 1500); } else play("blip"); }; const again = () => { setR(newRound(seed())); setWon(false); play("back"); }; useConsoleInput((a: Action) => { if (how.openRef.current) { if (a === "a" || a === "b") how.hide(); return; } if (isComplete(live.current.r)) { if (a === "a") again(); return; } if (a === "right" || a === "a") change(1); else if (a === "left") change(-1); }); const p = PALETTES[r.current], tg = PALETTES[r.target]; const [hue, sat, bri] = p.hue; const complete = isComplete(r); const vars = { "--zbg": p.bg, "--zfg": p.fg, "--zac": p.ac, "--tbg": tg.bg, "--tfg": tg.fg, "--tac": tg.ac } as React.CSSProperties; return ( <div className="dm dm-zenmatch" style={vars} data-won={won} data-done={complete}> <header className="zm-head"> <b>omarchy-zen</b> <span>{t.goal}</span> <em aria-live="polite">{t.count} {Math.min(r.solved, ZEN_GOAL)}/{ZEN_GOAL}<span className="zm-pips" aria-hidden="true">{Array.from({ length: ZEN_GOAL }, (_, i) => <i key={i} className={i < r.solved ? "on" : ""} />)}</span></em> </header> <div className="zm-stage"> <div className="zm-scene"> <picture> <source srcSet={withBase("/art/v3/games/zen-landscape.avif")} type="image/avif" /> {} <img src={withBase("/art/v3/games/zen-landscape.webp")} alt={t.scene} width={1500} height={632} decoding="async" draggable={false} style={{ filter: `hue-rotate(${hue}deg) saturate(${sat}%) brightness(${bri}%)` }} /> </picture> <i className="zm-tint" /> <div className={`zm-window${won ? " won" : ""}`} aria-label={`${t.target}: ${t.names[tg.id]}`}> <span className="zm-dots"><i /><i /><i /></span> <span className="zm-pane"><i /><i /><i /></span> <b>{won ? t.matched : t.names[tg.id]}</b> </div> {won && <span className="zm-bloom" aria-hidden="true">{Array.from({ length: 9 }, (_, i) => <i key={i} style={{ "--i": i } as React.CSSProperties} />)}</span>} </div> {complete && ( <div className="zm-done" role="status"> <b>{t.doneTitle}</b> <p>{t.doneBody}</p> <button type="button" onClick={again}>{t.again}</button> </div> )} </div> <div className="zm-bar"> <button type="button" onClick={() => change(-1)} aria-label={t.prev} disabled={complete}>‹</button> <span className="zm-chip"><i style={{ background: tg.ac }} />{t.target}: <b>{t.names[tg.id]}</b></span> <span className="zm-chip now"><i style={{ background: p.ac }} />{t.now}: <b>{t.names[p.id]}</b></span> <button type="button" onClick={() => change(1)} aria-label={t.next} disabled={complete}>›</button> </div> <p className="zm-hint">{complete ? "" : t.hint}</p> <HowTo id="zen" locale={locale} how={how} /> </div> );}
Recreación simplificada hecha para este sitio, no es el código del proyecto.