@coffic/cosy-ui 0.5.8 → 0.5.12
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/LICENSE +21 -0
- package/README.md +32 -35
- package/dist/app.css +1 -1
- package/dist/database/BlogDB.ts +199 -0
- package/dist/database/CourseDB.ts +85 -0
- package/dist/database/ExperimentDB.ts +103 -0
- package/dist/database/LessonDB.ts +103 -0
- package/dist/database/MetaDB.ts +75 -0
- package/dist/entities/BaseDoc.ts +170 -0
- package/dist/entities/BlogDoc.ts +53 -0
- package/dist/entities/CourseDoc.ts +56 -0
- package/dist/entities/ExperimentDoc.ts +117 -0
- package/dist/entities/Heading.ts +13 -0
- package/dist/entities/LessonDoc.ts +114 -0
- package/dist/entities/MetaDoc.ts +82 -0
- package/dist/entities/Tag.ts +42 -0
- package/dist/index.ts +1 -1
- package/dist/types/static-path.ts +8 -0
- package/dist/utils/image.ts +74 -70
- package/dist/utils/language.ts +0 -7
- package/dist/utils/link.ts +245 -239
- package/dist/utils/logger.ts +101 -126
- package/dist/utils/social.ts +1 -1
- package/package.json +24 -18
- package/dist/models/BaseDoc.ts +0 -164
package/dist/utils/image.ts
CHANGED
@@ -6,78 +6,82 @@
|
|
6
6
|
export type ImageProvider = 'picsum' | 'unsplash' | 'placeholder' | 'robohash';
|
7
7
|
|
8
8
|
export interface ImageOptions {
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
9
|
+
width: number;
|
10
|
+
height: number;
|
11
|
+
tag?: string;
|
12
|
+
randomSeed?: number | string;
|
13
|
+
provider?: ImageProvider;
|
14
|
+
grayscale?: boolean;
|
15
|
+
blur?: number;
|
16
16
|
}
|
17
17
|
|
18
18
|
/**
|
19
19
|
* 获取示例图片URL
|
20
20
|
* @param options 图片选项配置
|
21
21
|
* @returns 生成的图片URL
|
22
|
-
*
|
22
|
+
*
|
23
23
|
* @example
|
24
24
|
* // 基本用法
|
25
25
|
* getExampleImage({ width: 400, height: 300 })
|
26
|
-
*
|
26
|
+
*
|
27
27
|
* @example
|
28
28
|
* // 使用Unsplash并添加标签
|
29
|
-
* getExampleImage({
|
30
|
-
* width: 400,
|
31
|
-
* height: 300,
|
32
|
-
* provider: 'unsplash',
|
33
|
-
* tag: 'nature'
|
29
|
+
* getExampleImage({
|
30
|
+
* width: 400,
|
31
|
+
* height: 300,
|
32
|
+
* provider: 'unsplash',
|
33
|
+
* tag: 'nature'
|
34
34
|
* })
|
35
35
|
*/
|
36
36
|
export function getExampleImage(options: ImageOptions): string {
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
37
|
+
const {
|
38
|
+
width,
|
39
|
+
height,
|
40
|
+
provider = 'picsum',
|
41
|
+
tag = '',
|
42
|
+
randomSeed = Math.floor(Math.random() * 1000),
|
43
|
+
grayscale = false,
|
44
|
+
blur = 0,
|
45
|
+
} = options;
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
47
|
+
switch (provider) {
|
48
|
+
case 'picsum': {
|
49
|
+
const picsumParams = [];
|
50
|
+
if (grayscale) picsumParams.push('grayscale');
|
51
|
+
if (blur > 0 && blur <= 10) picsumParams.push(`blur=${blur}`);
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
53
|
+
const picsumQuery = picsumParams.length
|
54
|
+
? `?${picsumParams.join('&')}`
|
55
|
+
: `?random=${randomSeed}`;
|
56
56
|
|
57
|
-
|
57
|
+
return `https://picsum.photos/${width}/${height}${picsumQuery}`;
|
58
|
+
}
|
58
59
|
|
59
|
-
|
60
|
-
|
61
|
-
|
60
|
+
case 'unsplash': {
|
61
|
+
const tagQuery = tag ? `?${tag}` : '';
|
62
|
+
return `https://source.unsplash.com/random/${width}x${height}${tagQuery}`;
|
63
|
+
}
|
62
64
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
65
|
+
case 'placeholder': {
|
66
|
+
const color = grayscale ? 'gray' : '';
|
67
|
+
const placeholderParams = [];
|
68
|
+
if (tag) placeholderParams.push(`text=${encodeURIComponent(tag)}`);
|
69
|
+
if (color) placeholderParams.push(`bg=${color}`);
|
68
70
|
|
69
|
-
|
70
|
-
`?${placeholderParams.join('&')}` : '';
|
71
|
+
const placeholderQuery = placeholderParams.length ? `?${placeholderParams.join('&')}` : '';
|
71
72
|
|
72
|
-
|
73
|
+
return `https://via.placeholder.com/${width}x${height}${placeholderQuery}`;
|
74
|
+
}
|
73
75
|
|
74
|
-
|
75
|
-
|
76
|
-
|
76
|
+
case 'robohash': {
|
77
|
+
const seed = String(tag || randomSeed);
|
78
|
+
return `https://robohash.org/${encodeURIComponent(seed)}?size=${width}x${height}`;
|
79
|
+
}
|
77
80
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
+
default: {
|
82
|
+
return `https://picsum.photos/${width}/${height}?random=${randomSeed}`;
|
83
|
+
}
|
84
|
+
}
|
81
85
|
}
|
82
86
|
|
83
87
|
/**
|
@@ -85,13 +89,13 @@ export function getExampleImage(options: ImageOptions): string {
|
|
85
89
|
* @param options 可选的图片选项配置
|
86
90
|
*/
|
87
91
|
export function getProductImage(options: Partial<ImageOptions> = {}): string {
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
92
|
+
return getExampleImage({
|
93
|
+
width: options.width || 400,
|
94
|
+
height: options.height || 300,
|
95
|
+
provider: options.provider || 'picsum',
|
96
|
+
tag: options.tag || 'product',
|
97
|
+
...options,
|
98
|
+
});
|
95
99
|
}
|
96
100
|
|
97
101
|
/**
|
@@ -99,12 +103,12 @@ export function getProductImage(options: Partial<ImageOptions> = {}): string {
|
|
99
103
|
* @param options 可选的图片选项配置
|
100
104
|
*/
|
101
105
|
export function getAvatarImage(options: Partial<ImageOptions> = {}): string {
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
106
|
+
return getExampleImage({
|
107
|
+
width: options.width || 200,
|
108
|
+
height: options.height || 200,
|
109
|
+
provider: options.provider || 'robohash',
|
110
|
+
...options,
|
111
|
+
});
|
108
112
|
}
|
109
113
|
|
110
114
|
/**
|
@@ -112,11 +116,11 @@ export function getAvatarImage(options: Partial<ImageOptions> = {}): string {
|
|
112
116
|
* @param options 可选的图片选项配置
|
113
117
|
*/
|
114
118
|
export function getLandscapeImage(options: Partial<ImageOptions> = {}): string {
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
}
|
119
|
+
return getExampleImage({
|
120
|
+
width: options.width || 800,
|
121
|
+
height: options.height || 400,
|
122
|
+
provider: options.provider || 'unsplash',
|
123
|
+
tag: options.tag || 'landscape',
|
124
|
+
...options,
|
125
|
+
});
|
126
|
+
}
|
package/dist/utils/language.ts
CHANGED
@@ -94,13 +94,6 @@ export class LanguageUtil {
|
|
94
94
|
return pathMatch[1];
|
95
95
|
}
|
96
96
|
|
97
|
-
// 如果网站运行在二级目录,则从路径中提取语言代码
|
98
|
-
// 例如: /docs/zh-cn/components/button
|
99
|
-
const pathMatch2 = currentUrl.match(/^\/([^\/]+)\/([\w-]+)\//);
|
100
|
-
if (pathMatch2) {
|
101
|
-
return pathMatch2[2];
|
102
|
-
}
|
103
|
-
|
104
97
|
// 尝试从查询参数中提取语言代码
|
105
98
|
// 例如: ?lang=zh-cn
|
106
99
|
const urlParams = new URLSearchParams(currentUrl.split('?')[1]);
|