@sinnstack/ui 0.0.0-stage → 0.3.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 (306) hide show
  1. package/CHANGELOG.md +89 -0
  2. package/LICENSE +373 -0
  3. package/README.md +188 -2
  4. package/docs/blocks.md +373 -0
  5. package/docs/data.md +128 -0
  6. package/docs/finishes.md +165 -0
  7. package/docs/motion.md +166 -0
  8. package/docs/primitives.md +510 -0
  9. package/docs/seo.md +191 -0
  10. package/docs/tokens.md +122 -0
  11. package/package.json +132 -3
  12. package/scripts/check-contrast.mjs +180 -0
  13. package/src/blocks/BlockRenderer.astro +60 -0
  14. package/src/blocks/CTABanner.astro +121 -0
  15. package/src/blocks/CTAPair.astro +110 -0
  16. package/src/blocks/CardGrid.astro +167 -0
  17. package/src/blocks/ConsentEmbed.astro +125 -0
  18. package/src/blocks/ConsentManager.astro +147 -0
  19. package/src/blocks/ConsentScript.astro +47 -0
  20. package/src/blocks/ContactCard.astro +164 -0
  21. package/src/blocks/ContactForm.astro +224 -0
  22. package/src/blocks/ErrorPage.astro +242 -0
  23. package/src/blocks/FAQ.astro +135 -0
  24. package/src/blocks/FeatureGrid.astro +148 -0
  25. package/src/blocks/Hero.astro +171 -0
  26. package/src/blocks/HeroCarousel.astro +220 -0
  27. package/src/blocks/HighlightCards.astro +107 -0
  28. package/src/blocks/LocationHours.astro +311 -0
  29. package/src/blocks/LogoCloud.astro +135 -0
  30. package/src/blocks/MaintenancePage.astro +173 -0
  31. package/src/blocks/MediaText.astro +177 -0
  32. package/src/blocks/PageHeader.astro +126 -0
  33. package/src/blocks/ProseSection.astro +98 -0
  34. package/src/blocks/Reviews.astro +194 -0
  35. package/src/blocks/RichText.astro +58 -0
  36. package/src/blocks/StatsBand.astro +117 -0
  37. package/src/blocks/Steps.astro +141 -0
  38. package/src/blocks/Testimonials.astro +144 -0
  39. package/src/blocks/Topbar.astro +158 -0
  40. package/src/blocks/cms/card-grid.ts +48 -0
  41. package/src/blocks/cms/consent.ts +16 -0
  42. package/src/blocks/cms/contact-card.ts +46 -0
  43. package/src/blocks/cms/contact-form.ts +37 -0
  44. package/src/blocks/cms/cta-banner.ts +27 -0
  45. package/src/blocks/cms/cta-pair.ts +30 -0
  46. package/src/blocks/cms/data-base.ts +5 -0
  47. package/src/blocks/cms/data.ts +257 -0
  48. package/src/blocks/cms/faq.ts +38 -0
  49. package/src/blocks/cms/feature-grid.ts +47 -0
  50. package/src/blocks/cms/fixtures.ts +591 -0
  51. package/src/blocks/cms/hero-carousel.ts +36 -0
  52. package/src/blocks/cms/hero.ts +33 -0
  53. package/src/blocks/cms/highlight-cards.ts +41 -0
  54. package/src/blocks/cms/images.ts +37 -0
  55. package/src/blocks/cms/index.ts +59 -0
  56. package/src/blocks/cms/location-hours.ts +67 -0
  57. package/src/blocks/cms/logo-cloud.ts +36 -0
  58. package/src/blocks/cms/media-text.ts +26 -0
  59. package/src/blocks/cms/page-header.ts +27 -0
  60. package/src/blocks/cms/pages.ts +35 -0
  61. package/src/blocks/cms/prose-section.ts +25 -0
  62. package/src/blocks/cms/reviews.ts +50 -0
  63. package/src/blocks/cms/schema-dsl.ts +134 -0
  64. package/src/blocks/cms/schema.ts +794 -0
  65. package/src/blocks/cms/shared.ts +63 -0
  66. package/src/blocks/cms/stats-band.ts +35 -0
  67. package/src/blocks/cms/steps.ts +40 -0
  68. package/src/blocks/cms/testimonials.ts +46 -0
  69. package/src/blocks/cms/topbar.ts +27 -0
  70. package/src/blocks/cms/types.ts +27 -0
  71. package/src/blocks/consent.ts +14 -0
  72. package/src/blocks/icons.ts +47 -0
  73. package/src/blocks/index.ts +42 -0
  74. package/src/blocks/internal/Actions.astro +35 -0
  75. package/src/blocks/internal/BlockHeader.astro +45 -0
  76. package/src/blocks/internal/BlockShell.astro +58 -0
  77. package/src/blocks/internal/CarouselScript.astro +7 -0
  78. package/src/blocks/internal/ConsentEmbedScript.astro +7 -0
  79. package/src/blocks/internal/ConsentManagerScript.astro +7 -0
  80. package/src/blocks/internal/HoursScript.astro +7 -0
  81. package/src/blocks/internal/Placeholder.astro +13 -0
  82. package/src/blocks/internal/RichTextNode.astro +133 -0
  83. package/src/blocks/internal/StandaloneDocument.astro +53 -0
  84. package/src/blocks/internal/consent.ts +96 -0
  85. package/src/blocks/internal/fields.ts +18 -0
  86. package/src/blocks/internal/registry-contract.ts +67 -0
  87. package/src/blocks/internal/reviews.ts +22 -0
  88. package/src/blocks/internal/slug.ts +12 -0
  89. package/src/blocks/internal/util.ts +23 -0
  90. package/src/blocks/lib/contact.ts +92 -0
  91. package/src/blocks/lib/error-pages.ts +119 -0
  92. package/src/blocks/lib/faq.ts +37 -0
  93. package/src/blocks/lib/hours.ts +201 -0
  94. package/src/blocks/lib/maintenance.ts +129 -0
  95. package/src/blocks/lib/markdown.ts +350 -0
  96. package/src/blocks/lib/rich-text.ts +132 -0
  97. package/src/blocks/registry.ts +79 -0
  98. package/src/blocks/scripts/carousel.ts +218 -0
  99. package/src/blocks/scripts/consent-embed.ts +105 -0
  100. package/src/blocks/scripts/consent-manager.ts +112 -0
  101. package/src/blocks/scripts/consent-store.ts +86 -0
  102. package/src/blocks/scripts/error-page.ts +71 -0
  103. package/src/blocks/scripts/hours.ts +107 -0
  104. package/src/blocks/scripts/maintenance.ts +109 -0
  105. package/src/blocks/styles/blocks.css +1320 -0
  106. package/src/blocks/styles/consent.css +102 -0
  107. package/src/blocks/styles/faq.css +28 -0
  108. package/src/blocks/styles/location.css +92 -0
  109. package/src/blocks/styles/prose-section.css +13 -0
  110. package/src/blocks/styles/quotes.css +123 -0
  111. package/src/blocks/styles/rich-text.css +14 -0
  112. package/src/blocks/types.ts +293 -0
  113. package/src/data/ChartAxis.astro +19 -0
  114. package/src/data/ChartContainer.astro +152 -0
  115. package/src/data/ChartLegend.astro +25 -0
  116. package/src/data/ChartSeries.astro +14 -0
  117. package/src/data/ChartTable.astro +17 -0
  118. package/src/data/ChartTooltip.astro +20 -0
  119. package/src/data/Sparkline.astro +55 -0
  120. package/src/data/cms.ts +130 -0
  121. package/src/data/index.ts +10 -0
  122. package/src/data/internal/scale.ts +107 -0
  123. package/src/data/lib/chart.ts +459 -0
  124. package/src/data/lib/render.ts +219 -0
  125. package/src/data/lib/sparkline.ts +117 -0
  126. package/src/data/schema.ts +65 -0
  127. package/src/data/scripts/chart.ts +324 -0
  128. package/src/data/styles/chart.css +392 -0
  129. package/src/finishes/aurora.css +75 -0
  130. package/src/finishes/autumn.css +87 -0
  131. package/src/finishes/blueprint.css +69 -0
  132. package/src/finishes/brutalist.css +55 -0
  133. package/src/finishes/clay.css +48 -0
  134. package/src/finishes/day-cycle.css +46 -0
  135. package/src/finishes/fog.css +71 -0
  136. package/src/finishes/glass.css +149 -0
  137. package/src/finishes/holographic.css +91 -0
  138. package/src/finishes/night.css +77 -0
  139. package/src/finishes/paper.css +58 -0
  140. package/src/finishes/polished-glass.css +159 -0
  141. package/src/finishes/rain.css +84 -0
  142. package/src/finishes/scripts/day-cycle.ts +30 -0
  143. package/src/finishes/scripts/holographic.ts +37 -0
  144. package/src/finishes/scripts/spotlight.ts +30 -0
  145. package/src/finishes/spotlight.css +41 -0
  146. package/src/finishes/spring.css +80 -0
  147. package/src/finishes/terminal.css +49 -0
  148. package/src/motion/Marquee.astro +90 -0
  149. package/src/motion/MotionProvider.astro +50 -0
  150. package/src/motion/PageTransitions.astro +61 -0
  151. package/src/motion/Parallax.astro +44 -0
  152. package/src/motion/ParallaxLayer.astro +31 -0
  153. package/src/motion/RevealOnScroll.astro +59 -0
  154. package/src/motion/SceneRegistry.astro +38 -0
  155. package/src/motion/ScrollScene.astro +81 -0
  156. package/src/motion/index.ts +12 -0
  157. package/src/motion/integration.ts +48 -0
  158. package/src/motion/runtime/page-transitions.ts +68 -0
  159. package/src/motion/runtime/runtime.ts +180 -0
  160. package/src/motion/runtime/scenes.ts +248 -0
  161. package/src/motion/runtime/types.ts +103 -0
  162. package/src/motion/styles/motion.css +332 -0
  163. package/src/motion/transitions.ts +74 -0
  164. package/src/motion/virtual.d.ts +4 -0
  165. package/src/primitives/Accordion.astro +129 -0
  166. package/src/primitives/Breadcrumbs.astro +50 -0
  167. package/src/primitives/BulletList.astro +69 -0
  168. package/src/primitives/Button.astro +73 -0
  169. package/src/primitives/ButtonGroup.astro +54 -0
  170. package/src/primitives/Callout.astro +137 -0
  171. package/src/primitives/Caption.astro +35 -0
  172. package/src/primitives/Card.astro +72 -0
  173. package/src/primitives/CardContent.astro +24 -0
  174. package/src/primitives/CardFooter.astro +36 -0
  175. package/src/primitives/CardHeader.astro +86 -0
  176. package/src/primitives/Checkbox.astro +38 -0
  177. package/src/primitives/ChoiceGroup.astro +23 -0
  178. package/src/primitives/Cluster.astro +49 -0
  179. package/src/primitives/Container.astro +44 -0
  180. package/src/primitives/DescriptionList.astro +83 -0
  181. package/src/primitives/Dialog.astro +38 -0
  182. package/src/primitives/Disclosure.astro +67 -0
  183. package/src/primitives/Divider.astro +93 -0
  184. package/src/primitives/Drawer.astro +33 -0
  185. package/src/primitives/Fieldset.astro +80 -0
  186. package/src/primitives/Flex.astro +64 -0
  187. package/src/primitives/FocusRing.astro +63 -0
  188. package/src/primitives/FocusTrap.astro +64 -0
  189. package/src/primitives/Footer.astro +155 -0
  190. package/src/primitives/Form.astro +68 -0
  191. package/src/primitives/FormDescription.astro +26 -0
  192. package/src/primitives/FormError.astro +106 -0
  193. package/src/primitives/FormField.astro +72 -0
  194. package/src/primitives/Grid.astro +64 -0
  195. package/src/primitives/Heading.astro +45 -0
  196. package/src/primitives/IconButton.astro +48 -0
  197. package/src/primitives/Image.astro +125 -0
  198. package/src/primitives/Input.astro +86 -0
  199. package/src/primitives/Label.astro +50 -0
  200. package/src/primitives/Link.astro +81 -0
  201. package/src/primitives/LinkButton.astro +66 -0
  202. package/src/primitives/List.astro +39 -0
  203. package/src/primitives/ListItem.astro +178 -0
  204. package/src/primitives/MediaObject.astro +66 -0
  205. package/src/primitives/MetricCard.astro +278 -0
  206. package/src/primitives/NavLink.astro +81 -0
  207. package/src/primitives/NavMenu.astro +109 -0
  208. package/src/primitives/Navbar.astro +197 -0
  209. package/src/primitives/Panel.astro +153 -0
  210. package/src/primitives/Picture.astro +167 -0
  211. package/src/primitives/Popover.astro +95 -0
  212. package/src/primitives/Prose.astro +45 -0
  213. package/src/primitives/Radio.astro +21 -0
  214. package/src/primitives/Rating.astro +135 -0
  215. package/src/primitives/ReducedMotion.astro +90 -0
  216. package/src/primitives/SegmentedControl.astro +132 -0
  217. package/src/primitives/Select.astro +109 -0
  218. package/src/primitives/Sheet.astro +45 -0
  219. package/src/primitives/SkipLink.astro +31 -0
  220. package/src/primitives/Slider.astro +186 -0
  221. package/src/primitives/Spacer.astro +35 -0
  222. package/src/primitives/Stack.astro +51 -0
  223. package/src/primitives/Surface.astro +70 -0
  224. package/src/primitives/Switch.astro +22 -0
  225. package/src/primitives/Table.astro +382 -0
  226. package/src/primitives/Tabs.astro +126 -0
  227. package/src/primitives/Text.astro +56 -0
  228. package/src/primitives/Textarea.astro +75 -0
  229. package/src/primitives/Thumbnail.astro +154 -0
  230. package/src/primitives/Toggle.astro +99 -0
  231. package/src/primitives/Tooltip.astro +50 -0
  232. package/src/primitives/VisuallyHidden.astro +29 -0
  233. package/src/primitives/index.ts +103 -0
  234. package/src/primitives/internal/AccordionScript.astro +7 -0
  235. package/src/primitives/internal/ChoiceField.astro +91 -0
  236. package/src/primitives/internal/FocusTrapScript.astro +8 -0
  237. package/src/primitives/internal/FormValidationScript.astro +10 -0
  238. package/src/primitives/internal/IndeterminateScript.astro +13 -0
  239. package/src/primitives/internal/ModalPanel.astro +114 -0
  240. package/src/primitives/internal/OverlayScript.astro +7 -0
  241. package/src/primitives/internal/ReducedMotionScript.astro +7 -0
  242. package/src/primitives/internal/SliderScript.astro +7 -0
  243. package/src/primitives/internal/SparklineScript.astro +7 -0
  244. package/src/primitives/internal/TableSortScript.astro +7 -0
  245. package/src/primitives/internal/TabsScript.astro +7 -0
  246. package/src/primitives/internal/TooltipScript.astro +7 -0
  247. package/src/primitives/internal/image-plan.ts +82 -0
  248. package/src/primitives/internal/image.ts +129 -0
  249. package/src/primitives/internal/slider.ts +170 -0
  250. package/src/primitives/lib/deprecate.ts +47 -0
  251. package/src/primitives/lib/focus-trap.ts +197 -0
  252. package/src/primitives/lib/focus.ts +60 -0
  253. package/src/primitives/lib/motion.ts +68 -0
  254. package/src/primitives/scripts/accordion.ts +123 -0
  255. package/src/primitives/scripts/form-validation.ts +225 -0
  256. package/src/primitives/scripts/overlay.ts +71 -0
  257. package/src/primitives/scripts/reduced-motion.ts +59 -0
  258. package/src/primitives/scripts/slider.ts +150 -0
  259. package/src/primitives/scripts/sparkline.ts +131 -0
  260. package/src/primitives/scripts/table-sort.ts +68 -0
  261. package/src/primitives/scripts/tabs.ts +151 -0
  262. package/src/primitives/scripts/tooltip.ts +28 -0
  263. package/src/primitives/styles/a11y.css +104 -0
  264. package/src/primitives/styles/accordion.css +53 -0
  265. package/src/primitives/styles/breadcrumbs.css +59 -0
  266. package/src/primitives/styles/bullet-list.css +89 -0
  267. package/src/primitives/styles/button.css +237 -0
  268. package/src/primitives/styles/choice.css +164 -0
  269. package/src/primitives/styles/cluster.css +24 -0
  270. package/src/primitives/styles/container.css +19 -0
  271. package/src/primitives/styles/data.css +849 -0
  272. package/src/primitives/styles/disclosure.css +140 -0
  273. package/src/primitives/styles/divider.css +50 -0
  274. package/src/primitives/styles/flex.css +42 -0
  275. package/src/primitives/styles/form.css +241 -0
  276. package/src/primitives/styles/grid.css +36 -0
  277. package/src/primitives/styles/media.css +247 -0
  278. package/src/primitives/styles/nav.css +792 -0
  279. package/src/primitives/styles/overlay.css +362 -0
  280. package/src/primitives/styles/prose.css +146 -0
  281. package/src/primitives/styles/scale.css +175 -0
  282. package/src/primitives/styles/segmented.css +165 -0
  283. package/src/primitives/styles/slider.css +170 -0
  284. package/src/primitives/styles/spacer.css +17 -0
  285. package/src/primitives/styles/stack.css +25 -0
  286. package/src/primitives/styles/surface.css +403 -0
  287. package/src/primitives/styles/tabs.css +223 -0
  288. package/src/primitives/styles/typography.css +144 -0
  289. package/src/primitives/styles/utilities.css +24 -0
  290. package/src/primitives/types.ts +385 -0
  291. package/src/primitives/utils.ts +254 -0
  292. package/src/seo/JSONLD.astro +35 -0
  293. package/src/seo/SEOHead.astro +47 -0
  294. package/src/seo/cms.ts +59 -0
  295. package/src/seo/index.ts +10 -0
  296. package/src/seo/integration.ts +268 -0
  297. package/src/seo/internal/url.ts +68 -0
  298. package/src/seo/lib/jsonld.ts +342 -0
  299. package/src/seo/lib/meta.ts +205 -0
  300. package/src/seo/lib/redirects.ts +293 -0
  301. package/src/seo/lib/robots.ts +33 -0
  302. package/src/seo/lib/rss.ts +98 -0
  303. package/src/seo/lib/sitemap.ts +105 -0
  304. package/src/seo/schema.ts +43 -0
  305. package/src/tokens/base.css +71 -0
  306. package/src/tokens/tokens.css +210 -0
