Guide.svelte 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <script lang="ts">
  2. import { onMount } from 'svelte';
  3. import { mdTextToHljs } from './../../utils/index';
  4. import { themeStore, sysThemeStore, isWideScreenStore } from '../../store';
  5. interface Props {
  6. guide?: string;
  7. }
  8. let { guide = 'button' }: Props = $props();
  9. const isZh = localStorage.getItem('lang') === 'zh_CN';
  10. let loading = $state(true);
  11. let theme = $derived($themeStore === 'auto' ? ($sysThemeStore === 'dark' ? 'dark' : 'light') : $themeStore);
  12. const getMdStrFunc = async (nav: string) => {
  13. loading = true;
  14. const rawObj = await import(`../../../../mds/components/${nav}/guide${isZh ? '' : '_en'}.md`);
  15. const mdStr = rawObj.default;
  16. loading = false;
  17. return mdTextToHljs(
  18. mdStr
  19. .replace(/<img src="/g, `<img class="w-full md:w-1/2${theme === 'dark' ? ' invert' : ''}" src="./assets/images/guide/`)
  20. .replace(/<a href="/g, '<a target="_blank" href="')
  21. );
  22. };
  23. let guideText: string | null = $state(null);
  24. onMount(async () => {
  25. guideText = await getMdStrFunc(guide);
  26. });
  27. // 全屏
  28. const changeFullFunc = () => {
  29. if ($isWideScreenStore) {
  30. isWideScreenStore.set(false);
  31. localStorage.setItem('isFull', 'notFull');
  32. } else {
  33. isWideScreenStore.set(true);
  34. localStorage.setItem('isFull', 'full');
  35. }
  36. };
  37. </script>
  38. <article
  39. class="prose dark:prose-invert prose-strong:text-primary dark:prose-strong:text-dark pb-12 {$isWideScreenStore
  40. ? 'max-w-full'
  41. : 'max-w-5xl'}"
  42. >
  43. {#if loading}
  44. {isZh ? '请等待...' : 'Please wait...'}
  45. {:else}
  46. {@html guideText}
  47. {/if}
  48. </article>
  49. <div class="flex gap-2 pb-8 text-xs">
  50. <a
  51. href={'https://github.com/any-tdf/stdf/edit/main/docs/mds/components/' + guide + '/guide' + (isZh ? '' : '_en') + '.md'}
  52. target="_blank"
  53. class="text-primary dark:text-dark flex"
  54. >
  55. <span class="mr-1 h-4 w-4">
  56. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" class="h-4 w-4" style="fill: currentColor;">
  57. <path
  58. 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"
  59. />
  60. </svg>
  61. </span>
  62. {isZh ? '在 GitHub 上编辑' : 'Edit on GitHub'}
  63. </a>
  64. </div>
  65. <button
  66. 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"
  67. onclick={changeFullFunc}
  68. >
  69. {#if $isWideScreenStore}
  70. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"
  71. ><path
  72. 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"
  73. fill="currentColor"
  74. ></path></svg
  75. >
  76. {:else}
  77. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"
  78. ><path
  79. 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"
  80. fill="currentColor"
  81. ></path></svg
  82. >
  83. {/if}
  84. </button>