comarkserv 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +389 -0
  3. package/dist/THIRD_PARTY_LICENSES.md +932 -0
  4. package/dist/build-CsToYJrU.mjs +2 -0
  5. package/dist/build-Cv5aO0CB.mjs +205 -0
  6. package/dist/cli.d.mts +1 -0
  7. package/dist/cli.mjs +894 -0
  8. package/dist/cloudflared-6f_lzz4F.mjs +181 -0
  9. package/dist/dist-B-IALNns.mjs +2 -0
  10. package/dist/dist-BK-bpLWg.mjs +2 -0
  11. package/dist/dist-BQzCbTko.mjs +1693 -0
  12. package/dist/dist-BWcWG5YB.mjs +671 -0
  13. package/dist/dist-BiVw4ojz.mjs +592 -0
  14. package/dist/dist-BnmL9jeq.mjs +538 -0
  15. package/dist/dist-BtedNLrc.mjs +276 -0
  16. package/dist/dist-BvdNTrap.mjs +2710 -0
  17. package/dist/dist-ByijHttv.mjs +69 -0
  18. package/dist/dist-C2E4zSX1.mjs +347 -0
  19. package/dist/dist-CWYRQLUT.mjs +2 -0
  20. package/dist/dist-CXQ7eTfT.mjs +417 -0
  21. package/dist/dist-CfsjQ0o8.mjs +905 -0
  22. package/dist/dist-CsTXDvwi.mjs +300 -0
  23. package/dist/dist-CtONMLh4.mjs +283 -0
  24. package/dist/dist-DMftjyxU.mjs +370 -0
  25. package/dist/dist-Dr9uTCX7.mjs +2 -0
  26. package/dist/dist-Dxvc11TH.mjs +339 -0
  27. package/dist/dist-GmbcGEAc.mjs +3 -0
  28. package/dist/dist-V1rkISnf.mjs +220 -0
  29. package/dist/dist-ZoN94PJ0.mjs +76 -0
  30. package/dist/dist-fh99cWMN.mjs +524 -0
  31. package/dist/editor-CHDyOp-8.mjs +721 -0
  32. package/dist/index.d.mts +301 -0
  33. package/dist/index.mjs +6 -0
  34. package/dist/languages-C0kEygG_.mjs +119 -0
  35. package/dist/markdown-BqKed1Vq.mjs +710 -0
  36. package/dist/markdown-DWuqfzps.mjs +2 -0
  37. package/dist/rolldown-runtime-CMFfr-1z.mjs +26 -0
  38. package/dist/server-Dkjk_D1Y.mjs +2628 -0
  39. package/dist/terminal-aKr5Xlp3.mjs +169 -0
  40. package/dist/themes-mEufQ_3e.mjs +2194 -0
  41. package/dist/twinkleplop.production-Coccf2Q9.mjs +2 -0
  42. package/dist/twinkleplop.production-DekYmX6O.mjs +4697 -0
  43. package/dist/twinkleplop.tokens-CgBUTCSg.mjs +76 -0
  44. package/package.json +133 -0
