@tarojs/plugin-platform-harmony-ets 4.0.0-alpha.3 → 4.0.0-alpha.31

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 (131) hide show
  1. package/dist/apis/base/system.ts +73 -20
  2. package/dist/apis/canvas/index.ts +10 -1
  3. package/dist/apis/device/clipboard.ts +16 -8
  4. package/dist/apis/framework/index.ts +1 -5
  5. package/dist/apis/index.ts +25 -17
  6. package/dist/apis/media/image/index.ts +207 -44
  7. package/dist/apis/storage/index.ts +146 -78
  8. package/dist/apis/ui/animation/animation.ts +71 -29
  9. package/dist/apis/ui/background.ts +2 -1
  10. package/dist/apis/ui/interaction/index.ts +42 -59
  11. package/dist/apis/ui/navigation-bar/index.ts +1 -1
  12. package/dist/apis/ui/pull-down-refresh.ts +9 -3
  13. package/dist/apis/ui/scroll/index.ts +5 -5
  14. package/dist/apis/ui/tab-bar.ts +3 -3
  15. package/dist/apis/utils/index.ts +20 -2
  16. package/dist/apis/utils/permissions.ts +6 -0
  17. package/dist/apis/wxml/IntersectionObserver.ts +18 -10
  18. package/dist/apis/wxml/selectorQuery.ts +26 -13
  19. package/dist/components-harmony-ets/button.ets +64 -34
  20. package/dist/components-harmony-ets/canvas.ets +51 -0
  21. package/dist/components-harmony-ets/checkbox.ets +73 -62
  22. package/dist/components-harmony-ets/form.ets +51 -29
  23. package/dist/components-harmony-ets/icon.ets +31 -19
  24. package/dist/components-harmony-ets/image.ets +34 -14
  25. package/dist/components-harmony-ets/index.ets +92 -0
  26. package/dist/components-harmony-ets/innerHtml.ets +11 -6
  27. package/dist/components-harmony-ets/input.ets +63 -41
  28. package/dist/components-harmony-ets/label.ets +71 -44
  29. package/dist/components-harmony-ets/listView.ets +31 -0
  30. package/dist/components-harmony-ets/movableArea.ets +126 -0
  31. package/dist/components-harmony-ets/movableView.ets +93 -0
  32. package/dist/components-harmony-ets/navigationBar.ets +65 -0
  33. package/dist/components-harmony-ets/pageMeta.ets +94 -0
  34. package/dist/components-harmony-ets/picker.ets +43 -39
  35. package/dist/components-harmony-ets/progress.ets +52 -0
  36. package/dist/components-harmony-ets/pseudo.ets +80 -0
  37. package/dist/components-harmony-ets/radio.ets +78 -68
  38. package/dist/components-harmony-ets/richText.ets +14 -30
  39. package/dist/components-harmony-ets/scrollList.ets +103 -0
  40. package/dist/components-harmony-ets/scrollView.ets +61 -57
  41. package/dist/components-harmony-ets/slider.ets +19 -15
  42. package/dist/components-harmony-ets/stickySection.ets +42 -0
  43. package/dist/components-harmony-ets/style.ets +386 -130
  44. package/dist/components-harmony-ets/swiper.ets +61 -20
  45. package/dist/components-harmony-ets/switch.ets +36 -32
  46. package/dist/components-harmony-ets/{index.ts → tag.ts} +6 -0
  47. package/dist/components-harmony-ets/text.ets +112 -50
  48. package/dist/components-harmony-ets/textArea.ets +50 -35
  49. package/dist/components-harmony-ets/utils/AttributeManager.ets +2 -2
  50. package/dist/components-harmony-ets/utils/DynamicCenter.ts +2 -2
  51. package/dist/components-harmony-ets/utils/flexManager.ets +49 -19
  52. package/dist/components-harmony-ets/utils/helper.ets +20 -8
  53. package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
  54. package/dist/components-harmony-ets/utils/htmlParser/index.ts +1 -1
  55. package/dist/components-harmony-ets/utils/index.ts +54 -50
  56. package/dist/components-harmony-ets/utils/styles.ets +172 -93
  57. package/dist/components-harmony-ets/video.ets +34 -21
  58. package/dist/components-harmony-ets/view.ets +63 -52
  59. package/dist/components-harmony-ets/webView.ets +40 -34
  60. package/dist/index.d.ts +152 -0
  61. package/dist/index.js +102 -56
  62. package/dist/index.js.map +1 -1
  63. package/dist/runtime-ets/bom/document.ts +6 -4
  64. package/dist/runtime-ets/bom/getComputedStyle.ts +2 -2
  65. package/dist/runtime-ets/bom/window.ts +7 -0
  66. package/dist/runtime-ets/current.ts +5 -1
  67. package/dist/runtime-ets/dom/bind.ts +28 -12
  68. package/dist/runtime-ets/dom/class-list.ts +2 -2
  69. package/dist/runtime-ets/dom/cssNesting.ts +419 -0
  70. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +28 -42
  71. package/dist/runtime-ets/dom/document.ts +8 -11
  72. package/dist/runtime-ets/dom/element/canvas.ts +136 -0
  73. package/dist/runtime-ets/dom/element/element.ts +376 -57
  74. package/dist/runtime-ets/dom/element/form.ts +31 -26
  75. package/dist/runtime-ets/dom/element/index.ts +30 -2
  76. package/dist/runtime-ets/dom/element/movableArea.ts +11 -0
  77. package/dist/runtime-ets/dom/element/movableView.ts +244 -0
  78. package/dist/runtime-ets/dom/element/normal.ts +35 -8
  79. package/dist/runtime-ets/dom/element/progress.ts +11 -0
  80. package/dist/runtime-ets/dom/element/scrollView.ts +1 -0
  81. package/dist/runtime-ets/dom/element/text.ts +1 -8
  82. package/dist/runtime-ets/dom/element/video.ts +5 -4
  83. package/dist/runtime-ets/dom/element/webView.ts +12 -5
  84. package/dist/runtime-ets/dom/event.ts +3 -5
  85. package/dist/runtime-ets/dom/eventTarget.ts +2 -3
  86. package/dist/runtime-ets/dom/node.ts +65 -32
  87. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +418 -237
  88. package/dist/runtime-ets/dom/stylesheet/index.ts +29 -311
  89. package/dist/runtime-ets/dom/stylesheet/type.ts +53 -11
  90. package/dist/runtime-ets/dom/stylesheet/util.ts +33 -27
  91. package/dist/runtime-ets/index.ts +2 -1
  92. package/dist/runtime-ets/interface/event.ts +1 -1
  93. package/dist/runtime-ets/utils/index.ts +74 -13
  94. package/dist/runtime-ets/utils/info.ts +2 -2
  95. package/dist/runtime-framework/react/app.ts +15 -10
  96. package/dist/runtime-framework/react/hooks.ts +0 -1
  97. package/dist/runtime-framework/react/index.ts +0 -2
  98. package/dist/runtime-framework/react/native-page.ts +185 -78
  99. package/dist/runtime-framework/react/page.ts +4 -9
  100. package/dist/runtime-framework/react/utils/index.ts +3 -3
  101. package/dist/runtime-framework/solid/app.ts +30 -46
  102. package/dist/runtime-framework/solid/connect.ts +21 -3
  103. package/dist/runtime-framework/solid/hooks.ts +16 -11
  104. package/dist/runtime-framework/solid/index.ts +6 -2
  105. package/dist/runtime-framework/solid/page.ts +85 -31
  106. package/dist/runtime-framework/solid/reconciler/props.ts +70 -25
  107. package/dist/runtime-framework/solid/reconciler/render.ts +16 -6
  108. package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
  109. package/dist/runtime-framework/solid/utils/index.ts +3 -5
  110. package/dist/runtime-utils.d.ts +827 -0
  111. package/dist/runtime-utils.js +652 -283
  112. package/dist/runtime-utils.js.map +1 -1
  113. package/dist/runtime.d.ts +1 -0
  114. package/dist/runtime.js +652 -283
  115. package/dist/runtime.js.map +1 -1
  116. package/index.js +3 -1
  117. package/package.json +14 -15
  118. package/static/media/cancel.svg +1 -1
  119. package/static/media/circle.svg +1 -1
  120. package/static/media/clear.svg +1 -1
  121. package/static/media/download.svg +1 -1
  122. package/static/media/info.svg +1 -1
  123. package/static/media/info_circle.svg +1 -1
  124. package/static/media/search.svg +1 -1
  125. package/static/media/success.svg +1 -1
  126. package/static/media/success_no_circle.svg +1 -1
  127. package/static/media/warn.svg +1 -1
  128. package/types/harmony.d.ts +5 -0
  129. package/types/index.d.ts +4 -0
  130. package/types/runtime.d.ts +1 -1
  131. /package/dist/runtime-framework/solid/{contant.ts → constant.ts} +0 -0
package/dist/runtime.js CHANGED
@@ -1,14 +1,16 @@
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 { Current, eventCenter, window, eventSource, hooks, document as document$1, getPageScrollerOrNode, findChildNodeWithDFS, setNodeEventCallbackAndTriggerComponentUpdate, AREA_CHANGE_EVENT_NAME, disconnectEvent, VISIBLE_CHANGE_EVENT_NAME, getCurrentInstance } from '@tarojs/runtime';
4
+ import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
5
+ import ConfigurationConstant from '@ohos.app.ability.ConfigurationConstant';
5
6
  import deviceInfo from '@ohos.deviceInfo';
6
7
  import i18n from '@ohos.i18n';
7
- import deviceMethod from '@system.device';
8
8
  import errorManager from '@ohos.app.ability.errorManager';
9
+ import { eventCenter as eventCenter$1, Events, History } from '@tarojs/runtime/dist/runtime.esm';
9
10
  import sensor from '@ohos.sensor';
10
11
  import batteryInfo, { BatteryChargeState } from '@ohos.batteryInfo';
11
12
  import pasteboard from '@ohos.pasteboard';
13
+ import promptAction from '@ohos.promptAction';
12
14
  import inputMethodEngine from '@ohos.inputMethodEngine';
13
15
  import network from '@system.network';
14
16
  import call from '@ohos.telephony.call';
@@ -21,6 +23,7 @@ import app from '@system.app';
21
23
  import file from '@system.file';
22
24
  import geoLocationManager from '@ohos.geoLocationManager';
23
25
  import mediaLibrary from '@ohos.multimedia.mediaLibrary';
26
+ import fs from '@ohos.file.fs';
24
27
  import picker from '@ohos.file.picker';
25
28
  import image from '@ohos.multimedia.image';
26
29
  import request$1 from '@ohos.request';
@@ -28,11 +31,9 @@ import http from '@ohos.net.http';
28
31
  import webSocket from '@ohos.net.webSocket';
29
32
  import router from '@ohos.router';
