Skip to content

Commit

Permalink
fix#4288 根据1050的快应用规范刷新样式规则
Browse files Browse the repository at this point in the history
  • Loading branch information
Qiyu8 committed Aug 30, 2019
1 parent 21c70ef commit 63b400d
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,41 @@ export default {
addDeclaration('background-image', value)
} else {
// 颜色值为transparent时忽略
if (!~value.indexOf('transparent')) {
if (!~value.indexOf('transparent') || !~value.indexOf('-webkit')) {
addDeclaration('background-color', value)
}
}
return 'I:'
},
'background-color': (value, declaration, addDeclaration) => {
if (~value.indexOf('transparent')) {
if (~value.indexOf('transparent') || !~value.indexOf('-webkit')) {
return 'I:'
}
},
'background-image': '',
'background-size': '',
'background-repeat': 'I:',
'background-size': (value, declaration, addDeclaration) => {
//最多支持2个参数,比如50% 50%
const len = value.split(' ')
if (len <= 2) {
return ''
}
return 'I:'
},
'background-repeat': (value, declaration, addDeclaration) => {
const validValue = ['repeat', 'repeat-x', 'repeat-y', 'no-repeat']
if (~validValue.indexOf(value)) {
return ''
}
return 'I:'
},
'background-attachment': 'I:',
'background-position': 'I:',
'background-position': (value, declaration, addDeclaration) => {
//不支持逗号分隔
if (~value.indexOf(',')) {
return 'I:'
}
return ''
},
'background-origin': 'I:',
'background-clip': 'I:'
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ export default {
setWidth(value, declaration)
},
'border-radius': (value, declaration, addDeclaration) => { // width也不支持百分数,后期在转换
if (~value.indexOf(' ')) {
return 'I:'
}
if (~value.indexOf('%')) {
// 其实应当按照当前组件的宽高为基准计算,但这里拿不到,暂时这样处理下。
value = 750 / 100 * parseInt(value) + 'px'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ export default {
'height': (value, declaration, addDeclaration) => {
if (~value.indexOf('auto') || ~value.indexOf('inherit')) {
addDeclaration('display', 'flex') // 部分应用利用height:0,height:auto来实现隐藏,显示
// addDeclaration('flex-direction', 'row')
return 'I:'
}
if (~value.indexOf('calc')) {
return 'I:'
}
if (parseInt(value) === 0) {
Expand All @@ -18,13 +20,21 @@ export default {
'width': (value, declaration, addDeclaration) => {
if (~value.indexOf('auto') || ~value.indexOf('inherit')) {
addDeclaration('display', 'flex') // 部分应用利用height:0,height:auto来实现隐藏,显示
// addDeclaration('flex-direction', 'row')
return 'I:'
}
if (~value.indexOf('calc')) {
return 'I:'
}
if (parseInt(value) === 0) {
addDeclaration('display', 'none') // 部分应用利用height:0,height:auto来实现隐藏,显示
return 'I:'
}
return ''
},
'display': (value, declaration, addDeclaration) => {
if (~['flex', 'none'].indexOf(value)) {
return ''
}
return 'I:'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ export default {
if (~value.indexOf('%')) {
return 'I:'
}
//不能同时出现translateX和translateY
if(~value.indexOf('translateX') && ~value.indexOf('translateY')) {
return 'I:'
}
}
}
3 changes: 2 additions & 1 deletion packages/taro-cli/src/quickapp/style/selector/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ export default function rewriter (selector, rule, output) {
}
return ''
}).join('')
return selector
//替换.a.b.c .e.d为.a .b .c .e .d
return selector.replace(/(\w)\./g, '$1 .')
}
6 changes: 4 additions & 2 deletions packages/taro-cli/src/quickapp/style/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ const processDeclarationValueUnit = v => {
} else if (~lowerCaseV.indexOf('px')) {
const numberV = parseFloat(lowerCaseV)
if (!isNaN(numberV)) {
return numberV * 2 + 'px'
return v.replace(numberV, numberV * 2)
}
} else if (~lowerCaseV.indexOf('em')) {
const numberV = parseFloat(lowerCaseV)
if (!isNaN(numberV)) {
return numberV * defaultFontSize + 'px'
return lowerCaseV.replace(numberV, numberV * defaultFontSize).replace('em', 'px')
}
} else if (~lowerCaseV.indexOf('vh')) {
return lowerCaseV.replace('vh', 'px')
}
return v
}
Expand Down

0 comments on commit 63b400d

Please sign in to comment.