@coffic/cosy-ui 0.9.1 → 0.9.3

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.
@@ -5,67 +5,67 @@ import type { IMetaProps } from './meta';
5
5
  import type { ISidebarProps } from './sidebar';
6
6
 
7
7
  export interface IAppLayoutProps {
8
- /**
9
- * 是否显示侧边栏
10
- * @default true
11
- */
12
- showSidebar?: boolean;
8
+ /**
9
+ * 是否显示侧边栏
10
+ * @default true
11
+ */
12
+ showSidebar?: boolean;
13
13
 
14
- /**
15
- * 是否显示页眉
16
- * @default true
17
- */
18
- showHeader?: boolean;
14
+ /**
15
+ * 是否显示页眉
16
+ * @default true
17
+ */
18
+ showHeader?: boolean;
19
19
 
20
- /**
21
- * 是否显示页脚
22
- * @default true
23
- */
24
- showFooter?: boolean;
20
+ /**
21
+ * 是否显示页脚
22
+ * @default true
23
+ */
24
+ showFooter?: boolean;
25
25
 
26
- /**
27
- * 自定义头部内容
28
- */
29
- head?: astroHTML.JSX.Element;
26
+ /**
27
+ * 自定义头部内容
28
+ */
29
+ head?: any;
30
30
 
31
- /**
32
- * 自定义头部内容
33
- */
34
- headerConfig: IHeaderProps;
31
+ /**
32
+ * 自定义头部内容
33
+ */
34
+ headerConfig: IHeaderProps;
35
35
 
36
- /**
37
- * 侧边栏配置
38
- */
39
- sidebarConfig: ISidebarProps;
36
+ /**
37
+ * 侧边栏配置
38
+ */
39
+ sidebarConfig: ISidebarProps;
40
40
 
41
- /**
42
- * 主内容配置
43
- */
44
- mainContentConfig: IMainContentProps;
41
+ /**
42
+ * 主内容配置
43
+ */
44
+ mainContentConfig: IMainContentProps;
45
45
 
46
- /**
47
- * 页面类名
48
- */
49
- class?: string;
46
+ /**
47
+ * 页面类名
48
+ */
49
+ class?: string;
50
50
 
51
- /**
52
- * 类名列表
53
- */
54
- 'class:list'?: any;
51
+ /**
52
+ * 类名列表
53
+ */
54
+ 'class:list'?: any;
55
55
 
56
- /**
57
- * 调试模式,显示各个部分的边框
58
- * @default false
59
- */
60
- debug?: boolean;
56
+ /**
57
+ * 调试模式,显示各个部分的边框
58
+ * @default false
59
+ */
60
+ debug?: boolean;
61
61
 
62
- /**
63
- * 元数据配置
64
- */
65
- metaConfig: IMetaProps;
62
+ /**
63
+ * 元数据配置
64
+ */
65
+ metaConfig: IMetaProps;
66
66
 
67
- /**
68
- * 页脚相关配置
69
- */
70
- footerConfig: IFooterProps;
67
+ /**
68
+ * 页脚相关配置
69
+ */
70
+ footerConfig: IFooterProps;
71
71
  }
