@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.
@@ -6,78 +6,82 @@
6
6
  export type ImageProvider = 'picsum' | 'unsplash' | 'placeholder' | 'robohash';
7
7
 
8
8
  export interface ImageOptions {
9
- width: number;
10
- height: number;
11
- tag?: string;
12
- randomSeed?: number | string;
13
- provider?: ImageProvider;
14
- grayscale?: boolean;
15
- blur?: number;
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
- 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;
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
- switch (provider) {
48
- case 'picsum':
49
- const picsumParams = [];
50
- if (grayscale) picsumParams.push('grayscale');
51
- if (blur > 0 && blur <= 10) picsumParams.push(`blur=${blur}`);
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
- const picsumQuery = picsumParams.length ?
54
- `?${picsumParams.join('&')}` :
55
- `?random=${randomSeed}`;
53
+ const picsumQuery = picsumParams.length
54
+ ? `?${picsumParams.join('&')}`
55
+ : `?random=${randomSeed}`;
56
56
 
57
- return `https://picsum.photos/${width}/${height}${picsumQuery}`;
57
+ return `https://picsum.photos/${width}/${height}${picsumQuery}`;
58
+ }
58
59
 
59
- case 'unsplash':
60
- const tagQuery = tag ? `?${tag}` : '';
61
- return `https://source.unsplash.com/random/${width}x${height}${tagQuery}`;
60
+ case 'unsplash': {
61
+ const tagQuery = tag ? `?${tag}` : '';
62
+ return `https://source.unsplash.com/random/${width}x${height}${tagQuery}`;
63
+ }
62
64
 
63
- case 'placeholder':
64
- const color = grayscale ? 'gray' : '';
65
- const placeholderParams = [];
66
- if (tag) placeholderParams.push(`text=${encodeURIComponent(tag)}`);
67
- if (color) placeholderParams.push(`bg=${color}`);
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
- const placeholderQuery = placeholderParams.length ?
70
- `?${placeholderParams.join('&')}` : '';
71
+ const placeholderQuery = placeholderParams.length ? `?${placeholderParams.join('&')}` : '';
71
72
 
72
- return `https://via.placeholder.com/${width}x${height}${placeholderQuery}`;
73
+ return `https://via.placeholder.com/${width}x${height}${placeholderQuery}`;
74
+ }
73
75
 
74
- case 'robohash':
75
- const seed = String(tag || randomSeed);
76
- return `https://robohash.org/${encodeURIComponent(seed)}?size=${width}x${height}`;
76
+ case 'robohash': {
77
+ const seed = String(tag || randomSeed);
78
+ return `https://robohash.org/${encodeURIComponent(seed)}?size=${width}x${height}`;
79
+ }
77
80
 
78
- default:
79
- return `https://picsum.photos/${width}/${height}?random=${randomSeed}`;
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
- return getExampleImage({
89
- width: options.width || 400,
90
- height: options.height || 300,
91
- provider: options.provider || 'picsum',
92
- tag: options.tag || 'product',
93
- ...options
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
- return getExampleImage({
103
- width: options.width || 200,
104
- height: options.height || 200,
105
- provider: options.provider || 'robohash',
106
- ...options
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
- return getExampleImage({
116
- width: options.width || 800,
117
- height: options.height || 400,
118
- provider: options.provider || 'unsplash',
119
- tag: options.tag || 'landscape',
120
- ...options
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
+ }
@@ -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]);