@tarojs/plugin-platform-harmony-cpp 4.1.0 → 4.1.1-alpha.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/README.md +0 -7
- package/dist/index.js +1236 -0
- package/dist/runtime/apis/apis.ts +20 -0
- package/dist/runtime/apis/base/crypto.ts +4 -0
- package/dist/runtime/apis/base/debug.ts +5 -0
- package/dist/runtime/apis/base/index.ts +13 -0
- package/dist/runtime/apis/base/performance.ts +8 -0
- package/dist/runtime/apis/base/system.ts +181 -0
- package/dist/runtime/apis/base/update.ts +5 -0
- package/dist/runtime/apis/base/weapp/app-event.ts +75 -0
- package/dist/runtime/apis/base/weapp/life-cycle.ts +21 -0
- package/dist/runtime/apis/canvas/index.ts +27 -0
- package/dist/runtime/apis/data-analysis/index.ts +6 -0
- package/dist/runtime/apis/device/accelerometer.ts +79 -0
- package/dist/runtime/apis/device/accessibility.ts +4 -0
- package/dist/runtime/apis/device/battery.ts +24 -0
- package/dist/runtime/apis/device/bluetooth-ble.ts +19 -0
- package/dist/runtime/apis/device/bluetooth-peripheral.ts +6 -0
- package/dist/runtime/apis/device/bluetooth.ts +16 -0
- package/dist/runtime/apis/device/calendar.ts +5 -0
- package/dist/runtime/apis/device/clipboard.ts +85 -0
- package/dist/runtime/apis/device/compass.ts +21 -0
- package/dist/runtime/apis/device/contact.ts +5 -0
- package/dist/runtime/apis/device/crypto.ts +4 -0
- package/dist/runtime/apis/device/gyroscope.ts +77 -0
- package/dist/runtime/apis/device/iBeacon.ts +10 -0
- package/dist/runtime/apis/device/index.ts +24 -0
- package/dist/runtime/apis/device/keyboard.ts +63 -0
- package/dist/runtime/apis/device/memory.ts +11 -0
- package/dist/runtime/apis/device/motion.ts +6 -0
- package/dist/runtime/apis/device/network.ts +123 -0
- package/dist/runtime/apis/device/nfc.ts +10 -0
- package/dist/runtime/apis/device/phone.ts +44 -0
- package/dist/runtime/apis/device/scan.ts +4 -0
- package/dist/runtime/apis/device/screen.ts +80 -0
- package/dist/runtime/apis/device/sms.ts +4 -0
- package/dist/runtime/apis/device/vibrate.ts +32 -0
- package/dist/runtime/apis/device/wifi.ts +15 -0
- package/dist/runtime/apis/ext/index.ts +5 -0
- package/dist/runtime/apis/files/index.ts +136 -0
- package/dist/runtime/apis/files/manager.ts +942 -0
- package/dist/runtime/apis/framework/index.ts +48 -0
- package/dist/runtime/apis/harmony/task-pool.ts +39 -0
- package/dist/runtime/apis/index.ts +61 -0
- package/dist/runtime/apis/location/index.ts +133 -0
- package/dist/runtime/apis/media/EditorContext.ts +32 -0
- package/dist/runtime/apis/media/audio/index.ts +36 -0
- package/dist/runtime/apis/media/background-audio/index.ts +16 -0
- package/dist/runtime/apis/media/camera.ts +16 -0
- package/dist/runtime/apis/media/common.ts +58 -0
- package/dist/runtime/apis/media/image/index.ts +291 -0
- package/dist/runtime/apis/media/index.ts +13 -0
- package/dist/runtime/apis/media/live.ts +5 -0
- package/dist/runtime/apis/media/map.ts +4 -0
- package/dist/runtime/apis/media/media-recorder.ts +4 -0
- package/dist/runtime/apis/media/recorder.ts +6 -0
- package/dist/runtime/apis/media/video/VideoContext.ts +67 -0
- package/dist/runtime/apis/media/video/index.ts +45 -0
- package/dist/runtime/apis/media/video-decoder.ts +4 -0
- package/dist/runtime/apis/media/video-processing.ts +4 -0
- package/dist/runtime/apis/media/voip.ts +19 -0
- package/dist/runtime/apis/navigate/index.ts +8 -0
- package/dist/runtime/apis/network/downloadFile.ts +85 -0
- package/dist/runtime/apis/network/index.ts +7 -0
- package/dist/runtime/apis/network/mdns.ts +13 -0
- package/dist/runtime/apis/network/request.ts +140 -0
- package/dist/runtime/apis/network/tcp.ts +4 -0
- package/dist/runtime/apis/network/udp.ts +4 -0
- package/dist/runtime/apis/network/uploadFile.ts +105 -0
- package/dist/runtime/apis/network/webSocket.ts +126 -0
- package/dist/runtime/apis/open-api/account.ts +4 -0
- package/dist/runtime/apis/open-api/address.ts +4 -0
- package/dist/runtime/apis/open-api/authorize.ts +5 -0
- package/dist/runtime/apis/open-api/card.ts +5 -0
- package/dist/runtime/apis/open-api/channels-live.ts +11 -0
- package/dist/runtime/apis/open-api/customer-service.ts +4 -0
- package/dist/runtime/apis/open-api/device-voip.ts +5 -0
- package/dist/runtime/apis/open-api/facial.ts +7 -0
- package/dist/runtime/apis/open-api/favorites.ts +5 -0
- package/dist/runtime/apis/open-api/group.ts +4 -0
- package/dist/runtime/apis/open-api/index.ts +21 -0
- package/dist/runtime/apis/open-api/invoice.ts +5 -0
- package/dist/runtime/apis/open-api/license-plate.ts +4 -0
- package/dist/runtime/apis/open-api/login.ts +6 -0
- package/dist/runtime/apis/open-api/my-miniprogram.ts +4 -0
- package/dist/runtime/apis/open-api/privacy.ts +7 -0
- package/dist/runtime/apis/open-api/red-package.ts +4 -0
- package/dist/runtime/apis/open-api/settings.ts +5 -0
- package/dist/runtime/apis/open-api/soter.ts +6 -0
- package/dist/runtime/apis/open-api/subscribe-message.ts +6 -0
- package/dist/runtime/apis/open-api/user-info.ts +70 -0
- package/dist/runtime/apis/open-api/werun.ts +5 -0
- package/dist/runtime/apis/payment/index.ts +6 -0
- package/dist/runtime/apis/route/index.ts +88 -0
- package/dist/runtime/apis/share/index.ts +33 -0
- package/dist/runtime/apis/storage/background-fetch.ts +7 -0
- package/dist/runtime/apis/storage/cache-manager.ts +4 -0
- package/dist/runtime/apis/storage/index.ts +203 -0
- package/dist/runtime/apis/ui/animation/animation.ts +264 -0
- package/dist/runtime/apis/ui/animation/index.ts +7 -0
- package/dist/runtime/apis/ui/background.ts +20 -0
- package/dist/runtime/apis/ui/custom-component.ts +1 -0
- package/dist/runtime/apis/ui/fonts.ts +4 -0
- package/dist/runtime/apis/ui/index.ts +12 -0
- package/dist/runtime/apis/ui/interaction/index.ts +198 -0
- package/dist/runtime/apis/ui/menu.ts +4 -0
- package/dist/runtime/apis/ui/navigation-bar/index.ts +72 -0
- package/dist/runtime/apis/ui/pull-down-refresh.ts +47 -0
- package/dist/runtime/apis/ui/scroll/index.ts +82 -0
- package/dist/runtime/apis/ui/sticky.ts +4 -0
- package/dist/runtime/apis/ui/tab-bar.ts +144 -0
- package/dist/runtime/apis/ui/window.ts +20 -0
- package/dist/runtime/apis/utils/constant.ts +1 -0
- package/dist/runtime/apis/utils/handler.ts +117 -0
- package/dist/runtime/apis/utils/index.ts +105 -0
- package/dist/runtime/apis/utils/permissions.ts +6 -0
- package/dist/runtime/apis/utils/types.ts +12 -0
- package/dist/runtime/apis/utils/unit.ts +104 -0
- package/dist/runtime/apis/utils/validate.ts +87 -0
- package/dist/runtime/apis/worker/index.ts +4 -0
- package/dist/runtime/apis/wxml/index.ts +17 -0
- package/dist/runtime/apis/wxml/intersectionObserver.ts +100 -0
- package/dist/runtime/apis/wxml/nodesRef.ts +58 -0
- package/dist/runtime/apis/wxml/selectorQuery.ts +221 -0
- package/dist/runtime/apischunk/index.d.ts +802 -0
- package/dist/runtime/apischunk/index.js +5054 -0
- package/dist/runtime/components/deprecated.ets +43 -0
- package/dist/runtime/components/index.ets +49 -0
- package/dist/runtime/components/innerHtml.ets +16 -0
- package/dist/runtime/components/navigationBar.ets +65 -0
- package/dist/runtime/components/pageMeta.ets +94 -0
- package/dist/runtime/components/richText.ets +24 -0
- package/dist/runtime/components/slider.ets +119 -0
- package/dist/runtime/components/style.ets +286 -0
- package/dist/runtime/components/switch.ets +73 -0
- package/dist/runtime/components/tag.ts +58 -0
- package/dist/runtime/components/utils/AttributeManager.ets +252 -0
- package/dist/runtime/components/utils/DynamicCenter.ts +41 -0
- package/dist/runtime/components/utils/constant/event.ets +25 -0
- package/dist/runtime/components/utils/constant/style.ets +91 -0
- package/dist/runtime/components/utils/events.ts +26 -0
- package/dist/runtime/components/utils/flexManager.ets +49 -0
- package/dist/runtime/components/utils/helper.ets +51 -0
- package/dist/runtime/components/utils/htmlParser/HarmonyHTMLParser.ts +100 -0
- package/dist/runtime/components/utils/htmlParser/index.ts +58 -0
- package/dist/runtime/components/utils/index.ts +77 -0
- package/dist/runtime/components/utils/styles.ets +41 -0
- package/dist/runtime/components/video.ets +119 -0
- package/dist/runtime/components/webView.ets +55 -0
- package/dist/runtime/components/xComponent.ets +89 -0
- package/dist/runtime/framework/app.ts +248 -0
- package/dist/runtime/framework/connect.ts +24 -0
- package/dist/runtime/framework/constant.ts +3 -0
- package/dist/runtime/framework/hooks.ts +99 -0
- package/dist/runtime/framework/index.ts +15 -0
- package/dist/runtime/framework/native-page.ts +511 -0
- package/dist/runtime/framework/page.ts +256 -0
- package/dist/runtime/framework/utils/index.ts +17 -0
- package/dist/runtime/framework/utils/is.ts +26 -0
- package/dist/runtime/framework-reconciler/componentTree.ts +81 -0
- package/dist/runtime/framework-reconciler/constant.ts +86 -0
- package/dist/runtime/framework-reconciler/domInput.ts +90 -0
- package/dist/runtime/framework-reconciler/event.ts +108 -0
- package/dist/runtime/framework-reconciler/index.ts +99 -0
- package/dist/runtime/framework-reconciler/inputValueTracking.ts +106 -0
- package/dist/runtime/framework-reconciler/props.ts +132 -0
- package/dist/runtime/framework-reconciler/reconciler.ts +202 -0
- package/dist/runtime/framework-reconciler/render.ts +139 -0
- package/dist/runtime/framework-reconciler/workTags.ts +53 -0
- package/dist/runtime/runtime-cpp/bom/URL.ts +2 -0
- package/dist/runtime/runtime-cpp/bom/document.ts +45 -0
- package/dist/runtime/runtime-cpp/bom/history.ts +1 -0
- package/dist/runtime/runtime-cpp/bom/location.ts +1 -0
- package/dist/runtime/runtime-cpp/bom/navigator.ts +1 -0
- package/dist/runtime/runtime-cpp/bom/raf.ts +1 -0
- package/dist/runtime/runtime-cpp/bom/window.ts +57 -0
- package/dist/runtime/runtime-cpp/constant.ts +29 -0
- package/dist/runtime/runtime-cpp/current.ts +48 -0
- package/dist/runtime/runtime-cpp/dom/class-list.ts +41 -0
- package/dist/runtime/runtime-cpp/dom/comment.ts +9 -0
- package/dist/runtime/runtime-cpp/dom/dataSource.ts +87 -0
- package/dist/runtime/runtime-cpp/dom/document.ts +113 -0
- package/dist/runtime/runtime-cpp/dom/element/canvas.ts +285 -0
- package/dist/runtime/runtime-cpp/dom/element/element.ts +262 -0
- package/dist/runtime/runtime-cpp/dom/element/form.ts +371 -0
- package/dist/runtime/runtime-cpp/dom/element/index.ts +129 -0
- package/dist/runtime/runtime-cpp/dom/element/movable.ts +250 -0
- package/dist/runtime/runtime-cpp/dom/element/normal.ts +123 -0
- package/dist/runtime/runtime-cpp/dom/element/scroll_view.ts +32 -0
- package/dist/runtime/runtime-cpp/dom/element/text.ts +9 -0
- package/dist/runtime/runtime-cpp/dom/element/video.ts +66 -0
- package/dist/runtime/runtime-cpp/dom/element/web_view.ts +72 -0
- package/dist/runtime/runtime-cpp/dom/event-source.ts +1 -0
- package/dist/runtime/runtime-cpp/dom/event.ts +187 -0
- package/dist/runtime/runtime-cpp/dom/eventTarget.ts +81 -0
- package/dist/runtime/runtime-cpp/dom/node.ts +307 -0
- package/dist/runtime/runtime-cpp/dom/style.ts +44 -0
- package/dist/runtime/runtime-cpp/dom/stylesheet/index.ts +379 -0
- package/dist/runtime/runtime-cpp/dom/stylesheet/type.ts +212 -0
- package/dist/runtime/runtime-cpp/dom/stylesheet/util.ts +186 -0
- package/dist/runtime/runtime-cpp/emitter/emitter.ts +29 -0
- package/dist/runtime/runtime-cpp/env.ts +1 -0
- package/dist/runtime/runtime-cpp/harmony-library.ts +1 -0
- package/dist/runtime/runtime-cpp/index.ts +79 -0
- package/dist/runtime/runtime-cpp/interface/event.ts +10 -0
- package/dist/runtime/runtime-cpp/interface/index.ts +7 -0
- package/dist/runtime/runtime-cpp/next-tick.ts +14 -0
- package/dist/runtime/runtime-cpp/system.ts +213 -0
- package/dist/runtime/runtime-cpp/utils/index.ts +63 -0
- package/dist/runtime/runtime-cpp/utils/info.ts +123 -0
- package/dist/runtime/runtime-cpp/utils/page.ts +12 -0
- package/dist/runtime/runtime-cpp/utils/router.ts +1 -0
- package/dist/runtime/runtime-harmony/apis/helper.ets +33 -0
- package/dist/runtime/runtime-harmony/apis/network/common.ets +41 -0
- package/dist/runtime/runtime-harmony/apis/network/downloadFile.ets +327 -0
- package/dist/runtime/runtime-harmony/apis/network/index.ets +58 -0
- package/dist/runtime/runtime-harmony/apis/network/request.ets +206 -0
- package/dist/runtime/runtime-harmony/apis/network/uploadFile.ets +190 -0
- package/dist/runtime/runtime-harmony/apis/route.ets +110 -0
- package/dist/runtime/runtime-harmony/apis/taskpool.ets +149 -0
- package/dist/runtime/runtime-harmony/index.ets +41 -0
- package/dist/runtime/runtime-harmony/utils.ts +53 -0
- package/package.json +25 -23
- package/static/@taro-oh/library-4.1.1-alpha.0.har +0 -0
- package/LICENSE +0 -174
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import abilityAccessCtrl from '@ohos.abilityAccessCtrl'
|
|
2
|
+
import { Current, eventCenter } from '@tarojs/runtime'
|
|
3
|
+
|
|
4
|
+
import { ICallbackResult, MethodHandler } from './handler'
|
|
5
|
+
|
|
6
|
+
import type { FunctionType, IAsyncParams } from './types'
|
|
7
|
+
|
|
8
|
+
export * from './constant'
|
|
9
|
+
export * from './unit'
|
|
10
|
+
export * from './validate'
|
|
11
|
+
export { MethodHandler }
|
|
12
|
+
export { noop } from '@tarojs/shared'
|
|
13
|
+
|
|
14
|
+
export function requestPermissions (permissions: string[]) {
|
|
15
|
+
return new Promise<void>((resolve, reject) => {
|
|
16
|
+
const context = getContext(Current?.page)
|
|
17
|
+
const atManager = abilityAccessCtrl.createAtManager()
|
|
18
|
+
|
|
19
|
+
atManager.requestPermissionsFromUser(context, permissions, (err, _) => {
|
|
20
|
+
if (err) {
|
|
21
|
+
// eslint-disable-next-line prefer-promise-reject-errors
|
|
22
|
+
reject(`[Taro] 请求用户授权 ${permissions.join('、')} 失败:${JSON.stringify(err)}`)
|
|
23
|
+
} else {
|
|
24
|
+
resolve()
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function object2String (obj) {
|
|
31
|
+
let str = ''
|
|
32
|
+
for (const item in obj) {
|
|
33
|
+
str = str + item + ':' + obj[item] + ' \n'
|
|
34
|
+
}
|
|
35
|
+
return str
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function temporarilyNotSupport (name: string, recommended?: string) {
|
|
39
|
+
return (option = {}, ...args) => {
|
|
40
|
+
const { success, fail, complete } = option as any
|
|
41
|
+
const handle = new MethodHandler({ name, success, fail, complete })
|
|
42
|
+
let errMsg = `暂时不支持 API ${name}`
|
|
43
|
+
if (recommended) {
|
|
44
|
+
errMsg += `, 请使用 ${recommended}`
|
|
45
|
+
}
|
|
46
|
+
eventCenter.trigger('__taroNotSupport', {
|
|
47
|
+
name,
|
|
48
|
+
args: [option, ...args],
|
|
49
|
+
type: 'method',
|
|
50
|
+
category: 'temporarily',
|
|
51
|
+
})
|
|
52
|
+
if (process.env.NODE_ENV === 'production') {
|
|
53
|
+
console.warn(errMsg)
|
|
54
|
+
return handle.success({ errMsg })
|
|
55
|
+
} else {
|
|
56
|
+
return handle.fail({ errMsg })
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function permanentlyNotSupport (name = '') {
|
|
62
|
+
return (option = {}, ...args: any[]) => {
|
|
63
|
+
const { success, fail, complete } = option as any
|
|
64
|
+
const handle = new MethodHandler<ICallbackResult>({ name, success, fail, complete })
|
|
65
|
+
const errMsg = '不支持 API'
|
|
66
|
+
eventCenter.trigger('__taroNotSupport', {
|
|
67
|
+
name,
|
|
68
|
+
args: [option, ...args],
|
|
69
|
+
type: 'method',
|
|
70
|
+
category: 'permanently',
|
|
71
|
+
})
|
|
72
|
+
if (process.env.NODE_ENV === 'production') {
|
|
73
|
+
console.warn(errMsg)
|
|
74
|
+
return handle.success({ errMsg })
|
|
75
|
+
} else {
|
|
76
|
+
return handle.fail({ errMsg })
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** @deprecated */
|
|
82
|
+
export function callCallbackSuccess<T extends FunctionType> (res, options?: IAsyncParams<T>) {
|
|
83
|
+
options?.success?.(res)
|
|
84
|
+
options?.complete?.(res)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** @deprecated */
|
|
88
|
+
export function callCallbackFail<T extends FunctionType> (res, options?: IAsyncParams<T>) {
|
|
89
|
+
options?.fail?.(res)
|
|
90
|
+
options?.complete?.(res)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** @deprecated */
|
|
94
|
+
export function callAsyncSuccess<T extends FunctionType> (resolve, res, options?: IAsyncParams<T>) {
|
|
95
|
+
options?.success?.(res)
|
|
96
|
+
options?.complete?.(res)
|
|
97
|
+
resolve(res)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** @deprecated */
|
|
101
|
+
export function callAsyncFail<T extends FunctionType> (reject, res, options?: IAsyncParams<T>) {
|
|
102
|
+
options?.fail?.(res)
|
|
103
|
+
options?.complete?.(res)
|
|
104
|
+
reject(res)
|
|
105
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export const READ_IMAGEVIDEO_PERMISSIONS = 'ohos.permission.READ_IMAGEVIDEO'
|
|
2
|
+
export const READ_MEDIA_PERMISSIONS = 'ohos.permission.READ_MEDIA'
|
|
3
|
+
export const WRITE_MEDIA_PERMISSIONS = 'ohos.permission.WRITE_MEDIA'
|
|
4
|
+
export const MEDIA_LOCATION_PERMISSIONS = 'ohos.permission.MEDIA_LOCATION'
|
|
5
|
+
|
|
6
|
+
export const IMAGE_PERMISSION = [READ_IMAGEVIDEO_PERMISSIONS, READ_MEDIA_PERMISSIONS, WRITE_MEDIA_PERMISSIONS, MEDIA_LOCATION_PERMISSIONS]
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
type GeneralCallback = (res: any) => void
|
|
2
|
+
|
|
3
|
+
export type FunctionType = (...args: any) => any
|
|
4
|
+
|
|
5
|
+
export interface IAsyncParams<T extends FunctionType = GeneralCallback> {
|
|
6
|
+
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
|
|
7
|
+
complete?: GeneralCallback
|
|
8
|
+
/** 接口调用失败的回调函数 */
|
|
9
|
+
fail?: GeneralCallback
|
|
10
|
+
/** 接口调用成功的回调函数 */
|
|
11
|
+
success?: T
|
|
12
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import _display from '@ohos.display'
|
|
2
|
+
import { Current } from '@tarojs/runtime'
|
|
3
|
+
import { isFunction } from '@tarojs/shared'
|
|
4
|
+
|
|
5
|
+
const defaultDesignWidth = 750
|
|
6
|
+
const defaultDesignRatio: Record<string | number, number> = {
|
|
7
|
+
640: 2.34 / 2,
|
|
8
|
+
750: 1,
|
|
9
|
+
828: 1.81 / 2
|
|
10
|
+
}
|
|
11
|
+
const defaultBaseFontSize = 20
|
|
12
|
+
const defaultUnitPrecision = 5
|
|
13
|
+
const defaultTargetUnit = 'vp'
|
|
14
|
+
|
|
15
|
+
export function initPxTransform ({
|
|
16
|
+
designWidth = defaultDesignWidth,
|
|
17
|
+
deviceRatio = defaultDesignRatio,
|
|
18
|
+
baseFontSize = defaultBaseFontSize,
|
|
19
|
+
unitPrecision = defaultUnitPrecision,
|
|
20
|
+
targetUnit = defaultTargetUnit
|
|
21
|
+
}) {
|
|
22
|
+
const taro = Current.taro
|
|
23
|
+
|
|
24
|
+
if (taro) {
|
|
25
|
+
taro.config ||= {}
|
|
26
|
+
const config = taro.config
|
|
27
|
+
config.designWidth = designWidth
|
|
28
|
+
config.deviceRatio = deviceRatio
|
|
29
|
+
config.baseFontSize = baseFontSize
|
|
30
|
+
config.targetUnit = targetUnit
|
|
31
|
+
config.unitPrecision = unitPrecision
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const display = _display.getDefaultDisplaySync()
|
|
36
|
+
|
|
37
|
+
const displayWidth = display.width
|
|
38
|
+
const displayHeight = display.height
|
|
39
|
+
let ratioCache: number | false = false
|
|
40
|
+
let designWidthFunc: (input: number) => number
|
|
41
|
+
let designWidth = defaultDesignWidth
|
|
42
|
+
function getRatio (value: number, customDesignWidth?: number) {
|
|
43
|
+
// Note: 提前调用 display 可能无法获取正确值
|
|
44
|
+
if (ratioCache === false || typeof customDesignWidth !== 'undefined') {
|
|
45
|
+
const config = Current.taro?.config || {}
|
|
46
|
+
if (!isFunction(designWidthFunc)) {
|
|
47
|
+
designWidthFunc = isFunction(config.designWidth)
|
|
48
|
+
? config.designWidth
|
|
49
|
+
: () => config.designWidth
|
|
50
|
+
designWidth = designWidthFunc(value) || defaultDesignWidth
|
|
51
|
+
}
|
|
52
|
+
let displayWidth_ = displayWidth
|
|
53
|
+
if (px2vp(displayWidth) >= 600 && px2vp(displayHeight) <= (600 * 10.8)) {
|
|
54
|
+
displayWidth_ = displayWidth_ / 2
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
ratioCache = displayWidth_ / (customDesignWidth || designWidth)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return ratioCache
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Note: 设置为 style 单位时会自动完成设计稿转换,设计开发者调用 API 时也许抹平差异,例如 pageScrollTo[option.offsetTop]
|
|
64
|
+
export function pxTransformHelper (size: number, unit?: string, isNumber = false): number | string {
|
|
65
|
+
const config = Current.taro?.config || {}
|
|
66
|
+
const targetUnit = unit || config.targetUnit || defaultTargetUnit
|
|
67
|
+
|
|
68
|
+
if (targetUnit === 'PX') {
|
|
69
|
+
return px2vp(size * display.scaledDensity) + 'vp'
|
|
70
|
+
}
|
|
71
|
+
const ratio = getRatio(size)
|
|
72
|
+
let val = size * ratio
|
|
73
|
+
|
|
74
|
+
switch (targetUnit) {
|
|
75
|
+
case 'vp':
|
|
76
|
+
// Note: 在应用创建前调用无效
|
|
77
|
+
val = px2vp(val)
|
|
78
|
+
break
|
|
79
|
+
default:
|
|
80
|
+
}
|
|
81
|
+
return isNumber ? val : val + targetUnit
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function pxTransform (size: number, designWidth?: number): number | string {
|
|
85
|
+
const config = Current.taro?.config || {}
|
|
86
|
+
const targetUnit = config.targetUnit || defaultTargetUnit
|
|
87
|
+
|
|
88
|
+
if (typeof designWidth !== 'undefined') {
|
|
89
|
+
// 允许动态改变
|
|
90
|
+
const ratio = getRatio(size, designWidth)
|
|
91
|
+
let val = size * ratio
|
|
92
|
+
val = px2vp(val)
|
|
93
|
+
return val
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const val = size
|
|
97
|
+
switch (targetUnit) {
|
|
98
|
+
case 'vp':
|
|
99
|
+
return pxTransformHelper(size, 'vp')
|
|
100
|
+
default:
|
|
101
|
+
// NOTE: 鸿蒙环境下 style 会自动完成设计稿转换,无需在方法内二次调整
|
|
102
|
+
}
|
|
103
|
+
return val + targetUnit
|
|
104
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { isArray, isNull, isObject, isString } from '@tarojs/shared'
|
|
2
|
+
|
|
3
|
+
type JSTypes = 'string' | 'number' | 'boolean' | 'undefined' | 'null' | 'bigint' | 'symbol' | 'array' | 'object' | 'function'
|
|
4
|
+
|
|
5
|
+
type NormalParamSchema = string[]
|
|
6
|
+
type ObjectParamSchema = Record<string, string>
|
|
7
|
+
|
|
8
|
+
type Schema = NormalParamSchema | ObjectParamSchema
|
|
9
|
+
|
|
10
|
+
interface ValidateParams {
|
|
11
|
+
<T>(name: string, params: any, schema: Schema): asserts params is T
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function shouldBeObject (target: unknown) {
|
|
15
|
+
if (target && typeof target === 'object') return { flag: true }
|
|
16
|
+
return {
|
|
17
|
+
flag: false,
|
|
18
|
+
msg: getParameterError({
|
|
19
|
+
correct: 'Object',
|
|
20
|
+
wrong: target
|
|
21
|
+
})
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface IParameterErrorParam {
|
|
26
|
+
name?: string
|
|
27
|
+
para?: string
|
|
28
|
+
correct?: string
|
|
29
|
+
wrong?: unknown
|
|
30
|
+
level?: 'warn' | 'error' | 'log' | 'info' | 'debug'
|
|
31
|
+
}
|
|
32
|
+
export function getParameterError ({ name = '', para, correct, wrong, level = 'error' }: IParameterErrorParam) {
|
|
33
|
+
const parameter = para ? `parameter.${para}` : 'parameter'
|
|
34
|
+
const errorType = upperCaseFirstLetter(wrong === null ? 'Null' : typeof wrong)
|
|
35
|
+
return `${name ? `${name}:fail ` : ''}parameter ${level}: ${parameter} should be ${correct} instead of ${errorType}`
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function upperCaseFirstLetter (string: string): string {
|
|
39
|
+
if (!isString(string)) return string
|
|
40
|
+
string = string.replace(/^./, match => match.toUpperCase())
|
|
41
|
+
return string
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function getType (param: string): JSTypes {
|
|
45
|
+
if (isNull(param)) {
|
|
46
|
+
return 'null'
|
|
47
|
+
} else if (isArray(param)) {
|
|
48
|
+
return 'array'
|
|
49
|
+
} else {
|
|
50
|
+
return typeof param
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function assertType (target: any, type: string, methodName: string, paramName?: string) {
|
|
55
|
+
const correct = upperCaseFirstLetter(type)
|
|
56
|
+
if (correct !== upperCaseFirstLetter(getType(target))) {
|
|
57
|
+
const err = getParameterError({ name: methodName, para: paramName, correct, wrong: target })
|
|
58
|
+
throw new Error(err)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 用于校验方法的参数类型
|
|
64
|
+
* @param name 方法名称
|
|
65
|
+
* @param params [array|object] 当前参数
|
|
66
|
+
* @param schema [array|object] 参数类型规范
|
|
67
|
+
* @example
|
|
68
|
+
* ```js
|
|
69
|
+
* // 例子一:
|
|
70
|
+
* validateParams(methodA, [key], [string])
|
|
71
|
+
* // 例子二:
|
|
72
|
+
* validateParams(methodB, { key: 123 }, { key: number })
|
|
73
|
+
* ```
|
|
74
|
+
* @todo 校验可选参数
|
|
75
|
+
*/
|
|
76
|
+
export const validateParams: ValidateParams = function (name, params, schema) {
|
|
77
|
+
if (isArray(schema) && isString(schema[0])) {
|
|
78
|
+
schema.forEach((correctType, index) => assertType(params[index], correctType, name, `[${index}]`))
|
|
79
|
+
} else if (isObject(schema)) {
|
|
80
|
+
const optionsSchema = schema
|
|
81
|
+
|
|
82
|
+
assertType(params, 'object', name)
|
|
83
|
+
for (const key in optionsSchema) {
|
|
84
|
+
assertType(params[key], optionsSchema[key], name, key)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils'
|
|
2
|
+
import { IntersectionObserver } from './intersectionObserver'
|
|
3
|
+
import { SelectorQuery } from './selectorQuery'
|
|
4
|
+
|
|
5
|
+
import type Taro from '@tarojs/taro/types'
|
|
6
|
+
|
|
7
|
+
export const createSelectorQuery = () => {
|
|
8
|
+
return new SelectorQuery()
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const createIntersectionObserver: typeof Taro.createIntersectionObserver = (component, options) => {
|
|
12
|
+
return new IntersectionObserver(component, options)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const createMediaQueryObserver = /* @__PURE__ */ temporarilyNotSupport('createMediaQueryObserver')
|
|
16
|
+
|
|
17
|
+
export { IntersectionObserver }
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { Current, document, getPageScrollerOrNode, TaroElement } from '@tarojs/runtime'
|
|
2
|
+
|
|
3
|
+
import { temporarilyNotSupport } from '../utils'
|
|
4
|
+
|
|
5
|
+
export class IntersectionObserver {
|
|
6
|
+
// 自定义组件实例
|
|
7
|
+
private _component: any
|
|
8
|
+
// 监听的nodes
|
|
9
|
+
private _observerNodes: TaroElement[] | TaroElement | null
|
|
10
|
+
// 选项
|
|
11
|
+
private _timer
|
|
12
|
+
|
|
13
|
+
_options = {
|
|
14
|
+
thresholds: [0],
|
|
15
|
+
initialRatio: 0,
|
|
16
|
+
observeAll: false,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
_viewportMargins = {
|
|
20
|
+
left: 0,
|
|
21
|
+
top: 0,
|
|
22
|
+
right: 0,
|
|
23
|
+
bottom: 0
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
constructor(component, options = {}) {
|
|
27
|
+
const taro = Current.taro
|
|
28
|
+
const page = taro.getCurrentInstance().page
|
|
29
|
+
|
|
30
|
+
// 兼容小程序原本的 getCurrentInstance()?.page 的写法
|
|
31
|
+
if (component && component.page === page && component.node) {
|
|
32
|
+
this._component = component.node
|
|
33
|
+
} else {
|
|
34
|
+
this._component = component || getPageScrollerOrNode(page?.node, page)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
Object.assign(this._options, options)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
disconnect () {
|
|
41
|
+
if (this._observerNodes && this._component) {
|
|
42
|
+
if (this._observerNodes instanceof Array) {
|
|
43
|
+
this._observerNodes.forEach((n) => {
|
|
44
|
+
Current.nativeModule.disconnectObserve(n)
|
|
45
|
+
})
|
|
46
|
+
} else {
|
|
47
|
+
Current.nativeModule.disconnectObserve(this._observerNodes)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (this._timer) {
|
|
51
|
+
clearTimeout(this._timer)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
this._observerNodes = null
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
observe (targetSelector, callback) {
|
|
59
|
+
if (!this._component) return
|
|
60
|
+
|
|
61
|
+
const { observeAll, thresholds, initialRatio } = this._options
|
|
62
|
+
const querySelectName = observeAll ? 'querySelectorAll' : 'querySelector'
|
|
63
|
+
const isComponentHaveSelectFunction = !!this._component[querySelectName]
|
|
64
|
+
const querySelector = isComponentHaveSelectFunction ? this._component[querySelectName].bind(this._component) : document[querySelectName].bind(document)
|
|
65
|
+
const node = querySelector(targetSelector)
|
|
66
|
+
this._observerNodes = node
|
|
67
|
+
|
|
68
|
+
if (!node) {
|
|
69
|
+
callback({
|
|
70
|
+
errMsg: 'IntersectionObserver.observe:fail cannot find the node for selector.'
|
|
71
|
+
})
|
|
72
|
+
return
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const list = node instanceof Array ? node : [node]
|
|
76
|
+
list.forEach((item) => {
|
|
77
|
+
Current.nativeModule.createObserve(item, this._viewportMargins, thresholds, initialRatio, (data) => {
|
|
78
|
+
this._timer = setTimeout(() => {
|
|
79
|
+
callback({
|
|
80
|
+
id: item.id,
|
|
81
|
+
dataset: item.dataset,
|
|
82
|
+
time: new Date().getTime(),
|
|
83
|
+
...data
|
|
84
|
+
})
|
|
85
|
+
}, 20)
|
|
86
|
+
})
|
|
87
|
+
})
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
relativeTo () {
|
|
91
|
+
temporarilyNotSupport('relativeTo')()
|
|
92
|
+
return this
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
relativeToViewport (option) {
|
|
96
|
+
this._viewportMargins = Object.assign(this._viewportMargins, option)
|
|
97
|
+
|
|
98
|
+
return this
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { SelectorQuery } from './selectorQuery'
|
|
2
|
+
|
|
3
|
+
import type Taro from '@tarojs/taro/types'
|
|
4
|
+
|
|
5
|
+
export class NodesRef implements Taro.NodesRef {
|
|
6
|
+
_component?: any
|
|
7
|
+
_selector: string
|
|
8
|
+
_selectorQuery: SelectorQuery
|
|
9
|
+
_single: boolean
|
|
10
|
+
|
|
11
|
+
constructor (selector: string, querySelectorQuery: SelectorQuery, single: boolean) {
|
|
12
|
+
this._component = querySelectorQuery._component
|
|
13
|
+
this._selector = selector
|
|
14
|
+
this._selectorQuery = querySelectorQuery
|
|
15
|
+
this._single = single
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
context (cb) {
|
|
19
|
+
const { _selector, _component, _single, _selectorQuery } = this
|
|
20
|
+
_selectorQuery._push(_selector, _component, _single, { context: !0 }, cb)
|
|
21
|
+
return _selectorQuery
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
node (cb?: Taro.NodesRef.NodeCallback) {
|
|
25
|
+
const { _selector, _component, _single, _selectorQuery } = this
|
|
26
|
+
_selectorQuery._push(_selector, _component, _single, { nodeCanvasType: !0, node: !0 }, cb)
|
|
27
|
+
return _selectorQuery
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
boundingClientRect (cb?: Taro.NodesRef.BoundingClientRectCallback) {
|
|
31
|
+
const { _selector, _component, _single, _selectorQuery } = this
|
|
32
|
+
_selectorQuery._push(_selector, _component, _single, { id: !0, dataset: !0, rect: !0, size: !0 }, cb)
|
|
33
|
+
return _selectorQuery
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
scrollOffset (cb) {
|
|
37
|
+
const { _selector, _component, _single, _selectorQuery } = this
|
|
38
|
+
_selectorQuery._push(_selector, _component, _single, { id: !0, dataset: !0, scrollOffset: !0 }, cb)
|
|
39
|
+
return _selectorQuery
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
fields (fields: Taro.NodesRef.Fields & { nodeCanvasType: Taro.NodesRef.Fields['node'] }, cb?: Taro.NodesRef.FieldsCallback) {
|
|
43
|
+
const { _selector, _component, _single, _selectorQuery } = this
|
|
44
|
+
const { id, dataset, rect, size, scrollOffset, properties = [], computedStyle = [], node, nodeCanvasType } = fields
|
|
45
|
+
_selectorQuery._push(_selector, _component, _single, {
|
|
46
|
+
id,
|
|
47
|
+
dataset,
|
|
48
|
+
rect,
|
|
49
|
+
size,
|
|
50
|
+
scrollOffset,
|
|
51
|
+
properties,
|
|
52
|
+
computedStyle,
|
|
53
|
+
node,
|
|
54
|
+
nodeCanvasType,
|
|
55
|
+
}, cb)
|
|
56
|
+
return _selectorQuery
|
|
57
|
+
}
|
|
58
|
+
}
|