From 1c6067a2cbff318e9847c34516e15a9b8dfb09ef Mon Sep 17 00:00:00 2001 From: Joshua Seigler Date: Sun, 7 Apr 2024 22:58:50 -0400 Subject: [PATCH] polish --- src/components/DualText.tsx | 12 ++- src/components/Main.tsx | 174 +--------------------------------- src/components/ReadingBox.tsx | 9 +- src/components/Reference.tsx | 22 ++--- src/components/store.ts | 2 +- src/style.css | 34 +++++-- 6 files changed, 52 insertions(+), 201 deletions(-) diff --git a/src/components/DualText.tsx b/src/components/DualText.tsx index 6914ed8..a44161a 100644 --- a/src/components/DualText.tsx +++ b/src/components/DualText.tsx @@ -1,8 +1,8 @@ import { ligatures } from "./store"; -export default function DualText({ children }: { children: string }) { +export default function DualText({ text }: { text: string }) { const words: string[] = []; - children.split(/\n/).forEach((line, index, lines) => { + text.split(/\n/).forEach((line, index, lines) => { line.split(/\b(?=\w)/).forEach((word) => { words.push(word); }); @@ -10,6 +10,8 @@ export default function DualText({ children }: { children: string }) { words.push("\n"); } }); + const currentLigatures = ligatures.value; + return ( {words.map((word) => { @@ -19,7 +21,7 @@ export default function DualText({ children }: { children: string }) { const letters: string[] = []; for (let i = 0; i < word.length; i += 1) { const nextTwoCharacters = word.slice(i, i + 2); - if (ligatures.value.includes(nextTwoCharacters.toLowerCase())) { + if (currentLigatures.includes(nextTwoCharacters.toLowerCase())) { letters.push(nextTwoCharacters); i += 1; } else { @@ -27,8 +29,8 @@ export default function DualText({ children }: { children: string }) { } } return ( - - {word} + + {word}
{letters.map((character) => { return ; diff --git a/src/components/Main.tsx b/src/components/Main.tsx index 8934494..f9965ab 100644 --- a/src/components/Main.tsx +++ b/src/components/Main.tsx @@ -1,92 +1,10 @@ -import { computed, effect, signal } from "@preact/signals"; import localforage from "localforage"; import { useEffect } from "preact/hooks"; +import { selectedFont } from "./store"; import ReadingBox from "./ReadingBox"; - -const fonts: Record = { - "AB-Equinox": { - ligatures: ["ch", "sh", "th", "ae", "eo", "kh", "ng", "oo"], - lowercase: false, - }, - "AurebeshAF-Canon": { - ligatures: [], - lowercase: false, - }, - "AurebeshAF-CanonTech": { - ligatures: [], - lowercase: false, - }, - "AurebeshAF-Legends": { - ligatures: ["ch", "sh", "th", "ae", "eo", "kh", "ng", "oo"], - lowercase: false, - }, - "AurebeshAF-LegendsTech": { - ligatures: ["ch", "sh", "th", "ae", "eo", "kh", "ng", "oo"], - lowercase: false, - }, - "Aurebesh_Rodian-Oblique": { - ligatures: [], - lowercase: false, - }, - "Aurebesh_Rodian-OblqOutline": { - ligatures: [], - lowercase: false, - }, - Aurebesh_Rodian: { - ligatures: [], - lowercase: false, - }, - "Aurebesh_Rodian-Outline": { - ligatures: [], - lowercase: false, - }, - "AurebeshTypewriter-Light": { - ligatures: [], - lowercase: true, - }, - "AurebeshTypewriter-Regular": { - ligatures: [], - lowercase: true, - }, - Droidobesh: { - ligatures: [], - lowercase: false, - }, - LaptiNekAF: { - ligatures: [], - lowercase: false, - }, - Maulobesh: { - ligatures: [], - lowercase: false, - }, - Nirvanabesh: { - ligatures: [], - lowercase: false, - }, - Skyhook: { - ligatures: [], - lowercase: false, - }, -}; - -const fontNames = Object.keys(fonts); - -const selectedFont = signal("AurebeshAF-Legends"); -effect(() => { - if (typeof window !== "undefined") { - document.documentElement.style.setProperty( - "--font-aurebesh", - selectedFont.value - ); - } -}); -const ligatures = computed(() => { - return fonts[selectedFont.value].ligatures; -}); -const lowercase = computed(() => { - return fonts[selectedFont.value].lowercase; -}); +import Reference from "./Reference"; +import FontPicker from "./FontPicker"; +import DualText from "./DualText"; export default function Main() { useEffect(() => { @@ -105,7 +23,7 @@ export default function Main() { <>

- Learn Aurebesh +

@@ -118,85 +36,3 @@ export default function Main() { ); } - -function FontPicker() { - return ( - - ); -} - -function DualText({ children }: { children: string }) { - const words: string[] = []; - children.split(/\n/).forEach((line, index, lines) => { - line.split(/\b(?=\w)/).forEach((word) => { - words.push(word); - }); - if (index < lines.length - 1) { - words.push("\n"); - } - }); - return ( - - {words.map((word) => { - if (word === "\n") { - return
; - } - const letters: string[] = []; - for (let i = 0; i < word.length; i += 1) { - const nextTwoCharacters = word.slice(i, i + 2); - if (ligatures.value.includes(nextTwoCharacters.toLowerCase())) { - letters.push(nextTwoCharacters); - i += 1; - } else { - letters.push(nextTwoCharacters[0]); - } - } - return ( - - {word} -
- {letters.map((character) => { - return ; - })} -
-
- ); - })} -
- ); -} - -function Reference() { - return ( - - ); -} diff --git a/src/components/ReadingBox.tsx b/src/components/ReadingBox.tsx index 7d88485..d576235 100644 --- a/src/components/ReadingBox.tsx +++ b/src/components/ReadingBox.tsx @@ -36,7 +36,7 @@ Pursued by the Empire's sinister agents, Princess Leia races home aboard her sta }} /> - {isEditing.value ? ( + {isEditing.value && (