@expressive-code/plugin-shiki
Advanced tools
Comparing version 0.30.0 to 0.30.1
@@ -8,2 +8,3 @@ // src/index.ts | ||
var highlighterPromiseByConfig = /* @__PURE__ */ new Map(); | ||
var promisesByHighlighter = /* @__PURE__ */ new WeakMap(); | ||
var themeCacheKeys = /* @__PURE__ */ new WeakMap(); | ||
@@ -17,14 +18,16 @@ async function getCachedHighlighter(config = {}) { | ||
}); | ||
highlighterPromiseByConfig.set(configCacheKey, highlighterPromise); | ||
} | ||
return await highlighterPromise; | ||
return highlighterPromise; | ||
} | ||
async function ensureThemeIsLoaded(highlighter, theme) { | ||
let cacheKey = themeCacheKeys.get(theme); | ||
if (!cacheKey) { | ||
cacheKey = `${theme.name}-${getStableObjectHash({ bg: theme.bg, fg: theme.fg, settings: theme.settings })}`; | ||
const existingCacheKey = themeCacheKeys.get(theme); | ||
const cacheKey = existingCacheKey ?? `${theme.name}-${getStableObjectHash({ bg: theme.bg, fg: theme.fg, settings: theme.settings })}`; | ||
if (!existingCacheKey) | ||
themeCacheKeys.set(theme, cacheKey); | ||
} | ||
if (!highlighter.getLoadedThemes().includes(cacheKey)) { | ||
const themeUsingCacheKey = { ...theme, name: cacheKey, settings: theme.settings }; | ||
await highlighter.loadTheme(themeUsingCacheKey); | ||
await memoizeHighlighterTask(highlighter, `loadTheme:${cacheKey}`, () => { | ||
const themeUsingCacheKey = { ...theme, name: cacheKey, settings: theme.settings }; | ||
return highlighter.loadTheme(themeUsingCacheKey); | ||
}); | ||
} | ||
@@ -39,6 +42,19 @@ return cacheKey; | ||
} | ||
await highlighter.loadLanguage(language); | ||
await memoizeHighlighterTask(highlighter, `loadLanguage:${language}`, () => highlighter.loadLanguage(language)); | ||
} | ||
return language; | ||
} | ||
function memoizeHighlighterTask(highlighter, taskId, taskFn) { | ||
let promises = promisesByHighlighter.get(highlighter); | ||
if (!promises) { | ||
promises = /* @__PURE__ */ new Map(); | ||
promisesByHighlighter.set(highlighter, promises); | ||
} | ||
let promise = promises.get(taskId); | ||
if (promise === void 0) { | ||
promise = taskFn(); | ||
promises.set(taskId, promise); | ||
} | ||
return promise; | ||
} | ||
@@ -45,0 +61,0 @@ // src/index.ts |
{ | ||
"name": "@expressive-code/plugin-shiki", | ||
"version": "0.30.0", | ||
"version": "0.30.1", | ||
"description": "Shiki syntax highlighting plugin for Expressive Code, a text marking & annotation engine for presenting source code on the web.", | ||
@@ -26,3 +26,3 @@ "keywords": [], | ||
"dependencies": { | ||
"@expressive-code/core": "^0.30.0", | ||
"@expressive-code/core": "^0.30.1", | ||
"shikiji": "^0.8.0" | ||
@@ -29,0 +29,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
56300
381