@tarojs/plugin-platform-harmony-ets 4.0.0-beta.12 → 4.0.0-beta.121

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 (143) hide show
  1. package/dist/apis/base/system.ts +60 -25
  2. package/dist/apis/base/weapp/life-cycle.ts +1 -1
  3. package/dist/apis/canvas/index.ts +10 -1
  4. package/dist/apis/device/clipboard.ts +23 -8
  5. package/dist/apis/framework/index.ts +2 -6
  6. package/dist/apis/index.ts +25 -17
  7. package/dist/apis/media/image/index.ts +169 -17
  8. package/dist/apis/route/index.ts +1 -2
  9. package/dist/apis/storage/index.ts +135 -131
  10. package/dist/apis/ui/animation/animation.ts +71 -29
  11. package/dist/apis/ui/background.ts +3 -2
  12. package/dist/apis/ui/interaction/index.ts +58 -59
  13. package/dist/apis/ui/navigation-bar/index.ts +2 -2
  14. package/dist/apis/ui/pull-down-refresh.ts +9 -3
  15. package/dist/apis/ui/scroll/index.ts +6 -6
  16. package/dist/apis/ui/tab-bar.ts +4 -5
  17. package/dist/apis/utils/index.ts +20 -2
  18. package/dist/apis/utils/permissions.ts +6 -0
  19. package/dist/apis/wxml/IntersectionObserver.ts +18 -10
  20. package/dist/apis/wxml/selectorQuery.ts +26 -13
  21. package/dist/components-harmony-ets/button.ets +36 -9
  22. package/dist/components-harmony-ets/canvas.ets +51 -0
  23. package/dist/components-harmony-ets/checkbox.ets +69 -60
  24. package/dist/components-harmony-ets/form.ets +33 -15
  25. package/dist/components-harmony-ets/icon.ets +16 -8
  26. package/dist/components-harmony-ets/image.ets +22 -6
  27. package/dist/components-harmony-ets/index.ets +39 -0
  28. package/dist/components-harmony-ets/innerHtml.ets +6 -5
  29. package/dist/components-harmony-ets/input.ets +63 -37
  30. package/dist/components-harmony-ets/label.ets +43 -21
  31. package/dist/components-harmony-ets/listView.ets +32 -0
  32. package/dist/components-harmony-ets/movableArea.ets +110 -51
  33. package/dist/components-harmony-ets/movableView.ets +74 -47
  34. package/dist/components-harmony-ets/navigationBar.ets +65 -0
  35. package/dist/components-harmony-ets/pageMeta.ets +94 -0
  36. package/dist/components-harmony-ets/picker.ets +36 -33
  37. package/dist/components-harmony-ets/progress.ets +31 -24
  38. package/dist/components-harmony-ets/pseudo.ets +80 -0
  39. package/dist/components-harmony-ets/radio.ets +75 -66
  40. package/dist/components-harmony-ets/richText.ets +4 -25
  41. package/dist/components-harmony-ets/scrollList.ets +108 -0
  42. package/dist/components-harmony-ets/scrollView.ets +46 -42
  43. package/dist/components-harmony-ets/slider.ets +19 -15
  44. package/dist/components-harmony-ets/stickySection.ets +42 -0
  45. package/dist/components-harmony-ets/style.ets +386 -129
  46. package/dist/components-harmony-ets/swiper.ets +42 -5
  47. package/dist/components-harmony-ets/switch.ets +36 -32
  48. package/dist/components-harmony-ets/{index.ts → tag.ts} +6 -0
  49. package/dist/components-harmony-ets/text.ets +102 -46
  50. package/dist/components-harmony-ets/textArea.ets +49 -34
  51. package/dist/components-harmony-ets/utils/AttributeManager.ets +2 -2
  52. package/dist/components-harmony-ets/utils/DynamicCenter.ts +2 -2
  53. package/dist/components-harmony-ets/utils/flexManager.ets +49 -19
  54. package/dist/components-harmony-ets/utils/helper.ets +20 -8
  55. package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
  56. package/dist/components-harmony-ets/utils/htmlParser/index.ts +1 -1
  57. package/dist/components-harmony-ets/utils/index.ts +54 -50
  58. package/dist/components-harmony-ets/utils/styles.ets +169 -91
  59. package/dist/components-harmony-ets/video.ets +28 -20
  60. package/dist/components-harmony-ets/view.ets +45 -39
  61. package/dist/components-harmony-ets/webView.ets +6 -5
  62. package/dist/index.d.ts +152 -0
  63. package/dist/index.js +73 -44
  64. package/dist/index.js.map +1 -1
  65. package/dist/runtime-ets/bom/URL.ts +2 -0
  66. package/dist/runtime-ets/bom/document.ts +5 -4
  67. package/dist/runtime-ets/bom/getComputedStyle.ts +2 -3
  68. package/dist/runtime-ets/bom/history.ts +1 -0
  69. package/dist/runtime-ets/bom/location.ts +1 -0
  70. package/dist/runtime-ets/bom/navigator.ts +1 -21
  71. package/dist/runtime-ets/bom/raf.ts +1 -37
  72. package/dist/runtime-ets/bom/window.ts +10 -4
  73. package/dist/runtime-ets/constant.ts +17 -10
  74. package/dist/runtime-ets/current.ts +5 -2
  75. package/dist/runtime-ets/dom/bind.ts +28 -12
  76. package/dist/runtime-ets/dom/class-list.ts +2 -2
  77. package/dist/runtime-ets/dom/cssNesting.ts +419 -0
  78. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +28 -42
  79. package/dist/runtime-ets/dom/document.ts +9 -12
  80. package/dist/runtime-ets/dom/element/canvas.ts +137 -0
  81. package/dist/runtime-ets/dom/element/element.ts +379 -55
  82. package/dist/runtime-ets/dom/element/form.ts +26 -22
  83. package/dist/runtime-ets/dom/element/index.ts +22 -2
  84. package/dist/runtime-ets/dom/element/movableArea.ts +0 -1
  85. package/dist/runtime-ets/dom/element/movableView.ts +238 -2
  86. package/dist/runtime-ets/dom/element/normal.ts +27 -6
  87. package/dist/runtime-ets/dom/element/progress.ts +0 -2
  88. package/dist/runtime-ets/dom/element/text.ts +0 -8
  89. package/dist/runtime-ets/dom/element/video.ts +4 -4
  90. package/dist/runtime-ets/dom/element/webView.ts +4 -5
  91. package/dist/runtime-ets/dom/event-source.ts +1 -0
  92. package/dist/runtime-ets/dom/event.ts +3 -5
  93. package/dist/runtime-ets/dom/eventTarget.ts +3 -4
  94. package/dist/runtime-ets/dom/node.ts +53 -22
  95. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +418 -237
  96. package/dist/runtime-ets/dom/stylesheet/index.ts +29 -311
  97. package/dist/runtime-ets/dom/stylesheet/type.ts +53 -11
  98. package/dist/runtime-ets/dom/stylesheet/util.ts +33 -27
  99. package/dist/runtime-ets/emitter/emitter.ts +1 -0
  100. package/dist/runtime-ets/env.ts +1 -0
  101. package/dist/runtime-ets/index.ts +23 -7
  102. package/dist/runtime-ets/interface/event.ts +1 -1
  103. package/dist/runtime-ets/interface/index.ts +6 -0
  104. package/dist/runtime-ets/utils/index.ts +78 -19
  105. package/dist/runtime-ets/utils/info.ts +2 -2
  106. package/dist/runtime-ets/utils/router.ts +9 -0
  107. package/dist/runtime-framework/react/app.ts +15 -11
  108. package/dist/runtime-framework/react/hooks.ts +1 -2
  109. package/dist/runtime-framework/react/index.ts +0 -2
  110. package/dist/runtime-framework/react/native-page.ts +217 -81
  111. package/dist/runtime-framework/react/page.ts +4 -10
  112. package/dist/runtime-framework/react/utils/index.ts +3 -3
  113. package/dist/runtime-framework/solid/app.ts +29 -46
  114. package/dist/runtime-framework/solid/connect.ts +21 -3
  115. package/dist/runtime-framework/solid/hooks.ts +16 -11
  116. package/dist/runtime-framework/solid/index.ts +6 -2
  117. package/dist/runtime-framework/solid/page.ts +84 -31
  118. package/dist/runtime-framework/solid/reconciler/props.ts +73 -29
  119. package/dist/runtime-framework/solid/reconciler/render.ts +16 -6
  120. package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
  121. package/dist/runtime-framework/solid/utils/index.ts +3 -5
  122. package/dist/runtime-utils.d.ts +827 -0
  123. package/dist/runtime-utils.js +574 -285
  124. package/dist/runtime-utils.js.map +1 -1
  125. package/dist/runtime.d.ts +1 -0
  126. package/dist/runtime.js +574 -285
  127. package/dist/runtime.js.map +1 -1
  128. package/index.js +3 -1
  129. package/package.json +14 -15
  130. package/static/media/cancel.svg +1 -1
  131. package/static/media/circle.svg +1 -1
  132. package/static/media/clear.svg +1 -1
  133. package/static/media/download.svg +1 -1
  134. package/static/media/info.svg +1 -1
  135. package/static/media/info_circle.svg +1 -1
  136. package/static/media/search.svg +1 -1
  137. package/static/media/success.svg +1 -1
  138. package/static/media/success_no_circle.svg +1 -1
  139. package/static/media/warn.svg +1 -1
  140. package/types/harmony.d.ts +5 -0
  141. package/types/index.d.ts +4 -0
  142. package/types/runtime.d.ts +1 -1
  143. /package/dist/runtime-framework/solid/{contant.ts → constant.ts} +0 -0
package/dist/runtime.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { isFunction, isString, isArray, isObject, isNull, isNumber, isUndefined, queryToJson, PLATFORM_TYPE, singleQuote, internalComponents, mergeReconciler, mergeInternalComponents } from '@tarojs/shared';
2
2
  import _display from '@ohos.display';
