@tarojs/taro-h5 3.3.16 → 3.4.0-beta.1

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 (175) hide show
  1. package/dist/index.cjs.js +9439 -10025
  2. package/dist/index.js +10767 -0
  3. package/dist/taroApis.js +1 -1
  4. package/package.json +9 -13
  5. package/src/api/ad/index.ts +5 -0
  6. package/src/api/ai/facial.ts +6 -0
  7. package/src/api/ai/index.ts +2 -0
  8. package/src/api/ai/visual.ts +4 -0
  9. package/src/api/alipay/index.ts +4 -0
  10. package/src/api/base/crypto.ts +4 -0
  11. package/src/api/base/debug.ts +5 -0
  12. package/src/api/base/index.ts +23 -0
  13. package/src/api/base/performance.ts +5 -0
  14. package/src/api/base/system/index.ts +2 -0
  15. package/src/api/base/system/info.ts +64 -0
  16. package/src/api/base/system/network.ts +70 -0
  17. package/src/api/base/update.ts +5 -0
  18. package/src/api/base/weapp/app-event.ts +19 -0
  19. package/src/api/base/weapp/life-cycle.ts +5 -0
  20. package/src/api/canvas/CanvasContext.ts +230 -0
  21. package/src/api/canvas/canvasGetImageData.ts +27 -0
  22. package/src/api/canvas/canvasPutImageData.ts +24 -0
  23. package/src/api/canvas/canvasToTempFilePath.ts +24 -0
  24. package/src/api/canvas/createCanvasContext.ts +18 -0
  25. package/src/api/canvas/index.ts +10 -0
  26. package/src/api/cloud/index.ts +27 -0
  27. package/src/api/data-analysis/index.ts +6 -0
  28. package/src/api/device/accelerometer.ts +87 -0
  29. package/src/api/device/accessibility.ts +4 -0
  30. package/src/api/device/battery.ts +5 -0
  31. package/src/api/device/bluetooth-ble.ts +19 -0
  32. package/src/api/device/bluetooth-peripheral.ts +6 -0
  33. package/src/api/device/bluetooth.ts +16 -0
  34. package/src/api/device/calendar.ts +5 -0
  35. package/src/api/device/clipboard.ts +67 -0
  36. package/src/api/device/compass.ts +67 -0
  37. package/src/api/device/contact.ts +5 -0
  38. package/src/api/device/crypto.ts +4 -0
  39. package/src/api/device/gyroscope.ts +7 -0
  40. package/src/api/device/iBeacon.ts +10 -0
  41. package/src/api/device/index.ts +22 -0
  42. package/src/api/device/keyboard.ts +7 -0
  43. package/src/api/device/memory.ts +5 -0
  44. package/src/api/device/motion.ts +85 -0
  45. package/src/api/device/nfc.ts +10 -0
  46. package/src/api/device/phone.ts +30 -0
  47. package/src/api/device/scan.ts +7 -0
  48. package/src/api/device/screen.ts +9 -0
  49. package/src/api/device/vibrate.ts +36 -0
  50. package/src/api/device/wifi.ts +13 -0
  51. package/src/api/ext/index.ts +5 -0
  52. package/src/api/files/index.ts +11 -0
  53. package/src/api/framework/index.ts +10 -0
  54. package/src/api/index.ts +25 -0
  55. package/src/api/location/chooseLocation.ts +106 -0
  56. package/src/api/location/index.ts +19 -0
  57. package/src/api/location/style.css +8 -8
  58. package/src/api/media/audio/index.ts +105 -0
  59. package/src/api/media/background-audio.ts +12 -0
  60. package/src/api/media/camera.ts +4 -0
  61. package/src/api/media/editor.ts +29 -0
  62. package/src/api/media/image/chooseImage.ts +78 -0
  63. package/src/api/media/image/getImageInfo.ts +35 -0
  64. package/src/api/media/image/index.ts +13 -0
  65. package/src/api/media/image/previewImage.ts +101 -0
  66. package/src/api/media/index.ts +13 -0
  67. package/src/api/media/live.ts +5 -0
  68. package/src/api/media/map.ts +4 -0
  69. package/src/api/media/media-recorder.ts +4 -0
  70. package/src/api/media/recorder.ts +6 -0
  71. package/src/api/media/video/index.ts +82 -0
  72. package/src/api/media/video-decoder.ts +4 -0
  73. package/src/api/media/video-processing.ts +4 -0
  74. package/src/api/media/voip.ts +17 -0
  75. package/src/api/navigate/index.ts +7 -0
  76. package/src/api/{fileTransfer/downloadFile.js → network/download.ts} +16 -27
  77. package/src/api/network/index.ts +7 -0
  78. package/src/api/network/mdns.ts +13 -0
  79. package/src/api/{request/index.js → network/request/index.ts} +9 -6
  80. package/src/api/network/tcp.ts +4 -0
  81. package/src/api/network/udp.ts +4 -0
  82. package/src/api/{fileTransfer/uploadFile.js → network/upload.ts} +28 -32
  83. package/src/api/{fileTransfer/utils.js → network/utils.ts} +0 -0
  84. package/src/api/network/websocket/index.ts +88 -0
  85. package/src/api/{webSocket/socketTask.js → network/websocket/socketTask.ts} +17 -7
  86. package/src/api/open-api/account.ts +4 -0
  87. package/src/api/open-api/address.ts +4 -0
  88. package/src/api/open-api/authorize.ts +5 -0
  89. package/src/api/open-api/card.ts +5 -0
  90. package/src/api/open-api/channels-live.ts +9 -0
  91. package/src/api/open-api/customer-service.ts +4 -0
  92. package/src/api/open-api/facial.ts +7 -0
  93. package/src/api/open-api/favorites.ts +5 -0
  94. package/src/api/open-api/group.ts +4 -0
  95. package/src/api/open-api/index.ts +18 -0
  96. package/src/api/open-api/invoice.ts +5 -0
  97. package/src/api/open-api/license-plate.ts +4 -0
  98. package/src/api/open-api/login.ts +6 -0
  99. package/src/api/open-api/red-package.ts +4 -0
  100. package/src/api/open-api/settings.ts +5 -0
  101. package/src/api/open-api/soter.ts +6 -0
  102. package/src/api/open-api/subscribe-message.ts +4 -0
  103. package/src/api/open-api/user-info.ts +5 -0
  104. package/src/api/open-api/werun.ts +5 -0
  105. package/src/api/payment/index.ts +5 -0
  106. package/src/api/route/index.ts +10 -0
  107. package/src/api/share/index.ts +13 -0
  108. package/src/api/storage/background-fetch.ts +7 -0
  109. package/src/api/storage/index.ts +181 -0
  110. package/src/api/swan/index.ts +31 -0
  111. package/src/{taro/index.js → api/taro.ts} +89 -149
  112. package/src/api/{createAnimation/index.js → ui/animation/index.ts} +51 -35
  113. package/src/api/ui/background.ts +5 -0
  114. package/src/api/ui/custom-component.ts +4 -0
  115. package/src/api/ui/fonts.ts +4 -0
  116. package/src/api/ui/index.ts +12 -0
  117. package/src/api/ui/interaction/actionSheet.ts +212 -0
  118. package/src/api/{interactive/index.js → ui/interaction/index.ts} +93 -77
  119. package/src/api/ui/interaction/modal.ts +237 -0
  120. package/src/api/{interactive/toast.js → ui/interaction/toast.ts} +35 -33
  121. package/src/api/ui/menu.ts +4 -0
  122. package/src/api/ui/navigation-bar/index.ts +52 -0
  123. package/src/api/ui/pull-down-refresh.ts +27 -0
  124. package/src/api/ui/scroll/index.ts +85 -0
  125. package/src/api/ui/sticky.ts +4 -0
  126. package/src/api/ui/tab-bar.ts +326 -0
  127. package/src/api/ui/window.ts +37 -0
  128. package/src/api/utils/handler.ts +105 -0
  129. package/src/api/utils/{index.js → index.ts} +36 -115
  130. package/src/api/worker/index.ts +4 -0
  131. package/src/api/wxml/index.ts +9 -0
  132. package/src/api/wxml/nodesRef.ts +49 -0
  133. package/src/api/{createSelectorQuery/index.js → wxml/selectorQuery.ts} +75 -94
  134. package/src/index.ts +6 -0
  135. package/src/types/api.d.ts +4 -0
  136. package/src/types/define.d.ts +2 -0
  137. package/{types → src/types}/index.d.ts +0 -0
  138. package/{types → src/types}/type.ts +1 -1
  139. package/src/api/accelerometer/index.js +0 -105
  140. package/src/api/audio/index.js +0 -137
  141. package/src/api/canvas/canvasGetImageData.js +0 -44
  142. package/src/api/canvas/canvasPutImageData.js +0 -45
  143. package/src/api/canvas/canvasToTempFilePath.js +0 -49
  144. package/src/api/canvas/createCanvasContext.js +0 -340
  145. package/src/api/canvas/index.js +0 -4
  146. package/src/api/clipboard/index.js +0 -113
  147. package/src/api/compass/index.js +0 -99
  148. package/src/api/deviceMotion/index.js +0 -105
  149. package/src/api/fileTransfer/index.js +0 -2
  150. package/src/api/image/chooseImage.js +0 -87
  151. package/src/api/image/getImageInfo.js +0 -74
  152. package/src/api/image/index.js +0 -7
  153. package/src/api/image/previewImage.js +0 -94
  154. package/src/api/index.js +0 -29
  155. package/src/api/interactive/actionSheet.js +0 -214
  156. package/src/api/interactive/modal.js +0 -256
  157. package/src/api/location/chooseLocation.js +0 -143
  158. package/src/api/location/index.js +0 -5
  159. package/src/api/navigationBar/index.js +0 -57
  160. package/src/api/open/index.js +0 -5
  161. package/src/api/others/index.js +0 -43
  162. package/src/api/pullDownRefresh/index.js +0 -51
  163. package/src/api/scroll/index.js +0 -99
  164. package/src/api/storage/index.js +0 -211
  165. package/src/api/system/index.js +0 -9
  166. package/src/api/system/info.js +0 -36
  167. package/src/api/system/network.js +0 -68
  168. package/src/api/tabBar/index.js +0 -402
  169. package/src/api/unsupportedApi/index.js +0 -278
  170. package/src/api/vibrate/index.js +0 -49
  171. package/src/api/video/index.js +0 -87
  172. package/src/api/webSocket/index.js +0 -103
  173. package/src/api/window/index.js +0 -38
  174. package/src/index.cjs.js +0 -11
  175. package/src/index.js +0 -6
