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 rn atomic css #1788

Open
wants to merge 61 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
68434b2
[feat]rn-atomic-css
CommanderXL Nov 8, 2024
a88cdd9
[fix]lint
CommanderXL Nov 8, 2024
f9ab9c1
[feat]add empty rule transform
CommanderXL Nov 14, 2024
e39ec8a
[feat]add warn&errors
CommanderXL Nov 14, 2024
450f76b
[feat]add shadow rule
CommanderXL Nov 14, 2024
777dcca
[fix]lint
CommanderXL Nov 14, 2024
c414f17
[feat]add more rules
CommanderXL Nov 19, 2024
ff99449
update
CommanderXL Nov 21, 2024
7e90afe
[feat]support hover pseudo class
CommanderXL Nov 22, 2024
386c0ff
[feat]add hasUnoCSS for template compiler
CommanderXL Nov 22, 2024
11ddc5b
[feat]add new rule and upgrade unocss version
CommanderXL Dec 3, 2024
2034a02
[update]
CommanderXL Dec 3, 2024
372ab91
[feat]support modern rgb/hsl grammer
CommanderXL Dec 3, 2024
99dd414
[update]extra code
CommanderXL Dec 5, 2024
7c9f994
feat: upgrade unocss
mater1996 Dec 5, 2024
27c13ac
[fix]formatValue
CommanderXL Dec 6, 2024
3da4fee
fix: preset
mater1996 Dec 10, 2024
f898f6b
fix: type
mater1996 Dec 10, 2024
792cde2
Merge branch 'feat-rn-atomic-css' of github.com:didi/mpx into feat-rn…
mater1996 Dec 10, 2024
cc0cbf8
fix: unocss ready
mater1996 Dec 10, 2024
13fd97d
fix: uno存储问题
mater1996 Dec 10, 2024
f3789ca
fix: mpx instance
mater1996 Dec 17, 2024
d86b308
fix: remove debugg
mater1996 Dec 17, 2024
dc50729
fix: lint
mater1996 Dec 17, 2024
57ce2f8
fix: remove console
mater1996 Dec 17, 2024
c933e3e
Merge pull request #1741 from didi/feat-rn-atomic-css-upgrade
CommanderXL Dec 17, 2024
320ace5
fix: minimatch
mater1996 Dec 17, 2024
abf1b6f
feat: preset
mater1996 Dec 18, 2024
ea891f8
feat: preset
mater1996 Dec 20, 2024
e238722
[update]add new rules
CommanderXL Dec 23, 2024
dbccab7
fix: rules
mater1996 Dec 23, 2024
f5f4160
fix: console
mater1996 Dec 23, 2024
dc6373f
[update]optimize combine preset
CommanderXL Dec 23, 2024
b5e03c4
fix: divide support
mater1996 Dec 23, 2024
c4c9825
[feat]support dark mode
CommanderXL Dec 24, 2024
8d21de4
[update]typograph rule
CommanderXL Dec 24, 2024
a3dacd4
[update]border rule
CommanderXL Dec 24, 2024
30e96f7
fix: preset
mater1996 Dec 24, 2024
f0adcbb
fix: transform
mater1996 Dec 24, 2024
eaaf945
fix: transform
mater1996 Dec 24, 2024
c5cbd43
fix: format
mater1996 Dec 25, 2024
7e1327e
fix: support rule
mater1996 Dec 25, 2024
8161d1b
fix: wx build error
mater1996 Dec 26, 2024
77e9d1a
fix: import
mater1996 Dec 26, 2024
b918849
fix: 移除transform从一些工具类
mater1996 Dec 26, 2024
dd43b07
[update]preset
CommanderXL Dec 26, 2024
aa2a250
[merge]merge from master
CommanderXL Dec 26, 2024
9466418
Merge branch 'feat-rn-atomic-css' of github.com:didi/mpx into feat-rn…
CommanderXL Dec 26, 2024
db17b59
[fix]
CommanderXL Dec 26, 2024
45e2202
Merge branch 'feat-rn-atomic-css' of github.com:didi/mpx into feat-rn…
CommanderXL Dec 26, 2024
dc6a12f
[fix]merge code from master
CommanderXL Dec 26, 2024
01b76bf
Merge branch 'feat-rn-atomic-css' of github.com:didi/mpx into feat-rn…
CommanderXL Dec 26, 2024
6d7a499
[fix]some method
CommanderXL Dec 26, 2024
769f7c7
[fix]some error
CommanderXL Dec 26, 2024
ce5fbd3
[fix]lint
CommanderXL Dec 26, 2024
5be0325
[update]the order of unocss and app css
CommanderXL Dec 26, 2024
e14884b
little adjust
CommanderXL Dec 26, 2024
f9b4b40
Merge pull request #1767 from didi/feat-uno-rn-preset
CommanderXL Dec 26, 2024
c66de72
[update]clear code
CommanderXL Dec 26, 2024
459165e
[update]decoration & filter
CommanderXL Dec 26, 2024
c6dbef1
[update]add font theme
CommanderXL Dec 27, 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
2 changes: 1 addition & 1 deletion legacy/windicss-plugin/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class MpxWindicssPlugin {
if (filepath) {
compilation.fileDependencies.add(filepath)
// fix jiti require cache for watch
delete require.cache[filepath]
// delete require.cache[filepath]
}

if (!config) {
Expand Down
68 changes: 35 additions & 33 deletions packages/core/src/platform/builtInMixins/styleHelperMixin.ios.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isObject, isArray, dash2hump, cached, isEmptyObject } from '@mpxjs/utils'
import { Dimensions, StyleSheet } from 'react-native'
import { Dimensions, StyleSheet, Appearance } from 'react-native'

let { width, height } = Dimensions.get('screen')

Expand Down Expand Up @@ -43,35 +43,6 @@ function formatValue (value) {

global.__formatValue = formatValue

const escapeReg = /[()[\]{}#!.:,%'"+$]/g
const escapeMap = {
'(': '_pl_',
')': '_pr_',
'[': '_bl_',
']': '_br_',
'{': '_cl_',
'}': '_cr_',
'#': '_h_',
'!': '_i_',
'/': '_s_',
'.': '_d_',
':': '_c_',
',': '_2c_',
'%': '_p_',
'\'': '_q_',
'"': '_dq_',
'+': '_a_',
$: '_si_'
}

const mpEscape = cached((str) => {
return str.replace(escapeReg, function (match) {
if (escapeMap[match]) return escapeMap[match]
// unknown escaped
return '_u_'
})
})

function concat (a = '', b = '') {
return a ? b ? (a + ' ' + b) : a : b
}
Expand Down Expand Up @@ -170,17 +141,19 @@ export default function styleHelperMixin () {
__getStyle (staticClass, dynamicClass, staticStyle, dynamicStyle, hide) {
const result = {}
const classMap = this.__getClassMap?.() || {}
const unoClassMap = global.__getUnoClassMap?.() || {}
const appClassMap = global.__getAppClassMap?.() || {}

if (staticClass || dynamicClass) {
// todo 当前为了复用小程序unocss产物,暂时进行mpEscape,等后续正式支持unocss后可不进行mpEscape
const classString = mpEscape(concat(staticClass, stringifyDynamicClass(dynamicClass)))
const classString = concat(staticClass, stringifyDynamicClass(dynamicClass))
classString.split(/\s+/).forEach((className) => {
if (classMap[className]) {
Object.assign(result, classMap[className])
} else if (appClassMap[className]) {
// todo 全局样式在每个页面和组件中生效,以支持全局原子类,后续支持样式模块复用后可考虑移除
Object.assign(result, appClassMap[className])
} else if (unoClassMap[className]) {
Object.assign(result, unoClassMap[className])
} else if (this.__props[className] && isObject(this.__props[className])) {
// externalClasses必定以对象形式传递下来
Object.assign(result, this.__props[className])
Expand All @@ -198,8 +171,37 @@ export default function styleHelperMixin () {
display: 'none'
})
}

return isEmptyObject(result) ? empty : result
},
__getDynamicClass (dynamicClass, mediaQueryClass) {
return [dynamicClass, this.__getMediaQueryClass(mediaQueryClass)]
},
__getMediaQueryClass (mediaQueryClass = []) {
if (!mediaQueryClass.length) return ''
const { width, height } = Dimensions.get('screen')
const colorScheme = Appearance.getColorScheme()
const { entries, entriesMap } = global.__getUnoBreakpoints()
return mediaQueryClass.map(([className, querypoints = []]) => {
const res = querypoints.every(([prefix = '', point = 0]) => {
if (prefix === 'landscape') return width > height
if (prefix === 'portrait') return width <= height
if (prefix === 'dark') return colorScheme === 'dark'
if (prefix === 'light') return colorScheme === 'light'
const size = formatValue(entriesMap[point] || point)
const index = entries.findIndex(item => item[0] === point)
const isGtPrefix = prefix.startsWith('min-')
const isLtPrefix = prefix.startsWith('lt-') || prefix.startsWith('<') || prefix.startsWith('max-')
const isAtPrefix = prefix.startsWith('at-') || prefix.startsWith('~')
if (isGtPrefix) return width > size
if (isLtPrefix) return width < size
if (isAtPrefix && (index && index < entries.length - 1)) {
return width >= size && width < formatValue(entries[index + 1][1])
}
return width > size
})

return res ? className : ''
})
}
}
}
Expand Down
18 changes: 14 additions & 4 deletions packages/unocss-base/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
const { presetUno } = require('@unocss/preset-uno')
import { presetUno } from '@unocss/preset-uno'
import presetRn from '../preset-rn/index.js'

// eslint-disable-next-line
const remRE = /(-?[\.\d]+)rem/g

module.exports = function presetMpx (options = {}) {
export default function presetMpx (options = {}) {
const mpxCurrentTargetMode = process.env.MPX_CURRENT_TARGET_MODE
const isReact = mpxCurrentTargetMode === 'ios' || mpxCurrentTargetMode === 'android'
const extraPresets = []
if (isReact) {
extraPresets.push(presetRn())
options.dark = 'media'
}
const uno = presetUno(options)
const { baseFontSize = 37.5 } = options

return {
...uno,
name: '@mpxjs/unocss-base',
Expand All @@ -17,11 +26,12 @@ module.exports = function presetMpx (options = {}) {
util.entries.forEach((i) => {
const value = i[1]
if (typeof value === 'string' && remRE.test(value)) {
i[1] = value.replace(remRE, (_, p1) => process.env.MPX_CURRENT_TARGET_MODE === 'web'
i[1] = value.replace(remRE, (_, p1) => mpxCurrentTargetMode === 'web'
? `${p1 * baseFontSize * (100 / 750).toFixed(8)}vw`
: `${p1 * baseFontSize}rpx`)
}
})
}
},
presets: extraPresets
}
}
3 changes: 2 additions & 1 deletion packages/unocss-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"directories": {
"lib": "lib"
},
"type": "module",
"scripts": {},
"author": "",
"license": "Apache-2.0",
Expand All @@ -14,6 +15,6 @@
"access": "public"
},
"dependencies": {
"@unocss/preset-uno": "^0.52.7"
"@unocss/preset-uno": "^0.65.1"
}
}
10 changes: 10 additions & 0 deletions packages/unocss-base/preset-rn/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import rules from './rules/index.js'
import theme from './theme.js'

export default function presetRnMpx () {
return {
name: '@mpxjs/unocss-preset-rn',
rules,
theme
}
}
38 changes: 38 additions & 0 deletions packages/unocss-base/preset-rn/rules/align.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { textAligns, verticalAligns } from '@unocss/preset-mini/rules'
import { findRawRules, ruleCallback, transformEmptyRule } from '../../utils/index.js'

const support = [
'mid',
'start',
'btm',
'end',
'auto',
'top',
'bottom',
'middle'
]

const verticalAlignsRules = verticalAligns.map(v => {
const [regex, matcher, ...another] = v
return [
regex,
(...args) => {
const [[, v]] = args
if (support.includes(v)) return matcher(...args)
return ruleCallback(...args)
},
...another
]
})

const textAlignValuesRules = transformEmptyRule(
findRawRules(
['text-start', 'text-end', 'text-align-start', 'text-align-end'],
textAligns
)
)

export {
verticalAlignsRules as verticalAligns,
textAlignValuesRules as textAligns
}
6 changes: 6 additions & 0 deletions packages/unocss-base/preset-rn/rules/animation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { animations } from '@unocss/preset-wind/rules'
import { transformEmptyRule } from '../../utils/index.js'

const animationsRules = transformEmptyRule(animations)

export { animationsRules as animations }
21 changes: 21 additions & 0 deletions packages/unocss-base/preset-rn/rules/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { backgroundStyles } from '@unocss/preset-wind/rules'
import { findRawRules, transformEmptyRule } from '../../utils/index.js'

// todo background-position 剔除
const NewBackgroundRules = transformEmptyRule(findRawRules(
[
// attachments
'bg-fixed',
'bg-locale',
'bg-scroll',
// repeat
/^bg-repeat-?.*/,
// origins
/^bg-origin-.*/,
// clips
/^bg-clip-.*/
],
backgroundStyles
))

export { NewBackgroundRules as backgroundStyles }
17 changes: 17 additions & 0 deletions packages/unocss-base/preset-rn/rules/behaviors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { imageRenderings, overscrolls, listStyle, accents, carets } from '@unocss/preset-wind/rules'
import { appearance, outline, willChange } from '@unocss/preset-mini/rules'
import { transformEmptyRule } from '../../utils/index.js'

export default [
...transformEmptyRule(
overscrolls,
imageRenderings,
listStyle,
outline,
willChange,
appearance,
accents,
carets,
willChange
)
]
17 changes: 17 additions & 0 deletions packages/unocss-base/preset-rn/rules/border.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { borders } from '@unocss/preset-mini/rules'
import { ruleCallback } from '../../utils/index.js'

const bordersRules = borders.map(v => {
const [regex, matcher, ...another] = v
return [
regex,
(...args) => {
const [[, a]] = args
if (['block', 'inline'].includes(a)) return ruleCallback(...args)
return matcher(...args)
},
...another
]
})

export default bordersRules
6 changes: 6 additions & 0 deletions packages/unocss-base/preset-rn/rules/color.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { colorScheme } from '@unocss/preset-mini/rules'
import { transformEmptyRule } from '../../utils/index.js'

const colorSchemeRules = transformEmptyRule(colorScheme)

export { colorSchemeRules as colorScheme }
6 changes: 6 additions & 0 deletions packages/unocss-base/preset-rn/rules/columns.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { columns } from '@unocss/preset-wind/rules'
import { transformEmptyRule } from '../../utils/index.js'

const columnsRules = transformEmptyRule(columns)

export { columnsRules as columns }
11 changes: 11 additions & 0 deletions packages/unocss-base/preset-rn/rules/container.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { containerParent } from '@unocss/preset-mini/rules'
import { container } from '@unocss/preset-wind/rules'
import { transformEmptyRule } from '../../utils/index.js'

const containerParentRules = transformEmptyRule(containerParent)
const containerRules = transformEmptyRule(container)

export {
containerParentRules as containerParent,
containerRules as container
}
38 changes: 38 additions & 0 deletions packages/unocss-base/preset-rn/rules/decoration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { textDecorations } from '@unocss/preset-mini/rules'
import { transformEmptyRule, ruleCallback, findRawRules } from '../../utils/index.js'

const unSupport = [
'auto',
'from-font',
'overline'
]

const textDecorationsRules = textDecorations.map(v => {
const [regex, matcher, ...another] = v
if (typeof matcher === 'function') {
return [
regex,
(...args) => {
const [[, v]] = args
if (unSupport.includes(v)) return ruleCallback(...args)
const res = matcher(...args)
if (res['text-decoration-thickness'] || res['text-underline-offset']) {
return ruleCallback(...args)
}
return res
},
...another
]
}
return v
})

const textDecorationsWavyStyle = transformEmptyRule(
findRawRules(['underline-wavy', 'decoration-wavy'], textDecorationsRules)
)

textDecorationsRules.push(...textDecorationsWavyStyle)

export {
textDecorationsRules as textDecorations
}
6 changes: 6 additions & 0 deletions packages/unocss-base/preset-rn/rules/divide.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { divides } from '@unocss/preset-wind/rules'
import { transformEmptyRule } from '../../utils/index.js'

const divideRules = transformEmptyRule(divides)

export { divideRules as divides }
Loading
Loading