@tarojs/plugin-platform-harmony-ets 4.0.0-beta.11 → 4.0.0-beta.111

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.
Files changed (129) hide show
  1. package/dist/apis/base/system.ts +73 -20
  2. package/dist/apis/canvas/index.ts +10 -1
  3. package/dist/apis/device/clipboard.ts +16 -8
  4. package/dist/apis/framework/index.ts +1 -5
  5. package/dist/apis/index.ts +25 -17
  6. package/dist/apis/media/image/index.ts +1 -1
  7. package/dist/apis/storage/index.ts +135 -131
  8. package/dist/apis/ui/animation/animation.ts +71 -29
  9. package/dist/apis/ui/background.ts +2 -1
  10. package/dist/apis/ui/interaction/index.ts +42 -59
  11. package/dist/apis/ui/navigation-bar/index.ts +1 -1
  12. package/dist/apis/ui/pull-down-refresh.ts +9 -3
  13. package/dist/apis/ui/scroll/index.ts +5 -5
  14. package/dist/apis/ui/tab-bar.ts +3 -3
  15. package/dist/apis/utils/index.ts +2 -1
  16. package/dist/apis/wxml/IntersectionObserver.ts +18 -10
  17. package/dist/apis/wxml/selectorQuery.ts +26 -13
  18. package/dist/components-harmony-ets/button.ets +35 -8
  19. package/dist/components-harmony-ets/canvas.ets +51 -0
  20. package/dist/components-harmony-ets/checkbox.ets +70 -60
  21. package/dist/components-harmony-ets/form.ets +35 -16
  22. package/dist/components-harmony-ets/icon.ets +16 -8
  23. package/dist/components-harmony-ets/image.ets +22 -6
  24. package/dist/components-harmony-ets/index.ets +92 -0
  25. package/dist/components-harmony-ets/innerHtml.ets +6 -5
  26. package/dist/components-harmony-ets/input.ets +62 -40
  27. package/dist/components-harmony-ets/label.ets +44 -21
  28. package/dist/components-harmony-ets/listView.ets +31 -0
  29. package/dist/components-harmony-ets/movableArea.ets +112 -53
  30. package/dist/components-harmony-ets/movableView.ets +75 -48
  31. package/dist/components-harmony-ets/navigationBar.ets +65 -0
  32. package/dist/components-harmony-ets/pageMeta.ets +94 -0
  33. package/dist/components-harmony-ets/picker.ets +41 -38
  34. package/dist/components-harmony-ets/progress.ets +31 -24
  35. package/dist/components-harmony-ets/pseudo.ets +80 -0
  36. package/dist/components-harmony-ets/radio.ets +76 -66
  37. package/dist/components-harmony-ets/richText.ets +4 -25
  38. package/dist/components-harmony-ets/scrollList.ets +103 -0
  39. package/dist/components-harmony-ets/scrollView.ets +47 -47
  40. package/dist/components-harmony-ets/slider.ets +18 -14
  41. package/dist/components-harmony-ets/stickySection.ets +42 -0
  42. package/dist/components-harmony-ets/style.ets +386 -130
  43. package/dist/components-harmony-ets/swiper.ets +41 -4
  44. package/dist/components-harmony-ets/switch.ets +35 -31
  45. package/dist/components-harmony-ets/{index.ts → tag.ts} +6 -0
  46. package/dist/components-harmony-ets/text.ets +102 -46
  47. package/dist/components-harmony-ets/textArea.ets +49 -34
  48. package/dist/components-harmony-ets/utils/AttributeManager.ets +2 -2
  49. package/dist/components-harmony-ets/utils/DynamicCenter.ts +2 -2
  50. package/dist/components-harmony-ets/utils/flexManager.ets +49 -19
  51. package/dist/components-harmony-ets/utils/helper.ets +20 -8
  52. package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
  53. package/dist/components-harmony-ets/utils/htmlParser/index.ts +1 -1
  54. package/dist/components-harmony-ets/utils/index.ts +54 -50
  55. package/dist/components-harmony-ets/utils/styles.ets +170 -93
  56. package/dist/components-harmony-ets/video.ets +27 -19
  57. package/dist/components-harmony-ets/view.ets +47 -40
  58. package/dist/components-harmony-ets/webView.ets +6 -5
  59. package/dist/index.d.ts +152 -0
  60. package/dist/index.js +69 -43
  61. package/dist/index.js.map +1 -1
  62. package/dist/runtime-ets/bom/document.ts +6 -4
  63. package/dist/runtime-ets/bom/getComputedStyle.ts +2 -2
  64. package/dist/runtime-ets/bom/window.ts +7 -0
  65. package/dist/runtime-ets/current.ts +5 -1
  66. package/dist/runtime-ets/dom/bind.ts +28 -12
  67. package/dist/runtime-ets/dom/class-list.ts +2 -2
  68. package/dist/runtime-ets/dom/cssNesting.ts +419 -0
  69. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +28 -42
  70. package/dist/runtime-ets/dom/document.ts +8 -11
  71. package/dist/runtime-ets/dom/element/canvas.ts +136 -0
  72. package/dist/runtime-ets/dom/element/element.ts +376 -56
  73. package/dist/runtime-ets/dom/element/form.ts +20 -22
  74. package/dist/runtime-ets/dom/element/index.ts +22 -2
  75. package/dist/runtime-ets/dom/element/movableArea.ts +0 -1
  76. package/dist/runtime-ets/dom/element/movableView.ts +234 -2
  77. package/dist/runtime-ets/dom/element/normal.ts +27 -6
  78. package/dist/runtime-ets/dom/element/progress.ts +0 -2
  79. package/dist/runtime-ets/dom/element/text.ts +0 -8
  80. package/dist/runtime-ets/dom/element/video.ts +4 -4
  81. package/dist/runtime-ets/dom/element/webView.ts +4 -5
  82. package/dist/runtime-ets/dom/event.ts +3 -5
  83. package/dist/runtime-ets/dom/eventTarget.ts +2 -3
  84. package/dist/runtime-ets/dom/node.ts +51 -19
  85. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +418 -237
  86. package/dist/runtime-ets/dom/stylesheet/index.ts +29 -311
  87. package/dist/runtime-ets/dom/stylesheet/type.ts +51 -9
  88. package/dist/runtime-ets/dom/stylesheet/util.ts +33 -27
  89. package/dist/runtime-ets/index.ts +2 -1
  90. package/dist/runtime-ets/interface/event.ts +1 -1
  91. package/dist/runtime-ets/utils/index.ts +74 -13
  92. package/dist/runtime-ets/utils/info.ts +2 -2
  93. package/dist/runtime-framework/react/app.ts +15 -10
  94. package/dist/runtime-framework/react/hooks.ts +0 -1
  95. package/dist/runtime-framework/react/index.ts +0 -2
  96. package/dist/runtime-framework/react/native-page.ts +185 -78
  97. package/dist/runtime-framework/react/page.ts +4 -9
  98. package/dist/runtime-framework/react/utils/index.ts +3 -3
  99. package/dist/runtime-framework/solid/app.ts +30 -46
  100. package/dist/runtime-framework/solid/connect.ts +21 -3
  101. package/dist/runtime-framework/solid/hooks.ts +16 -11
  102. package/dist/runtime-framework/solid/index.ts +6 -2
  103. package/dist/runtime-framework/solid/page.ts +85 -31
  104. package/dist/runtime-framework/solid/reconciler/props.ts +70 -25
  105. package/dist/runtime-framework/solid/reconciler/render.ts +16 -6
  106. package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
  107. package/dist/runtime-framework/solid/utils/index.ts +3 -5
  108. package/dist/runtime-utils.d.ts +827 -0
  109. package/dist/runtime-utils.js +425 -253
  110. package/dist/runtime-utils.js.map +1 -1
  111. package/dist/runtime.d.ts +1 -0
  112. package/dist/runtime.js +425 -253
  113. package/dist/runtime.js.map +1 -1
  114. package/index.js +3 -1
  115. package/package.json +14 -15
  116. package/static/media/cancel.svg +1 -1
  117. package/static/media/circle.svg +1 -1
  118. package/static/media/clear.svg +1 -1
  119. package/static/media/download.svg +1 -1
  120. package/static/media/info.svg +1 -1
  121. package/static/media/info_circle.svg +1 -1
  122. package/static/media/search.svg +1 -1
  123. package/static/media/success.svg +1 -1
  124. package/static/media/success_no_circle.svg +1 -1
  125. package/static/media/warn.svg +1 -1
  126. package/types/harmony.d.ts +4 -0
  127. package/types/index.d.ts +4 -0
  128. package/types/runtime.d.ts +1 -1
  129. /package/dist/runtime-framework/solid/{contant.ts → constant.ts} +0 -0
