@eos-ui/tokens 0.5.3 → 0.5.4

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/dist/theme.js CHANGED
@@ -159,9 +159,12 @@ function deriveGround(input, out, dark) {
159
159
  out["scrim"] = "rgb(0 0 0 / 0.75)";
160
160
  }
161
161
  }
162
+ function isDark(input) {
163
+ return input.surface !== undefined && luminance(input.surface) < DARK_BELOW;
164
+ }
162
165
  function derive(input) {
163
166
  const out = { ...defaults };
164
- const dark = input.surface !== undefined && luminance(input.surface) < DARK_BELOW;
167
+ const dark = isDark(input);
165
168
  if (dark) {
166
169
  for (const t of ["on-primary", "on-secondary", "on-danger"])
167
170
  out[t] = BLACK;
@@ -275,6 +278,8 @@ const WASHES = [
275
278
  export function defineTheme(input = {}) {
276
279
  const name = input.name ?? "custom";
277
280
  const tokens = derive(input);
281
+ // Tells the browser which way the page leans, so its own controls (scrollbars, colour picker, autofill) match.
282
+ const scheme = isDark(input) ? "dark" : "light";
278
283
  const issues = checkContrast(tokens);
279
284
  if (input.strict && issues.length) {
280
285
  throw new Error("Theme fails contrast:\n" +
@@ -289,13 +294,14 @@ export function defineTheme(input = {}) {
289
294
  .map(([k, v]) => ` --e-${k}: ${v};`)
290
295
  .join("\n");
291
296
  const derived = `${selector}, [data-e-theme] {\n${WASHES.map((w) => " " + w).join("\n")}\n}`;
292
- const rules = `${selector} {\n${decls}\n}\n${derived}\n`;
297
+ const rules = `${selector} {\n color-scheme: ${scheme};\n${decls}\n}\n${derived}\n`;
293
298
  const body = layer ? `@layer e.tokens {\n${rules}}\n` : rules;
294
299
  return (header ? `/* Generated from tokens.json. Theme: ${name}. */\n@layer ${LAYER_ORDER};\n` : "") + body;
295
300
  },
296
301
  apply(el = document.documentElement) {
297
302
  for (const [k, v] of Object.entries(tokens))
298
303
  el.style.setProperty(`--e-${k}`, v);
304
+ el.style.colorScheme = scheme;
299
305
  el.setAttribute("data-e-theme", name);
300
306
  },
301
307
  };
package/dist/tokens.css CHANGED
@@ -2,6 +2,7 @@
2
2
  @layer e.reset, e.tokens, e.base, e.primitives, e.blocks, e.controls, e.composites, e.containers, e.page;
3
3
  @layer e.tokens {
4
4
  :root {
5
+ color-scheme: light;
5
6
  --e-brand-blue: #2c95b4;
6
7
  --e-brand-green: #72c451;
7
8
  --e-primary: #17586d;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eos-ui/tokens",
3
- "version": "0.5.3",
3
+ "version": "0.5.4",
4
4
  "description": "Eos design tokens: CSS custom properties, typed values and a theme generator with contrast checks.",
5
5
  "type": "module",
6
6
  "license": "MIT",