From 67377c4690312441d239028c84a3783f75ae4a37 Mon Sep 17 00:00:00 2001 From: Branden J Brown Date: Tue, 16 Jun 2026 14:20:03 -0400 Subject: [PATCH] zenno: format --- zenno/src/lib/CharaPick.svelte | 42 ++++++++----- zenno/src/lib/stringsearch.ts | 84 +++++++++++++------------- zenno/src/routes/doc/race/+page.svelte | 4 +- 3 files changed, 71 insertions(+), 59 deletions(-) diff --git a/zenno/src/lib/CharaPick.svelte b/zenno/src/lib/CharaPick.svelte index 7017e3e..bcc330d 100644 --- a/zenno/src/lib/CharaPick.svelte +++ b/zenno/src/lib/CharaPick.svelte @@ -22,7 +22,7 @@ let search = $state(''); const charas = $derived(characters ?? []); - const searchedCharas = $derived(stringsearch(search, charas, ({name}) => name) || charas); + const searchedCharas = $derived(stringsearch(search, charas, ({ name }) => name) || charas); $effect(() => { if (required && value == null && charas.length > 0) { @@ -41,14 +41,14 @@ case 'ArrowDown': { const opts = [...optionsContainer!.children] as HTMLElement[]; const i = opts.findIndex((n) => parseInt(n.dataset.charaId ?? '') === value?.chara_id); - const o = i != null && i >= 0 ? opts[Math.min(i+1, opts.length - 1)] : opts[0]; + const o = i != null && i >= 0 ? opts[Math.min(i + 1, opts.length - 1)] : opts[0]; setByElem(o); break; } case 'ArrowUp': { const opts = [...optionsContainer!.children] as HTMLElement[]; const i = opts.findIndex((n) => parseInt(n.dataset.charaId ?? '') === value?.chara_id); - const o = i != null && i > 0 ? opts[i-1] : opts[0]; + const o = i != null && i > 0 ? opts[i - 1] : opts[0]; setByElem(o); break; } @@ -83,48 +83,60 @@
popover?.togglePopover()} {onkeydown} - tabindex="0" - >{value?.name ?? ''} + tabindex="0">{value?.name ?? ''}
- +
{#if !required}
{value = undefined; search = ''; popover!.hidePopover()}} - onfocus={() => value = undefined} + onmousedown={() => { + value = undefined; + search = ''; + popover!.hidePopover(); + }} + onfocus={() => (value = undefined)} {onkeydown} > - Reset + Reset
{/if} {#each searchedCharas as c (c.chara_id)}
{value = c; popover!.hidePopover()}} - onfocus={() => value = c} + onmousedown={() => { + value = c; + popover!.hidePopover(); + }} + onfocus={() => (value = c)} {onkeydown} > {#if option != null} diff --git a/zenno/src/lib/stringsearch.ts b/zenno/src/lib/stringsearch.ts index f390ff3..0d5d90f 100644 --- a/zenno/src/lib/stringsearch.ts +++ b/zenno/src/lib/stringsearch.ts @@ -1,39 +1,39 @@ const WORD_BOUNDARY = " ,!?/-+();#○☆♡'=♪∀゚∴"; function score(s: string, tt: string): number { - let k: number | undefined; - let r = 0; - let run = 0; - for (const c of s) { - const j = tt.indexOf(c, k); - // If the character isn't in the string, there's a major penalty. - if (j < 0) { - // The penalty scales with run length, on the assumption that we're - // typing something else. - // Really this should scale with the longest current run among all - // search terms, but that's infeasible to implement. - r -= 6 + run*run; - run = 0; - continue; - } - run++; - // Characters at word boundaries get extra score. - if (j == 0 || WORD_BOUNDARY.includes(tt[j-1])) { - r += 2; - } - // As do characters that *are* word boundaries. - if (WORD_BOUNDARY.includes(c)) { - r += 2; - } - // And runs of matches scale with run length. - if (j === k) { - r += (run+1) * (run+1); - } else { - run = 0; - } - k = j + 1; - } - return r; + let k: number | undefined; + let r = 0; + let run = 0; + for (const c of s) { + const j = tt.indexOf(c, k); + // If the character isn't in the string, there's a major penalty. + if (j < 0) { + // The penalty scales with run length, on the assumption that we're + // typing something else. + // Really this should scale with the longest current run among all + // search terms, but that's infeasible to implement. + r -= 6 + run * run; + run = 0; + continue; + } + run++; + // Characters at word boundaries get extra score. + if (j == 0 || WORD_BOUNDARY.includes(tt[j - 1])) { + r += 2; + } + // As do characters that *are* word boundaries. + if (WORD_BOUNDARY.includes(c)) { + r += 2; + } + // And runs of matches scale with run length. + if (j === k) { + r += (run + 1) * (run + 1); + } else { + run = 0; + } + k = j + 1; + } + return r; } /** @@ -44,13 +44,13 @@ function score(s: string, tt: string): number { * @returns Matching terms in decreasing match quality order */ export function stringsearch(sub: string, terms: Iterable, map: (t: T) => string): T[] { - const s = sub.toLocaleLowerCase(); - const scored: [T, number][] = []; - for (const t of terms) { - const sc = score(s, map(t).toLocaleLowerCase()); - if (sc >= 0) { - scored.push([t, sc]); - } - } - return scored.sort(([, a], [, b]) => b - a).map(([t,]) => t); + const s = sub.toLocaleLowerCase(); + const scored: [T, number][] = []; + for (const t of terms) { + const sc = score(s, map(t).toLocaleLowerCase()); + if (sc >= 0) { + scored.push([t, sc]); + } + } + return scored.sort(([, a], [, b]) => b - a).map(([t]) => t); } diff --git a/zenno/src/routes/doc/race/+page.svelte b/zenno/src/routes/doc/race/+page.svelte index 7c3de9e..4f7442d 100644 --- a/zenno/src/routes/doc/race/+page.svelte +++ b/zenno/src/routes/doc/race/+page.svelte @@ -252,7 +252,7 @@ HP

Max HP, i.e. starting HP.

- {@render statChart(race.Stat.Stamina, hp, 'HP', [1000, 5000], {len: true})} + {@render statChart(race.Stat.Stamina, hp, 'HP', [1000, 5000], { len: true })} Power @@ -270,7 +270,7 @@ Acceleration

Acceleration.

- {@render statChart(race.Stat.Power, accel, 'Acceleration (m/s²)', [0.1, 0.5], {style: true})} + {@render statChart(race.Stat.Power, accel, 'Acceleration (m/s²)', [0.1, 0.5], { style: true })} Lane Change Target Speed

Horizontal (rather than forward) target speed of changing lanes.