postcss-pxtransform 3.6.1 → 3.6.2-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/LICENSE +21 -0
- package/__tests__/index.test.js +25 -0
- package/index.js +14 -5
- package/package.json +5 -2
package/LICENSE
CHANGED
|
@@ -137,3 +137,24 @@ MIT (miniprogram-render):
|
|
|
137
137
|
The following files embed [miniprogram-render](https://github.com/Tencent/kbone) MIT:
|
|
138
138
|
`/packages/taro-plugin-http/src/runtime/Cookie.ts`
|
|
139
139
|
See `/LICENSE` for details of the license.
|
|
140
|
+
|
|
141
|
+
==================
|
|
142
|
+
|
|
143
|
+
MIT (stencil-ds-output-targets):
|
|
144
|
+
The following files embed [stencil-ds-output-targets](https://github.com/ionic-team/stencil-ds-output-targets/) MIT:
|
|
145
|
+
`/packages/taro-components-library-react/src/react-component-lib/utils/attachProps.ts`
|
|
146
|
+
`/packages/taro-components-library-react/src/react-component-lib/utils/case.ts`
|
|
147
|
+
`/packages/taro-components-library-react/src/react-component-lib/utils/dev.ts`
|
|
148
|
+
`/packages/taro-components-library-react/src/react-component-lib/utils/index.tsx`
|
|
149
|
+
`/packages/taro-components-library-react/src/react-component-lib/createComponent.tsx`
|
|
150
|
+
`/packages/taro-components-library-react/src/react-component-lib/createOverlayComponent.tsx`
|
|
151
|
+
`/packages/taro-components-library-react/src/react-component-lib/interfaces.ts`
|
|
152
|
+
`/packages/taro-components-library-vue3/src/vue-component-lib/utils.ts`
|
|
153
|
+
See `/LICENSE` for details of the license.
|
|
154
|
+
|
|
155
|
+
==================
|
|
156
|
+
|
|
157
|
+
MIT (stencil-vue2-output-target):
|
|
158
|
+
The following files embed [stencil-vue2-output-target](https://github.com/diondree/stencil-vue2-output-target) MIT:
|
|
159
|
+
`/packages/taro-components-library-vue2/src/vue-component-lib/utils.ts`
|
|
160
|
+
See `/LICENSE` for details of the license.
|
package/__tests__/index.test.js
CHANGED
|
@@ -631,6 +631,7 @@ describe('rpx 单位转换', () => {
|
|
|
631
631
|
const processed = postcss(px2rem(options)).process(rules).css
|
|
632
632
|
expect(processed).toBe('h1 {margin: 0 0 20rpx;font-size: 40Px;line-height: 1.2;} .test{}')
|
|
633
633
|
})
|
|
634
|
+
|
|
634
635
|
it('{platform: \'h5\', designWidth: 640} ', () => {
|
|
635
636
|
const rules = 'h1 {margin: 0 0 20rpx;font-size: 40Px;line-height: 1.2;} .test{}'
|
|
636
637
|
const options = {
|
|
@@ -642,6 +643,30 @@ describe('rpx 单位转换', () => {
|
|
|
642
643
|
})
|
|
643
644
|
})
|
|
644
645
|
|
|
646
|
+
describe('vw 单位转换', () => {
|
|
647
|
+
it('{platform: \'h5\', designWidth: 640} ', () => {
|
|
648
|
+
const rules = 'h1 {margin: 0 0 640px;font-size: 40Px;line-height: 1.2;} .test{}'
|
|
649
|
+
const options = {
|
|
650
|
+
platform: 'h5',
|
|
651
|
+
designWidth: 750,
|
|
652
|
+
targetUnit: 'vw'
|
|
653
|
+
}
|
|
654
|
+
const processed = postcss(px2rem(options)).process(rules).css
|
|
655
|
+
expect(processed).toBe('h1 {margin: 0 0 85.33333vw;font-size: 40Px;line-height: 1.2;} .test{}')
|
|
656
|
+
})
|
|
657
|
+
|
|
658
|
+
it('{platform: \'h5\', designWidth: 750} ', () => {
|
|
659
|
+
const rules = 'h1 {margin: 0 0 375px;font-size: 40Px;line-height: 1.2;} .test{}'
|
|
660
|
+
const options = {
|
|
661
|
+
platform: 'h5',
|
|
662
|
+
designWidth: 750,
|
|
663
|
+
targetUnit: 'vw'
|
|
664
|
+
}
|
|
665
|
+
const processed = postcss(px2rem(options)).process(rules).css
|
|
666
|
+
expect(processed).toBe('h1 {margin: 0 0 50vw;font-size: 40Px;line-height: 1.2;} .test{}')
|
|
667
|
+
})
|
|
668
|
+
})
|
|
669
|
+
|
|
645
670
|
describe('platform 为 rn,适配', () => {
|
|
646
671
|
it('{platform: \'rn\', designWidth: 750} ', () => {
|
|
647
672
|
const rules = 'view { width: 100px; }'
|
package/index.js
CHANGED
|
@@ -42,13 +42,19 @@ module.exports = (options = {}) => {
|
|
|
42
42
|
options = Object.assign({}, DEFAULT_WEAPP_OPTIONS, options)
|
|
43
43
|
|
|
44
44
|
const transUnits = ['px']
|
|
45
|
-
|
|
45
|
+
let baseFontSize = options.baseFontSize || (options.minRootSize >= 1 ? options.minRootSize : 20)
|
|
46
46
|
const designWidth = (input) =>
|
|
47
47
|
typeof options.designWidth === 'function' ? options.designWidth(input) : options.designWidth
|
|
48
|
+
|
|
48
49
|
switch (options.platform) {
|
|
49
50
|
case 'h5': {
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
targetUnit = options.targetUnit ?? 'rem'
|
|
52
|
+
options.rootValue = (input) => {
|
|
53
|
+
if (targetUnit === 'vw') {
|
|
54
|
+
baseFontSize = 0.5 * designWidth(input) / 100
|
|
55
|
+
}
|
|
56
|
+
return (baseFontSize / options.deviceRatio[designWidth(input)]) * 2
|
|
57
|
+
}
|
|
52
58
|
transUnits.push('rpx')
|
|
53
59
|
break
|
|
54
60
|
}
|
|
@@ -240,9 +246,12 @@ function createPxReplace (rootValue, unitPrecision, minPixelValue, onePxTransfor
|
|
|
240
246
|
}
|
|
241
247
|
const pixels = parseFloat($1)
|
|
242
248
|
if (pixels < minPixelValue) return m
|
|
243
|
-
|
|
249
|
+
let val = pixels / rootValue(input, m, $1)
|
|
250
|
+
if (unitPrecision >= 0 && unitPrecision <= 100) {
|
|
251
|
+
val = toFixed(val, unitPrecision)
|
|
252
|
+
}
|
|
244
253
|
// 不带单位不支持在calc表达式中参与计算(https://github.com/NervJS/taro/issues/12607)
|
|
245
|
-
return
|
|
254
|
+
return val + targetUnit
|
|
246
255
|
}
|
|
247
256
|
}
|
|
248
257
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-pxtransform",
|
|
3
|
-
"version": "3.6.
|
|
3
|
+
"version": "3.6.2-canary.0",
|
|
4
4
|
"description": "PostCSS plugin px 转小程序 rpx及h5 rem 单位",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"keywords": [
|
|
@@ -20,9 +20,12 @@
|
|
|
20
20
|
},
|
|
21
21
|
"homepage": "https://github.com/NervJS/taro#readme",
|
|
22
22
|
"jest": {
|
|
23
|
-
"testEnvironment": "node"
|
|
23
|
+
"testEnvironment": "node",
|
|
24
|
+
"testEnvironmentOptions": {}
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
27
|
+
"jest": "^29.3.1",
|
|
28
|
+
"jest-cli": "^29.3.1",
|
|
26
29
|
"postcss": "^8.4.18"
|
|
27
30
|
},
|
|
28
31
|
"peerDependencies": {
|