@tarojs/taro-h5 3.4.0-beta.2 → 3.4.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 (168) hide show
  1. package/dist/api/ad/index.js +4 -0
  2. package/dist/api/ai/facial.js +5 -0
  3. package/dist/api/ai/index.js +2 -0
  4. package/dist/api/ai/visual.js +5 -0
  5. package/dist/api/alipay/index.js +3 -0
  6. package/dist/api/base/crypto.js +3 -0
  7. package/dist/api/base/debug.js +4 -0
  8. package/dist/api/base/index.js +17 -0
  9. package/dist/api/base/performance.js +4 -0
  10. package/dist/api/base/system.js +187 -0
  11. package/dist/api/base/update.js +4 -0
  12. package/dist/api/base/weapp/app-event.js +18 -0
  13. package/dist/api/base/weapp/life-cycle.js +4 -0
  14. package/dist/api/canvas/CanvasContext.js +191 -0
  15. package/dist/api/canvas/canvasGetImageData.js +25 -0
  16. package/dist/api/canvas/canvasPutImageData.js +22 -0
  17. package/dist/api/canvas/canvasToTempFilePath.js +22 -0
  18. package/dist/api/canvas/createCanvasContext.js +16 -0
  19. package/dist/api/canvas/index.js +12 -0
  20. package/dist/api/cloud/index.js +21 -0
  21. package/dist/api/data-analysis/index.js +5 -0
  22. package/dist/api/device/accelerometer.js +83 -0
  23. package/dist/api/device/accessibility.js +3 -0
  24. package/dist/api/device/battery.js +21 -0
  25. package/dist/api/device/bluetooth-ble.js +18 -0
  26. package/dist/api/device/bluetooth-peripheral.js +5 -0
  27. package/dist/api/device/bluetooth.js +15 -0
  28. package/dist/api/device/calendar.js +4 -0
  29. package/dist/api/device/clipboard.js +65 -0
  30. package/dist/api/device/compass.js +64 -0
  31. package/dist/api/device/contact.js +4 -0
  32. package/dist/api/device/crypto.js +3 -0
  33. package/dist/api/device/gyroscope.js +6 -0
  34. package/dist/api/device/iBeacon.js +9 -0
  35. package/dist/api/device/index.js +23 -0
  36. package/dist/api/device/keyboard.js +6 -0
  37. package/dist/api/device/memory.js +4 -0
  38. package/dist/api/device/motion.js +81 -0
  39. package/dist/api/device/network.js +78 -0
  40. package/dist/api/device/nfc.js +9 -0
  41. package/dist/api/device/phone.js +24 -0
  42. package/dist/api/device/scan.js +6 -0
  43. package/dist/api/device/screen.js +8 -0
  44. package/dist/api/device/vibrate.js +35 -0
  45. package/dist/api/device/wifi.js +13 -0
  46. package/dist/api/ext/index.js +4 -0
  47. package/dist/api/files/index.js +10 -0
  48. package/dist/api/framework/index.js +7 -0
  49. package/dist/api/index.js +24 -0
  50. package/dist/api/location/chooseLocation.js +93 -0
  51. package/dist/api/location/index.js +13 -0
  52. package/dist/api/location/style.css +79 -0
  53. package/dist/api/media/EditorContext.js +19 -0
  54. package/dist/api/media/audio/InnerAudioContext.js +84 -0
  55. package/dist/api/media/audio/index.js +15 -0
  56. package/dist/api/media/background-audio/BackgroundAudioManager.js +86 -0
  57. package/dist/api/media/background-audio/index.js +15 -0
  58. package/dist/api/media/camera.js +3 -0
  59. package/dist/api/media/image/chooseImage.js +74 -0
  60. package/dist/api/media/image/getImageInfo.js +31 -0
  61. package/dist/api/media/image/index.js +9 -0
  62. package/dist/api/media/image/previewImage.js +67 -0
  63. package/dist/api/media/index.js +12 -0
  64. package/dist/api/media/live.js +4 -0
  65. package/dist/api/media/map.js +3 -0
  66. package/dist/api/media/media-recorder.js +3 -0
  67. package/dist/api/media/recorder.js +5 -0
  68. package/dist/api/media/video/index.js +74 -0
  69. package/dist/api/media/video-decoder.js +3 -0
  70. package/dist/api/media/video-processing.js +3 -0
  71. package/dist/api/media/voip.js +16 -0
  72. package/dist/api/navigate/index.js +6 -0
  73. package/dist/api/network/download.js +124 -0
  74. package/dist/api/network/index.js +7 -0
  75. package/dist/api/network/mdns.js +12 -0
  76. package/dist/api/network/request/index.js +125 -0
  77. package/dist/api/network/tcp.js +3 -0
  78. package/dist/api/network/udp.js +3 -0
  79. package/dist/api/network/upload.js +146 -0
  80. package/dist/api/network/utils.js +65 -0
  81. package/dist/api/network/websocket/index.js +70 -0
  82. package/dist/api/network/websocket/socketTask.js +63 -0
  83. package/dist/api/open-api/account.js +3 -0
  84. package/dist/api/open-api/address.js +3 -0
  85. package/dist/api/open-api/authorize.js +4 -0
  86. package/dist/api/open-api/card.js +4 -0
  87. package/dist/api/open-api/channels-live.js +8 -0
  88. package/dist/api/open-api/customer-service.js +3 -0
  89. package/dist/api/open-api/facial.js +6 -0
  90. package/dist/api/open-api/favorites.js +4 -0
  91. package/dist/api/open-api/group.js +3 -0
  92. package/dist/api/open-api/index.js +18 -0
  93. package/dist/api/open-api/invoice.js +4 -0
  94. package/dist/api/open-api/license-plate.js +3 -0
  95. package/dist/api/open-api/login.js +5 -0
  96. package/dist/api/open-api/red-package.js +3 -0
  97. package/dist/api/open-api/settings.js +4 -0
  98. package/dist/api/open-api/soter.js +5 -0
  99. package/dist/api/open-api/subscribe-message.js +3 -0
  100. package/dist/api/open-api/user-info.js +4 -0
  101. package/dist/api/open-api/werun.js +4 -0
  102. package/dist/api/payment/index.js +4 -0
  103. package/dist/api/route/index.js +3 -0
  104. package/dist/api/share/index.js +12 -0
  105. package/dist/api/storage/background-fetch.js +6 -0
  106. package/dist/api/storage/index.js +157 -0
  107. package/dist/api/swan/index.js +26 -0
  108. package/dist/api/taro.js +47 -0
  109. package/dist/api/ui/animation/index.js +288 -0
  110. package/dist/api/ui/background.js +4 -0
  111. package/dist/api/ui/custom-component.js +3 -0
  112. package/dist/api/ui/fonts.js +51 -0
  113. package/dist/api/ui/index.js +12 -0
  114. package/dist/api/ui/interaction/actionSheet.js +188 -0
  115. package/dist/api/ui/interaction/index.js +268 -0
  116. package/dist/api/ui/interaction/modal.js +207 -0
  117. package/dist/api/ui/interaction/toast.js +195 -0
  118. package/dist/api/ui/menu.js +3 -0
  119. package/dist/api/ui/navigation-bar/index.js +42 -0
  120. package/dist/api/ui/pull-down-refresh.js +26 -0
  121. package/dist/api/ui/scroll/index.js +83 -0
  122. package/dist/api/ui/sticky.js +3 -0
  123. package/dist/api/ui/tab-bar.js +282 -0
  124. package/dist/api/ui/window.js +31 -0
  125. package/dist/api/utils/handler.js +80 -0
  126. package/dist/api/utils/index.js +172 -0
  127. package/dist/api/worker/index.js +3 -0
  128. package/dist/api/wxml/index.js +6 -0
  129. package/dist/api/wxml/nodesRef.js +42 -0
  130. package/dist/api/wxml/selectorQuery.js +201 -0
  131. package/dist/index.cjs.js +5028 -6988
  132. package/dist/index.js +4 -10767
  133. package/dist/taroApis.js +1 -1
  134. package/dist/types/type.js +2 -0
  135. package/package.json +11 -13
  136. package/src/api/ai/visual.ts +3 -0
  137. package/src/api/base/system.ts +207 -0
  138. package/src/api/canvas/CanvasContext.ts +42 -39
  139. package/src/api/canvas/createCanvasContext.ts +2 -2
  140. package/src/api/canvas/index.ts +10 -2
  141. package/src/api/cloud/index.ts +4 -0
  142. package/src/api/device/battery.ts +18 -1
  143. package/src/api/device/index.ts +1 -0
  144. package/src/api/{base/system → device}/network.ts +35 -15
  145. package/src/api/device/wifi.ts +1 -0
  146. package/src/api/location/chooseLocation.ts +2 -2
  147. package/src/api/media/{editor.ts → EditorContext.ts} +2 -0
  148. package/src/api/media/audio/InnerAudioContext.ts +98 -0
  149. package/src/api/media/audio/index.ts +1 -86
  150. package/src/api/media/background-audio/BackgroundAudioManager.ts +103 -0
  151. package/src/api/media/{background-audio.ts → background-audio/index.ts} +7 -2
  152. package/src/api/media/image/previewImage.ts +4 -25
  153. package/src/api/media/index.ts +0 -1
  154. package/src/api/network/download.ts +5 -5
  155. package/src/api/network/upload.ts +7 -13
  156. package/src/api/network/websocket/index.ts +1 -1
  157. package/src/api/ui/animation/index.ts +11 -12
  158. package/src/api/ui/fonts.ts +61 -2
  159. package/src/api/ui/interaction/index.ts +12 -10
  160. package/src/api/ui/navigation-bar/index.ts +2 -2
  161. package/src/api/ui/scroll/index.ts +3 -3
  162. package/src/api/utils/handler.ts +4 -4
  163. package/src/api/utils/index.ts +34 -13
  164. package/src/api/wxml/nodesRef.ts +10 -3
  165. package/src/api/wxml/selectorQuery.ts +68 -23
  166. package/src/index.ts +2 -2
  167. package/src/api/base/system/index.ts +0 -2
  168. package/src/api/base/system/info.ts +0 -64