@@ -0,0 +1,133 @@
1
+ ---
2
+ /**
3
+ * @internal Renders one rich-text node and, recursively, its children. Only allowlisted node
4
+ * types render; text is escaped by Astro; URLs pass safeLinkUrl / safeMediaUrl first.
5
+ */
6
+ import Image from '../../primitives/Image.astro';
7
+ import { BLOCK_TYPES, INLINE_TYPES, safeLinkUrl, safeMediaUrl, shiftedHeading, type RichTextNode } from '../lib/rich-text';
8
+ import type { ImageResolver } from '../cms/types';
9
+
10
+ type Props = {
11
+ node: RichTextNode;
12
+ contentTop?: number;
13
+ topLevel: number;
14
+ resolveImage?: ImageResolver;
15
+ labels: { table: string };
16
+ };
17
+
18
+ const { node, contentTop, topLevel, resolveImage, labels } = Astro.props;
19
+ const type = typeof node?.type === 'string' ? node.type : '';
20
+ const known = BLOCK_TYPES.has(type) || INLINE_TYPES.has(type);
21
+ if (!known && import.meta.env?.DEV && type) console.warn(`[RichText] "${type}" content isn't supported and was left out.`);
22
+ const kids = Array.isArray(node?.children) ? node.children : [];
23
+ const Self = Astro.self;
24
+ const child = (n: RichTextNode) => ({ node: n, contentTop, topLevel, resolveImage, labels });
25
+
26
+ // Headings
27
+ const hMatch = /^h([1-6])$/.exec(type);
28
+ const H = hMatch ? (`h${shiftedHeading(Number(hMatch[1]), contentTop, topLevel)}` as 'h2') : undefined;
29
+
30
+ // Links
31
+ const href = type === 'a' ? safeLinkUrl(node.url) : undefined;
32
+ const external = href ? /^https?:\/\//i.test(href) : false;
33
+
34
+ // Images
35
+ let img: { meta?: any; src?: string; alt: string; caption?: string } | undefined;
36
+ if (type === 'img') {
37
+ const url = safeMediaUrl(node.url);
38
+ const resolved = url && resolveImage ? resolveImage(url) : undefined;
39
+ const alt = typeof node.alt === 'string' ? node.alt : '';
40
+ const caption = typeof node.caption === 'string' && node.caption.trim() ? node.caption.trim() : undefined;
41
+ if (resolved) img = { meta: resolved, alt, caption };
42
+ else if (url) {
43
+ img = { src: url, alt, caption };
44
+ if (import.meta.env?.DEV) console.warn(`[RichText] Image "${url}" has no known size; pass resolveImage so it doesn't shift the layout.`);
45
+ }
46
+ }
47
+
48
+ // Tables: a first row of header cells becomes the <thead>.
49
+ const sectioned = type === 'table' && kids.some((k) => k?.type === 'thead' || k?.type === 'tbody');
50
+ const headRow = type === 'table' && !sectioned && kids[0]?.type === 'tr' && (kids[0].children ?? []).length > 0 && (kids[0].children ?? []).every((c) => c?.type === 'th');
51
+
52
+ // Text leaf with marks. Underline is left out on purpose: underlined text reads as a link.
53
+ const text = type === 'text' && typeof node.text === 'string' ? node.text : undefined;
54
+ ---
55
+
56
+ {
57
+ text !== undefined ? (
58
+ node.code ? (
59
+ <code>{text}</code>
60
+ ) : node.bold && node.italic ? (
61
+ <strong><em>{node.strikethrough ? <s>{text}</s> : text}</em></strong>
62
+ ) : node.bold ? (
63
+ <strong>{node.strikethrough ? <s>{text}</s> : text}</strong>
64
+ ) : node.italic ? (
65
+ <em>{node.strikethrough ? <s>{text}</s> : text}</em>
66
+ ) : node.strikethrough ? (
67
+ <s>{text}</s>
68
+ ) : (
69
+ <Fragment>{text}</Fragment>
70
+ )
71
+ ) : type === 'break' ? (
72
+ <br />
73
+ ) : type === 'p' ? (
74
+ <p>{kids.map((k) => <Self {...child(k)} />)}</p>
75
+ ) : H ? (
76
+ <H>{kids.map((k) => <Self {...child(k)} />)}</H>
77
+ ) : type === 'ul' ? (
78
+ <ul>{kids.map((k) => <Self {...child(k)} />)}</ul>
79
+ ) : type === 'ol' ? (
80
+ <ol>{kids.map((k) => <Self {...child(k)} />)}</ol>
81
+ ) : type === 'li' ? (
82
+ <li>{kids.map((k) => <Self {...child(k)} />)}</li>
83
+ ) : type === 'lic' ? (
84
+ <Fragment>{kids.map((k) => <Self {...child(k)} />)}</Fragment>
85
+ ) : type === 'blockquote' ? (
86
+ <blockquote>{kids.map((k) => <Self {...child(k)} />)}</blockquote>
87
+ ) : type === 'a' ? (
88
+ href ? (
89
+ <a href={href} title={typeof node.title === 'string' ? node.title : undefined} rel={external ? 'noopener' : undefined}>
90
+ {kids.map((k) => <Self {...child(k)} />)}
91
+ </a>
92
+ ) : (
93
+ <Fragment>{kids.map((k) => <Self {...child(k)} />)}</Fragment>
94
+ )
95
+ ) : type === 'code_block' ? (
96
+ typeof node.value === 'string' && node.value.trim() ? (
97
+ <pre tabindex="0" data-lang={typeof node.lang === 'string' && node.lang ? node.lang : undefined}><code>{node.value}</code></pre>
98
+ ) : null
99
+ ) : type === 'hr' ? (
100
+ <hr />
101
+ ) : type === 'img' ? (
102
+ img ? (
103
+ img.caption ? (
104
+ <figure>
105
+ {img.meta ? <Image src={img.meta} alt={img.alt} placeholder={false} /> : <img src={img.src} alt={img.alt} loading="lazy" decoding="async" />}
106
+ <figcaption>{img.caption}</figcaption>
107
+ </figure>
108
+ ) : img.meta ? (
109
+ <Image src={img.meta} alt={img.alt} placeholder={false} />
110
+ ) : (
111
+ <img src={img.src} alt={img.alt} loading="lazy" decoding="async" />
112
+ )
113
+ ) : null
114
+ ) : type === 'table' ? (
115
+ <div class="sinn-prose__table" tabindex="0" role="region" aria-label={labels.table}>
116
+ <table>
117
+ {sectioned && kids.map((k) => <Self {...child(k)} />)}
118
+ {!sectioned && headRow && <thead><Self {...child(kids[0])} /></thead>}
119
+ {!sectioned && <tbody>{(headRow ? kids.slice(1) : kids).map((k) => <Self {...child(k)} />)}</tbody>}
120
+ </table>
121
+ </div>
122
+ ) : type === 'thead' ? (
123
+ <thead>{kids.map((k) => <Self {...child(k)} />)}</thead>
124
+ ) : type === 'tbody' ? (
125
+ <tbody>{kids.map((k) => <Self {...child(k)} />)}</tbody>
126
+ ) : type === 'tr' ? (
127
+ <tr>{kids.map((k) => <Self {...child(k)} />)}</tr>
128
+ ) : type === 'th' ? (
129
+ <th scope="col">{kids.map((k) => <Self {...child(k)} />)}</th>
130
+ ) : type === 'td' ? (
131
+ <td>{kids.map((k) => <Self {...child(k)} />)}</td>
132
+ ) : null
133
+ }
@@ -0,0 +1,53 @@
1
+ ---
2
+ /**
3
+ * @internal A minimal, self-contained HTML document for pages that must not depend on the site
4
+ * layout: a 500 page (the layout may be what failed) and the maintenance page (the CMS, nav data
5
+ * and other services may be down). Tokens + base styles, a plain header, <main>, noindex.
6
+ */
7
+ import '../../tokens/tokens.css';
8
+ import '../../tokens/base.css';
9
+ import SkipLink from '../../primitives/SkipLink.astro';
10
+
11
+ type Props = {
12
+ title: string;
13
+ description?: string;
14
+ lang?: string;
15
+ siteName?: string;
16
+ /** Link the site name to this URL (omit while the site is down). */
17
+ homeHref?: string;
18
+ };
19
+ const { title, description, lang = 'en', siteName, homeHref } = Astro.props;
20
+ const hasBrand = Boolean(siteName) || Astro.slots.has('brand');
21
+ ---
22
+
23
+ <!doctype html>
24
+ <html lang={lang}>
25
+ <head>
26
+ <meta charset="utf-8" />
27
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
28
+ <meta name="robots" content="noindex" />
29
+ <meta name="color-scheme" content="light dark" />
30
+ <title>{siteName ? `${title} | ${siteName}` : title}</title>
31
+ {description && <meta name="description" content={description} />}
32
+ <slot name="head" />
33
+ </head>
34
+ <body class="sinn-standalone">
35
+ <SkipLink />
36
+ {
37
+ hasBrand && (
38
+ <header class="sinn-standalone__header">
39
+ {Astro.slots.has('brand') ? (
40
+ <slot name="brand" />
41
+ ) : homeHref ? (
42
+ <a class="sinn-standalone__brand" href={homeHref}>{siteName}</a>
43
+ ) : (
44
+ <span class="sinn-standalone__brand">{siteName}</span>
45
+ )}
46
+ </header>
47
+ )
48
+ }
49
+ <main id="main" tabindex="-1" class="sinn-standalone__main">
50
+ <slot />
51
+ </main>
52
+ </body>
53
+ </html>
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Consent records: what a visitor allowed, when, and under which version of your policy.
3
+ * Pure functions (no DOM), shared by the browser store and the unit tests.
4
+ *
5
+ * A record is `{ v: version, t: savedAt (ms), c: { media: true, analytics: false, … } }`, kept
6
+ * in localStorage under `sinn-consent`. It's treated as missing (so the banner asks again) when
7
+ * it's malformed, from another policy version, or older than `maxAgeDays`.
8
+ */
9
+
10
+ export const CONSENT_KEY = 'sinn-consent';
11
+ export const CONSENT_EVENT = 'sinn-consent-change';
12
+
13
+ /** Categories with a fixed meaning. Sites can add their own ids. */
14
+ export type ConsentCategoryId = 'necessary' | 'media' | 'analytics' | 'marketing' | (string & {});
15
+ export type ConsentChoices = Record<string, boolean>;
16
+
17
+ export interface ConsentRecord {
18
+ v: string;
19
+ t: number;
20
+ c: ConsentChoices;
21
+ }
22
+
23
+ export interface ConsentCategory {
24
+ id: ConsentCategoryId;
25
+ label: string;
26
+ description: string;
27
+ }
28
+
29
+ /** Ready-made category texts. Pick the ones your site uses; edit the wording to match it. */
30
+ export const consentCategoryPresets: Record<'necessary' | 'media' | 'analytics' | 'marketing', ConsentCategory> = {
31
+ necessary: {
32
+ id: 'necessary',
33
+ label: 'Necessary',
34
+ description: 'Keeps the site working and remembers these choices. Always on.',
35
+ },
36
+ media: {
37
+ id: 'media',
38
+ label: 'Embedded content',
39
+ description: 'Maps, videos and booking tools from other companies. They may set their own cookies and see your IP address.',
40
+ },
41
+ analytics: {
42
+ id: 'analytics',
43
+ label: 'Analytics',
44
+ description: 'Statistics about how the site is used, so we can improve it.',
45
+ },
46
+ marketing: {
47
+ id: 'marketing',
48
+ label: 'Marketing',
49
+ description: 'Advertising and campaign measurement by other companies.',
50
+ },
51
+ };
52
+
53
+ export const DAY_MS = 86_400_000;
54
+
55
+ /** A stored record, or undefined when it's unusable (the visitor hasn't decided yet). */
56
+ export function parseConsent(raw: string | null | undefined, opts: { version?: string; maxAgeDays?: number; now?: number } = {}): ConsentRecord | undefined {
57
+ if (!raw) return undefined;
58
+ let rec: unknown;
59
+ try {
60
+ rec = JSON.parse(raw);
61
+ } catch {
62
+ return undefined;
63
+ }
64
+ if (!rec || typeof rec !== 'object') return undefined;
65
+ const { v, t, c } = rec as Partial<ConsentRecord>;
66
+ if (typeof v !== 'string' || typeof t !== 'number' || !Number.isFinite(t) || !c || typeof c !== 'object' || Array.isArray(c)) return undefined;
67
+ if (opts.version !== undefined && v !== opts.version) return undefined;
68
+ const now = opts.now ?? Date.now();
69
+ if (t > now + DAY_MS) return undefined; // saved "in the future": clock tampering or a bad record
70
+ if (opts.maxAgeDays !== undefined && now - t > opts.maxAgeDays * DAY_MS) return undefined;
71
+ const choices: ConsentChoices = {};
72
+ for (const [k, val] of Object.entries(c)) if (typeof val === 'boolean' && /^[a-z][a-z0-9-]*$/.test(k)) choices[k] = val;
73
+ return { v, t, c: choices };
74
+ }
75
+
76
+ export function serializeConsent(choices: ConsentChoices, version: string, now = Date.now()): string {
77
+ const c: ConsentChoices = {};
78
+ for (const [k, v] of Object.entries(choices)) if (k !== 'necessary') c[k] = v === true;
79
+ return JSON.stringify({ v: version, t: now, c });
80
+ }
81
+
82
+ /** Necessary is always allowed; everything else only with an explicit yes. */
83
+ export function allows(record: ConsentRecord | undefined, category: string): boolean {
84
+ if (category === 'necessary') return true;
85
+ return record?.c[category] === true;
86
+ }
87
+
88
+ /** Choices that set every listed category to `value` (Accept all / Reject all). */
89
+ export function allChoices(categories: string[], value: boolean): ConsentChoices {
90
+ return Object.fromEntries(categories.filter((c) => c !== 'necessary').map((c) => [c, value]));
91
+ }
92
+
93
+ /** Categories that were allowed before and aren't any more. */
94
+ export function revoked(before: ConsentRecord | undefined, after: ConsentRecord | undefined): string[] {
95
+ return Object.keys(before?.c ?? {}).filter((k) => before!.c[k] === true && !allows(after, k));
96
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @internal `data-sinn-field` annotations for SinnStackCMS visual editing (click a part of the
3
+ * preview to edit that field). Values are dotted paths into the content entry, e.g.
4
+ * `blocks.2.items.0.title`. BlockRenderer passes each block its path (`blocks.2`) when it is
5
+ * given `fieldPath`; without one, nothing is annotated and the HTML stays clean.
6
+ */
7
+
8
+ /** Joins path segments. Undefined when any segment is missing, so partial paths are never emitted. */
9
+ export function joinField(...segments: Array<string | number | null | undefined>): string | undefined {
10
+ if (!segments.length || segments.some((s) => s === undefined || s === null || s === '')) return undefined;
11
+ return segments.join('.');
12
+ }
13
+
14
+ /** Spread helper: {...sf(fieldPath, 'heading')} → { 'data-sinn-field': 'blocks.2.heading' } or {}. */
15
+ export function sf(...segments: Array<string | number | null | undefined>): Record<string, string> {
16
+ const value = joinField(...segments);
17
+ return value ? { 'data-sinn-field': value } : {};
18
+ }
@@ -0,0 +1,67 @@
1
+ /**
2
+ * @internal Type-only contract between each registry entry's mapper and its component: a mapper may
3
+ * only return props the component declares, with types it accepts. `astro check` fails otherwise.
4
+ * Nothing here runs; the file only exists for the type checker.
5
+ */
6
+ import type { ComponentProps } from 'astro/types';
7
+ import type Hero from '../Hero.astro';
8
+ import type CTABanner from '../CTABanner.astro';
9
+ import type FeatureGrid from '../FeatureGrid.astro';
10
+ import type CardGrid from '../CardGrid.astro';
11
+ import type LogoCloud from '../LogoCloud.astro';
12
+ import type HeroCarousel from '../HeroCarousel.astro';
13
+ import type PageHeader from '../PageHeader.astro';
14
+ import type ContactCard from '../ContactCard.astro';
15
+ import type Steps from '../Steps.astro';
16
+ import type MediaText from '../MediaText.astro';
17
+ import type CTAPair from '../CTAPair.astro';
18
+ import type StatsBand from '../StatsBand.astro';
19
+ import type HighlightCards from '../HighlightCards.astro';
20
+ import type ContactForm from '../ContactForm.astro';
21
+ import type ProseSection from '../ProseSection.astro';
22
+ import type FAQ from '../FAQ.astro';
23
+ import type Testimonials from '../Testimonials.astro';
24
+ import type Reviews from '../Reviews.astro';
25
+ import type LocationHours from '../LocationHours.astro';
26
+ import type { heroToProps } from '../cms/hero';
27
+ import type { ctaBannerToProps } from '../cms/cta-banner';
28
+ import type { featureGridToProps } from '../cms/feature-grid';
29
+ import type { cardGridToProps } from '../cms/card-grid';
30
+ import type { logoCloudToProps } from '../cms/logo-cloud';
31
+ import type { heroCarouselToProps } from '../cms/hero-carousel';
32
+ import type { pageHeaderToProps } from '../cms/page-header';
33
+ import type { contactCardToProps } from '../cms/contact-card';
34
+ import type { stepsToProps } from '../cms/steps';
35
+ import type { mediaTextToProps } from '../cms/media-text';
36
+ import type { ctaPairToProps } from '../cms/cta-pair';
37
+ import type { statsBandToProps } from '../cms/stats-band';
38
+ import type { highlightCardsToProps } from '../cms/highlight-cards';
39
+ import type { contactFormToProps } from '../cms/contact-form';
40
+ import type { proseSectionToProps } from '../cms/prose-section';
41
+ import type { faqToProps } from '../cms/faq';
42
+ import type { testimonialsToProps } from '../cms/testimonials';
43
+ import type { reviewsToProps } from '../cms/reviews';
44
+ import type { locationHoursToProps } from '../cms/location-hours';
45
+ type Fits<F extends (...a: any) => any, C extends (p: any) => any> = [Exclude<keyof ReturnType<F>, keyof ComponentProps<C>>] extends [never] ? (ReturnType<F> extends Partial<ComponentProps<C>> ? true : false) : false;
46
+ export type RegistryContract = [
47
+ Fits<typeof heroToProps, typeof Hero>, // hero
48
+ Fits<typeof ctaBannerToProps, typeof CTABanner>, // ctaBanner
49
+ Fits<typeof featureGridToProps, typeof FeatureGrid>, // featureGrid
50
+ Fits<typeof cardGridToProps, typeof CardGrid>, // cardGrid
51
+ Fits<typeof logoCloudToProps, typeof LogoCloud>, // logoCloud
52
+ Fits<typeof heroCarouselToProps, typeof HeroCarousel>, // heroCarousel
53
+ Fits<typeof pageHeaderToProps, typeof PageHeader>, // pageHeader
54
+ Fits<typeof contactCardToProps, typeof ContactCard>, // contactCard
55
+ Fits<typeof stepsToProps, typeof Steps>, // steps
56
+ Fits<typeof mediaTextToProps, typeof MediaText>, // mediaText
57
+ Fits<typeof ctaPairToProps, typeof CTAPair>, // ctaPair
58
+ Fits<typeof statsBandToProps, typeof StatsBand>, // statsBand
59
+ Fits<typeof highlightCardsToProps, typeof HighlightCards>, // highlightCards
60
+ Fits<typeof contactFormToProps, typeof ContactForm>, // contactForm
61
+ Fits<typeof proseSectionToProps, typeof ProseSection>, // proseSection
62
+ Fits<typeof faqToProps, typeof FAQ>, // faq
63
+ Fits<typeof testimonialsToProps, typeof Testimonials>, // testimonials
64
+ Fits<typeof reviewsToProps, typeof Reviews>, // reviews
65
+ Fits<typeof locationHoursToProps, typeof LocationHours>, // locationHours
66
+ ];
67
+ export const registryContract: RegistryContract = [true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true];
@@ -0,0 +1,22 @@
1
+ /** Review helpers: validation and date formatting (pure, unit-tested). */
2
+ import type { ReviewItem } from '../types';
3
+
4
+ /** Reviews with text, an author and a rating within 1..max (rounded to halves). */
5
+ export function validReviews(items: ReviewItem[] | null | undefined, max = 5): ReviewItem[] {
6
+ return (items ?? [])
7
+ .filter((r) => r && typeof r.text === 'string' && r.text.trim() && typeof r.author === 'string' && r.author.trim())
8
+ .filter((r) => typeof r.rating === 'number' && Number.isFinite(r.rating) && r.rating >= 1 && r.rating <= max)
9
+ .map((r) => ({ ...r, author: r.author.trim(), rating: Math.round(r.rating * 2) / 2 }));
10
+ }
11
+
12
+ /**
13
+ * "2026-10-14" → { iso: '2026-10-14', text: 'October 2026' }. Dates are calendar dates, so
14
+ * they're formatted in UTC (a review from the 1st never shows as the previous month).
15
+ */
16
+ export function formatReviewDate(value: string | undefined, locale = 'en-US'): { iso: string; text: string } | undefined {
17
+ if (!value || !/^\d{4}-\d{2}(-\d{2})?/.test(value)) return undefined;
18
+ const iso = value.slice(0, 10).length === 7 ? `${value.slice(0, 7)}-01` : value.slice(0, 10);
19
+ const d = new Date(`${iso}T00:00:00Z`);
20
+ if (Number.isNaN(d.getTime())) return undefined;
21
+ return { iso: value.slice(0, 10), text: new Intl.DateTimeFormat(locale, { month: 'long', year: 'numeric', timeZone: 'UTC' }).format(d) };
22
+ }
@@ -0,0 +1,12 @@
1
+ /** Dependency-free slug helper (shared by blocks and their unit tests). */
2
+
3
+ /** URL-fragment-safe slug for anchors: "Our Services!" → "our-services". */
4
+ export function slugify(value: string): string {
5
+ return value
6
+ .normalize('NFKD')
7
+ .replace(/[̀-ͯ]/g, '')
8
+ .toLowerCase()
9
+ .replace(/[^a-z0-9]+/g, '-')
10
+ .replace(/^-+|-+$/g, '')
11
+ .replace(/^(\d)/, 'n$1');
12
+ }
@@ -0,0 +1,23 @@
1
+ /** @internal Small helpers shared by blocks. */
2
+ import { uid } from '../../primitives/utils';
3
+ import type { ActionItem } from '../types';
4
+
5
+ export { slugify } from './slug';
6
+ import { slugify } from './slug';
7
+
8
+ /** The section's id (from `anchor` or `id`) and a heading id derived from it. */
9
+ export function blockIds(name: string, anchor?: string, id?: string | null): { sectionId?: string; headingId: string } {
10
+ const sectionId = anchor ? slugify(anchor) || undefined : (id ?? undefined);
11
+ return { sectionId, headingId: `${sectionId ?? uid(`sinn-${name}`)}-title` };
12
+ }
13
+
14
+ export function actionVariant(action: ActionItem, index: number): NonNullable<ActionItem['variant']> {
15
+ return action.variant ?? (index === 0 ? 'solid' : 'outline');
16
+ }
17
+
18
+ export function isNonEmpty(value: unknown): boolean {
19
+ return typeof value === 'string' ? value.trim().length > 0 : value != null;
20
+ }
21
+
22
+ /** Placeholder default: on in `astro dev`, off in builds (overridable per block). */
23
+ export const PLACEHOLDER_DEFAULT: boolean = Boolean(import.meta.env?.DEV);
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Contact helpers shared by ContactCard and Topbar: click-to-call links, mailto links and the
3
+ * per-type defaults (label, icon). Pure functions, SSR-safe.
4
+ */
5
+ import type { ContactItem } from '../types';
6
+
7
+ /**
8
+ * A `tel:` URL from a human-written number: "(888) 450-2884" → "tel:+18884502884".
9
+ * - Keeps a leading "+" (already international).
10
+ * - Ten digits get `countryCode` (default "1", NANP); eleven digits starting with it are kept.
11
+ * - Extensions ("x123", "ext. 123") become `;ext=123` (RFC 3966).
12
+ * - Capital letters (1-800-FLOWERS) are mapped to keypad digits. A value with lowercase letters
13
+ * ("Call us 24/7") isn't a phone number and returns undefined (extensions are handled first).
14
+ * Returns undefined when there are fewer than 3 digits (not a callable number).
15
+ */
16
+ export function telHref(value: string, countryCode = '1'): string | undefined {
17
+ if (typeof value !== 'string') return undefined;
18
+ const raw = value.trim();
19
+ if (!raw) return undefined;
20
+ const extMatch = /(?:\s*(?:ext\.?|extension|x|#)\s*)(\d{1,6})\s*$/i.exec(raw);
21
+ const main = extMatch ? raw.slice(0, extMatch.index) : raw;
22
+ const international = main.startsWith('+');
23
+ // Letters only count in a vanity number ("1-800-FLOWERS": capitals, at least 3 digits), never in
24
+ // prose ("Call us 24/7"): any lowercase letter means it isn't a phone number.
25
+ if ((main.match(/\d/g) ?? []).length < 3 || /[a-z]/.test(main)) return undefined;
26
+ const digits = main.toUpperCase().replace(/[A-Z]/g, (c) => KEYPAD[c] ?? '').replace(/\D/g, '');
27
+ if (digits.length < 3) return undefined;
28
+ let number: string;
29
+ if (international) number = `+${digits}`;
30
+ else if (digits.length === 10 && countryCode) number = `+${countryCode}${digits}`;
31
+ else if (countryCode && digits.length === 10 + countryCode.length && digits.startsWith(countryCode)) number = `+${digits}`;
32
+ else number = digits; // short codes (911, 988) and local numbers stay as dialed
33
+ return `tel:${number}${extMatch ? `;ext=${extMatch[1]}` : ''}`;
34
+ }
35
+
36
+ const KEYPAD: Record<string, string> = Object.fromEntries(
37
+ ['ABC2', 'DEF3', 'GHI4', 'JKL5', 'MNO6', 'PQRS7', 'TUV8', 'WXYZ9'].flatMap((group) => {
38
+ const digit = group.slice(-1);
39
+ return group.slice(0, -1).split('').map((c) => [c, digit]);
40
+ }),
41
+ );
42
+
43
+ export function mailHref(value: string): string | undefined {
44
+ const v = typeof value === 'string' ? value.trim() : '';
45
+ return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(v) ? `mailto:${v}` : undefined;
46
+ }
47
+
48
+ /**
49
+ * Only these schemes become links (CMS content can't inject javascript: or data: URLs).
50
+ * Browsers drop tabs, newlines and leading control characters from URLs (`java<TAB>script:` runs as
51
+ * `javascript:`) and read `\` as `/`, so values containing them are refused outright, as are
52
+ * protocol-relative `//host` links (they go to another site; write `https://` instead).
53
+ */
54
+ export function safeHref(href: string | null | undefined): string | undefined {
55
+ const v = typeof href === 'string' ? href.trim() : '';
56
+ if (!v || /[\x00-\x1f\x7f\\]/.test(v) || v.startsWith('//')) return undefined;
57
+ // A scheme needs something after it: bare `https://`, `mailto:` or `tel:` links nowhere.
58
+ if (/^(https?:\/\/[^/\s]|(mailto|tel|sms):\S)/i.test(v) || v.startsWith('/') || v.startsWith('#') || v.startsWith('?')) return v;
59
+ if (/^[a-z][a-z0-9+.-]*:/i.test(v)) return undefined; // any other scheme
60
+ return v; // relative path
61
+ }
62
+
63
+ export const contactDefaults: Record<ContactItem['type'], { label: string; icon: string }> = {
64
+ address: { label: 'Address', icon: 'mapPin' },
65
+ phone: { label: 'Phone', icon: 'phone' },
66
+ fax: { label: 'Fax', icon: 'fax' },
67
+ email: { label: 'Email', icon: 'mail' },
68
+ hours: { label: 'Hours', icon: 'clock' },
69
+ link: { label: '', icon: 'link' },
70
+ };
71
+
72
+ /** The link for a contact item, or undefined when it renders as text. */
73
+ export function contactHref(item: Pick<ContactItem, 'type' | 'value' | 'href'>, countryCode = '1'): string | undefined {
74
+ switch (item.type) {
75
+ case 'phone':
76
+ return safeHref(item.href) ?? telHref(item.value, countryCode);
77
+ case 'email':
78
+ return safeHref(item.href) ?? mailHref(item.value);
79
+ case 'link':
80
+ return safeHref(item.href) ?? safeHref(item.value);
81
+ default:
82
+ return undefined; // address, hours and fax are never links
83
+ }
84
+ }
85
+
86
+ /** Lines of a multi-line value ("560 N Kimball Ave\nSouthlake, TX"), trimmed, blanks dropped. */
87
+ export function lines(value: string): string[] {
88
+ return String(value ?? '')
89
+ .split(/\r?\n/)
90
+ .map((l) => l.trim())
91
+ .filter(Boolean);
92
+ }
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Error-page copy presets and the "Did you mean…?" matcher. Pure functions: used at build time,
3
+ * in the client script, and in tests. No DOM access.
4
+ */
5
+ export type ErrorStatus = 400 | 401 | 403 | 404 | 410 | 500 | 502 | 503 | 504;
6
+
7
+ export interface ErrorCopy {
8
+ /** Document <title> text (the site name is appended by the layout). */
9
+ title: string;
10
+ heading: string;
11
+ description: string;
12
+ }
13
+
14
+ /** Plain, calm copy. Override any field per site (and translate it). */
15
+ export const errorCopy: Record<ErrorStatus, ErrorCopy> = {
16
+ 400: { title: 'Bad request', heading: 'That request didn’t work', description: 'Something in the link or form wasn’t quite right. Go back and try again.' },
17
+ 401: { title: 'Sign in required', heading: 'Please sign in to continue', description: 'This page is only available after you sign in.' },
18
+ 403: { title: 'Access denied', heading: 'You don’t have access to this page', description: 'If you think you should, sign in with a different account or contact us.' },
19
+ 404: { title: 'Page not found', heading: 'We can’t find that page', description: 'The link may be broken, or the page may have moved. Check the address, or try one of the pages below.' },
20
+ 410: { title: 'Page removed', heading: 'This page is no longer available', description: 'It was removed on purpose. The pages below may have what you’re looking for.' },
21
+ 500: { title: 'Something went wrong', heading: 'Something went wrong on our end', description: 'It’s not something you did. Try again in a moment. If it keeps happening, please contact us.' },
22
+ 502: { title: 'Temporarily unavailable', heading: 'We’re having trouble right now', description: 'Our servers aren’t responding as they should. Try again in a minute.' },
23
+ 503: { title: 'Temporarily unavailable', heading: 'We’ll be right back', description: 'The site is briefly unavailable. Try again in a few minutes.' },
24
+ 504: { title: 'Temporarily unavailable', heading: 'That took too long', description: 'Our servers didn’t respond in time. Try again in a minute.' },
25
+ };
26
+
27
+ /** Copy for any status: known presets, otherwise the 4xx / 5xx family default. */
28
+ export function copyFor(status: number): ErrorCopy {
29
+ return (errorCopy as Record<number, ErrorCopy>)[status] ?? (status >= 500 ? errorCopy[500] : errorCopy[404]);
30
+ }
31
+
32
+ /** True for statuses where "the page you asked for isn't here" applies (suggest, search). */
33
+ export const isMissing = (status: number) => status === 404 || status === 410;
34
+ /** True for server-side failures (offer "Try again"). */
35
+ export const isServerError = (status: number) => status >= 500;
36
+
37
+ export interface SuggestCandidate {
38
+ href: string;
39
+ label: string;
40
+ }
41
+
42
+ /** Path normalized for comparison: lowercase, decoded, no query/hash/extension/trailing slash. */
43
+ export function normalizePath(path: string): string {
44
+ let p = path.split(/[?#]/)[0];
45
+ try {
46
+ p = decodeURIComponent(p);
47
+ } catch {
48
+ /* keep raw */
49
+ }
50
+ return (
51
+ p
52
+ .toLowerCase()
53
+ .replace(/\/index\.html?$/, '/')
54
+ .replace(/\.(html?|php|aspx?)$/, '')
55
+ .replace(/\/{2,}/g, '/')
56
+ .replace(/(.)\/$/, '$1') || '/'
57
+ );
58
+ }
59
+
60
+ /** Levenshtein distance with an early exit once it exceeds `max`. */
61
+ export function editDistance(a: string, b: string, max = Infinity): number {
62
+ if (Math.abs(a.length - b.length) > max) return max + 1;
63
+ let prev = Array.from({ length: b.length + 1 }, (_, i) => i);
64
+ for (let i = 1; i <= a.length; i++) {
65
+ const cur = [i];
66
+ let rowMin = i;
67
+ for (let j = 1; j <= b.length; j++) {
68
+ const v = Math.min(prev[j] + 1, cur[j - 1] + 1, prev[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
69
+ cur.push(v);
70
+ if (v < rowMin) rowMin = v;
71
+ }
72
+ if (rowMin > max) return max + 1;
73
+ prev = cur;
74
+ }
75
+ return prev[b.length];
76
+ }
77
+
78
+ const lastSegment = (p: string) => p.slice(p.lastIndexOf('/') + 1);
79
+ const words = (p: string) => p.split(/[^a-z0-9]+/).filter((w) => w.length > 1);
80
+
81
+ /**
82
+ * The closest known page to a missing path, or undefined if nothing is close enough.
83
+ * Catches typos ("/servcies" → "/services"), wrong case or extension ("/About.html" → "/about"),
84
+ * a moved page with the same slug ("/blog/astro-tips" → "/resources/astro-tips"), and reordered
85
+ * words ("/design-web" → "/web-design").
86
+ */
87
+ export function suggestPage(path: string, candidates: SuggestCandidate[]): SuggestCandidate | undefined {
88
+ const target = normalizePath(path);
89
+ if (target === '/') return undefined;
90
+ const tSlug = lastSegment(target);
91
+ const tWords = new Set(words(target));
92
+ let best: { c: SuggestCandidate; score: number } | undefined;
93
+ for (const c of candidates) {
94
+ const cand = normalizePath(c.href);
95
+ if (cand === target) return c; // only case/extension/slash differed
96
+ const cSlug = lastSegment(cand);
97
+ // Distances past their budget count as "too far" (score 1), not as a small ratio.
98
+ const ratio = (a: string, b: string, budget: number) => {
99
+ const d = editDistance(a, b, budget);
100
+ return d > budget ? 1 : d / Math.max(a.length, b.length);
101
+ };
102
+ const full = ratio(target, cand, Math.max(2, Math.floor(target.length * 0.3)));
103
+ const slug = tSlug.length >= 4 && cSlug.length >= 4 ? ratio(tSlug, cSlug, Math.max(1, Math.floor(tSlug.length * 0.34))) : 1;
104
+ const cWords = words(cand);
105
+ const shared = cWords.filter((w) => tWords.has(w)).length;
106
+ const overlap = cWords.length && tWords.size ? shared / Math.max(cWords.length, tWords.size) : 0;
107
+ const score = Math.min(full, slug + 0.05, 1 - overlap + 0.1);
108
+ if (!best || score < best.score) best = { c, score };
109
+ }
110
+ return best && best.score <= 0.34 ? best.c : undefined;
111
+ }
112
+
113
+ /** Search words taken from a missing path ("/services/home-helth" → "services home helth"). */
114
+ export function searchTermsFromPath(path: string, max = 6): string {
115
+ const parts = normalizePath(path)
116
+ .split(/[/\-_+.]+/)
117
+ .filter((w) => w && !/^\d+$/.test(w) && w.length > 1);
118
+ return parts.slice(-max).join(' ');
119
+ }