igniteui-astro-components 0.0.6 → 0.0.8

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/README.md +9 -8
  2. package/package.json +7 -5
  3. package/src/assets/icons/open-link-blank.svg +1 -1
  4. package/src/assets/logos/code-sandbox.svg +14 -0
  5. package/src/assets/logos/stackblitz.svg +13 -0
  6. package/src/components/DocsBreadcrumb/DocsBreadcrumb.scss +1 -1
  7. package/src/components/DocsSidebar/DocsSidebar.astro +15 -8
  8. package/src/components/DocsSidebar/DocsSidebar.scss +152 -2
  9. package/src/components/DocsSidebar/SidebarFilterInput.scss +7 -3
  10. package/src/components/DocsSidebar/SidebarLabel.astro +25 -4
  11. package/src/components/DocsSidebar/toTreeNodes.ts +1 -1
  12. package/src/components/DocsSubHeader/DocsSubHeader.astro +119 -302
  13. package/src/components/DocsSubHeader/DocsSubHeader.scss +111 -11
  14. package/src/components/DocsToc/DocsToc.astro +5 -2
  15. package/src/components/DocsToc/toTreeNodes.ts +1 -1
  16. package/src/components/DocsTree/DocsTree.astro +9 -0
  17. package/src/components/DocsTree/docs-tree.scss +139 -118
  18. package/src/components/GlobalFooter/GlobalFooter.astro +12 -62
  19. package/src/components/GlobalFooter/README.md +7 -10
  20. package/src/components/GlobalNavBar/GlobalNavBar.astro +8 -193
  21. package/src/components/GlobalNavBar/GlobalNavBar.module.scss +16 -6
  22. package/src/components/GlobalNavBar/README.md +8 -15
  23. package/src/components/LicenseIndicator/LicenseIndicator.astro +19 -0
  24. package/src/components/LicenseIndicator/LicenseIndicator.scss +5 -0
  25. package/src/components/Search/Search.astro +34 -15
  26. package/src/components/Search/Search.scss +10 -42
  27. package/src/components/SearchAdvanced/SearchAdvanced.astro +202 -366
  28. package/src/components/SearchAdvanced/SearchAdvanced.scss +177 -0
  29. package/src/components/ThemingWidget/ThemingWidget.astro +5 -10
  30. package/src/components/mdx/ApiRef/README.md +1 -1
  31. package/src/components/mdx/DocsAside/DocsAside.astro +37 -32
  32. package/src/components/mdx/DocsAside/DocsAside.scss +123 -35
  33. package/src/components/mdx/Sample/Sample.astro +55 -45
  34. package/src/components/mdx/Sample/Sample.scss +173 -30
  35. package/src/content.config.ts +1 -1
  36. package/src/integration.ts +25 -141
  37. package/src/layouts/DocsLayout/DocsLayout.astro +61 -20
  38. package/src/layouts/DocsLayout/DocsLayout.scss +51 -6
  39. package/src/lib/nav-helpers.ts +11 -4
  40. package/src/lib/sidebar/helpers.ts +14 -1
  41. package/src/lib/sidebar/types.ts +5 -7
  42. package/src/platform.ts +9 -16
  43. package/src/plugins/rehype-heading-anchors.ts +74 -0
  44. package/src/plugins/rehype-table-wrapper.ts +49 -0
  45. package/src/plugins/remark-docfx.ts +0 -368
  46. package/src/plugins/remark-env-vars.ts +110 -0
  47. package/src/plugins/remark-html-transforms.ts +32 -0
  48. package/src/plugins/remark-md-links.ts +75 -0
  49. package/src/scripts/sample-widget.ts +107 -116
  50. package/src/sidebar.ts +6 -7
  51. package/src/styles/global/_breakpoints.scss +4 -4
  52. package/src/styles/global/_code-blocks.scss +1 -1
  53. package/src/styles/global/_component-themes.scss +118 -18
  54. package/src/styles/global/_index.scss +2 -2
  55. package/src/styles/global/_markdown.scss +444 -32
  56. package/src/styles/global/_palette.scss +7 -0
  57. package/src/styles/global/_search-shared.scss +273 -0
  58. package/src/styles/global/_variables.scss +58 -3
  59. package/src/styles/theme.scss +80 -11
  60. package/src/virtual-modules.d.ts +1 -13
  61. package/src/assets/icons/copy-clipboard.svg +0 -3
  62. package/src/assets/icons/filter-clear.svg +0 -1
  63. package/src/styles/custom.scss +0 -20
