@tarojs/plugin-platform-harmony-ets 4.0.0-beta.45 → 4.0.0-beta.47

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.
@@ -103,6 +103,16 @@ export interface TaroStyleType {
103
103
  type: TextDecorationType
104
104
  }
105
105
 
106
+ // animation
107
+ animationName?: {
108
+ percentage: number
109
+ event: TaroStyleType
110
+ }[]
111
+ animationDuration?: number
112
+ animationTimingFunction?: string
113
+ animationDelay?: number
114
+ animationIterationCount?: number
115
+
106
116
  // other
107
117
  opacity?: number | Resource
108
118
  zIndex?: number
@@ -1,5 +1,5 @@
1
1
  import _display from '@ohos.display'
2
- import { pxTransformHelper } from '@tarojs/taro'
2
+ import { getSystemInfoSync, pxTransformHelper } from '@tarojs/taro'
3
3
 
4
4
  import { NodeType } from '../dom/node'
5
5
  import convertWebStyle2HmStyle from '../dom/stylesheet/covertWeb2Hm'
@@ -60,16 +60,12 @@ export function parseClasses (classNames: string | string[] = []): string[] {
60
60
  }
61
61
 
62
62
  // 合并静态样式,从样式表里面找到对应的样式
63
- export function calcStaticStyle (styleSheet: Record<string, CSSProperties>, classNames: string | string[] = [], style: CSSProperties): CSSProperties {
63
+ export function calcStaticStyle (styleSheet: Record<string, CSSProperties>, classNames: string | string[] = []): CSSProperties {
64
64
  const obj: CSSProperties[] = []
65
65
  const classes = parseClasses(classNames)
66
66
  if (classes.length === 1) {
67
- if (style) {
68
- return Object.assign({}, styleSheet[classes[0]], style)
69
- } else {
70
- // 同一个引用
71
- return styleSheet[classes[0]]
72
- }
67
+ // 同一个引用
68
+ return styleSheet[classes[0]]
73
69
  } else {
74
70
  for (let i = 0; i < classes.length; i++) {
75
71
  const className = classes[i]
@@ -77,9 +73,6 @@ export function calcStaticStyle (styleSheet: Record<string, CSSProperties>, clas
77
73
  obj.push(styleSheet[className])
78
74
  }
79
75
  }
80
- if (style) {
81
- obj.push(style)
82
- }
83
76
  return Object.assign.apply(null, [{}].concat(obj))
84
77
  }
85
78
  }
@@ -92,6 +85,27 @@ export function calcDynamicStyle (style: CSSProperties): CSSProperties {
92
85
  return {}
93
86
  }
94
87
 
88
+ // css env()环境样式获取
89
+ export function __env__(safeAreaType: string, fallback?: string | number) {
90
+ const sysInfo = getSystemInfoSync()
91
+
92
+ switch (safeAreaType) {
93
+ case 'safe-area-inset-top': {
94
+ return sysInfo.safeArea?.top ? `${sysInfo.safeArea?.top}px` : fallback
95
+ }
96
+ case 'safe-area-inset-right': {
97
+ return sysInfo.safeArea?.right ? `${sysInfo.screenWidth - sysInfo.safeArea?.right}px` : fallback
98
+ }
99
+ case 'safe-area-inset-bottom': {
100
+ return sysInfo.safeArea?.bottom ? `${sysInfo.screenHeight - sysInfo.safeArea?.bottom}px` : fallback
101
+ }
102
+ case 'safe-area-inset-left': {
103
+ return sysInfo.safeArea?.left ? `${sysInfo.safeArea?.left}px` : fallback
104
+ }
105
+ }
106
+ return fallback
107
+ }
108
+
95
109
  export function getPageScrollerOrNode (scrollerOrNode: any, page: any) {
96
110
  if (!page) return scrollerOrNode
97
111
 
@@ -9,6 +9,7 @@ import errorManager from '@ohos.app.ability.errorManager';
9
9
  import sensor from '@ohos.sensor';
10
10
  import batteryInfo, { BatteryChargeState } from '@ohos.batteryInfo';
11
11
  import pasteboard from '@ohos.pasteboard';
12
+ import promptAction from '@ohos.promptAction';
12
13
  import inputMethodEngine from '@ohos.inputMethodEngine';
13
14
  import network from '@system.network';
14
15
  import call from '@ohos.telephony.call';
@@ -30,7 +31,6 @@ import router from '@ohos.router';
30
31
  import bundleManager from '@ohos.bundle.bundleManager';
31
32
  import distributedKVStore from '@ohos.data.distributedKVStore';
32
33
  import matrix4 from '@ohos.matrix4';
33
- import prompt from '@ohos.prompt';
34
34
  import { pxTransformHelper as pxTransformHelper$1 } from '@tarojs/taro';
35
35
 
36
36
  class MethodHandler {
@@ -656,6 +656,7 @@ const setClipboardData = function (options) {
656
656
  callAsyncFail(reject, res, options);
657
657
  }
658
658
  else {
659
+ promptAction.showToast({ message: '内容已复制' });
659
660
  return handle.success({
660
661
  data,
661
662
  }, { resolve, reject });
@@ -3235,6 +3236,7 @@ const createCacheManager = /* @__PURE__ */ temporarilyNotSupport('createCacheMan
3235
3236
  let context;
3236
3237
  let kvManager;
3237
3238
  let kvStore;
3239
+ let kvStorePromise;
3238
3240
  Current.contextPromise.then((ctx) => {
3239
3241
  context = ctx;
3240
3242
  const kvManagerConfig = {
@@ -3256,13 +3258,16 @@ Current.contextPromise.then((ctx) => {
3256
3258
  securityLevel: distributedKVStore.SecurityLevel.S1
3257
3259
  };
3258
3260
  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
- // 请确保获取到键值数据库实例后,再进行相关数据操作
3261
+ kvStorePromise = new Promise(resolve => {
3262
+ kvManager.getKVStore(`${data.appInfo.uid}Store`, options, (err, store) => {
3263
+ if (err) {
3264
+ console.error(`Failed to get KVStore: Code:${err.code},message:${err.message}`);
3265
+ return;
3266
+ }
3267
+ kvStore = store;
3268
+ // 请确保获取到键值数据库实例后,再进行相关数据操作
3269
+ resolve();
3270
+ });
3266
3271
  });
3267
3272
  }
3268
3273
  catch (e) {
@@ -3274,7 +3279,7 @@ const storageSchema = {
3274
3279
  key: 'String'
3275
3280
  };
3276
3281
  function checkContextExist(api, isAsync = false) {
3277
- if (!context || !kvStore) {
3282
+ if (!context) {
3278
3283
  const message = `${api} 调用失败,Taro 不支持过早地调用 ${api},请确保页面已经渲染完成再调用此 API`;
3279
3284
  if (isAsync) {
3280
3285
  return {
@@ -3302,20 +3307,22 @@ function getStorage(options) {
3302
3307
  const { key, success, fail, complete } = options || {};
3303
3308
  const handle = new MethodHandler({ name, success, fail, complete });
3304
3309
  return new Promise((resolve, reject) => {
3305
- try {
3306
- validateParams(name, options, storageSchema);
3307
- }
3308
- catch (error) {
3309
- const res = { errMsg: error.message };
3310
- return handle.fail(res, { resolve, reject });
3311
- }
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;
3310
+ kvStorePromise.then(() => {
3311
+ try {
3312
+ validateParams(name, options, storageSchema);
3317
3313
  }
3318
- handle.success({ data }, { resolve, reject });
3314
+ catch (error) {
3315
+ const res = { errMsg: error.message };
3316
+ return handle.fail(res, { resolve, reject });
3317
+ }
3318
+ kvStore = kvStore;
3319
+ kvStore.get(key, (err, data) => {
3320
+ if (err) {
3321
+ handle.fail({ errMsg: `Failed to get data. Code:${err.code},message:${err.message}` }, { resolve, reject });
3322
+ return;
3323
+ }
3324
+ handle.success({ data }, { resolve, reject });
3325
+ });
3319
3326
  });
3320
3327
  });
3321
3328
  }
@@ -3328,20 +3335,22 @@ function setStorage(options) {
3328
3335
  const { key, data, success, fail, complete } = options || {};
3329
3336
  const handle = new MethodHandler({ name, success, fail, complete });
3330
3337
  return new Promise((resolve, reject) => {
3331
- try {
3332
- validateParams(name, options, storageSchema);
3333
- }
3334
- catch (error) {
3335
- const res = { errMsg: error.message };
3336
- return handle.fail(res, { resolve, reject });
3337
- }
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;
3338
+ kvStorePromise.then(() => {
3339
+ try {
3340
+ validateParams(name, options, storageSchema);
3341
+ }
3342
+ catch (error) {
3343
+ const res = { errMsg: error.message };
3344
+ return handle.fail(res, { resolve, reject });
3343
3345
  }
3344
- handle.success({}, { resolve, reject });
3346
+ kvStore = kvStore;
3347
+ kvStore.put(key, data, (err) => {
3348
+ if (err) {
3349
+ handle.fail({ errMsg: `Failed to put data. Code:${err.code},message:${err.message}` }, { resolve, reject });
3350
+ return;
3351
+ }
3352
+ handle.success({}, { resolve, reject });
3353
+ });
3345
3354
  });
3346
3355
  });
3347
3356
  }
@@ -3354,20 +3363,22 @@ function removeStorage(options) {
3354
3363
  const { key, success, fail, complete } = options || {};
3355
3364
  const handle = new MethodHandler({ name, success, fail, complete });
3356
3365
  return new Promise((resolve, reject) => {
3357
- try {
3358
- validateParams(name, options, storageSchema);
3359
- }
3360
- catch (error) {
3361
- const res = { errMsg: error.message };
3362
- return handle.fail(res, { resolve, reject });
3363
- }
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;
3366
+ kvStorePromise.then(() => {
3367
+ try {
3368
+ validateParams(name, options, storageSchema);
3369
3369
  }
3370
- handle.success({}, { resolve, reject });
3370
+ catch (error) {
3371
+ const res = { errMsg: error.message };
3372
+ return handle.fail(res, { resolve, reject });
3373
+ }
3374
+ kvStore = kvStore;
3375
+ kvStore.delete(key, (err) => {
3376
+ if (err) {
3377
+ handle.fail({ errMsg: `Failed to delete data. Code:${err.code},message:${err.message}` }, { resolve, reject });
3378
+ return;
3379
+ }
3380
+ handle.success({}, { resolve, reject });
3381
+ });
3371
3382
  });
3372
3383
  });
3373
3384
  }
@@ -3379,7 +3390,7 @@ const batchSetStorageSync = /* @__PURE__ */ temporarilyNotSupport('batchSetStora
3379
3390
  const batchSetStorage = /* @__PURE__ */ temporarilyNotSupport('batchSetStorage');
3380
3391
  const batchGetStorageSync = /* @__PURE__ */ temporarilyNotSupport('batchGetStorageSync');
3381
3392
  const batchGetStorage = /* @__PURE__ */ temporarilyNotSupport('batchGetStorage');
3382
- const clearStorage = temporarilyNotSupport('removeStorageSync');
3393
+ const clearStorage = temporarilyNotSupport('clearStorage');
3383
3394
  const getStorageSync = temporarilyNotSupport('getStorageSync', 'getStorage');
3384
3395
  const setStorageSync = temporarilyNotSupport('setStorageSync', 'setStorage');
3385
3396
  const clearStorageSync = temporarilyNotSupport('clearStorageSync', 'clearStorage');
@@ -3629,7 +3640,7 @@ function showToast(options) {
3629
3640
  const res = { errMsg: error.message };
3630
3641
  return callAsyncFail(reject, res, options);
3631
3642
  }
3632
- prompt.showToast({
3643
+ promptAction.showToast({
3633
3644
  message: options.title,
3634
3645
  duration: options.duration,
3635
3646
  bottom: options.bottom
@@ -3662,25 +3673,24 @@ function showModal(options) {
3662
3673
  color: confirmColor
3663
3674
  });
3664
3675
  }
3665
- return new Promise(resolve => {
3676
+ return new Promise((resolve, reject) => {
3666
3677
  const modalOptions = {
3667
3678
  title,
3668
3679
  message: content,
3669
3680
  buttons: buttons,
3670
- success: (data) => {
3671
- if (data.index === 1 || !showCancel) {
3672
- callAsyncSuccess(resolve, Object.assign(Object.assign({}, resCallback('showModal')), { confirm: true, cancel: false, content: null }), options);
3673
- }
3674
- else {
3675
- callAsyncSuccess(resolve, Object.assign(Object.assign({}, resCallback('showModal')), { confirm: false, cancel: true }), options);
3676
- }
3677
- },
3678
- // 鸿蒙没有失败方法,只有取消
3679
- cancel: (_) => {
3681
+ };
3682
+ promptAction.showDialog(modalOptions, (error, data) => {
3683
+ if (error) {
3684
+ const res = { errMsg: error };
3685
+ callAsyncFail(reject, res, options);
3686
+ }
3687
+ if (data.index === 0 && showCancel) {
3680
3688
  callAsyncSuccess(resolve, Object.assign(Object.assign({}, resCallback('showModal')), { confirm: false, cancel: true }), options);
3681
3689
  }
3682
- };
3683
- prompt.showDialog(modalOptions);
3690
+ else {
3691
+ callAsyncSuccess(resolve, Object.assign(Object.assign({}, resCallback('showModal')), { confirm: true, cancel: false, content: null }), options);
3692
+ }
3693
+ });
3684
3694
  });
3685
3695
  }
3686
3696
  const showActionSheetSchema = {
@@ -3711,21 +3721,19 @@ function showActionSheet(options) {
3711
3721
  });
3712
3722
  const actionSheetOptions = {
3713
3723
  title,
3714
- buttons,
3715
- success: (data) => {
3716
- callAsyncSuccess(resolve, Object.assign(Object.assign({}, data), resCallback('showActionSheet')), options);
3717
- },
3718
- // 取消方法,并非失败
3719
- fail: (data) => {
3724
+ buttons
3725
+ };
3726
+ promptAction.showActionMenu(actionSheetOptions, (error, data) => {
3727
+ if (error) {
3720
3728
  callAsyncFail(reject, Object.assign(Object.assign({}, data), { errMsg: data.errMsg.replace('showActionMenu', 'showActionSheet') }), options);
3721
3729
  }
3722
- };
3723
- prompt.showActionMenu(actionSheetOptions);
3730
+ callAsyncSuccess(resolve, Object.assign(Object.assign({}, data), resCallback('showActionSheet')), options);
3731
+ });
3724
3732
  });
3725
3733
  }
3726
3734
  function hideToast(options) {
3727
3735
  return new Promise(resolve => {
3728
- prompt.showToast({
3736
+ promptAction.showToast({
3729
3737
  message: '关闭中',
3730
3738
  duration: 10,
3731
3739
  bottom: '9999px'