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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/api/base/system.js +28 -24
  2. package/dist/api/canvas/CanvasContext.js +27 -16
  3. package/dist/api/device/accelerometer.js +9 -17
  4. package/dist/api/device/battery.js +12 -3
  5. package/dist/api/device/clipboard.js +13 -4
  6. package/dist/api/device/compass.js +32 -18
  7. package/dist/api/device/motion.js +8 -17
  8. package/dist/api/device/network.js +12 -3
  9. package/dist/api/location/chooseLocation.js +13 -8
  10. package/dist/api/media/image/previewImage.js +12 -3
  11. package/dist/api/taro.js +2 -3
  12. package/dist/api/ui/fonts.js +12 -3
  13. package/dist/api/ui/interaction/actionSheet.js +3 -12
  14. package/dist/api/ui/interaction/index.js +17 -8
  15. package/dist/api/ui/interaction/modal.js +6 -27
  16. package/dist/api/ui/interaction/toast.js +14 -40
  17. package/dist/api/utils/animation.js +14 -0
  18. package/dist/api/utils/index.js +3 -21
  19. package/dist/api/utils/lodash.js +29 -0
  20. package/dist/api/utils/valid.js +7 -0
  21. package/dist/dist/api/taro.d.ts +2 -2
  22. package/dist/dist/api/utils/animation.d.ts +6 -0
  23. package/dist/dist/api/utils/index.d.ts +3 -9
  24. package/dist/dist/api/utils/lodash.d.ts +2 -0
  25. package/dist/dist/api/utils/valid.d.ts +2 -0
  26. package/dist/index.cjs.js +424 -229
  27. package/dist/index.cjs.js.map +1 -1
  28. package/package.json +11 -12
  29. package/src/api/device/accelerometer.ts +8 -17
  30. package/src/api/device/compass.ts +34 -18
  31. package/src/api/device/motion.ts +9 -17
  32. package/src/api/taro.ts +2 -7
  33. package/src/api/ui/scroll/index.ts +1 -1
  34. package/src/api/utils/animation.ts +15 -0
  35. package/src/api/utils/index.ts +3 -25
  36. package/src/api/utils/lodash.ts +30 -0
  37. package/src/api/utils/valid.ts +8 -0
