@tarojs/taro-h5 3.4.7 → 3.5.0-alpha.2

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.
Files changed (37) hide show
  1. package/dist/api/base/system.js +28 -24
  2. package/dist/api/canvas/CanvasContext.js +27 -16
  3. package/dist/api/device/accelerometer.js +9 -17
  4. package/dist/api/device/battery.js +12 -3
  5. package/dist/api/device/clipboard.js +13 -4
  6. package/dist/api/device/compass.js +32 -18
  7. package/dist/api/device/motion.js +8 -17
  8. package/dist/api/device/network.js +12 -3
  9. package/dist/api/location/chooseLocation.js +13 -8
  10. package/dist/api/media/image/previewImage.js +12 -3
  11. package/dist/api/taro.js +2 -3
  12. package/dist/api/ui/fonts.js +12 -3
  13. package/dist/api/ui/interaction/actionSheet.js +3 -12
  14. package/dist/api/ui/interaction/index.js +17 -8
  15. package/dist/api/ui/interaction/modal.js +6 -27
  16. package/dist/api/ui/interaction/toast.js +14 -40
  17. package/dist/api/utils/animation.js +14 -0
  18. package/dist/api/utils/index.js +3 -21
  19. package/dist/api/utils/lodash.js +29 -0
  20. package/dist/api/utils/valid.js +7 -0
  21. package/dist/dist/api/taro.d.ts +2 -2
  22. package/dist/dist/api/utils/animation.d.ts +6 -0
  23. package/dist/dist/api/utils/index.d.ts +3 -9
  24. package/dist/dist/api/utils/lodash.d.ts +2 -0
  25. package/dist/dist/api/utils/valid.d.ts +2 -0
  26. package/dist/index.cjs.js +424 -229
  27. package/dist/index.cjs.js.map +1 -1
  28. package/package.json +11 -12
  29. package/src/api/device/accelerometer.ts +8 -17
  30. package/src/api/device/compass.ts +34 -18
  31. package/src/api/device/motion.ts +9 -17
  32. package/src/api/taro.ts +2 -7
  33. package/src/api/ui/scroll/index.ts +1 -1
  34. package/src/api/utils/animation.ts +15 -0
  35. package/src/api/utils/index.ts +3 -25
  36. package/src/api/utils/lodash.ts +30 -0
  37. package/src/api/utils/valid.ts +8 -0
@@ -1,3 +1,12 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
1
10
  import MobileDetect from 'mobile-detect';
2
11
  import { temporarilyNotSupport } from '../utils';
3
12
  import { MethodHandler } from '../utils/handler';
