/* * Copyright (c) 2020-2021 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. */ import { Image, ImageData, ImageBitmap } from "./global"; import { WebGLContextAttributes, WebGLRenderingContext } from "../../webgl/webgl"; import { WebGL2RenderingContext } from "../../webgl/webgl2"; import image from "../../@ohos.multimedia.image"; import { CanvasPattern } from './canvaspattern'; /** * Defines the focus param. * @syscap SystemCapability.ArkUI.ArkUI.Full * @since 3 */ export interface FocusParamObj { /** * Whether needs to focus. * @since 3 */ focus: boolean; } /** * @syscap SystemCapability.ArkUI.ArkUI.Full * @since 6 */ export interface RectObj { /** * @since 6 */ width: number; /** * @since 6 */ height: number; /** * @since 6 */ left: number; /** * @since 6 */ top: number; } /** * @syscap SystemCapability.ArkUI.ArkUI.Full * @since 6 */ export interface ContextAttrOptions { /** * @since 6 */ antialias: boolean; } /** * @syscap SystemCapability.ArkUI.ArkUI.Full * @since 4 */ export interface AnimateStyle { /** * Width value applied to the component after the animation is executed. * @since 4 */ width: number; /** * Height value applied to the component after the animation is executed. * @since 4 */ height: number; /** * left offset applied to the component after the animation is executed. * @since 4 */ left: number; /** * top offset applied to the component after the animation is executed. * @since 4 */ top: number; /** * right offset applied to the component after the animation is executed. * @since 4 */ right: number; /** * bottom offset applied to the component after the animation is executed. * @since 4 */ bottom: number; /** * Background color applied to the component after the animation is executed. * The default value is none. * @since 4 */ backgroundColor: string; /** * Opacity applied to the component. The value ranges from 0 to 1. * The default value is 1. * @since 4 */ opacity: number; /** * The value format is "x y", in percentage or pixels. * The first value indicates the horizontal position, and the second value indicates the vertical position. * If only one value is specified, the other value is 50% by default. * @since 4 */ backgroundPosition: string; /** * Origin position of the transformed element. * The first value indicates the x-axis position. The value can be left, center, right, a length, or percentage. * The second value indicates the y-axis position. The value can be top, center, bottom, a length, or a percentage. * @since 4 */ transformOrigin: string; /** * Transformation type applied to an element. * @since 4 */ transform: "none" | TransformObject; /** * The value of offset must be within (0.0,1.0] and sorted in ascending order if it is provided. * If there are only two frames, offset can be left empty. * If there are more than two frames, offset is mandatory. * @since 4 */ offset?: number; } /** * @syscap SystemCapability.ArkUI.ArkUI.Full * @since 4 */ export interface TransformObject { /** * Defines a 2D transformation, using a matrix of six values.. * @param scaleX the scale value for x-axis * @param skewX the skew value for y-axis * @param skewY the skew value for x-axis * @param scaleY the scale value for y-axis * @param translateX the translate value for x-axis * @param translateY the translate value for y-axis * @since 6 */ matrix(scaleX: number, skewX: number, skewY: number, scaleY: number, translateX: number, translateY: number): void; /** * Defines a 3D transformation using a 4x4 matrix of 16 values. * @param n00 the value of the 0 row and 0 column of the 4x4 matrix * @param n01 the value of the 0 row and 1 column of the 4x4 matrix * @param n02 the value of the 0 row and 2 column of the 4x4 matrix * @param n03 the value of the 0 row and 3 column of the 4x4 matrix * @param n10 the value of the 1 row and 0 column of the 4x4 matrix * @param n11 the value of the 1 row and 1 column of the 4x4 matrix * @param n12 the value of the 1 row and 2 column of the 4x4 matrix * @param n13 the value of the 1 row and 3 column of the 4x4 matrix * @param n20 the value of the 2 row and 0 column of the 4x4 matrix * @param n21 the value of the 2 row and 1 column of the 4x4 matrix * @param n22 the value of the 2 row and 2 column of the 4x4 matrix * @param n23 the value of the 2 row and 3 column of the 4x4 matrix * @param n30 the value of the 3 row and 0 column of the 4x4 matrix * @param n31 the value of the 3 row and 1 column of the 4x4 matrix * @param n32 the value of the 3 row and 2 column of the 4x4 matrix * @param n33 the value of the 3 row and 3 column of the 4x4 matrix * @since 6 */ matrix3d( n00: number, n01: number, n02: number, n03: number, n10: number, n11: number, n12: number, n13: number, n20: number, n21: number, n22: number, n23: number, n30: number, n31: number, n32: number, n33: number, ): void; /** * Defines 2D transformations for translation of the X and Y axes * @param x the translate value for x-axis * @param y the translate value for y-axis * @since 4 */ translate(x: number, y: number): void; /** * Defines 3D transformations for translation of the X / Y / Z axes * @param x the translate value for x-axis * @param y the translate value for y-axis * @param z the translate value for z-axis * @since 6 */ translate3d(x: number, y: number, z: number): void; /** * Defines 2D transformations for translation of the X axes * @param x the translate value for x-axis * @since 4 */ translateX(x: number): void; /** * Defines 2D transformations for translation of the Y axes * @param y the translate value for y-axis * @since 4 */ translateY(y: number): void; /** * Defines 3D transformations for translation of the Z axes * @param z the translate value for z-axis * @since 6 */ translateZ(z: number): void; /** * Defines 2D transformations for scaling of the X and Y axes * @param x the scale value for x-axis * @param y the scale value for y-axis * @since 4 */ scale(x: number, y: number): void; /** * Defines 3D transformations for scaling of the X / Y / Z axes * @param x the scale value for x-axis * @param y the scale value for y-axis * @param z the scale value for z-axis * @since 6 */ scale3d(x: number, y: number, z: number): void; /** * Defines 2D transformations for scaling of the X axes * @param x the scale value for x-axis * @since 4 */ scaleX(x: number): void; /** * Defines 2D transformations for scaling of the Y axes * @param y the scale value for y-axis * @since 4 */ scaleY(y: number): void; /** * Defines 3D transformations for scaling of the Z axes * @param z the scale value for z-axis * @since 6 */ scaleZ(z: number): void; /** * Define the 2D rotation and specify the angle in the parameters. * @param angle the rotate value for z-axis * @since 4 */ rotate(angle: number): void; /** * Defines a 3D transformation for rotating the X / Y / Z axes. * @param x the vector value of the x-axis * @param y the vector value of the y-axis * @param z the vector value of the z-axis * @param angle the rotate value for x&y&z vector. * @since 6 */ rotate3d(x: number, y: number, z: number, angle: number): void; /** * Defines 3D transformations for rotating of the X axes. * @param x the scale value for x-axis * @since 4 */ rotateX(angle: number): void; /** * Defines 3D transformations for rotating of the Y axes. * @param y the scale value for y-axis * @since 4 */ rotateY(angle: number): void; /** * Defines 3D transformations for rotating of the Z axes. * @param z the scale value for z-axis * @since 6 */ rotateZ(angle: number): void; /** * Defines the 2D skew transition along the X and Y axes. * @param xAngle the angle of inclination along the x axis. * @param yAngle the angle of inclination along the y axis. * @since 6 */ skew(xAngle: number, yAngle: number): void; /** * Defines the 2D skew transition along the X axes. * @param angle the angle of inclination along the x axis. * @since 6 */ skewX(angle: number): void; /** * Defines the 2D skew transition along the Y axes. * @param angle the angle of inclination along the y axis. * @since 6 */ skewY(angle: number): void; /** * Defines a perspective view for the 3D transformation element. * @param n the vertical distance from the observation point to the component plane. * @since 6 */ perspective(verticalDistance: number): void; } /** * @syscap SystemCapability.ArkUI.ArkUI.Full * @since 4 */ export interface AnimateOptions { /** * Duration of the animation, in milliseconds. * The default value is 0. * @since 4 */ duration: number; /** * Time curve of the animation. For details about the supported types. * linear The animation speed keeps unchanged. * ease The animation starts and ends at a low speed, cubic-bezier(0.25, 0.1, 0.25, 1.0). * ease-in The animation starts at a low speed, cubic-bezier(0.42, 0.0, 1.0, 1.0). * ease-out The animation ends at a low speed, cubic-bezier(0.0, 0.0, 0.58, 1.0). * ease-in-out The animation starts and ends at a low speed, cubic-bezier(0.42, 0.0, 0.58, 1.0). * fast-out-slow-in Standard curve, cubic-bezier(0.4, 0.0, 0.2, 1.0). * linear-out-slow-in Deceleration curve, cubic-bezier(0.0, 0.0, 0.2, 1.0). * fast-out-linear-in Acceleration curve, cubic-bezier(0.4, 0.0, 1.0, 1.0). * friction Damping curve, cubic-bezier(0.2, 0.0, 0.2, 1.0). * extreme-deceleration Extreme deceleration curve, cubic-bezier(0.0, 0.0, 0.0, 1.0). * sharp Sharp curve, cubic-bezier(0.33, 0.0, 0.67, 1.0). * rhythm Rhythm curve, cubic-bezier(0.7, 0.0, 0.2, 1.0). * smooth Smooth curve, cubic-bezier(0.4, 0.0, 0.4, 1.0). * cubic-bezier(x1, y1, x2, y2) You can customize an animation speed curve in the cubic-bezier() function. The x and y values of each input parameter must be between 0 and 1. * Step curve. The number must be set and only an integer is supported, step-position is optional. It can be set to start or end. The default value is end. * The default value is ease. * @since 4 */ easing: string; /** * Delay for the animation start. The default value indicates no delay. * The default value is 0. * @since 4 */ delay: number; /** * Number of times the animation will be played. number indicates a fixed number of playback operations, and Infinity indicates an unlimited number of playback operations. * The default value is 1. * @since 4 */ iterations: number | string; /** * The animation playback mode. * The default value is "normal". * @since 6 */ direction: "normal" | "reverse" | "alternate" | "alternate-reverse"; /** * Whether to resume to the initial state after the animation is executed. * none: The initial state is restored after the animation is executed. * forwards: The state at the end of the animation (defined in the last key frame) is retained after the animation is executed. * @since 4 */ fill: "none" | "forwards" | "backwards" | "both"; } /** * @syscap SystemCapability.ArkUI.ArkUI.Full * @since 4 */ export interface AnimationResult { /** * Read-only attribute, which indicates whether the animation playback is complete. * @since 4 */ finished: boolean; /** * Read-only attribute, which indicates whether an animation is waiting for the completion of other asynchronous operations (for example, start an animation with a delay). * @since 4 */ pending: boolean; /** * Animation running state: * idle: The animation is not running (playback ended or not started). * running: The animation is running. * paused: The animation is paused. * finished: Animation playback ends. * @since 4 */ playstate: string; /** * Animation start time. This attribute is similar to that of delay in the options parameters. * @since 4 */ startTime: number; /** * Starts the animation. * @since 4 */ play(): void; /** * Ends the animation. * @since 4 */ finish(): void; /** * Pauses the animation. * @since 4 */ pause(): void; /** * Cancels the animation. * @since 4 */ cancel(): void; /** * Plays the animation in reverse direction. * @since 4 */ reverse(): void; /** * The animation is started. * @since 4 */ onstart: () => void; /** * The animation is finished. * @since 4 */ onfinish: () => void; /** * The animation is canceled. * @since 4 */ oncancel: () => void; /** * The animation is repeated. * @since 4 */ onrepeat: () => void; } /** * @syscap SystemCapability.ArkUI.ArkUI.Full * @since 4 */ export interface Element { /** * Requests or cancels the focus for a component. * If focus is set to true, the focus is requested for the component. * If focus is set to false, the focus is canceled for the component. * This attribute can be defaulted to true. * @param obj { focus: true | false } * @since 4 */ focus(obj?: FocusParamObj): void; /** * Requests or cancels the crown rotation focus for a component. * If focus is set to true, the crown event focus is requested. * If focus is set to false, the crown event focus is canceled. * This attribute can be defaulted to true. * @param obj { focus: true | false } * @since 4 */ rotation(obj?: FocusParamObj): void; /** * Creates and runs an animation shortcut on the component. Specify the keyframes and options required for the animation. * @param keyframes keyframes is used to describe key frame parameters of the animation. * @param options Options. is used to describe animation parameters. * @returns This method returns the animation object. * @since 4 */ animate(keyframes: Array, options: AnimateOptions): AnimationResult; /** * Obtains the size and position of the element. * @returns RectObj the size position of the element. * @since 6 */ getBoundingClientRect(): RectObj; /** * Obtains attributes of the element. * @returns attributes of the element in json string. * @since 8 * @systemapi */ getInspector(): string; /** * If 0.5 is returned, 50% of the current component is visible. * @param radios Scope of Monitoring components. * @since 6 */ createIntersectionObserver(param: { ratios: Array }): observer; /** * Adds a node to the end of the child node list of the current node. * @param child Subnode object to be added * @since 8 */ addChild(child: Element): void; /** * Sets the value of an attribute on a specified element. If the attribute already exists, update the value. Otherwise, a new attribute is added with the specified name and value. * @param name attribute name * @param value attribute value¡¢ * @since 8 */ setAttribute(name: string, value: string): void; /** * Sets a style value on a specified element. If the style exists and the style value is valid, the setting is successful. Otherwise, the setting is invalid. * @param name style name * @param value style value * @returns If the setting is successful, true is returned. If the setting fails, false is returned. * @since 8 */ setStyle(name: string, value: string): boolean; } /** * Defines the observer interface. * @syscap SystemCapability.ArkUI.ArkUI.Full * @since 6 */ export interface observer { /** * Turn on the listener. * @since 6 */ observe(callback: string): void; /** * Turn off the listener. * @since 6 */ unobserve(): void; } /** * animation element * @syscap SystemCapability.ArkUI.ArkUI.Full * @since 4 */ export interface AnimationElement extends Element { /** * Starts the animation. * @since 4 */ play(): void; /** * Ends the animation. * @since 4 */ finish(): void; /** * Pauses the animation. * @since 4 */ pause(): void; /** * Cancels the animation. * @since 4 */ cancel(): void; /** * Plays the animation in reverse direction. * @since 4 */ reverse(): void; } /** * @syscap SystemCapability.ArkUI.ArkUI.Full * @since 4 */ export interface ScrollParam { /** * Offset for scrolling in the horizontal direction, in px. * @since 4 */ dx?: number; /** * Offset for scrolling in the vertical direction, in px. * @since 4 */ dy?: number; /** * Whether a sliding animation is displayed when scroll position is changed. * @since 4 */ smooth?: boolean; } /** * @syscap SystemCapability.ArkUI.ArkUI.Full * @since 4 */ export interface CurrentOffsetResultValue { /** * Scrolling offset in the x-axis, in px. * @since 4 */ x: number; /** * Scrolling offset in the y-axis, in px. * @since 4 */ y: number; } /** * @syscap SystemCapability.ArkUI.ArkUI.Full * @since 4 */ export interface ListScrollToOptions { /** * specified position. * @since 4 */ index: number; } /** * The component provides a list container. * @syscap SystemCapability.ArkUI.ArkUI.Full */ export interface ListElement extends Element { /** * Scrolls the list to the position of the item at the specified index. * @since 4 */ scrollTo(position: ListScrollToOptions): void; /** * Scrolls the list for a certain distance. * This method applies only to smart TVs. * @since 4 */ scrollBy(data: ScrollParam): void; /** * If smooth is set to false (default value), the list is directly scrolled to the top. * If smooth is set to true, the list is smoothly scrolled to the top. * @param param * @since 4 */ scrollTop(param: { smooth: boolean }): void; /** * If smooth is set to false (default value), the list is directly scrolled to the bottom. * If smooth is set to true, the list is smoothly scrolled to the bottom. * @param param * @since 4 */ scrollBottom(param: { smooth: boolean }): void; /** * If reverse is set to false (default value), the next page is displayed. If there is no next page, the list scrolls to the bottom. * If reverse is set to true, the previous page is displayed. If there is no previous page, the list scrolls to the top. * If smooth is set to false (default value), the list is directly scrolled to another page. * If smooth is set to true, the list is smoothly scrolled to another page. * @param params * @since 4 */ scrollPage(params: { reverse: boolean; smooth: boolean }): void; /** * If reverse is set to false (default value), the list scrolls towards the bottom for a certain distance. If there is no sufficient distance, the list scrolls to the bottom. * If reverse is set to true, the list scrolls towards the top for a certain distance. If there is no sufficient distance, the list scrolls to the top. * If smooth is set to false (default value), the list is directly scrolled. * If smooth is set to true, the list is smoothly scrolled. * @param params * @since 4 */ scrollArrow(params: { reverse: boolean; smooth: boolean }): void; /** * Collapses a group. * @param param * @since 4 */ collapseGroup(param: { /** * groupid: ID of the group to collapse. * All groups are collapsed when groupid is not specified. */ groupid: string; }): void; /** * Expands a group. * @param param * @since 4 */ expandGroup(param: { /** * groupid: ID of the group to expand. * All groups are expanded when groupid is not specified. */ groupid: string; }): void; /** * Returns the offset of the current scrolling. The return value type is Object. * @since 4 */ currentOffset(): CurrentOffsetResultValue; } /** * The component provides a swiper container. * @syscap SystemCapability.ArkUI.ArkUI.Full * @since 4 */ export interface SwiperElement extends Element { /** * Scrolls the child component to the position at the specified index. * @since 4 */ swipeTo(position: { /** * specified position. */ index: number; }): void; /** * Shows the next child component. * @since 4 */ showNext(): void; /** * Shows the previous child component. * @since 4 */ showPrevious(): void; } /** * @since 6 * @syscap SystemCapability.ArkUI.ArkUI.Full */ export interface CameraTakePhotoOptions { /** * Picture quality. * @since 6 */ quality: "high" | "normal" | "low"; /** * Callback function for successful interface invocation. * @param result the request execution result. * @since 6 */ success?: (result: Object) => void; /** * Callback function for interface invocation failure. * @param result the request execution result. * @since 6 */ fail?: (result: Object) => void; /** * Callback function at the end of the interface invoking (executed both successfully and unsuccessfully). * @param result the request execution result. * @since 6 */ complete?: (result: Object) => void; } /** * The component provides preview and photographing functions. * @syscap SystemCapability.ArkUI.ArkUI.Full * @since 6 */ export interface CameraElement extends Element { /** * Take photos with specified parameters. * @param options the parameters of camera. * @since 6 */ takePhoto(options: CameraTakePhotoOptions): void; } /** * The component is a container for displaying web page content. * @syscap SystemCapability.ArkUI.ArkUI.Full * @since 6 */ export interface WebElement extends Element { /** * Reload the web page content * @since 6 */ reload(): void; } /** * The component is a custom pop-up container. * @syscap SystemCapability.ArkUI.ArkUI.Full * @since 4 */ export interface DialogElement extends Element { /** * Shows a dialog box. * @since 4 */ show(): void; /** * Closes a dialog box. * @since 4 */ close(): void; } /** * The component is used to provide an image frame animator. * @syscap SystemCapability.ArkUI.ArkUI.Full * @since 4 */ export interface ImageAnimatorElement extends Element { /** * Starts to play the frame animation of an image. If this method is called again, the playback starts from the first frame. * @since 4 */ start(): void; /** * Pauses the frame animation playback of an image. * @since 4 */ pause(): void; /** * Stops the frame animation playback of an image. * @since 4 */ stop(): void; /** * Resumes the frame animation playback of an image. * @since 4 */ resume(): void; /** * Obtains the playback state. Available values are as follows: * Playing * Paused * Stopped * @since 4 */ getState(): "Playing" | "Paused" | "Stopped"; } /** * The component inserts scrolling text, which is displayed in a single line by default. * When the text length exceeds the display area of the component, the marquee effect is displayed. * @syscap SystemCapability.ArkUI.ArkUI.Full * @since 4 */ export interface MarqueeElement extends Element { /** * Starts scrolling. * @since 4 */ start(): void; /** * Stops scrolling. * @since 4 */ stop(): void; } /** * The component provides menus as temporary pop-up windows to display operations that can be performed by users. * @syscap SystemCapability.ArkUI.ArkUI.Full * @since 4 */ export interface MenuElement extends Element { /** * Displays the menu. * x and y specify the position of the displayed menu. * x indicates the X-axis coordinate from the left edge of the visible area, and does not include any scrolling offset. * y indicates the Y-axis coordinate from the upper edge of the visible area, and does not include any scrolling offset or a status bar. * The menu is preferentially displayed in the lower right corner. * When the visible space on the right is insufficient, the menu is moved leftward. * When the visible space in the lower part is insufficient, the menu is moved upward. * @param position * @since 4 */ show(position: { x: number; y: number }): void; } /** * The component displays line charts, gauge charts, and bar charts. * @syscap SystemCapability.ArkUI.ArkUI.Full * @since 4 */ export interface ChartElement extends Element { /** * Data is dynamically added to an existing data sequence. * The target sequence is specified based on serial, which is the subscript of the datasets array and starts from 0. * datasets[index].data is not updated. Only line charts support this attribute. * The value is incremented by 1 based on the horizontal coordinate and is related to the xAxis min/max setting. * @since 4 */ append(params: { /** * Set the data subscript of the line chart to be updated. */ serial: number; /** * Set the new data. */ data: Array; }): void; } /** * The component provides an interactive interface to receive user input, which is displayed in a single line by default. * @syscap SystemCapability.ArkUI.ArkUI.Full * @since 4 */ export interface InputElement extends Element { /** * Obtains or loses the focus of a component. * When the component type is set to text, email, date, time, number, or password, the input method can be displayed or collapsed. * @param param If focus is not passed, the default value true is used. * @since 4 */ focus(param: { focus: boolean }): void; /** * Displays the error message. * This attribute is available when the component type is set to text, email, date, time, number, or password. * @param param * @since 4 */ showError(param: { error: string }): void; /** * Deletes the previous character at the cursor position. * @since 6 */ delete(): void; } /** * The