@shikijs/core 1.2.3 → 1.2.4
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/chunk-tokens.d.mts +83 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +40 -12
- package/dist/textmate.d.mts +1 -1
- package/dist/textmate.mjs +1 -1
- package/dist/types.d.mts +2 -2
- package/package.json +1 -1
package/dist/chunk-tokens.d.mts
CHANGED
|
@@ -394,6 +394,18 @@ type RuleId = {
|
|
|
394
394
|
__brand: typeof ruleIdSymbol;
|
|
395
395
|
};
|
|
396
396
|
|
|
397
|
+
declare class Theme {
|
|
398
|
+
private readonly _colorMap;
|
|
399
|
+
private readonly _defaults;
|
|
400
|
+
private readonly _root;
|
|
401
|
+
static createFromRawTheme(source: IRawTheme | undefined, colorMap?: string[]): Theme;
|
|
402
|
+
static createFromParsedTheme(source: ParsedThemeRule[], colorMap?: string[]): Theme;
|
|
403
|
+
private readonly _cachedMatchRoot;
|
|
404
|
+
constructor(_colorMap: ColorMap, _defaults: StyleAttributes, _root: ThemeTrieElement);
|
|
405
|
+
getColorMap(): string[];
|
|
406
|
+
getDefaults(): StyleAttributes;
|
|
407
|
+
match(scopePath: ScopeStack | null): StyleAttributes | null;
|
|
408
|
+
}
|
|
397
409
|
/**
|
|
398
410
|
* Identifiers with a binary dot operator.
|
|
399
411
|
* Examples: `baz` or `foo.bar`
|
|
@@ -423,6 +435,76 @@ interface IRawThemeSetting {
|
|
|
423
435
|
readonly background?: string;
|
|
424
436
|
};
|
|
425
437
|
}
|
|
438
|
+
declare class ScopeStack {
|
|
439
|
+
readonly parent: ScopeStack | null;
|
|
440
|
+
readonly scopeName: ScopeName;
|
|
441
|
+
static push(path: ScopeStack | null, scopeNames: ScopeName[]): ScopeStack | null;
|
|
442
|
+
static from(first: ScopeName, ...segments: ScopeName[]): ScopeStack;
|
|
443
|
+
static from(...segments: ScopeName[]): ScopeStack | null;
|
|
444
|
+
constructor(parent: ScopeStack | null, scopeName: ScopeName);
|
|
445
|
+
push(scopeName: ScopeName): ScopeStack;
|
|
446
|
+
getSegments(): ScopeName[];
|
|
447
|
+
toString(): string;
|
|
448
|
+
extends(other: ScopeStack): boolean;
|
|
449
|
+
getExtensionIfDefined(base: ScopeStack | null): string[] | undefined;
|
|
450
|
+
}
|
|
451
|
+
declare class StyleAttributes {
|
|
452
|
+
readonly fontStyle: OrMask<FontStyle$1>;
|
|
453
|
+
readonly foregroundId: number;
|
|
454
|
+
readonly backgroundId: number;
|
|
455
|
+
constructor(fontStyle: OrMask<FontStyle$1>, foregroundId: number, backgroundId: number);
|
|
456
|
+
}
|
|
457
|
+
declare class ParsedThemeRule {
|
|
458
|
+
readonly scope: ScopeName;
|
|
459
|
+
readonly parentScopes: ScopeName[] | null;
|
|
460
|
+
readonly index: number;
|
|
461
|
+
readonly fontStyle: OrMask<FontStyle$1>;
|
|
462
|
+
readonly foreground: string | null;
|
|
463
|
+
readonly background: string | null;
|
|
464
|
+
constructor(scope: ScopeName, parentScopes: ScopeName[] | null, index: number, fontStyle: OrMask<FontStyle$1>, foreground: string | null, background: string | null);
|
|
465
|
+
}
|
|
466
|
+
declare const enum FontStyle$1 {
|
|
467
|
+
NotSet = -1,
|
|
468
|
+
None = 0,
|
|
469
|
+
Italic = 1,
|
|
470
|
+
Bold = 2,
|
|
471
|
+
Underline = 4,
|
|
472
|
+
Strikethrough = 8
|
|
473
|
+
}
|
|
474
|
+
declare class ColorMap {
|
|
475
|
+
private readonly _isFrozen;
|
|
476
|
+
private _lastColorId;
|
|
477
|
+
private _id2color;
|
|
478
|
+
private _color2id;
|
|
479
|
+
constructor(_colorMap?: string[]);
|
|
480
|
+
getId(color: string | null): number;
|
|
481
|
+
getColorMap(): string[];
|
|
482
|
+
}
|
|
483
|
+
declare class ThemeTrieElementRule {
|
|
484
|
+
scopeDepth: number;
|
|
485
|
+
parentScopes: ScopeName[] | null;
|
|
486
|
+
fontStyle: number;
|
|
487
|
+
foreground: number;
|
|
488
|
+
background: number;
|
|
489
|
+
constructor(scopeDepth: number, parentScopes: ScopeName[] | null, fontStyle: number, foreground: number, background: number);
|
|
490
|
+
clone(): ThemeTrieElementRule;
|
|
491
|
+
static cloneArr(arr: ThemeTrieElementRule[]): ThemeTrieElementRule[];
|
|
492
|
+
acceptOverwrite(scopeDepth: number, fontStyle: number, foreground: number, background: number): void;
|
|
493
|
+
}
|
|
494
|
+
interface ITrieChildrenMap {
|
|
495
|
+
[segment: string]: ThemeTrieElement;
|
|
496
|
+
}
|
|
497
|
+
declare class ThemeTrieElement {
|
|
498
|
+
private readonly _mainRule;
|
|
499
|
+
private readonly _children;
|
|
500
|
+
private readonly _rulesWithParentScopes;
|
|
501
|
+
constructor(_mainRule: ThemeTrieElementRule, rulesWithParentScopes?: ThemeTrieElementRule[], _children?: ITrieChildrenMap);
|
|
502
|
+
private static _sortBySpecificity;
|
|
503
|
+
private static _cmpBySpecificity;
|
|
504
|
+
match(scope: ScopeName): ThemeTrieElementRule[];
|
|
505
|
+
insert(scopeDepth: number, scope: ScopeName, parentScopes: ScopeName[] | null, fontStyle: number, foreground: number, background: number): void;
|
|
506
|
+
private _doInsertHere;
|
|
507
|
+
}
|
|
426
508
|
|
|
427
509
|
interface IRawGrammar extends ILocatable {
|
|
428
510
|
repository: IRawRepository;
|
|
@@ -1228,4 +1310,4 @@ declare enum FontStyle {
|
|
|
1228
1310
|
Underline = 4
|
|
1229
1311
|
}
|
|
1230
1312
|
|
|
1231
|
-
export { type
|
|
1313
|
+
export { type ThemeRegistration as $, type ThemeRegistrationAny as A, type BundledHighlighterOptions as B, type CodeToHastOptions as C, type ShikiTransformer as D, type Element as E, FontStyle as F, type AnsiLanguage as G, type HighlighterCoreOptions as H, INITIAL as I, type ResolveBundleKey as J, type LanguageRegistration as K, type LanguageInput as L, type MaybeArray as M, type Nodes as N, type BundledLanguageInfo as O, type PlainTextLanguage as P, type DynamicImportLanguageRegistration as Q, Registry as R, type StateStack as S, Theme as T, type CodeOptionsSingleTheme as U, type CodeOptionsMultipleThemes as V, type CodeOptionsThemes as W, type CodeToHastOptionsCommon as X, type CodeOptionsMeta as Y, type CodeToHastRenderOptionsCommon as Z, type ThemeRegistrationRaw as _, type IRawTheme as a, type DynamicImportThemeRegistration as a0, type BundledThemeInfo as a1, type ThemedTokenScopeExplanation as a2, type ThemedTokenExplanation as a3, type TokenBase as a4, type TransformerOptions as a5, type ShikiTransformerContextMeta as a6, type ShikiTransformerContext as a7, type Awaitable as a8, type MaybeGetter as a9, type MaybeModule as aa, type StringLiteralUnion as ab, type DecorationOptions as ac, type DecorationItem as ad, type ResolvedDecorationItem as ae, type DecorationTransformType as af, type Offset as ag, type OffsetOrPosition as ah, type ResolvedPosition as ai, type IRawGrammar as b, type IGrammar as c, type IGrammarConfiguration as d, type IOnigLib as e, type RegistryOptions as f, type IRawThemeSetting as g, type ThemeInput as h, type Root as i, type CodeToTokensOptions as j, type TokensResult as k, type RequireKeys as l, type CodeToTokensBaseOptions as m, type ThemedToken as n, type CodeToTokensWithThemesOptions as o, type ThemedTokenWithVariants as p, type SpecialLanguage as q, type SpecialTheme as r, type TokenStyles as s, type Position as t, type ThemeRegistrationResolved as u, type TokenizeWithThemeOptions as v, type ShikiTransformerContextCommon as w, type CodeToHastRenderOptions as x, type ShikiTransformerContextSource as y, type RootContent as z };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HighlighterCore, HighlighterGeneric, ShikiInternal } from './types.mjs';
|
|
2
|
-
import { H as HighlighterCoreOptions, B as BundledHighlighterOptions, L as LanguageInput,
|
|
3
|
-
export {
|
|
2
|
+
import { H as HighlighterCoreOptions, B as BundledHighlighterOptions, L as LanguageInput, h as ThemeInput, C as CodeToHastOptions, i as Root, j as CodeToTokensOptions, k as TokensResult, l as RequireKeys, m as CodeToTokensBaseOptions, n as ThemedToken, o as CodeToTokensWithThemesOptions, p as ThemedTokenWithVariants, M as MaybeArray, P as PlainTextLanguage, q as SpecialLanguage, r as SpecialTheme, E as Element, s as TokenStyles, t as Position, c as IGrammar, u as ThemeRegistrationResolved, v as TokenizeWithThemeOptions, w as ShikiTransformerContextCommon, x as CodeToHastRenderOptions, y as ShikiTransformerContextSource, N as Nodes$1, z as RootContent$1, A as ThemeRegistrationAny, D as ShikiTransformer } from './chunk-tokens.mjs';
|
|
3
|
+
export { G as AnsiLanguage, a8 as Awaitable, O as BundledLanguageInfo, a1 as BundledThemeInfo, Y as CodeOptionsMeta, V as CodeOptionsMultipleThemes, U as CodeOptionsSingleTheme, W as CodeOptionsThemes, X as CodeToHastOptionsCommon, Z as CodeToHastRenderOptionsCommon, ad as DecorationItem, ac as DecorationOptions, af as DecorationTransformType, Q as DynamicImportLanguageRegistration, a0 as DynamicImportThemeRegistration, F as FontStyle, K as LanguageRegistration, a9 as MaybeGetter, aa as MaybeModule, ag as Offset, ah as OffsetOrPosition, b as RawGrammar, a as RawTheme, g as RawThemeSetting, J as ResolveBundleKey, ae as ResolvedDecorationItem, ai as ResolvedPosition, a7 as ShikiTransformerContext, a6 as ShikiTransformerContextMeta, ab as StringLiteralUnion, $ as ThemeRegistration, _ as ThemeRegistrationRaw, a3 as ThemedTokenExplanation, a2 as ThemedTokenScopeExplanation, a4 as TokenBase, a5 as TransformerOptions } from './chunk-tokens.mjs';
|
|
4
4
|
import { L as LoadWasmOptions } from './chunk-index.mjs';
|
|
5
5
|
export { W as WebAssemblyInstantiator, l as loadWasm } from './chunk-index.mjs';
|
|
6
6
|
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StackElementMetadata, INITIAL, Registry as Registry$1 } from './textmate.mjs';
|
|
1
|
+
import { StackElementMetadata, INITIAL, Registry as Registry$1, Theme } from './textmate.mjs';
|
|
2
2
|
import { FontStyle } from './types.mjs';
|
|
3
3
|
|
|
4
4
|
function toArray(x) {
|
|
@@ -5111,16 +5111,20 @@ class Registry extends Registry$1 {
|
|
|
5111
5111
|
_resolver;
|
|
5112
5112
|
_themes;
|
|
5113
5113
|
_langs;
|
|
5114
|
+
_alias;
|
|
5114
5115
|
_resolvedThemes = {};
|
|
5115
5116
|
_resolvedGrammars = {};
|
|
5116
5117
|
_langMap = {};
|
|
5117
5118
|
_langGraph = new Map();
|
|
5118
|
-
|
|
5119
|
-
|
|
5119
|
+
_textmateThemeCache = new WeakMap();
|
|
5120
|
+
_loadedThemesCache = null;
|
|
5121
|
+
_loadedLanguagesCache = null;
|
|
5122
|
+
constructor(_resolver, _themes, _langs, _alias = {}) {
|
|
5120
5123
|
super(_resolver);
|
|
5121
5124
|
this._resolver = _resolver;
|
|
5122
5125
|
this._themes = _themes;
|
|
5123
5126
|
this._langs = _langs;
|
|
5127
|
+
this._alias = _alias;
|
|
5124
5128
|
_themes.forEach(t => this.loadTheme(t));
|
|
5125
5129
|
_langs.forEach(l => this.loadLanguage(l));
|
|
5126
5130
|
}
|
|
@@ -5132,18 +5136,37 @@ class Registry extends Registry$1 {
|
|
|
5132
5136
|
}
|
|
5133
5137
|
loadTheme(theme) {
|
|
5134
5138
|
const _theme = normalizeTheme(theme);
|
|
5135
|
-
if (_theme.name)
|
|
5139
|
+
if (_theme.name) {
|
|
5136
5140
|
this._resolvedThemes[_theme.name] = _theme;
|
|
5141
|
+
// Reset cache
|
|
5142
|
+
this._loadedThemesCache = null;
|
|
5143
|
+
}
|
|
5137
5144
|
return _theme;
|
|
5138
5145
|
}
|
|
5139
5146
|
getLoadedThemes() {
|
|
5140
|
-
|
|
5147
|
+
if (!this._loadedThemesCache)
|
|
5148
|
+
this._loadedThemesCache = Object.keys(this._resolvedThemes);
|
|
5149
|
+
return this._loadedThemesCache;
|
|
5150
|
+
}
|
|
5151
|
+
// Override and re-implement this method to cache the textmate themes as `TextMateTheme.createFromRawTheme`
|
|
5152
|
+
// is expensive. Themes can switch often especially for dual-theme support.
|
|
5153
|
+
//
|
|
5154
|
+
// The parent class also accepts `colorMap` as the second parameter, but since we don't use that,
|
|
5155
|
+
// we omit here so it's easier to cache the themes.
|
|
5156
|
+
setTheme(theme) {
|
|
5157
|
+
let textmateTheme = this._textmateThemeCache.get(theme);
|
|
5158
|
+
if (!textmateTheme) {
|
|
5159
|
+
textmateTheme = Theme.createFromRawTheme(theme);
|
|
5160
|
+
this._textmateThemeCache.set(theme, textmateTheme);
|
|
5161
|
+
}
|
|
5162
|
+
// @ts-expect-error Access private `_syncRegistry`, but should work in runtime
|
|
5163
|
+
this._syncRegistry.setTheme(textmateTheme);
|
|
5141
5164
|
}
|
|
5142
5165
|
getGrammar(name) {
|
|
5143
|
-
if (this.
|
|
5166
|
+
if (this._alias[name]) {
|
|
5144
5167
|
const resolved = new Set([name]);
|
|
5145
|
-
while (this.
|
|
5146
|
-
name = this.
|
|
5168
|
+
while (this._alias[name]) {
|
|
5169
|
+
name = this._alias[name];
|
|
5147
5170
|
if (resolved.has(name))
|
|
5148
5171
|
throw new ShikiError(`Circular alias \`${Array.from(resolved).join(' -> ')} -> ${name}\``);
|
|
5149
5172
|
resolved.add(name);
|
|
@@ -5166,13 +5189,17 @@ class Registry extends Registry$1 {
|
|
|
5166
5189
|
this._resolvedGrammars[lang.name] = g;
|
|
5167
5190
|
if (lang.aliases) {
|
|
5168
5191
|
lang.aliases.forEach((alias) => {
|
|
5169
|
-
this.
|
|
5192
|
+
this._alias[alias] = lang.name;
|
|
5170
5193
|
});
|
|
5171
5194
|
}
|
|
5195
|
+
// Reset cache
|
|
5196
|
+
this._loadedLanguagesCache = null;
|
|
5172
5197
|
// If there is a language that embeds this language lazily, we need to reload it
|
|
5173
5198
|
if (embeddedLazilyBy.size) {
|
|
5174
5199
|
for (const e of embeddedLazilyBy) {
|
|
5175
5200
|
delete this._resolvedGrammars[e.name];
|
|
5201
|
+
// Reset cache
|
|
5202
|
+
this._loadedLanguagesCache = null;
|
|
5176
5203
|
// @ts-expect-error clear cache
|
|
5177
5204
|
this._syncRegistry?._injectionGrammars?.delete(e.scopeName);
|
|
5178
5205
|
// @ts-expect-error clear cache
|
|
@@ -5202,7 +5229,9 @@ class Registry extends Registry$1 {
|
|
|
5202
5229
|
await this.loadLanguage(lang);
|
|
5203
5230
|
}
|
|
5204
5231
|
getLoadedLanguages() {
|
|
5205
|
-
|
|
5232
|
+
if (!this._loadedLanguagesCache)
|
|
5233
|
+
this._loadedLanguagesCache = Object.keys({ ...this._resolvedGrammars, ...this._alias });
|
|
5234
|
+
return this._loadedLanguagesCache;
|
|
5206
5235
|
}
|
|
5207
5236
|
resolveEmbeddedLanguages(lang) {
|
|
5208
5237
|
this._langMap[lang.name] = lang;
|
|
@@ -5293,8 +5322,7 @@ async function getShikiInternal(options = {}) {
|
|
|
5293
5322
|
return createOnigString(s);
|
|
5294
5323
|
},
|
|
5295
5324
|
}), langs);
|
|
5296
|
-
const _registry = new Registry(resolver, themes, langs);
|
|
5297
|
-
Object.assign(_registry.alias, options.langAlias);
|
|
5325
|
+
const _registry = new Registry(resolver, themes, langs, options.langAlias);
|
|
5298
5326
|
await _registry.init();
|
|
5299
5327
|
let _lastTheme;
|
|
5300
5328
|
function getLanguage(name) {
|
package/dist/textmate.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { F as FontStyle } from './chunk-tokens.mjs';
|
|
2
|
-
export { c as IGrammar, d as IGrammarConfiguration, I as INITIAL, e as IOnigLib, b as IRawGrammar, a as IRawTheme, g as IRawThemeSetting, R as Registry, f as RegistryOptions, S as StateStack } from './chunk-tokens.mjs';
|
|
2
|
+
export { c as IGrammar, d as IGrammarConfiguration, I as INITIAL, e as IOnigLib, b as IRawGrammar, a as IRawTheme, g as IRawThemeSetting, R as Registry, f as RegistryOptions, S as StateStack, T as Theme } from './chunk-tokens.mjs';
|
|
3
3
|
import './chunk-index.mjs';
|
|
4
4
|
|
|
5
5
|
declare const enum TemporaryStandardTokenType {
|
package/dist/textmate.mjs
CHANGED
package/dist/types.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { h as ThemeInput, r as SpecialTheme, L as LanguageInput, q as SpecialLanguage, A as ThemeRegistrationAny, u as ThemeRegistrationResolved, K as LanguageRegistration, c as IGrammar, C as CodeToHastOptions, J as ResolveBundleKey, i as Root, j as CodeToTokensOptions, k as TokensResult, m as CodeToTokensBaseOptions, n as ThemedToken, o as CodeToTokensWithThemesOptions, p as ThemedTokenWithVariants } from './chunk-tokens.mjs';
|
|
2
|
+
export { G as AnsiLanguage, a8 as Awaitable, B as BundledHighlighterOptions, O as BundledLanguageInfo, a1 as BundledThemeInfo, Y as CodeOptionsMeta, V as CodeOptionsMultipleThemes, U as CodeOptionsSingleTheme, W as CodeOptionsThemes, X as CodeToHastOptionsCommon, x as CodeToHastRenderOptions, Z as CodeToHastRenderOptionsCommon, ad as DecorationItem, ac as DecorationOptions, af as DecorationTransformType, Q as DynamicImportLanguageRegistration, a0 as DynamicImportThemeRegistration, F as FontStyle, H as HighlighterCoreOptions, M as MaybeArray, a9 as MaybeGetter, aa as MaybeModule, ag as Offset, ah as OffsetOrPosition, P as PlainTextLanguage, t as Position, b as RawGrammar, a as RawTheme, g as RawThemeSetting, l as RequireKeys, ae as ResolvedDecorationItem, ai as ResolvedPosition, D as ShikiTransformer, a7 as ShikiTransformerContext, w as ShikiTransformerContextCommon, a6 as ShikiTransformerContextMeta, y as ShikiTransformerContextSource, ab as StringLiteralUnion, $ as ThemeRegistration, _ as ThemeRegistrationRaw, a3 as ThemedTokenExplanation, a2 as ThemedTokenScopeExplanation, a4 as TokenBase, s as TokenStyles, v as TokenizeWithThemeOptions, a5 as TransformerOptions } from './chunk-tokens.mjs';
|
|
3
3
|
export { W as WebAssemblyInstantiator } from './chunk-index.mjs';
|
|
4
4
|
|
|
5
5
|
/**
|