Skip to content

Commit

Permalink
[update]add new rules
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderXL committed Dec 23, 2024
1 parent 320ace5 commit e238722
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 25 deletions.
1 change: 1 addition & 0 deletions packages/unocss-base/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { presetUno } from '@unocss/preset-uno'
// eslint-disable-next-line
const remRE = /(-?[\.\d]+)rem/g

// todo process.env.MPX_CURRENT_TARGET_MODE
export default function presetMpx (options = {}) {
const uno = presetUno(options)
const { baseFontSize = 37.5 } = options
Expand Down
11 changes: 11 additions & 0 deletions packages/unocss-base/lib/rn.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,24 @@ export default function presetRnMpx (options = {}) {
name: '@mpxjs/unocss-preset-rn',
...presetRn,
theme: {
preflightRoot: [],
letterSpacing: {
tighter: '-0.5px',
tight: '-0.25px',
normal: '0px',
wide: '0.25px',
wider: '0.5px',
widest: '1px'
},
boxShadow: {
DEFAULT: '0 1px 3px rgba(0 0 0 / 0.1)',
none: '0 0 rgba(0 0 0 / 0)',
sm: '0 1px 2px rgba(0 0 0 / 0.05)',
md: '0 4px 6px rgba(0 0 0 / 0.1)',
lg: '0 10px 15px rgba(0 0 0 / 0.1)',
xl: '0 20px 25px rgba(0 0 0 / 0.1)',
'2xl': '0 25px 50px rgba(0 0 0 / 0.25)',
inner: 'inset 0 2px 4px 0 rgb(0 0 0 / 0.05)'
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion packages/unocss-base/preset-rn/rules/behaviors.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { imageRenderings, overscrolls, listStyle } from '@unocss/preset-wind/rules'
import { outline } from '@unocss/preset-mini/rules'
import { transformEmptyRule } from '../../utils/index.js'

// todo
Expand All @@ -8,6 +9,7 @@ export default [
...transformEmptyRule(
overscrolls,
imageRenderings,
listStyle
listStyle,
outline
)
]
4 changes: 4 additions & 0 deletions packages/unocss-base/preset-rn/rules/divider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { divides } from '@unocss/preset-wind/rules'
import { transformEmptyRule } from '../../utils/index.js'

export default transformEmptyRule(divides)
6 changes: 5 additions & 1 deletion packages/unocss-base/preset-rn/rules/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import behaviors from './behaviors.js'
import layout from './layout.js'
import filters from './filters.js'
import staticRule from './static.js'
import divider from './divider.js'
import ring from './ring.js'

export default [
...color,
Expand All @@ -17,5 +19,7 @@ export default [
...behaviors,
...layout,
...filters,
...staticRule
...staticRule,
...divider,
...ring
]
4 changes: 4 additions & 0 deletions packages/unocss-base/preset-rn/rules/ring.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { rings } from '@unocss/preset-mini/rules'
import { transformEmptyRule } from '../../utils'

export default transformEmptyRule(rings)
33 changes: 12 additions & 21 deletions packages/unocss-base/preset-rn/rules/shadow.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
import { boxShadowsBase, boxShadows } from '@unocss/preset-mini/rules'
import { colorableShadows, colorResolver, h, hasParseableColor } from '@unocss/preset-mini/utils'

const findShadowColorRule = () => {
return boxShadows.find(rule => {
if (rule[0] instanceof RegExp && rule[0].test('shadow')) {
return rule
}
return false
}) || []
}

const shadowColorRule = findShadowColorRule()
const boxShadows = [
[/^shadow(?:-(.+))?$/, (match, context) => {
const [, d] = match
const { theme } = context
const v = theme.boxShadow?.[d || 'DEFAULT']
const c = d ? h.bracket.cssvar(d) : undefined

export default [
[shadowColorRule[0], (match, context) => {
const rawHandler = shadowColorRule[1]
const rawResult = rawHandler(match, context)
if (rawResult['box-shadow']) {
if ((v != null || c != null) && !hasParseableColor(c, theme, 'shadowColor')) {
return {
...boxShadowsBase,
...rawResult
'box-shadow': colorableShadows(v || c, '--un-shadow-color').join(',')
}
} else {
// 工具类
return rawResult
}
return colorResolver('--un-shadow-color', 'shadow', 'shadowColor')(match, context)
}]
]

export default boxShadows
5 changes: 3 additions & 2 deletions packages/unocss-base/preset-rn/rules/static.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { backgroundBlendModes } from '@unocss/preset-wind/rules'
import { backgroundBlendModes, mixBlendModes } from '@unocss/preset-wind/rules'
import { transformEmptyRule } from '../../utils/index.js'

export default transformEmptyRule(
backgroundBlendModes
backgroundBlendModes,
mixBlendModes
)

0 comments on commit e238722

Please sign in to comment.