@tarojs/plugin-platform-harmony-ets 4.0.0-beta.4 → 4.0.0-beta.41

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 (107) hide show
  1. package/dist/apis/base/system.ts +53 -20
  2. package/dist/apis/canvas/index.ts +10 -1
  3. package/dist/apis/framework/index.ts +1 -5
  4. package/dist/apis/index.ts +32 -17
  5. package/dist/apis/network/request.ts +5 -5
  6. package/dist/apis/route/index.ts +15 -0
  7. package/dist/apis/storage/index.ts +126 -68
  8. package/dist/apis/ui/animation/animation.ts +2 -1
  9. package/dist/apis/utils/index.ts +1 -1
  10. package/dist/apis/wxml/IntersectionObserver.ts +18 -10
  11. package/dist/apis/wxml/index.ts +2 -0
  12. package/dist/apis/wxml/selectorQuery.ts +18 -9
  13. package/dist/components-harmony-ets/button.ets +48 -34
  14. package/dist/components-harmony-ets/canvas.ets +51 -0
  15. package/dist/components-harmony-ets/checkbox.ets +69 -61
  16. package/dist/components-harmony-ets/form.ets +51 -29
  17. package/dist/components-harmony-ets/icon.ets +34 -19
  18. package/dist/components-harmony-ets/image.ets +27 -14
  19. package/dist/components-harmony-ets/index.ets +76 -0
  20. package/dist/components-harmony-ets/innerHtml.ets +11 -6
  21. package/dist/components-harmony-ets/input.ets +41 -40
  22. package/dist/components-harmony-ets/label.ets +71 -42
  23. package/dist/components-harmony-ets/movableArea.ets +126 -0
  24. package/dist/components-harmony-ets/movableView.ets +73 -0
  25. package/dist/components-harmony-ets/picker.ets +42 -38
  26. package/dist/components-harmony-ets/progress.ets +52 -0
  27. package/dist/components-harmony-ets/pseudo.ets +80 -0
  28. package/dist/components-harmony-ets/radio.ets +71 -64
  29. package/dist/components-harmony-ets/richText.ets +14 -30
  30. package/dist/components-harmony-ets/scrollView.ets +64 -30
  31. package/dist/components-harmony-ets/slider.ets +15 -14
  32. package/dist/components-harmony-ets/style.ets +346 -130
  33. package/dist/components-harmony-ets/swiper.ets +38 -20
  34. package/dist/components-harmony-ets/switch.ets +30 -28
  35. package/dist/components-harmony-ets/text.ets +121 -51
  36. package/dist/components-harmony-ets/textArea.ets +35 -34
  37. package/dist/components-harmony-ets/utils/AttributeManager.ets +1 -1
  38. package/dist/components-harmony-ets/utils/DynamicCenter.ts +1 -1
  39. package/dist/components-harmony-ets/utils/flexManager.ets +43 -19
  40. package/dist/components-harmony-ets/utils/helper.ets +4 -5
  41. package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
  42. package/dist/components-harmony-ets/utils/htmlParser/index.ts +1 -1
  43. package/dist/components-harmony-ets/utils/index.ts +50 -51
  44. package/dist/components-harmony-ets/utils/styles.ets +164 -92
  45. package/dist/components-harmony-ets/video.ets +34 -20
  46. package/dist/components-harmony-ets/view.ets +62 -29
  47. package/dist/components-harmony-ets/webView.ets +40 -34
  48. package/dist/index.d.ts +152 -0
  49. package/dist/index.js +74 -37
  50. package/dist/index.js.map +1 -1
  51. package/dist/runtime-ets/bom/document.ts +1 -1
  52. package/dist/runtime-ets/bom/getComputedStyle.ts +2 -2
  53. package/dist/runtime-ets/bom/window.ts +7 -0
  54. package/dist/runtime-ets/current.ts +3 -0
  55. package/dist/runtime-ets/dom/bind.ts +20 -6
  56. package/dist/runtime-ets/dom/cssNesting.ts +393 -0
  57. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +12 -40
  58. package/dist/runtime-ets/dom/document.ts +23 -8
  59. package/dist/runtime-ets/dom/element/canvas.ts +136 -0
  60. package/dist/runtime-ets/dom/element/element.ts +218 -51
  61. package/dist/runtime-ets/dom/element/form.ts +15 -18
  62. package/dist/runtime-ets/dom/element/index.ts +18 -2
  63. package/dist/runtime-ets/dom/element/movableArea.ts +12 -0
  64. package/dist/runtime-ets/dom/element/movableView.ts +193 -0
  65. package/dist/runtime-ets/dom/element/normal.ts +13 -4
  66. package/dist/runtime-ets/dom/element/progress.ts +12 -0
  67. package/dist/runtime-ets/dom/element/scrollView.ts +1 -0
  68. package/dist/runtime-ets/dom/element/text.ts +1 -8
  69. package/dist/runtime-ets/dom/element/video.ts +5 -3
  70. package/dist/runtime-ets/dom/element/webView.ts +8 -0
  71. package/dist/runtime-ets/dom/event.ts +0 -1
  72. package/dist/runtime-ets/dom/eventTarget.ts +0 -3
  73. package/dist/runtime-ets/dom/node.ts +45 -27
  74. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +330 -230
  75. package/dist/runtime-ets/dom/stylesheet/index.ts +28 -308
  76. package/dist/runtime-ets/dom/stylesheet/type.ts +28 -9
  77. package/dist/runtime-ets/dom/stylesheet/util.ts +33 -27
  78. package/dist/runtime-ets/index.ts +2 -2
  79. package/dist/runtime-ets/interface/event.ts +1 -1
  80. package/dist/runtime-ets/utils/index.ts +43 -10
  81. package/dist/runtime-ets/utils/info.ts +1 -1
  82. package/dist/runtime-framework/react/app.ts +7 -2
  83. package/dist/runtime-framework/react/index.ts +0 -2
  84. package/dist/runtime-framework/react/native-page.ts +22 -12
  85. package/dist/runtime-framework/react/page.ts +3 -8
  86. package/dist/runtime-framework/solid/app.ts +25 -45
  87. package/dist/runtime-framework/solid/connect.ts +21 -3
  88. package/dist/runtime-framework/solid/hooks.ts +16 -11
  89. package/dist/runtime-framework/solid/index.ts +6 -2
  90. package/dist/runtime-framework/solid/page.ts +84 -30
  91. package/dist/runtime-framework/solid/reconciler/props.ts +65 -20
  92. package/dist/runtime-framework/solid/reconciler/render.ts +16 -6
  93. package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
  94. package/dist/runtime-framework/solid/utils/index.ts +0 -2
  95. package/dist/runtime-utils.d.ts +827 -0
  96. package/dist/runtime-utils.js +284 -126
  97. package/dist/runtime-utils.js.map +1 -1
  98. package/dist/runtime.d.ts +1 -0
  99. package/dist/runtime.js +284 -126
  100. package/dist/runtime.js.map +1 -1
  101. package/index.js +3 -1
  102. package/package.json +13 -13
  103. package/types/harmony.d.ts +4 -0
  104. package/types/index.d.ts +4 -0
  105. package/dist/runtime-ets/utils/bind.ts +0 -24
  106. /package/dist/components-harmony-ets/{index.ts → tag.ts} +0 -0
  107. /package/dist/runtime-framework/solid/{contant.ts → constant.ts} +0 -0
