From cb1b56f5a0eddbf77446f415f2beda57c8305f85 Mon Sep 17 00:00:00 2001
From: polwex <polwex@sortug.com>
Date: Sun, 23 Nov 2025 01:12:53 +0700
Subject: wut

---
 packages/prosody-ui/src/Paragraph.tsx | 56 +++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)
 create mode 100644 packages/prosody-ui/src/Paragraph.tsx

(limited to 'packages/prosody-ui/src/Paragraph.tsx')

diff --git a/packages/prosody-ui/src/Paragraph.tsx b/packages/prosody-ui/src/Paragraph.tsx
new file mode 100644
index 0000000..72c43a7
--- /dev/null
+++ b/packages/prosody-ui/src/Paragraph.tsx
@@ -0,0 +1,56 @@
+import { franc } from "franc-all";
+import React, { useCallback, useEffect, useState } from "react";
+import ThaiText from "./thai/ThaiText";
+import { ColoredText } from "./components/Sentence";
+import type { AnalyzeRes, WordData } from "./logic/types";
+import { detectScript, langFromScript } from "./logic/utils";
+import LatinText from "./latin/LatinText";
+import { buildWiktionaryURL, parseWiktionary } from "./logic/wiki";
+import type { Result } from "sortug";
+import * as Stanza from "./logic/stanza";
+import { iso6393To1 } from "./logic/iso6393to1";
+
+export default function Paragraph({
+  text,
+}: {
+  text: string;
+  handleWord?: (wd: Result<WordData>) => any;
+}) {
+  useEffect(() => {
+    segmentString();
+  }, [text]);
+  const [lang, setLang] = useState("");
+  const [script, setScript] = useState("");
+  const [segs, setSegs] = useState<Stanza.StanzaSegment[]>([]);
+  useEffect(() => {
+    const res = franc(text);
+    console.log();
+    console.log({ res, text });
+    if (res === "und") detectLanguage();
+    else {
+      const smol = iso6393To1[res];
+      if (!smol) console.log("lang", res);
+      else setLang(smol);
+    }
+  }, [text]);
+
+  const segmentString = useCallback(async () => {
+    if (lang) {
+      const res = await Stanza.segmenter(text, lang);
+      if ("ok" in res) setSegs(res.ok.segments);
+      console.log("stanza", res);
+    }
+  }, [text, lang]);
+  const detectLanguage = useCallback(async () => {
+    const script = detectScript(text);
+    if ("error" in script) console.log("ded");
+    else {
+      setScript(script.ok);
+      const lng = langFromScript(script.ok);
+      if ("error" in lng) console.log("ded again!");
+      else setLang(lng.ok);
+    }
+  }, [text]);
+
+  return <div className="segmented-text">{text}</div>;
+}
-- 
cgit v1.2.3

