Spaces:
Running
Running
fix analysis
Browse files- src/lib/components/text-analysis/Preview.svelte +2 -2
- src/routes/sverdle/+page.server.ts +0 -69
- src/routes/sverdle/+page.svelte +0 -411
- src/routes/sverdle/game.ts +0 -75
- src/routes/sverdle/how-to-play/+page.svelte +0 -95
- src/routes/sverdle/how-to-play/+page.ts +0 -9
- src/routes/sverdle/reduced-motion.ts +0 -23
- src/routes/sverdle/words.server.ts +0 -0
- src/routes/text-generation/text-analysis/+page.svelte +1 -1
src/lib/components/text-analysis/Preview.svelte
CHANGED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
<script lang="ts">
|
| 2 |
export let body: Record<string, any>;
|
| 3 |
-
export let res:
|
| 4 |
|
| 5 |
|
| 6 |
-
$: progressions =
|
| 7 |
</script>
|
| 8 |
|
| 9 |
<div class="text-white p-6 font-code text-xs !leading-loose grid grid-cols-1 gap-3 w-full max-w-lg">
|
|
|
|
| 1 |
<script lang="ts">
|
| 2 |
export let body: Record<string, any>;
|
| 3 |
+
export let res: any[];
|
| 4 |
|
| 5 |
|
| 6 |
+
$: progressions = res?.length ? res.flat() : []
|
| 7 |
</script>
|
| 8 |
|
| 9 |
<div class="text-white p-6 font-code text-xs !leading-loose grid grid-cols-1 gap-3 w-full max-w-lg">
|
src/routes/sverdle/+page.server.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
| 1 |
-
import { fail } from '@sveltejs/kit';
|
| 2 |
-
import { Game } from './game';
|
| 3 |
-
import type { PageServerLoad, Actions } from './$types';
|
| 4 |
-
|
| 5 |
-
export const load = (({ cookies }) => {
|
| 6 |
-
const game = new Game(cookies.get('sverdle'));
|
| 7 |
-
|
| 8 |
-
return {
|
| 9 |
-
/**
|
| 10 |
-
* The player's guessed words so far
|
| 11 |
-
*/
|
| 12 |
-
guesses: game.guesses,
|
| 13 |
-
|
| 14 |
-
/**
|
| 15 |
-
* An array of strings like '__x_c' corresponding to the guesses, where 'x' means
|
| 16 |
-
* an exact match, and 'c' means a close match (right letter, wrong place)
|
| 17 |
-
*/
|
| 18 |
-
answers: game.answers,
|
| 19 |
-
|
| 20 |
-
/**
|
| 21 |
-
* The correct answer, revealed if the game is over
|
| 22 |
-
*/
|
| 23 |
-
answer: game.answers.length >= 6 ? game.answer : null
|
| 24 |
-
};
|
| 25 |
-
}) satisfies PageServerLoad;
|
| 26 |
-
|
| 27 |
-
export const actions = {
|
| 28 |
-
/**
|
| 29 |
-
* Modify game state in reaction to a keypress. If client-side JavaScript
|
| 30 |
-
* is available, this will happen in the browser instead of here
|
| 31 |
-
*/
|
| 32 |
-
update: async ({ request, cookies }) => {
|
| 33 |
-
const game = new Game(cookies.get('sverdle'));
|
| 34 |
-
|
| 35 |
-
const data = await request.formData();
|
| 36 |
-
const key = data.get('key');
|
| 37 |
-
|
| 38 |
-
const i = game.answers.length;
|
| 39 |
-
|
| 40 |
-
if (key === 'backspace') {
|
| 41 |
-
game.guesses[i] = game.guesses[i].slice(0, -1);
|
| 42 |
-
} else {
|
| 43 |
-
game.guesses[i] += key;
|
| 44 |
-
}
|
| 45 |
-
|
| 46 |
-
cookies.set('sverdle', game.toString());
|
| 47 |
-
},
|
| 48 |
-
|
| 49 |
-
/**
|
| 50 |
-
* Modify game state in reaction to a guessed word. This logic always runs on
|
| 51 |
-
* the server, so that people can't cheat by peeking at the JavaScript
|
| 52 |
-
*/
|
| 53 |
-
enter: async ({ request, cookies }) => {
|
| 54 |
-
const game = new Game(cookies.get('sverdle'));
|
| 55 |
-
|
| 56 |
-
const data = await request.formData();
|
| 57 |
-
const guess = data.getAll('guess') as string[];
|
| 58 |
-
|
| 59 |
-
if (!game.enter(guess)) {
|
| 60 |
-
return fail(400, { badGuess: true });
|
| 61 |
-
}
|
| 62 |
-
|
| 63 |
-
cookies.set('sverdle', game.toString());
|
| 64 |
-
},
|
| 65 |
-
|
| 66 |
-
restart: async ({ cookies }) => {
|
| 67 |
-
cookies.delete('sverdle');
|
| 68 |
-
}
|
| 69 |
-
} satisfies Actions;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/routes/sverdle/+page.svelte
DELETED
|
@@ -1,411 +0,0 @@
|
|
| 1 |
-
<script lang="ts">
|
| 2 |
-
import { confetti } from '@neoconfetti/svelte';
|
| 3 |
-
import { enhance } from '$app/forms';
|
| 4 |
-
import type { PageData, ActionData } from './$types';
|
| 5 |
-
import { reduced_motion } from './reduced-motion';
|
| 6 |
-
|
| 7 |
-
export let data: PageData;
|
| 8 |
-
|
| 9 |
-
export let form: ActionData;
|
| 10 |
-
|
| 11 |
-
/** Whether or not the user has won */
|
| 12 |
-
$: won = data.answers.at(-1) === 'xxxxx';
|
| 13 |
-
|
| 14 |
-
/** The index of the current guess */
|
| 15 |
-
$: i = won ? -1 : data.answers.length;
|
| 16 |
-
|
| 17 |
-
/** The current guess */
|
| 18 |
-
$: currentGuess = data.guesses[i] || '';
|
| 19 |
-
|
| 20 |
-
/** Whether the current guess can be submitted */
|
| 21 |
-
$: submittable = currentGuess.length === 5;
|
| 22 |
-
|
| 23 |
-
/**
|
| 24 |
-
* A map of classnames for all letters that have been guessed,
|
| 25 |
-
* used for styling the keyboard
|
| 26 |
-
*/
|
| 27 |
-
let classnames: Record<string, 'exact' | 'close' | 'missing'>;
|
| 28 |
-
|
| 29 |
-
/**
|
| 30 |
-
* A map of descriptions for all letters that have been guessed,
|
| 31 |
-
* used for adding text for assistive technology (e.g. screen readers)
|
| 32 |
-
*/
|
| 33 |
-
let description: Record<string, string>;
|
| 34 |
-
|
| 35 |
-
$: {
|
| 36 |
-
classnames = {};
|
| 37 |
-
description = {};
|
| 38 |
-
|
| 39 |
-
data.answers.forEach((answer, i) => {
|
| 40 |
-
const guess = data.guesses[i];
|
| 41 |
-
|
| 42 |
-
for (let i = 0; i < 5; i += 1) {
|
| 43 |
-
const letter = guess[i];
|
| 44 |
-
|
| 45 |
-
if (answer[i] === 'x') {
|
| 46 |
-
classnames[letter] = 'exact';
|
| 47 |
-
description[letter] = 'correct';
|
| 48 |
-
} else if (!classnames[letter]) {
|
| 49 |
-
classnames[letter] = answer[i] === 'c' ? 'close' : 'missing';
|
| 50 |
-
description[letter] = answer[i] === 'c' ? 'present' : 'absent';
|
| 51 |
-
}
|
| 52 |
-
}
|
| 53 |
-
});
|
| 54 |
-
}
|
| 55 |
-
|
| 56 |
-
/**
|
| 57 |
-
* Modify the game state without making a trip to the server,
|
| 58 |
-
* if client-side JavaScript is enabled
|
| 59 |
-
*/
|
| 60 |
-
function update(event: MouseEvent) {
|
| 61 |
-
const key = (event.target as HTMLButtonElement).getAttribute(
|
| 62 |
-
'data-key'
|
| 63 |
-
);
|
| 64 |
-
|
| 65 |
-
if (key === 'backspace') {
|
| 66 |
-
currentGuess = currentGuess.slice(0, -1);
|
| 67 |
-
if (form?.badGuess) form.badGuess = false;
|
| 68 |
-
} else if (currentGuess.length < 5) {
|
| 69 |
-
currentGuess += key;
|
| 70 |
-
}
|
| 71 |
-
}
|
| 72 |
-
|
| 73 |
-
/**
|
| 74 |
-
* Trigger form logic in response to a keydown event, so that
|
| 75 |
-
* desktop users can use the keyboard to play the game
|
| 76 |
-
*/
|
| 77 |
-
function keydown(event: KeyboardEvent) {
|
| 78 |
-
if (event.metaKey) return;
|
| 79 |
-
|
| 80 |
-
if (event.key === 'Enter' && !submittable) return;
|
| 81 |
-
|
| 82 |
-
document
|
| 83 |
-
.querySelector(`[data-key="${event.key}" i]`)
|
| 84 |
-
?.dispatchEvent(new MouseEvent('click', { cancelable: true }));
|
| 85 |
-
}
|
| 86 |
-
</script>
|
| 87 |
-
|
| 88 |
-
<svelte:window on:keydown={keydown} />
|
| 89 |
-
|
| 90 |
-
<svelte:head>
|
| 91 |
-
<title>Sverdle</title>
|
| 92 |
-
<meta name="description" content="A Wordle clone written in SvelteKit" />
|
| 93 |
-
</svelte:head>
|
| 94 |
-
|
| 95 |
-
<h1 class="visually-hidden">Sverdle</h1>
|
| 96 |
-
|
| 97 |
-
<form
|
| 98 |
-
method="POST"
|
| 99 |
-
action="?/enter"
|
| 100 |
-
use:enhance={() => {
|
| 101 |
-
// prevent default callback from resetting the form
|
| 102 |
-
return ({ update }) => {
|
| 103 |
-
update({ reset: false });
|
| 104 |
-
};
|
| 105 |
-
}}
|
| 106 |
-
>
|
| 107 |
-
<a class="how-to-play" href="/sverdle/how-to-play">How to play</a>
|
| 108 |
-
|
| 109 |
-
<div class="grid" class:playing={!won} class:bad-guess={form?.badGuess}>
|
| 110 |
-
{#each Array.from(Array(6).keys()) as row (row)}
|
| 111 |
-
{@const current = row === i}
|
| 112 |
-
<h2 class="visually-hidden">Row {row + 1}</h2>
|
| 113 |
-
<div class="row" class:current>
|
| 114 |
-
{#each Array.from(Array(5).keys()) as column (column)}
|
| 115 |
-
{@const guess = current ? currentGuess : data.guesses[row]}
|
| 116 |
-
{@const answer = data.answers[row]?.[column]}
|
| 117 |
-
{@const value = guess?.[column] ?? ''}
|
| 118 |
-
{@const selected = current && column === guess.length}
|
| 119 |
-
{@const exact = answer === 'x'}
|
| 120 |
-
{@const close = answer === 'c'}
|
| 121 |
-
{@const missing = answer === '_'}
|
| 122 |
-
<div class="letter" class:exact class:close class:missing class:selected>
|
| 123 |
-
{value}
|
| 124 |
-
<span class="visually-hidden">
|
| 125 |
-
{#if exact}
|
| 126 |
-
(correct)
|
| 127 |
-
{:else if close}
|
| 128 |
-
(present)
|
| 129 |
-
{:else if missing}
|
| 130 |
-
(absent)
|
| 131 |
-
{:else}
|
| 132 |
-
empty
|
| 133 |
-
{/if}
|
| 134 |
-
</span>
|
| 135 |
-
<input name="guess" disabled={!current} type="hidden" {value} />
|
| 136 |
-
</div>
|
| 137 |
-
{/each}
|
| 138 |
-
</div>
|
| 139 |
-
{/each}
|
| 140 |
-
</div>
|
| 141 |
-
|
| 142 |
-
<div class="controls">
|
| 143 |
-
{#if won || data.answers.length >= 6}
|
| 144 |
-
{#if !won && data.answer}
|
| 145 |
-
<p>the answer was "{data.answer}"</p>
|
| 146 |
-
{/if}
|
| 147 |
-
<button data-key="enter" class="restart selected" formaction="?/restart">
|
| 148 |
-
{won ? 'you won :)' : `game over :(`} play again?
|
| 149 |
-
</button>
|
| 150 |
-
{:else}
|
| 151 |
-
<div class="keyboard">
|
| 152 |
-
<button data-key="enter" class:selected={submittable} disabled={!submittable}>enter</button>
|
| 153 |
-
|
| 154 |
-
<button
|
| 155 |
-
on:click|preventDefault={update}
|
| 156 |
-
data-key="backspace"
|
| 157 |
-
formaction="?/update"
|
| 158 |
-
name="key"
|
| 159 |
-
value="backspace"
|
| 160 |
-
>
|
| 161 |
-
back
|
| 162 |
-
</button>
|
| 163 |
-
|
| 164 |
-
{#each ['qwertyuiop', 'asdfghjkl', 'zxcvbnm'] as row}
|
| 165 |
-
<div class="row">
|
| 166 |
-
{#each row as letter}
|
| 167 |
-
<button
|
| 168 |
-
on:click|preventDefault={update}
|
| 169 |
-
data-key={letter}
|
| 170 |
-
class={classnames[letter]}
|
| 171 |
-
disabled={submittable}
|
| 172 |
-
formaction="?/update"
|
| 173 |
-
name="key"
|
| 174 |
-
value={letter}
|
| 175 |
-
aria-label="{letter} {description[letter] || ''}"
|
| 176 |
-
>
|
| 177 |
-
{letter}
|
| 178 |
-
</button>
|
| 179 |
-
{/each}
|
| 180 |
-
</div>
|
| 181 |
-
{/each}
|
| 182 |
-
</div>
|
| 183 |
-
{/if}
|
| 184 |
-
</div>
|
| 185 |
-
</form>
|
| 186 |
-
|
| 187 |
-
{#if won}
|
| 188 |
-
<div
|
| 189 |
-
style="position: absolute; left: 50%; top: 30%"
|
| 190 |
-
use:confetti={{
|
| 191 |
-
particleCount: $reduced_motion ? 0 : undefined,
|
| 192 |
-
force: 0.7,
|
| 193 |
-
stageWidth: window.innerWidth,
|
| 194 |
-
stageHeight: window.innerHeight,
|
| 195 |
-
colors: ['#ff3e00', '#40b3ff', '#676778']
|
| 196 |
-
}}
|
| 197 |
-
/>
|
| 198 |
-
{/if}
|
| 199 |
-
|
| 200 |
-
<style>
|
| 201 |
-
form {
|
| 202 |
-
width: 100%;
|
| 203 |
-
height: 100%;
|
| 204 |
-
display: flex;
|
| 205 |
-
flex-direction: column;
|
| 206 |
-
align-items: center;
|
| 207 |
-
justify-content: center;
|
| 208 |
-
gap: 1rem;
|
| 209 |
-
flex: 1;
|
| 210 |
-
}
|
| 211 |
-
|
| 212 |
-
.how-to-play {
|
| 213 |
-
color: var(--color-text);
|
| 214 |
-
}
|
| 215 |
-
|
| 216 |
-
.how-to-play::before {
|
| 217 |
-
content: 'i';
|
| 218 |
-
display: inline-block;
|
| 219 |
-
font-size: 0.8em;
|
| 220 |
-
font-weight: 900;
|
| 221 |
-
width: 1em;
|
| 222 |
-
height: 1em;
|
| 223 |
-
padding: 0.2em;
|
| 224 |
-
line-height: 1;
|
| 225 |
-
border: 1.5px solid var(--color-text);
|
| 226 |
-
border-radius: 50%;
|
| 227 |
-
text-align: center;
|
| 228 |
-
margin: 0 0.5em 0 0;
|
| 229 |
-
position: relative;
|
| 230 |
-
top: -0.05em;
|
| 231 |
-
}
|
| 232 |
-
|
| 233 |
-
.grid {
|
| 234 |
-
--width: min(100vw, 40vh, 380px);
|
| 235 |
-
max-width: var(--width);
|
| 236 |
-
align-self: center;
|
| 237 |
-
justify-self: center;
|
| 238 |
-
width: 100%;
|
| 239 |
-
height: 100%;
|
| 240 |
-
display: flex;
|
| 241 |
-
flex-direction: column;
|
| 242 |
-
justify-content: flex-start;
|
| 243 |
-
}
|
| 244 |
-
|
| 245 |
-
.grid .row {
|
| 246 |
-
display: grid;
|
| 247 |
-
grid-template-columns: repeat(5, 1fr);
|
| 248 |
-
grid-gap: 0.2rem;
|
| 249 |
-
margin: 0 0 0.2rem 0;
|
| 250 |
-
}
|
| 251 |
-
|
| 252 |
-
@media (prefers-reduced-motion: no-preference) {
|
| 253 |
-
.grid.bad-guess .row.current {
|
| 254 |
-
animation: wiggle 0.5s;
|
| 255 |
-
}
|
| 256 |
-
}
|
| 257 |
-
|
| 258 |
-
.grid.playing .row.current {
|
| 259 |
-
filter: drop-shadow(3px 3px 10px var(--color-bg-0));
|
| 260 |
-
}
|
| 261 |
-
|
| 262 |
-
.letter {
|
| 263 |
-
aspect-ratio: 1;
|
| 264 |
-
width: 100%;
|
| 265 |
-
display: flex;
|
| 266 |
-
align-items: center;
|
| 267 |
-
justify-content: center;
|
| 268 |
-
text-align: center;
|
| 269 |
-
box-sizing: border-box;
|
| 270 |
-
text-transform: lowercase;
|
| 271 |
-
border: none;
|
| 272 |
-
font-size: calc(0.08 * var(--width));
|
| 273 |
-
border-radius: 2px;
|
| 274 |
-
background: white;
|
| 275 |
-
margin: 0;
|
| 276 |
-
color: rgba(0, 0, 0, 0.7);
|
| 277 |
-
}
|
| 278 |
-
|
| 279 |
-
.letter.missing {
|
| 280 |
-
background: rgba(255, 255, 255, 0.5);
|
| 281 |
-
color: rgba(0, 0, 0, 0.5);
|
| 282 |
-
}
|
| 283 |
-
|
| 284 |
-
.letter.exact {
|
| 285 |
-
background: var(--color-theme-2);
|
| 286 |
-
color: white;
|
| 287 |
-
}
|
| 288 |
-
|
| 289 |
-
.letter.close {
|
| 290 |
-
border: 2px solid var(--color-theme-2);
|
| 291 |
-
}
|
| 292 |
-
|
| 293 |
-
.selected {
|
| 294 |
-
outline: 2px solid var(--color-theme-1);
|
| 295 |
-
}
|
| 296 |
-
|
| 297 |
-
.controls {
|
| 298 |
-
text-align: center;
|
| 299 |
-
justify-content: center;
|
| 300 |
-
height: min(18vh, 10rem);
|
| 301 |
-
}
|
| 302 |
-
|
| 303 |
-
.keyboard {
|
| 304 |
-
--gap: 0.2rem;
|
| 305 |
-
position: relative;
|
| 306 |
-
display: flex;
|
| 307 |
-
flex-direction: column;
|
| 308 |
-
gap: var(--gap);
|
| 309 |
-
height: 100%;
|
| 310 |
-
}
|
| 311 |
-
|
| 312 |
-
.keyboard .row {
|
| 313 |
-
display: flex;
|
| 314 |
-
justify-content: center;
|
| 315 |
-
gap: 0.2rem;
|
| 316 |
-
flex: 1;
|
| 317 |
-
}
|
| 318 |
-
|
| 319 |
-
.keyboard button,
|
| 320 |
-
.keyboard button:disabled {
|
| 321 |
-
--size: min(8vw, 4vh, 40px);
|
| 322 |
-
background-color: white;
|
| 323 |
-
color: black;
|
| 324 |
-
width: var(--size);
|
| 325 |
-
border: none;
|
| 326 |
-
border-radius: 2px;
|
| 327 |
-
font-size: calc(var(--size) * 0.5);
|
| 328 |
-
margin: 0;
|
| 329 |
-
}
|
| 330 |
-
|
| 331 |
-
.keyboard button.exact {
|
| 332 |
-
background: var(--color-theme-2);
|
| 333 |
-
color: white;
|
| 334 |
-
}
|
| 335 |
-
|
| 336 |
-
.keyboard button.missing {
|
| 337 |
-
opacity: 0.5;
|
| 338 |
-
}
|
| 339 |
-
|
| 340 |
-
.keyboard button.close {
|
| 341 |
-
border: 2px solid var(--color-theme-2);
|
| 342 |
-
}
|
| 343 |
-
|
| 344 |
-
.keyboard button:focus {
|
| 345 |
-
background: var(--color-theme-1);
|
| 346 |
-
color: white;
|
| 347 |
-
outline: none;
|
| 348 |
-
}
|
| 349 |
-
|
| 350 |
-
.keyboard button[data-key='enter'],
|
| 351 |
-
.keyboard button[data-key='backspace'] {
|
| 352 |
-
position: absolute;
|
| 353 |
-
bottom: 0;
|
| 354 |
-
width: calc(1.5 * var(--size));
|
| 355 |
-
height: calc(1 / 3 * (100% - 2 * var(--gap)));
|
| 356 |
-
text-transform: uppercase;
|
| 357 |
-
font-size: calc(0.3 * var(--size));
|
| 358 |
-
padding-top: calc(0.15 * var(--size));
|
| 359 |
-
}
|
| 360 |
-
|
| 361 |
-
.keyboard button[data-key='enter'] {
|
| 362 |
-
right: calc(50% + 3.5 * var(--size) + 0.8rem);
|
| 363 |
-
}
|
| 364 |
-
|
| 365 |
-
.keyboard button[data-key='backspace'] {
|
| 366 |
-
left: calc(50% + 3.5 * var(--size) + 0.8rem);
|
| 367 |
-
}
|
| 368 |
-
|
| 369 |
-
.keyboard button[data-key='enter']:disabled {
|
| 370 |
-
opacity: 0.5;
|
| 371 |
-
}
|
| 372 |
-
|
| 373 |
-
.restart {
|
| 374 |
-
width: 100%;
|
| 375 |
-
padding: 1rem;
|
| 376 |
-
background: rgba(255, 255, 255, 0.5);
|
| 377 |
-
border-radius: 2px;
|
| 378 |
-
border: none;
|
| 379 |
-
}
|
| 380 |
-
|
| 381 |
-
.restart:focus,
|
| 382 |
-
.restart:hover {
|
| 383 |
-
background: var(--color-theme-1);
|
| 384 |
-
color: white;
|
| 385 |
-
outline: none;
|
| 386 |
-
}
|
| 387 |
-
|
| 388 |
-
@keyframes wiggle {
|
| 389 |
-
0% {
|
| 390 |
-
transform: translateX(0);
|
| 391 |
-
}
|
| 392 |
-
10% {
|
| 393 |
-
transform: translateX(-2px);
|
| 394 |
-
}
|
| 395 |
-
30% {
|
| 396 |
-
transform: translateX(4px);
|
| 397 |
-
}
|
| 398 |
-
50% {
|
| 399 |
-
transform: translateX(-6px);
|
| 400 |
-
}
|
| 401 |
-
70% {
|
| 402 |
-
transform: translateX(+4px);
|
| 403 |
-
}
|
| 404 |
-
90% {
|
| 405 |
-
transform: translateX(-2px);
|
| 406 |
-
}
|
| 407 |
-
100% {
|
| 408 |
-
transform: translateX(0);
|
| 409 |
-
}
|
| 410 |
-
}
|
| 411 |
-
</style>
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/routes/sverdle/game.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
| 1 |
-
import { words, allowed } from './words.server';
|
| 2 |
-
|
| 3 |
-
export class Game {
|
| 4 |
-
index: number;
|
| 5 |
-
guesses: string[];
|
| 6 |
-
answers: string[];
|
| 7 |
-
answer: string;
|
| 8 |
-
|
| 9 |
-
/**
|
| 10 |
-
* Create a game object from the player's cookie, or initialise a new game
|
| 11 |
-
*/
|
| 12 |
-
constructor(serialized: string | undefined = undefined) {
|
| 13 |
-
if (serialized) {
|
| 14 |
-
const [index, guesses, answers] = serialized.split('-');
|
| 15 |
-
|
| 16 |
-
this.index = +index;
|
| 17 |
-
this.guesses = guesses ? guesses.split(' ') : [];
|
| 18 |
-
this.answers = answers ? answers.split(' ') : [];
|
| 19 |
-
} else {
|
| 20 |
-
this.index = Math.floor(Math.random() * words.length);
|
| 21 |
-
this.guesses = ['', '', '', '', '', ''];
|
| 22 |
-
this.answers = [];
|
| 23 |
-
}
|
| 24 |
-
|
| 25 |
-
this.answer = words[this.index];
|
| 26 |
-
}
|
| 27 |
-
|
| 28 |
-
/**
|
| 29 |
-
* Update game state based on a guess of a five-letter word. Returns
|
| 30 |
-
* true if the guess was valid, false otherwise
|
| 31 |
-
*/
|
| 32 |
-
enter(letters: string[]) {
|
| 33 |
-
const word = letters.join('');
|
| 34 |
-
const valid = allowed.has(word);
|
| 35 |
-
|
| 36 |
-
if (!valid) return false;
|
| 37 |
-
|
| 38 |
-
this.guesses[this.answers.length] = word;
|
| 39 |
-
|
| 40 |
-
const available = Array.from(this.answer);
|
| 41 |
-
const answer = Array(5).fill('_');
|
| 42 |
-
|
| 43 |
-
// first, find exact matches
|
| 44 |
-
for (let i = 0; i < 5; i += 1) {
|
| 45 |
-
if (letters[i] === available[i]) {
|
| 46 |
-
answer[i] = 'x';
|
| 47 |
-
available[i] = ' ';
|
| 48 |
-
}
|
| 49 |
-
}
|
| 50 |
-
|
| 51 |
-
// then find close matches (this has to happen
|
| 52 |
-
// in a second step, otherwise an early close
|
| 53 |
-
// match can prevent a later exact match)
|
| 54 |
-
for (let i = 0; i < 5; i += 1) {
|
| 55 |
-
if (answer[i] === '_') {
|
| 56 |
-
const index = available.indexOf(letters[i]);
|
| 57 |
-
if (index !== -1) {
|
| 58 |
-
answer[i] = 'c';
|
| 59 |
-
available[index] = ' ';
|
| 60 |
-
}
|
| 61 |
-
}
|
| 62 |
-
}
|
| 63 |
-
|
| 64 |
-
this.answers.push(answer.join(''));
|
| 65 |
-
|
| 66 |
-
return true;
|
| 67 |
-
}
|
| 68 |
-
|
| 69 |
-
/**
|
| 70 |
-
* Serialize game state so it can be set as a cookie
|
| 71 |
-
*/
|
| 72 |
-
toString() {
|
| 73 |
-
return `${this.index}-${this.guesses.join(' ')}-${this.answers.join(' ')}`;
|
| 74 |
-
}
|
| 75 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/routes/sverdle/how-to-play/+page.svelte
DELETED
|
@@ -1,95 +0,0 @@
|
|
| 1 |
-
<svelte:head>
|
| 2 |
-
<title>How to play Sverdle</title>
|
| 3 |
-
<meta name="description" content="How to play Sverdle" />
|
| 4 |
-
</svelte:head>
|
| 5 |
-
|
| 6 |
-
<div class="text-column">
|
| 7 |
-
<h1>How to play Sverdle</h1>
|
| 8 |
-
|
| 9 |
-
<p>
|
| 10 |
-
Sverdle is a clone of <a href="https://www.nytimes.com/games/wordle/index.html">Wordle</a>, the
|
| 11 |
-
word guessing game. To play, enter a five-letter English word. For example:
|
| 12 |
-
</p>
|
| 13 |
-
|
| 14 |
-
<div class="example">
|
| 15 |
-
<span class="close">r</span>
|
| 16 |
-
<span class="missing">i</span>
|
| 17 |
-
<span class="close">t</span>
|
| 18 |
-
<span class="missing">z</span>
|
| 19 |
-
<span class="exact">y</span>
|
| 20 |
-
</div>
|
| 21 |
-
|
| 22 |
-
<p>
|
| 23 |
-
The <span class="exact">y</span> is in the right place. <span class="close">r</span> and
|
| 24 |
-
<span class="close">t</span>
|
| 25 |
-
are the right letters, but in the wrong place. The other letters are wrong, and can be discarded.
|
| 26 |
-
Let's make another guess:
|
| 27 |
-
</p>
|
| 28 |
-
|
| 29 |
-
<div class="example">
|
| 30 |
-
<span class="exact">p</span>
|
| 31 |
-
<span class="exact">a</span>
|
| 32 |
-
<span class="exact">r</span>
|
| 33 |
-
<span class="exact">t</span>
|
| 34 |
-
<span class="exact">y</span>
|
| 35 |
-
</div>
|
| 36 |
-
|
| 37 |
-
<p>This time we guessed right! You have <strong>six</strong> guesses to get the word.</p>
|
| 38 |
-
|
| 39 |
-
<p>
|
| 40 |
-
Unlike the original Wordle, Sverdle runs on the server instead of in the browser, making it
|
| 41 |
-
impossible to cheat. It uses <code><form></code> and cookies to submit data, meaning you can
|
| 42 |
-
even play with JavaScript disabled!
|
| 43 |
-
</p>
|
| 44 |
-
</div>
|
| 45 |
-
|
| 46 |
-
<style>
|
| 47 |
-
span {
|
| 48 |
-
display: inline-flex;
|
| 49 |
-
justify-content: center;
|
| 50 |
-
align-items: center;
|
| 51 |
-
font-size: 0.8em;
|
| 52 |
-
width: 2.4em;
|
| 53 |
-
height: 2.4em;
|
| 54 |
-
background-color: white;
|
| 55 |
-
box-sizing: border-box;
|
| 56 |
-
border-radius: 2px;
|
| 57 |
-
border-width: 2px;
|
| 58 |
-
color: rgba(0, 0, 0, 0.7);
|
| 59 |
-
}
|
| 60 |
-
|
| 61 |
-
.missing {
|
| 62 |
-
background: rgba(255, 255, 255, 0.5);
|
| 63 |
-
color: rgba(0, 0, 0, 0.5);
|
| 64 |
-
}
|
| 65 |
-
|
| 66 |
-
.close {
|
| 67 |
-
border-style: solid;
|
| 68 |
-
border-color: var(--color-theme-2);
|
| 69 |
-
}
|
| 70 |
-
|
| 71 |
-
.exact {
|
| 72 |
-
background: var(--color-theme-2);
|
| 73 |
-
color: white;
|
| 74 |
-
}
|
| 75 |
-
|
| 76 |
-
.example {
|
| 77 |
-
display: flex;
|
| 78 |
-
justify-content: flex-start;
|
| 79 |
-
margin: 1rem 0;
|
| 80 |
-
gap: 0.2rem;
|
| 81 |
-
}
|
| 82 |
-
|
| 83 |
-
.example span {
|
| 84 |
-
font-size: 1.4rem;
|
| 85 |
-
}
|
| 86 |
-
|
| 87 |
-
p span {
|
| 88 |
-
position: relative;
|
| 89 |
-
border-width: 1px;
|
| 90 |
-
border-radius: 1px;
|
| 91 |
-
font-size: 0.4em;
|
| 92 |
-
transform: scale(2) translate(0, -10%);
|
| 93 |
-
margin: 0 1em;
|
| 94 |
-
}
|
| 95 |
-
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/routes/sverdle/how-to-play/+page.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
| 1 |
-
import { dev } from '$app/environment';
|
| 2 |
-
|
| 3 |
-
// we don't need any JS on this page, though we'll load
|
| 4 |
-
// it in dev so that we get hot module replacement
|
| 5 |
-
export const csr = dev;
|
| 6 |
-
|
| 7 |
-
// since there's no dynamic data here, we can prerender
|
| 8 |
-
// it so that it gets served as a static asset in production
|
| 9 |
-
export const prerender = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/routes/sverdle/reduced-motion.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
| 1 |
-
import { readable } from 'svelte/store';
|
| 2 |
-
import { browser } from '$app/environment';
|
| 3 |
-
|
| 4 |
-
const reduced_motion_query = '(prefers-reduced-motion: reduce)';
|
| 5 |
-
|
| 6 |
-
const get_initial_motion_preference = () => {
|
| 7 |
-
if (!browser) return false;
|
| 8 |
-
return window.matchMedia(reduced_motion_query).matches;
|
| 9 |
-
};
|
| 10 |
-
|
| 11 |
-
export const reduced_motion = readable(get_initial_motion_preference(), (set) => {
|
| 12 |
-
if (browser) {
|
| 13 |
-
const set_reduced_motion = (event: MediaQueryListEvent) => {
|
| 14 |
-
set(event.matches);
|
| 15 |
-
};
|
| 16 |
-
const media_query_list = window.matchMedia(reduced_motion_query);
|
| 17 |
-
media_query_list.addEventListener('change', set_reduced_motion);
|
| 18 |
-
|
| 19 |
-
return () => {
|
| 20 |
-
media_query_list.removeEventListener('change', set_reduced_motion);
|
| 21 |
-
};
|
| 22 |
-
}
|
| 23 |
-
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/routes/sverdle/words.server.ts
DELETED
|
The diff for this file is too large to render.
See raw diff
|
|
|
src/routes/text-generation/text-analysis/+page.svelte
CHANGED
|
@@ -43,7 +43,7 @@
|
|
| 43 |
{#if loading}
|
| 44 |
<Loading />
|
| 45 |
{/if}
|
| 46 |
-
|
| 47 |
</button>
|
| 48 |
</div>
|
| 49 |
</div>
|
|
|
|
| 43 |
{#if loading}
|
| 44 |
<Loading />
|
| 45 |
{/if}
|
| 46 |
+
Analyze
|
| 47 |
</button>
|
| 48 |
</div>
|
| 49 |
</div>
|