sproutsite 0.0.0-stage → 0.5.7

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 (116) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +14 -0
  3. package/README.md +604 -2
  4. package/THIRD_PARTY_NOTICES.md +85 -0
  5. package/VERSION +1 -0
  6. package/package.json +107 -5
  7. package/src/lib/sproutsite/colors.ts +7 -0
  8. package/src/lib/sproutsite/language-links.ts +60 -0
  9. package/src/lib/sproutsite/pages.ts +78 -0
  10. package/src/lib/sproutsite/rehype-ids.ts +20 -0
  11. package/src/lib/sproutsite/rehype-links.ts +19 -0
  12. package/src/lib/sproutsite/rehype-tables.ts +74 -0
  13. package/src/lib/sproutsite/remark-links.ts +19 -0
  14. package/src/lib/sproutsite/site-config.ts +110 -0
  15. package/src/lib/sproutsite/sitemap.ts +160 -0
  16. package/src/lib/sproutsite/types.ts +45 -0
  17. package/src/lib/sproutsite/urls.ts +79 -0
  18. package/src/lib/sproutsite/validation.ts +1406 -0
  19. package/src/package/404.astro +5 -0
  20. package/src/package/500.astro +5 -0
  21. package/src/package/components.ts +17 -0
  22. package/src/package/config.ts +161 -0
  23. package/src/package/content.ts +117 -0
  24. package/src/package/index.ts +3 -0
  25. package/src/package/manifest.ts +27 -0
  26. package/src/package/page.astro +124 -0
  27. package/src/themes/default/assets/branding/apple-touch-icon.png +0 -0
  28. package/src/themes/default/assets/branding/favicon-16x16.png +0 -0
  29. package/src/themes/default/assets/branding/favicon-32x32.png +0 -0
  30. package/src/themes/default/assets/branding/favicon-48x48.png +0 -0
  31. package/src/themes/default/assets/branding/favicon.ico +0 -0
  32. package/src/themes/default/assets/branding/favicon.svg +1 -0
  33. package/src/themes/default/assets/branding/icon-192x192.png +0 -0
  34. package/src/themes/default/assets/branding/icon-512x512.png +0 -0
  35. package/src/themes/default/assets/branding/icon-monochrome.svg +1 -0
  36. package/src/themes/default/assets/branding/icon.svg +18 -0
  37. package/src/themes/default/assets/branding/logo-dark.svg +18 -0
  38. package/src/themes/default/assets/branding/logo-monochrome.svg +1 -0
  39. package/src/themes/default/assets/branding/logo.svg +18 -0
  40. package/src/themes/default/assets/branding/social-card.png +0 -0
  41. package/src/themes/default/assets/hero-waves.svg +41 -0
  42. package/src/themes/default/components/atoms/Badge/Badge.astro +65 -0
  43. package/src/themes/default/components/atoms/Badge/Badge.css +5 -0
  44. package/src/themes/default/components/atoms/BrandLogo/BrandLogo.astro +26 -0
  45. package/src/themes/default/components/atoms/BrandLogo/BrandLogo.css +22 -0
  46. package/src/themes/default/components/atoms/Button/Button.astro +106 -0
  47. package/src/themes/default/components/atoms/Button/Button.css +14 -0
  48. package/src/themes/default/components/atoms/ContentImage/ContentImage.astro +54 -0
  49. package/src/themes/default/components/atoms/ContentImage/ContentImage.css +21 -0
  50. package/src/themes/default/components/atoms/Eyebrow/Eyebrow.astro +3 -0
  51. package/src/themes/default/components/atoms/Eyebrow/Eyebrow.css +18 -0
  52. package/src/themes/default/components/atoms/Icon/Icon.astro +80 -0
  53. package/src/themes/default/components/atoms/Icon/Icon.css +68 -0
  54. package/src/themes/default/components/atoms/Tab/Tab.astro +15 -0
  55. package/src/themes/default/components/atoms/Tab/Tab.css +34 -0
  56. package/src/themes/default/components/layout/Column/Column.astro +18 -0
  57. package/src/themes/default/components/layout/Column/Column.css +82 -0
  58. package/src/themes/default/components/layout/Columns/Columns.astro +163 -0
  59. package/src/themes/default/components/layout/Columns/Columns.css +177 -0
  60. package/src/themes/default/components/molecules/Accordion/Accordion.astro +17 -0
  61. package/src/themes/default/components/molecules/Accordion/Accordion.css +11 -0
  62. package/src/themes/default/components/molecules/Accordion/accordion.ts +47 -0
  63. package/src/themes/default/components/molecules/AccordionItem/AccordionItem.astro +100 -0
  64. package/src/themes/default/components/molecules/AccordionItem/AccordionItem.css +118 -0
  65. package/src/themes/default/components/molecules/Alert/Alert.astro +42 -0
  66. package/src/themes/default/components/molecules/Alert/Alert.css +13 -0
  67. package/src/themes/default/components/molecules/Card/Card.astro +57 -0
  68. package/src/themes/default/components/molecules/Card/Card.css +25 -0
  69. package/src/themes/default/components/molecules/CardActions/CardActions.astro +3 -0
  70. package/src/themes/default/components/molecules/CardActions/CardActions.css +13 -0
  71. package/src/themes/default/components/molecules/ContentTable/ContentTable.astro +42 -0
  72. package/src/themes/default/components/molecules/ContentTable/ContentTable.css +59 -0
  73. package/src/themes/default/components/molecules/Feature/Feature.astro +108 -0
  74. package/src/themes/default/components/molecules/Feature/Feature.css +157 -0
  75. package/src/themes/default/components/molecules/FoundationSample/FoundationSample.astro +165 -0
  76. package/src/themes/default/components/molecules/FoundationSample/FoundationSample.css +201 -0
  77. package/src/themes/default/components/molecules/LanguageSwitcher/LanguageSwitcher.astro +118 -0
  78. package/src/themes/default/components/molecules/LanguageSwitcher/LanguageSwitcher.css +134 -0
  79. package/src/themes/default/components/molecules/Tabs/Tabs.astro +33 -0
  80. package/src/themes/default/components/molecules/Tabs/Tabs.css +38 -0
  81. package/src/themes/default/components/molecules/Tabs/tabs.ts +91 -0
  82. package/src/themes/default/components/organisms/BlogIndex/BlogIndex.astro +86 -0
  83. package/src/themes/default/components/organisms/BlogIndex/BlogIndex.css +17 -0
  84. package/src/themes/default/components/organisms/BlogPost/BlogPost.astro +51 -0
  85. package/src/themes/default/components/organisms/BlogPost/BlogPost.css +5 -0
  86. package/src/themes/default/components/organisms/Footer/Footer.astro +57 -0
  87. package/src/themes/default/components/organisms/Footer/Footer.css +63 -0
  88. package/src/themes/default/components/organisms/Header/Header.astro +223 -0
  89. package/src/themes/default/components/organisms/Header/Header.css +282 -0
  90. package/src/themes/default/components/organisms/Hero/Hero.astro +106 -0
  91. package/src/themes/default/components/organisms/Hero/Hero.css +187 -0
  92. package/src/themes/default/components/organisms/PageTitle/PageTitle.astro +39 -0
  93. package/src/themes/default/components/organisms/PageTitle/PageTitle.css +25 -0
  94. package/src/themes/default/components/organisms/Section/Section.astro +39 -0
  95. package/src/themes/default/components/organisms/Section/Section.css +21 -0
  96. package/src/themes/default/i18n/de.yaml +38 -0
  97. package/src/themes/default/i18n/en.yaml +38 -0
  98. package/src/themes/default/i18n/index.ts +63 -0
  99. package/src/themes/default/layouts/ErrorPage/ErrorPage.astro +110 -0
  100. package/src/themes/default/layouts/PageLayout/PageLayout.astro +108 -0
  101. package/src/themes/default/layouts/PageLayout/PageLayout.css +15 -0
  102. package/src/themes/default/styles/foundation/base.css +19 -0
  103. package/src/themes/default/styles/foundation/focus.css +6 -0
  104. package/src/themes/default/styles/foundation/fonts/OFL.txt +93 -0
  105. package/src/themes/default/styles/foundation/fonts/nunito-latin-variable.woff2 +0 -0
  106. package/src/themes/default/styles/foundation/fonts.css +17 -0
  107. package/src/themes/default/styles/foundation/layout.css +6 -0
  108. package/src/themes/default/styles/foundation/prose.css +54 -0
  109. package/src/themes/default/styles/foundation/tokens.css +48 -0
  110. package/src/themes/default/styles/theme.css +99 -0
  111. package/src/themes/default/styles/themes/section-tones.css +30 -0
  112. package/third-party-licenses/daisyui-LICENSE +21 -0
  113. package/third-party-licenses/flag-icons-LICENSE +21 -0
  114. package/third-party-licenses/lucide-LICENSE +43 -0
  115. package/third-party-licenses/tailwindcss-LICENSE +21 -0
  116. package/third-party-licenses/tailwindcss-typography-LICENSE +21 -0
