postcss-pxtransform 3.5.0-theta.1 → 3.5.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.
@@ -1,10 +1,3 @@
1
- // Jasmine unit tests
2
- // To run tests, run these commands from the project root:
3
- // 1. `npm install -g jasmine-node`
4
- // 2. `jasmine-node spec`
5
-
6
- /* global describe, it, expect */
7
-
8
1
  'use strict'
9
2
  const postcss = require('postcss')
10
3
  const px2rem = require('../index')
@@ -41,7 +34,7 @@ describe('px2rem', function () {
41
34
  it('4 should handle < 1 values and values without a leading 0 - legacy',
42
35
  function () {
43
36
  const rules = '.rule { margin: 0.5rem .5px -0.2px -.2em }'
44
- const expected = '.rule { margin: 0.5rem 0.01462rem -0.00585rem -.2em }'
37
+ const expected = '.rule { margin: 0.5rem 0.01463rem -0.00585rem -.2em }'
45
38
  const options = {
46
39
  platform: 'h5',
47
40
  designWidth: 640,
@@ -54,7 +47,7 @@ describe('px2rem', function () {
54
47
 
55
48
  it('5 should handle < 1 values and values without a leading 0', function () {
56
49
  const rules = '.rule { margin: 0.5rem .5px -0.2px -.2em }'
57
- const expected = '.rule { margin: 0.5rem 0.01462rem -0.00585rem -.2em }'
50
+ const expected = '.rule { margin: 0.5rem 0.01463rem -0.00585rem -.2em }'
58
51
  const options = {
59
52
  platform: 'h5',
60
53
  designWidth: 640,
@@ -67,11 +60,8 @@ describe('px2rem', function () {
67
60
 
68
61
  it('6 should not add properties that already exist', function () {
69
62
  const expected = '.rule { font-size: 40px; font-size: 1rem; }'
70
- const options = {
71
- platform: 'h5',
72
- designWidth: 750
73
- }
74
- const processed = postcss(px2rem(options)).process(expected).css
63
+ const processed = postcss(px2rem({ platform: 'h5', designWidth: 750 }))
64
+ .process(expected).css
75
65
 
76
66
  expect(processed).toBe(expected)
77
67
  })
@@ -640,6 +630,6 @@ describe('rpx 单位转换', () => {
640
630
  designWidth: 640
641
631
  }
642
632
  const processed = postcss(px2rem(options)).process(rules).css
643
- expect(processed).toBe('h1 {margin: 0 0 0.2925rem;font-size: 40Px;line-height: 1.2;} .test{}')
633
+ expect(processed).toBe('h1 {margin: 0 0 0.585rem;font-size: 40Px;line-height: 1.2;} .test{}')
644
634
  })
645
635
  })
package/index.js CHANGED
@@ -41,16 +41,13 @@ module.exports = postcss.plugin('postcss-pxtransform', function (options = {}) {
41
41
  options = Object.assign({}, DEFAULT_WEAPP_OPTIONS, options)
42
42
 
43
43
  const transUnits = ['px']
44
+ const baseFontSize = options.baseFontSize ?? options.minRootSize >= 1 ? options.minRootSize : 20
44
45
  const designWidth = input => typeof options.designWidth === 'function'
45
46
  ? options.designWidth(input)
46
47
  : options.designWidth
47
48
  switch (options.platform) {
48
49
  case 'h5': {
49
- options.rootValue = (input, m) => {
50
- const rv = 1 / options.deviceRatio[designWidth(input)] * (designWidth(input) / 16)
51
- const val = Math.max(Math.min(rv, options.max ?? 40), options.mix ?? 20)
52
- return m.indexOf('rpx') >= 0 ? val / 0.5 : val
53
- }
50
+ options.rootValue = input => baseFontSize / options.deviceRatio[designWidth(input)] * 2
54
51
  targetUnit = 'rem'
55
52
  transUnits.push('rpx')
56
53
  break
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postcss-pxtransform",
3
- "version": "3.5.0-theta.1",
3
+ "version": "3.5.0",
4
4
  "description": "PostCSS plugin px 转小程序 rpx及h5 rem 单位",
5
5
  "keywords": [
6
6
  "postcss",