@@ -64,10 +64,7 @@ export default class Modal {
64
64
  // style
65
65
  const { maskStyle, modalStyle, titleStyle, textStyle, footStyle, btnStyle } = this.style;
66
66
  // configuration
67
- const config = {
68
- ...this.options,
69
- ...options
70
- };
67
+ const config = Object.assign(Object.assign({}, this.options), options);
71
68
  // wrapper
72
69
  this.el = document.createElement('div');
73
70
  this.el.className = 'taro__modal';
@@ -82,20 +79,13 @@ export default class Modal {
82
79
  modal.className = 'taro-modal__content';
83
80
  modal.setAttribute('style', inlineStyle(modalStyle));
84
81
  // title
85
- const titleCSS = config.title ? titleStyle : {
86
- ...titleStyle,
87
- display: 'none'
88
- };
82
+ const titleCSS = config.title ? titleStyle : Object.assign(Object.assign({}, titleStyle), { display: 'none' });
89
83
  this.title = document.createElement('div');
90
84
  this.title.className = 'taro-modal__title';
91
85
  this.title.setAttribute('style', inlineStyle(titleCSS));
92
86
  this.title.textContent = config.title;
93
87
  // text
94
- const textCSS = config.title ? textStyle : {
95
- ...textStyle,
96
- padding: '40px 20px 26px',
97
- color: '#353535'
98
- };
88
+ const textCSS = config.title ? textStyle : Object.assign(Object.assign({}, textStyle), { padding: '40px 20px 26px', color: '#353535' });
99
89
  this.text = document.createElement('div');
100
90
  this.text.className = 'taro-modal__text';
101
91
  this.text.setAttribute('style', inlineStyle(textCSS));
@@ -105,11 +95,7 @@ export default class Modal {
105
95
  foot.className = 'taro-modal__foot';
106
96
  foot.setAttribute('style', inlineStyle(footStyle));
107
97
  // cancel button
108
- const cancelCSS = {
109
- ...btnStyle,
110
- color: config.cancelColor,
111
- display: config.showCancel ? 'block' : 'none'
112
- };
98
+ const cancelCSS = Object.assign(Object.assign({}, btnStyle), { color: config.cancelColor, display: config.showCancel ? 'block' : 'none' });
113
99
  this.cancel = document.createElement('div');
114
100
  this.cancel.className = 'taro-model__btn taro-model__cancel';
115
101
  this.cancel.setAttribute('style', inlineStyle(cancelCSS));
@@ -143,10 +129,7 @@ export default class Modal {
143
129
  }
144
130
  show(options = {}) {
145
131
  return new Promise((resolve) => {
146
- const config = {
147
- ...this.options,
148
- ...options
149
- };
132
+ const config = Object.assign(Object.assign({}, this.options), options);
150
133
  if (this.hideOpacityTimer)
151
134
  clearTimeout(this.hideOpacityTimer);
152
135
  if (this.hideDisplayTimer)
@@ -162,11 +145,7 @@ export default class Modal {
162
145
  else {
163
146
  // block => none
164
147
  this.title.style.display = 'none';
165
- const textCSS = {
166
- ...textStyle,
167
- padding: '40px 20px 26px',
168
- color: '#353535'
169
- };
148
+ const textCSS = Object.assign(Object.assign({}, textStyle), { padding: '40px 20px 26px', color: '#353535' });
170
149
  this.text.setAttribute('style', inlineStyle(textCSS));
171
150
  }
172
151
  this.text.textContent = config.content || '';
@@ -78,11 +78,7 @@ export default class Toast {
78
78
  // style
79
79
  const { maskStyle, toastStyle, successStyle, errrorStyle, loadingStyle, imageStyle, textStyle } = this.style;
80
80
  // configuration
81
- const config = {
82
- ...this.options,
83
- ...options,
84
- _type
85
- };
81
+ const config = Object.assign(Object.assign(Object.assign({}, this.options), options), { _type });
86
82
  // wrapper
87
83
  this.el = document.createElement('div');
88
84
  this.el.className = 'taro__toast';
@@ -95,27 +91,18 @@ export default class Toast {
95
91
  // icon
96
92
  this.icon = document.createElement('p');
97
93
  if (config.image) {
98
- this.icon.setAttribute('style', inlineStyle({
99
- ...imageStyle,
100
- 'background-image': `url(${config.image})`
101
- }));
94
+ this.icon.setAttribute('style', inlineStyle(Object.assign(Object.assign({}, imageStyle), { 'background-image': `url(${config.image})` })));
102
95
  }
103
96
  else {
104
97
  const iconStyle = config.icon === 'loading' ? loadingStyle : config.icon === 'error' ? errrorStyle : successStyle;
105
- this.icon.setAttribute('style', inlineStyle({
106
- ...iconStyle,
107
- ...(config.icon === 'none' ? { display: 'none' } : {})
108
- }));
98
+ this.icon.setAttribute('style', inlineStyle(Object.assign(Object.assign({}, iconStyle), (config.icon === 'none' ? { display: 'none' } : {}))));
109
99
  }
110
100
  // toast
111
101
  this.toast = document.createElement('div');
112
- this.toast.setAttribute('style', inlineStyle({
113
- ...toastStyle,
114
- ...(config.icon === 'none' ? {
115
- 'min-height': '0',
116
- padding: '10px 15px'
117
- } : {})
118
- }));
102
+ this.toast.setAttribute('style', inlineStyle(Object.assign(Object.assign({}, toastStyle), (config.icon === 'none' ? {
103
+ 'min-height': '0',
104
+ padding: '10px 15px'
105
+ } : {}))));
119
106
  // title
120
107
  this.title = document.createElement('p');
121
108
  this.title.setAttribute('style', inlineStyle(textStyle));
@@ -134,11 +121,7 @@ export default class Toast {
134
121
  return '';
135
122
  }
136
123
  show(options = {}, _type = 'toast') {
137
- const config = {
138
- ...this.options,
139
- ...options,
140
- _type
141
- };
124
+ const config = Object.assign(Object.assign(Object.assign({}, this.options), options), { _type });
142
125
  if (this.hideOpacityTimer)
143
126
  clearTimeout(this.hideOpacityTimer);
144
127
  if (this.hideDisplayTimer)
@@ -150,28 +133,19 @@ export default class Toast {
150
133
  // image
151
134
  const { toastStyle, successStyle, errrorStyle, loadingStyle, imageStyle } = this.style;
152
135
  if (config.image) {
153
- this.icon.setAttribute('style', inlineStyle({
154
- ...imageStyle,
155
- 'background-image': `url(${config.image})`
156
- }));
136
+ this.icon.setAttribute('style', inlineStyle(Object.assign(Object.assign({}, imageStyle), { 'background-image': `url(${config.image})` })));
157
137
  }
158
138
  else {
159
139
  if (!config.image && config.icon) {
160
140
  const iconStyle = config.icon === 'loading' ? loadingStyle : config.icon === 'error' ? errrorStyle : successStyle;
161
- this.icon.setAttribute('style', inlineStyle({
162
- ...iconStyle,
163
- ...(config.icon === 'none' ? { display: 'none' } : {})
164
- }));
141
+ this.icon.setAttribute('style', inlineStyle(Object.assign(Object.assign({}, iconStyle), (config.icon === 'none' ? { display: 'none' } : {}))));
165
142
  }
166
143
  }
167
144
  // toast
168
- this.toast.setAttribute('style', inlineStyle({
169
- ...toastStyle,
170
- ...(config.icon === 'none' ? {
171
- 'min-height': '0',
172
- padding: '10px 15px'
173
- } : {})
174
- }));
145
+ this.toast.setAttribute('style', inlineStyle(Object.assign(Object.assign({}, toastStyle), (config.icon === 'none' ? {
146
+ 'min-height': '0',
147
+ padding: '10px 15px'
148
+ } : {}))));
175
149
  // show
176
150
  this.el.style.display = 'block';
177
151
  setTimeout(() => { this.el.style.opacity = '1'; }, 0);
@@ -0,0 +1,14 @@
1
+ /**
2
+ * ease-in-out的函数
3
+ * @param t 0-1的数字
4
+ */
5
+ export const easeInOut = (t) => (t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1);
6
+ export const getTimingFunc = (easeFunc, frameCnt) => {
7
+ return x => {
8
+ if (frameCnt <= 1) {
9
+ return easeFunc(1);
10
+ }
11
+ const t = x / (frameCnt - 1);
12
+ return easeFunc(t);
13
+ };
14
+ };
@@ -122,13 +122,6 @@ export function permanentlyNotSupport(apiName) {
122
122
  }
123
123
  };
124
124
  }
125
- export function isFunction(obj) {
126
- return typeof obj === 'function';
127
- }
128
- const VALID_COLOR_REG = /^#[0-9a-fA-F]{6}$/;
129
- export const isValidColor = (color) => {
130
- return VALID_COLOR_REG.test(color);
131
- };
132
125
  export function processOpenApi({ name, defaultOptions, standardMethod, formatOptions = options => options, formatResult = res => res }) {
133
126
  const notSupported = weixinCorpSupport(name);
134
127
  return (options = {}) => {
@@ -161,17 +154,6 @@ export function processOpenApi({ name, defaultOptions, standardMethod, formatOpt
161
154
  }
162
155
  };
163
156
  }
164
- /**
165
- * ease-in-out的函数
166
- * @param t 0-1的数字
167
- */
168
- export const easeInOut = (t) => t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1;
169
- export const getTimingFunc = (easeFunc, frameCnt) => {
170
- return x => {
171
- if (frameCnt <= 1) {
172
- return easeFunc(1);
173
- }
174
- const t = x / (frameCnt - 1);
175
- return easeFunc(t);
176
- };
177
- };
157
+ export * from './animation';
158
+ export * from './lodash';
159
+ export * from './valid';
@@ -0,0 +1,29 @@
1
+ export function throttle(fn, threshold = 250, scope) {
2
+ let lastTime = 0;
3
+ let deferTimer;
4
+ return function (...args) {
5
+ const context = scope || this;
6
+ const now = Date.now();
7
+ if (now - lastTime > threshold) {
8
+ fn.apply(this, args);
9
+ lastTime = now;
10
+ }
11
+ else {
12
+ clearTimeout(deferTimer);
13
+ deferTimer = setTimeout(() => {
14
+ lastTime = now;
15
+ fn.apply(context, args);
16
+ }, threshold);
17
+ }
18
+ };
19
+ }
20
+ export function debounce(fn, ms = 250, scope) {
21
+ let timer;
22
+ return function (...args) {
23
+ const context = scope || this;
24
+ clearTimeout(timer);
25
+ timer = setTimeout(function () {
26
+ fn.apply(context, args);
27
+ }, ms);
28
+ };
29
+ }
@@ -0,0 +1,7 @@
1
+ export function isFunction(obj) {
2
+ return typeof obj === 'function';
3
+ }
4
+ const VALID_COLOR_REG = /^#[0-9a-fA-F]{6}$/;
5
+ export const isValidColor = (color) => {
6
+ return VALID_COLOR_REG.test(color);
7
+ };
@@ -1,5 +1,5 @@
1
1
  import Taro from '@tarojs/api';
2
- import { history, createRouter } from '@tarojs/router';
2
+ import { history } from '@tarojs/router';
3
3
  declare const Behavior: any, getEnv: any, ENV_TYPE: any, Link: any, interceptors: any, Current: any, options: any, eventCenter: any, Events: any, preload: any;
4
4
  declare const taro: typeof Taro;
5
5
  declare const initPxTransform: any;
@@ -9,4 +9,4 @@ declare const requirePlugin: () => Promise<{
9
9
  declare const pxTransform: (size: any) => string;
10
10
  declare const canIUseWebp: () => boolean;
11
11
  export default taro;
12
- export { Behavior, getEnv, ENV_TYPE, Link, interceptors, initPxTransform, Current, options, eventCenter, Events, preload, requirePlugin, pxTransform, canIUseWebp, history, createRouter };
12
+ export { Behavior, getEnv, ENV_TYPE, Link, interceptors, initPxTransform, Current, options, eventCenter, Events, preload, requirePlugin, pxTransform, canIUseWebp, history };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * ease-in-out的函数
3
+ * @param t 0-1的数字
4
+ */
5
+ export declare const easeInOut: (t: number) => number;
6
+ export declare const getTimingFunc: (easeFunc: any, frameCnt: any) => (x: any) => any;
@@ -26,8 +26,6 @@ export declare function weixinCorpSupport(apiName: any): () => Promise<{
26
26
  export declare function permanentlyNotSupport(apiName: any): () => Promise<{
27
27
  errMsg: string;
28
28
  }>;
29
- export declare function isFunction(obj: any): boolean;
30
- export declare const isValidColor: (color: any) => boolean;
31
29
  interface IProcessOpenApi<TOptions = Record<string, unknown>, TResult extends TaroGeneral.CallbackResult = any> {
32
30
  name: string;
33
31
  defaultOptions?: TOptions;
@@ -36,10 +34,6 @@ interface IProcessOpenApi<TOptions = Record<string, unknown>, TResult extends Ta
36
34
  formatResult?: (res: TResult) => TResult;
37
35
  }
38
36
  export declare function processOpenApi<TOptions = Record<string, unknown>, TResult extends TaroGeneral.CallbackResult = any>({ name, defaultOptions, standardMethod, formatOptions, formatResult }: IProcessOpenApi<TOptions, TResult>): (options?: Partial<TOptions>) => Promise<TResult>;
39
- /**
40
- * ease-in-out的函数
41
- * @param t 0-1的数字
42
- */
43
- export declare const easeInOut: (t: number) => number;
44
- export declare const getTimingFunc: (easeFunc: any, frameCnt: any) => (x: any) => any;
45
- export {};
37
+ export * from './animation';
38
+ export * from './lodash';
39
+ export * from './valid';
@@ -0,0 +1,2 @@
1
+ export declare function throttle(fn: any, threshold?: number, scope?: any): (...args: any[]) => void;
2
+ export declare function debounce(fn: any, ms?: number, scope?: any): (...args: any[]) => void;
@@ -0,0 +1,2 @@
1
+ export declare function isFunction(obj: any): boolean;
2
+ export declare const isValidColor: (color: any) => boolean;