UNPKG

43.4 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', { value: true });
4
5var lib = {};
6
7Object.defineProperty(lib, '__esModule', { value: true });
8
9/******************************************************************************
10Copyright (c) Microsoft Corporation.
11
12Permission to use, copy, modify, and/or distribute this software for any
13purpose with or without fee is hereby granted.
14
15THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
16REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
17AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
18INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
19LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
20OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
21PERFORMANCE OF THIS SOFTWARE.
22***************************************************************************** */
23/* global Reflect, Promise */
24
25var 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
32function __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
40var __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
51function __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
63function __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
73function __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
101var PROVIDER$1 = "lc_weapp";
102var PLATFORM$1 = "weixin";
103function 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}
116var 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 /*yield*/, 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 /*return*/, {
131 authData: authData,
132 platform: platform,
133 provider: PROVIDER$1,
134 }];
135 }
136 });
137 });
138};
139
140var 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/******************************************************************************
156Copyright (c) Microsoft Corporation.
157
158Permission to use, copy, modify, and/or distribute this software for any
159purpose with or without fee is hereby granted.
160
161THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
162REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
163AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
164INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
165LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
166OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
167PERFORMANCE OF THIS SOFTWARE.
168***************************************************************************** */
169/* global Reflect, Promise */
170
171var 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
178function __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
186var AbortError = /** @class */ (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
196var 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};
229var 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 * @author Toru Nagashima <https://github.com/mysticatea>
275 * @copyright 2015 Toru Nagashima. All rights reserved.
276 * See LICENSE file in root directory for full license.
277 */
278/**
279 * @typedef {object} PrivateData
280 * @property {EventTarget} eventTarget The event target.
281 * @property {{type:string}} event The original event object.
282 * @property {number} eventPhase The current event phase.
283 * @property {EventTarget|null} currentTarget The current event target.
284 * @property {boolean} canceled The flag to prevent default.
285 * @property {boolean} stopped The flag to stop propagation.
286 * @property {boolean} immediateStopped The flag to stop propagation immediately.
287 * @property {Function|null} passiveListener The listener if the current listener is passive. Otherwise this is null.
288 * @property {number} timeStamp The unix time.
289 * @private
290 */
291
292/**
293 * Private data for event wrappers.
294 * @type {WeakMap<Event, PrivateData>}
295 * @private
296 */
297const privateData = new WeakMap();
298
299/**
300 * Cache for wrapper classes.
301 * @type {WeakMap<Object, Function>}
302 * @private
303 */
304const wrappers = new WeakMap();
305
306/**
307 * Get private data.
308 * @param {Event} event The event object to get private data.
309 * @returns {PrivateData} The private data of the event.
310 * @private
311 */
312function 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 * https://dom.spec.whatwg.org/#set-the-canceled-flag
324 * @param data {PrivateData} private data.
325 */
326function 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 * @see https://dom.spec.whatwg.org/#interface-event
351 * @private
352 */
353/**
354 * The event wrapper.
355 * @constructor
356 * @param {EventTarget} eventTarget The event target of this dispatching.
357 * @param {Event|{type:string}} event The original event to wrap.
358 */
359function 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 // https://heycam.github.io/webidl/#Unforgeable
373 Object.defineProperty(this, "isTrusted", { value: false, enumerable: true });
374
375 // Define accessors
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// Should be enumerable, but class methods are not enumerable.
386Event.prototype = {
387 /**
388 * The type of this event.
389 * @type {string}
390 */
391 get type() {
392 return pd(this).event.type
393 },
394
395 /**
396 * The target of this event.
397 * @type {EventTarget}
398 */
399 get target() {
400 return pd(this).eventTarget
401 },
402
403 /**
404 * The target of this event.
405 * @type {EventTarget}
406 */
407 get currentTarget() {
408 return pd(this).currentTarget
409 },
410
411 /**
412 * @returns {EventTarget[]} The composed path of this event.
413 */
414 composedPath() {
415 const currentTarget = pd(this).currentTarget;
416 if (currentTarget == null) {
417 return []
418 }
419 return [currentTarget]
420 },
421
422 /**
423 * Constant of NONE.
424 * @type {number}
425 */
426 get NONE() {
427 return 0
428 },
429
430 /**
431 * Constant of CAPTURING_PHASE.
432 * @type {number}
433 */
434 get CAPTURING_PHASE() {
435 return 1
436 },
437
438 /**
439 * Constant of AT_TARGET.
440 * @type {number}
441 */
442 get AT_TARGET() {
443 return 2
444 },
445
446 /**
447 * Constant of BUBBLING_PHASE.
448 * @type {number}
449 */
450 get BUBBLING_PHASE() {
451 return 3
452 },
453
454 /**
455 * The target of this event.
456 * @type {number}
457 */
458 get eventPhase() {
459 return pd(this).eventPhase
460 },
461
462 /**
463 * Stop event bubbling.
464 * @returns {void}
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 * Stop event bubbling.
477 * @returns {void}
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 * The flag to be bubbling.
491 * @type {boolean}
492 */
493 get bubbles() {
494 return Boolean(pd(this).event.bubbles)
495 },
496
497 /**
498 * The flag to be cancelable.
499 * @type {boolean}
500 */
501 get cancelable() {
502 return Boolean(pd(this).event.cancelable)
503 },
504
505 /**
506 * Cancel this event.
507 * @returns {void}
508 */
509 preventDefault() {
510 setCancelFlag(pd(this));
511 },
512
513 /**
514 * The flag to indicate cancellation state.
515 * @type {boolean}
516 */
517 get defaultPrevented() {
518 return pd(this).canceled
519 },
520
521 /**
522 * The flag to be composed.
523 * @type {boolean}
524 */
525 get composed() {
526 return Boolean(pd(this).event.composed)
527 },
528
529 /**
530 * The unix time of this event.
531 * @type {number}
532 */
533 get timeStamp() {
534 return pd(this).timeStamp
535 },
536
537 /**
538 * The target of this event.
539 * @type {EventTarget}
540 * @deprecated
541 */
542 get srcElement() {
543 return pd(this).eventTarget
544 },
545
546 /**
547 * The flag to stop event bubbling.
548 * @type {boolean}
549 * @deprecated
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 * The flag to indicate cancellation state.
568 * @type {boolean}
569 * @deprecated
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 * Initialize this event object. But do nothing under event dispatching.
582 * @param {string} type The event type.
583 * @param {boolean} [bubbles=false] The flag to be possible to bubble up.
584 * @param {boolean} [cancelable=false] The flag to be possible to cancel.
585 * @deprecated
586 */
587 initEvent() {
588 // Do nothing.
589 },
590};
591
592// `constructor` is not enumerable.
593Object.defineProperty(Event.prototype, "constructor", {
594 value: Event,
595 configurable: true,
596 writable: true,
597});
598
599// Ensure `event instanceof window.Event` is `true`.
600if (typeof window !== "undefined" && typeof window.Event !== "undefined") {
601 Object.setPrototypeOf(Event.prototype, window.Event.prototype);
602
603 // Make association for wrappers.
604 wrappers.set(window.Event.prototype, Event);
605}
606
607/**
608 * Get the property descriptor to redirect a given property.
609 * @param {string} key Property name to define property descriptor.
610 * @returns {PropertyDescriptor} The property descriptor to redirect the property.
611 * @private
612 */
613function 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 * Get the property descriptor to call a given method property.
628 * @param {string} key Property name to define property descriptor.
629 * @returns {PropertyDescriptor} The property descriptor to call the method property.
630 * @private
631 */
632function 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 * Define new wrapper class.
645 * @param {Function} BaseEvent The base wrapper class.
646 * @param {Object} proto The prototype of the original event.
647 * @returns {Function} The defined wrapper class.
648 * @private
649 */
650function defineWrapper(BaseEvent, proto) {
651 const keys = Object.keys(proto);
652 if (keys.length === 0) {
653 return BaseEvent
654 }
655
656 /** CustomEvent */
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 // Define accessors.
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 * Get the wrapper class of a given prototype.
686 * @param {Object} proto The prototype of the original event to get its wrapper.
687 * @returns {Function} The wrapper class.
688 * @private
689 */
690function 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 * Wrap a given event to management a dispatching.
705 * @param {EventTarget} eventTarget The event target of this dispatching.
706 * @param {Object} event The event to wrap.
707 * @returns {Event} The wrapper instance.
708 * @private
709 */
710function wrapEvent(eventTarget, event) {
711 const Wrapper = getWrapper(Object.getPrototypeOf(event));
712 return new Wrapper(eventTarget, event)
713}
714
715/**
716 * Get the immediateStopped flag of a given event.
717 * @param {Event} event The event to get.
718 * @returns {boolean} The flag to stop propagation immediately.
719 * @private
720 */
721function isStopped(event) {
722 return pd(event).immediateStopped
723}
724
725/**
726 * Set the current event phase of a given event.
727 * @param {Event} event The event to set current target.
728 * @param {number} eventPhase New event phase.
729 * @returns {void}
730 * @private
731 */
732function setEventPhase(event, eventPhase) {
733 pd(event).eventPhase = eventPhase;
734}
735
736/**
737 * Set the current target of a given event.
738 * @param {Event} event The event to set current target.
739 * @param {EventTarget|null} currentTarget New current target.
740 * @returns {void}
741 * @private
742 */
743function setCurrentTarget(event, currentTarget) {
744 pd(event).currentTarget = currentTarget;
745}
746
747/**
748 * Set a passive listener of a given event.
749 * @param {Event} event The event to set current target.
750 * @param {Function|null} passiveListener New passive listener.
751 * @returns {void}
752 * @private
753 */
754function setPassiveListener(event, passiveListener) {
755 pd(event).passiveListener = passiveListener;
756}
757
758/**
759 * @typedef {object} ListenerNode
760 * @property {Function} listener
761 * @property {1|2|3} listenerType
762 * @property {boolean} passive
763 * @property {boolean} once
764 * @property {ListenerNode|null} next
765 * @private
766 */
767
768/**
769 * @type {WeakMap<object, Map<string, ListenerNode>>}
770 * @private
771 */
772const listenersMap = new WeakMap();
773
774// Listener types
775const CAPTURE = 1;
776const BUBBLE = 2;
777const ATTRIBUTE = 3;
778
779/**
780 * Check whether a given value is an object or not.
781 * @param {any} x The value to check.
782 * @returns {boolean} `true` if the value is an object.
783 */
784function isObject(x) {
785 return x !== null && typeof x === "object" //eslint-disable-line no-restricted-syntax
786}
787
788/**
789 * Get listeners.
790 * @param {EventTarget} eventTarget The event target to get.
791 * @returns {Map<string, ListenerNode>} The listeners.
792 * @private
793 */
794function 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 * Get the property descriptor for the event attribute of a given event.
806 * @param {string} eventName The event name to get property descriptor.
807 * @returns {PropertyDescriptor} The property descriptor.
808 * @private
809 */
810function 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; // eslint-disable-line no-param-reassign
827 }
828 const listeners = getListeners(this);
829
830 // Traverse to the tail while removing old value.
831 let prev = null;
832 let node = listeners.get(eventName);
833 while (node != null) {
834 if (node.listenerType === ATTRIBUTE) {
835 // Remove old value.
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 // Add new value.
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 * Define an event attribute (e.g. `eventTarget.onclick`).
873 * @param {Object} eventTargetPrototype The event target prototype to define an event attrbite.
874 * @param {string} eventName The event name to define.
875 * @returns {void}
876 */
877function defineEventAttribute(eventTargetPrototype, eventName) {
878 Object.defineProperty(
879 eventTargetPrototype,
880 `on${eventName}`,
881 defineEventAttributeDescriptor(eventName)
882 );
883}
884
885/**
886 * Define a custom EventTarget with event attributes.
887 * @param {string[]} eventNames Event names for event attributes.
888 * @returns {EventTarget} The custom EventTarget.
889 * @private
890 */
891function defineCustomEventTarget(eventNames) {
892 /** CustomEventTarget */
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 * EventTarget.
914 *
915 * - This is constructor if no arguments.
916 * - This is a function which returns a CustomEventTarget constructor if there are arguments.
917 *
918 * For example:
919 *
920 * class A extends EventTarget {}
921 * class B extends EventTarget("message") {}
922 * class C extends EventTarget("message", "error") {}
923 * class D extends EventTarget(["message", "error"]) {}
924 */
925function EventTarget() {
926 /*eslint-disable consistent-return */
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 /*eslint-enable consistent-return */
943}
944
945// Should be enumerable, but class methods are not enumerable.
946EventTarget.prototype = {
947 /**
948 * Add a given listener to this event target.
949 * @param {string} eventName The event name to add.
950 * @param {Function} listener The listener to add.
951 * @param {boolean|{capture?:boolean,passive?:boolean,once?:boolean}} [options] The options for this listener.
952 * @returns {void}
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 // Set it as the first node if the first node is null.
977 let node = listeners.get(eventName);
978 if (node === undefined) {
979 listeners.set(eventName, newNode);
980 return
981 }
982
983 // Traverse to the tail while checking duplication..
984 let prev = null;
985 while (node != null) {
986 if (
987 node.listener === listener &&
988 node.listenerType === listenerType
989 ) {
990 // Should ignore duplication.
991 return
992 }
993 prev = node;
994 node = node.next;
995 }
996
997 // Add it.
998 prev.next = newNode;
999 },
1000
1001 /**
1002 * Remove a given listener from this event target.
1003 * @param {string} eventName The event name to remove.
1004 * @param {Function} listener The listener to remove.
1005 * @param {boolean|{capture?:boolean,passive?:boolean,once?:boolean}} [options] The options for this listener.
1006 * @returns {void}
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 * Dispatch a given event.
1043 * @param {Event|{type:string}} event The event to dispatch.
1044 * @returns {boolean} `false` if canceled.
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 // If listeners aren't registered, terminate.
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 // Since we cannot rewrite several properties, so wrap object.
1060 const wrappedEvent = wrapEvent(this, event);
1061
1062 // This doesn't process capturing phase and bubbling phase.
1063 // This isn't participating in a tree.
1064 let prev = null;
1065 while (node != null) {
1066 // Remove this listener if it's once
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 // Call this listener
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 // Break if `event.stopImmediatePropagation` was called.
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// `constructor` is not enumerable.
1118Object.defineProperty(EventTarget.prototype, "constructor", {
1119 value: EventTarget,
1120 configurable: true,
1121 writable: true,
1122});
1123
1124// Ensure `eventTarget instanceof window.EventTarget` is `true`.
1125if (
1126 typeof window !== "undefined" &&
1127 typeof window.EventTarget !== "undefined"
1128) {
1129 Object.setPrototypeOf(EventTarget.prototype, window.EventTarget.prototype);
1130}
1131
1132var WS = /** @class */ (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")));
1171var WechatWS = /** @class */ (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));
1241var WebSocket = WechatWS;
1242
1243var platformInfo$1 = {
1244 name: "Weapp",
1245};
1246
1247var WebSocket_1 = lib.WebSocket = WebSocket;
1248var getAuthInfo_1 = lib.getAuthInfo = getAuthInfo$1;
1249lib.platformInfo = platformInfo$1;
1250var request_1 = lib.request = request;
1251var storage_1 = lib.storage = storage;
1252var upload_1 = lib.upload = upload;
1253
1254/******************************************************************************
1255Copyright (c) Microsoft Corporation.
1256
1257Permission to use, copy, modify, and/or distribute this software for any
1258purpose with or without fee is hereby granted.
1259
1260THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
1261REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
1262AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
1263INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
1264LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
1265OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1266PERFORMANCE OF THIS SOFTWARE.
1267***************************************************************************** */
1268
1269function __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
1279function __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
1307var PROVIDER = "lc_qqapp";
1308var PLATFORM = "qq";
1309var 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 /*yield*/, 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 /*return*/, authInfo];
1324 }
1325 });
1326 });
1327};
1328
1329var platformInfo = {
1330 name: "QQApp",
1331};
1332
1333exports.WebSocket = WebSocket_1;
1334exports.getAuthInfo = getAuthInfo;
1335exports.platformInfo = platformInfo;
1336exports.request = request_1;
1337exports.storage = storage_1;
1338exports.upload = upload_1;
1339//# sourceMappingURL=index.js.map