@doubao-apps/taro-runtime 0.0.25 → 0.0.27

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.
@@ -3,7 +3,15 @@ type TaroStartAccelerometerOption = Parameters<typeof Taro.startAccelerometer>[0
3
3
  type TaroStartAccelerometerResult = Awaited<ReturnType<typeof Taro.startAccelerometer>>;
4
4
  type TaroStopAccelerometerOption = Parameters<typeof Taro.stopAccelerometer>[0];
5
5
  type TaroStopAccelerometerResult = Awaited<ReturnType<typeof Taro.stopAccelerometer>>;
6
+ type TaroAccelerometerChangeCallback = Parameters<typeof Taro.onAccelerometerChange>[0];
7
+ type TaroAccelerometerChangeCallbackResult = Parameters<TaroAccelerometerChangeCallback>[0];
8
+ type AccelerometerChangeCallbackResult = TaroAccelerometerChangeCallbackResult & {
9
+ timestamp: number;
10
+ };
11
+ type AccelerometerChangeCallback = (result: AccelerometerChangeCallbackResult) => void;
6
12
  export declare function startAccelerometer(option?: TaroStartAccelerometerOption): Promise<TaroStartAccelerometerResult>;
7
13
  export declare function stopAccelerometer(option?: TaroStopAccelerometerOption): Promise<TaroStopAccelerometerResult>;
14
+ export declare function onAccelerometerChange(callback: AccelerometerChangeCallback): void;
15
+ export declare function offAccelerometerChange(callback?: AccelerometerChangeCallback): void;
8
16
  export {};
9
17
  //# sourceMappingURL=accelerometer.d.ts.map
@@ -1,5 +1,6 @@
1
1
  import * as appFrameworkApi from '@byted-doubao-apps/framework/api';
2
2
  import { runCallbackApi } from '../utils.js';
3
+ const accelerometerChangeCallbacks = new Map();
3
4
  export async function startAccelerometer(option) {
4
5
  return runCallbackApi('startAccelerometer', option, () => appFrameworkApi.startAccelerometer({
5
6
  interval: option?.interval
@@ -8,4 +9,34 @@ export async function startAccelerometer(option) {
8
9
  export async function stopAccelerometer(option) {
9
10
  return runCallbackApi('stopAccelerometer', option, () => appFrameworkApi.stopAccelerometer({}));
10
11
  }
12
+ export function onAccelerometerChange(callback) {
13
+ if (typeof callback !== 'function' || accelerometerChangeCallbacks.has(callback)) {
14
+ return;
15
+ }
16
+ const unregister = appFrameworkApi.onAccelerometerChange((event) => {
17
+ callback({
18
+ x: event.x,
19
+ y: event.y,
20
+ z: event.z,
21
+ timestamp: event.timestamp
22
+ });
23
+ });
24
+ accelerometerChangeCallbacks.set(callback, unregister);
25
+ }
26
+ export function offAccelerometerChange(callback) {
27
+ if (typeof callback === 'function') {
28
+ const unregister = accelerometerChangeCallbacks.get(callback);
29
+ if (!unregister) {
30
+ return;
31
+ }
32
+ unregister();
33
+ accelerometerChangeCallbacks.delete(callback);
34
+ return;
35
+ }
36
+ if (callback !== undefined) {
37
+ return;
38
+ }
39
+ accelerometerChangeCallbacks.forEach((unregister) => unregister());
40
+ accelerometerChangeCallbacks.clear();
41
+ }
11
42
  //# sourceMappingURL=accelerometer.js.map
@@ -1,6 +1,12 @@
1
1
  import type Taro from '@tarojs/taro';
2
2
  type TaroGetBatteryInfoOption = Parameters<typeof Taro.getBatteryInfo>[0];
3
3
  type TaroGetBatteryInfoResult = Awaited<ReturnType<typeof Taro.getBatteryInfo>>;
4
+ type BatteryInfoChangeCallbackResult = {
5
+ isLowPowerModeEnabled: boolean;
6
+ };
7
+ type BatteryInfoChangeCallback = (result: BatteryInfoChangeCallbackResult) => void;
4
8
  export declare function getBatteryInfo(option?: TaroGetBatteryInfoOption): Promise<TaroGetBatteryInfoResult>;
9
+ export declare function onBatteryInfoChange(callback: BatteryInfoChangeCallback): void;
10
+ export declare function offBatteryInfoChange(callback?: BatteryInfoChangeCallback): void;
5
11
  export {};
6
12
  //# sourceMappingURL=battery.d.ts.map
@@ -1,5 +1,6 @@
1
1
  import * as appFrameworkApi from '@byted-doubao-apps/framework/api';
2
2
  import { buildOkCallbackResult, runTaroApi } from '../utils.js';
3
+ const batteryInfoChangeCallbacks = new Map();
3
4
  function buildGetBatteryInfoResult(result) {
4
5
  return {
5
6
  isCharging: Boolean(result.isCharging),
@@ -10,4 +11,31 @@ function buildGetBatteryInfoResult(result) {
10
11
  export async function getBatteryInfo(option) {
11
12
  return runTaroApi('getBatteryInfo', option, async () => buildGetBatteryInfoResult(await appFrameworkApi.getBatteryInfo({})));
12
13
  }
14
+ export function onBatteryInfoChange(callback) {
15
+ if (typeof callback !== 'function' || batteryInfoChangeCallbacks.has(callback)) {
16
+ return;
17
+ }
18
+ const unregister = appFrameworkApi.onBatteryInfoChange((event) => {
19
+ callback({
20
+ isLowPowerModeEnabled: Boolean(event.isLowPowerModeEnabled)
21
+ });
22
+ });
23
+ batteryInfoChangeCallbacks.set(callback, unregister);
24
+ }
25
+ export function offBatteryInfoChange(callback) {
26
+ if (typeof callback === 'function') {
27
+ const unregister = batteryInfoChangeCallbacks.get(callback);
28
+ if (!unregister) {
29
+ return;
30
+ }
31
+ unregister();
32
+ batteryInfoChangeCallbacks.delete(callback);
33
+ return;
34
+ }
35
+ if (callback !== undefined) {
36
+ return;
37
+ }
38
+ batteryInfoChangeCallbacks.forEach((unregister) => unregister());
39
+ batteryInfoChangeCallbacks.clear();
40
+ }
13
41
  //# sourceMappingURL=battery.js.map
@@ -3,7 +3,10 @@ type TaroStartCompassOption = Parameters<typeof Taro.startCompass>[0];
3
3
  type TaroStartCompassResult = Awaited<ReturnType<typeof Taro.startCompass>>;
4
4
  type TaroStopCompassOption = Parameters<typeof Taro.stopCompass>[0];
5
5
  type TaroStopCompassResult = Awaited<ReturnType<typeof Taro.stopCompass>>;
6
+ type CompassChangeCallback = Parameters<typeof Taro.onCompassChange>[0];
6
7
  export declare function startCompass(option?: TaroStartCompassOption): Promise<TaroStartCompassResult>;
7
8
  export declare function stopCompass(option?: TaroStopCompassOption): Promise<TaroStopCompassResult>;
9
+ export declare function onCompassChange(callback: CompassChangeCallback): void;
10
+ export declare function offCompassChange(callback?: CompassChangeCallback): void;
8
11
  export {};
9
12
  //# sourceMappingURL=compass.d.ts.map
@@ -1,9 +1,37 @@
1
1
  import * as appFrameworkApi from '@byted-doubao-apps/framework/api';
2
2
  import { runCallbackApi } from '../utils.js';
3
+ const compassChangeCallbacks = new Map();
3
4
  export async function startCompass(option) {
4
5
  return runCallbackApi('startCompass', option, () => appFrameworkApi.startCompass({}));
5
6
  }
6
7
  export async function stopCompass(option) {
7
8
  return runCallbackApi('stopCompass', option, () => appFrameworkApi.stopCompass({}));
8
9
  }
10
+ export function onCompassChange(callback) {
11
+ if (typeof callback !== 'function' || compassChangeCallbacks.has(callback)) {
12
+ return;
13
+ }
14
+ const unregister = appFrameworkApi.onCompassChange((event) => {
15
+ callback({
16
+ direction: event.direction
17
+ });
18
+ });
19
+ compassChangeCallbacks.set(callback, unregister);
20
+ }
21
+ export function offCompassChange(callback) {
22
+ if (typeof callback === 'function') {
23
+ const unregister = compassChangeCallbacks.get(callback);
24
+ if (!unregister) {
25
+ return;
26
+ }
27
+ unregister();
28
+ compassChangeCallbacks.delete(callback);
29
+ return;
30
+ }
31
+ if (callback !== undefined) {
32
+ return;
33
+ }
34
+ compassChangeCallbacks.forEach((unregister) => unregister());
35
+ compassChangeCallbacks.clear();
36
+ }
9
37
  //# sourceMappingURL=compass.js.map
@@ -3,7 +3,15 @@ type TaroStartGyroscopeOption = Parameters<typeof Taro.startGyroscope>[0];
3
3
  type TaroStartGyroscopeResult = Awaited<ReturnType<typeof Taro.startGyroscope>>;
4
4
  type TaroStopGyroscopeOption = Parameters<typeof Taro.stopGyroscope>[0];
5
5
  type TaroStopGyroscopeResult = Awaited<ReturnType<typeof Taro.stopGyroscope>>;
6
+ type TaroGyroscopeChangeCallback = Parameters<typeof Taro.onGyroscopeChange>[0];
7
+ type TaroGyroscopeChangeCallbackResult = Parameters<TaroGyroscopeChangeCallback>[0];
8
+ type GyroscopeChangeCallbackResult = TaroGyroscopeChangeCallbackResult & {
9
+ timestamp: number;
10
+ };
11
+ type GyroscopeChangeCallback = (result: GyroscopeChangeCallbackResult) => void;
6
12
  export declare function startGyroscope(option: TaroStartGyroscopeOption): Promise<TaroStartGyroscopeResult>;
7
13
  export declare function stopGyroscope(option?: TaroStopGyroscopeOption): Promise<TaroStopGyroscopeResult>;
14
+ export declare function onGyroscopeChange(callback: GyroscopeChangeCallback): void;
15
+ export declare function offGyroscopeChange(callback?: GyroscopeChangeCallback): void;
8
16
  export {};
9
17
  //# sourceMappingURL=gyroscope.d.ts.map
@@ -1,5 +1,6 @@
1
1
  import * as appFrameworkApi from '@byted-doubao-apps/framework/api';
2
2
  import { runCallbackApi } from '../utils.js';
3
+ const gyroscopeChangeCallbacks = new Map();
3
4
  export async function startGyroscope(option) {
4
5
  return runCallbackApi('startGyroscope', option, () => appFrameworkApi.startGyroscope({
5
6
  interval: option.interval
@@ -8,4 +9,34 @@ export async function startGyroscope(option) {
8
9
  export async function stopGyroscope(option) {
9
10
  return runCallbackApi('stopGyroscope', option, () => appFrameworkApi.stopGyroscope({}));
10
11
  }
12
+ export function onGyroscopeChange(callback) {
13
+ if (typeof callback !== 'function' || gyroscopeChangeCallbacks.has(callback)) {
14
+ return;
15
+ }
16
+ const unregister = appFrameworkApi.onGyroscopeChange((event) => {
17
+ callback({
18
+ x: event.x,
19
+ y: event.y,
20
+ z: event.z,
21
+ timestamp: event.timestamp
22
+ });
23
+ });
24
+ gyroscopeChangeCallbacks.set(callback, unregister);
25
+ }
26
+ export function offGyroscopeChange(callback) {
27
+ if (typeof callback === 'function') {
28
+ const unregister = gyroscopeChangeCallbacks.get(callback);
29
+ if (!unregister) {
30
+ return;
31
+ }
32
+ unregister();
33
+ gyroscopeChangeCallbacks.delete(callback);
34
+ return;
35
+ }
36
+ if (callback !== undefined) {
37
+ return;
38
+ }
39
+ gyroscopeChangeCallbacks.forEach((unregister) => unregister());
40
+ gyroscopeChangeCallbacks.clear();
41
+ }
11
42
  //# sourceMappingURL=gyroscope.js.map
@@ -11,7 +11,6 @@ export * from './contact.js';
11
11
  export * from './crypto.js';
12
12
  export * from './device-motion.js';
13
13
  export * from './gyroscope.js';
14
- export * from './hce.js';
15
14
  export * from './keyboard.js';
16
15
  export * from './network.js';
17
16
  export * from './scan.js';
@@ -11,7 +11,6 @@ export * from './contact.js';
11
11
  export * from './crypto.js';
12
12
  export * from './device-motion.js';
13
13
  export * from './gyroscope.js';
14
- export * from './hce.js';
15
14
  export * from './keyboard.js';
16
15
  export * from './network.js';
17
16
  export * from './scan.js';
@@ -5,8 +5,11 @@ type TaroSetScreenBrightnessOption = Parameters<typeof Taro.setScreenBrightness>
5
5
  type TaroSetScreenBrightnessResult = Awaited<ReturnType<typeof Taro.setScreenBrightness>>;
6
6
  type TaroSetKeepScreenOnOption = Parameters<typeof Taro.setKeepScreenOn>[0];
7
7
  type TaroSetKeepScreenOnResult = Awaited<ReturnType<typeof Taro.setKeepScreenOn>>;
8
+ type UserCaptureScreenCallback = (result: TaroGeneral.CallbackResult) => void;
8
9
  export declare function setVisualEffectOnCapture(option: TaroSetVisualEffectOnCaptureOption): Promise<TaroSetVisualEffectOnCaptureResult>;
9
10
  export declare function setScreenBrightness(option: TaroSetScreenBrightnessOption): Promise<TaroSetScreenBrightnessResult>;
10
11
  export declare function setKeepScreenOn(option: TaroSetKeepScreenOnOption): Promise<TaroSetKeepScreenOnResult>;
12
+ export declare function onUserCaptureScreen(callback: UserCaptureScreenCallback): void;
13
+ export declare function offUserCaptureScreen(callback?: UserCaptureScreenCallback): void;
11
14
  export {};
12
15
  //# sourceMappingURL=screen.d.ts.map
@@ -1,5 +1,6 @@
1
1
  import * as appFrameworkApi from '@byted-doubao-apps/framework/api';
2
- import { runCallbackApi } from '../utils.js';
2
+ import { buildOkCallbackResult, runCallbackApi } from '../utils.js';
3
+ const userCaptureScreenCallbacks = new Map();
3
4
  export async function setVisualEffectOnCapture(option) {
4
5
  return runCallbackApi('setVisualEffectOnCapture', option, () => appFrameworkApi.setVisualEffectOnCapture({
5
6
  visualEffect: option.visualEffect
@@ -15,4 +16,29 @@ export async function setKeepScreenOn(option) {
15
16
  keepScreenOn: option.keepScreenOn
16
17
  }));
17
18
  }
19
+ export function onUserCaptureScreen(callback) {
20
+ if (typeof callback !== 'function' || userCaptureScreenCallbacks.has(callback)) {
21
+ return;
22
+ }
23
+ const unregister = appFrameworkApi.onUserCaptureScreen(() => {
24
+ callback(buildOkCallbackResult('onUserCaptureScreen'));
25
+ });
26
+ userCaptureScreenCallbacks.set(callback, unregister);
27
+ }
28
+ export function offUserCaptureScreen(callback) {
29
+ if (typeof callback === 'function') {
30
+ const unregister = userCaptureScreenCallbacks.get(callback);
31
+ if (!unregister) {
32
+ return;
33
+ }
34
+ unregister();
35
+ userCaptureScreenCallbacks.delete(callback);
36
+ return;
37
+ }
38
+ if (callback !== undefined) {
39
+ return;
40
+ }
41
+ userCaptureScreenCallbacks.forEach((unregister) => unregister());
42
+ userCaptureScreenCallbacks.clear();
43
+ }
18
44
  //# sourceMappingURL=screen.js.map
@@ -1,4 +1,3 @@
1
1
  export * from './beacon.js';
2
- export * from './hce.js';
3
2
  export * from './wifi.js';
4
3
  //# sourceMappingURL=wireless.d.ts.map
@@ -1,4 +1,3 @@
1
1
  export * from './beacon.js';
2
- export * from './hce.js';
3
2
  export * from './wifi.js';
4
3
  //# sourceMappingURL=wireless.js.map
@@ -1,11 +1,13 @@
1
1
  export { getEnv, ENV_TYPE } from './base/index.js';
2
2
  export * from './device/index.js';
3
3
  export * from './device/index.js';
4
+ export * from './media/index.js';
4
5
  export { request } from './request/index.js';
5
6
  export { exitMiniProgram, navigateBack, navigateTo, getCurrentPages, reLaunch, redirectTo } from './router/index.js';
6
7
  export { setStorage, setStorageSync, getStorage, getStorageSync, removeStorage, removeStorageSync, clearStorage, clearStorageSync, getStorageInfo, getStorageInfoSync } from './storage/index.js';
7
8
  export * from './system/index.js';
8
9
  export { getLocation } from './location/index.js';
10
+ export { disableAlertBeforeUnload, enableAlertBeforeUnload, hideLoading, hideToast, showActionSheet, showLoading, showModal } from './interaction/index.js';
9
11
  export { showToast } from './show-toast/index.js';
10
12
  export { createMapContext } from './map/index.js';
11
13
  export { createSelectorQuery } from './create-selector-query/index.js';
package/dist/api/index.js CHANGED
@@ -1,11 +1,13 @@
1
1
  export { getEnv, ENV_TYPE } from './base/index.js';
2
2
  export * from './device/index.js';
3
3
  export * from './device/index.js';
4
+ export * from './media/index.js';
4
5
  export { request } from './request/index.js';
5
6
  export { exitMiniProgram, navigateBack, navigateTo, getCurrentPages, reLaunch, redirectTo } from './router/index.js';
6
7
  export { setStorage, setStorageSync, getStorage, getStorageSync, removeStorage, removeStorageSync, clearStorage, clearStorageSync, getStorageInfo, getStorageInfoSync } from './storage/index.js';
7
8
  export * from './system/index.js';
8
9
  export { getLocation } from './location/index.js';
10
+ export { disableAlertBeforeUnload, enableAlertBeforeUnload, hideLoading, hideToast, showActionSheet, showLoading, showModal } from './interaction/index.js';
9
11
  export { showToast } from './show-toast/index.js';
10
12
  export { createMapContext } from './map/index.js';
11
13
  export { createSelectorQuery } from './create-selector-query/index.js';
@@ -0,0 +1,24 @@
1
+ import type Taro from '@tarojs/taro';
2
+ type TaroShowModalOption = NonNullable<Parameters<typeof Taro.showModal>[0]>;
3
+ type TaroShowModalResult = Awaited<ReturnType<typeof Taro.showModal>>;
4
+ type TaroShowLoadingOption = Parameters<typeof Taro.showLoading>[0];
5
+ type TaroShowLoadingResult = Awaited<ReturnType<typeof Taro.showLoading>>;
6
+ type TaroHideToastOption = Parameters<typeof Taro.hideToast>[0];
7
+ type TaroHideToastResult = ReturnType<typeof Taro.hideToast>;
8
+ type TaroHideLoadingOption = Parameters<typeof Taro.hideLoading>[0];
9
+ type TaroHideLoadingResult = ReturnType<typeof Taro.hideLoading>;
10
+ type TaroShowActionSheetOption = Parameters<typeof Taro.showActionSheet>[0];
11
+ type TaroShowActionSheetResult = Awaited<ReturnType<typeof Taro.showActionSheet>>;
12
+ type TaroEnableAlertBeforeUnloadOption = Parameters<typeof Taro.enableAlertBeforeUnload>[0];
13
+ type TaroEnableAlertBeforeUnloadResult = ReturnType<typeof Taro.enableAlertBeforeUnload>;
14
+ type TaroDisableAlertBeforeUnloadOption = Parameters<typeof Taro.disableAlertBeforeUnload>[0];
15
+ type TaroDisableAlertBeforeUnloadResult = ReturnType<typeof Taro.disableAlertBeforeUnload>;
16
+ export declare function showModal(option?: TaroShowModalOption): Promise<TaroShowModalResult>;
17
+ export declare function showLoading(option?: TaroShowLoadingOption): Promise<TaroShowLoadingResult>;
18
+ export declare function hideToast(option?: TaroHideToastOption): TaroHideToastResult;
19
+ export declare function hideLoading(option?: TaroHideLoadingOption): TaroHideLoadingResult;
20
+ export declare function showActionSheet(option: TaroShowActionSheetOption): Promise<TaroShowActionSheetResult>;
21
+ export declare function enableAlertBeforeUnload(option: TaroEnableAlertBeforeUnloadOption): TaroEnableAlertBeforeUnloadResult;
22
+ export declare function disableAlertBeforeUnload(option?: TaroDisableAlertBeforeUnloadOption): TaroDisableAlertBeforeUnloadResult;
23
+ export {};
24
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,74 @@
1
+ import { disableAlertBeforeUnload as appDisableAlertBeforeUnload, enableAlertBeforeUnload as appEnableAlertBeforeUnload, hideLoading as appHideLoading, hideToast as appHideToast, showActionSheet as appShowActionSheet, showLoading as appShowLoading, showModal as appShowModal } from '@byted-doubao-apps/framework/api';
2
+ import { buildOkCallbackResult, runCallbackApi, runTaroApi } from '../utils.js';
3
+ function runVoidCallbackApi(apiName, callbacks, run) {
4
+ const task = runCallbackApi(apiName, callbacks, run);
5
+ void task.catch(() => undefined);
6
+ return task;
7
+ }
8
+ function buildShowModalParams(option) {
9
+ const params = {
10
+ content: typeof option?.content === 'string' ? option.content : ''
11
+ };
12
+ if (typeof option?.title === 'string') {
13
+ params.title = option.title;
14
+ }
15
+ if (typeof option?.showCancel === 'boolean') {
16
+ params.showCancel = option.showCancel;
17
+ }
18
+ if (typeof option?.cancelText === 'string') {
19
+ params.cancelText = option.cancelText;
20
+ }
21
+ if (typeof option?.confirmText === 'string') {
22
+ params.confirmText = option.confirmText;
23
+ }
24
+ return params;
25
+ }
26
+ function buildShowModalResult(result) {
27
+ return {
28
+ confirm: result.action === 'confirm',
29
+ cancel: result.action === 'cancel',
30
+ ...buildOkCallbackResult('showModal')
31
+ };
32
+ }
33
+ function buildShowActionSheetParams(option) {
34
+ const params = {
35
+ itemList: Array.isArray(option.itemList) ? option.itemList.filter((item) => typeof item === 'string') : []
36
+ };
37
+ if (typeof option.itemColor === 'string') {
38
+ params.itemColor = option.itemColor;
39
+ }
40
+ return params;
41
+ }
42
+ function buildShowActionSheetResult(result) {
43
+ return {
44
+ tapIndex: typeof result.tapIndex === 'number' ? result.tapIndex : 0,
45
+ ...buildOkCallbackResult('showActionSheet')
46
+ };
47
+ }
48
+ function buildEnableAlertBeforeUnloadParams(option) {
49
+ return {
50
+ message: typeof option.message === 'string' ? option.message : ''
51
+ };
52
+ }
53
+ export async function showModal(option) {
54
+ return runTaroApi('showModal', option, async () => buildShowModalResult(await appShowModal(buildShowModalParams(option))));
55
+ }
56
+ export async function showLoading(option) {
57
+ return runCallbackApi('showLoading', option, () => appShowLoading({}));
58
+ }
59
+ export function hideToast(option) {
60
+ return runVoidCallbackApi('hideToast', option, () => appHideToast(option));
61
+ }
62
+ export function hideLoading(option) {
63
+ return runVoidCallbackApi('hideLoading', option, () => appHideLoading(option));
64
+ }
65
+ export async function showActionSheet(option) {
66
+ return runTaroApi('showActionSheet', option, async () => buildShowActionSheetResult(await appShowActionSheet(buildShowActionSheetParams(option))));
67
+ }
68
+ export function enableAlertBeforeUnload(option) {
69
+ return runVoidCallbackApi('enableAlertBeforeUnload', option, () => appEnableAlertBeforeUnload(buildEnableAlertBeforeUnloadParams(option)));
70
+ }
71
+ export function disableAlertBeforeUnload(option) {
72
+ return runVoidCallbackApi('disableAlertBeforeUnload', option, () => appDisableAlertBeforeUnload({}));
73
+ }
74
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,18 @@
1
+ import type Taro from '@tarojs/taro';
2
+ type TaroSaveImageToPhotosAlbumOption = Parameters<typeof Taro.saveImageToPhotosAlbum>[0];
3
+ type TaroSaveImageToPhotosAlbumResult = Awaited<ReturnType<typeof Taro.saveImageToPhotosAlbum>>;
4
+ type TaroPreviewImageOption = Parameters<typeof Taro.previewImage>[0];
5
+ type TaroPreviewImageResult = Awaited<ReturnType<typeof Taro.previewImage>>;
6
+ type TaroGetImageInfoOption = Parameters<typeof Taro.getImageInfo>[0];
7
+ type TaroGetImageInfoResult = Awaited<ReturnType<typeof Taro.getImageInfo>>;
8
+ type TaroChooseImageOption = Parameters<typeof Taro.chooseImage>[0];
9
+ type TaroChooseImageResult = Awaited<ReturnType<typeof Taro.chooseImage>>;
10
+ type TaroCompressImageOption = Parameters<typeof Taro.compressImage>[0];
11
+ type TaroCompressImageResult = Awaited<ReturnType<typeof Taro.compressImage>>;
12
+ export declare function saveImageToPhotosAlbum(option: TaroSaveImageToPhotosAlbumOption): Promise<TaroSaveImageToPhotosAlbumResult>;
13
+ export declare function previewImage(option: TaroPreviewImageOption): Promise<TaroPreviewImageResult>;
14
+ export declare function getImageInfo(option: TaroGetImageInfoOption): Promise<TaroGetImageInfoResult>;
15
+ export declare function chooseImage(option?: TaroChooseImageOption): Promise<TaroChooseImageResult>;
16
+ export declare function compressImage(option: TaroCompressImageOption): Promise<TaroCompressImageResult>;
17
+ export {};
18
+ //# sourceMappingURL=image.d.ts.map
@@ -0,0 +1,62 @@
1
+ import * as appFrameworkApi from '@byted-doubao-apps/framework/api';
2
+ import { buildOkCallbackResult, runCallbackApi, runTaroApi } from '../utils.js';
3
+ function buildGetImageInfoResult(result, src) {
4
+ return {
5
+ height: result.height ?? 0,
6
+ orientation: result.orientation ?? 'up',
7
+ path: result.path ?? src,
8
+ type: result.type ?? '',
9
+ width: result.width ?? 0,
10
+ ...buildOkCallbackResult('getImageInfo')
11
+ };
12
+ }
13
+ function buildChooseImageResult(result) {
14
+ const tempFiles = result.tempFiles ?? result.tempFilePaths.map((path) => ({ path, size: 0 }));
15
+ const tempFilePaths = result.tempFilePaths ?? tempFiles.map((file) => file.path);
16
+ return {
17
+ tempFilePaths,
18
+ tempFiles,
19
+ ...buildOkCallbackResult('chooseImage')
20
+ };
21
+ }
22
+ function buildCompressImageResult(result) {
23
+ return {
24
+ tempFilePath: result.tempFilePath ?? '',
25
+ ...buildOkCallbackResult('compressImage')
26
+ };
27
+ }
28
+ export async function saveImageToPhotosAlbum(option) {
29
+ return runCallbackApi('saveImageToPhotosAlbum', option, () => appFrameworkApi.saveImageToPhotosAlbum({
30
+ filePath: option.filePath
31
+ }));
32
+ }
33
+ export async function previewImage(option) {
34
+ return runCallbackApi('previewImage', option, () => appFrameworkApi.previewImage({
35
+ urls: option.urls,
36
+ current: option.current,
37
+ showmenu: option.showmenu,
38
+ referrerPolicy: option.referrerPolicy
39
+ }));
40
+ }
41
+ export async function getImageInfo(option) {
42
+ return runTaroApi('getImageInfo', option, async () => buildGetImageInfoResult(await appFrameworkApi.getImageInfo({
43
+ src: option.src
44
+ }), option.src));
45
+ }
46
+ export async function chooseImage(option = {}) {
47
+ return runTaroApi('chooseImage', option, async () => buildChooseImageResult(await appFrameworkApi.chooseImage({
48
+ count: option.count,
49
+ sizeType: option.sizeType,
50
+ sourceType: option.sourceType,
51
+ imageId: option.imageId
52
+ })));
53
+ }
54
+ export async function compressImage(option) {
55
+ return runTaroApi('compressImage', option, async () => buildCompressImageResult(await appFrameworkApi.compressImage({
56
+ src: option.src,
57
+ quality: option.quality,
58
+ compressedWidth: option.compressedWidth,
59
+ compressedHeight: option.compressedHeight
60
+ })));
61
+ }
62
+ //# sourceMappingURL=image.js.map
@@ -0,0 +1,2 @@
1
+ export * from './image.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,2 @@
1
+ export * from './image.js';
2
+ //# sourceMappingURL=index.js.map
@@ -9,16 +9,21 @@ type TaroGetScreenBrightnessOption = Parameters<typeof taroGetScreenBrightness>[
9
9
  type TaroGetScreenBrightnessResult = Awaited<ReturnType<typeof taroGetScreenBrightness>>;
10
10
  type TaroSetClipboardDataOption = Parameters<typeof Taro.setClipboardData>[0];
11
11
  type TaroSetClipboardDataResult = Awaited<ReturnType<typeof Taro.setClipboardData>>;
12
+ type TaroMenuButtonBoundingClientRect = ReturnType<typeof Taro.getMenuButtonBoundingClientRect>;
12
13
  type KeyboardHeightChangeCallback = Parameters<typeof Taro.onKeyboardHeightChange>[0];
14
+ type NetworkStatusChangeCallback = Parameters<typeof Taro.onNetworkStatusChange>[0];
13
15
  export declare function getSystemSetting(): Taro.getSystemSetting.Result;
14
16
  export declare function getAppAuthorizeSetting(): Taro.getAppAuthorizeSetting.Result;
15
17
  export declare function getDeviceInfo(): Taro.getDeviceInfo.Result;
16
18
  export declare function getAppBaseInfo(): Taro.getAppBaseInfo.Result;
17
19
  export declare function getWindowInfo(): Taro.getWindowInfo.Result;
20
+ export declare function getMenuButtonBoundingClientRect(): TaroMenuButtonBoundingClientRect;
18
21
  export declare function makePhoneCall(option: TaroMakePhoneCallOption): Promise<TaroMakePhoneCallResult>;
19
22
  export declare function getNetworkType(option?: TaroGetNetworkTypeOption): Promise<TaroGetNetworkTypeResult>;
20
23
  export declare function getScreenBrightness(option?: TaroGetScreenBrightnessOption): Promise<TaroGetScreenBrightnessResult>;
21
24
  export declare function setClipboardData(option: TaroSetClipboardDataOption): Promise<TaroSetClipboardDataResult>;
22
25
  export declare function onKeyboardHeightChange(callback: KeyboardHeightChangeCallback): void;
26
+ export declare function onNetworkStatusChange(callback: NetworkStatusChangeCallback): void;
27
+ export declare function offNetworkStatusChange(callback?: NetworkStatusChangeCallback): void;
23
28
  export {};
24
29
  //# sourceMappingURL=index.d.ts.map
@@ -1,5 +1,6 @@
1
- import { getAppBaseInfoSync, getWindowInfoSync, makePhoneCall as appMakePhoneCall, getNetworkType as appGetNetworkType, getScreenBrightness as appGetScreenBrightness, setClipboardData as appSetClipboardData, onKeyboardHeightChange as appOnKeyboardHeightChange } from '@byted-doubao-apps/framework/api';
1
+ import { getAppBaseInfoSync, getMenuButtonBoundingClientRect as appGetMenuButtonBoundingClientRect, getSystemSetting as appGetSystemSetting, getWindowInfoSync, makePhoneCall as appMakePhoneCall, getNetworkType as appGetNetworkType, onNetworkStatusChange as appOnNetworkStatusChange, getScreenBrightness as appGetScreenBrightness, setClipboardData as appSetClipboardData, onKeyboardHeightChange as appOnKeyboardHeightChange } from '@byted-doubao-apps/framework/api';
2
2
  import { buildFailCallbackResult, emitFailure, runCallbackApi, runTaroApi } from '../utils.js';
3
+ const networkStatusChangeCallbacks = new Map();
3
4
  function buildVibrateShortParams(option) {
4
5
  if (option?.type === 'heavy' || option?.type === 'medium' || option?.type === 'light') {
5
6
  return { type: option.type };
@@ -7,7 +8,21 @@ function buildVibrateShortParams(option) {
7
8
  return { type: 'medium' };
8
9
  }
9
10
  export function getSystemSetting() {
10
- return {};
11
+ const result = appGetSystemSetting();
12
+ const systemSetting = {};
13
+ if (typeof result.bluetoothEnabled === 'boolean') {
14
+ systemSetting.bluetoothEnabled = result.bluetoothEnabled;
15
+ }
16
+ if (typeof result.locationEnabled === 'boolean') {
17
+ systemSetting.locationEnabled = result.locationEnabled;
18
+ }
19
+ if (typeof result.wifiEnabled === 'boolean') {
20
+ systemSetting.wifiEnabled = result.wifiEnabled;
21
+ }
22
+ if (result.deviceOrientation === 'portrait' || result.deviceOrientation === 'landscape') {
23
+ systemSetting.deviceOrientation = result.deviceOrientation;
24
+ }
25
+ return systemSetting;
11
26
  }
12
27
  export function getAppAuthorizeSetting() {
13
28
  return {
@@ -41,6 +56,9 @@ export function getAppBaseInfo() {
41
56
  export function getWindowInfo() {
42
57
  return getWindowInfoSync();
43
58
  }
59
+ export function getMenuButtonBoundingClientRect() {
60
+ return appGetMenuButtonBoundingClientRect();
61
+ }
44
62
  export async function makePhoneCall(option) {
45
63
  const { phoneNumber } = option;
46
64
  if (typeof phoneNumber !== 'string' || phoneNumber.length === 0) {
@@ -102,4 +120,33 @@ export function onKeyboardHeightChange(callback) {
102
120
  });
103
121
  });
104
122
  }
123
+ export function onNetworkStatusChange(callback) {
124
+ if (typeof callback !== 'function' || networkStatusChangeCallbacks.has(callback)) {
125
+ return;
126
+ }
127
+ const unregister = appOnNetworkStatusChange((event) => {
128
+ callback({
129
+ isConnected: event.isConnected,
130
+ networkType: event.networkType,
131
+ errMsg: 'onNetworkStatusChange:ok'
132
+ });
133
+ });
134
+ networkStatusChangeCallbacks.set(callback, unregister);
135
+ }
136
+ export function offNetworkStatusChange(callback) {
137
+ if (typeof callback === 'function') {
138
+ const unregister = networkStatusChangeCallbacks.get(callback);
139
+ if (!unregister) {
140
+ return;
141
+ }
142
+ unregister();
143
+ networkStatusChangeCallbacks.delete(callback);
144
+ return;
145
+ }
146
+ if (callback !== undefined) {
147
+ return;
148
+ }
149
+ networkStatusChangeCallbacks.forEach((unregister) => unregister());
150
+ networkStatusChangeCallbacks.clear();
151
+ }
105
152
  //# sourceMappingURL=index.js.map
@@ -1,42 +1,50 @@
1
- import { Children, cloneElement } from 'react';
2
1
  import { PickerView as DoubaoPickerView, PickerColumn as DoubaoPickerColumn } from '@byted-doubao-apps/components';
3
- import { buildOptionsFromRange, mapPickerViewProps, toPickerViewChangeEvent, warnUnsupportedPickerView } from './map.js';
2
+ import { warnUnsupported } from '../base/warn-unsupported.js';
3
+ import { buildOptionsFromChildren, buildOptionsFromRange, mapPickerViewColumnProps, mapPickerViewProps, resolveExplicitItemHeight, resolveItemHeightFromChildren, resolveSelectedIndexValue, toPickerViewChangeEvent } from './map.js';
4
+ const PICKER_VIEW_COLUMN_TYPE = 'taro-picker-view-column';
4
5
  export function PickerView(props) {
5
- const { value, onChange, children, ...rest } = props;
6
- const { mapped, unsupported } = mapPickerViewProps(rest);
7
- warnUnsupportedPickerView(unsupported);
8
- // Collect ranges from child columns to compute indices on change
9
- const ranges = [];
10
- const childrenWithProps = Children.map(children, (child, index) => {
11
- if (!child)
12
- return child;
13
- // We expect child to be <PickerViewColumn range={...} />
14
- const range = child?.props?.range;
15
- const options = buildOptionsFromRange(range);
16
- ranges[index] = options;
17
- const selectedIndex = Array.isArray(value) ? value[index] : undefined;
18
- const selectedValue = selectedIndex != null && options[selectedIndex] ? options[selectedIndex].value : undefined;
19
- return cloneElement(child, {
20
- __mappedOptions: options,
21
- __mappedValue: selectedValue
6
+ const { value, defaultValue, onChange, children, itemHeight: propItemHeight, ...rest } = props;
7
+ const { mapped, unsupported, indicatorItemHeight } = mapPickerViewProps(rest);
8
+ const explicitItemHeight = resolveExplicitItemHeight(propItemHeight);
9
+ const pickerViewId = typeof mapped.id === 'string' ? mapped.id : '';
10
+ warnUnsupported('PickerView', propItemHeight !== undefined && explicitItemHeight === undefined
11
+ ? [...unsupported, 'itemHeight must be a positive number']
12
+ : unsupported);
13
+ const columns = [];
14
+ toChildArray(children).forEach((child) => {
15
+ if (!isPickerViewColumnElement(child)) {
16
+ return;
17
+ }
18
+ const columnProps = child.props;
19
+ const { className, style, unsupported: columnUnsupported } = mapPickerViewColumnProps(columnProps);
20
+ warnUnsupported('PickerViewColumn', columnUnsupported);
21
+ columns.push({
22
+ options: Array.isArray(columnProps.range)
23
+ ? buildOptionsFromRange(columnProps.range)
24
+ : buildOptionsFromChildren(columnProps.children),
25
+ className,
26
+ style,
27
+ itemHeight: resolveItemHeightFromChildren(columnProps.children)
22
28
  });
23
29
  });
30
+ const resolvedItemHeight = explicitItemHeight ??
31
+ indicatorItemHeight ??
32
+ columns.find((column) => column.itemHeight !== undefined)?.itemHeight;
24
33
  const handleChange = (values, selectedOptions) => {
25
- // Map selected values back to indices per column
26
- const indices = values.map((val, idx) => {
27
- const opts = ranges[idx] ?? [];
28
- const found = opts.findIndex((opt) => opt.value === val);
29
- return found >= 0 ? found : 0;
34
+ const indices = values.map((selectedValue, index) => {
35
+ if (typeof selectedValue === 'number') {
36
+ return selectedValue;
37
+ }
38
+ const optionValue = selectedOptions[index]?.value;
39
+ return typeof optionValue === 'number' ? optionValue : 0;
30
40
  });
31
- onChange?.(toPickerViewChangeEvent(indices));
41
+ onChange?.(toPickerViewChangeEvent(indices, pickerViewId));
32
42
  };
33
- return (<DoubaoPickerView {...mapped} onChange={onChange ? handleChange : undefined}>
34
- {Children.map(childrenWithProps, (child) => {
35
- const options = child?.props?.__mappedOptions;
36
- const valueForColumn = child?.props?.__mappedValue;
37
- const columnClassName = child?.props?.className;
38
- const columnStyle = child?.props?.style;
39
- return (<DoubaoPickerColumn options={options ?? []} value={valueForColumn} className={columnClassName} style={columnStyle}/>);
43
+ return (<DoubaoPickerView {...mapped} itemHeight={resolvedItemHeight} onChange={onChange ? handleChange : undefined}>
44
+ {columns.map(({ options, className, style }, index) => {
45
+ const valueForColumn = resolveSelectedIndexValue(value, index, options);
46
+ const defaultValueForColumn = resolveSelectedIndexValue(defaultValue, index, options);
47
+ return (<DoubaoPickerColumn key={index} options={options} value={valueForColumn} defaultValue={defaultValueForColumn} className={className} style={style}/>);
40
48
  })}
41
49
  </DoubaoPickerView>);
42
50
  }
@@ -44,4 +52,29 @@ export function PickerViewColumn(_props) {
44
52
  // This is a placeholder wrapper. Real rendering is performed by PickerView above after mapping.
45
53
  return null;
46
54
  }
55
+ PickerViewColumn.__TARO_PICKER_VIEW_CHILD_TYPE = PICKER_VIEW_COLUMN_TYPE;
56
+ function isPickerViewColumnElement(child) {
57
+ if (!isReactElement(child)) {
58
+ return false;
59
+ }
60
+ const childType = child.type;
61
+ return (childType.__TARO_PICKER_VIEW_CHILD_TYPE === PICKER_VIEW_COLUMN_TYPE ||
62
+ childType.displayName === 'PickerViewColumn' ||
63
+ childType.name === 'PickerViewColumn' ||
64
+ child.type === 'picker-view-column' ||
65
+ child.type === 'taro-picker-view-column-core');
66
+ }
67
+ function isReactElement(node) {
68
+ return (typeof node === 'object' &&
69
+ node !== null &&
70
+ node.$$typeof === Symbol.for('react.element') &&
71
+ 'type' in node &&
72
+ 'props' in node);
73
+ }
74
+ function toChildArray(children) {
75
+ if (children === null || children === undefined || typeof children === 'boolean') {
76
+ return [];
77
+ }
78
+ return Array.isArray(children) ? children.flatMap(toChildArray) : [children];
79
+ }
47
80
  //# sourceMappingURL=index.jsx.map
@@ -1,36 +1,51 @@
1
1
  import type { CSSProperties } from '@lynx-js/types';
2
+ import type { ReactNode } from 'react';
3
+ import type { PickerViewProps as TaroPickerViewPropsBase } from '@tarojs/components';
2
4
  import type { PickerViewProps as LynxPickerViewProps, PickerColumnOption } from '@byted-doubao-apps/framework/components';
3
- export type TaroPickerViewProps = {
4
- className?: string;
5
- style?: CSSProperties;
6
- value?: number[];
7
- indicatorStyle?: CSSProperties;
8
- maskStyle?: CSSProperties;
9
- onChange?: (event: {
10
- type: string;
11
- timeStamp: number;
12
- detail: {
13
- value: number[];
14
- };
15
- }) => void;
16
- children?: any;
5
+ export type TaroPickerViewProps = TaroPickerViewPropsBase & {
6
+ children?: ReactNode;
17
7
  };
18
8
  export type TaroPickerViewColumnProps = {
9
+ children?: ReactNode;
19
10
  range?: Array<string | number>;
20
11
  className?: string;
21
12
  style?: CSSProperties;
22
13
  };
23
- export declare function toPickerViewChangeEvent(indices: number[]): {
14
+ export type PickerViewChangeEvent = {
24
15
  type: string;
25
16
  timeStamp: number;
17
+ target: {
18
+ id: string;
19
+ tagName: string;
20
+ dataset: Record<string, unknown>;
21
+ };
22
+ currentTarget: {
23
+ id: string;
24
+ tagName: string;
25
+ dataset: Record<string, unknown>;
26
+ };
26
27
  detail: {
27
28
  value: number[];
28
29
  };
30
+ preventDefault: () => void;
31
+ stopPropagation: () => void;
29
32
  };
33
+ export declare function toPickerViewChangeEvent(indices: number[], pickerViewId?: string): PickerViewChangeEvent;
30
34
  export declare function buildOptionsFromRange(range?: Array<string | number>): PickerColumnOption[];
31
- export declare function warnUnsupportedPickerView(unsupported: string[]): void;
35
+ export declare function buildOptionsFromChildren(children?: ReactNode): PickerColumnOption[];
36
+ export declare function resolveSelectedIndexValue(indices: number[] | undefined, columnIndex: number, options: PickerColumnOption[]): number | undefined;
32
37
  export declare function mapPickerViewProps(props: TaroPickerViewProps): {
33
- mapped: Pick<LynxPickerViewProps, 'className' | 'style'>;
38
+ mapped: Pick<LynxPickerViewProps, 'className' | 'style'> & Record<string, unknown>;
39
+ unsupported: string[];
40
+ pickerViewId: string;
41
+ indicatorItemHeight: number | undefined;
42
+ };
43
+ export declare function mapPickerViewColumnProps(props: TaroPickerViewColumnProps): {
44
+ className?: string;
45
+ style?: CSSProperties;
34
46
  unsupported: string[];
35
47
  };
48
+ export declare function resolveItemHeightFromChildren(children?: ReactNode): number | undefined;
49
+ export declare function resolveExplicitItemHeight(itemHeight: unknown): number | undefined;
50
+ export declare function resolveItemHeightFromIndicatorStyle(indicatorStyle: unknown): number | undefined;
36
51
  //# sourceMappingURL=map.d.ts.map
@@ -1,29 +1,201 @@
1
- export function toPickerViewChangeEvent(indices) {
1
+ import { BASE_PROP_MAP } from '../base/prop-map.js';
2
+ export function toPickerViewChangeEvent(indices, pickerViewId = '') {
2
3
  return {
3
4
  type: 'change',
4
5
  timeStamp: Date.now(),
5
- detail: { value: indices }
6
+ target: {
7
+ id: pickerViewId,
8
+ tagName: 'picker-view',
9
+ dataset: {}
10
+ },
11
+ currentTarget: {
12
+ id: pickerViewId,
13
+ tagName: 'picker-view',
14
+ dataset: {}
15
+ },
16
+ detail: { value: indices },
17
+ preventDefault: () => { },
18
+ stopPropagation: () => { }
6
19
  };
7
20
  }
8
21
  export function buildOptionsFromRange(range) {
9
- return (range ?? []).map((item) => ({ label: String(item), value: item }));
22
+ return (range ?? []).map((item, index) => ({ label: String(item), value: index }));
10
23
  }
11
- export function warnUnsupportedPickerView(unsupported) {
12
- if (unsupported.length > 0) {
13
- // Centralized warn helper exists for other components; keep inline minimal here
14
- console.warn(`[PickerView] Unsupported props: ${unsupported.join(', ')}`);
24
+ export function buildOptionsFromChildren(children) {
25
+ return toChildArray(children).map((child, index) => ({
26
+ label: extractText(child) || String(index),
27
+ value: index
28
+ }));
29
+ }
30
+ export function resolveSelectedIndexValue(indices, columnIndex, options) {
31
+ const selectedIndex = indices?.[columnIndex];
32
+ if (selectedIndex === undefined || options.length === 0) {
33
+ return undefined;
34
+ }
35
+ if (typeof selectedIndex !== 'number' || Number.isNaN(selectedIndex)) {
36
+ return undefined;
15
37
  }
38
+ return Math.min(Math.max(Math.trunc(selectedIndex), 0), options.length - 1);
16
39
  }
17
40
  export function mapPickerViewProps(props) {
41
+ const { value: _value, defaultValue: _defaultValue, children: _children, onChange: _onChange, indicatorStyle, indicatorClass, maskStyle, maskClass, immediateChange, onPickStart, onPickEnd, title, ariaLabel, ...rest } = props;
18
42
  const unsupported = [];
19
- if (props.maskStyle)
43
+ const indicatorItemHeight = resolveItemHeightFromIndicatorStyle(indicatorStyle);
44
+ unsupported.push(...getUnsupportedIndicatorStyleWarnings(indicatorStyle, indicatorItemHeight));
45
+ if (indicatorClass !== undefined)
46
+ unsupported.push('indicatorClass');
47
+ if (maskStyle !== undefined)
20
48
  unsupported.push('maskStyle');
21
- if (props.indicatorStyle)
22
- unsupported.push('indicatorStyle');
23
- const mapped = {
24
- className: props.className,
25
- style: props.style
49
+ if (maskClass !== undefined)
50
+ unsupported.push('maskClass');
51
+ if (immediateChange !== undefined)
52
+ unsupported.push('immediateChange');
53
+ if (onPickStart !== undefined)
54
+ unsupported.push('onPickStart');
55
+ if (onPickEnd !== undefined)
56
+ unsupported.push('onPickEnd');
57
+ if (title !== undefined)
58
+ unsupported.push('title');
59
+ if (ariaLabel !== undefined)
60
+ unsupported.push('ariaLabel');
61
+ const mapped = {};
62
+ Object.entries(rest).forEach(([key, value]) => {
63
+ const target = BASE_PROP_MAP[key];
64
+ if (target) {
65
+ mapped[target] = value;
66
+ return;
67
+ }
68
+ unsupported.push(key);
69
+ });
70
+ return {
71
+ mapped,
72
+ unsupported: dedupe(unsupported),
73
+ pickerViewId: resolveId(mapped.id),
74
+ indicatorItemHeight
75
+ };
76
+ }
77
+ export function mapPickerViewColumnProps(props) {
78
+ const { children: _children, range: _range, className, style, ...rest } = props;
79
+ return {
80
+ className,
81
+ style,
82
+ unsupported: Object.keys(rest)
26
83
  };
27
- return { mapped, unsupported };
84
+ }
85
+ export function resolveItemHeightFromChildren(children) {
86
+ const firstHeight = toChildArray(children)
87
+ .map((child) => {
88
+ if (!isReactElement(child)) {
89
+ return undefined;
90
+ }
91
+ return parseStyleHeight(child.props.style);
92
+ })
93
+ .find((height) => height !== undefined);
94
+ return firstHeight;
95
+ }
96
+ export function resolveExplicitItemHeight(itemHeight) {
97
+ return typeof itemHeight === 'number' && Number.isFinite(itemHeight) && itemHeight > 0
98
+ ? itemHeight
99
+ : undefined;
100
+ }
101
+ export function resolveItemHeightFromIndicatorStyle(indicatorStyle) {
102
+ if (typeof indicatorStyle === 'string') {
103
+ return parseStyleHeightString(indicatorStyle);
104
+ }
105
+ return parseStyleHeight(indicatorStyle);
106
+ }
107
+ function hasRpxIndicatorHeight(indicatorStyle) {
108
+ if (typeof indicatorStyle === 'string') {
109
+ return /(?:^|;)\s*height\s*:\s*\d+(?:\.\d+)?rpx\s*(?:;|$)/.test(indicatorStyle);
110
+ }
111
+ if (!indicatorStyle || typeof indicatorStyle !== 'object' || Array.isArray(indicatorStyle)) {
112
+ return false;
113
+ }
114
+ const height = indicatorStyle.height;
115
+ return typeof height === 'string' && /^\d+(?:\.\d+)?rpx$/.test(height.trim());
116
+ }
117
+ function getUnsupportedIndicatorStyleWarnings(indicatorStyle, indicatorItemHeight) {
118
+ if (indicatorStyle === undefined) {
119
+ return [];
120
+ }
121
+ const unsupported = [];
122
+ if (hasUnsupportedIndicatorStyleFields(indicatorStyle)) {
123
+ unsupported.push('indicatorStyle only supports height');
124
+ }
125
+ if (hasRpxIndicatorHeight(indicatorStyle)) {
126
+ unsupported.push('indicatorStyle.height uses rpx, please use px or number');
127
+ }
128
+ else if (indicatorItemHeight === undefined) {
129
+ unsupported.push('indicatorStyle.height must be px or number');
130
+ }
131
+ return unsupported;
132
+ }
133
+ function hasUnsupportedIndicatorStyleFields(indicatorStyle) {
134
+ if (typeof indicatorStyle === 'string') {
135
+ return parseStyleDeclarationNames(indicatorStyle).some((name) => name !== 'height');
136
+ }
137
+ if (!indicatorStyle || typeof indicatorStyle !== 'object' || Array.isArray(indicatorStyle)) {
138
+ return false;
139
+ }
140
+ return Object.keys(indicatorStyle).some((name) => name !== 'height');
141
+ }
142
+ function parseStyleDeclarationNames(style) {
143
+ return style
144
+ .split(';')
145
+ .map((declaration) => declaration.trim())
146
+ .filter(Boolean)
147
+ .map((declaration) => declaration.split(':')[0]?.trim())
148
+ .filter((name) => Boolean(name));
149
+ }
150
+ function extractText(node) {
151
+ if (node === null || node === undefined || typeof node === 'boolean') {
152
+ return '';
153
+ }
154
+ if (typeof node === 'string' || typeof node === 'number') {
155
+ return String(node);
156
+ }
157
+ if (Array.isArray(node)) {
158
+ return node.map(extractText).join('');
159
+ }
160
+ if (isReactElement(node)) {
161
+ return extractText(node.props.children);
162
+ }
163
+ return '';
164
+ }
165
+ function isReactElement(node) {
166
+ return (typeof node === 'object' &&
167
+ node !== null &&
168
+ node.$$typeof === Symbol.for('react.element') &&
169
+ 'props' in node);
170
+ }
171
+ function toChildArray(children) {
172
+ if (children === null || children === undefined || typeof children === 'boolean') {
173
+ return [];
174
+ }
175
+ return Array.isArray(children) ? children.flatMap(toChildArray) : [children];
176
+ }
177
+ function resolveId(id) {
178
+ return typeof id === 'string' ? id : '';
179
+ }
180
+ function dedupe(items) {
181
+ return Array.from(new Set(items));
182
+ }
183
+ function parseStyleHeight(style) {
184
+ if (!style || typeof style !== 'object' || Array.isArray(style)) {
185
+ return undefined;
186
+ }
187
+ const height = style.height;
188
+ if (typeof height === 'number' && Number.isFinite(height)) {
189
+ return height;
190
+ }
191
+ if (typeof height !== 'string') {
192
+ return undefined;
193
+ }
194
+ const match = height.trim().match(/^(\d+(?:\.\d+)?)px$/);
195
+ return match ? Number(match[1]) : undefined;
196
+ }
197
+ function parseStyleHeightString(style) {
198
+ const match = style.match(/(?:^|;)\s*height\s*:\s*(\d+(?:\.\d+)?)px\s*(?:;|$)/);
199
+ return match ? Number(match[1]) : undefined;
28
200
  }
29
201
  //# sourceMappingURL=map.js.map
package/package.json CHANGED
@@ -37,7 +37,7 @@
37
37
  "access": "public",
38
38
  "registry": "https://registry.npmjs.org/"
39
39
  },
40
- "version": "0.0.25",
40
+ "version": "0.0.27",
41
41
  "scripts": {
42
42
  "dev": "npm run build -- -w",
43
43
  "build": "rimraf dist bundle && tsc -p tsconfig.build.json",
@@ -1,11 +0,0 @@
1
- import type Taro from '@tarojs/taro';
2
- type TaroStartHCEOption = Taro.startHCE.Option;
3
- type TaroStopHCEOption = Taro.stopHCE.Option;
4
- type TaroSendHCEMessageOption = Taro.sendHCEMessage.Option;
5
- type TaroGetHCEStateOption = Taro.getHCEState.Option;
6
- export declare function startHCE(option: TaroStartHCEOption): Promise<TaroGeneral.CallbackResult>;
7
- export declare function stopHCE(option?: TaroStopHCEOption): Promise<TaroGeneral.CallbackResult>;
8
- export declare function sendHCEMessage(option: TaroSendHCEMessageOption): Promise<TaroGeneral.CallbackResult>;
9
- export declare function getHCEState(option?: TaroGetHCEStateOption): Promise<TaroGeneral.CallbackResult>;
10
- export {};
11
- //# sourceMappingURL=hce.d.ts.map
@@ -1,19 +0,0 @@
1
- import * as appFrameworkApi from '@byted-doubao-apps/framework/api';
2
- import { runCallbackApi } from '../utils.js';
3
- export async function startHCE(option) {
4
- return runCallbackApi('startHCE', option, () => appFrameworkApi.startHCE({
5
- aidList: option.aid_list
6
- }));
7
- }
8
- export async function stopHCE(option) {
9
- return runCallbackApi('stopHCE', option, () => appFrameworkApi.stopHCE({}));
10
- }
11
- export async function sendHCEMessage(option) {
12
- return runCallbackApi('sendHCEMessage', option, () => appFrameworkApi.sendHCEMessage({
13
- data: option.data
14
- }));
15
- }
16
- export async function getHCEState(option) {
17
- return runCallbackApi('getHCEState', option, () => appFrameworkApi.getHCEState({}));
18
- }
19
- //# sourceMappingURL=hce.js.map