feat: use webgl shaders instead of wasm

This commit is contained in:
Jet 2026-03-27 15:08:34 -07:00
parent 38efffa9b9
commit 51dc6c9ee6
No known key found for this signature in database
24 changed files with 1712 additions and 1607 deletions

View file

@ -4,51 +4,51 @@ import fs from "node:fs";
import type { Plugin } from "vite";
const colorMap: Record<string, string> = {
"ansi-black": "text-[var(--black)]",
"ansi-red": "text-[var(--red)]",
"ansi-green": "text-[var(--green)]",
"ansi-yellow": "text-[var(--brown)]",
"ansi-blue": "text-[var(--blue)]",
"ansi-magenta": "text-[var(--magenta)]",
"ansi-cyan": "text-[var(--cyan)]",
"ansi-white": "text-[var(--light-gray)]",
"ansi-bright-black": "text-[var(--dark-gray)]",
"ansi-bright-red": "text-[var(--light-red)]",
"ansi-bright-green": "text-[var(--light-green)]",
"ansi-bright-yellow": "text-[var(--yellow)]",
"ansi-bright-blue": "text-[var(--light-blue)]",
"ansi-bright-magenta": "text-[var(--light-magenta)]",
"ansi-bright-cyan": "text-[var(--light-cyan)]",
"ansi-bright-white": "text-[var(--white)]",
"ansi-black": "color: var(--black)",
"ansi-red": "color: var(--red)",
"ansi-green": "color: var(--green)",
"ansi-yellow": "color: var(--brown)",
"ansi-blue": "color: var(--blue)",
"ansi-magenta": "color: var(--magenta)",
"ansi-cyan": "color: var(--cyan)",
"ansi-white": "color: var(--light-gray)",
"ansi-bright-black": "color: var(--dark-gray)",
"ansi-bright-red": "color: var(--light-red)",
"ansi-bright-green": "color: var(--light-green)",
"ansi-bright-yellow": "color: var(--yellow)",
"ansi-bright-blue": "color: var(--light-blue)",
"ansi-bright-magenta": "color: var(--light-magenta)",
"ansi-bright-cyan": "color: var(--light-cyan)",
"ansi-bright-white": "color: var(--white)",
};
const bgColorMap: Record<string, string> = {
"ansi-black": "bg-transparent",
"ansi-red": "bg-[var(--red)]",
"ansi-green": "bg-[var(--green)]",
"ansi-yellow": "bg-[var(--brown)]",
"ansi-blue": "bg-[var(--blue)]",
"ansi-magenta": "bg-[var(--magenta)]",
"ansi-cyan": "bg-[var(--cyan)]",
"ansi-white": "bg-[var(--light-gray)]",
"ansi-bright-black": "bg-[var(--dark-gray)]",
"ansi-bright-red": "bg-[var(--light-red)]",
"ansi-bright-green": "bg-[var(--light-green)]",
"ansi-bright-yellow": "bg-[var(--yellow)]",
"ansi-bright-blue": "bg-[var(--light-blue)]",
"ansi-bright-magenta": "bg-[var(--light-magenta)]",
"ansi-bright-cyan": "bg-[var(--light-cyan)]",
"ansi-bright-white": "bg-[var(--white)]",
"ansi-black": "background-color: transparent",
"ansi-red": "background-color: var(--red)",
"ansi-green": "background-color: var(--green)",
"ansi-yellow": "background-color: var(--brown)",
"ansi-blue": "background-color: var(--blue)",
"ansi-magenta": "background-color: var(--magenta)",
"ansi-cyan": "background-color: var(--cyan)",
"ansi-white": "background-color: var(--light-gray)",
"ansi-bright-black": "background-color: var(--dark-gray)",
"ansi-bright-red": "background-color: var(--light-red)",
"ansi-bright-green": "background-color: var(--light-green)",
"ansi-bright-yellow": "background-color: var(--yellow)",
"ansi-bright-blue": "background-color: var(--light-blue)",
"ansi-bright-magenta": "background-color: var(--light-magenta)",
"ansi-bright-cyan": "background-color: var(--light-cyan)",
"ansi-bright-white": "background-color: var(--white)",
};
const decorationMap: Record<string, string> = {
bold: "font-bold",
dim: "opacity-50",
italic: "italic",
hidden: "invisible",
strikethrough: "line-through",
underline: "underline",
blink: "animate-pulse",
bold: "font-weight: 700",
dim: "opacity: 0.5",
italic: "font-style: italic",
hidden: "visibility: hidden",
strikethrough: "text-decoration: line-through",
underline: "text-decoration: underline",
blink: "animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite",
};
function fixBackspace(txt: string): string {
@ -60,18 +60,18 @@ function fixBackspace(txt: string): string {
return txt;
}
function createClass(bundle: AnserJsonEntry): string | null {
const classes: string[] = [];
function createStyle(bundle: AnserJsonEntry): string | null {
const declarations: string[] = [];
if (bundle.bg && bgColorMap[bundle.bg]) {
classes.push(bgColorMap[bundle.bg]!);
declarations.push(bgColorMap[bundle.bg]!);
}
if (bundle.fg && colorMap[bundle.fg]) {
classes.push(colorMap[bundle.fg]!);
declarations.push(colorMap[bundle.fg]!);
}
if (bundle.decoration && decorationMap[bundle.decoration]) {
classes.push(decorationMap[bundle.decoration]!);
declarations.push(decorationMap[bundle.decoration]!);
}
return classes.length ? classes.join(" ") : null;
return declarations.length ? declarations.join("; ") : null;
}
function escapeHtml(str: string): string {
@ -92,10 +92,10 @@ function renderAnsiToHtml(raw: string): string {
const spans = bundles
.map((bundle) => {
const cls = createClass(bundle);
const style = createStyle(bundle);
const content = escapeHtml(bundle.content);
if (cls) {
return `<span class="${cls}">${content}</span>`;
if (style) {
return `<span style="${style}">${content}</span>`;
}
return `<span>${content}</span>`;
})