@lightsoft/js-sdk 1.0.0 → 1.0.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.
@@ -0,0 +1,4 @@
1
+ declare function render(html: string, context?: {}): any;
2
+ declare function rebuild(selector: string, context: Record<string, any>): void;
3
+
4
+ export { rebuild, render };
@@ -0,0 +1,236 @@
1
+ var TAG_NAME_REGEX = /<\/?\s*([a-zA-Z][a-zA-Z0-9-]*)\b/; // 获取开始或结束标签的名
2
+ var SINGLE_TAG_REGEX = /<([^\s>]+)/; // 单标签
3
+ var TAG_REGEX = /<\/?[a-z]+[^>]*>|[^<>]+/gi; // 开始和结束标签
4
+ var $FOR_REGEX = /r-for\s*=\s*"([^"]+)"/; //$for 属性值
5
+ var $IF_REGEX = /r-if\s*=\s*"([^"]+)"/; //$if 属性值
6
+ var $STYLE_REGEX = /r-style\s*=\s*"([^"]+)"/; //$style 属性值
7
+ var $CLASS_REGEX = /r-class\s*=\s*"([^"]+)"/; //$class 属性值
8
+ var $ATTRS_REGEX = /\sr-[a-z]\w+\s*=\s*"[^"]*"/g; // 所有$符号的属性
9
+ var $CONTENT_REGEX = /\{\{(.+?)\}\}/g; // $符号内容
10
+ var RELATIONAL_SYMBOLS_REGEX = /<=|>=|\=+|>|</; // 关系符号
11
+ var STR_REGEX = /^("|'|`)(.*)\1$/;
12
+ var CALLBACK_REGEX = /\s*setContent\((.*?)\)\s*/g;
13
+ var FUN_NAME_REGEX = /([a-zA-Z_$][a-zA-Z0-9_$]*)/;
14
+ function useId() {
15
+ return Math.random().toString(36).substring(2, 15);
16
+ }
17
+ function hasSingleTag(tag) {
18
+ var _a;
19
+ return ['img', 'br', 'input'].includes((_a = tag.match(SINGLE_TAG_REGEX)) === null || _a === void 0 ? void 0 : _a[1]);
20
+ }
21
+ function findStartTag(currentIndex, tags) {
22
+ var _a, _b, _c, _d;
23
+ var index = 1;
24
+ var prevTag = tags[currentIndex - index];
25
+ var currentTag = tags[currentIndex];
26
+ var currentTagName = (_b = (_a = currentTag.tag) === null || _a === void 0 ? void 0 : _a.match(TAG_NAME_REGEX)) === null || _b === void 0 ? void 0 : _b[1];
27
+ var prevTagName;
28
+ while (currentTagName !== prevTagName) {
29
+ prevTag = tags[currentIndex - index] || prevTag;
30
+ prevTagName = (_d = (_c = prevTag.tag) === null || _c === void 0 ? void 0 : _c.match(TAG_NAME_REGEX)) === null || _d === void 0 ? void 0 : _d[1];
31
+ index++;
32
+ }
33
+ return prevTag;
34
+ }
35
+ function operatorsParse(content) {
36
+ if (content === void 0) { content = ''; }
37
+ return content.replace('&gt;', '>').replace('&lt;', '<').replaceAll('&amp;', '&');
38
+ }
39
+ function resolver(htmlStr) {
40
+ var _a, _b, _c, _d, _e, _f;
41
+ var tags = [];
42
+ var match;
43
+ var index = 0;
44
+ var annotation = false;
45
+ htmlStr = htmlStr.replace('<!--', '<annotation>').replace('-->', '</annotation>');
46
+ while ((match = TAG_REGEX.exec(htmlStr)) !== null) {
47
+ var tag = match[0].trim();
48
+ if (!tag)
49
+ continue;
50
+ if (tag.startsWith('</')) {
51
+ var item = {
52
+ type: 'node',
53
+ tag: tag,
54
+ };
55
+ if (annotation)
56
+ item.$disabledFor = true;
57
+ if ((_a = item === null || item === void 0 ? void 0 : item.tag) === null || _a === void 0 ? void 0 : _a.includes('</annotation>'))
58
+ annotation = false;
59
+ tags.push(item);
60
+ var prevTag = findStartTag(index, tags);
61
+ prevTag.endIndex = index;
62
+ }
63
+ else if (tag.startsWith('<')) {
64
+ var forMatch = (_b = tag.match($FOR_REGEX)) === null || _b === void 0 ? void 0 : _b[1];
65
+ var ifMatch = (_c = tag.match($IF_REGEX)) === null || _c === void 0 ? void 0 : _c[1];
66
+ var styleMatch = (_d = tag.match($STYLE_REGEX)) === null || _d === void 0 ? void 0 : _d[1];
67
+ var classMatch = (_e = tag.match($CLASS_REGEX)) === null || _e === void 0 ? void 0 : _e[1];
68
+ var item = {
69
+ type: 'node',
70
+ tag: tag.replace($ATTRS_REGEX, '')
71
+ };
72
+ if (forMatch)
73
+ item.$for = forMatch;
74
+ if (ifMatch)
75
+ item.$if = operatorsParse(ifMatch);
76
+ if (styleMatch)
77
+ item.$style = operatorsParse(styleMatch);
78
+ if (classMatch)
79
+ item.$class = operatorsParse(classMatch);
80
+ if ((_f = item === null || item === void 0 ? void 0 : item.tag) === null || _f === void 0 ? void 0 : _f.includes('<annotation>'))
81
+ annotation = true;
82
+ if (annotation)
83
+ item.$disabledFor = true;
84
+ tags.push(item);
85
+ }
86
+ else {
87
+ tags.push({
88
+ type: 'content',
89
+ content: tag,
90
+ });
91
+ }
92
+ index++;
93
+ }
94
+ return tags;
95
+ }
96
+ function callbackParse(content) {
97
+ if (content === void 0) { content = ''; }
98
+ return content.replace(CALLBACK_REGEX, function (_match, args) {
99
+ var _a;
100
+ var newArgs = args.split(',').map(function (arg) {
101
+ if (STR_REGEX.test(arg.trim()))
102
+ return arg;
103
+ return 'this.' + arg.trim();
104
+ });
105
+ var funName = (_a = content.match(FUN_NAME_REGEX)) === null || _a === void 0 ? void 0 : _a[0];
106
+ return "".concat(funName, "(").concat(newArgs, ")");
107
+ });
108
+ }
109
+ function contentParse(content) {
110
+ if (content === void 0) { content = ''; }
111
+ return content.replace($CONTENT_REGEX, function (_match, key) {
112
+ var newKey = callbackParse(key);
113
+ return '${this.' + newKey + '}';
114
+ });
115
+ }
116
+ function parseIf(ifContent) {
117
+ ifContent = ifContent.replace(/^\s*if\s*=\s*/, '');
118
+ var operator = ifContent.match(RELATIONAL_SYMBOLS_REGEX);
119
+ var _a = ifContent.split(RELATIONAL_SYMBOLS_REGEX), left = _a[0], right = _a[1];
120
+ var leftVariable = (STR_REGEX.test(left.trim()) || /\d/.test(left.trim())) ? left.trim() : "this.".concat(left.trim());
121
+ var rightVariable = (STR_REGEX.test(right.trim()) || /\d/.test(right.trim())) ? right.trim() : "this.".concat(right.trim());
122
+ var code = '';
123
+ code += "if(";
124
+ code += "".concat(leftVariable);
125
+ code += "".concat(operator);
126
+ code += "".concat(rightVariable);
127
+ code += ") {\n";
128
+ return code;
129
+ }
130
+ function styleParse(styleContent) {
131
+ var _a;
132
+ var styleValue = contentParse((_a = styleContent.match($CONTENT_REGEX)) === null || _a === void 0 ? void 0 : _a[0]);
133
+ return styleContent.replace($CONTENT_REGEX, styleValue);
134
+ }
135
+ function classParse(classContent) {
136
+ var _a;
137
+ if (classContent === void 0) { classContent = ''; }
138
+ var classValue = contentParse((_a = classContent.match($CONTENT_REGEX)) === null || _a === void 0 ? void 0 : _a[0]);
139
+ return classContent.replace($CONTENT_REGEX, classValue);
140
+ }
141
+ function attributeParse(tagData) {
142
+ var tag = tagData.tag;
143
+ var styleValue = styleParse(tagData.$style || '');
144
+ var classValue = classParse(tagData.$class || '');
145
+ var _style = styleValue ? ' style="' + styleValue + '"' : '';
146
+ var _class = classValue ? ' class="' + classValue + '"' : '';
147
+ return tag.replace('>', _style + _class + '>');
148
+ }
149
+ function parseFor(forContent) {
150
+ var expressionFor = forContent.split(/\s(in)\s/);
151
+ var iterable = expressionFor[expressionFor.length - 1];
152
+ var expressionLeft = expressionFor[0].split(',');
153
+ var itemKey = expressionLeft[0];
154
+ var indexKey = expressionLeft[1];
155
+ var code = '';
156
+ code += "for(let i = 0;i < this?.".concat(iterable, "?.length; i++) {\n");
157
+ code += "this.".concat(itemKey, " = this.").concat(iterable, "[i];\n");
158
+ if (indexKey)
159
+ code += "this.".concat(indexKey, " = i;\n");
160
+ return code;
161
+ }
162
+ function compose(tags) {
163
+ var code = '';
164
+ for (var _i = 0, tags_1 = tags; _i < tags_1.length; _i++) {
165
+ var t = tags_1[_i];
166
+ var type = t.type, content = t.content;
167
+ if (type === 'node') {
168
+ if (t.$if) {
169
+ code += parseIf(t.$if);
170
+ tags[t.endIndex].isIf = true;
171
+ }
172
+ if (t.$for && !t.$disabledFor) {
173
+ code += parseFor(t.$for);
174
+ if (hasSingleTag(t.tag))
175
+ t.isFor = true;
176
+ else
177
+ tags[t.endIndex].isFor = true;
178
+ }
179
+ if (t.$style || t.$class) {
180
+ t.tag = attributeParse(t);
181
+ }
182
+ code += 'html +=`' + t.tag + '`;\n';
183
+ if (t.isFor)
184
+ code += '}\n';
185
+ if (t.isIf)
186
+ code += '}\n';
187
+ }
188
+ else {
189
+ code += 'html +=`' + contentParse(content) + '`;\n';
190
+ }
191
+ }
192
+ return code;
193
+ }
194
+ // 解析模板
195
+ // 1. 解析标签
196
+ // 2. 替换内容
197
+ // 3. 返回渲染结果
198
+ // 4. 处理循环和条件
199
+ // 5. 返回最终的HTML字符串
200
+ // 6. 支持嵌套标签
201
+ // 7. 支持条件渲染
202
+ // 8. 支持循环渲染
203
+ // 9. 支持数据绑定
204
+ // 10. 支持内嵌样式绑定
205
+ // 11. 支持类绑定
206
+ function render(html, context) {
207
+ if (context === void 0) { context = {}; }
208
+ if (!Reflect.ownKeys(context).length)
209
+ return '';
210
+ var tags = resolver(html);
211
+ var code = compose(tags)
212
+ .replaceAll('<annotation>', '<!--')
213
+ .replaceAll('</annotation>', '-->');
214
+ var rendered = new Function("\n let html = '';\n\n ".concat(code, "\n return html;\n\n "));
215
+ return rendered.call(context);
216
+ }
217
+ function replaceElementWithPlaceholder(el, placeholderText) {
218
+ if (placeholderText === void 0) { placeholderText = 'PLACEHOLDER'; }
219
+ var comment = document.createComment(placeholderText);
220
+ el.replaceWith(comment);
221
+ return comment; // 可以用于恢复
222
+ }
223
+ function rebuild(selector, context) {
224
+ var element = document.querySelector(selector);
225
+ if (!element)
226
+ return;
227
+ var outerHTML = element.outerHTML;
228
+ element.setAttribute('hidden', 'true');
229
+ var id = useId();
230
+ replaceElementWithPlaceholder(element, id);
231
+ var newHtml = render(outerHTML, context);
232
+ document.body.innerHTML = document.body.innerHTML.replace("<!--".concat(id, "-->"), newHtml);
233
+ element.setAttribute('hidden', 'false');
234
+ }
235
+
236
+ export { rebuild, render };
@@ -0,0 +1,245 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.r = {}));
5
+ })(this, (function (exports) { 'use strict';
6
+
7
+ var TAG_NAME_REGEX = /<\/?\s*([a-zA-Z][a-zA-Z0-9-]*)\b/; // 获取开始或结束标签的名
8
+ var SINGLE_TAG_REGEX = /<([^\s>]+)/; // 单标签
9
+ var TAG_REGEX = /<\/?[a-z]+[^>]*>|[^<>]+/gi; // 开始和结束标签
10
+ var $FOR_REGEX = /r-for\s*=\s*"([^"]+)"/; //$for 属性值
11
+ var $IF_REGEX = /r-if\s*=\s*"([^"]+)"/; //$if 属性值
12
+ var $STYLE_REGEX = /r-style\s*=\s*"([^"]+)"/; //$style 属性值
13
+ var $CLASS_REGEX = /r-class\s*=\s*"([^"]+)"/; //$class 属性值
14
+ var $ATTRS_REGEX = /\sr-[a-z]\w+\s*=\s*"[^"]*"/g; // 所有$符号的属性
15
+ var $CONTENT_REGEX = /\{\{(.+?)\}\}/g; // $符号内容
16
+ var RELATIONAL_SYMBOLS_REGEX = /<=|>=|\=+|>|</; // 关系符号
17
+ var STR_REGEX = /^("|'|`)(.*)\1$/;
18
+ var CALLBACK_REGEX = /\s*setContent\((.*?)\)\s*/g;
19
+ var FUN_NAME_REGEX = /([a-zA-Z_$][a-zA-Z0-9_$]*)/;
20
+ function useId() {
21
+ return Math.random().toString(36).substring(2, 15);
22
+ }
23
+ function hasSingleTag(tag) {
24
+ var _a;
25
+ return ['img', 'br', 'input'].includes((_a = tag.match(SINGLE_TAG_REGEX)) === null || _a === void 0 ? void 0 : _a[1]);
26
+ }
27
+ function findStartTag(currentIndex, tags) {
28
+ var _a, _b, _c, _d;
29
+ var index = 1;
30
+ var prevTag = tags[currentIndex - index];
31
+ var currentTag = tags[currentIndex];
32
+ var currentTagName = (_b = (_a = currentTag.tag) === null || _a === void 0 ? void 0 : _a.match(TAG_NAME_REGEX)) === null || _b === void 0 ? void 0 : _b[1];
33
+ var prevTagName;
34
+ while (currentTagName !== prevTagName) {
35
+ prevTag = tags[currentIndex - index] || prevTag;
36
+ prevTagName = (_d = (_c = prevTag.tag) === null || _c === void 0 ? void 0 : _c.match(TAG_NAME_REGEX)) === null || _d === void 0 ? void 0 : _d[1];
37
+ index++;
38
+ }
39
+ return prevTag;
40
+ }
41
+ function operatorsParse(content) {
42
+ if (content === void 0) { content = ''; }
43
+ return content.replace('&gt;', '>').replace('&lt;', '<').replaceAll('&amp;', '&');
44
+ }
45
+ function resolver(htmlStr) {
46
+ var _a, _b, _c, _d, _e, _f;
47
+ var tags = [];
48
+ var match;
49
+ var index = 0;
50
+ var annotation = false;
51
+ htmlStr = htmlStr.replace('<!--', '<annotation>').replace('-->', '</annotation>');
52
+ while ((match = TAG_REGEX.exec(htmlStr)) !== null) {
53
+ var tag = match[0].trim();
54
+ if (!tag)
55
+ continue;
56
+ if (tag.startsWith('</')) {
57
+ var item = {
58
+ type: 'node',
59
+ tag: tag,
60
+ };
61
+ if (annotation)
62
+ item.$disabledFor = true;
63
+ if ((_a = item === null || item === void 0 ? void 0 : item.tag) === null || _a === void 0 ? void 0 : _a.includes('</annotation>'))
64
+ annotation = false;
65
+ tags.push(item);
66
+ var prevTag = findStartTag(index, tags);
67
+ prevTag.endIndex = index;
68
+ }
69
+ else if (tag.startsWith('<')) {
70
+ var forMatch = (_b = tag.match($FOR_REGEX)) === null || _b === void 0 ? void 0 : _b[1];
71
+ var ifMatch = (_c = tag.match($IF_REGEX)) === null || _c === void 0 ? void 0 : _c[1];
72
+ var styleMatch = (_d = tag.match($STYLE_REGEX)) === null || _d === void 0 ? void 0 : _d[1];
73
+ var classMatch = (_e = tag.match($CLASS_REGEX)) === null || _e === void 0 ? void 0 : _e[1];
74
+ var item = {
75
+ type: 'node',
76
+ tag: tag.replace($ATTRS_REGEX, '')
77
+ };
78
+ if (forMatch)
79
+ item.$for = forMatch;
80
+ if (ifMatch)
81
+ item.$if = operatorsParse(ifMatch);
82
+ if (styleMatch)
83
+ item.$style = operatorsParse(styleMatch);
84
+ if (classMatch)
85
+ item.$class = operatorsParse(classMatch);
86
+ if ((_f = item === null || item === void 0 ? void 0 : item.tag) === null || _f === void 0 ? void 0 : _f.includes('<annotation>'))
87
+ annotation = true;
88
+ if (annotation)
89
+ item.$disabledFor = true;
90
+ tags.push(item);
91
+ }
92
+ else {
93
+ tags.push({
94
+ type: 'content',
95
+ content: tag,
96
+ });
97
+ }
98
+ index++;
99
+ }
100
+ return tags;
101
+ }
102
+ function callbackParse(content) {
103
+ if (content === void 0) { content = ''; }
104
+ return content.replace(CALLBACK_REGEX, function (_match, args) {
105
+ var _a;
106
+ var newArgs = args.split(',').map(function (arg) {
107
+ if (STR_REGEX.test(arg.trim()))
108
+ return arg;
109
+ return 'this.' + arg.trim();
110
+ });
111
+ var funName = (_a = content.match(FUN_NAME_REGEX)) === null || _a === void 0 ? void 0 : _a[0];
112
+ return "".concat(funName, "(").concat(newArgs, ")");
113
+ });
114
+ }
115
+ function contentParse(content) {
116
+ if (content === void 0) { content = ''; }
117
+ return content.replace($CONTENT_REGEX, function (_match, key) {
118
+ var newKey = callbackParse(key);
119
+ return '${this.' + newKey + '}';
120
+ });
121
+ }
122
+ function parseIf(ifContent) {
123
+ ifContent = ifContent.replace(/^\s*if\s*=\s*/, '');
124
+ var operator = ifContent.match(RELATIONAL_SYMBOLS_REGEX);
125
+ var _a = ifContent.split(RELATIONAL_SYMBOLS_REGEX), left = _a[0], right = _a[1];
126
+ var leftVariable = (STR_REGEX.test(left.trim()) || /\d/.test(left.trim())) ? left.trim() : "this.".concat(left.trim());
127
+ var rightVariable = (STR_REGEX.test(right.trim()) || /\d/.test(right.trim())) ? right.trim() : "this.".concat(right.trim());
128
+ var code = '';
129
+ code += "if(";
130
+ code += "".concat(leftVariable);
131
+ code += "".concat(operator);
132
+ code += "".concat(rightVariable);
133
+ code += ") {\n";
134
+ return code;
135
+ }
136
+ function styleParse(styleContent) {
137
+ var _a;
138
+ var styleValue = contentParse((_a = styleContent.match($CONTENT_REGEX)) === null || _a === void 0 ? void 0 : _a[0]);
139
+ return styleContent.replace($CONTENT_REGEX, styleValue);
140
+ }
141
+ function classParse(classContent) {
142
+ var _a;
143
+ if (classContent === void 0) { classContent = ''; }
144
+ var classValue = contentParse((_a = classContent.match($CONTENT_REGEX)) === null || _a === void 0 ? void 0 : _a[0]);
145
+ return classContent.replace($CONTENT_REGEX, classValue);
146
+ }
147
+ function attributeParse(tagData) {
148
+ var tag = tagData.tag;
149
+ var styleValue = styleParse(tagData.$style || '');
150
+ var classValue = classParse(tagData.$class || '');
151
+ var _style = styleValue ? ' style="' + styleValue + '"' : '';
152
+ var _class = classValue ? ' class="' + classValue + '"' : '';
153
+ return tag.replace('>', _style + _class + '>');
154
+ }
155
+ function parseFor(forContent) {
156
+ var expressionFor = forContent.split(/\s(in)\s/);
157
+ var iterable = expressionFor[expressionFor.length - 1];
158
+ var expressionLeft = expressionFor[0].split(',');
159
+ var itemKey = expressionLeft[0];
160
+ var indexKey = expressionLeft[1];
161
+ var code = '';
162
+ code += "for(let i = 0;i < this?.".concat(iterable, "?.length; i++) {\n");
163
+ code += "this.".concat(itemKey, " = this.").concat(iterable, "[i];\n");
164
+ if (indexKey)
165
+ code += "this.".concat(indexKey, " = i;\n");
166
+ return code;
167
+ }
168
+ function compose(tags) {
169
+ var code = '';
170
+ for (var _i = 0, tags_1 = tags; _i < tags_1.length; _i++) {
171
+ var t = tags_1[_i];
172
+ var type = t.type, content = t.content;
173
+ if (type === 'node') {
174
+ if (t.$if) {
175
+ code += parseIf(t.$if);
176
+ tags[t.endIndex].isIf = true;
177
+ }
178
+ if (t.$for && !t.$disabledFor) {
179
+ code += parseFor(t.$for);
180
+ if (hasSingleTag(t.tag))
181
+ t.isFor = true;
182
+ else
183
+ tags[t.endIndex].isFor = true;
184
+ }
185
+ if (t.$style || t.$class) {
186
+ t.tag = attributeParse(t);
187
+ }
188
+ code += 'html +=`' + t.tag + '`;\n';
189
+ if (t.isFor)
190
+ code += '}\n';
191
+ if (t.isIf)
192
+ code += '}\n';
193
+ }
194
+ else {
195
+ code += 'html +=`' + contentParse(content) + '`;\n';
196
+ }
197
+ }
198
+ return code;
199
+ }
200
+ // 解析模板
201
+ // 1. 解析标签
202
+ // 2. 替换内容
203
+ // 3. 返回渲染结果
204
+ // 4. 处理循环和条件
205
+ // 5. 返回最终的HTML字符串
206
+ // 6. 支持嵌套标签
207
+ // 7. 支持条件渲染
208
+ // 8. 支持循环渲染
209
+ // 9. 支持数据绑定
210
+ // 10. 支持内嵌样式绑定
211
+ // 11. 支持类绑定
212
+ function render(html, context) {
213
+ if (context === void 0) { context = {}; }
214
+ if (!Reflect.ownKeys(context).length)
215
+ return '';
216
+ var tags = resolver(html);
217
+ var code = compose(tags)
218
+ .replaceAll('<annotation>', '<!--')
219
+ .replaceAll('</annotation>', '-->');
220
+ var rendered = new Function("\n let html = '';\n\n ".concat(code, "\n return html;\n\n "));
221
+ return rendered.call(context);
222
+ }
223
+ function replaceElementWithPlaceholder(el, placeholderText) {
224
+ if (placeholderText === void 0) { placeholderText = 'PLACEHOLDER'; }
225
+ var comment = document.createComment(placeholderText);
226
+ el.replaceWith(comment);
227
+ return comment; // 可以用于恢复
228
+ }
229
+ function rebuild(selector, context) {
230
+ var element = document.querySelector(selector);
231
+ if (!element)
232
+ return;
233
+ var outerHTML = element.outerHTML;
234
+ element.setAttribute('hidden', 'true');
235
+ var id = useId();
236
+ replaceElementWithPlaceholder(element, id);
237
+ var newHtml = render(outerHTML, context);
238
+ document.body.innerHTML = document.body.innerHTML.replace("<!--".concat(id, "-->"), newHtml);
239
+ element.setAttribute('hidden', 'false');
240
+ }
241
+
242
+ exports.rebuild = rebuild;
243
+ exports.render = render;
244
+
245
+ }));
@@ -0,0 +1,61 @@
1
+ export declare enum READY_STATE {
2
+ UNSENT = 0,
3
+ OPENED = 1,
4
+ HEADERS_RECEIVED = 2,
5
+ LOADING = 3,
6
+ DONE = 4
7
+ }
8
+ export declare enum STATUS_CODE {
9
+ OK = 200,
10
+ CREATED = 201,
11
+ ACCEPTED = 202,
12
+ NO_CONTENT = 204,
13
+ MOVED_PERMANENTLY = 301,
14
+ FOUND = 302,
15
+ NOT_MODIFIED = 304,
16
+ BAD_REQUEST = 400,
17
+ UNAUTHORIZED = 401,
18
+ FORBIDDEN = 403,
19
+ NOT_FOUND = 404,
20
+ INTERNAL_SERVER_ERROR = 500,
21
+ SERVICE_UNAVAILABLE = 503,
22
+ GATEWAY_TIMEOUT = 504
23
+ }
24
+ export declare enum HTTP_STATUS_MESSAGE {
25
+ OK = "\u8BF7\u6C42\u6210\u529F",
26
+ CREATED = "\u521B\u5EFA\u6210\u529F",
27
+ ACCEPTED = "\u5DF2\u63A5\u6536",
28
+ NO_CONTENT = "\u65E0\u5185\u5BB9",
29
+ MOVED_PERMANENTLY = "\u5DF2\u6C38\u4E45\u79FB\u52A8",
30
+ FOUND = "\u5DF2\u627E\u5230",
31
+ NOT_MODIFIED = "\u672A\u4FEE\u6539",
32
+ BAD_REQUEST = "\u8BF7\u6C42\u9519\u8BEF",
33
+ UNAUTHORIZED = "\u672A\u6388\u6743",
34
+ FORBIDDEN = "\u7981\u6B62\u8BBF\u95EE",
35
+ NOT_FOUND = "\u672A\u627E\u5230",
36
+ INTERNAL_SERVER_ERROR = "\u670D\u52A1\u5668\u9519\u8BEF",
37
+ SERVICE_UNAVAILABLE = "\u670D\u52A1\u4E0D\u53EF\u7528",
38
+ GATEWAY_TIMEOUT = "\u7F51\u5173\u8D85\u65F6"
39
+ }
40
+ export declare enum HTTP_METHOD {
41
+ GET = "GET",
42
+ POST = "POST",
43
+ PUT = "PUT",
44
+ DELETE = "DELETE"
45
+ }
46
+ export declare enum HTTP_HEADER {
47
+ CONTENT_TYPE = "Content-Type",
48
+ ACCEPT = "Accept",
49
+ AUTHORIZATION = "Authorization"
50
+ }
51
+ export declare enum HTTP_CONTENT_TYPE {
52
+ JSON = "application/json",
53
+ FORM_URLENCODED = "application/x-www-form-urlencoded",
54
+ MULTIPART_FORM_DATA = "multipart/form-data"
55
+ }
56
+ export declare enum HTTP_STATUS {
57
+ OK = 200,
58
+ CREATED = 201,
59
+ ACCEPTED = 202,
60
+ NO_CONTENT = 204
61
+ }
@@ -0,0 +1,23 @@
1
+ export declare enum RecordType {
2
+ AUDIO = "audio",
3
+ VIDEO = "video",
4
+ SCREEN = "screen"
5
+ }
6
+ export declare enum LOGIN_TYPE {
7
+ CODE = "CODE",
8
+ ACCOUNT = "ACCOUNT"
9
+ }
10
+ export declare enum LENGTH_LIMIT {
11
+ MIN_11 = 11,
12
+ MAX_11 = 11,
13
+ MIN_18 = 18,
14
+ MAX_18 = 18,
15
+ MIN_15 = 15,
16
+ MAX_15 = 15
17
+ }
18
+ export declare enum HAS_FEILD {
19
+ LABEL = "label",
20
+ VALUE = "value",
21
+ CHILDREN = "children",
22
+ LEAF = "leaf"
23
+ }
@@ -1,3 +1,4 @@
1
- export * from './uilts/index';
2
- export * from './enums/index.enum';
3
- export * from './types/index.interface';
1
+ export * from './utils';
2
+ export * from './enums';
3
+ export * from './types';
4
+ export * from './reg-exp';
@@ -0,0 +1,12 @@
1
+ /**
2
+ * 匹配中文字母数字
3
+ */
4
+ export declare const ZN_LETTER_NUMBER: RegExp;
5
+ /**
6
+ * 匹配 IP
7
+ */
8
+ export declare const IP: RegExp;
9
+ /**
10
+ * 匹配手机号
11
+ */
12
+ export declare const PHONE: RegExp;
@@ -0,0 +1,16 @@
1
+ export type RequestOptions = {
2
+ data?: Document | XMLHttpRequestBodyInit | null;
3
+ headers?: {
4
+ [key: string]: string;
5
+ };
6
+ async?: boolean;
7
+ };
8
+ export type RequestType = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'OPTIONS' | 'HEAD' | 'TRACE' | 'CONNECT';
9
+ export type RequestHeader = {
10
+ [key: string]: string;
11
+ };
12
+ export type RequestResponse = {
13
+ data: any;
14
+ code: number;
15
+ message: string;
16
+ };
@@ -0,0 +1,32 @@
1
+ export interface Tag {
2
+ type: 'node' | 'content';
3
+ tag?: string;
4
+ content?: string;
5
+ endIndex?: number;
6
+ $for?: string;
7
+ $if?: string;
8
+ $style?: string;
9
+ $class?: string;
10
+ $disabledFor?: boolean;
11
+ }
12
+ export type typeIsNull = string | number | boolean | null | undefined;
13
+ export interface ISectoralTable {
14
+ address: string;
15
+ appletQr: string;
16
+ hasChildren?: boolean;
17
+ cldOrgDepts?: ISectoralTable[];
18
+ deptAlias: string;
19
+ initialPinyin: string;
20
+ deptCode: string;
21
+ deptName: string;
22
+ email: string;
23
+ leader: string;
24
+ mark: string;
25
+ officialQr: string;
26
+ orgCode: string;
27
+ parentCode: string;
28
+ phone: string;
29
+ pk: string;
30
+ sort: number;
31
+ status: number;
32
+ }