@@ -0,0 +1 @@
1
+ export {};
package/dist/runtime.js CHANGED
@@ -1,10 +1,10 @@
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';
3
+ import { Current, window, eventSource, hooks, document as document$1, getPageScrollerOrNode, findChildNodeWithDFS, setNodeEventCallbackAndTriggerComponentUpdate, AREA_CHANGE_EVENT_NAME, disconnectEvent, VISIBLE_CHANGE_EVENT_NAME, getCurrentInstance } from '@tarojs/runtime';
4
4
  import { eventCenter, Events, History } from '@tarojs/runtime/dist/runtime.esm';
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
9
  import sensor from '@ohos.sensor';
10
10
  import batteryInfo, { BatteryChargeState } from '@ohos.batteryInfo';
@@ -28,11 +28,10 @@ import http from '@ohos.net.http';
28
28
  import webSocket from '@ohos.net.webSocket';
29
29
  import router from '@ohos.router';
30
30
  import bundleManager from '@ohos.bundle.bundleManager';
31
- import dataPreferences from '@ohos.data.preferences';
32
- import hilog from '@ohos.hilog';
31
+ import distributedKVStore from '@ohos.data.distributedKVStore';
33
32
  import matrix4 from '@ohos.matrix4';
34
33
  import prompt from '@ohos.prompt';
35
- import { pxTransformHelper } from '@tarojs/taro';
34
+ import { pxTransformHelper as pxTransformHelper$1 } from '@tarojs/taro';
36
35
 
