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 CHANGED
@@ -154,7 +154,21 @@ See `/LICENSE` for details of the license.
154
154
 
155
155
  ==================
156
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`
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
- const postcss = require('postcss')
2
-
3
- module.exports = postcss.plugin('postcss-taro-unit-transform', plugin)
4
-
5
- function plugin (opts) {
6
- return function (root) {
7
- root.walkDecls(function (decl) {
8
- let value = decl.value
9
- value = value.replace(/\b-?(\d+(\.\d+)?)px\b/ig, function (match, size) {
10
- // 绝对值<1的非0数值转十进制后会被转成0,赋值为1
11
- return Number(size) === 0 ? '0px': parseInt(size, 10) !== 0? (parseInt(size, 10) * 2) + 'px': '1px'
12
- }).replace(/\b-?(\d+(\.\d+)?)rpx\b/ig, function (match, size) {
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
- decl.value = value
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-canary.8",
3
+ "version": "4.0.0",
4
4
  "description": "小程序单位转换",
5
- "main": "index.js",
6
- "author": "luckyadam",
5
+ "author": "O2Team",
7
6
  "license": "MIT",
8
- "dependencies": {
9
- "postcss": "^6.0.21",
10
- "typescript": "^4.7.4"
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": "echo \"Error: no test specified\" && exit 1"
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
@@ -0,0 +1,5 @@
1
+ {
2
+ "compilerOptions": {
3
+ "esModuleInterop": true
4
+ }
5
+ }
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
- }