@sinnstack/ui 0.0.0-stage → 0.2.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 (280) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/LICENSE +373 -0
  3. package/README.md +186 -2
  4. package/docs/blocks.md +364 -0
  5. package/docs/data.md +128 -0
  6. package/docs/motion.md +166 -0
  7. package/docs/primitives.md +510 -0
  8. package/docs/seo.md +187 -0
  9. package/docs/tokens.md +122 -0
  10. package/package.json +141 -3
  11. package/scripts/check-contrast.mjs +180 -0
  12. package/src/blocks/BlockRenderer.astro +54 -0
  13. package/src/blocks/CTABanner.astro +121 -0
  14. package/src/blocks/CTAPair.astro +110 -0
  15. package/src/blocks/CardGrid.astro +167 -0
  16. package/src/blocks/ConsentEmbed.astro +125 -0
  17. package/src/blocks/ConsentManager.astro +147 -0
  18. package/src/blocks/ConsentScript.astro +47 -0
  19. package/src/blocks/ContactCard.astro +164 -0
  20. package/src/blocks/ContactForm.astro +224 -0
  21. package/src/blocks/ErrorPage.astro +242 -0
  22. package/src/blocks/FAQ.astro +135 -0
  23. package/src/blocks/FeatureGrid.astro +148 -0
  24. package/src/blocks/Hero.astro +171 -0
  25. package/src/blocks/HeroCarousel.astro +220 -0
  26. package/src/blocks/HighlightCards.astro +107 -0
  27. package/src/blocks/LocationHours.astro +311 -0
  28. package/src/blocks/LogoCloud.astro +135 -0
  29. package/src/blocks/MaintenancePage.astro +168 -0
  30. package/src/blocks/MediaText.astro +177 -0
  31. package/src/blocks/PageHeader.astro +126 -0
  32. package/src/blocks/ProseSection.astro +98 -0
  33. package/src/blocks/Reviews.astro +194 -0
  34. package/src/blocks/RichText.astro +57 -0
  35. package/src/blocks/StatsBand.astro +117 -0
  36. package/src/blocks/Steps.astro +141 -0
  37. package/src/blocks/Testimonials.astro +144 -0
  38. package/src/blocks/Topbar.astro +158 -0
  39. package/src/blocks/cms/card-grid.ts +80 -0
  40. package/src/blocks/cms/consent.ts +45 -0
  41. package/src/blocks/cms/contact-card.ts +88 -0
  42. package/src/blocks/cms/contact-form.ts +55 -0
  43. package/src/blocks/cms/cta-banner.ts +48 -0
  44. package/src/blocks/cms/cta-pair.ts +63 -0
  45. package/src/blocks/cms/data-base.ts +7 -0
  46. package/src/blocks/cms/data.ts +257 -0
  47. package/src/blocks/cms/faq.ts +70 -0
  48. package/src/blocks/cms/feature-grid.ts +80 -0
  49. package/src/blocks/cms/fixtures.ts +599 -0
  50. package/src/blocks/cms/hero-carousel.ts +80 -0
  51. package/src/blocks/cms/hero.ts +77 -0
  52. package/src/blocks/cms/highlight-cards.ts +76 -0
  53. package/src/blocks/cms/images.ts +38 -0
  54. package/src/blocks/cms/index.ts +87 -0
  55. package/src/blocks/cms/location-hours.ts +149 -0
  56. package/src/blocks/cms/logo-cloud.ts +62 -0
  57. package/src/blocks/cms/media-text.ts +44 -0
  58. package/src/blocks/cms/page-header.ts +49 -0
  59. package/src/blocks/cms/pages.ts +81 -0
  60. package/src/blocks/cms/prose-section.ts +45 -0
  61. package/src/blocks/cms/reviews.ts +101 -0
  62. package/src/blocks/cms/shared.ts +115 -0
  63. package/src/blocks/cms/stats-band.ts +61 -0
  64. package/src/blocks/cms/steps.ts +67 -0
  65. package/src/blocks/cms/testimonials.ts +80 -0
  66. package/src/blocks/cms/topbar.ts +64 -0
  67. package/src/blocks/cms/types.ts +63 -0
  68. package/src/blocks/consent.ts +14 -0
  69. package/src/blocks/icons.ts +47 -0
  70. package/src/blocks/index.ts +42 -0
  71. package/src/blocks/internal/Actions.astro +29 -0
  72. package/src/blocks/internal/BlockHeader.astro +45 -0
  73. package/src/blocks/internal/BlockShell.astro +58 -0
  74. package/src/blocks/internal/CarouselScript.astro +7 -0
  75. package/src/blocks/internal/ConsentEmbedScript.astro +7 -0
  76. package/src/blocks/internal/ConsentManagerScript.astro +7 -0
  77. package/src/blocks/internal/HoursScript.astro +7 -0
  78. package/src/blocks/internal/Placeholder.astro +13 -0
  79. package/src/blocks/internal/RichTextNode.astro +133 -0
  80. package/src/blocks/internal/StandaloneDocument.astro +53 -0
  81. package/src/blocks/internal/tina.ts +19 -0
  82. package/src/blocks/internal/util.ts +23 -0
  83. package/src/blocks/lib/consent.ts +96 -0
  84. package/src/blocks/lib/contact.ts +86 -0
  85. package/src/blocks/lib/error-pages.ts +119 -0
  86. package/src/blocks/lib/faq.ts +37 -0
  87. package/src/blocks/lib/hours.ts +201 -0
  88. package/src/blocks/lib/maintenance.ts +129 -0
  89. package/src/blocks/lib/reviews.ts +22 -0
  90. package/src/blocks/lib/rich-text.ts +143 -0
  91. package/src/blocks/lib/slug.ts +12 -0
  92. package/src/blocks/registry.ts +79 -0
  93. package/src/blocks/scripts/carousel.ts +218 -0
  94. package/src/blocks/scripts/consent-embed.ts +105 -0
  95. package/src/blocks/scripts/consent-manager.ts +112 -0
  96. package/src/blocks/scripts/consent-store.ts +86 -0
  97. package/src/blocks/scripts/error-page.ts +71 -0
  98. package/src/blocks/scripts/hours.ts +106 -0
  99. package/src/blocks/scripts/maintenance.ts +109 -0
  100. package/src/blocks/styles/blocks.css +1320 -0
  101. package/src/blocks/styles/consent.css +102 -0
  102. package/src/blocks/styles/faq.css +28 -0
  103. package/src/blocks/styles/location.css +92 -0
  104. package/src/blocks/styles/prose-section.css +13 -0
  105. package/src/blocks/styles/quotes.css +123 -0
  106. package/src/blocks/styles/rich-text.css +14 -0
  107. package/src/blocks/types.ts +283 -0
  108. package/src/data/ChartAxis.astro +19 -0
  109. package/src/data/ChartContainer.astro +151 -0
  110. package/src/data/ChartLegend.astro +25 -0
  111. package/src/data/ChartSeries.astro +14 -0
  112. package/src/data/ChartTable.astro +17 -0
  113. package/src/data/ChartTooltip.astro +20 -0
  114. package/src/data/Sparkline.astro +55 -0
  115. package/src/data/cms.ts +190 -0
  116. package/src/data/index.ts +10 -0
  117. package/src/data/lib/chart.ts +450 -0
  118. package/src/data/lib/render.ts +219 -0
  119. package/src/data/lib/scale.ts +107 -0
  120. package/src/data/lib/sparkline.ts +117 -0
  121. package/src/data/scripts/chart.ts +324 -0
  122. package/src/data/styles/chart.css +392 -0
  123. package/src/motion/Marquee.astro +90 -0
  124. package/src/motion/MotionProvider.astro +50 -0
  125. package/src/motion/PageTransitions.astro +61 -0
  126. package/src/motion/Parallax.astro +44 -0
  127. package/src/motion/ParallaxLayer.astro +31 -0
  128. package/src/motion/RevealOnScroll.astro +59 -0
  129. package/src/motion/SceneRegistry.astro +38 -0
  130. package/src/motion/ScrollScene.astro +81 -0
  131. package/src/motion/index.ts +12 -0
  132. package/src/motion/integration.ts +48 -0
  133. package/src/motion/runtime/page-transitions.ts +68 -0
  134. package/src/motion/runtime/runtime.ts +180 -0
  135. package/src/motion/runtime/scenes.ts +248 -0
  136. package/src/motion/runtime/types.ts +103 -0
  137. package/src/motion/styles/motion.css +332 -0
  138. package/src/motion/transitions.ts +74 -0
  139. package/src/motion/virtual.d.ts +4 -0
  140. package/src/primitives/Accordion.astro +129 -0
  141. package/src/primitives/Breadcrumbs.astro +50 -0
  142. package/src/primitives/BulletList.astro +69 -0
  143. package/src/primitives/Button.astro +73 -0
  144. package/src/primitives/ButtonGroup.astro +54 -0
  145. package/src/primitives/Callout.astro +137 -0
  146. package/src/primitives/Caption.astro +35 -0
  147. package/src/primitives/Card.astro +72 -0
  148. package/src/primitives/CardContent.astro +24 -0
  149. package/src/primitives/CardFooter.astro +36 -0
  150. package/src/primitives/CardHeader.astro +86 -0
  151. package/src/primitives/Checkbox.astro +38 -0
  152. package/src/primitives/ChoiceGroup.astro +23 -0
  153. package/src/primitives/Cluster.astro +49 -0
  154. package/src/primitives/Container.astro +44 -0
  155. package/src/primitives/DescriptionList.astro +83 -0
  156. package/src/primitives/Dialog.astro +38 -0
  157. package/src/primitives/Disclosure.astro +67 -0
  158. package/src/primitives/Divider.astro +93 -0
  159. package/src/primitives/Drawer.astro +33 -0
  160. package/src/primitives/Fieldset.astro +80 -0
  161. package/src/primitives/Flex.astro +64 -0
  162. package/src/primitives/FocusRing.astro +63 -0
  163. package/src/primitives/FocusTrap.astro +64 -0
  164. package/src/primitives/Footer.astro +155 -0
  165. package/src/primitives/Form.astro +68 -0
  166. package/src/primitives/FormDescription.astro +26 -0
  167. package/src/primitives/FormError.astro +106 -0
  168. package/src/primitives/FormField.astro +72 -0
  169. package/src/primitives/Grid.astro +64 -0
  170. package/src/primitives/Heading.astro +45 -0
  171. package/src/primitives/IconButton.astro +48 -0
  172. package/src/primitives/Image.astro +125 -0
  173. package/src/primitives/Input.astro +84 -0
  174. package/src/primitives/Label.astro +50 -0
  175. package/src/primitives/Link.astro +81 -0
  176. package/src/primitives/LinkButton.astro +66 -0
  177. package/src/primitives/List.astro +39 -0
  178. package/src/primitives/ListItem.astro +178 -0
  179. package/src/primitives/MediaObject.astro +66 -0
  180. package/src/primitives/MetricCard.astro +276 -0
  181. package/src/primitives/NavLink.astro +81 -0
  182. package/src/primitives/NavMenu.astro +109 -0
  183. package/src/primitives/Navbar.astro +197 -0
  184. package/src/primitives/Panel.astro +153 -0
  185. package/src/primitives/Picture.astro +167 -0
  186. package/src/primitives/Popover.astro +95 -0
  187. package/src/primitives/Prose.astro +45 -0
  188. package/src/primitives/Radio.astro +21 -0
  189. package/src/primitives/Rating.astro +135 -0
  190. package/src/primitives/ReducedMotion.astro +90 -0
  191. package/src/primitives/SegmentedControl.astro +132 -0
  192. package/src/primitives/Select.astro +107 -0
  193. package/src/primitives/Sheet.astro +45 -0
  194. package/src/primitives/SkipLink.astro +31 -0
  195. package/src/primitives/Slider.astro +186 -0
  196. package/src/primitives/Spacer.astro +35 -0
  197. package/src/primitives/Stack.astro +51 -0
  198. package/src/primitives/Surface.astro +70 -0
  199. package/src/primitives/Switch.astro +22 -0
  200. package/src/primitives/Table.astro +382 -0
  201. package/src/primitives/Tabs.astro +126 -0
  202. package/src/primitives/Text.astro +56 -0
  203. package/src/primitives/Textarea.astro +73 -0
  204. package/src/primitives/Thumbnail.astro +154 -0
  205. package/src/primitives/Toggle.astro +99 -0
  206. package/src/primitives/Tooltip.astro +50 -0
  207. package/src/primitives/VisuallyHidden.astro +29 -0
  208. package/src/primitives/index.ts +103 -0
  209. package/src/primitives/internal/AccordionScript.astro +7 -0
  210. package/src/primitives/internal/ChoiceField.astro +89 -0
  211. package/src/primitives/internal/FocusTrapScript.astro +8 -0
  212. package/src/primitives/internal/FormValidationScript.astro +10 -0
  213. package/src/primitives/internal/IndeterminateScript.astro +13 -0
  214. package/src/primitives/internal/ModalPanel.astro +114 -0
  215. package/src/primitives/internal/OverlayScript.astro +7 -0
  216. package/src/primitives/internal/ReducedMotionScript.astro +7 -0
  217. package/src/primitives/internal/SliderScript.astro +7 -0
  218. package/src/primitives/internal/SparklineScript.astro +7 -0
  219. package/src/primitives/internal/TableSortScript.astro +7 -0
  220. package/src/primitives/internal/TabsScript.astro +7 -0
  221. package/src/primitives/internal/TooltipScript.astro +7 -0
  222. package/src/primitives/lib/deprecate.ts +47 -0
  223. package/src/primitives/lib/focus-trap.ts +197 -0
  224. package/src/primitives/lib/focus.ts +60 -0
  225. package/src/primitives/lib/image-plan.ts +82 -0
  226. package/src/primitives/lib/image.ts +129 -0
  227. package/src/primitives/lib/motion.ts +68 -0
  228. package/src/primitives/lib/slider.ts +170 -0
  229. package/src/primitives/scripts/accordion.ts +123 -0
  230. package/src/primitives/scripts/form-validation.ts +225 -0
  231. package/src/primitives/scripts/overlay.ts +71 -0
  232. package/src/primitives/scripts/reduced-motion.ts +59 -0
  233. package/src/primitives/scripts/slider.ts +150 -0
  234. package/src/primitives/scripts/sparkline.ts +131 -0
  235. package/src/primitives/scripts/table-sort.ts +68 -0
  236. package/src/primitives/scripts/tabs.ts +151 -0
  237. package/src/primitives/scripts/tooltip.ts +28 -0
  238. package/src/primitives/styles/a11y.css +104 -0
  239. package/src/primitives/styles/accordion.css +53 -0
  240. package/src/primitives/styles/breadcrumbs.css +59 -0
  241. package/src/primitives/styles/bullet-list.css +89 -0
  242. package/src/primitives/styles/button.css +237 -0
  243. package/src/primitives/styles/choice.css +164 -0
  244. package/src/primitives/styles/cluster.css +24 -0
  245. package/src/primitives/styles/container.css +19 -0
  246. package/src/primitives/styles/data.css +849 -0
  247. package/src/primitives/styles/disclosure.css +140 -0
  248. package/src/primitives/styles/divider.css +50 -0
  249. package/src/primitives/styles/flex.css +42 -0
  250. package/src/primitives/styles/form.css +241 -0
  251. package/src/primitives/styles/grid.css +36 -0
  252. package/src/primitives/styles/media.css +247 -0
  253. package/src/primitives/styles/nav.css +792 -0
  254. package/src/primitives/styles/overlay.css +362 -0
  255. package/src/primitives/styles/prose.css +146 -0
  256. package/src/primitives/styles/scale.css +175 -0
  257. package/src/primitives/styles/segmented.css +165 -0
  258. package/src/primitives/styles/slider.css +170 -0
  259. package/src/primitives/styles/spacer.css +17 -0
  260. package/src/primitives/styles/stack.css +25 -0
  261. package/src/primitives/styles/surface.css +403 -0
  262. package/src/primitives/styles/tabs.css +223 -0
  263. package/src/primitives/styles/typography.css +144 -0
  264. package/src/primitives/styles/utilities.css +24 -0
  265. package/src/primitives/types.ts +385 -0
  266. package/src/primitives/utils.ts +254 -0
  267. package/src/seo/JSONLD.astro +35 -0
  268. package/src/seo/SEOHead.astro +47 -0
  269. package/src/seo/cms.ts +80 -0
  270. package/src/seo/index.ts +10 -0
  271. package/src/seo/integration.ts +231 -0
  272. package/src/seo/lib/jsonld.ts +334 -0
  273. package/src/seo/lib/meta.ts +205 -0
  274. package/src/seo/lib/redirects.ts +283 -0
  275. package/src/seo/lib/robots.ts +33 -0
  276. package/src/seo/lib/rss.ts +98 -0
  277. package/src/seo/lib/sitemap.ts +105 -0
  278. package/src/seo/lib/url.ts +68 -0
  279. package/src/tokens/base.css +71 -0
  280. package/src/tokens/tokens.css +210 -0
