@tarojs/taro-h5 3.3.20 → 3.4.0-beta.3

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 (125) hide show
  1. package/dist/api/ad/index.js +1 -0
  2. package/dist/api/ai/facial.js +1 -0
  3. package/dist/api/ai/visual.js +1 -0
  4. package/dist/api/alipay/index.js +1 -0
  5. package/dist/api/base/crypto.js +1 -0
  6. package/dist/api/base/index.js +1 -0
  7. package/dist/api/base/performance.js +1 -0
  8. package/dist/api/base/system/info.js +1 -0
  9. package/dist/api/base/system/network.js +12 -1
  10. package/dist/api/base/update.js +1 -0
  11. package/dist/api/base/weapp/app-event.js +1 -0
  12. package/dist/api/base/weapp/life-cycle.js +1 -0
  13. package/dist/api/canvas/CanvasContext.js +9 -0
  14. package/dist/api/canvas/canvasGetImageData.js +4 -0
  15. package/dist/api/canvas/canvasPutImageData.js +5 -0
  16. package/dist/api/canvas/canvasToTempFilePath.js +4 -0
  17. package/dist/api/canvas/createCanvasContext.js +3 -0
  18. package/dist/api/canvas/index.js +1 -0
  19. package/dist/api/cloud/index.js +3 -0
  20. package/dist/api/device/accelerometer.js +12 -0
  21. package/dist/api/device/accessibility.js +1 -0
  22. package/dist/api/device/battery.js +1 -0
  23. package/dist/api/device/bluetooth-ble.js +1 -0
  24. package/dist/api/device/bluetooth-peripheral.js +1 -0
  25. package/dist/api/device/bluetooth.js +1 -0
  26. package/dist/api/device/calendar.js +1 -0
  27. package/dist/api/device/clipboard.js +17 -0
  28. package/dist/api/device/compass.js +12 -0
  29. package/dist/api/device/contact.js +1 -0
  30. package/dist/api/device/crypto.js +1 -0
  31. package/dist/api/device/gyroscope.js +1 -0
  32. package/dist/api/device/iBeacon.js +1 -0
  33. package/dist/api/device/keyboard.js +1 -0
  34. package/dist/api/device/memory.js +1 -0
  35. package/dist/api/device/motion.js +12 -0
  36. package/dist/api/device/nfc.js +1 -0
  37. package/dist/api/device/phone.js +1 -0
  38. package/dist/api/device/scan.js +1 -0
  39. package/dist/api/device/screen.js +1 -0
  40. package/dist/api/device/vibrate.js +6 -0
  41. package/dist/api/device/wifi.js +1 -0
  42. package/dist/api/ext/index.js +1 -0
  43. package/dist/api/files/index.js +1 -0
  44. package/dist/api/framework/index.js +1 -0
  45. package/dist/api/location/chooseLocation.js +5 -0
  46. package/dist/api/location/index.js +1 -0
  47. package/dist/api/media/audio/index.js +7 -0
  48. package/dist/api/media/background-audio.js +1 -0
  49. package/dist/api/media/camera.js +1 -0
  50. package/dist/api/media/editor.js +1 -0
  51. package/dist/api/media/image/chooseImage.js +4 -0
  52. package/dist/api/media/image/getImageInfo.js +4 -0
  53. package/dist/api/media/image/index.js +1 -0
  54. package/dist/api/media/image/previewImage.js +10 -0
  55. package/dist/api/media/live.js +1 -0
  56. package/dist/api/media/map.js +1 -0
  57. package/dist/api/media/media-recorder.js +1 -0
  58. package/dist/api/media/recorder.js +1 -0
  59. package/dist/api/media/video/index.js +9 -0
  60. package/dist/api/media/video-decoder.js +1 -0
  61. package/dist/api/media/video-processing.js +1 -0
  62. package/dist/api/media/voip.js +1 -0
  63. package/dist/api/navigate/index.js +1 -0
  64. package/dist/api/network/download.js +23 -0
  65. package/dist/api/network/mdns.js +1 -0
  66. package/dist/api/network/request/index.js +2 -0
  67. package/dist/api/network/tcp.js +1 -0
  68. package/dist/api/network/udp.js +1 -0
  69. package/dist/api/network/upload.js +22 -0
  70. package/dist/api/network/utils.js +36 -1
  71. package/dist/api/network/websocket/index.js +5 -0
  72. package/dist/api/network/websocket/socketTask.js +2 -0
  73. package/dist/api/open-api/account.js +1 -0
  74. package/dist/api/open-api/address.js +1 -0
  75. package/dist/api/open-api/authorize.js +1 -0
  76. package/dist/api/open-api/card.js +1 -0
  77. package/dist/api/open-api/channels-live.js +1 -0
  78. package/dist/api/open-api/customer-service.js +1 -0
  79. package/dist/api/open-api/facial.js +1 -0
  80. package/dist/api/open-api/favorites.js +1 -0
  81. package/dist/api/open-api/group.js +1 -0
  82. package/dist/api/open-api/invoice.js +1 -0
  83. package/dist/api/open-api/license-plate.js +1 -0
  84. package/dist/api/open-api/login.js +1 -0
  85. package/dist/api/open-api/red-package.js +1 -0
  86. package/dist/api/open-api/settings.js +1 -0
  87. package/dist/api/open-api/soter.js +1 -0
  88. package/dist/api/open-api/subscribe-message.js +1 -0
  89. package/dist/api/open-api/user-info.js +1 -0
  90. package/dist/api/open-api/werun.js +1 -0
  91. package/dist/api/payment/index.js +1 -0
  92. package/dist/api/route/index.js +2 -0
  93. package/dist/api/share/index.js +1 -0
  94. package/dist/api/storage/background-fetch.js +1 -0
  95. package/dist/api/storage/index.js +5 -0
  96. package/dist/api/swan/index.js +4 -0
  97. package/dist/api/taro.js +6 -18
  98. package/dist/api/ui/animation/index.js +34 -0
  99. package/dist/api/ui/background.js +1 -0
  100. package/dist/api/ui/custom-component.js +1 -0
  101. package/dist/api/ui/fonts.js +1 -0
  102. package/dist/api/ui/interaction/actionSheet.js +16 -0
  103. package/dist/api/ui/interaction/index.js +9 -4
  104. package/dist/api/ui/interaction/modal.js +22 -0
  105. package/dist/api/ui/interaction/toast.js +16 -0
  106. package/dist/api/ui/menu.js +1 -0
  107. package/dist/api/ui/navigation-bar/index.js +5 -0
  108. package/dist/api/ui/pull-down-refresh.js +6 -0
  109. package/dist/api/ui/scroll/index.js +3 -0
  110. package/dist/api/ui/sticky.js +1 -0
  111. package/dist/api/ui/tab-bar.js +32 -0
  112. package/dist/api/ui/window.js +9 -0
  113. package/dist/api/utils/handler.js +16 -0
  114. package/dist/api/utils/index.js +7 -0
  115. package/dist/api/worker/index.js +1 -0
  116. package/dist/api/wxml/selectorQuery.js +13 -0
  117. package/dist/index.cjs.js +637 -160
  118. package/dist/index.js +2 -2
  119. package/package.json +9 -13
  120. package/src/api/media/image/previewImage.ts +1 -1
  121. package/src/api/taro.ts +4 -48
  122. package/src/api/ui/interaction/index.ts +6 -4
  123. package/src/api/ui/navigation-bar/index.ts +1 -1
  124. package/src/api/ui/scroll/index.ts +1 -1
  125. package/src/index.ts +2 -2
