@tarojs/plugin-platform-harmony-ets 4.0.0-beta.22 → 4.0.0-beta.23

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 (52) hide show
  1. package/dist/apis/index.ts +22 -12
  2. package/dist/apis/ui/animation/animation.ts +2 -1
  3. package/dist/apis/wxml/IntersectionObserver.ts +5 -1
  4. package/dist/components-harmony-ets/button.ets +8 -1
  5. package/dist/components-harmony-ets/canvas.ets +13 -5
  6. package/dist/components-harmony-ets/checkbox.ets +7 -3
  7. package/dist/components-harmony-ets/form.ets +10 -2
  8. package/dist/components-harmony-ets/icon.ets +8 -1
  9. package/dist/components-harmony-ets/image.ets +8 -1
  10. package/dist/components-harmony-ets/input.ets +2 -1
  11. package/dist/components-harmony-ets/label.ets +9 -2
  12. package/dist/components-harmony-ets/movableArea.ets +10 -3
  13. package/dist/components-harmony-ets/movableView.ets +10 -3
  14. package/dist/components-harmony-ets/picker.ets +1 -1
  15. package/dist/components-harmony-ets/progress.ets +8 -1
  16. package/dist/components-harmony-ets/radio.ets +7 -3
  17. package/dist/components-harmony-ets/scrollView.ets +9 -2
  18. package/dist/components-harmony-ets/slider.ets +2 -1
  19. package/dist/components-harmony-ets/style.ets +40 -4
  20. package/dist/components-harmony-ets/swiper.ets +8 -1
  21. package/dist/components-harmony-ets/switch.ets +3 -1
  22. package/dist/components-harmony-ets/text.ets +8 -1
  23. package/dist/components-harmony-ets/textArea.ets +2 -1
  24. package/dist/components-harmony-ets/utils/flexManager.ets +2 -2
  25. package/dist/components-harmony-ets/utils/helper.ets +1 -3
  26. package/dist/components-harmony-ets/utils/htmlParser/index.ts +1 -1
  27. package/dist/components-harmony-ets/utils/index.ts +4 -59
  28. package/dist/components-harmony-ets/video.ets +9 -2
  29. package/dist/components-harmony-ets/view.ets +9 -2
  30. package/dist/runtime-ets/current.ts +1 -0
  31. package/dist/runtime-ets/dom/bind.ts +3 -3
  32. package/dist/runtime-ets/dom/cssNesting.ts +104 -22
  33. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +2 -5
  34. package/dist/runtime-ets/dom/element/element.ts +1 -5
  35. package/dist/runtime-ets/dom/element/form.ts +4 -14
  36. package/dist/runtime-ets/dom/element/progress.ts +0 -1
  37. package/dist/runtime-ets/dom/element/text.ts +0 -8
  38. package/dist/runtime-ets/dom/element/video.ts +4 -3
  39. package/dist/runtime-ets/dom/node.ts +12 -11
  40. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +5 -4
  41. package/dist/runtime-ets/dom/stylesheet/util.ts +12 -10
  42. package/dist/runtime-ets/utils/index.ts +16 -2
  43. package/dist/runtime-ets/utils/info.ts +1 -1
  44. package/dist/runtime-framework/react/native-page.ts +1 -0
  45. package/dist/runtime-framework/react/page.ts +1 -0
  46. package/dist/runtime-framework/solid/reconciler/props.ts +3 -8
  47. package/dist/runtime-utils.js +16 -10
  48. package/dist/runtime-utils.js.map +1 -1
  49. package/dist/runtime.js +16 -10
  50. package/dist/runtime.js.map +1 -1
  51. package/package.json +10 -9
  52. /package/dist/template/{container.js/container.js → container.js} +0 -0
