@atelic-action/ui 7.1.0 → 8.0.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 (105) hide show
  1. package/README.md +313 -127
  2. package/package.json +14 -10
  3. package/src/app/ErrorFallback.tsx +6 -2
  4. package/src/app/context/AppContext.tsx +10 -1
  5. package/src/app/index.ts +0 -1
  6. package/src/app/layout/AppPage.tsx +36 -7
  7. package/src/app/layout/DesktopRail.tsx +9 -2
  8. package/src/app/layout/MobileMenu.tsx +5 -1
  9. package/src/app/layout/PageError.tsx +6 -3
  10. package/src/app/layout/PageSkeleton.tsx +33 -26
  11. package/src/app/layout/UserMenu.tsx +12 -6
  12. package/src/app/ui/alert.tsx +41 -11
  13. package/src/app/ui/badge.tsx +1 -1
  14. package/src/app/ui/button.tsx +2 -1
  15. package/src/app/ui/command.tsx +86 -21
  16. package/src/app/ui/country-dropdown.tsx +26 -47
  17. package/src/app/ui/form.tsx +46 -7
  18. package/src/app/ui/pagination.tsx +1 -1
  19. package/src/app/ui/progress.tsx +26 -12
  20. package/src/app/ui/search-input.tsx +16 -3
  21. package/src/app/ui/select.tsx +8 -3
  22. package/src/app/ui/slider.tsx +62 -15
  23. package/src/artifact/ArtifactShell.tsx +8 -3
  24. package/src/artifact/ErrorFallback.tsx +8 -1
  25. package/src/artifact/artifactConfig.ts +1 -1
  26. package/src/chrome/BrandLockup.tsx +71 -16
  27. package/src/chrome/ClosingBar.tsx +8 -5
  28. package/src/chrome/ContactDock.tsx +329 -0
  29. package/src/chrome/Footer.tsx +32 -9
  30. package/src/chrome/NavBadge.tsx +8 -0
  31. package/src/chrome/NavMegaPanel.tsx +388 -0
  32. package/src/chrome/SiteHeader.tsx +235 -18
  33. package/src/chrome/SiteMenu.tsx +197 -19
  34. package/src/chrome/SiteShell.tsx +130 -13
  35. package/src/chrome/StickyCTABar.tsx +56 -2
  36. package/src/chrome/brandMark.ts +56 -0
  37. package/src/chrome/icons.ts +58 -0
  38. package/src/chrome/index.ts +16 -0
  39. package/src/chrome/navSections.ts +55 -0
  40. package/src/components/ColumnChart.tsx +27 -2
  41. package/src/components/DataTable.tsx +104 -85
  42. package/src/components/Disclosure.tsx +3 -1
  43. package/src/components/Hint.tsx +3 -24
  44. package/src/components/NotFound.tsx +4 -1
  45. package/src/components/StarRating.tsx +45 -19
  46. package/src/components/ThresholdScale.tsx +36 -26
  47. package/src/email/atoms.tsx +13 -57
  48. package/src/email/frame.tsx +4 -6
  49. package/src/email/index.ts +4 -10
  50. package/src/email/scoreboard.tsx +107 -186
  51. package/src/email/text.ts +30 -0
  52. package/src/email/theme.tsx +76 -9
  53. package/src/hooks/useDismiss.ts +39 -0
  54. package/src/lib/useScrollsSideways.ts +26 -0
  55. package/src/primitives/Button.tsx +2 -0
  56. package/src/primitives/ProseBlocks.tsx +6 -1
  57. package/src/primitives/SectionHeading.tsx +3 -1
  58. package/src/primitives/StarRow.tsx +23 -8
  59. package/src/sections/BlogIndex.tsx +17 -3
  60. package/src/sections/BlogPost.tsx +10 -1
  61. package/src/sections/CTASection.tsx +2 -2
  62. package/src/sections/CalloutPanel.tsx +34 -0
  63. package/src/sections/ComparisonTable.tsx +23 -2
  64. package/src/sections/ContactForm.tsx +61 -17
  65. package/src/sections/FAQBrowser.tsx +11 -2
  66. package/src/sections/FeatureGrid.tsx +6 -2
  67. package/src/sections/FullBleedVideo.tsx +158 -0
  68. package/src/sections/Gallery.tsx +6 -4
  69. package/src/sections/Hero.tsx +63 -39
  70. package/src/sections/JumpRail.tsx +7 -0
  71. package/src/sections/LegalPage.tsx +10 -2
  72. package/src/sections/LinkColumns.tsx +64 -0
  73. package/src/sections/LocationSection.tsx +28 -5
  74. package/src/sections/Locations.tsx +17 -4
  75. package/src/sections/LogoMarquee.tsx +43 -11
  76. package/src/sections/MapEmbed.tsx +13 -9
  77. package/src/sections/PageHero.tsx +16 -2
  78. package/src/sections/ProcessSteps.tsx +27 -4
  79. package/src/sections/ProfileCards.tsx +12 -2
  80. package/src/sections/ProofStrip.tsx +44 -0
  81. package/src/sections/RevealSlider.tsx +28 -7
  82. package/src/sections/ReviewCarousel.tsx +17 -4
  83. package/src/sections/ReviewWall.tsx +2 -2
  84. package/src/sections/SplitSection.tsx +2 -1
  85. package/src/sections/index.ts +15 -6
  86. package/src/sections/siteConfig.ts +66 -3
  87. package/src/styles/app.css +24 -2
  88. package/src/styles/artifact.css +20 -8
  89. package/src/styles/base.css +42 -13
  90. package/src/styles/chrome.css +938 -48
  91. package/src/styles/components.css +104 -65
  92. package/src/styles/defaults.css +137 -0
  93. package/src/styles/gate.css +21 -10
  94. package/src/styles/primitives.css +97 -35
  95. package/src/styles/sections.css +477 -437
  96. package/src/styles/star-rating.css +1 -4
  97. package/src/tokens/palettes.ts +24 -4
  98. package/src/types.ts +212 -2
  99. package/src/app/CardErrorBoundary.tsx +0 -39
  100. package/src/sections/CTABanner.tsx +0 -93
  101. package/src/sections/DeviceShowcase.tsx +0 -39
  102. package/src/sections/MediaBand.tsx +0 -20
  103. package/src/sections/MenuList.tsx +0 -44
  104. package/src/sections/PressQuotes.tsx +0 -51
  105. package/src/sections/SocialStrip.tsx +0 -83
