@tarojs/taro-h5 3.3.16 → 3.4.0-beta.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/index.cjs.js +9439 -10025
- package/dist/index.js +10767 -0
- package/dist/taroApis.js +1 -1
- package/package.json +9 -13
- package/src/api/ad/index.ts +5 -0
- package/src/api/ai/facial.ts +6 -0
- package/src/api/ai/index.ts +2 -0
- package/src/api/ai/visual.ts +4 -0
- package/src/api/alipay/index.ts +4 -0
- package/src/api/base/crypto.ts +4 -0
- package/src/api/base/debug.ts +5 -0
- package/src/api/base/index.ts +23 -0
- package/src/api/base/performance.ts +5 -0
- package/src/api/base/system/index.ts +2 -0
- package/src/api/base/system/info.ts +64 -0
- package/src/api/base/system/network.ts +70 -0
- package/src/api/base/update.ts +5 -0
- package/src/api/base/weapp/app-event.ts +19 -0
- package/src/api/base/weapp/life-cycle.ts +5 -0
- package/src/api/canvas/CanvasContext.ts +230 -0
- package/src/api/canvas/canvasGetImageData.ts +27 -0
- package/src/api/canvas/canvasPutImageData.ts +24 -0
- package/src/api/canvas/canvasToTempFilePath.ts +24 -0
- package/src/api/canvas/createCanvasContext.ts +18 -0
- package/src/api/canvas/index.ts +10 -0
- package/src/api/cloud/index.ts +27 -0
- package/src/api/data-analysis/index.ts +6 -0
- package/src/api/device/accelerometer.ts +87 -0
- package/src/api/device/accessibility.ts +4 -0
- package/src/api/device/battery.ts +5 -0
- package/src/api/device/bluetooth-ble.ts +19 -0
- package/src/api/device/bluetooth-peripheral.ts +6 -0
- package/src/api/device/bluetooth.ts +16 -0
- package/src/api/device/calendar.ts +5 -0
- package/src/api/device/clipboard.ts +67 -0
- package/src/api/device/compass.ts +67 -0
- package/src/api/device/contact.ts +5 -0
- package/src/api/device/crypto.ts +4 -0
- package/src/api/device/gyroscope.ts +7 -0
- package/src/api/device/iBeacon.ts +10 -0
- package/src/api/device/index.ts +22 -0
- package/src/api/device/keyboard.ts +7 -0
- package/src/api/device/memory.ts +5 -0
- package/src/api/device/motion.ts +85 -0
- package/src/api/device/nfc.ts +10 -0
- package/src/api/device/phone.ts +30 -0
- package/src/api/device/scan.ts +7 -0
- package/src/api/device/screen.ts +9 -0
- package/src/api/device/vibrate.ts +36 -0
- package/src/api/device/wifi.ts +13 -0
- package/src/api/ext/index.ts +5 -0
- package/src/api/files/index.ts +11 -0
- package/src/api/framework/index.ts +10 -0
- package/src/api/index.ts +25 -0
- package/src/api/location/chooseLocation.ts +106 -0
- package/src/api/location/index.ts +19 -0
- package/src/api/location/style.css +8 -8
- package/src/api/media/audio/index.ts +105 -0
- package/src/api/media/background-audio.ts +12 -0
- package/src/api/media/camera.ts +4 -0
- package/src/api/media/editor.ts +29 -0
- package/src/api/media/image/chooseImage.ts +78 -0
- package/src/api/media/image/getImageInfo.ts +35 -0
- package/src/api/media/image/index.ts +13 -0
- package/src/api/media/image/previewImage.ts +101 -0
- package/src/api/media/index.ts +13 -0
- package/src/api/media/live.ts +5 -0
- package/src/api/media/map.ts +4 -0
- package/src/api/media/media-recorder.ts +4 -0
- package/src/api/media/recorder.ts +6 -0
- package/src/api/media/video/index.ts +82 -0
- package/src/api/media/video-decoder.ts +4 -0
- package/src/api/media/video-processing.ts +4 -0
- package/src/api/media/voip.ts +17 -0
- package/src/api/navigate/index.ts +7 -0
- package/src/api/{fileTransfer/downloadFile.js → network/download.ts} +16 -27
- package/src/api/network/index.ts +7 -0
- package/src/api/network/mdns.ts +13 -0
- package/src/api/{request/index.js → network/request/index.ts} +9 -6
- package/src/api/network/tcp.ts +4 -0
- package/src/api/network/udp.ts +4 -0
- package/src/api/{fileTransfer/uploadFile.js → network/upload.ts} +28 -32
- package/src/api/{fileTransfer/utils.js → network/utils.ts} +0 -0
- package/src/api/network/websocket/index.ts +88 -0
- package/src/api/{webSocket/socketTask.js → network/websocket/socketTask.ts} +17 -7
- package/src/api/open-api/account.ts +4 -0
- package/src/api/open-api/address.ts +4 -0
- package/src/api/open-api/authorize.ts +5 -0
- package/src/api/open-api/card.ts +5 -0
- package/src/api/open-api/channels-live.ts +9 -0
- package/src/api/open-api/customer-service.ts +4 -0
- package/src/api/open-api/facial.ts +7 -0
- package/src/api/open-api/favorites.ts +5 -0
- package/src/api/open-api/group.ts +4 -0
- package/src/api/open-api/index.ts +18 -0
- package/src/api/open-api/invoice.ts +5 -0
- package/src/api/open-api/license-plate.ts +4 -0
- package/src/api/open-api/login.ts +6 -0
- package/src/api/open-api/red-package.ts +4 -0
- package/src/api/open-api/settings.ts +5 -0
- package/src/api/open-api/soter.ts +6 -0
- package/src/api/open-api/subscribe-message.ts +4 -0
- package/src/api/open-api/user-info.ts +5 -0
- package/src/api/open-api/werun.ts +5 -0
- package/src/api/payment/index.ts +5 -0
- package/src/api/route/index.ts +10 -0
- package/src/api/share/index.ts +13 -0
- package/src/api/storage/background-fetch.ts +7 -0
- package/src/api/storage/index.ts +181 -0
- package/src/api/swan/index.ts +31 -0
- package/src/{taro/index.js → api/taro.ts} +89 -149
- package/src/api/{createAnimation/index.js → ui/animation/index.ts} +51 -35
- package/src/api/ui/background.ts +5 -0
- package/src/api/ui/custom-component.ts +4 -0
- package/src/api/ui/fonts.ts +4 -0
- package/src/api/ui/index.ts +12 -0
- package/src/api/ui/interaction/actionSheet.ts +212 -0
- package/src/api/{interactive/index.js → ui/interaction/index.ts} +93 -77
- package/src/api/ui/interaction/modal.ts +237 -0
- package/src/api/{interactive/toast.js → ui/interaction/toast.ts} +35 -33
- package/src/api/ui/menu.ts +4 -0
- package/src/api/ui/navigation-bar/index.ts +52 -0
- package/src/api/ui/pull-down-refresh.ts +27 -0
- package/src/api/ui/scroll/index.ts +85 -0
- package/src/api/ui/sticky.ts +4 -0
- package/src/api/ui/tab-bar.ts +326 -0
- package/src/api/ui/window.ts +37 -0
- package/src/api/utils/handler.ts +105 -0
- package/src/api/utils/{index.js → index.ts} +36 -115
- package/src/api/worker/index.ts +4 -0
- package/src/api/wxml/index.ts +9 -0
- package/src/api/wxml/nodesRef.ts +49 -0
- package/src/api/{createSelectorQuery/index.js → wxml/selectorQuery.ts} +75 -94
- package/src/index.ts +6 -0
- package/src/types/api.d.ts +4 -0
- package/src/types/define.d.ts +2 -0
- package/{types → src/types}/index.d.ts +0 -0
- package/{types → src/types}/type.ts +1 -1
- package/src/api/accelerometer/index.js +0 -105
- package/src/api/audio/index.js +0 -137
- package/src/api/canvas/canvasGetImageData.js +0 -44
- package/src/api/canvas/canvasPutImageData.js +0 -45
- package/src/api/canvas/canvasToTempFilePath.js +0 -49
- package/src/api/canvas/createCanvasContext.js +0 -340
- package/src/api/canvas/index.js +0 -4
- package/src/api/clipboard/index.js +0 -113
- package/src/api/compass/index.js +0 -99
- package/src/api/deviceMotion/index.js +0 -105
- package/src/api/fileTransfer/index.js +0 -2
- package/src/api/image/chooseImage.js +0 -87
- package/src/api/image/getImageInfo.js +0 -74
- package/src/api/image/index.js +0 -7
- package/src/api/image/previewImage.js +0 -94
- package/src/api/index.js +0 -29
- package/src/api/interactive/actionSheet.js +0 -214
- package/src/api/interactive/modal.js +0 -256
- package/src/api/location/chooseLocation.js +0 -143
- package/src/api/location/index.js +0 -5
- package/src/api/navigationBar/index.js +0 -57
- package/src/api/open/index.js +0 -5
- package/src/api/others/index.js +0 -43
- package/src/api/pullDownRefresh/index.js +0 -51
- package/src/api/scroll/index.js +0 -99
- package/src/api/storage/index.js +0 -211
- package/src/api/system/index.js +0 -9
- package/src/api/system/info.js +0 -36
- package/src/api/system/network.js +0 -68
- package/src/api/tabBar/index.js +0 -402
- package/src/api/unsupportedApi/index.js +0 -278
- package/src/api/vibrate/index.js +0 -49
- package/src/api/video/index.js +0 -87
- package/src/api/webSocket/index.js +0 -103
- package/src/api/window/index.js +0 -38
- package/src/index.cjs.js +0 -11
- package/src/index.js +0 -6
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
type TCallback<T = Partial<TaroGeneral.CallbackResult>> = (res: T) => Promise<void> | void
|
|
2
|
+
interface IMethodParam<T = Partial<TaroGeneral.CallbackResult>> {
|
|
3
|
+
name: string
|
|
4
|
+
success?: TCallback<T>
|
|
5
|
+
fail?: TCallback
|
|
6
|
+
complete?: TCallback
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class MethodHandler<T = Partial<TaroGeneral.CallbackResult>> {
|
|
10
|
+
methodName: string
|
|
11
|
+
|
|
12
|
+
protected __success?: TCallback<T>
|
|
13
|
+
protected __fail?: TCallback
|
|
14
|
+
protected __complete?: TCallback
|
|
15
|
+
|
|
16
|
+
constructor ({ name, success, fail, complete }: IMethodParam<T>) {
|
|
17
|
+
this.methodName = name
|
|
18
|
+
this.__success = success
|
|
19
|
+
this.__fail = fail
|
|
20
|
+
this.__complete = complete
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
success<U = Record<string, unknown>> (res: Partial<T> & Partial<TaroGeneral.CallbackResult> = {}, resolve = Promise.resolve.bind(Promise)): Promise<T & U & TaroGeneral.CallbackResult> {
|
|
24
|
+
if (!res.errMsg) {
|
|
25
|
+
res.errMsg = `${this.methodName}:ok`
|
|
26
|
+
}
|
|
27
|
+
typeof this.__success === 'function' && this.__success(res as T)
|
|
28
|
+
typeof this.__complete === 'function' && this.__complete(res)
|
|
29
|
+
return resolve(res as Required<T & U & TaroGeneral.CallbackResult>)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
fail<U = Record<string, unknown>> (res: Partial<T> & Partial<TaroGeneral.CallbackResult> = {}, reject = Promise.reject.bind(Promise)): Promise<T & U & TaroGeneral.CallbackResult> {
|
|
33
|
+
if (!res.errMsg) {
|
|
34
|
+
res.errMsg = `${this.methodName}:fail`
|
|
35
|
+
} else {
|
|
36
|
+
res.errMsg = `${this.methodName}:fail ${res.errMsg}`
|
|
37
|
+
}
|
|
38
|
+
console.error(res.errMsg)
|
|
39
|
+
typeof this.__fail === 'function' && this.__fail(res)
|
|
40
|
+
typeof this.__complete === 'function' && this.__complete(res)
|
|
41
|
+
return reject(res)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
type TCallbackManagerParam = (...arr: unknown[]) => void
|
|
46
|
+
interface ICallbackManagerOption {
|
|
47
|
+
callback?: TCallbackManagerParam
|
|
48
|
+
ctx?: any
|
|
49
|
+
[key: string]: unknown
|
|
50
|
+
}
|
|
51
|
+
type TCallbackManagerListItem = (TCallbackManagerParam | ICallbackManagerOption)
|
|
52
|
+
type TCallbackManagerList = TCallbackManagerListItem[]
|
|
53
|
+
|
|
54
|
+
export class CallbackManager {
|
|
55
|
+
callbacks: TCallbackManagerList = []
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 添加回调
|
|
59
|
+
* @param {{ callback: function, ctx: any } | function} opt
|
|
60
|
+
*/
|
|
61
|
+
add (opt?: TCallbackManagerListItem) {
|
|
62
|
+
if (opt) this.callbacks.push(opt)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 移除回调
|
|
67
|
+
* @param {{ callback: function, ctx: any } | function} opt
|
|
68
|
+
*/
|
|
69
|
+
remove (opt?: TCallbackManagerListItem) {
|
|
70
|
+
if (opt) {
|
|
71
|
+
let pos = -1
|
|
72
|
+
this.callbacks.forEach((callback, k) => {
|
|
73
|
+
if (callback === opt) {
|
|
74
|
+
pos = k
|
|
75
|
+
}
|
|
76
|
+
})
|
|
77
|
+
if (pos > -1) {
|
|
78
|
+
this.callbacks.splice(pos, 1)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* 获取回调函数数量
|
|
85
|
+
* @return {number}
|
|
86
|
+
*/
|
|
87
|
+
count () {
|
|
88
|
+
return this.callbacks.length
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* 触发回调
|
|
93
|
+
* @param {...any} args 回调的调用参数
|
|
94
|
+
*/
|
|
95
|
+
trigger (...args: TCallbackManagerList) {
|
|
96
|
+
this.callbacks.forEach(opt => {
|
|
97
|
+
if (typeof opt === 'function') {
|
|
98
|
+
opt(...args)
|
|
99
|
+
} else {
|
|
100
|
+
const { callback, ctx } = opt
|
|
101
|
+
typeof callback === 'function' && callback.call(ctx, ...args)
|
|
102
|
+
}
|
|
103
|
+
})
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/* eslint-disable prefer-promise-reject-errors */
|
|
2
|
-
import { Current, container, SERVICE_IDENTIFIER } from '@tarojs/runtime'
|
|
2
|
+
import { Current, container, SERVICE_IDENTIFIER, IHooks, TaroElement } from '@tarojs/runtime'
|
|
3
3
|
|
|
4
|
-
function shouldBeObject (target) {
|
|
5
|
-
if (target && typeof target === 'object') return {
|
|
4
|
+
export function shouldBeObject (target: unknown) {
|
|
5
|
+
if (target && typeof target === 'object') return { flag: true }
|
|
6
6
|
return {
|
|
7
|
-
|
|
7
|
+
flag: false,
|
|
8
8
|
msg: getParameterError({
|
|
9
9
|
correct: 'Object',
|
|
10
10
|
wrong: target
|
|
@@ -12,8 +12,8 @@ function shouldBeObject (target) {
|
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export function findDOM (inst) {
|
|
16
|
-
const runtimeHooks = container.get(SERVICE_IDENTIFIER.Hooks)
|
|
15
|
+
export function findDOM (inst): TaroElement | HTMLElement | undefined {
|
|
16
|
+
const runtimeHooks = container.get<IHooks>(SERVICE_IDENTIFIER.Hooks)
|
|
17
17
|
|
|
18
18
|
if (inst) {
|
|
19
19
|
const find = runtimeHooks.getDOMNode
|
|
@@ -23,7 +23,7 @@ export function findDOM (inst) {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
const page = Current.page
|
|
26
|
-
const path = page
|
|
26
|
+
const path = page?.path
|
|
27
27
|
const msg = '没有找到已经加载了的页面,请在页面加载完成后时候此 API。'
|
|
28
28
|
if (path == null) {
|
|
29
29
|
throw new Error(msg)
|
|
@@ -37,10 +37,20 @@ export function findDOM (inst) {
|
|
|
37
37
|
return el
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
interface IParameterErrorParam {
|
|
41
|
+
name?: string
|
|
42
|
+
para?: string
|
|
43
|
+
correct?: string
|
|
44
|
+
wrong?: unknown
|
|
45
|
+
}
|
|
46
|
+
export function getParameterError ({ name = '', para, correct, wrong }: IParameterErrorParam) {
|
|
41
47
|
const parameter = para ? `parameter.${para}` : 'parameter'
|
|
42
48
|
const errorType = upperCaseFirstLetter(wrong === null ? 'Null' : typeof wrong)
|
|
43
|
-
|
|
49
|
+
if (name) {
|
|
50
|
+
return `${name}:fail parameter error: ${parameter} should be ${correct} instead of ${errorType}`
|
|
51
|
+
} else {
|
|
52
|
+
return `parameter error: ${parameter} should be ${correct} instead of ${errorType}`
|
|
53
|
+
}
|
|
44
54
|
}
|
|
45
55
|
|
|
46
56
|
function upperCaseFirstLetter (string) {
|
|
@@ -49,7 +59,7 @@ function upperCaseFirstLetter (string) {
|
|
|
49
59
|
return string
|
|
50
60
|
}
|
|
51
61
|
|
|
52
|
-
function inlineStyle (style) {
|
|
62
|
+
export function inlineStyle (style) {
|
|
53
63
|
let res = ''
|
|
54
64
|
for (const attr in style) res += `${attr}: ${style[attr]};`
|
|
55
65
|
if (res.indexOf('display: flex;') >= 0) res += 'display: -webkit-box;display: -webkit-flex;'
|
|
@@ -58,32 +68,12 @@ function inlineStyle (style) {
|
|
|
58
68
|
return res
|
|
59
69
|
}
|
|
60
70
|
|
|
61
|
-
function setTransform (el, val) {
|
|
71
|
+
export function setTransform (el, val) {
|
|
62
72
|
el.style.webkitTransform = val
|
|
63
73
|
el.style.transform = val
|
|
64
74
|
}
|
|
65
75
|
|
|
66
|
-
function
|
|
67
|
-
return typeof obj === 'function'
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function successHandler (success, complete) {
|
|
71
|
-
return function (res) {
|
|
72
|
-
isFunction(success) && success(res)
|
|
73
|
-
isFunction(complete) && complete(res)
|
|
74
|
-
return Promise.resolve(res)
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function errorHandler (fail, complete) {
|
|
79
|
-
return function (res) {
|
|
80
|
-
isFunction(fail) && fail(res)
|
|
81
|
-
isFunction(complete) && complete(res)
|
|
82
|
-
return Promise.reject(res)
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function serializeParams (params) {
|
|
76
|
+
export function serializeParams (params) {
|
|
87
77
|
if (!params) {
|
|
88
78
|
return ''
|
|
89
79
|
}
|
|
@@ -95,7 +85,7 @@ function serializeParams (params) {
|
|
|
95
85
|
.join('&')
|
|
96
86
|
}
|
|
97
87
|
|
|
98
|
-
function temporarilyNotSupport (apiName) {
|
|
88
|
+
export function temporarilyNotSupport (apiName) {
|
|
99
89
|
return () => {
|
|
100
90
|
const errMsg = `暂时不支持 API ${apiName}`
|
|
101
91
|
console.error(errMsg)
|
|
@@ -105,7 +95,7 @@ function temporarilyNotSupport (apiName) {
|
|
|
105
95
|
}
|
|
106
96
|
}
|
|
107
97
|
|
|
108
|
-
function weixinCorpSupport (apiName) {
|
|
98
|
+
export function weixinCorpSupport (apiName) {
|
|
109
99
|
return () => {
|
|
110
100
|
const errMsg = `h5端仅在微信公众号中支持 API ${apiName}`
|
|
111
101
|
console.error(errMsg)
|
|
@@ -115,7 +105,7 @@ function weixinCorpSupport (apiName) {
|
|
|
115
105
|
}
|
|
116
106
|
}
|
|
117
107
|
|
|
118
|
-
function permanentlyNotSupport (apiName) {
|
|
108
|
+
export function permanentlyNotSupport (apiName) {
|
|
119
109
|
return () => {
|
|
120
110
|
const errMsg = `不支持 API ${apiName}`
|
|
121
111
|
console.error(errMsg)
|
|
@@ -125,69 +115,18 @@ function permanentlyNotSupport (apiName) {
|
|
|
125
115
|
}
|
|
126
116
|
}
|
|
127
117
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
const isValidColor = (color) => {
|
|
131
|
-
return VALID_COLOR_REG.test(color)
|
|
118
|
+
export function isFunction (obj) {
|
|
119
|
+
return typeof obj === 'function'
|
|
132
120
|
}
|
|
133
121
|
|
|
134
|
-
const
|
|
135
|
-
const callbacks = []
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* 添加回调
|
|
139
|
-
* @param {{ callback: function, ctx: any } | function} opt
|
|
140
|
-
*/
|
|
141
|
-
const add = (opt) => {
|
|
142
|
-
callbacks.push(opt)
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* 移除回调
|
|
147
|
-
* @param {{ callback: function, ctx: any } | function} opt
|
|
148
|
-
*/
|
|
149
|
-
const remove = (opt) => {
|
|
150
|
-
let pos = -1
|
|
151
|
-
callbacks.forEach((callback, k) => {
|
|
152
|
-
if (callback === opt) {
|
|
153
|
-
pos = k
|
|
154
|
-
}
|
|
155
|
-
})
|
|
156
|
-
if (pos > -1) {
|
|
157
|
-
callbacks.splice(pos, 1)
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* 获取回调函数数量
|
|
163
|
-
* @return {number}
|
|
164
|
-
*/
|
|
165
|
-
const count = () => callbacks.length
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* 触发回调
|
|
169
|
-
* @param {...any} args 回调的调用参数
|
|
170
|
-
*/
|
|
171
|
-
const trigger = (...args) => {
|
|
172
|
-
callbacks.forEach(opt => {
|
|
173
|
-
if (typeof opt === 'function') {
|
|
174
|
-
opt(...args)
|
|
175
|
-
} else {
|
|
176
|
-
const { callback, ctx } = opt
|
|
177
|
-
callback.call(ctx, ...args)
|
|
178
|
-
}
|
|
179
|
-
})
|
|
180
|
-
}
|
|
122
|
+
const VALID_COLOR_REG = /^#[0-9a-fA-F]{6}$/
|
|
181
123
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
remove,
|
|
185
|
-
count,
|
|
186
|
-
trigger
|
|
187
|
-
}
|
|
124
|
+
export const isValidColor = (color) => {
|
|
125
|
+
return VALID_COLOR_REG.test(color)
|
|
188
126
|
}
|
|
189
127
|
|
|
190
|
-
function
|
|
128
|
+
export function processOpenApi (apiName: string, defaultOptions?: Record<string, unknown>, formatResult = res => res, formatParams = options => options) {
|
|
129
|
+
// @ts-ignore
|
|
191
130
|
if (!window.wx) {
|
|
192
131
|
return weixinCorpSupport(apiName)
|
|
193
132
|
}
|
|
@@ -206,6 +145,7 @@ function processOpenapi (apiName, defaultOptions, formatResult = res => res, for
|
|
|
206
145
|
}
|
|
207
146
|
}
|
|
208
147
|
})
|
|
148
|
+
// @ts-ignore
|
|
209
149
|
wx[apiName](formatParams(obj))
|
|
210
150
|
})
|
|
211
151
|
return p
|
|
@@ -214,11 +154,11 @@ function processOpenapi (apiName, defaultOptions, formatResult = res => res, for
|
|
|
214
154
|
|
|
215
155
|
/**
|
|
216
156
|
* ease-in-out的函数
|
|
217
|
-
* @param
|
|
157
|
+
* @param t 0-1的数字
|
|
218
158
|
*/
|
|
219
|
-
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
|
|
220
160
|
|
|
221
|
-
const getTimingFunc = (easeFunc, frameCnt) => {
|
|
161
|
+
export const getTimingFunc = (easeFunc, frameCnt) => {
|
|
222
162
|
return x => {
|
|
223
163
|
if (frameCnt <= 1) {
|
|
224
164
|
return easeFunc(1)
|
|
@@ -227,22 +167,3 @@ const getTimingFunc = (easeFunc, frameCnt) => {
|
|
|
227
167
|
return easeFunc(t)
|
|
228
168
|
}
|
|
229
169
|
}
|
|
230
|
-
|
|
231
|
-
export {
|
|
232
|
-
shouldBeObject,
|
|
233
|
-
getParameterError,
|
|
234
|
-
inlineStyle,
|
|
235
|
-
setTransform,
|
|
236
|
-
successHandler,
|
|
237
|
-
errorHandler,
|
|
238
|
-
serializeParams,
|
|
239
|
-
temporarilyNotSupport,
|
|
240
|
-
weixinCorpSupport,
|
|
241
|
-
permanentlyNotSupport,
|
|
242
|
-
isValidColor,
|
|
243
|
-
isFunction,
|
|
244
|
-
createCallbackManager,
|
|
245
|
-
processOpenapi,
|
|
246
|
-
easeInOut,
|
|
247
|
-
getTimingFunc
|
|
248
|
-
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import Taro from '@tarojs/api'
|
|
2
|
+
import { temporarilyNotSupport } from '../utils'
|
|
3
|
+
import { SelectorQuery } from './selectorQuery'
|
|
4
|
+
|
|
5
|
+
export const createSelectorQuery: typeof Taro.createSelectorQuery = () => {
|
|
6
|
+
return new SelectorQuery()
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const createIntersectionObserver = temporarilyNotSupport('createIntersectionObserver')
|
|
@@ -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
|
+
}
|
|
@@ -1,58 +1,25 @@
|
|
|
1
|
+
import Taro from '@tarojs/api'
|
|
1
2
|
import { findDOM } from '../utils'
|
|
3
|
+
import { NodesRef } from './nodesRef'
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
* WXML节点信息API
|
|
5
|
-
* @return {Object} SelectorQuery 对象实例
|
|
6
|
-
*/
|
|
7
|
-
function queryBat (queue, cb) {
|
|
8
|
-
const res = []
|
|
9
|
-
|
|
10
|
-
queue.forEach(item => {
|
|
11
|
-
const { selector, single, fields, component } = item
|
|
12
|
-
// selector 的容器节点
|
|
13
|
-
/* eslint-disable */
|
|
14
|
-
const container = (
|
|
15
|
-
component !== null ?
|
|
16
|
-
(findDOM(component) || document) :
|
|
17
|
-
document
|
|
18
|
-
)
|
|
19
|
-
/* eslint-enable */
|
|
20
|
-
|
|
21
|
-
// 特殊处理 ---- 选自己
|
|
22
|
-
let selectSelf = false
|
|
23
|
-
if (container !== document) {
|
|
24
|
-
const $nodeList = container.parentNode.querySelectorAll(selector)
|
|
25
|
-
for (let i = 0, len = $nodeList.length; i < len; ++i) {
|
|
26
|
-
if (container === $nodeList[i]) {
|
|
27
|
-
selectSelf = true
|
|
28
|
-
break
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
5
|
+
type TElement = Document | HTMLElement | Element
|
|
32
6
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const children = []
|
|
39
|
-
selectSelf === true && children.push(container)
|
|
40
|
-
for (let i = 0, len = $children.length; i < len; ++i) {
|
|
41
|
-
children.push($children[i])
|
|
42
|
-
}
|
|
43
|
-
res.push(children.map(dom => filter(fields, dom)))
|
|
44
|
-
}
|
|
45
|
-
})
|
|
46
|
-
cb(res)
|
|
7
|
+
interface ISelectorQueryQueue {
|
|
8
|
+
component: TaroGeneral.IAnyObject
|
|
9
|
+
selector: string
|
|
10
|
+
single: boolean
|
|
11
|
+
fields
|
|
47
12
|
}
|
|
48
13
|
|
|
49
|
-
|
|
14
|
+
type TSelectorQueryQueueCallback = (res: ISelectorQueryQueue) => void
|
|
15
|
+
|
|
16
|
+
function filter (fields, dom?: HTMLElement, selector?: string) {
|
|
50
17
|
if (!dom) return null
|
|
51
18
|
|
|
52
19
|
const { id, dataset, rect, size, scrollOffset, properties = [], computedStyle = [] } = fields
|
|
53
20
|
const { left, right, top, bottom, width, height } = dom.getBoundingClientRect()
|
|
54
21
|
const isViewport = selector === 'html'
|
|
55
|
-
const res = {}
|
|
22
|
+
const res: any = {}
|
|
56
23
|
|
|
57
24
|
if (id) res.id = dom.id
|
|
58
25
|
if (dataset) res.dataset = Object.assign({}, dom.dataset)
|
|
@@ -99,27 +66,81 @@ function filter (fields, dom, selector) {
|
|
|
99
66
|
return res
|
|
100
67
|
}
|
|
101
68
|
|
|
102
|
-
|
|
69
|
+
/**
|
|
70
|
+
* WXML节点信息API
|
|
71
|
+
* @return {Object} SelectorQuery 对象实例
|
|
72
|
+
*/
|
|
73
|
+
function queryBat (queue: ISelectorQueryQueue[], cb: (...args: any[]) => any): void {
|
|
74
|
+
const result: any[] = []
|
|
75
|
+
|
|
76
|
+
queue.forEach(item => {
|
|
77
|
+
const { selector, single, fields, component } = item
|
|
78
|
+
// selector 的容器节点
|
|
79
|
+
/* eslint-disable */
|
|
80
|
+
const container: TElement = (
|
|
81
|
+
component !== null ?
|
|
82
|
+
(findDOM(component) as HTMLElement || document) :
|
|
83
|
+
document
|
|
84
|
+
)
|
|
85
|
+
/* eslint-enable */
|
|
86
|
+
|
|
87
|
+
// 特殊处理 ---- 选自己
|
|
88
|
+
let selectSelf = false
|
|
89
|
+
if (container !== document) {
|
|
90
|
+
const $nodeList = container.parentNode?.querySelectorAll(selector)
|
|
91
|
+
if ($nodeList) {
|
|
92
|
+
for (let i = 0, len = $nodeList.length; i < len; ++i) {
|
|
93
|
+
if (container === $nodeList[i]) {
|
|
94
|
+
selectSelf = true
|
|
95
|
+
break
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (single) {
|
|
102
|
+
const el = selectSelf === true ? container : container.querySelector(selector)
|
|
103
|
+
result.push(filter(fields, el as HTMLElement, selector))
|
|
104
|
+
} else {
|
|
105
|
+
const $children = container.querySelectorAll(selector)
|
|
106
|
+
const children: TElement[] = []
|
|
107
|
+
selectSelf === true && children.push(container)
|
|
108
|
+
for (let i = 0, len = $children.length; i < len; ++i) {
|
|
109
|
+
children.push($children[i])
|
|
110
|
+
}
|
|
111
|
+
result.push(children.map(dom => filter(fields, dom as HTMLElement)))
|
|
112
|
+
}
|
|
113
|
+
})
|
|
114
|
+
cb(result)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export class SelectorQuery implements Taro.SelectorQuery {
|
|
118
|
+
_defaultWebviewId: string | null
|
|
119
|
+
_webviewId: string | null
|
|
120
|
+
_queue: ISelectorQueryQueue[]
|
|
121
|
+
_queueCb: (TSelectorQueryQueueCallback | null)[]
|
|
122
|
+
_component?: TaroGeneral.IAnyObject
|
|
123
|
+
|
|
103
124
|
constructor () {
|
|
104
125
|
this._defaultWebviewId = null
|
|
105
126
|
this._webviewId = null
|
|
106
127
|
this._queue = []
|
|
107
128
|
this._queueCb = []
|
|
108
|
-
this._component
|
|
129
|
+
this._component
|
|
109
130
|
}
|
|
110
131
|
|
|
111
|
-
in (component) {
|
|
132
|
+
in (component: TaroGeneral.IAnyObject) {
|
|
112
133
|
this._component = component
|
|
113
134
|
return this
|
|
114
135
|
}
|
|
115
136
|
|
|
116
|
-
select (selector) {
|
|
137
|
+
select (selector: string) {
|
|
117
138
|
// 小程序里跨自定义组件的后代选择器 '>>>' 在 h5 替换为普通后代选择器 '>'
|
|
118
139
|
if (typeof selector === 'string') selector = selector.replace('>>>', '>')
|
|
119
140
|
return new NodesRef(selector, this, true)
|
|
120
141
|
}
|
|
121
142
|
|
|
122
|
-
selectAll (selector) {
|
|
143
|
+
selectAll (selector: string) {
|
|
123
144
|
// 小程序里跨自定义组件的后代选择器 '>>>' 在 h5 替换为普通后代选择器 '>'
|
|
124
145
|
if (typeof selector === 'string') selector = selector.replace('>>>', '>')
|
|
125
146
|
return new NodesRef(selector, this, false)
|
|
@@ -133,13 +154,15 @@ class Query {
|
|
|
133
154
|
queryBat(this._queue, res => {
|
|
134
155
|
const _queueCb = this._queueCb
|
|
135
156
|
res.forEach((item, index) => {
|
|
136
|
-
|
|
157
|
+
const cb = _queueCb[index]
|
|
158
|
+
typeof cb === 'function' && cb.call(this, item)
|
|
137
159
|
})
|
|
138
160
|
typeof cb === 'function' && cb.call(this, res)
|
|
139
161
|
})
|
|
162
|
+
return this as unknown as Taro.NodesRef
|
|
140
163
|
}
|
|
141
164
|
|
|
142
|
-
_push (selector, component, single, fields, callback = null) {
|
|
165
|
+
_push (selector: string, component, single, fields, callback: TSelectorQueryQueueCallback | null = null) {
|
|
143
166
|
this._queue.push({
|
|
144
167
|
component,
|
|
145
168
|
selector,
|
|
@@ -149,45 +172,3 @@ class Query {
|
|
|
149
172
|
this._queueCb.push(callback)
|
|
150
173
|
}
|
|
151
174
|
}
|
|
152
|
-
|
|
153
|
-
class NodesRef {
|
|
154
|
-
constructor (selector, querySelectorQuery, single) {
|
|
155
|
-
this._component = querySelectorQuery._component
|
|
156
|
-
this._selector = selector
|
|
157
|
-
this._selectorQuery = querySelectorQuery
|
|
158
|
-
this._single = single
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
boundingClientRect (cb) {
|
|
162
|
-
const { _selector, _component, _single, _selectorQuery } = this
|
|
163
|
-
_selectorQuery._push(_selector, _component, _single, { id: !0, dataset: !0, rect: !0, size: !0 }, cb)
|
|
164
|
-
return _selectorQuery
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
scrollOffset (cb) {
|
|
168
|
-
const { _selector, _component, _single, _selectorQuery } = this
|
|
169
|
-
_selectorQuery._push(_selector, _component, _single, { id: !0, dataset: !0, scrollOffset: !0 }, cb)
|
|
170
|
-
return _selectorQuery
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
fields (fields, cb) {
|
|
174
|
-
const { _selector, _component, _single, _selectorQuery } = this
|
|
175
|
-
const { id, dataset, rect, size, scrollOffset, properties = [], computedStyle = [] } = fields
|
|
176
|
-
|
|
177
|
-
_selectorQuery._push(_selector, _component, _single, {
|
|
178
|
-
id,
|
|
179
|
-
dataset,
|
|
180
|
-
rect,
|
|
181
|
-
size,
|
|
182
|
-
scrollOffset,
|
|
183
|
-
properties,
|
|
184
|
-
computedStyle
|
|
185
|
-
}, cb)
|
|
186
|
-
|
|
187
|
-
return _selectorQuery
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
export function createSelectorQuery () {
|
|
192
|
-
return new Query()
|
|
193
|
-
}
|
package/src/index.ts
ADDED
|
File without changes
|