@astronox/core 0.1.0

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 (259) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +66 -0
  3. package/package.json +77 -0
  4. package/src/client/clipboard.ts +7 -0
  5. package/src/client/focus.ts +17 -0
  6. package/src/client/index.ts +3 -0
  7. package/src/client/scroll.ts +15 -0
  8. package/src/components/actions/ActionListItem/ActionListItem.astro +78 -0
  9. package/src/components/actions/ActionListItem/ActionListItem.css +43 -0
  10. package/src/components/actions/Button/Button.astro +100 -0
  11. package/src/components/actions/Button/Button.css +165 -0
  12. package/src/components/actions/CardAction/CardAction.astro +97 -0
  13. package/src/components/actions/CardAction/CardAction.css +188 -0
  14. package/src/components/actions/MediaTrigger/MediaTrigger.astro +55 -0
  15. package/src/components/actions/MediaTrigger/MediaTrigger.css +175 -0
  16. package/src/components/actions/ScrollToTop/ScrollToTop.astro +36 -0
  17. package/src/components/actions/ScrollToTop/ScrollToTop.css +19 -0
  18. package/src/components/actions/ScrollToTop/scrollToTopController.ts +32 -0
  19. package/src/components/content/CardBody/CardBody.astro +31 -0
  20. package/src/components/content/CardBody/CardBody.css +74 -0
  21. package/src/components/content/CardFooter/CardFooter.astro +58 -0
  22. package/src/components/content/CardFooter/CardFooter.css +102 -0
  23. package/src/components/content/CardHeader/CardHeader.astro +96 -0
  24. package/src/components/content/CardHeader/CardHeader.css +164 -0
  25. package/src/components/content/CardLink/CardLink.astro +138 -0
  26. package/src/components/content/CardLink/CardLink.css +362 -0
  27. package/src/components/content/CodeBlock/CodeBlock.astro +102 -0
  28. package/src/components/content/CodeBlock/CodeBlock.css +85 -0
  29. package/src/components/content/CodeBlock/codeBlockController.ts +60 -0
  30. package/src/components/content/CodeBlock/contracts.ts +8 -0
  31. package/src/components/content/InlineDefinition/InlineDefinition.astro +31 -0
  32. package/src/components/content/InlineDefinition/InlineDefinition.css +9 -0
  33. package/src/components/content/MarkdownContent/MarkdownContent.astro +32 -0
  34. package/src/components/content/MarkdownContent/MarkdownContent.css +358 -0
  35. package/src/components/content/MarkdownContent/MarkdownInline.astro +44 -0
  36. package/src/components/content/MarkdownContent/MarkdownNode.astro +280 -0
  37. package/src/components/content/MarkdownContent/MarkdownSymbol.astro +47 -0
  38. package/src/components/content/MarkdownContent/contracts.ts +181 -0
  39. package/src/components/data-display/BadgeList/BadgeList.astro +54 -0
  40. package/src/components/data-display/BadgeList/BadgeList.css +29 -0
  41. package/src/components/data-display/IconList/IconList.astro +64 -0
  42. package/src/components/data-display/IconList/IconList.css +55 -0
  43. package/src/components/data-display/MetricTile/MetricTile.astro +68 -0
  44. package/src/components/data-display/MetricTile/MetricTile.css +103 -0
  45. package/src/components/data-display/MetricTile/MetricTileContent.astro +70 -0
  46. package/src/components/data-display/MetricTile/metricTileController.ts +9 -0
  47. package/src/components/data-display/Tag/Tag.astro +67 -0
  48. package/src/components/data-display/Tag/Tag.css +134 -0
  49. package/src/components/data-display/Tag/TagAffix.astro +33 -0
  50. package/src/components/data-display/TextPair/TextPair.astro +63 -0
  51. package/src/components/data-display/TextPair/TextPair.css +99 -0
  52. package/src/components/feedback/Spinner/Spinner.astro +32 -0
  53. package/src/components/feedback/Spinner/Spinner.css +37 -0
  54. package/src/components/feedback/Tooltip/Tooltip.astro +66 -0
  55. package/src/components/feedback/Tooltip/Tooltip.css +67 -0
  56. package/src/components/feedback/Tooltip/tooltipController.ts +371 -0
  57. package/src/components/forms/FieldError/FieldError.astro +31 -0
  58. package/src/components/forms/FieldError/FieldError.css +12 -0
  59. package/src/components/forms/FieldError/fieldErrorState.ts +21 -0
  60. package/src/components/forms/FieldLabel/FieldLabel.astro +32 -0
  61. package/src/components/forms/FieldLabel/FieldLabel.css +17 -0
  62. package/src/components/forms/TextInput/TextInput.astro +79 -0
  63. package/src/components/forms/TextInput/TextInput.css +121 -0
  64. package/src/components/forms/TextInput/textInputController.ts +53 -0
  65. package/src/components/icons/ArrowDownIcon.astro +26 -0
  66. package/src/components/icons/ArrowLeftIcon.astro +26 -0
  67. package/src/components/icons/ArrowRightIcon.astro +26 -0
  68. package/src/components/icons/ArrowUpDownIcon.astro +26 -0
  69. package/src/components/icons/ArrowUpIcon.astro +26 -0
  70. package/src/components/icons/BulletIcon.astro +21 -0
  71. package/src/components/icons/BurnIcon.astro +24 -0
  72. package/src/components/icons/CircleSymbolIcon.css +66 -0
  73. package/src/components/icons/ClearIcon.astro +28 -0
  74. package/src/components/icons/CloseIcon.astro +21 -0
  75. package/src/components/icons/CopyIcon.astro +30 -0
  76. package/src/components/icons/CurrencyIcon.css +9 -0
  77. package/src/components/icons/DayIcon.astro +33 -0
  78. package/src/components/icons/DollarIcon.astro +28 -0
  79. package/src/components/icons/DownloadIcon.astro +22 -0
  80. package/src/components/icons/EnterFullscreenIcon.astro +22 -0
  81. package/src/components/icons/EqualIcon.astro +25 -0
  82. package/src/components/icons/ExitFullscreenIcon.astro +22 -0
  83. package/src/components/icons/ExternalLinkIcon.astro +22 -0
  84. package/src/components/icons/FieldIcon.astro +28 -0
  85. package/src/components/icons/GrassIcon.astro +29 -0
  86. package/src/components/icons/InfoIcon.astro +24 -0
  87. package/src/components/icons/MinusIcon.astro +21 -0
  88. package/src/components/icons/MountainIcon.astro +31 -0
  89. package/src/components/icons/NightIcon.astro +32 -0
  90. package/src/components/icons/PlayIcon.astro +22 -0
  91. package/src/components/icons/PlusIcon.astro +21 -0
  92. package/src/components/icons/PoisonIcon.astro +24 -0
  93. package/src/components/icons/RibbonIcon.astro +25 -0
  94. package/src/components/icons/SlashIcon.astro +22 -0
  95. package/src/components/icons/SlowIcon.astro +25 -0
  96. package/src/components/icons/StarIcon.astro +28 -0
  97. package/src/components/icons/StunIcon.astro +22 -0
  98. package/src/components/icons/TableSortIcon.astro +34 -0
  99. package/src/components/icons/WaterIcon.astro +30 -0
  100. package/src/components/index.ts +83 -0
  101. package/src/components/media/CanvasFrame/CanvasFrame.astro +130 -0
  102. package/src/components/media/CanvasFrame/CanvasFrame.css +59 -0
  103. package/src/components/media/CanvasFrame/canvasFrameController.ts +104 -0
  104. package/src/components/media/EmbedFrame/EmbedFrame.astro +147 -0
  105. package/src/components/media/EmbedFrame/EmbedFrame.css +51 -0
  106. package/src/components/media/EmbedFrame/embedFrameController.ts +66 -0
  107. package/src/components/media/MediaFrame/MediaFrame.astro +34 -0
  108. package/src/components/media/MediaFrame/MediaFrame.css +66 -0
  109. package/src/components/navigation/Breadcrumbs/Breadcrumbs.astro +55 -0
  110. package/src/components/navigation/Breadcrumbs/Breadcrumbs.css +89 -0
  111. package/src/components/navigation/DesktopNavigation.astro +92 -0
  112. package/src/components/navigation/DesktopNavigation.css +99 -0
  113. package/src/components/navigation/Header.astro +73 -0
  114. package/src/components/navigation/Header.css +20 -0
  115. package/src/components/navigation/MobileNavigation.astro +124 -0
  116. package/src/components/navigation/MobileNavigation.css +177 -0
  117. package/src/components/navigation/NavigationBrand.astro +63 -0
  118. package/src/components/navigation/NavigationBrand.css +52 -0
  119. package/src/components/navigation/NavigationControl.css +166 -0
  120. package/src/components/navigation/NavigationItemContent.astro +24 -0
  121. package/src/components/navigation/NavigationLink.astro +121 -0
  122. package/src/components/navigation/NavigationLinks.astro +27 -0
  123. package/src/components/navigation/NavigationMenuList.astro +37 -0
  124. package/src/components/navigation/NavigationMenuList.css +6 -0
  125. package/src/components/navigation/SkipLink/SkipLink.astro +18 -0
  126. package/src/components/navigation/SkipLink/SkipLink.css +26 -0
  127. package/src/components/navigation/SubNavigation/SubNavigation.astro +124 -0
  128. package/src/components/navigation/SubNavigation/SubNavigation.css +211 -0
  129. package/src/components/navigation/mobileNavigationController.ts +122 -0
  130. package/src/components/navigation/navigationState.ts +35 -0
  131. package/src/components/navigation/navigationTypes.ts +18 -0
  132. package/src/components/seo/SeoHead.astro +194 -0
  133. package/src/components/widgetTypes.ts +3 -0
  134. package/src/composition/Grid/Grid.astro +82 -0
  135. package/src/composition/Grid/Grid.css +314 -0
  136. package/src/composition/GridItem/GridItem.astro +50 -0
  137. package/src/composition/GridItem/GridItem.css +95 -0
  138. package/src/composition/Inline/Inline.astro +48 -0
  139. package/src/composition/Inline/Inline.css +65 -0
  140. package/src/composition/Stack/Stack.astro +37 -0
  141. package/src/composition/Stack/Stack.css +31 -0
  142. package/src/composition/SurfaceGroup/SurfaceGroup.astro +44 -0
  143. package/src/composition/SurfaceGroup/SurfaceGroup.css +76 -0
  144. package/src/composition/SurfaceGroup/stickySurfaceGroupController.ts +89 -0
  145. package/src/composition/index.ts +6 -0
  146. package/src/config/index.ts +2 -0
  147. package/src/config/pageMeta.ts +55 -0
  148. package/src/config/siteConfig.ts +90 -0
  149. package/src/data/collectionValidation.ts +61 -0
  150. package/src/data/index.ts +1 -0
  151. package/src/display/contracts.ts +284 -0
  152. package/src/display/index.ts +1 -0
  153. package/src/index.ts +6 -0
  154. package/src/layouts/BaseLayout.astro +74 -0
  155. package/src/layouts/PageSurface.astro +15 -0
  156. package/src/layouts/PageSurface.css +24 -0
  157. package/src/layouts/index.ts +2 -0
  158. package/src/patterns/CircuitPuzzle/CircuitPuzzle.astro +93 -0
  159. package/src/patterns/CircuitPuzzle/CircuitPuzzle.css +118 -0
  160. package/src/patterns/CircuitPuzzle/circuitPuzzleController.ts +205 -0
  161. package/src/patterns/CircuitPuzzle/contracts.ts +42 -0
  162. package/src/patterns/Combobox/Combobox.astro +462 -0
  163. package/src/patterns/Combobox/Combobox.css +403 -0
  164. package/src/patterns/Combobox/comboboxController.ts +788 -0
  165. package/src/patterns/Combobox/contracts.ts +18 -0
  166. package/src/patterns/Dropdown/Dropdown.astro +127 -0
  167. package/src/patterns/Dropdown/Dropdown.css +100 -0
  168. package/src/patterns/Dropdown/dropdownController.ts +157 -0
  169. package/src/patterns/Fullscreen/FullscreenControl.astro +103 -0
  170. package/src/patterns/Fullscreen/FullscreenControl.css +49 -0
  171. package/src/patterns/Fullscreen/fullscreenController.ts +73 -0
  172. package/src/patterns/GlitchOverlay/GlitchOverlay.astro +50 -0
  173. package/src/patterns/GlitchOverlay/GlitchOverlay.css +234 -0
  174. package/src/patterns/GlitchOverlay/glitchOverlayController.ts +152 -0
  175. package/src/patterns/GuidedFlow/GuidedFlow.astro +60 -0
  176. package/src/patterns/GuidedFlow/GuidedFlow.css +82 -0
  177. package/src/patterns/GuidedFlow/contracts.ts +3 -0
  178. package/src/patterns/GuidedFlow/guidedFlowController.ts +49 -0
  179. package/src/patterns/MagneticFieldPuzzle/MagneticFieldPuzzle.astro +217 -0
  180. package/src/patterns/MagneticFieldPuzzle/MagneticFieldPuzzle.css +383 -0
  181. package/src/patterns/MagneticFieldPuzzle/contracts.ts +81 -0
  182. package/src/patterns/MagneticFieldPuzzle/magneticFieldPuzzleController.ts +802 -0
  183. package/src/patterns/MagneticFieldPuzzle/simulation.ts +244 -0
  184. package/src/patterns/MapViewport/MapViewport.astro +296 -0
  185. package/src/patterns/MapViewport/MapViewport.css +257 -0
  186. package/src/patterns/MapViewport/contracts.ts +79 -0
  187. package/src/patterns/MapViewport/geometry.ts +80 -0
  188. package/src/patterns/MapViewport/mapViewportController.ts +636 -0
  189. package/src/patterns/Modal/Modal.astro +64 -0
  190. package/src/patterns/Modal/Modal.css +87 -0
  191. package/src/patterns/Modal/ModalClose.astro +37 -0
  192. package/src/patterns/Modal/ModalOpen.astro +36 -0
  193. package/src/patterns/Modal/modalController.ts +118 -0
  194. package/src/patterns/PuzzleGrid/PuzzleGrid.astro +22 -0
  195. package/src/patterns/PuzzleGrid/PuzzleGrid.css +149 -0
  196. package/src/patterns/PuzzleGrid/contracts.ts +2 -0
  197. package/src/patterns/PuzzleGrid/selectionDismissal.ts +27 -0
  198. package/src/patterns/PuzzleGrid/state.ts +25 -0
  199. package/src/patterns/SpriteProjectilePreview/SpriteProjectilePreview.astro +65 -0
  200. package/src/patterns/SpriteProjectilePreview/SpriteProjectilePreview.css +35 -0
  201. package/src/patterns/SpriteProjectilePreview/contracts.ts +33 -0
  202. package/src/patterns/SpriteProjectilePreview/spriteProjectilePreviewController.ts +586 -0
  203. package/src/patterns/StageFlow/StageFlow.astro +57 -0
  204. package/src/patterns/StageFlow/StageFlow.css +54 -0
  205. package/src/patterns/StageFlow/StageFlowAlternative.astro +23 -0
  206. package/src/patterns/StageFlow/StageFlowArrow.astro +22 -0
  207. package/src/patterns/StageFlow/StageFlowConnector.astro +7 -0
  208. package/src/patterns/StageFlow/StageFlowConnector.css +4 -0
  209. package/src/patterns/StageFlow/StageFlowStage.astro +51 -0
  210. package/src/patterns/StageFlow/StageFlowStage.css +106 -0
  211. package/src/patterns/StageFlow/StageFlowStep.astro +24 -0
  212. package/src/patterns/StageFlow/StageFlowStep.css +19 -0
  213. package/src/patterns/StageFlow/StageFlowSymbol.css +28 -0
  214. package/src/patterns/Table/Table.astro +176 -0
  215. package/src/patterns/Table/Table.css +70 -0
  216. package/src/patterns/Table/TableBody.astro +185 -0
  217. package/src/patterns/Table/TableBody.css +262 -0
  218. package/src/patterns/Table/TableCell.astro +59 -0
  219. package/src/patterns/Table/TableCell.css +99 -0
  220. package/src/patterns/Table/TableCellValue.astro +86 -0
  221. package/src/patterns/Table/TableFooter.astro +32 -0
  222. package/src/patterns/Table/TableFooter.css +31 -0
  223. package/src/patterns/Table/TableHeader.astro +118 -0
  224. package/src/patterns/Table/TableHeader.css +209 -0
  225. package/src/patterns/Table/TablePagination.astro +70 -0
  226. package/src/patterns/Table/TablePagination.css +133 -0
  227. package/src/patterns/Table/TableSkeleton.astro +36 -0
  228. package/src/patterns/Table/TableSkeleton.css +81 -0
  229. package/src/patterns/Table/tableCellController.ts +11 -0
  230. package/src/patterns/Table/tableFilterController.ts +206 -0
  231. package/src/patterns/Table/tableHeaderOverflowController.ts +105 -0
  232. package/src/patterns/Table/tableLayout.ts +113 -0
  233. package/src/patterns/Table/tableProgressiveController.ts +319 -0
  234. package/src/patterns/Table/tableRowNavigationController.ts +91 -0
  235. package/src/patterns/Table/tableScrollController.ts +192 -0
  236. package/src/patterns/Table/tableSortController.ts +272 -0
  237. package/src/patterns/index.ts +46 -0
  238. package/src/primitives/index.ts +4 -0
  239. package/src/primitives/layout/Separator/Separator.astro +29 -0
  240. package/src/primitives/layout/Separator/Separator.css +20 -0
  241. package/src/primitives/media/AmbientAudio/AmbientAudio.astro +28 -0
  242. package/src/primitives/media/Media/Media.astro +122 -0
  243. package/src/primitives/media/Media/Media.css +161 -0
  244. package/src/primitives/text/TextBlock/TextBlock.astro +46 -0
  245. package/src/primitives/text/TextBlock/TextBlock.css +21 -0
  246. package/src/seo/StaticRedirect.astro +32 -0
  247. package/src/seo/index.ts +6 -0
  248. package/src/seo/pageSeo.ts +99 -0
  249. package/src/seo/robots.ts +16 -0
  250. package/src/seo/sitemap.ts +38 -0
  251. package/src/seo/structuredData.ts +133 -0
  252. package/src/seo/url.ts +64 -0
  253. package/src/styles/base.css +148 -0
  254. package/src/styles/interaction.css +108 -0
  255. package/src/styles/style.css +93 -0
  256. package/src/styles/tokens.css +256 -0
  257. package/src/theme/contracts.ts +7 -0
  258. package/src/theme/index.ts +1 -0
  259. package/tsconfig.json +20 -0
