postcss-pxtransform 3.5.4-canary.0 → 3.5.5-alpha.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.
@@ -72,6 +72,13 @@ describe('px2rem', function () {
72
72
 
73
73
  expect(processed).toBe(expected)
74
74
  })
75
+
76
+ it('8 should work on custom baseFontSize', function () {
77
+ const processed = postcss(px2rem({ platform: 'h5', baseFontSize: 15 })).process(basicCSS).css
78
+ const expected = '.rule { font-size: 0.5rem }'
79
+
80
+ expect(processed).toBe(expected)
81
+ })
75
82
  })
76
83
 
77
84
  describe('value parsing', function () {
package/index.js CHANGED
@@ -2,7 +2,6 @@
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')
6
5
  const filterPropList = require('./lib/filter-prop-list')
7
6
 
8
7
  const defaults = {
@@ -42,7 +41,7 @@ module.exports = postcss.plugin('postcss-pxtransform', function (options = {}) {
42
41
  options = Object.assign({}, DEFAULT_WEAPP_OPTIONS, options)
43
42
 
44
43
  const transUnits = ['px']
45
- const baseFontSize = options.baseFontSize || options.minRootSize >= 1 ? options.minRootSize : 20
44
+ const baseFontSize = options.baseFontSize || (options.minRootSize >= 1 ? options.minRootSize : 20)
46
45
  const designWidth = input => typeof options.designWidth === 'function'
47
46
  ? options.designWidth(input)
48
47
  : options.designWidth
@@ -63,11 +62,6 @@ module.exports = postcss.plugin('postcss-pxtransform', function (options = {}) {
63
62
  targetUnit = 'px'
64
63
  break
65
64
  }
66
- case 'harmony': {
67
- options.rootValue = input => 1 / options.deviceRatio[designWidth(input)]
68
- targetUnit = 'px'
69
- break
70
- }
71
65
  default: {
72
66
  // mini-program
73
67
  options.rootValue = input => 1 / options.deviceRatio[designWidth(input)]
@@ -113,27 +107,6 @@ module.exports = postcss.plugin('postcss-pxtransform', function (options = {}) {
113
107
  })
114
108
  }
115
109
 
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
-
137
110
  /* #ifdef %PLATFORM% */
138
111
  // 平台特有样式
139
112
  /* #endif */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postcss-pxtransform",
3
- "version": "3.5.4-canary.0",
3
+ "version": "3.5.5-alpha.0",
4
4
  "description": "PostCSS plugin px 转小程序 rpx及h5 rem 单位",
5
5
  "keywords": [
6
6
  "postcss",
@@ -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