@aiot-toolkit/parser 2.0.5-beta.9 → 2.0.5-widget-provider-beta.2
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/ElementConfig.js +8 -0
- 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.d.ts +4 -0
- package/lib/ux/translate/vela/utils/SourceMapUtil.js +36 -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 +165 -165
- 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 +4 -5
- 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
|
@@ -14,82 +14,82 @@ var _StyleSelectorType = require("../enum/StyleSelectorType");
|
|
|
14
14
|
var _StyleAttributeConfig = require("../config/vela/StyleAttributeConfig");
|
|
15
15
|
var _tinycolor = _interopRequireDefault(require("tinycolor2"));
|
|
16
16
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
17
|
-
/**
|
|
18
|
-
* StyleUtil
|
|
17
|
+
/**
|
|
18
|
+
* StyleUtil
|
|
19
19
|
*/
|
|
20
20
|
class StyleUtil {
|
|
21
|
-
/**
|
|
22
|
-
* 判断节点是否为declaration节点
|
|
23
|
-
* @param node
|
|
24
|
-
* @returns
|
|
21
|
+
/**
|
|
22
|
+
* 判断节点是否为declaration节点
|
|
23
|
+
* @param node
|
|
24
|
+
* @returns
|
|
25
25
|
*/
|
|
26
26
|
static isDeclaration(node) {
|
|
27
27
|
return node.type === 'Declaration';
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
/**
|
|
31
|
-
* 判断节点是否为Identifier类型
|
|
32
|
-
* @param node
|
|
33
|
-
* @returns
|
|
30
|
+
/**
|
|
31
|
+
* 判断节点是否为Identifier类型
|
|
32
|
+
* @param node
|
|
33
|
+
* @returns
|
|
34
34
|
*/
|
|
35
35
|
static isIdentifier(node) {
|
|
36
36
|
return node.type === 'Identifier';
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
/**
|
|
40
|
-
* 判断节点是否为SelectorList类型
|
|
41
|
-
* @param node
|
|
42
|
-
* @returns
|
|
39
|
+
/**
|
|
40
|
+
* 判断节点是否为SelectorList类型
|
|
41
|
+
* @param node
|
|
42
|
+
* @returns
|
|
43
43
|
*/
|
|
44
44
|
static isSelectorList(node) {
|
|
45
45
|
return node.type === 'SelectorList';
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
/**
|
|
49
|
-
* 判断节点是否为AtrulePrelude类型
|
|
50
|
-
* @param node
|
|
51
|
-
* @returns
|
|
48
|
+
/**
|
|
49
|
+
* 判断节点是否为AtrulePrelude类型
|
|
50
|
+
* @param node
|
|
51
|
+
* @returns
|
|
52
52
|
*/
|
|
53
53
|
static isAtrulePrelude(node) {
|
|
54
54
|
return node.type === 'AtrulePrelude';
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
/**
|
|
58
|
-
* 判断节点是否为MediaFeature类型
|
|
59
|
-
* @param node
|
|
60
|
-
* @returns
|
|
57
|
+
/**
|
|
58
|
+
* 判断节点是否为MediaFeature类型
|
|
59
|
+
* @param node
|
|
60
|
+
* @returns
|
|
61
61
|
*/
|
|
62
62
|
static isMediaFeature(node) {
|
|
63
63
|
return node.type === 'MediaFeature';
|
|
64
64
|
}
|
|
65
|
-
/**
|
|
66
|
-
* 判断节点是否为MediaQuery类型
|
|
67
|
-
* @param node
|
|
68
|
-
* @returns
|
|
65
|
+
/**
|
|
66
|
+
* 判断节点是否为MediaQuery类型
|
|
67
|
+
* @param node
|
|
68
|
+
* @returns
|
|
69
69
|
*/
|
|
70
70
|
static isMediaQuery(node) {
|
|
71
71
|
return node.type === 'MediaQuery';
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
/**
|
|
75
|
-
* 判断节点是否为MediaQueryList类型
|
|
76
|
-
* @param node
|
|
77
|
-
* @returns
|
|
74
|
+
/**
|
|
75
|
+
* 判断节点是否为MediaQueryList类型
|
|
76
|
+
* @param node
|
|
77
|
+
* @returns
|
|
78
78
|
*/
|
|
79
79
|
static isMediaQueryList(node) {
|
|
80
80
|
return node.type === 'MediaQueryList';
|
|
81
81
|
}
|
|
82
82
|
|
|
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
|
|
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
|
|
93
93
|
*/
|
|
94
94
|
static generateNodename(node) {
|
|
95
95
|
let nodeName = '';
|
|
@@ -106,13 +106,13 @@ class StyleUtil {
|
|
|
106
106
|
}
|
|
107
107
|
return nodeName;
|
|
108
108
|
}
|
|
109
|
-
/**
|
|
110
|
-
* 处理 @media 媒体查询条件
|
|
111
|
-
* 1. 循环MediaQueryList节点的子节点(MediaQuery节点)
|
|
112
|
-
* 2. 检查每个MediaQuery节点的媒体类型
|
|
113
|
-
*
|
|
114
|
-
* @param node
|
|
115
|
-
* @returns
|
|
109
|
+
/**
|
|
110
|
+
* 处理 @media 媒体查询条件
|
|
111
|
+
* 1. 循环MediaQueryList节点的子节点(MediaQuery节点)
|
|
112
|
+
* 2. 检查每个MediaQuery节点的媒体类型
|
|
113
|
+
*
|
|
114
|
+
* @param node
|
|
115
|
+
* @returns
|
|
116
116
|
*/
|
|
117
117
|
static parseMediaQueryList(options, node, styleMapUtil) {
|
|
118
118
|
let resultList = [];
|
|
@@ -163,15 +163,15 @@ class StyleUtil {
|
|
|
163
163
|
return resultList;
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
-
/**
|
|
167
|
-
* 处理css中资源引入
|
|
168
|
-
* 1. 判断是否为绝对路径
|
|
169
|
-
* 1.1 资源路径为绝对路径时
|
|
170
|
-
* 1.2 资源路径为非绝对路径时,拼接路径为一个绝对路径
|
|
171
|
-
* 2. 判断由第一步生成的绝对路径是否在指定路径外
|
|
172
|
-
* 2.1 资源在指定路径外,复制资源到指定文件夹下,返回修改后的路径
|
|
173
|
-
* 2.2 资源在指定路径内,返回相对路径
|
|
174
|
-
*
|
|
166
|
+
/**
|
|
167
|
+
* 处理css中资源引入
|
|
168
|
+
* 1. 判断是否为绝对路径
|
|
169
|
+
* 1.1 资源路径为绝对路径时
|
|
170
|
+
* 1.2 资源路径为非绝对路径时,拼接路径为一个绝对路径
|
|
171
|
+
* 2. 判断由第一步生成的绝对路径是否在指定路径外
|
|
172
|
+
* 2.1 资源在指定路径外,复制资源到指定文件夹下,返回修改后的路径
|
|
173
|
+
* 2.2 资源在指定路径内,返回相对路径
|
|
174
|
+
*
|
|
175
175
|
*/
|
|
176
176
|
static handleDynamicAssets(options, compilerOption, assetsPath, collectImageResource, position) {
|
|
177
177
|
// 判断url值是否为网址等
|
|
@@ -235,14 +235,14 @@ class StyleUtil {
|
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
237
|
|
|
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
|
|
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
|
|
246
246
|
*/
|
|
247
247
|
static getRelativePath(reslovePath, options, compilerOption) {
|
|
248
248
|
const {
|
|
@@ -273,11 +273,11 @@ class StyleUtil {
|
|
|
273
273
|
return true;
|
|
274
274
|
}
|
|
275
275
|
|
|
276
|
-
/**
|
|
277
|
-
* 收集解析错误
|
|
278
|
-
* @param error
|
|
279
|
-
* @param fallbackNode
|
|
280
|
-
* @returns
|
|
276
|
+
/**
|
|
277
|
+
* 收集解析错误
|
|
278
|
+
* @param error
|
|
279
|
+
* @param fallbackNode
|
|
280
|
+
* @returns
|
|
281
281
|
*/
|
|
282
282
|
static collectParserError(error, fallbackNode) {
|
|
283
283
|
// 检查错误解析是否为需要输出
|
|
@@ -307,11 +307,11 @@ class StyleUtil {
|
|
|
307
307
|
}
|
|
308
308
|
}
|
|
309
309
|
|
|
310
|
-
/**
|
|
311
|
-
* 收集CSS语法错误
|
|
312
|
-
* @param errors
|
|
313
|
-
* @param trace 是否需要追溯到上一次sourcemap, default: false
|
|
314
|
-
* @returns
|
|
310
|
+
/**
|
|
311
|
+
* 收集CSS语法错误
|
|
312
|
+
* @param errors
|
|
313
|
+
* @param trace 是否需要追溯到上一次sourcemap, default: false
|
|
314
|
+
* @returns
|
|
315
315
|
*/
|
|
316
316
|
static collectSyntaxError(errors, instance) {
|
|
317
317
|
let trace = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
@@ -413,15 +413,15 @@ class StyleUtil {
|
|
|
413
413
|
return syntaxErrors;
|
|
414
414
|
}
|
|
415
415
|
|
|
416
|
-
/**
|
|
417
|
-
* 相同选择器时融合样式
|
|
418
|
-
* 1. 遍历待融合列表,如果元素长度为3,判断选择器列表是否在存储列表中存在
|
|
419
|
-
* 2. 存在相同选择器列表时,再判断condition是否一致,都一致表示为相同选择器
|
|
420
|
-
* 3. 如果元素长度为2,判断选择器列表是否在存储列表中存在,是则表示为相同选择器
|
|
421
|
-
* 4. 如果元素长度为1,则提示样式内容为空,去掉该选择器
|
|
422
|
-
* @param compareList 存储融合结果的样式列表
|
|
423
|
-
* @param candidateList 待融合的样式列表
|
|
424
|
-
* @returns
|
|
416
|
+
/**
|
|
417
|
+
* 相同选择器时融合样式
|
|
418
|
+
* 1. 遍历待融合列表,如果元素长度为3,判断选择器列表是否在存储列表中存在
|
|
419
|
+
* 2. 存在相同选择器列表时,再判断condition是否一致,都一致表示为相同选择器
|
|
420
|
+
* 3. 如果元素长度为2,判断选择器列表是否在存储列表中存在,是则表示为相同选择器
|
|
421
|
+
* 4. 如果元素长度为1,则提示样式内容为空,去掉该选择器
|
|
422
|
+
* @param compareList 存储融合结果的样式列表
|
|
423
|
+
* @param candidateList 待融合的样式列表
|
|
424
|
+
* @returns
|
|
425
425
|
*/
|
|
426
426
|
static mergeSelectorList(compareList, candidateList) {
|
|
427
427
|
let resultList = [...compareList];
|
|
@@ -481,19 +481,19 @@ class StyleUtil {
|
|
|
481
481
|
return resultList;
|
|
482
482
|
}
|
|
483
483
|
|
|
484
|
-
/**
|
|
485
|
-
* 判断StyleItem类型的节点是否有"condition"属性
|
|
486
|
-
* @param conditionNode
|
|
487
|
-
* @returns
|
|
484
|
+
/**
|
|
485
|
+
* 判断StyleItem类型的节点是否有"condition"属性
|
|
486
|
+
* @param conditionNode
|
|
487
|
+
* @returns
|
|
488
488
|
*/
|
|
489
489
|
static isConditionStyleItem(conditionNode) {
|
|
490
490
|
return 'condition' in conditionNode && typeof conditionNode['condition'] === 'string';
|
|
491
491
|
}
|
|
492
492
|
|
|
493
|
-
/**
|
|
494
|
-
* 转换百分号
|
|
495
|
-
* @param unit
|
|
496
|
-
* @returns
|
|
493
|
+
/**
|
|
494
|
+
* 转换百分号
|
|
495
|
+
* @param unit
|
|
496
|
+
* @returns
|
|
497
497
|
*/
|
|
498
498
|
static translatePercentage(unit) {
|
|
499
499
|
return unit === 'Percentage' ? '%' : unit;
|
|
@@ -502,25 +502,25 @@ class StyleUtil {
|
|
|
502
502
|
return obj && 'name' in obj && 'param' in obj;
|
|
503
503
|
}
|
|
504
504
|
|
|
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
|
|
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
|
|
524
524
|
*/
|
|
525
525
|
static compressStyleAttributeName(sourceNodes) {
|
|
526
526
|
const cloneNodes = _lodash.default.cloneDeep(sourceNodes);
|
|
@@ -545,16 +545,16 @@ class StyleUtil {
|
|
|
545
545
|
return cloneNodes;
|
|
546
546
|
}
|
|
547
547
|
|
|
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
|
-
*
|
|
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
|
+
*
|
|
558
558
|
*/
|
|
559
559
|
static checkMediaType(options, node, styleMapUil) {
|
|
560
560
|
const {
|
|
@@ -610,18 +610,18 @@ class StyleUtil {
|
|
|
610
610
|
}
|
|
611
611
|
}
|
|
612
612
|
|
|
613
|
-
/**
|
|
614
|
-
* 转换 keyframe 的规则项
|
|
615
|
-
*
|
|
616
|
-
* @param rule 规则项。 示例
|
|
617
|
-
* ```css
|
|
618
|
-
* from {
|
|
619
|
-
* width: 100px;
|
|
620
|
-
* color: red;
|
|
621
|
-
* }
|
|
622
|
-
* ```
|
|
623
|
-
* @param options
|
|
624
|
-
* @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
|
|
625
625
|
*/
|
|
626
626
|
static translateKeyFramesRule(rule, options) {
|
|
627
627
|
const {
|
|
@@ -669,17 +669,17 @@ class StyleUtil {
|
|
|
669
669
|
return result;
|
|
670
670
|
}
|
|
671
671
|
|
|
672
|
-
/**
|
|
673
|
-
* 转换样式块
|
|
674
|
-
* @param sourceNodes 样式块. 示例
|
|
675
|
-
* ```css
|
|
676
|
-
* {
|
|
677
|
-
* color: red;
|
|
678
|
-
* font-size: 12px
|
|
679
|
-
* }
|
|
680
|
-
* ```
|
|
681
|
-
* @param options
|
|
682
|
-
* @returns
|
|
672
|
+
/**
|
|
673
|
+
* 转换样式块
|
|
674
|
+
* @param sourceNodes 样式块. 示例
|
|
675
|
+
* ```css
|
|
676
|
+
* {
|
|
677
|
+
* color: red;
|
|
678
|
+
* font-size: 12px
|
|
679
|
+
* }
|
|
680
|
+
* ```
|
|
681
|
+
* @param options
|
|
682
|
+
* @returns
|
|
683
683
|
*/
|
|
684
684
|
static translateBlock(sourceNodes, options) {
|
|
685
685
|
let targetList = {};
|
|
@@ -717,15 +717,15 @@ class StyleUtil {
|
|
|
717
717
|
return targetList;
|
|
718
718
|
}
|
|
719
719
|
|
|
720
|
-
/**
|
|
721
|
-
* 转换值节点
|
|
722
|
-
*
|
|
723
|
-
* 1. ComplexValueType类型
|
|
724
|
-
* 2. SimpleValueType类型
|
|
725
|
-
* 无论哪种类型,转换后还是数组
|
|
726
|
-
*
|
|
727
|
-
* @param sourceNode sourceNode为数组,且数组元素只会是一种类型
|
|
728
|
-
* @returns
|
|
720
|
+
/**
|
|
721
|
+
* 转换值节点
|
|
722
|
+
*
|
|
723
|
+
* 1. ComplexValueType类型
|
|
724
|
+
* 2. SimpleValueType类型
|
|
725
|
+
* 无论哪种类型,转换后还是数组
|
|
726
|
+
*
|
|
727
|
+
* @param sourceNode sourceNode为数组,且数组元素只会是一种类型
|
|
728
|
+
* @returns
|
|
729
729
|
*/
|
|
730
730
|
static translateValueNode(sourceNode) {
|
|
731
731
|
// 1.
|
|
@@ -748,12 +748,12 @@ class StyleUtil {
|
|
|
748
748
|
}
|
|
749
749
|
}
|
|
750
750
|
|
|
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
|
|
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
|
|
757
757
|
*/
|
|
758
758
|
static translateNodeValue(node) {
|
|
759
759
|
const {
|
|
@@ -799,13 +799,13 @@ class StyleUtil {
|
|
|
799
799
|
}
|
|
800
800
|
}
|
|
801
801
|
|
|
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
|
|
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
|
|
809
809
|
*/
|
|
810
810
|
static translateToNormalValue(value) {
|
|
811
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.2",
|
|
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.9",
|
|
23
|
+
"@aiot-toolkit/shared-utils": "2.0.5-widget-provider-beta.2",
|
|
25
24
|
"@babel/core": "^7.23.6",
|
|
26
25
|
"@babel/generator": "^7.24.10",
|
|
27
26
|
"@babel/parser": "^7.24.8",
|
|
@@ -32,7 +31,7 @@
|
|
|
32
31
|
"css-tree": "npm:aiot-css-tree@^2.3.1",
|
|
33
32
|
"csstree-validator": "^3.0.0",
|
|
34
33
|
"eslint": "^8.46.0",
|
|
35
|
-
"file-lane": "2.0.5-beta.
|
|
34
|
+
"file-lane": "2.0.5-widget-provider-beta.2",
|
|
36
35
|
"fs-extra": "^11.2.0",
|
|
37
36
|
"google-protobuf": "^3.21.2",
|
|
38
37
|
"less": "^4.2.0",
|
|
@@ -61,5 +60,5 @@
|
|
|
61
60
|
"@types/tinycolor2": "^1.4.6",
|
|
62
61
|
"babel-plugin-tester": "^11.0.4"
|
|
63
62
|
},
|
|
64
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "4a8894bc66a9c78cd835ed6c1af74d054300e064"
|
|
65
64
|
}
|
package/lib/xts/XtsParser.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* xts生成 xts 的 ast 树
|
|
3
|
-
* 工作内容为
|
|
4
|
-
* 1. 替换component 为 class + 4个空格
|
|
5
|
-
* 2. 使用typescript 解析成 ast 树
|
|
6
|
-
*/
|
|
7
|
-
import { Logger } from '@aiot-toolkit/shared-utils';
|
|
8
|
-
import { Project, SourceFile } from 'ts-morph';
|
|
9
|
-
import IOffset from '../interface/IOffset';
|
|
10
|
-
import IParser from '../interface/IParser';
|
|
11
|
-
export default class XtsParser implements IParser<SourceFile> {
|
|
12
|
-
project: Project;
|
|
13
|
-
onLog: Logger;
|
|
14
|
-
constructor(project: Project, onLog: Logger);
|
|
15
|
-
parser(content: string, fileName: string): {
|
|
16
|
-
ast: SourceFile;
|
|
17
|
-
offsetList: IOffset[];
|
|
18
|
-
};
|
|
19
|
-
private replaceKeyWord;
|
|
20
|
-
}
|