@@ -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
+ }
@@ -1,66 +1,115 @@
1
- import { eventSource } from '@tarojs/runtime/dist/runtime.esm'
1
+ // @ts-ignore
2
+ import { getPageById } from '@tarojs/plugin-framework-react/dist/runtime'
3
+ import { eventCenter, eventSource } from '@tarojs/runtime/dist/runtime.esm'
4
+ import { EMPTY_OBJ, toCamelCase } from '@tarojs/shared'
2
5
 
3
6
  import { ATTRIBUTES_CALLBACK_TRIGGER_MAP, ID } from '../../constant'
7
+ import { Current } from '../../current'
4
8
  import { findChildNodeWithDFS } from '../../utils'
5
9
  import { initComponentNodeInfo, triggerAttributesCallback } from '../../utils/info'
6
10
  import { bindAnimation } from '../bind'
7
11
  import { ClassList } from '../class-list'
12
+ import { type ICSSStyleDeclaration, createCSSStyleDeclaration } from '../cssStyleDeclaration'
8
13
  import { NodeType, TaroNode } from '../node'
9
- import StyleSheet from '../stylesheet'
14
+ import StyleSheet, { HarmonyStyle, TaroStyleType } from '../stylesheet'
10
15
 
11
- import type { StandardProps } from '@tarojs/components/types'
16
+ import type { BaseTouchEvent, ITouchEvent, StandardProps } from '@tarojs/components/types'
12
17
  import type { TaroAny } from '../../utils'
