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

fix: inline import css compressed & upgrade deps #9

Merged
merged 20 commits into from
Mar 19, 2024
Merged
1 change: 1 addition & 0 deletions .eslintcache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"/Users/chris/projects/unocss-preset-useful/test/preflights.test.ts":"1"},{"size":806,"mtime":1710865966010,"results":"2","hashOfConfig":"3"},{"filePath":"4","messages":"5","suppressedMessages":"6","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"vaw7uk","/Users/chris/projects/unocss-preset-useful/test/preflights.test.ts",[],[]]
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ dist
*.log
.vscode
data
.eslintcache
27 changes: 14 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,25 @@
"magicAnimate": "esno scripts/magicAnimate.ts"
},
"devDependencies": {
"@antfu/eslint-config": "2.6.3",
"@babel/types": "^7.23.9",
"@antfu/eslint-config": "2.8.0",
"@babel/types": "^7.24.0",
"@types/fs-extra": "^11.0.4",
"@types/node": "^20.11.10",
"@types/node": "^20.11.25",
"@types/postcss-js": "^4.0.4",
"@unocss/eslint-plugin": "^0.58.4",
"bumpp": "^9.3.0",
"eslint": "^8.56.0",
"esno": "^4.0.0",
"@unocss/eslint-plugin": "^0.58.5",
"bumpp": "^9.4.0",
"eslint": "^8.57.0",
"esno": "^4.7.0",
"fs-extra": "^11.2.0",
"lint-staged": "^15.2.0",
"simple-git-hooks": "^2.9.0",
"typescript": "5.3.3",
"lint-staged": "^15.2.2",
"magic.css": "^1.4.8",
"simple-git-hooks": "^2.10.0",
"typescript": "5.4.2",
"unbuild": "^2.0.0",
"unocss": "^0.58.4",
"unocss": "^0.58.5",
"unocss-preset-useful": "workspace:*",
"vite": "^5.0.12",
"vitest": "^1.2.2"
"vite": "^5.1.5",
"vitest": "^1.3.1"
},
"simple-git-hooks": {
"pre-commit": "npx lint-staged"
Expand Down
22 changes: 10 additions & 12 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,16 @@
"stub": "unbuild --stub"
},
"dependencies": {
"@unocss/core": "^0.58.0",
"@unocss/preset-attributify": "^0.58.0",
"@unocss/preset-icons": "^0.58.0",
"@unocss/preset-mini": "^0.58.0",
"@unocss/preset-rem-to-px": "^0.58.0",
"@unocss/preset-tagify": "^0.58.0",
"@unocss/preset-typography": "^0.58.0",
"@unocss/preset-uno": "^0.58.0",
"@unocss/preset-web-fonts": "^0.58.0",
"magic.css": "^1.4.8",
"postcss": "^8.4.32",
"@unocss/preset-attributify": "^0.58.5",
"@unocss/preset-icons": "^0.58.5",
"@unocss/preset-mini": "^0.58.5",
"@unocss/preset-rem-to-px": "^0.58.5",
"@unocss/preset-tagify": "^0.58.5",
"@unocss/preset-typography": "^0.58.5",
"@unocss/preset-uno": "^0.58.5",
"@unocss/preset-web-fonts": "^0.58.5",
"postcss": "^8.4.35",
"postcss-js": "^4.0.1",
"unocss-preset-scrollbar": "latest"
"unocss-preset-scrollbar": "^0.3.1"
}
}
2 changes: 1 addition & 1 deletion packages/core/src/core/autocomplete.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { UserConfig } from '@unocss/core'
import type { UserConfig } from 'unocss'
import { magicAnimate } from './theme/magic-animate'

const keyframes = magicAnimate()?.keyframes ?? {}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/core/extractors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Extractor } from '@unocss/core'
import type { Extractor } from 'unocss'

// IN-README-START
// https://github.com/unocss/unocss/pull/2485
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/core/postprocess.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Postprocessor } from '@unocss/core'
import type { Postprocessor } from 'unocss'

