@aiot-toolkit/shared-utils 1.0.20 → 1.0.21-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.
@@ -1,242 +1,2 @@
1
- "use strict";
2
-
3
- const vdom_pb = require('./vdom_pb');
4
- /* eslint-disable */
5
-
6
-
7
- class AIOT {
8
- constructor(aiotf) {
9
- this.funcArr = [];
10
- this.chld = [];
11
- this.idCount = -1;
12
- this.expCell = new vdom_pb.ExportCell();
13
- this.aiotf = aiotf;
14
- this.optArr = [];
15
- }
16
-
17
- init(expName) {
18
- this.expCell.setTagname(expName);
19
- }
20
-
21
- parseObj(opts) {
22
- let styVaA = new vdom_pb.StyleValueArr();
23
-
24
- for (let key in opts) {
25
- let sKey = new vdom_pb.StyleKey();
26
- let onesvl = new vdom_pb.OneStyleValue();
27
- sKey.setValue(key);
28
- onesvl.setKey(sKey);
29
- let typ = Object.prototype.toString.call(opts[key]);
30
-
31
- if (typ === '[object Number]') {
32
- // TODO:double
33
- onesvl.setDoublevl(opts[key]);
34
- } else if (typ === '[object String]') {
35
- // console.log(`String ${opts[key]}`)
36
- onesvl.setStringvl(opts[key]);
37
- } else if (typ === '[object Function]') {
38
- if (this.aiotf == undefined) {
39
- this.funcArr.push(opts[key]);
40
- onesvl.setFuncid(this.funcArr.length - 1);
41
- } else {
42
- this.aiotf.funcArr.push(opts[key]);
43
- onesvl.setFuncid(this.aiotf.funcArr.length - 1);
44
- }
45
- } else if (typ === '[object Object]') {
46
- // console.log(`object ${opts[key]}`)
47
- let styVaA_ = new vdom_pb.StyleValueArr();
48
- styVaA_ = this.parseObj(opts[key]);
49
- onesvl.setStylevlarr(styVaA_);
50
- } else if (typ === '[object Array]') {
51
- //TODO:default string arr
52
- // console.log(`Array ${opts[key]}`)
53
- let strarr = new vdom_pb.StringArr();
54
- strarr.setStringvlarrList(opts[key]);
55
- onesvl.setStringarr(strarr);
56
- } else if (typ === '[object Boolean]') {
57
- onesvl.setBoolvl(opts[key]);
58
- }
59
-
60
- styVaA.addVlarr(onesvl);
61
- }
62
-
63
- return styVaA;
64
- }
65
-
66
- __cdc__(tagName, opts, childsArr) {
67
- return this.__ce__(tagName, opts, childsArr, '__cdc__');
68
- }
69
-
70
- __ce__(tagName, opts, childsArr, type = '__ce__') {
71
- let tempOne = new vdom_pb.TemplateOne();
72
- let ce = new vdom_pb.TemplateUnit();
73
- ce.setType(type);
74
- ce.setTag(tagName);
75
-
76
- if (Array.isArray(childsArr) && childsArr.length > 0) {
77
- let arr = [];
78
-
79
- for (let key in childsArr) {
80
- arr.push(childsArr[key].id_);
81
- }
82
-
83
- tempOne.setChldsidList(arr);
84
- }
85
-
86
- tempOne.setId(++this.idCount);
87
- let styVaA_ = this.parseObj(opts.__opts__);
88
- ce.setOptsarrList(styVaA_.getVlarrList());
89
- tempOne.setCv(ce);
90
- this.expCell.addTemplatearr(tempOne);
91
- return {
92
- id_: this.idCount,
93
- aiot_: this
94
- };
95
- }
96
-
97
- __ci__(opts, renderFunc) {
98
- let tempOne = new vdom_pb.TemplateOne();
99
- let ci = new vdom_pb.TemplateUnit();
100
- ci.setType('__ci__');
101
- tempOne.setId(++this.idCount);
102
- let styVaA_ = this.parseObj(opts.__opts__);
103
- ci.setOptsarrList(styVaA_.getVlarrList()); // function(aiot) {
104
-
105
- let aiotif = new AIOT(this);
106
- aiotif.funcArr = this.funcArr;
107
- aiotif.optArr = this.optArr;
108
- let renderArr = renderFunc(aiotif);
109
- let typ = Object.prototype.toString.call(renderArr);
110
-
111
- if (typ === '[object Object]') {
112
- ci.setTemplaterenderList(renderArr.aiot_.expCell.getTemplatearrList());
113
- } else if (typ === '[object Array]') {
114
- for (let key in renderArr) {
115
- ci.setTemplaterenderList(renderArr[key].aiot_.expCell.getTemplatearrList());
116
- break;
117
- }
118
- }
119
-
120
- this.funcArr = aiotif.aiotf.funcArr;
121
- tempOne.setCv(ci);
122
- this.expCell.addTemplatearr(tempOne);
123
- return {
124
- id_: this.idCount,
125
- aiot_: this
126
- };
127
- }
128
-
129
- __cf__(opts, renderFunc) {
130
- let tempOne = new vdom_pb.TemplateOne();
131
- let cf = new vdom_pb.TemplateUnit();
132
- cf.setType('__cf__');
133
- tempOne.setId(++this.idCount);
134
- let styVaA_ = this.parseObj(opts.__opts__);
135
- cf.setOptsarrList(styVaA_.getVlarrList());
136
- let aiotfor = new AIOT();
137
- aiotfor.optArr = this.optArr;
138
- let key_, value_;
139
- let renderArr = renderFunc(key_, value_, aiotfor);
140
- let typ = Object.prototype.toString.call(renderArr);
141
-
142
- if (typ === '[object Object]') {
143
- cf.setTemplaterenderList(renderArr.aiot_.expCell.getTemplatearrList());
144
- } else if (typ === '[object Array]') {
145
- for (let key in renderArr) {
146
- cf.setTemplaterenderList(renderArr[key].aiot_.expCell.getTemplatearrList());
147
- break;
148
- }
149
- }
150
-
151
- if (aiotfor.funcArr.length > 0) {
152
- const fun = function ($idx, $item) {
153
- return aiotfor.aiotf.funcArr;
154
- };
155
-
156
- fun.aiotfor = aiotfor;
157
- fun.aiotfor.key = opts.__opts__['key'];
158
- fun.aiotfor.value = opts.__opts__['value'];
159
- this.funcArr.push(fun);
160
- cf.setFuncrender(this.funcArr.length - 1);
161
- } else {
162
- cf.setFuncrender(-1);
163
- }
164
-
165
- tempOne.setCv(cf);
166
- this.expCell.addTemplatearr(tempOne);
167
- return {
168
- id_: this.idCount,
169
- aiot_: this
170
- };
171
- }
172
-
173
- __cc__(tagName, opts) {
174
- let tempOne = new vdom_pb.TemplateOne();
175
- let cc = new vdom_pb.TemplateUnit();
176
- cc.setType('__cc__');
177
- cc.setTag(tagName);
178
- tempOne.setId(++this.idCount); // 设置__opts__在数组中得索引
179
- // if (Object.keys(opts.__opts__).length > 0) {
180
- // this.optArr.push(opts.__opts__) //save to js
181
- // cc.setOptsid(this.optArr.length - 1)
182
- // } else {
183
- // cc.setOptsid(-1)
184
- // }
185
-
186
- let styVaA_ = this.parseObj(opts.__opts__);
187
- cc.setOptsarrList(styVaA_.getVlarrList());
188
- tempOne.setCv(cc);
189
- this.expCell.addTemplatearr(tempOne);
190
- return {
191
- id_: this.idCount,
192
- aiot_: this
193
- };
194
- }
195
-
196
- __cb__(opts, renderFunc) {
197
- let tempOne = new vdom_pb.TemplateOne();
198
- let cb = new vdom_pb.TemplateUnit();
199
- cb.setType('__cb__');
200
- tempOne.setId(++this.idCount);
201
- let styVaA_ = this.parseObj(opts.__opts__);
202
- cb.setOptsarrList(styVaA_.getVlarrList());
203
- let aiotcb = new AIOT();
204
- aiotcb.optArr = this.optArr;
205
- let $data;
206
- let renderArr = renderFunc($data, aiotcb);
207
- let typ = Object.prototype.toString.call(renderArr);
208
-
209
- if (typ === '[object Object]') {
210
- cb.setTemplaterenderList(renderArr.aiot_.expCell.getTemplatearrList());
211
- } else if (typ === '[object Array]') {
212
- for (let key in renderArr) {
213
- cb.setTemplaterenderList(renderArr[key].aiot_.expCell.getTemplatearrList());
214
- break;
215
- }
216
- }
217
-
218
- if (aiotcb.funcArr.length > 0) {
219
- const fun = function ($data) {
220
- return aiotcb.aiotf.funcArr;
221
- };
222
-
223
- fun.aiotcb = aiotcb;
224
- this.funcArr.push(fun);
225
- cb.setFuncrender(this.funcArr.length - 1);
226
- } else {
227
- cb.setFuncrender(-1);
228
- } // this.funcArr = aiotcb.aiotf.funcArr
229
-
230
-
231
- tempOne.setCv(cb);
232
- this.expCell.addTemplatearr(tempOne);
233
- return {
234
- id_: this.idCount,
235
- aiot_: this
236
- };
237
- }
238
-
239
- }
240
-
241
- module.exports = AIOT;
1
+ "use strict";const vdom_pb=require("./vdom_pb");class AIOT{constructor(e){this.funcArr=[],this.chld=[],this.idCount=-1,this.expCell=new vdom_pb.ExportCell,this.aiotf=e,this.optArr=[]}init(e){this.expCell.setTagname(e)}parseObj(e){let t=new vdom_pb.StyleValueArr;for(let r in e){let s=new vdom_pb.StyleKey,i=new vdom_pb.OneStyleValue;s.setValue(r),i.setKey(s);let l=Object.prototype.toString.call(e[r]);if("[object Number]"===l)i.setDoublevl(e[r]);else if("[object String]"===l)i.setStringvl(e[r]);else if("[object Function]"===l)null==this.aiotf?(this.funcArr.push(e[r]),i.setFuncid(this.funcArr.length-1)):(this.aiotf.funcArr.push(e[r]),i.setFuncid(this.aiotf.funcArr.length-1));else if("[object Object]"===l){let t=new vdom_pb.StyleValueArr;t=this.parseObj(e[r]),i.setStylevlarr(t)}else if("[object Array]"===l){let t=new vdom_pb.StringArr;t.setStringvlarrList(e[r]),i.setStringarr(t)}else"[object Boolean]"===l&&i.setBoolvl(e[r]);t.addVlarr(i)}return t}__cdc__(e,t,r){return this.__ce__(e,t,r,"__cdc__")}__ce__(e,t,r,s="__ce__"){let i=new vdom_pb.TemplateOne,l=new vdom_pb.TemplateUnit;if(l.setType(s),l.setTag(e),Array.isArray(r)&&r.length>0){let e=[];for(let t in r)e.push(r[t].id_);i.setChldsidList(e)}i.setId(++this.idCount);let n=this.parseObj(t.__opts__);return l.setOptsarrList(n.getVlarrList()),i.setCv(l),this.expCell.addTemplatearr(i),{id_:this.idCount,aiot_:this}}__ci__(e,t){let r=new vdom_pb.TemplateOne,s=new vdom_pb.TemplateUnit;s.setType("__ci__"),r.setId(++this.idCount);let i=this.parseObj(e.__opts__);s.setOptsarrList(i.getVlarrList());let l=new AIOT(this);l.funcArr=this.funcArr,l.optArr=this.optArr;let n=t(l),_=Object.prototype.toString.call(n);if("[object Object]"===_)s.setTemplaterenderList(n.aiot_.expCell.getTemplatearrList());else if("[object Array]"===_)for(let e in n){s.setTemplaterenderList(n[e].aiot_.expCell.getTemplatearrList());break}return this.funcArr=l.aiotf.funcArr,r.setCv(s),this.expCell.addTemplatearr(r),{id_:this.idCount,aiot_:this}}__cf__(e,t){let r=new vdom_pb.TemplateOne,s=new vdom_pb.TemplateUnit;s.setType("__cf__"),r.setId(++this.idCount);let i=this.parseObj(e.__opts__);s.setOptsarrList(i.getVlarrList());let l=new AIOT;l.optArr=this.optArr;let n=t(undefined,undefined,l),_=Object.prototype.toString.call(n);if("[object Object]"===_)s.setTemplaterenderList(n.aiot_.expCell.getTemplatearrList());else if("[object Array]"===_)for(let e in n){s.setTemplaterenderList(n[e].aiot_.expCell.getTemplatearrList());break}if(l.funcArr.length>0){const t=function(e,t){return l.aiotf.funcArr};t.aiotfor=l,t.aiotfor.key=e.__opts__.key,t.aiotfor.value=e.__opts__.value,this.funcArr.push(t),s.setFuncrender(this.funcArr.length-1)}else s.setFuncrender(-1);return r.setCv(s),this.expCell.addTemplatearr(r),{id_:this.idCount,aiot_:this}}__cc__(e,t){let r=new vdom_pb.TemplateOne,s=new vdom_pb.TemplateUnit;s.setType("__cc__"),s.setTag(e),r.setId(++this.idCount);let i=this.parseObj(t.__opts__);return s.setOptsarrList(i.getVlarrList()),r.setCv(s),this.expCell.addTemplatearr(r),{id_:this.idCount,aiot_:this}}__cb__(e,t){let r=new vdom_pb.TemplateOne,s=new vdom_pb.TemplateUnit;s.setType("__cb__"),r.setId(++this.idCount);let i=this.parseObj(e.__opts__);s.setOptsarrList(i.getVlarrList());let l=new AIOT;l.optArr=this.optArr;let n=t(undefined,l),_=Object.prototype.toString.call(n);if("[object Object]"===_)s.setTemplaterenderList(n.aiot_.expCell.getTemplatearrList());else if("[object Array]"===_)for(let e in n){s.setTemplaterenderList(n[e].aiot_.expCell.getTemplatearrList());break}if(l.funcArr.length>0){const e=function(e){return l.aiotf.funcArr};e.aiotcb=l,this.funcArr.push(e),s.setFuncrender(this.funcArr.length-1)}else s.setFuncrender(-1);return r.setCv(s),this.expCell.addTemplatearr(r),{id_:this.idCount,aiot_:this}}}module.exports=AIOT;
242
2
  //# sourceMappingURL=protobuf.js.map
