wl-live2d
Version:
Live2D for web, 这是一个运行在浏览器环境的 Live2D 看板组件
2,335 lines (2,304 loc) • 74.7 kB
TypeScript
import { MotionPreloadStrategy, Live2DModel } from 'pixi-live2d-display';
import * as pixi_js from 'pixi.js';
import { Application } from 'pixi.js';
import { EventEmitter } from 'eventemitter3';
import { HitAreaFrames } from 'pixi-live2d-display/extra';
/**
* @class
* @summary 消息数据类
* @classdesc 消息数据集合, 用于存储消息数据, 包括但不限于 DMessage
* @memberof module:modules
* @alias DMessage
* @mixes DHourMessage
* @mixes DSeasonsMessage
* @mixes DEventMessage
*/
declare class DMessage implements Record<string, any> {
/**
* 条件函数, 满足条件时显示消息, 不满足时不显示消息
*
* 消息从 `condition() == true` 中的集合中选取
* @summary 条件函数
* @type {?TBoolCallback}
* @default FHelp.T
* @see FHelp.T
*/
condition: TBoolCallback | null;
/**
* 在提示框中显示的消息文本, 可以是 string 也可以是 string[]
*
* 是数组的话将会从其中随机选取
* @summary 消息文本
* @type {string|string[]}
* @default ''
*/
text: string | string[];
/**
* 优先级, 高优先级消息将会覆盖低优先级的消息
* @summary 消息优先级
* @type {?number}
* @default 2
*/
priority: number | null;
/**
* 消息的类型, 例如: hour, date, event 等等
*
* 也可以自定义类型用于自定义插件
* @summary 消息类型
* @type {?string}
* @default null
*/
type: string | null;
/**
* 创建消息数据实例
* @summary 消息数据构造
* @hideconstructor
* @param {DMessage | null} [data=null] 消息数据
*/
constructor(data?: DMessage | null);
/**
* 消息的默认优先级
* @summary 默认优先级
* @readonly
*/
static readonly priority = 2;
}
/**
* @class
* @summary 模型数据类
* @classdesc 模型数据集合, 用于存储模型数据
* @memberof module:modules
* @alias DModel
*/
declare class DModel {
/**
* 模型的 json 文件的 url 地址, 可以是相对路径, 必填项.
* @summary url 地址
* @type {string}
* @default ''
* @example
* // 绝对路径
* https://fastly.jsdelivr.net/gh/Eikanya/Live2d-model/%E5%B4%A9%E5%9D%8F%E5%AD%A6%E5%9B%AD2/yiselin/model.json
*
* // 相对路径
* // 假设你的主机URL为https://fastly.jsdelivr.net, 那么相对路径如下
* /gh/Eikanya/Live2d-model/%E5%B4%A9%E5%9D%8F%E5%AD%A6%E5%9B%AD2/yiselin/model.json
*/
path: string;
/**
* 模型音量, 用于控制播发音频时的音量大小
* @summary 模型音量
* @type {?number}
* @default 0.5
*/
volume: number | null;
/**
* 模型的缩放比例
* @summary 模型缩放
* @type {?number}
* @default 1
*/
scale: number | null;
/**
* 模型的旋转角度
* @summary 模型旋转
* @type {?number}
* @default 0
*/
rotate: number | null;
/**
* 模型在舞台中的位置. x: 横坐标, y: 纵坐标
* @summary 模型位置
* @type {?TPosition}
* @default {x: 0, y: 0}
*/
position: TPosition | null;
/**
* 舞台的背景颜色, 取有效的颜色值, rbg 或 rgba, 默认透明未设置默认为空的
* @summary 模型背景颜色
* @type {?string}
* @default 'transparent'
*/
backgroundColor: string | null;
/**
* 模型的宽度, 单位 px, 默认不设置, 将自适应使用模型本体的宽度
* @summary 模型宽度
* @type {?number}
* @default null
*/
width: number | null;
/**
* 模型的高度, 单位 px, 默认不设置, 将自适应使用模型本体的高度
* @summary 模型高度
* @type {?number}
* @default null
*/
height: number | null;
/**
* 指示如何预加载动作
* @summary motion 预加载
* @type {?TMotionPreload}
* @default TMotionPreload.NONE
*/
motionPreload: MotionPreloadStrategy | null;
/**
* 创建模型数据实例
* @summary 模型数据构造
* @hideconstructor
* @param {?DModel} [data=null] 模型数据
*/
constructor(data?: DModel | null);
}
/**
* @class
* @summary 基础插件
* @classdesc live2d 基础插件, 所有插件都需要从此类继承
* @abstract
* @hideconstructor
* @memberof module:plugins
* @alias FBasePlugin
*/
declare class FBasePlugin {
/**
* 插件名称必须是唯一的, 如果有重复的名称, 则后面的插件将不会安装
* @summary 插件名称
* @readonly
* @type {string}
* @default ''
*/
readonly name: string;
/**
* 插件优先级, 在安装插件是会按照优先级依次执行
* @summary 优先级
* @protected
* @type {number}
* @default 0
*/
readonly priority: number;
/**
* 插件 live2d 上下文, 用于获取对应的数据
* @summary live2d 上下文
* @protected
* @type {ULive2dController}
*/
private _live2d;
/**
* 插件 live2d 上下文, 用于获取对应的数据
* @summary live2d 上下文
* @protected
* @type {ULive2dController}
*/
get live2d(): ULive2dController;
/**
* 设置插排的 live2d 上下文
* @param {FBasePlugin} plugin 插件
* @param {ULive2dController | null} context live2d 上下文
*/
static setContext(plugin: FBasePlugin, context: ULive2dController | null): void;
/**
* 在安装插件时需要调用的函数, 一般用于初始化以及事件绑定等等
* @summary 安装插件
* @abstract
* @return {void}
*/
install(): void;
/**
* 在卸载插件时需要调用的函数, 一般用于销毁数据以及事件解绑等等
* @summary 卸载插件
* @abstract
* @return {void}
*/
uninstall(): void;
}
/**
* @class
* @summary 图片捕获插件
* @classdesc 用于捕获 live2d 图片的捕获插件
* @hideconstructor
* @extends {FBasePlugin}
* @memberof module:plugins
* @alias FCapturePlugin
* @see 关于如何捕获 image 请参阅 [Extract]{@link https://api.pixijs.io/@pixi/extract/PIXI/Extract.html}
*/
declare class FCapturePlugin extends FBasePlugin {
/**
* @default capture
* @override
*/
readonly name = "capture";
/**
* @default 8
* @override
*/
priority: number;
/**
* 图片捕获的按钮元素
* @type {HTMLDivElement}
* @protected
*/
protected _button: HTMLDivElement | null;
/**
* 监听事件函数
* @type {TFunc<any>}
* @private
*/
private _func?;
/**
* @override
*/
install(): void;
/**
* @override
*/
uninstall(): void;
/**
* 将捕获的 live2d 图片下载到本地
* @summary 下载图片
* @return {Promise<void>}
* @async
*/
downloadImage(): Promise<void>;
}
/**
* @class
* @summary wrapper 拖拽插件
* @classdesc 拖拽 wrapper 元素的拖拽插件
* @hideconstructor
* @extends {FBasePlugin}
* @memberof module:plugins
* @alias FDragPlugin
*/
declare class FDragPlugin extends FBasePlugin {
/**
* 插件名称必须是唯一的, 如果有重复的名称, 则后面的插件将不会安装
* @summary 插件名称
* @protected
* @type {string}
* @default 'drag'
*/
readonly name: string;
/**
* 当前窗口显示区域的宽高
* @summary 窗口宽高
* @type {TRect}
* @protected
*/
protected _screen: TRect;
/**
* true: wrapper 在左边, false: wrapper 在右边
* @summary wrapper 的左右位置
* @type {boolean}
* @default true
* @protected
*/
protected _isLeft: boolean;
protected _startFun: (event: any) => void;
protected _runFun: (event: any) => void;
protected _endFun: () => void;
/**
* 需要进行拖拽的元素 - stage.wrapper
* @summary 拖拽的元素
* @type {HTMLElement}
* @protected
*/
protected _element: HTMLElement | null;
/**
* 拖拽时的上一个事件数据
* @summary 拖拽事件数据
* @type {MouseEvent|TouchEvent}
* @protected
*/
protected _event: (MouseEvent & TouchEvent) | null;
/**
* 在安装插件时需要调用的函数, 一般用于初始化以及事件绑定等等
* @summary 安装插件
* @return {void}
*/
install(): void;
/**
* 在卸载插件时需要调用的函数, 一般用于销毁数据以及事件解绑等等
* @summary 卸载插件
* @return {void}
*/
uninstall(): void;
/**
* 获取当前需要进行拖拽的元素
* @summary 获取拖拽元素
* @return {HTMLElement}
*/
getDragElement(): HTMLElement;
/**
* 获取当前窗口显示区域的宽高
* @summary 获取窗口宽高
* @return {TRect} 宽高
*/
getWidthHeight(): TRect;
/**
* 当鼠标移动或者触摸移动时持续更新拖拽位置
* @summary 运行拖拽
* @param {MouseEvent|TouchEvent} event 鼠标事件 | 触摸事件
* @protected
*/
protected _run(event: MouseEvent & TouchEvent): void;
/**
* 当鼠标离开或者触摸结束时清除事件
* @summary 拖拽结束
* @protected
*/
protected _end(): void;
/**
* 当鼠标按下或者触摸开始时开始拖拽 element 元素
* @summary 拖拽开始
* @param {MouseEvent|TouchEvent} event 拖拽时的初始事件
* @protected
*/
protected _start(event: MouseEvent & TouchEvent): void;
}
/**
* @class
* @summary tips 拖拽插件
* @classdesc 拖拽 tips 元素的拖拽插件
* @hideconstructor
* @extends {FDragPlugin}
* @memberof module:plugins
* @alias FTipsDragPlugin
*/
declare class FTipsDragPlugin extends FDragPlugin {
/**
* @default 'tipsDrag'
* @override
*/
readonly name = "tipsDrag";
/**
* @override
*/
install(): void;
/**
* @override
*/
uninstall(): void;
/**
* @override
*/
getDragElement(): HTMLElement;
/**
* @override
*/
protected _start(event: MouseEvent & TouchEvent): void;
/**
* @override
*/
protected _run(event: MouseEvent & TouchEvent): void;
}
/**
* @class
* @summary 返回首页插件
* @classdesc 点击后用于返回到首页的的捕获插件
* @hideconstructor
* @extends {FBasePlugin}
* @memberof module:plugins
* @alias FHomePlugin
*/
declare class FHomePlugin extends FBasePlugin {
/**
* @default 'quit'
* @override
*/
readonly name = "home";
/**
* @default 0
* @override
*/
priority: number;
/**
* 返回首页的按钮元素
* @type {HTMLDivElement | null}
* @protected
*/
protected _back: HTMLDivElement | null;
/**
* 监听事件函数
* @type {TFunc<any>}
* @private
*/
private _func?;
/**
* @override
*/
install(): void;
/**
* @override
*/
uninstall(): void;
/**
* 点击首页按钮式返回到网站的首页
* @summary 返回首页
*/
backToHome(): void;
}
/**
* @class
* @summary 文档信息插件
* @classdesc 用于跳转到文档信息的插件
* @hideconstructor
* @extends {FBasePlugin}
* @memberof module:plugins
* @alias FInfoPlugin
*/
declare class FInfoPlugin extends FBasePlugin {
/**
* @default 'info'
* @override
*/
readonly name = "info";
/**
* @default 4
* @override
*/
priority: number;
/**
* 信息按钮元素, 用于跳转网页
* @summary 元素
* @protected
* @type {HTMLElement}
* @protected
*/
protected _button: HTMLElement | null;
/**
* @override
*/
install(): void;
/**
* @override
*/
uninstall(): void;
/**
* 在外部网页打开开发文档
* @summary 打开文档
* @see 详情请查看 [wlLive2d](https://live2d.doc.nianian.cn/)
*/
openDocs(): void;
}
/**
* @class
* @summary null 消息插件
* @classdesc null 类型的消息提示插件
* @hideconstructor
* @extends {FBasePlugin}
* @memberof module:plugins
* @alias FNullMessagePlugin
*/
declare abstract class FNullMessagePlugin<T extends DMessage = DMessage> extends FBasePlugin {
/**
* 插件名称必须是唯一的, 如果有重复的名称, 则后面的插件将不会安装
* @summary 插件名称
* @protected
* @type {string}
* @default 'nullMessage'
*/
readonly name: string;
/**
* 既是消息提示的优先级, 也是插件的优先级
* @summary 优先级
* @protected
* @type {number}
* @default 2
*/
priority: number;
/**
* 消息数据对应的类型
* @summary 消息类型
* @type {?string}
* @protected
* @default null
*/
protected _type: string | null;
/**
* 与 type 对应的消息集合
* @summary 消息集
* @type {DMessage[]}
* @protected
* @default []
*/
protected _messages: T[];
/**
* 在安装插件时需要调用的函数, 一般用于初始化, 类型混合, 消息筛选以及事件绑定等等
* @summary 安装插件
* @return {void}
*/
install(): void;
/**
* 在卸载插件时需要调用的函数, 一般用于销毁数据以及恢复消息默认值等等
* @summary 卸载插件
* @return {void}
*/
uninstall(): void;
/**
* 判断消息类型是否与指定的类型相同
* @summary 判断消息类型
* @template {DMessage} T
* @param {T} message 需需要判断的消息
* @return {boolean} true: 相同
*/
isType(message: T): boolean;
/**
* 消息实例的判断函数, 用于判断是否显示消息
* @summary 条件判断
* @return {boolean} true: 可以显示该消息
* @this DMessage
*/
condition(): boolean;
/**
* 卸载时恢复消息实例的默认值
* @summary 恢复默认值
* @template {DMessage} T
* @param {T} message 消息实例
*/
setDefault(message: T): void;
}
/**
* @class
* @summary 事件消息
* @classdesc 与事件相关的消息数据类
* @memberof module:plugins
* @alias DEventMessage
* @mixin
*/
declare class DEventMessage extends DMessage {
/**
* 指定的事件类型, 例如 `copy`, `console` 等等
* @summary 事件
* @type {?string}
* @default null
*/
event: string | null;
}
/**
* @class
* @summary 事件消息
* @classdesc 事件类型的消息提示插件
* @hideconstructor
* @abstract
* @extends {FNullMessagePlugin}
* @memberof module:plugins
* @alias FEventMessagePlugin
*/
declare class FEventMessagePlugin extends FNullMessagePlugin<DEventMessage> {
/**
* 插件名称必须是唯一的, 如果有重复的名称, 则后面的插件将不会安装
* @summary 插件名称
* @protected
* @type {string}
* @default 'eventMessage'
*/
readonly name: string;
/**
* @default 18
* @override
*/
priority: number;
/**
* @default 'event'
* @override
*/
protected _type: string;
/**
* 消息数据的事件对应的类型
* @summary 事件类型
* @type {?string}
* @default null
* @protected
*/
protected _event: string | null;
/**
* @override
*/
install(): void;
/**
* @override
*/
uninstall(): void;
/**
* @override
*/
isType(message: DEventMessage): boolean;
/**
* @override
* @this {DMessage}
*/
condition(): boolean;
/**
* @override
*/
setDefault(message: DEventMessage): void;
/**
* 添加 event 对应的事件监听
* @summary 添加事件
* @abstract
*/
addListener(): void;
/**
* 移除 event 对应的事件监听
* @summary 移除监事件
* @abstract
*/
removeListener(): void;
/**
* 立即通知对应的事件消息
* @summary 通知消息
* @async
*/
notify(): Promise<void>;
}
/**
* @class
* @summary 控制台事件消息
* @classdesc 控制台打开事件对应的消息提示插件
* @hideconstructor
* @extends {FEventMessagePlugin}
* @memberof module:plugins
* @alias FConsoleMessagePlugin
* @see 更多开发工具检测请参见 [devtools-detect](https://github.com/sindresorhus/devtools-detect)
*/
declare class FConsoleMessagePlugin extends FEventMessagePlugin {
/**
* @default 'consoleEventMessage'
* @override
*/
readonly name = "consoleEventMessage";
/**
* query控制台是否打开打开, true: 已打开, false: 没有打开
* @summary 控制台打开
* @type {boolean}
* @default false
* @protected
*/
protected _open: boolean;
/**
* @default 'copy'
* @override
*/
protected _event: string;
/**
* 监听事件函数
* @type {TFunc<any>}
* @private
*/
private _func?;
/**
* @override
*/
addListener(): void;
/**
* @override
*/
removeListener(): void;
/**
* @override
*/
notify(): Promise<void>;
/**
* 检测控制台是否打开
* @summary 控制台打开
* @return {boolean} true: 控制台已打开
*/
isOpen(): boolean;
}
/**
* @class
* @summary 拷贝事件消息
* @classdesc 拷贝事件对应的消息提示插件
* @hideconstructor
* @extends {FEventMessagePlugin}
* @memberof module:plugins
* @alias FCopyMessagePlugin
*/
declare class FCopyMessagePlugin extends FEventMessagePlugin {
/**
* @default 'copyEventMessage'
* @override
*/
readonly name = "copyEventMessage";
/**
* @default 'copy'
* @override
*/
protected _event: string;
/**
* 监听事件函数
* @type {TFunc<any>}
* @private
*/
private _func?;
/**
* @override
*/
addListener(): void;
/**
* @override
*/
removeListener(): void;
}
/**
* @class
* @classdesc 可见性事件消息
* @classdesc wrapper 变得可见或被隐藏时的事件对应的消息提示插件
* @hideconstructor
* @extends {FEventMessagePlugin}
* @memberof module:plugins
* @alias FVisibilityMessagePlugin
*/
declare class FVisibilityMessagePlugin extends FEventMessagePlugin {
/**
* @default 'visibilityEventMessage'
* @override
*/
readonly name = "visibilityEventMessage";
/**
* @default 'copy'
* @override
*/
protected _event: string;
/**
* 判断 wrapper 是否已经显示
* @summary wrapper 已显示
* @type {boolean}
* @default true
* @protected
*/
protected _show: boolean;
/**
* 记录的属性
* @type {any}
* @private
*/
private _prop;
/**
* @override
*/
addListener(): void;
/**
* @override
*/
removeListener(): void;
}
/**
* @class
* @summary 时间消息
* @classdesc 与时间相关的消息数据类
* @memberof module:plugins
* @alias DHourMessage
* @mixin
*/
declare class DHourMessage extends DMessage {
/**
* 指定的小时时间段,
* 例: 2-4, 4,
* 如果为 null 则不显示消息
* @summary 小时
* @type {?string}
* @default null
*/
hour: string | null;
/**
* 用于指示消息是否只显示一次
* @summary 执行一次
* @type {?boolean}
* @default true
*/
once: boolean | null;
}
/**
* @class
* @summary 小时消息插件
* @classdesc 小时类型的消息提示插件
* @hideconstructor
* @extends {FNullMessagePlugin}
* @memberof module:plugins
* @alias FHourMessagePlugin
*/
declare class FHourMessagePlugin extends FNullMessagePlugin<DHourMessage> {
/**
* @default 'hourMessage'
* @override
*/
readonly name = "hourMessage";
/**
* @default 'hour'
* @override
*/
protected _type: string;
/**
* @default 8
* @override
*/
priority: number;
/**
* @override
* @this {DMessage & DHourMessage}
*/
condition(): boolean;
}
/**
* @class
* @summary motion 消息
* @classdesc 模型触发 motion 时的消息提示插件
* @hideconstructor
* @extends {FBasePlugin}
* @memberof module:plugins
* @alias FMotionMessagePlugin
*/
declare class FMotionMessagePlugin extends FBasePlugin {
/**
* @default 'motionMessage'
* @override
*/
readonly name = "motionMessage";
/**
* @default 22
* @override
*/
priority: number;
/**
* @override
* @listens EEvent#motionStart 模型运动开始事件
*/
install(): void;
/**
* @override
*/
uninstall(): void;
/**
* 当 motion 开始时显示对应的消息
* @summary 通知 motion 消息
* @param {string} group motion 分组名
* @param {number} index motion 分组中的索引
* @param {HTMLAudioElement | null} audio 音频元素
* @async
*/
motion(group: string, index: number, audio: HTMLAudioElement | null): Promise<void>;
}
/**
* @class
* @summary 季节消息
* @classdesc 与季节相关的消息数据类
* @memberof module:plugins
* @alias DSeasonsMessage
* @mixin
*/
declare class DSeasonsMessage extends DMessage {
/**
* 指定的季节日期,
* 例: 01/01, 02/14,
* 如果为 null 则不显示消息
* @summary 日期
* @type {?string}
* @default null
*/
date: string | null;
/**
* 用于指示消息是否只显示一次
* @summary 执行一次
* @type {?boolean}
* @default true
*/
once: boolean | null;
}
/**
* @class
* @summary 季节消息插件
* @classdesc 季节类型的消息提示插件
* @hideconstructor
* @extends {FNullMessagePlugin}
* @memberof module:plugins
* @alias FSeasonsMessagePlugin
*/
declare class FSeasonsMessagePlugin extends FNullMessagePlugin<DSeasonsMessage> {
/**
* @default 'seasonsMessage'
* @override
*/
readonly name = "seasonsMessage";
/**
* @default 16
* @override
*/
priority: number;
/**
* @default 'seasons'
* @override
*/
protected _type: string | null;
/**
* @override
* @this {DSeasonsMessage}
*/
condition(): boolean;
}
/**
* @class
* @summary 随机消息
* @classdesc 用于获取随机消息的消息提示插件
* @hideconstructor
* @extends {FBasePlugin}
* @memberof module:plugins
* @alias FTalkMessagePlugin
* @see
* > [一言API]{@link https://developer.hitokoto.cn/sentence/demo.html}
* >>
* > [夏柔-每日一言]{@link https://api.aa1.cn/doc/yiyan.html}
* >>
* > [TenApi-随机一言]{@link https://docs.tenapi.cn/random/yiyan.html#%E9%9A%8F%E6%9C%BA%E4%B8%80%E8%A8%80}
*/
declare class FTalkMessagePlugin extends FBasePlugin {
/**
* @default 'sentenceMessage'
* @override
*/
readonly name = "sentenceMessage";
/**
* @default 20
* @override
*/
priority: number;
/**
* 消息数据对应的类型
* @summary 消息类型
* @type {string}
* @default 'talk'
* @protected
*/
protected _type: string;
/**
* 获取的随机消息所使用的消息载体
* @summary 随机消息
* @type {DMessage}
* @protected
*/
protected _message: DMessage | null;
/**
* 时间间隔定时器 id
* @summary 定时器 id
* @protected
* @type {?number}
* @default null
*/
protected _handler: number | null;
/**
* 用于存储 url 以及处理 talk 结果的对象
* @summary talk api 对象
* @type {TTalkApi[]}
* @default []
* @protected
*/
protected _talkApis: TTalkApi[];
/**
* @override
*/
install(): void;
/**
* @override
*/
uninstall(): void;
/**
* 消息实例的判断函数, 用于判断是否显示消息
* @summary 条件判断
* @param {UTipsController} tips tips 控制器
* @return {boolean} true: 可以显示该消息
* @this {DMessage}
*/
condition(tips: UTipsController): boolean;
/**
* 间隔一定时间后获获取随机文本, 并将该消息添加到 tips 的消息集中
* @summary 获取随机文本
* @return {Promise<void>}
* @async
*/
getTalkValue(): Promise<void>;
}
/**
* @class
* @summary 关闭和打开看板娘
* @classdesc 用于关闭看板娘以及打开看板娘的插件
* @hideconstructor
* @extends {FBasePlugin}
* @memberof module:plugins
* @alias FQuitPlugin
*/
declare class FQuitPlugin extends FBasePlugin {
/**
* @default 'quit'
* @override
*/
readonly name = "quit";
/**
* @default 0
* @override
*/
priority: number;
/**
* 用于关闭看板娘的元素
* @summary 关闭按钮元素
* @protected
* @type {?HTMLElement}
*/
protected _quit: HTMLElement | null;
/**
* 用于打开看板娘的元素
* @summary 打开按钮元素
* @protected
* @type {HTMLElement}
*/
protected _show: HTMLElement | null;
/**
* 监听事件函数
* @type {TFunc<any>}
* @private
*/
private _hiddenFun?;
/**
* 监听事件函数
* @type {TFunc<any>}
* @private
*/
private _showFun?;
/**
* @override
*/
install(): void;
/**
* @override
*/
uninstall(): void;
/**
* 在点击关闭按钮元素时隐藏 live2d 舞台
* @summary 隐藏 live2d
*/
hiddenLive2d(): void;
/**
* 在点击关闭按钮元素时显示 live2d 舞台
* @summary 显示 live2d
*/
showLive2d(): void;
/**
* 判断看板娘的显示按钮是覆盖在右边还是左边
* @summary 判断显示按钮的位置是在左边还是右边
* @return {boolean} true 和 false
*/
isRight(): boolean;
}
/**
* @class
* @summary 基础切换插件
* @classdesc 用于切换的基础切换插件
* @hideconstructor
* @abstract
* @extends {FBasePlugin}
* @memberof module:plugins
* @alias FBaseSwitchPlugin
*/
declare class FBaseSwitchPlugin extends FBasePlugin {
/**
* 插件名称必须是唯一的, 如果有重复的名称, 则后面的插件将不会安装
* @summary 插件名称
* @protected
* @type {string}
* @default 'switch'
*/
readonly name: string;
/**
* 用于切换的按钮元素
* @summary 切换按钮
* @protected
* @type {HTMLElement}
*/
protected _button: HTMLElement | null;
/**
* 用于切换模型后显示是否还在加载中的加载元素
* @summary 加载中
* @protected
* @type {HTMLElement}
*/
protected _loading: HTMLElement | null;
/**
* 监听事件函数
* @type {TFunc<any>}
* @private
*/
private _func?;
/**
* 在安装插件时需要调用的函数, 一般用于初始化以及事件绑定等等
* @summary 安装插件
* @return {void}
*/
install(): void;
/**
* 在卸载插件时需要调用的函数, 一般用于销毁数据以及事件解绑等等
* @summary 卸载插件
* @return {void}
*/
uninstall(): void;
/**
* 点击切换按钮后开始切换模型
* @summary 开始切换
* @return {Promise<void>}
* @async
*/
startSwitch(): Promise<void>;
/**
* 是否应该显示加载元素, true: 显示加载, false: 不显示加载
* @summary 显示加载元素
* @abstract
* @return {boolean} true: 显示加载, false: 不显示加载
*/
showLoading(): boolean;
/**
* 用于切换模型或者服装
* @summary 切换功能
* @abstract
* @return {Promise<void>}
* @async
*/
switch(): Promise<void>;
}
/**
* @class
* @summary 模型切换插件
* @classdesc 用于切换模型的切换插件
* @hideconstructor
* @extends {FBaseSwitchPlugin}
* @memberof module:plugins
* @alias FSwitchModulePlugin
*/
declare class FSwitchModulePlugin extends FBaseSwitchPlugin {
/**
* @default 'switchModule'
* @override
*/
readonly name = "switchModule";
/**
* @default 12
* @override
*/
priority: number;
/**
* @override
*/
install(): void;
/**
* @summary 切换模型
* @override
*/
switch(): Promise<void>;
/**
* @override
*/
showLoading(): boolean;
}
/**
* @class
* @summary 服装切换插件
* @classdesc 用于切换模型型服的切换插件
* @hideconstructor
* @extends {FBaseSwitchPlugin}
* @memberof module:plugins
* @alias FSwitchTexturePlugin
*/
declare class FSwitchTexturePlugin extends FBaseSwitchPlugin {
/**
* @default 'switchTexture'
* @override
*/
readonly name = "switchTexture";
/**
* @default 16
* @override
*/
priority: number;
/**
* @override
*/
install(): void;
/**
* @summary 切换服装
* @override
*/
switch(): Promise<void>;
/**
* @override
*/
showLoading(): boolean;
}
/**
* @class
* @summary 命中区域帧检测插件
* @classdesc 点击后用于显示 model 的帧检测
* @hideconstructor
* @extends {FBasePlugin}
* @memberof module:plugins
* @alias FHitFramesPlugin
*/
declare class FHitFramesPlugin extends FBasePlugin {
/**
* @default 'hitFrames'
* @override
*/
readonly name = "hitFrames";
/**
* @default 0
* @override
*/
priority: number;
/**
* 返回首页的按钮元素
* @type {HTMLDivElement | null}
* @protected
*/
protected _button: HTMLDivElement | null;
/**
* 开启和关闭时的图标
* @type {{close: string, open: string}}
* @private
*/
private _icons;
/**
* 监听事件函数
* @type {TFunc<any>}
* @private
*/
private _func?;
/**
* @override
*/
install(): void;
/**
* @override
*/
uninstall(): void;
/**
* 点击测试帧按钮
* @summary 显示或关闭测试帧
*/
clickTestFrame(): void;
}
/**
* @module plugins
*/
declare const plugins: {
FHomePlugin: typeof FHomePlugin;
FDragPlugin: typeof FDragPlugin;
FInfoPlugin: typeof FInfoPlugin;
FQuitPlugin: typeof FQuitPlugin;
FCapturePlugin: typeof FCapturePlugin;
FTipsDragPlugin: typeof FTipsDragPlugin;
FTestFramePlugin: typeof FHitFramesPlugin;
FSwitchModulePlugin: typeof FSwitchModulePlugin;
FSwitchTexturePlugin: typeof FSwitchTexturePlugin;
FHourMessagePlugin: typeof FHourMessagePlugin;
FMotionMessagePlugin: typeof FMotionMessagePlugin;
FSeasonsMessagePlugin: typeof FSeasonsMessagePlugin;
FTalkMessagePlugin: typeof FTalkMessagePlugin;
FCopyMessagePlugin: typeof FCopyMessagePlugin;
FConsoleMessagePlugin: typeof FConsoleMessagePlugin;
FVisibilityMessagePlugin: typeof FVisibilityMessagePlugin;
};
/**
* @class
* @summary 提示数据类
* @classdesc 提示数据集合, 用于存储提示数据, 以及消息数据
* @memberof module:modules
* @alias DTips
*/
declare class DTips {
/**
* 提示框最小宽度, 单位 px
* @summary 最小宽度
* @type {?number}
* @default 230
*/
minWidth: number | null;
/**
* 提示框最小高度, 单位 px
* @summary 最小高度
* @type {?number}
* @default 100
*/
minHeight: number | null;
/**
* 调整提示框位于舞台中的 x 轴方向偏移量
* @summary x 偏移量
* @type {?number}
* @default 0
*/
offsetX: number | null;
/**
* 调整提示框位于舞台中的 y 轴方向偏移量
* @summary y 偏移量
* @type {?number}
* @default 0
*/
offsetY: number | null;
/**
* 提示框显示时的持续时间, 单位 ms
* @summary 持续时间
* @type {?number}
* @default 3000
*/
duration: number | null;
/**
* 提示框隐藏时的持续时间, 单位 ms
* @summary 隐藏时间
* @type {?number}
* @default 5000
*/
interval: number | null;
/**
* 播放的消息内容, 需要是一个字符串数组, 播放时会从中随机取出一条进行提示, 空数组则不播放, 默认为空数组
* @summary 消息数组
* @type {?(DMessage[])}
* @default []
* @example
* [
* {
* "text": "好久不见,日子过得好快呢……"
* },
* {
* "text": "大坏蛋!你都多久没理人家了呀,嘤嘤嘤~"
* },
* {
* "type": "seasons",
* "date": "01/01",
* "text": "<span>元旦</span>了呢,新的一年又开始了,今年是{year}年~"
* },
* {
* "type": "hour",
* "hour": "6-7",
* "text": "早上好!一日之计在于晨,美好的一天就要开始了~"
* },
* {
* "type": "event",
* "event": "console",
* "text": "哈哈,你打开了控制台,是想要看看我的小秘密吗?"
* },
* ]
*/
message: DMessage[] | null;
/**
* 如果是 true, 则启用 tips 元素的拖拽, 否则不启用拖拽
* @summary 启用拖拽
* @type {?boolean}
* @default true
*/
drag: boolean | null;
/**
* true: 启用随机说话
* @summary 随机说话
* @type {?boolean}
* @default true
*/
talk: boolean | null;
/**
* 随机说话的时间间隔, 单位 ms
* @summary 说话间隔
* @type {?number}
* @default 30s
*/
talkInterval: number | null;
/**
* 用于存储 url 以及处理 talk 结果的对象
* @summary talk api 对象
* @type {?(TTalkApi[])}
* @default []
* @example
* [
* {
* url: 'https://v1.hitokoto.cn/',
* handle: async (res) => (await res.json()).hitokoto
* },
* {
* url: 'https://v.api.aa1.cn/api/yiyan/index.php',
* handle: async (res) => (await res.text()).match(/<p>(.*)<\/p>/)[1]
* },
* {
* url: 'https://tenapi.cn/v2/yiyan',
* handle: async res => await res.text()
* }
* ]
*/
talkApis: TTalkApi[] | null;
/**
* 控制是否启用 motion 消息, true: 启用, false: 关闭
* @summary 启用 motion 消息
* @type {?boolean}
* @default true
*/
motionMessage: boolean | null;
/**
* 创建提示数据实例
* @summary 提示数据构造
* @hideconstructor
* @param {DTips | null} [data=null] 提示数据
*/
constructor(data?: DTips | null);
}
/**
* @class
* @summary Live2d 数据类
* @classdesc Live2d 数据集合, 用于存储 live2d 对应的数据
* @memberof module:modules
* @alias DLive2dOptions
*/
declare class DLive2dOptions {
/**
* 是否在初始化阶段打印项目信息
* @summary 打印项目信息
* @type {?boolean}
* @default true
*/
sayHello: boolean | null;
/**
* 元素入场和离开的过渡动画时长,单位 ms
* @summary 过渡动画时长
* @type {?number}
* @default 500
*/
transitionTime: number | null;
/**
* 模型配置, 默认值是空数组, 请至少配置一个有效的模型配置
*
* path 可以使用相对于主机 URL 的相对地址, 也可以使用绝对 URL 地址
*
* 前往{@link DModel}模型选项查看详细内容
*
* @summary 模型配置
* @type {?TModels}
* @default []
* @see TModels
* @example
* [ // 用于切换不同模型
* {
* "path": "https://.../model1.json",
* "scale": 0.5
* },
* {
* "path": "https://.../model2.json",
* "scale": 0.5
* },
* [ // 用于模型的服装切换
* {
* "path": "https://.../model/texture1.json",
* "scale": 0.5
* },
* {
* "path": "https://.../model/texture2.json",
* "scale": 0.5
* },
* ]
* ]
*/
models: TModels | null;
/**
* 自定义提示框样式和内容, 前往 {@link DTips} 提示框选项查看详细内容
* @summary 消息提示配置
* @type {?DTips}
* @default null
* @see DTips
* @example
* {
* drag: true,
* duration: 3000,
* interval: 1000,
* motionMessage: true,
* offsetX: 0,
* offsetY: 0,
* message: [],
* }
*/
tips: DTips | null;
/**
* 默认你启用的菜单项
* @summary 菜单项
* @type {?(string[])}
* @default ['home', 'switchTexture', 'switchModule', 'capture', 'info', 'quit']
* @example
* [
* 'home', 'switchTexture', 'switchModule',
* 'capture', 'info', 'quit'
* ]
*/
menus: string[] | null;
/**
* 父元素的选择器, 支持 css 选择器语法, 以及 xpath 语法. 默认父元素为 {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/body document.body}
*
* 如果父元素有效, 则会将 Live2d 插入到父元素之下
* @summary 父元素选择器
* @type {?string}
* @default ''
* @example
* '#id' // => document.querySelector('#id');
* '//*[@id="id"]' // => document.evaluate('//*[@id="id"]', document).iterateNext();
*/
selector: string | null;
/**
* 组件是否使用固定定位
* > 注意, 关闭这个属性后舞台的定位属性将从 fixed 改为 relative, 使舞台回到文档流,
* >
* > 另外该属性不影响状态条定位属性, 状态条与舞台之间相互独立,样式互不干扰.
* @summary 组件固定定位
* @type {?boolean}
* @default true
*/
fixed: boolean | null;
/**
* 需要使用的插件集,
*
* 可以添加自定义插件用于实现自定义的功能
* @summary 插件
* @type {?(FBasePlugin[])}
* @default []
*/
plugins: FBasePlugin[] | null;
/**
* 如果是 true, 则启用 wrapper 元素的拖拽, 否则不启用拖拽
* @summary 启用拖拽
* @type {?boolean}
* @default true
*/
drag: boolean | null;
/**
* {@link FHomePlugin} 所使用的 URL 地址, 点击后将会跳转到该地址
*
* 如果已 `http://` 开头, 则会跳转对应地址, 否则将会追加至 `window.location.origin` 后跳转到对应地址
* @summary url 路径
* @type {?string}
* @default ''
* @example
* let url = 'https://localhost/live2d';
* // origin => https://localhost
* // homePath => /live2d
*/
homePath: string | null;
/**
* 启用命中区域帧检测
* @summary 帧检测
* @type {?boolean}
* @default false
*/
hitFrame: boolean | null;
/**
* 组件停靠位置, 当您希望组件靠右展示时这个属性会非常有用
* @summary 右边停靠
* @type {?boolean}
* @default false
*/
dockedRight: boolean | null;
/**
* 创建 live2d 数据实例
* @summary Live2d 数据构造
* @hideconstructor
* @param {DLive2dOptions | null} [data=null] live2d 数据
*/
constructor(data?: DLive2dOptions | null);
}
/**
* @class
* @summary live2d 舞台数据
* @classdesc live2d 舞台数据集合, 用于存储 canvas, tips 等文档元素
* @memberof module:modules
* @alias DStage
*/
declare class DStage {
/**
* wrapper 元素的父元素, 默认是 body
*
* 如果 [selector]{@link DLive2dOptions.selector} 已经指定, 则父元素是 selector 对应的元素
* @summary 父元素
* @type {HTMLElement}
* @default body
*/
parent: HTMLElement;
/**
* 画布的包装器元素, 即画布的父元素
* @summary 包装器元素
* @type {HTMLElement}
* @default div
*/
wrapper: HTMLElement;
/**
* 模型需要使用的画布元素
* @summary 画布元素
* @type {HTMLCanvasElement}
* @default canvas
*/
canvas: HTMLCanvasElement;
/**
* 消息提示需要使用的元素
* @summary 消息提示元素
* @type {HTMLDivElement}
* @default canvas
*/
tips: HTMLDivElement;
/**
* 菜单项目的父元素
* @summary 菜单元素
* @type {HTMLElement}
* @default div
*/
menus: HTMLElement;
/**
* 与画布同级别的其它元素
* @summary 其它元素
* @type {HTMLElement}
* @default div
*/
other: HTMLElement;
/**
* 创建 stage 中的所有元素, 如果其中的元素没有指定, 则创建默认类型的元素
* @summary Stage数据构造
* @hideconstructor
* @param {DStage | null} [data=null] 舞台数据
*/
constructor(data?: DStage | null);
}
/**
* @class
* @summary live2d model 属性
* @classdesc 分离出来的 UModelController 的属性
* @extends UBaseController
* @memberof module:controller
* @alias UModelProperty
*/
declare abstract class UModelProperty extends UBaseController {
/**
* 命中区域帧
* @type {HitAreaFrames}
* @protected
*/
protected _hitAreaFrames: HitAreaFrames | null;
/**
* 所有的模型数据, 用于存储对应的模型数据
* @summary 模型数据集
* @protected
* @type {TModels}
*/
protected _data: TModels;
/**
* getter: 所有的模型数据
* @summary 模型数据
* @type {TModels}
* @readonly
*/
get data(): TModels;
/**
* 当前模型在模型集中的位置索引
* @summary 模型索引
* @protected
* @type {number}
*/
protected _modelId: number;
/**
* 当前模型在模型集中的位置索引
* @summary 模型索引
* @type {number}
*/
get modelId(): number;
/**
* @param {number} index 模型索引
*/
protected set modelId(index: number);
/**
* 当前模型贴图在模型集 `data[modelId]` 中的二维位置索引
* @summary 贴图索引
* @protected
* @type {number}
*/
protected _textureId: number;
/**
* 当前模型贴图在模型集 `data[modelId]` 中的位置索引
* @summary 贴图索引
* @type {number}
*/
get textureId(): number;
/**
* @param {number} index 贴图索引
*/
protected set textureId(index: number);
/**
* 当前模型集 `data[modelId]` 的最大贴图索引
* @return {number}
*/
get textureMaxIndex(): number;
/**
* 模型加载完成后的模型实例
* @summary 模型实例
* @default null
*/
protected _model: TLive2DModel | null;
/**
* 获取当前正在展示的 live2d 模型实例, 只有在模型加载完成后才不为 null
* @summary 模型实例
* @type {?TLive2DModel}
* @readonly
*/
get model(): TLive2DModel;
/**
* 当前模型索引对应的模型数据项目
* @summary 模型数据项目
* @type {TModelItem}
* @readonly
*/
get modelData(): TModelItem;
/**
* 当前模型正在执行的 motion
* @summary 模型 motion
* @protected
* @type {?string}
* @default null
*/
protected _currentMotion: string | null;
/**
* 当前模型正在执行的 motion, 未执行时为 null
* @summary 模型 motion
* @type {?string}
* @readonly
*/
get currentMotion(): string | null;
/**
* 当前正在展示的模型数据中定义的背景颜色, 默认为 transparent
* @summary 模型背景色
* @type {string}
* @readonly
*/
get backgroundColor(): string;
}
/**
* @class
* @summary model 控制器类
* @classdesc 用于控制模型相关的的控制器, 例如加载模型, 切换模型等等
* @extends UModelProperty
* @memberof module:controller
* @alias UModelController
*/
declare class UModelController extends UModelProperty {
/**
* 创建 live2d model 控制器
* @summary model 控制器构造
* @constructor
* @param {ULive2dController} live2d live2d 上下文
* @param {TModels} [data=[]] 模型数据集
*/
constructor(live2d: ULive2dController, data?: TModels | null);
/**
* 在 model 控制器初始化时开始加载与 modelId 及 textureId 对应的模型
* @summary 初始化 model 控制器
* @override
*/
init(): void;
/**
* 销毁模型实例, 移除模型数据, 以及移除绑定的事件
* @summary 销毁 model 控制器
* @override
*/
destroy(): void;
/**
* 加载与 modelId 及 textureId 对应的模型
*
* modelId 指 {@link TModels} 的第一维的数组索引
*
* textureId 指 {@link TModels} 的第二维的数组索引, 并且存在于 modelId 对应的一维数组内
* @summary 加载模型
* @param {number} modelId 模型索引
* @param {number} [textureId=0] 模型服装索引
* @return {Promise<void>}
* @fires EEvent#modelStart 模型开始加载事件
* @fires EEvent#modelError 模型加载错误事件
* @fires EEvent#modelLoad 模型加载成功事件
* @async
*/
loadModel(modelId: number, textureId?: number): Promise<void>;
/**
* 切换与 modelId 及 textureId 对应的模型
* @summary 切换模型
* @param {number} id 模型索引
* @param {number} [textureId=0] 模型服装索引
* @return {Promise<void>}
* @async
*/
switchModel(id: number, textureId?: number): Promise<void>;
/**
* 切换模型数据集中的下一个模型, 循环切换
* @summary 下一个模型
* @return {Promise<void>}
* @async
*/
nextModel(): Promise<void>;
/**
* 开始切换模型的下一个服装, 循环切换
* @summary 下一个服装
* @return {Promise<void>}
* @async
*/
nextTexture(): Promise<void>;
/**
* 重新加载当前模型
* @summary 重置模型
* @return {Promise<void>}
* @async
*/
resetModel(): Promise<void>;
/**
* 显示模型的可点击区域
* @summary 显示可点击区域
*/
showHitAreaFrames(): void;
/**
* 隐藏模型的可点击区域
* @summary 隐藏可点击区域
*/
hiddenHitAreaFrames(): void;
/**
* 模型触发 hit 时的事件
* @summary hit 事件
* @param {TFunc<string[]>} func 回调函数, 参数为 hitAreas
* @param context this 指向
* @param {boolean} once 是否只用一次
*/
onModelHit(func: TFunc<string[]>, context?: any, once?: boolean): void;
/**
* 在模型加载完成后绑定模型的 `hit` 事件, 并在点击时触发对应的 motion, 同时绑定 motionStart 与 motionFinish
* @summary 绑定 motion
* @param model {TLive2DModel} 模型
* @return {UModelController} 自身引用
* @fires EEvent#motionStart 模型运动开始事件
* @fires EEvent#motionFinish 模型运动完成事件
*/
protected _bindMotion(model: TLive2DModel): UModelController;
}
/**
* @summary 淡入模式
* @enum
*/
declare enum TFadeMode {
/** 淡入 */
fadeIn = "fadeIn",
/** 淡出 */
fadeOut = "fadeOut"
}
/**
* @class
* @summary stage 控制器类
* @classdesc 用于控制 stage 相关的的控制器, 例如控制元素淡入淡出等等
* @extends UBaseController
* @memberof module:controller
* @alias UStageController
*/
declare class UStageController extends UBaseController {
/**
* live2d 舞台数据集合, 用于存储 canvas, tips 等文档元素
* @summary stage 数据
* @protected
* @type {DStage}
*/
protected _data: DStage | null;
/**
* 记录 [_showAndHiddenMenus]{@link _showAndHiddenMenus} 绑定后的函数
* @type {?TFunc<any>}
* @private
*/
private _menuFunc;
/**
* 创建 live2d stage 控制器
* @summary stage 控制器构造
* @constructor
* @param {ULive2dController} live2d live2d 上下文
* @param {string | null} [selector=null] 父元素选择器
* @param {DStage | null} [data=null] 舞台元素数据
* @listens EEvent#modelLoaded 模型加载完成的事件
*/
constructor(live2d: ULive2dController, selector?: string | null, data?: DStage | null);
/**
* 在菜单元素中显示的菜单集
* @protected
* @summary 菜单集
* @type {TStageMenuItem[]}
* @default []
*/
protected _menuItems: TStageMenuItem[];
/**
* getter: 菜单元素数组
* @summary 菜单数组
* @type {TStageMenuItem[]}
* @readonly
*/
get menuItems(): TStageMenuItem[];
/**
* getter: 包装器元素
* @summary 包装器元素
* @return {HTMLElement}
* @readonly
*/
get wrapper(): HTMLElement;
/**
* getter: live2d 模型使用的画布元素
* @summary 画布元素
* @type {HTMLCanvasElement}
* @readonly
*/
get canvas(): HTMLCanvasElement;
/**
* getter: 消息提示框元素
* @summary 提示元素
* @type {HTMLElement}
* @readonly
*/
get tips(): HTMLDivElement;
/**
* getter: 菜单元素
* @summary 菜单元素
* @type {HTMLElement}
* @readonly
*/
get menus(): HTMLElement;
/**
* getter: 其它元素
* @summary 其它元素
* @type {HTMLElement}
* @readonly
*/
get other(): HTMLElement;
/**
* getter: wrapper 的父元素
* @summary 父元素
* @type {HTMLElement}
* @readonly
*/
get parent(): HTMLElement;
/**
* 初始化 stage 控制器, 并为元素设置层级结构以及类名与样式
* @summary 初始化 stage 控制器
* @override
*/
init(): void;
/**
* 销毁控制器, 移除菜单元素, 以及移除绑定的事件
* @summary 销毁 stage 控制器
* @override
*/
destroy(): void;
/**
* 对指定元素应用者淡入动画
* @summary 元素淡入
* @param {HTMLElement | null} [element=null] 需要执行淡入的元素, 默认是包装器元素
* @return {Promise<void>}
* @async
*/
fadeIn(element?: HTMLElement | null): Promise<void>;
/**
* 对指定元素应用者淡出动画
* @summary 元素淡出
* @param {HTMLElement | null} [element=null] 需要执行淡出的元素, 默认是包装器元素
* @return {Promise<void>}
* @async
*/
fadeOut(element?: HTMLElement | null): Promise<void>;
/**
* 将菜单元素及优先级作为一个对象添加到 menuItems, 菜单按照 `priority` 从从大到小排序
* @summary 添加菜单元素
* @param {HTMLElement} element 文档元素
* @param {number} [priority=2] 优先级
* @return {UStageController} 自身引用
*/
addMenu(element: HTMLElement, priority?: number): UStageController;
/**
* 在 menuItems 中移除指定的菜单元素
* @summary 移除菜单元素
* @param {HTMLElement} element 文档元素
* @return {UStageController} 自身引用
*/
removeMenu(element: HTMLElement | null): UStageController;
/**
* 从选择器中获取父元素
*
* `css` 选择器规则优先, 其次是 `xpath` 规则, 当两个都找不到时, 则使用 body 为父元素
* @summary 获取父元素
* @param {string | null} [selector=null] 选择器
* @return {HTMLElement} 获取到的节点元素
*/
getParentFromSelector(selector?: string | null): HTMLElement;
/**
* 获取指定元素的 transition-duration 值, 单位为 ms
* @summary 获取过度时间
* @param {HTMLElement} element 元素
* @return {number} 持续时间
*/
getTransitionDuration(element: HTMLElement): number;
/**
* 判断 wrapper 元素是在窗口的左边还是右边
* @summary 判断 wrapper 的左右位置
* @return {boolean} true 和 false
*/
isRight(): boolean;
/**
* 模型加载完成后触发的事件, 负责设置包装器的宽高, 以及调整模型大小
* @protected
* @summary 模型加载完成后的回调事件
* @param {TLive2DModel} model 模型宽高
* @return {void}
*/
_onModelLoad(model: TLive2DModel): void;
/**
* 当鼠标进入舞台时显示菜单, 离开时隐藏
*
* 当触摸到舞台时显示菜单, 否则隐藏菜单
* @summary 显示和隐藏菜单
* @param {MouseEvent | TouchEvent} event 鼠标事件 | 触摸事件
* @protected
*/
protected _showAndHiddenMenus(event: MouseEvent | TouchEvent): void;
/**
* 对指定元素应用淡入或者淡出动画
* @summary 元素淡入淡出
* @param {HTMLElement | null} element 需要执行动画的元素, 默认是包装器元素
* @param {'fadeIn' | 'fadeOut'} proceed 需要进行的动画名称
* @param {'fadeIn' | 'fadeOut'} exit 需要退出的动画名称
* @return {Promise<void>}
* @fires EEvent#fadeStart 淡入淡出开始时间
* @fires EEvent#fadeEnd 淡入淡出结束事件
* @fires EEvent#fadeCancel 淡入淡出取消事件
* @protected
* @async
*/
protected _fade(element: HTMLElement | null, proceed: TFadeMode, exit: TFadeMode): Promise<void>;
}
/**
* @class
* @summary live2d tips 属性
* @classdesc 分离出来的 UTipsController 的属性
* @extends UBaseController
* @memberof module:controller
* @alias UTipsProperty
*/
declare abstract class UTipsProperty extends UBaseController {
/**
* 在提示框显示期间的定时器 id
* @summary 显示定时器 id
* @protected
* @type {?number}
* @default null
*/
protected _showId?: number;
/**
* 在提示框隐藏期间的定时器 id
* @summary 隐藏定时器 id
* @protected
* @type {?number}
* @default null
*/
protected _hiddenId?: number;
/**
* 提示数据集合, 用于存储提示数据, 以及消息数据
* @summary tips 数据
* @protected
* @type {DTips}
*/
protected _data: DTips;
/**
* getter: 消息提示数据
* @summary tips 数据
* @type {DTips}
* @readonly
*/
get data(): DTips;
/**
* 消息数据集合, 用于存储消息数据, 包括但不限于 DMessage
* @summary 消息数据集
* @protected
* @type {DMessage[]}
* @default []
*/
protected _messages: DMessage[];
/**
* getter: 所有消息提示数据集合
* @summary 消息数据集
* @type {DMessage[]}
* @readonly
*/
get messages(): DMessage[];
/**
* 在提示框显示时期需要显示的文本
* @summary 消息文本
* @protected
* @type {string}
* @default ''
*/
protected _text: string;
/**
* getter: 提示框显示时期的文本值
* @summary 提示框文本
* @type {string}
* @readonly
*/
get text(): string;
/**
* 是否停止 tips 的淡入淡出循环, 如果需要停止的话则需要等待淡出之后才会生效
* @summary 停止提示框循环
* @type {boolean}
* @protected
* @default false
*/
protected _stop: boolean;
/**
* getter: 指示当前是否已经停止 tips 的淡入淡出循环, 如果需要停止的话则需要等待淡出之后才会生效
* @summary 停止提示框循环
* @type {boolean}
* @readonly
*/
get stop(): boolean;
/**
* getter: 提示框显示时的持续时间, 单位 ms
* @summary 显示时的持续时间
* @type {number}
* @readonly
*/
get duration(): number;
/**
* setter: 设置提示框显示时的持续时间, 单位 ms
* @summary 设置显示时的持续时间
* @param {number} value
*/
set duration(value: number);
/**
* getter: 提示框隐藏时的持续时间, 单位 ms
* @summary 隐藏时的持续时间
* @type {number}
* @readonly
*/
get interval(): number;
/**
* setter: 设置提示框隐藏时的持续时间, 单位 ms
* @summary 隐藏时的持续时间
* @param {number} value
*/
set interval(value: number);
}
/**
* @class
* @summary tips 控制器类
* @classdesc 用于控制 tips 相关的的控制器, 例如控制提示框淡入淡出, 以及消息的显示等等
* @extends UTipsProperty
* @memberof module:controller
* @alias UTipsController
*/
declare class UTipsController extends UTipsProperty {
/**
* 创建 live2d tips 控制器
* @summary tips 控制器构造
* @constructor
* @param {ULive2dController} live2d live2d 上下文
* @param {DTips | null} [data=null] tips 数据
*/
constructor(live2d: ULive2dController, data?: DTips | null);
/**
* 初始化 tips 控制器, 并开始提示框的淡入淡出
* @summary 初始化tips控制器
* @override
*/
init(): void;
/**
* 移除绑定事件, 停止淡入淡出, 以及销毁消息集合
* @summary 销毁控制器
* @override
*/
destroy(): void;
/**
* 开始淡入提示框, 淡入完成后等待一段时间执行淡出
*
* 如果 `inherit = true`, 则继承原有的时间, 否则重新开始计时
*
* 如果消息集合为空, 则会一直循环等待消息的添加, 而循环时长为隐藏时长
* @summary 提示框淡入
* @param {boolean} [inherit=false] 继承原有时间
* @return {Promise<void>}
* @async
*/
fadeIn(inherit?: boolean): Promise<void>;
/**
* 开始淡出提示框, 淡出完成后等待一段时间执行淡入
*
* 如果 `inherit = true`, 则继承原有的时间, 否则重新开始计时
* @summary 提示框淡出
* @param {boolean} [inherit=fale] 继承原有时间
* @return {Promise<void>}
* @async
*/
fadeOut(inherit?: boolean): Promise<void>;
/**
* 开始进行淡入, 并将 `stop = false`, 之后恢复淡入淡出循环
* @summary 结束淡入淡出
*/
startFade(): void;
/**
* 立即进行淡出, 并将 `stop = true`, 淡出完成后停止淡入淡出
* @summary 结束淡入淡出
*/
stopFade(): void;
/**
* 立即淡入提示框显示对应的消息, 并且重置提示框显示时长, 完成后从消息集合中移除对应的消息
* @summary 通知消息
* @param {string} text 需要显示的文本
* @async
*/
notify(text: string): Promise<void>;
/**
* 将消息集添加到消息列表中
*
* 通常这并不会立即显示, 而是等待下一轮提示框显示时根据一定概率随机抽取消息进行显示
* @summary 添加消息
* @param {...DMessage} messages 消息集
* @return {UTipsController} 自身引用
*/
addMessage(...messages: DMessage[]): UTipsController;
/**
* 从消息列表中移除对应的消息
* @summary 移除消息
* @param {...DMessage} message 消息集
* @return {UTipsController} 自身引用
*/
removeMessage(...message: DMessage[]): UTipsController;
/**
* 从消息列表中按照一定概率随机获取消息
* @summary 随机获取消息
* @return {string} 消息文本
*/
getRandomMessage(): string;
/**
* 清除显示定时器 id, 以及隐藏定时器 id
* @summary 清除时间句柄
* @private
*/
protected _clearTime(): void;
}
/**
* @class
* @summary live2d 属性
* @classdesc 分离出来的 ULive2dController 的属性
* @memberof module:controller
* @alias ULive2dProperty
*/
declare abstract class ULive2dProperty {
/**
* PIXI.Application 实例
* @summary app 实例
* @protected
* @type {TApplication}
*/
protected _app: TApplication;
/**
* getter: Application 实例
* @summary app 实例
* @type {TApplication}
* @readonly
*/
get app(): TApplication;
/**
* Liv