diff --git a/deps.ts b/deps.ts index aeb3021..3ec5341 100644 --- a/deps.ts +++ b/deps.ts @@ -35,13 +35,16 @@ export { default as presetWind } from "https://cdn.skypack.dev/@unocss/preset-wi export { default as presetTypography } from "https://cdn.skypack.dev/@unocss/preset-typography@0.30.11"; export { default as presetIcons } from "https://cdn.skypack.dev/@unocss/preset-icons@0.30.11"; +const _iconifyCache = new Map(); export const iconifyCollections = async (...sets: string[]) => { const reqs = [], sourceUrl = "https://esm.sh/@iconify/json@2.1.18/json"; for (const set of sets) { - reqs.push( - fetch(`${sourceUrl}/${set}.json`) - .then((res) => res.json()).then((json) => [set, json]), - ); + if (!_iconifyCache.has(set)) { + const req = fetch(`${sourceUrl}/${set}.json`) + .then((res) => res.json()).then((json) => [set, json]); + _iconifyCache.set(set, req); + } + reqs.push(_iconifyCache.get(set)); } return { collections: Object.fromEntries(await Promise.all(reqs)) }; }; diff --git a/render.tsx b/render.tsx index 8fc19c4..9292b53 100644 --- a/render.tsx +++ b/render.tsx @@ -180,25 +180,24 @@ const h = ( }); // configuration -let unoTheme: unknown = undefined; -const setTheme = (theme: unknown) => { - unoTheme = theme; - return unoTheme; -}; +const uno = createGenerator(), + setTheme = async (theme?: unknown) => { + uno.setConfig({ + presets: [ + presetWind({ dark: "class", variablePrefix: "uno-" }), + presetIcons(await iconifyCollections("twemoji", "ph")), + ], + theme: theme ?? undefined, + }); + }; +await setTheme(); // renderers const renderStylesheet = async (className: string) => { - const uno = createGenerator({ - presets: [ - presetWind({ dark: "class", variablePrefix: "uno-" }), - presetIcons(await iconifyCollections("twemoji", "ph")), - ], - theme: unoTheme, - }), - { css } = await uno.generate( - className, // - { id: undefined, scope: undefined, minify: true }, - ); + const { css } = await uno.generate( + className, // + { id: undefined, scope: undefined, minify: true }, + ); return css; }, renderIsland = async ($: JSX.Element | JSX.Element[]) => {