@shikijs/core 1.18.0 → 1.20.0
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/dist/index.d.mts +70 -9
- package/dist/index.d.ts +70 -9
- package/dist/index.mjs +282 -23
- package/dist/shared/core.afb6276c.mjs +10 -0
- package/dist/wasm-inlined.mjs +3 -0
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { CreatedBundledHighlighterOptions, CreateHighlighterFactory, LanguageInput, ThemeInput, HighlighterCoreOptions, CodeToHastOptions, CodeToTokensOptions, TokensResult, RequireKeys, CodeToTokensBaseOptions, ThemedToken, CodeToTokensWithThemesOptions, ThemedTokenWithVariants, BundledHighlighterOptions, HighlighterGeneric, GrammarState, HighlighterCore, ShikiInternal, LoadWasmOptions, ShikiTransformerContextCommon, CodeToHastRenderOptions, ShikiTransformerContextSource, ThemeRegistrationResolved, TokenizeWithThemeOptions, ThemeRegistrationAny, ShikiTransformer, MaybeArray, PlainTextLanguage, SpecialLanguage, SpecialTheme, MaybeGetter, TokenStyles, Position } from '@shikijs/types';
|
|
1
|
+
import { CreatedBundledHighlighterOptions, CreateHighlighterFactory, LanguageInput, ThemeInput, HighlighterCoreOptions, CodeToHastOptions, CodeToTokensOptions, TokensResult, RequireKeys, CodeToTokensBaseOptions, ThemedToken, CodeToTokensWithThemesOptions, ThemedTokenWithVariants, BundledHighlighterOptions, HighlighterGeneric, GrammarState, HighlighterCore, ShikiInternal, RegexEngine, LoadWasmOptions, ShikiTransformerContextCommon, CodeToHastRenderOptions, ShikiTransformerContextSource, ThemeRegistrationResolved, TokenizeWithThemeOptions, ThemeRegistrationAny, ThemeRegistration, ShikiTransformer, MaybeArray, PlainTextLanguage, SpecialLanguage, SpecialTheme, MaybeGetter, TokenStyles, Position } from '@shikijs/types';
|
|
2
2
|
export * from '@shikijs/types';
|
|
3
3
|
import { Root, Element } from 'hast';
|
|
4
|
-
|
|
4
|
+
import { JavaScriptRegexEngineOptions } from '@shikijs/engine-javascript';
|
|
5
5
|
import { IGrammar } from '@shikijs/vscode-textmate';
|
|
6
6
|
export { FontStyle, EncodedTokenMetadata as StackElementMetadata } from '@shikijs/vscode-textmate';
|
|
7
|
-
export { createWasmOnigEngine, loadWasm } from '@shikijs/engine-oniguruma';
|
|
8
7
|
export { toHtml as hastToHtml } from 'hast-util-to-html';
|
|
9
8
|
|
|
10
9
|
/**
|
|
@@ -21,7 +20,7 @@ export { toHtml as hastToHtml } from 'hast-util-to-html';
|
|
|
21
20
|
* nord: () => import('shiki/themes/nord.mjs'),
|
|
22
21
|
* // ...
|
|
23
22
|
* },
|
|
24
|
-
* engine: () =>
|
|
23
|
+
* engine: () => createOnigurumaEngine(), // or createJavaScriptRegexEngine()
|
|
25
24
|
* })
|
|
26
25
|
* ```
|
|
27
26
|
*
|
|
@@ -123,10 +122,26 @@ declare function getShikiInternal(options?: HighlighterCoreOptions): Promise<Shi
|
|
|
123
122
|
declare function createShikiInternalSync(options: HighlighterCoreOptions<true>): ShikiInternal;
|
|
124
123
|
|
|
125
124
|
/**
|
|
126
|
-
*
|
|
127
|
-
|
|
125
|
+
* @deprecated Import `createJavaScriptRegexEngine` from `@shikijs/engine-javascript` or `shiki/engine/javascript` instead.
|
|
126
|
+
*/
|
|
127
|
+
declare function createJavaScriptRegexEngine(options?: JavaScriptRegexEngineOptions): RegexEngine;
|
|
128
|
+
/**
|
|
129
|
+
* @deprecated Import `defaultJavaScriptRegexConstructor` from `@shikijs/engine-javascript` or `shiki/engine/javascript` instead.
|
|
130
|
+
*/
|
|
131
|
+
declare function defaultJavaScriptRegexConstructor(pattern: string): RegExp;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* @deprecated Import `createOnigurumaEngine` from `@shikijs/engine-oniguruma` or `shiki/engine/oniguruma` instead.
|
|
135
|
+
*/
|
|
136
|
+
declare function createOnigurumaEngine(options?: LoadWasmOptions | null): Promise<RegexEngine>;
|
|
137
|
+
/**
|
|
138
|
+
* @deprecated Import `createOnigurumaEngine` from `@shikijs/engine-oniguruma` or `shiki/engine/oniguruma` instead.
|
|
139
|
+
*/
|
|
140
|
+
declare function createWasmOnigEngine(options?: LoadWasmOptions | null): Promise<RegexEngine>;
|
|
141
|
+
/**
|
|
142
|
+
* @deprecated Import `loadWasm` from `@shikijs/engine-oniguruma` or `shiki/engine/oniguruma` instead.
|
|
128
143
|
*/
|
|
129
|
-
declare function
|
|
144
|
+
declare function loadWasm(options: LoadWasmOptions): Promise<void>;
|
|
130
145
|
|
|
131
146
|
declare function codeToHast(internal: ShikiInternal, code: string, options: CodeToHastOptions, transformerContext?: ShikiTransformerContextCommon): Root;
|
|
132
147
|
declare function tokensToHast(tokens: ThemedToken[][], options: CodeToHastRenderOptions, transformerContext: ShikiTransformerContextSource): Root;
|
|
@@ -161,6 +176,39 @@ declare function codeToTokensWithThemes(internal: ShikiInternal, code: string, o
|
|
|
161
176
|
*/
|
|
162
177
|
declare function normalizeTheme(rawTheme: ThemeRegistrationAny): ThemeRegistrationResolved;
|
|
163
178
|
|
|
179
|
+
interface CssVariablesThemeOptions {
|
|
180
|
+
/**
|
|
181
|
+
* Theme name. Need to unique if multiple css variables themes are created
|
|
182
|
+
*
|
|
183
|
+
* @default 'css-variables'
|
|
184
|
+
*/
|
|
185
|
+
name?: string;
|
|
186
|
+
/**
|
|
187
|
+
* Prefix for css variables
|
|
188
|
+
*
|
|
189
|
+
* @default '--shiki-'
|
|
190
|
+
*/
|
|
191
|
+
variablePrefix?: string;
|
|
192
|
+
/**
|
|
193
|
+
* Default value for css variables, the key is without the prefix
|
|
194
|
+
*
|
|
195
|
+
* @example `{ 'token-comment': '#888' }` will generate `var(--shiki-token-comment, #888)` for comments
|
|
196
|
+
*/
|
|
197
|
+
variableDefaults?: Record<string, string>;
|
|
198
|
+
/**
|
|
199
|
+
* Enable font style
|
|
200
|
+
*
|
|
201
|
+
* @default true
|
|
202
|
+
*/
|
|
203
|
+
fontStyle?: boolean;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* A factory function to create a css-variable-based theme
|
|
207
|
+
*
|
|
208
|
+
* @see https://shiki.style/guide/theme-colors#css-variables-theme
|
|
209
|
+
*/
|
|
210
|
+
declare function createCssVariablesTheme(options?: CssVariablesThemeOptions): ThemeRegistration;
|
|
211
|
+
|
|
164
212
|
/**
|
|
165
213
|
* A built-in transformer to add decorations to the highlighted code.
|
|
166
214
|
*/
|
|
@@ -219,7 +267,7 @@ declare function resolveColorReplacements(theme: ThemeRegistrationAny | string,
|
|
|
219
267
|
declare function applyColorReplacements(color: string, replacements?: Record<string, string | undefined>): string;
|
|
220
268
|
declare function applyColorReplacements(color?: string | undefined, replacements?: Record<string, string | undefined>): string | undefined;
|
|
221
269
|
declare function getTokenStyleObject(token: TokenStyles): Record<string, string>;
|
|
222
|
-
declare function stringifyTokenStyle(token: Record<string, string>): string;
|
|
270
|
+
declare function stringifyTokenStyle(token: string | Record<string, string>): string;
|
|
223
271
|
/**
|
|
224
272
|
* Creates a converter between index and position in a code block.
|
|
225
273
|
*
|
|
@@ -231,4 +279,17 @@ declare function createPositionConverter(code: string): {
|
|
|
231
279
|
posToIndex: (line: number, character: number) => number;
|
|
232
280
|
};
|
|
233
281
|
|
|
234
|
-
|
|
282
|
+
/**
|
|
283
|
+
* Enable runtime warning for deprecated APIs, for the future versions of Shiki.
|
|
284
|
+
*
|
|
285
|
+
* Disabled by default, will be enabled in Shiki v2.
|
|
286
|
+
*
|
|
287
|
+
* @experimental The accuracy of the warning messages is not yet guaranteed.
|
|
288
|
+
*/
|
|
289
|
+
declare function enableDeprecationWarnings(value?: boolean): void;
|
|
290
|
+
/**
|
|
291
|
+
* @internal
|
|
292
|
+
*/
|
|
293
|
+
declare function warnDeprecated(message: string): void;
|
|
294
|
+
|
|
295
|
+
export { type CssVariablesThemeOptions, type ShorthandsBundle, addClassToHast, applyColorReplacements, codeToHast, codeToHtml, codeToTokens, codeToTokensBase, codeToTokensWithThemes, createCssVariablesTheme, createHighlighterCore, createHighlighterCoreSync, createJavaScriptRegexEngine, createOnigurumaEngine, createPositionConverter, createShikiInternal, createShikiInternalSync, createSingletonShorthands, createWasmOnigEngine, createdBundledHighlighter, defaultJavaScriptRegexConstructor, enableDeprecationWarnings, getHighlighterCore, getShikiInternal, getSingletonHighlighterCore, getTokenStyleObject, isNoneTheme, isPlainLang, isSpecialLang, isSpecialTheme, loadWasm, makeSingletonHighlighter, makeSingletonHighlighterCore, normalizeGetter, normalizeTheme, resolveColorReplacements, splitLines, splitToken, splitTokens, stringifyTokenStyle, toArray, tokenizeAnsiWithTheme, tokenizeWithTheme, tokensToHast, transformerDecorations, warnDeprecated };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { CreatedBundledHighlighterOptions, CreateHighlighterFactory, LanguageInput, ThemeInput, HighlighterCoreOptions, CodeToHastOptions, CodeToTokensOptions, TokensResult, RequireKeys, CodeToTokensBaseOptions, ThemedToken, CodeToTokensWithThemesOptions, ThemedTokenWithVariants, BundledHighlighterOptions, HighlighterGeneric, GrammarState, HighlighterCore, ShikiInternal, LoadWasmOptions, ShikiTransformerContextCommon, CodeToHastRenderOptions, ShikiTransformerContextSource, ThemeRegistrationResolved, TokenizeWithThemeOptions, ThemeRegistrationAny, ShikiTransformer, MaybeArray, PlainTextLanguage, SpecialLanguage, SpecialTheme, MaybeGetter, TokenStyles, Position } from '@shikijs/types';
|
|
1
|
+
import { CreatedBundledHighlighterOptions, CreateHighlighterFactory, LanguageInput, ThemeInput, HighlighterCoreOptions, CodeToHastOptions, CodeToTokensOptions, TokensResult, RequireKeys, CodeToTokensBaseOptions, ThemedToken, CodeToTokensWithThemesOptions, ThemedTokenWithVariants, BundledHighlighterOptions, HighlighterGeneric, GrammarState, HighlighterCore, ShikiInternal, RegexEngine, LoadWasmOptions, ShikiTransformerContextCommon, CodeToHastRenderOptions, ShikiTransformerContextSource, ThemeRegistrationResolved, TokenizeWithThemeOptions, ThemeRegistrationAny, ThemeRegistration, ShikiTransformer, MaybeArray, PlainTextLanguage, SpecialLanguage, SpecialTheme, MaybeGetter, TokenStyles, Position } from '@shikijs/types';
|
|
2
2
|
export * from '@shikijs/types';
|
|
3
3
|
import { Root, Element } from 'hast';
|
|
4
|
-
|
|
4
|
+
import { JavaScriptRegexEngineOptions } from '@shikijs/engine-javascript';
|
|
5
5
|
import { IGrammar } from '@shikijs/vscode-textmate';
|
|
6
6
|
export { FontStyle, EncodedTokenMetadata as StackElementMetadata } from '@shikijs/vscode-textmate';
|
|
7
|
-
export { createWasmOnigEngine, loadWasm } from '@shikijs/engine-oniguruma';
|
|
8
7
|
export { toHtml as hastToHtml } from 'hast-util-to-html';
|
|
9
8
|
|
|
10
9
|
/**
|
|
@@ -21,7 +20,7 @@ export { toHtml as hastToHtml } from 'hast-util-to-html';
|
|
|
21
20
|
* nord: () => import('shiki/themes/nord.mjs'),
|
|
22
21
|
* // ...
|
|
23
22
|
* },
|
|
24
|
-
* engine: () =>
|
|
23
|
+
* engine: () => createOnigurumaEngine(), // or createJavaScriptRegexEngine()
|
|
25
24
|
* })
|
|
26
25
|
* ```
|
|
27
26
|
*
|
|
@@ -123,10 +122,26 @@ declare function getShikiInternal(options?: HighlighterCoreOptions): Promise<Shi
|
|
|
123
122
|
declare function createShikiInternalSync(options: HighlighterCoreOptions<true>): ShikiInternal;
|
|
124
123
|
|
|
125
124
|
/**
|
|
126
|
-
*
|
|
127
|
-
|
|
125
|
+
* @deprecated Import `createJavaScriptRegexEngine` from `@shikijs/engine-javascript` or `shiki/engine/javascript` instead.
|
|
126
|
+
*/
|
|
127
|
+
declare function createJavaScriptRegexEngine(options?: JavaScriptRegexEngineOptions): RegexEngine;
|
|
128
|
+
/**
|
|
129
|
+
* @deprecated Import `defaultJavaScriptRegexConstructor` from `@shikijs/engine-javascript` or `shiki/engine/javascript` instead.
|
|
130
|
+
*/
|
|
131
|
+
declare function defaultJavaScriptRegexConstructor(pattern: string): RegExp;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* @deprecated Import `createOnigurumaEngine` from `@shikijs/engine-oniguruma` or `shiki/engine/oniguruma` instead.
|
|
135
|
+
*/
|
|
136
|
+
declare function createOnigurumaEngine(options?: LoadWasmOptions | null): Promise<RegexEngine>;
|
|
137
|
+
/**
|
|
138
|
+
* @deprecated Import `createOnigurumaEngine` from `@shikijs/engine-oniguruma` or `shiki/engine/oniguruma` instead.
|
|
139
|
+
*/
|
|
140
|
+
declare function createWasmOnigEngine(options?: LoadWasmOptions | null): Promise<RegexEngine>;
|
|
141
|
+
/**
|
|
142
|
+
* @deprecated Import `loadWasm` from `@shikijs/engine-oniguruma` or `shiki/engine/oniguruma` instead.
|
|
128
143
|
*/
|
|
129
|
-
declare function
|
|
144
|
+
declare function loadWasm(options: LoadWasmOptions): Promise<void>;
|
|
130
145
|
|
|
131
146
|
declare function codeToHast(internal: ShikiInternal, code: string, options: CodeToHastOptions, transformerContext?: ShikiTransformerContextCommon): Root;
|
|
132
147
|
declare function tokensToHast(tokens: ThemedToken[][], options: CodeToHastRenderOptions, transformerContext: ShikiTransformerContextSource): Root;
|
|
@@ -161,6 +176,39 @@ declare function codeToTokensWithThemes(internal: ShikiInternal, code: string, o
|
|
|
161
176
|
*/
|
|
162
177
|
declare function normalizeTheme(rawTheme: ThemeRegistrationAny): ThemeRegistrationResolved;
|
|
163
178
|
|
|
179
|
+
interface CssVariablesThemeOptions {
|
|
180
|
+
/**
|
|
181
|
+
* Theme name. Need to unique if multiple css variables themes are created
|
|
182
|
+
*
|
|
183
|
+
* @default 'css-variables'
|
|
184
|
+
*/
|
|
185
|
+
name?: string;
|
|
186
|
+
/**
|
|
187
|
+
* Prefix for css variables
|
|
188
|
+
*
|
|
189
|
+
* @default '--shiki-'
|
|
190
|
+
*/
|
|
191
|
+
variablePrefix?: string;
|
|
192
|
+
/**
|
|
193
|
+
* Default value for css variables, the key is without the prefix
|
|
194
|
+
*
|
|
195
|
+
* @example `{ 'token-comment': '#888' }` will generate `var(--shiki-token-comment, #888)` for comments
|
|
196
|
+
*/
|
|
197
|
+
variableDefaults?: Record<string, string>;
|
|
198
|
+
/**
|
|
199
|
+
* Enable font style
|
|
200
|
+
*
|
|
201
|
+
* @default true
|
|
202
|
+
*/
|
|
203
|
+
fontStyle?: boolean;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* A factory function to create a css-variable-based theme
|
|
207
|
+
*
|
|
208
|
+
* @see https://shiki.style/guide/theme-colors#css-variables-theme
|
|
209
|
+
*/
|
|
210
|
+
declare function createCssVariablesTheme(options?: CssVariablesThemeOptions): ThemeRegistration;
|
|
211
|
+
|
|
164
212
|
/**
|
|
165
213
|
* A built-in transformer to add decorations to the highlighted code.
|
|
166
214
|
*/
|
|
@@ -219,7 +267,7 @@ declare function resolveColorReplacements(theme: ThemeRegistrationAny | string,
|
|
|
219
267
|
declare function applyColorReplacements(color: string, replacements?: Record<string, string | undefined>): string;
|
|
220
268
|
declare function applyColorReplacements(color?: string | undefined, replacements?: Record<string, string | undefined>): string | undefined;
|
|
221
269
|
declare function getTokenStyleObject(token: TokenStyles): Record<string, string>;
|
|
222
|
-
declare function stringifyTokenStyle(token: Record<string, string>): string;
|
|
270
|
+
declare function stringifyTokenStyle(token: string | Record<string, string>): string;
|
|
223
271
|
/**
|
|
224
272
|
* Creates a converter between index and position in a code block.
|
|
225
273
|
*
|
|
@@ -231,4 +279,17 @@ declare function createPositionConverter(code: string): {
|
|
|
231
279
|
posToIndex: (line: number, character: number) => number;
|
|
232
280
|
};
|
|
233
281
|
|
|
234
|
-
|
|
282
|
+
/**
|
|
283
|
+
* Enable runtime warning for deprecated APIs, for the future versions of Shiki.
|
|
284
|
+
*
|
|
285
|
+
* Disabled by default, will be enabled in Shiki v2.
|
|
286
|
+
*
|
|
287
|
+
* @experimental The accuracy of the warning messages is not yet guaranteed.
|
|
288
|
+
*/
|
|
289
|
+
declare function enableDeprecationWarnings(value?: boolean): void;
|
|
290
|
+
/**
|
|
291
|
+
* @internal
|
|
292
|
+
*/
|
|
293
|
+
declare function warnDeprecated(message: string): void;
|
|
294
|
+
|
|
295
|
+
export { type CssVariablesThemeOptions, type ShorthandsBundle, addClassToHast, applyColorReplacements, codeToHast, codeToHtml, codeToTokens, codeToTokensBase, codeToTokensWithThemes, createCssVariablesTheme, createHighlighterCore, createHighlighterCoreSync, createJavaScriptRegexEngine, createOnigurumaEngine, createPositionConverter, createShikiInternal, createShikiInternalSync, createSingletonShorthands, createWasmOnigEngine, createdBundledHighlighter, defaultJavaScriptRegexConstructor, enableDeprecationWarnings, getHighlighterCore, getShikiInternal, getSingletonHighlighterCore, getTokenStyleObject, isNoneTheme, isPlainLang, isSpecialLang, isSpecialTheme, loadWasm, makeSingletonHighlighter, makeSingletonHighlighterCore, normalizeGetter, normalizeTheme, resolveColorReplacements, splitLines, splitToken, splitTokens, stringifyTokenStyle, toArray, tokenizeAnsiWithTheme, tokenizeWithTheme, tokensToHast, transformerDecorations, warnDeprecated };
|
package/dist/index.mjs
CHANGED
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
import { ShikiError as ShikiError$1 } from '@shikijs/types';
|
|
2
2
|
export * from '@shikijs/types';
|
|
3
|
+
import { createOnigurumaEngine as createOnigurumaEngine$1, loadWasm as loadWasm$1, getDefaultWasmLoader } from '@shikijs/engine-oniguruma';
|
|
4
|
+
import { w as warnDeprecated } from './shared/core.afb6276c.mjs';
|
|
5
|
+
export { e as enableDeprecationWarnings } from './shared/core.afb6276c.mjs';
|
|
3
6
|
import { FontStyle, INITIAL, EncodedTokenMetadata, Registry as Registry$1, Theme } from '@shikijs/vscode-textmate';
|
|
4
7
|
export { FontStyle, EncodedTokenMetadata as StackElementMetadata } from '@shikijs/vscode-textmate';
|
|
5
8
|
import { toHtml } from 'hast-util-to-html';
|
|
6
9
|
export { toHtml as hastToHtml } from 'hast-util-to-html';
|
|
7
|
-
import {
|
|
8
|
-
export { createWasmOnigEngine, loadWasm } from '@shikijs/engine-oniguruma';
|
|
9
|
-
export { createJavaScriptRegexEngine, defaultJavaScriptRegexConstructor } from '@shikijs/engine-javascript';
|
|
10
|
+
import { createJavaScriptRegexEngine as createJavaScriptRegexEngine$1, defaultJavaScriptRegexConstructor as defaultJavaScriptRegexConstructor$1 } from '@shikijs/engine-javascript';
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
function createOnigurumaEngine(options) {
|
|
13
|
+
warnDeprecated("import `createOnigurumaEngine` from `@shikijs/engine-oniguruma` or `shiki/engine/oniguruma` instead");
|
|
14
|
+
return createOnigurumaEngine$1(options);
|
|
14
15
|
}
|
|
15
|
-
function
|
|
16
|
-
|
|
16
|
+
function createWasmOnigEngine(options) {
|
|
17
|
+
warnDeprecated("import `createOnigurumaEngine` from `@shikijs/engine-oniguruma` or `shiki/engine/oniguruma` instead");
|
|
18
|
+
return createOnigurumaEngine$1(options);
|
|
19
|
+
}
|
|
20
|
+
function loadWasm(options) {
|
|
21
|
+
warnDeprecated("import `loadWasm` from `@shikijs/engine-oniguruma` or `shiki/engine/oniguruma` instead");
|
|
22
|
+
return loadWasm$1(options);
|
|
17
23
|
}
|
|
18
24
|
|
|
19
25
|
function toArray(x) {
|
|
@@ -131,6 +137,8 @@ function getTokenStyleObject(token) {
|
|
|
131
137
|
return styles;
|
|
132
138
|
}
|
|
133
139
|
function stringifyTokenStyle(token) {
|
|
140
|
+
if (typeof token === "string")
|
|
141
|
+
return token;
|
|
134
142
|
return Object.entries(token).map(([key, value]) => `${key}:${value}`).join(";");
|
|
135
143
|
}
|
|
136
144
|
function createPositionConverter(code) {
|
|
@@ -1039,23 +1047,20 @@ function mergeToken(merged, variantsOrder, cssVariablePrefix, defaultColor) {
|
|
|
1039
1047
|
};
|
|
1040
1048
|
const styles = variantsOrder.map((t) => getTokenStyleObject(merged.variants[t]));
|
|
1041
1049
|
const styleKeys = new Set(styles.flatMap((t) => Object.keys(t)));
|
|
1042
|
-
const mergedStyles =
|
|
1050
|
+
const mergedStyles = {};
|
|
1051
|
+
styles.forEach((cur, idx) => {
|
|
1043
1052
|
for (const key of styleKeys) {
|
|
1044
1053
|
const value = cur[key] || "inherit";
|
|
1045
1054
|
if (idx === 0 && defaultColor) {
|
|
1046
|
-
|
|
1055
|
+
mergedStyles[key] = value;
|
|
1047
1056
|
} else {
|
|
1048
1057
|
const keyName = key === "color" ? "" : key === "background-color" ? "-bg" : `-${key}`;
|
|
1049
1058
|
const varKey = cssVariablePrefix + variantsOrder[idx] + (key === "color" ? "" : keyName);
|
|
1050
|
-
|
|
1051
|
-
acc[key] += `;${varKey}:${value}`;
|
|
1052
|
-
else
|
|
1053
|
-
acc[key] = `${varKey}:${value}`;
|
|
1059
|
+
mergedStyles[varKey] = value;
|
|
1054
1060
|
}
|
|
1055
1061
|
}
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
token.htmlStyle = defaultColor ? stringifyTokenStyle(mergedStyles) : Object.values(mergedStyles).join(";");
|
|
1062
|
+
});
|
|
1063
|
+
token.htmlStyle = mergedStyles;
|
|
1059
1064
|
return token;
|
|
1060
1065
|
}
|
|
1061
1066
|
|
|
@@ -1181,14 +1186,18 @@ function tokensToHast(tokens, options, transformerContext) {
|
|
|
1181
1186
|
let tokenNode = {
|
|
1182
1187
|
type: "element",
|
|
1183
1188
|
tagName: "span",
|
|
1184
|
-
properties: {
|
|
1189
|
+
properties: {
|
|
1190
|
+
...token.htmlAttrs
|
|
1191
|
+
},
|
|
1185
1192
|
children: [{ type: "text", value: token.content }]
|
|
1186
1193
|
};
|
|
1187
|
-
|
|
1194
|
+
if (typeof token.htmlStyle === "string")
|
|
1195
|
+
warnDeprecated("`htmlStyle` as a string is deprecated. Use an object instead.");
|
|
1196
|
+
const style = stringifyTokenStyle(token.htmlStyle || getTokenStyleObject(token));
|
|
1188
1197
|
if (style)
|
|
1189
1198
|
tokenNode.properties.style = style;
|
|
1190
1199
|
for (const transformer of transformers)
|
|
1191
|
-
tokenNode = transformer?.span?.call(context, tokenNode, idx + 1, col, lineNode) || tokenNode;
|
|
1200
|
+
tokenNode = transformer?.span?.call(context, tokenNode, idx + 1, col, lineNode, token) || tokenNode;
|
|
1192
1201
|
if (structure === "inline")
|
|
1193
1202
|
root.children.push(tokenNode);
|
|
1194
1203
|
else if (structure === "classic")
|
|
@@ -1694,6 +1703,9 @@ function createShikiInternalSync(options) {
|
|
|
1694
1703
|
}
|
|
1695
1704
|
|
|
1696
1705
|
async function createShikiInternal(options = {}) {
|
|
1706
|
+
if (options.loadWasm) {
|
|
1707
|
+
warnDeprecated("`loadWasm` option is deprecated. Use `engine: createOnigurumaEngine(loadWasm)` instead.");
|
|
1708
|
+
}
|
|
1697
1709
|
const [
|
|
1698
1710
|
themes,
|
|
1699
1711
|
langs,
|
|
@@ -1701,7 +1713,7 @@ async function createShikiInternal(options = {}) {
|
|
|
1701
1713
|
] = await Promise.all([
|
|
1702
1714
|
resolveThemes(options.themes || []),
|
|
1703
1715
|
resolveLangs(options.langs || []),
|
|
1704
|
-
options.engine ||
|
|
1716
|
+
options.engine || createOnigurumaEngine$1(options.loadWasm || getDefaultWasmLoader())
|
|
1705
1717
|
]);
|
|
1706
1718
|
return createShikiInternalSync({
|
|
1707
1719
|
...options,
|
|
@@ -1712,6 +1724,7 @@ async function createShikiInternal(options = {}) {
|
|
|
1712
1724
|
});
|
|
1713
1725
|
}
|
|
1714
1726
|
function getShikiInternal(options = {}) {
|
|
1727
|
+
warnDeprecated("`getShikiInternal` is deprecated. Use `createShikiInternal` instead.");
|
|
1715
1728
|
return createShikiInternal(options);
|
|
1716
1729
|
}
|
|
1717
1730
|
|
|
@@ -1764,6 +1777,7 @@ function makeSingletonHighlighterCore(createHighlighter) {
|
|
|
1764
1777
|
}
|
|
1765
1778
|
const getSingletonHighlighterCore = /* @__PURE__ */ makeSingletonHighlighterCore(createHighlighterCore);
|
|
1766
1779
|
function getHighlighterCore(options = {}) {
|
|
1780
|
+
warnDeprecated("`getHighlighterCore` is deprecated. Use `createHighlighterCore` or `getSingletonHighlighterCore` instead.");
|
|
1767
1781
|
return createHighlighterCore(options);
|
|
1768
1782
|
}
|
|
1769
1783
|
|
|
@@ -1772,9 +1786,10 @@ function createdBundledHighlighter(arg1, arg2, arg3) {
|
|
|
1772
1786
|
let bundledThemes;
|
|
1773
1787
|
let engine;
|
|
1774
1788
|
if (arg2) {
|
|
1789
|
+
warnDeprecated("`createdBundledHighlighter` signature with `bundledLanguages` and `bundledThemes` is deprecated. Use the options object signature instead.");
|
|
1775
1790
|
bundledLanguages = arg1;
|
|
1776
1791
|
bundledThemes = arg2;
|
|
1777
|
-
engine = () =>
|
|
1792
|
+
engine = () => createOnigurumaEngine(arg3);
|
|
1778
1793
|
} else {
|
|
1779
1794
|
const options = arg1;
|
|
1780
1795
|
bundledLanguages = options.langs;
|
|
@@ -1896,4 +1911,248 @@ function createSingletonShorthands(createHighlighter) {
|
|
|
1896
1911
|
};
|
|
1897
1912
|
}
|
|
1898
1913
|
|
|
1899
|
-
|
|
1914
|
+
function createJavaScriptRegexEngine(options) {
|
|
1915
|
+
warnDeprecated("import `createJavaScriptRegexEngine` from `@shikijs/engine-javascript` or `shiki/engine/javascript` instead");
|
|
1916
|
+
return createJavaScriptRegexEngine$1(options);
|
|
1917
|
+
}
|
|
1918
|
+
function defaultJavaScriptRegexConstructor(pattern) {
|
|
1919
|
+
warnDeprecated("import `defaultJavaScriptRegexConstructor` from `@shikijs/engine-javascript` or `shiki/engine/javascript` instead");
|
|
1920
|
+
return defaultJavaScriptRegexConstructor$1(pattern);
|
|
1921
|
+
}
|
|
1922
|
+
|
|
1923
|
+
function createCssVariablesTheme(options = {}) {
|
|
1924
|
+
const {
|
|
1925
|
+
name = "css-variables",
|
|
1926
|
+
variablePrefix = "--shiki-",
|
|
1927
|
+
fontStyle = true
|
|
1928
|
+
} = options;
|
|
1929
|
+
const variable = (name2) => {
|
|
1930
|
+
if (options.variableDefaults?.[name2])
|
|
1931
|
+
return `var(${variablePrefix}${name2}, ${options.variableDefaults[name2]})`;
|
|
1932
|
+
return `var(${variablePrefix}${name2})`;
|
|
1933
|
+
};
|
|
1934
|
+
const theme = {
|
|
1935
|
+
name,
|
|
1936
|
+
type: "dark",
|
|
1937
|
+
colors: {
|
|
1938
|
+
"editor.foreground": variable("foreground"),
|
|
1939
|
+
"editor.background": variable("background"),
|
|
1940
|
+
"terminal.ansiBlack": variable("ansi-black"),
|
|
1941
|
+
"terminal.ansiRed": variable("ansi-red"),
|
|
1942
|
+
"terminal.ansiGreen": variable("ansi-green"),
|
|
1943
|
+
"terminal.ansiYellow": variable("ansi-yellow"),
|
|
1944
|
+
"terminal.ansiBlue": variable("ansi-blue"),
|
|
1945
|
+
"terminal.ansiMagenta": variable("ansi-magenta"),
|
|
1946
|
+
"terminal.ansiCyan": variable("ansi-cyan"),
|
|
1947
|
+
"terminal.ansiWhite": variable("ansi-white"),
|
|
1948
|
+
"terminal.ansiBrightBlack": variable("ansi-bright-black"),
|
|
1949
|
+
"terminal.ansiBrightRed": variable("ansi-bright-red"),
|
|
1950
|
+
"terminal.ansiBrightGreen": variable("ansi-bright-green"),
|
|
1951
|
+
"terminal.ansiBrightYellow": variable("ansi-bright-yellow"),
|
|
1952
|
+
"terminal.ansiBrightBlue": variable("ansi-bright-blue"),
|
|
1953
|
+
"terminal.ansiBrightMagenta": variable("ansi-bright-magenta"),
|
|
1954
|
+
"terminal.ansiBrightCyan": variable("ansi-bright-cyan"),
|
|
1955
|
+
"terminal.ansiBrightWhite": variable("ansi-bright-white")
|
|
1956
|
+
},
|
|
1957
|
+
tokenColors: [
|
|
1958
|
+
{
|
|
1959
|
+
scope: [
|
|
1960
|
+
"keyword.operator.accessor",
|
|
1961
|
+
"meta.group.braces.round.function.arguments",
|
|
1962
|
+
"meta.template.expression",
|
|
1963
|
+
"markup.fenced_code meta.embedded.block"
|
|
1964
|
+
],
|
|
1965
|
+
settings: {
|
|
1966
|
+
foreground: variable("foreground")
|
|
1967
|
+
}
|
|
1968
|
+
},
|
|
1969
|
+
{
|
|
1970
|
+
scope: "emphasis",
|
|
1971
|
+
settings: {
|
|
1972
|
+
fontStyle: "italic"
|
|
1973
|
+
}
|
|
1974
|
+
},
|
|
1975
|
+
{
|
|
1976
|
+
scope: ["strong", "markup.heading.markdown", "markup.bold.markdown"],
|
|
1977
|
+
settings: {
|
|
1978
|
+
fontStyle: "bold"
|
|
1979
|
+
}
|
|
1980
|
+
},
|
|
1981
|
+
{
|
|
1982
|
+
scope: ["markup.italic.markdown"],
|
|
1983
|
+
settings: {
|
|
1984
|
+
fontStyle: "italic"
|
|
1985
|
+
}
|
|
1986
|
+
},
|
|
1987
|
+
{
|
|
1988
|
+
scope: "meta.link.inline.markdown",
|
|
1989
|
+
settings: {
|
|
1990
|
+
fontStyle: "underline",
|
|
1991
|
+
foreground: variable("token-link")
|
|
1992
|
+
}
|
|
1993
|
+
},
|
|
1994
|
+
{
|
|
1995
|
+
scope: ["string", "markup.fenced_code", "markup.inline"],
|
|
1996
|
+
settings: {
|
|
1997
|
+
foreground: variable("token-string")
|
|
1998
|
+
}
|
|
1999
|
+
},
|
|
2000
|
+
{
|
|
2001
|
+
scope: ["comment", "string.quoted.docstring.multi"],
|
|
2002
|
+
settings: {
|
|
2003
|
+
foreground: variable("token-comment")
|
|
2004
|
+
}
|
|
2005
|
+
},
|
|
2006
|
+
{
|
|
2007
|
+
scope: [
|
|
2008
|
+
"constant.numeric",
|
|
2009
|
+
"constant.language",
|
|
2010
|
+
"constant.other.placeholder",
|
|
2011
|
+
"constant.character.format.placeholder",
|
|
2012
|
+
"variable.language.this",
|
|
2013
|
+
"variable.other.object",
|
|
2014
|
+
"variable.other.class",
|
|
2015
|
+
"variable.other.constant",
|
|
2016
|
+
"meta.property-name",
|
|
2017
|
+
"meta.property-value",
|
|
2018
|
+
"support"
|
|
2019
|
+
],
|
|
2020
|
+
settings: {
|
|
2021
|
+
foreground: variable("token-constant")
|
|
2022
|
+
}
|
|
2023
|
+
},
|
|
2024
|
+
{
|
|
2025
|
+
scope: [
|
|
2026
|
+
"keyword",
|
|
2027
|
+
"storage.modifier",
|
|
2028
|
+
"storage.type",
|
|
2029
|
+
"storage.control.clojure",
|
|
2030
|
+
"entity.name.function.clojure",
|
|
2031
|
+
"entity.name.tag.yaml",
|
|
2032
|
+
"support.function.node",
|
|
2033
|
+
"support.type.property-name.json",
|
|
2034
|
+
"punctuation.separator.key-value",
|
|
2035
|
+
"punctuation.definition.template-expression"
|
|
2036
|
+
],
|
|
2037
|
+
settings: {
|
|
2038
|
+
foreground: variable("token-keyword")
|
|
2039
|
+
}
|
|
2040
|
+
},
|
|
2041
|
+
{
|
|
2042
|
+
scope: "variable.parameter.function",
|
|
2043
|
+
settings: {
|
|
2044
|
+
foreground: variable("token-parameter")
|
|
2045
|
+
}
|
|
2046
|
+
},
|
|
2047
|
+
{
|
|
2048
|
+
scope: [
|
|
2049
|
+
"support.function",
|
|
2050
|
+
"entity.name.type",
|
|
2051
|
+
"entity.other.inherited-class",
|
|
2052
|
+
"meta.function-call",
|
|
2053
|
+
"meta.instance.constructor",
|
|
2054
|
+
"entity.other.attribute-name",
|
|
2055
|
+
"entity.name.function",
|
|
2056
|
+
"constant.keyword.clojure"
|
|
2057
|
+
],
|
|
2058
|
+
settings: {
|
|
2059
|
+
foreground: variable("token-function")
|
|
2060
|
+
}
|
|
2061
|
+
},
|
|
2062
|
+
{
|
|
2063
|
+
scope: [
|
|
2064
|
+
"entity.name.tag",
|
|
2065
|
+
"string.quoted",
|
|
2066
|
+
"string.regexp",
|
|
2067
|
+
"string.interpolated",
|
|
2068
|
+
"string.template",
|
|
2069
|
+
"string.unquoted.plain.out.yaml",
|
|
2070
|
+
"keyword.other.template"
|
|
2071
|
+
],
|
|
2072
|
+
settings: {
|
|
2073
|
+
foreground: variable("token-string-expression")
|
|
2074
|
+
}
|
|
2075
|
+
},
|
|
2076
|
+
{
|
|
2077
|
+
scope: [
|
|
2078
|
+
"punctuation.definition.arguments",
|
|
2079
|
+
"punctuation.definition.dict",
|
|
2080
|
+
"punctuation.separator",
|
|
2081
|
+
"meta.function-call.arguments"
|
|
2082
|
+
],
|
|
2083
|
+
settings: {
|
|
2084
|
+
foreground: variable("token-punctuation")
|
|
2085
|
+
}
|
|
2086
|
+
},
|
|
2087
|
+
{
|
|
2088
|
+
// [Custom] Markdown links
|
|
2089
|
+
scope: [
|
|
2090
|
+
"markup.underline.link",
|
|
2091
|
+
"punctuation.definition.metadata.markdown"
|
|
2092
|
+
],
|
|
2093
|
+
settings: {
|
|
2094
|
+
foreground: variable("token-link")
|
|
2095
|
+
}
|
|
2096
|
+
},
|
|
2097
|
+
{
|
|
2098
|
+
// [Custom] Markdown list
|
|
2099
|
+
scope: ["beginning.punctuation.definition.list.markdown"],
|
|
2100
|
+
settings: {
|
|
2101
|
+
foreground: variable("token-string")
|
|
2102
|
+
}
|
|
2103
|
+
},
|
|
2104
|
+
{
|
|
2105
|
+
// [Custom] Markdown punctuation definition brackets
|
|
2106
|
+
scope: [
|
|
2107
|
+
"punctuation.definition.string.begin.markdown",
|
|
2108
|
+
"punctuation.definition.string.end.markdown",
|
|
2109
|
+
"string.other.link.title.markdown",
|
|
2110
|
+
"string.other.link.description.markdown"
|
|
2111
|
+
],
|
|
2112
|
+
settings: {
|
|
2113
|
+
foreground: variable("token-keyword")
|
|
2114
|
+
}
|
|
2115
|
+
},
|
|
2116
|
+
{
|
|
2117
|
+
// [Custom] Diff
|
|
2118
|
+
scope: [
|
|
2119
|
+
"markup.inserted",
|
|
2120
|
+
"meta.diff.header.to-file",
|
|
2121
|
+
"punctuation.definition.inserted"
|
|
2122
|
+
],
|
|
2123
|
+
settings: {
|
|
2124
|
+
foreground: variable("token-inserted")
|
|
2125
|
+
}
|
|
2126
|
+
},
|
|
2127
|
+
{
|
|
2128
|
+
scope: [
|
|
2129
|
+
"markup.deleted",
|
|
2130
|
+
"meta.diff.header.from-file",
|
|
2131
|
+
"punctuation.definition.deleted"
|
|
2132
|
+
],
|
|
2133
|
+
settings: {
|
|
2134
|
+
foreground: variable("token-deleted")
|
|
2135
|
+
}
|
|
2136
|
+
},
|
|
2137
|
+
{
|
|
2138
|
+
scope: [
|
|
2139
|
+
"markup.changed",
|
|
2140
|
+
"punctuation.definition.changed"
|
|
2141
|
+
],
|
|
2142
|
+
settings: {
|
|
2143
|
+
foreground: variable("token-changed")
|
|
2144
|
+
}
|
|
2145
|
+
}
|
|
2146
|
+
]
|
|
2147
|
+
};
|
|
2148
|
+
if (!fontStyle) {
|
|
2149
|
+
theme.tokenColors = theme.tokenColors?.map((tokenColor) => {
|
|
2150
|
+
if (tokenColor.settings?.fontStyle)
|
|
2151
|
+
delete tokenColor.settings.fontStyle;
|
|
2152
|
+
return tokenColor;
|
|
2153
|
+
});
|
|
2154
|
+
}
|
|
2155
|
+
return theme;
|
|
2156
|
+
}
|
|
2157
|
+
|
|
2158
|
+
export { addClassToHast, applyColorReplacements, codeToHast, codeToHtml, codeToTokens, codeToTokensBase, codeToTokensWithThemes, createCssVariablesTheme, createHighlighterCore, createHighlighterCoreSync, createJavaScriptRegexEngine, createOnigurumaEngine, createPositionConverter, createShikiInternal, createShikiInternalSync, createSingletonShorthands, createWasmOnigEngine, createdBundledHighlighter, defaultJavaScriptRegexConstructor, getHighlighterCore, getShikiInternal, getSingletonHighlighterCore, getTokenStyleObject, isNoneTheme, isPlainLang, isSpecialLang, isSpecialTheme, loadWasm, makeSingletonHighlighter, makeSingletonHighlighterCore, normalizeGetter, normalizeTheme, resolveColorReplacements, splitLines, splitToken, splitTokens, stringifyTokenStyle, toArray, tokenizeAnsiWithTheme, tokenizeWithTheme, tokensToHast, transformerDecorations, warnDeprecated };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
let emitDeprecation = false;
|
|
2
|
+
function enableDeprecationWarnings(value = true) {
|
|
3
|
+
emitDeprecation = value;
|
|
4
|
+
}
|
|
5
|
+
function warnDeprecated(message) {
|
|
6
|
+
if (emitDeprecation)
|
|
7
|
+
console.trace(`[SHIKI DEPRECATE]: ${message}`);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { enableDeprecationWarnings as e, warnDeprecated as w };
|
package/dist/wasm-inlined.mjs
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
+
import { w as warnDeprecated } from './shared/core.afb6276c.mjs';
|
|
1
2
|
export * from '@shikijs/engine-oniguruma/wasm-inlined';
|
|
2
3
|
export { default } from '@shikijs/engine-oniguruma/wasm-inlined';
|
|
4
|
+
|
|
5
|
+
warnDeprecated("Import from `@shikijs/engine-oniguruma/wasm-inlined` instead");
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shikijs/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.20.0",
|
|
5
5
|
"description": "Core of Shiki",
|
|
6
6
|
"author": "Pine Wu <octref@gmail.com>; Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -63,9 +63,9 @@
|
|
|
63
63
|
"@shikijs/vscode-textmate": "^9.2.2",
|
|
64
64
|
"@types/hast": "^3.0.4",
|
|
65
65
|
"hast-util-to-html": "^9.0.3",
|
|
66
|
-
"@shikijs/engine-
|
|
67
|
-
"@shikijs/
|
|
68
|
-
"@shikijs/
|
|
66
|
+
"@shikijs/engine-javascript": "1.20.0",
|
|
67
|
+
"@shikijs/engine-oniguruma": "1.20.0",
|
|
68
|
+
"@shikijs/types": "1.20.0"
|
|
69
69
|
},
|
|
70
70
|
"scripts": {
|
|
71
71
|
"build": "unbuild",
|