@loopstack/loopstack-studio 0.25.2 → 0.26.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 (96) hide show
  1. package/dist/api/environments.js +4 -0
  2. package/dist/api/index.js +13 -9
  3. package/dist/app/EnvironmentEmbedRoot.js +29 -19
  4. package/dist/components/data-table/DataList.js +93 -91
  5. package/dist/components/data-table/DataTable.js +128 -126
  6. package/dist/components/feedback/Snackbar.js +1 -1
  7. package/dist/components/layout/StudioSidebar.js +124 -131
  8. package/dist/components/ui/sidebar.js +2 -2
  9. package/dist/components/ui/slider.js +37 -26
  10. package/dist/components/ui-widgets/widgets/SandboxRun.js +16 -14
  11. package/dist/features/code-explorer/components/CodeExplorerTree.js +1 -0
  12. package/dist/features/code-explorer/components/FileContentViewer.js +1 -1
  13. package/dist/features/dashboard/RunItem.js +39 -37
  14. package/dist/features/debug/lib/flow-utils.js +1 -1
  15. package/dist/features/documents/DocumentRenderer.js +59 -58
  16. package/dist/features/documents/renderers/useDocumentTransition.js +29 -24
  17. package/dist/features/feature-registry/FeatureRegistryProvider.js +17 -0
  18. package/dist/features/feature-registry/index.js +1 -0
  19. package/dist/features/file-explorer/api/files.js +7 -0
  20. package/dist/features/file-explorer/components/FileExplorerPanel.js +95 -0
  21. package/dist/features/{workbench/components/RemoteFileTabsBar.js → file-explorer/components/FileTabsBar.js} +4 -4
  22. package/dist/features/{workbench/components/RemoteFileTree.js → file-explorer/components/FileTree.js} +6 -6
  23. package/dist/features/file-explorer/file-explorer-feature.js +12 -0
  24. package/dist/features/file-explorer/hooks/useFileExplorer.js +44 -0
  25. package/dist/features/file-explorer/index.js +2 -0
  26. package/dist/features/file-explorer/providers/FileExplorerProvider.js +112 -0
  27. package/dist/features/oauth/OAuthPromptRenderer.js +162 -132
  28. package/dist/features/runs/Runs.js +1 -1
  29. package/dist/features/secrets/components/WorkbenchSecretsPanel.js +178 -0
  30. package/dist/features/secrets/index.js +1 -0
  31. package/dist/features/{documents → secrets}/renderers/SecretInputRenderer.js +17 -17
  32. package/dist/features/secrets/secrets-feature.js +14 -0
  33. package/dist/features/workbench/Workbench.js +32 -82
  34. package/dist/features/workbench/WorkflowList.js +109 -46
  35. package/dist/features/workbench/components/SidebarPanel.js +155 -0
  36. package/dist/features/workbench/components/WorkbenchEnvironmentPanel.js +82 -0
  37. package/dist/features/workbench/components/WorkbenchIconSidebar.js +128 -60
  38. package/dist/features/workbench/components/WorkbenchPreviewPanel.js +127 -114
  39. package/dist/features/workbench/components/WorkbenchRunsPanel.js +32 -0
  40. package/dist/features/workbench/components/WorkbenchSidebarShell.js +80 -0
  41. package/dist/features/workbench/hooks/useWorkflowData.js +3 -3
  42. package/dist/features/workbench/index.js +3 -2
  43. package/dist/features/workbench/providers/WorkbenchLayoutProvider.js +60 -62
  44. package/dist/features/workspaces/Workspaces.js +1 -1
  45. package/dist/features/workspaces/components/EnvironmentSlotSelector.js +68 -51
  46. package/dist/features/workspaces/components/WorkflowRunForm.js +1 -1
  47. package/dist/features/workspaces/components/WorkspaceHomePage.js +1 -1
  48. package/dist/hooks/useEnvironmentPreviewUrl.js +13 -0
  49. package/dist/hooks/useEnvironments.js +8 -0
  50. package/dist/hooks/useWorkflows.js +28 -26
  51. package/dist/hooks/useWorkspaces.js +28 -26
  52. package/dist/index.d.ts +98 -7
  53. package/dist/index.js +8 -1
  54. package/dist/loopstack-studio.css +1 -1
  55. package/dist/node_modules/@shikijs/core/dist/index.js +105 -643
  56. package/dist/node_modules/@shikijs/engine-oniguruma/dist/index.js +135 -122
  57. package/dist/node_modules/@shikijs/langs/dist/bird2.js +1 -1
  58. package/dist/node_modules/@shikijs/langs/dist/cobol.js +1 -1
  59. package/dist/node_modules/@shikijs/langs/dist/css.js +1 -1
  60. package/dist/node_modules/@shikijs/langs/dist/dart.js +1 -1
  61. package/dist/node_modules/@shikijs/langs/dist/emacs-lisp.js +1 -1
  62. package/dist/node_modules/@shikijs/langs/dist/es-tag-sql.js +1 -1
  63. package/dist/node_modules/@shikijs/langs/dist/go.js +1 -1
  64. package/dist/node_modules/@shikijs/langs/dist/kusto.js +1 -1
  65. package/dist/node_modules/@shikijs/langs/dist/nextflow-groovy.js +1 -1
  66. package/dist/node_modules/@shikijs/langs/dist/php.js +1 -1
  67. package/dist/node_modules/@shikijs/langs/dist/ruby.js +1 -1
  68. package/dist/node_modules/@shikijs/langs/dist/typespec.js +1 -1
  69. package/dist/node_modules/@shikijs/primitive/dist/index.js +538 -0
  70. package/dist/node_modules/@shikijs/themes/dist/horizon-bright.js +1 -1
  71. package/dist/node_modules/@xyflow/react/dist/esm/index.js +1 -1
  72. package/dist/node_modules/shiki/dist/bundle-full.js +6 -5
  73. package/dist/node_modules/shiki/dist/chunk-CtajNgzt.js +15 -0
  74. package/dist/node_modules/shiki/dist/engine-oniguruma.js +5 -0
  75. package/dist/node_modules/shiki/dist/{langs.js → langs-bundle-full-DfKZStlK.js} +1 -1
  76. package/dist/node_modules/shiki/dist/themes.js +1 -1
  77. package/dist/pages/DashboardPage.js +54 -79
  78. package/dist/pages/DebugWorkflowDetailsPage.js +41 -55
  79. package/dist/pages/DebugWorkflowsPage.js +151 -112
  80. package/dist/pages/EmbedWorkbenchPage.js +2 -1
  81. package/dist/pages/PreviewWorkbenchPage.js +77 -59
  82. package/dist/pages/RunsListPage.js +27 -41
  83. package/dist/pages/RunsPage.js +21 -36
  84. package/dist/pages/WorkbenchPage.js +48 -70
  85. package/dist/pages/WorkflowDebugPage.js +65 -79
  86. package/dist/pages/WorkspacePage.js +59 -86
  87. package/dist/pages/WorkspaceRunsPage.js +59 -54
  88. package/dist/pages/WorkspacesPage.js +11 -27
  89. package/dist/providers/StudioPreferencesProvider.js +54 -0
  90. package/package.json +29 -29
  91. package/dist/features/workbench/components/WorkbenchFilesPanel.js +0 -67
  92. package/dist/features/workbench/components/WorkbenchFloatingPanel.js +0 -57
  93. package/dist/features/workbench/components/WorkbenchFlowPanel.js +0 -47
  94. package/dist/features/workbench/components/WorkbenchSecretsPanel.js +0 -182
  95. package/dist/features/workbench/providers/RemoteFileExplorerProvider.js +0 -160
  96. /package/dist/{node_modules → frontend/studio/node_modules}/@dagrejs/dagre/dist/dagre.esm.js +0 -0
