@tarojs/taro-h5 3.3.18 → 3.3.19
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.
- package/dist/api/ad/index.js +3 -0
- package/dist/api/ai/facial.js +4 -0
- package/dist/api/ai/index.js +2 -0
- package/dist/api/ai/visual.js +2 -0
- package/dist/api/alipay/index.js +2 -0
- package/dist/api/base/crypto.js +2 -0
- package/dist/api/base/debug.js +4 -0
- package/dist/api/base/index.js +16 -0
- package/dist/api/base/performance.js +3 -0
- package/dist/api/base/system/index.js +2 -0
- package/dist/api/base/system/info.js +56 -0
- package/dist/api/base/system/network.js +52 -0
- package/dist/api/base/update.js +3 -0
- package/dist/api/base/weapp/app-event.js +17 -0
- package/dist/api/base/weapp/life-cycle.js +3 -0
- package/dist/api/canvas/CanvasContext.js +182 -0
- package/dist/api/canvas/canvasGetImageData.js +21 -0
- package/dist/api/canvas/canvasPutImageData.js +17 -0
- package/dist/api/canvas/canvasToTempFilePath.js +18 -0
- package/dist/api/canvas/createCanvasContext.js +13 -0
- package/dist/api/canvas/index.js +7 -0
- package/dist/api/cloud/index.js +14 -0
- package/dist/api/data-analysis/index.js +5 -0
- package/dist/api/device/accelerometer.js +71 -0
- package/dist/api/device/accessibility.js +2 -0
- package/dist/api/device/battery.js +3 -0
- package/dist/api/device/bluetooth-ble.js +17 -0
- package/dist/api/device/bluetooth-peripheral.js +4 -0
- package/dist/api/device/bluetooth.js +14 -0
- package/dist/api/device/calendar.js +3 -0
- package/dist/api/device/clipboard.js +48 -0
- package/dist/api/device/compass.js +52 -0
- package/dist/api/device/contact.js +3 -0
- package/dist/api/device/crypto.js +2 -0
- package/dist/api/device/gyroscope.js +5 -0
- package/dist/api/device/iBeacon.js +8 -0
- package/dist/api/device/index.js +22 -0
- package/dist/api/device/keyboard.js +5 -0
- package/dist/api/device/memory.js +3 -0
- package/dist/api/device/motion.js +69 -0
- package/dist/api/device/nfc.js +8 -0
- package/dist/api/device/phone.js +23 -0
- package/dist/api/device/scan.js +5 -0
- package/dist/api/device/screen.js +7 -0
- package/dist/api/device/vibrate.js +29 -0
- package/dist/api/device/wifi.js +11 -0
- package/dist/api/ext/index.js +3 -0
- package/dist/api/files/index.js +9 -0
- package/dist/api/framework/index.js +6 -0
- package/dist/api/index.js +24 -0
- package/dist/api/location/chooseLocation.js +88 -0
- package/dist/api/location/index.js +12 -0
- package/dist/api/location/style.css +79 -0
- package/dist/api/media/audio/index.js +81 -0
- package/dist/api/media/background-audio.js +10 -0
- package/dist/api/media/camera.js +2 -0
- package/dist/api/media/editor.js +17 -0
- package/dist/api/media/image/chooseImage.js +70 -0
- package/dist/api/media/image/getImageInfo.js +27 -0
- package/dist/api/media/image/index.js +8 -0
- package/dist/api/media/image/previewImage.js +78 -0
- package/dist/api/media/index.js +13 -0
- package/dist/api/media/live.js +3 -0
- package/dist/api/media/map.js +2 -0
- package/dist/api/media/media-recorder.js +2 -0
- package/dist/api/media/recorder.js +4 -0
- package/dist/api/media/video/index.js +65 -0
- package/dist/api/media/video-decoder.js +2 -0
- package/dist/api/media/video-processing.js +2 -0
- package/dist/api/media/voip.js +15 -0
- package/dist/api/navigate/index.js +5 -0
- package/dist/api/network/download.js +101 -0
- package/dist/api/network/index.js +7 -0
- package/dist/api/network/mdns.js +11 -0
- package/dist/api/network/request/index.js +123 -0
- package/dist/api/network/tcp.js +2 -0
- package/dist/api/network/udp.js +2 -0
- package/dist/api/network/upload.js +129 -0
- package/dist/api/network/utils.js +30 -0
- package/dist/api/network/websocket/index.js +65 -0
- package/dist/api/network/websocket/socketTask.js +61 -0
- package/dist/api/open-api/account.js +2 -0
- package/dist/api/open-api/address.js +2 -0
- package/dist/api/open-api/authorize.js +3 -0
- package/dist/api/open-api/card.js +3 -0
- package/dist/api/open-api/channels-live.js +7 -0
- package/dist/api/open-api/customer-service.js +2 -0
- package/dist/api/open-api/facial.js +5 -0
- package/dist/api/open-api/favorites.js +3 -0
- package/dist/api/open-api/group.js +2 -0
- package/dist/api/open-api/index.js +18 -0
- package/dist/api/open-api/invoice.js +3 -0
- package/dist/api/open-api/license-plate.js +2 -0
- package/dist/api/open-api/login.js +4 -0
- package/dist/api/open-api/red-package.js +2 -0
- package/dist/api/open-api/settings.js +3 -0
- package/dist/api/open-api/soter.js +4 -0
- package/dist/api/open-api/subscribe-message.js +2 -0
- package/dist/api/open-api/user-info.js +3 -0
- package/dist/api/open-api/werun.js +3 -0
- package/dist/api/payment/index.js +3 -0
- package/dist/api/route/index.js +1 -0
- package/dist/api/share/index.js +11 -0
- package/dist/api/storage/background-fetch.js +5 -0
- package/dist/api/storage/index.js +152 -0
- package/dist/api/swan/index.js +22 -0
- package/dist/api/taro.js +59 -0
- package/dist/api/ui/animation/index.js +255 -0
- package/dist/api/ui/background.js +3 -0
- package/dist/api/ui/custom-component.js +2 -0
- package/dist/api/ui/fonts.js +2 -0
- package/dist/api/ui/index.js +12 -0
- package/dist/api/ui/interaction/actionSheet.js +172 -0
- package/dist/api/ui/interaction/index.js +263 -0
- package/dist/api/ui/interaction/modal.js +185 -0
- package/dist/api/ui/interaction/toast.js +179 -0
- package/dist/api/ui/menu.js +2 -0
- package/dist/api/ui/navigation-bar/index.js +37 -0
- package/dist/api/ui/pull-down-refresh.js +20 -0
- package/dist/api/ui/scroll/index.js +80 -0
- package/dist/api/ui/sticky.js +2 -0
- package/dist/api/ui/tab-bar.js +250 -0
- package/dist/api/ui/window.js +22 -0
- package/dist/api/utils/handler.js +64 -0
- package/dist/api/utils/index.js +141 -0
- package/dist/api/worker/index.js +2 -0
- package/dist/api/wxml/index.js +6 -0
- package/dist/api/wxml/nodesRef.js +35 -0
- package/dist/api/wxml/selectorQuery.js +140 -0
- package/dist/index.cjs.js +4261 -5796
- package/dist/index.js +4 -9493
- package/dist/types/type.js +2 -0
- package/package.json +8 -11
- package/src/api/network/download.ts +5 -5
- package/src/api/network/upload.ts +5 -5
- package/src/api/network/websocket/index.ts +1 -1
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
class StyleSheet {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.appendStyleSheet = () => {
|
|
4
|
+
var _a, _b, _c;
|
|
5
|
+
(_a = this.$style) === null || _a === void 0 ? void 0 : _a.setAttribute('type', 'text/css');
|
|
6
|
+
(_b = this.$style) === null || _b === void 0 ? void 0 : _b.setAttribute('data-type', 'Taro');
|
|
7
|
+
document.getElementsByTagName('head')[0].appendChild(this.$style);
|
|
8
|
+
this.sheet = (_c = this.$style) === null || _c === void 0 ? void 0 : _c.sheet;
|
|
9
|
+
if (this.sheet && !('insertRule' in this.sheet)) {
|
|
10
|
+
console.warn('当前浏览器不支持 stylesheet.insertRule 接口');
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
this.add = (cssText, index = 0) => {
|
|
14
|
+
var _a;
|
|
15
|
+
if (this.sheet === null) {
|
|
16
|
+
this.appendStyleSheet();
|
|
17
|
+
}
|
|
18
|
+
(_a = this.sheet) === null || _a === void 0 ? void 0 : _a.insertRule(cssText, index);
|
|
19
|
+
};
|
|
20
|
+
this.$style = document.createElement('style');
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const styleSheet = new StyleSheet();
|
|
24
|
+
let TRANSITION_END = 'transitionend';
|
|
25
|
+
let TRANSFORM = 'transform';
|
|
26
|
+
const $detect = document.createElement('div');
|
|
27
|
+
$detect.style.cssText = `
|
|
28
|
+
-webkit-animation-name: webkit;
|
|
29
|
+
-moz-animation-name: moz;
|
|
30
|
+
-ms-animation-name: ms;
|
|
31
|
+
animation-name: standard;
|
|
32
|
+
`;
|
|
33
|
+
if ($detect.style['animation-name'] === 'standard') {
|
|
34
|
+
TRANSITION_END = 'transitionend';
|
|
35
|
+
TRANSFORM = 'transform';
|
|
36
|
+
}
|
|
37
|
+
else if ($detect.style['-webkit-animation-name'] === 'webkit') {
|
|
38
|
+
TRANSITION_END = 'webkitTransitionEnd';
|
|
39
|
+
TRANSFORM = '-webkit-transform';
|
|
40
|
+
}
|
|
41
|
+
else if ($detect.style['-moz-animation-name'] === 'moz') {
|
|
42
|
+
TRANSITION_END = 'mozTransitionEnd';
|
|
43
|
+
TRANSFORM = '-moz-transform';
|
|
44
|
+
}
|
|
45
|
+
else if ($detect.style['-ms-animation-name'] === 'ms') {
|
|
46
|
+
TRANSITION_END = 'msTransitionEnd';
|
|
47
|
+
TRANSFORM = '-ms-transform';
|
|
48
|
+
}
|
|
49
|
+
let animId = 0;
|
|
50
|
+
class Animation {
|
|
51
|
+
constructor({ duration = 400, delay = 0, timingFunction = 'linear', transformOrigin = '50% 50% 0', unit = 'px' } = {}) {
|
|
52
|
+
this.rules = [];
|
|
53
|
+
this.transform = [`${TRANSFORM}:`];
|
|
54
|
+
this.steps = [];
|
|
55
|
+
this.animationMap = {};
|
|
56
|
+
this.animationMapCount = 0;
|
|
57
|
+
this.setDefault(duration, delay, timingFunction, transformOrigin);
|
|
58
|
+
this.unit = unit;
|
|
59
|
+
let animAttr = 'animation';
|
|
60
|
+
this.id = ++animId;
|
|
61
|
+
document.body.addEventListener(TRANSITION_END, (e) => {
|
|
62
|
+
const target = e.target;
|
|
63
|
+
if (target.getAttribute(animAttr) === null) {
|
|
64
|
+
animAttr = 'data-animation';
|
|
65
|
+
}
|
|
66
|
+
const animData = target.getAttribute(animAttr);
|
|
67
|
+
if (animData === null)
|
|
68
|
+
return;
|
|
69
|
+
const [animName, animPath] = animData.split('__');
|
|
70
|
+
if (animName === `taro-h5-poly-fill/${this.id}/create-animation`) {
|
|
71
|
+
const [animIndex, __stepIndex = 0] = animPath.split('--');
|
|
72
|
+
const stepIndex = Number(__stepIndex);
|
|
73
|
+
const animStepsCount = this.animationMap[`${animName}__${animIndex}`];
|
|
74
|
+
const animStepsMaxIndex = animStepsCount - 1;
|
|
75
|
+
if (stepIndex < animStepsMaxIndex) {
|
|
76
|
+
target.setAttribute(animAttr, `${animName}__${animIndex}--${stepIndex + 1}`);
|
|
77
|
+
if (animAttr === 'animation') {
|
|
78
|
+
target.setAttribute('data-animation', `${animName}__${animIndex}--${stepIndex + 1}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
transformUnit(...args) {
|
|
85
|
+
const ret = [];
|
|
86
|
+
args.forEach(each => {
|
|
87
|
+
ret.push(isNaN(each) ? each : `${each}${this.unit}`);
|
|
88
|
+
});
|
|
89
|
+
return ret;
|
|
90
|
+
}
|
|
91
|
+
setDefault(duration, delay, timingFunction, transformOrigin) {
|
|
92
|
+
this.DEFAULT = { duration, delay, timingFunction, transformOrigin };
|
|
93
|
+
}
|
|
94
|
+
matrix(a, b, c, d, tx, ty) {
|
|
95
|
+
this.transform.push(`matrix(${a}, ${b}, ${c}, ${d}, ${tx}, ${ty})`);
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
matrix3d(a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4) {
|
|
99
|
+
this.transform.push(`matrix3d(${a1}, ${b1}, ${c1}, ${d1}, ${a2}, ${b2}, ${c2}, ${d2}, ${a3}, ${b3}, ${c3}, ${d3}, ${a4}, ${b4}, ${c4}, ${d4})`);
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
rotate(angle) {
|
|
103
|
+
this.transform.push(`rotate(${angle}deg)`);
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
106
|
+
rotate3d(x, y, z, angle) {
|
|
107
|
+
if (typeof y !== 'number') {
|
|
108
|
+
this.transform.push(`rotate3d(${x})`);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
this.transform.push(`rotate3d(${x}, ${y || 0}, ${z || 0}, ${angle || 0}deg)`);
|
|
112
|
+
}
|
|
113
|
+
return this;
|
|
114
|
+
}
|
|
115
|
+
rotateX(angle) {
|
|
116
|
+
this.transform.push(`rotateX(${angle}deg)`);
|
|
117
|
+
return this;
|
|
118
|
+
}
|
|
119
|
+
rotateY(angle) {
|
|
120
|
+
this.transform.push(`rotateY(${angle}deg)`);
|
|
121
|
+
return this;
|
|
122
|
+
}
|
|
123
|
+
rotateZ(angle) {
|
|
124
|
+
this.transform.push(`rotateZ(${angle}deg)`);
|
|
125
|
+
return this;
|
|
126
|
+
}
|
|
127
|
+
scale(x, y) {
|
|
128
|
+
this.transform.push(`scale(${x}, ${y})`);
|
|
129
|
+
return this;
|
|
130
|
+
}
|
|
131
|
+
scale3d(x, y, z) {
|
|
132
|
+
this.transform.push(`scale3d(${x}, ${y}, ${z})`);
|
|
133
|
+
return this;
|
|
134
|
+
}
|
|
135
|
+
scaleX(scale) {
|
|
136
|
+
this.transform.push(`scaleX(${scale})`);
|
|
137
|
+
return this;
|
|
138
|
+
}
|
|
139
|
+
scaleY(scale) {
|
|
140
|
+
this.transform.push(`scaleY(${scale})`);
|
|
141
|
+
return this;
|
|
142
|
+
}
|
|
143
|
+
scaleZ(scale) {
|
|
144
|
+
this.transform.push(`scaleZ(${scale})`);
|
|
145
|
+
return this;
|
|
146
|
+
}
|
|
147
|
+
skew(x, y) {
|
|
148
|
+
this.transform.push(`skew(${x}, ${y})`);
|
|
149
|
+
return this;
|
|
150
|
+
}
|
|
151
|
+
skewX(angle) {
|
|
152
|
+
this.transform.push(`skewX(${angle})`);
|
|
153
|
+
return this;
|
|
154
|
+
}
|
|
155
|
+
skewY(angle) {
|
|
156
|
+
this.transform.push(`skewY(${angle})`);
|
|
157
|
+
return this;
|
|
158
|
+
}
|
|
159
|
+
translate(x, y) {
|
|
160
|
+
[x, y] = this.transformUnit(x, y);
|
|
161
|
+
this.transform.push(`translate(${x}, ${y})`);
|
|
162
|
+
return this;
|
|
163
|
+
}
|
|
164
|
+
translate3d(x, y, z) {
|
|
165
|
+
[x, y, z] = this.transformUnit(x, y, z);
|
|
166
|
+
this.transform.push(`translate3d(${x}, ${y}, ${z})`);
|
|
167
|
+
return this;
|
|
168
|
+
}
|
|
169
|
+
translateX(translate) {
|
|
170
|
+
[translate] = this.transformUnit(translate);
|
|
171
|
+
this.transform.push(`translateX(${translate})`);
|
|
172
|
+
return this;
|
|
173
|
+
}
|
|
174
|
+
translateY(translate) {
|
|
175
|
+
[translate] = this.transformUnit(translate);
|
|
176
|
+
this.transform.push(`translateY(${translate})`);
|
|
177
|
+
return this;
|
|
178
|
+
}
|
|
179
|
+
translateZ(translate) {
|
|
180
|
+
[translate] = this.transformUnit(translate);
|
|
181
|
+
this.transform.push(`translateZ(${translate})`);
|
|
182
|
+
return this;
|
|
183
|
+
}
|
|
184
|
+
opacity(value) {
|
|
185
|
+
this.rules.push(`opacity: ${value}`);
|
|
186
|
+
return this;
|
|
187
|
+
}
|
|
188
|
+
backgroundColor(value) {
|
|
189
|
+
this.rules.push(`background-color: ${value}`);
|
|
190
|
+
return this;
|
|
191
|
+
}
|
|
192
|
+
width(value) {
|
|
193
|
+
[value] = this.transformUnit(value);
|
|
194
|
+
this.rules.push(`width: ${value}`);
|
|
195
|
+
return this;
|
|
196
|
+
}
|
|
197
|
+
height(value) {
|
|
198
|
+
[value] = this.transformUnit(value);
|
|
199
|
+
this.rules.push(`height: ${value}`);
|
|
200
|
+
return this;
|
|
201
|
+
}
|
|
202
|
+
top(value) {
|
|
203
|
+
[value] = this.transformUnit(value);
|
|
204
|
+
this.rules.push(`top: ${value}`);
|
|
205
|
+
return this;
|
|
206
|
+
}
|
|
207
|
+
right(value) {
|
|
208
|
+
[value] = this.transformUnit(value);
|
|
209
|
+
this.rules.push(`right: ${value}`);
|
|
210
|
+
return this;
|
|
211
|
+
}
|
|
212
|
+
bottom(value) {
|
|
213
|
+
[value] = this.transformUnit(value);
|
|
214
|
+
this.rules.push(`bottom: ${value}`);
|
|
215
|
+
return this;
|
|
216
|
+
}
|
|
217
|
+
left(value) {
|
|
218
|
+
[value] = this.transformUnit(value);
|
|
219
|
+
this.rules.push(`left: ${value}`);
|
|
220
|
+
return this;
|
|
221
|
+
}
|
|
222
|
+
step(arg = {}) {
|
|
223
|
+
const { DEFAULT } = this;
|
|
224
|
+
const { duration = DEFAULT.duration, delay = DEFAULT.delay, timingFunction = DEFAULT.timingFunction, transformOrigin = DEFAULT.transformOrigin } = arg;
|
|
225
|
+
this.steps.push([
|
|
226
|
+
this.rules.map(rule => `${rule}!important`).join(';'),
|
|
227
|
+
`${this.transform.join(' ')}!important`,
|
|
228
|
+
`${TRANSFORM}-origin: ${transformOrigin}`,
|
|
229
|
+
`transition: all ${duration}ms ${timingFunction} ${delay}ms`
|
|
230
|
+
]
|
|
231
|
+
.filter(item => item !== '' && item !== `${TRANSFORM}:`)
|
|
232
|
+
.join(';'));
|
|
233
|
+
this.rules = [];
|
|
234
|
+
this.transform = [`${TRANSFORM}:`];
|
|
235
|
+
return this;
|
|
236
|
+
}
|
|
237
|
+
createAnimationData() {
|
|
238
|
+
const animIndex = `taro-h5-poly-fill/${this.id}/create-animation__${this.animationMapCount++}`;
|
|
239
|
+
this.animationMap[animIndex] = this.steps.length;
|
|
240
|
+
this.steps.forEach((step, index) => {
|
|
241
|
+
const selector = index === 0
|
|
242
|
+
? `[animation="${animIndex}"], [data-animation="${animIndex}"]`
|
|
243
|
+
: `[animation="${animIndex}--${index}"], [data-animation="${animIndex}--${index}"]`;
|
|
244
|
+
styleSheet.add(`${selector} { ${step} }`);
|
|
245
|
+
});
|
|
246
|
+
this.steps = [];
|
|
247
|
+
return animIndex;
|
|
248
|
+
}
|
|
249
|
+
export() {
|
|
250
|
+
return this.createAnimationData();
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
export const createAnimation = (option) => {
|
|
254
|
+
return new Animation(option);
|
|
255
|
+
};
|
|
@@ -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,172 @@
|
|
|
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
|
+
const { maskStyle, actionSheetStyle, menuStyle, cellStyle, cancelStyle } = this.style;
|
|
58
|
+
const config = {
|
|
59
|
+
...this.options,
|
|
60
|
+
...options
|
|
61
|
+
};
|
|
62
|
+
this.lastConfig = config;
|
|
63
|
+
this.el = document.createElement('div');
|
|
64
|
+
this.el.className = 'taro__actionSheet';
|
|
65
|
+
this.el.style.opacity = '0';
|
|
66
|
+
this.el.style.transition = 'opacity 0.2s linear';
|
|
67
|
+
const mask = document.createElement('div');
|
|
68
|
+
mask.setAttribute('style', inlineStyle(maskStyle));
|
|
69
|
+
this.actionSheet = document.createElement('div');
|
|
70
|
+
this.actionSheet.setAttribute('style', inlineStyle(actionSheetStyle));
|
|
71
|
+
this.menu = document.createElement('div');
|
|
72
|
+
this.menu.setAttribute('style', inlineStyle({
|
|
73
|
+
...menuStyle,
|
|
74
|
+
color: config.itemColor
|
|
75
|
+
}));
|
|
76
|
+
this.cells = config.itemList.map((item, index) => {
|
|
77
|
+
const cell = document.createElement('div');
|
|
78
|
+
cell.className = 'taro-actionsheet__cell';
|
|
79
|
+
cell.setAttribute('style', inlineStyle(cellStyle));
|
|
80
|
+
cell.textContent = item;
|
|
81
|
+
cell.dataset.tapIndex = `${index}`;
|
|
82
|
+
cell.onclick = e => {
|
|
83
|
+
this.hide();
|
|
84
|
+
const target = e.currentTarget;
|
|
85
|
+
const index = Number(target === null || target === void 0 ? void 0 : target.dataset.tapIndex) || 0;
|
|
86
|
+
resolve(index);
|
|
87
|
+
};
|
|
88
|
+
return cell;
|
|
89
|
+
});
|
|
90
|
+
this.cancel = document.createElement('div');
|
|
91
|
+
this.cancel.setAttribute('style', inlineStyle(cancelStyle));
|
|
92
|
+
this.cancel.textContent = '取消';
|
|
93
|
+
this.cells.forEach(item => this.menu.appendChild(item));
|
|
94
|
+
this.actionSheet.appendChild(this.menu);
|
|
95
|
+
this.actionSheet.appendChild(this.cancel);
|
|
96
|
+
this.el.appendChild(mask);
|
|
97
|
+
this.el.appendChild(this.actionSheet);
|
|
98
|
+
const cb = () => {
|
|
99
|
+
this.hide();
|
|
100
|
+
resolve('cancel');
|
|
101
|
+
};
|
|
102
|
+
mask.onclick = cb;
|
|
103
|
+
this.cancel.onclick = cb;
|
|
104
|
+
document.body.appendChild(this.el);
|
|
105
|
+
setTimeout(() => {
|
|
106
|
+
this.el.style.opacity = '1';
|
|
107
|
+
setTransform(this.actionSheet, 'translate(0, 0)');
|
|
108
|
+
}, 0);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
show(options = {}) {
|
|
112
|
+
return new Promise((resolve) => {
|
|
113
|
+
const config = {
|
|
114
|
+
...this.options,
|
|
115
|
+
...options
|
|
116
|
+
};
|
|
117
|
+
this.lastConfig = config;
|
|
118
|
+
if (this.hideOpacityTimer)
|
|
119
|
+
clearTimeout(this.hideOpacityTimer);
|
|
120
|
+
if (this.hideDisplayTimer)
|
|
121
|
+
clearTimeout(this.hideDisplayTimer);
|
|
122
|
+
if (config.itemColor)
|
|
123
|
+
this.menu.style.color = config.itemColor;
|
|
124
|
+
const { cellStyle } = this.style;
|
|
125
|
+
config.itemList.forEach((item, index) => {
|
|
126
|
+
let cell;
|
|
127
|
+
if (this.cells[index]) {
|
|
128
|
+
cell = this.cells[index];
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
cell = document.createElement('div');
|
|
132
|
+
cell.className = 'taro-actionsheet__cell';
|
|
133
|
+
cell.setAttribute('style', inlineStyle(cellStyle));
|
|
134
|
+
cell.dataset.tapIndex = `${index}`;
|
|
135
|
+
this.cells.push(cell);
|
|
136
|
+
this.menu.appendChild(cell);
|
|
137
|
+
}
|
|
138
|
+
cell.textContent = item;
|
|
139
|
+
cell.onclick = e => {
|
|
140
|
+
this.hide();
|
|
141
|
+
const target = e.currentTarget;
|
|
142
|
+
const index = Number(target === null || target === void 0 ? void 0 : target.dataset.tapIndex) || 0;
|
|
143
|
+
resolve(index);
|
|
144
|
+
};
|
|
145
|
+
});
|
|
146
|
+
const cellsLen = this.cells.length;
|
|
147
|
+
const itemListLen = config.itemList.length;
|
|
148
|
+
if (cellsLen > itemListLen) {
|
|
149
|
+
for (let i = itemListLen; i < cellsLen; i++) {
|
|
150
|
+
this.menu.removeChild(this.cells[i]);
|
|
151
|
+
}
|
|
152
|
+
this.cells.splice(itemListLen);
|
|
153
|
+
}
|
|
154
|
+
this.el.style.display = 'block';
|
|
155
|
+
setTimeout(() => {
|
|
156
|
+
this.el.style.opacity = '1';
|
|
157
|
+
setTransform(this.actionSheet, 'translate(0, 0)');
|
|
158
|
+
}, 0);
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
hide() {
|
|
162
|
+
if (this.hideOpacityTimer)
|
|
163
|
+
clearTimeout(this.hideOpacityTimer);
|
|
164
|
+
if (this.hideDisplayTimer)
|
|
165
|
+
clearTimeout(this.hideDisplayTimer);
|
|
166
|
+
this.hideOpacityTimer = setTimeout(() => {
|
|
167
|
+
this.el.style.opacity = '0';
|
|
168
|
+
setTransform(this.actionSheet, 'translate(0, 100%)');
|
|
169
|
+
this.hideDisplayTimer = setTimeout(() => { this.el.style.display = 'none'; }, 200);
|
|
170
|
+
}, 0);
|
|
171
|
+
}
|
|
172
|
+
}
|