Skip to content

Commit 8f010ed

Browse files
committed
Improve lookup samples
1 parent 47a8189 commit 8f010ed

File tree

4 files changed

+138
-2
lines changed

4 files changed

+138
-2
lines changed

apps/web/src/css/sample.css

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
.sample-shadow {
2+
text-shadow: 0.05em 0.05em 0 currentColor;
3+
}
4+
5+
.sample-overstrike {
6+
text-decoration-line: line-through;
7+
}
8+
9+
.sample-underline-none {
10+
text-decoration: none;
11+
}
12+
13+
.sample-underline-double {
14+
text-decoration-line: underline;
15+
text-decoration-style: double;
16+
}
17+
18+
.sample-underline-wavy {
19+
text-decoration-line: underline;
20+
text-decoration-style: wavy;
21+
}
22+
23+
.sample-underline-dotted {
24+
text-decoration-line: underline;
25+
text-decoration-style: dotted;
26+
}
27+
28+
.sample-underline-dashed {
29+
text-decoration-line: underline;
30+
text-decoration-style: dashed;
31+
}
32+
33+
.sample-foreground-colored-24bit {
34+
color: #ff69b4;
35+
}
36+
37+
.sample-foreground-colored-8bit {
38+
color: #ff8700;
39+
}
40+
41+
.sample-background-colored-24bit {
42+
background-color: #ff69b4;
43+
}
44+
45+
.sample-background-colored-8bit {
46+
background-color: #ff8700;
47+
}
48+
49+
.sample-underline-colored-24bit {
50+
text-decoration-line: underline;
51+
text-decoration-style: solid;
52+
text-decoration-thickness: 0.15em;
53+
text-decoration-color: #ff69b4;
54+
text-decoration-skip-ink: none;
55+
}
56+
57+
.sample-underline-colored-8bit {
58+
text-decoration-line: underline;
59+
text-decoration-style: solid;
60+
text-decoration-thickness: 0.15em;
61+
text-decoration-color: #ff8700;
62+
text-decoration-skip-ink: none;
63+
}
64+
65+
.sample-superscript {
66+
position: relative;
67+
top: -0.17em;
68+
font-size: 0.83em;
69+
}
70+
71+
.sample-subscript {
72+
position: relative;
73+
top: 0.17em;
74+
font-size: 0.83em;
75+
}
76+
77+
.sample-blink-slow {
78+
animation: ansi-blink-slow 1s steps(1, end) infinite;
79+
}
80+
81+
.sample-blink-fast {
82+
animation: ansi-blink-fast 0.5s steps(1, end) infinite;
83+
}
84+
85+
@keyframes ansi-blink-slow {
86+
0%,
87+
49% {
88+
opacity: 1;
89+
}
90+
50%,
91+
100% {
92+
opacity: 0;
93+
}
94+
}
95+
96+
@keyframes ansi-blink-fast {
97+
0%,
98+
24% {
99+
opacity: 1;
100+
}
101+
25%,
102+
100% {
103+
opacity: 0;
104+
}
105+
}

apps/web/src/lookup.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import { computed, document, effect, html, raw, render, signal } from "isum/preactive";
22
import { createRowsFromCodes, sortControlCodes } from "./util/table.ts";
3+
import { theme } from "ansi-to-pre";
34
import "./css/global.css";
45
import "./css/input.css";
56
import "./css/lookup.css";
67
import "./css/table.css";
8+
import "./css/sample.css";
9+
10+
theme({ defaultColor: "#ffffff" });
711

812
const getSearchParams = () => new URLSearchParams(typeof location === "undefined" ? "" : location.search);
913
const getSearchParam = (param: string): string => (getSearchParams().get(param) ?? "").trim().toLowerCase();

apps/web/src/util/sgr-map.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { ansiToPre } from "ansi-to-pre";
2+
3+
const SGR_SAMPLE_TEXT = "Sample";
4+
const SGR_SAMPLE_HTML = ansiToPre(SGR_SAMPLE_TEXT);
5+
export const SGR_MAP: Record<string, string> = {
6+
"1:2": "sample-shadow",
7+
"4:0": "sample-underline-none",
8+
"4:1": "sample-underline-single",
9+
"4:2": "sample-underline-double",
10+
"4:3": "sample-underline-wavy",
11+
"4:4": "sample-underline-dotted",
12+
"4:5": "sample-underline-dashed",
13+
"5": "sample-blink-slow",
14+
"6": "sample-blink-fast",
15+
"8:7": "sample-overstrike",
16+
"21": "sample-underline-double",
17+
"58;2": "sample-underline-colored-24bit",
18+
"58;5": "sample-underline-colored-8bit",
19+
"73": "sample-superscript",
20+
"74": "sample-subscript",
21+
};
22+
23+
export function render(className: string) {
24+
const span = `<span class="${className}">${SGR_SAMPLE_TEXT}</span>`;
25+
return SGR_SAMPLE_HTML.replace(SGR_SAMPLE_TEXT, span);
26+
}

apps/web/src/util/table.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { ansiToPre } from "ansi-to-pre";
44
import { controlCodes, codeMaps } from "../codes.ts";
55
import { getColorName } from "./color.ts";
66
import { ESC, ST } from "./string.ts";
7+
import { SGR_MAP, render } from "./sgr-map.ts";
78

89
interface TableRow {
910
type: CONTROL_CODE["type"];
@@ -208,8 +209,8 @@ export function createRowsFromCodes() {
208209
case CODE_TYPES.SGR: {
209210
const { description, template } = item;
210211
const code = `${PREFIX}[${item.code}${template ?? ""}m`;
211-
const raw = `${PREFIX_RAW}[${item.code}${tpl(item.template, item.example)}m`;
212-
const example = item.code.includes(":") ? "" : ansiToPre(`${raw}Sample\u001b[0m`);
212+
const raw = `${PREFIX_RAW}[${item.code}${tpl(template, item.example)}m`;
213+
const example = item.code in SGR_MAP ? render(SGR_MAP[item.code]) : ansiToPre(`${raw}Sample\u001b[0m`);
213214
rows.push({ type, sort: item.code, code, mnemonic: "", description, example });
214215
break;
215216
}

0 commit comments

Comments
 (0)