@sinnstack/ui 0.0.0-stage → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (306) hide show
  1. package/CHANGELOG.md +89 -0
  2. package/LICENSE +373 -0
  3. package/README.md +188 -2
  4. package/docs/blocks.md +373 -0
  5. package/docs/data.md +128 -0
  6. package/docs/finishes.md +165 -0
  7. package/docs/motion.md +166 -0
  8. package/docs/primitives.md +510 -0
  9. package/docs/seo.md +191 -0
  10. package/docs/tokens.md +122 -0
  11. package/package.json +132 -3
  12. package/scripts/check-contrast.mjs +180 -0
  13. package/src/blocks/BlockRenderer.astro +60 -0
  14. package/src/blocks/CTABanner.astro +121 -0
  15. package/src/blocks/CTAPair.astro +110 -0
  16. package/src/blocks/CardGrid.astro +167 -0
  17. package/src/blocks/ConsentEmbed.astro +125 -0
  18. package/src/blocks/ConsentManager.astro +147 -0
  19. package/src/blocks/ConsentScript.astro +47 -0
  20. package/src/blocks/ContactCard.astro +164 -0
  21. package/src/blocks/ContactForm.astro +224 -0
  22. package/src/blocks/ErrorPage.astro +242 -0
  23. package/src/blocks/FAQ.astro +135 -0
  24. package/src/blocks/FeatureGrid.astro +148 -0
  25. package/src/blocks/Hero.astro +171 -0
  26. package/src/blocks/HeroCarousel.astro +220 -0
  27. package/src/blocks/HighlightCards.astro +107 -0
  28. package/src/blocks/LocationHours.astro +311 -0
  29. package/src/blocks/LogoCloud.astro +135 -0
  30. package/src/blocks/MaintenancePage.astro +173 -0
  31. package/src/blocks/MediaText.astro +177 -0
  32. package/src/blocks/PageHeader.astro +126 -0
  33. package/src/blocks/ProseSection.astro +98 -0
  34. package/src/blocks/Reviews.astro +194 -0
  35. package/src/blocks/RichText.astro +58 -0
  36. package/src/blocks/StatsBand.astro +117 -0
  37. package/src/blocks/Steps.astro +141 -0
  38. package/src/blocks/Testimonials.astro +144 -0
  39. package/src/blocks/Topbar.astro +158 -0
  40. package/src/blocks/cms/card-grid.ts +48 -0
  41. package/src/blocks/cms/consent.ts +16 -0
  42. package/src/blocks/cms/contact-card.ts +46 -0
  43. package/src/blocks/cms/contact-form.ts +37 -0
  44. package/src/blocks/cms/cta-banner.ts +27 -0
  45. package/src/blocks/cms/cta-pair.ts +30 -0
  46. package/src/blocks/cms/data-base.ts +5 -0
  47. package/src/blocks/cms/data.ts +257 -0
  48. package/src/blocks/cms/faq.ts +38 -0
  49. package/src/blocks/cms/feature-grid.ts +47 -0
  50. package/src/blocks/cms/fixtures.ts +591 -0
  51. package/src/blocks/cms/hero-carousel.ts +36 -0
  52. package/src/blocks/cms/hero.ts +33 -0
  53. package/src/blocks/cms/highlight-cards.ts +41 -0
  54. package/src/blocks/cms/images.ts +37 -0
  55. package/src/blocks/cms/index.ts +59 -0
  56. package/src/blocks/cms/location-hours.ts +67 -0
  57. package/src/blocks/cms/logo-cloud.ts +36 -0
  58. package/src/blocks/cms/media-text.ts +26 -0
  59. package/src/blocks/cms/page-header.ts +27 -0
  60. package/src/blocks/cms/pages.ts +35 -0
  61. package/src/blocks/cms/prose-section.ts +25 -0
  62. package/src/blocks/cms/reviews.ts +50 -0
  63. package/src/blocks/cms/schema-dsl.ts +134 -0
  64. package/src/blocks/cms/schema.ts +794 -0
  65. package/src/blocks/cms/shared.ts +63 -0
  66. package/src/blocks/cms/stats-band.ts +35 -0
  67. package/src/blocks/cms/steps.ts +40 -0
  68. package/src/blocks/cms/testimonials.ts +46 -0
  69. package/src/blocks/cms/topbar.ts +27 -0
  70. package/src/blocks/cms/types.ts +27 -0
  71. package/src/blocks/consent.ts +14 -0
  72. package/src/blocks/icons.ts +47 -0
  73. package/src/blocks/index.ts +42 -0
  74. package/src/blocks/internal/Actions.astro +35 -0
  75. package/src/blocks/internal/BlockHeader.astro +45 -0
  76. package/src/blocks/internal/BlockShell.astro +58 -0
  77. package/src/blocks/internal/CarouselScript.astro +7 -0
  78. package/src/blocks/internal/ConsentEmbedScript.astro +7 -0
  79. package/src/blocks/internal/ConsentManagerScript.astro +7 -0
  80. package/src/blocks/internal/HoursScript.astro +7 -0
  81. package/src/blocks/internal/Placeholder.astro +13 -0
  82. package/src/blocks/internal/RichTextNode.astro +133 -0
  83. package/src/blocks/internal/StandaloneDocument.astro +53 -0
  84. package/src/blocks/internal/consent.ts +96 -0
  85. package/src/blocks/internal/fields.ts +18 -0
  86. package/src/blocks/internal/registry-contract.ts +67 -0
  87. package/src/blocks/internal/reviews.ts +22 -0
  88. package/src/blocks/internal/slug.ts +12 -0
  89. package/src/blocks/internal/util.ts +23 -0
  90. package/src/blocks/lib/contact.ts +92 -0
  91. package/src/blocks/lib/error-pages.ts +119 -0
  92. package/src/blocks/lib/faq.ts +37 -0
  93. package/src/blocks/lib/hours.ts +201 -0
  94. package/src/blocks/lib/maintenance.ts +129 -0
  95. package/src/blocks/lib/markdown.ts +350 -0
  96. package/src/blocks/lib/rich-text.ts +132 -0
  97. package/src/blocks/registry.ts +79 -0
  98. package/src/blocks/scripts/carousel.ts +218 -0
  99. package/src/blocks/scripts/consent-embed.ts +105 -0
  100. package/src/blocks/scripts/consent-manager.ts +112 -0
  101. package/src/blocks/scripts/consent-store.ts +86 -0
  102. package/src/blocks/scripts/error-page.ts +71 -0
  103. package/src/blocks/scripts/hours.ts +107 -0
  104. package/src/blocks/scripts/maintenance.ts +109 -0
  105. package/src/blocks/styles/blocks.css +1320 -0
  106. package/src/blocks/styles/consent.css +102 -0
  107. package/src/blocks/styles/faq.css +28 -0
  108. package/src/blocks/styles/location.css +92 -0
  109. package/src/blocks/styles/prose-section.css +13 -0
  110. package/src/blocks/styles/quotes.css +123 -0
  111. package/src/blocks/styles/rich-text.css +14 -0
  112. package/src/blocks/types.ts +293 -0
  113. package/src/data/ChartAxis.astro +19 -0
  114. package/src/data/ChartContainer.astro +152 -0
  115. package/src/data/ChartLegend.astro +25 -0
  116. package/src/data/ChartSeries.astro +14 -0
  117. package/src/data/ChartTable.astro +17 -0
  118. package/src/data/ChartTooltip.astro +20 -0
  119. package/src/data/Sparkline.astro +55 -0
  120. package/src/data/cms.ts +130 -0
  121. package/src/data/index.ts +10 -0
  122. package/src/data/internal/scale.ts +107 -0
  123. package/src/data/lib/chart.ts +459 -0
  124. package/src/data/lib/render.ts +219 -0
  125. package/src/data/lib/sparkline.ts +117 -0
  126. package/src/data/schema.ts +65 -0
  127. package/src/data/scripts/chart.ts +324 -0
  128. package/src/data/styles/chart.css +392 -0
  129. package/src/finishes/aurora.css +75 -0
  130. package/src/finishes/autumn.css +87 -0
  131. package/src/finishes/blueprint.css +69 -0
  132. package/src/finishes/brutalist.css +55 -0
  133. package/src/finishes/clay.css +48 -0
  134. package/src/finishes/day-cycle.css +46 -0
  135. package/src/finishes/fog.css +71 -0
  136. package/src/finishes/glass.css +149 -0
  137. package/src/finishes/holographic.css +91 -0
  138. package/src/finishes/night.css +77 -0
  139. package/src/finishes/paper.css +58 -0
  140. package/src/finishes/polished-glass.css +159 -0
  141. package/src/finishes/rain.css +84 -0
  142. package/src/finishes/scripts/day-cycle.ts +30 -0
  143. package/src/finishes/scripts/holographic.ts +37 -0
  144. package/src/finishes/scripts/spotlight.ts +30 -0
  145. package/src/finishes/spotlight.css +41 -0
  146. package/src/finishes/spring.css +80 -0
  147. package/src/finishes/terminal.css +49 -0
  148. package/src/motion/Marquee.astro +90 -0
  149. package/src/motion/MotionProvider.astro +50 -0
  150. package/src/motion/PageTransitions.astro +61 -0
  151. package/src/motion/Parallax.astro +44 -0
  152. package/src/motion/ParallaxLayer.astro +31 -0
  153. package/src/motion/RevealOnScroll.astro +59 -0
  154. package/src/motion/SceneRegistry.astro +38 -0
  155. package/src/motion/ScrollScene.astro +81 -0
  156. package/src/motion/index.ts +12 -0
  157. package/src/motion/integration.ts +48 -0
  158. package/src/motion/runtime/page-transitions.ts +68 -0
  159. package/src/motion/runtime/runtime.ts +180 -0
  160. package/src/motion/runtime/scenes.ts +248 -0
  161. package/src/motion/runtime/types.ts +103 -0
  162. package/src/motion/styles/motion.css +332 -0
  163. package/src/motion/transitions.ts +74 -0
  164. package/src/motion/virtual.d.ts +4 -0
  165. package/src/primitives/Accordion.astro +129 -0
  166. package/src/primitives/Breadcrumbs.astro +50 -0
  167. package/src/primitives/BulletList.astro +69 -0
  168. package/src/primitives/Button.astro +73 -0
  169. package/src/primitives/ButtonGroup.astro +54 -0
  170. package/src/primitives/Callout.astro +137 -0
  171. package/src/primitives/Caption.astro +35 -0
  172. package/src/primitives/Card.astro +72 -0
  173. package/src/primitives/CardContent.astro +24 -0
  174. package/src/primitives/CardFooter.astro +36 -0
  175. package/src/primitives/CardHeader.astro +86 -0
  176. package/src/primitives/Checkbox.astro +38 -0
  177. package/src/primitives/ChoiceGroup.astro +23 -0
  178. package/src/primitives/Cluster.astro +49 -0
  179. package/src/primitives/Container.astro +44 -0
  180. package/src/primitives/DescriptionList.astro +83 -0
  181. package/src/primitives/Dialog.astro +38 -0
  182. package/src/primitives/Disclosure.astro +67 -0
  183. package/src/primitives/Divider.astro +93 -0
  184. package/src/primitives/Drawer.astro +33 -0
  185. package/src/primitives/Fieldset.astro +80 -0
  186. package/src/primitives/Flex.astro +64 -0
  187. package/src/primitives/FocusRing.astro +63 -0
  188. package/src/primitives/FocusTrap.astro +64 -0
  189. package/src/primitives/Footer.astro +155 -0
  190. package/src/primitives/Form.astro +68 -0
  191. package/src/primitives/FormDescription.astro +26 -0
  192. package/src/primitives/FormError.astro +106 -0
  193. package/src/primitives/FormField.astro +72 -0
  194. package/src/primitives/Grid.astro +64 -0
  195. package/src/primitives/Heading.astro +45 -0
  196. package/src/primitives/IconButton.astro +48 -0
  197. package/src/primitives/Image.astro +125 -0
  198. package/src/primitives/Input.astro +86 -0
  199. package/src/primitives/Label.astro +50 -0
  200. package/src/primitives/Link.astro +81 -0
  201. package/src/primitives/LinkButton.astro +66 -0
  202. package/src/primitives/List.astro +39 -0
  203. package/src/primitives/ListItem.astro +178 -0
  204. package/src/primitives/MediaObject.astro +66 -0
  205. package/src/primitives/MetricCard.astro +278 -0
  206. package/src/primitives/NavLink.astro +81 -0
  207. package/src/primitives/NavMenu.astro +109 -0
  208. package/src/primitives/Navbar.astro +197 -0
  209. package/src/primitives/Panel.astro +153 -0
  210. package/src/primitives/Picture.astro +167 -0
  211. package/src/primitives/Popover.astro +95 -0
  212. package/src/primitives/Prose.astro +45 -0
  213. package/src/primitives/Radio.astro +21 -0
  214. package/src/primitives/Rating.astro +135 -0
  215. package/src/primitives/ReducedMotion.astro +90 -0
  216. package/src/primitives/SegmentedControl.astro +132 -0
  217. package/src/primitives/Select.astro +109 -0
  218. package/src/primitives/Sheet.astro +45 -0
  219. package/src/primitives/SkipLink.astro +31 -0
  220. package/src/primitives/Slider.astro +186 -0
  221. package/src/primitives/Spacer.astro +35 -0
  222. package/src/primitives/Stack.astro +51 -0
  223. package/src/primitives/Surface.astro +70 -0
  224. package/src/primitives/Switch.astro +22 -0
  225. package/src/primitives/Table.astro +382 -0
  226. package/src/primitives/Tabs.astro +126 -0
  227. package/src/primitives/Text.astro +56 -0
  228. package/src/primitives/Textarea.astro +75 -0
  229. package/src/primitives/Thumbnail.astro +154 -0
  230. package/src/primitives/Toggle.astro +99 -0
  231. package/src/primitives/Tooltip.astro +50 -0
  232. package/src/primitives/VisuallyHidden.astro +29 -0
  233. package/src/primitives/index.ts +103 -0
  234. package/src/primitives/internal/AccordionScript.astro +7 -0
  235. package/src/primitives/internal/ChoiceField.astro +91 -0
  236. package/src/primitives/internal/FocusTrapScript.astro +8 -0
  237. package/src/primitives/internal/FormValidationScript.astro +10 -0
  238. package/src/primitives/internal/IndeterminateScript.astro +13 -0
  239. package/src/primitives/internal/ModalPanel.astro +114 -0
  240. package/src/primitives/internal/OverlayScript.astro +7 -0
  241. package/src/primitives/internal/ReducedMotionScript.astro +7 -0
  242. package/src/primitives/internal/SliderScript.astro +7 -0
  243. package/src/primitives/internal/SparklineScript.astro +7 -0
  244. package/src/primitives/internal/TableSortScript.astro +7 -0
  245. package/src/primitives/internal/TabsScript.astro +7 -0
  246. package/src/primitives/internal/TooltipScript.astro +7 -0
  247. package/src/primitives/internal/image-plan.ts +82 -0
  248. package/src/primitives/internal/image.ts +129 -0
  249. package/src/primitives/internal/slider.ts +170 -0
  250. package/src/primitives/lib/deprecate.ts +47 -0
  251. package/src/primitives/lib/focus-trap.ts +197 -0
  252. package/src/primitives/lib/focus.ts +60 -0
  253. package/src/primitives/lib/motion.ts +68 -0
  254. package/src/primitives/scripts/accordion.ts +123 -0
  255. package/src/primitives/scripts/form-validation.ts +225 -0
  256. package/src/primitives/scripts/overlay.ts +71 -0
  257. package/src/primitives/scripts/reduced-motion.ts +59 -0
  258. package/src/primitives/scripts/slider.ts +150 -0
  259. package/src/primitives/scripts/sparkline.ts +131 -0
  260. package/src/primitives/scripts/table-sort.ts +68 -0
  261. package/src/primitives/scripts/tabs.ts +151 -0
  262. package/src/primitives/scripts/tooltip.ts +28 -0
  263. package/src/primitives/styles/a11y.css +104 -0
  264. package/src/primitives/styles/accordion.css +53 -0
  265. package/src/primitives/styles/breadcrumbs.css +59 -0
  266. package/src/primitives/styles/bullet-list.css +89 -0
  267. package/src/primitives/styles/button.css +237 -0
  268. package/src/primitives/styles/choice.css +164 -0
  269. package/src/primitives/styles/cluster.css +24 -0
  270. package/src/primitives/styles/container.css +19 -0
  271. package/src/primitives/styles/data.css +849 -0
  272. package/src/primitives/styles/disclosure.css +140 -0
  273. package/src/primitives/styles/divider.css +50 -0
  274. package/src/primitives/styles/flex.css +42 -0
  275. package/src/primitives/styles/form.css +241 -0
  276. package/src/primitives/styles/grid.css +36 -0
  277. package/src/primitives/styles/media.css +247 -0
  278. package/src/primitives/styles/nav.css +792 -0
  279. package/src/primitives/styles/overlay.css +362 -0
  280. package/src/primitives/styles/prose.css +146 -0
  281. package/src/primitives/styles/scale.css +175 -0
  282. package/src/primitives/styles/segmented.css +165 -0
  283. package/src/primitives/styles/slider.css +170 -0
  284. package/src/primitives/styles/spacer.css +17 -0
  285. package/src/primitives/styles/stack.css +25 -0
  286. package/src/primitives/styles/surface.css +403 -0
  287. package/src/primitives/styles/tabs.css +223 -0
  288. package/src/primitives/styles/typography.css +144 -0
  289. package/src/primitives/styles/utilities.css +24 -0
  290. package/src/primitives/types.ts +385 -0
  291. package/src/primitives/utils.ts +254 -0
  292. package/src/seo/JSONLD.astro +35 -0
  293. package/src/seo/SEOHead.astro +47 -0
  294. package/src/seo/cms.ts +59 -0
  295. package/src/seo/index.ts +10 -0
  296. package/src/seo/integration.ts +268 -0
  297. package/src/seo/internal/url.ts +68 -0
  298. package/src/seo/lib/jsonld.ts +342 -0
  299. package/src/seo/lib/meta.ts +205 -0
  300. package/src/seo/lib/redirects.ts +293 -0
  301. package/src/seo/lib/robots.ts +33 -0
  302. package/src/seo/lib/rss.ts +98 -0
  303. package/src/seo/lib/sitemap.ts +105 -0
  304. package/src/seo/schema.ts +43 -0
  305. package/src/tokens/base.css +71 -0
  306. package/src/tokens/tokens.css +210 -0
