@tarojs/taro-h5 3.3.17 → 3.3.18

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 (34) hide show
  1. package/dist/index.cjs.js +1081 -627
  2. package/dist/index.js +1077 -628
  3. package/dist/taroApis.js +1 -1
  4. package/package.json +6 -6
  5. package/src/api/base/system/index.ts +2 -2
  6. package/src/api/canvas/canvasGetImageData.ts +1 -3
  7. package/src/api/canvas/canvasPutImageData.ts +1 -3
  8. package/src/api/canvas/canvasToTempFilePath.ts +1 -3
  9. package/src/api/canvas/createCanvasContext.ts +1 -3
  10. package/src/api/canvas/index.ts +4 -4
  11. package/src/api/cloud/index.ts +1 -1
  12. package/src/api/device/accelerometer.ts +4 -6
  13. package/src/api/device/compass.ts +4 -11
  14. package/src/api/device/motion.ts +4 -11
  15. package/src/api/location/index.ts +1 -1
  16. package/src/api/media/audio/index.ts +12 -6
  17. package/src/api/media/image/chooseImage.ts +1 -3
  18. package/src/api/media/image/getImageInfo.ts +35 -0
  19. package/src/api/media/image/index.ts +3 -3
  20. package/src/api/media/image/previewImage.ts +101 -0
  21. package/src/api/network/download.ts +1 -3
  22. package/src/api/network/upload.ts +1 -3
  23. package/src/api/network/websocket/index.ts +12 -20
  24. package/src/api/network/websocket/socketTask.ts +1 -1
  25. package/src/api/storage/index.ts +58 -70
  26. package/src/api/ui/animation/index.ts +25 -21
  27. package/src/api/ui/interaction/index.ts +28 -24
  28. package/src/api/ui/pull-down-refresh.ts +2 -7
  29. package/src/api/ui/scroll/index.ts +8 -10
  30. package/src/api/utils/index.ts +17 -33
  31. package/src/api/wxml/nodesRef.ts +49 -0
  32. package/src/api/wxml/selectorQuery.ts +2 -48
  33. package/src/api/media/image/getImageInfo.js +0 -74
  34. package/src/api/media/image/previewImage.js +0 -98
@@ -2,8 +2,22 @@ import Taro from '@tarojs/api'
2
2
  import { shouldBeObject, getParameterError, temporarilyNotSupport } from '../utils'
3
3
  import { MethodHandler } from '../utils/handler'
4
4
 
5
+ function getItem (key) {
6
+ let item
7
+ try {
8
+ item = JSON.parse(localStorage.getItem(key) || '')
9
+ } catch (e) {}
10
+
11
+ // 只返回使用 Taro.setStorage API 存储的数据
12
+ if (item && typeof item === 'object' && item.hasOwnProperty('data')) {
13
+ return { result: true, data: item.data }
14
+ } else {
15
+ return { result: false }
16
+ }
17
+ }
18
+
5
19
  // 数据缓存
