Skip to content

Commit 627941f

Browse files
committed
chore: bump unocss from 0.59.4 to 66.5.2
1 parent 6c31d71 commit 627941f

File tree

8 files changed

+501
-419
lines changed

8 files changed

+501
-419
lines changed

docs/tutorialkit.dev/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@
3131
"sharp": "^0.32.6",
3232
"starlight-links-validator": "^0.9.0",
3333
"typescript": "^5.4.5",
34-
"unocss": "^0.59.4"
34+
"unocss": "66.5.2"
3535
}
3636
}

e2e/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@
2727
"@types/node": "^22.2.0",
2828
"@types/react": "^18.3.3",
2929
"@types/react-dom": "^18.3.0",
30-
"@unocss/reset": "^0.59.4",
31-
"@unocss/transformer-directives": "^0.62.0",
30+
"@unocss/reset": "66.5.2",
31+
"@unocss/transformer-directives": "66.5.2",
3232
"astro": "^4.15.0",
3333
"fast-glob": "^3.3.2",
3434
"playwright": "^1.46.0",
3535
"react": "^18.3.1",
3636
"react-dom": "^18.3.1",
37-
"unocss": "^0.59.4",
37+
"unocss": "66.5.2",
3838
"unzipper": "^0.12.3"
3939
}
4040
}

e2e/test/topbar.test.ts

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { readdirSync, readFileSync, rmSync } from 'node:fs';
33
import type { Readable } from 'node:stream';
44
import { test, expect } from '@playwright/test';
55
import * as unzipper from 'unzipper';
6-
import { theme } from '../../packages/theme/src/theme';
6+
import { theme } from '../../packages/theme/src/theme.js';
77

