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