@@ -1,37 +1,7 @@
1
1
  import { ShikiError } from "../../types/dist/index.js";
2
- import { EncodedTokenMetadata, FontStyle, INITIAL, Registry, Theme } from "../../vscode-textmate/dist/index.js";
2
+ import { FontStyle } from "../../vscode-textmate/dist/index.js";
3
+ import { applyColorReplacements, codeToTokensBase, codeToTokensWithThemes, createShikiPrimitive, createShikiPrimitiveAsync, getLastGrammarState, getLastGrammarStateFromMap, isNoneTheme, isPlainLang, isSpecialLang, isSpecialTheme, normalizeGetter, normalizeTheme, resolveColorReplacements, setLastGrammarStateToMap, splitLines, toArray, tokenizeWithTheme } from "../../primitive/dist/index.js";
3
4
  import { toHtml } from "../../../hast-util-to-html/lib/index.js";
4
- function resolveColorReplacements(a, P) {
5
- let F = typeof a == "string" ? {} : { ...a.colorReplacements }, I = typeof a == "string" ? a : a.name;
6
- for (let [a, L] of Object.entries(P?.colorReplacements || {})) typeof L == "string" ? F[a] = L : a === I && Object.assign(F, L);
7
- return F;
8
- }
9
- function applyColorReplacements(a, P) {
10
- return a && (P?.[a?.toLowerCase()] || a);
11
- }
12
- function toArray(a) {
13
- return Array.isArray(a) ? a : [a];
14
- }
15
- async function normalizeGetter(a) {
16
- return Promise.resolve(typeof a == "function" ? a() : a).then((a) => a.default || a);
17
- }
18
- function isPlainLang(a) {
19
- return !a || [
20
- "plaintext",
21
- "txt",
22
- "text",
23
- "plain"
24
- ].includes(a);
25
- }
26
- function isSpecialLang(a) {
27
- return a === "ansi" || isPlainLang(a);
28
- }
29
- function isNoneTheme(a) {
30
- return a === "none";
31
- }
32
- function isSpecialTheme(a) {
33
- return isNoneTheme(a);
34
- }
35
5
  function addClassToHast(a, P) {
36
6
  if (!P) return a;
37
7
  a.properties ||= {}, a.properties.class ||= [], typeof a.properties.class == "string" && (a.properties.class = a.properties.class.split(/\s+/g)), Array.isArray(a.properties.class) || (a.properties.class = []);
@@ -39,15 +9,6 @@ function addClassToHast(a, P) {
39
9
  for (let P of F) P && !a.properties.class.includes(P) && a.properties.class.push(P);
40
10
  return a;
41
11
  }
42
- function splitLines(a, P = !1) {
43
- if (a.length === 0) return [["", 0]];
44
- let F = a.split(/(\r?\n)/g), I = 0, L = [];
45
- for (let a = 0; a < F.length; a += 2) {
46
- let R = P ? F[a] + (F[a + 1] || "") : F[a];
47
- L.push([R, I]), I += F[a].length, I += F[a + 1]?.length || 0;
48
- }
49
- return L;
50
- }
51
12
  function createPositionConverter(a) {
52
13
  let P = splitLines(a, !0).map(([a]) => a);
53
14
  function F(F) {
@@ -141,107 +102,49 @@ function flatTokenVariants(P, F, I, L, R = "css-vars") {
141
102
  }), z.htmlStyle = H, z;
142
103
  }
143
104
  function getTokenStyleObject(a) {
144
- let P = {};
145
- if (a.color && (P.color = a.color), a.bgColor && (P["background-color"] = a.bgColor), a.fontStyle) {
146
- a.fontStyle & FontStyle.Italic && (P["font-style"] = "italic"), a.fontStyle & FontStyle.Bold && (P["font-weight"] = "bold");
105
+ let F = {};
106
+ if (a.color && (F.color = a.color), a.bgColor && (F["background-color"] = a.bgColor), a.fontStyle) {
107
+ a.fontStyle & FontStyle.Italic && (F["font-style"] = "italic"), a.fontStyle & FontStyle.Bold && (F["font-weight"] = "bold");
147
108
  let I = [];
148
- a.fontStyle & FontStyle.Underline && I.push("underline"), a.fontStyle & FontStyle.Strikethrough && I.push("line-through"), I.length && (P["text-decoration"] = I.join(" "));
109
+ a.fontStyle & FontStyle.Underline && I.push("underline"), a.fontStyle & FontStyle.Strikethrough && I.push("line-through"), I.length && (F["text-decoration"] = I.join(" "));
149
110
  }
150
- return P;
111
+ return F;
151
112
  }
152
113
  function stringifyTokenStyle(a) {
153
114
  return typeof a == "string" ? a : Object.entries(a).map(([a, P]) => `${a}:${P}`).join(";");
154
115
  }
155
- var _grammarStateMap = /* @__PURE__ */ new WeakMap();
156
- function setLastGrammarStateToMap(a, P) {
157
- _grammarStateMap.set(a, P);
158
- }
159
- function getLastGrammarStateFromMap(a) {
160
- return _grammarStateMap.get(a);
161
- }
162
- var GrammarState = class a {
163
- _stacks = {};
164
- lang;
165
- get themes() {
166
- return Object.keys(this._stacks);
167
- }
168
- get theme() {
169
- return this.themes[0];
170
- }
171
- get _stack() {
172
- return this._stacks[this.theme];
173
- }
174
- static initial(P, F) {
175
- return new a(Object.fromEntries(toArray(F).map((a) => [a, INITIAL])), P);
176
- }
177
- constructor(...a) {
178
- if (a.length === 2) {
179
- let [P, F] = a;
180
- this.lang = F, this._stacks = P;
181
- } else {
182
- let [P, F, I] = a;
183
- this.lang = F, this._stacks = { [I]: P };
184
- }
185
- }
186
- getInternalStack(a = this.theme) {
187
- return this._stacks[a];
188
- }
189
- getScopes(a = this.theme) {
190
- return getScopes(this._stacks[a]);
191
- }
192
- toJSON() {
193
- return {
194
- lang: this.lang,
195
- theme: this.theme,
196
- themes: this.themes,
197
- scopes: this.getScopes()
198
- };
199
- }
200
- };
201
- function getScopes(a) {
202
- let P = [], F = /* @__PURE__ */ new Set();
203
- function I(a) {
204
- if (F.has(a)) return;
205
- F.add(a);
206
- let L = a?.nameScopesList?.scopeName;
207
- L && P.push(L), a.parent && I(a.parent);
208
- }
209
- return I(a), P;
210
- }
211
- function getGrammarStack(P, F) {
212
- if (!(P instanceof GrammarState)) throw new ShikiError("Invalid grammar state");
213
- return P.getInternalStack(F);
214
- }
215
116
  function transformerDecorations() {
216
117
  let P = /* @__PURE__ */ new WeakMap();
217
118
  function F(F) {
218
119
  if (!P.has(F.meta)) {
219
- let I = function(P) {
120
+ let I = createPositionConverter(F.source);
121
+ function L(P) {
220
122
  if (typeof P == "number") {
221
123
  if (P < 0 || P > F.source.length) throw new ShikiError(`Invalid decoration offset: ${P}. Code length: ${F.source.length}`);
222
124
  return {
223
- ...L.indexToPos(P),
125
+ ...I.indexToPos(P),
224
126
  offset: P
225
127
  };
226
128
  } else {
227
- let F = L.lines[P.line];
228
- if (F === void 0) throw new ShikiError(`Invalid decoration position ${JSON.stringify(P)}. Lines length: ${L.lines.length}`);
229
- let I = P.character;
230
- if (I < 0 && (I = F.length + I), I < 0 || I > F.length) throw new ShikiError(`Invalid decoration position ${JSON.stringify(P)}. Line ${P.line} length: ${F.length}`);
129
+ let F = I.lines[P.line];
130
+ if (F === void 0) throw new ShikiError(`Invalid decoration position ${JSON.stringify(P)}. Lines length: ${I.lines.length}`);
131
+ let L = P.character;
132
+ if (L < 0 && (L = F.length + L), L < 0 || L > F.length) throw new ShikiError(`Invalid decoration position ${JSON.stringify(P)}. Line ${P.line} length: ${F.length}`);
231
133
  return {
232
134
  ...P,
233
- character: I,
234
- offset: L.posToIndex(P.line, I)
135
+ character: L,
136
+ offset: I.posToIndex(P.line, L)
235
137
  };
236
138
  }
237
- }, L = createPositionConverter(F.source), R = (F.options.decorations || []).map((a) => ({
139
+ }
140
+ let R = (F.options.decorations || []).map((a) => ({
238
141
  ...a,
239
- start: I(a.start),
240
- end: I(a.end)
142
+ start: L(a.start),
143
+ end: L(a.end)
241
144
  }));
242
145
  verifyIntersections(R), P.set(F.meta, {
243
146
  decorations: R,
244
- converter: L,
147
+ converter: I,
245
148
  source: F.source
246
149
  });
247
150
  }
@@ -567,20 +470,20 @@ var defaultAnsiColors = {
567
470
  brightCyan: "#29B8DB",
568
471
  brightWhite: "#FFFFFF"
569
472
  };
570
- function tokenizeAnsiWithTheme(a, P, I) {
571
- let L = resolveColorReplacements(a, I), R = splitLines(P), z = createColorPalette(Object.fromEntries(namedColors.map((P) => {
473
+ function tokenizeAnsiWithTheme(a, I, L) {
474
+ let R = resolveColorReplacements(a, L), z = splitLines(I), B = createColorPalette(Object.fromEntries(namedColors.map((P) => {
572
475
  let F = `terminal.ansi${P[0].toUpperCase()}${P.substring(1)}`;
573
476
  return [P, a.colors?.[F] || defaultAnsiColors[P]];
574
- }))), H = createAnsiSequenceParser();
575
- return R.map((P) => H.parse(P[0]).map((I) => {
576
- let R, B;
577
- I.decorations.has("reverse") ? (R = I.background ? z.value(I.background) : a.bg, B = I.foreground ? z.value(I.foreground) : a.fg) : (R = I.foreground ? z.value(I.foreground) : a.fg, B = I.background ? z.value(I.background) : void 0), R = applyColorReplacements(R, L), B = applyColorReplacements(B, L), I.decorations.has("dim") && (R = dimColor(R));
477
+ }))), V = createAnsiSequenceParser();
478
+ return z.map((I) => V.parse(I[0]).map((L) => {
479
+ let z, V;
480
+ L.decorations.has("reverse") ? (z = L.background ? B.value(L.background) : a.bg, V = L.foreground ? B.value(L.foreground) : a.fg) : (z = L.foreground ? B.value(L.foreground) : a.fg, V = L.background ? B.value(L.background) : void 0), z = applyColorReplacements(z, R), V = applyColorReplacements(V, R), L.decorations.has("dim") && (z = dimColor(z));
578
481
  let H = FontStyle.None;
579
- return I.decorations.has("bold") && (H |= FontStyle.Bold), I.decorations.has("italic") && (H |= FontStyle.Italic), I.decorations.has("underline") && (H |= FontStyle.Underline), I.decorations.has("strikethrough") && (H |= FontStyle.Strikethrough), {
580
- content: I.value,
581
- offset: P[1],
582
- color: R,
583
- bgColor: B,
482
+ return L.decorations.has("bold") && (H |= FontStyle.Bold), L.decorations.has("italic") && (H |= FontStyle.Italic), L.decorations.has("underline") && (H |= FontStyle.Underline), L.decorations.has("strikethrough") && (H |= FontStyle.Strikethrough), {
483
+ content: L.value,
484
+ offset: I[1],
485
+ color: z,
486
+ bgColor: V,
584
487
  fontStyle: H
585
488
  };
586
489
  }));
@@ -604,225 +507,55 @@ function dimColor(a) {
604
507
  let F = a.match(/var\((--[\w-]+-ansi-[\w-]+)\)/);
605
508
  return F ? `var(${F[1]}-dim)` : a;
606
509
  }
607
- function codeToTokensBase(P, F, I = {}) {
608
- let { theme: L = P.getLoadedThemes()[0] } = I, R = P.resolveLangAlias(I.lang || "text");
609
- if (isPlainLang(R) || isNoneTheme(L)) return splitLines(F).map((a) => [{
610
- content: a[0],
611
- offset: a[1]
612
- }]);
613
- let { theme: z, colorMap: B } = P.setTheme(L);
614
- if (R === "ansi") return tokenizeAnsiWithTheme(z, F, I);
615
- let V = P.getLanguage(I.lang || "text");
616
- if (I.grammarState) {
617
- if (I.grammarState.lang !== V.name) throw new ShikiError(`Grammar state language "${I.grammarState.lang}" does not match highlight language "${V.name}"`);
618
- if (!I.grammarState.themes.includes(z.name)) throw new ShikiError(`Grammar state themes "${I.grammarState.themes}" do not contain highlight theme "${z.name}"`);
619
- }
620
- return tokenizeWithTheme(F, V, z, B, I);
621
- }
622
- function getLastGrammarState(...P) {
623
- if (P.length === 2) return getLastGrammarStateFromMap(P[1]);
624
- let [F, I, L = {}] = P, { lang: R = "text", theme: z = F.getLoadedThemes()[0] } = L;
625
- if (isPlainLang(R) || isNoneTheme(z)) throw new ShikiError("Plain language does not have grammar state");
626
- if (R === "ansi") throw new ShikiError("ANSI language does not have grammar state");
627
- let { theme: B, colorMap: V } = F.setTheme(z), H = F.getLanguage(R);
628
- return new GrammarState(_tokenizeWithTheme(I, H, B, V, L).stateStack, H.name, B.name);
629
- }
630
- function tokenizeWithTheme(a, P, F, I, L) {
631
- let R = _tokenizeWithTheme(a, P, F, I, L), z = new GrammarState(R.stateStack, P.name, F.name);
632
- return setLastGrammarStateToMap(R.tokens, z), R.tokens;
633
- }
634
- function _tokenizeWithTheme(a, F, L, R, z) {
635
- let H = resolveColorReplacements(L, z), { tokenizeMaxLineLength: U = 0, tokenizeTimeLimit: W = 500 } = z, G = splitLines(a), K = z.grammarState ? getGrammarStack(z.grammarState, L.name) ?? INITIAL : z.grammarContextCode == null ? INITIAL : _tokenizeWithTheme(z.grammarContextCode, F, L, R, {
636
- ...z,
637
- grammarState: void 0,
638
- grammarContextCode: void 0
639
- }).stateStack, q = [], J = [];
640
- for (let a = 0, I = G.length; a < I; a++) {
641
- let [I, B] = G[a];
642
- if (I === "") {
643
- q = [], J.push([]);
644
- continue;
645
- }
646
- if (U > 0 && I.length >= U) {
647
- q = [], J.push([{
648
- content: I,
649
- offset: B,
650
- color: "",
651
- fontStyle: 0
652
- }]);
653
- continue;
654
- }
655
- let Y, X, Z;
656
- z.includeExplanation && (Y = F.tokenizeLine(I, K, W), X = Y.tokens, Z = 0);
657
- let Q = F.tokenizeLine2(I, K, W), $ = Q.tokens.length / 2;
658
- for (let a = 0; a < $; a++) {
659
- let F = Q.tokens[2 * a], U = a + 1 < $ ? Q.tokens[2 * a + 2] : I.length;
660
- if (F === U) continue;
661
- let W = Q.tokens[2 * a + 1], G = applyColorReplacements(R[EncodedTokenMetadata.getForeground(W)], H), K = EncodedTokenMetadata.getFontStyle(W), J = {
662
- content: I.substring(F, U),
663
- offset: B + F,
664
- color: G,
665
- fontStyle: K
666
- };
667
- if (z.includeExplanation) {
668
- let a = [];
669
- if (z.includeExplanation !== "scopeName") for (let P of L.settings) {
670
- let F;
671
- switch (typeof P.scope) {
672
- case "string":
673
- F = P.scope.split(/,/).map((a) => a.trim());
674
- break;
675
- case "object":
676
- F = P.scope;
677
- break;
678
- default: continue;
679
- }
680
- a.push({
681
- settings: P,
682
- selectors: F.map((a) => a.split(/ /))
683
- });
684
- }
685
- J.explanation = [];
686
- let P = 0;
687
- for (; F + P < U;) {
688
- let F = X[Z], L = I.substring(F.startIndex, F.endIndex);
689
- P += L.length, J.explanation.push({
690
- content: L,
691
- scopes: z.includeExplanation === "scopeName" ? explainThemeScopesNameOnly(F.scopes) : explainThemeScopesFull(a, F.scopes)
692
- }), Z += 1;
693
- }
694
- }
695
- q.push(J);
696
- }
697
- J.push(q), q = [], K = Q.ruleStack;
698
- }
699
- return {
700
- tokens: J,
701
- stateStack: K
702
- };
703
- }
704
- function explainThemeScopesNameOnly(a) {
705
- return a.map((a) => ({ scopeName: a }));
706
- }
707
- function explainThemeScopesFull(a, P) {
708
- let F = [];
709
- for (let I = 0, L = P.length; I < L; I++) {
710
- let L = P[I];
711
- F[I] = {
712
- scopeName: L,
713
- themeMatches: explainThemeScope(a, L, P.slice(0, I))
714
- };
715
- }
716
- return F;
717
- }
718
- function matchesOne(a, P) {
719
- return a === P || P.substring(0, a.length) === a && P[a.length] === ".";
720
- }
721
- function matches(a, P, F) {
722
- if (!matchesOne(a[a.length - 1], P)) return !1;
723
- let I = a.length - 2, L = F.length - 1;
724
- for (; I >= 0 && L >= 0;) matchesOne(a[I], F[L]) && --I, --L;
725
- return I === -1;
726
- }
727
- function explainThemeScope(a, P, F) {
728
- let I = [];
729
- for (let { selectors: L, settings: R } of a) for (let a of L) if (matches(a, P, F)) {
730
- I.push(R);
731
- break;
510
+ function codeToTokensBase$1(a, P, F = {}) {
511
+ let L = a.resolveLangAlias(F.lang || "text"), { theme: R = a.getLoadedThemes()[0] } = F;
512
+ if (!isPlainLang(L) && !isNoneTheme(R) && L === "ansi") {
513
+ let { theme: I } = a.setTheme(R);
514
+ return tokenizeAnsiWithTheme(I, P, F);
732
515
  }
733
- return I;
516
+ return codeToTokensBase(a, P, F);
734
517
  }
735
- function codeToTokensWithThemes(a, P, F) {
736
- let I = Object.entries(F.themes).filter((a) => a[1]).map((a) => ({
737
- color: a[0],
738
- theme: a[1]
739
- })), L = I.map((I) => {
740
- let L = codeToTokensBase(a, P, {
741
- ...F,
742
- theme: I.theme
743
- });
744
- return {
745
- tokens: L,
746
- state: getLastGrammarStateFromMap(L),
747
- theme: typeof I.theme == "string" ? I.theme : I.theme.name
748
- };
749
- }), R = syncThemesTokenization(...L.map((a) => a.tokens)), z = R[0].map((a, P) => a.map((a, L) => {
750
- let z = {
751
- content: a.content,
752
- variants: {},
753
- offset: a.offset
754
- };
755
- return "includeExplanation" in F && F.includeExplanation && (z.explanation = a.explanation), R.forEach((a, F) => {
756
- let { content: R, explanation: B, offset: V, ...H } = a[P][L];
757
- z.variants[I[F].color] = H;
758
- }), z;
759
- })), B = L[0].state ? new GrammarState(Object.fromEntries(L.map((a) => [a.theme, a.state?.getInternalStack(a.theme)])), L[0].state.lang) : void 0;
760
- return B && setLastGrammarStateToMap(z, B), z;
761
- }
762
- function syncThemesTokenization(...a) {
763
- let P = a.map(() => []), F = a.length;
764
- for (let I = 0; I < a[0].length; I++) {
765
- let L = a.map((a) => a[I]), R = P.map(() => []);
766
- P.forEach((a, P) => a.push(R[P]));
767
- let z = L.map(() => 0), B = L.map((a) => a[0]);
768
- for (; B.every((a) => a);) {
769
- let a = Math.min(...B.map((a) => a.content.length));
770
- for (let P = 0; P < F; P++) {
771
- let F = B[P];
772
- F.content.length === a ? (R[P].push(F), z[P] += 1, B[P] = L[P][z[P]]) : (R[P].push({
773
- ...F,
774
- content: F.content.slice(0, a)
775
- }), B[P] = {
776
- ...F,
777
- content: F.content.slice(a),
778
- offset: F.offset + a
779
- });
780
- }
781
- }
782
- }
783
- return P;
784
- }
785
- function codeToTokens(P, F, I) {
786
- let L, R, z, H, U, W;
787
- if ("themes" in I) {
788
- let { defaultColor: V = "light", cssVariablePrefix: G = "--shiki-", colorsRendering: K = "css-vars" } = I, q = Object.entries(I.themes).filter((a) => a[1]).map((a) => ({
518
+ function codeToTokens(P, I, R) {
519
+ let z, B, H, U, W, G;
520
+ if ("themes" in R) {
521
+ let { defaultColor: F = "light", cssVariablePrefix: K = "--shiki-", colorsRendering: q = "css-vars" } = R, Y = Object.entries(R.themes).filter((a) => a[1]).map((a) => ({
789
522
  color: a[0],
790
523
  theme: a[1]
791
- })).sort((a, P) => a.color === V ? -1 : P.color === V ? 1 : 0);
792
- if (q.length === 0) throw new ShikiError("`themes` option must not be empty");
793
- let J = codeToTokensWithThemes(P, F, I);
794
- if (W = getLastGrammarStateFromMap(J), V && DEFAULT_COLOR_LIGHT_DARK !== V && !q.find((a) => a.color === V)) throw new ShikiError(`\`themes\` option must contain the defaultColor key \`${V}\``);
795
- let Y = q.map((a) => P.getTheme(a.theme)), X = q.map((a) => a.color);
796
- z = J.map((a) => a.map((a) => flatTokenVariants(a, X, G, V, K))), W && setLastGrammarStateToMap(z, W);
797
- let Z = q.map((a) => resolveColorReplacements(a.theme, I));
798
- R = mapThemeColors(q, Y, Z, G, V, "fg", K), L = mapThemeColors(q, Y, Z, G, V, "bg", K), H = `shiki-themes ${Y.map((a) => a.name).join(" ")}`, U = V ? void 0 : [R, L].join(";");
799
- } else if ("theme" in I) {
800
- let a = resolveColorReplacements(I.theme, I);
801
- z = codeToTokensBase(P, F, I);
802
- let U = P.getTheme(I.theme);
803
- L = applyColorReplacements(U.bg, a), R = applyColorReplacements(U.fg, a), H = U.name, W = getLastGrammarStateFromMap(z);
524
+ })).sort((a, P) => a.color === F ? -1 : P.color === F ? 1 : 0);
525
+ if (Y.length === 0) throw new ShikiError("`themes` option must not be empty");
526
+ let X = codeToTokensWithThemes(P, I, R, codeToTokensBase$1);
527
+ if (G = getLastGrammarStateFromMap(X), F && DEFAULT_COLOR_LIGHT_DARK !== F && !Y.find((a) => a.color === F)) throw new ShikiError(`\`themes\` option must contain the defaultColor key \`${F}\``);
528
+ let Z = Y.map((a) => P.getTheme(a.theme)), Q = Y.map((a) => a.color);
529
+ H = X.map((a) => a.map((a) => flatTokenVariants(a, Q, K, F, q))), G && setLastGrammarStateToMap(H, G);
530
+ let $ = Y.map((a) => resolveColorReplacements(a.theme, R));
531
+ B = mapThemeColors(Y, Z, $, K, F, "fg", q), z = mapThemeColors(Y, Z, $, K, F, "bg", q), U = `shiki-themes ${Z.map((a) => a.name).join(" ")}`, W = F ? void 0 : [B, z].join(";");
532
+ } else if ("theme" in R) {
533
+ let a = resolveColorReplacements(R.theme, R);
534
+ H = codeToTokensBase$1(P, I, R);
535
+ let L = P.getTheme(R.theme);
536
+ z = applyColorReplacements(L.bg, a), B = applyColorReplacements(L.fg, a), U = L.name, G = getLastGrammarStateFromMap(H);
804
537
  } else throw new ShikiError("Invalid options, either `theme` or `themes` must be provided");
805
538
  return {
806
- tokens: z,
807
- fg: R,
808
- bg: L,
809
- themeName: H,
810
- rootStyle: U,
811
- grammarState: W
539
+ tokens: H,
540
+ fg: B,
541
+ bg: z,
542
+ themeName: U,
543
+ rootStyle: W,
544
+ grammarState: G
812
545
  };
813
546
  }
814
- function mapThemeColors(P, F, I, L, R, z, B) {
547
+ function mapThemeColors(P, I, L, R, z, B, V) {
815
548
  return P.map((H, U) => {
816
- let W = applyColorReplacements(F[U][z], I[U]) || "inherit", G = `${L + H.color}${z === "bg" ? "-bg" : ""}:${W}`;
817
- if (U === 0 && R) {
818
- if (R === DEFAULT_COLOR_LIGHT_DARK && P.length > 1) {
819
- let L = P.findIndex((a) => a.color === "light"), R = P.findIndex((a) => a.color === "dark");
820
- if (L === -1 || R === -1) throw new ShikiError("When using `defaultColor: \"light-dark()\"`, you must provide both `light` and `dark` themes");
821
- return `light-dark(${applyColorReplacements(F[L][z], I[L]) || "inherit"}, ${applyColorReplacements(F[R][z], I[R]) || "inherit"});${G}`;
549
+ let W = applyColorReplacements(I[U][B], L[U]) || "inherit", G = `${R + H.color}${B === "bg" ? "-bg" : ""}:${W}`;
550
+ if (U === 0 && z) {
551
+ if (z === DEFAULT_COLOR_LIGHT_DARK && P.length > 1) {
552
+ let R = P.findIndex((a) => a.color === "light"), z = P.findIndex((a) => a.color === "dark");
553
+ if (R === -1 || z === -1) throw new ShikiError("When using `defaultColor: \"light-dark()\"`, you must provide both `light` and `dark` themes");
554
+ return `light-dark(${applyColorReplacements(I[R][B], L[R]) || "inherit"}, ${applyColorReplacements(I[z][B], L[z]) || "inherit"});${G}`;
822
555
  }
823
556
  return W;
824
557
  }
825
- return B === "css-vars" ? G : null;
558
+ return V === "css-vars" ? G : null;
826
559
  }).filter((a) => !!a).join(";");
827
560
  }
828
561
  function codeToHast(a, P, F, I = {
@@ -854,21 +587,21 @@ function tokensToHast(a, P, F, I = getLastGrammarStateFromMap(a)) {
854
587
  let L = getTransformers(P), R = [], z = {
855
588
  type: "root",
856
589
  children: []
857
- }, { structure: B = "classic", tabindex: V = "0" } = P, H = { class: `shiki ${P.themeName || ""}` };
858
- P.rootStyle !== !1 && (P.rootStyle == null ? H.style = `background-color:${P.bg};color:${P.fg}` : H.style = P.rootStyle), V !== !1 && V != null && (H.tabindex = V.toString());
859
- for (let [a, F] of Object.entries(P.meta || {})) a.startsWith("_") || (H[a] = F);
860
- let U = {
590
+ }, { structure: B = "classic", tabindex: H = "0" } = P, U = { class: `shiki ${P.themeName || ""}` };
591
+ P.rootStyle !== !1 && (P.rootStyle == null ? U.style = `background-color:${P.bg};color:${P.fg}` : U.style = P.rootStyle), H !== !1 && H != null && (U.tabindex = H.toString());
592
+ for (let [a, F] of Object.entries(P.meta || {})) a.startsWith("_") || (U[a] = F);
593
+ let W = {
861
594
  type: "element",
862
595
  tagName: "pre",
863
- properties: H,
596
+ properties: U,
864
597
  children: [],
865
598
  data: P.data
866
- }, W = {
599
+ }, G = {
867
600
  type: "element",
868
601
  tagName: "code",
869
602
  properties: {},
870
603
  children: R
871
- }, G = [], K = {
604
+ }, K = [], q = {
872
605
  ...F,
873
606
  structure: B,
874
607
  addClassToHast,
@@ -885,13 +618,13 @@ function tokensToHast(a, P, F, I = getLastGrammarStateFromMap(a)) {
885
618
  return z;
886
619
  },
887
620
  get pre() {
888
- return U;
621
+ return W;
889
622
  },
890
623
  get code() {
891
- return W;
624
+ return G;
892
625
  },
893
626
  get lines() {
894
- return G;
627
+ return K;
895
628
  }
896
629
  };
897
630
  if (a.forEach((a, P) => {
@@ -921,18 +654,18 @@ function tokensToHast(a, P, F, I = getLastGrammarStateFromMap(a)) {
921
654
  }]
922
655
  }, V = stringifyTokenStyle(R.htmlStyle || getTokenStyleObject(R));
923
656
  V && (a.properties.style = V);
924
- for (let z of L) a = z?.span?.call(K, a, P + 1, I, F, R) || a;
657
+ for (let z of L) a = z?.span?.call(q, a, P + 1, I, F, R) || a;
925
658
  B === "inline" ? z.children.push(a) : B === "classic" && F.children.push(a), I += R.content.length;
926
659
  }
927
660
  if (B === "classic") {
928
- for (let a of L) F = a?.line?.call(K, F, P + 1) || F;
929
- G.push(F), R.push(F);
930
- } else B === "inline" && G.push(F);
661
+ for (let a of L) F = a?.line?.call(q, F, P + 1) || F;
662
+ K.push(F), R.push(F);
663
+ } else B === "inline" && K.push(F);
931
664
  }), B === "classic") {
932
- for (let a of L) W = a?.code?.call(K, W) || W;
933
- U.children.push(W);
934
- for (let a of L) U = a?.pre?.call(K, U) || U;
935
- z.children.push(U);
665
+ for (let a of L) G = a?.code?.call(q, G) || G;
666
+ W.children.push(G);
667
+ for (let a of L) W = a?.pre?.call(q, W) || W;
668
+ z.children.push(W);
936
669
  } else if (B === "inline") {
937
670
  let a = [], P = {
938
671
  type: "element",
@@ -953,7 +686,7 @@ function tokensToHast(a, P, F, I = getLastGrammarStateFromMap(a)) {
953
686
  properties: {},
954
687
  children: a
955
688
  };
956
- for (let a of L) F = a?.code?.call(K, F) || F;
689
+ for (let a of L) F = a?.code?.call(q, F) || F;
957
690
  z.children = [];
958
691
  for (let a = 0; a < F.children.length; a++) {
959
692
  a > 0 && z.children.push({
@@ -966,24 +699,24 @@ function tokensToHast(a, P, F, I = getLastGrammarStateFromMap(a)) {
966
699
  P.type === "element" && z.children.push(...P.children);
967
700
  }
968
701
  }
969
- let q = z;
970
- for (let a of L) q = a?.root?.call(K, q) || q;
971
- return I && setLastGrammarStateToMap(q, I), q;
702
+ let J = z;
703
+ for (let a of L) J = a?.root?.call(q, J) || J;
704
+ return I && setLastGrammarStateToMap(J, I), J;
972
705
  }
973
706
  function mergeWhitespaceTokens(a) {
974
707
  return a.map((a) => {
975
- let P = [], I = "", L;
708
+ let F = [], I = "", L;
976
709
  return a.forEach((R, z) => {
977
710
  let B = !(R.fontStyle && (R.fontStyle & FontStyle.Underline || R.fontStyle & FontStyle.Strikethrough));
978
- B && R.content.match(/^\s+$/) && a[z + 1] ? (L === void 0 && (L = R.offset), I += R.content) : I ? (B ? P.push({
711
+ B && R.content.match(/^\s+$/) && a[z + 1] ? (L === void 0 && (L = R.offset), I += R.content) : I ? (B ? F.push({
979
712
  ...R,
980
713
  offset: L,
981
714
  content: I + R.content
982
- }) : P.push({
715
+ }) : F.push({
983
716
  content: I,
984
717
  offset: L
985
- }, R), L = void 0, I = "") : P.push(R);
986
- }), P;
718
+ }, R), L = void 0, I = "") : F.push(R);
719
+ }), F;
987
720
  });
988
721
  }
989
722
  function splitWhitespaceTokens(a) {
@@ -1009,16 +742,16 @@ function splitWhitespaceTokens(a) {
1009
742
  }
1010
743
  function mergeAdjacentStyledTokens(a) {
1011
744
  return a.map((a) => {
1012
- let P = [];
745
+ let F = [];
1013
746
  for (let I of a) {
1014
- if (P.length === 0) {
1015
- P.push({ ...I });
747
+ if (F.length === 0) {
748
+ F.push({ ...I });
1016
749
  continue;
1017
750
  }
1018
- let a = P[P.length - 1], L = stringifyTokenStyle(a.htmlStyle || getTokenStyleObject(a)), R = stringifyTokenStyle(I.htmlStyle || getTokenStyleObject(I)), z = a.fontStyle && (a.fontStyle & FontStyle.Underline || a.fontStyle & FontStyle.Strikethrough), B = I.fontStyle && (I.fontStyle & FontStyle.Underline || I.fontStyle & FontStyle.Strikethrough);
1019
- !z && !B && L === R ? a.content += I.content : P.push({ ...I });
751
+ let a = F[F.length - 1], L = stringifyTokenStyle(a.htmlStyle || getTokenStyleObject(a)), R = stringifyTokenStyle(I.htmlStyle || getTokenStyleObject(I)), z = a.fontStyle && (a.fontStyle & FontStyle.Underline || a.fontStyle & FontStyle.Strikethrough), B = I.fontStyle && (I.fontStyle & FontStyle.Underline || I.fontStyle & FontStyle.Strikethrough);
752
+ !z && !B && L === R ? a.content += I.content : F.push({ ...I });
1020
753
  }
1021
- return P;
754
+ return F;
1022
755
  });
1023
756
  }
1024
757
  var hastToHtml = toHtml;
@@ -1032,282 +765,11 @@ function codeToHtml(a, P, F) {
1032
765
  for (let a of getTransformers(F)) L = a.postprocess?.call(I, L, F) || L;
1033
766
  return L;
1034
767
  }
1035
- var VSCODE_FALLBACK_EDITOR_FG = {
1036
- light: "#333333",
1037
- dark: "#bbbbbb"
1038
- }, VSCODE_FALLBACK_EDITOR_BG = {
1039
- light: "#fffffe",
1040
- dark: "#1e1e1e"
1041
- }, RESOLVED_KEY = "__shiki_resolved";
1042
- function normalizeTheme(a) {
1043
- if (a?.[RESOLVED_KEY]) return a;
1044
- let P = { ...a };
1045
- P.tokenColors && !P.settings && (P.settings = P.tokenColors, delete P.tokenColors), P.type ||= "dark", P.colorReplacements = { ...P.colorReplacements }, P.settings ||= [];
1046
- let { bg: F, fg: I } = P;
1047
- if (!F || !I) {
1048
- let a = P.settings ? P.settings.find((a) => !a.name && !a.scope) : void 0;
1049
- a?.settings?.foreground && (I = a.settings.foreground), a?.settings?.background && (F = a.settings.background), !I && P?.colors?.["editor.foreground"] && (I = P.colors["editor.foreground"]), !F && P?.colors?.["editor.background"] && (F = P.colors["editor.background"]), I ||= P.type === "light" ? VSCODE_FALLBACK_EDITOR_FG.light : VSCODE_FALLBACK_EDITOR_FG.dark, F ||= P.type === "light" ? VSCODE_FALLBACK_EDITOR_BG.light : VSCODE_FALLBACK_EDITOR_BG.dark, P.fg = I, P.bg = F;
1050
- }
1051
- P.settings[0] && P.settings[0].settings && !P.settings[0].scope || P.settings.unshift({ settings: {
1052
- foreground: P.fg,
1053
- background: P.bg
1054
- } });
1055
- let L = 0, R = /* @__PURE__ */ new Map();
1056
- function z(a) {
1057
- if (R.has(a)) return R.get(a);
1058
- L += 1;
1059
- let F = `#${L.toString(16).padStart(8, "0").toLowerCase()}`;
1060
- return P.colorReplacements?.[`#${F}`] ? z(a) : (R.set(a, F), F);
1061
- }
1062
- P.settings = P.settings.map((a) => {
1063
- let F = a.settings?.foreground && !a.settings.foreground.startsWith("#"), I = a.settings?.background && !a.settings.background.startsWith("#");
1064
- if (!F && !I) return a;
1065
- let L = {
1066
- ...a,
1067
- settings: { ...a.settings }
1068
- };
1069
- if (F) {
1070
- let F = z(a.settings.foreground);
1071
- P.colorReplacements[F] = a.settings.foreground, L.settings.foreground = F;
1072
- }
1073
- if (I) {
1074
- let F = z(a.settings.background);
1075
- P.colorReplacements[F] = a.settings.background, L.settings.background = F;
1076
- }
1077
- return L;
1078
- });
1079
- for (let a of Object.keys(P.colors || {})) if ((a === "editor.foreground" || a === "editor.background" || a.startsWith("terminal.ansi")) && !P.colors[a]?.startsWith("#")) {
1080
- let F = z(P.colors[a]);
1081
- P.colorReplacements[F] = P.colors[a], P.colors[a] = F;
1082
- }
1083
- return Object.defineProperty(P, RESOLVED_KEY, {
1084
- enumerable: !1,
1085
- writable: !1,
1086
- value: !0
1087
- }), P;
1088
- }
1089
- async function resolveLangs(a) {
1090
- return Array.from(new Set((await Promise.all(a.filter((a) => !isSpecialLang(a)).map(async (a) => await normalizeGetter(a).then((a) => Array.isArray(a) ? a : [a])))).flat()));
1091
- }
1092
- async function resolveThemes(a) {
1093
- return (await Promise.all(a.map(async (a) => isSpecialTheme(a) ? null : normalizeTheme(await normalizeGetter(a))))).filter((a) => !!a);
1094
- }
1095
- var _emitDeprecation = 3, _emitError = !1;
1096
- function warnDeprecated(a, P = 3) {
1097
- if (_emitDeprecation && !(typeof _emitDeprecation == "number" && P > _emitDeprecation)) {
1098
- if (_emitError) throw Error(`[SHIKI DEPRECATE]: ${a}`);
1099
- console.trace(`[SHIKI DEPRECATE]: ${a}`);
1100
- }
1101
- }
1102
- var ShikiError$1 = class extends Error {
1103
- constructor(a) {
1104
- super(a), this.name = "ShikiError";
1105
- }
1106
- };
1107
- function resolveLangAlias(a, P) {
1108
- if (!P) return a;
1109
- if (P[a]) {
1110
- let F = /* @__PURE__ */ new Set([a]);
1111
- for (; P[a];) {
1112
- if (a = P[a], F.has(a)) throw new ShikiError$1(`Circular alias \`${Array.from(F).join(" -> ")} -> ${a}\``);
1113
- F.add(a);
1114
- }
1115
- }
1116
- return a;
1117
- }
1118
- var Registry$1 = class extends Registry {
1119
- constructor(a, P, F, I = {}) {
1120
- super(a), this._resolver = a, this._themes = P, this._langs = F, this._alias = I, this._themes.map((a) => this.loadTheme(a)), this.loadLanguages(this._langs);
1121
- }
1122
- _resolvedThemes = /* @__PURE__ */ new Map();
1123
- _resolvedGrammars = /* @__PURE__ */ new Map();
1124
- _langMap = /* @__PURE__ */ new Map();
1125
- _langGraph = /* @__PURE__ */ new Map();
1126
- _textmateThemeCache = /* @__PURE__ */ new WeakMap();
1127
- _loadedThemesCache = null;
1128
- _loadedLanguagesCache = null;
1129
- getTheme(a) {
1130
- return typeof a == "string" ? this._resolvedThemes.get(a) : this.loadTheme(a);
1131
- }
1132
- loadTheme(a) {
1133
- let P = normalizeTheme(a);
1134
- return P.name && (this._resolvedThemes.set(P.name, P), this._loadedThemesCache = null), P;
1135
- }
1136
- getLoadedThemes() {
1137
- return this._loadedThemesCache ||= [...this._resolvedThemes.keys()], this._loadedThemesCache;
1138
- }
1139
- setTheme(a) {
1140
- let P = this._textmateThemeCache.get(a);
1141
- P || (P = Theme.createFromRawTheme(a), this._textmateThemeCache.set(a, P)), this._syncRegistry.setTheme(P);
1142
- }
1143
- getGrammar(a) {
1144
- return a = resolveLangAlias(a, this._alias), this._resolvedGrammars.get(a);
1145
- }
1146
- loadLanguage(a) {
1147
- if (this.getGrammar(a.name)) return;
1148
- let P = new Set([...this._langMap.values()].filter((P) => P.embeddedLangsLazy?.includes(a.name)));
1149
- this._resolver.addLanguage(a);
1150
- let F = {
1151
- balancedBracketSelectors: a.balancedBracketSelectors || ["*"],
1152
- unbalancedBracketSelectors: a.unbalancedBracketSelectors || []
1153
- };
1154
- this._syncRegistry._rawGrammars.set(a.scopeName, a);
1155
- let I = this.loadGrammarWithConfiguration(a.scopeName, 1, F);
1156
- if (I.name = a.name, this._resolvedGrammars.set(a.name, I), a.aliases && a.aliases.forEach((P) => {
1157
- this._alias[P] = a.name;
1158
- }), this._loadedLanguagesCache = null, P.size) for (let a of P) this._resolvedGrammars.delete(a.name), this._loadedLanguagesCache = null, this._syncRegistry?._injectionGrammars?.delete(a.scopeName), this._syncRegistry?._grammars?.delete(a.scopeName), this.loadLanguage(this._langMap.get(a.name));
1159
- }
1160
- dispose() {
1161
- super.dispose(), this._resolvedThemes.clear(), this._resolvedGrammars.clear(), this._langMap.clear(), this._langGraph.clear(), this._loadedThemesCache = null;
1162
- }
1163
- loadLanguages(a) {
1164
- for (let P of a) this.resolveEmbeddedLanguages(P);
1165
- let P = Array.from(this._langGraph.entries()), F = P.filter(([a, P]) => !P);
1166
- if (F.length) {
1167
- let a = P.filter(([a, P]) => P ? (P.embeddedLanguages || P.embeddedLangs)?.some((a) => F.map(([a]) => a).includes(a)) : !1).filter((a) => !F.includes(a));
1168
- throw new ShikiError$1(`Missing languages ${F.map(([a]) => `\`${a}\``).join(", ")}, required by ${a.map(([a]) => `\`${a}\``).join(", ")}`);
1169
- }
1170
- for (let [a, F] of P) this._resolver.addLanguage(F);
1171
- for (let [a, F] of P) this.loadLanguage(F);
1172
- }
1173
- getLoadedLanguages() {
1174
- return this._loadedLanguagesCache ||= [.../* @__PURE__ */ new Set([...this._resolvedGrammars.keys(), ...Object.keys(this._alias)])], this._loadedLanguagesCache;
1175
- }
1176
- resolveEmbeddedLanguages(a) {
1177
- this._langMap.set(a.name, a), this._langGraph.set(a.name, a);
1178
- let P = a.embeddedLanguages ?? a.embeddedLangs;
1179
- if (P) for (let a of P) this._langGraph.set(a, this._langMap.get(a));
1180
- }
1181
- }, Resolver = class {
1182
- _langs = /* @__PURE__ */ new Map();
1183
- _scopeToLang = /* @__PURE__ */ new Map();
1184
- _injections = /* @__PURE__ */ new Map();
1185
- _onigLib;
1186
- constructor(a, P) {
1187
- this._onigLib = {
1188
- createOnigScanner: (P) => a.createScanner(P),
1189
- createOnigString: (P) => a.createString(P)
1190
- }, P.forEach((a) => this.addLanguage(a));
1191
- }
1192
- get onigLib() {
1193
- return this._onigLib;
1194
- }
1195
- getLangRegistration(a) {
1196
- return this._langs.get(a);
1197
- }
1198
- loadGrammar(a) {
1199
- return this._scopeToLang.get(a);
1200
- }
1201
- addLanguage(a) {
1202
- this._langs.set(a.name, a), a.aliases && a.aliases.forEach((P) => {
1203
- this._langs.set(P, a);
1204
- }), this._scopeToLang.set(a.scopeName, a), a.injectTo && a.injectTo.forEach((P) => {
1205
- this._injections.get(P) || this._injections.set(P, []), this._injections.get(P).push(a.scopeName);
1206
- });
1207
- }
1208
- getInjections(a) {
1209
- let P = a.split("."), F = [];
1210
- for (let a = 1; a <= P.length; a++) {
1211
- let I = P.slice(0, a).join(".");
1212
- F = [...F, ...this._injections.get(I) || []];
1213
- }
1214
- return F;
1215
- }
1216
- }, instancesCount = 0;
1217
- function createShikiInternalSync(a) {
1218
- instancesCount += 1, a.warnings !== !1 && instancesCount >= 10 && instancesCount % 10 == 0 && console.warn(`[Shiki] ${instancesCount} instances have been created. Shiki is supposed to be used as a singleton, consider refactoring your code to cache your highlighter instance; Or call \`highlighter.dispose()\` to release unused instances.`);
1219
- let P = !1;
1220
- if (!a.engine) throw new ShikiError$1("`engine` option is required for synchronous mode");
1221
- let F = (a.langs || []).flat(1), I = (a.themes || []).flat(1).map(normalizeTheme), L = new Registry$1(new Resolver(a.engine, F), I, F, a.langAlias), R;
1222
- function z(P) {
1223
- return resolveLangAlias(P, a.langAlias);
1224
- }
1225
- function B(a) {
1226
- Y();
1227
- let P = L.getGrammar(typeof a == "string" ? a : a.name);
1228
- if (!P) throw new ShikiError$1(`Language \`${a}\` not found, you may need to load it first`);
1229
- return P;
1230
- }
1231
- function V(a) {
1232
- if (a === "none") return {
1233
- bg: "",
1234
- fg: "",
1235
- name: "none",
1236
- settings: [],
1237
- type: "dark"
1238
- };
1239
- Y();
1240
- let P = L.getTheme(a);
1241
- if (!P) throw new ShikiError$1(`Theme \`${a}\` not found, you may need to load it first`);
1242
- return P;
1243
- }
1244
- function H(a) {
1245
- Y();
1246
- let P = V(a);
1247
- return R !== a && (L.setTheme(P), R = a), {
1248
- theme: P,
1249
- colorMap: L.getColorMap()
1250
- };
1251
- }
1252
- function U() {
1253
- return Y(), L.getLoadedThemes();
1254
- }
1255
- function W() {
1256
- return Y(), L.getLoadedLanguages();
1257
- }
1258
- function G(...a) {
1259
- Y(), L.loadLanguages(a.flat(1));
1260
- }
1261
- async function K(...a) {
1262
- return G(await resolveLangs(a));
1263
- }
1264
- function q(...a) {
1265
- Y();
1266
- for (let P of a.flat(1)) L.loadTheme(P);
1267
- }
1268
- async function J(...a) {
1269
- return Y(), q(await resolveThemes(a));
1270
- }
1271
- function Y() {
1272
- if (P) throw new ShikiError$1("Shiki instance has been disposed");
1273
- }
1274
- function X() {
1275
- P || (P = !0, L.dispose(), --instancesCount);
1276
- }
1277
- return {
1278
- setTheme: H,
1279
- getTheme: V,
1280
- getLanguage: B,
1281
- getLoadedThemes: U,
1282
- getLoadedLanguages: W,
1283
- resolveLangAlias: z,
1284
- loadLanguage: K,
1285
- loadLanguageSync: G,
1286
- loadTheme: J,
1287
- loadThemeSync: q,
1288
- dispose: X,
1289
- [Symbol.dispose]: X
1290
- };
1291
- }
1292
- async function createShikiInternal(a) {
1293
- a.engine || warnDeprecated("`engine` option is required. Use `createOnigurumaEngine` or `createJavaScriptRegexEngine` to create an engine.");
1294
- let [P, F, I] = await Promise.all([
1295
- resolveThemes(a.themes || []),
1296
- resolveLangs(a.langs || []),
1297
- a.engine
1298
- ]);
1299
- return createShikiInternalSync({
1300
- ...a,
1301
- themes: P,
1302
- langs: F,
1303
- engine: I
1304
- });
1305
- }
1306
768
  async function createHighlighterCore(a) {
1307
- let P = await createShikiInternal(a);
769
+ let P = await createShikiPrimitiveAsync(a);
1308
770
  return {
1309
771
  getLastGrammarState: (...a) => getLastGrammarState(P, ...a),
1310
- codeToTokensBase: (a, F) => codeToTokensBase(P, a, F),
772
+ codeToTokensBase: (a, F) => codeToTokensBase$1(P, a, F),
1311
773
  codeToTokensWithThemes: (a, F) => codeToTokensWithThemes(P, a, F),
1312
774
  codeToTokens: (a, F) => codeToTokens(P, a, F),
1313
775
  codeToHast: (a, F) => codeToHast(P, a, F),
@@ -1417,4 +879,4 @@ function createSingletonShorthands(a, P) {
1417
879
  }
1418
880
  };
1419
881
  }
1420
- export { addClassToHast, applyColorReplacements, createBundledHighlighter, createHighlighterCore, createPositionConverter, createShikiInternal, createShikiInternalSync, createSingletonShorthands, flatTokenVariants, getTokenStyleObject, guessEmbeddedLanguages, hastToHtml, isNoneTheme, isPlainLang, isSpecialLang, isSpecialTheme, makeSingletonHighlighter, normalizeGetter, normalizeTheme, resolveColorReplacements, splitLines, splitToken, splitTokens, stringifyTokenStyle, toArray, tokenizeAnsiWithTheme, tokenizeWithTheme, tokensToHast, transformerDecorations, warnDeprecated };
882
+ export { addClassToHast, createBundledHighlighter, createHighlighterCore, createPositionConverter, createSingletonShorthands, flatTokenVariants, getTokenStyleObject, guessEmbeddedLanguages, hastToHtml, makeSingletonHighlighter, splitToken, splitTokens, stringifyTokenStyle, tokenizeAnsiWithTheme, tokensToHast, transformerDecorations };