@tarojs/taro-h5 3.5.0-beta.1 → 3.5.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,35 @@
1
+ import Taro from '@tarojs/api';
2
+ import { parse } from 'query-string';
1
3
  import { temporarilyNotSupport } from '../../../utils';
4
+ import { CallbackManager } from '../../../utils/handler';
5
+ const appShowCallbackManager = new CallbackManager();
6
+ const appHideCallbackManager = new CallbackManager();
7
+ const getApp = () => {
8
+ var _a;
9
+ const path = (_a = Taro.Current.page) === null || _a === void 0 ? void 0 : _a.path;
10
+ return {
11
+ /** 小程序切前台的路径 */
12
+ path: path === null || path === void 0 ? void 0 : path.substring(0, path.indexOf('?')),
13
+ /** 小程序切前台的 query 参数 */
14
+ query: parse(location.search),
15
+ /** 来源信息。 */
16
+ referrerInfo: {},
17
+ /** 小程序切前台的[场景值](https://developers.weixin.qq.com/miniprogram/dev/framework/app-service/scene.html) */
18
+ scene: 0,
19
+ /** shareTicket,详见[获取更多转发信息](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share.html) */
20
+ shareTicket: ''
21
+ };
22
+ };
23
+ const appShowListener = () => {
24
+ if (document.visibilityState !== 'hidden') {
25
+ appShowCallbackManager.trigger(getApp());
26
+ }
27
+ };
28
+ const appHideListener = () => {
29
+ if (document.visibilityState === 'hidden') {
30
+ appHideCallbackManager.trigger(getApp());
31
+ }
32
+ };
2
33
  // 应用级事件
3
34
  export const onUnhandledRejection = temporarilyNotSupport('onUnhandledRejection');
4
35
  export const onThemeChange = temporarilyNotSupport('onThemeChange');
@@ -6,13 +37,33 @@ export const onPageNotFound = temporarilyNotSupport('onPageNotFound');
6
37
  export const onError = temporarilyNotSupport('onError');
7
38
  export const onAudioInterruptionEnd = temporarilyNotSupport('onAudioInterruptionEnd');
8
39
  export const onAudioInterruptionBegin = temporarilyNotSupport('onAudioInterruptionBegin');
9
- export const onAppShow = temporarilyNotSupport('onAppShow');
10
- export const onAppHide = temporarilyNotSupport('onAppHide');
40
+ export const onAppShow = callback => {
41
+ appShowCallbackManager.add(callback);
42
+ if (appShowCallbackManager.count() === 1) {
43
+ window.addEventListener('visibilitychange', appShowListener);
44
+ }
45
+ };
46
+ export const onAppHide = callback => {
47
+ appHideCallbackManager.add(callback);
48
+ if (appHideCallbackManager.count() === 1) {
49
+ window.addEventListener('visibilitychange', appHideListener);
50
+ }
51
+ };
11
52
  export const offUnhandledRejection = temporarilyNotSupport('offUnhandledRejection');
12
53
  export const offThemeChange = temporarilyNotSupport('offThemeChange');
13
54
  export const offPageNotFound = temporarilyNotSupport('offPageNotFound');
14
55
  export const offError = temporarilyNotSupport('offError');
15
56
  export const offAudioInterruptionEnd = temporarilyNotSupport('offAudioInterruptionEnd');
16
57
  export const offAudioInterruptionBegin = temporarilyNotSupport('offAudioInterruptionBegin');
17
- export const offAppShow = temporarilyNotSupport('offAppShow');
18
- export const offAppHide = temporarilyNotSupport('offAppHide');
58
+ export const offAppShow = callback => {
59
+ appShowCallbackManager.remove(callback);
60
+ if (appShowCallbackManager.count() === 0) {
61
+ window.removeEventListener('visibilitychange', appShowListener);
62
+ }
63
+ };
64
+ export const offAppHide = callback => {
65
+ appHideCallbackManager.remove(callback);
66
+ if (appHideCallbackManager.count() === 0) {
67
+ window.removeEventListener('visibilitychange', appHideListener);
68
+ }
69
+ };
@@ -63,7 +63,7 @@ export class InnerAudioContext {
63
63
  get duration() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.duration) || 0; }