3
- import { Current, window, hooks, document as document$1, getPageScrollerOrNode, findChildNodeWithDFS, setNodeEventCallbackAndTriggerComponentUpdate, AREA_CHANGE_EVENT_NAME, disconnectEvent, VISIBLE_CHANGE_EVENT_NAME } from '@tarojs/runtime';
4
- import { eventCenter, Events, History } from '@tarojs/runtime/dist/runtime.esm';
3
+ import { eventCenter, Current, window, eventSource, hooks, document as document$1, getPageScrollerOrNode, findChildNodeWithDFS, setNodeEventCallbackAndTriggerComponentUpdate, AREA_CHANGE_EVENT_NAME, disconnectEvent, VISIBLE_CHANGE_EVENT_NAME, Events, History, getCurrentInstance } from '@tarojs/runtime';
4
+ import '@ohos.abilityAccessCtrl';
5
5
  import ConfigurationConstant from '@ohos.app.ability.ConfigurationConstant';
6
6
  import deviceInfo from '@ohos.deviceInfo';
7
7
  import i18n from '@ohos.i18n';
@@ -21,6 +21,7 @@ import app from '@system.app';
21
21
  import file from '@system.file';
22
22
  import geoLocationManager from '@ohos.geoLocationManager';
23
23
  import mediaLibrary from '@ohos.multimedia.mediaLibrary';
24
+ import fs from '@ohos.file.fs';
24
25
  import picker from '@ohos.file.picker';
25
26
  import image from '@ohos.multimedia.image';
26
27
  import request$1 from '@ohos.request';
@@ -28,11 +29,8 @@ import http from '@ohos.net.http';
28
29
  import webSocket from '@ohos.net.webSocket';
29
30
  import router from '@ohos.router';
30
31
  import bundleManager from '@ohos.bundle.bundleManager';
31
- import dataPreferences from '@ohos.data.preferences';
32
- import hilog from '@ohos.hilog';
32
+ import distributedKVStore from '@ohos.data.distributedKVStore';
33
33
  import matrix4 from '@ohos.matrix4';
34
- import prompt from '@ohos.prompt';
35
- import { pxTransformHelper } from '@tarojs/taro';
36
34
 