@@ -0,0 +1,169 @@
1
+ import { a as resolveLanguage, i as loadTokenizer, l as isElement, s as childrenOf, u as stringAttr } from "./languages-C0kEygG_.mjs";
2
+ import { createRequire } from "node:module";
3
+ import { readFileSync } from "node:fs";
4
+ import { createMarkdownParser } from "comark";
5
+ import emoji from "comark/plugins/emoji";
6
+ import footnotes from "comark/plugins/footnotes";
7
+ import math from "comark/plugins/math";
8
+ import mermaid from "comark/plugins/mermaid";
9
+ import { renderAnsiFromDocument } from "@comark/ansi";
10
+ import { Mermaid } from "@comark/ansi/plugins/mermaid";
11
+ //#region src/terminal.ts
12
+ const ALERT_TYPES = {
13
+ note: "NOTE",
14
+ info: "NOTE",
15
+ callout: "NOTE",
16
+ tip: "TIP",
17
+ success: "TIP",
18
+ important: "IMPORTANT",
19
+ warning: "WARNING",
20
+ caution: "CAUTION",
21
+ danger: "CAUTION"
22
+ };
23
+ const INLINE_LANGUAGE = /\{:([^{}\s]+)\}$/;
24
+ const UNWRAP = /* @__PURE__ */ new Set([
25
+ "code-group",
26
+ "div",
27
+ "figcaption",
28
+ "figure",
29
+ "kbd",
30
+ "mark",
31
+ "section",
32
+ "small",
33
+ "span",
34
+ "sub",
35
+ "sup"
36
+ ]);
37
+ const BOLD = "\x1B[1m";
38
+ const DIM = "\x1B[2m";
39
+ const CYAN = "\x1B[36m";
40
+ const YELLOW = "\x1B[33m";
41
+ const RESET = "\x1B[0m";
42
+ let darkColors;
43
+ function tokenColors() {
44
+ if (darkColors) return darkColors;
45
+ const css = readFileSync(createRequire(import.meta.url).resolve("@twinkleplop/theme-github"), "utf8");
46
+ const dark = /\.dark\s*\{([^}]*)\}/.exec(css)?.[1] ?? "";
47
+ darkColors = Object.fromEntries([...dark.matchAll(/--twp-([a-z0-9_]+):\s*(#[0-9a-f]{3,8})\s*;/gi)].map((match) => [match[1] ?? "", match[2] ?? ""]));
48
+ return darkColors;
49
+ }
50
+ async function highlight(node) {
51
+ const [tag, attrs, code] = node;
52
+ const id = resolveLanguage(stringAttr(attrs, "language"));
53
+ if (!id || !isElement(code)) return node;
54
+ const text = childrenOf(code).filter((child) => typeof child === "string").join("");
55
+ const tokens = (await loadTokenizer(id))(text);
56
+ const colors = tokenColors();
57
+ const children = [];
58
+ let position = 0;
59
+ for (const token of tokens) {
60
+ if (token.start > position) children.push(text.slice(position, token.start));
61
+ const color = colors[token.type];
62
+ children.push(color ? [
63
+ "span",
64
+ { style: `color:${color}` },
65
+ token.value
66
+ ] : token.value);
67
+ position = token.end;
68
+ }
69
+ if (position < text.length) children.push(text.slice(position));
70
+ return [
71
+ tag,
72
+ attrs,
73
+ [
74
+ code[0],
75
+ code[1],
76
+ ...children
77
+ ]
78
+ ];
79
+ }
80
+ async function prepare(nodes) {
81
+ const prepared = await Promise.all(nodes.map(async (node) => {
82
+ if (!isElement(node)) return [node];
83
+ const [tag, attrs] = node;
84
+ if (tag === "pre") return [await highlight(node)];
85
+ const children = await prepare(childrenOf(node));
86
+ const alert = tag === "alert" ? ALERT_TYPES[stringAttr(attrs, "type") ?? "note"] : ALERT_TYPES[tag];
87
+ if (alert) return [[
88
+ "blockquote",
89
+ { as: alert.toLowerCase() },
90
+ ...children
91
+ ]];
92
+ if (UNWRAP.has(tag) || tag === "a" && stringAttr(attrs, "href")?.startsWith("#")) return children;
93
+ const raw = {
94
+ ...attrs,
95
+ $: {
96
+ ...attrs.$,
97
+ html: 1,
98
+ block: 1
99
+ }
100
+ };
101
+ if (tag === "code" && children.length === 1 && typeof children[0] === "string") return [[
102
+ tag,
103
+ raw,
104
+ children[0].replace(INLINE_LANGUAGE, "")
105
+ ]];
106
+ return [[
107
+ tag,
108
+ raw,
109
+ ...children
110
+ ]];
111
+ }));
112
+ const merged = [];
113
+ for (const node of prepared.flat()) {
114
+ const last = merged.at(-1);
115
+ if (typeof node === "string" && typeof last === "string") merged[merged.length - 1] = last + node;
116
+ else merged.push(node);
117
+ }
118
+ return merged;
119
+ }
120
+ function createTerminalRenderer(options = {}) {
121
+ const parse = createMarkdownParser({ plugins: [
122
+ footnotes(),
123
+ emoji(),
124
+ math(),
125
+ mermaid()
126
+ ] });
127
+ const colors = options.colors ?? !process.env.NO_COLOR;
128
+ const paint = (style, text) => colors ? `${style}${text}${RESET}` : text;
129
+ const components = {
130
+ details: async (node, state) => `${paint(BOLD, `▸ ${stringAttr(node[1], "summary") ?? "Details"}`)}\n${(await state.flow(node, state)).trim()}\n\n`,
131
+ math: ([, attrs]) => {
132
+ const content = stringAttr(attrs, "content") ?? "";
133
+ return (stringAttr(attrs, "class") ?? "").includes("inline") ? paint(YELLOW, `$${content}$`) : `${paint(YELLOW, content)}\n\n`;
134
+ },
135
+ mermaid: Mermaid,
136
+ pre: ([, attrs, code]) => {
137
+ const language = stringAttr(attrs, "language") ?? "";
138
+ const filename = stringAttr(attrs, "filename") ?? "";
139
+ return `\`\`\`${[language && paint(BOLD + CYAN, language), filename && paint(DIM, filename)].filter(Boolean).join(" ")}\n${isElement(code) ? childrenOf(code).map(codePart).join("") : ""}\n\`\`\`\n\n`;
140
+ }
141
+ };
142
+ const codePart = (part) => {
143
+ if (typeof part === "string") return part;
144
+ if (!isElement(part)) return "";
145
+ const text = childrenOf(part).filter((child) => typeof child === "string").join("");
146
+ const color = /color:\s*#([0-9a-f]{6})/i.exec(stringAttr(part[1], "style") ?? "")?.[1];
147
+ if (!colors || !color) return text;
148
+ const [r, g, b] = [
149
+ 0,
150
+ 2,
151
+ 4
152
+ ].map((start) => Number.parseInt(color.slice(start, start + 2), 16));
153
+ return `\x1b[38;2;${r};${g};${b}m${text}${RESET}`;
154
+ };
155
+ return async (source) => {
156
+ const doc = await parse(source);
157
+ const nodes = await prepare(doc.nodes);
158
+ return renderAnsiFromDocument({
159
+ ...doc,
160
+ nodes
161
+ }, {
162
+ colors,
163
+ width: options.width ?? 80,
164
+ components
165
+ });
166
+ };
167
+ }
168
+ //#endregion
169
+ export { createTerminalRenderer };