vitepress-openapi 0.2.5 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{angular-html-DUEd47TJ.js → angular-html-C0iYY931.js} +2 -2
- package/dist/{angular-html-Dg3-tcsc.cjs → angular-html-DAq3gDGA.cjs} +1 -1
- package/dist/{angular-ts-D0NAnxgV.cjs → angular-ts-B2PPB0Y5.cjs} +1 -1
- package/dist/{angular-ts-syduVA-F.js → angular-ts-Ct5d_gHN.js} +2 -2
- package/dist/{apl-Cq9hivV8.js → apl-CiiA3JDJ.js} +5 -5
- package/dist/{apl-Dx6odmvQ.cjs → apl-CoWANpfc.cjs} +1 -1
- package/dist/{astro-CfDpOFJP.cjs → astro-BX6R0KnA.cjs} +1 -1
- package/dist/{astro-CIc9naVs.js → astro-Bzlt-IuJ.js} +5 -5
- package/dist/{blade-BxfKHaSj.cjs → blade-BBZCfhID.cjs} +1 -1
- package/dist/{blade-C5_pOwH9.js → blade-BGVF6ubL.js} +7 -7
- package/dist/{c-Bx-MD8Df.js → c-BpiaxH9s.js} +1 -1
- package/dist/{c-hpMPM8RV.cjs → c-CHRY6FQk.cjs} +1 -1
- package/dist/{chapel-keWPCgW7.cjs → chapel-CCUE2hqL.cjs} +1 -1
- package/dist/{chapel-DNuPgf4Q.js → chapel-fECU7c1r.js} +1 -1
- package/dist/{cobol-DZd5ojad.cjs → cobol-Ete-w65U.cjs} +1 -1
- package/dist/{cobol-DS4J3FEo.js → cobol-lxVOio4o.js} +2 -2
- package/dist/{coffee-CV4WwegX.js → coffee-D_GP6Mp_.js} +1 -1
- package/dist/{coffee-w3B5krTo.cjs → coffee-DcVdEhV6.cjs} +1 -1
- package/dist/{cpp-Jl_TC1Nw.cjs → cpp-BQiBH6_n.cjs} +1 -1
- package/dist/{cpp-ePkK8ak4.js → cpp-C2_nndOX.js} +3 -3
- package/dist/{crystal-BzagR96f.js → crystal-D68fQQf4.js} +6 -6
- package/dist/{crystal-CwIeEKN9.cjs → crystal-bWCs3mcQ.cjs} +1 -1
- package/dist/{css-BYV3ABNT.js → css-CwZ52NVY.js} +1 -1
- package/dist/{css-BGNe3YXa.cjs → css-LUs62piT.cjs} +1 -1
- package/dist/{edge-CdQqWKGq.cjs → edge-CRrD84FE.cjs} +1 -1
- package/dist/{edge-DCZlk9GE.js → edge-CxIBp4BJ.js} +3 -3
- package/dist/{elixir-_UY-lG6-.js → elixir-DzlkeFTp.js} +1 -1
- package/dist/{elixir-CxPipDUR.cjs → elixir-txrLIPgt.cjs} +1 -1
- package/dist/{elm-Bjkcqmf_.js → elm-BSAvBsXU.js} +1 -1
- package/dist/{elm-Ccn6fAWV.cjs → elm-D3rgeOAI.cjs} +1 -1
- package/dist/{erb-pmNxLm5n.js → erb-CDFFPhk2.js} +2 -2
- package/dist/{erb-DfkBkh24.cjs → erb-CEerDw7_.cjs} +1 -1
- package/dist/{git-rebase-B1W6M8Gc.js → git-rebase-BI3TNfL1.js} +1 -1
- package/dist/{git-rebase-v-Ukhgl9.cjs → git-rebase-BRc34H8A.cjs} +1 -1
- package/dist/{glimmer-js-BZ-ju6iq.js → glimmer-js-BCOl9pkK.js} +4 -4
- package/dist/{glimmer-js-BAbqnV3-.cjs → glimmer-js-BjCbjAxk.cjs} +1 -1
- package/dist/{glimmer-ts-B3Cx5KtA.cjs → glimmer-ts-BaygTMht.cjs} +1 -1
- package/dist/{glimmer-ts-B12x5nAB.js → glimmer-ts-DtU3AR2J.js} +4 -4
- package/dist/{glsl-BzoNCWEn.js → glsl-C3jot75m.js} +2 -2
- package/dist/{glsl-BHIO0OBH.cjs → glsl-C4QVQ8IM.cjs} +1 -1
- package/dist/{graphql-BxIBMUHp.js → graphql-C57m_foI.js} +5 -5
- package/dist/{graphql-CQN3OclW.cjs → graphql-CWVurcx-.cjs} +1 -1
- package/dist/{hack-ColLjcl2.cjs → hack-CO29PdAW.cjs} +1 -1
- package/dist/{hack-BV5Clp_u.js → hack-LG-O4iX2.js} +2 -2
- package/dist/{haml-DGyVMTHl.cjs → haml-D5udMhEZ.cjs} +1 -1
- package/dist/{haml-BJ7DUgvS.js → haml-Qqt96dA3.js} +3 -3
- package/dist/{handlebars-DuylF_6e.js → handlebars-BBft0uRg.js} +4 -4
- package/dist/{handlebars-B5ZIr_aZ.cjs → handlebars-dotklBKW.cjs} +1 -1
- package/dist/{html-iLgKH72m.js → html-Cm4eMgz9.js} +3 -3
- package/dist/{html-derivative-UTkRrivP.cjs → html-derivative-Cu6O2gHN.cjs} +1 -1
- package/dist/{html-derivative-D_4Aj8Gh.js → html-derivative-DMWaumzq.js} +1 -1
- package/dist/{html-DN9f8kSH.cjs → html-hrBEmwSv.cjs} +1 -1
- package/dist/{http-C5ID-Qyz.js → http-Cz6VY5Wo.js} +4 -4
- package/dist/{http-BlHmF7m2.cjs → http-D168KNW_.cjs} +1 -1
- package/dist/{hurl--xoG0pPf.js → hurl-D36azgIj.js} +2 -2
- package/dist/{hurl-LrIzh9fX.cjs → hurl-DSwY6Z5G.cjs} +1 -1
- package/dist/{java-Zhvn3v1V.js → java-BKXCRk8D.js} +1 -1
- package/dist/{java-wSZjiYL-.cjs → java-CFiC7SeI.cjs} +1 -1
- package/dist/{javascript-BriSQyZc.cjs → javascript-Bx9N9g1f.cjs} +1 -1
- package/dist/{javascript-Btk6dvZV.js → javascript-DljrdC8t.js} +1 -1
- package/dist/{jinja-CUxfPCtW.js → jinja-NZUdcntO.js} +1 -1
- package/dist/{jinja-D76hx3-7.cjs → jinja-f05HaP8v.cjs} +1 -1
- package/dist/{jison-hYIOwwCK.js → jison-BQnZ1V4P.js} +1 -1
- package/dist/{jison-C3U4f0s4.cjs → jison-Dlb0RIZ3.cjs} +1 -1
- package/dist/{json-Bo-RT5A6.cjs → json-CzaEM6zR.cjs} +1 -1
- package/dist/{json-DPSZpJKU.js → json-DyprfpNy.js} +1 -1
- package/dist/{jsx-W4w_W_OV.js → jsx-DoPFZPXc.js} +1 -1
- package/dist/{jsx-CPH8GKtA.cjs → jsx-X5IYTTmR.cjs} +1 -1
- package/dist/{julia-Cac7DCT1.cjs → julia-BUcVnjBf.cjs} +1 -1
- package/dist/{julia-BxaHlyqA.js → julia-DrSudrKE.js} +4 -4
- package/dist/{just--lfP6IF9.cjs → just-DydEbCQZ.cjs} +1 -1
- package/dist/{just-CJOpWB1x.js → just-tTSTWYrq.js} +5 -5
- package/dist/{latex-CUtR5DE9.cjs → latex-BQA9tWbc.cjs} +1 -1
- package/dist/{latex-C7_sFdk3.js → latex-BUsA-DrV.js} +1 -1
- package/dist/{liquid-Drum6HOR.cjs → liquid-DkgygF2N.cjs} +1 -1
- package/dist/{liquid-DUN9LxqY.js → liquid-cWkPgL2I.js} +4 -4
- package/dist/{lua-BvhsgZmU.js → lua-C6iAvpwo.js} +2 -2
- package/dist/{lua-CjaqZWcv.cjs → lua-DIfY63me.cjs} +1 -1
- package/dist/{marko-CcYz_oXC.js → marko-CNIbHKC5.js} +3 -3
- package/dist/{marko-DZv2qjgg.cjs → marko-Du_QgmTX.cjs} +1 -1
- package/dist/{mdc-3sjk0StN.cjs → mdc-C_TsMRBC.cjs} +1 -1
- package/dist/{mdc-BkMDB3R8.js → mdc-DJo1F4gz.js} +2 -2
- package/dist/{nginx-CACh9sPZ.cjs → nginx-B4IJHacq.cjs} +1 -1
- package/dist/{nginx-Cwf0UjFL.js → nginx-CwCNXVm0.js} +1 -1
- package/dist/{nim-B7jmB3EZ.cjs → nim-rz8U_2RE.cjs} +1 -1
- package/dist/{nim-BT5yHPyY.js → nim-vPNRZtmW.js} +6 -6
- package/dist/{org-Bm-Fs1EQ.cjs → org-BJUQuLxI.cjs} +1 -1
- package/dist/{org-HmsRb9Fx.js → org-BXPZpMn-.js} +26 -26
- package/dist/{perl-Bfu0kGvH.js → perl-C4EazcOb.js} +5 -5
- package/dist/{perl-CIYgk-FU.cjs → perl-CmADOgcQ.cjs} +1 -1
- package/dist/{php-DH38roRY.cjs → php-BDdD_YcH.cjs} +1 -1
- package/dist/{php-B6Nhf791.js → php-BsJ_ZqPP.js} +6 -6
- package/dist/{pug-CyTLuK8P.js → pug-BYXwQyBY.js} +3 -3
- package/dist/{pug-DoZlAXyU.cjs → pug-BqCAm08K.cjs} +1 -1
- package/dist/{qml-jygIc27G.cjs → qml-BkLbkVNV.cjs} +1 -1
- package/dist/{qml-B5FZziLo.js → qml-CnP9LpPo.js} +1 -1
- package/dist/{r-CoMuq6NS.js → r-BskJ0B3b.js} +1 -1
- package/dist/{r-BLUZ58Oc.cjs → r-Crbt2ian.cjs} +1 -1
- package/dist/{razor-m7NZ_pEx.cjs → razor-CcOw1mzY.cjs} +1 -1
- package/dist/{razor-Ddj7i4qk.js → razor-CgobKwDB.js} +1 -1
- package/dist/{regexp-Cp4UOZ0d.js → regexp-35oNQcei.js} +1 -1
- package/dist/{regexp-DF2aMHu6.cjs → regexp-CiRKg-B7.cjs} +1 -1
- package/dist/{rst-CL0hK4OH.cjs → rst-0CCQrjRR.cjs} +1 -1
- package/dist/{rst-BFqthg8Z.js → rst-CcG1VyHf.js} +6 -6
- package/dist/{ruby-CHSsp6bd.cjs → ruby-Bz7pH067.cjs} +1 -1
- package/dist/{ruby-5apGWg3y.js → ruby-D84T3HVs.js} +12 -12
- package/dist/{sas-CH-7XeYU.cjs → sas-CfNVA6xj.cjs} +1 -1
- package/dist/{sas-BbCoQvHs.js → sas-leffZV-t.js} +1 -1
- package/dist/{scss-DKCpW6E9.js → scss-ConKgv_x.js} +2 -2
- package/dist/{scss-C7dGw39f.cjs → scss-tjluFEfq.cjs} +1 -1
- package/dist/{shellscript-DzADwDC7.cjs → shellscript-CZORtZ0m.cjs} +1 -1
- package/dist/{shellscript-iRYVRA9e.js → shellscript-Cqrf74-d.js} +1 -1
- package/dist/{shellsession-D34Gt-in.cjs → shellsession-C7TZqfBX.cjs} +1 -1
- package/dist/{shellsession-BipBVLfD.js → shellsession-DGN6o4H4.js} +1 -1
- package/dist/{soy-Ci5cHh9q.js → soy-C3C1N4BB.js} +1 -1
- package/dist/{soy-Cv5kA5BX.cjs → soy-CYwevEyV.cjs} +1 -1
- package/dist/{sql-1x77nIrC.cjs → sql-CKAdltev.cjs} +1 -1
- package/dist/{sql-CJLfxqoj.js → sql-D28Ep8kC.js} +1 -1
- package/dist/{stata-DhsCD8op.js → stata-BdKZ3Tfa.js} +1 -1
- package/dist/{stata-DkbZWhWM.cjs → stata-gwURYib4.cjs} +1 -1
- package/dist/{surrealql-DUNVEbqd.js → surrealql-BE3WUki2.js} +1 -1
- package/dist/{surrealql-uXRgsy4L.cjs → surrealql-CBAekr00.cjs} +1 -1
- package/dist/{svelte-BGQHd2p8.js → svelte-BIf-Q33W.js} +3 -3
- package/dist/{svelte-DhYdFOnU.cjs → svelte-ClXPqtyX.cjs} +1 -1
- package/dist/{templ-B8A_nNAL.cjs → templ-CJJCQFkp.cjs} +1 -1
- package/dist/{templ-Krzitdzq.js → templ-KcJQzTCJ.js} +2 -2
- package/dist/{tex-Br8lzWjy.js → tex-DtiwEWZU.js} +2 -2
- package/dist/{tex-DEhQZyOi.cjs → tex-V7tXlPyb.cjs} +1 -1
- package/dist/{ts-tags-DI5ydRJo.cjs → ts-tags-BaSrqEU0.cjs} +1 -1
- package/dist/{ts-tags-B3-QzjQ_.js → ts-tags-gxidxB8R.js} +7 -7
- package/dist/{tsx-D4QsIoAS.js → tsx-CLVkAc-4.js} +1 -1
- package/dist/{tsx-LB2Qf5Sb.cjs → tsx-yCIscrGd.cjs} +1 -1
- package/dist/{twig-B8pX6bsJ.js → twig-BozPiA4G.js} +5 -5
- package/dist/{twig-C0fyOpEP.cjs → twig-DucNk_L2.cjs} +1 -1
- package/dist/types/src/composables/useShiki.d.ts +13 -2
- package/dist/types/src/composables/useTheme.d.ts +53 -0
- package/dist/types/src/lib/playground/coercePlaygroundParameterValue.d.ts +20 -0
- package/dist/types/src/lib/shiki/resolveGrammar.d.ts +11 -0
- package/dist/{typescript-CT8UeVwI.cjs → typescript-CpL8J23X.cjs} +1 -1
- package/dist/{typescript-wL9ijY8z.js → typescript-v3MDZy3z.js} +1 -1
- package/dist/{typst-DqyPUBrE.js → typst-BqVfAgGz.js} +29 -29
- package/dist/{typst-3LVjvi1_.cjs → typst-KAYwLgnz.cjs} +1 -1
- package/dist/{useOpenapi-BYPXpEA6.js → useOpenapi-B8TP2xUt.js} +1734 -1679
- package/dist/{useOpenapi-o5WHNLy8.cjs → useOpenapi-_Y6U0hd9.cjs} +107 -107
- package/dist/vitepress-openapi.client.cjs.js +126 -126
- package/dist/vitepress-openapi.client.es.js +13941 -13849
- package/dist/vitepress-openapi.node.cjs.js +1 -1
- package/dist/vitepress-openapi.node.es.js +1 -1
- package/dist/{vue-_R2ZNdvJ.js → vue-CCBnDBrj.js} +6 -6
- package/dist/{vue-Dd3o2hqW.cjs → vue-DDP4ToP4.cjs} +1 -1
- package/dist/{vue-html-p7YZPSEJ.js → vue-html-ChckxjrF.js} +1 -1
- package/dist/{vue-html-DlzvdKGY.cjs → vue-html-pUsOdCRA.cjs} +1 -1
- package/dist/{vue-vine-DJ0FTVBO.cjs → vue-vine-C-R1ePqA.cjs} +1 -1
- package/dist/{vue-vine-C8dYPMH7.js → vue-vine-CW6_oew-.js} +3 -3
- package/dist/{xml-KS4atlJN.cjs → xml-5oO_YDXi.cjs} +1 -1
- package/dist/{xml-s2Q8hq3H.js → xml-BjuxZasO.js} +2 -2
- package/dist/{xsl-MpmIueyf.js → xsl-A-O9TTaY.js} +1 -1
- package/dist/{xsl-VX4kCG3h.cjs → xsl-BfGzl8_E.cjs} +1 -1
- package/dist/{yaml-BRDvY_60.cjs → yaml-CFG4vyir.cjs} +1 -1
- package/dist/{yaml-Cbx-ssDW.js → yaml-DgRJBItn.js} +1 -1
- package/package.json +1 -1
- package/src/components/Playground/OAPlaygroundParameterInput.vue +42 -1
- package/src/composables/useShiki.ts +226 -105
- package/src/composables/useTheme.ts +57 -0
- package/src/lib/codeSamples/buildRequest.ts +29 -6
- package/src/lib/playground/coercePlaygroundParameterValue.ts +105 -0
- package/src/lib/shiki/resolveGrammar.ts +42 -0
|
@@ -1,158 +1,279 @@
|
|
|
1
|
-
import type { HighlighterCore } from 'shiki/core'
|
|
1
|
+
import type { HighlighterCore, LanguageRegistration } from 'shiki/core'
|
|
2
2
|
import type { BundledLanguage } from 'shiki/langs'
|
|
3
3
|
import { createHighlighterCore } from 'shiki/core'
|
|
4
4
|
import { createJavaScriptRegexEngine } from 'shiki/engine/javascript'
|
|
5
5
|
import { bundledLanguages as highlighterImports } from 'shiki/langs'
|
|
6
6
|
import { ref } from 'vue'
|
|
7
|
+
import {
|
|
8
|
+
collectEmbeddedLangs,
|
|
9
|
+
resolveShikiLanguageSource,
|
|
10
|
+
withRegistryAlias,
|
|
11
|
+
} from '../lib/shiki/resolveGrammar'
|
|
7
12
|
import { useTheme } from './useTheme'
|
|
8
13
|
|
|
9
|
-
|
|
14
|
+
/** Always loaded for response / schema bodies (not the code-samples UI). */
|
|
10
15
|
const CORE_HIGHLIGHTERS: BundledLanguage[] = ['json', 'xml', 'markdown']
|
|
11
16
|
|
|
17
|
+
const FALLBACK_HTML = (content: string) => `<pre><code>${content}</code></pre>`
|
|
18
|
+
|
|
12
19
|
let shiki: HighlighterCore | null = null
|
|
13
20
|
let initPromise: Promise<void> | null = null
|
|
14
|
-
|
|
15
|
-
// Track in-flight language loads to avoid duplicate requests
|
|
16
21
|
const languageLoadPromises = new Map<string, Promise<boolean>>()
|
|
17
|
-
|
|
22
|
+
/** In-flight registered-grammar resolves, shared across concurrent batch walks. */
|
|
23
|
+
const languageSourcePromises = new Map<string, Promise<LanguageRegistration[]>>()
|
|
18
24
|
const loading = ref(true)
|
|
19
25
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
function init(): Promise<void> {
|
|
26
|
-
if (initPromise) {
|
|
27
|
-
return initPromise
|
|
28
|
-
}
|
|
26
|
+
async function resolveRegisteredGrammars(lang: string): Promise<LanguageRegistration[] | null> {
|
|
27
|
+
const cached = languageSourcePromises.get(lang)
|
|
28
|
+
if (cached) {
|
|
29
|
+
return cached
|
|
30
|
+
}
|
|
29
31
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const themeConfig = useTheme()
|
|
38
|
-
|
|
39
|
-
// Load only core highlighters during init
|
|
40
|
-
const coreLangModules = await Promise.all(
|
|
41
|
-
CORE_HIGHLIGHTERS.map(async (lang) => {
|
|
42
|
-
const importer = highlighterImports[lang]
|
|
43
|
-
if (!importer) {
|
|
44
|
-
return []
|
|
45
|
-
}
|
|
46
|
-
try {
|
|
47
|
-
const mod = await importer()
|
|
48
|
-
return mod.default
|
|
49
|
-
} catch {
|
|
50
|
-
return []
|
|
51
|
-
}
|
|
52
|
-
}),
|
|
53
|
-
)
|
|
54
|
-
|
|
55
|
-
shiki = await createHighlighterCore({
|
|
56
|
-
themes: [
|
|
57
|
-
themeConfig.getHighlighterTheme()?.light,
|
|
58
|
-
themeConfig.getHighlighterTheme()?.dark,
|
|
59
|
-
],
|
|
60
|
-
langs: coreLangModules.filter(Boolean).flat(),
|
|
61
|
-
engine: createJavaScriptRegexEngine({
|
|
62
|
-
target: 'ES2018',
|
|
63
|
-
}),
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
if (!shiki) {
|
|
67
|
-
throw new Error('Failed to create Shiki highlighter')
|
|
68
|
-
}
|
|
32
|
+
const source = useTheme().getShikiLanguage(lang)
|
|
33
|
+
if (!source) {
|
|
34
|
+
return null
|
|
35
|
+
}
|
|
69
36
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
37
|
+
const pending = Promise.resolve(resolveShikiLanguageSource(source))
|
|
38
|
+
.then(grammars => withRegistryAlias(grammars, lang) as LanguageRegistration[])
|
|
39
|
+
.catch((error) => {
|
|
40
|
+
// Drop only this attempt so a later ensureLanguage can retry the loader.
|
|
41
|
+
if (languageSourcePromises.get(lang) === pending) {
|
|
42
|
+
languageSourcePromises.delete(lang)
|
|
74
43
|
}
|
|
75
|
-
|
|
44
|
+
throw error
|
|
45
|
+
})
|
|
76
46
|
|
|
77
|
-
|
|
47
|
+
languageSourcePromises.set(lang, pending)
|
|
48
|
+
return pending
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function importBundledLanguage(lang: BundledLanguage): Promise<LanguageRegistration[]> {
|
|
52
|
+
const importer = highlighterImports[lang]
|
|
53
|
+
if (!importer) {
|
|
54
|
+
return []
|
|
78
55
|
}
|
|
79
56
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
57
|
+
try {
|
|
58
|
+
const mod = await importer()
|
|
59
|
+
return mod.default
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return []
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async function loadCoreLanguages(): Promise<LanguageRegistration[]> {
|
|
67
|
+
const modules = await Promise.all(CORE_HIGHLIGHTERS.map(importBundledLanguage))
|
|
68
|
+
return modules.flat()
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function createHighlighter(): Promise<HighlighterCore> {
|
|
72
|
+
const themeConfig = useTheme()
|
|
73
|
+
const highlighter = await createHighlighterCore({
|
|
74
|
+
themes: [
|
|
75
|
+
themeConfig.getHighlighterTheme()?.light,
|
|
76
|
+
themeConfig.getHighlighterTheme()?.dark,
|
|
77
|
+
],
|
|
78
|
+
langs: await loadCoreLanguages(),
|
|
79
|
+
engine: createJavaScriptRegexEngine({
|
|
80
|
+
target: 'ES2018',
|
|
81
|
+
}),
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
if (!highlighter) {
|
|
85
|
+
throw new Error('Failed to create Shiki highlighter')
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return highlighter
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function isLanguageReady(lang: string): boolean {
|
|
92
|
+
return shiki?.getLoadedLanguages().includes(lang) ?? false
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Walk registered grammars (including circular embeds) into one batch, and
|
|
97
|
+
* collect bundled embed ids that must be ensured before the batch load.
|
|
98
|
+
* Cycles among registered grammars are handled by `batch.has(lang)`.
|
|
99
|
+
*/
|
|
100
|
+
async function collectRegisteredGrammarBatch(
|
|
101
|
+
lang: string,
|
|
102
|
+
batch: Map<string, LanguageRegistration[]>,
|
|
103
|
+
bundledEmbeds: Set<string>,
|
|
104
|
+
): Promise<void> {
|
|
105
|
+
if (batch.has(lang) || isLanguageReady(lang)) {
|
|
106
|
+
return
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const grammars = await resolveRegisteredGrammars(lang)
|
|
110
|
+
if (!grammars) {
|
|
111
|
+
return
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
batch.set(lang, grammars)
|
|
115
|
+
|
|
116
|
+
for (const embeddedLang of collectEmbeddedLangs(grammars)) {
|
|
117
|
+
if (isLanguageReady(embeddedLang)) {
|
|
118
|
+
continue
|
|
91
119
|
}
|
|
92
120
|
|
|
93
|
-
if (
|
|
121
|
+
if (useTheme().getShikiLanguage(embeddedLang)) {
|
|
122
|
+
// Keep cyclic / nested registered grammars in the same loadLanguage call.
|
|
123
|
+
await collectRegisteredGrammarBatch(embeddedLang, batch, bundledEmbeds)
|
|
124
|
+
continue
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
bundledEmbeds.add(embeddedLang)
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async function loadRegisteredLanguage(lang: string): Promise<boolean> {
|
|
132
|
+
if (!shiki) {
|
|
133
|
+
return false
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const batch = new Map<string, LanguageRegistration[]>()
|
|
137
|
+
const bundledEmbeds = new Set<string>()
|
|
138
|
+
|
|
139
|
+
try {
|
|
140
|
+
await collectRegisteredGrammarBatch(lang, batch, bundledEmbeds)
|
|
141
|
+
|
|
142
|
+
if (!batch.has(lang)) {
|
|
94
143
|
return false
|
|
95
144
|
}
|
|
96
145
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
146
|
+
for (const embeddedLang of bundledEmbeds) {
|
|
147
|
+
if (isLanguageReady(embeddedLang)) {
|
|
148
|
+
continue
|
|
149
|
+
}
|
|
150
|
+
await ensureLanguage(embeddedLang)
|
|
100
151
|
}
|
|
101
152
|
|
|
102
|
-
//
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
153
|
+
// Register the whole registered subgraph together so circular embeds resolve.
|
|
154
|
+
await shiki.loadLanguage([...batch.values()].flat())
|
|
155
|
+
return isLanguageReady(lang)
|
|
156
|
+
}
|
|
157
|
+
finally {
|
|
158
|
+
for (const key of batch.keys()) {
|
|
159
|
+
languageSourcePromises.delete(key)
|
|
106
160
|
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
107
163
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
164
|
+
async function loadBundledLanguage(lang: string): Promise<boolean> {
|
|
165
|
+
if (!shiki) {
|
|
166
|
+
return false
|
|
167
|
+
}
|
|
111
168
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
169
|
+
const grammars = await importBundledLanguage(lang as BundledLanguage)
|
|
170
|
+
if (grammars.length === 0) {
|
|
171
|
+
console.warn(`Shiki language "${lang}" not available.`)
|
|
172
|
+
return false
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
await shiki.loadLanguage(grammars)
|
|
176
|
+
return true
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
async function loadLanguage(lang: string): Promise<boolean> {
|
|
180
|
+
try {
|
|
181
|
+
if (useTheme().getShikiLanguage(lang)) {
|
|
182
|
+
return await loadRegisteredLanguage(lang)
|
|
183
|
+
}
|
|
184
|
+
return await loadBundledLanguage(lang)
|
|
185
|
+
}
|
|
186
|
+
catch (error) {
|
|
187
|
+
console.error(`Failed to load Shiki language "${lang}":`, error)
|
|
188
|
+
return false
|
|
189
|
+
}
|
|
190
|
+
finally {
|
|
191
|
+
languageLoadPromises.delete(lang)
|
|
192
|
+
languageSourcePromises.delete(lang)
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Initialize Shiki with core highlighters only (json, xml, markdown).
|
|
198
|
+
* Additional languages are loaded on-demand via ensureLanguage().
|
|
199
|
+
*/
|
|
200
|
+
function init(): Promise<void> {
|
|
201
|
+
if (initPromise) {
|
|
202
|
+
return initPromise
|
|
203
|
+
}
|
|
116
204
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
console.error(`Failed to load Shiki language "${lang}":`, e)
|
|
123
|
-
return false
|
|
124
|
-
} finally {
|
|
125
|
-
languageLoadPromises.delete(lang)
|
|
205
|
+
initPromise = (async () => {
|
|
206
|
+
try {
|
|
207
|
+
if (shiki) {
|
|
208
|
+
loading.value = false
|
|
209
|
+
return
|
|
126
210
|
}
|
|
127
|
-
})()
|
|
128
211
|
|
|
129
|
-
|
|
130
|
-
|
|
212
|
+
shiki = await createHighlighter()
|
|
213
|
+
loading.value = false
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
initPromise = null
|
|
217
|
+
throw error
|
|
218
|
+
}
|
|
219
|
+
})()
|
|
220
|
+
|
|
221
|
+
return initPromise
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Ensure a language is loaded. Loads it on-demand if not already available.
|
|
226
|
+
* Returns true if the language is ready, false if it couldn't be loaded.
|
|
227
|
+
*/
|
|
228
|
+
async function ensureLanguage(lang: string): Promise<boolean> {
|
|
229
|
+
try {
|
|
230
|
+
await init()
|
|
231
|
+
}
|
|
232
|
+
catch (error) {
|
|
233
|
+
console.error('Failed to initialize Shiki:', error)
|
|
234
|
+
return false
|
|
131
235
|
}
|
|
132
236
|
|
|
237
|
+
if (!shiki) {
|
|
238
|
+
return false
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if (isLanguageReady(lang)) {
|
|
242
|
+
return true
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const inFlight = languageLoadPromises.get(lang)
|
|
246
|
+
if (inFlight) {
|
|
247
|
+
return inFlight
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const loadPromise = loadLanguage(lang)
|
|
251
|
+
languageLoadPromises.set(lang, loadPromise)
|
|
252
|
+
return loadPromise
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export function useShiki() {
|
|
133
256
|
function isReady(): boolean {
|
|
134
257
|
return shiki !== null
|
|
135
258
|
}
|
|
136
259
|
|
|
137
260
|
function isLanguageLoaded(lang: string): boolean {
|
|
138
|
-
return
|
|
261
|
+
return isLanguageReady(lang)
|
|
139
262
|
}
|
|
140
263
|
|
|
141
264
|
function renderShiki(content: string, { lang, theme }: { lang: string, theme: string }) {
|
|
142
|
-
if (shiki
|
|
143
|
-
return
|
|
144
|
-
lang,
|
|
145
|
-
theme,
|
|
146
|
-
})
|
|
147
|
-
} else {
|
|
148
|
-
return `<pre><code>${content}</code></pre>`
|
|
265
|
+
if (!shiki || !isLanguageReady(lang)) {
|
|
266
|
+
return FALLBACK_HTML(content)
|
|
149
267
|
}
|
|
268
|
+
|
|
269
|
+
return shiki.codeToHtml(content, { lang, theme })
|
|
150
270
|
}
|
|
151
271
|
|
|
152
272
|
function reset() {
|
|
153
273
|
shiki = null
|
|
154
274
|
initPromise = null
|
|
155
275
|
languageLoadPromises.clear()
|
|
276
|
+
languageSourcePromises.clear()
|
|
156
277
|
loading.value = true
|
|
157
278
|
}
|
|
158
279
|
|
|
@@ -51,11 +51,41 @@ export type PlaygroundJsonEditorMode = 'text' | 'tree' | 'table'
|
|
|
51
51
|
export type Languages = 'es' | 'en' | 'ja' | 'pt-BR' | 'zh' | string
|
|
52
52
|
export type Messages = Record<Languages, Record<string, string>>
|
|
53
53
|
|
|
54
|
+
export interface ShikiGrammar {
|
|
55
|
+
name: string
|
|
56
|
+
scopeName: string
|
|
57
|
+
displayName?: string
|
|
58
|
+
aliases?: string[]
|
|
59
|
+
embeddedLangs?: string[]
|
|
60
|
+
embeddedLanguages?: string[]
|
|
61
|
+
patterns?: readonly unknown[]
|
|
62
|
+
repository?: Record<string, unknown>
|
|
63
|
+
injectTo?: string[]
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface ShikiLanguageModule {
|
|
67
|
+
default: ShikiGrammar | ShikiGrammar[]
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
type ShikiLanguageResolved = ShikiLanguageModule | ShikiGrammar | ShikiGrammar[]
|
|
71
|
+
|
|
72
|
+
export type ShikiLanguageSource
|
|
73
|
+
= | ShikiGrammar
|
|
74
|
+
| ShikiGrammar[]
|
|
75
|
+
| (() => ShikiLanguageResolved | Promise<ShikiLanguageResolved>)
|
|
76
|
+
|
|
77
|
+
export type ShikiLanguages = Record<string, ShikiLanguageSource>
|
|
78
|
+
|
|
54
79
|
export interface ThemeConfig {
|
|
55
80
|
highlighterTheme?: {
|
|
56
81
|
light?: any
|
|
57
82
|
dark?: any
|
|
58
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* TextMate grammars for languages that Shiki does not bundle.
|
|
86
|
+
* Keys are the ids passed as `LanguageConfig.highlighter` or `OACodeBlock` `lang`.
|
|
87
|
+
*/
|
|
88
|
+
shikiLanguages?: ShikiLanguages
|
|
59
89
|
}
|
|
60
90
|
|
|
61
91
|
export interface PathConfig {
|
|
@@ -512,6 +542,10 @@ export function useTheme(initialConfig: PartialUseThemeConfig = {}) {
|
|
|
512
542
|
setHighlighterTheme(config.theme.highlighterTheme)
|
|
513
543
|
}
|
|
514
544
|
|
|
545
|
+
if (config.theme?.shikiLanguages) {
|
|
546
|
+
setShikiLanguages(config.theme.shikiLanguages)
|
|
547
|
+
}
|
|
548
|
+
|
|
515
549
|
// Path
|
|
516
550
|
if (config.path?.showBaseURL !== undefined) {
|
|
517
551
|
ensureRefProperty(themeConfig, 'path', 'showBaseURL', config.path.showBaseURL)
|
|
@@ -634,6 +668,9 @@ export function useTheme(initialConfig: PartialUseThemeConfig = {}) {
|
|
|
634
668
|
|
|
635
669
|
function reset() {
|
|
636
670
|
setConfig(defaultValues)
|
|
671
|
+
if (themeConfig.theme) {
|
|
672
|
+
themeConfig.theme.shikiLanguages = {}
|
|
673
|
+
}
|
|
637
674
|
}
|
|
638
675
|
|
|
639
676
|
function getState() {
|
|
@@ -665,6 +702,22 @@ export function useTheme(initialConfig: PartialUseThemeConfig = {}) {
|
|
|
665
702
|
}
|
|
666
703
|
}
|
|
667
704
|
|
|
705
|
+
function getShikiLanguages(): ShikiLanguages {
|
|
706
|
+
return themeConfig.theme?.shikiLanguages ?? {}
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
function getShikiLanguage(lang: string): ShikiLanguageSource | undefined {
|
|
710
|
+
return themeConfig.theme?.shikiLanguages?.[lang]
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
function setShikiLanguages(languages: ShikiLanguages) {
|
|
714
|
+
const theme = ensureNestedProperty(themeConfig, 'theme')
|
|
715
|
+
theme.shikiLanguages = {
|
|
716
|
+
...theme.shikiLanguages,
|
|
717
|
+
...languages,
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
|
|
668
721
|
function getRequestBodyDefaultView(): BodyViewType | undefined {
|
|
669
722
|
return themeConfig?.requestBody?.defaultView?.value
|
|
670
723
|
}
|
|
@@ -1120,6 +1173,10 @@ export function useTheme(initialConfig: PartialUseThemeConfig = {}) {
|
|
|
1120
1173
|
getLocale,
|
|
1121
1174
|
setLocale,
|
|
1122
1175
|
getHighlighterTheme,
|
|
1176
|
+
setHighlighterTheme,
|
|
1177
|
+
getShikiLanguages,
|
|
1178
|
+
getShikiLanguage,
|
|
1179
|
+
setShikiLanguages,
|
|
1123
1180
|
/** @deprecated Use `getRequestBodyDefaultView` instead. */
|
|
1124
1181
|
getSchemaDefaultView: getRequestBodyDefaultView,
|
|
1125
1182
|
getRequestBodyDefaultView,
|
|
@@ -3,6 +3,7 @@ import type { PlaygroundSecurityScheme } from '../../types'
|
|
|
3
3
|
import { unref } from 'vue'
|
|
4
4
|
import { DEFAULT_BASE_URL } from '../../composables/useTheme'
|
|
5
5
|
import { getPropertyExample } from '../examples/getPropertyExample'
|
|
6
|
+
import { coercePlaygroundParameterValue } from '../playground/coercePlaygroundParameterValue'
|
|
6
7
|
import { resolveBaseUrl } from '../utils/resolveBaseUrl'
|
|
7
8
|
import { OARequest } from './request'
|
|
8
9
|
|
|
@@ -13,20 +14,38 @@ type ParameterValue
|
|
|
13
14
|
| Record<string, unknown>
|
|
14
15
|
| Array<string | number | boolean | Record<string, unknown>>
|
|
15
16
|
|
|
17
|
+
function joinParameterArray(value: readonly unknown[]): string {
|
|
18
|
+
return value.map((element) => {
|
|
19
|
+
if (Array.isArray(element) || (element !== null && typeof element === 'object')) {
|
|
20
|
+
return JSON.stringify(element)
|
|
21
|
+
}
|
|
22
|
+
// Match Array#toString for null and undefined.
|
|
23
|
+
return element == null ? '' : String(element)
|
|
24
|
+
}).join(',')
|
|
25
|
+
}
|
|
26
|
+
|
|
16
27
|
function processParameters(
|
|
17
28
|
variables: Record<string, ParameterValue>,
|
|
18
29
|
parameters: OpenAPIV3.ParameterObject[],
|
|
19
30
|
callback: (key: string, value: string) => void,
|
|
20
31
|
) {
|
|
21
|
-
const
|
|
32
|
+
const parametersByName = new Map(
|
|
33
|
+
parameters.flatMap(parameter => parameter.name ? [[parameter.name, parameter] as const] : []),
|
|
34
|
+
)
|
|
35
|
+
|
|
22
36
|
for (const [key, rawValue] of Object.entries(variables)) {
|
|
23
|
-
|
|
37
|
+
const parameter = parametersByName.get(key)
|
|
38
|
+
if (!parameter) {
|
|
24
39
|
continue
|
|
25
40
|
}
|
|
26
|
-
|
|
41
|
+
|
|
42
|
+
const coerced = coercePlaygroundParameterValue(parameter.schema, rawValue)
|
|
43
|
+
// Only arrays come from the JSON text field. Leave objects on the old path.
|
|
44
|
+
const value = Array.isArray(coerced) ? coerced : rawValue
|
|
45
|
+
if (value === undefined || value === '') {
|
|
27
46
|
continue
|
|
28
47
|
}
|
|
29
|
-
callback(key, String(
|
|
48
|
+
callback(key, Array.isArray(value) ? joinParameterArray(value) : String(value))
|
|
30
49
|
}
|
|
31
50
|
}
|
|
32
51
|
|
|
@@ -245,12 +264,16 @@ function getQuery(
|
|
|
245
264
|
return
|
|
246
265
|
}
|
|
247
266
|
|
|
248
|
-
const
|
|
267
|
+
const rawValue = variables[parameter.name]
|
|
268
|
+
const coerced = coercePlaygroundParameterValue(parameter.schema, rawValue)
|
|
269
|
+
// Arrays are edited as JSON text. Objects stay on the existing path.
|
|
270
|
+
const value = (Array.isArray(coerced) ? coerced : rawValue) as ParameterValue
|
|
249
271
|
if (value === undefined || value === '') {
|
|
250
272
|
return
|
|
251
273
|
}
|
|
252
274
|
|
|
253
|
-
// Default style for query is form, explode is true
|
|
275
|
+
// Default style for query is form, explode is true.
|
|
276
|
+
// https://spec.openapis.org/oas/v3.1.2.html#style-examples
|
|
254
277
|
const style = parameter.style || 'form'
|
|
255
278
|
const explode = parameter.explode ?? true
|
|
256
279
|
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
export interface ParameterSchemaLike {
|
|
2
|
+
type?: string | readonly string[]
|
|
3
|
+
items?: unknown
|
|
4
|
+
prefixItems?: unknown
|
|
5
|
+
properties?: unknown
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
type JsonKind = 'array' | 'object'
|
|
9
|
+
|
|
10
|
+
function jsonKinds(schema: unknown): Set<JsonKind> {
|
|
11
|
+
if (!schema || typeof schema !== 'object') {
|
|
12
|
+
return new Set()
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// A bare $ref has no local kind. OpenAPI 3.1 Schema Objects can also
|
|
16
|
+
// carry keywords next to $ref, and those keywords still apply.
|
|
17
|
+
// https://spec.openapis.org/oas/v3.1.2.html#schema-object
|
|
18
|
+
|
|
19
|
+
const candidate = schema as ParameterSchemaLike
|
|
20
|
+
const rawType = candidate.type
|
|
21
|
+
const types = Array.isArray(rawType)
|
|
22
|
+
? rawType
|
|
23
|
+
: typeof rawType === 'string'
|
|
24
|
+
? [rawType]
|
|
25
|
+
: []
|
|
26
|
+
|
|
27
|
+
const kinds = new Set<JsonKind>()
|
|
28
|
+
|
|
29
|
+
if (types.includes('array') || (types.length === 0 && (candidate.items !== undefined || candidate.prefixItems !== undefined))) {
|
|
30
|
+
kinds.add('array')
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (types.includes('object') || (types.length === 0 && candidate.properties !== undefined)) {
|
|
34
|
+
kinds.add('object')
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return kinds
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function schemaAcceptsStructuredJson(schema: unknown): boolean {
|
|
41
|
+
return jsonKinds(schema).size > 0
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The playground text field shows arrays and objects as JSON.
|
|
46
|
+
* An edit stores that text. Parse it back when the schema expects
|
|
47
|
+
* an array or object, so OpenAPI `style` and `explode` can run.
|
|
48
|
+
* Incomplete JSON stays as text while the user types.
|
|
49
|
+
*/
|
|
50
|
+
export function coercePlaygroundParameterValue(schema: unknown, value: unknown): unknown {
|
|
51
|
+
if (typeof value !== 'string') {
|
|
52
|
+
return value
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const kinds = jsonKinds(schema)
|
|
56
|
+
if (kinds.size === 0) {
|
|
57
|
+
return value
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const trimmed = value.trim()
|
|
61
|
+
if (!trimmed) {
|
|
62
|
+
return value
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const looksLikeArray = trimmed.startsWith('[')
|
|
66
|
+
const looksLikeObject = trimmed.startsWith('{')
|
|
67
|
+
if (looksLikeArray && !kinds.has('array')) {
|
|
68
|
+
return value
|
|
69
|
+
}
|
|
70
|
+
if (looksLikeObject && !kinds.has('object')) {
|
|
71
|
+
return value
|
|
72
|
+
}
|
|
73
|
+
if (!looksLikeArray && !looksLikeObject) {
|
|
74
|
+
return value
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
try {
|
|
78
|
+
const parsed = JSON.parse(trimmed)
|
|
79
|
+
if (kinds.has('array') && Array.isArray(parsed)) {
|
|
80
|
+
return parsed
|
|
81
|
+
}
|
|
82
|
+
if (kinds.has('object') && parsed !== null && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
83
|
+
return parsed
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
return value
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return value
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Value stored from the playground text field.
|
|
95
|
+
* Only an array is parsed. Object JSON stays a string so query serialization
|
|
96
|
+
* does not switch to form-object keys.
|
|
97
|
+
*/
|
|
98
|
+
export function valueFromPlaygroundTextField(schema: unknown, value: unknown): unknown {
|
|
99
|
+
if (typeof value !== 'string') {
|
|
100
|
+
return value
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const coerced = coercePlaygroundParameterValue(schema, value)
|
|
104
|
+
return Array.isArray(coerced) ? coerced : value
|
|
105
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { ShikiGrammar, ShikiLanguageSource } from '../../composables/useTheme'
|
|
2
|
+
|
|
3
|
+
function isLanguageModule(value: object): value is { default: ShikiGrammar | ShikiGrammar[] } {
|
|
4
|
+
return 'default' in value && !('scopeName' in value)
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Resolve a registry entry (grammar, array, or loader) into TextMate grammars.
|
|
9
|
+
*/
|
|
10
|
+
export async function resolveShikiLanguageSource(source: ShikiLanguageSource): Promise<ShikiGrammar[]> {
|
|
11
|
+
const resolved = typeof source === 'function' ? await source() : source
|
|
12
|
+
const grammars = isLanguageModule(resolved) ? resolved.default : resolved
|
|
13
|
+
return Array.isArray(grammars) ? grammars : [grammars]
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Ensure the registry key can be used as a Shiki language id when it differs
|
|
18
|
+
* from the grammar `name` / `aliases`.
|
|
19
|
+
*/
|
|
20
|
+
export function withRegistryAlias(grammars: ShikiGrammar[], lang: string): ShikiGrammar[] {
|
|
21
|
+
if (grammars.length === 0) {
|
|
22
|
+
return grammars
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const known = grammars.some(grammar => grammar.name === lang || grammar.aliases?.includes(lang))
|
|
26
|
+
if (known) {
|
|
27
|
+
return grammars
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const [first, ...rest] = grammars
|
|
31
|
+
return [{
|
|
32
|
+
...first,
|
|
33
|
+
aliases: [...(first.aliases ?? []), lang],
|
|
34
|
+
}, ...rest]
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function collectEmbeddedLangs(grammars: ShikiGrammar[]): string[] {
|
|
38
|
+
return [...new Set(grammars.flatMap(grammar => [
|
|
39
|
+
...(grammar.embeddedLangs ?? []),
|
|
40
|
+
...(grammar.embeddedLanguages ?? []),
|
|
41
|
+
]))]
|
|
42
|
+
}
|