@atomic-ui/design-tokens 0.1.2 → 0.1.3

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/README.md CHANGED
@@ -75,6 +75,26 @@ would otherwise validate, be dropped, and leave an editor looking at a brand tha
75
75
  ignores a value they set. Being refused says what is actually true: there is nowhere to
76
76
  put a foreground colour, because foregrounds are measured.
77
77
 
78
+ ## Layout
79
+
80
+ A brand's `layout` sets the page frame and the gutters between columns:
81
+
82
+ - `pageWidth` is the widest the content gets, from 640 to 1600px.
83
+ - `margin.phone`, `margin.tablet` and `margin.desktop` are the space at the screen's edge.
84
+ - `gutter.sm`, `gutter.md` and `gutter.lg` are the three gaps a grid can choose.
85
+
86
+ Margins and gutters name steps on the spacing scale, such as `'4'` or `'6'`, rather than
87
+ pixels, so they follow `shape.spaceBase`. Each has a default, so a brand that sets none
88
+ of this looks as it did before.
89
+
90
+ `toStylesheet` emits them as `--impkt-layout-*` tokens, plus an `impkt-page` class. An
91
+ app puts that class on the element its pages fill, and the content is then centred,
92
+ held to the page width, and given the brand's margin for each size of screen:
93
+
94
+ ```tsx
95
+ <main className="impkt-page"><RouterView … /></main>
96
+ ```
97
+
78
98
  ## Commands
79
99
 
80
100
  ```bash
@@ -9,12 +9,26 @@ function toStyleProperties(tokens) {
9
9
  function toCssDeclarations(tokens, indent = " ") {
10
10
  return Object.entries(tokens).map(([path, value]) => `${indent}${cssVarName(path)}: ${value};`).join("\n");
11
11
  }
12
- function toStylesheet(tokens, options = {}) {
13
- const { selector = ":root", fonts = [] } = options;
14
- const faces = fonts.map((f) => {
12
+ var PAGE_FRAME = [
13
+ `.impkt-page {
14
+ box-sizing: border-box;
15
+ inline-size: 100%;
16
+ max-inline-size: calc(${"var(--impkt-layout-page-width, 1200px)"} + 2 * ${"var(--impkt-layout-margin-desktop, 64px)"});
17
+ margin-inline: auto;
18
+ padding-inline: var(--impkt-layout-margin-phone, 16px);
19
+ }`,
20
+ `@media (min-width: 40rem) {
21
+ .impkt-page { padding-inline: var(--impkt-layout-margin-tablet, 32px); }
22
+ }`,
23
+ `@media (min-width: 64rem) {
24
+ .impkt-page { padding-inline: var(--impkt-layout-margin-desktop, 64px); }
25
+ }`
26
+ ].join("\n");
27
+ function fontFaceCss(fonts) {
28
+ return fonts.filter((f) => f.url).map((f) => {
15
29
  const lines = [
16
30
  ` font-family: ${JSON.stringify(f.family)};`,
17
- ` src: url(${JSON.stringify(f.url)}) format("woff2");`,
31
+ ` src: url(${JSON.stringify(f.url)}) format("${/\.woff(\?|#|$)/i.test(f.url) ? "woff" : "woff2"}");`,
18
32
  ` font-display: ${f.display ?? "swap"};`
19
33
  ];
20
34
  if (f.weight) lines.push(` font-weight: ${f.weight};`);
@@ -22,10 +36,14 @@ function toStylesheet(tokens, options = {}) {
22
36
  return `@font-face {
23
37
  ${lines.join("\n")}
24
38
  }`;
25
- });
26
- return [...faces, `${selector} {
39
+ }).join("\n\n");
40
+ }
41
+ function toStylesheet(tokens, options = {}) {
42
+ const { selector = ":root", fonts = [] } = options;
43
+ const faces = fontFaceCss(fonts);
44
+ return [...faces ? [faces] : [], `${selector} {
27
45
  ${toCssDeclarations(tokens)}
28
- }`].join("\n\n") + "\n";
46
+ }`, PAGE_FRAME].join("\n\n") + "\n";
29
47
  }
30
48
  var escapeStyleText = (css) => css.replace(/<\/(style)/gi, "<\\/$1");
31
49
 
@@ -34,7 +52,9 @@ export {
34
52
  cssVarName,
35
53
  toStyleProperties,
36
54
  toCssDeclarations,
55
+ PAGE_FRAME,
56
+ fontFaceCss,
37
57
  toStylesheet,
38
58
  escapeStyleText
39
59
  };
40
- //# sourceMappingURL=chunk-YUZFJX3U.js.map
60
+ //# sourceMappingURL=chunk-7BKTXJHX.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/css.ts"],"sourcesContent":["/**\n * Tokens → CSS custom properties.\n *\n * One emitter, used by both paths. The house theme is written to a stylesheet\n * at build time and a partner's brand is emitted at runtime from a published\n * document, and if those were two pieces of code they would drift — quietly,\n * because nothing would compare them. The same reasoning as the delivery API's\n * export command, which issues a real request rather than re-implementing the\n * response.\n */\nimport type { TokenSet } from './derive';\nimport type { WebFont } from './inputs';\n\n/** The namespace. Every property this package emits starts with it. */\nexport const PREFIX = '--impkt';\n\n/** `color.text.on-brand` → `--impkt-color-text-on-brand`. */\nexport const cssVarName = (path: string): string => `${PREFIX}-${path.replace(/\\./g, '-')}`;\n\n/** Tokens as a style object, for a runtime `style={}` or `element.style`. */\nexport function toStyleProperties(tokens: TokenSet): Record<string, string> {\n const out: Record<string, string> = {};\n for (const [path, value] of Object.entries(tokens)) out[cssVarName(path)] = value;\n return out;\n}\n\n/** Tokens as declarations, for a stylesheet or a `<style>` block. */\nexport function toCssDeclarations(tokens: TokenSet, indent = ' '): string {\n return Object.entries(tokens)\n .map(([path, value]) => `${indent}${cssVarName(path)}: ${value};`)\n .join('\\n');\n}\n\nexport interface StylesheetOptions {\n /** Defaults to `:root`. A preview frame or a brand switcher passes its own. */\n selector?: string;\n fonts?: WebFont[];\n}\n\n/**\n * A complete stylesheet: the faces the brand needs, then its properties.\n *\n * `@font-face` travels with the brand rather than being compiled into one\n * app's stylesheet, because a partner brings its own typeface and the shell\n * cannot know in advance what it is.\n */\n/**\n * The page frame a brand's layout describes, as a class an app puts on the\n * element its pages fill: the content no wider than the page width, centred,\n * with the brand's margin for each size of screen between it and the edge.\n * The breakpoints are the ones the grid stacks at.\n */\nexport const PAGE_FRAME = [\n `.impkt-page {\\n box-sizing: border-box;\\n inline-size: 100%;\\n max-inline-size: calc(${'var(--impkt-layout-page-width, 1200px)'} + 2 * ${'var(--impkt-layout-margin-desktop, 64px)'});\\n margin-inline: auto;\\n padding-inline: var(--impkt-layout-margin-phone, 16px);\\n}`,\n `@media (min-width: 40rem) {\\n .impkt-page { padding-inline: var(--impkt-layout-margin-tablet, 32px); }\\n}`,\n `@media (min-width: 64rem) {\\n .impkt-page { padding-inline: var(--impkt-layout-margin-desktop, 64px); }\\n}`,\n].join('\\n');\n\n/** The `@font-face` rules for a brand's font files. */\nexport function fontFaceCss(fonts: readonly WebFont[]): string {\n return fonts.filter((f) => f.url).map((f) => {\n const lines = [\n ` font-family: ${JSON.stringify(f.family)};`,\n ` src: url(${JSON.stringify(f.url)}) format(\"${/\\.woff(\\?|#|$)/i.test(f.url) ? 'woff' : 'woff2'}\");`,\n ` font-display: ${f.display ?? 'swap'};`,\n ];\n if (f.weight) lines.push(` font-weight: ${f.weight};`);\n if (f.style) lines.push(` font-style: ${f.style};`);\n return `@font-face {\\n${lines.join('\\n')}\\n}`;\n }).join('\\n\\n');\n}\n\nexport function toStylesheet(tokens: TokenSet, options: StylesheetOptions = {}): string {\n const { selector = ':root', fonts = [] } = options;\n const faces = fontFaceCss(fonts);\n return [...(faces ? [faces] : []), `${selector} {\\n${toCssDeclarations(tokens)}\\n}`, PAGE_FRAME].join('\\n\\n') + '\\n';\n}\n\n/**\n * Escape a stylesheet for inline injection.\n *\n * A brand is authored content, and authored content reaches a `<style>` block\n * here. `</style>` inside a font family name would close the element and start\n * an injection; the font-family value is already JSON-quoted above, and this is\n * the second line of defence for whoever writes the third emitter.\n */\nexport const escapeStyleText = (css: string): string => css.replace(/<\\/(style)/gi, '<\\\\/$1');\n"],"mappings":";AAcO,IAAM,SAAS;AAGf,IAAM,aAAa,CAAC,SAAyB,GAAG,MAAM,IAAI,KAAK,QAAQ,OAAO,GAAG,CAAC;AAGlF,SAAS,kBAAkB,QAA0C;AAC1E,QAAM,MAA8B,CAAC;AACrC,aAAW,CAAC,MAAM,KAAK,KAAK,OAAO,QAAQ,MAAM,EAAG,KAAI,WAAW,IAAI,CAAC,IAAI;AAC5E,SAAO;AACT;AAGO,SAAS,kBAAkB,QAAkB,SAAS,MAAc;AACzE,SAAO,OAAO,QAAQ,MAAM,EACzB,IAAI,CAAC,CAAC,MAAM,KAAK,MAAM,GAAG,MAAM,GAAG,WAAW,IAAI,CAAC,KAAK,KAAK,GAAG,EAChE,KAAK,IAAI;AACd;AAqBO,IAAM,aAAa;AAAA,EACxB;AAAA;AAAA;AAAA,0BAA2F,wCAAwC,UAAU,0CAA0C;AAAA;AAAA;AAAA;AAAA,EACvL;AAAA;AAAA;AAAA,EACA;AAAA;AAAA;AACF,EAAE,KAAK,IAAI;AAGJ,SAAS,YAAY,OAAmC;AAC7D,SAAO,MAAM,OAAO,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,CAAC,MAAM;AAC3C,UAAM,QAAQ;AAAA,MACZ,kBAAkB,KAAK,UAAU,EAAE,MAAM,CAAC;AAAA,MAC1C,cAAc,KAAK,UAAU,EAAE,GAAG,CAAC,aAAa,kBAAkB,KAAK,EAAE,GAAG,IAAI,SAAS,OAAO;AAAA,MAChG,mBAAmB,EAAE,WAAW,MAAM;AAAA,IACxC;AACA,QAAI,EAAE,OAAQ,OAAM,KAAK,kBAAkB,EAAE,MAAM,GAAG;AACtD,QAAI,EAAE,MAAO,OAAM,KAAK,iBAAiB,EAAE,KAAK,GAAG;AACnD,WAAO;AAAA,EAAiB,MAAM,KAAK,IAAI,CAAC;AAAA;AAAA,EAC1C,CAAC,EAAE,KAAK,MAAM;AAChB;AAEO,SAAS,aAAa,QAAkB,UAA6B,CAAC,GAAW;AACtF,QAAM,EAAE,WAAW,SAAS,QAAQ,CAAC,EAAE,IAAI;AAC3C,QAAM,QAAQ,YAAY,KAAK;AAC/B,SAAO,CAAC,GAAI,QAAQ,CAAC,KAAK,IAAI,CAAC,GAAI,GAAG,QAAQ;AAAA,EAAO,kBAAkB,MAAM,CAAC;AAAA,IAAO,UAAU,EAAE,KAAK,MAAM,IAAI;AAClH;AAUO,IAAM,kBAAkB,CAAC,QAAwB,IAAI,QAAQ,gBAAgB,QAAQ;","names":[]}
package/dist/css.d.ts CHANGED
@@ -30,6 +30,15 @@ export interface StylesheetOptions {
30
30
  * app's stylesheet, because a partner brings its own typeface and the shell
31
31
  * cannot know in advance what it is.
32
32
  */
33
+ /**
34
+ * The page frame a brand's layout describes, as a class an app puts on the
35
+ * element its pages fill: the content no wider than the page width, centred,
36
+ * with the brand's margin for each size of screen between it and the edge.
37
+ * The breakpoints are the ones the grid stacks at.
38
+ */
39
+ export declare const PAGE_FRAME: string;
40
+ /** The `@font-face` rules for a brand's font files. */
41
+ export declare function fontFaceCss(fonts: readonly WebFont[]): string;
33
42
  export declare function toStylesheet(tokens: TokenSet, options?: StylesheetOptions): string;
34
43
  /**
35
44
  * Escape a stylesheet for inline injection.
package/dist/css.js CHANGED
@@ -1,15 +1,19 @@
1
1
  import {
2
+ PAGE_FRAME,
2
3
  PREFIX,
3
4
  cssVarName,
4
5
  escapeStyleText,
6
+ fontFaceCss,
5
7
  toCssDeclarations,
6
8
  toStyleProperties,
7
9
  toStylesheet
8
- } from "./chunk-YUZFJX3U.js";
10
+ } from "./chunk-7BKTXJHX.js";
9
11
  export {
12
+ PAGE_FRAME,
10
13
  PREFIX,
11
14
  cssVarName,
12
15
  escapeStyleText,
16
+ fontFaceCss,
13
17
  toCssDeclarations,
14
18
  toStyleProperties,
15
19
  toStylesheet
package/dist/derive.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { BrandInputs } from './inputs';
1
+ import { type BrandInputs } from './inputs';
2
2
  /** A flat token set: dotted path → CSS value. */
3
3
  export type TokenSet = Record<string, string>;
4
4
  /**
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Fonts a brand names, and whether anything will actually draw them.
3
+ *
4
+ * A brand names its typefaces by family ("GT Walsheim Pro"). A browser draws a
5
+ * family only if the device has it or the page loads it with `@font-face`, and
6
+ * when it can do neither it falls back to its default, which is Times. So every
7
+ * family a brand names is followed by a fallback stack, and a family is only
8
+ * called loaded when the brand carries a file for it.
9
+ */
10
+ import type { WebFont } from './inputs';
11
+ /** What a browser draws when a sans-serif family is missing: the device's own interface font. */
12
+ export declare const SYSTEM_SANS = "system-ui, -apple-system, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif";
13
+ /** The serif equivalent, for a brand whose type is a serif. */
14
+ export declare const SYSTEM_SERIF = "Georgia, Cambria, \"Times New Roman\", serif";
15
+ /** The weights Strata's components use: body, medium labels, semibold and bold headings. */
16
+ export declare const FONT_WEIGHTS: readonly ["400", "500", "600", "700"];
17
+ /** The families in a `font-family` value, unquoted, in order. */
18
+ export declare function fontFamilies(value: string | undefined): string[];
19
+ /** The family a brand means: the first one named. */
20
+ export declare function primaryFamily(value: string | undefined): string;
21
+ /**
22
+ * A `font-family` value that never ends in the browser's default. The families
23
+ * the brand names come first, exactly as named; a generic fallback is added
24
+ * when none is there.
25
+ */
26
+ export declare function fontStack(value: string | undefined, fallback?: 'sans' | 'serif'): string;
27
+ export type FontStatus = {
28
+ kind: 'system';
29
+ family: string;
30
+ } | {
31
+ kind: 'loaded';
32
+ family: string;
33
+ weights: string[];
34
+ missingWeights: string[];
35
+ } | {
36
+ kind: 'missing';
37
+ family: string;
38
+ };
39
+ /** Whether pages will draw the family a brand names, and which weights it has files for. */
40
+ export declare function fontStatus(value: string | undefined, webFonts?: readonly WebFont[]): FontStatus;
41
+ export interface OpenFont {
42
+ family: string;
43
+ category: 'sans' | 'serif';
44
+ }
45
+ /**
46
+ * Open-licence families Strata fetches and stores itself, so a customer's
47
+ * browser loads them from Strata and never calls a third party.
48
+ */
49
+ export declare const OPEN_FONTS: readonly OpenFont[];
50
+ /** The open font of that name, if Strata can fetch it. */
51
+ export declare const openFont: (family: string) => OpenFont | undefined;
package/dist/index.d.ts CHANGED
@@ -7,9 +7,11 @@
7
7
  * set, and nothing exports a way to pin a derived value. See
8
8
  * [ADR 0010](../../../docs/decisions/0010-what-a-brand-may-set.md).
9
9
  */
10
- export { BrandInputsSchema, DEFAULT_BRAND_INPUTS, HexColorSchema, SurfaceValueSchema, TypeScaleSchema, WebFontSchema, type BrandInputs, type WebFont, } from './inputs';
10
+ export { BrandInputsSchema, DEFAULT_BRAND_INPUTS, HexColorSchema, SPACE_STEP_NAMES, SpaceStepSchema, SurfaceValueSchema, TypeScaleSchema, WebFontSchema, type BrandInputs, type SpaceStep, type WebFont, } from './inputs';
11
11
  export { deriveTokens, LOCKED_TOKENS, type TokenSet } from './derive';
12
- export { cssVarName, escapeStyleText, PREFIX, toCssDeclarations, toStyleProperties, toStylesheet, type StylesheetOptions, } from './css';
12
+ export { brandToVariables, INPUT_VARIABLE_PATHS, variablesToBrand, VARIABLES_FORMAT, VARIABLES_VERSION, type BrandVariable, type BrandVariables, type VariableChange, type VariablesImport, type VariableType, } from './variables';
13
+ export { cssVarName, escapeStyleText, fontFaceCss, PAGE_FRAME, PREFIX, toCssDeclarations, toStyleProperties, toStylesheet, type StylesheetOptions, } from './css';
13
14
  export { checkBrandContrast, checkContrast, type ContrastIssue, type ContrastReport, } from './validate';
14
15
  export { toDtcg, type DtcgGroup } from './dtcg';
15
16
  export { AA_LARGE_TEXT, AA_NON_TEXT, AA_TEXT, contrastRatio, darken, ensureContrast, lighten, luminance, mix, parseHex, pickForeground, tint, toHex, type Hex, type Rgb, } from './contrast';
17
+ export { FONT_WEIGHTS, fontFamilies, fontStack, fontStatus, OPEN_FONTS, openFont, primaryFamily, SYSTEM_SANS, SYSTEM_SERIF, type FontStatus, type OpenFont, } from './fonts';
package/dist/index.js CHANGED
@@ -1,11 +1,13 @@
1
1
  import {
2
+ PAGE_FRAME,
2
3
  PREFIX,
3
4
  cssVarName,
4
5
  escapeStyleText,
6
+ fontFaceCss,
5
7
  toCssDeclarations,
6
8
  toStyleProperties,
7
9
  toStylesheet
8
- } from "./chunk-YUZFJX3U.js";
10
+ } from "./chunk-7BKTXJHX.js";
9
11
 
