@salesforcedevs/dx-components 1.20.6 → 1.20.7-shiki-1

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/dx-components",
3
- "version": "1.20.6",
3
+ "version": "1.20.7-shiki-1",
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 * as shiki from "shiki";
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: shiki.HighlighterCore | null;
18
+ highlighter: HighlighterCore | null;
9
19
  initialized: boolean;
10
- initPromise: Promise<shiki.HighlighterCore> | null;
20
+ initPromise: Promise<HighlighterCore> | null;
11
21
  }
12
22
 
13
23
  const shikiInstance: ShikiSingleton = {
@@ -50,9 +60,8 @@ const LANGUAGE_MAP: Record<string, BundledLanguage> = {
50
60
  sh: "bash"
51
61
  };
52
62
 
53
- // Core languages that should be loaded immediately for best performance
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",
@@ -88,11 +97,11 @@ const OPTIONAL_LANGUAGES: Record<string, any> = {
88
97
  // @ts-ignore
89
98
  dataweave: getCustomLanguageGrammars().dataweave,
90
99
  // @ts-ignore
91
- agentscript: getCustomLanguageGrammars().agentscript
100
+ afscript: getCustomLanguageGrammars().afscript
92
101
  };
93
102
 
94
- // Initialize Shiki highlighter with fine-grained modules for better performance
95
- async function initializeShiki(): Promise<shiki.HighlighterCore> {
103
+ // Initialize Shiki highlighter (lazy-load module and keep initial set minimal)
104
+ async function initializeShiki(): Promise<HighlighterCore> {
96
105
  if (shikiInstance.highlighter) {
97
106
  return shikiInstance.highlighter;
98
107
  }
@@ -101,6 +110,7 @@ async function initializeShiki(): Promise<shiki.HighlighterCore> {
101
110
  return shikiInstance.initPromise;
102
111
  }
103
112
 
113
+ const shiki = await getShiki();
104
114
  shikiInstance.initPromise = shiki.createHighlighter({
105
115
  themes: ["light-plus", "material-theme-darker"],
106
116
  langs: CORE_LANGUAGES
@@ -119,7 +129,7 @@ async function initializeShiki(): Promise<shiki.HighlighterCore> {
119
129
 
120
130
  // Async function to load additional languages when needed
121
131
  async function loadLanguageIfNeeded(
122
- highlighter: shiki.HighlighterCore,
132
+ highlighter: HighlighterCore,
123
133
  language: string
124
134
  ): Promise<void> {
125
135
  const loadedLanguages = highlighter.getLoadedLanguages();
@@ -167,6 +177,8 @@ export async function highlightCode(
167
177
  mappedLanguage = "text" as BundledLanguage;
168
178
  }
169
179
 
180
+ const { transformerColorizedBrackets } = await getBrackets();
181
+
170
182
  return highlighter.codeToHtml(code, {
171
183
  lang: mappedLanguage,
172
184
  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.