Skip to content

Commit

Permalink
chore: pref
Browse files Browse the repository at this point in the history
  • Loading branch information
MellowCo committed Jul 22, 2023
1 parent 8056b28 commit 593b0a0
Show file tree
Hide file tree
Showing 19 changed files with 92 additions and 81 deletions.
2 changes: 1 addition & 1 deletion examples/uniapp_vue3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"@dcloudio/vite-plugin-uni": "3.0.0-alpha-3070020230117001",
"@iconify/json": "^2.2.70",
"typescript": "^5.0.4",
"unocss": "^0.53.4",
"unocss": "^0.53.6",
"unocss-preset-weapp": "link:../../",
"vite": "^4.0.3"
}
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,25 +90,25 @@
},
"dependencies": {
"@rollup/pluginutils": "^5.0.2",
"@unocss/core": "^0.53.5",
"@unocss/extractor-arbitrary-variants": "^0.53.5",
"@unocss/core": "^0.53.6",
"@unocss/extractor-arbitrary-variants": "^0.53.6",
"unplugin-attributify-to-class": "^0.2.4",
"unplugin-transform-class": "^0.4.1"
"unplugin-transform-class": "^0.5.1"
},
"devDependencies": {
"@antfu/eslint-config": "^0.39.8",
"@antfu/ni": "^0.21.5",
"@types/node": "^20.4.2",
"@unocss/autocomplete": "^0.53.5",
"@types/node": "^20.4.3",
"@unocss/autocomplete": "^0.53.6",
"bumpp": "^9.1.1",
"eslint": "^8.45.0",
"eslint-formatter-mo": "^1.2.0",
"magic-string": "^0.30.1",
"msw": "^1.2.2",
"msw": "^1.2.3",
"taze": "^0.11.2",
"typescript": "^5.1.6",
"unbuild": "^1.2.1",
"vite": "^4.4.4",
"vite": "^4.4.6",
"vitest": "^0.33.0"
}
}
80 changes: 45 additions & 35 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Preset, PresetOptions } from '@unocss/core'
import { defaultRules, transformEscapESelector } from 'unplugin-transform-class/utils'
import { cacheTransformEscapESelector, defaultRules } from 'unplugin-transform-class/utils'
import { extractorArbitraryVariants } from '@unocss/extractor-arbitrary-variants'
import preflights from './preflights'
import { rules } from './rules'
Expand Down Expand Up @@ -173,7 +173,7 @@ export function presetWeapp(options: PresetWeappOptions = {}): Preset<Theme> {
postprocess(css) {
// 是否转义class
if (options.transform)
css.selector = transformEscapESelector(css.selector, options.transformRules)
css.selector = cacheTransformEscapESelector(css.selector, options.transformRules)

// 设置变量前缀
if (options.variablePrefix !== 'un-')
Expand Down
4 changes: 2 additions & 2 deletions src/rules/animation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Rule } from '@unocss/core'
import { restoreSelector } from 'unplugin-transform-class/utils'
import { cacheRestoreSelector } from 'unplugin-transform-class/utils'
import { globalKeywords, handler as h, makeGlobalStaticRules } from '../utils'
import type { Theme } from '../'

Expand All @@ -15,7 +15,7 @@ export const animations: Rule<Theme>[] = [
}, { autocomplete: ['animate-keyframes-$animation.keyframes', 'keyframes-$animation.keyframes'] }],

