Skip to content

Commit

Permalink
patch: update unocss, use provider cdn for icons
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonwocky committed May 16, 2022
1 parent 98eebd7 commit bee72ed
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 26 deletions.
22 changes: 4 additions & 18 deletions deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,7 @@ export { math, mathHtml } from "https://esm.sh/[email protected]";
export { default as hljs } from "https://esm.sh/[email protected]";
export type { HtmlExtension } from "https://esm.sh/[email protected]/index.d.ts";

export { createGenerator } from "https://cdn.skypack.dev/@unocss/[email protected]";
export { default as presetWind } from "https://cdn.skypack.dev/@unocss/[email protected]";
export { default as presetTypography } from "https://cdn.skypack.dev/@unocss/[email protected]";
export { default as presetIcons } from "https://cdn.skypack.dev/@unocss/[email protected]";

const _iconifyCache = new Map();
export const iconifyCollections = async (...sets: string[]) => {
const reqs = [], sourceUrl = "https://esm.sh/@iconify/[email protected]/json";
for (const set of sets) {
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)) };
};
export { createGenerator } from "https://cdn.skypack.dev/@unocss/[email protected]";
export { default as presetWind } from "https://cdn.skypack.dev/@unocss/[email protected]";
export { default as presetTypography } from "https://cdn.skypack.dev/@unocss/[email protected]";
export { default as presetIcons } from "https://cdn.skypack.dev/@unocss/[email protected]";
17 changes: 9 additions & 8 deletions render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@
* @jsxFrag jsxFrag
*/

import {
createGenerator,
iconifyCollections,
presetIcons,
presetWind,
} from "./deps.ts";
import { createGenerator, presetIcons, presetWind } from "./deps.ts";
import { transform } from "./transform.ts";

declare global {
Expand Down Expand Up @@ -181,11 +176,17 @@ const h = (

// configuration
const uno = createGenerator(),
setTheme = async (theme?: unknown) => {
setTheme = (theme?: unknown) => {
uno.setConfig({
presets: [
presetWind({ dark: "class", variablePrefix: "uno-" }),
presetIcons(await iconifyCollections("twemoji", "ph")),
presetIcons({
cdn: "https://esm.sh/",
extraProperties: {
"display": "inline-block",
"vertical-align": "middle",
},
}),
],
theme: theme ?? undefined,
});
Expand Down

0 comments on commit bee72ed

Please sign in to comment.