@@ -77,10 +77,8 @@ export class TaroNode extends TaroDataSourceElement {
77
77
 
78
78
  // 更新对应的 ArkUI 组件
79
79
  public updateComponent () {
80
- if (!this._isCompileMode) return
81
-
82
- // 半编译模式下走 @State 的更新模式
83
- if (this._isDynamicNode) {
80
+ // 非半编译模式或者半编译模式下拥有自主更新权力的节点走 @State 的更新模式
81
+ if (this._isDynamicNode || !this._isCompileMode) {
84
82
  this._updateTrigger++
85
83
  } else {
86
84
  this.parentNode?.updateComponent()
@@ -128,11 +126,12 @@ export class TaroNode extends TaroDataSourceElement {
128
126
  public set textContent (value: string) {
129
127
  if (this.nodeType === NodeType.TEXT_NODE) {
130
128
  this._textContent = value
131
- this.parentNode?.updateComponent()
132
129
  } else if (this.nodeType === NodeType.ELEMENT_NODE) {
133
130
  const node = new TaroTextNode(value)
134
131
  node._doc = this.ownerDocument
135
- this.childNodes = [node]
132
+ node.parentNode = this
133
+ this.childNodes.length = 0
134
+ this.childNodes.push(node)
136
135
  }
137
136
  }
138
137
 
@@ -150,7 +149,6 @@ export class TaroNode extends TaroDataSourceElement {
150
149
  public set nodeValue (value: string | null) {
151
150
  if (this.nodeType === NodeType.TEXT_NODE && value) {
152
151
  this.textContent = value
153
- this.parentNode?.updateComponent()
154
152
  }
155
153
  }
156
154
 
@@ -163,11 +161,13 @@ export class TaroNode extends TaroDataSourceElement {
163
161
  }
164
162
 
165
163
  // TODO cloneNode()、contains()
166
-
167
- public appendChild (child: TaroNode): TaroNode {
164
+ public connectParentNode (child: TaroNode) {
168
165
  child.parentNode?.removeChild(child)
169
166
  child.parentNode = this
167
+ }
170
168
 
169
+ public appendChild (child: TaroNode): TaroNode {
170
+ this.connectParentNode(child)
171
171
  this.childNodes.push(child)
172
172
  this.notifyDataAdd(this.childNodes.length - 1)
173
173
 
@@ -175,14 +175,15 @@ export class TaroNode extends TaroDataSourceElement {
175
175
  return child
176
176
  }
177
177
 
178
- public insertBefore (newNode: TaroNode, referenceNode: TaroNode | null): TaroNode {
178
+ public insertBefore (newNode: TaroNode, referenceNode?: TaroNode): TaroNode {
179
179
  newNode.parentNode?.removeChild(newNode)
180
180
 
181
- if (referenceNode === null) {
181
+ if (!referenceNode) {
182
182
  this.appendChild(newNode)
183
183
  } else {
184
184
  const idxOfRef = this.findIndex(referenceNode)
185
185
  this.childNodes.splice(idxOfRef, 0, newNode)
186
+ this.connectParentNode(newNode)
186
187
  // TODO: 优化
187
188
  this.notifyDataReload()
188
189
  }
@@ -2,11 +2,12 @@
2
2
 
3
3
  import { CSSProperties } from 'react'
4
4
 
5
+ import { TaroElement } from '../element/element'
5
6
  import { BORDER_STYLE_MAP, capitalizeFirstLetter, FlexManager, getNodeMarginOrPaddingData, getUnit } from './util'
6
7
 
7
- // 将web端的style转换为hm端的style
8
- export default function convertWebStyle2HmStyle(webStyle: CSSProperties) {
9
- const hmStyle: Record<string, any> = {}
8
+ // Note: web 端的 style 转换为 hm 端的 style
9
+ export default function convertWebStyle2HmStyle(webStyle: CSSProperties, node?: TaroElement) {
10
+ const hmStyle: Record<string, any> = node?._st?.hmStyle || {}
10
11
  Object.keys(webStyle).forEach((key) => {
11
12
  const value = webStyle[key]
12
13
  switch (key) {
@@ -405,7 +406,7 @@ export default function convertWebStyle2HmStyle(webStyle: CSSProperties) {
405
406
  }
406
407
  case 'WebkitLineClamp': {
407
408
  hmStyle.WebkitLineClamp = Number(value)
408
- break
409
+ break
409
410
  }
410
411
  case 'transform': {
411
412
  // todo: 需要更新
@@ -183,7 +183,6 @@ export class BORDER_STYLE_MAP {
183
183
  case BorderStyle.Solid: return 'solid'
184
184
  default: return ''
185
185
  }
186
-
187
186
  }
188
187
  }
189
188
 
@@ -191,25 +190,28 @@ export function getNodeMarginOrPaddingData (dataValue: string) {
191
190
  let res: any = {}
192
191
  if (dataValue) {
193
192
  const values = dataValue.toString().trim().split(new RegExp('\\s+'))
193
+ let val1: string
194
+ let val2: string
194
195
  switch (values.length) {
195
196
  case 1:
196
- res = { top: values[0], right: values[0], bottom: values[0], left: values[0] }
197
+ val1 = getUnit(values[0])
198
+ res = { top: val1, right: val1, bottom: val1, left: val1 }
197
199
  break
198
200
  case 2:
199
- res = { top: values[0], right: values[1], bottom: values[0], left: values[1] }
201
+ val1 = getUnit(values[0])
202
+ val2 = getUnit(values[1])
203
+ res = { top: val1, right: val2, bottom: val1, left: val2 }
200
204
  break
201
205
  case 3:
202
- res = { top: values[0], right: values[1], bottom: values[2], left: values[1] }
206
+ val2 = getUnit(values[1])
207
+ res = { top: getUnit(values[0]), right: val2, bottom: getUnit(values[2]), left: val2 }
203
208
  break
204
209
  case 4:
205
- res = { top: values[0], right: values[1], bottom: values[2], left: values[3] }
210
+ res = { top: getUnit(values[0]), right: getUnit(values[1]), bottom: getUnit(values[2]), left: getUnit(values[3]) }
206
211
  break
207
212
  default:
208
213
  break
209
214
  }
210
- Object.keys(res).forEach(key => {
211
- res[key] = getUnit(res[key]) || 0
212
- })
213
215
  }
214
216
  return res
215
217
  }
@@ -225,9 +227,9 @@ export function getUnit (val) {
225
227
  }
226
228
  if (val) {
227
229
  // 匹配vw\vh
228
- const exec = val.match(/(\d+)(vw|vh|px)$/)
230
+ const exec = val.match(/(-?\d*(\.\d+)?)(vw|vh|px)$/)
229
231
  if (exec) {
230
- const [, num, unit] = exec
232
+ const [, num, , unit] = exec
231
233
  return convertNumber2VP(parseFloat(num), unit)
232
234
  }
233
235
  }
@@ -49,10 +49,20 @@ export function convertNumber2VP (value: number, unit = 'px') {
49
49
  return pxTransformHelper(value, 'vp')
50
50
  }
51
51
 
52
+ export function parseClasses (classNames: string | string[] = []): string[] {
53
+ if (typeof classNames === 'string') {
54
+ return classNames.includes(' ') ? classNames.split(' ') : [classNames]
55
+ } else if (Array.isArray(classNames)) {
56
+ return classNames // Note: 不考虑支持单个元素传入多个类名的情况,过于损耗性能
57
+ }
58
+
59
+ return []
60
+ }
61
+
52
62
  // 合并静态样式,从样式表里面找到对应的样式
53
- export function calcStaticStyle (styleSheet: Record<string, CSSProperties>, classNames: string, style: CSSProperties): CSSProperties {
63
+ export function calcStaticStyle (styleSheet: Record<string, CSSProperties>, classNames: string | string[] = [], style: CSSProperties): CSSProperties {
54
64
  const obj: CSSProperties[] = []
55
- const classes = typeof classNames === 'string' ? classNames.split(' ') : []
65
+ const classes = parseClasses(classNames)
56
66
  if (classes.length === 1) {
57
67
  if (style) {
58
68
  return Object.assign({}, styleSheet[classNames], style)
@@ -96,6 +106,10 @@ export function getPageScrollerOrNode (scrollerOrNode: any, page: any) {
96
106
  return scrollerOrNode
97
107
  }
98
108
 
109
+ export function ObjectKeys(obj: object): string[] {
110
+ return Object.keys(obj)
111
+ }
112
+
99
113
  export function ObjectAssign(...objects) {
100
114
  return Object.assign.apply(this, [{}].concat(...objects))
101
115
  }
@@ -50,7 +50,7 @@ function tapCallbackToNodeAndUpdate (node: TaroElement, eventName: string, callb
50
50
  callback && callback(...eventResult)
51
51
  }
52
52
 
53
- if (!node._isDynamicNode || !node._isCompileMode) {
53
+ if (!node._isDynamicNode && node._isCompileMode) {
54
54
  node.updateComponent()
55
55
  }
56
56
  }
@@ -278,6 +278,7 @@ export function createNativePageConfig (Component, pageName: string, react: type
278
278
  safeExecute(this.$taroPath, ON_READY)
279
279
  // 通过事件触发子组件的生命周期
280
280
  requestAnimationFrame(() => eventCenter.trigger(getOnReadyEventKey(id)))
281
+ this.onReady = {}
281
282
  this.onReady.called = true
282
283
  })
283
284
  },
@@ -184,6 +184,7 @@ export function createPageConfig (component: any, pageName?: string, pageConfig?
184
184
  safeExecute(this.$taroPath, ON_READY)
185
185
  // 通过事件触发子组件的生命周期
186
186
  requestAnimationFrame(() => eventCenter.trigger(getOnReadyEventKey(id)))
187
+ this.onReady = {}
187
188
  this.onReady.called = true
188
189
  })
189
190
  },
@@ -108,13 +108,9 @@ interface DangerouslySetInnerHTML {
108
108
  export function setProperty (dom: TaroElement, name: string, value: unknown, oldValue?: unknown) {
109
109
  name = name === 'className' ? 'class' : name
110
110
 
111
- if (
112
- name === 'key' ||
113
- name === 'children' ||
114
- name === 'ref'
115
- ) {
116
- // skip
117
- } else if (name === 'style') {
111
+ if (['key', 'children', 'ref'].includes(name)) return
112
+
113
+ if (name === 'style') {
118
114
  const style = dom.style
119
115
  if (isString(value)) {
120
116
  style.cssText = value
@@ -169,7 +165,6 @@ export function setProperty (dom: TaroElement, name: string, value: unknown, old
169
165
  }
170
166
  }
171
167
  }
172
-
173
168
  } else if (isEventName(name)) {
174
169
  setEvent(dom, name, value, oldValue)
175
170
  } else if (name === 'dangerouslySetInnerHTML') {
@@ -266,7 +266,7 @@ const preloadWebview = /* @__PURE__ */ temporarilyNotSupport('preloadWebview');
266
266
  const preloadSkylineView = /* @__PURE__ */ temporarilyNotSupport('preloadSkylineView');
267
267
  const preloadAssets = /* @__PURE__ */ temporarilyNotSupport('preloadAssets');
268
268
 
269
- let display;
269
+ let display$1;
270
270
  let navigationIndicatorRect;
271
271
  let safeArea = null;
272
272
  let statusBarHeight;
@@ -279,18 +279,18 @@ Current.contextPromise.then((context) => {
279
279
  statusBarHeight = topRect.top + topRect.height;
280
280
  windowRect = mainWindow.getWindowProperties().windowRect;
281
281
  try {
282
- display = _display.getDefaultDisplaySync();
282
+ display$1 = _display.getDefaultDisplaySync();
283
283
  // @ts-ignore
284
- display.getCutoutInfo((err, { boundingRects = [], waterfallDisplayAreaRects = {} } = {}) => {
284
+ display$1.getCutoutInfo((err, { boundingRects = [], waterfallDisplayAreaRects = {} } = {}) => {
285
285
  var _a, _b, _c, _d, _e, _f;
286
286
  if (err === null || err === void 0 ? void 0 : err.code) {
287
287
  console.error('Failed to get cutout info', JSON.stringify(err));
288
288
  return;
289
289
  }
290
290
  const top = Math.max(...boundingRects.map(rect => rect.top + rect.height), ((_a = waterfallDisplayAreaRects.top) === null || _a === void 0 ? void 0 : _a.top) + ((_b = waterfallDisplayAreaRects.top) === null || _b === void 0 ? void 0 : _b.height), statusBarHeight);
291
- const bottom = display.height - Math.min((_c = waterfallDisplayAreaRects.bottom) === null || _c === void 0 ? void 0 : _c.top, navigationIndicatorRect === null || navigationIndicatorRect === void 0 ? void 0 : navigationIndicatorRect.top);
291
+ const bottom = display$1.height - Math.min((_c = waterfallDisplayAreaRects.bottom) === null || _c === void 0 ? void 0 : _c.top, navigationIndicatorRect === null || navigationIndicatorRect === void 0 ? void 0 : navigationIndicatorRect.top);
292
292
  const left = ((_d = waterfallDisplayAreaRects.left) === null || _d === void 0 ? void 0 : _d.left) + ((_e = waterfallDisplayAreaRects.left) === null || _e === void 0 ? void 0 : _e.width);
293
- const right = display.width - ((_f = waterfallDisplayAreaRects.right) === null || _f === void 0 ? void 0 : _f.left);
293
+ const right = display$1.width - ((_f = waterfallDisplayAreaRects.right) === null || _f === void 0 ? void 0 : _f.left);
294
294
  safeArea = {
295
295
  top,
296
296
  bottom,
@@ -329,11 +329,11 @@ const getSystemInfoSync = function () {
329
329
  res.notificationSoundAuthorized = false; // 通知带有声音的开关(仅 iOS 有效)boolean
330
330
  res.phoneCalendarAuthorized = null; // 使用日历的开关 boolean
331
331
  res.wifiEnabled = false; // Wi-Fi 的系统开关 boolean
332
- res.pixelRatio = display && display.densityPixels; // 设备像素比,number
332
+ res.pixelRatio = display$1 && display$1.densityPixels; // 设备像素比,number
333
333
  res.platform = 'harmony'; // 客户端平台 string
334
334
  res.safeArea = safeArea; // 在竖屏正方向下的安全区域 General.SafeAreaResult
335
- res.screenHeight = display === null || display === void 0 ? void 0 : display.height; // 屏幕高度,单位px number
336
- res.screenWidth = display === null || display === void 0 ? void 0 : display.width; // 屏幕宽度,单位px number
335
+ res.screenHeight = display$1 === null || display$1 === void 0 ? void 0 : display$1.height; // 屏幕高度,单位px number
336
+ res.screenWidth = display$1 === null || display$1 === void 0 ? void 0 : display$1.width; // 屏幕宽度,单位px number
337
337
  res.statusBarHeight = statusBarHeight; // 状态栏的高度,单位px number
338
338
  res.system = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.osFullName; // 操作系统及版本 string
339
339
  // Note: 更新配置时才能记录
@@ -3444,7 +3444,7 @@ class Animation {
3444
3444
  return this;
3445
3445
  }
3446
3446
  scale(sx, sy) {
3447
- this.rule.scale = { x: sx, y: sy };
3447
+ this.rule.scale = { x: sx, y: isUndefined(sy) ? sx : sy };
3448
3448
  return this;
3449
3449
  }
3450
3450
  scale3d(sx, sy, sz) {
@@ -4055,6 +4055,11 @@ class IntersectionObserver {
4055
4055
  });
4056
4056
  }
4057
4057
  }
4058
+ else {
4059
+ callback({
4060
+ errMsg: 'IntersectionObserver.observe:fail cannot find the node for selector.'
4061
+ });
4062
+ }
4058
4063
  }
4059
4064
  relativeTo() {
4060
4065
  temporarilyNotSupport('relativeTo')();
@@ -4806,7 +4811,8 @@ function initPxTransform({ designWidth = defaultDesignWidth, deviceRatio = defau
4806
4811
  config.unitPrecision = unitPrecision;
4807
4812
  }
4808
4813
  }
4809
- _display.getDefaultDisplaySync();
4814
+ const display = _display.getDefaultDisplaySync();
4815
+ display.width;
4810
4816
  function pxTransform(size) {
4811
4817
  var _a;
4812
4818
  const config = ((_a = Current.taro) === null || _a === void 0 ? void 0 : _a.config) || {};