@tarojs/plugin-platform-harmony-ets 4.0.0-beta.42 → 4.0.0-beta.44

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.
@@ -35,7 +35,7 @@ let windowRect
35
35
  }
36
36
 
37
37
  const top = Math.max(...boundingRects.map(rect => rect.top + rect.height), waterfallDisplayAreaRects.top?.top + waterfallDisplayAreaRects.top?.height, statusBarHeight)
38
- const bottom = display.height - Math.min(waterfallDisplayAreaRects.bottom?.top, navigationIndicatorRect?.top)
38
+ const bottom = Math.min(display.height - waterfallDisplayAreaRects.bottom?.top, navigationIndicatorRect?.top)
39
39
  const left = waterfallDisplayAreaRects.left?.left + waterfallDisplayAreaRects.left?.width
40
40
  const right = display.width - waterfallDisplayAreaRects.right?.left
41
41
  safeArea = {
@@ -72,6 +72,9 @@ export class Animation implements Taro.Animation {
72
72
  transformOrigin,
73
73
  rule: Object.assign({}, this.rule)
74
74
  })
75
+ if (this.rule.transform) {
76
+ this.rule.transform = Object.assign({}, this.rule.transform)
77
+ }
75
78
  return this
76
79
  }
77
80
 
@@ -86,92 +89,137 @@ export class Animation implements Taro.Animation {
86
89
  }
87
90
 
88
91
  rotate (angle: number): Taro.Animation {
89
- this.rule.rotate = { x: 0, y: 0, z: 1, angle }
92
+ if (!this.rule.transform) {
93
+ this.rule.transform = {}
94
+ }
95
+ this.rule.transform.Rotate = { x: 0, y: 0, z: 1, angle }
90
96
  return this
91
97
  }
92
98
 
93
99
  rotate3d (x: number, y?: number | undefined, z?: number | undefined, angle?: number | undefined): Taro.Animation {
94
- this.rule.rotate = { x, y, z, angle }
100
+ if (!this.rule.transform) {
101
+ this.rule.transform = {}
102
+ }
103
+ this.rule.transform.Rotate = { x, y, z, angle }
95
104
  return this
96
105
  }
97
106
 
98
107
  rotateX (angle: number): Taro.Animation {
99
- this.rule.rotate = { x: 1, y: 0, z: 0, angle }
108
+ if (!this.rule.transform) {
109
+ this.rule.transform = {}
110
+ }
111
+ this.rule.transform.Rotate = { x: 1, y: 0, z: 0, angle }
100
112
  return this
101
113
  }
102
114
 
103
115
  rotateY (angle: number): Taro.Animation {
104
- this.rule.rotate = { x: 0, y: 1, z: 0, angle }
116
+ if (!this.rule.transform) {
117
+ this.rule.transform = {}
118
+ }
119
+ this.rule.transform.Rotate = { x: 0, y: 1, z: 0, angle }
105
120
  return this
106
121
  }
107
122
 
108
123
  rotateZ (angle: number): Taro.Animation {
109
- this.rule.rotate = { x: 0, y: 0, z: 1, angle }
124
+ if (!this.rule.transform) {
125
+ this.rule.transform = {}
126
+ }
127
+ this.rule.transform.Rotate = { x: 0, y: 0, z: 1, angle }
110
128
  return this
111
129
  }
112
130
 
113
131
  scale (sx: number, sy?: number | undefined): Taro.Animation {
114
- this.rule.scale = { x: sx, y: isUndefined(sy) ? sx : sy }
132
+ if (!this.rule.transform) {
133
+ this.rule.transform = {}
134
+ }
135
+ this.rule.transform.Scale = { x: sx, y: isUndefined(sy) ? sx : sy }
115
136
  return this
116
137
  }
117
138
 
118
139
  scale3d (sx: number, sy: number, sz: number): Taro.Animation {
119
- this.rule.scale = { x: sx, y: sy, z: sz }
140
+ if (!this.rule.transform) {
141
+ this.rule.transform = {}
142
+ }
143
+ this.rule.transform.Scale = { x: sx, y: sy, z: sz }
120
144
  return this
121
145
  }
