From c44b3383a7e55553cc95bba7bd5574f71c2e3406 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 10 Mar 2025 01:21:18 +0900 Subject: feat(frontend): use fine-grained bundle of shiki --- frontend/app/components/Gaming/CodeBlock.tsx | 2 +- frontend/app/shiki.bundle.ts | 58 ++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 frontend/app/shiki.bundle.ts (limited to 'frontend/app') diff --git a/frontend/app/components/Gaming/CodeBlock.tsx b/frontend/app/components/Gaming/CodeBlock.tsx index 0a9a2e5..36ccae1 100644 --- a/frontend/app/components/Gaming/CodeBlock.tsx +++ b/frontend/app/components/Gaming/CodeBlock.tsx @@ -1,5 +1,5 @@ import { useEffect, useState } from "react"; -import { codeToHtml } from "shiki"; +import { codeToHtml } from "../../shiki.bundle"; type Props = { code: string; diff --git a/frontend/app/shiki.bundle.ts b/frontend/app/shiki.bundle.ts new file mode 100644 index 0000000..1d03de3 --- /dev/null +++ b/frontend/app/shiki.bundle.ts @@ -0,0 +1,58 @@ +/* Generate by @shikijs/codegen */ +import type { + DynamicImportLanguageRegistration, + DynamicImportThemeRegistration, + HighlighterGeneric, +} from '@shikijs/types' +import { + createSingletonShorthands, + createdBundledHighlighter, +} from '@shikijs/core' +import { createJavaScriptRegexEngine } from '@shikijs/engine-javascript' + +type BundledLanguage = 'php' +type BundledTheme = 'github-light' +type Highlighter = HighlighterGeneric + +const bundledLanguages = { + php: () => import('@shikijs/langs/php'), +} as Record + +const bundledThemes = { + 'github-light': () => import('@shikijs/themes/github-light'), +} as Record + +const createHighlighter = /* @__PURE__ */ createdBundledHighlighter< + BundledLanguage, + BundledTheme +>({ + langs: bundledLanguages, + themes: bundledThemes, + engine: () => createJavaScriptRegexEngine(), +}) + +const { + codeToHtml, + codeToHast, + codeToTokensBase, + codeToTokens, + codeToTokensWithThemes, + getSingletonHighlighter, + getLastGrammarState, +} = /* @__PURE__ */ createSingletonShorthands( + createHighlighter, +) + +export { + bundledLanguages, + bundledThemes, + codeToHast, + codeToHtml, + codeToTokens, + codeToTokensBase, + codeToTokensWithThemes, + createHighlighter, + getLastGrammarState, + getSingletonHighlighter, +} +export type { BundledLanguage, BundledTheme, Highlighter } -- cgit v1.2.3-70-g09d2