@tarojs/plugin-platform-harmony-ets 4.0.0-beta.21 → 4.0.0-beta.22
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 +1 -1
- package/dist/apis/canvas/index.ts +10 -1
- package/dist/apis/index.ts +4 -1
- package/dist/components-harmony-ets/canvas.ets +43 -0
- package/dist/components-harmony-ets/index.ets +53 -0
- package/dist/components-harmony-ets/utils/index.ts +4 -3
- package/dist/index.d.ts +1 -1
- package/dist/runtime-ets/bom/window.ts +5 -0
- package/dist/runtime-ets/dom/element/canvas.ts +136 -0
- package/dist/runtime-ets/dom/element/element.ts +58 -39
- package/dist/runtime-ets/dom/element/index.ts +4 -2
- package/dist/runtime-ets/dom/node.ts +3 -3
- package/dist/runtime-ets/utils/index.ts +4 -0
- package/dist/runtime-framework/react/app.ts +2 -1
- package/dist/runtime-framework/react/native-page.ts +2 -2
- package/dist/runtime-framework/solid/app.ts +19 -39
- package/dist/runtime-framework/solid/connect.ts +20 -2
- package/dist/runtime-framework/solid/hooks.ts +16 -11
- package/dist/runtime-framework/solid/index.ts +7 -1
- package/dist/runtime-framework/solid/page.ts +84 -23
- package/dist/runtime-framework/solid/reconciler/props.ts +63 -13
- package/dist/runtime-framework/solid/reconciler/render.ts +2 -1
- package/dist/runtime-utils.d.ts +3 -1
- package/dist/runtime-utils.js +9 -3
- package/dist/runtime-utils.js.map +1 -1
- package/dist/runtime.js +9 -3
- package/dist/runtime.js.map +1 -1
- package/package.json +8 -9
- /package/dist/components-harmony-ets/{index.ts → tag.ts} +0 -0
- /package/dist/runtime-framework/solid/{contant.ts → constant.ts} +0 -0
- /package/dist/template/{container.js → container.js/container.js} +0 -0
package/dist/apis/base/system.ts
CHANGED
|
@@ -75,7 +75,7 @@ export const getSystemInfoSync: typeof Taro.getSystemInfoSync = function () {
|
|
|
75
75
|
res.notificationSoundAuthorized = false // 通知带有声音的开关(仅 iOS 有效)boolean
|
|
76
76
|
res.phoneCalendarAuthorized = null // 使用日历的开关 boolean
|
|
77
77
|
res.wifiEnabled = false // Wi-Fi 的系统开关 boolean
|
|
78
|
-
res.pixelRatio = display &&
|
|
78
|
+
res.pixelRatio = display && display.densityPixels // 设备像素比,number
|
|
79
79
|
res.platform = 'harmony' // 客户端平台 string
|
|
80
80
|
res.safeArea = safeArea // 在竖屏正方向下的安全区域 General.SafeAreaResult
|
|
81
81
|
res.screenHeight = display?.height // 屏幕高度,单位px number
|
|
@@ -1,12 +1,21 @@
|
|
|
1
|
+
import { eventSource } from '@tarojs/runtime'
|
|
2
|
+
|
|
1
3
|
import { temporarilyNotSupport } from '../utils'
|
|
2
4
|
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
import type { TaroCanvasElement } from '@tarojs/runtime'
|
|
3
7
|
// 画布
|
|
4
8
|
|
|
5
9
|
/** 创建离屏 canvas 实例 */
|
|
6
10
|
export const createOffscreenCanvas = /* @__PURE__ */ temporarilyNotSupport('createOffscreenCanvas')
|
|
7
11
|
|
|
8
12
|
/** 创建 canvas 的绘图上下文 CanvasContext 对象 */
|
|
9
|
-
export const createCanvasContext = /* @__PURE__ */ temporarilyNotSupport('createOffscreenCanvas')
|
|
13
|
+
// export const createCanvasContext = /* @__PURE__ */ temporarilyNotSupport('createOffscreenCanvas')
|
|
14
|
+
export const createCanvasContext = (canvasId: string) => {
|
|
15
|
+
const dom = eventSource.get(`canvasId-${canvasId}`)
|
|
16
|
+
// return dom as TaroCanvasElement
|
|
17
|
+
if (dom) return (dom as unknown as TaroCanvasElement).context
|
|
18
|
+
}
|
|
10
19
|
|
|
11
20
|
/** 把当前画布指定区域的内容导出生成指定大小的图片 */
|
|
12
21
|
export const canvasToTempFilePath = /* @__PURE__ */ temporarilyNotSupport('createOffscreenCanvas')
|
package/dist/apis/index.ts
CHANGED
|
@@ -78,7 +78,10 @@ function getRatio (value: number) {
|
|
|
78
78
|
export function pxTransformHelper (size: number, unit?: string, isNumber = false): number | string {
|
|
79
79
|
const config = (Current as any).taro?.config || {}
|
|
80
80
|
const targetUnit = unit || config.targetUnit || defaultTargetUnit
|
|
81
|
-
|
|
81
|
+
|
|
82
|
+
if (targetUnit === 'PX') {
|
|
83
|
+
return px2vp(size * display.scaledDensity) + 'vp'
|
|
84
|
+
}
|
|
82
85
|
const ratio = getRatio(size)
|
|
83
86
|
let val = size * ratio
|
|
84
87
|
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { TaroCanvasElement } from '@tarojs/runtime'
|
|
2
|
+
import { cancelAnimationFrame, requestAnimationFrame } from '@tarojs/runtime'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
@Component
|
|
6
|
+
export default struct TaroCanvas {
|
|
7
|
+
@ObjectLink node: TaroCanvasElement
|
|
8
|
+
rafId: number = 0
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
aboutToDisappear() {
|
|
12
|
+
if(this.rafId) {
|
|
13
|
+
cancelAnimationFrame(this.rafId)
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
build() {
|
|
18
|
+
Canvas(this.node._context)
|
|
19
|
+
.width('100%')
|
|
20
|
+
.height('100%')
|
|
21
|
+
.backgroundColor('#ffff00')
|
|
22
|
+
.onReady(() => {
|
|
23
|
+
const context = this.node._context
|
|
24
|
+
|
|
25
|
+
const draw = () => {
|
|
26
|
+
if (this.node._drawList.length) {
|
|
27
|
+
while (this.node._drawList.length) {
|
|
28
|
+
const item = this.node._drawList.shift()
|
|
29
|
+
if (item) {
|
|
30
|
+
if (typeof context[item.key] === 'function') {
|
|
31
|
+
context[item.key](...[].concat(item.value))
|
|
32
|
+
} else {
|
|
33
|
+
context[item.key] = item.value
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
this.rafId = requestAnimationFrame(draw)
|
|
39
|
+
}
|
|
40
|
+
draw()
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import TaroImage from './image'
|
|
2
|
+
import TaroText from './text'
|
|
3
|
+
import TaroView from './view'
|
|
4
|
+
import TaroIcon from './icon'
|
|
5
|
+
import TaroForm from './form'
|
|
6
|
+
import TaroLabel from './label'
|
|
7
|
+
import TaroInput from './input'
|
|
8
|
+
import TaroVideo from './video'
|
|
9
|
+
import TaroCanvas from './canvas'
|
|
10
|
+
import TaroButton from './button'
|
|
11
|
+
import TaroPicker from './picker'
|
|
12
|
+
import TaroSlider from './slider'
|
|
13
|
+
import TaroSwitch from './switch'
|
|
14
|
+
import TaroSwiper from './swiper'
|
|
15
|
+
import TaroWebView from './webView'
|
|
16
|
+
import TaroTextArea from './textArea'
|
|
17
|
+
import TaroRichText from './richText'
|
|
18
|
+
import TaroProgress from './progress'
|
|
19
|
+
import TaroInnerHtml from './innerHtml'
|
|
20
|
+
import TaroScrollView from './scrollView'
|
|
21
|
+
import TaroMovableArea from './movableArea'
|
|
22
|
+
import TaroMovableView from './movableView'
|
|
23
|
+
import { TaroRadio, TaroRadioGroup } from './radio'
|
|
24
|
+
import { TaroCheckboxGroup, TaroCheckbox } from './checkbox'
|
|
25
|
+
|
|
26
|
+
export {
|
|
27
|
+
TaroImage,
|
|
28
|
+
TaroCanvas,
|
|
29
|
+
TaroText,
|
|
30
|
+
TaroView,
|
|
31
|
+
TaroIcon,
|
|
32
|
+
TaroForm,
|
|
33
|
+
TaroLabel,
|
|
34
|
+
TaroInput,
|
|
35
|
+
TaroVideo,
|
|
36
|
+
TaroButton,
|
|
37
|
+
TaroPicker,
|
|
38
|
+
TaroSlider,
|
|
39
|
+
TaroSwitch,
|
|
40
|
+
TaroSwiper,
|
|
41
|
+
TaroWebView,
|
|
42
|
+
TaroTextArea,
|
|
43
|
+
TaroRichText,
|
|
44
|
+
TaroProgress,
|
|
45
|
+
TaroInnerHtml,
|
|
46
|
+
TaroScrollView,
|
|
47
|
+
TaroMovableArea,
|
|
48
|
+
TaroMovableView,
|
|
49
|
+
TaroRadio,
|
|
50
|
+
TaroRadioGroup,
|
|
51
|
+
TaroCheckboxGroup,
|
|
52
|
+
TaroCheckbox
|
|
53
|
+
}
|
|
@@ -110,8 +110,8 @@ function parseHtmlNode (nodes: Array<RichTextProps.Text | RichTextProps.HTMLElem
|
|
|
110
110
|
|
|
111
111
|
// 背景偏移算法:https://developer.mozilla.org/zh-CN/docs/Web/CSS/background-position
|
|
112
112
|
export function computeBackgroundPosition(style) {
|
|
113
|
-
let offsetX = 0
|
|
114
|
-
let offsetY = 0
|
|
113
|
+
let offsetX = style.backgroundPosition?.x || 0
|
|
114
|
+
let offsetY = style.backgroundPosition?.y || 0
|
|
115
115
|
if (style.backgroundSize && typeof style.backgroundSize !== 'number') {
|
|
116
116
|
if (!isUndefined(style.backgroundSize.width) && style.width) {
|
|
117
117
|
if (typeof style.backgroundPosition.x === 'string' && style.backgroundPosition.x.indexOf('%') > 0) {
|
|
@@ -132,5 +132,6 @@ export function computeBackgroundPosition(style) {
|
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
|
-
|
|
135
|
+
|
|
136
|
+
return { offsetX, offsetY }
|
|
136
137
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -50,7 +50,7 @@ declare class Harmony extends TaroPlatformHarmony {
|
|
|
50
50
|
runtimePath: string[] | string;
|
|
51
51
|
taroComponentsPath: string;
|
|
52
52
|
constructor(ctx: IPluginContext, config: TConfig);
|
|
53
|
-
get framework(): "vue3" | "react" | "preact" | "nerv" | "vue";
|
|
53
|
+
get framework(): "solid" | "vue3" | "react" | "preact" | "nerv" | "vue";
|
|
54
54
|
get aliasFramework(): string;
|
|
55
55
|
get apiLibrary(): string;
|
|
56
56
|
get apiEntry(): RegExp[];
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import ohosWindow from '@ohos.window'
|
|
2
2
|
import { History, Location } from '@tarojs/runtime/dist/runtime.esm'
|
|
3
|
+
import { getSystemInfoSync } from '@tarojs/taro'
|
|
3
4
|
|
|
4
5
|
import { TaroEventTarget } from '../dom/eventTarget'
|
|
5
6
|
import { getComputedStyle } from './getComputedStyle'
|
|
@@ -30,6 +31,10 @@ class Window extends TaroEventTarget {
|
|
|
30
31
|
return this._doc
|
|
31
32
|
}
|
|
32
33
|
|
|
34
|
+
get devicePixelRatio () {
|
|
35
|
+
return getSystemInfoSync().pixelRatio
|
|
36
|
+
}
|
|
37
|
+
|
|
33
38
|
setTimeout (...args: Parameters<typeof setTimeout>) {
|
|
34
39
|
setTimeout(...args)
|
|
35
40
|
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { eventSource, TaroAny, TaroNode } from '@tarojs/runtime'
|
|
2
|
+
|
|
3
|
+
import { TaroElement } from './element'
|
|
4
|
+
|
|
5
|
+
import type { CanvasProps, CanvasTouchEvent } from '@tarojs/components/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
|
+
function getContextKey(obj) {
|
|
71
|
+
let currentObj = obj
|
|
72
|
+
let res = []
|
|
73
|
+
while (currentObj) {
|
|
74
|
+
if (currentObj instanceof CanvasRenderingContext2D) {
|
|
75
|
+
res = [...res, ...Object.getOwnPropertyNames(currentObj)]
|
|
76
|
+
}
|
|
77
|
+
currentObj = Object.getPrototypeOf(currentObj)
|
|
78
|
+
}
|
|
79
|
+
return res
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
@Observed
|
|
83
|
+
export class TaroCanvasElement extends TaroElement<CanvasProps, CanvasTouchEvent> {
|
|
84
|
+
_drawList: {
|
|
85
|
+
key: string
|
|
86
|
+
value: TaroAny
|
|
87
|
+
}[] = []
|
|
88
|
+
|
|
89
|
+
settings: RenderingContextSettings
|
|
90
|
+
_context: CanvasRenderingContext2D
|
|
91
|
+
_contextProxy: CanvasRenderingContext2D
|
|
92
|
+
|
|
93
|
+
constructor() {
|
|
94
|
+
super('Canvas')
|
|
95
|
+
this.settings = new RenderingContextSettings(true)
|
|
96
|
+
const context = new CanvasRenderingContext2DWXAdapter(this.settings) as CanvasRenderingContext2D
|
|
97
|
+
this._context = context
|
|
98
|
+
|
|
99
|
+
const proxyObj = getContextKey(context).reduce((obj, key) => {
|
|
100
|
+
if (typeof context[key] === 'function') {
|
|
101
|
+
obj[key] = new Proxy(context[key], {
|
|
102
|
+
apply: (target, thisArg, argumentsList) => {
|
|
103
|
+
this._drawList.push({
|
|
104
|
+
key,
|
|
105
|
+
value: argumentsList,
|
|
106
|
+
})
|
|
107
|
+
},
|
|
108
|
+
})
|
|
109
|
+
} else {
|
|
110
|
+
obj[key] = context[key]
|
|
111
|
+
}
|
|
112
|
+
return obj
|
|
113
|
+
}, {})
|
|
114
|
+
|
|
115
|
+
this._contextProxy = new Proxy(proxyObj, {
|
|
116
|
+
set: (_, property, value) => {
|
|
117
|
+
this._drawList.push({
|
|
118
|
+
key: property,
|
|
119
|
+
value,
|
|
120
|
+
})
|
|
121
|
+
return true
|
|
122
|
+
},
|
|
123
|
+
})
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
get context() {
|
|
127
|
+
return this._contextProxy
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
public setAttribute(name: string, value: TaroAny): void {
|
|
131
|
+
if (name === 'canvasId') {
|
|
132
|
+
eventSource.set(`canvasId-${value}`, this as TaroNode)
|
|
133
|
+
}
|
|
134
|
+
super.setAttribute(name, value)
|
|
135
|
+
}
|
|
136
|
+
}
|
|
@@ -10,10 +10,10 @@ import { type ICSSStyleDeclaration, createCSSStyleDeclaration } from '../cssStyl
|
|
|
10
10
|
import { NodeType, TaroNode } from '../node'
|
|
11
11
|
import StyleSheet, { HarmonyStyle } from '../stylesheet'
|
|
12
12
|
|
|
13
|
-
import type { StandardProps } from '@tarojs/components/types'
|
|
13
|
+
import type { BaseTouchEvent, ITouchEvent, StandardProps } from '@tarojs/components/types'
|
|
14
14
|
import type { TaroAny } from '../../utils'
|
|
15
15
|
|
|
16
|
-
type NamedNodeMap =
|
|
16
|
+
type NamedNodeMap = { name: string, value: string }[]
|
|
17
17
|
|
|
18
18
|
export interface TaroExtraProps {
|
|
19
19
|
compileMode?: string | boolean
|
|
@@ -21,7 +21,10 @@ export interface TaroExtraProps {
|
|
|
21
21
|
disabled?: boolean
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export class TaroElement<
|
|
24
|
+
export class TaroElement<
|
|
25
|
+
T extends StandardProps<any, U> = StandardProps,
|
|
26
|
+
U extends BaseTouchEvent<any> = ITouchEvent
|
|
27
|
+
> extends TaroNode {
|
|
25
28
|
public _innerHTML = ''
|
|
26
29
|
public _nodeInfo: TaroAny = {}
|
|
27
30
|
public readonly tagName: string
|
|
@@ -36,30 +39,30 @@ export class TaroElement<T extends StandardProps = StandardProps> extends TaroNo
|
|
|
36
39
|
bindAnimation(this)
|
|
37
40
|
}
|
|
38
41
|
|
|
39
|
-
public set id
|
|
42
|
+
public set id(value: string) {
|
|
40
43
|
this.setAttribute('id', value)
|
|
41
44
|
}
|
|
42
45
|
|
|
43
|
-
public get id
|
|
46
|
+
public get id(): string {
|
|
44
47
|
return this.getAttribute('id') || this._nid
|
|
45
48
|
}
|
|
46
49
|
|
|
47
|
-
public set className
|
|
50
|
+
public set className(value: string) {
|
|
48
51
|
this.setAttribute('class', value)
|
|
49
52
|
}
|
|
50
53
|
|
|
51
|
-
public get className
|
|
54
|
+
public get className(): string {
|
|
52
55
|
return this.getAttribute('class') || ''
|
|
53
56
|
}
|
|
54
57
|
|
|
55
|
-
public get classList
|
|
58
|
+
public get classList(): ClassList {
|
|
56
59
|
return new ClassList(this.className, this)
|
|
57
60
|
}
|
|
58
61
|
|
|
59
|
-
public get attributes
|
|
62
|
+
public get attributes(): NamedNodeMap {
|
|
60
63
|
const list: NamedNodeMap = []
|
|
61
64
|
|
|
62
|
-
Object.keys(this._attrs).forEach(name => {
|
|
65
|
+
Object.keys(this._attrs).forEach((name) => {
|
|
63
66
|
const value: TaroAny = this._attrs[name]
|
|
64
67
|
|
|
65
68
|
list.push({ name, value })
|
|
@@ -68,11 +71,11 @@ export class TaroElement<T extends StandardProps = StandardProps> extends TaroNo
|
|
|
68
71
|
return list
|
|
69
72
|
}
|
|
70
73
|
|
|
71
|
-
public get children
|
|
72
|
-
return this.childNodes.filter(node => node.nodeType === NodeType.ELEMENT_NODE) as TaroElement[]
|
|
74
|
+
public get children(): TaroElement[] {
|
|
75
|
+
return this.childNodes.filter((node) => node.nodeType === NodeType.ELEMENT_NODE) as TaroElement[]
|
|
73
76
|
}
|
|
74
77
|
|
|
75
|
-
public setAttribute
|
|
78
|
+
public setAttribute(name: string, value: TaroAny): void {
|
|
76
79
|
switch (name) {
|
|
77
80
|
case ID:
|
|
78
81
|
eventSource.delete(this._attrs.id)
|
|
@@ -106,48 +109,64 @@ export class TaroElement<T extends StandardProps = StandardProps> extends TaroNo
|
|
|
106
109
|
}
|
|
107
110
|
}
|
|
108
111
|
|
|
109
|
-
public getAttribute
|
|
112
|
+
public getAttribute(name: string): string {
|
|
110
113
|
return this._attrs[name]
|
|
111
114
|
}
|
|
112
115
|
|
|
113
|
-
public removeAttribute
|
|
116
|
+
public removeAttribute(name: string): void {
|
|
114
117
|
this._attrs[name] = null
|
|
115
118
|
}
|
|
116
119
|
|
|
117
|
-
public hasAttribute
|
|
120
|
+
public hasAttribute(name: string): boolean {
|
|
118
121
|
return !!this._attrs[name]
|
|
119
122
|
}
|
|
120
123
|
|
|
121
|
-
public hasAttributes
|
|
124
|
+
public hasAttributes(): boolean {
|
|
122
125
|
return Object.keys(this._attrs).length > 0
|
|
123
126
|
}
|
|
124
127
|
|
|
125
|
-
public getElementById<T extends TaroElement = TaroElement>
|
|
126
|
-
return findChildNodeWithDFS<T>(
|
|
127
|
-
|
|
128
|
-
|
|
128
|
+
public getElementById<T extends TaroElement = TaroElement>(id: string | undefined | null) {
|
|
129
|
+
return findChildNodeWithDFS<T>(
|
|
130
|
+
this as TaroAny,
|
|
131
|
+
(el) => {
|
|
132
|
+
return el.id === id
|
|
133
|
+
},
|
|
134
|
+
false
|
|
135
|
+
)
|
|
129
136
|
}
|
|
130
137
|
|
|
131
|
-
public getElementsByTagName<T extends TaroElement = TaroElement>
|
|
132
|
-
return
|
|
133
|
-
|
|
134
|
-
|
|
138
|
+
public getElementsByTagName<T extends TaroElement = TaroElement>(tagName: string) {
|
|
139
|
+
return (
|
|
140
|
+
findChildNodeWithDFS<T>(
|
|
141
|
+
this as TaroAny,
|
|
142
|
+
(el) => {
|
|
143
|
+
return el.nodeName === tagName || (tagName === '*' && (this as TaroAny) !== el)
|
|
144
|
+
},
|
|
145
|
+
true
|
|
146
|
+
) || []
|
|
147
|
+
)
|
|
135
148
|
}
|
|
136
149
|
|
|
137
|
-
public getElementsByClassName<T extends TaroElement = TaroElement>
|
|
150
|
+
public getElementsByClassName<T extends TaroElement = TaroElement>(className: string) {
|
|
138
151
|
const classNames = className.trim().split(new RegExp('\\s+'))
|
|
139
152
|
|
|
140
|
-
return
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
153
|
+
return (
|
|
154
|
+
findChildNodeWithDFS<T>(
|
|
155
|
+
this as TaroAny,
|
|
156
|
+
(el) => {
|
|
157
|
+
const classList = el.classList
|
|
158
|
+
return classNames.every((c) => {
|
|
159
|
+
const bool = classList.contains(c)
|
|
144
160
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
161
|
+
return bool
|
|
162
|
+
})
|
|
163
|
+
},
|
|
164
|
+
true
|
|
165
|
+
) || []
|
|
166
|
+
)
|
|
148
167
|
}
|
|
149
168
|
|
|
150
|
-
public set innerHTML
|
|
169
|
+
public set innerHTML(value: string) {
|
|
151
170
|
if (this.nodeType === NodeType.ELEMENT_NODE && this.ownerDocument) {
|
|
152
171
|
const ele = this.ownerDocument.createElement('inner-html')
|
|
153
172
|
ele._innerHTML = value
|
|
@@ -155,7 +174,7 @@ export class TaroElement<T extends StandardProps = StandardProps> extends TaroNo
|
|
|
155
174
|
}
|
|
156
175
|
}
|
|
157
176
|
|
|
158
|
-
public get innerHTML
|
|
177
|
+
public get innerHTML(): string {
|
|
159
178
|
return this._innerHTML
|
|
160
179
|
}
|
|
161
180
|
|
|
@@ -163,13 +182,13 @@ export class TaroElement<T extends StandardProps = StandardProps> extends TaroNo
|
|
|
163
182
|
public _st = new StyleSheet()
|
|
164
183
|
|
|
165
184
|
// 经转换后的鸿蒙样式
|
|
166
|
-
public get hmStyle
|
|
185
|
+
public get hmStyle() {
|
|
167
186
|
return this._st.hmStyle
|
|
168
187
|
}
|
|
169
188
|
|
|
170
189
|
public _style: ICSSStyleDeclaration | null = null
|
|
171
190
|
|
|
172
|
-
public get style
|
|
191
|
+
public get style(): ICSSStyleDeclaration | null {
|
|
173
192
|
return this._style
|
|
174
193
|
}
|
|
175
194
|
|
|
@@ -177,7 +196,7 @@ export class TaroElement<T extends StandardProps = StandardProps> extends TaroNo
|
|
|
177
196
|
// 可根据实际情况,迁移到具体的组件中,如View、ScrollView中,Text\Image其实是不需要的
|
|
178
197
|
public _pseudo_before: StyleSheet | null = null
|
|
179
198
|
|
|
180
|
-
public set_pseudo_before
|
|
199
|
+
public set_pseudo_before(value: HarmonyStyle | null) {
|
|
181
200
|
if (value) {
|
|
182
201
|
if (!this._pseudo_before) {
|
|
183
202
|
this._pseudo_before = new StyleSheet()
|
|
@@ -192,7 +211,7 @@ export class TaroElement<T extends StandardProps = StandardProps> extends TaroNo
|
|
|
192
211
|
|
|
193
212
|
public _pseudo_after: StyleSheet | null = null
|
|
194
213
|
|
|
195
|
-
public set_pseudo_after
|
|
214
|
+
public set_pseudo_after(value: HarmonyStyle | null) {
|
|
196
215
|
if (value) {
|
|
197
216
|
if (!this._pseudo_after) {
|
|
198
217
|
this._pseudo_after = new StyleSheet()
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Current } from '../../current'
|
|
2
2
|
import { TaroTextNode } from '../node'
|
|
3
|
+
import { TaroCanvasElement } from './canvas'
|
|
3
4
|
import { TaroElement } from './element'
|
|
4
5
|
import {
|
|
5
6
|
FormElement,
|
|
@@ -55,6 +56,7 @@ export function initHarmonyElement () {
|
|
|
55
56
|
case 'icon': return new TaroIconElement()
|
|
56
57
|
case 'label': return new TaroLabelElement()
|
|
57
58
|
case 'rich-text': return new TaroRichTextElement()
|
|
59
|
+
case 'canvas': return new TaroCanvasElement()
|
|
58
60
|
case 'swiper': return new TaroSwiperElement()
|
|
59
61
|
case 'swiper-item': return new TaroSwiperItemElement()
|
|
60
62
|
case 'textarea': return new TaroTextAreaElement()
|
|
@@ -74,6 +76,7 @@ export function initHarmonyElement () {
|
|
|
74
76
|
export {
|
|
75
77
|
FormElement,
|
|
76
78
|
TaroButtonElement,
|
|
79
|
+
TaroCanvasElement,
|
|
77
80
|
TaroCheckboxElement,
|
|
78
81
|
TaroCheckboxGroupElement,
|
|
79
82
|
TaroElement,
|
|
@@ -99,5 +102,4 @@ export {
|
|
|
99
102
|
TaroTextElement,
|
|
100
103
|
TaroVideoElement,
|
|
101
104
|
TaroViewElement,
|
|
102
|
-
TaroWebViewElement
|
|
103
|
-
}
|
|
105
|
+
TaroWebViewElement }
|
|
@@ -59,8 +59,8 @@ export class TaroNode extends TaroDataSourceElement {
|
|
|
59
59
|
return this.childNodes[index] as TaroElement
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
public findIndex (refChild
|
|
63
|
-
return this.childNodes.findIndex(node => node._nid === refChild
|
|
62
|
+
public findIndex (refChild?: TaroNode): number {
|
|
63
|
+
return this.childNodes.findIndex(node => node._nid === refChild?._nid)
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
public updateTextNode () {
|
|
@@ -83,7 +83,7 @@ export class TaroNode extends TaroDataSourceElement {
|
|
|
83
83
|
if (this._isDynamicNode) {
|
|
84
84
|
this._updateTrigger++
|
|
85
85
|
} else {
|
|
86
|
-
this.parentNode
|
|
86
|
+
this.parentNode?.updateComponent()
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
|
|
@@ -42,6 +42,10 @@ export function convertNumber2VP (value: number, unit = 'px') {
|
|
|
42
42
|
if (unit === 'vw' || unit === 'vh') {
|
|
43
43
|
return (value / 100 * (unit === 'vw' ? display.width: display.height)) + 'px'
|
|
44
44
|
}
|
|
45
|
+
if (unit === 'PX') {
|
|
46
|
+
// 特殊单位:相当于PX、pX、Px
|
|
47
|
+
return pxTransformHelper(value, 'PX')
|
|
48
|
+
}
|
|
45
49
|
return pxTransformHelper(value, 'vp')
|
|
46
50
|
}
|
|
47
51
|
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Current, document } from '@tarojs/runtime' // eslint-disable-line import/no-duplicates
|
|
2
|
-
import {
|
|
2
|
+
import { eventCenter } from '@tarojs/runtime/dist/runtime.esm' // eslint-disable-line import/no-duplicates
|
|
3
3
|
|
|
4
4
|
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
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
addLeadingSlash,
|
|
10
10
|
getOnHideEventKey,
|
|
11
11
|
getOnReadyEventKey,
|
|
12
|
-
getOnShowEventKey,
|
|
12
|
+
getOnShowEventKey,
|
|
13
13
|
getPath,
|
|
14
14
|
injectPageInstance,
|
|
15
15
|
removePageInstance,
|
|
@@ -157,7 +157,7 @@ function initNativeComponentEntry (params: InitNativeComponentEntryParams) {
|
|
|
157
157
|
// create
|
|
158
158
|
const nativeApp = document.createElement('nativeComponent')
|
|
159
159
|
// insert
|
|
160
|
-
app
|
|
160
|
+
app?.appendChild(nativeApp)
|
|
161
161
|
app = nativeApp
|
|
162
162
|
}
|
|
163
163
|
// eslint-disable-next-line react/no-deprecated
|