@salesforcedevs/dx-components 1.29.0-ssgalpha1 → 1.29.0-ssgalpha3
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/package.json
CHANGED
|
@@ -1,19 +1,13 @@
|
|
|
1
1
|
import type { BundledLanguage, BundledTheme, HighlighterCore } from "shiki";
|
|
2
|
+
import { getShikiModule, getBracketsModule } from "./shikiLoader";
|
|
2
3
|
import { getCustomLanguageGrammars } from "dxUtils/shikiGrammars";
|
|
3
4
|
|
|
4
|
-
let shikiModulePromise: Promise<typeof import("shiki")> | null = null;
|
|
5
|
-
let bracketsModulePromise: Promise<
|
|
6
|
-
typeof import("@shikijs/colorized-brackets")
|
|
7
|
-
> | null = null;
|
|
8
|
-
|
|
9
5
|
async function getShiki() {
|
|
10
|
-
return (
|
|
6
|
+
return getShikiModule();
|
|
11
7
|
}
|
|
12
8
|
|
|
13
9
|
async function getBrackets() {
|
|
14
|
-
return (
|
|
15
|
-
"@shikijs/colorized-brackets/dist/index.mjs"
|
|
16
|
-
));
|
|
10
|
+
return getBracketsModule();
|
|
17
11
|
}
|
|
18
12
|
|
|
19
13
|
interface ShikiSingleton {
|
|
@@ -103,7 +97,7 @@ const OPTIONAL_LANGUAGES: Record<string, any> = {
|
|
|
103
97
|
agentscript: getCustomLanguageGrammars().agentscript
|
|
104
98
|
};
|
|
105
99
|
|
|
106
|
-
// Initialize Shiki highlighter
|
|
100
|
+
// Initialize Shiki highlighter
|
|
107
101
|
async function initializeShiki(): Promise<HighlighterCore> {
|
|
108
102
|
if (shikiInstance.highlighter) {
|
|
109
103
|
return shikiInstance.highlighter;
|
|
@@ -115,8 +109,8 @@ async function initializeShiki(): Promise<HighlighterCore> {
|
|
|
115
109
|
|
|
116
110
|
// Assign promise IMMEDIATELY before any async work to prevent race conditions
|
|
117
111
|
shikiInstance.initPromise = (async () => {
|
|
118
|
-
const
|
|
119
|
-
const highlighter = await
|
|
112
|
+
const shikiModule = await getShiki();
|
|
113
|
+
const highlighter = await shikiModule.createHighlighter({
|
|
120
114
|
themes: ["light-plus", "material-theme-darker"],
|
|
121
115
|
langs: CORE_LANGUAGES
|
|
122
116
|
});
|
|
@@ -184,12 +178,12 @@ export async function highlightCode(
|
|
|
184
178
|
mappedLanguage = "text" as BundledLanguage;
|
|
185
179
|
}
|
|
186
180
|
|
|
187
|
-
const { transformerColorizedBrackets } = await getBrackets();
|
|
181
|
+
const { transformerColorizedBrackets: transformer } = await getBrackets();
|
|
188
182
|
|
|
189
183
|
return highlighter.codeToHtml(code, {
|
|
190
184
|
lang: mappedLanguage,
|
|
191
185
|
theme: THEME_MAP[theme],
|
|
192
|
-
transformers: [
|
|
186
|
+
transformers: [transformer()],
|
|
193
187
|
colorReplacements:
|
|
194
188
|
THEME_MAP_COLOR_REPLACEMENTS[theme].colorReplacements
|
|
195
189
|
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ShikiModule, BracketsModule } from "./shikiLoaderStatic";
|
|
2
|
+
|
|
3
|
+
export type { ShikiModule, BracketsModule };
|
|
4
|
+
|
|
5
|
+
const USE_STATIC_IMPORT = process.env.SHIKI_STATIC_IMPORT === "false";
|
|
6
|
+
|
|
7
|
+
export async function getShikiModule(): Promise<ShikiModule> {
|
|
8
|
+
if (USE_STATIC_IMPORT) {
|
|
9
|
+
const loader = await import("./shikiLoaderStatic");
|
|
10
|
+
return loader.getShikiModule();
|
|
11
|
+
} else {
|
|
12
|
+
const loader = await import("./shikiLoaderDynamic");
|
|
13
|
+
return loader.getShikiModule();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export async function getBracketsModule(): Promise<BracketsModule> {
|
|
18
|
+
if (USE_STATIC_IMPORT) {
|
|
19
|
+
const loader = await import("./shikiLoaderStatic");
|
|
20
|
+
return loader.getBracketsModule();
|
|
21
|
+
} else {
|
|
22
|
+
const loader = await import("./shikiLoaderDynamic");
|
|
23
|
+
return loader.getBracketsModule();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ShikiModule, BracketsModule } from "./shikiLoaderStatic";
|
|
2
|
+
|
|
3
|
+
export type { ShikiModule, BracketsModule };
|
|
4
|
+
|
|
5
|
+
export async function getShikiModule(): Promise<ShikiModule> {
|
|
6
|
+
const shiki = await import("shiki");
|
|
7
|
+
return shiki as unknown as ShikiModule;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export async function getBracketsModule(): Promise<BracketsModule> {
|
|
11
|
+
const brackets = await import("@shikijs/colorized-brackets");
|
|
12
|
+
return brackets as BracketsModule;
|
|
13
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { HighlighterCore } from "shiki";
|
|
2
|
+
import * as shiki from "shiki";
|
|
3
|
+
import { transformerColorizedBrackets } from "@shikijs/colorized-brackets";
|
|
4
|
+
|
|
5
|
+
export interface ShikiModule {
|
|
6
|
+
createHighlighter: typeof shiki.createHighlighter;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface BracketsModule {
|
|
10
|
+
transformerColorizedBrackets: typeof transformerColorizedBrackets;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export async function getShikiModule(): Promise<ShikiModule> {
|
|
14
|
+
return shiki;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export async function getBracketsModule(): Promise<BracketsModule> {
|
|
18
|
+
return { transformerColorizedBrackets };
|
|
19
|
+
}
|