@kya-os/consent 0.4.0 → 0.4.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.
Files changed (226) hide show
  1. package/README.md +182 -22
  2. package/dist/bundle/index.d.ts +4 -0
  3. package/dist/bundle/index.d.ts.map +1 -1
  4. package/dist/bundle/index.js +6 -0
  5. package/dist/bundle/index.js.map +1 -1
  6. package/dist/bundle/inline.d.ts.map +1 -1
  7. package/dist/bundle/inline.js +4 -4
  8. package/dist/bundle/inline.js.map +1 -1
  9. package/dist/cjs/bundle/index.js +15 -1
  10. package/dist/cjs/bundle/index.js.map +1 -1
  11. package/dist/cjs/bundle/inline.js +4 -4
  12. package/dist/cjs/bundle/inline.js.map +1 -1
  13. package/dist/cjs/components/consent-action-bar.js +97 -25
  14. package/dist/cjs/components/consent-action-bar.js.map +1 -1
  15. package/dist/cjs/components/consent-agent-header.js +7 -105
  16. package/dist/cjs/components/consent-agent-header.js.map +1 -1
  17. package/dist/cjs/components/consent-button.js +6 -1
  18. package/dist/cjs/components/consent-button.js.map +1 -1
  19. package/dist/cjs/components/consent-capabilities-screen.js +454 -68
  20. package/dist/cjs/components/consent-capabilities-screen.js.map +1 -1
  21. package/dist/cjs/components/consent-capability-card.js +131 -27
  22. package/dist/cjs/components/consent-capability-card.js.map +1 -1
  23. package/dist/cjs/components/consent-checkbox.js +7 -0
  24. package/dist/cjs/components/consent-checkbox.js.map +1 -1
  25. package/dist/cjs/components/consent-connector-header.js +206 -43
  26. package/dist/cjs/components/consent-connector-header.js.map +1 -1
  27. package/dist/cjs/components/consent-duration.js +1 -1
  28. package/dist/cjs/components/consent-footer.js +13 -12
  29. package/dist/cjs/components/consent-footer.js.map +1 -1
  30. package/dist/cjs/components/consent-headline.js +399 -33
  31. package/dist/cjs/components/consent-headline.js.map +1 -1
  32. package/dist/cjs/components/consent-oauth-button.js +71 -62
  33. package/dist/cjs/components/consent-oauth-button.js.map +1 -1
  34. package/dist/cjs/components/consent-otp-input.js +5 -0
  35. package/dist/cjs/components/consent-otp-input.js.map +1 -1
  36. package/dist/cjs/components/consent-phone-handoff.js +3 -3
  37. package/dist/cjs/components/consent-request-expiry.js +1 -1
  38. package/dist/cjs/components/consent-revocation-notice.js +4 -2
  39. package/dist/cjs/components/consent-revocation-notice.js.map +1 -1
  40. package/dist/cjs/components/consent-revoke.js +9 -4
  41. package/dist/cjs/components/consent-revoke.js.map +1 -1
  42. package/dist/cjs/components/consent-secured-by.js +106 -0
  43. package/dist/cjs/components/consent-secured-by.js.map +1 -0
  44. package/dist/cjs/components/consent-shell.js +1 -1
  45. package/dist/cjs/components/consent-terms.js +7 -0
  46. package/dist/cjs/components/consent-terms.js.map +1 -1
  47. package/dist/cjs/components/consent-wallet-check.js +1 -1
  48. package/dist/cjs/components/consent-wallet-notice.js +1 -1
  49. package/dist/cjs/components/consent-wallet-orb.js +1 -1
  50. package/dist/cjs/components/consent-wallet-signature.js +1 -1
  51. package/dist/cjs/components/decision-icons.js +33 -0
  52. package/dist/cjs/components/decision-icons.js.map +1 -0
  53. package/dist/cjs/components/edit-region.js +309 -0
  54. package/dist/cjs/components/edit-region.js.map +1 -0
  55. package/dist/cjs/components/grant-field-styles.js +2 -2
  56. package/dist/cjs/components/index.js +4 -1
  57. package/dist/cjs/components/index.js.map +1 -1
  58. package/dist/cjs/components/mcp-consent.js +81 -36
  59. package/dist/cjs/components/mcp-consent.js.map +1 -1
  60. package/dist/cjs/components/preview.js +67 -0
  61. package/dist/cjs/components/preview.js.map +1 -0
  62. package/dist/cjs/constants/capabilities.js +12 -2
  63. package/dist/cjs/constants/capabilities.js.map +1 -1
  64. package/dist/cjs/copy/tokens.js +60 -21
  65. package/dist/cjs/copy/tokens.js.map +1 -1
  66. package/dist/cjs/identity/agent-identity.js +3 -2
  67. package/dist/cjs/identity/agent-identity.js.map +1 -1
  68. package/dist/cjs/mcp-app/inline.js +2 -2
  69. package/dist/cjs/mcp-app/inline.js.map +1 -1
  70. package/dist/cjs/react/index.js +11 -2
  71. package/dist/cjs/react/index.js.map +1 -1
  72. package/dist/cjs/styles/brand.js +385 -0
  73. package/dist/cjs/styles/brand.js.map +1 -0
  74. package/dist/cjs/styles/index.js +1 -0
  75. package/dist/cjs/styles/index.js.map +1 -1
  76. package/dist/cjs/styles/theme.js +100 -30
  77. package/dist/cjs/styles/theme.js.map +1 -1
  78. package/dist/cjs/types/capabilities.types.js +1 -2
  79. package/dist/cjs/types/capabilities.types.js.map +1 -1
  80. package/dist/cjs/types/decision.types.js +13 -0
  81. package/dist/cjs/types/decision.types.js.map +1 -0
  82. package/dist/cjs/types/edit.types.js +80 -0
  83. package/dist/cjs/types/edit.types.js.map +1 -0
  84. package/dist/cjs/types/index.js +2 -0
  85. package/dist/cjs/types/index.js.map +1 -1
  86. package/dist/components/consent-action-bar.d.ts +20 -1
  87. package/dist/components/consent-action-bar.d.ts.map +1 -1
  88. package/dist/components/consent-action-bar.js +97 -25
  89. package/dist/components/consent-action-bar.js.map +1 -1
  90. package/dist/components/consent-agent-header.d.ts +4 -17
  91. package/dist/components/consent-agent-header.d.ts.map +1 -1
  92. package/dist/components/consent-agent-header.js +7 -105
  93. package/dist/components/consent-agent-header.js.map +1 -1
  94. package/dist/components/consent-button.d.ts +2 -0
  95. package/dist/components/consent-button.d.ts.map +1 -1
  96. package/dist/components/consent-button.js +6 -1
  97. package/dist/components/consent-button.js.map +1 -1
  98. package/dist/components/consent-capabilities-screen.d.ts +85 -17
  99. package/dist/components/consent-capabilities-screen.d.ts.map +1 -1
  100. package/dist/components/consent-capabilities-screen.js +456 -70
  101. package/dist/components/consent-capabilities-screen.js.map +1 -1
  102. package/dist/components/consent-capability-card.d.ts +23 -3
  103. package/dist/components/consent-capability-card.d.ts.map +1 -1
  104. package/dist/components/consent-capability-card.js +131 -27
  105. package/dist/components/consent-capability-card.js.map +1 -1
  106. package/dist/components/consent-checkbox.d.ts +2 -0
  107. package/dist/components/consent-checkbox.d.ts.map +1 -1
  108. package/dist/components/consent-checkbox.js +7 -0
  109. package/dist/components/consent-checkbox.js.map +1 -1
  110. package/dist/components/consent-connector-header.d.ts +39 -7
  111. package/dist/components/consent-connector-header.d.ts.map +1 -1
  112. package/dist/components/consent-connector-header.js +206 -43
  113. package/dist/components/consent-connector-header.js.map +1 -1
  114. package/dist/components/consent-duration.js +1 -1
  115. package/dist/components/consent-footer.d.ts +6 -4
  116. package/dist/components/consent-footer.d.ts.map +1 -1
  117. package/dist/components/consent-footer.js +13 -12
  118. package/dist/components/consent-footer.js.map +1 -1
  119. package/dist/components/consent-headline.d.ts +55 -16
  120. package/dist/components/consent-headline.d.ts.map +1 -1
  121. package/dist/components/consent-headline.js +398 -34
  122. package/dist/components/consent-headline.js.map +1 -1
  123. package/dist/components/consent-oauth-button.d.ts +7 -3
  124. package/dist/components/consent-oauth-button.d.ts.map +1 -1
  125. package/dist/components/consent-oauth-button.js +74 -65
  126. package/dist/components/consent-oauth-button.js.map +1 -1
  127. package/dist/components/consent-otp-input.d.ts.map +1 -1
  128. package/dist/components/consent-otp-input.js +5 -0
  129. package/dist/components/consent-otp-input.js.map +1 -1
  130. package/dist/components/consent-passkey.d.ts +6 -0
  131. package/dist/components/consent-passkey.d.ts.map +1 -1
  132. package/dist/components/consent-passkey.js +67 -9
  133. package/dist/components/consent-passkey.js.map +1 -1
  134. package/dist/components/consent-phone-handoff.js +3 -3
  135. package/dist/components/consent-request-expiry.js +1 -1
  136. package/dist/components/consent-revocation-notice.d.ts.map +1 -1
  137. package/dist/components/consent-revocation-notice.js +4 -2
  138. package/dist/components/consent-revocation-notice.js.map +1 -1
  139. package/dist/components/consent-revoke.d.ts +2 -0
  140. package/dist/components/consent-revoke.d.ts.map +1 -1
  141. package/dist/components/consent-revoke.js +9 -4
  142. package/dist/components/consent-revoke.js.map +1 -1
  143. package/dist/components/consent-secured-by.d.ts +25 -0
  144. package/dist/components/consent-secured-by.d.ts.map +1 -0
  145. package/dist/components/consent-secured-by.js +103 -0
  146. package/dist/components/consent-secured-by.js.map +1 -0
  147. package/dist/components/consent-shell.js +1 -1
  148. package/dist/components/consent-terms.d.ts +2 -0
  149. package/dist/components/consent-terms.d.ts.map +1 -1
  150. package/dist/components/consent-terms.js +7 -0
  151. package/dist/components/consent-terms.js.map +1 -1
  152. package/dist/components/consent-wallet-check.js +1 -1
  153. package/dist/components/consent-wallet-notice.js +1 -1
  154. package/dist/components/consent-wallet-orb.js +1 -1
  155. package/dist/components/consent-wallet-signature.js +1 -1
  156. package/dist/components/decision-icons.d.ts +22 -0
  157. package/dist/components/decision-icons.d.ts.map +1 -0
  158. package/dist/components/decision-icons.js +30 -0
  159. package/dist/components/decision-icons.js.map +1 -0
  160. package/dist/components/edit-region.d.ts +50 -0
  161. package/dist/components/edit-region.d.ts.map +1 -0
  162. package/dist/components/edit-region.js +305 -0
  163. package/dist/components/edit-region.js.map +1 -0
  164. package/dist/components/grant-field-styles.js +2 -2
  165. package/dist/components/index.d.ts +2 -1
  166. package/dist/components/index.d.ts.map +1 -1
  167. package/dist/components/index.js +2 -1
  168. package/dist/components/index.js.map +1 -1
  169. package/dist/components/mcp-consent.d.ts +15 -0
  170. package/dist/components/mcp-consent.d.ts.map +1 -1
  171. package/dist/components/mcp-consent.js +81 -36
  172. package/dist/components/mcp-consent.js.map +1 -1
  173. package/dist/components/preview.d.ts +38 -0
  174. package/dist/components/preview.d.ts.map +1 -0
  175. package/dist/components/preview.js +61 -0
  176. package/dist/components/preview.js.map +1 -0
  177. package/dist/consent.js +2104 -389
  178. package/dist/consent.min.js +1289 -497
  179. package/dist/constants/capabilities.d.ts +12 -3
  180. package/dist/constants/capabilities.d.ts.map +1 -1
  181. package/dist/constants/capabilities.js +12 -2
  182. package/dist/constants/capabilities.js.map +1 -1
  183. package/dist/copy/tokens.d.ts +60 -21
  184. package/dist/copy/tokens.d.ts.map +1 -1
  185. package/dist/copy/tokens.js +60 -21
  186. package/dist/copy/tokens.js.map +1 -1
  187. package/dist/identity/agent-identity.d.ts +3 -2
  188. package/dist/identity/agent-identity.d.ts.map +1 -1
  189. package/dist/identity/agent-identity.js +3 -2
  190. package/dist/identity/agent-identity.js.map +1 -1
  191. package/dist/mcp-app/inline.d.ts.map +1 -1
  192. package/dist/mcp-app/inline.js +2 -2
  193. package/dist/mcp-app/inline.js.map +1 -1
  194. package/dist/react/index.d.ts +6 -1
  195. package/dist/react/index.d.ts.map +1 -1
  196. package/dist/react/index.js +10 -1
  197. package/dist/react/index.js.map +1 -1
  198. package/dist/styles/brand.d.ts +184 -0
  199. package/dist/styles/brand.d.ts.map +1 -0
  200. package/dist/styles/brand.js +372 -0
  201. package/dist/styles/brand.js.map +1 -0
  202. package/dist/styles/index.d.ts +1 -0
  203. package/dist/styles/index.d.ts.map +1 -1
  204. package/dist/styles/index.js +1 -0
  205. package/dist/styles/index.js.map +1 -1
  206. package/dist/styles/theme.d.ts +73 -13
  207. package/dist/styles/theme.d.ts.map +1 -1
  208. package/dist/styles/theme.js +96 -29
  209. package/dist/styles/theme.js.map +1 -1
  210. package/dist/types/capabilities.types.d.ts +12 -14
  211. package/dist/types/capabilities.types.d.ts.map +1 -1
  212. package/dist/types/capabilities.types.js +1 -2
  213. package/dist/types/capabilities.types.js.map +1 -1
  214. package/dist/types/decision.types.d.ts +57 -0
  215. package/dist/types/decision.types.d.ts.map +1 -0
  216. package/dist/types/decision.types.js +12 -0
  217. package/dist/types/decision.types.js.map +1 -0
  218. package/dist/types/edit.types.d.ts +73 -0
  219. package/dist/types/edit.types.d.ts.map +1 -0
  220. package/dist/types/edit.types.js +76 -0
  221. package/dist/types/edit.types.js.map +1 -0
  222. package/dist/types/index.d.ts +2 -0
  223. package/dist/types/index.d.ts.map +1 -1
  224. package/dist/types/index.js +2 -0
  225. package/dist/types/index.js.map +1 -1
  226. package/package.json +2 -2
