postcss-pxtransform 3.6.0 → 3.6.1-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.
- package/LICENSE +119 -1
- package/__tests__/index.test.js +35 -1
- package/index.js +9 -3
- package/package.json +1 -1
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2018
|
|
3
|
+
Copyright (c) 2018 O2Team
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -19,3 +19,121 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
========================================================================
|
|
24
|
+
|
|
25
|
+
MIT (react-devtools):
|
|
26
|
+
The following files embed [react-devtools](https://github.com/facebook/react) MIT:
|
|
27
|
+
`/packages/taro-plugin-react-devtools/src/backend/index.js`
|
|
28
|
+
See `/LICENSE` for details of the license.
|
|
29
|
+
|
|
30
|
+
==================
|
|
31
|
+
|
|
32
|
+
MIT (vue-devtools):
|
|
33
|
+
The following files embed [vue-devtools](https://github.com/vuejs/devtools) MIT:
|
|
34
|
+
`/packages/taro-plugin-vue-devtools/src/backend/*`
|
|
35
|
+
See `/LICENSE` for details of the license.
|
|
36
|
+
|
|
37
|
+
==================
|
|
38
|
+
|
|
39
|
+
MIT (vite):
|
|
40
|
+
The following files embed [vite](https://github.com/vitejs/vite) MIT:
|
|
41
|
+
`/packages/taro-webpack5-prebundle/src/prebundle/scanImport.ts`,
|
|
42
|
+
`/packages/taro-webpack5-prebundle/src/prebundle/bundle.ts`,
|
|
43
|
+
`/packages/taro-webpack5-prebundle/src/h5.ts`,
|
|
44
|
+
`/packages/taro-webpack5-prebundle/src/min.ts`
|
|
45
|
+
See `/LICENSE` for details of the license.
|
|
46
|
+
|
|
47
|
+
==================
|
|
48
|
+
|
|
49
|
+
MIT (webpack):
|
|
50
|
+
The following files embed [webpack](https://github.com/webpack/webpack) MIT:
|
|
51
|
+
`/packages/taro-webpack5-prebundle/src/webpack/TaroContainerEntryModule.ts`,
|
|
52
|
+
`/packages/taro-webpack5-prebundle/src/webpack/TaroContainerPlugin.ts`,
|
|
53
|
+
`/packages/taro-webpack5-prebundle/src/webpack/TaroContainerReferencePlugin.ts`,
|
|
54
|
+
`/packages/taro-webpack5-prebundle/src/webpack/TaroModuleFederationPlugin.ts`
|
|
55
|
+
See `/LICENSE` for details of the license.
|
|
56
|
+
|
|
57
|
+
==================
|
|
58
|
+
|
|
59
|
+
MIT (sizzle):
|
|
60
|
+
The following files embed [sizzle](https://github.com/jquery/sizzle) MIT:
|
|
61
|
+
`/packages/taro-extends/src/jquery/sizzle.js`
|
|
62
|
+
See `/LICENSE.txt` for details of the license.
|
|
63
|
+
|
|
64
|
+
==================
|
|
65
|
+
|
|
66
|
+
MIT (zepto):
|
|
67
|
+
The following files embed [zepto](https://github.com/madrobby/zepto) MIT:
|
|
68
|
+
`/packages/taro-extends/src/jquery/zepto.js`,
|
|
69
|
+
`/packages/taro-extends/src/jquery/event.js`
|
|
70
|
+
See `/MIT-LICENSE` for details of the license.
|
|
71
|
+
|
|
72
|
+
==================
|
|
73
|
+
|
|
74
|
+
MIT (css-to-react-native):
|
|
75
|
+
The following files embed [css-to-react-native](https://github.com/styled-components/css-to-react-native) MIT:
|
|
76
|
+
`/packages/css-to-react-native/src/css-to-react-native/*`
|
|
77
|
+
See `/LICENSE.md` for details of the license.
|
|
78
|
+
|
|
79
|
+
==================
|
|
80
|
+
|
|
81
|
+
MIT (reactify-wc):
|
|
82
|
+
The following files embed [reactify-wc](https://github.com/BBKolton/reactify-wc) MIT:
|
|
83
|
+
`/packages/taro-components-library-react/src/component-lib/reactify-wc.ts`
|
|
84
|
+
See `/LICENSE` for details of the license.
|
|
85
|
+
|
|
86
|
+
==================
|
|
87
|
+
|
|
88
|
+
MIT (ant-design-mobile-rn):
|
|
89
|
+
The following files embed [ant-design-mobile-rn](https://github.com/ant-design/ant-design-mobile-rn) MIT:
|
|
90
|
+
`/packages/taro-components-rn/src/components/Swiper/carousel.tsx`
|
|
91
|
+
See `/LICENSE` for details of the license.
|
|
92
|
+
|
|
93
|
+
==================
|
|
94
|
+
|
|
95
|
+
MIT (react-wx-images-viewer):
|
|
96
|
+
The following files embed [react-wx-images-viewer](https://github.com/react-ld/react-wx-images-viewer) MIT:
|
|
97
|
+
`/packages/taro-h5/src/api/media/image/previewImage.ts`
|
|
98
|
+
See `/LICENSE` for details of the license.
|
|
99
|
+
|
|
100
|
+
==================
|
|
101
|
+
|
|
102
|
+
MIT (webpack-contrib/css-loader):
|
|
103
|
+
The following files embed [webpack-contrib/css-loader](https://github.com/webpack-contrib/css-loader) MIT:
|
|
104
|
+
`/packages/taro-rn-style-transformer/src/utils/index.ts`
|
|
105
|
+
See `/LICENSE` for details of the license.
|
|
106
|
+
|
|
107
|
+
==================
|
|
108
|
+
|
|
109
|
+
MIT (react-native):
|
|
110
|
+
The following files embed [react-native](https://github.com/facebook/react-native) MIT:
|
|
111
|
+
`/packages/taro-rn-style-transformer/src/transforms/StyleSheet/*`
|
|
112
|
+
See `/LICENSE` for details of the license.
|
|
113
|
+
|
|
114
|
+
==================
|
|
115
|
+
|
|
116
|
+
MIT (myrne/performance-now):
|
|
117
|
+
The following files embed [myrne/performance-now](https://github.com/myrne/performance-now) MIT:
|
|
118
|
+
`/packages/taro-runtime/src/bom/raf.ts`
|
|
119
|
+
See `/LICENSE` for details of the license.
|
|
120
|
+
|
|
121
|
+
==================
|
|
122
|
+
|
|
123
|
+
Apache (chameleon-api):
|
|
124
|
+
The following files embed [chameleon-api](https://github.com/chameleon-team/chameleon-api) Apache:
|
|
125
|
+
`/packages/taro-h5/src/api/device/clipboard.ts`
|
|
126
|
+
|
|
127
|
+
==================
|
|
128
|
+
|
|
129
|
+
MIT (uni-app):
|
|
130
|
+
The following files embed [uni-app](https://github.com/dcloudio/uni-app) MIT:
|
|
131
|
+
`/packages/taro-components-rn/src/components/Video/index.tsx`
|
|
132
|
+
See `/LICENSE` for details of the license.
|
|
133
|
+
|
|
134
|
+
==================
|
|
135
|
+
|
|
136
|
+
MIT (miniprogram-render):
|
|
137
|
+
The following files embed [miniprogram-render](https://github.com/Tencent/kbone) MIT:
|
|
138
|
+
`/packages/taro-plugin-http/src/runtime/Cookie.ts`
|
|
139
|
+
See `/LICENSE` for details of the license.
|
package/__tests__/index.test.js
CHANGED
|
@@ -73,7 +73,7 @@ describe('px2rem', function () {
|
|
|
73
73
|
|
|
74
74
|
expect(processed).toBe(expected)
|
|
75
75
|
})
|
|
76
|
-
|
|
76
|
+
|
|
77
77
|
it('8 should work on custom baseFontSize', function () {
|
|
78
78
|
const processed = postcss(px2rem({ platform: 'h5', baseFontSize: 15 })).process(basicCSS).css
|
|
79
79
|
const expected = '.rule { font-size: 0.5rem }'
|
|
@@ -641,3 +641,37 @@ describe('rpx 单位转换', () => {
|
|
|
641
641
|
expect(processed).toBe('h1 {margin: 0 0 0.585rem;font-size: 40Px;line-height: 1.2;} .test{}')
|
|
642
642
|
})
|
|
643
643
|
})
|
|
644
|
+
|
|
645
|
+
describe('platform 为 rn,适配', () => {
|
|
646
|
+
it('{platform: \'rn\', designWidth: 750} ', () => {
|
|
647
|
+
const rules = 'view { width: 100px; }'
|
|
648
|
+
const options = {
|
|
649
|
+
platform: 'rn',
|
|
650
|
+
designWidth: 750,
|
|
651
|
+
deviceRatio: {
|
|
652
|
+
640: 2.34 / 2,
|
|
653
|
+
750: 1,
|
|
654
|
+
828: 1.81 / 2
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
const processed = postcss(px2rem(options)).process(rules).css
|
|
658
|
+
expect(processed).toBe('view { width: 50px; }')
|
|
659
|
+
})
|
|
660
|
+
})
|
|
661
|
+
|
|
662
|
+
describe('platform 为 harmony,适配', () => {
|
|
663
|
+
it('{platform: \'harmony\', designWidth: 640} ', () => {
|
|
664
|
+
const rules = 'view { width: 100PX; }'
|
|
665
|
+
const options = {
|
|
666
|
+
platform: 'harmony',
|
|
667
|
+
designWidth: 640,
|
|
668
|
+
deviceRatio: {
|
|
669
|
+
640: 2.34 / 2,
|
|
670
|
+
750: 1,
|
|
671
|
+
828: 1.81 / 2
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
const processed = postcss(px2rem(options)).process(rules).css
|
|
675
|
+
expect(processed).toBe('view { width: 100vp; }')
|
|
676
|
+
})
|
|
677
|
+
})
|
package/index.js
CHANGED
|
@@ -33,6 +33,9 @@ const DEFAULT_WEAPP_OPTIONS = {
|
|
|
33
33
|
deviceRatio
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
const processed = Symbol('processed')
|
|
37
|
+
|
|
38
|
+
|
|
36
39
|
let targetUnit
|
|
37
40
|
|
|
38
41
|
module.exports = (options = {}) => {
|
|
@@ -93,6 +96,7 @@ module.exports = (options = {}) => {
|
|
|
93
96
|
let skip = false
|
|
94
97
|
|
|
95
98
|
return {
|
|
99
|
+
// 注意:钩子在节点变动时会重新执行,Once,OnceExit只执行一次,https://github.com/NervJS/taro/issues/13238
|
|
96
100
|
Comment (comment) {
|
|
97
101
|
if (comment.text === 'postcss-pxtransform disable') {
|
|
98
102
|
skip = true
|
|
@@ -157,6 +161,11 @@ module.exports = (options = {}) => {
|
|
|
157
161
|
Declaration (decl) {
|
|
158
162
|
if (skip) return
|
|
159
163
|
|
|
164
|
+
if (decl[processed]) return
|
|
165
|
+
|
|
166
|
+
// 标记当前 node 已处理
|
|
167
|
+
decl[processed] = true
|
|
168
|
+
|
|
160
169
|
if (options.platform === 'harmony') {
|
|
161
170
|
if (decl.value.indexOf('PX') === -1) return
|
|
162
171
|
const value = decl.value.replace(PXRegex, function (m, _$1, $2) {
|
|
@@ -169,11 +178,9 @@ module.exports = (options = {}) => {
|
|
|
169
178
|
if (!satisfyPropList(decl.prop)) return
|
|
170
179
|
|
|
171
180
|
if (blacklistedSelector(opts.selectorBlackList, decl.parent.selector)) return
|
|
172
|
-
|
|
173
181
|
const value = decl.value.replace(pxRgx, pxReplace)
|
|
174
182
|
// if rem unit already exists, do not add or replace
|
|
175
183
|
if (declarationExists(decl.parent, decl.prop, value)) return
|
|
176
|
-
|
|
177
184
|
if (opts.replace) {
|
|
178
185
|
decl.value = value
|
|
179
186
|
} else {
|
|
@@ -181,7 +188,6 @@ module.exports = (options = {}) => {
|
|
|
181
188
|
}
|
|
182
189
|
}
|
|
183
190
|
},
|
|
184
|
-
|
|
185
191
|
AtRule: {
|
|
186
192
|
media: (rule) => {
|
|
187
193
|
if (skip) return
|