@kanso-labs/kanso-ui-core 0.5.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -14,13 +14,38 @@ they read, so an app installs one of them rather than this.
14
14
 
15
15
  ## What it publishes
16
16
 
17
- | Import | What it is |
18
- | --------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
19
- | `@kanso-labs/kanso-ui-core` | `light` and `dark`, every `--kui-*` property at its value in each scheme; `daily`, the same pair in Daily's product colour; `breakpoints`, the window size classes; the `KuiTheme` type |
20
- | `@kanso-labs/kanso-ui-core/glyphs` | The path data of the glyphs both libraries draw inside their controls, one `<name>Path` constant each, and the 24-unit `gridSize` |
21
- | `@kanso-labs/kanso-ui-core/themes` | `demoThemes`, the seven demo schemes both libraries' Storybooks render, each a `KuiTheme` with a label and a description |
22
- | `@kanso-labs/kanso-ui-core/tokens.css` | The `--kui-*` custom properties at their defaults, the dark colours and shadows under `prefers-color-scheme: dark`, and the `kui-theme-daily` class, as both libraries publish them |
23
- | `@kanso-labs/kanso-ui-core/tokens.json` | The design tokens themselves, in the W3C Design Tokens format |
17
+ | Import | What it is |
18
+ | --------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
19
+ | `@kanso-labs/kanso-ui-core` | `light` and `dark`, every `--kui-*` property at its value in each scheme; `defineProductTheme`, which builds a product's theme from its own colours and checks their contrast; `breakpoints`, the window size classes; the `KuiTheme` type |
20
+ | `@kanso-labs/kanso-ui-core/glyphs` | The path data of the glyphs both libraries draw inside their controls, one `<name>Path` constant each, and the 24-unit `gridSize` |
21
+ | `@kanso-labs/kanso-ui-core/themes` | `demoThemes`, the seven demo schemes both libraries' Storybooks render, each a `KuiTheme` with a label and a description; `demoProductThemes`, the sample product colour, violet |
22
+ | `@kanso-labs/kanso-ui-core/tokens.css` | The `--kui-*` custom properties at their defaults, the dark colours and shadows under `prefers-color-scheme: dark`, as both libraries publish them |
23
+ | `@kanso-labs/kanso-ui-core/tokens.json` | The design tokens themselves, in the W3C Design Tokens format |
24
+
25
+ ## A product's own colour
26
+
27
+ Kanso's brand is ink and paper, with no colour of its own, so the base draws the
28
+ product roles in ink. A product brings one colour for them: it keeps its
29
+ palette, the twelve product roles in light and in dark, as data in its own
30
+ package, and builds its theme once.
31
+
32
+ ```ts
33
+ import { defineProductTheme } from '@kanso-labs/kanso-ui-core'
34
+
35
+ const productTheme = defineProductTheme({
36
+ dark: { accent: '#cdb0f5', onAccent: '#2a0d4a' /* …the other ten roles */ },
37
+ light: { accent: '#6b3fa0', onAccent: '#ffffff' /* … */ },
38
+ })
39
+ ```
40
+
41
+ Every colour that reads a product role follows it, `primary` and `focus-ring`
42
+ among them. `defineProductTheme` holds the colours to Kanso's contrast targets,
43
+ WCAG 2's 4.5:1 for text and 3:1 for the rest, in both schemes, and throws a
44
+ `ProductThemeError` naming each pair that misses one. The theme it returns holds
45
+ `light` and `dark`, every property at its value in that scheme, and `changes`,
46
+ every colour that follows a product role, those it leaves at the default
47
+ included, so a scope setting them replaces any product around it. Both
48
+ libraries' `ThemeScope` is to take it as `productTheme`.
24
49
 
25
50
  ## Development
26
51
 
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as light, i as dark, n as breakpoints, r as daily, t as KuiTheme } from "./defaults-Bzm8IVEs.js";
2
- export { type KuiTheme, breakpoints, daily, dark, light };
1
+ import { a as ProductThemeError, c as KuiTheme, d as dark, f as light, i as ProductTheme, l as ProductRole, n as ProductColors, o as Scheme, p as productRoles, r as ProductPalette, s as defineProductTheme, t as ContrastFailure, u as breakpoints } from "./product-theme-B_5X3tl7.js";
2
+ export { type ContrastFailure, type KuiTheme, type ProductColors, type ProductPalette, type ProductRole, type ProductTheme, ProductThemeError, type Scheme, breakpoints, dark, defineProductTheme, light, productRoles };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export { t as breakpoints, n as daily, r as dark, i as light } from "./defaults-BllR5oU-.js";
1
+ export { t as ProductThemeError, r as breakpoints, i as dark, n as defineProductTheme, a as light, o as productRoles } from "./product-theme-BpaQ7tJd.js";
@@ -727,14 +727,81 @@ declare const breakpoints: {
727
727
  readonly extraLarge: 1600;
728
728
  };