64
64
  set loop(e) { this.setProperty('loop', e); }
65
65
  get loop() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.loop) || false; }
66
- get paused() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.paused) || true; }
66
+ get paused() { var _a, _b; return (_b = (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.paused) !== null && _b !== void 0 ? _b : true; }
67
67
  set src(e) { this.setProperty('src', e); }
68
68
  get src() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.src) || ''; }
69
69
  set volume(e) { this.setProperty('volume', e); }
@@ -21,7 +21,7 @@ const createUploadTask = ({ url, filePath, formData = {}, name, header, timeout,
21
21
  callbackManager.progressUpdate.trigger({
22
22
  progress: Math.round(loaded / total * 100),
23
23
  totalBytesSent: loaded,
24
- totalBytesExpectedToSent: total
24
+ totalBytesExpectedToSend: total
25
25
  });
26
26
  };
27
27
  xhr.onreadystatechange = () => {
package/dist/index.cjs.js CHANGED
@@ -250,7 +250,7 @@ const getLogManager = temporarilyNotSupport('getLogManager');
250
250
  const reportPerformance = temporarilyNotSupport('reportPerformance');
251
251
  const getPerformance = temporarilyNotSupport('getPerformance');
252
252
 
253
- /*! *****************************************************************************
253
+ /******************************************************************************
254
254
  Copyright (c) Microsoft Corporation.
255
255
 
256
256
  Permission to use, copy, modify, and/or distribute this software for any
@@ -359,7 +359,11 @@ function __generator(thisArg, body) {
359
359
 
360
360
  var __createBinding = Object.create ? (function(o, m, k, k2) {
361
361
  if (k2 === undefined) k2 = k;
362
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
362
+ var desc = Object.getOwnPropertyDescriptor(m, k);
363
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
364
+ desc = { enumerable: true, get: function() { return m[k]; } };
365
+ }
366
+ Object.defineProperty(o, k2, desc);
363
367
  }) : (function(o, m, k, k2) {
364
368
  if (k2 === undefined) k2 = k;
365
369
  o[k2] = m[k];
@@ -488,6 +492,11 @@ function __classPrivateFieldSet(receiver, state, value, kind, f) {
488
492
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
489
493
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
490
494
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
495
+ }
496
+
497
+ function __classPrivateFieldIn(state, receiver) {
498
+ if (receiver === null || (typeof receiver !== "object" && typeof receiver !== "function")) throw new TypeError("Cannot use 'in' operator on non-object");
499
+ return typeof state === "function" ? receiver === state : state.has(receiver);
491
500
  }
492
501
 
493
502
  class MethodHandler {
@@ -755,6 +764,34 @@ const getSystemInfo = (options = {}) => __awaiter(void 0, void 0, void 0, functi
755
764
  const updateWeChatApp = temporarilyNotSupport('updateWeChatApp');
756
765
  const getUpdateManager = temporarilyNotSupport('getUpdateManager');
757
766
 
767
+ const appShowCallbackManager = new CallbackManager();
768
+ const appHideCallbackManager = new CallbackManager();
769
+ const getApp$1 = () => {
770
+ var _a;
771
+ const path = (_a = Taro__default["default"].Current.page) === null || _a === void 0 ? void 0 : _a.path;
772
+ return {
773
+ /** 小程序切前台的路径 */
774
+ path: path === null || path === void 0 ? void 0 : path.substring(0, path.indexOf('?')),
775
+ /** 小程序切前台的 query 参数 */
776
+ query: queryString.parse(location.search),
777
+ /** 来源信息。 */
778
+ referrerInfo: {},
779
+ /** 小程序切前台的[场景值](https://developers.weixin.qq.com/miniprogram/dev/framework/app-service/scene.html) */
780
+ scene: 0,
781
+ /** shareTicket,详见[获取更多转发信息](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share.html) */
782
+ shareTicket: ''
783
+ };
784
+ };
785
+ const appShowListener = () => {
786
+ if (document.visibilityState !== 'hidden') {
787
+ appShowCallbackManager.trigger(getApp$1());
788
+ }
789
+ };
790
+ const appHideListener = () => {
791
+ if (document.visibilityState === 'hidden') {
792
+ appHideCallbackManager.trigger(getApp$1());
793
+ }
794
+ };
758
795
  // 应用级事件