122
146
 
123
147
  scaleX (scale: number): Taro.Animation {
124
- this.rule.scale = { x: scale }
148
+ if (!this.rule.transform) {
149
+ this.rule.transform = {}
150
+ }
151
+ this.rule.transform.Scale = { x: scale }
125
152
  return this
126
153
  }
127
154
 
128
155
  scaleY (scale: number): Taro.Animation {
129
- this.rule.scale = { y: scale }
156
+ if (!this.rule.transform) {
157
+ this.rule.transform = {}
158
+ }
159
+ this.rule.transform.Scale = { y: scale }
130
160
  return this
131
161
  }
132
162
 
133
163
  scaleZ (scale: number): Taro.Animation {
134
- this.rule.scale = { z: scale }
164
+ if (!this.rule.transform) {
165
+ this.rule.transform = {}
166
+ }
167
+ this.rule.transform.Scale = { z: scale }
135
168
  return this
136
169
  }
137
170
 
138
171
  skew (ax: number, ay: number): Taro.Animation {
139
- this.rule.skew = { x: ax, y: ay }
172
+ temporarilyNotSupport('animation.skew:' + `${ax}, ${ay}`)(ax, ay)
140
173
  return this
141
174
  }
142
175
 
143
176
  skewX (angle: number): Taro.Animation {
144
- this.rule.skew = { x: angle }
177
+ temporarilyNotSupport('animation.skewX:' + angle)(angle)
145
178
  return this
146
179
  }
147
180
 
148
181
  skewY (angle: number): Taro.Animation {
149
- this.rule.skew = { y: angle }
182
+ temporarilyNotSupport('animation.skewY:' + angle)(angle)
150
183
  return this
151
184
  }
152
185
 
153
186
  translate (tx?: number | undefined, ty?: number | undefined): Taro.Animation {
154
- this.rule.translate = { x: tx, y: ty }
187
+ if (!this.rule.transform) {
188
+ this.rule.transform = {}
189
+ }
190
+ this.rule.transform.Translate = { x: tx, y: ty }
155
191
  return this
156
192
  }
157
193
 
158
194
  translate3d (tx?: number | undefined, ty?: number | undefined, tz?: number | undefined): Taro.Animation {
159
- this.rule.translate = { x: tx, y: ty, z: tz }
195
+ if (!this.rule.transform) {
196
+ this.rule.transform = {}
197
+ }
198
+ this.rule.transform.Translate = { x: tx, y: ty, z: tz }
160
199
  return this
161
200
  }
162
201
 
163
202
  translateX (translation: number): Taro.Animation {
164
- this.rule.translate = { x: translation }
203
+ if (!this.rule.transform) {
204
+ this.rule.transform = {}
205
+ }
206
+ this.rule.transform.Translate = { x: translation }
165
207
  return this
166
208
  }
167
209
 
168
210
  translateY (translation: number): Taro.Animation {
169
- this.rule.translate = { y: translation }
211
+ if (!this.rule.transform) {
212
+ this.rule.transform = {}
213
+ }
214
+ this.rule.transform.Translate = { y: translation }
170
215
  return this
171
216
  }
172
217
 
173
218
  translateZ (translation: number): Taro.Animation {
174
- this.rule.translate = { z: translation }
219
+ if (!this.rule.transform) {
220
+ this.rule.transform = {}
221
+ }
222
+ this.rule.transform.Translate = { z: translation }
175
223
  return this
176
224
  }
177
225
 
@@ -186,23 +234,17 @@ export class Animation implements Taro.Animation {
186
234
  }
187
235
 
188
236
  width (value: string | number): Taro.Animation {
189
- this.rule.size = {
190
- ...this.rule.size,
191
- width: value
192
- }
237
+ this.rule.width = value
193
238
  return this
194
239
  }
195
240
 
