mini-shiki 4.0.2 → 4.1.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.
Files changed (2) hide show
  1. package/dist/shiki.js +15 -8
  2. package/package.json +5 -5
package/dist/shiki.js CHANGED
@@ -79,9 +79,10 @@ function isSpecialTheme(theme) {
79
79
  * // => [['hello\n', 0], ['world', 6]]
80
80
  * ```
81
81
  */
82
+ const RE_NEWLINE = /(\r?\n)/g;
82
83
  function splitLines(code, preserveEnding = false) {
83
84
  if (code.length === 0) return [["", 0]];
84
- const parts = code.split(/(\r?\n)/g);
85
+ const parts = code.split(RE_NEWLINE);
85
86
  let index = 0;
86
87
  const lines = [];
87
88
  for (let i = 0; i < parts.length; i += 2) {
@@ -195,7 +196,7 @@ function normalizeTheme(rawTheme) {
195
196
  * Resolve
196
197
  */
197
198
  async function resolveLangs(langs) {
198
- return Array.from(new Set((await Promise.all(langs.filter((l) => !isSpecialLang(l)).map(async (lang) => await normalizeGetter(lang).then((r) => Array.isArray(r) ? r : [r])))).flat()));
199
+ return [...new Set((await Promise.all(langs.filter((l) => !isSpecialLang(l)).map(async (lang) => await normalizeGetter(lang).then((r) => Array.isArray(r) ? r : [r])))).flat())];
199
200
  }
200
201
  async function resolveThemes(themes) {
201
202
  return (await Promise.all(themes.map(async (theme) => isSpecialTheme(theme) ? null : normalizeTheme(await normalizeGetter(theme))))).filter((i) => !!i);
@@ -206,13 +207,17 @@ function resolveLangAlias(name, alias) {
206
207
  const resolved = new Set([name]);
207
208
  while (alias[name]) {
208
209
  name = alias[name];
209
- if (resolved.has(name)) throw new ShikiError(`Circular alias \`${Array.from(resolved).join(" -> ")} -> ${name}\``);
210
+ if (resolved.has(name)) throw new ShikiError(`Circular alias \`${[...resolved].join(" -> ")} -> ${name}\``);
210
211
  resolved.add(name);
211
212
  }
212
213
  }
213
214
  return name;
214
215
  }
215
216
  var Registry$1 = class extends Registry {
217
+ _resolver;
218
+ _themes;
219
+ _langs;
220
+ _alias;
216
221
  _resolvedThemes = /* @__PURE__ */ new Map();
217
222
  _resolvedGrammars = /* @__PURE__ */ new Map();
218
223
  _langMap = /* @__PURE__ */ new Map();
@@ -291,7 +296,7 @@ var Registry$1 = class extends Registry {
291
296
  }
292
297
  loadLanguages(langs) {
293
298
  for (const lang of langs) this.resolveEmbeddedLanguages(lang);
294
- const langsGraphArray = Array.from(this._langGraph.entries());
299
+ const langsGraphArray = [...this._langGraph.entries()];
295
300
  const missingLangs = langsGraphArray.filter(([_, lang]) => !lang);
296
301
  if (missingLangs.length) {
297
302
  const dependents = langsGraphArray.filter(([_, lang]) => {
@@ -553,6 +558,8 @@ function getGrammarStack(state, theme) {
553
558
  if (!(state instanceof GrammarState)) throw new ShikiError("Invalid grammar state");
554
559
  return state.getInternalStack(theme);
555
560
  }
561
+ const RE_COMMA = /,/;
562
+ const RE_SPACE = / /;
556
563
  /**
557
564
  * Code to tokens, with a simple theme.
558
565
  */
@@ -633,7 +640,7 @@ function _tokenizeWithTheme(code, grammar, theme, colorMap, options) {
633
640
  let selectors;
634
641
  switch (typeof setting.scope) {
635
642
  case "string":
636
- selectors = setting.scope.split(/,/).map((scope) => scope.trim());
643
+ selectors = setting.scope.split(RE_COMMA).map((scope) => scope.trim());
637
644
  break;
638
645
  case "object":
639
646
  selectors = setting.scope;
@@ -642,7 +649,7 @@ function _tokenizeWithTheme(code, grammar, theme, colorMap, options) {
642
649
  }
643
650
  themeSettingsSelectors.push({
644
651
  settings: setting,
645
- selectors: selectors.map((selector) => selector.split(/ /))
652
+ selectors: selectors.map((selector) => selector.split(RE_SPACE))
646
653
  });
647
654
  }
648
655
  token.explanation = [];
@@ -687,7 +694,7 @@ function matchesOne(selector, scope) {
687
694
  return selector === scope || scope.substring(0, selector.length) === selector && scope[selector.length] === ".";
688
695
  }
689
696
  function matches(selectors, scope, parentScopes) {
690
- if (!matchesOne(selectors[selectors.length - 1], scope)) return false;
697
+ if (!matchesOne(selectors.at(-1), scope)) return false;
691
698
  let selectorParentIndex = selectors.length - 2;
692
699
  let parentIndex = parentScopes.length - 1;
693
700
  while (selectorParentIndex >= 0 && parentIndex >= 0) {
@@ -790,7 +797,7 @@ function alignThemesTokenization(...themes) {
790
797
  }
791
798
 
792
799
  //#endregion
793
- //#region node_modules/shiki/dist/langs-bundle-full-DfKZStlK.mjs
800
+ //#region node_modules/shiki/dist/langs-bundle-full-YTHnHqaM.mjs
794
801
  const bundledLanguagesInfo = [
795
802
  {
796
803
  "id": "abap",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mini-shiki",
3
- "version": "4.0.2",
3
+ "version": "4.1.0",
4
4
  "type": "module",
5
5
  "repository": "git+https://github.com/un-ts/mini-shiki.git",
6
6
  "homepage": "https://github.com/un-ts/mini-shiki#readme",
@@ -21,10 +21,10 @@
21
21
  "static"
22
22
  ],
23
23
  "dependencies": {
24
- "@shikijs/engine-oniguruma": "^4.0.2",
25
- "@shikijs/langs": "^4.0.2",
26
- "@shikijs/themes": "^4.0.2",
27
- "@shikijs/types": "^4.0.2",
24
+ "@shikijs/engine-oniguruma": "^4.1.0",
25
+ "@shikijs/langs": "^4.1.0",
26
+ "@shikijs/themes": "^4.1.0",
27
+ "@shikijs/types": "^4.1.0",
28
28
  "@shikijs/vscode-textmate": "^10.0.2"
29
29
  }
30
30
  }