[/^animate-(.+)$/, ([, name], { theme }) => {
name = restoreSelector(name, theme.transformRules)
name = cacheRestoreSelector(name, theme.transformRules)
const kf = theme.animation?.keyframes?.[name]

if (kf) {
Expand Down
4 changes: 2 additions & 2 deletions src/rules/background.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CSSColorValue, Rule, RuleContext } from '@unocss/core'
import { restoreSelector } from 'unplugin-transform-class/utils'
import { cacheRestoreSelector } from 'unplugin-transform-class/utils'
import { colorOpacityToString, colorToString, globalKeywords, handler as h, makeGlobalStaticRules, parseColor, positionMap } from '../utils'
import type { Theme } from '../'

Expand Down Expand Up @@ -72,7 +72,7 @@ const bgLengthRE = /^\[length:.+\]$/
const bgPositionRE = /^\[position:.+\]$/
export const backgroundStyles: Rule<Theme>[] = [
[/^bg-(.+)$/, ([, d], { theme }) => {
d = restoreSelector(d, theme?.transformRules)
d = cacheRestoreSelector(d, theme?.transformRules)
if (bgUrlRE.test(d))
return { '--un-url': h.bracket(d), 'background-image': 'var(--un-url)' }
if (bgLengthRE.test(d) && h.bracketOfLength(d) != null)
Expand Down
5 changes: 3 additions & 2 deletions src/rules/border.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CSSEntries, CSSObject, Rule, RuleContext } from '@unocss/core'
import { restoreSelector } from 'unplugin-transform-class/utils'
import { cacheRestoreSelector } from 'unplugin-transform-class/utils'
import type { Theme } from '../theme'
import { colorOpacityToString, colorToString, cornerMap, directionMap, globalKeywords, handler as h, hasParseableColor, parseColor } from '../utils'

Expand Down Expand Up @@ -113,7 +113,8 @@ function handlerBorderOpacity([, a = '', opacity]: string[]): CSSEntries | undef
}

function handlerRounded([, a = '', s]: string[], { theme }: RuleContext<Theme>): CSSEntries | undefined {
s = restoreSelector(s, theme?.transformRules)
s = cacheRestoreSelector(s, theme?.transformRules)

const v = theme.borderRadius?.[s || 'DEFAULT'] || h.bracket.cssvar.global.fraction.remToRpx(s || '1')
if (a in cornerMap && v != null)
return cornerMap[a].map(i => [`border${i}-radius`, v])
Expand Down
6 changes: 3 additions & 3 deletions src/rules/flex.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Rule } from '@unocss/core'
import { restoreSelector } from 'unplugin-transform-class/utils'
import { cacheRestoreSelector } from 'unplugin-transform-class/utils'
import type { Theme } from '../theme'
import { handler as h } from '../utils'

Expand All @@ -11,7 +11,7 @@ export const flex: Rule<Theme>[] = [

// flex
[/^flex-(.*)$/, ([, d], { theme }) => {
d = restoreSelector(d, theme?.transformRules)
d = cacheRestoreSelector(d, theme?.transformRules)

return { flex: h.bracket(d) != null ? h.bracket(d)!.split(' ').map(e => h.cssvar.fraction(e) ?? e).join(' ') : h.cssvar.fraction(d) }
}],
Expand All @@ -24,7 +24,7 @@ export const flex: Rule<Theme>[] = [
[/^(?:flex-)?shrink(?:-(.*))?$/, ([, d = '']) => ({ 'flex-shrink': h.bracket.cssvar.number(d) ?? 1 }), { autocomplete: ['flex-shrink-<num>', 'shrink-<num>'] }],
[/^(?:flex-)?grow(?:-(.*))?$/, ([, d = '']) => ({ 'flex-grow': h.bracket.cssvar.number(d) ?? 1 }), { autocomplete: ['flex-grow-<num>', 'grow-<num>'] }],
[/^(?:flex-)?basis-(.+)$/, ([, d], { theme }) => {
d = restoreSelector(d, theme?.transformRules)
d = cacheRestoreSelector(d, theme?.transformRules)
return { 'flex-basis': theme.spacing?.[d] ?? h.bracket.cssvar.auto.fraction.remToRpx(d) }
},
{ autocomplete: ['flex-basis-$spacing', 'basis-$spacing'] }],
Expand Down
4 changes: 2 additions & 2 deletions src/rules/position.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CSSEntries, Rule, RuleContext, StaticRule } from '@unocss/core'
import { restoreSelector } from 'unplugin-transform-class/utils'
import { cacheRestoreSelector } from 'unplugin-transform-class/utils'
import type { Theme } from '../theme'
import { globalKeywords, handler as h, insetMap, makeGlobalStaticRules } from '../utils'

Expand Down Expand Up @@ -109,7 +109,7 @@ export const flexGridJustifiesAlignments = [...justifies, ...alignments]
])

function handleInsetValue(v: string, { theme }: RuleContext<Theme>): string | number | undefined {
v = restoreSelector(v, theme?.transformRules)
v = cacheRestoreSelector(v, theme?.transformRules)
return theme.spacing?.[v] ?? (theme?.whRpx ? h.bracket.cssvar.global.auto.fraction.rpx(v) : h.bracket.cssvar.global.auto.fraction.remToRpx(v))
}

Expand Down
4 changes: 2 additions & 2 deletions src/rules/shadow.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Rule } from '@unocss/core'
import { restoreSelector } from 'unplugin-transform-class/utils'
import { cacheRestoreSelector } from 'unplugin-transform-class/utils'
import type { Theme } from '../theme'
import { colorResolver, colorableShadows, handler as h, hasParseableColor } from '../utils'
import { varEmpty } from './static'
Expand All @@ -15,7 +15,7 @@ export const boxShadows: Rule<Theme>[] = [
[/^shadow(?:-(.+))?$/, (match, context) => {
let [, d] = match
const { theme } = context
d = restoreSelector(d, theme.transformRules)
d = cacheRestoreSelector(d, theme.transformRules)

const v = theme.boxShadow?.[d || 'DEFAULT']
const c = d ? h.bracket.cssvar(d) : undefined
Expand Down
4 changes: 2 additions & 2 deletions src/rules/size.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Rule } from '@unocss/core'
import { restoreSelector } from 'unplugin-transform-class/utils'
import { cacheRestoreSelector } from 'unplugin-transform-class/utils'
import type { Theme } from '../theme'
import { handler as h, resolveBreakpoints, resolveVerticalBreakpoints } from '../utils'

Expand All @@ -17,7 +17,7 @@ function getPropName(minmax: string, hw: string) {
type SizeProps = 'width' | 'height' | 'maxWidth' | 'maxHeight' | 'minWidth' | 'minHeight' | 'inlineSize' | 'blockSize' | 'maxInlineSize' | 'maxBlockSize' | 'minInlineSize' | 'minBlockSize'

function getSizeValue(minmax: string, hw: string, theme: Theme, prop: string) {
prop = restoreSelector(prop, theme?.transformRules)
prop = cacheRestoreSelector(prop, theme?.transformRules)

const str = getPropName(minmax, hw)
.replace(/-(\w)/g, (_, p) => p.toUpperCase()) as SizeProps
Expand Down
Loading

0 comments on commit 593b0a0

Please sign in to comment.