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