6
- const setStorageSync: typeof Taro.setStorageSync = (key, data = '') => {
20
+ export const setStorageSync: typeof Taro.setStorageSync = (key, data = '') => {
7
21
  if (typeof key !== 'string') {
8
22
  console.error(getParameterError({
9
23
  name: 'setStorage',
@@ -24,7 +38,7 @@ const setStorageSync: typeof Taro.setStorageSync = (key, data = '') => {
24
38
  localStorage.setItem(key, JSON.stringify(obj))
25
39
  }
26
40
 
27
- const setStorage: typeof Taro.setStorage = (options) => {
41
+ export const setStorage: typeof Taro.setStorage = (options) => {
28
42
  // options must be an Object
29
43
  const isObject = shouldBeObject(options)
30
44
  if (!isObject.flag) {
@@ -50,17 +64,31 @@ const setStorage: typeof Taro.setStorage = (options) => {
50
64
  return handle.success()
51
65
  }
52
66
 
53
- const getStorage: typeof Taro.getStorage = <T>(options) => {
67
+ export const revokeBufferURL = temporarilyNotSupport('revokeBufferURL')
68
+
69
+ export const removeStorageSync: typeof Taro.removeStorageSync = (key: string) => {
70
+ if (typeof key !== 'string') {
71
+ console.error(getParameterError({
72
+ name: 'removeStorage',
73
+ correct: 'String',
74
+ wrong: key
75
+ }))
76
+ return
77
+ }
78
+
79
+ localStorage.removeItem(key)
80
+ }
81
+
82
+ export const removeStorage: typeof Taro.removeStorage = (options: Taro.removeStorage.Option) => {
54
83
  // options must be an Object
55
84
  const isObject = shouldBeObject(options)
56
85
  if (!isObject.flag) {
57
- const res = { errMsg: `getStorage:fail ${isObject.msg}` }
86
+ const res = { errMsg: `removeStorage:fail ${isObject.msg}` }
58
87
  console.error(res.errMsg)
59
88
  return Promise.reject(res)
60
89
  }
61
-
62
90
  const { key, success, fail, complete } = options
63
- const handle = new MethodHandler<Taro.getStorage.SuccessCallbackResult<T>>({ name: 'getStorage', success, fail, complete })
91
+ const handle = new MethodHandler({ name: 'removeStorage', success, fail, complete })
64
92
 
65
93
  if (typeof key !== 'string') {
66
94
  return handle.fail({
@@ -72,17 +100,11 @@ const getStorage: typeof Taro.getStorage = <T>(options) => {
72
100
  })
73
101
  }
74
102
 
75
- const { result, data } = getItem(key)
76
- if (result) {
77
- return handle.success({ data })
78
- } else {
79
- return handle.fail({
80
- errMsg: 'data not found'
81
- })
82
- }
103
+ removeStorageSync(key)
104
+ return handle.success()
83
105
  }
84
106
 
85
- const getStorageSync: typeof Taro.getStorageSync = (key) => {
107
+ export const getStorageSync: typeof Taro.getStorageSync = (key) => {
86
108
  if (typeof key !== 'string') {
87
109
  console.error(getParameterError({
88
110
  name: 'getStorageSync',
@@ -98,21 +120,7 @@ const getStorageSync: typeof Taro.getStorageSync = (key) => {
98
120
  return ''
99
121
  }
100
122
 
101
- function getItem (key) {
102
- let item
103
- try {
104
- item = JSON.parse(localStorage.getItem(key) || '')
105
- } catch (e) {}
106
-
107
- // 只返回使用 Taro.setStorage API 存储的数据
108
- if (item && typeof item === 'object' && item.hasOwnProperty('data')) {
109
- return { result: true, data: item.data }
110
- } else {
111
- return { result: false }
112
- }
113
- }
114
-
115
- const getStorageInfoSync: typeof Taro.getStorageInfoSync = () => {
123
+ export const getStorageInfoSync: typeof Taro.getStorageInfoSync = () => {
116
124
  const res: Taro.getStorageInfoSync.Option = {
117
125
  keys: Object.keys(localStorage),
118
126
  limitSize: NaN,
@@ -121,34 +129,22 @@ const getStorageInfoSync: typeof Taro.getStorageInfoSync = () => {
121
129
  return res
122
130
  }
123
131
 
124
- const getStorageInfo: typeof Taro.getStorageInfo = ({ success, fail, complete } = {}) => {
132
+ export const getStorageInfo: typeof Taro.getStorageInfo = ({ success, fail, complete } = {}) => {
125
133
  const handle = new MethodHandler<Taro.getStorageInfo.SuccessCallbackOption>({ name: 'getStorageInfo', success, fail, complete })
126
134
  return handle.success(getStorageInfoSync())
127
135
  }
128
136
 
129
- const removeStorageSync: typeof Taro.removeStorageSync = (key: string) => {
130
- if (typeof key !== 'string') {
131
- console.error(getParameterError({
132
- name: 'removeStorage',
133
- correct: 'String',
134
- wrong: key
135
- }))
136
- return
137
- }
138
-
139
- localStorage.removeItem(key)
140
- }
141
-
142
- const removeStorage: typeof Taro.removeStorage = (options: Taro.removeStorage.Option) => {
137
+ export const getStorage: typeof Taro.getStorage = <T>(options) => {
143
138
  // options must be an Object
144
139
  const isObject = shouldBeObject(options)
145
140
  if (!isObject.flag) {
146
- const res = { errMsg: `removeStorage:fail ${isObject.msg}` }
141
+ const res = { errMsg: `getStorage:fail ${isObject.msg}` }
147
142
  console.error(res.errMsg)
148
143
  return Promise.reject(res)
149
144
  }
145
+
150
146
  const { key, success, fail, complete } = options
151
- const handle = new MethodHandler({ name: 'removeStorage', success, fail, complete })
147
+ const handle = new MethodHandler<Taro.getStorage.SuccessCallbackResult<T>>({ name: 'getStorage', success, fail, complete })
152
148
 
153
149
  if (typeof key !== 'string') {
154
150
  return handle.fail({
@@ -160,34 +156,26 @@ const removeStorage: typeof Taro.removeStorage = (options: Taro.removeStorage.Op
160
156
  })
161
157
  }
162
158
 
163
- removeStorageSync(key)
164
- return handle.success()
159
+ const { result, data } = getItem(key)
160
+ if (result) {
161
+ return handle.success({ data })
162
+ } else {
163
+ return handle.fail({
164
+ errMsg: 'data not found'
165
+ })
166
+ }
165
167
  }
166
168
 
167
- const clearStorage: typeof Taro.clearStorage = ({ success, fail, complete } = {}) => {
168
- const handle = new MethodHandler({ name: 'clearStorage', success, fail, complete })
169
- localStorage.clear()
170
- return handle.success()
171
- }
169
+ export const createBufferURL = temporarilyNotSupport('createBufferURL')
172
170
 
173
- const clearStorageSync: typeof Taro.clearStorageSync = () => {
174
- clearStorage()
171
+ export const clearStorageSync: typeof Taro.clearStorageSync = () => {
172
+ localStorage.clear()
175
173
  }
176
174
 
177
- const revokeBufferURL = temporarilyNotSupport('revokeBufferURL')
178
-
179
- export {
180
- setStorageSync,
181
- setStorage,
182
- revokeBufferURL,
183
- removeStorageSync,
184
- removeStorage,
185
- getStorageSync,
186
- getStorageInfoSync,
187
- getStorageInfo,
188
- getStorage,
189
- clearStorageSync,
190
- clearStorage
175
+ export const clearStorage: typeof Taro.clearStorage = ({ success, fail, complete } = {}) => {
176
+ const handle = new MethodHandler({ name: 'clearStorage', success, fail, complete })
177
+ clearStorageSync()
178
+ return handle.success()
191
179
  }
192
180
 
193
181
  export * from './background-fetch'
@@ -1,3 +1,5 @@
1
+ import Taro from '@tarojs/api'
2
+
1
3
  /**
2
4
  * H5 下的 styleSheet 操作
3
5
  * @author leeenx
@@ -48,15 +50,15 @@ 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
 
@@ -69,8 +71,7 @@ interface IAnimationAttr {
69
71
  transformOrigin: string
70
72
  }
71
73
 
72
- // Animation
73
- class Animation {
74
+ class Animation implements Taro.Animation {
74
75
  unit: string
75
76
  id: number
76
77
  DEFAULT: IAnimationAttr
@@ -82,7 +83,7 @@ class Animation {
82
83
  timingFunction = 'linear',
83
84
  transformOrigin = '50% 50% 0',
84
85
  unit = 'px'
85
- } = {}
86
+ }: Taro.createAnimation.Option = {}
86
87
  ) {
87
88
  // 默认值
88
89
  this.setDefault(duration, delay, timingFunction, transformOrigin)
@@ -108,7 +109,7 @@ class Animation {
108
109
  const animStepsCount = this.animationMap[`${animName}__${animIndex}`]
109
110
  const animStepsMaxIndex = animStepsCount - 1
110
111
  if (stepIndex < animStepsMaxIndex) {
111
- // 播放下一个关键帧(因为 nevr 和 react 有差异所以 animation & data-animation 都需要写)
112
+ // 播放下一个关键帧(因为 nerv 和 react 有差异所以 animation & data-animation 都需要写)
112
113
  target.setAttribute(animAttr, `${animName}__${animIndex}--${stepIndex + 1}`)
113
114
  if (animAttr === 'animation') {
114
115
  // Nerv 环境,animation & data-animation 双重保险
@@ -142,23 +143,28 @@ class Animation {
142
143
  animationMap = {}
143
144
  // animationMap 的长度
144
145
  animationMapCount = 0
145
- matrix (a, b, c, d, e, f) {
146
- 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})`)
147
149
  return this
148
150
  }
149
151
 
150
- 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) {
151
153
  this.transform.push(`matrix3d(${a1}, ${b1}, ${c1}, ${d1}, ${a2}, ${b2}, ${c2}, ${d2}, ${a3}, ${b3}, ${c3}, ${d3}, ${a4}, ${b4}, ${c4}, ${d4})`)
152
154
  return this
153
155
  }
154
156
 
155
- rotate (angle) {
157
+ rotate (angle: number) {
156
158
  this.transform.push(`rotate(${angle}deg)`)
157
159
  return this
158
160
  }
159
161
 
160
- rotate3d (x, y, z, angle) {
161
- 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
+ }
162
168
  return this
163
169
  }
164
170
 
@@ -318,7 +324,7 @@ class Animation {
318
324
  // 清空 rules 和 transform
319
325
  this.rules = []
320
326
  this.transform = [`${TRANSFORM}:`]
321
- return this
327
+ return this as Taro.Animation
322
328
  }
323
329
 
324
330
  // 创建底层数据
@@ -341,13 +347,11 @@ class Animation {
341
347
 
342
348
  // 动画数据产出
343
349
  export () {
344
- return this.createAnimationData()
350
+ return this.createAnimationData() as unknown as ReturnType<Taro.Animation['export']>
345
351
  }
346
352
  }
347
353
 
348
354
  // h5 的 createAnimation
349
- function createAnimation (...arg) {
350
- return new Animation(...arg)
355
+ export const createAnimation: typeof Taro.createAnimation = (option) => {
356
+ return new Animation(option)
351
357
  }
352
-
353
- export { createAnimation }
@@ -24,14 +24,15 @@ const toast = new Toast()
24
24
  const modal = new Modal()
25
25
  const actionSheet = new ActionSheet()
26
26
 
27
- const showToast: typeof Taro.showToast = (options = {
28
- title: '',
29
- icon: 'success',
30
- image: '',
31
- duration: 1500,
32
- mask: false
33
- }) => {
27
+ const showToast: typeof Taro.showToast = (options = { title: '' }) => {
34
28
  init(document)
29
+ options = Object.assign({
30
+ title: '',
31
+ icon: 'success',
32
+ image: '',
33
+ duration: 1500,
34
+ mask: false
35
+ }, options)
35
36
  const { success, fail, complete } = options
36
37
  const handle = new MethodHandler({ name: 'showToast', success, fail, complete })
37
38
 
@@ -75,11 +76,12 @@ const hideToast: typeof Taro.hideToast = ({ success, fail, complete } = {}) => {
75
76
  return handle.success()
76
77
  }
77
78
 
78
- const showLoading: typeof Taro.showLoading = (options = {
79
- title: '',
80
- mask: false
81
- }) => {
79
+ const showLoading: typeof Taro.showLoading = (options = { title: '' }) => {
82
80
  init(document)
81
+ options = Object.assign({
82
+ title: '',
83
+ mask: false
84
+ }, options)
83
85
  const { success, fail, complete } = options
84
86
  const handle = new MethodHandler({ name: 'showLoading', success, fail, complete })
85
87
 
@@ -119,16 +121,17 @@ const hideLoading: typeof Taro.hideLoading = ({ success, fail, complete } = {})
119
121
  return handle.success()
120
122
  }
121
123
 
122
- const showModal: typeof Taro.showModal = async (options = {
123
- title: '',
124
- content: '',
125
- showCancel: true,
126
- cancelText: '取消',
127
- cancelColor: '#000000',
128
- confirmText: '确定',
129
- confirmColor: '#3CC51F'
130
- }) => {
124
+ const showModal: typeof Taro.showModal = async (options = {}) => {
131
125
  init(document)
126
+ options = Object.assign({
127
+ title: '',
128
+ content: '',
129
+ showCancel: true,
130
+ cancelText: '取消',
131
+ cancelColor: '#000000',
132
+ confirmText: '确定',
133
+ confirmColor: '#3CC51F'
134
+ }, options)
132
135
  const { success, fail, complete } = options
133
136
  const handle = new MethodHandler({ name: 'showModal', success, fail, complete })
134
137
 
@@ -220,11 +223,12 @@ function hideModal () {
220
223
  modal.hide()
221
224
  }
222
225
 
223
- const showActionSheet: typeof Taro.showActionSheet = async (options = {
224
- itemColor: '#000000',
225
- itemList: []
226
- }) => {
226
+ const showActionSheet: typeof Taro.showActionSheet = async (options = { itemList: [] }) => {
227
227
  init(document)
228
+ options = Object.assign({
229
+ itemColor: '#000000',
230
+ itemList: []
231
+ }, options)
228
232
  const { success, fail, complete } = options
229
233
  const handle = new MethodHandler<Taro.showActionSheet.SuccessCallbackResult>({ name: 'showActionSheet', success, fail, complete })
230
234
 
@@ -3,7 +3,7 @@ import { MethodHandler } from '../utils/handler'
3
3
  /**
4
4
  * 开始下拉刷新。调用后触发下拉刷新动画,效果与用户手动下拉刷新一致。
5
5
  */
6
- const startPullDownRefresh: typeof Taro.startPullDownRefresh = function ({ success, fail, complete } = {}) {
6
+ export const startPullDownRefresh: typeof Taro.startPullDownRefresh = function ({ success, fail, complete } = {}) {
7
7
  const handle = new MethodHandler({ name: 'startPullDownRefresh', success, fail, complete })
8
8
  return new Promise((resolve, reject) => {
9
9
  Taro.eventCenter.trigger('__taroStartPullDownRefresh', {
@@ -16,7 +16,7 @@ const startPullDownRefresh: typeof Taro.startPullDownRefresh = function ({ succe
16
16
  /**
17
17
  * 停止当前页面下拉刷新。
18
18
  */
19
- const stopPullDownRefresh: typeof Taro.stopPullDownRefresh = function ({ success, fail, complete } = {}) {
19
+ export const stopPullDownRefresh: typeof Taro.stopPullDownRefresh = function ({ success, fail, complete } = {}) {
20
20
  const handle = new MethodHandler({ name: 'stopPullDownRefresh', success, fail, complete })
21
21
  return new Promise((resolve, reject) => {
22
22
  Taro.eventCenter.trigger('__taroStopPullDownRefresh', {
@@ -25,8 +25,3 @@ const stopPullDownRefresh: typeof Taro.stopPullDownRefresh = function ({ success
25
25
  })
26
26
  })
27
27
  }
28
-
29
- export {
30
- startPullDownRefresh,
31
- stopPullDownRefresh
32
- }
@@ -1,9 +1,9 @@
1
1
  import Taro from '@tarojs/api'
2
+ import { Current } from '@tarojs/runtime'
2
3
 
3
4
  import { MethodHandler } from '../../utils/handler'
4
5
  import { getTimingFunc, easeInOut } from '../../utils'
5
6
 
6
- let scrollFunc
7
7
  let timer: NodeJS.Timeout
8
8
  const FRAME_DURATION = 17
9
9
 
@@ -11,6 +11,7 @@ const FRAME_DURATION = 17
11
11
  * 将页面滚动到目标位置
12
12
  */
13
13
  export const pageScrollTo: typeof Taro.pageScrollTo = ({ scrollTop, selector = '', duration = 300, success, fail, complete }) => {
14
+ let scrollFunc
14
15
  const handle = new MethodHandler({ name: 'pageScrollTo', success, fail, complete })
15
16
  return new Promise((resolve, reject) => {
16
17
  try {
@@ -20,17 +21,14 @@ export const pageScrollTo: typeof Taro.pageScrollTo = ({ scrollTop, selector = '
20
21
  }, reject)
21
22
  }
22
23
 
23
- let el
24
- if (document.querySelector('.taro-tabbar__tabbar') === null) {
25
- // 没设置tabbar
26
- el = window
27
- } else {
28
- // 有设置tabbar
29
- el = document.querySelector('.taro-tabbar__panel') || window
30
- }
24
+ const id = Current.page?.path
25
+ const el: HTMLDivElement | null = (id
26
+ ? document.getElementById(id)
27
+ : document.querySelector('.taro_page') ||
28
+ document.querySelector('.taro_router')) as HTMLDivElement
31
29
 
32
30
  if (!scrollFunc) {
33
- if (el === window) {
31
+ if (!el) {
34
32
  scrollFunc = pos => {
35
33
  if (pos === undefined) {
36
34
  return window.pageYOffset
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable prefer-promise-reject-errors */
2
2
  import { Current, container, SERVICE_IDENTIFIER, IHooks, TaroElement } from '@tarojs/runtime'
3
3
 
4
- function shouldBeObject (target: unknown) {
4
+ export function shouldBeObject (target: unknown) {
5
5
  if (target && typeof target === 'object') return { flag: true }
6
6
  return {
7
7
  flag: false,
@@ -43,7 +43,7 @@ interface IParameterErrorParam {
43
43
  correct?: string
44
44
  wrong?: unknown
45
45
  }
46
- function getParameterError ({ name = '', para, correct, wrong }: IParameterErrorParam) {
46
+ export function getParameterError ({ name = '', para, correct, wrong }: IParameterErrorParam) {
47
47
  const parameter = para ? `parameter.${para}` : 'parameter'
48
48
  const errorType = upperCaseFirstLetter(wrong === null ? 'Null' : typeof wrong)
49
49
  if (name) {
@@ -59,7 +59,7 @@ function upperCaseFirstLetter (string) {
59
59
  return string
60
60
  }
61
61
 
62
- function inlineStyle (style) {
62
+ export function inlineStyle (style) {
63
63
  let res = ''
64
64
  for (const attr in style) res += `${attr}: ${style[attr]};`
65
65
  if (res.indexOf('display: flex;') >= 0) res += 'display: -webkit-box;display: -webkit-flex;'
@@ -68,16 +68,12 @@ function inlineStyle (style) {
68
68
  return res
69
69
  }
70
70
 
71
- function setTransform (el, val) {
71
+ export function setTransform (el, val) {
72
72
  el.style.webkitTransform = val
73
73
  el.style.transform = val
74
74
  }
75
75
 
76
- function isFunction (obj) {
77
- return typeof obj === 'function'
78
- }
79
-
80
- function serializeParams (params) {
76
+ export function serializeParams (params) {
81
77
  if (!params) {
82
78
  return ''
83
79
  }
@@ -89,7 +85,7 @@ function serializeParams (params) {
89
85
  .join('&')
90
86
  }
91
87
 
92
- function temporarilyNotSupport (apiName) {
88
+ export function temporarilyNotSupport (apiName) {
93
89
  return () => {
94
90
  const errMsg = `暂时不支持 API ${apiName}`
95
91
  console.error(errMsg)
@@ -99,7 +95,7 @@ function temporarilyNotSupport (apiName) {
99
95
  }
100
96
  }
101
97
 
102
- function weixinCorpSupport (apiName) {
98
+ export function weixinCorpSupport (apiName) {
103
99
  return () => {
104
100
  const errMsg = `h5端仅在微信公众号中支持 API ${apiName}`
105
101
  console.error(errMsg)
@@ -109,7 +105,7 @@ function weixinCorpSupport (apiName) {
109
105
  }
110
106
  }
111
107
 
112
- function permanentlyNotSupport (apiName) {
108
+ export function permanentlyNotSupport (apiName) {
113
109
  return () => {
114
110
  const errMsg = `不支持 API ${apiName}`
115
111
  console.error(errMsg)
@@ -119,13 +115,17 @@ function permanentlyNotSupport (apiName) {
119
115
  }
120
116
  }
121
117
 
118
+ export function isFunction (obj) {
119
+ return typeof obj === 'function'
120
+ }
121
+
122
122
  const VALID_COLOR_REG = /^#[0-9a-fA-F]{6}$/
123
123
 
124
- const isValidColor = (color) => {
124
+ export const isValidColor = (color) => {
125
125
  return VALID_COLOR_REG.test(color)
126
126
  }
127
127
 
128
- function processOpenApi (apiName: string, defaultOptions?: Record<string, unknown>, formatResult = res => res, formatParams = options => options) {
128
+ export function processOpenApi (apiName: string, defaultOptions?: Record<string, unknown>, formatResult = res => res, formatParams = options => options) {
129
129
  // @ts-ignore
130
130
  if (!window.wx) {
131
131
  return weixinCorpSupport(apiName)
@@ -154,11 +154,11 @@ function processOpenApi (apiName: string, defaultOptions?: Record<string, unknow
154
154
 
155
155
  /**
156
156
  * ease-in-out的函数
157
- * @param {number} t 0-1的数字
157
+ * @param t 0-1的数字
158
158
  */
159
- const easeInOut = t => t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1
159
+ export const easeInOut = (t: number) => t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1
160
160
 
161
- const getTimingFunc = (easeFunc, frameCnt) => {
161
+ export const getTimingFunc = (easeFunc, frameCnt) => {
162
162
  return x => {
163
163
  if (frameCnt <= 1) {
164
164
  return easeFunc(1)
@@ -167,19 +167,3 @@ const getTimingFunc = (easeFunc, frameCnt) => {
167
167
  return easeFunc(t)
168
168
  }
169
169
  }
170
-
171
- export {
172
- shouldBeObject,
173
- getParameterError,
174
- inlineStyle,
175
- setTransform,
176
- serializeParams,
177
- temporarilyNotSupport,
178
- weixinCorpSupport,
179
- permanentlyNotSupport,
180
- isValidColor,
181
- isFunction,
182
- processOpenApi,
183
- easeInOut,
184
- getTimingFunc
185
- }
@@ -0,0 +1,49 @@
1
+ import { temporarilyNotSupport } from '../utils'
2
+ import { SelectorQuery } from './selectorQuery'
3
+
4
+ export class NodesRef implements Taro.NodesRef {
5
+ _component?: TaroGeneral.IAnyObject
6
+ _selector: string
7
+ _selectorQuery: SelectorQuery
8
+ _single: boolean
9
+
10
+ constructor (selector: string, querySelectorQuery: SelectorQuery, single: boolean) {
11
+ this._component = querySelectorQuery._component
12
+ this._selector = selector
13
+ this._selectorQuery = querySelectorQuery
14
+ this._single = single
15
+ }
16
+
17
+ context = temporarilyNotSupport('NodesRef.context') as unknown as Taro.NodesRef['context']
18
+
19
+ node = temporarilyNotSupport('NodesRef.node') as unknown as Taro.NodesRef['node']
20
+
21
+ boundingClientRect (cb) {
22
+ const { _selector, _component, _single, _selectorQuery } = this
23
+ _selectorQuery._push(_selector, _component, _single, { id: !0, dataset: !0, rect: !0, size: !0 }, cb)
24
+ return _selectorQuery
25
+ }
26
+
27
+ scrollOffset (cb) {
28
+ const { _selector, _component, _single, _selectorQuery } = this
29
+ _selectorQuery._push(_selector, _component, _single, { id: !0, dataset: !0, scrollOffset: !0 }, cb)
30
+ return _selectorQuery
31
+ }
32
+
33
+ fields (fields, cb) {
34
+ const { _selector, _component, _single, _selectorQuery } = this
35
+ const { id, dataset, rect, size, scrollOffset, properties = [], computedStyle = [] } = fields
36
+
37
+ _selectorQuery._push(_selector, _component, _single, {
38
+ id,
39
+ dataset,
40
+ rect,
41
+ size,
42
+ scrollOffset,
43
+ properties,
44
+ computedStyle
45
+ }, cb)
46
+
47
+ return _selectorQuery
48
+ }
49
+ }