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 | console.assert(
|
315 | retv != null,
|
316 | "'this' is expected an Event object, but got",
|
317 | event
|
318 | );
|
319 | return retv
|
320 | }
|
321 |
|
322 |
|
323 |
|
324 |
|
325 |
|
326 | function setCancelFlag(data) {
|
327 | if (data.passiveListener != null) {
|
328 | if (
|
329 | typeof console !== "undefined" &&
|
330 | typeof console.error === "function"
|
331 | ) {
|
332 | console.error(
|
333 | "Unable to preventDefault inside passive event listener invocation.",
|
334 | data.passiveListener
|
335 | );
|
336 | }
|
337 | return
|
338 | }
|
339 | if (!data.event.cancelable) {
|
340 | return
|
341 | }
|
342 |
|
343 | data.canceled = true;
|
344 | if (typeof data.event.preventDefault === "function") {
|
345 | data.event.preventDefault();
|
346 | }
|
347 | }
|
348 |
|
349 |
|
350 |
|
351 |
|
352 |
|
353 |
|
354 |
|
355 |
|
356 |
|
357 |
|
358 |
|
359 | function Event(eventTarget, event) {
|
360 | privateData.set(this, {
|
361 | eventTarget,
|
362 | event,
|
363 | eventPhase: 2,
|
364 | currentTarget: eventTarget,
|
365 | canceled: false,
|
366 | stopped: false,
|
367 | immediateStopped: false,
|
368 | passiveListener: null,
|
369 | timeStamp: event.timeStamp || Date.now(),
|
370 | });
|
371 |
|
372 |
|
373 | Object.defineProperty(this, "isTrusted", { value: false, enumerable: true });
|
374 |
|
375 |
|
376 | const keys = Object.keys(event);
|
377 | for (let i = 0; i < keys.length; ++i) {
|
378 | const key = keys[i];
|
379 | if (!(key in this)) {
|
380 | Object.defineProperty(this, key, defineRedirectDescriptor(key));
|
381 | }
|
382 | }
|
383 | }
|
384 |
|
385 |
|
386 | Event.prototype = {
|
387 | |
388 |
|
389 |
|
390 |
|
391 | get type() {
|
392 | return pd(this).event.type
|
393 | },
|
394 |
|
395 | |
396 |
|
397 |
|
398 |
|
399 | get target() {
|
400 | return pd(this).eventTarget
|
401 | },
|
402 |
|
403 | |
404 |
|
405 |
|
406 |
|
407 | get currentTarget() {
|
408 | return pd(this).currentTarget
|
409 | },
|
410 |
|
411 | |
412 |
|
413 |
|
414 | composedPath() {
|
415 | const currentTarget = pd(this).currentTarget;
|
416 | if (currentTarget == null) {
|
417 | return []
|
418 | }
|
419 | return [currentTarget]
|
420 | },
|
421 |
|
422 | |
423 |
|
424 |
|
425 |
|
426 | get NONE() {
|
427 | return 0
|
428 | },
|
429 |
|
430 | |
431 |
|
432 |
|
433 |
|
434 | get CAPTURING_PHASE() {
|
435 | return 1
|
436 | },
|
437 |
|
438 | |
439 |
|
440 |
|
441 |
|
442 | get AT_TARGET() {
|
443 | return 2
|
444 | },
|
445 |
|
446 | |
447 |
|
448 |
|
449 |
|
450 | get BUBBLING_PHASE() {
|
451 | return 3
|
452 | },
|
453 |
|
454 | |
455 |
|
456 |
|
457 |
|
458 | get eventPhase() {
|
459 | return pd(this).eventPhase
|
460 | },
|
461 |
|
462 | |
463 |
|
464 |
|
465 |
|
466 | stopPropagation() {
|
467 | const data = pd(this);
|
468 |
|
469 | data.stopped = true;
|
470 | if (typeof data.event.stopPropagation === "function") {
|
471 | data.event.stopPropagation();
|
472 | }
|
473 | },
|
474 |
|
475 | |
476 |
|
477 |
|
478 |
|
479 | stopImmediatePropagation() {
|
480 | const data = pd(this);
|
481 |
|
482 | data.stopped = true;
|
483 | data.immediateStopped = true;
|
484 | if (typeof data.event.stopImmediatePropagation === "function") {
|
485 | data.event.stopImmediatePropagation();
|
486 | }
|
487 | },
|
488 |
|
489 | |
490 |
|
491 |
|
492 |
|
493 | get bubbles() {
|
494 | return Boolean(pd(this).event.bubbles)
|
495 | },
|
496 |
|
497 | |
498 |
|
499 |
|
500 |
|
501 | get cancelable() {
|
502 | return Boolean(pd(this).event.cancelable)
|
503 | },
|
504 |
|
505 | |
506 |
|
507 |
|
508 |
|
509 | preventDefault() {
|
510 | setCancelFlag(pd(this));
|
511 | },
|
512 |
|
513 | |
514 |
|
515 |
|
516 |
|
517 | get defaultPrevented() {
|
518 | return pd(this).canceled
|
519 | },
|
520 |
|
521 | |
522 |
|
523 |
|
524 |
|
525 | get composed() {
|
526 | return Boolean(pd(this).event.composed)
|
527 | },
|
528 |
|
529 | |
530 |
|
531 |
|
532 |
|
533 | get timeStamp() {
|
534 | return pd(this).timeStamp
|
535 | },
|
536 |
|
537 | |
538 |
|
539 |
|
540 |
|
541 |
|
542 | get srcElement() {
|
543 | return pd(this).eventTarget
|
544 | },
|
545 |
|
546 | |
547 |
|
548 |
|
549 |
|
550 |
|
551 | get cancelBubble() {
|
552 | return pd(this).stopped
|
553 | },
|
554 | set cancelBubble(value) {
|
555 | if (!value) {
|
556 | return
|
557 | }
|
558 | const data = pd(this);
|
559 |
|
560 | data.stopped = true;
|
561 | if (typeof data.event.cancelBubble === "boolean") {
|
562 | data.event.cancelBubble = true;
|
563 | }
|
564 | },
|
565 |
|
566 | |
567 |
|
568 |
|
569 |
|
570 |
|
571 | get returnValue() {
|
572 | return !pd(this).canceled
|
573 | },
|
574 | set returnValue(value) {
|
575 | if (!value) {
|
576 | setCancelFlag(pd(this));
|
577 | }
|
578 | },
|
579 |
|
580 | |
581 |
|
582 |
|
583 |
|
584 |
|
585 |
|
586 |
|
587 | initEvent() {
|
588 |
|
589 | },
|
590 | };
|
591 |
|
592 |
|
593 | Object.defineProperty(Event.prototype, "constructor", {
|
594 | value: Event,
|
595 | configurable: true,
|
596 | writable: true,
|
597 | });
|
598 |
|
599 |
|
600 | if (typeof window !== "undefined" && typeof window.Event !== "undefined") {
|
601 | Object.setPrototypeOf(Event.prototype, window.Event.prototype);
|
602 |
|
603 |
|
604 | wrappers.set(window.Event.prototype, Event);
|
605 | }
|
606 |
|
607 |
|
608 |
|
609 |
|
610 |
|
611 |
|
612 |
|
613 | function defineRedirectDescriptor(key) {
|
614 | return {
|
615 | get() {
|
616 | return pd(this).event[key]
|
617 | },
|
618 | set(value) {
|
619 | pd(this).event[key] = value;
|
620 | },
|
621 | configurable: true,
|
622 | enumerable: true,
|
623 | }
|
624 | }
|
625 |
|
626 |
|
627 |
|
628 |
|
629 |
|
630 |
|
631 |
|
632 | function defineCallDescriptor(key) {
|
633 | return {
|
634 | value() {
|
635 | const event = pd(this).event;
|
636 | return event[key].apply(event, arguments)
|
637 | },
|
638 | configurable: true,
|
639 | enumerable: true,
|
640 | }
|
641 | }
|
642 |
|
643 |
|
644 |
|
645 |
|
646 |
|
647 |
|
648 |
|
649 |
|
650 | function defineWrapper(BaseEvent, proto) {
|
651 | const keys = Object.keys(proto);
|
652 | if (keys.length === 0) {
|
653 | return BaseEvent
|
654 | }
|
655 |
|
656 |
|
657 | function CustomEvent(eventTarget, event) {
|
658 | BaseEvent.call(this, eventTarget, event);
|
659 | }
|
660 |
|
661 | CustomEvent.prototype = Object.create(BaseEvent.prototype, {
|
662 | constructor: { value: CustomEvent, configurable: true, writable: true },
|
663 | });
|
664 |
|
665 |
|
666 | for (let i = 0; i < keys.length; ++i) {
|
667 | const key = keys[i];
|
668 | if (!(key in BaseEvent.prototype)) {
|
669 | const descriptor = Object.getOwnPropertyDescriptor(proto, key);
|
670 | const isFunc = typeof descriptor.value === "function";
|
671 | Object.defineProperty(
|
672 | CustomEvent.prototype,
|
673 | key,
|
674 | isFunc
|
675 | ? defineCallDescriptor(key)
|
676 | : defineRedirectDescriptor(key)
|
677 | );
|
678 | }
|
679 | }
|
680 |
|
681 | return CustomEvent
|
682 | }
|
683 |
|
684 |
|
685 |
|
686 |
|
687 |
|
688 |
|
689 |
|
690 | function getWrapper(proto) {
|
691 | if (proto == null || proto === Object.prototype) {
|
692 | return Event
|
693 | }
|
694 |
|
695 | let wrapper = wrappers.get(proto);
|
696 | if (wrapper == null) {
|
697 | wrapper = defineWrapper(getWrapper(Object.getPrototypeOf(proto)), proto);
|
698 | wrappers.set(proto, wrapper);
|
699 | }
|
700 | return wrapper
|
701 | }
|
702 |
|
703 |
|
704 |
|
705 |
|
706 |
|
707 |
|
708 |
|
709 |
|
710 | function wrapEvent(eventTarget, event) {
|
711 | const Wrapper = getWrapper(Object.getPrototypeOf(event));
|
712 | return new Wrapper(eventTarget, event)
|
713 | }
|
714 |
|
715 |
|
716 |
|
717 |
|
718 |
|
719 |
|
720 |
|
721 | function isStopped(event) {
|
722 | return pd(event).immediateStopped
|
723 | }
|
724 |
|
725 |
|
726 |
|
727 |
|
728 |
|
729 |
|
730 |
|
731 |
|
732 | function setEventPhase(event, eventPhase) {
|
733 | pd(event).eventPhase = eventPhase;
|
734 | }
|
735 |
|
736 |
|
737 |
|
738 |
|
739 |
|
740 |
|
741 |
|
742 |
|
743 | function setCurrentTarget(event, currentTarget) {
|
744 | pd(event).currentTarget = currentTarget;
|
745 | }
|
746 |
|
747 |
|
748 |
|
749 |
|
750 |
|
751 |
|
752 |
|
753 |
|
754 | function setPassiveListener(event, passiveListener) {
|
755 | pd(event).passiveListener = passiveListener;
|
756 | }
|
757 |
|
758 |
|
759 |
|
760 |
|
761 |
|
762 |
|
763 |
|
764 |
|
765 |
|
766 |
|
767 |
|
768 |
|
769 |
|
770 |
|
771 |
|
772 | const listenersMap = new WeakMap();
|
773 |
|
774 |
|
775 | const CAPTURE = 1;
|
776 | const BUBBLE = 2;
|
777 | const ATTRIBUTE = 3;
|
778 |
|
779 |
|
780 |
|
781 |
|
782 |
|
783 |
|
784 | function isObject(x) {
|
785 | return x !== null && typeof x === "object"
|
786 | }
|
787 |
|
788 |
|
789 |
|
790 |
|
791 |
|
792 |
|
793 |
|
794 | function getListeners(eventTarget) {
|
795 | const listeners = listenersMap.get(eventTarget);
|
796 | if (listeners == null) {
|
797 | throw new TypeError(
|
798 | "'this' is expected an EventTarget object, but got another value."
|
799 | )
|
800 | }
|
801 | return listeners
|
802 | }
|
803 |
|
804 |
|
805 |
|
806 |
|
807 |
|
808 |
|
809 |
|
810 | function defineEventAttributeDescriptor(eventName) {
|
811 | return {
|
812 | get() {
|
813 | const listeners = getListeners(this);
|
814 | let node = listeners.get(eventName);
|
815 | while (node != null) {
|
816 | if (node.listenerType === ATTRIBUTE) {
|
817 | return node.listener
|
818 | }
|
819 | node = node.next;
|
820 | }
|
821 | return null
|
822 | },
|
823 |
|
824 | set(listener) {
|
825 | if (typeof listener !== "function" && !isObject(listener)) {
|
826 | listener = null;
|
827 | }
|
828 | const listeners = getListeners(this);
|
829 |
|
830 |
|
831 | let prev = null;
|
832 | let node = listeners.get(eventName);
|
833 | while (node != null) {
|
834 | if (node.listenerType === ATTRIBUTE) {
|
835 |
|
836 | if (prev !== null) {
|
837 | prev.next = node.next;
|
838 | } else if (node.next !== null) {
|
839 | listeners.set(eventName, node.next);
|
840 | } else {
|
841 | listeners.delete(eventName);
|
842 | }
|
843 | } else {
|
844 | prev = node;
|
845 | }
|
846 |
|
847 | node = node.next;
|
848 | }
|
849 |
|
850 |
|
851 | if (listener !== null) {
|
852 | const newNode = {
|
853 | listener,
|
854 | listenerType: ATTRIBUTE,
|
855 | passive: false,
|
856 | once: false,
|
857 | next: null,
|
858 | };
|
859 | if (prev === null) {
|
860 | listeners.set(eventName, newNode);
|
861 | } else {
|
862 | prev.next = newNode;
|
863 | }
|
864 | }
|
865 | },
|
866 | configurable: true,
|
867 | enumerable: true,
|
868 | }
|
869 | }
|
870 |
|
871 |
|
872 |
|
873 |
|
874 |
|
875 |
|
876 |
|
877 | function defineEventAttribute(eventTargetPrototype, eventName) {
|
878 | Object.defineProperty(
|
879 | eventTargetPrototype,
|
880 | `on${eventName}`,
|
881 | defineEventAttributeDescriptor(eventName)
|
882 | );
|
883 | }
|
884 |
|
885 |
|
886 |
|
887 |
|
888 |
|
889 |
|
890 |
|
891 | function defineCustomEventTarget(eventNames) {
|
892 |
|
893 | function CustomEventTarget() {
|
894 | EventTarget.call(this);
|
895 | }
|
896 |
|
897 | CustomEventTarget.prototype = Object.create(EventTarget.prototype, {
|
898 | constructor: {
|
899 | value: CustomEventTarget,
|
900 | configurable: true,
|
901 | writable: true,
|
902 | },
|
903 | });
|
904 |
|
905 | for (let i = 0; i < eventNames.length; ++i) {
|
906 | defineEventAttribute(CustomEventTarget.prototype, eventNames[i]);
|
907 | }
|
908 |
|
909 | return CustomEventTarget
|
910 | }
|
911 |
|
912 |
|
913 |
|
914 |
|
915 |
|
916 |
|
917 |
|
918 |
|
919 |
|
920 |
|
921 |
|
922 |
|
923 |
|
924 |
|
925 | function EventTarget() {
|
926 |
|
927 | if (this instanceof EventTarget) {
|
928 | listenersMap.set(this, new Map());
|
929 | return
|
930 | }
|
931 | if (arguments.length === 1 && Array.isArray(arguments[0])) {
|
932 | return defineCustomEventTarget(arguments[0])
|
933 | }
|
934 | if (arguments.length > 0) {
|
935 | const types = new Array(arguments.length);
|
936 | for (let i = 0; i < arguments.length; ++i) {
|
937 | types[i] = arguments[i];
|
938 | }
|
939 | return defineCustomEventTarget(types)
|
940 | }
|
941 | throw new TypeError("Cannot call a class as a function")
|
942 |
|
943 | }
|
944 |
|
945 |
|
946 | EventTarget.prototype = {
|
947 | |
948 |
|
949 |
|
950 |
|
951 |
|
952 |
|
953 |
|
954 | addEventListener(eventName, listener, options) {
|
955 | if (listener == null) {
|
956 | return
|
957 | }
|
958 | if (typeof listener !== "function" && !isObject(listener)) {
|
959 | throw new TypeError("'listener' should be a function or an object.")
|
960 | }
|
961 |
|
962 | const listeners = getListeners(this);
|
963 | const optionsIsObj = isObject(options);
|
964 | const capture = optionsIsObj
|
965 | ? Boolean(options.capture)
|
966 | : Boolean(options);
|
967 | const listenerType = capture ? CAPTURE : BUBBLE;
|
968 | const newNode = {
|
969 | listener,
|
970 | listenerType,
|
971 | passive: optionsIsObj && Boolean(options.passive),
|
972 | once: optionsIsObj && Boolean(options.once),
|
973 | next: null,
|
974 | };
|
975 |
|
976 |
|
977 | let node = listeners.get(eventName);
|
978 | if (node === undefined) {
|
979 | listeners.set(eventName, newNode);
|
980 | return
|
981 | }
|
982 |
|
983 |
|
984 | let prev = null;
|
985 | while (node != null) {
|
986 | if (
|
987 | node.listener === listener &&
|
988 | node.listenerType === listenerType
|
989 | ) {
|
990 |
|
991 | return
|
992 | }
|
993 | prev = node;
|
994 | node = node.next;
|
995 | }
|
996 |
|
997 |
|
998 | prev.next = newNode;
|
999 | },
|
1000 |
|
1001 | |
1002 |
|
1003 |
|
1004 |
|
1005 |
|
1006 |
|
1007 |
|
1008 | removeEventListener(eventName, listener, options) {
|
1009 | if (listener == null) {
|
1010 | return
|
1011 | }
|
1012 |
|
1013 | const listeners = getListeners(this);
|
1014 | const capture = isObject(options)
|
1015 | ? Boolean(options.capture)
|
1016 | : Boolean(options);
|
1017 | const listenerType = capture ? CAPTURE : BUBBLE;
|
1018 |
|
1019 | let prev = null;
|
1020 | let node = listeners.get(eventName);
|
1021 | while (node != null) {
|
1022 | if (
|
1023 | node.listener === listener &&
|
1024 | node.listenerType === listenerType
|
1025 | ) {
|
1026 | if (prev !== null) {
|
1027 | prev.next = node.next;
|
1028 | } else if (node.next !== null) {
|
1029 | listeners.set(eventName, node.next);
|
1030 | } else {
|
1031 | listeners.delete(eventName);
|
1032 | }
|
1033 | return
|
1034 | }
|
1035 |
|
1036 | prev = node;
|
1037 | node = node.next;
|
1038 | }
|
1039 | },
|
1040 |
|
1041 | |
1042 |
|
1043 |
|
1044 |
|
1045 |
|
1046 | dispatchEvent(event) {
|
1047 | if (event == null || typeof event.type !== "string") {
|
1048 | throw new TypeError('"event.type" should be a string.')
|
1049 | }
|
1050 |
|
1051 |
|
1052 | const listeners = getListeners(this);
|
1053 | const eventName = event.type;
|
1054 | let node = listeners.get(eventName);
|
1055 | if (node == null) {
|
1056 | return true
|
1057 | }
|
1058 |
|
1059 |
|
1060 | const wrappedEvent = wrapEvent(this, event);
|
1061 |
|
1062 |
|
1063 |
|
1064 | let prev = null;
|
1065 | while (node != null) {
|
1066 |
|
1067 | if (node.once) {
|
1068 | if (prev !== null) {
|
1069 | prev.next = node.next;
|
1070 | } else if (node.next !== null) {
|
1071 | listeners.set(eventName, node.next);
|
1072 | } else {
|
1073 | listeners.delete(eventName);
|
1074 | }
|
1075 | } else {
|
1076 | prev = node;
|
1077 | }
|
1078 |
|
1079 |
|
1080 | setPassiveListener(
|
1081 | wrappedEvent,
|
1082 | node.passive ? node.listener : null
|
1083 | );
|
1084 | if (typeof node.listener === "function") {
|
1085 | try {
|
1086 | node.listener.call(this, wrappedEvent);
|
1087 | } catch (err) {
|
1088 | if (
|
1089 | typeof console !== "undefined" &&
|
1090 | typeof console.error === "function"
|
1091 | ) {
|
1092 | console.error(err);
|
1093 | }
|
1094 | }
|
1095 | } else if (
|
1096 | node.listenerType !== ATTRIBUTE &&
|
1097 | typeof node.listener.handleEvent === "function"
|
1098 | ) {
|
1099 | node.listener.handleEvent(wrappedEvent);
|
1100 | }
|
1101 |
|
1102 |
|
1103 | if (isStopped(wrappedEvent)) {
|
1104 | break
|
1105 | }
|
1106 |
|
1107 | node = node.next;
|
1108 | }
|
1109 | setPassiveListener(wrappedEvent, null);
|
1110 | setEventPhase(wrappedEvent, 0);
|
1111 | setCurrentTarget(wrappedEvent, null);
|
1112 |
|
1113 | return !wrappedEvent.defaultPrevented
|
1114 | },
|
1115 | };
|
1116 |
|
1117 |
|
1118 | Object.defineProperty(EventTarget.prototype, "constructor", {
|
1119 | value: EventTarget,
|
1120 | configurable: true,
|
1121 | writable: true,
|
1122 | });
|
1123 |
|
1124 |
|
1125 | if (
|
1126 | typeof window !== "undefined" &&
|
1127 | typeof window.EventTarget !== "undefined"
|
1128 | ) {
|
1129 | Object.setPrototypeOf(EventTarget.prototype, window.EventTarget.prototype);
|
1130 | }
|
1131 |
|
1132 | var WS = (function (_super) {
|
1133 | __extends$1(WS, _super);
|
1134 | function WS(url, protocol) {
|
1135 | var _this = _super.call(this) || this;
|
1136 | _this._readyState = WS.CLOSED;
|
1137 | if (!url) {
|
1138 | throw new TypeError("Failed to construct 'WebSocket': url required");
|
1139 | }
|
1140 | _this._url = url;
|
1141 | _this._protocol = protocol;
|
1142 | return _this;
|
1143 | }
|
1144 | Object.defineProperty(WS.prototype, "url", {
|
1145 | get: function () {
|
1146 | return this._url;
|
1147 | },
|
1148 | enumerable: false,
|
1149 | configurable: true
|
1150 | });
|
1151 | Object.defineProperty(WS.prototype, "protocol", {
|
1152 | get: function () {
|
1153 | return this._protocol;
|
1154 | },
|
1155 | enumerable: false,
|
1156 | configurable: true
|
1157 | });
|
1158 | Object.defineProperty(WS.prototype, "readyState", {
|
1159 | get: function () {
|
1160 | return this._readyState;
|
1161 | },
|
1162 | enumerable: false,
|
1163 | configurable: true
|
1164 | });
|
1165 | WS.CONNECTING = 0;
|
1166 | WS.OPEN = 1;
|
1167 | WS.CLOSING = 2;
|
1168 | WS.CLOSED = 3;
|
1169 | return WS;
|
1170 | }(EventTarget("open", "error", "message", "close")));
|
1171 | var WechatWS = (function (_super) {
|
1172 | __extends$1(WechatWS, _super);
|
1173 | function WechatWS(url, protocol) {
|
1174 | var _this = _super.call(this, url, protocol) || this;
|
1175 | if (protocol &&
|
1176 | !(wx.canIUse && wx.canIUse("connectSocket.object.protocols"))) {
|
1177 | throw new Error("subprotocol not supported in weapp");
|
1178 | }
|
1179 | _this._readyState = WS.CONNECTING;
|
1180 | var errorHandler = function (event) {
|
1181 | _this._readyState = WS.CLOSED;
|
1182 | _this.dispatchEvent({
|
1183 | type: "error",
|
1184 | message: event.errMsg,
|
1185 | });
|
1186 | };
|
1187 | var socketTask = wx.connectSocket({
|
1188 | url: url,
|
1189 | protocols: _this._protocol === undefined || Array.isArray(_this._protocol)
|
1190 | ? _this._protocol
|
1191 | : [_this._protocol],
|
1192 | fail: function (error) { return setTimeout(function () { return errorHandler(error); }, 0); },
|
1193 | });
|
1194 | _this._socketTask = socketTask;
|
1195 | socketTask.onOpen(function () {
|
1196 | _this._readyState = WS.OPEN;
|
1197 | _this.dispatchEvent({
|
1198 | type: "open",
|
1199 | });
|
1200 | });
|
1201 | socketTask.onError(errorHandler);
|
1202 | socketTask.onMessage(function (event) {
|
1203 | var data = event.data;
|
1204 | _this.dispatchEvent({
|
1205 | data: data,
|
1206 | type: "message",
|
1207 | });
|
1208 | });
|
1209 | socketTask.onClose(function (event) {
|
1210 | _this._readyState = WS.CLOSED;
|
1211 | var code = event.code, reason = event.reason;
|
1212 | _this.dispatchEvent({
|
1213 | code: code,
|
1214 | reason: reason,
|
1215 | type: "close",
|
1216 | });
|
1217 | });
|
1218 | return _this;
|
1219 | }
|
1220 | WechatWS.prototype.close = function () {
|
1221 | if (this.readyState === WS.CLOSED)
|
1222 | return;
|
1223 | if (this.readyState === WS.CONNECTING) {
|
1224 | console.warn("close WebSocket which is connecting might not work");
|
1225 | }
|
1226 | this._socketTask.close({});
|
1227 | };
|
1228 | WechatWS.prototype.send = function (data) {
|
1229 | if (this.readyState !== WS.OPEN) {
|
1230 | throw new Error("INVALID_STATE_ERR");
|
1231 | }
|
1232 | if (!(typeof data === "string" || data instanceof ArrayBuffer)) {
|
1233 | throw new TypeError("only String/ArrayBuffer supported");
|
1234 | }
|
1235 | this._socketTask.send({
|
1236 | data: data,
|
1237 | });
|
1238 | };
|
1239 | return WechatWS;
|
1240 | }(WS));
|
1241 | var WebSocket = WechatWS;
|
1242 |
|
1243 | var platformInfo$1 = {
|
1244 | name: "Weapp",
|
1245 | };
|
1246 |
|
1247 | var WebSocket_1 = lib.WebSocket = WebSocket;
|
1248 | var getAuthInfo_1 = lib.getAuthInfo = getAuthInfo$1;
|
1249 | lib.platformInfo = platformInfo$1;
|
1250 | var request_1 = lib.request = request;
|
1251 | var storage_1 = lib.storage = storage;
|
1252 | var upload_1 = lib.upload = upload;
|
1253 |
|
1254 |
|
1255 |
|
1256 |
|
1257 |
|
1258 |
|
1259 |
|
1260 |
|
1261 |
|
1262 |
|
1263 |
|
1264 |
|
1265 |
|
1266 |
|
1267 |
|
1268 |
|
1269 | function __awaiter(thisArg, _arguments, P, generator) {
|
1270 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
1271 | return new (P || (P = Promise))(function (resolve, reject) {
|
1272 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
1273 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
1274 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
1275 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
1276 | });
|
1277 | }
|
1278 |
|
1279 | function __generator(thisArg, body) {
|
1280 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
1281 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
1282 | function verb(n) { return function (v) { return step([n, v]); }; }
|
1283 | function step(op) {
|
1284 | if (f) throw new TypeError("Generator is already executing.");
|
1285 | while (_) try {
|
1286 | 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;
|
1287 | if (y = 0, t) op = [op[0] & 2, t.value];
|
1288 | switch (op[0]) {
|
1289 | case 0: case 1: t = op; break;
|
1290 | case 4: _.label++; return { value: op[1], done: false };
|
1291 | case 5: _.label++; y = op[1]; op = [0]; continue;
|
1292 | case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
1293 | default:
|
1294 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
1295 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
1296 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
1297 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
1298 | if (t[2]) _.ops.pop();
|
1299 | _.trys.pop(); continue;
|
1300 | }
|
1301 | op = body.call(thisArg, _);
|
1302 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
1303 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
1304 | }
|
1305 | }
|
1306 |
|
1307 | var PROVIDER = "lc_qqapp";
|
1308 | var PLATFORM = "qq";
|
1309 | var getAuthInfo = function (_a) {
|
1310 | 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;
|
1311 | return __awaiter(this, void 0, void 0, function () {
|
1312 | var authInfo;
|
1313 | return __generator(this, function (_f) {
|
1314 | switch (_f.label) {
|
1315 | case 0: return [4 , getAuthInfo_1({
|
1316 | platform: platform,
|
1317 | preferUnionId: preferUnionId,
|
1318 | asMainAccount: asMainAccount,
|
1319 | })];
|
1320 | case 1:
|
1321 | authInfo = _f.sent();
|
1322 | authInfo.provider = PROVIDER;
|
1323 | return [2 , authInfo];
|
1324 | }
|
1325 | });
|
1326 | });
|
1327 | };
|
1328 |
|
1329 | var platformInfo = {
|
1330 | name: "QQApp",
|
1331 | };
|
1332 |
|
1333 | exports.WebSocket = WebSocket_1;
|
1334 | exports.getAuthInfo = getAuthInfo;
|
1335 | exports.platformInfo = platformInfo;
|
1336 | exports.request = request_1;
|
1337 | exports.storage = storage_1;
|
1338 | exports.upload = upload_1;
|
1339 |
|