@nanahoshi/mona-ui 0.24.10 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (165) hide show
  1. package/README.md +9 -0
  2. package/chart/README.md +223 -77
  3. package/fesm2022/nanahoshi-mona-ui-auto-complete.mjs +11 -10
  4. package/fesm2022/nanahoshi-mona-ui-avatar.mjs +37 -20
  5. package/fesm2022/nanahoshi-mona-ui-breadcrumb.mjs +239 -47
  6. package/fesm2022/nanahoshi-mona-ui-button-group.mjs +184 -31
  7. package/fesm2022/nanahoshi-mona-ui-button.mjs +47 -11
  8. package/fesm2022/nanahoshi-mona-ui-calendar.mjs +17 -13
  9. package/fesm2022/nanahoshi-mona-ui-card.mjs +54 -30
  10. package/fesm2022/nanahoshi-mona-ui-chart.mjs +1909 -666
  11. package/fesm2022/nanahoshi-mona-ui-check-box.mjs +112 -31
  12. package/fesm2022/nanahoshi-mona-ui-chip.mjs +131 -89
  13. package/fesm2022/nanahoshi-mona-ui-circular-progress-bar.mjs +59 -19
  14. package/fesm2022/nanahoshi-mona-ui-collapsible.mjs +118 -41
  15. package/fesm2022/nanahoshi-mona-ui-color-gradient.mjs +243 -212
  16. package/fesm2022/nanahoshi-mona-ui-color-palette.mjs +155 -86
  17. package/fesm2022/nanahoshi-mona-ui-color-picker.mjs +161 -131
  18. package/fesm2022/nanahoshi-mona-ui-combo-box.mjs +12 -11
  19. package/fesm2022/nanahoshi-mona-ui-common.mjs +18 -1
  20. package/fesm2022/nanahoshi-mona-ui-date-picker.mjs +10 -9
  21. package/fesm2022/nanahoshi-mona-ui-datetime-picker.mjs +10 -9
  22. package/fesm2022/nanahoshi-mona-ui-dialog.mjs +2 -2
  23. package/fesm2022/nanahoshi-mona-ui-dropdown-button.mjs +2 -2
  24. package/fesm2022/nanahoshi-mona-ui-dropdown-list.mjs +10 -9
  25. package/fesm2022/nanahoshi-mona-ui-editor.mjs +25 -24
  26. package/fesm2022/nanahoshi-mona-ui-expansion-panel.mjs +202 -33
  27. package/fesm2022/nanahoshi-mona-ui-fieldset.mjs +31 -10
  28. package/fesm2022/nanahoshi-mona-ui-filter.mjs +1 -1
  29. package/fesm2022/{nanahoshi-mona-ui-grid-grid-footer-row.component-DhKLnW06.mjs → nanahoshi-mona-ui-grid-grid-footer-row.component-2tVhD2hK.mjs} +2 -2
  30. package/fesm2022/{nanahoshi-mona-ui-grid-grid-list.component-voGbKOiB.mjs → nanahoshi-mona-ui-grid-grid-list.component-BAN70Wcn.mjs} +4 -4
  31. package/fesm2022/{nanahoshi-mona-ui-grid-grid-row.component-HQ1Kv6R9.mjs → nanahoshi-mona-ui-grid-grid-row.component-C_kCaA5b.mjs} +7 -7
  32. package/fesm2022/{nanahoshi-mona-ui-grid-grid-virtual-list.component-PNLJFcuH.mjs → nanahoshi-mona-ui-grid-grid-virtual-list.component-BsNfrAHz.mjs} +4 -4
  33. package/fesm2022/{nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-BO19AVwC.mjs → nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-CEfVa7eo.mjs} +27 -29
  34. package/fesm2022/nanahoshi-mona-ui-grid.mjs +1 -1
  35. package/fesm2022/nanahoshi-mona-ui-i18n-icu.mjs +146 -5
  36. package/fesm2022/nanahoshi-mona-ui-internal-filter-input.mjs +2 -2
  37. package/fesm2022/nanahoshi-mona-ui-internal-indicator-icon.mjs +1 -1
  38. package/fesm2022/nanahoshi-mona-ui-internal-list.mjs +5 -5
  39. package/fesm2022/nanahoshi-mona-ui-internal-tree.mjs +7 -7
  40. package/fesm2022/nanahoshi-mona-ui-internal.mjs +183 -47
  41. package/fesm2022/nanahoshi-mona-ui-label.mjs +111 -15
  42. package/fesm2022/nanahoshi-mona-ui-list-box.mjs +1 -1
  43. package/fesm2022/nanahoshi-mona-ui-list-view.mjs +1 -1
  44. package/fesm2022/nanahoshi-mona-ui-locales-ar-sa.mjs +111 -5
  45. package/fesm2022/nanahoshi-mona-ui-locales-de-de.mjs +103 -5
  46. package/fesm2022/nanahoshi-mona-ui-locales-es-es.mjs +103 -5
  47. package/fesm2022/nanahoshi-mona-ui-locales-fr-fr.mjs +100 -6
  48. package/fesm2022/nanahoshi-mona-ui-locales-id-id.mjs +90 -5
  49. package/fesm2022/nanahoshi-mona-ui-locales-it-it.mjs +103 -5
  50. package/fesm2022/nanahoshi-mona-ui-locales-ja-jp.mjs +90 -5
  51. package/fesm2022/nanahoshi-mona-ui-locales-ko-kr.mjs +90 -5
  52. package/fesm2022/nanahoshi-mona-ui-locales-pt-br.mjs +103 -5
  53. package/fesm2022/nanahoshi-mona-ui-locales-ru-ru.mjs +105 -5
  54. package/fesm2022/nanahoshi-mona-ui-locales-tr-tr.mjs +103 -5
  55. package/fesm2022/nanahoshi-mona-ui-locales-zh-cn.mjs +90 -5
  56. package/fesm2022/nanahoshi-mona-ui-locales-zh-tw.mjs +90 -5
  57. package/fesm2022/nanahoshi-mona-ui-menubar.mjs +2 -2
  58. package/fesm2022/nanahoshi-mona-ui-multi-select.mjs +14 -13
  59. package/fesm2022/nanahoshi-mona-ui-notification.mjs +1 -1
  60. package/fesm2022/nanahoshi-mona-ui-numeric-text-box.mjs +13 -12
  61. package/fesm2022/nanahoshi-mona-ui-otp-input.mjs +192 -56
  62. package/fesm2022/nanahoshi-mona-ui-pager.mjs +1 -1
  63. package/fesm2022/nanahoshi-mona-ui-placeholder.mjs +3 -1
  64. package/fesm2022/nanahoshi-mona-ui-popup-menu.mjs +2 -2
  65. package/fesm2022/nanahoshi-mona-ui-progress-bar.mjs +60 -29
  66. package/fesm2022/nanahoshi-mona-ui-radio-button.mjs +334 -37
  67. package/fesm2022/nanahoshi-mona-ui-rating.mjs +84 -30
  68. package/fesm2022/nanahoshi-mona-ui-scroll-view.mjs +274 -108
  69. package/fesm2022/nanahoshi-mona-ui-segmented.mjs +127 -37
  70. package/fesm2022/nanahoshi-mona-ui-sheet.mjs +2 -2
  71. package/fesm2022/nanahoshi-mona-ui-sidebar.mjs +595 -170
  72. package/fesm2022/nanahoshi-mona-ui-skeleton.mjs +3 -2
  73. package/fesm2022/nanahoshi-mona-ui-slider.mjs +323 -166
  74. package/fesm2022/nanahoshi-mona-ui-spinner.mjs +167 -82
  75. package/fesm2022/nanahoshi-mona-ui-split-button.mjs +3 -3
  76. package/fesm2022/nanahoshi-mona-ui-splitter.mjs +273 -165
  77. package/fesm2022/nanahoshi-mona-ui-stepper.mjs +219 -132
  78. package/fesm2022/nanahoshi-mona-ui-switch.mjs +84 -32
  79. package/fesm2022/nanahoshi-mona-ui-tabs.mjs +337 -116
  80. package/fesm2022/nanahoshi-mona-ui-text-area.mjs +10 -12
  81. package/fesm2022/nanahoshi-mona-ui-text-box.mjs +21 -8
  82. package/fesm2022/nanahoshi-mona-ui-theme.mjs +444 -88
  83. package/fesm2022/nanahoshi-mona-ui-time-picker.mjs +10 -9
  84. package/fesm2022/nanahoshi-mona-ui-time-selector.mjs +15 -14
  85. package/fesm2022/nanahoshi-mona-ui-tooltip.mjs +17 -3
  86. package/fesm2022/nanahoshi-mona-ui-window.mjs +1 -1
  87. package/i18n/catalogs/en-US.messages.json +90 -5
  88. package/locales/ar-sa/ar-sa.messages.json +90 -5
  89. package/locales/de-de/de-de.messages.json +90 -5
  90. package/locales/es-es/es-es.messages.json +90 -5
  91. package/locales/fr-fr/fr-fr.messages.json +91 -6
  92. package/locales/id-id/id-id.messages.json +90 -5
  93. package/locales/it-it/it-it.messages.json +90 -5
  94. package/locales/ja-jp/ja-jp.messages.json +90 -5
  95. package/locales/ko-kr/ko-kr.messages.json +90 -5
  96. package/locales/pt-br/pt-br.messages.json +90 -5
  97. package/locales/ru-ru/ru-ru.messages.json +90 -5
  98. package/locales/tr-tr/tr-tr.messages.json +90 -5
  99. package/locales/zh-cn/zh-cn.messages.json +90 -5
  100. package/locales/zh-tw/zh-tw.messages.json +90 -5
  101. package/package.json +2 -1
  102. package/styles.css +156 -0
  103. package/types/nanahoshi-mona-ui-auto-complete.d.ts +1 -0
  104. package/types/nanahoshi-mona-ui-avatar.d.ts +18 -11
  105. package/types/nanahoshi-mona-ui-breadcrumb.d.ts +62 -14
  106. package/types/nanahoshi-mona-ui-button-group.d.ts +86 -16
  107. package/types/nanahoshi-mona-ui-button.d.ts +26 -3
  108. package/types/nanahoshi-mona-ui-calendar.d.ts +1 -0
  109. package/types/nanahoshi-mona-ui-card.d.ts +22 -6
  110. package/types/nanahoshi-mona-ui-chart.d.ts +519 -527
  111. package/types/nanahoshi-mona-ui-check-box.d.ts +54 -13
  112. package/types/nanahoshi-mona-ui-chip.d.ts +31 -18
  113. package/types/nanahoshi-mona-ui-circular-progress-bar.d.ts +21 -5
  114. package/types/nanahoshi-mona-ui-collapsible.d.ts +20 -11
  115. package/types/nanahoshi-mona-ui-color-gradient.d.ts +62 -36
  116. package/types/nanahoshi-mona-ui-color-palette.d.ts +65 -27
  117. package/types/nanahoshi-mona-ui-color-picker.d.ts +64 -23
  118. package/types/nanahoshi-mona-ui-combo-box.d.ts +1 -0
  119. package/types/nanahoshi-mona-ui-common.d.ts +28 -2
  120. package/types/nanahoshi-mona-ui-date-picker.d.ts +1 -0
  121. package/types/nanahoshi-mona-ui-datetime-picker.d.ts +1 -0
  122. package/types/nanahoshi-mona-ui-dropdown-list.d.ts +1 -0
  123. package/types/nanahoshi-mona-ui-editor.d.ts +1 -0
  124. package/types/nanahoshi-mona-ui-expansion-panel.d.ts +51 -7
  125. package/types/nanahoshi-mona-ui-fieldset.d.ts +18 -4
  126. package/types/nanahoshi-mona-ui-grid.d.ts +0 -1
  127. package/types/nanahoshi-mona-ui-i18n.d.ts +130 -3
  128. package/types/nanahoshi-mona-ui-internal.d.ts +95 -14
  129. package/types/nanahoshi-mona-ui-label.d.ts +17 -2
  130. package/types/nanahoshi-mona-ui-locales-ar-sa.d.ts +85 -0
  131. package/types/nanahoshi-mona-ui-locales-de-de.d.ts +85 -0
  132. package/types/nanahoshi-mona-ui-locales-es-es.d.ts +85 -0
  133. package/types/nanahoshi-mona-ui-locales-fr-fr.d.ts +85 -0
  134. package/types/nanahoshi-mona-ui-locales-id-id.d.ts +85 -0
  135. package/types/nanahoshi-mona-ui-locales-it-it.d.ts +85 -0
  136. package/types/nanahoshi-mona-ui-locales-ja-jp.d.ts +85 -0
  137. package/types/nanahoshi-mona-ui-locales-ko-kr.d.ts +85 -0
  138. package/types/nanahoshi-mona-ui-locales-pt-br.d.ts +85 -0
  139. package/types/nanahoshi-mona-ui-locales-ru-ru.d.ts +85 -0
  140. package/types/nanahoshi-mona-ui-locales-tr-tr.d.ts +85 -0
  141. package/types/nanahoshi-mona-ui-locales-zh-cn.d.ts +85 -0
  142. package/types/nanahoshi-mona-ui-locales-zh-tw.d.ts +85 -0
  143. package/types/nanahoshi-mona-ui-multi-select.d.ts +1 -0
  144. package/types/nanahoshi-mona-ui-numeric-text-box.d.ts +1 -0
  145. package/types/nanahoshi-mona-ui-otp-input.d.ts +49 -12
  146. package/types/nanahoshi-mona-ui-placeholder.d.ts +2 -1
  147. package/types/nanahoshi-mona-ui-progress-bar.d.ts +21 -9
  148. package/types/nanahoshi-mona-ui-radio-button.d.ts +165 -20
  149. package/types/nanahoshi-mona-ui-rating.d.ts +21 -6
  150. package/types/nanahoshi-mona-ui-scroll-view.d.ts +59 -27
  151. package/types/nanahoshi-mona-ui-segmented.d.ts +52 -24
  152. package/types/nanahoshi-mona-ui-sidebar.d.ts +104 -41
  153. package/types/nanahoshi-mona-ui-skeleton.d.ts +1 -1
  154. package/types/nanahoshi-mona-ui-slider.d.ts +99 -35
  155. package/types/nanahoshi-mona-ui-spinner.d.ts +9 -5
  156. package/types/nanahoshi-mona-ui-splitter.d.ts +31 -10
  157. package/types/nanahoshi-mona-ui-stepper.d.ts +58 -12
  158. package/types/nanahoshi-mona-ui-switch.d.ts +32 -10
  159. package/types/nanahoshi-mona-ui-tabs.d.ts +75 -20
  160. package/types/nanahoshi-mona-ui-text-area.d.ts +7 -7
  161. package/types/nanahoshi-mona-ui-text-box.d.ts +2 -0
  162. package/types/nanahoshi-mona-ui-theme.d.ts +392 -15
  163. package/types/nanahoshi-mona-ui-time-picker.d.ts +1 -0
  164. package/types/nanahoshi-mona-ui-time-selector.d.ts +1 -0
  165. package/types/nanahoshi-mona-ui-tooltip.d.ts +7 -1