@@ -0,0 +1,46 @@
1
+ ---
2
+ import type { HTMLAttributes } from 'astro/types';
3
+ import type { Tone } from '../../../theme/contracts';
4
+
5
+ type Props = HTMLAttributes<'p'> & {
6
+ 'data-tone'?: Tone;
7
+ preserveBreaks?: boolean;
8
+ text: string;
9
+ };
10
+
11
+ const {
12
+ class: className,
13
+ 'data-tone': dataTone,
14
+ preserveBreaks = false,
15
+ text,
16
+ ...attrs
17
+ }: Props = Astro.props;
18
+ const paragraphs = preserveBreaks
19
+ ? text.split(/\r?\n(?:[ \t]*\r?\n)+/)
20
+ : [];
21
+ ---
22
+
23
+ {
24
+ preserveBreaks ? (
25
+ <div
26
+ {...attrs}
27
+ class:list={['text-block', className]}
28
+ data-widget="text-block"
29
+ data-preserve-breaks
30
+ data-tone={dataTone}
31
+ >
32
+ {paragraphs.map((paragraph) => (
33
+ <p class="text-block__paragraph">{paragraph}</p>
34
+ ))}
35
+ </div>
36
+ ) : (
37
+ <p
38
+ {...attrs}
39
+ class:list={['text-block', className]}
40
+ data-widget="text-block"
41
+ data-tone={dataTone}
42
+ >
43
+ {text}
44
+ </p>
45
+ )
46
+ }
@@ -0,0 +1,21 @@
1
+ .text-block {
2
+ margin: 0;
3
+ overflow-wrap: anywhere;
4
+ }
5
+
6
+ .text-block[data-preserve-breaks] {
7
+ display: grid;
8
+ gap: var(--nox-content-padding, var(--nox-space-5));
9
+ line-height: 1.5;
10
+ }
11
+
12
+ .text-block__paragraph {
13
+ margin: 0;
14
+ white-space: pre-wrap;
15
+ }
16
+
17
+ @container (width < 32rem) {
18
+ .text-block[data-preserve-breaks] {
19
+ line-height: 1.4;
20
+ }
21
+ }
@@ -0,0 +1,32 @@
1
+ ---
2
+ import { createAbsoluteUrl, normalizePathname } from './url';
3
+
4
+ type Props = {
5
+ destination: string;
6
+ lang: string;
7
+ siteUrl: string;
8
+ title: string;
9
+ };
10
+
11
+ const { destination, lang, siteUrl, title } = Astro.props;
12
+ const normalizedDestination = normalizePathname(destination);
13
+ const canonical = createAbsoluteUrl(siteUrl, normalizedDestination);
14
+ const refresh = `0; url=${canonical}`;
15
+ ---
16
+
17
+ <!doctype html>
18
+ <html lang={lang}>
19
+ <head>
20
+ <meta charset="UTF-8" />
21
+ <meta name="viewport" content="width=device-width" />
22
+ <title>{title}</title>
23
+ <link rel="canonical" href={canonical} />
24
+ <script is:inline define:vars={{ destination: normalizedDestination }}>
25
+ window.location.replace(
26
+ `${destination}${window.location.search}${window.location.hash}`,
27
+ );
28
+ </script>
29
+ <meta http-equiv="refresh" content={refresh} />
30
+ </head>
31
+ <body></body>
32
+ </html>
@@ -0,0 +1,6 @@
1
+ export { default as StaticRedirect } from './StaticRedirect.astro';
2
+ export * from './pageSeo';
3
+ export * from './robots';
4
+ export * from './sitemap';
5
+ export * from './structuredData';
6
+ export * from './url';
@@ -0,0 +1,99 @@
1
+ import type { PageMeta } from '../config/pageMeta';
2
+ import { formatRobotsDirective } from '../config/pageMeta';
3
+ import type { SiteConfig, TwitterCardType } from '../config/siteConfig';
4
+ import { createAbsoluteUrl, createCanonicalUrl } from './url';
5
+
6
+ export type ResolvedPageSeo = {
7
+ lang: string;
8
+ documentTitle: string;
9
+ description: string | undefined;
10
+ canonicalUrl: string;
11
+ robots: string | undefined;
12
+ socialImageUrl: string | undefined;
13
+ socialImageAlt: string | undefined;
14
+ socialImageType: string | undefined;
15
+ socialImageWidth: number | undefined;
16
+ socialImageHeight: number | undefined;
17
+ openGraphType: 'article' | 'website';
18
+ openGraphLocale: string;
19
+ openGraphLocaleAlternates: readonly string[];
20
+ alternates: readonly {
21
+ lang: string;
22
+ href: string;
23
+ }[];
24
+ seoType: 'article' | 'collection-page' | 'web-page';
25
+ datePublished: string | undefined;
26
+ twitterCard: TwitterCardType;
27
+ };
28
+
29
+ export function resolvePageSeo({
30
+ meta,
31
+ pathname,
32
+ site,
33
+ }: {
34
+ meta: PageMeta;
35
+ pathname: string;
36
+ site: SiteConfig;
37
+ }): ResolvedPageSeo {
38
+ const lang = meta.lang ?? site.defaultMeta.lang;
39
+ const description = meta.description ?? site.defaultMeta.description;
40
+ const canonicalUrl = createCanonicalUrl(
41
+ site.seo.siteUrl,
42
+ meta.canonical ?? pathname,
43
+ );
44
+ const socialImage = meta.socialImage ?? site.seo.defaultSocialImage;
45
+ const localeConfig = site.locales.find(
46
+ (locale) =>
47
+ locale.languageTag === lang ||
48
+ locale.id === lang ||
49
+ locale.intlLocale === lang,
50
+ );
51
+
52
+ return {
53
+ lang,
54
+ documentTitle: formatDocumentTitle({
55
+ branding: meta.titleBranding,
56
+ pageTitle: meta.title,
57
+ separator: site.seo.titleSeparator,
58
+ siteName: site.identity.name,
59
+ }),
60
+ description,
61
+ canonicalUrl,
62
+ robots: formatRobotsDirective(meta.robots ?? site.defaultMeta.robots),
63
+ socialImageUrl: socialImage
64
+ ? createAbsoluteUrl(site.seo.siteUrl, socialImage)
65
+ : undefined,
66
+ socialImageAlt: meta.socialImageAlt ?? site.seo.defaultSocialImageAlt,
67
+ socialImageType: meta.socialImageType ?? site.seo.defaultSocialImageType,
68
+ socialImageWidth: meta.socialImageWidth ?? site.seo.defaultSocialImageWidth,
69
+ socialImageHeight:
70
+ meta.socialImageHeight ?? site.seo.defaultSocialImageHeight,
71
+ openGraphType: meta.openGraphType ?? 'website',
72
+ openGraphLocale:
73
+ meta.openGraphLocale ?? localeConfig?.openGraphLocale ?? lang,
74
+ openGraphLocaleAlternates: meta.openGraphLocaleAlternates ?? [],
75
+ alternates: (meta.alternates ?? []).map((alternate) => ({
76
+ lang: alternate.lang,
77
+ href: createCanonicalUrl(site.seo.siteUrl, alternate.href),
78
+ })),
79
+ seoType: meta.seoType ?? 'web-page',
80
+ datePublished: meta.datePublished,
81
+ twitterCard: site.seo.twitterCard,
82
+ };
83
+ }
84
+
85
+ function formatDocumentTitle({
86
+ branding = 'append',
87
+ pageTitle,
88
+ separator,
89
+ siteName,
90
+ }: {
91
+ branding?: PageMeta['titleBranding'];
92
+ pageTitle: string;
93
+ separator: string;
94
+ siteName: string;
95
+ }): string {
96
+ return branding === 'none' || pageTitle === siteName
97
+ ? pageTitle
98
+ : `${pageTitle} ${separator} ${siteName}`;
99
+ }
@@ -0,0 +1,16 @@
1
+ import { createAbsoluteUrl } from './url';
2
+
3
+ export function renderRobotsTxt({
4
+ sitemapPath,
5
+ siteUrl,
6
+ }: {
7
+ sitemapPath: string;
8
+ siteUrl: string;
9
+ }): string {
10
+ return [
11
+ 'User-agent: *',
12
+ 'Allow: /',
13
+ `Sitemap: ${createAbsoluteUrl(siteUrl, sitemapPath)}`,
14
+ '',
15
+ ].join('\n');
16
+ }
@@ -0,0 +1,38 @@
1
+ import { createAbsoluteUrl, normalizePathname } from './url';
2
+
3
+ export type SitemapEntry = {
4
+ path: string;
5
+ lastModified?: string;
6
+ };
7
+
8
+ export function renderSitemap({
9
+ entries,
10
+ siteUrl,
11
+ }: {
12
+ entries: readonly SitemapEntry[];
13
+ siteUrl: string;
14
+ }): string {
15
+ const urls = entries
16
+ .map((entry) => renderSitemapUrl(entry, siteUrl))
17
+ .join('');
18
+
19
+ return `<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">${urls}</urlset>\n`;
20
+ }
21
+
22
+ function renderSitemapUrl(entry: SitemapEntry, siteUrl: string): string {
23
+ const loc = createAbsoluteUrl(siteUrl, normalizePathname(entry.path));
24
+ const lastModified = entry.lastModified
25
+ ? `<lastmod>${escapeXml(entry.lastModified)}</lastmod>`
26
+ : '';
27
+
28
+ return `<url><loc>${escapeXml(loc)}</loc>${lastModified}</url>`;
29
+ }
30
+
31
+ function escapeXml(value: string): string {
32
+ return value
33
+ .replaceAll('&', '&amp;')
34
+ .replaceAll('"', '&quot;')
35
+ .replaceAll("'", '&apos;')
36
+ .replaceAll('<', '&lt;')
37
+ .replaceAll('>', '&gt;');
38
+ }
@@ -0,0 +1,133 @@
1
+ import type { SiteConfig } from '../config/siteConfig';
2
+ import type { BreadcrumbItem } from '../display/contracts';
3
+ import { createAbsoluteUrl, createCanonicalUrl } from './url';
4
+
5
+ export type JsonLdPrimitive = boolean | number | string | null;
6
+
7
+ export type JsonLdValue =
8
+ | JsonLdPrimitive
9
+ | JsonLdValue[]
10
+ | {
11
+ [key: string]: JsonLdValue;
12
+ };
13
+
14
+ export type JsonLdNode = {
15
+ [key: string]: JsonLdValue;
16
+ };
17
+
18
+ type JsonLdNodeInput = {
19
+ [key: string]: JsonLdValue | undefined;
20
+ };
21
+
22
+ export type WebPageStructuredDataInput = {
23
+ site: SiteConfig;
24
+ name: string;
25
+ description: string | undefined;
26
+ url: string;
27
+ lang: string;
28
+ type?: 'CollectionPage' | 'WebPage';
29
+ };
30
+
31
+ export type ArticleStructuredDataInput = {
32
+ site?: SiteConfig;
33
+ datePublished: string;
34
+ description: string | undefined;
35
+ headline: string;
36
+ lang?: string;
37
+ url: string;
38
+ };
39
+
40
+ export function createWebSiteJsonLd(site: SiteConfig): JsonLdNode {
41
+ const siteUrl = createAbsoluteUrl(site.seo.siteUrl, '/');
42
+
43
+ return removeUndefinedValues({
44
+ '@context': 'https://schema.org',
45
+ '@type': 'WebSite',
46
+ '@id': `${siteUrl}#website`,
47
+ name: site.identity.name,
48
+ alternateName: site.identity.shortName,
49
+ description: site.defaultMeta.description,
50
+ url: siteUrl,
51
+ inLanguage: site.defaultMeta.lang,
52
+ });
53
+ }
54
+
55
+ export function createWebPageJsonLd({
56
+ description,
57
+ lang,
58
+ name,
59
+ site,
60
+ type = 'WebPage',
61
+ url,
62
+ }: WebPageStructuredDataInput): JsonLdNode {
63
+ const siteUrl = createAbsoluteUrl(site.seo.siteUrl, '/');
64
+
65
+ return removeUndefinedValues({
66
+ '@context': 'https://schema.org',
67
+ '@type': type,
68
+ '@id': `${url}#webpage`,
69
+ url,
70
+ name,
71
+ description,
72
+ inLanguage: lang,
73
+ isPartOf: {
74
+ '@id': `${siteUrl}#website`,
75
+ },
76
+ });
77
+ }
78
+
79
+ export function createArticleJsonLd({
80
+ site,
81
+ datePublished,
82
+ description,
83
+ headline,
84
+ lang,
85
+ url,
86
+ }: ArticleStructuredDataInput): JsonLdNode {
87
+ const siteUrl = site ? createAbsoluteUrl(site.seo.siteUrl, '/') : undefined;
88
+
89
+ return removeUndefinedValues({
90
+ '@context': 'https://schema.org',
91
+ '@type': 'Article',
92
+ '@id': `${url}#article`,
93
+ headline,
94
+ description,
95
+ datePublished,
96
+ mainEntityOfPage: url,
97
+ inLanguage: lang,
98
+ isPartOf: siteUrl
99
+ ? {
100
+ '@id': `${siteUrl}#website`,
101
+ }
102
+ : undefined,
103
+ });
104
+ }
105
+
106
+ export function createBreadcrumbListJsonLd({
107
+ breadcrumbs,
108
+ siteUrl,
109
+ }: {
110
+ breadcrumbs: readonly BreadcrumbItem[];
111
+ siteUrl: string;
112
+ }): JsonLdNode {
113
+ return {
114
+ '@context': 'https://schema.org',
115
+ '@type': 'BreadcrumbList',
116
+ itemListElement: breadcrumbs.map((breadcrumb, index) => ({
117
+ '@type': 'ListItem',
118
+ position: index + 1,
119
+ name: breadcrumb.label,
120
+ item: createCanonicalUrl(siteUrl, breadcrumb.href),
121
+ })),
122
+ };
123
+ }
124
+
125
+ export function serializeJsonLd(node: JsonLdNode): string {
126
+ return JSON.stringify(node).replace(/</g, '\\u003c');
127
+ }
128
+
129
+ function removeUndefinedValues(node: JsonLdNodeInput): JsonLdNode {
130
+ return Object.fromEntries(
131
+ Object.entries(node).filter(([, value]) => value !== undefined),
132
+ ) as JsonLdNode;
133
+ }
package/src/seo/url.ts ADDED
@@ -0,0 +1,64 @@
1
+ const absoluteUrlPattern = /^https?:\/\//i;
2
+
3
+ export function createAbsoluteUrl(siteUrl: string, pathOrUrl: string): string {
4
+ const cleanValue = pathOrUrl.trim();
5
+
6
+ if (absoluteUrlPattern.test(cleanValue)) {
7
+ return new URL(cleanValue).toString();
8
+ }
9
+
10
+ return new URL(
11
+ ensureLeadingSlash(cleanValue),
12
+ normalizeSiteUrl(siteUrl),
13
+ ).toString();
14
+ }
15
+
16
+ export function createCanonicalUrl(siteUrl: string, pathOrUrl: string): string {
17
+ const cleanValue = pathOrUrl.trim();
18
+
19
+ if (absoluteUrlPattern.test(cleanValue)) {
20
+ const url = new URL(cleanValue);
21
+
22
+ url.hash = '';
23
+ url.pathname = normalizePathname(url.pathname);
24
+ url.search = '';
25
+
26
+ return url.toString();
27
+ }
28
+
29
+ return createAbsoluteUrl(siteUrl, normalizePathname(cleanValue));
30
+ }
31
+
32
+ export function normalizeSiteUrl(siteUrl: string): string {
33
+ const url = new URL(siteUrl);
34
+ url.hash = '';
35
+ url.search = '';
36
+
37
+ return url.toString();
38
+ }
39
+
40
+ export function normalizePathname(pathOrUrl: string): string {
41
+ const cleanValue = removeHashAndSearch(pathOrUrl.trim());
42
+
43
+ if (absoluteUrlPattern.test(cleanValue)) {
44
+ return normalizePathPart(new URL(cleanValue).pathname);
45
+ }
46
+
47
+ return normalizePathPart(ensureLeadingSlash(cleanValue));
48
+ }
49
+
50
+ function ensureLeadingSlash(pathname: string): string {
51
+ if (pathname.length === 0) {
52
+ return '/';
53
+ }
54
+
55
+ return pathname.startsWith('/') ? pathname : `/${pathname}`;
56
+ }
57
+
58
+ function normalizePathPart(pathname: string): string {
59
+ return pathname.length > 1 ? pathname.replace(/\/+$/, '') : '/';
60
+ }
61
+
62
+ function removeHashAndSearch(value: string): string {
63
+ return value.split('#')[0]?.split('?')[0] ?? value;
64
+ }
@@ -0,0 +1,148 @@
1
+ * {
2
+ box-sizing: border-box;
3
+ scrollbar-color: var(--nox-scrollbar-thumb) var(--nox-scrollbar-track);
4
+ scrollbar-width: thin;
5
+ }
6
+
7
+ [hidden] {
8
+ display: none !important;
9
+ }
10
+
11
+ *::-webkit-scrollbar {
12
+ width: var(--nox-scrollbar-size);
13
+ height: var(--nox-scrollbar-size);
14
+ }
15
+
16
+ *::-webkit-scrollbar-track {
17
+ background: var(--nox-scrollbar-track);
18
+ }
19
+
20
+ *::-webkit-scrollbar-thumb {
21
+ border: 0.1875rem solid transparent;
22
+ border-radius: var(--nox-radius-pill);
23
+ background: var(--nox-scrollbar-thumb);
24
+ background-clip: content-box;
25
+ }
26
+
27
+ *::-webkit-scrollbar-thumb:hover {
28
+ background: var(--nox-scrollbar-thumb-hover);
29
+ background-clip: content-box;
30
+ }
31
+
32
+ :where([data-scrollbar='native']) {
33
+ scrollbar-color: auto;
34
+ scrollbar-width: auto;
35
+ }
36
+
37
+ :where([data-scrollbar='hidden']) {
38
+ scrollbar-width: none;
39
+ }
40
+
41
+ :where([data-scrollbar='hidden'])::-webkit-scrollbar {
42
+ display: none;
43
+ }
44
+
45
+ html {
46
+ min-width: 320px;
47
+ height: 100%;
48
+ min-height: 100%;
49
+ overflow: hidden;
50
+ background: var(--nox-page-background);
51
+ color: var(--nox-text);
52
+ font-family: var(--nox-font-body);
53
+ }
54
+
55
+ body {
56
+ display: grid;
57
+ height: 100vh;
58
+ min-height: 100vh;
59
+ grid-template-rows: auto minmax(0, 1fr);
60
+ margin: 0;
61
+ overflow: hidden;
62
+ background: var(--nox-page-background);
63
+ }
64
+
65
+ @supports (height: 100dvh) {
66
+ body {
67
+ height: 100dvh;
68
+ min-height: 100dvh;
69
+ }
70
+ }
71
+
72
+ a {
73
+ color: inherit;
74
+ }
75
+
76
+ a:focus-visible,
77
+ button:focus-visible {
78
+ outline: var(--nox-focus-ring-width) solid var(--nox-focus-ring);
79
+ outline-offset: var(--nox-focus-ring-offset);
80
+ }
81
+
82
+ button {
83
+ font: inherit;
84
+ }
85
+
86
+ img,
87
+ svg,
88
+ video {
89
+ max-width: 100%;
90
+ height: auto;
91
+ }
92
+
93
+ h1,
94
+ h2,
95
+ h3,
96
+ p {
97
+ margin: 0;
98
+ }
99
+
100
+ .site-viewport {
101
+ min-width: 0;
102
+ min-height: 0;
103
+ overflow-x: hidden;
104
+ overflow-y: auto;
105
+ background: var(--nox-page-background);
106
+ overscroll-behavior-y: contain;
107
+ scrollbar-gutter: stable both-edges;
108
+ }
109
+
110
+ .site-main {
111
+ --site-main-content-gap: var(--nox-space-5);
112
+
113
+ display: grid;
114
+ width: var(--nox-page-width);
115
+ margin: 0 auto;
116
+ padding-block: var(--site-main-content-gap) var(--nox-space-7);
117
+ gap: var(--nox-layout-gap);
118
+ }
119
+
120
+ .site-main__content {
121
+ display: grid;
122
+ min-width: 0;
123
+ gap: var(--site-main-content-gap);
124
+ }
125
+
126
+ .site-main:has(> .site-main__content > .breadcrumbs) {
127
+ padding-block-start: 0;
128
+ }
129
+
130
+ .site-main__content:has(> .breadcrumbs) {
131
+ gap: 0;
132
+ }
133
+
134
+ @media (width < 48rem) {
135
+ .site-main {
136
+ --site-main-content-gap: var(--nox-space-4);
137
+
138
+ padding-block-end: var(--nox-space-6);
139
+ }
140
+ }
141
+
142
+ code {
143
+ padding: 0.125em 0.375em;
144
+ border: var(--nox-border-width) solid var(--nox-border);
145
+ border-radius: var(--nox-radius-sm);
146
+ background: var(--nox-surface-muted);
147
+ color: var(--nox-text);
148
+ }