196
241
  height (value: string | number): Taro.Animation {
197
- this.rule.size = {
198
- ...this.rule.size,
199
- height: value
200
- }
242
+ this.rule.height = value
201
243
  return this
202
244
  }
203
245
 
204
246
  left (value: string | number): Taro.Animation {
205
- temporarilyNotSupport('animation.left:' + value)(value)
247
+ this.rule.left = value
206
248
  return this
207
249
  }
208
250
 
@@ -212,7 +254,7 @@ export class Animation implements Taro.Animation {
212
254
  }
213
255
 
214
256
  top (value: string | number): Taro.Animation {
215
- temporarilyNotSupport('animation.top:' + value)(value)
257
+ this.rule.top = value
216
258
  return this
217
259
  }
218
260
 
@@ -25,7 +25,7 @@ function textNormalFontStyle (style: TaroStyleType) {
25
25
  .fontStyle(style.fontStyle)
26
26
  .fontFamily(style.fontFamily)
27
27
  .decoration({
28
- type: style.textDecoration,
28
+ type: style.textDecoration?.type || TextDecorationType.None,
29
29
  color: style.color
30
30
  })
31
31
  }
@@ -10,21 +10,12 @@ class TextStyleModify implements AttributeModifier<TextAttribute> {
10
10
  node: TaroTextElement | null = null
11
11
  style: HarmonyStyle | null = null
12
12
  overwriteStyle: Record<string, TaroAny> = {}
13
- withNormal = false
14
-
15
- withNormalStyle () {
16
- this.withNormal = true
17
- return this
18
- }
19
-
20
- setAnimationStyle (overwriteStyle: Record<string, TaroAny>) {
21
- this.overwriteStyle = overwriteStyle
22
-
23
- return this
24
- }
13
+ withNormal: boolean = false
25
14
 
26
15
  setNode (node: TaroTextElement, initStyle?: HarmonyStyle) {
27
16
  this.node = node
17
+ this.withNormal = false
18
+ this.overwriteStyle = {}
28
19
  this.style = getNormalAttributes(this.node)
29
20
  this.initStyle = initStyle
30
21
  // 覆盖初始化样式
@@ -38,6 +29,16 @@ class TextStyleModify implements AttributeModifier<TextAttribute> {
38
29
  return this
39
30
  }
40
31
 
32
+ withNormalStyle () {
33
+ this.withNormal = true
34
+ return this
35
+ }
36
+
37
+ setAnimationStyle (overwriteStyle: Record<string, TaroAny>) {
38
+ this.overwriteStyle = overwriteStyle
39
+ return this
40
+ }
41
+
41
42
  applyNormalAttribute(instance: TextAttribute): void {
42
43
  if (this.node && this.style) {
43
44
  if (this.withNormal) {
@@ -55,18 +56,13 @@ class CommonStyleModify implements AttributeModifier<CommonAttribute> {
55
56
  initStyle?: TaroStyleType
56
57
  node: TaroElement | null = null
57
58
  style: TaroStyleType | null = null
58
- overwriteStyle: Record<string, TaroAny> = {}
59
-
60
- setAnimationStyle (overwriteStyle: Record<string, TaroAny>) {
61
- this.overwriteStyle = overwriteStyle
62
-
63
- return this
64
- }
59
+ overwriteStyle: TaroStyleType = {}
65
60
 
66
61
  setNode (node: TaroElement, initStyle?: TaroStyleType) {
67
62
  this.node = node
68
63
  this.style = getNormalAttributes(this.node)
69
64
  this.initStyle = initStyle
65
+ this.overwriteStyle = {}
70
66
  // 覆盖初始化样式
71
67
  if (initStyle) {
72
68
  Object.keys(initStyle).forEach(key => {
@@ -77,6 +73,16 @@ class CommonStyleModify implements AttributeModifier<CommonAttribute> {
77
73
  }
78
74
  return this
79
75
  }
76
+
77
+ setAnimationStyle (overwriteStyle: Record<string, TaroAny>) {
78
+ this.overwriteStyle = overwriteStyle
79
+ if (this.style && this.overwriteStyle) {
80
+ Object.keys(this.overwriteStyle).forEach(key => {
81
+ this.style![key] = this.overwriteStyle[key]
82
+ })
83
+ }
84
+ return this
85
+ }
80
86
 
81
87
  applyNormalAttribute(instance: CommonAttribute): void {
82
88
  if (this.node && this.style) {
@@ -145,26 +151,26 @@ class ColumnStyleModify extends CommonStyleModify {
145
151
 
146
152
  export function setAnimationAttributeIntoInstance(instance: CommonAttribute, overwriteStyle: Record<string, TaroAny>, style: TaroStyleType) {
147
153
  // Animation 需要提前和 @State 变量绑定才能产生动画效果,因此不能做 if else 判断
148
- instance.translate({
149
- x: overwriteStyle.translate?.x || style.transform?.Translate?.x,
150
- y: overwriteStyle.translate?.y || style.transform?.Translate?.y,
151
- z: overwriteStyle.translate?.z || style.transform?.Translate?.z,
152
- })
153
- instance.scale({
154
- x: overwriteStyle.scale?.x || style.transform?.Scale?.x,
155
- y: overwriteStyle.scale?.y || style.transform?.Scale?.y,
156
- z: overwriteStyle.scale?.z || style.transform?.Scale?.z,
157
- centerX: overwriteStyle.transformOrigin?.x || style.transformOrigin?.x || 0,
158
- centerY: overwriteStyle.transformOrigin?.y || style.transformOrigin?.y || 0,
159
- })
160
- instance.rotate({
161
- x: overwriteStyle.rotate?.x || style.transform?.Rotate?.x,
162
- y: overwriteStyle.rotate?.y || style.transform?.Rotate?.y,
163
- z: overwriteStyle.rotate?.z || style.transform?.Rotate?.z,
164
- centerX: overwriteStyle.transformOrigin?.x || style.transformOrigin?.x || 0,
165
- centerY: overwriteStyle.transformOrigin?.y || style.transformOrigin?.y || 0,
166
- angle: overwriteStyle.rotate?.angle || style.transform?.Rotate?.angle || 0,
167
- })
154
+ // instance.translate({
155
+ // x: overwriteStyle.translate?.x || style.transform?.Translate?.x,
156
+ // y: overwriteStyle.translate?.y || style.transform?.Translate?.y,
157
+ // z: overwriteStyle.translate?.z || style.transform?.Translate?.z,
158
+ // })
159
+ // instance.scale({
160
+ // x: overwriteStyle.scale?.x || style.transform?.Scale?.x,
161
+ // y: overwriteStyle.scale?.y || style.transform?.Scale?.y,
162
+ // z: overwriteStyle.scale?.z || style.transform?.Scale?.z,
163
+ // centerX: overwriteStyle.transformOrigin?.x || style.transformOrigin?.x || 0,
164
+ // centerY: overwriteStyle.transformOrigin?.y || style.transformOrigin?.y || 0,
165
+ // })
166
+ // instance.rotate({
167
+ // x: overwriteStyle.rotate?.x || style.transform?.Rotate?.x,
168
+ // y: overwriteStyle.rotate?.y || style.transform?.Rotate?.y,
169
+ // z: overwriteStyle.rotate?.z || style.transform?.Rotate?.z,
170
+ // centerX: overwriteStyle.transformOrigin?.x || style.transformOrigin?.x || 0,
171
+ // centerY: overwriteStyle.transformOrigin?.y || style.transformOrigin?.y || 0,
172
+ // angle: overwriteStyle.rotate?.angle || style.transform?.Rotate?.angle || 0,
173
+ // })
168
174
  }
169
175
 
170
176
  export function setNormalTextAttributeIntoInstance(instance: TextAttribute | SpanAttribute, style: HarmonyStyle, node?: TaroTextElement | null) {
@@ -185,7 +191,7 @@ export function setNormalTextAttributeIntoInstance(instance: TextAttribute | Spa
185
191
  }
186
192
  if (!isUndefined(style.textDecoration)) {
187
193
  instance.decoration({
188
- type: style.textDecoration,
194
+ type: style.textDecoration.type,
189
195
  color: style.color
190
196
  })
191
197
  }
@@ -360,6 +366,34 @@ export function setNormalAttributeIntoInstance(instance: CommonAttribute, style:
360
366
  // 为了适应position不设置z-index也能高于同层级组件,估且让设置了z-index的会更高一级
361
367
  instance.zIndex(style.zIndex + 1)
362
368
  }
369
+ if (!isUndefined(style.transform)) {
370
+ if (style.transform.Translate) {
371
+ instance.translate({
372
+ x: style.transform.Translate.x || 0,
373
+ y: style.transform.Translate.y || 0,
374
+ z: style.transform.Translate.z || 0,
375
+ })
376
+ }
377
+ if (style.transform.Scale) {
378
+ instance.scale({
379
+ x: style.transform.Scale.x || 0,
380
+ y: style.transform.Scale.y || 0,
381
+ z: style.transform.Scale.z || 0,
382
+ centerX: style.transformOrigin?.x || 0,
383
+ centerY: style.transformOrigin?.y || 0,
384
+ })
385
+ }
386
+ if (style.transform.Rotate) {
387
+ instance.rotate({
388
+ x: style.transform.Rotate.x || 0,
389
+ y: style.transform.Rotate.y || 0,
390
+ z: style.transform.Rotate.z || 0,
391
+ centerX: style.transformOrigin?.x || 0,
392
+ centerY: style.transformOrigin?.y || 0,
393
+ angle: style.transform.Rotate.angle
394
+ })
395
+ }
396
+ }
363
397
  }
364
398
 
365
399
  export const pseudoModify = new PseudoStyleModify()
package/dist/index.d.ts CHANGED
@@ -70,7 +70,7 @@ declare class Harmony extends TaroPlatformHarmony {
70
70
  indexOfLibraries(lib: string): number;
71
71
  removeFromLibraries(lib: string): void;
72
72
  moveLibraries(lib: string, target?: string, basedir?: string, sync?: boolean): void;
73
- replaceDefineValue(code: string, define: Record<string, string>): string;
73
+ replaceDefineValue(code: string, define: Record<string, string>, ext?: string): string;
74
74
  /**
75
75
  * 修改 Vite 配置
76
76
  */
package/dist/index.js CHANGED
@@ -506,8 +506,8 @@ let Harmony$1 = class Harmony extends TaroPlatformHarmony {
506
506
  if ([/(@tarojs[\\/]runtime|taro-runtime)[\\/]dist/].some(e => e.test(lib))) {
507
507
  define.global = 'globalThis';
508
508
  }
509
- code = this.replaceDefineValue(code, define);
510
509
  const ext = path__namespace.extname(target);
510
+ code = this.replaceDefineValue(code, define, ext);
511
511
  if (['.ts'].includes(ext)) {
512
512
  code = '// @ts-nocheck\n' + code;
513
513
  }
@@ -556,9 +556,13 @@ declare global {
556
556
  this.moveLibraries(realPath, target, basedir);
557
557
  }
558
558
  }
559
- replaceDefineValue(code, define) {
559
+ replaceDefineValue(code, define, ext = '.js') {
560
560
  Object.keys(define).forEach(key => {
561
- code = code.replace(new RegExp(`\\b${key}\\b`, 'g'), define[key]);
561
+ let value = define[key];
562
+ if (/^['"`].*['"`]$/.test(value) && ['.ts', '.tsx', '.ets'].includes(ext)) {
563
+ value = `(${value} as string)`;
564
+ }
565
+ code = code.replace(new RegExp(`\\b${key}\\b`, 'g'), value);
562
566
  });
563
567
  return code;
564
568
  }