@tarojs/plugin-platform-harmony-ets 4.0.0-beta.35 → 4.0.0-beta.36

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.
@@ -5,7 +5,7 @@ import { shouldBindEvent, getNodeThresholds } from './utils/helper'
5
5
 
6
6
  import type { TaroImageElement, TaroAny } from '@tarojs/runtime'
7
7
 
8
- function getImageMode (mode: string): ImageFit {
8
+ export function getImageMode (mode: string): ImageFit {
9
9
  switch (mode) {
10
10
  case 'aspectFit': return ImageFit.Contain
11
11
  case 'aspectFill': return ImageFit.Cover
@@ -1,9 +1,55 @@
1
- import type { TaroAny, HarmonyStyle, TaroElement, TaroStyleType } from '@tarojs/runtime'
1
+ import type { TaroAny, HarmonyStyle, TaroElement, TaroStyleType, TaroTextElement } from '@tarojs/runtime'
2
2
  import { isUndefined } from '@tarojs/shared'
3
3
  import { computeBackgroundPosition } from './utils'
4
4
  import { getNormalAttributes } from './utils/helper'
5
5
  import { isMaxWidthView } from './utils/styles'
6
6
 
7
+ class TextStyleModify implements AttributeModifier<TextAttribute> {
8
+ initStyle?: TaroStyleType
9
+ node: TaroTextElement | null = null
10
+ style: HarmonyStyle | null = null
11
+ overwriteStyle: Record<string, TaroAny> = {}
12
+ withNormal = false
13
+
14
+ withNormalStyle () {
15
+ this.withNormal = true
16
+ return this
17
+ }
18
+
19
+ setAnimationStyle (overwriteStyle: Record<string, TaroAny>) {
20
+ this.overwriteStyle = overwriteStyle
21
+
22
+ return this
23
+ }
24
+
25
+ setNode (node: TaroTextElement, initStyle?: HarmonyStyle) {
26
+ this.node = node
27
+ this.style = getNormalAttributes(this.node)
28
+ this.initStyle = initStyle
29
+ // 覆盖初始化样式
30
+ if (initStyle) {
31
+ Object.keys(initStyle).forEach(key => {
32
+ if (this.style && !this.style[key]) {
33
+ this.style[key] = initStyle[key]
34
+ }
35
+ })
36
+ }
37
+ return this
38
+ }
39
+
40
+ applyNormalAttribute(instance: TextAttribute): void {
41
+ if (this.node && this.style) {
42
+ if (this.withNormal) {
43
+ setNormalAttributeIntoInstance(instance, this.style, this.node)
44
+ }
45
+ setNormalTextAttributeIntoInstance(instance, this.style, this.node)
46
+ setSpecialTextAttributeIntoInstance(instance, this.style, this.node)
47
+ }
48
+
49
+ setAnimationAttributeIntoInstance(instance, this.overwriteStyle, this.style || {})
50
+ }
51
+ }
52
+
7
53
  class CommonStyleModify implements AttributeModifier<CommonAttribute> {
8
54
  initStyle?: TaroStyleType
9
55
  node: TaroElement | null = null
@@ -55,7 +101,6 @@ class PseudoStyleModify implements AttributeModifier<CommonAttribute> {
55
101
  }
56
102
  }
57
103
 
58
-
59
104
  class RowStyleModify extends CommonStyleModify {
60
105
 
61
106
  applyNormalAttribute(instance: CommonAttribute): void {
@@ -89,7 +134,7 @@ class ColumnStyleModify extends CommonStyleModify {
89
134
  }
90
135
  }
91
136
 
92
- function setAnimationAttributeIntoInstance(instance: CommonAttribute, overwriteStyle: Record<string, TaroAny>, style: TaroStyleType) {
137
+ export function setAnimationAttributeIntoInstance(instance: CommonAttribute, overwriteStyle: Record<string, TaroAny>, style: TaroStyleType) {
93
138
  // Animation 需要提前和 @State 变量绑定才能产生动画效果,因此不能做 if else 判断
94
139
  instance.translate({
95
140
  x: overwriteStyle.translate?.x || style.transform?.Translate?.x,
@@ -113,7 +158,52 @@ function setAnimationAttributeIntoInstance(instance: CommonAttribute, overwriteS
113
158
  })
114
159
  }
115
160
 
116
- function setNormalAttributeIntoInstance(instance: CommonAttribute, style: TaroStyleType, node?: TaroElement | null) {
161
+ export function setNormalTextAttributeIntoInstance(instance: TextAttribute | SpanAttribute, style: HarmonyStyle, node?: TaroTextElement | null) {
162
+ if (!isUndefined(style.color)) {
163
+ instance.fontColor(style.color)
164
+ }
165
+ if (!isUndefined(style.fontSize)) {
166
+ instance.fontSize(style.fontSize)
167
+ }
168
+ if (!isUndefined(style.fontWeight)) {
169
+ instance.fontWeight(style.fontWeight)
170
+ }
171
+ if (!isUndefined(style.fontStyle)) {
172
+ instance.fontStyle(style.fontStyle)
173
+ }
174
+ if (!isUndefined(style.fontFamily)) {
175
+ instance.fontFamily(style.fontFamily)
176
+ }
177
+ if (!isUndefined(style.textDecoration)) {
178
+ instance.decoration({
179
+ type: style.textDecoration,
180
+ color: style.color
181
+ })
182
+ }
183
+ }
184
+
185
+ export function setSpecialTextAttributeIntoInstance(instance: TextAttribute, style: HarmonyStyle, node?: TaroTextElement | null) {
186
+ if (!isUndefined(style.textAlign)) {
187
+ instance.textAlign(style.textAlign)
188
+ }
189
+ if (!isUndefined(style.verticalAlign)) {
190
+ instance.align(style.verticalAlign)
191
+ }
192
+ if (!isUndefined(style.textOverflow)) {
193
+ instance.textOverflow(style.textOverflow)
194
+ }
195
+ if (!isUndefined(style.WebkitLineClamp)) {
196
+ instance.maxLines(style.WebkitLineClamp)
197
+ }
198
+ if (!isUndefined(style.letterSpacing)) {
199
+ instance.letterSpacing(style.letterSpacing)
200
+ }
201
+ if (!isUndefined(style.lineHeight)) {
202
+ instance.lineHeight(style.lineHeight)
203
+ }
204
+ }
205
+
206
+ export function setNormalAttributeIntoInstance(instance: CommonAttribute, style: TaroStyleType, node?: TaroElement | null) {
117
207
  if (!isUndefined(style.id)) {
118
208
  instance.id(style.id)
119
209
  instance.key(style.id)
@@ -288,5 +378,6 @@ function setNormalAttributeIntoInstance(instance: CommonAttribute, style: TaroSt
288
378
  export const pseudoModify = new PseudoStyleModify()
289
379
  export const rowModify = new RowStyleModify()
290
380
  export const columnModify = new ColumnStyleModify()
381
+ export const textModify = new TextStyleModify()
291
382
 
292
383
  export default new CommonStyleModify()
@@ -1,38 +1,13 @@
1
1
  import { isString } from '@tarojs/shared'
2
2
  import { eventHandler, convertNumber2VP, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, NodeType } from '@tarojs/runtime'
3
3
 
4
- import commonStyleModify from './style'
4
+ import commonStyleModify, { textModify, setNormalTextAttributeIntoInstance } from './style'
5
5
  import { getButtonColor } from './button'
6
+ import { getImageMode } from './image'
6
7
  import { BUTTON_THEME_COLOR } from './utils/constant/style'
7
- import { getNodeThresholds, getStyleAttr, getFontAttributes, shouldBindEvent, getNormalAttributes } from './utils/helper'
8
-
9
- import type { TaroButtonElement, TaroElement, TaroTextElement, TaroAny, TaroTextStyleType, TaroStyleType } from '@tarojs/runtime'
10
-
11
- @Extend(Text)
12
- function textNormalFontStyle (style: TaroStyleType) {
13
- .id(style.id)
14
- .key(style.id)
15
- .opacity(style.opacity)
16
- .fontColor(style.color)
17
- .fontSize(style.fontSize)
18
- .fontWeight(style.fontWeight)
19
- .fontStyle(style.fontStyle)
20
- .fontFamily(style.fontFamily)
21
- .decoration({
22
- type: style.textDecoration,
23
- color: style.color
24
- })
25
- }
8
+ import { getNodeThresholds, getStyleAttr, shouldBindEvent, getNormalAttributes } from './utils/helper'
26
9
 
27
- @Extend(Text)
28
- function textSpecialFontStyle(attr: TaroTextStyleType) {
29
- .textAlign(attr.textAlign)
30
- .align(attr.verticalAlign)
31
- .textOverflow(attr.textOverflow)
32
- .maxLines(attr.WebkitLineClamp)
33
- .letterSpacing(attr.letterSpacing)
34
- .lineHeight(attr.lineHeight)
35
- }
10
+ import type { TaroButtonElement, TaroElement, TaroTextElement, TaroAny, HarmonyStyle } from '@tarojs/runtime'
36
11
 
37
12
  function getButtonFontSize (node: TaroButtonElement): string | number {
38
13
  const isMini = node._attrs.size === 'mini'
@@ -51,6 +26,7 @@ function getTextInViewWidth (node: TaroElement | null): TaroAny {
51
26
  }
52
27
  }
53
28
 
29
+
54
30
  @Component
55
31
  export default struct TaroText {
56
32
  @Builder customBuilder() {}
@@ -69,25 +45,27 @@ export default struct TaroText {
69
45
  if (this.node.parentNode) {
70
46
  if ((this.node.parentNode as TaroElement).tagName === 'BUTTON') {
71
47
  Text(this.node.textContent)
72
- .textNormalFontStyle(getNormalAttributes(this.node.parentElement!, {
48
+ .attributeModifier(textModify.setNode(this.node, {
73
49
  fontSize: getButtonFontSize(this.node.parentNode as TaroButtonElement),
74
50
  color: getButtonColor(this.node.parentNode as TaroButtonElement, BUTTON_THEME_COLOR.get((this.node.parentNode as TaroButtonElement)._attrs.type || '').text)
75
51
  }))
76
- .textSpecialFontStyle(getFontAttributes(this.node.parentElement as TaroElement))
77
52
  } else {
78
53
  Text(this.node.textContent)
79
- .textNormalFontStyle(getNormalAttributes(this.node.parentElement!))
80
- .textSpecialFontStyle(getFontAttributes(this.node.parentElement as TaroElement))
54
+ .attributeModifier(textModify.setNode(this.node))
81
55
  .width(getTextInViewWidth(this.node.parentElement))
82
56
  }
83
57
  }
84
58
  } else {
85
59
  if (this.node.hmStyle?.display !== 'none') {
86
- Text(this.node.textContent)
60
+ Text(this.node.textContent) {
61
+ if (this.node.childNodes.length > 1) {
62
+ ForEach(this.node.childNodes, (item: TaroElement) => {
63
+ createTextChildNode(item, getSpanVerticalAlign(this.node.hmStyle?.verticalAlign))
64
+ }, (item: TaroElement) => item._nid)
65
+ }
66
+ }
87
67
  .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
88
- .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
89
- .textNormalFontStyle(getNormalAttributes(this.node))
90
- .textSpecialFontStyle(getFontAttributes(this.node))
68
+ .attributeModifier(textModify.setNode(this.node).withNormalStyle().setAnimationStyle(this.overwriteStyle))
91
69
  .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
92
70
  .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
93
71
  this.node._nodeInfo.areaInfo = res[1]
@@ -96,3 +74,64 @@ export default struct TaroText {
96
74
  }
97
75
  }
98
76
  }
77
+
78
+ @Builder
79
+ function createTextChildNode (item: TaroElement, align: ImageSpanAlignment) {
80
+ if (item.tagName === 'IMAGE') {
81
+ ImageSpan(item.getAttribute('src'))
82
+ .attributeModifier(commonStyleModify.setNode(item))
83
+ .objectFit(getImageMode(item.getAttribute('mode')))
84
+ .verticalAlign(align)
85
+ .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', item), item, ['click']))
86
+ } else if (item.nodeType === NodeType.TEXT_NODE) {
87
+ Span(item.textContent)
88
+ } else if (item.tagName === 'TEXT') {
89
+ Span(item.textContent)
90
+ .attributeModifier(spanModify.setNode(item))
91
+ .letterSpacing(item._st.hmStyle.letterSpacing)
92
+ .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', item), item, ['click']))
93
+ }
94
+ }
95
+
96
+ function getSpanVerticalAlign (verticalAlign?: Alignment) {
97
+ switch (verticalAlign) {
98
+ case Alignment.Start:
99
+ case Alignment.TopStart:
100
+ case Alignment.Top:
101
+ case Alignment.TopEnd: {
102
+ return ImageSpanAlignment.TOP
103
+ }
104
+ case Alignment.End:
105
+ case Alignment.BottomStart:
106
+ case Alignment.Bottom:
107
+ case Alignment.BottomEnd: {
108
+ return ImageSpanAlignment.BOTTOM
109
+ }
110
+ case Alignment.Center: {
111
+ return ImageSpanAlignment.CENTER
112
+ }
113
+ }
114
+ return ImageSpanAlignment.BASELINE
115
+ }
116
+
117
+
118
+ class SpanStyleModify implements AttributeModifier<SpanAttribute> {
119
+ node: TaroTextElement | null = null
120
+ style: HarmonyStyle | null = null
121
+ overwriteStyle: Record<string, TaroAny> = {}
122
+ withNormal = false
123
+
124
+ setNode (node: TaroTextElement) {
125
+ this.node = node
126
+ this.style = getNormalAttributes(this.node)
127
+ return this
128
+ }
129
+
130
+ applyNormalAttribute(instance: SpanAttribute): void {
131
+ if (this.node && this.style) {
132
+ setNormalTextAttributeIntoInstance(instance, this.style, this.node)
133
+ }
134
+ }
135
+ }
136
+
137
+ const spanModify = new SpanStyleModify()
@@ -22,6 +22,7 @@ import {
22
22
  TaroIconElement,
23
23
  TaroImageElement,
24
24
  TaroLabelElement,
25
+ TaroOtherElement,
25
26
  TaroRichTextElement,
26
27
  TaroSwiperElement,
27
28
  TaroSwiperItemElement,
@@ -63,7 +64,7 @@ export function initHarmonyElement () {
63
64
  case 'form': return new TaroFormElement()
64
65
  case 'web-view': return new TaroWebViewElement()
65
66
  case 'inner-html': return new TaroInnerHtmlElement()
66
- default: return new TaroElement(tagName)
67
+ default: return new TaroOtherElement(tagName)
67
68
  }
68
69
  }
69
70
 
@@ -88,6 +89,7 @@ export {
88
89
  TaroLabelElement,
89
90
  TaroMovableAreaElement,
90
91
  TaroMovableViewElement,
92
+ TaroOtherElement,
91
93
  TaroPickerElement,
92
94
  TaroProgressElement,
93
95
  TaroRadioElement,
@@ -102,4 +104,5 @@ export {
102
104
  TaroTextElement,
103
105
  TaroVideoElement,
104
106
  TaroViewElement,
105
- TaroWebViewElement }
107
+ TaroWebViewElement
108
+ }
@@ -12,6 +12,9 @@ import type {
12
12
  ViewProps
13
13
  } from '@tarojs/components/types'
14
14
 
15
+ @Observed
16
+ class TaroOtherElement extends TaroElement<ViewProps> {}
17
+
15
18
  @Observed
16
19
  class TaroViewElement extends TaroElement<ViewProps> {
17
20
  constructor() {
@@ -83,6 +86,7 @@ export {
83
86
  TaroIconElement,
84
87
  TaroImageElement,
85
88
  TaroLabelElement,
89
+ TaroOtherElement,
86
90
  TaroRichTextElement,
87
91
  TaroSwiperElement,
88
92
  TaroSwiperItemElement,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tarojs/plugin-platform-harmony-ets",
3
- "version": "4.0.0-beta.35",
3
+ "version": "4.0.0-beta.36",
4
4
  "description": "OpenHarmony & 鸿蒙系统插件",
5
5
  "author": "O2Team",
6
6
  "homepage": "https://gitee.com/openharmony-sig/taro",
@@ -25,13 +25,13 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "webpack-sources": "^3.2.3",
28
- "@tarojs/components": "4.0.0-beta.35",
29
- "@tarojs/runner-utils": "4.0.0-beta.35",
30
- "@tarojs/helper": "4.0.0-beta.35",
31
- "@tarojs/runtime": "4.0.0-beta.35",
32
- "@tarojs/taro": "4.0.0-beta.35",
33
- "@tarojs/service": "4.0.0-beta.35",
34
- "@tarojs/shared": "4.0.0-beta.35"
28
+ "@tarojs/components": "4.0.0-beta.36",
29
+ "@tarojs/helper": "4.0.0-beta.36",
30
+ "@tarojs/runner-utils": "4.0.0-beta.36",
31
+ "@tarojs/runtime": "4.0.0-beta.36",
32
+ "@tarojs/service": "4.0.0-beta.36",
33
+ "@tarojs/shared": "4.0.0-beta.36",
34
+ "@tarojs/taro": "4.0.0-beta.36"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@rollup/plugin-commonjs": "^25.0.7",
@@ -44,7 +44,7 @@
44
44
  "solid-js": "^1.8.16",
45
45
  "tslib": "^2.4.0",
46
46
  "typescript": "^4.8.2",
47
- "rollup-plugin-copy": "4.0.0-beta.35"
47
+ "rollup-plugin-copy": "4.0.0-beta.36"
48
48
  },
49
49
  "scripts": {
50
50
  "prebuild": "rimraf ./dist",