@doki-land/live2d-core 0.0.14 โ†’ 0.0.16

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,112 @@
1
1
  # @doki-land/live2d-core
2
2
 
3
- live2d.ts package 0.0.14.
3
+ Framework-independent contracts and data structures for the `live2d.ts` runtime.
4
+
5
+ This is an implementation package. Application developers should normally install `@doki-land/live2d` instead.
6
+
7
+ ## ๐Ÿงญ Package Role
8
+
9
+ The core package defines the shared language used by loaders, model runtimes, renderers, and the public facade:
10
+
11
+ - model sources and normalized settings;
12
+ - session phases and state;
13
+ - runtime events and progress payloads;
14
+ - model programs and instances;
15
+ - frame snapshots and drawable data;
16
+ - asset resolver contracts;
17
+ - format detection shared across packages.
18
+
19
+ It does not fetch network resources, decode MOC binaries, create a canvas, or issue GPU commands.
20
+
21
+ ## ๐Ÿ“ฆ Installation
22
+
23
+ ```bash
24
+ pnpm add @doki-land/live2d-core
25
+ ```
26
+
27
+ Install this package directly only when implementing a compatible loader, renderer, diagnostic tool, or host
28
+ integration.
29
+
30
+ ## ๐Ÿงฑ Design Principles
31
+
32
+ - Contracts remain independent of game engines, blog engines, and UI frameworks.
33
+ - Graphics API types do not leak into model and session contracts.
34
+ - Model-format parsing does not belong in core.
35
+ - Public data uses explicit typed structures rather than hidden runtime globals.
36
+ - Events remain small enough for browsers and lightweight hosts.
37
+
38
+ ## ๐Ÿงฉ Core Contracts
39
+
40
+ The package exposes types such as:
41
+
42
+ ```ts
43
+ import type {
44
+ AssetResolver,
45
+ FrameSnapshot,
46
+ Live2DSession,
47
+ ModelSettings,
48
+ ModelSource,
49
+ } from "@doki-land/live2d-core";
50
+ ```
51
+
52
+ An asset resolver provides model-related resources without prescribing HTTP, file-system, CDN, or package-registry
53
+ behavior:
54
+
55
+ ```ts
56
+ const resolver: AssetResolver = {
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
+ };
66
+ ```
67
+
68
+ Use the exact exported interface as the source of truth; the example illustrates the ownership boundary rather than
69
+ guaranteeing every method name across versions.
70
+
71
+ ## ๐Ÿ”„ Session Lifecycle
72
+
73
+ A runtime session moves through explicit phases rather than relying on DOM state:
74
+
75
+ ```text
76
+ idle -> mounting -> ready -> loading -> live
77
+ \-> error
78
+ ```
79
+
80
+ Consumers should listen to phase and error events instead of inferring readiness from a non-null canvas or model
81
+ reference.
82
+
83
+ ## ๐Ÿ“ธ Frame Data
84
+
85
+ `FrameSnapshot` represents evaluated CPU-side model output. It is useful for:
86
+
87
+ - renderer input;
88
+ - deterministic fixtures;
89
+ - diagnostic capture;
90
+ - regression fingerprints;
91
+ - model inspection tools.
92
+
93
+ Frame data must not contain host-specific UI state or require a renderer to reload source assets.
94
+
95
+ ## ๐Ÿงช Development
96
+
97
+ ```bash
98
+ pnpm --filter @doki-land/live2d-core typecheck
99
+ pnpm --filter @doki-land/live2d-core test
100
+ ```
101
+
102
+ Contract changes should include compatibility notes in the change itself and update all workspace consumers in the same
103
+ change set.
104
+
105
+ ## ๐Ÿค Contributing
106
+
107
+ Avoid adding convenience APIs that belong to the facade. A core abstraction should be shared by at least two
108
+ implementation layers and remain meaningful without a browser UI framework.
109
+
110
+ ## ๐Ÿ“„ License
111
+
112
+ See the repository license.
package/dist/index.d.ts CHANGED
@@ -182,6 +182,24 @@ interface FrameSnapshot {
182
182
  readonly drawables: readonly FrameDrawable[];
183
183
  }
184
184
 
185
+ /**
186
+ * Read-only model resources shared across actors on one stage
187
+ * (settings, decoded topology, textures, motion definitions).
188
+ */
189
+ interface ModelAsset {
190
+ readonly key: string;
191
+ readonly settings: ModelSettings;
192
+ }
193
+ /** Stage-scoped model resource cache (`stage.assets`). */
194
+ interface Live2dStageAssets {
195
+ load(source: ModelSource, resolver?: AssetResolver): Promise<ModelAsset>;
196
+ }
197
+ /** Per-actor mutable runtime bound to a shared {@link ModelAsset}. */
198
+ interface ActorInstance {
199
+ readonly asset: ModelAsset;
200
+ readonly model: InternalModel;
201
+ }
202
+
185
203
  /**
186
204
  * CPU model program / instance shapes (format adapters fill these).
187
205
  */