@@ -1,173 +1,2 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.extractFunctions = extractFunctions;
7
- exports.createBin = createBin;
8
-
9
- var _lib = require("../../lib");
10
-
11
- const vdom_pb = require('./vdom_pb');
12
-
13
- const Path = require('path');
14
-
15
- const fs = require('fs');
16
-
17
- const AIOT = require('./protobuf');
18
- /**
19
- *
20
- * @param {[[[number, string]], {[key:string]:string|number}][]} style
21
- */
22
-
23
-
24
- function translateStyle(style, aiot) {
25
- const exportCell = aiot.expCell;
26
- style.forEach(item => {
27
- const hasProperty = item.length === 3;
28
- let property;
29
- let selectorList = item[0];
30
- let styleValue = item[1];
31
-
32
- if (hasProperty) {
33
- property = item[0];
34
- selectorList = item[1];
35
- styleValue = item[2];
36
- }
37
-
38
- const cssCell = exportCell.addCssarr(); // 如果有 property,写入
39
-
40
- if (hasProperty && property) {
41
- Object.keys(property).forEach(key => {
42
- const value = property[key];
43
- const propertyArr = cssCell.addPropertyarr(); // 设置属性名
44
-
45
- const propertyKey = new vdom_pb.StyleKey();
46
- propertyKey.setValue(key);
47
- propertyArr.setKey(propertyKey); // 设置属性值
48
-
49
- switch (typeof value) {
50
- case 'string':
51
- propertyArr.setStringvl(value);
52
- break;
53
-
54
- case 'number':
55
- if (Number.isInteger(value)) {
56
- propertyArr.setInt32vl(value);
57
- } else {
58
- propertyArr.setDoublevl(value);
59
- }
60
-
61
- break;
62
- }
63
- });
64
- } // 写入选择器
65
-
66
-
67
- selectorList.forEach(selectorItem => {
68
- const selector = cssCell.addSelectorarr();
69
- selector.setId(selectorItem[0]);
70
- selector.setName(selectorItem[1]);
71
- }); // 写入属性值
72
-
73
- Object.keys(styleValue).forEach(key => {
74
- const value = styleValue[key];
75
- const styleVl = cssCell.addStylearr(); // 设置css属性名称
76
-
77
- const pk = new vdom_pb.StyleKey();
78
- pk.setValue(key);
79
- styleVl.setKey(pk);
80
- const valueType = typeof value; // 设置css值
81
-
82
- switch (valueType) {
83
- case 'string':
84
- styleVl.setStringvl(value);
85
- break;
86
-
87
- case 'number':
88
- if (Number.isInteger(value)) {
89
- styleVl.setInt32vl(value);
90
- } else {
91
- styleVl.setDoublevl(value);
92
- }
93
-
94
- break;
95
-
96
- case 'object':
97
- styleVl.setStylevlarr(aiot.parseObj(value));
98
- break;
99
-
100
- default:
101
- _lib.colorconsole.warn(`CssValue Of ${valueType} NotProcessed`);
102
-
103
- }
104
- });
105
- });
106
- return exportCell;
107
- }
108
-
109
- function translateTemplate(template, aiot) {
110
- const vm = {};
111
-
112
- if (template) {
113
- // eslint-disable-next-line no-eval
114
- eval(`(${template})`)(vm);
115
- }
116
- }
117
-
118
- function createItem(entryName, style, template) {
119
- // 创建aiot对象
120
- let aiot = new AIOT();
121
- aiot.init(entryName || 'entry'); // 写入template
122
-
123
- translateTemplate(template, aiot); // 写入style
124
-
125
- translateStyle(style, aiot);
126
- return aiot;
127
- }
128
- /**
129
- *
130
- * @param {*} template
131
- */
132
-
133
-
134
- function extractFunctions(template) {
135
- // 创建aiot对象
136
- let aiot = new AIOT();
137
- aiot.init('temp'); // 写入template
138
-
139
- translateTemplate(template, aiot);
140
- return aiot;
141
- }
142
- /**
143
- * 创建bin文件
144
- * @param {string} fileName
145
- * @param {string[]} styleList
146
- * @param {string[]} templateList
147
- */
148
-
149
-
150
- function createBin(fileName, tagList, styleList, templateList) {
151
- const dataList = styleList.map((item, index) => {
152
- return createItem(tagList[index], JSON.parse(item), templateList[index]);
153
- }); // 写入数据
154
-
155
- let indexExport = new vdom_pb.ExportArr();
156
- indexExport.clearValuearrList();
157
- dataList.forEach(item => {
158
- indexExport.addValuearr(item.expCell);
159
- }); // 如果文件夹不存在,则创建
160
-
161
- const folder = Path.dirname(fileName);
162
-
163
- if (!fs.existsSync(folder)) {
164
- fs.mkdirSync(folder, {
165
- recursive: true
166
- });
167
- } // 写入文件
168
-
169
-
170
- let outbuff = indexExport.serializeBinary();
171
- fs.writeFileSync(fileName, outbuff);
172
- }
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.extractFunctions=extractFunctions,exports.createBin=createBin;var _lib=require("../../lib");const vdom_pb=require("./vdom_pb"),Path=require("path"),fs=require("fs"),AIOT=require("./protobuf");function translateStyle(e,t){const r=t.expCell;return e.forEach((e=>{const a=3===e.length;let s,n=e[0],l=e[1];a&&(s=e[0],n=e[1],l=e[2]);const c=r.addCssarr();a&&s&&Object.keys(s).forEach((e=>{const t=s[e],r=c.addPropertyarr(),a=new vdom_pb.StyleKey;switch(a.setValue(e),r.setKey(a),typeof t){case"string":r.setStringvl(t);break;case"number":Number.isInteger(t)?r.setInt32vl(t):r.setDoublevl(t)}})),n.forEach((e=>{const t=c.addSelectorarr();t.setId(e[0]),t.setName(e[1])})),Object.keys(l).forEach((e=>{const r=l[e],a=c.addStylearr(),s=new vdom_pb.StyleKey;s.setValue(e),a.setKey(s);const n=typeof r;switch(n){case"string":a.setStringvl(r);break;case"number":Number.isInteger(r)?a.setInt32vl(r):a.setDoublevl(r);break;case"object":a.setStylevlarr(t.parseObj(r));break;default:_lib.colorconsole.warn(`CssValue Of ${n} NotProcessed`)}}))})),r}function translateTemplate(template,aiot){const vm={};template&&eval(`(${template})`)(vm)}function createItem(e,t,r){let a=new AIOT;return a.init(e||"entry"),translateTemplate(r,a),translateStyle(t,a),a}function extractFunctions(e){let t=new AIOT;return t.init("temp"),translateTemplate(e,t),t}function createBin(e,t,r,a){const s=r.map(((e,r)=>createItem(t[r],JSON.parse(e),a[r])));let n=new vdom_pb.ExportArr;n.clearValuearrList(),s.forEach((e=>{n.addValuearr(e.expCell)}));const l=Path.dirname(e);fs.existsSync(l)||fs.mkdirSync(l,{recursive:!0});let c=n.serializeBinary();fs.writeFileSync(e,c)}
173
2
  //# sourceMappingURL=protobufControl.js.map