@salesforcedevs/dx-components 1.20.6 → 1.20.7-shiki
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 +2 -3
- package/src/modules/dxUtils/shiki/shiki.ts +41 -20
- package/LICENSE +0 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforcedevs/dx-components",
|
|
3
|
-
"version": "1.20.
|
|
3
|
+
"version": "1.20.7-shiki",
|
|
4
4
|
"description": "DX Lightning web components",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"engines": {
|
|
@@ -46,6 +46,5 @@
|
|
|
46
46
|
"volta": {
|
|
47
47
|
"node": "20.19.0",
|
|
48
48
|
"yarn": "1.22.19"
|
|
49
|
-
}
|
|
50
|
-
"gitHead": "c46ebfccf4f9313336961195d9cd7f1fc92270c5"
|
|
49
|
+
}
|
|
51
50
|
}
|
|
@@ -1,13 +1,23 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import type { BundledLanguage, BundledTheme } from "shiki";
|
|
4
|
-
import { transformerColorizedBrackets } from "@shikijs/colorized-brackets";
|
|
1
|
+
import type { BundledLanguage, BundledTheme, HighlighterCore } from "shiki";
|
|
5
2
|
import { getCustomLanguageGrammars } from "dxUtils/shikiGrammars";
|
|
6
3
|
|
|
4
|
+
let shikiModulePromise: Promise<typeof import("shiki")> | null = null;
|
|
5
|
+
let bracketsModulePromise: Promise<
|
|
6
|
+
typeof import("@shikijs/colorized-brackets")
|
|
7
|
+
> | null = null;
|
|
8
|
+
|
|
9
|
+
async function getShiki() {
|
|
10
|
+
return (shikiModulePromise ??= import("shiki"));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async function getBrackets() {
|
|
14
|
+
return (bracketsModulePromise ??= import("@shikijs/colorized-brackets"));
|
|
15
|
+
}
|
|
16
|
+
|
|
7
17
|
interface ShikiSingleton {
|
|
8
|
-
highlighter:
|
|
18
|
+
highlighter: HighlighterCore | null;
|
|
9
19
|
initialized: boolean;
|
|
10
|
-
initPromise: Promise<
|
|
20
|
+
initPromise: Promise<HighlighterCore> | null;
|
|
11
21
|
}
|
|
12
22
|
|
|
13
23
|
const shikiInstance: ShikiSingleton = {
|
|
@@ -50,19 +60,13 @@ const LANGUAGE_MAP: Record<string, BundledLanguage> = {
|
|
|
50
60
|
sh: "bash"
|
|
51
61
|
};
|
|
52
62
|
|
|
53
|
-
// Core languages
|
|
54
|
-
const CORE_LANGUAGES = [
|
|
55
|
-
"apex",
|
|
63
|
+
// Core languages loaded eagerly (keep minimal; load others on demand)
|
|
64
|
+
const CORE_LANGUAGES: BundledLanguage[] = [
|
|
56
65
|
"javascript",
|
|
57
66
|
"html",
|
|
58
67
|
"css",
|
|
59
68
|
"json",
|
|
60
|
-
|
|
61
|
-
"bash",
|
|
62
|
-
"xml",
|
|
63
|
-
"graphql",
|
|
64
|
-
"jsx",
|
|
65
|
-
getCustomLanguageGrammars().ampscript
|
|
69
|
+
getCustomLanguageGrammars().ampscript as BundledLanguage
|
|
66
70
|
];
|
|
67
71
|
|
|
68
72
|
// Non-critical languages that can be loaded asynchronously when needed
|
|
@@ -88,11 +92,11 @@ const OPTIONAL_LANGUAGES: Record<string, any> = {
|
|
|
88
92
|
// @ts-ignore
|
|
89
93
|
dataweave: getCustomLanguageGrammars().dataweave,
|
|
90
94
|
// @ts-ignore
|
|
91
|
-
|
|
95
|
+
afscript: getCustomLanguageGrammars().afscript
|
|
92
96
|
};
|
|
93
97
|
|
|
94
|
-
// Initialize Shiki highlighter
|
|
95
|
-
async function initializeShiki(): Promise<
|
|
98
|
+
// Initialize Shiki highlighter (lazy-load module and keep initial set minimal)
|
|
99
|
+
async function initializeShiki(): Promise<HighlighterCore> {
|
|
96
100
|
if (shikiInstance.highlighter) {
|
|
97
101
|
return shikiInstance.highlighter;
|
|
98
102
|
}
|
|
@@ -101,8 +105,9 @@ async function initializeShiki(): Promise<shiki.HighlighterCore> {
|
|
|
101
105
|
return shikiInstance.initPromise;
|
|
102
106
|
}
|
|
103
107
|
|
|
108
|
+
const shiki = await getShiki();
|
|
104
109
|
shikiInstance.initPromise = shiki.createHighlighter({
|
|
105
|
-
themes: ["light-plus"
|
|
110
|
+
themes: ["light-plus"],
|
|
106
111
|
langs: CORE_LANGUAGES
|
|
107
112
|
});
|
|
108
113
|
|
|
@@ -117,9 +122,22 @@ async function initializeShiki(): Promise<shiki.HighlighterCore> {
|
|
|
117
122
|
}
|
|
118
123
|
}
|
|
119
124
|
|
|
125
|
+
async function ensureTheme(
|
|
126
|
+
highlighter: HighlighterCore,
|
|
127
|
+
theme: "light" | "dark"
|
|
128
|
+
) {
|
|
129
|
+
if (theme === "dark") {
|
|
130
|
+
try {
|
|
131
|
+
await highlighter.loadTheme("material-theme-darker");
|
|
132
|
+
} catch (e) {
|
|
133
|
+
// ignore if not supported; fallback still renders
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
120
138
|
// Async function to load additional languages when needed
|
|
121
139
|
async function loadLanguageIfNeeded(
|
|
122
|
-
highlighter:
|
|
140
|
+
highlighter: HighlighterCore,
|
|
123
141
|
language: string
|
|
124
142
|
): Promise<void> {
|
|
125
143
|
const loadedLanguages = highlighter.getLoadedLanguages();
|
|
@@ -156,6 +174,7 @@ export async function highlightCode(
|
|
|
156
174
|
): Promise<string> {
|
|
157
175
|
try {
|
|
158
176
|
const highlighter = await initializeShiki();
|
|
177
|
+
await ensureTheme(highlighter, theme);
|
|
159
178
|
let mappedLanguage = getMappedLanguage(language);
|
|
160
179
|
|
|
161
180
|
// Try to load the language asynchronously if it's not already loaded
|
|
@@ -167,6 +186,8 @@ export async function highlightCode(
|
|
|
167
186
|
mappedLanguage = "text" as BundledLanguage;
|
|
168
187
|
}
|
|
169
188
|
|
|
189
|
+
const { transformerColorizedBrackets } = await getBrackets();
|
|
190
|
+
|
|
170
191
|
return highlighter.codeToHtml(code, {
|
|
171
192
|
lang: mappedLanguage,
|
|
172
193
|
theme: THEME_MAP[theme],
|
package/LICENSE
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
Copyright (c) 2020, Salesforce.com, Inc.
|
|
2
|
-
All rights reserved.
|
|
3
|
-
|
|
4
|
-
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
5
|
-
|
|
6
|
-
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
7
|
-
|
|
8
|
-
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
9
|
-
|
|
10
|
-
* Neither the name of Salesforce.com nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
11
|
-
|
|
12
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|