| 6 | |
| 7 | let hlPromise = null |
| 8 | function getHighlighter() { |
| 9 | if (!hlPromise) { |
| 10 | // Core + JS RegExp engine instead of the `shiki` bundle: skips the multi-MB Oniguruma WASM engine and every other grammar/theme, shipping only python + the two themes we render. This is the dominant payload of the first Run. |
| 11 | // Import via shiki's public re-exports, not @shikijs/* transitive deps that break under strict installs. |
| 12 | hlPromise = Promise.all([ |
| 13 | import('shiki/core'), |
| 14 | import('shiki/engine/javascript'), |
| 15 | ]).then(([{ createHighlighterCore }, { createJavaScriptRegexEngine }]) => |
| 16 | createHighlighterCore({ |
| 17 | themes: [import('shiki/themes/github-light.mjs'), import('shiki/themes/github-dark.mjs')], |
| 18 | langs: [import('shiki/langs/python.mjs')], |
| 19 | // forgiving: skip untranslatable grammar patterns instead of throwing and killing the highlighter. |
| 20 | engine: createJavaScriptRegexEngine({ forgiving: true }), |
| 21 | }), |
| 22 | ) |
| 23 | } |
| 24 | return hlPromise |
| 25 | } |
| 26 | |
| 27 | const isDark = () => |
| 28 | typeof document !== 'undefined' && document.documentElement.classList.contains('dark') |