@@ -125,44 +134,39 @@ export const getSystemInfoSync = () => {
125
134
  const appBaseInfo = getAppBaseInfo();
126
135
  const appAuthorizeSetting = getAppAuthorizeSetting();
127
136
  delete deviceInfo.abi;
128
- const info = {
129
- ...windowInfo,
130
- ...systemSetting,
131
- ...deviceInfo,
132
- ...appBaseInfo,
137
+ const info = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, windowInfo), systemSetting), deviceInfo), appBaseInfo), {
133
138
  /** 用户字体大小(单位px)。以微信客户端「我-设置-通用-字体大小」中的设置为准 */
134
- fontSizeSetting: NaN,
139
+ fontSizeSetting: NaN,
135
140
  /** 允许微信使用相册的开关(仅 iOS 有效) */
136
- albumAuthorized: appAuthorizeSetting.albumAuthorized === 'authorized',
141
+ albumAuthorized: appAuthorizeSetting.albumAuthorized === 'authorized',
137
142
  /** 允许微信使用摄像头的开关 */
138
- cameraAuthorized: appAuthorizeSetting.cameraAuthorized === 'authorized',
143
+ cameraAuthorized: appAuthorizeSetting.cameraAuthorized === 'authorized',
139
144
  /** 允许微信使用定位的开关 */
140
- locationAuthorized: appAuthorizeSetting.locationAuthorized === 'authorized',
145
+ locationAuthorized: appAuthorizeSetting.locationAuthorized === 'authorized',
141
146
  /** 允许微信使用麦克风的开关 */
142
- microphoneAuthorized: appAuthorizeSetting.microphoneAuthorized === 'authorized',
147
+ microphoneAuthorized: appAuthorizeSetting.microphoneAuthorized === 'authorized',
143
148
  /** 允许微信通知的开关 */
144
- notificationAuthorized: appAuthorizeSetting.notificationAuthorized === 'authorized',
149
+ notificationAuthorized: appAuthorizeSetting.notificationAuthorized === 'authorized',
145
150
  /** 允许微信通知带有提醒的开关(仅 iOS 有效) */
146
- notificationAlertAuthorized: appAuthorizeSetting.notificationAlertAuthorized === 'authorized',
151
+ notificationAlertAuthorized: appAuthorizeSetting.notificationAlertAuthorized === 'authorized',
147
152
  /** 允许微信通知带有标记的开关(仅 iOS 有效) */
148
- notificationBadgeAuthorized: appAuthorizeSetting.notificationBadgeAuthorized === 'authorized',
153
+ notificationBadgeAuthorized: appAuthorizeSetting.notificationBadgeAuthorized === 'authorized',
149
154
  /** 允许微信通知带有声音的开关(仅 iOS 有效) */
150
- notificationSoundAuthorized: appAuthorizeSetting.notificationSoundAuthorized === 'authorized',
155
+ notificationSoundAuthorized: appAuthorizeSetting.notificationSoundAuthorized === 'authorized',
151
156
  /** 允许微信使用日历的开关 */
152
- phoneCalendarAuthorized: appAuthorizeSetting.phoneCalendarAuthorized === 'authorized',
157
+ phoneCalendarAuthorized: appAuthorizeSetting.phoneCalendarAuthorized === 'authorized',
153
158
  /** `true` 表示模糊定位,`false` 表示精确定位,仅 iOS 支持 */
154
- locationReducedAccuracy: appAuthorizeSetting.locationReducedAccuracy,
159
+ locationReducedAccuracy: appAuthorizeSetting.locationReducedAccuracy,
155
160
  /** 小程序当前运行环境 */
156
- environment: ''
157
- };
161
+ environment: '' });
158
162
  return info;
159
163
  };
160
164
  /** 获取系统信息 */
161
- export const getSystemInfoAsync = async (options = {}) => {
165
+ export const getSystemInfoAsync = (options = {}) => __awaiter(void 0, void 0, void 0, function* () {
162
166
  const { success, fail, complete } = options;
163
167
  const handle = new MethodHandler({ name: 'getSystemInfoAsync', success, fail, complete });
164
168
  try {
165
- const info = await getSystemInfoSync();
169
+ const info = yield getSystemInfoSync();
166
170
  return handle.success(info);
167
171
  }
168
172
  catch (error) {
@@ -170,13 +174,13 @@ export const getSystemInfoAsync = async (options = {}) => {
170
174
  errMsg: error
171
175
  });
172
176
  }
173
- };
177
+ });
174
178
  /** 获取系统信息 */
