@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.
- package/dist/api/ad/index.js +4 -0
- package/dist/api/ai/facial.js +5 -0
- package/dist/api/ai/index.js +2 -0
- package/dist/api/ai/visual.js +3 -0
- package/dist/api/alipay/index.js +3 -0
- package/dist/api/base/crypto.js +3 -0
- package/dist/api/base/debug.js +4 -0
- package/dist/api/base/index.js +17 -0
- package/dist/api/base/performance.js +4 -0
- package/dist/api/base/system/index.js +2 -0
- package/dist/api/base/system/info.js +57 -0
- package/dist/api/base/system/network.js +63 -0
- package/dist/api/base/update.js +4 -0
- package/dist/api/base/weapp/app-event.js +18 -0
- package/dist/api/base/weapp/life-cycle.js +4 -0
- package/dist/api/canvas/CanvasContext.js +191 -0
- package/dist/api/canvas/canvasGetImageData.js +25 -0
- package/dist/api/canvas/canvasPutImageData.js +22 -0
- package/dist/api/canvas/canvasToTempFilePath.js +22 -0
- package/dist/api/canvas/createCanvasContext.js +16 -0
- package/dist/api/canvas/index.js +8 -0
- package/dist/api/cloud/index.js +21 -0
- package/dist/api/data-analysis/index.js +5 -0
- package/dist/api/device/accelerometer.js +83 -0
- package/dist/api/device/accessibility.js +3 -0
- package/dist/api/device/battery.js +4 -0
- package/dist/api/device/bluetooth-ble.js +18 -0
- package/dist/api/device/bluetooth-peripheral.js +5 -0
- package/dist/api/device/bluetooth.js +15 -0
- package/dist/api/device/calendar.js +4 -0
- package/dist/api/device/clipboard.js +65 -0
- package/dist/api/device/compass.js +64 -0
- package/dist/api/device/contact.js +4 -0
- package/dist/api/device/crypto.js +3 -0
- package/dist/api/device/gyroscope.js +6 -0
- package/dist/api/device/iBeacon.js +9 -0
- package/dist/api/device/index.js +22 -0
- package/dist/api/device/keyboard.js +6 -0
- package/dist/api/device/memory.js +4 -0
- package/dist/api/device/motion.js +81 -0
- package/dist/api/device/nfc.js +9 -0
- package/dist/api/device/phone.js +24 -0
- package/dist/api/device/scan.js +6 -0
- package/dist/api/device/screen.js +8 -0
- package/dist/api/device/vibrate.js +35 -0
- package/dist/api/device/wifi.js +12 -0
- package/dist/api/ext/index.js +4 -0
- package/dist/api/files/index.js +10 -0
- package/dist/api/framework/index.js +7 -0
- package/dist/api/index.js +24 -0
- package/dist/api/location/chooseLocation.js +93 -0
- package/dist/api/location/index.js +13 -0
- package/dist/api/location/style.css +79 -0
- package/dist/api/media/EditorContext.js +18 -0
- package/dist/api/media/audio/InnerAudioContext.js +84 -0
- package/dist/api/media/audio/index.js +15 -0
- package/dist/api/media/background-audio/BackgroundAudioManager.js +86 -0
- package/dist/api/media/background-audio/index.js +15 -0
- package/dist/api/media/camera.js +3 -0
- package/dist/api/media/image/chooseImage.js +74 -0
- package/dist/api/media/image/getImageInfo.js +31 -0
- package/dist/api/media/image/index.js +9 -0
- package/dist/api/media/image/previewImage.js +67 -0
- package/dist/api/media/index.js +12 -0
- package/dist/api/media/live.js +4 -0
- package/dist/api/media/map.js +3 -0
- package/dist/api/media/media-recorder.js +3 -0
- package/dist/api/media/recorder.js +5 -0
- package/dist/api/media/video/index.js +74 -0
- package/dist/api/media/video-decoder.js +3 -0
- package/dist/api/media/video-processing.js +3 -0
- package/dist/api/media/voip.js +16 -0
- package/dist/api/navigate/index.js +6 -0
- package/dist/api/network/download.js +124 -0
- package/dist/api/network/index.js +7 -0
- package/dist/api/network/mdns.js +12 -0
- package/dist/api/network/request/index.js +125 -0
- package/dist/api/network/tcp.js +3 -0
- package/dist/api/network/udp.js +3 -0
- package/dist/api/network/upload.js +151 -0
- package/dist/api/network/utils.js +65 -0
- package/dist/api/network/websocket/index.js +70 -0
- package/dist/api/network/websocket/socketTask.js +63 -0
- package/dist/api/open-api/account.js +3 -0
- package/dist/api/open-api/address.js +3 -0
- package/dist/api/open-api/authorize.js +4 -0
- package/dist/api/open-api/card.js +4 -0
- package/dist/api/open-api/channels-live.js +8 -0
- package/dist/api/open-api/customer-service.js +3 -0
- package/dist/api/open-api/facial.js +6 -0
- package/dist/api/open-api/favorites.js +4 -0
- package/dist/api/open-api/group.js +3 -0
- package/dist/api/open-api/index.js +18 -0
- package/dist/api/open-api/invoice.js +4 -0
- package/dist/api/open-api/license-plate.js +3 -0
- package/dist/api/open-api/login.js +5 -0
- package/dist/api/open-api/red-package.js +3 -0
- package/dist/api/open-api/settings.js +4 -0
- package/dist/api/open-api/soter.js +5 -0
- package/dist/api/open-api/subscribe-message.js +3 -0
- package/dist/api/open-api/user-info.js +4 -0
- package/dist/api/open-api/werun.js +4 -0
- package/dist/api/payment/index.js +4 -0
- package/dist/api/route/index.js +3 -0
- package/dist/api/share/index.js +12 -0
- package/dist/api/storage/background-fetch.js +6 -0
- package/dist/api/storage/index.js +157 -0
- package/dist/api/swan/index.js +26 -0
- package/dist/api/taro.js +47 -0
- package/dist/api/ui/animation/index.js +288 -0
- package/dist/api/ui/background.js +4 -0
- package/dist/api/ui/custom-component.js +3 -0
- package/dist/api/ui/fonts.js +3 -0
- package/dist/api/ui/index.js +12 -0
- package/dist/api/ui/interaction/actionSheet.js +188 -0
- package/dist/api/ui/interaction/index.js +268 -0
- package/dist/api/ui/interaction/modal.js +207 -0
- package/dist/api/ui/interaction/toast.js +195 -0
- package/dist/api/ui/menu.js +3 -0
- package/dist/api/ui/navigation-bar/index.js +42 -0
- package/dist/api/ui/pull-down-refresh.js +26 -0
- package/dist/api/ui/scroll/index.js +83 -0
- package/dist/api/ui/sticky.js +3 -0
- package/dist/api/ui/tab-bar.js +282 -0
- package/dist/api/ui/window.js +31 -0
- package/dist/api/utils/handler.js +80 -0
- package/dist/api/utils/index.js +172 -0
- package/dist/api/worker/index.js +3 -0
- package/dist/api/wxml/index.js +6 -0
- package/dist/api/wxml/nodesRef.js +42 -0
- package/dist/api/wxml/selectorQuery.js +201 -0
- package/dist/index.cjs.js +4756 -6934
- package/dist/index.js +4 -10767
- package/dist/taroApis.js +1 -1
- package/dist/types/type.js +2 -0
- package/package.json +11 -13
- package/src/api/canvas/CanvasContext.ts +36 -33
- package/src/api/canvas/createCanvasContext.ts +2 -2
- package/src/api/cloud/index.ts +4 -0
- package/src/api/location/chooseLocation.ts +2 -2
- package/src/api/media/{editor.ts → EditorContext.ts} +0 -0
- package/src/api/media/audio/InnerAudioContext.ts +98 -0
- package/src/api/media/audio/index.ts +1 -86
- package/src/api/media/background-audio/BackgroundAudioManager.ts +103 -0
- package/src/api/media/{background-audio.ts → background-audio/index.ts} +7 -2
- package/src/api/media/image/previewImage.ts +4 -25
- package/src/api/media/index.ts +0 -1
- package/src/api/network/download.ts +5 -5
- package/src/api/network/upload.ts +6 -6
- package/src/api/network/websocket/index.ts +1 -1
- package/src/api/ui/animation/index.ts +11 -12
- package/src/api/ui/interaction/index.ts +12 -10
- package/src/api/ui/navigation-bar/index.ts +2 -2
- package/src/api/ui/scroll/index.ts +3 -3
- package/src/api/utils/index.ts +34 -13
- package/src/api/wxml/nodesRef.ts +10 -3
- package/src/api/wxml/selectorQuery.ts +68 -23
- 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
|
|
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
|
|
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 '
|
|
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
|
|
13
|
-
sheet?: CSSStyleSheet | null
|
|
12
|
+
$style?: HTMLStyleElement | null = null
|
|
13
|
+
sheet?: CSSStyleSheet | null = null
|
|
14
|
+
|
|
14
15
|
appendStyleSheet = () => {
|
|
15
|
-
this.$style
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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, '
|
|
65
|
+
errMsg = toast.create(options, 'toast')
|
|
66
66
|
} else {
|
|
67
|
-
errMsg = toast.show(options, '
|
|
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: '
|
|
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: '
|
|
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
|
|
212
|
+
let result = ''
|
|
213
213
|
if (!modal.el) {
|
|
214
|
-
|
|
214
|
+
result = await modal.create(options)
|
|
215
215
|
} else {
|
|
216
|
-
|
|
216
|
+
result = await modal.show(options)
|
|
217
217
|
}
|
|
218
|
-
|
|
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: '
|
|
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: '
|
|
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/
|
|
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: '
|
|
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:
|
|
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.
|
|
26
|
+
? document.querySelector(`.taro_page#${id}`)
|
|
27
27
|
: document.querySelector('.taro_page') ||
|
|
28
28
|
document.querySelector('.taro_router')) as HTMLDivElement
|
|
29
29
|
|
package/src/api/utils/index.ts
CHANGED
|
@@ -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
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
|
package/src/api/wxml/nodesRef.ts
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
20
|
-
const {
|
|
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 (
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
res.
|
|
36
|
-
res.
|
|
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 (
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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('
|
|
195
|
+
return new NodesRef('.taro_page', this, true)
|
|
151
196
|
}
|
|
152
197
|
|
|
153
198
|
exec (cb) {
|
package/src/index.ts
CHANGED