postcss-pxtransform 3.4.0-beta.0 → 3.5.0-canary.0

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 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 = {
@@ -43,11 +44,6 @@ module.exports = postcss.plugin('postcss-pxtransform', function (options) {
43
44
  options = Object.assign(DEFAULT_WEAPP_OPTIONS, options || {})
44
45
 
45
46
  switch (options.platform) {
46
- case 'weapp': {
47
- options.rootValue = 1 / options.deviceRatio[options.designWidth]
48
- targetUnit = 'rpx'
49
- break
50
- }
51
47
  case 'h5': {
52
48
  options.rootValue = baseFontSize * options.designWidth / 640
53
49
  targetUnit = 'rem'
@@ -58,6 +54,21 @@ module.exports = postcss.plugin('postcss-pxtransform', function (options) {
58
54
  targetUnit = 'px'
59
55
  break
60
56
  }
57
+ case 'quickapp': {
58
+ options.rootValue = 1
59
+ targetUnit = 'px'
60
+ break
61
+ }
62
+ case 'harmony': {
63
+ options.rootValue = 1 / options.deviceRatio[options.designWidth]
64
+ targetUnit = 'px'
65
+ break
66
+ }
67
+ default: {
68
+ // mini-program
69
+ options.rootValue = 1 / options.deviceRatio[options.designWidth]
70
+ targetUnit = 'rpx'
71
+ }
61
72
  }
62
73
 
63
74
  convertLegacyOptions(options)
@@ -97,6 +108,27 @@ module.exports = postcss.plugin('postcss-pxtransform', function (options) {
97
108
  })
98
109
  }
99
110
 
111
+ // PX -> vp in harmony
112
+ if (options.platform === 'harmony') {
113
+ css.walkDecls(function (decl) {
114
+ if (decl.value.indexOf('PX') === -1) return
115
+ const value = decl.value.replace(PXRegex, function (m, _$1, $2) {
116
+ return m.replace($2, 'vp')
117
+ })
118
+ decl.value = value
119
+ })
120
+
121
+ if (opts.mediaQuery) {
122
+ css.walkAtRules('media', function (rule) {
123
+ if (rule.params.indexOf('PX') === -1) return
124
+ const value = rule.params.replace(PXRegex, function (m, _$1, $2) {
125
+ return m.replace($2, 'vp')
126
+ })
127
+ rule.params = value
128
+ })
129
+ }
130
+ }
131
+
100
132
  /* #ifdef %PLATFORM% */
101
133
  // 平台特有样式
102
134
  /* #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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postcss-pxtransform",
3
- "version": "3.4.0-beta.0",
3
+ "version": "3.5.0-canary.0",
4
4
  "description": "PostCSS plugin px 转小程序 rpx及h5 rem 单位",
5
5
  "keywords": [
6
6
  "postcss",
@@ -28,5 +28,5 @@
28
28
  "testEnvironment": "node"
29
29
  },
30
30
  "main": "index.js",
31
- "gitHead": "107670bc2360ee9136a0e558e6d5fad1db640fba"
31
+ "gitHead": "a0222bc41bc05b0e34413d6db3de963d777a5015"
32
32
  }