@@ -0,0 +1,1406 @@
1
+ import { readdirSync, readFileSync, statSync } from 'node:fs';
2
+ import { extname, join, relative, resolve } from 'node:path';
3
+ import GithubSlugger from 'github-slugger';
4
+ import type { Root } from 'mdast';
5
+ import { z } from 'zod';
6
+ import { parse as parseYaml } from 'yaml';
7
+ import { unified } from 'unified';
8
+ import remarkParse from 'remark-parse';
9
+ import remarkMdx from 'remark-mdx';
10
+ import remarkGfm from 'remark-gfm';
11
+ import { visit } from 'unist-util-visit';
12
+ import { loadSiteConfig } from './site-config.js';
13
+ import { heroTypes, sectionSpacings, tones } from './types.js';
14
+ import { isHexColor } from './colors.js';
15
+ import { routeFromPageId } from './urls.js';
16
+
17
+ const pageSchema = z.object({
18
+ title: z.string().trim().min(1),
19
+ description: z.string().trim().min(1),
20
+ layout: z.enum(['default', 'landing']).default('default'),
21
+ url: z
22
+ .string()
23
+ .trim()
24
+ .regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, {
25
+ message: 'must use lowercase letters, digits, and hyphens',
26
+ })
27
+ .optional(),
28
+ });
29
+ const markdownSchema = z
30
+ .object({
31
+ tone: z.enum(tones).optional(),
32
+ eyebrow: z.string().trim().min(1).optional(),
33
+ })
34
+ .strict();
35
+ const sectionSchema = markdownSchema.extend({
36
+ tone: z
37
+ .union(
38
+ [
39
+ z.enum(tones),
40
+ z.object({ odd: z.enum(tones), even: z.enum(tones) }).strict(),
41
+ ],
42
+ {
43
+ error: 'Expected default, muted, or brand, or a YAML object with both odd and even set to those tones (not a list).',
44
+ },
45
+ )
46
+ .optional(),
47
+ fullWidth: z.boolean().optional(),
48
+ spacing: z.enum(sectionSpacings).optional(),
49
+ });
50
+ const heroClass = z.string().regex(/^ss-[a-z0-9][a-z0-9_-]*$/, {
51
+ message:
52
+ 'must start with ss- and contain only lowercase letters, digits, underscores, or hyphens',
53
+ });
54
+ const heroAction = z
55
+ .object({
56
+ label: z.string().trim().min(1),
57
+ href: z.string().trim().min(1),
58
+ variant: z.enum(['primary', 'secondary']),
59
+ })
60
+ .strict();
61
+ const heroSchema = markdownSchema
62
+ .extend({
63
+ title: z.string().trim().min(1),
64
+ type: z.enum(heroTypes).default('small'),
65
+ titleHighlight: z
66
+ .string()
67
+ .trim()
68
+ .min(1)
69
+ .refine((value) => !value.includes('\n'), {
70
+ message: 'must not contain a line break',
71
+ })
72
+ .optional(),
73
+ classes: z.array(heroClass).max(8).nullable().optional(),
74
+ 'background-image': z.string().trim().min(1).optional(),
75
+ actions: z.array(heroAction).min(1).max(2).optional(),
76
+ claim: z.string().trim().min(1).optional(),
77
+ tagline: z.string().trim().min(1).optional(),
78
+ })
79
+ .superRefine((hero, context) => {
80
+ if (hero.titleHighlight && !hero.title.includes(hero.titleHighlight)) {
81
+ context.addIssue({
82
+ code: 'custom',
83
+ path: ['titleHighlight'],
84
+ message: 'must occur in title',
85
+ });
86
+ }
87
+ });
88
+ const sectionPattern = /^\d{2,}-[a-z0-9][a-z0-9-]*\.(?:md|mdx)$/;
89
+ const localizedContentFile = /\.de\.(?:md|mdx|yaml)$/;
90
+ const mdxComponentImport =
91
+ /^import\s*\{\s*Column\s*,\s*Columns(?:\s*,\s*Eyebrow)?\s*\}\s*from\s*['"]sproutsite\/components['"];?$/;
92
+ const eyebrowComponentImport =
93
+ /^import\s*\{\s*Eyebrow\s*\}\s*from\s*['"]sproutsite\/components['"];?$/;
94
+ const alertComponentImport =
95
+ /^import\s*\{\s*Alert\s*\}\s*from\s*['"]sproutsite\/components['"];?$/;
96
+ const contentImageComponentImport =
97
+ /^import\s*\{\s*ContentImage\s*\}\s*from\s*['"]sproutsite\/components['"];?$/;
98
+ const cardComponentImport =
99
+ /^import\s*\{\s*Card(?:\s*,\s*CardActions)?\s*\}\s*from\s*['"]sproutsite\/components['"];?$/;
100
+ const tabsComponentImport =
101
+ /^import\s*\{\s*Tabs\s*,\s*Tab\s*\}\s*from\s*['"]sproutsite\/components['"];?$/;
102
+ const contentTableImport =
103
+ /^import\s*\{\s*ContentTable\s*\}\s*from\s*['"]sproutsite\/components['"];?$/;
104
+ const foundationSampleImport =
105
+ /^import\s*\{\s*FoundationSample\s*\}\s*from\s*['"]sproutsite\/components['"];?$/;
106
+ const buttonComponentImport =
107
+ /^import\s*\{\s*Button\s*\}\s*from\s*['"]sproutsite\/components['"];?$/;
108
+ const badgeComponentImport =
109
+ /^import\s*\{\s*Badge\s*\}\s*from\s*['"]sproutsite\/components['"];?$/;
110
+ const iconComponentImport =
111
+ /^import\s*\{\s*Icon\s*\}\s*from\s*['"]sproutsite\/components['"];?$/;
112
+ const featureComponentImport =
113
+ /^import\s*\{\s*Feature\s*\}\s*from\s*['"]sproutsite\/components['"];?$/;
114
+ const accordionComponentImport =
115
+ /^import\s*\{\s*Accordion\s*,\s*AccordionItem\s*\}\s*from\s*['"]sproutsite\/components['"];?$/;
116
+ const localImageImport =
117
+ /^import\s+([A-Za-z_$][\w$]*)\s+from\s+['"](?:\.\.\/|\.\/)[a-z0-9_][a-z0-9._/-]*\.(?:avif|jpe?g|png|webp)['"];?$/i;
118
+ const imageExtensions = new Set(['.avif', '.jpeg', '.jpg', '.png', '.webp']);
119
+
120
+ interface MdxNode {
121
+ type: string;
122
+ name?: string | null;
123
+ value?: string;
124
+ attributes?: MdxAttribute[];
125
+ children?: MdxNode[];
126
+ }
127
+
128
+ interface MdxAttribute {
129
+ type: string;
130
+ name?: string;
131
+ value?: string | { type: string; value?: string } | null;
132
+ }
133
+
134
+ function filesIn(directory: string): string[] {
135
+ return readdirSync(directory).flatMap((name) => {
136
+ const path = join(directory, name);
137
+ return statSync(path).isDirectory() ? filesIn(path) : [path];
138
+ });
139
+ }
140
+
141
+ function fail(contentRoot: string, path: string, message: string): never {
142
+ const displayPath =
143
+ relative(process.cwd(), path) || relative(contentRoot, path);
144
+ throw new Error(`${displayPath}: ${message}`);
145
+ }
146
+
147
+ function contentDirectory(contentRoot: string, path: string): string {
148
+ const directory = relative(contentRoot, join(path, '..')).replaceAll(
149
+ '\\',
150
+ '/',
151
+ );
152
+ return directory === '.' ? '' : directory;
153
+ }
154
+
155
+ function isReservedContentDirectory(directory: string): boolean {
156
+ return directory.split('/').some((segment) => segment.startsWith('_'));
157
+ }
158
+
159
+ function frontmatterAndTree(path: string) {
160
+ const source = readFileSync(path, 'utf8');
161
+ const match = source.match(/^---\s*\n([\s\S]*?)\n---\s*\n?/);
162
+ const frontmatter = match ? parseYaml(match[1]) : {};
163
+ const body = match ? source.slice(match[0].length) : source;
164
+ const processor = unified().use(remarkParse).use(remarkGfm);
165
+ if (path.endsWith('.mdx')) processor.use(remarkMdx);
166
+ return { frontmatter, tree: processor.parse(body) };
167
+ }
168
+
169
+ function validateMdxLayout(
170
+ contentRoot: string,
171
+ path: string,
172
+ tree: Root,
173
+ ): void {
174
+ let hasComponentImport = false;
175
+ let columnsCount = 0;
176
+ let tabsCount = 0;
177
+ let contentTableCount = 0;
178
+ let foundationSampleCount = 0;
179
+ let alertCount = 0;
180
+ let contentImageCount = 0;
181
+ let cardCount = 0;
182
+ let eyebrowCount = 0;
183
+ let buttonCount = 0;
184
+ let badgeCount = 0;
185
+ let iconCount = 0;
186
+ let featureCount = 0;
187
+ let accordionCount = 0;
188
+ const validatedAccordionItems = new Set<MdxNode>();
189
+ const localImageImports = new Set<string>();
190
+ const validatedColumns = new Set<MdxNode>();
191
+ const validatedTabs = new Set<MdxNode>();
192
+ const validatedCardActions = new Set<MdxNode>();
193
+
194
+ visit(tree, (node) => {
195
+ const mdxNode = node as MdxNode;
196
+ if (mdxNode.type === 'mdxjsEsm') {
197
+ const imports = (mdxNode.value?.trim() ?? '')
198
+ .split('\n')
199
+ .map((statement) => statement.trim())
200
+ .filter(Boolean);
201
+ for (const importValue of imports) {
202
+ const localImageMatch = importValue.match(localImageImport);
203
+ if (localImageMatch) {
204
+ localImageImports.add(localImageMatch[1]);
205
+ continue;
206
+ }
207
+ if (
208
+ !mdxComponentImport.test(importValue) &&
209
+ !eyebrowComponentImport.test(importValue) &&
210
+ !alertComponentImport.test(importValue) &&
211
+ !contentImageComponentImport.test(importValue) &&
212
+ !cardComponentImport.test(importValue) &&
213
+ !tabsComponentImport.test(importValue) &&
214
+ !foundationSampleImport.test(importValue) &&
215
+ !contentTableImport.test(importValue) &&
216
+ !buttonComponentImport.test(importValue) &&
217
+ !badgeComponentImport.test(importValue) &&
218
+ !iconComponentImport.test(importValue) &&
219
+ !featureComponentImport.test(importValue) &&
220
+ !accordionComponentImport.test(importValue)
221
+ )
222
+ fail(
223
+ contentRoot,
224
+ path,
225
+ 'MDX may only import supported components from sproutsite/components and local relative images',
226
+ );
227
+ hasComponentImport = true;
228
+ }
229
+ }
230
+ if (
231
+ mdxNode.type === 'mdxFlowExpression' ||
232
+ mdxNode.type === 'mdxTextExpression'
233
+ )
234
+ fail(contentRoot, path, 'MDX expressions are not allowed');
235
+ if (
236
+ mdxNode.type === 'mdxJsxFlowElement' ||
237
+ mdxNode.type === 'mdxJsxTextElement'
238
+ ) {
239
+ if (mdxNode.name === 'Accordion') {
240
+ accordionCount += 1;
241
+ const attributes = mdxNode.attributes ?? [];
242
+ const children = mdxNode.children ?? [];
243
+ const items = children.filter(
244
+ (child) =>
245
+ child.type === 'mdxJsxFlowElement' &&
246
+ child.name === 'AccordionItem',
247
+ );
248
+ const isBoolean = (value: unknown) =>
249
+ value === null ||
250
+ (typeof value === 'object' &&
251
+ value !== null &&
252
+ 'value' in value &&
253
+ ['true', 'false'].includes(String(value.value)));
254
+ if (
255
+ attributes.length > 1 ||
256
+ attributes.some(
257
+ (attribute) =>
258
+ attribute.type !== 'mdxJsxAttribute' ||
259
+ attribute.name !== 'multiple' ||
260
+ !isBoolean(attribute.value),
261
+ ) ||
262
+ items.length === 0 ||
263
+ children.some(
264
+ (child) =>
265
+ !items.includes(child) &&
266
+ !(child.type === 'text' && !child.value?.trim()),
267
+ )
268
+ )
269
+ fail(
270
+ contentRoot,
271
+ path,
272
+ 'Accordion accepts optional boolean multiple and requires direct AccordionItem children.',
273
+ );
274
+ const multipleValue = attributes[0]?.value;
275
+ const multiple =
276
+ attributes.length > 0 &&
277
+ (multipleValue === null ||
278
+ (typeof multipleValue === 'object' &&
279
+ multipleValue?.value === 'true'));
280
+ const initiallyOpen = items.filter((item) =>
281
+ item.attributes?.some(
282
+ (attribute) =>
283
+ attribute.name === 'open' &&
284
+ (attribute.value === null ||
285
+ (typeof attribute.value === 'object' &&
286
+ attribute.value?.value === 'true')),
287
+ ),
288
+ );
289
+ if (!multiple && initiallyOpen.length > 1)
290
+ fail(
291
+ contentRoot,
292
+ path,
293
+ 'Accordion without multiple permits only one initially open item.',
294
+ );
295
+ items.forEach((item) => validatedAccordionItems.add(item));
296
+ } else if (mdxNode.name === 'AccordionItem') {
297
+ const attributes = mdxNode.attributes ?? [];
298
+ const value = (name: string) =>
299
+ attributes.find((attribute) => attribute.name === name)
300
+ ?.value;
301
+ const title = value('title');
302
+ const color = value('color');
303
+ const icon = value('icon');
304
+ const open = attributes.find(
305
+ (attribute) => attribute.name === 'open',
306
+ );
307
+ if (
308
+ !validatedAccordionItems.has(mdxNode) ||
309
+ typeof title !== 'string' ||
310
+ !title.trim() ||
311
+ attributes.some(
312
+ (attribute) =>
313
+ attribute.type !== 'mdxJsxAttribute' ||
314
+ ![
315
+ 'title',
316
+ 'icon',
317
+ 'color',
318
+ 'backgroundColor',
319
+ 'surfaceColor',
320
+ 'openSurfaceColor',
321
+ 'openBorderColor',
322
+ 'open',
323
+ ].includes(attribute.name ?? ''),
324
+ ) ||
325
+ new Set(attributes.map((attribute) => attribute.name))
326
+ .size !== attributes.length ||
327
+ (icon !== undefined &&
328
+ (typeof icon !== 'string' ||
329
+ !/^[A-Z][A-Za-z0-9]*$/.test(icon))) ||
330
+ (color !== undefined &&
331
+ (typeof color !== 'string' ||
332
+ (!isHexColor(color) &&
333
+ ![
334
+ 'primary',
335
+ 'secondary',
336
+ 'accent',
337
+ 'neutral',
338
+ 'info',
339
+ 'success',
340
+ 'warning',
341
+ 'error',
342
+ ].includes(color)))) ||
343
+ [
344
+ 'backgroundColor',
345
+ 'surfaceColor',
346
+ 'openSurfaceColor',
347
+ 'openBorderColor',
348
+ ].some(
349
+ (name) =>
350
+ value(name) !== undefined &&
351
+ !isHexColor(value(name)),
352
+ ) ||
353
+ (open &&
354
+ !(
355
+ open.value === null ||
356
+ (typeof open.value === 'object' &&
357
+ ['true', 'false'].includes(
358
+ open.value?.value ?? '',
359
+ ))
360
+ ))
361
+ )
362
+ fail(
363
+ contentRoot,
364
+ path,
365
+ 'AccordionItem must be a direct child of Accordion with a non-empty title, optional PascalCase icon, semantic or hex color, hex backgroundColor/surfaceColor/openSurfaceColor/openBorderColor, and boolean open.',
366
+ );
367
+ } else if (mdxNode.name === 'Feature') {
368
+ featureCount += 1;
369
+ const attributes = mdxNode.attributes ?? [];
370
+ const value = (name: string) =>
371
+ attributes.find((attribute) => attribute.name === name)
372
+ ?.value;
373
+ const icon = value('icon');
374
+ const title = value('title');
375
+ const layout = value('layout');
376
+ const iconSize = value('iconSize');
377
+ const variant = value('variant');
378
+ const color = value('color');
379
+ const backgroundColor = value('backgroundColor');
380
+ const heading = value('headingLevel');
381
+ const headingValue =
382
+ heading !== null && typeof heading === 'object'
383
+ ? heading.value
384
+ : undefined;
385
+ if (
386
+ attributes.some(
387
+ (attribute) =>
388
+ attribute.type !== 'mdxJsxAttribute' ||
389
+ ![
390
+ 'icon',
391
+ 'title',
392
+ 'layout',
393
+ 'iconSize',
394
+ 'variant',
395
+ 'color',
396
+ 'backgroundColor',
397
+ 'headingLevel',
398
+ ].includes(attribute.name ?? ''),
399
+ ) ||
400
+ new Set(attributes.map((attribute) => attribute.name))
401
+ .size !== attributes.length ||
402
+ typeof icon !== 'string' ||
403
+ !/^[A-Z][A-Za-z0-9]*$/.test(icon) ||
404
+ typeof title !== 'string' ||
405
+ !title.trim() ||
406
+ (backgroundColor !== undefined &&
407
+ !isHexColor(backgroundColor)) ||
408
+ (iconSize !== undefined &&
409
+ (typeof iconSize !== 'string' ||
410
+ !['xs', 'sm', 'md', 'lg', 'xl'].includes(
411
+ iconSize,
412
+ ))) ||
413
+ (layout !== undefined &&
414
+ (typeof layout !== 'string' ||
415
+ !['horizontal', 'vertical', 'card'].includes(
416
+ layout,
417
+ ))) ||
418
+ (variant !== undefined &&
419
+ !['soft', 'solid', 'plain'].includes(
420
+ String(variant),
421
+ )) ||
422
+ (color !== undefined &&
423
+ ![
424
+ 'primary',
425
+ 'secondary',
426
+ 'accent',
427
+ 'neutral',
428
+ 'info',
429
+ 'success',
430
+ 'warning',
431
+ 'error',
432
+ ].includes(String(color)) &&
433
+ !isHexColor(color)) ||
434
+ (heading !== undefined &&
435
+ !['2', '3', '4', '5', '6'].includes(headingValue ?? ''))
436
+ )
437
+ fail(
438
+ contentRoot,
439
+ path,
440
+ 'Feature requires a canonical PascalCase icon and non-empty title; layout is horizontal, vertical, or card, iconSize is xs, sm, md, lg, or xl, variant is soft, solid, or plain, color is a semantic theme color or valid CSS hex color, and headingLevel is a numeric literal from 2 to 6',
441
+ );
442
+ } else if (mdxNode.name === 'Icon') {
443
+ iconCount += 1;
444
+ const attributes = mdxNode.attributes ?? [];
445
+ const name = attributes.find(
446
+ (attribute) => attribute.name === 'name',
447
+ );
448
+ const label = attributes.find(
449
+ (attribute) => attribute.name === 'label',
450
+ );
451
+ const color = attributes.find(
452
+ (attribute) => attribute.name === 'color',
453
+ );
454
+ const background = attributes.find(
455
+ (attribute) => attribute.name === 'background',
456
+ );
457
+ const numbersValid = attributes
458
+ .filter((attribute) =>
459
+ ['size', 'strokeWidth'].includes(attribute.name ?? ''),
460
+ )
461
+ .every((attribute) => {
462
+ const value = attribute.value;
463
+ return (
464
+ value !== null &&
465
+ typeof value === 'object' &&
466
+ /^\d+(?:\.\d+)?$/.test(value.value ?? '') &&
467
+ Number(value.value) > 0 &&
468
+ Number.isFinite(Number(value.value))
469
+ );
470
+ });
471
+ if (
472
+ attributes.some(
473
+ (attribute) =>
474
+ attribute.type !== 'mdxJsxAttribute' ||
475
+ ![
476
+ 'name',
477
+ 'size',
478
+ 'strokeWidth',
479
+ 'color',
480
+ 'background',
481
+ 'label',
482
+ ].includes(attribute.name ?? ''),
483
+ ) ||
484
+ new Set(attributes.map((attribute) => attribute.name))
485
+ .size !== attributes.length ||
486
+ typeof name?.value !== 'string' ||
487
+ !/^[A-Z][A-Za-z0-9]*$/.test(name.value) ||
488
+ (label &&
489
+ (typeof label.value !== 'string' ||
490
+ !label.value.trim())) ||
491
+ (color &&
492
+ ![
493
+ 'inherit',
494
+ 'primary',
495
+ 'secondary',
496
+ 'accent',
497
+ 'info',
498
+ 'success',
499
+ 'warning',
500
+ 'error',
501
+ ].includes(String(color.value))) ||
502
+ (background &&
503
+ ![
504
+ 'primary',
505
+ 'secondary',
506
+ 'accent',
507
+ 'neutral',
508
+ 'info',
509
+ 'success',
510
+ 'warning',
511
+ 'error',
512
+ ].includes(String(background.value))) ||
513
+ !numbersValid ||
514
+ (mdxNode.children ?? []).some(
515
+ (child) => child.type !== 'text' || child.value?.trim(),
516
+ )
517
+ )
518
+ fail(
519
+ contentRoot,
520
+ path,
521
+ 'Icon requires a canonical PascalCase name; optional size and strokeWidth are positive numeric literals, color is inherit or a semantic theme color, background is a semantic theme color, label is non-empty, and children are not allowed',
522
+ );
523
+ } else if (mdxNode.name === 'ContentTable') {
524
+ contentTableCount += 1;
525
+ const attributes = mdxNode.attributes ?? [];
526
+ const caption = attributes.find(
527
+ (attribute) => attribute.name === 'caption',
528
+ );
529
+ const variant = attributes.find(
530
+ (attribute) => attribute.name === 'variant',
531
+ );
532
+ const density = attributes.find(
533
+ (attribute) => attribute.name === 'density',
534
+ );
535
+ const wide = attributes.find(
536
+ (attribute) => attribute.name === 'wide',
537
+ );
538
+ const highlight = attributes.find(
539
+ (attribute) => attribute.name === 'highlight',
540
+ );
541
+ const highlightValue = highlight?.value;
542
+ const rowNumber = Number(
543
+ highlightValue && typeof highlightValue === 'object'
544
+ ? highlightValue.value
545
+ : undefined,
546
+ );
547
+ const children = (mdxNode.children ?? []).filter(
548
+ (child) => !(child.type === 'text' && !child.value?.trim()),
549
+ );
550
+ const table = children[0];
551
+ const rowCount = (table?.children?.length ?? 1) - 1;
552
+ if (
553
+ attributes.some(
554
+ (attribute) =>
555
+ attribute.type !== 'mdxJsxAttribute' ||
556
+ ![
557
+ 'caption',
558
+ 'variant',
559
+ 'density',
560
+ 'wide',
561
+ 'highlight',
562
+ ].includes(attribute.name ?? ''),
563
+ ) ||
564
+ new Set(attributes.map((attribute) => attribute.name))
565
+ .size !== attributes.length ||
566
+ typeof caption?.value !== 'string' ||
567
+ !caption.value.trim() ||
568
+ (variant &&
569
+ !['plain', 'striped'].includes(
570
+ String(variant.value),
571
+ )) ||
572
+ (density &&
573
+ !['comfortable', 'compact'].includes(
574
+ String(density.value),
575
+ )) ||
576
+ (wide && wide.value !== null) ||
577
+ children.length !== 1 ||
578
+ table?.type !== 'table' ||
579
+ (highlight &&
580
+ (!Number.isInteger(rowNumber) ||
581
+ rowNumber < 1 ||
582
+ rowNumber > rowCount))
583
+ )
584
+ fail(
585
+ contentRoot,
586
+ path,
587
+ 'ContentTable requires a caption and exactly one Markdown table; variant is plain or striped, density is comfortable or compact, wide is a boolean flag, and highlight must be an existing body row number',
588
+ );
589
+ } else if (mdxNode.name === 'FoundationSample') {
590
+ foundationSampleCount += 1;
591
+ const attributes = mdxNode.attributes ?? [];
592
+ const kind = attributes[0];
593
+ if (
594
+ attributes.length !== 1 ||
595
+ kind?.type !== 'mdxJsxAttribute' ||
596
+ kind.name !== 'kind' ||
597
+ typeof kind.value !== 'string' ||
598
+ ![
599
+ 'colors',
600
+ 'type',
601
+ 'spacing',
602
+ 'radius',
603
+ 'shadow',
604
+ 'focus',
605
+ ].includes(kind.value) ||
606
+ mdxNode.children?.length
607
+ )
608
+ fail(
609
+ contentRoot,
610
+ path,
611
+ 'FoundationSample accepts exactly one kind: colors, type, spacing, radius, shadow, or focus, and no children',
612
+ );
613
+ } else if (mdxNode.name === 'Tabs') {
614
+ tabsCount += 1;
615
+ const attributes = mdxNode.attributes ?? [];
616
+ const label = attributes.find(
617
+ (attribute) => attribute.name === 'label',
618
+ );
619
+ const variant = attributes.find(
620
+ (attribute) => attribute.name === 'variant',
621
+ );
622
+ const initial = attributes.find(
623
+ (attribute) => attribute.name === 'initial',
624
+ );
625
+ const initialValue = initial?.value;
626
+ const initialNumber = initial
627
+ ? Number(
628
+ initialValue && typeof initialValue === 'object'
629
+ ? initialValue.value
630
+ : undefined,
631
+ )
632
+ : 1;
633
+ const children = mdxNode.children ?? [];
634
+ const tabs = children.filter(
635
+ (child) =>
636
+ child.type === 'mdxJsxFlowElement' &&
637
+ child.name === 'Tab',
638
+ );
639
+ if (
640
+ attributes.some(
641
+ (attribute) =>
642
+ attribute.type !== 'mdxJsxAttribute' ||
643
+ !['label', 'variant', 'initial'].includes(
644
+ attribute.name ?? '',
645
+ ),
646
+ ) ||
647
+ new Set(attributes.map((attribute) => attribute.name))
648
+ .size !== attributes.length ||
649
+ typeof label?.value !== 'string' ||
650
+ !label.value.trim() ||
651
+ (variant &&
652
+ !['border', 'box', 'lift'].includes(
653
+ String(variant.value),
654
+ )) ||
655
+ tabs.length < 1 ||
656
+ children.some(
657
+ (child) =>
658
+ !(
659
+ child.type === 'mdxJsxFlowElement' &&
660
+ child.name === 'Tab'
661
+ ) &&
662
+ !(child.type === 'text' && !child.value?.trim()),
663
+ ) ||
664
+ !Number.isInteger(initialNumber) ||
665
+ initialNumber < 1 ||
666
+ initialNumber > tabs.length
667
+ )
668
+ fail(
669
+ contentRoot,
670
+ path,
671
+ 'Tabs requires a non-empty label, direct Tab children, optional variant border, box, or lift, and an initial index from 1 to the number of tabs',
672
+ );
673
+ tabs.forEach((tab) => validatedTabs.add(tab));
674
+ } else if (mdxNode.name === 'Tab') {
675
+ const attributes = mdxNode.attributes ?? [];
676
+ const title = attributes[0];
677
+ if (
678
+ !validatedTabs.has(mdxNode) ||
679
+ attributes.length !== 1 ||
680
+ title?.type !== 'mdxJsxAttribute' ||
681
+ title.name !== 'title' ||
682
+ typeof title.value !== 'string' ||
683
+ !title.value.trim()
684
+ )
685
+ fail(
686
+ contentRoot,
687
+ path,
688
+ 'Tab must be a direct child of Tabs and accepts exactly one non-empty title',
689
+ );
690
+ } else if (mdxNode.name === 'Columns') {
691
+ columnsCount += 1;
692
+ const attributes = mdxNode.attributes ?? [];
693
+ const divider = attributes.find(
694
+ (attribute) => attribute.name === 'divider',
695
+ );
696
+ const dividerColor = attributes.find(
697
+ (attribute) => attribute.name === 'dividerColor',
698
+ );
699
+ const dividerValue = divider?.value;
700
+ const separator = attributes.find(
701
+ (attribute) => attribute.name === 'separator',
702
+ );
703
+ const separatorAlign = attributes.find(
704
+ (attribute) => attribute.name === 'separatorAlign',
705
+ );
706
+ const invalidGap = attributes
707
+ .filter((attribute) =>
708
+ [
709
+ 'gap',
710
+ 'gapMobile',
711
+ 'dividerGap',
712
+ 'dividerGapMobile',
713
+ ].includes(attribute.name ?? ''),
714
+ )
715
+ .some((attribute) => {
716
+ const value = attribute.value;
717
+ return (
718
+ typeof value !== 'string' ||
719
+ !['xs', 'sm', 'md', 'lg', 'xl'].includes(value)
720
+ );
721
+ });
722
+ const columns = (mdxNode.children ?? []).filter(
723
+ (child) => child.type === 'mdxJsxFlowElement',
724
+ );
725
+ if (
726
+ attributes.some(
727
+ (attribute) =>
728
+ attribute.type !== 'mdxJsxAttribute' ||
729
+ ![
730
+ 'divider',
731
+ 'gap',
732
+ 'gapMobile',
733
+ 'separator',
734
+ 'separatorAlign',
735
+ 'dividerColor',
736
+ 'dividerGap',
737
+ 'dividerGapMobile',
738
+ ].includes(attribute.name ?? ''),
739
+ ) ||
740
+ new Set(attributes.map((attribute) => attribute.name))
741
+ .size !== attributes.length ||
742
+ (divider !== undefined &&
743
+ dividerValue !== null &&
744
+ !(
745
+ typeof dividerValue === 'object' &&
746
+ ['true', 'false'].includes(
747
+ dividerValue.value?.trim() ?? '',
748
+ )
749
+ )) ||
750
+ (dividerColor !== undefined &&
751
+ !isHexColor(dividerColor.value)) ||
752
+ (separator !== undefined &&
753
+ (typeof separator.value !== 'string' ||
754
+ !/^[A-Z][A-Za-z0-9]*$/.test(separator.value))) ||
755
+ (separatorAlign !== undefined &&
756
+ (typeof separatorAlign.value !== 'string' ||
757
+ !['centered', 'top'].includes(
758
+ separatorAlign.value,
759
+ ))) ||
760
+ invalidGap ||
761
+ columns.length < 1 ||
762
+ columns.some((column) => column.name !== 'Column')
763
+ )
764
+ fail(
765
+ contentRoot,
766
+ path,
767
+ 'Columns must contain at least one direct Column component; optional divider must be boolean, separator must be a canonical PascalCase Lucide name, separatorAlign must be centered or top, dividerColor must be a CSS hex color, and gap, gapMobile, dividerGap, and dividerGapMobile must be xs, sm, md, lg, or xl',
768
+ );
769
+ columns.forEach((column) => {
770
+ validatedColumns.add(column);
771
+ if ((column.attributes?.length ?? 0) === 0) return;
772
+ const span = column.attributes?.find(
773
+ (attribute) =>
774
+ attribute.type === 'mdxJsxAttribute' &&
775
+ attribute.name === 'span',
776
+ );
777
+ const spanValue = span?.value;
778
+ const value =
779
+ spanValue !== null && typeof spanValue === 'object'
780
+ ? spanValue.value
781
+ : undefined;
782
+ const numericValue = Number(value);
783
+ if (
784
+ column.attributes?.length !== 1 ||
785
+ !Number.isInteger(numericValue) ||
786
+ numericValue < 1 ||
787
+ numericValue > 12
788
+ )
789
+ fail(
790
+ contentRoot,
791
+ path,
792
+ 'Column accepts no props for span 12 or exactly one numeric span prop from 1 to 12',
793
+ );
794
+ });
795
+ } else if (mdxNode.name === 'Column') {
796
+ if (!validatedColumns.has(mdxNode))
797
+ fail(
798
+ contentRoot,
799
+ path,
800
+ 'Column must be a direct child of Columns',
801
+ );
802
+ } else if (mdxNode.name === 'Alert') {
803
+ alertCount += 1;
804
+ const attributes = mdxNode.attributes ?? [];
805
+ const variant = attributes.find(
806
+ (attribute) =>
807
+ attribute.type === 'mdxJsxAttribute' &&
808
+ attribute.name === 'variant',
809
+ );
810
+ const style = attributes.find(
811
+ (attribute) =>
812
+ attribute.type === 'mdxJsxAttribute' &&
813
+ attribute.name === 'style',
814
+ );
815
+ const variantValue = variant?.value;
816
+ const styleValue = style?.value;
817
+ if (
818
+ attributes.length > 2 ||
819
+ attributes.some(
820
+ (attribute) =>
821
+ attribute.type !== 'mdxJsxAttribute' ||
822
+ (attribute.name !== 'variant' &&
823
+ attribute.name !== 'style'),
824
+ ) ||
825
+ (variantValue !== undefined &&
826
+ variantValue !== 'info' &&
827
+ variantValue !== 'success' &&
828
+ variantValue !== 'warning' &&
829
+ variantValue !== 'error') ||
830
+ (styleValue !== undefined &&
831
+ styleValue !== 'normal' &&
832
+ styleValue !== 'soft' &&
833
+ styleValue !== 'outline' &&
834
+ styleValue !== 'dash')
835
+ )
836
+ fail(
837
+ contentRoot,
838
+ path,
839
+ 'Alert accepts optional variant (info, success, warning, error) and style (normal, soft, outline, dash) props',
840
+ );
841
+ } else if (mdxNode.name === 'Button') {
842
+ buttonCount += 1;
843
+ const attributes = mdxNode.attributes ?? [];
844
+ const variant = attributes.find(
845
+ (attribute) => attribute.name === 'variant',
846
+ );
847
+ const style = attributes.find(
848
+ (attribute) => attribute.name === 'style',
849
+ );
850
+ const size = attributes.find(
851
+ (attribute) => attribute.name === 'size',
852
+ );
853
+ const href = attributes.find(
854
+ (attribute) => attribute.name === 'href',
855
+ );
856
+ const type = attributes.find(
857
+ (attribute) => attribute.name === 'type',
858
+ );
859
+ const disabled = attributes.find(
860
+ (attribute) => attribute.name === 'disabled',
861
+ );
862
+ if (
863
+ attributes.some(
864
+ (attribute) =>
865
+ attribute.type !== 'mdxJsxAttribute' ||
866
+ ![
867
+ 'variant',
868
+ 'style',
869
+ 'size',
870
+ 'href',
871
+ 'type',
872
+ 'disabled',
873
+ ].includes(attribute.name ?? ''),
874
+ ) ||
875
+ new Set(attributes.map((attribute) => attribute.name))
876
+ .size !== attributes.length ||
877
+ (variant &&
878
+ ![
879
+ 'primary',
880
+ 'secondary',
881
+ 'accent',
882
+ 'neutral',
883
+ 'info',
884
+ 'success',
885
+ 'warning',
886
+ 'error',
887
+ ].includes(String(variant.value))) ||
888
+ (style &&
889
+ !['solid', 'outline', 'soft', 'ghost', 'link'].includes(
890
+ String(style.value),
891
+ )) ||
892
+ (size &&
893
+ !['xs', 'sm', 'md', 'lg', 'xl'].includes(
894
+ String(size.value),
895
+ )) ||
896
+ (href &&
897
+ (typeof href.value !== 'string' ||
898
+ !href.value.trim() ||
899
+ /^(?:javascript:|data:|\/\/)/i.test(href.value))) ||
900
+ (type &&
901
+ !['button', 'submit', 'reset'].includes(
902
+ String(type.value),
903
+ )) ||
904
+ (disabled && disabled.value !== null) ||
905
+ (href && (type || disabled))
906
+ )
907
+ fail(
908
+ contentRoot,
909
+ path,
910
+ 'Button accepts optional variant, style, size, href, type, and disabled props; links cannot also have type or disabled',
911
+ );
912
+ } else if (mdxNode.name === 'Badge') {
913
+ badgeCount += 1;
914
+ const attributes = mdxNode.attributes ?? [];
915
+ const variant = attributes.find(
916
+ (attribute) => attribute.name === 'variant',
917
+ );
918
+ const style = attributes.find(
919
+ (attribute) => attribute.name === 'style',
920
+ );
921
+ const size = attributes.find(
922
+ (attribute) => attribute.name === 'size',
923
+ );
924
+ if (
925
+ attributes.some(
926
+ (attribute) =>
927
+ attribute.type !== 'mdxJsxAttribute' ||
928
+ !['variant', 'style', 'size'].includes(
929
+ attribute.name ?? '',
930
+ ),
931
+ ) ||
932
+ new Set(attributes.map((attribute) => attribute.name))
933
+ .size !== attributes.length ||
934
+ (variant &&
935
+ ![
936
+ 'default',
937
+ 'primary',
938
+ 'secondary',
939
+ 'accent',
940
+ 'neutral',
941
+ 'info',
942
+ 'success',
943
+ 'warning',
944
+ 'error',
945
+ ].includes(String(variant.value))) ||
946
+ (style &&
947
+ !['solid', 'outline', 'soft', 'dash'].includes(
948
+ String(style.value),
949
+ )) ||
950
+ (size &&
951
+ !['xs', 'sm', 'md', 'lg', 'xl'].includes(
952
+ String(size.value),
953
+ ))
954
+ )
955
+ fail(
956
+ contentRoot,
957
+ path,
958
+ 'Badge accepts optional variant, style (solid, outline, soft, dash), and size props',
959
+ );
960
+ } else if (mdxNode.name === 'Eyebrow') {
961
+ eyebrowCount += 1;
962
+ if (mdxNode.attributes?.length !== 0)
963
+ fail(contentRoot, path, 'Eyebrow does not accept props');
964
+ } else if (mdxNode.name === 'ContentImage') {
965
+ contentImageCount += 1;
966
+ const attributes = mdxNode.attributes ?? [];
967
+ const attributeNames = attributes.map(
968
+ (attribute) => attribute.name,
969
+ );
970
+ const src = attributes.find(
971
+ (attribute) =>
972
+ attribute.type === 'mdxJsxAttribute' &&
973
+ attribute.name === 'src',
974
+ );
975
+ const alt = attributes.find(
976
+ (attribute) =>
977
+ attribute.type === 'mdxJsxAttribute' &&
978
+ attribute.name === 'alt',
979
+ );
980
+ const width = attributes.find(
981
+ (attribute) =>
982
+ attribute.type === 'mdxJsxAttribute' &&
983
+ attribute.name === 'width',
984
+ );
985
+ const height = attributes.find(
986
+ (attribute) =>
987
+ attribute.type === 'mdxJsxAttribute' &&
988
+ attribute.name === 'height',
989
+ );
990
+ const fullWidth = attributes.find(
991
+ (attribute) =>
992
+ attribute.type === 'mdxJsxAttribute' &&
993
+ attribute.name === 'fullWidth',
994
+ );
995
+ const shape = attributes.find(
996
+ (attribute) =>
997
+ attribute.type === 'mdxJsxAttribute' &&
998
+ attribute.name === 'shape',
999
+ );
1000
+ const border = attributes.find(
1001
+ (attribute) =>
1002
+ attribute.type === 'mdxJsxAttribute' &&
1003
+ attribute.name === 'border',
1004
+ );
1005
+ const srcValue = src?.value;
1006
+ const widthValue = width?.value;
1007
+ const heightValue = height?.value;
1008
+ const srcName =
1009
+ srcValue !== null && typeof srcValue === 'object'
1010
+ ? srcValue.value
1011
+ : undefined;
1012
+ const widthNumber = Number(
1013
+ widthValue !== null && typeof widthValue === 'object'
1014
+ ? widthValue.value
1015
+ : undefined,
1016
+ );
1017
+ const heightNumber = Number(
1018
+ heightValue !== null && typeof heightValue === 'object'
1019
+ ? heightValue.value
1020
+ : undefined,
1021
+ );
1022
+ if (
1023
+ attributes.some(
1024
+ (attribute) =>
1025
+ attribute.type !== 'mdxJsxAttribute' ||
1026
+ ![
1027
+ 'src',
1028
+ 'alt',
1029
+ 'width',
1030
+ 'height',
1031
+ 'fullWidth',
1032
+ 'shape',
1033
+ 'border',
1034
+ ].includes(attribute.name ?? ''),
1035
+ ) ||
1036
+ new Set(attributeNames).size !== attributeNames.length ||
1037
+ !src ||
1038
+ !localImageImports.has(srcName ?? '') ||
1039
+ typeof alt?.value !== 'string' ||
1040
+ alt.value.trim() === '' ||
1041
+ (width &&
1042
+ (!Number.isInteger(widthNumber) || widthNumber < 1)) ||
1043
+ (height &&
1044
+ (!Number.isInteger(heightNumber) ||
1045
+ heightNumber < 1)) ||
1046
+ (fullWidth && fullWidth.value !== null) ||
1047
+ (shape &&
1048
+ shape.value !== 'rounded' &&
1049
+ shape.value !== 'square') ||
1050
+ (border &&
1051
+ border.value !== 'default' &&
1052
+ border.value !== 'none')
1053
+ )
1054
+ fail(
1055
+ contentRoot,
1056
+ path,
1057
+ 'ContentImage requires a local image src expression and non-empty alt; optional width and height are positive integers, fullWidth is a boolean prop, shape is rounded or square, and border is default or none',
1058
+ );
1059
+ } else if (mdxNode.name === 'Card') {
1060
+ cardCount += 1;
1061
+ const attributes = mdxNode.attributes ?? [];
1062
+ const image = attributes.find(
1063
+ (attribute) =>
1064
+ attribute.type === 'mdxJsxAttribute' &&
1065
+ attribute.name === 'image',
1066
+ );
1067
+ const imageAlt = attributes.find(
1068
+ (attribute) =>
1069
+ attribute.type === 'mdxJsxAttribute' &&
1070
+ attribute.name === 'imageAlt',
1071
+ );
1072
+ const shadow = attributes.find(
1073
+ (attribute) =>
1074
+ attribute.type === 'mdxJsxAttribute' &&
1075
+ attribute.name === 'shadow',
1076
+ );
1077
+ const imageValue = image?.value;
1078
+ const imageImport =
1079
+ imageValue !== null && typeof imageValue === 'object'
1080
+ ? imageValue.value
1081
+ : undefined;
1082
+ const actions = (mdxNode.children ?? []).filter(
1083
+ (child) =>
1084
+ child.type === 'mdxJsxFlowElement' &&
1085
+ child.name === 'CardActions',
1086
+ );
1087
+ actions.forEach((action) => validatedCardActions.add(action));
1088
+ if (
1089
+ attributes.length > 3 ||
1090
+ attributes.some(
1091
+ (attribute) =>
1092
+ attribute.type !== 'mdxJsxAttribute' ||
1093
+ (attribute.name !== 'image' &&
1094
+ attribute.name !== 'imageAlt' &&
1095
+ attribute.name !== 'shadow'),
1096
+ ) ||
1097
+ Boolean(image) !== Boolean(imageAlt) ||
1098
+ (image && !localImageImports.has(imageImport ?? '')) ||
1099
+ (imageAlt &&
1100
+ (typeof imageAlt.value !== 'string' ||
1101
+ imageAlt.value.trim() === '')) ||
1102
+ (shadow &&
1103
+ (typeof shadow.value !== 'string' ||
1104
+ !['none', 'sm', 'md', 'lg', 'xl'].includes(
1105
+ shadow.value,
1106
+ ))) ||
1107
+ actions.length > 1
1108
+ )
1109
+ fail(
1110
+ contentRoot,
1111
+ path,
1112
+ 'Card accepts image and imageAlt together, or neither; optional shadow is none, sm, md, lg, or xl; it may contain one direct CardActions component',
1113
+ );
1114
+ } else if (mdxNode.name === 'CardActions') {
1115
+ if (
1116
+ mdxNode.attributes?.length !== 0 ||
1117
+ !validatedCardActions.has(mdxNode)
1118
+ )
1119
+ fail(
1120
+ contentRoot,
1121
+ path,
1122
+ 'CardActions must be a direct child of Card and does not accept props',
1123
+ );
1124
+ } else {
1125
+ fail(
1126
+ contentRoot,
1127
+ path,
1128
+ `unsupported MDX component: ${mdxNode.name ?? 'anonymous'}`,
1129
+ );
1130
+ }
1131
+ }
1132
+ });
1133
+
1134
+ if (
1135
+ !hasComponentImport ||
1136
+ (columnsCount === 0 &&
1137
+ tabsCount === 0 &&
1138
+ contentTableCount === 0 &&
1139
+ foundationSampleCount === 0 &&
1140
+ alertCount === 0 &&
1141
+ contentImageCount === 0 &&
1142
+ cardCount === 0 &&
1143
+ eyebrowCount === 0 &&
1144
+ buttonCount === 0 &&
1145
+ badgeCount === 0 &&
1146
+ iconCount === 0 &&
1147
+ featureCount === 0 &&
1148
+ accordionCount === 0)
1149
+ )
1150
+ fail(
1151
+ contentRoot,
1152
+ path,
1153
+ 'MDX section requires a supported Sproutsite component and its import',
1154
+ );
1155
+ }
1156
+
1157
+ /** Validates Sproutsite's file-based content contract in the current Astro project. */
1158
+ export function validateSproutsiteContent(
1159
+ contentRoot = resolve(process.cwd(), 'src/content/pages'),
1160
+ ): void {
1161
+ const site = loadSiteConfig();
1162
+ const allFiles = filesIn(contentRoot);
1163
+ const pageFiles = allFiles.filter((path) => path.endsWith('/page.yaml'));
1164
+ const pageDirectories = new Set(
1165
+ pageFiles.map((path) => contentDirectory(contentRoot, path)),
1166
+ );
1167
+ const pageDataByDirectory = new Map<string, z.infer<typeof pageSchema>>();
1168
+ const routes = new Set<string>();
1169
+ const headingsByRoute = new Map<string, Set<string>>();
1170
+ const landingHeadings = new Map<string, number>();
1171
+
1172
+ for (const pagePath of pageFiles) {
1173
+ const directory = contentDirectory(contentRoot, pagePath);
1174
+ if (isReservedContentDirectory(directory))
1175
+ fail(
1176
+ contentRoot,
1177
+ pagePath,
1178
+ 'page.yaml is not allowed in a reserved directory beginning with _',
1179
+ );
1180
+ const parsed = pageSchema.safeParse(
1181
+ parseYaml(readFileSync(pagePath, 'utf8')),
1182
+ );
1183
+ if (!parsed.success)
1184
+ fail(
1185
+ contentRoot,
1186
+ pagePath,
1187
+ `invalid page metadata: ${parsed.error.issues.map((issue) => `${issue.path.join('.')}: ${issue.message}`).join('; ')}`,
1188
+ );
1189
+ pageDataByDirectory.set(directory, parsed.data);
1190
+ }
1191
+
1192
+ const routeForDirectory = (directory: string): string =>
1193
+ routeFromPageId(
1194
+ `${directory === '' ? '' : `${directory}/`}page.yaml`,
1195
+ (path) => pageDataByDirectory.get(path)?.url,
1196
+ );
1197
+
1198
+ for (const pagePath of pageFiles) {
1199
+ const directory = contentDirectory(contentRoot, pagePath);
1200
+ const route = routeForDirectory(directory);
1201
+ if (routes.has(route))
1202
+ fail(contentRoot, pagePath, `URL collision at ${route}`);
1203
+ routes.add(route);
1204
+ headingsByRoute.set(route, new Set(['page-title']));
1205
+ }
1206
+
1207
+ for (const path of allFiles) {
1208
+ if (localizedContentFile.test(path)) continue;
1209
+ if (imageExtensions.has(extname(path).toLowerCase())) continue;
1210
+ const filename = path.split('/').at(-1)!;
1211
+ if (filename === 'page.yaml') continue;
1212
+ const directory = contentDirectory(contentRoot, path);
1213
+ if (!pageDirectories.has(directory))
1214
+ fail(
1215
+ contentRoot,
1216
+ path,
1217
+ 'hero or section file has no directly associated page.yaml',
1218
+ );
1219
+ if (filename !== 'hero.md' && !sectionPattern.test(filename))
1220
+ fail(
1221
+ contentRoot,
1222
+ path,
1223
+ 'invalid content filename; expected hero.md or NN-name.md(x)',
1224
+ );
1225
+ const { frontmatter, tree } = frontmatterAndTree(path);
1226
+ const landing =
1227
+ pageDataByDirectory.get(directory)?.layout === 'landing';
1228
+ if (landing && filename === 'hero.md')
1229
+ fail(contentRoot, path, 'landing pages must not contain hero.md');
1230
+ const metadata = (
1231
+ filename === 'hero.md' ? heroSchema : sectionSchema
1232
+ ).safeParse(frontmatter);
1233
+ if (!metadata.success)
1234
+ fail(
1235
+ contentRoot,
1236
+ path,
1237
+ `invalid frontmatter: ${metadata.error.issues.map((issue) => `${issue.path.join('.')}: ${issue.message}`).join('; ')}`,
1238
+ );
1239
+ if (filename === 'hero.md') {
1240
+ const heroMetadata = heroSchema.parse(frontmatter);
1241
+ for (const action of heroMetadata.actions ?? []) {
1242
+ if (
1243
+ /^(?:javascript:|data:)/i.test(action.href) ||
1244
+ action.href.startsWith('//')
1245
+ )
1246
+ fail(
1247
+ contentRoot,
1248
+ path,
1249
+ `disallowed hero action link protocol: ${action.href}`,
1250
+ );
1251
+ if (action.href.startsWith('/')) {
1252
+ const [targetWithQuery] = action.href.split('#', 1);
1253
+ const [target] = targetWithQuery.split('?', 1);
1254
+ const normalized =
1255
+ target === ''
1256
+ ? '/'
1257
+ : target.endsWith('/')
1258
+ ? target
1259
+ : `${target}/`;
1260
+ if (!routes.has(normalized))
1261
+ fail(
1262
+ contentRoot,
1263
+ path,
1264
+ `hero action target does not exist: ${action.href}`,
1265
+ );
1266
+ }
1267
+ }
1268
+ }
1269
+ if (path.endsWith('.mdx')) validateMdxLayout(contentRoot, path, tree);
1270
+ const route = routeForDirectory(directory);
1271
+ const seen = headingsByRoute.get(route)!;
1272
+ const headingSlugger = new GithubSlugger();
1273
+ let firstHeading: number | undefined;
1274
+ let previousHeading = 0;
1275
+ visit(tree, (node) => {
1276
+ if (node.type === 'html')
1277
+ fail(contentRoot, path, 'raw HTML is not allowed in Markdown');
1278
+ // A rendered Feature heading can introduce a section without an
1279
+ // additional Markdown title. Its props have already been validated.
1280
+ if (
1281
+ firstHeading === undefined &&
1282
+ (node.type === 'mdxJsxFlowElement' ||
1283
+ node.type === 'mdxJsxTextElement')
1284
+ ) {
1285
+ const component = node as unknown as MdxNode;
1286
+ if (component.name === 'Feature') {
1287
+ const level = component.attributes?.find(
1288
+ (attribute) => attribute.name === 'headingLevel',
1289
+ )?.value;
1290
+ firstHeading =
1291
+ level && typeof level === 'object'
1292
+ ? Number(level.value)
1293
+ : 3;
1294
+ previousHeading = firstHeading;
1295
+ }
1296
+ }
1297
+ if (node.type === 'heading') {
1298
+ firstHeading ??= node.depth;
1299
+ if (node.depth === 1 && !landing)
1300
+ fail(contentRoot, path, 'Markdown must not contain an h1');
1301
+ if (node.depth === 1 && landing)
1302
+ landingHeadings.set(
1303
+ directory,
1304
+ (landingHeadings.get(directory) ?? 0) + 1,
1305
+ );
1306
+ if (previousHeading > 0 && node.depth > previousHeading + 1)
1307
+ fail(
1308
+ contentRoot,
1309
+ path,
1310
+ `heading level jumps from h${previousHeading} to h${node.depth}`,
1311
+ );
1312
+ previousHeading = node.depth;
1313
+ const text = node.children
1314
+ .map((child) => ('value' in child ? child.value : ''))
1315
+ .join('');
1316
+ const id = `${filename.replace(/\.(?:md|mdx)$/, '')}-${headingSlugger.slug(text)}`;
1317
+ if (seen.has(id))
1318
+ fail(
1319
+ contentRoot,
1320
+ path,
1321
+ `duplicate generated heading id ${id}`,
1322
+ );
1323
+ seen.add(id);
1324
+ }
1325
+ if (node.type === 'link') {
1326
+ const href = node.url;
1327
+ if (
1328
+ /^(?:javascript:|data:)/i.test(href) ||
1329
+ href.startsWith('//')
1330
+ )
1331
+ fail(
1332
+ contentRoot,
1333
+ path,
1334
+ `disallowed link protocol: ${href}`,
1335
+ );
1336
+ if (href.startsWith('/')) {
1337
+ const [targetWithQuery, fragment] = href.split('#', 2);
1338
+ const [target] = targetWithQuery.split('?', 1);
1339
+ const normalized =
1340
+ target === ''
1341
+ ? '/'
1342
+ : target.endsWith('/')
1343
+ ? target
1344
+ : `${target}/`;
1345
+ if (!routes.has(normalized))
1346
+ fail(
1347
+ contentRoot,
1348
+ path,
1349
+ `internal link target does not exist: ${href}`,
1350
+ );
1351
+ if (
1352
+ fragment &&
1353
+ !headingsByRoute.get(normalized)?.has(fragment)
1354
+ )
1355
+ fail(
1356
+ contentRoot,
1357
+ path,
1358
+ `internal link fragment does not exist: ${href}`,
1359
+ );
1360
+ }
1361
+ }
1362
+ });
1363
+ if (
1364
+ filename !== 'hero.md' &&
1365
+ firstHeading !== 2 &&
1366
+ !(landing && firstHeading === 1)
1367
+ )
1368
+ fail(contentRoot, path, 'a section must begin with an h2');
1369
+ }
1370
+
1371
+ for (const directory of pageDirectories) {
1372
+ if (
1373
+ pageDataByDirectory.get(directory)?.layout === 'landing' &&
1374
+ landingHeadings.get(directory) !== 1
1375
+ )
1376
+ fail(
1377
+ contentRoot,
1378
+ join(contentRoot, directory, 'page.yaml'),
1379
+ 'landing pages require exactly one visible h1 in their sections',
1380
+ );
1381
+ const sections = allFiles.filter(
1382
+ (path) =>
1383
+ contentDirectory(contentRoot, path) === directory &&
1384
+ sectionPattern.test(path.split('/').at(-1)!),
1385
+ );
1386
+ const numbers = new Set<number>();
1387
+ for (const section of sections) {
1388
+ const number = Number(
1389
+ section.split('/').at(-1)!.match(/^\d+/)?.[0],
1390
+ );
1391
+ if (numbers.has(number))
1392
+ fail(
1393
+ contentRoot,
1394
+ section,
1395
+ `duplicate section number ${number}`,
1396
+ );
1397
+ numbers.add(number);
1398
+ }
1399
+ }
1400
+ if (site.base !== '/' && !site.base.endsWith('/'))
1401
+ fail(
1402
+ contentRoot,
1403
+ resolve('src/content/site.yaml'),
1404
+ 'base must end in /',
1405
+ );
1406
+ }