@doubao-apps/taro-runtime 0.0.18 → 0.0.19

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 (63) hide show
  1. package/dist/api/base/index.d.ts +12 -0
  2. package/dist/api/base/index.js +13 -1
  3. package/dist/api/create-selector-query/index.d.ts +3 -0
  4. package/dist/api/create-selector-query/index.js +577 -0
  5. package/dist/api/index.d.ts +7 -3
  6. package/dist/api/index.js +7 -3
  7. package/dist/api/location/index.d.ts +10 -0
  8. package/dist/api/location/index.js +77 -0
  9. package/dist/api/map/index.js +28 -30
  10. package/dist/api/request/index.js +8 -18
  11. package/dist/api/router/index.d.ts +4 -0
  12. package/dist/api/router/index.js +4 -0
  13. package/dist/api/router/navigate-back.d.ts +5 -0
  14. package/dist/api/router/navigate-back.js +20 -0
  15. package/dist/api/{navigate/index.d.ts → router/navigate-to.d.ts} +2 -2
  16. package/dist/api/{navigate/index.js → router/navigate-to.js} +7 -7
  17. package/dist/api/router/redirect-to.d.ts +5 -0
  18. package/dist/api/router/redirect-to.js +22 -0
  19. package/dist/api/show-toast/index.d.ts +6 -0
  20. package/dist/api/show-toast/index.js +39 -0
  21. package/dist/api/storage/index.d.ts +16 -0
  22. package/dist/api/storage/index.js +55 -0
  23. package/dist/api/system/index.d.ts +12 -0
  24. package/dist/api/system/index.js +40 -10
  25. package/dist/api/utils.d.ts +21 -0
  26. package/dist/api/utils.js +65 -0
  27. package/dist/components/Image/index.d.ts +2 -1
  28. package/dist/components/Image/index.jsx +3 -2
  29. package/dist/components/Input/index.d.ts +3 -5
  30. package/dist/components/Input/index.jsx +50 -3
  31. package/dist/components/Input/map.d.ts +50 -0
  32. package/dist/components/Input/map.js +226 -0
  33. package/dist/components/Map/bridge.d.ts +32 -4
  34. package/dist/components/Map/bridge.js +224 -13
  35. package/dist/components/Map/index.jsx +78 -58
  36. package/dist/components/Map/mapping.d.ts +71 -3
  37. package/dist/components/Map/mapping.js +0 -15
  38. package/dist/components/PickerView/index.d.ts +8 -0
  39. package/dist/components/PickerView/index.jsx +47 -0
  40. package/dist/components/PickerView/map.d.ts +36 -0
  41. package/dist/components/PickerView/map.js +29 -0
  42. package/dist/components/Radio/index.d.ts +5 -0
  43. package/dist/components/Radio/index.jsx +82 -0
  44. package/dist/components/Radio/map.d.ts +38 -0
  45. package/dist/components/Radio/map.js +109 -0
  46. package/dist/components/Radio/shared.d.ts +7 -0
  47. package/dist/components/Radio/shared.js +9 -0
  48. package/dist/components/RadioGroup/context.d.ts +11 -0
  49. package/dist/components/RadioGroup/context.js +3 -0
  50. package/dist/components/RadioGroup/index.d.ts +3 -0
  51. package/dist/components/RadioGroup/index.jsx +80 -0
  52. package/dist/components/RadioGroup/map.d.ts +44 -0
  53. package/dist/components/RadioGroup/map.js +109 -0
  54. package/dist/components/WebView/index.d.ts +3 -0
  55. package/dist/components/WebView/index.jsx +24 -0
  56. package/dist/components/index.d.ts +4 -0
  57. package/dist/components/index.js +4 -0
  58. package/dist/exports/app-core.d.ts +1 -1
  59. package/dist/exports/app-core.js +1 -1
  60. package/dist/exports/view-core.d.ts +1 -1
  61. package/dist/exports/view-core.js +1 -1
  62. package/dist/internal/map-context/index.d.ts +7 -1
  63. package/package.json +1 -1
