ui-svelte 0.2.17 → 0.2.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/css/base.css +3 -0
- package/dist/navigation/NavMenu.svelte +39 -1
- package/package.json +1 -1
package/dist/css/base.css
CHANGED
|
@@ -48,6 +48,8 @@
|
|
|
48
48
|
let openSubmenuIndex = $state<number | null>(null);
|
|
49
49
|
let triggerElements = $state<Record<number, HTMLElement>>({});
|
|
50
50
|
let popoverElement = $state<HTMLElement>();
|
|
51
|
+
let activeHash = $state<string | null>(null);
|
|
52
|
+
let sectionObserver: IntersectionObserver | null = null;
|
|
51
53
|
let position = $state({
|
|
52
54
|
top: 0,
|
|
53
55
|
left: 0,
|
|
@@ -84,6 +86,11 @@
|
|
|
84
86
|
|
|
85
87
|
function isItemActive(href?: string): boolean {
|
|
86
88
|
if (!href) return false;
|
|
89
|
+
|
|
90
|
+
if (href.startsWith('#')) {
|
|
91
|
+
return activeHash === href;
|
|
92
|
+
}
|
|
93
|
+
|
|
87
94
|
return page.url.pathname === href || page.url.pathname.startsWith(href + '/');
|
|
88
95
|
}
|
|
89
96
|
|
|
@@ -191,7 +198,38 @@
|
|
|
191
198
|
}
|
|
192
199
|
|
|
193
200
|
onMount(() => {
|
|
194
|
-
|
|
201
|
+
const hashLinks = items
|
|
202
|
+
.flatMap((item) => [item.href, ...(item.subitems?.map((s) => s.href) || [])])
|
|
203
|
+
.filter((href): href is string => !!href && href.startsWith('#'))
|
|
204
|
+
.map((href) => href.slice(1));
|
|
205
|
+
|
|
206
|
+
if (hashLinks.length > 0) {
|
|
207
|
+
sectionObserver = new IntersectionObserver(
|
|
208
|
+
(entries) => {
|
|
209
|
+
const visibleEntries = entries.filter((e) => e.isIntersecting);
|
|
210
|
+
if (visibleEntries.length > 0) {
|
|
211
|
+
const mostVisible = visibleEntries.reduce((prev, curr) =>
|
|
212
|
+
curr.intersectionRatio > prev.intersectionRatio ? curr : prev
|
|
213
|
+
);
|
|
214
|
+
activeHash = '#' + mostVisible.target.id;
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
threshold: [0.1, 0.5, 0.9],
|
|
219
|
+
rootMargin: '-10% 0px -10% 0px'
|
|
220
|
+
}
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
hashLinks.forEach((id) => {
|
|
224
|
+
const el = document.getElementById(id);
|
|
225
|
+
if (el) sectionObserver!.observe(el);
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return () => {
|
|
230
|
+
sectionObserver?.disconnect();
|
|
231
|
+
stopEventListeners();
|
|
232
|
+
};
|
|
195
233
|
});
|
|
196
234
|
</script>
|
|
197
235
|
|