1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', { value: true });
|
4 |
|
5 | var lib = {};
|
6 |
|
7 | Object.defineProperty(lib, '__esModule', { value: true });
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | var extendStatics$1 = function(d, b) {
|
26 | extendStatics$1 = Object.setPrototypeOf ||
|
27 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
28 | function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
29 | return extendStatics$1(d, b);
|
30 | };
|
31 |
|
32 | function __extends$1(d, b) {
|
33 | if (typeof b !== "function" && b !== null)
|
34 | throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
35 | extendStatics$1(d, b);
|
36 | function __() { this.constructor = d; }
|
37 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
38 | }
|
39 |
|
40 | var __assign = function() {
|
41 | __assign = Object.assign || function __assign(t) {
|
42 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
43 | s = arguments[i];
|
44 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
45 | }
|
46 | return t;
|
47 | };
|
48 | return __assign.apply(this, arguments);
|
49 | };
|
50 |
|
51 | function __rest(s, e) {
|
52 | var t = {};
|
53 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
54 | t[p] = s[p];
|
55 | if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
56 | for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
57 | if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
58 | t[p[i]] = s[p[i]];
|
59 | }
|
60 | return t;
|
61 | }
|
62 |
|
63 | function __awaiter$1(thisArg, _arguments, P, generator) {
|
64 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
65 | return new (P || (P = Promise))(function (resolve, reject) {
|
66 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
67 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
68 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
69 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
70 | });
|
71 | }
|
72 |
|
73 | function __generator$1(thisArg, body) {
|
74 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
75 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
76 | function verb(n) { return function (v) { return step([n, v]); }; }
|
77 | function step(op) {
|
78 | if (f) throw new TypeError("Generator is already executing.");
|
79 | while (_) try {
|
80 | 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;
|
81 | if (y = 0, t) op = [op[0] & 2, t.value];
|
82 | switch (op[0]) {
|
83 | case 0: case 1: t = op; break;
|
84 | case 4: _.label++; return { value: op[1], done: false };
|
85 | case 5: _.label++; y = op[1]; op = [0]; continue;
|
86 | case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
87 | default:
|
88 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
89 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
90 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
91 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
92 | if (t[2]) _.ops.pop();
|
93 | _.trys.pop(); continue;
|
94 | }
|
95 | op = body.call(thisArg, _);
|
96 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
97 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
98 | }
|
99 | }
|
100 |
|
101 | var PROVIDER$1 = "lc_weapp";
|
102 | var PLATFORM$1 = "weixin";
|
103 | function getLoginCode() {
|
104 | return new Promise(function (resolve, reject) {
|
105 | wx.login({
|
106 | success: function (res) {
|
107 | return res.code ? resolve(res.code) : reject(new Error(res.errMsg));
|
108 | },
|
109 | fail: function (_a) {
|
110 | var errMsg = _a.errMsg;
|
111 | return reject(new Error(errMsg));
|
112 | },
|
113 | });
|
114 | });
|
115 | }
|
116 | var getAuthInfo$1 = function (_a) {
|
117 | var _b = _a === void 0 ? {} : _a, _c = _b.platform, platform = _c === void 0 ? PLATFORM$1 : _c, _d = _b.preferUnionId, preferUnionId = _d === void 0 ? false : _d, _e = _b.asMainAccount, asMainAccount = _e === void 0 ? false : _e;
|
118 | return __awaiter$1(this, void 0, void 0, function () {
|
119 | var code, authData;
|
120 | return __generator$1(this, function (_f) {
|
121 | switch (_f.label) {
|
122 | case 0: return [4 , getLoginCode()];
|
123 | case 1:
|
124 | code = _f.sent();
|
125 | authData = { code: code };
|
126 | if (preferUnionId) {
|
127 | authData.platform = platform;
|
128 | authData.main_account = asMainAccount;
|
129 | }
|
130 | return [2 , {
|
131 | authData: authData,
|
132 | platform: platform,
|
133 | provider: PROVIDER$1,
|
134 | }];
|
135 | }
|
136 | });
|
137 | });
|
138 | };
|
139 |
|
140 | var storage = {
|
141 | getItem: function (key) {
|
142 | return wx.getStorageSync(key);
|
143 | },
|
144 | setItem: function (key, value) {
|
145 | return wx.setStorageSync(key, value);
|
146 | },
|
147 | removeItem: function (key) {
|
148 | return wx.removeStorageSync(key);
|
149 | },
|
150 | clear: function () {
|
151 | return wx.clearStorageSync();
|
152 | },
|
153 | };
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 | var extendStatics = function(d, b) {
|
172 | extendStatics = Object.setPrototypeOf ||
|
173 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
174 | function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
175 | return extendStatics(d, b);
|
176 | };
|
177 |
|
178 | function __extends(d, b) {
|
179 | if (typeof b !== "function" && b !== null)
|
180 | throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
181 | extendStatics(d, b);
|
182 | function __() { this.constructor = d; }
|
183 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
184 | }
|
185 |
|
186 | var AbortError = (function (_super) {
|
187 | __extends(AbortError, _super);
|
188 | function AbortError() {
|
189 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
190 | _this.name = "AbortError";
|
191 | return _this;
|
192 | }
|
193 | return AbortError;
|
194 | }(Error));
|
195 |
|
196 | var request = function (url, options) {
|
197 | if (options === void 0) { options = {}; }
|
198 | var method = options.method, data = options.data, headers = options.headers, signal = options.signal;
|
199 | if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
|
200 | return Promise.reject(new AbortError("Request aborted"));
|
201 | }
|
202 | return new Promise(function (resolve, reject) {
|
203 | var task = wx.request({
|
204 | url: url,
|
205 | method: method,
|
206 | data: data,
|
207 | header: headers,
|
208 | complete: function (res) {
|
209 | signal === null || signal === void 0 ? void 0 : signal.removeEventListener("abort", abortListener);
|
210 | if (!res.statusCode) {
|
211 | reject(new Error(res.errMsg));
|
212 | return;
|
213 | }
|
214 | resolve({
|
215 | ok: !(res.statusCode >= 400),
|
216 | status: res.statusCode,
|
217 | headers: res.header,
|
218 | data: res.data,
|
219 | });
|
220 | },
|
221 | });
|
222 | var abortListener = function () {
|
223 | reject(new AbortError("Request aborted"));
|
224 | task.abort();
|
225 | };
|
226 | signal === null || signal === void 0 ? void 0 : signal.addEventListener("abort", abortListener);
|
227 | });
|
228 | };
|
229 | var upload = function (url, file, options) {
|
230 | if (options === void 0) { options = {}; }
|
231 | var headers = options.headers, data = options.data, onprogress = options.onprogress, signal = options.signal;
|
232 | if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
|
233 | return Promise.reject(new AbortError("Request aborted"));
|
234 | }
|
235 | if (!(file && file.data && file.data.uri)) {
|
236 | return Promise.reject(new TypeError("File data must be an object like { uri: localPath }."));
|
237 | }
|
238 | return new Promise(function (resolve, reject) {
|
239 | var task = wx.uploadFile({
|
240 | url: url,
|
241 | header: headers,
|
242 | filePath: file.data.uri,
|
243 | name: file.field,
|
244 | formData: data,
|
245 | success: function (response) {
|
246 | var status = response.statusCode, data = response.data, rest = __rest(response, ["statusCode", "data"]);
|
247 | resolve(__assign(__assign({}, rest), { data: typeof data === "string" ? JSON.parse(data) : data, status: status, ok: !(status >= 400) }));
|
248 | },
|
249 | fail: function (response) {
|
250 | reject(new Error(response.errMsg));
|
251 | },
|
252 | complete: function () {
|
253 | signal === null || signal === void 0 ? void 0 : signal.removeEventListener("abort", abortListener);
|
254 | },
|
255 | });
|
256 | var abortListener = function () {
|
257 | reject(new AbortError("Request aborted"));
|
258 | task.abort();
|
259 | };
|
260 | signal === null || signal === void 0 ? void 0 : signal.addEventListener("abort", abortListener);
|
261 | if (onprogress) {
|
262 | task.onProgressUpdate(function (event) {
|
263 | return onprogress({
|
264 | loaded: event.totalBytesSent,
|
265 | total: event.totalBytesExpectedToSend,
|
266 | percent: event.progress,
|
267 | });
|
268 | });
|
269 | }
|
270 | });
|
271 | };
|
272 |
|
273 |
|
274 |
|
275 |
|
276 |
|
277 |
|
278 |
|
279 |
|
280 |
|
281 |
|
282 |
|
283 |
|
284 |
|
285 |
|
286 |
|
287 |
|
288 |
|
289 |
|
290 |
|
291 |
|
292 |
|
293 |
|
294 |
|
295 |
|
296 |
|
297 | const privateData = new WeakMap();
|
298 |
|
299 |
|
300 |
|
301 |
|
302 |
|
303 |
|
304 | const wrappers = new WeakMap();
|
305 |
|
306 |
|
307 |
|
308 |
|
309 |
|
310 |
|
311 |
|
312 | function pd(event) {
|
313 | const retv = privateData.get(event);
|
314 | return retv
|
315 | }
|
316 |
|
317 |
|
318 |
|
319 |
|
320 |
|
321 | function setCancelFlag(data) {
|
322 | if (data.passiveListener != null) {
|
323 | if (
|
324 | typeof console !== "undefined" &&
|
325 | typeof console.error === "function"
|
326 | ) {
|
327 | console.error(
|
328 | "Unable to preventDefault inside passive event listener invocation.",
|
329 | data.passiveListener
|
330 | );
|
331 | }
|
332 | return
|
333 | }
|
334 | if (!data.event.cancelable) {
|
335 | return
|
336 | }
|
337 |
|
338 | data.canceled = true;
|
339 | if (typeof data.event.preventDefault === "function") {
|
340 | data.event.preventDefault();
|
341 | }
|
342 | }
|
343 |
|
344 |
|
345 |
|
346 |
|
347 |
|
348 |
|
349 |
|
350 |
|
351 |
|
352 |
|
353 |
|
354 | function Event(eventTarget, event) {
|
355 | privateData.set(this, {
|
356 | eventTarget,
|
357 | event,
|
358 | eventPhase: 2,
|
359 | currentTarget: eventTarget,
|
360 | canceled: false,
|
361 | stopped: false,
|
362 | immediateStopped: false,
|
363 | passiveListener: null,
|
364 | timeStamp: event.timeStamp || Date.now(),
|
365 | });
|
366 |
|
367 |
|
368 | Object.defineProperty(this, "isTrusted", { value: false, enumerable: true });
|
369 |
|
370 |
|
371 | const keys = Object.keys(event);
|
372 | for (let i = 0; i < keys.length; ++i) {
|
373 | const key = keys[i];
|
374 | if (!(key in this)) {
|
375 | Object.defineProperty(this, key, defineRedirectDescriptor(key));
|
376 | }
|
377 | }
|
378 | }
|
379 |
|
380 |
|
381 | Event.prototype = {
|
382 | |
383 |
|
384 |
|
385 |
|
386 | get type() {
|
387 | return pd(this).event.type
|
388 | },
|
389 |
|
390 | |
391 |
|
392 |
|
393 |
|
394 | get target() {
|
395 | return pd(this).eventTarget
|
396 | },
|
397 |
|
398 | |
399 |
|
400 |
|
401 |
|
402 | get currentTarget() {
|
403 | return pd(this).currentTarget
|
404 | },
|
405 |
|
406 | |
407 |
|
408 |
|
409 | composedPath() {
|
410 | const currentTarget = pd(this).currentTarget;
|
411 | if (currentTarget == null) {
|
412 | return []
|
413 | }
|
414 | return [currentTarget]
|
415 | },
|
416 |
|
417 | |
418 |
|
419 |
|
420 |
|
421 | get NONE() {
|
422 | return 0
|
423 | },
|
424 |
|
425 | |
426 |
|
427 |
|
428 |
|
429 | get CAPTURING_PHASE() {
|
430 | return 1
|
431 | },
|
432 |
|
433 | |
434 |
|
435 |
|
436 |
|
437 | get AT_TARGET() {
|
438 | return 2
|
439 | },
|
440 |
|
441 | |
442 |
|
443 |
|
444 |
|
445 | get BUBBLING_PHASE() {
|
446 | return 3
|
447 | },
|
448 |
|
449 | |
450 |
|
451 |
|
452 |
|
453 | get eventPhase() {
|
454 | return pd(this).eventPhase
|
455 | },
|
456 |
|
457 | |
458 |
|
459 |
|
460 |
|
461 | stopPropagation() {
|
462 | const data = pd(this);
|
463 |
|
464 | data.stopped = true;
|
465 | if (typeof data.event.stopPropagation === "function") {
|
466 | data.event.stopPropagation();
|
467 | }
|
468 | },
|
469 |
|
470 | |
471 |
|
472 |
|
473 |
|
474 | stopImmediatePropagation() {
|
475 | const data = pd(this);
|
476 |
|
477 | data.stopped = true;
|
478 | data.immediateStopped = true;
|
479 | if (typeof data.event.stopImmediatePropagation === "function") {
|
480 | data.event.stopImmediatePropagation();
|
481 | }
|
482 | },
|
483 |
|
484 | |
485 |
|
486 |
|
487 |
|
488 | get bubbles() {
|
489 | return Boolean(pd(this).event.bubbles)
|
490 | },
|
491 |
|
492 | |
493 |
|
494 |
|
495 |
|
496 | get cancelable() {
|
497 | return Boolean(pd(this).event.cancelable)
|
498 | },
|
499 |
|
500 | |
501 |
|
502 |
|
503 |
|
504 | preventDefault() {
|
505 | setCancelFlag(pd(this));
|
506 | },
|
507 |
|
508 | |
509 |
|
510 |
|
511 |
|
512 | get defaultPrevented() {
|
513 | return pd(this).canceled
|
514 | },
|
515 |
|
516 | |
517 |
|
518 |
|
519 |
|
520 | get composed() {
|
521 | return Boolean(pd(this).event.composed)
|
522 | },
|
523 |
|
524 | |
525 |
|
526 |
|
527 |
|
528 | get timeStamp() {
|
529 | return pd(this).timeStamp
|
530 | },
|
531 |
|
532 | |
533 |
|
534 |
|
535 |
|
536 |
|
537 | get srcElement() {
|
538 | return pd(this).eventTarget
|
539 | },
|
540 |
|
541 | |
542 |
|
543 |
|
544 |
|
545 |
|
546 | get cancelBubble() {
|
547 | return pd(this).stopped
|
548 | },
|
549 | set cancelBubble(value) {
|
550 | if (!value) {
|
551 | return
|
552 | }
|
553 | const data = pd(this);
|
554 |
|
555 | data.stopped = true;
|
556 | if (typeof data.event.cancelBubble === "boolean") {
|
557 | data.event.cancelBubble = true;
|
558 | }
|
559 | },
|
560 |
|
561 | |
562 |
|
563 |
|
564 |
|
565 |
|
566 | get returnValue() {
|
567 | return !pd(this).canceled
|
568 | },
|
569 | set returnValue(value) {
|
570 | if (!value) {
|
571 | setCancelFlag(pd(this));
|
572 | }
|
573 | },
|
574 |
|
575 | |
576 |
|
577 |
|
578 |
|
579 |
|
580 |
|
581 |
|
582 | initEvent() {
|
583 |
|
584 | },
|
585 | };
|
586 |
|
587 |
|
588 | Object.defineProperty(Event.prototype, "constructor", {
|
589 | value: Event,
|
590 | configurable: true,
|
591 | writable: true,
|
592 | });
|
593 |
|
594 |
|
595 | if (typeof window !== "undefined" && typeof window.Event !== "undefined") {
|
596 | Object.setPrototypeOf(Event.prototype, window.Event.prototype);
|
597 |
|
598 |
|
599 | wrappers.set(window.Event.prototype, Event);
|
600 | }
|
601 |
|
602 |
|
603 |
|
604 |
|
605 |
|
606 |
|
607 |
|
608 | function defineRedirectDescriptor(key) {
|
609 | return {
|
610 | get() {
|
611 | return pd(this).event[key]
|
612 | },
|
613 | set(value) {
|
614 | pd(this).event[key] = value;
|
615 | },
|
616 | configurable: true,
|
617 | enumerable: true,
|
618 | }
|
619 | }
|
620 |
|
621 |
|
622 |
|
623 |
|
624 |
|
625 |
|
626 |
|
627 | function defineCallDescriptor(key) {
|
628 | return {
|
629 | value() {
|
630 | const event = pd(this).event;
|
631 | return event[key].apply(event, arguments)
|
632 | },
|
633 | configurable: true,
|
634 | enumerable: true,
|
635 | }
|
636 | }
|
637 |
|
638 |
|
639 |
|
640 |
|
641 |
|
642 |
|
643 |
|
644 |
|
645 | function defineWrapper(BaseEvent, proto) {
|
646 | const keys = Object.keys(proto);
|
647 | if (keys.length === 0) {
|
648 | return BaseEvent
|
649 | }
|
650 |
|
651 |
|
652 | function CustomEvent(eventTarget, event) {
|
653 | BaseEvent.call(this, eventTarget, event);
|
654 | }
|
655 |
|
656 | CustomEvent.prototype = Object.create(BaseEvent.prototype, {
|
657 | constructor: { value: CustomEvent, configurable: true, writable: true },
|
658 | });
|
659 |
|
660 |
|
661 | for (let i = 0; i < keys.length; ++i) {
|
662 | const key = keys[i];
|
663 | if (!(key in BaseEvent.prototype)) {
|
664 | const descriptor = Object.getOwnPropertyDescriptor(proto, key);
|
665 | const isFunc = typeof descriptor.value === "function";
|
666 | Object.defineProperty(
|
667 | CustomEvent.prototype,
|
668 | key,
|
669 | isFunc
|
670 | ? defineCallDescriptor(key)
|
671 | : defineRedirectDescriptor(key)
|
672 | );
|
673 | }
|
674 | }
|
675 |
|
676 | return CustomEvent
|
677 | }
|
678 |
|
679 |
|
680 |
|
681 |
|
682 |
|
683 |
|
684 |
|
685 | function getWrapper(proto) {
|
686 | if (proto == null || proto === Object.prototype) {
|
687 | return Event
|
688 | }
|
689 |
|
690 | let wrapper = wrappers.get(proto);
|
691 | if (wrapper == null) {
|
692 | wrapper = defineWrapper(getWrapper(Object.getPrototypeOf(proto)), proto);
|
693 | wrappers.set(proto, wrapper);
|
694 | }
|
695 | return wrapper
|
696 | }
|
697 |
|
698 |
|
699 |
|
700 |
|
701 |
|
702 |
|
703 |
|
704 |
|
705 | function wrapEvent(eventTarget, event) {
|
706 | const Wrapper = getWrapper(Object.getPrototypeOf(event));
|
707 | return new Wrapper(eventTarget, event)
|
708 | }
|
709 |
|
710 |
|
711 |
|
712 |
|
713 |
|
714 |
|
715 |
|
716 | function isStopped(event) {
|
717 | return pd(event).immediateStopped
|
718 | }
|
719 |
|
720 |
|
721 |
|
722 |
|
723 |
|
724 |
|
725 |
|
726 |
|
727 | function setEventPhase(event, eventPhase) {
|
728 | pd(event).eventPhase = eventPhase;
|
729 | }
|
730 |
|
731 |
|
732 |
|
733 |
|
734 |
|
735 |
|
736 |
|
737 |
|
738 | function setCurrentTarget(event, currentTarget) {
|
739 | pd(event).currentTarget = currentTarget;
|
740 | }
|
741 |
|
742 |
|
743 |
|
744 |
|
745 |
|
746 |
|
747 |
|
748 |
|
749 | function setPassiveListener(event, passiveListener) {
|
750 | pd(event).passiveListener = passiveListener;
|
751 | }
|
752 |
|
753 |
|
754 |
|
755 |
|
756 |
|
757 |
|
758 |
|
759 |
|
760 |
|
761 |
|
762 |
|
763 |
|
764 |
|
765 |
|
766 |
|
767 | const listenersMap = new WeakMap();
|
768 |
|
769 |
|
770 | const CAPTURE = 1;
|
771 | const BUBBLE = 2;
|
772 | const ATTRIBUTE = 3;
|
773 |
|
774 |
|
775 |
|
776 |
|
777 |
|
778 |
|
779 | function isObject(x) {
|
780 | return x !== null && typeof x === "object"
|
781 | }
|
782 |
|
783 |
|
784 |
|
785 |
|
786 |
|
787 |
|
788 |
|
789 | function getListeners(eventTarget) {
|
790 | const listeners = listenersMap.get(eventTarget);
|
791 | if (listeners == null) {
|
792 | throw new TypeError(
|
793 | "'this' is expected an EventTarget object, but got another value."
|
794 | )
|
795 | }
|
796 | return listeners
|
797 | }
|
798 |
|
799 |
|
800 |
|
801 |
|
802 |
|
803 |
|
804 |
|
805 | function defineEventAttributeDescriptor(eventName) {
|
806 | return {
|
807 | get() {
|
808 | const listeners = getListeners(this);
|
809 | let node = listeners.get(eventName);
|
810 | while (node != null) {
|
811 | if (node.listenerType === ATTRIBUTE) {
|
812 | return node.listener
|
813 | }
|
814 | node = node.next;
|
815 | }
|
816 | return null
|
817 | },
|
818 |
|
819 | set(listener) {
|
820 | if (typeof listener !== "function" && !isObject(listener)) {
|
821 | listener = null;
|
822 | }
|
823 | const listeners = getListeners(this);
|
824 |
|
825 |
|
826 | let prev = null;
|
827 | let node = listeners.get(eventName);
|
828 | while (node != null) {
|
829 | if (node.listenerType === ATTRIBUTE) {
|
830 |
|
831 | if (prev !== null) {
|
832 | prev.next = node.next;
|
833 | } else if (node.next !== null) {
|
834 | listeners.set(eventName, node.next);
|
835 | } else {
|
836 | listeners.delete(eventName);
|
837 | }
|
838 | } else {
|
839 | prev = node;
|
840 | }
|
841 |
|
842 | node = node.next;
|
843 | }
|
844 |
|
845 |
|
846 | if (listener !== null) {
|
847 | const newNode = {
|
848 | listener,
|
849 | listenerType: ATTRIBUTE,
|
850 | passive: false,
|
851 | once: false,
|
852 | next: null,
|
853 | };
|
854 | if (prev === null) {
|
855 | listeners.set(eventName, newNode);
|
856 | } else {
|
857 | prev.next = newNode;
|
858 | }
|
859 | }
|
860 | },
|
861 | configurable: true,
|
862 | enumerable: true,
|
863 | }
|
864 | }
|
865 |
|
866 |
|
867 |
|
868 |
|
869 |
|
870 |
|
871 |
|
872 | function defineEventAttribute(eventTargetPrototype, eventName) {
|
873 | Object.defineProperty(
|
874 | eventTargetPrototype,
|
875 | `on${eventName}`,
|
876 | defineEventAttributeDescriptor(eventName)
|
877 | );
|
878 | }
|
879 |
|
880 |
|
881 |
|
882 |
|
883 |
|
884 |
|
885 |
|
886 | function defineCustomEventTarget(eventNames) {
|
887 |
|
888 | function CustomEventTarget() {
|
889 | EventTarget.call(this);
|
890 | }
|
891 |
|
892 | CustomEventTarget.prototype = Object.create(EventTarget.prototype, {
|
893 | constructor: {
|
894 | value: CustomEventTarget,
|
895 | configurable: true,
|
896 | writable: true,
|
897 | },
|
898 | });
|
899 |
|
900 | for (let i = 0; i < eventNames.length; ++i) {
|
901 | defineEventAttribute(CustomEventTarget.prototype, eventNames[i]);
|
902 | }
|
903 |
|
904 | return CustomEventTarget
|
905 | }
|
906 |
|
907 |
|
908 |
|
909 |
|
910 |
|
911 |
|
912 |
|
913 |
|
914 |
|
915 |
|
916 |
|
917 |
|
918 |
|
919 |
|
920 | function EventTarget() {
|
921 |
|
922 | if (this instanceof EventTarget) {
|
923 | listenersMap.set(this, new Map());
|
924 | return
|
925 | }
|
926 | if (arguments.length === 1 && Array.isArray(arguments[0])) {
|
927 | return defineCustomEventTarget(arguments[0])
|
928 | }
|
929 | if (arguments.length > 0) {
|
930 | const types = new Array(arguments.length);
|
931 | for (let i = 0; i < arguments.length; ++i) {
|
932 | types[i] = arguments[i];
|
933 | }
|
934 | return defineCustomEventTarget(types)
|
935 | }
|
936 | throw new TypeError("Cannot call a class as a function")
|
937 |
|
938 | }
|
939 |
|
940 |
|
941 | EventTarget.prototype = {
|
942 | |
943 |
|
944 |
|
945 |
|
946 |
|
947 |
|
948 |
|
949 | addEventListener(eventName, listener, options) {
|
950 | if (listener == null) {
|
951 | return
|
952 | }
|
953 | if (typeof listener !== "function" && !isObject(listener)) {
|
954 | throw new TypeError("'listener' should be a function or an object.")
|
955 | }
|
956 |
|
957 | const listeners = getListeners(this);
|
958 | const optionsIsObj = isObject(options);
|
959 | const capture = optionsIsObj
|
960 | ? Boolean(options.capture)
|
961 | : Boolean(options);
|
962 | const listenerType = capture ? CAPTURE : BUBBLE;
|
963 | const newNode = {
|
964 | listener,
|
965 | listenerType,
|
966 | passive: optionsIsObj && Boolean(options.passive),
|
967 | once: optionsIsObj && Boolean(options.once),
|
968 | next: null,
|
969 | };
|
970 |
|
971 |
|
972 | let node = listeners.get(eventName);
|
973 | if (node === undefined) {
|
974 | listeners.set(eventName, newNode);
|
975 | return
|
976 | }
|
977 |
|
978 |
|
979 | let prev = null;
|
980 | while (node != null) {
|
981 | if (
|
982 | node.listener === listener &&
|
983 | node.listenerType === listenerType
|
984 | ) {
|
985 |
|
986 | return
|
987 | }
|
988 | prev = node;
|
989 | node = node.next;
|
990 | }
|
991 |
|
992 |
|
993 | prev.next = newNode;
|
994 | },
|
995 |
|
996 | |
997 |
|
998 |
|
999 |
|
1000 |
|
1001 |
|
1002 |
|
1003 | removeEventListener(eventName, listener, options) {
|
1004 | if (listener == null) {
|
1005 | return
|
1006 | }
|
1007 |
|
1008 | const listeners = getListeners(this);
|
1009 | const capture = isObject(options)
|
1010 | ? Boolean(options.capture)
|
1011 | : Boolean(options);
|
1012 | const listenerType = capture ? CAPTURE : BUBBLE;
|
1013 |
|
1014 | let prev = null;
|
1015 | let node = listeners.get(eventName);
|
1016 | while (node != null) {
|
1017 | if (
|
1018 | node.listener === listener &&
|
1019 | node.listenerType === listenerType
|
1020 | ) {
|
1021 | if (prev !== null) {
|
1022 | prev.next = node.next;
|
1023 | } else if (node.next !== null) {
|
1024 | listeners.set(eventName, node.next);
|
1025 | } else {
|
1026 | listeners.delete(eventName);
|
1027 | }
|
1028 | return
|
1029 | }
|
1030 |
|
1031 | prev = node;
|
1032 | node = node.next;
|
1033 | }
|
1034 | },
|
1035 |
|
1036 | |
1037 |
|
1038 |
|
1039 |
|
1040 |
|
1041 | dispatchEvent(event) {
|
1042 | if (event == null || typeof event.type !== "string") {
|
1043 | throw new TypeError('"event.type" should be a string.')
|
1044 | }
|
1045 |
|
1046 |
|
1047 | const listeners = getListeners(this);
|
1048 | const eventName = event.type;
|
1049 | let node = listeners.get(eventName);
|
1050 | if (node == null) {
|
1051 | return true
|
1052 | }
|
1053 |
|
1054 |
|
1055 | const wrappedEvent = wrapEvent(this, event);
|
1056 |
|
1057 |
|
1058 |
|
1059 | let prev = null;
|
1060 | while (node != null) {
|
1061 |
|
1062 | if (node.once) {
|
1063 | if (prev !== null) {
|
1064 | prev.next = node.next;
|
1065 | } else if (node.next !== null) {
|
1066 | listeners.set(eventName, node.next);
|
1067 | } else {
|
1068 | listeners.delete(eventName);
|
1069 | }
|
1070 | } else {
|
1071 | prev = node;
|
1072 | }
|
1073 |
|
1074 |
|
1075 | setPassiveListener(
|
1076 | wrappedEvent,
|
1077 | node.passive ? node.listener : null
|
1078 | );
|
1079 | if (typeof node.listener === "function") {
|
1080 | try {
|
1081 | node.listener.call(this, wrappedEvent);
|
1082 | } catch (err) {
|
1083 | if (
|
1084 | typeof console !== "undefined" &&
|
1085 | typeof console.error === "function"
|
1086 | ) {
|
1087 | console.error(err);
|
1088 | }
|
1089 | }
|
1090 | } else if (
|
1091 | node.listenerType !== ATTRIBUTE &&
|
1092 | typeof node.listener.handleEvent === "function"
|
1093 | ) {
|
1094 | node.listener.handleEvent(wrappedEvent);
|
1095 | }
|
1096 |
|
1097 |
|
1098 | if (isStopped(wrappedEvent)) {
|
1099 | break
|
1100 | }
|
1101 |
|
1102 | node = node.next;
|
1103 | }
|
1104 | setPassiveListener(wrappedEvent, null);
|
1105 | setEventPhase(wrappedEvent, 0);
|
1106 | setCurrentTarget(wrappedEvent, null);
|
1107 |
|
1108 | return !wrappedEvent.defaultPrevented
|
1109 | },
|
1110 | };
|
1111 |
|
1112 |
|
1113 | Object.defineProperty(EventTarget.prototype, "constructor", {
|
1114 | value: EventTarget,
|
1115 | configurable: true,
|
1116 | writable: true,
|
1117 | });
|
1118 |
|
1119 |
|
1120 | if (
|
1121 | typeof window !== "undefined" &&
|
1122 | typeof window.EventTarget !== "undefined"
|
1123 | ) {
|
1124 | Object.setPrototypeOf(EventTarget.prototype, window.EventTarget.prototype);
|
1125 | }
|
1126 |
|
1127 | var WS = (function (_super) {
|
1128 | __extends$1(WS, _super);
|
1129 | function WS(url, protocol) {
|
1130 | var _this = _super.call(this) || this;
|
1131 | _this._readyState = WS.CLOSED;
|
1132 | if (!url) {
|
1133 | throw new TypeError("Failed to construct 'WebSocket': url required");
|
1134 | }
|
1135 | _this._url = url;
|
1136 | _this._protocol = protocol;
|
1137 | return _this;
|
1138 | }
|
1139 | Object.defineProperty(WS.prototype, "url", {
|
1140 | get: function () {
|
1141 | return this._url;
|
1142 | },
|
1143 | enumerable: false,
|
1144 | configurable: true
|
1145 | });
|
1146 | Object.defineProperty(WS.prototype, "protocol", {
|
1147 | get: function () {
|
1148 | return this._protocol;
|
1149 | },
|
1150 | enumerable: false,
|
1151 | configurable: true
|
1152 | });
|
1153 | Object.defineProperty(WS.prototype, "readyState", {
|
1154 | get: function () {
|
1155 | return this._readyState;
|
1156 | },
|
1157 | enumerable: false,
|
1158 | configurable: true
|
1159 | });
|
1160 | WS.CONNECTING = 0;
|
1161 | WS.OPEN = 1;
|
1162 | WS.CLOSING = 2;
|
1163 | WS.CLOSED = 3;
|
1164 | return WS;
|
1165 | }(EventTarget("open", "error", "message", "close")));
|
1166 | var WechatWS = (function (_super) {
|
1167 | __extends$1(WechatWS, _super);
|
1168 | function WechatWS(url, protocol) {
|
1169 | var _this = _super.call(this, url, protocol) || this;
|
1170 | if (protocol &&
|
1171 | !(wx.canIUse && wx.canIUse("connectSocket.object.protocols"))) {
|
1172 | throw new Error("subprotocol not supported in weapp");
|
1173 | }
|
1174 | _this._readyState = WS.CONNECTING;
|
1175 | var errorHandler = function (event) {
|
1176 | _this._readyState = WS.CLOSED;
|
1177 | _this.dispatchEvent({
|
1178 | type: "error",
|
1179 | message: event.errMsg,
|
1180 | });
|
1181 | };
|
1182 | var socketTask = wx.connectSocket({
|
1183 | url: url,
|
1184 | protocols: _this._protocol === undefined || Array.isArray(_this._protocol)
|
1185 | ? _this._protocol
|
1186 | : [_this._protocol],
|
1187 | fail: function (error) { return setTimeout(function () { return errorHandler(error); }, 0); },
|
1188 | });
|
1189 | _this._socketTask = socketTask;
|
1190 | socketTask.onOpen(function () {
|
1191 | _this._readyState = WS.OPEN;
|
1192 | _this.dispatchEvent({
|
1193 | type: "open",
|
1194 | });
|
1195 | });
|
1196 | socketTask.onError(errorHandler);
|
1197 | socketTask.onMessage(function (event) {
|
1198 | var data = event.data;
|
1199 | _this.dispatchEvent({
|
1200 | data: data,
|
1201 | type: "message",
|
1202 | });
|
1203 | });
|
1204 | socketTask.onClose(function (event) {
|
1205 | _this._readyState = WS.CLOSED;
|
1206 | var code = event.code, reason = event.reason;
|
1207 | _this.dispatchEvent({
|
1208 | code: code,
|
1209 | reason: reason,
|
1210 | type: "close",
|
1211 | });
|
1212 | });
|
1213 | return _this;
|
1214 | }
|
1215 | WechatWS.prototype.close = function () {
|
1216 | if (this.readyState === WS.CLOSED)
|
1217 | return;
|
1218 | if (this.readyState === WS.CONNECTING) {
|
1219 | console.warn("close WebSocket which is connecting might not work");
|
1220 | }
|
1221 | this._socketTask.close({});
|
1222 | };
|
1223 | WechatWS.prototype.send = function (data) {
|
1224 | if (this.readyState !== WS.OPEN) {
|
1225 | throw new Error("INVALID_STATE_ERR");
|
1226 | }
|
1227 | if (!(typeof data === "string" || data instanceof ArrayBuffer)) {
|
1228 | throw new TypeError("only String/ArrayBuffer supported");
|
1229 | }
|
1230 | this._socketTask.send({
|
1231 | data: data,
|
1232 | });
|
1233 | };
|
1234 | return WechatWS;
|
1235 | }(WS));
|
1236 | var WebSocket = WechatWS;
|
1237 |
|
1238 | var platformInfo$1 = {
|
1239 | name: "Weapp",
|
1240 | };
|
1241 |
|
1242 | var WebSocket_1 = lib.WebSocket = WebSocket;
|
1243 | var getAuthInfo_1 = lib.getAuthInfo = getAuthInfo$1;
|
1244 | lib.platformInfo = platformInfo$1;
|
1245 | var request_1 = lib.request = request;
|
1246 | var storage_1 = lib.storage = storage;
|
1247 | var upload_1 = lib.upload = upload;
|
1248 |
|
1249 |
|
1250 |
|
1251 |
|
1252 |
|
1253 |
|
1254 |
|
1255 |
|
1256 |
|
1257 |
|
1258 |
|
1259 |
|
1260 |
|
1261 |
|
1262 |
|
1263 |
|
1264 | function __awaiter(thisArg, _arguments, P, generator) {
|
1265 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
1266 | return new (P || (P = Promise))(function (resolve, reject) {
|
1267 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
1268 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
1269 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
1270 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
1271 | });
|
1272 | }
|
1273 |
|
1274 | function __generator(thisArg, body) {
|
1275 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
1276 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
1277 | function verb(n) { return function (v) { return step([n, v]); }; }
|
1278 | function step(op) {
|
1279 | if (f) throw new TypeError("Generator is already executing.");
|
1280 | while (_) try {
|
1281 | 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;
|
1282 | if (y = 0, t) op = [op[0] & 2, t.value];
|
1283 | switch (op[0]) {
|
1284 | case 0: case 1: t = op; break;
|
1285 | case 4: _.label++; return { value: op[1], done: false };
|
1286 | case 5: _.label++; y = op[1]; op = [0]; continue;
|
1287 | case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
1288 | default:
|
1289 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
1290 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
1291 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
1292 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
1293 | if (t[2]) _.ops.pop();
|
1294 | _.trys.pop(); continue;
|
1295 | }
|
1296 | op = body.call(thisArg, _);
|
1297 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
1298 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
1299 | }
|
1300 | }
|
1301 |
|
1302 | var PROVIDER = "lc_qqapp";
|
1303 | var PLATFORM = "qq";
|
1304 | var getAuthInfo = function (_a) {
|
1305 | var _b = _a === void 0 ? {} : _a, _c = _b.platform, platform = _c === void 0 ? PLATFORM : _c, _d = _b.preferUnionId, preferUnionId = _d === void 0 ? false : _d, _e = _b.asMainAccount, asMainAccount = _e === void 0 ? false : _e;
|
1306 | return __awaiter(this, void 0, void 0, function () {
|
1307 | var authInfo;
|
1308 | return __generator(this, function (_f) {
|
1309 | switch (_f.label) {
|
1310 | case 0: return [4 , getAuthInfo_1({
|
1311 | platform: platform,
|
1312 | preferUnionId: preferUnionId,
|
1313 | asMainAccount: asMainAccount,
|
1314 | })];
|
1315 | case 1:
|
1316 | authInfo = _f.sent();
|
1317 | authInfo.provider = PROVIDER;
|
1318 | return [2 , authInfo];
|
1319 | }
|
1320 | });
|
1321 | });
|
1322 | };
|
1323 |
|
1324 | var platformInfo = {
|
1325 | name: "QQApp",
|
1326 | };
|
1327 |
|
1328 | exports.WebSocket = WebSocket_1;
|
1329 | exports.getAuthInfo = getAuthInfo;
|
1330 | exports.platformInfo = platformInfo;
|
1331 | exports.request = request_1;
|
1332 | exports.storage = storage_1;
|
1333 | exports.upload = upload_1;
|
1334 |
|