Skip to content

Commit ef76b2d

Browse files
zouhangwithsweetclark.zou
andauthored
feat!: compat to preset wind4 (#31)
* feat: compat to preset wind4 * chore: upgrade pnpm action to v4 in CI and release workflows * chore: update unocss and related dependencies to version 66.5.0, add npm registry configuration * chore: update dependencies in pnpm-lock.yaml to latest versions * chore: bump version to 1.0.0 in package.json --------- Co-authored-by: clark.zou <clark.zou@zoom.us>
1 parent a227e41 commit ef76b2d

13 files changed

Lines changed: 1766 additions & 627 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
node-version: ${{ matrix.node }}
3030

3131
- name: Install pnpm
32-
uses: pnpm/action-setup@v3
32+
uses: pnpm/action-setup@v4
3333
with:
3434
run_install: |
3535
- args: [--frozen-lockfile]

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
registry-url: "https://registry.npmjs.org"
2828

2929
- name: Install pnpm
30-
uses: pnpm/action-setup@v3
30+
uses: pnpm/action-setup@v4
3131
with:
3232
run_install: |
3333
- args: [--frozen-lockfile]

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
registry=https://registry.npmjs.org/
12
ignore-workspace-root-check=true

build.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { defineBuildConfig } from 'unbuild'
22

33
export default defineBuildConfig({
4-
entries: ['src/index'],
4+
entries: ['src/index', 'src/v3'],
55
declaration: true,
66
clean: true,
77
rollup: {

package.json

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "unocss-preset-shadcn",
33
"type": "module",
4-
"version": "0.5.0",
4+
"version": "1.0.0",
55
"packageManager": "pnpm@10.6.2",
66
"description": "use shadcn ui with unocss",
77
"author": "Stephen Zhou <hi@hyoban.cc>",
@@ -27,6 +27,16 @@
2727
"types": "./dist/index.d.cts",
2828
"default": "./dist/index.cjs"
2929
}
30+
},
31+
"./v3": {
32+
"import": {
33+
"types": "./dist/v3.d.mts",
34+
"default": "./dist/v3.mjs"
35+
},
36+
"require": {
37+
"types": "./dist/v3.d.cts",
38+
"default": "./dist/v3.cjs"
39+
}
3040
}
3141
},
3242
"main": "./dist/index.cjs",
@@ -61,17 +71,16 @@
6171
"@antfu/ni": "^24.1.0",
6272
"@antfu/utils": "^9.1.0",
6373
"@types/node": "^22.13.10",
64-
"@unocss/preset-mini": "^66.1.0-beta.3",
74+
"@unocss/preset-mini": "^66.5.0",
6575
"eslint": "^9.22.0",
6676
"eslint-config-hyoban": "^4.0.1",
6777
"lint-staged": "^15.5.0",
68-
"pnpm": "^10.6.2",
6978
"release-it": "^18.1.2",
7079
"release-it-pnpm": "^4.6.4",
7180
"simple-git-hooks": "^2.11.1",
7281
"typescript": "^5.8.2",
7382
"unbuild": "^3.5.0",
74-
"unocss": "^66.1.0-beta.3",
83+
"unocss": "^66.5.0",
7584
"vite": "^6.2.1",
7685
"vitest": "^3.0.8"
7786
},

pnpm-lock.yaml

Lines changed: 640 additions & 567 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/generate.ts

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { mergeDeep } from 'unocss'
22

3-
import type { ThemeCSSVarKey, ThemeCSSVars, ThemeCSSVarsVariant } from './themes'
4-
import { themeCSSVarKeys, themes } from './themes'
3+
import type { ThemeCSSVarKey, ThemeCSSVars, ThemeCSSVarsVariant, themes } from './themes/v3'
4+
import { themeCSSVarKeys } from './themes/v3'
55
import type { ColorOptions, PresetShadcnThemeOptions } from './types'
66