@@ -1,3 +1,5 @@
1
+ import type { ImageMetadata } from 'astro';
2
+
1
3
  export interface IMetaProps {
2
4
  title: string;
3
5
  description: string;
@@ -41,7 +43,7 @@ export interface IMetaProps {
41
43
  /**
42
44
  * 自定义头部内容
43
45
  */
44
- head?: astroHTML.JSX.Element;
46
+ head?: any;
45
47
 
46
48
  /**
47
49
  * 页面类名
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coffic/cosy-ui",
3
- "version": "0.9.1",
3
+ "version": "0.9.3",
4
4
  "description": "An astro component library",
5
5
  "author": {
6
6
  "name": "nookery",
@@ -1,121 +0,0 @@
1
- import { getRelativeLocaleUrl } from 'astro:i18n';
2
- import type { AstroGlobal } from 'astro';
3
- import { cosyLogger } from '../cosy';
4
-
5
- // 默认语言
6
- export const DEFAULT_LANGUAGE = 'en';
7
-
8
- /**
9
- * 语言工具模块
10
- *
11
- * 提供语言相关的工具函数,用于多语言支持
12
- */
13
- export class LanguageUtil {
14
- static getRelativeLink(locale: string, astro: AstroGlobal): string {
15
- const debug = false;
16
- const currentLocale = astro.currentLocale;
17
- const originalPath = astro.originPathname;
18
- const result = getRelativeLocaleUrl(
19
- locale,
20
- originalPath.replaceAll('/' + currentLocale, '')
21
- );
22
-
23
- if (debug) {
24
- cosyLogger.debug(
25
- `getRelativeLink: locale=${locale}, currentPath=${originalPath}, currentLocale=${currentLocale}, result=${result}`
26
- );
27
- }
28
-
29
- return result;
30
- }
31
-
32
- static getLanguageName(code: string | undefined): string {
33
- switch (code) {
34
- case 'en':
35
- return 'English';
36
- case 'zh-cn':
37
- return '简体中文';
38
- case 'zh':
39
- return '中文';
40
- case undefined:
41
- default:
42
- return 'not known';
43
- }
44
- }
45
-
46
- /**
47
- * 获取当前语言
48
- * @param astro Astro全局对象
49
- * @returns 当前应使用的语言代码
50
- */
51
- static getCurrentLanguage(astro: AstroGlobal): string {
52
- // 尝试从Astro全局对象中获取语言
53
- const astroLang = astro.currentLocale;
54
- if (astroLang) {
55
- return astroLang;
56
- }
57
- // 尝试从URL中获取语言
58
- const urlLang = this.getLanguageFromURL(astro.url.pathname);
59
- if (urlLang) {
60
- return urlLang;
61
- }
62
-
63
- // 尝试从浏览器设置中获取语言
64
- const browserLang = this.getLanguageFromBrowser();
65
- if (browserLang) {
66
- return browserLang;
67
- }
68
-
69
- // 尝试从Astro全局对象中获取语言
70
- const preferredLocale = astro.preferredLocale;
71
- if (preferredLocale) {
72
- return preferredLocale;
73
- }
74
-
75
- // 如果无法检测,返回默认语言
76
- return DEFAULT_LANGUAGE;
77
- }
78
-
79
- /**
80
- * 从URL中提取语言代码
81
- * @param url 当前URL
82
- * @returns 从URL中提取的语言代码,如果无法提取则返回undefined
83
- */
84
- private static getLanguageFromURL(url: string): string | undefined {
85
- let currentUrl = url;
86
-
87
- if (currentUrl === undefined) {
88
- if (typeof window === 'undefined') return undefined;
89
- currentUrl = window.location.href;
90
- }
91
-
92
- // 尝试从路径中提取语言代码
93
- // 例如: /zh-cn/components/button
94
- const pathMatch = currentUrl.match(/^\/([\w-]+)\//);
95
- if (pathMatch) {
96
- return pathMatch[1];
97
- }
98
-
99
- // 尝试从查询参数中提取语言代码
100
- // 例如: ?lang=zh-cn
101
- const urlParams = new URLSearchParams(currentUrl.split('?')[1]);
102
- const langParam = urlParams.get('lang');
103
- if (langParam) {
104
- return langParam;
105
- }
106
-
107
- return undefined;
108
- }
109
-
110
- /**
111
- * 从浏览器设置中获取首选语言
112
- * @returns 从浏览器设置中获取的语言代码,如果无法获取则返回undefined
113
- */
114
- private static getLanguageFromBrowser(): string | undefined {
115
- if (typeof navigator === 'undefined') return undefined;
116
-
117
- // 获取浏览器语言
118
- const browserLang = navigator.language.toLowerCase();
119
- return browserLang;
120
- }
121
- }