<div class="demo-caption">A file</div>
<ray-code language="ray" filename="src/main.ray" line-numbers highlight="6-8"><script type="text/plain">
import std/ui;

fn main() -> int {
    let h = ui.open("Ray Remote", "ray://app/index.html", 960, 640).unwrap();
    // The page asks; the program answers.
    for e in ui.events() {
        if let Option.Some((id, body)) = ui.as_request(e) {
            ui.reply(h, id, "pong: ${body}");
        }
    }
    0
}
</script></ray-code>

<div class="demo-caption">Languages</div>
<div class="demo-grid demo-code-grid">
  <ray-code language="html" filename="index.html"><template>
<form id="login">
  <ray-input name="email" label="Email" type="email" required></ray-input>
  <ray-password-input name="password" label="Password"></ray-password-input>
  <!-- Submits like any form -->
  <ray-button type="submit">Sign in</ray-button>
</form>
</template></ray-code>
  <ray-code language="ts" filename="app.ts"><script type="text/plain">
import { notify } from "@raylang/elements";

type Build = { id: number; ok: boolean };

export async function report(build: Build): Promise<void> {
  const color = build.ok ? "green" : "red";
  notify({ title: `Build #${build.id}`, color });
}
</script></ray-code>
  <ray-code language="css" filename="theme.css"><template>
:root {
  --ray-radius-md: 0.625rem; /* rounder */
}
ray-button::part(button):hover {
  background: color-mix(in srgb, var(--ray-primary) 90%, black);
}
</template></ray-code>
  <ray-code language="json" filename="update.json"><template>
{
  "version": "0.4.1",
  "artifacts": {
    "macos-aarch64": { "size": 4404019, "signed": true }
  }
}
</template></ray-code>
</div>

<div class="demo-caption">Terminal, diff and long code</div>
<div class="demo-grid demo-code-grid">
  <ray-code language="sh" hide-header><template>
# Build and bundle the desktop app
ray build --native --release src/main.ray
ray bundle --name "Ray Remote" -o dist
echo "done: $HOME/dist"
</template></ray-code>
  <ray-code language="diff" filename="dialog.js"><template>
@@ -68,3 +68,4 @@
-  .body { flex: 1; overflow: auto; }
+  /* Safari collapses a 0% basis under a max-height. */
+  .body { flex: 1 1 auto; min-height: 0; overflow: auto; }
   .footer { display: flex; }
</template></ray-code>
</div>
<ray-code language="js" filename="tokens.js" line-numbers max-height="12rem" wrap id="demo-long"></ray-code>

<div class="demo-caption">Data as it came</div>
<p class="demo-muted" style="margin: 0">verbatim shows and copies the text untouched: a response body or a log keeps its indentation and its blank last line.</p>
<ray-code filename="response body" line-numbers verbatim id="demo-code-verbatim"></ray-code>

<div class="demo-caption">Bring your own highlighter</div>
<p class="demo-muted" style="margin: 0">setHighlighter() hands every block to a library; its classes are painted with the ray-elements tokens, so the colors stay the same. Returning nothing falls back to the built-in one.</p>
<div class="demo-grid demo-code-grid">
  <ray-code language="js" filename="Prism"><script type="text/plain">
import Prism from "prismjs";
import { setHighlighter } from "@raylang/elements";

setHighlighter((code, lang) =>
  Prism.languages[lang] ? Prism.highlight(code, Prism.languages[lang], lang) : null);
</script></ray-code>
  <ray-code language="js" filename="highlight.js"><script type="text/plain">
import hljs from "highlight.js/lib/common";
import { setHighlighter } from "@raylang/elements";

setHighlighter((code, lang) =>
  hljs.getLanguage(lang) ? hljs.highlight(code, { language: lang }).value : null);
</script></ray-code>
  <ray-code language="js" filename="Shiki"><script type="text/plain">
import { codeToHtml, createCssVariablesTheme } from "shiki";
import { setHighlighter } from "@raylang/elements";

// The css-variables theme: ray-code maps its variables to the tokens.
const theme = createCssVariablesTheme({ name: "ray-elements", variablePrefix: "--shiki-" });
setHighlighter((code, lang) => codeToHtml(code, { lang, theme }));
</script></ray-code>
</div>

<script type="module">
  // Code from script: the `code` property (what React and Vue use).
  document.getElementById("demo-long").code = Array.from({ length: 24 }, (_, i) =>
    `export const space${i} = "${(i * 0.25).toFixed(2)}rem"; // step ${i} of the spacing scale, used by gaps and paddings`).join("\n");
  document.getElementById("demo-code-verbatim").code = "    error: connection refused\n    retrying in 2s\n";
</script>