30
33
  import bundleManager from '@ohos.bundle.bundleManager';
31
- import dataPreferences from '@ohos.data.preferences';
32
- import hilog from '@ohos.hilog';
34
+ import distributedKVStore from '@ohos.data.distributedKVStore';
33
35
  import matrix4 from '@ohos.matrix4';
34
- import prompt from '@ohos.prompt';
35
- import { pxTransformHelper } from '@tarojs/taro';
36
+ import { pxTransformHelper as pxTransformHelper$1 } from '@tarojs/taro';
36
37
 
37
38
  class MethodHandler {
38
39
  constructor({ name, success, fail, complete }) {
@@ -175,6 +176,21 @@ const validateParams = function (name, params, schema) {
175
176
  }
176
177
  };
177
178
 
179
+ function requestPermissions(permissions) {
180
+ return new Promise((resolve, reject) => {
181
+ const context = getContext(Current === null || Current === void 0 ? void 0 : Current.page);
182
+ const atManager = abilityAccessCtrl.createAtManager();
183
+ atManager.requestPermissionsFromUser(context, permissions, (err, _) => {
184
+ if (err) {
185
+ // eslint-disable-next-line prefer-promise-reject-errors
186
+ reject(`[Taro] 请求用户授权 ${permissions.join('、')} 失败:${JSON.stringify(err)}`);
187
+ }
188
+ else {
189
+ resolve();
190
+ }
191
+ });
192
+ });
193
+ }
178
194
  function object2String(obj) {
179
195
  let str = '';
180
196
  for (const item in obj) {
@@ -186,7 +202,7 @@ function temporarilyNotSupport(name, recommended) {
186
202
  return (option = {}, ...args) => {
187
203
  const { success, fail, complete } = option;
188
204
  const handle = new MethodHandler({ name, success, fail, complete });
189
- let errMsg = '暂时不支持 API';
205
+ let errMsg = `暂时不支持 API ${name}`;
190
206
  if (recommended) {
191
207
  errMsg += `, 请使用 ${recommended}`;
192
208
  }
@@ -266,16 +282,63 @@ const preloadWebview = /* @__PURE__ */ temporarilyNotSupport('preloadWebview');
266
282
  const preloadSkylineView = /* @__PURE__ */ temporarilyNotSupport('preloadSkylineView');
267
283
  const preloadAssets = /* @__PURE__ */ temporarilyNotSupport('preloadAssets');
268
284
 
269
- // 设备信息,从 API Version 6 开始支持
270
- const display = _display.getDefaultDisplaySync();
271
- let device;
272
- deviceMethod.getInfo({
273
- success: data => {
274
- device = data;
275
- }
285
+ let display$1;
286
+ let navigationIndicatorRect;
287
+ let safeArea = null;
288
+ let statusBarHeight;
289
+ let windowRect;
290
+ Current.contextPromise.then((context) => {
291
+ const win = window.__ohos.getLastWindow(context);
292
+ win.then(mainWindow => {
293
+ const topRect = mainWindow.getWindowAvoidArea(window.__ohos.AvoidAreaType.TYPE_SYSTEM).topRect;
294
+ navigationIndicatorRect = mainWindow.getWindowAvoidArea(window.__ohos.AvoidAreaType.TYPE_NAVIGATION_INDICATOR).bottomRect;
295
+ statusBarHeight = topRect.top + topRect.height;
296
+ windowRect = mainWindow.getWindowProperties().windowRect;
297
+ try {
298
+ display$1 = _display.getDefaultDisplaySync();
299
+ setSafeArea({
300
+ top: statusBarHeight,
301
+ left: 0,
302
+ right: display$1.width,
303
+ bottom: navigationIndicatorRect === null || navigationIndicatorRect === void 0 ? void 0 : navigationIndicatorRect.top
304
+ });
305
+ // @ts-ignore
306
+ display$1.getCutoutInfo((err, { boundingRects = [], waterfallDisplayAreaRects = {} } = {}) => {
307
+ var _a, _b, _c, _d, _e, _f;
308
+ if (err === null || err === void 0 ? void 0 : err.code) {
309
+ console.error('Failed to get cutout info', JSON.stringify(err));
310
+ return;
311
+ }
312
+ 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);
313
+ 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);
314
+ const left = ((_d = waterfallDisplayAreaRects.left) === null || _d === void 0 ? void 0 : _d.left) + ((_e = waterfallDisplayAreaRects.left) === null || _e === void 0 ? void 0 : _e.width);
315
+ const right = display$1.width - ((_f = waterfallDisplayAreaRects.right) === null || _f === void 0 ? void 0 : _f.left);
316
+ setSafeArea({
317
+ top,
318
+ left,
319
+ right,
320
+ bottom
321
+ });
322
+ });
323
+ }
324
+ catch (e) {
325
+ console.error('Failed to get display', e);
326
+ }
327
+ });
276
328
  });
329
+ function setSafeArea({ top, left, right, bottom }) {
330
+ safeArea = {
331
+ top,
332
+ bottom,
333
+ left,
334
+ right,
335
+ height: bottom - top,
336
+ width: right - left,
337
+ };
338
+ }
277
339
  /* 同步版本 */
278
340
  const getSystemInfoSync = function () {
341
+ var _a, _b;
279
342
  const res = {};
280
343
  res.SDKVersion = deviceInfo && deviceInfo.sdkApiVersion; // 客户端基础库版本 string
281
344
  res.albumAuthorized = false; // 允许使用相册的开关(仅 iOS 有效) boolean
@@ -285,7 +348,7 @@ const getSystemInfoSync = function () {
285
348
  res.cameraAuthorized = null; // 允许使用摄像头的开关 boolean
286
349
  res.enableDebug = null; // 是否已打开调试 boolean
287
350
  res.fontSizeSetting = null; // 用户字体大小(单位px) number
288
- res.language = i18n && i18n.getSystemLanguage && i18n.getSystemLanguage(); // string
351
+ res.language = (_a = i18n === null || i18n === void 0 ? void 0 : i18n.getSystemLanguage) === null || _a === void 0 ? void 0 : _a.call(i18n); // string
289
352
  res.locationAuthorized = null; // 定位的开关 boolean
290
353
  res.locationEnabled = null; // 地理位置的系统开关 boolean
291
354
  res.microphoneAuthorized = null; // 麦克风的开关 boolean
@@ -296,17 +359,18 @@ const getSystemInfoSync = function () {
296
359
  res.notificationSoundAuthorized = false; // 通知带有声音的开关(仅 iOS 有效)boolean
297
360
  res.phoneCalendarAuthorized = null; // 使用日历的开关 boolean
298
361
  res.wifiEnabled = false; // Wi-Fi 的系统开关 boolean
299
- res.pixelRatio = null; // 设备像素比,number
300
- res.platform = 'android'; // 客户端平台 string
301
- res.safeArea = null; // 在竖屏正方向下的安全区域 General.SafeAreaResult
302
- res.screenHeight = display && display.height; // 屏幕高度,单位px number
303
- res.screenWidth = display && display.width; // 屏幕宽度,单位px number
304
- res.statusBarHeight = null; // 状态栏的高度,单位px number
305
- res.system = deviceInfo && deviceInfo.osFullName; // 操作系统及版本 string
306
- res.theme = null; // 系统当前主题,取值为light或dark 'light' | 'dark'
307
- res.windowWidth = device && device.windowWidth; // 可使用窗口宽度,单位px number
308
- res.windowHeight = device && device.windowHeight; // 可使用窗口高度,单位px number
309
- res.version = deviceInfo && deviceInfo.displayVersion; // 版本号 string
362
+ res.pixelRatio = display$1 && display$1.densityPixels; // 设备像素比,number
363
+ res.platform = 'harmony'; // 客户端平台 string
364
+ res.safeArea = safeArea; // 在竖屏正方向下的安全区域 General.SafeAreaResult
365
+ res.screenHeight = display$1 === null || display$1 === void 0 ? void 0 : display$1.height; // 屏幕高度,单位px number
366
+ res.screenWidth = display$1 === null || display$1 === void 0 ? void 0 : display$1.width; // 屏幕宽度,单位px number
367
+ res.statusBarHeight = statusBarHeight; // 状态栏的高度,单位px number
368
+ res.system = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.osFullName; // 操作系统及版本 string
369
+ // Note: 更新配置时才能记录
370
+ 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'
371
+ res.windowHeight = windowRect === null || windowRect === void 0 ? void 0 : windowRect.height; // 可使用窗口高度,单位px number
372
+ res.windowWidth = windowRect === null || windowRect === void 0 ? void 0 : windowRect.width; // 可使用窗口宽度,单位px number
373
+ res.version = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.displayVersion; // 版本号 string
310
374
  return res;
311
375
  };
312
376
  /* 异步版本 */
@@ -399,7 +463,7 @@ const launchOptions = {
399
463
  function initLaunchOptions(options = {}) {
400
464
  Object.assign(launchOptions, options);
401
465
  }
402
- eventCenter.once('__taroRouterLaunch', initLaunchOptions);
466
+ eventCenter$1.once('__taroRouterLaunch', initLaunchOptions);
403
467
  // 生命周期
404
468
  const getLaunchOptionsSync = () => launchOptions;
405
469
  const getEnterOptionsSync = () => launchOptions;
@@ -412,7 +476,13 @@ const base64ToArrayBuffer = /* @__PURE__ */ temporarilyNotSupport('base64ToArray
412
476
  /** 创建离屏 canvas 实例 */
413
477
  const createOffscreenCanvas = /* @__PURE__ */ temporarilyNotSupport('createOffscreenCanvas');
414
478
  /** 创建 canvas 的绘图上下文 CanvasContext 对象 */
415
- const createCanvasContext = /* @__PURE__ */ temporarilyNotSupport('createOffscreenCanvas');
479
+ // export const createCanvasContext = /* @__PURE__ */ temporarilyNotSupport('createOffscreenCanvas')
480
+ const createCanvasContext = (canvasId) => {
481
+ const dom = eventSource.get(`canvasId-${canvasId}`);
482
+ // return dom as TaroCanvasElement
483
+ if (dom)
484
+ return dom.context;
485
+ };
416
486
  /** 把当前画布指定区域的内容导出生成指定大小的图片 */
417
487
  const canvasToTempFilePath = /* @__PURE__ */ temporarilyNotSupport('createOffscreenCanvas');
418
488
  /** 将像素数据绘制到画布 */
@@ -533,7 +603,7 @@ const getBatteryInfoSync = () => ({
533
603
  isCharging: [BatteryChargeState.ENABLE, BatteryChargeState.FULL].includes(batteryInfo.chargingStatus),
534
604
  level: batteryInfo.batterySOC
535
605
  });
536
- const getBatteryInfo = ({ success, fail, complete } = {}) => __awaiter(void 0, void 0, void 0, function* () {
606
+ const getBatteryInfo = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* ({ success, fail, complete } = {}) {
537
607
  const handle = new MethodHandler({ name: 'getBatteryInfo', success, fail, complete });
538
608
  try {
539
609
  return handle.success(getBatteryInfoSync());
@@ -606,8 +676,20 @@ const setClipboardData = function (options) {
606
676
  }
607
677
  return new Promise((resolve, reject) => {
608
678
  const systemPasteboard = pasteboard.getSystemPasteboard();
609
- const pasteData = pasteboard.createPlainTextData(data);
610
- systemPasteboard.setPasteData(pasteData, (error, data) => {
679
+ const pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, data);
680
+ try {
681
+ systemPasteboard.setDataSync(pasteData);
682
+ promptAction.showToast({
683
+ message: '内容已复制',
684
+ duration: 1500,
685
+ bottom: '50%',
686
+ showMode: 1 // 设置弹窗显示模式,显示在应用之上。
687
+ });
688
+ return handle.success({
689
+ data,
690
+ }, { resolve, reject });
691
+ }
692
+ catch (error) {
611
693
  if (error) {
612
694
  console.error('Failed to set PasteData. Cause: ' + JSON.stringify(error));
613
695
  res = {
@@ -616,12 +698,7 @@ const setClipboardData = function (options) {
616
698
  };
617
699
  callAsyncFail(reject, res, options);
618
700
  }
619
- else {
620
- return handle.success({
621
- data,
622
- }, { resolve, reject });
623
- }
624
- });
701
+ }
625
702
  });
626
703
  };
627
704
  /**
@@ -632,7 +709,7 @@ const getClipboardData = function (options) {
632
709
  const handle = new MethodHandler({ name: 'getClipboardData', success, fail, complete });
633
710
  return new Promise((resolve, reject) => {
634
711
  const systemPasteboard = pasteboard.getSystemPasteboard();
635
- systemPasteboard.getPasteData((error, pasteData) => {
712
+ systemPasteboard.getData((error, pasteData) => {
636
713
  if (error) {
637
714
  console.error('Failed to obtain PasteData. Cause: ' + JSON.stringify(error));
638
715
  return handle.fail({
@@ -771,7 +848,7 @@ const getNetworkType = (options = {}) => {
771
848
  });
772
849
  };
773
850
  const networkStatusManager = new CallbackManager();
774
- const networkStatusListener = (data, code = 0) => __awaiter(void 0, void 0, void 0, function* () {
851
+ const networkStatusListener = (data_1, ...args_1) => __awaiter(void 0, [data_1, ...args_1], void 0, function* (data, code = 0) {
775
852
  if (code > 0) {
776
853
  return networkStatusManager.trigger({ isConnected: false, networkType: 'none' });
777
854
  }
@@ -1984,7 +2061,6 @@ function getEnv() {
1984
2061
  }
1985
2062
  // TODO
1986
2063
  const getCurrentPages = () => [];
1987
- const getCurrentInstance = () => Current;
1988
2064
  const requirePlugin$1 = temporarilyNotSupport('requirePlugin');
1989
2065
 
1990
2066
  // @ts-nocheck
@@ -2014,7 +2090,7 @@ function formatLocation(location) {
2014
2090
  altitude: location.altitude,
2015
2091
  accuracy: location.accuracy,
2016
2092
  speed: location.speed,
2017
- verticalAccuracy: 0,
2093
+ verticalAccuracy: 0, // OHOS 不支持返回此参数,直接设置为默认值
2018
2094
  horizontalAccuracy: 0 // OHOS 不支持返回此参数,直接设置为默认值
2019
2095
  };
2020
2096
  return wxLocate;
@@ -2203,20 +2279,20 @@ const chooseMedia = function (options) {
2203
2279
  });
2204
2280
  };
2205
2281
 
2282
+ const READ_IMAGEVIDEO_PERMISSIONS = 'ohos.permission.READ_IMAGEVIDEO';
2283
+ const READ_MEDIA_PERMISSIONS = 'ohos.permission.READ_MEDIA';
2284
+ const WRITE_MEDIA_PERMISSIONS = 'ohos.permission.WRITE_MEDIA';
2285
+ const MEDIA_LOCATION_PERMISSIONS = 'ohos.permission.MEDIA_LOCATION';
2286
+ const IMAGE_PERMISSION = [READ_IMAGEVIDEO_PERMISSIONS, READ_MEDIA_PERMISSIONS, WRITE_MEDIA_PERMISSIONS, MEDIA_LOCATION_PERMISSIONS];
2287
+
2206
2288
  // HarmonyOS 图片模块首批接口从API version 7开始支持。
2207
2289
  // HarmonyOS 文档链接:https://developer.harmonyos.com/cn/docs/documentation/doc-references/js-apis-image-0000001122977382
2208
2290
  // WX 文档链接:https://developers.weixin.qq.com/miniprogram/dev/api/media/image/wx.saveImageToPhotosAlbum.html
2209
- // ✅ wx.getImageInfo(Object object) API7以上支持
2210
- // ✅ wx.compressImage(Object object) API7以上支持
2211
- // ✅ wx.chooseImage(Object object)
2212
- // ❌ wx.chooseMessageFile(Object object) HarmonyOS不支持
2213
- // ❌ wx.saveImageToPhotosAlbum(Object object) api 9+ HarmonyOS不支持
2214
- // ❌ wx.previewImage(Object object) api 9+ HarmonyOS不支持
2215
2291
  const getImageInfoSchema = {
2216
- url: 'String'
2292
+ src: 'String'
2217
2293
  };
2218
2294
  const compressImageSchema = {
2219
- url: 'String'
2295
+ src: 'String'
2220
2296
  };
2221
2297
  const chooseImageSchema = {
2222
2298
  count: 'Number'
@@ -2246,56 +2322,191 @@ const getImageInfo = function (options) {
2246
2322
  });
2247
2323
  });
2248
2324
  };
2249
- const compressImage = function (options) {
2250
- return new Promise((resolve, reject) => {
2325
+ class CompressedImageInfo {
2326
+ constructor() {
2327
+ this.imageUri = ''; // 压缩后图片保存位置的uri
2328
+ this.imageByteLength = 0; // 压缩后图片字节长度
2329
+ }
2330
+ }
2331
+ function saveImage(compressedImageData, compressedImageUri) {
2332
+ return __awaiter(this, void 0, void 0, function* () {
2333
+ const tempArr = compressedImageUri.split('/');
2334
+ const name = tempArr[tempArr.length - 1];
2335
+ const context = getContext(Current === null || Current === void 0 ? void 0 : Current.page);
2336
+ const applicationContext = context.getApplicationContext();
2337
+ const tempDir = applicationContext.tempDir;
2338
+ const filePath = `${tempDir}/${name}`;
2251
2339
  try {
2252
- validateParams('compressImage', options, compressImageSchema);
2253
- }
2254
- catch (error) {
2255
- const res = { errMsg: error.message };
2256
- return callAsyncFail(reject, res, options);
2257
- }
2258
- const { src, quality = 80 } = options;
2259
- const source = image.createImageSource(src);
2260
- if (isNull(source)) {
2261
- const createImageSourceError = { errMsg: 'compressImage fail: createImageSource has failed.' };
2262
- callAsyncFail(reject, createImageSourceError, options);
2263
- return;
2340
+ const res = fs.accessSync(filePath);
2341
+ if (res) {
2342
+ // 如果图片afterCompressiona.jpeg已存在,则删除
2343
+ fs.unlinkSync(filePath);
2344
+ }
2264
2345
  }
2265
- const packer = image.createImagePacker(src);
2266
- if (isNull(packer)) {
2267
- const createImagePackerError = { errMsg: 'compressImage fail: createImagePacker has failed.' };
2268
- callAsyncFail(reject, createImagePackerError, options);
2346
+ catch (err) {
2347
+ console.error(`[Taro] saveImage Error: AccessSync failed with error message: ${err.message}, error code: ${err.code}`);
2269
2348
  }
2270
- const packingOptionsOHOS = {
2271
- // TODO:需要获取文件名后缀
2272
- format: 'image/jpeg',
2273
- quality: quality
2274
- };
2275
- packer.packing(source, packingOptionsOHOS).then((value) => {
2276
- callAsyncSuccess(resolve, value, options);
2277
- }).catch((error) => {
2278
- callAsyncFail(reject, error, options);
2349
+ // 知识点:保存图片。获取最终图片压缩数据compressedImageData,保存图片。
2350
+ // 压缩图片数据写入文件
2351
+ const file = fs.openSync(filePath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
2352
+ fs.writeSync(file.fd, compressedImageData);
2353
+ fs.closeSync(file);
2354
+ // 获取压缩图片信息
2355
+ const compressedImageInfo = new CompressedImageInfo();
2356
+ compressedImageInfo.imageUri = filePath;
2357
+ compressedImageInfo.imageByteLength = compressedImageData.byteLength;
2358
+ return compressedImageInfo;
2359
+ });
2360
+ }
2361
+ const compressImage = function (options) {
2362
+ return new Promise((resolve, reject) => {
2363
+ requestPermissions(IMAGE_PERMISSION).then(() => {
2364
+ try {
2365
+ validateParams('compressImage', options, compressImageSchema);
2366
+ }
2367
+ catch (error) {
2368
+ const res = { errMsg: error.message };
2369
+ return callAsyncFail(reject, res, options);
2370
+ }
2371
+ const { src, quality = 80, compressedWidth, compressedHeight } = options;
2372
+ const srcAfterCompress = src.includes('_after_compress') ? src : src.split('.').join('_after_compress.');
2373
+ const file = fs.openSync(src, fs.OpenMode.READ_ONLY);
2374
+ // const stat = fs.statSync(file.fd)
2375
+ // console.log('[Taro] 压缩前图片的大小为:', stat.size)
2376
+ const source = image.createImageSource(file.fd);
2377
+ if (isNull(source)) {
2378
+ const createImageSourceError = { errMsg: 'compressImage fail: createImageSource has failed.' };
2379
+ callAsyncFail(reject, createImageSourceError, options);
2380
+ return;
2381
+ }
2382
+ const width = source.getImageInfoSync().size.width;
2383
+ const height = source.getImageInfoSync().size.height;
2384
+ let wantWidth = compressedWidth || compressedHeight || 0;
2385
+ let wantHeight = compressedHeight || compressedWidth || 0;
2386
+ if (width > wantWidth || height > wantHeight) {
2387
+ const heightRatio = height / wantHeight;
2388
+ const widthRatio = width / wantWidth;
2389
+ const finalRatio = heightRatio < widthRatio ? heightRatio : widthRatio;
2390
+ wantWidth = Math.round(width / finalRatio);
2391
+ wantHeight = Math.round(height / finalRatio);
2392
+ }
2393
+ const decodingOptions = {
2394
+ editable: true,
2395
+ desiredPixelFormat: image.PixelMapFormat.RGBA_8888,
2396
+ desiredSize: { width: wantWidth, height: wantHeight }
2397
+ };
2398
+ source.createPixelMap(decodingOptions, (error, pixelMap) => {
2399
+ if (error !== undefined) {
2400
+ fs.closeSync(file);
2401
+ const res = { errMsg: error };
2402
+ callAsyncFail(reject, res, options);
2403
+ }
2404
+ else {
2405
+ const packer = image.createImagePacker(file.fd);
2406
+ if (isNull(packer)) {
2407
+ fs.closeSync(file);
2408
+ const createImagePackerError = { errMsg: 'compressImage fail: createImagePacker has failed.' };
2409
+ callAsyncFail(reject, createImagePackerError, options);
2410
+ return;
2411
+ }
2412
+ const isPNG = src.endsWith('.png');
2413
+ const packingOptionsOHOS = {
2414
+ format: isPNG ? 'image/png' : 'image/jpeg',
2415
+ quality: quality
2416
+ };
2417
+ packer.packing(pixelMap, packingOptionsOHOS).then((value) => {
2418
+ fs.closeSync(file);
2419
+ saveImage(value, srcAfterCompress).then(result => {
2420
+ callAsyncSuccess(resolve, { tempFilePath: result.imageUri }, options);
2421
+ });
2422
+ }).catch((error) => {
2423
+ fs.closeSync(file);
2424
+ callAsyncFail(reject, error, options);
2425
+ });
2426
+ }
2427
+ });
2428
+ }, (error) => {
2429
+ const res = { errMsg: error };
2430
+ return callAsyncFail(reject, res, options);
2279
2431
  });
2280
2432
  });
2281
2433
  };
2282
2434
  const chooseImage = function (options) {
2283
2435
  return new Promise((resolve, reject) => {
2284
- try {
2285
- validateParams('chooseImage', options, chooseImageSchema);
2286
- }
2287
- catch (error) {
2288
- const res = { errMsg: error.message };
2436
+ requestPermissions(IMAGE_PERMISSION).then(() => {
2437
+ try {
2438
+ validateParams('chooseImage', options, chooseImageSchema);
2439
+ }
2440
+ catch (error) {
2441
+ const res = { errMsg: error.message };
2442
+ return callAsyncFail(reject, res, options);
2443
+ }
2444
+ const { count = 9 } = options;
2445
+ const photoViewPicker = new picker.PhotoViewPicker();
2446
+ let sizeType = options.sizeType;
2447
+ if (!sizeType || !sizeType.length) {
2448
+ sizeType = ['compressed', 'original'];
2449
+ }
2450
+ photoSelectOptions.maxSelectNumber = count; // 选择媒体文件的最大数目
2451
+ photoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE; // 过滤选择媒体文件类型为IMAGE
2452
+ photoViewPicker.select(photoSelectOptions).then((photoSelectResult) => {
2453
+ const result = {};
2454
+ const isOrigin = photoSelectResult.isOriginalPhoto;
2455
+ if (isOrigin) {
2456
+ const tempFilePaths = [];
2457
+ const tempFiles = photoSelectResult.photoUris.map(uri => {
2458
+ const file = fs.openSync(uri, fs.OpenMode.READ_ONLY);
2459
+ const stat = fs.statSync(file.fd);
2460
+ const size = stat.size;
2461
+ fs.closeSync(file);
2462
+ tempFilePaths.push(uri);
2463
+ return {
2464
+ size,
2465
+ path: uri,
2466
+ };
2467
+ });
2468
+ result.tempFiles = tempFiles;
2469
+ result.tempFilePaths = tempFilePaths;
2470
+ callAsyncSuccess(resolve, result, options);
2471
+ }
2472
+ else {
2473
+ const actions = photoSelectResult.photoUris.map(uri => {
2474
+ return new Promise(resolve => {
2475
+ compressImage({
2476
+ src: uri,
2477
+ compressedWidth: getSystemInfoSync().screenWidth / 2,
2478
+ compressedHeight: getSystemInfoSync().screenHeight / 2,
2479
+ success: (compressResult) => {
2480
+ resolve(compressResult.tempFilePath);
2481
+ }
2482
+ });
2483
+ });
2484
+ });
2485
+ Promise.all(actions).then(tempFilePaths => {
2486
+ const tempFiles = tempFilePaths.map(uri => {
2487
+ const file = fs.openSync(uri, fs.OpenMode.READ_ONLY);
2488
+ const stat = fs.statSync(file.fd);
2489
+ const size = stat.size;
2490
+ fs.closeSync(file);
2491
+ return {
2492
+ size,
2493
+ path: uri,
2494
+ };
2495
+ });
2496
+ result.tempFilePaths = tempFilePaths;
2497
+ result.tempFiles = tempFiles;
2498
+ callAsyncSuccess(resolve, result, options);
2499
+ }).catch(error => {
2500
+ const res = { errMsg: error };
2501
+ return callAsyncFail(reject, res, options);
2502
+ });
2503
+ }
2504
+ }).catch((error) => {
2505
+ callAsyncFail(reject, error, options);
2506
+ });
2507
+ }, (error) => {
2508
+ const res = { errMsg: error };
2289
2509
  return callAsyncFail(reject, res, options);
2290
- }
2291
- const { count = 9 } = options;
2292
- const photoViewPicker = new picker.PhotoViewPicker();
2293
- photoSelectOptions.maxSelectNumber = count; // 选择媒体文件的最大数目
2294
- photoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE; // 过滤选择媒体文件类型为IMAGE
2295
- photoViewPicker.select(photoSelectOptions).then((photoSelectResult) => {
2296
- callAsyncSuccess(resolve, { tempFilePaths: photoSelectResult.photoUris });
2297
- }).catch((error) => {
2298
- callAsyncFail(reject, error, options);
2299
2510
  });
2300
2511
  });
2301
2512
  };
@@ -3136,7 +3347,7 @@ const switchTab = (options) => {
3136
3347
  }
3137
3348
  if (((_a = stack[stack.length - 1]) === null || _a === void 0 ? void 0 : _a.path) === url) {
3138
3349
  // Note: 当前为 Tab 页时,触发 switch 事件
3139
- eventCenter.trigger('__taroSwitchTab', { url, params });
3350
+ eventCenter$1.trigger('__taroSwitchTab', { url, params });
3140
3351
  router.getLength() > 1 && router.clear();
3141
3352
  }
3142
3353
  else if (stack.some(item => item.path === url)) {
@@ -3190,113 +3401,172 @@ const getBackgroundFetchData = /* @__PURE__ */ temporarilyNotSupport('getBackgro
3190
3401
  // 周期性更新
3191
3402
  const createCacheManager = /* @__PURE__ */ temporarilyNotSupport('createCacheManager');
3192
3403
 
3193
- const preferencesPromise = Current.contextPromise
3194
- .then((context) => {
3195
- return bundleManager
3196
- .getBundleInfoForSelf(bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION)
3197
- .then(data => {
3198
- return dataPreferences
3199
- .getPreferences(context, `${data.appInfo.uid}Store`);
3200
- });
3201
- })
3202
- .catch((error) => {
3203
- hilog.error(0x0000, 'TaroFailedTag', 'Failed to load the storage. Cause: %{public}s', error.code ? JSON.stringify(error) : error.message || error);
3404
+ /**
3405
+ * 从API Version 6开始,该模块不再维护,可以使用模块@ohos.data.storage。在API Version 9后,推荐使用新模块@ohos.data.preferences。
3406
+ * https://developer.harmonyos.com/cn/docs/documentation/doc-references-V3/js-apis-data-preferences-0000001427745052-V3
3407
+ */
3408
+ let context;
3409
+ let kvManager;
3410
+ let kvStore;
3411
+ let kvStorePromise;
3412
+ Current.contextPromise.then((ctx) => {
3413
+ context = ctx;
3414
+ const kvManagerConfig = {
3415
+ context: context,
3416
+ bundleName: 'com.example.taro'
3417
+ };
3418
+ try {
3419
+ // 创建KVManager实例
3420
+ kvManager = distributedKVStore.createKVManager(kvManagerConfig);
3421
+ // 继续创建获取数据库
3422
+ const options = {
3423
+ createIfMissing: true,
3424
+ encrypt: false,
3425
+ backup: false,
3426
+ autoSync: false,
3427
+ // kvStoreType不填时,默认创建多设备协同数据库
3428
+ kvStoreType: distributedKVStore.KVStoreType.SINGLE_VERSION,
3429
+ // 多设备协同数据库:kvStoreType: distributedKVStore.KVStoreType.DEVICE_COLLABORATION,
3430
+ securityLevel: distributedKVStore.SecurityLevel.S1
3431
+ };
3432
+ const data = bundleManager.getBundleInfoForSelfSync(bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION);
3433
+ kvStorePromise = new Promise(resolve => {
3434
+ kvManager.getKVStore(`${data.appInfo.uid}Store`, options, (err, store) => {
3435
+ if (err) {
3436
+ console.error(`Failed to get KVStore: Code:${err.code},message:${err.message}`);
3437
+ return;
3438
+ }
3439
+ kvStore = store;
3440
+ // 请确保获取到键值数据库实例后,再进行相关数据操作
3441
+ resolve();
3442
+ });
3443
+ });
3444
+ }
3445
+ catch (e) {
3446
+ console.error(`Failed to create KVManager. Code:${e.code},message:${e.message}`);
3447
+ }
3448
+ return context;
3204
3449
  });
3205
- function getItem(key) {
3206
- return __awaiter(this, void 0, void 0, function* () {
3207
- try {
3208
- const preferences = yield preferencesPromise;
3209
- const item = yield preferences.get(key, null);
3210
- return { result: true, data: item };
3211
- }
3212
- catch (error) {
3213
- return { result: false };
3214
- }
3215
- });
3216
- }
3217
3450
  const storageSchema = {
3218
3451
  key: 'String'
3219
3452
  };
3220
- function getStorage(options) {
3221
- return new Promise((resolve, reject) => {
3222
- try {
3223
- validateParams('getStorage', options, storageSchema);
3453
+ function checkContextExist(api, isAsync = false) {
3454
+ if (!context) {
3455
+ const message = `${api} 调用失败,Taro 不支持过早地调用 ${api},请确保页面已经渲染完成再调用此 API`;
3456
+ if (isAsync) {
3457
+ return {
3458
+ isExist: false,
3459
+ error: Promise.reject(new Error(message))
3460
+ };
3224
3461
  }
3225
- catch (error) {
3226
- const res = { errMsg: error.message };
3227
- return callAsyncFail(reject, res, options);
3462
+ else {
3463
+ console.warn(message);
3464
+ return {
3465
+ isExist: false,
3466
+ };
3228
3467
  }
3229
- getItem(options.key).then(({ result, data }) => {
3230
- const res = { errMsg: 'getStorage:ok' };
3231
- if (result) {
3232
- res.data = data;
3233
- callAsyncSuccess(resolve, res, options);
3468
+ }
3469
+ return {
3470
+ isExist: true,
3471
+ };
3472
+ }
3473
+ function getStorage(options) {
3474
+ const name = 'getStorage';
3475
+ const { isExist, error } = checkContextExist(name, true);
3476
+ if (!isExist) {
3477
+ return error;
3478
+ }
3479
+ const { key, success, fail, complete } = options || {};
3480
+ const handle = new MethodHandler({ name, success, fail, complete });
3481
+ return new Promise((resolve, reject) => {
3482
+ kvStorePromise.then(() => {
3483
+ try {
3484
+ validateParams(name, options, storageSchema);
3234
3485
  }
3235
- else {
3236
- res.errMsg = 'getStorage:fail data not found';
3237
- callAsyncFail(reject, res, options);
3486
+ catch (error) {
3487
+ const res = { errMsg: error.message };
3488
+ return handle.fail(res, { resolve, reject });
3238
3489
  }
3490
+ kvStore = kvStore;
3491
+ kvStore.get(key, (err, data) => {
3492
+ if (err) {
3493
+ handle.fail({ errMsg: `Failed to get data. Code:${err.code},message:${err.message}` }, { resolve, reject });
3494
+ return;
3495
+ }
3496
+ handle.success({ data }, { resolve, reject });
3497
+ });
3239
3498
  });
3240
3499
  });
3241
3500
  }
3242
3501
  function setStorage(options) {
3502
+ const name = 'setStorage';
3503
+ const { isExist, error } = checkContextExist(name, true);
3504
+ if (!isExist) {
3505
+ return error;
3506
+ }
3507
+ const { key, data, success, fail, complete } = options || {};
3508
+ const handle = new MethodHandler({ name, success, fail, complete });
3243
3509
  return new Promise((resolve, reject) => {
3244
- try {
3245
- validateParams('setStorage', options, storageSchema);
3246
- }
3247
- catch (error) {
3248
- const res = { errMsg: error.message };
3249
- return callAsyncFail(reject, res, options);
3250
- }
3251
- const { key, data } = options;
3252
- const res = { errMsg: 'setStorage:ok' };
3253
- preferencesPromise.then((preferences) => __awaiter(this, void 0, void 0, function* () {
3254
- yield preferences.put(key, data);
3255
- yield preferences.flush();
3256
- callAsyncSuccess(resolve, res, options);
3257
- }));
3510
+ kvStorePromise.then(() => {
3511
+ try {
3512
+ validateParams(name, options, storageSchema);
3513
+ }
3514
+ catch (error) {
3515
+ const res = { errMsg: error.message };
3516
+ return handle.fail(res, { resolve, reject });
3517
+ }
3518
+ kvStore = kvStore;
3519
+ kvStore.put(key, data, (err) => {
3520
+ if (err) {
3521
+ handle.fail({ errMsg: `Failed to put data. Code:${err.code},message:${err.message}` }, { resolve, reject });
3522
+ return;
3523
+ }
3524
+ handle.success({}, { resolve, reject });
3525
+ });
3526
+ });
3258
3527
  });
3259
3528
  }
3260
3529
  function removeStorage(options) {
3530
+ const name = 'removeStorage';
3531
+ const { isExist, error } = checkContextExist(name, true);
3532
+ if (!isExist) {
3533
+ return error;
3534
+ }
3535
+ const { key, success, fail, complete } = options || {};
3536
+ const handle = new MethodHandler({ name, success, fail, complete });
3261
3537
  return new Promise((resolve, reject) => {
3262
- try {
3263
- validateParams('removeStorage', options, storageSchema);
3264
- }
3265
- catch (error) {
3266
- const res = { errMsg: error.message };
3267
- return callAsyncFail(reject, res, options);
3268
- }
3269
- const { key } = options;
3270
- preferencesPromise.then((preferences) => __awaiter(this, void 0, void 0, function* () {
3271
- yield preferences.delete(key);
3272
- yield preferences.flush();
3273
- const res = { errMsg: 'removeStorage:ok' };
3274
- callAsyncSuccess(resolve, res, options);
3275
- }));
3276
- });
3277
- }
3278
- function clearStorage(options) {
3279
- return new Promise(resolve => {
3280
- preferencesPromise.then((preferences) => __awaiter(this, void 0, void 0, function* () {
3281
- yield preferences.clear();
3282
- yield preferences.flush();
3283
- const res = { errMsg: 'clearStorage:ok' };
3284
- callAsyncSuccess(resolve, res, options);
3285
- }));
3538
+ kvStorePromise.then(() => {
3539
+ try {
3540
+ validateParams(name, options, storageSchema);
3541
+ }
3542
+ catch (error) {
3543
+ const res = { errMsg: error.message };
3544
+ return handle.fail(res, { resolve, reject });
3545
+ }
3546
+ kvStore = kvStore;
3547
+ kvStore.delete(key, (err) => {
3548
+ if (err) {
3549
+ handle.fail({ errMsg: `Failed to delete data. Code:${err.code},message:${err.message}` }, { resolve, reject });
3550
+ return;
3551
+ }
3552
+ handle.success({}, { resolve, reject });
3553
+ });
3554
+ });
3286
3555
  });
3287
3556
  }
3288
3557
  const getStorageInfoSync = temporarilyNotSupport('getStorageInfoSync');
3289
3558
  const getStorageInfo = temporarilyNotSupport('getStorageInfo');
3290
- const getStorageSync = temporarilyNotSupport('getStorageSync', 'getStorage');
3291
- const setStorageSync = temporarilyNotSupport('setStorageSync', 'setStorage');
3292
- const clearStorageSync = temporarilyNotSupport('clearStorageSync', 'clearStorage');
3293
- const removeStorageSync = temporarilyNotSupport('removeStorageSync', 'removeStorage');
3294
3559
  const createBufferURL = /* @__PURE__ */ temporarilyNotSupport('createBufferURL');
3295
3560
  const revokeBufferURL = /* @__PURE__ */ temporarilyNotSupport('revokeBufferURL');
3296
3561
  const batchSetStorageSync = /* @__PURE__ */ temporarilyNotSupport('batchSetStorageSync');
3297
3562
  const batchSetStorage = /* @__PURE__ */ temporarilyNotSupport('batchSetStorage');
3298
3563
  const batchGetStorageSync = /* @__PURE__ */ temporarilyNotSupport('batchGetStorageSync');
3299
3564
  const batchGetStorage = /* @__PURE__ */ temporarilyNotSupport('batchGetStorage');
3565
+ const clearStorage = temporarilyNotSupport('clearStorage');
3566
+ const getStorageSync = temporarilyNotSupport('getStorageSync', 'getStorage');
3567
+ const setStorageSync = temporarilyNotSupport('setStorageSync', 'setStorage');
3568
+ const clearStorageSync = temporarilyNotSupport('clearStorageSync', 'clearStorage');
3569
+ const removeStorageSync = temporarilyNotSupport('removeStorageSync', 'removeStorage');
3300
3570
 
3301
3571
  class Animation {
3302
3572
  constructor({ duration = 400, delay = 0, timingFunction = 'linear', transformOrigin = '50% 50% 0', unit = 'px' } = {}) {
@@ -3329,6 +3599,9 @@ class Animation {
3329
3599
  transformOrigin,
3330
3600
  rule: Object.assign({}, this.rule)
3331
3601
  });
3602
+ if (this.rule.transform) {
3603
+ this.rule.transform = Object.assign({}, this.rule.transform);
3604
+ }
3332
3605
  return this;
3333
3606
  }
3334
3607
  matrix(a, b, c, d, tx, ty) {
@@ -3340,75 +3613,120 @@ class Animation {
3340
3613
  return this;
3341
3614
  }
3342
3615
  rotate(angle) {
3343
- this.rule.rotate = { x: 0, y: 0, z: 1, angle };
3616
+ if (!this.rule.transform) {
3617
+ this.rule.transform = {};
3618
+ }
3619
+ this.rule.transform.Rotate = { x: 0, y: 0, z: 1, angle };
3344
3620
  return this;
3345
3621
  }
3346
3622
  rotate3d(x, y, z, angle) {
3347
- this.rule.rotate = { x, y, z, angle };
3623
+ if (!this.rule.transform) {
3624
+ this.rule.transform = {};
3625
+ }
3626
+ this.rule.transform.Rotate = { x, y, z, angle };
3348
3627
  return this;
3349
3628
  }
3350
3629
  rotateX(angle) {
3351
- this.rule.rotate = { x: 1, y: 0, z: 0, angle };
3630
+ if (!this.rule.transform) {
3631
+ this.rule.transform = {};
3632
+ }
3633
+ this.rule.transform.Rotate = { x: 1, y: 0, z: 0, angle };
3352
3634
  return this;
3353
3635
  }
3354
3636
  rotateY(angle) {
3355
- this.rule.rotate = { x: 0, y: 1, z: 0, angle };
3637
+ if (!this.rule.transform) {
3638
+ this.rule.transform = {};
3639
+ }
3640
+ this.rule.transform.Rotate = { x: 0, y: 1, z: 0, angle };
3356
3641
  return this;
3357
3642
  }
3358
3643
  rotateZ(angle) {
3359
- this.rule.rotate = { x: 0, y: 0, z: 1, angle };
3644
+ if (!this.rule.transform) {
3645
+ this.rule.transform = {};
3646
+ }
3647
+ this.rule.transform.Rotate = { x: 0, y: 0, z: 1, angle };
3360
3648
  return this;
3361
3649
  }
3362
3650
  scale(sx, sy) {
3363
- this.rule.scale = { x: sx, y: sy };
3651
+ if (!this.rule.transform) {
3652
+ this.rule.transform = {};
3653
+ }
3654
+ this.rule.transform.Scale = { x: sx, y: isUndefined(sy) ? sx : sy };
3364
3655
  return this;
3365
3656
  }
3366
3657
  scale3d(sx, sy, sz) {
3367
- this.rule.scale = { x: sx, y: sy, z: sz };
3658
+ if (!this.rule.transform) {
3659
+ this.rule.transform = {};
3660
+ }
3661
+ this.rule.transform.Scale = { x: sx, y: sy, z: sz };
3368
3662
  return this;
3369
3663
  }
3370
3664
  scaleX(scale) {
3371
- this.rule.scale = { x: scale };
3665
+ if (!this.rule.transform) {
3666
+ this.rule.transform = {};
3667
+ }
3668
+ this.rule.transform.Scale = { x: scale };
3372
3669
  return this;
3373
3670
  }
3374
3671
  scaleY(scale) {
3375
- this.rule.scale = { y: scale };
3672
+ if (!this.rule.transform) {
3673
+ this.rule.transform = {};
3674
+ }
3675
+ this.rule.transform.Scale = { y: scale };
3376
3676
  return this;
3377
3677
  }
3378
3678
  scaleZ(scale) {
3379
- this.rule.scale = { z: scale };
3679
+ if (!this.rule.transform) {
3680
+ this.rule.transform = {};
3681
+ }
3682
+ this.rule.transform.Scale = { z: scale };
3380
3683
  return this;
3381
3684
  }
3382
3685
  skew(ax, ay) {
3383
- this.rule.skew = { x: ax, y: ay };
3686
+ temporarilyNotSupport('animation.skew:' + `${ax}, ${ay}`)(ax, ay);
3384
3687
  return this;
3385
3688
  }
3386
3689
  skewX(angle) {
3387
- this.rule.skew = { x: angle };
3690
+ temporarilyNotSupport('animation.skewX:' + angle)(angle);
3388
3691
  return this;
3389
3692
  }
3390
3693
  skewY(angle) {
3391
- this.rule.skew = { y: angle };
3694
+ temporarilyNotSupport('animation.skewY:' + angle)(angle);
3392
3695
  return this;
3393
3696
  }
3394
3697
  translate(tx, ty) {
3395
- this.rule.translate = { x: tx, y: ty };
3698
+ if (!this.rule.transform) {
3699
+ this.rule.transform = {};
3700
+ }
3701
+ this.rule.transform.Translate = { x: tx, y: ty };
3396
3702
  return this;
3397
3703
  }
3398
3704
  translate3d(tx, ty, tz) {
3399
- this.rule.translate = { x: tx, y: ty, z: tz };
3705
+ if (!this.rule.transform) {
3706
+ this.rule.transform = {};
3707
+ }
3708
+ this.rule.transform.Translate = { x: tx, y: ty, z: tz };
3400
3709
  return this;
3401
3710
  }
3402
3711
  translateX(translation) {
3403
- this.rule.translate = { x: translation };
3712
+ if (!this.rule.transform) {
3713
+ this.rule.transform = {};
3714
+ }
3715
+ this.rule.transform.Translate = { x: translation };
3404
3716
  return this;
3405
3717
  }
3406
3718
  translateY(translation) {
3407
- this.rule.translate = { y: translation };
3719
+ if (!this.rule.transform) {
3720
+ this.rule.transform = {};
3721
+ }
3722
+ this.rule.transform.Translate = { y: translation };
3408
3723
  return this;
3409
3724
  }
3410
3725
  translateZ(translation) {
3411
- this.rule.translate = { z: translation };
3726
+ if (!this.rule.transform) {
3727
+ this.rule.transform = {};
3728
+ }
3729
+ this.rule.transform.Translate = { z: translation };
3412
3730
  return this;
3413
3731
  }
3414
3732
  opacity(value) {
@@ -3420,15 +3738,15 @@ class Animation {
3420
3738
  return this;
3421
3739
  }
3422
3740
  width(value) {
3423
- this.rule.size = Object.assign(Object.assign({}, this.rule.size), { width: value });
3741
+ this.rule.width = value;
3424
3742
  return this;
3425
3743
  }
3426
3744
  height(value) {
3427
- this.rule.size = Object.assign(Object.assign({}, this.rule.size), { height: value });
3745
+ this.rule.height = value;
3428
3746
  return this;
3429
3747
  }
3430
3748
  left(value) {
3431
- temporarilyNotSupport('animation.left:' + value)(value);
3749
+ this.rule.left = value;
3432
3750
  return this;
3433
3751
  }
3434
3752
  right(value) {
@@ -3436,7 +3754,7 @@ class Animation {
3436
3754
  return this;
3437
3755
  }
3438
3756
  top(value) {
3439
- temporarilyNotSupport('animation.top:' + value)(value);
3757
+ this.rule.top = value;
3440
3758
  return this;
3441
3759
  }
3442
3760
  bottom(value) {
@@ -3454,8 +3772,9 @@ function setBackgroundColor(options) {
3454
3772
  const { success, fail, complete } = options || {};
3455
3773
  const handle = new MethodHandler({ name: 'setBackgroundColor', success, fail, complete });
3456
3774
  return new Promise((resolve, reject) => {
3457
- eventCenter.trigger('__taroPageStyle', {
3458
- backgroundColor: options.backgroundColor || options.backgroundColorTop || options.backgroundColorBottom,
3775
+ eventCenter$1.trigger('__taroPageStyle', {
3776
+ backgroundColor: options.backgroundColorBottom || options.backgroundColor,
3777
+ backgroundColorContext: options.backgroundColorTop || options.backgroundColor
3459
3778
  });
3460
3779
  return handle.success({}, { resolve, reject });
3461
3780
  });
@@ -3494,10 +3813,11 @@ function showToast(options) {
3494
3813
  const res = { errMsg: error.message };
3495
3814
  return callAsyncFail(reject, res, options);
3496
3815
  }
3497
- prompt.showToast({
3816
+ promptAction.showToast({
3498
3817
  message: options.title,
3499
3818
  duration: options.duration,
3500
- bottom: options.bottom
3819
+ bottom: options.bottom,
3820
+ showMode: 1 // 设置弹窗显示模式,显示在应用之上。
3501
3821
  });
3502
3822
  callAsyncSuccess(resolve, resCallback('showToast'), options);
3503
3823
  });
@@ -3527,25 +3847,24 @@ function showModal(options) {
3527
3847
  color: confirmColor
3528
3848
  });
3529
3849
  }
3530
- return new Promise(resolve => {
3850
+ return new Promise((resolve, reject) => {
3531
3851
  const modalOptions = {
3532
3852
  title,
3533
3853
  message: content,
3534
3854
  buttons: buttons,
3535
- success: (data) => {
3536
- if (data.index === 1 || !showCancel) {
3537
- callAsyncSuccess(resolve, Object.assign(Object.assign({}, resCallback('showModal')), { confirm: true, cancel: false, content: null }), options);
3538
- }
3539
- else {
3540
- callAsyncSuccess(resolve, Object.assign(Object.assign({}, resCallback('showModal')), { confirm: false, cancel: true }), options);
3541
- }
3542
- },
3543
- // 鸿蒙没有失败方法,只有取消
3544
- cancel: (_) => {
3855
+ };
3856
+ promptAction.showDialog(modalOptions, (error, data) => {
3857
+ if (error) {
3858
+ const res = { errMsg: error };
3859
+ callAsyncFail(reject, res, options);
3860
+ }
3861
+ if (data.index === 0 && showCancel) {
3545
3862
  callAsyncSuccess(resolve, Object.assign(Object.assign({}, resCallback('showModal')), { confirm: false, cancel: true }), options);
3546
3863
  }
3547
- };
3548
- prompt.showDialog(modalOptions);
3864
+ else {
3865
+ callAsyncSuccess(resolve, Object.assign(Object.assign({}, resCallback('showModal')), { confirm: true, cancel: false, content: null }), options);
3866
+ }
3867
+ });
3549
3868
  });
3550
3869
  }
3551
3870
  const showActionSheetSchema = {
@@ -3576,28 +3895,18 @@ function showActionSheet(options) {
3576
3895
  });
3577
3896
  const actionSheetOptions = {
3578
3897
  title,
3579
- buttons,
3580
- success: (data) => {
3581
- callAsyncSuccess(resolve, Object.assign(Object.assign({}, data), resCallback('showActionSheet')), options);
3582
- },
3583
- // 取消方法,并非失败
3584
- fail: (data) => {
3585
- callAsyncFail(reject, Object.assign(Object.assign({}, data), { errMsg: data.errMsg.replace('showActionMenu', 'showActionSheet') }), options);
3586
- }
3898
+ buttons
3587
3899
  };
3588
- prompt.showActionMenu(actionSheetOptions);
3589
- });
3590
- }
3591
- function hideToast(options) {
3592
- return new Promise(resolve => {
3593
- prompt.showToast({
3594
- message: '关闭中',
3595
- duration: 10,
3596
- bottom: '9999px'
3900
+ promptAction.showActionMenu(actionSheetOptions, (error, data) => {
3901
+ var _a;
3902
+ if (error) {
3903
+ callAsyncFail(reject, Object.assign(Object.assign({}, data), { errMsg: (_a = data.errMsg) === null || _a === void 0 ? void 0 : _a.replace('showActionMenu', 'showActionSheet') }), options);
3904
+ }
3905
+ callAsyncSuccess(resolve, Object.assign(Object.assign({}, data), resCallback('showActionSheet')), options);
3597
3906
  });
3598
- callAsyncSuccess(resolve, resCallback('hideToast'), options);
3599
3907
  });
3600
3908
  }
3909
+ const hideToast = /* @__PURE__ */ temporarilyNotSupport('hideToast');
3601
3910
  const showLoading = temporarilyNotSupport('showLoading');
3602
3911
  const hideLoading = temporarilyNotSupport('hideLoading');
3603
3912
  const enableAlertBeforeUnload = /* @__PURE__ */ temporarilyNotSupport('enableAlertBeforeUnload');
@@ -3610,7 +3919,7 @@ const setNavigationBarTitle = function (options) {
3610
3919
  const { success, fail, complete } = options || {};
3611
3920
  const handle = new MethodHandler({ name: 'setNavigationBarTitle', success, fail, complete });
3612
3921
  return new Promise((resolve, reject) => {
3613
- eventCenter.trigger('__taroNavigationStyle', {
3922
+ eventCenter$1.trigger('__taroNavigationStyle', {
3614
3923
  title: options.title,
3615
3924
  });
3616
3925
  return handle.success({}, { resolve, reject });
@@ -3618,9 +3927,9 @@ const setNavigationBarTitle = function (options) {
3618
3927
  };
3619
3928
  const setNavigationBarColor = function (options) {
3620
3929
  const { success, fail, complete } = options || {};
3621
- const handle = new MethodHandler({ name: 'setNavigationBarTitle', success, fail, complete });
3930
+ const handle = new MethodHandler({ name: 'setNavigationBarColor', success, fail, complete });
3622
3931
  return new Promise((resolve, reject) => {
3623
- eventCenter.trigger('__taroNavigationStyle', {
3932
+ eventCenter$1.trigger('__taroNavigationStyle', {
3624
3933
  animation: options.animation,
3625
3934
  backgroundColor: options.backgroundColor,
3626
3935
  frontColor: options.frontColor,
@@ -3632,7 +3941,7 @@ const showNavigationBarLoading = function (options) {
3632
3941
  const { success, fail, complete } = options || {};
3633
3942
  const handle = new MethodHandler({ name: 'showNavigationBarLoading', success, fail, complete });
3634
3943
  return new Promise((resolve, reject) => {
3635
- eventCenter.trigger('__taroNavigationStyle', {
3944
+ eventCenter$1.trigger('__taroNavigationStyle', {
3636
3945
  loading: true,
3637
3946
  });
3638
3947
  return handle.success({}, { resolve, reject });
@@ -3642,7 +3951,7 @@ const hideNavigationBarLoading = function (options) {
3642
3951
  const { success, fail, complete } = options || {};
3643
3952
  const handle = new MethodHandler({ name: 'hideNavigationBarLoading', success, fail, complete });
3644
3953
  return new Promise((resolve, reject) => {
3645
- eventCenter.trigger('__taroNavigationStyle', {
3954
+ eventCenter$1.trigger('__taroNavigationStyle', {
3646
3955
  loading: false,
3647
3956
  });
3648
3957
  return handle.success({}, { resolve, reject });
@@ -3652,7 +3961,7 @@ const hideHomeButton = function (options) {
3652
3961
  const { success, fail, complete } = options || {};
3653
3962
  const handle = new MethodHandler({ name: 'hideHomeButton', success, fail, complete });
3654
3963
  return new Promise((resolve, reject) => {
3655
- eventCenter.trigger('__taroNavigationStyle', {
3964
+ eventCenter$1.trigger('__taroNavigationStyle', {
3656
3965
  home: false,
3657
3966
  });
3658
3967
  return handle.success({}, { resolve, reject });
@@ -3660,10 +3969,13 @@ const hideHomeButton = function (options) {
3660
3969
  };
3661
3970
 
3662
3971
  const startPullDownRefresh = function (options) {
3663
- return new Promise(resolve => {
3972
+ return new Promise((resolve, reject) => {
3664
3973
  var _a;
3665
3974
  const taro = Current.taro;
3666
3975
  const page = taro.getCurrentInstance().page;
3976
+ if (!page) {
3977
+ return callAsyncFail(reject, { errMsg: 'stopPullDownRefresh:fail' }, options);
3978
+ }
3667
3979
  if (page.isRefreshing instanceof Array) {
3668
3980
  const index = page.tabBarCurrentIndex || 0;
3669
3981
  page.isRefreshing[index] = true;
@@ -3677,10 +3989,13 @@ const startPullDownRefresh = function (options) {
3677
3989
  });
3678
3990
  };
3679
3991
  const stopPullDownRefresh = function (options) {
3680
- return new Promise(resolve => {
3992
+ return new Promise((resolve, reject) => {
3681
3993
  var _a;
3682
3994
  const taro = Current.taro;
3683
3995
  const page = taro.getCurrentInstance().page;
3996
+ if (!page) {
3997
+ return callAsyncFail(reject, { errMsg: 'stopPullDownRefresh:fail' }, options);
3998
+ }
3684
3999
  if (page.isRefreshing instanceof Array) {
3685
4000
  const index = page.tabBarCurrentIndex || 0;
3686
4001
  page.isRefreshing[index] = false;
@@ -3713,8 +4028,8 @@ const pageScrollTo = (options) => {
3713
4028
  const taro = Current.taro;
3714
4029
  const page = taro.getCurrentInstance().page;
3715
4030
  let scrollValue = -1;
3716
- let scroller = page.scroller;
3717
- const currentPageNode = getPageScrollerOrNode(page.node, page);
4031
+ let scroller = getPageScrollerOrNode(page === null || page === void 0 ? void 0 : page.scroller, page);
4032
+ const currentPageNode = getPageScrollerOrNode(page === null || page === void 0 ? void 0 : page.node, page);
3718
4033
  if (scrollTop || typeof scrollTop === 'number') {
3719
4034
  scrollValue = scrollTop;
3720
4035
  }
@@ -3736,15 +4051,15 @@ const pageScrollTo = (options) => {
3736
4051
  scroller = getPageScrollerOrNode(scroller, page);
3737
4052
  const { yOffset } = scroller.currentOffset();
3738
4053
  if (areaInfo) {
3739
- scrollValue = areaInfo.globalPosition.y + yOffset + pxTransformHelper(offsetTop, 'px', true);
4054
+ scrollValue = areaInfo.globalPosition.y + yOffset + pxTransformHelper$1(offsetTop, 'px', true);
3740
4055
  }
3741
4056
  }
3742
- const { xOffset } = scroller.currentOffset();
3743
- if (scrollValue === -1) {
4057
+ if (!scroller || scrollValue === -1) {
3744
4058
  return handle.fail({
3745
4059
  errMsg: '请检查传入的 scrollTop 或 selector 是否合法'
3746
4060
  }, { resolve, reject });
3747
4061
  }
4062
+ const { xOffset } = scroller.currentOffset();
3748
4063
  try {
3749
4064
  scroller.scrollTo({
3750
4065
  xOffset,
@@ -3776,7 +4091,7 @@ const toggleTabBar = function (type) {
3776
4091
  var _a, _b;
3777
4092
  const taro = Current.taro;
3778
4093
  const page = taro.getCurrentInstance().page;
3779
- const currentData = ((_a = page._data) === null || _a === void 0 ? void 0 : _a.taroTabBar) || page.tabBar;
4094
+ 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);
3780
4095
  const res = { errMsg: `${type}TabBar:ok` };
3781
4096
  const error = { errMsg: `${type}TabBar:fail not TabBar page` };
3782
4097
  if (!currentData) {
@@ -3785,7 +4100,7 @@ const toggleTabBar = function (type) {
3785
4100
  else {
3786
4101
  const isShow = type === 'show';
3787
4102
  const event = isShow ? '__taroShowTabBar' : '__taroHideTabBar';
3788
- eventCenter.trigger(event, {
4103
+ eventCenter$1.trigger(event, {
3789
4104
  animation: options === null || options === void 0 ? void 0 : options.animation,
3790
4105
  });
3791
4106
  (_b = page.$set) === null || _b === void 0 ? void 0 : _b.call(page, 'isShowTaroTabBar', isShow);
@@ -3801,7 +4116,7 @@ const setTabBarStyle = function (options = {}) {
3801
4116
  var _a, _b;
3802
4117
  const taro = Current.taro;
3803
4118
  const page = taro.getCurrentInstance().page;
3804
- const currentData = ((_a = page._data) === null || _a === void 0 ? void 0 : _a.taroTabBar) || page.tabBar;
4119
+ 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);
3805
4120
  const res = { errMsg: 'setTabBarStyle:ok' };
3806
4121
  const error = { errMsg: 'setTabBarStyle:fail not TabBar page' };
3807
4122
  if (!currentData) {
@@ -3817,7 +4132,7 @@ const setTabBarStyle = function (options = {}) {
3817
4132
  data.backgroundColor = options.backgroundColor;
3818
4133
  if (options.borderStyle)
3819
4134
  data.borderStyle = options.borderStyle;
3820
- eventCenter.trigger('__taroSetTabBarStyle', options);
4135
+ eventCenter$1.trigger('__taroSetTabBarStyle', options);
3821
4136
  (_b = page.$set) === null || _b === void 0 ? void 0 : _b.call(page, 'taroTabBar', data);
3822
4137
  callAsyncSuccess(resolve, res, options);
3823
4138
  }
@@ -3828,7 +4143,7 @@ const setTabBarItem = function (options) {
3828
4143
  var _a, _b;
3829
4144
  const taro = Current.taro;
3830
4145
  const page = taro.getCurrentInstance().page;
3831
- const currentData = ((_a = page._data) === null || _a === void 0 ? void 0 : _a.taroTabBar) || page.tabBar;
4146
+ 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);
3832
4147
  const res = { errMsg: 'setTabBarItem:ok' };
3833
4148
  const error = { errMsg: 'setTabBarItem:fail not TabBar page' };
3834
4149
  if (!currentData) {
@@ -3849,7 +4164,7 @@ const setTabBarItem = function (options) {
3849
4164
  ...currentData.list.slice(index + 1)
3850
4165
  ];
3851
4166
  const data = Object.assign({}, currentData, { list });
3852
- eventCenter.trigger('__taroSetTabBarItem', options);
4167
+ eventCenter$1.trigger('__taroSetTabBarItem', options);
3853
4168
  (_b = page.$set) === null || _b === void 0 ? void 0 : _b.call(page, 'taroTabBar', data);
3854
4169
  callAsyncSuccess(resolve, res, options);
3855
4170
  }
@@ -3858,7 +4173,7 @@ const setTabBarItem = function (options) {
3858
4173
  function showTabBarRedDot(options) {
3859
4174
  const res = { errMsg: 'showTabBarRedDot:ok' };
3860
4175
  return new Promise((resolve) => {
3861
- eventCenter.trigger('__taroShowTabBarRedDotHandler', {
4176
+ eventCenter$1.trigger('__taroShowTabBarRedDotHandler', {
3862
4177
  index: (options === null || options === void 0 ? void 0 : options.index) || 0,
3863
4178
  });
3864
4179
  callAsyncSuccess(resolve, res, options);
@@ -3867,7 +4182,7 @@ function showTabBarRedDot(options) {
3867
4182
  function hideTabBarRedDot(options) {
3868
4183
  const res = { errMsg: 'hideTabBarRedDot:ok' };
3869
4184
  return new Promise((resolve) => {
3870
- eventCenter.trigger('__taroHideTabBarRedDotHandler', {
4185
+ eventCenter$1.trigger('__taroHideTabBarRedDotHandler', {
3871
4186
  index: (options === null || options === void 0 ? void 0 : options.index) || 0,
3872
4187
  });
3873
4188
  callAsyncSuccess(resolve, res, options);
@@ -3877,7 +4192,7 @@ function setTabBarBadge(options) {
3877
4192
  const res = { errMsg: 'setTabBarBadge:ok' };
3878
4193
  return new Promise((resolve) => {
3879
4194
  const text = (options === null || options === void 0 ? void 0 : options.text) || '';
3880
- eventCenter.trigger('__taroSetTabBarBadge', {
4195
+ eventCenter$1.trigger('__taroSetTabBarBadge', {
3881
4196
  index: (options === null || options === void 0 ? void 0 : options.index) || 0,
3882
4197
  text: text.replace(/[\u0391-\uFFE5]/g, 'aa').length > 4 ? '...' : text,
3883
4198
  });
@@ -3887,7 +4202,7 @@ function setTabBarBadge(options) {
3887
4202
  function removeTabBarBadge(options) {
3888
4203
  const res = { errMsg: 'removeTabBarBadge:ok' };
3889
4204
  return new Promise((resolve) => {
3890
- eventCenter.trigger('__taroRemoveTabBarBadge', {
4205
+ eventCenter$1.trigger('__taroRemoveTabBarBadge', {
3891
4206
  index: (options === null || options === void 0 ? void 0 : options.index) || 0,
3892
4207
  });
3893
4208
  callAsyncSuccess(resolve, res, options);
@@ -3921,19 +4236,16 @@ class IntersectionObserver {
3921
4236
  };
3922
4237
  const taro = Current.taro;
3923
4238
  const page = taro.getCurrentInstance().page;
3924
- const currentPage = getPageScrollerOrNode(page.node, page);
3925
- this._component = component || currentPage;
4239
+ this._component = component || getPageScrollerOrNode(page === null || page === void 0 ? void 0 : page.node, page);
3926
4240
  Object.assign(this._options, options);
3927
4241
  }
3928
4242
  disconnect() {
3929
- var _a;
3930
- if (this._observerNodes) {
4243
+ if (this._observerNodes && this._component) {
3931
4244
  if (this._observerNodes instanceof Array) {
3932
4245
  this._observerNodes.forEach((n) => {
3933
- var _a;
3934
4246
  disconnectEvent(n, VISIBLE_CHANGE_EVENT_NAME);
3935
4247
  // @ts-ignore
3936
- (_a = n._nodeInfo) === null || _a === void 0 ? void 0 : _a.thresholds = null;
4248
+ n._nodeInfo.thresholds = null;
3937
4249
  });
3938
4250
  }
3939
4251
  else {
@@ -3941,35 +4253,40 @@ class IntersectionObserver {
3941
4253
  // @ts-ignore
3942
4254
  if (this._observerNodes._nodeInfo) {
3943
4255
  // @ts-ignore
3944
- (_a = this._observerNodes._nodeInfo) === null || _a === void 0 ? void 0 : _a.thresholds = null;
4256
+ this._observerNodes._nodeInfo.thresholds = null;
3945
4257
  }
3946
4258
  }
3947
4259
  }
3948
4260
  }
3949
4261
  observe(targetSelector, callback) {
3950
- var _a;
4262
+ if (!this._component)
4263
+ return;
3951
4264
  const { observeAll, thresholds } = this._options;
3952
4265
  const node = findChildNodeWithDFS(this._component, targetSelector, observeAll);
3953
4266
  this._observerNodes = node;
3954
4267
  if (node) {
3955
4268
  if (node instanceof Array) {
3956
4269
  node.forEach(n => {
3957
- var _a;
3958
4270
  // @ts-ignore
3959
- (_a = n._nodeInfo) === null || _a === void 0 ? void 0 : _a.thresholds = thresholds;
4271
+ n._nodeInfo.thresholds = thresholds;
3960
4272
  setNodeEventCallbackAndTriggerComponentUpdate(n, VISIBLE_CHANGE_EVENT_NAME, (isVisible, currentRatio) => {
3961
- callback(this.handleResult(isVisible, currentRatio));
4273
+ callback(this.handleResult(isVisible, currentRatio, n));
3962
4274
  });
3963
4275
  });
3964
4276
  }
3965
4277
  else {
3966
4278
  // @ts-ignore
3967
- (_a = node._nodeInfo) === null || _a === void 0 ? void 0 : _a.thresholds = thresholds;
4279
+ node._nodeInfo.thresholds = thresholds;
3968
4280
  setNodeEventCallbackAndTriggerComponentUpdate(node, VISIBLE_CHANGE_EVENT_NAME, (isVisible, currentRatio) => {
3969
- callback(this.handleResult(isVisible, currentRatio));
4281
+ callback(this.handleResult(isVisible, currentRatio, node));
3970
4282
  });
3971
4283
  }
3972
4284
  }
4285
+ else {
4286
+ callback({
4287
+ errMsg: 'IntersectionObserver.observe:fail cannot find the node for selector.'
4288
+ });
4289
+ }
3973
4290
  }
3974
4291
  relativeTo() {
3975
4292
  temporarilyNotSupport('relativeTo')();
@@ -3980,8 +4297,10 @@ class IntersectionObserver {
3980
4297
  return this;
3981
4298
  }
3982
4299
  // @ts-ignore
3983
- handleResult(isVisible, currentRatio) {
4300
+ handleResult(isVisible, currentRatio, node) {
3984
4301
  const result = {
4302
+ id: node.id,
4303
+ dataset: node.dataset,
3985
4304
  intersectionRatio: currentRatio,
3986
4305
  // TODO 未做,等待能拿到element的info信息
3987
4306
  boundingClientRect: {
@@ -4189,32 +4508,45 @@ function filter(fields, dom) {
4189
4508
  }
4190
4509
  function querySelector(selector, selectAll) {
4191
4510
  if (typeof selector === 'string') {
4192
- return parseHandler(selector, selectAll);
4511
+ return selector.split(',').reduce((prev, current) => {
4512
+ const item = current.trim();
4513
+ return prev.concat(parseHandler(item, selectAll));
4514
+ }, []);
4193
4515
  }
4194
- return null;
4516
+ return [];
4195
4517
  }
4196
4518
  function queryBat(queue, cb) {
4197
4519
  const result = [];
4198
4520
  const taro = Current.taro;
4199
4521
  const page = taro.getCurrentInstance().page;
4200
- const element = getPageScrollerOrNode(page.node, page);
4201
- if (element == null)
4522
+ const element = getPageScrollerOrNode(page === null || page === void 0 ? void 0 : page.node, page);
4523
+ if (!element)
4202
4524
  return null;
4203
4525
  arr = [];
4204
4526
  traversalDFSDom(element);
4205
- queue.forEach(item => {
4527
+ queue.forEach((item) => {
4206
4528
  const { selector, single, fields } = item;
4207
- const nodeList = querySelector(selector, !single);
4208
- result.push(nodeList.map(dom => {
4529
+ if (single) {
4530
+ const dom = querySelector(selector, !single)[0];
4209
4531
  // eslint-disable-next-line no-async-promise-executor
4210
- return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
4532
+ result.push(new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
4211
4533
  yield setNodeEventCallbackAndTriggerComponentUpdate(dom, AREA_CHANGE_EVENT_NAME, null, true);
4212
4534
  resolve(filter(fields, dom));
4535
+ })));
4536
+ }
4537
+ else {
4538
+ const nodeList = querySelector(selector, !single);
4539
+ result.push(nodeList.map(dom => {
4540
+ // eslint-disable-next-line no-async-promise-executor
4541
+ return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
4542
+ yield setNodeEventCallbackAndTriggerComponentUpdate(dom, AREA_CHANGE_EVENT_NAME, null, true);
4543
+ resolve(filter(fields, dom));
4544
+ }));
4213
4545
  }));
4214
- }));
4546
+ }
4215
4547
  });
4216
4548
  Promise.all(result.map(item => {
4217
- return Promise.all(item);
4549
+ return item instanceof Array ? Promise.all(item) : item;
4218
4550
  })).then(data => {
4219
4551
  cb(data);
4220
4552
  });
@@ -4366,7 +4698,7 @@ var apis = /*#__PURE__*/Object.freeze({
4366
4698
  disableAlertBeforeUnload: disableAlertBeforeUnload,
4367
4699
  downloadFile: downloadFile,
4368
4700
  enableAlertBeforeUnload: enableAlertBeforeUnload,
4369
- eventCenter: eventCenter,
4701
+ eventCenter: eventCenter$1,
4370
4702
  exitMiniProgram: exitMiniProgram,
4371
4703
  exitVoIPChat: exitVoIPChat,
4372
4704
  faceVerifyForPay: faceVerifyForPay,
@@ -4707,7 +5039,7 @@ const defaultBaseFontSize = 20;
4707
5039
  const defaultUnitPrecision = 5;
4708
5040
  const defaultTargetUnit = 'vp';
4709
5041
  function getApp$1() {
4710
- return Current.app;
5042
+ return Current.app || {};
4711
5043
  }
4712
5044
  function initPxTransform({ designWidth = defaultDesignWidth, deviceRatio = defaultDesignRatio, baseFontSize = defaultBaseFontSize, unitPrecision = defaultUnitPrecision, targetUnit = defaultTargetUnit }) {
4713
5045
  const taro = Current.taro;
@@ -4721,19 +5053,56 @@ function initPxTransform({ designWidth = defaultDesignWidth, deviceRatio = defau
4721
5053
  config.unitPrecision = unitPrecision;
4722
5054
  }
4723
5055
  }
4724
- _display.getDefaultDisplaySync();
5056
+ const display = _display.getDefaultDisplaySync();
5057
+ let displayWidth = display.width;
5058
+ let ratioCache = false;
5059
+ let designWidthFunc;
5060
+ let designWidth = defaultDesignWidth;
5061
+ function getRatio(value) {
5062
+ var _a;
5063
+ // Note: 提前调用 display 可能无法获取正确值
5064
+ if (ratioCache === false || displayWidth !== display.width) {
5065
+ const config = ((_a = Current.taro) === null || _a === void 0 ? void 0 : _a.config) || {};
5066
+ if (!isFunction(designWidthFunc)) {
5067
+ designWidthFunc = isFunction(config.designWidth)
5068
+ ? config.designWidth
5069
+ : () => config.designWidth;
5070
+ designWidth = designWidthFunc(value) || defaultDesignWidth;
5071
+ }
5072
+ displayWidth = display.width;
5073
+ ratioCache = Math.min(display.width, display.height) / designWidth;
5074
+ }
5075
+ return ratioCache;
5076
+ }
5077
+ // Note: 设置为 style 单位时会自动完成设计稿转换,设计开发者调用 API 时也许抹平差异,例如 pageScrollTo[option.offsetTop]
5078
+ function pxTransformHelper(size, unit, isNumber = false) {
5079
+ var _a;
5080
+ const config = ((_a = Current.taro) === null || _a === void 0 ? void 0 : _a.config) || {};
5081
+ const targetUnit = unit || config.targetUnit || defaultTargetUnit;
5082
+ if (targetUnit === 'PX') {
5083
+ return px2vp(size * display.scaledDensity) + 'vp';
5084
+ }
5085
+ const ratio = getRatio(size);
5086
+ let val = size * ratio;
5087
+ switch (targetUnit) {
5088
+ case 'vp':
5089
+ // Note: 在应用创建前调用无效
5090
+ val = px2vp(val);
5091
+ break;
5092
+ }
5093
+ return isNumber ? val : val + targetUnit;
5094
+ }
4725
5095
  function pxTransform(size) {
4726
5096
  var _a;
4727
5097
  const config = ((_a = Current.taro) === null || _a === void 0 ? void 0 : _a.config) || {};
4728
5098
  const targetUnit = config.targetUnit || defaultTargetUnit;
4729
- let val = size;
5099
+ const val = size;
4730
5100
  switch (targetUnit) {
4731
5101
  case 'vp':
4732
- val = px2vp(size);
4733
- break;
5102
+ return pxTransformHelper(size, 'px');
4734
5103
  // NOTE: 鸿蒙环境下 style 会自动完成设计稿转换,无需在方法内二次调整
4735
5104
  }
4736
- return val + config.targetUnit;
5105
+ return val + targetUnit;
4737
5106
  }
4738
5107
  function canIUseWebp() {
4739
5108
  return true;