/* * Copyright (c) 2020 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 } from "./global"; export interface FocusParamObj { focus: boolean; } export interface AnimateStyle { /** * Width value applied to the component after the animation is executed. */ width: number; /** * Height value applied to the component after the animation is executed. */ height: number; /** * Background color applied to the component after the animation is executed. * The default value is none. */ backgroundColor: string; /** * Opacity applied to the component. The value ranges from 0 to 1. * The default value is 1. */ 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. */ 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. */ transformOrigin: string; /** * Transformation type applied to an element. */ transform: object; /** * 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. */ offset?: number; } export interface AnimateOptions { /** * Duration of the animation, in milliseconds. * The default value is 0. */ duration: number; /** * Time curve of the animation. For details about the supported types. * linear The animation speed keeps unchanged. * 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 linear. */ easing: string; /** * Delay for the animation start. The default value indicates no delay. * The default value is 0. */ 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. */ iterations: number | string; /** * 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. */ fill: "none" | "forwards"; } export interface AnimationResult { /** * Read-only attribute, which indicates whether the animation playback is complete. */ 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). */ 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. */ playstate: string; /** * Animation start time. This attribute is similar to that of delay in the options parameters. */ startTime: number; /** * Starts the animation. */ play(): void; /** * Ends the animation. */ finish(): void; /** * Pauses the animation. */ pause(): void; /** * Cancels the animation. */ cancel(): void; /** * Plays the animation in reverse direction. */ reverse(): void; /** * The animation is finished. */ onfinish: () => void; /** * The animation is canceled. */ oncancel: () => void; } 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 } */ 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 } */ 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. */ animate( keyframes: Array, options: AnimateOptions ): AnimationResult; } /** * animation element */ export interface AnimationElement extends Element { /** * Starts the animation. */ play(): void; /** * Ends the animation. */ finish(): void; /** * Pauses the animation. */ pause(): void; /** * Cancels the animation. */ cancel(): void; /** * Plays the animation in reverse direction. */ reverse(): void; } export interface CurrentOffsetResultValue { /** * Scrolling offset in the x-axis, in px. */ x: number; /** * Scrolling offset in the y-axis, in px. */ y: number; } /** * The component provides a list container. */ export interface ListElement extends Element { /** * Scrolls the list to the position of the item at the specified index. */ scrollTo(position: { /** * specified position. */ index: number; }): 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 */ 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 */ 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 */ 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 */ scrollArrow(params: { reverse: boolean; smooth: boolean }): void; /** * Collapses a group. * @param param */ 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 */ 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. */ currentOffset(): CurrentOffsetResultValue; } /** * The component provides a swiper container. */ export interface SwiperElement extends Element { /** * Scrolls the child component to the position at the specified index. */ swipeTo(position: { /** * specified position. */ index: number; }): void; /** * Shows the next child component. */ showNext(): void; /** * Shows the previous child component. */ showPrevious(): void; } /** * The component is a custom pop-up container. */ export interface DialogElement extends Element { /** * Shows a dialog box. */ show(): void; /** * Closes a dialog box. */ close(): void; } /** * The component is used to provide an image frame animator. */ 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. */ start(): void; /** * Pauses the frame animation playback of an image. */ pause(): void; /** * Stops the frame animation playback of an image. */ stop(): void; /** * Resumes the frame animation playback of an image. */ resume(): void; /** * Obtains the playback state. Available values are as follows: * Playing * Paused * Stopped */ getState(): string; } /** * 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. */ export interface MarqueeElement extends Element { /** * Starts scrolling. */ start(): void; /** * Stops scrolling. */ stop(): void; } /** * The component provides menus as temporary pop-up windows to display operations that can be performed by users. */ 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 */ show(position: { x: number; y: number }): void; } /** * The component displays line charts, gauge charts, and bar charts. */ 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. */ 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. */ 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. */ 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 */ showError(param: { error: string }): void; } /** * The