@@ -0,0 +1,372 @@
1
+ /**
2
+ * Brand Colors on the Consent Screens
3
+ *
4
+ * A host's brand is operator data: a primary color, maybe a secondary, and
5
+ * maybe the page's own colors (card, panel, border, text, quieter text, focus
6
+ * ring). These turn it into the `--cs-*` properties the screens read, each
7
+ * one checked so it reads:
8
+ *
9
+ * - a word in the brand (an action) reaches 4.5:1 (WCAG 1.4.3) on the card
10
+ * and on the brand's tint, else it is drawn in the text color;
11
+ * - a mark or focus ring in the brand reaches 3:1 (WCAG 1.4.11), else the
12
+ * text color;
13
+ * - an icon in the secondary keeps its hue and moves darker or lighter,
14
+ * whichever is nearer, until it reaches 3:1 on every surface an icon sits on;
15
+ * - a page color that would not read is dropped, and the theme's is drawn.
16
+ *
17
+ * `brandTokens(brand)` returns the properties; set them on any element above
18
+ * the screens (a style attribute is enough) and the screens take them.
19
+ * Everything here is pure: importing it defines no element.
20
+ *
21
+ * Unless a brand chooses its own page colors, these judge against the light
22
+ * theme's surfaces.
23
+ *
24
+ * @module @kya-os/consent/styles/brand
25
+ */
26
+ import { contrastRatio, isHexColor, relativeLuminance } from "./contrast.js";
27
+ import { TINT_LINE_PERCENT, TINT_PERCENT, lightTheme } from "./theme.js";
28
+ /** WCAG 1.4.11's ratio for a graphic or a focus indicator. */
29
+ export const AA_GRAPHIC_CONTRAST = 3;
30
+ /** WCAG 1.4.3's ratio for text at body size. */
31
+ const TEXT_CONTRAST = 4.5;
32
+ /** The share of the primary in an icon's tile. */
33
+ export const ICON_TILE_PERCENT = 8;
34
+ /** The share of the primary in a hovered row under that tile. */
35
+ export const HOVERED_ROW_PERCENT = 4;
36
+ /** The share of the text in the quieter text the page draws from it. */
37
+ export const MUTED_TEXT_PERCENT = 64;
38
+ /** The share of the text in a panel made for a chosen card with no panel chosen. */
39
+ export const PANEL_TINT_PERCENT = 4;
40
+ /** How far each try lowers an icon's lightness: about 0.03 of contrast. */
41
+ const LIGHTNESS_STEP = 0.005;
42
+ /** The light theme's own colors, all `#rrggbb`. */
43
+ export const LIGHT_DRAWN_COLORS = Object.freeze({
44
+ surface: lightTheme.surfaceCard,
45
+ panel: lightTheme.surfaceInset,
46
+ text: lightTheme.textPrimary,
47
+ mutedText: lightTheme.textTertiary,
48
+ });
49
+ /** The page colors a brand may choose, one color per field. */
50
+ export const PALETTE_FIELDS = [
51
+ "surfaceColor",
52
+ "panelColor",
53
+ "borderColor",
54
+ "textColor",
55
+ "mutedTextColor",
56
+ "focusColor",
57
+ ];
58
+ function rgbOf(hex) {
59
+ return [1, 3, 5].map((at) => Number.parseInt(hex.slice(at, at + 2), 16));
60
+ }
61
+ function hexOf(channels) {
62
+ return `#${channels
63
+ .map((value) => Math.round(value).toString(16).padStart(2, "0"))
64
+ .join("")}`;
65
+ }
66
+ /**
67
+ * `top` at `percent` over the opaque `under`, as a browser composites it
68
+ * (both `#rrggbb`).
69
+ *
70
+ * @example
71
+ * mixOver("#000000", 50, "#ffffff"); // "#808080"
72
+ */
73
+ export function mixOver(top, percent, under) {
74
+ const share = percent / 100;
75
+ const below = rgbOf(under);
76
+ return hexOf(rgbOf(top).map((above, i) => above * share + below[i] * (1 - share)));
77
+ }
78
+ function hslOf(hex) {
79
+ const [red, green, blue] = rgbOf(hex).map((value) => value / 255);
80
+ const high = Math.max(red, green, blue);
81
+ const low = Math.min(red, green, blue);
82
+ const spread = high - low;
83
+ const lightness = (high + low) / 2;
84
+ if (spread === 0)
85
+ return { hue: 0, saturation: 0, lightness };
86
+ const saturation = spread / (1 - Math.abs(2 * lightness - 1));
87
+ const sector = high === red
88
+ ? (green - blue) / spread
89
+ : high === green
90
+ ? (blue - red) / spread + 2
91
+ : (red - green) / spread + 4;
92
+ return { hue: (sector * 60 + 360) % 360, saturation, lightness };
93
+ }
94
+ function hexFromHsl({ hue, saturation, lightness }) {
95
+ const reach = saturation * Math.min(lightness, 1 - lightness);
96
+ const channel = (offset) => {
97
+ const turn = (offset + hue / 30) % 12;
98
+ return ((lightness - reach * Math.max(-1, Math.min(turn - 3, 9 - turn, 1))) * 255);
99
+ };
100
+ return hexOf([channel(0), channel(8), channel(4)]);
101
+ }
102
+ /**
103
+ * What an icon is drawn in, for a chosen secondary (`hex`) under a primary:
104
+ * the secondary itself when it shows at 3:1 on everything an icon sits on
105
+ * (the card, the panel, and the primary's icon tile at rest and on a hovered
106
+ * row), else the same hue and saturation at the nearest lightness that does,
107
+ * darker or lighter. Light surfaces push it darker and dark ones lighter, so a
108
+ * dark palette gets a light icon. When no lightness shows on all of them, the
109
+ * icon is black or white, whichever reads better on the worst of them.
110
+ *
111
+ * @example
112
+ * iconColorFor("#1e3a5f", "#111111"); // "#1e3a5f", it already shows
113
+ * iconColorFor("#b08d57", "#111111"); // a darker gold
114
+ * iconColorFor("#333344", "#2563eb", { surface: "#1b1d24", panel: "#25272e" });
115
+ * // a lighter slate
116
+ */
117
+ export function iconColorFor(hex, primary, drawn = LIGHT_DRAWN_COLORS) {
118
+ const hoveredRow = mixOver(primary, HOVERED_ROW_PERCENT, drawn.surface);
119
+ const surfaces = [
120
+ drawn.surface,
121
+ drawn.panel,
122
+ mixOver(primary, ICON_TILE_PERCENT, drawn.surface),
123
+ mixOver(primary, ICON_TILE_PERCENT, hoveredRow),
124
+ ];
125
+ const worstRatio = (candidate) => Math.min(...surfaces.map((surface) => contrastRatio(candidate, surface)));
126
+ if (worstRatio(hex) >= AA_GRAPHIC_CONTRAST)
127
+ return hex;
128
+ // Step away from the chosen lightness both ways at once, darker first, so
129
+ // the first lightness that shows is the nearest one.
130
+ const start = hslOf(hex);
131
+ for (let steps = 1; steps * LIGHTNESS_STEP <= 1; steps++) {
132
+ for (const lightness of [
133
+ start.lightness - steps * LIGHTNESS_STEP,
134
+ start.lightness + steps * LIGHTNESS_STEP,
135
+ ]) {
136
+ if (lightness < 0 || lightness > 1)
137
+ continue;
138
+ const candidate = hexFromHsl({ ...start, lightness });
139
+ if (worstRatio(candidate) >= AA_GRAPHIC_CONTRAST)
140
+ return candidate;
141
+ }
142
+ }
143
+ return worstRatio("#000000") >= worstRatio("#ffffff") ? "#000000" : "#ffffff";
144
+ }
145
+ /**
146
+ * What a focus ring on the card is drawn in: the brand when it shows on the
147
+ * card at 3:1, else the text color. A light brand (#ffd23f is 1.44:1 on
148
+ * white) gets the text color.
149
+ *
150
+ * @example
151
+ * focusRingFor("#1e3a5f"); // "brand"
152
+ * focusRingFor("#ffd23f"); // "ink"
153
+ */
154
+ export function focusRingFor(hex, surface = LIGHT_DRAWN_COLORS.surface) {
155
+ return contrastRatio(hex, surface) >= AA_GRAPHIC_CONTRAST ? "brand" : "ink";
156
+ }
157
+ /** Whether `hex` reaches `ratio` on the card and on its own tint over the card. */
158
+ function readsOnCardAndTint(hex, ratio, surface) {
159
+ const tint = mixOver(hex, TINT_PERCENT, surface);
160
+ return (contrastRatio(hex, surface) >= ratio && contrastRatio(hex, tint) >= ratio);
161
+ }
162
+ /**
163
+ * What words in the brand are drawn in (a link, the agent's name): the brand
164
+ * when it reads at 4.5:1 on the card and on its tint, else the text color.
165
+ *
166
+ * @example
167
+ * actionColorFor("#1e3a5f"); // "brand"
168
+ * actionColorFor("#2b9348"); // "ink", 3.91:1 on white
169
+ */
170
+ export function actionColorFor(hex, surface = LIGHT_DRAWN_COLORS.surface) {
171
+ return readsOnCardAndTint(hex, TEXT_CONTRAST, surface) ? "brand" : "ink";
172
+ }
173
+ /**
174
+ * What marks in the brand are drawn in (a shield, the icons in the details):
175
+ * the brand when it shows at 3:1 on the card and on its tint, else the text
176
+ * color.
177
+ *
178
+ * @example
179
+ * markColorFor("#2b9348"); // "brand", 3.91:1 on white
180
+ * markColorFor("#ffd23f"); // "ink"
181
+ */
182
+ export function markColorFor(hex, surface = LIGHT_DRAWN_COLORS.surface) {
183
+ return readsOnCardAndTint(hex, AA_GRAPHIC_CONTRAST, surface)
184
+ ? "brand"
185
+ : "ink";
186
+ }
187
+ /** Black or white, whichever reads better on `hex`; a tie gives black. */
188
+ export function onPrimaryFor(hex) {
189
+ const luminance = relativeLuminance(hex);
190
+ const againstWhite = 1.05 / (luminance + 0.05);
191
+ const againstBlack = (luminance + 0.05) / 0.05;
192
+ return againstBlack >= againstWhite ? "black" : "white";
193
+ }
194
+ /**
195
+ * The panel drawn inside the card: a chosen panel as it is; with none, the
196
+ * theme's own when the card is the theme's too, else the text at
197
+ * {@link PANEL_TINT_PERCENT} over the chosen card, so a chosen card never
198
+ * sits around a panel it was not chosen for.
199
+ */
200
+ function panelOf(palette, text, drawn) {
201
+ if (palette.panelColor)
202
+ return palette.panelColor;
203
+ if (palette.surfaceColor)
204
+ return mixOver(text, PANEL_TINT_PERCENT, palette.surfaceColor);
205
+ return drawn.panel;
206
+ }
207
+ /** The quieter text drawn on `background`. */
208
+ function mutedOn(palette, background, drawn) {
209
+ if (palette.mutedTextColor)
210
+ return palette.mutedTextColor;
211
+ if (palette.textColor)
212
+ return mixOver(palette.textColor, MUTED_TEXT_PERCENT, background);
213
+ return drawn.mutedText;
214
+ }
215
+ /** A ratio rounded down to two places: 4.4995 is 4.49, never 4.50. */
216
+ function floorToHundredths(ratio) {
217
+ return Math.floor(ratio * 100) / 100;
218
+ }
219
+ /**
220
+ * Every pair of the page's colors that would not read: the text and the
221
+ * quieter text at 4.5:1 and the focus ring at 3:1, each on the card and on
222
+ * the panel. A color the brand did not choose is judged as the page draws it
223
+ * (`drawn`, the light theme unless given). The border is decorative and has
224
+ * no ratio to meet.
225
+ *
226
+ * An editor can use the list to refuse a pair before it is saved;
227
+ * `drawablePalette` drops what fails.
228
+ *
229
+ * @example
230
+ * paletteFailures({ surfaceColor: "#f8f5f0", textColor: "#2f3440", mutedTextColor: "#5a5f6a" });
231
+ * // []
232
+ * paletteFailures({ surfaceColor: "#1b1d24" });
233
+ * // [{ foreground: "textColor", background: "surfaceColor", ratio: 1.11, needs: 4.5 }, ...]
234
+ */
235
+ export function paletteFailures(palette, drawn = {}) {
236
+ const colors = { ...LIGHT_DRAWN_COLORS, ...drawn };
237
+ const text = palette.textColor ?? colors.text;
238
+ const backgrounds = [
239
+ {
240
+ background: "surfaceColor",
241
+ color: palette.surfaceColor ?? colors.surface,
242
+ },
243
+ { background: "panelColor", color: panelOf(palette, text, colors) },
244
+ ];
245
+ return backgrounds.flatMap(({ background, color }) => {
246
+ const pairs = [
247
+ { foreground: "textColor", color: text, needs: TEXT_CONTRAST },
248
+ {
249
+ foreground: "mutedTextColor",
250
+ color: mutedOn(palette, color, colors),
251
+ needs: TEXT_CONTRAST,
252
+ },
253
+ ...(palette.focusColor
254
+ ? [
255
+ {
256
+ foreground: "focusColor",
257
+ color: palette.focusColor,
258
+ needs: AA_GRAPHIC_CONTRAST,
259
+ },
260
+ ]
261
+ : []),
262
+ ];
263
+ return pairs.flatMap(({ foreground, color: ink, needs }) => {
264
+ const ratio = contrastRatio(ink, color);
265
+ return ratio >= needs
266
+ ? []
267
+ : [{ foreground, background, ratio: floorToHundredths(ratio), needs }];
268
+ });
269
+ });
270
+ }
271
+ /**
272
+ * The part of a chosen palette the page can draw. The card, the panel and the
273
+ * text on them stand or fall together: dropping one alone could leave the
274
+ * rest unreadable (light text kept on a dark card that was dropped), so a
275
+ * failing pair among them leaves the theme's look for all four. The focus
276
+ * ring is then judged on what is kept, and dropped alone. The border needs no
277
+ * ratio.
278
+ */
279
+ export function drawablePalette(chosen, drawn = {}) {
280
+ const { focusColor, borderColor, ...surfacesAndText } = chosen;
281
+ const kept = paletteFailures(surfacesAndText, drawn).length === 0 ? surfacesAndText : {};
282
+ const focusShows = focusColor !== undefined &&
283
+ paletteFailures({ ...kept, focusColor }, drawn).length === 0;
284
+ return {
285
+ ...kept,
286
+ ...(borderColor ? { borderColor } : {}),
287
+ ...(focusShows ? { focusColor } : {}),
288
+ };
289
+ }
290
+ /**
291
+ * The custom properties that draw a brand on the consent screens. Set them on
292
+ * any element above the screens: the screens take a property the page sets
293
+ * over their theme's own.
294
+ *
295
+ * - The brand fills the primary action and the selected checkboxes, with
296
+ * black or white on it, whichever reads.
297
+ * - The tint (`--cs-tint`, `--cs-tint-line`) is the brand over the card.
298
+ * - Marks, actions (and `--consent-link`, the older primitives' links) and
299
+ * the focus ring are the brand where it reads, else the text color.
300
+ * - Icons are the secondary, made darker or lighter to read, when the brand
301
+ * has one.
302
+ * - The page colors are drawn where they read ({@link drawablePalette}).
303
+ *
304
+ * @throws RangeError when a color is not `#rrggbb`.
305
+ *
306
+ * @example
307
+ * brandTokens({ primaryColor: "#1e3a5f" });
308
+ * // { "--consent-primary": "#1e3a5f", "--cs-surface-accent": "#1e3a5f",
309
+ * // "--cs-tint": "#eef0f3", "--cs-mark": "#1e3a5f", ... }
310
+ */
311
+ export function brandTokens(brand) {
312
+ for (const [field, value] of Object.entries(brand)) {
313
+ if (value !== undefined && !isHexColor(value)) {
314
+ throw new RangeError(`${field} must be a #rrggbb color, got ${JSON.stringify(value)}`);
315
+ }
316
+ }
317
+ const { primaryColor: primary, secondaryColor, ...chosen } = brand;
318
+ const palette = drawablePalette(chosen);
319
+ const surface = palette.surfaceColor ?? LIGHT_DRAWN_COLORS.surface;
320
+ const panel = panelOf(palette, palette.textColor ?? LIGHT_DRAWN_COLORS.text, LIGHT_DRAWN_COLORS);
321
+ const ink = palette.textColor ?? LIGHT_DRAWN_COLORS.text;
322
+ const onPrimary = onPrimaryFor(primary);
323
+ const inBrand = (pick) => (pick === "brand" ? primary : ink);
324
+ const tokens = {
325
+ "--consent-primary": primary,
326
+ "--consent-on-primary": onPrimary,
327
+ "--consent-link": inBrand(actionColorFor(primary, surface)),
328
+ "--cs-surface-accent": primary,
329
+ "--cs-surface-accent-text": onPrimary,
330
+ "--cs-tint": mixOver(primary, TINT_PERCENT, surface),
331
+ "--cs-tint-line": mixOver(primary, TINT_LINE_PERCENT, surface),
332
+ "--cs-mark": inBrand(markColorFor(primary, surface)),
333
+ "--cs-action": inBrand(actionColorFor(primary, surface)),
334
+ "--cs-focus-ring": palette.focusColor ?? inBrand(focusRingFor(primary, surface)),
335
+ };
336
+ if (secondaryColor) {
337
+ tokens["--cs-icon"] = iconColorFor(secondaryColor, primary, {
338
+ surface,
339
+ panel,
340
+ });
341
+ }
342
+ if (palette.surfaceColor)
343
+ tokens["--cs-surface-card"] = palette.surfaceColor;
344
+ if (palette.surfaceColor || palette.panelColor)
345
+ tokens["--cs-surface-inset"] = panel;
346
+ if (palette.borderColor)
347
+ tokens["--cs-surface-border"] = palette.borderColor;
348
+ if (palette.textColor) {
349
+ tokens["--cs-text-primary"] = palette.textColor;
350
+ tokens["--cs-text-secondary"] = palette.textColor;
351
+ }
352
+ if (palette.mutedTextColor) {
353
+ tokens["--cs-text-tertiary"] = palette.mutedTextColor;
354
+ }
355
+ else if (palette.textColor) {
356
+ tokens["--cs-text-tertiary"] =
357
+ `color-mix(in srgb, ${palette.textColor} ${MUTED_TEXT_PERCENT}%, transparent)`;
358
+ }
359
+ return tokens;
360
+ }
361
+ /**
362
+ * `brandTokens(brand)` as a declaration list for a style attribute.
363
+ *
364
+ * @example
365
+ * `<main style="${brandStyle({ primaryColor: "#1e3a5f" })}">`
366
+ */
367
+ export function brandStyle(brand) {
368
+ return Object.entries(brandTokens(brand))
369
+ .map(([property, value]) => `${property}: ${value};`)
370
+ .join(" ");
371
+ }
372
+ //# sourceMappingURL=brand.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"brand.js","sourceRoot":"","sources":["../../src/styles/brand.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAC7E,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAEzE,8DAA8D;AAC9D,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC;AACrC,gDAAgD;AAChD,MAAM,aAAa,GAAG,GAAG,CAAC;AAE1B,kDAAkD;AAClD,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC;AACnC,iEAAiE;AACjE,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC;AACrC,wEAAwE;AACxE,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,CAAC;AACrC,oF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CAAC,SAAS,EAAE,CAAC;QAC7B,MAAM,CAAC,oBAAoB,CAAC;YAC1B,sBAAsB,OAAO,CAAC,SAAS,IAAI,kBAAkB,iBAAiB,CAAC;IACnF,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,KAAyB;IAClD,OAAO,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;SACtC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,GAAG,QAAQ,KAAK,KAAK,GAAG,CAAC;SACpD,IAAI,CAAC,GAAG,CAAC,CAAC;AACf,CAAC"}
@@ -11,4 +11,5 @@ export * from "./contrast.js";
11
11
  export * from "./css-variables.js";
