@lightsoft/js-sdk 1.0.1 → 1.1.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.
package/dist/index.umd.js CHANGED
@@ -1,246 +1,345 @@
1
1
  (function (global, factory) {
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue')) :
3
3
  typeof define === 'function' && define.amd ? define(['exports', 'vue'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.s = {}, global.vue));
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.s = {}, global.Vue));
5
5
  })(this, (function (exports, vue) { 'use strict';
6
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++;
7
+ /******************************************************************************
8
+ Copyright (c) Microsoft Corporation.
9
+
10
+ Permission to use, copy, modify, and/or distribute this software for any
11
+ purpose with or without fee is hereby granted.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
14
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
16
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
18
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19
+ PERFORMANCE OF THIS SOFTWARE.
20
+ ***************************************************************************** */
21
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
22
+
23
+
24
+ var __assign = function() {
25
+ __assign = Object.assign || function __assign(t) {
26
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
27
+ s = arguments[i];
28
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
29
+ }
30
+ return t;
31
+ };
32
+ return __assign.apply(this, arguments);
33
+ };
34
+
35
+ function __awaiter(thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ }
44
+
45
+ function __generator(thisArg, body) {
46
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
47
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
48
+ function verb(n) { return function (v) { return step([n, v]); }; }
49
+ function step(op) {
50
+ if (f) throw new TypeError("Generator is already executing.");
51
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
52
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
53
+ if (y = 0, t) op = [op[0] & 2, t.value];
54
+ switch (op[0]) {
55
+ case 0: case 1: t = op; break;
56
+ case 4: _.label++; return { value: op[1], done: false };
57
+ case 5: _.label++; y = op[1]; op = [0]; continue;
58
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
59
+ default:
60
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
61
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
62
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
63
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
64
+ if (t[2]) _.ops.pop();
65
+ _.trys.pop(); continue;
66
+ }
67
+ op = body.call(thisArg, _);
68
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
69
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
70
+ }
71
+ }
72
+
73
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
74
+ var e = new Error(message);
75
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
76
+ };
77
+
78
+ var READY_STATE;
79
+ (function (READY_STATE) {
80
+ // 未初始化
81
+ READY_STATE[READY_STATE["UNSENT"] = 0] = "UNSENT";
82
+ // 已打开
83
+ READY_STATE[READY_STATE["OPENED"] = 1] = "OPENED";
84
+ // 已获取响应头
85
+ READY_STATE[READY_STATE["HEADERS_RECEIVED"] = 2] = "HEADERS_RECEIVED";
86
+ // 已加载响应体
87
+ READY_STATE[READY_STATE["LOADING"] = 3] = "LOADING";
88
+ // 已完成
89
+ READY_STATE[READY_STATE["DONE"] = 4] = "DONE";
90
+ })(READY_STATE || (READY_STATE = {}));
91
+ var STATUS_CODE;
92
+ (function (STATUS_CODE) {
93
+ // 2xx 成功
94
+ STATUS_CODE[STATUS_CODE["OK"] = 200] = "OK";
95
+ STATUS_CODE[STATUS_CODE["CREATED"] = 201] = "CREATED";
96
+ STATUS_CODE[STATUS_CODE["ACCEPTED"] = 202] = "ACCEPTED";
97
+ STATUS_CODE[STATUS_CODE["NO_CONTENT"] = 204] = "NO_CONTENT";
98
+ // 3xx 重定向
99
+ STATUS_CODE[STATUS_CODE["MOVED_PERMANENTLY"] = 301] = "MOVED_PERMANENTLY";
100
+ STATUS_CODE[STATUS_CODE["FOUND"] = 302] = "FOUND";
101
+ STATUS_CODE[STATUS_CODE["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
102
+ // 4xx 客户端错误
103
+ STATUS_CODE[STATUS_CODE["BAD_REQUEST"] = 400] = "BAD_REQUEST";
104
+ STATUS_CODE[STATUS_CODE["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
105
+ STATUS_CODE[STATUS_CODE["FORBIDDEN"] = 403] = "FORBIDDEN";
106
+ STATUS_CODE[STATUS_CODE["NOT_FOUND"] = 404] = "NOT_FOUND";
107
+ // 5xx 服务器错误
108
+ STATUS_CODE[STATUS_CODE["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
109
+ STATUS_CODE[STATUS_CODE["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
110
+ STATUS_CODE[STATUS_CODE["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
111
+ })(STATUS_CODE || (STATUS_CODE = {}));
112
+ var HTTP_STATUS_MESSAGE;
113
+ (function (HTTP_STATUS_MESSAGE) {
114
+ // 2xx 成功
115
+ HTTP_STATUS_MESSAGE["OK"] = "\u8BF7\u6C42\u6210\u529F";
116
+ HTTP_STATUS_MESSAGE["CREATED"] = "\u521B\u5EFA\u6210\u529F";
117
+ HTTP_STATUS_MESSAGE["ACCEPTED"] = "\u5DF2\u63A5\u6536";
118
+ HTTP_STATUS_MESSAGE["NO_CONTENT"] = "\u65E0\u5185\u5BB9";
119
+ // 3xx 重定向
120
+ HTTP_STATUS_MESSAGE["MOVED_PERMANENTLY"] = "\u5DF2\u6C38\u4E45\u79FB\u52A8";
121
+ HTTP_STATUS_MESSAGE["FOUND"] = "\u5DF2\u627E\u5230";
122
+ HTTP_STATUS_MESSAGE["NOT_MODIFIED"] = "\u672A\u4FEE\u6539";
123
+ // 4xx 客户端错误
124
+ HTTP_STATUS_MESSAGE["BAD_REQUEST"] = "\u8BF7\u6C42\u9519\u8BEF";
125
+ HTTP_STATUS_MESSAGE["UNAUTHORIZED"] = "\u672A\u6388\u6743";
126
+ HTTP_STATUS_MESSAGE["FORBIDDEN"] = "\u7981\u6B62\u8BBF\u95EE";
127
+ HTTP_STATUS_MESSAGE["NOT_FOUND"] = "\u672A\u627E\u5230";
128
+ // 5xx 服务器错误
129
+ HTTP_STATUS_MESSAGE["INTERNAL_SERVER_ERROR"] = "\u670D\u52A1\u5668\u9519\u8BEF";
130
+ HTTP_STATUS_MESSAGE["SERVICE_UNAVAILABLE"] = "\u670D\u52A1\u4E0D\u53EF\u7528";
131
+ HTTP_STATUS_MESSAGE["GATEWAY_TIMEOUT"] = "\u7F51\u5173\u8D85\u65F6";
132
+ })(HTTP_STATUS_MESSAGE || (HTTP_STATUS_MESSAGE = {}));
133
+ var HTTP_METHOD;
134
+ (function (HTTP_METHOD) {
135
+ HTTP_METHOD["GET"] = "GET";
136
+ HTTP_METHOD["POST"] = "POST";
137
+ HTTP_METHOD["PUT"] = "PUT";
138
+ HTTP_METHOD["DELETE"] = "DELETE";
139
+ })(HTTP_METHOD || (HTTP_METHOD = {}));
140
+ var HTTP_HEADER;
141
+ (function (HTTP_HEADER) {
142
+ HTTP_HEADER["CONTENT_TYPE"] = "Content-Type";
143
+ HTTP_HEADER["ACCEPT"] = "Accept";
144
+ HTTP_HEADER["AUTHORIZATION"] = "Authorization";
145
+ })(HTTP_HEADER || (HTTP_HEADER = {}));
146
+ var HTTP_CONTENT_TYPE;
147
+ (function (HTTP_CONTENT_TYPE) {
148
+ HTTP_CONTENT_TYPE["JSON"] = "application/json";
149
+ HTTP_CONTENT_TYPE["FORM_URLENCODED"] = "application/x-www-form-urlencoded";
150
+ HTTP_CONTENT_TYPE["MULTIPART_FORM_DATA"] = "multipart/form-data";
151
+ })(HTTP_CONTENT_TYPE || (HTTP_CONTENT_TYPE = {}));
152
+ var HTTP_STATUS;
153
+ (function (HTTP_STATUS) {
154
+ HTTP_STATUS[HTTP_STATUS["OK"] = 200] = "OK";
155
+ HTTP_STATUS[HTTP_STATUS["CREATED"] = 201] = "CREATED";
156
+ HTTP_STATUS[HTTP_STATUS["ACCEPTED"] = 202] = "ACCEPTED";
157
+ HTTP_STATUS[HTTP_STATUS["NO_CONTENT"] = 204] = "NO_CONTENT";
158
+ })(HTTP_STATUS || (HTTP_STATUS = {}));
159
+
160
+ var Request = /** @class */ (function () {
161
+ function Request() {
162
+ this.beforeRequestOptions = {};
163
+ this.xhr = this.create();
38
164
  }
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);
165
+ Request.prototype.create = function () {
166
+ if (window.XMLHttpRequest)
167
+ return new XMLHttpRequest();
168
+ else if (window.ActiveXObject)
169
+ return new ActiveXObject('Microsoft.XMLHTTP');
170
+ throw new Error('您的浏览器暂不支持XMLHttpRequest');
171
+ };
172
+ Request.prototype.useState = function (state) {
173
+ switch (state) {
174
+ case 'SUCCESS':
175
+ return this.xhr.readyState === READY_STATE.DONE && this.xhr.status >= 200 && this.xhr.status < 300;
176
+ case 'FAIL':
177
+ return this.xhr.readyState === READY_STATE.DONE && (this.xhr.status < 200 || this.xhr.status >= 300);
178
+ case 'PENDING':
179
+ return this.xhr.readyState < READY_STATE.DONE;
180
+ default:
181
+ return false;
91
182
  }
92
- else {
93
- tags.push({
94
- type: 'content',
95
- content: tag,
183
+ };
184
+ Request.prototype.send = function (type, url, options) {
185
+ if (options === void 0) { options = {}; }
186
+ var _a = this, xhr = _a.xhr, beforeRequestOptions = _a.beforeRequestOptions, beforeResponseCallback = _a.beforeResponseCallback;
187
+ var useState = this.useState.bind(this);
188
+ var transformResponse = this.transformResponse.bind(this);
189
+ return new Promise(function (resolve, reject) {
190
+ xhr.open(type, url, options.async || true);
191
+ var requestOptions = __assign(__assign({}, beforeRequestOptions), options);
192
+ Object.keys(requestOptions.headers || {}).forEach(function (key) {
193
+ var _a;
194
+ xhr.setRequestHeader(key, (_a = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers) === null || _a === void 0 ? void 0 : _a[key]);
96
195
  });
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 (this['".concat(itemKey, "'] of this.").concat(iterable, " || []) {\n");
163
- if (indexKey)
164
- code += "this.".concat(indexKey, " = this.").concat(iterable, ".indexOf(this.").concat(itemKey, ");\n");
165
- return code;
166
- }
167
- function compose(tags) {
168
- var code = '';
169
- for (var _i = 0, tags_1 = tags; _i < tags_1.length; _i++) {
170
- var t = tags_1[_i];
171
- var type = t.type, content = t.content;
172
- if (type === 'node') {
173
- if (t.$if) {
174
- code += parseIf(t.$if);
175
- tags[t.endIndex].isIf = true;
196
+ xhr.onreadystatechange = function () {
197
+ var success = useState('SUCCESS');
198
+ var fail = useState('FAIL');
199
+ if (success) {
200
+ beforeResponseCallback
201
+ ? beforeResponseCallback(transformResponse(xhr), resolve, reject)
202
+ : resolve(transformResponse(xhr));
203
+ }
204
+ else if (fail) {
205
+ reject(transformResponse(xhr));
206
+ }
207
+ };
208
+ xhr.onerror = function () {
209
+ reject(transformResponse(xhr));
210
+ };
211
+ if (options.data instanceof FormData) {
212
+ xhr.send(options.data);
176
213
  }
177
- if (t.$for && !t.$disabledFor) {
178
- code += parseFor(t.$for);
179
- if (hasSingleTag(t.tag))
180
- t.isFor = true;
181
- else
182
- tags[t.endIndex].isFor = true;
214
+ else if (type === 'POST' || type === 'PUT') {
215
+ xhr.send(JSON.stringify(options.data));
183
216
  }
184
- if (t.$style || t.$class) {
185
- t.tag = attributeParse(t);
217
+ else {
218
+ xhr.send();
186
219
  }
187
- code += 'html +=`' + t.tag + '`;\n';
188
- if (t.isFor)
189
- code += '}\n';
190
- if (t.isIf)
191
- code += '}\n';
220
+ });
221
+ };
222
+ Request.prototype.transformResponse = function (response) {
223
+ return {
224
+ data: JSON.parse(response.responseText),
225
+ code: response.status,
226
+ message: response.statusText,
227
+ };
228
+ };
229
+ Request.prototype.transformQuery = function (url, query) {
230
+ var queryData = Object.keys(query || {});
231
+ if (!queryData.length)
232
+ return url;
233
+ var queryString = queryData.map(function (key) {
234
+ return window.encodeURIComponent(key) + '=' + window.encodeURIComponent(query[key]);
235
+ }).join('&');
236
+ url += (url.includes('?') ? '&' : '?') + queryString;
237
+ return url;
238
+ };
239
+ Request.prototype.beforeSend = function (callback) {
240
+ this.beforeRequestOptions = callback();
241
+ };
242
+ Request.prototype.beforeResponse = function (callback) {
243
+ this.beforeResponseCallback = callback;
244
+ };
245
+ Request.prototype.abort = function () {
246
+ this.xhr.abort();
247
+ };
248
+ Request.prototype.get = function (url, query, headers) {
249
+ if (headers === void 0) { headers = {}; }
250
+ var newUrl = this.transformQuery(url, query);
251
+ return this.send('GET', newUrl, { headers: headers });
252
+ };
253
+ Request.prototype.post = function (url, data, headers) {
254
+ if (headers === void 0) { headers = {}; }
255
+ return this.send('POST', url, { data: data, headers: headers });
256
+ };
257
+ Request.prototype.put = function (url, data, headers) {
258
+ if (headers === void 0) { headers = {}; }
259
+ return this.send('PUT', url, { data: data, headers: headers });
260
+ };
261
+ Request.prototype.delete = function (url, data, headers) {
262
+ if (headers === void 0) { headers = {}; }
263
+ return this.send('DELETE', url, { data: data, headers: headers });
264
+ };
265
+ Request.prototype.patch = function (url, data, headers) {
266
+ if (headers === void 0) { headers = {}; }
267
+ return this.send('PATCH', url, { data: data, headers: headers });
268
+ };
269
+ Request.prototype.options = function (url, data, headers) {
270
+ if (headers === void 0) { headers = {}; }
271
+ return this.send('OPTIONS', url, { data: data, headers: headers });
272
+ };
273
+ Request.prototype.head = function (url, data, headers) {
274
+ if (headers === void 0) { headers = {}; }
275
+ return this.send('HEAD', url, { data: data, headers: headers });
276
+ };
277
+ Request.prototype.trace = function (url, data, headers) {
278
+ if (headers === void 0) { headers = {}; }
279
+ return this.send('TRACE', url, { data: data, headers: headers });
280
+ };
281
+ Request.prototype.connect = function (url, data, headers) {
282
+ if (headers === void 0) { headers = {}; }
283
+ return this.send('CONNECT', url, { data: data, headers: headers });
284
+ };
285
+ return Request;
286
+ }());
287
+ var RequestChain = /** @class */ (function () {
288
+ function RequestChain() {
289
+ var args = [];
290
+ for (var _i = 0; _i < arguments.length; _i++) {
291
+ args[_i] = arguments[_i];
292
+ }
293
+ this.fieldList = [{}];
294
+ this.responses = [];
295
+ this.setParams.apply(this, args);
296
+ }
297
+ RequestChain.prototype.getParams = function (type, data, fields) {
298
+ var keys = Object.keys(fields);
299
+ var values = Object.values(fields);
300
+ if (type === 'query') {
301
+ var query = keys.map(function (key, index) {
302
+ return "".concat(key, "=").concat(data[values[index]]);
303
+ }).join('&');
304
+ return query;
192
305
  }
193
306
  else {
194
- code += 'html +=`' + contentParse(content) + '`;\n';
307
+ var body_1 = {};
308
+ keys.forEach(function (key, index) {
309
+ body_1[key] = data[values[index]];
310
+ });
311
+ return body_1;
195
312
  }
196
- }
197
- return code;
198
- }
199
- // 解析模板
200
- // 1. 解析标签
201
- // 2. 替换内容
202
- // 3. 返回渲染结果
203
- // 4. 处理循环和条件
204
- // 5. 返回最终的HTML字符串
205
- // 6. 支持嵌套标签
206
- // 7. 支持条件渲染
207
- // 8. 支持循环渲染
208
- // 9. 支持数据绑定
209
- // 10. 支持内嵌样式绑定
210
- // 11. 支持类绑定
211
- function render(html, context) {
212
- if (context === void 0) { context = {}; }
213
- if (!Reflect.ownKeys(context).length)
214
- return '';
215
- var tags = resolver(html);
216
- var code = compose(tags)
217
- .replaceAll('<annotation>', '<!--')
218
- .replaceAll('</annotation>', '-->');
219
- var renderedContent = new Function("\n let html = ''\n;\n ".concat(code, "\n return html;\n\n "));
220
- return renderedContent.call(context);
221
- }
222
- function replaceElementWithPlaceholder(el, placeholderText) {
223
- if (placeholderText === void 0) { placeholderText = 'PLACEHOLDER'; }
224
- var comment = document.createComment(placeholderText);
225
- el.replaceWith(comment);
226
- return comment; // 可以用于恢复
227
- }
228
- function rebuild(selector, context) {
229
- var element = document.querySelector(selector);
230
- if (!element)
231
- return;
232
- var outerHTML = element.outerHTML;
233
- element.setAttribute('hidden', 'true');
234
- var id = useId();
235
- replaceElementWithPlaceholder(element, id);
236
- var newHtml = render(outerHTML, context);
237
- document.body.innerHTML = document.body.innerHTML.replace("<!--".concat(id, "-->"), newHtml);
238
- element.setAttribute('hidden', 'false');
239
- }
240
- window.s = {
241
- rebuild: rebuild,
242
- render: render
243
- };
313
+ };
314
+ RequestChain.prototype.setParams = function () {
315
+ var args = [];
316
+ for (var _i = 0; _i < arguments.length; _i++) {
317
+ args[_i] = arguments[_i];
318
+ }
319
+ for (var i = 0; i < args.length; i++) {
320
+ var arg = args[i];
321
+ this.fieldList.push(arg);
322
+ }
323
+ };
324
+ RequestChain.prototype.chain = function (list) {
325
+ var _this = this;
326
+ return list.reduce(function (pre, cur, index) {
327
+ return new Promise(function (resolve, reject) {
328
+ pre().then(function (preRes) {
329
+ var fields = _this.fieldList[index];
330
+ var type = (fields === null || fields === void 0 ? void 0 : fields.query) ? 'query' : 'body';
331
+ var params = _this.getParams(type, preRes, (fields === null || fields === void 0 ? void 0 : fields.query) || fields);
332
+ _this.responses.push(preRes);
333
+ cur(params).then(function (curRes) {
334
+ _this.responses.push(curRes);
335
+ resolve(_this.responses);
336
+ });
337
+ });
338
+ });
339
+ });
340
+ };
341
+ return RequestChain;
342
+ }());
244
343
 
245
344
  /**
246
345
  *
@@ -253,10 +352,10 @@
253
352
  if (text === void 0) { text = '发送验证码'; }
254
353
  var countdownNum = vue.ref(num);
255
354
  var countdownText = vue.ref(text);
256
- var isDisabled = vue.ref(false);
355
+ var disabled = vue.ref(false);
257
356
  var send = function () {
258
357
  countdownText.value = "".concat(countdownNum.value, "s");
259
- isDisabled.value = true;
358
+ disabled.value = true;
260
359
  var timer = setInterval(function () {
261
360
  countdownNum.value--;
262
361
  countdownText.value = "".concat(countdownNum.value, "s");
@@ -264,46 +363,13 @@
264
363
  clearInterval(timer);
265
364
  countdownNum.value = num;
266
365
  countdownText.value = text;
267
- isDisabled.value = false;
366
+ disabled.value = false;
268
367
  }
269
368
  }, 1000);
270
369
  };
271
- return { countdownText: countdownText, isDisabled: isDisabled, send: send };
370
+ return { countdownText: countdownText, disabled: disabled, send: send };
272
371
  }
273
372
 
274
- /******************************************************************************
275
- Copyright (c) Microsoft Corporation.
276
-
277
- Permission to use, copy, modify, and/or distribute this software for any
278
- purpose with or without fee is hereby granted.
279
-
280
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
281
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
282
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
283
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
284
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
285
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
286
- PERFORMANCE OF THIS SOFTWARE.
287
- ***************************************************************************** */
288
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
289
-
290
-
291
- var __assign = function() {
292
- __assign = Object.assign || function __assign(t) {
293
- for (var s, i = 1, n = arguments.length; i < n; i++) {
294
- s = arguments[i];
295
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
296
- }
297
- return t;
298
- };
299
- return __assign.apply(this, arguments);
300
- };
301
-
302
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
303
- var e = new Error(message);
304
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
305
- };
306
-
307
373
  exports.RecordType = void 0;
308
374
  (function (RecordType) {
309
375
  RecordType["AUDIO"] = "audio";
@@ -612,17 +678,293 @@
612
678
  }
613
679
  }
614
680
 
681
+ var Mask = /** @class */ (function () {
682
+ function Mask(selectors, opacity) {
683
+ if (opacity === void 0) { opacity = 0.3; }
684
+ this.task = [];
685
+ this.selectors = [];
686
+ this.opacity = 0.3;
687
+ this.elementIndex = 0;
688
+ this.selectors = selectors;
689
+ this.opacity = opacity;
690
+ }
691
+ Mask.prototype.start = function () {
692
+ var _this = this;
693
+ this.task.reduce(function (pre, cur, index) { return __awaiter(_this, void 0, void 0, function () {
694
+ return __generator(this, function (_a) {
695
+ switch (_a.label) {
696
+ case 0: return [4 /*yield*/, pre];
697
+ case 1:
698
+ _a.sent();
699
+ return [4 /*yield*/, new Promise(function (resolve) {
700
+ cur.callback(resolve, index);
701
+ })];
702
+ case 2:
703
+ _a.sent();
704
+ this.close();
705
+ return [2 /*return*/];
706
+ }
707
+ });
708
+ }); }, Promise.resolve());
709
+ };
710
+ Mask.prototype.process = function (handle) {
711
+ var _this = this;
712
+ this.task.push({
713
+ callback: function (resolve, index) {
714
+ _this.elementIndex = index;
715
+ _this.open();
716
+ handle(resolve, index, document.querySelector(_this.selectors[index]));
717
+ }
718
+ });
719
+ return this;
720
+ };
721
+ Mask.prototype.open = function (element) {
722
+ if ((element === null || element === void 0 ? void 0 : element.nodeType) === Node.ELEMENT_NODE)
723
+ this.selectors.push(element);
724
+ var currentElement = document.querySelector(this.selectors[this.elementIndex]);
725
+ if (!currentElement)
726
+ return;
727
+ currentElement.style.position = 'relative';
728
+ currentElement.style.boxShadow = "1px 1px 0 100vw rgba(0, 0, 0, ".concat(this.opacity, ")");
729
+ };
730
+ Mask.prototype.close = function () {
731
+ var currentElement = document.querySelector(this.selectors[this.elementIndex]);
732
+ currentElement.style.removeProperty('position');
733
+ currentElement.style.removeProperty('box-shadow');
734
+ };
735
+ return Mask;
736
+ }());
737
+
738
+ var Tour = /** @class */ (function () {
739
+ function Tour(selectors) {
740
+ this.selectors = [];
741
+ this.elementIndex = 0;
742
+ this.tourTargetElement = null;
743
+ this.tourElement = null;
744
+ this.tourElementContentTemplate = "\n <style>\n .tour-content-title {\n font-size: 16px;\n font-weight: 500;\n }\n\n .tour-buttons {\n display: flex;\n justify-content: end;\n margin-top: 14px;\n }\n\n .tour-prev, .tour-next {\n padding: 4px;\n min-width: 40px;\n text-align: center;\n border: 1px solid #000;\n border-radius: 4px;\n cursor: pointer;\n }\n\n .tour-next {\n margin-left: 6px;\n }\n </style>\n <div class=\"tour-content\">\n <p class=\"tour-content-title\">\n <$title>\n </p>\n <p class=\"tour-content-text\">\n <$text>\n </p>\n </div>\n <div class=\"tour-buttons\">\n <div class=\"tour-prev\">prev</div>\n <div class=\"tour-next\"><$next></div>\n </div>\n ";
745
+ this.placeholder = {
746
+ title: '<$title>',
747
+ text: '<$text>',
748
+ next: '<$next>',
749
+ };
750
+ this.config = {
751
+ prev: '.tour-prev',
752
+ next: '.tour-next',
753
+ nextText: 'next',
754
+ closeText: 'close',
755
+ };
756
+ this.selectors = selectors;
757
+ this.tourTargetElement = document.createElement('div');
758
+ this.tourElement = document.createElement('div');
759
+ }
760
+ Tour.prototype.setPlaceholder = function (placeholder) {
761
+ this.placeholder = placeholder;
762
+ };
763
+ Tour.prototype.setContentTemplate = function (template) {
764
+ this.tourElementContentTemplate = template;
765
+ };
766
+ Tour.prototype.setConfig = function (config) {
767
+ this.config = __assign(__assign({}, this.config), config);
768
+ };
769
+ Tour.prototype.start = function () {
770
+ var elementName = this.selectors[this.elementIndex].el;
771
+ var element = document.querySelector(elementName);
772
+ if (element instanceof HTMLElement)
773
+ this.layout(element);
774
+ };
775
+ Tour.prototype.layout = function (element) {
776
+ var _this = this;
777
+ var rect = element === null || element === void 0 ? void 0 : element.getBoundingClientRect();
778
+ var tourTargetElement = this.tourTargetElement;
779
+ var tourElement = this.tourElement;
780
+ if (!tourTargetElement || !tourElement)
781
+ return;
782
+ tourTargetElement.style.padding = '4px';
783
+ tourTargetElement.style.position = 'fixed';
784
+ tourTargetElement.style.top = "".concat((rect === null || rect === void 0 ? void 0 : rect.top) - 4, "px");
785
+ tourTargetElement.style.left = "".concat((rect === null || rect === void 0 ? void 0 : rect.left) - 4, "px");
786
+ tourTargetElement.style.width = "".concat(rect === null || rect === void 0 ? void 0 : rect.width, "px");
787
+ tourTargetElement.style.height = "".concat(rect === null || rect === void 0 ? void 0 : rect.height, "px");
788
+ tourTargetElement.style.zIndex = '60';
789
+ tourTargetElement.style.boxShadow = "1px 1px 0 1000vw rgba(0, 0, 0, 0.3)";
790
+ document.body.appendChild(tourTargetElement);
791
+ tourElement.style.padding = '16px';
792
+ tourElement.style.position = 'fixed';
793
+ tourElement.style.width = "200px";
794
+ tourElement.style.backgroundColor = '#fff';
795
+ tourElement.style.borderRadius = '4px';
796
+ tourElement.style.zIndex = '62';
797
+ tourElement.innerHTML = this.tourElementContentTemplate
798
+ .replace(this.placeholder.title, this.selectors[this.elementIndex].title)
799
+ .replace(this.placeholder.text, this.selectors[this.elementIndex].text)
800
+ .replace(this.placeholder.next, this.elementIndex === this.selectors.length - 1 ? this.config.closeText : this.config.nextText);
801
+ var prevButton = tourElement.querySelector(this.config.prev);
802
+ var nextButton = tourElement.querySelector(this.config.next);
803
+ prevButton === null || prevButton === void 0 ? void 0 : prevButton.addEventListener('click', function () {
804
+ _this.elementIndex--;
805
+ if (_this.elementIndex < 0)
806
+ _this.elementIndex = _this.selectors.length - 1;
807
+ _this.start();
808
+ });
809
+ nextButton === null || nextButton === void 0 ? void 0 : nextButton.addEventListener('click', function () {
810
+ _this.elementIndex++;
811
+ if (_this.elementIndex > _this.selectors.length - 1) {
812
+ _this.elementIndex = 0;
813
+ _this.close();
814
+ return;
815
+ }
816
+ _this.start();
817
+ });
818
+ document.body.appendChild(tourElement);
819
+ if (rect.bottom + 14 + tourElement.offsetHeight >= document.documentElement.clientHeight)
820
+ tourElement.style.top = "".concat((rect === null || rect === void 0 ? void 0 : rect.top) - tourElement.offsetHeight - 14, "px");
821
+ else
822
+ tourElement.style.top = "".concat((rect === null || rect === void 0 ? void 0 : rect.bottom) + 14, "px");
823
+ if (rect.left + tourElement.offsetWidth >= document.documentElement.clientWidth)
824
+ tourElement.style.left = "".concat((rect === null || rect === void 0 ? void 0 : rect.left) - tourElement.offsetWidth - 14, "px");
825
+ else
826
+ tourElement.style.left = "".concat((rect === null || rect === void 0 ? void 0 : rect.left) + 14, "px");
827
+ };
828
+ Tour.prototype.close = function () {
829
+ var tourElement = this.tourElement;
830
+ document.body.removeChild(tourElement);
831
+ document.body.removeChild(this.tourTargetElement);
832
+ };
833
+ return Tour;
834
+ }());
835
+
836
+ var defaultWebSocketConfig = {
837
+ heartbeat: false,
838
+ heartbeatTime: 15000,
839
+ reconnect: false,
840
+ reconnectTime: 1000,
841
+ maxReconnectNumber: 3,
842
+ };
843
+ function createWebSocket(url, config, onOpen) {
844
+ config = __assign(__assign({}, defaultWebSocketConfig), config);
845
+ var open = reconnectWebSocket();
846
+ var init = function () {
847
+ var ws = new WebSocket(url);
848
+ ws.onopen = function () {
849
+ if (config === null || config === void 0 ? void 0 : config.heartbeat)
850
+ heartbeat(ws, config);
851
+ onOpen === null || onOpen === void 0 ? void 0 : onOpen();
852
+ };
853
+ ws.onerror = function () {
854
+ if ((config === null || config === void 0 ? void 0 : config.reconnect) && open) {
855
+ open(ws, config, init);
856
+ }
857
+ else {
858
+ open = null;
859
+ config = null;
860
+ }
861
+ };
862
+ return ws;
863
+ };
864
+ return init();
865
+ }
866
+ function getState(ws, type) {
867
+ return ws.readyState === WebSocket[type];
868
+ }
869
+ function reconnectWebSocket() {
870
+ var reconnectTimeout;
871
+ var reconnectNumber = 0;
872
+ var open = function (ws, config, callback) {
873
+ var reconnectTime = config.reconnectTime, _a = config.maxReconnectNumber, maxReconnectNumber = _a === void 0 ? 1 : _a;
874
+ var isOpen = getState(ws, 'OPEN');
875
+ if (isOpen || (reconnectTimeout && reconnectNumber >= maxReconnectNumber)) {
876
+ clearTimeout(reconnectTimeout);
877
+ reconnectTimeout = null;
878
+ reconnectNumber = null;
879
+ config.reconnect = false;
880
+ return;
881
+ }
882
+ reconnectTimeout = setTimeout(function () {
883
+ reconnectNumber += 1;
884
+ callback();
885
+ }, reconnectTime);
886
+ };
887
+ return open;
888
+ }
889
+ function heartbeat(ws, config) {
890
+ var heartbeatTime = config.heartbeatTime;
891
+ var timer = null;
892
+ timer = setInterval(function () {
893
+ var isOpen = getState(ws, 'OPEN');
894
+ var isConnected = getState(ws, 'CONNECTING');
895
+ if (isOpen) {
896
+ useSendMessage(ws, {
897
+ type: 'heartbeat',
898
+ timestamp: Date.now()
899
+ });
900
+ }
901
+ else if (!isConnected) {
902
+ var open_1 = reconnectWebSocket();
903
+ open_1(ws, config, function () {
904
+ timer && clearInterval(timer);
905
+ heartbeat(ws, config);
906
+ });
907
+ }
908
+ }, heartbeatTime);
909
+ }
910
+ function useSendMessage(ws, data) {
911
+ var isOpen = getState(ws, 'OPEN');
912
+ if (isOpen)
913
+ ws.send(JSON.stringify(data));
914
+ }
915
+ function useWebSocketMessage(ws, callback) {
916
+ try {
917
+ ws.onmessage = function (e) {
918
+ var data = JSON.parse(e.data);
919
+ callback(data, e);
920
+ };
921
+ }
922
+ catch (error) {
923
+ console.error(error);
924
+ }
925
+ }
926
+ function useWebSocketClose(ws, code, message) {
927
+ code = code || 1000;
928
+ message = message || 'connection closed by client';
929
+ ws.close(code, message);
930
+ }
931
+
932
+ /**
933
+ * 匹配中文字母数字
934
+ */
935
+ var ZN_LETTER_NUMBER = /^[\u4E00-\u9FA5\w]+$/;
936
+ /**
937
+ * 匹配 IP
938
+ */
939
+ var IP = /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})$/;
940
+ /**
941
+ * 匹配手机号
942
+ */
943
+ var PHONE = /^1[3-9]\d{9}$/;
944
+
945
+ exports.IP = IP;
615
946
  exports.InputLegalityValidate = InputLegalityValidate;
616
947
  exports.InputLengthValidate = InputLengthValidate;
948
+ exports.Mask = Mask;
949
+ exports.PHONE = PHONE;
950
+ exports.Request = Request;
951
+ exports.RequestChain = RequestChain;
952
+ exports.Tour = Tour;
953
+ exports.ZN_LETTER_NUMBER = ZN_LETTER_NUMBER;
954
+ exports.createWebSocket = createWebSocket;
617
955
  exports.dataHandler = dataHandler;
618
956
  exports.debounce = debounce;
619
957
  exports.deepMerge = deepMerge;
620
958
  exports.findTreeDataNode = findTreeDataNode;
621
959
  exports.findTreeDataNodeName = findTreeDataNodeName;
960
+ exports.getState = getState;
622
961
  exports.isMobileDevice = isMobileDevice;
623
962
  exports.isNull = isNull;
624
963
  exports.objectArrayToString = objectArrayToString;
625
964
  exports.throttle = throttle;
626
965
  exports.useCountDown = useCountDown;
966
+ exports.useSendMessage = useSendMessage;
967
+ exports.useWebSocketClose = useWebSocketClose;
968
+ exports.useWebSocketMessage = useWebSocketMessage;
627
969
 
628
970
  }));