Type a word, a function name or an error code.
Opening the index…
The search index did not load. Type again to retry.
Nothing in the docs matches “”.
↑↓ to moveenter to goesc to close
Conditionals
4 min·Assumes: statestate, eventsevents
import { state } from '@markless/core';
export default function Lavafunction Lava(): Element() @{@{ · Statement containerHolds instructions: setup lines, then the element to show.
let alivelet alive: boolean = statestate · Watched valueDeclares a variable the page watches. You read and assign it like any other variable, and the page keeps up.(true);
<section<section> · HTML elementA section of a page, usually with its own heading.>
@if@if · ConditionalShows its block while the test is true. (alive) {
<p<p> · HTML elementA paragraph.>Level 1</p<p> · HTML elementA paragraph.>
} @else@else · Fallback branchShows its block when the @if test is false. {
<p<p> · HTML elementA paragraph.>Game over</p<p> · HTML elementA paragraph.>
}
<button<button> · HTML elementA button a person can press. onClickonClick · Event handlerRuns when this element gets the DOM event named after on, with the browser's own event object.={() => (alive = false)}>
Touch the lava
</button<button> · HTML elementA button a person can press.>
</section<section> · HTML elementA section of a page, usually with its own heading.>
}@if@if · ConditionalShows its block while the test is true. shows its elements while the condition is true, and @else@else · Fallback branchShows its block when the @if test is false. shows what goes there instead.
Show one thing or the other
A condition is a question with a yes or no answer. One side is on the page for yes, the other for no.
import { computed, state } from '@markless/core';import { act, bars, look, moves, next, say, start,} from './fight.ts';export default function BossFight() @{ let fight = state(start()); const fled = computed(() => fight.fled); <section class="boss" style={look(fight)} data-turn={fight.turn}> @if (fled) { <p class="empty-field" /> } @else { <p class="party"> <i class="swordsman" /> <i class="archer" /> <i class="wizard" /> </p> } <b>x{bars(fight)}</b> <output onAnimationEnd={() => next(fight)}> {say(fight)} </output> @for (const move of moves; key move) { <button onClick={() => act(fight, move)}> {move} </button> } </section>}
export type Turn = | 'menu' | 'attack' | 'scratch' | 'raise' | 'cast' | 'struck' | 'flee' | 'fallen' | 'won';export type Fight = { turn: Turn; fled: boolean; boss: number; down: number;};export const moves = [ 'Fight', 'Run', 'Try again',] as const;type Move = (typeof moves)[number];// Her spell takes them out in this order.const party = ['swordsman', 'archer', 'wizard'];// A bar holds 30 points; each attack takes one.const bar = 30;const full = 99 * bar;export const start = (): Fight => ({ turn: 'menu', fled: false, boss: full, down: 0,});export const bars = ({ boss }: Fight) => Math.ceil(boss / bar);// How full her top bar is, from 0 to 1.const top = (boss: number) => boss && (((boss - 1) % bar) + 1) / bar;export const look = ({ boss, down }: Fight) => `--top:${top(boss)};--down:${down}`;const standing = ({ down }: Fight) => party.length - down;const to = (fight: Fight, turn: Turn): Fight => ({ ...fight, turn });const over = ({ turn }: Fight) => turn === 'fallen' || turn === 'won';function chosen(fight: Fight, move: Move): Fight { if (move === 'Try again') return over(fight) ? start() : fight; if (fight.turn !== 'menu') return fight; if (move === 'Run') return fight.fled ? fight : to(fight, 'flee'); return to({ ...fight, fled: false }, 'attack');}const scratched = (fight: Fight): Fight => ({ ...fight, boss: Math.max(0, fight.boss - standing(fight)),});// What follows each moment once it is over.function after(fight: Fight): Fight { switch (fight.turn) { case 'attack': { const hurt = scratched(fight); const next = hurt.boss ? 'scratch' : 'won'; return to(hurt, next); } case 'scratch': return to(fight, 'raise'); case 'raise': return to(fight, 'cast'); case 'cast': { const down = fight.down + 1; return { ...to(fight, 'struck'), down }; } case 'struck': { const gone = standing(fight) === 0; return to(fight, gone ? 'fallen' : 'menu'); } case 'flee': return { ...to(fight, 'menu'), fled: true }; default: return fight; }}type Line = Exclude<Turn, 'struck'>;const lines: Record<Line, string> = { menu: 'Fight or run?', attack: 'They give it everything.', scratch: "She didn't notice.", raise: "She isn't even looking.", cast: 'She yawns.', flee: 'They run.', fallen: 'The party has fallen.', won: "She didn't see that coming.",};export function say({ turn, fled, down }: Fight) { if (fled) return 'She waves goodbye.'; if (turn === 'struck') return `The ${party[down - 1]} is down.`; return lines[turn];}// These write the fight they are given.export function act(fight: Fight, move: Move) { Object.assign(fight, chosen(fight, move));}export function next(fight: Fight) { Object.assign(fight, after(fight));}
/* The scene is 240 x 250 units: 1cqw is 2.4. */.boss { --pose: 0; container-type: inline-size; position: relative; display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; background: 0 0 / 100% no-repeat url(/examples/ink/if2-field.svg); font-family: 'Shantell Sans', sans-serif; user-select: none;}/* How long each moment lasts, and her pose: a frame of if2-her.svg. */.boss[data-turn='attack'] { --for: calc((3 - var(--down)) * 0.7s);}.boss[data-turn='scratch'] { --for: 1.2s; --pose: 1;}.boss[data-turn='raise'] { --for: 1.4s; --pose: 2;}.boss[data-turn='cast'] { --for: 1.1s; --pose: 3;}.boss[data-turn='struck'] { --for: 1.4s; --pose: 4;}.boss[data-turn='flee'] { --for: 1.2s;}.boss:is([data-turn='fallen'], :has(.empty-field)) { --pose: 5;}.boss[data-turn='won'] { --pose: 6;}/* Every drawing is a layer the size of the scene; most show one frame of a sheet of them. */.boss::before,.boss::after,.boss p::before,.boss p::after,.boss i,.boss i::before { content: ''; position: absolute; top: 0; left: 0; width: 100cqw; aspect-ratio: 240 / 250; background: 0 0 / 100% no-repeat; pointer-events: none;}.boss::before { background: url(/examples/ink/if2-her.svg) calc(var(--pose) * 16.667%) 0 / 700% 100%;}.boss p { grid-column: 1 / -1; position: relative; aspect-ratio: 240 / 250; margin: 0; clip-path: inset(0);}.boss .empty-field { background: 0 0 / 100% no-repeat url(/examples/ink/if2-gone.svg);}/* A column each, in the order her spell takes them out. Rows: standing, knocked flat, attacking, running. Each attacks in a slot of its own; anyone down has had theirs. */.boss i { --k: 0; --row: 0; --from: -1cqw 6cqw; --out: clamp(0, var(--down) - var(--k), 1); --at: calc((var(--k) - var(--down)) * 0.7s); --y: max(var(--out), var(--row) * (1 - var(--out))); background: url(/examples/ink/if2-party.svg) calc(var(--k) * 50%) calc(var(--y) * 33.333%) / 300% 400%;}.boss .archer { --k: 1; --from: -19cqw 24cqw;}.boss .wizard { --k: 2; --from: -37cqw 17.5cqw;}/* Each attack in flight, then its mark on her. */.boss i::before { --hit: 0; background: url(/examples/ink/if2-shots.svg) calc(var(--k) * 50%) calc(var(--hit) * 100%) / 300% 200%; opacity: 0;}.boss[data-turn='attack'] i { animation: go 0.7s var(--at);}.boss[data-turn='attack'] i::before { animation: shot 0.7s var(--at);}.boss[data-turn='flee'] i { --row: 3;}/* Her spell gathers, comes down on the next one standing, and lands. */.boss[data-turn='raise']::after { background-image: url(/examples/ink/if2-charge.svg);}.boss[data-turn='cast'] p::before,.boss[data-turn='struck'] p::after { --x: calc((var(--down) - var(--hit)) * 50%); background: url(/examples/ink/if2-spell.svg) var(--x) calc(var(--hit) * 100%) / 300% 200%; transform-origin: calc(54% - var(--down) * 15%) 85%;}.boss p::before { --hit: 0;}.boss p::after { --hit: 1;}/* Her meter: red is what is left of the top bar, yellow the slice just taken. */.boss b { --cut: calc(96.67% - var(--top) * 80.83%); position: absolute; inset: 0 0 auto; display: grid; align-items: end; justify-content: end; aspect-ratio: 240 / 46; padding-right: 2%; background: 0 0 / 100% no-repeat url(/examples/ink/if2-meter.svg);}.boss b::before,.boss b::after { content: ''; position: absolute; inset: 0; background: 0 0 / 100% no-repeat url(/examples/ink/if2-meter-chip.svg); clip-path: inset(0 var(--cut) 0 0);}.boss b::after { background-image: url(/examples/ink/if2-meter-red.svg);}/* Each line fades in, and its end moves the fight on; two names, so each line restarts. */.boss output { grid-column: 1 / -1; min-height: 2.6em; font-weight: 700; text-align: center;}.boss:not([data-turn='menu'], [data-turn='won'], [data-turn='fallen']) output { animation: line var(--for);}.boss:is([data-turn='scratch'], [data-turn='cast']) output { animation-name: line-again;}/* Every drawing loads before the first press. */.boss output::before { content: ''; position: absolute; background-image: url(/examples/ink/if2-shots.svg), url(/examples/ink/if2-charge.svg), url(/examples/ink/if2-spell.svg), url(/examples/ink/if2-gone.svg);}.boss button { padding: 0.3em 0.9em; border: 2px solid; border-radius: 6px; background: none; color: inherit; font: inherit; cursor: pointer; touch-action: manipulation;}.boss button:focus-visible { outline: 2px dashed currentColor; outline-offset: 2px;}/* While a turn plays the menu waits, and so does Run once they have run. Last is Try again. */.boss:not([data-turn='menu']) button:not(:last-child),.boss:has(.empty-field) button + button { border-style: dashed; opacity: 0.4; cursor: not-allowed;}.boss button:last-child { grid-column: 1 / -1; display: none;}.boss:is([data-turn='fallen'], [data-turn='won']) button:last-child { display: block;}@keyframes line { from { color: transparent; } 20% { color: currentColor; }}@keyframes line-again { from { color: transparent; } 20% { color: currentColor; }}@keyframes go { from, to { --row: 2; }}@keyframes shot { from, 60% { opacity: 1; --hit: 0; } 61%, 95% { opacity: 1; --hit: 1; }}/* Motion, unless less is asked for; without it each drawing still shows in its turn. */@media (prefers-reduced-motion: no-preference) { .boss b::before { transition: clip-path 0.4s 0.3s; } .boss[data-turn='attack'] i::before { animation: shot 0.7s var(--at), fly 0.7s linear var(--at); } .boss[data-turn='raise']::after { transform-origin: 40.9% 32.8%; animation: charge var(--for) ease-in; } .boss[data-turn='cast'] p::before { animation: beam var(--for) ease-out; } .boss[data-turn='struck'] p::after { animation: boom var(--for) ease-out both; } .boss[data-turn='flee'] i { animation: flee var(--for) ease-in both; } .boss[data-turn='won']::before { animation: jolt 0.5s; }}@keyframes fly { from { translate: var(--from); opacity: 0; } 60% { translate: 0 0; }}@keyframes charge { from { scale: 0.1; opacity: 0; } 70% { scale: 1; opacity: 1; } 80% { scale: 1.15; }}@keyframes beam { from { clip-path: inset(0 0 40%); } 40% { clip-path: inset(0); }}@keyframes boom { from { scale: 0.5; } 15%, 45% { scale: 1; opacity: 1; } to { opacity: 0; }}@keyframes flee { to { translate: -64cqw 0; }}@keyframes jolt { 25%, 75% { translate: 1cqw 0; } 50% { translate: -1cqw 0; }}
x99
- To do: Press Fight until one of them is down, then Run.
- To do: Press Fight: they come back, and whoever was down is still down.
- To do: Give her one point: in fight.ts, change
99 * barto1, then press Fight.
What isn't showing isn't on the page
When the condition is false, the elements inside aren't hidden. They are taken off the page, and built new the next time it is true. Smash the pots, then leave the room and come back.
To keep something, declare it above the @if@if · ConditionalShows its block while the test is true.:
let notelet note: string = statestate · Watched valueDeclares a variable the page watches. You read and assign it like any other variable, and the page keeps up.('');
@if@if · ConditionalShows its block while the test is true. (open) {
<textarea<textarea> · HTML elementA text field with several lines.
value(property) value?: string | undefined={note}
onInputonInput · Event handlerRuns when this element gets the DOM event named after on, with the browser's own event object.={(event(parameter) event: EventWithCurrentTarget<Event, HTMLTextAreaElement>) => {
notelet note: string = event.currentTarget.value;
}}
/>
}The first true condition wins
@else if@else if · Chained conditionalAnother test, tried when the ones before it were false. asks another question when the one before it was false. They are asked from the top, and @else@else · Fallback branchShows its block when the @if test is false. catches whatever is left. Throw a lever.
@if@if · ConditionalShows its block while the test is true. (firstLever) {
<Goldimport Gold />
} @else if@else if · Chained conditionalAnother test, tried when the ones before it were false. (secondLever) {
<Gemsimport Gems />
} @else@else · Fallback branchShows its block when the @if test is false. {
<Rocksimport Rocks />
}Pick one of many with @switch
@switch@switch · Value matchShows the one @case that matches, or @default. compares one value with each @case@case · Match branchShows when the @switch value equals this one. and shows the first that matches. @default@default · Match fallbackShows when no @case matched. shows when none does.
import { computed, state } from '@markless/core';import { again, hp, kind, land, moves, next, play, say, start,} from './rules.ts';export default function Battle() @{ let fight = state(start()); const move = computed(() => fight.move); <section class="battle" style={hp(fight)} data-turn={fight.turn} data-foe={fight.reply} onAnimationEnd={() => land(fight)}> @switch (move) { @case 'fireball': { <i class="fire" /> } @case 'downpour': { <i class="rain" /> } @case 'pounce': { <i class="paw" /> } @default: { <i class="miss" /> } } <b class="foe">Sprig</b><b class="you">Pip</b> <output onAnimationEnd={() => next(fight)}> {say(fight)} </output> @for (const name of moves; key name) { <button data-kind={kind(name)} onClick={() => play(fight, name)} > {name} </button> } <button onClick={() => again(fight)}> Battle again </button> </section>}
type Kind = | 'fire' | 'water' | 'leaf' | 'ice' | 'normal';type Effect = 'super' | 'weak' | 'plain';type Move = { kind: Kind; power: number };type Side = { name: string; kind: Kind };export type Turn = | 'menu' | 'you' | 'hit' | 'miss' | 'foe' | 'struck' | 'won' | 'lost';export type Fight = { move: string; reply: string; turn: Turn; hp: { you: number; foe: number };};export const moves = [ 'pounce', 'downpour', 'wiggle', 'fireball',];const book = new Map<string, Move>([ ['fireball', { kind: 'fire', power: 30 }], ['downpour', { kind: 'water', power: 30 }], ['pounce', { kind: 'normal', power: 25 }], ['snowball', { kind: 'ice', power: 30 }], ['thorn whip', { kind: 'leaf', power: 40 }], ['dew spray', { kind: 'water', power: 30 }],]);const still: Move = { kind: 'normal', power: 0 };export const kind = (move: string) => (book.get(move) ?? still).kind;const pip: Side = { name: 'Pip', kind: 'fire' };const sprig: Side = { name: 'Sprig', kind: 'leaf',};// Each kind beats one other kind.const beats: Partial<Record<Kind, Kind>> = { fire: 'leaf', leaf: 'water', water: 'fire', ice: 'leaf',};function effect(move: string, { kind }: Side) { const used = (book.get(move) ?? still).kind; if (beats[used] === kind) return 'super'; if (used === kind || beats[kind] === used) return 'weak'; return 'plain';}const times: Record<Effect, number> = { super: 2, weak: 0.5, plain: 1,};function hurt( hp: number, move: string, to: Side,) { const { power } = book.get(move) ?? still; const lost = power * times[effect(move, to)]; return Math.max(0, hp - Math.round(lost));}// Sprig whips while healthy and sprays once hurt.const replyAt = (hp: number) => hp > 50 ? 'thorn whip' : 'dew spray';export const start = (): Fight => ({ move: '', reply: '', turn: 'menu', hp: { you: 100, foe: 100 },});function pick(fight: Fight, move: string): Fight { if (fight.turn !== 'menu') return fight; return { ...fight, move, turn: 'you' };}// Pip's attack reached Sprig: the hit lands once.function landed(fight: Fight): Fight { const { turn, move, hp } = fight; if (turn !== 'you') return fight; return { ...fight, turn: 'hit', hp: { ...hp, foe: hurt(hp.foe, move, sprig) }, };}// What follows each moment once it is over.function after(fight: Fight): Fight { const { turn, hp, reply } = fight; const to = (next: Turn): Fight => ({ ...fight, turn: next }); switch (turn) { case 'you': return to('miss'); case 'hit': case 'miss': { if (hp.foe === 0) return to('won'); const next = replyAt(hp.foe); return { ...to('foe'), reply: next }; } case 'foe': { const you = hurt(hp.you, reply, pip); const now = { ...hp, you }; return { ...to('struck'), hp: now }; } case 'struck': return to(hp.you === 0 ? 'lost' : 'menu'); default: return fight; }}const verdicts: Record<Effect, string> = { super: "It's super effective!", weak: "It's not very effective…", plain: '',};const title = (move: string) => move.replace(/\b\w/g, (a) => a.toUpperCase());export function say(fight: Fight) { const { turn, move, reply } = fight; const wild = `The wild ${sprig.name}`; const used = `${pip.name} used ${title(move)}!`; const whips = `${wild} used ${title(reply)}!`; const hit = verdicts[effect(move, sprig)]; const struck = verdicts[effect(reply, pip)]; switch (turn) { case 'menu': return `What will ${pip.name} do?`; case 'you': return used; case 'hit': return hit || used; case 'miss': return 'But nothing happened!'; case 'foe': return whips; case 'struck': return struck || whips; case 'won': return `${wild} fainted!`; case 'lost': return `${pip.name} fainted!`; }}export const hp = ({ hp: { foe, you } }: Fight) => `--foe:${foe};--you:${you}`;// These write the fight they are given.export function play(fight: Fight, move: string) { Object.assign(fight, pick(fight, move));}export function land(fight: Fight) { Object.assign(fight, landed(fight));}export function next(fight: Fight) { Object.assign(fight, after(fight));}export function again(fight: Fight) { Object.assign(fight, start());}
@property --foe { syntax: '<integer>'; inherits: true; initial-value: 100;}@property --you { syntax: '<integer>'; inherits: true; initial-value: 100;}/* The scene is 240 x 170 units: 1cqw is 2.4. */.battle { container-type: inline-size; position: relative; display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; padding-top: calc(100% * 170 / 240); background: 0 0 / 100% no-repeat url(/examples/ink/bt-field.svg); font-family: 'Shantell Sans', sans-serif; user-select: none; transition: --foe 0.8s, --you 0.8s;}/* Sprig, Pip, the attacks and Sprig's moves. */.battle::before,.battle::after,.battle i,.battle .you::before { content: ''; position: absolute; top: 0; left: 0; width: 100cqw; aspect-ratio: 240 / 170; background: 0 0 / 100% no-repeat var(--art); pointer-events: none;}.battle::before { --art: url(/examples/ink/bt-sprig.svg); transform-origin: 73% 53%;}.battle::after { --art: url(/examples/ink/bt-pip.svg); transform-origin: 27% 92%;}/* Only an attack's own animation may end while Pip's move flies: its end is the hit. */.battle i { display: none; transform-origin: 72% 38%;}.battle:is([data-turn='you'], [data-turn='hit']) i,.battle[data-turn='miss'] .miss { display: block;}.battle .fire { --art: url(/examples/ink/bt-fire.svg); --hit: url(/examples/ink/bt-fire-hit.svg); animation: fly 0.7s ease-in both;}.battle .rain { --art: url(/examples/ink/bt-rain.svg); --hit: url(/examples/ink/bt-rain-hit.svg); animation: gather 0.7s ease-out both;}.battle .paw { --art: url(/examples/ink/bt-paw.svg); --hit: url(/examples/ink/bt-paw-hit.svg); animation: dash 0.6s ease-out both;}.battle .snow { --art: url(/examples/ink/bt-snow.svg); --hit: url(/examples/ink/bt-snow-hit.svg); animation: fly 0.7s ease-in both;}.battle .miss { --art: url(/examples/ink/bt-miss.svg); --hit: url(/examples/ink/bt-miss.svg);}.battle[data-turn='hit'] i { --art: var(--hit); animation: burst 1s ease-out both;}/* Pip wiggles for as long as the move lasts. */.battle[data-turn='you']:has(.miss)::after { animation: wiggle 0.2s ease-in-out infinite alternate;}.battle[data-turn='hit']::before,.battle[data-turn='struck']::after { animation: flinch 0.5s;}.battle[data-turn='won']::before { --art: url(/examples/ink/bt-sprig-down.svg); animation: faint 0.6s ease-in;}.battle[data-turn='lost']::after { --art: url(/examples/ink/bt-pip-down.svg); animation: faint 0.6s ease-in;}/* Sprig's move lands on Pip. */.battle .you::before { --art: url(/examples/ink/bt-thorns.svg); display: none; top: -48.33cqw; left: -51.67cqw; animation: grow 2.2s ease-out both;}.battle:is([data-turn='foe'], [data-turn='struck']) .you::before { display: block;}.battle[data-foe='dew spray'] .you::before { --art: url(/examples/ink/bt-dew.svg); animation-name: spray;}/* A plate: 112 x 34 units, the bar in its trough from x 31 to 103. */.battle b { position: absolute; z-index: 1; box-sizing: border-box; width: 46.67cqw; aspect-ratio: 112 / 34; padding-left: 3cqw; background: 0 0 / 100% no-repeat url(/examples/ink/bt-plate.svg); font-size: clamp(0.75rem, 5cqw, 1rem); line-height: 7cqw;}.battle .foe { --hp: var(--foe); top: 2.5cqw; left: 2.5cqw;}.battle .you { --hp: var(--you); top: 48.33cqw; left: 51.67cqw;}/* Green, then yellow under 51, red under 21. */.battle b::after { --high: clamp(0, var(--hp) - 50, 1); --mid: clamp(0, var(--hp) - 20, 1); content: ''; position: absolute; top: 67.6%; left: 27.7%; width: calc(var(--hp) * 0.643%); height: 14.7%; border-radius: 2px; background: color-mix(in srgb, #8fc07a calc(var(--high) * 100%), color-mix(in srgb, #ffd84d calc(var(--mid) * 100%), #e07a6a));}/* Every drawing loads before the first move. */.battle .foe::before { content: ''; position: absolute; background-image: url(/examples/ink/bt-fire.svg), url(/examples/ink/bt-fire-hit.svg), url(/examples/ink/bt-rain.svg), url(/examples/ink/bt-rain-hit.svg), url(/examples/ink/bt-paw.svg), url(/examples/ink/bt-paw-hit.svg), url(/examples/ink/bt-snow.svg), url(/examples/ink/bt-snow-hit.svg), url(/examples/ink/bt-miss.svg), url(/examples/ink/bt-thorns.svg), url(/examples/ink/bt-dew.svg), url(/examples/ink/bt-sprig-down.svg), url(/examples/ink/bt-pip-down.svg);}/* Each line's end moves the fight on. */.battle output { grid-column: 1 / -1; display: flex; align-items: center; min-height: 3.4em; padding: 0.4em 0.9em; background: 0 0 / 100% 100% no-repeat url(/examples/ink/bt-box.svg); font-size: 0.95rem; line-height: 1.3;}.battle:is([data-turn='you'], [data-turn='foe']) output { animation: line 1.2s;}/* A second name, so the next line restarts. */.battle:is( [data-turn='hit'], [data-turn='miss'], [data-turn='struck']) output { animation: line-again 1s;}/* The move menu. */.battle button { padding: 0.4em 0.5em; border: 2px solid; border-radius: 6px; background: none; color: inherit; font: inherit; text-transform: capitalize; cursor: pointer; touch-action: manipulation;}.battle button:focus-visible { outline: 2px dashed currentColor; outline-offset: 2px;}/* While a turn plays out, the menu waits. */.battle:not([data-turn='menu']) button:not(:last-child) { border-style: dashed; opacity: 0.4; pointer-events: none;}/* Each move wears its element. */.battle button[data-kind]::after { content: attr(data-kind); display: block; width: fit-content; margin: 0.2em auto 0; padding: 0 0.5em; border-radius: 1em; background: var(--tint, #e6dcc6); color: #2d2a24; font-size: 0.7em; text-transform: uppercase; letter-spacing: 0.04em;}.battle [data-kind='fire'] { --tint: #f6b89c; }.battle [data-kind='water'] { --tint: #a9c9f0; }.battle [data-kind='leaf'] { --tint: #b9dba0; }.battle [data-kind='ice'] { --tint: #cfe8f2; }/* The last button is Battle again. */.battle button:last-child { grid-column: 1 / -1; display: none; text-transform: none;}.battle:is([data-turn='won'], [data-turn='lost']) button { display: none;}.battle:is([data-turn='won'], [data-turn='lost']) button:last-child { display: block;}@keyframes line { from { color: transparent; } 20% { color: currentColor; }}@keyframes line-again { from { color: transparent; } 20% { color: currentColor; }}@keyframes fly { from { translate: -44cqw 27cqw; scale: 0.5; }}@keyframes gather { from { translate: 0 -12cqw; opacity: 0; }}@keyframes dash { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0); }}@keyframes burst { from { scale: 0.6; } 20%, 75% { scale: 1; opacity: 1; } to { opacity: 0; }}@keyframes wiggle { from { rotate: -7deg; } to { rotate: 7deg; }}@keyframes flinch { 20%, 60% { translate: 1.5cqw 0; opacity: 0.3; } 40%, 80% { translate: -1.5cqw 0; }}@keyframes faint { from { translate: 0 -5cqw; opacity: 0.3; }}@keyframes grow { from { clip-path: inset(100% 0 0 0); } 25%, 80% { clip-path: inset(0); opacity: 1; } to { clip-path: inset(0); opacity: 0; }}@keyframes spray { from { translate: 44cqw -27cqw; opacity: 0; } 25%, 80% { translate: 0 0; opacity: 1; } to { opacity: 0; }}/* No motion: each move keeps its timing, so the hit still lands. */@media (prefers-reduced-motion: reduce) { .battle { transition: none; } @keyframes fly { to { opacity: 1; } } @keyframes gather { to { opacity: 1; } } @keyframes dash { to { opacity: 1; } } @keyframes burst { to { opacity: 1; } } @keyframes wiggle { to { opacity: 1; } } @keyframes flinch { to { opacity: 1; } } @keyframes faint { to { opacity: 1; } } @keyframes grow { to { opacity: 1; } } @keyframes spray { to { opacity: 1; } }}
- To do: Win the fight: find the move a leaf creature can't stand.
- To do: Press wiggle. No case is named for it, so
@defaultplays. - To do: Teach Pip a fifth move: add
'snowball'tomovesin rules.ts, and@case 'snowball': { <i class="snow" /> }above@default. Then press snowball. - To do: Misspell a case: change
@case 'fireball':to@case 'firebal':, then press fireball. No case matches, so@defaultplays and the fireball never lands.
Can a case be a condition instead of a value?
Yes. Write true as the value, and each @case becomes a question of its own:
@switch@switch · Value matchShows the one @case that matches, or @default. (true) {
@case@case · Match branchShows when the @switch value equals this one. hpimport hp < 20: {
<p<p> · HTML elementA paragraph.>Run!</p<p> · HTML elementA paragraph.>
}
@case@case · Match branchShows when the @switch value equals this one. hpimport hp < 50: {
<p<p> · HTML elementA paragraph.>Drink a potion.</p<p> · HTML elementA paragraph.>
}
@default@default · Match fallbackShows when no @case matched.: {
<p<p> · HTML elementA paragraph.>Keep fighting.</p<p> · HTML elementA paragraph.>
}
}What does the build stop?
Three mistakes, each with a message that says how to fix it:
elsewritten without its@:MARKLESS_BRANCH_ELSE_SPELLING.- Two elements side by side in one
@if@if · ConditionalShows its block while the test is true. or@case:MARKLESS_BLOCK_SIBLING_NODES. Wrap them in<>and</>. computed()written inside an@if:MARKLESS_STATE_CREATION_SITE_UNSTABLE. Declare it above.
Coming from JSX?
In JSX you write {open && <Panel />} or a ternary inside the markup. Here the same choice is a block, @if (open) { <Panel /> }, so each side reads top to bottom and @else if@else if · Chained conditionalAnother test, tried when the ones before it were false. needs no nesting.