@atomic-ui/design-tokens 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +86 -2
- package/dist/chunk-6CBHZQ2Z.js +47 -0
- package/dist/chunk-6CBHZQ2Z.js.map +1 -0
- package/dist/contrast.d.ts +96 -0
- package/dist/css.d.ts +42 -0
- package/dist/css.js +17 -0
- package/dist/css.js.map +1 -0
- package/dist/derive.d.ts +18 -0
- package/dist/dtcg.d.ts +27 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +4434 -0
- package/dist/index.js.map +1 -0
- package/dist/inputs.d.ts +285 -0
- package/dist/tailwind.d.ts +70 -0
- package/dist/tailwind.js +69 -0
- package/dist/tailwind.js.map +1 -0
- package/dist/validate.d.ts +23 -0
- package/package.json +41 -4
package/README.md
CHANGED
|
@@ -1,3 +1,87 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @atomic-ui/design-tokens
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The tokens every Impkt component reads, and the derivation that produces them from
|
|
4
|
+
the handful of values a partner sets.
|
|
5
|
+
|
|
6
|
+
A brand authors around twenty **inputs**. Eighty-five **tokens** come out, and the
|
|
7
|
+
eighty-five are not authorable. That ratio is the whole design, and the reasoning —
|
|
8
|
+
with what Stripe, Cloudscape, Salesforce and Auth0 each allow — is
|
|
9
|
+
[ADR 0010](../../docs/decisions/0010-what-a-brand-may-set.md).
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { brandToInputs, deriveTokens, checkContrast, toStylesheet } from '@atomic-ui/design-tokens';
|
|
13
|
+
|
|
14
|
+
const { inputs, dropped } = brandToInputs(publishedBrandDocument);
|
|
15
|
+
const tokens = deriveTokens(inputs);
|
|
16
|
+
|
|
17
|
+
const report = checkContrast(tokens); // blocks a publish when it fails
|
|
18
|
+
const css = toStylesheet(tokens, { fonts: inputs.font.webFonts });
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## What a partner sets
|
|
22
|
+
|
|
23
|
+
Colour: `brand`, `accent`, four surfaces (`page`, `card`, `header`, `footer`), `text`,
|
|
24
|
+
and `danger` / `warning` / `success` / `info`. Typography: body family, heading family,
|
|
25
|
+
base size, ramp ratio, web fonts. Shape: base radius, base spacing unit, base border
|
|
26
|
+
width. Assets: logo, dark logo, favicon.
|
|
27
|
+
|
|
28
|
+
Two absences are the point. There is **no foreground colour** — text on a surface is
|
|
29
|
+
picked by measured contrast, so a partner cannot pin white text onto a mid-tone brand
|
|
30
|
+
colour, which is the most common white-label accessibility failure. And there is **no
|
|
31
|
+
focus colour** — the ring keeps system values, because a focus indicator drawn in a
|
|
32
|
+
partner's brand colour on that partner's background is where focus visibility dies.
|
|
33
|
+
|
|
34
|
+
The page surface is the one that may be a gradient. It is safe by construction rather
|
|
35
|
+
than by exception: nothing is read against it, because text sits on a card.
|
|
36
|
+
|
|
37
|
+
## What derives
|
|
38
|
+
|
|
39
|
+
Hover, active and subtle states are tone shifts. The type ramp scales from the base
|
|
40
|
+
size in `rem`, with a 12px floor. Spacing and radii are multiples of their units.
|
|
41
|
+
Muted text, placeholder text and borders are blends toward the surface, each **ratcheted
|
|
42
|
+
until it passes** — 4.5:1 for text, 3:1 for a UI boundary — so a blend that works for
|
|
43
|
+
one brand cannot quietly fail for the next.
|
|
44
|
+
|
|
45
|
+
Headings take the accent colour, which is what every migrated theme set
|
|
46
|
+
`typography.headingColor` to. Header and footer text takes the accent on a light band
|
|
47
|
+
and the picked foreground on a dark one, which reproduces Northwind's purple-on-white
|
|
48
|
+
header rather than flattening it to near-black.
|
|
49
|
+
|
|
50
|
+
Status colours get `.default` at 3:1 and `.text` at 4.5:1 separately, because the yellow
|
|
51
|
+
that is fine as a warning icon is not fine as warning text.
|
|
52
|
+
|
|
53
|
+
## What it will not do
|
|
54
|
+
|
|
55
|
+
Derivation keeps what is *ours* legible. It will not change what is *theirs*: a
|
|
56
|
+
near-white brand colour stays near-white, and `checkContrast` reports it against 1.4.11
|
|
57
|
+
rather than silently darkening it. Telling a partner their brand colour cannot be a
|
|
58
|
+
filled button is honest; changing their brand without saying so is not.
|
|
59
|
+
|
|
60
|
+
The gate is a floor, not a certificate. It is arithmetic over colour pairs — it cannot
|
|
61
|
+
see text baked into a logo, a value rendered over an image, or whether an error message
|
|
62
|
+
makes sense. `ContrastReport.checked` reports how many pairs it looked at so a clean
|
|
63
|
+
result is not mistaken for an audit.
|
|
64
|
+
|
|
65
|
+
## This is the brand schema
|
|
66
|
+
|
|
67
|
+
`BrandInputsSchema` is not a projection of the stored brand document — it *is* it.
|
|
68
|
+
`@atomic-ui/content-schemas` extends it with the site key and nothing else
|
|
69
|
+
([ADR 0012](../../docs/decisions/0012-brand-schema-is-the-inputs.md)), so there is one
|
|
70
|
+
definition rather than a contract and an implementation drifting apart.
|
|
71
|
+
|
|
72
|
+
Every group is `.strict()`. Zod strips unknown keys by default, so `color.onBrand`
|
|
73
|
+
would otherwise validate, be dropped, and leave an editor looking at a brand that
|
|
74
|
+
ignores a value they set. Being refused says what is actually true: there is nowhere to
|
|
75
|
+
put a foreground colour, because foregrounds are measured.
|
|
76
|
+
|
|
77
|
+
## Commands
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
pnpm --filter @atomic-ui/design-tokens test # derivation, contrast, round-trip
|
|
81
|
+
pnpm --filter @atomic-ui/design-tokens typecheck
|
|
82
|
+
pnpm --filter @atomic-ui/design-tokens emit # dist/tokens.css + dist/tokens.dtcg.json
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
`emit` writes the house theme: what a shell renders before it knows which partner it is
|
|
86
|
+
serving. It calls the same `deriveTokens` the runtime does, so the file on disk and the
|
|
87
|
+
properties a live page carries cannot disagree.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// packages/design-tokens/src/css.ts
|
|
8
|
+
var PREFIX = "--impkt";
|
|
9
|
+
var cssVarName = (path) => `${PREFIX}-${path.replace(/\./g, "-")}`;
|
|
10
|
+
function toStyleProperties(tokens) {
|
|
11
|
+
const out = {};
|
|
12
|
+
for (const [path, value] of Object.entries(tokens)) out[cssVarName(path)] = value;
|
|
13
|
+
return out;
|
|
14
|
+
}
|
|
15
|
+
function toCssDeclarations(tokens, indent = " ") {
|
|
16
|
+
return Object.entries(tokens).map(([path, value]) => `${indent}${cssVarName(path)}: ${value};`).join("\n");
|
|
17
|
+
}
|
|
18
|
+
function toStylesheet(tokens, options = {}) {
|
|
19
|
+
const { selector = ":root", fonts = [] } = options;
|
|
20
|
+
const faces = fonts.map((f) => {
|
|
21
|
+
const lines = [
|
|
22
|
+
` font-family: ${JSON.stringify(f.family)};`,
|
|
23
|
+
` src: url(${JSON.stringify(f.url)}) format("woff2");`,
|
|
24
|
+
` font-display: ${f.display ?? "swap"};`
|
|
25
|
+
];
|
|
26
|
+
if (f.weight) lines.push(` font-weight: ${f.weight};`);
|
|
27
|
+
if (f.style) lines.push(` font-style: ${f.style};`);
|
|
28
|
+
return `@font-face {
|
|
29
|
+
${lines.join("\n")}
|
|
30
|
+
}`;
|
|
31
|
+
});
|
|
32
|
+
return [...faces, `${selector} {
|
|
33
|
+
${toCssDeclarations(tokens)}
|
|
34
|
+
}`].join("\n\n") + "\n";
|
|
35
|
+
}
|
|
36
|
+
var escapeStyleText = (css) => css.replace(/<\/(style)/gi, "<\\/$1");
|
|
37
|
+
|
|
38
|
+
export {
|
|
39
|
+
__export,
|
|
40
|
+
PREFIX,
|
|
41
|
+
cssVarName,
|
|
42
|
+
toStyleProperties,
|
|
43
|
+
toCssDeclarations,
|
|
44
|
+
toStylesheet,
|
|
45
|
+
escapeStyleText
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=chunk-6CBHZQ2Z.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 */\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;AACtD,QAAI,EAAE,MAAO,OAAM,KAAK,iBAAiB,EAAE,KAAK,GAAG;AACnD,WAAO;AAAA,EAAiB,MAAM,KAAK,IAAI,CAAC;AAAA;AAAA,EAC1C,CAAC;AAED,SAAO,CAAC,GAAG,OAAO,GAAG,QAAQ;AAAA,EAAO,kBAAkB,MAAM,CAAC;AAAA,EAAK,EAAE,KAAK,MAAM,IAAI;AACrF;AAUO,IAAM,kBAAkB,CAAC,QAAwB,IAAI,QAAQ,gBAAgB,QAAQ;","names":[]}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contrast maths, to WCAG 2.x.
|
|
3
|
+
*
|
|
4
|
+
* This file exists because of one decision: a partner never authors a text
|
|
5
|
+
* colour to sit on a background ([ADR 0010](../../../docs/decisions/0010-what-a-brand-may-set.md)).
|
|
6
|
+
* They pick a brand colour and the system picks what reads on top of it. That
|
|
7
|
+
* makes the most common white-label accessibility failure — a mid-tone brand
|
|
8
|
+
* colour under a white label — unrepresentable rather than merely discouraged.
|
|
9
|
+
*
|
|
10
|
+
* The formulae are from WCAG 2.2 (relative luminance, and the (L1+0.05)/(L2+0.05)
|
|
11
|
+
* contrast ratio). They are stable, cheap and exactly what an auditor will use.
|
|
12
|
+
* APCA is better maths and is not normative yet; when it is, this is the one
|
|
13
|
+
* file that changes.
|
|
14
|
+
*/
|
|
15
|
+
/** A colour this module can reason about: #rgb, #rrggbb, or #rrggbbaa. */
|
|
16
|
+
export type Hex = string;
|
|
17
|
+
export interface Rgb {
|
|
18
|
+
r: number;
|
|
19
|
+
g: number;
|
|
20
|
+
b: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Parse a hex colour. Returns null rather than throwing: callers are usually
|
|
24
|
+
* validating authored content, where "this is not a colour" is a message to an
|
|
25
|
+
* editor and not an exception.
|
|
26
|
+
*/
|
|
27
|
+
export declare function parseHex(value: string): Rgb | null;
|
|
28
|
+
export declare function toHex({ r, g, b }: Rgb): Hex;
|
|
29
|
+
/** WCAG relative luminance. */
|
|
30
|
+
export declare function luminance(rgb: Rgb): number;
|
|
31
|
+
/** WCAG contrast ratio, 1–21. Returns 0 for anything unparseable. */
|
|
32
|
+
export declare function contrastRatio(a: string, b: string): number;
|
|
33
|
+
/** The thresholds, named, so call sites read as the criterion they enforce. */
|
|
34
|
+
export declare const AA_TEXT = 4.5;
|
|
35
|
+
export declare const AA_LARGE_TEXT = 3;
|
|
36
|
+
/** 1.4.11 Non-text Contrast: UI components and meaningful graphics. */
|
|
37
|
+
export declare const AA_NON_TEXT = 3;
|
|
38
|
+
/**
|
|
39
|
+
* The two foregrounds anything may be drawn in.
|
|
40
|
+
*
|
|
41
|
+
* Not pure black and white. Pure black on a light surface is harsher than it
|
|
42
|
+
* needs to be and pure white on a saturated brand colour haloes; these are the
|
|
43
|
+
* near-neutrals most systems settle on, and they still clear 4.5:1 against
|
|
44
|
+
* every surface the inputs can produce — which the tests assert rather than
|
|
45
|
+
* assume.
|
|
46
|
+
*/
|
|
47
|
+
export declare const FOREGROUND_DARK = "#1a1a1a";
|
|
48
|
+
export declare const FOREGROUND_LIGHT = "#ffffff";
|
|
49
|
+
/**
|
|
50
|
+
* Pick the foreground that reads best on `background`.
|
|
51
|
+
*
|
|
52
|
+
* Deliberately returns the BETTER of the two rather than the first that passes.
|
|
53
|
+
* On a mid-tone brand colour both may clear 4.5:1 and the winner is still
|
|
54
|
+
* visibly easier to read; on a colour where neither passes, the better one is
|
|
55
|
+
* what gets rendered while the publish check reports the failure. A caller that
|
|
56
|
+
* needs to know whether it passed asks `contrastRatio` — this function always
|
|
57
|
+
* answers.
|
|
58
|
+
*/
|
|
59
|
+
export declare function pickForeground(background: string): Hex;
|
|
60
|
+
/**
|
|
61
|
+
* Shift a colour toward black or white by `amount` (0–1).
|
|
62
|
+
*
|
|
63
|
+
* This is how every hover, active and subtle state is derived. Mixing in sRGB
|
|
64
|
+
* is not perceptually uniform and a perceptual space would give more even
|
|
65
|
+
* steps; sRGB is used because it is what CSS `color-mix` does, so a value
|
|
66
|
+
* derived here and a value a stylesheet computes agree. Matching the platform
|
|
67
|
+
* matters more here than being slightly more correct than it.
|
|
68
|
+
*/
|
|
69
|
+
export declare function shade(color: string, amount: number): Hex;
|
|
70
|
+
/** Darken toward black. */
|
|
71
|
+
export declare const darken: (color: string, amount: number) => Hex;
|
|
72
|
+
/** Lighten toward white. */
|
|
73
|
+
export declare const lighten: (color: string, amount: number) => Hex;
|
|
74
|
+
/**
|
|
75
|
+
* A very light tint of a colour, for subtle backgrounds — an info panel, a
|
|
76
|
+
* selected row. Always light enough to take the dark foreground, which is what
|
|
77
|
+
* makes "subtle" a safe surface rather than a guess.
|
|
78
|
+
*/
|
|
79
|
+
export declare const tint: (color: string) => Hex;
|
|
80
|
+
/** Blend two colours. `amount` is how far from `a` toward `b`. */
|
|
81
|
+
export declare function mix(a: string, b: string, amount: number): Hex;
|
|
82
|
+
/**
|
|
83
|
+
* Walk a foreground away from its background until it clears `target`.
|
|
84
|
+
*
|
|
85
|
+
* This is the mechanism that makes a derived token safe rather than merely
|
|
86
|
+
* plausible. Muted text, placeholder text and borders are all produced by
|
|
87
|
+
* blending toward a surface, and a blend that looks right on one brand falls
|
|
88
|
+
* under 4.5:1 on the next. Rather than pick a blend that happens to work for
|
|
89
|
+
* the brands we have, each derived value is pushed back until it passes.
|
|
90
|
+
*
|
|
91
|
+
* It moves toward whichever end of the scale is already further from the
|
|
92
|
+
* background, in small steps, and gives up after it runs out of room — at
|
|
93
|
+
* which point the colour is returned as-is and the publish check reports it.
|
|
94
|
+
* Silently returning black would hide a brand that cannot work.
|
|
95
|
+
*/
|
|
96
|
+
export declare function ensureContrast(foreground: string, background: string, target: number): Hex;
|
package/dist/css.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tokens → CSS custom properties.
|
|
3
|
+
*
|
|
4
|
+
* One emitter, used by both paths. The house theme is written to a stylesheet
|
|
5
|
+
* at build time and a partner's brand is emitted at runtime from a published
|
|
6
|
+
* document, and if those were two pieces of code they would drift — quietly,
|
|
7
|
+
* because nothing would compare them. The same reasoning as the delivery API's
|
|
8
|
+
* export command, which issues a real request rather than re-implementing the
|
|
9
|
+
* response.
|
|
10
|
+
*/
|
|
11
|
+
import type { TokenSet } from './derive';
|
|
12
|
+
import type { WebFont } from './inputs';
|
|
13
|
+
/** The namespace. Every property this package emits starts with it. */
|
|
14
|
+
export declare const PREFIX = "--impkt";
|
|
15
|
+
/** `color.text.on-brand` → `--impkt-color-text-on-brand`. */
|
|
16
|
+
export declare const cssVarName: (path: string) => string;
|
|
17
|
+
/** Tokens as a style object, for a runtime `style={}` or `element.style`. */
|
|
18
|
+
export declare function toStyleProperties(tokens: TokenSet): Record<string, string>;
|
|
19
|
+
/** Tokens as declarations, for a stylesheet or a `<style>` block. */
|
|
20
|
+
export declare function toCssDeclarations(tokens: TokenSet, indent?: string): string;
|
|
21
|
+
export interface StylesheetOptions {
|
|
22
|
+
/** Defaults to `:root`. A preview frame or a brand switcher passes its own. */
|
|
23
|
+
selector?: string;
|
|
24
|
+
fonts?: WebFont[];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* A complete stylesheet: the faces the brand needs, then its properties.
|
|
28
|
+
*
|
|
29
|
+
* `@font-face` travels with the brand rather than being compiled into one
|
|
30
|
+
* app's stylesheet, because a partner brings its own typeface and the shell
|
|
31
|
+
* cannot know in advance what it is.
|
|
32
|
+
*/
|
|
33
|
+
export declare function toStylesheet(tokens: TokenSet, options?: StylesheetOptions): string;
|
|
34
|
+
/**
|
|
35
|
+
* Escape a stylesheet for inline injection.
|
|
36
|
+
*
|
|
37
|
+
* A brand is authored content, and authored content reaches a `<style>` block
|
|
38
|
+
* here. `</style>` inside a font family name would close the element and start
|
|
39
|
+
* an injection; the font-family value is already JSON-quoted above, and this is
|
|
40
|
+
* the second line of defence for whoever writes the third emitter.
|
|
41
|
+
*/
|
|
42
|
+
export declare const escapeStyleText: (css: string) => string;
|
package/dist/css.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PREFIX,
|
|
3
|
+
cssVarName,
|
|
4
|
+
escapeStyleText,
|
|
5
|
+
toCssDeclarations,
|
|
6
|
+
toStyleProperties,
|
|
7
|
+
toStylesheet
|
|
8
|
+
} from "./chunk-6CBHZQ2Z.js";
|
|
9
|
+
export {
|
|
10
|
+
PREFIX,
|
|
11
|
+
cssVarName,
|
|
12
|
+
escapeStyleText,
|
|
13
|
+
toCssDeclarations,
|
|
14
|
+
toStyleProperties,
|
|
15
|
+
toStylesheet
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=css.js.map
|
package/dist/css.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/derive.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { BrandInputs } from './inputs';
|
|
2
|
+
/** A flat token set: dotted path → CSS value. */
|
|
3
|
+
export type TokenSet = Record<string, string>;
|
|
4
|
+
/**
|
|
5
|
+
* The locked tokens. A brand cannot reach these and nothing derives them.
|
|
6
|
+
*
|
|
7
|
+
* The focus ring is two-tone — a light inner ring inside a dark outer one — so
|
|
8
|
+
* that it stays visible on any surface a partner can produce, including their
|
|
9
|
+
* own brand colour. A single-colour ring has to assume a background, and the
|
|
10
|
+
* one it assumes is the one a white-label product does not have. This is the
|
|
11
|
+
* rule Scotland's design system states directly: adopters may change the
|
|
12
|
+
* colours, and must still keep the system's colours for focus.
|
|
13
|
+
*
|
|
14
|
+
* `target.min` is WCAG 2.2's 2.5.8 minimum. It is here rather than in the
|
|
15
|
+
* spacing scale so that shrinking the spacing unit cannot shrink a tap target.
|
|
16
|
+
*/
|
|
17
|
+
export declare const LOCKED_TOKENS: TokenSet;
|
|
18
|
+
export declare function deriveTokens(input: BrandInputs): TokenSet;
|
package/dist/dtcg.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tokens → the W3C Design Tokens Community Group format.
|
|
3
|
+
*
|
|
4
|
+
* An OUTPUT, not the source. ADR 0005 originally had tokens authored as DTCG
|
|
5
|
+
* files and built by Style Dictionary; writing the derivation showed why that
|
|
6
|
+
* cannot be the whole story. A partner's tokens are computed at runtime from a
|
|
7
|
+
* published brand document, so the authoring format has to be code — a
|
|
8
|
+
* build-time pipeline can only ever produce the house theme, and a second
|
|
9
|
+
* emitter for the runtime path would drift from it.
|
|
10
|
+
*
|
|
11
|
+
* So the format is kept as an export. It is what Figma, Style Dictionary and
|
|
12
|
+
* the token tooling read, which is what makes a design-tool round trip a thing
|
|
13
|
+
* we can add later rather than a rewrite, and it costs one function.
|
|
14
|
+
*/
|
|
15
|
+
import type { TokenSet } from './derive';
|
|
16
|
+
export type DtcgType = 'color' | 'dimension' | 'fontFamily' | 'fontWeight' | 'number' | 'shadow';
|
|
17
|
+
interface DtcgToken {
|
|
18
|
+
$type: DtcgType;
|
|
19
|
+
$value: string;
|
|
20
|
+
$description?: string;
|
|
21
|
+
}
|
|
22
|
+
export type DtcgGroup = {
|
|
23
|
+
[key: string]: DtcgGroup | DtcgToken;
|
|
24
|
+
};
|
|
25
|
+
/** A flat token set as a nested DTCG document. */
|
|
26
|
+
export declare function toDtcg(tokens: TokenSet): DtcgGroup;
|
|
27
|
+
export {};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @impkt/design-tokens — the tokens every component reads, and the
|
|
3
|
+
* derivation that produces them from the handful of values a partner sets.
|
|
4
|
+
*
|
|
5
|
+
* The shape of the package is the decision it implements: `BrandInputs` is
|
|
6
|
+
* small and closed, `deriveTokens` is the only way to get from there to a token
|
|
7
|
+
* set, and nothing exports a way to pin a derived value. See
|
|
8
|
+
* [ADR 0010](../../../docs/decisions/0010-what-a-brand-may-set.md).
|
|
9
|
+
*/
|
|
10
|
+
export { BrandInputsSchema, DEFAULT_BRAND_INPUTS, HexColorSchema, SurfaceValueSchema, TypeScaleSchema, WebFontSchema, type BrandInputs, type WebFont, } from './inputs';
|
|
11
|
+
export { deriveTokens, LOCKED_TOKENS, type TokenSet } from './derive';
|
|
12
|
+
export { cssVarName, escapeStyleText, PREFIX, toCssDeclarations, toStyleProperties, toStylesheet, type StylesheetOptions, } from './css';
|
|
13
|
+
export { checkBrandContrast, checkContrast, type ContrastIssue, type ContrastReport, } from './validate';
|
|
14
|
+
export { toDtcg, type DtcgGroup } from './dtcg';
|
|
15
|
+
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';
|