@@ -1,3 +1,5 @@
1
+ import Taro from '@tarojs/api'
2
+
1
3
  /**
2
4
  * H5 下的 styleSheet 操作
3
5
  * @author leeenx
@@ -7,14 +9,14 @@ class StyleSheet {
7
9
  this.$style = document.createElement('style')
8
10
  }
9
11
 
10
- $style = null
11
- sheet = null
12
+ $style: HTMLStyleElement
13
+ sheet?: CSSStyleSheet | null
12
14
  appendStyleSheet = () => {
13
- this.$style.setAttribute('type', 'text/css')
14
- this.$style.setAttribute('data-type', 'Taro')
15
+ this.$style?.setAttribute('type', 'text/css')
16
+ this.$style?.setAttribute('data-type', 'Taro')
15
17
  document.getElementsByTagName('head')[0].appendChild(this.$style)
16
- this.sheet = this.$style.sheet
17
- if (!('insertRule' in this.sheet)) {
18
+ this.sheet = this.$style?.sheet
19
+ if (this.sheet && !('insertRule' in this.sheet)) {
18
20
  console.warn('当前浏览器不支持 stylesheet.insertRule 接口')
19
21
  }
20
22
  }
@@ -25,7 +27,7 @@ class StyleSheet {
25
27
  // $style 未插入到 DOM
26
28
  this.appendStyleSheet()
27
29
  }
28
- this.sheet.insertRule(cssText, index)
30
+ this.sheet?.insertRule(cssText, index)
29
31
  }
30
32
  }
31
33
 
@@ -48,22 +50,32 @@ if ($detect.style['animation-name'] === 'standard') {
48
50
  TRANSFORM = 'transform'
49
51
  } else if ($detect.style['-webkit-animation-name'] === 'webkit') {
50
52
  // webkit 前缀
51
- TRANSITION_END = 'webkitTransionEnd'
53
+ TRANSITION_END = 'webkitTransitionEnd'
52
54
  TRANSFORM = '-webkit-transform'
53
55
  } else if ($detect.style['-moz-animation-name'] === 'moz') {
54
- // webkit 前缀
55
- TRANSITION_END = 'mozTransionEnd'
56
+ // moz 前缀
57
+ TRANSITION_END = 'mozTransitionEnd'
56
58
  TRANSFORM = '-moz-transform'
57
59
  } else if ($detect.style['-ms-animation-name'] === 'ms') {
58
- // webkit 前缀
59
- TRANSITION_END = 'MSTransionEnd'
60
+ // ms 前缀
61
+ TRANSITION_END = 'msTransitionEnd'
60
62
  TRANSFORM = '-ms-transform'
61
63
  }
62
64
 
63
65
  let animId = 0
64
66
 
65
- // Animation
66
- class Animation {
67
+ interface IAnimationAttr {
68
+ duration: number
69
+ delay: number
70
+ timingFunction: string
71
+ transformOrigin: string
72
+ }
73
+
74
+ class Animation implements Taro.Animation {
75
+ unit: string
76
+ id: number
77
+ DEFAULT: IAnimationAttr
78
+
67
79
  constructor (
68
80
  {
69
81
  duration = 400,
@@ -71,7 +83,7 @@ class Animation {
71
83
  timingFunction = 'linear',
72
84
  transformOrigin = '50% 50% 0',
73
85
  unit = 'px'
74
- } = {}
86
+ }: Taro.createAnimation.Option = {}
75
87
  ) {
76
88
  // 默认值
77
89
  this.setDefault(duration, delay, timingFunction, transformOrigin)
@@ -81,8 +93,8 @@ class Animation {
81
93
  // 动画 id
82
94
  this.id = ++animId
83
95
  // 监听事件
84
- document.body.addEventListener(TRANSITION_END, e => {
85
- const { target } = e
96
+ document.body.addEventListener(TRANSITION_END, (e: TransitionEvent) => {
97
+ const target = e.target as HTMLElement
86
98
  if (target.getAttribute(animAttr) === null) {
87
99
  animAttr = 'data-animation'
88
100
  }
@@ -91,12 +103,13 @@ class Animation {
91
103
  if (animData === null) return
92
104
  const [animName, animPath] = animData.split('__')
93
105
  if (animName === `taro-h5-poly-fill/${this.id}/create-animation`) {
94
- const [animIndex, stepIndex = 0] = animPath.split('--')
106
+ const [animIndex, __stepIndex = 0] = animPath.split('--')
107
+ const stepIndex = Number(__stepIndex)
95
108
  // 动画总的关键帧
96
109
  const animStepsCount = this.animationMap[`${animName}__${animIndex}`]
97
110
  const animStepsMaxIndex = animStepsCount - 1
98
111
  if (stepIndex < animStepsMaxIndex) {
99
- // 播放下一个关键帧(因为 nevr 和 react 有差异所以 animation & data-animation 都需要写)
112
+ // 播放下一个关键帧(因为 nerv 和 react 有差异所以 animation & data-animation 都需要写)
100
113
  target.setAttribute(animAttr, `${animName}__${animIndex}--${stepIndex + 1}`)
101
114
  if (animAttr === 'animation') {
102
115
  // Nerv 环境,animation & data-animation 双重保险
@@ -108,7 +121,7 @@ class Animation {
108
121
  }
109
122
 
110
123
  transformUnit (...args) {
111
- const ret = []
124
+ const ret: string[] = []
112
125
  args.forEach(each => {
113
126
  ret.push(isNaN(each) ? each : `${each}${this.unit}`)
114
127
  })
@@ -121,32 +134,37 @@ class Animation {
121
134
  }
122
135
 
123
136
  // 属性组合
124
- rules = []
137
+ rules: string[] = []
125
138
  // transform 对象
126
139
  transform = [`${TRANSFORM}:`]
127
140
  // 组合动画
128
- steps = []
141
+ steps: string[] = []
129
142
  // 动画 map ----- 永久保留
130
143
  animationMap = {}
131
144
  // animationMap 的长度
132
145
  animationMapCount = 0
133
- matrix (a, b, c, d, e, f) {
134
- this.transform.push(`matrix(${a}, ${b}, ${c}, ${d}, ${e}, ${f})`)
146
+
147
+ matrix (a: number, b: number, c: number, d: number, tx: number, ty: number) {
148
+ this.transform.push(`matrix(${a}, ${b}, ${c}, ${d}, ${tx}, ${ty})`)
135
149
  return this
136
150
  }
137
151
 
138
- matrix3d (a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4) {
152
+ matrix3d (a1: number, b1: number, c1: number, d1: number, a2: number, b2: number, c2: number, d2: number, a3: number, b3: number, c3: number, d3: number, a4: number, b4: number, c4: number, d4: number) {
139
153
  this.transform.push(`matrix3d(${a1}, ${b1}, ${c1}, ${d1}, ${a2}, ${b2}, ${c2}, ${d2}, ${a3}, ${b3}, ${c3}, ${d3}, ${a4}, ${b4}, ${c4}, ${d4})`)
140
154
  return this
141
155
  }
142
156
 
143
- rotate (angle) {
157
+ rotate (angle: number) {
144
158
  this.transform.push(`rotate(${angle}deg)`)
145
159
  return this
146
160
  }
147
161
 
148
- rotate3d (x, y, z, angle) {
149
- this.transform.push(`rotate3d(${x}, ${y}, ${z}, ${angle}deg)`)
162
+ rotate3d (x: number, y?: number, z?: number, angle?: number) {
163
+ if (typeof y !== 'number') {
164
+ this.transform.push(`rotate3d(${x})`)
165
+ } else {
166
+ this.transform.push(`rotate3d(${x}, ${y || 0}, ${z || 0}, ${angle || 0}deg)`)
167
+ }
150
168
  return this
151
169
  }
152
170
 
@@ -284,7 +302,7 @@ class Animation {
284
302
  }
285
303
 
286
304
  // 关键帧载入
287
- step (arg = {}) {
305
+ step (arg: Partial<IAnimationAttr> = {}) {
288
306
  const { DEFAULT } = this
289
307
  const {
290
308
  duration = DEFAULT.duration,
@@ -306,7 +324,7 @@ class Animation {
306
324
  // 清空 rules 和 transform
307
325
  this.rules = []
308
326
  this.transform = [`${TRANSFORM}:`]
309
- return this
327
+ return this as Taro.Animation
310
328
  }
311
329
 
312
330
  // 创建底层数据
@@ -329,13 +347,11 @@ class Animation {
329
347
 
330
348
  // 动画数据产出
331
349
  export () {
332
- return this.createAnimationData()
350
+ return this.createAnimationData() as unknown as ReturnType<Taro.Animation['export']>
333
351
  }
334
352
  }
335
353
 
336
354
  // h5 的 createAnimation
337
- function createAnimation (...arg) {
338
- return new Animation(...arg)
355
+ export const createAnimation: typeof Taro.createAnimation = (option) => {
356
+ return new Animation(option)
339
357
  }
340
-
341
- export { createAnimation }
@@ -0,0 +1,5 @@
1
+ import { temporarilyNotSupport } from '../utils'
2
+
3
+ // 背景
4
+ export const setBackgroundTextStyle = temporarilyNotSupport('setBackgroundTextStyle')
5
+ export const setBackgroundColor = temporarilyNotSupport('setBackgroundColor')
@@ -0,0 +1,4 @@
1
+ import Taro from '@tarojs/api'
2
+
3
+ // 自定义组件
4
+ export const nextTick = Taro.nextTick
@@ -0,0 +1,4 @@
1
+ import { temporarilyNotSupport } from '../utils'
2
+
3
+ // 字体
4
+ export const loadFontFace = temporarilyNotSupport('loadFontFace')
@@ -0,0 +1,12 @@
1
+ export * from './animation'
2
+ export * from './background'
3
+ export * from './custom-component'
4
+ export * from './fonts'
5
+ export * from './menu'
6
+ export * from './navigation-bar'
7
+ export * from './pull-down-refresh'
8
+ export * from './scroll'
9
+ export * from './sticky'
10
+ export * from './tab-bar'
11
+ export * from './window'
12
+ export * from './interaction'
@@ -0,0 +1,212 @@
1
+ import { inlineStyle, setTransform } from '../../utils'
2
+
3
+ const noop = function () {}
4
+
5
+ export default class ActionSheet {
6
+ options = {
7
+ itemList: [],
8
+ itemColor: '#000000',
9
+ success: noop,
10
+ fail: noop,
11
+ complete: noop
12
+ }
13
+
14
+ style = {
15
+ maskStyle: {
16
+ position: 'fixed',
17
+ 'z-index': '1000',
18
+ top: '0',
19
+ right: '0',
20
+ left: '0',
21
+ bottom: '0',
22
+ background: 'rgba(0,0,0,0.6)'
23
+ },
24
+ actionSheetStyle: {
25
+ 'z-index': '4999',
26
+ position: 'fixed',
27
+ left: '0',
28
+ bottom: '0',
29
+ '-webkit-transform': 'translate(0, 100%)',
30
+ transform: 'translate(0, 100%)',
31
+ width: '100%',
32
+ 'line-height': '1.6',
33
+ background: '#EFEFF4',
34
+ '-webkit-transition': '-webkit-transform .3s',
35
+ transition: 'transform .3s'
36
+ },
37
+ menuStyle: {
38
+ 'background-color': '#FCFCFD'
39
+ },
40
+ cellStyle: {
41
+ position: 'relative',
42
+ padding: '10px 0',
43
+ 'text-align': 'center',
44
+ 'font-size': '18px'
45
+ },
46
+ cancelStyle: {
47
+ 'margin-top': '6px',
48
+ padding: '10px 0',
49
+ 'text-align': 'center',
50
+ 'font-size': '18px',
51
+ color: '#000000',
52
+ 'background-color': '#FCFCFD'
53
+ }
54
+ }
55
+
56
+ lastConfig = {}
57
+ el: HTMLDivElement
58
+ actionSheet: HTMLDivElement
59
+ menu: HTMLDivElement
60
+ cells: HTMLDivElement[]
61
+ cancel: HTMLDivElement
62
+ hideOpacityTimer: any
63
+ hideDisplayTimer: any
64
+
65
+ create (options = {}) {
66
+ return new Promise<string | number>((resolve) => {
67
+ // style
68
+ const { maskStyle, actionSheetStyle, menuStyle, cellStyle, cancelStyle } = this.style
69
+
70
+ // configuration
71
+ const config = {
72
+ ...this.options,
73
+ ...options
74
+ }
75
+
76
+ this.lastConfig = config
77
+
78
+ // wrapper
79
+ this.el = document.createElement('div')
80
+ this.el.className = 'taro__actionSheet'
81
+ this.el.style.opacity = '0'
82
+ this.el.style.transition = 'opacity 0.2s linear'
83
+
84
+ // mask
85
+ const mask = document.createElement('div')
86
+ mask.setAttribute('style', inlineStyle(maskStyle))
87
+
88
+ // actionSheet
89
+ this.actionSheet = document.createElement('div')
90
+ this.actionSheet.setAttribute('style', inlineStyle(actionSheetStyle))
91
+
92
+ // menu
93
+ this.menu = document.createElement('div')
94
+ this.menu.setAttribute('style', inlineStyle({
95
+ ...menuStyle,
96
+ color: config.itemColor
97
+ }))
98
+
99
+ // cells
100
+ this.cells = config.itemList.map((item, index) => {
101
+ const cell: HTMLDivElement = document.createElement('div')
102
+ cell.className = 'taro-actionsheet__cell'
103
+ cell.setAttribute('style', inlineStyle(cellStyle))
104
+ cell.textContent = item
105
+ cell.dataset.tapIndex = `${index}`
106
+ cell.onclick = e => {
107
+ this.hide()
108
+ const target = e.currentTarget as HTMLDivElement
109
+ const index = Number(target?.dataset.tapIndex) || 0
110
+ resolve(index)
111
+ }
112
+ return cell
113
+ })
114
+
115
+ // cancel
116
+ this.cancel = document.createElement('div')
117
+ this.cancel.setAttribute('style', inlineStyle(cancelStyle))
118
+ this.cancel.textContent = '取消'
119
+
120
+ // result
121
+ this.cells.forEach(item => this.menu.appendChild(item))
122
+ this.actionSheet.appendChild(this.menu)
123
+ this.actionSheet.appendChild(this.cancel)
124
+ this.el.appendChild(mask)
125
+ this.el.appendChild(this.actionSheet)
126
+
127
+ // callbacks
128
+ const cb = () => {
129
+ this.hide()
130
+ resolve('cancel')
131
+ }
132
+ mask.onclick = cb
133
+ this.cancel.onclick = cb
134
+
135
+ // show immediately
136
+ document.body.appendChild(this.el)
137
+ setTimeout(() => {
138
+ this.el.style.opacity = '1'
139
+ setTransform(this.actionSheet, 'translate(0, 0)')
140
+ }, 0)
141
+ })
142
+ }
143
+
144
+ show (options = {}) {
145
+ return new Promise<string | number>((resolve) => {
146
+ const config = {
147
+ ...this.options,
148
+ ...options
149
+ }
150
+
151
+ this.lastConfig = config
152
+
153
+ if (this.hideOpacityTimer) clearTimeout(this.hideOpacityTimer)
154
+ if (this.hideDisplayTimer) clearTimeout(this.hideDisplayTimer)
155
+
156
+ // itemColor
157
+ if (config.itemColor) this.menu.style.color = config.itemColor
158
+
159
+ // cells
160
+ const { cellStyle } = this.style
161
+
162
+ config.itemList.forEach((item, index) => {
163
+ let cell: HTMLDivElement
164
+ if (this.cells[index]) {
165
+ // assign new content
166
+ cell = this.cells[index]
167
+ } else {
168
+ // create new cell
169
+ cell = document.createElement('div')
170
+ cell.className = 'taro-actionsheet__cell'
171
+ cell.setAttribute('style', inlineStyle(cellStyle))
172
+ cell.dataset.tapIndex = `${index}`
173
+ this.cells.push(cell)
174
+ this.menu.appendChild(cell)
175
+ }
176
+ cell.textContent = item
177
+ cell.onclick = e => {
178
+ this.hide()
179
+ const target = e.currentTarget as HTMLDivElement
180
+ const index = Number(target?.dataset.tapIndex) || 0
181
+ resolve(index)
182
+ }
183
+ })
184
+ const cellsLen = this.cells.length
185
+ const itemListLen = config.itemList.length
186
+ if (cellsLen > itemListLen) {
187
+ for (let i = itemListLen; i < cellsLen; i++) {
188
+ this.menu.removeChild(this.cells[i])
189
+ }
190
+ this.cells.splice(itemListLen)
191
+ }
192
+
193
+ // show
194
+ this.el.style.display = 'block'
195
+ setTimeout(() => {
196
+ this.el.style.opacity = '1'
197
+ setTransform(this.actionSheet, 'translate(0, 0)')
198
+ }, 0)
199
+ })
200
+ }
201
+
202
+ hide () {
203
+ if (this.hideOpacityTimer) clearTimeout(this.hideOpacityTimer)
204
+ if (this.hideDisplayTimer) clearTimeout(this.hideDisplayTimer)
205
+
206
+ this.hideOpacityTimer = setTimeout(() => {
207
+ this.el.style.opacity = '0'
208
+ setTransform(this.actionSheet, 'translate(0, 100%)')
209
+ this.hideDisplayTimer = setTimeout(() => { this.el.style.display = 'none' }, 200)
210
+ }, 0)
211
+ }
212
+ }