From 9fb1c9737714f45cd32b1a8cf9e5897a6da806d9 Mon Sep 17 00:00:00 2001 From: Jason Morse Date: Thu, 5 Nov 2026 14:28:15 -0800 Subject: [PATCH] allow both cool and warm tokens to be used independently --- .changeset/design-flex-palette-loading.md | 5 + .changeset/design-system-default-state.md | 5 + apps/bundle-size/scenarios.json | 55 ++- packages/agentic/design/README.md | 8 +- .../agentic/design/references/contributing.md | 5 +- .../agentic/design/references/entry-points.md | 31 +- packages/agentic/design/references/theming.md | 26 +- packages/agentic/design/references/tokens.md | 11 +- .../flex-defaults/generate-defaults.mjs | 63 ++- .../src/flex/defaults/coolTokens.generated.ts | 95 ++++ .../flex/defaults/defaultTokens.generated.ts | 423 ------------------ .../design/src/flex/defaults/defaultTokens.ts | 14 +- .../flex/defaults/sharedTokens.generated.ts | 303 +++++++++++++ .../src/flex/defaults/warmTokens.generated.ts | 82 ++++ .../design/src/flex/flexThemeReference.ts | 2 +- .../design/src/flex/themeState.test.ts | 32 ++ .../agentic/design/src/flex/themeState.ts | 28 +- .../design/src/flex/themeState.types.ts | 5 +- .../design/src/flex/useThemeState.test.ts | 20 + .../agentic/design/src/flex/useThemeState.ts | 8 +- .../__snapshots__/entryPoints.test.ts.snap | 1 + .../compatibility/importBoundaries.test.ts | 20 +- .../design/src/themes/flex/flexCoolTheme.ts | 9 + .../design/src/themes/flex/flexTheme.ts | 9 +- .../src/themes/flex/flexThemes.test.tsx | 37 +- .../design/src/themes/flex/flexWarmTheme.ts | 8 +- packages/agentic/design/src/themes/index.ts | 1 + .../design/src/theming/ThemedRoot.test.tsx | 14 + .../agentic/design/src/theming/ThemedRoot.tsx | 3 +- 29 files changed, 793 insertions(+), 530 deletions(-) create mode 100644 .changeset/design-flex-palette-loading.md create mode 100644 .changeset/design-system-default-state.md create mode 100644 packages/agentic/design/src/flex/defaults/coolTokens.generated.ts delete mode 100644 packages/agentic/design/src/flex/defaults/defaultTokens.generated.ts create mode 100644 packages/agentic/design/src/flex/defaults/sharedTokens.generated.ts create mode 100644 packages/agentic/design/src/flex/defaults/warmTokens.generated.ts create mode 100644 packages/agentic/design/src/flex/themeState.test.ts create mode 100644 packages/agentic/design/src/themes/flex/flexCoolTheme.ts diff --git a/.changeset/design-flex-palette-loading.md b/.changeset/design-flex-palette-loading.md new file mode 100644 index 0000000000..68a48fb448 --- /dev/null +++ b/.changeset/design-flex-palette-loading.md @@ -0,0 +1,5 @@ +--- +'@fluentui-react-native/design': patch +--- + +Add independently bundleable flexCoolTheme and flexWarmTheme descriptions, let flexTheme select its palette from appearance.colorTone, and use flexCoolTheme for no-theme fallbacks. diff --git a/.changeset/design-system-default-state.md b/.changeset/design-system-default-state.md new file mode 100644 index 0000000000..6691290809 --- /dev/null +++ b/.changeset/design-system-default-state.md @@ -0,0 +1,5 @@ +--- +'@fluentui-react-native/design': patch +--- + +Lazily initialize the fallback Flex theme state once using the current system light or dark appearance, and keep the fallback appearance hooks consistent. diff --git a/apps/bundle-size/scenarios.json b/apps/bundle-size/scenarios.json index 2ad4fd7240..0fe097f2a4 100644 --- a/apps/bundle-size/scenarios.json +++ b/apps/bundle-size/scenarios.json @@ -11,18 +11,6 @@ "module": "@fluentui-react-native/components", "namespace": true }, - { - "name": "design-theme-state", - "module": "@fluentui-react-native/design", - "exports": ["FlexThemeReference", "ThemeProvider", "useThemeState"], - "forbiddenInputPatterns": ["/design/src/fluent/", "/design/src/deprecated/", "/design/src/test/", "/color-lib/compositing."], - "requiredInputPatterns": [ - "/design/src/flex/flexThemeReference.", - "/design/src/flex/useThemeState.", - "/design/src/theming/ThemeProvider." - ], - "requiredOutputPatterns": ["/color-lib/interaction.", "/design/src/flex/colors/interactionPolicy."] - }, { "name": "design-themed-root", "module": "@fluentui-react-native/design", @@ -153,9 +141,34 @@ "/design/src/test/", "/color-lib/compositing." ], - "requiredInputPatterns": ["/design/src/flex/defaults/defaultTokens.generated."], - "forbiddenOutputPatterns": ["/design/src/fluent/", "/design/src/themes/fluent/", "/design/src/themes/flex/flexWarmTheme."], - "requiredOutputPatterns": ["/design/src/themes/flex/flexTheme.", "/design/src/flex/defaults/defaultTokens.generated."] + "requiredInputPatterns": ["/design/src/flex/defaults/sharedTokens.generated."], + "forbiddenOutputPatterns": ["/design/src/fluent/", "/design/src/themes/fluent/"], + "requiredOutputPatterns": [ + "/design/src/themes/flex/flexTheme.", + "/design/src/flex/defaults/coolTokens.generated.", + "/design/src/flex/defaults/warmTokens.generated." + ] + }, + { + "name": "design-flex-cool-theme", + "module": "@fluentui-react-native/design/themes", + "exports": ["flexCoolTheme"], + "forbiddenInputPatterns": [ + "/design/src/fluent/compat/", + "/design/src/deprecated/", + "/design/src/fluent/useTheme.", + "/design/src/test/", + "/color-lib/compositing." + ], + "requiredInputPatterns": ["/design/src/flex/defaults/sharedTokens.generated."], + "forbiddenOutputPatterns": [ + "/design/src/fluent/", + "/design/src/themes/fluent/", + "/design/src/themes/flex/flexTheme.", + "/design/src/themes/flex/flexWarmTheme.", + "/design/src/flex/defaults/warmTokens.generated." + ], + "requiredOutputPatterns": ["/design/src/themes/flex/flexCoolTheme.", "/design/src/flex/defaults/coolTokens.generated."] }, { "name": "design-flex-warm-theme", @@ -168,9 +181,15 @@ "/design/src/test/", "/color-lib/compositing." ], - "requiredInputPatterns": ["/design/src/flex/defaults/defaultTokens.generated."], - "forbiddenOutputPatterns": ["/design/src/fluent/", "/design/src/themes/fluent/", "/design/src/themes/flex/flexTheme."], - "requiredOutputPatterns": ["/design/src/themes/flex/flexWarmTheme.", "/design/src/flex/defaults/defaultTokens.generated."] + "requiredInputPatterns": ["/design/src/flex/defaults/sharedTokens.generated."], + "forbiddenOutputPatterns": [ + "/design/src/fluent/", + "/design/src/themes/fluent/", + "/design/src/themes/flex/flexTheme.", + "/design/src/themes/flex/flexCoolTheme.", + "/design/src/flex/defaults/coolTokens.generated." + ], + "requiredOutputPatterns": ["/design/src/themes/flex/flexWarmTheme.", "/design/src/flex/defaults/warmTokens.generated."] } ] } diff --git a/packages/agentic/design/README.md b/packages/agentic/design/README.md index 904c360512..e1076490fe 100644 --- a/packages/agentic/design/README.md +++ b/packages/agentic/design/README.md @@ -46,9 +46,9 @@ export const App = () => ( Use `fluentLightTheme` or `fluentDarkTheme` when you need one fixed `Theme` object, or `fluentHcTheme` to always use high contrast. -The same entry point ships the x3 Flex defaults as `flexTheme` (cool) and `flexWarmTheme` (warm). Each is a -`FlexThemeDescription` covering light and dark; use one as a `FlexThemeReference` base to start from that palette and -tone: +The same entry point ships the x3 Flex defaults as `flexCoolTheme` and `flexWarmTheme`, independently bundleable +descriptions covering light and dark. `flexTheme` includes both and switches palettes with `appearance.colorTone`. +Use one as a `FlexThemeReference` base: ```tsx import { FlexThemeReference } from '@fluentui-react-native/design'; @@ -57,6 +57,8 @@ import { flexWarmTheme } from '@fluentui-react-native/design/themes'; const theme = new FlexThemeReference({ base: flexWarmTheme, appearance: { colorScheme: 'system' } }); ``` +Without an explicit theme or inherited boundary, `ThemedRoot` and the theme hooks use `flexCoolTheme`. + ## Documentation | Topic | Covers | diff --git a/packages/agentic/design/references/contributing.md b/packages/agentic/design/references/contributing.md index 09d0fb9dc4..e73af29573 100644 --- a/packages/agentic/design/references/contributing.md +++ b/packages/agentic/design/references/contributing.md @@ -51,8 +51,9 @@ committed; change their inputs and regenerate rather than editing them. - Keep `src/themes/` a consumer of generated tokens. `src/themes/fluent/` may reach `ThemeReference`, the generated Fluent tokens, and the generated global tokens, but never `src/flex/`, `src/color-lib/`, `useTheme`, `src/fluent/compat/`, or `src/deprecated/`, and it authors no color value that the generated alias colors lack. - `src/themes/flex/` exposes the x3 default descriptions unchanged and never reaches `src/fluent/` or - `color-lib/compositing`. The tests under `src/themes/`, the import-boundary test, and the `design-fluent-*` and + `src/themes/flex/` exposes the fixed x3 default descriptions unchanged and an adaptive description that selects one + by resolved color tone. Each fixed theme must not reach the other palette's generated module. These themes never reach + `src/fluent/` or `color-lib/compositing`. The tests under `src/themes/`, the import-boundary test, and the `design-fluent-*` and `design-flex-*` bundle-size scenarios guard this. - Never mutate author-owned theme inputs; caches are external and keyed by source, revision, and resolved appearance. - Keep color resolution lazy: resolving tokens, reading rest, merging, and copying the color map must not run the diff --git a/packages/agentic/design/references/entry-points.md b/packages/agentic/design/references/entry-points.md index df9c54bc7f..610e3b3e85 100644 --- a/packages/agentic/design/references/entry-points.md +++ b/packages/agentic/design/references/entry-points.md @@ -10,20 +10,20 @@ owner_paths: The package is `sideEffects: false` and exposes explicit subpaths so consumers load only the graph they use. Export public symbols by name from each entry point; do not add barrel re-exports. -| Subpath | Contents | -| ------------------------- | -------------------------------------------------------------------------------------------------------------------------- | -| `.` (root) | Modern theming (`ThemeProvider`, `ThemedRoot`, `FlexThemeReference`, hooks), Flex token types | -| `./theming` | The complete modern and legacy theming API, including `ThemeReference` and `useTheme` | -| `./theming/legacy-source` | `ThemeReference` without the legacy consumption graph | -| `./theming/compat` | `themeFromFlexTokens`, which projects Flex tokens onto the Fluent theme for the appearance | -| `./themes` | Ready-made themes: `fluentLightTheme`, `fluentDarkTheme`, `fluentHcTheme`, `fluentTheme`, `flexTheme`, and `flexWarmTheme` | -| `./tokens/global` | Generated platform global token constants | -| `./color-lib` | Raw color parsing, conversion, compositing, and interaction algorithms; see `color-lib.md` | -| `./styling` | State and color style factories; see `styling.md` | -| `./styling/stylesheet` | The legacy `themedStyleSheet` helper | -| `./styling/tokens` | Legacy token-to-style builders | -| `./testing` | Test-only fixtures and validation; see `testing.md` | -| `./deprecated` | Fluent 2 token JSON loaders and pipeline mappers, restricted to existing consumers; see [below](#deprecated-entry-point) | +| Subpath | Contents | +| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | +| `.` (root) | Modern theming (`ThemeProvider`, `ThemedRoot`, `FlexThemeReference`, hooks), Flex token types | +| `./theming` | The complete modern and legacy theming API, including `ThemeReference` and `useTheme` | +| `./theming/legacy-source` | `ThemeReference` without the legacy consumption graph | +| `./theming/compat` | `themeFromFlexTokens`, which projects Flex tokens onto the Fluent theme for the appearance | +| `./themes` | Ready-made themes: `fluentLightTheme`, `fluentDarkTheme`, `fluentHcTheme`, `fluentTheme`, `flexTheme`, `flexCoolTheme`, and `flexWarmTheme` | +| `./tokens/global` | Generated platform global token constants | +| `./color-lib` | Raw color parsing, conversion, compositing, and interaction algorithms; see `color-lib.md` | +| `./styling` | State and color style factories; see `styling.md` | +| `./styling/stylesheet` | The legacy `themedStyleSheet` helper | +| `./styling/tokens` | Legacy token-to-style builders | +| `./testing` | Test-only fixtures and validation; see `testing.md` | +| `./deprecated` | Fluent 2 token JSON loaders and pipeline mappers, restricted to existing consumers; see [below](#deprecated-entry-point) | The `apps/bundle-size` `design-*` scenarios guard these boundaries. Input patterns check the import graph and output patterns check the modules a tree-shaken bundle retains. Every design scenario except the color-library one forbids @@ -34,7 +34,8 @@ legacy-source scenario also forbids a retained `FlexThemeReference`. Only the le `color-lib/` or `flex/` module. The Fluent theme scenarios forbid `useTheme` and the compatibility modules from the import graph and any retained `flex/`, `color-lib/`, or Flex theme module, and a bundle that imports only `fluentLightTheme` retains no other theme and no `ThemeReference`, while one that imports only `fluentHcTheme` retains -only the high-contrast themes. The Flex theme scenarios require the x3 defaults and forbid `fluent/` and +only the high-contrast themes. The fixed Flex theme scenarios reject the other palette's generated data in retained +output; the dynamic `flexTheme` scenario requires both palettes. The Flex theme scenarios require the x3 defaults and forbid `fluent/` and `color-lib/compositing`. The color-library scenario requires its algorithms, and the legacy-projection scenario requires the projection, the Fluent theme selection, and the generated Fluent tokens it projects onto. Every scenario also requires a module it is expected to load, so a moved file cannot make a forbidden pattern pass vacuously. diff --git a/packages/agentic/design/references/theming.md b/packages/agentic/design/references/theming.md index f38db516f8..2e0b499cfa 100644 --- a/packages/agentic/design/references/theming.md +++ b/packages/agentic/design/references/theming.md @@ -31,8 +31,9 @@ may be a function of the resolved appearance, which always has a concrete `color authored description and the resolved appearance. `PartialFlexTokens` is shape-aware so opaque React Native colors stay leaves. `tokens.md` describes the defaults. -A base may instead be a `FlexThemeDescription`: a complete `FlexTokenDescription` in `tokens` and an optional -`colorTone`. Its tokens replace the package defaults for every appearance, and its tone becomes the reference's default +A base may instead be a `FlexThemeDescription`: a complete `FlexTokenDescription` in `tokens`, or a function of the +resolved appearance returning one, and an optional `colorTone`. Its tokens replace the package defaults for every +appearance, and its tone becomes the reference's default `appearance.colorTone` when the `appearance` option sets none. A provider's `appearance` request still wins, and it changes only the interaction algorithm, not the description's palette. The Flex themes below are descriptions. @@ -73,7 +74,7 @@ resolves from the provider prop, then the source option, then the selected appea `ThemedRoot` is a `View` wrapped in a `ThemeProvider`. With no `theme`, it inherits the nearest boundary's source, requested appearance, appearance source, and fallback, overriding only the fields it sets; with no boundary it uses a -default `FlexThemeReference`. An explicit `theme` starts a new configuration. The outermost root also provides +`FlexThemeReference` based on `flexCoolTheme`. An explicit `theme` starts a new configuration. The outermost root also provides `RootContext` and input-modality tracking; `RootInputBoundary` attaches popup or window content to the same scene. User-facing examples are in the repository's [theming basics](https://github.com/microsoft/fluentui-react-native/blob/main/docs/pages/Theming/Basics.md). @@ -92,6 +93,11 @@ legacy boundary for all of them, which keeps deprecated `ThemeLayer` and direct `ThemeState.highContrast` is deprecated; use `appearance.contrast`. +Without a boundary, the first call to either Flex hook initializes one shared default state from `flexCoolTheme`, using +React Native `Appearance.getColorScheme()` (or light when unavailable). Its tokens, resolved appearance, and style +registry are reused for subsequent calls; it does not subscribe to system changes. Use a provider or `ThemedRoot` for +live appearance updates. + | Active source | Provider mount | `useThemeState` | `useTheme` | | ------------- | ---------------------------------- | --------------------------------- | -------------------------------------- | | Legacy | Resolves the authored `Theme` only | Projects `Theme` to Flex once | Returns the authored `Theme` | @@ -167,13 +173,16 @@ The `themes` entry point also provides the x3 Flex defaults (`tokens.md`) as `Fl | Export | Kind | Contents | | --------------- | ---------------------- | -------------------------------------------------- | -| `flexTheme` | `FlexThemeDescription` | The cool light and dark defaults, with tone `cool` | +| `flexCoolTheme` | `FlexThemeDescription` | The cool light and dark defaults, with tone `cool` | | `flexWarmTheme` | `FlexThemeDescription` | The warm light and dark defaults, with tone `warm` | +| `flexTheme` | `FlexThemeDescription` | Both palettes, selected by resolved `colorTone` | Each is a theme description rather than a source: pass it as a `FlexThemeReference` base, alone or under recipes. A -reference built on `flexTheme` or `flexWarmTheme` resolves the same tokens as a default `FlexThemeReference` requesting -that tone. Both descriptions are the shared default objects, so treat them as read-only; author changes as recipes or a -new description. +reference built on a fixed theme keeps its palette even if a provider requests another interaction tone. Each fixed +theme loads only its own palette and the tokens both palettes share. `flexTheme.tokens` is a resolver that selects the +cool or warm description for the resolved `appearance.colorTone`; changing that provider request changes both the +palette and interaction tone, with normal per-appearance caching. With no tone request it selects cool. Treat these +shared descriptions as read-only; author changes as recipes or a new description. ```ts import { FlexThemeReference } from '@fluentui-react-native/design'; @@ -182,6 +191,9 @@ import { flexWarmTheme } from '@fluentui-react-native/design/themes'; const theme = new FlexThemeReference({ base: flexWarmTheme, appearance: { colorScheme: 'system' } }); ``` +For dynamic palette switching, use `flexTheme` as the base and set +`` (or `'cool'`). + ## Legacy projection and bundle boundary The package root exports only the modern authoring and consumption APIs. It reaches the forward Theme-to-Flex adapter, diff --git a/packages/agentic/design/references/tokens.md b/packages/agentic/design/references/tokens.md index 3401cc4be9..ca8752758b 100644 --- a/packages/agentic/design/references/tokens.md +++ b/packages/agentic/design/references/tokens.md @@ -70,9 +70,12 @@ objects that the declarations spread. The emitted key order is therefore not mea ## Default tokens -`src/flex/defaults/defaultTokens.generated.ts` holds the cool and warm x3 defaults, and `defaultTokens.ts` normalizes -them. `FlexThemeReference` merges the default for the resolved `colorTone` under its base and recipes, and the `themes` -entry point exposes the two defaults as `flexTheme` and `flexWarmTheme` (`theming.md`). The x3 sources +`src/flex/defaults/sharedTokens.generated.ts` holds only entries identical in both palettes. +`coolTokens.generated.ts` and `warmTokens.generated.ts` add each palette's entries without importing the other. +`defaultTokens.ts` exposes the normalized defaults for existing internal consumers and test fixtures. +`FlexThemeReference` merges the default for the resolved `colorTone` under its base and recipes, unless a complete +description replaces it. The `themes` entry point exposes isolated `flexCoolTheme` and `flexWarmTheme` descriptions +and an adaptive `flexTheme` description (`theming.md`). The x3 sources define no high-contrast or elevated values, so those appearances use the light or dark default. Defaults do not otherwise vary by contrast or interface level; see `remaining-work.md`. Tests that assert default values should read them from `defaultFlexTokens` in the `testing` entry point rather than repeating literals. @@ -85,7 +88,7 @@ values, whether each interaction state is computed or explicit, and any native a 16 density-independent pixels, durations to milliseconds, `cubic-bezier()` to tuples, variable font weights to native static weights, and relative `oklch` shadow alphas to `#rrggbbaa`. Opaque colors are emitted as `#rrggbb`. -Regenerate both files from the pinned snapshots, or verify that they are current: +Regenerate the token files and coverage ledger from the pinned snapshots, or verify that they are current: ```sh yarn workspace @fluentui-react-native/design gen:flex-defaults diff --git a/packages/agentic/design/scripts/flex-defaults/generate-defaults.mjs b/packages/agentic/design/scripts/flex-defaults/generate-defaults.mjs index cfd19fafe7..202f1bb77a 100644 --- a/packages/agentic/design/scripts/flex-defaults/generate-defaults.mjs +++ b/packages/agentic/design/scripts/flex-defaults/generate-defaults.mjs @@ -14,7 +14,9 @@ import { fileURLToPath, pathToFileURL } from 'node:url'; const scriptDir = path.dirname(fileURLToPath(import.meta.url)); const packageRoot = path.resolve(scriptDir, '../..'); const outputPaths = { - defaults: path.join(packageRoot, 'src/flex/defaults/defaultTokens.generated.ts'), + shared: path.join(packageRoot, 'src/flex/defaults/sharedTokens.generated.ts'), + cool: path.join(packageRoot, 'src/flex/defaults/coolTokens.generated.ts'), + warm: path.join(packageRoot, 'src/flex/defaults/warmTokens.generated.ts'), ledger: path.join(scriptDir, 'coverage.generated.json'), }; const pinPath = path.join(packageRoot, 'src/tokens/mappings/upstream-pin.json'); @@ -566,17 +568,11 @@ function nameValue(value) { return undefined; } -/** - * Emit the tone defaults through a value pool, which shares the entries the tones hold in common through ancestor - * objects and hoists repeated values into constants, keeping the minified module small. - */ -function emitDefaults(pin, files, toneTokens) { +/** Emit one independently loadable part of the defaults, hoisting repeated values within it. */ +function emitDefaults(pin, files, filePath, name, tokens, footer = '') { const identifiers = new Set(); - collectIdentifiers( - toneTokens.map(({ tokens }) => tokens), - identifiers, - ); - const file = new GeneratedFile(outputPaths.defaults); + collectIdentifiers(tokens, identifiers); + const file = new GeneratedFile(filePath); file.header = makeComment( [ `Generated by ${generatorPath}. Do not edit; run \`yarn gen:flex-defaults\`.`, @@ -587,18 +583,14 @@ function emitDefaults(pin, files, toneTokens) { ], 'line', ); - const pool = new ValuePool({ name: nameValue }).reserve('CompleteFlexTokenInput'); - for (const { tone, tokens } of toneTokens) { - pool.declare(tone.exportName, tokens, { - type: 'CompleteFlexTokenInput', - comment: `The x3 ${tone.name}-tone defaults. Omitted interaction states are computed from rest.`, - }); - } + const pool = new ValuePool({ name: nameValue }).reserve('CompleteFlexTokenInput', 'PartialFlexTokens', 'sharedFlexTokenInput'); + pool.declare(name, tokens, { satisfies: 'PartialFlexTokens' }); const imports = [ - ...formatImport([...identifiers].sort(), '../../tokens/global.generated'), - "import type { CompleteFlexTokenInput } from '../tokens.types';", + ...(identifiers.size > 0 ? formatImport([...identifiers].sort(), '../../tokens/global.generated') : []), + `import type { ${footer ? 'CompleteFlexTokenInput, ' : ''}PartialFlexTokens } from '../tokens.types';`, + ...(footer ? ["import { sharedFlexTokenInput } from './sharedTokens.generated';"] : []), ]; - file.add(`\n${imports.join('\n')}\n\n`, pool); + file.add(`\n${imports.join('\n')}\n\n`, pool, footer); return file.render(); } @@ -663,10 +655,35 @@ function generate() { return { tone, tokens: resolveTone(tone, inputs, mappingEntries, ledger) }; }); - return new Map([ - [outputPaths.defaults, emitDefaults(pin, files, toneTokens)], + const shared = {}; + for (const [group, entries] of Object.entries(toneTokens[0].tokens)) { + shared[group] = Object.fromEntries( + Object.entries(entries).filter(([token, value]) => toneTokens.every(({ tokens }) => sameValue(value, tokens[group][token]))), + ); + } + const outputs = new Map([ + [outputPaths.shared, emitDefaults(pin, files, outputPaths.shared, 'sharedFlexTokenInput', shared)], [outputPaths.ledger, emitLedger(pin, files, ledger)], ]); + for (const { tone, tokens } of toneTokens) { + const overrides = Object.fromEntries( + Object.entries(tokens) + .map(([group, entries]) => [ + group, + Object.fromEntries(Object.entries(entries).filter(([token]) => !Object.hasOwn(shared[group], token))), + ]) + .filter(([, entries]) => Object.keys(entries).length > 0), + ); + const name = `${tone.name}FlexTokenOverrides`; + const groups = Object.keys(tokens).map((group) => { + const base = `sharedFlexTokenInput.${group}`; + const value = Object.hasOwn(overrides, group) ? `{ ...${base}, ...${name}.${group} }` : base; + return ` ${group}: ${value},`; + }); + const footer = `\n/** The x3 ${tone.name}-tone defaults. Omitted interaction states are computed from rest. */\nexport const ${tone.exportName}: CompleteFlexTokenInput = {\n${groups.join('\n')}\n};\n`; + outputs.set(outputPaths[tone.name], emitDefaults(pin, files, outputPaths[tone.name], name, overrides, footer)); + } + return outputs; } const check = process.argv.includes('--check'); diff --git a/packages/agentic/design/src/flex/defaults/coolTokens.generated.ts b/packages/agentic/design/src/flex/defaults/coolTokens.generated.ts new file mode 100644 index 0000000000..ce314b2fd2 --- /dev/null +++ b/packages/agentic/design/src/flex/defaults/coolTokens.generated.ts @@ -0,0 +1,95 @@ +// Generated by scripts/flex-defaults/generate-defaults.mjs. Do not edit; run `yarn gen:flex-defaults`. +// Source: x3-design/fluent-design@206e890b645fb450ad7c5df2ff981765349a2b58 +// cool: dev/web/flex-themes/css/semantic.css, dev/web/flex-themes/css/interaction-fallback.css +// warm: dev/web/flex-themes/css/warm/semantic.css, dev/web/flex-themes/css/warm/interaction-fallback.css +// Generic sources: src/tokens/mappings/flex-token-map.yaml +// Coverage: scripts/flex-defaults/coverage.generated.json + +import type { CompleteFlexTokenInput, PartialFlexTokens } from '../tokens.types'; +import { sharedFlexTokenInput } from './sharedTokens.generated'; + +const inverted = 'inverted'; +const rgb000000db = '#000000db'; +const rgb242424 = '#242424'; +const rgb3c3c3c80 = '#3c3c3c80'; +const rgbffffff = '#ffffff'; +const rgbffffff14 = '#ffffff14'; +const rgbffffff80 = '#ffffff80'; + +const backgroundNeutralSoft = ['#00000014', '#ffffff1f'] as const; +const backgroundNeutralSubtle = ['#0000000d', rgbffffff14] as const; +const backgroundNeutralTransparent = ['#24242400', '#ffffff00'] as const; +const rest1 = ['#6f6f6f', '#929292'] as const; +const rest2 = [rgb242424, '#dedede'] as const; + +const backgroundNeutralHeavy = { rest: [rgb242424, rgbffffff], type: inverted } as const; +const backgroundNeutralLoud = { rest: rest1, type: inverted } as const; +const strokeNeutralOnloud = { rest: [rgbffffff, rgb000000db], type: inverted } as const; + +const strokeNeutralSoft = { + rest: ['#0000006d', '#ffffff61'], + hover: ['#02020277', '#ffffff69'], + pressed: ['#04040481', '#ffffff70'], +} as const; + +const strokeNeutralSubtle = { rest: ['#00000021', '#ffffff48'], pressed: ['#05050535', '#ffffff57'] } as const; + +export const coolFlexTokenOverrides = { + color: { + surfaceNeutralFarther: ['#ebebeb', '#1b1b1b'], + surfaceNeutralFar: ['#f2f2f2', '#1f1f1f'], + surfaceNeutralNear: ['#fcfcfc', '#181818'], + surfaceNeutralNearer: [rgbffffff, '#292929'], + surfaceNeutralTranslucent: [rgbffffff80, rgb3c3c3c80], + backgroundNeutralHeavy, + backgroundNeutralLoud, + backgroundNeutralSoft, + backgroundNeutralSubtle, + backgroundNeutralTransparent, + backgroundNeutralTranslucent: { + rest: ['#e9e9e980', rgb3c3c3c80], + hover: ['#d8d8d88a', '#56565688'], + pressed: ['#cacaca94', '#6d6d6d8f'], + }, + backgroundBrandHeavy: backgroundNeutralHeavy, + backgroundBrandLoud: backgroundNeutralLoud, + backgroundBrandSoft: backgroundNeutralSoft, + backgroundBrandSubtle: ['#0000000a', rgbffffff14], + backgroundBrandTransparent: backgroundNeutralTransparent, + strokeNeutralHeavy: { rest: rest2, type: inverted }, + strokeNeutralLoud: backgroundNeutralLoud, + strokeNeutralSoft, + strokeNeutralSubtle, + strokeNeutralTransparent: backgroundNeutralTransparent, + strokeNeutralOnloud, + strokeBrandLoud: backgroundNeutralLoud, + strokeBrandSoft: strokeNeutralSoft, + strokeBrandSubtle: strokeNeutralSubtle, + strokeBrandOnloud: { rest: [rgbffffff, rgb242424], type: inverted }, + foregroundNeutralPrimary: [rgb000000db, '#ffffffde'], + foregroundNeutralSecondary: ['#000000a2', '#ffffffa1'], + foregroundNeutralTertiary: ['#00000090', rgbffffff80], + foregroundNeutralOnloud: strokeNeutralOnloud, + foregroundBrandPrimary: rest2, + foregroundBrandOnloud: strokeNeutralOnloud, + expressionAccentHeavy: [rgb242424, rgbffffff], + expressionAccentLoud: rest1, + expressionAccentSoft: backgroundNeutralSoft, + expressionAccentSubtle: backgroundNeutralSubtle, + backgroundNeutralSubtleDisabled: ['#00000008', '#ffffff07'], + }, +} satisfies PartialFlexTokens; + +/** The x3 cool-tone defaults. Omitted interaction states are computed from rest. */ +export const coolFlexTokenInput: CompleteFlexTokenInput = { + color: { ...sharedFlexTokenInput.color, ...coolFlexTokenOverrides.color }, + shadow: sharedFlexTokenInput.shadow, + fontWeight: sharedFlexTokenInput.fontWeight, + fontFamily: sharedFlexTokenInput.fontFamily, + fontSize: sharedFlexTokenInput.fontSize, + lineHeight: sharedFlexTokenInput.lineHeight, + borderRadius: sharedFlexTokenInput.borderRadius, + spacing: sharedFlexTokenInput.spacing, + strokeWidth: sharedFlexTokenInput.strokeWidth, + motion: sharedFlexTokenInput.motion, +}; diff --git a/packages/agentic/design/src/flex/defaults/defaultTokens.generated.ts b/packages/agentic/design/src/flex/defaults/defaultTokens.generated.ts deleted file mode 100644 index c99af74464..0000000000 --- a/packages/agentic/design/src/flex/defaults/defaultTokens.generated.ts +++ /dev/null @@ -1,423 +0,0 @@ -// Generated by scripts/flex-defaults/generate-defaults.mjs. Do not edit; run `yarn gen:flex-defaults`. -// Source: x3-design/fluent-design@206e890b645fb450ad7c5df2ff981765349a2b58 -// cool: dev/web/flex-themes/css/semantic.css, dev/web/flex-themes/css/interaction-fallback.css -// warm: dev/web/flex-themes/css/warm/semantic.css, dev/web/flex-themes/css/warm/interaction-fallback.css -// Generic sources: src/tokens/mappings/flex-token-map.yaml -// Coverage: scripts/flex-defaults/coverage.generated.json - -import { - fontFamilyBase, - fontFamilyMonospace, - fontWeightBold, - fontWeightMedium, - fontWeightRegular, - fontWeightSemibold, -} from '../../tokens/global.generated'; -import type { CompleteFlexTokenInput } from '../tokens.types'; - -const inverted = 'inverted'; -const rgb000000 = '#000000'; -const rgb00000008 = '#00000008'; -const rgb0000000d = '#0000000d'; -const rgb0000000f = '#0000000f'; -const rgb00000014 = '#00000014'; -const rgb0000001a = '#0000001a'; -const rgb0000001f = '#0000001f'; -const rgb00000029 = '#00000029'; -const rgb000000db = '#000000db'; -const rgb0b0600e1 = '#0b0600e1'; -const rgb0b497f = '#0b497f'; -const rgb0c5722 = '#0c5722'; -const rgb242424 = '#242424'; -const rgb28231e = '#28231e'; -const rgb294482 = '#294482'; -const rgb2f95f4 = '#2f95f4'; -const rgb32ad52 = '#32ad52'; -const rgb345200 = '#345200'; -const rgb3c3c3c80 = '#3c3c3c80'; -const rgb484848 = '#484848'; -const rgb523778 = '#523778'; -const rgb524800 = '#524800'; -const rgb5c8df8 = '#5c8df8'; -const rgb5dce97 = '#5dce97'; -const rgb6da603 = '#6da603'; -const rgb6f2b53 = '#6f2b53'; -const rgb762f0e = '#762f0e'; -const rgb772b28 = '#772b28'; -const rgb929292 = '#929292'; -const rgba575e8 = '#a575e8'; -const rgbbaedc1 = '#baedc1'; -const rgbc6e1ff = '#c6e1ff'; -const rgbcbff93 = '#cbff93'; -const rgbcd4808 = '#cd4808'; -const rgbcedeff = '#cedeff'; -const rgbd961a6 = '#d961a6'; -const rgbdedede = '#dedede'; -const rgbe4d6ff = '#e4d6ff'; -const rgbe55e7a = '#e55e7a'; -const rgbe56738 = '#e56738'; -const rgbe6ffcf = '#e6ffcf'; -const rgbe7615b = '#e7615b'; -const rgbe7fce9 = '#e7fce9'; -const rgbeef6ff = '#eef6ff'; -const rgbf0f5ff = '#f0f5ff'; -const rgbf5f5f5 = '#f5f5f5'; -const rgbf7f3ff = '#f7f3ff'; -const rgbfb966e = '#fb966e'; -const rgbfbdf06 = '#fbdf06'; -const rgbfc9571 = '#fc9571'; -const rgbfef2ee = '#fef2ee'; -const rgbffcee6 = '#ffcee6'; -const rgbffd2cd = '#ffd2cd'; -const rgbffd3c2 = '#ffd3c2'; -const rgbffed85 = '#ffed85'; -const rgbfff1f7 = '#fff1f7'; -const rgbfff2f0 = '#fff2f0'; -const rgbfff7c4 = '#fff7c4'; -const rgbffffff = '#ffffff'; -const rgbffffff00 = '#ffffff00'; -const rgbffffff14 = '#ffffff14'; -const rgbffffff80 = '#ffffff80'; - -const backgroundNeutralDisabled = [rgb00000008, '#ffffff07'] as const; -const backgroundNeutralSoft1 = [rgb00000014, '#ffffff1f'] as const; -const backgroundNeutralSoft2 = ['#4d200028', '#ffe3cb40'] as const; -const backgroundNeutralSubtle = ['#6c31001a', '#fff4ef14'] as const; -const backgroundNeutralTransparent1 = ['#24242400', rgbffffff00] as const; -const backgroundNeutralTransparent2 = ['#28231e00', rgbffffff00] as const; -const easingFunctionalEnter = [0, 0, 0, 1] as const; -const easingFunctionalExit = [0.6, 0, 0.75, 0.4] as const; -const easingFunctionalTransition = [0.33, 0, 0, 1] as const; -const foregroundNeutralPrimary = [rgb0b0600e1, '#fff7f2e3'] as const; -const rest1 = ['#6f6f6f', rgb929292] as const; -const rest2 = ['#e9e9e980', rgb3c3c3c80] as const; -const rest3 = ['#0000006d', '#ffffff61'] as const; -const rest4 = ['#1e0d009a', '#ffeee39a'] as const; -const shadowLayer1 = { x: 0, y: 0, blur: 2, color: rgb0000001a } as const; -const shadowLayer2 = { x: 0, y: 0, blur: 2, color: '#00000033' } as const; -const shadowLayer3 = { x: 0, y: 8, blur: 16, color: rgb0000001f } as const; -const shadowLayer4 = { x: 0, y: 8, blur: 16, color: rgb00000008 } as const; -const strokeNeutralSoft2 = ['#250f0076', '#ffe6d35c'] as const; - -const backgroundDangerLoud = { rest: ['#c02e56', rgbe55e7a], type: inverted } as const; -const backgroundNeutralHeavy1 = { rest: [rgb242424, rgbffffff], type: inverted } as const; -const backgroundNeutralHeavy2 = { rest: [rgb28231e, rgbffffff], type: inverted } as const; -const backgroundNeutralLoud1 = { rest: rest1, type: inverted } as const; -const backgroundNeutralLoud2 = { rest: rest4, type: inverted } as const; -const backgroundSuccessLoud = { rest: ['#008455', '#05ad72'], type: inverted } as const; -const strokeBrandOnloud = { rest: [rgbffffff, rgb242424], type: inverted } as const; -const strokeNeutralLoud = { rest: ['#776d65', '#9a9089'], type: inverted } as const; -const strokeNeutralOnloud1 = { rest: [rgbffffff, rgb000000db], type: inverted } as const; -const strokeNeutralOnloud2 = { rest: [rgbffffff, rgb0b0600e1], type: inverted } as const; -const strokeNeutralSoft1 = { rest: rest3, hover: ['#02020277', '#ffffff69'], pressed: ['#04040481', '#ffffff70'] } as const; -const strokeNeutralSubtle = { rest: ['#00000021', '#ffffff48'], pressed: ['#05050535', '#ffffff57'] } as const; - -const sharedFlexTokenInputColor = { - backgroundDangerLoud, - backgroundDangerSoft: ['#ffe3e6', '#5a2932'], - backgroundDangerSubtle: ['#fff1f3', '#402529'], - backgroundWarningLoud: { rest: ['#bb4001', rgbe56738], type: inverted }, - backgroundWarningSoft: ['#ffe5dc', '#592c1c'], - backgroundWarningSubtle: ['#fff2ee', '#40261d'], - backgroundSuccessLoud, - backgroundSuccessSoft: ['#c9f8dd', '#0c462d'], - backgroundSuccessSubtle: ['#e3fcee', '#193426'], - strokeDangerLoud: backgroundDangerLoud, - strokeDangerSoft: [rgbe55e7a, '#d14164'], - strokeDangerSubtle: ['#ffd0d6', '#76293a'], - strokeDangerOnloud: strokeBrandOnloud, - strokeWarningLoud: { rest: [rgbcd4808, rgbe56738], type: inverted }, - strokeWarningSoft: [rgbfc9571, rgbcd4808], - strokeWarningSubtle: ['#ffd3c4', '#762e12'], - strokeWarningOnloud: strokeBrandOnloud, - strokeSuccessLoud: backgroundSuccessLoud, - strokeSuccessSoft: [rgb5dce97, '#008e5c'], - strokeSuccessSubtle: ['#b1efcc', '#025636'], - strokeSuccessOnloud: strokeBrandOnloud, - foregroundDangerPrimary: ['#a62147', '#fd8ea1'], - foregroundDangerOnloud: strokeNeutralOnloud1, - foregroundWarningPrimary: ['#a93901', rgbfc9571], - foregroundWarningOnloud: strokeNeutralOnloud1, - foregroundSuccessPrimary: ['#017048', rgb5dce97], - foregroundSuccessOnloud: strokeNeutralOnloud1, - fixedWhite: rgbffffff, - fixedBlack: rgb000000, - expressionAchromaticHeavy: [rgb000000, rgbffffff], - expressionAchromaticSubtle: [rgbffffff, rgb000000], - expressionGrayHeavy: [rgb484848, rgbf5f5f5], - expressionGrayLoud: [rgb929292, rgbdedede], - expressionGraySoft: [rgbdedede, rgb929292], - expressionGraySubtle: [rgbf5f5f5, rgb484848], - expressionNavyHeavy: [rgb294482, rgbf0f5ff], - expressionNavyLoud: [rgb5c8df8, rgbcedeff], - expressionNavySoft: [rgbcedeff, rgb5c8df8], - expressionNavySubtle: [rgbf0f5ff, rgb294482], - expressionBlueHeavy: [rgb0b497f, rgbeef6ff], - expressionBlueLoud: [rgb2f95f4, rgbc6e1ff], - expressionBlueSoft: [rgbc6e1ff, rgb2f95f4], - expressionBlueSubtle: [rgbeef6ff, rgb0b497f], - expressionGreenHeavy: [rgb0c5722, rgbe7fce9], - expressionGreenLoud: [rgb32ad52, rgbbaedc1], - expressionGreenSoft: [rgbbaedc1, rgb32ad52], - expressionGreenSubtle: [rgbe7fce9, rgb0c5722], - expressionLimeHeavy: [rgb345200, rgbe6ffcf], - expressionLimeLoud: [rgb6da603, rgbcbff93], - expressionLimeSoft: [rgbcbff93, rgb6da603], - expressionLimeSubtle: [rgbe6ffcf, rgb345200], - expressionYellowHeavy: [rgb524800, rgbfff7c4], - expressionYellowLoud: [rgbfbdf06, rgbffed85], - expressionYellowSoft: [rgbffed85, rgbfbdf06], - expressionYellowSubtle: [rgbfff7c4, rgb524800], - expressionPumpkinHeavy: [rgb762f0e, rgbfef2ee], - expressionPumpkinLoud: [rgbfb966e, rgbffd3c2], - expressionPumpkinSoft: [rgbffd3c2, rgbfb966e], - expressionPumpkinSubtle: [rgbfef2ee, rgb762f0e], - expressionRedHeavy: [rgb772b28, rgbfff2f0], - expressionRedLoud: [rgbe7615b, rgbffd2cd], - expressionRedSoft: [rgbffd2cd, rgbe7615b], - expressionRedSubtle: [rgbfff2f0, rgb772b28], - expressionPinkHeavy: [rgb6f2b53, rgbfff1f7], - expressionPinkLoud: [rgbd961a6, rgbffcee6], - expressionPinkSoft: [rgbffcee6, rgbd961a6], - expressionPinkSubtle: [rgbfff1f7, rgb6f2b53], - expressionPurpleHeavy: [rgb523778, rgbf7f3ff], - expressionPurpleLoud: [rgba575e8, rgbe4d6ff], - expressionPurpleSoft: [rgbe4d6ff, rgba575e8], - expressionPurpleSubtle: [rgbf7f3ff, rgb523778], - overlayNeutralTranslucent: ['#00000026', '#00000099'], - materialBackgroundThick: ['#fffffff1', '#262626ea'], - materialBackgroundRegular: ['#ffffffd7', '#2f2f2fd1'], - materialBackgroundThin: ['#ffffff7e', '#3434348b'], - backgroundNeutralDisabled, - backgroundNeutralHeavyDisabled: [rgb0000001a, '#ffffff20'], - strokeNeutralDisabled: [rgb00000014, '#ffffff24'], - foregroundNeutralDisabled: rest3, - strokeFocusInner: [rgbffffff, rgb000000], - strokeFocusOuter: [rgb000000, rgbffffff], - shadow: rgb000000, -} as const; - -const sharedFlexTokenInput = { - shadow: { - lowest: [[shadowLayer1, { x: 0, y: 1, blur: 2, color: rgb0000000d }], [shadowLayer2, { x: 0, y: 1, blur: 2, color: rgb0000001a }]], - lower: [[shadowLayer1, { x: 0, y: 2, blur: 4, color: rgb00000014 }], [shadowLayer2, { x: 0, y: 2, blur: 4, color: rgb00000029 }]], - low: [ - [shadowLayer1, { x: 0, y: 2, blur: 4, color: rgb00000008 }, { x: 0, y: 4, blur: 8, color: rgb00000014 }], - [shadowLayer2, { x: 0, y: 2, blur: 4, color: rgb0000001f }, { x: 0, y: 4, blur: 8, color: rgb00000029 }], - ], - high: [ - [shadowLayer1, { x: 0, y: 4, blur: 8, color: rgb00000008 }, { x: 0, y: 8, blur: 16, color: rgb0000000f }], - [shadowLayer2, { x: 0, y: 4, blur: 8, color: rgb0000001f }, shadowLayer3], - ], - higher: [ - [shadowLayer1, shadowLayer4, { x: 0, y: 16, blur: 32, color: rgb0000000f }], - [shadowLayer2, shadowLayer3, { x: 0, y: 16, blur: 32, color: rgb0000001f }], - ], - highest: [ - [shadowLayer1, shadowLayer4, { x: 0, y: 32, blur: 64, color: rgb0000000f }], - [shadowLayer2, shadowLayer3, { x: 0, y: 32, blur: 64, color: rgb0000001f }], - ], - }, - fontWeight: { - functionalRegular: fontWeightRegular, - functionalMedium: fontWeightMedium, - functionalSemibold: fontWeightSemibold, - functionalBold: fontWeightBold, - contentRegular: fontWeightRegular, - contentMedium: fontWeightMedium, - contentSemibold: fontWeightSemibold, - contentBold: fontWeightBold, - contentEditorialRegular: fontWeightRegular, - contentEditorialMedium: fontWeightMedium, - contentEditorialSemibold: fontWeightSemibold, - contentEditorialBold: fontWeightBold, - }, - fontFamily: { functional: fontFamilyBase, content: fontFamilyBase, contentEditorial: fontFamilyBase, contentCode: fontFamilyMonospace }, - fontSize: { - functionalDisplay: 68, - functionalPagetitle: 40, - functionalTitleLarge: 32, - functionalTitleMedium: 28, - functionalTitleSmall: 24, - functionalSubtitle: 20, - functionalBodyLarge: 16, - functionalBodyMedium: 14, - functionalBodySmall: 12, - functionalCaption: 10, - contentStatement: 56, - contentExpressiveLarge: 48, - contentExpressiveMedium: 36, - contentExpressiveSmall: 28, - contentH1: 36, - contentH2: 32, - contentH3: 28, - contentH4: 24, - contentH5: 20, - contentSubheadline: 16, - contentParagraphLarge: 20, - contentParagraphMedium: 16, - contentParagraphSmall: 12, - contentSubtext: 10, - contentTable: 16, - contentCode: 16, - }, - lineHeight: { - functionalDisplay: 82, - functionalPagetitle: 48, - functionalTitleLarge: 38, - functionalTitleMedium: 34, - functionalTitleSmall: 28, - functionalSubtitle: 28, - functionalBodyLarge: 22, - functionalBodyMedium: 20, - functionalBodySmall: 16, - functionalCaption: 14, - contentStatement: 68, - contentExpressiveLarge: 58, - contentExpressiveMedium: 44, - contentExpressiveSmall: 34, - contentH1: 44, - contentH2: 38, - contentH3: 34, - contentH4: 28, - contentH5: 24, - contentSubheadline: 22, - contentParagraphLarge: 34, - contentParagraphMedium: 28, - contentParagraphSmall: 20, - contentSubtext: 14, - contentTable: 22, - contentCode: 22, - }, - borderRadius: { base100: 4, base200: 8, base300: 12, base400: 16, base600: 24, base700: 28, circular: 9999 }, - spacing: { - componentBase50: 2, - componentBase100: 4, - componentBase150: 6, - componentBase200: 8, - componentBase250: 10, - componentBase300: 12, - componentBase400: 16, - componentBase500: 20, - componentBase600: 24, - componentBase700: 28, - componentBase800: 32, - layoutBase100: 8, - layoutBase200: 16, - layoutBase300: 24, - layoutBase400: 32, - layoutBase450: 36, - layoutBase500: 40, - layoutBase600: 48, - layoutBase700: 56, - layoutBase800: 64, - layoutBase1000: 80, - layoutBase1200: 96, - }, - strokeWidth: { thin: 1, thick: 2, thicker: 3, thickest: 4 }, - motion: { - durationBase50: 50, - durationBase100: 100, - durationBase200: 200, - durationBase300: 300, - durationBase500: 500, - durationBase1000: 1000, - easingFunctionalEnter, - easingFunctionalExit, - easingFunctionalTransition, - easingFunctionalLinear: [0, 0, 1, 1], - easingExpressiveEnter: easingFunctionalEnter, - easingExpressiveExit: easingFunctionalExit, - easingExpressiveTransition: easingFunctionalTransition, - }, -} as const; - -/** The x3 cool-tone defaults. Omitted interaction states are computed from rest. */ -export const coolFlexTokenInput: CompleteFlexTokenInput = { - ...sharedFlexTokenInput, - color: { - ...sharedFlexTokenInputColor, - surfaceNeutralFarther: ['#ebebeb', '#1b1b1b'], - surfaceNeutralFar: ['#f2f2f2', '#1f1f1f'], - surfaceNeutralNear: ['#fcfcfc', '#181818'], - surfaceNeutralNearer: [rgbffffff, '#292929'], - surfaceNeutralTranslucent: [rgbffffff80, rgb3c3c3c80], - backgroundNeutralHeavy: backgroundNeutralHeavy1, - backgroundNeutralLoud: backgroundNeutralLoud1, - backgroundNeutralSoft: backgroundNeutralSoft1, - backgroundNeutralSubtle: [rgb0000000d, rgbffffff14], - backgroundNeutralTransparent: backgroundNeutralTransparent1, - backgroundNeutralTranslucent: { rest: rest2, hover: ['#d8d8d88a', '#56565688'], pressed: ['#cacaca94', '#6d6d6d8f'] }, - backgroundBrandHeavy: backgroundNeutralHeavy1, - backgroundBrandLoud: backgroundNeutralLoud1, - backgroundBrandSoft: backgroundNeutralSoft1, - backgroundBrandSubtle: ['#0000000a', rgbffffff14], - backgroundBrandTransparent: backgroundNeutralTransparent1, - strokeNeutralHeavy: { rest: [rgb242424, rgbdedede], type: inverted }, - strokeNeutralLoud: backgroundNeutralLoud1, - strokeNeutralSoft: strokeNeutralSoft1, - strokeNeutralSubtle, - strokeNeutralTransparent: backgroundNeutralTransparent1, - strokeNeutralOnloud: strokeNeutralOnloud1, - strokeBrandLoud: backgroundNeutralLoud1, - strokeBrandSoft: strokeNeutralSoft1, - strokeBrandSubtle: strokeNeutralSubtle, - strokeBrandOnloud, - foregroundNeutralPrimary: [rgb000000db, '#ffffffde'], - foregroundNeutralSecondary: ['#000000a2', '#ffffffa1'], - foregroundNeutralTertiary: ['#00000090', rgbffffff80], - foregroundNeutralOnloud: strokeNeutralOnloud1, - foregroundBrandPrimary: [rgb242424, rgbdedede], - foregroundBrandOnloud: strokeNeutralOnloud1, - expressionAccentHeavy: [rgb242424, rgbffffff], - expressionAccentLoud: rest1, - expressionAccentSoft: backgroundNeutralSoft1, - expressionAccentSubtle: [rgb0000000d, rgbffffff14], - backgroundNeutralSubtleDisabled: backgroundNeutralDisabled, - }, -}; - -/** The x3 warm-tone defaults. Omitted interaction states are computed from rest. */ -export const warmFlexTokenInput: CompleteFlexTokenInput = { - ...sharedFlexTokenInput, - color: { - ...sharedFlexTokenInputColor, - surfaceNeutralFarther: ['#f0eae5', '#1e1916'], - surfaceNeutralFar: ['#faf4f0', '#231e1a'], - surfaceNeutralNear: ['#f6f1ec', '#1c1714'], - surfaceNeutralNearer: [rgbffffff, '#2e2823'], - surfaceNeutralTranslucent: [rgbffffff80, '#00000080'], - backgroundNeutralHeavy: backgroundNeutralHeavy2, - backgroundNeutralLoud: backgroundNeutralLoud2, - backgroundNeutralSoft: backgroundNeutralSoft2, - backgroundNeutralSubtle, - backgroundNeutralTransparent: backgroundNeutralTransparent2, - backgroundNeutralTranslucent: rest2, - backgroundBrandHeavy: backgroundNeutralHeavy2, - backgroundBrandLoud: backgroundNeutralLoud2, - backgroundBrandSoft: backgroundNeutralSoft2, - backgroundBrandSubtle: backgroundNeutralSubtle, - backgroundBrandTransparent: backgroundNeutralTransparent2, - strokeNeutralHeavy: { rest: [rgb28231e, '#e3dcd7'], type: inverted }, - strokeNeutralLoud, - strokeNeutralSoft: strokeNeutralSoft2, - strokeNeutralSubtle: backgroundNeutralSoft2, - strokeNeutralTransparent: backgroundNeutralTransparent2, - strokeNeutralOnloud: strokeNeutralOnloud2, - strokeBrandLoud: strokeNeutralLoud, - strokeBrandSoft: strokeNeutralSoft2, - strokeBrandSubtle: backgroundNeutralSoft2, - strokeBrandOnloud: strokeNeutralOnloud2, - foregroundNeutralPrimary, - foregroundNeutralSecondary: ['#190c00ab', '#fff2e8b5'], - foregroundNeutralTertiary: rest4, - foregroundNeutralOnloud: strokeNeutralOnloud2, - foregroundBrandPrimary: foregroundNeutralPrimary, - foregroundBrandOnloud: strokeNeutralOnloud2, - expressionAccentHeavy: [rgb28231e, rgbffffff], - expressionAccentLoud: rest4, - expressionAccentSoft: backgroundNeutralSoft2, - expressionAccentSubtle: backgroundNeutralSubtle, - backgroundNeutralSubtleDisabled: [rgb0000000d, '#ffffff1b'], - }, -}; diff --git a/packages/agentic/design/src/flex/defaults/defaultTokens.ts b/packages/agentic/design/src/flex/defaults/defaultTokens.ts index 7dbc434388..6698ba2286 100644 --- a/packages/agentic/design/src/flex/defaults/defaultTokens.ts +++ b/packages/agentic/design/src/flex/defaults/defaultTokens.ts @@ -1,25 +1,19 @@ import { defaultResolvedThemeAppearance } from '../../theming/appearance'; import type { ColorTone } from '../../types/appearance.types'; import { resolveFlexTokenDescription } from '../colors/interactionPolicy'; -import { createFlexTokenDescription } from '../flexTokenDescription'; +import { flexCoolTheme } from '../../themes/flex/flexCoolTheme'; +import { flexWarmTheme } from '../../themes/flex/flexWarmTheme'; import type { FlexTokenDescription, FlexTokens } from '../tokens.types'; -import { coolFlexTokenInput, warmFlexTokenInput } from './defaultTokens.generated'; /** * The x3 cool-tone default description. Interactive colors author only the * hover and pressed states the interaction policy cannot reproduce. */ -export const defaultFlexTokenDescription: FlexTokenDescription = createFlexTokenDescription(coolFlexTokenInput); - -let warmFlexTokenDescription: FlexTokenDescription | undefined; +export const defaultFlexTokenDescription: FlexTokenDescription = flexCoolTheme.tokens; /** The x3 default description for a color tone. */ export function getDefaultFlexTokenDescription(colorTone: ColorTone): FlexTokenDescription { - if (colorTone === 'warm') { - warmFlexTokenDescription ??= createFlexTokenDescription(warmFlexTokenInput); - return warmFlexTokenDescription; - } - return defaultFlexTokenDescription; + return colorTone === 'warm' ? flexWarmTheme.tokens : flexCoolTheme.tokens; } /** diff --git a/packages/agentic/design/src/flex/defaults/sharedTokens.generated.ts b/packages/agentic/design/src/flex/defaults/sharedTokens.generated.ts new file mode 100644 index 0000000000..fd223c4551 --- /dev/null +++ b/packages/agentic/design/src/flex/defaults/sharedTokens.generated.ts @@ -0,0 +1,303 @@ +// Generated by scripts/flex-defaults/generate-defaults.mjs. Do not edit; run `yarn gen:flex-defaults`. +// Source: x3-design/fluent-design@206e890b645fb450ad7c5df2ff981765349a2b58 +// cool: dev/web/flex-themes/css/semantic.css, dev/web/flex-themes/css/interaction-fallback.css +// warm: dev/web/flex-themes/css/warm/semantic.css, dev/web/flex-themes/css/warm/interaction-fallback.css +// Generic sources: src/tokens/mappings/flex-token-map.yaml +// Coverage: scripts/flex-defaults/coverage.generated.json + +import { + fontFamilyBase, + fontFamilyMonospace, + fontWeightBold, + fontWeightMedium, + fontWeightRegular, + fontWeightSemibold, +} from '../../tokens/global.generated'; +import type { PartialFlexTokens } from '../tokens.types'; + +const inverted = 'inverted'; +const rgb000000 = '#000000'; +const rgb00000008 = '#00000008'; +const rgb0000000f = '#0000000f'; +const rgb00000014 = '#00000014'; +const rgb0000001a = '#0000001a'; +const rgb0000001f = '#0000001f'; +const rgb00000029 = '#00000029'; +const rgb0b497f = '#0b497f'; +const rgb0c5722 = '#0c5722'; +const rgb294482 = '#294482'; +const rgb2f95f4 = '#2f95f4'; +const rgb32ad52 = '#32ad52'; +const rgb345200 = '#345200'; +const rgb484848 = '#484848'; +const rgb523778 = '#523778'; +const rgb524800 = '#524800'; +const rgb5c8df8 = '#5c8df8'; +const rgb5dce97 = '#5dce97'; +const rgb6da603 = '#6da603'; +const rgb6f2b53 = '#6f2b53'; +const rgb762f0e = '#762f0e'; +const rgb772b28 = '#772b28'; +const rgb929292 = '#929292'; +const rgba575e8 = '#a575e8'; +const rgbbaedc1 = '#baedc1'; +const rgbc6e1ff = '#c6e1ff'; +const rgbcbff93 = '#cbff93'; +const rgbcd4808 = '#cd4808'; +const rgbcedeff = '#cedeff'; +const rgbd961a6 = '#d961a6'; +const rgbdedede = '#dedede'; +const rgbe4d6ff = '#e4d6ff'; +const rgbe55e7a = '#e55e7a'; +const rgbe56738 = '#e56738'; +const rgbe6ffcf = '#e6ffcf'; +const rgbe7615b = '#e7615b'; +const rgbe7fce9 = '#e7fce9'; +const rgbeef6ff = '#eef6ff'; +const rgbf0f5ff = '#f0f5ff'; +const rgbf5f5f5 = '#f5f5f5'; +const rgbf7f3ff = '#f7f3ff'; +const rgbfb966e = '#fb966e'; +const rgbfbdf06 = '#fbdf06'; +const rgbfc9571 = '#fc9571'; +const rgbfef2ee = '#fef2ee'; +const rgbffcee6 = '#ffcee6'; +const rgbffd2cd = '#ffd2cd'; +const rgbffd3c2 = '#ffd3c2'; +const rgbffed85 = '#ffed85'; +const rgbfff1f7 = '#fff1f7'; +const rgbfff2f0 = '#fff2f0'; +const rgbfff7c4 = '#fff7c4'; +const rgbffffff = '#ffffff'; + +const easingFunctionalEnter = [0, 0, 0, 1] as const; +const easingFunctionalExit = [0.6, 0, 0.75, 0.4] as const; +const easingFunctionalTransition = [0.33, 0, 0, 1] as const; +const shadowLayer1 = { x: 0, y: 0, blur: 2, color: rgb0000001a } as const; +const shadowLayer2 = { x: 0, y: 0, blur: 2, color: '#00000033' } as const; +const shadowLayer3 = { x: 0, y: 8, blur: 16, color: rgb0000001f } as const; +const shadowLayer4 = { x: 0, y: 8, blur: 16, color: rgb00000008 } as const; + +const backgroundDangerLoud = { rest: ['#c02e56', rgbe55e7a], type: inverted } as const; +const backgroundSuccessLoud = { rest: ['#008455', '#05ad72'], type: inverted } as const; +const foregroundDangerOnloud = { rest: [rgbffffff, '#000000db'], type: inverted } as const; +const strokeDangerOnloud = { rest: [rgbffffff, '#242424'], type: inverted } as const; + +export const sharedFlexTokenInput = { + color: { + backgroundDangerLoud, + backgroundDangerSoft: ['#ffe3e6', '#5a2932'], + backgroundDangerSubtle: ['#fff1f3', '#402529'], + backgroundWarningLoud: { rest: ['#bb4001', rgbe56738], type: inverted }, + backgroundWarningSoft: ['#ffe5dc', '#592c1c'], + backgroundWarningSubtle: ['#fff2ee', '#40261d'], + backgroundSuccessLoud, + backgroundSuccessSoft: ['#c9f8dd', '#0c462d'], + backgroundSuccessSubtle: ['#e3fcee', '#193426'], + strokeDangerLoud: backgroundDangerLoud, + strokeDangerSoft: [rgbe55e7a, '#d14164'], + strokeDangerSubtle: ['#ffd0d6', '#76293a'], + strokeDangerOnloud, + strokeWarningLoud: { rest: [rgbcd4808, rgbe56738], type: inverted }, + strokeWarningSoft: [rgbfc9571, rgbcd4808], + strokeWarningSubtle: ['#ffd3c4', '#762e12'], + strokeWarningOnloud: strokeDangerOnloud, + strokeSuccessLoud: backgroundSuccessLoud, + strokeSuccessSoft: [rgb5dce97, '#008e5c'], + strokeSuccessSubtle: ['#b1efcc', '#025636'], + strokeSuccessOnloud: strokeDangerOnloud, + foregroundDangerPrimary: ['#a62147', '#fd8ea1'], + foregroundDangerOnloud, + foregroundWarningPrimary: ['#a93901', rgbfc9571], + foregroundWarningOnloud: foregroundDangerOnloud, + foregroundSuccessPrimary: ['#017048', rgb5dce97], + foregroundSuccessOnloud: foregroundDangerOnloud, + fixedWhite: rgbffffff, + fixedBlack: rgb000000, + expressionAchromaticHeavy: [rgb000000, rgbffffff], + expressionAchromaticSubtle: [rgbffffff, rgb000000], + expressionGrayHeavy: [rgb484848, rgbf5f5f5], + expressionGrayLoud: [rgb929292, rgbdedede], + expressionGraySoft: [rgbdedede, rgb929292], + expressionGraySubtle: [rgbf5f5f5, rgb484848], + expressionNavyHeavy: [rgb294482, rgbf0f5ff], + expressionNavyLoud: [rgb5c8df8, rgbcedeff], + expressionNavySoft: [rgbcedeff, rgb5c8df8], + expressionNavySubtle: [rgbf0f5ff, rgb294482], + expressionBlueHeavy: [rgb0b497f, rgbeef6ff], + expressionBlueLoud: [rgb2f95f4, rgbc6e1ff], + expressionBlueSoft: [rgbc6e1ff, rgb2f95f4], + expressionBlueSubtle: [rgbeef6ff, rgb0b497f], + expressionGreenHeavy: [rgb0c5722, rgbe7fce9], + expressionGreenLoud: [rgb32ad52, rgbbaedc1], + expressionGreenSoft: [rgbbaedc1, rgb32ad52], + expressionGreenSubtle: [rgbe7fce9, rgb0c5722], + expressionLimeHeavy: [rgb345200, rgbe6ffcf], + expressionLimeLoud: [rgb6da603, rgbcbff93], + expressionLimeSoft: [rgbcbff93, rgb6da603], + expressionLimeSubtle: [rgbe6ffcf, rgb345200], + expressionYellowHeavy: [rgb524800, rgbfff7c4], + expressionYellowLoud: [rgbfbdf06, rgbffed85], + expressionYellowSoft: [rgbffed85, rgbfbdf06], + expressionYellowSubtle: [rgbfff7c4, rgb524800], + expressionPumpkinHeavy: [rgb762f0e, rgbfef2ee], + expressionPumpkinLoud: [rgbfb966e, rgbffd3c2], + expressionPumpkinSoft: [rgbffd3c2, rgbfb966e], + expressionPumpkinSubtle: [rgbfef2ee, rgb762f0e], + expressionRedHeavy: [rgb772b28, rgbfff2f0], + expressionRedLoud: [rgbe7615b, rgbffd2cd], + expressionRedSoft: [rgbffd2cd, rgbe7615b], + expressionRedSubtle: [rgbfff2f0, rgb772b28], + expressionPinkHeavy: [rgb6f2b53, rgbfff1f7], + expressionPinkLoud: [rgbd961a6, rgbffcee6], + expressionPinkSoft: [rgbffcee6, rgbd961a6], + expressionPinkSubtle: [rgbfff1f7, rgb6f2b53], + expressionPurpleHeavy: [rgb523778, rgbf7f3ff], + expressionPurpleLoud: [rgba575e8, rgbe4d6ff], + expressionPurpleSoft: [rgbe4d6ff, rgba575e8], + expressionPurpleSubtle: [rgbf7f3ff, rgb523778], + overlayNeutralTranslucent: ['#00000026', '#00000099'], + materialBackgroundThick: ['#fffffff1', '#262626ea'], + materialBackgroundRegular: ['#ffffffd7', '#2f2f2fd1'], + materialBackgroundThin: ['#ffffff7e', '#3434348b'], + backgroundNeutralDisabled: [rgb00000008, '#ffffff07'], + backgroundNeutralHeavyDisabled: [rgb0000001a, '#ffffff20'], + strokeNeutralDisabled: [rgb00000014, '#ffffff24'], + foregroundNeutralDisabled: ['#0000006d', '#ffffff61'], + strokeFocusInner: [rgbffffff, rgb000000], + strokeFocusOuter: [rgb000000, rgbffffff], + shadow: rgb000000, + }, + shadow: { + lowest: [[shadowLayer1, { x: 0, y: 1, blur: 2, color: '#0000000d' }], [shadowLayer2, { x: 0, y: 1, blur: 2, color: rgb0000001a }]], + lower: [[shadowLayer1, { x: 0, y: 2, blur: 4, color: rgb00000014 }], [shadowLayer2, { x: 0, y: 2, blur: 4, color: rgb00000029 }]], + low: [ + [shadowLayer1, { x: 0, y: 2, blur: 4, color: rgb00000008 }, { x: 0, y: 4, blur: 8, color: rgb00000014 }], + [shadowLayer2, { x: 0, y: 2, blur: 4, color: rgb0000001f }, { x: 0, y: 4, blur: 8, color: rgb00000029 }], + ], + high: [ + [shadowLayer1, { x: 0, y: 4, blur: 8, color: rgb00000008 }, { x: 0, y: 8, blur: 16, color: rgb0000000f }], + [shadowLayer2, { x: 0, y: 4, blur: 8, color: rgb0000001f }, shadowLayer3], + ], + higher: [ + [shadowLayer1, shadowLayer4, { x: 0, y: 16, blur: 32, color: rgb0000000f }], + [shadowLayer2, shadowLayer3, { x: 0, y: 16, blur: 32, color: rgb0000001f }], + ], + highest: [ + [shadowLayer1, shadowLayer4, { x: 0, y: 32, blur: 64, color: rgb0000000f }], + [shadowLayer2, shadowLayer3, { x: 0, y: 32, blur: 64, color: rgb0000001f }], + ], + }, + fontWeight: { + functionalRegular: fontWeightRegular, + functionalMedium: fontWeightMedium, + functionalSemibold: fontWeightSemibold, + functionalBold: fontWeightBold, + contentRegular: fontWeightRegular, + contentMedium: fontWeightMedium, + contentSemibold: fontWeightSemibold, + contentBold: fontWeightBold, + contentEditorialRegular: fontWeightRegular, + contentEditorialMedium: fontWeightMedium, + contentEditorialSemibold: fontWeightSemibold, + contentEditorialBold: fontWeightBold, + }, + fontFamily: { functional: fontFamilyBase, content: fontFamilyBase, contentEditorial: fontFamilyBase, contentCode: fontFamilyMonospace }, + fontSize: { + functionalDisplay: 68, + functionalPagetitle: 40, + functionalTitleLarge: 32, + functionalTitleMedium: 28, + functionalTitleSmall: 24, + functionalSubtitle: 20, + functionalBodyLarge: 16, + functionalBodyMedium: 14, + functionalBodySmall: 12, + functionalCaption: 10, + contentStatement: 56, + contentExpressiveLarge: 48, + contentExpressiveMedium: 36, + contentExpressiveSmall: 28, + contentH1: 36, + contentH2: 32, + contentH3: 28, + contentH4: 24, + contentH5: 20, + contentSubheadline: 16, + contentParagraphLarge: 20, + contentParagraphMedium: 16, + contentParagraphSmall: 12, + contentSubtext: 10, + contentTable: 16, + contentCode: 16, + }, + lineHeight: { + functionalDisplay: 82, + functionalPagetitle: 48, + functionalTitleLarge: 38, + functionalTitleMedium: 34, + functionalTitleSmall: 28, + functionalSubtitle: 28, + functionalBodyLarge: 22, + functionalBodyMedium: 20, + functionalBodySmall: 16, + functionalCaption: 14, + contentStatement: 68, + contentExpressiveLarge: 58, + contentExpressiveMedium: 44, + contentExpressiveSmall: 34, + contentH1: 44, + contentH2: 38, + contentH3: 34, + contentH4: 28, + contentH5: 24, + contentSubheadline: 22, + contentParagraphLarge: 34, + contentParagraphMedium: 28, + contentParagraphSmall: 20, + contentSubtext: 14, + contentTable: 22, + contentCode: 22, + }, + borderRadius: { base100: 4, base200: 8, base300: 12, base400: 16, base600: 24, base700: 28, circular: 9999 }, + spacing: { + componentBase50: 2, + componentBase100: 4, + componentBase150: 6, + componentBase200: 8, + componentBase250: 10, + componentBase300: 12, + componentBase400: 16, + componentBase500: 20, + componentBase600: 24, + componentBase700: 28, + componentBase800: 32, + layoutBase100: 8, + layoutBase200: 16, + layoutBase300: 24, + layoutBase400: 32, + layoutBase450: 36, + layoutBase500: 40, + layoutBase600: 48, + layoutBase700: 56, + layoutBase800: 64, + layoutBase1000: 80, + layoutBase1200: 96, + }, + strokeWidth: { thin: 1, thick: 2, thicker: 3, thickest: 4 }, + motion: { + durationBase50: 50, + durationBase100: 100, + durationBase200: 200, + durationBase300: 300, + durationBase500: 500, + durationBase1000: 1000, + easingFunctionalEnter, + easingFunctionalExit, + easingFunctionalTransition, + easingFunctionalLinear: [0, 0, 1, 1], + easingExpressiveEnter: easingFunctionalEnter, + easingExpressiveExit: easingFunctionalExit, + easingExpressiveTransition: easingFunctionalTransition, + }, +} satisfies PartialFlexTokens; diff --git a/packages/agentic/design/src/flex/defaults/warmTokens.generated.ts b/packages/agentic/design/src/flex/defaults/warmTokens.generated.ts new file mode 100644 index 0000000000..4b6cbda9e3 --- /dev/null +++ b/packages/agentic/design/src/flex/defaults/warmTokens.generated.ts @@ -0,0 +1,82 @@ +// Generated by scripts/flex-defaults/generate-defaults.mjs. Do not edit; run `yarn gen:flex-defaults`. +// Source: x3-design/fluent-design@206e890b645fb450ad7c5df2ff981765349a2b58 +// cool: dev/web/flex-themes/css/semantic.css, dev/web/flex-themes/css/interaction-fallback.css +// warm: dev/web/flex-themes/css/warm/semantic.css, dev/web/flex-themes/css/warm/interaction-fallback.css +// Generic sources: src/tokens/mappings/flex-token-map.yaml +// Coverage: scripts/flex-defaults/coverage.generated.json + +import type { CompleteFlexTokenInput, PartialFlexTokens } from '../tokens.types'; +import { sharedFlexTokenInput } from './sharedTokens.generated'; + +const inverted = 'inverted'; +const rgb0b0600e1 = '#0b0600e1'; +const rgb28231e = '#28231e'; +const rgbffffff = '#ffffff'; + +const backgroundNeutralSoft = ['#4d200028', '#ffe3cb40'] as const; +const backgroundNeutralSubtle = ['#6c31001a', '#fff4ef14'] as const; +const backgroundNeutralTransparent = ['#28231e00', '#ffffff00'] as const; +const foregroundNeutralPrimary = [rgb0b0600e1, '#fff7f2e3'] as const; +const rest = ['#1e0d009a', '#ffeee39a'] as const; +const strokeNeutralSoft = ['#250f0076', '#ffe6d35c'] as const; + +const backgroundNeutralHeavy = { rest: [rgb28231e, rgbffffff], type: inverted } as const; +const backgroundNeutralLoud = { rest, type: inverted } as const; +const strokeNeutralLoud = { rest: ['#776d65', '#9a9089'], type: inverted } as const; +const strokeNeutralOnloud = { rest: [rgbffffff, rgb0b0600e1], type: inverted } as const; + +export const warmFlexTokenOverrides = { + color: { + surfaceNeutralFarther: ['#f0eae5', '#1e1916'], + surfaceNeutralFar: ['#faf4f0', '#231e1a'], + surfaceNeutralNear: ['#f6f1ec', '#1c1714'], + surfaceNeutralNearer: [rgbffffff, '#2e2823'], + surfaceNeutralTranslucent: ['#ffffff80', '#00000080'], + backgroundNeutralHeavy, + backgroundNeutralLoud, + backgroundNeutralSoft, + backgroundNeutralSubtle, + backgroundNeutralTransparent, + backgroundNeutralTranslucent: ['#e9e9e980', '#3c3c3c80'], + backgroundBrandHeavy: backgroundNeutralHeavy, + backgroundBrandLoud: backgroundNeutralLoud, + backgroundBrandSoft: backgroundNeutralSoft, + backgroundBrandSubtle: backgroundNeutralSubtle, + backgroundBrandTransparent: backgroundNeutralTransparent, + strokeNeutralHeavy: { rest: [rgb28231e, '#e3dcd7'], type: inverted }, + strokeNeutralLoud, + strokeNeutralSoft, + strokeNeutralSubtle: backgroundNeutralSoft, + strokeNeutralTransparent: backgroundNeutralTransparent, + strokeNeutralOnloud, + strokeBrandLoud: strokeNeutralLoud, + strokeBrandSoft: strokeNeutralSoft, + strokeBrandSubtle: backgroundNeutralSoft, + strokeBrandOnloud: strokeNeutralOnloud, + foregroundNeutralPrimary, + foregroundNeutralSecondary: ['#190c00ab', '#fff2e8b5'], + foregroundNeutralTertiary: rest, + foregroundNeutralOnloud: strokeNeutralOnloud, + foregroundBrandPrimary: foregroundNeutralPrimary, + foregroundBrandOnloud: strokeNeutralOnloud, + expressionAccentHeavy: [rgb28231e, rgbffffff], + expressionAccentLoud: rest, + expressionAccentSoft: backgroundNeutralSoft, + expressionAccentSubtle: backgroundNeutralSubtle, + backgroundNeutralSubtleDisabled: ['#0000000d', '#ffffff1b'], + }, +} satisfies PartialFlexTokens; + +/** The x3 warm-tone defaults. Omitted interaction states are computed from rest. */ +export const warmFlexTokenInput: CompleteFlexTokenInput = { + color: { ...sharedFlexTokenInput.color, ...warmFlexTokenOverrides.color }, + shadow: sharedFlexTokenInput.shadow, + fontWeight: sharedFlexTokenInput.fontWeight, + fontFamily: sharedFlexTokenInput.fontFamily, + fontSize: sharedFlexTokenInput.fontSize, + lineHeight: sharedFlexTokenInput.lineHeight, + borderRadius: sharedFlexTokenInput.borderRadius, + spacing: sharedFlexTokenInput.spacing, + strokeWidth: sharedFlexTokenInput.strokeWidth, + motion: sharedFlexTokenInput.motion, +}; diff --git a/packages/agentic/design/src/flex/flexThemeReference.ts b/packages/agentic/design/src/flex/flexThemeReference.ts index 729c3f0576..0900972c29 100644 --- a/packages/agentic/design/src/flex/flexThemeReference.ts +++ b/packages/agentic/design/src/flex/flexThemeReference.ts @@ -165,7 +165,7 @@ export class FlexThemeReference implements FlexThemeSource { return this.base.resolveDescription(appearance, key); } if (isFlexThemeDescription(this.base)) { - return this.base.tokens; + return typeof this.base.tokens === 'function' ? this.base.tokens(appearance) : this.base.tokens; } const base = typeof this.base === 'function' ? this.base(appearance) : this.base; return mergeFlexTokenDescription(getDefaultFlexTokenDescription(appearance.colorTone), base); diff --git a/packages/agentic/design/src/flex/themeState.test.ts b/packages/agentic/design/src/flex/themeState.test.ts new file mode 100644 index 0000000000..c4792dc23e --- /dev/null +++ b/packages/agentic/design/src/flex/themeState.test.ts @@ -0,0 +1,32 @@ +import { Appearance } from 'react-native'; + +import type { ThemeState } from './themeState.types'; + +describe('getDefaultThemeState', () => { + afterEach(() => jest.restoreAllMocks()); + + it.each(['light', 'dark', null] as const)('resolves the Flex theme for system scheme %s only on first use', (colorScheme) => { + jest.isolateModules(() => { + const getColorScheme = jest.spyOn(Appearance, 'getColorScheme').mockReturnValue(colorScheme); + const { getDefaultThemeState } = require('./themeState') as typeof import('./themeState'); + const { flexCoolTheme } = require('../themes/flex/flexCoolTheme') as typeof import('../themes/flex/flexCoolTheme'); + const { resolveFlexTokenDescription } = require('./colors/interactionPolicy') as typeof import('./colors/interactionPolicy'); + expect(getColorScheme).not.toHaveBeenCalled(); + + const state: ThemeState = getDefaultThemeState(); + expect(state.appearance).toEqual({ + colorScheme: colorScheme ?? 'light', + contrast: 'standard', + interfaceLevel: 'base', + colorTone: 'cool', + }); + const expected = resolveFlexTokenDescription(flexCoolTheme.tokens, state.appearance); + expect(state.tokens.color.surfaceNeutralNear.rest).toBe(expected.color.surfaceNeutralNear.rest); + expect(getColorScheme).toHaveBeenCalledTimes(1); + + getColorScheme.mockReturnValue(colorScheme === 'dark' ? 'light' : 'dark'); + expect(getDefaultThemeState()).toBe(state); + expect(getColorScheme).toHaveBeenCalledTimes(1); + }); + }); +}); diff --git a/packages/agentic/design/src/flex/themeState.ts b/packages/agentic/design/src/flex/themeState.ts index 156c197f60..4e98e3db49 100644 --- a/packages/agentic/design/src/flex/themeState.ts +++ b/packages/agentic/design/src/flex/themeState.ts @@ -1,18 +1,30 @@ -import { defaultFlexTokens } from './defaults/defaultTokens'; +import { Appearance } from 'react-native'; + +import { flexCoolTheme } from '../themes/flex/flexCoolTheme'; +import { resolveFlexTokenDescription } from './colors/interactionPolicy'; import { flexTokensFromTheme } from './adapters/flexTokensFromTheme'; import type { FlexTokens } from './tokens.types'; -import { defaultResolvedThemeAppearance } from '../theming/appearance'; +import { resolveThemeAppearance } from '../theming/appearance'; import { getFlexSourceTokens, getThemeAppearanceCache } from '../theming/themeRuntime'; import type { ThemeSource } from '../theming/themeSource'; import type { NormalizedThemeAppearance } from '../types/appearance.types'; import type { ThemeState } from './themeState.types'; -export const defaultThemeState: ThemeState = { - tokens: defaultFlexTokens, - appearance: defaultResolvedThemeAppearance, - highContrast: false, - themeStyles: {}, -}; +export const getDefaultThemeState = (() => { + let state: ThemeState | undefined; + return (): ThemeState => { + if (!state) { + const { resolved: appearance } = resolveThemeAppearance(undefined, { colorScheme: Appearance.getColorScheme() }); + state = { + tokens: resolveFlexTokenDescription(flexCoolTheme.tokens, appearance), + appearance, + highContrast: false, + themeStyles: {}, + }; + } + return state; + }; +})(); /** * Resolve Flex tokens for any source. Legacy sources use the forward adapter. diff --git a/packages/agentic/design/src/flex/themeState.types.ts b/packages/agentic/design/src/flex/themeState.types.ts index c7a12cd71f..95a85c877f 100644 --- a/packages/agentic/design/src/flex/themeState.types.ts +++ b/packages/agentic/design/src/flex/themeState.types.ts @@ -7,9 +7,10 @@ import type { FlexTokenDescription, FlexTokens } from './tokens.types'; */ export type FlexThemeDescription = { /** - * The complete authored token description, covering light and dark. + * The complete authored token description, covering light and dark, or a + * resolver that selects one for the resolved appearance. */ - readonly tokens: FlexTokenDescription; + readonly tokens: FlexTokenDescription | ((appearance: Readonly) => FlexTokenDescription); /** * The palette tone of these tokens. A `FlexThemeReference` built on this * description uses it as its default requested tone, which also selects the diff --git a/packages/agentic/design/src/flex/useThemeState.test.ts b/packages/agentic/design/src/flex/useThemeState.test.ts index ce3980b6fa..a7c5f3e226 100644 --- a/packages/agentic/design/src/flex/useThemeState.test.ts +++ b/packages/agentic/design/src/flex/useThemeState.test.ts @@ -70,6 +70,26 @@ function createMutableAppearanceSource() { } describe('useThemeState', () => { + it('shares the fallback appearance between theme hooks without a boundary', () => { + const states: ThemeState[] = []; + const appearances: ReturnType[] = []; + let component: ReactTestRenderer; + act(() => { + component = create( + React.createElement( + React.Fragment, + null, + React.createElement(ThemeStateProbe, { states }), + React.createElement(ThemeAppearanceProbe, { states: appearances }), + ), + ); + }); + + expect(appearances[0].resolved).toBe(states[0].appearance); + expect(appearances[0].requested.colorScheme).toBe('system'); + act(() => component!.unmount()); + }); + it('shares lazily created theme style sheets between component instances', () => { const states: ThemeState[] = []; let component: ReactTestRenderer; diff --git a/packages/agentic/design/src/flex/useThemeState.ts b/packages/agentic/design/src/flex/useThemeState.ts index 71db5db091..23e8b564bc 100644 --- a/packages/agentic/design/src/flex/useThemeState.ts +++ b/packages/agentic/design/src/flex/useThemeState.ts @@ -1,8 +1,8 @@ import type { ImageStyle, TextStyle, ViewStyle } from 'react-native'; -import { defaultThemeAppearanceState } from '../theming/appearance'; +import { resolveThemeAppearance } from '../theming/appearance'; import { useThemeBoundary } from '../theming/context'; -import { defaultThemeState, getThemeState } from './themeState'; +import { getDefaultThemeState, getThemeState } from './themeState'; import type { ThemeAppearanceState } from '../types/appearance.types'; import type { ThemeState } from './themeState.types'; @@ -20,7 +20,7 @@ export type ThemeStyleSheet = Record */ export function useThemeState(): ThemeState { const boundary = useThemeBoundary(); - return boundary ? getThemeState(boundary.source, boundary.appearance.resolved) : defaultThemeState; + return boundary ? getThemeState(boundary.source, boundary.appearance.resolved) : getDefaultThemeState(); } /** @@ -28,7 +28,7 @@ export function useThemeState(): ThemeState { */ export function useThemeAppearance(): Readonly { const boundary = useThemeBoundary(); - return boundary?.appearance ?? defaultThemeAppearanceState; + return boundary?.appearance ?? resolveThemeAppearance(undefined, getDefaultThemeState().appearance); } /** diff --git a/packages/agentic/design/src/test/compatibility/__snapshots__/entryPoints.test.ts.snap b/packages/agentic/design/src/test/compatibility/__snapshots__/entryPoints.test.ts.snap index dfc0a221e8..d21a14bc5d 100644 --- a/packages/agentic/design/src/test/compatibility/__snapshots__/entryPoints.test.ts.snap +++ b/packages/agentic/design/src/test/compatibility/__snapshots__/entryPoints.test.ts.snap @@ -112,6 +112,7 @@ exports[`public entry points ./testing keeps its runtime export names 1`] = ` exports[`public entry points ./themes keeps its runtime export names 1`] = ` [ + "flexCoolTheme: object", "flexTheme: object", "flexWarmTheme: object", "fluentDarkTheme: object", diff --git a/packages/agentic/design/src/test/compatibility/importBoundaries.test.ts b/packages/agentic/design/src/test/compatibility/importBoundaries.test.ts index 3609408765..3ef017ce79 100644 --- a/packages/agentic/design/src/test/compatibility/importBoundaries.test.ts +++ b/packages/agentic/design/src/test/compatibility/importBoundaries.test.ts @@ -291,13 +291,29 @@ describe('runtime graph ownership', () => { }); it('keeps the Flex themes on the generated Flex defaults, free of legacy Fluent runtime', () => { - for (const entry of ['themes/flex/flexTheme.ts', 'themes/flex/flexWarmTheme.ts']) { + for (const entry of ['themes/flex/flexTheme.ts', 'themes/flex/flexCoolTheme.ts', 'themes/flex/flexWarmTheme.ts']) { const graph = runtimeGraph(entry); - expect(graph).toContain('flex/defaults/defaultTokens.generated.ts'); + expect(graph).toContain('flex/defaults/sharedTokens.generated.ts'); expect([entry, reachedUnder(graph, 'fluent/')]).toEqual([entry, []]); expect(graph).not.toContain('color-lib/compositing.ts'); } }); + + it.each([ + ['cool', 'warm', 'flexCoolTheme'], + ['warm', 'cool', 'flexWarmTheme'], + ])('keeps the fixed %s palette independent of the %s tokens', (tone, otherTone, theme) => { + const graph = runtimeGraph(`themes/flex/${theme}.ts`); + expect(graph).toContain(`flex/defaults/${tone}Tokens.generated.ts`); + expect(graph).not.toContain(`flex/defaults/${otherTone}Tokens.generated.ts`); + expect(graph).not.toContain('flex/defaults/defaultTokens.ts'); + }); + + it('keeps the provider-free fallback on the cool palette only', () => { + const graph = runtimeGraph('flex/useThemeState.ts'); + expect(graph).toContain('themes/flex/flexCoolTheme.ts'); + expect(graph).not.toContain('flex/defaults/warmTokens.generated.ts'); + }); }); describe('shared types', () => { diff --git a/packages/agentic/design/src/themes/flex/flexCoolTheme.ts b/packages/agentic/design/src/themes/flex/flexCoolTheme.ts new file mode 100644 index 0000000000..c5360e4ccc --- /dev/null +++ b/packages/agentic/design/src/themes/flex/flexCoolTheme.ts @@ -0,0 +1,9 @@ +import { coolFlexTokenInput } from '../../flex/defaults/coolTokens.generated'; +import { createFlexTokenDescription } from '../../flex/flexTokenDescription'; +import type { FlexThemeDescription } from '../../flex/themeState.types'; + +/** The cool-tone Flex theme, covering light and dark without the warm palette. */ +export const flexCoolTheme = { + tokens: /* @__PURE__ */ createFlexTokenDescription(coolFlexTokenInput), + colorTone: 'cool', +} satisfies FlexThemeDescription; diff --git a/packages/agentic/design/src/themes/flex/flexTheme.ts b/packages/agentic/design/src/themes/flex/flexTheme.ts index fee34cc8af..084dfdf52b 100644 --- a/packages/agentic/design/src/themes/flex/flexTheme.ts +++ b/packages/agentic/design/src/themes/flex/flexTheme.ts @@ -1,7 +1,10 @@ -import { defaultFlexTokenDescription } from '../../flex/defaults/defaultTokens'; +import { flexCoolTheme } from './flexCoolTheme'; +import { flexWarmTheme } from './flexWarmTheme'; import type { FlexThemeDescription } from '../../flex/themeState.types'; /** - * The cool-tone Flex theme: the x3 cool default tokens for light and dark. + * The adaptive Flex theme, selecting its palette from the resolved color tone. */ -export const flexTheme: FlexThemeDescription = { tokens: defaultFlexTokenDescription, colorTone: 'cool' }; +export const flexTheme = { + tokens: (appearance) => (appearance.colorTone === 'warm' ? flexWarmTheme.tokens : flexCoolTheme.tokens), +} satisfies FlexThemeDescription; diff --git a/packages/agentic/design/src/themes/flex/flexThemes.test.tsx b/packages/agentic/design/src/themes/flex/flexThemes.test.tsx index 3f5667e89b..771a732ddc 100644 --- a/packages/agentic/design/src/themes/flex/flexThemes.test.tsx +++ b/packages/agentic/design/src/themes/flex/flexThemes.test.tsx @@ -5,11 +5,11 @@ import type { ThemeState } from '../../flex/themeState.types'; import { useThemeState } from '../../flex/useThemeState'; import { ThemeProvider } from '../../theming/ThemeProvider'; import type { ColorTone } from '../../types/appearance.types'; -import { flexTheme, flexWarmTheme } from '../index'; +import { flexCoolTheme, flexTheme, flexWarmTheme } from '../index'; describe('Flex themes', () => { it.each([ - ['flexTheme', flexTheme, 'cool'], + ['flexCoolTheme', flexCoolTheme, 'cool'], ['flexWarmTheme', flexWarmTheme, 'warm'], ] as const)('%s reproduces the package defaults for its tone in light and dark', (_name, theme, colorTone) => { const reference = new FlexThemeReference({ base: theme }); @@ -21,6 +21,39 @@ describe('Flex themes', () => { } }); + it.each(['light', 'dark'] as const)('switches flexTheme palettes with the requested tone in %s mode', (colorScheme) => { + const reference = new FlexThemeReference({ base: flexTheme }); + const coolReference = new FlexThemeReference({ base: flexCoolTheme }); + const warmReference = new FlexThemeReference({ base: flexWarmTheme }); + const seen: ThemeState[] = []; + const Probe = () => { + seen.push(useThemeState()); + return null; + }; + const render = (colorTone: ColorTone) => ( + + + + ); + let component!: ReturnType; + + act(() => { + component = create(render('cool')); + }); + const coolState = seen.at(-1)!; + expect(coolState.tokens).toEqual(coolReference.resolveFlexTokens(coolState.appearance)); + + act(() => component.update(render('warm'))); + const warmState = seen.at(-1)!; + expect(warmState.tokens).toEqual(warmReference.resolveFlexTokens(warmState.appearance)); + expect(warmState.tokens.color.surfaceNeutralNear.rest).not.toBe(coolState.tokens.color.surfaceNeutralNear.rest); + expect(warmState.themeStyles).not.toBe(coolState.themeStyles); + + act(() => component.update(render('cool'))); + expect(seen.at(-1)).toBe(coolState); + act(() => component.unmount()); + }); + it('makes a reference built on flexWarmTheme warm until a provider requests another tone', () => { const reference = new FlexThemeReference({ base: flexWarmTheme }); const seen: ThemeState[] = []; diff --git a/packages/agentic/design/src/themes/flex/flexWarmTheme.ts b/packages/agentic/design/src/themes/flex/flexWarmTheme.ts index 615aef2627..55d868a2f0 100644 --- a/packages/agentic/design/src/themes/flex/flexWarmTheme.ts +++ b/packages/agentic/design/src/themes/flex/flexWarmTheme.ts @@ -1,7 +1,11 @@ -import { getDefaultFlexTokenDescription } from '../../flex/defaults/defaultTokens'; +import { warmFlexTokenInput } from '../../flex/defaults/warmTokens.generated'; +import { createFlexTokenDescription } from '../../flex/flexTokenDescription'; import type { FlexThemeDescription } from '../../flex/themeState.types'; /** * The warm-tone Flex theme: the x3 warm default tokens for light and dark. */ -export const flexWarmTheme: FlexThemeDescription = { tokens: /* @__PURE__ */ getDefaultFlexTokenDescription('warm'), colorTone: 'warm' }; +export const flexWarmTheme = { + tokens: /* @__PURE__ */ createFlexTokenDescription(warmFlexTokenInput), + colorTone: 'warm', +} satisfies FlexThemeDescription; diff --git a/packages/agentic/design/src/themes/index.ts b/packages/agentic/design/src/themes/index.ts index 20b80200f7..33ebac6508 100644 --- a/packages/agentic/design/src/themes/index.ts +++ b/packages/agentic/design/src/themes/index.ts @@ -1,3 +1,4 @@ +export { flexCoolTheme } from './flex/flexCoolTheme'; export { flexTheme } from './flex/flexTheme'; export { flexWarmTheme } from './flex/flexWarmTheme'; export { fluentDarkTheme } from './fluent/fluentDarkTheme'; diff --git a/packages/agentic/design/src/theming/ThemedRoot.test.tsx b/packages/agentic/design/src/theming/ThemedRoot.test.tsx index 01da79d1bd..9c2ce8ccdd 100644 --- a/packages/agentic/design/src/theming/ThemedRoot.test.tsx +++ b/packages/agentic/design/src/theming/ThemedRoot.test.tsx @@ -11,6 +11,7 @@ import type { ThemeState } from '../flex/themeState.types'; import type { ResolvedThemeAppearance, ThemeAppearanceSource, ThemeAppearanceSourceSnapshot } from '../types/appearance.types'; import { ThemeContext } from './context'; import { FlexThemeReference } from '../flex/flexThemeReference'; +import { flexCoolTheme } from '../themes/flex/flexCoolTheme'; import { useRootSettings } from './rootContext'; import type { RootSettings } from './rootContext'; import { ThemedRoot } from './ThemedRoot'; @@ -117,6 +118,19 @@ describe('ThemedRoot', () => { expect(keyEvent.stopPropagation).not.toHaveBeenCalled(); }); + it('uses the cool palette when no theme is specified, even with a warm tone request', () => { + const themes: ThemeState[] = []; + render( + + + , + ); + + const state = themes[0]; + expect(state.appearance.colorTone).toBe('warm'); + expect(state.tokens).toEqual(new FlexThemeReference({ base: flexCoolTheme }).resolveFlexTokens(state.appearance)); + }); + it('updates modality before invoking caller handlers and preserves responder ownership', () => { const roots: RootSettings[] = []; const onKeyDown = jest.fn(() => expect(roots[0].inputModality).toBe('keyboard')); diff --git a/packages/agentic/design/src/theming/ThemedRoot.tsx b/packages/agentic/design/src/theming/ThemedRoot.tsx index 085cfa8146..04342fc29f 100644 --- a/packages/agentic/design/src/theming/ThemedRoot.tsx +++ b/packages/agentic/design/src/theming/ThemedRoot.tsx @@ -5,6 +5,7 @@ import type { IViewProps } from '@fluentui-react-native/adapters'; import { useThemeBoundary } from './context'; import { FlexThemeReference } from '../flex/flexThemeReference'; +import { flexCoolTheme } from '../themes/flex/flexCoolTheme'; import { RootContext } from './rootContext'; import { createRootInputController, RootInputContext } from './rootInputController'; import { useRootInputProps } from './useRootInputProps'; @@ -20,7 +21,7 @@ export interface ThemedRootProps extends IViewProps, Pick