igniteui-astro-components 0.0.27 → 0.0.28

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.
Files changed (93) hide show
  1. package/README.md +82 -74
  2. package/package.json +15 -2
  3. package/src/components/CopyCode/CopyCode.astro +21 -7
  4. package/src/components/DocsBreadcrumb/DocsBreadcrumb.astro +33 -21
  5. package/src/components/DocsBreadcrumb/DocsBreadcrumb.scss +44 -43
  6. package/src/components/DocsBreadcrumb/README.md +10 -14
  7. package/src/components/DocsSidebar/DocsSidebar.astro +47 -45
  8. package/src/components/DocsSidebar/DocsSidebar.scss +120 -122
  9. package/src/components/DocsSidebar/README.md +25 -21
  10. package/src/components/DocsSidebar/SidebarFilterInput.astro +24 -29
  11. package/src/components/DocsSidebar/SidebarFilterInput.scss +90 -89
  12. package/src/components/DocsSidebar/SidebarLabel.astro +35 -26
  13. package/src/components/DocsSidebar/sidebar-filter.ts +93 -56
  14. package/src/components/DocsSubHeader/DocsSubHeader.astro +256 -195
  15. package/src/components/DocsSubHeader/DocsSubHeader.scss +181 -178
  16. package/src/components/DocsSubHeader/README.md +18 -16
  17. package/src/components/DocsToc/DocsToc.astro +301 -280
  18. package/src/components/DocsToc/DocsToc.scss +20 -21
  19. package/src/components/DocsToc/README.md +11 -9
  20. package/src/components/DocsToc/toTreeNodes.ts +3 -8
  21. package/src/components/DocsTree/DocsTree.astro +32 -20
  22. package/src/components/DocsTree/DocsTreeItem.astro +35 -30
  23. package/src/components/DocsTree/README.md +16 -15
  24. package/src/components/DocsTree/docs-tree.scss +267 -268
  25. package/src/components/GlobalFooter/GlobalFooter.astro +10 -10
  26. package/src/components/GlobalFooter/README.md +3 -2
  27. package/src/components/GlobalNavBar/GlobalNavBar.astro +4 -2
  28. package/src/components/GlobalNavBar/GlobalNavBar.module.scss +222 -222
  29. package/src/components/GlobalNavBar/README.md +3 -2
  30. package/src/components/LicenseIndicator/LicenseIndicator.astro +7 -5
  31. package/src/components/LicenseIndicator/LicenseIndicator.scss +3 -3
  32. package/src/components/MobileSidebarToggle/MobileSidebarToggle.astro +16 -17
  33. package/src/components/MobileSidebarToggle/README.md +3 -2
  34. package/src/components/MobileTocToggle/MobileTocToggle.astro +75 -61
  35. package/src/components/MobileTocToggle/MobileTocToggle.scss +65 -59
  36. package/src/components/Search/README.md +1 -0
  37. package/src/components/Search/Search.astro +137 -109
  38. package/src/components/Search/Search.scss +20 -20
  39. package/src/components/SearchAdvanced/README.md +21 -15
  40. package/src/components/SearchAdvanced/SearchAdvanced.astro +205 -133
  41. package/src/components/SearchAdvanced/SearchAdvanced.scss +152 -153
  42. package/src/components/mdx/ApiLink/ApiLink.astro +133 -113
  43. package/src/components/mdx/ApiLink/ApiLink.scss +9 -9
  44. package/src/components/mdx/ApiLink/README.md +26 -22
  45. package/src/components/mdx/ApiLink/api-link-index.ts +196 -173
  46. package/src/components/mdx/ApiRef/ApiRef.astro +54 -51
  47. package/src/components/mdx/ApiRef/README.md +20 -15
  48. package/src/components/mdx/Badge/Badge.astro +14 -14
  49. package/src/components/mdx/Badge/Badge.scss +61 -56
  50. package/src/components/mdx/Badge/README.md +24 -19
  51. package/src/components/mdx/DocsAside/DocsAside.astro +30 -37
  52. package/src/components/mdx/DocsAside/DocsAside.scss +82 -82
  53. package/src/components/mdx/DocsAside/README.md +22 -22
  54. package/src/components/mdx/Faq/Faq.astro +86 -0
  55. package/src/components/mdx/Faq/Faq.scss +105 -0
  56. package/src/components/mdx/Faq/FaqItem.astro +117 -0
  57. package/src/components/mdx/Faq/README.md +223 -0
  58. package/src/components/mdx/Faq/types.ts +34 -0
  59. package/src/components/mdx/PlatformBlock/PlatformBlock.astro +3 -2
  60. package/src/components/mdx/PlatformBlock/README.md +6 -8
  61. package/src/components/mdx/Sample/README.md +21 -16
  62. package/src/components/mdx/Sample/Sample.astro +97 -74
  63. package/src/components/mdx/Sample/Sample.scss +132 -132
  64. package/src/content-helper.ts +71 -72
  65. package/src/content.config.ts +1 -6
  66. package/src/integration.ts +566 -512
  67. package/src/layouts/DocsLayout/DocsLayout.astro +228 -182
  68. package/src/layouts/DocsLayout/DocsLayout.scss +261 -261
  69. package/src/layouts/DocsLayout/README.md +24 -35
  70. package/src/lib/nav-helpers.ts +88 -82
  71. package/src/lib/types.ts +76 -76
  72. package/src/llms.ts +205 -166
  73. package/src/platform.ts +312 -162
  74. package/src/plugins/rehype-heading-anchors.ts +45 -45
  75. package/src/plugins/rehype-pagefind-ignore.ts +19 -19
  76. package/src/plugins/rehype-table-wrapper.ts +30 -30
  77. package/src/plugins/remark-docfx.ts +12 -0
  78. package/src/plugins/remark-env-vars.ts +12 -4
  79. package/src/plugins/remark-md-links.ts +10 -4
  80. package/src/scripts/icon-manifest.ts +13 -5
  81. package/src/scripts/sample-widget.ts +557 -501
  82. package/src/sidebar.ts +103 -97
  83. package/src/styles/global/_code-blocks.scss +43 -44
  84. package/src/styles/global/_component-themes.scss +151 -153
  85. package/src/styles/global/_icon-gallery.scss +81 -81
  86. package/src/styles/global/_index.scss +0 -1
  87. package/src/styles/global/_markdown.scss +816 -787
  88. package/src/styles/global/_palette.scss +456 -110
  89. package/src/styles/global/_search-shared.scss +402 -398
  90. package/src/styles/global/_type-scale.scss +127 -127
  91. package/src/styles/global/_variables.scss +138 -111
  92. package/src/styles/theme.scss +41 -41
  93. package/src/virtual-modules.d.ts +11 -2
