@aiot-toolkit/parser 2.0.5-beta.8 → 2.0.5-widget-provider-beta.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/README.md +11 -11
- package/lib/index.d.ts +1 -4
- package/lib/index.js +0 -27
- package/lib/utils/ParserUtil.js +15 -15
- package/lib/ux/config/ExtensionConfig.js +2 -2
- package/lib/ux/config/FeatureConfig.js +19 -19
- package/lib/ux/config/vela/StyleAttributeConfig.js +87 -87
- package/lib/ux/enum/StyleSelectorType.js +6 -6
- package/lib/ux/enum/TemplateNodeType.js +2 -2
- package/lib/ux/enum/android/StyleSelectorName.js +2 -2
- package/lib/ux/parser/ScriptParser.js +2 -2
- package/lib/ux/parser/StyleParser.js +62 -62
- package/lib/ux/parser/TemplateValueParser.js +49 -49
- package/lib/ux/parser/UxParser.js +11 -11
- package/lib/ux/translate/android/StyleToTypescript.js +51 -51
- package/lib/ux/translate/android/TemplateToTypescript.js +51 -51
- package/lib/ux/translate/android/UxToTypescript.js +14 -14
- package/lib/ux/translate/android/attributeTranslate/ForTranslate.js +17 -17
- package/lib/ux/translate/android/attributeTranslate/IfTranslate.js +9 -9
- package/lib/ux/translate/vela/ScriptToTypescript.js +13 -12
- package/lib/ux/translate/vela/StyleToTypescript.js +10 -10
- package/lib/ux/translate/vela/TemplateToTypescript.js +74 -74
- package/lib/ux/translate/vela/TranslateCache.js +2 -2
- package/lib/ux/translate/vela/UxToTypescript.js +6 -6
- package/lib/ux/translate/vela/VelaContext.js +2 -2
- package/lib/ux/translate/vela/plugins/e2e.js +61 -61
- package/lib/ux/translate/vela/protobuf/BinaryPlugin.js +172 -172
- package/lib/ux/translate/vela/protobuf/protobuf.js +235 -235
- package/lib/ux/translate/vela/protobuf/protobufControl.js +159 -159
- package/lib/ux/translate/vela/protobuf/vdom_pb.js +2374 -2374
- package/lib/ux/translate/vela/runtime/velaTestLibrary.js +104 -104
- package/lib/ux/translate/vela/utils/AttributeConfig.js +15 -15
- package/lib/ux/translate/vela/utils/ExtendedBoxStyle.js +38 -38
- package/lib/ux/translate/vela/utils/SourceMapUtil.js +30 -30
- package/lib/ux/translate/vela/utils/TemplateUtil.d.ts +10 -8
- package/lib/ux/translate/vela/utils/TemplateUtil.js +206 -191
- package/lib/ux/translate/vela/wrap/CbTranslate.js +8 -8
- package/lib/ux/translate/vela/wrap/CfTranslate.js +14 -14
- package/lib/ux/translate/vela/wrap/CiTranslate.js +11 -11
- package/lib/ux/utils/BabelUtil.js +35 -35
- package/lib/ux/utils/ElementConfigUtil.js +24 -24
- package/lib/ux/utils/StyleMapUtil.js +26 -16
- package/lib/ux/utils/StyleUtil.js +176 -174
- package/lib/ux/utils/UxUtil.js +32 -32
- package/lib/ux/validate/ElementValidate.js +2 -2
- package/lib/ux/validate/UxFileValidate.js +2 -2
- package/package.json +6 -6
- package/lib/xts/XtsParser.d.ts +0 -20
- package/lib/xts/XtsParser.js +0 -86
- package/lib/xts/XtsToTypescript.d.ts +0 -69
- package/lib/xts/XtsToTypescript.js +0 -894
- package/lib/xts/config/CommonAttributeList.d.ts +0 -6
- package/lib/xts/config/CommonAttributeList.js +0 -17
- package/lib/xts/config/classCount.json +0 -38
- package/lib/xts/config/commonAttribute.json +0 -84
- package/lib/xts/config/componentList.d.ts +0 -56
- package/lib/xts/config/componentList.js +0 -9
- package/lib/xts/config/predefinedComponent.json +0 -91
- package/lib/xts/config/render.json +0 -31
- package/lib/xts/data/ElementType.d.ts +0 -6
- package/lib/xts/data/ElementType.js +0 -5
- package/lib/xts/data/element/CommentElement.d.ts +0 -16
- package/lib/xts/data/element/CommentElement.js +0 -26
- package/lib/xts/data/element/ElementBase.d.ts +0 -14
- package/lib/xts/data/element/ElementBase.js +0 -20
- package/lib/xts/data/element/ForElement.d.ts +0 -58
- package/lib/xts/data/element/ForElement.js +0 -81
- package/lib/xts/data/element/IfElement.d.ts +0 -55
- package/lib/xts/data/element/IfElement.js +0 -87
- package/lib/xts/data/element/NodeElement.d.ts +0 -39
- package/lib/xts/data/element/NodeElement.js +0 -86
- package/lib/xts/enum/AttributeType.d.ts +0 -31
- package/lib/xts/enum/AttributeType.js +0 -53
- package/lib/xts/enum/Framework.d.ts +0 -98
- package/lib/xts/enum/Framework.js +0 -107
- package/lib/xts/interface/IContext.d.ts +0 -11
- package/lib/xts/interface/IContext.js +0 -1
- package/lib/xts/interface/IElement.d.ts +0 -17
- package/lib/xts/interface/IElement.js +0 -5
- package/lib/xts/interface/IExpressNode.d.ts +0 -20
- package/lib/xts/interface/IExpressNode.js +0 -1
- package/lib/xts/interface/config/ICommon.d.ts +0 -23
- package/lib/xts/interface/config/ICommon.js +0 -5
- package/lib/xts/interface/config/IRenderNode.d.ts +0 -25
- package/lib/xts/interface/config/IRenderNode.js +0 -1
- package/lib/xts/interface/validate/IAttibuteValidate.d.ts +0 -8
- package/lib/xts/interface/validate/IAttibuteValidate.js +0 -1
- package/lib/xts/interface/validate/IComponentValidate.d.ts +0 -9
- package/lib/xts/interface/validate/IComponentValidate.js +0 -1
- package/lib/xts/interface/validate/IRenderValidate.d.ts +0 -10
- package/lib/xts/interface/validate/IRenderValidate.js +0 -1
- package/lib/xts/interface/validate/ISourceFileValidate.d.ts +0 -7
- package/lib/xts/interface/validate/ISourceFileValidate.js +0 -1
- package/lib/xts/utils/AttributeUtil.d.ts +0 -73
- package/lib/xts/utils/AttributeUtil.js +0 -206
- package/lib/xts/utils/TypeUtil.d.ts +0 -60
- package/lib/xts/utils/TypeUtil.js +0 -97
- package/lib/xts/utils/TypescriptUtil.d.ts +0 -42
- package/lib/xts/utils/TypescriptUtil.js +0 -128
- package/lib/xts/validate/AttibuteValidate.d.ts +0 -18
- package/lib/xts/validate/AttibuteValidate.js +0 -97
- package/lib/xts/validate/ComponentValidate.d.ts +0 -19
- package/lib/xts/validate/ComponentValidate.js +0 -90
- package/lib/xts/validate/RenderValidate.d.ts +0 -63
- package/lib/xts/validate/RenderValidate.js +0 -239
- package/lib/xts/validate/SourceFileValidate.d.ts +0 -10
- package/lib/xts/validate/SourceFileValidate.js +0 -43
|
@@ -12,86 +12,84 @@ var _path = _interopRequireDefault(require("path"));
|
|
|
12
12
|
var _CompressConfig = require("../config/CompressConfig");
|
|
13
13
|
var _StyleSelectorType = require("../enum/StyleSelectorType");
|
|
14
14
|
var _StyleAttributeConfig = require("../config/vela/StyleAttributeConfig");
|
|
15
|
-
var
|
|
16
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
17
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
15
|
+
var _tinycolor = _interopRequireDefault(require("tinycolor2"));
|
|
18
16
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
19
|
-
/**
|
|
20
|
-
* StyleUtil
|
|
17
|
+
/**
|
|
18
|
+
* StyleUtil
|
|
21
19
|
*/
|
|
22
20
|
class StyleUtil {
|
|
23
|
-
/**
|
|
24
|
-
* 判断节点是否为declaration节点
|
|
25
|
-
* @param node
|
|
26
|
-
* @returns
|
|
21
|
+
/**
|
|
22
|
+
* 判断节点是否为declaration节点
|
|
23
|
+
* @param node
|
|
24
|
+
* @returns
|
|
27
25
|
*/
|
|
28
26
|
static isDeclaration(node) {
|
|
29
27
|
return node.type === 'Declaration';
|
|
30
28
|
}
|
|
31
29
|
|
|
32
|
-
/**
|
|
33
|
-
* 判断节点是否为Identifier类型
|
|
34
|
-
* @param node
|
|
35
|
-
* @returns
|
|
30
|
+
/**
|
|
31
|
+
* 判断节点是否为Identifier类型
|
|
32
|
+
* @param node
|
|
33
|
+
* @returns
|
|
36
34
|
*/
|
|
37
35
|
static isIdentifier(node) {
|
|
38
36
|
return node.type === 'Identifier';
|
|
39
37
|
}
|
|
40
38
|
|
|
41
|
-
/**
|
|
42
|
-
* 判断节点是否为SelectorList类型
|
|
43
|
-
* @param node
|
|
44
|
-
* @returns
|
|
39
|
+
/**
|
|
40
|
+
* 判断节点是否为SelectorList类型
|
|
41
|
+
* @param node
|
|
42
|
+
* @returns
|
|
45
43
|
*/
|
|
46
44
|
static isSelectorList(node) {
|
|
47
45
|
return node.type === 'SelectorList';
|
|
48
46
|
}
|
|
49
47
|
|
|
50
|
-
/**
|
|
51
|
-
* 判断节点是否为AtrulePrelude类型
|
|
52
|
-
* @param node
|
|
53
|
-
* @returns
|
|
48
|
+
/**
|
|
49
|
+
* 判断节点是否为AtrulePrelude类型
|
|
50
|
+
* @param node
|
|
51
|
+
* @returns
|
|
54
52
|
*/
|
|
55
53
|
static isAtrulePrelude(node) {
|
|
56
54
|
return node.type === 'AtrulePrelude';
|
|
57
55
|
}
|
|
58
56
|
|
|
59
|
-
/**
|
|
60
|
-
* 判断节点是否为MediaFeature类型
|
|
61
|
-
* @param node
|
|
62
|
-
* @returns
|
|
57
|
+
/**
|
|
58
|
+
* 判断节点是否为MediaFeature类型
|
|
59
|
+
* @param node
|
|
60
|
+
* @returns
|
|
63
61
|
*/
|
|
64
62
|
static isMediaFeature(node) {
|
|
65
63
|
return node.type === 'MediaFeature';
|
|
66
64
|
}
|
|
67
|
-
/**
|
|
68
|
-
* 判断节点是否为MediaQuery类型
|
|
69
|
-
* @param node
|
|
70
|
-
* @returns
|
|
65
|
+
/**
|
|
66
|
+
* 判断节点是否为MediaQuery类型
|
|
67
|
+
* @param node
|
|
68
|
+
* @returns
|
|
71
69
|
*/
|
|
72
70
|
static isMediaQuery(node) {
|
|
73
71
|
return node.type === 'MediaQuery';
|
|
74
72
|
}
|
|
75
73
|
|
|
76
|
-
/**
|
|
77
|
-
* 判断节点是否为MediaQueryList类型
|
|
78
|
-
* @param node
|
|
79
|
-
* @returns
|
|
74
|
+
/**
|
|
75
|
+
* 判断节点是否为MediaQueryList类型
|
|
76
|
+
* @param node
|
|
77
|
+
* @returns
|
|
80
78
|
*/
|
|
81
79
|
static isMediaQueryList(node) {
|
|
82
80
|
return node.type === 'MediaQueryList';
|
|
83
81
|
}
|
|
84
82
|
|
|
85
|
-
/**
|
|
86
|
-
* 生成节点的name
|
|
87
|
-
* 1. 节点存在name且存在value时,nodeName = generate(node)生成css代码
|
|
88
|
-
* 2. 节点存在name且没有value时,nodeName = node.name
|
|
89
|
-
* 3. 节点存在value且没有name时,nodeName = node.value
|
|
90
|
-
*
|
|
91
|
-
* 例如:#title为存在name且没有value的情况,应返回node.name返回;
|
|
92
|
-
* 例如:50% {}时,节点存在value没有name,应返回node.value
|
|
93
|
-
* @param node
|
|
94
|
-
* @returns
|
|
83
|
+
/**
|
|
84
|
+
* 生成节点的name
|
|
85
|
+
* 1. 节点存在name且存在value时,nodeName = generate(node)生成css代码
|
|
86
|
+
* 2. 节点存在name且没有value时,nodeName = node.name
|
|
87
|
+
* 3. 节点存在value且没有name时,nodeName = node.value
|
|
88
|
+
*
|
|
89
|
+
* 例如:#title为存在name且没有value的情况,应返回node.name返回;
|
|
90
|
+
* 例如:50% {}时,节点存在value没有name,应返回node.value
|
|
91
|
+
* @param node
|
|
92
|
+
* @returns
|
|
95
93
|
*/
|
|
96
94
|
static generateNodename(node) {
|
|
97
95
|
let nodeName = '';
|
|
@@ -108,13 +106,13 @@ class StyleUtil {
|
|
|
108
106
|
}
|
|
109
107
|
return nodeName;
|
|
110
108
|
}
|
|
111
|
-
/**
|
|
112
|
-
* 处理 @media 媒体查询条件
|
|
113
|
-
* 1. 循环MediaQueryList节点的子节点(MediaQuery节点)
|
|
114
|
-
* 2. 检查每个MediaQuery节点的媒体类型
|
|
115
|
-
*
|
|
116
|
-
* @param node
|
|
117
|
-
* @returns
|
|
109
|
+
/**
|
|
110
|
+
* 处理 @media 媒体查询条件
|
|
111
|
+
* 1. 循环MediaQueryList节点的子节点(MediaQuery节点)
|
|
112
|
+
* 2. 检查每个MediaQuery节点的媒体类型
|
|
113
|
+
*
|
|
114
|
+
* @param node
|
|
115
|
+
* @returns
|
|
118
116
|
*/
|
|
119
117
|
static parseMediaQueryList(options, node, styleMapUtil) {
|
|
120
118
|
let resultList = [];
|
|
@@ -165,15 +163,15 @@ class StyleUtil {
|
|
|
165
163
|
return resultList;
|
|
166
164
|
}
|
|
167
165
|
|
|
168
|
-
/**
|
|
169
|
-
* 处理css中资源引入
|
|
170
|
-
* 1. 判断是否为绝对路径
|
|
171
|
-
* 1.1 资源路径为绝对路径时
|
|
172
|
-
* 1.2 资源路径为非绝对路径时,拼接路径为一个绝对路径
|
|
173
|
-
* 2. 判断由第一步生成的绝对路径是否在指定路径外
|
|
174
|
-
* 2.1 资源在指定路径外,复制资源到指定文件夹下,返回修改后的路径
|
|
175
|
-
* 2.2 资源在指定路径内,返回相对路径
|
|
176
|
-
*
|
|
166
|
+
/**
|
|
167
|
+
* 处理css中资源引入
|
|
168
|
+
* 1. 判断是否为绝对路径
|
|
169
|
+
* 1.1 资源路径为绝对路径时
|
|
170
|
+
* 1.2 资源路径为非绝对路径时,拼接路径为一个绝对路径
|
|
171
|
+
* 2. 判断由第一步生成的绝对路径是否在指定路径外
|
|
172
|
+
* 2.1 资源在指定路径外,复制资源到指定文件夹下,返回修改后的路径
|
|
173
|
+
* 2.2 资源在指定路径内,返回相对路径
|
|
174
|
+
*
|
|
177
175
|
*/
|
|
178
176
|
static handleDynamicAssets(options, compilerOption, assetsPath, collectImageResource, position) {
|
|
179
177
|
// 判断url值是否为网址等
|
|
@@ -237,14 +235,14 @@ class StyleUtil {
|
|
|
237
235
|
}
|
|
238
236
|
}
|
|
239
237
|
|
|
240
|
-
/**
|
|
241
|
-
* 转换相对路径为 “相对项目源码目录的绝对路径”
|
|
242
|
-
*
|
|
243
|
-
* 例如:有文件`project/src/page/a.so`,则将 `./a.so` 转换为 `/page/a.so`
|
|
244
|
-
* @param reslovePath 路径值, 例如 `require('./a.so'), 则此值为 `./a.so`
|
|
245
|
-
* @param options
|
|
246
|
-
* @param compilerOption
|
|
247
|
-
* @returns
|
|
238
|
+
/**
|
|
239
|
+
* 转换相对路径为 “相对项目源码目录的绝对路径”
|
|
240
|
+
*
|
|
241
|
+
* 例如:有文件`project/src/page/a.so`,则将 `./a.so` 转换为 `/page/a.so`
|
|
242
|
+
* @param reslovePath 路径值, 例如 `require('./a.so'), 则此值为 `./a.so`
|
|
243
|
+
* @param options
|
|
244
|
+
* @param compilerOption
|
|
245
|
+
* @returns
|
|
248
246
|
*/
|
|
249
247
|
static getRelativePath(reslovePath, options, compilerOption) {
|
|
250
248
|
const {
|
|
@@ -275,11 +273,11 @@ class StyleUtil {
|
|
|
275
273
|
return true;
|
|
276
274
|
}
|
|
277
275
|
|
|
278
|
-
/**
|
|
279
|
-
* 收集解析错误
|
|
280
|
-
* @param error
|
|
281
|
-
* @param fallbackNode
|
|
282
|
-
* @returns
|
|
276
|
+
/**
|
|
277
|
+
* 收集解析错误
|
|
278
|
+
* @param error
|
|
279
|
+
* @param fallbackNode
|
|
280
|
+
* @returns
|
|
283
281
|
*/
|
|
284
282
|
static collectParserError(error, fallbackNode) {
|
|
285
283
|
// 检查错误解析是否为需要输出
|
|
@@ -309,11 +307,11 @@ class StyleUtil {
|
|
|
309
307
|
}
|
|
310
308
|
}
|
|
311
309
|
|
|
312
|
-
/**
|
|
313
|
-
* 收集CSS语法错误
|
|
314
|
-
* @param errors
|
|
315
|
-
* @param trace 是否需要追溯到上一次sourcemap, default: false
|
|
316
|
-
* @returns
|
|
310
|
+
/**
|
|
311
|
+
* 收集CSS语法错误
|
|
312
|
+
* @param errors
|
|
313
|
+
* @param trace 是否需要追溯到上一次sourcemap, default: false
|
|
314
|
+
* @returns
|
|
317
315
|
*/
|
|
318
316
|
static collectSyntaxError(errors, instance) {
|
|
319
317
|
let trace = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
@@ -415,15 +413,15 @@ class StyleUtil {
|
|
|
415
413
|
return syntaxErrors;
|
|
416
414
|
}
|
|
417
415
|
|
|
418
|
-
/**
|
|
419
|
-
* 相同选择器时融合样式
|
|
420
|
-
* 1. 遍历待融合列表,如果元素长度为3,判断选择器列表是否在存储列表中存在
|
|
421
|
-
* 2. 存在相同选择器列表时,再判断condition是否一致,都一致表示为相同选择器
|
|
422
|
-
* 3. 如果元素长度为2,判断选择器列表是否在存储列表中存在,是则表示为相同选择器
|
|
423
|
-
* 4. 如果元素长度为1,则提示样式内容为空,去掉该选择器
|
|
424
|
-
* @param compareList 存储融合结果的样式列表
|
|
425
|
-
* @param candidateList 待融合的样式列表
|
|
426
|
-
* @returns
|
|
416
|
+
/**
|
|
417
|
+
* 相同选择器时融合样式
|
|
418
|
+
* 1. 遍历待融合列表,如果元素长度为3,判断选择器列表是否在存储列表中存在
|
|
419
|
+
* 2. 存在相同选择器列表时,再判断condition是否一致,都一致表示为相同选择器
|
|
420
|
+
* 3. 如果元素长度为2,判断选择器列表是否在存储列表中存在,是则表示为相同选择器
|
|
421
|
+
* 4. 如果元素长度为1,则提示样式内容为空,去掉该选择器
|
|
422
|
+
* @param compareList 存储融合结果的样式列表
|
|
423
|
+
* @param candidateList 待融合的样式列表
|
|
424
|
+
* @returns
|
|
427
425
|
*/
|
|
428
426
|
static mergeSelectorList(compareList, candidateList) {
|
|
429
427
|
let resultList = [...compareList];
|
|
@@ -483,19 +481,19 @@ class StyleUtil {
|
|
|
483
481
|
return resultList;
|
|
484
482
|
}
|
|
485
483
|
|
|
486
|
-
/**
|
|
487
|
-
* 判断StyleItem类型的节点是否有"condition"属性
|
|
488
|
-
* @param conditionNode
|
|
489
|
-
* @returns
|
|
484
|
+
/**
|
|
485
|
+
* 判断StyleItem类型的节点是否有"condition"属性
|
|
486
|
+
* @param conditionNode
|
|
487
|
+
* @returns
|
|
490
488
|
*/
|
|
491
489
|
static isConditionStyleItem(conditionNode) {
|
|
492
490
|
return 'condition' in conditionNode && typeof conditionNode['condition'] === 'string';
|
|
493
491
|
}
|
|
494
492
|
|
|
495
|
-
/**
|
|
496
|
-
* 转换百分号
|
|
497
|
-
* @param unit
|
|
498
|
-
* @returns
|
|
493
|
+
/**
|
|
494
|
+
* 转换百分号
|
|
495
|
+
* @param unit
|
|
496
|
+
* @returns
|
|
499
497
|
*/
|
|
500
498
|
static translatePercentage(unit) {
|
|
501
499
|
return unit === 'Percentage' ? '%' : unit;
|
|
@@ -504,25 +502,25 @@ class StyleUtil {
|
|
|
504
502
|
return obj && 'name' in obj && 'param' in obj;
|
|
505
503
|
}
|
|
506
504
|
|
|
507
|
-
/**
|
|
508
|
-
* 压缩css属性名
|
|
509
|
-
* 1. 取出转换结果中的每一组样式( 选择器 + 样式对象)styleNode
|
|
510
|
-
* 一般样式的格式为:
|
|
511
|
-
* [
|
|
512
|
-
* [[]],
|
|
513
|
-
* {}
|
|
514
|
-
* ]
|
|
515
|
-
* 1.1 @meida的样式不需要压缩 (condition + 选择器 + 样式对象)
|
|
516
|
-
* [
|
|
517
|
-
* {},
|
|
518
|
-
* [[]],
|
|
519
|
-
* {}
|
|
520
|
-
* ]
|
|
521
|
-
* 2. 从styleNode中取出样式对象 AttrObj
|
|
522
|
-
* 3. 遍历样式对象,找到属性对应的压缩值
|
|
523
|
-
* 4. 替换属性名和属性值
|
|
524
|
-
* @param sourceNodes
|
|
525
|
-
* @returns
|
|
505
|
+
/**
|
|
506
|
+
* 压缩css属性名
|
|
507
|
+
* 1. 取出转换结果中的每一组样式( 选择器 + 样式对象)styleNode
|
|
508
|
+
* 一般样式的格式为:
|
|
509
|
+
* [
|
|
510
|
+
* [[]],
|
|
511
|
+
* {}
|
|
512
|
+
* ]
|
|
513
|
+
* 1.1 @meida的样式不需要压缩 (condition + 选择器 + 样式对象)
|
|
514
|
+
* [
|
|
515
|
+
* {},
|
|
516
|
+
* [[]],
|
|
517
|
+
* {}
|
|
518
|
+
* ]
|
|
519
|
+
* 2. 从styleNode中取出样式对象 AttrObj
|
|
520
|
+
* 3. 遍历样式对象,找到属性对应的压缩值
|
|
521
|
+
* 4. 替换属性名和属性值
|
|
522
|
+
* @param sourceNodes
|
|
523
|
+
* @returns
|
|
526
524
|
*/
|
|
527
525
|
static compressStyleAttributeName(sourceNodes) {
|
|
528
526
|
const cloneNodes = _lodash.default.cloneDeep(sourceNodes);
|
|
@@ -547,16 +545,16 @@ class StyleUtil {
|
|
|
547
545
|
return cloneNodes;
|
|
548
546
|
}
|
|
549
547
|
|
|
550
|
-
/**
|
|
551
|
-
* 检查每一个MediaQuery的MediaType
|
|
552
|
-
* 1. 判断节点是否为MediaQuery类型,非MediaQuery暂不处理
|
|
553
|
-
* 2. 取出节点的所有子节点
|
|
554
|
-
* 3. MediaType应该只出现在前两个Identifier节点中
|
|
555
|
-
* 3.1 @media screen and...时,screen在第一个Identifier节点上
|
|
556
|
-
* 3.2 @media not|only screen and...时,screen在第二个Identifier节点上
|
|
557
|
-
* 3.3 @media not {}
|
|
558
|
-
* 4. 校验MediaType是否合法
|
|
559
|
-
*
|
|
548
|
+
/**
|
|
549
|
+
* 检查每一个MediaQuery的MediaType
|
|
550
|
+
* 1. 判断节点是否为MediaQuery类型,非MediaQuery暂不处理
|
|
551
|
+
* 2. 取出节点的所有子节点
|
|
552
|
+
* 3. MediaType应该只出现在前两个Identifier节点中
|
|
553
|
+
* 3.1 @media screen and...时,screen在第一个Identifier节点上
|
|
554
|
+
* 3.2 @media not|only screen and...时,screen在第二个Identifier节点上
|
|
555
|
+
* 3.3 @media not {}
|
|
556
|
+
* 4. 校验MediaType是否合法
|
|
557
|
+
*
|
|
560
558
|
*/
|
|
561
559
|
static checkMediaType(options, node, styleMapUil) {
|
|
562
560
|
const {
|
|
@@ -612,18 +610,18 @@ class StyleUtil {
|
|
|
612
610
|
}
|
|
613
611
|
}
|
|
614
612
|
|
|
615
|
-
/**
|
|
616
|
-
* 转换 keyframe 的规则项
|
|
617
|
-
*
|
|
618
|
-
* @param rule 规则项。 示例
|
|
619
|
-
* ```css
|
|
620
|
-
* from {
|
|
621
|
-
* width: 100px;
|
|
622
|
-
* color: red;
|
|
623
|
-
* }
|
|
624
|
-
* ```
|
|
625
|
-
* @param options
|
|
626
|
-
* @returns
|
|
613
|
+
/**
|
|
614
|
+
* 转换 keyframe 的规则项
|
|
615
|
+
*
|
|
616
|
+
* @param rule 规则项。 示例
|
|
617
|
+
* ```css
|
|
618
|
+
* from {
|
|
619
|
+
* width: 100px;
|
|
620
|
+
* color: red;
|
|
621
|
+
* }
|
|
622
|
+
* ```
|
|
623
|
+
* @param options
|
|
624
|
+
* @returns
|
|
627
625
|
*/
|
|
628
626
|
static translateKeyFramesRule(rule, options) {
|
|
629
627
|
const {
|
|
@@ -671,17 +669,17 @@ class StyleUtil {
|
|
|
671
669
|
return result;
|
|
672
670
|
}
|
|
673
671
|
|
|
674
|
-
/**
|
|
675
|
-
* 转换样式块
|
|
676
|
-
* @param sourceNodes 样式块. 示例
|
|
677
|
-
* ```css
|
|
678
|
-
* {
|
|
679
|
-
* color: red;
|
|
680
|
-
* font-size: 12px
|
|
681
|
-
* }
|
|
682
|
-
* ```
|
|
683
|
-
* @param options
|
|
684
|
-
* @returns
|
|
672
|
+
/**
|
|
673
|
+
* 转换样式块
|
|
674
|
+
* @param sourceNodes 样式块. 示例
|
|
675
|
+
* ```css
|
|
676
|
+
* {
|
|
677
|
+
* color: red;
|
|
678
|
+
* font-size: 12px
|
|
679
|
+
* }
|
|
680
|
+
* ```
|
|
681
|
+
* @param options
|
|
682
|
+
* @returns
|
|
685
683
|
*/
|
|
686
684
|
static translateBlock(sourceNodes, options) {
|
|
687
685
|
let targetList = {};
|
|
@@ -719,15 +717,15 @@ class StyleUtil {
|
|
|
719
717
|
return targetList;
|
|
720
718
|
}
|
|
721
719
|
|
|
722
|
-
/**
|
|
723
|
-
* 转换值节点
|
|
724
|
-
*
|
|
725
|
-
* 1. ComplexValueType类型
|
|
726
|
-
* 2. SimpleValueType类型
|
|
727
|
-
* 无论哪种类型,转换后还是数组
|
|
728
|
-
*
|
|
729
|
-
* @param sourceNode sourceNode为数组,且数组元素只会是一种类型
|
|
730
|
-
* @returns
|
|
720
|
+
/**
|
|
721
|
+
* 转换值节点
|
|
722
|
+
*
|
|
723
|
+
* 1. ComplexValueType类型
|
|
724
|
+
* 2. SimpleValueType类型
|
|
725
|
+
* 无论哪种类型,转换后还是数组
|
|
726
|
+
*
|
|
727
|
+
* @param sourceNode sourceNode为数组,且数组元素只会是一种类型
|
|
728
|
+
* @returns
|
|
731
729
|
*/
|
|
732
730
|
static translateValueNode(sourceNode) {
|
|
733
731
|
// 1.
|
|
@@ -750,12 +748,12 @@ class StyleUtil {
|
|
|
750
748
|
}
|
|
751
749
|
}
|
|
752
750
|
|
|
753
|
-
/**
|
|
754
|
-
* 1. 数字值且无单位,则转换为数字, 示例: opaticy: 1 的"1" -->1
|
|
755
|
-
* 2. 颜色值,进行格式化,示例: rgba(1,1,1,.88) --> rgba(1,1,1.0.88)
|
|
756
|
-
* 3. 其它,保持原值,但百分比单位转换为%
|
|
757
|
-
* @param node
|
|
758
|
-
* @returns
|
|
751
|
+
/**
|
|
752
|
+
* 1. 数字值且无单位,则转换为数字, 示例: opaticy: 1 的"1" -->1
|
|
753
|
+
* 2. 颜色值,进行格式化,示例: rgba(1,1,1,.88) --> rgba(1,1,1.0.88)
|
|
754
|
+
* 3. 其它,保持原值,但百分比单位转换为%
|
|
755
|
+
* @param node
|
|
756
|
+
* @returns
|
|
759
757
|
*/
|
|
760
758
|
static translateNodeValue(node) {
|
|
761
759
|
const {
|
|
@@ -769,41 +767,45 @@ class StyleUtil {
|
|
|
769
767
|
return numberValue;
|
|
770
768
|
}
|
|
771
769
|
// 2
|
|
772
|
-
else if (StyleUtil.isColor(value)) {
|
|
773
|
-
return StyleUtil.formatColor(value);
|
|
770
|
+
else if (StyleUtil.isColor(`${value}${unit}`)) {
|
|
771
|
+
return StyleUtil.formatColor(`${value}${unit}`);
|
|
774
772
|
}
|
|
775
773
|
// 3
|
|
776
774
|
return node.value + this.translatePercentage(unit);
|
|
777
775
|
}
|
|
778
776
|
static isColor(color) {
|
|
779
|
-
const colorItem =
|
|
777
|
+
const colorItem = (0, _tinycolor.default)(color);
|
|
780
778
|
return colorItem.isValid();
|
|
781
779
|
}
|
|
782
780
|
static formatColor(color) {
|
|
783
|
-
const colorItem =
|
|
781
|
+
const colorItem = (0, _tinycolor.default)(color);
|
|
784
782
|
if (!colorItem.isValid()) {
|
|
785
783
|
return color;
|
|
786
784
|
}
|
|
787
|
-
const format =
|
|
785
|
+
const format = colorItem.getFormat();
|
|
788
786
|
switch (format) {
|
|
789
787
|
case 'hex':
|
|
790
|
-
return colorItem.
|
|
788
|
+
return colorItem.toHexString();
|
|
789
|
+
case 'hex8':
|
|
790
|
+
return colorItem.toHex8String();
|
|
791
791
|
case 'rgb':
|
|
792
792
|
return colorItem.toRgbString();
|
|
793
793
|
case 'hsl':
|
|
794
794
|
return colorItem.toHslString();
|
|
795
|
+
case 'name':
|
|
796
|
+
return color;
|
|
795
797
|
default:
|
|
796
798
|
return colorItem.toRgbString();
|
|
797
799
|
}
|
|
798
800
|
}
|
|
799
801
|
|
|
800
|
-
/**
|
|
801
|
-
* 属性值目前存储在数组中,该函数将数组中的值转换为字符串、数字
|
|
802
|
-
* animation-name属性值为 ['GO','Color','scaleX'] --> "GO, Color, scaleX"
|
|
803
|
-
* opacity属性值为 [1] --> 数字1
|
|
804
|
-
* transform属性值为对象`transform: scale(1) rotate(180deg)` --> `transform: '{"scaleX":1,"scaleY":1,"rotate":"180deg"}'`
|
|
805
|
-
* @param value
|
|
806
|
-
* @returns
|
|
802
|
+
/**
|
|
803
|
+
* 属性值目前存储在数组中,该函数将数组中的值转换为字符串、数字
|
|
804
|
+
* animation-name属性值为 ['GO','Color','scaleX'] --> "GO, Color, scaleX"
|
|
805
|
+
* opacity属性值为 [1] --> 数字1
|
|
806
|
+
* transform属性值为对象`transform: scale(1) rotate(180deg)` --> `transform: '{"scaleX":1,"scaleY":1,"rotate":"180deg"}'`
|
|
807
|
+
* @param value
|
|
808
|
+
* @returns
|
|
807
809
|
*/
|
|
808
810
|
static translateToNormalValue(value) {
|
|
809
811
|
if (typeof value === 'object') {
|
package/lib/ux/utils/UxUtil.js
CHANGED
|
@@ -6,15 +6,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _path = _interopRequireDefault(require("path"));
|
|
8
8
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
-
/**
|
|
10
|
-
* UxParserUtil
|
|
9
|
+
/**
|
|
10
|
+
* UxParserUtil
|
|
11
11
|
*/
|
|
12
12
|
class UxUtil {
|
|
13
|
-
/**
|
|
14
|
-
* 重组文件名
|
|
15
|
-
* @param fileName
|
|
16
|
-
* @param extValue
|
|
17
|
-
* @returns
|
|
13
|
+
/**
|
|
14
|
+
* 重组文件名
|
|
15
|
+
* @param fileName
|
|
16
|
+
* @param extValue
|
|
17
|
+
* @returns
|
|
18
18
|
*/
|
|
19
19
|
static spliceFileName(fileName, extValue) {
|
|
20
20
|
const {
|
|
@@ -22,10 +22,10 @@ class UxUtil {
|
|
|
22
22
|
} = _path.default.parse(fileName);
|
|
23
23
|
return name && extValue ? `${name}.${extValue}` : '';
|
|
24
24
|
}
|
|
25
|
-
/**
|
|
26
|
-
* 获取css的lang类型
|
|
27
|
-
* @param node
|
|
28
|
-
* @returns
|
|
25
|
+
/**
|
|
26
|
+
* 获取css的lang类型
|
|
27
|
+
* @param node
|
|
28
|
+
* @returns
|
|
29
29
|
*/
|
|
30
30
|
static getLangType(node) {
|
|
31
31
|
let langType = 'css';
|
|
@@ -37,27 +37,27 @@ class UxUtil {
|
|
|
37
37
|
}
|
|
38
38
|
return langType;
|
|
39
39
|
}
|
|
40
|
-
/**
|
|
41
|
-
* 更新文件路径中的后缀
|
|
42
|
-
* @param path
|
|
43
|
-
* @param extValue
|
|
44
|
-
* @returns
|
|
40
|
+
/**
|
|
41
|
+
* 更新文件路径中的后缀
|
|
42
|
+
* @param path
|
|
43
|
+
* @param extValue
|
|
44
|
+
* @returns
|
|
45
45
|
*/
|
|
46
46
|
static updateFileName(path, extValue) {
|
|
47
47
|
const dirName = _path.default.dirname(path);
|
|
48
48
|
let newFileName = UxUtil.spliceFileName(path, extValue);
|
|
49
49
|
return newFileName ? _path.default.posix.join(dirName, newFileName) : path;
|
|
50
50
|
}
|
|
51
|
-
/**
|
|
52
|
-
* 将全局变量根据样式语言类型转为对应的变量声明
|
|
53
|
-
* {
|
|
54
|
-
* "a": "#fff"
|
|
55
|
-
* }
|
|
56
|
-
* 转为
|
|
57
|
-
* $a: #fff 或者 @a: #fff
|
|
58
|
-
* @param globalVar
|
|
59
|
-
* @param langType
|
|
60
|
-
* @returns
|
|
51
|
+
/**
|
|
52
|
+
* 将全局变量根据样式语言类型转为对应的变量声明
|
|
53
|
+
* {
|
|
54
|
+
* "a": "#fff"
|
|
55
|
+
* }
|
|
56
|
+
* 转为
|
|
57
|
+
* $a: #fff 或者 @a: #fff
|
|
58
|
+
* @param globalVar
|
|
59
|
+
* @param langType
|
|
60
|
+
* @returns
|
|
61
61
|
*/
|
|
62
62
|
static convertGlobalJson(globalVar) {
|
|
63
63
|
let langType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'css';
|
|
@@ -73,12 +73,12 @@ class UxUtil {
|
|
|
73
73
|
return varArray.join('\n');
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
/**
|
|
77
|
-
* 是否是绝对资源路径
|
|
78
|
-
*
|
|
79
|
-
* 1. 以/开头:/a/b/c.png
|
|
80
|
-
* 2. 以 ***://开头的视为绝对路径: package://a.png
|
|
81
|
-
* @param path
|
|
76
|
+
/**
|
|
77
|
+
* 是否是绝对资源路径
|
|
78
|
+
*
|
|
79
|
+
* 1. 以/开头:/a/b/c.png
|
|
80
|
+
* 2. 以 ***://开头的视为绝对路径: package://a.png
|
|
81
|
+
* @param path
|
|
82
82
|
*/
|
|
83
83
|
static isAbsoluteResource(path) {
|
|
84
84
|
if (!path) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiot-toolkit/parser",
|
|
3
|
-
"version": "2.0.5-beta.
|
|
3
|
+
"version": "2.0.5-widget-provider-beta.1",
|
|
4
4
|
"description": "Parse the source code of aiot and convert it to the AST (Abstract Syntax Tree) of the target code.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"aiot",
|
|
@@ -20,8 +20,7 @@
|
|
|
20
20
|
"test": "node ./__tests__/parser.test.js"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@aiot-toolkit/
|
|
24
|
-
"@aiot-toolkit/shared-utils": "2.0.5-beta.8",
|
|
23
|
+
"@aiot-toolkit/shared-utils": "2.0.5-widget-provider-beta.1",
|
|
25
24
|
"@babel/core": "^7.23.6",
|
|
26
25
|
"@babel/generator": "^7.24.10",
|
|
27
26
|
"@babel/parser": "^7.24.8",
|
|
@@ -29,11 +28,10 @@
|
|
|
29
28
|
"@babel/traverse": "^7.23.7",
|
|
30
29
|
"@babel/types": "^7.23.6",
|
|
31
30
|
"aiot-parse5": "^1.0.2",
|
|
32
|
-
"colord": "^2.9.3",
|
|
33
31
|
"css-tree": "npm:aiot-css-tree@^2.3.1",
|
|
34
32
|
"csstree-validator": "^3.0.0",
|
|
35
33
|
"eslint": "^8.46.0",
|
|
36
|
-
"file-lane": "2.0.5-beta.
|
|
34
|
+
"file-lane": "2.0.5-widget-provider-beta.1",
|
|
37
35
|
"fs-extra": "^11.2.0",
|
|
38
36
|
"google-protobuf": "^3.21.2",
|
|
39
37
|
"less": "^4.2.0",
|
|
@@ -46,6 +44,7 @@
|
|
|
46
44
|
"sass": "^1.69.5",
|
|
47
45
|
"sass-alias": "^2.0.1",
|
|
48
46
|
"source-map": "^0.7.4",
|
|
47
|
+
"tinycolor2": "^1.6.0",
|
|
49
48
|
"ts-morph": "^19.0.0",
|
|
50
49
|
"vela-chai": "^1.0.2",
|
|
51
50
|
"vela-quickapp-test": "^1.0.13"
|
|
@@ -58,7 +57,8 @@
|
|
|
58
57
|
"@types/postcss-import": "^14.0.3",
|
|
59
58
|
"@types/postcss-url": "^10.0.4",
|
|
60
59
|
"@types/reserved-words": "^0.1.4",
|
|
60
|
+
"@types/tinycolor2": "^1.4.6",
|
|
61
61
|
"babel-plugin-tester": "^11.0.4"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "64842a2c374b8b3b344cef377d9c032eaf1a99a7"
|
|
64
64
|
}
|