@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,285 @@
|
|
|
1
|
+
import { TaroNativeModule } from '../../harmony-library'
|
|
2
|
+
import { TaroElement } from './element'
|
|
3
|
+
|
|
4
|
+
import type { CanvasProps, CanvasTouchEvent } from '@tarojs/components/types'
|
|
5
|
+
import type Taro from '@tarojs/taro/types'
|
|
6
|
+
|
|
7
|
+
export class CanvasRenderingContext2DWXAdapter extends CanvasRenderingContext2D {
|
|
8
|
+
// constructor(settings?: RenderingContextSetting) {
|
|
9
|
+
// super(settings)
|
|
10
|
+
// }
|
|
11
|
+
|
|
12
|
+
createCircularGradient() {
|
|
13
|
+
// Not supported now
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
draw(cb?: (...args: any[]) => any) {
|
|
17
|
+
typeof cb === 'function' && cb()
|
|
18
|
+
// Not supported now
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
setFillStyle(fillStyle: typeof this.fillStyle) {
|
|
22
|
+
this.fillStyle = fillStyle
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
setFontSize(fontSize: number) {
|
|
26
|
+
const font = this.font.split(' ')
|
|
27
|
+
font[2] = `${fontSize}`
|
|
28
|
+
this.font = font.join(' ')
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
setGlobalAlpha(globalAlpha: typeof this.globalAlpha) {
|
|
32
|
+
this.globalAlpha = globalAlpha
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
setLineCap(lineCap: typeof this.lineCap) {
|
|
36
|
+
this.lineCap = lineCap
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
setLineJoin(lineJoin: typeof this.lineJoin) {
|
|
40
|
+
this.lineJoin = lineJoin
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
setLineWidth(lineWidth: typeof this.lineWidth) {
|
|
44
|
+
this.lineWidth = lineWidth
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
setMiterLimit(miterLimit: typeof this.miterLimit) {
|
|
48
|
+
this.miterLimit = miterLimit
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
setShadow(offsetX: number, offsetY: number, blur: number, color: string) {
|
|
52
|
+
this.shadowOffsetX = offsetX
|
|
53
|
+
this.shadowOffsetY = offsetY
|
|
54
|
+
this.shadowBlur = blur
|
|
55
|
+
this.shadowColor = color
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
setStrokeStyle(strokeStyle: typeof this.strokeStyle) {
|
|
59
|
+
this.strokeStyle = strokeStyle
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
setTextAlign(textAlign: typeof this.textAlign) {
|
|
63
|
+
this.textAlign = textAlign
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
setTextBaseline(textBaseline: typeof this.textBaseline) {
|
|
67
|
+
this.textBaseline = textBaseline
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
class TaroCanvasContext {
|
|
72
|
+
type = '2d'
|
|
73
|
+
element: TaroCanvasElement
|
|
74
|
+
|
|
75
|
+
private font_ = ''
|
|
76
|
+
|
|
77
|
+
setStrokeStyle(color: string): void {
|
|
78
|
+
TaroNativeModule.executeNodeFunc(this.element, 'setStrokeStyle', color)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
setLineWidth(lineWidth: number): void {
|
|
82
|
+
TaroNativeModule.executeNodeFunc(this.element, 'setLineWidth', lineWidth)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
rect(x: number, y: number, width: number, height: number): void {
|
|
86
|
+
TaroNativeModule.executeNodeFunc(this.element, 'rect', [x, y, width, height])
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
draw(): Promise<void> {
|
|
90
|
+
return new Promise(resolve => {
|
|
91
|
+
TaroNativeModule.executeNodeFunc(this.element, 'drawAble', () => {
|
|
92
|
+
TaroNativeModule.executeNodeFunc(this.element, 'draw')
|
|
93
|
+
resolve()
|
|
94
|
+
})
|
|
95
|
+
})
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
stroke(): void {
|
|
99
|
+
TaroNativeModule.executeNodeFunc(this.element, 'stroke')
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
moveTo(x: number, y: number): void {
|
|
103
|
+
TaroNativeModule.executeNodeFunc(this.element, 'moveTo', [x, y])
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
arc(x: number, y: number, r: number, sAngle: number, eAngle: number, counterclockwise = false): void {
|
|
107
|
+
TaroNativeModule.executeNodeFunc(this.element, 'arc', [x, y, r, sAngle, eAngle, counterclockwise])
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
lineTo(x: number, y: number): void {
|
|
111
|
+
TaroNativeModule.executeNodeFunc(this.element, 'lineTo', [x, y])
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
setFontSize(fontSize: number): void {
|
|
115
|
+
TaroNativeModule.executeNodeFunc(this.element, 'setFontSize', fontSize)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
setTextAlign(textAlign: string): void {
|
|
119
|
+
TaroNativeModule.executeNodeFunc(this.element, 'setTextAlign', textAlign)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
fillText(text: string, x: number, y: number): void {
|
|
123
|
+
TaroNativeModule.executeNodeFunc(this.element, 'fillText', [text, x, y])
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
fillRect(x: number, y: number, width: number, height: number): void {
|
|
127
|
+
TaroNativeModule.executeNodeFunc(this.element, 'fillRect', [x, y, width, height])
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
strokeRect(x: number, y: number, width: number, height: number): void {
|
|
131
|
+
TaroNativeModule.executeNodeFunc(this.element, 'strokeRect', [x, y, width, height])
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
fill(): void {
|
|
135
|
+
TaroNativeModule.executeNodeFunc(this.element, 'fill')
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
setFillStyle(color: string): void {
|
|
139
|
+
TaroNativeModule.executeNodeFunc(this.element, 'setFillStyle', color)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
beginPath(): void {
|
|
143
|
+
TaroNativeModule.executeNodeFunc(this.element, 'beginPath')
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
closePath(): void {
|
|
147
|
+
TaroNativeModule.executeNodeFunc(this.element, 'closePath')
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
translate(x: number, y: number): void {
|
|
151
|
+
TaroNativeModule.executeNodeFunc(this.element, 'translate', [x, y])
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
rotate(rotate: number): void {
|
|
155
|
+
TaroNativeModule.executeNodeFunc(this.element, 'rotate', rotate)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
scale(scaleWidth: number, scaleHeight: number): void {
|
|
159
|
+
TaroNativeModule.executeNodeFunc(this.element, 'scale', [scaleWidth, scaleHeight])
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
get font () {
|
|
163
|
+
return this.font_
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
set font(value: string) {
|
|
167
|
+
this.font_ = value
|
|
168
|
+
TaroNativeModule.executeNodeFunc(this.element, 'font', this.font_)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
measureText(text: string): { width: number } {
|
|
172
|
+
return {
|
|
173
|
+
width: TaroNativeModule.executeNodeFunc(this.element, 'measure', text)
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
drawImage(...args): { width: number } {
|
|
178
|
+
// 解构参数
|
|
179
|
+
const [imageResource, ...rest] = args
|
|
180
|
+
let src = imageResource
|
|
181
|
+
if (imageResource instanceof TaroCanvasImage) {
|
|
182
|
+
src = imageResource.src
|
|
183
|
+
}
|
|
184
|
+
switch (rest.length) {
|
|
185
|
+
case 2: {
|
|
186
|
+
const [dx, dy] = rest
|
|
187
|
+
return this.drawSimple(src, dx, dy)
|
|
188
|
+
}
|
|
189
|
+
case 3:
|
|
190
|
+
case 4: {
|
|
191
|
+
const [dx2, dy2, dWidth, dHeight] = rest
|
|
192
|
+
return this.drawWithSize(src, dx2, dy2, dWidth, dHeight)
|
|
193
|
+
}
|
|
194
|
+
case 8: {
|
|
195
|
+
const [sx, sy, sWidth, sHeight, dx3, dy3, dWidth2, dHeight2] = rest
|
|
196
|
+
return this.drawWithCrop(src, sx, sy, sWidth, sHeight, dx3, dy3, dWidth2, dHeight2)
|
|
197
|
+
}
|
|
198
|
+
default:
|
|
199
|
+
throw new Error('Invalid number of arguments')
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
private drawSimple(src, dx, dy) {
|
|
204
|
+
return {
|
|
205
|
+
width: TaroNativeModule.executeNodeFunc(this.element, 'drawImage', {
|
|
206
|
+
src, dx, dy
|
|
207
|
+
})
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
private drawWithSize(src, dx, dy, dWidth, dHeight) {
|
|
212
|
+
return {
|
|
213
|
+
width: TaroNativeModule.executeNodeFunc(this.element, 'drawImage', {
|
|
214
|
+
src, dx, dy, dWidth, dHeight
|
|
215
|
+
})
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
private drawWithCrop(src, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight) {
|
|
220
|
+
return {
|
|
221
|
+
width: TaroNativeModule.executeNodeFunc(this.element, 'drawImage', {
|
|
222
|
+
src, dx, dy, dWidth, dHeight, sx, sy, sWidth, sHeight
|
|
223
|
+
})
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
reset(): void {
|
|
228
|
+
TaroNativeModule.executeNodeFunc(this.element, 'reset')
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
class TaroCanvasImage {
|
|
233
|
+
width: number
|
|
234
|
+
height: number
|
|
235
|
+
onload: () => void
|
|
236
|
+
onerror: () => void
|
|
237
|
+
|
|
238
|
+
private _src = ''
|
|
239
|
+
|
|
240
|
+
get src () {
|
|
241
|
+
return this._src
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
set src (val: string) {
|
|
245
|
+
this._src = val
|
|
246
|
+
|
|
247
|
+
TaroNativeModule.loadImage(val, (width, height) => {
|
|
248
|
+
this.width = width
|
|
249
|
+
this.height = height
|
|
250
|
+
if (typeof this.onload === 'function') {
|
|
251
|
+
this.onload()
|
|
252
|
+
}
|
|
253
|
+
}, () => {
|
|
254
|
+
if (typeof this.onerror === 'function') {
|
|
255
|
+
this.onerror()
|
|
256
|
+
}
|
|
257
|
+
})
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export class TaroCanvasElement extends TaroElement<CanvasProps, CanvasTouchEvent> {
|
|
262
|
+
constructor() {
|
|
263
|
+
super('Canvas')
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
getContext(_type = '2d') {
|
|
267
|
+
const canvasContext = new TaroCanvasContext()
|
|
268
|
+
canvasContext.element = this
|
|
269
|
+
return canvasContext
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
createImage() {
|
|
273
|
+
return new TaroCanvasImage()
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
toDataURL(type: string): string {
|
|
277
|
+
return this.exportDataUrl({
|
|
278
|
+
fileType: type as unknown as keyof Taro.canvasToTempFilePath.FileType
|
|
279
|
+
})
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
exportDataUrl(opts: Taro.canvasToTempFilePath.Option): string {
|
|
283
|
+
return TaroNativeModule.executeNodeFunc(this, 'toDataUrl', opts)
|
|
284
|
+
}
|
|
285
|
+
}
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { ATTRIBUTES_CALLBACK_TRIGGER_MAP } from '../../constant'
|
|
2
|
+
import { Current } from '../../current'
|
|
3
|
+
import { eventCenter } from '../../emitter/emitter'
|
|
4
|
+
import { TaroNativeModule } from '../../harmony-library'
|
|
5
|
+
import { initComponentNodeInfo, printInfo, runInDebug, triggerAttributesCallback } from '../../utils/info'
|
|
6
|
+
import { ClassList } from '../class-list'
|
|
7
|
+
import { TaroDataSourceElement } from '../dataSource'
|
|
8
|
+
import { NodeType } from '../node'
|
|
9
|
+
import { Style } from '../style'
|
|
10
|
+
import StyleSheet from '../stylesheet'
|
|
11
|
+
|
|
12
|
+
import type { BaseTouchEvent, ITouchEvent, StandardProps } from '@tarojs/components/types'
|
|
13
|
+
import type { TaroAny } from '../../interface'
|
|
14
|
+
|
|
15
|
+
type NamedNodeMap = { name: string, value: string }[]
|
|
16
|
+
|
|
17
|
+
export interface TaroExtraProps {
|
|
18
|
+
compileMode?: string | boolean
|
|
19
|
+
compileIf?: boolean
|
|
20
|
+
disabled?: boolean
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export class TaroElement<
|
|
24
|
+
T extends StandardProps<any, U> = StandardProps,
|
|
25
|
+
U extends BaseTouchEvent<any> = ITouchEvent
|
|
26
|
+
> extends TaroDataSourceElement {
|
|
27
|
+
public _innerHTML = ''
|
|
28
|
+
public _nodeInfo: TaroAny = {
|
|
29
|
+
layer: 0 // 渲染层级
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
isETS = false
|
|
33
|
+
|
|
34
|
+
public hm_instance: TaroAny
|
|
35
|
+
|
|
36
|
+
public get _instance () {
|
|
37
|
+
return this.hm_instance
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public set _instance (value) {
|
|
41
|
+
this.hm_instance = value
|
|
42
|
+
if (this._nodeInfo.aboutToAppear) {
|
|
43
|
+
let task
|
|
44
|
+
// eslint-disable-next-line no-cond-assign
|
|
45
|
+
while (task = this._nodeInfo.aboutToAppear.shift()) {
|
|
46
|
+
task()
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public readonly tagName: string
|
|
52
|
+
public _attrs: T & TaroExtraProps = {} as T
|
|
53
|
+
|
|
54
|
+
constructor(tagName: string) {
|
|
55
|
+
super(tagName.replace(new RegExp('(?<=.)([A-Z])', 'g'), '-$1').toUpperCase(), NodeType.ELEMENT_NODE)
|
|
56
|
+
this.tagName = this.nodeName
|
|
57
|
+
this.style = new Style(this)
|
|
58
|
+
initComponentNodeInfo(this)
|
|
59
|
+
|
|
60
|
+
TaroNativeModule.createTaroNode(this)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public set id(value: string) {
|
|
64
|
+
this.setAttribute('id', value)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public get id(): string {
|
|
68
|
+
return this.getAttribute('id')
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public get uid(): string {
|
|
72
|
+
return this.getAttribute('uid')
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public set className(value: string) {
|
|
76
|
+
this.setAttribute('class', value)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
public get className(): string {
|
|
80
|
+
return this.getAttribute('class') || ''
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
public get classList(): ClassList {
|
|
84
|
+
return new ClassList(this)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
public get attributes(): NamedNodeMap {
|
|
88
|
+
const list: NamedNodeMap = []
|
|
89
|
+
|
|
90
|
+
// FIXME
|
|
91
|
+
Object.keys(this._attrs).forEach((name) => {
|
|
92
|
+
const value: TaroAny = this._attrs[name]
|
|
93
|
+
|
|
94
|
+
list.push({ name, value })
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
return list
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
public get children(): TaroElement[] {
|
|
101
|
+
return TaroNativeModule.getTaroNodeProperty(this, 'children')
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
public get dataset(): Record<string, unknown> {
|
|
105
|
+
return TaroNativeModule.getTaroNodeProperty(this, 'dataset') || {}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
public setAttribute(name: string, value: TaroAny): void {
|
|
109
|
+
this._attrs[name] = value
|
|
110
|
+
|
|
111
|
+
// 混合开发的组件没办法自动更新,需要把父级的结点删掉新建
|
|
112
|
+
// Current.nativeComponentNames会在render.ets中赋值
|
|
113
|
+
if (Current.nativeComponentNames?.includes(this.tagName)) {
|
|
114
|
+
const idxOfRef = (this.parentNode as TaroDataSourceElement)?.findIndex(this)
|
|
115
|
+
|
|
116
|
+
if (idxOfRef !== undefined) {
|
|
117
|
+
this._nativeUpdateTrigger++
|
|
118
|
+
if (this.isETS) {
|
|
119
|
+
(this.parentNode as TaroDataSourceElement)?.notifyDataChange?.(idxOfRef)
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (['PAGE-META', 'NAVIGATION-BAR'].includes(this.tagName)) {
|
|
125
|
+
// FIXME 等 Harmony 支持更细粒度的 @Watch 方法后移出
|
|
126
|
+
eventCenter.trigger('__taroComponentAttributeUpdate', {
|
|
127
|
+
id: this._nid,
|
|
128
|
+
tagName: this.tagName,
|
|
129
|
+
attribute: name,
|
|
130
|
+
value
|
|
131
|
+
})
|
|
132
|
+
} else {
|
|
133
|
+
const attributeTriggerValue: TaroAny = ATTRIBUTES_CALLBACK_TRIGGER_MAP[name]
|
|
134
|
+
if (attributeTriggerValue) {
|
|
135
|
+
const triggerName: TaroAny = attributeTriggerValue.triggerName
|
|
136
|
+
const valueInspect: TaroAny = attributeTriggerValue.valueInspect
|
|
137
|
+
|
|
138
|
+
if (valueInspect && !valueInspect(value)) return
|
|
139
|
+
|
|
140
|
+
runInDebug(() => {
|
|
141
|
+
printInfo('setAttribute', this._nid, this.parentNode?.nodeName, this.nodeName, triggerName, this._attrs[triggerName])
|
|
142
|
+
})
|
|
143
|
+
TaroNativeModule.setTaroNodeAttribute(this, triggerName, this._attrs[triggerName])
|
|
144
|
+
triggerAttributesCallback(this, triggerName)
|
|
145
|
+
} else {
|
|
146
|
+
runInDebug(() => {
|
|
147
|
+
printInfo('setAttribute', this._nid, this.parentNode?.nodeName, this.nodeName, name, value ?? null)
|
|
148
|
+
})
|
|
149
|
+
TaroNativeModule.setTaroNodeAttribute(this, name, value ?? null)
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
public getAttribute(name: string): any {
|
|
155
|
+
return TaroNativeModule.getTaroNodeAttribute(this, name)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
public removeAttribute(name: string): void {
|
|
159
|
+
this._attrs[name] = null
|
|
160
|
+
TaroNativeModule.removeTaroNodeAttribute(this, name)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
public hasAttribute(name: string): boolean {
|
|
164
|
+
return TaroNativeModule.hasTaroNodeAttribute(this, name)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
public hasAttributes(): boolean {
|
|
168
|
+
return TaroNativeModule.hasTaroNodeAttributes(this)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
public set innerHTML(value: string) {
|
|
172
|
+
if (this.nodeType === NodeType.ELEMENT_NODE && this.ownerDocument) {
|
|
173
|
+
const ele = this.ownerDocument.createElement('inner-html')
|
|
174
|
+
ele._innerHTML = value
|
|
175
|
+
this.appendChild(ele as TaroAny)
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
public get innerHTML(): string {
|
|
180
|
+
return this._innerHTML
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// 存放的样式,获取其实跟获取style是一样的,只不过这里取的更快捷,不需要走style的get方法进到cssStyleDeclaration
|
|
184
|
+
public _st: TaroAny = new StyleSheet()
|
|
185
|
+
|
|
186
|
+
// 经转换后的鸿蒙样式
|
|
187
|
+
public get hmStyle(): TaroAny {
|
|
188
|
+
return this._st.hmStyle
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
public style: Style | null = null
|
|
192
|
+
|
|
193
|
+
// 设置动画
|
|
194
|
+
public setAnimation (playing) {
|
|
195
|
+
if (!this._instance) {
|
|
196
|
+
if (!this._nodeInfo.aboutToAppear) {
|
|
197
|
+
this._nodeInfo.aboutToAppear = []
|
|
198
|
+
}
|
|
199
|
+
this._nodeInfo.aboutToAppear.push(() => {
|
|
200
|
+
this.setAnimation(playing)
|
|
201
|
+
})
|
|
202
|
+
return
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const keyframes = this._st.hmStyle.animationName
|
|
206
|
+
|
|
207
|
+
// 防止动画闪烁,需要把第一帧的内容先设置上去设置初始样式
|
|
208
|
+
if (playing && keyframes && keyframes[0] && keyframes[0].percentage === 0) {
|
|
209
|
+
this._instance.overwriteStyle = keyframes[0].event
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// 首次设置,不用实例替换
|
|
213
|
+
if (!this._nodeInfo.hasAnimation && playing) {
|
|
214
|
+
this._nodeInfo.hasAnimation = true
|
|
215
|
+
// 下一帧播放,等节点样式首次设置上去在进行覆盖
|
|
216
|
+
setTimeout(() => {
|
|
217
|
+
if (playing) {
|
|
218
|
+
this.playAnimation()
|
|
219
|
+
}
|
|
220
|
+
}, 0)
|
|
221
|
+
} else if (this.parentNode) {
|
|
222
|
+
const idx = (this.parentNode as TaroDataSourceElement).findIndex(this)
|
|
223
|
+
;(this.parentNode as TaroDataSourceElement).notifyDataDelete(idx)
|
|
224
|
+
|
|
225
|
+
// 下一帧播放,等实例被移除掉,再重新插入
|
|
226
|
+
setTimeout(() => {
|
|
227
|
+
// insert
|
|
228
|
+
(this.parentNode as TaroDataSourceElement)?.notifyDataAdd(idx)
|
|
229
|
+
|
|
230
|
+
// 执行动画
|
|
231
|
+
if (playing) {
|
|
232
|
+
this.playAnimation()
|
|
233
|
+
}
|
|
234
|
+
}, playing ? 0 : 100)
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
private playAnimation () {
|
|
239
|
+
const {
|
|
240
|
+
animationDuration = 0, animationDelay = 0, animationIterationCount = 1, animationName: keyframes,
|
|
241
|
+
animationTimingFunction
|
|
242
|
+
} = this._st.hmStyle
|
|
243
|
+
|
|
244
|
+
if (keyframes) {
|
|
245
|
+
let cur_percentage = 0
|
|
246
|
+
this._instance.getUIContext()?.keyframeAnimateTo({
|
|
247
|
+
delay: animationDelay,
|
|
248
|
+
iterations: animationIterationCount,
|
|
249
|
+
}, keyframes.map(item => {
|
|
250
|
+
const duration = (item.percentage - cur_percentage) * animationDuration
|
|
251
|
+
cur_percentage = item.percentage
|
|
252
|
+
return {
|
|
253
|
+
duration: duration,
|
|
254
|
+
curve: item.event.animationTimingFunction || animationTimingFunction,
|
|
255
|
+
event: () => {
|
|
256
|
+
this._instance.overwriteStyle = item.event
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}))
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|