13
- import type { ICSSStyleDeclaration } from '../cssStyleDeclaration'
14
18
 
15
- type NamedNodeMap = ({ name: string, value: string })[]
19
+ type NamedNodeMap = { name: string, value: string }[]
16
20
 
17
21
  export interface TaroExtraProps {
18
22
  compileMode?: string | boolean
19
23
  compileIf?: boolean
20
24
  disabled?: boolean
25
+ __hmStyle?: TaroStyleType
21
26
  }
22
27
 
23
- export class TaroElement<T extends StandardProps = StandardProps> extends TaroNode {
28
+ export class TaroElement<
29
+ T extends StandardProps<any, U> = StandardProps,
30
+ U extends BaseTouchEvent<any> = ITouchEvent
31
+ > extends TaroNode {
24
32
  public _innerHTML = ''
25
- public _nodeInfo: TaroAny = {}
33
+ public _nodeInfo: TaroAny = {
34
+ layer: 0 // 渲染层级
35
+ }
36
+
37
+ public _hm_instance: TaroAny
38
+ public weak_hm_instance: WeakRef<TaroAny>
39
+ public use_weak_hm_instance: boolean = true
40
+
41
+
42
+ public get hm_instance(): TaroAny {
43
+ if (this.use_weak_hm_instance && this.weak_hm_instance) {
44
+ return this.weak_hm_instance?.deref()
45
+ }
46
+ return this._hm_instance
47
+ }
48
+
49
+ public set hm_instance(instance) {
50
+ if (this.use_weak_hm_instance && instance) {
51
+ this.weak_hm_instance = new WeakRef(instance)
52
+ return
53
+ }
54
+ this._hm_instance = instance
55
+ }
56
+
57
+
58
+ public get _instance () {
59
+ return this.hm_instance
60
+ }
61
+
62
+ public set _instance (value) {
63
+ this.hm_instance = value
64
+ if (this._nodeInfo.aboutToAppear) {
65
+ let task
66
+ // eslint-disable-next-line no-cond-assign
67
+ while (task = this._nodeInfo.aboutToAppear.shift()) {
68
+ task()
69
+ }
70
+ }
71
+ }
72
+
26
73
  public readonly tagName: string
74
+ public dataset: Record<string, unknown> = EMPTY_OBJ
27
75
  public _attrs: T & TaroExtraProps = {} as T & TaroExtraProps
28
76
 
29
- _client?: Area
30
- _scroll?: Area
77
+ private _page: any
31
78
 
32
79
  constructor(tagName: string) {
33
80
  super(tagName.replace(new RegExp('(?<=.)([A-Z])', 'g'), '-$1').toUpperCase(), NodeType.ELEMENT_NODE)
34
81
  this.tagName = this.nodeName
35
-
82
+ this._style = createCSSStyleDeclaration(this)
36
83
  initComponentNodeInfo(this)
37
84
  bindAnimation(this)
85
+
86
+ this._page = Current.page
38
87
  }
39
88
 
40
- public set id (value: string) {
89
+ public set id(value: string) {
41
90
  this.setAttribute('id', value)
42
91
  }
43
92
 
44
- public get id (): string {
93
+ public get id(): string {
45
94
  return this.getAttribute('id') || this._nid
46
95
  }
47
96
 
48
- public set className (value: string) {
97
+ public set className(value: string) {
49
98
  this.setAttribute('class', value)
50
99
  }
51
100
 
52
- public get className (): string {
101
+ public get className(): string {
53
102
  return this.getAttribute('class') || ''
54
103
  }
55
104
 
56
- public get classList (): ClassList {
105
+ public get classList(): ClassList {
57
106
  return new ClassList(this.className, this)
58
107
  }
59
108
 
60
- public get attributes (): NamedNodeMap {
109
+ public get attributes(): NamedNodeMap {
61
110
  const list: NamedNodeMap = []
62
111
 
63
- Object.keys(this._attrs).forEach(name => {
112
+ Object.keys(this._attrs).forEach((name) => {
64
113
  const value: TaroAny = this._attrs[name]
65
114
 
66
115
  list.push({ name, value })
@@ -69,73 +118,118 @@ export class TaroElement<T extends StandardProps = StandardProps> extends TaroNo
69
118
  return list
70
119
  }
71
120
 
72
- public get children (): TaroElement[] {
73
- return this.childNodes.filter(node => node.nodeType === NodeType.ELEMENT_NODE) as TaroElement[]
121
+ public get children(): TaroElement[] {
122
+ return this.childNodes.filter((node) => node.nodeType === NodeType.ELEMENT_NODE) as TaroElement[]
74
123
  }
75
124
 
76
- public setAttribute (name: string, value: TaroAny): void {
77
- if (name === ID) {
78
- eventSource.delete(this._attrs.id)
79
- eventSource.set(value, this as TaroAny)
125
+ public setAttribute(name: string, value: TaroAny): void {
126
+ switch (name) {
127
+ case ID:
128
+ eventSource.delete(this._attrs.id)
129
+ eventSource.set(value, this as TaroAny)
130
+ break
131
+ default:
132
+ if (name.startsWith('data-')) {
133
+ if (this.dataset === EMPTY_OBJ) {
134
+ this.dataset = Object.create(null)
135
+ }
136
+ this.dataset[toCamelCase(name.replace(/^data-/, ''))] = value
137
+ }
138
+ break
80
139
  }
81
140
 
82
141
  this._attrs[name] = value
83
142
 
84
- const attributeTriggerValue: TaroAny = ATTRIBUTES_CALLBACK_TRIGGER_MAP[name]
85
- if (attributeTriggerValue) {
86
- const triggerName: TaroAny = attributeTriggerValue.triggerName
87
- const valueInspect: TaroAny = attributeTriggerValue.valueInspect
143
+ // 混合开发的组件没办法自动更新,需要把父级的结点删掉新建
144
+ // Current.nativeComponentNames会在render.ets中赋值
145
+ if (Current.nativeComponentNames?.includes(this.tagName)) {
146
+ const idxOfRef = this.parentNode?.findIndex(this)
88
147
 
89
- if (valueInspect && !valueInspect(value)) return
148
+ if (idxOfRef !== undefined) {
149
+ this._nativeUpdateTrigger++
150
+ this.parentNode?.notifyDataChange(idxOfRef)
151
+ }
152
+ }
90
153
 
91
- triggerAttributesCallback(this, triggerName)
154
+ if (['PAGE-META', 'NAVIGATION-BAR'].includes(this.tagName)) {
155
+ // FIXME 等 Harmony 支持更细粒度的 @Watch 方法后移出
156
+ eventCenter.trigger('__taroComponentAttributeUpdate', {
157
+ id: this._nid,
158
+ tagName: this.tagName,
159
+ attribute: name,
160
+ value
161
+ })
162
+ } else {
163
+ const attributeTriggerValue: TaroAny = ATTRIBUTES_CALLBACK_TRIGGER_MAP[name]
164
+ if (attributeTriggerValue) {
165
+ const triggerName: TaroAny = attributeTriggerValue.triggerName
166
+ const valueInspect: TaroAny = attributeTriggerValue.valueInspect
167
+
168
+ if (valueInspect && !valueInspect(value)) return
169
+
170
+ triggerAttributesCallback(this, triggerName)
171
+ }
92
172
  }
93
173
  }
94
174
 
95
- public getAttribute (name: string): string {
175
+ public getAttribute(name: string): string {
96
176
  return this._attrs[name]
97
177
  }
98
178
 
99
- public removeAttribute (name: string): void {
179
+ public removeAttribute(name: string): void {
100
180
  this._attrs[name] = null
101
181
  }
102
182
 
103
- public hasAttribute (name: string): boolean {
183
+ public hasAttribute(name: string): boolean {
104
184
  return !!this._attrs[name]
105
185
  }
106
186
 
107
- public hasAttributes (): boolean {
187
+ public hasAttributes(): boolean {
108
188
  return Object.keys(this._attrs).length > 0
109
189
  }
110
190
 
111
- public getElementById<T extends TaroElement = TaroElement> (id: string | undefined | null) {
112
- return findChildNodeWithDFS<T>(this as TaroAny, (el) => {
113
- return el.id === id
114
- }, false)
191
+ public getElementById<T extends TaroElement = TaroElement>(id: string | undefined | null) {
192
+ return findChildNodeWithDFS<T>(
193
+ this as TaroAny,
194
+ (el) => {
195
+ return el.id === id
196
+ },
197
+ false
198
+ )
115
199
  }
116
200
 
117
- public getElementsByTagName<T extends TaroElement = TaroElement> (tagName: string) {
118
- return findChildNodeWithDFS<T>(this as TaroAny, (el) => {
119
- return el.nodeName === tagName || (tagName === '*' && this as TaroAny !== el)
120
- }, true) || []
201
+ public getElementsByTagName<T extends TaroElement = TaroElement>(tagName: string) {
202
+ return (
203
+ findChildNodeWithDFS<T>(
204
+ this as TaroAny,
205
+ (el) => {
206
+ return el.nodeName === tagName || (tagName === '*' && (this as TaroAny) !== el)
207
+ },
208
+ true
209
+ ) || []
210
+ )
121
211
  }
122
212
 
123
- public getElementsByClassName<T extends TaroElement = TaroElement> (className: string) {
213
+ public getElementsByClassName<T extends TaroElement = TaroElement>(className: string) {
124
214
  const classNames = className.trim().split(new RegExp('\\s+'))
125
215
 
126
- return findChildNodeWithDFS<T>(this as TaroAny, (el) => {
127
- const classList = el.classList
128
- return classNames.every(c => {
129
- const bool = classList.contains(c)
130
-
131
- return bool
132
- })
133
- }, true) || []
216
+ return (
217
+ findChildNodeWithDFS<T>(
218
+ this as TaroAny,
219
+ (el) => {
220
+ const classList = el.classList
221
+ return classNames.every((c) => {
222
+ const bool = classList.contains(c)
223
+
224
+ return bool
225
+ })
226
+ },
227
+ true
228
+ ) || []
229
+ )
134
230
  }
135
231
 
136
- // TODO dataset
137
-
138
- public set innerHTML (value: string) {
232
+ public set innerHTML(value: string) {
139
233
  if (this.nodeType === NodeType.ELEMENT_NODE && this.ownerDocument) {
140
234
  const ele = this.ownerDocument.createElement('inner-html')
141
235
  ele._innerHTML = value
@@ -143,20 +237,246 @@ export class TaroElement<T extends StandardProps = StandardProps> extends TaroNo
143
237
  }
144
238
  }
145
239
 
146
- public get innerHTML (): string {
240
+ public get innerHTML(): string {
147
241
  return this._innerHTML
148
242
  }
149
243
 
244
+ // 存放的样式,获取其实跟获取style是一样的,只不过这里取的更快捷,不需要走style的get方法进到cssStyleDeclaration
150
245
  public _st = new StyleSheet()
151
246
 
152
247
  // 经转换后的鸿蒙样式
153
- public get hmStyle () {
248
+ public get hmStyle() {
154
249
  return this._st.hmStyle
155
250
  }
156
251
 
157
252
  public _style: ICSSStyleDeclaration | null = null
158
253
 
159
- public get style (): ICSSStyleDeclaration | null {
254
+ public get style(): ICSSStyleDeclaration | null {
160
255
  return this._style
161
256
  }
257
+
258
+ // 伪元素,不存在style动态设置,均已被转换为鸿蒙样式
259
+ // 可根据实际情况,迁移到具体的组件中,如View、ScrollView中,Text\Image其实是不需要的
260
+ public _pseudo_before: StyleSheet | null = null
261
+
262
+ public set_pseudo_before(value: HarmonyStyle | null) {
263
+ if (value) {
264
+ if (!this._pseudo_before) {
265
+ this._pseudo_before = new StyleSheet()
266
+ }
267
+ Object.keys(value).forEach(key => {
268
+ this._pseudo_before!.hmStyle[key] = value[key]
269
+ })
270
+ } else {
271
+ this._pseudo_before = null
272
+ }
273
+ }
274
+
275
+ public _pseudo_after: StyleSheet | null = null
276
+
277
+ public set_pseudo_after(value: HarmonyStyle | null) {
278
+ if (value) {
279
+ if (!this._pseudo_after) {
280
+ this._pseudo_after = new StyleSheet()
281
+ }
282
+ Object.keys(value).forEach(key => {
283
+ this._pseudo_after!.hmStyle[key] = value[key]
284
+ })
285
+ } else {
286
+ this._pseudo_after = null
287
+ }
288
+ }
289
+
290
+ // 伪类,在获取的时候根据dom和parent的关系,动态设置
291
+ public _pseudo_class: Record<string, StyleSheet | null> = {
292
+ // ["::first-child"]: new StyleSheet(),
293
+ }
294
+
295
+ public set_pseudo_class(name: string, value: HarmonyStyle | null) {
296
+ if (value) {
297
+ if (!this._pseudo_class[name]) {
298
+ this._pseudo_class[name] = new StyleSheet()
299
+ }
300
+ Object.keys(value).forEach(key => {
301
+ this._pseudo_class[name]!.hmStyle[key] = value[key]
302
+ })
303
+ } else {
304
+ this._pseudo_class[name] = null
305
+ }
306
+ }
307
+
308
+ get currentLayerNode () {
309
+ if (!this._page) return null
310
+ if (typeof this._page.tabBarCurrentIndex !== 'undefined') {
311
+ this._page.layerNode ||= []
312
+ this._page.layerNode[this._page.tabBarCurrentIndex] ||= Current.createHarmonyElement('VIEW')
313
+ // Tabbar
314
+ return this._page.layerNode[this._page.tabBarCurrentIndex]
315
+ } else {
316
+ this._page.layerNode ||= Current.createHarmonyElement('VIEW')
317
+ return this._page.layerNode
318
+ }
319
+ }
320
+
321
+ get currentLayerParents () {
322
+ if (!this._page) return null
323
+ if (typeof this._page.tabBarCurrentIndex !== 'undefined') {
324
+ this._page.layerParents ||= {}
325
+ this._page.layerParents[this._page.tabBarCurrentIndex] ||= {}
326
+ // Tabbar
327
+ return this._page.layerParents[this._page.tabBarCurrentIndex]
328
+ } else {
329
+ this._page.layerParents ||= {}
330
+ return this._page.layerParents
331
+ }
332
+ }
333
+
334
+ // 设置渲染层级,0为正常层级,大于0为固定层级
335
+ // 1、appendChild的时候会判断是否需要设置层级
336
+ // 2、taro-react的setProperty,在处理属性变化的时候,会判断是否需要设置层级
337
+ // 3、removeChild的时候,会判断是否需要移除层级
338
+ public setLayer (value: number) {
339
+ if (!this.parentNode) return // 没有父节点,不需要设置层级关系
340
+
341
+
342
+ const currentPage = getPageById(this.getAttribute('__fixed'))
343
+ if (currentPage) {
344
+ this._page = currentPage
345
+ }
346
+
347
+ this._nodeInfo.layer = value
348
+
349
+ const currentLayerNode = this.currentLayerNode
350
+ const currentLayerParents = this.currentLayerParents
351
+ if (!currentLayerNode || !currentLayerParents) return
352
+ if (value > 0) {
353
+ // 插入到固定浮层
354
+ currentLayerNode.childNodes.push(this)
355
+ currentLayerNode.notifyDataAdd(currentLayerNode.childNodes.length - 1)
356
+ // 绑定祖先的节点id,建立关系,方便在祖先卸载(removeChild)的时候,能够找到该节点使其卸载
357
+ const _parentRecord = {}
358
+ generateLayerParentIds(_parentRecord, this)
359
+ currentLayerParents[this.getStrNid()] = _parentRecord
360
+ } else {
361
+ const idx = currentLayerNode.childNodes.findIndex(n => n.getStrNid() === this.getStrNid())
362
+ currentLayerNode.childNodes.splice(idx, 1)
363
+ currentLayerNode.notifyDataDelete(idx)
364
+
365
+ delete currentLayerParents[this.getStrNid()]
366
+ }
367
+
368
+ if (this.parentNode) {
369
+ this.parentNode.notifyDataChange(this.parentNode.findIndex(this))
370
+ this.updateComponent()
371
+ }
372
+ }
373
+
374
+ protected toggleLayer(add: boolean) {
375
+ if (add) {
376
+ if (this._st?.hmStyle.position === 'fixed') {
377
+ this.setLayer(1)
378
+ }
379
+ } else {
380
+ const currentLayerParents = this.currentLayerParents
381
+ if (!currentLayerParents) return
382
+ // 识别Current.page.layerParents里面是否有需要移除的固定元素
383
+ if (this._nodeInfo?.layer > 0) {
384
+ delete currentLayerParents[this.getStrNid()]
385
+ this.setLayer(0)
386
+ } else {
387
+ Object.keys(currentLayerParents).forEach(fixedId => {
388
+ const parentIds = currentLayerParents[fixedId]
389
+ if (parentIds[this.getStrNid()]) {
390
+ // 需要移除fixedId
391
+ delete currentLayerParents[fixedId]
392
+ const fixedNode = eventSource.get(this.getNumNid(fixedId)) as unknown as TaroElement
393
+ if (fixedNode) {
394
+ fixedNode.setLayer(0)
395
+ }
396
+ }
397
+ })
398
+ }
399
+ }
400
+ }
401
+
402
+ // 设置动画
403
+ public setAnimation (playing) {
404
+ if (!this._instance) {
405
+ if (!this._nodeInfo.aboutToAppear) {
406
+ this._nodeInfo.aboutToAppear = []
407
+ }
408
+ this._nodeInfo.aboutToAppear.push(() => {
409
+ this.setAnimation(playing)
410
+ })
411
+ return
412
+ }
413
+
414
+ const keyframes = this._st.hmStyle.animationName
415
+
416
+ // 防止动画闪烁,需要把第一帧的内容先设置上去设置初始样式
417
+ if (playing && keyframes && keyframes[0] && keyframes[0].percentage === 0) {
418
+ this._instance.overwriteStyle = keyframes[0].event
419
+ }
420
+
421
+ // 首次设置,不用实例替换
422
+ if (!this._nodeInfo.hasAnimation && playing) {
423
+ this._nodeInfo.hasAnimation = true
424
+ // 下一帧播放,等节点样式首次设置上去在进行覆盖
425
+ setTimeout(() => {
426
+ if (playing) {
427
+ this.playAnimation()
428
+ }
429
+ }, 0)
430
+ } else if (this.parentNode) {
431
+ const idx = this.parentNode.findIndex(this)
432
+ // Note: 因为keyframeAnimateTo无法暂停,华为没有支持,只能临时先换掉实例,重新创建ark节点,使得原本的keyframeAnimateTo失效
433
+ // remove
434
+ this.parentNode.childNodes.splice(idx, 1)
435
+ this.parentNode.notifyDataDelete(idx)
436
+
437
+ // 下一帧播放,等实例被移除掉,再重新插入
438
+ setTimeout(() => {
439
+ // insert
440
+ this.parentNode?.childNodes.splice(idx, 0, this)
441
+ this.parentNode?.notifyDataAdd(idx)
442
+
443
+ // 执行动画
444
+ if (playing) {
445
+ this.playAnimation()
446
+ }
447
+ }, playing ? 0 : 100)
448
+ }
449
+ }
450
+
451
+ private playAnimation () {
452
+ const {
453
+ animationDuration = 0, animationDelay = 0, animationIterationCount = 1, animationName: keyframes,
454
+ animationTimingFunction
455
+ } = this._st.hmStyle
456
+
457
+ if (keyframes) {
458
+ let cur_percentage = 0
459
+ this._instance.getUIContext()?.keyframeAnimateTo({
460
+ delay: animationDelay,
461
+ iterations: animationIterationCount,
462
+ }, keyframes.map(item => {
463
+ const duration = (item.percentage - cur_percentage) * animationDuration
464
+ cur_percentage = item.percentage
465
+ return {
466
+ duration: duration,
467
+ curve: item.event.animationTimingFunction || animationTimingFunction,
468
+ event: () => {
469
+ this._instance.overwriteStyle = item.event
470
+ }
471
+ }
472
+ }))
473
+ }
474
+ }
475
+ }
476
+
477
+ function generateLayerParentIds(ids: Record<string, true>, node?: TaroElement) {
478
+ if (node?.parentElement) {
479
+ ids[node.parentElement.getStrNid()] = true
480
+ generateLayerParentIds(ids, node.parentElement)
481
+ }
162
482
  }