@@ -320,6 +338,8 @@ interface Live2dActor {
320
338
  getTransform(): ActorTransform;
321
339
  setTransform(patch: Partial<ActorTransform>): void;
322
340
  load(source: ModelSource, resolver?: AssetResolver): Promise<InternalModel>;
341
+ /** Attach a stage-cached {@link ModelAsset} without re-fetching resources. */
342
+ loadAsset(asset: ModelAsset): Promise<InternalModel>;
323
343
  setParameter(id: string, value: number): void;
324
344
  listParameters(): ReadonlyArray<{
325
345
  id: string;
@@ -347,6 +367,8 @@ interface Live2dActor {
347
367
  /** Multi-character stage owning one canvas surface and shared renderer. */
348
368
  interface Live2dStage {
349
369
  readonly actors: readonly Live2dActor[];
370
+ /** Shared model resource cache for multi-actor reuse. */
371
+ readonly assets: Live2dStageAssets;
350
372
  mount(canvas: HTMLCanvasElement): Promise<void>;
351
373
  createActor(options?: CreateActorOptions): Live2dActor;
352
374
  getActor(id: string): Live2dActor | null;
@@ -374,4 +396,4 @@ interface Live2dStage {
374
396
 
375
397
  declare const LIVE2D_CORE_VERSION: "0.0.0";
376
398
 
377
- 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 PlayMotionActorOptions, type PointerTrackingMode, type PointerTrackingPolicy, type SessionPhase, type SessionState, type StagePointerEvent, type StageUpdateMode, createSessionStub, detectModelSettingsFormat, modelSourceUrl };
399
+ 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 Live2DEventMap, type Live2DEventName, type Live2DListener, type Live2DSession, type Live2dActor, 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
@@ -1,10 +1,15 @@
1
1
  {
2
2
  "name": "@doki-land/live2d-core",
3
- "version": "0.0.14",
4
- "description": "Live2D types, events, and session contracts",
3
+ "version": "0.0.16",
4
+ "description": "Shared TypeScript contracts for live2d.ts โ€” ModelSource, Live2dStage/Actor, ModelAsset, events (no DOM/GPU).",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
- "author": "Doki Land",
7
+ "homepage": "https://github.com/doki-land/live2d.ts",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/doki-land/live2d.ts.git",
11
+ "directory": "projects/live2d-core"
12
+ },
8
13
  "keywords": [
9
14
  "live2d",
10
15
  "doki-land"
@@ -16,7 +21,8 @@
16
21
  },
17
22
  "files": [
18
23
  "dist",
19
- "src"
24
+ "src",
25
+ "README.md"
20
26
  ],
21
27
  "publishConfig": {
22
28
  "access": "public",
@@ -34,9 +40,5 @@
34
40
  "typecheck": "tsc --noEmit",
35
41
  "test": "vitest run --passWithNoTests"
36
42
  },
37
- "sideEffects": false,
38
- "repository": {
39
- "type": "git",
40
- "url": "git+https://github.com/doki-land/live2d.ts.git"
41
- }
43
+ "sideEffects": false
42
44
  }
package/src/index.ts CHANGED
@@ -33,6 +33,11 @@ export type {
33
33
  ModelSettings,
34
34
  MotionDefinition,
35
35
  } from "./model.js";
36
+ export type {
37
+ ActorInstance,
38
+ Live2dStageAssets,
39
+ ModelAsset,
40
+ } from "./model-asset.js";
36
41
  export type {
37
42
  DrawableProgram,
38
43
  ModelInstance,
@@ -0,0 +1,22 @@
1
+ import type { AssetResolver, ModelSource } from "./contracts.js";
2
+ import type { InternalModel, ModelSettings } from "./model.js";
3
+
4
+ /**
5
+ * Read-only model resources shared across actors on one stage
6
+ * (settings, decoded topology, textures, motion definitions).
7
+ */
8
+ export interface ModelAsset {
9
+ readonly key: string;
10
+ readonly settings: ModelSettings;
11
+ }
12
+
13
+ /** Stage-scoped model resource cache (`stage.assets`). */
14
+ export interface Live2dStageAssets {
15
+ load(source: ModelSource, resolver?: AssetResolver): Promise<ModelAsset>;
16
+ }
17
+
18
+ /** Per-actor mutable runtime bound to a shared {@link ModelAsset}. */
19
+ export interface ActorInstance {
20
+ readonly asset: ModelAsset;
21
+ readonly model: InternalModel;
22
+ }
package/src/stage.ts CHANGED
@@ -1,4 +1,6 @@
1
+ import type { AssetResolver, ModelSource } from "./contracts.js";
1
2
  import type { InternalModel, MotionDefinition } from "./model.js";
3
+ import type { ModelAsset } from "./model-asset.js";
2
4
 
3
5
  /** Normalized stage placement for one actor (0,0) top-left โ†’ (1,1) bottom-right. */
4
6
  export interface ActorTransform {
@@ -100,10 +102,10 @@ export interface Live2dActor {
100
102
 
101
103
  setTransform(patch: Partial<ActorTransform>): void;
102
104
 
103
- load(
104
- source: import("./contracts.js").ModelSource,
105
- resolver?: import("./contracts.js").AssetResolver,
106
- ): Promise<InternalModel>;
105
+ load(source: ModelSource, resolver?: AssetResolver): Promise<InternalModel>;
106
+
107
+ /** Attach a stage-cached {@link ModelAsset} without re-fetching resources. */
108
+ loadAsset(asset: ModelAsset): Promise<InternalModel>;
107
109
 
108
110
  setParameter(id: string, value: number): void;
109
111
 
@@ -142,6 +144,9 @@ export interface Live2dActor {
142
144
  export interface Live2dStage {
143
145
  readonly actors: readonly Live2dActor[];
144
146
 
147
+ /** Shared model resource cache for multi-actor reuse. */
148
+ readonly assets: import("./model-asset.js").Live2dStageAssets;
149
+
145
150
  mount(canvas: HTMLCanvasElement): Promise<void>;
146
151
 
147
152
  createActor(options?: CreateActorOptions): Live2dActor;