diff --git a/packages/taro-cli/src/quickapp/style/declaration/background/index.ts b/packages/taro-cli/src/quickapp/style/declaration/background/index.ts index ba84191e1d92..c3e3ec515e6d 100644 --- a/packages/taro-cli/src/quickapp/style/declaration/background/index.ts +++ b/packages/taro-cli/src/quickapp/style/declaration/background/index.ts @@ -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:' } diff --git a/packages/taro-cli/src/quickapp/style/declaration/border/index.ts b/packages/taro-cli/src/quickapp/style/declaration/border/index.ts index 6dfea0334261..807f1c8684a7 100644 --- a/packages/taro-cli/src/quickapp/style/declaration/border/index.ts +++ b/packages/taro-cli/src/quickapp/style/declaration/border/index.ts @@ -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' diff --git a/packages/taro-cli/src/quickapp/style/declaration/dimension/index.ts b/packages/taro-cli/src/quickapp/style/declaration/dimension/index.ts index 9eeeca09f8f3..1f3c071cc13d 100644 --- a/packages/taro-cli/src/quickapp/style/declaration/dimension/index.ts +++ b/packages/taro-cli/src/quickapp/style/declaration/dimension/index.ts @@ -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) { @@ -18,7 +20,9 @@ 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) { @@ -26,5 +30,11 @@ export default { return 'I:' } return '' + }, + 'display': (value, declaration, addDeclaration) => { + if (~['flex', 'none'].indexOf(value)) { + return '' + } + return 'I:' } } diff --git a/packages/taro-cli/src/quickapp/style/declaration/transform/transform.ts b/packages/taro-cli/src/quickapp/style/declaration/transform/transform.ts index dca247ae3c3b..87f01d1cb221 100644 --- a/packages/taro-cli/src/quickapp/style/declaration/transform/transform.ts +++ b/packages/taro-cli/src/quickapp/style/declaration/transform/transform.ts @@ -9,5 +9,9 @@ export default { if (~value.indexOf('%')) { return 'I:' } + //不能同时出现translateX和translateY + if(~value.indexOf('translateX') && ~value.indexOf('translateY')) { + return 'I:' + } } } diff --git a/packages/taro-cli/src/quickapp/style/selector/index.ts b/packages/taro-cli/src/quickapp/style/selector/index.ts index 2301050146b5..ce738a382b68 100644 --- a/packages/taro-cli/src/quickapp/style/selector/index.ts +++ b/packages/taro-cli/src/quickapp/style/selector/index.ts @@ -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 .') } diff --git a/packages/taro-cli/src/quickapp/style/util.ts b/packages/taro-cli/src/quickapp/style/util.ts index 340602f6bcd3..be464aba2148 100644 --- a/packages/taro-cli/src/quickapp/style/util.ts +++ b/packages/taro-cli/src/quickapp/style/util.ts @@ -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 }