88
test('user can change theme', async ({ page }) => {
99
await page.goto('/');
@@ -13,12 +13,43 @@ test('user can change theme', async ({ page }) => {
1313

1414
// default light theme
1515
await expect(html).toHaveAttribute('data-theme', 'light');
16-
await expect(heading).toHaveCSS('color', hexToRGB(theme.colors.gray[800]));
16+
17+
/**
18+
* Normalize both the expected token and the computed style to canonical rgba(...) to
19+
* avoid mismatches caused by different color-space serializations (oklab vs rgb)
20+
*/
21+
const normalizeColor = (cssColor: string) =>
22+
page.evaluate((c: string) => {
23+
const canvas = document.createElement('canvas');
24+
canvas.width = 1;
25+
canvas.height = 1;
26+
27+
const ctx = canvas.getContext('2d');
28+
29+
if (!ctx) {
30+
return c;
31+
}
32+
33+
ctx.clearRect(0, 0, 1, 1);
34+
ctx.fillStyle = c;
35+
ctx.fillRect(0, 0, 1, 1);
36+
37+
const d = ctx.getImageData(0, 0, 1, 1).data;
38+
39+
return 'rgba(' + d[0] + ', ' + d[1] + ', ' + d[2] + ', ' + d[3] / 255 + ')';
40+
}, cssColor);
41+
42+
const expectedLight = await normalizeColor(hexToRGB(theme.colors.gray[800]));
43+
const observedLightRgba = await normalizeColor(await heading.evaluate((el) => getComputedStyle(el).color));
44+
expect(observedLightRgba).toBe(expectedLight);
1745

1846
await page.getByRole('navigation').getByRole('button', { name: 'Toggle Theme' }).click();
1947

2048
await expect(html).toHaveAttribute('data-theme', 'dark');
21-
await expect(heading).toHaveCSS('color', hexToRGB(theme.colors.gray[200]));
49+
50+
const expectedDark = await normalizeColor(hexToRGB(theme.colors.gray[200]));
51+
const observedDarkRgba = await normalizeColor(await heading.evaluate((el) => getComputedStyle(el).color));
52+
expect(observedDarkRgba).toBe(expectedDark);
2253
});
2354

2455
test('user can download project as zip', async ({ page }) => {

packages/astro/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"@tutorialkit/theme": "workspace:*",
4545
"@tutorialkit/types": "workspace:*",
4646
"@types/react": "^18.3.3",
47-
"@unocss/reset": "^0.62.2",
47+
"@unocss/reset": "66.5.2",
4848
"@webcontainer/api": "1.5.1",
4949
"astro": "^4.15.0",
5050
"astro-expressive-code": "^0.35.3",
@@ -61,7 +61,7 @@
6161
"remark-directive": "^3.0.0",
6262
"unified": "^11.0.5",
6363
"unist-util-visit": "^5.0.0",
64-
"unocss": "^0.59.4",
64+
"unocss": "66.5.2",
6565
"zod": "3.23.8"
6666
},
6767
"devDependencies": {

packages/astro/src/remark/callouts.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ export function remarkCalloutsPlugin() {
106106
const hideIcon = attributes.hideIcon === 'true';
107107

108108
const classes = [
109-
`callout callout-${variant} my-4 flex flex-col p-3 bg-tk-elements-markdown-callouts-backgroundColor text-tk-elements-markdown-callouts-textColor`,
109+
`callout callout-${variant} my-4 flex flex-col p-3 bg-[var(--tk-elements-markdown-callouts-backgroundColor)] text-[var(--tk-elements-markdown-callouts-textColor)]`,
110110
attributes.class ?? '',
111-
...(noBorder ? [] : ['border-l-3', 'border-tk-elements-markdown-callouts-borderColor']),
111+
...(noBorder ? [] : ['border-l-3', 'border-[var(--tk-elements-markdown-callouts-borderColor)]']),
112112
];
113113

114114
node.attributes = {
@@ -139,7 +139,7 @@ function generate(title: string, children: any[], callout: Callout, hideIcon: bo
139139
data: {
140140
hName: 'div',
141141
hProperties: {
142-
className: 'w-full flex gap-2 items-center text-tk-elements-markdown-callouts-titleTextColor',
142+
className: 'w-full flex gap-2 items-center text-[var(--tk-elements-markdown-callouts-titleTextColor)]',
143143
ariaHidden: true,
144144
},
145145
},
@@ -149,7 +149,7 @@ function generate(title: string, children: any[], callout: Callout, hideIcon: bo
149149
: ([
150150
{
151151
type: 'html',
152-
value: `<span class="text-6 inline-block text-tk-elements-markdown-callouts-iconColor ${callout.icon}"></span>`,
152+
value: `<span class="text-6 inline-block text-[var(--tk-elements-markdown-callouts-iconColor)] ${callout.icon}"></span>`,
153153
},
154154
] satisfies Children)),
155155
{

packages/theme/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"@iconify-json/ph": "^1.1.13",
3636
"@iconify-json/svg-spinners": "^1.1.2",
3737
"fast-glob": "^3.3.2",
38-
"unocss": "^0.59.4"
38+
"unocss": "66.5.2"
3939
},
4040
"devDependencies": {
4141
"@types/node": "^22.4.1",

packages/theme/src/index.ts

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import * as fastGlob from 'fast-glob';
12
import fs from 'node:fs/promises';
23
import { createRequire } from 'node:module';
34
import { basename, dirname, resolve } from 'node:path';
4-
import * as fastGlob from 'fast-glob';
5-
import { mergeConfigs, presetIcons, presetUno, transformerDirectives, type UserConfig } from 'unocss';
5+
import { mergeConfigs, presetIcons, presetWind4, transformerDirectives, type UserConfig } from 'unocss';
66

77
import { theme } from './theme.js';
88
import { transitionTheme } from './transition-theme.js';
@@ -26,16 +26,16 @@ export function defineConfig(config: UserConfig) {
2626
}),
2727
},
2828
presets: [
29-
presetUno({
29+
presetWind4({
3030
dark: {
3131
dark: '[data-theme="dark"]',
3232
},
3333
}),
3434
presetIcons({
3535
collections: {
3636
...readCustomIcons(),
37-
ph: () => import('@iconify-json/ph').then((i) => i.icons),
38-
'svg-spinners': () => import('@iconify-json/svg-spinners').then((i) => i.icons),
37+
ph: () => loadIconifyCollection('ph'),
38+
'svg-spinners': () => loadIconifyCollection('svg-spinners'),
3939
},
4040
}),
4141
],
@@ -87,3 +87,51 @@ const shortcuts: UserConfig['shortcuts'] = {
8787
'panel-button':
8888
'flex items-center gap-1.5 whitespace-nowrap rounded-md text-sm transition-theme bg-tk-elements-panel-headerButton-backgroundColor hover:bg-tk-elements-panel-headerButton-backgroundColorHover text-tk-elements-panel-headerButton-textColor hover:text-tk-elements-panel-headerButton-textColorHover',
8989
};
90+
91+
async function loadIconifyCollection(name: string) {
92+
// Try to require the package (works for CJS or when package exposes a CJS entry)
93+
try {
94+
// use createRequire to ensure resolution from the package context
95+
96+
const pkg = require(`@iconify-json/${name}`);
97+
98+
if (pkg && pkg.icons) {
99+
return pkg.icons;
100+
}
101+
} catch {
102+
// fallthrough to fs-based resolution
103+
}
104+
105+
// Fall back: resolve package root and try to find a JSON file with icons
106+
try {
107+
const pkgJsonPath = require.resolve(`@iconify-json/${name}/package.json`, { paths: [process.cwd()] });
108+
const pkgRoot = dirname(pkgJsonPath);
109+
110+
// Common icon file names
111+
const candidates = ['icons.json', 'index.json', 'icons/index.json'];
112+
113+
for (const cand of candidates) {
114+
try {
115+
const full = resolve(pkgRoot, cand);
116+
const text = await fs.readFile(full, 'utf8');
117+
const parsed = JSON.parse(text);
118+
119+
if (parsed && parsed.icons) {
120+
return parsed.icons;
121+
}
122+
123+
// sometimes the package itself *is* the icons object
124+
if (parsed && Object.keys(parsed).length) {
125+
return parsed;
126+
}
127+
} catch {
128+
// try next candidate
129+
}
130+
}
131+
} catch {
132+
// give up
133+
}
134+
135+
// Last resort: return an empty collection to avoid throwing at build-time
136+
return {};
137+
}

0 commit comments

Comments
 (0)