@aiot-toolkit/parser 2.0.5-widget-provider-beta.2 → 2.0.6-alpha.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.
Files changed (49) hide show
  1. package/README.md +11 -11
  2. package/lib/utils/ParserUtil.js +15 -15
  3. package/lib/ux/config/ExtensionConfig.js +2 -2
  4. package/lib/ux/config/FeatureConfig.js +19 -19
  5. package/lib/ux/config/vela/ElementConfig.js +0 -8
  6. package/lib/ux/config/vela/StyleAttributeConfig.js +134 -88
  7. package/lib/ux/enum/StyleSelectorType.js +6 -6
  8. package/lib/ux/enum/TemplateNodeType.js +2 -2
  9. package/lib/ux/enum/android/StyleSelectorName.js +2 -2
  10. package/lib/ux/interface/IUxAst.d.ts +2 -0
  11. package/lib/ux/parser/ScriptParser.js +2 -2
  12. package/lib/ux/parser/StyleParser.js +79 -72
  13. package/lib/ux/parser/TemplateValueParser.js +49 -49
  14. package/lib/ux/parser/UxParser.js +18 -12
  15. package/lib/ux/translate/android/StyleToTypescript.js +51 -51
  16. package/lib/ux/translate/android/TemplateToTypescript.js +51 -51
  17. package/lib/ux/translate/android/UxToTypescript.js +14 -14
  18. package/lib/ux/translate/android/attributeTranslate/ForTranslate.js +17 -17
  19. package/lib/ux/translate/android/attributeTranslate/IfTranslate.js +9 -9
  20. package/lib/ux/translate/vela/ScriptToTypescript.js +10 -10
  21. package/lib/ux/translate/vela/StyleToTypescript.js +10 -10
  22. package/lib/ux/translate/vela/TemplateToTypescript.js +74 -74
  23. package/lib/ux/translate/vela/TranslateCache.js +2 -2
  24. package/lib/ux/translate/vela/UxToTypescript.js +6 -6
  25. package/lib/ux/translate/vela/VelaContext.js +2 -2
  26. package/lib/ux/translate/vela/plugins/e2e.js +63 -62
  27. package/lib/ux/translate/vela/plugins/startPage.js +1 -1
  28. package/lib/ux/translate/vela/protobuf/BinaryPlugin.js +172 -172
  29. package/lib/ux/translate/vela/protobuf/protobuf.js +235 -235
  30. package/lib/ux/translate/vela/protobuf/protobufControl.js +159 -159
  31. package/lib/ux/translate/vela/protobuf/vdom_pb.js +2374 -2374
  32. package/lib/ux/translate/vela/runtime/velaTestLibrary.js +104 -104
  33. package/lib/ux/translate/vela/utils/AttributeConfig.js +15 -15
  34. package/lib/ux/translate/vela/utils/ExtendedBoxStyle.js +38 -38
  35. package/lib/ux/translate/vela/utils/SourceMapUtil.d.ts +0 -4
  36. package/lib/ux/translate/vela/utils/SourceMapUtil.js +30 -36
  37. package/lib/ux/translate/vela/utils/TemplateUtil.js +180 -180
  38. package/lib/ux/translate/vela/wrap/CbTranslate.js +8 -8
  39. package/lib/ux/translate/vela/wrap/CfTranslate.js +14 -14
  40. package/lib/ux/translate/vela/wrap/CiTranslate.js +11 -11
  41. package/lib/ux/utils/BabelUtil.js +35 -35
  42. package/lib/ux/utils/ElementConfigUtil.js +24 -24
  43. package/lib/ux/utils/StyleMapUtil.js +15 -15
  44. package/lib/ux/utils/StyleUtil.d.ts +1 -1
  45. package/lib/ux/utils/StyleUtil.js +192 -248
  46. package/lib/ux/utils/UxUtil.js +32 -32
  47. package/lib/ux/validate/ElementValidate.js +2 -2
  48. package/lib/ux/validate/UxFileValidate.js +2 -2
  49. package/package.json +4 -4
