@bixlab/mtone 0.7.0 → 0.9.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.
- package/README.md +2 -2
- package/dist/index.d.ts +563 -42
- package/dist/index.js +3524 -1037
- package/dist/styles.css +1 -1
- package/dist/typography-highlight-WZ7OAZVP.js +62 -0
- package/llms.txt +989 -115
- package/package.json +5 -1
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// src/typography-highlight.ts
|
|
2
|
+
import { createHighlighterCore } from "@shikijs/core";
|
|
3
|
+
import { createJavaScriptRegexEngine } from "@shikijs/engine-javascript";
|
|
4
|
+
var grammars = {
|
|
5
|
+
js: () => import("@shikijs/langs/javascript"),
|
|
6
|
+
ts: () => import("@shikijs/langs/typescript"),
|
|
7
|
+
jsx: () => import("@shikijs/langs/jsx"),
|
|
8
|
+
tsx: () => import("@shikijs/langs/tsx"),
|
|
9
|
+
json: () => import("@shikijs/langs/json"),
|
|
10
|
+
html: () => import("@shikijs/langs/html"),
|
|
11
|
+
css: () => import("@shikijs/langs/css"),
|
|
12
|
+
bash: () => import("@shikijs/langs/shellscript")
|
|
13
|
+
};
|
|
14
|
+
var themes = { light: "github-light", dark: "github-dark" };
|
|
15
|
+
var createHighlighter = () => createHighlighterCore({
|
|
16
|
+
themes: [
|
|
17
|
+
import("@shikijs/themes/github-light"),
|
|
18
|
+
import("@shikijs/themes/github-dark")
|
|
19
|
+
],
|
|
20
|
+
langs: [],
|
|
21
|
+
engine: createJavaScriptRegexEngine()
|
|
22
|
+
});
|
|
23
|
+
var highlighter;
|
|
24
|
+
var loaded = /* @__PURE__ */ new Map();
|
|
25
|
+
var color = (value) => value && /^#(?:[0-9a-f]{6}|[0-9a-f]{8})$/i.test(value) ? value : void 0;
|
|
26
|
+
async function highlightCode(text, language) {
|
|
27
|
+
highlighter ??= createHighlighter().catch((error) => {
|
|
28
|
+
highlighter = void 0;
|
|
29
|
+
throw error;
|
|
30
|
+
});
|
|
31
|
+
const shiki = await highlighter;
|
|
32
|
+
let grammar = loaded.get(language);
|
|
33
|
+
if (!grammar) {
|
|
34
|
+
grammar = shiki.loadLanguage(grammars[language]()).catch((error) => {
|
|
35
|
+
loaded.delete(language);
|
|
36
|
+
throw error;
|
|
37
|
+
});
|
|
38
|
+
loaded.set(language, grammar);
|
|
39
|
+
}
|
|
40
|
+
await grammar;
|
|
41
|
+
const pieces = text.split(/(\r\n|\n|\r)/);
|
|
42
|
+
const lines = pieces.filter((_, index) => index % 2 === 0);
|
|
43
|
+
const highlighted = shiki.codeToTokensWithThemes(lines.join("\n"), {
|
|
44
|
+
lang: language,
|
|
45
|
+
themes
|
|
46
|
+
});
|
|
47
|
+
if (highlighted.length !== lines.length) return [{ text }];
|
|
48
|
+
return highlighted.flatMap((line, index) => {
|
|
49
|
+
const ending = pieces[index * 2 + 1];
|
|
50
|
+
const tokens = line.map(({ content, variants }) => ({
|
|
51
|
+
text: content,
|
|
52
|
+
light: color(variants.light?.color),
|
|
53
|
+
dark: color(variants.dark?.color)
|
|
54
|
+
}));
|
|
55
|
+
if (tokens.map((token) => token.text).join("") !== lines[index])
|
|
56
|
+
return [{ text: lines[index] + (ending ?? "") }];
|
|
57
|
+
return ending ? [...tokens, { text: ending }] : tokens;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
export {
|
|
61
|
+
highlightCode
|
|
62
|
+
};
|