@tarojs/rn-style-transformer 4.0.1-alpha.0 → 4.0.1
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/.eslintrc.js +8 -0
- package/LICENSE +8 -8
- package/README.md +21 -36
- package/__tests__/config.spec.js +203 -0
- package/__tests__/index.spec.js +252 -0
- package/__tests__/platform.spec.js +78 -0
- package/__tests__/styles/b.css +3 -0
- package/__tests__/styles/b.less +3 -0
- package/__tests__/styles/b.rn.css +3 -0
- package/__tests__/styles/b.scss +3 -0
- package/__tests__/styles/b.styl +3 -0
- package/__tests__/styles/c.css +3 -0
- package/__tests__/styles/c.less +5 -0
- package/__tests__/styles/c.rn.scss +5 -0
- package/__tests__/styles/c.scss +5 -0
- package/__tests__/styles/d.rn.scss +3 -0
- package/__tests__/styles/d.scss +3 -0
- package/__tests__/styles/mixins.scss +18 -0
- package/__tests__/styles/nest.rn.less +3 -0
- package/__tests__/styles/variable.scss +1 -0
- package/babel.config.js +12 -0
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/transforms/StyleSheet/ColorPropType.js.map +1 -1
- package/dist/transforms/StyleSheet/ImageStylePropTypes.js +1 -1
- package/dist/transforms/StyleSheet/ImageStylePropTypes.js.map +1 -1
- package/dist/transforms/StyleSheet/ShadowPropTypesIOS.js +1 -1
- package/dist/transforms/StyleSheet/ShadowPropTypesIOS.js.map +1 -1
- package/dist/transforms/StyleSheet/StyleSheetValidation.js +1 -1
- package/dist/transforms/StyleSheet/StyleSheetValidation.js.map +1 -1
- package/dist/transforms/StyleSheet/TextStylePropTypes.js +1 -1
- package/dist/transforms/StyleSheet/TextStylePropTypes.js.map +1 -1
- package/dist/transforms/StyleSheet/TransformPropTypes.js.map +1 -1
- package/dist/transforms/StyleSheet/ViewStylePropTypes.js +1 -1
- package/dist/transforms/StyleSheet/ViewStylePropTypes.js.map +1 -1
- package/dist/transforms/StyleSheet/deprecatedPropType.js.map +1 -1
- package/dist/transforms/StyleSheet/normalizeColor.js.map +1 -1
- package/dist/transforms/index.js +6 -6
- package/dist/transforms/index.js.map +1 -1
- package/dist/transforms/less.js +1 -1
- package/dist/transforms/less.js.map +1 -1
- package/dist/transforms/postcss.js +5 -17
- package/dist/transforms/postcss.js.map +1 -1
- package/dist/transforms/sass.js +2 -2
- package/dist/transforms/sass.js.map +1 -1
- package/dist/transforms/stylus.js +1 -1
- package/dist/transforms/stylus.js.map +1 -1
- package/dist/utils/index.js +2 -2
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/reporterSkip.js.map +1 -1
- package/jest.config.js +8 -0
- package/package.json +31 -34
- package/src/config/rn-stylelint.json +5 -0
- package/src/index.ts +52 -0
- package/src/transforms/StyleSheet/ColorPropType.ts +76 -0
- package/src/transforms/StyleSheet/ImageResizeMode.ts +50 -0
- package/src/transforms/StyleSheet/ImageStylePropTypes.ts +62 -0
- package/src/transforms/StyleSheet/LayoutPropTypes.ts +559 -0
- package/src/transforms/StyleSheet/ShadowPropTypesIOS.ts +48 -0
- package/src/transforms/StyleSheet/StyleSheetValidation.ts +81 -0
- package/src/transforms/StyleSheet/TextStylePropTypes.ts +123 -0
- package/src/transforms/StyleSheet/TransformPropTypes.ts +109 -0
- package/src/transforms/StyleSheet/ViewStylePropTypes.ts +61 -0
- package/src/transforms/StyleSheet/deprecatedPropType.ts +31 -0
- package/src/transforms/StyleSheet/index.ts +5 -0
- package/src/transforms/StyleSheet/normalizeColor.ts +369 -0
- package/src/transforms/index.ts +231 -0
- package/src/transforms/less.ts +50 -0
- package/src/transforms/postcss.ts +96 -0
- package/src/transforms/sass.ts +151 -0
- package/src/transforms/stylus.ts +124 -0
- package/src/types/index.ts +242 -0
- package/src/utils/index.ts +229 -0
- package/src/utils/lessImport.ts +50 -0
- package/src/utils/reporterSkip.ts +27 -0
- package/tsconfig.json +12 -0
- package/dist/index.d.ts +0 -8
- package/dist/transforms/StyleSheet/ColorPropType.d.ts +0 -10
- package/dist/transforms/StyleSheet/ImageResizeMode.d.ts +0 -6
- package/dist/transforms/StyleSheet/ImageStylePropTypes.d.ts +0 -128
- package/dist/transforms/StyleSheet/LayoutPropTypes.d.ts +0 -388
- package/dist/transforms/StyleSheet/ShadowPropTypesIOS.d.ts +0 -45
- package/dist/transforms/StyleSheet/StyleSheetValidation.d.ts +0 -15
- package/dist/transforms/StyleSheet/TextStylePropTypes.d.ts +0 -191
- package/dist/transforms/StyleSheet/TransformPropTypes.d.ts +0 -67
- package/dist/transforms/StyleSheet/ViewStylePropTypes.d.ts +0 -136
- package/dist/transforms/StyleSheet/deprecatedPropType.d.ts +0 -13
- package/dist/transforms/StyleSheet/index.d.ts +0 -2
- package/dist/transforms/StyleSheet/normalizeColor.d.ts +0 -10
- package/dist/transforms/index.d.ts +0 -56
- package/dist/transforms/less.d.ts +0 -2
- package/dist/transforms/postcss.d.ts +0 -13
- package/dist/transforms/sass.d.ts +0 -2
- package/dist/transforms/stylus.d.ts +0 -3
- package/dist/types/index.d.ts +0 -206
- package/dist/utils/index.d.ts +0 -21
- package/dist/utils/lessImport.d.ts +0 -5
- package/dist/utils/reporterSkip.d.ts +0 -7
package/.eslintrc.js
ADDED
package/LICENSE
CHANGED
|
@@ -154,8 +154,15 @@ 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`
|
|
160
|
+
See `/LICENSE` for details of the license.
|
|
161
|
+
|
|
162
|
+
==================
|
|
163
|
+
|
|
157
164
|
MIT (weui):
|
|
158
|
-
The following files embed [
|
|
165
|
+
The following files embed [stencil-vue2-output-target](https://github.com/Tencent/weui) MIT:
|
|
159
166
|
`/packages/taro-components/src/components/*.scss`
|
|
160
167
|
See `/LICENSE.txt` for details of the license.
|
|
161
168
|
|
|
@@ -165,10 +172,3 @@ Apache-2.0 (intersection-observer):
|
|
|
165
172
|
The following files embed [intersection-observer](https://github.com/GoogleChromeLabs/intersection-observer) Apache-2.0:
|
|
166
173
|
`/packages/taro-api/src/polyfill/intersection-observer.ts`
|
|
167
174
|
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/*`
|
|
174
|
-
See `/LICENSE` for details of the license.
|
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
`object`
|
|
8
8
|
|
|
9
|
-
`postcss` 相关配置,其他样式语言预处理后经过此配置。
|
|
9
|
+
`postcss` 相关配置,其他样式语言预处理后经过此配置。
|
|
10
10
|
|
|
11
11
|
```js
|
|
12
12
|
module.exports = {
|
|
@@ -15,30 +15,19 @@ module.exports = {
|
|
|
15
15
|
// ...
|
|
16
16
|
postcss: {
|
|
17
17
|
// postcss 配置,参考 https://github.com/postcss/postcss#options
|
|
18
|
-
options: {
|
|
19
|
-
/* ... */
|
|
20
|
-
},
|
|
18
|
+
options: { /* ... */ },
|
|
21
19
|
// 默认true,控制是否对 css value 进行 scalePx2dp 转换,pxtransform配置 enable 才生效
|
|
22
20
|
scalable: boolean,
|
|
23
21
|
pxtransform: {
|
|
24
22
|
enable: boolean, // 默认true
|
|
25
|
-
config: {
|
|
26
|
-
/* ... */
|
|
27
|
-
}, // 插件 pxtransform 配置项,参考尺寸章节
|
|
23
|
+
config: { /* ... */ } // 插件 pxtransform 配置项,参考尺寸章节
|
|
28
24
|
},
|
|
29
25
|
// 跟其他端 css module 配置保持统一
|
|
30
26
|
cssModules: {
|
|
31
27
|
enable: true, // 默认为 false,如需使用 css modules 功能,则设为 true
|
|
32
|
-
}
|
|
33
|
-
// postcss-css-variables 配置,样式变量编译相关
|
|
34
|
-
'postcss-css-variables': {
|
|
35
|
-
enable: boolean, // 默认 true
|
|
36
|
-
config: {
|
|
37
|
-
/* ... */
|
|
38
|
-
}, // 插件 postcss-css-variables 配置项,参考 https://github.com/MadLittleMods/postcss-css-variables?tab=readme-ov-file#options
|
|
39
|
-
},
|
|
28
|
+
}
|
|
40
29
|
},
|
|
41
|
-
}
|
|
30
|
+
}
|
|
42
31
|
}
|
|
43
32
|
```
|
|
44
33
|
|
|
@@ -46,7 +35,7 @@ module.exports = {
|
|
|
46
35
|
|
|
47
36
|
`object`
|
|
48
37
|
|
|
49
|
-
`sass` 相关配置。`options` 配置项参考[官方文档](https://github.com/sass/node-sass#options)。
|
|
38
|
+
`sass` 相关配置。`options` 配置项参考[官方文档](https://github.com/sass/node-sass#options)。
|
|
50
39
|
|
|
51
40
|
```js
|
|
52
41
|
module.exports = {
|
|
@@ -54,13 +43,11 @@ module.exports = {
|
|
|
54
43
|
rn: {
|
|
55
44
|
// ...
|
|
56
45
|
sass: {
|
|
57
|
-
options: {
|
|
58
|
-
|
|
59
|
-
},
|
|
60
|
-
// 加入到脚本注入的每个 sass 文件头部,在 config.sass 之前
|
|
46
|
+
options: { /* ... */ },
|
|
47
|
+
// 加入到脚本注入的每个 sass 文件头部,在 config.sass 之前
|
|
61
48
|
additionalData: '', // {String|Function}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
64
51
|
}
|
|
65
52
|
```
|
|
66
53
|
|
|
@@ -76,12 +63,10 @@ module.exports = {
|
|
|
76
63
|
rn: {
|
|
77
64
|
// ...
|
|
78
65
|
less: {
|
|
79
|
-
options: {
|
|
80
|
-
/* ... */
|
|
81
|
-
},
|
|
66
|
+
options: { /* ... */ },
|
|
82
67
|
additionalData: '', // {String|Function}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
85
70
|
}
|
|
86
71
|
```
|
|
87
72
|
|
|
@@ -89,7 +74,7 @@ module.exports = {
|
|
|
89
74
|
|
|
90
75
|
`object`
|
|
91
76
|
|
|
92
|
-
`stylus` 相关配置。`options` 配置项如下。
|
|
77
|
+
`stylus` 相关配置。`options` 配置项如下。
|
|
93
78
|
|
|
94
79
|
```js
|
|
95
80
|
module.exports = {
|
|
@@ -104,7 +89,7 @@ module.exports = {
|
|
|
104
89
|
* @type {(string|Function)[]}
|
|
105
90
|
* @default []
|
|
106
91
|
*/
|
|
107
|
-
use: [
|
|
92
|
+
use: ["nib"],
|
|
108
93
|
|
|
109
94
|
/**
|
|
110
95
|
* Add path(s) to the import lookup paths.
|
|
@@ -112,7 +97,7 @@ module.exports = {
|
|
|
112
97
|
* @type {string[]}
|
|
113
98
|
* @default []
|
|
114
99
|
*/
|
|
115
|
-
include: [path.join(__dirname,
|
|
100
|
+
include: [path.join(__dirname, "src/styl/config")],
|
|
116
101
|
|
|
117
102
|
/**
|
|
118
103
|
* Import the specified Stylus files/paths.
|
|
@@ -120,7 +105,7 @@ module.exports = {
|
|
|
120
105
|
* @type {string[]}
|
|
121
106
|
* @default []
|
|
122
107
|
*/
|
|
123
|
-
import: [
|
|
108
|
+
import: ["nib", path.join(__dirname, "src/styl/mixins")],
|
|
124
109
|
|
|
125
110
|
/**
|
|
126
111
|
* Define Stylus variables or functions.
|
|
@@ -130,8 +115,8 @@ module.exports = {
|
|
|
130
115
|
*/
|
|
131
116
|
// Array is the recommended syntax: [key, value, raw]
|
|
132
117
|
define: [
|
|
133
|
-
[
|
|
134
|
-
[
|
|
118
|
+
["$development", process.env.NODE_ENV === "development"],
|
|
119
|
+
["rawVar", 42, true],
|
|
135
120
|
],
|
|
136
121
|
// Object is deprecated syntax (there is no possibility to specify "raw')
|
|
137
122
|
// define: {
|
|
@@ -168,7 +153,7 @@ module.exports = {
|
|
|
168
153
|
hoistAtrules: true,
|
|
169
154
|
},
|
|
170
155
|
additionalData: '', // {String|Function}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
173
158
|
}
|
|
174
159
|
```
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { recursiveMerge } from '@tarojs/helper'
|
|
2
|
+
import * as path from 'path'
|
|
3
|
+
|
|
4
|
+
import StyleTransform, { getWrapedCSS } from '../src/transforms'
|
|
5
|
+
|
|
6
|
+
const defaultConfig = {
|
|
7
|
+
designWidth: 750,
|
|
8
|
+
deviceRatio: {
|
|
9
|
+
640: 2.34 / 2,
|
|
10
|
+
750: 1,
|
|
11
|
+
828: 1.81 / 2
|
|
12
|
+
},
|
|
13
|
+
alias: {
|
|
14
|
+
'@': path.resolve(__dirname, './styles')
|
|
15
|
+
},
|
|
16
|
+
rn: {
|
|
17
|
+
postcss: {
|
|
18
|
+
options: {
|
|
19
|
+
plugins: []
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
sass: {
|
|
23
|
+
options: {},
|
|
24
|
+
additionalData: ''
|
|
25
|
+
},
|
|
26
|
+
less: {
|
|
27
|
+
options: {},
|
|
28
|
+
additionalData: ''
|
|
29
|
+
},
|
|
30
|
+
stylus: {
|
|
31
|
+
options: {},
|
|
32
|
+
additionalData: ''
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function run (src, filename = './__tests__/styles/a.css', debug) {
|
|
38
|
+
let options = { platform: 'android' }
|
|
39
|
+
let config
|
|
40
|
+
|
|
41
|
+
if (typeof src === 'object') {
|
|
42
|
+
({
|
|
43
|
+
src,
|
|
44
|
+
filename = './__tests__/styles/a.css',
|
|
45
|
+
options = { platform: 'android' },
|
|
46
|
+
debug,
|
|
47
|
+
config
|
|
48
|
+
} = src || {})
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const mergeConfig = recursiveMerge({}, defaultConfig, config)
|
|
52
|
+
// console.log('mergeConfig', JSON.stringify(mergeConfig, null, ' '))
|
|
53
|
+
const styleTransform = new StyleTransform(mergeConfig)
|
|
54
|
+
const css = await styleTransform.transform(src, filename, options)
|
|
55
|
+
if (debug) {
|
|
56
|
+
// eslint-disable-next-line
|
|
57
|
+
console.log(filename + ' source: ', src)
|
|
58
|
+
// eslint-disable-next-line
|
|
59
|
+
console.log(filename + ' target: ', css)
|
|
60
|
+
}
|
|
61
|
+
return css
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
describe('style transform with config options', () => {
|
|
65
|
+
it('config.sass option', async () => {
|
|
66
|
+
const css = await run({
|
|
67
|
+
src: `
|
|
68
|
+
.test {
|
|
69
|
+
color: $base-color;
|
|
70
|
+
height: 10px;
|
|
71
|
+
}
|
|
72
|
+
`,
|
|
73
|
+
config: {
|
|
74
|
+
sass: {
|
|
75
|
+
resource: [
|
|
76
|
+
'__tests__/styles/variable.scss',
|
|
77
|
+
'__tests__/styles/b.css'
|
|
78
|
+
],
|
|
79
|
+
projectDirectory: path.resolve(__dirname, '..'),
|
|
80
|
+
data: '.data { width: 200px }'
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
filename: './__tests__/styles/a.scss'
|
|
84
|
+
})
|
|
85
|
+
expect(css).toEqual(getWrapedCSS(`{
|
|
86
|
+
"brn": {
|
|
87
|
+
"color": "red"
|
|
88
|
+
},
|
|
89
|
+
"data": {
|
|
90
|
+
"width": scalePx2dp(100)
|
|
91
|
+
},
|
|
92
|
+
"test": {
|
|
93
|
+
"color": "#c6538c",
|
|
94
|
+
"height": scalePx2dp(5)
|
|
95
|
+
}
|
|
96
|
+
}`))
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
it('config.sass option without projectDirectory', async () => {
|
|
100
|
+
const css = await run({
|
|
101
|
+
src: `
|
|
102
|
+
.test {
|
|
103
|
+
color: $base-color;
|
|
104
|
+
height: 10px;
|
|
105
|
+
}
|
|
106
|
+
`,
|
|
107
|
+
filename: './__tests__/styles/a.scss',
|
|
108
|
+
config: {
|
|
109
|
+
sass: {
|
|
110
|
+
resource: [
|
|
111
|
+
path.resolve(__dirname, 'styles/variable.scss'),
|
|
112
|
+
path.resolve(__dirname, 'styles/b.css')
|
|
113
|
+
],
|
|
114
|
+
projectDirectory: path.resolve(__dirname, '..'),
|
|
115
|
+
data: '.data { width: 200px }'
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
})
|
|
119
|
+
expect(css).toEqual(getWrapedCSS(`{
|
|
120
|
+
"brn": {
|
|
121
|
+
"color": "red"
|
|
122
|
+
},
|
|
123
|
+
"data": {
|
|
124
|
+
"width": scalePx2dp(100)
|
|
125
|
+
},
|
|
126
|
+
"test": {
|
|
127
|
+
"color": "#c6538c",
|
|
128
|
+
"height": scalePx2dp(5)
|
|
129
|
+
}
|
|
130
|
+
}`))
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
it('config.postcss disable pxTransform', async () => {
|
|
134
|
+
const css = await run(`
|
|
135
|
+
.test {
|
|
136
|
+
height: 10px;
|
|
137
|
+
}
|
|
138
|
+
`)
|
|
139
|
+
expect(css).toEqual(getWrapedCSS(`{
|
|
140
|
+
"test": {
|
|
141
|
+
"height": scalePx2dp(5)
|
|
142
|
+
}
|
|
143
|
+
}`))
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
it('config.postcss disable scalePx2dp', async () => {
|
|
147
|
+
const config = {
|
|
148
|
+
rn: {
|
|
149
|
+
postcss: {
|
|
150
|
+
options: {
|
|
151
|
+
plugins: []
|
|
152
|
+
},
|
|
153
|
+
scalable: false
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
const css = await run({
|
|
158
|
+
src: `
|
|
159
|
+
.test {
|
|
160
|
+
height: 10px;
|
|
161
|
+
}
|
|
162
|
+
`,
|
|
163
|
+
config
|
|
164
|
+
})
|
|
165
|
+
expect(css).toEqual(getWrapedCSS(`{
|
|
166
|
+
"test": {
|
|
167
|
+
"height": 5
|
|
168
|
+
}
|
|
169
|
+
}`))
|
|
170
|
+
})
|
|
171
|
+
it('config.alias in css', async () => {
|
|
172
|
+
const css = await run("@import '@/b.css';")
|
|
173
|
+
expect(css).toEqual(getWrapedCSS(`{
|
|
174
|
+
"brn": {
|
|
175
|
+
"color": "red"
|
|
176
|
+
}
|
|
177
|
+
}`))
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
it('config.alias in sass', async () => {
|
|
181
|
+
const css = await run({
|
|
182
|
+
src: "@import '@/b.scss';",
|
|
183
|
+
filename: './__tests__/styles/a.scss'
|
|
184
|
+
})
|
|
185
|
+
expect(css).toEqual(getWrapedCSS(`{
|
|
186
|
+
"b": {
|
|
187
|
+
"color": "red"
|
|
188
|
+
}
|
|
189
|
+
}`))
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
it('config.alias in less', async () => {
|
|
193
|
+
const css = await run({
|
|
194
|
+
src: "@import '@/b.less';",
|
|
195
|
+
filename: './__tests__/styles/a.less'
|
|
196
|
+
})
|
|
197
|
+
expect(css).toEqual(getWrapedCSS(`{
|
|
198
|
+
"b": {
|
|
199
|
+
"color": "red"
|
|
200
|
+
}
|
|
201
|
+
}`))
|
|
202
|
+
})
|
|
203
|
+
})
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import StyleTransform, { getWrapedCSS } from '../src/transforms'
|
|
2
|
+
|
|
3
|
+
// 初始化
|
|
4
|
+
const styleTransform = new StyleTransform({})
|
|
5
|
+
|
|
6
|
+
async function run (src, filename = './__tests__/styles/a.css', debug) {
|
|
7
|
+
let options = { platform: 'android' }
|
|
8
|
+
|
|
9
|
+
if (typeof src === 'object') {
|
|
10
|
+
({
|
|
11
|
+
src,
|
|
12
|
+
filename = './__tests__/styles/a.css',
|
|
13
|
+
options = { platform: 'android' },
|
|
14
|
+
debug
|
|
15
|
+
} = src || {})
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const css = await styleTransform.transform(src, filename, options)
|
|
19
|
+
if (debug) {
|
|
20
|
+
// eslint-disable-next-line
|
|
21
|
+
console.log(filename + ' source: ', src)
|
|
22
|
+
// eslint-disable-next-line
|
|
23
|
+
console.log(filename + ' target: ', css)
|
|
24
|
+
}
|
|
25
|
+
return css
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
describe('style transform', () => {
|
|
29
|
+
it('.css transform basic', async () => {
|
|
30
|
+
const css = await run(`
|
|
31
|
+
.test {
|
|
32
|
+
color: red;
|
|
33
|
+
height: 10px;
|
|
34
|
+
}
|
|
35
|
+
`)
|
|
36
|
+
expect(css).toEqual(getWrapedCSS(`{
|
|
37
|
+
"test": {
|
|
38
|
+
"color": "red",
|
|
39
|
+
"height": scalePx2dp(5)
|
|
40
|
+
}
|
|
41
|
+
}`))
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it('.css transform viewport unit', async () => {
|
|
45
|
+
const css = await run(`
|
|
46
|
+
.test {
|
|
47
|
+
height: 10vh;
|
|
48
|
+
}
|
|
49
|
+
`)
|
|
50
|
+
expect(css).toEqual(getWrapedCSS(`{
|
|
51
|
+
"test": {
|
|
52
|
+
"height": scaleVu2dp(10, 'vh')
|
|
53
|
+
},
|
|
54
|
+
"__viewportUnits": true
|
|
55
|
+
}`))
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it('.css transform @import', async () => {
|
|
59
|
+
const css = await run(`
|
|
60
|
+
@import './b.css';
|
|
61
|
+
.test {
|
|
62
|
+
color: red;
|
|
63
|
+
}
|
|
64
|
+
`)
|
|
65
|
+
expect(css).toEqual(getWrapedCSS(`{
|
|
66
|
+
"brn": {
|
|
67
|
+
"color": "red"
|
|
68
|
+
},
|
|
69
|
+
"test": {
|
|
70
|
+
"color": "red"
|
|
71
|
+
}
|
|
72
|
+
}`))
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
it('.css import source omit extension', async () => {
|
|
76
|
+
const css = await run("@import './b';", './__tests__/styles/a.css')
|
|
77
|
+
expect(css).toEqual(getWrapedCSS(`{
|
|
78
|
+
"brn": {
|
|
79
|
+
"color": "red"
|
|
80
|
+
}
|
|
81
|
+
}`))
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
it('.sass transform basic', async () => {
|
|
85
|
+
const css = await run(`
|
|
86
|
+
.test {
|
|
87
|
+
color: red;
|
|
88
|
+
}
|
|
89
|
+
`, './__tests__/styles/a.scss')
|
|
90
|
+
expect(css).toEqual(getWrapedCSS(`{
|
|
91
|
+
"test": {
|
|
92
|
+
"color": "red"
|
|
93
|
+
}
|
|
94
|
+
}`))
|
|
95
|
+
})
|
|
96
|
+
//
|
|
97
|
+
it('.sass transform @import', async () => {
|
|
98
|
+
const css = await run(`
|
|
99
|
+
@import './b.scss';
|
|
100
|
+
.test {
|
|
101
|
+
color: red;
|
|
102
|
+
}
|
|
103
|
+
`, './__tests__/styles/a.scss')
|
|
104
|
+
expect(css).toEqual(getWrapedCSS(`{
|
|
105
|
+
"b": {
|
|
106
|
+
"color": "red"
|
|
107
|
+
},
|
|
108
|
+
"test": {
|
|
109
|
+
"color": "red"
|
|
110
|
+
}
|
|
111
|
+
}`))
|
|
112
|
+
})
|
|
113
|
+
it('.sass transform @import css file', async () => {
|
|
114
|
+
const css = await run(`
|
|
115
|
+
@import './c.css';
|
|
116
|
+
.test {
|
|
117
|
+
color: red;
|
|
118
|
+
}
|
|
119
|
+
`, './__tests__/styles/a.scss')
|
|
120
|
+
expect(css).toEqual(getWrapedCSS(`{
|
|
121
|
+
"c": {
|
|
122
|
+
"color": "red"
|
|
123
|
+
},
|
|
124
|
+
"test": {
|
|
125
|
+
"color": "red"
|
|
126
|
+
}
|
|
127
|
+
}`))
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
it('.sass transform @import with mixins', async () => {
|
|
131
|
+
const css = await run(`
|
|
132
|
+
@import './mixins.scss';
|
|
133
|
+
.test {
|
|
134
|
+
color: red;
|
|
135
|
+
@include hairline(width);
|
|
136
|
+
}
|
|
137
|
+
`, './__tests__/styles/a.scss')
|
|
138
|
+
expect(css).toEqual(getWrapedCSS(`{
|
|
139
|
+
"test": {
|
|
140
|
+
"color": "red",
|
|
141
|
+
"width": scalePx2dp(0.5)
|
|
142
|
+
}
|
|
143
|
+
}`))
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
it('.sass import source omit extension', async () => {
|
|
147
|
+
const css = await run("@import './b';", './__tests__/styles/a.scss')
|
|
148
|
+
expect(css).toEqual(getWrapedCSS(`{
|
|
149
|
+
"b": {
|
|
150
|
+
"color": "red"
|
|
151
|
+
}
|
|
152
|
+
}`))
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
it('.less transform basic', async () => {
|
|
156
|
+
const css = await run(`
|
|
157
|
+
.test {
|
|
158
|
+
color: red;
|
|
159
|
+
}
|
|
160
|
+
`, './__tests__/styles/a.less')
|
|
161
|
+
expect(css).toEqual(getWrapedCSS(`{
|
|
162
|
+
"test": {
|
|
163
|
+
"color": "red"
|
|
164
|
+
}
|
|
165
|
+
}`))
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
it('.less transform @import', async () => {
|
|
169
|
+
const css = await run(`
|
|
170
|
+
@import './b.less';
|
|
171
|
+
.test {
|
|
172
|
+
color: red;
|
|
173
|
+
}
|
|
174
|
+
`, './__tests__/styles/a.less')
|
|
175
|
+
expect(css).toEqual(getWrapedCSS(`{
|
|
176
|
+
"b": {
|
|
177
|
+
"color": "red"
|
|
178
|
+
},
|
|
179
|
+
"test": {
|
|
180
|
+
"color": "red"
|
|
181
|
+
}
|
|
182
|
+
}`))
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
it('.less tranform nest import', async () => {
|
|
186
|
+
const css = await run(`
|
|
187
|
+
@import './c.less';
|
|
188
|
+
.test {
|
|
189
|
+
color: red;
|
|
190
|
+
}
|
|
191
|
+
`, './__tests__/styles/a.less')
|
|
192
|
+
expect(css).toEqual(getWrapedCSS(`{
|
|
193
|
+
"nest": {
|
|
194
|
+
"color": "red"
|
|
195
|
+
},
|
|
196
|
+
"c": {
|
|
197
|
+
"color": "red"
|
|
198
|
+
},
|
|
199
|
+
"test": {
|
|
200
|
+
"color": "red"
|
|
201
|
+
}
|
|
202
|
+
}`))
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
it('.less tranform node_modules file import', async () => {
|
|
206
|
+
const css = await run("@import 'less/test/browser/css/global-vars/simple.css';", './__tests__/styles/a.less')
|
|
207
|
+
expect(css).toEqual(getWrapedCSS(`{
|
|
208
|
+
"test": {
|
|
209
|
+
"color": "red"
|
|
210
|
+
}
|
|
211
|
+
}`))
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
it('.less import source omit extension', async () => {
|
|
215
|
+
const css = await run("@import './b';", './__tests__/styles/a.less')
|
|
216
|
+
expect(css).toEqual(getWrapedCSS(`{
|
|
217
|
+
"b": {
|
|
218
|
+
"color": "red"
|
|
219
|
+
}
|
|
220
|
+
}`))
|
|
221
|
+
})
|
|
222
|
+
|
|
223
|
+
it('.styl transform basic', async () => {
|
|
224
|
+
const css = await run(`
|
|
225
|
+
.test {
|
|
226
|
+
color: red;
|
|
227
|
+
}
|
|
228
|
+
`, './__tests__/styles/a.styl')
|
|
229
|
+
expect(css).toEqual(getWrapedCSS(`{
|
|
230
|
+
"test": {
|
|
231
|
+
"color": "#f00"
|
|
232
|
+
}
|
|
233
|
+
}`))
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
it('.styl transform @import', async () => {
|
|
237
|
+
const css = await run(`
|
|
238
|
+
@import './b.styl';
|
|
239
|
+
.test {
|
|
240
|
+
color: red;
|
|
241
|
+
}
|
|
242
|
+
`, './__tests__/styles/a.styl')
|
|
243
|
+
expect(css).toEqual(getWrapedCSS(`{
|
|
244
|
+
"b": {
|
|
245
|
+
"color": "#f00"
|
|
246
|
+
},
|
|
247
|
+
"test": {
|
|
248
|
+
"color": "#f00"
|
|
249
|
+
}
|
|
250
|
+
}`))
|
|
251
|
+
})
|
|
252
|
+
})
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import StyleTransform, { getWrapedCSS } from '../src/transforms'
|
|
2
|
+
|
|
3
|
+
// 初始化config
|
|
4
|
+
const styleTransform = new StyleTransform({})
|
|
5
|
+
|
|
6
|
+
async function run (src, filename = './__tests__/styles/a.css', options = { platform: 'android' }, debug) {
|
|
7
|
+
if (typeof src === 'object') {
|
|
8
|
+
({
|
|
9
|
+
src,
|
|
10
|
+
filename = './__tests__/styles/a.css',
|
|
11
|
+
options = { platform: 'android' },
|
|
12
|
+
debug
|
|
13
|
+
} = src || {})
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const css = await styleTransform.transform(src, filename, options)
|
|
17
|
+
if (debug) {
|
|
18
|
+
// eslint-disable-next-line
|
|
19
|
+
console.log(filename + ' source: ', src)
|
|
20
|
+
// eslint-disable-next-line
|
|
21
|
+
console.log(filename + ' target: ', css)
|
|
22
|
+
}
|
|
23
|
+
return css
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
describe('style transform in cross platform', () => {
|
|
27
|
+
it('postcss cross platform conditional compile', async () => {
|
|
28
|
+
const css = await run(`
|
|
29
|
+
.test {
|
|
30
|
+
color: red;
|
|
31
|
+
}
|
|
32
|
+
/* #ifdef rn */
|
|
33
|
+
.rn { width: 100px }
|
|
34
|
+
/* #endif */
|
|
35
|
+
/* #ifndef rn */
|
|
36
|
+
.h5 { errSet: 100px }
|
|
37
|
+
/* #endif */
|
|
38
|
+
`)
|
|
39
|
+
expect(css).toEqual(getWrapedCSS(`{
|
|
40
|
+
"test": {
|
|
41
|
+
"color": "red"
|
|
42
|
+
},
|
|
43
|
+
"rn": {
|
|
44
|
+
"width": scalePx2dp(50)
|
|
45
|
+
}
|
|
46
|
+
}`))
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('not surport style', async () => {
|
|
50
|
+
const css = await run(`
|
|
51
|
+
.test {
|
|
52
|
+
o: 0.5;
|
|
53
|
+
background: red;
|
|
54
|
+
}
|
|
55
|
+
`)
|
|
56
|
+
expect(css).toEqual(getWrapedCSS(`{
|
|
57
|
+
"test": {
|
|
58
|
+
"o": 0.5,
|
|
59
|
+
"backgroundColor": "red"
|
|
60
|
+
}
|
|
61
|
+
}`))
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('nest sass import cross platform', async () => {
|
|
65
|
+
const css = await run({
|
|
66
|
+
filename: './__tests__/styles/a.scss',
|
|
67
|
+
src: "@import './c.scss';"
|
|
68
|
+
})
|
|
69
|
+
expect(css).toEqual(getWrapedCSS(`{
|
|
70
|
+
"drn": {
|
|
71
|
+
"color": "red"
|
|
72
|
+
},
|
|
73
|
+
"crn": {
|
|
74
|
+
"color": "red"
|
|
75
|
+
}
|
|
76
|
+
}`))
|
|
77
|
+
})
|
|
78
|
+
})
|