diff --git a/.vscode/settings.json b/.vscode/settings.json index 12f4eb8..6299696 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -16,5 +16,8 @@ }, "[tailwindcss]": { "editor.defaultFormatter": "biomejs.biome" + }, + "[xml]": { + "editor.defaultFormatter": "biomejs.biome" } } diff --git a/apps/bulls-and-cows/package.json b/apps/bulls-and-cows/package.json index 3fa575a..6d1de85 100644 --- a/apps/bulls-and-cows/package.json +++ b/apps/bulls-and-cows/package.json @@ -22,6 +22,7 @@ "@tailwindcss/vite": "catalog:", "@unplugin-pwa/core": "catalog:", "@vite-pwa/astro": "catalog:", + "@vite-pwa/workbox-swkit": "catalog:", "@vite-pwa/workbox-window": "catalog:", "magicast": "catalog:", "rolldown": "catalog:", diff --git a/apps/bulls-and-cows/src/env.d.ts b/apps/bulls-and-cows/src/env.d.ts index 3c69371..5ac56e6 100644 --- a/apps/bulls-and-cows/src/env.d.ts +++ b/apps/bulls-and-cows/src/env.d.ts @@ -1,6 +1,7 @@ /// /// +/// /// /// /// diff --git a/apps/bulls-and-cows/src/pages/index.astro b/apps/bulls-and-cows/src/pages/index.astro index 74f8af2..6be3cc3 100644 --- a/apps/bulls-and-cows/src/pages/index.astro +++ b/apps/bulls-and-cows/src/pages/index.astro @@ -5,7 +5,7 @@ import Layout from "#layout"; const id = "bulls-and-cows"; const title = "Bulls and Cows"; -const canonical = `https://games.rman.dev/${id}`; +const canonical = `https://${id}.rman.dev/`; const description = `Classic Bulls and Cows game. Play on ${canonical}`; --- diff --git a/apps/wordle/astro.config.ts b/apps/wordle/astro.config.ts index 7214bdd..70f236e 100644 --- a/apps/wordle/astro.config.ts +++ b/apps/wordle/astro.config.ts @@ -1,10 +1,23 @@ import solid from "@astrojs/solid-js"; import tailwindcss from "@tailwindcss/vite"; +import { AstroPWAIntegration } from "@vite-pwa/astro"; import { defineConfig } from "astro/config"; export default defineConfig({ - output: "static", - integrations: [solid()], + integrations: [ + solid(), + AstroPWAIntegration({ + manifest: { + name: "Wordle", + short_name: "Wordle", + theme_color: "#6AAA64", + icons: [ + { src: "icons/192x192.png", sizes: "192x192", type: "image/png" }, + { src: "icons/512x512.png", sizes: "512x512", type: "image/png" }, + ], + }, + }), + ], vite: { plugins: [tailwindcss()], build: { cssTarget: "safari15" } }, site: "https://wordle.rman.dev", }); diff --git a/apps/wordle/package.json b/apps/wordle/package.json index e588524..08d3fa8 100644 --- a/apps/wordle/package.json +++ b/apps/wordle/package.json @@ -25,6 +25,12 @@ "devDependencies": { "@astrojs/solid-js": "catalog:", "@tailwindcss/vite": "catalog:", + "@unplugin-pwa/core": "catalog:", + "@vite-pwa/astro": "catalog:", + "@vite-pwa/workbox-swkit": "catalog:", + "@vite-pwa/workbox-window": "catalog:", + "magicast": "catalog:", + "rolldown": "catalog:", "wrangler": "catalog:" } } diff --git a/apps/wordle/public/favicon.ico b/apps/wordle/public/favicon.ico new file mode 100644 index 0000000..9bc9b08 Binary files /dev/null and b/apps/wordle/public/favicon.ico differ diff --git a/apps/wordle/public/images/wordle.png b/apps/wordle/public/icons/192x192.png similarity index 100% rename from apps/wordle/public/images/wordle.png rename to apps/wordle/public/icons/192x192.png diff --git a/apps/wordle/public/icons/512x512.png b/apps/wordle/public/icons/512x512.png new file mode 100644 index 0000000..c6a6a8a Binary files /dev/null and b/apps/wordle/public/icons/512x512.png differ diff --git a/apps/wordle/public/images/wordle.svg b/apps/wordle/public/icons/wordle.svg similarity index 100% rename from apps/wordle/public/images/wordle.svg rename to apps/wordle/public/icons/wordle.svg diff --git a/apps/wordle/src/config.ts b/apps/wordle/src/config.ts index 2618336..997eb4c 100644 --- a/apps/wordle/src/config.ts +++ b/apps/wordle/src/config.ts @@ -1,6 +1,21 @@ +import answersRaw from "./data/answers.txt?raw"; +import guessesRaw from "./data/guesses.txt?raw"; + +function parseWords(raw: string): string[] { + return raw + .split("\n") + .map((word) => word.trim()) + .filter(Boolean); +} + +const answers = parseWords(answersRaw); + export const WORDS = { - guesses: [] as string[], - answers: [] as string[], + guesses: new Set(parseWords(guessesRaw).concat(answers)), + answers, + + answersRaw, + guessesRaw, }; export const CONFIG = { @@ -14,8 +29,5 @@ export const CONFIG = { AZERTY: ["AZERTYUIOP", "QSDFGHJKLM", "WXCVBN"], }, - dataUrls: { - guesses: "/data/guesses.txt", - answers: "/data/answers.txt", - }, + gameUrl: "https://wordle.rman.dev/", } as const; diff --git a/apps/wordle/public/data/answers.txt b/apps/wordle/src/data/answers.txt similarity index 100% rename from apps/wordle/public/data/answers.txt rename to apps/wordle/src/data/answers.txt diff --git a/apps/wordle/public/data/guesses.txt b/apps/wordle/src/data/guesses.txt similarity index 100% rename from apps/wordle/public/data/guesses.txt rename to apps/wordle/src/data/guesses.txt diff --git a/apps/wordle/src/env.d.ts b/apps/wordle/src/env.d.ts new file mode 100644 index 0000000..5ac56e6 --- /dev/null +++ b/apps/wordle/src/env.d.ts @@ -0,0 +1,9 @@ +/// +/// + +/// +/// +/// +/// + +declare module "#styles" {} diff --git a/apps/wordle/src/hooks/useGame.ts b/apps/wordle/src/hooks/useGame.ts index acb0334..573de49 100644 --- a/apps/wordle/src/hooks/useGame.ts +++ b/apps/wordle/src/hooks/useGame.ts @@ -107,7 +107,7 @@ export function useGame() { } async function submitGuess(guess: string) { - if (!WORDS.guesses.includes(guess)) { + if (!WORDS.guesses.has(guess)) { await shakeCurrentRow(); showNotification(`Word ${guess.toUpperCase()} does not exist`); return; @@ -144,25 +144,6 @@ export function useGame() { }); } - async function fetchWords() { - try { - const [guessesString, answersString] = await Promise.all([ - fetch(CONFIG.dataUrls.guesses).then((r) => r.text()), - fetch(CONFIG.dataUrls.answers).then((r) => r.text()), - ]); - - const guesses = guessesString.split("\n").map((word) => word.trim()); - const answers = answersString.split("\n").map((word) => word.trim()); - - WORDS.guesses = guesses.concat(answers); - WORDS.answers = answers; - } catch (error) { - console.error("Error fetching words:", error); - } - - return WORDS; - } - function handleBoardAction(action: BoardAction) { if (getState() !== "playing") return; @@ -231,7 +212,7 @@ export function useGame() { } function init() { - fetchWords().then(() => startNewGame("daily")); + startNewGame("daily"); document.addEventListener("keydown", (event) => { const action = getBoardAction(event); if (!action) return; diff --git a/apps/wordle/src/layouts/Layout.astro b/apps/wordle/src/layouts/Layout.astro index 1a158ca..2c32d0b 100644 --- a/apps/wordle/src/layouts/Layout.astro +++ b/apps/wordle/src/layouts/Layout.astro @@ -1,15 +1,20 @@ --- import "#styles"; +import { pwaInfo } from "virtual:pwa-info"; + +import type { JSXElement } from "solid-js"; + interface Props { title: string; description: string; canonical: string; - thumbnail: string; - children: unknown; + children: () => JSXElement; } -const { title, description, canonical, thumbnail } = Astro.props; +const { title, description, canonical } = Astro.props; + +const thumbnail = "/icons/512x512.png"; --- @@ -33,7 +38,17 @@ const { title, description, canonical, thumbnail } = Astro.props; - + + + + + {pwaInfo && } + + diff --git a/apps/wordle/src/lib/get-guess-patern.ts b/apps/wordle/src/lib/get-guess-patern.ts index 0402f54..0f607fa 100644 --- a/apps/wordle/src/lib/get-guess-patern.ts +++ b/apps/wordle/src/lib/get-guess-patern.ts @@ -4,18 +4,18 @@ import { getTileColors } from "./get-tile-colors"; type PatternSymbol = "🟩" | "🟨" | "⬛"; +const colorMap = { + absent: "⬛", + present: "🟨", + correct: "🟩", +} as const satisfies Record; + function getGuessPattern( guesses: readonly string[], secretWord: string, ): string { const pattern: string[] = []; - const colorMap = { - absent: "⬛", - present: "🟨", - correct: "🟩", - } as const satisfies Record; - for (const guess of guesses) { const colors = getTileColors(guess, secretWord); const rowPattern: PatternSymbol[] = colors.map((color) => colorMap[color]); diff --git a/apps/wordle/src/lib/show-share-popup.ts b/apps/wordle/src/lib/show-share-popup.ts index e35dcf7..6bf0f4a 100644 --- a/apps/wordle/src/lib/show-share-popup.ts +++ b/apps/wordle/src/lib/show-share-popup.ts @@ -1,3 +1,4 @@ +import { CONFIG } from "#config"; import { getGuessPattern } from "./get-guess-patern"; export function getSharePopupData({ @@ -19,7 +20,7 @@ export function getSharePopupData({ const topText = isWin ? `I guessed a word in Wordle in ${attempts} attempts` : `I did not guess a word in Wordle`; - const shareText = `${topText}\n\n${pattern}\n\nPlay on ${window.location.href}`; + const shareText = `${topText}\n\n${pattern}\n\nPlay on ${CONFIG.gameUrl}`; return { isWin, title, pattern, shareText }; } diff --git a/apps/wordle/src/pages/data/answers.txt.ts b/apps/wordle/src/pages/data/answers.txt.ts new file mode 100644 index 0000000..db4204a --- /dev/null +++ b/apps/wordle/src/pages/data/answers.txt.ts @@ -0,0 +1,7 @@ +import type { APIRoute } from "astro"; +import { WORDS } from "#config"; + +// biome-ignore lint/nursery/useReactFunctionComponentDefinition: false positive +export const GET: APIRoute = () => { + return new Response(WORDS.answersRaw); +}; diff --git a/apps/wordle/src/pages/data/guesses.txt.ts b/apps/wordle/src/pages/data/guesses.txt.ts new file mode 100644 index 0000000..54d0da5 --- /dev/null +++ b/apps/wordle/src/pages/data/guesses.txt.ts @@ -0,0 +1,7 @@ +import type { APIRoute } from "astro"; +import { WORDS } from "#config"; + +// biome-ignore lint/nursery/useReactFunctionComponentDefinition: false positive +export const GET: APIRoute = () => { + return new Response(WORDS.guessesRaw); +}; diff --git a/apps/wordle/src/pages/index.astro b/apps/wordle/src/pages/index.astro index 48631b9..db85631 100644 --- a/apps/wordle/src/pages/index.astro +++ b/apps/wordle/src/pages/index.astro @@ -1,14 +1,13 @@ --- import Game from "#components/Game"; +import { CONFIG } from "#config"; import Layout from "#layout"; -const id = "wordle"; const title = "Wordle - Daily and Unlimited Word Puzzle Game"; -const canonical = `https://games.rman.dev/${id}`; +const canonical = CONFIG.gameUrl; const description = `Challenge yourself with Wordle, the addictive daily word puzzle. Enjoy unlimited games or a new daily challenge. Play now on ${canonical}`; -const thumbnail = `/images/${id}.png`; --- - + diff --git a/bun.lock b/bun.lock index 6c1d05c..80e54c3 100644 --- a/bun.lock +++ b/bun.lock @@ -49,6 +49,7 @@ "@tailwindcss/vite": "catalog:", "@unplugin-pwa/core": "catalog:", "@vite-pwa/astro": "catalog:", + "@vite-pwa/workbox-swkit": "catalog:", "@vite-pwa/workbox-window": "catalog:", "magicast": "catalog:", "rolldown": "catalog:", @@ -143,6 +144,12 @@ "devDependencies": { "@astrojs/solid-js": "catalog:", "@tailwindcss/vite": "catalog:", + "@unplugin-pwa/core": "catalog:", + "@vite-pwa/astro": "catalog:", + "@vite-pwa/workbox-swkit": "catalog:", + "@vite-pwa/workbox-window": "catalog:", + "magicast": "catalog:", + "rolldown": "catalog:", "wrangler": "catalog:", }, }, @@ -164,6 +171,7 @@ "@tailwindcss/vite": "4.3.5", "@unplugin-pwa/core": "0.0.3", "@vite-pwa/astro": "2.0.0", + "@vite-pwa/workbox-swkit": "8.0.14", "@vite-pwa/workbox-window": "8.0.14", "astro": "7.4.2", "magicast": "0.5.5", diff --git a/package.json b/package.json index 84d026e..646096e 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "@tailwindcss/vite": "4.3.5", "@unplugin-pwa/core": "0.0.3", "@vite-pwa/astro": "2.0.0", + "@vite-pwa/workbox-swkit": "8.0.14", "@vite-pwa/workbox-window": "8.0.14", "astro": "7.4.2", "magicast": "0.5.5",