@@ -1,368 +0,0 @@
1
- /**
2
- * Remark plugin that transforms docfx-specific markdown syntax into
3
- * standard HTML / markdown that Starlight can render.
4
- *
5
- * Handles:
6
- * 1. {environment:...} variable substitution in text, links, and raw HTML
7
- * 2. <code-view> elements -> .ig-code-view placeholder divs (enhanced by code-view.js)
8
- * 3. <div class="divider--half"></div> -> <hr>
9
- * 4. Relative .md link rewriting for Astro trailing-slash URLs
10
- */
11
-
12
- import { visit } from 'unist-util-visit';
13
- import fs from 'node:fs';
14
- import path from 'node:path';
15
-
16
- // ENV is loaded lazily the first time replaceEnvVars() is called — NOT at
17
- // module load time. Module-level code runs while the Astro config is being
18
- // evaluated, before createDocsSite() has had a chance to set DOCS_SOURCE_PATH.
19
- // Deferring the load ensures we read the correct environment.json for the
20
- // active project (Angular, Blazor, React, WC, …).
21
- let _ENV: Record<string, string> | null = null;
22
- let _envSourcePath: string | null = null; // tracks which DOCS_SOURCE_PATH was used
23
-
24
- function loadEnv(): Record<string, string> {
25
- const currentPath = process.env.DOCS_SOURCE_PATH ?? null;
26
- // Re-load if the source path changed (e.g. two projects built in the same process)
27
- if (_ENV !== null && currentPath === _envSourcePath) return _ENV as Record<string, string>;
28
- _envSourcePath = currentPath;
29
- _ENV = null;
30
-
31
- if (!process.env.DOCS_SOURCE_PATH) { _ENV = {}; return _ENV as Record<string, string>; }
32
- const sourceRoot = path.resolve(process.env.DOCS_SOURCE_PATH);
33
-
34
- // Search order:
35
- // 1. {docsDir}/en/environment.json — docfx repo layout
36
- // 2. {docsDir}/environment.json — flat layout
37
- // 3. {docsDir}/../environment.json — xplat layout: docsDir = dist/{P}/{lang}/components,
38
- // environment.json lives one level up
39
- // 4. {docsDir}/../en/environment.json
40
- const parent = path.dirname(sourceRoot);
41
- const candidates = [
42
- path.join(sourceRoot, 'en', 'environment.json'),
43
- path.join(sourceRoot, 'environment.json'),
44
- path.join(parent, 'environment.json'),
45
- path.join(parent, 'en', 'environment.json'),
46
- ];
47
-
48
- const envPath = candidates.find(c => fs.existsSync(c));
49
- if (!envPath) { _ENV = {}; return _ENV; }
50
-
51
- try {
52
- const envData = JSON.parse(fs.readFileSync(envPath, 'utf-8'));
53
- // DOCS_ENV overrides explicitly (useful for staging builds).
54
- // Otherwise fall back to NODE_ENV ('development' | 'production').
55
- // Matches environment.json keys: development / staging / production.
56
- const envKey = process.env.DOCS_ENV ?? process.env.NODE_ENV ?? 'production';
57
- _ENV = envData[envKey] ?? envData.production ?? {};
58
- } catch {
59
- _ENV = {};
60
- }
61
-
62
- return _ENV as Record<string, string>;
63
- }
64
-
65
- const ENV_PATTERN = /\{environment:(\w+)\}/g;
66
-
67
- /**
68
- * Rewrite a relative .md link to a root-relative Astro URL.
69
- * Absolute, root-relative, fragment-only, and protocol links are left untouched.
70
- * @param url - Raw link URL from the markdown AST.
71
- * @param filePath - Absolute path of the current .md file.
72
- * @param docsDir - Absolute path to the docs root (DOCS_SOURCE_PATH).
73
- */
74
- function rewriteMdLink(url: string, filePath: string, docsDir: string): string {
75
- if (!url) return url;
76
- if (
77
- url.startsWith('http://') || url.startsWith('https://') ||
78
- url.startsWith('/') || url.startsWith('#') || url.startsWith('mailto:')
79
- ) return url;
80
-
81
- // Separate path from fragment / query-string suffix.
82
- const hashIdx = url.indexOf('#');
83
- const qIdx = url.indexOf('?');
84
- const splitAt = hashIdx !== -1 ? hashIdx : qIdx !== -1 ? qIdx : -1;
85
- let mdPath = splitAt !== -1 ? url.slice(0, splitAt) : url;
86
- const suffix = splitAt !== -1 ? url.slice(splitAt) : '';
87
-
88
- if (!mdPath.endsWith('.md')) return url;
89
-
90
- // Resolve the link relative to the current file's directory.
91
- const fileDir = path.dirname(filePath);
92
- const resolved = path.resolve(fileDir, mdPath);
93
-
94
- // Compute the slug: path relative to docsDir, forward slashes, no .md extension.
95
- const rel = path.relative(docsDir, resolved).replace(/\\/g, '/');
96
- const slug = rel.endsWith('.md') ? rel.slice(0, -3) : rel;
97
-
98
- // Return a URL with the site base prepended so links remain correct when
99
- // the site is mounted at a sub-path (e.g. /docs-react-new/).
100
- // DOCS_BASE is set by createDocsSite() in integration.ts; it is empty in dev mode.
101
- const docsBase = (process.env.DOCS_BASE ?? '').replace(/\/$/, '');
102
- return docsBase + '/' + slug.toLowerCase() + '/' + suffix;
103
- }
104
-
105
- export function replaceEnvVars(str: string): string {
106
- if (!str || typeof str !== 'string') return str;
107
- const env = loadEnv();
108
- return str.replace(ENV_PATTERN, (_match, key) => env[key] ?? `{environment:${key}}`);
109
- }
110
-
111
- /**
112
- * Build the pre-rendered widget HTML shell (matches the Sample.astro structure).
113
- * Picked up at runtime by sample-widget.ts via `.code-view[data-platform]`.
114
- */
115
- function buildWidgetHtml(
116
- src: string,
117
- demosBase: string,
118
- githubSrc: string,
119
- height: string,
120
- alt: string,
121
- platform: string,
122
- ): string {
123
- const widgetId = 'cw' + src.replace(/[^a-z0-9]/gi, '-');
124
- const tabId = `${widgetId}-example`;
125
- const safeAlt = alt.replace(/"/g, '&quot;');
126
- return (
127
- `<div class="code-view" id="${widgetId}"` +
128
- ` data-iframe-src="${src}"` +
129
- (demosBase ? ` data-demos-base-url="${demosBase}"` : '') +
130
- (githubSrc ? ` data-github-src="${githubSrc}"` : '') +
131
- ` data-platform="${platform}">` +
132
- `<div class="code-view-navbar">` +
133
- `<div class="code-view-tab code-view-tab--active" data-tab-id="${tabId}">EXAMPLE</div>` +
134
- `<span class="fs-button-container" title="Expand to fullscreen"></span>` +
135
- `</div>` +
136
- `<div class="code-views-container">` +
137
- `<div id="${tabId}" class="sample-container code-view-tab-content loading" style="height: ${height}">` +
138
- `<iframe data-src="${src}" title="${safeAlt}" style="width: 100%; height: 100%;" frameborder="0" seamless=""></iframe>` +
139
- `</div>` +
140
- `</div>` +
141
- `</div>`
142
- );
143
- }
144
-
145
- /**
146
- * Transform <code-view ...> ... </code-view> raw HTML blocks into the
147
- * pre-rendered widget shell consumed by sample-widget.ts at runtime.
148
- */
149
- function transformCodeView(html: string): string {
150
- return html.replace(
151
- /<code-view\s+([\s\S]*?)>\s*(?:<\/code-view>)?/g,
152
- (_match, attrs: string) => {
153
- const stackblitzMatch = attrs.match(/stackblitz="([^"]*)"/);
154
- const codesandboxMatch = attrs.match(/codesandbox="([^"]*)"/);
155
- const srcMatch = attrs.match(/iframe-src="([^"]*)"/);
156
- const demosBaseMatch = attrs.match(/data-demos-base-url="([^"]*)"/);
157
- const githubSrcMatch = attrs.match(/github-src="([^"]*)"/);
158
- const heightMatch = attrs.match(/style="height:\s*(\d+px)"/);
159
- const altMatch = attrs.match(/alt="([^"]*)"/);
160
- const height = heightMatch ? heightMatch[1] : '400px';
161
- const alt = altMatch ? altMatch[1] : 'Demo';
162
-
163
- // Explicit StackBlitz embed (stackblitz="<project-or-url>")
164
- if (stackblitzMatch) {
165
- const project = replaceEnvVars(stackblitzMatch[1]);
166
- const embedUrl = project.startsWith('http')
167
- ? project
168
- : `https://stackblitz.com/edit/${project}?embed=1&file=src/app/app.component.ts`;
169
- return `<iframe src="${embedUrl}" style="width:100%;height:${height};border:1px solid #e5e7eb;border-radius:8px;" title="${alt} (StackBlitz)" loading="lazy" allow="accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking" sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"></iframe>`;
170
- }
171
-
172
- // Explicit CodeSandbox embed (codesandbox="<project-or-url>")
173
- if (codesandboxMatch) {
174
- const project = replaceEnvVars(codesandboxMatch[1]);
175
- const embedUrl = project.startsWith('http')
176
- ? project
177
- : `https://codesandbox.io/embed/${project}?fontsize=14&hidenavigation=1&theme=light`;
178
- return `<iframe src="${embedUrl}" style="width:100%;height:${height};border:1px solid #e5e7eb;border-radius:8px;" title="${alt} (CodeSandbox)" loading="lazy" allow="accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking" sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"></iframe>`;
179
- }
180
-
181
- // Standard docfx code-view with iframe-src + data-demos-base-url.
182
- // Output the pre-rendered widget shell; sample-widget.ts activates it at runtime.
183
- if (srcMatch) {
184
- const src = replaceEnvVars(srcMatch[1]);
185
- if (!src || src.includes('{environment:')) return ''; // env var not resolved
186
- const demosBaseUrl = demosBaseMatch ? replaceEnvVars(demosBaseMatch[1]) : '';
187
- const githubSrc = githubSrcMatch ? githubSrcMatch[1] : '';
188
- const platform = process.env.DOCS_PLATFORM || 'angular';
189
- return buildWidgetHtml(src, demosBaseUrl, githubSrc, height, alt, platform);
190
- }
191
-
192
- return '';
193
- }
194
- );
195
- }
196
-
197
- /**
198
- * Transform <div class="divider--half"></div> into <hr>
199
- */
200
- function transformDividers(html: string): string {
201
- return html.replace(/<div\s+class="divider--half"\s*>\s*<\/div>/g, '<hr/>');
202
- }
203
-
204
- function strVal(v: unknown): string {
205
- return typeof v === 'string' ? v : Array.isArray(v) ? v.join(' ') : String(v ?? '');
206
- }
207
-
208
- /**
209
- * Rehype plugin — transforms <code-view> elements into the pre-rendered widget shell.
210
- *
211
- * Handles two HAST representations depending on what's in the pipeline:
212
- *
213
- * 1. `element` nodes (tagName === 'code-view') — produced when rehype-raw is
214
- * present and re-parses raw HTML fragments into proper HAST elements.
215
- *
216
- * 2. `raw` string nodes — produced when rehype-raw is NOT in the pipeline
217
- * (e.g. Astro content-collection .md files). In that case multiline
218
- * <code-view> blocks are opaque raw strings; we run the same regex
219
- * transformer used in the remark stage.
220
- */
221
- export function rehypeCodeView() {
222
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
223
- return (tree: any) => {
224
- // ── 1. element nodes (after rehype-raw) ──────────────────────────────────
225
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
226
- visit(tree, 'element', (node: any) => {
227
- if (node.tagName !== 'code-view') return;
228
-
229
- const p = node.properties || {};
230
-
231
- // HAST converts hyphenated attributes to camelCase via property-information.
232
- const iframeSrc = strVal(p.iframeSrc ?? p['iframe-src'] ?? '');
233
- const demosBase = strVal(p.dataDemosBaseUrl ?? p['data-demos-base-url'] ?? '');
234
- const githubSrc = strVal(p.githubSrc ?? p['github-src'] ?? '');
235
- const styleStr = strVal(p.style ?? '');
236
- const alt = strVal(p.alt ?? 'Demo');
237
-
238
- const src = replaceEnvVars(iframeSrc);
239
- const baseUrl = replaceEnvVars(demosBase);
240
-
241
- if (!src || src.includes('{environment:')) return;
242
-
243
- const heightMatch = styleStr.match(/height:\s*(\d+\s*px)/i);
244
- const height = heightMatch ? heightMatch[1].replace(/\s+/, '') : '400px';
245
- const platform = process.env.DOCS_PLATFORM || 'angular';
246
- const widgetId = 'cw' + src.replace(/[^a-z0-9]/gi, '-');
247
- const tabId = `${widgetId}-example`;
248
-
249
- node.tagName = 'div';
250
- node.properties = {
251
- className: ['code-view'],
252
- id: widgetId,
253
- 'data-iframe-src': src,
254
- 'data-platform': platform,
255
- ...(baseUrl ? { 'data-demos-base-url': baseUrl } : {}),
256
- ...(githubSrc ? { 'data-github-src': githubSrc } : {}),
257
- };
258
- node.children = [
259
- {
260
- type: 'element', tagName: 'div',
261
- properties: { className: ['code-view-navbar'] },
262
- children: [
263
- {
264
- type: 'element', tagName: 'div',
265
- properties: { className: ['code-view-tab', 'code-view-tab--active'], 'data-tab-id': tabId },
266
- children: [{ type: 'text', value: 'EXAMPLE' }],
267
- },
268
- {
269
- type: 'element', tagName: 'span',
270
- properties: { className: ['fs-button-container'], title: 'Expand to fullscreen' },
271
- children: [],
272
- },
273
- ],
274
- },
275
- {
276
- type: 'element', tagName: 'div',
277
- properties: { className: ['code-views-container'] },
278
- children: [
279
- {
280
- type: 'element', tagName: 'div',
281
- properties: {
282
- id: tabId,
283
- className: ['sample-container', 'code-view-tab-content', 'loading'],
284
- style: `height: ${height}`,
285
- },
286
- children: [
287
- {
288
- type: 'element', tagName: 'iframe',
289
- properties: {
290
- 'data-src': src,
291
- title: alt,
292
- style: 'width: 100%; height: 100%;',
293
- frameBorder: '0',
294
- seamless: '',
295
- },
296
- children: [],
297
- },
298
- ],
299
- },
300
- ],
301
- },
302
- ];
303
- });
304
-
305
- // ── 2. raw string nodes (no rehype-raw in pipeline) ──────────────────────
306
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
307
- visit(tree, 'raw', (node: any) => {
308
- if (!node.value || !node.value.includes('<code-view')) return;
309
- const updated = transformCodeView(replaceEnvVars(node.value as string));
310
- if (updated !== node.value) node.value = updated;
311
- });
312
- };
313
- }
314
-
315
- export function remarkDocfx() {
316
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
317
- return (tree: any, file: any) => {
318
- const filePath = (file.path as string) ?? '';
319
- const docsDir = process.env.DOCS_SOURCE_PATH
320
- ? path.resolve(process.env.DOCS_SOURCE_PATH)
321
- : (filePath ? path.dirname(filePath) : '');
322
- // 1. Walk the AST and replace environment variables in text/links/html
323
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
324
- visit(tree, (node: any) => {
325
- // Text nodes
326
- if (node.type === 'text' && node.value) {
327
- node.value = replaceEnvVars(node.value as string);
328
- }
329
-
330
- // Links
331
- if (node.type === 'link' && node.url) {
332
- node.url = replaceEnvVars(node.url as string);
333
- node.url = rewriteMdLink(node.url as string, filePath, docsDir);
334
- // Prepend DOCS_BASE to root-relative internal links that were not already
335
- // rewritten by rewriteMdLink (e.g. bare /grids/grid/… links that skip
336
- // the .md-only rewriter above).
337
- const docsBase = (process.env.DOCS_BASE ?? '').replace(/\/$/, '');
338
- if (
339
- docsBase &&
340
- (node.url as string).startsWith('/') &&
341
- !(node.url as string).startsWith('//') &&
342
- !(node.url as string).startsWith(docsBase + '/')
343
- ) {
344
- node.url = docsBase + (node.url as string);
345
- }
346
- }
347
-
348
- // Images
349
- if (node.type === 'image' && node.url) {
350
- node.url = replaceEnvVars(node.url as string);
351
- node.url = (node.url as string).replace(/^(\.\.\/)+images\//, '/images/');
352
- }
353
-
354
- // Code blocks — normalize language identifiers to lowercase
355
- if (node.type === 'code' && node.lang) {
356
- node.lang = (node.lang as string).toLowerCase();
357
- }
358
-
359
- // Inline HTML
360
- if (node.type === 'html' && node.value) {
361
- node.value = replaceEnvVars(node.value as string);
362
- node.value = transformCodeView(node.value as string);
363
- node.value = transformDividers(node.value as string);
364
- node.value = (node.value as string).replace(/src="(\.\.\/)+images\//g, 'src="/images/');
365
- }
366
- });
367
- };
368
- }
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Remark plugin: environment variable substitution.
3
+ *
4
+ * Replaces `{environment:key}` tokens in markdown text, link URLs, image URLs,
5
+ * and inline HTML with values from the project's environment.json.
6
+ *
7
+ * Resolution order for environment.json:
8
+ * 1. {DOCS_SOURCE_PATH}/en/environment.json
9
+ * 2. {DOCS_SOURCE_PATH}/environment.json
10
+ * 3. {DOCS_SOURCE_PATH}/../environment.json
11
+ * 4. {DOCS_SOURCE_PATH}/../en/environment.json
12
+ * 5. Fallback: read demosBaseUrl from docConfig.json
13
+ *
14
+ * DOCS_ENV (or NODE_ENV) selects the env block: development | staging | production.
15
+ */
16
+
17
+ import { visit } from 'unist-util-visit';
18
+ import fs from 'node:fs';
19
+ import path from 'node:path';
20
+
21
+ const ENV_PATTERN = /\{environment:(\w+)\}/g;
22
+
23
+ const DOCCONFIG_PLATFORM_MAP: Record<string, string> = {
24
+ angular: 'Angular',
25
+ react: 'React',
26
+ 'web-components': 'WebComponents',
27
+ blazor: 'Blazor',
28
+ };
29
+
30
+ // Lazy-loaded, cached per DOCS_SOURCE_PATH value.
31
+ let _env: Record<string, string> | null = null;
32
+ let _envSourcePath: string | null = null;
33
+
34
+ function loadEnv(): Record<string, string> {
35
+ const currentPath = process.env.DOCS_SOURCE_PATH ?? null;
36
+ if (_env !== null && currentPath === _envSourcePath) return _env;
37
+ _envSourcePath = currentPath;
38
+ _env = null;
39
+
40
+ if (!currentPath) { _env = {}; return _env; }
41
+ const sourceRoot = path.resolve(currentPath);
42
+ const parent = path.dirname(sourceRoot);
43
+
44
+ const candidates = [
45
+ path.join(sourceRoot, 'en', 'environment.json'),
46
+ path.join(sourceRoot, 'environment.json'),
47
+ path.join(parent, 'environment.json'),
48
+ path.join(parent, 'en', 'environment.json'),
49
+ ];
50
+
51
+ const envPath = candidates.find(c => fs.existsSync(c));
52
+
53
+ if (!envPath) {
54
+ try {
55
+ const envKey = process.env.DOCS_ENV ?? process.env.NODE_ENV ?? 'production';
56
+ const platform = DOCCONFIG_PLATFORM_MAP[process.env.DOCS_PLATFORM ?? ''] ?? '';
57
+ if (platform) {
58
+ const configPath = path.resolve(process.cwd(), 'docConfig.json');
59
+ const docConfig = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
60
+ const demosUrl: string =
61
+ docConfig[platform]?.samplesBrowsers?.[envKey] ??
62
+ docConfig[platform]?.samplesBrowsers?.['development'] ?? '';
63
+ _env = { dvDemosBaseUrl: demosUrl, demosBaseUrl: demosUrl, infragisticsBaseUrl: 'https://www.infragistics.com' };
64
+ } else {
65
+ _env = {};
66
+ }
67
+ } catch {
68
+ _env = {};
69
+ }
70
+ return _env;
71
+ }
72
+
73
+ try {
74
+ const data = JSON.parse(fs.readFileSync(envPath, 'utf-8'));
75
+ const envKey = process.env.DOCS_ENV ?? process.env.NODE_ENV ?? 'production';
76
+ _env = data[envKey] ?? data.production ?? {};
77
+ } catch {
78
+ _env = {};
79
+ }
80
+ return _env!;
81
+ }
82
+
83
+ /** Replace all `{environment:key}` tokens in a string. Exported for use by other modules. */
84
+ export function replaceEnvVars(str: string): string {
85
+ if (!str || typeof str !== 'string') return str;
86
+ const env = loadEnv();
87
+ return str.replace(ENV_PATTERN, (_match, key) => env[key] ?? `{environment:${key}}`);
88
+ }
89
+
90
+ /** Remark plugin that substitutes `{environment:key}` tokens in the markdown AST. */
91
+ export function remarkEnvVars() {
92
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
93
+ return (tree: any) => {
94
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
95
+ visit(tree, (node: any) => {
96
+ if (node.type === 'text' && node.value) {
97
+ node.value = replaceEnvVars(node.value);
98
+ }
99
+ if (node.type === 'link' && node.url) {
100
+ node.url = replaceEnvVars(node.url);
101
+ }
102
+ if (node.type === 'image' && node.url) {
103
+ node.url = replaceEnvVars(node.url);
104
+ }
105
+ if (node.type === 'html' && node.value) {
106
+ node.value = replaceEnvVars(node.value);
107
+ }
108
+ });
109
+ };
110
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Remark plugin: inline HTML transforms.
3
+ *
4
+ * Handles legacy HTML patterns in markdown content:
5
+ * - `<div class="divider--half"></div>` → `<hr/>`
6
+ * - Normalizes code block language identifiers to lowercase
7
+ */
8
+
9
+ import { visit } from 'unist-util-visit';
10
+
11
+ const DIVIDER_PATTERN = /<div\s+class="divider--half"\s*>\s*<\/div>/g;
12
+ const IMG_SRC_PATTERN = /src="(\.\.\/)+images\//g;
13
+
14
+ /** Remark plugin that transforms legacy HTML patterns in the AST. */
15
+ export function remarkHtmlTransforms() {
16
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
+ return (tree: any) => {
18
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
+ visit(tree, (node: any) => {
20
+ // Inline HTML: divider → hr, relative img src → root-relative
21
+ if (node.type === 'html' && node.value) {
22
+ node.value = (node.value as string).replace(DIVIDER_PATTERN, '<hr/>');
23
+ node.value = (node.value as string).replace(IMG_SRC_PATTERN, 'src="/images/');
24
+ }
25
+
26
+ // Code blocks: normalize language to lowercase
27
+ if (node.type === 'code' && node.lang) {
28
+ node.lang = (node.lang as string).toLowerCase();
29
+ }
30
+ });
31
+ };
32
+ }
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Remark plugin: rewrite relative .md links to Astro-compatible URLs.
3
+ *
4
+ * Transforms `[label](./some-page.md)` or `[label](../folder/page.md#section)`
5
+ * into root-relative URLs like `/products/.../some-page/` (with DOCS_BASE prepended).
6
+ *
7
+ * Also prepends DOCS_BASE to bare root-relative internal links (e.g. `/grids/grid/...`)
8
+ * that are already absolute but missing the site base path.
9
+ */
10
+
11
+ import { visit } from 'unist-util-visit';
12
+ import path from 'node:path';
13
+
14
+ /**
15
+ * Resolve a relative .md link to an absolute Astro URL.
16
+ * Non-relative, non-.md, and external links are returned unchanged.
17
+ */
18
+ function rewriteMdLink(url: string, filePath: string, docsDir: string): string {
19
+ if (!url) return url;
20
+ if (
21
+ url.startsWith('http://') || url.startsWith('https://') ||
22
+ url.startsWith('/') || url.startsWith('#') || url.startsWith('mailto:')
23
+ ) return url;
24
+
25
+ const hashIdx = url.indexOf('#');
26
+ const qIdx = url.indexOf('?');
27
+ const splitAt = hashIdx !== -1 ? hashIdx : qIdx !== -1 ? qIdx : -1;
28
+ let mdPath = splitAt !== -1 ? url.slice(0, splitAt) : url;
29
+ const suffix = splitAt !== -1 ? url.slice(splitAt) : '';
30
+
31
+ if (!mdPath.endsWith('.md')) return url;
32
+
33
+ const fileDir = path.dirname(filePath);
34
+ const resolved = path.resolve(fileDir, mdPath);
35
+ const rel = path.relative(docsDir, resolved).replace(/\\/g, '/');
36
+ const slug = rel.endsWith('.md') ? rel.slice(0, -3) : rel;
37
+
38
+ const docsBase = (process.env.DOCS_BASE ?? '').replace(/\/$/, '');
39
+ return docsBase + '/' + slug.toLowerCase() + '/' + suffix;
40
+ }
41
+
42
+ /** Remark plugin that rewrites relative .md links, prepends DOCS_BASE, and fixes relative image paths. */
43
+ export function remarkMdLinks() {
44
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
45
+ return (tree: any, file: any) => {
46
+ const filePath = (file.path as string) ?? '';
47
+ const docsDir = process.env.DOCS_SOURCE_PATH
48
+ ? path.resolve(process.env.DOCS_SOURCE_PATH)
49
+ : (filePath ? path.dirname(filePath) : '');
50
+
51
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
52
+ visit(tree, (node: any) => {
53
+ if (node.type === 'link' && node.url) {
54
+ node.url = rewriteMdLink(node.url as string, filePath, docsDir);
55
+
56
+ // Prepend DOCS_BASE to root-relative internal links not already prefixed.
57
+ const docsBase = (process.env.DOCS_BASE ?? '').replace(/\/$/, '');
58
+ if (
59
+ docsBase &&
60
+ (node.url as string).startsWith('/') &&
61
+ !(node.url as string).startsWith('//') &&
62
+ !(node.url as string).startsWith(docsBase + '/')
63
+ ) {
64
+ node.url = docsBase + (node.url as string);
65
+ }
66
+ }
67
+
68
+ // Rewrite relative `../images/` paths in markdown image nodes to root-relative `/images/`.
69
+ // Generated MDX files may contain relative image references that Vite cannot resolve.
70
+ if (node.type === 'image' && node.url) {
71
+ node.url = (node.url as string).replace(/^(\.\.\/)+images\//, '/images/');
72
+ }
73
+ });
74
+ };
75
+ }