postcss-pxtransform 3.5.7-alpha.9 → 3.5.8
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 +51 -69
- package/package.json +5 -8
- package/lib/pixel-upper-unit-regex.js +0 -11
package/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const postcss = require('postcss')
|
|
1
4
|
const pxRegex = require('./lib/pixel-unit-regex')
|
|
2
|
-
const PXRegex = require('./lib/pixel-upper-unit-regex')
|
|
3
5
|
const filterPropList = require('./lib/filter-prop-list')
|
|
4
6
|
|
|
5
7
|
const defaults = {
|
|
@@ -35,7 +37,7 @@ const DEFAULT_WEAPP_OPTIONS = {
|
|
|
35
37
|
|
|
36
38
|
let targetUnit
|
|
37
39
|
|
|
38
|
-
module.exports = (options = {})
|
|
40
|
+
module.exports = postcss.plugin('postcss-pxtransform', function (options = {}) {
|
|
39
41
|
options = Object.assign({}, DEFAULT_WEAPP_OPTIONS, options)
|
|
40
42
|
|
|
41
43
|
const transUnits = ['px']
|
|
@@ -60,11 +62,6 @@ module.exports = (options = {}) => {
|
|
|
60
62
|
targetUnit = 'px'
|
|
61
63
|
break
|
|
62
64
|
}
|
|
63
|
-
case 'harmony': {
|
|
64
|
-
options.rootValue = input => 1 / options.deviceRatio[designWidth(input)]
|
|
65
|
-
targetUnit = 'px'
|
|
66
|
-
break
|
|
67
|
-
}
|
|
68
65
|
default: {
|
|
69
66
|
// mini-program
|
|
70
67
|
options.rootValue = input => 1 / options.deviceRatio[designWidth(input)]
|
|
@@ -80,20 +77,26 @@ module.exports = (options = {}) => {
|
|
|
80
77
|
|
|
81
78
|
const satisfyPropList = createPropListMatcher(opts.propList)
|
|
82
79
|
|
|
83
|
-
return {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
80
|
+
return function (css) {
|
|
81
|
+
const pxReplace = createPxReplace(opts.rootValue, opts.unitPrecision, opts.minPixelValue, onePxTransform)(css.source.input)
|
|
82
|
+
|
|
83
|
+
for (let i = 0; i < css.nodes.length; i++) {
|
|
84
|
+
if (css.nodes[i].type === 'comment') {
|
|
85
|
+
if (css.nodes[i].text === 'postcss-pxtransform disable') {
|
|
86
|
+
return
|
|
87
|
+
} else {
|
|
88
|
+
break
|
|
89
|
+
}
|
|
88
90
|
}
|
|
91
|
+
}
|
|
89
92
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
+
// delete code between comment in RN
|
|
94
|
+
if (options.platform === 'rn') {
|
|
95
|
+
css.walkComments(comment => {
|
|
93
96
|
if (comment.text === 'postcss-pxtransform rn eject enable') {
|
|
94
97
|
let next = comment.next()
|
|
95
98
|
while (next) {
|
|
96
|
-
if (next.text === 'postcss-pxtransform rn eject disable') {
|
|
99
|
+
if (next.type === 'comment' && next.text === 'postcss-pxtransform rn eject disable') {
|
|
97
100
|
break
|
|
98
101
|
}
|
|
99
102
|
const temp = next.next()
|
|
@@ -101,11 +104,13 @@ module.exports = (options = {}) => {
|
|
|
101
104
|
next = temp
|
|
102
105
|
}
|
|
103
106
|
}
|
|
104
|
-
}
|
|
107
|
+
})
|
|
108
|
+
}
|
|
105
109
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
110
|
+
/* #ifdef %PLATFORM% */
|
|
111
|
+
// 平台特有样式
|
|
112
|
+
/* #endif */
|
|
113
|
+
css.walkComments(comment => {
|
|
109
114
|
const wordList = comment.text.split(' ')
|
|
110
115
|
// 指定平台保留
|
|
111
116
|
if (wordList.indexOf('#ifdef') > -1) {
|
|
@@ -122,10 +127,13 @@ module.exports = (options = {}) => {
|
|
|
122
127
|
}
|
|
123
128
|
}
|
|
124
129
|
}
|
|
130
|
+
})
|
|
125
131
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
132
|
+
/* #ifndef %PLATFORM% */
|
|
133
|
+
// 平台特有样式
|
|
134
|
+
/* #endif */
|
|
135
|
+
css.walkComments(comment => {
|
|
136
|
+
const wordList = comment.text.split(' ')
|
|
129
137
|
// 指定平台剔除
|
|
130
138
|
if (wordList.indexOf('#ifndef') > -1) {
|
|
131
139
|
// 指定平台
|
|
@@ -141,60 +149,36 @@ module.exports = (options = {}) => {
|
|
|
141
149
|
}
|
|
142
150
|
}
|
|
143
151
|
}
|
|
144
|
-
}
|
|
152
|
+
})
|
|
145
153
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
const value = decl.value.replace(PXRegex, function (m, _$1, $2) {
|
|
150
|
-
return m.replace($2, 'vp')
|
|
151
|
-
})
|
|
152
|
-
decl.value = value
|
|
153
|
-
}
|
|
154
|
-
},
|
|
155
|
-
|
|
156
|
-
AtRule (rule) {
|
|
157
|
-
if (options.platform === 'harmony' && rule.name === 'media') {
|
|
158
|
-
if (rule.params.indexOf('PX') === -1) return
|
|
159
|
-
const value = rule.params.replace(PXRegex, function (m, _$1, $2) {
|
|
160
|
-
return m.replace($2, 'vp')
|
|
161
|
-
})
|
|
162
|
-
rule.params = value
|
|
163
|
-
}
|
|
164
|
-
},
|
|
154
|
+
css.walkDecls(function (decl, i) {
|
|
155
|
+
// This should be the fastest test and will remove most declarations
|
|
156
|
+
if (decl.value.indexOf('px') === -1) return
|
|
165
157
|
|
|
166
|
-
|
|
167
|
-
const pxReplace = createPxReplace(opts.rootValue, opts.unitPrecision, opts.minPixelValue, onePxTransform)(root.source.input)
|
|
158
|
+
if (!satisfyPropList(decl.prop)) return
|
|
168
159
|
|
|
169
|
-
|
|
170
|
-
// This should be the fastest test and will remove most declarations
|
|
171
|
-
if (decl.value.indexOf('px') === -1) return
|
|
160
|
+
if (blacklistedSelector(opts.selectorBlackList, decl.parent.selector)) return
|
|
172
161
|
|
|
173
|
-
|
|
162
|
+
const value = decl.value.replace(pxRgx, pxReplace)
|
|
174
163
|
|
|
175
|
-
|
|
164
|
+
// if rem unit already exists, do not add or replace
|
|
165
|
+
if (declarationExists(decl.parent, decl.prop, value)) return
|
|
176
166
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
167
|
+
if (opts.replace) {
|
|
168
|
+
decl.value = value
|
|
169
|
+
} else {
|
|
170
|
+
decl.parent.insertAfter(i, decl.clone({ value: value }))
|
|
171
|
+
}
|
|
172
|
+
})
|
|
181
173
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}
|
|
174
|
+
if (opts.mediaQuery) {
|
|
175
|
+
css.walkAtRules('media', function (rule) {
|
|
176
|
+
if (rule.params.indexOf('px') === -1) return
|
|
177
|
+
rule.params = rule.params.replace(pxRgx, pxReplace)
|
|
187
178
|
})
|
|
188
|
-
|
|
189
|
-
if (opts.mediaQuery) {
|
|
190
|
-
root.walkAtRules('media', function (rule) {
|
|
191
|
-
if (rule.params.indexOf('px') === -1) return
|
|
192
|
-
rule.params = rule.params.replace(pxRgx, pxReplace)
|
|
193
|
-
})
|
|
194
|
-
}
|
|
195
179
|
}
|
|
196
180
|
}
|
|
197
|
-
}
|
|
181
|
+
})
|
|
198
182
|
|
|
199
183
|
function convertLegacyOptions (options) {
|
|
200
184
|
if (typeof options !== 'object') return
|
|
@@ -300,5 +284,3 @@ function createPropListMatcher (propList) {
|
|
|
300
284
|
)
|
|
301
285
|
}
|
|
302
286
|
}
|
|
303
|
-
|
|
304
|
-
module.exports.postcss = true
|
package/package.json
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-pxtransform",
|
|
3
|
-
"version": "3.5.
|
|
3
|
+
"version": "3.5.8",
|
|
4
4
|
"description": "PostCSS plugin px 转小程序 rpx及h5 rem 单位",
|
|
5
|
-
"main": "index.js",
|
|
6
5
|
"keywords": [
|
|
7
6
|
"postcss",
|
|
8
7
|
"css",
|
|
@@ -19,15 +18,13 @@
|
|
|
19
18
|
"url": "https://github.com/NervJS/taro/issues"
|
|
20
19
|
},
|
|
21
20
|
"homepage": "https://github.com/NervJS/taro#readme",
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"postcss": "^6.0.22"
|
|
23
|
+
},
|
|
22
24
|
"jest": {
|
|
23
25
|
"testEnvironment": "node"
|
|
24
26
|
},
|
|
25
|
-
"
|
|
26
|
-
"postcss": "^8.4.18"
|
|
27
|
-
},
|
|
28
|
-
"peerDependencies": {
|
|
29
|
-
"postcss": "^8.4.18"
|
|
30
|
-
},
|
|
27
|
+
"main": "index.js",
|
|
31
28
|
"scripts": {
|
|
32
29
|
"test": "jest"
|
|
33
30
|
}
|
|
@@ -1,11 +0,0 @@
|
|
|
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
|