@doki-land/live2d-core 0.0.16 → 0.0.18
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.d.ts +51 -45
- package/dist/index.js +24 -24
- package/package.json +1 -1
- package/src/{detect-format.ts → format/detect-format.ts} +1 -1
- package/src/index.ts +11 -5
- package/src/{model-asset.ts → model/model-asset.ts} +1 -1
- package/src/session.ts +1 -1
- package/src/{stage.ts → stage/stage.ts} +4 -4
- /package/src/{model.ts → model/model.ts} +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -37,51 +37,6 @@ interface SessionState {
|
|
|
37
37
|
readonly generation: number;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
/** Model binary family (file extension / settings shape). */
|
|
41
|
-
type ModelFormat = "moc2" | "moc3";
|
|
42
|
-
/** Normalized, format-agnostic model settings. */
|
|
43
|
-
interface ModelSettings {
|
|
44
|
-
format: ModelFormat;
|
|
45
|
-
url: string;
|
|
46
|
-
name?: string;
|
|
47
|
-
moc: string;
|
|
48
|
-
textures: string[];
|
|
49
|
-
motionGroups: Record<string, MotionDefinition[]>;
|
|
50
|
-
expressions: ExpressionDefinition[];
|
|
51
|
-
physics?: string;
|
|
52
|
-
pose?: string;
|
|
53
|
-
hitAreas: HitAreaDefinition[];
|
|
54
|
-
layout?: Record<string, number>;
|
|
55
|
-
}
|
|
56
|
-
interface MotionDefinition {
|
|
57
|
-
file: string;
|
|
58
|
-
sound?: string;
|
|
59
|
-
fadeInTime?: number;
|
|
60
|
-
fadeOutTime?: number;
|
|
61
|
-
}
|
|
62
|
-
interface ExpressionDefinition {
|
|
63
|
-
name: string;
|
|
64
|
-
file: string;
|
|
65
|
-
}
|
|
66
|
-
interface HitAreaDefinition {
|
|
67
|
-
name: string;
|
|
68
|
-
id: string;
|
|
69
|
-
}
|
|
70
|
-
/** Opaque in-memory model handle. */
|
|
71
|
-
interface InternalModel {
|
|
72
|
-
readonly id: string;
|
|
73
|
-
readonly settings: ModelSettings;
|
|
74
|
-
readonly format: ModelFormat;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Settings JSON format detection (moc2 vs moc3).
|
|
79
|
-
* Shared by loader normalize and renderer backends — keep binary peek in renderer.
|
|
80
|
-
*/
|
|
81
|
-
|
|
82
|
-
/** Detect moc2 vs moc3 from model settings JSON shape. Returns null if unknown. */
|
|
83
|
-
declare function detectModelSettingsFormat(json: unknown): ModelFormat | null;
|
|
84
|
-
|
|
85
40
|
/** Load pipeline stage for progress UI. */
|
|
86
41
|
type LoadProgressStage = "mounting" | "resolve" | "settings" | "moc" | "textures" | "decode" | "ready";
|
|
87
42
|
interface LoadProgress {
|
|
@@ -151,6 +106,51 @@ declare class EventEmitter {
|
|
|
151
106
|
clear(): void;
|
|
152
107
|
}
|
|
153
108
|
|
|
109
|
+
/** Model binary family (file extension / settings shape). */
|
|
110
|
+
type ModelFormat = "moc2" | "moc3";
|
|
111
|
+
/** Normalized, format-agnostic model settings. */
|
|
112
|
+
interface ModelSettings {
|
|
113
|
+
format: ModelFormat;
|
|
114
|
+
url: string;
|
|
115
|
+
name?: string;
|
|
116
|
+
moc: string;
|
|
117
|
+
textures: string[];
|
|
118
|
+
motionGroups: Record<string, MotionDefinition[]>;
|
|
119
|
+
expressions: ExpressionDefinition[];
|
|
120
|
+
physics?: string;
|
|
121
|
+
pose?: string;
|
|
122
|
+
hitAreas: HitAreaDefinition[];
|
|
123
|
+
layout?: Record<string, number>;
|
|
124
|
+
}
|
|
125
|
+
interface MotionDefinition {
|
|
126
|
+
file: string;
|
|
127
|
+
sound?: string;
|
|
128
|
+
fadeInTime?: number;
|
|
129
|
+
fadeOutTime?: number;
|
|
130
|
+
}
|
|
131
|
+
interface ExpressionDefinition {
|
|
132
|
+
name: string;
|
|
133
|
+
file: string;
|
|
134
|
+
}
|
|
135
|
+
interface HitAreaDefinition {
|
|
136
|
+
name: string;
|
|
137
|
+
id: string;
|
|
138
|
+
}
|
|
139
|
+
/** Opaque in-memory model handle. */
|
|
140
|
+
interface InternalModel {
|
|
141
|
+
readonly id: string;
|
|
142
|
+
readonly settings: ModelSettings;
|
|
143
|
+
readonly format: ModelFormat;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Settings JSON format detection (moc2 vs moc3).
|
|
148
|
+
* Shared by loader normalize and renderer backends — keep binary peek in renderer.
|
|
149
|
+
*/
|
|
150
|
+
|
|
151
|
+
/** Detect moc2 vs moc3 from model settings JSON shape. Returns null if unknown. */
|
|
152
|
+
declare function detectModelSettingsFormat(json: unknown): ModelFormat | null;
|
|
153
|
+
|
|
154
154
|
/**
|
|
155
155
|
* CPU frame output — format-agnostic mesh list ready for any RenderDevice.
|
|
156
156
|
*/
|
|
@@ -392,6 +392,12 @@ interface Live2dStage {
|
|
|
392
392
|
|
|
393
393
|
/**
|
|
394
394
|
* `@doki-land/live2d-core` — types, events, session contracts.
|
|
395
|
+
*
|
|
396
|
+
* Layout:
|
|
397
|
+
* - `format/` — settings JSON format detection
|
|
398
|
+
* - `model/` — settings / asset / actor instance types
|
|
399
|
+
* - `stage/` — stage + actor contracts
|
|
400
|
+
* - root — contracts, events, frame, program, session
|
|
395
401
|
*/
|
|
396
402
|
|
|
397
403
|
declare const LIVE2D_CORE_VERSION: "0.0.0";
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,29 @@ function modelSourceUrl(source) {
|
|
|
9
9
|
return source.baseUrl;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
// src/
|
|
12
|
+
// src/events.ts
|
|
13
|
+
var EventEmitter = class {
|
|
14
|
+
#listeners = /* @__PURE__ */ new Map();
|
|
15
|
+
on(event, listener) {
|
|
16
|
+
const set = this.#listeners.get(event) ?? /* @__PURE__ */ new Set();
|
|
17
|
+
set.add(listener);
|
|
18
|
+
this.#listeners.set(event, set);
|
|
19
|
+
return () => this.off(event, listener);
|
|
20
|
+
}
|
|
21
|
+
off(event, listener) {
|
|
22
|
+
this.#listeners.get(event)?.delete(listener);
|
|
23
|
+
}
|
|
24
|
+
emit(event, payload) {
|
|
25
|
+
for (const listener of this.#listeners.get(event) ?? []) {
|
|
26
|
+
listener(payload);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
clear() {
|
|
30
|
+
this.#listeners.clear();
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// src/format/detect-format.ts
|
|
13
35
|
function detectModelSettingsFormat(json) {
|
|
14
36
|
if (!json || typeof json !== "object") return null;
|
|
15
37
|
const o = json;
|
|
@@ -33,28 +55,6 @@ function detectModelSettingsFormat(json) {
|
|
|
33
55
|
return null;
|
|
34
56
|
}
|
|
35
57
|
|
|
36
|
-
// src/events.ts
|
|
37
|
-
var EventEmitter = class {
|
|
38
|
-
#listeners = /* @__PURE__ */ new Map();
|
|
39
|
-
on(event, listener) {
|
|
40
|
-
const set = this.#listeners.get(event) ?? /* @__PURE__ */ new Set();
|
|
41
|
-
set.add(listener);
|
|
42
|
-
this.#listeners.set(event, set);
|
|
43
|
-
return () => this.off(event, listener);
|
|
44
|
-
}
|
|
45
|
-
off(event, listener) {
|
|
46
|
-
this.#listeners.get(event)?.delete(listener);
|
|
47
|
-
}
|
|
48
|
-
emit(event, payload) {
|
|
49
|
-
for (const listener of this.#listeners.get(event) ?? []) {
|
|
50
|
-
listener(payload);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
clear() {
|
|
54
|
-
this.#listeners.clear();
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
|
|
58
58
|
// src/frame.ts
|
|
59
59
|
var FrameBlendMode = {
|
|
60
60
|
Normal: 0,
|
|
@@ -109,7 +109,7 @@ function createSessionStub() {
|
|
|
109
109
|
};
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
// src/stage.ts
|
|
112
|
+
// src/stage/stage.ts
|
|
113
113
|
var DEFAULT_ACTOR_TRANSFORM = {
|
|
114
114
|
x: 0.5,
|
|
115
115
|
y: 1,
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Shared by loader normalize and renderer backends — keep binary peek in renderer.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import type { ModelFormat } from "
|
|
6
|
+
import type { ModelFormat } from "../model/model.js";
|
|
7
7
|
|
|
8
8
|
/** Detect moc2 vs moc3 from model settings JSON shape. Returns null if unknown. */
|
|
9
9
|
export function detectModelSettingsFormat(json: unknown): ModelFormat | null {
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `@doki-land/live2d-core` — types, events, session contracts.
|
|
3
|
+
*
|
|
4
|
+
* Layout:
|
|
5
|
+
* - `format/` — settings JSON format detection
|
|
6
|
+
* - `model/` — settings / asset / actor instance types
|
|
7
|
+
* - `stage/` — stage + actor contracts
|
|
8
|
+
* - root — contracts, events, frame, program, session
|
|
3
9
|
*/
|
|
4
10
|
|
|
5
11
|
export type {
|
|
@@ -10,7 +16,6 @@ export type {
|
|
|
10
16
|
SessionState,
|
|
11
17
|
} from "./contracts.js";
|
|
12
18
|
export { modelSourceUrl } from "./contracts.js";
|
|
13
|
-
export { detectModelSettingsFormat } from "./detect-format.js";
|
|
14
19
|
export {
|
|
15
20
|
EventEmitter,
|
|
16
21
|
type FrameProfile,
|
|
@@ -20,6 +25,7 @@ export {
|
|
|
20
25
|
type LoadProgress,
|
|
21
26
|
type LoadProgressStage,
|
|
22
27
|
} from "./events.js";
|
|
28
|
+
export { detectModelSettingsFormat } from "./format/detect-format.js";
|
|
23
29
|
export {
|
|
24
30
|
FrameBlendMode,
|
|
25
31
|
type FrameDrawable,
|
|
@@ -32,12 +38,12 @@ export type {
|
|
|
32
38
|
ModelFormat,
|
|
33
39
|
ModelSettings,
|
|
34
40
|
MotionDefinition,
|
|
35
|
-
} from "./model.js";
|
|
41
|
+
} from "./model/model.js";
|
|
36
42
|
export type {
|
|
37
43
|
ActorInstance,
|
|
38
44
|
Live2dStageAssets,
|
|
39
45
|
ModelAsset,
|
|
40
|
-
} from "./model-asset.js";
|
|
46
|
+
} from "./model/model-asset.js";
|
|
41
47
|
export type {
|
|
42
48
|
DrawableProgram,
|
|
43
49
|
ModelInstance,
|
|
@@ -60,7 +66,7 @@ export type {
|
|
|
60
66
|
PointerTrackingPolicy,
|
|
61
67
|
StagePointerEvent,
|
|
62
68
|
StageUpdateMode,
|
|
63
|
-
} from "./stage.js";
|
|
64
|
-
export { DEFAULT_ACTOR_TRANSFORM } from "./stage.js";
|
|
69
|
+
} from "./stage/stage.js";
|
|
70
|
+
export { DEFAULT_ACTOR_TRANSFORM } from "./stage/stage.js";
|
|
65
71
|
|
|
66
72
|
export const LIVE2D_CORE_VERSION = "0.0.0" as const;
|
package/src/session.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AssetResolver, ModelSource, SessionState } from "./contracts.js";
|
|
2
2
|
import { EventEmitter } from "./events.js";
|
|
3
3
|
import type { FrameSnapshot } from "./frame.js";
|
|
4
|
-
import type { InternalModel } from "./model.js";
|
|
4
|
+
import type { InternalModel } from "./model/model.js";
|
|
5
5
|
|
|
6
6
|
/** High-level runtime session for one mounted surface. */
|
|
7
7
|
export interface Live2DSession {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { AssetResolver, ModelSource } from "
|
|
2
|
-
import type { InternalModel, MotionDefinition } from "
|
|
3
|
-
import type { ModelAsset } from "
|
|
1
|
+
import type { AssetResolver, ModelSource } from "../contracts.js";
|
|
2
|
+
import type { InternalModel, MotionDefinition } from "../model/model.js";
|
|
3
|
+
import type { ModelAsset } from "../model/model-asset.js";
|
|
4
4
|
|
|
5
5
|
/** Normalized stage placement for one actor (0,0) top-left → (1,1) bottom-right. */
|
|
6
6
|
export interface ActorTransform {
|
|
@@ -145,7 +145,7 @@ export interface Live2dStage {
|
|
|
145
145
|
readonly actors: readonly Live2dActor[];
|
|
146
146
|
|
|
147
147
|
/** Shared model resource cache for multi-actor reuse. */
|
|
148
|
-
readonly assets: import("
|
|
148
|
+
readonly assets: import("../model/model-asset.js").Live2dStageAssets;
|
|
149
149
|
|
|
150
150
|
mount(canvas: HTMLCanvasElement): Promise<void>;
|
|
151
151
|
|
|
File without changes
|