@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.
- package/CHANGELOG.md +15 -0
- package/LICENSE +373 -0
- package/README.md +186 -2
- package/docs/blocks.md +364 -0
- package/docs/data.md +128 -0
- package/docs/motion.md +166 -0
- package/docs/primitives.md +510 -0
- package/docs/seo.md +187 -0
- package/docs/tokens.md +122 -0
- package/package.json +141 -3
- package/scripts/check-contrast.mjs +180 -0
- package/src/blocks/BlockRenderer.astro +54 -0
- package/src/blocks/CTABanner.astro +121 -0
- package/src/blocks/CTAPair.astro +110 -0
- package/src/blocks/CardGrid.astro +167 -0
- package/src/blocks/ConsentEmbed.astro +125 -0
- package/src/blocks/ConsentManager.astro +147 -0
- package/src/blocks/ConsentScript.astro +47 -0
- package/src/blocks/ContactCard.astro +164 -0
- package/src/blocks/ContactForm.astro +224 -0
- package/src/blocks/ErrorPage.astro +242 -0
- package/src/blocks/FAQ.astro +135 -0
- package/src/blocks/FeatureGrid.astro +148 -0
- package/src/blocks/Hero.astro +171 -0
- package/src/blocks/HeroCarousel.astro +220 -0
- package/src/blocks/HighlightCards.astro +107 -0
- package/src/blocks/LocationHours.astro +311 -0
- package/src/blocks/LogoCloud.astro +135 -0
- package/src/blocks/MaintenancePage.astro +168 -0
- package/src/blocks/MediaText.astro +177 -0
- package/src/blocks/PageHeader.astro +126 -0
- package/src/blocks/ProseSection.astro +98 -0
- package/src/blocks/Reviews.astro +194 -0
- package/src/blocks/RichText.astro +57 -0
- package/src/blocks/StatsBand.astro +117 -0
- package/src/blocks/Steps.astro +141 -0
- package/src/blocks/Testimonials.astro +144 -0
- package/src/blocks/Topbar.astro +158 -0
- package/src/blocks/cms/card-grid.ts +80 -0
- package/src/blocks/cms/consent.ts +45 -0
- package/src/blocks/cms/contact-card.ts +88 -0
- package/src/blocks/cms/contact-form.ts +55 -0
- package/src/blocks/cms/cta-banner.ts +48 -0
- package/src/blocks/cms/cta-pair.ts +63 -0
- package/src/blocks/cms/data-base.ts +7 -0
- package/src/blocks/cms/data.ts +257 -0
- package/src/blocks/cms/faq.ts +70 -0
- package/src/blocks/cms/feature-grid.ts +80 -0
- package/src/blocks/cms/fixtures.ts +599 -0
- package/src/blocks/cms/hero-carousel.ts +80 -0
- package/src/blocks/cms/hero.ts +77 -0
- package/src/blocks/cms/highlight-cards.ts +76 -0
- package/src/blocks/cms/images.ts +38 -0
- package/src/blocks/cms/index.ts +87 -0
- package/src/blocks/cms/location-hours.ts +149 -0
- package/src/blocks/cms/logo-cloud.ts +62 -0
- package/src/blocks/cms/media-text.ts +44 -0
- package/src/blocks/cms/page-header.ts +49 -0
- package/src/blocks/cms/pages.ts +81 -0
- package/src/blocks/cms/prose-section.ts +45 -0
- package/src/blocks/cms/reviews.ts +101 -0
- package/src/blocks/cms/shared.ts +115 -0
- package/src/blocks/cms/stats-band.ts +61 -0
- package/src/blocks/cms/steps.ts +67 -0
- package/src/blocks/cms/testimonials.ts +80 -0
- package/src/blocks/cms/topbar.ts +64 -0
- package/src/blocks/cms/types.ts +63 -0
- package/src/blocks/consent.ts +14 -0
- package/src/blocks/icons.ts +47 -0
- package/src/blocks/index.ts +42 -0
- package/src/blocks/internal/Actions.astro +29 -0
- package/src/blocks/internal/BlockHeader.astro +45 -0
- package/src/blocks/internal/BlockShell.astro +58 -0
- package/src/blocks/internal/CarouselScript.astro +7 -0
- package/src/blocks/internal/ConsentEmbedScript.astro +7 -0
- package/src/blocks/internal/ConsentManagerScript.astro +7 -0
- package/src/blocks/internal/HoursScript.astro +7 -0
- package/src/blocks/internal/Placeholder.astro +13 -0
- package/src/blocks/internal/RichTextNode.astro +133 -0
- package/src/blocks/internal/StandaloneDocument.astro +53 -0
- package/src/blocks/internal/tina.ts +19 -0
- package/src/blocks/internal/util.ts +23 -0
- package/src/blocks/lib/consent.ts +96 -0
- package/src/blocks/lib/contact.ts +86 -0
- package/src/blocks/lib/error-pages.ts +119 -0
- package/src/blocks/lib/faq.ts +37 -0
- package/src/blocks/lib/hours.ts +201 -0
- package/src/blocks/lib/maintenance.ts +129 -0
- package/src/blocks/lib/reviews.ts +22 -0
- package/src/blocks/lib/rich-text.ts +143 -0
- package/src/blocks/lib/slug.ts +12 -0
- package/src/blocks/registry.ts +79 -0
- package/src/blocks/scripts/carousel.ts +218 -0
- package/src/blocks/scripts/consent-embed.ts +105 -0
- package/src/blocks/scripts/consent-manager.ts +112 -0
- package/src/blocks/scripts/consent-store.ts +86 -0
- package/src/blocks/scripts/error-page.ts +71 -0
- package/src/blocks/scripts/hours.ts +106 -0
- package/src/blocks/scripts/maintenance.ts +109 -0
- package/src/blocks/styles/blocks.css +1320 -0
- package/src/blocks/styles/consent.css +102 -0
- package/src/blocks/styles/faq.css +28 -0
- package/src/blocks/styles/location.css +92 -0
- package/src/blocks/styles/prose-section.css +13 -0
- package/src/blocks/styles/quotes.css +123 -0
- package/src/blocks/styles/rich-text.css +14 -0
- package/src/blocks/types.ts +283 -0
- package/src/data/ChartAxis.astro +19 -0
- package/src/data/ChartContainer.astro +151 -0
- package/src/data/ChartLegend.astro +25 -0
- package/src/data/ChartSeries.astro +14 -0
- package/src/data/ChartTable.astro +17 -0
- package/src/data/ChartTooltip.astro +20 -0
- package/src/data/Sparkline.astro +55 -0
- package/src/data/cms.ts +190 -0
- package/src/data/index.ts +10 -0
- package/src/data/lib/chart.ts +450 -0
- package/src/data/lib/render.ts +219 -0
- package/src/data/lib/scale.ts +107 -0
- package/src/data/lib/sparkline.ts +117 -0
- package/src/data/scripts/chart.ts +324 -0
- package/src/data/styles/chart.css +392 -0
- package/src/motion/Marquee.astro +90 -0
- package/src/motion/MotionProvider.astro +50 -0
- package/src/motion/PageTransitions.astro +61 -0
- package/src/motion/Parallax.astro +44 -0
- package/src/motion/ParallaxLayer.astro +31 -0
- package/src/motion/RevealOnScroll.astro +59 -0
- package/src/motion/SceneRegistry.astro +38 -0
- package/src/motion/ScrollScene.astro +81 -0
- package/src/motion/index.ts +12 -0
- package/src/motion/integration.ts +48 -0
- package/src/motion/runtime/page-transitions.ts +68 -0
- package/src/motion/runtime/runtime.ts +180 -0
- package/src/motion/runtime/scenes.ts +248 -0
- package/src/motion/runtime/types.ts +103 -0
- package/src/motion/styles/motion.css +332 -0
- package/src/motion/transitions.ts +74 -0
- package/src/motion/virtual.d.ts +4 -0
- package/src/primitives/Accordion.astro +129 -0
- package/src/primitives/Breadcrumbs.astro +50 -0
- package/src/primitives/BulletList.astro +69 -0
- package/src/primitives/Button.astro +73 -0
- package/src/primitives/ButtonGroup.astro +54 -0
- package/src/primitives/Callout.astro +137 -0
- package/src/primitives/Caption.astro +35 -0
- package/src/primitives/Card.astro +72 -0
- package/src/primitives/CardContent.astro +24 -0
- package/src/primitives/CardFooter.astro +36 -0
- package/src/primitives/CardHeader.astro +86 -0
- package/src/primitives/Checkbox.astro +38 -0
- package/src/primitives/ChoiceGroup.astro +23 -0
- package/src/primitives/Cluster.astro +49 -0
- package/src/primitives/Container.astro +44 -0
- package/src/primitives/DescriptionList.astro +83 -0
- package/src/primitives/Dialog.astro +38 -0
- package/src/primitives/Disclosure.astro +67 -0
- package/src/primitives/Divider.astro +93 -0
- package/src/primitives/Drawer.astro +33 -0
- package/src/primitives/Fieldset.astro +80 -0
- package/src/primitives/Flex.astro +64 -0
- package/src/primitives/FocusRing.astro +63 -0
- package/src/primitives/FocusTrap.astro +64 -0
- package/src/primitives/Footer.astro +155 -0
- package/src/primitives/Form.astro +68 -0
- package/src/primitives/FormDescription.astro +26 -0
- package/src/primitives/FormError.astro +106 -0
- package/src/primitives/FormField.astro +72 -0
- package/src/primitives/Grid.astro +64 -0
- package/src/primitives/Heading.astro +45 -0
- package/src/primitives/IconButton.astro +48 -0
- package/src/primitives/Image.astro +125 -0
- package/src/primitives/Input.astro +84 -0
- package/src/primitives/Label.astro +50 -0
- package/src/primitives/Link.astro +81 -0
- package/src/primitives/LinkButton.astro +66 -0
- package/src/primitives/List.astro +39 -0
- package/src/primitives/ListItem.astro +178 -0
- package/src/primitives/MediaObject.astro +66 -0
- package/src/primitives/MetricCard.astro +276 -0
- package/src/primitives/NavLink.astro +81 -0
- package/src/primitives/NavMenu.astro +109 -0
- package/src/primitives/Navbar.astro +197 -0
- package/src/primitives/Panel.astro +153 -0
- package/src/primitives/Picture.astro +167 -0
- package/src/primitives/Popover.astro +95 -0
- package/src/primitives/Prose.astro +45 -0
- package/src/primitives/Radio.astro +21 -0
- package/src/primitives/Rating.astro +135 -0
- package/src/primitives/ReducedMotion.astro +90 -0
- package/src/primitives/SegmentedControl.astro +132 -0
- package/src/primitives/Select.astro +107 -0
- package/src/primitives/Sheet.astro +45 -0
- package/src/primitives/SkipLink.astro +31 -0
- package/src/primitives/Slider.astro +186 -0
- package/src/primitives/Spacer.astro +35 -0
- package/src/primitives/Stack.astro +51 -0
- package/src/primitives/Surface.astro +70 -0
- package/src/primitives/Switch.astro +22 -0
- package/src/primitives/Table.astro +382 -0
- package/src/primitives/Tabs.astro +126 -0
- package/src/primitives/Text.astro +56 -0
- package/src/primitives/Textarea.astro +73 -0
- package/src/primitives/Thumbnail.astro +154 -0
- package/src/primitives/Toggle.astro +99 -0
- package/src/primitives/Tooltip.astro +50 -0
- package/src/primitives/VisuallyHidden.astro +29 -0
- package/src/primitives/index.ts +103 -0
- package/src/primitives/internal/AccordionScript.astro +7 -0
- package/src/primitives/internal/ChoiceField.astro +89 -0
- package/src/primitives/internal/FocusTrapScript.astro +8 -0
- package/src/primitives/internal/FormValidationScript.astro +10 -0
- package/src/primitives/internal/IndeterminateScript.astro +13 -0
- package/src/primitives/internal/ModalPanel.astro +114 -0
- package/src/primitives/internal/OverlayScript.astro +7 -0
- package/src/primitives/internal/ReducedMotionScript.astro +7 -0
- package/src/primitives/internal/SliderScript.astro +7 -0
- package/src/primitives/internal/SparklineScript.astro +7 -0
- package/src/primitives/internal/TableSortScript.astro +7 -0
- package/src/primitives/internal/TabsScript.astro +7 -0
- package/src/primitives/internal/TooltipScript.astro +7 -0
- package/src/primitives/lib/deprecate.ts +47 -0
- package/src/primitives/lib/focus-trap.ts +197 -0
- package/src/primitives/lib/focus.ts +60 -0
- package/src/primitives/lib/image-plan.ts +82 -0
- package/src/primitives/lib/image.ts +129 -0
- package/src/primitives/lib/motion.ts +68 -0
- package/src/primitives/lib/slider.ts +170 -0
- package/src/primitives/scripts/accordion.ts +123 -0
- package/src/primitives/scripts/form-validation.ts +225 -0
- package/src/primitives/scripts/overlay.ts +71 -0
- package/src/primitives/scripts/reduced-motion.ts +59 -0
- package/src/primitives/scripts/slider.ts +150 -0
- package/src/primitives/scripts/sparkline.ts +131 -0
- package/src/primitives/scripts/table-sort.ts +68 -0
- package/src/primitives/scripts/tabs.ts +151 -0
- package/src/primitives/scripts/tooltip.ts +28 -0
- package/src/primitives/styles/a11y.css +104 -0
- package/src/primitives/styles/accordion.css +53 -0
- package/src/primitives/styles/breadcrumbs.css +59 -0
- package/src/primitives/styles/bullet-list.css +89 -0
- package/src/primitives/styles/button.css +237 -0
- package/src/primitives/styles/choice.css +164 -0
- package/src/primitives/styles/cluster.css +24 -0
- package/src/primitives/styles/container.css +19 -0
- package/src/primitives/styles/data.css +849 -0
- package/src/primitives/styles/disclosure.css +140 -0
- package/src/primitives/styles/divider.css +50 -0
- package/src/primitives/styles/flex.css +42 -0
- package/src/primitives/styles/form.css +241 -0
- package/src/primitives/styles/grid.css +36 -0
- package/src/primitives/styles/media.css +247 -0
- package/src/primitives/styles/nav.css +792 -0
- package/src/primitives/styles/overlay.css +362 -0
- package/src/primitives/styles/prose.css +146 -0
- package/src/primitives/styles/scale.css +175 -0
- package/src/primitives/styles/segmented.css +165 -0
- package/src/primitives/styles/slider.css +170 -0
- package/src/primitives/styles/spacer.css +17 -0
- package/src/primitives/styles/stack.css +25 -0
- package/src/primitives/styles/surface.css +403 -0
- package/src/primitives/styles/tabs.css +223 -0
- package/src/primitives/styles/typography.css +144 -0
- package/src/primitives/styles/utilities.css +24 -0
- package/src/primitives/types.ts +385 -0
- package/src/primitives/utils.ts +254 -0
- package/src/seo/JSONLD.astro +35 -0
- package/src/seo/SEOHead.astro +47 -0
- package/src/seo/cms.ts +80 -0
- package/src/seo/index.ts +10 -0
- package/src/seo/integration.ts +231 -0
- package/src/seo/lib/jsonld.ts +334 -0
- package/src/seo/lib/meta.ts +205 -0
- package/src/seo/lib/redirects.ts +283 -0
- package/src/seo/lib/robots.ts +33 -0
- package/src/seo/lib/rss.ts +98 -0
- package/src/seo/lib/sitemap.ts +105 -0
- package/src/seo/lib/url.ts +68 -0
- package/src/tokens/base.css +71 -0
- package/src/tokens/tokens.css +210 -0
package/docs/seo.md
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
# @sinnstack/ui/seo
|
|
2
|
+
|
|
3
|
+
SEO for Sinnstack sites, all server-rendered and CSP-safe:
|
|
4
|
+
|
|
5
|
+
| Piece | What it is | Import |
|
|
6
|
+
| --- | --- | --- |
|
|
7
|
+
| **SEOHead** | Title, description, canonical, robots, hreflang, Open Graph, Twitter/X, feeds | `@sinnstack/ui/seo` |
|
|
8
|
+
| **JSONLD** | Structured data, with typed builders and checks | `@sinnstack/ui/seo` + `@sinnstack/ui/seo/jsonld` |
|
|
9
|
+
| **Sitemap / RSS** | Sitemaps built from your pages, RSS feeds and robots.txt | `@sinnstack/ui/seo/integration`, `/rss`, `/sitemap` |
|
|
10
|
+
| **RedirectMap** | Redirects from old URLs, checked and exported to Astro or your host | `@sinnstack/ui/seo/redirects` |
|
|
11
|
+
|
|
12
|
+
```js
|
|
13
|
+
// astro.config.mjs
|
|
14
|
+
import sinnSeo from '@sinnstack/ui/seo/integration';
|
|
15
|
+
import { redirects } from './src/data/redirects.mjs';
|
|
16
|
+
export default defineConfig({
|
|
17
|
+
site: 'https://championhealthcare.com', // required: canonicals, sitemaps and share URLs use it
|
|
18
|
+
integrations: [sinnSeo({ redirects, robots: { production: process.env.DEPLOY_ENV === 'production' } })],
|
|
19
|
+
});
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## SEOHead
|
|
23
|
+
|
|
24
|
+
Place it in your layout's `<head>`:
|
|
25
|
+
|
|
26
|
+
```astro
|
|
27
|
+
<SEOHead title={title} titleTemplate="%s | Champion Healthcare" defaultTitle="Champion Healthcare"
|
|
28
|
+
description={description} siteName="Champion Healthcare" locale="en_US"
|
|
29
|
+
image={{ src: cover, alt: 'A nurse reviewing a care plan with a patient' }}
|
|
30
|
+
noindex={noindex} feeds={[{ title: 'Blog', href: '/blog/rss.xml' }]} />
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
**Canonical URL**
|
|
34
|
+
- Built from the current URL, but always on your production `site` origin, so preview deploys never claim to be the real page.
|
|
35
|
+
- The hash and every query parameter are dropped (UTM tags, for example), except those you list in `keepQuery`, such as `page`.
|
|
36
|
+
- `index.html` is removed and your `trailingSlash` setting is applied (the integration passes it in).
|
|
37
|
+
- An explicit `canonical` can be relative (resolved on the site) or absolute (for content syndicated from elsewhere).
|
|
38
|
+
|
|
39
|
+
**Title:** `titleTemplate` is skipped when the title already contains the site name. `og:title` uses the bare page title.
|
|
40
|
+
|
|
41
|
+
**Share image:** an imported image is cropped to a 1200×630 JPEG, the size Facebook, LinkedIn, Slack and X show large. URL strings are used as given. With an image, the Twitter card is `summary_large_image`; without one it's `summary`.
|
|
42
|
+
|
|
43
|
+
**Robots:** indexable pages get `max-image-preview:large`, so Google can show big image previews. `noindex` also keeps the page out of the sitemap.
|
|
44
|
+
|
|
45
|
+
**Development warnings** (`warn`, on by default in dev):
|
|
46
|
+
- a missing title or description, or one that's too long or too short;
|
|
47
|
+
- no share image, a share image smaller than 1200×630, or missing image alt text;
|
|
48
|
+
- `noindex` while the canonical points elsewhere;
|
|
49
|
+
- duplicate hreflang values, or hreflang alternates that don't include the page itself;
|
|
50
|
+
- no `site` set.
|
|
51
|
+
|
|
52
|
+
**Safety:** every value is escaped (tested with `</title><script>` in a title).
|
|
53
|
+
|
|
54
|
+
Without Astro, `buildHead(input)` returns the tags plus warnings, and `renderHead(tags)` returns HTML.
|
|
55
|
+
|
|
56
|
+
## JSONLD
|
|
57
|
+
|
|
58
|
+
```astro
|
|
59
|
+
---
|
|
60
|
+
import { breadcrumbList, article } from '@sinnstack/ui/seo/jsonld';
|
|
61
|
+
---
|
|
62
|
+
<JSONLD data={[breadcrumbList([{ name: 'Home', url: '/' }, { name: 'Blog', url: '/blog/' }, { name: post.title }], { site: Astro.site }),
|
|
63
|
+
article({ type: 'BlogPosting', url, headline: post.title, images: [cover], datePublished: post.date, authors: [{ name: post.author }] })]} />
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
**Builders:**
|
|
67
|
+
|
|
68
|
+
| Builder | Notes |
|
|
69
|
+
| --- | --- |
|
|
70
|
+
| `organization` | Any type, e.g. `MedicalOrganization` |
|
|
71
|
+
| `localBusiness` | `MedicalClinic`, `Physician`, `Dentist`, `Pharmacy`… Includes opening hours from `{ days: ['Mo','Fr'], opens, closes }`, geo, area served, medical specialty and the parent organization |
|
|
72
|
+
| `website` | Includes the site search action |
|
|
73
|
+
| `webPage` | |
|
|
74
|
+
| `breadcrumbList` | Positions added automatically, URLs made absolute |
|
|
75
|
+
| `article` / `BlogPosting` / `NewsArticle` | |
|
|
76
|
+
| `faqPage` | Google currently shows FAQ rich results mainly for authoritative health and government sites |
|
|
77
|
+
| `event` | In person or online, with offers |
|
|
78
|
+
| `person` | |
|
|
79
|
+
| `service` | |
|
|
80
|
+
|
|
81
|
+
**Linking:** `graph()` combines nodes into one `@graph`, linked by `@id`. For example, a location's `parentOrganization` points to `https://site/#organization`.
|
|
82
|
+
|
|
83
|
+
**Development checks:**
|
|
84
|
+
- Google's required and recommended properties for each type.
|
|
85
|
+
- Dates in ISO 8601, and datetimes that include a time zone.
|
|
86
|
+
- Absolute URLs.
|
|
87
|
+
- Breadcrumb positions, and only the last breadcrumb may omit its URL.
|
|
88
|
+
- FAQ answers that are actually filled in.
|
|
89
|
+
- `@id` references that point to nodes not in the graph.
|
|
90
|
+
|
|
91
|
+
**Serialization** escapes `<`, `>`, `&` and U+2028/2029, so CMS text containing `</script>` can't break out. A test checks this in Chrome.
|
|
92
|
+
|
|
93
|
+
**CSP:** `application/ld+json` is a data block that browsers never execute, so `script-src` doesn't apply. A test checks this under `script-src 'self'` and finds no violations.
|
|
94
|
+
|
|
95
|
+
## Sitemap, RSS and robots.txt
|
|
96
|
+
|
|
97
|
+
**Sitemap (integration).** After the build, it reads each page's `<head>` from the HTML Astro actually wrote, so the sitemap agrees with SEOHead.
|
|
98
|
+
- **Left out:**
|
|
99
|
+
- pages marked `noindex`;
|
|
100
|
+
- pages whose canonical points to another URL (print versions, duplicates);
|
|
101
|
+
- Astro's redirect stubs;
|
|
102
|
+
- `404` and `500` pages;
|
|
103
|
+
- anything matching `exclude` or rejected by `filter`.
|
|
104
|
+
- **Carried over:** hreflang alternates, and `article:modified_time` as `lastmod`. `og:image` too, if you turn on `images: true`.
|
|
105
|
+
- **Size limits:** the sitemap is split into files of at most 45,000 URLs (protocol limit 50,000 / 50 MB) under `sitemap-index.xml`.
|
|
106
|
+
- **Redirect conflicts:** the build warns when a redirect source is also a real page.
|
|
107
|
+
- **On-demand pages** aren't files, so add them yourself:
|
|
108
|
+
- with `extraEntries: async () => [...]`; or
|
|
109
|
+
- with a `sitemapEndpoint` route listed in `extraSitemaps`.
|
|
110
|
+
|
|
111
|
+
**robots.txt.** The integration writes it unless one already exists in `public/`.
|
|
112
|
+
- **Production:** allows crawling and lists the sitemap index.
|
|
113
|
+
- **Every other environment** (`robots.production: false`): `Disallow: /`, so preview and staging deploys never get indexed. Production defaults to `true`, so wire the flag to your deploy environment.
|
|
114
|
+
|
|
115
|
+
**RSS.** Set up a feed with `rssEndpoint`:
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
// src/pages/blog/rss.xml.ts
|
|
119
|
+
export const GET = rssEndpoint(async ({ site }) => ({
|
|
120
|
+
title: 'Champion Healthcare blog', description: '…', site: site!, feedUrl: new URL('/blog/rss.xml', site).href,
|
|
121
|
+
items: posts.map((p) => ({ title: p.title, link: `/blog/${p.slug}/`, pubDate: p.date, description: p.summary, content: p.html })),
|
|
122
|
+
}));
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
- It's RSS 2.0 with `atom:link rel="self"`.
|
|
126
|
+
- Items are newest first, limited to 50.
|
|
127
|
+
- Dates use RFC 822, and relative links are made absolute.
|
|
128
|
+
- `content:encoded` handles `]]>` correctly, and `dc:creator` holds the authors (RSS `<author>` would need an email address).
|
|
129
|
+
- Invalid items are dropped.
|
|
130
|
+
|
|
131
|
+
## RedirectMap
|
|
132
|
+
|
|
133
|
+
```js
|
|
134
|
+
// src/data/redirects.mjs
|
|
135
|
+
export const redirects = new RedirectMap([
|
|
136
|
+
{ from: '/home-health-services', to: '/services/home-health' },
|
|
137
|
+
{ from: '/news/[slug]', to: '/blog/[slug]' },
|
|
138
|
+
{ from: '/docs/[...path]', to: '/help/[...path]' },
|
|
139
|
+
{ from: '/flu-shots', to: '/contact', status: 302 },
|
|
140
|
+
]);
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
**Checks, which fail the build:**
|
|
144
|
+
- loops (`/a → /b → /a`);
|
|
145
|
+
- the same source pointing to two different places;
|
|
146
|
+
- self-redirects;
|
|
147
|
+
- destination params that aren't in the source;
|
|
148
|
+
- non-redirect status codes.
|
|
149
|
+
|
|
150
|
+
**Cleanup, reported as warnings:**
|
|
151
|
+
- **Chains collapse:** `/a → /b → /c` becomes `/a → /c`, so visitors and crawlers take one hop.
|
|
152
|
+
- **Sources are normalized:** trailing slash, `//`, and full old URLs reduced to their path.
|
|
153
|
+
- **Query strings in a source:** reported, because they can't be matched.
|
|
154
|
+
|
|
155
|
+
**Exporting.** The integration feeds `toAstro()` into the config. Astro's adapters (Netlify, Vercel, Cloudflare) turn that into real redirects, while a purely static build gets meta-refresh pages. For other hosts:
|
|
156
|
+
- `toRedirectsFile()` writes a Netlify or Cloudflare Pages `_redirects` file (`[slug]` becomes `:slug`, `[...rest]` becomes `*` / `:splat`).
|
|
157
|
+
- `toVercel()` gives Vercel's format (`:path*`).
|
|
158
|
+
|
|
159
|
+
**Site migrations:** `RedirectMap.fromCsv(text)` reads a `from,to,status` export from a crawl spreadsheet. It handles quotes, BOM, CRLF and `#` comments. Use `caseInsensitive: true` for old IIS sites.
|
|
160
|
+
|
|
161
|
+
**Redirects managed in the CMS** on SSR sites, without a rebuild:
|
|
162
|
+
|
|
163
|
+
```ts
|
|
164
|
+
export const onRequest = createRedirectMiddleware(async () => redirectMapFromCms((await getSettings()).redirects));
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
The incoming query string is kept, and the destination's own parameters win.
|
|
168
|
+
|
|
169
|
+
## CMS (Tina)
|
|
170
|
+
|
|
171
|
+
- `seoField` is a per-page "Search & sharing" object: title, description, share image and alt text, hide from search, canonical. Each field has editor hints about length.
|
|
172
|
+
- `seoProps(page.seo, fallbacks)` maps it to SEOHead props.
|
|
173
|
+
- `redirectsField` is a redirect list for a settings singleton, and `redirectMapFromCms(rows)` turns it into a RedirectMap.
|
|
174
|
+
|
|
175
|
+
## Testing
|
|
176
|
+
|
|
177
|
+
```sh
|
|
178
|
+
pnpm test # 30 tests, including the sitemap build on a fake dist/
|
|
179
|
+
pnpm test:browser # 25 checks: XML via lxml (+ xmllint when installed); head + JSON-LD in Chrome under strict CSP
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Setup and flags: [TESTING.md](../../TESTING.md). Without `xmllint` the 6 xmllint checks are skipped (19 run).
|
|
183
|
+
|
|
184
|
+
**Not yet verified:**
|
|
185
|
+
- **Astro:** `astro build` / `astro check`, i.e. the `getImage` crop, the integration hooks against Astro 5's real objects, and adapter redirect output.
|
|
186
|
+
- **Schemas:** the XML is checked to be well-formed and structurally right, but not against the sitemaps.org XSD, which wasn't available offline.
|
|
187
|
+
- **Google:** results from Google's Rich Results Test.
|
package/docs/tokens.md
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# @sinnstack/ui
|
|
2
|
+
|
|
3
|
+
Design tokens for Sinnstack sites, as CSS custom properties. Every component in `@sinnstack/ui` reads these variables, so one stylesheet themes the whole library. Each color carries both a light and a dark value, and the contrast of every pairing the components use is checked against WCAG 2.2.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
pnpm add @sinnstack/ui
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
| Entry | What's in it |
|
|
10
|
+
| --- | --- |
|
|
11
|
+
| `@sinnstack/ui/tokens.css` | All tokens, the cascade-layer order, light/dark switching and reduced-motion handling. Required. |
|
|
12
|
+
| `@sinnstack/ui/base.css` | An optional page baseline: box sizing, body type and colors, responsive media, one focus ring for everything, and reduced motion for content the library doesn't own. |
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
Import once, in your root layout, before any component styles:
|
|
17
|
+
|
|
18
|
+
```astro
|
|
19
|
+
---
|
|
20
|
+
import '@sinnstack/ui/tokens.css';
|
|
21
|
+
import '@sinnstack/ui/base.css'; // skip if the site has its own reset
|
|
22
|
+
---
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Use the tokens in your own CSS like any custom property:
|
|
26
|
+
|
|
27
|
+
```css
|
|
28
|
+
.promo {
|
|
29
|
+
padding: var(--sinn-space-l);
|
|
30
|
+
border-radius: var(--sinn-radius-l);
|
|
31
|
+
background: var(--sinn-color-accent-soft);
|
|
32
|
+
color: var(--sinn-color-text);
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## What's included
|
|
37
|
+
|
|
38
|
+
All names start with `--sinn-`.
|
|
39
|
+
|
|
40
|
+
| Group | Tokens | Notes |
|
|
41
|
+
| --- | --- | --- |
|
|
42
|
+
| **Space** | `space-none`, `3xs`, `2xs`, `xs`, `s`, `m`, `l`, `xl`, `2xl`, `3xl` | Fluid between 320 px and 1240 px viewports, with rem bounds so browser zoom still works. These are the keys component props take (`gap="m"`). |
|
|
43
|
+
| **Measures** | `measure-xs` … `measure-xl`, `measure-prose` | Minimum item widths for Grid and the Flex switch point. |
|
|
44
|
+
| **Containers** | `container-narrow`, `container-default`, `container-wide` | |
|
|
45
|
+
| **Type** | `font-sans`, `font-heading`, `font-mono`; `text-xs` … `text-4xl`; `leading-*`, `weight-*`, `tracking-heading` | Fluid type scale. System font stack by default. |
|
|
46
|
+
| **Surfaces** | `color-surface-sunken`, `surface`, `surface-subtle`, `surface-raised` | Lowest to highest. In dark mode higher is lighter, which reads as elevation. |
|
|
47
|
+
| **Text and borders** | `color-text`, `text-muted`; `color-border-subtle`, `border`, `border-strong` | `border-strong` holds 3:1 for control outlines. |
|
|
48
|
+
| **Tones** | `color-{accent, neutral, danger, success, warning}`, each with `-contrast`, `-soft` and `-text` | Solid fill, text on that fill, soft fill, and text on a surface or soft fill. |
|
|
49
|
+
| **Focus** | `color-focus`, `focus-width`, `focus-offset` | |
|
|
50
|
+
| **Data display** | `color-series-1` … `series-8`, `color-data-*`, `color-chart-*`, `color-rating-*`, `color-skeleton` | The categorical series order is tuned for colorblind safety. Keep the order and don't add a ninth hue. Series colors are for marks, never text. |
|
|
51
|
+
| **Elevation** | `shadow-s`, `shadow-m`, `shadow-l`, `shadow-color`, `color-backdrop` | |
|
|
52
|
+
| **Shape** | `border-width-thin`, `border-width-thick`; `radius-s`, `m`, `l`, `full`, `radius-control` | |
|
|
53
|
+
| **Controls** | `control-s`, `control-m`, `control-l` | Control heights in rem, all at least 24 px (WCAG 2.5.8). |
|
|
54
|
+
| **Layering** | `z-sticky`, `z-tooltip`, `z-skip-link`; `dialog-s` … `dialog-xl` | Dialogs and popovers use the browser's top layer and need no z-index. |
|
|
55
|
+
| **Motion** | `duration-fast`, `duration-base`, `ease-standard`, `motion-scale` | `motion-scale` is 1 for full motion and 0 when reduced. Components scale their movement by it. |
|
|
56
|
+
|
|
57
|
+
## Theming a client site
|
|
58
|
+
|
|
59
|
+
Override only what changes, in a stylesheet loaded after `tokens.css`. Write colors with `light-dark()` so both themes stay covered:
|
|
60
|
+
|
|
61
|
+
```css
|
|
62
|
+
/* src/styles/theme.css */
|
|
63
|
+
@layer sinn.tokens {
|
|
64
|
+
:root {
|
|
65
|
+
--sinn-font-heading: 'Fraunces', Georgia, serif;
|
|
66
|
+
--sinn-radius-control: var(--sinn-radius-full);
|
|
67
|
+
|
|
68
|
+
--sinn-color-accent: light-dark(oklch(0.5 0.15 160), oklch(0.75 0.12 160));
|
|
69
|
+
--sinn-color-accent-contrast: light-dark(oklch(1 0 0), oklch(0.17 0.02 160));
|
|
70
|
+
--sinn-color-accent-soft: light-dark(oklch(0.95 0.03 160), oklch(0.29 0.05 160));
|
|
71
|
+
--sinn-color-accent-text: light-dark(oklch(0.45 0.15 160), oklch(0.82 0.1 160));
|
|
72
|
+
--sinn-color-focus: light-dark(oklch(0.5 0.15 160), oklch(0.8 0.1 160));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
When you change a tone, change all four of its tokens together (fill, `-contrast`, `-soft`, `-text`) so text on each fill still passes.
|
|
78
|
+
|
|
79
|
+
### Check your theme's contrast
|
|
80
|
+
|
|
81
|
+
The package ships its contrast checker. Point it at your theme file; it layers your overrides on top of the base tokens and checks every pairing the components use, in light and dark:
|
|
82
|
+
|
|
83
|
+
```sh
|
|
84
|
+
node node_modules/@sinnstack/ui/scripts/check-contrast.mjs src/styles/theme.css
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
It prints each pair with its ratio and exits non-zero if any fail, so you can run it in CI. Text needs 4.5:1. Control outlines, focus rings and chart marks need 3:1.
|
|
88
|
+
|
|
89
|
+
## Light and dark
|
|
90
|
+
|
|
91
|
+
The site follows the visitor's OS setting by default. To force one theme, set it on `<html>`:
|
|
92
|
+
|
|
93
|
+
```html
|
|
94
|
+
<html data-theme="dark"> <!-- or "light" -->
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Reduced motion
|
|
98
|
+
|
|
99
|
+
`tokens.css` drops durations to 0 and sets `--sinn-motion-scale: 0` when the visitor prefers reduced motion. A site can override the OS setting:
|
|
100
|
+
|
|
101
|
+
```html
|
|
102
|
+
<html data-motion="reduce"> <!-- always reduce -->
|
|
103
|
+
<html data-motion="full"> <!-- always full motion -->
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
`setMotionPreference` in `@sinnstack/ui/primitives/motion` sets this for a site-level "Reduce motion" switch.
|
|
107
|
+
|
|
108
|
+
`base.css` also cuts animations and transitions to near-instant for content the library doesn't own, such as your own CSS and third-party embeds. Mark motion that has to stay, such as a progress indicator, with `data-motion-essential`.
|
|
109
|
+
|
|
110
|
+
## Cascade layers
|
|
111
|
+
|
|
112
|
+
`tokens.css` declares the layer order every Sinnstack stylesheet uses:
|
|
113
|
+
|
|
114
|
+
```css
|
|
115
|
+
@layer sinn.reset, sinn.tokens, sinn.primitives, sinn.data, sinn.motion, sinn.blocks, sinn.overrides;
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Put site adjustments to library components in `@layer sinn.overrides`. Unlayered site CSS beats every layer.
|
|
119
|
+
|
|
120
|
+
## License
|
|
121
|
+
|
|
122
|
+
[MPL-2.0](LICENSE)
|
package/package.json
CHANGED
|
@@ -1,6 +1,144 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sinnstack/ui",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Astro components and design tokens for fast, accessible marketing sites: layout and form primitives, page-section blocks with TinaCMS schemas, SEO tooling, SVG charts and optional motion. Static HTML first, strict-CSP safe.",
|
|
6
|
+
"license": "MPL-2.0",
|
|
7
|
+
"author": "Jeffrey Jackson (Sinnstack)",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/SinnStack/ui.git",
|
|
11
|
+
"directory": "packages/ui"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/SinnStack/ui#readme",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/SinnStack/ui/issues"
|
|
16
|
+
},
|
|
17
|
+
"exports": {
|
|
18
|
+
"./tokens.css": "./src/tokens/tokens.css",
|
|
19
|
+
"./base.css": "./src/tokens/base.css",
|
|
20
|
+
"./primitives": "./src/primitives/index.ts",
|
|
21
|
+
"./primitives/*.astro": "./src/primitives/*.astro",
|
|
22
|
+
"./primitives/types": "./src/primitives/types.ts",
|
|
23
|
+
"./primitives/utils": "./src/primitives/utils.ts",
|
|
24
|
+
"./primitives/motion": "./src/primitives/lib/motion.ts",
|
|
25
|
+
"./primitives/focus": "./src/primitives/lib/focus.ts",
|
|
26
|
+
"./primitives/focus-trap": "./src/primitives/lib/focus-trap.ts",
|
|
27
|
+
"./primitives/deprecate": "./src/primitives/lib/deprecate.ts",
|
|
28
|
+
"./primitives/internal/*": null,
|
|
29
|
+
"./blocks": "./src/blocks/index.ts",
|
|
30
|
+
"./blocks/*.astro": "./src/blocks/*.astro",
|
|
31
|
+
"./blocks/types": "./src/blocks/types.ts",
|
|
32
|
+
"./blocks/icons": "./src/blocks/icons.ts",
|
|
33
|
+
"./blocks/cms": "./src/blocks/cms/index.ts",
|
|
34
|
+
"./blocks/registry": "./src/blocks/registry.ts",
|
|
35
|
+
"./blocks/maintenance": "./src/blocks/lib/maintenance.ts",
|
|
36
|
+
"./blocks/error-pages": "./src/blocks/lib/error-pages.ts",
|
|
37
|
+
"./blocks/contact": "./src/blocks/lib/contact.ts",
|
|
38
|
+
"./blocks/consent": "./src/blocks/consent.ts",
|
|
39
|
+
"./blocks/rich-text": "./src/blocks/lib/rich-text.ts",
|
|
40
|
+
"./blocks/hours": "./src/blocks/lib/hours.ts",
|
|
41
|
+
"./blocks/faq": "./src/blocks/lib/faq.ts",
|
|
42
|
+
"./blocks/styles.css": "./src/blocks/styles/blocks.css",
|
|
43
|
+
"./blocks/internal/*": null,
|
|
44
|
+
"./seo": "./src/seo/index.ts",
|
|
45
|
+
"./seo/*.astro": "./src/seo/*.astro",
|
|
46
|
+
"./seo/meta": "./src/seo/lib/meta.ts",
|
|
47
|
+
"./seo/jsonld": "./src/seo/lib/jsonld.ts",
|
|
48
|
+
"./seo/sitemap": "./src/seo/lib/sitemap.ts",
|
|
49
|
+
"./seo/rss": "./src/seo/lib/rss.ts",
|
|
50
|
+
"./seo/robots": "./src/seo/lib/robots.ts",
|
|
51
|
+
"./seo/redirects": "./src/seo/lib/redirects.ts",
|
|
52
|
+
"./seo/integration": "./src/seo/integration.ts",
|
|
53
|
+
"./seo/cms": "./src/seo/cms.ts",
|
|
54
|
+
"./seo/internal/*": null,
|
|
55
|
+
"./data": "./src/data/index.ts",
|
|
56
|
+
"./data/*.astro": "./src/data/*.astro",
|
|
57
|
+
"./data/chart": "./src/data/lib/chart.ts",
|
|
58
|
+
"./data/sparkline": "./src/data/lib/sparkline.ts",
|
|
59
|
+
"./data/render": "./src/data/lib/render.ts",
|
|
60
|
+
"./data/cms": "./src/data/cms.ts",
|
|
61
|
+
"./data/styles.css": "./src/data/styles/chart.css",
|
|
62
|
+
"./data/internal/*": null,
|
|
63
|
+
"./motion": "./src/motion/index.ts",
|
|
64
|
+
"./motion/*.astro": "./src/motion/*.astro",
|
|
65
|
+
"./motion/runtime": "./src/motion/runtime/runtime.ts",
|
|
66
|
+
"./motion/scenes": "./src/motion/runtime/scenes.ts",
|
|
67
|
+
"./motion/types": "./src/motion/runtime/types.ts",
|
|
68
|
+
"./motion/transitions": "./src/motion/transitions.ts",
|
|
69
|
+
"./motion/integration": "./src/motion/integration.ts",
|
|
70
|
+
"./motion/styles.css": "./src/motion/styles/motion.css",
|
|
71
|
+
"./motion/internal/*": null,
|
|
72
|
+
"./package.json": "./package.json"
|
|
73
|
+
},
|
|
74
|
+
"files": [
|
|
75
|
+
"src",
|
|
76
|
+
"scripts/check-contrast.mjs",
|
|
77
|
+
"docs",
|
|
78
|
+
"README.md",
|
|
79
|
+
"CHANGELOG.md",
|
|
80
|
+
"LICENSE"
|
|
81
|
+
],
|
|
82
|
+
"sideEffects": [
|
|
83
|
+
"**/*.css",
|
|
84
|
+
"**/*.astro",
|
|
85
|
+
"./src/primitives/scripts/*.ts",
|
|
86
|
+
"./src/blocks/scripts/*.ts",
|
|
87
|
+
"./src/data/scripts/*.ts"
|
|
88
|
+
],
|
|
89
|
+
"peerDependencies": {
|
|
90
|
+
"astro": "^5.10.0",
|
|
91
|
+
"gsap": "^3.13.0",
|
|
92
|
+
"lenis": "^1.3.0"
|
|
93
|
+
},
|
|
94
|
+
"peerDependenciesMeta": {
|
|
95
|
+
"gsap": {
|
|
96
|
+
"optional": true
|
|
97
|
+
},
|
|
98
|
+
"lenis": {
|
|
99
|
+
"optional": true
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
"devDependencies": {
|
|
103
|
+
"@astrojs/check": "^0.9.0",
|
|
104
|
+
"@size-limit/preset-small-lib": "^11.1.0",
|
|
105
|
+
"@types/node": "^22",
|
|
106
|
+
"astro": "^5.10.0",
|
|
107
|
+
"gsap": "^3.13.0",
|
|
108
|
+
"lenis": "^1.3.0",
|
|
109
|
+
"sharp": "^0.34.5",
|
|
110
|
+
"size-limit": "^11.1.0"
|
|
111
|
+
},
|
|
112
|
+
"keywords": [
|
|
113
|
+
"astro",
|
|
114
|
+
"astro-component",
|
|
115
|
+
"astro-integration",
|
|
116
|
+
"design-tokens",
|
|
117
|
+
"ui",
|
|
118
|
+
"layout",
|
|
119
|
+
"landing-page",
|
|
120
|
+
"blocks",
|
|
121
|
+
"tinacms",
|
|
122
|
+
"seo",
|
|
123
|
+
"sitemap",
|
|
124
|
+
"json-ld",
|
|
125
|
+
"charts",
|
|
126
|
+
"accessible",
|
|
127
|
+
"csp",
|
|
128
|
+
"motion",
|
|
129
|
+
"gsap"
|
|
130
|
+
],
|
|
131
|
+
"publishConfig": {
|
|
132
|
+
"access": "public"
|
|
133
|
+
},
|
|
134
|
+
"scripts": {
|
|
135
|
+
"gen": "node scripts/generate-scale-css.mjs",
|
|
136
|
+
"gen:chart-css": "node scripts/generate-chart-css.mjs",
|
|
137
|
+
"gen:motion-css": "node scripts/generate-motion-css.mjs",
|
|
138
|
+
"check": "node scripts/check-contrast.mjs && astro check",
|
|
139
|
+
"test": "node --no-warnings test/primitives/controls/slider.unit.mjs && node --no-warnings test/primitives/layer-order.unit.mjs && node --no-warnings test/blocks/unit/system-pages.unit.mjs && node --no-warnings test/blocks/unit/new-blocks.unit.mjs && node --no-warnings test/blocks/unit/content-blocks.unit.mjs && node --no-warnings test/seo/unit/seo.unit.mjs && node --no-warnings test/data/unit/chart-model.unit.mjs",
|
|
140
|
+
"test:browser": "node ../../scripts/test-browser.mjs all",
|
|
141
|
+
"test:visual": "node ../../scripts/test-browser.mjs all --only-visual",
|
|
142
|
+
"size": "size-limit"
|
|
143
|
+
}
|
|
6
144
|
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
// Verifies WCAG 2.2 contrast for token pairs in both light and dark themes.
|
|
2
|
+
// Exits non-zero on failure so CI blocks a theme that breaks contrast (§7: "Tokens enforce contrast").
|
|
3
|
+
// Usage: node scripts/check-contrast.mjs [path/to/theme.css] (defaults to src/tokens.css)
|
|
4
|
+
import { readFileSync } from 'node:fs';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
|
|
7
|
+
const file = process.argv[2] ?? fileURLToPath(new URL('../src/tokens/tokens.css', import.meta.url));
|
|
8
|
+
const css = readFileSync(file, 'utf8');
|
|
9
|
+
|
|
10
|
+
// [foreground, background, minimum ratio, why]
|
|
11
|
+
const PAIRS = [
|
|
12
|
+
['text', 'surface', 4.5, 'body text'],
|
|
13
|
+
['text-muted', 'surface', 4.5, 'captions, muted text'],
|
|
14
|
+
['accent-text', 'surface', 4.5, 'links, outline/ghost buttons'],
|
|
15
|
+
['danger-text', 'surface', 4.5, 'error text, danger ghost'],
|
|
16
|
+
['success-text', 'surface', 4.5, 'success text'],
|
|
17
|
+
['neutral-text', 'neutral-soft', 4.5, 'neutral soft button'],
|
|
18
|
+
['accent-text', 'accent-soft', 4.5, 'accent soft button / pressed toggle'],
|
|
19
|
+
['danger-text', 'danger-soft', 4.5, 'danger soft button'],
|
|
20
|
+
['accent-contrast', 'accent', 4.5, 'solid accent button, checkmark'],
|
|
21
|
+
['neutral-contrast', 'neutral', 4.5, 'solid neutral button'],
|
|
22
|
+
['danger-contrast', 'danger', 4.5, 'solid danger button'],
|
|
23
|
+
['border-strong', 'surface', 3, 'unchecked control boundary (1.4.11)'],
|
|
24
|
+
['accent', 'surface', 3, 'checked control fill (1.4.11)'],
|
|
25
|
+
['focus', 'surface', 3, 'focus indicator (2.4.13 / 1.4.11)'],
|
|
26
|
+
['surface', 'border-strong', 3, 'switch thumb on unchecked track'],
|
|
27
|
+
// Surfaces
|
|
28
|
+
['text', 'surface-subtle', 4.5, 'text on subtle surface'],
|
|
29
|
+
['text-muted', 'surface-subtle', 4.5, 'muted text on subtle surface (card footer)'],
|
|
30
|
+
['text', 'surface-sunken', 4.5, 'text on sunken surface'],
|
|
31
|
+
['text-muted', 'surface-sunken', 4.5, 'muted text on sunken surface'],
|
|
32
|
+
['text', 'surface-raised', 4.5, 'text on raised surface (cards)'],
|
|
33
|
+
['text-muted', 'surface-raised', 4.5, 'muted text on raised surface'],
|
|
34
|
+
['accent-text', 'surface-raised', 4.5, 'links in cards'],
|
|
35
|
+
// Tinted surfaces / Callout
|
|
36
|
+
['text', 'accent-soft', 4.5, 'body text in info callout'],
|
|
37
|
+
['text', 'success-soft', 4.5, 'body text in success callout'],
|
|
38
|
+
['text', 'warning-soft', 4.5, 'body text in warning callout'],
|
|
39
|
+
['text', 'danger-soft', 4.5, 'body text in danger callout'],
|
|
40
|
+
['text', 'neutral-soft', 4.5, 'body text in neutral callout'],
|
|
41
|
+
['success-text', 'success-soft', 4.5, 'success title/icon on its fill'],
|
|
42
|
+
['warning-text', 'warning-soft', 4.5, 'warning title/icon on its fill'],
|
|
43
|
+
['warning-text', 'surface', 4.5, 'warning text on surface'],
|
|
44
|
+
['success-contrast', 'success', 4.5, 'solid success fill'],
|
|
45
|
+
['warning-contrast', 'warning', 4.5, 'solid warning fill'],
|
|
46
|
+
['accent-text', 'accent-soft', 4.5, 'link in info callout'],
|
|
47
|
+
['accent-text', 'warning-soft', 4.5, 'link in warning callout'],
|
|
48
|
+
['accent-text', 'danger-soft', 4.5, 'link in danger callout'],
|
|
49
|
+
['accent-text', 'success-soft', 4.5, 'link in success callout'],
|
|
50
|
+
// Data display
|
|
51
|
+
['data-muted', 'surface-raised', 3, 'sparkline / de-emphasis line (graphic)'],
|
|
52
|
+
['accent', 'surface-raised', 3, 'current-period dot, meter fill (graphic)'],
|
|
53
|
+
['accent', 'data-track', 3, 'meter fill against its track'],
|
|
54
|
+
['rating-stroke', 'surface-raised', 3, 'star outline (graphic)'],
|
|
55
|
+
['success-text', 'surface-raised', 4.5, 'positive delta text in cards'],
|
|
56
|
+
['danger-text', 'surface-raised', 4.5, 'negative delta text in cards'],
|
|
57
|
+
['text-muted', 'neutral-soft', 4.5, 'muted text in hovered table row'],
|
|
58
|
+
];
|
|
59
|
+
|
|
60
|
+
// Blended pairs, as the blocks draw them: [name, foreground, background, weight of foreground]
|
|
61
|
+
// Muted text on a strong section is color-mix(in oklch, contrast 86%, solid) (blocks.css).
|
|
62
|
+
const BLENDS = [
|
|
63
|
+
['strong-muted-accent', 'accent-contrast', 'accent', 0.86],
|
|
64
|
+
['strong-muted-neutral', 'neutral-contrast', 'neutral', 0.86],
|
|
65
|
+
];
|
|
66
|
+
PAIRS.push(
|
|
67
|
+
['strong-muted-accent', 'accent', 4.5, 'muted text / eyebrow on a strong accent block'],
|
|
68
|
+
['strong-muted-neutral', 'neutral', 4.5, 'muted text / eyebrow on a strong neutral block'],
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
// --- Colour parsing: oklch(), #hex and rgb() are all accepted. -----------------------------------
|
|
72
|
+
const COLOR = String.raw`(?:oklch\([^)]*\)|#[0-9a-fA-F]{3,8}\b|rgba?\([^)]*\))`;
|
|
73
|
+
|
|
74
|
+
/** Parse one CSS colour into OKLCH ({ L, C, H }), or null when the syntax isn't supported. */
|
|
75
|
+
function toOklch(str) {
|
|
76
|
+
str = str.trim();
|
|
77
|
+
if (str.startsWith('oklch(')) {
|
|
78
|
+
const [L, C, H] = str.slice(6, -1).split('/')[0].trim().split(/\s+/).map((v) =>
|
|
79
|
+
v.endsWith('%') ? parseFloat(v) / 100 : parseFloat(v),
|
|
80
|
+
);
|
|
81
|
+
return { L, C, H: Number.isFinite(H) ? H : 0 };
|
|
82
|
+
}
|
|
83
|
+
let rgb;
|
|
84
|
+
if (str.startsWith('#')) {
|
|
85
|
+
let h = str.slice(1);
|
|
86
|
+
if (h.length <= 4) h = [...h].map((c) => c + c).join('');
|
|
87
|
+
rgb = [0, 2, 4].map((i) => parseInt(h.slice(i, i + 2), 16) / 255);
|
|
88
|
+
} else if (/^rgba?\(/.test(str)) {
|
|
89
|
+
rgb = str.replace(/^rgba?\(|\)$/g, '').split('/')[0].split(/[\s,]+/).filter(Boolean).slice(0, 3)
|
|
90
|
+
.map((v) => (v.endsWith('%') ? parseFloat(v) / 100 : parseFloat(v) / 255));
|
|
91
|
+
} else return null;
|
|
92
|
+
const lin = rgb.map((c) => (c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4));
|
|
93
|
+
const l = Math.cbrt(0.4122214708 * lin[0] + 0.5363325363 * lin[1] + 0.0514459929 * lin[2]);
|
|
94
|
+
const m = Math.cbrt(0.2119034982 * lin[0] + 0.6806995451 * lin[1] + 0.1073969566 * lin[2]);
|
|
95
|
+
const s = Math.cbrt(0.0883024619 * lin[0] + 0.2817188376 * lin[1] + 0.6299787005 * lin[2]);
|
|
96
|
+
const L = 0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s;
|
|
97
|
+
const a = 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s;
|
|
98
|
+
const b = 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s;
|
|
99
|
+
return { L, C: Math.hypot(a, b), H: ((Math.atan2(b, a) * 180) / Math.PI + 360) % 360 };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** color-mix(in oklch, a w, b): straight interpolation, shorter hue arc (as browsers do). */
|
|
103
|
+
function mixOklch(a, b, w) {
|
|
104
|
+
let [h1, h2] = [a.H, b.H];
|
|
105
|
+
if (a.C < 1e-4) h1 = h2;
|
|
106
|
+
if (b.C < 1e-4) h2 = h1;
|
|
107
|
+
const d = ((h2 - h1 + 540) % 360) - 180;
|
|
108
|
+
return { L: a.L * w + b.L * (1 - w), C: a.C * w + b.C * (1 - w), H: (h1 + d * (1 - w) + 360) % 360 };
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Read --sinn-color-* tokens from a stylesheet. `light-dark(a, b)` gives each side; a plain value
|
|
113
|
+
* applies to both (themes that only ship one scheme write plain values).
|
|
114
|
+
*/
|
|
115
|
+
function readTokens(source) {
|
|
116
|
+
const out = {};
|
|
117
|
+
const re = new RegExp(String.raw`--sinn-color-([\w-]+):\s*(?:light-dark\(\s*(${COLOR})\s*,\s*(${COLOR})\s*\)|(${COLOR}))\s*;`, 'g');
|
|
118
|
+
for (const m of source.matchAll(re)) {
|
|
119
|
+
const light = toOklch(m[2] ?? m[4]);
|
|
120
|
+
const dark = toOklch(m[3] ?? m[4]);
|
|
121
|
+
if (light && dark) out[m[1]] = { light, dark };
|
|
122
|
+
}
|
|
123
|
+
return out;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// The base tokens first, then the theme file on top: a client theme only overrides some tokens.
|
|
127
|
+
const basePath = fileURLToPath(new URL('../src/tokens/tokens.css', import.meta.url));
|
|
128
|
+
const tokens = { ...readTokens(readFileSync(basePath, 'utf8')), ...(file === basePath ? {} : readTokens(css)) };
|
|
129
|
+
for (const [name, fg, bg, w] of BLENDS) {
|
|
130
|
+
if (tokens[fg] && tokens[bg]) {
|
|
131
|
+
tokens[name] = {
|
|
132
|
+
light: mixOklch(tokens[fg].light, tokens[bg].light, w),
|
|
133
|
+
dark: mixOklch(tokens[fg].dark, tokens[bg].dark, w),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// A theme that fixes one scheme (`color-scheme: dark` on :root) is only checked in that scheme.
|
|
139
|
+
const scheme = css.match(/:root\s*\{[^}]*?color-scheme:\s*(light|dark)\s*;/)?.[1];
|
|
140
|
+
const THEMES = scheme ? [scheme] : ['light', 'dark'];
|
|
141
|
+
|
|
142
|
+
function luminance({ L, C, H }) {
|
|
143
|
+
const h = (H * Math.PI) / 180;
|
|
144
|
+
const a = C * Math.cos(h);
|
|
145
|
+
const b = C * Math.sin(h);
|
|
146
|
+
const l = (L + 0.3963377774 * a + 0.2158037573 * b) ** 3;
|
|
147
|
+
const m = (L - 0.1055613458 * a - 0.0638541728 * b) ** 3;
|
|
148
|
+
const s = (L - 0.0894841775 * a - 1.291485548 * b) ** 3;
|
|
149
|
+
const clamp = (x) => Math.min(1, Math.max(0, x));
|
|
150
|
+
const R = clamp(4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s);
|
|
151
|
+
const G = clamp(-1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s);
|
|
152
|
+
const B = clamp(-0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s);
|
|
153
|
+
const toSrgb = (c) => (c <= 0.0031308 ? 12.92 * c : 1.055 * c ** (1 / 2.4) - 0.055);
|
|
154
|
+
const lin = (c) => (c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4);
|
|
155
|
+
// Clamp in gamma space (as a browser paints it), then back to linear for WCAG luminance.
|
|
156
|
+
return 0.2126 * lin(toSrgb(R)) + 0.7152 * lin(toSrgb(G)) + 0.0722 * lin(toSrgb(B));
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const ratio = (fg, bg) => {
|
|
160
|
+
const [a, b] = [luminance(fg), luminance(bg)].sort((x, y) => y - x);
|
|
161
|
+
return (a + 0.05) / (b + 0.05);
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
let failed = 0;
|
|
165
|
+
for (const theme of THEMES) {
|
|
166
|
+
console.log(`\n${theme.toUpperCase()}`);
|
|
167
|
+
for (const [fg, bg, min, why] of PAIRS) {
|
|
168
|
+
if (!tokens[fg] || !tokens[bg]) {
|
|
169
|
+
console.log(` ✗ missing token: ${!tokens[fg] ? fg : bg}`);
|
|
170
|
+
failed++;
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
const r = ratio(tokens[fg][theme], tokens[bg][theme]);
|
|
174
|
+
const ok = r >= min;
|
|
175
|
+
if (!ok) failed++;
|
|
176
|
+
console.log(` ${ok ? '✓' : '✗'} ${r.toFixed(2).padStart(5)} ≥ ${min} ${fg} on ${bg} (${why})`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
console.log(failed ? `\n${failed} contrast check(s) failed` : '\nAll contrast checks passed');
|
|
180
|
+
process.exit(failed ? 1 : 0);
|