@doki-land/live2d 0.0.5 → 0.0.7

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/src/fs/index.ts CHANGED
@@ -1,88 +1,93 @@
1
- import { minimatch } from 'minimatch';
2
- import * as fs from 'fs';
3
- import * as path from 'path';
4
- import { ModelOptions } from '@/types/index.js';
5
-
6
- /**
7
- * 判断根据当前路径和指定的包含/排除规则,是否允许显示 Live2D 功能。
8
- *
9
- * @param currentPath 当前页面路径。
10
- * @param includePaths 包含 Live2D 功能的路径列表。
11
- * @param excludePaths 排除 Live2D 功能的路径列表。
12
- * @returns 如果满足显示条件返回 true,否则返回 false。
13
- *
14
- * @description
15
- *
16
- * 排除的优先级高于包括
17
- */
18
- export function allowShowLive2D(currentPath: string, includePaths: string[], excludePaths: string[]): boolean {
19
-
20
- // 如果当前路径匹配任何排除路径规则,不显示 Live2D
21
- if (excludePaths.some(pattern => minimatch(currentPath, pattern))) {
22
- return false;
23
- }
24
-
25
- // 如果包含路径列表不为空,则仅当当前路径匹配任意包含路径规则时才显示 Live2D
26
- if (includePaths.length > 0) {
27
- return includePaths.some(pattern => minimatch(currentPath, pattern));
28
- }
29
-
30
- // 默认情况下,允许显示 Live2D
31
- return true;
32
- }
33
-
34
-
35
- /**
36
- * 找到文件夹里的所有模型的相对路径
37
- * @param folder
38
- * @param depth
39
- *
40
- * @returns 模型路径列表
41
- *
42
- * @description
43
- *
44
- * 模型需要以 `*.model.json` 或 `*.model3.json` 结尾
45
- */
46
- export function findAllModels(folder: string, depth: number = 99): string[] {
47
- const models: string[] = [];
48
- for (const file of fs.readdirSync(folder)) {
49
- const filePath = path.join(folder, file);
50
- const stat = fs.statSync(filePath);
51
- if (stat.isDirectory()) {
52
- if (depth > 0) {
53
- models.push(...findAllModels(filePath, depth - 1));
54
- }
55
- } else if (file.endsWith('.model.json') || file.endsWith('.model3.json')) {
56
- models.push(filePath);
57
- }
58
- }
59
- return models;
60
- }
61
-
62
- /**
63
- * 合并模型函数
64
- * 该函数的目的是将一系列本地模型与远程模型选项合并,以生成一个新的模型列表
65
- * 它接受一个基础URL字符串,一个本地模型名称数组和一个远程模型选项数组作为输入
66
- *
67
- * @param base 基础URL字符串,用于解析相对URL
68
- * @param local 本地模型名称数组,这些模型将被合并到最终的模型列表中
69
- * @param remote 远程模型选项数组
70
- * @returns 返回一个新的模型 url 列表
71
- *
72
- * @description
73
- *
74
- * 本地模型的优先级更高, 本地模型根据自然序(Natural Sort)排列
75
- */
76
- export function mergeModels(base: string, local: string[], remote: ModelOptions[]): string[] {
77
- const models: string[] = [];
78
- const url = new URL(base);
79
- for (const model of local) {
80
- models.push(new URL(model, url).href);
81
- }
82
- for (const model of remote) {
83
- models.push(model.model_url);
84
- }
85
- return models
86
- }
87
-
88
-
1
+ import { minimatch } from 'minimatch';
2
+ import { ModelOptions } from '@/types/index.js';
3
+ import path from 'node:path';
4
+ import fs from 'node:fs';
5
+
6
+ /**
7
+ * 判断根据当前路径和指定的包含/排除规则,是否允许显示 Live2D 功能。
8
+ *
9
+ * @param currentPath 当前页面路径。
10
+ * @param includePaths 包含 Live2D 功能的路径列表。
11
+ * @param excludePaths 排除 Live2D 功能的路径列表。
12
+ * @returns 如果满足显示条件返回 true,否则返回 false。
13
+ *
14
+ * @description
15
+ *
16
+ * 排除的优先级高于包括
17
+ */
18
+ export function allowShowLive2D(currentPath: string, includePaths: string[], excludePaths: string[]): boolean {
19
+
20
+ // 如果当前路径匹配任何排除路径规则,不显示 Live2D
21
+ if (excludePaths.some(pattern => minimatch(currentPath, pattern))) {
22
+ return false;
23
+ }
24
+
25
+ // 如果包含路径列表不为空,则仅当当前路径匹配任意包含路径规则时才显示 Live2D
26
+ if (includePaths.length > 0) {
27
+ return includePaths.some(pattern => minimatch(currentPath, pattern));
28
+ }
29
+
30
+ // 默认情况下,允许显示 Live2D
31
+ return true;
32
+ }
33
+
34
+
35
+ /**
36
+ * 找到文件夹里的所有模型的相对路径
37
+ * @param folder
38
+ * @param depth
39
+ *
40
+ * @returns 模型路径列表
41
+ *
42
+ * @description
43
+ *
44
+ * 模型需要以 `*.model.json` 或 `*.model3.json` 结尾
45
+ */
46
+ export function findAllModels(folder: string, depth: number = 99): string[] {
47
+ const models: string[] = [];
48
+ if (fs.existsSync(folder)) {
49
+ for (const file of fs.readdirSync(folder)) {
50
+ const filePath = path.join(folder, file);
51
+ const stat = fs.statSync(filePath);
52
+ if (stat.isDirectory()) {
53
+ if (depth > 0) {
54
+ models.push(...findAllModels(filePath, depth - 1));
55
+ }
56
+ } else if (file.endsWith('.model.json') || file.endsWith('.model3.json')) {
57
+ models.push(filePath);
58
+ }
59
+ }
60
+ }
61
+
62
+ return models;
63
+ }
64
+
65
+ /**
66
+ * 合并模型函数
67
+ * 该函数的目的是将一系列本地模型与远程模型选项合并,以生成一个新的模型列表
68
+ * 它接受一个基础URL字符串,一个本地模型名称数组和一个远程模型选项数组作为输入
69
+ *
70
+ * @param base 基础URL字符串,用于解析相对URL
71
+ * @param local 本地模型名称数组,这些模型将被合并到最终的模型列表中
72
+ * @param remote 远程模型选项数组
73
+ * @returns 返回一个新的模型 url 列表
74
+ *
75
+ * @description
76
+ *
77
+ * 本地模型的优先级更高, 本地模型根据自然序(Natural Sort)排列
78
+ */
79
+ export function mergeModels(base: string, local: string[], remote: ModelOptions[]): ModelOptions[] {
80
+ const models: ModelOptions[] = [];
81
+ const url = new URL(base);
82
+ for (const model of local) {
83
+ models.push({
84
+ model_url: new URL(model, url).href,
85
+ });
86
+ }
87
+ for (const model of remote) {
88
+ models.push(model);
89
+ }
90
+ return models
91
+ }
92
+
93
+
@@ -1,39 +1,39 @@
1
- // 图标定义
2
- export const icons = [
3
- {
4
- id: 'message',
5
- svg: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm0 14H5.17L4 17.17V4h16v12z"/></svg>`,
6
- title: '发送消息',
7
- action: 'message'
8
- },
9
- {
10
- id: 'telegram',
11
- svg: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.78 18.65l.28-4.23 7.68-6.92c.34-.31-.07-.46-.52-.19L7.74 13.3 3.64 12c-.88-.25-.89-.86.2-1.3l15.97-6.16c.73-.33 1.43.18 1.15 1.3l-2.72 12.81c-.19.91-.74 1.13-1.5.71L12.6 16.3l-1.99 1.93c-.23.23-.42.42-.83.42z"/></svg>`,
12
- title: '联系我们',
13
- action: 'telegram'
14
- },
15
- {
16
- id: 'user',
17
- svg: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z"/></svg>`,
18
- title: '用户信息',
19
- action: 'user'
20
- },
21
- {
22
- id: 'info',
23
- svg: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z"/></svg>`,
24
- title: '关于',
25
- action: 'info'
26
- },
27
- {
28
- id: 'photo',
29
- svg: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 12c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm0 1c-1.63 0-3.06.79-3.98 2H8c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2h8c1.1 0 2 .9 2 2v7c0 1.1-.9 2-2 2h-.02c-.92-1.21-2.35-2-3.98-2zm7-8h-4.18C14.4 4.84 13.3 4 12 4c-1.3 0-2.4.84-2.82 2H5c-.14 0-.27.01-.4.04-.39.08-.74.28-1.01.55-.18.18-.33.4-.43.64-.1.23-.16.49-.16.77v14c0 .27.06.54.16.78s.25.45.43.64c.27.27.62.47 1.01.55.13.02.26.03.4.03h14c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm-7 0c.55 0 1 .45 1 1s-.45 1-1 1-1-.45-1-1 .45-1 1-1zm5 13c0 .55-.45 1-1 1H6c-.55 0-1-.45-1-1V8c0-.55.45-1 1-1h2.18c.42 1.16 1.52 2 2.82 2 1.3 0 2.4-.84 2.82-2H16c.55 0 1 .45 1 1v10z"/></svg>`,
30
- title: '拍照',
31
- action: 'photo'
32
- },
33
- {
34
- id: 'close',
35
- svg: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z"/></svg>`,
36
- title: '关闭',
37
- action: 'close'
38
- }
1
+ // 图标定义
2
+ export const icons = [
3
+ {
4
+ id: 'message',
5
+ svg: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm0 14H5.17L4 17.17V4h16v12z"/></svg>`,
6
+ title: '发送消息',
7
+ action: 'message'
8
+ },
9
+ {
10
+ id: 'telegram',
11
+ svg: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.78 18.65l.28-4.23 7.68-6.92c.34-.31-.07-.46-.52-.19L7.74 13.3 3.64 12c-.88-.25-.89-.86.2-1.3l15.97-6.16c.73-.33 1.43.18 1.15 1.3l-2.72 12.81c-.19.91-.74 1.13-1.5.71L12.6 16.3l-1.99 1.93c-.23.23-.42.42-.83.42z"/></svg>`,
12
+ title: '联系我们',
13
+ action: 'telegram'
14
+ },
15
+ {
16
+ id: 'user',
17
+ svg: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z"/></svg>`,
18
+ title: '用户信息',
19
+ action: 'user'
20
+ },
21
+ {
22
+ id: 'info',
23
+ svg: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z"/></svg>`,
24
+ title: '关于',
25
+ action: 'info'
26
+ },
27
+ {
28
+ id: 'photo',
29
+ svg: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 12c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm0 1c-1.63 0-3.06.79-3.98 2H8c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2h8c1.1 0 2 .9 2 2v7c0 1.1-.9 2-2 2h-.02c-.92-1.21-2.35-2-3.98-2zm7-8h-4.18C14.4 4.84 13.3 4 12 4c-1.3 0-2.4.84-2.82 2H5c-.14 0-.27.01-.4.04-.39.08-.74.28-1.01.55-.18.18-.33.4-.43.64-.1.23-.16.49-.16.77v14c0 .27.06.54.16.78s.25.45.43.64c.27.27.62.47 1.01.55.13.02.26.03.4.03h14c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm-7 0c.55 0 1 .45 1 1s-.45 1-1 1-1-.45-1-1 .45-1 1-1zm5 13c0 .55-.45 1-1 1H6c-.55 0-1-.45-1-1V8c0-.55.45-1 1-1h2.18c.42 1.16 1.52 2 2.82 2 1.3 0 2.4-.84 2.82-2H16c.55 0 1 .45 1 1v10z"/></svg>`,
30
+ title: '拍照',
31
+ action: 'photo'
32
+ },
33
+ {
34
+ id: 'close',
35
+ svg: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z"/></svg>`,
36
+ title: '关闭',
37
+ action: 'close'
38
+ }
39
39
  ];
@@ -1,38 +1,38 @@
1
- .live2d-icon-panel {
2
- position: fixed;
3
- right: 10px;
4
- bottom: 150px;
5
- z-index: 10000;
6
- display: flex;
7
- flex-direction: column;
8
- gap: 10px;
9
- opacity: 0;
10
- transition: opacity 0.3s ease;
11
- }
12
-
13
- .live2d-icon-panel.visible {
14
- opacity: 1;
15
- }
16
-
17
- .live2d-icon {
18
- width: 40px;
19
- height: 40px;
20
- background-color: rgba(255, 255, 255, 0.8);
21
- border-radius: 50%;
22
- display: flex;
23
- justify-content: center;
24
- align-items: center;
25
- cursor: pointer;
26
- box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
27
- transition: transform 0.2s ease;
28
- }
29
-
30
- .live2d-icon:hover {
31
- transform: scale(1.1);
32
- }
33
-
34
- .live2d-icon svg {
35
- width: 24px;
36
- height: 24px;
37
- fill: #666;
1
+ .live2d-icon-panel {
2
+ position: fixed;
3
+ right: 10px;
4
+ bottom: 150px;
5
+ z-index: 10000;
6
+ display: flex;
7
+ flex-direction: column;
8
+ gap: 10px;
9
+ opacity: 0;
10
+ transition: opacity 0.3s ease;
11
+ }
12
+
13
+ .live2d-icon-panel.visible {
14
+ opacity: 1;
15
+ }
16
+
17
+ .live2d-icon {
18
+ width: 40px;
19
+ height: 40px;
20
+ background-color: rgba(255, 255, 255, 0.8);
21
+ border-radius: 50%;
22
+ display: flex;
23
+ justify-content: center;
24
+ align-items: center;
25
+ cursor: pointer;
26
+ box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
27
+ transition: transform 0.2s ease;
28
+ }
29
+
30
+ .live2d-icon:hover {
31
+ transform: scale(1.1);
32
+ }
33
+
34
+ .live2d-icon svg {
35
+ width: 24px;
36
+ height: 24px;
37
+ fill: #666;
38
38
  }
package/src/index.ts CHANGED
@@ -12,7 +12,7 @@ import { Application, } from 'pixi.js';
12
12
  import './icons/style.css';
13
13
  import { Live2dOptions } from '@/types/index.js';
14
14
 
15
- export { MotionManager, SoundManager, Live2DModel, PIXI };
15
+ export {MotionManager, SoundManager, Live2DModel, PIXI};
16
16
 
17
17
  /**
18
18
  * 创建Live2D模型
@@ -1,56 +1,56 @@
1
- import { ModelOptions } from './ModelOptions.js';
2
-
3
- /**
4
- * Live2D模型配置选项
5
- */
6
- export interface Live2dOptions {
7
- /**
8
- * 模型配置选项
9
- */
10
- models: ModelOptions[];
11
- /**
12
- * 画布的ID
13
- * @default 'live2d-canvas'
14
- */
15
- element_id?: string,
16
- /**
17
- * 画布的宽度
18
- * @default 300
19
- */
20
- width?: number;
21
- /**
22
- * 画布的高度
23
- * @default 300
24
- */
25
- height?: number;
26
- /**
27
- * 模型位置,可选 'left' 或 'right'
28
- * @default 'right'
29
- */
30
- position?: 'left' | 'right';
31
- /**
32
- * 模型与左右边框的距离(像素)
33
- * @default 20
34
- */
35
- spacing_x?: number;
36
- /**
37
- * 模型与底部边框的距离(像素)
38
- * @default 20
39
- */
40
- spacing_y?: number;
41
- /**
42
- * 是否自动适应模型大小
43
- * @default true
44
- */
45
- auto_fit?: boolean;
46
- /**
47
- * 是否自动开始动画
48
- * @default true
49
- */
50
- auto_motion?: boolean;
51
- /**
52
- * 是否启用鼠标跟踪
53
- * @default true
54
- */
55
- mouse_tracking?: boolean;
1
+ import { ModelOptions } from './ModelOptions.js';
2
+
3
+ /**
4
+ * Live2D模型配置选项
5
+ */
6
+ export interface Live2dOptions {
7
+ /**
8
+ * 模型配置选项
9
+ */
10
+ models: ModelOptions[];
11
+ /**
12
+ * 画布的ID
13
+ * @default 'live2d-canvas'
14
+ */
15
+ element_id?: string,
16
+ /**
17
+ * 画布的宽度
18
+ * @default 300
19
+ */
20
+ width?: number;
21
+ /**
22
+ * 画布的高度
23
+ * @default 300
24
+ */
25
+ height?: number;
26
+ /**
27
+ * 模型位置,可选 'left' 或 'right'
28
+ * @default 'right'
29
+ */
30
+ position?: 'left' | 'right';
31
+ /**
32
+ * 模型与左右边框的距离(像素)
33
+ * @default 20
34
+ */
35
+ spacing_x?: number;
36
+ /**
37
+ * 模型与底部边框的距离(像素)
38
+ * @default 20
39
+ */
40
+ spacing_y?: number;
41
+ /**
42
+ * 是否自动适应模型大小
43
+ * @default true
44
+ */
45
+ auto_fit?: boolean;
46
+ /**
47
+ * 是否自动开始动画
48
+ * @default true
49
+ */
50
+ auto_motion?: boolean;
51
+ /**
52
+ * 是否启用鼠标跟踪
53
+ * @default true
54
+ */
55
+ mouse_tracking?: boolean;
56
56
  }
@@ -1,40 +1,40 @@
1
- export type ModelOptions = ModelMainOptions & ModelMobileAdaptation;
2
- export interface ModelMobileAdaptation {
3
- /**
4
- * 移动端配置, 会覆盖 desktop 中的主配置
5
- * @default null
6
- */
7
- mobile?: Partial<ModelOptions>;
8
- }
9
- export interface ModelMainOptions {
10
- /**
11
- * 模型JSON文件的路径
12
- */
13
- model_url: string;
14
- position?: ModelPosition;
15
- }
16
-
17
- export interface ModelPosition {
18
- /**
19
- * 模型在画布中的缩放
20
- */
21
- scale?: number,
22
- /**
23
- * 模型在画布中的位置
24
- */
25
- anchor_x?: number;
26
- /**
27
- * 模型在画布中的位置
28
- */
29
- anchor_y?: number;
30
- /**
31
- * 画布宽度
32
- * @default 300
33
- */
34
- width?: number;
35
- /**
36
- * 画布高度
37
- * @default 300
38
- */
39
- height?: number;
1
+ export type ModelOptions = ModelMainOptions & ModelMobileAdaptation;
2
+ export interface ModelMobileAdaptation {
3
+ /**
4
+ * 移动端配置, 会覆盖 desktop 中的主配置
5
+ * @default null
6
+ */
7
+ mobile?: Partial<ModelOptions>;
8
+ }
9
+ export interface ModelMainOptions {
10
+ /**
11
+ * 模型JSON文件的路径
12
+ */
13
+ model_url: string;
14
+ position?: ModelPosition;
15
+ }
16
+
17
+ export interface ModelPosition {
18
+ /**
19
+ * 模型在画布中的缩放
20
+ */
21
+ scale?: number,
22
+ /**
23
+ * 模型在画布中的位置
24
+ */
25
+ anchor_x?: number;
26
+ /**
27
+ * 模型在画布中的位置
28
+ */
29
+ anchor_y?: number;
30
+ /**
31
+ * 画布宽度
32
+ * @default 300
33
+ */
34
+ width?: number;
35
+ /**
36
+ * 画布高度
37
+ * @default 300
38
+ */
39
+ height?: number;
40
40
  }
@@ -1,2 +1,2 @@
1
- export * from './Live2dOptions.js';
1
+ export * from './Live2dOptions.js';
2
2
  export * from './ModelOptions.js';