narraleaf-react
Version:
A React visual novel player framework
103 lines (102 loc) • 4.1 kB
TypeScript
import type { TransformDefinitions } from "../../elements/transform/type";
import { Color, CommonDisplayableConfig, ImageSrc } from "../../types";
import { LogicAction } from "../../game";
import { FlexibleTuple, SelectElementFromEach } from "../../../../util/data";
import { Chained, Proxied } from "../../action/chain";
import { Displayable } from "../../elements/displayable/displayable";
import { EventfulDisplayable } from "../../../player/elements/displayable/type";
import { ImageTransition } from "../../elements/transition/transitions/image/imageTransition";
import { Layer } from "../../elements/layer";
export type TagDefinition<T extends TagGroupDefinition | null> = T extends TagGroupDefinition ? TagDefinitionObject<T> : never;
export type TagDefinitionObject<T extends TagGroupDefinition> = {
groups: T;
defaults: SelectElementFromEach<T>;
resolve: TagSrcResolver<T>;
};
type ImageSrcType<T extends TagGroupDefinition | null = TagGroupDefinition | null> = T extends TagGroupDefinition ? TagDefinition<T> : (Color | ImageSrc);
export interface IImageUserConfig<Tag extends TagGroupDefinition | null = TagGroupDefinition | null> extends CommonDisplayableConfig {
/**
* The name of the image, only for debugging purposes
*/
name: string;
/**
* If set to false, the image won't be initialized unless you call `init` method
* @default true
*/
autoInit: boolean;
/**
* Image Src, see [Image](https://react.narraleaf.com/documentation/core/elements/image) for more information
*/
src: ImageSrcType<Tag>;
/**
* Auto resize image's width to fit the screen
* @default false
*/
autoFit: boolean;
/**
* layer of the image
*/
layer?: Layer;
/**
* Darkness of the image, between 0 and 1
* @default 0
*/
darkness?: number;
}
export type TagGroupDefinition = string[][];
export type TagSrcResolver<T extends TagGroupDefinition> = (...tags: SelectElementFromEach<T>) => string;
export declare class Image<Tags extends TagGroupDefinition | null = TagGroupDefinition | null> extends Displayable<ImageDataRaw, Image, TransformDefinitions.ImageTransformProps> implements EventfulDisplayable {
constructor(config?: Partial<IImageUserConfig<Tags>>);
/**
* Set the source of the image
*
* - Tag-based image: the src will be resolved from the tags
* - Static image: the src will be a string or StaticImageData
* @example
* ```ts
* image.char("path/to/image.png", new Dissolve(1000));
* ```
* @example
* ```ts
* image.char(["happy", "t-shirt", "shorts"], new Dissolve(1000));
* ```
* @chainable
*/
char(src: ImageSrc | Color, transition?: ImageTransition): Proxied<Image, Chained<LogicAction.Actions>>;
char(tags: SelectElementFromEach<Tags> | FlexibleTuple<SelectElementFromEach<Tags>>, transition?: ImageTransition): Proxied<Image, Chained<LogicAction.Actions>>;
/**
* Set the darkness of the image
* @param darkness - The darkness of the image, between 0 and 1
* @chainable
*/
darken(darkness: number, duration?: number, easing?: TransformDefinitions.EasingDefinition): Proxied<Image, Chained<LogicAction.Actions>>;
/**
* Add a wearable to the image
* @param children - Wearable image or images
*/
addWearable(children: Image | Image[]): this;
/**
* Add a wearable to the image
*
* Alias of {@link Image.addWearable}
* @param children - Wearable image or images
*/
wear(children: Image | Image[]): this;
/**
* Bind this image to a parent image as a wearable
* @param parent - The parent image
*/
bindWearable(parent: Image): this;
/**
* Bind this image to a parent image as a wearable
*
* Alias of {@link Image.bindWearable}
* @param parent - The parent image
*/
asWearableOf(parent: Image): this;
/**
* Use layer for the image, will override the layer in the image config
*/
useLayer(layer: Layer | null): this;
}
export {};