postcss-pxtransform 3.4.0-beta.3 → 3.5.0-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 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 = {
@@ -49,7 +50,7 @@ module.exports = postcss.plugin('postcss-pxtransform', function (options) {
49
50
  break
50
51
  }
51
52
  case 'rn': {
52
- options.rootValue = options.deviceRatio[options.designWidth] * 2
53
+ options.rootValue = 1 / options.deviceRatio[options.designWidth]
53
54
  targetUnit = 'px'
54
55
  break
55
56
  }
@@ -58,6 +59,11 @@ module.exports = postcss.plugin('postcss-pxtransform', function (options) {
58
59
  targetUnit = 'px'
59
60
  break
60
61
  }
62
+ case 'harmony': {
63
+ options.rootValue = 1 / options.deviceRatio[options.designWidth]
64
+ targetUnit = 'px'
65
+ break
66
+ }
61
67
  default: {
62
68
  // mini-program
63
69
  options.rootValue = 1 / options.deviceRatio[options.designWidth]
@@ -102,6 +108,27 @@ module.exports = postcss.plugin('postcss-pxtransform', function (options) {
102
108
  })
103
109
  }
104
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
+
105
132
  /* #ifdef %PLATFORM% */
106
133
  // 平台特有样式
107
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.3",
3
+ "version": "3.5.0-canary.1",
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": "2ef7e8c10c9e5784e98bb1ad3a803d5fd6a46c8b"
31
+ "gitHead": "c61624d2f763e6d31e67d6cf9c564efc8b0d0887"
32
32
  }