@@ -1,159 +1,159 @@
1
- const vdom_pb = require('./vdom_pb')
2
- const Path = require('path')
3
- const fs = require('fs')
4
- const AIOT = require('./protobuf')
5
-
6
- /**
7
- *
8
- * @param {[[[number, string]], {[key:string]:string|number}][]} style
9
- */
10
- function translateStyle(style, aiot) {
11
- const exportCell = aiot.expCell
12
-
13
- style.forEach((item) => {
14
- const hasProperty = item.length === 3
15
- let property
16
- let selectorList = item[0]
17
- let styleValue = item[1]
18
- if (hasProperty) {
19
- property = item[0]
20
- selectorList = item[1]
21
- styleValue = item[2]
22
- }
23
-
24
- const cssCell = exportCell.addCssarr()
25
-
26
- // 如果有 property,写入
27
- if (hasProperty && property) {
28
- Object.keys(property).forEach((key) => {
29
- const value = property[key]
30
- const propertyArr = cssCell.addPropertyarr()
31
- // 设置属性名
32
- const propertyKey = new vdom_pb.StyleKey()
33
- propertyKey.setValue(key)
34
- propertyArr.setKey(propertyKey)
35
-
36
- // 设置属性值
37
- switch (typeof value) {
38
- case 'string':
39
- propertyArr.setStringvl(value)
40
- break
41
- case 'number':
42
- if (Number.isInteger(value)) {
43
- propertyArr.setInt32vl(value)
44
- } else {
45
- propertyArr.setDoublevl(value)
46
- }
47
- break
48
- }
49
- })
50
- }
51
-
52
- // 写入选择器
53
- selectorList.forEach((selectorItem) => {
54
- const selector = cssCell.addSelectorarr()
55
- selector.setId(selectorItem[0])
56
- selector.setName(selectorItem[1])
57
- })
58
-
59
- // 写入属性值
60
- Object.keys(styleValue).forEach((key) => {
61
- const value = styleValue[key]
62
-
63
- const styleVl = cssCell.addStylearr()
64
-
65
- // 设置css属性名称
66
- const pk = new vdom_pb.StyleKey()
67
- pk.setValue(key)
68
- styleVl.setKey(pk)
69
-
70
- const valueType = typeof value
71
- // 设置css值
72
- switch (valueType) {
73
- case 'string':
74
- styleVl.setStringvl(value)
75
- break
76
- case 'number':
77
- if (Number.isInteger(value)) {
78
- styleVl.setInt32vl(value)
79
- } else {
80
- styleVl.setDoublevl(value)
81
- }
82
- break
83
- case 'object':
84
- styleVl.setStylevlarr(aiot.parseObj(value))
85
- break
86
- default:
87
- console.warn(`CssValue Of ${valueType} NotProcessed`)
88
- }
89
- })
90
- })
91
- return exportCell
92
- }
93
-
94
- function translateTemplate(template, aiot) {
95
- const vm = {}
96
- if (template) {
97
- // eslint-disable-next-line no-eval
98
- eval(`(${template})`)(vm)
99
- }
100
- }
101
-
102
- function createItem(entryName, style, template) {
103
- // 创建aiot对象
104
- let aiot = new AIOT()
105
- aiot.init(entryName || 'entry')
106
- // 写入template
107
- translateTemplate(template, aiot)
108
- // 写入style
109
- translateStyle(style, aiot)
110
-
111
- return aiot
112
- }
113
-
114
- /**
115
- *
116
- * @param {*} template
117
- */
118
- function extractFunctions(template) {
119
- // 创建aiot对象
120
- let aiot = new AIOT()
121
- aiot.init('temp')
122
-
123
- // 写入template
124
- translateTemplate(template, aiot)
125
-
126
- return aiot
127
- }
128
-
129
- /**
130
- * 创建bin文件
131
- * @param {string} fileName
132
- * @param {string[]} styleList
133
- * @param {string[]} templateList
134
- */
135
- function createBin(fileName, tagList, styleList, templateList) {
136
- const dataList = styleList.map((item, index) => {
137
- return createItem(tagList[index], JSON.parse(item), templateList[index])
138
- })
139
-
140
- // 写入数据
141
- let indexExport = new vdom_pb.ExportArr()
142
- indexExport.clearValuearrList()
143
- dataList.forEach((item) => {
144
- indexExport.addValuearr(item.expCell)
145
- })
146
-
147
- // 如果文件夹不存在,则创建
148
- const folder = Path.dirname(fileName)
149
- if (!fs.existsSync(folder)) {
150
- fs.mkdirSync(folder, { recursive: true })
151
- }
152
- // 写入文件
153
- let outbuff = indexExport.serializeBinary()
154
- fs.writeFileSync(fileName, outbuff)
155
- }
156
- module.exports = {
157
- extractFunctions,
158
- createBin
159
- }
1
+ const vdom_pb = require('./vdom_pb')
2
+ const Path = require('path')
3
+ const fs = require('fs')
4
+ const AIOT = require('./protobuf')
5
+
6
+ /**
7
+ *
8
+ * @param {[[[number, string]], {[key:string]:string|number}][]} style
9
+ */
10
+ function translateStyle(style, aiot) {
11
+ const exportCell = aiot.expCell
12
+
13
+ style.forEach((item) => {
14
+ const hasProperty = item.length === 3
15
+ let property
16
+ let selectorList = item[0]
17
+ let styleValue = item[1]
18
+ if (hasProperty) {
19
+ property = item[0]
20
+ selectorList = item[1]
21
+ styleValue = item[2]
22
+ }
23
+
24
+ const cssCell = exportCell.addCssarr()
25
+
26
+ // 如果有 property,写入
27
+ if (hasProperty && property) {
28
+ Object.keys(property).forEach((key) => {
29
+ const value = property[key]
30
+ const propertyArr = cssCell.addPropertyarr()
31
+ // 设置属性名
32
+ const propertyKey = new vdom_pb.StyleKey()
33
+ propertyKey.setValue(key)
34
+ propertyArr.setKey(propertyKey)
35
+
36
+ // 设置属性值
37
+ switch (typeof value) {
38
+ case 'string':
39
+ propertyArr.setStringvl(value)
40
+ break
41
+ case 'number':
42
+ if (Number.isInteger(value)) {
43
+ propertyArr.setInt32vl(value)
44
+ } else {
45
+ propertyArr.setDoublevl(value)
46
+ }
47
+ break
48
+ }
49
+ })
50
+ }
51
+
52
+ // 写入选择器
53
+ selectorList.forEach((selectorItem) => {
54
+ const selector = cssCell.addSelectorarr()
55
+ selector.setId(selectorItem[0])
56
+ selector.setName(selectorItem[1])
57
+ })
58
+
59
+ // 写入属性值
60
+ Object.keys(styleValue).forEach((key) => {
61
+ const value = styleValue[key]
62
+
63
+ const styleVl = cssCell.addStylearr()
64
+
65
+ // 设置css属性名称
66
+ const pk = new vdom_pb.StyleKey()
67
+ pk.setValue(key)
68
+ styleVl.setKey(pk)
69
+
70
+ const valueType = typeof value
71
+ // 设置css值
72
+ switch (valueType) {
73
+ case 'string':
74
+ styleVl.setStringvl(value)
75
+ break
76
+ case 'number':
77
+ if (Number.isInteger(value)) {
78
+ styleVl.setInt32vl(value)
79
+ } else {
80
+ styleVl.setDoublevl(value)
81
+ }
82
+ break
83
+ case 'object':
84
+ styleVl.setStylevlarr(aiot.parseObj(value))
85
+ break
86
+ default:
87
+ console.warn(`CssValue Of ${valueType} NotProcessed`)
88
+ }
89
+ })
90
+ })
91
+ return exportCell
92
+ }
93
+
94
+ function translateTemplate(template, aiot) {
95
+ const vm = {}
96
+ if (template) {
97
+ // eslint-disable-next-line no-eval
98
+ eval(`(${template})`)(vm)
99
+ }
100
+ }
101
+
102
+ function createItem(entryName, style, template) {
103
+ // 创建aiot对象
104
+ let aiot = new AIOT()
105
+ aiot.init(entryName || 'entry')
106
+ // 写入template
107
+ translateTemplate(template, aiot)
108
+ // 写入style
109
+ translateStyle(style, aiot)
110
+
111
+ return aiot
112
+ }
113
+
114
+ /**
115
+ *
116
+ * @param {*} template
117
+ */
118
+ function extractFunctions(template) {
119
+ // 创建aiot对象
120
+ let aiot = new AIOT()
121
+ aiot.init('temp')
122
+
123
+ // 写入template
124
+ translateTemplate(template, aiot)
125
+
126
+ return aiot
127
+ }
128
+
129
+ /**
130
+ * 创建bin文件
131
+ * @param {string} fileName
132
+ * @param {string[]} styleList
133
+ * @param {string[]} templateList
134
+ */
135
+ function createBin(fileName, tagList, styleList, templateList) {
136
+ const dataList = styleList.map((item, index) => {
137
+ return createItem(tagList[index], JSON.parse(item), templateList[index])
138
+ })
139
+
140
+ // 写入数据
141
+ let indexExport = new vdom_pb.ExportArr()
142
+ indexExport.clearValuearrList()
143
+ dataList.forEach((item) => {
144
+ indexExport.addValuearr(item.expCell)
145
+ })
146
+
147
+ // 如果文件夹不存在,则创建
148
+ const folder = Path.dirname(fileName)
149
+ if (!fs.existsSync(folder)) {
150
+ fs.mkdirSync(folder, { recursive: true })
151
+ }
152
+ // 写入文件
153
+ let outbuff = indexExport.serializeBinary()
154
+ fs.writeFileSync(fileName, outbuff)
155
+ }
156
+ module.exports = {
157
+ extractFunctions,
158
+ createBin
159
+ }