generated from ryanatkn/fuz_template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTome_Section.svelte
46 lines (38 loc) · 1.13 KB
/
Tome_Section.svelte
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
<script lang="ts" module>
export type Register_Section_Header = (slug: string) => void;
export const register_section_header_context = create_context<Register_Section_Header>();
</script>
<script lang="ts">
import type {Snippet} from 'svelte';
import type {SvelteHTMLElements} from 'svelte/elements';
import {DEV} from 'esm-env';
import {create_context} from '$lib/context_helpers.js';
import {intersect} from '$lib/intersect.js';
import {library_links_context} from '$lib/library_helpers.svelte.js';
interface Props {
attrs?: SvelteHTMLElements['section'];
children: Snippet;
}
const {attrs, children}: Props = $props();
const library_links = library_links_context.get();
let slug: string;
register_section_header_context.set((s) => {
slug = s;
});
</script>
<section
{...attrs}
use:intersect={({intersecting}) => {
if (!slug) {
if (DEV) console.error('Tome_Section_Header must be a child of Tome_Section'); // eslint-disable-line no-console
return;
}
if (intersecting) {
library_links.slugs_onscreen.add(slug);
} else {
library_links.slugs_onscreen.delete(slug);
}
}}
>
{@render children()}
</section>