759
796
  const onUnhandledRejection = temporarilyNotSupport('onUnhandledRejection');
760
797
  const onThemeChange = temporarilyNotSupport('onThemeChange');
@@ -762,16 +799,36 @@ const onPageNotFound = temporarilyNotSupport('onPageNotFound');
762
799
  const onError = temporarilyNotSupport('onError');
763
800
  const onAudioInterruptionEnd = temporarilyNotSupport('onAudioInterruptionEnd');
764
801
  const onAudioInterruptionBegin = temporarilyNotSupport('onAudioInterruptionBegin');
765
- const onAppShow = temporarilyNotSupport('onAppShow');
766
- const onAppHide = temporarilyNotSupport('onAppHide');
802
+ const onAppShow = callback => {
803
+ appShowCallbackManager.add(callback);
804
+ if (appShowCallbackManager.count() === 1) {
805
+ window.addEventListener('visibilitychange', appShowListener);
806
+ }
807
+ };
808
+ const onAppHide = callback => {
809
+ appHideCallbackManager.add(callback);
810
+ if (appHideCallbackManager.count() === 1) {
811
+ window.addEventListener('visibilitychange', appHideListener);
812
+ }
813
+ };
767
814
  const offUnhandledRejection = temporarilyNotSupport('offUnhandledRejection');
768
815
  const offThemeChange = temporarilyNotSupport('offThemeChange');
769
816
  const offPageNotFound = temporarilyNotSupport('offPageNotFound');
770
817
  const offError = temporarilyNotSupport('offError');
771
818
  const offAudioInterruptionEnd = temporarilyNotSupport('offAudioInterruptionEnd');
772
819
  const offAudioInterruptionBegin = temporarilyNotSupport('offAudioInterruptionBegin');
773
- const offAppShow = temporarilyNotSupport('offAppShow');
774
- const offAppHide = temporarilyNotSupport('offAppHide');
820
+ const offAppShow = callback => {
821
+ appShowCallbackManager.remove(callback);
822
+ if (appShowCallbackManager.count() === 0) {
823
+ window.removeEventListener('visibilitychange', appShowListener);
824
+ }
825
+ };
826
+ const offAppHide = callback => {
827
+ appHideCallbackManager.remove(callback);
828
+ if (appHideCallbackManager.count() === 0) {
829
+ window.removeEventListener('visibilitychange', appHideListener);
830
+ }
831
+ };
775
832
 
776
833
  // 生命周期
777
834
  const getLaunchOptionsSync = temporarilyNotSupport('getLaunchOptionsSync');
@@ -2093,7 +2150,7 @@ class InnerAudioContext {
2093
2150
  get duration() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.duration) || 0; }
2094
2151
  set loop(e) { this.setProperty('loop', e); }
2095
2152
  get loop() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.loop) || false; }
2096
- get paused() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.paused) || true; }
2153
+ get paused() { var _a, _b; return (_b = (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.paused) !== null && _b !== void 0 ? _b : true; }
2097
2154
  set src(e) { this.setProperty('src', e); }
2098
2155
  get src() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.src) || ''; }
2099
2156
  set volume(e) { this.setProperty('volume', e); }
@@ -2902,7 +2959,7 @@ const createUploadTask = ({ url, filePath, formData = {}, name, header, timeout,
2902
2959
  callbackManager.progressUpdate.trigger({
2903
2960
  progress: Math.round(loaded / total * 100),
2904
2961
  totalBytesSent: loaded,
2905
- totalBytesExpectedToSent: total
2962
+ totalBytesExpectedToSend: total
2906
2963
  });
2907
2964
  };
2908
2965
  xhr.onreadystatechange = () => {