@@ -0,0 +1,77 @@
1
+ import { getLocation as appGetLocation } from '@byted-doubao-apps/framework/api';
2
+ import { buildOkCallbackResult, runTaroApi } from '../utils.js';
3
+ function resolveMode(option) {
4
+ if (typeof option.mode === 'number') {
5
+ return option.mode;
6
+ }
7
+ if (option.isHighAccuracy === true) {
8
+ return 2;
9
+ }
10
+ if (option.isHighAccuracy === false) {
11
+ return 0;
12
+ }
13
+ return undefined;
14
+ }
15
+ function resolveTimeoutMs(option) {
16
+ if (typeof option.timeoutMs === 'number') {
17
+ return option.timeoutMs;
18
+ }
19
+ if (typeof option.highAccuracyExpireTime === 'number') {
20
+ return option.highAccuracyExpireTime;
21
+ }
22
+ return undefined;
23
+ }
24
+ function resolveMaxCacheMs(option) {
25
+ if (typeof option.maxCacheMs === 'number') {
26
+ return option.maxCacheMs;
27
+ }
28
+ if (typeof option.cacheTimeout === 'number') {
29
+ return option.cacheTimeout;
30
+ }
31
+ return undefined;
32
+ }
33
+ function buildFrameworkParams(option) {
34
+ const params = {};
35
+ const mode = resolveMode(option);
36
+ const timeoutMs = resolveTimeoutMs(option);
37
+ const maxCacheMs = resolveMaxCacheMs(option);
38
+ if (typeof mode === 'number') {
39
+ params.mode = mode;
40
+ }
41
+ if (typeof timeoutMs === 'number') {
42
+ params.timeoutMs = timeoutMs;
43
+ }
44
+ if (typeof maxCacheMs === 'number') {
45
+ params.maxCacheMs = maxCacheMs;
46
+ }
47
+ if (typeof option.source === 'string') {
48
+ params.source = option.source;
49
+ }
50
+ return params;
51
+ }
52
+ function normalizeNumber(value) {
53
+ if (typeof value === 'number' && Number.isFinite(value)) {
54
+ return value;
55
+ }
56
+ return 0;
57
+ }
58
+ function buildSuccessResult(response) {
59
+ const accuracy = normalizeNumber(response.accuracy);
60
+ return {
61
+ latitude: normalizeNumber(response.latitude),
62
+ longitude: normalizeNumber(response.longitude),
63
+ speed: normalizeNumber(response.speed),
64
+ accuracy,
65
+ altitude: 0,
66
+ horizontalAccuracy: accuracy,
67
+ verticalAccuracy: 0,
68
+ ...buildOkCallbackResult('getLocation')
69
+ };
70
+ }
71
+ export async function getLocation(option = {}) {
72
+ return runTaroApi('getLocation', option, async () => {
73
+ const response = await appGetLocation(buildFrameworkParams(option));
74
+ return buildSuccessResult(response);
75
+ });
76
+ }
77
+ //# sourceMappingURL=index.js.map
@@ -1,3 +1,4 @@
1
+ import { buildFailCallbackResult, buildOkCallbackResult, emitFailure, emitSuccess, normalizeErrorMessage } from '../utils.js';
1
2
  import { getMapController, MAP_CONTEXT_METHOD_TO_COMPONENT_METHOD } from '../../internal/map-context/index.js';