175
- export const getSystemInfo = async (options = {}) => {
179
+ export const getSystemInfo = (options = {}) => __awaiter(void 0, void 0, void 0, function* () {
176
180
  const { success, fail, complete } = options;
177
181
  const handle = new MethodHandler({ name: 'getSystemInfo', success, fail, complete });
178
182
  try {
179
- const info = await getSystemInfoSync();
183
+ const info = yield getSystemInfoSync();
180
184
  return handle.success(info);
181
185
  }
182
186
  catch (error) {
@@ -184,4 +188,4 @@ export const getSystemInfo = async (options = {}) => {
184
188
  errMsg: error
185
189
  });
186
190
  }
187
- };
191
+ });
@@ -1,3 +1,12 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
1
10
  const TextBaseLineMap = {
2
11
  top: 'top',
3
12
  bottom: 'bottom',
@@ -81,24 +90,26 @@ export class CanvasContext {
81
90
  * 将之前在绘图上下文中的描述(路径、变形、样式)画到 canvas 中。
82
91
  * @todo 每次 draw 都会读取 width 和 height
83
92
  */
84
- async draw(reserve, callback) {
85
- try {
86
- if (!reserve) {
87
- this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
93
+ draw(reserve, callback) {
94
+ return __awaiter(this, void 0, void 0, function* () {
95
+ try {
96
+ if (!reserve) {
97
+ this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
98
+ }
99
+ // 部分 action 是异步的
100
+ for (const { func, args } of this.actions) {
101
+ yield func.apply(this.ctx, args);
102
+ }
103
+ this.emptyActions();
104
+ callback && callback();
88
105
  }
89
- // 部分 action 是异步的
90
- for (const { func, args } of this.actions) {
91
- await func.apply(this.ctx, args);
106
+ catch (e) {
107
+ /* eslint-disable no-throw-literal */
108
+ throw {
109
+ errMsg: e.message
110
+ };
92
111
  }
93
- this.emptyActions();
94
- callback && callback();
95
- }
96
- catch (e) {
97
- /* eslint-disable no-throw-literal */
98
- throw {
99
- errMsg: e.message
100
- };
101
- }
112
+ });
102
113
  }
103
114
  drawImage(imageResource, ...extra) {
104
115
  this.enqueueActions(() => {
@@ -1,3 +1,4 @@
1
+ import { throttle } from '../utils';
1
2
  import { CallbackManager, MethodHandler } from '../utils/handler';
2
3
  const callbackManager = new CallbackManager();
3
4
  let devicemotionListener;
@@ -30,22 +31,6 @@ const INTERVAL_MAP = {
30
31
  frequency: 5
31
32
  }
32
33
  };
33
- const getDevicemotionListener = interval => {
34
- let lock;
35
- let timer;
36
- return evt => {
37
- if (lock)
38
- return;
39
- lock = true;
40
- timer && clearTimeout(timer);
41
- callbackManager.trigger({
42
- x: evt.acceleration.x || 0,
43
- y: evt.acceleration.y || 0,
44
- z: evt.acceleration.z || 0
45
- });
46
- timer = setTimeout(() => { lock = false; }, interval);
47
- };
48
- };
49
34
  /**
50
35
  * 开始监听加速度数据。
51
36
  */
@@ -57,7 +42,14 @@ export const startAccelerometer = ({ interval = 'normal', success, fail, complet
57
42
  if (devicemotionListener) {
58
43
  stopAccelerometer();
59
44
  }
60
- devicemotionListener = getDevicemotionListener(intervalObj.interval);
45
+ devicemotionListener = throttle((evt) => {
46
+ var _a, _b, _c;
47
+ callbackManager.trigger({
48
+ x: ((_a = evt.acceleration) === null || _a === void 0 ? void 0 : _a.x) || 0,
49
+ y: ((_b = evt.acceleration) === null || _b === void 0 ? void 0 : _b.y) || 0,
50
+ z: ((_c = evt.acceleration) === null || _c === void 0 ? void 0 : _c.z) || 0
51
+ });
52
+ }, intervalObj.interval);
61
53
  window.addEventListener('devicemotion', devicemotionListener, true);
62
54
  }
63
55
  else {
@@ -1,13 +1,22 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
1
10
  import { temporarilyNotSupport } from '../utils';
2
11
  import { MethodHandler } from '../utils/handler';
3
12
  // 电量
4
13
  export const getBatteryInfoSync = temporarilyNotSupport('getBatteryInfoSync');
5
- export const getBatteryInfo = async ({ success, fail, complete } = {}) => {
14
+ export const getBatteryInfo = ({ success, fail, complete } = {}) => __awaiter(void 0, void 0, void 0, function* () {
6
15
  var _a;
7
16
  const handle = new MethodHandler({ name: 'getBatteryInfo', success, fail, complete });
8
17
  try {
9
18
  // @ts-ignore
10
- const battery = await ((_a = navigator.getBattery) === null || _a === void 0 ? void 0 : _a.call(navigator));
19
+ const battery = yield ((_a = navigator.getBattery) === null || _a === void 0 ? void 0 : _a.call(navigator));
11
20
  return handle.success({
12
21
  isCharging: battery.charging,
13
22
  level: Number(battery.level || 0) * 100
@@ -18,4 +27,4 @@ export const getBatteryInfo = async ({ success, fail, complete } = {}) => {
18
27
  errMsg: (error === null || error === void 0 ? void 0 : error.message) || error
19
28
  });
20
29
  }
21
- };
30
+ });
@@ -4,6 +4,15 @@
4
4
  * setClipboardData: https://github.com/chameleon-team/chameleon-api/tree/master/src/interfaces/setClipBoardData
5
5
  * getClipboardData: https://github.com/chameleon-team/chameleon-api/tree/master/src/interfaces/getClipBoardData
6
6
  */
7
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
9
+ return new (P || (P = Promise))(function (resolve, reject) {
10
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
12
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
13
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
14
+ });
15
+ };
7
16
  import { setStorage, setStorageSync, getStorageSync } from '../storage/index';
8
17
  import { MethodHandler } from '../utils/handler';
9
18
  const CLIPBOARD_STORAGE_NAME = 'taro_clipboard';
@@ -19,7 +28,7 @@ document.addEventListener('copy', () => {
19
28
  /**
20
29
  * 设置系统剪贴板的内容
21
30
  */
22
- export const setClipboardData = async ({ data, success, fail, complete }) => {
31
+ export const setClipboardData = ({ data, success, fail, complete }) => __awaiter(void 0, void 0, void 0, function* () {
23
32
  const handle = new MethodHandler({ name: 'setClipboardData', success, fail, complete });
24
33
  try {
25
34
  setStorageSync(CLIPBOARD_STORAGE_NAME, data);
@@ -49,11 +58,11 @@ export const setClipboardData = async ({ data, success, fail, complete }) => {
49
58
  catch (e) {
50
59
  return handle.fail({ errMsg: e.message });
51
60
  }
52
- };
61
+ });
53
62
  /**
54
63
  * 获取系统剪贴板的内容
55
64
  */
56
- export const getClipboardData = async ({ success, fail, complete } = {}) => {
65
+ export const getClipboardData = ({ success, fail, complete } = {}) => __awaiter(void 0, void 0, void 0, function* () {
57
66
  const handle = new MethodHandler({ name: 'getClipboardData', success, fail, complete });
58
67
  try {
59
68
  const data = getStorageSync(CLIPBOARD_STORAGE_NAME);
@@ -62,4 +71,4 @@ export const getClipboardData = async ({ success, fail, complete } = {}) => {
62
71
  catch (e) {
63
72
  return handle.fail({ errMsg: e.message });
64
73
  }
65
- };
74
+ });
@@ -1,45 +1,59 @@
1
+ import { getDeviceInfo } from '../base/system';
2
+ import { throttle } from '../utils';
1
3
  import { CallbackManager, MethodHandler } from '../utils/handler';
2
4
  const callbackManager = new CallbackManager();
3
5
  let compassListener;
6
+ /**
7
+ * Note: 按系统类型获取对应绝对 orientation 事件名,因为安卓系统中直接监听 deviceorientation 事件得到的不是绝对 orientation
8
+ */
9
+ const deviceorientationEventName = ['absolutedeviceorientation', 'deviceorientationabsolute', 'deviceorientation'].find(item => {
10
+ if ('on' + item in window) {
11
+ return item;
12
+ }
13
+ }) || '';
4
14
  /**
5
15
  * 停止监听罗盘数据
6
16
  */
7
17
  export const stopCompass = ({ success, fail, complete } = {}) => {
8
18
  const handle = new MethodHandler({ name: 'stopCompass', success, fail, complete });
9
19
  try {
10
- window.removeEventListener('deviceorientation', compassListener, true);
20
+ window.removeEventListener(deviceorientationEventName, compassListener, true);
11
21
  return handle.success();
12
22
  }
13
23
  catch (e) {
14
24
  return handle.fail({ errMsg: e.message });
15
25
  }
16
26
  };
17
- const getDeviceOrientationListener = interval => {
18
- let lock;
19
- let timer;
20
- return evt => {
21
- if (lock)
22
- return;
23
- lock = true;
24
- timer && clearTimeout(timer);
25
- callbackManager.trigger({
26
- direction: 360 - evt.alpha
27
- });
28
- timer = setTimeout(() => { lock = false; }, interval);
29
- };
30
- };
27
+ let CompassChangeTrigger = false;
31
28
  /**
32
29
  * 开始监听罗盘数据
33
30
  */
34
31
  export const startCompass = ({ success, fail, complete } = {}) => {
35
32
  const handle = new MethodHandler({ name: 'startCompass', success, fail, complete });
36
33
  try {
37
- if (window.DeviceOrientationEvent) {
34
+ if (deviceorientationEventName !== '') {
38
35
  if (compassListener) {
39
36
  stopCompass();
40
37
  }
41
- compassListener = getDeviceOrientationListener(200);
42
- window.addEventListener('deviceorientation', compassListener, true);
38
+ compassListener = throttle((evt) => {
39
+ const isAndroid = getDeviceInfo().system === 'AndroidOS';
40
+ if (isAndroid && !evt.absolute && !CompassChangeTrigger) {
41
+ CompassChangeTrigger = true;
42
+ console.warn('Warning: In \'onCompassChange\', your browser is not supported to get the orientation relative to the earth, the orientation data will be related to the initial orientation of the device .');
43
+ }
44
+ const alpha = evt.alpha || 0;
45
+ /**
46
+ * 由于平台差异,accuracy 在 iOS/Android 的值不同。
47
+ * - iOS:accuracy 是一个 number 类型的值,表示相对于磁北极的偏差。0 表示设备指向磁北,90 表示指向东,180 表示指向南,依此类推。
48
+ * - Android:accuracy 是一个 string 类型的枚举值。
49
+ */
50
+ const accuracy = isAndroid ? evt.absolute ? 'high' : 'medium' : alpha;
51
+ callbackManager.trigger({
52
+ direction: 360 - alpha,
53
+ accuracy: accuracy
54
+ });
55
+ }, 5000);
56
+ window.addEventListener(deviceorientationEventName, compassListener, true);
43
57
  }
44
58
  else {
45
59
  throw new Error('compass is not supported');
@@ -1,3 +1,4 @@
1
+ import { throttle } from '../utils';
1
2
  import { CallbackManager, MethodHandler } from '../utils/handler';
2
3
  const callbackManager = new CallbackManager();
3
4
  let deviceMotionListener;
@@ -28,22 +29,6 @@ export const stopDeviceMotionListening = ({ success, fail, complete } = {}) => {
28
29
  return handle.fail({ errMsg: e.message });
29
30
  }
30
31
  };
31
- const getDeviceOrientationListener = interval => {
32
- let lock;
33
- let timer;
34
- return evt => {
35
- if (lock)
36
- return;
37
- lock = true;
38
- timer && clearTimeout(timer);
39
- callbackManager.trigger({
40
- alpha: evt.alpha,
41
- beta: evt.beta,
42
- gamma: evt.gamma
43
- });
44
- timer = setTimeout(() => { lock = false; }, interval);
45
- };
46
- };
47
32
  /**
48
33
  * 开始监听设备方向的变化。
49
34
  */
@@ -55,7 +40,13 @@ export const startDeviceMotionListening = ({ interval = 'normal', success, fail,
55
40
  if (deviceMotionListener) {
56
41
  stopDeviceMotionListening();
57
42
  }
58
- deviceMotionListener = getDeviceOrientationListener(intervalObj.interval);
43
+ deviceMotionListener = throttle((evt) => {
44
+ callbackManager.trigger({
45
+ alpha: evt.alpha,
46
+ beta: evt.beta,
47
+ gamma: evt.gamma
48
+ });
49
+ }, intervalObj.interval);
59
50
  window.addEventListener('deviceorientation', deviceMotionListener, true);
60
51
  }
61
52
  else {
@@ -1,3 +1,12 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
1
10
  import { CallbackManager, MethodHandler } from '../utils/handler';
2
11
  import { temporarilyNotSupport } from '../utils';
3
12
  function getConnection() {
@@ -46,12 +55,12 @@ export const getNetworkType = (options = {}) => {
46
55
  return handle.success({ networkType });
47
56
  };
48
57
  const networkStatusManager = new CallbackManager();
49
- const networkStatusListener = async () => {
50
- const { networkType } = await getNetworkType();
58
+ const networkStatusListener = () => __awaiter(void 0, void 0, void 0, function* () {
59
+ const { networkType } = yield getNetworkType();
51
60
  const isConnected = networkType !== 'none';
52
61
  const obj = { isConnected, networkType };
53
62
  networkStatusManager.trigger(obj);
54
- };
63
+ });
55
64
  /**
56
65
  * 在最近的八次网络请求中, 出现下列三个现象之一则判定弱网。
57
66
  * - 出现三次以上连接超时
@@ -1,16 +1,21 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
1
12
  import { stringify } from 'query-string';
2
13
  import { MethodHandler } from '../utils/handler';
3
14
  import './style.css';
4
15
  function createLocationChooser(handler, key = LOCATION_APIKEY, mapOpt = {}) {
5
16
  var _a, _b, _c;
6
- const { latitude, longitude, ...opts } = mapOpt;
7
- const query = {
8
- key,
9
- type: 1,
10
- coord: ((_a = mapOpt.coord) !== null && _a !== void 0 ? _a : [latitude, longitude].every(e => Number(e) >= 0)) ? `${latitude},${longitude}` : undefined,
11
- referer: 'myapp',
12
- ...opts
13
- };
17
+ const { latitude, longitude } = mapOpt, opts = __rest(mapOpt, ["latitude", "longitude"]);
18
+ const query = Object.assign({ key, type: 1, coord: ((_a = mapOpt.coord) !== null && _a !== void 0 ? _a : [latitude, longitude].every(e => Number(e) >= 0)) ? `${latitude},${longitude}` : undefined, referer: 'myapp' }, opts);
14
19
  const html = `
15
20
  <div class='taro_choose_location'>
16
21
  <div class='taro_choose_location_bar'>
@@ -1,3 +1,12 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
1
10
  import { shouldBeObject } from '../../utils';
2
11
  import { MethodHandler } from '../../utils/handler';
3
12
  /**
@@ -6,7 +15,7 @@ import { MethodHandler } from '../../utils/handler';
6
15
  /**
7
16
  * 在新页面中全屏预览图片。预览的过程中用户可以进行保存图片、发送给朋友等操作。
8
17
  */
9
- export const previewImage = async (options) => {
18
+ export const previewImage = (options) => __awaiter(void 0, void 0, void 0, function* () {
10
19
  function loadImage(url, loadFail) {
11
20
  return new Promise((resolve) => {
12
21
  const item = document.createElement('taro-swiper-item-core');
@@ -47,7 +56,7 @@ export const previewImage = async (options) => {
47
56
  swiper.full = true;
48
57
  let children = [];
49
58
  try {
50
- children = await Promise.all(urls.map(e => loadImage(e, fail)));
59
+ children = yield Promise.all(urls.map(e => loadImage(e, fail)));
51
60
  }
52
61
  catch (error) {
53
62
  return handle.fail({
@@ -64,4 +73,4 @@ export const previewImage = async (options) => {
64
73
  container.appendChild(swiper);
65
74
  document.body.appendChild(container);
66
75
  return handle.success();
67
- };
76
+ });
package/dist/api/taro.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import Taro from '@tarojs/api';
2
- import { history, createRouter } from '@tarojs/router';
2
+ import { history } from '@tarojs/router';
3
3
  import { getApp, getCurrentInstance, getCurrentPages, nextTick, navigateBack, navigateTo, reLaunch, redirectTo, switchTab } from '../api';
4
4
  import { permanentlyNotSupport } from '../api/utils';
5
5
  const { Behavior, getEnv, ENV_TYPE, Link, interceptors, getInitPxTransform, Current, options, eventCenter, Events, preload } = Taro;
@@ -18,7 +18,6 @@ const taro = {
18
18
  Events,
19
19
  preload,
20
20
  history,
21
- createRouter,
22
21
  navigateBack,
23
22
  navigateTo,
24
23
  reLaunch,
@@ -44,4 +43,4 @@ taro.initPxTransform = initPxTransform;
44
43
  // @ts-ignore
45
44
  taro.canIUseWebp = canIUseWebp;
46
45
  export default taro;
47
- export { Behavior, getEnv, ENV_TYPE, Link, interceptors, initPxTransform, Current, options, eventCenter, Events, preload, requirePlugin, pxTransform, canIUseWebp, history, createRouter };
46
+ export { Behavior, getEnv, ENV_TYPE, Link, interceptors, initPxTransform, Current, options, eventCenter, Events, preload, requirePlugin, pxTransform, canIUseWebp, history };
@@ -1,6 +1,15 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
1
10
  import { MethodHandler } from '../utils/handler';
2
11
  // 字体
3
- export const loadFontFace = async (options) => {
12
+ export const loadFontFace = (options) => __awaiter(void 0, void 0, void 0, function* () {
4
13
  options = Object.assign({ global: false }, options);
5
14
  const { success, fail, complete, family, source, desc = {} } = options;
6
15
  const handle = new MethodHandler({ name: 'loadFontFace', success, fail, complete });
@@ -10,7 +19,7 @@ export const loadFontFace = async (options) => {
10
19
  // @ts-ignore
11
20
  const fontFace = new FontFace(family, source, desc);
12
21
  try {
13
- await fontFace.load();
22
+ yield fontFace.load();
14
23
  fonts.add(fontFace);
15
24
  return handle.success({});
16
25
  }
@@ -48,4 +57,4 @@ export const loadFontFace = async (options) => {
48
57
  document.head.appendChild(style);
49
58
  return handle.success();
50
59
  }
51
- };
60
+ });
@@ -57,10 +57,7 @@ export default class ActionSheet {
57
57
  // style
58
58
  const { maskStyle, actionSheetStyle, menuStyle, cellStyle, cancelStyle } = this.style;
59
59
  // configuration
60
- const config = {
61
- ...this.options,
62
- ...options
63
- };
60
+ const config = Object.assign(Object.assign({}, this.options), options);
64
61
  this.lastConfig = config;
65
62
  // wrapper
66
63
  this.el = document.createElement('div');
@@ -75,10 +72,7 @@ export default class ActionSheet {
75
72
  this.actionSheet.setAttribute('style', inlineStyle(actionSheetStyle));
76
73
  // menu
77
74
  this.menu = document.createElement('div');
78
- this.menu.setAttribute('style', inlineStyle({
79
- ...menuStyle,
80
- color: config.itemColor
81
- }));
75
+ this.menu.setAttribute('style', inlineStyle(Object.assign(Object.assign({}, menuStyle), { color: config.itemColor })));
82
76
  // cells
83
77
  this.cells = config.itemList.map((item, index) => {
84
78
  const cell = document.createElement('div');
@@ -121,10 +115,7 @@ export default class ActionSheet {
121
115
  }
122
116
  show(options = {}) {
123
117
  return new Promise((resolve) => {
124
- const config = {
125
- ...this.options,
126
- ...options
127
- };
118
+ const config = Object.assign(Object.assign({}, this.options), options);
128
119
  this.lastConfig = config;
129
120
  if (this.hideOpacityTimer)
130
121
  clearTimeout(this.hideOpacityTimer);
@@ -1,3 +1,12 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
1
10
  import Taro from '@tarojs/api';
2
11
  import { getParameterError, temporarilyNotSupport } from '../../utils';
3
12
  import { MethodHandler } from '../../utils/handler';
@@ -106,7 +115,7 @@ const hideLoading = ({ success, fail, complete } = {}) => {
106
115
  toast.hide(0, 'loading');
107
116
  return handle.success();
108
117
  };
109
- const showModal = async (options = {}) => {
118
+ const showModal = (options = {}) => __awaiter(void 0, void 0, void 0, function* () {
110
119
  init(document);
111
120
  options = Object.assign({
112
121
  title: '',
@@ -186,21 +195,21 @@ const showModal = async (options = {}) => {
186
195
  options.showCancel = !!options.showCancel;
187
196
  let result = '';
188
197
  if (!modal.el) {
189
- result = await modal.create(options);
198
+ result = yield modal.create(options);
190
199
  }
191
200
  else {
192
- result = await modal.show(options);
201
+ result = yield modal.show(options);
193
202
  }
194
203
  const res = { cancel: !1, confirm: !1 };
195
204
  res[result] = !0;
196
205
  return handle.success(res);
197
- };
206
+ });
198
207
  function hideModal() {
199
208
  if (!modal.el)
200
209
  return;
201
210
  modal.hide();
202
211
  }
203
- const showActionSheet = async (options = { itemList: [] }) => {
212
+ const showActionSheet = (options = { itemList: [] }) => __awaiter(void 0, void 0, void 0, function* () {
204
213
  init(document);
205
214
  options = Object.assign({
206
215
  itemColor: '#000000',
@@ -246,10 +255,10 @@ const showActionSheet = async (options = { itemList: [] }) => {
246
255
  }
247
256
  let result = '';
248
257
  if (!actionSheet.el) {
249
- result = await actionSheet.create(options);
258
+ result = yield actionSheet.create(options);
250
259
  }
251
260
  else {
252
- result = await actionSheet.show(options);
261
+ result = yield actionSheet.show(options);
253
262
  }
254
263
  if (typeof result === 'string') {
255
264
  return handle.fail(({ errMsg: result }));
@@ -257,7 +266,7 @@ const showActionSheet = async (options = { itemList: [] }) => {
257
266
  else {
258
267
  return handle.success(({ tapIndex: result }));
259
268
  }
260
- };
269
+ });
261
270
  Taro.eventCenter.on('__taroRouterChange', () => {
262
271
  hideToast();
263
272
  hideLoading();