77
function generateColorCSSVars(color: ThemeCSSVars) {
@@ -38,7 +38,7 @@ ${generateRadiusCSSVars(radius)}
3838
`
3939
}
4040

41-
export function generateGlobalStyles() {
41+
export function generateGlobalStylesV3() {
4242
return `
4343
* {
4444
border-color: hsl(var(--border));
@@ -51,8 +51,21 @@ body {
5151
`
5252
}
5353

54-
function getBuiltInTheme(name: string): ThemeCSSVarsVariant {
55-
const theme = themes.find(t => t.name === name)
54+
export function generateGlobalStyles() {
55+
return `
56+
* {
57+
border-color: oklch(var(--border));
58+
}
59+
60+
body {
61+
color: oklch(var(--foreground));
62+
background: oklch(var(--background));
63+
}
64+
`
65+
}
66+
67+
function getBuiltInTheme(name: string, themesRaw: typeof themes): ThemeCSSVarsVariant {
68+
const theme = themesRaw.find(t => t.name === name)
5669
if (!theme)
5770
throw new Error(`Unknown color: ${name}`)
5871
return {
@@ -61,18 +74,18 @@ function getBuiltInTheme(name: string): ThemeCSSVarsVariant {
6174
}
6275
}
6376

64-
function getColorTheme(color: ColorOptions) {
77+
function getColorTheme(color: ColorOptions, themesRaw: typeof themes) {
6578
let light: ThemeCSSVars
6679
let dark: ThemeCSSVars
6780
let name: string
6881

6982
if (typeof color === 'string') {
7083
name = color
71-
;({ light, dark } = getBuiltInTheme(color))
84+
;({ light, dark } = getBuiltInTheme(color, themesRaw))
7285
}
7386
else if ('base' in color) {
7487
name = color.base
75-
;({ light, dark } = mergeDeep(getBuiltInTheme(color.base), color))
88+
;({ light, dark } = mergeDeep(getBuiltInTheme(color.base, themesRaw), color))
7689
}
7790
else {
7891
name = color.name
@@ -83,10 +96,11 @@ function getColorTheme(color: ColorOptions) {
8396

8497
export function generateCSSVars(
8598
theme: PresetShadcnThemeOptions,
99+
themesRaw: typeof themes,
86100
onlyOne = true,
87101
): string {
88102
if (Array.isArray(theme))
89-
return theme.map(t => generateCSSVars(t, false)).join('\n')
103+
return theme.map(t => generateCSSVars(t, themesRaw, false)).join('\n')
90104

91105
const { color = 'zinc', radius = 0.5, darkSelector = '.dark' } = theme
92106

@@ -97,7 +111,7 @@ export function generateCSSVars(
97111
cssStyle += radiusCSSVarsStyles(radius)
98112
}
99113
else {
100-
const { light, dark, name } = getColorTheme(color)
114+
const { light, dark, name } = getColorTheme(color, themesRaw)
101115
const lightVars = generateColorCSSVars(light)
102116
const darkVars = generateColorCSSVars(dark)
103117

src/index.ts

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import type { Preset } from 'unocss'
22
import type { Theme } from 'unocss/preset-mini'
33

44
import { generateCSSVars, generateGlobalStyles } from './generate'
5-
import { themes } from './themes'
5+
import type { themes as themesV3 } from './themes/v3'
6+
import { themes } from './themes/v4'
67
import type { PresetShadcnControlOptions, PresetShadcnThemeOptions } from './types'
78

89
export const builtinColors = themes.map(theme => theme.name)
@@ -24,7 +25,7 @@ export function presetShadcn(
2425
@keyframes shadcn-collapsible-down { from{ height: 0 } to { height: var(--${componentLibrary}-collapsible-content-height)} }
2526
@keyframes shadcn-collapsible-up { from{ height: var(--${componentLibrary}-collapsible-content-height)} to { height: 0 } }
2627
27-
${generateCSSVars(themeOptions)}
28+
${generateCSSVars(themeOptions, themes as unknown as typeof themesV3)}
2829
2930
${globals ? generateGlobalStyles() : ''}
3031
`,
@@ -58,58 +59,58 @@ export function presetShadcn(
5859
],
5960
theme: {
6061
colors: {
61-
border: 'hsl(var(--border))',
62-
input: 'hsl(var(--input))',
63-
ring: 'hsl(var(--ring))',
64-
background: 'hsl(var(--background))',
65-
foreground: 'hsl(var(--foreground))',
62+
border: 'oklch(var(--border))',
63+
input: 'oklch(var(--input))',
64+
ring: 'oklch(var(--ring))',
65+
background: 'oklch(var(--background))',
66+
foreground: 'oklch(var(--foreground))',
6667
primary: {
67-
DEFAULT: 'hsl(var(--primary))',
68-
foreground: 'hsl(var(--primary-foreground))',
68+
DEFAULT: 'oklch(var(--primary))',
69+
foreground: 'oklch(var(--primary-foreground))',
6970
},
7071
secondary: {
71-
DEFAULT: 'hsl(var(--secondary))',
72-
foreground: 'hsl(var(--secondary-foreground))',
72+
DEFAULT: 'oklch(var(--secondary))',
73+
foreground: 'oklch(var(--secondary-foreground))',
7374
},
7475
destructive: {
75-
DEFAULT: 'hsl(var(--destructive))',
76-
foreground: 'hsl(var(--destructive-foreground))',
76+
DEFAULT: 'oklch(var(--destructive))',
77+
foreground: 'oklch(var(--destructive-foreground))',
7778
},
7879
muted: {
79-
DEFAULT: 'hsl(var(--muted))',
80-
foreground: 'hsl(var(--muted-foreground))',
80+
DEFAULT: 'oklch(var(--muted))',
81+
foreground: 'oklch(var(--muted-foreground))',
8182
},
8283
accent: {
83-
DEFAULT: 'hsl(var(--accent))',
84-
foreground: 'hsl(var(--accent-foreground))',
84+
DEFAULT: 'oklch(var(--accent))',
85+
foreground: 'oklch(var(--accent-foreground))',
8586
},
8687
popover: {
87-
DEFAULT: 'hsl(var(--popover))',
88-
foreground: 'hsl(var(--popover-foreground))',
88+
DEFAULT: 'oklch(var(--popover))',
89+
foreground: 'oklch(var(--popover-foreground))',
8990
},
9091
card: {
91-
DEFAULT: 'hsl(var(--card))',
92-
foreground: 'hsl(var(--card-foreground))',
92+
DEFAULT: 'oklch(var(--card))',
93+
foreground: 'oklch(var(--card-foreground))',
9394
},
94-
chart1: 'hsl(var(--chart1))',
95-
chart2: 'hsl(var(--chart2))',
96-
chart3: 'hsl(var(--chart3))',
97-
chart4: 'hsl(var(--chart4))',
98-
chart5: 'hsl(var(--chart5))',
95+
chart1: 'oklch(var(--chart1))',
96+
chart2: 'oklch(var(--chart2))',
97+
chart3: 'oklch(var(--chart3))',
98+
chart4: 'oklch(var(--chart4))',
99+
chart5: 'oklch(var(--chart5))',
99100
sidebar: {
100-
DEFAULT: 'hsl(var(--sidebar-background))',
101-
background: 'hsl(var(--sidebar-background))',
102-
foreground: 'hsl(var(--sidebar-foreground))',
101+
DEFAULT: 'oklch(var(--sidebar-background))',
102+
background: 'oklch(var(--sidebar-background))',
103+
foreground: 'oklch(var(--sidebar-foreground))',
103104
primary: {
104-
DEFAULT: 'hsl(var(--sidebar-primary))',
105-
foreground: 'hsl(var(--sidebar-primary-foreground))',
105+
DEFAULT: 'oklch(var(--sidebar-primary))',
106+
foreground: 'oklch(var(--sidebar-primary-foreground))',
106107
},
107108
accent: {
108-
DEFAULT: 'hsl(var(--sidebar-accent))',
109-
foreground: 'hsl(var(--sidebar-accent-foreground))',
109+
DEFAULT: 'oklch(var(--sidebar-accent))',
110+
foreground: 'oklch(var(--sidebar-accent-foreground))',
110111
},
111-
border: 'hsl(var(--sidebar-border))',
112-
ring: 'hsl(var(--sidebar-ring))',
112+
border: 'oklch(var(--sidebar-border))',
113+
ring: 'oklch(var(--sidebar-ring))',
113114
},
114115
},
115116
borderRadius: {
File renamed without changes.

0 commit comments

Comments
 (0)