729
729
  /**
730
- * Daily's theme: every property at its value in each scheme, with
731
- * the product roles in Daily's colour and every colour that follows them.
732
- * The `kui-theme-daily` class in `tokens.css` follows the reader's
733
- * `prefers-color-scheme` only; a page that pins its scheme hands
734
- * `daily.light` or `daily.dark` to `ThemeScope` for the scheme it pins.
730
+ * The roles a product brings its own colour for, in light and in dark: the
731
+ * accent and the spotlight, each with what is drawn on it. The base fills them
732
+ * from the neutrals, since Kanso's brand is ink and paper.
735
733
  */
736
- declare const daily: {
734
+ declare const productRoles: readonly ["accent", "onAccent", "accentSoft", "onAccentSoft", "accentOnInk", "spotlight", "onSpotlight", "onSpotlightMuted", "spotlightButton", "onSpotlightButton", "spotlightTonal", "spotlightLine"];
735
+ /** A role a product sets: one of {@link productRoles}. */
736
+ type ProductRole = (typeof productRoles)[number];
737
+ /** A pair a product's colours draw below its target. */
738
+ type ContrastFailure = {
739
+ /** The colour drawn, by its name without `--kui-color-`, such as `on-accent`. */
740
+ readonly foreground: string;
741
+ /** The colour the foreground is drawn on, `a over b` for a translucent `a` painted on `b`. */
742
+ readonly ground: string;
743
+ /** The ratio it is drawn at. */
744
+ readonly ratio: number;
745
+ /** The scheme the pair is drawn in. */
746
+ readonly scheme: Scheme;
747
+ /** WCAG 2's bar: 4.5 for text, 3 for everything else. */
748
+ readonly target: number;
749
+ };
750
+ /** One scheme's product colours: a `#rrggbb` or `rgba()` value for every role. */
751
+ type ProductColors = { readonly [Role in ProductRole]: string; };
752
+ /** A product's colours in each scheme: what a product keeps as data. */
753
+ type ProductPalette = {
754
+ readonly dark: ProductColors;
755
+ readonly light: ProductColors;
756
+ };
757
+ /** A product's theme, as {@link defineProductTheme} builds it. */
758
+ type ProductTheme = {
759
+ /**
760
+ * Every colour that follows a product role, with the same properties in both
761
+ * schemes, each at its value in that scheme. It lists a colour the product
762
+ * leaves at its default too, so a scope declaring it replaces whatever
763
+ * product is set around it rather than only the colours this one moves.
764
+ */
765
+ readonly changes: {
766
+ readonly dark: KuiTheme;
767
+ readonly light: KuiTheme;
768
+ };
769
+ /** Every property at its value in the dark scheme, the product's colours in. */
737
770
  readonly dark: Required<KuiTheme>;
771
+ /** Every property at its value in the light scheme, the product's colours in. */
738
772
  readonly light: Required<KuiTheme>;
773
+ /** The palette the theme was built from. */
774
+ readonly palette: ProductPalette;
739
775
  };
740
- export { light as a, dark as i, breakpoints as n, daily as r, KuiTheme as t };
776
+ /** A colour scheme, as a product's palette and theme are keyed by it. */
777
+ type Scheme = 'dark' | 'light';
778
+ /** Thrown by {@link defineProductTheme} for a palette below a contrast target. */
779
+ declare class ProductThemeError extends Error {
780
+ /** Every pair below its target, in light and then in dark. */
781
+ readonly failures: readonly ContrastFailure[];
782
+ constructor(failures: readonly ContrastFailure[]);
783
+ }
784
+ /**
785
+ * Builds a product's theme from its colours: every colour that follows a
786
+ * product role takes the product's value of it, `primary`, `focus-ring` and
787
+ * the other Material Design roles that alias the accent included, and
788
+ * everything else keeps its default.
789
+ *
790
+ * The colours are held to Kanso's contrast targets, WCAG 2's 4.5:1 for text
791
+ * and 3:1 for the rest, in both schemes, over the same pairs the base clears:
792
+ * those Kanso's usage notes name and those both libraries draw. A palette
793
+ * below one throws a {@link ProductThemeError} naming every pair; one missing
794
+ * a scheme or a role, naming one it does not have, or holding a value that is not a
795
+ * `#rrggbb` or `rgba()` colour throws a `TypeError`.
796
+ *
797
+ * Build it once, as a constant: both libraries' `ThemeScope` is to keep what
798
+ * it resolves for each theme object it is handed.
799
+ *
800
+ * ```ts
801
+ * const productTheme = defineProductTheme({ dark: { accent: '#cdb0f5', … }, light: { accent: '#6b3fa0', … } })
802
+ *
803
+ * <ThemeScope productTheme={productTheme}>…</ThemeScope>
804
+ * ```
805
+ */
806
+ declare function defineProductTheme(palette: ProductPalette): ProductTheme;
807
+ export { ProductThemeError as a, KuiTheme as c, dark as d, light as f, ProductTheme as i, ProductRole as l, ProductColors as n, Scheme as o, productRoles as p, ProductPalette as r, defineProductTheme as s, ContrastFailure as t, breakpoints as u };