@tonycodes-ui/mortar 0.12.0 → 0.14.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 +6 -45
- package/DESIGN.md +1 -1
- package/README.md +1 -1
- package/catalog.json +413 -377
- package/cli/audit.mjs +152 -0
- package/dist/agent-data.json +1 -1
- package/dist/application.d.ts +30 -5
- package/dist/application.js +20 -8
- package/dist/email-theme.d.ts +38 -0
- package/dist/email-theme.js +200 -0
- package/dist/email.d.ts +100 -0
- package/dist/email.js +152 -0
- package/dist/index.d.ts +1 -1
- package/dist/inspection.js +17 -1
- package/dist/internal.d.ts +15 -1
- package/dist/internal.js +12 -1
- package/dist/marketing.d.ts +3 -2
- package/dist/marketing.js +2 -6
- package/dist/primitives.js +20 -11
- package/docs/agents.md +21 -18
- package/docs/auth-flows.md +2 -0
- package/docs/email.md +101 -0
- package/docs/theming.md +72 -1
- package/package.json +14 -3
- package/skills/mortar/SKILL.md +1 -1
- package/src/application.css +95 -1
- package/src/application.tsx +88 -19
- package/src/data.css +58 -2
- package/src/email-theme.ts +254 -0
- package/src/email.tsx +413 -0
- package/src/foundation.css +10 -0
- package/src/index.ts +3 -0
- package/src/inspection.tsx +15 -0
- package/src/internal.tsx +93 -2
- package/src/marketing.tsx +4 -74
- package/src/primitives.tsx +38 -19
package/src/application.css
CHANGED
|
@@ -264,6 +264,20 @@
|
|
|
264
264
|
.m-stacked-shell > main:focus {
|
|
265
265
|
outline: none;
|
|
266
266
|
}
|
|
267
|
+
/* A second row of page tabs under the bar; the row draws the full-width rule. */
|
|
268
|
+
.m-stacked-tabs {
|
|
269
|
+
padding: 0 24px;
|
|
270
|
+
border-bottom: 1px solid var(--m-line);
|
|
271
|
+
background: var(--m-surface);
|
|
272
|
+
}
|
|
273
|
+
.m-stacked-tabs .m-tab-nav ul {
|
|
274
|
+
border-bottom: 0;
|
|
275
|
+
}
|
|
276
|
+
@media (max-width: 900px) {
|
|
277
|
+
.m-stacked-tabs {
|
|
278
|
+
padding: 0 16px;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
267
281
|
|
|
268
282
|
/* == Navbar == */
|
|
269
283
|
.m-navbar {
|
|
@@ -274,6 +288,39 @@
|
|
|
274
288
|
padding: 0 24px;
|
|
275
289
|
border-bottom: 1px solid var(--m-line);
|
|
276
290
|
background: var(--m-surface);
|
|
291
|
+
color: var(--m-ink);
|
|
292
|
+
}
|
|
293
|
+
/* Accent bar: the brand's accent fill, remapped like the accent bands
|
|
294
|
+
(marketing.css): on-accent text, links and focus, inverted primary
|
|
295
|
+
actions and outlined secondary ones. --m-sunken uses --m-accent-wash, the
|
|
296
|
+
same direction as an accent button's hover, so a selected row or hover
|
|
297
|
+
moves the fill away from the on-accent text. A mix towards --m-on-accent
|
|
298
|
+
drops that text below 4.5:1. Panels open in a portal and keep the page's
|
|
299
|
+
colours. Inverse needs nothing here: [data-tone="inverse"] remaps every
|
|
300
|
+
token (tokens.css). */
|
|
301
|
+
.m-navbar[data-tone="accent"] {
|
|
302
|
+
background-color: var(--m-accent);
|
|
303
|
+
background-image: var(--m-accent-fill);
|
|
304
|
+
--m-ink: var(--m-on-accent);
|
|
305
|
+
--m-secondary: var(--m-on-accent);
|
|
306
|
+
--m-muted: var(--m-on-accent);
|
|
307
|
+
--m-link: var(--m-on-accent);
|
|
308
|
+
--m-focus: var(--m-on-accent);
|
|
309
|
+
--m-line: color-mix(in oklab, var(--m-on-accent) 35%, transparent);
|
|
310
|
+
--m-line-strong: var(--m-on-accent);
|
|
311
|
+
--m-primary: var(--m-on-accent);
|
|
312
|
+
--m-primary-hover: var(--m-on-accent);
|
|
313
|
+
--m-primary-active: var(--m-on-accent);
|
|
314
|
+
--m-on-primary: var(--m-accent);
|
|
315
|
+
--m-surface: transparent;
|
|
316
|
+
--m-sunken: color-mix(
|
|
317
|
+
in oklab,
|
|
318
|
+
var(--m-accent-wash, transparent) 14%,
|
|
319
|
+
transparent
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
.m-navbar[data-tone="accent"] .m-button-primary:hover {
|
|
323
|
+
box-shadow: inset 0 0 0 2px var(--m-accent);
|
|
277
324
|
}
|
|
278
325
|
.m-navbar > .m-brand {
|
|
279
326
|
display: inline-flex;
|
|
@@ -316,6 +363,27 @@
|
|
|
316
363
|
font-weight: var(--m-weight-semibold);
|
|
317
364
|
box-shadow: inset 0 -2px 0 var(--m-primary);
|
|
318
365
|
}
|
|
366
|
+
/* A group's trigger looks like the links beside it; its panel is the
|
|
367
|
+
shared flyout (marketing.css). */
|
|
368
|
+
.m-navbar > nav > .m-flyout {
|
|
369
|
+
display: flex;
|
|
370
|
+
}
|
|
371
|
+
.m-navbar .m-flyout-trigger {
|
|
372
|
+
padding: 0 10px;
|
|
373
|
+
color: var(--m-secondary);
|
|
374
|
+
font-size: var(--m-font-size);
|
|
375
|
+
font-weight: var(--m-weight-medium);
|
|
376
|
+
box-shadow: inset 0 -2px 0 transparent;
|
|
377
|
+
}
|
|
378
|
+
.m-navbar .m-flyout-trigger:hover {
|
|
379
|
+
color: var(--m-ink);
|
|
380
|
+
box-shadow: inset 0 -2px 0 var(--m-line-strong);
|
|
381
|
+
}
|
|
382
|
+
.m-navbar .m-flyout[data-current] > .m-flyout-trigger {
|
|
383
|
+
color: var(--m-ink);
|
|
384
|
+
font-weight: var(--m-weight-semibold);
|
|
385
|
+
box-shadow: inset 0 -2px 0 var(--m-primary);
|
|
386
|
+
}
|
|
319
387
|
@media (max-width: 900px) {
|
|
320
388
|
.m-navbar {
|
|
321
389
|
flex-wrap: wrap;
|
|
@@ -362,6 +430,25 @@
|
|
|
362
430
|
box-shadow: inset 3px 0 0 var(--m-primary);
|
|
363
431
|
background: var(--m-sunken);
|
|
364
432
|
}
|
|
433
|
+
.m-navbar > nav > .m-flyout {
|
|
434
|
+
display: block;
|
|
435
|
+
}
|
|
436
|
+
.m-navbar .m-flyout-trigger {
|
|
437
|
+
width: 100%;
|
|
438
|
+
min-height: 44px;
|
|
439
|
+
justify-content: space-between;
|
|
440
|
+
padding: 0 12px;
|
|
441
|
+
border-radius: var(--m-radius);
|
|
442
|
+
box-shadow: none;
|
|
443
|
+
}
|
|
444
|
+
.m-navbar .m-flyout-trigger:hover {
|
|
445
|
+
box-shadow: none;
|
|
446
|
+
background: var(--m-sunken);
|
|
447
|
+
}
|
|
448
|
+
.m-navbar .m-flyout[data-current] > .m-flyout-trigger {
|
|
449
|
+
box-shadow: inset 3px 0 0 var(--m-primary);
|
|
450
|
+
background: var(--m-sunken);
|
|
451
|
+
}
|
|
365
452
|
}
|
|
366
453
|
|
|
367
454
|
/* == Breadcrumbs == */
|
|
@@ -549,14 +636,21 @@
|
|
|
549
636
|
--m-tone: var(--m-secondary);
|
|
550
637
|
}
|
|
551
638
|
@media (max-width: 560px) {
|
|
639
|
+
/* Two metrics a row, but a value too wide for half a row takes a row of
|
|
640
|
+
its own instead of being clipped; a value wider than the whole row
|
|
641
|
+
wraps. */
|
|
552
642
|
.m-metrics {
|
|
553
|
-
|
|
643
|
+
display: flex;
|
|
644
|
+
flex-wrap: wrap;
|
|
554
645
|
}
|
|
555
646
|
.m-metrics > div {
|
|
647
|
+
flex: 1 1 40%;
|
|
648
|
+
max-width: 100%;
|
|
556
649
|
border-bottom: 1px solid var(--m-line);
|
|
557
650
|
}
|
|
558
651
|
.m-metrics dd {
|
|
559
652
|
font-size: 24px;
|
|
653
|
+
overflow-wrap: break-word;
|
|
560
654
|
}
|
|
561
655
|
}
|
|
562
656
|
|
package/src/application.tsx
CHANGED
|
@@ -13,6 +13,7 @@ import { AuthHeader, ProviderButtons, type SignInProvider } from "./auth.js";
|
|
|
13
13
|
import { ArrowDown, ArrowUp, Check, SortArrows } from "./icons.js";
|
|
14
14
|
import { headingTag, type HeadingLevel } from "./heading.js";
|
|
15
15
|
import {
|
|
16
|
+
Flyout,
|
|
16
17
|
LinkContent,
|
|
17
18
|
NavGroups,
|
|
18
19
|
NavTreeLinks,
|
|
@@ -21,7 +22,9 @@ import {
|
|
|
21
22
|
cx,
|
|
22
23
|
componentRoot,
|
|
23
24
|
classedIntroSlots,
|
|
25
|
+
sectionTone,
|
|
24
26
|
useDomId,
|
|
27
|
+
type FlyoutItem,
|
|
25
28
|
} from "./internal.js";
|
|
26
29
|
/**
|
|
27
30
|
* A navigation link; `icon` replaces the default marker in the sidebar. With
|
|
@@ -189,11 +192,16 @@ export interface StackedShellProps {
|
|
|
189
192
|
brand: string;
|
|
190
193
|
logo?: ReactNode;
|
|
191
194
|
homeHref?: string;
|
|
192
|
-
|
|
195
|
+
/** Top-level links, or labelled groups that open a dropdown panel. */
|
|
196
|
+
navigation: NavbarItem[];
|
|
193
197
|
actions?: ReactNode;
|
|
194
198
|
/** Page heading shown above the content, e.g. a PageHeading. */
|
|
195
199
|
header?: ReactNode;
|
|
196
200
|
width?: "md" | "lg" | "xl" | "full";
|
|
201
|
+
/** The bar's surface: default, inverse (the other appearance) or accent (the brand's accent fill). */
|
|
202
|
+
tone?: NavbarTone;
|
|
203
|
+
/** A second row of page tabs under the bar, rendered as a TabNav named by `label`. */
|
|
204
|
+
tabs?: ItemGroup<TabNavItem>;
|
|
197
205
|
children: ReactNode;
|
|
198
206
|
className?: string;
|
|
199
207
|
}
|
|
@@ -206,6 +214,8 @@ export function StackedShell({
|
|
|
206
214
|
actions,
|
|
207
215
|
header,
|
|
208
216
|
width = "lg",
|
|
217
|
+
tone,
|
|
218
|
+
tabs,
|
|
209
219
|
children,
|
|
210
220
|
className,
|
|
211
221
|
}: StackedShellProps) {
|
|
@@ -224,7 +234,13 @@ export function StackedShell({
|
|
|
224
234
|
homeHref={homeHref}
|
|
225
235
|
items={navigation}
|
|
226
236
|
actions={actions}
|
|
237
|
+
tone={tone}
|
|
227
238
|
/>
|
|
239
|
+
{tabs && (
|
|
240
|
+
<div className="m-stacked-tabs">
|
|
241
|
+
<TabNav label={tabs.label} items={tabs.items} />
|
|
242
|
+
</div>
|
|
243
|
+
)}
|
|
228
244
|
<main id={contentId} tabIndex={-1} data-width={width}>
|
|
229
245
|
{header && <div className="m-stacked-header">{header}</div>}
|
|
230
246
|
{children}
|
|
@@ -232,13 +248,20 @@ export function StackedShell({
|
|
|
232
248
|
</div>
|
|
233
249
|
);
|
|
234
250
|
}
|
|
251
|
+
/** A labelled group of links that opens a dropdown panel from the bar. */
|
|
252
|
+
export type NavbarGroup = ItemGroup<FlyoutItem>;
|
|
253
|
+
/** A top-level link, or a group; a group holding the current page is marked current. */
|
|
254
|
+
export type NavbarItem = LinkItem | NavbarGroup;
|
|
255
|
+
export type NavbarTone = "default" | "inverse" | "accent";
|
|
235
256
|
export interface NavbarProps {
|
|
236
257
|
brand: string;
|
|
237
258
|
logo?: ReactNode;
|
|
238
259
|
homeHref?: string;
|
|
239
|
-
/** Top-level links
|
|
240
|
-
items:
|
|
260
|
+
/** Top-level links, or labelled groups that open a dropdown panel. */
|
|
261
|
+
items: NavbarItem[];
|
|
241
262
|
actions?: ReactNode;
|
|
263
|
+
/** The bar's surface: default, inverse (the other appearance) or accent (the brand's accent fill). */
|
|
264
|
+
tone?: NavbarTone;
|
|
242
265
|
/** Accessible name of the navigation landmark. */
|
|
243
266
|
label?: string;
|
|
244
267
|
className?: string;
|
|
@@ -250,13 +273,19 @@ export function Navbar({
|
|
|
250
273
|
homeHref = "/",
|
|
251
274
|
items,
|
|
252
275
|
actions,
|
|
276
|
+
tone,
|
|
253
277
|
label = "Primary",
|
|
254
278
|
className,
|
|
255
279
|
}: NavbarProps) {
|
|
256
280
|
const [open, setOpen] = useState(false);
|
|
257
281
|
const id = useId();
|
|
282
|
+
const close = () => setOpen(false);
|
|
258
283
|
return (
|
|
259
|
-
<header
|
|
284
|
+
<header
|
|
285
|
+
{...componentRoot("Navbar")}
|
|
286
|
+
className={cx("m-navbar", className)}
|
|
287
|
+
data-tone={sectionTone(tone)}
|
|
288
|
+
>
|
|
260
289
|
<KitLink className="m-brand" href={homeHref}>
|
|
261
290
|
<BrandMark logo={logo} />
|
|
262
291
|
{brand}
|
|
@@ -271,21 +300,30 @@ export function Navbar({
|
|
|
271
300
|
Menu
|
|
272
301
|
</Button>
|
|
273
302
|
<nav id={id} aria-label={label} data-open={open || undefined}>
|
|
274
|
-
{items.map((item, index) =>
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
aria-current={item.current ? "page" : undefined}
|
|
279
|
-
onClick={() => setOpen(false)}
|
|
280
|
-
>
|
|
281
|
-
<LinkContent
|
|
282
|
-
prefix="nav"
|
|
283
|
-
icon={item.icon}
|
|
303
|
+
{items.map((item, index) =>
|
|
304
|
+
"items" in item ? (
|
|
305
|
+
<Flyout
|
|
306
|
+
key={`${item.label}:group:${index}`}
|
|
284
307
|
label={item.label}
|
|
285
|
-
|
|
308
|
+
items={item.items}
|
|
309
|
+
onNavigate={close}
|
|
286
310
|
/>
|
|
287
|
-
|
|
288
|
-
|
|
311
|
+
) : (
|
|
312
|
+
<KitLink
|
|
313
|
+
key={`${item.label}:${item.href}:${index}`}
|
|
314
|
+
href={item.href}
|
|
315
|
+
aria-current={item.current ? "page" : undefined}
|
|
316
|
+
onClick={close}
|
|
317
|
+
>
|
|
318
|
+
<LinkContent
|
|
319
|
+
prefix="nav"
|
|
320
|
+
icon={item.icon}
|
|
321
|
+
label={item.label}
|
|
322
|
+
count={item.count}
|
|
323
|
+
/>
|
|
324
|
+
</KitLink>
|
|
325
|
+
),
|
|
326
|
+
)}
|
|
289
327
|
</nav>
|
|
290
328
|
{actions && <div className="m-actions">{actions}</div>}
|
|
291
329
|
</header>
|
|
@@ -689,6 +727,28 @@ export interface DataTableColumn<T> {
|
|
|
689
727
|
width?: string;
|
|
690
728
|
/** Clip long values to one line with an ellipsis. */
|
|
691
729
|
truncate?: boolean;
|
|
730
|
+
/**
|
|
731
|
+
* How long the column stays as the table narrows (its own width, not the
|
|
732
|
+
* screen's): `medium` hides below 480px, `low` below 768px. The first
|
|
733
|
+
* column always shows. Hidden columns leave the accessibility tree too, so
|
|
734
|
+
* keep what people need in visible columns or on the detail page.
|
|
735
|
+
*/
|
|
736
|
+
priority?: "high" | "medium" | "low";
|
|
737
|
+
/**
|
|
738
|
+
* `end` pins the column to the trailing edge while the table scrolls
|
|
739
|
+
* sideways, so a row-actions or status column stays reachable.
|
|
740
|
+
*/
|
|
741
|
+
pin?: "end";
|
|
742
|
+
}
|
|
743
|
+
/** Responsive attributes shared by a column's `col`, header and cells. */
|
|
744
|
+
function columnLayout<T>(col: DataTableColumn<T>, index: number) {
|
|
745
|
+
return {
|
|
746
|
+
"data-priority":
|
|
747
|
+
index > 0 && col.priority && col.priority !== "high"
|
|
748
|
+
? col.priority
|
|
749
|
+
: undefined,
|
|
750
|
+
"data-pin": col.pin,
|
|
751
|
+
};
|
|
692
752
|
}
|
|
693
753
|
export interface DataTableProps<T extends { id: string }> {
|
|
694
754
|
caption: string;
|
|
@@ -894,6 +954,7 @@ export function DataTable<T extends { id: string }>({
|
|
|
894
954
|
<th
|
|
895
955
|
scope="row"
|
|
896
956
|
key={col.key}
|
|
957
|
+
{...columnLayout(col, index)}
|
|
897
958
|
data-align={columnAlign(col.align)}
|
|
898
959
|
data-truncate={col.truncate || undefined}
|
|
899
960
|
>
|
|
@@ -908,6 +969,7 @@ export function DataTable<T extends { id: string }>({
|
|
|
908
969
|
) : (
|
|
909
970
|
<td
|
|
910
971
|
key={col.key}
|
|
972
|
+
{...columnLayout(col, index)}
|
|
911
973
|
data-align={columnAlign(col.align)}
|
|
912
974
|
data-truncate={col.truncate || undefined}
|
|
913
975
|
>
|
|
@@ -926,6 +988,11 @@ export function DataTable<T extends { id: string }>({
|
|
|
926
988
|
aria-label={caption}
|
|
927
989
|
data-density={density === "default" ? undefined : density}
|
|
928
990
|
data-striped={striped || undefined}
|
|
991
|
+
data-prioritised={
|
|
992
|
+
columns.some((col, index) => columnLayout(col, index)["data-priority"])
|
|
993
|
+
? true
|
|
994
|
+
: undefined
|
|
995
|
+
}
|
|
929
996
|
>
|
|
930
997
|
{(toolbar || selectedIds.length > 0) && (
|
|
931
998
|
<div className="m-table-toolbar">
|
|
@@ -977,9 +1044,10 @@ export function DataTable<T extends { id: string }>({
|
|
|
977
1044
|
{columns.some((col) => col.width) && (
|
|
978
1045
|
<colgroup>
|
|
979
1046
|
{onSelectionChange && <col className="m-table-select-col" />}
|
|
980
|
-
{columns.map((col) => (
|
|
1047
|
+
{columns.map((col, index) => (
|
|
981
1048
|
<col
|
|
982
1049
|
key={col.key}
|
|
1050
|
+
{...columnLayout(col, index)}
|
|
983
1051
|
style={col.width ? { width: col.width } : undefined}
|
|
984
1052
|
/>
|
|
985
1053
|
))}
|
|
@@ -996,13 +1064,14 @@ export function DataTable<T extends { id: string }>({
|
|
|
996
1064
|
/>
|
|
997
1065
|
</th>
|
|
998
1066
|
)}
|
|
999
|
-
{columns.map((col) => {
|
|
1067
|
+
{columns.map((col, index) => {
|
|
1000
1068
|
const direction =
|
|
1001
1069
|
sort?.key === col.key ? sort.direction : undefined;
|
|
1002
1070
|
return (
|
|
1003
1071
|
<th
|
|
1004
1072
|
key={col.key}
|
|
1005
1073
|
scope="col"
|
|
1074
|
+
{...columnLayout(col, index)}
|
|
1006
1075
|
data-align={columnAlign(col.align)}
|
|
1007
1076
|
aria-sort={col.sortable ? direction || "none" : undefined}
|
|
1008
1077
|
>
|
package/src/data.css
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
/* One table base for DataTable, Table, PlanComparison and prose tables. Each sets
|
|
10
10
|
its cell padding; DataTable and Table follow density through --m-row-pad. */
|
|
11
11
|
.m-data-table {
|
|
12
|
+
container: m-data-table / inline-size;
|
|
12
13
|
overflow: hidden;
|
|
13
14
|
min-width: 0;
|
|
14
15
|
--m-cell-pad-y: var(--m-row-pad);
|
|
@@ -255,9 +256,64 @@
|
|
|
255
256
|
.m-data-table[data-density="compact"] .m-table-group th {
|
|
256
257
|
padding-block: 4px;
|
|
257
258
|
}
|
|
259
|
+
/* Pinned columns stay at the trailing edge while the table scrolls. Sticky
|
|
260
|
+
cells need an opaque background: the surface, or the row's own state.
|
|
261
|
+
Zero-specificity base, so stripes (after it) and hover and selection win. */
|
|
262
|
+
:where(.m-data-table) [data-pin="end"] {
|
|
263
|
+
position: sticky;
|
|
264
|
+
inset-inline-end: 0;
|
|
265
|
+
z-index: 2;
|
|
266
|
+
background-color: var(--m-surface);
|
|
267
|
+
box-shadow: inset 1px 0 0 var(--m-line);
|
|
268
|
+
}
|
|
269
|
+
:where(.m-data-table:dir(rtl)) [data-pin="end"] {
|
|
270
|
+
box-shadow: inset -1px 0 0 var(--m-line);
|
|
271
|
+
}
|
|
272
|
+
:where(
|
|
273
|
+
.m-data-table[data-striped]
|
|
274
|
+
tbody
|
|
275
|
+
tr:nth-child(even of :not(.m-table-group))
|
|
276
|
+
)
|
|
277
|
+
> [data-pin] {
|
|
278
|
+
background-color: var(--m-sunken);
|
|
279
|
+
}
|
|
280
|
+
.m-data-table thead th[data-pin] {
|
|
281
|
+
background-color: var(--m-paper);
|
|
282
|
+
}
|
|
283
|
+
.m-table-scroll[data-sticky] thead th[data-pin] {
|
|
284
|
+
z-index: 3;
|
|
285
|
+
}
|
|
286
|
+
/* (0,2,1): above the pinned stripe, below forced-colours selection (0,3,0).
|
|
287
|
+
:where(.m-data-table) does that for a selected cell. Hover also zeroes
|
|
288
|
+
[data-linked]; :hover alone would stay at (0,3,1) and keep HighlightText
|
|
289
|
+
on the author's background. */
|
|
290
|
+
:where(.m-data-table) tr:where([data-linked]):hover > [data-pin] {
|
|
291
|
+
background-color: var(--m-sunken);
|
|
292
|
+
}
|
|
293
|
+
:where(.m-data-table) tr[data-selected] > [data-pin] {
|
|
294
|
+
background-color: var(--m-selected);
|
|
295
|
+
}
|
|
296
|
+
/* Column priority follows the table's own width, so a table in a narrow
|
|
297
|
+
panel collapses as it would on a phone. */
|
|
298
|
+
@container m-data-table (max-width: 767px) {
|
|
299
|
+
.m-data-table [data-priority="low"] {
|
|
300
|
+
display: none;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
@container m-data-table (max-width: 479px) {
|
|
304
|
+
.m-data-table [data-priority="medium"] {
|
|
305
|
+
display: none;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
/* A table with column priorities is meant to fit, so truncated columns keep
|
|
309
|
+
shrinking on narrow screens, down to a readable floor. */
|
|
310
|
+
.m-data-table[data-prioritised] [data-truncate] .m-truncate {
|
|
311
|
+
min-width: 5rem;
|
|
312
|
+
}
|
|
258
313
|
@media (max-width: 640px) {
|
|
259
|
-
/* Narrow screens scroll the table instead of collapsing truncated columns
|
|
260
|
-
|
|
314
|
+
/* Narrow screens scroll the table instead of collapsing truncated columns,
|
|
315
|
+
unless it has column priorities (above). */
|
|
316
|
+
.m-data-table:not([data-prioritised]) [data-truncate] {
|
|
261
317
|
max-width: none;
|
|
262
318
|
}
|
|
263
319
|
.m-truncate {
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
/* Email theme. Email clients cannot read Mortar's stylesheet: Gmail drops CSS
|
|
2
|
+
variables and Outlook for Windows renders with Word. So an email takes its
|
|
3
|
+
colours and fonts as literal values, resolved here from a brand the way
|
|
4
|
+
tokens.css resolves it for the light appearance: omitted values keep
|
|
5
|
+
Mortar's defaults or derive from primary, and derived colours
|
|
6
|
+
(color-mix(in oklab, …)) are computed in JS. tests/email.test.mjs checks
|
|
7
|
+
the defaults against tokens.css. */
|
|
8
|
+
|
|
9
|
+
import { isBrandFont, type BrandDefinition } from "./brand.js";
|
|
10
|
+
|
|
11
|
+
/** Literal colours (#rrggbb) and font stacks for an email. */
|
|
12
|
+
export interface EmailTheme {
|
|
13
|
+
/** The page behind the message. */
|
|
14
|
+
paper: string;
|
|
15
|
+
/** The message card. */
|
|
16
|
+
surface: string;
|
|
17
|
+
/** Recessed areas such as a one-time code. */
|
|
18
|
+
sunken: string;
|
|
19
|
+
line: string;
|
|
20
|
+
ink: string;
|
|
21
|
+
secondary: string;
|
|
22
|
+
muted: string;
|
|
23
|
+
primary: string;
|
|
24
|
+
onPrimary: string;
|
|
25
|
+
accent: string;
|
|
26
|
+
onAccent: string;
|
|
27
|
+
link: string;
|
|
28
|
+
/** A tint of primary on the paper, for highlighted rows and callouts. */
|
|
29
|
+
selected: string;
|
|
30
|
+
success: string;
|
|
31
|
+
warning: string;
|
|
32
|
+
danger: string;
|
|
33
|
+
info: string;
|
|
34
|
+
/** Body font stack, ending in fonts every email client has. */
|
|
35
|
+
font: string;
|
|
36
|
+
/** Heading font stack; the body stack unless the brand sets one. */
|
|
37
|
+
fontHeading: string;
|
|
38
|
+
mono: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/* The light defaults in tokens.css. */
|
|
42
|
+
const DEFAULTS = {
|
|
43
|
+
paper: "#ffffff",
|
|
44
|
+
surface: "#ffffff",
|
|
45
|
+
sunken: "#f5f5f7",
|
|
46
|
+
line: "#e5e5ea",
|
|
47
|
+
ink: "#000000",
|
|
48
|
+
secondary: "#3a3a3c",
|
|
49
|
+
muted: "#6e6e73",
|
|
50
|
+
primary: "#000000",
|
|
51
|
+
onPrimary: "#ffffff",
|
|
52
|
+
success: "#1f7a36",
|
|
53
|
+
warning: "#945700",
|
|
54
|
+
danger: "#c70014",
|
|
55
|
+
info: "#0060c7",
|
|
56
|
+
};
|
|
57
|
+
/* The neutral brand's tuned selected tint (no brand at all). */
|
|
58
|
+
const NEUTRAL_SELECTED = "#f2f2f4";
|
|
59
|
+
|
|
60
|
+
/* Mortar's system stack, plus the fonts Windows and Android mail apps have. */
|
|
61
|
+
const SANS =
|
|
62
|
+
'-apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif';
|
|
63
|
+
const SERIF = 'Georgia, "Times New Roman", Times, serif';
|
|
64
|
+
const MONO = '"SF Mono", Menlo, Consolas, "Courier New", monospace';
|
|
65
|
+
const GENERIC: Record<string, string> = {
|
|
66
|
+
"sans-serif": SANS,
|
|
67
|
+
"system-ui": SANS,
|
|
68
|
+
"ui-sans-serif": SANS,
|
|
69
|
+
serif: SERIF,
|
|
70
|
+
"ui-serif": SERIF,
|
|
71
|
+
monospace: MONO,
|
|
72
|
+
"ui-monospace": MONO,
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* A brand font list for email: `var()` entries (which email cannot resolve)
|
|
77
|
+
* and generic families are dropped, and a stack every client has is
|
|
78
|
+
* appended, serif or monospace when the brand's generic family is one.
|
|
79
|
+
*/
|
|
80
|
+
function fontStack(value: string | undefined, key: string): string | undefined {
|
|
81
|
+
const text = value?.trim();
|
|
82
|
+
if (!text) return undefined;
|
|
83
|
+
if (!isBrandFont(text))
|
|
84
|
+
throw new Error(
|
|
85
|
+
`Invalid Mortar brand font for fonts.${key}: "${text}". Use family names, quoted names and generic families separated by commas, e.g. "Inter", sans-serif.`,
|
|
86
|
+
);
|
|
87
|
+
let fallback = SANS;
|
|
88
|
+
const names = text
|
|
89
|
+
.split(",")
|
|
90
|
+
.map((name) => name.trim())
|
|
91
|
+
.filter((name) => {
|
|
92
|
+
if (/^var\(/i.test(name)) return false;
|
|
93
|
+
const generic = GENERIC[name.toLowerCase()];
|
|
94
|
+
if (generic) fallback = generic;
|
|
95
|
+
return !generic;
|
|
96
|
+
});
|
|
97
|
+
return [...names, fallback].join(", ");
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/* Colour parsing: the opaque colour syntax a brand can resolve without a
|
|
101
|
+
browser. Everything is converted to sRGB and written as #rrggbb. */
|
|
102
|
+
type Rgb = [number, number, number];
|
|
103
|
+
|
|
104
|
+
const linear = (v: number) =>
|
|
105
|
+
v <= 0.04045 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4;
|
|
106
|
+
const gamma = (v: number) =>
|
|
107
|
+
v <= 0.0031308 ? v * 12.92 : 1.055 * v ** (1 / 2.4) - 0.055;
|
|
108
|
+
|
|
109
|
+
function toOklab([r, g, b]: Rgb): Rgb {
|
|
110
|
+
const [lr, lg, lb] = [r, g, b].map(linear);
|
|
111
|
+
const l = Math.cbrt(
|
|
112
|
+
0.4122214708 * lr + 0.5363325363 * lg + 0.0514459929 * lb,
|
|
113
|
+
);
|
|
114
|
+
const m = Math.cbrt(
|
|
115
|
+
0.2119034982 * lr + 0.6806995451 * lg + 0.1073969566 * lb,
|
|
116
|
+
);
|
|
117
|
+
const s = Math.cbrt(
|
|
118
|
+
0.0883024619 * lr + 0.2817188376 * lg + 0.6299787005 * lb,
|
|
119
|
+
);
|
|
120
|
+
return [
|
|
121
|
+
0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s,
|
|
122
|
+
1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s,
|
|
123
|
+
0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s,
|
|
124
|
+
];
|
|
125
|
+
}
|
|
126
|
+
function fromOklab([L, a, b]: Rgb): Rgb {
|
|
127
|
+
const l = (L + 0.3963377774 * a + 0.2158037573 * b) ** 3;
|
|
128
|
+
const m = (L - 0.1055613458 * a - 0.0638541728 * b) ** 3;
|
|
129
|
+
const s = (L - 0.0894841775 * a - 1.291485548 * b) ** 3;
|
|
130
|
+
return [
|
|
131
|
+
4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,
|
|
132
|
+
-1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,
|
|
133
|
+
-0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s,
|
|
134
|
+
].map(gamma) as Rgb;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** sRGB channels in 0–1 as #rrggbb, clipped to the sRGB gamut. */
|
|
138
|
+
function hex(rgb: Rgb): string {
|
|
139
|
+
return `#${rgb
|
|
140
|
+
.map((v) =>
|
|
141
|
+
Math.round(Math.min(1, Math.max(0, v)) * 255)
|
|
142
|
+
.toString(16)
|
|
143
|
+
.padStart(2, "0"),
|
|
144
|
+
)
|
|
145
|
+
.join("")}`;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** A number, or a percentage of `whole`. */
|
|
149
|
+
function amount(value: string, whole: number): number {
|
|
150
|
+
const n = parseFloat(value);
|
|
151
|
+
if (!/^[+-]?(?:\d+\.?\d*|\.\d+)%?$/.test(value) || Number.isNaN(n))
|
|
152
|
+
throw new Error();
|
|
153
|
+
return value.endsWith("%") ? (n / 100) * whole : n;
|
|
154
|
+
}
|
|
155
|
+
function hue(value: string): number {
|
|
156
|
+
const m = /^([+-]?(?:\d+\.?\d*|\.\d+))(deg|turn|rad)?$/.exec(value);
|
|
157
|
+
if (!m) throw new Error();
|
|
158
|
+
const n = parseFloat(m[1]);
|
|
159
|
+
return m[2] === "turn" ? n * 360 : m[2] === "rad" ? (n * 180) / Math.PI : n;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function hslToRgb(h: number, s: number, l: number): Rgb {
|
|
163
|
+
const k = (n: number) => (n + h / 30) % 12;
|
|
164
|
+
const a = s * Math.min(l, 1 - l);
|
|
165
|
+
return [0, 8, 4].map(
|
|
166
|
+
(n) => l - a * Math.max(-1, Math.min(k(n) - 3, 9 - k(n), 1)),
|
|
167
|
+
) as Rgb;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function parseColour(value: string): Rgb {
|
|
171
|
+
const text = value.trim().toLowerCase();
|
|
172
|
+
if (text === "white") return [1, 1, 1];
|
|
173
|
+
if (text === "black") return [0, 0, 0];
|
|
174
|
+
const short = /^#([0-9a-f])([0-9a-f])([0-9a-f])$/.exec(text);
|
|
175
|
+
if (short) return short.slice(1).map((d) => parseInt(d + d, 16) / 255) as Rgb;
|
|
176
|
+
const long = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/.exec(text);
|
|
177
|
+
if (long) return long.slice(1).map((d) => parseInt(d, 16) / 255) as Rgb;
|
|
178
|
+
const fn = /^(rgba?|hsla?|oklab|oklch)\(([^()]*)\)$/.exec(text);
|
|
179
|
+
if (!fn) throw new Error();
|
|
180
|
+
const [channels, alpha] = fn[2].split("/");
|
|
181
|
+
const parts = channels.trim().split(/[\s,]+/);
|
|
182
|
+
const extraAlpha = parts.length === 4 ? parts.pop() : undefined;
|
|
183
|
+
const opacity = alpha ?? extraAlpha;
|
|
184
|
+
if (opacity !== undefined && amount(opacity.trim(), 1) !== 1)
|
|
185
|
+
throw new Error();
|
|
186
|
+
if (parts.length !== 3) throw new Error();
|
|
187
|
+
const [x, y, z] = parts;
|
|
188
|
+
switch (fn[1]) {
|
|
189
|
+
case "rgb":
|
|
190
|
+
case "rgba":
|
|
191
|
+
return [x, y, z].map((v) => amount(v, 255) / 255) as Rgb;
|
|
192
|
+
case "hsl":
|
|
193
|
+
case "hsla":
|
|
194
|
+
return hslToRgb(hue(x), amount(y, 100) / 100, amount(z, 100) / 100);
|
|
195
|
+
case "oklab":
|
|
196
|
+
return fromOklab([amount(x, 1), amount(y, 0.4), amount(z, 0.4)]);
|
|
197
|
+
default: {
|
|
198
|
+
const c = amount(y, 0.4),
|
|
199
|
+
h = (hue(z) * Math.PI) / 180;
|
|
200
|
+
return fromOklab([amount(x, 1), c * Math.cos(h), c * Math.sin(h)]);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function colour(value: string | undefined, key: string): string | undefined {
|
|
206
|
+
const text = value?.trim();
|
|
207
|
+
if (!text) return undefined;
|
|
208
|
+
try {
|
|
209
|
+
return hex(parseColour(text));
|
|
210
|
+
} catch {
|
|
211
|
+
throw new Error(
|
|
212
|
+
`Mortar email colours must be literal and opaque, for light.${key}: "${text}". Use a hex value, white, black, or rgb(), hsl(), oklab() or oklch().`,
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** color-mix(in oklab, a p%, b) as #rrggbb. */
|
|
218
|
+
function mix(a: string, b: string, percentA: number): string {
|
|
219
|
+
const t = percentA / 100;
|
|
220
|
+
const [x, y] = [toOklab(parseColour(a)), toOklab(parseColour(b))];
|
|
221
|
+
return hex(fromOklab(x.map((v, i) => v * t + y[i] * (1 - t)) as Rgb));
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* The email theme for a brand, in its light appearance: emails render light,
|
|
226
|
+
* since most clients ignore or override a dark one. Without a brand, Mortar's
|
|
227
|
+
* neutral defaults. Brand colours must be literal (`var()`, `color-mix()`
|
|
228
|
+
* and `light-dark()` need a browser) and opaque; the accent gradient is not
|
|
229
|
+
* used, as most clients cannot paint one, so accents use the flat `accent`.
|
|
230
|
+
*/
|
|
231
|
+
export function emailTheme(brand?: BrandDefinition): EmailTheme {
|
|
232
|
+
const light = brand?.light ?? {};
|
|
233
|
+
const paper = colour(light.paper, "paper") ?? DEFAULTS.paper;
|
|
234
|
+
const primary = colour(light.primary, "primary") ?? DEFAULTS.primary;
|
|
235
|
+
const onPrimary = colour(light.onPrimary, "onPrimary") ?? DEFAULTS.onPrimary;
|
|
236
|
+
const font = fontStack(brand?.fonts?.body, "body") ?? SANS;
|
|
237
|
+
return {
|
|
238
|
+
...DEFAULTS,
|
|
239
|
+
paper,
|
|
240
|
+
surface: colour(light.surface, "surface") ?? DEFAULTS.surface,
|
|
241
|
+
sunken: colour(light.sunken, "sunken") ?? DEFAULTS.sunken,
|
|
242
|
+
primary,
|
|
243
|
+
onPrimary,
|
|
244
|
+
accent: colour(light.accent, "accent") ?? primary,
|
|
245
|
+
onAccent: colour(light.onAccent, "onAccent") ?? onPrimary,
|
|
246
|
+
link: colour(light.link, "link") ?? primary,
|
|
247
|
+
selected:
|
|
248
|
+
colour(light.selected, "selected") ??
|
|
249
|
+
(brand ? mix(primary, paper, 8) : NEUTRAL_SELECTED),
|
|
250
|
+
font,
|
|
251
|
+
fontHeading: fontStack(brand?.fonts?.heading, "heading") ?? font,
|
|
252
|
+
mono: MONO,
|
|
253
|
+
};
|
|
254
|
+
}
|