From cb1b56f5a0eddbf77446f415f2beda57c8305f85 Mon Sep 17 00:00:00 2001 From: polwex Date: Sun, 23 Nov 2025 01:12:53 +0700 Subject: wut --- packages/prosody-ui/src/latin/LatinText.tsx | 77 +++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 packages/prosody-ui/src/latin/LatinText.tsx (limited to 'packages/prosody-ui/src/latin') diff --git a/packages/prosody-ui/src/latin/LatinText.tsx b/packages/prosody-ui/src/latin/LatinText.tsx new file mode 100644 index 0000000..e5b13ff --- /dev/null +++ b/packages/prosody-ui/src/latin/LatinText.tsx @@ -0,0 +1,77 @@ +import React, { useCallback, useEffect, useState } from "react"; +import type { AnalyzeRes } from "../logic/types"; +import { ColoredText } from "../components/Sentence"; +import Word from "../components/Word"; +import { iso6393To1 } from "../logic/iso6393to1"; + +function segmentate( + text: string, + lang: string, + granularity: "sentence" | "word" | "grapheme", +) { + // TODO proper error handling here + console.log("segmenting", lang); + const la = iso6393To1[lang]; + const lng = la || lang; + const segmenter = new Intl.Segmenter(lng, { granularity }); + const segments = Array.from(segmenter.segment(text)); + console.log("seg", segments[0]); + return segments.reduce((acc: string[], s) => { + const trimmed = s.segment.trim(); + if (trimmed) return [...acc, trimmed]; + else return acc; + }, []); +} + +export default function LatinText({ + text, + lang, + openWord, +}: { + text: string; + lang: string; + openWord?: (word: string) => void; +}) { + useEffect(() => { + const sentences = segmentate(text, lang, "sentence"); + if (sentences) setSentences(sentences); + }, [text]); + const [sentences, setSentences] = useState([]); + console.log({ sentences }); + return ( + <> + {sentences.map((s, i) => ( + + ))} + + ); +} + +function Sentence({ + text, + lang, + openWord, +}: { + text: string; + lang: string; + + openWord?: (word: string) => void; +}) { + useEffect(() => { + const w = segmentate(text, lang, "word"); + if (w) setWords(w); + console.log({ words }); + }, [text]); + const [words, setWords] = useState([]); + console.log({ words }); + + // const [data, setData] = useState>({}); + const [word, setWord] = useState(); + + return ( + <> + ; + {word && } + + ); +} -- cgit v1.2.3