@@ -0,0 +1,114 @@
1
+ ---
2
+ /**
3
+ * @internal Shared markup for Dialog, Drawer and Sheet: a native modal <dialog> with a
4
+ * header (title, description, close button), scrollable body, and optional footer.
5
+ *
6
+ * Opening: any button with `commandfor={id} command="show-modal"`. Closing: the built-in
7
+ * close button, Esc, `command="close"`, `<form method="dialog">`, or a backdrop click when
8
+ * `dismissible="any"`. Focus moves into the dialog on open and back to the trigger on close
9
+ * (native). The page behind is inert.
10
+ */
11
+ import type { ModalPanelProps } from '../types';
12
+ import { uid } from '../utils';
13
+ import OverlayScript from './OverlayScript.astro';
14
+ import '../styles/utilities.css';
15
+ import '../styles/typography.css';
16
+ import '../styles/button.css';
17
+ import '../styles/overlay.css';
18
+
19
+ type Props = ModalPanelProps & {
20
+ placement?: 'center' | 'start' | 'end' | 'top' | 'bottom';
21
+ handle?: boolean;
22
+ contained?: boolean;
23
+ /** Class name added for the specific component (sinn-drawer, sinn-sheet). */
24
+ kindClass?: string;
25
+ };
26
+
27
+ const {
28
+ title,
29
+ hideTitle = false,
30
+ titleLevel = 2,
31
+ description,
32
+ size = 'm',
33
+ role = 'dialog',
34
+ dismissible = role === 'alertdialog' ? 'none' : 'any',
35
+ closeButton = role !== 'alertdialog',
36
+ closeLabel = 'Close',
37
+ footerJustify = 'end',
38
+ placement = 'center',
39
+ handle = false,
40
+ contained = false,
41
+ kindClass,
42
+ id = uid('sinn-dialog'),
43
+ class: className,
44
+ ...rest
45
+ } = Astro.props;
46
+
47
+ // Newer platform attributes go through spreads so type-checking doesn't depend on
48
+ // Astro's DOM typings knowing them yet.
49
+ const dialogAttrs = { closedby: dismissible };
50
+ const closeAttrs = { commandfor: id, command: 'close' };
51
+ const titleId = `${id}-title`;
52
+ const descId = description ? `${id}-desc` : undefined;
53
+ const T = `h${titleLevel}` as 'h2';
54
+ const hasFooter = Astro.slots.has('footer');
55
+ ---
56
+
57
+ <dialog
58
+ id={id}
59
+ class:list={['sinn-dialog', kindClass, className]}
60
+ role={role === 'alertdialog' ? 'alertdialog' : undefined}
61
+ aria-labelledby={titleId}
62
+ aria-describedby={descId}
63
+ {...dialogAttrs}
64
+ data-size={size === 'm' ? undefined : size}
65
+ data-placement={placement === 'center' ? undefined : placement}
66
+ data-contained={contained ? '' : undefined}
67
+ {...rest}
68
+ >
69
+ {handle && <div class="sinn-dialog__handle" aria-hidden="true" />}
70
+ <header class="sinn-dialog__header">
71
+ <div class="sinn-dialog__heading">
72
+ <T id={titleId} class:list={['sinn-dialog__title', { 'sinn-sr-only': hideTitle }]}>{title}</T>
73
+ {
74
+ description && (
75
+ <p id={descId} class="sinn-type sinn-text sinn-dialog__description" data-size="s" data-tone="muted">
76
+ {description}
77
+ </p>
78
+ )
79
+ }
80
+ <slot name="header" />
81
+ </div>
82
+ {
83
+ closeButton && (
84
+ <button
85
+ type="button"
86
+ class="sinn-button sinn-dialog__close"
87
+ data-variant="ghost"
88
+ data-tone="neutral"
89
+ data-size="s"
90
+ data-icon-only
91
+ {...closeAttrs}
92
+ >
93
+ <span class="sinn-button__content">
94
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true">
95
+ <path d="M6 6l12 12M18 6 6 18" />
96
+ </svg>
97
+ <span class="sinn-sr-only">{closeLabel}</span>
98
+ </span>
99
+ </button>
100
+ )
101
+ }
102
+ </header>
103
+ <div class="sinn-dialog__body">
104
+ <slot />
105
+ </div>
106
+ {
107
+ hasFooter && (
108
+ <footer class="sinn-dialog__footer" data-justify={footerJustify === 'end' ? undefined : footerJustify}>
109
+ <slot name="footer" />
110
+ </footer>
111
+ )
112
+ }
113
+ </dialog>
114
+ <OverlayScript />
@@ -0,0 +1,7 @@
1
+ ---
2
+ /** @internal Loaded once per page that renders a Dialog, Drawer or Sheet. ~0.5 KB, mostly feature detection. */
3
+ ---
4
+
5
+ <script>
6
+ import '../scripts/overlay';
7
+ </script>
@@ -0,0 +1,7 @@
1
+ ---
2
+ /** @internal Loaded once per page that renders a ReducedMotion region. ~0.8 KB. */
3
+ ---
4
+
5
+ <script>
6
+ import '../scripts/reduced-motion';
7
+ </script>
@@ -0,0 +1,7 @@
1
+ ---
2
+ /** @internal Loaded once per page that renders a Slider. ~2 KB: fill, readout, formatted value, range clamping. */
3
+ ---
4
+
5
+ <script>
6
+ import '../scripts/slider';
7
+ </script>
@@ -0,0 +1,7 @@
1
+ ---
2
+ /** @internal Loaded once per page that renders an interactive MetricCard sparkline. ~1 KB. */
3
+ ---
4
+
5
+ <script>
6
+ import '../scripts/sparkline';
7
+ </script>
@@ -0,0 +1,7 @@
1
+ ---
2
+ /** @internal Loaded once per page that renders a Table with sortable="client". ~1 KB. */
3
+ ---
4
+
5
+ <script>
6
+ import '../scripts/table-sort';
7
+ </script>
@@ -0,0 +1,7 @@
1
+ ---
2
+ /** @internal Loaded once per page that renders Tabs. ~1.4 KB: upgrades in-page links to ARIA tabs. */
3
+ ---
4
+
5
+ <script>
6
+ import '../scripts/tabs';
7
+ </script>
@@ -0,0 +1,7 @@
1
+ ---
2
+ /** @internal Loaded once per page that renders a Tooltip. ~300 B: Esc-to-dismiss. */
3
+ ---
4
+
5
+ <script>
6
+ import '../scripts/tooltip';
7
+ </script>
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Pure planning for responsive images: which widths to generate, the `sizes` hint, and the
3
+ * width/height attributes that reserve space (CLS ≈ 0). No Astro imports, so it's unit-testable;
4
+ * `image.ts` feeds the plan to Astro's getImage().
5
+ */
6
+
7
+ export type Aspect = 'auto' | '1/1' | '4/3' | '3/2' | '16/9' | '21/9' | '3/4' | '2/3' | '4/5';
8
+
9
+ /**
10
+ * - `constrained`: shown at up to `width` CSS px, shrinking with its container (the default).
11
+ * - `full`: spans the viewport (heroes, banners).
12
+ * - `fixed`: always exactly `width` px (avatars, logos); 1x and 2x densities.
13
+ */
14
+ export type ImageLayout = 'constrained' | 'full' | 'fixed';
15
+
16
+ /** Common device/layout widths; candidates for srcset. */
17
+ export const BREAKPOINTS = [320, 480, 640, 768, 960, 1280, 1600, 1920, 2560] as const;
18
+
19
+ export interface ImagePlanInput {
20
+ /** Intrinsic size of the source file. */
21
+ sourceWidth: number;
22
+ sourceHeight: number;
23
+ /** Largest CSS width it will be displayed at. Default: the source width (capped at 1280 for constrained). */
24
+ width?: number;
25
+ aspect?: Aspect;
26
+ layout?: ImageLayout;
27
+ /** Explicit sizes attribute; overrides the computed one. */
28
+ sizes?: string;
29
+ /**
30
+ * Lazy images get `sizes="auto, …"`: browsers that support it use the image's real laid-out
31
+ * width (a 286px grid cell gets a ~300w file, not the 800w maximum); others fall back to the hint.
32
+ */
33
+ lazy?: boolean;
34
+ }
35
+
36
+ export interface ImagePlan {
37
+ /** Width for the `src` fallback. */
38
+ width: number;
39
+ /** width/height attributes (aspect applied), so the browser reserves the box before load. */
40
+ attrWidth: number;
41
+ attrHeight: number;
42
+ /** Widths to generate for a `w` srcset (constrained/full). */
43
+ widths?: number[];
44
+ /** Densities for an `x` srcset (fixed). */
45
+ densities?: number[];
46
+ sizes?: string;
47
+ }
48
+
49
+ export function ratioOf(aspect: Aspect | undefined, fallback: number): number {
50
+ if (!aspect || aspect === 'auto') return fallback;
51
+ const [a, b] = aspect.split('/').map(Number);
52
+ return a > 0 && b > 0 ? a / b : fallback;
53
+ }
54
+
55
+ export function planImage(input: ImagePlanInput): ImagePlan {
56
+ const { sourceWidth, sourceHeight, aspect, layout = 'constrained' } = input;
57
+ if (!(sourceWidth > 0) || !(sourceHeight > 0)) throw new Error('planImage: source dimensions must be positive');
58
+
59
+ const defaultWidth = layout === 'constrained' ? Math.min(sourceWidth, 1280) : sourceWidth;
60
+ // Never upscale.
61
+ const width = Math.min(Math.round(input.width ?? defaultWidth), sourceWidth);
62
+ const ratio = ratioOf(aspect, sourceWidth / sourceHeight);
63
+ const attrWidth = width;
64
+ const attrHeight = Math.round(width / ratio);
65
+
66
+ if (layout === 'fixed') {
67
+ // 2x only if the source can actually provide it.
68
+ const densities = sourceWidth >= width * 2 ? [1, 2] : [1];
69
+ return { width, attrWidth, attrHeight, densities, sizes: input.sizes };
70
+ }
71
+
72
+ const cap = layout === 'full' ? sourceWidth : Math.min(sourceWidth, width * 2);
73
+ const set = new Set<number>(BREAKPOINTS.filter((bp) => bp < cap));
74
+ set.add(Math.min(width, sourceWidth));
75
+ set.add(cap);
76
+ const widths = [...set].filter((w) => w > 0).sort((a, b) => a - b);
77
+
78
+ const hint = layout === 'full' ? '100vw' : `(min-width: ${width}px) ${width}px, 100vw`;
79
+ const sizes = input.sizes ?? (input.lazy ? `auto, ${hint}` : hint);
80
+
81
+ return { width, attrWidth, attrHeight, widths, sizes };
82
+ }
@@ -0,0 +1,129 @@
1
+ /**
2
+ * Bridges planImage() to Astro's image service. Imports `astro:assets`, so it runs only
3
+ * inside an Astro build (it's used by Image, Picture and Thumbnail at render time).
4
+ */
5
+ import { getImage } from 'astro:assets';
6
+ import type { ImageMetadata } from 'astro';
7
+ import { planImage, type Aspect, type ImageLayout } from './image-plan';
8
+
9
+ export type ImageSource = ImageMetadata | string;
10
+ export type ImageFormat = 'avif' | 'webp' | 'jpeg' | 'jpg' | 'png' | 'svg';
11
+ export type ImageQuality = 'low' | 'mid' | 'high' | 'max' | number;
12
+
13
+ export interface ImageSetOptions {
14
+ src: ImageSource;
15
+ /** Required for remote (string) images unless `inferSize`. */
16
+ width?: number;
17
+ height?: number;
18
+ aspect?: Aspect;
19
+ layout?: ImageLayout;
20
+ sizes?: string;
21
+ format?: ImageFormat;
22
+ quality?: ImageQuality;
23
+ /** Remote images: fetch the file to read its size (slower builds). */
24
+ inferSize?: boolean;
25
+ /** Focus point when cropping to `aspect`. */
26
+ position?: 'center' | 'top' | 'bottom' | 'start' | 'end';
27
+ /**
28
+ * Largest CSS width it's shown at, when `width` describes the file (remote images).
29
+ * For local images `width` already means display width.
30
+ */
31
+ displayWidth?: number;
32
+ /** Rendered with loading="lazy" (enables sizes="auto"). */
33
+ lazy?: boolean;
34
+ }
35
+
36
+ /** Art-direction source for Picture. */
37
+ export interface PictureSource {
38
+ /** Media query, e.g. '(max-width: 40rem)'. */
39
+ media: string;
40
+ src: ImageSource;
41
+ width?: number;
42
+ height?: number;
43
+ displayWidth?: number;
44
+ aspect?: Aspect;
45
+ sizes?: string;
46
+ }
47
+
48
+ export interface ImageSet {
49
+ src: string;
50
+ srcset?: string;
51
+ sizes?: string;
52
+ width: number;
53
+ height: number;
54
+ type?: string;
55
+ }
56
+
57
+ const MIME: Record<string, string> = {
58
+ avif: 'image/avif',
59
+ webp: 'image/webp',
60
+ jpeg: 'image/jpeg',
61
+ jpg: 'image/jpeg',
62
+ png: 'image/png',
63
+ svg: 'image/svg+xml',
64
+ };
65
+
66
+ async function sourceSize(o: ImageSetOptions): Promise<{ w: number; h: number }> {
67
+ if (typeof o.src !== 'string') return { w: o.src.width, h: o.src.height };
68
+ if (o.width && o.height) return { w: o.width, h: o.height };
69
+ if (o.inferSize) {
70
+ const probe = await getImage({ src: o.src, inferSize: true });
71
+ const w = Number(probe.attributes.width ?? probe.options.width);
72
+ const h = Number(probe.attributes.height ?? probe.options.height);
73
+ if (w && h) return { w, h };
74
+ }
75
+ throw new Error(`Image "${o.src}": remote images need width and height (or inferSize).`);
76
+ }
77
+
78
+ export async function buildImageSet(o: ImageSetOptions): Promise<ImageSet> {
79
+ const { w: sourceWidth, h: sourceHeight } = await sourceSize(o);
80
+ const remote = typeof o.src === 'string';
81
+ // For local files, `width` is the display width; for remote ones it's also the intrinsic width.
82
+ const plan = planImage({
83
+ sourceWidth,
84
+ sourceHeight,
85
+ width: o.displayWidth ?? (remote ? undefined : o.width),
86
+ aspect: o.aspect,
87
+ layout: o.layout,
88
+ sizes: o.sizes,
89
+ lazy: o.lazy,
90
+ });
91
+
92
+ // With an aspect, crop the files themselves (fit: cover) so every srcset candidate has the
93
+ // reserved ratio: the box never changes once the image loads, even when art direction
94
+ // swaps sources. Without one, keep the source's proportions.
95
+ const crop = Boolean(o.aspect && o.aspect !== 'auto');
96
+ const POSITION = { center: 'center', top: 'top', bottom: 'bottom', start: 'left', end: 'right' } as const;
97
+ const result = await getImage({
98
+ src: o.src,
99
+ width: plan.width,
100
+ ...(crop
101
+ ? { height: plan.attrHeight, fit: 'cover', position: POSITION[o.position ?? 'center'] }
102
+ : remote
103
+ ? { height: Math.round((plan.width * sourceHeight) / sourceWidth) }
104
+ : {}),
105
+ ...(o.format ? { format: o.format } : {}),
106
+ ...(o.quality !== undefined ? { quality: o.quality } : {}),
107
+ ...(plan.widths ? { widths: plan.widths } : {}),
108
+ ...(plan.densities && plan.densities.length > 1 ? { densities: plan.densities } : {}),
109
+ });
110
+
111
+ return {
112
+ src: result.src,
113
+ srcset: result.srcSet?.attribute || undefined,
114
+ sizes: plan.densities ? undefined : plan.sizes,
115
+ width: plan.attrWidth,
116
+ height: plan.attrHeight,
117
+ type: o.format ? MIME[o.format] : undefined,
118
+ };
119
+ }
120
+
121
+ /** Default fallback format for <Picture>: keep PNG (transparency), otherwise JPEG. */
122
+ export function fallbackFormatFor(src: ImageSource): ImageFormat {
123
+ if (typeof src !== 'string') {
124
+ if (src.format === 'svg') return 'svg';
125
+ if (src.format === 'png' || src.format === 'gif') return 'png';
126
+ return 'jpg';
127
+ }
128
+ return /\.png($|\?)/i.test(src) ? 'png' : 'jpg';
129
+ }
@@ -0,0 +1,170 @@
1
+ /**
2
+ * Slider model: snaps and clamps values, works out track positions and formatted text.
3
+ * Pure (no DOM), shared by Slider.astro and the tests. The client script only re-runs the
4
+ * small parts it needs (snap, pct, text) as the thumbs move.
5
+ */
6
+ import type { ValueFormat } from '../types';
7
+ import { formatValue } from '../utils';
8
+
9
+ export interface SliderMarkInput {
10
+ value: number;
11
+ /** Text under the track. Omit for a tick with no label. */
12
+ label?: string;
13
+ }
14
+
15
+ export interface SliderInput {
16
+ min?: number;
17
+ max?: number;
18
+ step?: number;
19
+ /** One number for a single thumb, two for a range. */
20
+ value?: number | readonly [number, number];
21
+ /** Range only: the smallest allowed distance between the thumbs, in steps. */
22
+ minGap?: number;
23
+ format?: ValueFormat;
24
+ locale?: string;
25
+ /**
26
+ * `true`: label the two ends. An array: ticks at those values (with optional labels).
27
+ * Values outside min–max are dropped.
28
+ */
29
+ marks?: boolean | ReadonlyArray<number | SliderMarkInput>;
30
+ }
31
+
32
+ export interface SliderMark {
33
+ value: number;
34
+ /** Position along the track, 0–100. */
35
+ pct: number;
36
+ /** Whole-number position for the data-pct label rule. */
37
+ pctRound: number;
38
+ label?: string;
39
+ /** Inside the selected part of the track (drawn in the fill color). */
40
+ active: boolean;
41
+ /** Labels at the ends hug the edge instead of centering past it. */
42
+ edge?: 'start' | 'end';
43
+ }
44
+
45
+ export interface SliderModel {
46
+ range: boolean;
47
+ min: number;
48
+ max: number;
49
+ step: number;
50
+ /** Snapped, clamped, ordered. One value, or [low, high]. */
51
+ values: number[];
52
+ /** Thumb positions, 0–100. */
53
+ pcts: number[];
54
+ /** Formatted values, for aria-valuetext and the readout. */
55
+ texts: string[];
56
+ /** The visible readout: "$20" or "$20 – $80". */
57
+ output: string;
58
+ /** Selected part of the track as [from, to] in percent. A single slider fills from 0. */
59
+ fill: [number, number];
60
+ marks: SliderMark[];
61
+ /** Range only: which thumb is stacked on top (so a thumb parked at an end can still move). */
62
+ top: 'lo' | 'hi';
63
+ minGap: number;
64
+ warnings: string[];
65
+ }
66
+
67
+ /** Decimal places in a step (0.25 → 2), so snapping doesn't produce 0.30000000000000004. */
68
+ export function stepDecimals(step: number): number {
69
+ const s = String(step);
70
+ if (s.includes('e-')) return Number(s.split('e-')[1]);
71
+ return s.includes('.') ? s.split('.')[1].length : 0;
72
+ }
73
+
74
+ export function snap(value: number, min: number, max: number, step: number): number {
75
+ if (!Number.isFinite(value)) return min;
76
+ const d = stepDecimals(step);
77
+ const n = Math.round((Math.min(max, Math.max(min, value)) - min) / step);
78
+ // The highest reachable value may sit below max when (max - min) isn't a multiple of step.
79
+ const last = Math.floor((max - min) / step + 1e-9);
80
+ return Number((min + Math.min(n, last) * step).toFixed(d));
81
+ }
82
+
83
+ export function toPct(value: number, min: number, max: number): number {
84
+ return max === min ? 0 : Math.round(((value - min) / (max - min)) * 1e6) / 1e4;
85
+ }
86
+
87
+ /** The thumb stacked on top: low when it's in the upper half (else it could get stuck at max). */
88
+ export function topThumb(lo: number, min: number, max: number): 'lo' | 'hi' {
89
+ return lo > (min + max) / 2 ? 'lo' : 'hi';
90
+ }
91
+
92
+ /** Readout for a range. The en dash is spaced so "−$20 – $80" stays readable. */
93
+ export function rangeText(a: string, b: string): string {
94
+ return `${a} – ${b}`;
95
+ }
96
+
97
+ export function sliderModel(input: SliderInput): SliderModel {
98
+ const warnings: string[] = [];
99
+ let min = Number(input.min ?? 0);
100
+ let max = Number(input.max ?? 100);
101
+ let step = Number(input.step ?? 1);
102
+ if (!(max > min)) {
103
+ warnings.push(`Slider max (${max}) must be greater than min (${min}).`);
104
+ max = min + 1;
105
+ }
106
+ if (!(step > 0)) {
107
+ warnings.push(`Slider step must be positive; using 1.`);
108
+ step = 1;
109
+ }
110
+ const range = Array.isArray(input.value);
111
+ const minGap = Math.max(0, Math.floor(input.minGap ?? 0));
112
+ const gap = minGap * step;
113
+ if (range && gap > max - min) warnings.push(`minGap (${minGap} steps) is wider than the whole range.`);
114
+
115
+ let values: number[];
116
+ if (range) {
117
+ const [a, b] = input.value as readonly [number, number];
118
+ let lo = snap(Math.min(a, b), min, max, step);
119
+ let hi = snap(Math.max(a, b), min, max, step);
120
+ if (hi - lo < gap) {
121
+ hi = snap(Math.min(max, lo + gap), min, max, step);
122
+ lo = snap(Math.max(min, hi - gap), min, max, step);
123
+ }
124
+ values = [lo, hi];
125
+ } else {
126
+ const v = input.value === undefined ? min + (max - min) / 2 : (input.value as number);
127
+ values = [snap(v, min, max, step)];
128
+ }
129
+
130
+ const pcts = values.map((v) => toPct(v, min, max));
131
+ const fmt = (v: number) => formatValue(v, input.format ?? 'number', input.locale ?? 'en-US');
132
+ const texts = values.map(fmt);
133
+ const fill: [number, number] = range ? [pcts[0], pcts[1]] : [0, pcts[0]];
134
+
135
+ const raw: SliderMarkInput[] =
136
+ input.marks === true
137
+ ? [{ value: min, label: fmt(min) }, { value: max, label: fmt(max) }]
138
+ : Array.isArray(input.marks)
139
+ ? input.marks.map((m) => (typeof m === 'number' ? { value: m, label: fmt(m) } : m))
140
+ : [];
141
+ const marks: SliderMark[] = raw
142
+ .filter((m) => Number.isFinite(m.value) && m.value >= min && m.value <= max)
143
+ .map((m) => {
144
+ const pct = toPct(m.value, min, max);
145
+ return {
146
+ value: m.value,
147
+ pct,
148
+ pctRound: Math.round(pct),
149
+ label: m.label,
150
+ active: m.value >= (range ? values[0] : min) && m.value <= values[values.length - 1],
151
+ edge: pct <= 2 ? 'start' : pct >= 98 ? 'end' : undefined,
152
+ };
153
+ });
154
+
155
+ return {
156
+ range,
157
+ min,
158
+ max,
159
+ step,
160
+ values,
161
+ pcts,
162
+ texts,
163
+ output: range ? rangeText(texts[0], texts[1]) : texts[0],
164
+ fill,
165
+ marks,
166
+ top: range ? topThumb(values[0], min, max) : 'hi',
167
+ minGap,
168
+ warnings,
169
+ };
170
+ }
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Deprecated prop names and values.
3
+ *
4
+ * When the vocabulary changes, the old name keeps working for at least one minor release: it is
5
+ * mapped to the new one here and a warning is logged once per message in development (never in
6
+ * production builds). The rendered HTML is identical whichever name is used.
7
+ *
8
+ * The current vocabulary and every rename are listed under "Prop vocabulary" in the primitives
9
+ * README.
10
+ */
11
+
12
+ const seen = new Set<string>();
13
+
14
+ /** Log a development-only warning, once per component and message. */
15
+ export function warnOnce(component: string, message: string): void {
16
+ const key = `${component}\u0000${message}`;
17
+ if (seen.has(key)) return;
18
+ seen.add(key);
19
+ if (import.meta.env?.DEV) console.warn(`[${component}] ${message}`);
20
+ }
21
+
22
+ /**
23
+ * Map a deprecated value to its replacement. Values not in `renames` pass through unchanged.
24
+ *
25
+ * @example
26
+ * const v = renameValue('Tabs', 'variant', variant, { pills: 'pill' });
27
+ */
28
+ export function renameValue<T>(component: string, prop: string, value: T, renames: Readonly<Record<string, string>>): T {
29
+ if (typeof value === 'string' && Object.prototype.hasOwnProperty.call(renames, value)) {
30
+ const next = renames[value];
31
+ warnOnce(component, `${prop}="${value}" is deprecated; use ${prop}="${next}".`);
32
+ return next as T;
33
+ }
34
+ return value;
35
+ }
36
+
37
+ /**
38
+ * Read a renamed prop: the new name wins; the old name is used (with a warning) when only it is set.
39
+ *
40
+ * @example
41
+ * const columns = renameProp('Grid', 'columns', props.columns, 'cols', props.cols);
42
+ */
43
+ export function renameProp<T>(component: string, name: string, value: T | undefined, oldName: string, oldValue: T | undefined): T | undefined {
44
+ if (oldValue === undefined) return value;
45
+ warnOnce(component, `\`${oldName}\` is deprecated; use \`${name}\`.`);
46
+ return value ?? oldValue;
47
+ }