This repository was archived by the owner on Sep 2, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 332
Expand file tree
/
Copy pathMain.svelte
More file actions
223 lines (203 loc) · 5.53 KB
/
Copy pathMain.svelte
File metadata and controls
223 lines (203 loc) · 5.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<script lang="ts" context="module">
import { writable } from 'svelte/store';
export type NavLink = {
label: string;
href: string;
};
export const isHeaderHidden = writable(false);
export const isMobileNavOpen = writable(false);
</script>
<script lang="ts">
import { browser } from '$app/environment';
import { MobileNav } from '$lib/components';
import { isVisible } from '$lib/utils/isVisible';
import { createScrollInfo } from '$lib/utils/scroll';
import { addEventListener } from '@melt-ui/svelte/internal/helpers';
import { onMount } from 'svelte';
let theme: 'light' | 'dark' | null = 'dark';
function setupThemeObserver() {
const handleVisibility = () => {
theme = getVisibleTheme();
};
const observer = new MutationObserver(handleVisibility);
observer.observe(document.body, { childList: true, subtree: true });
const callbacks = [
addEventListener(window, 'scroll', handleVisibility),
addEventListener(window, 'resize', handleVisibility)
];
return () => {
observer.disconnect();
callbacks.forEach((callback) => callback());
};
}
function isInViewport(element: Element): boolean {
return isVisible(element, {
top: 32,
bottom: 32,
left: 0,
right: window.innerWidth
});
}
function getVisibleTheme() {
const themes = Array.from(document.querySelectorAll('.theme-dark, .theme-light')).filter(
(element) => {
const { classList, dataset } = element as HTMLElement;
if (
classList.contains('aw-mobile-header') ||
classList.contains('aw-main-header') ||
element === document.body ||
typeof dataset['themeIgnore'] === 'string'
) {
return false;
}
return true;
}
);
for (const theme of themes) {
if (isInViewport(theme)) {
return theme.classList.contains('theme-light') ? 'light' : 'dark';
}
}
return 'dark';
}
onMount(() => {
return setupThemeObserver();
});
let navLinks: NavLink[] = [
{
label: 'Docs',
href: '/docs'
},
{
label: 'Community',
href: '/community'
},
{
label: 'Blog',
href: '/blog'
},
{
label: 'Pricing',
href: '/pricing'
}
];
$: resolvedTheme = $isMobileNavOpen ? 'dark' : theme;
const scrollInfo = createScrollInfo();
$: $isHeaderHidden = (() => {
if ($scrollInfo.top < 250) {
return false;
}
if ($scrollInfo.direction === 'down') {
return true;
}
return $scrollInfo.deltaDirChange < 200;
})();
</script>
<div class="u-position-relative">
<section
class="aw-mobile-header theme-{resolvedTheme}"
class:is-transparent={browser && !$isMobileNavOpen}
class:is-hidden={$isHeaderHidden}
>
<div class="aw-mobile-header-start">
<a href="/">
<img
class="aw-logo aw-u-only-dark"
src="/images/logos/appwrite.svg"
alt="appwrite"
width="130"
/>
<img
class="aw-logo aw-u-only-light"
src="/images/logos/appwrite-light.svg"
alt="appwrite"
width="130"
/>
</a>
</div>
<div class="aw-mobile-header-end">
{#if !$isMobileNavOpen}
<a href="https://cloud.appwrite.io" class="aw-button">
<span class="text">Get started</span>
</a>
{/if}
<button
class="aw-button is-text"
aria-label="open navigation"
on:click={() => ($isMobileNavOpen = !$isMobileNavOpen)}
>
{#if $isMobileNavOpen}
<span aria-hidden="true" class="aw-icon-close" />
{:else}
<span aria-hidden="true" class="aw-icon-hamburger-menu" />
{/if}
</button>
</div>
</section>
<header
class="aw-main-header theme-{resolvedTheme}"
class:is-transparent={browser}
class:is-hidden={$isHeaderHidden}
>
<!-- <div class="aw-top-banner">
<div class="aw-top-banner-content aw-u-color-text-primary">
<span class="aw-caption-500">We are having lots of fun on</span>
<span class="aw-icon-discord" aria-hidden="true" />
<span class="aw-caption-500">Discord. Come and join us!</span>
<button class="aw-top-banner-button" aria-label="close discord message">
<span class="aw-icon-close" aria-hidden="true" />
</button>
</div>
</div> -->
<div class="aw-container" style="--container-size:103rem">
<div class="aw-main-header-wrapper">
<div class="aw-main-header-row">
<div class="aw-main-header-start">
<a href="/">
<img
class="aw-logo aw-u-only-dark"
src="/images/logos/appwrite.svg"
alt="appwrite"
width="130"
/>
<img
class="aw-logo aw-u-only-light"
src="/images/logos/appwrite-light.svg"
alt="appwrite"
width="130"
/>
</a>
<nav class="aw-main-header-nav">
<ul class="aw-main-header-nav-list">
{#each navLinks as { label, href }}
<li class="aw-main-header-nav-item">
<a class="aw-main-header-nav-link" {href}>{label}</a>
</li>
{/each}
</ul>
</nav>
</div>
<div class="aw-main-header-end">
<a
href="https://github.com/appwrite/appwrite/stargazers"
target="_blank"
class="aw-button is-text"
>
<span aria-hidden="true" class="aw-icon-star" />
<span class="text">Star on GitHub</span>
<span class="aw-inline-tag aw-sub-body-400">33.2K</span>
</a>
<a href="https://cloud.appwrite.io/register" class="aw-button is-secondary">Sign up</a>
<a href="https://cloud.appwrite.io" class="aw-button">
<span class="text">Get started</span>
</a>
</div>
</div>
</div>
</div>
</header>
<MobileNav bind:open={$isMobileNavOpen} links={navLinks} />
<main class="aw-main-section" class:aw-u-hide-mobile={$isMobileNavOpen}>
<slot />
</main>
</div>