postcss-pxtransform 3.5.4-alpha.0 → 3.5.4-canary.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +27 -0
- package/lib/pixel-upper-unit-regex.js +11 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const postcss = require('postcss')
|
|
4
4
|
const pxRegex = require('./lib/pixel-unit-regex')
|
|
5
|
+
const PXRegex = require('./lib/pixel-upper-unit-regex')
|
|
5
6
|
const filterPropList = require('./lib/filter-prop-list')
|
|
6
7
|
|
|
7
8
|
const defaults = {
|
|
@@ -62,6 +63,11 @@ module.exports = postcss.plugin('postcss-pxtransform', function (options = {}) {
|
|
|
62
63
|
targetUnit = 'px'
|
|
63
64
|
break
|
|
64
65
|
}
|
|
66
|
+
case 'harmony': {
|
|
67
|
+
options.rootValue = input => 1 / options.deviceRatio[designWidth(input)]
|
|
68
|
+
targetUnit = 'px'
|
|
69
|
+
break
|
|
70
|
+
}
|
|
65
71
|
default: {
|
|
66
72
|
// mini-program
|
|
67
73
|
options.rootValue = input => 1 / options.deviceRatio[designWidth(input)]
|
|
@@ -107,6 +113,27 @@ module.exports = postcss.plugin('postcss-pxtransform', function (options = {}) {
|
|
|
107
113
|
})
|
|
108
114
|
}
|
|
109
115
|
|
|
116
|
+
// PX -> vp in harmony
|
|
117
|
+
if (options.platform === 'harmony') {
|
|
118
|
+
css.walkDecls(function (decl) {
|
|
119
|
+
if (decl.value.indexOf('PX') === -1) return
|
|
120
|
+
const value = decl.value.replace(PXRegex, function (m, _$1, $2) {
|
|
121
|
+
return m.replace($2, 'vp')
|
|
122
|
+
})
|
|
123
|
+
decl.value = value
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
if (opts.mediaQuery) {
|
|
127
|
+
css.walkAtRules('media', function (rule) {
|
|
128
|
+
if (rule.params.indexOf('PX') === -1) return
|
|
129
|
+
const value = rule.params.replace(PXRegex, function (m, _$1, $2) {
|
|
130
|
+
return m.replace($2, 'vp')
|
|
131
|
+
})
|
|
132
|
+
rule.params = value
|
|
133
|
+
})
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
110
137
|
/* #ifdef %PLATFORM% */
|
|
111
138
|
// 平台特有样式
|
|
112
139
|
/* #endif */
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/*eslint-disable*/
|
|
2
|
+
|
|
3
|
+
// excluding regex trick: http://www.rexegg.com/regex-best-trick.html
|
|
4
|
+
|
|
5
|
+
// Not anything inside double quotes
|
|
6
|
+
// Not anything inside single quotes
|
|
7
|
+
// Not anything inside url()
|
|
8
|
+
// Any digit followed by PX
|
|
9
|
+
// !singlequotes|!doublequotes|!url()|pixelunit
|
|
10
|
+
|
|
11
|
+
module.exports = /"[^"]+"|'[^']+'|url\([^\)]+\)|(\d*\.?\d+)(PX)/g
|