|
2 | 2 | import {onMount, onDestroy} from 'svelte'; |
3 | 3 | import {currentPage} from '../store'; |
4 | 4 | import {wikis} from '../config'; |
| 5 | + import {fade, fly} from 'svelte/transition'; |
| 6 | + import Scroll from '../assets/scroll.svg?raw'; |
| 7 | + import Close from '../assets/close.svg?raw'; |
5 | 8 | import gsap from 'gsap'; |
6 | 9 |
|
7 | 10 | let visible = true; |
|
46 | 49 | } |
47 | 50 |
|
48 | 51 | onMount(() => { |
| 52 | + document.addEventListener('click', handleClick); |
49 | 53 | setTimeout(scroll, 50); |
| 54 | + return () => { |
| 55 | + document.removeEventListener('click', handleClick); |
| 56 | + }; |
50 | 57 | }); |
51 | | -
|
52 | 58 | onDestroy(() => { |
53 | 59 | if (ticker) ticker.kill(); |
54 | 60 | }); |
| 61 | +
|
| 62 | + function handleClick(event: MouseEvent) { |
| 63 | + const isTextInteraction = window.getSelection()?.toString(); |
| 64 | + if (showModal && (event.target as HTMLElement).closest('#wiki-modal') && !isTextInteraction) { |
| 65 | + showModal = false; |
| 66 | + } |
| 67 | + } |
55 | 68 | </script> |
56 | 69 |
|
57 | 70 | {#if visible && wikiText} |
58 | | - <div class="fixed top-0 left-0 w-full bg-white/70 backdrop-blur-sm shadow-xs z-10 h-8 flex items-center"> |
| 71 | + <div |
| 72 | + class="fixed top-0 left-0 w-full text-[var(--textColor)] bg-white/70 backdrop-blur-sm shadow-xs z-10 h-8 flex items-center" |
| 73 | + > |
| 74 | + <button |
| 75 | + class="pl-1 w-9 cursor-pointer" |
| 76 | + on:click={() => (showModal = true)} |
| 77 | + > |
| 78 | + {@html Scroll} |
| 79 | + </button> |
59 | 80 | <div class="relative overflow-hidden flex-1 h-full"> |
60 | 81 | <div |
61 | 82 | bind:this={textEl} |
62 | | - class="absolute whitespace-nowrap text-sm lg:text-base will-change-transform text-[var(--textColor)] top-0 left-24 h-full flex items-center" |
| 83 | + class="absolute whitespace-nowrap text-sm lg:text-base will-change-transform top-0 left-12 h-full flex items-center" |
63 | 84 | > |
64 | 85 | {#each Array(2) as _} |
65 | 86 | {#each lines as line} |
|
69 | 90 | {/each} |
70 | 91 | </div> |
71 | 92 | </div> |
| 93 | + <button |
| 94 | + class="pr-1 w-8 cursor-pointer" |
| 95 | + on:click={() => (visible = false)} |
| 96 | + > |
| 97 | + {@html Close} |
| 98 | + </button> |
72 | 99 | </div> |
73 | 100 | {/if} |
74 | | - |
75 | 101 | {#if showModal} |
76 | | - <div class="fixed inset-0 bg-black/50 flex items-center justify-center z-50"> |
77 | | - <div class="bg-white rounded-lg shadow-lg max-w-lg w-full p-6"> |
78 | | - <div class="text-lg font-semibold mb-4">Wiki</div> |
79 | | - <pre class="whitespace-pre-wrap text-sm text-gray-700">{wikiText}</pre> |
80 | | - <div class="mt-4 text-right"> |
81 | | - <button |
82 | | - class="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600" |
83 | | - on:click={() => (showModal = false)} |
84 | | - > |
85 | | - close |
86 | | - </button> |
| 102 | + <div |
| 103 | + class="fixed inset-0 bg-black/60 flex items-center justify-center z-50 backdrop-blur-lg" |
| 104 | + id="wiki-modal" |
| 105 | + transition:fade={{duration: 150}} |
| 106 | + > |
| 107 | + <div |
| 108 | + class="rounded-lg px-4 md:px-20 text-[var(--textColor)] text-center overflow-y-auto py-6 max-h-[90vh]" |
| 109 | + transition:fly={{y: 20, duration: 300}} |
| 110 | + > |
| 111 | + <div class="space-y-4 text-2xl lg:text-4xl leading-9 md:leading-14 font-sans italic"> |
| 112 | + {#each lines as line} |
| 113 | + <p>{line}</p> |
| 114 | + {/each} |
87 | 115 | </div> |
88 | 116 | </div> |
89 | 117 | </div> |
|
0 commit comments