37
35
  class MethodHandler {
38
36
  constructor({ name, success, fail, complete }) {
@@ -186,7 +184,7 @@ function temporarilyNotSupport(name, recommended) {
186
184
  return (option = {}, ...args) => {
187
185
  const { success, fail, complete } = option;
188
186
  const handle = new MethodHandler({ name, success, fail, complete });
189
- let errMsg = '暂时不支持 API';
187
+ let errMsg = `暂时不支持 API ${name}`;
190
188
  if (recommended) {
191
189
  errMsg += `, 请使用 ${recommended}`;
192
190
  }
@@ -266,33 +264,59 @@ const preloadWebview = /* @__PURE__ */ temporarilyNotSupport('preloadWebview');
266
264
  const preloadSkylineView = /* @__PURE__ */ temporarilyNotSupport('preloadSkylineView');
267
265
  const preloadAssets = /* @__PURE__ */ temporarilyNotSupport('preloadAssets');
268
266
 
269
- let display;
267
+ let display$1;
268
+ let navigationIndicatorRect;
270
269
  let safeArea = null;
271
- try {
272
- display = _display.getDefaultDisplaySync();
273
- // @ts-ignore
274
- display.getCutoutInfo((err, { boundingRects = [], waterfallDisplayAreaRects = {} } = {}) => {
275
- var _a, _b, _c, _d, _e, _f, _g, _h;
276
- if (err === null || err === void 0 ? void 0 : err.code) {
277
- console.error('Failed to get cutout info', JSON.stringify(err));
278
- return;
270
+ let statusBarHeight;
271
+ let windowRect;
272
+ Current.contextPromise.then((context) => {
273
+ const win = window.__ohos.getLastWindow(context);
274
+ win.then(mainWindow => {
275
+ const topRect = mainWindow.getWindowAvoidArea(window.__ohos.AvoidAreaType.TYPE_SYSTEM).topRect;
276
+ navigationIndicatorRect = mainWindow.getWindowAvoidArea(window.__ohos.AvoidAreaType.TYPE_NAVIGATION_INDICATOR).bottomRect;
277
+ statusBarHeight = topRect.top + topRect.height;
278
+ windowRect = mainWindow.getWindowProperties().windowRect;
279
+ try {
280
+ display$1 = _display.getDefaultDisplaySync();
281
+ setSafeArea({
282
+ top: statusBarHeight,
283
+ left: 0,
284
+ right: display$1.width,
285
+ bottom: navigationIndicatorRect === null || navigationIndicatorRect === void 0 ? void 0 : navigationIndicatorRect.top
286
+ });
287
+ // @ts-ignore
288
+ display$1.getCutoutInfo((err, { boundingRects = [], waterfallDisplayAreaRects = {} } = {}) => {
289
+ var _a, _b, _c, _d, _e, _f;
290
+ if (err === null || err === void 0 ? void 0 : err.code) {
291
+ console.error('Failed to get cutout info', JSON.stringify(err));
292
+ return;
293
+ }
294
+ 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);
295
+ const bottom = Math.min(display$1.height - ((_c = waterfallDisplayAreaRects.bottom) === null || _c === void 0 ? void 0 : _c.top), navigationIndicatorRect === null || navigationIndicatorRect === void 0 ? void 0 : navigationIndicatorRect.top);
296
+ const left = ((_d = waterfallDisplayAreaRects.left) === null || _d === void 0 ? void 0 : _d.left) + ((_e = waterfallDisplayAreaRects.left) === null || _e === void 0 ? void 0 : _e.width);
297
+ const right = display$1.width - ((_f = waterfallDisplayAreaRects.right) === null || _f === void 0 ? void 0 : _f.left);
298
+ setSafeArea({
299
+ top,
300
+ left,
301
+ right,
302
+ bottom
303
+ });
304
+ });
305
+ }
306
+ catch (e) {
307
+ console.error('Failed to get display', e);
279
308
  }
280
- const top = Math.max(...boundingRects.map(rect => rect.top * 2 + rect.height), ((_a = waterfallDisplayAreaRects.top) === null || _a === void 0 ? void 0 : _a.top) + ((_b = waterfallDisplayAreaRects.top) === null || _b === void 0 ? void 0 : _b.height));
281
- const bottom = (((_c = waterfallDisplayAreaRects.bottom) === null || _c === void 0 ? void 0 : _c.top) + ((_d = waterfallDisplayAreaRects.bottom) === null || _d === void 0 ? void 0 : _d.height)) || display.height;
282
- const left = ((_e = waterfallDisplayAreaRects.left) === null || _e === void 0 ? void 0 : _e.left) + ((_f = waterfallDisplayAreaRects.left) === null || _f === void 0 ? void 0 : _f.width);
283
- const right = (((_g = waterfallDisplayAreaRects.right) === null || _g === void 0 ? void 0 : _g.left) + ((_h = waterfallDisplayAreaRects.right) === null || _h === void 0 ? void 0 : _h.width)) || display.width;
284
- safeArea = {
285
- top,
286
- bottom,
287
- left,
288
- right,
289
- height: bottom - top,
290
- width: right - left,
291
- };
292
309
  });
293
- }
294
- catch (e) {
295
- console.error('Failed to get display', e);
310
+ });
311
+ function setSafeArea({ top, left, right, bottom }) {
312
+ safeArea = {
313
+ top,
314
+ bottom,
315
+ left,
316
+ right,
317
+ height: bottom - top,
318
+ width: right - left,
319
+ };
296
320
  }
297
321
  /* 同步版本 */
298
322
  const getSystemInfoSync = function () {
@@ -317,17 +341,17 @@ const getSystemInfoSync = function () {
317
341
  res.notificationSoundAuthorized = false; // 通知带有声音的开关(仅 iOS 有效)boolean
318
342
  res.phoneCalendarAuthorized = null; // 使用日历的开关 boolean
319
343
  res.wifiEnabled = false; // Wi-Fi 的系统开关 boolean
320
- res.pixelRatio = display && (Math.round(display.xDPI / display.width * 100) / 100); // 设备像素比,number
344
+ res.pixelRatio = display$1 && display$1.densityPixels; // 设备像素比,number
321
345
  res.platform = 'harmony'; // 客户端平台 string
322
346
  res.safeArea = safeArea; // 在竖屏正方向下的安全区域 General.SafeAreaResult
323
- res.screenHeight = display === null || display === void 0 ? void 0 : display.height; // 屏幕高度,单位px number
324
- res.screenWidth = display === null || display === void 0 ? void 0 : display.width; // 屏幕宽度,单位px number
325
- res.statusBarHeight = safeArea === null || safeArea === void 0 ? void 0 : safeArea.top; // 状态栏的高度,单位px number
347
+ res.screenHeight = display$1 === null || display$1 === void 0 ? void 0 : display$1.height; // 屏幕高度,单位px number
348
+ res.screenWidth = display$1 === null || display$1 === void 0 ? void 0 : display$1.width; // 屏幕宽度,单位px number
349
+ res.statusBarHeight = statusBarHeight; // 状态栏的高度,单位px number
326
350
  res.system = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.osFullName; // 操作系统及版本 string
327
351
  // Note: 更新配置时才能记录
328
352
  res.theme = ((_b = AppStorage.get('__TARO_APP_CONFIG')) === null || _b === void 0 ? void 0 : _b.colorMode) === ConfigurationConstant.ColorMode.COLOR_MODE_DARK ? 'dark' : 'light'; // 系统当前主题,取值为light或dark 'light' | 'dark'
329
- res.windowHeight = display === null || display === void 0 ? void 0 : display.height; // 可使用窗口高度,单位px number
330
- res.windowWidth = display === null || display === void 0 ? void 0 : display.width; // 可使用窗口宽度,单位px number
353
+ res.windowHeight = windowRect === null || windowRect === void 0 ? void 0 : windowRect.height; // 可使用窗口高度,单位px number
354
+ res.windowWidth = windowRect === null || windowRect === void 0 ? void 0 : windowRect.width; // 可使用窗口宽度,单位px number
331
355
  res.version = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.displayVersion; // 版本号 string
332
356
  return res;
333
357
  };
@@ -434,7 +458,13 @@ const base64ToArrayBuffer = /* @__PURE__ */ temporarilyNotSupport('base64ToArray
434
458
  /** 创建离屏 canvas 实例 */
435
459
  const createOffscreenCanvas = /* @__PURE__ */ temporarilyNotSupport('createOffscreenCanvas');
436
460
  /** 创建 canvas 的绘图上下文 CanvasContext 对象 */
437
- const createCanvasContext = /* @__PURE__ */ temporarilyNotSupport('createOffscreenCanvas');
461
+ // export const createCanvasContext = /* @__PURE__ */ temporarilyNotSupport('createOffscreenCanvas')
462
+ const createCanvasContext = (canvasId) => {
463
+ const dom = eventSource.get(`canvasId-${canvasId}`);
464
+ // return dom as TaroCanvasElement
465
+ if (dom)
466
+ return dom.context;
467
+ };
438
468
  /** 把当前画布指定区域的内容导出生成指定大小的图片 */
439
469
  const canvasToTempFilePath = /* @__PURE__ */ temporarilyNotSupport('createOffscreenCanvas');
440
470
  /** 将像素数据绘制到画布 */
@@ -555,7 +585,7 @@ const getBatteryInfoSync = () => ({
555
585
  isCharging: [BatteryChargeState.ENABLE, BatteryChargeState.FULL].includes(batteryInfo.chargingStatus),
556
586
  level: batteryInfo.batterySOC
557
587
  });
558
- const getBatteryInfo = ({ success, fail, complete } = {}) => __awaiter(void 0, void 0, void 0, function* () {
588
+ const getBatteryInfo = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* ({ success, fail, complete } = {}) {
559
589
  const handle = new MethodHandler({ name: 'getBatteryInfo', success, fail, complete });
560
590
  try {
561
591
  return handle.success(getBatteryInfoSync());
@@ -627,9 +657,26 @@ const setClipboardData = function (options) {
627
657
  });
628
658
  }
629
659
  return new Promise((resolve, reject) => {
660
+ var _a, _b;
630
661
  const systemPasteboard = pasteboard.getSystemPasteboard();
631
- const pasteData = pasteboard.createPlainTextData(data);
632
- systemPasteboard.setPasteData(pasteData, (error, data) => {
662
+ const pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, data);
663
+ try {
664
+ systemPasteboard.setDataSync(pasteData);
665
+ // @ts-ignore
666
+ const uiContext = (_b = (_a = Current === null || Current === void 0 ? void 0 : Current.page) === null || _a === void 0 ? void 0 : _a.getUIContext) === null || _b === void 0 ? void 0 : _b.call(_a);
667
+ if (!uiContext)
668
+ return;
669
+ uiContext.getPromptAction().showToast({
670
+ message: '内容已复制',
671
+ duration: 1500,
672
+ bottom: '50%',
673
+ showMode: 1 // 设置弹窗显示模式,显示在应用之上。
674
+ });
675
+ return handle.success({
676
+ data,
677
+ }, { resolve, reject });
678
+ }
679
+ catch (error) {
633
680
  if (error) {
634
681
  console.error('Failed to set PasteData. Cause: ' + JSON.stringify(error));
635
682
  res = {
@@ -638,12 +685,7 @@ const setClipboardData = function (options) {
638
685
  };
639
686
  callAsyncFail(reject, res, options);
640
687
  }
641
- else {
642
- return handle.success({
643
- data,
644
- }, { resolve, reject });
645
- }
646
- });
688
+ }
647
689
  });
648
690
  };
649
691
  /**
@@ -654,7 +696,7 @@ const getClipboardData = function (options) {
654
696
  const handle = new MethodHandler({ name: 'getClipboardData', success, fail, complete });
655
697
  return new Promise((resolve, reject) => {
656
698
  const systemPasteboard = pasteboard.getSystemPasteboard();
657
- systemPasteboard.getPasteData((error, pasteData) => {
699
+ systemPasteboard.getData((error, pasteData) => {
658
700
  if (error) {
659
701
  console.error('Failed to obtain PasteData. Cause: ' + JSON.stringify(error));
660
702
  return handle.fail({
@@ -793,7 +835,7 @@ const getNetworkType = (options = {}) => {
793
835
  });
794
836
  };
795
837
  const networkStatusManager = new CallbackManager();
796
- const networkStatusListener = (data, code = 0) => __awaiter(void 0, void 0, void 0, function* () {
838
+ const networkStatusListener = (data_1, ...args_1) => __awaiter(void 0, [data_1, ...args_1], void 0, function* (data, code = 0) {
797
839
  if (code > 0) {
798
840
  return networkStatusManager.trigger({ isConnected: false, networkType: 'none' });
799
841
  }
@@ -2006,7 +2048,6 @@ function getEnv() {
2006
2048
  }
2007
2049
  // TODO
2008
2050
  const getCurrentPages = () => [];
2009
- const getCurrentInstance = () => Current;
2010
2051
  const requirePlugin$1 = temporarilyNotSupport('requirePlugin');
2011
2052
 
2012
2053
  // @ts-nocheck
@@ -2036,7 +2077,7 @@ function formatLocation(location) {
2036
2077
  altitude: location.altitude,
2037
2078
  accuracy: location.accuracy,
2038
2079
  speed: location.speed,
2039
- verticalAccuracy: 0,
2080
+ verticalAccuracy: 0, // OHOS 不支持返回此参数,直接设置为默认值
2040
2081
  horizontalAccuracy: 0 // OHOS 不支持返回此参数,直接设置为默认值
2041
2082
  };
2042
2083
  return wxLocate;
@@ -2228,17 +2269,11 @@ const chooseMedia = function (options) {
2228
2269
  // HarmonyOS 图片模块首批接口从API version 7开始支持。
2229
2270
  // HarmonyOS 文档链接:https://developer.harmonyos.com/cn/docs/documentation/doc-references/js-apis-image-0000001122977382
2230
2271
  // WX 文档链接:https://developers.weixin.qq.com/miniprogram/dev/api/media/image/wx.saveImageToPhotosAlbum.html
2231
- // ✅ wx.getImageInfo(Object object) API7以上支持
2232
- // ✅ wx.compressImage(Object object) API7以上支持
2233
- // ✅ wx.chooseImage(Object object)
2234
- // ❌ wx.chooseMessageFile(Object object) HarmonyOS不支持
2235
- // ❌ wx.saveImageToPhotosAlbum(Object object) api 9+ HarmonyOS不支持
2236
- // ❌ wx.previewImage(Object object) api 9+ HarmonyOS不支持
2237
2272
  const getImageInfoSchema = {
2238
- url: 'String'
2273
+ src: 'String'
2239
2274
  };
2240
2275
  const compressImageSchema = {
2241
- url: 'String'
2276
+ src: 'String'
2242
2277
  };
2243
2278
  const chooseImageSchema = {
2244
2279
  count: 'Number'
@@ -2268,6 +2303,42 @@ const getImageInfo = function (options) {
2268
2303
  });
2269
2304
  });
2270
2305
  };
2306
+ class CompressedImageInfo {
2307
+ constructor() {
2308
+ this.imageUri = ''; // 压缩后图片保存位置的uri
2309
+ this.imageByteLength = 0; // 压缩后图片字节长度
2310
+ }
2311
+ }
2312
+ function saveImage(compressedImageData, compressedImageUri) {
2313
+ return __awaiter(this, void 0, void 0, function* () {
2314
+ const tempArr = compressedImageUri.split('/');
2315
+ const name = tempArr[tempArr.length - 1];
2316
+ const context = getContext(Current === null || Current === void 0 ? void 0 : Current.page);
2317
+ const applicationContext = context.getApplicationContext();
2318
+ const tempDir = applicationContext.tempDir;
2319
+ const filePath = `${tempDir}/${name}`;
2320
+ try {
2321
+ const res = fs.accessSync(filePath);
2322
+ if (res) {
2323
+ // 如果图片afterCompressiona.jpeg已存在,则删除
2324
+ fs.unlinkSync(filePath);
2325
+ }
2326
+ }
2327
+ catch (err) {
2328
+ console.error(`[Taro] saveImage Error: AccessSync failed with error message: ${err.message}, error code: ${err.code}`);
2329
+ }
2330
+ // 知识点:保存图片。获取最终图片压缩数据compressedImageData,保存图片。
2331
+ // 压缩图片数据写入文件
2332
+ const file = fs.openSync(filePath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
2333
+ fs.writeSync(file.fd, compressedImageData);
2334
+ fs.closeSync(file);
2335
+ // 获取压缩图片信息
2336
+ const compressedImageInfo = new CompressedImageInfo();
2337
+ compressedImageInfo.imageUri = filePath;
2338
+ compressedImageInfo.imageByteLength = compressedImageData.byteLength;
2339
+ return compressedImageInfo;
2340
+ });
2341
+ }
2271
2342
  const compressImage = function (options) {
2272
2343
  return new Promise((resolve, reject) => {
2273
2344
  try {
@@ -2277,27 +2348,62 @@ const compressImage = function (options) {
2277
2348
  const res = { errMsg: error.message };
2278
2349
  return callAsyncFail(reject, res, options);
2279
2350
  }
2280
- const { src, quality = 80 } = options;
2281
- const source = image.createImageSource(src);
2351
+ const { src, quality = 80, compressedWidth, compressedHeight } = options;
2352
+ const srcAfterCompress = src.includes('_after_compress') ? src : src.split('.').join('_after_compress.');
2353
+ const file = fs.openSync(src, fs.OpenMode.READ_ONLY);
2354
+ // const stat = fs.statSync(file.fd)
2355
+ // console.log('[Taro] 压缩前图片的大小为:', stat.size)
2356
+ const source = image.createImageSource(file.fd);
2282
2357
  if (isNull(source)) {
2283
2358
  const createImageSourceError = { errMsg: 'compressImage fail: createImageSource has failed.' };
2284
2359
  callAsyncFail(reject, createImageSourceError, options);
2285
2360
  return;
2286
2361
  }
2287
- const packer = image.createImagePacker(src);
2288
- if (isNull(packer)) {
2289
- const createImagePackerError = { errMsg: 'compressImage fail: createImagePacker has failed.' };
2290
- callAsyncFail(reject, createImagePackerError, options);
2362
+ const width = source.getImageInfoSync().size.width;
2363
+ const height = source.getImageInfoSync().size.height;
2364
+ let wantWidth = compressedWidth || compressedHeight || 0;
2365
+ let wantHeight = compressedHeight || compressedWidth || 0;
2366
+ if (width > wantWidth || height > wantHeight) {
2367
+ const heightRatio = height / wantHeight;
2368
+ const widthRatio = width / wantWidth;
2369
+ const finalRatio = heightRatio < widthRatio ? heightRatio : widthRatio;
2370
+ wantWidth = Math.round(width / finalRatio);
2371
+ wantHeight = Math.round(height / finalRatio);
2291
2372
  }
2292
- const packingOptionsOHOS = {
2293
- // TODO:需要获取文件名后缀
2294
- format: 'image/jpeg',
2295
- quality: quality
2373
+ const decodingOptions = {
2374
+ editable: true,
2375
+ desiredPixelFormat: image.PixelMapFormat.RGBA_8888,
2376
+ desiredSize: { width: wantWidth, height: wantHeight }
2296
2377
  };
2297
- packer.packing(source, packingOptionsOHOS).then((value) => {
2298
- callAsyncSuccess(resolve, value, options);
2299
- }).catch((error) => {
2300
- callAsyncFail(reject, error, options);
2378
+ source.createPixelMap(decodingOptions, (error, pixelMap) => {
2379
+ if (error !== undefined) {
2380
+ fs.closeSync(file);
2381
+ const res = { errMsg: error };
2382
+ callAsyncFail(reject, res, options);
2383
+ }
2384
+ else {
2385
+ const packer = image.createImagePacker(file.fd);
2386
+ if (isNull(packer)) {
2387
+ fs.closeSync(file);
2388
+ const createImagePackerError = { errMsg: 'compressImage fail: createImagePacker has failed.' };
2389
+ callAsyncFail(reject, createImagePackerError, options);
2390
+ return;
2391
+ }
2392
+ const isPNG = src.endsWith('.png');
2393
+ const packingOptionsOHOS = {
2394
+ format: isPNG ? 'image/png' : 'image/jpeg',
2395
+ quality: quality
2396
+ };
2397
+ packer.packing(pixelMap, packingOptionsOHOS).then((value) => {
2398
+ fs.closeSync(file);
2399
+ saveImage(value, srcAfterCompress).then(result => {
2400
+ callAsyncSuccess(resolve, { tempFilePath: result.imageUri }, options);
2401
+ });
2402
+ }).catch((error) => {
2403
+ fs.closeSync(file);
2404
+ callAsyncFail(reject, error, options);
2405
+ });
2406
+ }
2301
2407
  });
2302
2408
  });
2303
2409
  };
@@ -2312,10 +2418,64 @@ const chooseImage = function (options) {
2312
2418
  }
2313
2419
  const { count = 9 } = options;
2314
2420
  const photoViewPicker = new picker.PhotoViewPicker();
2421
+ let sizeType = options.sizeType;
2422
+ if (!sizeType || !sizeType.length) {
2423
+ sizeType = ['compressed', 'original'];
2424
+ }
2315
2425
  photoSelectOptions.maxSelectNumber = count; // 选择媒体文件的最大数目
2316
2426
  photoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE; // 过滤选择媒体文件类型为IMAGE
2317
2427
  photoViewPicker.select(photoSelectOptions).then((photoSelectResult) => {
2318
- callAsyncSuccess(resolve, { tempFilePaths: photoSelectResult.photoUris });
2428
+ const result = {};
2429
+ const isOrigin = photoSelectResult.isOriginalPhoto;
2430
+ if (isOrigin) {
2431
+ const tempFilePaths = [];
2432
+ const tempFiles = photoSelectResult.photoUris.map(uri => {
2433
+ const file = fs.openSync(uri, fs.OpenMode.READ_ONLY);
2434
+ const stat = fs.statSync(file.fd);
2435
+ const size = stat.size;
2436
+ fs.closeSync(file);
2437
+ tempFilePaths.push(uri);
2438
+ return {
2439
+ size,
2440
+ path: uri,
2441
+ };
2442
+ });
2443
+ result.tempFiles = tempFiles;
2444
+ result.tempFilePaths = tempFilePaths;
2445
+ callAsyncSuccess(resolve, result, options);
2446
+ }
2447
+ else {
2448
+ const actions = photoSelectResult.photoUris.map(uri => {
2449
+ return new Promise(resolve => {
2450
+ compressImage({
2451
+ src: uri,
2452
+ compressedWidth: getSystemInfoSync().screenWidth / 2,
2453
+ compressedHeight: getSystemInfoSync().screenHeight / 2,
2454
+ success: (compressResult) => {
2455
+ resolve(compressResult.tempFilePath);
2456
+ }
2457
+ });
2458
+ });
2459
+ });
2460
+ Promise.all(actions).then(tempFilePaths => {
2461
+ const tempFiles = tempFilePaths.map(uri => {
2462
+ const file = fs.openSync(uri, fs.OpenMode.READ_ONLY);
2463
+ const stat = fs.statSync(file.fd);
2464
+ const size = stat.size;
2465
+ fs.closeSync(file);
2466
+ return {
2467
+ size,
2468
+ path: uri,
2469
+ };
2470
+ });
2471
+ result.tempFilePaths = tempFilePaths;
2472
+ result.tempFiles = tempFiles;
2473
+ callAsyncSuccess(resolve, result, options);
2474
+ }).catch(error => {
2475
+ const res = { errMsg: error };
2476
+ return callAsyncFail(reject, res, options);
2477
+ });
2478
+ }
2319
2479
  }).catch((error) => {
2320
2480
  callAsyncFail(reject, error, options);
2321
2481
  });
@@ -3217,144 +3377,153 @@ const createCacheManager = /* @__PURE__ */ temporarilyNotSupport('createCacheMan
3217
3377
  * https://developer.harmonyos.com/cn/docs/documentation/doc-references-V3/js-apis-data-preferences-0000001427745052-V3
3218
3378
  */
3219
3379
  let context;
3220
- let preferences;
3380
+ let kvManager;
3381
+ let kvStore;
3382
+ let kvStorePromise;
3221
3383
  Current.contextPromise.then((ctx) => {
3222
3384
  context = ctx;
3223
- return context;
3224
- });
3225
- function getPreferences() {
3385
+ const kvManagerConfig = {
3386
+ context: context,
3387
+ bundleName: 'com.example.taro'
3388
+ };
3226
3389
  try {
3227
- if (!preferences) {
3228
- const data = bundleManager.getBundleInfoForSelfSync(bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION);
3229
- preferences = dataPreferences.getPreferencesSync(context, { name: `${data.appInfo.uid}Store` });
3230
- }
3390
+ // 创建KVManager实例
3391
+ kvManager = distributedKVStore.createKVManager(kvManagerConfig);
3392
+ // 继续创建获取数据库
3393
+ const options = {
3394
+ createIfMissing: true,
3395
+ encrypt: false,
3396
+ backup: false,
3397
+ autoSync: false,
3398
+ // kvStoreType不填时,默认创建多设备协同数据库
3399
+ kvStoreType: distributedKVStore.KVStoreType.SINGLE_VERSION,
3400
+ // 多设备协同数据库:kvStoreType: distributedKVStore.KVStoreType.DEVICE_COLLABORATION,
3401
+ securityLevel: distributedKVStore.SecurityLevel.S1
3402
+ };
3403
+ const data = bundleManager.getBundleInfoForSelfSync(bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION);
3404
+ kvStorePromise = new Promise(resolve => {
3405
+ kvManager.getKVStore(`${data.appInfo.uid}Store`, options, (err, store) => {
3406
+ if (err) {
3407
+ console.error(`Failed to get KVStore: Code:${err.code},message:${err.message}`);
3408
+ return;
3409
+ }
3410
+ kvStore = store;
3411
+ // 请确保获取到键值数据库实例后,再进行相关数据操作
3412
+ resolve();
3413
+ });
3414
+ });
3231
3415
  }
3232
- catch (error) {
3233
- hilog.error(0x0000, 'TaroFailedTag', 'Failed to load the storage. Cause: %{public}s', error.code ? JSON.stringify(error) : error.message || error);
3416
+ catch (e) {
3417
+ console.error(`Failed to create KVManager. Code:${e.code},message:${e.message}`);
3234
3418
  }
3235
- return preferences;
3236
- }
3419
+ return context;
3420
+ });
3237
3421
  const storageSchema = {
3238
3422
  key: 'String'
3239
3423
  };
3240
- function getStorage(options) {
3241
- const { key, success, fail, complete } = options || {};
3242
- const handle = new MethodHandler({ name: 'getStorage', success, fail, complete });
3243
- return new Promise((resolve, reject) => {
3244
- try {
3245
- validateParams('getStorage', options, storageSchema);
3246
- }
3247
- catch (error) {
3248
- const res = { errMsg: error.message };
3249
- return handle.fail(res, { resolve, reject });
3250
- }
3251
- const preferences = getPreferences();
3252
- if (!preferences)
3253
- return handle.fail({}, { resolve, reject });
3254
- const data = preferences.getSync(key, null);
3255
- if (data) {
3256
- return handle.success({ data }, { resolve, reject });
3424
+ function checkContextExist(api, isAsync = false) {
3425
+ if (!context) {
3426
+ const message = `${api} 调用失败,Taro 不支持过早地调用 ${api},请确保页面已经渲染完成再调用此 API`;
3427
+ if (isAsync) {
3428
+ return {
3429
+ isExist: false,
3430
+ error: Promise.reject(new Error(message))
3431
+ };
3257
3432
  }
3258
3433
  else {
3259
- return handle.success({ errMsg: 'data not found' }, { resolve, reject });
3434
+ console.warn(message);
3435
+ return {
3436
+ isExist: false,
3437
+ };
3260
3438
  }
3261
- });
3262
- }
3263
- function getStorageSync(key) {
3264
- if (!key) {
3265
- throw new Error('getStorageSync:fail parameter error: parameter should be String');
3266
3439
  }
3267
- const preferences = getPreferences();
3268
- if (!preferences) {
3269
- throw new Error('getStorageSync:fail:preferences is null');
3270
- }
3271
- const data = preferences.getSync(key, null);
3272
- if (data) {
3273
- return data;
3274
- }
3275
- else {
3276
- throw new Error('data not found');
3277
- }
3278
- }
3279
- function setStorage(options) {
3280
- const { key, data, success, fail, complete } = options || {};
3281
- const handle = new MethodHandler({ name: 'setStorage', success, fail, complete });
3282
- return new Promise((resolve, reject) => {
3283
- try {
3284
- validateParams('setStorage', options, storageSchema);
3285
- }
3286
- catch (error) {
3287
- const res = { errMsg: error.message };
3288
- return handle.fail(res, { resolve, reject });
3289
- }
3290
- const preferences = getPreferences();
3291
- if (!preferences)
3292
- return handle.fail({}, { resolve, reject });
3293
- preferences.putSync(key, data);
3294
- preferences.flush();
3295
- return handle.success({}, { resolve, reject });
3296
- });
3440
+ return {
3441
+ isExist: true,
3442
+ };
3297
3443
  }
3298
- function setStorageSync(key, data) {
3299
- if (!key) {
3300
- throw new Error('setStorageSync:fail key error: key should be String');
3301
- }
3302
- const preferences = getPreferences();
3303
- if (!preferences) {
3304
- throw new Error('setStorageSync:fail:preferences is null');
3444
+ function getStorage(options) {
3445
+ const name = 'getStorage';
3446
+ const { isExist, error } = checkContextExist(name, true);
3447
+ if (!isExist) {
3448
+ return error;
3305
3449
  }
3306
- preferences.putSync(key, data);
3307
- preferences.flush();
3308
- }
3309
- function removeStorage(options) {
3310
3450
  const { key, success, fail, complete } = options || {};
3311
- const handle = new MethodHandler({ name: 'removeStorage', success, fail, complete });
3451
+ const handle = new MethodHandler({ name, success, fail, complete });
3312
3452
  return new Promise((resolve, reject) => {
3313
- try {
3314
- validateParams('removeStorage', options, storageSchema);
3315
- }
3316
- catch (error) {
3317
- const res = { errMsg: error.message };
3318
- return handle.fail(res, { resolve, reject });
3319
- }
3320
- const preferences = getPreferences();
3321
- if (!preferences)
3322
- return handle.fail({}, { resolve, reject });
3323
- preferences.deleteSync(key);
3324
- preferences.flush();
3325
- return handle.success({}, { resolve, reject });
3453
+ kvStorePromise.then(() => {
3454
+ try {
3455
+ validateParams(name, options, storageSchema);
3456
+ }
3457
+ catch (error) {
3458
+ const res = { errMsg: error.message };
3459
+ return handle.fail(res, { resolve, reject });
3460
+ }
3461
+ kvStore = kvStore;
3462
+ kvStore.get(key, (err, data) => {
3463
+ if (err) {
3464
+ handle.fail({ errMsg: `Failed to get data. Code:${err.code},message:${err.message}` }, { resolve, reject });
3465
+ return;
3466
+ }
3467
+ handle.success({ data }, { resolve, reject });
3468
+ });
3469
+ });
3326
3470
  });
3327
3471
  }
3328
- function removeStorageSync(key) {
3329
- if (!key) {
3330
- throw new Error('removeStorageSync:fail key error: key should be String');
3331
- }
3332
- const preferences = getPreferences();
3333
- if (!preferences) {
3334
- throw new Error('removeStorageSync:fail:preferences is null');
3472
+ function setStorage(options) {
3473
+ const name = 'setStorage';
3474
+ const { isExist, error } = checkContextExist(name, true);
3475
+ if (!isExist) {
3476
+ return error;
3335
3477
  }
3336
- preferences.deleteSync(key);
3337
- preferences.flush();
3338
- }
3339
- function clearStorage(options) {
3340
- const { success, fail, complete } = options || {};
3341
- const handle = new MethodHandler({ name: 'clearStorage', success, fail, complete });
3478
+ const { key, data, success, fail, complete } = options || {};
3479
+ const handle = new MethodHandler({ name, success, fail, complete });
3342
3480
  return new Promise((resolve, reject) => {
3343
- const preferences = getPreferences();
3344
- if (!preferences)
3345
- return handle.fail({}, { resolve, reject });
3346
- preferences.clearSync();
3347
- preferences.flush();
3348
- return handle.success({}, { resolve, reject });
3481
+ kvStorePromise.then(() => {
3482
+ try {
3483
+ validateParams(name, options, storageSchema);
3484
+ }
3485
+ catch (error) {
3486
+ const res = { errMsg: error.message };
3487
+ return handle.fail(res, { resolve, reject });
3488
+ }
3489
+ kvStore = kvStore;
3490
+ kvStore.put(key, data, (err) => {
3491
+ if (err) {
3492
+ handle.fail({ errMsg: `Failed to put data. Code:${err.code},message:${err.message}` }, { resolve, reject });
3493
+ return;
3494
+ }
3495
+ handle.success({}, { resolve, reject });
3496
+ });
3497
+ });
3349
3498
  });
3350
3499
  }
3351
- function clearStorageSync() {
3352
- const preferences = getPreferences();
3353
- if (!preferences) {
3354
- throw new Error('clearStorageSync:fail:preferences is null');
3500
+ function removeStorage(options) {
3501
+ const name = 'removeStorage';
3502
+ const { isExist, error } = checkContextExist(name, true);
3503
+ if (!isExist) {
3504
+ return error;
3355
3505
  }
3356
- preferences.clearSync();
3357
- preferences.flush();
3506
+ const { key, success, fail, complete } = options || {};
3507
+ const handle = new MethodHandler({ name, success, fail, complete });
3508
+ return new Promise((resolve, reject) => {
3509
+ kvStorePromise.then(() => {
3510
+ try {
3511
+ validateParams(name, options, storageSchema);
3512
+ }
3513
+ catch (error) {
3514
+ const res = { errMsg: error.message };
3515
+ return handle.fail(res, { resolve, reject });
3516
+ }
3517
+ kvStore = kvStore;
3518
+ kvStore.delete(key, (err) => {
3519
+ if (err) {
3520
+ handle.fail({ errMsg: `Failed to delete data. Code:${err.code},message:${err.message}` }, { resolve, reject });
3521
+ return;
3522
+ }
3523
+ handle.success({}, { resolve, reject });
3524
+ });
3525
+ });
3526
+ });
3358
3527
  }
3359
3528
  const getStorageInfoSync = temporarilyNotSupport('getStorageInfoSync');
3360
3529
  const getStorageInfo = temporarilyNotSupport('getStorageInfo');
@@ -3364,6 +3533,11 @@ const batchSetStorageSync = /* @__PURE__ */ temporarilyNotSupport('batchSetStora
3364
3533
  const batchSetStorage = /* @__PURE__ */ temporarilyNotSupport('batchSetStorage');
3365
3534
  const batchGetStorageSync = /* @__PURE__ */ temporarilyNotSupport('batchGetStorageSync');
3366
3535
  const batchGetStorage = /* @__PURE__ */ temporarilyNotSupport('batchGetStorage');
3536
+ const clearStorage = temporarilyNotSupport('clearStorage');
3537
+ const getStorageSync = temporarilyNotSupport('getStorageSync', 'getStorage');
3538
+ const setStorageSync = temporarilyNotSupport('setStorageSync', 'setStorage');
3539
+ const clearStorageSync = temporarilyNotSupport('clearStorageSync', 'clearStorage');
3540
+ const removeStorageSync = temporarilyNotSupport('removeStorageSync', 'removeStorage');
3367
3541
 
3368
3542
  class Animation {
3369
3543
  constructor({ duration = 400, delay = 0, timingFunction = 'linear', transformOrigin = '50% 50% 0', unit = 'px' } = {}) {
@@ -3396,6 +3570,9 @@ class Animation {
3396
3570
  transformOrigin,
3397
3571
  rule: Object.assign({}, this.rule)
3398
3572
  });
3573
+ if (this.rule.transform) {
3574
+ this.rule.transform = Object.assign({}, this.rule.transform);
3575
+ }
3399
3576
  return this;
3400
3577
  }
3401
3578
  matrix(a, b, c, d, tx, ty) {
@@ -3407,75 +3584,120 @@ class Animation {
3407
3584
  return this;
3408
3585
  }
3409
3586
  rotate(angle) {
3410
- this.rule.rotate = { x: 0, y: 0, z: 1, angle };
3587
+ if (!this.rule.transform) {
3588
+ this.rule.transform = {};
3589
+ }
3590
+ this.rule.transform.Rotate = { x: 0, y: 0, z: 1, angle };
3411
3591
  return this;
3412
3592
  }
3413
3593
  rotate3d(x, y, z, angle) {
3414
- this.rule.rotate = { x, y, z, angle };
3594
+ if (!this.rule.transform) {
3595
+ this.rule.transform = {};
3596
+ }
3597
+ this.rule.transform.Rotate = { x, y, z, angle };
3415
3598
  return this;
3416
3599
  }
3417
3600
  rotateX(angle) {
3418
- this.rule.rotate = { x: 1, y: 0, z: 0, angle };
3601
+ if (!this.rule.transform) {
3602
+ this.rule.transform = {};
3603
+ }
3604
+ this.rule.transform.Rotate = { x: 1, y: 0, z: 0, angle };
3419
3605
  return this;
3420
3606
  }
3421
3607
  rotateY(angle) {
3422
- this.rule.rotate = { x: 0, y: 1, z: 0, angle };
3608
+ if (!this.rule.transform) {
3609
+ this.rule.transform = {};
3610
+ }
3611
+ this.rule.transform.Rotate = { x: 0, y: 1, z: 0, angle };
3423
3612
  return this;
3424
3613
  }
3425
3614
  rotateZ(angle) {
3426
- this.rule.rotate = { x: 0, y: 0, z: 1, angle };
3615
+ if (!this.rule.transform) {
3616
+ this.rule.transform = {};
3617
+ }
3618
+ this.rule.transform.Rotate = { x: 0, y: 0, z: 1, angle };
3427
3619
  return this;
3428
3620
  }
3429
3621
  scale(sx, sy) {
3430
- this.rule.scale = { x: sx, y: sy };
3622
+ if (!this.rule.transform) {
3623
+ this.rule.transform = {};
3624
+ }
3625
+ this.rule.transform.Scale = { x: sx, y: isUndefined(sy) ? sx : sy };
3431
3626
  return this;
3432
3627
  }
3433
3628
  scale3d(sx, sy, sz) {
3434
- this.rule.scale = { x: sx, y: sy, z: sz };
3629
+ if (!this.rule.transform) {
3630
+ this.rule.transform = {};
3631
+ }
3632
+ this.rule.transform.Scale = { x: sx, y: sy, z: sz };
3435
3633
  return this;
3436
3634
  }
3437
3635
  scaleX(scale) {
3438
- this.rule.scale = { x: scale };
3636
+ if (!this.rule.transform) {
3637
+ this.rule.transform = {};
3638
+ }
3639
+ this.rule.transform.Scale = { x: scale };
3439
3640
  return this;
3440
3641
  }
3441
3642
  scaleY(scale) {
3442
- this.rule.scale = { y: scale };
3643
+ if (!this.rule.transform) {
3644
+ this.rule.transform = {};
3645
+ }
3646
+ this.rule.transform.Scale = { y: scale };
3443
3647
  return this;
3444
3648
  }
3445
3649
  scaleZ(scale) {
3446
- this.rule.scale = { z: scale };
3650
+ if (!this.rule.transform) {
3651
+ this.rule.transform = {};
3652
+ }
3653
+ this.rule.transform.Scale = { z: scale };
3447
3654
  return this;
3448
3655
  }
3449
3656
  skew(ax, ay) {
3450
- this.rule.skew = { x: ax, y: ay };
3657
+ temporarilyNotSupport('animation.skew:' + `${ax}, ${ay}`)(ax, ay);
3451
3658
  return this;
3452
3659
  }
3453
3660
  skewX(angle) {
3454
- this.rule.skew = { x: angle };
3661
+ temporarilyNotSupport('animation.skewX:' + angle)(angle);
3455
3662
  return this;
3456
3663
  }
3457
3664
  skewY(angle) {
3458
- this.rule.skew = { y: angle };
3665
+ temporarilyNotSupport('animation.skewY:' + angle)(angle);
3459
3666
  return this;
3460
3667
  }
3461
3668
  translate(tx, ty) {
3462
- this.rule.translate = { x: tx, y: ty };
3669
+ if (!this.rule.transform) {
3670
+ this.rule.transform = {};
3671
+ }
3672
+ this.rule.transform.Translate = { x: tx, y: ty };
3463
3673
  return this;
3464
3674
  }
3465
3675
  translate3d(tx, ty, tz) {
3466
- this.rule.translate = { x: tx, y: ty, z: tz };
3676
+ if (!this.rule.transform) {
3677
+ this.rule.transform = {};
3678
+ }
3679
+ this.rule.transform.Translate = { x: tx, y: ty, z: tz };
3467
3680
  return this;
3468
3681
  }
3469
3682
  translateX(translation) {
3470
- this.rule.translate = { x: translation };
3683
+ if (!this.rule.transform) {
3684
+ this.rule.transform = {};
3685
+ }
3686
+ this.rule.transform.Translate = { x: translation };
3471
3687
  return this;
3472
3688
  }
3473
3689
  translateY(translation) {
3474
- this.rule.translate = { y: translation };
3690
+ if (!this.rule.transform) {
3691
+ this.rule.transform = {};
3692
+ }
3693
+ this.rule.transform.Translate = { y: translation };
3475
3694
  return this;
3476
3695
  }
3477
3696
  translateZ(translation) {
3478
- this.rule.translate = { z: translation };
3697
+ if (!this.rule.transform) {
3698
+ this.rule.transform = {};
3699
+ }
3700
+ this.rule.transform.Translate = { z: translation };
3479
3701
  return this;
3480
3702
  }
3481
3703
  opacity(value) {
@@ -3487,15 +3709,15 @@ class Animation {
3487
3709
  return this;
3488
3710
  }
3489
3711
  width(value) {
3490
- this.rule.size = Object.assign(Object.assign({}, this.rule.size), { width: value });
3712
+ this.rule.width = value;
3491
3713
  return this;
3492
3714
  }
3493
3715
  height(value) {
3494
- this.rule.size = Object.assign(Object.assign({}, this.rule.size), { height: value });
3716
+ this.rule.height = value;
3495
3717
  return this;
3496
3718
  }
3497
3719
  left(value) {
3498
- temporarilyNotSupport('animation.left:' + value)(value);
3720
+ this.rule.left = value;
3499
3721
  return this;
3500
3722
  }
3501
3723
  right(value) {
@@ -3503,7 +3725,7 @@ class Animation {
3503
3725
  return this;
3504
3726
  }
3505
3727
  top(value) {
3506
- temporarilyNotSupport('animation.top:' + value)(value);
3728
+ this.rule.top = value;
3507
3729
  return this;
3508
3730
  }
3509
3731
  bottom(value) {
@@ -3522,7 +3744,8 @@ function setBackgroundColor(options) {
3522
3744
  const handle = new MethodHandler({ name: 'setBackgroundColor', success, fail, complete });
3523
3745
  return new Promise((resolve, reject) => {
3524
3746
  eventCenter.trigger('__taroPageStyle', {
3525
- backgroundColor: options.backgroundColor || options.backgroundColorTop || options.backgroundColorBottom,
3747
+ backgroundColor: options.backgroundColorBottom || options.backgroundColor,
3748
+ backgroundColorContext: options.backgroundColorTop || options.backgroundColor
3526
3749
  });
3527
3750
  return handle.success({}, { resolve, reject });
3528
3751
  });
@@ -3538,6 +3761,7 @@ const nextTick = (cb, ctx) => {
3538
3761
  // 字体
3539
3762
  const loadFontFace = /* @__PURE__ */ temporarilyNotSupport('getMenuButtonBoundingClientRect');
3540
3763
 
3764
+ // @ts-ignore
3541
3765
  const resCallback = (res) => {
3542
3766
  return { errMsg: `${res}:ok` };
3543
3767
  };
@@ -3548,6 +3772,7 @@ const showToastSchema = {
3548
3772
  };
3549
3773
  function showToast(options) {
3550
3774
  return new Promise((resolve, reject) => {
3775
+ var _a, _b;
3551
3776
  const _default = {
3552
3777
  title: '',
3553
3778
  duration: 1500,
@@ -3561,10 +3786,15 @@ function showToast(options) {
3561
3786
  const res = { errMsg: error.message };
3562
3787
  return callAsyncFail(reject, res, options);
3563
3788
  }
3564
- prompt.showToast({
3789
+ // @ts-ignore
3790
+ const uiContext = (_b = (_a = Current === null || Current === void 0 ? void 0 : Current.page) === null || _a === void 0 ? void 0 : _a.getUIContext) === null || _b === void 0 ? void 0 : _b.call(_a);
3791
+ if (!uiContext)
3792
+ return;
3793
+ uiContext.getPromptAction().showToast({
3565
3794
  message: options.title,
3566
3795
  duration: options.duration,
3567
- bottom: options.bottom
3796
+ bottom: options.bottom,
3797
+ showMode: 1 // 设置弹窗显示模式,显示在应用之上。
3568
3798
  });
3569
3799
  callAsyncSuccess(resolve, resCallback('showToast'), options);
3570
3800
  });
@@ -3594,25 +3824,29 @@ function showModal(options) {
3594
3824
  color: confirmColor
3595
3825
  });
3596
3826
  }
3597
- return new Promise(resolve => {
3827
+ return new Promise((resolve, reject) => {
3828
+ var _a, _b;
3598
3829
  const modalOptions = {
3599
3830
  title,
3600
3831
  message: content,
3601
3832
  buttons: buttons,
3602
- success: (data) => {
3603
- if (data.index === 1 || !showCancel) {
3604
- callAsyncSuccess(resolve, Object.assign(Object.assign({}, resCallback('showModal')), { confirm: true, cancel: false, content: null }), options);
3605
- }
3606
- else {
3607
- callAsyncSuccess(resolve, Object.assign(Object.assign({}, resCallback('showModal')), { confirm: false, cancel: true }), options);
3608
- }
3609
- },
3610
- // 鸿蒙没有失败方法,只有取消
3611
- cancel: (_) => {
3833
+ };
3834
+ // @ts-ignore
3835
+ const uiContext = (_b = (_a = Current === null || Current === void 0 ? void 0 : Current.page) === null || _a === void 0 ? void 0 : _a.getUIContext) === null || _b === void 0 ? void 0 : _b.call(_a);
3836
+ if (!uiContext)
3837
+ return;
3838
+ uiContext.getPromptAction().showDialog(modalOptions, (error, data) => {
3839
+ if (error) {
3840
+ const res = { errMsg: error };
3841
+ callAsyncFail(reject, res, options);
3842
+ }
3843
+ if (data.index === 0 && showCancel) {
3612
3844
  callAsyncSuccess(resolve, Object.assign(Object.assign({}, resCallback('showModal')), { confirm: false, cancel: true }), options);
3613
3845
  }
3614
- };
3615
- prompt.showDialog(modalOptions);
3846
+ else {
3847
+ callAsyncSuccess(resolve, Object.assign(Object.assign({}, resCallback('showModal')), { confirm: true, cancel: false, content: null }), options);
3848
+ }
3849
+ });
3616
3850
  });
3617
3851
  }
3618
3852
  const showActionSheetSchema = {
@@ -3621,6 +3855,7 @@ const showActionSheetSchema = {
3621
3855
  };
3622
3856
  function showActionSheet(options) {
3623
3857
  return new Promise((resolve, reject) => {
3858
+ var _a, _b;
3624
3859
  const _default = {
3625
3860
  title: '',
3626
3861
  itemList: [],
@@ -3643,28 +3878,22 @@ function showActionSheet(options) {
3643
3878
  });
3644
3879
  const actionSheetOptions = {
3645
3880
  title,
3646
- buttons,
3647
- success: (data) => {
3648
- callAsyncSuccess(resolve, Object.assign(Object.assign({}, data), resCallback('showActionSheet')), options);
3649
- },
3650
- // 取消方法,并非失败
3651
- fail: (data) => {
3652
- callAsyncFail(reject, Object.assign(Object.assign({}, data), { errMsg: data.errMsg.replace('showActionMenu', 'showActionSheet') }), options);
3653
- }
3881
+ buttons
3654
3882
  };
3655
- prompt.showActionMenu(actionSheetOptions);
3656
- });
3657
- }
3658
- function hideToast(options) {
3659
- return new Promise(resolve => {
3660
- prompt.showToast({
3661
- message: '关闭中',
3662
- duration: 10,
3663
- bottom: '9999px'
3883
+ // @ts-ignore
3884
+ const uiContext = (_b = (_a = Current === null || Current === void 0 ? void 0 : Current.page) === null || _a === void 0 ? void 0 : _a.getUIContext) === null || _b === void 0 ? void 0 : _b.call(_a);
3885
+ if (!uiContext)
3886
+ return;
3887
+ uiContext.getPromptAction().showActionMenu(actionSheetOptions, (error, data) => {
3888
+ var _a;
3889
+ if (error) {
3890
+ callAsyncFail(reject, Object.assign(Object.assign({}, data), { errMsg: (_a = data.errMsg) === null || _a === void 0 ? void 0 : _a.replace('showActionMenu', 'showActionSheet') }), options);
3891
+ }
3892
+ callAsyncSuccess(resolve, Object.assign(Object.assign({}, data), resCallback('showActionSheet')), options);
3664
3893
  });
3665
- callAsyncSuccess(resolve, resCallback('hideToast'), options);
3666
3894
  });
3667
3895
  }
3896
+ const hideToast = /* @__PURE__ */ temporarilyNotSupport('hideToast');
3668
3897
  const showLoading = temporarilyNotSupport('showLoading');
3669
3898
  const hideLoading = temporarilyNotSupport('hideLoading');
3670
3899
  const enableAlertBeforeUnload = /* @__PURE__ */ temporarilyNotSupport('enableAlertBeforeUnload');
@@ -3685,7 +3914,7 @@ const setNavigationBarTitle = function (options) {
3685
3914
  };
3686
3915
  const setNavigationBarColor = function (options) {
3687
3916
  const { success, fail, complete } = options || {};
3688
- const handle = new MethodHandler({ name: 'setNavigationBarTitle', success, fail, complete });
3917
+ const handle = new MethodHandler({ name: 'setNavigationBarColor', success, fail, complete });
3689
3918
  return new Promise((resolve, reject) => {
3690
3919
  eventCenter.trigger('__taroNavigationStyle', {
3691
3920
  animation: options.animation,
@@ -3727,10 +3956,13 @@ const hideHomeButton = function (options) {
3727
3956
  };
3728
3957
 
3729
3958
  const startPullDownRefresh = function (options) {
3730
- return new Promise(resolve => {
3959
+ return new Promise((resolve, reject) => {
3731
3960
  var _a;
3732
3961
  const taro = Current.taro;
3733
3962
  const page = taro.getCurrentInstance().page;
3963
+ if (!page) {
3964
+ return callAsyncFail(reject, { errMsg: 'stopPullDownRefresh:fail' }, options);
3965
+ }
3734
3966
  if (page.isRefreshing instanceof Array) {
3735
3967
  const index = page.tabBarCurrentIndex || 0;
3736
3968
  page.isRefreshing[index] = true;
@@ -3744,10 +3976,13 @@ const startPullDownRefresh = function (options) {
3744
3976
  });
3745
3977
  };
3746
3978
  const stopPullDownRefresh = function (options) {
3747
- return new Promise(resolve => {
3979
+ return new Promise((resolve, reject) => {
3748
3980
  var _a;
3749
3981
  const taro = Current.taro;
3750
3982
  const page = taro.getCurrentInstance().page;
3983
+ if (!page) {
3984
+ return callAsyncFail(reject, { errMsg: 'stopPullDownRefresh:fail' }, options);
3985
+ }
3751
3986
  if (page.isRefreshing instanceof Array) {
3752
3987
  const index = page.tabBarCurrentIndex || 0;
3753
3988
  page.isRefreshing[index] = false;
@@ -3780,8 +4015,8 @@ const pageScrollTo = (options) => {
3780
4015
  const taro = Current.taro;
3781
4016
  const page = taro.getCurrentInstance().page;
3782
4017
  let scrollValue = -1;
3783
- let scroller = page.scroller;
3784
- const currentPageNode = getPageScrollerOrNode(page.node, page);
4018
+ let scroller = getPageScrollerOrNode(page === null || page === void 0 ? void 0 : page.scroller, page);
4019
+ const currentPageNode = getPageScrollerOrNode(page === null || page === void 0 ? void 0 : page.node, page);
3785
4020
  if (scrollTop || typeof scrollTop === 'number') {
3786
4021
  scrollValue = scrollTop;
3787
4022
  }
@@ -3806,12 +4041,12 @@ const pageScrollTo = (options) => {
3806
4041
  scrollValue = areaInfo.globalPosition.y + yOffset + pxTransformHelper(offsetTop, 'px', true);
3807
4042
  }
3808
4043
  }
3809
- const { xOffset } = scroller.currentOffset();
3810
- if (scrollValue === -1) {
4044
+ if (!scroller || scrollValue === -1) {
3811
4045
  return handle.fail({
3812
4046
  errMsg: '请检查传入的 scrollTop 或 selector 是否合法'
3813
4047
  }, { resolve, reject });
3814
4048
  }
4049
+ const { xOffset } = scroller.currentOffset();
3815
4050
  try {
3816
4051
  scroller.scrollTo({
3817
4052
  xOffset,
@@ -3843,7 +4078,7 @@ const toggleTabBar = function (type) {
3843
4078
  var _a, _b;
3844
4079
  const taro = Current.taro;
3845
4080
  const page = taro.getCurrentInstance().page;
3846
- const currentData = ((_a = page._data) === null || _a === void 0 ? void 0 : _a.taroTabBar) || page.tabBar;
4081
+ const currentData = ((_a = page === null || page === void 0 ? void 0 : page._data) === null || _a === void 0 ? void 0 : _a.taroTabBar) || (page === null || page === void 0 ? void 0 : page.tabBar);
3847
4082
  const res = { errMsg: `${type}TabBar:ok` };
3848
4083
  const error = { errMsg: `${type}TabBar:fail not TabBar page` };
3849
4084
  if (!currentData) {
@@ -3868,7 +4103,7 @@ const setTabBarStyle = function (options = {}) {
3868
4103
  var _a, _b;
3869
4104
  const taro = Current.taro;
3870
4105
  const page = taro.getCurrentInstance().page;
3871
- const currentData = ((_a = page._data) === null || _a === void 0 ? void 0 : _a.taroTabBar) || page.tabBar;
4106
+ const currentData = ((_a = page === null || page === void 0 ? void 0 : page._data) === null || _a === void 0 ? void 0 : _a.taroTabBar) || (page === null || page === void 0 ? void 0 : page.tabBar);
3872
4107
  const res = { errMsg: 'setTabBarStyle:ok' };
3873
4108
  const error = { errMsg: 'setTabBarStyle:fail not TabBar page' };
3874
4109
  if (!currentData) {
@@ -3895,7 +4130,7 @@ const setTabBarItem = function (options) {
3895
4130
  var _a, _b;
3896
4131
  const taro = Current.taro;
3897
4132
  const page = taro.getCurrentInstance().page;
3898
- const currentData = ((_a = page._data) === null || _a === void 0 ? void 0 : _a.taroTabBar) || page.tabBar;
4133
+ const currentData = ((_a = page === null || page === void 0 ? void 0 : page._data) === null || _a === void 0 ? void 0 : _a.taroTabBar) || (page === null || page === void 0 ? void 0 : page.tabBar);
3899
4134
  const res = { errMsg: 'setTabBarItem:ok' };
3900
4135
  const error = { errMsg: 'setTabBarItem:fail not TabBar page' };
3901
4136
  if (!currentData) {
@@ -3988,19 +4223,16 @@ class IntersectionObserver {
3988
4223
  };
3989
4224
  const taro = Current.taro;
3990
4225
  const page = taro.getCurrentInstance().page;
3991
- const currentPage = getPageScrollerOrNode(page.node, page);
3992
- this._component = component || currentPage;
4226
+ this._component = component || getPageScrollerOrNode(page === null || page === void 0 ? void 0 : page.node, page);
3993
4227
  Object.assign(this._options, options);
3994
4228
  }
3995
4229
  disconnect() {
3996
- var _a;
3997
- if (this._observerNodes) {
4230
+ if (this._observerNodes && this._component) {
3998
4231
  if (this._observerNodes instanceof Array) {
3999
4232
  this._observerNodes.forEach((n) => {
4000
- var _a;
4001
4233
  disconnectEvent(n, VISIBLE_CHANGE_EVENT_NAME);
4002
4234
  // @ts-ignore
4003
- (_a = n._nodeInfo) === null || _a === void 0 ? void 0 : _a.thresholds = null;
4235
+ n._nodeInfo.thresholds = null;
4004
4236
  });
4005
4237
  }
4006
4238
  else {
@@ -4008,35 +4240,40 @@ class IntersectionObserver {
4008
4240
  // @ts-ignore
4009
4241
  if (this._observerNodes._nodeInfo) {
4010
4242
  // @ts-ignore
4011
- (_a = this._observerNodes._nodeInfo) === null || _a === void 0 ? void 0 : _a.thresholds = null;
4243
+ this._observerNodes._nodeInfo.thresholds = null;
4012
4244
  }
4013
4245
  }
4014
4246
  }
4015
4247
  }
4016
4248
  observe(targetSelector, callback) {
4017
- var _a;
4249
+ if (!this._component)
4250
+ return;
4018
4251
  const { observeAll, thresholds } = this._options;
4019
4252
  const node = findChildNodeWithDFS(this._component, targetSelector, observeAll);
4020
4253
  this._observerNodes = node;
4021
4254
  if (node) {
4022
4255
  if (node instanceof Array) {
4023
4256
  node.forEach(n => {
4024
- var _a;
4025
4257
  // @ts-ignore
4026
- (_a = n._nodeInfo) === null || _a === void 0 ? void 0 : _a.thresholds = thresholds;
4258
+ n._nodeInfo.thresholds = thresholds;
4027
4259
  setNodeEventCallbackAndTriggerComponentUpdate(n, VISIBLE_CHANGE_EVENT_NAME, (isVisible, currentRatio) => {
4028
- callback(this.handleResult(isVisible, currentRatio));
4260
+ callback(this.handleResult(isVisible, currentRatio, n));
4029
4261
  });
4030
4262
  });
4031
4263
  }
4032
4264
  else {
4033
4265
  // @ts-ignore
4034
- (_a = node._nodeInfo) === null || _a === void 0 ? void 0 : _a.thresholds = thresholds;
4266
+ node._nodeInfo.thresholds = thresholds;
4035
4267
  setNodeEventCallbackAndTriggerComponentUpdate(node, VISIBLE_CHANGE_EVENT_NAME, (isVisible, currentRatio) => {
4036
- callback(this.handleResult(isVisible, currentRatio));
4268
+ callback(this.handleResult(isVisible, currentRatio, node));
4037
4269
  });
4038
4270
  }
4039
4271
  }
4272
+ else {
4273
+ callback({
4274
+ errMsg: 'IntersectionObserver.observe:fail cannot find the node for selector.'
4275
+ });
4276
+ }
4040
4277
  }
4041
4278
  relativeTo() {
4042
4279
  temporarilyNotSupport('relativeTo')();
@@ -4047,8 +4284,10 @@ class IntersectionObserver {
4047
4284
  return this;
4048
4285
  }
4049
4286
  // @ts-ignore
4050
- handleResult(isVisible, currentRatio) {
4287
+ handleResult(isVisible, currentRatio, node) {
4051
4288
  const result = {
4289
+ id: node.id,
4290
+ dataset: node.dataset,
4052
4291
  intersectionRatio: currentRatio,
4053
4292
  // TODO 未做,等待能拿到element的info信息
4054
4293
  boundingClientRect: {
@@ -4256,32 +4495,45 @@ function filter(fields, dom) {
4256
4495
  }
4257
4496
  function querySelector(selector, selectAll) {
4258
4497
  if (typeof selector === 'string') {
4259
- return parseHandler(selector, selectAll);
4498
+ return selector.split(',').reduce((prev, current) => {
4499
+ const item = current.trim();
4500
+ return prev.concat(parseHandler(item, selectAll));
4501
+ }, []);
4260
4502
  }
4261
- return null;
4503
+ return [];
4262
4504
  }
4263
4505
  function queryBat(queue, cb) {
4264
4506
  const result = [];
4265
4507
  const taro = Current.taro;
4266
4508
  const page = taro.getCurrentInstance().page;
4267
- const element = getPageScrollerOrNode(page.node, page);
4268
- if (element == null)
4509
+ const element = getPageScrollerOrNode(page === null || page === void 0 ? void 0 : page.node, page);
4510
+ if (!element)
4269
4511
  return null;
4270
4512
  arr = [];
4271
4513
  traversalDFSDom(element);
4272
- queue.forEach(item => {
4514
+ queue.forEach((item) => {
4273
4515
  const { selector, single, fields } = item;
4274
- const nodeList = querySelector(selector, !single);
4275
- result.push(nodeList.map(dom => {
4516
+ if (single) {
4517
+ const dom = querySelector(selector, !single)[0];
4276
4518
  // eslint-disable-next-line no-async-promise-executor
4277
- return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
4519
+ result.push(new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
4278
4520
  yield setNodeEventCallbackAndTriggerComponentUpdate(dom, AREA_CHANGE_EVENT_NAME, null, true);
4279
4521
  resolve(filter(fields, dom));
4522
+ })));
4523
+ }
4524
+ else {
4525
+ const nodeList = querySelector(selector, !single);
4526
+ result.push(nodeList.map(dom => {
4527
+ // eslint-disable-next-line no-async-promise-executor
4528
+ return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
4529
+ yield setNodeEventCallbackAndTriggerComponentUpdate(dom, AREA_CHANGE_EVENT_NAME, null, true);
4530
+ resolve(filter(fields, dom));
4531
+ }));
4280
4532
  }));
4281
- }));
4533
+ }
4282
4534
  });
4283
4535
  Promise.all(result.map(item => {
4284
- return Promise.all(item);
4536
+ return item instanceof Array ? Promise.all(item) : item;
4285
4537
  })).then(data => {
4286
4538
  cb(data);
4287
4539
  });
@@ -4774,7 +5026,7 @@ const defaultBaseFontSize = 20;
4774
5026
  const defaultUnitPrecision = 5;
4775
5027
  const defaultTargetUnit = 'vp';
4776
5028
  function getApp$1() {
4777
- return Current.app;
5029
+ return Current.app || {};
4778
5030
  }
4779
5031
  function initPxTransform({ designWidth = defaultDesignWidth, deviceRatio = defaultDesignRatio, baseFontSize = defaultBaseFontSize, unitPrecision = defaultUnitPrecision, targetUnit = defaultTargetUnit }) {
4780
5032
  const taro = Current.taro;
@@ -4788,19 +5040,56 @@ function initPxTransform({ designWidth = defaultDesignWidth, deviceRatio = defau
4788
5040
  config.unitPrecision = unitPrecision;
4789
5041
  }
4790
5042
  }
4791
- _display.getDefaultDisplaySync();
5043
+ const display = _display.getDefaultDisplaySync();
5044
+ let displayWidth = display.width;
5045
+ let ratioCache = false;
5046
+ let designWidthFunc;
5047
+ let designWidth = defaultDesignWidth;
5048
+ function getRatio(value) {
5049
+ var _a;
5050
+ // Note: 提前调用 display 可能无法获取正确值
5051
+ if (ratioCache === false || displayWidth !== display.width) {
5052
+ const config = ((_a = Current.taro) === null || _a === void 0 ? void 0 : _a.config) || {};
5053
+ if (!isFunction(designWidthFunc)) {
5054
+ designWidthFunc = isFunction(config.designWidth)
5055
+ ? config.designWidth
5056
+ : () => config.designWidth;
5057
+ designWidth = designWidthFunc(value) || defaultDesignWidth;
5058
+ }
5059
+ displayWidth = display.width;
5060
+ ratioCache = Math.min(display.width, display.height) / designWidth;
5061
+ }
5062
+ return ratioCache;
5063
+ }
5064
+ // Note: 设置为 style 单位时会自动完成设计稿转换,设计开发者调用 API 时也许抹平差异,例如 pageScrollTo[option.offsetTop]
5065
+ function pxTransformHelper(size, unit, isNumber = false) {
5066
+ var _a;
5067
+ const config = ((_a = Current.taro) === null || _a === void 0 ? void 0 : _a.config) || {};
5068
+ const targetUnit = unit || config.targetUnit || defaultTargetUnit;
5069
+ if (targetUnit === 'PX') {
5070
+ return px2vp(size * display.scaledDensity) + 'vp';
5071
+ }
5072
+ const ratio = getRatio(size);
5073
+ let val = size * ratio;
5074
+ switch (targetUnit) {
5075
+ case 'vp':
5076
+ // Note: 在应用创建前调用无效
5077
+ val = px2vp(val);
5078
+ break;
5079
+ }
5080
+ return isNumber ? val : val + targetUnit;
5081
+ }
4792
5082
  function pxTransform(size) {
4793
5083
  var _a;
4794
5084
  const config = ((_a = Current.taro) === null || _a === void 0 ? void 0 : _a.config) || {};
4795
5085
  const targetUnit = config.targetUnit || defaultTargetUnit;
4796
- let val = size;
5086
+ const val = size;
4797
5087
  switch (targetUnit) {
4798
5088
  case 'vp':
4799
- val = px2vp(size);
4800
- break;
5089
+ return pxTransformHelper(size, 'px');
4801
5090
  // NOTE: 鸿蒙环境下 style 会自动完成设计稿转换,无需在方法内二次调整
4802
5091
  }
4803
- return val + config.targetUnit;
5092
+ return val + targetUnit;
4804
5093
  }
4805
5094
  function canIUseWebp() {
4806
5095
  return true;