igniteui-astro-components 0.0.1

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 (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +374 -0
  3. package/package.json +109 -0
  4. package/src/components/DocsSidebar/DocsSidebar.astro +99 -0
  5. package/src/components/DocsSidebar/README.md +166 -0
  6. package/src/components/DocsSidebar/SidebarFilterInput.astro +74 -0
  7. package/src/components/DocsSidebar/SidebarLabel.astro +40 -0
  8. package/src/components/DocsSidebar/sidebar-filter.ts +393 -0
  9. package/src/components/DocsSidebar/toTreeNodes.ts +66 -0
  10. package/src/components/DocsSubHeader/DocsSubHeader.astro +320 -0
  11. package/src/components/DocsSubHeader/README.md +74 -0
  12. package/src/components/DocsToc/DocsToc.astro +307 -0
  13. package/src/components/DocsToc/README.md +68 -0
  14. package/src/components/DocsToc/toTreeNodes.ts +57 -0
  15. package/src/components/DocsTree/DocsTree.astro +66 -0
  16. package/src/components/DocsTree/DocsTreeItem.astro +84 -0
  17. package/src/components/DocsTree/README.md +105 -0
  18. package/src/components/DocsTree/docs-tree.css +227 -0
  19. package/src/components/DocsTree/types.ts +47 -0
  20. package/src/components/GlobalFooter/GlobalFooter.astro +90 -0
  21. package/src/components/GlobalFooter/GlobalFooter.module.scss +23 -0
  22. package/src/components/GlobalFooter/README.md +35 -0
  23. package/src/components/GlobalNavBar/GlobalNavBar.astro +218 -0
  24. package/src/components/GlobalNavBar/GlobalNavBar.module.scss +215 -0
  25. package/src/components/GlobalNavBar/README.md +49 -0
  26. package/src/components/MobileSidebarToggle/MobileSidebarToggle.astro +112 -0
  27. package/src/components/MobileSidebarToggle/README.md +31 -0
  28. package/src/components/Search/README.md +43 -0
  29. package/src/components/Search/Search.astro +222 -0
  30. package/src/components/ThemingWidget/README.md +35 -0
  31. package/src/components/ThemingWidget/ThemingWidget.astro +152 -0
  32. package/src/components/mdx/ApiLink/ApiLink.astro +121 -0
  33. package/src/components/mdx/ApiLink/README.md +68 -0
  34. package/src/components/mdx/ApiRef/ApiRef.astro +92 -0
  35. package/src/components/mdx/ApiRef/README.md +50 -0
  36. package/src/components/mdx/DocsAside/DocsAside.astro +86 -0
  37. package/src/components/mdx/DocsAside/README.md +66 -0
  38. package/src/components/mdx/DocsAside/icons/caution.svg +3 -0
  39. package/src/components/mdx/DocsAside/icons/danger.svg +3 -0
  40. package/src/components/mdx/DocsAside/icons/note.svg +3 -0
  41. package/src/components/mdx/DocsAside/icons/tip.svg +4 -0
  42. package/src/components/mdx/PlatformBlock/PlatformBlock.astro +24 -0
  43. package/src/components/mdx/PlatformBlock/README.md +57 -0
  44. package/src/components/mdx/Sample/README.md +59 -0
  45. package/src/components/mdx/Sample/Sample.astro +142 -0
  46. package/src/content-helper.ts +159 -0
  47. package/src/content.config.ts +17 -0
  48. package/src/index.ts +42 -0
  49. package/src/integration.ts +841 -0
  50. package/src/layouts/DocsLayout/DocsLayout.astro +307 -0
  51. package/src/layouts/DocsLayout/README.md +124 -0
  52. package/src/lib/nav-helpers.ts +155 -0
  53. package/src/lib/platform-context.ts +305 -0
  54. package/src/lib/sidebar/helpers.ts +81 -0
  55. package/src/lib/sidebar/types.ts +36 -0
  56. package/src/llms.ts +315 -0
  57. package/src/platform.ts +281 -0
  58. package/src/plugins/remark-docfx.ts +368 -0
  59. package/src/scripts/sample-widget.ts +516 -0
  60. package/src/sidebar.ts +167 -0
  61. package/src/styles/custom.scss +254 -0
  62. package/src/styles/ig-theme.scss +43 -0
  63. package/src/virtual-modules.d.ts +35 -0
@@ -0,0 +1,307 @@
1
+ ---
2
+ import { ClientRouter } from 'astro:transitions';
3
+ import GlobalNavBar from '../../components/GlobalNavBar/GlobalNavBar.astro';
4
+ import GlobalFooter from '../../components/GlobalFooter/GlobalFooter.astro';
5
+ import DocsSubHeader from '../../components/DocsSubHeader/DocsSubHeader.astro';
6
+ import MobileSidebarToggle from '../../components/MobileSidebarToggle/MobileSidebarToggle.astro';
7
+ import { widgetScriptSrc, platform as virtualPlatform } from 'virtual:docs-template/nav-html';
8
+ import { title as siteTitle, headEntries } from 'virtual:docs-template/site-meta';
9
+ import '../../styles/ig-theme.scss';
10
+ import '../../styles/custom.scss';
11
+
12
+ export interface Props {
13
+ title?: string;
14
+ description?: string | null;
15
+ keywords?: string | null;
16
+ hasSidebar?: boolean;
17
+ /** Slug of the current page; used to compute breadcrumbs in the subheader. */
18
+ currentSlug?: string;
19
+ /**
20
+ * Override the site name shown in the <title> and sub-header.
21
+ * Defaults to the value from `virtual:docs-template/site-meta`.
22
+ * Useful when consuming without `siteMetaIntegration`.
23
+ */
24
+ siteTitle?: string;
25
+ }
26
+
27
+ const { title, description, keywords, hasSidebar = true, currentSlug = '', siteTitle: siteTitleProp } = Astro.props;
28
+ const resolvedSiteTitle = siteTitleProp ?? siteTitle;
29
+ const navTheme = (virtualPlatform ?? import.meta.env.VITE_NAV_THEME ?? 'igniteui') as string;
30
+ const showGlobalNav = navTheme !== 'none';
31
+ const pageTitle = title ? `${title} | ${resolvedSiteTitle}` : resolvedSiteTitle;
32
+
33
+ type HeadEntry = { tag: string; attrs?: Record<string, string | boolean | undefined>; content?: string };
34
+ ---
35
+
36
+ <!DOCTYPE html>
37
+ <html lang="en" data-theme="light" style={!showGlobalNav ? '--docs-global-nav-height: 0' : undefined}>
38
+ <head>
39
+ <meta charset="UTF-8" />
40
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
41
+ <title>{pageTitle}</title>
42
+ {description && <meta name="description" content={description} />}
43
+ {keywords && <meta name="keywords" content={keywords} />}
44
+ <link rel="icon" href="/favicon.svg" type="image/svg+xml" />
45
+ {widgetScriptSrc && <script is:inline src={widgetScriptSrc} async></script>}
46
+ {(headEntries as HeadEntry[]).map(({ tag: Tag, attrs = {}, content }) =>
47
+ content ? <Tag {...attrs} set:html={content} /> : <Tag {...attrs} />
48
+ )}
49
+ <slot name="head" />
50
+ <ClientRouter />
51
+ <script is:inline>
52
+ // Force light theme on load and after every View Transitions swap
53
+ try { localStorage.setItem('starlight-theme', 'light'); } catch (_) {}
54
+ document.documentElement.setAttribute('data-theme', 'light');
55
+ document.addEventListener('astro:after-swap', function () {
56
+ document.documentElement.setAttribute('data-theme', 'light');
57
+ });
58
+
59
+ // Preserve dynamically-injected <style> tags across View Transitions
60
+ var _styleIndex = 0;
61
+ function tagStyle(style) {
62
+ var isAstroStyle = Array.from(style.attributes).some(function (a) { return a.name.startsWith('data-astro'); });
63
+ if (!isAstroStyle && !style.hasAttribute('data-vt-preserved')) {
64
+ style.setAttribute('data-vt-preserved', String(++_styleIndex));
65
+ }
66
+ }
67
+ document.head.querySelectorAll('style').forEach(tagStyle);
68
+ new MutationObserver(function (mutations) {
69
+ mutations.forEach(function (m) {
70
+ m.addedNodes.forEach(function (node) {
71
+ if (node instanceof HTMLStyleElement) tagStyle(node);
72
+ });
73
+ });
74
+ }).observe(document.head, { childList: true });
75
+ document.addEventListener('astro:before-swap', function (e) {
76
+ document.head.querySelectorAll('style[data-vt-preserved]').forEach(function (style) {
77
+ var id = style.getAttribute('data-vt-preserved');
78
+ if (!e.newDocument.head.querySelector('style[data-vt-preserved="' + id + '"]')) {
79
+ e.newDocument.head.appendChild(style.cloneNode(true));
80
+ }
81
+ });
82
+ });
83
+
84
+ function updateNavHeight() {
85
+ var navChild = document.querySelector('[data-astro-transition-persist="global-nav-bar"] > *:first-child');
86
+ if (!navChild) return;
87
+ var h = navChild.getBoundingClientRect().height;
88
+ if (h > 0) {
89
+ document.documentElement.style.setProperty('--docs-global-nav-height', h + 'px');
90
+ var wrapper = document.querySelector('[data-nav-height-wrapper]');
91
+ if (wrapper) wrapper.style.setProperty('--docs-global-nav-height', h + 'px');
92
+ }
93
+ }
94
+ document.addEventListener('astro:page-load', updateNavHeight);
95
+ window.addEventListener('resize', updateNavHeight);
96
+ updateNavHeight();
97
+ var _navChild = document.querySelector('[data-astro-transition-persist="global-nav-bar"] > *:first-child');
98
+ if (_navChild) new ResizeObserver(updateNavHeight).observe(_navChild);
99
+ </script>
100
+ </head>
101
+ <body>
102
+ {showGlobalNav && <GlobalNavBar />}
103
+ <div style={`--docs-global-nav-height: ${showGlobalNav ? '4.7rem' : '0'}`} data-nav-height-wrapper>
104
+ <DocsSubHeader pageTitle={title} currentSlug={currentSlug} siteTitle={siteTitleProp} />
105
+ </div>
106
+ <div class="page">
107
+ {hasSidebar && (
108
+ <nav class="sidebar print:hidden" aria-label="Documentation navigation">
109
+ <MobileSidebarToggle />
110
+ <div class="sidebar-pane">
111
+ <div class="sidebar-content">
112
+ <slot name="sidebar" />
113
+ </div>
114
+ </div>
115
+ </nav>
116
+ )}
117
+ <div class="main-frame">
118
+ <slot />
119
+ </div>
120
+ <aside class="toc-sidebar">
121
+ <slot name="toc" />
122
+ </aside>
123
+ </div>
124
+ <GlobalFooter />
125
+ </body>
126
+ </html>
127
+
128
+ <style is:global>
129
+ /* ── Design tokens — replaces Starlight's built-in CSS custom properties ── */
130
+ :root {
131
+ /* Sidebar */
132
+ --sl-sidebar-width: 18.75rem;
133
+ --sl-sidebar-pad-x: 1rem;
134
+ --sl-content-inline-start: var(--sl-sidebar-width);
135
+ /* Z-index */
136
+ --sl-z-index-navbar: 10;
137
+ --sl-z-index-menu: 9;
138
+ /* Nav */
139
+ --sl-nav-gap: 1rem;
140
+ --sl-menu-button-size: 2rem;
141
+ /* Typography */
142
+ --sl-text-xs: 0.75rem;
143
+ --sl-text-sm: 0.875rem;
144
+ --sl-text-base: 1rem;
145
+ --sl-text-lg: 1.125rem;
146
+ --sl-text-xl: 1.25rem;
147
+ --sl-text-2xl: 1.5rem;
148
+ --sl-text-3xl: 1.875rem;
149
+ --sl-text-4xl: 2.25rem;
150
+ /* Light-mode colors */
151
+ --sl-color-white: hsl(0, 0%, 100%);
152
+ --sl-color-gray-1: hsl(240, 6%, 90%);
153
+ --sl-color-gray-2: hsl(240, 5%, 74%);
154
+ --sl-color-gray-3: hsl(240, 5%, 58%);
155
+ --sl-color-gray-4: hsl(240, 4%, 46%);
156
+ --sl-color-gray-5: hsl(240, 5%, 35%);
157
+ --sl-color-gray-6: hsl(240, 10%, 26%);
158
+ --sl-color-black: hsl(240, 16%, 11%);
159
+ --sl-color-bg: hsl(0, 0%, 100%);
160
+ --sl-color-bg-nav: hsl(0, 0%, 100%);
161
+ --sl-color-bg-sidebar: hsl(224, 10%, 97%);
162
+ --sl-color-bg-inline-code: hsl(219, 13%, 93%);
163
+ --sl-color-hairline-light: hsl(240, 6%, 90%);
164
+ --sl-color-hairline: hsl(240, 9%, 85%);
165
+ --sl-color-hairline-shade: hsl(240, 6%, 78%);
166
+ --sl-color-text: hsl(240, 16%, 11%);
167
+ --sl-color-text-accent: hsl(234, 90%, 60%);
168
+ --sl-color-accent: hsl(234, 90%, 60%);
169
+ --sl-color-accent-low: hsl(234, 88%, 90%);
170
+ --sl-color-accent-high: hsl(234, 90%, 45%);
171
+ /* Shadows */
172
+ --sl-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.1);
173
+ --sl-shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
174
+ --sl-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
175
+ }
176
+
177
+ *, *::before, *::after {
178
+ box-sizing: border-box;
179
+ }
180
+
181
+ html {
182
+ scroll-behavior: smooth;
183
+ }
184
+
185
+ body {
186
+ margin: 0;
187
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
188
+ font-size: var(--sl-text-base);
189
+ color: var(--sl-color-text);
190
+ background-color: var(--sl-color-bg);
191
+ line-height: 1.625;
192
+ }
193
+
194
+ a {
195
+ color: var(--sl-color-text-accent);
196
+ text-decoration: none;
197
+ }
198
+ a:hover { text-decoration: underline; }
199
+
200
+ /* ── Page shell ──────────────────────────────────────────────────────────── */
201
+
202
+ .page {
203
+ min-height: 100vh;
204
+ padding-block-start: var(--sl-nav-height);
205
+ }
206
+
207
+ /* ── Sidebar ─────────────────────────────────────────────────────────────── */
208
+
209
+ /*
210
+ * Mobile: sidebar-pane is a fixed full-width overlay controlled by the
211
+ * MobileSidebarToggle button (aria-expanded sibling + body attribute).
212
+ * Desktop: sidebar-pane is a fixed left rail, always visible.
213
+ */
214
+
215
+ .sidebar-pane {
216
+ visibility: var(--sl-sidebar-visibility, hidden);
217
+ position: fixed;
218
+ z-index: var(--sl-z-index-menu);
219
+ inset-block: calc(var(--sl-nav-height) + var(--docs-mobile-toggle-height)) 0;
220
+ inset-inline-start: 0;
221
+ width: 100%;
222
+ background-color: var(--sl-color-bg-sidebar);
223
+ /* The inner .sidebar-scroll owns vertical scrolling so the filter input
224
+ (rendered above it) stays pinned and always visible. */
225
+ overflow: hidden;
226
+ display: flex;
227
+ flex-direction: column;
228
+ }
229
+
230
+ /* Show sidebar when the toggle button (preceding sibling) is expanded */
231
+ [aria-expanded='true'] ~ .sidebar-pane {
232
+ --sl-sidebar-visibility: visible;
233
+ }
234
+
235
+ .sidebar-content {
236
+ flex: 1;
237
+ min-height: 0;
238
+ padding: 1rem var(--sl-sidebar-pad-x) 0;
239
+ display: flex;
240
+ flex-direction: column;
241
+ gap: 1rem;
242
+ }
243
+
244
+ @media (min-width: 50rem) {
245
+ .sidebar-content::after {
246
+ content: '';
247
+ padding-bottom: 1px;
248
+ }
249
+
250
+ .sidebar-pane {
251
+ --sl-sidebar-visibility: visible;
252
+ width: var(--sl-sidebar-width);
253
+ background-color: var(--sl-color-bg-sidebar);
254
+ border-inline-end: 1px solid var(--sl-color-hairline-shade);
255
+ inset-block-start: var(--sl-nav-height);
256
+ }
257
+ }
258
+
259
+ /* ── Main frame ──────────────────────────────────────────────────────────── */
260
+
261
+ .main-frame {
262
+ padding-block-start: var(--docs-mobile-toggle-height);
263
+ }
264
+
265
+ @media (min-width: 50rem) {
266
+ .main-frame {
267
+ padding-block-start: 0;
268
+ padding-inline-start: var(--sl-content-inline-start, 0);
269
+ }
270
+ }
271
+
272
+ /* ── Content prose ───────────────────────────────────────────────────────── */
273
+
274
+ .sl-markdown-content {
275
+ max-width: 50rem;
276
+ margin: 0 auto;
277
+ padding: 2rem 1.5rem;
278
+ }
279
+
280
+ .sl-markdown-content h1 { font-size: var(--sl-text-4xl); margin-block: 0 1rem; }
281
+ .sl-markdown-content h2 { font-size: var(--sl-text-2xl); margin-block: 2rem 0.75rem; }
282
+ .sl-markdown-content h3 { font-size: var(--sl-text-xl); margin-block: 1.5rem 0.5rem; }
283
+ .sl-markdown-content p { margin-block: 0.75rem; }
284
+ .sl-markdown-content pre {
285
+ background: var(--sl-color-bg-sidebar);
286
+ border: 1px solid var(--sl-color-hairline);
287
+ border-radius: 0.375rem;
288
+ padding: 1rem;
289
+ overflow-x: auto;
290
+ }
291
+ .sl-markdown-content code {
292
+ background: var(--sl-color-bg-inline-code);
293
+ border-radius: 0.25rem;
294
+ padding: 0.125rem 0.25rem;
295
+ font-size: 0.875em;
296
+ }
297
+ .sl-markdown-content pre code {
298
+ background: transparent;
299
+ padding: 0;
300
+ }
301
+
302
+ /* ── Utility ─────────────────────────────────────────────────────────────── */
303
+
304
+ @media print {
305
+ .print\:hidden { display: none !important; }
306
+ }
307
+ </style>
@@ -0,0 +1,124 @@
1
+ # DocsLayout
2
+
3
+ Top-level page shell. Composes the global nav bar, sub-header, optional sidebar slot, main content area, "On this page" TOC slot, and footer into a single full-page layout.
4
+
5
+ ## Import
6
+
7
+ ```astro
8
+ import DocsLayout from 'igniteui-astro-components/layouts/DocsLayout.astro';
9
+ ```
10
+
11
+ ## Props
12
+
13
+ | Prop | Type | Default | Description |
14
+ |------|------|---------|-------------|
15
+ | `title` | `string` | — | Page `<title>` prepended to the site name. Omit to show the site name only. |
16
+ | `description` | `string \| null` | — | `<meta name="description">` value. |
17
+ | `keywords` | `string \| null` | — | `<meta name="keywords">` value. |
18
+ | `hasSidebar` | `boolean` | `true` | Renders the sidebar rail when `true`. Provide content via `<… slot="sidebar">`. |
19
+ | `currentSlug` | `string` | `''` | Slug of the current page — used for breadcrumbs in the sub-header. |
20
+ | `siteTitle` | `string` | virtual module | Override the site name used in `<title>` and the sub-header. Use this when not running `siteMetaIntegration`. |
21
+
22
+ ## Slots
23
+
24
+ | Slot | Description |
25
+ |------|-------------|
26
+ | *(default)* | Main page content. |
27
+ | `sidebar` | Sidebar content — typically `<DocsSidebar>`. Only rendered when `hasSidebar={true}`. |
28
+ | `toc` | "On this page" column — pass `<DocsToc slot="toc" headings={headings} />` here. Omit to hide the TOC sidebar entirely. |
29
+ | `head` | Extra `<head>` entries injected after platform defaults. |
30
+
31
+ ## Example
32
+
33
+ ### With TOC (prop-driven, no `siteMetaIntegration` required)
34
+
35
+ Pass all data directly as props. The `virtual:docs-template/site-meta` module
36
+ still needs to be resolvable at Vite build time — supply a minimal stub (see
37
+ [playground/astro.config.mjs](../../../playground/astro.config.mjs)).
38
+
39
+ ```astro
40
+ ---
41
+ import DocsLayout from 'igniteui-astro-components/layouts/DocsLayout.astro';
42
+ import DocsSidebar from 'igniteui-astro-components/components/sidebar/DocsSidebar.astro';
43
+ import DocsToc from 'igniteui-astro-components/components/DocsToc.astro';
44
+ import type { SidebarEntry } from 'igniteui-astro-components/lib/sidebar/types';
45
+ import type { MarkdownHeading } from 'astro';
46
+
47
+ const { headings } = Astro.props as { headings: MarkdownHeading[] };
48
+ const slug = Astro.params.slug ?? '';
49
+
50
+ const sidebar: SidebarEntry[] = [
51
+ { label: 'Getting Started', collapsed: false, items: [
52
+ { label: 'Introduction', slug: '' },
53
+ ]},
54
+ { label: 'Components', collapsed: false, items: [
55
+ { label: 'Toast', slug: 'components/toast' },
56
+ ]},
57
+ ];
58
+ ---
59
+ <DocsLayout
60
+ title="Toast"
61
+ siteTitle="My Library"
62
+ hasSidebar
63
+ currentSlug={slug}
64
+ >
65
+ <DocsSidebar slot="sidebar" items={sidebar} currentSlug={slug} />
66
+ <DocsToc slot="toc" headings={headings} offsetTarget=".docs-subheader" />
67
+ <slot />
68
+ </DocsLayout>
69
+ ```
70
+
71
+ ### Without TOC
72
+
73
+ Omit the `toc` slot entirely — the TOC sidebar collapses automatically via CSS.
74
+
75
+ ```astro
76
+ ---
77
+ import DocsLayout from 'igniteui-astro-components/layouts/DocsLayout.astro';
78
+ import DocsSidebar from 'igniteui-astro-components/components/sidebar/DocsSidebar.astro';
79
+
80
+ const slug = Astro.params.slug ?? '';
81
+ ---
82
+ <DocsLayout title="Changelog" siteTitle="My Library" hasSidebar currentSlug={slug}>
83
+ <DocsSidebar slot="sidebar" currentSlug={slug} />
84
+ <slot />
85
+ </DocsLayout>
86
+ ```
87
+
88
+ ### With `siteMetaIntegration` (integration-driven)
89
+
90
+ When `createDocsSite()` / `siteMetaIntegration()` is configured, `siteTitle`
91
+ can be omitted — it is read from the virtual module automatically.
92
+
93
+ ```astro
94
+ ---
95
+ import DocsLayout from 'igniteui-astro-components/layouts/DocsLayout.astro';
96
+ import DocsSidebar from 'igniteui-astro-components/components/sidebar/DocsSidebar.astro';
97
+ import DocsToc from 'igniteui-astro-components/components/DocsToc.astro';
98
+
99
+ const { headings } = Astro.props;
100
+ const slug = Astro.params.slug ?? '';
101
+ ---
102
+ <DocsLayout
103
+ title="Toast"
104
+ description="Toast component documentation"
105
+ hasSidebar
106
+ currentSlug={slug}
107
+ >
108
+ <DocsSidebar slot="sidebar" currentSlug={slug} />
109
+ <DocsToc slot="toc" headings={headings} offsetTarget=".docs-subheader" />
110
+ <slot />
111
+ </DocsLayout>
112
+ ```
113
+
114
+ ## Virtual module dependencies
115
+
116
+ `DocsLayout` imports from two virtual modules. When using `siteMetaIntegration`
117
+ they are provided automatically. When not, supply minimal stubs via a Vite
118
+ plugin (see [playground/astro.config.mjs](../../../playground/astro.config.mjs)
119
+ for a reference implementation):
120
+
121
+ | Module | Used for | Can be overridden by prop |
122
+ |--------|----------|--------------------------|
123
+ | `virtual:docs-template/site-meta` | Site title, sidebar tree, product links, extra `<head>` entries | `siteTitle` on `DocsLayout`, `items` on `DocsSidebar`, `productLinks`/`sidebarItems` on `DocsSubHeader` |
124
+ | `virtual:docs-template/nav-html` | Pre-fetched nav/footer HTML, widget script URL, platform key | — (not yet prop-overridable) |
@@ -0,0 +1,155 @@
1
+ /**
2
+ * nav-helpers.ts
3
+ *
4
+ * Shared build-time utilities for fetching and sanitising the Infragistics
5
+ * global nav / footer HTML.
6
+ *
7
+ * Used by:
8
+ * - integration.ts (siteMetaIntegration virtual-module pipeline)
9
+ * - components/GlobalNavBar/GlobalNavBar.astro
10
+ * - components/GlobalFooter/GlobalFooter.astro
11
+ */
12
+
13
+ import { JSDOM } from 'jsdom';
14
+ import type { NavLang } from '../platform.ts';
15
+
16
+ // ---------------------------------------------------------------------------
17
+ // Low-level HTML helpers
18
+ // ---------------------------------------------------------------------------
19
+
20
+ /**
21
+ * Strip all <script> tags from an HTML string using a DOM parser.
22
+ * The nav HTML fetched from infragistics.com may contain inline or external
23
+ * scripts that don't belong in the docs page. Platform-specific scripts are
24
+ * already injected cleanly via getPlatformHead().
25
+ */
26
+ export function stripScripts(html: string): string {
27
+ const dom = new JSDOM(html);
28
+ const { document } = dom.window;
29
+ document.querySelectorAll('script').forEach((el: Element) => el.remove());
30
+ return document.body.innerHTML;
31
+ }
32
+
33
+ /**
34
+ * Rewrite root-relative href/src/action attributes to absolute URLs using
35
+ * the given base origin (e.g. 'https://www.infragistics.com').
36
+ *
37
+ * Without this, links like href="/products/ignite-ui" resolve against the
38
+ * local dev-server origin and Astro's client-side router intercepts them.
39
+ */
40
+ export function absolutifyNavUrls(html: string, baseOrigin: string): string {
41
+ return html
42
+ .replace(/(href|src|action)="(\/)([^"]*)"/g, `$1="${baseOrigin}/$3"`)
43
+ .replace(/(href|src|action)='(\/)([^']*)'/g, `$1='${baseOrigin}/$3'`);
44
+ }
45
+
46
+ /**
47
+ * Nesting-aware outer-HTML extractor.
48
+ * Finds the first tag whose opening tag matches `openPattern` and returns the
49
+ * complete element including its closing tag.
50
+ *
51
+ * @param html - Full HTML string to search.
52
+ * @param openPattern - Regex source for the opening tag (no flags).
53
+ */
54
+ export function extractOuterHtml(html: string, openPattern: string): string {
55
+ const openRe = new RegExp(openPattern, 'i');
56
+ const tagRe = /<\/?([a-z][a-z0-9]*)[^>]*>/gi;
57
+
58
+ let tagName: string | null = null;
59
+ let depth = 0;
60
+ let startIdx = -1;
61
+
62
+ let m: RegExpExecArray | null;
63
+ while ((m = tagRe.exec(html)) !== null) {
64
+ const full = m[0];
65
+ const name = m[1].toLowerCase();
66
+ const isSelfClose = full.endsWith('/>');
67
+ const isClose = full.startsWith('</');
68
+
69
+ if (tagName === null) {
70
+ if (openRe.test(full)) {
71
+ tagName = name;
72
+ startIdx = m.index;
73
+ depth = isSelfClose ? 0 : 1;
74
+ if (depth === 0) return full;
75
+ }
76
+ continue;
77
+ }
78
+
79
+ if (name !== tagName) continue;
80
+ if (isSelfClose) continue;
81
+ if (isClose) { depth--; if (depth === 0) return html.slice(startIdx, tagRe.lastIndex); }
82
+ else depth++;
83
+ }
84
+
85
+ return '';
86
+ }
87
+
88
+ // ---------------------------------------------------------------------------
89
+ // High-level IG nav prefetch
90
+ // ---------------------------------------------------------------------------
91
+
92
+ export interface IgNavHtml {
93
+ headerHtml: string;
94
+ uiFooterHtml: string;
95
+ footerHtml: string;
96
+ /** True when the fetch succeeded and the HTML fields are populated. */
97
+ prefetched: boolean;
98
+ }
99
+
100
+ /** Module-level cache keyed by locale — fetch runs at most once per locale per build. */
101
+ const _cache = new Map<string, IgNavHtml>();
102
+
103
+ /**
104
+ * Fetch the Infragistics global nav/footer HTML for the given locale.
105
+ *
106
+ * Performs a single HTTP request to `{igBase}/navigation`, extracts the
107
+ * three relevant HTML fragments, strips scripts, and absolutifies URLs.
108
+ * Results are cached per locale so subsequent calls (e.g. from multiple
109
+ * pages using `GlobalNavBarIg`) are free.
110
+ *
111
+ * Fails gracefully: returns `prefetched: false` with empty strings when the
112
+ * network is unavailable (offline builds, CI without outbound access, etc.)
113
+ */
114
+ export async function fetchIgNav(lang: NavLang = 'en'): Promise<IgNavHtml> {
115
+ if (_cache.has(lang)) return _cache.get(lang)!;
116
+
117
+ const igBase = lang === 'jp' ? 'https://jp.infragistics.com' : 'https://www.infragistics.com';
118
+ const navUrl = `${igBase}/navigation`;
119
+
120
+ let headerHtml = '';
121
+ let uiFooterHtml = '';
122
+ let footerHtml = '';
123
+
124
+ try {
125
+ const res = await fetch(navUrl, {
126
+ credentials: 'omit',
127
+ signal: AbortSignal.timeout(15_000),
128
+ });
129
+ if (res.ok) {
130
+ const html = await res.text();
131
+ headerHtml = absolutifyNavUrls(
132
+ stripScripts(extractOuterHtml(html, '<header[^>]+id="header"')),
133
+ igBase,
134
+ );
135
+ uiFooterHtml = absolutifyNavUrls(
136
+ stripScripts(extractOuterHtml(html, '<footer[^>]+class="[^"]*\\bui-footer\\b')),
137
+ igBase,
138
+ );
139
+ footerHtml = absolutifyNavUrls(
140
+ stripScripts(extractOuterHtml(html, '<footer[^>]+id="footer"')),
141
+ igBase,
142
+ );
143
+ // Strip the hello-bar promotional strip
144
+ headerHtml = headerHtml.replace(/<div[^>]+id="hello-bar"[\s\S]*?<\/div>\s*/i, '');
145
+ } else {
146
+ console.warn(`[igniteui-astro-components] Nav fetch returned ${res.status} — using static fallback.`);
147
+ }
148
+ } catch (err: unknown) {
149
+ console.warn(`[igniteui-astro-components] Could not fetch IG nav: ${(err as Error).message} — using static fallback.`);
150
+ }
151
+
152
+ const result: IgNavHtml = { headerHtml, uiFooterHtml, footerHtml, prefetched: !!headerHtml };
153
+ _cache.set(lang, result);
154
+ return result;
155
+ }