@tarojs/plugin-platform-harmony-ets 3.7.0-alpha.27
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/LICENSE +160 -0
- package/dist/apis/apis.ts +15 -0
- package/dist/apis/base/index.ts +5 -0
- package/dist/apis/base/system.ts +77 -0
- package/dist/apis/device/accelerometer.ts +76 -0
- package/dist/apis/device/battery.ts +24 -0
- package/dist/apis/device/clipboard.ts +70 -0
- package/dist/apis/device/index.ts +9 -0
- package/dist/apis/device/keyboard.ts +62 -0
- package/dist/apis/device/memory.ts +4 -0
- package/dist/apis/device/network.ts +72 -0
- package/dist/apis/device/phone.ts +43 -0
- package/dist/apis/device/screen.ts +79 -0
- package/dist/apis/device/vibrate.ts +24 -0
- package/dist/apis/files/index.ts +135 -0
- package/dist/apis/files/manager.ts +941 -0
- package/dist/apis/framework/index.ts +32 -0
- package/dist/apis/index.ts +124 -0
- package/dist/apis/location/index.ts +133 -0
- package/dist/apis/media/common.ts +74 -0
- package/dist/apis/media/image.ts +122 -0
- package/dist/apis/media/index.ts +3 -0
- package/dist/apis/media/video.ts +86 -0
- package/dist/apis/navigate/index.ts +8 -0
- package/dist/apis/network/downloadFile.ts +113 -0
- package/dist/apis/network/index.ts +4 -0
- package/dist/apis/network/request.ts +113 -0
- package/dist/apis/network/uploadFile.ts +158 -0
- package/dist/apis/network/webSocket.ts +130 -0
- package/dist/apis/open-api/index.ts +7 -0
- package/dist/apis/open-api/user-info/index.ts +85 -0
- package/dist/apis/page/index.ts +92 -0
- package/dist/apis/route/index.ts +138 -0
- package/dist/apis/storage/index.ts +133 -0
- package/dist/apis/tabbar/index.ts +147 -0
- package/dist/apis/ui/animation.ts +222 -0
- package/dist/apis/ui/background.ts +35 -0
- package/dist/apis/ui/index.ts +14 -0
- package/dist/apis/ui/interaction/index.ts +195 -0
- package/dist/apis/ui/navigation-bar/index.ts +33 -0
- package/dist/apis/ui/pull-down-refresh.ts +41 -0
- package/dist/apis/utils/handler.ts +116 -0
- package/dist/apis/utils/index.ts +85 -0
- package/dist/apis/utils/types.ts +12 -0
- package/dist/apis/utils/validate.ts +87 -0
- package/dist/apis/wxml/IntersectionObserver.ts +119 -0
- package/dist/apis/wxml/index.ts +12 -0
- package/dist/apis/wxml/nodesRef.ts +56 -0
- package/dist/apis/wxml/selectorQuery.ts +287 -0
- package/dist/components/components-react.js +51 -0
- package/dist/components/components-react.js.map +1 -0
- package/dist/components-harmony/button/index.css +109 -0
- package/dist/components-harmony/button/index.hml +31 -0
- package/dist/components-harmony/button/index.js +105 -0
- package/dist/components-harmony/camera/index.hml +6 -0
- package/dist/components-harmony/camera/index.js +12 -0
- package/dist/components-harmony/checkbox/index.hml +11 -0
- package/dist/components-harmony/checkbox/index.js +60 -0
- package/dist/components-harmony/checkbox-group/index.hml +3 -0
- package/dist/components-harmony/checkbox-group/index.js +22 -0
- package/dist/components-harmony/cover-image/index.css +4 -0
- package/dist/components-harmony/cover-image/index.hml +9 -0
- package/dist/components-harmony/cover-image/index.js +15 -0
- package/dist/components-harmony/form/index.hml +10 -0
- package/dist/components-harmony/form/index.js +11 -0
- package/dist/components-harmony/icon/index.css +27 -0
- package/dist/components-harmony/icon/index.hml +54 -0
- package/dist/components-harmony/icon/index.js +17 -0
- package/dist/components-harmony/image/index.css +5 -0
- package/dist/components-harmony/image/index.hml +11 -0
- package/dist/components-harmony/image/index.js +28 -0
- package/dist/components-harmony/input/index.hml +21 -0
- package/dist/components-harmony/input/index.js +98 -0
- package/dist/components-harmony/label/index.hml +3 -0
- package/dist/components-harmony/label/index.js +6 -0
- package/dist/components-harmony/navbar/index.css +56 -0
- package/dist/components-harmony/navbar/index.hml +9 -0
- package/dist/components-harmony/navbar/index.js +30 -0
- package/dist/components-harmony/navigator/index.css +8 -0
- package/dist/components-harmony/navigator/index.hml +9 -0
- package/dist/components-harmony/navigator/index.js +104 -0
- package/dist/components-harmony/picker/index.hml +25 -0
- package/dist/components-harmony/picker/index.js +132 -0
- package/dist/components-harmony/picker-view/index.hml +23 -0
- package/dist/components-harmony/picker-view/index.js +161 -0
- package/dist/components-harmony/picker-view-column/index.hml +3 -0
- package/dist/components-harmony/picker-view-column/index.js +3 -0
- package/dist/components-harmony/progress/index.css +4 -0
- package/dist/components-harmony/progress/index.hml +28 -0
- package/dist/components-harmony/progress/index.js +23 -0
- package/dist/components-harmony/radio/index.hml +11 -0
- package/dist/components-harmony/radio/index.js +41 -0
- package/dist/components-harmony/radio-group/index.hml +3 -0
- package/dist/components-harmony/radio-group/index.js +11 -0
- package/dist/components-harmony/rich-text/index.hml +5 -0
- package/dist/components-harmony/rich-text/index.js +16 -0
- package/dist/components-harmony/scroll-view/index.css +5 -0
- package/dist/components-harmony/scroll-view/index.hml +12 -0
- package/dist/components-harmony/scroll-view/index.js +65 -0
- package/dist/components-harmony/slider/index.hml +16 -0
- package/dist/components-harmony/slider/index.js +53 -0
- package/dist/components-harmony/swiper/index.css +3 -0
- package/dist/components-harmony/swiper/index.hml +14 -0
- package/dist/components-harmony/swiper/index.js +19 -0
- package/dist/components-harmony/switch/index.hml +7 -0
- package/dist/components-harmony/switch/index.js +16 -0
- package/dist/components-harmony/tabbar/index.css +7 -0
- package/dist/components-harmony/tabbar/index.hml +26 -0
- package/dist/components-harmony/tabbar/index.js +42 -0
- package/dist/components-harmony/textarea/index.hml +24 -0
- package/dist/components-harmony/textarea/index.js +92 -0
- package/dist/components-harmony/utils/index.js +41 -0
- package/dist/components-harmony/video/index.hml +7 -0
- package/dist/components-harmony/video/index.js +73 -0
- package/dist/components-harmony/web-view/index.hml +8 -0
- package/dist/components-harmony/web-view/index.js +22 -0
- package/dist/components-harmony-ets/base.ets +63 -0
- package/dist/components-harmony-ets/button.ets +119 -0
- package/dist/components-harmony-ets/checkbox.ets +219 -0
- package/dist/components-harmony-ets/element.ets +223 -0
- package/dist/components-harmony-ets/form.ets +149 -0
- package/dist/components-harmony-ets/icon.ets +84 -0
- package/dist/components-harmony-ets/image.ets +85 -0
- package/dist/components-harmony-ets/index.ts +49 -0
- package/dist/components-harmony-ets/innerHtml.ets +79 -0
- package/dist/components-harmony-ets/input.ets +195 -0
- package/dist/components-harmony-ets/label.ets +111 -0
- package/dist/components-harmony-ets/picker.ets +370 -0
- package/dist/components-harmony-ets/radio.ets +225 -0
- package/dist/components-harmony-ets/richText.ets +97 -0
- package/dist/components-harmony-ets/scrollView.ets +199 -0
- package/dist/components-harmony-ets/slider.ets +159 -0
- package/dist/components-harmony-ets/swiper.ets +204 -0
- package/dist/components-harmony-ets/switch.ets +113 -0
- package/dist/components-harmony-ets/text.ets +97 -0
- package/dist/components-harmony-ets/textArea.ets +169 -0
- package/dist/components-harmony-ets/utils/AttributeManager.ets +250 -0
- package/dist/components-harmony-ets/utils/DynamicCenter.ts +48 -0
- package/dist/components-harmony-ets/utils/constant/event.ets +25 -0
- package/dist/components-harmony-ets/utils/constant/icon.ts +19 -0
- package/dist/components-harmony-ets/utils/constant/style.ets +88 -0
- package/dist/components-harmony-ets/utils/events.ts +24 -0
- package/dist/components-harmony-ets/utils/flexManager.ets +107 -0
- package/dist/components-harmony-ets/utils/helper.ets +99 -0
- package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +103 -0
- package/dist/components-harmony-ets/utils/htmlParser/index.ts +56 -0
- package/dist/components-harmony-ets/utils/index.ts +83 -0
- package/dist/components-harmony-ets/utils/styles.ets +91 -0
- package/dist/components-harmony-ets/video.ets +161 -0
- package/dist/components-harmony-ets/view.ets +79 -0
- package/dist/index.js +1183 -0
- package/dist/index.js.map +1 -0
- package/dist/runtime-ets/bom/document.ts +38 -0
- package/dist/runtime-ets/bom/getComputedStyle.ts +5 -0
- package/dist/runtime-ets/bom/navigator.ts +21 -0
- package/dist/runtime-ets/bom/raf.ts +37 -0
- package/dist/runtime-ets/bom/window.ts +44 -0
- package/dist/runtime-ets/constant.ts +29 -0
- package/dist/runtime-ets/current.ts +16 -0
- package/dist/runtime-ets/dom/class-list.ts +117 -0
- package/dist/runtime-ets/dom/comment.ts +10 -0
- package/dist/runtime-ets/dom/cssStyleDeclaration.ts +105 -0
- package/dist/runtime-ets/dom/document.ts +108 -0
- package/dist/runtime-ets/dom/element.ts +457 -0
- package/dist/runtime-ets/dom/event.ts +164 -0
- package/dist/runtime-ets/dom/eventTarget.ts +98 -0
- package/dist/runtime-ets/dom/node.ts +215 -0
- package/dist/runtime-ets/dom/stylesheet/index.ts +687 -0
- package/dist/runtime-ets/dom/stylesheet/type.ts +136 -0
- package/dist/runtime-ets/dom/stylesheet/util.ts +134 -0
- package/dist/runtime-ets/dom/text.ts +19 -0
- package/dist/runtime-ets/index.ts +19 -0
- package/dist/runtime-ets/interface/event.ts +9 -0
- package/dist/runtime-ets/interface/index.ts +1 -0
- package/dist/runtime-ets/utils/bind.ts +35 -0
- package/dist/runtime-ets/utils/index.ts +135 -0
- package/dist/runtime-ets/utils/info.ts +128 -0
- package/dist/runtime-framework/react/app.ts +256 -0
- package/dist/runtime-framework/react/connect.ts +24 -0
- package/dist/runtime-framework/react/constant.ts +5 -0
- package/dist/runtime-framework/react/hooks.ts +101 -0
- package/dist/runtime-framework/react/index.ts +16 -0
- package/dist/runtime-framework/react/page.ts +263 -0
- package/dist/runtime-framework/react/utils/index.ts +25 -0
- package/dist/runtime-framework/react/utils/is.ts +46 -0
- package/dist/runtime-framework/solid/README.md +99 -0
- package/dist/runtime-framework/solid/app.ts +200 -0
- package/dist/runtime-framework/solid/connect.ts +11 -0
- package/dist/runtime-framework/solid/contant.ts +5 -0
- package/dist/runtime-framework/solid/hooks.ts +88 -0
- package/dist/runtime-framework/solid/index.ts +10 -0
- package/dist/runtime-framework/solid/page.ts +202 -0
- package/dist/runtime-framework/solid/reconciler/h.ts +132 -0
- package/dist/runtime-framework/solid/reconciler/index.ts +3 -0
- package/dist/runtime-framework/solid/reconciler/props.ts +151 -0
- package/dist/runtime-framework/solid/reconciler/render.ts +61 -0
- package/dist/runtime-framework/solid/reconciler/use.ts +8 -0
- package/dist/runtime-framework/solid/utils/index.ts +49 -0
- package/dist/runtime-framework/solid/utils/is.ts +46 -0
- package/dist/runtime-utils.js +4149 -0
- package/dist/runtime-utils.js.map +1 -0
- package/dist/runtime.js +4150 -0
- package/dist/runtime.js.map +1 -0
- package/dist/template/container.js +7 -0
- package/index.js +4 -0
- package/package.json +54 -0
- package/types/api.d.ts +4 -0
- package/types/component.d.ts +4 -0
- package/types/harmony.d.ts +11 -0
- package/types/runtime.d.ts +15 -0
- package/types/taro.d.ts +7 -0
- package/types/webpack-sources.d.ts +108 -0
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { convertNumber2VP, TaroAny } from '@tarojs/runtime'
|
|
2
|
+
import matrix4 from '@ohos.matrix4'
|
|
3
|
+
|
|
4
|
+
type matrixNums = [number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number]
|
|
5
|
+
|
|
6
|
+
interface IRotate {
|
|
7
|
+
x?: number,
|
|
8
|
+
y?: number,
|
|
9
|
+
z?: number,
|
|
10
|
+
angle: number | string,
|
|
11
|
+
centerX?: number | string,
|
|
12
|
+
centerY?: number | string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface ITranslate {
|
|
16
|
+
x?: number | string,
|
|
17
|
+
y?: number | string,
|
|
18
|
+
z? : number | string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface IScale {
|
|
22
|
+
x?: number,
|
|
23
|
+
y?: number,
|
|
24
|
+
z?: number,
|
|
25
|
+
centerX?: number | string,
|
|
26
|
+
centerY?: number | string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface ITransform {
|
|
30
|
+
rotate: IRotate
|
|
31
|
+
translate: ITranslate
|
|
32
|
+
scale: IScale
|
|
33
|
+
transform?: matrix4.Matrix4Transit
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
class AttributeManager {
|
|
37
|
+
|
|
38
|
+
static getNodeStyle<T = TaroAny> (style: TaroAny = {}, name: string, defaultValue?: TaroAny): T {
|
|
39
|
+
const res: TaroAny = style[name]
|
|
40
|
+
|
|
41
|
+
if (res === undefined) return defaultValue
|
|
42
|
+
|
|
43
|
+
return res
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
static getTextAlign (style: TaroAny = {}): TextAlign {
|
|
47
|
+
const value: string = style.textAlign
|
|
48
|
+
switch (value) {
|
|
49
|
+
case 'right':
|
|
50
|
+
return TextAlign.End
|
|
51
|
+
case 'center':
|
|
52
|
+
return TextAlign.Center
|
|
53
|
+
default:
|
|
54
|
+
return TextAlign.Start
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
static getNodeAnimationData (style: TaroAny = {}): TaroAny {
|
|
59
|
+
let res: TaroAny = {}
|
|
60
|
+
const dataValue: string = AttributeManager.getNodeStyle(style, 'animation')
|
|
61
|
+
|
|
62
|
+
if (dataValue) {
|
|
63
|
+
let values: string[] = dataValue.trim().split(new RegExp("/\s+/"))
|
|
64
|
+
switch (values.length) {
|
|
65
|
+
case 4:
|
|
66
|
+
res = { duration: values[0], curve: values[1], delay: values[2] }
|
|
67
|
+
break
|
|
68
|
+
case 8:
|
|
69
|
+
res = { duration: values[0], curve: values[1], delay: values[2], iterations: values[3], playMode: values[4] }
|
|
70
|
+
break
|
|
71
|
+
default:
|
|
72
|
+
break
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
Object.keys(res).forEach(key => {
|
|
76
|
+
if (!isNaN(res[key]) && values.length > 1) {
|
|
77
|
+
res[key] = convertNumber2VP(res[key])
|
|
78
|
+
}
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
let playMode: PlayMode
|
|
83
|
+
switch (AttributeManager.getNodeStyle(style, 'animationDirection') || res.playMode) {
|
|
84
|
+
case 'reverse':
|
|
85
|
+
playMode = PlayMode.Reverse
|
|
86
|
+
break
|
|
87
|
+
case 'alternate':
|
|
88
|
+
playMode = PlayMode.Alternate
|
|
89
|
+
break
|
|
90
|
+
case 'alternate-reverse':
|
|
91
|
+
playMode = PlayMode.AlternateReverse
|
|
92
|
+
break
|
|
93
|
+
case 'normal':
|
|
94
|
+
default:
|
|
95
|
+
playMode = PlayMode.Normal
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
duration: AttributeManager.parseTime2Number(AttributeManager.getNodeStyle(style, 'animationDuration') || res.duration || 1000),
|
|
99
|
+
tempo: 1,
|
|
100
|
+
curve: AttributeManager.getNodeStyle(style, 'animationTimingFunction') || res.curve || Curve.EaseInOut,
|
|
101
|
+
delay: AttributeManager.parseTime2Number(AttributeManager.getNodeStyle(style, 'animationDelay') || res.delay || 0),
|
|
102
|
+
iterations: Number(AttributeManager.getNodeStyle(style, 'animationIterationCount') || res.iterations) || 1,
|
|
103
|
+
playMode,
|
|
104
|
+
// TODO onFinish
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
static parseTime2Number (time = ''): number {
|
|
109
|
+
if (typeof time === 'number') return time
|
|
110
|
+
if (time === 'infinite') return Infinity
|
|
111
|
+
if (time === 'auto') return 0
|
|
112
|
+
|
|
113
|
+
const matchs = time.match(new RegExp("/^(\d*)([a-z]*)$/")) || []
|
|
114
|
+
|
|
115
|
+
const value = matchs[1]
|
|
116
|
+
const unit = matchs[2]
|
|
117
|
+
|
|
118
|
+
let ms = Number(value)
|
|
119
|
+
switch (unit) {
|
|
120
|
+
case 's':
|
|
121
|
+
ms *= 1000
|
|
122
|
+
break
|
|
123
|
+
case 'ms':
|
|
124
|
+
default:
|
|
125
|
+
ms *= 1
|
|
126
|
+
}
|
|
127
|
+
return ms
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
static getTransform(style: TaroAny = {}): ITransform {
|
|
131
|
+
const transform: string = style.transform || ''
|
|
132
|
+
const transformOrigin: string = AttributeManager.getNodeStyle(style, 'transformOrigin') || '0 0'
|
|
133
|
+
|
|
134
|
+
const origin: (string | number)[] = transformOrigin.split(new RegExp("/\s+/")).map(item => item)
|
|
135
|
+
|
|
136
|
+
const result: ITransform = {
|
|
137
|
+
rotate: { angle: 0 },
|
|
138
|
+
translate: {},
|
|
139
|
+
scale: {},
|
|
140
|
+
}
|
|
141
|
+
let resultTransform: matrix4.Matrix4Transit
|
|
142
|
+
|
|
143
|
+
const matches = transform.match(new RegExp("/(\w+)\(([^)]+)\)/g")) || [];
|
|
144
|
+
|
|
145
|
+
// 处理matrix
|
|
146
|
+
|
|
147
|
+
matches.forEach(match => {
|
|
148
|
+
const matchs = match.split(new RegExp("/\(|\)/")).filter(Boolean);
|
|
149
|
+
const name: string = matchs[0]
|
|
150
|
+
const params: string[] = []
|
|
151
|
+
for (let i = 1; i < matchs.length; i++) {
|
|
152
|
+
params.push(matchs[i])
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
switch (name) {
|
|
156
|
+
case 'translateX':
|
|
157
|
+
result.translate.x = parseTransformUnit(params[0])
|
|
158
|
+
break;
|
|
159
|
+
case 'translateY':
|
|
160
|
+
result.translate.y = parseTransformUnit(params[0])
|
|
161
|
+
break;
|
|
162
|
+
case 'translateZ':
|
|
163
|
+
result.translate.z = parseTransformUnit(params[0])
|
|
164
|
+
break;
|
|
165
|
+
case 'scaleX':
|
|
166
|
+
result.scale.x = parseFloat(params[0])
|
|
167
|
+
break;
|
|
168
|
+
case 'scaleY':
|
|
169
|
+
result.scale.y = parseFloat(params[0])
|
|
170
|
+
break;
|
|
171
|
+
case 'scaleZ':
|
|
172
|
+
result.scale.z = parseFloat(params[0])
|
|
173
|
+
break;
|
|
174
|
+
case 'rotateX':
|
|
175
|
+
result.rotate.x = parseFloat(params[0])
|
|
176
|
+
break;
|
|
177
|
+
case 'rotateY':
|
|
178
|
+
result.rotate.y = parseFloat(params[0])
|
|
179
|
+
break;
|
|
180
|
+
case 'rotateZ':
|
|
181
|
+
result.rotate.z = parseFloat(params[0])
|
|
182
|
+
break;
|
|
183
|
+
case 'translate':
|
|
184
|
+
const xy = params[0].split(new RegExp("/\s*,\s*/"))
|
|
185
|
+
result.translate.x = parseTransformUnit(xy[0])
|
|
186
|
+
result.translate.y = parseTransformUnit(xy[1])
|
|
187
|
+
break;
|
|
188
|
+
case 'translate3d':
|
|
189
|
+
const xyz = params[0].split(new RegExp("/\s*,\s*/"))
|
|
190
|
+
result.translate.x = parseTransformUnit(xyz[0])
|
|
191
|
+
result.translate.y = parseTransformUnit(xyz[1])
|
|
192
|
+
result.translate.z = parseTransformUnit(xyz[2])
|
|
193
|
+
break;
|
|
194
|
+
case 'scale':
|
|
195
|
+
result.scale.x = parseFloat(params[0])
|
|
196
|
+
result.scale.y = parseFloat(params[1]) || result.scale.x
|
|
197
|
+
break;
|
|
198
|
+
case 'scale3d':
|
|
199
|
+
result.scale.x = parseFloat(params[0])
|
|
200
|
+
result.scale.y = parseFloat(params[1]) || result.scale.x
|
|
201
|
+
result.scale.z = parseFloat(params[2]) || result.scale.x
|
|
202
|
+
break;
|
|
203
|
+
case 'rotate':
|
|
204
|
+
const angle = parseFloat(params[0])
|
|
205
|
+
const axis = parseTransformUnit(params[1]) || 'z';
|
|
206
|
+
switch (axis) {
|
|
207
|
+
case 'x': result.rotate.x = angle; break
|
|
208
|
+
case 'y': result.rotate.y = angle; break
|
|
209
|
+
case 'z': result.rotate.z = angle; break
|
|
210
|
+
}
|
|
211
|
+
break;
|
|
212
|
+
case 'rotate3d':
|
|
213
|
+
result.rotate.x = parseFloat(params[0]) || 0
|
|
214
|
+
result.rotate.y = parseFloat(params[1]) || 0
|
|
215
|
+
result.rotate.z = parseFloat(params[2]) || 0
|
|
216
|
+
break;
|
|
217
|
+
case 'matrix':
|
|
218
|
+
const matrixArr: number[] = params[0].split(',').map(item => parseFloat(item))
|
|
219
|
+
result.transform = matrix4.init(convertMatrixToMatrix3d(matrixArr))
|
|
220
|
+
break;
|
|
221
|
+
case 'matrix3d':
|
|
222
|
+
const matrix3dArr: number[] = params[0].split(',').map(item => parseFloat(item))
|
|
223
|
+
result.transform = matrix4.init(matrix3dArr as matrixNums)
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
return result
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
function parseTransformUnit (val: string) {
|
|
234
|
+
return parseFloat(val) === 0 ? 0 : val
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
// matrix 转 matrix3d
|
|
239
|
+
function convertMatrixToMatrix3d(matrix2d: number[]): matrixNums {
|
|
240
|
+
const matrix3d: number[] = new Array(16).fill(0);
|
|
241
|
+
matrix3d[0] = matrix2d[0];
|
|
242
|
+
matrix3d[5] = matrix2d[3];
|
|
243
|
+
matrix3d[10] = 1;
|
|
244
|
+
matrix3d[15] = 1;
|
|
245
|
+
matrix3d[12] = matrix2d[4];
|
|
246
|
+
matrix3d[13] = matrix2d[5];
|
|
247
|
+
return matrix3d as matrixNums;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export { AttributeManager }
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { bindFocus, bindInstanceToNode, bindScrollTo, initComponentNodeInfo, TaroAny, TaroElement } from '@tarojs/runtime'
|
|
2
|
+
|
|
3
|
+
import { bindAnimation } from './helper'
|
|
4
|
+
|
|
5
|
+
export class DynamicCenter {
|
|
6
|
+
|
|
7
|
+
install (node: TaroElement, parentNode: TaroElement) {
|
|
8
|
+
if (!parentNode._isCompileMode) return
|
|
9
|
+
|
|
10
|
+
this.bindComponentToNodeWithDFS(node, parentNode._instance)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
uninstall (node: TaroElement) {
|
|
14
|
+
if (!node._isCompileMode || !node._instance) return
|
|
15
|
+
|
|
16
|
+
if (node._attrs?._dynamicID) {
|
|
17
|
+
node._instance[node._attrs._dynamicID] = null
|
|
18
|
+
}
|
|
19
|
+
node._instance = null
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
bindComponentToNodeWithDFS (node: TaroElement, component: TaroAny) {
|
|
23
|
+
if (!node) return
|
|
24
|
+
|
|
25
|
+
const dynamicID = node._attrs?._dynamicID
|
|
26
|
+
|
|
27
|
+
// dynamicID 只是为了更新到精准的 node
|
|
28
|
+
// 而为了让半编译模板中每个 node 都能响应 api 的调用,因此 initComponentNodeInfo、bindInstanceToNode 和各种 bindAttribute 都需要执行
|
|
29
|
+
initComponentNodeInfo(component, node)
|
|
30
|
+
bindInstanceToNode(node, component)
|
|
31
|
+
bindFocus(node)
|
|
32
|
+
bindAnimation(node)
|
|
33
|
+
bindScrollTo(node, component)
|
|
34
|
+
|
|
35
|
+
node._isCompileMode = true
|
|
36
|
+
|
|
37
|
+
if (dynamicID) {
|
|
38
|
+
node._isDynamicNode = true
|
|
39
|
+
component[dynamicID] = node
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (!node.childNodes || !node.childNodes.length) return
|
|
43
|
+
|
|
44
|
+
for (let i = 0; i < node.childNodes.length; i++) {
|
|
45
|
+
this.bindComponentToNodeWithDFS(node.childNodes[i] as TaroElement, component)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export class TOUCH_EVENT_MAP {
|
|
2
|
+
static readonly TouchTypeUp = 'touchend'
|
|
3
|
+
static readonly TouchTypeMove = 'touchmove'
|
|
4
|
+
static readonly TouchTypeDown = 'touchstart'
|
|
5
|
+
static readonly TouchTypeCancel = 'touchcancel'
|
|
6
|
+
|
|
7
|
+
static get (event: TouchType) {
|
|
8
|
+
switch (event) {
|
|
9
|
+
case TouchType.Up: return TOUCH_EVENT_MAP.TouchTypeUp
|
|
10
|
+
case TouchType.Move: return TOUCH_EVENT_MAP.TouchTypeMove
|
|
11
|
+
case TouchType.Down: return TOUCH_EVENT_MAP.TouchTypeDown
|
|
12
|
+
case TouchType.Cancel: return TOUCH_EVENT_MAP.TouchTypeCancel
|
|
13
|
+
}
|
|
14
|
+
return TOUCH_EVENT_MAP.TouchTypeUp
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static values () {
|
|
18
|
+
return [
|
|
19
|
+
TOUCH_EVENT_MAP.TouchTypeUp,
|
|
20
|
+
TOUCH_EVENT_MAP.TouchTypeMove,
|
|
21
|
+
TOUCH_EVENT_MAP.TouchTypeUp,
|
|
22
|
+
TOUCH_EVENT_MAP.TouchTypeUp,
|
|
23
|
+
]
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const _ICON_SVG_MAP = {
|
|
2
|
+
success: 'data:image/svg+xml,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M12%2022C6.477%2022%202%2017.523%202%2012S6.477%202%2012%202s10%204.477%2010%2010-4.477%2010-10%2010zm-1.177-7.86l-2.765-2.767L7%2012.431l3.119%203.121a1%201%200%20001.414%200l5.952-5.95-1.062-1.062-5.6%205.6z%22%2F%3E%3C%2Fsvg%3E',
|
|
3
|
+
success_no_circle: 'data:image/svg+xml,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M8.657%2018.435L3%2012.778l1.414-1.414%204.95%204.95L20.678%205l1.414%201.414-12.02%2012.021a1%201%200%2001-1.415%200z%22%20fill-rule%3D%22evenodd%22%2F%3E%3C%2Fsvg%3E',
|
|
4
|
+
info: 'data:image/svg+xml,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M12%2022C6.477%2022%202%2017.523%202%2012S6.477%202%2012%202s10%204.477%2010%2010-4.477%2010-10%2010zm-.75-12v7h1.5v-7h-1.5zM12%209a1%201%200%20100-2%201%201%200%20000%202z%22%2F%3E%3C%2Fsvg%3E',
|
|
5
|
+
warn: 'data:image/svg+xml,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M12%2022C6.477%2022%202%2017.523%202%2012S6.477%202%2012%202s10%204.477%2010%2010-4.477%2010-10%2010zm-.763-15.864l.11%207.596h1.305l.11-7.596h-1.525zm.759%2010.967c.512%200%20.902-.383.902-.882%200-.5-.39-.882-.902-.882a.878.878%200%2000-.896.882c0%20.499.396.882.896.882z%22%2F%3E%3C%2Fsvg%3E',
|
|
6
|
+
waiting: 'data:image/svg+xml,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M12.75%2011.38V6h-1.5v6l4.243%204.243%201.06-1.06-3.803-3.804zM12%2022C6.477%2022%202%2017.523%202%2012S6.477%202%2012%202s10%204.477%2010%2010-4.477%2010-10%2010z%22%20fill-rule%3D%22evenodd%22%2F%3E%3C%2Fsvg%3E',
|
|
7
|
+
cancel: 'data:image/svg+xml,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cg%20fill-rule%3D%22evenodd%22%3E%3Cpath%20d%3D%22M12%2022C6.477%2022%202%2017.523%202%2012S6.477%202%2012%202s10%204.477%2010%2010-4.477%2010-10%2010zm0-1.2a8.8%208.8%200%20100-17.6%208.8%208.8%200%20000%2017.6z%22%20fill-rule%3D%22nonzero%22%2F%3E%3Cpath%20d%3D%22M12.849%2012l3.11%203.111-.848.849L12%2012.849l-3.111%203.11-.849-.848L11.151%2012l-3.11-3.111.848-.849L12%2011.151l3.111-3.11.849.848L12.849%2012z%22%2F%3E%3C%2Fg%3E%3C%2Fsvg%3E',
|
|
8
|
+
download: 'data:image/svg+xml,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M11.25%2012.04l-1.72-1.72-1.06%201.06%202.828%202.83a1%201%200%20001.414-.001l2.828-2.828-1.06-1.061-1.73%201.73V7h-1.5v5.04zm0-5.04V2h1.5v5h6.251c.55%200%20.999.446.999.996v13.008a.998.998%200%2001-.996.996H4.996A.998.998%200%20014%2021.004V7.996A1%201%200%20014.999%207h6.251z%22%2F%3E%3C%2Fsvg%3E',
|
|
9
|
+
search: 'data:image/svg+xml,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M16.31%2015.561l4.114%204.115-.848.848-4.123-4.123a7%207%200%2011.857-.84zM16.8%2011a5.8%205.8%200%2010-11.6%200%205.8%205.8%200%200011.6%200z%22%20fill-rule%3D%22evenodd%22%2F%3E%3C%2Fsvg%3E',
|
|
10
|
+
clear: 'data:image/svg+xml,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M13.06%2012l3.006-3.005-1.06-1.06L12%2010.938%208.995%207.934l-1.06%201.06L10.938%2012l-3.005%203.005%201.06%201.06L12%2013.062l3.005%203.005%201.06-1.06L13.062%2012zM12%2022C6.477%2022%202%2017.523%202%2012S6.477%202%2012%202s10%204.477%2010%2010-4.477%2010-10%2010z%22%2F%3E%3C%2Fsvg%3E',
|
|
11
|
+
circle: 'data:image/svg+xml,%3Csvg%20width%3D%221000%22%20height%3D%221000%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M500%20916.667C269.881%20916.667%2083.333%20730.119%2083.333%20500%2083.333%20269.881%20269.881%2083.333%20500%2083.333c230.119%200%20416.667%20186.548%20416.667%20416.667%200%20230.119-186.548%20416.667-416.667%20416.667zm0-50c202.504%200%20366.667-164.163%20366.667-366.667%200-202.504-164.163-366.667-366.667-366.667-202.504%200-366.667%20164.163-366.667%20366.667%200%20202.504%20164.163%20366.667%20366.667%20366.667z%22%20fill-rule%3D%22evenodd%22%20fill-opacity%3D%22.9%22%2F%3E%3C%2Fsvg%3E',
|
|
12
|
+
info_circle: 'data:image/svg+xml,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M12%2022C6.477%2022%202%2017.523%202%2012S6.477%202%2012%202s10%204.477%2010%2010-4.477%2010-10%2010zm0-1.2a8.8%208.8%200%20100-17.6%208.8%208.8%200%20000%2017.6zM11.4%2010h1.2v7h-1.2v-7zm.6-1a1%201%200%20110-2%201%201%200%20010%202z%22%2F%3E%3C%2Fsvg%3E',
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class ICON_SVG_MAP {
|
|
16
|
+
static get (key: string): string {
|
|
17
|
+
return _ICON_SVG_MAP[key]
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// 各种组件的默认样式
|
|
2
|
+
|
|
3
|
+
export class TEXT_DEFAULT_STYLE {
|
|
4
|
+
static COLOR = 'black'
|
|
5
|
+
static FONT_SIZE = '24'
|
|
6
|
+
static FONT_WEIGHT = FontWeight.Normal
|
|
7
|
+
static FONT_FAMILY = 'HarmonyOS Sans'
|
|
8
|
+
static TEXT_ALIGN = TextAlign.Start
|
|
9
|
+
static TEXT_OVERFLOW = TextOverflow.Clip
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface IBUTTON_THEME_COLOR {
|
|
13
|
+
text: string
|
|
14
|
+
background: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export class BUTTON_THEME_COLOR {
|
|
18
|
+
static get (type: string): IBUTTON_THEME_COLOR {
|
|
19
|
+
switch (type) {
|
|
20
|
+
case 'primary': return {
|
|
21
|
+
text: '#fff',
|
|
22
|
+
background: '#1aad19',
|
|
23
|
+
}
|
|
24
|
+
case 'warn': return {
|
|
25
|
+
text: '#fff',
|
|
26
|
+
background: '#e64340'
|
|
27
|
+
}
|
|
28
|
+
default: return {
|
|
29
|
+
text: '#000',
|
|
30
|
+
background: '#f7f7f7',
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
export class INPUT_TYPE_MAP {
|
|
38
|
+
static get (type: string) {
|
|
39
|
+
switch (type) {
|
|
40
|
+
case 'text': return InputType.Normal;
|
|
41
|
+
case 'number': return InputType.Number;
|
|
42
|
+
case 'idcard': return InputType.Number;
|
|
43
|
+
case 'safe-password': return InputType.Password;
|
|
44
|
+
}
|
|
45
|
+
return InputType.Normal
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export class INPUT_CONFIRM_MAP {
|
|
50
|
+
static go = EnterKeyType.Go // 右下角按钮为“前往”
|
|
51
|
+
static send = EnterKeyType.Send // 右下角按钮为“发送”
|
|
52
|
+
static done = EnterKeyType.Done // 右下角按钮为“完成”
|
|
53
|
+
static next = EnterKeyType.Next // 右下角按钮为“下一个”
|
|
54
|
+
static search = EnterKeyType.Search // 右下角按钮为“搜索”
|
|
55
|
+
|
|
56
|
+
static get (type: string) {
|
|
57
|
+
switch (type) {
|
|
58
|
+
case 'go': return EnterKeyType.Go
|
|
59
|
+
case 'send': return EnterKeyType.Send
|
|
60
|
+
case 'done': return EnterKeyType.Done
|
|
61
|
+
case 'next': return EnterKeyType.Next
|
|
62
|
+
case 'search': return EnterKeyType.Search
|
|
63
|
+
}
|
|
64
|
+
return EnterKeyType.Done
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export class CurveMap {
|
|
69
|
+
static default = Curve.Linear
|
|
70
|
+
static linear = Curve.Linear
|
|
71
|
+
static easeInCubic = Curve.EaseIn
|
|
72
|
+
static easeOutCubic = Curve.EaseOut
|
|
73
|
+
static easeInOutCubic = Curve.EaseInOut
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export class BORDER_STYLE_MAP {
|
|
77
|
+
static solid = BorderStyle.Solid
|
|
78
|
+
static dotted = BorderStyle.Dotted
|
|
79
|
+
static dashed = BorderStyle.Dashed
|
|
80
|
+
|
|
81
|
+
static get(type: string): BorderStyle {
|
|
82
|
+
switch (type) {
|
|
83
|
+
case 'dotted': return BorderStyle.Dotted;
|
|
84
|
+
case 'dashed': return BorderStyle.Dashed;
|
|
85
|
+
default: return BorderStyle.Solid;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { EventOptions, TaroElement, TaroEvent } from '@tarojs/runtime'
|
|
2
|
+
|
|
3
|
+
export function createTaroEvent(type: string, opts: Partial<EventOptions> = {}, node?: TaroElement) {
|
|
4
|
+
opts.bubbles ||= true
|
|
5
|
+
opts.cancelable ||= true
|
|
6
|
+
const e = new TaroEvent(type, opts as Required<EventOptions>)
|
|
7
|
+
|
|
8
|
+
if (node) {
|
|
9
|
+
const properties: Record<string, PropertyDescriptor> = {}
|
|
10
|
+
properties.target = properties.currentTarget = {
|
|
11
|
+
get() {
|
|
12
|
+
return node
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
Object.defineProperties(e, properties)
|
|
16
|
+
}
|
|
17
|
+
for (const key in opts) {
|
|
18
|
+
if (['bubbles', 'cancelable'].includes(key)) {
|
|
19
|
+
continue
|
|
20
|
+
}
|
|
21
|
+
e[key] = opts[key]
|
|
22
|
+
}
|
|
23
|
+
return e
|
|
24
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type { TaroAny, TaroElement } from '@tarojs/runtime'
|
|
2
|
+
|
|
3
|
+
class FlexManager {
|
|
4
|
+
static flexOptions (node: TaroElement): FlexOptions {
|
|
5
|
+
const hmStyle = node.hmStyle
|
|
6
|
+
|
|
7
|
+
let flexDirection = hmStyle.direction
|
|
8
|
+
if (!flexDirection && flexDirection !== 0) {
|
|
9
|
+
flexDirection = hmStyle.display === 'flex' ? FlexDirection.Row : FlexDirection.Column
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
direction: flexDirection,
|
|
14
|
+
justifyContent: hmStyle.justifyContent,
|
|
15
|
+
alignItems: hmStyle.alignItems
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
static flexAlign (value: string | number | undefined): FlexAlign {
|
|
20
|
+
switch (value) {
|
|
21
|
+
case 'flex-end':
|
|
22
|
+
return FlexAlign.End
|
|
23
|
+
case 'center':
|
|
24
|
+
return FlexAlign.Center
|
|
25
|
+
case 'space-between':
|
|
26
|
+
return FlexAlign.SpaceBetween
|
|
27
|
+
case 'space-around':
|
|
28
|
+
return FlexAlign.SpaceAround
|
|
29
|
+
case 'space-evenly':
|
|
30
|
+
return FlexAlign.SpaceEvenly
|
|
31
|
+
default:
|
|
32
|
+
return FlexAlign.Start
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
static direction (value: string): FlexDirection {
|
|
37
|
+
switch (value) {
|
|
38
|
+
case 'row': return FlexDirection.Row;
|
|
39
|
+
case 'row-reverse': return FlexDirection.RowReverse;
|
|
40
|
+
case 'column-reverse': return FlexDirection.ColumnReverse;
|
|
41
|
+
default: return FlexDirection.Column;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static itemAlign (value: string | number | undefined): ItemAlign {
|
|
46
|
+
switch (value) {
|
|
47
|
+
case 'flex-start':
|
|
48
|
+
return ItemAlign.Start
|
|
49
|
+
case 'flex-end':
|
|
50
|
+
return ItemAlign.End
|
|
51
|
+
case 'center':
|
|
52
|
+
return ItemAlign.Center
|
|
53
|
+
case 'stretch':
|
|
54
|
+
return ItemAlign.Stretch
|
|
55
|
+
case 'baseline':
|
|
56
|
+
return ItemAlign.Baseline
|
|
57
|
+
default:
|
|
58
|
+
return ItemAlign.Auto
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
static justifyContent (value: string): FlexAlign {
|
|
63
|
+
return FlexManager.flexAlign(value)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
static alignItems (value: string): ItemAlign {
|
|
67
|
+
return FlexManager.itemAlign(value)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
static alignSelf (value: string): ItemAlign {
|
|
71
|
+
return FlexManager.itemAlign(value)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
static flexWrap (value: string): FlexWrap {
|
|
75
|
+
return value === 'wrap' ? FlexWrap.Wrap : FlexWrap.NoWrap
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
static alignContent (style: Record<string, string | number> = {}): FlexAlign | undefined {
|
|
79
|
+
if (style.flexWrap !== 'wrap') return undefined
|
|
80
|
+
const value = style.alignContent
|
|
81
|
+
return FlexManager.flexAlign(value)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
static flexSize (style: Record<string, string | number> = {}): [number, number, number | string] {
|
|
85
|
+
const flex = style.flex
|
|
86
|
+
const flexGrow = style.flexGrow || 0
|
|
87
|
+
const flexShrink = style.flexShrink || 0
|
|
88
|
+
const flexBasis = style.flexBasis || 'auto'
|
|
89
|
+
let res: [number, number, number | string] = [Number(flexGrow), Number(flexShrink), flexBasis]
|
|
90
|
+
|
|
91
|
+
if (typeof flex === 'number') {
|
|
92
|
+
res = [flex, 1, 0]
|
|
93
|
+
} else if (flex === 'auto') {
|
|
94
|
+
res = [1, 1, 'auto']
|
|
95
|
+
} else if (flex === 'none') {
|
|
96
|
+
res = [0, 0, 'auto']
|
|
97
|
+
} else if (typeof flex === 'string') {
|
|
98
|
+
const FlexList = flex.replace(new RegExp("/\s+/g"), ' ').split(' ')
|
|
99
|
+
FlexList.forEach((item, index) => {
|
|
100
|
+
res[index] = index < 2 ? Number(item) : item
|
|
101
|
+
})
|
|
102
|
+
}
|
|
103
|
+
return res
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export { FlexManager }
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { getNormalAttributes, getFontAttributes } from './styles'
|
|
2
|
+
import { bindAttributesCallback, ObjectAssign } from '@tarojs/runtime'
|
|
3
|
+
|
|
4
|
+
import type { TaroAny, TaroElement } from '@tarojs/runtime'
|
|
5
|
+
import type { Func } from '@tarojs/runtime/dist/runtime.esm'
|
|
6
|
+
|
|
7
|
+
export const parseStyles = (styles = ''): Record<string, string> => {
|
|
8
|
+
const styleObj: Record<string, string> = {}
|
|
9
|
+
styles
|
|
10
|
+
.split(';')
|
|
11
|
+
.filter((style) => style.split(':').length === 2)
|
|
12
|
+
.map((style) => [
|
|
13
|
+
style.split(':')[0].trim().replace(new RegExp("/-./g"), c => c.substring(1).toUpperCase()),
|
|
14
|
+
style.split(':')[1].trim()
|
|
15
|
+
])
|
|
16
|
+
.forEach((style) => {
|
|
17
|
+
const key = style[0]
|
|
18
|
+
const value = style[1]
|
|
19
|
+
styleObj[key] = value
|
|
20
|
+
})
|
|
21
|
+
return styleObj
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
export function shouldBindEvent (cb: Func, node: TaroElement, eventNames: string[], disabled = false) {
|
|
26
|
+
if (!node || node._attrs?.disabled || disabled) return null
|
|
27
|
+
if (!node.__listeners) {
|
|
28
|
+
return null
|
|
29
|
+
}
|
|
30
|
+
const listeners = Object.keys(node.__listeners)
|
|
31
|
+
if (listeners.every(e => !eventNames.includes(e))) return null
|
|
32
|
+
return cb
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function getNodeThresholds (node: TaroElement): number[] | null {
|
|
36
|
+
if (!node) return null
|
|
37
|
+
|
|
38
|
+
const id = node._nid
|
|
39
|
+
const instance: TaroAny = node._instance
|
|
40
|
+
|
|
41
|
+
return instance?.nodeInfoMap?.[id]?.thresholds || null
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function convertToCamelCase(str: string) {
|
|
45
|
+
return str.replace(new RegExp("/-(.)/g"), (_, char: string) => char.toUpperCase()).replace(new RegExp("/^\w/"), firstChar => firstChar.toUpperCase())
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// 动画绑定
|
|
49
|
+
export function bindAnimation (node: TaroElement) {
|
|
50
|
+
bindAttributesCallback(node, 'animation', async (animation: TaroAny) => {
|
|
51
|
+
if (animation && animation.actions) {
|
|
52
|
+
for (let i = 0; i < animation.actions.length; i++) {
|
|
53
|
+
const anim: TaroAny = animation.actions[i]
|
|
54
|
+
// 动画队列
|
|
55
|
+
await new Promise<TaroAny>((resolve: TaroAny) => {
|
|
56
|
+
const timingFunction: TaroAny = anim.timingFunction
|
|
57
|
+
const animateParams: AnimateParam = {
|
|
58
|
+
duration: anim.duration,
|
|
59
|
+
delay: anim.delay,
|
|
60
|
+
tempo: 1,
|
|
61
|
+
// TODO: ETS转TS
|
|
62
|
+
playMode: PlayMode.Normal,
|
|
63
|
+
iterations: 1,
|
|
64
|
+
onFinish: resolve
|
|
65
|
+
}
|
|
66
|
+
if (timingFunction === 'step-start') {
|
|
67
|
+
animateParams.tempo = 0
|
|
68
|
+
} else if (timingFunction === 'step-end') {
|
|
69
|
+
animateParams.tempo = 0
|
|
70
|
+
animateParams.delay = anim.duration + anim.delay
|
|
71
|
+
animateParams.duration = 0
|
|
72
|
+
}
|
|
73
|
+
animateParams.curve = Curve[convertToCamelCase(timingFunction)] || Curve.EaseInOut
|
|
74
|
+
animateTo(animateParams, () => {
|
|
75
|
+
const component: TaroAny = node._instance
|
|
76
|
+
const transformOrigin: string = anim.transformOrigin
|
|
77
|
+
|
|
78
|
+
if (transformOrigin) {
|
|
79
|
+
const splitOrigin = transformOrigin.split(' ')
|
|
80
|
+
Object.keys(anim.rule).forEach(key => {
|
|
81
|
+
if (['scale', 'rotate'].includes(key)) {
|
|
82
|
+
anim.rule[key] = ObjectAssign(anim.rule[key], {
|
|
83
|
+
centerX: splitOrigin[0],
|
|
84
|
+
centerY: splitOrigin[1],
|
|
85
|
+
})
|
|
86
|
+
}
|
|
87
|
+
})
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
component.nodeInfoMap[node._nid].overwriteStyle = anim.rule
|
|
91
|
+
node.updateComponent()
|
|
92
|
+
})
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
})
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export { getNormalAttributes, getFontAttributes }
|