@seayoo-web/pixi-live2d 0.0.2 → 0.0.4

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/dist/index.js CHANGED
@@ -21673,7 +21673,7 @@ class Th {
21673
21673
  }
21674
21674
  /** 设置点击交互 */
21675
21675
  setupInteraction() {
21676
- this.model && (this.model.interactive = !0, this.model.on("pointertap", () => {
21676
+ this.model && (this.model.interactive = this.options.enableMouseTracking !== !1, this.model.on("pointertap", () => {
21677
21677
  this.model?.motion("TapBody");
21678
21678
  }));
21679
21679
  }
@@ -21707,9 +21707,23 @@ class Th {
21707
21707
  * @param group - 动作分组名称
21708
21708
  * @param no - 动作编号
21709
21709
  * @param priority - 动作优先级,默认值为 1
21710
+ * @param startTime - 动作开始时间(秒),默认值为 0
21711
+ * @returns Promise,动作开始播放后 resolve
21710
21712
  */
21711
- startMotion(e, r, i = 1) {
21712
- return this.model?.motion(e, r, i);
21713
+ async startMotion(e, r, i = 1, n = 0) {
21714
+ if (!this.model) return !1;
21715
+ const s = await this.model.motion(e, r, i);
21716
+ if (s && n > 0) {
21717
+ const a = this.model.internalModel.motionManager.queueManager;
21718
+ if (a) {
21719
+ const o = a._motions;
21720
+ if (o && o.length > 0) {
21721
+ const h = o[o.length - 1];
21722
+ h && h.isAvailable() && h._motion?.setOffsetTime(n);
21723
+ }
21724
+ }
21725
+ }
21726
+ return s;
21713
21727
  }
21714
21728
  /**
21715
21729
  * 播放指定表情
@@ -21729,6 +21743,30 @@ class Th {
21729
21743
  this.model.internalModel.motionManager.on("motionFinish", r);
21730
21744
  });
21731
21745
  }
21746
+ /**
21747
+ * 启用动作循环播放模式
21748
+ * 从第 startTime 秒开始循环播放,直到动画结束
21749
+ * @param startTime - 循环开始时间(秒),默认为 2 秒
21750
+ * @returns 停止循环的函数
21751
+ */
21752
+ loop(e = 2) {
21753
+ if (!this.model)
21754
+ return () => {
21755
+ };
21756
+ let r = !0;
21757
+ const i = this.model.internalModel.motionManager, n = () => {
21758
+ if (!r || !this.model) return;
21759
+ const a = i.queueManager;
21760
+ if (!a) return;
21761
+ const o = a._motions;
21762
+ if (!(!o || o.length === 0))
21763
+ for (const h of o)
21764
+ h && h.isAvailable() && !h.isFinished() && h.getStateTime() >= e && h.setState(e, h.getStateWeight());
21765
+ }, s = this.app.ticker;
21766
+ return s.add(n), () => {
21767
+ r = !1, s.remove(n);
21768
+ };
21769
+ }
21732
21770
  /** 销毁实例,清理资源和监听器 */
21733
21771
  destroy() {
21734
21772
  this.options.autoResize !== !1 && window.removeEventListener("resize", this.handleResize), this.app.destroy(!0);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@seayoo-web/pixi-live2d",
3
3
  "description": "pixi-live2d viewer",
4
- "version": "0.0.2",
4
+ "version": "0.0.4",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",
@@ -20,6 +20,15 @@
20
20
  "engines": {
21
21
  "node": ">=22"
22
22
  },
23
+ "scripts": {
24
+ "build": "vite build && tsc --build --force --emitDeclarationOnly",
25
+ "type-check": "tsc --noEmit",
26
+ "lint": "eslint ./**/*.ts",
27
+ "lint:fix": "eslint ./**/*.ts --fix",
28
+ "prepublish": "pnpm lint:fix && pnpm build",
29
+ "test": "vitest --dom",
30
+ "coverage": "vitest run --coverage"
31
+ },
23
32
  "keywords": [
24
33
  "pixi-live2d"
25
34
  ],
@@ -41,17 +50,8 @@
41
50
  "pixi.js": "6.5.2"
42
51
  },
43
52
  "devDependencies": {
44
- "@types/node": "^22.13.1",
45
- "@seayoo-web/utils": "^4.4.1",
46
- "@seayoo-web/tsconfig": "^1.0.6"
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"
53
+ "@seayoo-web/tsconfig": "workspace:^",
54
+ "@seayoo-web/utils": "workspace:^",
55
+ "@types/node": "^22.13.1"
56
56
  }
57
- }
57
+ }
package/types/index.d.ts CHANGED
@@ -23,12 +23,14 @@ export interface Live2DViewerOptions {
23
23
  designHeight?: number;
24
24
  /** Cubism Core 库的加载 URL */
25
25
  cubismCoreUrl?: string;
26
+ /** 是否响应鼠标/触摸移动进行跟随动画,默认为 true */
27
+ enableMouseTracking?: boolean;
26
28
  /** 模型加载完成后的回调函数 */
27
29
  onModelLoaded?: (model: Live2DModel<InternalModel>) => void;
28
30
  /** 模型加载失败的回调函数 */
29
31
  onModelError?: (error: Error) => void;
30
32
  }
31
- export { MotionPriority };
33
+ export { MotionPriority } from "pixi-live2d-display/cubism4";
32
34
  export declare class Live2DViewer {
33
35
  /** 引擎加载状态 Promise,用于确保全局只加载一次 Core 库 */
34
36
  private static coreLoadingPromise;
@@ -73,8 +75,10 @@ export declare class Live2DViewer {
73
75
  * @param group - 动作分组名称
74
76
  * @param no - 动作编号
75
77
  * @param priority - 动作优先级,默认值为 1
78
+ * @param startTime - 动作开始时间(秒),默认值为 0
79
+ * @returns Promise,动作开始播放后 resolve
76
80
  */
77
- startMotion(group: string, no: number, priority?: MotionPriority): Promise<boolean> | undefined;
81
+ startMotion(group: string, no: number, priority?: MotionPriority, startTime?: number): Promise<boolean>;
78
82
  /**
79
83
  * 播放指定表情
80
84
  * @param name - 表情名称或索引
@@ -82,6 +86,13 @@ export declare class Live2DViewer {
82
86
  expression(name: string | number): Promise<boolean> | undefined;
83
87
  /** 等待当前动作播放结束 */
84
88
  waitForMotionFinish(): Promise<boolean>;
89
+ /**
90
+ * 启用动作循环播放模式
91
+ * 从第 startTime 秒开始循环播放,直到动画结束
92
+ * @param startTime - 循环开始时间(秒),默认为 2 秒
93
+ * @returns 停止循环的函数
94
+ */
95
+ loop(startTime?: number): () => void;
85
96
  /** 销毁实例,清理资源和监听器 */
86
97
  destroy(): void;
87
98
  }