+layout.svelte 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <script lang="ts">
  2. import { onMount } from 'svelte';
  3. import { isShowNavStore, isWideScreenStore } from '../../store';
  4. import Menu from '$lib/menu/Menu.svelte';
  5. import { page } from '$app/stores';
  6. import type { MenuListChild } from '../../data/menuList.js';
  7. import { goto } from '$app/navigation';
  8. let { children } = $props();
  9. const isZh = localStorage.getItem('lang') === 'zh_CN';
  10. type menuListChildsProps = { title: string; title_en: string; nav: string; doc?: string };
  11. type menuListProps = { class: string; class_en: string; childs: menuListChildsProps[] };
  12. const menuList: menuListProps[] = [
  13. {
  14. class: '常规',
  15. class_en: 'General',
  16. childs: [
  17. { title: '快速上手', title_en: 'Quick start', nav: 'quick-start', doc: 'quickStart' },
  18. { title: '主题配置', title_en: 'Theme', nav: 'theme', doc: 'theme' },
  19. { title: '图标', title_en: 'Icon', nav: 'icon', doc: 'icon' },
  20. {
  21. title: '国际化',
  22. title_en: 'Internationalization',
  23. nav: 'internation',
  24. doc: 'internation'
  25. },
  26. { title: '更新日志', title_en: 'Changelog', nav: 'changelog', doc: 'changelog' },
  27. { title: '常见问题', title_en: 'FAQ', nav: 'faq', doc: 'faq' },
  28. {
  29. title: '贡献指南',
  30. title_en: 'Contribution Guide',
  31. nav: 'contribution',
  32. doc: 'contribution'
  33. },
  34. { title: '兼容性', title_en: 'Compatibility', nav: 'compatibility', doc: 'compatibility' }
  35. ]
  36. },
  37. {
  38. class: '设计',
  39. class_en: 'Design',
  40. childs: [
  41. { title: '色彩', title_en: 'Color', nav: 'color' },
  42. { title: 'LOGO', title_en: 'LOGO', nav: 'logo' }
  43. ]
  44. },
  45. {
  46. class: '工具',
  47. class_en: 'Tools',
  48. childs: [
  49. { title: '主题生成器', title_en: 'Theme generator', nav: 'generator' },
  50. { title: 'IDE 插件', title_en: 'IDE plugin', nav: 'vscode', doc: 'vscode' },
  51. { title: '脚手架', title_en: 'Create cli', nav: 'create' },
  52. { title: '图标插件', title_en: 'Icon plugin', nav: 'icon-plugin' },
  53. { title: 'MD 插件', title_en: 'MD plugin', nav: 'md' },
  54. { title: '快捷键', title_en: 'Shortcut key', nav: 'shortkey' }
  55. ]
  56. },
  57. {
  58. class: '其他',
  59. class_en: 'Other',
  60. childs: [
  61. { title: '关于', title_en: 'About', nav: 'about', doc: 'about' },
  62. { title: '里程碑', title_en: 'Milestone', nav: 'milestone', doc: 'milestone' },
  63. { title: '计划', title_en: 'Future', nav: 'future', doc: 'future' }
  64. ]
  65. }
  66. ];
  67. //扁平 menuList
  68. const flatMenuList: menuListChildsProps[] = [];
  69. for (let e = 0; e < menuList.length; e++) {
  70. flatMenuList.push(...menuList[e].childs);
  71. }
  72. let currentNav = $state(menuList[0].childs[0]);
  73. let menuHeight = $state(0);
  74. const getMenuHeightFun = () => {
  75. menuHeight = document.documentElement.clientHeight - 56;
  76. };
  77. const menuClickFun = (currentMenu: MenuListChild) => {
  78. if ($isShowNavStore) {
  79. isShowNavStore.set(false);
  80. }
  81. currentNav = currentMenu;
  82. // 将当前点击的 currentMenu 设置 url 参数
  83. // window.location.href = '/guide?nav=' + currentMenu.nav;
  84. goto(`/guide${currentMenu.nav === 'quick-start' ? '' : `/${currentMenu.nav}`}`);
  85. };
  86. onMount(() => {
  87. menuHeight = document.documentElement.clientHeight - 56;
  88. window.addEventListener('resize', getMenuHeightFun);
  89. // 根据 $page.url.pathname 获取 currentNav
  90. const urlNav = flatMenuList.find((item) => ($page.url.pathname.includes(item.nav) ? item : null));
  91. currentNav = urlNav || flatMenuList[0];
  92. return () => {
  93. window.removeEventListener('resize', getMenuHeightFun);
  94. };
  95. });
  96. // 全屏
  97. const changeFullFunc = () => {
  98. if ($isWideScreenStore) {
  99. isWideScreenStore.set(false);
  100. localStorage.setItem('isFull', 'notFull');
  101. } else {
  102. isWideScreenStore.set(true);
  103. localStorage.setItem('isFull', 'full');
  104. }
  105. };
  106. // 编辑地址处理
  107. const editUrlFn = (nav: string) => {
  108. const baseUrl = 'https://github.com/any-tdf/stdf/edit/main/';
  109. if (nav === 'create') {
  110. return baseUrl + 'packages/create-stdf/README' + (isZh ? '_CN' : '') + '.md';
  111. }
  112. if (nav === 'icon-plugin') {
  113. return baseUrl + 'packages/rollup-plugin-stdf-icon/README' + (isZh ? '_CN' : '') + '.md';
  114. }
  115. return baseUrl + `docs/mds/guide/${flatMenuList.filter((item) => item.nav === nav)[0]?.doc}${isZh ? '' : '_en'}.md`;
  116. };
  117. </script>
  118. <div class="flex">
  119. <div
  120. class="fixed -left-52 top-14 z-[100] w-48 overflow-y-scroll border-r border-black/10 bg-white transition-all duration-300 md:left-0 md:bg-transparent dark:border-white/20 dark:bg-black dark:md:bg-transparent"
  121. class:left-0={$isShowNavStore}
  122. class:-left-52={!$isShowNavStore}
  123. style="height:{menuHeight + 'px'}"
  124. >
  125. <Menu {menuList} currentNav={currentNav.nav} onclickMenu={menuClickFun} showNum={false} />
  126. </div>
  127. <div class="w-screen md:pl-48">
  128. {#if !$page.url.pathname.includes('generator')}
  129. <div class="px-4 py-12 md:px-8 md:py-4">
  130. <div class="text-4xl font-bold">
  131. {isZh ? currentNav.title : currentNav.title_en}
  132. </div>
  133. </div>
  134. <div class="h-px bg-black/10 dark:bg-white/20"></div>
  135. {/if}
  136. <div class="px-4 pt-4 {$page.url.pathname.includes('generator') ? 'md:px-4 md:pt-4' : 'md:px-8 md:pt-12'}">
  137. {@render children()}
  138. </div>
  139. {#if !$page.url.pathname.includes('generator') && currentNav.nav != 'color' && currentNav.nav != 'logo' && currentNav.nav != 'shortkey'}
  140. <div class="flex gap-2 px-4 pb-8 text-xs md:px-8">
  141. <a href={editUrlFn(currentNav.nav)} class="text-primary dark:text-dark flex w-full" target="_blank">
  142. <span class="mr-1 h-4 w-4">
  143. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" class="h-4 w-4" style="fill: currentColor;">
  144. <path
  145. d="M12.8995 6.85431L17.1421 11.0969L7.24264 20.9964H3V16.7538L12.8995 6.85431ZM14.3137 5.44009L16.435 3.31877C16.8256 2.92825 17.4587 2.92825 17.8492 3.31877L20.6777 6.1472C21.0682 6.53772 21.0682 7.17089 20.6777 7.56141L18.5563 9.68273L14.3137 5.44009Z"
  146. />
  147. </svg>
  148. </span>
  149. {isZh ? '在 GitHub 上编辑' : 'Edit on GitHub'}
  150. </a>
  151. </div>
  152. {/if}
  153. </div>
  154. </div>
  155. {#if !$page.url.pathname.includes('generator')}
  156. <button
  157. class="bg-primary shadow-primary/50 dark:bg-dark dark:shadow-dark/50 fixed bottom-4 right-2 z-50 hidden h-8 w-8 rounded-full p-1.5 text-white shadow-md md:block dark:text-black"
  158. onclick={changeFullFunc}
  159. >
  160. {#if $isWideScreenStore}
  161. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"
  162. ><path
  163. d="M20 3C20.5523 3 21 3.44772 21 4V20C21 20.5523 20.5523 21 20 21H4C3.44772 21 3 20.5523 3 20V4C3 3.44772 3.44772 3 4 3H20ZM11 5H5V19H11V15H13V19H19V5H13V9H11V5ZM15 9L18 12L15 15V13H9V15L6 12L9 9V11H15V9Z"
  164. fill="currentColor"
  165. ></path></svg
  166. >
  167. {:else}
  168. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"
  169. ><path
  170. d="M20 3C20.5523 3 21 3.44772 21 4V20C21 20.5523 20.5523 21 20 21H4C3.44772 21 3 20.5523 3 20V4C3 3.44772 3.44772 3 4 3H20ZM11 5H5V10.999H7V9L10 12L7 15V13H5V19H11V17H13V19H19V13H17V15L14 12L17 9V10.999H19V5H13V7H11V5ZM13 13V15H11V13H13ZM13 9V11H11V9H13Z"
  171. fill="currentColor"
  172. ></path></svg
  173. >
  174. {/if}
  175. </button>
  176. {/if}
  177. <!-- 为 code-groups 预先编译 tailwind -->
  178. <div
  179. class="peer-checked/tab-0-0:border-primary peer-checked/tab-0-1:border-primary peer-checked/tab-0-2:border-primary peer-checked/tab-0-3:border-primary peer-checked/tab-0-4:border-primary peer-checked/tab-0-5:border-primary
  180. peer-checked/tab-1-0:border-primary peer-checked/tab-1-1:border-primary peer-checked/tab-1-2:border-primary
  181. peer-checked/tab-1-3:border-primary peer-checked/tab-1-4:border-primary peer-checked/tab-1-5:border-primary
  182. peer-checked/tab-2-0:border-primary peer-checked/tab-2-1:border-primary peer-checked/tab-2-2:border-primary
  183. peer-checked/tab-2-3:border-primary peer-checked/tab-2-4:border-primary peer-checked/tab-2-5:border-primary
  184. peer-checked/tab-3-0:border-primary peer-checked/tab-3-1:border-primary peer-checked/tab-3-2:border-primary
  185. peer-checked/tab-3-3:border-primary peer-checked/tab-3-4:border-primary peer-checked/tab-3-5:border-primary
  186. peer-checked/tab-4-0:border-primary peer-checked/tab-4-1:border-primary peer-checked/tab-4-2:border-primary
  187. peer-checked/tab-4-3:border-primary peer-checked/tab-4-4:border-primary peer-checked/tab-4-5:border-primary
  188. dark:peer-checked/tab-0-0:border-dark dark:peer-checked/tab-0-1:border-dark dark:peer-checked/tab-0-2:border-dark
  189. dark:peer-checked/tab-0-3:border-dark dark:peer-checked/tab-0-4:border-dark dark:peer-checked/tab-0-5:border-dark
  190. dark:peer-checked/tab-1-0:border-dark dark:peer-checked/tab-1-1:border-dark dark:peer-checked/tab-1-2:border-dark
  191. dark:peer-checked/tab-1-3:border-dark dark:peer-checked/tab-1-4:border-dark dark:peer-checked/tab-1-5:border-dark
  192. dark:peer-checked/tab-2-0:border-dark dark:peer-checked/tab-2-1:border-dark dark:peer-checked/tab-2-2:border-dark
  193. dark:peer-checked/tab-2-3:border-dark dark:peer-checked/tab-2-4:border-dark dark:peer-checked/tab-2-5:border-dark
  194. dark:peer-checked/tab-3-0:border-dark dark:peer-checked/tab-3-1:border-dark dark:peer-checked/tab-3-2:border-dark
  195. dark:peer-checked/tab-3-3:border-dark dark:peer-checked/tab-3-4:border-dark dark:peer-checked/tab-3-5:border-dark
  196. dark:peer-checked/tab-4-0:border-dark dark:peer-checked/tab-4-1:border-dark dark:peer-checked/tab-4-2:border-dark
  197. dark:peer-checked/tab-4-3:border-dark dark:peer-checked/tab-4-4:border-dark dark:peer-checked/tab-4-5:border-dark
  198. hidden border-b-2 border-black/10 peer-checked/tab-0-0:block
  199. peer-checked/tab-0-1:block peer-checked/tab-0-2:block peer-checked/tab-0-3:block
  200. peer-checked/tab-0-4:block peer-checked/tab-0-5:block peer-checked/tab-1-0:block
  201. peer-checked/tab-1-1:block peer-checked/tab-1-2:block peer-checked/tab-1-3:block
  202. peer-checked/tab-1-4:block peer-checked/tab-1-5:block peer-checked/tab-2-0:block
  203. peer-checked/tab-2-1:block peer-checked/tab-2-2:block peer-checked/tab-2-3:block
  204. peer-checked/tab-2-4:block peer-checked/tab-2-5:block peer-checked/tab-3-0:block
  205. peer-checked/tab-3-1:block peer-checked/tab-3-2:block peer-checked/tab-3-3:block
  206. peer-checked/tab-3-4:block peer-checked/tab-3-5:block peer-checked/tab-4-0:block
  207. peer-checked/tab-4-1:block peer-checked/tab-4-2:block peer-checked/tab-4-3:block
  208. peer-checked/tab-4-4:block peer-checked/tab-4-5:block dark:border-white/10 dark:bg-[#202020]"
  209. ></div>