@@ -1,3 +1,7 @@
1
+ /**
2
+ * H5 下的 styleSheet 操作
3
+ * @author leeenx
4
+ */
1
5
  class StyleSheet {
2
6
  constructor() {
3
7
  this.appendStyleSheet = () => {
@@ -10,9 +14,11 @@ class StyleSheet {
10
14
  console.warn('当前浏览器不支持 stylesheet.insertRule 接口');
11
15
  }
12
16
  };
17
+ // 添加样式命令
13
18
  this.add = (cssText, index = 0) => {
14
19
  var _a;
15
20
  if (this.sheet === null) {
21
+ // $style 未插入到 DOM
16
22
  this.appendStyleSheet();
17
23
  }
18
24
  (_a = this.sheet) === null || _a === void 0 ? void 0 : _a.insertRule(cssText, index);
@@ -21,55 +27,73 @@ class StyleSheet {
21
27
  }
22
28
  }
23
29
  const styleSheet = new StyleSheet();
30
+ // 监听事件
24
31
  let TRANSITION_END = 'transitionend';
25
32
  let TRANSFORM = 'transform';
26
33
  const $detect = document.createElement('div');
27
34
  $detect.style.cssText = '-webkit-animation-name:webkit;-moz-animation-name:moz;-ms-animation-name:ms;animation-name:standard;';
28
35
  if ($detect.style['animation-name'] === 'standard') {
36
+ // 支持标准写法
29
37
  TRANSITION_END = 'transitionend';
30
38
  TRANSFORM = 'transform';
31
39
  }
32
40
  else if ($detect.style['-webkit-animation-name'] === 'webkit') {
41
+ // webkit 前缀
33
42
  TRANSITION_END = 'webkitTransitionEnd';
34
43
  TRANSFORM = '-webkit-transform';
35
44
  }
36
45
  else if ($detect.style['-moz-animation-name'] === 'moz') {
46
+ // moz 前缀
37
47
  TRANSITION_END = 'mozTransitionEnd';
38
48
  TRANSFORM = '-moz-transform';
39
49
  }
40
50
  else if ($detect.style['-ms-animation-name'] === 'ms') {
51
+ // ms 前缀
41
52
  TRANSITION_END = 'msTransitionEnd';
42
53
  TRANSFORM = '-ms-transform';
43
54
  }
44
55
  let animId = 0;
45
56
  class Animation {
46
57
  constructor({ duration = 400, delay = 0, timingFunction = 'linear', transformOrigin = '50% 50% 0', unit = 'px' } = {}) {
58
+ // 属性组合
47
59
  this.rules = [];
60
+ // transform 对象
48
61
  this.transform = [`${TRANSFORM}:`];
62
+ // 组合动画
49
63
  this.steps = [];
64
+ // 动画 map ----- 永久保留
50
65
  this.animationMap = {};
66
+ // animationMap 的长度
51
67
  this.animationMapCount = 0;
68
+ // 默认值
52
69
  this.setDefault(duration, delay, timingFunction, transformOrigin);
53
70
  this.unit = unit;
71
+ // atom 环境下,animation 属性不会显示,所以要改成 data-animation
54
72
  let animAttr = 'animation';
73
+ // 动画 id
55
74
  this.id = ++animId;
75
+ // 监听事件
56
76
  document.body.addEventListener(TRANSITION_END, (e) => {
57
77
  const target = e.target;
58
78
  if (target.getAttribute(animAttr) === null) {
59
79
  animAttr = 'data-animation';
60
80
  }
61
81
  const animData = target.getAttribute(animAttr);
82
+ // 没有动画存在
62
83
  if (animData === null)
63
84
  return;
64
85
  const [animName, animPath] = animData.split('__');
65
86
  if (animName === `taro-h5-poly-fill/${this.id}/create-animation`) {
66
87
  const [animIndex, __stepIndex = 0] = animPath.split('--');
67
88
  const stepIndex = Number(__stepIndex);
89
+ // 动画总的关键帧
68
90
  const animStepsCount = this.animationMap[`${animName}__${animIndex}`];
69
91
  const animStepsMaxIndex = animStepsCount - 1;
70
92
  if (stepIndex < animStepsMaxIndex) {
93
+ // 播放下一个关键帧(因为 nerv 和 react 有差异所以 animation & data-animation 都需要写)
71
94
  target.setAttribute(animAttr, `${animName}__${animIndex}--${stepIndex + 1}`);
72
95
  if (animAttr === 'animation') {
96
+ // Nerv 环境,animation & data-animation 双重保险
73
97
  target.setAttribute('data-animation', `${animName}__${animIndex}--${stepIndex + 1}`);
74
98
  }
75
99
  }
@@ -83,6 +107,7 @@ class Animation {
83
107
  });
84
108
  return ret;
85
109
  }
110
+ // 设置默认值
86
111
  setDefault(duration, delay, timingFunction, transformOrigin) {
87
112
  this.DEFAULT = { duration, delay, timingFunction, transformOrigin };
88
113
  }
@@ -214,9 +239,11 @@ class Animation {
214
239
  this.rules.push(`left: ${value}`);
215
240
  return this;
216
241
  }
242
+ // 关键帧载入
217
243
  step(arg = {}) {
218
244
  const { DEFAULT } = this;
219
245
  const { duration = DEFAULT.duration, delay = DEFAULT.delay, timingFunction = DEFAULT.timingFunction, transformOrigin = DEFAULT.transformOrigin } = arg;
246
+ // 生成一条 transition 动画
220
247
  this.steps.push([
221
248
  this.rules.map(rule => `${rule}!important`).join(';'),
222
249
  `${this.transform.join(' ')}!important`,
@@ -225,26 +252,33 @@ class Animation {
225
252
  ]
226
253
  .filter(item => item !== '' && item !== `${TRANSFORM}:`)
227
254
  .join(';'));
255
+ // 清空 rules 和 transform
228
256
  this.rules = [];
229
257
  this.transform = [`${TRANSFORM}:`];
230
258
  return this;
231
259
  }
260
+ // 创建底层数据
232
261
  createAnimationData() {
233
262
  const animIndex = `taro-h5-poly-fill/${this.id}/create-animation__${this.animationMapCount++}`;
263
+ // 记录动画分几个 step
234
264
  this.animationMap[animIndex] = this.steps.length;
265
+ // 吐出 step
235
266
  this.steps.forEach((step, index) => {
236
267
  const selector = index === 0
237
268
  ? `[animation="${animIndex}"], [data-animation="${animIndex}"]`
238
269
  : `[animation="${animIndex}--${index}"], [data-animation="${animIndex}--${index}"]`;
239
270
  styleSheet.add(`${selector} { ${step} }`);
240
271
  });
272
+ // 清空 steps
241
273
  this.steps = [];
242
274
  return animIndex;
243
275
  }
276
+ // 动画数据产出
244
277
  export() {
245
278
  return this.createAnimationData();
246
279
  }
247
280
  }
281
+ // h5 的 createAnimation
248
282
  export const createAnimation = (option) => {
249
283
  return new Animation(option);
250
284
  };
@@ -1,3 +1,4 @@
1
1
  import { temporarilyNotSupport } from '../utils';
2
+ // 背景
2
3
  export const setBackgroundTextStyle = temporarilyNotSupport('setBackgroundTextStyle');
3
4
  export const setBackgroundColor = temporarilyNotSupport('setBackgroundColor');
@@ -1,2 +1,3 @@
1
1
  import Taro from '@tarojs/api';
2
+ // 自定义组件
2
3
  export const nextTick = Taro.nextTick;
@@ -1,2 +1,3 @@
1
1
  import { temporarilyNotSupport } from '../utils';
2
+ // 字体
2
3
  export const loadFontFace = temporarilyNotSupport('loadFontFace');
@@ -54,25 +54,32 @@ export default class ActionSheet {
54
54
  }
55
55
  create(options = {}) {
56
56
  return new Promise((resolve) => {
57
+ // style
57
58
  const { maskStyle, actionSheetStyle, menuStyle, cellStyle, cancelStyle } = this.style;
59
+ // configuration
58
60
  const config = {
59
61
  ...this.options,
60
62
  ...options
61
63
  };
62
64
  this.lastConfig = config;
65
+ // wrapper
63
66
  this.el = document.createElement('div');
64
67
  this.el.className = 'taro__actionSheet';
65
68
  this.el.style.opacity = '0';
66
69
  this.el.style.transition = 'opacity 0.2s linear';
70
+ // mask
67
71
  const mask = document.createElement('div');
68
72
  mask.setAttribute('style', inlineStyle(maskStyle));
73
+ // actionSheet
69
74
  this.actionSheet = document.createElement('div');
70
75
  this.actionSheet.setAttribute('style', inlineStyle(actionSheetStyle));
76
+ // menu
71
77
  this.menu = document.createElement('div');
72
78
  this.menu.setAttribute('style', inlineStyle({
73
79
  ...menuStyle,
74
80
  color: config.itemColor
75
81
  }));
82
+ // cells
76
83
  this.cells = config.itemList.map((item, index) => {
77
84
  const cell = document.createElement('div');
78
85
  cell.className = 'taro-actionsheet__cell';
@@ -87,20 +94,24 @@ export default class ActionSheet {
87
94
  };
88
95
  return cell;
89
96
  });
97
+ // cancel
90
98
  this.cancel = document.createElement('div');
91
99
  this.cancel.setAttribute('style', inlineStyle(cancelStyle));
92
100
  this.cancel.textContent = '取消';
101
+ // result
93
102
  this.cells.forEach(item => this.menu.appendChild(item));
94
103
  this.actionSheet.appendChild(this.menu);
95
104
  this.actionSheet.appendChild(this.cancel);
96
105
  this.el.appendChild(mask);
97
106
  this.el.appendChild(this.actionSheet);
107
+ // callbacks
98
108
  const cb = () => {
99
109
  this.hide();
100
110
  resolve('cancel');
101
111
  };
102
112
  mask.onclick = cb;
103
113
  this.cancel.onclick = cb;
114
+ // show immediately
104
115
  document.body.appendChild(this.el);
105
116
  setTimeout(() => {
106
117
  this.el.style.opacity = '1';
@@ -119,15 +130,19 @@ export default class ActionSheet {
119
130
  clearTimeout(this.hideOpacityTimer);
120
131
  if (this.hideDisplayTimer)
121
132
  clearTimeout(this.hideDisplayTimer);
133
+ // itemColor
122
134
  if (config.itemColor)
123
135
  this.menu.style.color = config.itemColor;
136
+ // cells
124
137
  const { cellStyle } = this.style;
125
138
  config.itemList.forEach((item, index) => {
126
139
  let cell;
127
140
  if (this.cells[index]) {
141
+ // assign new content
128
142
  cell = this.cells[index];
129
143
  }
130
144
  else {
145
+ // create new cell
131
146
  cell = document.createElement('div');
132
147
  cell.className = 'taro-actionsheet__cell';
133
148
  cell.setAttribute('style', inlineStyle(cellStyle));
@@ -151,6 +166,7 @@ export default class ActionSheet {
151
166
  }
152
167
  this.cells.splice(itemListLen);
153
168
  }
169
+ // show
154
170
  this.el.style.display = 'block';
155
171
  setTimeout(() => {
156
172
  this.el.style.opacity = '1';
@@ -4,7 +4,9 @@ import { MethodHandler } from '../../utils/handler';
4
4
  import Toast from './toast';
5
5
  import Modal from './modal';
6
6
  import ActionSheet from './actionSheet';
7
+ // 交互
7
8
  let status = 'default';
9
+ // inject necessary style
8
10
  function init(doc) {
9
11
  if (status === 'ready')
10
12
  return;
@@ -182,14 +184,16 @@ const showModal = async (options = {}) => {
182
184
  });
183
185
  }
184
186
  options.showCancel = !!options.showCancel;
185
- let errMsg = '';
187
+ let result = '';
186
188
  if (!modal.el) {
187
- errMsg = await modal.create(options);
189
+ result = await modal.create(options);
188
190
  }
189
191
  else {
190
- errMsg = await modal.show(options);
192
+ result = await modal.show(options);
191
193
  }
192
- return handle.success({ errMsg });
194
+ const res = { cancel: !1, confirm: !1 };
195
+ res[result] = !0;
196
+ return handle.success(res);
193
197
  };
194
198
  function hideModal() {
195
199
  if (!modal.el)
@@ -204,6 +208,7 @@ const showActionSheet = async (options = { itemList: [] }) => {
204
208
  }, options);
205
209
  const { success, fail, complete } = options;
206
210
  const handle = new MethodHandler({ name: 'showActionSheet', success, fail, complete });
211
+ // list item String
207
212
  if (!Array.isArray(options.itemList)) {
208
213
  return handle.fail({
209
214
  errMsg: getParameterError({
@@ -61,21 +61,27 @@ export default class Modal {
61
61
  }
62
62
  create(options = {}) {
63
63
  return new Promise((resolve) => {
64
+ // style
64
65
  const { maskStyle, modalStyle, titleStyle, textStyle, footStyle, btnStyle } = this.style;
66
+ // configuration
65
67
  const config = {
66
68
  ...this.options,
67
69
  ...options
68
70
  };
71
+ // wrapper
69
72
  this.el = document.createElement('div');
70
73
  this.el.className = 'taro__modal';
71
74
  this.el.style.opacity = '0';
72
75
  this.el.style.transition = 'opacity 0.2s linear';
76
+ // mask
73
77
  const mask = document.createElement('div');
74
78
  mask.className = 'taro-modal__mask';
75
79
  mask.setAttribute('style', inlineStyle(maskStyle));
80
+ // modal
76
81
  const modal = document.createElement('div');
77
82
  modal.className = 'taro-modal__content';
78
83
  modal.setAttribute('style', inlineStyle(modalStyle));
84
+ // title
79
85
  const titleCSS = config.title ? titleStyle : {
80
86
  ...titleStyle,
81
87
  display: 'none'
@@ -84,6 +90,7 @@ export default class Modal {
84
90
  this.title.className = 'taro-modal__title';
85
91
  this.title.setAttribute('style', inlineStyle(titleCSS));
86
92
  this.title.textContent = config.title;
93
+ // text
87
94
  const textCSS = config.title ? textStyle : {
88
95
  ...textStyle,
89
96
  padding: '40px 20px 26px',
@@ -93,9 +100,11 @@ export default class Modal {
93
100
  this.text.className = 'taro-modal__text';
94
101
  this.text.setAttribute('style', inlineStyle(textCSS));
95
102
  this.text.textContent = config.content;
103
+ // foot
96
104
  const foot = document.createElement('div');
97
105
  foot.className = 'taro-modal__foot';
98
106
  foot.setAttribute('style', inlineStyle(footStyle));
107
+ // cancel button
99
108
  const cancelCSS = {
100
109
  ...btnStyle,
101
110
  color: config.cancelColor,
@@ -109,6 +118,7 @@ export default class Modal {
109
118
  this.hide();
110
119
  resolve('cancel');
111
120
  };
121
+ // confirm button
112
122
  this.confirm = document.createElement('div');
113
123
  this.confirm.className = 'taro-model__btn taro-model__confirm';
114
124
  this.confirm.setAttribute('style', inlineStyle(btnStyle));
@@ -118,6 +128,7 @@ export default class Modal {
118
128
  this.hide();
119
129
  resolve('confirm');
120
130
  };
131
+ // result
121
132
  foot.appendChild(this.cancel);
122
133
  foot.appendChild(this.confirm);
123
134
  modal.appendChild(this.title);
@@ -125,6 +136,7 @@ export default class Modal {
125
136
  modal.appendChild(foot);
126
137
  this.el.appendChild(mask);
127
138
  this.el.appendChild(modal);
139
+ // show immediately
128
140
  document.body.appendChild(this.el);
129
141
  setTimeout(() => { this.el.style.opacity = '1'; }, 0);
130
142
  });
@@ -139,13 +151,16 @@ export default class Modal {
139
151
  clearTimeout(this.hideOpacityTimer);
140
152
  if (this.hideDisplayTimer)
141
153
  clearTimeout(this.hideDisplayTimer);
154
+ // title & text
142
155
  const { textStyle } = this.style;
143
156
  if (config.title) {
144
157
  this.title.textContent = config.title;
158
+ // none => block
145
159
  this.title.style.display = 'block';
146
160
  this.text.setAttribute('style', inlineStyle(textStyle));
147
161
  }
148
162
  else {
163
+ // block => none
149
164
  this.title.style.display = 'none';
150
165
  const textCSS = {
151
166
  ...textStyle,
@@ -155,11 +170,17 @@ export default class Modal {
155
170
  this.text.setAttribute('style', inlineStyle(textCSS));
156
171
  }
157
172
  this.text.textContent = config.content || '';
173
+ // showCancel
158
174
  this.cancel.style.display = config.showCancel ? 'block' : 'none';
175
+ // cancelText
159
176
  this.cancel.textContent = config.cancelText || '';
177
+ // cancelColor
160
178
  this.cancel.style.color = config.cancelColor || '';
179
+ // confirmText
161
180
  this.confirm.textContent = config.confirmText || '';
181
+ // confirmColor
162
182
  this.confirm.style.color = config.confirmColor || '';
183
+ // cbs
163
184
  this.cancel.onclick = () => {
164
185
  this.hide();
165
186
  resolve('cancel');
@@ -168,6 +189,7 @@ export default class Modal {
168
189
  this.hide();
169
190
  resolve('confirm');
170
191
  };
192
+ // show
171
193
  this.el.style.display = 'block';
172
194
  setTimeout(() => { this.el.style.opacity = '1'; }, 0);
173
195
  });
@@ -75,19 +75,24 @@ export default class Toast {
75
75
  };
76
76
  }
77
77
  create(options = {}, _type = 'toast') {
78
+ // style
78
79
  const { maskStyle, toastStyle, successStyle, errrorStyle, loadingStyle, imageStyle, textStyle } = this.style;
80
+ // configuration
79
81
  const config = {
80
82
  ...this.options,
81
83
  ...options,
82
84
  _type
83
85
  };
86
+ // wrapper
84
87
  this.el = document.createElement('div');
85
88
  this.el.className = 'taro__toast';
86
89
  this.el.style.opacity = '0';
87
90
  this.el.style.transition = 'opacity 0.1s linear';
91
+ // mask
88
92
  this.mask = document.createElement('div');
89
93
  this.mask.setAttribute('style', inlineStyle(maskStyle));
90
94
  this.mask.style.display = config.mask ? 'block' : 'none';
95
+ // icon
91
96
  this.icon = document.createElement('p');
92
97
  if (config.image) {
93
98
  this.icon.setAttribute('style', inlineStyle({
@@ -102,6 +107,7 @@ export default class Toast {
102
107
  ...(config.icon === 'none' ? { display: 'none' } : {})
103
108
  }));
104
109
  }
110
+ // toast
105
111
  this.toast = document.createElement('div');
106
112
  this.toast.setAttribute('style', inlineStyle({
107
113
  ...toastStyle,
@@ -110,16 +116,20 @@ export default class Toast {
110
116
  padding: '10px 15px'
111
117
  } : {})
112
118
  }));
119
+ // title
113
120
  this.title = document.createElement('p');
114
121
  this.title.setAttribute('style', inlineStyle(textStyle));
115
122
  this.title.textContent = config.title;
123
+ // result
116
124
  this.toast.appendChild(this.icon);
117
125
  this.toast.appendChild(this.title);
118
126
  this.el.appendChild(this.mask);
119
127
  this.el.appendChild(this.toast);
128
+ // show immediately
120
129
  document.body.appendChild(this.el);
121
130
  setTimeout(() => { this.el.style.opacity = '1'; }, 0);
122
131
  this.type = config._type;
132
+ // disappear after duration
123
133
  config.duration >= 0 && this.hide(config.duration, this.type);
124
134
  return '';
125
135
  }
@@ -133,8 +143,11 @@ export default class Toast {
133
143
  clearTimeout(this.hideOpacityTimer);
134
144
  if (this.hideDisplayTimer)
135
145
  clearTimeout(this.hideDisplayTimer);
146
+ // title
136
147
  this.title.textContent = config.title || '';
148
+ // mask
137
149
  this.mask.style.display = config.mask ? 'block' : 'none';
150
+ // image
138
151
  const { toastStyle, successStyle, errrorStyle, loadingStyle, imageStyle } = this.style;
139
152
  if (config.image) {
140
153
  this.icon.setAttribute('style', inlineStyle({
@@ -151,6 +164,7 @@ export default class Toast {
151
164
  }));
152
165
  }
153
166
  }
167
+ // toast
154
168
  this.toast.setAttribute('style', inlineStyle({
155
169
  ...toastStyle,
156
170
  ...(config.icon === 'none' ? {
@@ -158,9 +172,11 @@ export default class Toast {
158
172
  padding: '10px 15px'
159
173
  } : {})
160
174
  }));
175
+ // show
161
176
  this.el.style.display = 'block';
162
177
  setTimeout(() => { this.el.style.opacity = '1'; }, 0);
163
178
  this.type = config._type;
179
+ // disappear after duration
164
180
  config.duration >= 0 && this.hide(config.duration, this.type);
165
181
  return '';
166
182
  }
@@ -1,2 +1,3 @@
1
1
  import { temporarilyNotSupport } from '../utils';
2
+ // 菜单
2
3
  export const getMenuButtonBoundingClientRect = temporarilyNotSupport('getMenuButtonBoundingClientRect');
@@ -1,7 +1,9 @@
1
1
  import { MethodHandler } from '../../utils/handler';
2
2
  import { getParameterError, shouldBeObject, temporarilyNotSupport } from '../../utils';
3
+ // 导航栏
3
4
  export const showNavigationBarLoading = temporarilyNotSupport('showNavigationBarLoading');
4
5
  export function setNavigationBarTitle(options) {
6
+ // options must be an Object
5
7
  const isObject = shouldBeObject(options);
6
8
  if (!isObject.flag) {
7
9
  const res = { errMsg: `setNavigationBarTitle:fail ${isObject.msg}` };
@@ -24,6 +26,9 @@ export function setNavigationBarTitle(options) {
24
26
  }
25
27
  return handle.success();
26
28
  }
29
+ /**
30
+ * 设置页面导航条颜色
31
+ */
27
32
  export const setNavigationBarColor = (options) => {
28
33
  const { backgroundColor, success, fail, complete } = options;
29
34
  const handle = new MethodHandler({ name: 'setNavigationBarColor', success, fail, complete });
@@ -1,5 +1,8 @@
1
1
  import Taro from '@tarojs/api';
2
2
  import { MethodHandler } from '../utils/handler';
3
+ /**
4
+ * 开始下拉刷新。调用后触发下拉刷新动画,效果与用户手动下拉刷新一致。
5
+ */
3
6
  export const startPullDownRefresh = function ({ success, fail, complete } = {}) {
4
7
  const handle = new MethodHandler({ name: 'startPullDownRefresh', success, fail, complete });
5
8
  return new Promise((resolve, reject) => {
@@ -9,6 +12,9 @@ export const startPullDownRefresh = function ({ success, fail, complete } = {})
9
12
  });
10
13
  });
11
14
  };
15
+ /**
16
+ * 停止当前页面下拉刷新。
17
+ */
12
18
  export const stopPullDownRefresh = function ({ success, fail, complete } = {}) {
13
19
  const handle = new MethodHandler({ name: 'stopPullDownRefresh', success, fail, complete });
14
20
  return new Promise((resolve, reject) => {
@@ -3,6 +3,9 @@ import { MethodHandler } from '../../utils/handler';
3
3
  import { getTimingFunc, easeInOut } from '../../utils';
4
4
  let timer;
5
5
  const FRAME_DURATION = 17;
6
+ /**
7
+ * 将页面滚动到目标位置
8
+ */
6
9
  export const pageScrollTo = ({ scrollTop, selector = '', duration = 300, success, fail, complete }) => {
7
10
  let scrollFunc;
8
11
  const handle = new MethodHandler({ name: 'pageScrollTo', success, fail, complete });
@@ -1,2 +1,3 @@
1
1
  import { temporarilyNotSupport } from '../utils';
2
+ // 置顶
2
3
  export const setTopBarText = temporarilyNotSupport('setTopBarText');
@@ -5,7 +5,11 @@ let tabConf;
5
5
  export function initTabBarApis(config = {}) {
6
6
  tabConf = config.tabBar;
7
7
  }
8
+ /**
9
+ * 显示 tabBar 某一项的右上角的红点
10
+ */
8
11
  export const showTabBarRedDot = (options) => {
12
+ // options must be an Object
9
13
  const isObject = shouldBeObject(options);
10
14
  if (!isObject.flag) {
11
15
  const res = { errMsg: `showTabBarRedDot:fail ${isObject.msg}` };
@@ -31,7 +35,11 @@ export const showTabBarRedDot = (options) => {
31
35
  });
32
36
  });
33
37
  };
38
+ /**
39
+ * 显示 tabBar
40
+ */
34
41
  export const showTabBar = (options = {}) => {
42
+ // options must be an Object
35
43
  const isObject = shouldBeObject(options);
36
44
  if (!isObject.flag) {
37
45
  const res = { errMsg: `showTabBar:fail ${isObject.msg}` };
@@ -57,7 +65,11 @@ export const showTabBar = (options = {}) => {
57
65
  });
58
66
  });
59
67
  };
68
+ /**
69
+ * 动态设置 tabBar 的整体样式
70
+ */
60
71
  export const setTabBarStyle = (options = {}) => {
72
+ // options must be an Object
61
73
  const isObject = shouldBeObject(options);
62
74
  if (!isObject.flag) {
63
75
  const res = { errMsg: `setTabBarStyle:fail ${isObject.msg}` };
@@ -105,7 +117,11 @@ export const setTabBarStyle = (options = {}) => {
105
117
  });
106
118
  });
107
119
  };
120
+ /**
121
+ * 动态设置 tabBar 某一项的内容
122
+ */
108
123
  export const setTabBarItem = (options) => {
124
+ // options must be an Object
109
125
  const isObject = shouldBeObject(options);
110
126
  if (!isObject.flag) {
111
127
  const res = { errMsg: `setTabBarItem:fail ${isObject.msg}` };
@@ -134,7 +150,11 @@ export const setTabBarItem = (options) => {
134
150
  });
135
151
  });
136
152
  };
153
+ /**
154
+ * 为 tabBar 某一项的右上角添加文本
155
+ */
137
156
  export const setTabBarBadge = (options) => {
157
+ // options must be an Object
138
158
  const isObject = shouldBeObject(options);
139
159
  if (!isObject.flag) {
140
160
  const res = { errMsg: `setTabBarBadge:fail ${isObject.msg}` };
@@ -170,7 +190,11 @@ export const setTabBarBadge = (options) => {
170
190
  });
171
191
  });
172
192
  };
193
+ /**
194
+ * 移除 tabBar 某一项右上角的文本
195
+ */
173
196
  export const removeTabBarBadge = (options) => {
197
+ // options must be an Object
174
198
  const isObject = shouldBeObject(options);
175
199
  if (!isObject.flag) {
176
200
  const res = { errMsg: `removeTabBarBadge:fail ${isObject.msg}` };
@@ -196,7 +220,11 @@ export const removeTabBarBadge = (options) => {
196
220
  });
197
221
  });
198
222
  };
223
+ /**
224
+ * 隐藏 tabBar 某一项的右上角的红点
225
+ */
199
226
  export const hideTabBarRedDot = (options) => {
227
+ // options must be an Object
200
228
  const isObject = shouldBeObject(options);
201
229
  if (!isObject.flag) {
202
230
  const res = { errMsg: `hideTabBarRedDot:fail ${isObject.msg}` };
@@ -222,7 +250,11 @@ export const hideTabBarRedDot = (options) => {
222
250
  });
223
251
  });
224
252
  };
253
+ /**
254
+ * 隐藏 tabBar
255
+ */
225
256
  export const hideTabBar = (options = {}) => {
257
+ // options must be an Object
226
258
  const isObject = shouldBeObject(options);
227
259
  if (!isObject.flag) {
228
260
  const res = { errMsg: `hideTabBar:fail ${isObject.msg}` };
@@ -7,13 +7,22 @@ const resizeListener = () => {
7
7
  windowHeight: window.screen.height
8
8
  });
9
9
  };
10
+ /**
11
+ * 设置窗口大小,该接口仅适用于 PC 平台,使用细则请参见指南
12
+ */
10
13
  export const setWindowSize = temporarilyNotSupport('setWindowSize');
14
+ /**
15
+ * 监听窗口尺寸变化事件
16
+ */
11
17
  export const onWindowResize = callback => {
12
18
  callbackManager.add(callback);
13
19
  if (callbackManager.count() === 1) {
14
20
  window.addEventListener('resize', resizeListener);
15
21
  }
16
22
  };
23
+ /**
24
+ * 取消监听窗口尺寸变化事件
25
+ */
17
26
  export const offWindowResize = callback => {
18
27
  callbackManager.remove(callback);
19
28
  if (callbackManager.count() === 0) {