Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(preset-mini): add rawColorComment #3887

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e58f2ea
feat(preset-mini): add originThemeColor option
Simon-He95 May 30, 2024
307af4e
chore: test
Simon-He95 May 30, 2024
e72611d
chore: lint
Simon-He95 May 30, 2024
2ad5bc8
Merge branch 'main' into originThemeColor
Simon-He95 May 31, 2024
cc4b502
chore: use envMode replace new param
Simon-He95 Jun 1, 2024
e1e622c
Merge branch 'main' into originThemeColor
Simon-He95 Jun 1, 2024
49ac24c
chore: update
Simon-He95 Jun 1, 2024
f7b3108
chore: update
antfu Jun 1, 2024
4276573
Merge branch 'main' into originThemeColor
Simon-He95 Jun 1, 2024
95738c1
Merge branch 'main' into originThemeColor
Simon-He95 Jun 1, 2024
2628220
Merge branch 'main' into originThemeColor
Simon-He95 Jun 8, 2024
4ed0312
Merge branch 'main' into originThemeColor
antfu Jun 11, 2024
d696af5
Merge branch 'main' into originThemeColor
Simon-He95 Jun 11, 2024
3a191fc
chore: update
Simon-He95 Jun 12, 2024
532f9b0
test: move test files for better organize
antfu Jun 11, 2024
9aeae59
feat(preset-mini): Add support for peer and group variants on aria-* …
Johnkat-Mj Jun 11, 2024
b9a660c
docs: add unocss-transformer-classnames-minifier to community transfo…
alisobirjanov Jun 11, 2024
82bdf08
feat(core): support generator in rule matcher (#3884)
antfu Jun 11, 2024
3bf8d5f
fix(preset-mini): `transform-cpu` should not include `rotate-x` and `…
zzc6332 Jun 11, 2024
b5e22b7
feat(core): introduce special symbols for applying custom variants (#…
antfu Jun 11, 2024
0c838d5
chore: update deps
antfu Jun 11, 2024
3698df9
chore: update deps
antfu Jun 11, 2024
3dea37d
chore: release v0.61.0
antfu Jun 11, 2024
5a42410
feat(preset-mini): add originThemeColor option
Simon-He95 May 30, 2024
934519a
chore: test
Simon-He95 May 30, 2024
74e3d11
chore: lint
Simon-He95 May 30, 2024
8c8dea9
chore: use envMode replace new param
Simon-He95 Jun 1, 2024
b38e14d
chore: update
Simon-He95 Jun 1, 2024
8dcbe4b
chore: update
Simon-He95 Jun 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions bench/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.60.4",
"version": "0.61.0",
"scripts": {
"bench": "node run.mjs"
},
Expand All @@ -10,9 +10,9 @@
"fs-extra": "^11.2.0",
"local-pkg": "^0.5.0",
"postcss": "^8.4.38",
"tailwindcss": "^3.4.3",
"tailwindcss": "^3.4.4",
"unocss": "workspace:*",
"vite": "^5.2.12",
"vite": "^5.2.13",
"vite-plugin-windicss": "^1.9.3",
"vue": "^3.4.27",
"windicss": "^3.5.6"
Expand Down
112 changes: 89 additions & 23 deletions docs/config/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,95 @@ the corresponding CSS will be generated:

Congratulations! Now you've got your own powerful atomic CSS utilities. Enjoy!

## Ordering

UnoCSS respects the order of the rules you defined in the generated CSS. Latter ones come with higher priority.

When using dynamic rules, it may match multiple tokens. By default, the output of those matched under a single dynamic rule will be sorted alphabetically within the group.

## Rules merging

By default, UnoCSS will merge CSS rules with the same body to minimize the CSS size.

For example, `<div class="m-2 hover:m2">` will generate:

```css
.hover\:m2:hover, .m-2 { margin: 0.5rem; }
```

Instead of two separate rules:

```css
.hover\:m2:hover { margin: 0.5rem; }
.m-2 { margin: 0.5rem; }
```

## Special symbols

Since v0.61, UnoCSS supports special symbols to define additional meta information for your generated CSS. You can access symbols from the second argument of the dynamic rule matcher function.

For example:

```ts
rules: [
[/^grid$/, ([, d], { symbols }) => {
return {
[symbols.parent]: '@supports (display: grid)',
display: 'grid',
}
}],
]
```

Will generate:

```css
@supports (display: grid) {
.grid {
display: grid;
}
}
```

### Available symbols

- `symbols.parent`: The parent wrapper of the generated CSS rule (eg. `@supports`, `@media`, etc.)
- `symbols.selector`: A function to modify the selector of the generated CSS rule (see the example below)
- `symbols.variants`: An array of variant handler that are applied to the current CSS object
- `symbols.shortcutsNoMerge`: A boolean to disable the merging of the current rule in shortcuts

## Multi-selector rules

Since v0.61, UnoCSS supports multi-selector via [JavaScript Generator functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator).

For example:

```ts
rules: [
[/^button-(.*)$/, function* ([, color], { symbols }) {
yield {
background: color
}
yield {
[symbols.selector]: selector => `${selector}:hover`,
// https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/color-mix
background: `color-mix(in srgb, ${color} 90%, black)`
}
}],
]
```

Will generate multiple CSS rules:

```css
.button-red {
background: red;
}
.button-red:hover {
background: color-mix(in srgb, red 90%, black);
}
```

## Fully controlled rules

::: tip
Expand Down Expand Up @@ -113,26 +202,3 @@ ${selector}::after {
],
})
```

## Ordering

UnoCSS respects the order of the rules you defined in the generated CSS. Latter ones come with higher priority.

When using dynamic rules, it may match multiple tokens. By default, the output of those matched under a single dynamic rule will be sorted alphabetically within the group.

## Rules merging

By default, UnoCSS will merge CSS rules with the same body to minimize the CSS size.

For example, `<div class="m-2 hover:m2">` will generate:

```css
.hover\:m2:hover, .m-2 { margin: 0.5rem; }
```

Instead of two separate rules:

```css
.hover\:m2:hover { margin: 0.5rem; }
.m-2 { margin: 0.5rem; }
```
10 changes: 5 additions & 5 deletions docs/package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{
"name": "docs",
"type": "module",
"version": "0.60.4",
"version": "0.61.0",
"private": true,
"scripts": {
"docs:dev": "vitepress dev",
"docs:build": "vitepress build",
"docs:preview": "vitepress preview"
},
"devDependencies": {
"@iconify-json/carbon": "^1.1.34",
"@iconify-json/logos": "^1.1.42",
"@iconify-json/carbon": "^1.1.35",
"@iconify-json/logos": "^1.1.43",
"@iconify-json/mdi": "^1.1.66",
"@iconify-json/ph": "^1.1.13",
"@iconify-json/twemoji": "^1.1.15",
"@iconify-json/vscode-icons": "^1.1.34",
"@iconify-json/vscode-icons": "^1.1.35",
"ofetch": "^1.3.4",
"unocss": "workspace:*",
"vitepress": "^1.2.2"
"vitepress": "^1.2.3"
}
}
1 change: 1 addition & 0 deletions docs/presets/community.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
- [unocss-transformer-attribute-values-group](https://github.com/lvjiaxuan/unocss-transformer-attribute-values-group) - Attribute values group transformer for UnoCSS by [@lvjiaxuan](https://github.com/lvjiaxuan).
- [unocss-transformer-alias](https://github.com/zyyv/unocss-transformer-alias) - Transform alias for UnoCSS shortcuts by [@zyyv](https://github.com/zyyv).
- [CSS to UnoCss](https://github.com/Simon-He95/transformToUnoCSS) - Transform CSS to Unocss by [@Simon-He95](https://github.com/Simon-He95).
- [unocss-transformer-classnames-minifier](https://github.com/alisobirjanov/unocss-transformer-classnames-minifier) - Transform UnoCSS classnames minifier by [@alisobirjanov](https://github.com/alisobirjanov).

# Community tools

Expand Down
6 changes: 3 additions & 3 deletions examples/astro-vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
"vue": "^3.4.27"
},
"devDependencies": {
"@astrojs/vue": "^4.3.0",
"@iconify-json/logos": "^1.1.42",
"@astrojs/vue": "^4.4.0",
"@iconify-json/logos": "^1.1.43",
"@unocss/reset": "link:../../packages/reset",
"astro": "^4.9.2",
"astro": "^4.10.2",
"unocss": "link:../../packages/unocss"
},
"stackblitz": {
Expand Down
4 changes: 2 additions & 2 deletions examples/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"astro": "astro"
},
"devDependencies": {
"@iconify-json/logos": "^1.1.42",
"@iconify-json/logos": "^1.1.43",
"@unocss/reset": "link:../../packages/reset",
"astro": "^4.9.2",
"astro": "^4.10.2",
"canvas-confetti": "^1.9.3",
"unocss": "link:../../packages/unocss"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"react-dom": "18.2.0"
},
"devDependencies": {
"@iconify-json/lucide": "^1.1.188",
"@iconify-json/lucide": "^1.1.191",
"@types/node": "20.8.3",
"@types/react": "18.2.25",
"@types/react-dom": "18.2.11",
Expand Down
2 changes: 1 addition & 1 deletion examples/nuxt2-webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"start": "nuxt start"
},
"devDependencies": {
"@iconify-json/carbon": "^1.1.34",
"@iconify-json/carbon": "^1.1.35",
"@unocss/core": "link:../../packages/core",
"@unocss/nuxt": "link:../../packages/nuxt",
"@unocss/reset": "link:../../packages/reset",
Expand Down
2 changes: 1 addition & 1 deletion examples/nuxt2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"start": "node .output/server/index.mjs"
},
"devDependencies": {
"@iconify-json/carbon": "^1.1.34",
"@iconify-json/carbon": "^1.1.35",
"@nuxt/bridge-edge": "latest",
"@unocss/core": "link:../../packages/core",
"@unocss/nuxt": "link:../../packages/nuxt",
Expand Down
4 changes: 2 additions & 2 deletions examples/nuxt3-layers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
"lint:fix": "nr lint --fix"
},
"devDependencies": {
"@iconify-json/carbon": "^1.1.34",
"@iconify-json/carbon": "^1.1.35",
"@unocss/core": "link:../../packages/core",
"@unocss/eslint-plugin": "link:../../packages/eslint-plugin",
"@unocss/nuxt": "link:../../packages/nuxt",
"@unocss/reset": "link:../../packages/reset",
"nuxt": "^3.11.2",
"nuxt": "^3.12.1",
"unocss": "link:../../packages/unocss"
},
"stackblitz": {
Expand Down
4 changes: 2 additions & 2 deletions examples/nuxt3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
"preview": "nuxi preview"
},
"devDependencies": {
"@iconify-json/carbon": "^1.1.34",
"@iconify-json/carbon": "^1.1.35",
"@unocss/core": "link:../../packages/core",
"@unocss/nuxt": "link:../../packages/nuxt",
"@unocss/reset": "link:../../packages/reset",
"nuxt": "^3.11.2",
"nuxt": "^3.12.1",
"unocss": "link:../../packages/unocss"
},
"stackblitz": {
Expand Down
2 changes: 1 addition & 1 deletion examples/quasar/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@quasar/extras": "^1.16.11",
"quasar": "^2.6.0",
"vue": "^3.4.27",
"vue-router": "^4.3.2"
"vue-router": "^4.3.3"
},
"devDependencies": {
"@quasar/app-vite": "^1.9.3",
Expand Down
2 changes: 1 addition & 1 deletion examples/qwik/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@unocss/reset": "link:../../packages/reset",
"typescript": "^5.4.5",
"unocss": "link:../../packages/unocss",
"vite": "^5.2.12"
"vite": "^5.2.13"
},
"stackblitz": {
"installDependencies": false,
Expand Down
2 changes: 1 addition & 1 deletion examples/remix/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"concurrently": "^8.2.2",
"typescript": "^5.4.5",
"unocss": "link:../../packages/unocss",
"vite": "^5.2.12",
"vite": "^5.2.13",
"vite-tsconfig-paths": "^4.3.2"
},
"stackblitz": {
Expand Down
4 changes: 2 additions & 2 deletions examples/remix/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
"resolveJsonModule": true,
"types": ["@remix-run/node", "vite/client"],
"allowJs": true,
"esModuleInterop": true,
"isolatedModules": true,
"strict": true,

// Vite takes care of building everything, not tsc.
"noEmit": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"skipLibCheck": true
},
"include": [
Expand Down
8 changes: 4 additions & 4 deletions examples/sveltekit-preprocess/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"svelte": "./dist/index.js",
"devDependencies": {
"@iconify-json/logos": "^1.1.42",
"@iconify-json/logos": "^1.1.43",
"@sveltejs/adapter-auto": "^3.2.1",
"@sveltejs/kit": "^2.5.10",
"@sveltejs/package": "^2.3.1",
Expand All @@ -33,12 +33,12 @@
"@unocss/preset-icons": "link:../../packages/preset-icons",
"@unocss/svelte-scoped": "link:../../packages/svelte-scoped",
"publint": "^0.2.8",
"svelte": "^4.2.17",
"svelte": "^4.2.18",
"svelte-check": "^3.8.0",
"tslib": "^2.6.2",
"tslib": "^2.6.3",
"typescript": "^5.4.5",
"unocss": "link:../../packages/unocss",
"vite": "^5.2.12"
"vite": "^5.2.13"
},
"stackblitz": {
"installDependencies": false,
Expand Down
8 changes: 4 additions & 4 deletions examples/sveltekit-scoped/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
},
"devDependencies": {
"@iconify-json/logos": "^1.1.42",
"@iconify-json/logos": "^1.1.43",
"@iconify-json/ri": "^1.1.20",
"@julr/unocss-preset-forms": "^0.1.0",
"@sveltejs/adapter-auto": "^3.2.1",
Expand All @@ -18,12 +18,12 @@
"@unocss/core": "link:../../packages/core",
"@unocss/preset-icons": "link:../../packages/preset-icons",
"@unocss/svelte-scoped": "link:../../packages/svelte-scoped",
"svelte": "^4.2.17",
"svelte": "^4.2.18",
"svelte-check": "^3.8.0",
"tslib": "^2.6.2",
"tslib": "^2.6.3",
"typescript": "^5.4.5",
"unocss": "link:../../packages/unocss",
"vite": "^5.2.12"
"vite": "^5.2.13"
},
"stackblitz": {
"installDependencies": false,
Expand Down
8 changes: 4 additions & 4 deletions examples/sveltekit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
},
"devDependencies": {
"@iconify-json/logos": "^1.1.42",
"@iconify-json/logos": "^1.1.43",
"@iconify/utils": "^2.1.24",
"@sveltejs/adapter-auto": "^3.2.1",
"@sveltejs/kit": "^2.5.10",
Expand All @@ -18,12 +18,12 @@
"@unocss/extractor-svelte": "link:../../packages/extractor-svelte",
"@unocss/preset-icons": "link:../../packages/preset-icons",
"@unocss/preset-uno": "link:../../packages/preset-uno",
"svelte": "^4.2.17",
"svelte": "^4.2.18",
"svelte-check": "^3.8.0",
"tslib": "^2.6.2",
"tslib": "^2.6.3",
"typescript": "^5.4.5",
"unocss": "link:../../packages/unocss",
"vite": "^5.2.12"
"vite": "^5.2.13"
},
"stackblitz": {
"installDependencies": false,
Expand Down
Loading