@atomic-ui/design-tokens 0.1.5 → 0.2.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 +2 -2
- package/dist/{chunk-7BKTXJHX.js → chunk-ZTASNIBX.js} +8 -1
- package/dist/chunk-ZTASNIBX.js.map +1 -0
- package/dist/contrast.d.ts +1 -1
- package/dist/css.js +1 -1
- package/dist/derive.d.ts +10 -0
- package/dist/dtcg.d.ts +1 -1
- package/dist/fonts.d.ts +12 -4
- package/dist/index.d.ts +3 -2
- package/dist/index.js +273 -58
- package/dist/index.js.map +1 -1
- package/dist/inputs.d.ts +94 -9
- package/dist/motion.d.ts +118 -0
- package/dist/tailwind.js +1 -1
- package/package.json +8 -2
- package/dist/chunk-7BKTXJHX.js.map +0 -1
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ the handful of values a partner sets.
|
|
|
6
6
|
A brand authors around twenty **inputs**. Eighty-five **tokens** come out, and the
|
|
7
7
|
eighty-five are not authorable. That ratio is the whole design, and the reasoning —
|
|
8
8
|
with what Stripe, Cloudscape, Salesforce and Auth0 each allow — is
|
|
9
|
-
[ADR 0010](
|
|
9
|
+
[ADR 0010](https://github.com/matthill8286/strata/blob/main/docs/decisions/0010-what-a-brand-may-set.md).
|
|
10
10
|
|
|
11
11
|
```ts
|
|
12
12
|
import { DEFAULT_BRAND_INPUTS, deriveTokens, checkContrast, toStylesheet } from '@atomic-ui/design-tokens';
|
|
@@ -67,7 +67,7 @@ result is not mistaken for an audit.
|
|
|
67
67
|
|
|
68
68
|
`BrandInputsSchema` is not a projection of the stored brand document — it *is* it.
|
|
69
69
|
`@atomic-ui/content-schemas` extends it with the site key and nothing else
|
|
70
|
-
([ADR 0012](
|
|
70
|
+
([ADR 0012](https://github.com/matthill8286/strata/blob/main/docs/decisions/0012-brand-schema-is-the-inputs.md)), so there is one
|
|
71
71
|
definition rather than a contract and an implementation drifting apart.
|
|
72
72
|
|
|
73
73
|
Every group is `.strict()`. Zod strips unknown keys by default, so `color.onBrand`
|
|
@@ -22,6 +22,13 @@ var PAGE_FRAME = [
|
|
|
22
22
|
}`,
|
|
23
23
|
`@media (min-width: 64rem) {
|
|
24
24
|
.impkt-page { padding-inline: var(--impkt-layout-margin-desktop, 64px); }
|
|
25
|
+
}`,
|
|
26
|
+
// A node hidden on one size of screen (its `hideOn`), at the grid's phone breakpoint.
|
|
27
|
+
`@media (max-width: 40rem) {
|
|
28
|
+
[data-impkt-hide-on="phone"] { display: none !important; }
|
|
29
|
+
}`,
|
|
30
|
+
`@media (min-width: 40.0625rem) {
|
|
31
|
+
[data-impkt-hide-on="wide"] { display: none !important; }
|
|
25
32
|
}`
|
|
26
33
|
].join("\n");
|
|
27
34
|
function fontFaceCss(fonts) {
|
|
@@ -57,4 +64,4 @@ export {
|
|
|
57
64
|
toStylesheet,
|
|
58
65
|
escapeStyleText
|
|
59
66
|
};
|
|
60
|
-
//# sourceMappingURL=chunk-
|
|
67
|
+
//# sourceMappingURL=chunk-ZTASNIBX.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 // A node hidden on one size of screen (its `hideOn`), at the grid's phone breakpoint.\n `@media (max-width: 40rem) {\\n [data-impkt-hide-on=\"phone\"] { display: none !important; }\\n}`,\n `@media (min-width: 40.0625rem) {\\n [data-impkt-hide-on=\"wide\"] { display: none !important; }\\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;AAAA;AAAA,EAEA;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/contrast.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Contrast maths, to WCAG 2.x.
|
|
3
3
|
*
|
|
4
4
|
* This file exists because of one decision: a partner never authors a text
|
|
5
|
-
* colour to sit on a background ([ADR 0010](
|
|
5
|
+
* colour to sit on a background ([ADR 0010](https://github.com/matthill8286/strata/blob/main/docs/decisions/0010-what-a-brand-may-set.md)).
|
|
6
6
|
* They pick a brand colour and the system picks what reads on top of it. That
|
|
7
7
|
* makes the most common white-label accessibility failure — a mid-tone brand
|
|
8
8
|
* colour under a white label — unrepresentable rather than merely discouraged.
|
package/dist/css.js
CHANGED
package/dist/derive.d.ts
CHANGED
|
@@ -15,4 +15,14 @@ export type TokenSet = Record<string, string>;
|
|
|
15
15
|
* spacing scale so that shrinking the spacing unit cannot shrink a tap target.
|
|
16
16
|
*/
|
|
17
17
|
export declare const LOCKED_TOKENS: TokenSet;
|
|
18
|
+
/** Spacing steps, as multiples of the base unit. */
|
|
19
|
+
/**
|
|
20
|
+
* The spacing scale: each step is that many quarters of the brand's base unit,
|
|
21
|
+
* so with a 4px base `space.4` is 16px and `space.12` is 48px. Every step is a
|
|
22
|
+
* whole multiple, which is what keeps a page on its grid: two things that are
|
|
23
|
+
* `space.6` apart line up with anything else that is.
|
|
24
|
+
*/
|
|
25
|
+
export declare const SPACE_SCALE: readonly [0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 16, 20, 24, 28, 32, 36, 40, 48, 56, 64, 72, 80, 96];
|
|
26
|
+
/** A step's token name: `0.5` is `space.0-5`, since a dot separates the path. */
|
|
27
|
+
export declare const spaceName: (step: number) => string;
|
|
18
28
|
export declare function deriveTokens(input: BrandInputs): TokenSet;
|
package/dist/dtcg.d.ts
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* we can add later rather than a rewrite, and it costs one function.
|
|
14
14
|
*/
|
|
15
15
|
import type { TokenSet } from './derive';
|
|
16
|
-
export type DtcgType = 'color' | 'dimension' | 'fontFamily' | 'fontWeight' | 'number' | 'shadow';
|
|
16
|
+
export type DtcgType = 'color' | 'dimension' | 'fontFamily' | 'fontWeight' | 'number' | 'shadow' | 'duration' | 'cubicBezier' | 'string';
|
|
17
17
|
interface DtcgToken {
|
|
18
18
|
$type: DtcgType;
|
|
19
19
|
$value: string;
|
package/dist/fonts.d.ts
CHANGED
|
@@ -8,10 +8,18 @@
|
|
|
8
8
|
* called loaded when the brand carries a file for it.
|
|
9
9
|
*/
|
|
10
10
|
import type { WebFont } from './inputs';
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
/**
|
|
12
|
+
* What a browser draws when a sans-serif family is missing: the device's own
|
|
13
|
+
* interface font. A brand font often has only Latin letters, so the stack also
|
|
14
|
+
* names fonts that have Greek, Cyrillic and Simplified Chinese (ADR 0026):
|
|
15
|
+
* Arial and Roboto carry Greek and Cyrillic, and PingFang SC (Apple), Microsoft
|
|
16
|
+
* YaHei (Windows) and Noto Sans SC (Android and Linux) carry Chinese. A browser
|
|
17
|
+
* picks per letter, so a Greek page in a Latin-only brand font keeps the brand
|
|
18
|
+
* font for digits and Latin names and takes the Greek letters from these.
|
|
19
|
+
*/
|
|
20
|
+
export declare const SYSTEM_SANS = "system-ui, -apple-system, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, \"Noto Sans\", \"PingFang SC\", \"Microsoft YaHei\", \"Noto Sans SC\", sans-serif";
|
|
21
|
+
/** The serif equivalent, for a brand whose type is a serif, with the same cover. */
|
|
22
|
+
export declare const SYSTEM_SERIF = "Georgia, Cambria, \"Times New Roman\", \"Noto Serif\", \"Songti SC\", SimSun, \"Noto Serif SC\", serif";
|
|
15
23
|
/** The weights Strata's components use: body, medium labels, semibold and bold headings. */
|
|
16
24
|
export declare const FONT_WEIGHTS: readonly ["400", "500", "600", "700"];
|
|
17
25
|
/** The families in a `font-family` value, unquoted, in order. */
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
2
|
+
* @atomic-ui/design-tokens — the tokens every component reads, and the
|
|
3
3
|
* derivation that produces them from the handful of values a partner sets.
|
|
4
4
|
*
|
|
5
5
|
* The shape of the package is the decision it implements: `BrandInputs` is
|
|
6
6
|
* small and closed, `deriveTokens` is the only way to get from there to a token
|
|
7
7
|
* set, and nothing exports a way to pin a derived value. See
|
|
8
|
-
* [ADR 0010](
|
|
8
|
+
* [ADR 0010](https://github.com/matthill8286/strata/blob/main/docs/decisions/0010-what-a-brand-may-set.md).
|
|
9
9
|
*/
|
|
10
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 { deriveMotionTokens, DISTANCE_NAMES, DURATION_LIMITS, DURATION_NAMES, EASING_NAMES, MOTION_PERSONALITIES, MotionInputsSchema, PERSONALITIES, resolveMotion, scaleSpring, SPRING_NAMES, springAt, springDuration, springToLinear, STAGGER_NAMES, type Bezier, type DistanceName, type DurationName, type EasingName, type MotionInputs, type MotionPersonality, type ResolvedMotion, type Spring, type SpringName, type StaggerName, } from './motion';
|
|
12
13
|
export { brandToVariables, INPUT_VARIABLE_PATHS, variablesToBrand, VARIABLES_FORMAT, VARIABLES_VERSION, type BrandVariable, type BrandVariables, type VariableChange, type VariablesImport, type VariableType, } from './variables';
|
|
13
14
|
export { cssVarName, escapeStyleText, fontFaceCss, PAGE_FRAME, PREFIX, toCssDeclarations, toStyleProperties, toStylesheet, type StylesheetOptions, } from './css';
|
|
14
15
|
export { checkBrandContrast, checkContrast, type ContrastIssue, type ContrastReport, } from './validate';
|
package/dist/index.js
CHANGED
|
@@ -7,27 +7,140 @@ import {
|
|
|
7
7
|
toCssDeclarations,
|
|
8
8
|
toStyleProperties,
|
|
9
9
|
toStylesheet
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-ZTASNIBX.js";
|
|
11
11
|
|
|
12
12
|
// packages/design-tokens/src/inputs.ts
|
|
13
|
+
import { z as z2 } from "zod";
|
|
14
|
+
|
|
15
|
+
// packages/design-tokens/src/motion.ts
|
|
13
16
|
import { z } from "zod";
|
|
14
|
-
var
|
|
15
|
-
var
|
|
17
|
+
var MOTION_PERSONALITIES = ["calm", "lively", "expressive"];
|
|
18
|
+
var MotionInputsSchema = z.strictObject({
|
|
19
|
+
personality: z.enum(MOTION_PERSONALITIES).default("calm"),
|
|
20
|
+
speed: z.number().min(0.75).max(1.25).default(1)
|
|
21
|
+
});
|
|
22
|
+
var DURATION_NAMES = ["instant", "fast", "base", "slow", "scene"];
|
|
23
|
+
var EASING_NAMES = ["standard", "enter", "exit", "emphasis"];
|
|
24
|
+
var SPRING_NAMES = ["snappy", "gentle", "bouncy"];
|
|
25
|
+
var STAGGER_NAMES = ["tight", "base", "loose"];
|
|
26
|
+
var DISTANCE_NAMES = ["near", "far"];
|
|
27
|
+
var PERSONALITIES = {
|
|
28
|
+
calm: {
|
|
29
|
+
duration: { fast: 140, base: 220, slow: 360, scene: 700 },
|
|
30
|
+
easing: { standard: [0.2, 0, 0, 1], enter: [0, 0, 0.2, 1], exit: [0.4, 0, 1, 1], emphasis: [0.65, 0, 0.35, 1] },
|
|
31
|
+
spring: {
|
|
32
|
+
snappy: { stiffness: 400, dampingRatio: 1, mass: 1 },
|
|
33
|
+
gentle: { stiffness: 170, dampingRatio: 1, mass: 1 },
|
|
34
|
+
bouncy: { stiffness: 260, dampingRatio: 0.82, mass: 1 }
|
|
35
|
+
},
|
|
36
|
+
stagger: { tight: 30, base: 60, loose: 100 },
|
|
37
|
+
distance: { near: 4, far: 12 }
|
|
38
|
+
},
|
|
39
|
+
lively: {
|
|
40
|
+
duration: { fast: 160, base: 260, slow: 440, scene: 900 },
|
|
41
|
+
easing: { standard: [0.2, 0, 0, 1], enter: [0.22, 1, 0.36, 1], exit: [0.55, 0, 1, 0.45], emphasis: [0.83, 0, 0.17, 1] },
|
|
42
|
+
spring: {
|
|
43
|
+
snappy: { stiffness: 500, dampingRatio: 0.86, mass: 1 },
|
|
44
|
+
gentle: { stiffness: 200, dampingRatio: 0.9, mass: 1 },
|
|
45
|
+
bouncy: { stiffness: 300, dampingRatio: 0.65, mass: 1 }
|
|
46
|
+
},
|
|
47
|
+
stagger: { tight: 40, base: 80, loose: 140 },
|
|
48
|
+
distance: { near: 6, far: 16 }
|
|
49
|
+
},
|
|
50
|
+
expressive: {
|
|
51
|
+
duration: { fast: 180, base: 320, slow: 560, scene: 1200 },
|
|
52
|
+
easing: { standard: [0.2, 0, 0, 1], enter: [0.16, 1, 0.3, 1], exit: [0.7, 0, 0.84, 0], emphasis: [0.7, 0, 0.2, 1] },
|
|
53
|
+
spring: {
|
|
54
|
+
snappy: { stiffness: 520, dampingRatio: 0.75, mass: 1 },
|
|
55
|
+
gentle: { stiffness: 180, dampingRatio: 0.8, mass: 1 },
|
|
56
|
+
bouncy: { stiffness: 320, dampingRatio: 0.5, mass: 1 }
|
|
57
|
+
},
|
|
58
|
+
stagger: { tight: 50, base: 100, loose: 180 },
|
|
59
|
+
distance: { near: 8, far: 24 }
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
var DURATION_LIMITS = { min: 0, max: 2e3 };
|
|
63
|
+
function springAt(spring, t) {
|
|
64
|
+
const { stiffness: k, dampingRatio: z3, mass: m } = spring;
|
|
65
|
+
const w0 = Math.sqrt(k / m);
|
|
66
|
+
if (z3 < 1) {
|
|
67
|
+
const wd = w0 * Math.sqrt(1 - z3 * z3);
|
|
68
|
+
return 1 - Math.exp(-z3 * w0 * t) * (Math.cos(wd * t) + z3 * w0 / wd * Math.sin(wd * t));
|
|
69
|
+
}
|
|
70
|
+
return 1 - Math.exp(-w0 * t) * (1 + w0 * t);
|
|
71
|
+
}
|
|
72
|
+
function springDuration(spring, tolerance = 1e-3) {
|
|
73
|
+
const step = 1 / 240;
|
|
74
|
+
let last = 0;
|
|
75
|
+
for (let t = 0; t < 10; t += step) if (Math.abs(1 - springAt(spring, t)) > tolerance) last = t;
|
|
76
|
+
return Math.ceil((last + step) * 1e3);
|
|
77
|
+
}
|
|
78
|
+
function springToLinear(spring, points = 40) {
|
|
79
|
+
const durationMs = springDuration(spring);
|
|
80
|
+
const values = [];
|
|
81
|
+
for (let i = 0; i <= points; i += 1) {
|
|
82
|
+
const v = i === points ? 1 : springAt(spring, durationMs / 1e3 * (i / points));
|
|
83
|
+
values.push(String(Math.round(v * 1e4) / 1e4));
|
|
84
|
+
}
|
|
85
|
+
return { easing: `linear(${values.join(", ")})`, durationMs };
|
|
86
|
+
}
|
|
87
|
+
function scaleSpring(spring, speed) {
|
|
88
|
+
return { ...spring, stiffness: spring.stiffness * speed * speed };
|
|
89
|
+
}
|
|
90
|
+
var ms = (n) => `${Math.round(n)}ms`;
|
|
91
|
+
var bezier = (b) => `cubic-bezier(${b.join(", ")})`;
|
|
92
|
+
var round = (n) => String(Math.round(n * 1e3) / 1e3);
|
|
93
|
+
function resolveMotion(input, spaceBase = 4) {
|
|
94
|
+
const { personality, speed } = MotionInputsSchema.parse(input ?? {});
|
|
95
|
+
const p = PERSONALITIES[personality];
|
|
96
|
+
const scaled = (r) => Object.fromEntries(Object.entries(r).map(([k, v]) => [k, v / speed]));
|
|
97
|
+
return {
|
|
98
|
+
personality,
|
|
99
|
+
speed,
|
|
100
|
+
duration: { instant: 0, ...scaled(p.duration) },
|
|
101
|
+
easing: p.easing,
|
|
102
|
+
spring: Object.fromEntries(Object.entries(p.spring).map(([k, s]) => [k, scaleSpring(s, speed)])),
|
|
103
|
+
stagger: scaled(p.stagger),
|
|
104
|
+
distance: Object.fromEntries(Object.entries(p.distance).map(([k, steps]) => [k, steps * spaceBase]))
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function deriveMotionTokens(input, spaceBase = 4) {
|
|
108
|
+
const m = resolveMotion(input, spaceBase);
|
|
109
|
+
const tokens = {};
|
|
110
|
+
for (const name of DURATION_NAMES) tokens[`motion.duration.${name}`] = ms(m.duration[name]);
|
|
111
|
+
for (const name of EASING_NAMES) tokens[`motion.easing.${name}`] = bezier(m.easing[name]);
|
|
112
|
+
for (const name of SPRING_NAMES) {
|
|
113
|
+
const s = m.spring[name];
|
|
114
|
+
const baked = springToLinear(s);
|
|
115
|
+
tokens[`motion.spring.${name}.stiffness`] = round(s.stiffness);
|
|
116
|
+
tokens[`motion.spring.${name}.damping-ratio`] = round(s.dampingRatio);
|
|
117
|
+
tokens[`motion.spring.${name}.mass`] = round(s.mass);
|
|
118
|
+
tokens[`motion.spring.${name}.easing`] = baked.easing;
|
|
119
|
+
tokens[`motion.spring.${name}.duration`] = ms(baked.durationMs);
|
|
120
|
+
}
|
|
121
|
+
for (const name of STAGGER_NAMES) tokens[`motion.stagger.${name}`] = ms(m.stagger[name]);
|
|
122
|
+
for (const name of DISTANCE_NAMES) tokens[`motion.distance.${name}`] = `${m.distance[name]}px`;
|
|
123
|
+
return tokens;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// packages/design-tokens/src/inputs.ts
|
|
127
|
+
var HexColorSchema = z2.string().regex(/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/, "Must be a hex colour, e.g. #5e10b1");
|
|
128
|
+
var SurfaceValueSchema = z2.union([
|
|
16
129
|
HexColorSchema,
|
|
17
|
-
|
|
130
|
+
z2.string().regex(/^(linear|radial|conic)-gradient\(.+\)$/, "Must be a hex colour or a CSS gradient")
|
|
18
131
|
]);
|
|
19
|
-
var WebFontSchema =
|
|
20
|
-
family:
|
|
21
|
-
url:
|
|
22
|
-
weight:
|
|
23
|
-
style:
|
|
24
|
-
display:
|
|
132
|
+
var WebFontSchema = z2.object({
|
|
133
|
+
family: z2.string(),
|
|
134
|
+
url: z2.string(),
|
|
135
|
+
weight: z2.string().optional(),
|
|
136
|
+
style: z2.string().optional(),
|
|
137
|
+
display: z2.string().optional()
|
|
25
138
|
});
|
|
26
|
-
var TypeScaleSchema =
|
|
139
|
+
var TypeScaleSchema = z2.number().min(1.067).max(1.333);
|
|
27
140
|
var SPACE_STEP_NAMES = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"];
|
|
28
|
-
var SpaceStepSchema =
|
|
29
|
-
var BrandInputsSchema =
|
|
30
|
-
color:
|
|
141
|
+
var SpaceStepSchema = z2.enum(SPACE_STEP_NAMES);
|
|
142
|
+
var BrandInputsSchema = z2.object({
|
|
143
|
+
color: z2.strictObject({
|
|
31
144
|
/** The partner's primary colour: actions, emphasis, selected states. */
|
|
32
145
|
brand: HexColorSchema,
|
|
33
146
|
/** The secondary colour. Defaults to the brand colour when unset. */
|
|
@@ -40,6 +153,18 @@ var BrandInputsSchema = z.object({
|
|
|
40
153
|
surfaceHeader: HexColorSchema,
|
|
41
154
|
/** The footer band. */
|
|
42
155
|
surfaceFooter: HexColorSchema,
|
|
156
|
+
/** Text in the header band. Unset, it is the accent on a light band and white or black on a dark one. */
|
|
157
|
+
textHeader: HexColorSchema.optional(),
|
|
158
|
+
/** Text in the footer band. Unset, it follows the same rule as the header's. */
|
|
159
|
+
textFooter: HexColorSchema.optional(),
|
|
160
|
+
/** Headings. Unset, they take the accent; a brand whose headings are set in ink names it here. */
|
|
161
|
+
textHeading: HexColorSchema.optional(),
|
|
162
|
+
/**
|
|
163
|
+
* Colours for things told apart by colour alone: the lanes of a timeline,
|
|
164
|
+
* the branches of a list, the stripe along a footer. In order; unset, the
|
|
165
|
+
* accent and the status colours stand in.
|
|
166
|
+
*/
|
|
167
|
+
chart: z2.array(HexColorSchema).max(8).optional(),
|
|
43
168
|
/** Default body text, on `surfaceCard`. */
|
|
44
169
|
text: HexColorSchema,
|
|
45
170
|
danger: HexColorSchema,
|
|
@@ -47,23 +172,34 @@ var BrandInputsSchema = z.object({
|
|
|
47
172
|
success: HexColorSchema,
|
|
48
173
|
info: HexColorSchema
|
|
49
174
|
}),
|
|
50
|
-
font:
|
|
51
|
-
body:
|
|
175
|
+
font: z2.strictObject({
|
|
176
|
+
body: z2.string(),
|
|
52
177
|
/** Defaults to `body` when unset — most brands have one typeface. */
|
|
53
|
-
heading:
|
|
178
|
+
heading: z2.string().optional(),
|
|
179
|
+
/** Code-like labels: hashes, branches, version lines. Unset, the device's own monospace face. */
|
|
180
|
+
mono: z2.string().optional(),
|
|
181
|
+
/** The face of the small line above a heading. `mono` sets it as a code label, as a changelog would. */
|
|
182
|
+
eyebrow: z2.enum(["body", "mono"]).default("body"),
|
|
54
183
|
/** Root size in px. Everything else is `rem`, scaled from this. */
|
|
55
|
-
sizeBase:
|
|
184
|
+
sizeBase: z2.number().min(14).max(20).default(16),
|
|
56
185
|
scale: TypeScaleSchema.default(1.2),
|
|
57
186
|
/** Faces the shell must load. A partner brings its own typeface. */
|
|
58
|
-
webFonts:
|
|
187
|
+
webFonts: z2.array(WebFontSchema).default([])
|
|
59
188
|
}),
|
|
60
|
-
shape:
|
|
189
|
+
shape: z2.strictObject({
|
|
61
190
|
/** Corner rounding in px. Every radius derives from it. */
|
|
62
|
-
radiusBase:
|
|
191
|
+
radiusBase: z2.number().min(0).max(24).default(4),
|
|
63
192
|
/** The spacing unit in px. All spacing is a multiple. */
|
|
64
|
-
spaceBase:
|
|
193
|
+
spaceBase: z2.number().min(2).max(8).default(4),
|
|
65
194
|
/** Default border weight in px. */
|
|
66
|
-
borderWidth:
|
|
195
|
+
borderWidth: z2.number().min(1).max(3).default(1),
|
|
196
|
+
/** A form field: a card-coloured box with a border, or a box filled a shade off the page with a fainter one. */
|
|
197
|
+
fields: z2.enum(["outlined", "filled"]).default("outlined"),
|
|
198
|
+
/**
|
|
199
|
+
* What a solid button does when pointed at: a shade darker, or turn the
|
|
200
|
+
* accent colour, its arrow lifting a quarter-turn up, as some brands do.
|
|
201
|
+
*/
|
|
202
|
+
buttonHover: z2.enum(["shade", "accent"]).default("shade")
|
|
67
203
|
}),
|
|
68
204
|
/**
|
|
69
205
|
* The page's frame and the spacing between columns.
|
|
@@ -75,29 +211,42 @@ var BrandInputsSchema = z.object({
|
|
|
75
211
|
* be read comfortably. Every value defaults to what pages had before this
|
|
76
212
|
* group existed, so a brand that sets none of it looks the same.
|
|
77
213
|
*/
|
|
78
|
-
layout:
|
|
214
|
+
layout: z2.strictObject({
|
|
79
215
|
/** The widest the content gets on a large screen, in px, inside the margins. */
|
|
80
|
-
pageWidth:
|
|
216
|
+
pageWidth: z2.number().min(640).max(1600).default(1200),
|
|
81
217
|
/** Space between the screen's edge and the content, at each size. */
|
|
82
|
-
margin:
|
|
218
|
+
margin: z2.strictObject({
|
|
83
219
|
phone: SpaceStepSchema.default("4"),
|
|
84
220
|
tablet: SpaceStepSchema.default("6"),
|
|
85
221
|
desktop: SpaceStepSchema.default("8")
|
|
86
222
|
}).default({}),
|
|
87
223
|
/** The three gutters a grid may choose between columns. */
|
|
88
|
-
gutter:
|
|
224
|
+
gutter: z2.strictObject({
|
|
89
225
|
sm: SpaceStepSchema.default("2"),
|
|
90
226
|
md: SpaceStepSchema.default("4"),
|
|
91
227
|
lg: SpaceStepSchema.default("6")
|
|
92
228
|
}).default({})
|
|
93
229
|
}).default({}),
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
230
|
+
/**
|
|
231
|
+
* How the brand moves: a personality and a playback speed, and nothing else.
|
|
232
|
+
* Every duration, curve and spring is derived from these two
|
|
233
|
+
* ([ADR 0027](https://github.com/matthill8286/strata/blob/main/docs/decisions/0027-motion-is-states-transitions-and-timelines.md)).
|
|
234
|
+
* Defaults to calm at normal speed, so a brand that sets none of it is quiet.
|
|
235
|
+
*/
|
|
236
|
+
motion: MotionInputsSchema.default({}),
|
|
237
|
+
/**
|
|
238
|
+
* The logo and favicon. A site made in the CMS before anyone uploads a logo
|
|
239
|
+
* has none, which is the house default's empty logo rather than a missing
|
|
240
|
+
* brand: without the default, delivery refused the whole brand and the site
|
|
241
|
+
* rendered in the generic look.
|
|
242
|
+
*/
|
|
243
|
+
assets: z2.strictObject({
|
|
244
|
+
logo: z2.string(),
|
|
245
|
+
logoAlt: z2.string(),
|
|
97
246
|
/** For use on dark surfaces, where the main logo would disappear. */
|
|
98
|
-
logoDark:
|
|
99
|
-
favicon:
|
|
100
|
-
})
|
|
247
|
+
logoDark: z2.string().optional(),
|
|
248
|
+
favicon: z2.string().optional()
|
|
249
|
+
}).default({ logo: "", logoAlt: "" })
|
|
101
250
|
});
|
|
102
251
|
var DEFAULT_BRAND_INPUTS = BrandInputsSchema.parse({
|
|
103
252
|
color: {
|
|
@@ -118,8 +267,8 @@ var DEFAULT_BRAND_INPUTS = BrandInputsSchema.parse({
|
|
|
118
267
|
});
|
|
119
268
|
|
|
120
269
|
// 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';
|
|
270
|
+
var SYSTEM_SANS = 'system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif';
|
|
271
|
+
var SYSTEM_SERIF = 'Georgia, Cambria, "Times New Roman", "Noto Serif", "Songti SC", SimSun, "Noto Serif SC", serif';
|
|
123
272
|
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
273
|
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
274
|
var FONT_WEIGHTS = ["400", "500", "600", "700"];
|
|
@@ -254,6 +403,7 @@ function ensureContrast(foreground, background, target) {
|
|
|
254
403
|
}
|
|
255
404
|
|
|
256
405
|
// packages/design-tokens/src/derive.ts
|
|
406
|
+
var MONO_STACK = 'ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace';
|
|
257
407
|
var LOCKED_TOKENS = {
|
|
258
408
|
"focus.ring.inner": "#ffffff",
|
|
259
409
|
"focus.ring.outer": "#1a1a1a",
|
|
@@ -263,7 +413,9 @@ var LOCKED_TOKENS = {
|
|
|
263
413
|
"target.min": "24px",
|
|
264
414
|
"target.spacing": "8px"
|
|
265
415
|
};
|
|
266
|
-
var
|
|
416
|
+
var SPACE_SCALE = [0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 16, 20, 24, 28, 32, 36, 40, 48, 56, 64, 72, 80, 96];
|
|
417
|
+
var spaceName = (step) => `space.${String(step).replace(".", "-")}`;
|
|
418
|
+
var LAYOUT_STEPS = {
|
|
267
419
|
"0": 0,
|
|
268
420
|
"1": 1,
|
|
269
421
|
"2": 2,
|
|
@@ -276,16 +428,20 @@ var SPACE_STEPS = {
|
|
|
276
428
|
"9": 24,
|
|
277
429
|
"10": 32
|
|
278
430
|
};
|
|
279
|
-
var
|
|
280
|
-
"2xs":
|
|
281
|
-
xs:
|
|
282
|
-
sm:
|
|
283
|
-
md:
|
|
284
|
-
lg:
|
|
285
|
-
xl:
|
|
286
|
-
"2xl":
|
|
287
|
-
"3xl":
|
|
431
|
+
var TYPE_SCALE = {
|
|
432
|
+
"2xs": { size: 12, leading: 16 },
|
|
433
|
+
xs: { size: 12, leading: 16 },
|
|
434
|
+
sm: { size: 14, leading: 20 },
|
|
435
|
+
md: { size: 16, leading: 24 },
|
|
436
|
+
lg: { size: 18, leading: 28 },
|
|
437
|
+
xl: { size: 20, leading: 28 },
|
|
438
|
+
"2xl": { size: 24, leading: 32 },
|
|
439
|
+
"3xl": { size: 30, leading: 36 },
|
|
440
|
+
"4xl": { size: 36, leading: 40 },
|
|
441
|
+
"5xl": { size: 48, leading: 52 },
|
|
442
|
+
"6xl": { size: 60, leading: 64 }
|
|
288
443
|
};
|
|
444
|
+
var DISPLAY_FROM = 24;
|
|
289
445
|
var MIN_FONT_PX = 12;
|
|
290
446
|
function onSurface(surface, accent) {
|
|
291
447
|
const rgb = parseHex(surface);
|
|
@@ -294,11 +450,17 @@ function onSurface(surface, accent) {
|
|
|
294
450
|
}
|
|
295
451
|
function typeRamp(sizeBase, scale) {
|
|
296
452
|
const out = {};
|
|
297
|
-
|
|
298
|
-
|
|
453
|
+
const stretch = Math.max(0.8, Math.min(1.4, scale / 1.25));
|
|
454
|
+
for (const [name, { size, leading }] of Object.entries(TYPE_SCALE)) {
|
|
455
|
+
const display = size >= DISPLAY_FROM ? 1 + (stretch - 1) * Math.min(1, (size - 16) / 44) : 1;
|
|
456
|
+
const px = Math.max(MIN_FONT_PX, size / 16 * sizeBase * display);
|
|
299
457
|
const rem = Math.ceil(px / sizeBase * 1e4) / 1e4;
|
|
300
458
|
out[`font.size.${name}`] = `${rem}rem`;
|
|
459
|
+
out[`font.leading.${name}`] = String(Math.round(leading / size * 1e3) / 1e3);
|
|
301
460
|
}
|
|
461
|
+
out["font.tracking.tight"] = "-0.02em";
|
|
462
|
+
out["font.tracking.normal"] = "0em";
|
|
463
|
+
out["font.tracking.wide"] = "0.06em";
|
|
302
464
|
return out;
|
|
303
465
|
}
|
|
304
466
|
function deriveTokens(input) {
|
|
@@ -325,13 +487,27 @@ function deriveTokens(input) {
|
|
|
325
487
|
tokens["color.text.muted"] = ensureContrast(mix(color.text, card, 0.38), card, AA_TEXT);
|
|
326
488
|
tokens["color.text.placeholder"] = ensureContrast(mix(color.text, card, 0.5), card, AA_TEXT);
|
|
327
489
|
tokens["color.text.on-brand"] = pickForeground(color.brand);
|
|
328
|
-
tokens["color.text.on-header"] = onSurface(color.surfaceHeader, accent);
|
|
329
|
-
tokens["color.text.on-footer"] = onSurface(color.surfaceFooter, accent);
|
|
330
|
-
tokens["color.text.heading"] = ensureContrast(accent, card, AA_TEXT);
|
|
490
|
+
tokens["color.text.on-header"] = color.textHeader ? ensureContrast(color.textHeader, color.surfaceHeader, AA_TEXT) : onSurface(color.surfaceHeader, accent);
|
|
491
|
+
tokens["color.text.on-footer"] = color.textFooter ? ensureContrast(color.textFooter, color.surfaceFooter, AA_TEXT) : onSurface(color.surfaceFooter, accent);
|
|
492
|
+
tokens["color.text.heading"] = ensureContrast(color.textHeading ?? accent, card, AA_TEXT);
|
|
493
|
+
const chart = color.chart?.length ? color.chart : [accent, color.info, color.success, color.warning, color.danger];
|
|
494
|
+
chart.forEach((c, i) => {
|
|
495
|
+
tokens[`color.chart.${i + 1}`] = ensureContrast(c, card, AA_NON_TEXT);
|
|
496
|
+
});
|
|
331
497
|
tokens["color.text.link"] = ensureContrast(color.brand, card, AA_TEXT);
|
|
332
498
|
tokens["color.text.link-hover"] = darken(tokens["color.text.link"], 0.2);
|
|
333
499
|
tokens["color.border.default"] = ensureContrast(mix(color.text, card, 0.7), card, AA_NON_TEXT);
|
|
334
500
|
tokens["color.border.strong"] = ensureContrast(mix(color.text, card, 0.45), card, AA_NON_TEXT);
|
|
501
|
+
if (shape.fields === "filled") {
|
|
502
|
+
tokens["color.field.surface"] = mix(card, pickForeground(card), 0.05);
|
|
503
|
+
tokens["color.field.border"] = tokens["color.border.default"];
|
|
504
|
+
tokens["shadow.field"] = "none";
|
|
505
|
+
}
|
|
506
|
+
if (shape.buttonHover === "accent") {
|
|
507
|
+
tokens["color.action.hover"] = accent;
|
|
508
|
+
tokens["color.action.on-hover"] = pickForeground(accent);
|
|
509
|
+
tokens["motion.button.turn"] = "-45deg";
|
|
510
|
+
}
|
|
335
511
|
for (const name of ["danger", "warning", "success", "info"]) {
|
|
336
512
|
const base = color[name];
|
|
337
513
|
tokens[`color.status.${name}.default`] = ensureContrast(base, card, AA_NON_TEXT);
|
|
@@ -342,6 +518,13 @@ function deriveTokens(input) {
|
|
|
342
518
|
const fallbackFor = (value) => openFont(primaryFamily(value))?.category === "serif" ? "serif" : "sans";
|
|
343
519
|
tokens["font.family.body"] = fontStack(font.body, fallbackFor(font.body));
|
|
344
520
|
tokens["font.family.heading"] = fontStack(font.heading ?? font.body, fallbackFor(font.heading ?? font.body));
|
|
521
|
+
tokens["font.family.mono"] = font.mono ? `${fontFamilies(font.mono).map((f) => JSON.stringify(f)).join(", ")}, ${MONO_STACK}` : MONO_STACK;
|
|
522
|
+
tokens["font.family.eyebrow"] = font.eyebrow === "mono" ? tokens["font.family.mono"] : tokens["font.family.body"];
|
|
523
|
+
if (font.eyebrow === "mono") {
|
|
524
|
+
tokens["color.text.eyebrow"] = tokens["color.text.muted"];
|
|
525
|
+
tokens["font.weight.eyebrow"] = "500";
|
|
526
|
+
tokens["font.size.eyebrow"] = "0.6875rem";
|
|
527
|
+
}
|
|
345
528
|
tokens["font.size.root"] = `${font.sizeBase}px`;
|
|
346
529
|
Object.assign(tokens, typeRamp(font.sizeBase, font.scale));
|
|
347
530
|
tokens["font.weight.regular"] = "400";
|
|
@@ -351,18 +534,27 @@ function deriveTokens(input) {
|
|
|
351
534
|
tokens["font.line-height.tight"] = "1.25";
|
|
352
535
|
tokens["font.line-height.normal"] = "1.5";
|
|
353
536
|
tokens["font.line-height.relaxed"] = "1.75";
|
|
354
|
-
for (const
|
|
355
|
-
|
|
356
|
-
}
|
|
537
|
+
for (const step2 of SPACE_SCALE) tokens[spaceName(step2)] = `${shape.spaceBase * step2}px`;
|
|
538
|
+
const r = (multiple) => `${Math.round(shape.radiusBase * multiple * 10) / 10}px`;
|
|
357
539
|
tokens["radius.none"] = "0";
|
|
358
|
-
tokens["radius.
|
|
359
|
-
tokens["radius.
|
|
360
|
-
tokens["radius.
|
|
361
|
-
tokens["radius.
|
|
540
|
+
tokens["radius.xs"] = r(1 / 3);
|
|
541
|
+
tokens["radius.sm"] = r(2 / 3);
|
|
542
|
+
tokens["radius.md"] = r(1);
|
|
543
|
+
tokens["radius.lg"] = r(4 / 3);
|
|
544
|
+
tokens["radius.xl"] = r(2);
|
|
545
|
+
tokens["radius.2xl"] = r(8 / 3);
|
|
546
|
+
tokens["radius.3xl"] = r(4);
|
|
362
547
|
tokens["radius.full"] = "9999px";
|
|
548
|
+
const ink = parseHex(color.text) ? color.text : "#000000";
|
|
549
|
+
const a = (alpha) => `color-mix(in srgb, ${ink} ${Math.round(alpha * 100)}%, transparent)`;
|
|
550
|
+
tokens["shadow.xs"] = `0 1px 2px 0 ${a(0.05)}`;
|
|
551
|
+
tokens["shadow.sm"] = `0 1px 3px 0 ${a(0.1)}, 0 1px 2px -1px ${a(0.1)}`;
|
|
552
|
+
tokens["shadow.md"] = `0 4px 6px -1px ${a(0.1)}, 0 2px 4px -2px ${a(0.1)}`;
|
|
553
|
+
tokens["shadow.lg"] = `0 10px 15px -3px ${a(0.1)}, 0 4px 6px -4px ${a(0.1)}`;
|
|
554
|
+
tokens["shadow.xl"] = `0 20px 25px -5px ${a(0.1)}, 0 8px 10px -6px ${a(0.1)}`;
|
|
363
555
|
tokens["border.width.thin"] = `${shape.borderWidth}px`;
|
|
364
556
|
tokens["border.width.thick"] = `${shape.borderWidth * 2}px`;
|
|
365
|
-
const step = (name) => `${shape.spaceBase * (
|
|
557
|
+
const step = (name) => `${shape.spaceBase * (LAYOUT_STEPS[name] ?? 0)}px`;
|
|
366
558
|
tokens["layout.page.width"] = `${layout.pageWidth}px`;
|
|
367
559
|
tokens["layout.margin.phone"] = step(layout.margin.phone);
|
|
368
560
|
tokens["layout.margin.tablet"] = step(layout.margin.tablet);
|
|
@@ -370,6 +562,7 @@ function deriveTokens(input) {
|
|
|
370
562
|
tokens["layout.gutter.sm"] = step(layout.gutter.sm);
|
|
371
563
|
tokens["layout.gutter.md"] = step(layout.gutter.md);
|
|
372
564
|
tokens["layout.gutter.lg"] = step(layout.gutter.lg);
|
|
565
|
+
Object.assign(tokens, deriveMotionTokens(input.motion, input.shape?.spaceBase ?? 4));
|
|
373
566
|
return tokens;
|
|
374
567
|
}
|
|
375
568
|
|
|
@@ -547,6 +740,13 @@ var checkBrandContrast = (input) => checkContrast(deriveTokens(input));
|
|
|
547
740
|
|
|
548
741
|
// packages/design-tokens/src/dtcg.ts
|
|
549
742
|
function typeOf(path, value) {
|
|
743
|
+
if (path.startsWith("motion.")) {
|
|
744
|
+
if (/ms$/.test(value)) return "duration";
|
|
745
|
+
if (value.startsWith("cubic-bezier(")) return "cubicBezier";
|
|
746
|
+
if (value.startsWith("linear(")) return "string";
|
|
747
|
+
if (/px$/.test(value)) return "dimension";
|
|
748
|
+
return "number";
|
|
749
|
+
}
|
|
550
750
|
if (path.startsWith("color.") || path.startsWith("focus.ring.") && !/width|offset|shadow/.test(path)) return "color";
|
|
551
751
|
if (path.includes("font.family")) return "fontFamily";
|
|
552
752
|
if (path.includes("font.weight")) return "fontWeight";
|
|
@@ -575,14 +775,23 @@ export {
|
|
|
575
775
|
AA_TEXT,
|
|
576
776
|
BrandInputsSchema,
|
|
577
777
|
DEFAULT_BRAND_INPUTS,
|
|
778
|
+
DISTANCE_NAMES,
|
|
779
|
+
DURATION_LIMITS,
|
|
780
|
+
DURATION_NAMES,
|
|
781
|
+
EASING_NAMES,
|
|
578
782
|
FONT_WEIGHTS,
|
|
579
783
|
HexColorSchema,
|
|
580
784
|
INPUT_VARIABLE_PATHS,
|
|
581
785
|
LOCKED_TOKENS,
|
|
786
|
+
MOTION_PERSONALITIES,
|
|
787
|
+
MotionInputsSchema,
|
|
582
788
|
OPEN_FONTS,
|
|
583
789
|
PAGE_FRAME,
|
|
790
|
+
PERSONALITIES,
|
|
584
791
|
PREFIX,
|
|
585
792
|
SPACE_STEP_NAMES,
|
|
793
|
+
SPRING_NAMES,
|
|
794
|
+
STAGGER_NAMES,
|
|
586
795
|
SYSTEM_SANS,
|
|
587
796
|
SYSTEM_SERIF,
|
|
588
797
|
SpaceStepSchema,
|
|
@@ -597,6 +806,7 @@ export {
|
|
|
597
806
|
contrastRatio,
|
|
598
807
|
cssVarName,
|
|
599
808
|
darken,
|
|
809
|
+
deriveMotionTokens,
|
|
600
810
|
deriveTokens,
|
|
601
811
|
ensureContrast,
|
|
602
812
|
escapeStyleText,
|
|
@@ -611,6 +821,11 @@ export {
|
|
|
611
821
|
parseHex,
|
|
612
822
|
pickForeground,
|
|
613
823
|
primaryFamily,
|
|
824
|
+
resolveMotion,
|
|
825
|
+
scaleSpring,
|
|
826
|
+
springAt,
|
|
827
|
+
springDuration,
|
|
828
|
+
springToLinear,
|
|
614
829
|
tint,
|
|
615
830
|
toCssDeclarations,
|
|
616
831
|
toDtcg,
|