@tarojs/taro-h5 3.4.0-beta.1 → 3.4.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 (158) 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 +3 -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/index.js +2 -0
  11. package/dist/api/base/system/info.js +57 -0
  12. package/dist/api/base/system/network.js +63 -0
  13. package/dist/api/base/update.js +4 -0
  14. package/dist/api/base/weapp/app-event.js +18 -0
  15. package/dist/api/base/weapp/life-cycle.js +4 -0
  16. package/dist/api/canvas/CanvasContext.js +191 -0
  17. package/dist/api/canvas/canvasGetImageData.js +25 -0
  18. package/dist/api/canvas/canvasPutImageData.js +22 -0
  19. package/dist/api/canvas/canvasToTempFilePath.js +22 -0
  20. package/dist/api/canvas/createCanvasContext.js +16 -0
  21. package/dist/api/canvas/index.js +8 -0
  22. package/dist/api/cloud/index.js +21 -0
  23. package/dist/api/data-analysis/index.js +5 -0
  24. package/dist/api/device/accelerometer.js +83 -0
  25. package/dist/api/device/accessibility.js +3 -0
  26. package/dist/api/device/battery.js +4 -0
  27. package/dist/api/device/bluetooth-ble.js +18 -0
  28. package/dist/api/device/bluetooth-peripheral.js +5 -0
  29. package/dist/api/device/bluetooth.js +15 -0
  30. package/dist/api/device/calendar.js +4 -0
  31. package/dist/api/device/clipboard.js +65 -0
  32. package/dist/api/device/compass.js +64 -0
  33. package/dist/api/device/contact.js +4 -0
  34. package/dist/api/device/crypto.js +3 -0
  35. package/dist/api/device/gyroscope.js +6 -0
  36. package/dist/api/device/iBeacon.js +9 -0
  37. package/dist/api/device/index.js +22 -0
  38. package/dist/api/device/keyboard.js +6 -0
  39. package/dist/api/device/memory.js +4 -0
  40. package/dist/api/device/motion.js +81 -0
  41. package/dist/api/device/nfc.js +9 -0
  42. package/dist/api/device/phone.js +24 -0
  43. package/dist/api/device/scan.js +6 -0
  44. package/dist/api/device/screen.js +8 -0
  45. package/dist/api/device/vibrate.js +35 -0
  46. package/dist/api/device/wifi.js +12 -0
  47. package/dist/api/ext/index.js +4 -0
  48. package/dist/api/files/index.js +10 -0
  49. package/dist/api/framework/index.js +7 -0
  50. package/dist/api/index.js +24 -0
  51. package/dist/api/location/chooseLocation.js +93 -0
  52. package/dist/api/location/index.js +13 -0
  53. package/dist/api/location/style.css +79 -0
  54. package/dist/api/media/EditorContext.js +18 -0
  55. package/dist/api/media/audio/InnerAudioContext.js +84 -0
  56. package/dist/api/media/audio/index.js +15 -0
  57. package/dist/api/media/background-audio/BackgroundAudioManager.js +86 -0
  58. package/dist/api/media/background-audio/index.js +15 -0
  59. package/dist/api/media/camera.js +3 -0
  60. package/dist/api/media/image/chooseImage.js +74 -0
  61. package/dist/api/media/image/getImageInfo.js +31 -0
  62. package/dist/api/media/image/index.js +9 -0
  63. package/dist/api/media/image/previewImage.js +67 -0
  64. package/dist/api/media/index.js +12 -0
  65. package/dist/api/media/live.js +4 -0
  66. package/dist/api/media/map.js +3 -0
  67. package/dist/api/media/media-recorder.js +3 -0
  68. package/dist/api/media/recorder.js +5 -0
  69. package/dist/api/media/video/index.js +74 -0
  70. package/dist/api/media/video-decoder.js +3 -0
  71. package/dist/api/media/video-processing.js +3 -0
  72. package/dist/api/media/voip.js +16 -0
  73. package/dist/api/navigate/index.js +6 -0
  74. package/dist/api/network/download.js +124 -0
  75. package/dist/api/network/index.js +7 -0
  76. package/dist/api/network/mdns.js +12 -0
  77. package/dist/api/network/request/index.js +125 -0
  78. package/dist/api/network/tcp.js +3 -0
  79. package/dist/api/network/udp.js +3 -0
  80. package/dist/api/network/upload.js +151 -0
  81. package/dist/api/network/utils.js +65 -0
  82. package/dist/api/network/websocket/index.js +70 -0
  83. package/dist/api/network/websocket/socketTask.js +63 -0
  84. package/dist/api/open-api/account.js +3 -0
  85. package/dist/api/open-api/address.js +3 -0
  86. package/dist/api/open-api/authorize.js +4 -0
  87. package/dist/api/open-api/card.js +4 -0
  88. package/dist/api/open-api/channels-live.js +8 -0
  89. package/dist/api/open-api/customer-service.js +3 -0
  90. package/dist/api/open-api/facial.js +6 -0
  91. package/dist/api/open-api/favorites.js +4 -0
  92. package/dist/api/open-api/group.js +3 -0
  93. package/dist/api/open-api/index.js +18 -0
  94. package/dist/api/open-api/invoice.js +4 -0
  95. package/dist/api/open-api/license-plate.js +3 -0
  96. package/dist/api/open-api/login.js +5 -0
  97. package/dist/api/open-api/red-package.js +3 -0
  98. package/dist/api/open-api/settings.js +4 -0
  99. package/dist/api/open-api/soter.js +5 -0
  100. package/dist/api/open-api/subscribe-message.js +3 -0
  101. package/dist/api/open-api/user-info.js +4 -0
  102. package/dist/api/open-api/werun.js +4 -0
  103. package/dist/api/payment/index.js +4 -0
  104. package/dist/api/route/index.js +3 -0
  105. package/dist/api/share/index.js +12 -0
  106. package/dist/api/storage/background-fetch.js +6 -0
  107. package/dist/api/storage/index.js +157 -0
  108. package/dist/api/swan/index.js +26 -0
  109. package/dist/api/taro.js +47 -0
  110. package/dist/api/ui/animation/index.js +288 -0
  111. package/dist/api/ui/background.js +4 -0
  112. package/dist/api/ui/custom-component.js +3 -0
  113. package/dist/api/ui/fonts.js +3 -0
  114. package/dist/api/ui/index.js +12 -0
  115. package/dist/api/ui/interaction/actionSheet.js +188 -0
  116. package/dist/api/ui/interaction/index.js +268 -0
  117. package/dist/api/ui/interaction/modal.js +207 -0
  118. package/dist/api/ui/interaction/toast.js +195 -0
  119. package/dist/api/ui/menu.js +3 -0
  120. package/dist/api/ui/navigation-bar/index.js +42 -0
  121. package/dist/api/ui/pull-down-refresh.js +26 -0
  122. package/dist/api/ui/scroll/index.js +83 -0
  123. package/dist/api/ui/sticky.js +3 -0
  124. package/dist/api/ui/tab-bar.js +282 -0
  125. package/dist/api/ui/window.js +31 -0
  126. package/dist/api/utils/handler.js +80 -0
  127. package/dist/api/utils/index.js +172 -0
  128. package/dist/api/worker/index.js +3 -0
  129. package/dist/api/wxml/index.js +6 -0
  130. package/dist/api/wxml/nodesRef.js +42 -0
  131. package/dist/api/wxml/selectorQuery.js +201 -0
  132. package/dist/index.cjs.js +4756 -6934
  133. package/dist/index.js +4 -10767
  134. package/dist/taroApis.js +1 -1
  135. package/dist/types/type.js +2 -0
  136. package/package.json +11 -13
  137. package/src/api/canvas/CanvasContext.ts +36 -33
  138. package/src/api/canvas/createCanvasContext.ts +2 -2
  139. package/src/api/cloud/index.ts +4 -0
  140. package/src/api/location/chooseLocation.ts +2 -2
  141. package/src/api/media/{editor.ts → EditorContext.ts} +0 -0
  142. package/src/api/media/audio/InnerAudioContext.ts +98 -0
  143. package/src/api/media/audio/index.ts +1 -86
  144. package/src/api/media/background-audio/BackgroundAudioManager.ts +103 -0
  145. package/src/api/media/{background-audio.ts → background-audio/index.ts} +7 -2
  146. package/src/api/media/image/previewImage.ts +4 -25
  147. package/src/api/media/index.ts +0 -1
  148. package/src/api/network/download.ts +5 -5
  149. package/src/api/network/upload.ts +6 -6
  150. package/src/api/network/websocket/index.ts +1 -1
  151. package/src/api/ui/animation/index.ts +11 -12
  152. package/src/api/ui/interaction/index.ts +12 -10
  153. package/src/api/ui/navigation-bar/index.ts +2 -2
  154. package/src/api/ui/scroll/index.ts +3 -3
  155. package/src/api/utils/index.ts +34 -13
  156. package/src/api/wxml/nodesRef.ts +10 -3
  157. package/src/api/wxml/selectorQuery.ts +68 -23
  158. package/src/index.ts +2 -2
