@doki-land/live2d 0.0.12 → 0.0.14

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/README.md CHANGED
@@ -1,3 +1,3 @@
1
1
  # @doki-land/live2d
2
2
 
3
- live2d.ts package 0.0.12.
3
+ live2d.ts package 0.0.14.
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import * as _doki_land_live2d_core from '@doki-land/live2d-core';
2
- import { LoadProgress, InternalModel, ModelSource, AssetResolver, Live2dActor, CreateActorOptions, ActorTransform, ActorHit, CreateLive2dStageOptions, Live2dStage, PointerTrackingPolicy, StagePointerEvent, Live2DSession } from '@doki-land/live2d-core';
3
- export { ActorHit, ActorTransform, AssetResolver, CreateActorOptions, CreateLive2dStageOptions, DEFAULT_ACTOR_TRANSFORM, EventEmitter, FrameProfile, FrameSnapshot, InternalModel, Live2DSession, Live2dActor, Live2dStage, LoadProgress, LoadProgressStage, ModelFormat, ModelInstance, ModelProgram, ModelSettings, ModelSource, PointerTrackingMode, PointerTrackingPolicy, SessionPhase, SessionState, StagePointerEvent, StageUpdateMode } from '@doki-land/live2d-core';
2
+ import { LoadProgress, InternalModel, ModelSource, AssetResolver, Live2dActor, CreateActorOptions, ActorTransform, PlayMotionActorOptions, ActorHit, CreateLive2dStageOptions, Live2dStage, PointerTrackingPolicy, StagePointerEvent, Live2DSession } from '@doki-land/live2d-core';
3
+ export { ActorHit, ActorTransform, AssetResolver, CreateActorOptions, CreateLive2dStageOptions, DEFAULT_ACTOR_TRANSFORM, EventEmitter, FrameProfile, FrameSnapshot, InternalModel, Live2DSession, Live2dActor, Live2dStage, LoadProgress, LoadProgressStage, ModelFormat, ModelInstance, ModelProgram, ModelSettings, ModelSource, PlayMotionActorOptions, PointerTrackingMode, PointerTrackingPolicy, SessionPhase, SessionState, StagePointerEvent, StageUpdateMode } from '@doki-land/live2d-core';
4
4
  export { DEFAULT_NPM_CDN, resolveModelSourceUrl, resolveNpmSpecifier } from '@doki-land/live2d-loader';
5
+ import * as _doki_land_live2d_renderer from '@doki-land/live2d-renderer';
5
6
  import { ModelBackend, Renderer, ParameterBinding, DrawableMesh, RendererKind } from '@doki-land/live2d-renderer';
6
7
  export { ModelBackend, ParameterBinding, Renderer, RendererKind, createCanvas2DRenderer, createMoc2Backend, createMoc3Backend, createQuadProgram, createRenderer, createWebGl2Renderer, createWebGpuRenderer, decodeMoc3, evaluateFrame, fingerprintSnapshot, parseCpuProgram, serializeCpuProgram } from '@doki-land/live2d-renderer';
7
8
 
