@coffic/cosy-ui 0.6.24 → 0.6.28

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.
Files changed (124) hide show
  1. package/README.md +5 -1
  2. package/dist/{components/base → alert}/Alert.astro +2 -2
  3. package/dist/alert/AlertBasic.astro +5 -0
  4. package/dist/alert/AlertCustomStyle.astro +7 -0
  5. package/dist/alert/AlertTypes.astro +13 -0
  6. package/dist/alert/AlertWithTitle.astro +5 -0
  7. package/dist/alert/index.ts +20 -0
  8. package/dist/app.css +1 -1
  9. package/dist/{components/typography → article}/Article.astro +2 -2
  10. package/dist/article/ArticleBasic.astro +31 -0
  11. package/dist/article/index.ts +11 -0
  12. package/dist/{components/base → button}/Button.astro +1 -2
  13. package/dist/button/ButtonBasic.astro +18 -0
  14. package/dist/button/ButtonShapes.astro +23 -0
  15. package/dist/button/ButtonSizes.astro +15 -0
  16. package/dist/button/ButtonStates.astro +12 -0
  17. package/dist/button/ButtonWithIcons.astro +25 -0
  18. package/dist/button/index.ts +23 -0
  19. package/dist/components/containers/Main.astro +1 -2
  20. package/dist/components/data-display/ProductCard.astro +2 -1
  21. package/dist/components/data-display/TeamMember.astro +2 -1
  22. package/dist/components/data-display/TeamMembers.astro +2 -1
  23. package/dist/components/display/Hero.astro +1 -1
  24. package/dist/components/display/Modal.astro +1 -1
  25. package/dist/{components/errors → errors}/404.astro +1 -1
  26. package/dist/errors/404Basic.astro +5 -0
  27. package/dist/errors/index.ts +11 -0
  28. package/dist/flex/FlexBasic.astro +9 -0
  29. package/dist/flex/index.ts +11 -0
  30. package/dist/{components/layouts → footer}/Footer.astro +8 -8
  31. package/dist/footer/FooterBasic.astro +12 -0
  32. package/dist/footer/FooterSection.astro +46 -0
  33. package/dist/footer/index.ts +11 -0
  34. package/dist/{components/layouts → grid}/Grid.astro +1 -1
  35. package/dist/grid/GridBasic.astro +9 -0
  36. package/dist/grid/index.ts +11 -0
  37. package/dist/{components/layouts → header}/Header.astro +14 -51
  38. package/dist/header/HeaderBasic.astro +14 -0
  39. package/dist/header/HeaderCustomNavbarEnd.astro +20 -0
  40. package/dist/header/HeaderCustomPosition.astro +23 -0
  41. package/dist/header/HeaderWithNavigation.astro +22 -0
  42. package/dist/header/index.ts +20 -0
  43. package/dist/{components/typography → heading}/Heading.astro +2 -2
  44. package/dist/heading/HeadingBasic.astro +10 -0
  45. package/dist/heading/index.ts +11 -0
  46. package/dist/{components/base → image}/Image.astro +9 -7
  47. package/dist/image/ImageBasic.astro +1 -0
  48. package/dist/image/ImageEffects.astro +32 -0
  49. package/dist/image/ImageLoading.astro +35 -0
  50. package/dist/image/index.ts +17 -0
  51. package/dist/index.ts +2 -95
  52. package/dist/index_astro.ts +78 -0
  53. package/dist/index_utils.ts +8 -0
  54. package/dist/{components/navigation → language-switcher}/LanguageSwitcher.astro +3 -3
  55. package/dist/language-switcher/LanguageSwitcherBasic.astro +7 -0
  56. package/dist/language-switcher/index.ts +11 -0
  57. package/dist/{components/layouts → layout-app}/AppLayout.astro +10 -4
  58. package/dist/layout-app/AppLayoutBasic.astro +53 -0
  59. package/dist/layout-app/index.ts +11 -0
  60. package/dist/{components/layouts → layout-basic}/BaseLayout.astro +2 -2
  61. package/dist/layout-basic/BaseLayoutBasic.astro +16 -0
  62. package/dist/layout-basic/index.ts +11 -0
  63. package/dist/{components/layouts → layout-dashboard}/DashboardLayout.astro +2 -2
  64. package/dist/layout-dashboard/DashboardLayoutBasic.astro +48 -0
  65. package/dist/layout-dashboard/index.ts +11 -0
  66. package/dist/{components/base → link}/Link.astro +1 -1
  67. package/dist/link/LinkAnimations.astro +21 -0
  68. package/dist/link/LinkBasic.astro +17 -0
  69. package/dist/link/LinkVariants.astro +20 -0
  70. package/dist/link/index.ts +17 -0
  71. package/dist/module/Module.astro +61 -0
  72. package/dist/module/ModuleBasic.astro +12 -0
  73. package/dist/module/ModuleCustom.astro +14 -0
  74. package/dist/module/ModuleGrid.astro +26 -0
  75. package/dist/module/index.ts +17 -0
  76. package/dist/{components/layouts → nav-item}/NavItems.astro +2 -3
  77. package/dist/nav-item/NavItemsBasic.astro +27 -0
  78. package/dist/nav-item/index.ts +11 -0
  79. package/dist/nav-section/NavSection.astro +42 -0
  80. package/dist/nav-section/NavSectionBasic.astro +12 -0
  81. package/dist/nav-section/index.ts +11 -0
  82. package/dist/{components/layouts → sidebar}/Sidebar.astro +5 -6
  83. package/dist/sidebar/SidebarBasic.astro +1 -0
  84. package/dist/sidebar/index.ts +11 -0
  85. package/dist/{components/layouts → sidebar-nav}/SidebarNav.astro +3 -3
  86. package/dist/sidebar-nav/SidebarNavBasic.astro +32 -0
  87. package/dist/sidebar-nav/index.ts +11 -0
  88. package/dist/speak/Speak.astro +65 -0
  89. package/dist/speak/SpeakBasic.astro +13 -0
  90. package/dist/speak/SpeakGrid.astro +29 -0
  91. package/dist/speak/index.ts +14 -0
  92. package/dist/{components/layouts → stack}/Stack.astro +1 -1
  93. package/dist/stack/StackBasic.astro +15 -0
  94. package/dist/stack/index.ts +11 -0
  95. package/dist/{components/typography → text}/Text.astro +1 -1
  96. package/dist/text/TextBasic.astro +12 -0
  97. package/dist/text/TextSizes.astro +11 -0
  98. package/dist/text/index.ts +11 -0
  99. package/dist/theme-item/ThemeItem.astro +45 -0
  100. package/dist/theme-item/ThemeItemBasic.astro +10 -0
  101. package/dist/theme-item/index.ts +11 -0
  102. package/dist/{components/navigation → theme-switcher}/ThemeSwitcher.astro +4 -4
  103. package/dist/theme-switcher/ThemeSwitcherBasic.astro +7 -0
  104. package/dist/theme-switcher/index.ts +11 -0
  105. package/dist/{components/navigation → toc}/TableOfContents.astro +3 -3
  106. package/dist/toc/TableOfContentsBasic.astro +25 -0
  107. package/dist/toc/index.ts +11 -0
  108. package/dist/types/image.ts +16 -0
  109. package/dist/types/menu.ts +24 -0
  110. package/dist/utils/component.ts +39 -0
  111. package/dist/vue/AlertDialog/index.ts +3 -41
  112. package/dist/vue/BannerBox/index.ts +9 -44
  113. package/dist/vue/BlogList/index.ts +5 -27
  114. package/dist/vue/Buttons/index.ts +5 -27
  115. package/dist/vue/ConfirmDialog/index.ts +3 -41
  116. package/dist/vue/MacWindow/index.ts +7 -21
  117. package/dist/vue/SmartHero/index.ts +4 -26
  118. package/dist/vue/iPhone/index.ts +5 -18
  119. package/package.json +7 -7
  120. package/dist/components/base/Module.astro +0 -18
  121. package/dist/components/base/Speak.astro +0 -22
  122. package/dist/components/base/ThemeItem.astro +0 -21
  123. package/dist/components/layouts/NavSection.astro +0 -32
  124. /package/dist/{components/layouts → flex}/Flex.astro +0 -0