37
36
  class MethodHandler {
38
37
  constructor({ name, success, fail, complete }) {
@@ -186,7 +185,7 @@ function temporarilyNotSupport(name, recommended) {
186
185
  return (option = {}, ...args) => {
187
186
  const { success, fail, complete } = option;
188
187
  const handle = new MethodHandler({ name, success, fail, complete });
189
- let errMsg = '暂时不支持 API';
188
+ let errMsg = `暂时不支持 API ${name}`;
190
189
  if (recommended) {
191
190
  errMsg += `, 请使用 ${recommended}`;
192
191
  }
@@ -266,16 +265,49 @@ const preloadWebview = /* @__PURE__ */ temporarilyNotSupport('preloadWebview');
266
265
  const preloadSkylineView = /* @__PURE__ */ temporarilyNotSupport('preloadSkylineView');
267
266
  const preloadAssets = /* @__PURE__ */ temporarilyNotSupport('preloadAssets');
268
267
 
269
- // 设备信息,从 API Version 6 开始支持
270
- const display = _display.getDefaultDisplaySync();
271
- let device;
272
- deviceMethod.getInfo({
273
- success: data => {
274
- device = data;
275
- }
268
+ let display$1;
269
+ let navigationIndicatorRect;
270
+ let safeArea = null;
271
+ let statusBarHeight;
272
+ let windowRect;
273
+ Current.contextPromise.then((context) => {
274
+ const win = window.__ohos.getLastWindow(context);
275
+ win.then(mainWindow => {
276
+ const topRect = mainWindow.getWindowAvoidArea(window.__ohos.AvoidAreaType.TYPE_SYSTEM).topRect;
277
+ navigationIndicatorRect = mainWindow.getWindowAvoidArea(window.__ohos.AvoidAreaType.TYPE_NAVIGATION_INDICATOR).bottomRect;
278
+ statusBarHeight = topRect.top + topRect.height;
279
+ windowRect = mainWindow.getWindowProperties().windowRect;
280
+ try {
281
+ display$1 = _display.getDefaultDisplaySync();
282
+ // @ts-ignore
283
+ display$1.getCutoutInfo((err, { boundingRects = [], waterfallDisplayAreaRects = {} } = {}) => {
284
+ var _a, _b, _c, _d, _e, _f;
285
+ if (err === null || err === void 0 ? void 0 : err.code) {
286
+ console.error('Failed to get cutout info', JSON.stringify(err));
287
+ return;
288
+ }
289
+ 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);
290
+ const bottom = display$1.height - Math.min((_c = waterfallDisplayAreaRects.bottom) === null || _c === void 0 ? void 0 : _c.top, navigationIndicatorRect === null || navigationIndicatorRect === void 0 ? void 0 : navigationIndicatorRect.top);
291
+ const left = ((_d = waterfallDisplayAreaRects.left) === null || _d === void 0 ? void 0 : _d.left) + ((_e = waterfallDisplayAreaRects.left) === null || _e === void 0 ? void 0 : _e.width);
292
+ const right = display$1.width - ((_f = waterfallDisplayAreaRects.right) === null || _f === void 0 ? void 0 : _f.left);
293
+ safeArea = {
294
+ top,
295
+ bottom,
296
+ left,
297
+ right,
298
+ height: bottom - top,
299
+ width: right - left,
300
+ };
301
+ });
302
+ }
303
+ catch (e) {
304
+ console.error('Failed to get display', e);
305
+ }
306
+ });
276
307
  });
277
308
  /* 同步版本 */
278
309
  const getSystemInfoSync = function () {
310
+ var _a, _b;
279
311
  const res = {};
280
312
  res.SDKVersion = deviceInfo && deviceInfo.sdkApiVersion; // 客户端基础库版本 string
281
313
  res.albumAuthorized = false; // 允许使用相册的开关(仅 iOS 有效) boolean
@@ -285,7 +317,7 @@ const getSystemInfoSync = function () {
285
317
  res.cameraAuthorized = null; // 允许使用摄像头的开关 boolean
286
318
  res.enableDebug = null; // 是否已打开调试 boolean
287
319
  res.fontSizeSetting = null; // 用户字体大小(单位px) number
288
- res.language = i18n && i18n.getSystemLanguage && i18n.getSystemLanguage(); // string
320
+ res.language = (_a = i18n === null || i18n === void 0 ? void 0 : i18n.getSystemLanguage) === null || _a === void 0 ? void 0 : _a.call(i18n); // string
289
321
  res.locationAuthorized = null; // 定位的开关 boolean
290
322
  res.locationEnabled = null; // 地理位置的系统开关 boolean
291
323
  res.microphoneAuthorized = null; // 麦克风的开关 boolean
@@ -296,17 +328,18 @@ const getSystemInfoSync = function () {
296
328
  res.notificationSoundAuthorized = false; // 通知带有声音的开关(仅 iOS 有效)boolean
297
329
  res.phoneCalendarAuthorized = null; // 使用日历的开关 boolean
298
330
  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
331
+ res.pixelRatio = display$1 && display$1.densityPixels; // 设备像素比,number
332
+ res.platform = 'harmony'; // 客户端平台 string
333
+ res.safeArea = safeArea; // 在竖屏正方向下的安全区域 General.SafeAreaResult
334
+ res.screenHeight = display$1 === null || display$1 === void 0 ? void 0 : display$1.height; // 屏幕高度,单位px number
335
+ res.screenWidth = display$1 === null || display$1 === void 0 ? void 0 : display$1.width; // 屏幕宽度,单位px number
336
+ res.statusBarHeight = statusBarHeight; // 状态栏的高度,单位px number
337
+ res.system = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.osFullName; // 操作系统及版本 string
338
+ // Note: 更新配置时才能记录
339
+ 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'
340
+ res.windowHeight = windowRect === null || windowRect === void 0 ? void 0 : windowRect.height; // 可使用窗口高度,单位px number
341
+ res.windowWidth = windowRect === null || windowRect === void 0 ? void 0 : windowRect.width; // 可使用窗口宽度,单位px number
342
+ res.version = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.displayVersion; // 版本号 string
310
343
  return res;
311
344
  };
312
345
  /* 异步版本 */
@@ -412,7 +445,13 @@ const base64ToArrayBuffer = /* @__PURE__ */ temporarilyNotSupport('base64ToArray
412
445
  /** 创建离屏 canvas 实例 */
413
446
  const createOffscreenCanvas = /* @__PURE__ */ temporarilyNotSupport('createOffscreenCanvas');
414
447
  /** 创建 canvas 的绘图上下文 CanvasContext 对象 */
415
- const createCanvasContext = /* @__PURE__ */ temporarilyNotSupport('createOffscreenCanvas');
448
+
449
+ const createCanvasContext = (canvasId) => {
450
+ const dom = eventSource.get(`canvasId-${canvasId}`);
451
+ // return dom as TaroCanvasElement
452
+ if (dom)
453
+ return dom.context;
454
+ };
416
455
  /** 把当前画布指定区域的内容导出生成指定大小的图片 */
417
456
  const canvasToTempFilePath = /* @__PURE__ */ temporarilyNotSupport('createOffscreenCanvas');
418
457
  /** 将像素数据绘制到画布 */
@@ -1984,7 +2023,6 @@ function getEnv() {
1984
2023
  }
1985
2024
  // TODO
1986
2025
  const getCurrentPages = () => [];
1987
- const getCurrentInstance = () => Current;
1988
2026
  const requirePlugin$1 = temporarilyNotSupport('requirePlugin');
1989
2027
 
1990
2028
  // @ts-nocheck
@@ -2611,10 +2649,10 @@ const request = function (options) {
2611
2649
  header['Content-Type'] = 'application/json';
2612
2650
  }
2613
2651
  // 检查 Header 是否有 Referer
2614
- if (isUndefined(header.Referer)) {
2615
- const error = { errMsg: 'request fail parameter error: the header doesn‘t support Referer property' };
2616
- callAsyncFail(reject, error, options);
2617
- }
2652
+ // if (isUndefined(header.Referer)) {
2653
+ // const error = { errMsg: 'request fail parameter error: the header doesn‘t support Referer property' }
2654
+ // callAsyncFail(reject, error, options)
2655
+ // }
2618
2656
  // 检查 method 是否正确
2619
2657
  if (method) {
2620
2658
  if (!METHOD.includes(method)) {
@@ -3060,6 +3098,19 @@ function parseURL(raw = '') {
3060
3098
  const [urlStr, queryStr = ''] = raw.split('?');
3061
3099
  const query = queryToJson(queryStr);
3062
3100
  let url = urlStr.replace(/^\//, '');
3101
+ // 处理相对路径
3102
+ if (url.indexOf('.') === 0) {
3103
+ const page = router.getState();
3104
+ const parts = page.path.split('/');
3105
+ parts.pop();
3106
+ url.split('/').forEach((item) => {
3107
+ if (item === '.') {
3108
+ return;
3109
+ }
3110
+ item === '..' ? parts.pop() : parts.push(item);
3111
+ });
3112
+ url = parts.join('/');
3113
+ }
3063
3114
  if (isTabPage(url)) {
3064
3115
  query.$page = url;
3065
3116
  url = TARO_TABBAR_PAGE_PATH;
@@ -3177,113 +3228,162 @@ const getBackgroundFetchData = /* @__PURE__ */ temporarilyNotSupport('getBackgro
3177
3228
  // 周期性更新
3178
3229
  const createCacheManager = /* @__PURE__ */ temporarilyNotSupport('createCacheManager');
3179
3230
 
3180
- const preferencesPromise = Current.contextPromise
3181
- .then((context) => {
3182
- return bundleManager
3183
- .getBundleInfoForSelf(bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION)
3184
- .then(data => {
3185
- return dataPreferences
3186
- .getPreferences(context, `${data.appInfo.uid}Store`);
3187
- });
3188
- })
3189
- .catch((error) => {
3190
- hilog.error(0x0000, 'TaroFailedTag', 'Failed to load the storage. Cause: %{public}s', error.code ? JSON.stringify(error) : error.message || error);
3231
+ /**
3232
+ * 从API Version 6开始,该模块不再维护,可以使用模块@ohos.data.storage。在API Version 9后,推荐使用新模块@ohos.data.preferences。
3233
+ * https://developer.harmonyos.com/cn/docs/documentation/doc-references-V3/js-apis-data-preferences-0000001427745052-V3
3234
+ */
3235
+ let context;
3236
+ let kvManager;
3237
+ let kvStore;
3238
+ Current.contextPromise.then((ctx) => {
3239
+ context = ctx;
3240
+ const kvManagerConfig = {
3241
+ context: context,
3242
+ bundleName: 'com.example.taro'
3243
+ };
3244
+ try {
3245
+ // 创建KVManager实例
3246
+ kvManager = distributedKVStore.createKVManager(kvManagerConfig);
3247
+ // 继续创建获取数据库
3248
+ const options = {
3249
+ createIfMissing: true,
3250
+ encrypt: false,
3251
+ backup: false,
3252
+ autoSync: false,
3253
+ // kvStoreType不填时,默认创建多设备协同数据库
3254
+ kvStoreType: distributedKVStore.KVStoreType.SINGLE_VERSION,
3255
+ // 多设备协同数据库:kvStoreType: distributedKVStore.KVStoreType.DEVICE_COLLABORATION,
3256
+ securityLevel: distributedKVStore.SecurityLevel.S1
3257
+ };
3258
+ const data = bundleManager.getBundleInfoForSelfSync(bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION);
3259
+ kvManager.getKVStore(`${data.appInfo.uid}Store`, options, (err, store) => {
3260
+ if (err) {
3261
+ console.error(`Failed to get KVStore: Code:${err.code},message:${err.message}`);
3262
+ return;
3263
+ }
3264
+ kvStore = store;
3265
+ // 请确保获取到键值数据库实例后,再进行相关数据操作
3266
+ });
3267
+ }
3268
+ catch (e) {
3269
+ console.error(`Failed to create KVManager. Code:${e.code},message:${e.message}`);
3270
+ }
3271
+ return context;
3191
3272
  });
3192
- function getItem(key) {
3193
- return __awaiter(this, void 0, void 0, function* () {
3194
- try {
3195
- const preferences = yield preferencesPromise;
3196
- const item = yield preferences.get(key, null);
3197
- return { result: true, data: item };
3198
- }
3199
- catch (error) {
3200
- return { result: false };
3201
- }
3202
- });
3203
- }
3204
3273
  const storageSchema = {
3205
3274
  key: 'String'
3206
3275
  };
3276
+ function checkContextExist(api, isAsync = false) {
3277
+ if (!context || !kvStore) {
3278
+ const message = `${api} 调用失败,Taro 不支持过早地调用 ${api},请确保页面已经渲染完成再调用此 API`;
3279
+ if (isAsync) {
3280
+ return {
3281
+ isExist: false,
3282
+ error: Promise.reject(new Error(message))
3283
+ };
3284
+ }
3285
+ else {
3286
+ console.warn(message);
3287
+ return {
3288
+ isExist: false,
3289
+ };
3290
+ }
3291
+ }
3292
+ return {
3293
+ isExist: true,
3294
+ };
3295
+ }
3207
3296
  function getStorage(options) {
3297
+ const name = 'getStorage';
3298
+ const { isExist, error } = checkContextExist(name, true);
3299
+ if (!isExist) {
3300
+ return error;
3301
+ }
3302
+ const { key, success, fail, complete } = options || {};
3303
+ const handle = new MethodHandler({ name, success, fail, complete });
3208
3304
  return new Promise((resolve, reject) => {
3209
3305
  try {
3210
- validateParams('getStorage', options, storageSchema);
3306
+ validateParams(name, options, storageSchema);
3211
3307
  }
3212
3308
  catch (error) {
3213
3309
  const res = { errMsg: error.message };
3214
- return callAsyncFail(reject, res, options);
3310
+ return handle.fail(res, { resolve, reject });
3215
3311
  }
3216
- getItem(options.key).then(({ result, data }) => {
3217
- const res = { errMsg: 'getStorage:ok' };
3218
- if (result) {
3219
- res.data = data;
3220
- callAsyncSuccess(resolve, res, options);
3221
- }
3222
- else {
3223
- res.errMsg = 'getStorage:fail data not found';
3224
- callAsyncFail(reject, res, options);
3312
+ kvStore = kvStore;
3313
+ kvStore.get(key, (err, data) => {
3314
+ if (!err) {
3315
+ handle.fail({ errMsg: `Failed to get data. Code:${err.code},message:${err.message}` }, { resolve, reject });
3316
+ return;
3225
3317
  }
3318
+ handle.success({ data }, { resolve, reject });
3226
3319
  });
3227
3320
  });
3228
3321
  }
3229
3322
  function setStorage(options) {
3323
+ const name = 'setStorage';
3324
+ const { isExist, error } = checkContextExist(name, true);
3325
+ if (!isExist) {
3326
+ return error;
3327
+ }
3328
+ const { key, data, success, fail, complete } = options || {};
3329
+ const handle = new MethodHandler({ name, success, fail, complete });
3230
3330
  return new Promise((resolve, reject) => {
3231
3331
  try {
3232
- validateParams('setStorage', options, storageSchema);
3332
+ validateParams(name, options, storageSchema);
3233
3333
  }
3234
3334
  catch (error) {
3235
3335
  const res = { errMsg: error.message };
3236
- return callAsyncFail(reject, res, options);
3336
+ return handle.fail(res, { resolve, reject });
3237
3337
  }
3238
- const { key, data } = options;
3239
- const res = { errMsg: 'setStorage:ok' };
3240
- preferencesPromise.then((preferences) => __awaiter(this, void 0, void 0, function* () {
3241
- yield preferences.put(key, data);
3242
- yield preferences.flush();
3243
- callAsyncSuccess(resolve, res, options);
3244
- }));
3338
+ kvStore = kvStore;
3339
+ kvStore.put(key, data, (err) => {
3340
+ if (!err) {
3341
+ handle.fail({ errMsg: `Failed to put data. Code:${err.code},message:${err.message}` }, { resolve, reject });
3342
+ return;
3343
+ }
3344
+ handle.success({}, { resolve, reject });
3345
+ });
3245
3346
  });
3246
3347
  }
3247
3348
  function removeStorage(options) {
3349
+ const name = 'removeStorage';
3350
+ const { isExist, error } = checkContextExist(name, true);
3351
+ if (!isExist) {
3352
+ return error;
3353
+ }
3354
+ const { key, success, fail, complete } = options || {};
3355
+ const handle = new MethodHandler({ name, success, fail, complete });
3248
3356
  return new Promise((resolve, reject) => {
3249
3357
  try {
3250
- validateParams('removeStorage', options, storageSchema);
3358
+ validateParams(name, options, storageSchema);
3251
3359
  }
3252
3360
  catch (error) {
3253
3361
  const res = { errMsg: error.message };
3254
- return callAsyncFail(reject, res, options);
3362
+ return handle.fail(res, { resolve, reject });
3255
3363
  }
3256
- const { key } = options;
3257
- preferencesPromise.then((preferences) => __awaiter(this, void 0, void 0, function* () {
3258
- yield preferences.delete(key);
3259
- yield preferences.flush();
3260
- const res = { errMsg: 'removeStorage:ok' };
3261
- callAsyncSuccess(resolve, res, options);
3262
- }));
3263
- });
3264
- }
3265
- function clearStorage(options) {
3266
- return new Promise(resolve => {
3267
- preferencesPromise.then((preferences) => __awaiter(this, void 0, void 0, function* () {
3268
- yield preferences.clear();
3269
- yield preferences.flush();
3270
- const res = { errMsg: 'clearStorage:ok' };
3271
- callAsyncSuccess(resolve, res, options);
3272
- }));
3364
+ kvStore = kvStore;
3365
+ kvStore.delete(key, (err) => {
3366
+ if (!err) {
3367
+ handle.fail({ errMsg: `Failed to delete data. Code:${err.code},message:${err.message}` }, { resolve, reject });
3368
+ return;
3369
+ }
3370
+ handle.success({}, { resolve, reject });
3371
+ });
3273
3372
  });
3274
3373
  }
3275
3374
  const getStorageInfoSync = temporarilyNotSupport('getStorageInfoSync');
3276
3375
  const getStorageInfo = temporarilyNotSupport('getStorageInfo');
3277
- const getStorageSync = temporarilyNotSupport('getStorageSync', 'getStorage');
3278
- const setStorageSync = temporarilyNotSupport('setStorageSync', 'setStorage');
3279
- const clearStorageSync = temporarilyNotSupport('clearStorageSync', 'clearStorage');
3280
- const removeStorageSync = temporarilyNotSupport('removeStorageSync', 'removeStorage');
3281
3376
  const createBufferURL = /* @__PURE__ */ temporarilyNotSupport('createBufferURL');
3282
3377
  const revokeBufferURL = /* @__PURE__ */ temporarilyNotSupport('revokeBufferURL');
3283
3378
  const batchSetStorageSync = /* @__PURE__ */ temporarilyNotSupport('batchSetStorageSync');
3284
3379
  const batchSetStorage = /* @__PURE__ */ temporarilyNotSupport('batchSetStorage');
3285
3380
  const batchGetStorageSync = /* @__PURE__ */ temporarilyNotSupport('batchGetStorageSync');
3286
3381
  const batchGetStorage = /* @__PURE__ */ temporarilyNotSupport('batchGetStorage');
3382
+ const clearStorage = temporarilyNotSupport('removeStorageSync');
3383
+ const getStorageSync = temporarilyNotSupport('getStorageSync', 'getStorage');
3384
+ const setStorageSync = temporarilyNotSupport('setStorageSync', 'setStorage');
3385
+ const clearStorageSync = temporarilyNotSupport('clearStorageSync', 'clearStorage');
3386
+ const removeStorageSync = temporarilyNotSupport('removeStorageSync', 'removeStorage');
3287
3387
 
3288
3388
  class Animation {
3289
3389
  constructor({ duration = 400, delay = 0, timingFunction = 'linear', transformOrigin = '50% 50% 0', unit = 'px' } = {}) {
@@ -3347,7 +3447,7 @@ class Animation {
3347
3447
  return this;
3348
3448
  }
3349
3449
  scale(sx, sy) {
3350
- this.rule.scale = { x: sx, y: sy };
3450
+ this.rule.scale = { x: sx, y: isUndefined(sy) ? sx : sy };
3351
3451
  return this;
3352
3452
  }
3353
3453
  scale3d(sx, sy, sz) {
@@ -3723,7 +3823,7 @@ const pageScrollTo = (options) => {
3723
3823
  scroller = getPageScrollerOrNode(scroller, page);
3724
3824
  const { yOffset } = scroller.currentOffset();
3725
3825
  if (areaInfo) {
3726
- scrollValue = areaInfo.globalPosition.y + yOffset + pxTransformHelper(offsetTop, 'px', true);
3826
+ scrollValue = areaInfo.globalPosition.y + yOffset + pxTransformHelper$1(offsetTop, 'px', true);
3727
3827
  }
3728
3828
  }
3729
3829
  const { xOffset } = scroller.currentOffset();
@@ -3908,19 +4008,16 @@ class IntersectionObserver {
3908
4008
  };
3909
4009
  const taro = Current.taro;
3910
4010
  const page = taro.getCurrentInstance().page;
3911
- const currentPage = getPageScrollerOrNode(page.node, page);
3912
- this._component = component || currentPage;
4011
+ this._component = component || getPageScrollerOrNode(page === null || page === void 0 ? void 0 : page.node, page);
3913
4012
  Object.assign(this._options, options);
3914
4013
  }
3915
4014
  disconnect() {
3916
- var _a;
3917
- if (this._observerNodes) {
4015
+ if (this._observerNodes && this._component) {
3918
4016
  if (this._observerNodes instanceof Array) {
3919
4017
  this._observerNodes.forEach((n) => {
3920
- var _a;
3921
4018
  disconnectEvent(n, VISIBLE_CHANGE_EVENT_NAME);
3922
4019
  // @ts-ignore
3923
- (_a = n._nodeInfo) === null || _a === void 0 ? void 0 : _a.thresholds = null;
4020
+ n._nodeInfo.thresholds = null;
3924
4021
  });
3925
4022
  }
3926
4023
  else {
@@ -3928,35 +4025,40 @@ class IntersectionObserver {
3928
4025
  // @ts-ignore
3929
4026
  if (this._observerNodes._nodeInfo) {
3930
4027
  // @ts-ignore
3931
- (_a = this._observerNodes._nodeInfo) === null || _a === void 0 ? void 0 : _a.thresholds = null;
4028
+ this._observerNodes._nodeInfo.thresholds = null;
3932
4029
  }
3933
4030
  }
3934
4031
  }
3935
4032
  }
3936
4033
  observe(targetSelector, callback) {
3937
- var _a;
4034
+ if (!this._component)
4035
+ return;
3938
4036
  const { observeAll, thresholds } = this._options;
3939
4037
  const node = findChildNodeWithDFS(this._component, targetSelector, observeAll);
3940
4038
  this._observerNodes = node;
3941
4039
  if (node) {
3942
4040
  if (node instanceof Array) {
3943
4041
  node.forEach(n => {
3944
- var _a;
3945
4042
  // @ts-ignore
3946
- (_a = n._nodeInfo) === null || _a === void 0 ? void 0 : _a.thresholds = thresholds;
4043
+ n._nodeInfo.thresholds = thresholds;
3947
4044
  setNodeEventCallbackAndTriggerComponentUpdate(n, VISIBLE_CHANGE_EVENT_NAME, (isVisible, currentRatio) => {
3948
- callback(this.handleResult(isVisible, currentRatio));
4045
+ callback(this.handleResult(isVisible, currentRatio, n));
3949
4046
  });
3950
4047
  });
3951
4048
  }
3952
4049
  else {
3953
4050
  // @ts-ignore
3954
- (_a = node._nodeInfo) === null || _a === void 0 ? void 0 : _a.thresholds = thresholds;
4051
+ node._nodeInfo.thresholds = thresholds;
3955
4052
  setNodeEventCallbackAndTriggerComponentUpdate(node, VISIBLE_CHANGE_EVENT_NAME, (isVisible, currentRatio) => {
3956
- callback(this.handleResult(isVisible, currentRatio));
4053
+ callback(this.handleResult(isVisible, currentRatio, node));
3957
4054
  });
3958
4055
  }
3959
4056
  }
4057
+ else {
4058
+ callback({
4059
+ errMsg: 'IntersectionObserver.observe:fail cannot find the node for selector.'
4060
+ });
4061
+ }
3960
4062
  }
3961
4063
  relativeTo() {
3962
4064
  temporarilyNotSupport('relativeTo')();
@@ -3967,8 +4069,10 @@ class IntersectionObserver {
3967
4069
  return this;
3968
4070
  }
3969
4071
  // @ts-ignore
3970
- handleResult(isVisible, currentRatio) {
4072
+ handleResult(isVisible, currentRatio, node) {
3971
4073
  const result = {
4074
+ id: node.id,
4075
+ dataset: node.dataset,
3972
4076
  intersectionRatio: currentRatio,
3973
4077
  // TODO 未做,等待能拿到element的info信息
3974
4078
  boundingClientRect: {
@@ -4189,19 +4293,29 @@ function queryBat(queue, cb) {
4189
4293
  return null;
4190
4294
  arr = [];
4191
4295
  traversalDFSDom(element);
4192
- queue.forEach(item => {
4296
+ queue.forEach((item) => {
4193
4297
  const { selector, single, fields } = item;
4194
- const nodeList = querySelector(selector, !single);
4195
- result.push(nodeList.map(dom => {
4298
+ if (single) {
4299
+ const dom = querySelector(selector, !single)[0];
4196
4300
  // eslint-disable-next-line no-async-promise-executor
4197
- return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
4301
+ result.push(new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
4198
4302
  yield setNodeEventCallbackAndTriggerComponentUpdate(dom, AREA_CHANGE_EVENT_NAME, null, true);
4199
4303
  resolve(filter(fields, dom));
4304
+ })));
4305
+ }
4306
+ else {
4307
+ const nodeList = querySelector(selector, !single);
4308
+ result.push(nodeList.map(dom => {
4309
+ // eslint-disable-next-line no-async-promise-executor
4310
+ return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
4311
+ yield setNodeEventCallbackAndTriggerComponentUpdate(dom, AREA_CHANGE_EVENT_NAME, null, true);
4312
+ resolve(filter(fields, dom));
4313
+ }));
4200
4314
  }));
4201
- }));
4315
+ }
4202
4316
  });
4203
4317
  Promise.all(result.map(item => {
4204
- return Promise.all(item);
4318
+ return item instanceof Array ? Promise.all(item) : item;
4205
4319
  })).then(data => {
4206
4320
  cb(data);
4207
4321
  });
@@ -4280,6 +4394,7 @@ var apis = /*#__PURE__*/Object.freeze({
4280
4394
  ENV_TYPE: ENV_TYPE,
4281
4395
  Events: Events,
4282
4396
  History: History,
4397
+ IntersectionObserver: IntersectionObserver,
4283
4398
  addCard: addCard,
4284
4399
  addFileToFavorites: addFileToFavorites,
4285
4400
  addPhoneCalendar: addPhoneCalendar,
@@ -4669,7 +4784,7 @@ var apis = /*#__PURE__*/Object.freeze({
4669
4784
  writeBLECharacteristicValue: writeBLECharacteristicValue
4670
4785
  });
4671
4786
 
4672
- Object.assign({}, apis);
4787
+ const taro = Object.assign({}, apis);
4673
4788
  const requirePlugin = /* @__PURE__ */ permanentlyNotSupport('requirePlugin');
4674
4789
  function initNativeApi(taro) {
4675
4790
  Current.taro = taro;
@@ -4693,7 +4808,7 @@ const defaultBaseFontSize = 20;
4693
4808
  const defaultUnitPrecision = 5;
4694
4809
  const defaultTargetUnit = 'vp';
4695
4810
  function getApp$1() {
4696
- return Current.app;
4811
+ return Current.app || {};
4697
4812
  }
4698
4813
  function initPxTransform({ designWidth = defaultDesignWidth, deviceRatio = defaultDesignRatio, baseFontSize = defaultBaseFontSize, unitPrecision = defaultUnitPrecision, targetUnit = defaultTargetUnit }) {
4699
4814
  const taro = Current.taro;
@@ -4707,19 +4822,61 @@ function initPxTransform({ designWidth = defaultDesignWidth, deviceRatio = defau
4707
4822
  config.unitPrecision = unitPrecision;
4708
4823
  }
4709
4824
  }
4710
- _display.getDefaultDisplaySync();
4825
+ const display = _display.getDefaultDisplaySync();
4826
+ let displayWidth = display.width;
4827
+ let ratioCache = false;
4828
+ let designWidthFunc;
4829
+ let designWidth = defaultDesignWidth;
4830
+ let deviceRatio = defaultDesignRatio;
4831
+ function getRatio(value) {
4832
+ var _a;
4833
+ // Note: 提前调用 display 可能无法获取正确值
4834
+ if (ratioCache === false || displayWidth !== display.width) {
4835
+ const config = ((_a = Current.taro) === null || _a === void 0 ? void 0 : _a.config) || {};
4836
+ if (!isFunction(designWidthFunc)) {
4837
+ designWidthFunc = isFunction(config.designWidth)
4838
+ ? config.designWidth
4839
+ : () => config.designWidth;
4840
+ designWidth = designWidthFunc(value) || defaultDesignWidth;
4841
+ deviceRatio = config.deviceRatio || defaultDesignRatio;
4842
+ if (!(designWidth in deviceRatio)) {
4843
+ throw new Error(`deviceRatio 配置中不存在 ${designWidth} 的设置!`);
4844
+ }
4845
+ }
4846
+ displayWidth = display.width;
4847
+ ratioCache = Math.min(display.width, display.height) / designWidth;
4848
+ }
4849
+ return ratioCache;
4850
+ }
4851
+ // Note: 设置为 style 单位时会自动完成设计稿转换,设计开发者调用 API 时也许抹平差异,例如 pageScrollTo[option.offsetTop]
4852
+ function pxTransformHelper(size, unit, isNumber = false) {
4853
+ var _a;
4854
+ const config = ((_a = Current.taro) === null || _a === void 0 ? void 0 : _a.config) || {};
4855
+ const targetUnit = unit || config.targetUnit || defaultTargetUnit;
4856
+ if (targetUnit === 'PX') {
4857
+ return px2vp(size * display.scaledDensity) + 'vp';
4858
+ }
4859
+ const ratio = getRatio(size);
4860
+ let val = size * ratio;
4861
+ switch (targetUnit) {
4862
+ case 'vp':
4863
+ // Note: 在应用创建前调用无效
4864
+ val = px2vp(val);
4865
+ break;
4866
+ }
4867
+ return isNumber ? val : val + targetUnit;
4868
+ }
4711
4869
  function pxTransform(size) {
4712
4870
  var _a;
4713
4871
  const config = ((_a = Current.taro) === null || _a === void 0 ? void 0 : _a.config) || {};
4714
4872
  const targetUnit = config.targetUnit || defaultTargetUnit;
4715
- let val = size;
4873
+ const val = size;
4716
4874
  switch (targetUnit) {
4717
4875
  case 'vp':
4718
- val = px2vp(size);
4719
- break;
4876
+ return pxTransformHelper(size, 'px');
4720
4877
  // NOTE: 鸿蒙环境下 style 会自动完成设计稿转换,无需在方法内二次调整
4721
4878
  }
4722
- return val + config.targetUnit;
4879
+ return val + targetUnit;
4723
4880
  }
4724
4881
  function canIUseWebp() {
4725
4882
  return true;
@@ -4733,6 +4890,7 @@ function getAppInfo() {
4733
4890
  designWidth: config === null || config === void 0 ? void 0 : config.designWidth,
4734
4891
  };
4735
4892
  }
4893
+ initNativeApi(taro);
4736
4894
 
4737
4895
  const components = {
4738
4896
  Checkbox: {