ui-svelte 0.2.16 → 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 CHANGED
@@ -1,4 +1,7 @@
1
1
  @layer base {
2
+ html {
3
+ scroll-behavior: smooth;
4
+ }
2
5
  body {
3
6
  @apply h-dvh flex flex-col relative;
4
7
  @apply bg-background text-on-background;
@@ -20,6 +20,7 @@
20
20
  | 'surface'
21
21
  | 'background';
22
22
  variant?: 'solid' | 'soft' | 'ghost';
23
+ id?: string;
23
24
  isBoxed?: boolean;
24
25
  };
25
26
 
@@ -32,6 +33,7 @@
32
33
  color = 'background',
33
34
  variant = 'solid',
34
35
  children,
36
+ id,
35
37
  isBoxed
36
38
  }: Props = $props();
37
39
 
@@ -54,7 +56,7 @@
54
56
  };
55
57
  </script>
56
58
 
57
- <section class={cn('section', variants[variant], colors[color], rootClass)}>
59
+ <section {id} class={cn('section', variants[variant], colors[color], rootClass)}>
58
60
  {#if cover}
59
61
  <img src={cover} alt="cover" class={cn('section-cover', coverClass)} />
60
62
  <div class={cn('section-overlay', overlayClass)}></div>
@@ -8,6 +8,7 @@ type Props = {
8
8
  cover?: string;
9
9
  color?: 'primary' | 'secondary' | 'muted' | 'success' | 'info' | 'warning' | 'danger' | 'surface' | 'background';
10
10
  variant?: 'solid' | 'soft' | 'ghost';
11
+ id?: string;
11
12
  isBoxed?: boolean;
12
13
  };
13
14
  declare const Section: import("svelte").Component<Props, {}, "">;
@@ -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
- return () => stopEventListeners();
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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ui-svelte",
3
- "version": "0.2.16",
3
+ "version": "0.2.18",
4
4
  "author": {
5
5
  "name": "SappsDev",
6
6
  "email": "info@sappsdev.com"