@@ -114,7 +114,7 @@ const createDownloadTask = ({ url, header, success, error }): Taro.DownloadTask
114
114
  * 注意:请在服务端响应的 header 中指定合理的 Content-Type 字段,以保证客户端正确处理文件类型。
115
115
  */
116
116
  export const downloadFile: typeof Taro.downloadFile = ({ url, header, success, fail, complete }) => {
117
- let task: Taro.DownloadTask
117
+ let task!: Taro.DownloadTask
118
118
  const result: ReturnType<typeof Taro.downloadFile> = new Promise((resolve, reject) => {
119
119
  task = createDownloadTask({
120
120
  url,
@@ -130,11 +130,11 @@ export const downloadFile: typeof Taro.downloadFile = ({ url, header, success, f
130
130
  reject(res)
131
131
  }
132
132
  })
133
-
134
- result.headersReceive = task.onHeadersReceived
135
- result.progress = task.onProgressUpdate
136
- result.abort = task.abort
137
133
  }) as any
138
134
 
135
+ result.headersReceive = task.onHeadersReceived
136
+ result.progress = task.onProgressUpdate
137
+ result.abort = task.abort
138
+
139
139
  return result
140
140
  }
@@ -8,7 +8,7 @@ import {
8
8
  XHR_STATS
9
9
  } from './utils'
10
10
 
11
- const createUploadTask = ({ url, filePath, formData, name, header, timeout, fileName, success, error }): Taro.UploadTask => {
11
+ const createUploadTask = ({ url, filePath, formData = {}, name, header, timeout, fileName, success, error }): Taro.UploadTask => {
12
12
  let timeoutInter
13
13
  let formKey
14
14
  const apiName = 'uploadFile'
@@ -143,7 +143,7 @@ const createUploadTask = ({ url, filePath, formData, name, header, timeout, file
143
143
  * 将本地资源上传到服务器。客户端发起一个 HTTPS POST 请求,其中 content-type 为 multipart/form-data。使用前请注意阅读相关说明。
144
144
  */
145
145
  export const uploadFile: typeof Taro.uploadFile = ({ url, filePath, name, header, formData, timeout, fileName, success, fail, complete }) => {
146
- let task: Taro.UploadTask
146
+ let task!: Taro.UploadTask
147
147
  const result: ReturnType<typeof Taro.uploadFile> = new Promise((resolve, reject) => {
148
148
  task = createUploadTask({
149
149
  url,
@@ -164,11 +164,11 @@ export const uploadFile: typeof Taro.uploadFile = ({ url, filePath, name, header
164
164
  reject(res)
165
165
  }
166
166
  })
167
-
168
- result.headersReceive = task.onHeadersReceived
169
- result.progress = task.onProgressUpdate
170
- result.abort = task.abort
171
167
  }) as any
172
168
 
169
+ result.headersReceive = task.onHeadersReceived
170
+ result.progress = task.onProgressUpdate
171
+ result.abort = task.abort
172
+
173
173
  return result
174
174
  }
@@ -1,6 +1,6 @@
1
1
  import { SocketTask } from './socketTask'
2
2
  import { shouldBeObject, getParameterError } from '../../utils'
3
- import { MethodHandler } from 'src/api/utils/handler'
3
+ import { MethodHandler } from '../../utils/handler'
4
4
 
5
5
  let socketTasks: SocketTask[] = []
6
6
  let socketsCounter = 1
@@ -9,13 +9,17 @@ class StyleSheet {
9
9
  this.$style = document.createElement('style')
10
10
  }
11
11
 
12
- $style: HTMLStyleElement
13
- sheet?: CSSStyleSheet | null
12
+ $style?: HTMLStyleElement | null = null
13
+ sheet?: CSSStyleSheet | null = null
14
+
14
15
  appendStyleSheet = () => {
15
- this.$style?.setAttribute('type', 'text/css')
16
- this.$style?.setAttribute('data-type', 'Taro')
17
- document.getElementsByTagName('head')[0].appendChild(this.$style)
18
- this.sheet = this.$style?.sheet
16
+ if (this.$style) {
17
+ const head = document.getElementsByTagName('head')[0]
18
+ this.$style.setAttribute('type', 'text/css')
19
+ this.$style.setAttribute('data-type', 'Taro')
20
+ head.appendChild(this.$style)
21
+ this.sheet = this.$style.sheet
22
+ }
19
23
  if (this.sheet && !('insertRule' in this.sheet)) {
20
24
  console.warn('当前浏览器不支持 stylesheet.insertRule 接口')
21
25
  }
@@ -38,12 +42,7 @@ let TRANSITION_END = 'transitionend'
38
42
  let TRANSFORM = 'transform'
39
43
 
40
44
  const $detect = document.createElement('div')
41
- $detect.style.cssText = `
42
- -webkit-animation-name: webkit;
43
- -moz-animation-name: moz;
44
- -ms-animation-name: ms;
45
- animation-name: standard;
46
- `
45
+ $detect.style.cssText = '-webkit-animation-name:webkit;-moz-animation-name:moz;-ms-animation-name:ms;animation-name:standard;'
47
46
  if ($detect.style['animation-name'] === 'standard') {
48
47
  // 支持标准写法
49
48
  TRANSITION_END = 'transitionend'
@@ -62,9 +62,9 @@ const showToast: typeof Taro.showToast = (options = { title: '' }) => {
62
62
 
63
63
  let errMsg = ''
64
64
  if (!toast.el) {
65
- errMsg = toast.create(options, 'loading')
65
+ errMsg = toast.create(options, 'toast')
66
66
  } else {
67
- errMsg = toast.show(options, 'loading')
67
+ errMsg = toast.show(options, 'toast')
68
68
  }
69
69
  return handle.success({ errMsg })
70
70
  }
@@ -167,7 +167,7 @@ const showModal: typeof Taro.showModal = async (options = {}) => {
167
167
 
168
168
  if (options.cancelText.replace(/[\u0391-\uFFE5]/g, 'aa').length > 8) {
169
169
  return handle.fail({
170
- errMsg: 'showModal:fail cancelText length should not larger then 4 Chinese characters'
170
+ errMsg: 'cancelText length should not larger then 4 Chinese characters'
171
171
  })
172
172
  }
173
173
 
@@ -183,7 +183,7 @@ const showModal: typeof Taro.showModal = async (options = {}) => {
183
183
 
184
184
  if (options.confirmText.replace(/[\u0391-\uFFE5]/g, 'aa').length > 8) {
185
185
  return handle.fail({
186
- errMsg: 'showModal:fail confirmText length should not larger then 4 Chinese characters'
186
+ errMsg: 'confirmText length should not larger then 4 Chinese characters'
187
187
  })
188
188
  }
189
189
 
@@ -209,13 +209,15 @@ const showModal: typeof Taro.showModal = async (options = {}) => {
209
209
 
210
210
  options.showCancel = !!options.showCancel
211
211
 
212
- let errMsg = ''
212
+ let result = ''
213
213
  if (!modal.el) {
214
- errMsg = await modal.create(options)
214
+ result = await modal.create(options)
215
215
  } else {
216
- errMsg = await modal.show(options)
216
+ result = await modal.show(options)
217
217
  }
218
- return handle.success({ errMsg })
218
+ const res = { cancel: !1, confirm: !1 }
219
+ res[result] = !0
220
+ return handle.success(res)
219
221
  }
220
222
 
221
223
  function hideModal () {
@@ -244,11 +246,11 @@ const showActionSheet: typeof Taro.showActionSheet = async (options = { itemList
244
246
  }
245
247
 
246
248
  if (options.itemList.length < 1) {
247
- return handle.fail({ errMsg: 'showActionSheet:fail parameter error: parameter.itemList should have at least 1 item' })
249
+ return handle.fail({ errMsg: 'parameter error: parameter.itemList should have at least 1 item' })
248
250
  }
249
251
 
250
252
  if (options.itemList.length > 6) {
251
- return handle.fail({ errMsg: 'showActionSheet:fail parameter error: parameter.itemList should not be large than 6' })
253
+ return handle.fail({ errMsg: 'parameter error: parameter.itemList should not be large than 6' })
252
254
  }
253
255
 
254
256
  for (let i = 0; i < options.itemList.length; i++) {
@@ -1,4 +1,4 @@
1
- import Taro from '@tarojs/taro'
1
+ import Taro from '@tarojs/api'
2
2
 
3
3
  import { MethodHandler } from '../../utils/handler'
4
4
  import { getParameterError, shouldBeObject, temporarilyNotSupport } from '../../utils'
@@ -16,7 +16,7 @@ export function setNavigationBarTitle (options) {
16
16
  }
17
17
 
18
18
  const { title, success, fail, complete } = options
19
- const handle = new MethodHandler({ name: 'makePhoneCall', success, fail, complete })
19
+ const handle = new MethodHandler({ name: 'setNavigationBarTitle', success, fail, complete })
20
20
 
21
21
  if (!title || typeof title !== 'string') {
22
22
  return handle.fail({
@@ -4,7 +4,7 @@ import { Current } from '@tarojs/runtime'
4
4
  import { MethodHandler } from '../../utils/handler'
5
5
  import { getTimingFunc, easeInOut } from '../../utils'
6
6
 
7
- let timer: number
7
+ let timer: NodeJS.Timer
8
8
  const FRAME_DURATION = 17
9
9
 
10
10
  /**
@@ -21,9 +21,9 @@ export const pageScrollTo: typeof Taro.pageScrollTo = ({ scrollTop, selector = '
21
21
  }, reject)
22
22
  }
23
23
 
24
- const id = Current.page?.path
24
+ const id = Current.page?.path?.replace(/([^a-z0-9\u00a0-\uffff_-])/ig, '\\$1')
25
25
  const el: HTMLDivElement | null = (id
26
- ? document.getElementById(id)
26
+ ? document.querySelector(`.taro_page#${id}`)
27
27
  : document.querySelector('.taro_page') ||
28
28
  document.querySelector('.taro_router')) as HTMLDivElement
29
29
 
@@ -12,7 +12,7 @@ export function shouldBeObject (target: unknown) {
12
12
  }
13
13
  }
14
14
 
15
- export function findDOM (inst): TaroElement | HTMLElement | undefined {
15
+ export function findDOM (inst?): TaroElement | HTMLElement | undefined {
16
16
  const runtimeHooks = container.get<IHooks>(SERVICE_IDENTIFIER.Hooks)
17
17
 
18
18
  if (inst) {
@@ -88,30 +88,51 @@ export function serializeParams (params) {
88
88
  export function temporarilyNotSupport (apiName) {
89
89
  return () => {
90
90
  const errMsg = `暂时不支持 API ${apiName}`
91
- console.error(errMsg)
92
- return Promise.reject({
93
- errMsg
94
- })
91
+ if (process.env.NODE_ENV !== 'production') {
92
+ console.error(errMsg)
93
+ return Promise.reject({
94
+ errMsg
95
+ })
96
+ } else {
97
+ console.warn(errMsg)
98
+ return Promise.resolve({
99
+ errMsg
100
+ })
101
+ }
95
102
  }
96
103
  }
97
104
 
98
105
  export function weixinCorpSupport (apiName) {
99
106
  return () => {
100
107
  const errMsg = `h5端仅在微信公众号中支持 API ${apiName}`
101
- console.error(errMsg)
102
- return Promise.reject({
103
- errMsg
104
- })
108
+ if (process.env.NODE_ENV !== 'production') {
109
+ console.error(errMsg)
110
+ return Promise.reject({
111
+ errMsg
112
+ })
113
+ } else {
114
+ console.warn(errMsg)
115
+ return Promise.resolve({
116
+ errMsg
117
+ })
118
+ }
105
119
  }
106
120
  }
107
121
 
108
122
  export function permanentlyNotSupport (apiName) {
109
123
  return () => {
110
124
  const errMsg = `不支持 API ${apiName}`
111
- console.error(errMsg)
112
- return Promise.reject({
113
- errMsg
114
- })
125
+ if (process.env.NODE_ENV !== 'production') {
126
+ console.error(errMsg)
127
+ return Promise.reject({
128
+ errMsg
129
+ })
130
+ } else {
131
+ console.warn(errMsg)
132
+ return Promise.resolve({
133
+ errMsg
134
+ })
135
+ }
115
136
  }
116
137
  }
117
138
 
@@ -1,4 +1,3 @@
1
- import { temporarilyNotSupport } from '../utils'
2
1
  import { SelectorQuery } from './selectorQuery'
3
2
 
4
3
  export class NodesRef implements Taro.NodesRef {
@@ -14,9 +13,17 @@ export class NodesRef implements Taro.NodesRef {
14
13
  this._single = single
15
14
  }
16
15
 
17
- context = temporarilyNotSupport('NodesRef.context') as unknown as Taro.NodesRef['context']
16
+ context (cb) {
17
+ const { _selector, _component, _single, _selectorQuery } = this
18
+ _selectorQuery._push(_selector, _component, _single, { context: !0 }, cb)
19
+ return _selectorQuery
20
+ }
18
21
 
19
- node = temporarilyNotSupport('NodesRef.node') as unknown as Taro.NodesRef['node']
22
+ node (cb) {
23
+ const { _selector, _component, _single, _selectorQuery } = this
24
+ _selectorQuery._push(_selector, _component, _single, { nodeCanvasType: !0, node: !0 }, cb)
25
+ return _selectorQuery
26
+ }
20
27
 
21
28
  boundingClientRect (cb) {
22
29
  const { _selector, _component, _single, _selectorQuery } = this
@@ -1,4 +1,5 @@
1
1
  import Taro from '@tarojs/api'
2
+ import { CanvasContext } from '../canvas/CanvasContext'
2
3
  import { findDOM } from '../utils'
3
4
  import { NodesRef } from './nodesRef'
4
5
 
@@ -16,33 +17,77 @@ type TSelectorQueryQueueCallback = (res: ISelectorQueryQueue) => void
16
17
  function filter (fields, dom?: HTMLElement, selector?: string) {
17
18
  if (!dom) return null
18
19
 
19
- const { id, dataset, rect, size, scrollOffset, properties = [], computedStyle = [] } = fields
20
- const { left, right, top, bottom, width, height } = dom.getBoundingClientRect()
21
- const isViewport = selector === 'html'
20
+ const isViewport = selector === '.taro_page'
21
+ const { id, dataset, rect, size, scrollOffset, properties = [], computedStyle = [], nodeCanvasType, node, context } = fields
22
22
  const res: any = {}
23
23
 
24
- if (id) res.id = dom.id
25
- if (dataset) res.dataset = Object.assign({}, dom.dataset)
26
- if (rect) {
27
- if (!isViewport) {
28
- res.left = left
29
- res.right = right
30
- res.top = top
31
- res.bottom = bottom
24
+ if (nodeCanvasType && node) {
25
+ const tagName = dom.tagName
26
+ res.node = {
27
+ id: dom.id,
28
+ $taroElement: dom
29
+ }
30
+ if (/^taro-canvas-core/i.test(tagName)) {
31
+ const type = (dom as any).type! || ''
32
+ res.nodeCanvasType = type
33
+ const canvas = dom.getElementsByTagName('canvas')[0]
34
+ if (/^(2d|webgl)/i.test(type) && canvas) {
35
+ res.node = canvas
36
+ } else {
37
+ res.node = null
38
+ }
32
39
  } else {
33
- res.left = 0
34
- res.right = 0
35
- res.top = 0
36
- res.bottom = 0
40
+ // TODO https://developers.weixin.qq.com/miniprogram/dev/component/scroll-view.html
41
+ // if (/^taro-scroll-view-core/i.test(tagName))
42
+ res.nodeCanvasType = ''
43
+ res.node = dom
37
44
  }
45
+ return res
38
46
  }
39
- if (size) {
40
- if (!isViewport) {
41
- res.width = width
42
- res.height = height
43
- } else {
44
- res.width = dom.clientWidth
45
- res.height = dom.clientHeight
47
+ if (context) {
48
+ const tagName = dom.tagName
49
+ if (/^taro-video-core/i.test(tagName)) {
50
+ // TODO HTMLVideoElement to VideoContext
51
+ return { context: dom as unknown as Taro.VideoContext }
52
+ } else if (/^taro-canvas-core/i.test(tagName)) {
53
+ const type = (dom as any).type! || '2d'
54
+ const canvas = dom?.querySelector('canvas') as HTMLCanvasElement
55
+ const ctx = canvas?.getContext(type) as CanvasRenderingContext2D
56
+ return { context: new CanvasContext(canvas, ctx) }
57
+ } else if (/^taro-live-player-core/i.test(tagName)) {
58
+ console.error('暂时不支持通过 NodesRef.context 获取 LivePlayerContext')
59
+ } else if (/^taro-editor-core/i.test(tagName)) {
60
+ console.error('暂时不支持通过 NodesRef.context 获取 EditorContext')
61
+ } else if (/^taro-map-core/i.test(tagName)) {
62
+ console.error('暂时不支持通过 NodesRef.context 获取 MapContext')
63
+ }
64
+ return
65
+ }
66
+ if (id) res.id = dom.id
67
+ if (dataset) res.dataset = Object.assign({}, dom.dataset)
68
+ if (rect || size) {
69
+ const { left, right, top, bottom, width, height } = dom.getBoundingClientRect()
70
+ if (rect) {
71
+ if (!isViewport) {
72
+ res.left = left
73
+ res.right = right
74
+ res.top = top
75
+ res.bottom = bottom
76
+ } else {
77
+ res.left = 0
78
+ res.right = 0
79
+ res.top = 0
80
+ res.bottom = 0
81
+ }
82
+ }
83
+ if (size) {
84
+ if (!isViewport) {
85
+ res.width = width
86
+ res.height = height
87
+ } else {
88
+ res.width = dom.clientWidth
89
+ res.height = dom.clientHeight
90
+ }
46
91
  }
47
92
  }
48
93
  if (scrollOffset) {
@@ -147,7 +192,7 @@ export class SelectorQuery implements Taro.SelectorQuery {
147
192
  }
148
193
 
149
194
  selectViewport () {
150
- return new NodesRef('html', this, true)
195
+ return new NodesRef('.taro_page', this, true)
151
196
  }
152
197
 
153
198
  exec (cb) {
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
1
- import Taro from './api/taro'
1
+ import taro from './api/taro'
2
2
 
3
3
  export * from './api/index'
4
4
  export * from './api/taro'
5
5
 
6
- export default Taro
6
+ export default taro