@doki-land/live2d-core 0.0.11 → 0.0.13
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 +1 -1
- package/dist/index.d.ts +94 -1
- package/dist/index.js +10 -0
- package/package.json +1 -1
- package/src/index.ts +13 -0
- package/src/stage.ts +147 -0
package/README.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -244,10 +244,103 @@ interface Live2DSession {
|
|
|
244
244
|
}
|
|
245
245
|
declare function createSessionStub(): Live2DSession;
|
|
246
246
|
|
|
247
|
+
/** Normalized stage placement for one actor (0,0) top-left → (1,1) bottom-right. */
|
|
248
|
+
interface ActorTransform {
|
|
249
|
+
/** Anchor point X in stage space. */
|
|
250
|
+
x: number;
|
|
251
|
+
/** Anchor point Y in stage space. */
|
|
252
|
+
y: number;
|
|
253
|
+
/** Uniform scale; ignored when `scaleX` / `scaleY` are set. */
|
|
254
|
+
scale?: number;
|
|
255
|
+
scaleX?: number;
|
|
256
|
+
scaleY?: number;
|
|
257
|
+
/** Radians, counter-clockwise. */
|
|
258
|
+
rotation?: number;
|
|
259
|
+
/** Horizontal anchor within the model bounds (0 = left, 1 = right). */
|
|
260
|
+
anchorX?: number;
|
|
261
|
+
/** Vertical anchor within the model bounds (0 = top, 1 = bottom in stage space). */
|
|
262
|
+
anchorY?: number;
|
|
263
|
+
}
|
|
264
|
+
declare const DEFAULT_ACTOR_TRANSFORM: Readonly<ActorTransform>;
|
|
265
|
+
type PointerTrackingMode = "all" | "focused" | "hovered" | "nearest" | "none" | "custom";
|
|
266
|
+
interface PointerTrackingPolicy {
|
|
267
|
+
mode: PointerTrackingMode;
|
|
268
|
+
/** Used when `mode` is `custom`. */
|
|
269
|
+
targetActorId?: string;
|
|
270
|
+
}
|
|
271
|
+
interface CreateActorOptions {
|
|
272
|
+
id?: string;
|
|
273
|
+
transform?: Partial<ActorTransform>;
|
|
274
|
+
layer?: string;
|
|
275
|
+
order?: number;
|
|
276
|
+
visible?: boolean;
|
|
277
|
+
opacity?: number;
|
|
278
|
+
}
|
|
279
|
+
interface ActorHit {
|
|
280
|
+
readonly actor: Live2dActor;
|
|
281
|
+
readonly actorId: string;
|
|
282
|
+
readonly area: string;
|
|
283
|
+
readonly drawableIndex: number;
|
|
284
|
+
readonly stageX: number;
|
|
285
|
+
readonly stageY: number;
|
|
286
|
+
readonly localX: number;
|
|
287
|
+
readonly localY: number;
|
|
288
|
+
}
|
|
289
|
+
interface StagePointerEvent {
|
|
290
|
+
readonly actor: Live2dActor | null;
|
|
291
|
+
readonly actorId: string | null;
|
|
292
|
+
readonly area: string | null;
|
|
293
|
+
readonly stageX: number;
|
|
294
|
+
readonly stageY: number;
|
|
295
|
+
readonly clientX: number;
|
|
296
|
+
readonly clientY: number;
|
|
297
|
+
readonly hit: ActorHit | null;
|
|
298
|
+
}
|
|
299
|
+
type StageUpdateMode = "auto" | "manual";
|
|
300
|
+
interface CreateLive2dStageOptions {
|
|
301
|
+
updateMode?: StageUpdateMode;
|
|
302
|
+
}
|
|
303
|
+
/** Read-only actor surface exposed by the stage. */
|
|
304
|
+
interface Live2dActor {
|
|
305
|
+
readonly id: string;
|
|
306
|
+
readonly model: InternalModel | null;
|
|
307
|
+
readonly visible: boolean;
|
|
308
|
+
readonly opacity: number;
|
|
309
|
+
readonly layer: string;
|
|
310
|
+
readonly order: number;
|
|
311
|
+
readonly creationIndex: number;
|
|
312
|
+
getTransform(): ActorTransform;
|
|
313
|
+
setTransform(patch: Partial<ActorTransform>): void;
|
|
314
|
+
load(source: ModelSource, resolver?: AssetResolver): Promise<InternalModel>;
|
|
315
|
+
setParameter(id: string, value: number): void;
|
|
316
|
+
lookAt(stageX: number, stageY: number): void;
|
|
317
|
+
destroy(): void;
|
|
318
|
+
}
|
|
319
|
+
/** Multi-character stage owning one canvas surface and shared renderer. */
|
|
320
|
+
interface Live2dStage {
|
|
321
|
+
readonly actors: readonly Live2dActor[];
|
|
322
|
+
mount(canvas: HTMLCanvasElement): Promise<void>;
|
|
323
|
+
createActor(options?: CreateActorOptions): Live2dActor;
|
|
324
|
+
removeActor(actor: Live2dActor | string): void;
|
|
325
|
+
defineLayers(layers: readonly string[]): void;
|
|
326
|
+
update(deltaTimeSeconds: number): void;
|
|
327
|
+
render(): void;
|
|
328
|
+
start(): void;
|
|
329
|
+
pause(): void;
|
|
330
|
+
resume(): void;
|
|
331
|
+
stop(): void;
|
|
332
|
+
hitTest(stageX: number, stageY: number): ActorHit | null;
|
|
333
|
+
hitTestAll(stageX: number, stageY: number): readonly ActorHit[];
|
|
334
|
+
addEventListener(type: "pointerdown" | "pointermove" | "pointerup", listener: (event: StagePointerEvent) => void): void;
|
|
335
|
+
removeEventListener(type: "pointerdown" | "pointermove" | "pointerup", listener: (event: StagePointerEvent) => void): void;
|
|
336
|
+
destroy(): void;
|
|
337
|
+
pointerTracking: PointerTrackingPolicy;
|
|
338
|
+
}
|
|
339
|
+
|
|
247
340
|
/**
|
|
248
341
|
* `@doki-land/live2d-core` — types, events, session contracts.
|
|
249
342
|
*/
|
|
250
343
|
|
|
251
344
|
declare const LIVE2D_CORE_VERSION: "0.0.0";
|
|
252
345
|
|
|
253
|
-
export { type AssetKey, type AssetResolver, type DrawableProgram, EventEmitter, type ExpressionDefinition, FrameBlendMode, type FrameDrawable, type FrameProfile, type FrameSnapshot, type HitAreaDefinition, type InternalModel, LIVE2D_CORE_VERSION, type Live2DEventMap, type Live2DEventName, type Live2DListener, type Live2DSession, type LoadProgress, type LoadProgressStage, type ModelFormat, type ModelInstance, type ModelProgram, type ModelSettings, type ModelSource, type MotionDefinition, type ParameterProgram, type SessionPhase, type SessionState, createSessionStub, detectModelSettingsFormat, modelSourceUrl };
|
|
346
|
+
export { type ActorHit, 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 Live2DEventMap, type Live2DEventName, type Live2DListener, type Live2DSession, type Live2dActor, type Live2dStage, type LoadProgress, type LoadProgressStage, type ModelFormat, type ModelInstance, type ModelProgram, type ModelSettings, type ModelSource, type MotionDefinition, type ParameterProgram, type PointerTrackingMode, type PointerTrackingPolicy, type SessionPhase, type SessionState, type StagePointerEvent, type StageUpdateMode, createSessionStub, detectModelSettingsFormat, modelSourceUrl };
|
package/dist/index.js
CHANGED
|
@@ -109,9 +109,19 @@ function createSessionStub() {
|
|
|
109
109
|
};
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
+
// src/stage.ts
|
|
113
|
+
var DEFAULT_ACTOR_TRANSFORM = {
|
|
114
|
+
x: 0.5,
|
|
115
|
+
y: 1,
|
|
116
|
+
scale: 1,
|
|
117
|
+
anchorX: 0.5,
|
|
118
|
+
anchorY: 1
|
|
119
|
+
};
|
|
120
|
+
|
|
112
121
|
// src/index.ts
|
|
113
122
|
var LIVE2D_CORE_VERSION = "0.0.0";
|
|
114
123
|
export {
|
|
124
|
+
DEFAULT_ACTOR_TRANSFORM,
|
|
115
125
|
EventEmitter,
|
|
116
126
|
FrameBlendMode,
|
|
117
127
|
LIVE2D_CORE_VERSION,
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -43,5 +43,18 @@ export {
|
|
|
43
43
|
createSessionStub,
|
|
44
44
|
type Live2DSession,
|
|
45
45
|
} from "./session.js";
|
|
46
|
+
export type {
|
|
47
|
+
ActorHit,
|
|
48
|
+
ActorTransform,
|
|
49
|
+
CreateActorOptions,
|
|
50
|
+
CreateLive2dStageOptions,
|
|
51
|
+
Live2dActor,
|
|
52
|
+
Live2dStage,
|
|
53
|
+
PointerTrackingMode,
|
|
54
|
+
PointerTrackingPolicy,
|
|
55
|
+
StagePointerEvent,
|
|
56
|
+
StageUpdateMode,
|
|
57
|
+
} from "./stage.js";
|
|
58
|
+
export { DEFAULT_ACTOR_TRANSFORM } from "./stage.js";
|
|
46
59
|
|
|
47
60
|
export const LIVE2D_CORE_VERSION = "0.0.0" as const;
|
package/src/stage.ts
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import type { InternalModel } from "./model.js";
|
|
2
|
+
|
|
3
|
+
/** Normalized stage placement for one actor (0,0) top-left → (1,1) bottom-right. */
|
|
4
|
+
export interface ActorTransform {
|
|
5
|
+
/** Anchor point X in stage space. */
|
|
6
|
+
x: number;
|
|
7
|
+
/** Anchor point Y in stage space. */
|
|
8
|
+
y: number;
|
|
9
|
+
/** Uniform scale; ignored when `scaleX` / `scaleY` are set. */
|
|
10
|
+
scale?: number;
|
|
11
|
+
scaleX?: number;
|
|
12
|
+
scaleY?: number;
|
|
13
|
+
/** Radians, counter-clockwise. */
|
|
14
|
+
rotation?: number;
|
|
15
|
+
/** Horizontal anchor within the model bounds (0 = left, 1 = right). */
|
|
16
|
+
anchorX?: number;
|
|
17
|
+
/** Vertical anchor within the model bounds (0 = top, 1 = bottom in stage space). */
|
|
18
|
+
anchorY?: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const DEFAULT_ACTOR_TRANSFORM: Readonly<ActorTransform> = {
|
|
22
|
+
x: 0.5,
|
|
23
|
+
y: 1,
|
|
24
|
+
scale: 1,
|
|
25
|
+
anchorX: 0.5,
|
|
26
|
+
anchorY: 1,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export type PointerTrackingMode =
|
|
30
|
+
| "all"
|
|
31
|
+
| "focused"
|
|
32
|
+
| "hovered"
|
|
33
|
+
| "nearest"
|
|
34
|
+
| "none"
|
|
35
|
+
| "custom";
|
|
36
|
+
|
|
37
|
+
export interface PointerTrackingPolicy {
|
|
38
|
+
mode: PointerTrackingMode;
|
|
39
|
+
/** Used when `mode` is `custom`. */
|
|
40
|
+
targetActorId?: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface CreateActorOptions {
|
|
44
|
+
id?: string;
|
|
45
|
+
transform?: Partial<ActorTransform>;
|
|
46
|
+
layer?: string;
|
|
47
|
+
order?: number;
|
|
48
|
+
visible?: boolean;
|
|
49
|
+
opacity?: number;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface ActorHit {
|
|
53
|
+
readonly actor: Live2dActor;
|
|
54
|
+
readonly actorId: string;
|
|
55
|
+
readonly area: string;
|
|
56
|
+
readonly drawableIndex: number;
|
|
57
|
+
readonly stageX: number;
|
|
58
|
+
readonly stageY: number;
|
|
59
|
+
readonly localX: number;
|
|
60
|
+
readonly localY: number;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface StagePointerEvent {
|
|
64
|
+
readonly actor: Live2dActor | null;
|
|
65
|
+
readonly actorId: string | null;
|
|
66
|
+
readonly area: string | null;
|
|
67
|
+
readonly stageX: number;
|
|
68
|
+
readonly stageY: number;
|
|
69
|
+
readonly clientX: number;
|
|
70
|
+
readonly clientY: number;
|
|
71
|
+
readonly hit: ActorHit | null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export type StageUpdateMode = "auto" | "manual";
|
|
75
|
+
|
|
76
|
+
export interface CreateLive2dStageOptions {
|
|
77
|
+
updateMode?: StageUpdateMode;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Read-only actor surface exposed by the stage. */
|
|
81
|
+
export interface Live2dActor {
|
|
82
|
+
readonly id: string;
|
|
83
|
+
readonly model: InternalModel | null;
|
|
84
|
+
readonly visible: boolean;
|
|
85
|
+
readonly opacity: number;
|
|
86
|
+
readonly layer: string;
|
|
87
|
+
readonly order: number;
|
|
88
|
+
readonly creationIndex: number;
|
|
89
|
+
|
|
90
|
+
getTransform(): ActorTransform;
|
|
91
|
+
|
|
92
|
+
setTransform(patch: Partial<ActorTransform>): void;
|
|
93
|
+
|
|
94
|
+
load(
|
|
95
|
+
source: import("./contracts.js").ModelSource,
|
|
96
|
+
resolver?: import("./contracts.js").AssetResolver,
|
|
97
|
+
): Promise<InternalModel>;
|
|
98
|
+
|
|
99
|
+
setParameter(id: string, value: number): void;
|
|
100
|
+
|
|
101
|
+
lookAt(stageX: number, stageY: number): void;
|
|
102
|
+
|
|
103
|
+
destroy(): void;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Multi-character stage owning one canvas surface and shared renderer. */
|
|
107
|
+
export interface Live2dStage {
|
|
108
|
+
readonly actors: readonly Live2dActor[];
|
|
109
|
+
|
|
110
|
+
mount(canvas: HTMLCanvasElement): Promise<void>;
|
|
111
|
+
|
|
112
|
+
createActor(options?: CreateActorOptions): Live2dActor;
|
|
113
|
+
|
|
114
|
+
removeActor(actor: Live2dActor | string): void;
|
|
115
|
+
|
|
116
|
+
defineLayers(layers: readonly string[]): void;
|
|
117
|
+
|
|
118
|
+
update(deltaTimeSeconds: number): void;
|
|
119
|
+
|
|
120
|
+
render(): void;
|
|
121
|
+
|
|
122
|
+
start(): void;
|
|
123
|
+
|
|
124
|
+
pause(): void;
|
|
125
|
+
|
|
126
|
+
resume(): void;
|
|
127
|
+
|
|
128
|
+
stop(): void;
|
|
129
|
+
|
|
130
|
+
hitTest(stageX: number, stageY: number): ActorHit | null;
|
|
131
|
+
|
|
132
|
+
hitTestAll(stageX: number, stageY: number): readonly ActorHit[];
|
|
133
|
+
|
|
134
|
+
addEventListener(
|
|
135
|
+
type: "pointerdown" | "pointermove" | "pointerup",
|
|
136
|
+
listener: (event: StagePointerEvent) => void,
|
|
137
|
+
): void;
|
|
138
|
+
|
|
139
|
+
removeEventListener(
|
|
140
|
+
type: "pointerdown" | "pointermove" | "pointerup",
|
|
141
|
+
listener: (event: StagePointerEvent) => void,
|
|
142
|
+
): void;
|
|
143
|
+
|
|
144
|
+
destroy(): void;
|
|
145
|
+
|
|
146
|
+
pointerTracking: PointerTrackingPolicy;
|
|
147
|
+
}
|