10
12
  // packages/design-tokens/src/inputs.ts
11
13
  import { z } from "zod";
@@ -22,6 +24,8 @@ var WebFontSchema = z.object({
22
24
  display: z.string().optional()
23
25
  });
24
26
  var TypeScaleSchema = z.number().min(1.067).max(1.333);
27
+ var SPACE_STEP_NAMES = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"];
28
+ var SpaceStepSchema = z.enum(SPACE_STEP_NAMES);
25
29
  var BrandInputsSchema = z.object({
26
30
  color: z.strictObject({
27
31
  /** The partner's primary colour: actions, emphasis, selected states. */
@@ -61,6 +65,32 @@ var BrandInputsSchema = z.object({
61
65
  /** Default border weight in px. */
62
66
  borderWidth: z.number().min(1).max(3).default(1)
63
67
  }),
68
+ /**
69
+ * The page's frame and the spacing between columns.
70
+ *
71
+ * Margins and gutters name steps on the spacing scale rather than pixels,
72
+ * so they move with `shape.spaceBase` and stay on the same rhythm as
73
+ * everything else. The page width is bounded: below 640px a desktop page
74
+ * reads as a phone page, and above 1600px a line of text outgrows what can
75
+ * be read comfortably. Every value defaults to what pages had before this
76
+ * group existed, so a brand that sets none of it looks the same.
77
+ */
78
+ layout: z.strictObject({
79
+ /** The widest the content gets on a large screen, in px, inside the margins. */
80
+ pageWidth: z.number().min(640).max(1600).default(1200),
81
+ /** Space between the screen's edge and the content, at each size. */
82
+ margin: z.strictObject({
83
+ phone: SpaceStepSchema.default("4"),
84
+ tablet: SpaceStepSchema.default("6"),
85
+ desktop: SpaceStepSchema.default("8")
86
+ }).default({}),
87
+ /** The three gutters a grid may choose between columns. */
88
+ gutter: z.strictObject({
89
+ sm: SpaceStepSchema.default("2"),
90
+ md: SpaceStepSchema.default("4"),
91
+ lg: SpaceStepSchema.default("6")
92
+ }).default({})
93
+ }).default({}),
64
94
  assets: z.strictObject({
65
95
  logo: z.string(),
66
96
  logoAlt: z.string(),
@@ -87,6 +117,60 @@ var DEFAULT_BRAND_INPUTS = BrandInputsSchema.parse({
87
117
  assets: { logo: "", logoAlt: "" }
88
118
  });
89
119
 
120
+ // packages/design-tokens/src/fonts.ts
121
+ var SYSTEM_SANS = 'system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif';
122
+ var SYSTEM_SERIF = 'Georgia, Cambria, "Times New Roman", serif';
123
+ var GENERIC = /* @__PURE__ */ new Set(["serif", "sans-serif", "monospace", "cursive", "fantasy", "system-ui", "ui-sans-serif", "ui-serif", "ui-monospace", "ui-rounded", "math", "emoji"]);
124
+ var ON_EVERY_DEVICE = /* @__PURE__ */ new Set([...GENERIC, "-apple-system", "blinkmacsystemfont", "segoe ui", "helvetica", "helvetica neue", "arial", "georgia", "times new roman", "cambria", "courier new", "verdana", "tahoma", "trebuchet ms"]);
125
+ var FONT_WEIGHTS = ["400", "500", "600", "700"];
126
+ var unquote = (s) => s.trim().replace(/^['"]|['"]$/g, "").trim();
127
+ var quote = (s) => GENERIC.has(s.toLowerCase()) || s.startsWith("-") || /^[a-z0-9-]+$/i.test(s) ? s : JSON.stringify(s);
128
+ function fontFamilies(value) {
129
+ return (value ?? "").split(",").map(unquote).filter(Boolean);
130
+ }
131
+ function primaryFamily(value) {
132
+ return fontFamilies(value)[0] ?? "";
133
+ }
134
+ function fontStack(value, fallback = "sans") {
135
+ const named = fontFamilies(value);
136
+ if (named.some((f) => GENERIC.has(f.toLowerCase()))) return named.map(quote).join(", ");
137
+ const stack = fontFamilies(fallback === "serif" ? SYSTEM_SERIF : SYSTEM_SANS);
138
+ const seen = new Set(named.map((f) => f.toLowerCase()));
139
+ return [...named, ...stack.filter((f) => !seen.has(f.toLowerCase()))].map(quote).join(", ");
140
+ }
141
+ function fontStatus(value, webFonts = []) {
142
+ const family = primaryFamily(value);
143
+ if (!family || ON_EVERY_DEVICE.has(family.toLowerCase())) return { kind: "system", family: family || "system-ui" };
144
+ const faces = webFonts.filter((f) => f.url && f.family.toLowerCase() === family.toLowerCase() && (f.style ?? "normal") === "normal");
145
+ if (!faces.length) return { kind: "missing", family };
146
+ const covers = (w) => faces.some((f) => !f.weight || f.weight === w || /^\d+ \d+$/.test(f.weight) && Number(f.weight.split(" ")[0]) <= Number(w) && Number(w) <= Number(f.weight.split(" ")[1]));
147
+ const weights = FONT_WEIGHTS.filter(covers);
148
+ return { kind: "loaded", family, weights, missingWeights: FONT_WEIGHTS.filter((w) => !covers(w)) };
149
+ }
150
+ var OPEN_FONTS = [
151
+ { family: "Inter", category: "sans" },
152
+ { family: "Roboto", category: "sans" },
153
+ { family: "Open Sans", category: "sans" },
154
+ { family: "Lato", category: "sans" },
155
+ { family: "Montserrat", category: "sans" },
156
+ { family: "Poppins", category: "sans" },
157
+ { family: "Nunito Sans", category: "sans" },
158
+ { family: "Source Sans 3", category: "sans" },
159
+ { family: "Work Sans", category: "sans" },
160
+ { family: "DM Sans", category: "sans" },
161
+ { family: "IBM Plex Sans", category: "sans" },
162
+ { family: "Manrope", category: "sans" },
163
+ { family: "Plus Jakarta Sans", category: "sans" },
164
+ { family: "Figtree", category: "sans" },
165
+ { family: "Raleway", category: "sans" },
166
+ { family: "Merriweather", category: "serif" },
167
+ { family: "Lora", category: "serif" },
168
+ { family: "Playfair Display", category: "serif" },
169
+ { family: "Source Serif 4", category: "serif" },
170
+ { family: "IBM Plex Serif", category: "serif" }
171
+ ];
172
+ var openFont = (family) => OPEN_FONTS.find((f) => f.family.toLowerCase() === family.trim().toLowerCase());
173
+
90
174
  // packages/design-tokens/src/contrast.ts
91
175
  var HEX = /^#?([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
92
176
  function parseHex(value) {
@@ -219,6 +303,7 @@ function typeRamp(sizeBase, scale) {
219
303
  }
220
304
  function deriveTokens(input) {
221
305
  const { color, font, shape } = input;
306
+ const layout = input.layout ?? BrandInputsSchema.shape.layout.parse(void 0);
222
307
  const card = color.surfaceCard;
223
308
  const accent = color.accent ?? color.brand;
224
309
  const tokens = { ...LOCKED_TOKENS };
@@ -254,8 +339,9 @@ function deriveTokens(input) {
254
339
  tokens[`color.status.${name}.subtle`] = tint(base);
255
340
  tokens[`color.status.${name}.on`] = pickForeground(base);
256
341
  }
257
- tokens["font.family.body"] = font.body;
258
- tokens["font.family.heading"] = font.heading ?? font.body;
342
+ const fallbackFor = (value) => openFont(primaryFamily(value))?.category === "serif" ? "serif" : "sans";
343
+ tokens["font.family.body"] = fontStack(font.body, fallbackFor(font.body));
344
+ tokens["font.family.heading"] = fontStack(font.heading ?? font.body, fallbackFor(font.heading ?? font.body));
259
345
  tokens["font.size.root"] = `${font.sizeBase}px`;
260
346
  Object.assign(tokens, typeRamp(font.sizeBase, font.scale));
261
347
  tokens["font.weight.regular"] = "400";
@@ -276,9 +362,134 @@ function deriveTokens(input) {
276
362
  tokens["radius.full"] = "9999px";
277
363
  tokens["border.width.thin"] = `${shape.borderWidth}px`;
278
364
  tokens["border.width.thick"] = `${shape.borderWidth * 2}px`;
365
+ const step = (name) => `${shape.spaceBase * (SPACE_STEPS[name] ?? 0)}px`;
366
+ tokens["layout.page.width"] = `${layout.pageWidth}px`;
367
+ tokens["layout.margin.phone"] = step(layout.margin.phone);
368
+ tokens["layout.margin.tablet"] = step(layout.margin.tablet);
369
+ tokens["layout.margin.desktop"] = step(layout.margin.desktop);
370
+ tokens["layout.gutter.sm"] = step(layout.gutter.sm);
371
+ tokens["layout.gutter.md"] = step(layout.gutter.md);
372
+ tokens["layout.gutter.lg"] = step(layout.gutter.lg);
279
373
  return tokens;
280
374
  }
281
375
 
376
+ // packages/design-tokens/src/variables.ts
377
+ var VARIABLES_FORMAT = "strata.brand-variables";
378
+ var VARIABLES_VERSION = 1;
379
+ var STEP_MULTIPLES = { "0": 0, "1": 1, "2": 2, "3": 3, "4": 4, "5": 6, "6": 8, "7": 12, "8": 16, "9": 24, "10": 32 };
380
+ var HEX2 = /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;
381
+ var INPUTS = [
382
+ { path: "color.brand", name: "color/brand" },
383
+ { path: "color.accent", name: "color/accent" },
384
+ { path: "color.surfacePage", name: "color/surface/page", description: "May be a gradient; carries no text." },
385
+ { path: "color.surfaceCard", name: "color/surface/card" },
386
+ { path: "color.surfaceHeader", name: "color/surface/header" },
387
+ { path: "color.surfaceFooter", name: "color/surface/footer" },
388
+ { path: "color.text", name: "color/text" },
389
+ { path: "color.danger", name: "color/status/danger" },
390
+ { path: "color.warning", name: "color/status/warning" },
391
+ { path: "color.success", name: "color/status/success" },
392
+ { path: "color.info", name: "color/status/info" },
393
+ { path: "font.body", name: "font/body" },
394
+ { path: "font.heading", name: "font/heading" },
395
+ { path: "font.sizeBase", name: "font/size-base", description: "Root size in px, 14 to 20." },
396
+ { path: "font.scale", name: "font/scale", description: "Type ramp ratio, 1.067 to 1.333." },
397
+ { path: "shape.radiusBase", name: "shape/radius", description: "Corner radius in px, 0 to 24." },
398
+ { path: "shape.spaceBase", name: "shape/space-unit", description: "The spacing unit in px, 2 to 8." },
399
+ { path: "shape.borderWidth", name: "shape/border-width", description: "Border weight in px, 1 to 3." },
400
+ { path: "layout.pageWidth", name: "layout/page-width", description: "Widest content in px, 640 to 1600." },
401
+ { path: "layout.margin.phone", name: "layout/margin/phone", step: true },
402
+ { path: "layout.margin.tablet", name: "layout/margin/tablet", step: true },
403
+ { path: "layout.margin.desktop", name: "layout/margin/desktop", step: true },
404
+ { path: "layout.gutter.sm", name: "layout/gutter/sm", step: true },
405
+ { path: "layout.gutter.md", name: "layout/gutter/md", step: true },
406
+ { path: "layout.gutter.lg", name: "layout/gutter/lg", step: true }
407
+ ];
408
+ var STEP_HINT = "A step on the spacing scale, in px: a multiple of the space unit (1, 2, 3, 4, 6, 8, 12, 16, 24 or 32 times).";
409
+ var read = (source, path) => path.split(".").reduce((at, key) => at && typeof at === "object" ? at[key] : void 0, source);
410
+ function write(target, path, value) {
411
+ const keys = path.split(".");
412
+ let at = target;
413
+ for (const key of keys.slice(0, -1)) at = at[key] ??= {};
414
+ at[keys[keys.length - 1]] = value;
415
+ }
416
+ function brandToVariables(brand, site) {
417
+ const inputs = BrandInputsSchema.parse(brand);
418
+ const unit = inputs.shape.spaceBase;
419
+ const fromInputs = [];
420
+ for (const spec of INPUTS) {
421
+ let value = read(inputs, spec.path);
422
+ if (value === void 0 && spec.path === "color.accent") value = inputs.color.brand;
423
+ if (value === void 0 && spec.path === "font.heading") value = inputs.font.body;
424
+ if (value === void 0) continue;
425
+ if (spec.step) {
426
+ fromInputs.push({ name: spec.name, path: spec.path, type: "FLOAT", value: unit * (STEP_MULTIPLES[String(value)] ?? 0), description: STEP_HINT });
427
+ continue;
428
+ }
429
+ const type = typeof value === "number" ? "FLOAT" : spec.path.startsWith("color.") && HEX2.test(String(value)) ? "COLOR" : "STRING";
430
+ fromInputs.push({ name: spec.name, path: spec.path, type, value, ...spec.description ? { description: spec.description } : {} });
431
+ }
432
+ const derived = [];
433
+ for (const [path, value] of Object.entries(deriveTokens(inputs))) {
434
+ const name = path.replace(/\./g, "/");
435
+ if (HEX2.test(value)) derived.push({ name, path, type: "COLOR", value });
436
+ else if (/^-?[\d.]+px$/.test(value)) derived.push({ name, path, type: "FLOAT", value: Number.parseFloat(value) });
437
+ else if (/^-?[\d.]+$/.test(value)) derived.push({ name, path, type: "FLOAT", value: Number(value) });
438
+ else derived.push({ name, path, type: "STRING", value });
439
+ }
440
+ return { format: VARIABLES_FORMAT, version: VARIABLES_VERSION, site, inputs: fromInputs, derived };
441
+ }
442
+ function variablesToBrand(document, base) {
443
+ const doc = document;
444
+ if (!doc || doc.format !== VARIABLES_FORMAT || !Array.isArray(doc.inputs)) {
445
+ return { ok: false, problems: ["This is not a Strata brand variables export."] };
446
+ }
447
+ const current = BrandInputsSchema.parse(base);
448
+ const next = structuredClone(current);
449
+ const problems = [];
450
+ const changes = [];
451
+ const unitVariable = doc.inputs.find((v) => v.path === "shape.spaceBase");
452
+ const unit = typeof unitVariable?.value === "number" ? unitVariable.value : current.shape.spaceBase;
453
+ for (const variable of doc.inputs) {
454
+ const spec = INPUTS.find((s) => s.path === variable?.path);
455
+ if (!spec) continue;
456
+ let value = variable.value;
457
+ if (typeof value === "number") value = Math.round(value * 1e4) / 1e4;
458
+ if (spec.step) {
459
+ const step = typeof value === "number" ? SPACE_STEP_NAMES.find((name) => unit * (STEP_MULTIPLES[name] ?? -1) === value) : void 0;
460
+ if (!step) {
461
+ problems.push(`${spec.name} is ${String(value)}px, which is not a step on the spacing scale at a ${unit}px unit.`);
462
+ continue;
463
+ }
464
+ value = step;
465
+ }
466
+ if (typeof value === "string" && spec.path.startsWith("color.") && HEX2.test(value)) value = value.toLowerCase();
467
+ const was = read(current, spec.path);
468
+ write(next, spec.path, value);
469
+ const comparable = (v) => typeof v === "string" ? v.toLowerCase() : v;
470
+ if (comparable(was) !== comparable(value) && !(was === void 0 && (spec.path === "color.accent" || spec.path === "font.heading") && value === (spec.path === "color.accent" ? current.color.brand : current.font.body))) {
471
+ const show = (v, at) => v === void 0 ? "not set" : spec.step ? `${at * (STEP_MULTIPLES[String(v)] ?? 0)}px` : String(v);
472
+ changes.push({ path: spec.path, name: spec.name, from: was, to: value, shown: { from: show(was, current.shape.spaceBase), to: show(value, unit) } });
473
+ }
474
+ }
475
+ const parsed = BrandInputsSchema.safeParse(next);
476
+ if (!parsed.success) {
477
+ for (const issue of parsed.error.issues) {
478
+ const path = issue.path.join(".");
479
+ const spec = INPUTS.find((s) => s.path === path);
480
+ if (!spec) {
481
+ problems.push(`${path}: ${issue.message}`);
482
+ continue;
483
+ }
484
+ const sent = doc.inputs.find((v) => v?.path === path)?.value;
485
+ problems.push(`${spec.name} is ${JSON.stringify(sent)}. ${issue.message.replace(/\.?$/, ".")}`);
486
+ }
487
+ }
488
+ if (problems.length || !parsed.success) return { ok: false, problems };
489
+ return { ok: true, inputs: parsed.data, changes };
490
+ }
491
+ var INPUT_VARIABLE_PATHS = Object.fromEntries(INPUTS.map((spec) => [spec.name, spec.path]));
492
+
282
493
  // packages/design-tokens/src/validate.ts
283
494
  var isMeasurable = (value) => parseHex(value) !== null;
284
495
  function pairsFor(tokens) {
@@ -364,12 +575,23 @@ export {
364
575
  AA_TEXT,
365
576
  BrandInputsSchema,
366
577
  DEFAULT_BRAND_INPUTS,
578
+ FONT_WEIGHTS,
367
579
  HexColorSchema,
580
+ INPUT_VARIABLE_PATHS,
368
581
  LOCKED_TOKENS,
582
+ OPEN_FONTS,
583
+ PAGE_FRAME,
369
584
  PREFIX,
585
+ SPACE_STEP_NAMES,
586
+ SYSTEM_SANS,
587
+ SYSTEM_SERIF,
588
+ SpaceStepSchema,
370
589
  SurfaceValueSchema,
371
590
  TypeScaleSchema,
591
+ VARIABLES_FORMAT,
592
+ VARIABLES_VERSION,
372
593
  WebFontSchema,
594
+ brandToVariables,
373
595
  checkBrandContrast,
374
596
  checkContrast,
375
597
  contrastRatio,
@@ -378,16 +600,23 @@ export {
378
600
  deriveTokens,
379
601
  ensureContrast,
380
602
  escapeStyleText,
603
+ fontFaceCss,
604
+ fontFamilies,
605
+ fontStack,
606
+ fontStatus,
381
607
  lighten,
382
608
  luminance,
383
609
  mix,
610
+ openFont,
384
611
  parseHex,
385
612
  pickForeground,
613
+ primaryFamily,
386
614
  tint,
387
615
  toCssDeclarations,
388
616
  toDtcg,
389
617
  toHex,
390
618
  toStyleProperties,
391
- toStylesheet
619
+ toStylesheet,
620
+ variablesToBrand
392
621
  };
393
622
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/inputs.ts","../src/contrast.ts","../src/derive.ts","../src/validate.ts","../src/dtcg.ts"],"sourcesContent":["/**\n * Brand inputs — everything a partner may set, and nothing else.\n *\n * The list is closed, and it is short on purpose. Stripe's Appearance API gets\n * almost all of its brand expression from eight variables and derives the rest;\n * Cloudscape allows typography, colour and border radius and refuses the\n * question beyond that; the legacy Sanity CMS this replaces allowed everything\n * and accumulated forty per-viewport override fields nobody could prune. The\n * reasoning, with sources, is\n * [ADR 0010](../../../docs/decisions/0010-what-a-brand-may-set.md).\n *\n * Two absences are the point of the whole file. There is no foreground colour\n * anywhere — text on a surface is computed, so a partner cannot pin white text\n * onto a mid-tone brand colour. And there is no focus colour — the ring keeps\n * system values, because a focus indicator drawn in a partner's own brand\n * colour on that partner's own background is where focus visibility dies.\n */\nimport { z } from 'zod';\n\n/** A hex colour. The only colour form the inputs accept. */\nexport const HexColorSchema = z\n .string()\n .regex(/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/, 'Must be a hex colour, e.g. #5e10b1');\n\n/**\n * The page background, which may be a gradient.\n *\n * It is the one exception and it is safe by construction rather than by\n * exception: the page background never carries text directly — text sits on a\n * card — so it is the only surface with nothing to contrast against. Northwind\n * Plus's shell is a three-stop gradient, which is a real requirement and\n * would otherwise need an escape hatch.\n */\nexport const SurfaceValueSchema = z.union([\n HexColorSchema,\n z.string().regex(/^(linear|radial|conic)-gradient\\(.+\\)$/, 'Must be a hex colour or a CSS gradient'),\n]);\n\nexport const WebFontSchema = z.object({\n family: z.string(),\n url: z.string(),\n weight: z.string().optional(),\n style: z.string().optional(),\n display: z.string().optional(),\n});\nexport type WebFont = z.infer<typeof WebFontSchema>;\n\n/**\n * The type ramp ratio.\n *\n * Bounded rather than free. Below 1.067 the ramp stops distinguishing levels\n * and heading structure becomes invisible to a sighted reader even though the\n * markup is correct; above 1.333 the top of the scale overflows a 360px\n * viewport at 200% zoom, which fails 1.4.4. A partner who wants bigger headings\n * raises the base size.\n */\nexport const TypeScaleSchema = z.number().min(1.067).max(1.333);\n\n/**\n * Each group is `.strict()`.\n *\n * Zod strips unknown keys by default, so `color.onBrand` would validate, be\n * dropped, and leave an editor looking at a brand that ignores a value they\n * set. Rejecting it says what is actually true: there is nowhere to put a\n * foreground colour, because foregrounds are measured.\n */\nexport const BrandInputsSchema = z.object({\n color: z.strictObject({\n /** The partner's primary colour: actions, emphasis, selected states. */\n brand: HexColorSchema,\n /** The secondary colour. Defaults to the brand colour when unset. */\n accent: HexColorSchema.optional(),\n\n /** The page behind everything. May be a gradient; carries no text. */\n surfacePage: SurfaceValueSchema,\n /** Where content actually sits, and what text is read against. */\n surfaceCard: HexColorSchema,\n /** The header band. */\n surfaceHeader: HexColorSchema,\n /** The footer band. */\n surfaceFooter: HexColorSchema,\n\n /** Default body text, on `surfaceCard`. */\n text: HexColorSchema,\n\n danger: HexColorSchema,\n warning: HexColorSchema,\n success: HexColorSchema,\n info: HexColorSchema,\n }),\n\n font: z.strictObject({\n body: z.string(),\n /** Defaults to `body` when unset — most brands have one typeface. */\n heading: z.string().optional(),\n /** Root size in px. Everything else is `rem`, scaled from this. */\n sizeBase: z.number().min(14).max(20).default(16),\n scale: TypeScaleSchema.default(1.2),\n /** Faces the shell must load. A partner brings its own typeface. */\n webFonts: z.array(WebFontSchema).default([]),\n }),\n\n shape: z.strictObject({\n /** Corner rounding in px. Every radius derives from it. */\n radiusBase: z.number().min(0).max(24).default(4),\n /** The spacing unit in px. All spacing is a multiple. */\n spaceBase: z.number().min(2).max(8).default(4),\n /** Default border weight in px. */\n borderWidth: z.number().min(1).max(3).default(1),\n }),\n\n assets: z.strictObject({\n logo: z.string(),\n logoAlt: z.string(),\n /** For use on dark surfaces, where the main logo would disappear. */\n logoDark: z.string().optional(),\n favicon: z.string().optional(),\n }),\n});\n\nexport type BrandInputs = z.infer<typeof BrandInputsSchema>;\n\n/**\n * The house defaults — a complete, neutral, AA-passing brand.\n *\n * Every input is optional at the edges of the system because this exists: a\n * site with no brand document still renders something legible rather than\n * unstyled, which is what makes a missing brand a visible problem instead of a\n * broken page.\n */\nexport const DEFAULT_BRAND_INPUTS: BrandInputs = BrandInputsSchema.parse({\n color: {\n brand: '#1f4ed8',\n surfacePage: '#f4f5f7',\n surfaceCard: '#ffffff',\n surfaceHeader: '#ffffff',\n surfaceFooter: '#1f2430',\n text: '#1a1a1a',\n danger: '#c8102e',\n warning: '#b45309',\n success: '#047857',\n info: '#1f4ed8',\n },\n font: { body: 'system-ui, -apple-system, \"Segoe UI\", Roboto, sans-serif' },\n shape: {},\n assets: { logo: '', logoAlt: '' },\n});\n","/**\n * Contrast maths, to WCAG 2.x.\n *\n * This file exists because of one decision: a partner never authors a text\n * colour to sit on a background ([ADR 0010](../../../docs/decisions/0010-what-a-brand-may-set.md)).\n * They pick a brand colour and the system picks what reads on top of it. That\n * makes the most common white-label accessibility failure — a mid-tone brand\n * colour under a white label — unrepresentable rather than merely discouraged.\n *\n * The formulae are from WCAG 2.2 (relative luminance, and the (L1+0.05)/(L2+0.05)\n * contrast ratio). They are stable, cheap and exactly what an auditor will use.\n * APCA is better maths and is not normative yet; when it is, this is the one\n * file that changes.\n */\n\n/** A colour this module can reason about: #rgb, #rrggbb, or #rrggbbaa. */\nexport type Hex = string;\n\nexport interface Rgb {\n r: number;\n g: number;\n b: number;\n}\n\nconst HEX = /^#?([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i;\n\n/**\n * Parse a hex colour. Returns null rather than throwing: callers are usually\n * validating authored content, where \"this is not a colour\" is a message to an\n * editor and not an exception.\n */\nexport function parseHex(value: string): Rgb | null {\n const m = HEX.exec(value.trim());\n if (!m) return null;\n let h = m[1];\n if (h.length === 3) h = h.split('').map((c) => c + c).join('');\n return {\n r: parseInt(h.slice(0, 2), 16),\n g: parseInt(h.slice(2, 4), 16),\n b: parseInt(h.slice(4, 6), 16),\n };\n}\n\nexport function toHex({ r, g, b }: Rgb): Hex {\n const c = (n: number) => Math.round(Math.min(255, Math.max(0, n))).toString(16).padStart(2, '0');\n return `#${c(r)}${c(g)}${c(b)}`;\n}\n\n/** WCAG relative luminance. */\nexport function luminance(rgb: Rgb): number {\n const channel = (v: number) => {\n const s = v / 255;\n return s <= 0.03928 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;\n };\n return 0.2126 * channel(rgb.r) + 0.7152 * channel(rgb.g) + 0.0722 * channel(rgb.b);\n}\n\n/** WCAG contrast ratio, 1–21. Returns 0 for anything unparseable. */\nexport function contrastRatio(a: string, b: string): number {\n const ra = parseHex(a);\n const rb = parseHex(b);\n if (!ra || !rb) return 0;\n const la = luminance(ra);\n const lb = luminance(rb);\n const [hi, lo] = la > lb ? [la, lb] : [lb, la];\n return (hi + 0.05) / (lo + 0.05);\n}\n\n/** The thresholds, named, so call sites read as the criterion they enforce. */\nexport const AA_TEXT = 4.5;\nexport const AA_LARGE_TEXT = 3;\n/** 1.4.11 Non-text Contrast: UI components and meaningful graphics. */\nexport const AA_NON_TEXT = 3;\n\n/**\n * The two foregrounds anything may be drawn in.\n *\n * Not pure black and white. Pure black on a light surface is harsher than it\n * needs to be and pure white on a saturated brand colour haloes; these are the\n * near-neutrals most systems settle on, and they still clear 4.5:1 against\n * every surface the inputs can produce — which the tests assert rather than\n * assume.\n */\nexport const FOREGROUND_DARK = '#1a1a1a';\nexport const FOREGROUND_LIGHT = '#ffffff';\n\n/**\n * Pick the foreground that reads best on `background`.\n *\n * Deliberately returns the BETTER of the two rather than the first that passes.\n * On a mid-tone brand colour both may clear 4.5:1 and the winner is still\n * visibly easier to read; on a colour where neither passes, the better one is\n * what gets rendered while the publish check reports the failure. A caller that\n * needs to know whether it passed asks `contrastRatio` — this function always\n * answers.\n */\nexport function pickForeground(background: string): Hex {\n const dark = contrastRatio(background, FOREGROUND_DARK);\n const light = contrastRatio(background, FOREGROUND_LIGHT);\n return dark >= light ? FOREGROUND_DARK : FOREGROUND_LIGHT;\n}\n\n/**\n * Shift a colour toward black or white by `amount` (0–1).\n *\n * This is how every hover, active and subtle state is derived. Mixing in sRGB\n * is not perceptually uniform and a perceptual space would give more even\n * steps; sRGB is used because it is what CSS `color-mix` does, so a value\n * derived here and a value a stylesheet computes agree. Matching the platform\n * matters more here than being slightly more correct than it.\n */\nexport function shade(color: string, amount: number): Hex {\n const rgb = parseHex(color);\n if (!rgb) return color;\n const t = amount < 0 ? 255 : 0;\n const k = Math.abs(amount);\n return toHex({\n r: rgb.r + (t - rgb.r) * k,\n g: rgb.g + (t - rgb.g) * k,\n b: rgb.b + (t - rgb.b) * k,\n });\n}\n\n/** Darken toward black. */\nexport const darken = (color: string, amount: number): Hex => shade(color, amount);\n/** Lighten toward white. */\nexport const lighten = (color: string, amount: number): Hex => shade(color, -amount);\n\n/**\n * A very light tint of a colour, for subtle backgrounds — an info panel, a\n * selected row. Always light enough to take the dark foreground, which is what\n * makes \"subtle\" a safe surface rather than a guess.\n */\nexport const tint = (color: string): Hex => lighten(color, 0.88);\n\n/** Blend two colours. `amount` is how far from `a` toward `b`. */\nexport function mix(a: string, b: string, amount: number): Hex {\n const ra = parseHex(a);\n const rb = parseHex(b);\n if (!ra || !rb) return a;\n const k = Math.min(1, Math.max(0, amount));\n return toHex({\n r: ra.r + (rb.r - ra.r) * k,\n g: ra.g + (rb.g - ra.g) * k,\n b: ra.b + (rb.b - ra.b) * k,\n });\n}\n\n/**\n * Walk a foreground away from its background until it clears `target`.\n *\n * This is the mechanism that makes a derived token safe rather than merely\n * plausible. Muted text, placeholder text and borders are all produced by\n * blending toward a surface, and a blend that looks right on one brand falls\n * under 4.5:1 on the next. Rather than pick a blend that happens to work for\n * the brands we have, each derived value is pushed back until it passes.\n *\n * It moves toward whichever end of the scale is already further from the\n * background, in small steps, and gives up after it runs out of room — at\n * which point the colour is returned as-is and the publish check reports it.\n * Silently returning black would hide a brand that cannot work.\n */\nexport function ensureContrast(foreground: string, background: string, target: number): Hex {\n const fg = parseHex(foreground);\n const bg = parseHex(background);\n if (!fg || !bg) return foreground;\n if (contrastRatio(foreground, background) >= target) return toHex(fg);\n\n const toward = luminance(bg) > 0.5 ? FOREGROUND_DARK : FOREGROUND_LIGHT;\n let current = toHex(fg);\n for (let step = 1; step <= 20; step += 1) {\n current = mix(toHex(fg), toward, step / 20);\n if (contrastRatio(current, background) >= target) return current;\n }\n return current;\n}\n","/**\n * Brand inputs → the semantic tokens components actually read.\n *\n * This is the whole argument of\n * [ADR 0010](../../../docs/decisions/0010-what-a-brand-may-set.md) in executable\n * form: around twenty authored values go in, roughly a hundred come out, and\n * the hundred are not authorable. A partner who wants a different hover colour\n * is describing a change to this function, which is a product decision with a\n * version number, rather than a field in a CMS nobody can later prune.\n *\n * Three rules run through it. Foregrounds are always picked by measured\n * contrast, never authored. Anything that carries text is ratcheted until it\n * passes AA rather than trusted to. And the focus ring and the minimum target\n * size are constants, because they are the two things a brand would break first\n * and notice last.\n */\nimport {\n AA_NON_TEXT,\n AA_TEXT,\n darken,\n ensureContrast,\n luminance,\n mix,\n parseHex,\n pickForeground,\n tint,\n} from './contrast';\nimport type { BrandInputs } from './inputs';\n\n/** A flat token set: dotted path → CSS value. */\nexport type TokenSet = Record<string, string>;\n\n/**\n * The locked tokens. A brand cannot reach these and nothing derives them.\n *\n * The focus ring is two-tone — a light inner ring inside a dark outer one — so\n * that it stays visible on any surface a partner can produce, including their\n * own brand colour. A single-colour ring has to assume a background, and the\n * one it assumes is the one a white-label product does not have. This is the\n * rule Scotland's design system states directly: adopters may change the\n * colours, and must still keep the system's colours for focus.\n *\n * `target.min` is WCAG 2.2's 2.5.8 minimum. It is here rather than in the\n * spacing scale so that shrinking the spacing unit cannot shrink a tap target.\n */\nexport const LOCKED_TOKENS: TokenSet = {\n 'focus.ring.inner': '#ffffff',\n 'focus.ring.outer': '#1a1a1a',\n 'focus.ring.width': '2px',\n 'focus.ring.offset': '2px',\n 'focus.ring.shadow': '0 0 0 2px #ffffff, 0 0 0 4px #1a1a1a',\n 'target.min': '24px',\n 'target.spacing': '8px',\n};\n\n/** Spacing steps, as multiples of the base unit. */\nconst SPACE_STEPS: Record<string, number> = {\n '0': 0, '1': 1, '2': 2, '3': 3, '4': 4,\n '5': 6, '6': 8, '7': 12, '8': 16, '9': 24, '10': 32,\n};\n\n/** Type ramp, as powers of the scale ratio either side of the base. */\nconst TYPE_STEPS: Record<string, number> = {\n '2xs': -3, xs: -2, sm: -1, md: 0, lg: 1, xl: 2, '2xl': 3, '3xl': 4,\n};\n\n/**\n * The smallest text the ramp may produce, in px.\n *\n * A 1.333 ratio three steps below a 14px base lands at 5.9px. Clamping here\n * rather than narrowing the ratio keeps the top of the ramp expressive while\n * stopping the bottom from becoming unreadable.\n */\nconst MIN_FONT_PX = 12;\n\n/**\n * The text colour for a branded band — the header, the footer.\n *\n * Not simply the picked foreground, because that throws away real brand\n * expression: Northwind's header is white with dark-purple text, and deriving\n * near-black there would be legible and wrong. On a LIGHT band the accent\n * colour is used, ratcheted until it passes, which is what partners actually\n * do and what every migrated theme authored. On a DARK band the picked\n * foreground wins, because coloured text on a saturated brand background is\n * exactly where legibility goes, and a washed-out tint of the band's own\n * colour is worse than white.\n *\n * An unparseable surface — a gradient — is treated as dark, since a gradient\n * is only allowed on the page and the page is the one band nothing sits on.\n */\nfunction onSurface(surface: string, accent: string): string {\n const rgb = parseHex(surface);\n if (!rgb) return pickForeground('#000000');\n return luminance(rgb) > 0.5 ? ensureContrast(accent, surface, AA_TEXT) : pickForeground(surface);\n}\n\nfunction typeRamp(sizeBase: number, scale: number): TokenSet {\n const out: TokenSet = {};\n for (const [name, step] of Object.entries(TYPE_STEPS)) {\n const px = Math.max(MIN_FONT_PX, sizeBase * scale ** step);\n // Round UP at four places. Rounding to nearest loses the 12px floor by a\n // ten-thousandth, which is invisible until a test asserts the floor and\n // fails — and the floor is the accessibility claim, so it rounds its way.\n const rem = Math.ceil((px / sizeBase) * 10000) / 10000;\n out[`font.size.${name}`] = `${rem}rem`;\n }\n return out;\n}\n\nexport function deriveTokens(input: BrandInputs): TokenSet {\n const { color, font, shape } = input;\n const card = color.surfaceCard;\n const accent = color.accent ?? color.brand;\n\n const tokens: TokenSet = { ...LOCKED_TOKENS };\n\n // --- surfaces ------------------------------------------------------------\n // `page` is the only one that may be a gradient, and the only one nothing is\n // read against. `inset` is for wells and disabled fields: a step away from\n // the card in whichever direction the card is not.\n tokens['color.surface.page'] = color.surfacePage;\n tokens['color.surface.card'] = card;\n tokens['color.surface.header'] = color.surfaceHeader;\n tokens['color.surface.footer'] = color.surfaceFooter;\n tokens['color.surface.subtle'] = tint(color.brand);\n tokens['color.surface.inset'] = mix(card, pickForeground(card), 0.05);\n\n // --- brand ---------------------------------------------------------------\n // Hover and active are tone shifts rather than authored colours. The\n // direction is fixed: darker on interaction, because a lighter hover on a\n // light surface reads as disabled.\n tokens['color.brand.default'] = color.brand;\n tokens['color.brand.hover'] = darken(color.brand, 0.12);\n tokens['color.brand.active'] = darken(color.brand, 0.24);\n tokens['color.brand.subtle'] = tint(color.brand);\n tokens['color.brand.on'] = pickForeground(color.brand);\n\n tokens['color.accent.default'] = accent;\n tokens['color.accent.hover'] = darken(accent, 0.12);\n tokens['color.accent.on'] = pickForeground(accent);\n\n // --- text ----------------------------------------------------------------\n // Muted and placeholder are blends toward the surface, then ratcheted back\n // until they clear AA. Placeholder is included deliberately: it is routinely\n // treated as exempt and 1.4.3 does not exempt it.\n tokens['color.text.default'] = ensureContrast(color.text, card, AA_TEXT);\n tokens['color.text.muted'] = ensureContrast(mix(color.text, card, 0.38), card, AA_TEXT);\n tokens['color.text.placeholder'] = ensureContrast(mix(color.text, card, 0.5), card, AA_TEXT);\n tokens['color.text.on-brand'] = pickForeground(color.brand);\n tokens['color.text.on-header'] = onSurface(color.surfaceHeader, accent);\n tokens['color.text.on-footer'] = onSurface(color.surfaceFooter, accent);\n // A link is the brand colour where that is readable, and a darkened brand\n // colour where it is not — so a partner with a pale brand still gets links\n // that look like theirs.\n // Headings take the accent colour. The legacy schema had an authored\n // `typography.headingColor`, and on every migrated theme it was the secondary\n // colour — so deriving it reproduces them exactly and removes a field whose\n // only job was to restate another one.\n tokens['color.text.heading'] = ensureContrast(accent, card, AA_TEXT);\n tokens['color.text.link'] = ensureContrast(color.brand, card, AA_TEXT);\n tokens['color.text.link-hover'] = darken(tokens['color.text.link'], 0.2);\n\n // --- borders -------------------------------------------------------------\n // 1.4.11 governs these: a field border is a UI component boundary, so 3:1,\n // not 4.5:1.\n tokens['color.border.default'] = ensureContrast(mix(color.text, card, 0.7), card, AA_NON_TEXT);\n tokens['color.border.strong'] = ensureContrast(mix(color.text, card, 0.45), card, AA_NON_TEXT);\n\n // --- status --------------------------------------------------------------\n // Each gets three: the colour itself at UI contrast, a tint to sit behind it,\n // and the foreground that reads on it. `*.text` is separate from `*.default`\n // because the same red that is fine as a 3:1 border is not fine as 4.5:1 body\n // text, and conflating them is how error messages end up unreadable.\n for (const name of ['danger', 'warning', 'success', 'info'] as const) {\n const base = color[name];\n tokens[`color.status.${name}.default`] = ensureContrast(base, card, AA_NON_TEXT);\n tokens[`color.status.${name}.text`] = ensureContrast(base, card, AA_TEXT);\n tokens[`color.status.${name}.subtle`] = tint(base);\n tokens[`color.status.${name}.on`] = pickForeground(base);\n }\n\n // --- typography ----------------------------------------------------------\n tokens['font.family.body'] = font.body;\n tokens['font.family.heading'] = font.heading ?? font.body;\n tokens['font.size.root'] = `${font.sizeBase}px`;\n Object.assign(tokens, typeRamp(font.sizeBase, font.scale));\n tokens['font.weight.regular'] = '400';\n tokens['font.weight.medium'] = '500';\n tokens['font.weight.semibold'] = '600';\n tokens['font.weight.bold'] = '700';\n // 1.4.8 asks for 1.5 within a paragraph; `tight` is for headings, where it\n // does not apply.\n tokens['font.line-height.tight'] = '1.25';\n tokens['font.line-height.normal'] = '1.5';\n tokens['font.line-height.relaxed'] = '1.75';\n\n // --- space, radius, border width -----------------------------------------\n for (const [name, multiple] of Object.entries(SPACE_STEPS)) {\n tokens[`space.${name}`] = `${shape.spaceBase * multiple}px`;\n }\n tokens['radius.none'] = '0';\n tokens['radius.sm'] = `${shape.radiusBase / 2}px`;\n tokens['radius.md'] = `${shape.radiusBase}px`;\n tokens['radius.lg'] = `${shape.radiusBase * 2}px`;\n tokens['radius.xl'] = `${shape.radiusBase * 3}px`;\n tokens['radius.full'] = '9999px';\n tokens['border.width.thin'] = `${shape.borderWidth}px`;\n tokens['border.width.thick'] = `${shape.borderWidth * 2}px`;\n\n return tokens;\n}\n","/**\n * The contrast gate.\n *\n * Derivation means most pairs cannot fail — a foreground is picked by measured\n * contrast and a blend is ratcheted until it passes. What is left are the pairs\n * a partner controls both sides of: their brand colour against their own\n * surfaces, their text against their own card, and their status colours\n * against it. Those are checked here, and a failure blocks a publish the way a\n * dangling reference already does\n * ([ADR 0009](../../../docs/decisions/0009-wcag-is-an-authoring-gate.md)).\n *\n * This is a floor, not a certificate. It is arithmetic over colour pairs: it\n * cannot see a value rendered on an image, text baked into a logo, or a\n * disabled control whose contrast is exempt but whose meaning is not. Treating\n * a green build as \"the brand is accessible\" is the failure mode to guard\n * against, which is why the result says what it checked.\n */\nimport { AA_NON_TEXT, AA_TEXT, contrastRatio, parseHex } from './contrast';\nimport { deriveTokens, type TokenSet } from './derive';\nimport type { BrandInputs } from './inputs';\n\nexport interface ContrastIssue {\n /** The token that fails, as an editor would be shown it. */\n token: string;\n foreground: string;\n background: string;\n ratio: number;\n required: number;\n /** The WCAG criterion, so the message can cite it. */\n criterion: '1.4.3 Contrast (Minimum)' | '1.4.11 Non-text Contrast';\n message: string;\n}\n\nexport interface ContrastReport {\n ok: boolean;\n issues: ContrastIssue[];\n /** How many pairs were examined — the honest denominator. */\n checked: number;\n}\n\ninterface Pair {\n token: string;\n fg: string;\n bg: string;\n required: number;\n criterion: ContrastIssue['criterion'];\n what: string;\n}\n\n/**\n * A gradient has no single luminance, so it is skipped rather than guessed at.\n * Safe because nothing is read directly against the page surface — the one\n * place a gradient is allowed.\n */\nconst isMeasurable = (value: string): boolean => parseHex(value) !== null;\n\nfunction pairsFor(tokens: TokenSet): Pair[] {\n const card = tokens['color.surface.card'];\n const text = (t: string) => ({ required: AA_TEXT, criterion: '1.4.3 Contrast (Minimum)' as const, what: t });\n const ui = (t: string) => ({ required: AA_NON_TEXT, criterion: '1.4.11 Non-text Contrast' as const, what: t });\n\n const pairs: Pair[] = [\n { token: 'color.text.default', fg: tokens['color.text.default'], bg: card, ...text('Body text on a card') },\n { token: 'color.text.muted', fg: tokens['color.text.muted'], bg: card, ...text('Muted text on a card') },\n { token: 'color.text.placeholder', fg: tokens['color.text.placeholder'], bg: card, ...text('Placeholder text in a field') },\n { token: 'color.text.link', fg: tokens['color.text.link'], bg: card, ...text('A link on a card') },\n { token: 'color.text.on-brand', fg: tokens['color.text.on-brand'], bg: tokens['color.brand.default'], ...text('Text on a brand-coloured button') },\n { token: 'color.text.on-header', fg: tokens['color.text.on-header'], bg: tokens['color.surface.header'], ...text('Text in the header') },\n { token: 'color.text.on-footer', fg: tokens['color.text.on-footer'], bg: tokens['color.surface.footer'], ...text('Text in the footer') },\n { token: 'color.brand.default', fg: tokens['color.brand.default'], bg: card, ...ui('A brand-coloured control against a card') },\n { token: 'color.border.default', fg: tokens['color.border.default'], bg: card, ...ui('A field border against a card') },\n ];\n\n for (const name of ['danger', 'warning', 'success', 'info']) {\n pairs.push({\n token: `color.status.${name}.text`,\n fg: tokens[`color.status.${name}.text`],\n bg: card,\n ...text(`${name[0].toUpperCase()}${name.slice(1)} message text`),\n });\n pairs.push({\n token: `color.status.${name}.default`,\n fg: tokens[`color.status.${name}.default`],\n bg: card,\n ...ui(`The ${name} indicator against a card`),\n });\n }\n\n return pairs;\n}\n\n/** Check a derived token set. */\nexport function checkContrast(tokens: TokenSet): ContrastReport {\n const issues: ContrastIssue[] = [];\n let checked = 0;\n\n for (const pair of pairsFor(tokens)) {\n if (!isMeasurable(pair.fg) || !isMeasurable(pair.bg)) continue;\n checked += 1;\n const ratio = contrastRatio(pair.fg, pair.bg);\n if (ratio >= pair.required) continue;\n issues.push({\n token: pair.token,\n foreground: pair.fg,\n background: pair.bg,\n ratio: Math.round(ratio * 100) / 100,\n required: pair.required,\n criterion: pair.criterion,\n message:\n `${pair.what} is ${(Math.round(ratio * 100) / 100).toFixed(2)}:1, ` +\n `below the ${pair.required}:1 that ${pair.criterion} requires.`,\n });\n }\n\n return { ok: issues.length === 0, issues, checked };\n}\n\n/** Check a brand before its tokens exist. What the CMS editor calls. */\nexport const checkBrandContrast = (input: BrandInputs): ContrastReport =>\n checkContrast(deriveTokens(input));\n","/**\n * Tokens → the W3C Design Tokens Community Group format.\n *\n * An OUTPUT, not the source. ADR 0005 originally had tokens authored as DTCG\n * files and built by Style Dictionary; writing the derivation showed why that\n * cannot be the whole story. A partner's tokens are computed at runtime from a\n * published brand document, so the authoring format has to be code — a\n * build-time pipeline can only ever produce the house theme, and a second\n * emitter for the runtime path would drift from it.\n *\n * So the format is kept as an export. It is what Figma, Style Dictionary and\n * the token tooling read, which is what makes a design-tool round trip a thing\n * we can add later rather than a rewrite, and it costs one function.\n */\nimport type { TokenSet } from './derive';\n\nexport type DtcgType = 'color' | 'dimension' | 'fontFamily' | 'fontWeight' | 'number' | 'shadow';\n\ninterface DtcgToken {\n $type: DtcgType;\n $value: string;\n $description?: string;\n}\n\nexport type DtcgGroup = { [key: string]: DtcgGroup | DtcgToken };\n\n/**\n * Infer the type from the token's path and value.\n *\n * By path first, because a value alone is ambiguous — `\"400\"` is a font weight\n * and `\"2px\"` is a dimension and both are strings. The paths are ours, so this\n * is reading our own naming convention rather than guessing.\n */\nfunction typeOf(path: string, value: string): DtcgType {\n if (path.startsWith('color.') || path.startsWith('focus.ring.') && !/width|offset|shadow/.test(path)) return 'color';\n if (path.includes('font.family')) return 'fontFamily';\n if (path.includes('font.weight')) return 'fontWeight';\n if (path.includes('line-height')) return 'number';\n if (path.includes('shadow')) return 'shadow';\n if (/^-?[\\d.]+(px|rem|em|%)$/.test(value) || value === '0') return 'dimension';\n return 'color';\n}\n\n/** A flat token set as a nested DTCG document. */\nexport function toDtcg(tokens: TokenSet): DtcgGroup {\n const root: DtcgGroup = {};\n for (const [path, value] of Object.entries(tokens)) {\n const parts = path.split('.');\n const leaf = parts.pop() as string;\n let node = root;\n for (const part of parts) {\n if (!(part in node) || '$value' in (node[part] as DtcgToken)) node[part] = {} as DtcgGroup;\n node = node[part] as DtcgGroup;\n }\n node[leaf] = { $type: typeOf(path, value), $value: value };\n }\n return root;\n}\n"],"mappings":";;;;;;;;;;AAiBA,SAAS,SAAS;AAGX,IAAM,iBAAiB,EAC3B,OAAO,EACP,MAAM,sCAAsC,oCAAoC;AAW5E,IAAM,qBAAqB,EAAE,MAAM;AAAA,EACxC;AAAA,EACA,EAAE,OAAO,EAAE,MAAM,0CAA0C,wCAAwC;AACrG,CAAC;AAEM,IAAM,gBAAgB,EAAE,OAAO;AAAA,EACpC,QAAQ,EAAE,OAAO;AAAA,EACjB,KAAK,EAAE,OAAO;AAAA,EACd,QAAQ,EAAE,OAAO,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AAO;AACzC,MAAI,KAAK,SAAS,aAAa,EAAG,QAAO;AACzC,MAAI,KAAK,SAAS,QAAQ,EAAG,QAAO;AACpC,MAAI,0BAA0B,KAAK,KAAK,KAAK,UAAU,IAAK,QAAO;AACnE,SAAO;AACT;AAGO,SAAS,OAAO,QAA6B;AAClD,QAAM,OAAkB,CAAC;AACzB,aAAW,CAAC,MAAM,KAAK,KAAK,OAAO,QAAQ,MAAM,GAAG;AAClD,UAAM,QAAQ,KAAK,MAAM,GAAG;AAC5B,UAAM,OAAO,MAAM,IAAI;AACvB,QAAI,OAAO;AACX,eAAW,QAAQ,OAAO;AACxB,UAAI,EAAE,QAAQ,SAAS,YAAa,KAAK,IAAI,EAAiB,MAAK,IAAI,IAAI,CAAC;AAC5E,aAAO,KAAK,IAAI;AAAA,IAClB;AACA,SAAK,IAAI,IAAI,EAAE,OAAO,OAAO,MAAM,KAAK,GAAG,QAAQ,MAAM;AAAA,EAC3D;AACA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/inputs.ts","../src/fonts.ts","../src/contrast.ts","../src/derive.ts","../src/variables.ts","../src/validate.ts","../src/dtcg.ts"],"sourcesContent":["/**\n * Brand inputs — everything a partner may set, and nothing else.\n *\n * The list is closed, and it is short on purpose. Stripe's Appearance API gets\n * almost all of its brand expression from eight variables and derives the rest;\n * Cloudscape allows typography, colour and border radius and refuses the\n * question beyond that; the legacy Sanity CMS this replaces allowed everything\n * and accumulated forty per-viewport override fields nobody could prune. The\n * reasoning, with sources, is\n * [ADR 0010](../../../docs/decisions/0010-what-a-brand-may-set.md).\n *\n * Two absences are the point of the whole file. There is no foreground colour\n * anywhere — text on a surface is computed, so a partner cannot pin white text\n * onto a mid-tone brand colour. And there is no focus colour — the ring keeps\n * system values, because a focus indicator drawn in a partner's own brand\n * colour on that partner's own background is where focus visibility dies.\n */\nimport { z } from 'zod';\n\n/** A hex colour. The only colour form the inputs accept. */\nexport const HexColorSchema = z\n .string()\n .regex(/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/, 'Must be a hex colour, e.g. #5e10b1');\n\n/**\n * The page background, which may be a gradient.\n *\n * It is the one exception and it is safe by construction rather than by\n * exception: the page background never carries text directly — text sits on a\n * card — so it is the only surface with nothing to contrast against. Northwind\n * Plus's shell is a three-stop gradient, which is a real requirement and\n * would otherwise need an escape hatch.\n */\nexport const SurfaceValueSchema = z.union([\n HexColorSchema,\n z.string().regex(/^(linear|radial|conic)-gradient\\(.+\\)$/, 'Must be a hex colour or a CSS gradient'),\n]);\n\nexport const WebFontSchema = z.object({\n family: z.string(),\n url: z.string(),\n weight: z.string().optional(),\n style: z.string().optional(),\n display: z.string().optional(),\n});\nexport type WebFont = z.infer<typeof WebFontSchema>;\n\n/**\n * The type ramp ratio.\n *\n * Bounded rather than free. Below 1.067 the ramp stops distinguishing levels\n * and heading structure becomes invisible to a sighted reader even though the\n * markup is correct; above 1.333 the top of the scale overflows a 360px\n * viewport at 200% zoom, which fails 1.4.4. A partner who wants bigger headings\n * raises the base size.\n */\nexport const TypeScaleSchema = z.number().min(1.067).max(1.333);\n\n/**\n * A step on the spacing scale, as the `space.*` tokens name them: `4` is four\n * spacing units, `6` is eight, `8` is sixteen. Layout names a step rather\n * than a size, so it follows the brand's spacing unit.\n */\nexport const SPACE_STEP_NAMES = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10'] as const;\nexport const SpaceStepSchema = z.enum(SPACE_STEP_NAMES);\nexport type SpaceStep = z.infer<typeof SpaceStepSchema>;\n\n/**\n * Each group is `.strict()`.\n *\n * Zod strips unknown keys by default, so `color.onBrand` would validate, be\n * dropped, and leave an editor looking at a brand that ignores a value they\n * set. Rejecting it says what is actually true: there is nowhere to put a\n * foreground colour, because foregrounds are measured.\n */\nexport const BrandInputsSchema = z.object({\n color: z.strictObject({\n /** The partner's primary colour: actions, emphasis, selected states. */\n brand: HexColorSchema,\n /** The secondary colour. Defaults to the brand colour when unset. */\n accent: HexColorSchema.optional(),\n\n /** The page behind everything. May be a gradient; carries no text. */\n surfacePage: SurfaceValueSchema,\n /** Where content actually sits, and what text is read against. */\n surfaceCard: HexColorSchema,\n /** The header band. */\n surfaceHeader: HexColorSchema,\n /** The footer band. */\n surfaceFooter: HexColorSchema,\n\n /** Default body text, on `surfaceCard`. */\n text: HexColorSchema,\n\n danger: HexColorSchema,\n warning: HexColorSchema,\n success: HexColorSchema,\n info: HexColorSchema,\n }),\n\n font: z.strictObject({\n body: z.string(),\n /** Defaults to `body` when unset — most brands have one typeface. */\n heading: z.string().optional(),\n /** Root size in px. Everything else is `rem`, scaled from this. */\n sizeBase: z.number().min(14).max(20).default(16),\n scale: TypeScaleSchema.default(1.2),\n /** Faces the shell must load. A partner brings its own typeface. */\n webFonts: z.array(WebFontSchema).default([]),\n }),\n\n shape: z.strictObject({\n /** Corner rounding in px. Every radius derives from it. */\n radiusBase: z.number().min(0).max(24).default(4),\n /** The spacing unit in px. All spacing is a multiple. */\n spaceBase: z.number().min(2).max(8).default(4),\n /** Default border weight in px. */\n borderWidth: z.number().min(1).max(3).default(1),\n }),\n\n /**\n * The page's frame and the spacing between columns.\n *\n * Margins and gutters name steps on the spacing scale rather than pixels,\n * so they move with `shape.spaceBase` and stay on the same rhythm as\n * everything else. The page width is bounded: below 640px a desktop page\n * reads as a phone page, and above 1600px a line of text outgrows what can\n * be read comfortably. Every value defaults to what pages had before this\n * group existed, so a brand that sets none of it looks the same.\n */\n layout: z.strictObject({\n /** The widest the content gets on a large screen, in px, inside the margins. */\n pageWidth: z.number().min(640).max(1600).default(1200),\n /** Space between the screen's edge and the content, at each size. */\n margin: z.strictObject({\n phone: SpaceStepSchema.default('4'),\n tablet: SpaceStepSchema.default('6'),\n desktop: SpaceStepSchema.default('8'),\n }).default({}),\n /** The three gutters a grid may choose between columns. */\n gutter: z.strictObject({\n sm: SpaceStepSchema.default('2'),\n md: SpaceStepSchema.default('4'),\n lg: SpaceStepSchema.default('6'),\n }).default({}),\n }).default({}),\n\n assets: z.strictObject({\n logo: z.string(),\n logoAlt: z.string(),\n /** For use on dark surfaces, where the main logo would disappear. */\n logoDark: z.string().optional(),\n favicon: z.string().optional(),\n }),\n});\n\nexport type BrandInputs = z.infer<typeof BrandInputsSchema>;\n\n/**\n * The house defaults — a complete, neutral, AA-passing brand.\n *\n * Every input is optional at the edges of the system because this exists: a\n * site with no brand document still renders something legible rather than\n * unstyled, which is what makes a missing brand a visible problem instead of a\n * broken page.\n */\nexport const DEFAULT_BRAND_INPUTS: BrandInputs = BrandInputsSchema.parse({\n color: {\n brand: '#1f4ed8',\n surfacePage: '#f4f5f7',\n surfaceCard: '#ffffff',\n surfaceHeader: '#ffffff',\n surfaceFooter: '#1f2430',\n text: '#1a1a1a',\n danger: '#c8102e',\n warning: '#b45309',\n success: '#047857',\n info: '#1f4ed8',\n },\n font: { body: 'system-ui, -apple-system, \"Segoe UI\", Roboto, sans-serif' },\n shape: {},\n assets: { logo: '', logoAlt: '' },\n});\n","/**\n * Fonts a brand names, and whether anything will actually draw them.\n *\n * A brand names its typefaces by family (\"GT Walsheim Pro\"). A browser draws a\n * family only if the device has it or the page loads it with `@font-face`, and\n * when it can do neither it falls back to its default, which is Times. So every\n * family a brand names is followed by a fallback stack, and a family is only\n * called loaded when the brand carries a file for it.\n */\nimport type { WebFont } from './inputs';\n\n/** What a browser draws when a sans-serif family is missing: the device's own interface font. */\nexport const SYSTEM_SANS = 'system-ui, -apple-system, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif';\n/** The serif equivalent, for a brand whose type is a serif. */\nexport const SYSTEM_SERIF = 'Georgia, Cambria, \"Times New Roman\", serif';\n\nconst GENERIC = new Set(['serif', 'sans-serif', 'monospace', 'cursive', 'fantasy', 'system-ui', 'ui-sans-serif', 'ui-serif', 'ui-monospace', 'ui-rounded', 'math', 'emoji']);\n/** Families every device has, or that name the device's own font, so nothing needs loading. */\nconst ON_EVERY_DEVICE = new Set([...GENERIC, '-apple-system', 'blinkmacsystemfont', 'segoe ui', 'helvetica', 'helvetica neue', 'arial', 'georgia', 'times new roman', 'cambria', 'courier new', 'verdana', 'tahoma', 'trebuchet ms']);\n\n/** The weights Strata's components use: body, medium labels, semibold and bold headings. */\nexport const FONT_WEIGHTS = ['400', '500', '600', '700'] as const;\n\nconst unquote = (s: string) => s.trim().replace(/^['\"]|['\"]$/g, '').trim();\nconst quote = (s: string) => (GENERIC.has(s.toLowerCase()) || s.startsWith('-') || /^[a-z0-9-]+$/i.test(s) ? s : JSON.stringify(s));\n\n/** The families in a `font-family` value, unquoted, in order. */\nexport function fontFamilies(value: string | undefined): string[] {\n return (value ?? '').split(',').map(unquote).filter(Boolean);\n}\n\n/** The family a brand means: the first one named. */\nexport function primaryFamily(value: string | undefined): string {\n return fontFamilies(value)[0] ?? '';\n}\n\n/**\n * A `font-family` value that never ends in the browser's default. The families\n * the brand names come first, exactly as named; a generic fallback is added\n * when none is there.\n */\nexport function fontStack(value: string | undefined, fallback: 'sans' | 'serif' = 'sans'): string {\n const named = fontFamilies(value);\n if (named.some((f) => GENERIC.has(f.toLowerCase()))) return named.map(quote).join(', ');\n const stack = fontFamilies(fallback === 'serif' ? SYSTEM_SERIF : SYSTEM_SANS);\n const seen = new Set(named.map((f) => f.toLowerCase()));\n return [...named, ...stack.filter((f) => !seen.has(f.toLowerCase()))].map(quote).join(', ');\n}\n\nexport type FontStatus =\n | { kind: 'system'; family: string }\n | { kind: 'loaded'; family: string; weights: string[]; missingWeights: string[] }\n | { kind: 'missing'; family: string };\n\n/** Whether pages will draw the family a brand names, and which weights it has files for. */\nexport function fontStatus(value: string | undefined, webFonts: readonly WebFont[] = []): FontStatus {\n const family = primaryFamily(value);\n if (!family || ON_EVERY_DEVICE.has(family.toLowerCase())) return { kind: 'system', family: family || 'system-ui' };\n // A face found on a partner's site is recorded without a file until someone with the right to upload it does.\n const faces = webFonts.filter((f) => f.url && f.family.toLowerCase() === family.toLowerCase() && (f.style ?? 'normal') === 'normal');\n if (!faces.length) return { kind: 'missing', family };\n // A face with no weight, or a range such as \"100 900\", is a variable font and covers them all.\n const covers = (w: string) => faces.some((f) => !f.weight || f.weight === w || (/^\\d+ \\d+$/.test(f.weight) && Number(f.weight.split(' ')[0]) <= Number(w) && Number(w) <= Number(f.weight.split(' ')[1])));\n const weights = FONT_WEIGHTS.filter(covers);\n return { kind: 'loaded', family, weights, missingWeights: FONT_WEIGHTS.filter((w) => !covers(w)) };\n}\n\nexport interface OpenFont { family: string; category: 'sans' | 'serif' }\n\n/**\n * Open-licence families Strata fetches and stores itself, so a customer's\n * browser loads them from Strata and never calls a third party.\n */\nexport const OPEN_FONTS: readonly OpenFont[] = [\n { family: 'Inter', category: 'sans' },\n { family: 'Roboto', category: 'sans' },\n { family: 'Open Sans', category: 'sans' },\n { family: 'Lato', category: 'sans' },\n { family: 'Montserrat', category: 'sans' },\n { family: 'Poppins', category: 'sans' },\n { family: 'Nunito Sans', category: 'sans' },\n { family: 'Source Sans 3', category: 'sans' },\n { family: 'Work Sans', category: 'sans' },\n { family: 'DM Sans', category: 'sans' },\n { family: 'IBM Plex Sans', category: 'sans' },\n { family: 'Manrope', category: 'sans' },\n { family: 'Plus Jakarta Sans', category: 'sans' },\n { family: 'Figtree', category: 'sans' },\n { family: 'Raleway', category: 'sans' },\n { family: 'Merriweather', category: 'serif' },\n { family: 'Lora', category: 'serif' },\n { family: 'Playfair Display', category: 'serif' },\n { family: 'Source Serif 4', category: 'serif' },\n { family: 'IBM Plex Serif', category: 'serif' },\n];\n\n/** The open font of that name, if Strata can fetch it. */\nexport const openFont = (family: string): OpenFont | undefined => OPEN_FONTS.find((f) => f.family.toLowerCase() === family.trim().toLowerCase());\n","/**\n * Contrast maths, to WCAG 2.x.\n *\n * This file exists because of one decision: a partner never authors a text\n * colour to sit on a background ([ADR 0010](../../../docs/decisions/0010-what-a-brand-may-set.md)).\n * They pick a brand colour and the system picks what reads on top of it. That\n * makes the most common white-label accessibility failure — a mid-tone brand\n * colour under a white label — unrepresentable rather than merely discouraged.\n *\n * The formulae are from WCAG 2.2 (relative luminance, and the (L1+0.05)/(L2+0.05)\n * contrast ratio). They are stable, cheap and exactly what an auditor will use.\n * APCA is better maths and is not normative yet; when it is, this is the one\n * file that changes.\n */\n\n/** A colour this module can reason about: #rgb, #rrggbb, or #rrggbbaa. */\nexport type Hex = string;\n\nexport interface Rgb {\n r: number;\n g: number;\n b: number;\n}\n\nconst HEX = /^#?([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i;\n\n/**\n * Parse a hex colour. Returns null rather than throwing: callers are usually\n * validating authored content, where \"this is not a colour\" is a message to an\n * editor and not an exception.\n */\nexport function parseHex(value: string): Rgb | null {\n const m = HEX.exec(value.trim());\n if (!m) return null;\n let h = m[1];\n if (h.length === 3) h = h.split('').map((c) => c + c).join('');\n return {\n r: parseInt(h.slice(0, 2), 16),\n g: parseInt(h.slice(2, 4), 16),\n b: parseInt(h.slice(4, 6), 16),\n };\n}\n\nexport function toHex({ r, g, b }: Rgb): Hex {\n const c = (n: number) => Math.round(Math.min(255, Math.max(0, n))).toString(16).padStart(2, '0');\n return `#${c(r)}${c(g)}${c(b)}`;\n}\n\n/** WCAG relative luminance. */\nexport function luminance(rgb: Rgb): number {\n const channel = (v: number) => {\n const s = v / 255;\n return s <= 0.03928 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;\n };\n return 0.2126 * channel(rgb.r) + 0.7152 * channel(rgb.g) + 0.0722 * channel(rgb.b);\n}\n\n/** WCAG contrast ratio, 1–21. Returns 0 for anything unparseable. */\nexport function contrastRatio(a: string, b: string): number {\n const ra = parseHex(a);\n const rb = parseHex(b);\n if (!ra || !rb) return 0;\n const la = luminance(ra);\n const lb = luminance(rb);\n const [hi, lo] = la > lb ? [la, lb] : [lb, la];\n return (hi + 0.05) / (lo + 0.05);\n}\n\n/** The thresholds, named, so call sites read as the criterion they enforce. */\nexport const AA_TEXT = 4.5;\nexport const AA_LARGE_TEXT = 3;\n/** 1.4.11 Non-text Contrast: UI components and meaningful graphics. */\nexport const AA_NON_TEXT = 3;\n\n/**\n * The two foregrounds anything may be drawn in.\n *\n * Not pure black and white. Pure black on a light surface is harsher than it\n * needs to be and pure white on a saturated brand colour haloes; these are the\n * near-neutrals most systems settle on, and they still clear 4.5:1 against\n * every surface the inputs can produce — which the tests assert rather than\n * assume.\n */\nexport const FOREGROUND_DARK = '#1a1a1a';\nexport const FOREGROUND_LIGHT = '#ffffff';\n\n/**\n * Pick the foreground that reads best on `background`.\n *\n * Deliberately returns the BETTER of the two rather than the first that passes.\n * On a mid-tone brand colour both may clear 4.5:1 and the winner is still\n * visibly easier to read; on a colour where neither passes, the better one is\n * what gets rendered while the publish check reports the failure. A caller that\n * needs to know whether it passed asks `contrastRatio` — this function always\n * answers.\n */\nexport function pickForeground(background: string): Hex {\n const dark = contrastRatio(background, FOREGROUND_DARK);\n const light = contrastRatio(background, FOREGROUND_LIGHT);\n return dark >= light ? FOREGROUND_DARK : FOREGROUND_LIGHT;\n}\n\n/**\n * Shift a colour toward black or white by `amount` (0–1).\n *\n * This is how every hover, active and subtle state is derived. Mixing in sRGB\n * is not perceptually uniform and a perceptual space would give more even\n * steps; sRGB is used because it is what CSS `color-mix` does, so a value\n * derived here and a value a stylesheet computes agree. Matching the platform\n * matters more here than being slightly more correct than it.\n */\nexport function shade(color: string, amount: number): Hex {\n const rgb = parseHex(color);\n if (!rgb) return color;\n const t = amount < 0 ? 255 : 0;\n const k = Math.abs(amount);\n return toHex({\n r: rgb.r + (t - rgb.r) * k,\n g: rgb.g + (t - rgb.g) * k,\n b: rgb.b + (t - rgb.b) * k,\n });\n}\n\n/** Darken toward black. */\nexport const darken = (color: string, amount: number): Hex => shade(color, amount);\n/** Lighten toward white. */\nexport const lighten = (color: string, amount: number): Hex => shade(color, -amount);\n\n/**\n * A very light tint of a colour, for subtle backgrounds — an info panel, a\n * selected row. Always light enough to take the dark foreground, which is what\n * makes \"subtle\" a safe surface rather than a guess.\n */\nexport const tint = (color: string): Hex => lighten(color, 0.88);\n\n/** Blend two colours. `amount` is how far from `a` toward `b`. */\nexport function mix(a: string, b: string, amount: number): Hex {\n const ra = parseHex(a);\n const rb = parseHex(b);\n if (!ra || !rb) return a;\n const k = Math.min(1, Math.max(0, amount));\n return toHex({\n r: ra.r + (rb.r - ra.r) * k,\n g: ra.g + (rb.g - ra.g) * k,\n b: ra.b + (rb.b - ra.b) * k,\n });\n}\n\n/**\n * Walk a foreground away from its background until it clears `target`.\n *\n * This is the mechanism that makes a derived token safe rather than merely\n * plausible. Muted text, placeholder text and borders are all produced by\n * blending toward a surface, and a blend that looks right on one brand falls\n * under 4.5:1 on the next. Rather than pick a blend that happens to work for\n * the brands we have, each derived value is pushed back until it passes.\n *\n * It moves toward whichever end of the scale is already further from the\n * background, in small steps, and gives up after it runs out of room — at\n * which point the colour is returned as-is and the publish check reports it.\n * Silently returning black would hide a brand that cannot work.\n */\nexport function ensureContrast(foreground: string, background: string, target: number): Hex {\n const fg = parseHex(foreground);\n const bg = parseHex(background);\n if (!fg || !bg) return foreground;\n if (contrastRatio(foreground, background) >= target) return toHex(fg);\n\n const toward = luminance(bg) > 0.5 ? FOREGROUND_DARK : FOREGROUND_LIGHT;\n let current = toHex(fg);\n for (let step = 1; step <= 20; step += 1) {\n current = mix(toHex(fg), toward, step / 20);\n if (contrastRatio(current, background) >= target) return current;\n }\n return current;\n}\n","/**\n * Brand inputs → the semantic tokens components actually read.\n *\n * This is the whole argument of\n * [ADR 0010](../../../docs/decisions/0010-what-a-brand-may-set.md) in executable\n * form: around twenty authored values go in, roughly a hundred come out, and\n * the hundred are not authorable. A partner who wants a different hover colour\n * is describing a change to this function, which is a product decision with a\n * version number, rather than a field in a CMS nobody can later prune.\n *\n * Three rules run through it. Foregrounds are always picked by measured\n * contrast, never authored. Anything that carries text is ratcheted until it\n * passes AA rather than trusted to. And the focus ring and the minimum target\n * size are constants, because they are the two things a brand would break first\n * and notice last.\n */\nimport { fontStack, openFont, primaryFamily } from './fonts';\nimport {\n AA_NON_TEXT,\n AA_TEXT,\n darken,\n ensureContrast,\n luminance,\n mix,\n parseHex,\n pickForeground,\n tint,\n} from './contrast';\nimport { BrandInputsSchema, type BrandInputs } from './inputs';\n\n/** A flat token set: dotted path → CSS value. */\nexport type TokenSet = Record<string, string>;\n\n/**\n * The locked tokens. A brand cannot reach these and nothing derives them.\n *\n * The focus ring is two-tone — a light inner ring inside a dark outer one — so\n * that it stays visible on any surface a partner can produce, including their\n * own brand colour. A single-colour ring has to assume a background, and the\n * one it assumes is the one a white-label product does not have. This is the\n * rule Scotland's design system states directly: adopters may change the\n * colours, and must still keep the system's colours for focus.\n *\n * `target.min` is WCAG 2.2's 2.5.8 minimum. It is here rather than in the\n * spacing scale so that shrinking the spacing unit cannot shrink a tap target.\n */\nexport const LOCKED_TOKENS: TokenSet = {\n 'focus.ring.inner': '#ffffff',\n 'focus.ring.outer': '#1a1a1a',\n 'focus.ring.width': '2px',\n 'focus.ring.offset': '2px',\n 'focus.ring.shadow': '0 0 0 2px #ffffff, 0 0 0 4px #1a1a1a',\n 'target.min': '24px',\n 'target.spacing': '8px',\n};\n\n/** Spacing steps, as multiples of the base unit. */\nconst SPACE_STEPS: Record<string, number> = {\n '0': 0, '1': 1, '2': 2, '3': 3, '4': 4,\n '5': 6, '6': 8, '7': 12, '8': 16, '9': 24, '10': 32,\n};\n\n/** Type ramp, as powers of the scale ratio either side of the base. */\nconst TYPE_STEPS: Record<string, number> = {\n '2xs': -3, xs: -2, sm: -1, md: 0, lg: 1, xl: 2, '2xl': 3, '3xl': 4,\n};\n\n/**\n * The smallest text the ramp may produce, in px.\n *\n * A 1.333 ratio three steps below a 14px base lands at 5.9px. Clamping here\n * rather than narrowing the ratio keeps the top of the ramp expressive while\n * stopping the bottom from becoming unreadable.\n */\nconst MIN_FONT_PX = 12;\n\n/**\n * The text colour for a branded band — the header, the footer.\n *\n * Not simply the picked foreground, because that throws away real brand\n * expression: Northwind's header is white with dark-purple text, and deriving\n * near-black there would be legible and wrong. On a LIGHT band the accent\n * colour is used, ratcheted until it passes, which is what partners actually\n * do and what every migrated theme authored. On a DARK band the picked\n * foreground wins, because coloured text on a saturated brand background is\n * exactly where legibility goes, and a washed-out tint of the band's own\n * colour is worse than white.\n *\n * An unparseable surface — a gradient — is treated as dark, since a gradient\n * is only allowed on the page and the page is the one band nothing sits on.\n */\nfunction onSurface(surface: string, accent: string): string {\n const rgb = parseHex(surface);\n if (!rgb) return pickForeground('#000000');\n return luminance(rgb) > 0.5 ? ensureContrast(accent, surface, AA_TEXT) : pickForeground(surface);\n}\n\nfunction typeRamp(sizeBase: number, scale: number): TokenSet {\n const out: TokenSet = {};\n for (const [name, step] of Object.entries(TYPE_STEPS)) {\n const px = Math.max(MIN_FONT_PX, sizeBase * scale ** step);\n // Round UP at four places. Rounding to nearest loses the 12px floor by a\n // ten-thousandth, which is invisible until a test asserts the floor and\n // fails — and the floor is the accessibility claim, so it rounds its way.\n const rem = Math.ceil((px / sizeBase) * 10000) / 10000;\n out[`font.size.${name}`] = `${rem}rem`;\n }\n return out;\n}\n\nexport function deriveTokens(input: BrandInputs): TokenSet {\n const { color, font, shape } = input;\n // A brand stored before layout existed has none, and gets the frame pages had then.\n const layout = input.layout ?? BrandInputsSchema.shape.layout.parse(undefined);\n const card = color.surfaceCard;\n const accent = color.accent ?? color.brand;\n\n const tokens: TokenSet = { ...LOCKED_TOKENS };\n\n // --- surfaces ------------------------------------------------------------\n // `page` is the only one that may be a gradient, and the only one nothing is\n // read against. `inset` is for wells and disabled fields: a step away from\n // the card in whichever direction the card is not.\n tokens['color.surface.page'] = color.surfacePage;\n tokens['color.surface.card'] = card;\n tokens['color.surface.header'] = color.surfaceHeader;\n tokens['color.surface.footer'] = color.surfaceFooter;\n tokens['color.surface.subtle'] = tint(color.brand);\n tokens['color.surface.inset'] = mix(card, pickForeground(card), 0.05);\n\n // --- brand ---------------------------------------------------------------\n // Hover and active are tone shifts rather than authored colours. The\n // direction is fixed: darker on interaction, because a lighter hover on a\n // light surface reads as disabled.\n tokens['color.brand.default'] = color.brand;\n tokens['color.brand.hover'] = darken(color.brand, 0.12);\n tokens['color.brand.active'] = darken(color.brand, 0.24);\n tokens['color.brand.subtle'] = tint(color.brand);\n tokens['color.brand.on'] = pickForeground(color.brand);\n\n tokens['color.accent.default'] = accent;\n tokens['color.accent.hover'] = darken(accent, 0.12);\n tokens['color.accent.on'] = pickForeground(accent);\n\n // --- text ----------------------------------------------------------------\n // Muted and placeholder are blends toward the surface, then ratcheted back\n // until they clear AA. Placeholder is included deliberately: it is routinely\n // treated as exempt and 1.4.3 does not exempt it.\n tokens['color.text.default'] = ensureContrast(color.text, card, AA_TEXT);\n tokens['color.text.muted'] = ensureContrast(mix(color.text, card, 0.38), card, AA_TEXT);\n tokens['color.text.placeholder'] = ensureContrast(mix(color.text, card, 0.5), card, AA_TEXT);\n tokens['color.text.on-brand'] = pickForeground(color.brand);\n tokens['color.text.on-header'] = onSurface(color.surfaceHeader, accent);\n tokens['color.text.on-footer'] = onSurface(color.surfaceFooter, accent);\n // A link is the brand colour where that is readable, and a darkened brand\n // colour where it is not — so a partner with a pale brand still gets links\n // that look like theirs.\n // Headings take the accent colour. The legacy schema had an authored\n // `typography.headingColor`, and on every migrated theme it was the secondary\n // colour — so deriving it reproduces them exactly and removes a field whose\n // only job was to restate another one.\n tokens['color.text.heading'] = ensureContrast(accent, card, AA_TEXT);\n tokens['color.text.link'] = ensureContrast(color.brand, card, AA_TEXT);\n tokens['color.text.link-hover'] = darken(tokens['color.text.link'], 0.2);\n\n // --- borders -------------------------------------------------------------\n // 1.4.11 governs these: a field border is a UI component boundary, so 3:1,\n // not 4.5:1.\n tokens['color.border.default'] = ensureContrast(mix(color.text, card, 0.7), card, AA_NON_TEXT);\n tokens['color.border.strong'] = ensureContrast(mix(color.text, card, 0.45), card, AA_NON_TEXT);\n\n // --- status --------------------------------------------------------------\n // Each gets three: the colour itself at UI contrast, a tint to sit behind it,\n // and the foreground that reads on it. `*.text` is separate from `*.default`\n // because the same red that is fine as a 3:1 border is not fine as 4.5:1 body\n // text, and conflating them is how error messages end up unreadable.\n for (const name of ['danger', 'warning', 'success', 'info'] as const) {\n const base = color[name];\n tokens[`color.status.${name}.default`] = ensureContrast(base, card, AA_NON_TEXT);\n tokens[`color.status.${name}.text`] = ensureContrast(base, card, AA_TEXT);\n tokens[`color.status.${name}.subtle`] = tint(base);\n tokens[`color.status.${name}.on`] = pickForeground(base);\n }\n\n // --- typography ----------------------------------------------------------\n // A family the device lacks and the brand does not load would fall back to Times, so each is followed by a stack.\n const fallbackFor = (value: string) => (openFont(primaryFamily(value))?.category === 'serif' ? 'serif' : 'sans');\n tokens['font.family.body'] = fontStack(font.body, fallbackFor(font.body));\n tokens['font.family.heading'] = fontStack(font.heading ?? font.body, fallbackFor(font.heading ?? font.body));\n tokens['font.size.root'] = `${font.sizeBase}px`;\n Object.assign(tokens, typeRamp(font.sizeBase, font.scale));\n tokens['font.weight.regular'] = '400';\n tokens['font.weight.medium'] = '500';\n tokens['font.weight.semibold'] = '600';\n tokens['font.weight.bold'] = '700';\n // 1.4.8 asks for 1.5 within a paragraph; `tight` is for headings, where it\n // does not apply.\n tokens['font.line-height.tight'] = '1.25';\n tokens['font.line-height.normal'] = '1.5';\n tokens['font.line-height.relaxed'] = '1.75';\n\n // --- space, radius, border width -----------------------------------------\n for (const [name, multiple] of Object.entries(SPACE_STEPS)) {\n tokens[`space.${name}`] = `${shape.spaceBase * multiple}px`;\n }\n tokens['radius.none'] = '0';\n tokens['radius.sm'] = `${shape.radiusBase / 2}px`;\n tokens['radius.md'] = `${shape.radiusBase}px`;\n tokens['radius.lg'] = `${shape.radiusBase * 2}px`;\n tokens['radius.xl'] = `${shape.radiusBase * 3}px`;\n tokens['radius.full'] = '9999px';\n tokens['border.width.thin'] = `${shape.borderWidth}px`;\n tokens['border.width.thick'] = `${shape.borderWidth * 2}px`;\n\n // --- layout: the page frame and the gutters between columns ----------------\n const step = (name: string) => `${shape.spaceBase * (SPACE_STEPS[name] ?? 0)}px`;\n tokens['layout.page.width'] = `${layout.pageWidth}px`;\n tokens['layout.margin.phone'] = step(layout.margin.phone);\n tokens['layout.margin.tablet'] = step(layout.margin.tablet);\n tokens['layout.margin.desktop'] = step(layout.margin.desktop);\n tokens['layout.gutter.sm'] = step(layout.gutter.sm);\n tokens['layout.gutter.md'] = step(layout.gutter.md);\n tokens['layout.gutter.lg'] = step(layout.gutter.lg);\n\n return tokens;\n}\n","/**\n * A brand as design-tool variables, and back.\n *\n * Figma, and tools like it, keep a design system's values as variables in\n * collections. This turns a partner's brand into two collections: the inputs a\n * designer may change, and the tokens Strata derives from them, which are\n * there to design with and are never read back. Changes come back as a patch\n * to the brand inputs, checked by the same schema as any other edit, so\n * nothing Strata would refuse in the CMS gets in through a design file.\n *\n * Plain JSON with no Figma types, so the plugin, the delivery API and the CMS\n * share it, and it is tested without Figma.\n */\nimport { BrandInputsSchema, SPACE_STEP_NAMES, type BrandInputs } from './inputs';\nimport { deriveTokens } from './derive';\n\nexport const VARIABLES_FORMAT = 'strata.brand-variables';\nexport const VARIABLES_VERSION = 1;\n\nexport type VariableType = 'COLOR' | 'FLOAT' | 'STRING';\n\n/** One variable. `name` uses `/` for groups, as Figma does; `path` is where it lives in Strata. */\nexport interface BrandVariable {\n name: string;\n path: string;\n type: VariableType;\n value: string | number;\n description?: string;\n}\n\nexport interface BrandVariables {\n format: typeof VARIABLES_FORMAT;\n version: typeof VARIABLES_VERSION;\n /** The site the brand belongs to, so a file says which partner it is. */\n site: string;\n /** What a designer may change, and what Strata reads back. */\n inputs: BrandVariable[];\n /** Worked out from the inputs. To design with; ignored when read back. */\n derived: BrandVariable[];\n}\n\n/** The spacing multiples the scale's step names stand for. */\nconst STEP_MULTIPLES: Record<string, number> = { '0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 6, '6': 8, '7': 12, '8': 16, '9': 24, '10': 32 };\n\nconst HEX = /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;\n\ninterface InputSpec {\n path: string;\n name: string;\n /** A spacing step, shown to a designer in pixels at the brand's spacing unit. */\n step?: boolean;\n description?: string;\n}\n\n/** The inputs a design tool may hold, in the order a designer meets them. Assets and web fonts stay in the CMS. */\nconst INPUTS: InputSpec[] = [\n { path: 'color.brand', name: 'color/brand' },\n { path: 'color.accent', name: 'color/accent' },\n { path: 'color.surfacePage', name: 'color/surface/page', description: 'May be a gradient; carries no text.' },\n { path: 'color.surfaceCard', name: 'color/surface/card' },\n { path: 'color.surfaceHeader', name: 'color/surface/header' },\n { path: 'color.surfaceFooter', name: 'color/surface/footer' },\n { path: 'color.text', name: 'color/text' },\n { path: 'color.danger', name: 'color/status/danger' },\n { path: 'color.warning', name: 'color/status/warning' },\n { path: 'color.success', name: 'color/status/success' },\n { path: 'color.info', name: 'color/status/info' },\n { path: 'font.body', name: 'font/body' },\n { path: 'font.heading', name: 'font/heading' },\n { path: 'font.sizeBase', name: 'font/size-base', description: 'Root size in px, 14 to 20.' },\n { path: 'font.scale', name: 'font/scale', description: 'Type ramp ratio, 1.067 to 1.333.' },\n { path: 'shape.radiusBase', name: 'shape/radius', description: 'Corner radius in px, 0 to 24.' },\n { path: 'shape.spaceBase', name: 'shape/space-unit', description: 'The spacing unit in px, 2 to 8.' },\n { path: 'shape.borderWidth', name: 'shape/border-width', description: 'Border weight in px, 1 to 3.' },\n { path: 'layout.pageWidth', name: 'layout/page-width', description: 'Widest content in px, 640 to 1600.' },\n { path: 'layout.margin.phone', name: 'layout/margin/phone', step: true },\n { path: 'layout.margin.tablet', name: 'layout/margin/tablet', step: true },\n { path: 'layout.margin.desktop', name: 'layout/margin/desktop', step: true },\n { path: 'layout.gutter.sm', name: 'layout/gutter/sm', step: true },\n { path: 'layout.gutter.md', name: 'layout/gutter/md', step: true },\n { path: 'layout.gutter.lg', name: 'layout/gutter/lg', step: true },\n];\n\nconst STEP_HINT = 'A step on the spacing scale, in px: a multiple of the space unit (1, 2, 3, 4, 6, 8, 12, 16, 24 or 32 times).';\n\nconst read = (source: unknown, path: string): unknown =>\n path.split('.').reduce<unknown>((at, key) => (at && typeof at === 'object' ? (at as Record<string, unknown>)[key] : undefined), source);\n\nfunction write(target: Record<string, unknown>, path: string, value: unknown) {\n const keys = path.split('.');\n let at = target;\n for (const key of keys.slice(0, -1)) at = (at[key] ??= {}) as Record<string, unknown>;\n at[keys[keys.length - 1]!] = value;\n}\n\n/** A partner's brand as variables: its inputs, and the tokens derived from them. */\nexport function brandToVariables(brand: BrandInputs, site: string): BrandVariables {\n const inputs = BrandInputsSchema.parse(brand);\n const unit = inputs.shape.spaceBase;\n const fromInputs: BrandVariable[] = [];\n for (const spec of INPUTS) {\n let value = read(inputs, spec.path);\n // An unset accent or heading font means \"the same as the brand colour or body font\".\n if (value === undefined && spec.path === 'color.accent') value = inputs.color.brand;\n if (value === undefined && spec.path === 'font.heading') value = inputs.font.body;\n if (value === undefined) continue;\n if (spec.step) {\n fromInputs.push({ name: spec.name, path: spec.path, type: 'FLOAT', value: unit * (STEP_MULTIPLES[String(value)] ?? 0), description: STEP_HINT });\n continue;\n }\n const type: VariableType = typeof value === 'number' ? 'FLOAT' : spec.path.startsWith('color.') && HEX.test(String(value)) ? 'COLOR' : 'STRING';\n fromInputs.push({ name: spec.name, path: spec.path, type, value: value as string | number, ...(spec.description ? { description: spec.description } : {}) });\n }\n\n const derived: BrandVariable[] = [];\n for (const [path, value] of Object.entries(deriveTokens(inputs))) {\n const name = path.replace(/\\./g, '/');\n if (HEX.test(value)) derived.push({ name, path, type: 'COLOR', value });\n else if (/^-?[\\d.]+px$/.test(value)) derived.push({ name, path, type: 'FLOAT', value: Number.parseFloat(value) });\n else if (/^-?[\\d.]+$/.test(value)) derived.push({ name, path, type: 'FLOAT', value: Number(value) });\n else derived.push({ name, path, type: 'STRING', value });\n }\n return { format: VARIABLES_FORMAT, version: VARIABLES_VERSION, site, inputs: fromInputs, derived };\n}\n\nexport interface VariableChange {\n path: string;\n name: string;\n from: unknown;\n to: unknown;\n /** The change as a designer reads it: a spacing step in pixels rather than by its name. */\n shown: { from: string; to: string };\n}\n\nexport type VariablesImport =\n | { ok: true; inputs: BrandInputs; changes: VariableChange[] }\n | { ok: false; problems: string[] };\n\n/**\n * Read variables back onto a brand.\n *\n * Only the inputs are read; derived tokens are worked out again, never\n * copied. A spacing step comes back from pixels to the step it names, and a\n * value that is not one of the steps is refused rather than rounded, because\n * rounding would quietly change the designer's layout.\n */\nexport function variablesToBrand(document: unknown, base: BrandInputs): VariablesImport {\n const doc = document as Partial<BrandVariables> | null;\n if (!doc || doc.format !== VARIABLES_FORMAT || !Array.isArray(doc.inputs)) {\n return { ok: false, problems: ['This is not a Strata brand variables export.'] };\n }\n const current = BrandInputsSchema.parse(base);\n const next = structuredClone(current) as unknown as Record<string, unknown>;\n const problems: string[] = [];\n const changes: VariableChange[] = [];\n const unitVariable = doc.inputs.find((v) => v.path === 'shape.spaceBase');\n const unit = typeof unitVariable?.value === 'number' ? unitVariable.value : current.shape.spaceBase;\n\n for (const variable of doc.inputs) {\n const spec = INPUTS.find((s) => s.path === variable?.path);\n if (!spec) continue;\n let value: unknown = variable.value;\n // Figma keeps numbers as 32-bit floats, so 1.2 comes back as 1.2000000476837158.\n if (typeof value === 'number') value = Math.round(value * 10_000) / 10_000;\n if (spec.step) {\n const step = typeof value === 'number' ? SPACE_STEP_NAMES.find((name) => unit * (STEP_MULTIPLES[name] ?? -1) === value) : undefined;\n if (!step) { problems.push(`${spec.name} is ${String(value)}px, which is not a step on the spacing scale at a ${unit}px unit.`); continue; }\n value = step;\n }\n if (typeof value === 'string' && spec.path.startsWith('color.') && HEX.test(value)) value = value.toLowerCase();\n const was = read(current, spec.path);\n write(next, spec.path, value);\n const comparable = (v: unknown) => (typeof v === 'string' ? v.toLowerCase() : v);\n if (comparable(was) !== comparable(value) && !(was === undefined && (spec.path === 'color.accent' || spec.path === 'font.heading') && value === (spec.path === 'color.accent' ? current.color.brand : current.font.body))) {\n const show = (v: unknown, at: number) => (v === undefined ? 'not set' : spec.step ? `${at * (STEP_MULTIPLES[String(v)] ?? 0)}px` : String(v));\n changes.push({ path: spec.path, name: spec.name, from: was, to: value, shown: { from: show(was, current.shape.spaceBase), to: show(value, unit) } });\n }\n }\n // Check everything else too, so a designer sees every problem in one go rather than one round at a time.\n // A value refused above was never written, so it cannot be reported twice.\n const parsed = BrandInputsSchema.safeParse(next);\n if (!parsed.success) {\n for (const issue of parsed.error.issues) {\n const path = issue.path.join('.');\n const spec = INPUTS.find((s) => s.path === path);\n if (!spec) { problems.push(`${path}: ${issue.message}`); continue; }\n const sent = doc.inputs.find((v) => v?.path === path)?.value;\n problems.push(`${spec.name} is ${JSON.stringify(sent)}. ${issue.message.replace(/\\.?$/, '.')}`);\n }\n }\n if (problems.length || !parsed.success) return { ok: false, problems };\n return { ok: true, inputs: parsed.data, changes };\n}\n\n/** Each input variable's name, as a design tool shows it, and where it lives in Strata. A plugin reads variables back by name. */\nexport const INPUT_VARIABLE_PATHS: Readonly<Record<string, string>> = Object.fromEntries(INPUTS.map((spec) => [spec.name, spec.path]));\n","/**\n * The contrast gate.\n *\n * Derivation means most pairs cannot fail — a foreground is picked by measured\n * contrast and a blend is ratcheted until it passes. What is left are the pairs\n * a partner controls both sides of: their brand colour against their own\n * surfaces, their text against their own card, and their status colours\n * against it. Those are checked here, and a failure blocks a publish the way a\n * dangling reference already does\n * ([ADR 0009](../../../docs/decisions/0009-wcag-is-an-authoring-gate.md)).\n *\n * This is a floor, not a certificate. It is arithmetic over colour pairs: it\n * cannot see a value rendered on an image, text baked into a logo, or a\n * disabled control whose contrast is exempt but whose meaning is not. Treating\n * a green build as \"the brand is accessible\" is the failure mode to guard\n * against, which is why the result says what it checked.\n */\nimport { AA_NON_TEXT, AA_TEXT, contrastRatio, parseHex } from './contrast';\nimport { deriveTokens, type TokenSet } from './derive';\nimport type { BrandInputs } from './inputs';\n\nexport interface ContrastIssue {\n /** The token that fails, as an editor would be shown it. */\n token: string;\n foreground: string;\n background: string;\n ratio: number;\n required: number;\n /** The WCAG criterion, so the message can cite it. */\n criterion: '1.4.3 Contrast (Minimum)' | '1.4.11 Non-text Contrast';\n message: string;\n}\n\nexport interface ContrastReport {\n ok: boolean;\n issues: ContrastIssue[];\n /** How many pairs were examined — the honest denominator. */\n checked: number;\n}\n\ninterface Pair {\n token: string;\n fg: string;\n bg: string;\n required: number;\n criterion: ContrastIssue['criterion'];\n what: string;\n}\n\n/**\n * A gradient has no single luminance, so it is skipped rather than guessed at.\n * Safe because nothing is read directly against the page surface — the one\n * place a gradient is allowed.\n */\nconst isMeasurable = (value: string): boolean => parseHex(value) !== null;\n\nfunction pairsFor(tokens: TokenSet): Pair[] {\n const card = tokens['color.surface.card'];\n const text = (t: string) => ({ required: AA_TEXT, criterion: '1.4.3 Contrast (Minimum)' as const, what: t });\n const ui = (t: string) => ({ required: AA_NON_TEXT, criterion: '1.4.11 Non-text Contrast' as const, what: t });\n\n const pairs: Pair[] = [\n { token: 'color.text.default', fg: tokens['color.text.default'], bg: card, ...text('Body text on a card') },\n { token: 'color.text.muted', fg: tokens['color.text.muted'], bg: card, ...text('Muted text on a card') },\n { token: 'color.text.placeholder', fg: tokens['color.text.placeholder'], bg: card, ...text('Placeholder text in a field') },\n { token: 'color.text.link', fg: tokens['color.text.link'], bg: card, ...text('A link on a card') },\n { token: 'color.text.on-brand', fg: tokens['color.text.on-brand'], bg: tokens['color.brand.default'], ...text('Text on a brand-coloured button') },\n { token: 'color.text.on-header', fg: tokens['color.text.on-header'], bg: tokens['color.surface.header'], ...text('Text in the header') },\n { token: 'color.text.on-footer', fg: tokens['color.text.on-footer'], bg: tokens['color.surface.footer'], ...text('Text in the footer') },\n { token: 'color.brand.default', fg: tokens['color.brand.default'], bg: card, ...ui('A brand-coloured control against a card') },\n { token: 'color.border.default', fg: tokens['color.border.default'], bg: card, ...ui('A field border against a card') },\n ];\n\n for (const name of ['danger', 'warning', 'success', 'info']) {\n pairs.push({\n token: `color.status.${name}.text`,\n fg: tokens[`color.status.${name}.text`],\n bg: card,\n ...text(`${name[0].toUpperCase()}${name.slice(1)} message text`),\n });\n pairs.push({\n token: `color.status.${name}.default`,\n fg: tokens[`color.status.${name}.default`],\n bg: card,\n ...ui(`The ${name} indicator against a card`),\n });\n }\n\n return pairs;\n}\n\n/** Check a derived token set. */\nexport function checkContrast(tokens: TokenSet): ContrastReport {\n const issues: ContrastIssue[] = [];\n let checked = 0;\n\n for (const pair of pairsFor(tokens)) {\n if (!isMeasurable(pair.fg) || !isMeasurable(pair.bg)) continue;\n checked += 1;\n const ratio = contrastRatio(pair.fg, pair.bg);\n if (ratio >= pair.required) continue;\n issues.push({\n token: pair.token,\n foreground: pair.fg,\n background: pair.bg,\n ratio: Math.round(ratio * 100) / 100,\n required: pair.required,\n criterion: pair.criterion,\n message:\n `${pair.what} is ${(Math.round(ratio * 100) / 100).toFixed(2)}:1, ` +\n `below the ${pair.required}:1 that ${pair.criterion} requires.`,\n });\n }\n\n return { ok: issues.length === 0, issues, checked };\n}\n\n/** Check a brand before its tokens exist. What the CMS editor calls. */\nexport const checkBrandContrast = (input: BrandInputs): ContrastReport =>\n checkContrast(deriveTokens(input));\n","/**\n * Tokens → the W3C Design Tokens Community Group format.\n *\n * An OUTPUT, not the source. ADR 0005 originally had tokens authored as DTCG\n * files and built by Style Dictionary; writing the derivation showed why that\n * cannot be the whole story. A partner's tokens are computed at runtime from a\n * published brand document, so the authoring format has to be code — a\n * build-time pipeline can only ever produce the house theme, and a second\n * emitter for the runtime path would drift from it.\n *\n * So the format is kept as an export. It is what Figma, Style Dictionary and\n * the token tooling read, which is what makes a design-tool round trip a thing\n * we can add later rather than a rewrite, and it costs one function.\n */\nimport type { TokenSet } from './derive';\n\nexport type DtcgType = 'color' | 'dimension' | 'fontFamily' | 'fontWeight' | 'number' | 'shadow';\n\ninterface DtcgToken {\n $type: DtcgType;\n $value: string;\n $description?: string;\n}\n\nexport type DtcgGroup = { [key: string]: DtcgGroup | DtcgToken };\n\n/**\n * Infer the type from the token's path and value.\n *\n * By path first, because a value alone is ambiguous — `\"400\"` is a font weight\n * and `\"2px\"` is a dimension and both are strings. The paths are ours, so this\n * is reading our own naming convention rather than guessing.\n */\nfunction typeOf(path: string, value: string): DtcgType {\n if (path.startsWith('color.') || path.startsWith('focus.ring.') && !/width|offset|shadow/.test(path)) return 'color';\n if (path.includes('font.family')) return 'fontFamily';\n if (path.includes('font.weight')) return 'fontWeight';\n if (path.includes('line-height')) return 'number';\n if (path.includes('shadow')) return 'shadow';\n if (/^-?[\\d.]+(px|rem|em|%)$/.test(value) || value === '0') return 'dimension';\n return 'color';\n}\n\n/** A flat token set as a nested DTCG document. */\nexport function toDtcg(tokens: TokenSet): DtcgGroup {\n const root: DtcgGroup = {};\n for (const [path, value] of Object.entries(tokens)) {\n const parts = path.split('.');\n const leaf = parts.pop() as string;\n let node = root;\n for (const part of parts) {\n if (!(part in node) || '$value' in (node[part] as DtcgToken)) node[part] = {} as DtcgGroup;\n node = node[part] as DtcgGroup;\n }\n node[leaf] = { $type: typeOf(path, value), $value: value };\n }\n return root;\n}\n"],"mappings":";;;;;;;;;;;;AAiBA,SAAS,SAAS;AAGX,IAAM,iBAAiB,EAC3B,OAAO,EACP,MAAM,sCAAsC,oCAAoC;AAW5E,IAAM,qBAAqB,EAAE,MAAM;AAAA,EACxC;AAAA,EACA,EAAE,OAAO,EAAE,MAAM,0CAA0C,wCAAwC;AACrG,CAAC;AAEM,IAAM,gBAAgB,EAAE,OAAO;AAAA,EACpC,QAAQ,EAAE,OAAO;AAAA,EACjB,KAAK,EAAE,OAAO;AAAA,EACd,QAAQ,EAAE,OAAO,EAAE,SAAS;AAAA,EAC5B,OAAO,EAAE,OAAO,EAAE,SAAS;AAAA,EAC3B,SAAS,EAAE,OAAO,EAAE,SAAS;AAC/B,CAAC;AAYM,IAAM,kBAAkB,EAAE,OAAO,EAAE,IAAI,KAAK,EAAE,IAAI,KAAK;AAOvD,IAAM,mBAAmB,CAAC,KAAK,KAAK,K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AQ;AACpD;AAGO,IAAM,qBAAqB,CAAC,UACjC,cAAc,aAAa,KAAK,CAAC;;;ACtFnC,SAAS,OAAO,MAAc,OAAyB;AACrD,MAAI,KAAK,WAAW,QAAQ,KAAK,KAAK,WAAW,aAAa,KAAK,CAAC,sBAAsB,KAAK,IAAI,EAAG,QAAO;AAC7G,MAAI,KAAK,SAAS,aAAa,EAAG,QAAO;AACzC,MAAI,KAAK,SAAS,aAAa,EAAG,QAAO;AACzC,MAAI,KAAK,SAAS,aAAa,EAAG,QAAO;AACzC,MAAI,KAAK,SAAS,QAAQ,EAAG,QAAO;AACpC,MAAI,0BAA0B,KAAK,KAAK,KAAK,UAAU,IAAK,QAAO;AACnE,SAAO;AACT;AAGO,SAAS,OAAO,QAA6B;AAClD,QAAM,OAAkB,CAAC;AACzB,aAAW,CAAC,MAAM,KAAK,KAAK,OAAO,QAAQ,MAAM,GAAG;AAClD,UAAM,QAAQ,KAAK,MAAM,GAAG;AAC5B,UAAM,OAAO,MAAM,IAAI;AACvB,QAAI,OAAO;AACX,eAAW,QAAQ,OAAO;AACxB,UAAI,EAAE,QAAQ,SAAS,YAAa,KAAK,IAAI,EAAiB,MAAK,IAAI,IAAI,CAAC;AAC5E,aAAO,KAAK,IAAI;AAAA,IAClB;AACA,SAAK,IAAI,IAAI,EAAE,OAAO,OAAO,MAAM,KAAK,GAAG,QAAQ,MAAM;AAAA,EAC3D;AACA,SAAO;AACT;","names":["HEX"]}
package/dist/inputs.d.ts CHANGED
@@ -58,6 +58,14 @@ export type WebFont = z.infer<typeof WebFontSchema>;
58
58
  * raises the base size.
59
59
  */
60
60
  export declare const TypeScaleSchema: z.ZodNumber;
61
+ /**
62
+ * A step on the spacing scale, as the `space.*` tokens name them: `4` is four
63
+ * spacing units, `6` is eight, `8` is sixteen. Layout names a step rather
64
+ * than a size, so it follows the brand's spacing unit.
65
+ */
66
+ export declare const SPACE_STEP_NAMES: readonly ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"];
67
+ export declare const SpaceStepSchema: z.ZodEnum<["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]>;
68
+ export type SpaceStep = z.infer<typeof SpaceStepSchema>;
61
69
  /**
62
70
  * Each group is `.strict()`.
63
71
  *
@@ -179,6 +187,72 @@ export declare const BrandInputsSchema: z.ZodObject<{
179
187
  spaceBase?: number | undefined;
180
188
  borderWidth?: number | undefined;
181
189
  }>;
190
+ /**
191
+ * The page's frame and the spacing between columns.
192
+ *
193
+ * Margins and gutters name steps on the spacing scale rather than pixels,
194
+ * so they move with `shape.spaceBase` and stay on the same rhythm as
195
+ * everything else. The page width is bounded: below 640px a desktop page
196
+ * reads as a phone page, and above 1600px a line of text outgrows what can
197
+ * be read comfortably. Every value defaults to what pages had before this
198
+ * group existed, so a brand that sets none of it looks the same.
199
+ */
200
+ layout: z.ZodDefault<z.ZodObject<{
201
+ /** The widest the content gets on a large screen, in px, inside the margins. */
202
+ pageWidth: z.ZodDefault<z.ZodNumber>;
203
+ /** Space between the screen's edge and the content, at each size. */
204
+ margin: z.ZodDefault<z.ZodObject<{
205
+ phone: z.ZodDefault<z.ZodEnum<["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]>>;
206
+ tablet: z.ZodDefault<z.ZodEnum<["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]>>;
207
+ desktop: z.ZodDefault<z.ZodEnum<["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]>>;
208
+ }, "strict", z.ZodTypeAny, {
209
+ phone: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10";
210
+ tablet: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10";
211
+ desktop: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10";
212
+ }, {
213
+ phone?: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10" | undefined;
214
+ tablet?: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10" | undefined;
215
+ desktop?: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10" | undefined;
216
+ }>>;
217
+ /** The three gutters a grid may choose between columns. */
218
+ gutter: z.ZodDefault<z.ZodObject<{
219
+ sm: z.ZodDefault<z.ZodEnum<["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]>>;
220
+ md: z.ZodDefault<z.ZodEnum<["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]>>;
221
+ lg: z.ZodDefault<z.ZodEnum<["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]>>;
222
+ }, "strict", z.ZodTypeAny, {
223
+ sm: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10";
224
+ md: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10";
225
+ lg: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10";
226
+ }, {
227
+ sm?: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10" | undefined;
228
+ md?: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10" | undefined;
229
+ lg?: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10" | undefined;
230
+ }>>;
231
+ }, "strict", z.ZodTypeAny, {
232
+ pageWidth: number;
233
+ margin: {
234
+ phone: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10";
235
+ tablet: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10";
236
+ desktop: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10";
237
+ };
238
+ gutter: {
239
+ sm: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10";
240
+ md: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10";
241
+ lg: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10";
242
+ };
243
+ }, {
244
+ pageWidth?: number | undefined;
245
+ margin?: {
246
+ phone?: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10" | undefined;
247
+ tablet?: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10" | undefined;
248
+ desktop?: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10" | undefined;
249
+ } | undefined;
250
+ gutter?: {
251
+ sm?: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10" | undefined;
252
+ md?: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10" | undefined;
253
+ lg?: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10" | undefined;
254
+ } | undefined;
255
+ }>>;
182
256
  assets: z.ZodObject<{
183
257
  logo: z.ZodString;
184
258
  logoAlt: z.ZodString;
@@ -228,6 +302,19 @@ export declare const BrandInputsSchema: z.ZodObject<{
228
302
  spaceBase: number;
229
303
  borderWidth: number;
230
304
  };
305
+ layout: {
306
+ pageWidth: number;
307
+ margin: {
308
+ phone: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10";
309
+ tablet: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10";
310
+ desktop: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10";
311
+ };
312
+ gutter: {
313
+ sm: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10";
314
+ md: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10";
315
+ lg: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10";
316
+ };
317
+ };
231
318
  assets: {
232
319
  logo: string;
233
320
  logoAlt: string;
@@ -272,6 +359,19 @@ export declare const BrandInputsSchema: z.ZodObject<{
272
359
  logoDark?: string | undefined;
273
360
  favicon?: string | undefined;
274
361
  };
362
+ layout?: {
363
+ pageWidth?: number | undefined;
364
+ margin?: {
365
+ phone?: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10" | undefined;
366
+ tablet?: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10" | undefined;
367
+ desktop?: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10" | undefined;
368
+ } | undefined;
369
+ gutter?: {
370
+ sm?: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10" | undefined;
371
+ md?: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10" | undefined;
372
+ lg?: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10" | undefined;
373
+ } | undefined;
374
+ } | undefined;
275
375
  }>;
276
376
  export type BrandInputs = z.infer<typeof BrandInputsSchema>;
277
377
  /**
package/dist/tailwind.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  cssVarName
3
- } from "./chunk-YUZFJX3U.js";
3
+ } from "./chunk-7BKTXJHX.js";
4
4
 
5
5
  // packages/design-tokens/src/tailwind.ts
6
6
  var v = (path, fallback) => fallback ? `var(${cssVarName(path)}, ${fallback})` : `var(${cssVarName(path)})`;
@@ -0,0 +1,67 @@
1
+ /**
2
+ * A brand as design-tool variables, and back.
3
+ *
4
+ * Figma, and tools like it, keep a design system's values as variables in
5
+ * collections. This turns a partner's brand into two collections: the inputs a
6
+ * designer may change, and the tokens Strata derives from them, which are
7
+ * there to design with and are never read back. Changes come back as a patch
8
+ * to the brand inputs, checked by the same schema as any other edit, so
9
+ * nothing Strata would refuse in the CMS gets in through a design file.
10
+ *
11
+ * Plain JSON with no Figma types, so the plugin, the delivery API and the CMS
12
+ * share it, and it is tested without Figma.
13
+ */
14
+ import { type BrandInputs } from './inputs';
15
+ export declare const VARIABLES_FORMAT = "strata.brand-variables";
16
+ export declare const VARIABLES_VERSION = 1;
17
+ export type VariableType = 'COLOR' | 'FLOAT' | 'STRING';
18
+ /** One variable. `name` uses `/` for groups, as Figma does; `path` is where it lives in Strata. */
19
+ export interface BrandVariable {
20
+ name: string;
21
+ path: string;
22
+ type: VariableType;
23
+ value: string | number;
24
+ description?: string;
25
+ }
26
+ export interface BrandVariables {
27
+ format: typeof VARIABLES_FORMAT;
28
+ version: typeof VARIABLES_VERSION;
29
+ /** The site the brand belongs to, so a file says which partner it is. */
30
+ site: string;
31
+ /** What a designer may change, and what Strata reads back. */
32
+ inputs: BrandVariable[];
33
+ /** Worked out from the inputs. To design with; ignored when read back. */
34
+ derived: BrandVariable[];
35
+ }
36
+ /** A partner's brand as variables: its inputs, and the tokens derived from them. */
37
+ export declare function brandToVariables(brand: BrandInputs, site: string): BrandVariables;
38
+ export interface VariableChange {
39
+ path: string;
40
+ name: string;
41
+ from: unknown;
42
+ to: unknown;
43
+ /** The change as a designer reads it: a spacing step in pixels rather than by its name. */
44
+ shown: {
45
+ from: string;
46
+ to: string;
47
+ };
48
+ }
49
+ export type VariablesImport = {
50
+ ok: true;
51
+ inputs: BrandInputs;
52
+ changes: VariableChange[];
53
+ } | {
54
+ ok: false;
55
+ problems: string[];
56
+ };
57
+ /**
58
+ * Read variables back onto a brand.
59
+ *
60
+ * Only the inputs are read; derived tokens are worked out again, never
61
+ * copied. A spacing step comes back from pixels to the step it names, and a
62
+ * value that is not one of the steps is refused rather than rounded, because
63
+ * rounding would quietly change the designer's layout.
64
+ */
65
+ export declare function variablesToBrand(document: unknown, base: BrandInputs): VariablesImport;
66
+ /** Each input variable's name, as a design tool shows it, and where it lives in Strata. A plugin reads variables back by name. */
67
+ export declare const INPUT_VARIABLE_PATHS: Readonly<Record<string, string>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atomic-ui/design-tokens",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "The design tokens every Impkt component reads, and the derivation that turns a partner's handful of brand inputs into the whole set.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/css.ts"],"sourcesContent":["/**\n * Tokens → CSS custom properties.\n *\n * One emitter, used by both paths. The house theme is written to a stylesheet\n * at build time and a partner's brand is emitted at runtime from a published\n * document, and if those were two pieces of code they would drift — quietly,\n * because nothing would compare them. The same reasoning as the delivery API's\n * export command, which issues a real request rather than re-implementing the\n * response.\n */\nimport type { TokenSet } from './derive';\nimport type { WebFont } from './inputs';\n\n/** The namespace. Every property this package emits starts with it. */\nexport const PREFIX = '--impkt';\n\n/** `color.text.on-brand` → `--impkt-color-text-on-brand`. */\nexport const cssVarName = (path: string): string => `${PREFIX}-${path.replace(/\\./g, '-')}`;\n\n/** Tokens as a style object, for a runtime `style={}` or `element.style`. */\nexport function toStyleProperties(tokens: TokenSet): Record<string, string> {\n const out: Record<string, string> = {};\n for (const [path, value] of Object.entries(tokens)) out[cssVarName(path)] = value;\n return out;\n}\n\n/** Tokens as declarations, for a stylesheet or a `<style>` block. */\nexport function toCssDeclarations(tokens: TokenSet, indent = ' '): string {\n return Object.entries(tokens)\n .map(([path, value]) => `${indent}${cssVarName(path)}: ${value};`)\n .join('\\n');\n}\n\nexport interface StylesheetOptions {\n /** Defaults to `:root`. A preview frame or a brand switcher passes its own. */\n selector?: string;\n fonts?: WebFont[];\n}\n\n/**\n * A complete stylesheet: the faces the brand needs, then its properties.\n *\n * `@font-face` travels with the brand rather than being compiled into one\n * app's stylesheet, because a partner brings its own typeface and the shell\n * cannot know in advance what it is.\n */\nexport function toStylesheet(tokens: TokenSet, options: StylesheetOptions = {}): string {\n const { selector = ':root', fonts = [] } = options;\n const faces = fonts.map((f) => {\n const lines = [\n ` font-family: ${JSON.stringify(f.family)};`,\n ` src: url(${JSON.stringify(f.url)}) format(\"woff2\");`,\n ` font-display: ${f.display ?? 'swap'};`,\n ];\n if (f.weight) lines.push(` font-weight: ${f.weight};`);\n if (f.style) lines.push(` font-style: ${f.style};`);\n return `@font-face {\\n${lines.join('\\n')}\\n}`;\n });\n\n return [...faces, `${selector} {\\n${toCssDeclarations(tokens)}\\n}`].join('\\n\\n') + '\\n';\n}\n\n/**\n * Escape a stylesheet for inline injection.\n *\n * A brand is authored content, and authored content reaches a `<style>` block\n * here. `</style>` inside a font family name would close the element and start\n * an injection; the font-family value is already JSON-quoted above, and this is\n * the second line of defence for whoever writes the third emitter.\n */\nexport const escapeStyleText = (css: string): string => css.replace(/<\\/(style)/gi, '<\\\\/$1');\n"],"mappings":";AAcO,IAAM,SAAS;AAGf,IAAM,aAAa,CAAC,SAAyB,GAAG,MAAM,IAAI,KAAK,QAAQ,OAAO,GAAG,CAAC;AAGlF,SAAS,kBAAkB,QAA0C;AAC1E,QAAM,MAA8B,CAAC;AACrC,aAAW,CAAC,MAAM,KAAK,KAAK,OAAO,QAAQ,MAAM,EAAG,KAAI,WAAW,IAAI,CAAC,IAAI;AAC5E,SAAO;AACT;AAGO,SAAS,kBAAkB,QAAkB,SAAS,MAAc;AACzE,SAAO,OAAO,QAAQ,MAAM,EACzB,IAAI,CAAC,CAAC,MAAM,KAAK,MAAM,GAAG,MAAM,GAAG,WAAW,IAAI,CAAC,KAAK,KAAK,GAAG,EAChE,KAAK,IAAI;AACd;AAeO,SAAS,aAAa,QAAkB,UAA6B,CAAC,GAAW;AACtF,QAAM,EAAE,WAAW,SAAS,QAAQ,CAAC,EAAE,IAAI;AAC3C,QAAM,QAAQ,MAAM,IAAI,CAAC,MAAM;AAC7B,UAAM,QAAQ;AAAA,MACZ,kBAAkB,KAAK,UAAU,EAAE,MAAM,CAAC;AAAA,MAC1C,cAAc,KAAK,UAAU,EAAE,GAAG,CAAC;AAAA,MACnC,mBAAmB,EAAE,WAAW,MAAM;AAAA,IACxC;AACA,QAAI,EAAE,OAAQ,OAAM,KAAK,kBAAkB,EAAE,MAAM,GAAG;A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