@tarojs/plugin-platform-harmony-ets 4.0.0-alpha.0 → 4.0.0-alpha.11
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/apis/base/system.ts +73 -20
- package/dist/apis/canvas/index.ts +10 -1
- package/dist/apis/device/clipboard.ts +16 -8
- package/dist/apis/device/memory.ts +10 -3
- package/dist/apis/framework/index.ts +1 -5
- package/dist/apis/index.ts +27 -17
- package/dist/apis/media/image/index.ts +1 -1
- package/dist/apis/media/video/VideoContext.ts +56 -7
- package/dist/apis/media/video/index.ts +3 -2
- package/dist/apis/network/request.ts +5 -5
- package/dist/apis/route/index.ts +15 -0
- package/dist/apis/storage/index.ts +146 -78
- package/dist/apis/ui/animation/animation.ts +71 -29
- package/dist/apis/ui/background.ts +2 -1
- package/dist/apis/ui/interaction/index.ts +42 -59
- package/dist/apis/ui/navigation-bar/index.ts +1 -1
- package/dist/apis/ui/pull-down-refresh.ts +9 -3
- package/dist/apis/ui/scroll/index.ts +5 -5
- package/dist/apis/ui/tab-bar.ts +3 -3
- package/dist/apis/utils/index.ts +1 -1
- package/dist/apis/wxml/IntersectionObserver.ts +18 -10
- package/dist/apis/wxml/index.ts +2 -0
- package/dist/apis/wxml/selectorQuery.ts +26 -13
- package/dist/components-harmony-ets/button.ets +68 -68
- package/dist/components-harmony-ets/canvas.ets +51 -0
- package/dist/components-harmony-ets/checkbox.ets +81 -102
- package/dist/components-harmony-ets/form.ets +54 -45
- package/dist/components-harmony-ets/icon.ets +34 -50
- package/dist/components-harmony-ets/image.ets +35 -45
- package/dist/components-harmony-ets/index.ets +92 -0
- package/dist/components-harmony-ets/innerHtml.ets +11 -6
- package/dist/components-harmony-ets/input.ets +51 -67
- package/dist/components-harmony-ets/label.ets +73 -53
- package/dist/components-harmony-ets/listView.ets +26 -0
- package/dist/components-harmony-ets/movableArea.ets +124 -0
- package/dist/components-harmony-ets/movableView.ets +93 -0
- package/dist/components-harmony-ets/navigationBar.ets +65 -0
- package/dist/components-harmony-ets/pageMeta.ets +94 -0
- package/dist/components-harmony-ets/picker.ets +74 -77
- package/dist/components-harmony-ets/progress.ets +52 -0
- package/dist/components-harmony-ets/pseudo.ets +80 -0
- package/dist/components-harmony-ets/radio.ets +82 -104
- package/dist/components-harmony-ets/richText.ets +20 -68
- package/dist/components-harmony-ets/scrollList.ets +94 -0
- package/dist/components-harmony-ets/scrollView.ets +67 -103
- package/dist/components-harmony-ets/slider.ets +23 -47
- package/dist/components-harmony-ets/stickySection.ets +42 -0
- package/dist/components-harmony-ets/style.ets +396 -0
- package/dist/components-harmony-ets/swiper.ets +64 -53
- package/dist/components-harmony-ets/switch.ets +44 -55
- package/dist/components-harmony-ets/{index.ts → tag.ts} +6 -0
- package/dist/components-harmony-ets/text.ets +134 -75
- package/dist/components-harmony-ets/textArea.ets +54 -62
- package/dist/components-harmony-ets/utils/AttributeManager.ets +1 -1
- package/dist/components-harmony-ets/utils/DynamicCenter.ts +4 -13
- package/dist/components-harmony-ets/utils/flexManager.ets +76 -8
- package/dist/components-harmony-ets/utils/helper.ets +20 -7
- package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
- package/dist/components-harmony-ets/utils/htmlParser/index.ts +1 -1
- package/dist/components-harmony-ets/utils/index.ts +54 -50
- package/dist/components-harmony-ets/utils/styles.ets +178 -63
- package/dist/components-harmony-ets/video.ets +37 -54
- package/dist/components-harmony-ets/view.ets +63 -94
- package/dist/components-harmony-ets/webView.ets +56 -0
- package/dist/index.d.ts +152 -0
- package/dist/index.js +199 -58
- package/dist/index.js.map +1 -1
- package/dist/runtime-ets/bom/document.ts +6 -4
- package/dist/runtime-ets/bom/getComputedStyle.ts +2 -2
- package/dist/runtime-ets/bom/window.ts +9 -2
- package/dist/runtime-ets/current.ts +3 -0
- package/dist/runtime-ets/dom/bind.ts +28 -12
- package/dist/runtime-ets/dom/class-list.ts +2 -2
- package/dist/runtime-ets/dom/cssNesting.ts +409 -0
- package/dist/runtime-ets/dom/cssStyleDeclaration.ts +29 -19
- package/dist/runtime-ets/dom/document.ts +22 -8
- package/dist/runtime-ets/dom/element/canvas.ts +136 -0
- package/dist/runtime-ets/dom/element/element.ts +334 -57
- package/dist/runtime-ets/dom/element/form.ts +32 -26
- package/dist/runtime-ets/dom/element/index.ts +33 -2
- package/dist/runtime-ets/dom/element/movableArea.ts +11 -0
- package/dist/runtime-ets/dom/element/movableView.ts +242 -0
- package/dist/runtime-ets/dom/element/normal.ts +36 -8
- package/dist/runtime-ets/dom/element/progress.ts +11 -0
- package/dist/runtime-ets/dom/element/scrollView.ts +1 -0
- package/dist/runtime-ets/dom/element/text.ts +1 -8
- package/dist/runtime-ets/dom/element/video.ts +5 -4
- package/dist/runtime-ets/dom/element/webView.ts +68 -0
- package/dist/runtime-ets/dom/event.ts +2 -4
- package/dist/runtime-ets/dom/eventTarget.ts +2 -3
- package/dist/runtime-ets/dom/node.ts +62 -27
- package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +805 -0
- package/dist/runtime-ets/dom/stylesheet/index.ts +98 -518
- package/dist/runtime-ets/dom/stylesheet/type.ts +92 -17
- package/dist/runtime-ets/dom/stylesheet/util.ts +74 -16
- package/dist/runtime-ets/index.ts +2 -2
- package/dist/runtime-ets/interface/event.ts +3 -2
- package/dist/runtime-ets/utils/index.ts +77 -12
- package/dist/runtime-ets/utils/info.ts +4 -2
- package/dist/runtime-framework/react/app.ts +17 -22
- package/dist/runtime-framework/react/hooks.ts +3 -4
- package/dist/runtime-framework/react/index.ts +1 -2
- package/dist/runtime-framework/react/native-page.ts +421 -0
- package/dist/runtime-framework/react/page.ts +4 -9
- package/dist/runtime-framework/solid/app.ts +25 -45
- package/dist/runtime-framework/solid/connect.ts +21 -3
- package/dist/runtime-framework/solid/hooks.ts +17 -12
- package/dist/runtime-framework/solid/index.ts +6 -2
- package/dist/runtime-framework/solid/page.ts +84 -30
- package/dist/runtime-framework/solid/reconciler/props.ts +70 -25
- package/dist/runtime-framework/solid/reconciler/render.ts +16 -6
- package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
- package/dist/runtime-framework/solid/utils/index.ts +0 -2
- package/dist/runtime-utils.d.ts +827 -0
- package/dist/runtime-utils.js +510 -237
- package/dist/runtime-utils.js.map +1 -1
- package/dist/runtime.d.ts +1 -0
- package/dist/runtime.js +510 -237
- package/dist/runtime.js.map +1 -1
- package/index.js +3 -1
- package/package.json +14 -15
- package/static/media/cancel.svg +1 -0
- package/static/media/circle.svg +1 -0
- package/static/media/clear.svg +1 -0
- package/static/media/download.svg +1 -0
- package/static/media/info.svg +1 -0
- package/static/media/info_circle.svg +1 -0
- package/static/media/search.svg +1 -0
- package/static/media/success.svg +1 -0
- package/static/media/success_no_circle.svg +1 -0
- package/static/media/taro_arrow_left.svg +1 -0
- package/static/media/taro_home.svg +1 -0
- package/static/media/waiting.svg +1 -0
- package/static/media/warn.svg +1 -0
- package/types/harmony.d.ts +4 -0
- package/types/index.d.ts +4 -0
- package/types/runtime.d.ts +3 -1
- package/dist/runtime-ets/utils/bind.ts +0 -24
- /package/dist/runtime-framework/solid/{contant.ts → constant.ts} +0 -0
|
@@ -1,34 +1,53 @@
|
|
|
1
|
-
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
// import matrix4 from '@ohos.matrix4'
|
|
2
3
|
|
|
3
4
|
export interface HarmonyStyle extends TaroStyleType {
|
|
4
5
|
textAlign?: TextAlign
|
|
5
6
|
textOverflow?: HarmonyType.Overflow
|
|
6
|
-
|
|
7
|
+
WebkitLineClamp?: number
|
|
8
|
+
whiteSpace?: string
|
|
7
9
|
letterSpacing?: number | string
|
|
10
|
+
verticalAlign?: Alignment
|
|
11
|
+
lineHeight?: Length
|
|
8
12
|
}
|
|
9
13
|
|
|
10
14
|
export interface TaroStyleType {
|
|
11
15
|
id?: string
|
|
12
16
|
|
|
13
|
-
|
|
14
|
-
|
|
17
|
+
paddingTop?: Length
|
|
18
|
+
paddingRight?: Length
|
|
19
|
+
paddingBottom?: Length
|
|
20
|
+
paddingLeft?: Length
|
|
21
|
+
|
|
22
|
+
marginTop?: Length
|
|
23
|
+
marginRight?: Length
|
|
24
|
+
marginBottom?: Length
|
|
25
|
+
marginLeft?: Length
|
|
26
|
+
|
|
15
27
|
width?: Length
|
|
16
28
|
height?: Length
|
|
17
|
-
|
|
29
|
+
|
|
30
|
+
minHeight?: Length
|
|
31
|
+
maxHeight?: Length
|
|
32
|
+
minWidth?: Length
|
|
33
|
+
maxWidth?: Length
|
|
18
34
|
|
|
19
35
|
display?: 'flex' | 'block' | 'none'
|
|
36
|
+
visibility?: 'visible' | 'hidden'
|
|
20
37
|
|
|
21
38
|
// position
|
|
22
39
|
position?: 'relative' | 'absolute' | 'fixed'
|
|
23
40
|
top?: Length
|
|
24
41
|
left?: Length
|
|
42
|
+
bottom?: Length
|
|
43
|
+
right?: Length
|
|
25
44
|
|
|
26
45
|
// flex
|
|
27
46
|
flexBasis?: number | string
|
|
28
47
|
flexGrow?: number
|
|
29
48
|
flexShrink?: number
|
|
30
49
|
alignSelf?: ItemAlign
|
|
31
|
-
|
|
50
|
+
flexDirection?: FlexDirection
|
|
32
51
|
justifyContent?: FlexAlign
|
|
33
52
|
alignItems?: ItemAlign
|
|
34
53
|
flexWrap?: FlexWrap
|
|
@@ -36,22 +55,43 @@ export interface TaroStyleType {
|
|
|
36
55
|
|
|
37
56
|
// background
|
|
38
57
|
backgroundColor?: ResourceColor
|
|
39
|
-
backgroundImage?:
|
|
58
|
+
backgroundImage?: HarmonyType.Background.BackgroundImage
|
|
40
59
|
backgroundRepeat?: ImageRepeat
|
|
41
|
-
|
|
42
|
-
|
|
60
|
+
backgroundSize?: SizeOptions | ImageSize
|
|
61
|
+
backgroundPosition?: Position | Alignment
|
|
62
|
+
|
|
63
|
+
// 渐变
|
|
64
|
+
linearGradient?: HarmonyType.LinearGradient
|
|
65
|
+
radialGradient?: HarmonyType.RadialGradient
|
|
43
66
|
|
|
44
67
|
// transform
|
|
45
68
|
rotate?: HarmonyType.Transform.Rotate
|
|
46
69
|
translate?: HarmonyType.Transform.Translate
|
|
47
70
|
scale?: HarmonyType.Transform.Scale
|
|
48
71
|
transform?: HarmonyType.Transform.Transform
|
|
72
|
+
transformOrigin?: HarmonyType.Transform.Origin
|
|
49
73
|
|
|
50
74
|
// border
|
|
51
75
|
borderWidth?: Length | EdgeWidths
|
|
76
|
+
borderLeftWidth?: Length
|
|
77
|
+
borderRightWidth?: Length
|
|
78
|
+
borderTopWidth?: Length
|
|
79
|
+
borderBottomWidth?: Length
|
|
52
80
|
borderColor?: ResourceColor | EdgeColors
|
|
81
|
+
borderLeftColor?: ResourceColor
|
|
82
|
+
borderRightColor?: ResourceColor
|
|
83
|
+
borderTopColor?: ResourceColor
|
|
84
|
+
borderBottomColor?: ResourceColor
|
|
53
85
|
borderStyle?: BorderStyle | EdgeStyles
|
|
86
|
+
borderLeftStyle?: BorderStyle
|
|
87
|
+
borderRightStyle?: BorderStyle
|
|
88
|
+
borderTopStyle?: BorderStyle
|
|
89
|
+
borderBottomStyle?: BorderStyle
|
|
54
90
|
borderRadius?: Length | BorderRadiuses
|
|
91
|
+
borderTopLeftRadius?: Length
|
|
92
|
+
borderTopRightRadius?: Length
|
|
93
|
+
borderBottomLeftRadius?: Length
|
|
94
|
+
borderBottomRightRadius?: Length
|
|
55
95
|
|
|
56
96
|
// text
|
|
57
97
|
color?: ResourceColor
|
|
@@ -59,24 +99,45 @@ export interface TaroStyleType {
|
|
|
59
99
|
fontStyle?: FontStyle
|
|
60
100
|
fontWeight?: number | FontWeight | string
|
|
61
101
|
fontFamily?: string | Resource
|
|
62
|
-
|
|
63
|
-
|
|
102
|
+
textDecoration?: {
|
|
103
|
+
type: TextDecorationType
|
|
104
|
+
}
|
|
64
105
|
|
|
65
|
-
//
|
|
66
|
-
|
|
106
|
+
// animation
|
|
107
|
+
animationName?: {
|
|
108
|
+
percentage: number
|
|
109
|
+
event: TaroStyleType
|
|
110
|
+
}[]
|
|
111
|
+
animationDuration?: number
|
|
112
|
+
animationTimingFunction?: string
|
|
113
|
+
animationDelay?: number
|
|
114
|
+
animationIterationCount?: number
|
|
115
|
+
|
|
116
|
+
// shadow
|
|
117
|
+
boxShadow?: {
|
|
118
|
+
radius: number
|
|
119
|
+
color?: string
|
|
120
|
+
offsetX?: number
|
|
121
|
+
offsetY?: number
|
|
122
|
+
fill?: boolean
|
|
123
|
+
}
|
|
67
124
|
|
|
68
125
|
// other
|
|
69
126
|
opacity?: number | Resource
|
|
70
127
|
zIndex?: number
|
|
71
|
-
|
|
128
|
+
overflow?: string
|
|
72
129
|
focus?: boolean
|
|
130
|
+
content?: string
|
|
73
131
|
}
|
|
74
132
|
|
|
75
133
|
export interface TaroTextStyleType {
|
|
76
134
|
textAlign?: TextAlign
|
|
77
135
|
textOverflow?: HarmonyType.Overflow
|
|
78
|
-
|
|
136
|
+
WebkitLineClamp?: number
|
|
137
|
+
whiteSpace?: string
|
|
79
138
|
letterSpacing?: number | string
|
|
139
|
+
verticalAlign?: Alignment
|
|
140
|
+
lineHeight?: string | number | Resource
|
|
80
141
|
}
|
|
81
142
|
|
|
82
143
|
export namespace HarmonyType {
|
|
@@ -91,6 +152,12 @@ export namespace HarmonyType {
|
|
|
91
152
|
colors: Array<[ResourceColor, number]>
|
|
92
153
|
repeating?: boolean
|
|
93
154
|
}
|
|
155
|
+
export interface RadialGradient {
|
|
156
|
+
center: any
|
|
157
|
+
radius: number | string
|
|
158
|
+
colors: Array<[ResourceColor, number]>
|
|
159
|
+
repeating?: boolean
|
|
160
|
+
}
|
|
94
161
|
export interface Overflow {
|
|
95
162
|
overflow: TextOverflow
|
|
96
163
|
}
|
|
@@ -109,6 +176,10 @@ export namespace HarmonyType {
|
|
|
109
176
|
export type backgroundImagePosition = Position | Alignment
|
|
110
177
|
}
|
|
111
178
|
export namespace Transform {
|
|
179
|
+
export interface Origin {
|
|
180
|
+
x?: number
|
|
181
|
+
y?: number
|
|
182
|
+
}
|
|
112
183
|
export interface Rotate {
|
|
113
184
|
x?: number
|
|
114
185
|
y?: number
|
|
@@ -131,7 +202,11 @@ export namespace HarmonyType {
|
|
|
131
202
|
centerX?: number | string
|
|
132
203
|
centerY?: number | string
|
|
133
204
|
}
|
|
134
|
-
export type Transform = matrix4.Matrix4Transit
|
|
205
|
+
// export type Transform = matrix4.Matrix4Transit
|
|
206
|
+
export type Transform = {
|
|
207
|
+
Translate?: Translate
|
|
208
|
+
Scale?: Scale
|
|
209
|
+
Rotate?: Rotate
|
|
210
|
+
}
|
|
135
211
|
}
|
|
136
212
|
}
|
|
137
|
-
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
|
+
// import matrix4 from '@ohos.matrix4'
|
|
2
3
|
import { isNumber } from '@tarojs/shared'
|
|
3
4
|
|
|
4
5
|
import { convertNumber2VP } from '../../'
|
|
5
6
|
|
|
6
7
|
export class FlexManager {
|
|
7
|
-
|
|
8
8
|
static flexAlign (value: string | number | undefined): FlexAlign {
|
|
9
9
|
switch (value) {
|
|
10
10
|
case 'flex-end':
|
|
@@ -163,42 +163,100 @@ export class FlexManager {
|
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
+
export class BORDER_STYLE_MAP {
|
|
167
|
+
static solid = BorderStyle.Solid
|
|
168
|
+
static dotted = BorderStyle.Dotted
|
|
169
|
+
static dashed = BorderStyle.Dashed
|
|
170
|
+
|
|
171
|
+
static get(type: string): BorderStyle {
|
|
172
|
+
switch (type) {
|
|
173
|
+
case 'dotted': return BorderStyle.Dotted
|
|
174
|
+
case 'dashed': return BorderStyle.Dashed
|
|
175
|
+
default: return BorderStyle.Solid
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
static reverse(type: BorderStyle): string {
|
|
180
|
+
switch (type) {
|
|
181
|
+
case BorderStyle.Dotted: return 'dotted'
|
|
182
|
+
case BorderStyle.Dashed: return 'dashed'
|
|
183
|
+
case BorderStyle.Solid: return 'solid'
|
|
184
|
+
default: return ''
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
166
189
|
export function getNodeMarginOrPaddingData (dataValue: string) {
|
|
167
190
|
let res: any = {}
|
|
168
191
|
if (dataValue) {
|
|
169
|
-
const values = dataValue.trim().split(new RegExp('\\s+'))
|
|
192
|
+
const values = dataValue.toString().trim().split(new RegExp('\\s+'))
|
|
193
|
+
let val1: string
|
|
194
|
+
let val2: string
|
|
170
195
|
switch (values.length) {
|
|
171
196
|
case 1:
|
|
172
|
-
|
|
197
|
+
val1 = getUnit(values[0])
|
|
198
|
+
res = { top: val1, right: val1, bottom: val1, left: val1 }
|
|
173
199
|
break
|
|
174
200
|
case 2:
|
|
175
|
-
|
|
201
|
+
val1 = getUnit(values[0])
|
|
202
|
+
val2 = getUnit(values[1])
|
|
203
|
+
res = { top: val1, right: val2, bottom: val1, left: val2 }
|
|
176
204
|
break
|
|
177
205
|
case 3:
|
|
178
|
-
|
|
206
|
+
val2 = getUnit(values[1])
|
|
207
|
+
res = { top: getUnit(values[0]), right: val2, bottom: getUnit(values[2]), left: val2 }
|
|
179
208
|
break
|
|
180
209
|
case 4:
|
|
181
|
-
res = { top: values[0], right: values[1], bottom: values[2], left: values[3] }
|
|
210
|
+
res = { top: getUnit(values[0]), right: getUnit(values[1]), bottom: getUnit(values[2]), left: getUnit(values[3]) }
|
|
182
211
|
break
|
|
183
212
|
default:
|
|
184
213
|
break
|
|
185
214
|
}
|
|
186
|
-
Object.keys(res).forEach(key => {
|
|
187
|
-
const exec = `${res[key]}`.match(/(\d+)(px)$/)
|
|
188
|
-
if (exec && values.length > 1) {
|
|
189
|
-
res[key] = getUnit(+exec[1])
|
|
190
|
-
}
|
|
191
|
-
})
|
|
192
215
|
}
|
|
193
216
|
return res
|
|
194
217
|
}
|
|
195
218
|
|
|
196
|
-
|
|
197
219
|
export function getUnit (val) {
|
|
198
|
-
|
|
220
|
+
// 空的字符串代表 Reconciler remove 了这个 prop,不进行后面的逻辑了
|
|
221
|
+
if (val === '') return val
|
|
222
|
+
|
|
223
|
+
if (/\d+(vp|px)$/.test(val)) {
|
|
199
224
|
return val
|
|
200
|
-
} else if (isNumber(val)
|
|
201
|
-
return
|
|
225
|
+
} else if (isNumber(val)) {
|
|
226
|
+
return parseFloat(val) + 'px'
|
|
227
|
+
}
|
|
228
|
+
if (val) {
|
|
229
|
+
// 匹配vw\vh
|
|
230
|
+
const exec = val.match(/(-?\d*(\.\d+)?)(vw|vh)$/)
|
|
231
|
+
if (exec) {
|
|
232
|
+
const [, num, , unit] = exec
|
|
233
|
+
return convertNumber2VP(parseFloat(num), unit)
|
|
234
|
+
}
|
|
202
235
|
}
|
|
203
236
|
return val
|
|
204
237
|
}
|
|
238
|
+
|
|
239
|
+
export function getTransform(transform) {
|
|
240
|
+
// if (transform) {
|
|
241
|
+
// return transform.reduce((res, item) => {
|
|
242
|
+
// switch (item.type) {
|
|
243
|
+
// case 'Translate': return res.translate(item.value)
|
|
244
|
+
// case 'Scale': return res.scale(item.value)
|
|
245
|
+
// case 'Rotate': return res.rotate(item.value)
|
|
246
|
+
// case 'Matrix': return res.combine(matrix4.init(item.value))
|
|
247
|
+
// }
|
|
248
|
+
// return res
|
|
249
|
+
// }, matrix4.identity())
|
|
250
|
+
// }
|
|
251
|
+
const result = {}
|
|
252
|
+
if (transform) {
|
|
253
|
+
transform.forEach((item) => {
|
|
254
|
+
result[item.type] = item.value
|
|
255
|
+
})
|
|
256
|
+
return result
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export function capitalizeFirstLetter (str: string) {
|
|
261
|
+
return str.charAt(0).toUpperCase() + str.slice(1)
|
|
262
|
+
}
|
|
@@ -10,9 +10,9 @@ export * from './dom/element'
|
|
|
10
10
|
export * from './dom/event'
|
|
11
11
|
export * from './dom/node'
|
|
12
12
|
export * from './dom/stylesheet'
|
|
13
|
+
export * from './dom/cssNesting'
|
|
13
14
|
export * from './interface'
|
|
14
15
|
export * from './utils'
|
|
15
|
-
export * from './utils/bind'
|
|
16
16
|
export * from './utils/info'
|
|
17
|
-
export { URLSearchParams, eventSource } from '@tarojs/runtime/dist/runtime.esm'
|
|
17
|
+
export { URL, URLSearchParams, eventSource, Events } from '@tarojs/runtime/dist/runtime.esm'
|
|
18
18
|
export { hooks } from '@tarojs/shared'
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import _display from '@ohos.display'
|
|
2
|
-
import { pxTransformHelper } from '@tarojs/taro'
|
|
2
|
+
import { getSystemInfoSync, pxTransformHelper } from '@tarojs/taro'
|
|
3
3
|
|
|
4
4
|
import { NodeType } from '../dom/node'
|
|
5
|
+
import convertWebStyle2HmStyle from '../dom/stylesheet/covertWeb2Hm'
|
|
5
6
|
|
|
6
7
|
import type { CSSProperties } from 'react'
|
|
7
8
|
import type { TaroElement } from '../dom/element/element'
|
|
@@ -37,24 +38,85 @@ export function convertNumber2PX (value: number) {
|
|
|
37
38
|
return pxTransformHelper(value, 'vp')
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
export function convertNumber2VP (value: number, unit = 'px') {
|
|
41
|
+
export function convertNumber2VP (value: number, unit = 'px'): string | number {
|
|
41
42
|
if (unit === 'vw' || unit === 'vh') {
|
|
42
|
-
return (value / 100 * (unit === 'vw' ? display.width: display.height)) + 'px'
|
|
43
|
+
return (value / 100 * (unit === 'vw' ? display.width : display.height)) + 'px'
|
|
44
|
+
}
|
|
45
|
+
if (unit === 'PX') {
|
|
46
|
+
// 特殊单位:相当于PX、pX、Px
|
|
47
|
+
return pxTransformHelper(value, 'PX')
|
|
43
48
|
}
|
|
44
49
|
return pxTransformHelper(value, 'vp')
|
|
45
50
|
}
|
|
46
51
|
|
|
47
|
-
export function
|
|
52
|
+
export function parseClasses (classNames = ''): string[] {
|
|
53
|
+
if (typeof classNames !== 'string') {
|
|
54
|
+
return []
|
|
55
|
+
}
|
|
56
|
+
return classNames.includes(' ') ? classNames.split(' ') : [classNames]
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// 合并静态样式,从样式表里面找到对应的样式
|
|
60
|
+
export function calcStaticStyle (styleSheet: Record<string, CSSProperties>, classNames = ''): CSSProperties {
|
|
61
|
+
classNames = classNames || '' // 兼容有些开发者传入了false/null等非字符串类型
|
|
48
62
|
const obj: CSSProperties[] = []
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
63
|
+
|
|
64
|
+
if (!styleSheet.cache) {
|
|
65
|
+
styleSheet.cache = {}
|
|
66
|
+
}
|
|
67
|
+
const cache: Record<string, CSSProperties> = styleSheet.cache as Record<string, CSSProperties>
|
|
68
|
+
|
|
69
|
+
const classes = parseClasses(classNames)
|
|
70
|
+
if (!classes.length) return {}
|
|
71
|
+
if (classes.length === 1) {
|
|
72
|
+
// 同一个引用
|
|
73
|
+
return styleSheet[classes[0]]
|
|
74
|
+
} else {
|
|
75
|
+
if (cache[classNames]) {
|
|
76
|
+
return cache[classNames]
|
|
77
|
+
} else {
|
|
78
|
+
for (let i = 0; i < classes.length; i++) {
|
|
79
|
+
const className = classes[i]
|
|
80
|
+
if (styleSheet[className]) {
|
|
81
|
+
obj.push(styleSheet[className])
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const result = Object.assign.apply(null, [{}].concat(obj))
|
|
85
|
+
|
|
86
|
+
cache[classNames] = result
|
|
87
|
+
|
|
88
|
+
return result
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// 动态样式计算,需要经过web2harmony进行反转
|
|
94
|
+
export function calcDynamicStyle (style: CSSProperties): CSSProperties {
|
|
95
|
+
if (style) {
|
|
96
|
+
return convertWebStyle2HmStyle(style)
|
|
97
|
+
}
|
|
98
|
+
return {}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// css env()环境样式获取
|
|
102
|
+
export function __env__(safeAreaType: string, fallback?: string | number) {
|
|
103
|
+
const sysInfo = getSystemInfoSync()
|
|
104
|
+
|
|
105
|
+
switch (safeAreaType) {
|
|
106
|
+
case 'safe-area-inset-top': {
|
|
107
|
+
return sysInfo.safeArea?.top ? `${sysInfo.safeArea?.top}px` : fallback
|
|
108
|
+
}
|
|
109
|
+
case 'safe-area-inset-right': {
|
|
110
|
+
return sysInfo.safeArea?.right ? `${sysInfo.screenWidth - sysInfo.safeArea?.right}px` : fallback
|
|
111
|
+
}
|
|
112
|
+
case 'safe-area-inset-bottom': {
|
|
113
|
+
return sysInfo.safeArea?.bottom ? `${sysInfo.screenHeight - sysInfo.safeArea?.bottom}px` : fallback
|
|
114
|
+
}
|
|
115
|
+
case 'safe-area-inset-left': {
|
|
116
|
+
return sysInfo.safeArea?.left ? `${sysInfo.safeArea?.left}px` : fallback
|
|
54
117
|
}
|
|
55
118
|
}
|
|
56
|
-
|
|
57
|
-
return Object.assign.apply(null, [{}].concat(obj))
|
|
119
|
+
return fallback
|
|
58
120
|
}
|
|
59
121
|
|
|
60
122
|
export function getPageScrollerOrNode (scrollerOrNode: any, page: any) {
|
|
@@ -71,6 +133,10 @@ export function getPageScrollerOrNode (scrollerOrNode: any, page: any) {
|
|
|
71
133
|
return scrollerOrNode
|
|
72
134
|
}
|
|
73
135
|
|
|
136
|
+
export function ObjectKeys(obj: object): string[] {
|
|
137
|
+
return Object.keys(obj)
|
|
138
|
+
}
|
|
139
|
+
|
|
74
140
|
export function ObjectAssign(...objects) {
|
|
75
141
|
return Object.assign.apply(this, [{}].concat(...objects))
|
|
76
142
|
}
|
|
@@ -86,7 +152,6 @@ export function bindFn (fn: any, ctx: any, ...args: any) {
|
|
|
86
152
|
}
|
|
87
153
|
}
|
|
88
154
|
|
|
89
|
-
|
|
90
155
|
// 使用深度优先遍历寻找节点树中对应的子节点,且只需要找到第一个
|
|
91
156
|
// 通过 selector 判断是 id 还是 selector,从 node 的 id 和 className 属性中寻找
|
|
92
157
|
export function findChildNodeWithDFS<T extends TaroElement = TaroElement> (node: TaroElement, selector: string | ((ele: T) => boolean), selectAll: true): T[] | null;
|
|
@@ -50,7 +50,9 @@ function tapCallbackToNodeAndUpdate (node: TaroElement, eventName: string, callb
|
|
|
50
50
|
callback && callback(...eventResult)
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
node.
|
|
53
|
+
if (!node._isDynamicNode && node._isCompileMode) {
|
|
54
|
+
node.updateComponent()
|
|
55
|
+
}
|
|
54
56
|
}
|
|
55
57
|
|
|
56
58
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
@@ -89,7 +91,7 @@ export function triggerAttributesCallback (node, attributeName) {
|
|
|
89
91
|
|
|
90
92
|
const value = node._attrs[attributeName]
|
|
91
93
|
const cb = node._nodeInfo.attributeCallback[attributeName]
|
|
92
|
-
|
|
94
|
+
|
|
93
95
|
isFunction(cb) && cb(value)
|
|
94
96
|
}
|
|
95
97
|
|
|
@@ -5,6 +5,7 @@ import { setReconciler } from './connect'
|
|
|
5
5
|
import { injectPageInstance } from './page'
|
|
6
6
|
import { EMPTY_OBJ, incrementId, isClassComponent } from './utils'
|
|
7
7
|
|
|
8
|
+
import type { AppInstance } from '@tarojs/runtime'
|
|
8
9
|
import type React from 'react'
|
|
9
10
|
|
|
10
11
|
let h: typeof React.createElement
|
|
@@ -26,8 +27,11 @@ const pageKeyId = incrementId()
|
|
|
26
27
|
|
|
27
28
|
export function connectReactPage (
|
|
28
29
|
R: typeof React,
|
|
29
|
-
id: string
|
|
30
|
+
id: string,
|
|
31
|
+
getCtx: () => any
|
|
30
32
|
) {
|
|
33
|
+
const ctx = getCtx?.()
|
|
34
|
+
|
|
31
35
|
return (Page): React.ComponentClass<any> => {
|
|
32
36
|
// eslint-disable-next-line dot-notation
|
|
33
37
|
const isReactComponent = isClassComponent(R, Page)
|
|
@@ -63,7 +67,7 @@ export function connectReactPage (
|
|
|
63
67
|
const children = this.state.hasError
|
|
64
68
|
? []
|
|
65
69
|
: h(ReactMeta.PageContext.Provider, { value: id }, h(Page, {
|
|
66
|
-
...this.props,
|
|
70
|
+
...Object.assign({}, ctx?.props, this.props),
|
|
67
71
|
...refs
|
|
68
72
|
}))
|
|
69
73
|
|
|
@@ -126,8 +130,8 @@ export function createReactApp (
|
|
|
126
130
|
appWrapperResolver(this)
|
|
127
131
|
}
|
|
128
132
|
|
|
129
|
-
public mount (pageComponent: any, id: string, cb: () => void) {
|
|
130
|
-
const pageWrapper = connectReactPage(react, id)(pageComponent)
|
|
133
|
+
public mount (pageComponent: any, id: string, getCtx: () => any, cb: () => void) {
|
|
134
|
+
const pageWrapper = connectReactPage(react, id, getCtx)(pageComponent)
|
|
131
135
|
const key = id + pageKeyId()
|
|
132
136
|
const page = () => h(pageWrapper, { key, tid: id })
|
|
133
137
|
this.pages.push(page)
|
|
@@ -169,14 +173,13 @@ export function createReactApp (
|
|
|
169
173
|
render (cb: () => void) {
|
|
170
174
|
appWrapper.forceUpdate(cb)
|
|
171
175
|
},
|
|
172
|
-
mount (component: any, id: string, cb: () => void) {
|
|
176
|
+
mount (component: any, id: string, getCtx: () => any, cb: () => void) {
|
|
173
177
|
if (appWrapper) {
|
|
174
|
-
appWrapper.mount(component, id, cb)
|
|
178
|
+
appWrapper.mount(component, id, getCtx, cb)
|
|
175
179
|
} else {
|
|
176
|
-
appWrapperPromise.then(appWrapper => appWrapper.mount(component, id, cb))
|
|
180
|
+
appWrapperPromise.then(appWrapper => appWrapper.mount(component, id, getCtx, cb))
|
|
177
181
|
}
|
|
178
182
|
},
|
|
179
|
-
|
|
180
183
|
unmount (id: string, cb: () => void) {
|
|
181
184
|
appWrapper?.unmount(id, cb)
|
|
182
185
|
},
|
|
@@ -233,21 +236,13 @@ export function createReactApp (
|
|
|
233
236
|
app?.componentDidHide?.()
|
|
234
237
|
})
|
|
235
238
|
}
|
|
236
|
-
}
|
|
239
|
+
} as unknown as AppInstance
|
|
237
240
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
// const func = hooks.call('getLifecycle', instance, lifecycle)
|
|
244
|
-
// if (Array.isArray(func)) {
|
|
245
|
-
// func.forEach(cb => cb.apply(app, option))
|
|
246
|
-
// }
|
|
247
|
-
// }
|
|
248
|
-
// }
|
|
249
|
-
|
|
250
|
-
Current.app = app
|
|
241
|
+
if (Current.app) {
|
|
242
|
+
Current.app = Object.assign(app, Current.app)
|
|
243
|
+
} else {
|
|
244
|
+
Current.app = app
|
|
245
|
+
}
|
|
251
246
|
|
|
252
247
|
return app
|
|
253
248
|
}
|
|
@@ -7,14 +7,14 @@ import { HOOKS_APP_ID } from './utils'
|
|
|
7
7
|
|
|
8
8
|
import type {
|
|
9
9
|
AppInstance,
|
|
10
|
-
Func,
|
|
11
10
|
Instance,
|
|
12
11
|
PageLifeCycle,
|
|
13
|
-
PageProps
|
|
12
|
+
PageProps,
|
|
13
|
+
TFunc
|
|
14
14
|
} from '@tarojs/runtime/dist/runtime.esm'
|
|
15
15
|
|
|
16
16
|
const createTaroHook = (lifecycle: keyof PageLifeCycle | keyof AppInstance) => {
|
|
17
|
-
return (fn:
|
|
17
|
+
return (fn: TFunc) => {
|
|
18
18
|
const { R: React, PageContext } = ReactMeta
|
|
19
19
|
const id = React.useContext(PageContext) || HOOKS_APP_ID
|
|
20
20
|
const instRef = React.useRef<Instance<PageProps>>()
|
|
@@ -24,7 +24,6 @@ const createTaroHook = (lifecycle: keyof PageLifeCycle | keyof AppInstance) => {
|
|
|
24
24
|
if (fnRef.current !== fn) fnRef.current = fn
|
|
25
25
|
|
|
26
26
|
React.useLayoutEffect(() => {
|
|
27
|
-
|
|
28
27
|
let inst = instRef.current = getPageInstance(id)
|
|
29
28
|
let first = false
|
|
30
29
|
if (!inst) {
|
|
@@ -2,8 +2,6 @@ import { hooks } from '@tarojs/shared'
|
|
|
2
2
|
|
|
3
3
|
import * as taroHooks from './hooks'
|
|
4
4
|
|
|
5
|
-
// declare const __TARO_FRAMEWORK__: string;
|
|
6
|
-
|
|
7
5
|
hooks.tap('initNativeApi', function (taro) {
|
|
8
6
|
for (const hook in taroHooks) {
|
|
9
7
|
taro[hook] = taroHooks[hook]
|
|
@@ -13,4 +11,5 @@ hooks.tap('initNativeApi', function (taro) {
|
|
|
13
11
|
export * from './app'
|
|
14
12
|
export * from './connect'
|
|
15
13
|
export * from './hooks'
|
|
14
|
+
export * from './native-page'
|
|
16
15
|
export * from './page'
|