mirror of
https://gitee.com/openharmony/interface_sdk-js
synced 2025-04-17 20:50:34 +00:00

Signed-off-by: mazijian <mazijian2@huawei.com> Change-Id: I2058b3119d73710d9d59f6d582b82406d8634322
377 lines
13 KiB
TypeScript
377 lines
13 KiB
TypeScript
/*
|
|
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
/**
|
|
* @file
|
|
* @kit ArkUI
|
|
*/
|
|
|
|
import { AsyncCallback } from './@ohos.base';
|
|
import image from './@ohos.multimedia.image'
|
|
|
|
/**
|
|
* This module allows developers to export snapshot image from a component or a custom builder.
|
|
*
|
|
* @namespace componentSnapshot
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
|
* @crossplatform
|
|
* @since 10
|
|
*/
|
|
/**
|
|
* This module allows developers to export snapshot image from a component or a custom builder.
|
|
*
|
|
* @namespace componentSnapshot
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
|
* @crossplatform
|
|
* @atomicservice
|
|
* @since 12
|
|
*/
|
|
declare namespace componentSnapshot {
|
|
/**
|
|
* Defines the extra options for snapshot taking.
|
|
*
|
|
* @typedef SnapshotRegion
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
|
* @crossplatform
|
|
* @atomicservice
|
|
* @since 15
|
|
*/
|
|
interface SnapshotRegion {
|
|
/**
|
|
* Left side position of rectangle, in PX.
|
|
*
|
|
* @type { number }
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
|
* @crossplatform
|
|
* @atomicservice
|
|
* @since 15
|
|
*/
|
|
left: number;
|
|
|
|
/**
|
|
* Right side position of Rectangle, in PX.
|
|
*
|
|
* @type { number }
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
|
* @crossplatform
|
|
* @atomicservice
|
|
* @since 15
|
|
*/
|
|
right: number;
|
|
|
|
/**
|
|
* Top side position of Rectangle, in PX.
|
|
*
|
|
* @type { number }
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
|
* @crossplatform
|
|
* @atomicservice
|
|
* @since 15
|
|
*/
|
|
top: number;
|
|
|
|
/**
|
|
* Bottom side position of Rectangle, in PX.
|
|
*
|
|
* @type { number }
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
|
* @crossplatform
|
|
* @atomicservice
|
|
* @since 15
|
|
*/
|
|
bottom: number;
|
|
}
|
|
|
|
/**
|
|
* Defines the extra options for snapshot taking, if this is used, the start and end will
|
|
* be assigned to left and right value according to the layout direction of node automaticlly.
|
|
*
|
|
* @typedef LocalizedSnapshotRegion
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
|
* @crossplatform
|
|
* @atomicservice
|
|
* @since 15
|
|
*/
|
|
interface LocalizedSnapshotRegion {
|
|
/**
|
|
* Left/Right side position of rectangle, in PX
|
|
*
|
|
* @type { number }
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
|
* @crossplatform
|
|
* @atomicservice
|
|
* @since 15
|
|
*/
|
|
start: number;
|
|
|
|
/**
|
|
* End side position of Rectangle, in PX.
|
|
*
|
|
* @type { number }
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
|
* @crossplatform
|
|
* @atomicservice
|
|
* @since 15
|
|
*/
|
|
end: number;
|
|
|
|
/**
|
|
* Left/Right side position of rectangle, in PX
|
|
*
|
|
* @type { number }
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
|
* @crossplatform
|
|
* @atomicservice
|
|
* @since 15
|
|
*/
|
|
top: number;
|
|
|
|
/**
|
|
* Bottom side position of Rectangle, in PX.
|
|
*
|
|
* @type { number }
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
|
* @crossplatform
|
|
* @atomicservice
|
|
* @since 15
|
|
*/
|
|
bottom: number;
|
|
}
|
|
|
|
/**
|
|
* Defines the snapshot region rect type.
|
|
*
|
|
* @typedef { SnapshotRegion | LocalizedSnapshotRegion } SnapshotRegionType
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
|
* @crossplatform
|
|
* @atomicservice
|
|
* @since 15
|
|
*/
|
|
type SnapshotRegionType = SnapshotRegion | LocalizedSnapshotRegion;
|
|
|
|
/**
|
|
* Defines the extra options for snapshot taking.
|
|
*
|
|
* @typedef SnapshotOptions
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
|
* @crossplatform
|
|
* @atomicservice
|
|
* @since 12
|
|
*/
|
|
interface SnapshotOptions {
|
|
/**
|
|
* Defines the scale property to render the snapshot.
|
|
*
|
|
* @type {?number}
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
|
* @crossplatform
|
|
* @atomicservice
|
|
* @since 12
|
|
*/
|
|
scale?: number
|
|
|
|
/**
|
|
* Whether to wait the rendering is finished.
|
|
*
|
|
* @type {?boolean}
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
|
* @crossplatform
|
|
* @atomicservice
|
|
* @since 12
|
|
*/
|
|
waitUntilRenderFinished?: boolean
|
|
|
|
/**
|
|
* Defines the rect reigon type of the snapshot.
|
|
*
|
|
* @type {?SnapshotRegionType}
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
|
* @crossplatform
|
|
* @atomicservice
|
|
* @since 15
|
|
*/
|
|
region?: SnapshotRegionType
|
|
}
|
|
|
|
/**
|
|
* Take a snapshot of the target component.
|
|
*
|
|
* @param { string } id - Target component ID, set by developer through .id attribute.
|
|
* @param { AsyncCallback<image.PixelMap> } callback - Callback that contains the snapshot in PixelMap format.
|
|
* @throws { BusinessError } 401 - Parameter error. Possible causes:
|
|
* <br> 1. Mandatory parameters are left unspecified.
|
|
* <br> 2. Incorrect parameters types.
|
|
* <br> 3. Parameter verification failed.
|
|
* @throws { BusinessError } 100001 - Invalid ID.
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
|
* @crossplatform
|
|
* @since 10
|
|
*/
|
|
/**
|
|
* Take a snapshot of the target component.
|
|
*
|
|
* @param { string } id - Target component ID, set by developer through .id attribute.
|
|
* @param { AsyncCallback<image.PixelMap> } callback - Callback that contains the snapshot in PixelMap format.
|
|
* @param { SnapshotOptions } [options] - Define the snapshot options.
|
|
* @throws { BusinessError } 401 - Parameter error. Possible causes:
|
|
* <br> 1. Mandatory parameters are left unspecified.
|
|
* <br> 2. Incorrect parameters types.
|
|
* <br> 3. Parameter verification failed.
|
|
* @throws { BusinessError } 100001 - Invalid ID.
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
|
* @crossplatform
|
|
* @atomicservice
|
|
* @since 12
|
|
* @deprecated since 18
|
|
* @useinstead ohos.arkui.UIContext.ComponentSnapshot#get
|
|
*/
|
|
function get(id: string, callback: AsyncCallback<image.PixelMap>, options?: SnapshotOptions): void;
|
|
|
|
/**
|
|
* Take a snapshot of the target component.
|
|
*
|
|
* @param { string } id - Target component ID, set by developer through .id attribute.
|
|
* @returns { Promise<image.PixelMap> } A Promise with the snapshot in PixelMap format.
|
|
* @throws { BusinessError } 401 - Parameter error. Possible causes:
|
|
* <br> 1. Mandatory parameters are left unspecified.
|
|
* <br> 2. Incorrect parameters types.
|
|
* <br> 3. Parameter verification failed.
|
|
* @throws { BusinessError } 100001 - Invalid ID.
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
|
* @crossplatform
|
|
* @since 10
|
|
*/
|
|
/**
|
|
* Take a snapshot of the target component.
|
|
*
|
|
* @param { string } id - Target component ID, set by developer through .id attribute.
|
|
* @param { SnapshotOptions } [options] - Define the snapshot options.
|
|
* @returns { Promise<image.PixelMap> } A Promise with the snapshot in PixelMap format.
|
|
* @throws { BusinessError } 401 - Parameter error. Possible causes:
|
|
* <br> 1. Mandatory parameters are left unspecified.
|
|
* <br> 2. Incorrect parameters types.
|
|
* <br> 3. Parameter verification failed.
|
|
* @throws { BusinessError } 100001 - Invalid ID.
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
|
* @crossplatform
|
|
* @atomicservice
|
|
* @since 12
|
|
* @deprecated since 18
|
|
* @useinstead ohos.arkui.UIContext.ComponentSnapshot#get
|
|
*/
|
|
function get(id: string, options?: SnapshotOptions): Promise<image.PixelMap>;
|
|
|
|
/**
|
|
* Generate a snapshot from a custom component builder.
|
|
*
|
|
* @param { CustomBuilder } builder - Builder function of a custom component.
|
|
* @param { AsyncCallback<image.PixelMap> } callback - Callback that contains the snapshot in PixelMap format.
|
|
* @throws { BusinessError } 401 - Parameter error. Possible causes:
|
|
* <br> 1. Mandatory parameters are left unspecified.
|
|
* <br> 2. Incorrect parameters types.
|
|
* <br> 3. Parameter verification failed.
|
|
* @throws { BusinessError } 100001 - The builder is not a valid build function.
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
|
* @crossplatform
|
|
* @since 10
|
|
*/
|
|
/**
|
|
* Generate a snapshot from a custom component builder.
|
|
*
|
|
* @param { CustomBuilder } builder - Builder function of a custom component.
|
|
* @param { AsyncCallback<image.PixelMap> } callback - Callback that contains the snapshot in PixelMap format.
|
|
* @param { number } [delay] - Defines the delay time to render the snapshot.
|
|
* @param { boolean } [checkImageStatus] - Defines if check the image decoding status before taking snapshot.
|
|
* @param { SnapshotOptions } [options] - Define the snapshot options.
|
|
* @throws { BusinessError } 401 - Parameter error. Possible causes:
|
|
* <br> 1. Mandatory parameters are left unspecified.
|
|
* <br> 2. Incorrect parameters types.
|
|
* <br> 3. Parameter verification failed.
|
|
* @throws { BusinessError } 100001 - The builder is not a valid build function.
|
|
* @throws { BusinessError } 160001 - An image component in builder is not ready for taking a snapshot. The check for
|
|
* the ready state is required when the checkImageStatus option is enabled.
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
|
* @crossplatform
|
|
* @atomicservice
|
|
* @since 12
|
|
* @deprecated since 18
|
|
* @useinstead ohos.arkui.UIContext.ComponentSnapshot#createFromBuilder
|
|
*/
|
|
function createFromBuilder(builder: CustomBuilder, callback: AsyncCallback<image.PixelMap>,
|
|
delay?: number, checkImageStatus?: boolean, options?: SnapshotOptions): void;
|
|
|
|
/**
|
|
* Generate a snapshot from a custom component builder.
|
|
*
|
|
* @param { CustomBuilder } builder - Builder function of a custom component.
|
|
* @returns { Promise<image.PixelMap> } A Promise with the snapshot in PixelMap format.
|
|
* @throws { BusinessError } 401 - Parameter error. Possible causes:
|
|
* <br> 1. Mandatory parameters are left unspecified.
|
|
* <br> 2. Incorrect parameters types.
|
|
* <br> 3. Parameter verification failed.
|
|
* @throws { BusinessError } 100001 - The builder is not a valid build function.
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
|
* @crossplatform
|
|
* @since 10
|
|
*/
|
|
/**
|
|
* Generate a snapshot from a custom component builder.
|
|
*
|
|
* @param { CustomBuilder } builder - Builder function of a custom component.
|
|
* @param { number } [delay] - Defines the delay time to render the snapshot.
|
|
* @param { boolean } [checkImageStatus] - Defines if check the image decoding status before taking snapshot.
|
|
* @param { SnapshotOptions } [options] - Define the snapshot options.
|
|
* @returns { Promise<image.PixelMap> } A Promise with the snapshot in PixelMap format.
|
|
* @throws { BusinessError } 401 - Parameter error. Possible causes:
|
|
* <br> 1. Mandatory parameters are left unspecified.
|
|
* <br> 2. Incorrect parameters types.
|
|
* <br> 3. Parameter verification failed.
|
|
* @throws { BusinessError } 100001 - The builder is not a valid build function.
|
|
* @throws { BusinessError } 160001 - An image component in builder is not ready for taking a snapshot. The check for
|
|
* the ready state is required when the checkImageStatus option is enabled.
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
|
* @crossplatform
|
|
* @atomicservice
|
|
* @since 12
|
|
* @deprecated since 18
|
|
* @useinstead ohos.arkui.UIContext.ComponentSnapshot#createFromBuilder
|
|
*/
|
|
function createFromBuilder(builder: CustomBuilder, delay?: number,
|
|
checkImageStatus?: boolean, options?: SnapshotOptions): Promise<image.PixelMap>;
|
|
|
|
/**
|
|
* Take a screenshot of the specified component in synchronous mode,
|
|
* this mode will block the main thread, please use it with caution, the maximum
|
|
* waiting time of the interface is 3s, if it does not return after 3s, an exception will be thrown.
|
|
*
|
|
* @param { string } id - Target component ID, set by developer through .id attribute.
|
|
* @param { SnapshotOptions } [options] - Define the snapshot options.
|
|
* @returns { image.PixelMap } The snapshot result in PixelMap format.
|
|
* @throws { BusinessError } 401 - Parameter error. Possible causes:
|
|
* <br> 1. Mandatory parameters are left unspecified.
|
|
* <br> 2. Incorrect parameters types.
|
|
* <br> 3. Parameter verification failed.
|
|
* @throws { BusinessError } 100001 - Invalid ID.
|
|
* @throws { BusinessError } 160002 - Timeout.
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
|
* @crossplatform
|
|
* @atomicservice
|
|
* @since 12
|
|
*/
|
|
function getSync(id: string, options?: SnapshotOptions): image.PixelMap;
|
|
}
|
|
|
|
export default componentSnapshot;
|