From c99ed0cb53fe34196222ab13dd7a4f29b84bb8f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Thu, 19 Mar 2026 18:17:36 -0500 Subject: [PATCH] feat: types --- .vscode/settings.json | 1 + bun.lock | 8 ++ packages/website-ue/package.json | 2 + .../src/components/ApiDescription.astro | 3 + .../src/components/ApiMacroType.astro | 122 ++++++++++++++++++ .../Code/{index.css => index.module.css} | 1 + .../website-ue/src/components/Code/index.tsx | 4 +- .../src/components/HighlightedCode.astro | 23 ++++ .../src/components/HighlightedCodeContent.tsx | 28 ++++ .../src/components/SyntaxStyles.astro | 3 + .../src/pages/[...locale]/api/index.astro | 2 + 11 files changed, 195 insertions(+), 2 deletions(-) create mode 100644 packages/website-ue/src/components/ApiMacroType.astro rename packages/website-ue/src/components/Code/{index.css => index.module.css} (74%) create mode 100644 packages/website-ue/src/components/HighlightedCode.astro create mode 100644 packages/website-ue/src/components/HighlightedCodeContent.tsx create mode 100644 packages/website-ue/src/components/SyntaxStyles.astro diff --git a/.vscode/settings.json b/.vscode/settings.json index 77fb0e24b..f53df0c19 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -249,6 +249,7 @@ "winrate", "wireframe", "Woah", + "wooorm", "WOTB", "wotblitz", "wotbreplay", diff --git a/bun.lock b/bun.lock index 2a1cc768e..1cda5c8ff 100644 --- a/bun.lock +++ b/bun.lock @@ -210,12 +210,14 @@ "@types/react-dom": "^19.2.2", "@types/three": "^0.180.0", "@vite-pwa/astro": "^1.1.0", + "@wooorm/starry-night": "^3.9.0", "astro": "^5.14.4", "astro-favicons": "^3.1.5", "autoprefixer": "^10.4.23", "cssnano": "^7.1.2", "fuzzysort": "^3.1.0", "googleapis": "^171.1.0", + "hast-util-to-jsx-runtime": "^2.3.6", "immer": "^10.1.3", "lodash-es": "^4.17.21", "postcss": "^8.5.6", @@ -1262,6 +1264,8 @@ "@webgpu/types": ["@webgpu/types@0.1.69", "", {}, "sha512-RPmm6kgRbI8e98zSD3RVACvnuktIja5+yLgDAkTmxLr90BEwdTXRQWNLF3ETTTyH/8mKhznZuN5AveXYFEsMGQ=="], + "@wooorm/starry-night": ["@wooorm/starry-night@3.9.0", "", { "dependencies": { "@types/hast": "^3.0.0", "import-meta-resolve": "^4.0.0", "vscode-oniguruma": "^2.0.0", "vscode-textmate": "^9.0.0" } }, "sha512-LXVGKfYhTuFhoRuPAHz2XolS/J45L4lI/lCSIBugDpklXYDUPrJyA8tk17u7G32fcFaGODJXH/YDwQDfUXdPRw=="], + "abort-controller": ["abort-controller@3.0.0", "", { "dependencies": { "event-target-shim": "^5.0.0" } }, "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg=="], "acorn": ["acorn@8.15.0", "", { "bin": { "acorn": "bin/acorn" } }, "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg=="], @@ -2932,6 +2936,10 @@ "vscode-nls": ["vscode-nls@5.2.0", "", {}, "sha512-RAaHx7B14ZU04EU31pT+rKz2/zSl7xMsfIZuo8pd+KZO6PXtQmpevpq3vxvWNcrGbdmhM/rr5Uw5Mz+NBfhVng=="], + "vscode-oniguruma": ["vscode-oniguruma@2.0.1", "", {}, "sha512-poJU8iHIWnC3vgphJnrLZyI3YdqRlR27xzqDmpPXYzA93R4Gk8z7T6oqDzDoHjoikA2aS82crdXFkjELCdJsjQ=="], + + "vscode-textmate": ["vscode-textmate@9.3.2", "", {}, "sha512-n2uGbUcrjhUEBH16uGA0TvUfhWwliFZ1e3+pTjrkim1Mt7ydB41lV08aUvsi70OlzDWp6X7Bx3w/x3fAXIsN0Q=="], + "vscode-uri": ["vscode-uri@3.1.0", "", {}, "sha512-/BpdSx+yCQGnCvecbyXdxHDkuk55/G3xwnC0GqY4gmQ3j+A+g8kzzgB4Nk/SINjqn6+waqw3EgbVF2QKExkRxQ=="], "web-namespaces": ["web-namespaces@2.0.1", "", {}, "sha512-bKr1DkiNa2krS7qxNtdrtHAmzuYGFQLiQ13TsorsdT6ULTkPLKuu5+GsFpDlg6JFjUTwX2DyhMPG2be8uPrqsQ=="], diff --git a/packages/website-ue/package.json b/packages/website-ue/package.json index cf1c27fc8..db75b43dd 100644 --- a/packages/website-ue/package.json +++ b/packages/website-ue/package.json @@ -29,12 +29,14 @@ "@types/react-dom": "^19.2.2", "@types/three": "^0.180.0", "@vite-pwa/astro": "^1.1.0", + "@wooorm/starry-night": "^3.9.0", "astro": "^5.14.4", "astro-favicons": "^3.1.5", "autoprefixer": "^10.4.23", "cssnano": "^7.1.2", "fuzzysort": "^3.1.0", "googleapis": "^171.1.0", + "hast-util-to-jsx-runtime": "^2.3.6", "immer": "^10.1.3", "lodash-es": "^4.17.21", "postcss": "^8.5.6", diff --git a/packages/website-ue/src/components/ApiDescription.astro b/packages/website-ue/src/components/ApiDescription.astro index 3c9e70643..ad195bbde 100644 --- a/packages/website-ue/src/components/ApiDescription.astro +++ b/packages/website-ue/src/components/ApiDescription.astro @@ -1,5 +1,6 @@ --- import ApiMacroSee from "./ApiMacroSee.astro"; +import ApiMacroType from "./ApiMacroType.astro"; import { MarkdownCustom } from "./MarkdownCustom"; interface Props { @@ -54,6 +55,8 @@ for (const line of bodyOriginal.split("\n")) {
+ {"see" in macros && } + {"type" in macros && }
diff --git a/packages/website-ue/src/components/ApiMacroType.astro b/packages/website-ue/src/components/ApiMacroType.astro new file mode 100644 index 000000000..1527543ef --- /dev/null +++ b/packages/website-ue/src/components/ApiMacroType.astro @@ -0,0 +1,122 @@ +--- +import { existsSync } from "fs"; +import { readFile } from "fs/promises"; +import HighlightedCode from "./HighlightedCode.astro"; +import { Link } from "./Link"; + +interface Props { + value: string; +} + +const { value } = Astro.props; + +const roots = ["src/protos", "../closed/protos"]; + +const lang = "proto"; +const importPattern = /import "(.+)";/gm; +const messagePattern = /message .+ {\s*\n(.+\s*\n)+}/gm; + +const explored = new Set(); +let messages: string[] = []; + +await pullMessages(`${roots[0]}/${value}.proto`); + +async function pullMessages(path: string) { + if (explored.has(path)) return; + + explored.add(path); + + const file = await readFile(path); + const content = file.toString(); + const imports = content.matchAll(importPattern); + + for (const _import of imports) { + for (const root of roots) { + const path = `${root}/${_import[1]}`; + + if (existsSync(path)) { + await pullMessages(path); + break; + } + } + } + + const matchedMessages = content.matchAll(messagePattern); + + for (const message of matchedMessages) { + messages = [message[0], ...messages]; + } +} + +const content = messages.join("\n\n"); + +const indexPattern = /^( +).+\.(.+ = \d+;)$/m; + +let stripped = ""; + +for (const line of content.split("\n")) { + const matches = line.match(indexPattern); + + if (matches === null) { + stripped += `${line}\n`; + continue; + } + + stripped += `${matches[1]}${matches[2]}\n`; +} + +stripped = stripped.replaceAll(" ", " "); +--- + + + + + +
+ + +
+ + View full types + +
+
diff --git a/packages/website-ue/src/components/Code/index.css b/packages/website-ue/src/components/Code/index.module.css similarity index 74% rename from packages/website-ue/src/components/Code/index.css rename to packages/website-ue/src/components/Code/index.module.css index e9f39828e..c7efb8e86 100644 --- a/packages/website-ue/src/components/Code/index.css +++ b/packages/website-ue/src/components/Code/index.module.css @@ -1,3 +1,4 @@ .code { + font: inherit; font-family: var(--font-family-mono); } diff --git a/packages/website-ue/src/components/Code/index.tsx b/packages/website-ue/src/components/Code/index.tsx index 9c4c911d1..932aa334d 100644 --- a/packages/website-ue/src/components/Code/index.tsx +++ b/packages/website-ue/src/components/Code/index.tsx @@ -1,9 +1,9 @@ import type { ComponentProps } from "react"; import { classNames } from "../../core/ui/classNames"; -import "./index.css"; +import styles from "./index.module.css"; export interface CodeProps extends ComponentProps<"code"> {} export function Code({ className, ...props }: CodeProps) { - return ; + return ; } diff --git a/packages/website-ue/src/components/HighlightedCode.astro b/packages/website-ue/src/components/HighlightedCode.astro new file mode 100644 index 000000000..d2f730566 --- /dev/null +++ b/packages/website-ue/src/components/HighlightedCode.astro @@ -0,0 +1,23 @@ +--- +import { all, createStarryNight } from "@wooorm/starry-night"; +import { HighlightedCodeContent } from "./HighlightedCodeContent"; + +interface Props { + lang: string; + content: string; +} + +const { lang, content } = Astro.props; + +const starryNight = await createStarryNight(all); +const scope = starryNight.flagToScope(lang); + +if (scope === undefined && lang.length > 0) { + throw new Error(`Unsupported language: ${lang}`); +} + +const tree = + lang.length === 0 ? content : starryNight.highlight(content, scope!); +--- + + diff --git a/packages/website-ue/src/components/HighlightedCodeContent.tsx b/packages/website-ue/src/components/HighlightedCodeContent.tsx new file mode 100644 index 000000000..e0f1dbb97 --- /dev/null +++ b/packages/website-ue/src/components/HighlightedCodeContent.tsx @@ -0,0 +1,28 @@ +import type { Root } from "hast"; +import { toJsxRuntime } from "hast-util-to-jsx-runtime"; +import { Fragment, jsx, jsxs } from "react/jsx-runtime"; +import { Code } from "./Code"; + +interface Props { + tree: Root | string; +} + +export function HighlightedCodeContent({ tree }: Props) { + const node = + typeof tree === "string" + ? tree + : toJsxRuntime(tree, { Fragment, jsx, jsxs }); + + return ( + + ); +} diff --git a/packages/website-ue/src/components/SyntaxStyles.astro b/packages/website-ue/src/components/SyntaxStyles.astro new file mode 100644 index 000000000..c97fb2507 --- /dev/null +++ b/packages/website-ue/src/components/SyntaxStyles.astro @@ -0,0 +1,3 @@ + diff --git a/packages/website-ue/src/pages/[...locale]/api/index.astro b/packages/website-ue/src/pages/[...locale]/api/index.astro index e3632d7df..2e1863940 100644 --- a/packages/website-ue/src/pages/[...locale]/api/index.astro +++ b/packages/website-ue/src/pages/[...locale]/api/index.astro @@ -4,6 +4,7 @@ import { getCollection } from "astro:content"; import ApiGroup from "../../../components/ApiGroup.astro"; import { Heading } from "../../../components/Heading"; import { Section } from "../../../components/Section"; +import SyntaxStyles from "../../../components/SyntaxStyles.astro"; import ToolBanner from "../../../components/ToolBanner.astro"; import { api } from "../../../core/api/dynamic"; import { tools } from "../../../core/tools/tools"; @@ -25,6 +26,7 @@ paths.sort((a, b) => a.path.localeCompare(b.path)); +
{strings.api.json}