@@ -15,312 +15,333 @@ import { headingsToTreeNodes, type TocConfig } from './toTreeNodes';
15
15
  import './DocsToc.scss';
16
16
 
17
17
  interface Props {
18
- headings?: MarkdownHeading[];
19
- tocConfig?: TocConfig;
20
- label?: string;
21
- offsetTarget?: string;
18
+ headings?: MarkdownHeading[];
19
+ tocConfig?: TocConfig;
20
+ label?: string;
21
+ offsetTarget?: string;
22
22
  }
23
23
 
24
- const {
25
- headings = [],
26
- tocConfig,
27
- label = 'On this page',
28
- offsetTarget,
29
- } = Astro.props;
24
+ const { headings = [], tocConfig, label = 'On this page', offsetTarget } = Astro.props;
30
25
 
31
26
  const nodes = headingsToTreeNodes(headings, tocConfig);
32
27
  ---
33
28
 
34
- {nodes.length > 0 && (
29
+ {
30
+ nodes.length > 0 && (
35
31
  <aside class="toc-wrapper" data-pagefind-ignore="all">
36
- <docs-toc class="toc-sidebar" data-offset-target={offsetTarget}>
37
- <h2 class="toc-sidebar__heading" id="toc-heading">{label}</h2>
38
- <nav aria-labelledby="toc-heading">
39
- <DocsTree nodes={nodes} variant="toc" />
40
- </nav>
41
- </docs-toc>
32
+ <docs-toc class="toc-sidebar" data-offset-target={offsetTarget}>
33
+ <h2 class="toc-sidebar__heading" id="toc-heading">
34
+ {label}
35
+ </h2>
36
+ <nav aria-labelledby="toc-heading">
37
+ <DocsTree nodes={nodes} variant="toc" />
38
+ </nav>
39
+ </docs-toc>
42
40
  </aside>
43
- )}
41
+ )
42
+ }
44
43
 