@@ -1,6 +1,7 @@
1
1
  import * as i0 from '@angular/core';
2
- import { InjectionToken, inject, DOCUMENT, DestroyRef, signal, computed, Injectable, makeEnvironmentProviders } from '@angular/core';
2
+ import { isDevMode, InjectionToken, inject, DOCUMENT, PLATFORM_ID, signal, DestroyRef, Injector, computed, Injectable, provideEnvironmentInitializer, makeEnvironmentProviders } from '@angular/core';
3
3
  import { converter, parse, wcagContrast, clampChroma } from 'culori';
4
+ import { isPlatformBrowser } from '@angular/common';
4
5
 
5
6
  function flattenThemeProfile(profile) {
6
7
  return {
@@ -258,13 +259,13 @@ const dark$5 = Object.freeze({
258
259
  "--color-card": "var(--color-surface-raised)",
259
260
  "--color-card-foreground": "var(--color-foreground)",
260
261
  "--color-foreground": "#D6D6D8",
261
- "--color-muted-foreground": "#A8A8AD",
262
+ "--color-muted-foreground": "#B4B4B9",
262
263
  "--color-input-background": "#1D1E20",
263
264
  "--color-input-foreground": "var(--color-foreground)",
264
265
  "--color-border-subtle": "#0F0F10",
265
266
  "--color-border": "#131416",
266
- "--color-border-control": "#0F0F10",
267
- "--color-border-control-hover": "#17181A",
267
+ "--color-border-control": "#6F7077",
268
+ "--color-border-control-hover": "#818289",
268
269
  "--color-hover": "#242528",
269
270
  "--color-active": "#2A2B2E",
270
271
  "--color-disabled-foreground": "#9A9AA0",
@@ -300,9 +301,9 @@ const dark$5 = Object.freeze({
300
301
  "--color-selected-active-foreground": "var(--color-foreground)",
301
302
  "--color-selected-focus": "var(--color-primary)",
302
303
  "--color-selected-focus-foreground": "var(--color-primary-foreground)",
303
- "--color-selected-border": "var(--color-border-subtle)",
304
+ "--color-selected-border": "var(--color-focus-indicator)",
304
305
  "--color-focus-surface": "var(--color-surface)",
305
- "--color-focus-indicator": "#A174C2",
306
+ "--color-focus-indicator": "#BC94DB",
306
307
  "--color-background": "var(--color-surface)",
307
308
  "--color-background-dark": "var(--color-surface-muted)",
308
309
  "--color-header-background": "var(--color-surface-muted)",
@@ -321,13 +322,13 @@ const dark$5 = Object.freeze({
321
322
  // the same relationship its scrollbar track and popovers use.
322
323
  ...createSidebarColorRoles({ background: "var(--color-surface-muted)" }),
323
324
  "--color-chart-1": "#A174C2",
324
- "--color-chart-2": "#6F4A8A",
325
+ "--color-chart-2": "#C39BDF",
325
326
  "--color-chart-3": "#4DA3FF",
326
327
  "--color-chart-4": "#32BEA6",
327
328
  "--color-chart-5": "#FFDA6B",
328
- "--color-scrollbar-thumb": "#34353A",
329
- "--color-scrollbar-thumb-hover": "#4A4B51",
330
- "--color-scrollbar-thumb-active": "#62636A",
329
+ "--color-scrollbar-thumb": "#686970",
330
+ "--color-scrollbar-thumb-hover": "#7B7C83",
331
+ "--color-scrollbar-thumb-active": "#94959C",
331
332
  "--color-scrollbar-thumb-focus": "var(--color-focus-indicator)",
332
333
  "--color-scrollbar-track": "#161718",
333
334
  "--color-scrollbar-track-hover": "#1D1E20",
@@ -367,6 +368,12 @@ const annaTheme = Object.freeze({
367
368
  dark: Object.freeze({
368
369
  colors: annaThemeColors.dark,
369
370
  components,
371
+ // The violet fill is 1.73:1 on Anna's surface, which is fine under a label and not as the only thing
372
+ // showing a value. What's drawn by a fill alone takes the lighter violet instead.
373
+ custom: Object.freeze({
374
+ "--mona-indicator-color": "var(--color-primary-border)",
375
+ "--mona-indicator-foreground": "#161718"
376
+ }),
370
377
  effects: createDefaultThemeEffects(),
371
378
  motion: motion$1,
372
379
  shape: createDefaultThemeShape(),
@@ -392,16 +399,16 @@ const light$3 = Object.freeze({
392
399
  "--color-card": "var(--mona-effect-raised-background-color)",
393
400
  "--color-card-foreground": "var(--color-foreground)",
394
401
  "--color-foreground": "#252525",
395
- "--color-muted-foreground": "#6f7074",
402
+ "--color-muted-foreground": "#626367",
396
403
  "--color-input-background": "#f3f4f5",
397
404
  "--color-input-foreground": "var(--color-foreground)",
398
405
  "--color-border-subtle": "#eeeeef",
399
406
  "--color-border": "#e4e4e6",
400
- "--color-border-control": "#d5d6d9",
401
- "--color-border-control-hover": "#c5c6ca",
407
+ "--color-border-control": "#8a8b90",
408
+ "--color-border-control-hover": "#76777c",
402
409
  "--color-hover": "#ecedef",
403
410
  "--color-active": "#e2e3e6",
404
- "--color-disabled-foreground": "#77787c",
411
+ "--color-disabled-foreground": "#68696d",
405
412
  "--color-disabled-background": "#f0f0f1",
406
413
  "--color-disabled-border": "#e4e4e6",
407
414
  ...generatedRoles$1.light,
@@ -451,9 +458,9 @@ const light$3 = Object.freeze({
451
458
  "--color-chart-3": "#4f8a70",
452
459
  "--color-chart-4": "#b37a2b",
453
460
  "--color-chart-5": "#c55d5d",
454
- "--color-scrollbar-thumb": "#b7b8bc",
455
- "--color-scrollbar-thumb-hover": "#94969b",
456
- "--color-scrollbar-thumb-active": "#74767b",
461
+ "--color-scrollbar-thumb": "#8a8b90",
462
+ "--color-scrollbar-thumb-hover": "#76777c",
463
+ "--color-scrollbar-thumb-active": "#626367",
457
464
  "--color-scrollbar-thumb-focus": "var(--color-focus-indicator)",
458
465
  "--color-scrollbar-track": "var(--color-canvas)",
459
466
  "--color-scrollbar-track-hover": "var(--color-surface-muted)",
@@ -475,11 +482,11 @@ const dark$3 = Object.freeze({
475
482
  "--color-input-foreground": "var(--color-foreground)",
476
483
  "--color-border-subtle": "#303033",
477
484
  "--color-border": "#39393d",
478
- "--color-border-control": "#494a4f",
479
- "--color-border-control-hover": "#5a5b61",
485
+ "--color-border-control": "#74757a",
486
+ "--color-border-control-hover": "#85868c",
480
487
  "--color-hover": "#2f2f32",
481
488
  "--color-active": "#3a3a3e",
482
- "--color-disabled-foreground": "#85868b",
489
+ "--color-disabled-foreground": "#8f9095",
483
490
  "--color-disabled-background": "#222224",
484
491
  "--color-disabled-border": "#36363a",
485
492
  ...generatedRoles$1.dark,
@@ -528,9 +535,9 @@ const dark$3 = Object.freeze({
528
535
  "--color-chart-3": "#70aa8e",
529
536
  "--color-chart-4": "#d09a4c",
530
537
  "--color-chart-5": "#de7c7c",
531
- "--color-scrollbar-thumb": "#55565b",
532
- "--color-scrollbar-thumb-hover": "#73747a",
533
- "--color-scrollbar-thumb-active": "#929399",
538
+ "--color-scrollbar-thumb": "#707176",
539
+ "--color-scrollbar-thumb-hover": "#85868c",
540
+ "--color-scrollbar-thumb-active": "#9a9ba1",
534
541
  "--color-scrollbar-thumb-focus": "var(--color-focus-indicator)",
535
542
  "--color-scrollbar-track": "var(--color-canvas)",
536
543
  "--color-scrollbar-track-hover": "var(--color-surface-muted)",
@@ -719,13 +726,13 @@ const light$1 = Object.freeze({
719
726
  "--color-card": "var(--color-surface-raised)",
720
727
  "--color-card-foreground": "var(--color-foreground)",
721
728
  "--color-foreground": "oklch(14.1% 0.005 285.823)",
722
- "--color-muted-foreground": "oklch(55.2% 0.016 285.938)",
729
+ "--color-muted-foreground": "oklch(50% 0.016 285.938)",
723
730
  "--color-input-background": "oklch(100% 0 0)",
724
731
  "--color-input-foreground": "var(--color-foreground)",
725
732
  "--color-border-subtle": "oklch(94% 0.002 286.320)",
726
733
  "--color-border": "oklch(92.2% 0.004 286.320)",
727
- "--color-border-control": "oklch(87.1% 0.006 286.286)",
728
- "--color-border-control-hover": "oklch(80.5% 0.008 286.067)",
734
+ "--color-border-control": "oklch(64% 0.010 286.067)",
735
+ "--color-border-control-hover": "oklch(55.2% 0.010 285.938)",
729
736
  "--color-hover": "oklch(96.7% 0.001 286.375)",
730
737
  "--color-active": "oklch(92.2% 0.004 286.320)",
731
738
  "--color-disabled-foreground": "oklch(46% 0.010 285.938)",
@@ -761,13 +768,13 @@ const light$1 = Object.freeze({
761
768
  // rather than as another card.
762
769
  ...createSidebarColorRoles({ background: "var(--color-canvas)" }),
763
770
  "--color-chart-1": "oklch(20.5% 0.006 285.885)",
764
- "--color-chart-2": "oklch(37.1% 0.008 285.805)",
765
- "--color-chart-3": "oklch(55.2% 0.010 285.938)",
766
- "--color-chart-4": "oklch(70.5% 0.010 286.067)",
767
- "--color-chart-5": "oklch(87.1% 0.006 286.286)",
768
- "--color-scrollbar-thumb": "oklch(80.5% 0.008 286.067)",
769
- "--color-scrollbar-thumb-hover": "oklch(70.5% 0.010 286.067)",
770
- "--color-scrollbar-thumb-active": "oklch(55.2% 0.010 285.938)",
771
+ "--color-chart-2": "oklch(34% 0.008 285.805)",
772
+ "--color-chart-3": "oklch(46% 0.010 285.938)",
773
+ "--color-chart-4": "oklch(55.2% 0.010 285.938)",
774
+ "--color-chart-5": "oklch(63% 0.010 286.067)",
775
+ "--color-scrollbar-thumb": "oklch(64% 0.010 286.067)",
776
+ "--color-scrollbar-thumb-hover": "oklch(55.2% 0.010 285.938)",
777
+ "--color-scrollbar-thumb-active": "oklch(46% 0.010 285.938)",
771
778
  "--color-scrollbar-thumb-focus": "var(--color-primary)",
772
779
  "--color-scrollbar-track": "var(--color-canvas)",
773
780
  "--color-scrollbar-track-hover": "var(--color-surface-muted)",
@@ -784,13 +791,13 @@ const dark$1 = Object.freeze({
784
791
  "--color-card": "var(--color-surface-raised)",
785
792
  "--color-card-foreground": "var(--color-foreground)",
786
793
  "--color-foreground": "oklch(98.5% 0 0)",
787
- "--color-muted-foreground": "oklch(70.5% 0.015 286.067)",
794
+ "--color-muted-foreground": "oklch(75% 0.015 286.067)",
788
795
  "--color-input-background": "oklch(20.5% 0.006 285.885)",
789
796
  "--color-input-foreground": "var(--color-foreground)",
790
797
  "--color-border-subtle": "oklch(24% 0.006 286.033)",
791
798
  "--color-border": "oklch(30% 0.007 286.033)",
792
- "--color-border-control": "oklch(32% 0.008 285.938)",
793
- "--color-border-control-hover": "oklch(37.1% 0.008 285.805)",
799
+ "--color-border-control": "oklch(56% 0.010 286.067)",
800
+ "--color-border-control-hover": "oklch(65% 0.010 286.067)",
794
801
  "--color-hover": "oklch(32% 0.007 286.033)",
795
802
  "--color-active": "oklch(37.1% 0.008 285.805)",
796
803
  "--color-disabled-foreground": "oklch(70.5% 0.010 286.067)",
@@ -828,11 +835,11 @@ const dark$1 = Object.freeze({
828
835
  "--color-chart-1": "oklch(92.2% 0.004 286.320)",
829
836
  "--color-chart-2": "oklch(80.5% 0.008 286.067)",
830
837
  "--color-chart-3": "oklch(70.5% 0.010 286.067)",
831
- "--color-chart-4": "oklch(55.2% 0.010 285.938)",
832
- "--color-chart-5": "oklch(43.9% 0.010 285.938)",
833
- "--color-scrollbar-thumb": "oklch(37.1% 0.008 285.805)",
834
- "--color-scrollbar-thumb-hover": "oklch(52% 0.010 285.938)",
835
- "--color-scrollbar-thumb-active": "oklch(65% 0.010 286.067)",
838
+ "--color-chart-4": "oklch(62% 0.010 286.067)",
839
+ "--color-chart-5": "oklch(54% 0.010 285.938)",
840
+ "--color-scrollbar-thumb": "oklch(54% 0.010 285.938)",
841
+ "--color-scrollbar-thumb-hover": "oklch(62% 0.010 286.067)",
842
+ "--color-scrollbar-thumb-active": "oklch(70.5% 0.010 286.067)",
836
843
  "--color-scrollbar-thumb-focus": "var(--color-primary)",
837
844
  "--color-scrollbar-track": "var(--color-canvas)",
838
845
  "--color-scrollbar-track-hover": "var(--color-surface-muted)",
@@ -901,6 +908,60 @@ const builtInThemes = Object.freeze({
901
908
  mona: monaTheme
902
909
  });
903
910
 
911
+ /** The pairs a theme has to get right for the library to meet WCAG AA, and the contrast each needs. */
912
+ const contrastPairs = [
913
+ ["--color-foreground", "--color-surface", 4.5],
914
+ ["--color-muted-foreground", "--color-surface", 4.5],
915
+ ["--color-input-foreground", "--color-input-background", 4.5],
916
+ ["--color-primary-foreground", "--color-primary", 4.5],
917
+ ["--color-border-control", "--color-input-background", 3],
918
+ ["--color-focus-indicator", "--color-surface", 3],
919
+ ["--color-selected-border", "--color-surface", 3]
920
+ ];
921
+ /**
922
+ * What's wrong with a theme's colors, as sentences. Only for development: an invalid value fails silently where
923
+ * it's used, far from where it was written. Values this can't read, such as `color-mix()` or a variable from
924
+ * outside the color tokens, aren't reported, because they may well be right.
925
+ */
926
+ function findThemeProblems(name, variant, profile) {
927
+ const colors = profile.colors;
928
+ const problems = [];
929
+ const unreadable = Object.entries(colors)
930
+ .filter(([, value]) => !value.includes("(") && value.toLowerCase() !== "currentcolor" && !parse(value))
931
+ .map(([token, value]) => `${token}: "${value}"`);
932
+ if (unreadable.length > 0) {
933
+ problems.push(`Theme "${name}" (${variant}) has values that aren't colors: ${unreadable.join(", ")}.`);
934
+ }
935
+ for (const [foreground, background, minimum] of contrastPairs) {
936
+ const first = resolveColor(colors, foreground);
937
+ const second = resolveColor(colors, background);
938
+ if (first && second && parse(first) && parse(second)) {
939
+ const contrast = wcagContrast(first, second);
940
+ if (contrast < minimum) {
941
+ problems.push(`Theme "${name}" (${variant}): ${foreground} on ${background} is ${contrast.toFixed(2)}:1, and WCAG AA needs ${minimum}:1.`);
942
+ }
943
+ }
944
+ }
945
+ const custom = Object.keys(profile.custom ?? {}).filter(key => !key.startsWith("--"));
946
+ if (custom.length > 0) {
947
+ problems.push(`Theme "${name}" (${variant}) has custom variables without "--": ${custom.join(", ")}.`);
948
+ }
949
+ return problems;
950
+ }
951
+ function resolveColor(colors, token) {
952
+ const seen = new Set();
953
+ let value = colors[token];
954
+ while (value !== undefined && !seen.has(value)) {
955
+ seen.add(value);
956
+ const alias = /^var\((--[^),]+)\)$/.exec(value.trim());
957
+ if (!alias) {
958
+ return value;
959
+ }
960
+ value = colors[alias[1]];
961
+ }
962
+ return undefined;
963
+ }
964
+
904
965
  class DefaultThemeStrategy {
905
966
  #overrides;
906
967
  #themes = new Map();
@@ -920,7 +981,7 @@ class DefaultThemeStrategy {
920
981
  throw new Error(`Cannot override unknown Mona UI theme "${override.theme}".`);
921
982
  }
922
983
  for (const variant of ["light", "dark"]) {
923
- if (override[variant] && !family.variants[variant]) {
984
+ if (override[variant] && !family.variants[variant] && !override.generated) {
924
985
  throw new Error(`Cannot override undeclared "${variant}" variant of Mona UI theme "${override.theme}".`);
925
986
  }
926
987
  }
@@ -929,6 +990,15 @@ class DefaultThemeStrategy {
929
990
  validateCustomVariables(override.theme, override.dark?.custom);
930
991
  }
931
992
  this.#overrides = overrides;
993
+ if (isDevMode()) {
994
+ this.#reportProblems(registrations, overrides);
995
+ }
996
+ }
997
+ availableThemes() {
998
+ return [...this.#themes.values()].map(theme => Object.freeze({
999
+ name: theme.name,
1000
+ variants: Object.freeze(getDefinedVariants(theme).map(([variant]) => variant))
1001
+ }));
932
1002
  }
933
1003
  resolve(selection) {
934
1004
  const family = this.#themes.get(selection.name);
@@ -952,6 +1022,9 @@ class DefaultThemeStrategy {
952
1022
  if (!registration.name.trim()) {
953
1023
  throw new Error("Mona UI theme names cannot be empty.");
954
1024
  }
1025
+ if (/\s/.test(registration.name)) {
1026
+ throw new Error(`Mona UI theme name "${registration.name}" cannot contain whitespace.`);
1027
+ }
955
1028
  if (this.#themes.has(registration.name)) {
956
1029
  throw new Error(`Mona UI theme "${registration.name}" is already registered.`);
957
1030
  }
@@ -964,6 +1037,17 @@ class DefaultThemeStrategy {
964
1037
  }
965
1038
  this.#themes.set(registration.name, registration);
966
1039
  }
1040
+ /** Custom themes, and built-in ones as overridden. The built-in ones as written have specs of their own. */
1041
+ #reportProblems(registrations, overrides) {
1042
+ const names = new Set([...registrations.map(({ name }) => name), ...overrides.map(({ theme }) => theme)]);
1043
+ for (const name of names) {
1044
+ for (const [variant] of getDefinedVariants(this.#themes.get(name))) {
1045
+ for (const problem of findThemeProblems(name, variant, this.resolve({ name, variant }))) {
1046
+ console.warn(`Mona UI: ${problem}`);
1047
+ }
1048
+ }
1049
+ }
1050
+ }
967
1051
  }
968
1052
  function getDefinedVariants(registration) {
969
1053
  const entries = Object.entries(registration.variants);
@@ -1012,58 +1096,161 @@ function validateCustomVariables(name, custom) {
1012
1096
  }
1013
1097
  }
1014
1098
 
1099
+ /**
1100
+ * The default `ThemeStorage`: `localStorage`, as JSON, under the `persistKey`.
1101
+ *
1102
+ * Reads report `null` anywhere `localStorage` can't answer, and writes are dropped there. That covers the
1103
+ * server, a browser that refuses it, and a full quota. `ThemeService` checks what comes back, so a value that
1104
+ * isn't a preference, or names a theme that's gone, counts as nothing stored.
1105
+ *
1106
+ * A server-rendered application gets `initialTheme` in its markup and the remembered theme on hydration, which
1107
+ * shows as a flash. Storage that the server can read too, such as a cookie, avoids it; supply it through
1108
+ * `provideThemeStorage()`.
1109
+ */
1110
+ class LocalStorageThemeStorage {
1111
+ #browser;
1112
+ /** Takes the value of `PLATFORM_ID`, which is a string in practice though typed loosely. */
1113
+ constructor(platformId) {
1114
+ this.#browser = isPlatformBrowser(platformId);
1115
+ }
1116
+ read(key) {
1117
+ if (!this.#browser) {
1118
+ return null;
1119
+ }
1120
+ try {
1121
+ const stored = localStorage.getItem(key);
1122
+ return stored === null ? null : JSON.parse(stored);
1123
+ }
1124
+ catch {
1125
+ return null;
1126
+ }
1127
+ }
1128
+ write(key, preference) {
1129
+ if (!this.#browser) {
1130
+ return;
1131
+ }
1132
+ try {
1133
+ localStorage.setItem(key, JSON.stringify(preference));
1134
+ }
1135
+ catch {
1136
+ // Nothing to recover: the theme still applies, it just won't be remembered.
1137
+ }
1138
+ }
1139
+ }
1140
+
1015
1141
  const THEME_FAMILY_REGISTRATIONS = new InjectionToken("Mona UI theme family registrations");
1016
1142
  const THEME_OVERRIDE_REGISTRATIONS = new InjectionToken("Mona UI theme override registrations");
1017
1143
  const THEME_OPTIONS = new InjectionToken("Mona UI theme options", {
1018
1144
  providedIn: "root",
1019
1145
  factory: () => ({ initialTheme: { name: "mona", variant: "light" } })
1020
1146
  });
1147
+ /**
1148
+ * The element the theme is written to. Defaults to `<html>`. Replace it with `provideThemeRoot()`.
1149
+ */
1150
+ const THEME_ROOT = new InjectionToken("Mona UI theme root", {
1151
+ providedIn: "root",
1152
+ factory: () => inject(DOCUMENT).documentElement ?? null
1153
+ });
1154
+ /**
1155
+ * Where the theme is remembered when `provideThemeOptions()` has a `persistKey`. Defaults to `localStorage`.
1156
+ * Replace it with `provideThemeStorage()`.
1157
+ */
1158
+ const THEME_STORAGE = new InjectionToken("Mona UI theme storage", {
1159
+ providedIn: "root",
1160
+ factory: () => new LocalStorageThemeStorage(inject(PLATFORM_ID))
1161
+ });
1021
1162
  const THEME_STRATEGY = new InjectionToken("Mona UI theme strategy", {
1022
1163
  providedIn: "root",
1023
1164
  factory: () => new DefaultThemeStrategy(inject(THEME_FAMILY_REGISTRATIONS, { optional: true }) ?? [], inject(THEME_OVERRIDE_REGISTRATIONS, { optional: true }) ?? [])
1024
1165
  });
1025
1166
 
1167
+ /** Which service last wrote to an element, so that a second one can be reported and neither clears the other. */
1168
+ const themeWriters = new WeakMap();
1026
1169
  class ThemeService {
1170
+ #activeColorPaletteSeeds;
1171
+ #activePreference;
1172
+ #activeProfile;
1173
+ #activeSelection;
1027
1174
  #appliedVariables;
1028
- #document;
1175
+ #colorSchemeQuery;
1029
1176
  #destroyRef;
1030
- #initialSelection;
1177
+ #document;
1178
+ #injector;
1179
+ #options;
1180
+ #root;
1181
+ #storage;
1031
1182
  #strategy;
1032
- #activeSelection;
1033
- #activeProfile;
1034
- #activeColorPaletteSeeds;
1035
1183
  #transparencyQuery;
1184
+ #knownStored;
1036
1185
  #runtimeColorPalette;
1186
+ /** The root, and the overlay container for a root inside the page, since overlays render outside it. */
1187
+ #targets;
1037
1188
  constructor() {
1189
+ this.#activeColorPaletteSeeds = signal(null, /* @ts-ignore */
1190
+ ...(ngDevMode ? [{ debugName: "#activeColorPaletteSeeds" }] : /* istanbul ignore next */ []));
1038
1191
  this.#appliedVariables = new Set();
1039
- this.#document = inject(DOCUMENT);
1040
1192
  this.#destroyRef = inject(DestroyRef);
1041
- this.#initialSelection = normalizeSelection(inject(THEME_OPTIONS).initialTheme);
1193
+ this.#document = inject(DOCUMENT);
1194
+ this.#injector = inject(Injector);
1195
+ this.#options = inject(THEME_OPTIONS);
1196
+ this.#root = inject(THEME_ROOT);
1042
1197
  this.#strategy = inject(THEME_STRATEGY);
1043
- this.#activeSelection = signal(this.#initialSelection, /* @ts-ignore */
1044
- ...(ngDevMode ? [{ debugName: "#activeSelection" }] : /* istanbul ignore next */ []));
1045
- this.#activeProfile = signal(this.#strategy.resolve(this.#initialSelection), /* @ts-ignore */
1046
- ...(ngDevMode ? [{ debugName: "#activeProfile" }] : /* istanbul ignore next */ []));
1047
- this.#activeColorPaletteSeeds = signal(null, /* @ts-ignore */
1048
- ...(ngDevMode ? [{ debugName: "#activeColorPaletteSeeds" }] : /* istanbul ignore next */ []));
1049
- this.#transparencyQuery = this.#document.defaultView?.matchMedia?.("(prefers-reduced-transparency: reduce)");
1198
+ this.#knownStored = null;
1050
1199
  this.#runtimeColorPalette = null;
1200
+ /** The root, and the overlay container for a root inside the page, since overlays render outside it. */
1201
+ this.#targets = [];
1051
1202
  /** The consumer-provided seeds for the active runtime color palette, or `null` when provider defaults are active. */
1052
1203
  this.colorPaletteSeeds = this.#activeColorPaletteSeeds.asReadonly();
1053
- this.profile = this.#activeProfile.asReadonly();
1054
- this.selection = this.#activeSelection.asReadonly();
1055
1204
  this.themeName = computed(() => this.#activeSelection().name, /* @ts-ignore */
1056
1205
  ...(ngDevMode ? [{ debugName: "themeName" }] : /* istanbul ignore next */ []));
1057
1206
  this.themeVariant = computed(() => this.#activeSelection().variant, /* @ts-ignore */
1058
1207
  ...(ngDevMode ? [{ debugName: "themeVariant" }] : /* istanbul ignore next */ []));
1059
- this.#applyTheme(this.#initialSelection, this.#activeProfile());
1060
- const query = this.#transparencyQuery;
1061
- if (query) {
1208
+ const view = this.#document.defaultView;
1209
+ this.#colorSchemeQuery = view?.matchMedia?.("(prefers-color-scheme: dark)");
1210
+ this.#transparencyQuery = view?.matchMedia?.("(prefers-reduced-transparency: reduce)");
1211
+ this.#storage = this.#options.persistKey ? inject(THEME_STORAGE) : null;
1212
+ this.#targets = this.#root ? [this.#root] : [];
1213
+ const preference = this.#readStoredPreference() ?? normalizePreference(this.#options.initialTheme);
1214
+ const selection = this.#resolveSelection(preference);
1215
+ this.#activePreference = signal(preference, /* @ts-ignore */
1216
+ ...(ngDevMode ? [{ debugName: "#activePreference" }] : /* istanbul ignore next */ []));
1217
+ this.#activeSelection = signal(selection, /* @ts-ignore */
1218
+ ...(ngDevMode ? [{ debugName: "#activeSelection" }] : /* istanbul ignore next */ []));
1219
+ this.#activeProfile = signal(this.#strategy.resolve(selection), /* @ts-ignore */
1220
+ ...(ngDevMode ? [{ debugName: "#activeProfile" }] : /* istanbul ignore next */ []));
1221
+ this.preference = this.#activePreference.asReadonly();
1222
+ this.profile = this.#activeProfile.asReadonly();
1223
+ this.selection = this.#activeSelection.asReadonly();
1224
+ this.#claimRoot();
1225
+ this.#applyTheme(selection, this.#activeProfile());
1226
+ this.#destroyRef.onDestroy(() => this.#releaseRoot());
1227
+ if (this.#root && this.#root !== this.#document.documentElement) {
1228
+ this.#themeOverlayContainer();
1229
+ }
1230
+ const transparencyQuery = this.#transparencyQuery;
1231
+ if (transparencyQuery) {
1062
1232
  const onPreferenceChange = () => this.#applyTheme(this.#activeSelection(), this.#activeProfile());
1063
- query.addEventListener("change", onPreferenceChange);
1064
- this.#destroyRef.onDestroy(() => query.removeEventListener("change", onPreferenceChange));
1233
+ transparencyQuery.addEventListener("change", onPreferenceChange);
1234
+ this.#destroyRef.onDestroy(() => transparencyQuery.removeEventListener("change", onPreferenceChange));
1235
+ }
1236
+ const colorSchemeQuery = this.#colorSchemeQuery;
1237
+ if (colorSchemeQuery) {
1238
+ const onColorSchemeChange = () => {
1239
+ if (this.#activePreference().variant === "system") {
1240
+ this.#select(this.#activePreference());
1241
+ }
1242
+ };
1243
+ colorSchemeQuery.addEventListener("change", onColorSchemeChange);
1244
+ this.#destroyRef.onDestroy(() => colorSchemeQuery.removeEventListener("change", onColorSchemeChange));
1065
1245
  }
1066
1246
  }
1247
+ /**
1248
+ * The registered themes and the variants each one has. A custom `ThemeStrategy` reports them through its
1249
+ * optional `availableThemes()`, and this is empty for one that doesn't.
1250
+ */
1251
+ availableThemes() {
1252
+ return this.#strategy.availableThemes?.() ?? [];
1253
+ }
1067
1254
  /** Removes the runtime color palette and restores the registered profile and provider overrides. */
1068
1255
  clearColorPalette() {
1069
1256
  const selection = this.#activeSelection();
@@ -1092,47 +1279,161 @@ class ThemeService {
1092
1279
  setPrimaryColor(primary) {
1093
1280
  this.setColorPalette({ ...(this.#activeColorPaletteSeeds() ?? {}), primary });
1094
1281
  }
1095
- setTheme(selection) {
1096
- const normalized = normalizeSelection(selection);
1097
- const profile = this.#resolveProfile(normalized);
1098
- this.#applyTheme(normalized, profile);
1099
- this.#activeProfile.set(profile);
1100
- this.#activeSelection.set(normalized);
1282
+ /**
1283
+ * Switches the theme, and remembers it if a `persistKey` was given. `"system"` follows the operating system's
1284
+ * setting from then on, and takes the variant a theme has when it only has one.
1285
+ * @throws if the theme isn't registered, or doesn't have the variant asked for
1286
+ */
1287
+ setTheme(preference) {
1288
+ const normalized = normalizePreference(preference);
1289
+ this.#select(normalized);
1290
+ this.#activePreference.set(normalized);
1291
+ this.#writeStoredPreference(normalized);
1101
1292
  }
1102
- #applyTheme(selection, profile) {
1103
- const root = this.#document.documentElement;
1104
- if (!root) {
1105
- return;
1293
+ /** Whether `setTheme` would accept this. A saved choice can be checked with it before it's restored. */
1294
+ supportsVariant(name, variant) {
1295
+ try {
1296
+ this.#strategy.resolve({ name, variant });
1297
+ return true;
1298
+ }
1299
+ catch {
1300
+ return false;
1106
1301
  }
1302
+ }
1303
+ #applyTheme(selection, profile) {
1107
1304
  const transparency = this.#getTransparencyMode();
1108
1305
  const variables = getEffectiveVariables(profile, transparency);
1109
- for (const previousName of this.#appliedVariables) {
1110
- if (!(previousName in variables)) {
1111
- root.style.removeProperty(previousName);
1306
+ for (const target of this.#targets) {
1307
+ for (const previousName of this.#appliedVariables) {
1308
+ if (!(previousName in variables)) {
1309
+ target.style.removeProperty(previousName);
1310
+ }
1112
1311
  }
1312
+ for (const [name, value] of Object.entries(variables)) {
1313
+ target.style.setProperty(name, value);
1314
+ }
1315
+ target.style.setProperty("color-scheme", selection.variant);
1316
+ target.setAttribute("data-mona-theme", selection.name);
1317
+ target.setAttribute("data-mona-variant", selection.variant);
1318
+ target.setAttribute("data-mona-transparency", transparency);
1113
1319
  }
1114
- for (const [name, value] of Object.entries(variables)) {
1115
- root.style.setProperty(name, value);
1116
- }
1117
- root.setAttribute("data-mona-theme", selection.name);
1118
- root.setAttribute("data-mona-variant", selection.variant);
1119
- root.setAttribute("data-mona-transparency", transparency);
1120
1320
  this.#appliedVariables.clear();
1121
1321
  for (const name of Object.keys(variables)) {
1122
1322
  this.#appliedVariables.add(name);
1123
1323
  }
1124
1324
  }
1325
+ #claimRoot() {
1326
+ const root = this.#root;
1327
+ if (!root) {
1328
+ return;
1329
+ }
1330
+ if (isDevMode() && themeWriters.has(root)) {
1331
+ console.warn("Mona UI: two applications are writing a theme to the same element, so each overwrites the other. Give one of them its own element with provideThemeRoot().");
1332
+ }
1333
+ themeWriters.set(root, this);
1334
+ }
1125
1335
  #getTransparencyMode() {
1126
1336
  const css = this.#document.defaultView?.CSS;
1127
1337
  const supportsBackdropFilter = css?.supports("backdrop-filter", "blur(1px)") === true ||
1128
1338
  css?.supports("-webkit-backdrop-filter", "blur(1px)") === true;
1129
1339
  return supportsBackdropFilter && this.#transparencyQuery?.matches !== true ? "full" : "reduced";
1130
1340
  }
1341
+ /** What's stored, if this service could apply it. Anything else counts as nothing stored, and stays there. */
1342
+ #readStoredPreference() {
1343
+ const key = this.#options.persistKey;
1344
+ if (!key || !this.#storage) {
1345
+ return null;
1346
+ }
1347
+ let stored;
1348
+ try {
1349
+ stored = this.#storage.read(key);
1350
+ }
1351
+ catch (error) {
1352
+ this.#reportStorageError(error);
1353
+ return null;
1354
+ }
1355
+ if (!isThemePreference(stored) || !this.#canApply(stored)) {
1356
+ return null;
1357
+ }
1358
+ this.#knownStored = normalizePreference(stored);
1359
+ return this.#knownStored;
1360
+ }
1361
+ #canApply(preference) {
1362
+ return preference.variant === "system"
1363
+ ? this.supportsVariant(preference.name, "light") || this.supportsVariant(preference.name, "dark")
1364
+ : this.supportsVariant(preference.name, preference.variant);
1365
+ }
1366
+ #releaseRoot() {
1367
+ const root = this.#root;
1368
+ if (!root || themeWriters.get(root) !== this) {
1369
+ return;
1370
+ }
1371
+ themeWriters.delete(root);
1372
+ for (const target of this.#targets) {
1373
+ for (const name of this.#appliedVariables) {
1374
+ target.style.removeProperty(name);
1375
+ }
1376
+ target.style.removeProperty("color-scheme");
1377
+ target.removeAttribute("data-mona-theme");
1378
+ target.removeAttribute("data-mona-variant");
1379
+ target.removeAttribute("data-mona-transparency");
1380
+ }
1381
+ this.#targets = [];
1382
+ }
1383
+ #reportStorageError(error) {
1384
+ if (isDevMode()) {
1385
+ console.error("Mona UI: the theme storage threw.", error);
1386
+ }
1387
+ }
1131
1388
  #resolveProfile(selection) {
1132
1389
  const profile = this.#strategy.resolve(selection);
1133
1390
  const palette = this.#runtimeColorPalette;
1134
1391
  return palette ? applyColorPalette(profile, palette[selection.variant]) : profile;
1135
1392
  }
1393
+ #resolveSelection(preference) {
1394
+ if (preference.variant !== "system") {
1395
+ return Object.freeze({ name: preference.name, variant: preference.variant });
1396
+ }
1397
+ const wanted = this.#colorSchemeQuery?.matches === true ? "dark" : "light";
1398
+ const other = wanted === "dark" ? "light" : "dark";
1399
+ const onlyOther = !this.supportsVariant(preference.name, wanted) && this.supportsVariant(preference.name, other);
1400
+ return Object.freeze({ name: preference.name, variant: onlyOther ? other : wanted });
1401
+ }
1402
+ #select(preference) {
1403
+ const selection = this.#resolveSelection(preference);
1404
+ const profile = this.#resolveProfile(selection);
1405
+ this.#applyTheme(selection, profile);
1406
+ this.#activeProfile.set(profile);
1407
+ this.#activeSelection.set(selection);
1408
+ }
1409
+ /**
1410
+ * Loaded on demand, so an application themed at `<html>` doesn't take on the overlay module for this. An overlay
1411
+ * opened before it arrives gets its colors when it does.
1412
+ */
1413
+ #themeOverlayContainer() {
1414
+ void import('@angular/cdk/overlay').then(overlay => {
1415
+ if (this.#targets.length > 0) {
1416
+ this.#targets = [...this.#targets, this.#injector.get(overlay.OverlayContainer).getContainerElement()];
1417
+ this.#applyTheme(this.#activeSelection(), this.#activeProfile());
1418
+ }
1419
+ });
1420
+ }
1421
+ #writeStoredPreference(preference) {
1422
+ const key = this.#options.persistKey;
1423
+ const known = this.#knownStored;
1424
+ if (!key ||
1425
+ !this.#storage ||
1426
+ (known && known.name === preference.name && known.variant === preference.variant)) {
1427
+ return;
1428
+ }
1429
+ this.#knownStored = preference;
1430
+ try {
1431
+ this.#storage.write(key, preference);
1432
+ }
1433
+ catch (error) {
1434
+ this.#reportStorageError(error);
1435
+ }
1436
+ }
1136
1437
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: ThemeService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
1137
1438
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: ThemeService, providedIn: "root" }); }
1138
1439
  }
@@ -1141,6 +1442,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImpor
1141
1442
  args: [{ providedIn: "root" }]
1142
1443
  }], ctorParameters: () => [] });
1143
1444
  const effectLevels = ["control", "raised", "overlay"];
1445
+ const preferenceVariants = ["light", "dark", "system"];
1144
1446
  function applyColorPalette(profile, colors) {
1145
1447
  return Object.freeze({
1146
1448
  ...profile,
@@ -1160,27 +1462,81 @@ function getEffectiveVariables(profile, transparency) {
1160
1462
  }
1161
1463
  return variables;
1162
1464
  }
1163
- function normalizeSelection(selection) {
1164
- return Object.freeze({ name: selection.name, variant: selection.variant });
1465
+ function isThemePreference(value) {
1466
+ if (typeof value !== "object" || value === null) {
1467
+ return false;
1468
+ }
1469
+ const { name, variant } = value;
1470
+ return typeof name === "string" && preferenceVariants.includes(variant);
1471
+ }
1472
+ function normalizePreference(preference) {
1473
+ return Object.freeze({ name: preference.name, variant: preference.variant });
1165
1474
  }
1166
1475
 
1476
+ /**
1477
+ * Every theme provider applies the theme at startup, so it doesn't depend on something injecting `ThemeService`,
1478
+ * and a configuration that can't be applied fails at bootstrap rather than in whichever component came first.
1479
+ */
1480
+ function applyThemeAtStartup() {
1481
+ return provideEnvironmentInitializer(() => {
1482
+ inject(ThemeService);
1483
+ });
1484
+ }
1167
1485
  function provideThemeFamily(registration) {
1168
- return makeEnvironmentProviders([{ provide: THEME_FAMILY_REGISTRATIONS, multi: true, useValue: registration }]);
1486
+ return makeEnvironmentProviders([
1487
+ { provide: THEME_FAMILY_REGISTRATIONS, multi: true, useValue: registration },
1488
+ applyThemeAtStartup()
1489
+ ]);
1169
1490
  }
1170
1491
  function provideThemeOverrides(registration) {
1171
- return makeEnvironmentProviders([{ provide: THEME_OVERRIDE_REGISTRATIONS, multi: true, useValue: registration }]);
1492
+ return makeEnvironmentProviders([
1493
+ { provide: THEME_OVERRIDE_REGISTRATIONS, multi: true, useValue: registration },
1494
+ applyThemeAtStartup()
1495
+ ]);
1172
1496
  }
1173
1497
  function provideThemeOptions(options) {
1174
- return makeEnvironmentProviders([{ provide: THEME_OPTIONS, useValue: options }]);
1498
+ return makeEnvironmentProviders([{ provide: THEME_OPTIONS, useValue: options }, applyThemeAtStartup()]);
1175
1499
  }
1500
+ /**
1501
+ * Generates a light and a dark palette from the seeds, and applies whichever the theme has.
1502
+ */
1176
1503
  function provideThemeColorPalette(registration) {
1177
1504
  const colors = generateThemeColorPalette(registration.seeds);
1178
1505
  return provideThemeOverrides({
1506
+ generated: true,
1179
1507
  theme: registration.theme,
1180
1508
  light: { colors: colors.light },
1181
1509
  dark: { colors: colors.dark }
1182
1510
  });
1183
1511
  }
1512
+ /**
1513
+ * Applies the theme to an element in place of `<html>`, for an application embedded in part of a page. Overlays
1514
+ * render outside any such element, so the overlay container gets the theme too. Each application has its own
1515
+ * overlay container, so two embedded applications can have two themes.
1516
+ * @param root the element, or a factory for it that runs in an injection context. It has to exist at startup.
1517
+ */
1518
+ function provideThemeRoot(root) {
1519
+ return makeEnvironmentProviders([
1520
+ typeof root === "function"
1521
+ ? { provide: THEME_ROOT, useFactory: root }
1522
+ : { provide: THEME_ROOT, useValue: root },
1523
+ applyThemeAtStartup()
1524
+ ]);
1525
+ }
1526
+ /**
1527
+ * Replaces where the theme is remembered, which is `localStorage` by default. Only used when
1528
+ * `provideThemeOptions()` has a `persistKey`. Supply something the server can read too, such as a cookie, to have a
1529
+ * server-rendered application render the remembered theme rather than correcting it on hydration.
1530
+ * @param storage the storage, or a factory for it that runs in an injection context
1531
+ */
1532
+ function provideThemeStorage(storage) {
1533
+ return makeEnvironmentProviders([
1534
+ typeof storage === "function"
1535
+ ? { provide: THEME_STORAGE, useFactory: storage }
1536
+ : { provide: THEME_STORAGE, useValue: storage },
1537
+ applyThemeAtStartup()
1538
+ ]);
1539
+ }
1184
1540
 
1185
1541
  /*
1186
1542
  * Public API Surface of @nanahoshi/mona-ui/theme
@@ -1190,5 +1546,5 @@ function provideThemeColorPalette(registration) {
1190
1546
  * Generated bundle index. Do not edit.
1191
1547
  */
1192
1548
 
1193
- export { THEME_STRATEGY, ThemeService, createSidebarColorRoles, flattenThemeProfile, generateThemeColorPalette, provideThemeColorPalette, provideThemeFamily, provideThemeOptions, provideThemeOverrides };
1549
+ export { DefaultThemeStrategy, LocalStorageThemeStorage, THEME_ROOT, THEME_STORAGE, THEME_STRATEGY, ThemeService, annaTheme, builtInThemes, createSidebarColorRoles, flattenThemeProfile, generateThemeColorPalette, lunaTheme, monaTheme, provideThemeColorPalette, provideThemeFamily, provideThemeOptions, provideThemeOverrides, provideThemeRoot, provideThemeStorage };
1194
1550
  //# sourceMappingURL=nanahoshi-mona-ui-theme.mjs.map