@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,112 @@
1
+ /**
2
+ * ConsentManager behavior: shows the banner until the visitor decides, saves Accept all /
3
+ * Reject all / the dialog's choices, keeps the dialog's switches in sync, and opens the dialog
4
+ * from any `[data-consent-open]` element (a "Cookie settings" link in the footer).
5
+ *
6
+ * Revoking a category that already ran scripts (analytics, marketing) reloads the page, because
7
+ * a script that has run can't be unloaded; embeds are unloaded in place.
8
+ */
9
+ import { allChoices, revoked } from '../lib/consent';
10
+ import { getConsentRecord, onConsentChange, openConsentSettings, setConsent } from './consent-store';
11
+
12
+ const FLAG = '__sinnConsentManager';
13
+ const w = (typeof window !== 'undefined' ? window : {}) as unknown as Record<string, boolean>;
14
+
15
+ function categoriesOf(root: HTMLElement): string[] {
16
+ return (root.dataset.categories ?? '').split(' ').filter(Boolean);
17
+ }
18
+
19
+ function syncSwitches(dialog: HTMLDialogElement) {
20
+ const rec = getConsentRecord();
21
+ for (const input of dialog.querySelectorAll<HTMLInputElement>('input[data-consent-category]')) {
22
+ const cat = input.dataset.consentCategory!;
23
+ input.checked = cat === 'necessary' ? true : rec?.c[cat] === true;
24
+ }
25
+ }
26
+
27
+ /** After a choice in the banner, focus goes to the page's main content, not to <body>. */
28
+ function focusAfterBanner(banner: HTMLElement) {
29
+ if (!banner.contains(document.activeElement)) return;
30
+ const target = document.querySelector<HTMLElement>('[data-skip-target], main, #main');
31
+ if (!target) return;
32
+ if (!target.hasAttribute('tabindex')) target.setAttribute('tabindex', '-1');
33
+ target.focus({ preventScroll: true });
34
+ }
35
+
36
+ function decide(root: HTMLElement, choices: Record<string, boolean>) {
37
+ const before = getConsentRecord();
38
+ setConsent(choices);
39
+ const banner = root.querySelector<HTMLElement>('[data-consent-banner]');
40
+ if (banner && !banner.hidden) {
41
+ focusAfterBanner(banner);
42
+ banner.hidden = true;
43
+ }
44
+ const dialog = root.querySelector<HTMLDialogElement>('dialog[data-sinn-consent-dialog]');
45
+ if (dialog?.open) dialog.close();
46
+ // Scripts that already ran for a revoked category can only be stopped by a reload.
47
+ const gone = revoked(before, getConsentRecord());
48
+ if (gone.some((c) => document.querySelector(`[data-sinn-consent-script][data-category="${c}"][data-loaded]`))) window.location.reload();
49
+ }
50
+
51
+ function init() {
52
+ const root = document.querySelector<HTMLElement>('[data-sinn-consent]:not([data-enhanced])');
53
+ if (!root) return;
54
+ root.dataset.enhanced = '';
55
+ const categories = categoriesOf(root);
56
+ const banner = root.querySelector<HTMLElement>('[data-consent-banner]');
57
+ const dialog = root.querySelector<HTMLDialogElement>('dialog[data-sinn-consent-dialog]');
58
+
59
+ if (banner) banner.hidden = Boolean(getConsentRecord());
60
+
61
+ root.addEventListener('click', (e) => {
62
+ const t = (e.target as Element).closest<HTMLElement>('[data-consent-accept], [data-consent-reject]');
63
+ if (!t || !root.contains(t)) return;
64
+ e.preventDefault();
65
+ decide(root, allChoices(categories, t.hasAttribute('data-consent-accept')));
66
+ });
67
+
68
+ if (dialog) {
69
+ syncSwitches(dialog);
70
+ dialog.addEventListener('sinn-consent-sync', () => syncSwitches(dialog));
71
+ // Opened by its invoker button (commandfor) or the fallback script: show the saved state.
72
+ dialog.addEventListener('beforetoggle', (e) => {
73
+ if ((e as ToggleEvent).newState === 'open') syncSwitches(dialog);
74
+ });
75
+ const form = dialog.querySelector<HTMLFormElement>('form[data-consent-form]');
76
+ form?.addEventListener('submit', (e) => {
77
+ e.preventDefault();
78
+ const choices: Record<string, boolean> = {};
79
+ for (const input of form.querySelectorAll<HTMLInputElement>('input[data-consent-category]')) {
80
+ if (input.dataset.consentCategory !== 'necessary') choices[input.dataset.consentCategory!] = input.checked;
81
+ }
82
+ decide(root, choices);
83
+ });
84
+ }
85
+ }
86
+
87
+ if (typeof window !== 'undefined' && !w[FLAG]) {
88
+ w[FLAG] = true;
89
+ // "Cookie settings" links anywhere on the page.
90
+ document.addEventListener('click', (e) => {
91
+ const opener = (e.target as Element | null)?.closest?.('[data-consent-open]');
92
+ if (!opener) return;
93
+ if (openConsentSettings()) e.preventDefault();
94
+ });
95
+ // Another tab changed the choice: follow it here (banner and switches).
96
+ window.addEventListener('storage', (e) => {
97
+ if (e.key !== 'sinn-consent') return;
98
+ const root = document.querySelector<HTMLElement>('[data-sinn-consent]');
99
+ const banner = root?.querySelector<HTMLElement>('[data-consent-banner]');
100
+ if (banner) banner.hidden = Boolean(getConsentRecord());
101
+ const rec = getConsentRecord();
102
+ document.dispatchEvent(new CustomEvent('sinn-consent-change', { detail: { choices: { ...(rec?.c ?? {}) }, decided: Boolean(rec) } }));
103
+ });
104
+ onConsentChange(() => {
105
+ const dialog = document.querySelector<HTMLDialogElement>('dialog[data-sinn-consent-dialog]');
106
+ if (dialog) syncSwitches(dialog);
107
+ });
108
+ document.addEventListener('astro:page-load', init);
109
+ }
110
+ if (typeof window !== 'undefined') init();
111
+
112
+ export {};
@@ -0,0 +1,86 @@
1
+ /**
2
+ * The browser side of consent: one store per page, shared by ConsentManager, ConsentEmbed,
3
+ * ConsentScript and your own code (`@sinnstack/ui/blocks/consent`).
4
+ *
5
+ * - Reads the policy version and maximum age from the page's ConsentManager
6
+ * (`data-version`, `data-max-age`); without one, any stored decision counts.
7
+ * - localStorage when it works; otherwise the choice lasts until the page is left.
8
+ * - Every change dispatches `sinn-consent-change` on `document`
9
+ * (detail: `{ choices, decided, previous }`).
10
+ * SSR-safe: nothing touches the DOM at import time outside the browser.
11
+ */
12
+ import { allows, CONSENT_EVENT, CONSENT_KEY, parseConsent, serializeConsent, type ConsentChoices, type ConsentRecord } from '../lib/consent';
13
+
14
+ export interface ConsentChangeDetail {
15
+ choices: ConsentChoices;
16
+ /** The visitor has made a choice (not just loaded the page). */
17
+ decided: boolean;
18
+ previous?: ConsentChoices;
19
+ }
20
+
21
+ let memory: string | null = null;
22
+
23
+ function config(): { version?: string; maxAgeDays?: number } {
24
+ const el = typeof document !== 'undefined' ? document.querySelector<HTMLElement>('[data-sinn-consent]') : null;
25
+ if (!el) return {};
26
+ const maxAge = Number(el.dataset.maxAge);
27
+ return { version: el.dataset.version || '1', maxAgeDays: Number.isFinite(maxAge) && maxAge > 0 ? maxAge : 365 };
28
+ }
29
+
30
+ function readRaw(): string | null {
31
+ try {
32
+ return window.localStorage.getItem(CONSENT_KEY) ?? memory;
33
+ } catch {
34
+ return memory;
35
+ }
36
+ }
37
+
38
+ function writeRaw(value: string): void {
39
+ memory = value;
40
+ try {
41
+ window.localStorage.setItem(CONSENT_KEY, value);
42
+ } catch {
43
+ /* storage blocked: keep the in-memory copy */
44
+ }
45
+ }
46
+
47
+ /** The current decision, or undefined when the visitor hasn't decided (or it expired). */
48
+ export function getConsentRecord(): ConsentRecord | undefined {
49
+ if (typeof window === 'undefined') return undefined;
50
+ return parseConsent(readRaw(), config());
51
+ }
52
+
53
+ /** Whether a category is allowed now. `necessary` is always true. */
54
+ export function hasConsent(category: string): boolean {
55
+ return allows(getConsentRecord(), category);
56
+ }
57
+
58
+ /** Save the visitor's choices (merged over the current ones) and notify listeners. */
59
+ export function setConsent(choices: ConsentChoices): void {
60
+ if (typeof window === 'undefined') return;
61
+ const before = getConsentRecord();
62
+ const merged = { ...(before?.c ?? {}), ...choices };
63
+ writeRaw(serializeConsent(merged, config().version ?? before?.v ?? '1'));
64
+ const after = getConsentRecord();
65
+ document.dispatchEvent(
66
+ new CustomEvent<ConsentChangeDetail>(CONSENT_EVENT, { detail: { choices: { ...(after?.c ?? merged) }, decided: true, previous: before?.c }, bubbles: true, composed: true }),
67
+ );
68
+ }
69
+
70
+ /** Run `fn` whenever choices change. Returns an unsubscribe function. */
71
+ export function onConsentChange(fn: (detail: ConsentChangeDetail) => void): () => void {
72
+ if (typeof document === 'undefined') return () => {};
73
+ const handler = (e: Event) => fn((e as CustomEvent<ConsentChangeDetail>).detail);
74
+ document.addEventListener(CONSENT_EVENT, handler);
75
+ return () => document.removeEventListener(CONSENT_EVENT, handler);
76
+ }
77
+
78
+ /** Open the privacy-choices dialog (ConsentManager), e.g. from a "Cookie settings" link. */
79
+ export function openConsentSettings(): boolean {
80
+ if (typeof document === 'undefined') return false;
81
+ const dialog = document.querySelector<HTMLDialogElement>('dialog[data-sinn-consent-dialog]');
82
+ if (!dialog) return false;
83
+ dialog.dispatchEvent(new CustomEvent('sinn-consent-sync'));
84
+ if (!dialog.open) dialog.showModal();
85
+ return true;
86
+ }
@@ -0,0 +1,71 @@
1
+ /**
2
+ * ErrorPage enhancements (the page is complete without them):
3
+ * - shows the address that failed (as text, never HTML),
4
+ * - "Did you mean …?" from the site's page list (data-pages JSON),
5
+ * - prefills site search with words from the broken address,
6
+ * - reveals "Go back" only when the visitor came from this site,
7
+ * - dispatches `sinn:error-page` { status, path, referrer } on document for analytics.
8
+ */
9
+ import { searchTermsFromPath, suggestPage, type SuggestCandidate } from '../lib/error-pages';
10
+
11
+ function enhance(root: HTMLElement): void {
12
+ if (root.dataset.enhanced) return;
13
+ root.dataset.enhanced = '';
14
+ const status = Number(root.dataset.sinnErrorPage);
15
+ const path = location.pathname + location.search;
16
+
17
+ const pathOut = root.querySelector<HTMLElement>('[data-sinn-error-path]');
18
+ if (pathOut && !pathOut.textContent?.trim()) {
19
+ let shown = location.pathname;
20
+ try {
21
+ shown = decodeURI(shown);
22
+ } catch {
23
+ /* keep encoded */
24
+ }
25
+ pathOut.textContent = shown;
26
+ pathOut.closest<HTMLElement>('[hidden]')?.removeAttribute('hidden');
27
+ }
28
+
29
+ const suggest = root.querySelector<HTMLElement>('[data-sinn-error-suggest]');
30
+ if (suggest) {
31
+ let pages: SuggestCandidate[] = [];
32
+ try {
33
+ pages = JSON.parse(suggest.dataset.pages ?? '[]');
34
+ } catch {
35
+ /* ignore bad data */
36
+ }
37
+ const hit = suggestPage(location.pathname, pages);
38
+ const link = suggest.querySelector('a');
39
+ if (hit && link) {
40
+ link.href = hit.href;
41
+ link.textContent = hit.label;
42
+ suggest.hidden = false;
43
+ }
44
+ }
45
+
46
+ const search = root.querySelector<HTMLInputElement>('input[data-sinn-error-search]');
47
+ if (search && !search.value) search.value = searchTermsFromPath(location.pathname);
48
+
49
+ const back = root.querySelector<HTMLButtonElement>('[data-sinn-error-back]');
50
+ if (back) {
51
+ let sameSite = false;
52
+ try {
53
+ sameSite = Boolean(document.referrer) && new URL(document.referrer).origin === location.origin && document.referrer !== location.href;
54
+ } catch {
55
+ /* no referrer */
56
+ }
57
+ if (sameSite && history.length > 1) {
58
+ back.hidden = false;
59
+ back.addEventListener('click', () => history.back());
60
+ }
61
+ }
62
+
63
+ document.dispatchEvent(new CustomEvent('sinn:error-page', { detail: { status, path, referrer: document.referrer || null } }));
64
+ }
65
+
66
+ const run = () => document.querySelectorAll<HTMLElement>('[data-sinn-error-page]').forEach(enhance);
67
+ run();
68
+ // Client-side navigation (Astro ClientRouter) swaps the page without reloading.
69
+ document.addEventListener('astro:page-load', run);
70
+
71
+ export {};
@@ -0,0 +1,106 @@
1
+ /**
2
+ * LocationHours enhancement: "Open now · Closes 5:00 PM" in the business's own time zone, marks
3
+ * today's row, and hides holiday entries that have passed. Re-checks every minute while the
4
+ * page is visible. Without JavaScript the status line stays hidden (it can't be known at build
5
+ * time), and the full hours are always there.
6
+ */
7
+ import { formatTime, openStatus, weekHours, zonedNow, dayName } from '../lib/hours';
8
+ import type { DayCode, HoursRow, SpecialHours } from '../types';
9
+
10
+ const FLAG = '__sinnHours';
11
+ const w = (typeof window !== 'undefined' ? window : {}) as unknown as Record<string, boolean>;
12
+
13
+ interface Labels {
14
+ openNow: string;
15
+ closed: string;
16
+ openAllDay: string;
17
+ closes: string;
18
+ closesTomorrow: string;
19
+ opensToday: string;
20
+ opensTomorrow: string;
21
+ opensDay: string;
22
+ }
23
+
24
+ function parse<T>(value: string | undefined, fallback: T): T {
25
+ try {
26
+ return value ? (JSON.parse(value) as T) : fallback;
27
+ } catch {
28
+ return fallback;
29
+ }
30
+ }
31
+
32
+ function update(root: HTMLElement) {
33
+ const tz = root.dataset.tz;
34
+ const status = root.querySelector<HTMLElement>('[data-hours-status]');
35
+ if (!tz || !status) return;
36
+ const locale = root.dataset.locale || 'en-US';
37
+ const rows = parse<HoursRow[]>(root.dataset.hours, []);
38
+ const special = parse<SpecialHours[]>(root.dataset.special, []);
39
+ const L = parse<Labels>(status.dataset.labels, {} as Labels);
40
+ const week = weekHours(rows);
41
+ let now: ReturnType<typeof zonedNow>;
42
+ try {
43
+ now = zonedNow(new Date(), tz);
44
+ } catch {
45
+ return; // unknown time zone: leave the status hidden
46
+ }
47
+ const s = openStatus(week, new Date(), tz, special);
48
+ const fill = (t: string, v: Record<string, string>) => t.replace(/\{(\w+)\}/g, (m, k) => v[k] ?? m);
49
+ const state = status.querySelector<HTMLElement>('[data-hours-state]')!;
50
+ const detail = status.querySelector<HTMLElement>('[data-hours-detail]')!;
51
+ if (s.open) {
52
+ state.textContent = L.openNow;
53
+ detail.textContent = s.allDay ? L.openAllDay : fill(s.closesTomorrow ? L.closesTomorrow : L.closes, { time: formatTime(s.closes, locale) });
54
+ } else {
55
+ state.textContent = L.closed;
56
+ if (s.opens && s.opensDay) {
57
+ const time = formatTime(s.opens, locale);
58
+ detail.textContent =
59
+ s.opensIn === 0 ? fill(L.opensToday, { time }) : s.opensIn === 1 ? fill(L.opensTomorrow, { time }) : fill(L.opensDay, { time, day: dayName(s.opensDay as DayCode, locale, 'long') });
60
+ } else detail.textContent = '';
61
+ }
62
+ status.dataset.open = s.open ? 'true' : 'false';
63
+ status.hidden = false;
64
+
65
+ for (const row of root.querySelectorAll<HTMLElement>('[data-hours-days]')) {
66
+ const today = (row.dataset.hoursDays ?? '').split(' ').includes(now.day);
67
+ row.toggleAttribute('data-today', today);
68
+ row.querySelector<HTMLElement>('[data-hours-today]')?.toggleAttribute('hidden', !today);
69
+ }
70
+ for (const item of root.querySelectorAll<HTMLElement>('[data-hours-date]')) {
71
+ item.hidden = (item.dataset.hoursDate ?? '') < now.date;
72
+ }
73
+ const specialList = root.querySelector<HTMLElement>('[data-hours-special]');
74
+ if (specialList) specialList.hidden = !specialList.querySelector('[data-hours-date]:not([hidden])');
75
+ }
76
+
77
+ const roots = new Set<HTMLElement>();
78
+ let timer: number | undefined;
79
+
80
+ function tick() {
81
+ if (document.hidden) return;
82
+ for (const r of roots) if (r.isConnected) update(r);
83
+ }
84
+
85
+ function init() {
86
+ for (const root of document.querySelectorAll<HTMLElement>('[data-sinn-hours]:not([data-enhanced])')) {
87
+ root.dataset.enhanced = '';
88
+ roots.add(root);
89
+ update(root);
90
+ }
91
+ if (roots.size && timer === undefined) timer = window.setInterval(tick, 60_000);
92
+ }
93
+
94
+ if (typeof window !== 'undefined' && !w[FLAG]) {
95
+ w[FLAG] = true;
96
+ document.addEventListener('visibilitychange', tick);
97
+ document.addEventListener('astro:before-swap', () => {
98
+ roots.clear();
99
+ window.clearInterval(timer);
100
+ timer = undefined;
101
+ });
102
+ document.addEventListener('astro:page-load', init);
103
+ }
104
+ if (typeof window !== 'undefined') init();
105
+
106
+ export {};
@@ -0,0 +1,109 @@
1
+ /**
2
+ * MaintenancePage enhancements (the page is complete without them):
3
+ * - shows the return time in the visitor's own time zone, with "in about 2 hours", kept current,
4
+ * - checks whether the site is back (after the expected time, or right away when none is given)
5
+ * and reloads when it is; "Check now" does the same on demand and reports the result.
6
+ * Checks only run while the tab is visible and the browser is online, with backoff.
7
+ */
8
+ import { formatUntil, relativeUntil } from '../lib/maintenance';
9
+
10
+ const MARKER = 'data-sinn-maintenance';
11
+
12
+ function setup(root: HTMLElement): void {
13
+ if (root.dataset.enhanced) return;
14
+ root.dataset.enhanced = '';
15
+ const until = root.dataset.until;
16
+ const locale = document.documentElement.lang || navigator.language || 'en-US';
17
+ const timeEl = root.querySelector<HTMLTimeElement>('[data-sinn-until]');
18
+ const relEl = root.querySelector<HTMLElement>('[data-sinn-until-relative]');
19
+ const lateEl = root.querySelector<HTMLElement>('[data-sinn-late]');
20
+ const statusEl = root.querySelector<HTMLElement>('[data-sinn-maintenance-status]');
21
+ const checkBtn = root.querySelector<HTMLButtonElement>('[data-sinn-check]');
22
+ const pollUrl = root.dataset.pollUrl || location.href;
23
+ const auto = root.dataset.autoRefresh !== 'false';
24
+ const base = Math.max(15, Number(root.dataset.pollInterval) || 60) * 1000;
25
+
26
+ const untilMs = until ? new Date(until).getTime() : NaN;
27
+ const hasUntil = Number.isFinite(untilMs);
28
+
29
+ function renderTime(): void {
30
+ if (!hasUntil) return;
31
+ if (timeEl) timeEl.textContent = formatUntil(until!, locale); // visitor's zone
32
+ const rel = relativeUntil(until!, locale);
33
+ if (relEl) {
34
+ relEl.textContent = rel ? `(${rel})` : '';
35
+ relEl.hidden = !rel;
36
+ }
37
+ if (lateEl) lateEl.hidden = Boolean(rel);
38
+ }
39
+ renderTime();
40
+ setInterval(renderTime, 30_000);
41
+
42
+ const say = (msg: string) => {
43
+ if (statusEl) statusEl.textContent = msg;
44
+ };
45
+
46
+ async function isBack(): Promise<boolean> {
47
+ try {
48
+ const res = await fetch(pollUrl, { cache: 'no-store', credentials: 'same-origin', headers: { accept: 'text/html' } });
49
+ if (!res.ok || res.headers.get('x-sinn-maintenance')) return false;
50
+ // A host that serves this page with 200 must not trigger a reload loop.
51
+ return !(await res.text()).includes(MARKER);
52
+ } catch {
53
+ return false;
54
+ }
55
+ }
56
+
57
+ let delay = base;
58
+ let timer: ReturnType<typeof setTimeout> | undefined;
59
+ let checking = false;
60
+
61
+ async function check(manual = false): Promise<void> {
62
+ if (checking) return;
63
+ checking = true;
64
+ if (checkBtn) checkBtn.setAttribute('aria-disabled', 'true');
65
+ if (manual) say('Checking…');
66
+ const back = await isBack();
67
+ checking = false;
68
+ checkBtn?.removeAttribute('aria-disabled');
69
+ if (back) {
70
+ say('We’re back. Reloading the page…');
71
+ root.dataset.state = 'back';
72
+ setTimeout(() => location.reload(), 1200);
73
+ return;
74
+ }
75
+ if (manual) say(auto ? 'Still unavailable. We’ll keep checking automatically.' : 'Still unavailable. Please try again later.');
76
+ delay = Math.min(delay * 1.5, 5 * 60_000);
77
+ schedule();
78
+ }
79
+
80
+ function schedule(): void {
81
+ clearTimeout(timer);
82
+ if (!auto) return;
83
+ const startIn = hasUntil ? Math.max(0, untilMs - Date.now()) : 0;
84
+ const wait = Math.max(startIn, delay) * (0.9 + Math.random() * 0.2);
85
+ timer = setTimeout(() => {
86
+ if (document.visibilityState === 'visible' && navigator.onLine) void check();
87
+ else schedule();
88
+ }, wait);
89
+ }
90
+
91
+ checkBtn?.removeAttribute('hidden');
92
+ if (auto) root.querySelector('[data-sinn-auto-note]')?.removeAttribute('hidden');
93
+ checkBtn?.addEventListener('click', () => {
94
+ delay = base;
95
+ void check(true);
96
+ });
97
+ document.addEventListener('visibilitychange', () => {
98
+ if (document.visibilityState === 'visible' && auto && (!hasUntil || Date.now() >= untilMs)) {
99
+ delay = base;
100
+ void check();
101
+ }
102
+ });
103
+ addEventListener('online', () => auto && void check());
104
+ schedule();
105
+ }
106
+
107
+ document.querySelectorAll<HTMLElement>('[data-sinn-maintenance]').forEach(setup);
108
+
109
+ export {};