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