const rgbaRE = /rgba\(((?:\d+,?){3}),([^)]*)\)/

Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/core/preflights/reset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,11 @@ Make elements with the HTML hidden attribute stay hidden by default.
}
`.trim()

function compressCSS(css: string) {
return css.replace(/[\s\r\n]+/g, ' ').replace(/\/\*[\s\S]*?\*\//g, '')
}

export const resetPreflight: Preflight = {
getCSS: () => resetCSS,
getCSS: () => compressCSS(resetCSS),
layer: layerMeta.layer,
}
2 changes: 1 addition & 1 deletion packages/core/src/core/rules.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { parseColor } from '@unocss/preset-mini/utils'
import type { Rule, RuleMeta } from '@unocss/core'
import type { Rule, RuleMeta } from 'unocss'
import { layerMeta } from '../meta'

// IN-README-START
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/core/shortcuts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RuleMeta, StaticShortcut } from '@unocss/core'
import type { RuleMeta, StaticShortcut } from 'unocss'
import { layerMeta } from '../meta'
import type { CustomStaticShortcuts } from '../types'

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/core/variants/active.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { VariantObject } from '@unocss/core'
import type { VariantObject } from 'unocss'

export const v_active: VariantObject = {
name: '@active',
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/core/variants/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Variant } from '@unocss/core'
import type { Variant } from 'unocss'
import type { Theme } from '@unocss/preset-mini'
import type { ResolvedOptions } from '../../types'
import { v_active } from './active'
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Postprocessor, PresetFactory } from 'unocss'
import { definePreset } from '@unocss/core'
import { definePreset } from 'unocss'
import { PRESET_NAME } from './meta'
import { autocomplete, extractors, preflights, rules, shortcuts, variants } from './core'
import { importantProcess, postprocessWithUnColor } from './core/postprocess'
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/meta.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RuleMeta } from '@unocss/core'
import type { RuleMeta } from 'unocss'

export const PRESET_NAME = 'useful'

Expand Down
20 changes: 9 additions & 11 deletions packages/core/src/resolve.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { presetAttributify } from '@unocss/preset-attributify'
import { presetIcons } from '@unocss/preset-icons'
import type { Theme } from '@unocss/preset-uno'
import { presetUno } from '@unocss/preset-uno'
import presetTagify from '@unocss/preset-tagify'
import { presetTypography } from '@unocss/preset-typography'
import presetWebFonts from '@unocss/preset-web-fonts'
import remToPxPreset from '@unocss/preset-rem-to-px'
import type { Theme } from '@unocss/preset-mini'
import { presetAttributify, presetIcons, presetTagify, presetTypography, presetUno, presetWebFonts } from 'unocss'
import presetRemToPx from '@unocss/preset-rem-to-px'
import { presetScrollbar } from 'unocss-preset-scrollbar'
import { nomarlizeTheme } from './core'
import type { CustomStaticShortcuts, ResolvedOptions, UsefulOptions, UsefulTheme } from './types'
Expand Down Expand Up @@ -41,13 +36,16 @@ export function resolveOptions(options: UsefulOptions) {
webFonts: presetWebFonts,
typography: presetTypography,
tagify: presetTagify,
remToPx: remToPxPreset,
remToPx: presetRemToPx,
scrollbar: presetScrollbar,
}

for (const [key, preset] of Object.entries(presetMap)) {
const option = optionsWithDefault[key as keyof typeof presetMap]
if (option)
presets.push(preset(typeof option === 'boolean' ? {} as any : option))
if (option) {
const p = preset as any
presets.push(p(typeof option === 'boolean' ? {} as any : option))
}
}

const { theme: t_theme, shortcuts } = resolveExtend(optionsWithDefault.theme.extend ?? {})
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import type { TypographyOptions } from '@unocss/preset-typography'
import type { TagifyOptions } from '@unocss/preset-tagify'
import type { RemToPxOptions } from '@unocss/preset-rem-to-px'
import type { PresetScrollbarDefaultOption } from 'unocss-preset-scrollbar'
import type { Preset, StaticShortcut } from '@unocss/core'
import type { Theme } from '@unocss/preset-mini'
import type { CSSObject } from 'unocss'
import type { CSSObject, Preset, StaticShortcut } from 'unocss'

type CustomStaticShortcut = [string | string[], StaticShortcut[1]] | [string | string[], StaticShortcut[1], StaticShortcut[2]]
export type CustomStaticShortcuts = CustomStaticShortcut[]
Expand Down
1 change: 0 additions & 1 deletion playground/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + Vue + TS</title>
</head>
Expand Down
2 changes: 1 addition & 1 deletion playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"private": true,
"scripts": {
"dev": "vite",
"build": "vue-tsc && vite build",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
Expand Down
1 change: 0 additions & 1 deletion playground/src/vite-env.d.ts

This file was deleted.

6 changes: 3 additions & 3 deletions playground/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import Vue from '@vitejs/plugin-vue'
import UnoCSS from 'unocss/vite'

// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
UnoCSS('../uno.config.ts'),
Vue(),
UnoCSS('../unocss.config.ts') as any,
],
})
Loading
Loading