@@ -0,0 +1,11 @@
1
+ import ThemeItem from './ThemeItem.astro';
2
+ import ThemeItemBasic from './ThemeItemBasic.astro';
3
+ import BasicSourceCode from './ThemeItemBasic.astro?raw';
4
+ import { extractSimpleExample } from '../utils/component';
5
+
6
+ export { ThemeItem, ThemeItemBasic };
7
+
8
+ // 导出示例源代码
9
+ export const ThemeItemExampleCodes = {
10
+ Basic: extractSimpleExample(BasicSourceCode, 'ThemeItem'),
11
+ };
@@ -25,9 +25,9 @@
25
25
  * ```
26
26
  */
27
27
 
28
- import Button from '../base/Button.astro';
29
- import SunCloudyIcon from '../../icons/SunCloudyIcon.astro';
30
- import '../../style.ts';
28
+ import Button from '../button/Button.astro';
29
+ import SunCloudyIcon from '../icons/SunCloudyIcon.astro';
30
+ import '../style.ts';
31
31
 
32
32
  interface Props {
33
33
  /**
@@ -75,7 +75,7 @@ const themes = [
75
75
  </div>
76
76
 
77
77
  <script>
78
- import { createThemeManager } from '../../utils/theme';
78
+ import { createThemeManager } from '../utils/theme';
79
79
 
80
80
  const themeManager = createThemeManager();
81
81
 
@@ -0,0 +1,7 @@
1
+ ---
2
+ import ThemeSwitcher from './ThemeSwitcher.astro';
3
+ ---
4
+
5
+ <div class="cosy:flex cosy:justify-center">
6
+ <ThemeSwitcher />
7
+ </div>
@@ -0,0 +1,11 @@
1
+ import ThemeSwitcher from './ThemeSwitcher.astro';
2
+ import ThemeSwitcherBasic from './ThemeSwitcherBasic.astro';
3
+ import BasicSourceCode from './ThemeSwitcherBasic.astro?raw';
4
+ import { extractSimpleExample } from '../utils/component';
5
+
6
+ export { ThemeSwitcher, ThemeSwitcherBasic };
7
+
8
+ // 导出示例源代码
9
+ export const ThemeSwitcherExampleCodes = {
10
+ Basic: extractSimpleExample(BasicSourceCode, 'ThemeSwitcher'),
11
+ };
@@ -53,9 +53,9 @@
53
53
  */
54
54
 
55
55
  // 导入样式
56
- import '../../style.ts';
57
- import { createTextGetter } from '../../utils/i18n';
58
- import { LanguageUtil } from '../../utils/language';
56
+ import '../style.ts';
57
+ import { createTextGetter } from '../utils/i18n';
58
+ import { LanguageUtil } from '../utils/language';
59
59
 
60
60
  interface Props {
61
61
  /**
@@ -0,0 +1,25 @@
1
+ ---
2
+ import TableOfContents from './TableOfContents.astro';
3
+ ---
4
+
5
+ <div class="cosy:flex cosy:gap-4">
6
+ <div class="cosy:w-64">
7
+ <TableOfContents />
8
+ </div>
9
+ <div class="cosy:flex-1">
10
+ <h2 id="introduction">介绍</h2>
11
+ <p>这是一个示例内容。</p>
12
+
13
+ <h2 id="features">功能特点</h2>
14
+ <p>这里列出了主要功能。</p>
15
+
16
+ <h3 id="feature-1">功能 1</h3>
17
+ <p>功能 1 的详细说明。</p>
18
+
19
+ <h3 id="feature-2">功能 2</h3>
20
+ <p>功能 2 的详细说明。</p>
21
+
22
+ <h2 id="conclusion">总结</h2>
23
+ <p>这是总结部分。</p>
24
+ </div>
25
+ </div>
@@ -0,0 +1,11 @@
1
+ import TableOfContents from './TableOfContents.astro';
2
+ import TableOfContentsBasic from './TableOfContentsBasic.astro';
3
+ import BasicSourceCode from './TableOfContentsBasic.astro?raw';
4
+ import { extractSimpleExample } from '../utils/component';
5
+
6
+ export { TableOfContents, TableOfContentsBasic };
7
+
8
+ // 导出示例源代码
9
+ export const TableOfContentsExampleCodes = {
10
+ Basic: extractSimpleExample(BasicSourceCode, 'TableOfContents'),
11
+ };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * 图片元数据接口
3
+ * 用于统一管理项目中的图片元数据类型
4
+ */
5
+ export interface ImageMetadata {
6
+ src: string;
7
+ width: number;
8
+ height: number;
9
+ format: string;
10
+ }
11
+
12
+ /**
13
+ * 图片源类型
14
+ * 可以是 ImageMetadata 对象或字符串 URL
15
+ */
16
+ export type ImageSource = ImageMetadata | string;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * 菜单项接口
3
+ */
4
+ export interface IMenuItem {
5
+ /**
6
+ * 菜单项文本
7
+ */
8
+ text: string;
9
+
10
+ /**
11
+ * 菜单项链接
12
+ */
13
+ href: string;
14
+
15
+ /**
16
+ * 菜单项图标
17
+ */
18
+ icon: string;
19
+
20
+ /**
21
+ * 子菜单项
22
+ */
23
+ items?: IMenuItem[];
24
+ }
@@ -0,0 +1,39 @@
1
+ // 提取简单示例源代码函数
2
+ export function extractSimpleExample(source: string, name: string): string {
3
+ // 提取模板部分
4
+ const templateMatch = source.match(/<template>([\s\S]*)<\/template>/m);
5
+ const scriptMatch = source.match(/<script[\s\S]*?>([\s\S]*)<\/script>/m);
6
+
7
+ if (!templateMatch) {
8
+ return source;
9
+ }
10
+
11
+ let importSection = `<script setup lang="ts">
12
+ import { ref } from 'vue'
13
+ import { ${name} } from '@cosy/index_vue'
14
+ `;
15
+
16
+ // 从源码中提取导入语句(除了组件的导入和app.css)
17
+ if (scriptMatch && scriptMatch[1]) {
18
+ const importLines = scriptMatch[1]
19
+ .split('\n')
20
+ .filter(
21
+ (line) => line.includes('import') && !line.includes('../../app.css') && !line.includes(name)
22
+ );
23
+
24
+ if (importLines.length > 0) {
25
+ importSection += importLines.join('\n') + '\n';
26
+ }
27
+ }
28
+
29
+ importSection += '</script>\n\n';
30
+
31
+ // 提取模板内容,并替换组件路径
32
+ const templateContent = templateMatch[1]
33
+ .replace(`./${name}.vue`, name)
34
+ .replace(`../${name}.vue`, name)
35
+ .replace(`./${name}.astro`, name)
36
+ .replace(`../${name}.astro`, name);
37
+
38
+ return importSection + '<template>' + templateContent + '</template>';
39
+ }
@@ -2,45 +2,7 @@ import Basic from './Basic.vue';
2
2
  import Multilang from './Multilang.vue';
3
3
  import BasicSource from './Basic.vue?raw';
4
4
  import MultilangSource from './Multilang.vue?raw';
5
-
6
- // 提取简单示例源代码函数
7
- function extractSimpleExample(source: string): string {
8
- // 提取模板部分
9
- const templateMatch = source.match(/<template>([\s\S]*)<\/template>/m);
10
- const scriptMatch = source.match(/<script[\s\S]*?>([\s\S]*)<\/script>/m);
11
-
12
- if (!templateMatch) {
13
- return source;
14
- }
15
-
16
- let importSection = `<script setup lang="ts">
17
- import { ref } from 'vue'
18
- import { AlertDialog } from '@cosy/index_vue'
19
- `;
20
-
21
- // 从源码中提取导入语句(除了组件的导入和app.css)
22
- if (scriptMatch && scriptMatch[1]) {
23
- const importLines = scriptMatch[1]
24
- .split('\n')
25
- .filter(
26
- (line) =>
27
- line.includes('import') &&
28
- !line.includes('../../app.css') &&
29
- !line.includes('AlertDialog')
30
- );
31
-
32
- if (importLines.length > 0) {
33
- importSection += importLines.join('\n') + '\n';
34
- }
35
- }
36
-
37
- importSection += '</script>\n\n';
38
-
39
- // 提取模板内容,并替换组件路径
40
- const templateContent = templateMatch[1].replace('../AlertDialog.vue', 'AlertDialog');
41
-
42
- return importSection + '<template>' + templateContent + '</template>';
43
- }
5
+ import { extractSimpleExample } from '../../utils/component';
44
6
 
45
7
  // 导出主组件
46
8
  export { default as AlertDialog } from './AlertDialog.vue';
@@ -53,6 +15,6 @@ export const AlertDialogExamples = {
53
15
 
54
16
  // 导出示例源代码
55
17
  export const AlertDialogExampleCodes = {
56
- Basic: extractSimpleExample(BasicSource),
57
- Multilang: extractSimpleExample(MultilangSource),
18
+ Basic: extractSimpleExample(BasicSource, 'Basic'),
19
+ Multilang: extractSimpleExample(MultilangSource, 'Multilang'),
58
20
  };
@@ -14,42 +14,7 @@ import DisplayModeNeverSource from './ExampleDisplayModeNever.vue?raw';
14
14
  import SmartBannerSource from './SmartBanner.vue?raw';
15
15
  import SizePresetSource from './ExampleSizePreset.vue?raw';
16
16
  import ImageExportSource from './ExampleImageExport.vue?raw';
17
-
18
- // 提取简单示例源代码函数
19
- function extractSimpleExample(source: string): string {
20
- // 提取模板部分
21
- const templateMatch = source.match(/<template>([\s\S]*)<\/template>/m);
22
- const scriptMatch = source.match(/<script[\s\S]*?>([\s\S]*)<\/script>/m);
23
-
24
- if (!templateMatch) {
25
- return source;
26
- }
27
-
28
- let importSection = `<script setup>
29
- import { BannerBox } from 'cosy-ui'
30
- `;
31
-
32
- // 从源码中提取导入语句(除了组件的导入和app.css)
33
- if (scriptMatch && scriptMatch[1]) {
34
- const importLines = scriptMatch[1]
35
- .split('\n')
36
- .filter(
37
- (line) =>
38
- line.includes('import') && !line.includes('../../app.css') && !line.includes('BannerBox')
39
- );
40
-
41
- if (importLines.length > 0) {
42
- importSection += importLines.join('\n') + '\n';
43
- }
44
- }
45
-
46
- importSection += '</script>\n\n';
47
-
48
- // 提取模板内容,并替换组件路径
49
- const templateContent = templateMatch[1].replace('../BannerBox.vue', 'BannerBox');
50
-
51
- return importSection + '<template>' + templateContent + '</template>';
52
- }
17
+ import { extractSimpleExample } from '../../utils/component';
53
18
 
54
19
  // 获取 BannerBox 和 FeatureCard 组件
55
20
  export { default as BannerBox } from './BannerBox.vue';
@@ -72,12 +37,12 @@ export const BannerBoxExamples = {
72
37
 
73
38
  // 导出示例源代码
74
39
  export const BannerBoxExampleCodes = {
75
- Basic: extractSimpleExample(BasicSource),
76
- CustomBg: extractSimpleExample(CustomBgSource),
77
- DisplayModeAlways: extractSimpleExample(DisplayModeAlwaysSource),
78
- DisplayModeHover: extractSimpleExample(DisplayModeHoverSource),
79
- DisplayModeNever: extractSimpleExample(DisplayModeNeverSource),
80
- SmartBanner: extractSimpleExample(SmartBannerSource),
81
- SizePreset: extractSimpleExample(SizePresetSource),
82
- ImageExport: extractSimpleExample(ImageExportSource),
40
+ Basic: extractSimpleExample(BasicSource, 'BannerBox'),
41
+ CustomBg: extractSimpleExample(CustomBgSource, 'BannerBox'),
42
+ DisplayModeAlways: extractSimpleExample(DisplayModeAlwaysSource, 'BannerBox'),
43
+ DisplayModeHover: extractSimpleExample(DisplayModeHoverSource, 'BannerBox'),
44
+ DisplayModeNever: extractSimpleExample(DisplayModeNeverSource, 'BannerBox'),
45
+ SmartBanner: extractSimpleExample(SmartBannerSource, 'BannerBox'),
46
+ SizePreset: extractSimpleExample(SizePresetSource, 'BannerBox'),
47
+ ImageExport: extractSimpleExample(ImageExportSource, 'BannerBox'),
83
48
  };
@@ -6,29 +6,7 @@ import BasicSource from './Basic.vue?raw';
6
6
  import EmptySource from './Empty.vue?raw';
7
7
  import EnglishSource from './English.vue?raw';
8
8
  import EmptyEnglishSource from './EmptyEnglish.vue?raw';
9
-
10
- // 转换Vue SFC组件为简化的示例代码(只保留template和setup script)
11
- function extractSimpleExample(source: string): string {
12
- // 提取模板部分
13
- const templateMatch = source.match(/<template>([\s\S]*?)<\/template>/);
14
- const template = templateMatch ? templateMatch[1].trim() : '';
15
-
16
- // 提取script setup部分(去除import部分)
17
- const scriptMatch = source.match(/<script setup lang="ts">([\s\S]*?)<\/script>/);
18
- let script = '';
19
- if (scriptMatch) {
20
- // 只保留相关变量定义,去除导入语句
21
- script = scriptMatch[1]
22
- .replace(/import [^;]+;/g, '')
23
- .replace(/import BlogList from '[^']+';/g, "import { BlogList } from 'cosy-ui';")
24
- .trim();
25
- }
26
-
27
- // 创建简化版本的代码
28
- return `<template>${template}</template>
29
-
30
- <script setup lang="ts">${script}</script>`;
31
- }
9
+ import { extractSimpleExample } from '../../utils/component';
32
10
 
33
11
  // 导出主组件
34
12
  export { default as BlogList } from './BlogList.vue';
@@ -44,8 +22,8 @@ export const BlogListExamples = {
44
22
 
45
23
  // 导出示例组件的源代码(简化版本)
46
24
  export const BlogListExampleCodes = {
47
- Basic: extractSimpleExample(BasicSource),
48
- Empty: extractSimpleExample(EmptySource),
49
- English: extractSimpleExample(EnglishSource),
50
- EmptyEnglish: extractSimpleExample(EmptyEnglishSource),
25
+ Basic: extractSimpleExample(BasicSource, 'BlogList'),
26
+ Empty: extractSimpleExample(EmptySource, 'BlogList'),
27
+ English: extractSimpleExample(EnglishSource, 'BlogList'),
28
+ EmptyEnglish: extractSimpleExample(EmptyEnglishSource, 'BlogList'),
51
29
  };
@@ -6,29 +6,7 @@ import FeatureBasicSource from './FeatureBasic.vue?raw';
6
6
  import FeatureWithTipsSource from './FeatureWithTips.vue?raw';
7
7
  import MultipleSource from './Multiple.vue?raw';
8
8
  import LinkBasicSource from './LinkBasic.vue?raw';
9
-
10
- // 转换Vue SFC组件为简化的示例代码(只保留template和setup script)
11
- function extractSimpleExample(source: string): string {
12
- // 提取模板部分
13
- const templateMatch = source.match(/<template>([\s\S]*?)<\/template>/);
14
- const template = templateMatch ? templateMatch[1].trim() : '';
15
-
16
- // 提取script setup部分(去除import部分)
17
- const scriptMatch = source.match(/<script setup lang="ts">([\s\S]*?)<\/script>/);
18
- let script = '';
19
- if (scriptMatch) {
20
- // 只保留相关变量定义,去除导入语句
21
- script = scriptMatch[1]
22
- .replace(/import [^;]+;/g, '')
23
- .replace(/import (FeatureButton|LinkButton) from '[^']+';/g, "import { $1 } from 'cosy-ui';")
24
- .trim();
25
- }
26
-
27
- // 创建简化版本的代码
28
- return `<template>${template}</template>
29
-
30
- <script setup lang="ts">${script}</script>`;
31
- }
9
+ import { extractSimpleExample } from '../../utils/component';
32
10
 
33
11
  // 导出组件
34
12
  export { default as FeatureButton } from './FeatureButton.vue';
@@ -49,11 +27,11 @@ export const ButtonsExamples = {
49
27
  // 导出示例组件的源代码(简化版本)
50
28
  export const ButtonsExampleCodes = {
51
29
  FeatureButton: {
52
- Basic: extractSimpleExample(FeatureBasicSource),
53
- WithTips: extractSimpleExample(FeatureWithTipsSource),
30
+ Basic: extractSimpleExample(FeatureBasicSource, 'Button'),
31
+ WithTips: extractSimpleExample(FeatureWithTipsSource, 'Button'),
54
32
  },
55
33
  LinkButton: {
56
- Basic: extractSimpleExample(LinkBasicSource),
57
- Multiple: extractSimpleExample(MultipleSource),
34
+ Basic: extractSimpleExample(LinkBasicSource, 'Button'),
35
+ Multiple: extractSimpleExample(MultipleSource, 'Button'),
58
36
  },
59
37
  };
@@ -2,45 +2,7 @@ import Basic from './Basic.vue';
2
2
  import CustomButtons from './CustomButtons.vue';
3
3
  import BasicSource from './Basic.vue?raw';
4
4
  import CustomButtonsSource from './CustomButtons.vue?raw';
5
-
6
- // 提取简单示例源代码函数
7
- function extractSimpleExample(source: string): string {
8
- // 提取模板部分
9
- const templateMatch = source.match(/<template>([\s\S]*)<\/template>/m);
10
- const scriptMatch = source.match(/<script[\s\S]*?>([\s\S]*)<\/script>/m);
11
-
12
- if (!templateMatch) {
13
- return source;
14
- }
15
-
16
- let importSection = `<script setup lang="ts">
17
- import { ref } from 'vue'
18
- import { ConfirmDialog } from '@cosy/index_vue'
19
- `;
20
-
21
- // 从源码中提取导入语句(除了组件的导入和app.css)
22
- if (scriptMatch && scriptMatch[1]) {
23
- const importLines = scriptMatch[1]
24
- .split('\n')
25
- .filter(
26
- (line) =>
27
- line.includes('import') &&
28
- !line.includes('../../app.css') &&
29
- !line.includes('ConfirmDialog')
30
- );
31
-
32
- if (importLines.length > 0) {
33
- importSection += importLines.join('\n') + '\n';
34
- }
35
- }
36
-
37
- importSection += '</script>\n\n';
38
-
39
- // 提取模板内容,并替换组件路径
40
- const templateContent = templateMatch[1].replace('../ConfirmDialog.vue', 'ConfirmDialog');
41
-
42
- return importSection + '<template>' + templateContent + '</template>';
43
- }
5
+ import { extractSimpleExample } from '../../utils/component';
44
6
 
45
7
  // 导出主组件
46
8
  export { default as ConfirmDialog } from './ConfirmDialog.vue';
@@ -53,6 +15,6 @@ export const ConfirmDialogExamples = {
53
15
 
54
16
  // 导出示例源代码
55
17
  export const ConfirmDialogExampleCodes = {
56
- Basic: extractSimpleExample(BasicSource),
57
- CustomButtons: extractSimpleExample(CustomButtonsSource),
18
+ Basic: extractSimpleExample(BasicSource, 'ConfirmDialog'),
19
+ CustomButtons: extractSimpleExample(CustomButtonsSource, 'ConfirmDialog'),
58
20
  };
@@ -10,21 +10,7 @@ import WithEventsSource from './WithEvents.vue?raw';
10
10
  import WithToolbarSource from './WithToolbar.vue?raw';
11
11
  import WithSidebarSource from './WithSidebar.vue?raw';
12
12
  import CustomHeightSource from './CustomHeight.vue?raw';
13
-
14
- // 转换Vue SFC组件为简化的示例代码(只保留template和setup script)
15
- function extractSimpleExample(source: string): string {
16
- // 提取模板部分
17
- const templateMatch = source.match(/<template>([\s\S]*?)<\/template>/);
18
- const template = templateMatch ? templateMatch[1].trim() : '';
19
-
20
- // 创建简化版本的代码
21
- return `<template>${template}</template>
22
-
23
- <script setup>
24
- import { MacWindow } from 'cosy-ui';
25
- import { SearchIcon, SettingsIcon, InfoIcon } from 'cosy-ui/icons';
26
- </script>`;
27
- }
13
+ import { extractSimpleExample } from '../../utils/component';
28
14
 
29
15
  // 导出主组件
30
16
  export { default as MacWindow } from './MacWindow.vue';
@@ -41,10 +27,10 @@ export const MacWindowExamples = {
41
27
 
42
28
  // 导出示例组件的源代码(简化版本)
43
29
  export const MacWindowExampleCodes = {
44
- Basic: extractSimpleExample(BasicSource),
45
- WithTabs: extractSimpleExample(WithTabsSource),
46
- WithEvents: extractSimpleExample(WithEventsSource),
47
- WithToolbar: extractSimpleExample(WithToolbarSource),
48
- WithSidebar: extractSimpleExample(WithSidebarSource),
49
- CustomHeight: extractSimpleExample(CustomHeightSource),
30
+ Basic: extractSimpleExample(BasicSource, 'MacWindow'),
31
+ WithTabs: extractSimpleExample(WithTabsSource, 'MacWindow'),
32
+ WithEvents: extractSimpleExample(WithEventsSource, 'MacWindow'),
33
+ WithToolbar: extractSimpleExample(WithToolbarSource, 'MacWindow'),
34
+ WithSidebar: extractSimpleExample(WithSidebarSource, 'MacWindow'),
35
+ CustomHeight: extractSimpleExample(CustomHeightSource, 'MacWindow'),
50
36
  };
@@ -4,29 +4,7 @@ import WithCustomContent from './WithCustomContent.vue';
4
4
  import BasicSource from './Basic.vue?raw';
5
5
  import WithImageSource from './WithImage.vue?raw';
6
6
  import WithCustomContentSource from './WithCustomContent.vue?raw';
7
-
8
- // 转换Vue SFC组件为简化的示例代码(只保留template和setup script)
9
- function extractSimpleExample(source: string): string {
10
- // 提取模板部分
11
- const templateMatch = source.match(/<template>([\s\S]*?)<\/template>/);
12
- const template = templateMatch ? templateMatch[1].trim() : '';
13
-
14
- // 提取script setup部分(去除import部分)
15
- const scriptMatch = source.match(/<script setup lang="ts">([\s\S]*?)<\/script>/);
16
- let script = '';
17
- if (scriptMatch) {
18
- // 只保留相关变量定义,去除导入语句
19
- script = scriptMatch[1]
20
- .replace(/import [^;]+;/g, '')
21
- .replace(/import SmartHero from '[^']+';/g, "import { SmartHero } from 'cosy-ui';")
22
- .trim();
23
- }
24
-
25
- // 创建简化版本的代码
26
- return `<template>${template}</template>
27
-
28
- <script setup lang="ts">${script}</script>`;
29
- }
7
+ import { extractSimpleExample } from '../../utils/component';
30
8
 
31
9
  // 导出主组件
32
10
  export { default as SmartHero } from './SmartHero.vue';
@@ -40,7 +18,7 @@ export const SmartHeroExamples = {
40
18
 
41
19
  // 导出示例组件的源代码(简化版本)
42
20
  export const SmartHeroExampleCodes = {
43
- Basic: extractSimpleExample(BasicSource),
44
- WithImage: extractSimpleExample(WithImageSource),
45
- WithCustomContent: extractSimpleExample(WithCustomContentSource),
21
+ Basic: extractSimpleExample(BasicSource, 'SmartHero'),
22
+ WithImage: extractSimpleExample(WithImageSource, 'SmartHero'),
23
+ WithCustomContent: extractSimpleExample(WithCustomContentSource, 'SmartHero'),
46
24
  };
@@ -6,20 +6,7 @@ import BasicSource from './Basic.vue?raw';
6
6
  import NoFrameSource from './NoFrame.vue?raw';
7
7
  import CustomBackgroundSource from './CustomBackground.vue?raw';
8
8
  import WeatherAppSource from './WeatherApp.vue?raw';
9
-
10
- // 转换Vue SFC组件为简化的示例代码(只保留template和setup script)
11
- function extractSimpleExample(source: string): string {
12
- // 提取模板部分
13
- const templateMatch = source.match(/<template>([\s\S]*?)<\/template>/);
14
- const template = templateMatch ? templateMatch[1].trim() : '';
15
-
16
- // 创建简化版本的代码
17
- return `<template>${template}</template>
18
-
19
- <script setup>
20
- import { iPhoneWindow } from 'cosy-ui';
21
- </script>`;
22
- }
9
+ import { extractSimpleExample } from '../../utils/component';
23
10
 
24
11
  // 导出主组件
25
12
  export { default as iPhoneWindow } from './iPhoneWindow.vue';
@@ -34,8 +21,8 @@ export const iPhoneWindowExamples = {
34
21
 
35
22
  // 导出示例组件的源代码(简化版本)
36
23
  export const iPhoneWindowExampleCodes = {
37
- Basic: extractSimpleExample(BasicSource),
38
- NoFrame: extractSimpleExample(NoFrameSource),
39
- CustomBackground: extractSimpleExample(CustomBackgroundSource),
40
- WeatherApp: extractSimpleExample(WeatherAppSource),
24
+ Basic: extractSimpleExample(BasicSource, 'iPhoneWindow'),
25
+ NoFrame: extractSimpleExample(NoFrameSource, 'iPhoneWindow'),
26
+ CustomBackground: extractSimpleExample(CustomBackgroundSource, 'iPhoneWindow'),
27
+ WeatherApp: extractSimpleExample(WeatherAppSource, 'iPhoneWindow'),
41
28
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coffic/cosy-ui",
3
- "version": "0.6.24",
3
+ "version": "0.6.28",
4
4
  "description": "An astro component library",
5
5
  "author": {
6
6
  "name": "nookery",
@@ -58,20 +58,20 @@
58
58
  "@astrojs/mdx": "^4.2.6",
59
59
  "@astrojs/ts-plugin": "^1.10.4",
60
60
  "@astrojs/vue": "^5.0.13",
61
- "@eslint/js": "^9.26.0",
61
+ "@eslint/js": "^9.27.0",
62
62
  "@tailwindcss/typography": "^0.5.16",
63
- "@tailwindcss/vite": "^4.1.6",
63
+ "@tailwindcss/vite": "^4.1.7",
64
64
  "@types/chai": "^5.2.2",
65
65
  "@types/eslint": "^9.6.1",
66
66
  "@types/fs-extra": "^11.0.4",
67
67
  "@types/mocha": "^10.0.10",
68
- "@types/node": "^22.15.18",
68
+ "@types/node": "^22.15.19",
69
69
  "@types/react": "^19.1.4",
70
70
  "@typescript-eslint/parser": "^8.32.1",
71
71
  "astro": "^5.7.13",
72
72
  "chai": "^4.5.0",
73
73
  "daisyui": "^5.0.35",
74
- "eslint": "^9.26.0",
74
+ "eslint": "^9.27.0",
75
75
  "eslint-plugin-astro": "^1.3.1",
76
76
  "globals": "^16.1.0",
77
77
  "mocha": "^10.8.2",
@@ -79,12 +79,12 @@
79
79
  "prettier-plugin-astro": "^0.14.1",
80
80
  "rollup-plugin-copy": "^3.5.0",
81
81
  "sharp": "^0.33.5",
82
- "tailwindcss": "^4.1.6",
82
+ "tailwindcss": "^4.1.7",
83
83
  "tsx": "^4.19.4",
84
84
  "typescript": "^5.8.3",
85
85
  "typescript-eslint": "^8.32.1",
86
86
  "vite": "^6.3.5",
87
- "vue": "^3.5.13",
87
+ "vue": "^3.5.14",
88
88
  "vue-eslint-parser": "^10.1.3"
89
89
  }
90
90
  }
@@ -1,18 +0,0 @@
1
- ---
2
- import { Image } from 'astro:assets';
3
- import type { ImageMetadata } from 'astro';
4
-
5
- interface Props {
6
- title: string;
7
- description: string;
8
- image: ImageMetadata;
9
- }
10
-
11
- const { title, description, image } = Astro.props;
12
- ---
13
-
14
- <div class="flex flex-col items-center gap-4">
15
- <Image src={image} alt={title} class="w-48 h-48 object-contain" />
16
- <h3 class="text-xl font-semibold">{title}</h3>
17
- <p class="text-gray-600">{description}</p>
18
- </div>