2
3
  export function createMapContext(mapId, _component) {
3
4
  return {
@@ -27,7 +28,7 @@ export function createMapContext(mapId, _component) {
27
28
  return rejectMethod('includePoints', resolvedOption, 'points is required');
28
29
  }
29
30
  return runWithController(mapId, 'includePoints', resolvedOption, (controller) => {
30
- controller[MAP_CONTEXT_METHOD_TO_COMPONENT_METHOD.includePoints](resolvedOption.points, normalizePadding(resolvedOption.padding));
31
+ controller[MAP_CONTEXT_METHOD_TO_COMPONENT_METHOD.includePoints](resolvedOption.points, resolvedOption.padding);
31
32
  return undefined;
32
33
  });
33
34
  },
@@ -51,8 +52,27 @@ export function createMapContext(mapId, _component) {
51
52
  toScreenLocation: createUnsupportedMethod('toScreenLocation'),
52
53
  fromScreenLocation: createUnsupportedMethod('fromScreenLocation'),
53
54
  openMapApp: createUnsupportedMethod('openMapApp'),
54
- addMarkers: createUnsupportedMethod('addMarkers'),
55
- removeMarkers: createUnsupportedMethod('removeMarkers'),
55
+ addMarkers: (option) => {
56
+ const resolvedOption = option ?? {};
57
+ if (!Array.isArray(resolvedOption.markers)) {
58
+ return rejectMethod('addMarkers', resolvedOption, 'markers is required');
59
+ }
60
+ return runWithController(mapId, 'addMarkers', resolvedOption, (controller) => {
61
+ controller.addMarkers(resolvedOption.markers, resolvedOption.clear === true);
62
+ return undefined;
63
+ });
64
+ },
65
+ removeMarkers: (option) => {
66
+ const resolvedOption = option ?? {};
67
+ if (!Array.isArray(resolvedOption.markerIds) ||
68
+ resolvedOption.markerIds.some((markerId) => typeof markerId !== 'number' || Number.isNaN(markerId))) {
69
+ return rejectMethod('removeMarkers', resolvedOption, 'markerIds is required');
70
+ }
71
+ return runWithController(mapId, 'removeMarkers', resolvedOption, (controller) => {
72
+ controller.removeMarkers(resolvedOption.markerIds);
73
+ return undefined;
74
+ });
75
+ },
56
76
  initMarkerCluster: createUnsupportedMethod('initMarkerCluster'),
57
77
  on: () => {
58
78
  console.warn('[doubao-apps/taro-runtime] MapContext.on is not supported yet.');
@@ -71,40 +91,18 @@ async function runWithController(mapId, method, option, run) {
71
91
  const result = await run(controller);
72
92
  const payload = {
73
93
  ...(result && typeof result === 'object' ? result : {}),
74
- errMsg: `${method}:ok`
94
+ ...buildOkCallbackResult(method)
75
95
  };
76
- option?.success?.(payload);
77
- option?.complete?.(payload);
78
- console.log('runWithController', payload);
96
+ emitSuccess(option, payload);
79
97
  return payload;
80
98
  }
81
99
  catch (error) {
82
- console.log('runWithController', error);
83
- return rejectMethod(method, option, normalizeError(error));
100
+ return rejectMethod(method, option, normalizeErrorMessage(error, 'unknown error'));
84
101
  }
85
102
  }
86
103
  function rejectMethod(method, option, message) {
87
- const payload = { errMsg: `${method}:fail ${message}` };
88
- option?.fail?.(payload);
89
- option?.complete?.(payload);
104
+ const payload = buildFailCallbackResult(method, message);
105
+ emitFailure(option, payload);
90
106
  return Promise.reject(payload);
91
107
  }
92
- function normalizePadding(padding) {
93
- if (!Array.isArray(padding) || padding.length === 0) {
94
- return undefined;
95
- }
96
- return typeof padding[0] === 'number' ? padding[0] : undefined;
97
- }
98
- function normalizeError(error) {
99
- if (typeof error === 'string') {
100
- return error;
101
- }
102
- if (error && typeof error === 'object' && 'errMsg' in error && typeof error.errMsg === 'string') {
103
- return error.errMsg;
104
- }
105
- if (error instanceof Error) {
106
- return error.message;
107
- }
108
- return 'unknown error';
109
- }
110
108
  //# sourceMappingURL=index.js.map
@@ -1,4 +1,5 @@
1
1
  import { request as appletRequest } from '@byted-doubao-apps/framework/api';
2
+ import { buildFailCallbackResult, buildOkCallbackResult, emitFailure, emitSuccess } from '../utils.js';
2
3
  import { createRequestTask } from './request-task.js';
3
4
  const DEFAULT_METHOD = 'GET';
4
5
  const DEFAULT_TIMEOUT = 60000;
@@ -7,16 +8,11 @@ function buildSuccessResult(response, header, statusCode) {
7
8
  data: response,
8
9
  header: header ?? {},
9
10
  statusCode: statusCode ?? 0,
10
- errMsg: 'request:ok'
11
+ ...buildOkCallbackResult('request')
11
12
  };
12
13
  }
13
14
  function buildFailResult(error) {
14
- const message = error instanceof Error ? error.message : String(error);
15
- return { errMsg: `request:fail ${message}` };
16
- }
17
- function runComplete(complete, result) {
18
- if (complete)
19
- complete(result);
15
+ return buildFailCallbackResult('request', error);
20
16
  }
21
17
  export function request(option) {
22
18
  const { url, data, header, method = DEFAULT_METHOD, timeout = DEFAULT_TIMEOUT, success, fail, complete } = option;
@@ -26,8 +22,8 @@ export function request(option) {
26
22
  const promise = appletRequest({
27
23
  url,
28
24
  method: upperMethod,
29
- data: data,
30
- header: { 'Content-Type': 'application/json', ...header }
25
+ data,
26
+ header
31
27
  })
32
28
  .then((res) => {
33
29
  if (settled)
@@ -36,9 +32,7 @@ export function request(option) {
36
32
  if (timeoutId)
37
33
  clearTimeout(timeoutId);
38
34
  const result = buildSuccessResult(res.data, res.header, res.statusCode);
39
- if (success)
40
- success(result);
41
- runComplete(complete, result);
35
+ emitSuccess({ success, complete }, result, result);
42
36
  return result;
43
37
  })
44
38
  .catch((error) => {
@@ -48,9 +42,7 @@ export function request(option) {
48
42
  if (timeoutId)
49
43
  clearTimeout(timeoutId);
50
44
  const result = buildFailResult(error);
51
- if (fail)
52
- fail(result);
53
- runComplete(complete, result);
45
+ emitFailure({ fail, complete }, result);
54
46
  return Promise.reject(result);
55
47
  });
56
48
  if (Number.isFinite(timeout) && timeout > 0) {
@@ -59,9 +51,7 @@ export function request(option) {
59
51
  return;
60
52
  settled = true;
61
53
  const result = buildFailResult('timeout');
62
- if (fail)
63
- fail(result);
64
- runComplete(complete, result);
54
+ emitFailure({ fail, complete }, result);
65
55
  }, timeout);
66
56
  }
67
57
  return createRequestTask(promise);
@@ -0,0 +1,4 @@
1
+ export { navigateBack } from './navigate-back.js';
2
+ export { navigateTo } from './navigate-to.js';
3
+ export { redirectTo } from './redirect-to.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,4 @@
1
+ export { navigateBack } from './navigate-back.js';
2
+ export { navigateTo } from './navigate-to.js';
3
+ export { redirectTo } from './redirect-to.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,5 @@
1
+ import type { navigateBack as taroNavigateBack } from '@tarojs/taro';
2
+ export declare function navigateBack(params?: Parameters<typeof taroNavigateBack>[0]): Promise<{
3
+ errMsg: string;
4
+ }>;
5
+ //# sourceMappingURL=navigate-back.d.ts.map
@@ -0,0 +1,20 @@
1
+ import { navigateBack as appNavigateBack } from '@byted-doubao-apps/framework/api';
2
+ export async function navigateBack(params) {
3
+ try {
4
+ await appNavigateBack(params);
5
+ return {
6
+ errMsg: ''
7
+ };
8
+ }
9
+ catch (err) {
10
+ if (err instanceof Error) {
11
+ return {
12
+ errMsg: err.message
13
+ };
14
+ }
15
+ return {
16
+ errMsg: String(err)
17
+ };
18
+ }
19
+ }
20
+ //# sourceMappingURL=navigate-back.js.map
@@ -1,5 +1,5 @@
1
1
  import type { navigateTo as taroNavigateTo } from '@tarojs/taro';
2
2
  export declare function navigateTo(params: Parameters<typeof taroNavigateTo>[0]): Promise<{
3
3
  errMsg: string;
4
- } | undefined>;
5
- //# sourceMappingURL=index.d.ts.map
4
+ }>;
5
+ //# sourceMappingURL=navigate-to.d.ts.map
@@ -1,11 +1,8 @@
1
- import { openPage } from '@byted-doubao-apps/framework/api';
2
- // TODO only impl major params
1
+ import { navigateTo as appNavigateTo } from '@byted-doubao-apps/framework/api';
3
2
  export async function navigateTo(params) {
4
3
  try {
5
- const pageId = params.url.split('/')[1];
6
- await openPage({
7
- pageId,
8
- context: {}
4
+ await appNavigateTo({
5
+ url: params.url
9
6
  });
10
7
  return {
11
8
  errMsg: ''
@@ -17,6 +14,9 @@ export async function navigateTo(params) {
17
14
  errMsg: err.message
18
15
  };
19
16
  }
17
+ return {
18
+ errMsg: String(err)
19
+ };
20
20
  }
21
21
  }
22
- //# sourceMappingURL=index.js.map
22
+ //# sourceMappingURL=navigate-to.js.map
@@ -0,0 +1,5 @@
1
+ import type { redirectTo as taroRedirectTo } from '@tarojs/taro';
2
+ export declare function redirectTo(params: Parameters<typeof taroRedirectTo>[0]): Promise<{
3
+ errMsg: string;
4
+ }>;
5
+ //# sourceMappingURL=redirect-to.d.ts.map
@@ -0,0 +1,22 @@
1
+ import { redirectTo as appRedirectTo } from '@byted-doubao-apps/framework/api';
2
+ export async function redirectTo(params) {
3
+ try {
4
+ await appRedirectTo({
5
+ url: params.url
6
+ });
7
+ return {
8
+ errMsg: ''
9
+ };
10
+ }
11
+ catch (err) {
12
+ if (err instanceof Error) {
13
+ return {
14
+ errMsg: err.message
15
+ };
16
+ }
17
+ return {
18
+ errMsg: String(err)
19
+ };
20
+ }
21
+ }
22
+ //# sourceMappingURL=redirect-to.js.map
@@ -0,0 +1,6 @@
1
+ import type { showToast as taroShowToast } from '@tarojs/taro';
2
+ type TaroShowToastOption = NonNullable<Parameters<typeof taroShowToast>[0]>;
3
+ type TaroShowToastResult = Awaited<ReturnType<typeof taroShowToast>>;
4
+ export declare function showToast(option?: TaroShowToastOption): Promise<TaroShowToastResult>;
5
+ export {};
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,39 @@
1
+ import { showToast as appShowToast } from '@byted-doubao-apps/framework/api';
2
+ import { runCallbackApi } from '../utils.js';
3
+ function resolveType(icon) {
4
+ if (icon === 'success' || icon === 'error') {
5
+ return icon;
6
+ }
7
+ return undefined;
8
+ }
9
+ function resolveIcon(icon) {
10
+ if (icon === 'success' || icon === 'error') {
11
+ return icon;
12
+ }
13
+ return undefined;
14
+ }
15
+ function buildFrameworkParams(option) {
16
+ const { title, duration, icon, image } = option ?? {};
17
+ const params = {
18
+ message: typeof title === 'string' ? title : ''
19
+ };
20
+ if (typeof duration === 'number') {
21
+ params.duration = duration;
22
+ }
23
+ if (typeof image === 'string') {
24
+ params.customIcon = image;
25
+ }
26
+ const mappedType = resolveType(icon);
27
+ const mappedIcon = resolveIcon(icon);
28
+ if (mappedType) {
29
+ params.type = mappedType;
30
+ }
31
+ if (mappedIcon && !params.customIcon) {
32
+ params.icon = mappedIcon;
33
+ }
34
+ return params;
35
+ }
36
+ export async function showToast(option) {
37
+ return runCallbackApi('showToast', option, () => appShowToast(buildFrameworkParams(option)));
38
+ }
39
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,16 @@
1
+ import { getStorageInfoSync as appGetStorageInfoSync } from '@byted-doubao-apps/framework/api';
2
+ import type { clearStorage as taroClearStorage, getStorageInfo as taroGetStorageInfo, removeStorage as taroRemoveStorage, setStorage as taroSetStorage } from '@tarojs/taro';
3
+ type GetStorageInfoResult = ReturnType<typeof appGetStorageInfoSync>;
4
+ type GetStorageResult<T = any> = Taro.getStorage.SuccessCallbackResult<T>;
5
+ export declare function setStorage(option: Parameters<typeof taroSetStorage>[0]): Promise<TaroGeneral.CallbackResult>;
6
+ export declare function setStorageSync(key: string, data: any): void;
7
+ export declare function getStorage<T = any>(option: Taro.getStorage.Option<T>): Promise<GetStorageResult<T>>;
8
+ export declare function getStorageSync<T = any>(key: string): T;
9
+ export declare function removeStorage(option: Parameters<typeof taroRemoveStorage>[0]): Promise<TaroGeneral.CallbackResult>;
10
+ export declare function removeStorageSync(key: string): void;
11
+ export declare function clearStorage(option?: Parameters<typeof taroClearStorage>[0]): Promise<TaroGeneral.CallbackResult>;
12
+ export declare function clearStorageSync(): void;
13
+ export declare function getStorageInfo(option?: Parameters<typeof taroGetStorageInfo>[0]): Promise<GetStorageInfoResult>;
14
+ export declare function getStorageInfoSync(): GetStorageInfoResult;
15
+ export {};
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,55 @@
1
+ import { clearStorage as appClearStorage, clearStorageSync as appClearStorageSync, getStorage as appGetStorage, getStorageInfo as appGetStorageInfo, getStorageInfoSync as appGetStorageInfoSync, getStorageSync as appGetStorageSync, removeStorage as appRemoveStorage, removeStorageSync as appRemoveStorageSync, setStorage as appSetStorage, setStorageSync as appSetStorageSync } from '@byted-doubao-apps/framework/api';
2
+ import { buildOkCallbackResult, runCallbackApi, runTaroApi } from '../utils.js';
3
+ export async function setStorage(option) {
4
+ const { key, data } = option;
5
+ return runCallbackApi('setStorage', option, () => appSetStorage({
6
+ key,
7
+ data
8
+ }));
9
+ }
10
+ export function setStorageSync(key, data) {
11
+ appSetStorageSync({
12
+ key,
13
+ data
14
+ });
15
+ }
16
+ export async function getStorage(option) {
17
+ const { key } = option;
18
+ return runTaroApi('getStorage', option, async () => {
19
+ const storage = await appGetStorage({
20
+ key
21
+ });
22
+ return {
23
+ data: storage.data,
24
+ ...buildOkCallbackResult('getStorage')
25
+ };
26
+ });
27
+ }
28
+ export function getStorageSync(key) {
29
+ return appGetStorageSync({
30
+ key
31
+ }).data;
32
+ }
33
+ export async function removeStorage(option) {
34
+ return runCallbackApi('removeStorage', option, () => appRemoveStorage({
35
+ key: option.key
36
+ }));
37
+ }
38
+ export function removeStorageSync(key) {
39
+ appRemoveStorageSync({
40
+ key
41
+ });
42
+ }
43
+ export async function clearStorage(option) {
44
+ return runCallbackApi('clearStorage', option, () => appClearStorage());
45
+ }
46
+ export function clearStorageSync() {
47
+ appClearStorageSync();
48
+ }
49
+ export async function getStorageInfo(option) {
50
+ return runTaroApi('getStorageInfo', option, () => appGetStorageInfo(), () => buildOkCallbackResult('getStorageInfo'));
51
+ }
52
+ export function getStorageInfoSync() {
53
+ return appGetStorageInfoSync();
54
+ }
55
+ //# sourceMappingURL=index.js.map
@@ -1,7 +1,19 @@
1
1
  import type Taro from '@tarojs/taro';
2
+ import type { getNetworkType as taroGetNetworkType } from '@tarojs/taro';
3
+ import type { getScreenBrightness as taroGetScreenBrightness } from '@tarojs/taro';
4
+ type TaroMakePhoneCallOption = Parameters<typeof Taro.makePhoneCall>[0];
5
+ type TaroMakePhoneCallResult = Awaited<ReturnType<typeof Taro.makePhoneCall>>;
6
+ type TaroGetNetworkTypeOption = Parameters<typeof taroGetNetworkType>[0];
7
+ type TaroGetNetworkTypeResult = Awaited<ReturnType<typeof taroGetNetworkType>>;
8
+ type TaroGetScreenBrightnessOption = Parameters<typeof taroGetScreenBrightness>[0];
9
+ type TaroGetScreenBrightnessResult = Awaited<ReturnType<typeof taroGetScreenBrightness>>;
2
10
  export declare function getSystemSetting(): Taro.getSystemSetting.Result;
3
11
  export declare function getAppAuthorizeSetting(): Taro.getAppAuthorizeSetting.Result;
4
12
  export declare function getDeviceInfo(): Taro.getDeviceInfo.Result;
5
13
  export declare function getAppBaseInfo(): Taro.getAppBaseInfo.Result;
6
14
  export declare function getWindowInfo(): Taro.getWindowInfo.Result;
15
+ export declare function makePhoneCall(option: TaroMakePhoneCallOption): Promise<TaroMakePhoneCallResult>;
16
+ export declare function getNetworkType(option?: TaroGetNetworkTypeOption): Promise<TaroGetNetworkTypeResult>;
17
+ export declare function getScreenBrightness(option?: TaroGetScreenBrightnessOption): Promise<TaroGetScreenBrightnessResult>;
18
+ export {};
7
19
  //# sourceMappingURL=index.d.ts.map
@@ -1,3 +1,5 @@
1
+ import { getAppBaseInfoSync, getWindowInfoSync, makePhoneCall as appMakePhoneCall, getNetworkType as appGetNetworkType, getScreenBrightness as appGetScreenBrightness } from '@byted-doubao-apps/framework/api';
2
+ import { buildFailCallbackResult, emitFailure, runCallbackApi, runTaroApi } from '../utils.js';
1
3
  export function getSystemSetting() {
2
4
  return {};
3
5
  }
@@ -28,17 +30,45 @@ export function getDeviceInfo() {
28
30
  };
29
31
  }
30
32
  export function getAppBaseInfo() {
31
- return {
32
- language: 'zh_CN'
33
- };
33
+ return getAppBaseInfoSync();
34
34
  }
35
35
  export function getWindowInfo() {
36
- return {
37
- pixelRatio: 1,
38
- screenWidth: 0,
39
- screenHeight: 0,
40
- windowWidth: 0,
41
- windowHeight: 0
42
- };
36
+ return getWindowInfoSync();
37
+ }
38
+ export async function makePhoneCall(option) {
39
+ const { phoneNumber } = option;
40
+ if (typeof phoneNumber !== 'string' || phoneNumber.length === 0) {
41
+ const result = buildFailCallbackResult('makePhoneCall', 'phoneNumber is required');
42
+ emitFailure(option, result);
43
+ return Promise.reject(result);
44
+ }
45
+ const params = { phoneNumber };
46
+ return runCallbackApi('makePhoneCall', option, () => appMakePhoneCall(params));
47
+ }
48
+ export async function getNetworkType(option = {}) {
49
+ return runTaroApi('getNetworkType', option, async () => {
50
+ const response = await appGetNetworkType({});
51
+ return {
52
+ networkType: response.networkType,
53
+ signalStrength: typeof response.signalStrength === 'number' ? response.signalStrength : undefined,
54
+ hasSystemProxy: typeof response.hasSystemProxy === 'boolean' ? response.hasSystemProxy : undefined,
55
+ weakNet: typeof response.weakNet === 'boolean' ? response.weakNet : undefined,
56
+ errMsg: 'getNetworkType:ok'
57
+ };
58
+ });
59
+ }
60
+ export async function getScreenBrightness(option = {}) {
61
+ return runTaroApi('getScreenBrightness', option, async () => {
62
+ const response = await appGetScreenBrightness();
63
+ const value = typeof response?.value === 'number' ? response.value : 0;
64
+ const errMsg = response?.errMsg;
65
+ if (typeof errMsg === 'string' && errMsg.startsWith('getScreenBrightness:')) {
66
+ return { value, errMsg };
67
+ }
68
+ return {
69
+ value,
70
+ errMsg: 'getScreenBrightness:ok'
71
+ };
72
+ });
43
73
  }
44
74
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,21 @@
1
+ export interface CallbackHooks<TSuccess, TFail = TaroGeneral.CallbackResult, TComplete = TSuccess | TFail> {
2
+ success?: (result: TSuccess) => void;
3
+ fail?: (result: TFail) => void;
4
+ complete?: (result: TComplete) => void;
5
+ }
6
+ type MaybePromise<T> = T | Promise<T>;
7
+ export declare function emitSuccess<TSuccess, TComplete = TSuccess>(callbacks: Partial<CallbackHooks<TSuccess, never, TComplete>> | undefined, successResult: TSuccess, completeResult?: TComplete): void;
8
+ export declare function emitFailure<TFail, TComplete = TFail>(callbacks: Partial<CallbackHooks<never, TFail, TComplete>> | undefined, result: TFail): void;
9
+ export declare function runAsyncApi<TSuccess, TFail, TComplete = TSuccess | TFail>({ callbacks, run, buildFailResult, buildCompleteResult }: {
10
+ callbacks: Partial<CallbackHooks<TSuccess, TFail, TComplete>> | undefined;
11
+ run: () => MaybePromise<TSuccess>;
12
+ buildFailResult: (error: unknown) => TFail;
13
+ buildCompleteResult?: (result: TSuccess) => TComplete;
14
+ }): Promise<TSuccess>;
15
+ export declare function normalizeErrorMessage(error: unknown, fallbackMessage?: string): string;
16
+ export declare function buildOkCallbackResult(apiName: string): TaroGeneral.CallbackResult;
17
+ export declare function buildFailCallbackResult(apiName: string, error: unknown, fallbackMessage?: string): TaroGeneral.CallbackResult;
18
+ export declare function runCallbackApi(apiName: string, callbacks: Partial<CallbackHooks<TaroGeneral.CallbackResult>> | undefined, run: () => MaybePromise<unknown>): Promise<TaroGeneral.CallbackResult>;
19
+ export declare function runTaroApi<TSuccess, TComplete = TSuccess>(apiName: string, callbacks: Partial<CallbackHooks<TSuccess, TaroGeneral.CallbackResult, TComplete>> | undefined, run: () => MaybePromise<TSuccess>, buildCompleteResult?: (result: TSuccess) => TComplete): Promise<TSuccess>;
20
+ export {};
21
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1,65 @@
1
+ export function emitSuccess(callbacks, successResult, completeResult) {
2
+ callbacks?.success?.(successResult);
3
+ callbacks?.complete?.(completeResult ?? successResult);
4
+ }
5
+ export function emitFailure(callbacks, result) {
6
+ callbacks?.fail?.(result);
7
+ callbacks?.complete?.(result);
8
+ }
9
+ export async function runAsyncApi({ callbacks, run, buildFailResult, buildCompleteResult }) {
10
+ try {
11
+ const result = await run();
12
+ emitSuccess(callbacks, result, buildCompleteResult?.(result));
13
+ return result;
14
+ }
15
+ catch (error) {
16
+ const result = buildFailResult(error);
17
+ emitFailure(callbacks, result);
18
+ return Promise.reject(result);
19
+ }
20
+ }
21
+ export function normalizeErrorMessage(error, fallbackMessage) {
22
+ if (typeof error === 'string') {
23
+ return error;
24
+ }
25
+ if (error && typeof error === 'object' && 'errMsg' in error && typeof error.errMsg === 'string') {
26
+ return error.errMsg;
27
+ }
28
+ if (error instanceof Error) {
29
+ return error.message;
30
+ }
31
+ if (typeof fallbackMessage === 'string') {
32
+ return fallbackMessage;
33
+ }
34
+ return String(error);
35
+ }
36
+ function buildCallbackResult(apiName, status, detail) {
37
+ return {
38
+ errMsg: detail ? `${apiName}:${status} ${detail}` : `${apiName}:${status}`
39
+ };
40
+ }
41
+ export function buildOkCallbackResult(apiName) {
42
+ return buildCallbackResult(apiName, 'ok');
43
+ }
44
+ export function buildFailCallbackResult(apiName, error, fallbackMessage) {
45
+ return buildCallbackResult(apiName, 'fail', normalizeErrorMessage(error, fallbackMessage));
46
+ }
47
+ export function runCallbackApi(apiName, callbacks, run) {
48
+ return runAsyncApi({
49
+ callbacks,
50
+ run: async () => {
51
+ await run();
52
+ return buildOkCallbackResult(apiName);
53
+ },
54
+ buildFailResult: (error) => buildFailCallbackResult(apiName, error)
55
+ });
56
+ }
57
+ export function runTaroApi(apiName, callbacks, run, buildCompleteResult) {
58
+ return runAsyncApi({
59
+ callbacks,
60
+ run,
61
+ buildFailResult: (error) => buildFailCallbackResult(apiName, error),
62
+ buildCompleteResult
63
+ });
64
+ }
65
+ //# sourceMappingURL=utils.js.map
@@ -1,6 +1,7 @@
1
1
  type ImageProps = {
2
2
  src?: string;
3
+ mode?: string;
3
4
  } & Record<string, unknown>;
4
- export declare function Image({ src, ...rest }: ImageProps): any;
5
+ export declare function Image({ src, mode, ...rest }: ImageProps): any;
5
6
  export {};
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -1,7 +1,8 @@
1
- export function Image({ src, ...rest }) {
1
+ export function Image({ src, mode, ...rest }) {
2
2
  if (src?.endsWith('.svg') || src?.startsWith('data:image/svg')) {
3
3
  return <svg src={src} {...rest}/>;
4
4
  }
5
- return <image src={src} {...rest}/>;
5
+ // @ts-expect-error
6
+ return <image {...rest} src={src ?? ''} mode={mode === 'widthFix' ? 'aspectFit' : mode}/>;
6
7
  }
7
8
  //# sourceMappingURL=index.jsx.map