lanhu-layer-tree 1.0.0
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/.env.example +11 -0
- package/README.md +317 -0
- package/dist/assets.d.ts +38 -0
- package/dist/assets.d.ts.map +1 -0
- package/dist/assets.js +247 -0
- package/dist/assets.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +322 -0
- package/dist/cli.js.map +1 -0
- package/dist/client.d.ts +44 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +441 -0
- package/dist/client.js.map +1 -0
- package/dist/cookie.d.ts +32 -0
- package/dist/cookie.d.ts.map +1 -0
- package/dist/cookie.js +177 -0
- package/dist/cookie.js.map +1 -0
- package/dist/formatter.d.ts +6 -0
- package/dist/formatter.d.ts.map +1 -0
- package/dist/formatter.js +225 -0
- package/dist/formatter.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/merger.d.ts +27 -0
- package/dist/merger.d.ts.map +1 -0
- package/dist/merger.js +141 -0
- package/dist/merger.js.map +1 -0
- package/dist/resolver.d.ts +27 -0
- package/dist/resolver.d.ts.map +1 -0
- package/dist/resolver.js +196 -0
- package/dist/resolver.js.map +1 -0
- package/dist/types.d.ts +85 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +23 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +106 -0
- package/dist/utils.js.map +1 -0
- package/package.json +38 -0
- package/src/assets.ts +221 -0
- package/src/cli.ts +333 -0
- package/src/client.ts +490 -0
- package/src/cookie.ts +156 -0
- package/src/formatter.ts +251 -0
- package/src/index.ts +4 -0
- package/src/merger.ts +154 -0
- package/src/resolver.ts +195 -0
- package/src/types.ts +94 -0
- package/src/utils.ts +120 -0
- package/tsconfig.json +20 -0
package/src/utils.ts
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 工具函数
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 标准化颜色格式为 #RRGGBB 或 #RRGGBBAA
|
|
7
|
+
*/
|
|
8
|
+
export function normalizeColor(c: any): string {
|
|
9
|
+
if (typeof c === 'string') {
|
|
10
|
+
return c;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (typeof c === 'object' && c !== null) {
|
|
14
|
+
let r = c.r ?? c.red ?? c.R ?? 0;
|
|
15
|
+
let g = c.g ?? c.green ?? c.G ?? 0;
|
|
16
|
+
let b = c.b ?? c.blue ?? c.B ?? 0;
|
|
17
|
+
let a = c.a ?? c.alpha ?? null;
|
|
18
|
+
|
|
19
|
+
// 如果是 0-1 范围的浮点数,转换为 0-255
|
|
20
|
+
if (typeof r === 'number' && r <= 1.0 && typeof g === 'number' && g <= 1.0) {
|
|
21
|
+
r = Math.round(r * 255);
|
|
22
|
+
g = Math.round(g * 255);
|
|
23
|
+
b = Math.round(b * 255);
|
|
24
|
+
if (a !== null && typeof a === 'number' && a <= 1.0) {
|
|
25
|
+
a = Math.round(a * 255);
|
|
26
|
+
}
|
|
27
|
+
} else {
|
|
28
|
+
r = Math.round(r);
|
|
29
|
+
g = Math.round(g);
|
|
30
|
+
b = Math.round(b);
|
|
31
|
+
if (a !== null) {
|
|
32
|
+
a = Math.round(a);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (a !== null && a < 255) {
|
|
37
|
+
return `#${r.toString(16).padStart(2, '0')}${g.toString(16).padStart(2, '0')}${b.toString(16).padStart(2, '0')}${a.toString(16).padStart(2, '0')}`.toUpperCase();
|
|
38
|
+
}
|
|
39
|
+
return `#${r.toString(16).padStart(2, '0')}${g.toString(16).padStart(2, '0')}${b.toString(16).padStart(2, '0')}`.toUpperCase();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return String(c);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* 解析蓝湖 URL,提取 tid/pid/image_id 等参数
|
|
47
|
+
*/
|
|
48
|
+
export function parseUrl(url: string, defaultTid?: string): { team_id: string; project_id: string; doc_id?: string } {
|
|
49
|
+
let queryString = url;
|
|
50
|
+
|
|
51
|
+
if (url.startsWith('http')) {
|
|
52
|
+
const urlObj = new URL(url);
|
|
53
|
+
const fragment = urlObj.hash;
|
|
54
|
+
if (!fragment) {
|
|
55
|
+
throw new Error('Invalid Lanhu URL: missing fragment part');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (fragment.includes('?')) {
|
|
59
|
+
queryString = fragment.split('?')[1];
|
|
60
|
+
} else {
|
|
61
|
+
queryString = fragment;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (queryString.startsWith('?')) {
|
|
66
|
+
queryString = queryString.substring(1);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const params: Record<string, string> = {};
|
|
70
|
+
queryString.split('&').forEach(part => {
|
|
71
|
+
if (part.includes('=')) {
|
|
72
|
+
const [key, value] = part.split('=');
|
|
73
|
+
params[key] = value;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const teamId = params.tid;
|
|
78
|
+
const projectId = params.pid;
|
|
79
|
+
const docId = params.docId || params.image_id;
|
|
80
|
+
|
|
81
|
+
if (!projectId) {
|
|
82
|
+
throw new Error('URL parsing failed: missing required param pid');
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (!teamId) {
|
|
86
|
+
if (!defaultTid) {
|
|
87
|
+
throw new Error('URL 缺少 tid 参数,且未配置默认 TID');
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
team_id: defaultTid,
|
|
91
|
+
project_id: projectId,
|
|
92
|
+
doc_id: docId
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
team_id: teamId,
|
|
98
|
+
project_id: projectId,
|
|
99
|
+
doc_id: docId
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* 将 PS 坐标系转换为游戏引擎 UI 坐标系(Cocos/Unity)
|
|
105
|
+
*
|
|
106
|
+
* PS 坐标系:左上角为原点 (0,0),x 向右,y 向下
|
|
107
|
+
* 引擎坐标系:父节点中心为原点 (0,0),x 向右,y 向上,锚点为元素中心 (0.5, 0.5)
|
|
108
|
+
*/
|
|
109
|
+
export function convertToEnginePos(
|
|
110
|
+
left: number,
|
|
111
|
+
top: number,
|
|
112
|
+
width: number,
|
|
113
|
+
height: number,
|
|
114
|
+
parentWidth: number,
|
|
115
|
+
parentHeight: number
|
|
116
|
+
): [number, number] {
|
|
117
|
+
const x = Math.round((left + width / 2 - parentWidth / 2) * 10) / 10;
|
|
118
|
+
const y = Math.round((parentHeight / 2 - (top + height / 2)) * 10) / 10;
|
|
119
|
+
return [x, y];
|
|
120
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "node16",
|
|
5
|
+
"lib": ["ES2020"],
|
|
6
|
+
"outDir": "./dist",
|
|
7
|
+
"rootDir": "./src",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true,
|
|
12
|
+
"resolveJsonModule": true,
|
|
13
|
+
"declaration": true,
|
|
14
|
+
"declarationMap": true,
|
|
15
|
+
"sourceMap": true,
|
|
16
|
+
"moduleResolution": "node16"
|
|
17
|
+
},
|
|
18
|
+
"include": ["src/**/*"],
|
|
19
|
+
"exclude": ["node_modules", "dist"]
|
|
20
|
+
}
|