postcss-taro-unit-transform 4.0.0-canary.8 → 4.0.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 +17 -3
- package/__tests__/index.test.ts +26 -0
- package/index.js +16 -15
- package/package.json +28 -7
- package/tsconfig.json +5 -0
- package/.eslintrc.js +0 -19
package/LICENSE
CHANGED
|
@@ -154,7 +154,21 @@ See `/LICENSE` for details of the license.
|
|
|
154
154
|
|
|
155
155
|
==================
|
|
156
156
|
|
|
157
|
-
MIT (
|
|
158
|
-
The following files embed [
|
|
159
|
-
`/packages/taro-components
|
|
157
|
+
MIT (weui):
|
|
158
|
+
The following files embed [weui](https://github.com/Tencent/weui) MIT:
|
|
159
|
+
`/packages/taro-components/src/components/*.scss`
|
|
160
|
+
See `/LICENSE.txt` for details of the license.
|
|
161
|
+
|
|
162
|
+
==================
|
|
163
|
+
|
|
164
|
+
Apache-2.0 (intersection-observer):
|
|
165
|
+
The following files embed [intersection-observer](https://github.com/GoogleChromeLabs/intersection-observer) Apache-2.0:
|
|
166
|
+
`/packages/taro-api/src/polyfill/intersection-observer.ts`
|
|
167
|
+
See `/LICENSE.txt` for details of the license.
|
|
168
|
+
|
|
169
|
+
==================
|
|
170
|
+
|
|
171
|
+
MIT (babel-plugin-jsx-dom-expressions):
|
|
172
|
+
The following files embed [babel-plugin-jsx-dom-expressions](https://github.com/ryansolid/dom-expressions/blob/main/packages/babel-plugin-jsx-dom-expressions) MIT:
|
|
173
|
+
`/packages/babel-plugin-transform-solid-jsx/src/*`
|
|
160
174
|
See `/LICENSE` for details of the license.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const Processors = require('postcss')
|
|
2
|
+
const unitTransform = require('../index')
|
|
3
|
+
|
|
4
|
+
describe('wxss解析', () => {
|
|
5
|
+
test('wxss文件样式解析', () => {
|
|
6
|
+
const input = `
|
|
7
|
+
.box{
|
|
8
|
+
width: 100px;
|
|
9
|
+
height: 200rpx;
|
|
10
|
+
border: 0.5px solid red;
|
|
11
|
+
margin: 0.5px 100px;
|
|
12
|
+
transform: translate(0px, 0rpx);
|
|
13
|
+
font-size: 0rpx;
|
|
14
|
+
}`
|
|
15
|
+
const result = Processors([unitTransform]).process(input)
|
|
16
|
+
expect(result.css).toBe(`
|
|
17
|
+
.box{
|
|
18
|
+
width: 200px;
|
|
19
|
+
height: 200px;
|
|
20
|
+
border: 1px solid red;
|
|
21
|
+
margin: 1px 200px;
|
|
22
|
+
transform: translate(0px, 0px);
|
|
23
|
+
font-size: 0px;
|
|
24
|
+
}`)
|
|
25
|
+
})
|
|
26
|
+
})
|
package/index.js
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return size + 'px'
|
|
1
|
+
function plugin () {
|
|
2
|
+
return {
|
|
3
|
+
postcssPlugin: 'postcss-taro-unit-transform',
|
|
4
|
+
Once (root) {
|
|
5
|
+
root.walkDecls(decl => {
|
|
6
|
+
let value = decl.value
|
|
7
|
+
value = value.replace(/\b-?(\d+(\.\d+)?)px\b/ig, function (_match, size) {
|
|
8
|
+
return Number(size) === 0 ? '0px' : parseFloat(size) * 2 + 'px'
|
|
9
|
+
}).replace(/\b-?(\d+(\.\d+)?)rpx\b/ig, function (_match, size) {
|
|
10
|
+
return size + 'px'
|
|
11
|
+
})
|
|
12
|
+
decl.value = value
|
|
14
13
|
})
|
|
15
|
-
|
|
16
|
-
})
|
|
14
|
+
}
|
|
17
15
|
}
|
|
18
16
|
}
|
|
17
|
+
plugin.postcss = true
|
|
18
|
+
|
|
19
|
+
module.exports = plugin
|
package/package.json
CHANGED
|
@@ -1,15 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-taro-unit-transform",
|
|
3
|
-
"version": "4.0.0
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "小程序单位转换",
|
|
5
|
-
"
|
|
6
|
-
"author": "luckyadam",
|
|
5
|
+
"author": "O2Team",
|
|
7
6
|
"license": "MIT",
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
"
|
|
7
|
+
"main": "index.js",
|
|
8
|
+
"jest": {
|
|
9
|
+
"testEnvironment": "node",
|
|
10
|
+
"transform": {
|
|
11
|
+
"^.+\\.tsx?$": "ts-jest"
|
|
12
|
+
},
|
|
13
|
+
"testRegex": "(/postcss-unit-transform/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
|
|
14
|
+
"moduleFileExtensions": [
|
|
15
|
+
"ts",
|
|
16
|
+
"tsx",
|
|
17
|
+
"js",
|
|
18
|
+
"jsx",
|
|
19
|
+
"json",
|
|
20
|
+
"node"
|
|
21
|
+
],
|
|
22
|
+
"testPathIgnorePatterns": [
|
|
23
|
+
"/node_modules/"
|
|
24
|
+
]
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"postcss": "^8"
|
|
11
28
|
},
|
|
12
29
|
"scripts": {
|
|
13
|
-
"test": "
|
|
30
|
+
"test": "jest",
|
|
31
|
+
"test:clear": "jest --clearCache",
|
|
32
|
+
"test:cov": "jest --coverage",
|
|
33
|
+
"test:updateSnapshot": "jest --updateSnapshot",
|
|
34
|
+
"test:ci": "cross-env NODE_ENV=test jest --ci -i"
|
|
14
35
|
}
|
|
15
36
|
}
|
package/tsconfig.json
ADDED
package/.eslintrc.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
const config = require('../../.eslintrc.js')
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
parser: config.parser,
|
|
5
|
-
plugins: [
|
|
6
|
-
'@typescript-eslint'
|
|
7
|
-
],
|
|
8
|
-
parserOptions: { },
|
|
9
|
-
extends: [
|
|
10
|
-
'eslint:recommended',
|
|
11
|
-
'standard',
|
|
12
|
-
'plugin:@typescript-eslint/recommended',
|
|
13
|
-
'prettier'
|
|
14
|
-
],
|
|
15
|
-
rules: {
|
|
16
|
-
'@typescript-eslint/no-unused-vars': 0,
|
|
17
|
-
'@typescript-eslint/no-var-requires': 0
|
|
18
|
-
}
|
|
19
|
-
}
|