12
12
  export * from "./stylesheet.js";
13
13
  export * from "./theme.js";
14
+ export * from "./brand.js";
14
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/styles/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/styles/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}
@@ -11,4 +11,5 @@ export * from "./contrast.js";
11
11
  export * from "./css-variables.js";
12
12
  export * from "./stylesheet.js";
13
13
  export * from "./theme.js";
14
+ export * from "./brand.js";
14
15
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/styles/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/styles/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}
@@ -13,8 +13,8 @@
13
13
  * primary button can adopt operator brand color while the rest of the
14
14
  * surface stays in the chosen theme.
15
15
  *
16
- * The amber `HIGHER RISK` chip token is fixed across themes so the visual
17
- * stays recognizable regardless of org branding.
16
+ * The `HIGHER RISK` chip is amber in both themes, whatever the org's brand:
17
+ * a soft warning amber on the light card, and a solid amber on the dark one.
18
18
  *
19
19
  * The agent logo tile tokens are fixed across themes too: agent artwork is
20
20
  * drawn on a white tile with a light border in both themes, so a logo never
@@ -49,15 +49,7 @@ export interface ConsentThemeTokens {
49
49
  surfaceAccent: string;
50
50
  /** Primary action text color. */
51
51
  surfaceAccentText: string;
52
- /** Verified pill background. */
53
- pillVerifiedBg: string;
54
- /** Verified pill text color. */
55
- pillVerifiedText: string;
56
- /** Unverified pill background. */
57
- pillUnverifiedBg: string;
58
- /** Unverified pill text color. */
59
- pillUnverifiedText: string;
60
- /** HIGHER RISK chip background. Fixed amber across themes. */
52
+ /** HIGHER RISK chip background. Amber in both themes. */
61
53
  chipRiskBg: string;
62
54
  /** HIGHER RISK chip text color. */
63
55
  chipRiskText: string;
@@ -82,7 +74,44 @@ export interface ConsentThemeTokens {
82
74
  * Optional: defaults to `#0F172A` when a theme omits it.
83
75
  */
84
76
  agentTileText?: string;
77
+ /**
78
+ * A light wash of the brand for tinted boxes and the bridge connector's
79
+ * shield. Optional: defaults to the primary text at 7% over the card, a
80
+ * neutral wash, until a brand sets it (`consentBrandStyle`).
81
+ */
82
+ tint?: string;
83
+ /** The edge of a tinted box. Optional: the primary text at 18% over the card. */
84
+ tintLine?: string;
85
+ /**
86
+ * Marks drawn in the brand, such as the bridge connector's shield: a graphic,
87
+ * so it needs 3:1 on the card and the tint. Optional: the primary text.
88
+ */
89
+ mark?: string;
90
+ /**
91
+ * Words drawn in the brand, such as a link that starts a check: text, so it
92
+ * needs 4.5:1 on the card and the tint. Optional: the primary text.
93
+ */
94
+ action?: string;
95
+ /**
96
+ * The Vouched lockup under the capabilities screen's card. Optional: the
97
+ * primary text; the light theme draws it in Vouched blue.
98
+ */
99
+ lockup?: string;
100
+ /**
101
+ * Warning words on the card, such as "Unverified agent": 4.5:1 on the card.
102
+ * Optional: the risk chip's text; the dark theme sets a lighter amber.
103
+ */
104
+ warningText?: string;
85
105
  }
106
+ /** The share of the brand (or the text, with no brand) in a tinted box. */
107
+ export declare const TINT_PERCENT = 7;
108
+ /** The share of the brand (or the text) in a tinted box's edge. */
109
+ export declare const TINT_LINE_PERCENT = 18;
110
+ /**
111
+ * The light theme. Its quietest text reaches 4.5:1 on the cream inset panel
112
+ * (4.54:1) as well as on the card, and its focus ring 3:1 on both, the
113
+ * ratios WCAG 1.4.3 and 1.4.11 ask for.
114
+ */
86
115
  export declare const lightTheme: ConsentThemeTokens;
87
116
  export declare const darkTheme: ConsentThemeTokens;
88
117
  /**
@@ -92,12 +121,43 @@ export declare function getConsentTheme(theme: ConsentTheme | undefined): Consen
92
121
  /**
93
122
  * Render a theme as a CSS string suitable for injecting into a `<style>` block
94
123
  * or `:host { ... }` rule. Each token becomes a `--cs-{kebab}` custom property.
95
- * Agent tile tokens a theme omits (or sets to undefined) are emitted with the
96
- * fixed white tile values, so the output never contains "undefined".
124
+ * Tokens a theme omits (or sets to undefined) are emitted with their fixed or
125
+ * derived values ({@link resolveThemeTokens}), so the output never contains
126
+ * "undefined".
97
127
  *
98
128
  * @example
99
129
  * themeToCssVariables(lightTheme);
100
130
  * // " --cs-surface-bg: #F4F1EA;\n ... \n --cs-agent-tile-bg: #FFFFFF;\n ..."
101
131
  */
102
132
  export declare function themeToCssVariables(tokens: ConsentThemeTokens): string;
133
+ /**
134
+ * Every token of `tokens`, with the optional ones a theme omits filled in:
135
+ * the fixed agent tile, and a tint, mark and action color made from the
136
+ * theme's own text and card.
137
+ */
138
+ export declare function resolveThemeTokens(tokens: ConsentThemeTokens): Required<ConsentThemeTokens>;
139
+ /**
140
+ * The CSS that themes an element's shadow tree while letting the page win: a
141
+ * `--cs-*` property the page sets, on the element or on any ancestor, is used
142
+ * as it is, and every other one comes from `tokens`.
143
+ *
144
+ * The element resolves each token once on `:host`, under a private name
145
+ * (`--_cs-*`), then publishes it under its public name on `scope`, the top
146
+ * elements of its shadow tree, so everything inside reads the public name as
147
+ * before. (The private step is what lets the public name take the page's
148
+ * value: a property cannot refer to itself.) A derived token the page does
149
+ * not set, such as the tint, is made from the resolved tokens, so a page that
150
+ * sets only its text and card colors gets a tint of those.
151
+ *
152
+ * @param tokens - The theme the element draws where the page sets nothing.
153
+ * @param scope - A selector list for the top elements of the shadow tree.
154
+ *
155
+ * @example
156
+ * themeScopeStyle(lightTheme, ".card");
157
+ * // ":host {\n --_cs-surface-bg: var(--cs-surface-bg, #F4F1EA);\n ... }
158
+ * // .card {\n --cs-surface-bg: var(--_cs-surface-bg);\n ... }"
159
+ */
160
+ export declare function themeScopeStyle(tokens: ConsentThemeTokens, scope: string): string;
161
+ /** The custom property a theme key is published as: `tintLine` is `--cs-tint-line`. */
162
+ export declare function themeTokenProperty(key: string): `--cs-${string}`;
103
163
  //# sourceMappingURL=theme.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../src/styles/theme.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;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