@doki-land/live2d 0.0.8 → 0.0.10
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/l2d.umd.js +1 -1
- package/dist/l2d.umd.js.map +1 -1
- package/dist/live2d.css +1 -1
- package/package.json +7 -11
- package/readme.md +50 -9
- package/src/fs/index.ts +1 -1
- package/src/helper/index.ts +25 -0
- package/src/icons/style.css +6 -0
- package/src/index.ts +9 -19
- package/src/types/Live2dOptions.ts +1 -1
- package/src/types/Resolve.ts +16 -0
- package/src/types/index.ts +3 -2
package/dist/live2d.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.live2d-icon-panel{position:fixed;right:10px;bottom:150px;z-index:10000;display:flex;flex-direction:column;gap:10px;opacity:0;transition:opacity .3s ease}.live2d-icon-panel.visible{opacity:1}.live2d-icon{width:40px;height:40px;background-color:#fffc;border-radius:50%;display:flex;justify-content:center;align-items:center;cursor:pointer;box-shadow:0 2px 5px #0003;transition:transform .2s ease}.live2d-icon:hover{transform:scale(1.1)}.live2d-icon svg{width:24px;height:24px;fill:#666}
|
|
1
|
+
.live2d-icon-panel{position:fixed;right:10px;bottom:150px;z-index:10000;display:flex;flex-direction:column;gap:10px;opacity:0;transition:opacity .3s ease}.live2d-icon-panel.visible{opacity:1}.live2d-icon{width:40px;height:40px;background-color:#fffc;border-radius:50%;display:flex;justify-content:center;align-items:center;cursor:pointer;box-shadow:0 2px 5px #0003;transition:transform .2s ease}.live2d-icon:hover{transform:scale(1.1)}.live2d-icon svg{width:24px;height:24px;fill:#666}.live2d-canvas{position:absolute;z-index:9999;display:block}
|
package/package.json
CHANGED
|
@@ -1,28 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@doki-land/live2d",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"live2d",
|
|
6
6
|
"pixi",
|
|
7
7
|
"typescript"
|
|
8
8
|
],
|
|
9
|
-
"description": "Live2D TypeScript runtime based on pixi
|
|
9
|
+
"description": "Live2D TypeScript runtime based on pixi",
|
|
10
10
|
"author": "Aster <192608617@qq.com>",
|
|
11
11
|
"license": "LGPL-3.0-or-later",
|
|
12
12
|
"type": "module",
|
|
13
13
|
"exports": {
|
|
14
14
|
".": {
|
|
15
15
|
"types": "./src/index.ts",
|
|
16
|
-
"
|
|
17
|
-
"
|
|
16
|
+
"import": "./src/index.ts",
|
|
17
|
+
"require": "./dist/l2d.umd.js"
|
|
18
18
|
},
|
|
19
|
-
"
|
|
20
|
-
"types": "./src
|
|
21
|
-
"import": "./src
|
|
22
|
-
},
|
|
23
|
-
"./types": {
|
|
24
|
-
"types": "./src/types/index.ts",
|
|
25
|
-
"import": "./src/types/index.ts"
|
|
19
|
+
"./*": {
|
|
20
|
+
"types": "./src/*/index.ts",
|
|
21
|
+
"import": "./src/*/index.ts"
|
|
26
22
|
}
|
|
27
23
|
},
|
|
28
24
|
"files": [
|
package/readme.md
CHANGED
|
@@ -1,19 +1,60 @@
|
|
|
1
|
-
|
|
1
|
+
# Live2D Core Adapter (Unofficial)
|
|
2
2
|
|
|
3
|
+
## Usage
|
|
3
4
|
|
|
5
|
+
This is the core library for rendering Live2D models in web applications.
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
It provides essential functionalities to load and display Live2D models with interactive capabilities.
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### In HTML via Module
|
|
6
12
|
|
|
7
13
|
```html
|
|
14
|
+
<script src="https://cdn.jsdelivr.net/npm/@doki-land/live2d@latest/dist/l2d.umd.js">
|
|
8
15
|
<script type="module">
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
initializeLive2D();
|
|
12
|
-
await createLive2dModel({
|
|
16
|
+
l2d.initializeLive2D();
|
|
17
|
+
l2d.createLive2D({
|
|
13
18
|
element_id: 'live2d-canvas',
|
|
14
19
|
models: [
|
|
15
|
-
|
|
20
|
+
{}
|
|
16
21
|
]
|
|
17
|
-
|
|
22
|
+
})
|
|
18
23
|
</script>
|
|
19
|
-
```
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### In Node via npm
|
|
28
|
+
|
|
29
|
+
- installation
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm install @doki-land/live2d-core
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
- usage
|
|
36
|
+
|
|
37
|
+
```javascript
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### In Other Frameworks
|
|
46
|
+
|
|
47
|
+
- [VitePress]()
|
|
48
|
+
- [VuePress]()
|
|
49
|
+
- [Hexo]()
|
|
50
|
+
|
|
51
|
+
## Features
|
|
52
|
+
|
|
53
|
+
- Render Live2D Cubism™ v1, v2 (`*.model.json`).
|
|
54
|
+
- Render Live2D Cubism™ v3, v4, v5 (`*.model3.json`).
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
### API Documentation
|
|
59
|
+
- `initializeLive2D()`: Initializes the Live2D environment
|
|
60
|
+
- `createLive2dModel(options)`: Creates and renders a Live2D model with specified options
|
package/src/fs/index.ts
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {findAllModels, mergeModels} from "@doki-land/live2d/fs";
|
|
2
|
+
import {ResolveCdn, ResolveElementId, ResolveModels} from "@doki-land/live2d/types";
|
|
3
|
+
|
|
4
|
+
export function generateModelList(options: ResolveModels) {
|
|
5
|
+
const models = mergeModels(options.domain || 'https://localhost:8080', findAllModels(options.models_folder || 'public/live2d'), options.models || []);
|
|
6
|
+
if (models.length == 0) {
|
|
7
|
+
throw new Error('At least one live2d model is required');
|
|
8
|
+
}
|
|
9
|
+
delete options.domain;
|
|
10
|
+
delete options.models;
|
|
11
|
+
delete options.models_folder;
|
|
12
|
+
return models;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function generateElementId(options: ResolveElementId) {
|
|
16
|
+
const element_id = options.element_id || 'live2d-canvas';
|
|
17
|
+
delete options.element_id;
|
|
18
|
+
return element_id
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function generateCdn(options: ResolveCdn) {
|
|
22
|
+
const cdn = options.cdn || 'https://cdn.jsdelivr.net/npm/@doki-land/live2d@latest/dist/l2d.umd.js';
|
|
23
|
+
delete options.cdn;
|
|
24
|
+
return cdn
|
|
25
|
+
}
|
package/src/icons/style.css
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
import '../lib/cubism2.min.js';
|
|
2
2
|
import '../lib/cubism5.min.js';
|
|
3
3
|
import * as PIXI from 'pixi.js';
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
Live2DModel,
|
|
8
|
-
MotionManager,
|
|
9
|
-
SoundManager
|
|
10
|
-
} from 'pixi-live2d-display-lipsyncpatch';
|
|
11
|
-
import { Application, } from 'pixi.js';
|
|
4
|
+
import {Application} from 'pixi.js';
|
|
5
|
+
import {Ticker} from '@pixi/ticker';
|
|
6
|
+
import {Live2DModel, MotionManager, SoundManager} from 'pixi-live2d-display-lipsyncpatch';
|
|
12
7
|
import './icons/style.css';
|
|
13
|
-
import {
|
|
8
|
+
import {Live2dOptions} from '@doki-land/live2d/types';
|
|
14
9
|
|
|
15
10
|
export {MotionManager, SoundManager, Live2DModel, PIXI};
|
|
16
11
|
|
|
@@ -50,7 +45,7 @@ export async function createLive2D(options: Live2dOptions): Promise<Live2DModel>
|
|
|
50
45
|
});
|
|
51
46
|
|
|
52
47
|
// 加载模型
|
|
53
|
-
const model = await Live2DModel.from(models[0].model_url,
|
|
48
|
+
const model = await Live2DModel.from(models[0].model_url, {
|
|
54
49
|
ticker: Ticker.system,
|
|
55
50
|
});
|
|
56
51
|
// 添加模型到舞台
|
|
@@ -76,7 +71,7 @@ export async function createLive2D(options: Live2dOptions): Promise<Live2DModel>
|
|
|
76
71
|
if (auto_motion) {
|
|
77
72
|
await startIdleAnimation(model);
|
|
78
73
|
}
|
|
79
|
-
|
|
74
|
+
|
|
80
75
|
// 创建右侧图标栏
|
|
81
76
|
// createIconPanel(model, element);
|
|
82
77
|
|
|
@@ -88,15 +83,10 @@ function findOrCreateCanvas(id: string, options: Live2dOptions): HTMLCanvasEleme
|
|
|
88
83
|
if (!canvas) {
|
|
89
84
|
canvas = document.createElement('canvas');
|
|
90
85
|
canvas.id = id;
|
|
91
|
-
|
|
92
|
-
canvas.style.display = 'none';
|
|
93
|
-
canvas.style.position = 'fixed';
|
|
94
|
-
// 设置画布样式
|
|
95
|
-
canvas.style.display = 'block';
|
|
96
|
-
canvas.style.position = 'absolute';
|
|
86
|
+
canvas.classList.add('live2d-canvas')
|
|
97
87
|
canvas.style.bottom = `${options.spacing_y || 0}px`;
|
|
98
88
|
canvas.style[options.position === 'left' ? 'left' : 'right'] = `${options.spacing_x || 0}px`;
|
|
99
|
-
|
|
89
|
+
document.body.appendChild(canvas);
|
|
100
90
|
}
|
|
101
91
|
return canvas;
|
|
102
92
|
}
|
|
@@ -124,7 +114,7 @@ function enableMouseTracking(model: Live2DModel, canvas: any) {
|
|
|
124
114
|
model.internalModel.focusController?.focus(mouseX, mouseY);
|
|
125
115
|
}
|
|
126
116
|
});
|
|
127
|
-
|
|
117
|
+
|
|
128
118
|
// 添加点击模型触发动作的交互
|
|
129
119
|
canvas.addEventListener('click', () => {
|
|
130
120
|
// 尝试播放tap_body动作,如果没有则尝试其他可用动作
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {ModelOptions} from "./ModelOptions.ts";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export type ResolveModels = {
|
|
5
|
+
domain?: string,
|
|
6
|
+
models?: ModelOptions[]
|
|
7
|
+
models_folder?: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type ResolveElementId = {
|
|
11
|
+
element_id?: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type ResolveCdn = {
|
|
15
|
+
cdn?: string
|
|
16
|
+
}
|
package/src/types/index.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export * from './Live2dOptions.
|
|
2
|
-
export * from './ModelOptions.
|
|
1
|
+
export * from './Live2dOptions.ts';
|
|
2
|
+
export * from './ModelOptions.ts';
|
|
3
|
+
export * from './Resolve.ts';
|