@@ -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,143 @@
1
+ /**
2
+ * Rich text from the CMS: TinaCMS's rich-text AST (or plain text), normalized for RichText.
3
+ *
4
+ * Safety by construction: RichText renders only the node types listed in BLOCK_TYPES and
5
+ * INLINE_TYPES, as Astro elements (text is always escaped). Raw HTML nodes, MDX templates and
6
+ * unknown types are dropped. Links and images keep only safe URLs (http(s), mailto, tel,
7
+ * relative); anything else (javascript:, data:, vbscript:…) is removed.
8
+ */
9
+ import { safeHref } from './contact';
10
+
11
+ export interface RichTextNode {
12
+ type: string;
13
+ children?: RichTextNode[];
14
+ /** Text leaves. */
15
+ text?: string;
16
+ bold?: boolean;
17
+ italic?: boolean;
18
+ code?: boolean;
19
+ strikethrough?: boolean;
20
+ underline?: boolean;
21
+ /** Links and images. */
22
+ url?: string;
23
+ title?: string;
24
+ alt?: string;
25
+ caption?: string;
26
+ /** Code blocks. */
27
+ value?: string;
28
+ lang?: string;
29
+ [key: string]: unknown;
30
+ }
31
+ export interface RichTextRoot extends RichTextNode {
32
+ type: 'root';
33
+ children: RichTextNode[];
34
+ }
35
+ /** What a block accepts: a Tina rich-text AST, plain text (blank lines separate paragraphs), or nothing. */
36
+ export type RichTextValue = RichTextRoot | RichTextNode[] | string | null | undefined;
37
+
38
+ export const BLOCK_TYPES = new Set(['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'ul', 'ol', 'li', 'lic', 'blockquote', 'code_block', 'img', 'hr', 'table', 'thead', 'tbody', 'tr', 'th', 'td']);
39
+ export const INLINE_TYPES = new Set(['text', 'a', 'break']);
40
+
41
+ /** Normalize any accepted value to a root node (plain text becomes paragraphs and line breaks). */
42
+ export function toRichTextRoot(value: RichTextValue): RichTextRoot {
43
+ if (value == null) return { type: 'root', children: [] };
44
+ if (typeof value === 'string') {
45
+ const paragraphs = value
46
+ .replace(/\r\n?/g, '\n')
47
+ .split(/\n\s*\n/)
48
+ .map((p) => p.trim())
49
+ .filter(Boolean);
50
+ return {
51
+ type: 'root',
52
+ children: paragraphs.map((p) => ({
53
+ type: 'p',
54
+ children: p.split('\n').flatMap((line, i) => (i ? [{ type: 'break' }, { type: 'text', text: line }] : [{ type: 'text', text: line }])),
55
+ })),
56
+ };
57
+ }
58
+ if (Array.isArray(value)) return { type: 'root', children: value };
59
+ if (value.type === 'root' && Array.isArray(value.children)) return value as RichTextRoot;
60
+ return { type: 'root', children: [value] };
61
+ }
62
+
63
+ /** True when the value would render no visible text or media. */
64
+ export function isRichTextEmpty(value: RichTextValue): boolean {
65
+ const root = toRichTextRoot(value);
66
+ const visible = (n: RichTextNode): boolean => {
67
+ if (!n || typeof n !== 'object') return false;
68
+ if (n.type === 'text') return Boolean(n.text?.trim());
69
+ if (n.type === 'img') return Boolean(safeMediaUrl(n.url));
70
+ if (n.type === 'code_block') return Boolean(n.value?.trim());
71
+ if (n.type === 'hr') return false;
72
+ if (!BLOCK_TYPES.has(n.type) && !INLINE_TYPES.has(n.type)) return false;
73
+ return (n.children ?? []).some(visible);
74
+ };
75
+ return !root.children.some(visible);
76
+ }
77
+
78
+ /**
79
+ * Plain text, for structured data (FAQ answers), meta descriptions and accessible names.
80
+ * Paragraph-level nodes are separated by a blank line and list items by a newline.
81
+ */
82
+ export function richTextPlain(value: RichTextValue): string {
83
+ const root = toRichTextRoot(value);
84
+ const BLOCKS = new Set(['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'blockquote', 'code_block', 'table', 'ul', 'ol']);
85
+ const walk = (n: RichTextNode): string => {
86
+ if (!n || typeof n !== 'object') return '';
87
+ if (n.type === 'text') return n.text ?? '';
88
+ if (n.type === 'break') return '\n';
89
+ if (n.type === 'code_block') return n.value ?? '';
90
+ if (n.type === 'img') return '';
91
+ if (!BLOCK_TYPES.has(n.type) && !INLINE_TYPES.has(n.type) && n.type !== 'root') return '';
92
+ const kids = n.children ?? [];
93
+ if (n.type === 'ul' || n.type === 'ol') return kids.map(walk).filter((s) => s.trim()).join('\n');
94
+ if (n.type === 'tr') return kids.map(walk).join('\t');
95
+ if (n.type === 'table' || n.type === 'thead' || n.type === 'tbody') return kids.map(walk).join('\n');
96
+ if (n.type === 'root') {
97
+ return kids
98
+ .map((k) => walk(k).trim())
99
+ .filter(Boolean)
100
+ .join('\n\n');
101
+ }
102
+ const inner = kids.map(walk).join('');
103
+ return BLOCKS.has(n.type) ? inner.trim() : inner;
104
+ };
105
+ return walk(root).replace(/[ \t]+\n/g, '\n').trim();
106
+ }
107
+
108
+ /** Smallest heading level used in the content (h1 → 1), or undefined when there are none. */
109
+ export function topHeadingLevel(value: RichTextValue): number | undefined {
110
+ let min: number | undefined;
111
+ const walk = (n: RichTextNode) => {
112
+ const m = /^h([1-6])$/.exec(n?.type ?? '');
113
+ if (m) min = Math.min(min ?? 6, Number(m[1]));
114
+ (n?.children ?? []).forEach(walk);
115
+ };
116
+ toRichTextRoot(value).children.forEach(walk);
117
+ return min;
118
+ }
119
+
120
+ /**
121
+ * The level a content heading renders at, so the content's top heading lands on `topLevel`
122
+ * (the editor's h1/h2 never competes with the page title) and relative levels are kept.
123
+ */
124
+ export function shiftedHeading(level: number, contentTop: number | undefined, topLevel: number): 2 | 3 | 4 | 5 | 6 {
125
+ const shift = topLevel - (contentTop ?? level);
126
+ return Math.min(6, Math.max(2, Math.max(topLevel, level + shift))) as 2 | 3 | 4 | 5 | 6;
127
+ }
128
+
129
+ /** Link targets: http(s), mailto, tel, sms, relative paths and fragments. */
130
+ export function safeLinkUrl(url: unknown): string | undefined {
131
+ return typeof url === 'string' ? safeHref(url) : undefined;
132
+ }
133
+
134
+ /** Image sources: http(s) or site paths only (no data:, blob:, javascript:). */
135
+ export function safeMediaUrl(url: unknown): string | undefined {
136
+ if (typeof url !== 'string') return undefined;
137
+ const v = url.trim();
138
+ if (!v) return undefined;
139
+ if (v.startsWith('//')) return undefined; // protocol-relative: another host
140
+ if (/^https?:\/\//i.test(v) || v.startsWith('/') || v.startsWith('./') || v.startsWith('../')) return v;
141
+ if (/^[a-z][a-z0-9+.-]*:/i.test(v)) return undefined;
142
+ return v;
143
+ }
@@ -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,79 @@
1
+ /**
2
+ * Registry: template name → component + CMS mapper (checklist §5). BlockRenderer uses it;
3
+ * sites extend it with their own blocks (an .astro component or a Lit tag wrapper):
4
+ *
5
+ * import { blockRegistry } from '@sinnstack/ui/blocks/registry';
6
+ * const registry = { ...blockRegistry, pricing: { component: Pricing, toProps: (d) => d } };
7
+ */
8
+ import Hero from './Hero.astro';
9
+ import CTABanner from './CTABanner.astro';
10
+ import FeatureGrid from './FeatureGrid.astro';
11
+ import CardGrid from './CardGrid.astro';
12
+ import LogoCloud from './LogoCloud.astro';
13
+ import HeroCarousel from './HeroCarousel.astro';
14
+ import PageHeader from './PageHeader.astro';
15
+ import ContactCard from './ContactCard.astro';
16
+ import Steps from './Steps.astro';
17
+ import MediaText from './MediaText.astro';
18
+ import CTAPair from './CTAPair.astro';
19
+ import StatsBand from './StatsBand.astro';
20
+ import HighlightCards from './HighlightCards.astro';
21
+ import ContactForm from './ContactForm.astro';
22
+ import ProseSection from './ProseSection.astro';
23
+ import FAQ from './FAQ.astro';
24
+ import Testimonials from './Testimonials.astro';
25
+ import Reviews from './Reviews.astro';
26
+ import LocationHours from './LocationHours.astro';
27
+ import { heroToProps } from './cms/hero';
28
+ import { ctaBannerToProps } from './cms/cta-banner';
29
+ import { featureGridToProps } from './cms/feature-grid';
30
+ import { cardGridToProps } from './cms/card-grid';
31
+ import { logoCloudToProps } from './cms/logo-cloud';
32
+ import { heroCarouselToProps } from './cms/hero-carousel';
33
+ import { pageHeaderToProps } from './cms/page-header';
34
+ import { contactCardToProps } from './cms/contact-card';
35
+ import { stepsToProps } from './cms/steps';
36
+ import { mediaTextToProps } from './cms/media-text';
37
+ import { ctaPairToProps } from './cms/cta-pair';
38
+ import { statsBandToProps } from './cms/stats-band';
39
+ import { highlightCardsToProps } from './cms/highlight-cards';
40
+ import { contactFormToProps } from './cms/contact-form';
41
+ import { proseSectionToProps } from './cms/prose-section';
42
+ import { faqToProps } from './cms/faq';
43
+ import { testimonialsToProps } from './cms/testimonials';
44
+ import { reviewsToProps } from './cms/reviews';
45
+ import { locationHoursToProps } from './cms/location-hours';
46
+ import type { MapContext } from './cms/types';
47
+
48
+ export interface RegistryEntry {
49
+ /** An Astro component (a Lit block is wrapped in a small .astro file that renders its tag). */
50
+ component: (props: any) => unknown;
51
+ toProps: (data: any, ctx: MapContext) => Record<string, unknown>;
52
+ /** Label for editor-facing messages. */
53
+ label?: string;
54
+ /** The block can hold the page's h1: BlockRenderer gives level 1 to the first such block. */
55
+ h1?: boolean;
56
+ }
57
+ export type BlockRegistry = Record<string, RegistryEntry>;
58
+
59
+ export const blockRegistry: BlockRegistry = {
60
+ hero: { component: Hero, toProps: heroToProps, label: 'Hero', h1: true },
61
+ ctaBanner: { component: CTABanner, toProps: ctaBannerToProps, label: 'Call to action' },
62
+ featureGrid: { component: FeatureGrid, toProps: featureGridToProps, label: 'Feature grid' },
63
+ cardGrid: { component: CardGrid, toProps: cardGridToProps, label: 'Card grid' },
64
+ logoCloud: { component: LogoCloud, toProps: logoCloudToProps, label: 'Logo cloud' },
65
+ heroCarousel: { component: HeroCarousel, toProps: heroCarouselToProps, label: 'Hero carousel' },
66
+ pageHeader: { component: PageHeader, toProps: pageHeaderToProps, label: 'Page header', h1: true },
67
+ contactCard: { component: ContactCard, toProps: contactCardToProps, label: 'Contact card' },
68
+ steps: { component: Steps, toProps: stepsToProps, label: 'Steps' },
69
+ mediaText: { component: MediaText, toProps: mediaTextToProps, label: 'Image and text' },
70
+ ctaPair: { component: CTAPair, toProps: ctaPairToProps, label: 'Two calls to action' },
71
+ statsBand: { component: StatsBand, toProps: statsBandToProps, label: 'Stats band' },
72
+ highlightCards: { component: HighlightCards, toProps: highlightCardsToProps, label: 'Highlight cards' },
73
+ contactForm: { component: ContactForm, toProps: contactFormToProps, label: 'Contact form' },
74
+ proseSection: { component: ProseSection, toProps: proseSectionToProps, label: 'Text' },
75
+ faq: { component: FAQ, toProps: faqToProps, label: 'FAQ' },
76
+ testimonials: { component: Testimonials, toProps: testimonialsToProps, label: 'Testimonials' },
77
+ reviews: { component: Reviews, toProps: reviewsToProps, label: 'Reviews' },
78
+ locationHours: { component: LocationHours, toProps: locationHoursToProps, label: 'Location and hours' },
79
+ };
@@ -0,0 +1,218 @@
1
+ /**
2
+ * HeroCarousel enhancement. The server renders a scroll-snap strip that works on its own; this
3
+ * adds controls, keeps them in sync with swipes/scrolls, makes inactive slides inert and runs the
4
+ * optional autoplay (WAI-ARIA APG carousel pattern).
5
+ *
6
+ * Moving between slides scrolls the strip (`scrollTo`), never the page. Reduced motion: instant
7
+ * jumps and no autoplay. Event: `sinn-slide-change` (bubbles, composed) { index, previousIndex }.
8
+ * SSR-safe: nothing runs at import time outside the browser.
9
+ */
10
+ import { prefersReducedMotion, onReducedMotionChange } from '../../primitives/lib/motion';
11
+
12
+ export interface SinnSlideChangeDetail {
13
+ index: number;
14
+ previousIndex: number;
15
+ }
16
+
17
+ const FLAG = '__sinnCarousel';
18
+ const w = (typeof window !== 'undefined' ? window : {}) as unknown as Record<string, boolean>;
19
+
20
+ class Carousel {
21
+ root: HTMLElement;
22
+ track: HTMLElement;
23
+ slides: HTMLElement[];
24
+ dots: HTMLButtonElement[];
25
+ rotate: HTMLButtonElement | null;
26
+ index = 0;
27
+ delay: number;
28
+ timer: number | undefined;
29
+ /** The user pressed pause (or reduced motion is on): never resume on its own. */
30
+ stopped: boolean;
31
+ hovering = false;
32
+ focused = false;
33
+ visible = true;
34
+ settleTimer: number | undefined;
35
+ cleanup: Array<() => void> = [];
36
+
37
+ constructor(root: HTMLElement) {
38
+ this.root = root;
39
+ this.track = root.querySelector<HTMLElement>(':scope > .sinn-carousel__track')!;
40
+ this.slides = [...this.track.querySelectorAll<HTMLElement>(':scope > .sinn-carousel__slide')];
41
+ const controls = root.querySelector<HTMLElement>(':scope > [data-carousel-controls]');
42
+ this.dots = [...(controls?.querySelectorAll<HTMLButtonElement>('[data-carousel-dot]') ?? [])];
43
+ this.rotate = controls?.querySelector<HTMLButtonElement>('[data-carousel-rotate]') ?? null;
44
+ this.delay = Math.max(5, Number(root.dataset.autoplay) || 0) * 1000;
45
+ this.stopped = !root.dataset.autoplay || prefersReducedMotion();
46
+
47
+ controls?.removeAttribute('hidden');
48
+ controls?.querySelector('[data-carousel-prev]')?.addEventListener('click', () => this.go(this.index - 1, true));
49
+ controls?.querySelector('[data-carousel-next]')?.addEventListener('click', () => this.go(this.index + 1, true));
50
+ this.dots.forEach((dot, i) => dot.addEventListener('click', () => this.go(i, true)));
51
+ this.rotate?.addEventListener('click', () => (this.stopped ? this.play() : this.pause(true)));
52
+
53
+ // Arrow keys on the focused strip move one slide (instead of scrolling by a few pixels).
54
+ this.track.addEventListener('keydown', (e) => {
55
+ if (e.target !== this.track || e.altKey || e.ctrlKey || e.metaKey) return;
56
+ const rtl = this.rtl();
57
+ const next = rtl ? 'ArrowLeft' : 'ArrowRight';
58
+ const prev = rtl ? 'ArrowRight' : 'ArrowLeft';
59
+ let to: number | null = null;
60
+ if (e.key === next) to = this.index + 1;
61
+ else if (e.key === prev) to = this.index - 1;
62
+ else if (e.key === 'Home') to = 0;
63
+ else if (e.key === 'End') to = this.slides.length - 1;
64
+ if (to === null) return;
65
+ e.preventDefault();
66
+ this.go(to, true);
67
+ });
68
+
69
+ // Swipes and native scrolling: sync the state once the strip settles.
70
+ const onScroll = () => {
71
+ window.clearTimeout(this.settleTimer);
72
+ this.settleTimer = window.setTimeout(() => this.syncFromScroll(), 120);
73
+ };
74
+ this.track.addEventListener('scroll', onScroll, { passive: true });
75
+ this.track.addEventListener('scrollend', () => this.syncFromScroll());
76
+
77
+ root.addEventListener('pointerenter', () => { this.hovering = true; this.schedule(); });
78
+ root.addEventListener('pointerleave', () => { this.hovering = false; this.schedule(); });
79
+ root.addEventListener('focusin', () => { this.focused = true; this.schedule(); });
80
+ root.addEventListener('focusout', (e) => {
81
+ if (!root.contains(e.relatedTarget as Node | null)) { this.focused = false; this.schedule(); }
82
+ });
83
+ const onVisibility = () => this.schedule();
84
+ document.addEventListener('visibilitychange', onVisibility);
85
+ this.cleanup.push(() => document.removeEventListener('visibilitychange', onVisibility));
86
+ if ('IntersectionObserver' in window) {
87
+ const io = new IntersectionObserver(([entry]) => { this.visible = Boolean(entry?.isIntersecting); this.schedule(); }, { threshold: 0.35 });
88
+ io.observe(root);
89
+ this.cleanup.push(() => io.disconnect());
90
+ }
91
+ this.cleanup.push(onReducedMotionChange((reduced) => { if (reduced) this.pause(false); }));
92
+
93
+ // Keep the current slide aligned when the strip changes width (rotation, resize).
94
+ if ('ResizeObserver' in window) {
95
+ const ro = new ResizeObserver(() => this.scrollToIndex(this.index, false));
96
+ ro.observe(this.track);
97
+ this.cleanup.push(() => ro.disconnect());
98
+ }
99
+
100
+ this.index = this.indexFromScroll();
101
+ this.render(false);
102
+ this.updateRotate();
103
+ this.root.dataset.enhanced = '';
104
+ this.schedule();
105
+ }
106
+
107
+ rtl() {
108
+ return getComputedStyle(this.track).direction === 'rtl';
109
+ }
110
+
111
+ indexFromScroll(): number {
112
+ const width = this.track.clientWidth || 1;
113
+ return Math.min(this.slides.length - 1, Math.max(0, Math.round(Math.abs(this.track.scrollLeft) / width)));
114
+ }
115
+
116
+ scrollToIndex(i: number, smooth: boolean) {
117
+ const left = (this.rtl() ? -1 : 1) * i * this.track.clientWidth;
118
+ this.track.scrollTo({ left, behavior: smooth && !prefersReducedMotion() ? 'smooth' : 'auto' });
119
+ }
120
+
121
+ /** `user`: a person moved the carousel (announce politely, stop autoplay for good). */
122
+ go(i: number, user: boolean) {
123
+ const n = this.slides.length;
124
+ const to = ((i % n) + n) % n;
125
+ if (user) this.pause(true);
126
+ this.scrollToIndex(to, true);
127
+ this.setIndex(to);
128
+ }
129
+
130
+ syncFromScroll() {
131
+ const i = this.indexFromScroll();
132
+ if (i !== this.index) this.setIndex(i);
133
+ }
134
+
135
+ setIndex(i: number) {
136
+ if (i === this.index) return this.render(false);
137
+ const previousIndex = this.index;
138
+ this.index = i;
139
+ this.render(true);
140
+ this.root.dispatchEvent(
141
+ new CustomEvent<SinnSlideChangeDetail>('sinn-slide-change', { bubbles: true, composed: true, detail: { index: i, previousIndex } }),
142
+ );
143
+ this.schedule();
144
+ }
145
+
146
+ render(_announce: boolean) {
147
+ this.slides.forEach((slide, k) => {
148
+ const on = k === this.index;
149
+ slide.toggleAttribute('data-current', on);
150
+ slide.inert = !on;
151
+ });
152
+ this.dots.forEach((dot, k) => (k === this.index ? dot.setAttribute('aria-current', 'true') : dot.removeAttribute('aria-current')));
153
+ // Silent while rotating on its own; polite when a person is driving it.
154
+ this.track.setAttribute('aria-live', this.running() ? 'off' : 'polite');
155
+ }
156
+
157
+ running() {
158
+ return !this.stopped;
159
+ }
160
+
161
+ play() {
162
+ this.stopped = false;
163
+ this.updateRotate();
164
+ this.render(false);
165
+ this.schedule();
166
+ }
167
+
168
+ pause(byUser: boolean) {
169
+ if (byUser || !this.stopped) this.stopped = true;
170
+ this.updateRotate();
171
+ this.render(false);
172
+ this.schedule();
173
+ }
174
+
175
+ updateRotate() {
176
+ if (!this.rotate) return;
177
+ const playing = !this.stopped;
178
+ this.rotate.dataset.state = playing ? 'playing' : 'paused';
179
+ const text = this.rotate.querySelector('[data-carousel-rotate-text]');
180
+ if (text) text.textContent = (playing ? this.rotate.dataset.labelPause : this.rotate.dataset.labelPlay) ?? '';
181
+ }
182
+
183
+ /** (Re)start or clear the autoplay timer for the current conditions. */
184
+ schedule() {
185
+ window.clearTimeout(this.timer);
186
+ this.timer = undefined;
187
+ if (this.stopped || this.hovering || this.focused || !this.visible || document.hidden || this.slides.length < 2) return;
188
+ this.timer = window.setTimeout(() => this.go(this.index + 1, false), this.delay);
189
+ }
190
+ }
191
+
192
+ const instances = new Set<Carousel>();
193
+
194
+ const init = () => {
195
+ for (const root of document.querySelectorAll<HTMLElement>('[data-sinn-carousel]:not([data-enhanced])')) {
196
+ if (!root.querySelector(':scope > .sinn-carousel__track')) continue;
197
+ instances.add(new Carousel(root));
198
+ }
199
+ };
200
+
201
+ /** Client-side navigation (Astro view transitions): drop timers and observers of the old page. */
202
+ const teardown = () => {
203
+ for (const c of instances) {
204
+ window.clearTimeout(c.timer);
205
+ window.clearTimeout(c.settleTimer);
206
+ c.cleanup.forEach((fn) => fn());
207
+ }
208
+ instances.clear();
209
+ };
210
+
211
+ if (typeof window !== 'undefined' && !w[FLAG]) {
212
+ w[FLAG] = true;
213
+ document.addEventListener('astro:page-load', init);
214
+ document.addEventListener('astro:before-swap', teardown);
215
+ }
216
+ if (typeof document !== 'undefined') init();
217
+
218
+ export {};
@@ -0,0 +1,105 @@
1
+ /**
2
+ * ConsentEmbed and ConsentScript behavior.
3
+ *
4
+ * Embeds: the iframe is kept in an inert `<template>` (the browser never requests it) until its
5
+ * category is allowed, or the visitor loads that one embed ("Load map"). "Always allow" saves
6
+ * consent for the category, which loads every embed of it on the page. When the category is
7
+ * revoked, loaded embeds go back to their notice.
8
+ *
9
+ * Scripts: `<template data-sinn-consent-script>` holds a URL; once its category is allowed a
10
+ * real `<script src>` is added to <head> (your CSP's script-src must list its origin).
11
+ */
12
+ import { hasConsent, onConsentChange, setConsent } from './consent-store';
13
+
14
+ const FLAG = '__sinnConsentEmbed';
15
+ const w = (typeof window !== 'undefined' ? window : {}) as unknown as Record<string, boolean>;
16
+ const notices = new WeakMap<HTMLElement, HTMLElement>();
17
+
18
+ function load(embed: HTMLElement, focus = false) {
19
+ if (embed.dataset.state === 'loaded') return;
20
+ const tpl = embed.querySelector<HTMLTemplateElement>('template[data-embed-template]');
21
+ const frame = embed.querySelector<HTMLElement>('[data-embed-frame]');
22
+ const notice = embed.querySelector<HTMLElement>('[data-embed-notice]');
23
+ if (!tpl || !frame) return;
24
+ const node = tpl.content.firstElementChild?.cloneNode(true) as HTMLElement | undefined;
25
+ if (!node) return;
26
+ if (notice) {
27
+ notices.set(embed, notice);
28
+ notice.remove();
29
+ }
30
+ frame.append(node);
31
+ embed.dataset.state = 'loaded';
32
+ if (focus) node.focus();
33
+ }
34
+
35
+ function unload(embed: HTMLElement) {
36
+ if (embed.dataset.state !== 'loaded' || embed.dataset.session === '') return;
37
+ const frame = embed.querySelector<HTMLElement>('[data-embed-frame]');
38
+ const notice = notices.get(embed);
39
+ frame?.querySelector('iframe')?.remove();
40
+ if (frame && notice) frame.append(notice);
41
+ embed.dataset.state = 'blocked';
42
+ }
43
+
44
+ function runScript(tpl: HTMLTemplateElement) {
45
+ if (tpl.hasAttribute('data-loaded')) return;
46
+ const src = tpl.dataset.src;
47
+ if (!src) return;
48
+ const s = document.createElement('script');
49
+ s.src = src;
50
+ if (tpl.dataset.module !== undefined) s.type = 'module';
51
+ if (tpl.dataset.async !== undefined) s.async = true;
52
+ if (tpl.dataset.defer !== undefined) s.defer = true;
53
+ if (tpl.dataset.id) s.id = tpl.dataset.id;
54
+ if (tpl.dataset.crossorigin) s.crossOrigin = tpl.dataset.crossorigin;
55
+ if (tpl.dataset.integrity) s.integrity = tpl.dataset.integrity;
56
+ if (tpl.dataset.referrerpolicy) s.referrerPolicy = tpl.dataset.referrerpolicy;
57
+ tpl.setAttribute('data-loaded', '');
58
+ document.head.append(s);
59
+ }
60
+
61
+ function apply() {
62
+ for (const embed of document.querySelectorAll<HTMLElement>('[data-sinn-embed]')) {
63
+ if (hasConsent(embed.dataset.category ?? 'media')) load(embed);
64
+ else unload(embed);
65
+ }
66
+ for (const tpl of document.querySelectorAll<HTMLTemplateElement>('template[data-sinn-consent-script]')) {
67
+ if (hasConsent(tpl.dataset.category ?? 'analytics')) runScript(tpl);
68
+ }
69
+ }
70
+
71
+ function init() {
72
+ for (const embed of document.querySelectorAll<HTMLElement>('[data-sinn-embed]:not([data-enhanced])')) {
73
+ embed.dataset.enhanced = '';
74
+ embed.querySelector<HTMLElement>('[data-embed-actions]')?.removeAttribute('hidden');
75
+ embed.addEventListener('click', (e) => {
76
+ const btn = (e.target as Element).closest<HTMLElement>('[data-embed-load], [data-embed-always]');
77
+ if (!btn || !embed.contains(btn)) return;
78
+ if (btn.hasAttribute('data-embed-always')) {
79
+ embed.dataset.focusNext = '';
80
+ setConsent({ [embed.dataset.category ?? 'media']: true });
81
+ return;
82
+ }
83
+ // This embed only, this page view only: nothing is stored.
84
+ embed.dataset.session = '';
85
+ load(embed, true);
86
+ });
87
+ }
88
+ apply();
89
+ }
90
+
91
+ if (typeof window !== 'undefined' && !w[FLAG]) {
92
+ w[FLAG] = true;
93
+ onConsentChange(() => {
94
+ apply();
95
+ const pending = document.querySelector<HTMLElement>('[data-sinn-embed][data-focus-next]');
96
+ if (pending) {
97
+ delete pending.dataset.focusNext;
98
+ pending.querySelector<HTMLElement>('iframe')?.focus();
99
+ }
100
+ });
101
+ document.addEventListener('astro:page-load', init);
102
+ }
103
+ if (typeof window !== 'undefined') init();
104
+
105
+ export {};