@doki-land/live2d-core 0.0.23 → 0.0.25
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 +13 -13
- package/dist/index.d.ts +12 -10
- package/package.json +1 -1
- package/src/events.ts +10 -10
- package/src/index.ts +4 -4
- package/src/session.ts +3 -2
package/README.md
CHANGED
|
@@ -41,11 +41,11 @@ The package exposes types such as:
|
|
|
41
41
|
|
|
42
42
|
```ts
|
|
43
43
|
import type {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
AssetResolver,
|
|
45
|
+
FrameSnapshot,
|
|
46
|
+
Live2dSession,
|
|
47
|
+
ModelSettings,
|
|
48
|
+
ModelSource,
|
|
49
49
|
} from "@doki-land/live2d-core";
|
|
50
50
|
```
|
|
51
51
|
|
|
@@ -54,14 +54,14 @@ behavior:
|
|
|
54
54
|
|
|
55
55
|
```ts
|
|
56
56
|
const resolver: AssetResolver = {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
57
|
+
async fetchJson(url) {
|
|
58
|
+
const response = await fetch(url);
|
|
59
|
+
return response.json();
|
|
60
|
+
},
|
|
61
|
+
async fetchBytes(url) {
|
|
62
|
+
const response = await fetch(url);
|
|
63
|
+
return response.arrayBuffer();
|
|
64
|
+
},
|
|
65
65
|
};
|
|
66
66
|
```
|
|
67
67
|
|
package/dist/index.d.ts
CHANGED
|
@@ -66,7 +66,7 @@ interface FrameProfile {
|
|
|
66
66
|
readonly indexCount: number;
|
|
67
67
|
}
|
|
68
68
|
/** Minimal event bus used by sessions and loaders. */
|
|
69
|
-
type
|
|
69
|
+
type Live2dEventMap = {
|
|
70
70
|
ready: {
|
|
71
71
|
modelId: string;
|
|
72
72
|
};
|
|
@@ -96,13 +96,13 @@ type Live2DEventMap = {
|
|
|
96
96
|
generation: number;
|
|
97
97
|
};
|
|
98
98
|
};
|
|
99
|
-
type
|
|
100
|
-
type
|
|
99
|
+
type Live2dEventName = keyof Live2dEventMap;
|
|
100
|
+
type Live2dListener<K extends Live2dEventName> = (payload: Live2dEventMap[K]) => void;
|
|
101
101
|
declare class EventEmitter {
|
|
102
102
|
#private;
|
|
103
|
-
on<K extends
|
|
104
|
-
off<K extends
|
|
105
|
-
emit<K extends
|
|
103
|
+
on<K extends Live2dEventName>(event: K, listener: Live2dListener<K>): () => void;
|
|
104
|
+
off<K extends Live2dEventName>(event: K, listener: Live2dListener<K>): void;
|
|
105
|
+
emit<K extends Live2dEventName>(event: K, payload: Live2dEventMap[K]): void;
|
|
106
106
|
clear(): void;
|
|
107
107
|
}
|
|
108
108
|
|
|
@@ -248,19 +248,21 @@ interface ModelInstance {
|
|
|
248
248
|
}
|
|
249
249
|
|
|
250
250
|
/** High-level runtime session for one mounted surface. */
|
|
251
|
-
interface
|
|
251
|
+
interface Live2dSession {
|
|
252
252
|
readonly events: EventEmitter;
|
|
253
253
|
readonly model: InternalModel | null;
|
|
254
254
|
readonly state: SessionState;
|
|
255
255
|
mount(canvas: HTMLCanvasElement): void;
|
|
256
|
-
loadModel(source: ModelSource, resolver?: AssetResolver
|
|
256
|
+
loadModel(source: ModelSource, resolver?: AssetResolver, options?: {
|
|
257
|
+
signal?: AbortSignal;
|
|
258
|
+
}): Promise<InternalModel>;
|
|
257
259
|
/** Latest CPU frame after update, or null if no model. */
|
|
258
260
|
captureFrame(): FrameSnapshot | null;
|
|
259
261
|
update(deltaTimeSeconds: number): void;
|
|
260
262
|
hitTest(x: number, y: number): string | null;
|
|
261
263
|
destroy(): void;
|
|
262
264
|
}
|
|
263
|
-
declare function createSessionStub():
|
|
265
|
+
declare function createSessionStub(): Live2dSession;
|
|
264
266
|
|
|
265
267
|
/** Normalized stage placement for one actor (0,0) top-left → (1,1) bottom-right. */
|
|
266
268
|
interface ActorTransform {
|
|
@@ -417,4 +419,4 @@ interface Live2dStage {
|
|
|
417
419
|
|
|
418
420
|
declare const LIVE2D_CORE_VERSION: "0.0.0";
|
|
419
421
|
|
|
420
|
-
export { type ActorHit, type ActorInstance, type ActorTransform, type AssetKey, type AssetResolver, type CreateActorOptions, type CreateLive2dStageOptions, DEFAULT_ACTOR_TRANSFORM, type DrawableProgram, EventEmitter, type ExpressionDefinition, FrameBlendMode, type FrameDrawable, type FrameProfile, type FrameSnapshot, type HitAreaDefinition, type InternalModel, LIVE2D_CORE_VERSION, type
|
|
422
|
+
export { type ActorHit, type ActorInstance, type ActorTransform, type AssetKey, type AssetResolver, type CreateActorOptions, type CreateLive2dStageOptions, DEFAULT_ACTOR_TRANSFORM, type DrawableProgram, EventEmitter, type ExpressionDefinition, FrameBlendMode, type FrameDrawable, type FrameProfile, type FrameSnapshot, type HitAreaDefinition, type InternalModel, LIVE2D_CORE_VERSION, type Live2dActor, type Live2dEventMap, type Live2dEventName, type Live2dListener, type Live2dSession, type Live2dStage, type Live2dStageAssets, type LoadProgress, type LoadProgressStage, type ModelAsset, type ModelFormat, type ModelInstance, type ModelProgram, type ModelSettings, type ModelSource, type MotionDefinition, type ParameterProgram, type PlayMotionActorOptions, type PointerTrackingMode, type PointerTrackingPolicy, type SessionPhase, type SessionState, type StagePointerEvent, type StageUpdateMode, createSessionStub, detectModelSettingsFormat, modelSourceUrl };
|
package/package.json
CHANGED
package/src/events.ts
CHANGED
|
@@ -37,7 +37,7 @@ export interface FrameProfile {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
/** Minimal event bus used by sessions and loaders. */
|
|
40
|
-
export type
|
|
40
|
+
export type Live2dEventMap = {
|
|
41
41
|
ready: { modelId: string };
|
|
42
42
|
error: { error: unknown };
|
|
43
43
|
progress: LoadProgress;
|
|
@@ -49,18 +49,18 @@ export type Live2DEventMap = {
|
|
|
49
49
|
phase: { phase: string; generation: number };
|
|
50
50
|
};
|
|
51
51
|
|
|
52
|
-
export type
|
|
52
|
+
export type Live2dEventName = keyof Live2dEventMap;
|
|
53
53
|
|
|
54
|
-
export type
|
|
55
|
-
payload:
|
|
54
|
+
export type Live2dListener<K extends Live2dEventName> = (
|
|
55
|
+
payload: Live2dEventMap[K],
|
|
56
56
|
) => void;
|
|
57
57
|
|
|
58
58
|
export class EventEmitter {
|
|
59
59
|
#listeners = new Map<string, Set<(payload: unknown) => void>>();
|
|
60
60
|
|
|
61
|
-
on<K extends
|
|
61
|
+
on<K extends Live2dEventName>(
|
|
62
62
|
event: K,
|
|
63
|
-
listener:
|
|
63
|
+
listener: Live2dListener<K>,
|
|
64
64
|
): () => void {
|
|
65
65
|
const set = this.#listeners.get(event) ?? new Set();
|
|
66
66
|
set.add(listener as (payload: unknown) => void);
|
|
@@ -68,18 +68,18 @@ export class EventEmitter {
|
|
|
68
68
|
return () => this.off(event, listener);
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
off<K extends
|
|
71
|
+
off<K extends Live2dEventName>(
|
|
72
72
|
event: K,
|
|
73
|
-
listener:
|
|
73
|
+
listener: Live2dListener<K>,
|
|
74
74
|
): void {
|
|
75
75
|
this.#listeners
|
|
76
76
|
.get(event)
|
|
77
77
|
?.delete(listener as (payload: unknown) => void);
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
emit<K extends
|
|
80
|
+
emit<K extends Live2dEventName>(
|
|
81
81
|
event: K,
|
|
82
|
-
payload:
|
|
82
|
+
payload: Live2dEventMap[K],
|
|
83
83
|
): void {
|
|
84
84
|
for (const listener of this.#listeners.get(event) ?? []) {
|
|
85
85
|
listener(payload);
|
package/src/index.ts
CHANGED
|
@@ -19,9 +19,9 @@ export { modelSourceUrl } from "./contracts.js";
|
|
|
19
19
|
export {
|
|
20
20
|
EventEmitter,
|
|
21
21
|
type FrameProfile,
|
|
22
|
-
type
|
|
23
|
-
type
|
|
24
|
-
type
|
|
22
|
+
type Live2dEventMap,
|
|
23
|
+
type Live2dEventName,
|
|
24
|
+
type Live2dListener,
|
|
25
25
|
type LoadProgress,
|
|
26
26
|
type LoadProgressStage,
|
|
27
27
|
} from "./events.js";
|
|
@@ -52,7 +52,7 @@ export type {
|
|
|
52
52
|
} from "./program.js";
|
|
53
53
|
export {
|
|
54
54
|
createSessionStub,
|
|
55
|
-
type
|
|
55
|
+
type Live2dSession,
|
|
56
56
|
} from "./session.js";
|
|
57
57
|
export type {
|
|
58
58
|
ActorHit,
|
package/src/session.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { FrameSnapshot } from "./frame.js";
|
|
|
4
4
|
import type { InternalModel } from "./model/model.js";
|
|
5
5
|
|
|
6
6
|
/** High-level runtime session for one mounted surface. */
|
|
7
|
-
export interface
|
|
7
|
+
export interface Live2dSession {
|
|
8
8
|
readonly events: EventEmitter;
|
|
9
9
|
readonly model: InternalModel | null;
|
|
10
10
|
readonly state: SessionState;
|
|
@@ -14,6 +14,7 @@ export interface Live2DSession {
|
|
|
14
14
|
loadModel(
|
|
15
15
|
source: ModelSource,
|
|
16
16
|
resolver?: AssetResolver,
|
|
17
|
+
options?: { signal?: AbortSignal },
|
|
17
18
|
): Promise<InternalModel>;
|
|
18
19
|
|
|
19
20
|
/** Latest CPU frame after update, or null if no model. */
|
|
@@ -26,7 +27,7 @@ export interface Live2DSession {
|
|
|
26
27
|
destroy(): void;
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
export function createSessionStub():
|
|
30
|
+
export function createSessionStub(): Live2dSession {
|
|
30
31
|
let canvas: HTMLCanvasElement | null = null;
|
|
31
32
|
let model: InternalModel | null = null;
|
|
32
33
|
const events = new EventEmitter();
|