@@ -225,6 +226,20 @@ declare class Live2dActorImpl implements Live2dActor {
225
226
  setTransform(patch: Partial<ActorTransform>): void;
226
227
  load(source: Parameters<Live2dActor["load"]>[0], resolver?: Parameters<Live2dActor["load"]>[1]): Promise<InternalModel>;
227
228
  setParameter(id: string, value: number): void;
229
+ listParameters(): readonly _doki_land_live2d_renderer.ParameterBinding[];
230
+ listMotionGroups(): Record<string, readonly _doki_land_live2d_core.MotionDefinition[]>;
231
+ playMotion(group: string, index?: number, options?: PlayMotionActorOptions): Promise<boolean>;
232
+ stopMotion(opts?: {
233
+ fade?: boolean;
234
+ slot?: string;
235
+ }): void;
236
+ listPlayingMotions(): readonly {
237
+ slot: string;
238
+ group: string;
239
+ index: number;
240
+ time: number;
241
+ priority: number;
242
+ }[];
228
243
  lookAt(stageX: number, stageY: number): void;
229
244
  /** Internal: evaluate motion/physics and cache drawables for render. */
230
245
  update(deltaTimeSeconds: number): DrawableMesh[] | null;
@@ -249,6 +264,8 @@ declare class Live2dStageImpl implements Live2dStage {
249
264
  get renderer(): Renderer;
250
265
  mount(canvas: HTMLCanvasElement): Promise<void>;
251
266
  createActor(options?: CreateActorOptions): Live2dActor;
267
+ getActor(id: string): Live2dActor | null;
268
+ resize(width?: number, height?: number): void;
252
269
  removeActor(actorOrId: Live2dActor | string): void;
253
270
  defineLayers(layers: readonly string[]): void;
254
271
  update(deltaTimeSeconds: number): void;
package/dist/index.js CHANGED
@@ -1091,6 +1091,25 @@ var Live2dActorImpl = class {
1091
1091
  setParameter(id, value) {
1092
1092
  this.#slot.setParameter(id, value);
1093
1093
  }
1094
+ listParameters() {
1095
+ return this.#slot.listParameters();
1096
+ }
1097
+ listMotionGroups() {
1098
+ return this.#slot.listMotionGroups();
1099
+ }
1100
+ playMotion(group, index, options) {
1101
+ return this.#slot.playMotion(
1102
+ group,
1103
+ index,
1104
+ options
1105
+ );
1106
+ }
1107
+ stopMotion(opts) {
1108
+ this.#slot.stopMotion(opts);
1109
+ }
1110
+ listPlayingMotions() {
1111
+ return this.#slot.listPlayingMotions();
1112
+ }
1094
1113
  lookAt(stageX, stageY) {
1095
1114
  const { dragX, dragY } = stageFocusDrag(
1096
1115
  stageX,
@@ -1227,19 +1246,19 @@ function createSingleActorFacade(stage, actor, backends) {
1227
1246
  return hit.area;
1228
1247
  },
1229
1248
  listParameters() {
1230
- return actor.slot.listParameters();
1249
+ return actor.listParameters();
1231
1250
  },
1232
1251
  listMotionGroups() {
1233
- return actor.slot.listMotionGroups();
1252
+ return actor.listMotionGroups();
1234
1253
  },
1235
1254
  playMotion(group, index, options) {
1236
- return actor.slot.playMotion(group, index, options);
1255
+ return actor.playMotion(group, index, options);
1237
1256
  },
1238
1257
  stopMotion(opts) {
1239
- actor.slot.stopMotion(opts);
1258
+ actor.stopMotion(opts);
1240
1259
  },
1241
1260
  listPlayingMotions() {
1242
- return actor.slot.listPlayingMotions();
1261
+ return actor.listPlayingMotions();
1243
1262
  },
1244
1263
  async capturePng(opts = {}) {
1245
1264
  if (!canvas) {
@@ -1392,6 +1411,19 @@ var Live2dStageImpl = class {
1392
1411
  }
1393
1412
  return actor;
1394
1413
  }
1414
+ getActor(id) {
1415
+ return this.#actors.get(id) ?? null;
1416
+ }
1417
+ resize(width, height) {
1418
+ if (!this.#canvas || this.#destroyed) return;
1419
+ const cssW = width ?? this.#canvas.clientWidth;
1420
+ const cssH = height ?? this.#canvas.clientHeight;
1421
+ if (cssW <= 0 || cssH <= 0) return;
1422
+ const dpr = typeof globalThis.devicePixelRatio === "number" ? globalThis.devicePixelRatio : 1;
1423
+ this.#canvas.width = Math.round(cssW * dpr);
1424
+ this.#canvas.height = Math.round(cssH * dpr);
1425
+ this.#renderer.resize(cssW, cssH);
1426
+ }
1395
1427
  removeActor(actorOrId) {
1396
1428
  const id = typeof actorOrId === "string" ? actorOrId : actorOrId.id;
1397
1429
  const actor = this.#actors.get(id);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@doki-land/live2d",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
4
  "description": "Live2D TypeScript library — public facade for Doki Land",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -57,9 +57,9 @@
57
57
  "test": "vitest run --passWithNoTests"
58
58
  },
59
59
  "dependencies": {
60
- "@doki-land/live2d-core": "0.0.12",
61
- "@doki-land/live2d-loader": "0.0.12",
62
- "@doki-land/live2d-renderer": "0.0.12"
60
+ "@doki-land/live2d-core": "0.0.14",
61
+ "@doki-land/live2d-loader": "0.0.14",
62
+ "@doki-land/live2d-renderer": "0.0.14"
63
63
  },
64
64
  "sideEffects": false
65
65
  }
package/src/index.ts CHANGED
@@ -25,6 +25,7 @@ export type {
25
25
  ModelProgram,
26
26
  ModelSettings,
27
27
  ModelSource,
28
+ PlayMotionActorOptions,
28
29
  PointerTrackingMode,
29
30
  PointerTrackingPolicy,
30
31
  SessionPhase,
@@ -4,6 +4,7 @@ import type {
4
4
  CreateActorOptions,
5
5
  InternalModel,
6
6
  Live2dActor,
7
+ PlayMotionActorOptions,
7
8
  } from "@doki-land/live2d-core";
8
9
  import type {
9
10
  DrawableMesh,
@@ -11,6 +12,7 @@ import type {
11
12
  Renderer,
12
13
  } from "@doki-land/live2d-renderer";
13
14
  import { focusParameterUpdates } from "../focus.js";
15
+ import type { PlayMotionOptions } from "../motion/index.js";
14
16
  import { ActorModelSlot } from "./actor-model-slot.js";
15
17
  import {
16
18
  resolveActorTransform,
@@ -117,6 +119,34 @@ export class Live2dActorImpl implements Live2dActor {
117
119
  this.#slot.setParameter(id, value);
118
120
  }
119
121
 
122
+ listParameters() {
123
+ return this.#slot.listParameters();
124
+ }
125
+
126
+ listMotionGroups() {
127
+ return this.#slot.listMotionGroups();
128
+ }
129
+
130
+ playMotion(
131
+ group: string,
132
+ index?: number,
133
+ options?: PlayMotionActorOptions,
134
+ ) {
135
+ return this.#slot.playMotion(
136
+ group,
137
+ index,
138
+ options as PlayMotionOptions | undefined,
139
+ );
140
+ }
141
+
142
+ stopMotion(opts?: { fade?: boolean; slot?: string }) {
143
+ this.#slot.stopMotion(opts);
144
+ }
145
+
146
+ listPlayingMotions() {
147
+ return this.#slot.listPlayingMotions();
148
+ }
149
+
120
150
  lookAt(stageX: number, stageY: number): void {
121
151
  const { dragX, dragY } = stageFocusDrag(
122
152
  stageX,
@@ -139,19 +139,19 @@ export function createSingleActorFacade(
139
139
  return hit.area;
140
140
  },
141
141
  listParameters() {
142
- return actor.slot.listParameters();
142
+ return actor.listParameters();
143
143
  },
144
144
  listMotionGroups() {
145
- return actor.slot.listMotionGroups();
145
+ return actor.listMotionGroups();
146
146
  },
147
147
  playMotion(group, index, options) {
148
- return actor.slot.playMotion(group, index, options);
148
+ return actor.playMotion(group, index, options);
149
149
  },
150
150
  stopMotion(opts) {
151
- actor.slot.stopMotion(opts);
151
+ actor.stopMotion(opts);
152
152
  },
153
153
  listPlayingMotions() {
154
- return actor.slot.listPlayingMotions();
154
+ return actor.listPlayingMotions();
155
155
  },
156
156
  async capturePng(opts = {}) {
157
157
  if (!canvas) {
@@ -127,6 +127,24 @@ export class Live2dStageImpl implements Live2dStage {
127
127
  return actor;
128
128
  }
129
129
 
130
+ getActor(id: string): Live2dActor | null {
131
+ return this.#actors.get(id) ?? null;
132
+ }
133
+
134
+ resize(width?: number, height?: number): void {
135
+ if (!this.#canvas || this.#destroyed) return;
136
+ const cssW = width ?? this.#canvas.clientWidth;
137
+ const cssH = height ?? this.#canvas.clientHeight;
138
+ if (cssW <= 0 || cssH <= 0) return;
139
+ const dpr =
140
+ typeof globalThis.devicePixelRatio === "number"
141
+ ? globalThis.devicePixelRatio
142
+ : 1;
143
+ this.#canvas.width = Math.round(cssW * dpr);
144
+ this.#canvas.height = Math.round(cssH * dpr);
145
+ this.#renderer.resize(cssW, cssH);
146
+ }
147
+
130
148
  removeActor(actorOrId: Live2dActor | string): void {
131
149
  const id = typeof actorOrId === "string" ? actorOrId : actorOrId.id;
132
150
  const actor = this.#actors.get(id);