@seayoo-web/pixi-live2d 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@seayoo-web/pixi-live2d",
3
+ "description": "pixi-live2d viewer",
4
+ "version": "0.0.1",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "source": "./index.ts",
9
+ "types": "./types/index.d.ts",
10
+ "sideEffects": false,
11
+ "files": [
12
+ "dist",
13
+ "types",
14
+ "docs",
15
+ "README.md"
16
+ ],
17
+ "publishConfig": {
18
+ "access": "public"
19
+ },
20
+ "engines": {
21
+ "node": ">=22"
22
+ },
23
+ "keywords": [
24
+ "pixi-live2d"
25
+ ],
26
+ "author": "web@seayoo.com",
27
+ "license": "MIT",
28
+ "dependencies": {
29
+ "@pixi/constants": "6.5.2",
30
+ "@pixi/core": "6.5.2",
31
+ "@pixi/display": "6.5.2",
32
+ "@pixi/extensions": "6.5.2",
33
+ "@pixi/loaders": "6.5.2",
34
+ "@pixi/math": "6.5.2",
35
+ "@pixi/runner": "6.5.2",
36
+ "@pixi/settings": "6.5.2",
37
+ "@pixi/sprite": "6.5.2",
38
+ "@pixi/ticker": "6.5.2",
39
+ "@pixi/utils": "6.5.2",
40
+ "pixi-live2d-display": "^0.4.0",
41
+ "pixi.js": "6.5.2"
42
+ },
43
+ "devDependencies": {
44
+ "@types/node": "^22.13.1",
45
+ "@seayoo-web/tsconfig": "^1.0.6",
46
+ "@seayoo-web/utils": "^4.4.1"
47
+ },
48
+ "scripts": {
49
+ "build": "vite build && tsc --build --force --emitDeclarationOnly",
50
+ "type-check": "tsc --noEmit",
51
+ "lint": "eslint ./**/*.ts",
52
+ "lint:fix": "eslint ./**/*.ts --fix",
53
+ "prepublish": "pnpm lint:fix && pnpm build",
54
+ "test": "vitest --dom",
55
+ "coverage": "vitest run --coverage"
56
+ }
57
+ }
@@ -0,0 +1,85 @@
1
+ import { InternalModel, Live2DModel } from "pixi-live2d-display/cubism4";
2
+ import * as PIXI from "pixi.js";
3
+ declare global {
4
+ interface Window {
5
+ PIXI?: typeof PIXI;
6
+ }
7
+ }
8
+ /** Live2D 查看器配置项 */
9
+ export interface Live2DViewerOptions {
10
+ /** 模型配置文件 (.json) 的路径 */
11
+ modelPath: string;
12
+ /** 是否监听窗口 resize 事件并自动调整模型大小,默认为 true */
13
+ autoResize?: boolean;
14
+ /** 模型初始缩放比例 */
15
+ scale?: number;
16
+ /** 模型初始 X 轴偏移 */
17
+ x?: number;
18
+ /** 模型初始 Y 轴偏移 */
19
+ y?: number;
20
+ /** 设计稿宽度,用于适配计算(默认 1920) */
21
+ designWidth?: number;
22
+ /** 设计稿高度,用于适配计算(默认 1080) */
23
+ designHeight?: number;
24
+ /** Cubism Core 库的加载 URL */
25
+ cubismCoreUrl?: string;
26
+ /** 模型加载完成后的回调函数 */
27
+ onModelLoaded?: (model: Live2DModel<InternalModel>) => void;
28
+ /** 模型加载失败的回调函数 */
29
+ onModelError?: (error: Error) => void;
30
+ }
31
+ export declare class Live2DViewer {
32
+ /** 引擎加载状态 Promise,用于确保全局只加载一次 Core 库 */
33
+ private static coreLoadingPromise;
34
+ /**
35
+ * 加载 Live2D Cubism Core 引擎
36
+ * @param url - Core 库的 URL 地址
37
+ */
38
+ static loadCubismCore(url?: string): Promise<void>;
39
+ /** PIXI 应用实例 */
40
+ app: PIXI.Application;
41
+ /** Live2D 模型实例 */
42
+ model: Live2DModel<InternalModel> | null;
43
+ /** 配置项副本 */
44
+ private options;
45
+ /**
46
+ * 创建 Live2D 查看器实例
47
+ * @param canvas - 用于渲染的 Canvas 元素或其 ID
48
+ * @param options - 配置项
49
+ */
50
+ constructor(canvas: HTMLCanvasElement | string, options: Live2DViewerOptions);
51
+ /** 初始化模型 */
52
+ private init;
53
+ /** 设置点击交互 */
54
+ private setupInteraction;
55
+ /** 窗口大小改变的处理函数 */
56
+ private handleResize;
57
+ /** 重新计算布局和缩放 */
58
+ resize(): void;
59
+ /**
60
+ * 设置模型缩放比例并刷新布局
61
+ * @param scale - 缩放比例
62
+ */
63
+ setScale(scale: number): void;
64
+ /**
65
+ * 设置模型坐标并刷新布局
66
+ * @param x - X 轴偏移
67
+ * @param y - Y 轴偏移
68
+ */
69
+ setXY(x: number, y: number): void;
70
+ /**
71
+ * 播放指定分组的动作
72
+ * @param group - 动作分组名称
73
+ * @param no - 动作编号
74
+ */
75
+ startMotion(group: string, no: number): Promise<boolean> | undefined;
76
+ /**
77
+ * 播放指定表情
78
+ * @param name - 表情名称或索引
79
+ */
80
+ expression(name: string | number): Promise<boolean> | undefined;
81
+ /** 等待当前动作播放结束 */
82
+ waitForMotionFinish(): Promise<boolean>;
83
+ /** 销毁实例,清理资源和监听器 */
84
+ destroy(): void;
85
+ }