@@ -0,0 +1,288 @@
1
+ /**
2
+ * H5 下的 styleSheet 操作
3
+ * @author leeenx
4
+ */
5
+ class StyleSheet {
6
+ constructor() {
7
+ this.$style = null;
8
+ this.sheet = null;
9
+ this.appendStyleSheet = () => {
10
+ if (this.$style) {
11
+ const head = document.getElementsByTagName('head')[0];
12
+ this.$style.setAttribute('type', 'text/css');
13
+ this.$style.setAttribute('data-type', 'Taro');
14
+ head.appendChild(this.$style);
15
+ this.sheet = this.$style.sheet;
16
+ }
17
+ if (this.sheet && !('insertRule' in this.sheet)) {
18
+ console.warn('当前浏览器不支持 stylesheet.insertRule 接口');
19
+ }
20
+ };
21
+ // 添加样式命令
22
+ this.add = (cssText, index = 0) => {
23
+ var _a;
24
+ if (this.sheet === null) {
25
+ // $style 未插入到 DOM
26
+ this.appendStyleSheet();
27
+ }
28
+ (_a = this.sheet) === null || _a === void 0 ? void 0 : _a.insertRule(cssText, index);
29
+ };
30
+ this.$style = document.createElement('style');
31
+ }
32
+ }
33
+ const styleSheet = new StyleSheet();
34
+ // 监听事件
35
+ let TRANSITION_END = 'transitionend';
36
+ let TRANSFORM = 'transform';
37
+ const $detect = document.createElement('div');
38
+ $detect.style.cssText = '-webkit-animation-name:webkit;-moz-animation-name:moz;-ms-animation-name:ms;animation-name:standard;';
39
+ if ($detect.style['animation-name'] === 'standard') {
40
+ // 支持标准写法
41
+ TRANSITION_END = 'transitionend';
42
+ TRANSFORM = 'transform';
43
+ }
44
+ else if ($detect.style['-webkit-animation-name'] === 'webkit') {
45
+ // webkit 前缀
46
+ TRANSITION_END = 'webkitTransitionEnd';
47
+ TRANSFORM = '-webkit-transform';
48
+ }
49
+ else if ($detect.style['-moz-animation-name'] === 'moz') {
50
+ // moz 前缀
51
+ TRANSITION_END = 'mozTransitionEnd';
52
+ TRANSFORM = '-moz-transform';
53
+ }
54
+ else if ($detect.style['-ms-animation-name'] === 'ms') {
55
+ // ms 前缀
56
+ TRANSITION_END = 'msTransitionEnd';
57
+ TRANSFORM = '-ms-transform';
58
+ }
59
+ let animId = 0;
60
+ class Animation {
61
+ constructor({ duration = 400, delay = 0, timingFunction = 'linear', transformOrigin = '50% 50% 0', unit = 'px' } = {}) {
62
+ // 属性组合
63
+ this.rules = [];
64
+ // transform 对象
65
+ this.transform = [`${TRANSFORM}:`];
66
+ // 组合动画
67
+ this.steps = [];
68
+ // 动画 map ----- 永久保留
69
+ this.animationMap = {};
70
+ // animationMap 的长度
71
+ this.animationMapCount = 0;
72
+ // 默认值
73
+ this.setDefault(duration, delay, timingFunction, transformOrigin);
74
+ this.unit = unit;
75
+ // atom 环境下,animation 属性不会显示,所以要改成 data-animation
76
+ let animAttr = 'animation';
77
+ // 动画 id
78
+ this.id = ++animId;
79
+ // 监听事件
80
+ document.body.addEventListener(TRANSITION_END, (e) => {
81
+ const target = e.target;
82
+ if (target.getAttribute(animAttr) === null) {
83
+ animAttr = 'data-animation';
84
+ }
85
+ const animData = target.getAttribute(animAttr);
86
+ // 没有动画存在
87
+ if (animData === null)
88
+ return;
89
+ const [animName, animPath] = animData.split('__');
90
+ if (animName === `taro-h5-poly-fill/${this.id}/create-animation`) {
91
+ const [animIndex, __stepIndex = 0] = animPath.split('--');
92
+ const stepIndex = Number(__stepIndex);
93
+ // 动画总的关键帧
94
+ const animStepsCount = this.animationMap[`${animName}__${animIndex}`];
95
+ const animStepsMaxIndex = animStepsCount - 1;
96
+ if (stepIndex < animStepsMaxIndex) {
97
+ // 播放下一个关键帧(因为 nerv 和 react 有差异所以 animation & data-animation 都需要写)
98
+ target.setAttribute(animAttr, `${animName}__${animIndex}--${stepIndex + 1}`);
99
+ if (animAttr === 'animation') {
100
+ // Nerv 环境,animation & data-animation 双重保险
101
+ target.setAttribute('data-animation', `${animName}__${animIndex}--${stepIndex + 1}`);
102
+ }
103
+ }
104
+ }
105
+ });
106
+ }
107
+ transformUnit(...args) {
108
+ const ret = [];
109
+ args.forEach(each => {
110
+ ret.push(isNaN(each) ? each : `${each}${this.unit}`);
111
+ });
112
+ return ret;
113
+ }
114
+ // 设置默认值
115
+ setDefault(duration, delay, timingFunction, transformOrigin) {
116
+ this.DEFAULT = { duration, delay, timingFunction, transformOrigin };
117
+ }
118
+ matrix(a, b, c, d, tx, ty) {
119
+ this.transform.push(`matrix(${a}, ${b}, ${c}, ${d}, ${tx}, ${ty})`);
120
+ return this;
121
+ }
122
+ matrix3d(a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4) {
123
+ this.transform.push(`matrix3d(${a1}, ${b1}, ${c1}, ${d1}, ${a2}, ${b2}, ${c2}, ${d2}, ${a3}, ${b3}, ${c3}, ${d3}, ${a4}, ${b4}, ${c4}, ${d4})`);
124
+ return this;
125
+ }
126
+ rotate(angle) {
127
+ this.transform.push(`rotate(${angle}deg)`);
128
+ return this;
129
+ }
130
+ rotate3d(x, y, z, angle) {
131
+ if (typeof y !== 'number') {
132
+ this.transform.push(`rotate3d(${x})`);
133
+ }
134
+ else {
135
+ this.transform.push(`rotate3d(${x}, ${y || 0}, ${z || 0}, ${angle || 0}deg)`);
136
+ }
137
+ return this;
138
+ }
139
+ rotateX(angle) {
140
+ this.transform.push(`rotateX(${angle}deg)`);
141
+ return this;
142
+ }
143
+ rotateY(angle) {
144
+ this.transform.push(`rotateY(${angle}deg)`);
145
+ return this;
146
+ }
147
+ rotateZ(angle) {
148
+ this.transform.push(`rotateZ(${angle}deg)`);
149
+ return this;
150
+ }
151
+ scale(x, y) {
152
+ this.transform.push(`scale(${x}, ${y})`);
153
+ return this;
154
+ }
155
+ scale3d(x, y, z) {
156
+ this.transform.push(`scale3d(${x}, ${y}, ${z})`);
157
+ return this;
158
+ }
159
+ scaleX(scale) {
160
+ this.transform.push(`scaleX(${scale})`);
161
+ return this;
162
+ }
163
+ scaleY(scale) {
164
+ this.transform.push(`scaleY(${scale})`);
165
+ return this;
166
+ }
167
+ scaleZ(scale) {
168
+ this.transform.push(`scaleZ(${scale})`);
169
+ return this;
170
+ }
171
+ skew(x, y) {
172
+ this.transform.push(`skew(${x}, ${y})`);
173
+ return this;
174
+ }
175
+ skewX(angle) {
176
+ this.transform.push(`skewX(${angle})`);
177
+ return this;
178
+ }
179
+ skewY(angle) {
180
+ this.transform.push(`skewY(${angle})`);
181
+ return this;
182
+ }
183
+ translate(x, y) {
184
+ [x, y] = this.transformUnit(x, y);
185
+ this.transform.push(`translate(${x}, ${y})`);
186
+ return this;
187
+ }
188
+ translate3d(x, y, z) {
189
+ [x, y, z] = this.transformUnit(x, y, z);
190
+ this.transform.push(`translate3d(${x}, ${y}, ${z})`);
191
+ return this;
192
+ }
193
+ translateX(translate) {
194
+ [translate] = this.transformUnit(translate);
195
+ this.transform.push(`translateX(${translate})`);
196
+ return this;
197
+ }
198
+ translateY(translate) {
199
+ [translate] = this.transformUnit(translate);
200
+ this.transform.push(`translateY(${translate})`);
201
+ return this;
202
+ }
203
+ translateZ(translate) {
204
+ [translate] = this.transformUnit(translate);
205
+ this.transform.push(`translateZ(${translate})`);
206
+ return this;
207
+ }
208
+ opacity(value) {
209
+ this.rules.push(`opacity: ${value}`);
210
+ return this;
211
+ }
212
+ backgroundColor(value) {
213
+ this.rules.push(`background-color: ${value}`);
214
+ return this;
215
+ }
216
+ width(value) {
217
+ [value] = this.transformUnit(value);
218
+ this.rules.push(`width: ${value}`);
219
+ return this;
220
+ }
221
+ height(value) {
222
+ [value] = this.transformUnit(value);
223
+ this.rules.push(`height: ${value}`);
224
+ return this;
225
+ }
226
+ top(value) {
227
+ [value] = this.transformUnit(value);
228
+ this.rules.push(`top: ${value}`);
229
+ return this;
230
+ }
231
+ right(value) {
232
+ [value] = this.transformUnit(value);
233
+ this.rules.push(`right: ${value}`);
234
+ return this;
235
+ }
236
+ bottom(value) {
237
+ [value] = this.transformUnit(value);
238
+ this.rules.push(`bottom: ${value}`);
239
+ return this;
240
+ }
241
+ left(value) {
242
+ [value] = this.transformUnit(value);
243
+ this.rules.push(`left: ${value}`);
244
+ return this;
245
+ }
246
+ // 关键帧载入
247
+ step(arg = {}) {
248
+ const { DEFAULT } = this;
249
+ const { duration = DEFAULT.duration, delay = DEFAULT.delay, timingFunction = DEFAULT.timingFunction, transformOrigin = DEFAULT.transformOrigin } = arg;
250
+ // 生成一条 transition 动画
251
+ this.steps.push([
252
+ this.rules.map(rule => `${rule}!important`).join(';'),
253
+ `${this.transform.join(' ')}!important`,
254
+ `${TRANSFORM}-origin: ${transformOrigin}`,
255
+ `transition: all ${duration}ms ${timingFunction} ${delay}ms`
256
+ ]
257
+ .filter(item => item !== '' && item !== `${TRANSFORM}:`)
258
+ .join(';'));
259
+ // 清空 rules 和 transform
260
+ this.rules = [];
261
+ this.transform = [`${TRANSFORM}:`];
262
+ return this;
263
+ }
264
+ // 创建底层数据
265
+ createAnimationData() {
266
+ const animIndex = `taro-h5-poly-fill/${this.id}/create-animation__${this.animationMapCount++}`;
267
+ // 记录动画分几个 step
268
+ this.animationMap[animIndex] = this.steps.length;
269
+ // 吐出 step
270
+ this.steps.forEach((step, index) => {
271
+ const selector = index === 0
272
+ ? `[animation="${animIndex}"], [data-animation="${animIndex}"]`
273
+ : `[animation="${animIndex}--${index}"], [data-animation="${animIndex}--${index}"]`;
274
+ styleSheet.add(`${selector} { ${step} }`);
275
+ });
276
+ // 清空 steps
277
+ this.steps = [];
278
+ return animIndex;
279
+ }
280
+ // 动画数据产出
281
+ export() {
282
+ return this.createAnimationData();
283
+ }
284
+ }
285
+ // h5 的 createAnimation
286
+ export const createAnimation = (option) => {
287
+ return new Animation(option);
288
+ };
@@ -0,0 +1,4 @@
1
+ import { temporarilyNotSupport } from '../utils';
2
+ // 背景
3
+ export const setBackgroundTextStyle = temporarilyNotSupport('setBackgroundTextStyle');
4
+ export const setBackgroundColor = temporarilyNotSupport('setBackgroundColor');
@@ -0,0 +1,3 @@
1
+ import Taro from '@tarojs/api';
2
+ // 自定义组件
3
+ export const nextTick = Taro.nextTick;
@@ -0,0 +1,51 @@
1
+ import { MethodHandler } from '../utils/handler';
2
+ // 字体
3
+ export const loadFontFace = async (options) => {
4
+ options = Object.assign({ global: false }, options);
5
+ const { success, fail, complete, family, source, desc = {} } = options;
6
+ const handle = new MethodHandler({ name: 'loadFontFace', success, fail, complete });
7
+ // @ts-ignore
8
+ const fonts = document.fonts;
9
+ if (fonts) {
10
+ // @ts-ignore
11
+ const fontFace = new FontFace(family, source, desc);
12
+ try {
13
+ await fontFace.load();
14
+ fonts.add(fontFace);
15
+ return handle.success({});
16
+ }
17
+ catch (error) {
18
+ return handle.fail({
19
+ errMsg: error.message || error
20
+ });
21
+ }
22
+ }
23
+ else {
24
+ const style = document.createElement('style');
25
+ let innerText = `font-family:"${family}";src:${source};font-style:${desc.style || 'normal'};font-weight:${desc.weight || 'normal'};font-variant:${desc.variant || 'normal'};`;
26
+ if (desc.ascentOverride) {
27
+ innerText += `ascent-override:${desc.ascentOverride};`;
28
+ }
29
+ if (desc.descentOverride) {
30
+ innerText += `descent-override:${desc.descentOverride};`;
31
+ }
32
+ if (desc.featureSettings) {
33
+ innerText += `font-feature-settings:${desc.featureSettings};`;
34
+ }
35
+ if (desc.lineGapOverride) {
36
+ innerText += `line-gap-override:${desc.lineGapOverride};`;
37
+ }
38
+ if (desc.stretch) {
39
+ innerText += `font-stretch:${desc.stretch};`;
40
+ }
41
+ if (desc.unicodeRange) {
42
+ innerText += `unicode-range:${desc.unicodeRange};`;
43
+ }
44
+ if (desc.variationSettings) {
45
+ innerText += `font-variation-settings:${desc.variationSettings};`;
46
+ }
47
+ style.innerText = `@font-face{${innerText}}`;
48
+ document.head.appendChild(style);
49
+ return handle.success();
50
+ }
51
+ };
@@ -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,188 @@
1
+ import { inlineStyle, setTransform } from '../../utils';
2
+ const noop = function () { };
3
+ export default class ActionSheet {
4
+ constructor() {
5
+ this.options = {
6
+ itemList: [],
7
+ itemColor: '#000000',
8
+ success: noop,
9
+ fail: noop,
10
+ complete: noop
11
+ };
12
+ this.style = {
13
+ maskStyle: {
14
+ position: 'fixed',
15
+ 'z-index': '1000',
16
+ top: '0',
17
+ right: '0',
18
+ left: '0',
19
+ bottom: '0',
20
+ background: 'rgba(0,0,0,0.6)'
21
+ },
22
+ actionSheetStyle: {
23
+ 'z-index': '4999',
24
+ position: 'fixed',
25
+ left: '0',
26
+ bottom: '0',
27
+ '-webkit-transform': 'translate(0, 100%)',
28
+ transform: 'translate(0, 100%)',
29
+ width: '100%',
30
+ 'line-height': '1.6',
31
+ background: '#EFEFF4',
32
+ '-webkit-transition': '-webkit-transform .3s',
33
+ transition: 'transform .3s'
34
+ },
35
+ menuStyle: {
36
+ 'background-color': '#FCFCFD'
37
+ },
38
+ cellStyle: {
39
+ position: 'relative',
40
+ padding: '10px 0',
41
+ 'text-align': 'center',
42
+ 'font-size': '18px'
43
+ },
44
+ cancelStyle: {
45
+ 'margin-top': '6px',
46
+ padding: '10px 0',
47
+ 'text-align': 'center',
48
+ 'font-size': '18px',
49
+ color: '#000000',
50
+ 'background-color': '#FCFCFD'
51
+ }
52
+ };
53
+ this.lastConfig = {};
54
+ }
55
+ create(options = {}) {
56
+ return new Promise((resolve) => {
57
+ // style
58
+ const { maskStyle, actionSheetStyle, menuStyle, cellStyle, cancelStyle } = this.style;
59
+ // configuration
60
+ const config = {
61
+ ...this.options,
62
+ ...options
63
+ };
64
+ this.lastConfig = config;
65
+ // wrapper
66
+ this.el = document.createElement('div');
67
+ this.el.className = 'taro__actionSheet';
68
+ this.el.style.opacity = '0';
69
+ this.el.style.transition = 'opacity 0.2s linear';
70
+ // mask
71
+ const mask = document.createElement('div');
72
+ mask.setAttribute('style', inlineStyle(maskStyle));
73
+ // actionSheet
74
+ this.actionSheet = document.createElement('div');
75
+ this.actionSheet.setAttribute('style', inlineStyle(actionSheetStyle));
76
+ // menu
77
+ this.menu = document.createElement('div');
78
+ this.menu.setAttribute('style', inlineStyle({
79
+ ...menuStyle,
80
+ color: config.itemColor
81
+ }));
82
+ // cells
83
+ this.cells = config.itemList.map((item, index) => {
84
+ const cell = document.createElement('div');
85
+ cell.className = 'taro-actionsheet__cell';
86
+ cell.setAttribute('style', inlineStyle(cellStyle));
87
+ cell.textContent = item;
88
+ cell.dataset.tapIndex = `${index}`;
89
+ cell.onclick = e => {
90
+ this.hide();
91
+ const target = e.currentTarget;
92
+ const index = Number(target === null || target === void 0 ? void 0 : target.dataset.tapIndex) || 0;
93
+ resolve(index);
94
+ };
95
+ return cell;
96
+ });
97
+ // cancel
98
+ this.cancel = document.createElement('div');
99
+ this.cancel.setAttribute('style', inlineStyle(cancelStyle));
100
+ this.cancel.textContent = '取消';
101
+ // result
102
+ this.cells.forEach(item => this.menu.appendChild(item));
103
+ this.actionSheet.appendChild(this.menu);
104
+ this.actionSheet.appendChild(this.cancel);
105
+ this.el.appendChild(mask);
106
+ this.el.appendChild(this.actionSheet);
107
+ // callbacks
108
+ const cb = () => {
109
+ this.hide();
110
+ resolve('cancel');
111
+ };
112
+ mask.onclick = cb;
113
+ this.cancel.onclick = cb;
114
+ // show immediately
115
+ document.body.appendChild(this.el);
116
+ setTimeout(() => {
117
+ this.el.style.opacity = '1';
118
+ setTransform(this.actionSheet, 'translate(0, 0)');
119
+ }, 0);
120
+ });
121
+ }
122
+ show(options = {}) {
123
+ return new Promise((resolve) => {
124
+ const config = {
125
+ ...this.options,
126
+ ...options
127
+ };
128
+ this.lastConfig = config;
129
+ if (this.hideOpacityTimer)
130
+ clearTimeout(this.hideOpacityTimer);
131
+ if (this.hideDisplayTimer)
132
+ clearTimeout(this.hideDisplayTimer);
133
+ // itemColor
134
+ if (config.itemColor)
135
+ this.menu.style.color = config.itemColor;
136
+ // cells
137
+ const { cellStyle } = this.style;
138
+ config.itemList.forEach((item, index) => {
139
+ let cell;
140
+ if (this.cells[index]) {
141
+ // assign new content
142
+ cell = this.cells[index];
143
+ }
144
+ else {
145
+ // create new cell
146
+ cell = document.createElement('div');
147
+ cell.className = 'taro-actionsheet__cell';
148
+ cell.setAttribute('style', inlineStyle(cellStyle));
149
+ cell.dataset.tapIndex = `${index}`;
150
+ this.cells.push(cell);
151
+ this.menu.appendChild(cell);
152
+ }
153
+ cell.textContent = item;
154
+ cell.onclick = e => {
155
+ this.hide();
156
+ const target = e.currentTarget;
157
+ const index = Number(target === null || target === void 0 ? void 0 : target.dataset.tapIndex) || 0;
158
+ resolve(index);
159
+ };
160
+ });
161
+ const cellsLen = this.cells.length;
162
+ const itemListLen = config.itemList.length;
163
+ if (cellsLen > itemListLen) {
164
+ for (let i = itemListLen; i < cellsLen; i++) {
165
+ this.menu.removeChild(this.cells[i]);
166
+ }
167
+ this.cells.splice(itemListLen);
168
+ }
169
+ // show
170
+ this.el.style.display = 'block';
171
+ setTimeout(() => {
172
+ this.el.style.opacity = '1';
173
+ setTransform(this.actionSheet, 'translate(0, 0)');
174
+ }, 0);
175
+ });
176
+ }
177
+ hide() {
178
+ if (this.hideOpacityTimer)
179
+ clearTimeout(this.hideOpacityTimer);
180
+ if (this.hideDisplayTimer)
181
+ clearTimeout(this.hideDisplayTimer);
182
+ this.hideOpacityTimer = setTimeout(() => {
183
+ this.el.style.opacity = '0';
184
+ setTransform(this.actionSheet, 'translate(0, 100%)');
185
+ this.hideDisplayTimer = setTimeout(() => { this.el.style.display = 'none'; }, 200);
186
+ }, 0);
187
+ }
188
+ }