feat(web): add async solver worker
This commit is contained in:
@@ -1,15 +1,23 @@
|
||||
<script lang="ts">
|
||||
import { Color } from "wordle-solver";
|
||||
|
||||
let { active=false,
|
||||
cursor=$bindable(0),
|
||||
letters=$bindable(["", "", "", "", ""]),
|
||||
colors=$bindable([Color.GREY, Color.GREY, Color.GREY, Color.GREY, Color.GREY]),
|
||||
info_gained=null } = $props();
|
||||
let {
|
||||
active = false,
|
||||
cursor = $bindable(0),
|
||||
letters = $bindable(["", "", "", "", ""]),
|
||||
colors = $bindable([
|
||||
Color.GREY,
|
||||
Color.GREY,
|
||||
Color.GREY,
|
||||
Color.GREY,
|
||||
Color.GREY,
|
||||
]),
|
||||
info_gained = null,
|
||||
} = $props();
|
||||
|
||||
function handleKey(event: KeyboardEvent) {
|
||||
if (!active) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
if (/^[a-zA-Z]$/.test(event.key)) {
|
||||
letters[cursor] = event.key.toUpperCase();
|
||||
@@ -27,7 +35,7 @@
|
||||
}
|
||||
|
||||
if (active) {
|
||||
letters[cursor] = "";
|
||||
letters[cursor] = "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +73,25 @@
|
||||
{letter}
|
||||
</div>
|
||||
{/each}
|
||||
<span class="w-12 text-sm text-zinc-500 self-center">{
|
||||
(info_gained !== null) ? info_gained.toFixed(2) + "bits" : '↵'
|
||||
}</span>
|
||||
<span
|
||||
class="w-12 text-sm text-zinc-500 self-center flex items-center justify-center"
|
||||
>
|
||||
{#if info_gained === null}
|
||||
↵
|
||||
{:else}
|
||||
{#await info_gained}
|
||||
<div
|
||||
class="size-3 animate-spin rounded-full border-2 border-gray-300 border-t-gray-700"
|
||||
></div>
|
||||
{:then i}
|
||||
{i.toFixed(2)}
|
||||
{:catch e}
|
||||
<span
|
||||
title={e}
|
||||
class="lex size-4 items-center justify-center rounded-full border border-red-500 text-[10px] font-bold text-red-500"
|
||||
>!</span
|
||||
>
|
||||
{/await}
|
||||
{/if}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user