@@ -20,8 +20,6 @@ export {
20
20
  type ListProps,
21
21
  ListRow,
22
22
  type ListRowProps,
23
- MonoTable,
24
- type MonoTableProps,
25
23
  Note,
26
24
  type NoteProps,
27
25
  Row,
@@ -62,22 +60,14 @@ export {
62
60
  type RecordsCell,
63
61
  type RecordsColumn,
64
62
  type RecordsProps,
65
- RecordTimelineLegend,
66
- type RecordTimelineLegendProps,
67
63
  RecordTimelineStrip,
68
64
  type RecordTimelineStripProps,
69
65
  Scoreboard,
70
66
  type ScoreboardProps,
71
- StatStrip,
72
- type StatStripEntry,
73
- type StatStripProps,
74
67
  SubEyebrow,
75
68
  type SubEyebrowProps,
76
69
  TargetRow,
77
70
  type TargetRowProps,
78
- WhatMoved,
79
- type WhatMovedItem,
80
- type WhatMovedProps,
81
71
  } from "./scoreboard";
82
72
  export {
83
73
  asciiDowncase,
@@ -91,6 +81,7 @@ export {
91
81
  type RecordTimeline,
92
82
  recordBadges,
93
83
  recordStackText,
84
+ recordTimelineSummary,
94
85
  recordTimelineText,
95
86
  rpad,
96
87
  spaces,
@@ -106,9 +97,12 @@ export {
106
97
  wrap,
107
98
  } from "./text";
108
99
  export {
100
+ accentInk,
101
+ contrastRatio,
109
102
  type EmailTheme,
110
103
  EmailThemeProvider,
111
104
  type EmailThemeProviderProps,
112
105
  eyebrowStyle,
113
106
  useEmailTheme,
107
+ wrapLong,
114
108
  } from "./theme";
@@ -6,27 +6,39 @@ import {
6
6
  type RecordStackItem,
7
7
  type RecordTimeline,
8
8
  recordBadges,
9
+ recordTimelineSummary,
9
10
  } from "./text";
10
- import { eyebrowStyle, tableReset, useEmailTheme } from "./theme";
11
+ import { accentInk, eyebrowStyle, tableReset, useEmailTheme, wrapLong } from "./theme";
11
12
 
12
13
  /*
13
14
  * The scoreboard pieces, ported one to one from the scoreboard section of
14
15
  * homebase `runners/lib/email.jq`. The accent marks a shortfall and nothing
15
- * else a row says.
16
+ * else a row says; where the mark is words it is set in the accent's ink
17
+ * (`accentInk`), since the bright accent fails as small words.
16
18
  */
17
19
 
18
- export type BarProps = { logged: number; target: number };
20
+ export type BarProps = {
21
+ logged: number;
22
+ target: number;
23
+ /**
24
+ * What a screen reader hears for the bar, which has no words of its own.
25
+ * Defaults to "<logged> of <target>". `false` draws it as decoration,
26
+ * for a bar beside a count that already says it (as in `TargetRow`).
27
+ */
28
+ label?: string | false;
29
+ };
19
30
 
20
31
  /**
21
32
  * A segmented bar, one segment per unit of the target, filled up to what was
22
33
  * logged. Wider segments for small targets so three reads as three.
23
34
  */
24
- export function Bar({ logged, target }: BarProps) {
35
+ export function Bar({ logged, target, label }: BarProps) {
25
36
  const { palette } = useEmailTheme();
26
37
  const w = target <= 3 ? "18" : "10";
27
38
  const filled = Math.min(logged, target);
39
+ const name = label === false ? null : (label ?? `${logged} of ${target}`);
28
40
  return (
29
- <table {...tableReset}>
41
+ <table {...tableReset} {...(name === null ? {} : { role: "img", "aria-label": name })}>
30
42
  <tbody>
31
43
  <tr>
32
44
  {Array.from({ length: target }, (_, i) => (
@@ -68,7 +80,7 @@ export function GroupRow({ text, first }: GroupRowProps) {
68
80
  style={{
69
81
  padding: `${first ? "0" : "18px"} 0 6px`,
70
82
  ...eyebrowStyle(fonts),
71
- color: palette.accent,
83
+ color: accentInk(palette),
72
84
  borderBottom: `1px solid ${palette.line}`,
73
85
  }}
74
86
  >
@@ -103,7 +115,7 @@ export function TargetRow({ text, logged, target, note, last }: TargetRowProps)
103
115
  ...rule,
104
116
  fontFamily: fonts.mono,
105
117
  fontSize: "13px",
106
- color: short ? palette.accent : palette.ink,
118
+ color: short ? accentInk(palette) : palette.ink,
107
119
  whiteSpace: "nowrap",
108
120
  }}
109
121
  >
@@ -111,7 +123,9 @@ export function TargetRow({ text, logged, target, note, last }: TargetRowProps)
111
123
  {target === null ? null : ` / ${target}`}
112
124
  </td>
113
125
  <td width="84" style={{ padding: "10px 0 10px 16px", ...rule }}>
114
- {target === null || target === 0 ? null : <Bar logged={logged} target={target} />}
126
+ {target === null || target === 0 ? null : (
127
+ <Bar logged={logged} target={target} label={false} />
128
+ )}
115
129
  </td>
116
130
  <td
117
131
  align="right"
@@ -143,50 +157,6 @@ export function Scoreboard({ children }: ScoreboardProps) {
143
157
  );
144
158
  }
145
159
 
146
- export type WhatMovedItem = { subject: string; event: string };
147
- export type WhatMovedProps = { items: WhatMovedItem[]; note?: string };
148
-
149
- /** The note bar on the cream ground under the scoreboard. */
150
- export function WhatMoved({ items, note }: WhatMovedProps) {
151
- const { palette, fonts } = useEmailTheme();
152
- return (
153
- <tr>
154
- <td style={{ padding: "22px 26px 26px" }}>
155
- <table
156
- {...tableReset}
157
- width="100%"
158
- style={{ background: palette.ground, borderRadius: "10px" }}
159
- >
160
- <tbody>
161
- <tr>
162
- <td
163
- style={{
164
- padding: "16px 18px",
165
- fontFamily: fonts.sans,
166
- fontSize: "14px",
167
- lineHeight: "1.6",
168
- color: palette.ink,
169
- }}
170
- >
171
- <span style={{ ...eyebrowStyle(fonts), color: palette.faint }}>What Moved</span>
172
- <br />
173
- {items.map((item, i) => (
174
- // biome-ignore lint/suspicious/noArrayIndexKey: an item's position is its identity
175
- <Fragment key={i}>
176
- <b style={{ fontWeight: "600" }}>{item.subject}</b> {item.event}
177
- <br />
178
- </Fragment>
179
- ))}
180
- {note ? <span style={{ color: palette.dim }}>{note}</span> : null}
181
- </td>
182
- </tr>
183
- </tbody>
184
- </table>
185
- </td>
186
- </tr>
187
- );
188
- }
189
-
190
160
  export type ReadBlockProps = { text: string; divider: boolean };
191
161
 
192
162
  /** A model written read at the top of a section card. */
@@ -198,10 +168,11 @@ export function ReadBlock({ text, divider }: ReadBlockProps) {
198
168
  style={{
199
169
  padding: "22px 24px 20px",
200
170
  fontFamily: fonts.sans,
171
+ ...wrapLong,
201
172
  ...(divider ? { borderBottom: `1px solid ${palette.line}` } : {}),
202
173
  }}
203
174
  >
204
- <span style={{ ...eyebrowStyle(fonts), color: palette.accent }}>The Read</span>
175
+ <span style={{ ...eyebrowStyle(fonts), color: accentInk(palette) }}>The Read</span>
205
176
  <div
206
177
  style={{
207
178
  fontSize: "15px",
@@ -231,13 +202,26 @@ export function SubEyebrow({ text }: SubEyebrowProps) {
231
202
  );
232
203
  }
233
204
 
234
- export type BadgeProps = { letter: string };
205
+ export type BadgeProps = {
206
+ letter: string;
207
+ /**
208
+ * What the letter stands for ("Social"), read by a screen reader in the
209
+ * letter's place and shown as a tooltip. Without it a reader hears the
210
+ * letter alone.
211
+ */
212
+ label?: string;
213
+ };
235
214
 
236
- /** A single letter in a hairline box after the word it tags (S for social). */
237
- export function Badge({ letter }: BadgeProps) {
215
+ /**
216
+ * A single letter in a hairline box after the word it tags (S for social),
217
+ * letter and box in the accent's ink: the bright accent fails as words.
218
+ */
219
+ export function Badge({ letter, label }: BadgeProps) {
238
220
  const { palette, fonts } = useEmailTheme();
221
+ const ink = accentInk(palette);
239
222
  return (
240
223
  <span
224
+ {...(label ? { role: "img", "aria-label": label, title: label } : {})}
241
225
  style={{
242
226
  display: "inline-block",
243
227
  fontFamily: fonts.mono,
@@ -245,9 +229,9 @@ export function Badge({ letter }: BadgeProps) {
245
229
  lineHeight: "12px",
246
230
  width: "12px",
247
231
  textAlign: "center",
248
- border: `1px solid ${palette.accent}`,
232
+ border: `1px solid ${ink}`,
249
233
  borderRadius: "3px",
250
- color: palette.accent,
234
+ color: ink,
251
235
  verticalAlign: "1px",
252
236
  marginLeft: "3px",
253
237
  }}
@@ -257,7 +241,13 @@ export function Badge({ letter }: BadgeProps) {
257
241
  );
258
242
  }
259
243
 
260
- export type DayEntry = { name: string; strong?: boolean; badge?: string };
244
+ export type DayEntry = {
245
+ name: string;
246
+ strong?: boolean;
247
+ badge?: string;
248
+ /** What the badge's letter stands for; see `Badge`'s `label`. */
249
+ badgeLabel?: string;
250
+ };
261
251
  export type Day = { label: string; entries: DayEntry[] };
262
252
  export type DayStripProps = { days: Day[]; last: boolean };
263
253
 
@@ -302,6 +292,7 @@ export function DayStrip({ days, last }: DayStripProps) {
302
292
  padding: "8px 2px",
303
293
  borderTop: `2px solid ${palette.ink}`,
304
294
  verticalAlign: "top",
295
+ ...wrapLong,
305
296
  }}
306
297
  >
307
298
  {day.entries.map((entry, e) => (
@@ -311,12 +302,16 @@ export function DayStrip({ days, last }: DayStripProps) {
311
302
  {entry.strong ? (
312
303
  <b style={{ color: palette.ink, fontWeight: "600" }}>
313
304
  {entry.name}
314
- {entry.badge ? <Badge letter={entry.badge} /> : null}
305
+ {entry.badge ? (
306
+ <Badge letter={entry.badge} label={entry.badgeLabel} />
307
+ ) : null}
315
308
  </b>
316
309
  ) : (
317
310
  <>
318
311
  {entry.name}
319
- {entry.badge ? <Badge letter={entry.badge} /> : null}
312
+ {entry.badge ? (
313
+ <Badge letter={entry.badge} label={entry.badgeLabel} />
314
+ ) : null}
320
315
  </>
321
316
  )}
322
317
  </Fragment>
@@ -331,102 +326,17 @@ export function DayStrip({ days, last }: DayStripProps) {
331
326
  );
332
327
  }
333
328
 
334
- export type StatStripEntry = {
335
- n: string | number;
336
- label: string;
337
- /**
338
- * A change beside the number, small under the label: "+3 (12%)". One that
339
- * opens on "+" wears the palette's `up`, one that opens on "-" its `down`,
340
- * anything else stays muted.
341
- */
342
- delta?: string;
343
- };
344
-
345
- /** The color a delta wears, read off its sign. */
346
- export function deltaColor(delta: string, palette: Palette): string {
347
- if (delta.startsWith("+")) return palette.up ?? atelicPalette.up ?? palette.faint;
348
- if (delta.startsWith("-") || delta.startsWith("\u2212")) {
349
- return palette.down ?? atelicPalette.down ?? palette.faint;
350
- }
351
- return palette.faint;
352
- }
353
- export type StatStripProps = { stats: StatStripEntry[] };
354
-
355
- /**
356
- * A strip of big numbers over eyebrow labels. Each stat is an inline block
357
- * cell with a floor on its width inside one centered cell, so six or seven
358
- * stats flow onto a second row on a phone instead of shrinking to nothing.
359
- */
360
- export function StatStrip({ stats }: StatStripProps) {
361
- const { palette, fonts } = useEmailTheme();
362
- const share = `${Math.floor(100 / Math.max(stats.length, 1))}%`;
363
- return (
364
- <table {...tableReset} width="100%">
365
- <tbody>
366
- <tr>
367
- <td align="center" style={{ textAlign: "center" }}>
368
- {stats.map((entry, i) => (
369
- <div
370
- // biome-ignore lint/suspicious/noArrayIndexKey: a stat's position is its identity
371
- key={i}
372
- style={{
373
- display: "inline-block",
374
- width: share,
375
- minWidth: "88px",
376
- boxSizing: "border-box",
377
- verticalAlign: "top",
378
- padding: "12px 6px 10px",
379
- borderTop: `2px solid ${palette.ink}`,
380
- textAlign: "center",
381
- }}
382
- >
383
- <span
384
- style={{
385
- fontFamily: fonts.sans,
386
- fontSize: "22px",
387
- fontWeight: "600",
388
- letterSpacing: "-0.02em",
389
- color: palette.ink,
390
- }}
391
- >
392
- {String(entry.n)}
393
- </span>
394
- <br />
395
- <span style={{ ...eyebrowStyle(fonts), color: palette.faint }}>{entry.label}</span>
396
- {entry.delta ? (
397
- <>
398
- <br />
399
- <span
400
- style={{
401
- fontFamily: fonts.mono,
402
- fontSize: "11px",
403
- color: deltaColor(entry.delta, palette),
404
- }}
405
- >
406
- {entry.delta}
407
- </span>
408
- </>
409
- ) : null}
410
- </div>
411
- ))}
412
- </td>
413
- </tr>
414
- </tbody>
415
- </table>
416
- );
417
- }
418
-
419
329
  type RecordBadgeProps = { text: string; tone?: RecordBadgeTone };
420
330
 
421
331
  /**
422
332
  * The pill on a record's title line. Faint is the stage word as it always
423
333
  * was, dim text in a hairline box; ink and accent are the Company Cards
424
334
  * pills (2026-09-29), bold, drawn in their own color on a heavier border:
425
- * the next touch in ink, New in the accent.
335
+ * the next touch in ink, New in the accent's ink.
426
336
  */
427
337
  function RecordBadge({ text, tone = "faint" }: RecordBadgeProps) {
428
338
  const { palette, fonts } = useEmailTheme();
429
- const color = tone === "ink" ? palette.ink : tone === "accent" ? palette.accent : palette.dim;
339
+ const color = tone === "ink" ? palette.ink : tone === "accent" ? accentInk(palette) : palette.dim;
430
340
  return (
431
341
  <span
432
342
  style={{
@@ -451,16 +361,24 @@ function RecordBadge({ text, tone = "faint" }: RecordBadgeProps) {
451
361
  export type { RecordStackItem };
452
362
 
453
363
  /** The default for a palette written before `warm` existed: the cooling tone between `up` and the accent. */
454
- const WARM = "#B7791F";
364
+ const WARM = "#966319";
455
365
 
456
366
  function asideColor(tone: RecordAsideTone | undefined, palette: Palette): string {
457
367
  if (tone === "up") return palette.up ?? atelicPalette.up ?? palette.ink;
458
368
  if (tone === "warm") return palette.warm ?? WARM;
459
- if (tone === "accent") return palette.accent;
369
+ if (tone === "accent") return accentInk(palette);
460
370
  return palette.faint;
461
371
  }
462
372
 
463
- export type RecordTimelineStripProps = { timeline: RecordTimeline };
373
+ export type RecordTimelineStripProps = {
374
+ timeline: RecordTimeline;
375
+ /**
376
+ * What a screen reader hears for the drawn strip. Defaults to
377
+ * `recordTimelineSummary` of the timeline ("Last 30 days: 2 sends, the
378
+ * latest 3 days ago; 1 open, today").
379
+ */
380
+ label?: string;
381
+ };
464
382
 
465
383
  /**
466
384
  * A record's recent days on one line, today at the right edge: an ink square
@@ -472,7 +390,7 @@ export type RecordTimelineStripProps = { timeline: RecordTimeline };
472
390
  * dozens of records. Nothing is positioned, so it survives every mail client
473
391
  * (Company Cards IA, 2026-09-29).
474
392
  */
475
- export function RecordTimelineStrip({ timeline }: RecordTimelineStripProps) {
393
+ export function RecordTimelineStrip({ timeline, label }: RecordTimelineStripProps) {
476
394
  const { palette, fonts } = useEmailTheme();
477
395
  const days = Math.max(1, Math.round(timeline.days));
478
396
  const touch = new Set(timeline.touches.map((d) => Math.round(d)));
@@ -498,6 +416,8 @@ export function RecordTimelineStrip({ timeline }: RecordTimelineStripProps) {
498
416
  return (
499
417
  <table
500
418
  {...tableReset}
419
+ role="img"
420
+ aria-label={label ?? recordTimelineSummary(timeline)}
501
421
  width="100%"
502
422
  style={{
503
423
  marginTop: "8px",
@@ -554,31 +474,6 @@ export function RecordTimelineStrip({ timeline }: RecordTimelineStripProps) {
554
474
  );
555
475
  }
556
476
 
557
- export type RecordTimelineLegendProps = { days: number };
558
-
559
- /** What the marks on a timeline are, once above a list of records: the square, the dot, and the span. */
560
- export function RecordTimelineLegend({ days }: RecordTimelineLegendProps) {
561
- const { palette, fonts } = useEmailTheme();
562
- const mark = (style: CSSProperties) => (
563
- <span
564
- style={{ display: "inline-block", verticalAlign: "middle", marginRight: "5px", ...style }}
565
- />
566
- );
567
- return (
568
- <div
569
- style={{ fontFamily: fonts.mono, fontSize: "11px", lineHeight: "16px", color: palette.faint }}
570
- >
571
- {mark({ width: "8px", height: "8px", background: palette.ink })}
572
- touch
573
- <span style={{ display: "inline-block", width: "14px" }} />
574
- {mark({ width: "5px", height: "5px", borderRadius: "50%", background: palette.accent })}
575
- open
576
- <span style={{ display: "inline-block", width: "14px" }} />
577
- {`${days} days to today`}
578
- </div>
579
- );
580
- }
581
-
582
477
  export type RecordStackProps = { records: RecordStackItem[] };
583
478
 
584
479
  /**
@@ -719,7 +614,7 @@ export function RecordStack({ records }: RecordStackProps) {
719
614
  color: palette.ink,
720
615
  }}
721
616
  >
722
- <span style={{ ...eyebrowStyle(fonts), color: palette.accent }}>
617
+ <span style={{ ...eyebrowStyle(fonts), color: accentInk(palette) }}>
723
618
  {record.callout.eyebrow}
724
619
  </span>
725
620
  <br />
@@ -739,7 +634,12 @@ export type RecordsColumn = {
739
634
  label: string;
740
635
  /** Aligns the column right and keeps its cells on one line. */
741
636
  right?: boolean;
742
- /** Pixels. A width on any column fixes the table's layout so sibling tables share a grid. */
637
+ /**
638
+ * Pixels at the desktop column's width. A width on any column fixes the
639
+ * table's layout so sibling tables share a grid; each is drawn as its
640
+ * share of the table (see `RECORDS_WIDTH`), so the same grid narrows on
641
+ * a phone instead of holding the table open past it.
642
+ */
743
643
  width?: number;
744
644
  /** Keeps the column even when every row leaves it empty. */
745
645
  keep?: boolean;
@@ -756,6 +656,20 @@ export type RecordsCell = {
756
656
 
757
657
  const hasMarkup = (html: ReactNode): boolean => html !== undefined && html !== null && html !== "";
758
658
 
659
+ /**
660
+ * The width, in pixels, a records table has inside a card's row on a
661
+ * desktop: the 680 column less the card's two border pixels and the row's
662
+ * 24 pixels a side. A column's pixel width is drawn as its share of this, or
663
+ * of the columns' sum when they ask for more, so at the desktop width every
664
+ * column is the pixels it asked for.
665
+ */
666
+ export const RECORDS_WIDTH = 630;
667
+
668
+ /** A column's pixel width as a percentage of the table, two decimals at most. */
669
+ function columnShare(width: number, total: number): string {
670
+ return `${Math.round((width / Math.max(total, RECORDS_WIDTH)) * 10000) / 100}%`;
671
+ }
672
+
759
673
  export type RecordsProps = { columns: RecordsColumn[]; rows: RecordsCell[][] };
760
674
 
761
675
  /**
@@ -772,9 +686,13 @@ export function Records({ columns, rows }: RecordsProps) {
772
686
  rows.some((row) => (row[i]?.value ?? "") !== "" || hasMarkup(row[i]?.html)),
773
687
  );
774
688
  const fixed = columns.some((c) => c.width !== undefined);
689
+ const total = keep.reduce((sum, i) => sum + (columns[i].width ?? 0), 0);
690
+ // A data table, not a layout one: no presentation role, so the header
691
+ // cells name the column a reader is in.
692
+ const { role: _layout, ...reset } = tableReset;
775
693
  return (
776
694
  <table
777
- {...tableReset}
695
+ {...reset}
778
696
  width="100%"
779
697
  style={{
780
698
  ...(fixed ? { tableLayout: "fixed" } : {}),
@@ -788,14 +706,17 @@ export function Records({ columns, rows }: RecordsProps) {
788
706
  <tr>
789
707
  {keep.map((i) => {
790
708
  const c = columns[i];
709
+ const share = c.width !== undefined ? columnShare(c.width, total) : undefined;
791
710
  return (
792
- <td
711
+ <th
793
712
  key={i}
713
+ scope="col"
794
714
  align={c.right ? "right" : "left"}
795
- {...(c.width !== undefined ? { width: String(c.width) } : {})}
715
+ {...(share ? { width: share } : {})}
796
716
  style={{
797
- ...(c.width !== undefined ? { width: `${c.width}px` } : {}),
717
+ ...(share ? { width: share } : {}),
798
718
  padding: "0 8px 6px 0",
719
+ fontWeight: "normal",
799
720
  fontFamily: fonts.mono,
800
721
  fontSize: "10px",
801
722
  letterSpacing: "0.1em",
@@ -806,7 +727,7 @@ export function Records({ columns, rows }: RecordsProps) {
806
727
  }}
807
728
  >
808
729
  {c.label}
809
- </td>
730
+ </th>
810
731
  );
811
732
  })}
812
733
  </tr>
@@ -826,13 +747,13 @@ export function Records({ columns, rows }: RecordsProps) {
826
747
  borderBottom: `1px solid ${r === rows.length - 1 ? palette.line : palette.hair}`,
827
748
  ...(cell.mono ? { fontFamily: fonts.mono, fontSize: "12px" } : {}),
828
749
  color: cell.hot
829
- ? palette.accent
750
+ ? accentInk(palette)
830
751
  : cell.muted
831
752
  ? palette.faint
832
753
  : cell.mono
833
754
  ? palette.dim
834
755
  : palette.ink,
835
- ...(c.right ? { whiteSpace: "nowrap" } : {}),
756
+ ...(c.right ? { whiteSpace: "nowrap" } : wrapLong),
836
757
  }}
837
758
  >
838
759
  {hasHTML ? cell.html : (cell.value ?? "")}
package/src/email/text.ts CHANGED
@@ -192,6 +192,36 @@ export function recordTimelineText(timeline: RecordTimeline): string {
192
192
  return `${days}d [${strip}|]`;
193
193
  }
194
194
 
195
+ /** "today", "yesterday", or "<n> days ago". */
196
+ function daysAgo(ago: number): string {
197
+ if (ago <= 0) return "today";
198
+ if (ago === 1) return "yesterday";
199
+ return `${ago} days ago`;
200
+ }
201
+
202
+ /** "no sends", "1 send, today", "3 sends, the latest 2 days ago". */
203
+ function countedDays(days: number[], one: string, many: string): string {
204
+ if (days.length === 0) return `no ${many}`;
205
+ const latest = daysAgo(Math.min(...days));
206
+ if (days.length === 1) return `1 ${one}, ${latest}`;
207
+ return `${days.length} ${many}, the latest ${latest}`;
208
+ }
209
+
210
+ /**
211
+ * The timeline in words, for a screen reader in place of the drawn strip:
212
+ * "Last 30 days: 2 sends, the latest 3 days ago; 1 open, today". Days are
213
+ * counted once each, as the strip draws them, and a day past the window is
214
+ * left out the same way.
215
+ */
216
+ export function recordTimelineSummary(timeline: RecordTimeline): string {
217
+ const days = Math.max(1, Math.round(timeline.days));
218
+ const within = (list: number[]) =>
219
+ [...new Set(list.map((d) => Math.round(d)))].filter((d) => d >= 0 && d < days);
220
+ const sends = countedDays(within(timeline.touches), "send", "sends");
221
+ const opens = countedDays(within(timeline.opens), "open", "opens");
222
+ return `Last ${days} ${days === 1 ? "day" : "days"}: ${sends}; ${opens}`;
223
+ }
224
+
195
225
  /**
196
226
  * The plain text twin of `RecordStack`: each title on its own line under a
197
227
  * two space indent with every badge after it in square brackets, the
@@ -48,6 +48,14 @@ export function eyebrowStyle(fonts: Fonts): CSSProperties {
48
48
  };
49
49
  }
50
50
 
51
+ /**
52
+ * One long token (a path, an address, a long word) breaks inside its cell
53
+ * instead of holding the cell open and widening the email past a phone. Mail
54
+ * clients honor both inline; `word-break: break-word` is the older spelling
55
+ * some still read.
56
+ */
57
+ export const wrapLong = { overflowWrap: "anywhere", wordBreak: "break-word" } as const;
58
+
51
59
  /** The props every layout table in an email carries. */
52
60
  export const tableReset = {
53
61
  role: "presentation" as const,
@@ -56,12 +64,9 @@ export const tableReset = {
56
64
  border: 0,
57
65
  };
58
66
 
59
- /**
60
- * `#FC4A1A` to `rgba(252,74,26,0)`, the masthead rule's fade out stop. An accent
61
- * that is not a three or six digit hex fades to `transparent` rather than to NaN.
62
- */
63
- export function fadeStop(hex: string): string {
64
- if (!/^#?(?:[0-9a-f]{3}|[0-9a-f]{6})$/i.test(hex)) return "transparent";
67
+ /** `#FC4A1A` or `#f4a` as red, green, and blue, or null for anything that is not a three or six digit hex. */
68
+ function rgb(hex: string): [number, number, number] | null {
69
+ if (!/^#?(?:[0-9a-f]{3}|[0-9a-f]{6})$/i.test(hex)) return null;
65
70
  const digits = hex.replace("#", "");
66
71
  const full =
67
72
  digits.length === 3
@@ -70,8 +75,70 @@ export function fadeStop(hex: string): string {
70
75
  .map((c) => c + c)
71
76
  .join("")
72
77
  : digits;
73
- const r = Number.parseInt(full.slice(0, 2), 16);
74
- const g = Number.parseInt(full.slice(2, 4), 16);
75
- const b = Number.parseInt(full.slice(4, 6), 16);
78
+ return [
79
+ Number.parseInt(full.slice(0, 2), 16),
80
+ Number.parseInt(full.slice(2, 4), 16),
81
+ Number.parseInt(full.slice(4, 6), 16),
82
+ ];
83
+ }
84
+
85
+ /**
86
+ * `#FC4A1A` to `rgba(252,74,26,0)`, the masthead rule's fade out stop. An accent
87
+ * that is not a three or six digit hex fades to `transparent` rather than to NaN.
88
+ */
89
+ export function fadeStop(hex: string): string {
90
+ const channels = rgb(hex);
91
+ if (!channels) return "transparent";
92
+ const [r, g, b] = channels;
76
93
  return `rgba(${r},${g},${b},0)`;
77
94
  }
95
+
96
+ function luminance([r, g, b]: [number, number, number]): number {
97
+ const linear = (v: number) => {
98
+ const c = v / 255;
99
+ return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
100
+ };
101
+ return 0.2126 * linear(r) + 0.7152 * linear(g) + 0.0722 * linear(b);
102
+ }
103
+
104
+ /** The WCAG contrast ratio of two hex colors, or null when either is not a hex. */
105
+ export function contrastRatio(a: string, b: string): number | null {
106
+ const x = rgb(a);
107
+ const y = rgb(b);
108
+ if (!x || !y) return null;
109
+ const [light, dark] = [luminance(x), luminance(y)].sort((p, q) => q - p);
110
+ return (light + 0.05) / (dark + 0.05);
111
+ }
112
+
113
+ /** The ratio small words need against what they sit on. */
114
+ const TEXT_CONTRAST = 4.5;
115
+
116
+ const toHex = (channels: number[]) =>
117
+ `#${channels
118
+ .map((v) => v.toString(16).padStart(2, "0"))
119
+ .join("")
120
+ .toUpperCase()}`;
121
+
122
+ /**
123
+ * The accent as the color of small words: the palette's own `accentInk`, or,
124
+ * for a palette that names only an accent, the accent darkened toward black
125
+ * one step at a time until it reads 4.5 to 1 on both the paper and the
126
+ * ground (the accent itself when it already does). A palette whose colors
127
+ * are not hex values falls back to its ink, which always reads.
128
+ */
129
+ export function accentInk(palette: Palette): string {
130
+ if (palette.accentInk) return palette.accentInk;
131
+ const channels = rgb(palette.accent);
132
+ const grounds = [palette.paper, palette.ground];
133
+ if (!channels || grounds.some((ground) => !rgb(ground))) return palette.ink;
134
+ if (grounds.every((ground) => (contrastRatio(palette.accent, ground) ?? 0) >= TEXT_CONTRAST)) {
135
+ return palette.accent;
136
+ }
137
+ for (let step = 1; step <= 100; step += 1) {
138
+ const candidate = toHex(channels.map((v) => Math.round(v * (1 - step / 100))));
139
+ if (grounds.every((ground) => (contrastRatio(candidate, ground) ?? 0) >= TEXT_CONTRAST)) {
140
+ return candidate;
141
+ }
142
+ }
143
+ return palette.ink;
144
+ }