nuxt-studio 1.3.1 → 1.3.2
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/README.md +4 -4
- package/dist/app/engine-compile-CsVoR5aC.js +47 -0
- package/dist/app/index-BHiGO8lZ.js +1 -0
- package/dist/app/{index-DPJS0mlQ.js → index-CY2pEuQG.js} +2 -2
- package/dist/app/index-D7Zn_pzM.js +2 -0
- package/dist/app/index-DZT0wMp9.js +1 -0
- package/dist/app/main-C_AGiNp-.js +44 -0
- package/dist/app/main-DnxMhNqU.js +44 -0
- package/dist/app/main.d.ts +13 -13
- package/dist/app/main.js +1 -1
- package/dist/app/rehype-DxMxi_g-.js +1 -0
- package/dist/app/rehype-sZkPNt5P.js +1 -0
- package/dist/app/service-worker.d.ts +12 -12
- package/dist/app/shared.d.ts +12 -12
- package/dist/app/shiki-BWNTJJZW.js +1 -0
- package/dist/app/shiki-C6xy7L7G.js +1 -0
- package/dist/app/wasm--yL7jHw-.js +1 -0
- package/dist/module/module.json +1 -1
- package/dist/module/module.mjs +17 -20
- package/dist/module/runtime/host.js +2 -2
- package/dist/module/runtime/server/routes/ai/analyze.post.js +1 -1
- package/dist/module/runtime/server/routes/auth/google.get.js +1 -1
- package/dist/module/runtime/utils/document/generate.js +4 -4
- package/dist/module/runtime/utils/document/index.d.ts +1 -1
- package/dist/module/runtime/utils/document/index.js +1 -1
- package/dist/module/runtime/utils/document/schema.d.ts +1 -1
- package/dist/module/runtime/utils/document/schema.js +4 -1
- package/package.json +17 -16
- package/dist/app/index-BR26Sfgr.js +0 -2
- package/dist/app/index-C-y2greB.js +0 -2
- package/dist/app/index-CS_mI4k2.js +0 -2
- package/dist/app/index-Cl-ktQMQ.js +0 -1
- package/dist/app/main--P1Cc3W1.js +0 -90
- package/dist/app/main-BJNMrnKc.js +0 -90
- package/dist/app/main-D38hv2hq.js +0 -90
- package/dist/app/main-DKqH6k_9.js +0 -69
- package/dist/app/shared-Bk3qBOVF.js +0 -1
- package/dist/app/shared-cDYJuGWk.js +0 -1
package/dist/module/module.json
CHANGED
package/dist/module/module.mjs
CHANGED
|
@@ -38,7 +38,7 @@ async function getAssetsStorageTemplate(assetsStorage, _nuxt) {
|
|
|
38
38
|
].join("\n");
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
const version = "1.3.
|
|
41
|
+
const version = "1.3.2";
|
|
42
42
|
|
|
43
43
|
function setupDevMode(nuxt, runtime, assetsStorage) {
|
|
44
44
|
nuxt.options.nitro.storage = {
|
|
@@ -111,7 +111,7 @@ function validateAuthConfig(options) {
|
|
|
111
111
|
const missingProviderEnv = provider === "github" ? !hasGitHubAuth : !hasGitLabAuth;
|
|
112
112
|
if (missingProviderEnv) {
|
|
113
113
|
logger$1.warn([
|
|
114
|
-
`
|
|
114
|
+
`In order to use Studio in production mode, you need to setup authentication:`,
|
|
115
115
|
"- Read more on `https://nuxt.studio/auth-providers`",
|
|
116
116
|
`- Alternatively, you can disable studio by setting \`$production: { studio: false }\` in your \`nuxt.config.ts\``
|
|
117
117
|
].join("\n"));
|
|
@@ -144,9 +144,9 @@ const module$1 = defineNuxtModule({
|
|
|
144
144
|
},
|
|
145
145
|
repository: {
|
|
146
146
|
provider: "github",
|
|
147
|
-
owner:
|
|
148
|
-
repo:
|
|
149
|
-
branch:
|
|
147
|
+
owner: void 0,
|
|
148
|
+
repo: void 0,
|
|
149
|
+
branch: void 0,
|
|
150
150
|
rootDir: "",
|
|
151
151
|
private: true
|
|
152
152
|
},
|
|
@@ -197,12 +197,12 @@ const module$1 = defineNuxtModule({
|
|
|
197
197
|
options.dev = false;
|
|
198
198
|
}
|
|
199
199
|
const isProdBuild = nuxt.options.dev === false && nuxt.options._prepare === false;
|
|
200
|
-
if (isProdBuild
|
|
201
|
-
const
|
|
202
|
-
if (
|
|
203
|
-
options.repository = defu(
|
|
204
|
-
logger.info(`Auto-detected repository from CI environment: ${detected.provider}:${detected.owner}/${detected.repo}#${detected.branch}`);
|
|
200
|
+
if (isProdBuild) {
|
|
201
|
+
const detectedRepo = detectRepositoryFromCI();
|
|
202
|
+
if (detectedRepo) {
|
|
203
|
+
options.repository = defu(detectedRepo, options.repository);
|
|
205
204
|
}
|
|
205
|
+
logger.info(`Using repository: ${options.repository?.provider}:${options.repository?.owner}/${options.repository?.repo}#${options.repository?.branch}`);
|
|
206
206
|
}
|
|
207
207
|
if (isProdBuild && !options.repository?.owner && !options.repository?.repo) {
|
|
208
208
|
throw new Error("Repository owner and repository name are required");
|
|
@@ -309,12 +309,7 @@ const module$1 = defineNuxtModule({
|
|
|
309
309
|
"nuxt-studio > debug",
|
|
310
310
|
"nuxt-studio > extend"
|
|
311
311
|
];
|
|
312
|
-
config.build ||= {};
|
|
313
|
-
config.build.target = "es2020";
|
|
314
312
|
});
|
|
315
|
-
nuxt.options.nitro.esbuild ||= {};
|
|
316
|
-
nuxt.options.nitro.esbuild.options ||= {};
|
|
317
|
-
nuxt.options.nitro.esbuild.options.target = "es2020";
|
|
318
313
|
addPlugin(process.env.STUDIO_DEV_SERVER ? runtime("./plugins/studio.client.dev") : runtime("./plugins/studio.client"));
|
|
319
314
|
const assetsStorage = createStorage({
|
|
320
315
|
driver: fsDriver({
|
|
@@ -371,11 +366,13 @@ const module$1 = defineNuxtModule({
|
|
|
371
366
|
route: "/__nuxt_studio/ai/generate",
|
|
372
367
|
handler: runtime("./server/routes/ai/generate.post")
|
|
373
368
|
});
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
369
|
+
if (options.ai?.experimental?.collectionContext) {
|
|
370
|
+
addServerHandler({
|
|
371
|
+
method: "post",
|
|
372
|
+
route: "/__nuxt_studio/ai/analyze",
|
|
373
|
+
handler: runtime("./server/routes/ai/analyze.post")
|
|
374
|
+
});
|
|
375
|
+
}
|
|
379
376
|
}
|
|
380
377
|
}
|
|
381
378
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ref } from "vue";
|
|
2
2
|
import { ensure } from "./utils/ensure.js";
|
|
3
3
|
import { getCollectionByFilePath, generateIdFromFsPath, generateRecordDeletion, generateRecordInsert, generateFsPathFromId, getCollectionById } from "./utils/collection.js";
|
|
4
|
-
import { applyCollectionSchema, isDocumentMatchingContent, generateDocumentFromContent, generateContentFromDocument, areDocumentsEqual, pickReservedKeysFromDocument,
|
|
4
|
+
import { applyCollectionSchema, isDocumentMatchingContent, generateDocumentFromContent, generateContentFromDocument, areDocumentsEqual, pickReservedKeysFromDocument, cleanDataKeys, sanitizeDocumentTree } from "./utils/document/index.js";
|
|
5
5
|
import { getHostStyles, getSidebarWidth, adjustFixedElements } from "./utils/sidebar.js";
|
|
6
6
|
import { clearError, getAppManifest, queryCollection, queryCollectionItemSurroundings, queryCollectionNavigation, queryCollectionSearchSections, useRuntimeConfig } from "#imports";
|
|
7
7
|
import { collections } from "#content/preview";
|
|
@@ -210,7 +210,7 @@ export function useStudioHost(user, repository) {
|
|
|
210
210
|
areEqual: (document1, document2) => areDocumentsEqual(document1, document2),
|
|
211
211
|
isMatchingContent: async (content, document2) => isDocumentMatchingContent(content, document2),
|
|
212
212
|
pickReservedKeys: (document2) => pickReservedKeysFromDocument(document2),
|
|
213
|
-
|
|
213
|
+
cleanDataKeys: (document2) => cleanDataKeys(document2),
|
|
214
214
|
detectActives: () => {
|
|
215
215
|
const wrappers = document.querySelectorAll("[data-content-id]");
|
|
216
216
|
return Array.from(wrappers).map((wrapper) => {
|
|
@@ -4,7 +4,6 @@ import { eventHandler, createError, useSession, getRequestProtocol, readBody } f
|
|
|
4
4
|
import { consola } from "consola";
|
|
5
5
|
import { useRuntimeConfig } from "#imports";
|
|
6
6
|
import { queryCollection } from "@nuxt/content/server";
|
|
7
|
-
import { generateContentFromDocument } from "../../../utils/document/generate.js";
|
|
8
7
|
import {
|
|
9
8
|
detectContentType,
|
|
10
9
|
analyzeArchitecture,
|
|
@@ -87,6 +86,7 @@ export default eventHandler(async (event) => {
|
|
|
87
86
|
}
|
|
88
87
|
let excerpt = "";
|
|
89
88
|
try {
|
|
89
|
+
const { generateContentFromDocument } = await import("../../../utils/document/generate.js");
|
|
90
90
|
const rawContent = await generateContentFromDocument(document);
|
|
91
91
|
if (rawContent) {
|
|
92
92
|
excerpt = rawContent;
|
|
@@ -101,7 +101,7 @@ export default eventHandler(async (event) => {
|
|
|
101
101
|
if (!moderators.includes(user.email)) {
|
|
102
102
|
if (import.meta.dev && moderators.length === 0) {
|
|
103
103
|
logger.warn([
|
|
104
|
-
"
|
|
104
|
+
"No moderators defined. Moderators are required for Google authentication.",
|
|
105
105
|
"Please set the `STUDIO_GOOGLE_MODERATORS` environment variable to a comma-separated list of email addresses of the moderators."
|
|
106
106
|
].join("\n"));
|
|
107
107
|
}
|
|
@@ -8,7 +8,7 @@ import destr from "destr";
|
|
|
8
8
|
import { parseFrontMatter, stringifyFrontMatter } from "remark-mdc";
|
|
9
9
|
import { useHostMeta } from "../../composables/useMeta.js";
|
|
10
10
|
import { addPageTypeFields, generateStemFromId, getFileExtension } from "./utils.js";
|
|
11
|
-
import {
|
|
11
|
+
import { cleanDataKeys } from "./schema.js";
|
|
12
12
|
import { remarkEmojiPlugin } from "nuxt-studio/app/utils";
|
|
13
13
|
const logger = consola.withTag("Nuxt Studio");
|
|
14
14
|
export async function generateDocumentFromContent(id, content, options = { compress: true }) {
|
|
@@ -121,21 +121,21 @@ export async function generateContentFromDocument(document) {
|
|
|
121
121
|
return null;
|
|
122
122
|
}
|
|
123
123
|
export async function generateContentFromYAMLDocument(document) {
|
|
124
|
-
return await stringifyFrontMatter(
|
|
124
|
+
return await stringifyFrontMatter(cleanDataKeys(document), "", {
|
|
125
125
|
prefix: "",
|
|
126
126
|
suffix: "",
|
|
127
127
|
lineWidth: 0
|
|
128
128
|
});
|
|
129
129
|
}
|
|
130
130
|
export async function generateContentFromJSONDocument(document) {
|
|
131
|
-
return JSON.stringify(
|
|
131
|
+
return JSON.stringify(cleanDataKeys(document), null, 2);
|
|
132
132
|
}
|
|
133
133
|
export async function generateContentFromMarkdownDocument(document) {
|
|
134
134
|
const body = document.body.type === "minimark" ? decompressTree(document.body) : document.body;
|
|
135
135
|
visit(body, (node) => node.type === "element" && node.tag === "a", (node) => {
|
|
136
136
|
Reflect.deleteProperty(node.props, "rel");
|
|
137
137
|
});
|
|
138
|
-
const markdown = await stringifyMarkdown(body,
|
|
138
|
+
const markdown = await stringifyMarkdown(body, cleanDataKeys(document), {
|
|
139
139
|
frontMatter: {
|
|
140
140
|
options: {
|
|
141
141
|
lineWidth: 0
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { applyCollectionSchema, pickReservedKeysFromDocument,
|
|
1
|
+
export { applyCollectionSchema, pickReservedKeysFromDocument, cleanDataKeys, reservedKeys, } from './schema.js';
|
|
2
2
|
export { isDocumentMatchingContent, areDocumentsEqual, } from './compare.js';
|
|
3
3
|
export { generateDocumentFromContent, generateDocumentFromMarkdownContent, generateDocumentFromYAMLContent, generateDocumentFromJSONContent, generateContentFromDocument, generateContentFromMarkdownDocument, generateContentFromYAMLDocument, generateContentFromJSONDocument, } from './generate.js';
|
|
4
4
|
export { addPageTypeFields, parseDocumentId, generatePathFromStem, generateStemFromId, generateTitleFromPath, getFileExtension, } from './utils.js';
|
|
@@ -3,4 +3,4 @@ import type { DatabaseItem } from 'nuxt-studio/app';
|
|
|
3
3
|
export declare const reservedKeys: string[];
|
|
4
4
|
export declare function applyCollectionSchema(id: string, collectionInfo: CollectionInfo, document: CollectionItemBase): DatabaseItem;
|
|
5
5
|
export declare function pickReservedKeysFromDocument(document: DatabaseItem): DatabaseItem;
|
|
6
|
-
export declare function
|
|
6
|
+
export declare function cleanDataKeys(document: DatabaseItem): DatabaseItem;
|
|
@@ -31,7 +31,7 @@ export function applyCollectionSchema(id, collectionInfo, document) {
|
|
|
31
31
|
export function pickReservedKeysFromDocument(document) {
|
|
32
32
|
return pick(document, reservedKeys);
|
|
33
33
|
}
|
|
34
|
-
export function
|
|
34
|
+
export function cleanDataKeys(document) {
|
|
35
35
|
const result = omit(document, reservedKeys);
|
|
36
36
|
if (result.navigation === true) {
|
|
37
37
|
Reflect.deleteProperty(result, "navigation");
|
|
@@ -57,6 +57,9 @@ export function removeReservedKeysFromDocument(document) {
|
|
|
57
57
|
if (result[key] === null) {
|
|
58
58
|
Reflect.deleteProperty(result, key);
|
|
59
59
|
}
|
|
60
|
+
if (Array.isArray(result[key]) && result[key].length === 0) {
|
|
61
|
+
Reflect.deleteProperty(result, key);
|
|
62
|
+
}
|
|
60
63
|
}
|
|
61
64
|
return result;
|
|
62
65
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-studio",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"description": "Nuxt Studio for Nuxt Content",
|
|
5
5
|
"private": false,
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "git+https://github.com/nuxt-content/studio.git"
|
|
8
|
+
"url": "git+https://github.com/nuxt-content/nuxt-studio.git"
|
|
9
9
|
},
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"type": "module",
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"types": "./dist/app/main.d.ts",
|
|
16
16
|
"default": "./dist/app/main.js"
|
|
17
17
|
},
|
|
18
|
+
"./app/*": "./dist/app/*",
|
|
18
19
|
"./app/utils": {
|
|
19
20
|
"types": "./dist/app/shared.d.ts",
|
|
20
21
|
"default": "./dist/app/shared.js"
|
|
@@ -47,12 +48,12 @@
|
|
|
47
48
|
"clean": "rm -rf dist .nuxt .output node_modules docs/node_modules docs/.output docs/.data docs/.nuxt playground/docus/node_modules playground/docus/.output playground/docus/.data playground/docus/.nuxt playground/minimal/node_modules playground/minimal/.output playground/minimal/.data playground/minimal/.nuxt pnpm-lock.yaml"
|
|
48
49
|
},
|
|
49
50
|
"dependencies": {
|
|
50
|
-
"@ai-sdk/gateway": "^3.0.
|
|
51
|
-
"@ai-sdk/vue": "^3.0.
|
|
52
|
-
"@iconify-json/lucide": "^1.2.
|
|
51
|
+
"@ai-sdk/gateway": "^3.0.42",
|
|
52
|
+
"@ai-sdk/vue": "^3.0.82",
|
|
53
|
+
"@iconify-json/lucide": "^1.2.90",
|
|
53
54
|
"@nuxtjs/mdc": "^0.20.1",
|
|
54
|
-
"@vueuse/core": "^14.2.
|
|
55
|
-
"ai": "^6.0.
|
|
55
|
+
"@vueuse/core": "^14.2.1",
|
|
56
|
+
"ai": "^6.0.82",
|
|
56
57
|
"defu": "^6.1.4",
|
|
57
58
|
"destr": "^2.0.5",
|
|
58
59
|
"js-yaml": "^4.1.1",
|
|
@@ -66,21 +67,21 @@
|
|
|
66
67
|
},
|
|
67
68
|
"devDependencies": {
|
|
68
69
|
"@gitbeaker/core": "^43.8.0",
|
|
69
|
-
"@iconify-json/simple-icons": "^1.2.
|
|
70
|
+
"@iconify-json/simple-icons": "^1.2.70",
|
|
70
71
|
"@nuxt/content": "^3.11.2",
|
|
71
|
-
"@nuxt/eslint-config": "^1.
|
|
72
|
-
"@nuxt/kit": "^4.3.
|
|
72
|
+
"@nuxt/eslint-config": "^1.15.1",
|
|
73
|
+
"@nuxt/kit": "^4.3.1",
|
|
73
74
|
"@nuxt/module-builder": "^1.0.2",
|
|
74
75
|
"@nuxt/ui": "^4.4.0",
|
|
75
76
|
"@octokit/types": "^16.0.0",
|
|
76
|
-
"@release-it/conventional-changelog": "^10.0.
|
|
77
|
+
"@release-it/conventional-changelog": "^10.0.5",
|
|
77
78
|
"@tailwindcss/typography": "^0.5.19",
|
|
78
79
|
"@tiptap/extension-emoji": "^3.19.0",
|
|
79
80
|
"@types/js-yaml": "^4.0.9",
|
|
80
|
-
"@unhead/vue": "^2.1.
|
|
81
|
+
"@unhead/vue": "^2.1.4",
|
|
81
82
|
"@unpic/vue": "^1.0.0",
|
|
82
83
|
"@vitejs/plugin-vue": "^6.0.4",
|
|
83
|
-
"eslint": "^
|
|
84
|
+
"eslint": "^10.0.0",
|
|
84
85
|
"idb-keyval": "^6.2.2",
|
|
85
86
|
"minimark": "^0.2.0",
|
|
86
87
|
"modern-monaco": "^0.3.7",
|
|
@@ -92,11 +93,11 @@
|
|
|
92
93
|
"vite-plugin-dts": "^4.5.4",
|
|
93
94
|
"vite-plugin-libcss": "^1.1.2",
|
|
94
95
|
"vitest": "^4.0.18",
|
|
95
|
-
"vue": "^3.5.
|
|
96
|
-
"vue-router": "^
|
|
96
|
+
"vue": "^3.5.28",
|
|
97
|
+
"vue-router": "^5.0.2",
|
|
97
98
|
"vue-tsc": "^3.2.4"
|
|
98
99
|
},
|
|
99
|
-
"packageManager": "pnpm@10.
|
|
100
|
+
"packageManager": "pnpm@10.29.3",
|
|
100
101
|
"keywords": [
|
|
101
102
|
"nuxt",
|
|
102
103
|
"content",
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
var e,t,n=Object.defineProperty,s=(e,t,s)=>((e,t,s)=>t in e?n(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s)(e,"symbol"!=typeof t?t+"":t,s);import{t as r}from"./main-BJNMrnKc.js";let o=class extends Error{constructor(e){super(e),this.name="ShikiError"}};function i(e){return Array.isArray(e)?function(e){let t=[];for(let n=0,s=e.length;n<s;n++)t[n]=i(e[n]);return t}(e):e instanceof RegExp?e:"object"==typeof e?function(e){let t={};for(let n in e)t[n]=i(e[n]);return t}(e):e}function a(e,...t){return t.forEach(t=>{for(let n in t)e[n]=t[n]}),e}function c(e){const t=~e.lastIndexOf("/")||~e.lastIndexOf("\\");return 0===t?e:~t===e.length-1?c(e.substring(0,e.length-1)):e.substr(1+~t)}var l=/\$(\d+)|\${(\d+):\/(downcase|upcase)}/g,u=class{static hasCaptures(e){return null!==e&&(l.lastIndex=0,l.test(e))}static replaceCaptures(e,t,n){return e.replace(l,(e,s,r,o)=>{let i=n[parseInt(s||r,10)];if(!i)return e;{let e=t.substring(i.start,i.end);for(;"."===e[0];)e=e.substring(1);switch(o){case"downcase":return e.toLowerCase();case"upcase":return e.toUpperCase();default:return e}}})}};function p(e,t){return e<t?-1:e>t?1:0}function d(e,t){if(null===e&&null===t)return 0;if(!e)return-1;if(!t)return 1;let n=e.length,s=t.length;if(n===s){for(let s=0;s<n;s++){let n=p(e[s],t[s]);if(0!==n)return n}return 0}return n-s}function g(e){return!!/^#[0-9a-f]{6}$/i.test(e)||(!!/^#[0-9a-f]{8}$/i.test(e)||(!!/^#[0-9a-f]{3}$/i.test(e)||!!/^#[0-9a-f]{4}$/i.test(e)))}function f(e){return e.replace(/[\-\\\{\}\*\+\?\|\^\$\.\,\[\]\(\)\#\s]/g,"\\$&")}var m=class{constructor(e){s(this,"cache",/* @__PURE__ */new Map),this.fn=e}get(e){if(this.cache.has(e))return this.cache.get(e);const t=this.fn(e);return this.cache.set(e,t),t}},_=class{constructor(e,t,n){s(this,"_cachedMatchRoot",new m(e=>this._root.match(e))),this._colorMap=e,this._defaults=t,this._root=n}static createFromRawTheme(e,t){return this.createFromParsedTheme(function(e){if(!e)return[];if(!e.settings||!Array.isArray(e.settings))return[];let t=e.settings,n=[],s=0;for(let r=0,o=t.length;r<o;r++){let e,o=t[r];if(!o.settings)continue;if("string"==typeof o.scope){let t=o.scope;t=t.replace(/^[,]+/,""),t=t.replace(/[,]+$/,""),e=t.split(",")}else e=Array.isArray(o.scope)?o.scope:[""];let i=-1;if("string"==typeof o.settings.fontStyle){i=0;let e=o.settings.fontStyle.split(" ");for(let t=0,n=e.length;t<n;t++){switch(e[t]){case"italic":i|=1;break;case"bold":i|=2;break;case"underline":i|=4;break;case"strikethrough":i|=8}}}let a=null;"string"==typeof o.settings.foreground&&g(o.settings.foreground)&&(a=o.settings.foreground);let c=null;"string"==typeof o.settings.background&&g(o.settings.background)&&(c=o.settings.background);for(let t=0,l=e.length;t<l;t++){let o=e[t].trim().split(" "),l=o[o.length-1],u=null;o.length>1&&(u=o.slice(0,o.length-1),u.reverse()),n[s++]=new S(l,u,r,i,a,c)}}return n}(e),t)}static createFromParsedTheme(e,t){return function(e,t){e.sort((e,t)=>{let n=p(e.scope,t.scope);return 0!==n?n:(n=d(e.parentScopes,t.parentScopes),0!==n?n:e.index-t.index)});let n=0,s="#000000",r="#ffffff";for(;e.length>=1&&""===e[0].scope;){let t=e.shift();-1!==t.fontStyle&&(n=t.fontStyle),null!==t.foreground&&(s=t.foreground),null!==t.background&&(r=t.background)}let o=new C(t),i=new k(n,o.getId(s),o.getId(r)),a=new v(new A(0,null,-1,0,0),[]);for(let c=0,l=e.length;c<l;c++){let t=e[c];a.insert(0,t.scope,t.parentScopes,t.fontStyle,o.getId(t.foreground),o.getId(t.background))}return new _(o,i,a)}(e,t)}getColorMap(){return this._colorMap.getColorMap()}getDefaults(){return this._defaults}match(e){if(null===e)return this._defaults;const t=e.scopeName,n=this._cachedMatchRoot.get(t).find(t=>function(e,t){if(0===t.length)return!0;for(let n=0;n<t.length;n++){let s=t[n],r=!1;if(">"===s){if(n===t.length-1)return!1;s=t[++n],r=!0}for(;e&&!b(e.scopeName,s);){if(r)return!1;e=e.parent}if(!e)return!1;e=e.parent}return!0}(e.parent,t.parentScopes));return n?new k(n.fontStyle,n.foreground,n.background):null}},y=class e{constructor(e,t){this.parent=e,this.scopeName=t}static push(t,n){for(const s of n)t=new e(t,s);return t}static from(...t){let n=null;for(let s=0;s<t.length;s++)n=new e(n,t[s]);return n}push(t){return new e(this,t)}getSegments(){let e=this;const t=[];for(;e;)t.push(e.scopeName),e=e.parent;return t.reverse(),t}toString(){return this.getSegments().join(" ")}extends(e){return this===e||null!==this.parent&&this.parent.extends(e)}getExtensionIfDefined(e){const t=[];let n=this;for(;n&&n!==e;)t.push(n.scopeName),n=n.parent;return n===e?t.reverse():void 0}};function b(e,t){return t===e||e.startsWith(t)&&"."===e[t.length]}var k=class{constructor(e,t,n){this.fontStyle=e,this.foregroundId=t,this.backgroundId=n}};var S=class{constructor(e,t,n,s,r,o){this.scope=e,this.parentScopes=t,this.index=n,this.fontStyle=s,this.foreground=r,this.background=o}},w=/* @__PURE__ */(e=>(e[e.NotSet=-1]="NotSet",e[e.None=0]="None",e[e.Italic=1]="Italic",e[e.Bold=2]="Bold",e[e.Underline=4]="Underline",e[e.Strikethrough=8]="Strikethrough",e))(w||{});var C=class{constructor(e){if(s(this,"_isFrozen"),s(this,"_lastColorId"),s(this,"_id2color"),s(this,"_color2id"),this._lastColorId=0,this._id2color=[],this._color2id=/* @__PURE__ */Object.create(null),Array.isArray(e)){this._isFrozen=!0;for(let t=0,n=e.length;t<n;t++)this._color2id[e[t]]=t,this._id2color[t]=e[t]}else this._isFrozen=!1}getId(e){if(null===e)return 0;e=e.toUpperCase();let t=this._color2id[e];if(t)return t;if(this._isFrozen)throw new Error(`Missing color in color map - ${e}`);return t=++this._lastColorId,this._color2id[e]=t,this._id2color[t]=e,t}getColorMap(){return this._id2color.slice(0)}},N=Object.freeze([]),A=class e{constructor(e,t,n,r,o){s(this,"scopeDepth"),s(this,"parentScopes"),s(this,"fontStyle"),s(this,"foreground"),s(this,"background"),this.scopeDepth=e,this.parentScopes=t||N,this.fontStyle=n,this.foreground=r,this.background=o}clone(){return new e(this.scopeDepth,this.parentScopes,this.fontStyle,this.foreground,this.background)}static cloneArr(e){let t=[];for(let n=0,s=e.length;n<s;n++)t[n]=e[n].clone();return t}acceptOverwrite(e,t,n,s){this.scopeDepth>e?console.log("how did this happen?"):this.scopeDepth=e,-1!==t&&(this.fontStyle=t),0!==n&&(this.foreground=n),0!==s&&(this.background=s)}},v=class e{constructor(e,t=[],n={}){s(this,"_rulesWithParentScopes"),this._mainRule=e,this._children=n,this._rulesWithParentScopes=t}static _cmpBySpecificity(e,t){if(e.scopeDepth!==t.scopeDepth)return t.scopeDepth-e.scopeDepth;let n=0,s=0;for(;">"===e.parentScopes[n]&&n++,">"===t.parentScopes[s]&&s++,!(n>=e.parentScopes.length||s>=t.parentScopes.length);){const r=t.parentScopes[s].length-e.parentScopes[n].length;if(0!==r)return r;n++,s++}return t.parentScopes.length-e.parentScopes.length}match(t){if(""!==t){let e,n,s=t.indexOf(".");if(-1===s?(e=t,n=""):(e=t.substring(0,s),n=t.substring(s+1)),this._children.hasOwnProperty(e))return this._children[e].match(n)}const n=this._rulesWithParentScopes.concat(this._mainRule);return n.sort(e._cmpBySpecificity),n}insert(t,n,s,r,o,i){if(""===n)return void this._doInsertHere(t,s,r,o,i);let a,c,l,u=n.indexOf(".");-1===u?(a=n,c=""):(a=n.substring(0,u),c=n.substring(u+1)),this._children.hasOwnProperty(a)?l=this._children[a]:(l=new e(this._mainRule.clone(),A.cloneArr(this._rulesWithParentScopes)),this._children[a]=l),l.insert(t+1,c,s,r,o,i)}_doInsertHere(e,t,n,s,r){if(null!==t){for(let o=0,i=this._rulesWithParentScopes.length;o<i;o++){let i=this._rulesWithParentScopes[o];if(0===d(i.parentScopes,t))return void i.acceptOverwrite(e,n,s,r)}-1===n&&(n=this._mainRule.fontStyle),0===s&&(s=this._mainRule.foreground),0===r&&(r=this._mainRule.background),this._rulesWithParentScopes.push(new A(e,t,n,s,r))}else this._mainRule.acceptOverwrite(e,n,s,r)}},P=class e{static toBinaryStr(e){return e.toString(2).padStart(32,"0")}static print(t){const n=e.getLanguageId(t),s=e.getTokenType(t),r=e.getFontStyle(t),o=e.getForeground(t),i=e.getBackground(t);console.log({languageId:n,tokenType:s,fontStyle:r,foreground:o,background:i})}static getLanguageId(e){return(255&e)>>>0}static getTokenType(e){return(768&e)>>>8}static containsBalancedBrackets(e){return!!(1024&e)}static getFontStyle(e){return(30720&e)>>>11}static getForeground(e){return(16744448&e)>>>15}static getBackground(e){return(4278190080&e)>>>24}static set(t,n,s,r,o,i,a){let c=e.getLanguageId(t),l=e.getTokenType(t),u=e.containsBalancedBrackets(t)?1:0,p=e.getFontStyle(t),d=e.getForeground(t),g=e.getBackground(t);return 0!==n&&(c=n),8!==s&&(l=s),null!==r&&(u=r?1:0),-1!==o&&(p=o),0!==i&&(d=i),0!==a&&(g=a),(c|l<<8|u<<10|p<<11|d<<15|g<<24)>>>0}};function I(e){return e}function R(e,t){const n=[],s=function(e){let t=/([LR]:|[\w\.:][\w\.:\-]*|[\,\|\-\(\)])/g,n=t.exec(e);return{next:()=>{if(!n)return null;const s=n[0];return n=t.exec(e),s}}}(e);let r=s.next();for(;null!==r;){let e=0;if(2===r.length&&":"===r.charAt(1)){switch(r.charAt(0)){case"R":e=1;break;case"L":e=-1;break;default:console.log(`Unknown priority ${r} in scope selector`)}r=s.next()}let t=i();if(n.push({matcher:t,priority:e}),","!==r)break;r=s.next()}return n;function o(){if("-"===r){r=s.next();const e=o();return t=>!!e&&!e(t)}if("("===r){r=s.next();const e=function(){const e=[];let t=i();for(;t&&(e.push(t),"|"===r||","===r);){do{r=s.next()}while("|"===r||","===r);t=i()}return t=>e.some(e=>e(t))}();return")"===r&&(r=s.next()),e}if(T(r)){const e=[];do{e.push(r),r=s.next()}while(T(r));return n=>t(e,n)}return null}function i(){const e=[];let t=o();for(;t;)e.push(t),t=o();return t=>e.every(e=>e(t))}}function T(e){return!!e&&!!e.match(/[\w\.:]+/)}function L(e){"function"==typeof e.dispose&&e.dispose()}var x=class{constructor(e){this.scopeName=e}toKey(){return this.scopeName}},G=class{constructor(e,t){this.scopeName=e,this.ruleName=t}toKey(){return`${this.scopeName}#${this.ruleName}`}},E=class{constructor(){s(this,"_references",[]),s(this,"_seenReferenceKeys",/* @__PURE__ */new Set),s(this,"visitedRule",/* @__PURE__ */new Set)}get references(){return this._references}add(e){const t=e.toKey();this._seenReferenceKeys.has(t)||(this._seenReferenceKeys.add(t),this._references.push(e))}},$=class{constructor(e,t){s(this,"seenFullScopeRequests",/* @__PURE__ */new Set),s(this,"seenPartialScopeRequests",/* @__PURE__ */new Set),s(this,"Q"),this.repo=e,this.initialScopeName=t,this.seenFullScopeRequests.add(this.initialScopeName),this.Q=[new x(this.initialScopeName)]}processQueue(){const e=this.Q;this.Q=[];const t=new E;for(const n of e)B(n,this.initialScopeName,this.repo,t);for(const n of t.references)if(n instanceof x){if(this.seenFullScopeRequests.has(n.scopeName))continue;this.seenFullScopeRequests.add(n.scopeName),this.Q.push(n)}else{if(this.seenFullScopeRequests.has(n.scopeName))continue;if(this.seenPartialScopeRequests.has(n.toKey()))continue;this.seenPartialScopeRequests.add(n.toKey()),this.Q.push(n)}}};function B(e,t,n,s){const r=n.lookup(e.scopeName);if(!r){if(e.scopeName===t)throw new Error(`No grammar provided for <${t}>`);return}const o=n.lookup(t);e instanceof x?O({baseGrammar:o,selfGrammar:r},s):M(e.ruleName,{baseGrammar:o,selfGrammar:r,repository:r.repository},s);const i=n.injections(e.scopeName);if(i)for(const a of i)s.add(new x(a))}function M(e,t,n){if(t.repository&&t.repository[e]){j([t.repository[e]],t,n)}}function O(e,t){e.selfGrammar.patterns&&Array.isArray(e.selfGrammar.patterns)&&j(e.selfGrammar.patterns,{...e,repository:e.selfGrammar.repository},t),e.selfGrammar.injections&&j(Object.values(e.selfGrammar.injections),{...e,repository:e.selfGrammar.repository},t)}function j(e,t,n){for(const s of e){if(n.visitedRule.has(s))continue;n.visitedRule.add(s);const e=s.repository?a({},t.repository,s.repository):t.repository;Array.isArray(s.patterns)&&j(s.patterns,{...t,repository:e},n);const r=s.include;if(!r)continue;const o=z(r);switch(o.kind){case 0:O({...t,selfGrammar:t.baseGrammar},n);break;case 1:O(t,n);break;case 2:M(o.ruleName,{...t,repository:e},n);break;case 3:case 4:const s=o.scopeName===t.selfGrammar.scopeName?t.selfGrammar:o.scopeName===t.baseGrammar.scopeName?t.baseGrammar:void 0;if(s){const r={baseGrammar:t.baseGrammar,selfGrammar:s,repository:e};4===o.kind?M(o.ruleName,r,n):O(r,n)}else 4===o.kind?n.add(new G(o.scopeName,o.ruleName)):n.add(new x(o.scopeName))}}}var F=class{constructor(){s(this,"kind",0)}},W=class{constructor(){s(this,"kind",1)}},D=class{constructor(e){s(this,"kind",2),this.ruleName=e}},q=class{constructor(e){s(this,"kind",3),this.scopeName=e}},U=class{constructor(e,t){s(this,"kind",4),this.scopeName=e,this.ruleName=t}};function z(e){if("$base"===e)return new F;if("$self"===e)return new W;const t=e.indexOf("#");if(-1===t)return new q(e);if(0===t)return new D(e.substring(1));{const n=e.substring(0,t),s=e.substring(t+1);return new U(n,s)}}var H=/\\(\d+)/,K=/\\(\d+)/g;var J=class{constructor(e,t,n,r){s(this,"$location"),s(this,"id"),s(this,"_nameIsCapturing"),s(this,"_name"),s(this,"_contentNameIsCapturing"),s(this,"_contentName"),this.$location=e,this.id=t,this._name=n||null,this._nameIsCapturing=u.hasCaptures(this._name),this._contentName=r||null,this._contentNameIsCapturing=u.hasCaptures(this._contentName)}get debugName(){const e=this.$location?`${c(this.$location.filename)}:${this.$location.line}`:"unknown";return`${this.constructor.name}#${this.id} @ ${e}`}getName(e,t){return this._nameIsCapturing&&null!==this._name&&null!==e&&null!==t?u.replaceCaptures(this._name,e,t):this._name}getContentName(e,t){return this._contentNameIsCapturing&&null!==this._contentName?u.replaceCaptures(this._contentName,e,t):this._contentName}},Q=class extends J{constructor(e,t,n,r,o){super(e,t,n,r),s(this,"retokenizeCapturedWithRuleId"),this.retokenizeCapturedWithRuleId=o}dispose(){}collectPatterns(e,t){throw new Error("Not supported!")}compile(e,t){throw new Error("Not supported!")}compileAG(e,t,n,s){throw new Error("Not supported!")}},Y=class extends J{constructor(e,t,n,r,o){super(e,t,n,null),s(this,"_match"),s(this,"captures"),s(this,"_cachedCompiledPatterns"),this._match=new te(r,this.id),this.captures=o,this._cachedCompiledPatterns=null}dispose(){this._cachedCompiledPatterns&&(this._cachedCompiledPatterns.dispose(),this._cachedCompiledPatterns=null)}get debugMatchRegExp(){return`${this._match.source}`}collectPatterns(e,t){t.push(this._match)}compile(e,t){return this._getCachedCompiledPatterns(e).compile(e)}compileAG(e,t,n,s){return this._getCachedCompiledPatterns(e).compileAG(e,n,s)}_getCachedCompiledPatterns(e){return this._cachedCompiledPatterns||(this._cachedCompiledPatterns=new ne,this.collectPatterns(e,this._cachedCompiledPatterns)),this._cachedCompiledPatterns}},V=class extends J{constructor(e,t,n,r,o){super(e,t,n,r),s(this,"hasMissingPatterns"),s(this,"patterns"),s(this,"_cachedCompiledPatterns"),this.patterns=o.patterns,this.hasMissingPatterns=o.hasMissingPatterns,this._cachedCompiledPatterns=null}dispose(){this._cachedCompiledPatterns&&(this._cachedCompiledPatterns.dispose(),this._cachedCompiledPatterns=null)}collectPatterns(e,t){for(const n of this.patterns){e.getRule(n).collectPatterns(e,t)}}compile(e,t){return this._getCachedCompiledPatterns(e).compile(e)}compileAG(e,t,n,s){return this._getCachedCompiledPatterns(e).compileAG(e,n,s)}_getCachedCompiledPatterns(e){return this._cachedCompiledPatterns||(this._cachedCompiledPatterns=new ne,this.collectPatterns(e,this._cachedCompiledPatterns)),this._cachedCompiledPatterns}},X=class extends J{constructor(e,t,n,r,o,i,a,c,l,u){super(e,t,n,r),s(this,"_begin"),s(this,"beginCaptures"),s(this,"_end"),s(this,"endHasBackReferences"),s(this,"endCaptures"),s(this,"applyEndPatternLast"),s(this,"hasMissingPatterns"),s(this,"patterns"),s(this,"_cachedCompiledPatterns"),this._begin=new te(o,this.id),this.beginCaptures=i,this._end=new te(a||"",-1),this.endHasBackReferences=this._end.hasBackReferences,this.endCaptures=c,this.applyEndPatternLast=l||!1,this.patterns=u.patterns,this.hasMissingPatterns=u.hasMissingPatterns,this._cachedCompiledPatterns=null}dispose(){this._cachedCompiledPatterns&&(this._cachedCompiledPatterns.dispose(),this._cachedCompiledPatterns=null)}get debugBeginRegExp(){return`${this._begin.source}`}get debugEndRegExp(){return`${this._end.source}`}getEndWithResolvedBackReferences(e,t){return this._end.resolveBackReferences(e,t)}collectPatterns(e,t){t.push(this._begin)}compile(e,t){return this._getCachedCompiledPatterns(e,t).compile(e)}compileAG(e,t,n,s){return this._getCachedCompiledPatterns(e,t).compileAG(e,n,s)}_getCachedCompiledPatterns(e,t){if(!this._cachedCompiledPatterns){this._cachedCompiledPatterns=new ne;for(const t of this.patterns){e.getRule(t).collectPatterns(e,this._cachedCompiledPatterns)}this.applyEndPatternLast?this._cachedCompiledPatterns.push(this._end.hasBackReferences?this._end.clone():this._end):this._cachedCompiledPatterns.unshift(this._end.hasBackReferences?this._end.clone():this._end)}return this._end.hasBackReferences&&(this.applyEndPatternLast?this._cachedCompiledPatterns.setSource(this._cachedCompiledPatterns.length()-1,t):this._cachedCompiledPatterns.setSource(0,t)),this._cachedCompiledPatterns}},Z=class extends J{constructor(e,t,n,r,o,i,a,c,l){super(e,t,n,r),s(this,"_begin"),s(this,"beginCaptures"),s(this,"whileCaptures"),s(this,"_while"),s(this,"whileHasBackReferences"),s(this,"hasMissingPatterns"),s(this,"patterns"),s(this,"_cachedCompiledPatterns"),s(this,"_cachedCompiledWhilePatterns"),this._begin=new te(o,this.id),this.beginCaptures=i,this.whileCaptures=c,this._while=new te(a,-2),this.whileHasBackReferences=this._while.hasBackReferences,this.patterns=l.patterns,this.hasMissingPatterns=l.hasMissingPatterns,this._cachedCompiledPatterns=null,this._cachedCompiledWhilePatterns=null}dispose(){this._cachedCompiledPatterns&&(this._cachedCompiledPatterns.dispose(),this._cachedCompiledPatterns=null),this._cachedCompiledWhilePatterns&&(this._cachedCompiledWhilePatterns.dispose(),this._cachedCompiledWhilePatterns=null)}get debugBeginRegExp(){return`${this._begin.source}`}get debugWhileRegExp(){return`${this._while.source}`}getWhileWithResolvedBackReferences(e,t){return this._while.resolveBackReferences(e,t)}collectPatterns(e,t){t.push(this._begin)}compile(e,t){return this._getCachedCompiledPatterns(e).compile(e)}compileAG(e,t,n,s){return this._getCachedCompiledPatterns(e).compileAG(e,n,s)}_getCachedCompiledPatterns(e){if(!this._cachedCompiledPatterns){this._cachedCompiledPatterns=new ne;for(const t of this.patterns){e.getRule(t).collectPatterns(e,this._cachedCompiledPatterns)}}return this._cachedCompiledPatterns}compileWhile(e,t){return this._getCachedCompiledWhilePatterns(e,t).compile(e)}compileWhileAG(e,t,n,s){return this._getCachedCompiledWhilePatterns(e,t).compileAG(e,n,s)}_getCachedCompiledWhilePatterns(e,t){return this._cachedCompiledWhilePatterns||(this._cachedCompiledWhilePatterns=new ne,this._cachedCompiledWhilePatterns.push(this._while.hasBackReferences?this._while.clone():this._while)),this._while.hasBackReferences&&this._cachedCompiledWhilePatterns.setSource(0,t||""),this._cachedCompiledWhilePatterns}},ee=class e{static createCaptureRule(e,t,n,s,r){return e.registerRule(e=>new Q(t,e,n,s,r))}static getCompiledRuleId(t,n,s){return t.id||n.registerRule(r=>{if(t.id=r,t.match)return new Y(t.$vscodeTextmateLocation,t.id,t.name,t.match,e._compileCaptures(t.captures,n,s));if(void 0===t.begin){t.repository&&(s=a({},s,t.repository));let r=t.patterns;return void 0===r&&t.include&&(r=[{include:t.include}]),new V(t.$vscodeTextmateLocation,t.id,t.name,t.contentName,e._compilePatterns(r,n,s))}return t.while?new Z(t.$vscodeTextmateLocation,t.id,t.name,t.contentName,t.begin,e._compileCaptures(t.beginCaptures||t.captures,n,s),t.while,e._compileCaptures(t.whileCaptures||t.captures,n,s),e._compilePatterns(t.patterns,n,s)):new X(t.$vscodeTextmateLocation,t.id,t.name,t.contentName,t.begin,e._compileCaptures(t.beginCaptures||t.captures,n,s),t.end,e._compileCaptures(t.endCaptures||t.captures,n,s),t.applyEndPatternLast,e._compilePatterns(t.patterns,n,s))}),t.id}static _compileCaptures(t,n,s){let r=[];if(t){let o=0;for(const e in t){if("$vscodeTextmateLocation"===e)continue;const t=parseInt(e,10);t>o&&(o=t)}for(let e=0;e<=o;e++)r[e]=null;for(const i in t){if("$vscodeTextmateLocation"===i)continue;const o=parseInt(i,10);let a=0;t[i].patterns&&(a=e.getCompiledRuleId(t[i],n,s)),r[o]=e.createCaptureRule(n,t[i].$vscodeTextmateLocation,t[i].name,t[i].contentName,a)}}return r}static _compilePatterns(t,n,s){let r=[];if(t)for(let o=0,i=t.length;o<i;o++){const i=t[o];let a=-1;if(i.include){const t=z(i.include);switch(t.kind){case 0:case 1:a=e.getCompiledRuleId(s[i.include],n,s);break;case 2:let r=s[t.ruleName];r&&(a=e.getCompiledRuleId(r,n,s));break;case 3:case 4:const o=t.scopeName,c=4===t.kind?t.ruleName:null,l=n.getExternalGrammar(o,s);if(l)if(c){let t=l.repository[c];t&&(a=e.getCompiledRuleId(t,n,l.repository))}else a=e.getCompiledRuleId(l.repository.$self,n,l.repository)}}else a=e.getCompiledRuleId(i,n,s);if(-1!==a){const e=n.getRule(a);let t=!1;if((e instanceof V||e instanceof X||e instanceof Z)&&e.hasMissingPatterns&&0===e.patterns.length&&(t=!0),t)continue;r.push(a)}}return{patterns:r,hasMissingPatterns:(t?t.length:0)!==r.length}}},te=class e{constructor(e,t){if(s(this,"source"),s(this,"ruleId"),s(this,"hasAnchor"),s(this,"hasBackReferences"),s(this,"_anchorCache"),e&&"string"==typeof e){const t=e.length;let n=0,s=[],r=!1;for(let o=0;o<t;o++){if("\\"===e.charAt(o)&&o+1<t){const t=e.charAt(o+1);"z"===t?(s.push(e.substring(n,o)),s.push("$(?!\\n)(?<!\\n)"),n=o+2):"A"!==t&&"G"!==t||(r=!0),o++}}this.hasAnchor=r,0===n?this.source=e:(s.push(e.substring(n,t)),this.source=s.join(""))}else this.hasAnchor=!1,this.source=e;this.hasAnchor?this._anchorCache=this._buildAnchorCache():this._anchorCache=null,this.ruleId=t,"string"==typeof this.source?this.hasBackReferences=H.test(this.source):this.hasBackReferences=!1}clone(){return new e(this.source,this.ruleId)}setSource(e){this.source!==e&&(this.source=e,this.hasAnchor&&(this._anchorCache=this._buildAnchorCache()))}resolveBackReferences(e,t){if("string"!=typeof this.source)throw new Error("This method should only be called if the source is a string");let n=t.map(t=>e.substring(t.start,t.end));return K.lastIndex=0,this.source.replace(K,(e,t)=>f(n[parseInt(t,10)]||""))}_buildAnchorCache(){if("string"!=typeof this.source)throw new Error("This method should only be called if the source is a string");let e,t,n,s,r=[],o=[],i=[],a=[];for(e=0,t=this.source.length;e<t;e++)n=this.source.charAt(e),r[e]=n,o[e]=n,i[e]=n,a[e]=n,"\\"===n&&e+1<t&&(s=this.source.charAt(e+1),"A"===s?(r[e+1]="",o[e+1]="",i[e+1]="A",a[e+1]="A"):"G"===s?(r[e+1]="",o[e+1]="G",i[e+1]="",a[e+1]="G"):(r[e+1]=s,o[e+1]=s,i[e+1]=s,a[e+1]=s),e++);return{A0_G0:r.join(""),A0_G1:o.join(""),A1_G0:i.join(""),A1_G1:a.join("")}}resolveAnchors(e,t){return this.hasAnchor&&this._anchorCache&&"string"==typeof this.source?e?t?this._anchorCache.A1_G1:this._anchorCache.A1_G0:t?this._anchorCache.A0_G1:this._anchorCache.A0_G0:this.source}},ne=class{constructor(){s(this,"_items"),s(this,"_hasAnchors"),s(this,"_cached"),s(this,"_anchorCache"),this._items=[],this._hasAnchors=!1,this._cached=null,this._anchorCache={A0_G0:null,A0_G1:null,A1_G0:null,A1_G1:null}}dispose(){this._disposeCaches()}_disposeCaches(){this._cached&&(this._cached.dispose(),this._cached=null),this._anchorCache.A0_G0&&(this._anchorCache.A0_G0.dispose(),this._anchorCache.A0_G0=null),this._anchorCache.A0_G1&&(this._anchorCache.A0_G1.dispose(),this._anchorCache.A0_G1=null),this._anchorCache.A1_G0&&(this._anchorCache.A1_G0.dispose(),this._anchorCache.A1_G0=null),this._anchorCache.A1_G1&&(this._anchorCache.A1_G1.dispose(),this._anchorCache.A1_G1=null)}push(e){this._items.push(e),this._hasAnchors=this._hasAnchors||e.hasAnchor}unshift(e){this._items.unshift(e),this._hasAnchors=this._hasAnchors||e.hasAnchor}length(){return this._items.length}setSource(e,t){this._items[e].source!==t&&(this._disposeCaches(),this._items[e].setSource(t))}compile(e){if(!this._cached){let t=this._items.map(e=>e.source);this._cached=new se(e,t,this._items.map(e=>e.ruleId))}return this._cached}compileAG(e,t,n){return this._hasAnchors?t?n?(this._anchorCache.A1_G1||(this._anchorCache.A1_G1=this._resolveAnchors(e,t,n)),this._anchorCache.A1_G1):(this._anchorCache.A1_G0||(this._anchorCache.A1_G0=this._resolveAnchors(e,t,n)),this._anchorCache.A1_G0):n?(this._anchorCache.A0_G1||(this._anchorCache.A0_G1=this._resolveAnchors(e,t,n)),this._anchorCache.A0_G1):(this._anchorCache.A0_G0||(this._anchorCache.A0_G0=this._resolveAnchors(e,t,n)),this._anchorCache.A0_G0):this.compile(e)}_resolveAnchors(e,t,n){let s=this._items.map(e=>e.resolveAnchors(t,n));return new se(e,s,this._items.map(e=>e.ruleId))}},se=class{constructor(e,t,n){s(this,"scanner"),this.regExps=t,this.rules=n,this.scanner=e.createOnigScanner(t)}dispose(){"function"==typeof this.scanner.dispose&&this.scanner.dispose()}toString(){const e=[];for(let t=0,n=this.rules.length;t<n;t++)e.push(" - "+this.rules[t]+": "+this.regExps[t]);return e.join("\n")}findNextMatchSync(e,t,n){const s=this.scanner.findNextMatchSync(e,t,n);return s?{ruleId:this.rules[s.index],captureIndices:s.captureIndices}:null}},re=class{constructor(e,t){this.languageId=e,this.tokenType=t}},oe=(e=class{constructor(e,t){s(this,"_defaultAttributes"),s(this,"_embeddedLanguagesMatcher"),s(this,"_getBasicScopeAttributes",new m(e=>{const t=this._scopeToLanguage(e),n=this._toStandardTokenType(e);return new re(t,n)})),this._defaultAttributes=new re(e,8),this._embeddedLanguagesMatcher=new ie(Object.entries(t||{}))}getDefaultAttributes(){return this._defaultAttributes}getBasicScopeAttributes(t){return null===t?e._NULL_SCOPE_METADATA:this._getBasicScopeAttributes.get(t)}_scopeToLanguage(e){return this._embeddedLanguagesMatcher.match(e)||0}_toStandardTokenType(t){const n=t.match(e.STANDARD_TOKEN_TYPE_REGEXP);if(!n)return 8;switch(n[1]){case"comment":return 1;case"string":return 2;case"regex":return 3;case"meta.embedded":return 0}throw new Error("Unexpected match for standard token type!")}},s(e,"_NULL_SCOPE_METADATA",new re(0,0)),s(e,"STANDARD_TOKEN_TYPE_REGEXP",/\b(comment|string|regex|meta\.embedded)\b/),e),ie=class{constructor(e){if(s(this,"values"),s(this,"scopesRegExp"),0===e.length)this.values=null,this.scopesRegExp=null;else{this.values=new Map(e);const t=e.map(([e,t])=>f(e));t.sort(),t.reverse(),this.scopesRegExp=new RegExp(`^((${t.join(")|(")}))($|\\.)`,"")}}match(e){if(!this.scopesRegExp)return;const t=e.match(this.scopesRegExp);return t?this.values.get(t[1]):void 0}};"undefined"!=typeof process&&process.env.VSCODE_TEXTMATE_DEBUG;var ae=class{constructor(e,t){this.stack=e,this.stoppedEarly=t}};function ce(e,t,n,s,r,o,i,a){const c=t.content.length;let l=!1,u=-1;if(i){const i=function(e,t,n,s,r,o){let i=r.beginRuleCapturedEOL?0:-1;const a=[];for(let c=r;c;c=c.pop()){const t=c.getRule(e);t instanceof Z&&a.push({rule:t,stack:c})}for(let c=a.pop();c;c=a.pop()){const{ruleScanner:a,findOptions:l}=le(c.rule,e,c.stack.endRule,n,s===i),u=a.findNextMatchSync(t,s,l);if(!u){r=c.stack.pop();break}if(-2!==u.ruleId){r=c.stack.pop();break}u.captureIndices&&u.captureIndices.length&&(o.produce(c.stack,u.captureIndices[0].start),ue(e,t,n,c.stack,o,c.rule.whileCaptures,u.captureIndices),o.produce(c.stack,u.captureIndices[0].end),i=u.captureIndices[0].end,u.captureIndices[0].end>s&&(s=u.captureIndices[0].end,n=!1))}return{stack:r,linePos:s,anchorPosition:i,isFirstLine:n}}(e,t,n,s,r,o);r=i.stack,s=i.linePos,n=i.isFirstLine,u=i.anchorPosition}const p=Date.now();for(;!l;){if(0!==a){if(Date.now()-p>a)return new ae(r,!0)}d()}return new ae(r,!1);function d(){const i=function(e,t,n,s,r,o){const i=function(e,t,n,s,r,o){const i=r.getRule(e),{ruleScanner:a,findOptions:c}=he(i,e,r.endRule,n,s===o),l=a.findNextMatchSync(t,s,c);if(l)return{captureIndices:l.captureIndices,matchedRuleId:l.ruleId};return null}(e,t,n,s,r,o),a=e.getInjections();if(0===a.length)return i;const c=function(e,t,n,s,r,o,i){let a,c=Number.MAX_VALUE,l=null,u=0;const p=o.contentNameScopesList.getScopeNames();for(let d=0,g=e.length;d<g;d++){const o=e[d];if(!o.matcher(p))continue;const g=t.getRule(o.ruleId),{ruleScanner:f,findOptions:m}=he(g,t,null,s,r===i),_=f.findNextMatchSync(n,r,m);if(!_)continue;const y=_.captureIndices[0].start;if(!(y>=c)&&(c=y,l=_.captureIndices,a=_.ruleId,u=o.priority,c===r))break}if(l)return{priorityMatch:-1===u,captureIndices:l,matchedRuleId:a};return null}(a,e,t,n,s,r,o);if(!c)return i;if(!i)return c;const l=i.captureIndices[0].start,u=c.captureIndices[0].start;if(u<l||c.priorityMatch&&u===l)return c;return i}(e,t,n,s,r,u);if(!i)return o.produce(r,c),void(l=!0);const a=i.captureIndices,p=i.matchedRuleId,d=!!(a&&a.length>0)&&a[0].end>s;if(-1===p){const i=r.getRule(e);o.produce(r,a[0].start),r=r.withContentNameScopesList(r.nameScopesList),ue(e,t,n,r,o,i.endCaptures,a),o.produce(r,a[0].end);const p=r;if(r=r.parent,u=p.getAnchorPos(),!d&&p.getEnterPos()===s)return r=p,o.produce(r,c),void(l=!0)}else{const i=e.getRule(p);o.produce(r,a[0].start);const g=r,f=i.getName(t.content,a),m=r.contentNameScopesList.pushAttributed(f,e);if(r=r.push(p,s,u,a[0].end===c,null,m,m),i instanceof X){const s=i;ue(e,t,n,r,o,s.beginCaptures,a),o.produce(r,a[0].end),u=a[0].end;const p=s.getContentName(t.content,a),f=m.pushAttributed(p,e);if(r=r.withContentNameScopesList(f),s.endHasBackReferences&&(r=r.withEndRule(s.getEndWithResolvedBackReferences(t.content,a))),!d&&g.hasSameRuleAs(r))return r=r.pop(),o.produce(r,c),void(l=!0)}else if(i instanceof Z){const s=i;ue(e,t,n,r,o,s.beginCaptures,a),o.produce(r,a[0].end),u=a[0].end;const p=s.getContentName(t.content,a),f=m.pushAttributed(p,e);if(r=r.withContentNameScopesList(f),s.whileHasBackReferences&&(r=r.withEndRule(s.getWhileWithResolvedBackReferences(t.content,a))),!d&&g.hasSameRuleAs(r))return r=r.pop(),o.produce(r,c),void(l=!0)}else{if(ue(e,t,n,r,o,i.captures,a),o.produce(r,a[0].end),r=r.pop(),!d)return r=r.safePop(),o.produce(r,c),void(l=!0)}}a[0].end>s&&(s=a[0].end,n=!1)}}function he(e,t,n,s,r){return{ruleScanner:e.compileAG(t,n,s,r),findOptions:0}}function le(e,t,n,s,r){return{ruleScanner:e.compileWhileAG(t,n,s,r),findOptions:0}}function ue(e,t,n,s,r,o,i){if(0===o.length)return;const a=t.content,c=Math.min(o.length,i.length),l=[],u=i[0].end;for(let p=0;p<c;p++){const t=o[p];if(null===t)continue;const c=i[p];if(0===c.length)continue;if(c.start>u)break;for(;l.length>0&&l[l.length-1].endPos<=c.start;)r.produceFromScopes(l[l.length-1].scopes,l[l.length-1].endPos),l.pop();if(l.length>0?r.produceFromScopes(l[l.length-1].scopes,c.start):r.produce(s,c.start),t.retokenizeCapturedWithRuleId){const o=t.getName(a,i),l=s.contentNameScopesList.pushAttributed(o,e),u=t.getContentName(a,i),p=l.pushAttributed(u,e),d=s.push(t.retokenizeCapturedWithRuleId,c.start,-1,!1,null,l,p),g=e.createOnigString(a.substring(0,c.end));ce(e,g,n&&0===c.start,c.start,d,r,!1,0),L(g);continue}const d=t.getName(a,i);if(null!==d){const t=(l.length>0?l[l.length-1].scopes:s.contentNameScopesList).pushAttributed(d,e);l.push(new pe(t,c.end))}}for(;l.length>0;)r.produceFromScopes(l[l.length-1].scopes,l[l.length-1].endPos),l.pop()}var pe=class{constructor(e,t){s(this,"scopes"),s(this,"endPos"),this.scopes=e,this.endPos=t}};function de(e,t,n,s,r){const o=R(t,ge),i=ee.getCompiledRuleId(n,s,r.repository);for(const a of o)e.push({debugSelector:t,matcher:a.matcher,ruleId:i,grammar:r,priority:a.priority})}function ge(e,t){if(t.length<e.length)return!1;let n=0;return e.every(e=>{for(let s=n;s<t.length;s++)if(fe(t[s],e))return n=s+1,!0;return!1})}function fe(e,t){if(!e)return!1;if(e===t)return!0;const n=t.length;return e.length>n&&e.substr(0,n)===t&&"."===e[n]}var me=class{constructor(e,t,n,r,o,i,a,c){if(s(this,"_rootId"),s(this,"_lastRuleId"),s(this,"_ruleId2desc"),s(this,"_includedGrammars"),s(this,"_grammarRepository"),s(this,"_grammar"),s(this,"_injections"),s(this,"_basicScopeAttributesProvider"),s(this,"_tokenTypeMatchers"),this._rootScopeName=e,this.balancedBracketSelectors=i,this._onigLib=c,this._basicScopeAttributesProvider=new oe(n,r),this._rootId=-1,this._lastRuleId=0,this._ruleId2desc=[null],this._includedGrammars={},this._grammarRepository=a,this._grammar=_e(t,null),this._injections=null,this._tokenTypeMatchers=[],o)for(const s of Object.keys(o)){const e=R(s,ge);for(const t of e)this._tokenTypeMatchers.push({matcher:t.matcher,type:o[s]})}}get themeProvider(){return this._grammarRepository}dispose(){for(const e of this._ruleId2desc)e&&e.dispose()}createOnigScanner(e){return this._onigLib.createOnigScanner(e)}createOnigString(e){return this._onigLib.createOnigString(e)}getMetadataForScope(e){return this._basicScopeAttributesProvider.getBasicScopeAttributes(e)}_collectInjections(){const e=e=>e===this._rootScopeName?this._grammar:this.getExternalGrammar(e),t=[],n=this._rootScopeName,s=e(n);if(s){const e=s.injections;if(e)for(let n in e)de(t,n,e[n],this,s);const r=this._grammarRepository.injections(n);r&&r.forEach(e=>{const n=this.getExternalGrammar(e);if(n){const e=n.injectionSelector;e&&de(t,e,n,this,n)}})}return t.sort((e,t)=>e.priority-t.priority),t}getInjections(){return null===this._injections&&(this._injections=this._collectInjections()),this._injections}registerRule(e){const t=++this._lastRuleId,n=e(t);return this._ruleId2desc[t]=n,n}getRule(e){return this._ruleId2desc[e]}getExternalGrammar(e,t){if(this._includedGrammars[e])return this._includedGrammars[e];if(this._grammarRepository){const n=this._grammarRepository.lookup(e);if(n)return this._includedGrammars[e]=_e(n,t&&t.$base),this._includedGrammars[e]}}tokenizeLine(e,t,n=0){const s=this._tokenize(e,t,!1,n);return{tokens:s.lineTokens.getResult(s.ruleStack,s.lineLength),ruleStack:s.ruleStack,stoppedEarly:s.stoppedEarly}}tokenizeLine2(e,t,n=0){const s=this._tokenize(e,t,!0,n);return{tokens:s.lineTokens.getBinaryResult(s.ruleStack,s.lineLength),ruleStack:s.ruleStack,stoppedEarly:s.stoppedEarly}}_tokenize(e,t,n,s){let r;if(-1===this._rootId&&(this._rootId=ee.getCompiledRuleId(this._grammar.repository.$self,this,this._grammar.repository),this.getInjections()),t&&t!==be.NULL)r=!1,t.reset();else{r=!0;const e=this._basicScopeAttributesProvider.getDefaultAttributes(),n=this.themeProvider.getDefaults(),s=P.set(0,e.languageId,e.tokenType,null,n.fontStyle,n.foregroundId,n.backgroundId),o=this.getRule(this._rootId).getName(null,null);let i;i=o?ye.createRootAndLookUpScopeName(o,s,this):ye.createRoot("unknown",s),t=new be(null,this._rootId,-1,-1,!1,null,i,i)}e+="\n";const o=this.createOnigString(e),i=o.content.length,a=new Se(n,e,this._tokenTypeMatchers,this.balancedBracketSelectors),c=ce(this,o,r,0,t,a,!0,s);return L(o),{lineLength:i,lineTokens:a,ruleStack:c.stack,stoppedEarly:c.stoppedEarly}}};function _e(e,t){return(e=i(e)).repository=e.repository||{},e.repository.$self={$vscodeTextmateLocation:e.$vscodeTextmateLocation,patterns:e.patterns,name:e.scopeName},e.repository.$base=t||e.repository.$self,e}var ye=class e{constructor(e,t,n){this.parent=e,this.scopePath=t,this.tokenAttributes=n}static fromExtension(t,n){let s=t,r=t?.scopePath??null;for(const o of n)r=y.push(r,o.scopeNames),s=new e(s,r,o.encodedTokenAttributes);return s}static createRoot(t,n){return new e(null,new y(null,t),n)}static createRootAndLookUpScopeName(t,n,s){const r=s.getMetadataForScope(t),o=new y(null,t),i=s.themeProvider.themeMatch(o),a=e.mergeAttributes(n,r,i);return new e(null,o,a)}get scopeName(){return this.scopePath.scopeName}toString(){return this.getScopeNames().join(" ")}equals(t){return e.equals(this,t)}static equals(e,t){for(;;){if(e===t)return!0;if(!e&&!t)return!0;if(!e||!t)return!1;if(e.scopeName!==t.scopeName||e.tokenAttributes!==t.tokenAttributes)return!1;e=e.parent,t=t.parent}}static mergeAttributes(e,t,n){let s=-1,r=0,o=0;return null!==n&&(s=n.fontStyle,r=n.foregroundId,o=n.backgroundId),P.set(e,t.languageId,t.tokenType,null,s,r,o)}pushAttributed(t,n){if(null===t)return this;if(-1===t.indexOf(" "))return e._pushAttributed(this,t,n);const s=t.split(/ /g);let r=this;for(const o of s)r=e._pushAttributed(r,o,n);return r}static _pushAttributed(t,n,s){const r=s.getMetadataForScope(n),o=t.scopePath.push(n),i=s.themeProvider.themeMatch(o),a=e.mergeAttributes(t.tokenAttributes,r,i);return new e(t,o,a)}getScopeNames(){return this.scopePath.getSegments()}getExtensionIfDefined(e){const t=[];let n=this;for(;n&&n!==e;)t.push({encodedTokenAttributes:n.tokenAttributes,scopeNames:n.scopePath.getExtensionIfDefined(n.parent?.scopePath??null)}),n=n.parent;return n===e?t.reverse():void 0}},be=(t=class{constructor(e,t,n,r,o,i,a,c){s(this,"_stackElementBrand"),s(this,"_enterPos"),s(this,"_anchorPos"),s(this,"depth"),this.parent=e,this.ruleId=t,this.beginRuleCapturedEOL=o,this.endRule=i,this.nameScopesList=a,this.contentNameScopesList=c,this.depth=this.parent?this.parent.depth+1:1,this._enterPos=n,this._anchorPos=r}equals(e){return null!==e&&t._equals(this,e)}static _equals(e,t){return e===t||!!this._structuralEquals(e,t)&&ye.equals(e.contentNameScopesList,t.contentNameScopesList)}static _structuralEquals(e,t){for(;;){if(e===t)return!0;if(!e&&!t)return!0;if(!e||!t)return!1;if(e.depth!==t.depth||e.ruleId!==t.ruleId||e.endRule!==t.endRule)return!1;e=e.parent,t=t.parent}}clone(){return this}static _reset(e){for(;e;)e._enterPos=-1,e._anchorPos=-1,e=e.parent}reset(){t._reset(this)}pop(){return this.parent}safePop(){return this.parent?this.parent:this}push(e,n,s,r,o,i,a){return new t(this,e,n,s,r,o,i,a)}getEnterPos(){return this._enterPos}getAnchorPos(){return this._anchorPos}getRule(e){return e.getRule(this.ruleId)}toString(){const e=[];return this._writeString(e,0),"["+e.join(",")+"]"}_writeString(e,t){return this.parent&&(t=this.parent._writeString(e,t)),e[t++]=`(${this.ruleId}, ${this.nameScopesList?.toString()}, ${this.contentNameScopesList?.toString()})`,t}withContentNameScopesList(e){return this.contentNameScopesList===e?this:this.parent.push(this.ruleId,this._enterPos,this._anchorPos,this.beginRuleCapturedEOL,this.endRule,this.nameScopesList,e)}withEndRule(e){return this.endRule===e?this:new t(this.parent,this.ruleId,this._enterPos,this._anchorPos,this.beginRuleCapturedEOL,e,this.nameScopesList,this.contentNameScopesList)}hasSameRuleAs(e){let t=this;for(;t&&t._enterPos===e._enterPos;){if(t.ruleId===e.ruleId)return!0;t=t.parent}return!1}toStateStackFrame(){return{ruleId:this.ruleId,beginRuleCapturedEOL:this.beginRuleCapturedEOL,endRule:this.endRule,nameScopesList:this.nameScopesList?.getExtensionIfDefined(this.parent?.nameScopesList??null)??[],contentNameScopesList:this.contentNameScopesList?.getExtensionIfDefined(this.nameScopesList)??[]}}static pushFrame(e,n){const s=ye.fromExtension(e?.nameScopesList??null,n.nameScopesList);return new t(e,n.ruleId,n.enterPos??-1,n.anchorPos??-1,n.beginRuleCapturedEOL,n.endRule,s,ye.fromExtension(s,n.contentNameScopesList))}},s(t,"NULL",new t(null,0,0,0,!1,null,null,null)),t),ke=class{constructor(e,t){s(this,"balancedBracketScopes"),s(this,"unbalancedBracketScopes"),s(this,"allowAny",!1),this.balancedBracketScopes=e.flatMap(e=>"*"===e?(this.allowAny=!0,[]):R(e,ge).map(e=>e.matcher)),this.unbalancedBracketScopes=t.flatMap(e=>R(e,ge).map(e=>e.matcher))}get matchesAlways(){return this.allowAny&&0===this.unbalancedBracketScopes.length}get matchesNever(){return 0===this.balancedBracketScopes.length&&!this.allowAny}match(e){for(const t of this.unbalancedBracketScopes)if(t(e))return!1;for(const t of this.balancedBracketScopes)if(t(e))return!0;return this.allowAny}},Se=class{constructor(e,t,n,r){s(this,"_emitBinaryTokens"),s(this,"_lineText"),s(this,"_tokens"),s(this,"_binaryTokens"),s(this,"_lastTokenEndIndex"),s(this,"_tokenTypeOverrides"),this.balancedBracketSelectors=r,this._emitBinaryTokens=e,this._tokenTypeOverrides=n,this._lineText=null,this._tokens=[],this._binaryTokens=[],this._lastTokenEndIndex=0}produce(e,t){this.produceFromScopes(e.contentNameScopesList,t)}produceFromScopes(e,t){if(this._lastTokenEndIndex>=t)return;if(this._emitBinaryTokens){let n=e?.tokenAttributes??0,s=!1;if(this.balancedBracketSelectors?.matchesAlways&&(s=!0),this._tokenTypeOverrides.length>0||this.balancedBracketSelectors&&!this.balancedBracketSelectors.matchesAlways&&!this.balancedBracketSelectors.matchesNever){const t=e?.getScopeNames()??[];for(const e of this._tokenTypeOverrides)e.matcher(t)&&(n=P.set(n,0,I(e.type),null,-1,0,0));this.balancedBracketSelectors&&(s=this.balancedBracketSelectors.match(t))}return s&&(n=P.set(n,0,8,s,-1,0,0)),this._binaryTokens.length>0&&this._binaryTokens[this._binaryTokens.length-1]===n?void(this._lastTokenEndIndex=t):(this._binaryTokens.push(this._lastTokenEndIndex),this._binaryTokens.push(n),void(this._lastTokenEndIndex=t))}const n=e?.getScopeNames()??[];this._tokens.push({startIndex:this._lastTokenEndIndex,endIndex:t,scopes:n}),this._lastTokenEndIndex=t}getResult(e,t){return this._tokens.length>0&&this._tokens[this._tokens.length-1].startIndex===t-1&&this._tokens.pop(),0===this._tokens.length&&(this._lastTokenEndIndex=-1,this.produce(e,t),this._tokens[this._tokens.length-1].startIndex=0),this._tokens}getBinaryResult(e,t){this._binaryTokens.length>0&&this._binaryTokens[this._binaryTokens.length-2]===t-1&&(this._binaryTokens.pop(),this._binaryTokens.pop()),0===this._binaryTokens.length&&(this._lastTokenEndIndex=-1,this.produce(e,t),this._binaryTokens[this._binaryTokens.length-2]=0);const n=new Uint32Array(this._binaryTokens.length);for(let s=0,r=this._binaryTokens.length;s<r;s++)n[s]=this._binaryTokens[s];return n}},we=class{constructor(e,t){s(this,"_grammars",/* @__PURE__ */new Map),s(this,"_rawGrammars",/* @__PURE__ */new Map),s(this,"_injectionGrammars",/* @__PURE__ */new Map),s(this,"_theme"),this._onigLib=t,this._theme=e}dispose(){for(const e of this._grammars.values())e.dispose()}setTheme(e){this._theme=e}getColorMap(){return this._theme.getColorMap()}addGrammar(e,t){this._rawGrammars.set(e.scopeName,e),t&&this._injectionGrammars.set(e.scopeName,t)}lookup(e){return this._rawGrammars.get(e)}injections(e){return this._injectionGrammars.get(e)}getDefaults(){return this._theme.getDefaults()}themeMatch(e){return this._theme.match(e)}grammarForScopeName(e,t,n,s,r){if(!this._grammars.has(e)){let o=this._rawGrammars.get(e);if(!o)return null;this._grammars.set(e,function(e,t,n,s,r,o,i,a){return new me(e,t,n,s,r,o,i,a)}(e,o,t,n,s,r,this,this._onigLib))}return this._grammars.get(e)}},Ce=class{constructor(e){s(this,"_options"),s(this,"_syncRegistry"),s(this,"_ensureGrammarCache"),this._options=e,this._syncRegistry=new we(_.createFromRawTheme(e.theme,e.colorMap),e.onigLib),this._ensureGrammarCache=/* @__PURE__ */new Map}dispose(){this._syncRegistry.dispose()}setTheme(e,t){this._syncRegistry.setTheme(_.createFromRawTheme(e,t))}getColorMap(){return this._syncRegistry.getColorMap()}loadGrammarWithEmbeddedLanguages(e,t,n){return this.loadGrammarWithConfiguration(e,t,{embeddedLanguages:n})}loadGrammarWithConfiguration(e,t,n){return this._loadGrammar(e,t,n.embeddedLanguages,n.tokenTypes,new ke(n.balancedBracketSelectors||[],n.unbalancedBracketSelectors||[]))}loadGrammar(e){return this._loadGrammar(e,0,null,null,null)}_loadGrammar(e,t,n,s,r){const o=new $(this._syncRegistry,e);for(;o.Q.length>0;)o.Q.map(e=>this._loadSingleGrammar(e.scopeName)),o.processQueue();return this._grammarForScopeName(e,t,n,s,r)}_loadSingleGrammar(e){this._ensureGrammarCache.has(e)||(this._doLoadSingleGrammar(e),this._ensureGrammarCache.set(e,!0))}_doLoadSingleGrammar(e){const t=this._options.loadGrammar(e);if(t){const n="function"==typeof this._options.getInjections?this._options.getInjections(e):void 0;this._syncRegistry.addGrammar(t,n)}}addGrammar(e,t=[],n=0,s=null){return this._syncRegistry.addGrammar(e,t),this._grammarForScopeName(e.scopeName,n,s)}_grammarForScopeName(e,t=0,n=null,s=null,r=null){return this._syncRegistry.grammarForScopeName(e,t,n,s,r)}},Ne=be.NULL;function Ae(e,t){const n="string"==typeof e?{}:{...e.colorReplacements},s="string"==typeof e?e:e.name;for(const[r,o]of Object.entries(t?.colorReplacements||{}))"string"==typeof o?n[r]=o:r===s&&Object.assign(n,o);return n}function ve(e,t){return e&&t?.[e?.toLowerCase()]||e}function Pe(e){return Array.isArray(e)?e:[e]}async function Ie(e){return Promise.resolve("function"==typeof e?e():e).then(e=>e.default||e)}function Re(e){return!e||["plaintext","txt","text","plain"].includes(e)}function Te(e){return"ansi"===e||Re(e)}function Le(e){return"none"===e}function xe(e){return Le(e)}function Ge(e,t){var n;if(!t)return e;e.properties||(e.properties={}),(n=e.properties).class||(n.class=[]),"string"==typeof e.properties.class&&(e.properties.class=e.properties.class.split(/\s+/g)),Array.isArray(e.properties.class)||(e.properties.class=[]);const s=Array.isArray(t)?t:t.split(/\s+/g);for(const r of s)r&&!e.properties.class.includes(r)&&e.properties.class.push(r);return e}function Ee(e,t=!1){if(0===e.length)return[["",0]];const n=e.split(/(\r?\n)/g);let s=0;const r=[];for(let o=0;o<n.length;o+=2){const e=t?n[o]+(n[o+1]||""):n[o];r.push([e,s]),s+=n[o].length,s+=n[o+1]?.length||0}return r}function $e(e){const t=Ee(e,!0).map(([e])=>e);return{lines:t,indexToPos:function(n){if(n===e.length)return{line:t.length-1,character:t[t.length-1].length};let s=n,r=0;for(const e of t){if(s<e.length)break;s-=e.length,r++}return{line:r,character:s}},posToIndex:function(e,n){let s=0;for(let r=0;r<e;r++)s+=t[r].length;return s+=n,s}}}const Be="light-dark()",Me=["color","background-color"];function Oe(e,t){let n=0;const s=[];for(const r of t)r>n&&s.push({...e,content:e.content.slice(n,r),offset:e.offset+n}),n=r;return n<e.content.length&&s.push({...e,content:e.content.slice(n),offset:e.offset+n}),s}function je(e,t){const n=Array.from(t instanceof Set?t:new Set(t)).sort((e,t)=>e-t);return n.length?e.map(e=>e.flatMap(e=>{const t=n.filter(t=>e.offset<t&&t<e.offset+e.content.length).map(t=>t-e.offset).sort((e,t)=>e-t);return t.length?Oe(e,t):e})):e}function Fe(e,t,n,s,r="css-vars"){const i={content:e.content,explanation:e.explanation,offset:e.offset},a=t.map(t=>We(e.variants[t])),c=new Set(a.flatMap(e=>Object.keys(e))),l={},u=(e,s)=>{const r="color"===s?"":"background-color"===s?"-bg":`-${s}`;return n+t[e]+("color"===s?"":r)};return a.forEach((e,n)=>{for(const i of c){const c=e[i]||"inherit";if(0===n&&s&&Me.includes(i))if(s===Be&&a.length>1){const e=t.findIndex(e=>"light"===e),s=t.findIndex(e=>"dark"===e);if(-1===e||-1===s)throw new o('When using `defaultColor: "light-dark()"`, you must provide both `light` and `dark` themes');const p=a[e][i]||"inherit",d=a[s][i]||"inherit";l[i]=`light-dark(${p}, ${d})`,"css-vars"===r&&(l[u(n,i)]=c)}else l[i]=c;else"css-vars"===r&&(l[u(n,i)]=c)}}),i.htmlStyle=l,i}function We(e){const t={};if(e.color&&(t.color=e.color),e.bgColor&&(t["background-color"]=e.bgColor),e.fontStyle){e.fontStyle&w.Italic&&(t["font-style"]="italic"),e.fontStyle&w.Bold&&(t["font-weight"]="bold");const n=[];e.fontStyle&w.Underline&&n.push("underline"),e.fontStyle&w.Strikethrough&&n.push("line-through"),n.length&&(t["text-decoration"]=n.join(" "))}return t}function De(e){return"string"==typeof e?e:Object.entries(e).map(([e,t])=>`${e}:${t}`).join(";")}const qe=/* @__PURE__ */new WeakMap;function Ue(e,t){qe.set(e,t)}function ze(e){return qe.get(e)}class He{constructor(...e){if(s(this,"_stacks",{}),s(this,"lang"),2===e.length){const[t,n]=e;this.lang=n,this._stacks=t}else{const[t,n,s]=e;this.lang=n,this._stacks={[s]:t}}}get themes(){return Object.keys(this._stacks)}get theme(){return this.themes[0]}get _stack(){return this._stacks[this.theme]}static initial(e,t){return new He(Object.fromEntries(Pe(t).map(e=>[e,Ne])),e)}getInternalStack(e=this.theme){return this._stacks[e]}getScopes(e=this.theme){return function(e){const t=[],n=/* @__PURE__ */new Set;function s(e){if(n.has(e))return;n.add(e);const r=e?.nameScopesList?.scopeName;r&&t.push(r),e.parent&&s(e.parent)}return s(e),t}(this._stacks[e])}toJSON(){return{lang:this.lang,theme:this.theme,themes:this.themes,scopes:this.getScopes()}}}function Ke(){const e=/* @__PURE__ */new WeakMap;function t(t){if(!e.has(t.meta)){let n=function(e){if("number"==typeof e){if(e<0||e>t.source.length)throw new o(`Invalid decoration offset: ${e}. Code length: ${t.source.length}`);return{...s.indexToPos(e),offset:e}}{const t=s.lines[e.line];if(void 0===t)throw new o(`Invalid decoration position ${JSON.stringify(e)}. Lines length: ${s.lines.length}`);let n=e.character;if(n<0&&(n=t.length+n),n<0||n>t.length)throw new o(`Invalid decoration position ${JSON.stringify(e)}. Line ${e.line} length: ${t.length}`);return{...e,character:n,offset:s.posToIndex(e.line,n)}}};const s=$e(t.source),r=(t.options.decorations||[]).map(e=>({...e,start:n(e.start),end:n(e.end)}));!function(e){for(let t=0;t<e.length;t++){const n=e[t];if(n.start.offset>n.end.offset)throw new o(`Invalid decoration range: ${JSON.stringify(n.start)} - ${JSON.stringify(n.end)}`);for(let s=t+1;s<e.length;s++){const t=e[s],r=n.start.offset<=t.start.offset&&t.start.offset<n.end.offset,i=n.start.offset<t.end.offset&&t.end.offset<=n.end.offset,a=t.start.offset<=n.start.offset&&n.start.offset<t.end.offset,c=t.start.offset<n.end.offset&&n.end.offset<=t.end.offset;if(r||i||a||c){if(r&&i)continue;if(a&&c)continue;if(a&&n.start.offset===n.end.offset)continue;if(i&&t.start.offset===t.end.offset)continue;throw new o(`Decorations ${JSON.stringify(n.start)} and ${JSON.stringify(t.start)} intersect.`)}}}}(r),e.set(t.meta,{decorations:r,converter:s,source:t.source})}return e.get(t.meta)}return{name:"shiki:decorations",tokens(e){if(!this.options.decorations?.length)return;return je(e,t(this).decorations.flatMap(e=>[e.start.offset,e.end.offset]))},code(e){if(!this.options.decorations?.length)return;const n=t(this),s=Array.from(e.children).filter(e=>"element"===e.type&&"span"===e.tagName);if(s.length!==n.converter.lines.length)throw new o(`Number of lines in code element (${s.length}) does not match the number of lines in the source (${n.converter.lines.length}). Failed to apply decorations.`);function r(e,t,n,r){const i=s[e];let c="",l=-1,u=-1;if(0===t&&(l=0),0===n&&(u=0),n===Number.POSITIVE_INFINITY&&(u=i.children.length),-1===l||-1===u)for(let s=0;s<i.children.length;s++)c+=Je(i.children[s]),-1===l&&c.length===t&&(l=s+1),-1===u&&c.length===n&&(u=s+1);if(-1===l)throw new o(`Failed to find start index for decoration ${JSON.stringify(r.start)}`);if(-1===u)throw new o(`Failed to find end index for decoration ${JSON.stringify(r.end)}`);const p=i.children.slice(l,u);if(r.alwaysWrap||p.length!==i.children.length)if(r.alwaysWrap||1!==p.length||"element"!==p[0].type){const e={type:"element",tagName:"span",properties:{},children:p};a(e,r,"wrapper"),i.children.splice(l,p.length,e)}else a(p[0],r,"token");else a(i,r,"line")}function i(e,t){s[e]=a(s[e],t,"line")}function a(e,t,n){const s=t.properties||{},r=t.transform||(e=>e);return e.tagName=t.tagName||"span",e.properties={...e.properties,...s,class:e.properties.class},t.properties?.class&&Ge(e,t.properties.class),e=r(e,n)||e}const c=[],l=n.decorations.sort((e,t)=>t.start.offset-e.start.offset||e.end.offset-t.end.offset);for(const t of l){const{start:e,end:n}=t;if(e.line===n.line)r(e.line,e.character,n.character,t);else if(e.line<n.line){r(e.line,e.character,Number.POSITIVE_INFINITY,t);for(let s=e.line+1;s<n.line;s++)c.unshift(()=>i(s,t));r(n.line,0,n.character,t)}}c.forEach(e=>e())}}}function Je(e){return"text"===e.type?e.value:"element"===e.type?e.children.map(Je).join(""):""}const Qe=[
|
|
2
|
-
/* @__PURE__ */Ke()];function Ye(e){const t=function(e){const t=[],n=[],s=[];for(const r of e)switch(r.enforce){case"pre":t.push(r);break;case"post":n.push(r);break;default:s.push(r)}return{pre:t,post:n,normal:s}}(e.transformers||[]);return[...t.pre,...t.normal,...t.post,...Qe]}var Ve=["black","red","green","yellow","blue","magenta","cyan","white","brightBlack","brightRed","brightGreen","brightYellow","brightBlue","brightMagenta","brightCyan","brightWhite"],Xe={1:"bold",2:"dim",3:"italic",4:"underline",7:"reverse",8:"hidden",9:"strikethrough"};function Ze(e,t){const n=e.indexOf("",t);if(-1!==n&&"["===e[n+1]){const t=e.indexOf("m",n);if(-1!==t)return{sequence:e.substring(n+2,t).split(";"),startPosition:n,position:t+1}}return{position:e.length}}function et(e){const t=e.shift();if("2"===t){const t=e.splice(0,3).map(e=>Number.parseInt(e));if(3!==t.length||t.some(e=>Number.isNaN(e)))return;return{type:"rgb",rgb:t}}if("5"===t){const t=e.shift();if(t)return{type:"table",index:Number(t)}}}function tt(e){const t=[];for(;e.length>0;){const n=e.shift();if(!n)continue;const s=Number.parseInt(n);if(!Number.isNaN(s))if(0===s)t.push({type:"resetAll"});else if(s<=9){Xe[s]&&t.push({type:"setDecoration",value:Xe[s]})}else if(s<=29){const e=Xe[s-20];e&&(t.push({type:"resetDecoration",value:e}),"dim"===e&&t.push({type:"resetDecoration",value:"bold"}))}else if(s<=37)t.push({type:"setForegroundColor",value:{type:"named",name:Ve[s-30]}});else if(38===s){const n=et(e);n&&t.push({type:"setForegroundColor",value:n})}else if(39===s)t.push({type:"resetForegroundColor"});else if(s<=47)t.push({type:"setBackgroundColor",value:{type:"named",name:Ve[s-40]}});else if(48===s){const n=et(e);n&&t.push({type:"setBackgroundColor",value:n})}else 49===s?t.push({type:"resetBackgroundColor"}):53===s?t.push({type:"setDecoration",value:"overline"}):55===s?t.push({type:"resetDecoration",value:"overline"}):s>=90&&s<=97?t.push({type:"setForegroundColor",value:{type:"named",name:Ve[s-90+8]}}):s>=100&&s<=107&&t.push({type:"setBackgroundColor",value:{type:"named",name:Ve[s-100+8]}})}return t}var nt={black:"#000000",red:"#bb0000",green:"#00bb00",yellow:"#bbbb00",blue:"#0000bb",magenta:"#ff00ff",cyan:"#00bbbb",white:"#eeeeee",brightBlack:"#555555",brightRed:"#ff5555",brightGreen:"#00ff00",brightYellow:"#ffff55",brightBlue:"#5555ff",brightMagenta:"#ff55ff",brightCyan:"#55ffff",brightWhite:"#ffffff"};function st(e=nt){function t(t){return e[t]}function n(e){return`#${e.map(e=>Math.max(0,Math.min(e,255)).toString(16).padStart(2,"0")).join("")}`}let s;function r(e){return function(){if(s)return s;s=[];for(let n=0;n<Ve.length;n++)s.push(t(Ve[n]));let e=[0,95,135,175,215,255];for(let t=0;t<6;t++)for(let r=0;r<6;r++)for(let o=0;o<6;o++)s.push(n([e[t],e[r],e[o]]));let r=8;for(let t=0;t<24;t++,r+=10)s.push(n([r,r,r]));return s}()[e]}return{value:function(e){switch(e.type){case"named":return t(e.name);case"rgb":return n(e.rgb);case"table":return r(e.index)}}}}const rt={black:"#000000",red:"#cd3131",green:"#0DBC79",yellow:"#E5E510",blue:"#2472C8",magenta:"#BC3FBC",cyan:"#11A8CD",white:"#E5E5E5",brightBlack:"#666666",brightRed:"#F14C4C",brightGreen:"#23D18B",brightYellow:"#F5F543",brightBlue:"#3B8EEA",brightMagenta:"#D670D6",brightCyan:"#29B8DB",brightWhite:"#FFFFFF"};function ot(e,t,n){const s=Ae(e,n),r=Ee(t),o=st(Object.fromEntries(Ve.map(t=>{const n=`terminal.ansi${t[0].toUpperCase()}${t.substring(1)}`,s=e.colors?.[n];return[t,s||rt[t]]}))),i=function(){let e=null,t=null,n=/* @__PURE__ */new Set;return{parse(s){const r=[];let o=0;do{const i=Ze(s,o),a=i.sequence?s.substring(o,i.startPosition):s.substring(o);if(a.length>0&&r.push({value:a,foreground:e,background:t,decorations:new Set(n)}),i.sequence){const s=tt(i.sequence);for(const r of s)"resetAll"===r.type?(e=null,t=null,n.clear()):"resetForegroundColor"===r.type?e=null:"resetBackgroundColor"===r.type?t=null:"resetDecoration"===r.type&&n.delete(r.value);for(const r of s)"setForegroundColor"===r.type?e=r.value:"setBackgroundColor"===r.type?t=r.value:"setDecoration"===r.type&&n.add(r.value)}o=i.position}while(o<s.length);return r}}}();return r.map(t=>i.parse(t[0]).map(n=>{let r,i;n.decorations.has("reverse")?(r=n.background?o.value(n.background):e.bg,i=n.foreground?o.value(n.foreground):e.fg):(r=n.foreground?o.value(n.foreground):e.fg,i=n.background?o.value(n.background):void 0),r=ve(r,s),i=ve(i,s),n.decorations.has("dim")&&(r=function(e){const t=e.match(/#([0-9a-f]{3,8})/i);if(t){const e=t[1];if(8===e.length){const t=Math.round(Number.parseInt(e.slice(6,8),16)/2).toString(16).padStart(2,"0");return`#${e.slice(0,6)}${t}`}if(6===e.length)return`#${e}80`;if(4===e.length){const t=e[0],n=e[1],s=e[2],r=e[3];return`#${t}${t}${n}${n}${s}${s}${Math.round(Number.parseInt(`${r}${r}`,16)/2).toString(16).padStart(2,"0")}`}if(3===e.length){const t=e[0],n=e[1],s=e[2];return`#${t}${t}${n}${n}${s}${s}80`}}const n=e.match(/var\((--[\w-]+-ansi-[\w-]+)\)/);return n?`var(${n[1]}-dim)`:e}(r));let a=w.None;return n.decorations.has("bold")&&(a|=w.Bold),n.decorations.has("italic")&&(a|=w.Italic),n.decorations.has("underline")&&(a|=w.Underline),n.decorations.has("strikethrough")&&(a|=w.Strikethrough),{content:n.value,offset:t[1],color:r,bgColor:i,fontStyle:a}}))}function it(e,t,n={}){const{theme:s=e.getLoadedThemes()[0]}=n,r=e.resolveLangAlias(n.lang||"text");if(Re(r)||Le(s))return Ee(t).map(e=>[{content:e[0],offset:e[1]}]);const{theme:i,colorMap:a}=e.setTheme(s);if("ansi"===r)return ot(i,t,n);const c=e.getLanguage(n.lang||"text");if(n.grammarState){if(n.grammarState.lang!==c.name)throw new o(`Grammar state language "${n.grammarState.lang}" does not match highlight language "${c.name}"`);if(!n.grammarState.themes.includes(i.name))throw new o(`Grammar state themes "${n.grammarState.themes}" do not contain highlight theme "${i.name}"`)}return at(t,c,i,a,n)}function at(e,t,n,s,r){const o=ct(e,t,n,s,r),i=new He(o.stateStack,t.name,n.name);return Ue(o.tokens,i),o.tokens}function ct(e,t,n,s,r){const i=Ae(n,r),{tokenizeMaxLineLength:a=0,tokenizeTimeLimit:c=500}=r,l=Ee(e);let u=r.grammarState?function(e,t){if(!(e instanceof He))throw new o("Invalid grammar state");return e.getInternalStack(t)}(r.grammarState,n.name)??Ne:null!=r.grammarContextCode?ct(r.grammarContextCode,t,n,s,{...r,grammarState:void 0,grammarContextCode:void 0}).stateStack:Ne,p=[];const d=[];for(let o=0,g=l.length;o<g;o++){const[e,g]=l[o];if(""===e){p=[],d.push([]);continue}if(a>0&&e.length>=a){p=[],d.push([{content:e,offset:g,color:"",fontStyle:0}]);continue}let f,m,_;r.includeExplanation&&(f=t.tokenizeLine(e,u,c),m=f.tokens,_=0);const y=t.tokenizeLine2(e,u,c),b=y.tokens.length/2;for(let t=0;t<b;t++){const o=y.tokens[2*t],a=t+1<b?y.tokens[2*t+2]:e.length;if(o===a)continue;const c=y.tokens[2*t+1],l=ve(s[P.getForeground(c)],i),u=P.getFontStyle(c),d={content:e.substring(o,a),offset:g+o,color:l,fontStyle:u};if(r.includeExplanation){const t=[];if("scopeName"!==r.includeExplanation)for(const e of n.settings){let n;switch(typeof e.scope){case"string":n=e.scope.split(/,/).map(e=>e.trim());break;case"object":n=e.scope;break;default:continue}t.push({settings:e,selectors:n.map(e=>e.split(/ /))})}d.explanation=[];let s=0;for(;o+s<a;){const n=m[_],o=e.substring(n.startIndex,n.endIndex);s+=o.length,d.explanation.push({content:o,scopes:"scopeName"===r.includeExplanation?ht(n.scopes):lt(t,n.scopes)}),_+=1}}p.push(d)}d.push(p),p=[],u=y.ruleStack}return{tokens:d,stateStack:u}}function ht(e){return e.map(e=>({scopeName:e}))}function lt(e,t){const n=[];for(let s=0,r=t.length;s<r;s++){const r=t[s];n[s]={scopeName:r,themeMatches:dt(e,r,t.slice(0,s))}}return n}function ut(e,t){return e===t||t.substring(0,e.length)===e&&"."===t[e.length]}function pt(e,t,n){if(!ut(e[e.length-1],t))return!1;let s=e.length-2,r=n.length-1;for(;s>=0&&r>=0;)ut(e[s],n[r])&&(s-=1),r-=1;return-1===s}function dt(e,t,n){const s=[];for(const{selectors:r,settings:o}of e)for(const e of r)if(pt(e,t,n)){s.push(o);break}return s}function gt(e,t,n){const s=Object.entries(n.themes).filter(e=>e[1]).map(e=>({color:e[0],theme:e[1]})),r=s.map(s=>{const r=it(e,t,{...n,theme:s.theme});return{tokens:r,state:ze(r),theme:"string"==typeof s.theme?s.theme:s.theme.name}}),o=function(...e){const t=e.map(()=>[]),n=e.length;for(let s=0;s<e[0].length;s++){const r=e.map(e=>e[s]),o=t.map(()=>[]);t.forEach((e,t)=>e.push(o[t]));const i=r.map(()=>0),a=r.map(e=>e[0]);for(;a.every(e=>e);){const e=Math.min(...a.map(e=>e.content.length));for(let t=0;t<n;t++){const n=a[t];n.content.length===e?(o[t].push(n),i[t]+=1,a[t]=r[t][i[t]]):(o[t].push({...n,content:n.content.slice(0,e)}),a[t]={...n,content:n.content.slice(e),offset:n.offset+e})}}}return t}(...r.map(e=>e.tokens)),i=o[0].map((e,t)=>e.map((e,r)=>{const i={content:e.content,variants:{},offset:e.offset};return"includeExplanation"in n&&n.includeExplanation&&(i.explanation=e.explanation),o.forEach((e,n)=>{const{content:o,explanation:a,offset:c,...l}=e[t][r];i.variants[s[n].color]=l}),i})),a=r[0].state?new He(Object.fromEntries(r.map(e=>[e.theme,e.state?.getInternalStack(e.theme)])),r[0].state.lang):void 0;return a&&Ue(i,a),i}function ft(e,t,n){let s,r,i,a,c,l;if("themes"in n){const{defaultColor:u="light",cssVariablePrefix:p="--shiki-",colorsRendering:d="css-vars"}=n,g=Object.entries(n.themes).filter(e=>e[1]).map(e=>({color:e[0],theme:e[1]})).sort((e,t)=>e.color===u?-1:t.color===u?1:0);if(0===g.length)throw new o("`themes` option must not be empty");const f=gt(e,t,n);if(l=ze(f),u&&Be!==u&&!g.find(e=>e.color===u))throw new o(`\`themes\` option must contain the defaultColor key \`${u}\``);const m=g.map(t=>e.getTheme(t.theme)),_=g.map(e=>e.color);i=f.map(e=>e.map(e=>Fe(e,_,p,u,d))),l&&Ue(i,l);const y=g.map(e=>Ae(e.theme,n));r=mt(g,m,y,p,u,"fg",d),s=mt(g,m,y,p,u,"bg",d),a=`shiki-themes ${m.map(e=>e.name).join(" ")}`,c=u?void 0:[r,s].join(";")}else{if(!("theme"in n))throw new o("Invalid options, either `theme` or `themes` must be provided");{const o=Ae(n.theme,n);i=it(e,t,n);const c=e.getTheme(n.theme);s=ve(c.bg,o),r=ve(c.fg,o),a=c.name,l=ze(i)}}return{tokens:i,fg:r,bg:s,themeName:a,rootStyle:c,grammarState:l}}function mt(e,t,n,s,r,i,a){return e.map((c,l)=>{const u=ve(t[l][i],n[l])||"inherit",p=`${s+c.color}${"bg"===i?"-bg":""}:${u}`;if(0===l&&r){if(r===Be&&e.length>1){const s=e.findIndex(e=>"light"===e.color),r=e.findIndex(e=>"dark"===e.color);if(-1===s||-1===r)throw new o('When using `defaultColor: "light-dark()"`, you must provide both `light` and `dark` themes');return`light-dark(${ve(t[s][i],n[s])||"inherit"}, ${ve(t[r][i],n[r])||"inherit"});${p}`}return u}return"css-vars"===a?p:null}).filter(e=>!!e).join(";")}function _t(e,t,n,s={meta:{},options:n,codeToHast:(t,n)=>_t(e,t,n),codeToTokens:(t,n)=>ft(e,t,n)}){let r=t;for(const f of Ye(n))r=f.preprocess?.call(s,r,n)||r;let{tokens:o,fg:i,bg:a,themeName:c,rootStyle:l,grammarState:u}=ft(e,r,n);const{mergeWhitespaces:p=!0,mergeSameStyleTokens:d=!1}=n;!0===p?o=function(e){return e.map(e=>{const t=[];let n,s="";return e.forEach((r,o)=>{const i=!(r.fontStyle&&(r.fontStyle&w.Underline||r.fontStyle&w.Strikethrough));i&&r.content.match(/^\s+$/)&&e[o+1]?(void 0===n&&(n=r.offset),s+=r.content):s?(i?t.push({...r,offset:n,content:s+r.content}):t.push({content:s,offset:n},r),n=void 0,s=""):t.push(r)}),t})}(o):"never"===p&&(o=function(e){return e.map(e=>e.flatMap(e=>{if(e.content.match(/^\s+$/))return e;const t=e.content.match(/^(\s*)(.*?)(\s*)$/);if(!t)return e;const[,n,s,r]=t;if(!n&&!r)return e;const o=[{...e,offset:e.offset+n.length,content:s}];return n&&o.unshift({content:n,offset:e.offset}),r&&o.push({content:r,offset:e.offset+n.length+s.length}),o}))}(o)),d&&(o=function(e){return e.map(e=>{const t=[];for(const n of e){if(0===t.length){t.push({...n});continue}const e=t[t.length-1],s=De(e.htmlStyle||We(e)),r=De(n.htmlStyle||We(n)),o=e.fontStyle&&(e.fontStyle&w.Underline||e.fontStyle&w.Strikethrough),i=n.fontStyle&&(n.fontStyle&w.Underline||n.fontStyle&w.Strikethrough);o||i||s!==r?t.push({...n}):e.content+=n.content}return t})}(o));const g={...s,get source(){return r}};for(const f of Ye(n))o=f.tokens?.call(g,o)||o;return yt(o,{...n,fg:i,bg:a,themeName:c,rootStyle:!1!==n.rootStyle&&(n.rootStyle??l)},g,u)}function yt(e,t,n,s=ze(e)){const r=Ye(t),o=[],i={type:"root",children:[]},{structure:a="classic",tabindex:c="0"}=t,l={class:`shiki ${t.themeName||""}`};!1!==t.rootStyle&&(null!=t.rootStyle?l.style=t.rootStyle:l.style=`background-color:${t.bg};color:${t.fg}`),!1!==c&&null!=c&&(l.tabindex=c.toString());for(const[m,_]of Object.entries(t.meta||{}))m.startsWith("_")||(l[m]=_);let u={type:"element",tagName:"pre",properties:l,children:[],data:t.data},p={type:"element",tagName:"code",properties:{},children:o};const d=[],g={...n,structure:a,addClassToHast:Ge,get source(){return n.source},get tokens(){return e},get options(){return t},get root(){return i},get pre(){return u},get code(){return p},get lines(){return d}};if(e.forEach((e,t)=>{t&&("inline"===a?i.children.push({type:"element",tagName:"br",properties:{},children:[]}):"classic"===a&&o.push({type:"text",value:"\n"}));let n={type:"element",tagName:"span",properties:{class:"line"},children:[]},s=0;for(const o of e){let e={type:"element",tagName:"span",properties:{...o.htmlAttrs},children:[{type:"text",value:o.content}]};const c=De(o.htmlStyle||We(o));c&&(e.properties.style=c);for(const i of r)e=i?.span?.call(g,e,t+1,s,n,o)||e;"inline"===a?i.children.push(e):"classic"===a&&n.children.push(e),s+=o.content.length}if("classic"===a){for(const e of r)n=e?.line?.call(g,n,t+1)||n;d.push(n),o.push(n)}else"inline"===a&&d.push(n)}),"classic"===a){for(const e of r)p=e?.code?.call(g,p)||p;u.children.push(p);for(const e of r)u=e?.pre?.call(g,u)||u;i.children.push(u)}else if("inline"===a){const e=[];let t={type:"element",tagName:"span",properties:{class:"line"},children:[]};for(const s of i.children)"element"===s.type&&"br"===s.tagName?(e.push(t),t={type:"element",tagName:"span",properties:{class:"line"},children:[]}):"element"!==s.type&&"text"!==s.type||t.children.push(s);e.push(t);let n={type:"element",tagName:"code",properties:{},children:e};for(const s of r)n=s?.code?.call(g,n)||n;i.children=[];for(let s=0;s<n.children.length;s++){s>0&&i.children.push({type:"element",tagName:"br",properties:{},children:[]});const e=n.children[s];"element"===e.type&&i.children.push(...e.children)}}let f=i;for(const m of r)f=m?.root?.call(g,f)||f;return s&&Ue(f,s),f}const bt=r;function kt(e,t,n){const s={meta:{},options:n,codeToHast:(t,n)=>_t(e,t,n),codeToTokens:(t,n)=>ft(e,t,n)};let r=bt(_t(e,t,n,s));for(const o of Ye(n))r=o.postprocess?.call(s,r,n)||r;return r}const St="#333333",wt="#bbbbbb",Ct="#fffffe",Nt="#1e1e1e",At="__shiki_resolved";function vt(e){if(e?.[At])return e;const t={...e};t.tokenColors&&!t.settings&&(t.settings=t.tokenColors,delete t.tokenColors),t.type||(t.type="dark"),t.colorReplacements={...t.colorReplacements},t.settings||(t.settings=[]);let{bg:n,fg:s}=t;if(!n||!s){const e=t.settings?t.settings.find(e=>!e.name&&!e.scope):void 0;e?.settings?.foreground&&(s=e.settings.foreground),e?.settings?.background&&(n=e.settings.background),!s&&t?.colors?.["editor.foreground"]&&(s=t.colors["editor.foreground"]),!n&&t?.colors?.["editor.background"]&&(n=t.colors["editor.background"]),s||(s="light"===t.type?St:wt),n||(n="light"===t.type?Ct:Nt),t.fg=s,t.bg=n}t.settings[0]&&t.settings[0].settings&&!t.settings[0].scope||t.settings.unshift({settings:{foreground:t.fg,background:t.bg}});let r=0;const o=/* @__PURE__ */new Map;function i(e){if(o.has(e))return o.get(e);r+=1;const n=`#${r.toString(16).padStart(8,"0").toLowerCase()}`;return t.colorReplacements?.[`#${n}`]?i(e):(o.set(e,n),n)}t.settings=t.settings.map(e=>{const n=e.settings?.foreground&&!e.settings.foreground.startsWith("#"),s=e.settings?.background&&!e.settings.background.startsWith("#");if(!n&&!s)return e;const r={...e,settings:{...e.settings}};if(n){const n=i(e.settings.foreground);t.colorReplacements[n]=e.settings.foreground,r.settings.foreground=n}if(s){const n=i(e.settings.background);t.colorReplacements[n]=e.settings.background,r.settings.background=n}return r});for(const a of Object.keys(t.colors||{}))if(("editor.foreground"===a||"editor.background"===a||a.startsWith("terminal.ansi"))&&!t.colors[a]?.startsWith("#")){const e=i(t.colors[a]);t.colorReplacements[e]=t.colors[a],t.colors[a]=e}return Object.defineProperty(t,At,{enumerable:!1,writable:!1,value:!0}),t}async function Pt(e){return Array.from(new Set((await Promise.all(e.filter(e=>!Te(e)).map(async e=>await Ie(e).then(e=>Array.isArray(e)?e:[e])))).flat()))}async function It(e){return(await Promise.all(e.map(async e=>xe(e)?null:vt(await Ie(e))))).filter(e=>!!e)}function Rt(e,t=3){t>3||console.trace(`[SHIKI DEPRECATE]: ${e}`)}class Tt extends Error{constructor(e){super(e),this.name="ShikiError"}}function Lt(e,t){if(!t)return e;if(t[e]){const n=/* @__PURE__ */new Set([e]);for(;t[e];){if(e=t[e],n.has(e))throw new Tt(`Circular alias \`${Array.from(n).join(" -> ")} -> ${e}\``);n.add(e)}}return e}class xt extends Ce{constructor(e,t,n,r={}){super(e),s(this,"_resolvedThemes",/* @__PURE__ */new Map),s(this,"_resolvedGrammars",/* @__PURE__ */new Map),s(this,"_langMap",/* @__PURE__ */new Map),s(this,"_langGraph",/* @__PURE__ */new Map),s(this,"_textmateThemeCache",/* @__PURE__ */new WeakMap),s(this,"_loadedThemesCache",null),s(this,"_loadedLanguagesCache",null),this._resolver=e,this._themes=t,this._langs=n,this._alias=r,this._themes.map(e=>this.loadTheme(e)),this.loadLanguages(this._langs)}getTheme(e){return"string"==typeof e?this._resolvedThemes.get(e):this.loadTheme(e)}loadTheme(e){const t=vt(e);return t.name&&(this._resolvedThemes.set(t.name,t),this._loadedThemesCache=null),t}getLoadedThemes(){return this._loadedThemesCache||(this._loadedThemesCache=[...this._resolvedThemes.keys()]),this._loadedThemesCache}setTheme(e){let t=this._textmateThemeCache.get(e);t||(t=_.createFromRawTheme(e),this._textmateThemeCache.set(e,t)),this._syncRegistry.setTheme(t)}getGrammar(e){return e=Lt(e,this._alias),this._resolvedGrammars.get(e)}loadLanguage(e){if(this.getGrammar(e.name))return;const t=new Set([...this._langMap.values()].filter(t=>t.embeddedLangsLazy?.includes(e.name)));this._resolver.addLanguage(e);const n={balancedBracketSelectors:e.balancedBracketSelectors||["*"],unbalancedBracketSelectors:e.unbalancedBracketSelectors||[]};this._syncRegistry._rawGrammars.set(e.scopeName,e);const s=this.loadGrammarWithConfiguration(e.scopeName,1,n);if(s.name=e.name,this._resolvedGrammars.set(e.name,s),e.aliases&&e.aliases.forEach(t=>{this._alias[t]=e.name}),this._loadedLanguagesCache=null,t.size)for(const r of t)this._resolvedGrammars.delete(r.name),this._loadedLanguagesCache=null,this._syncRegistry?._injectionGrammars?.delete(r.scopeName),this._syncRegistry?._grammars?.delete(r.scopeName),this.loadLanguage(this._langMap.get(r.name))}dispose(){super.dispose(),this._resolvedThemes.clear(),this._resolvedGrammars.clear(),this._langMap.clear(),this._langGraph.clear(),this._loadedThemesCache=null}loadLanguages(e){for(const s of e)this.resolveEmbeddedLanguages(s);const t=Array.from(this._langGraph.entries()),n=t.filter(([e,t])=>!t);if(n.length){const e=t.filter(([e,t])=>{if(!t)return!1;const s=t.embeddedLanguages||t.embeddedLangs;return s?.some(e=>n.map(([e])=>e).includes(e))}).filter(e=>!n.includes(e));throw new Tt(`Missing languages ${n.map(([e])=>`\`${e}\``).join(", ")}, required by ${e.map(([e])=>`\`${e}\``).join(", ")}`)}for(const[s,r]of t)this._resolver.addLanguage(r);for(const[s,r]of t)this.loadLanguage(r)}getLoadedLanguages(){return this._loadedLanguagesCache||(this._loadedLanguagesCache=[.../* @__PURE__ */new Set([...this._resolvedGrammars.keys(),...Object.keys(this._alias)])]),this._loadedLanguagesCache}resolveEmbeddedLanguages(e){this._langMap.set(e.name,e),this._langGraph.set(e.name,e);const t=e.embeddedLanguages??e.embeddedLangs;if(t)for(const n of t)this._langGraph.set(n,this._langMap.get(n))}}class Gt{constructor(e,t){s(this,"_langs",/* @__PURE__ */new Map),s(this,"_scopeToLang",/* @__PURE__ */new Map),s(this,"_injections",/* @__PURE__ */new Map),s(this,"_onigLib"),this._onigLib={createOnigScanner:t=>e.createScanner(t),createOnigString:t=>e.createString(t)},t.forEach(e=>this.addLanguage(e))}get onigLib(){return this._onigLib}getLangRegistration(e){return this._langs.get(e)}loadGrammar(e){return this._scopeToLang.get(e)}addLanguage(e){this._langs.set(e.name,e),e.aliases&&e.aliases.forEach(t=>{this._langs.set(t,e)}),this._scopeToLang.set(e.scopeName,e),e.injectTo&&e.injectTo.forEach(t=>{this._injections.get(t)||this._injections.set(t,[]),this._injections.get(t).push(e.scopeName)})}getInjections(e){const t=e.split(".");let n=[];for(let s=1;s<=t.length;s++){const e=t.slice(0,s).join(".");n=[...n,...this._injections.get(e)||[]]}return n}}let Et=0;function $t(e){Et+=1,!1!==e.warnings&&Et>=10&&Et%10==0&&console.warn(`[Shiki] ${Et} 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.`);let t=!1;if(!e.engine)throw new Tt("`engine` option is required for synchronous mode");const n=(e.langs||[]).flat(1),s=(e.themes||[]).flat(1).map(vt),r=new Gt(e.engine,n),o=new xt(r,s,n,e.langAlias);let i;function a(e){if("none"===e)return{bg:"",fg:"",name:"none",settings:[],type:"dark"};u();const t=o.getTheme(e);if(!t)throw new Tt(`Theme \`${e}\` not found, you may need to load it first`);return t}function c(...e){u(),o.loadLanguages(e.flat(1))}function l(...e){u();for(const t of e.flat(1))o.loadTheme(t)}function u(){if(t)throw new Tt("Shiki instance has been disposed")}function p(){t||(t=!0,o.dispose(),Et-=1)}return{setTheme:function(e){u();const t=a(e);return i!==e&&(o.setTheme(t),i=e),{theme:t,colorMap:o.getColorMap()}},getTheme:a,getLanguage:function(e){u();const t=o.getGrammar("string"==typeof e?e:e.name);if(!t)throw new Tt(`Language \`${e}\` not found, you may need to load it first`);return t},getLoadedThemes:function(){return u(),o.getLoadedThemes()},getLoadedLanguages:function(){return u(),o.getLoadedLanguages()},resolveLangAlias:function(t){return Lt(t,e.langAlias)},loadLanguage:async function(...e){return c(await Pt(e))},loadLanguageSync:c,loadTheme:async function(...e){return u(),l(await It(e))},loadThemeSync:l,dispose:p,[Symbol.dispose]:p}}async function Bt(e){e.engine||Rt("`engine` option is required. Use `createOnigurumaEngine` or `createJavaScriptRegexEngine` to create an engine.");const[t,n,s]=await Promise.all([It(e.themes||[]),Pt(e.langs||[]),e.engine]);return $t({...e,themes:t,langs:n,engine:s})}async function Mt(e){const t=await Bt(e);return{getLastGrammarState:(...e)=>function(...e){if(2===e.length)return ze(e[1]);const[t,n,s={}]=e,{lang:r="text",theme:i=t.getLoadedThemes()[0]}=s;if(Re(r)||Le(i))throw new o("Plain language does not have grammar state");if("ansi"===r)throw new o("ANSI language does not have grammar state");const{theme:a,colorMap:c}=t.setTheme(i),l=t.getLanguage(r);return new He(ct(n,l,a,c,s).stateStack,l.name,a.name)}(t,...e),codeToTokensBase:(e,n)=>it(t,e,n),codeToTokensWithThemes:(e,n)=>gt(t,e,n),codeToTokens:(e,n)=>ft(t,e,n),codeToHast:(e,n)=>_t(t,e,n),codeToHtml:(e,n)=>kt(t,e,n),getBundledLanguages:()=>({}),getBundledThemes:()=>({}),...t,getInternalContext:()=>t}}export{o as ShikiError,Ge as addClassToHast,ve as applyColorReplacements,_t as codeToHast,kt as codeToHtml,ft as codeToTokens,it as codeToTokensBase,gt as codeToTokensWithThemes,Mt as createHighlighterCore,$e as createPositionConverter,Bt as createShikiInternal,$t as createShikiInternalSync,Fe as flatTokenVariants,We as getTokenStyleObject,bt as hastToHtml,Le as isNoneTheme,Re as isPlainLang,Te as isSpecialLang,xe as isSpecialTheme,Ie as normalizeGetter,vt as normalizeTheme,Ae as resolveColorReplacements,Ee as splitLines,Oe as splitToken,je as splitTokens,De as stringifyTokenStyle,Pe as toArray,ot as tokenizeAnsiWithTheme,at as tokenizeWithTheme,yt as tokensToHast,Ke as transformerDecorations,Rt as warnDeprecated};
|