45
44
  <script>
46
- type ExpandableEl = HTMLElement & { expanded: boolean };
47
-
48
- class DocsToc extends HTMLElement {
49
- private static readonly DEFAULT_THRESHOLD = 160;
50
-
51
- private pageController: AbortController | undefined;
52
- private rafId: number | undefined;
53
- private initId = 0;
54
- private headings: HTMLElement[] = [];
55
- private links: HTMLAnchorElement[] = [];
56
- private currentLink: HTMLAnchorElement | undefined;
57
- private offsetEl: Element | null = null;
58
- private resizeObserver: ResizeObserver | undefined;
59
- private pinnedIndex: number | undefined;
60
-
61
- connectedCallback() {
62
- this.init();
63
- }
45
+ type ExpandableEl = HTMLElement & { expanded: boolean };
46
+
47
+ class DocsToc extends HTMLElement {
48
+ private static readonly DEFAULT_THRESHOLD = 160;
49
+
50
+ private pageController: AbortController | undefined;
51
+ private rafId: number | undefined;
52
+ private initId = 0;
53
+ private headings: HTMLElement[] = [];
54
+ private links: HTMLAnchorElement[] = [];
55
+ private currentLink: HTMLAnchorElement | undefined;
56
+ private offsetEl: Element | null = null;
57
+ private resizeObserver: ResizeObserver | undefined;
58
+ private pinnedIndex: number | undefined;
59
+
60
+ connectedCallback() {
61
+ this.init();
62
+ }
64
63
 
65
- disconnectedCallback() {
66
- this.teardown();
67
- }
64
+ disconnectedCallback() {
65
+ this.teardown();
66
+ }
68
67
 
69
- private teardown() {
70
- this.pageController?.abort();
71
- this.pageController = undefined;
72
- this.resizeObserver?.disconnect();
73
- this.resizeObserver = undefined;
74
- this.offsetEl = null;
75
- document.documentElement.style.removeProperty('--igd-toc-subheader-bottom');
76
- if (this.rafId !== undefined) {
77
- cancelAnimationFrame(this.rafId);
78
- this.rafId = undefined;
79
- }
80
- this.currentLink = undefined;
81
- this.pinnedIndex = undefined;
82
- }
68
+ private teardown() {
69
+ this.pageController?.abort();
70
+ this.pageController = undefined;
71
+ this.resizeObserver?.disconnect();
72
+ this.resizeObserver = undefined;
73
+ this.offsetEl = null;
74
+ document.documentElement.style.removeProperty('--igd-toc-subheader-bottom');
75
+ if (this.rafId !== undefined) {
76
+ cancelAnimationFrame(this.rafId);
77
+ this.rafId = undefined;
78
+ }
79
+ this.currentLink = undefined;
80
+ this.pinnedIndex = undefined;
81
+ }
83
82
 
84
- init() {
85
- this.teardown();
86
-
87
- // Invalidate any pending deferred _init from a previous call.
88
- const id = ++this.initId;
89
-
90
- // Wait for igc-tree to be defined before querying slotted links,
91
- // since the links live inside igc-tree-item light DOM and igc-tree
92
- // may not have upgraded yet when init() runs.
93
- customElements.whenDefined('igc-tree').then(() => requestAnimationFrame(() => {
94
- // Bail if init() was called again since we scheduled, or the
95
- // element was disconnected (e.g. a view transition swapped the DOM).
96
- if (this.initId !== id || !this.isConnected) return;
97
- this._init();
98
- }));
99
- }
83
+ init() {
84
+ this.teardown();
85
+
86
+ // Invalidate any pending deferred _init from a previous call.
87
+ const id = ++this.initId;
88
+
89
+ // Wait for igc-tree to be defined before querying slotted links,
90
+ // since the links live inside igc-tree-item light DOM and igc-tree
91
+ // may not have upgraded yet when init() runs.
92
+ customElements.whenDefined('igc-tree').then(() =>
93
+ requestAnimationFrame(() => {
94
+ // Bail if init() was called again since we scheduled, or the
95
+ // element was disconnected (e.g. a view transition swapped the DOM).
96
+ if (this.initId !== id || !this.isConnected) return;
97
+ this._init();
98
+ }),
99
+ );
100
+ }
100
101
 
101
- private _init() {
102
- // Clear any stale aria-current left over from a previous page.
103
- this.querySelectorAll('a[aria-current]').forEach(
104
- (a) => a.removeAttribute('aria-current'),
105
- );
106
- // Clear any stale selected / active state on tree items.
107
- this.querySelectorAll('igc-tree-item').forEach((item) => {
108
- const treeItem = item as HTMLElement & { selected: boolean; active: boolean };
109
- treeItem.selected = false;
110
- treeItem.active = false;
111
- });
112
-
113
- this.links = Array.from(this.querySelectorAll<HTMLAnchorElement>('a[href^="#"]'));
114
- this.headings = this.links
115
- .map((link) => document.getElementById(decodeURIComponent(link.hash.slice(1))))
116
- .filter((el): el is HTMLElement => el !== null);
117
-
118
- if (this.headings.length === 0) return;
119
-
120
- const schedule = () => {
121
- if (this.rafId !== undefined) return;
122
- this.rafId = requestAnimationFrame(() => {
123
- this.rafId = undefined;
124
- this.update();
125
- });
126
- };
127
-
128
- this.pageController = new AbortController();
129
- const opts = { passive: true, signal: this.pageController.signal };
130
-
131
- window.addEventListener('scroll', schedule, opts);
132
- window.addEventListener('resize', () => { this.syncScrollPadding(); schedule(); }, opts);
133
-
134
- // Any user-initiated scroll input releases the click pin so the
135
- // spy can take over again immediately.
136
- const releasePin = () => { this.pinnedIndex = undefined; };
137
- window.addEventListener('wheel', releasePin, opts);
138
- window.addEventListener('touchstart', releasePin, opts);
139
- window.addEventListener('keydown', releasePin, opts);
140
-
141
- // Browser back/forward navigation: release the pin and re-run the
142
- // spy so the active item reflects the restored scroll position.
143
- window.addEventListener('hashchange', () => {
144
- this.pinnedIndex = undefined;
145
- requestAnimationFrame(() => this.update());
146
- }, opts);
147
-
148
- // popstate covers back/forward cases that hashchange misses:
149
- // navigating to a URL with no hash, or the same hash as before.
150
- // Note: do NOT call scrollToHashIfNeeded() here — Chrome fires
151
- // popstate on anchor clicks too, which would override smooth scroll
152
- // with an instant jump. The browser handles scroll restoration on
153
- // back/forward automatically.
154
- window.addEventListener('popstate', () => {
155
- this.pinnedIndex = undefined;
156
- requestAnimationFrame(() => this.update());
157
- }, opts);
158
-
159
- this.addEventListener('click', (e) => {
160
- const target = (e.target as HTMLElement | null)?.closest('a[href^="#"]');
161
- if (!(target instanceof HTMLAnchorElement)) return;
162
- const idx = this.links.indexOf(target);
163
- if (idx === -1) return;
164
- this.pinnedIndex = idx;
165
- this.setActive(idx);
166
- }, { signal: this.pageController.signal });
167
-
168
- this.bindOffsetTarget();
169
-
170
- // Immediately highlight the first node so there is always a
171
- // visible active state, even before layout is fully settled.
172
- // this.setActive(0);
173
-
174
- this.update();
175
- // Safari: getBoundingClientRect() may not reflect final layout
176
- // during the first rAF (before first paint). Schedule one extra
177
- // update so the initial active item is always correct.
178
- // Also re-scroll to the hash now that syncScrollPadding has run
179
- // and scroll-padding-top reflects the true sticky header height.
180
- // Without this, a refresh with a #hash in the URL would scroll
181
- // before the CSS variable is set, landing the heading behind the header.
182
- requestAnimationFrame(() => {
183
- this.update();
184
- // Nest in a second rAF so igc-tree's internal scrollIntoView
185
- // (triggered by setActive → selected = true) settles first,
186
- // and our correction scroll wins.
187
- requestAnimationFrame(() => this.scrollToHashIfNeeded());
188
- });
189
- }
102
+ private _init() {
103
+ // Clear any stale aria-current left over from a previous page.
104
+ this.querySelectorAll('a[aria-current]').forEach((a) => a.removeAttribute('aria-current'));
105
+ // Clear any stale selected / active state on tree items.
106
+ this.querySelectorAll('igc-tree-item').forEach((item) => {
107
+ const treeItem = item as HTMLElement & { selected: boolean; active: boolean };
108
+ treeItem.selected = false;
109
+ treeItem.active = false;
110
+ });
111
+
112
+ this.links = Array.from(this.querySelectorAll<HTMLAnchorElement>('a[href^="#"]'));
113
+ this.headings = this.links
114
+ .map((link) => document.getElementById(decodeURIComponent(link.hash.slice(1))))
115
+ .filter((el): el is HTMLElement => el !== null);
116
+
117
+ if (this.headings.length === 0) return;
118
+
119
+ const schedule = () => {
120
+ if (this.rafId !== undefined) return;
121
+ this.rafId = requestAnimationFrame(() => {
122
+ this.rafId = undefined;
123
+ this.update();
124
+ });
125
+ };
126
+
127
+ this.pageController = new AbortController();
128
+ const opts = { passive: true, signal: this.pageController.signal };
129
+
130
+ window.addEventListener('scroll', schedule, opts);
131
+ window.addEventListener(
132
+ 'resize',
133
+ () => {
134
+ this.syncScrollPadding();
135
+ schedule();
136
+ },
137
+ opts,
138
+ );
139
+
140
+ // Any user-initiated scroll input releases the click pin so the
141
+ // spy can take over again immediately.
142
+ const releasePin = () => {
143
+ this.pinnedIndex = undefined;
144
+ };
145
+ window.addEventListener('wheel', releasePin, opts);
146
+ window.addEventListener('touchstart', releasePin, opts);
147
+ window.addEventListener('keydown', releasePin, opts);
148
+
149
+ // Browser back/forward navigation: release the pin and re-run the
150
+ // spy so the active item reflects the restored scroll position.
151
+ window.addEventListener(
152
+ 'hashchange',
153
+ () => {
154
+ this.pinnedIndex = undefined;
155
+ requestAnimationFrame(() => this.update());
156
+ },
157
+ opts,
158
+ );
159
+
160
+ // popstate covers back/forward cases that hashchange misses:
161
+ // navigating to a URL with no hash, or the same hash as before.
162
+ // Note: do NOT call scrollToHashIfNeeded() here — Chrome fires
163
+ // popstate on anchor clicks too, which would override smooth scroll
164
+ // with an instant jump. The browser handles scroll restoration on
165
+ // back/forward automatically.
166
+ window.addEventListener(
167
+ 'popstate',
168
+ () => {
169
+ this.pinnedIndex = undefined;
170
+ requestAnimationFrame(() => this.update());
171
+ },
172
+ opts,
173
+ );
174
+
175
+ this.addEventListener(
176
+ 'click',
177
+ (e) => {
178
+ const target = (e.target as HTMLElement | null)?.closest('a[href^="#"]');
179
+ if (!(target instanceof HTMLAnchorElement)) return;
180
+ const idx = this.links.indexOf(target);
181
+ if (idx === -1) return;
182
+ this.pinnedIndex = idx;
183
+ this.setActive(idx);
184
+ },
185
+ { signal: this.pageController.signal },
186
+ );
187
+
188
+ this.bindOffsetTarget();
189
+
190
+ // Immediately highlight the first node so there is always a
191
+ // visible active state, even before layout is fully settled.
192
+ // this.setActive(0);
193
+
194
+ this.update();
195
+ // Safari: getBoundingClientRect() may not reflect final layout
196
+ // during the first rAF (before first paint). Schedule one extra
197
+ // update so the initial active item is always correct.
198
+ // Also re-scroll to the hash now that syncScrollPadding has run
199
+ // and scroll-padding-top reflects the true sticky header height.
200
+ // Without this, a refresh with a #hash in the URL would scroll
201
+ // before the CSS variable is set, landing the heading behind the header.
202
+ requestAnimationFrame(() => {
203
+ this.update();
204
+ // Nest in a second rAF so igc-tree's internal scrollIntoView
205
+ // (triggered by setActive → selected = true) settles first,
206
+ // and our correction scroll wins.
207
+ requestAnimationFrame(() => this.scrollToHashIfNeeded());
208
+ });
209
+ }
190
210
 
191
- private bindOffsetTarget() {
192
- const selector = this.dataset.offsetTarget ?? null;
193
- // If an explicit selector is given, use it; otherwise fall back to
194
- // the docs subheader which is always present in the layout.
195
- this.offsetEl = (selector ? document.querySelector(selector) : null)
196
- ?? document.querySelector('docs-subheader-menu')
197
- ?? null;
198
- if (!this.offsetEl) return;
199
-
200
- this.syncScrollPadding();
201
- // Re-sync after layout settles (fonts, reflow) on initial load / navigation.
202
- requestAnimationFrame(() => this.syncScrollPadding());
203
-
204
- // Re-measure when the header itself resizes (responsive collapse,
205
- // font-load reflow, etc.).
206
- this.resizeObserver = new ResizeObserver(() => this.syncScrollPadding());
207
- this.resizeObserver.observe(this.offsetEl);
208
- }
211
+ private bindOffsetTarget() {
212
+ const selector = this.dataset.offsetTarget ?? null;
213
+ // If an explicit selector is given, use it; otherwise fall back to
214
+ // the docs subheader which is always present in the layout.
215
+ this.offsetEl =
216
+ (selector ? document.querySelector(selector) : null) ??
217
+ document.querySelector('docs-subheader-menu') ??
218
+ null;
219
+ if (!this.offsetEl) return;
220
+
221
+ this.syncScrollPadding();
222
+ // Re-sync after layout settles (fonts, reflow) on initial load / navigation.
223
+ requestAnimationFrame(() => this.syncScrollPadding());
224
+
225
+ // Re-measure when the header itself resizes (responsive collapse,
226
+ // font-load reflow, etc.).
227
+ this.resizeObserver = new ResizeObserver(() => this.syncScrollPadding());
228
+ this.resizeObserver.observe(this.offsetEl);
229
+ }
209
230
 
210
- private syncScrollPadding() {
211
- if (!this.offsetEl) return;
212
- const px = Math.round(this.offsetEl.getBoundingClientRect().bottom);
213
- // Write only the measured subheader height; the CSS adds --igd-toc-scroll-offset on top.
214
- document.documentElement.style.setProperty('--igd-toc-subheader-bottom', `${px}px`);
215
- }
231
+ private syncScrollPadding() {
232
+ if (!this.offsetEl) return;
233
+ const px = Math.round(this.offsetEl.getBoundingClientRect().bottom);
234
+ // Write only the measured subheader height; the CSS adds --igd-toc-scroll-offset on top.
235
+ document.documentElement.style.setProperty('--igd-toc-subheader-bottom', `${px}px`);
236
+ }
216
237
 
217
- // Re-scroll to the current URL hash so the heading lands below the sticky
218
- // header once scroll-padding-top has been set correctly by syncScrollPadding.
219
- private scrollToHashIfNeeded() {
220
- const hash = window.location.hash;
221
- if (!hash) return;
222
- const id = decodeURIComponent(hash.slice(1));
223
- const el = document.getElementById(id);
224
- if (el) el.scrollIntoView({ behavior: 'instant', block: 'start' });
225
- }
238
+ // Re-scroll to the current URL hash so the heading lands below the sticky
239
+ // header once scroll-padding-top has been set correctly by syncScrollPadding.
240
+ private scrollToHashIfNeeded() {
241
+ const hash = window.location.hash;
242
+ if (!hash) return;
243
+ const id = decodeURIComponent(hash.slice(1));
244
+ const el = document.getElementById(id);
245
+ if (el) el.scrollIntoView({ behavior: 'instant', block: 'start' });
246
+ }
226
247
 
227
- private update() {
228
- if (this.pinnedIndex !== undefined) {
229
- this.setActive(this.pinnedIndex);
230
- return;
231
- }
232
-
233
- const threshold = this.computeThreshold();
234
- let activeIndex = -1;
235
- for (let i = 0; i < this.headings.length; i++) {
236
- if (this.headings[i].getBoundingClientRect().top <= threshold) {
237
- activeIndex = i;
238
- } else {
239
- break;
240
- }
241
- }
242
-
243
- // Favor the closer heading: if the next heading is nearer to
244
- // the threshold than the current one, jump forward.
245
- if (activeIndex >= 0 && activeIndex + 1 < this.headings.length) {
246
- const currentDist = threshold - this.headings[activeIndex].getBoundingClientRect().top;
247
- const nextDist = this.headings[activeIndex + 1].getBoundingClientRect().top - threshold;
248
- if (nextDist < currentDist) {
249
- activeIndex = activeIndex + 1;
250
- }
251
- }
252
-
253
- // Above the first heading: default to the first item so there
254
- // is always an active entry when at the top of the page.
255
- if (activeIndex === -1) {
256
- activeIndex = 0;
257
- }
258
-
259
- this.setActive(activeIndex);
248
+ private update() {
249
+ if (this.pinnedIndex !== undefined) {
250
+ this.setActive(this.pinnedIndex);
251
+ return;
252
+ }
253
+
254
+ const threshold = this.computeThreshold();
255
+ let activeIndex = -1;
256
+ for (let i = 0; i < this.headings.length; i++) {
257
+ if (this.headings[i].getBoundingClientRect().top <= threshold) {
258
+ activeIndex = i;
259
+ } else {
260
+ break;
260
261
  }
261
-
262
- private computeThreshold(): number {
263
- // The bottom edge of the sticky header is the line below which
264
- // a heading is considered "passed". Add a small fudge so a
265
- // heading flush against the header still activates.
266
- if (this.offsetEl) return this.offsetEl.getBoundingClientRect().bottom + 8;
267
- return DocsToc.DEFAULT_THRESHOLD;
262
+ }
263
+
264
+ // Favor the closer heading: if the next heading is nearer to
265
+ // the threshold than the current one, jump forward.
266
+ if (activeIndex >= 0 && activeIndex + 1 < this.headings.length) {
267
+ const currentDist = threshold - this.headings[activeIndex].getBoundingClientRect().top;
268
+ const nextDist = this.headings[activeIndex + 1].getBoundingClientRect().top - threshold;
269
+ if (nextDist < currentDist) {
270
+ activeIndex = activeIndex + 1;
268
271
  }
272
+ }
269
273
 
270
- private setActive(index: number) {
271
- const next = this.links[index];
272
- if (!next || next === this.currentLink) return;
273
-
274
- const prevItem = this.currentLink?.closest<HTMLElement & { selected: boolean; active: boolean }>('igc-tree-item');
275
- if (prevItem) {
276
- prevItem.selected = false;
277
- prevItem.active = false;
278
- }
279
- this.currentLink?.removeAttribute('aria-current');
280
-
281
- next.setAttribute('aria-current', 'true');
282
- const nextItem = next.closest<HTMLElement & { selected: boolean; active: boolean }>('igc-tree-item');
283
- if (nextItem) nextItem.selected = true;
274
+ // Above the first heading: default to the first item so there
275
+ // is always an active entry when at the top of the page.
276
+ if (activeIndex === -1) {
277
+ activeIndex = 0;
278
+ }
284
279
 
285
- this.currentLink = next;
286
- this.syncExpansion(next);
287
- }
280
+ this.setActive(activeIndex);
281
+ }
288
282
 
289
- /**
290
- * Additive expansion: walk up from the active anchor through
291
- * every ancestor <igc-tree-item> (including the active item
292
- * itself when it has children) and ensure each is `expanded`.
293
- * Items outside the active path are left untouched, so
294
- * previously visited sections stay open as the user scrolls
295
- * past or back. Sections the user has never reached stay
296
- * collapsed.
297
- */
298
- private syncExpansion(activeLink: HTMLAnchorElement) {
299
- let item: Element | null = activeLink.closest('igc-tree-item');
300
- while (
301
- item &&
302
- item.tagName === 'IGC-TREE-ITEM' &&
303
- this.contains(item)
304
- ) {
305
- if (!(item as ExpandableEl).expanded) {
306
- (item as ExpandableEl).expanded = true;
307
- }
308
- item = item.parentElement?.closest('igc-tree-item') ?? null;
309
- }
310
- }
283
+ private computeThreshold(): number {
284
+ // The bottom edge of the sticky header is the line below which
285
+ // a heading is considered "passed". Add a small fudge so a
286
+ // heading flush against the header still activates.
287
+ if (this.offsetEl) return this.offsetEl.getBoundingClientRect().bottom + 8;
288
+ return DocsToc.DEFAULT_THRESHOLD;
311
289
  }
312
290
 
313
- if (!customElements.get('docs-toc')) {
314
- customElements.define('docs-toc', DocsToc);
291
+ private setActive(index: number) {
292
+ const next = this.links[index];
293
+ if (!next || next === this.currentLink) return;
294
+
295
+ const prevItem = this.currentLink?.closest<
296
+ HTMLElement & { selected: boolean; active: boolean }
297
+ >('igc-tree-item');
298
+ if (prevItem) {
299
+ prevItem.selected = false;
300
+ prevItem.active = false;
301
+ }
302
+ this.currentLink?.removeAttribute('aria-current');
303
+
304
+ next.setAttribute('aria-current', 'true');
305
+ const nextItem = next.closest<HTMLElement & { selected: boolean; active: boolean }>(
306
+ 'igc-tree-item',
307
+ );
308
+ if (nextItem) nextItem.selected = true;
309
+
310
+ this.currentLink = next;
311
+ this.syncExpansion(next);
315
312
  }
316
313
 
317
- // Astro View Transitions: bundled module scripts run only once, so
318
- // connectedCallback alone won't re-fire after a page swap if the
319
- // element is morphed rather than replaced. This top-level listener
320
- // fires on both initial load and after every navigation.
321
- document.addEventListener('astro:page-load', () => {
322
- document.querySelectorAll('docs-toc').forEach((el) => {
323
- if (el instanceof DocsToc) el.init();
324
- });
314
+ /**
315
+ * Additive expansion: walk up from the active anchor through
316
+ * every ancestor <igc-tree-item> (including the active item
317
+ * itself when it has children) and ensure each is `expanded`.
318
+ * Items outside the active path are left untouched, so
319
+ * previously visited sections stay open as the user scrolls
320
+ * past or back. Sections the user has never reached stay
321
+ * collapsed.
322
+ */
323
+ private syncExpansion(activeLink: HTMLAnchorElement) {
324
+ let item: Element | null = activeLink.closest('igc-tree-item');
325
+ while (item && item.tagName === 'IGC-TREE-ITEM' && this.contains(item)) {
326
+ if (!(item as ExpandableEl).expanded) {
327
+ (item as ExpandableEl).expanded = true;
328
+ }
329
+ item = item.parentElement?.closest('igc-tree-item') ?? null;
330
+ }
331
+ }
332
+ }
333
+
334
+ if (!customElements.get('docs-toc')) {
335
+ customElements.define('docs-toc', DocsToc);
336
+ }
337
+
338
+ // Astro View Transitions: bundled module scripts run only once, so
339
+ // connectedCallback alone won't re-fire after a page swap if the
340
+ // element is morphed rather than replaced. This top-level listener
341
+ // fires on both initial load and after every navigation.
342
+ document.addEventListener('astro:page-load', () => {
343
+ document.querySelectorAll('docs-toc').forEach((el) => {
344
+ if (el instanceof DocsToc) el.init();
325
345
  });
346
+ });
326
347
  </script>