@sixbell-telco/sdk 1.6.0 → 2.1.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.
- package/CHANGELOG.md +260 -711
- package/README.md +337 -278
- package/_index.css +3 -3
- package/components/accordion/accordion-item/accordion-item.component.d.ts +3 -4
- package/components/audio-player/audio-timeline/audio-timeline.component.d.ts +29 -2
- package/components/audio-player/services/audio.service.d.ts +14 -14
- package/components/audio-player/src/audio-player.component.d.ts +7 -3
- package/components/audio-player/volume-control/volume-control.component.d.ts +28 -1
- package/components/button/src/button.component.d.ts +46 -1
- package/components/countdown/src/countdown.component.d.ts +1 -1
- package/components/data-table/data-table-empty-actions/data-table-empty-actions.component.d.ts +5 -0
- package/components/data-table/public-api.d.ts +1 -0
- package/components/data-table/src/data-table.component.d.ts +11 -3
- package/components/dialog/src/dialog.component.d.ts +51 -5
- package/components/dropdown/dropdown-content/dropdown-content.component.d.ts +2 -1
- package/components/dropdown/dropdown-item/dropdown-item.component.d.ts +37 -1
- package/components/dropdown/dropdown-item-checkbox/dropdown-item-checkbox.component.d.ts +33 -1
- package/components/dropdown/dropdown-item-radio/dropdown-item-radio.component.d.ts +33 -1
- package/components/dropdown/dropdown-trigger/dropdown-trigger.component.d.ts +53 -2
- package/components/dropdown/src/dropdown.component.d.ts +2 -2
- package/components/dropdown-menu/bar/dropdown-menu-bar-content/dropdown-menu-bar-content.component.d.ts +2 -1
- package/components/dropdown-menu/bar/dropdown-menu-bar-item/dropdown-menu-bar-item.component.d.ts +33 -1
- package/components/dropdown-menu/bar/dropdown-menu-bar-item-checkbox/dropdown-menu-bar-item-checkbox.component.d.ts +33 -1
- package/components/dropdown-menu/bar/dropdown-menu-bar-item-radio/dropdown-menu-bar-item-radio.component.d.ts +33 -1
- package/components/dropdown-menu/src/directives/dropdown-menu.directive.d.ts +1 -3
- package/components/dropdown-menu/src/dropdown-menu-content/dropdown-menu-content.component.d.ts +4 -4
- package/components/dropdown-menu/src/dropdown-menu-item/dropdown-menu-item.component.d.ts +33 -1
- package/components/dropdown-menu/src/dropdown-menu-sub-content/dropdown-menu-sub-content.component.d.ts +2 -1
- package/components/dual-list/src/dual-list.component.d.ts +4 -2
- package/components/file-upload/file-dropzone/file-dropzone.component.d.ts +53 -8
- package/components/file-upload/file-uploader/file-uploader.component.d.ts +40 -9
- package/components/forms/checkbox/src/checkbox.component.d.ts +46 -2
- package/components/forms/combobox/src/combobox.component.d.ts +40 -5
- package/components/forms/date-picker/src/date-picker.component.d.ts +11 -1
- package/components/forms/form-group/README.md +114 -0
- package/components/forms/form-group/index.d.ts +5 -0
- package/components/forms/form-group/public-api.d.ts +1 -0
- package/components/forms/form-group/src/form-group.component.d.ts +150 -0
- package/components/forms/form-item/README.md +17 -0
- package/components/forms/form-item/index.d.ts +5 -0
- package/components/forms/form-item/public-api.d.ts +1 -0
- package/components/forms/form-item/src/form-item.component.d.ts +5 -0
- package/components/forms/input/src/input.component.d.ts +45 -2
- package/components/forms/radio/src/radio.component.d.ts +46 -2
- package/components/forms/range/src/range.component.d.ts +38 -1
- package/components/forms/select/src/select.component.d.ts +40 -5
- package/components/forms/switch/src/switch.component.d.ts +46 -2
- package/components/forms/textarea/src/textarea.component.d.ts +62 -12
- package/components/forms/toggle/src/toggle.component.d.ts +46 -1
- package/components/link/src/link.component.d.ts +0 -3
- package/components/overlay/overlay-content/overlay-content.component.d.ts +2 -1
- package/components/overlay/overlay-trigger/overlay-trigger.component.d.ts +37 -5
- package/components/overlay/src/overlay.component.d.ts +4 -5
- package/components/paginator/components/pagination-item/pagination-item.component.d.ts +37 -1
- package/components/tab/directives/tab-content/tab-content.directive.d.ts +5 -6
- package/components/tab/directives/tab-header/tab-header.directive.d.ts +2 -2
- package/components/table/public-api.d.ts +1 -0
- package/components/table/src/table.component.d.ts +36 -4
- package/components/table/table-empty-actions/table-empty-actions.component.d.ts +5 -0
- package/components/table/table-header-checkbox/table-header-checkbox.component.d.ts +5 -11
- package/components/table/table-row-checkbox/table-row-checkbox.component.d.ts +5 -11
- package/components/toast/toast-message/toast-message.component.d.ts +42 -1
- package/components/tooltip/src/tooltip.component.d.ts +10 -1
- package/components/wizard/services/wizard.service.d.ts +5 -5
- package/components/wizard/wizard-marker/wizard-marker.component.d.ts +2 -3
- package/directives/auto-focus/public-api.d.ts +1 -1
- package/directives/auto-focus/src/{autofocus.directive.d.ts → auto-focus.directive.d.ts} +9 -15
- package/directives/click-outside/src/click-outside.directive.d.ts +1 -3
- package/directives/only-numbers/public-api.d.ts +6 -1
- package/directives/only-numbers/src/only-numbers.directive.d.ts +36 -0
- package/fesm2022/sixbell-telco-sdk-components-accordion.mjs +6 -9
- package/fesm2022/sixbell-telco-sdk-components-accordion.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-audio-player.mjs +133 -51
- package/fesm2022/sixbell-telco-sdk-components-audio-player.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-avatar.mjs +1 -1
- package/fesm2022/sixbell-telco-sdk-components-avatar.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-badge.mjs +2 -2
- package/fesm2022/sixbell-telco-sdk-components-badge.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-button.mjs +78 -4
- package/fesm2022/sixbell-telco-sdk-components-button.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-countdown.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-data-table-sub-component-toggle.mjs +1 -1
- package/fesm2022/sixbell-telco-sdk-components-data-table-sub-component-toggle.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-data-table.mjs +53 -27
- package/fesm2022/sixbell-telco-sdk-components-data-table.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-dialog.mjs +82 -12
- package/fesm2022/sixbell-telco-sdk-components-dialog.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-dropdown-menu-bar.mjs +166 -13
- package/fesm2022/sixbell-telco-sdk-components-dropdown-menu-bar.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-dropdown-menu.mjs +68 -24
- package/fesm2022/sixbell-telco-sdk-components-dropdown-menu.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-dropdown.mjs +283 -16
- package/fesm2022/sixbell-telco-sdk-components-dropdown.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-dual-list.mjs +12 -9
- package/fesm2022/sixbell-telco-sdk-components-dual-list.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-file-upload.mjs +151 -10
- package/fesm2022/sixbell-telco-sdk-components-file-upload.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-checkbox.mjs +69 -3
- package/fesm2022/sixbell-telco-sdk-components-forms-checkbox.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-combobox.mjs +96 -19
- package/fesm2022/sixbell-telco-sdk-components-forms-combobox.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-date-picker.mjs +15 -3
- package/fesm2022/sixbell-telco-sdk-components-forms-date-picker.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-form-error.mjs +2 -2
- package/fesm2022/sixbell-telco-sdk-components-forms-form-error.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-form-group.mjs +159 -0
- package/fesm2022/sixbell-telco-sdk-components-forms-form-group.mjs.map +1 -0
- package/fesm2022/sixbell-telco-sdk-components-forms-form-item.mjs +20 -0
- package/fesm2022/sixbell-telco-sdk-components-forms-form-item.mjs.map +1 -0
- package/fesm2022/sixbell-telco-sdk-components-forms-input.mjs +62 -6
- package/fesm2022/sixbell-telco-sdk-components-forms-input.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-radio.mjs +69 -3
- package/fesm2022/sixbell-telco-sdk-components-forms-radio.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-range.mjs +57 -4
- package/fesm2022/sixbell-telco-sdk-components-forms-range.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-select.mjs +91 -20
- package/fesm2022/sixbell-telco-sdk-components-forms-select.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-switch.mjs +80 -6
- package/fesm2022/sixbell-telco-sdk-components-forms-switch.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-textarea.mjs +131 -13
- package/fesm2022/sixbell-telco-sdk-components-forms-textarea.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-toggle.mjs +69 -3
- package/fesm2022/sixbell-telco-sdk-components-forms-toggle.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-link.mjs +2 -7
- package/fesm2022/sixbell-telco-sdk-components-link.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-overlay.mjs +94 -42
- package/fesm2022/sixbell-telco-sdk-components-overlay.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-paginator.mjs +71 -10
- package/fesm2022/sixbell-telco-sdk-components-paginator.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-tab.mjs +5 -9
- package/fesm2022/sixbell-telco-sdk-components-tab.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-table.mjs +131 -47
- package/fesm2022/sixbell-telco-sdk-components-table.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-toast.mjs +69 -4
- package/fesm2022/sixbell-telco-sdk-components-toast.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-tooltip.mjs +15 -3
- package/fesm2022/sixbell-telco-sdk-components-tooltip.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-wizard.mjs +4 -4
- package/fesm2022/sixbell-telco-sdk-components-wizard.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-directives-auto-focus.mjs +29 -49
- package/fesm2022/sixbell-telco-sdk-directives-auto-focus.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-directives-click-outside.mjs +7 -10
- package/fesm2022/sixbell-telco-sdk-directives-click-outside.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-directives-only-numbers.mjs +48 -17
- package/fesm2022/sixbell-telco-sdk-directives-only-numbers.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-utils-date.mjs +1 -1
- package/fesm2022/sixbell-telco-sdk-utils-date.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-utils-pipes-to-bytes-extesion.mjs +1 -1
- package/fesm2022/sixbell-telco-sdk-utils-pipes-to-bytes-extesion.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-utils-runtime-config.mjs +339 -0
- package/fesm2022/sixbell-telco-sdk-utils-runtime-config.mjs.map +1 -0
- package/fesm2022/sixbell-telco-sdk-utils-sync.mjs +1 -1
- package/fesm2022/sixbell-telco-sdk-utils-sync.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-utils-theme.mjs +1062 -730
- package/fesm2022/sixbell-telco-sdk-utils-theme.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-utils-translation.mjs +350 -267
- package/fesm2022/sixbell-telco-sdk-utils-translation.mjs.map +1 -1
- package/package.json +55 -46
- package/utils/runtime-config/README.md +235 -0
- package/utils/{resource-loader → runtime-config}/index.d.ts +1 -1
- package/utils/runtime-config/public-api.d.ts +5 -0
- package/utils/runtime-config/src/http-client.d.ts +11 -0
- package/utils/runtime-config/src/runtime-config-loader.d.ts +23 -0
- package/utils/runtime-config/src/runtime-config-store.d.ts +11 -0
- package/utils/runtime-config/src/runtime-update-adapter.d.ts +15 -0
- package/utils/runtime-config/src/types.d.ts +66 -0
- package/utils/theme/README.md +324 -986
- package/utils/theme/public-api.d.ts +4 -4
- package/utils/theme/src/constants.d.ts +6 -12
- package/utils/theme/src/models/theme.d.ts +46 -173
- package/utils/theme/src/providers/theme.provider.d.ts +0 -10
- package/utils/theme/src/providers/theme.provider.types.d.ts +16 -15
- package/utils/theme/src/theme-assets/theme-assets.service.d.ts +16 -12
- package/utils/theme/src/theme-dom/theme-dom.service.d.ts +10 -3
- package/utils/theme/src/theme.service.d.ts +24 -27
- package/utils/theme/src/utils/utils.d.ts +2 -10
- package/utils/translation/README.md +170 -1390
- package/utils/translation/public-api.d.ts +3 -3
- package/utils/translation/src/constants.d.ts +7 -9
- package/utils/translation/src/models/translation.d.ts +9 -10
- package/utils/translation/src/providers/translation.provider.d.ts +17 -28
- package/utils/translation/src/providers/translation.provider.types.d.ts +13 -6
- package/utils/translation/src/translation-dom/translation-dom.service.d.ts +2 -3
- package/utils/translation/src/translation.service.d.ts +37 -9
- package/directives/only-numbers/src/just-numbers.directive.d.ts +0 -9
- package/fesm2022/sixbell-telco-sdk-utils-resource-loader.mjs +0 -1222
- package/fesm2022/sixbell-telco-sdk-utils-resource-loader.mjs.map +0 -1
- package/utils/resource-loader/README.md +0 -460
- package/utils/resource-loader/public-api.d.ts +0 -1
- package/utils/resource-loader/src/cache/index.d.ts +0 -2
- package/utils/resource-loader/src/cache/layers/factory.d.ts +0 -38
- package/utils/resource-loader/src/cache/layers/index.d.ts +0 -3
- package/utils/resource-loader/src/cache/layers/indexed-db-cache.d.ts +0 -118
- package/utils/resource-loader/src/cache/layers/local-storage-cache.d.ts +0 -86
- package/utils/resource-loader/src/cache/layers/memory-cache.d.ts +0 -76
- package/utils/resource-loader/src/cache/types.d.ts +0 -107
- package/utils/resource-loader/src/config/index.d.ts +0 -1
- package/utils/resource-loader/src/config/load-config.d.ts +0 -32
- package/utils/resource-loader/src/constants.d.ts +0 -38
- package/utils/resource-loader/src/http/index.d.ts +0 -1
- package/utils/resource-loader/src/http/retryable-client.d.ts +0 -43
- package/utils/resource-loader/src/index.d.ts +0 -1
- package/utils/resource-loader/src/resource-loader.d.ts +0 -67
- package/utils/resource-loader/src/types.d.ts +0 -152
- package/utils/resource-loader/src/utils/cache-validator.d.ts +0 -72
- package/utils/resource-loader/src/utils/helpers.d.ts +0 -15
- package/utils/resource-loader/src/utils/index.d.ts +0 -2
- package/utils/theme/src/providers/constants.d.ts +0 -7
- package/utils/translation/src/providers/constants.d.ts +0 -11
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import {
|
|
2
|
+
import { inject, Injectable, signal, RendererFactory2, computed, makeEnvironmentProviders, provideAppInitializer } from '@angular/core';
|
|
3
3
|
import { LoggerService } from '@sixbell-telco/sdk/utils/logger';
|
|
4
|
-
import {
|
|
5
|
-
import { Router, NavigationEnd } from '@angular/router';
|
|
4
|
+
import { RuntimeConfigStore, RuntimeConfigLoader, RuntimeUpdateAdapter } from '@sixbell-telco/sdk/utils/runtime-config';
|
|
6
5
|
import { TranslationService } from '@sixbell-telco/sdk/utils/translation';
|
|
7
|
-
import { filter } from 'rxjs/operators';
|
|
8
6
|
import { DOCUMENT } from '@angular/common';
|
|
9
7
|
|
|
10
8
|
/**
|
|
@@ -49,6 +47,11 @@ const THEME_SCHEME_SEPARATOR = '__';
|
|
|
49
47
|
* Default theme scheme preference
|
|
50
48
|
*/
|
|
51
49
|
const DEFAULT_SCHEME = 'system';
|
|
50
|
+
/**
|
|
51
|
+
* Schema version for runtime theme configuration payloads.
|
|
52
|
+
* Bump this when the JSON structure changes in a breaking way.
|
|
53
|
+
*/
|
|
54
|
+
const THEME_SCHEMA_VERSION = '2';
|
|
52
55
|
/**
|
|
53
56
|
* All valid scheme values
|
|
54
57
|
*/
|
|
@@ -57,15 +60,29 @@ const VALID_SCHEMES = ['system', 'light', 'dark'];
|
|
|
57
60
|
* Minimal runtime configuration used as a resilient fallback when remote loading fails
|
|
58
61
|
*/
|
|
59
62
|
const FALLBACK_RUNTIME_THEME_CONFIG = {
|
|
63
|
+
meta: {
|
|
64
|
+
name: DEFAULT_BASE_THEME,
|
|
65
|
+
updatedAt: new Date().toISOString(),
|
|
66
|
+
hash: 'fallback-hash',
|
|
67
|
+
schemaVersion: THEME_SCHEMA_VERSION,
|
|
68
|
+
},
|
|
69
|
+
fonts: [
|
|
70
|
+
{
|
|
71
|
+
family: 'Poppins',
|
|
72
|
+
faces: [
|
|
73
|
+
{ weight: 400, style: 'normal', src: '/assets/fonts/Poppins-Regular.ttf' },
|
|
74
|
+
{ weight: 500, style: 'normal', src: '/assets/fonts/Poppins-Medium.ttf' },
|
|
75
|
+
{ weight: 600, style: 'normal', src: '/assets/fonts/Poppins-SemiBold.ttf' },
|
|
76
|
+
{ weight: 700, style: 'normal', src: '/assets/fonts/Poppins-Bold.ttf' },
|
|
77
|
+
{ weight: 800, style: 'normal', src: '/assets/fonts/Poppins-ExtraBold.ttf' },
|
|
78
|
+
{ weight: 900, style: 'normal', src: '/assets/fonts/Poppins-Black.ttf' },
|
|
79
|
+
],
|
|
80
|
+
},
|
|
81
|
+
],
|
|
60
82
|
themes: {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
prefersDark: false,
|
|
65
|
-
variables: {
|
|
66
|
-
'--font-poppins': 'Poppins, sans-serif',
|
|
67
|
-
'--font-heading': 'Poppins, sans-serif',
|
|
68
|
-
'--font-body': 'Poppins, sans-serif',
|
|
83
|
+
light: {
|
|
84
|
+
variables: {
|
|
85
|
+
colors: {
|
|
69
86
|
'--color-base-100': 'oklch(96.65% 0.0045 258.32)',
|
|
70
87
|
'--color-base-200': 'oklch(100% 0 0)',
|
|
71
88
|
'--color-base-300': 'oklch(92.88% 0.0126 255.51)',
|
|
@@ -115,23 +132,31 @@ const FALLBACK_RUNTIME_THEME_CONFIG = {
|
|
|
115
132
|
'--color-metrics-intensity-low': 'oklch(76.18% 0.0656 213.66)',
|
|
116
133
|
'--color-metrics-intensity-lowest': 'oklch(78% 0.0473 211.88)',
|
|
117
134
|
'--color-scroll-thumb': 'oklch(75% 0 0)',
|
|
135
|
+
},
|
|
136
|
+
radius: {
|
|
118
137
|
'--radius-selector': '0.5rem',
|
|
119
138
|
'--radius-field': '0.25rem',
|
|
120
139
|
'--radius-box': '0.5rem',
|
|
140
|
+
},
|
|
141
|
+
sizes: {
|
|
121
142
|
'--size-selector': '0.25rem',
|
|
122
143
|
'--size-field': '0.25rem',
|
|
144
|
+
},
|
|
145
|
+
effects: {
|
|
123
146
|
'--border': '1px',
|
|
124
147
|
'--depth': '0',
|
|
125
148
|
'--noise': '0',
|
|
126
149
|
},
|
|
127
|
-
|
|
128
|
-
dark: {
|
|
129
|
-
daisyuiName: `${DEFAULT_BASE_THEME}__dark`,
|
|
130
|
-
prefersDark: true,
|
|
131
|
-
variables: {
|
|
150
|
+
others: {
|
|
132
151
|
'--font-poppins': 'Poppins, sans-serif',
|
|
133
152
|
'--font-heading': 'Poppins, sans-serif',
|
|
134
153
|
'--font-body': 'Poppins, sans-serif',
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
dark: {
|
|
158
|
+
variables: {
|
|
159
|
+
colors: {
|
|
135
160
|
'--color-base-100': 'oklch(18.22% 0 0)',
|
|
136
161
|
'--color-base-200': 'oklch(23.5% 0 0)',
|
|
137
162
|
'--color-base-300': 'oklch(28.5% 0 0)',
|
|
@@ -181,21 +206,36 @@ const FALLBACK_RUNTIME_THEME_CONFIG = {
|
|
|
181
206
|
'--color-metrics-intensity-low': 'oklch(76.18% 0.0656 213.66)',
|
|
182
207
|
'--color-metrics-intensity-lowest': 'oklch(78% 0.0473 211.88)',
|
|
183
208
|
'--color-scroll-thumb': 'oklch(35% 0 0)',
|
|
209
|
+
},
|
|
210
|
+
radius: {
|
|
184
211
|
'--radius-selector': '0.5rem',
|
|
185
212
|
'--radius-field': '0.25rem',
|
|
186
213
|
'--radius-box': '0.5rem',
|
|
214
|
+
},
|
|
215
|
+
sizes: {
|
|
187
216
|
'--size-selector': '0.25rem',
|
|
188
217
|
'--size-field': '0.25rem',
|
|
218
|
+
},
|
|
219
|
+
effects: {
|
|
189
220
|
'--border': '1px',
|
|
190
221
|
'--depth': '0',
|
|
191
222
|
'--noise': '0',
|
|
192
223
|
},
|
|
224
|
+
others: {
|
|
225
|
+
'--font-poppins': 'Poppins, sans-serif',
|
|
226
|
+
'--font-heading': 'Poppins, sans-serif',
|
|
227
|
+
'--font-body': 'Poppins, sans-serif',
|
|
228
|
+
},
|
|
193
229
|
},
|
|
194
230
|
},
|
|
195
231
|
},
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
232
|
+
assets: [
|
|
233
|
+
{
|
|
234
|
+
name: 'logo',
|
|
235
|
+
light: '/assets/logos/sixbell-logo-light-mode.svg',
|
|
236
|
+
dark: '/assets/logos/sixbell-logo-dark-mode.svg',
|
|
237
|
+
},
|
|
238
|
+
],
|
|
199
239
|
};
|
|
200
240
|
/**
|
|
201
241
|
* CSS class name applied to document when dark theme is detected
|
|
@@ -205,182 +245,406 @@ const DARK_THEME_CLASS = 'dark';
|
|
|
205
245
|
* Media query for detecting system dark mode preference
|
|
206
246
|
*/
|
|
207
247
|
const DARK_MODE_MEDIA_QUERY = '(prefers-color-scheme: dark)';
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Theme Utility Functions
|
|
251
|
+
* Pure, side-effect-free utilities for theme logic
|
|
252
|
+
*/
|
|
253
|
+
/**
|
|
254
|
+
* Validates that a given value is a valid theme scheme
|
|
255
|
+
* @param value - The value to validate
|
|
256
|
+
* @returns True if the value is a valid scheme ('system', 'light', or 'dark')
|
|
257
|
+
*/
|
|
258
|
+
function isValidScheme(value) {
|
|
259
|
+
return typeof value === 'string' && VALID_SCHEMES.includes(value);
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Builds the final theme identifier by combining theme name and scheme
|
|
263
|
+
* @param themeName - The name of the theme
|
|
264
|
+
* @param scheme - The scheme variant (light or dark)
|
|
265
|
+
* @returns Combined identifier (e.g., "sixbell_telco__light")
|
|
266
|
+
*/
|
|
267
|
+
function buildThemeIdentifier(themeName, scheme) {
|
|
268
|
+
return `${themeName}__${scheme}`;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Extracts theme name and scheme from a combined identifier
|
|
272
|
+
* @param identifier - The combined identifier (e.g., "sixbell_telco__light")
|
|
273
|
+
* @returns Object with extracted themeName and scheme
|
|
274
|
+
*/
|
|
275
|
+
function parseThemeIdentifier(identifier) {
|
|
276
|
+
const [themeName, scheme] = identifier.split('__');
|
|
277
|
+
return { themeName, scheme };
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Determines the effective default theme from configuration
|
|
281
|
+
* Ensures the default theme is in the available themes list
|
|
282
|
+
* Falls back to first available theme if default is not available
|
|
283
|
+
* @param defaultTheme - Configured default theme
|
|
284
|
+
* @param availableThemes - List of available themes
|
|
285
|
+
* @returns The effective default theme to use
|
|
286
|
+
*/
|
|
287
|
+
function resolveDefaultTheme(defaultTheme, availableThemes) {
|
|
288
|
+
// Use provided default if valid
|
|
289
|
+
if (defaultTheme && availableThemes.includes(defaultTheme)) {
|
|
290
|
+
return defaultTheme;
|
|
291
|
+
}
|
|
292
|
+
// Check if base theme is available
|
|
293
|
+
if (availableThemes.includes(DEFAULT_BASE_THEME)) {
|
|
294
|
+
return DEFAULT_BASE_THEME;
|
|
295
|
+
}
|
|
296
|
+
// Fallback to first available
|
|
297
|
+
return availableThemes[0] || DEFAULT_BASE_THEME;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Validates that a given theme exists in the available themes
|
|
301
|
+
* @param theme - Theme name to validate
|
|
302
|
+
* @param availableThemes - List of available themes
|
|
303
|
+
* @returns True if theme is available
|
|
304
|
+
*/
|
|
305
|
+
function isThemeAvailable(theme, availableThemes) {
|
|
306
|
+
return availableThemes.includes(theme);
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Validates the configuration and logs warnings for invalid states
|
|
310
|
+
* Returns true if configuration is valid for use
|
|
311
|
+
* @param config - Configuration to validate
|
|
312
|
+
* @param configName - Name of config for logging purposes
|
|
313
|
+
* @returns True if configuration is valid
|
|
314
|
+
*/
|
|
315
|
+
function validateThemeConfig(config, configName = 'ThemeConfig') {
|
|
316
|
+
const errors = [];
|
|
317
|
+
if (!config.availableThemes || config.availableThemes.length === 0) {
|
|
318
|
+
errors.push('availableThemes must be a non-empty array');
|
|
319
|
+
}
|
|
320
|
+
if (!config.defaultTheme) {
|
|
321
|
+
errors.push('defaultTheme must be defined');
|
|
322
|
+
}
|
|
323
|
+
if (config.defaultTheme && !config.availableThemes.includes(config.defaultTheme)) {
|
|
324
|
+
errors.push(`defaultTheme '${config.defaultTheme}' not in availableThemes`);
|
|
325
|
+
}
|
|
326
|
+
if (errors.length > 0) {
|
|
327
|
+
console.error(`${configName} validation failed:`, errors.join(', '));
|
|
328
|
+
return false;
|
|
329
|
+
}
|
|
330
|
+
return true;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Formats a theme name for display to users
|
|
334
|
+
* Converts snake_case to Title Case
|
|
335
|
+
* @param theme - Theme name to format
|
|
336
|
+
* @returns Formatted theme name
|
|
337
|
+
*/
|
|
338
|
+
function formatThemeName(theme) {
|
|
339
|
+
return theme.replace(/_/g, ' ').replace(/\b\w/g, (l) => l.toUpperCase());
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Formats a scheme name for display to users
|
|
343
|
+
* Capitalizes first letter
|
|
344
|
+
* @param scheme - Scheme name to format
|
|
345
|
+
* @returns Formatted scheme name
|
|
346
|
+
*/
|
|
347
|
+
function formatSchemeName(scheme) {
|
|
348
|
+
return scheme.charAt(0).toUpperCase() + scheme.slice(1);
|
|
349
|
+
}
|
|
208
350
|
/**
|
|
209
|
-
*
|
|
210
|
-
*
|
|
351
|
+
* Checks if the browser supports the matchMedia API
|
|
352
|
+
* Safe to call in non-browser environments
|
|
353
|
+
* @returns True if matchMedia is available
|
|
211
354
|
*/
|
|
212
|
-
|
|
355
|
+
function supportsMediaQuery() {
|
|
356
|
+
return typeof window !== 'undefined' && typeof window.matchMedia === 'function';
|
|
357
|
+
}
|
|
213
358
|
/**
|
|
214
|
-
*
|
|
215
|
-
*
|
|
359
|
+
* Checks if localStorage is available in the current environment
|
|
360
|
+
* Safe to call in non-browser environments
|
|
361
|
+
* @returns True if localStorage is accessible
|
|
216
362
|
*/
|
|
217
|
-
|
|
363
|
+
function hasLocalStorage() {
|
|
364
|
+
try {
|
|
365
|
+
return typeof window !== 'undefined' && typeof localStorage !== 'undefined' && localStorage !== null;
|
|
366
|
+
}
|
|
367
|
+
catch {
|
|
368
|
+
return false;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
218
371
|
|
|
219
372
|
/**
|
|
220
|
-
* Theme
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
* Responsibilities:
|
|
224
|
-
* - Retrieve assets (images, logos, illustrations) for current theme
|
|
225
|
-
* - Provide scheme-aware asset variants (light/dark)
|
|
226
|
-
* - Cache asset references with config-based resilience strategy
|
|
227
|
-
* - Validate asset availability and provide graceful fallback through memory layers
|
|
228
|
-
*
|
|
229
|
-
* Multi-Layer Caching Strategy (Like Theme Config Persistence):
|
|
230
|
-
* - Layer 1: Current config assets (read from active RuntimeThemeConfig)
|
|
231
|
-
* - Layer 2: Last working asset config (in-memory, persists across config updates)
|
|
232
|
-
* - Falls back to last complete working config if current config breaks
|
|
233
|
-
*
|
|
234
|
-
* This matches the ResourceLoader and ThemeService pattern where:
|
|
235
|
-
* - User preferences/working configs are stored in memory layers
|
|
236
|
-
* - When new config fails, the last working config is used automatically
|
|
237
|
-
* - Handles asset removal, name changes, path changes, config resets
|
|
373
|
+
* Theme Storage Service
|
|
374
|
+
* Handles persistent theme preferences using localStorage
|
|
238
375
|
*/
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* Layer 1: In-memory cache of resolved assets
|
|
247
|
-
* Maps "themeName:assetKey" to CachedAsset for fast retrieval
|
|
248
|
-
* Cleared when setConfig() is called to force re-resolution from new config
|
|
249
|
-
*/
|
|
250
|
-
assetCache = new Map();
|
|
251
|
-
/**
|
|
252
|
-
* Layer 2: Last working config storage (memory-based)
|
|
253
|
-
* Stores the most recent RuntimeThemeConfig that successfully resolved assets
|
|
254
|
-
* Persists across config updates as a complete fallback mechanism
|
|
255
|
-
* Similar to ThemeService's multi-layer config persistence
|
|
256
|
-
*
|
|
257
|
-
* When current config fails to provide an asset:
|
|
258
|
-
* - Falls back to the last complete working config
|
|
259
|
-
* - Handles asset removal, name changes, path changes
|
|
260
|
-
* - Automatically restores working state on config resets
|
|
261
|
-
* - No individual URL tracking - entire config stored once per successful load
|
|
262
|
-
*/
|
|
263
|
-
lastWorkingConfigLayer = null;
|
|
376
|
+
/**
|
|
377
|
+
* Service for managing theme preferences in local storage
|
|
378
|
+
* Provides safe access to localStorage with error handling
|
|
379
|
+
* Works gracefully in non-browser environments (SSR)
|
|
380
|
+
*/
|
|
381
|
+
class ThemeStorageService {
|
|
264
382
|
logger = inject(LoggerService);
|
|
265
|
-
constructor() { }
|
|
266
383
|
/**
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
* If new config successfully resolves assets, it becomes the new fallback layer.
|
|
271
|
-
* Otherwise, previous working config persists.
|
|
272
|
-
*
|
|
273
|
-
* Only updates Layer 2 if:
|
|
274
|
-
* - Config has no PARTIAL/BROKEN assets (missing variants)
|
|
275
|
-
* - Themes can be removed entirely (that's intentional)
|
|
276
|
-
* - But existing assets must be COMPLETE (both light and dark)
|
|
277
|
-
*
|
|
278
|
-
* This ensures that accidental removals of variants trigger fallback
|
|
279
|
-
* while intentional complete removals are allowed.
|
|
280
|
-
*
|
|
281
|
-
* @param config - Runtime configuration containing asset definitions
|
|
384
|
+
* Retrieves the saved theme preference from localStorage
|
|
385
|
+
* Returns null if no saved preference or storage unavailable
|
|
386
|
+
* @returns Saved theme name or null
|
|
282
387
|
*/
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
hasPartialAssets,
|
|
291
|
-
hasValidAssets: hasValid,
|
|
292
|
-
themes: config?.assets ? Object.keys(config.assets) : [],
|
|
293
|
-
hasLastWorking: !!this.lastWorkingConfigLayer,
|
|
294
|
-
});
|
|
295
|
-
// Only store as last working config if it has NO partial/broken assets
|
|
296
|
-
if (hasValid) {
|
|
297
|
-
this.logger.debug('Storing config as last working config', {
|
|
298
|
-
component: 'ThemeAssetsService',
|
|
299
|
-
action: 'setConfig',
|
|
300
|
-
});
|
|
301
|
-
this.lastWorkingConfigLayer = config;
|
|
388
|
+
getSavedTheme() {
|
|
389
|
+
try {
|
|
390
|
+
if (!hasLocalStorage()) {
|
|
391
|
+
return null;
|
|
392
|
+
}
|
|
393
|
+
const key = this.getStorageKey(THEME_STORAGE_THEME_KEY);
|
|
394
|
+
return localStorage.getItem(key);
|
|
302
395
|
}
|
|
303
|
-
|
|
304
|
-
this.logger.
|
|
305
|
-
component: '
|
|
306
|
-
action: '
|
|
396
|
+
catch (error) {
|
|
397
|
+
this.logger.error('Failed to retrieve saved theme', error, {
|
|
398
|
+
component: 'ThemeStorageService',
|
|
399
|
+
action: 'getSavedTheme',
|
|
307
400
|
});
|
|
401
|
+
return null;
|
|
308
402
|
}
|
|
309
|
-
this.clearCache();
|
|
310
403
|
}
|
|
311
404
|
/**
|
|
312
|
-
*
|
|
313
|
-
*
|
|
314
|
-
*
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
405
|
+
* Saves the current theme preference to localStorage
|
|
406
|
+
* Fails silently if storage is unavailable
|
|
407
|
+
* @param theme - Theme name to save
|
|
408
|
+
*/
|
|
409
|
+
saveTheme(theme) {
|
|
410
|
+
try {
|
|
411
|
+
if (!hasLocalStorage()) {
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
const key = this.getStorageKey(THEME_STORAGE_THEME_KEY);
|
|
415
|
+
localStorage.setItem(key, theme);
|
|
416
|
+
}
|
|
417
|
+
catch (error) {
|
|
418
|
+
this.logger.error('Failed to save theme', error, {
|
|
419
|
+
component: 'ThemeStorageService',
|
|
420
|
+
action: 'saveTheme',
|
|
421
|
+
theme,
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Retrieves the saved scheme preference from localStorage
|
|
427
|
+
* Returns null if no saved preference or storage unavailable
|
|
428
|
+
* @returns Saved scheme ('system', 'light', 'dark') or null
|
|
429
|
+
*/
|
|
430
|
+
getSavedScheme() {
|
|
431
|
+
try {
|
|
432
|
+
if (!hasLocalStorage()) {
|
|
433
|
+
return null;
|
|
434
|
+
}
|
|
435
|
+
const key = this.getStorageKey(THEME_STORAGE_SCHEME_KEY);
|
|
436
|
+
return localStorage.getItem(key);
|
|
437
|
+
}
|
|
438
|
+
catch (error) {
|
|
439
|
+
this.logger.error('Failed to retrieve saved scheme', error, {
|
|
440
|
+
component: 'ThemeStorageService',
|
|
441
|
+
action: 'getSavedScheme',
|
|
442
|
+
});
|
|
443
|
+
return null;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Saves the current scheme preference to localStorage
|
|
448
|
+
* Fails silently if storage is unavailable
|
|
449
|
+
* @param scheme - Scheme to save
|
|
450
|
+
*/
|
|
451
|
+
saveScheme(scheme) {
|
|
452
|
+
try {
|
|
453
|
+
if (!hasLocalStorage()) {
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
const key = this.getStorageKey(THEME_STORAGE_SCHEME_KEY);
|
|
457
|
+
localStorage.setItem(key, scheme);
|
|
458
|
+
}
|
|
459
|
+
catch (error) {
|
|
460
|
+
this.logger.error('Failed to save scheme', error, {
|
|
461
|
+
component: 'ThemeStorageService',
|
|
462
|
+
action: 'saveScheme',
|
|
463
|
+
scheme,
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Clears all saved theme preferences from localStorage
|
|
469
|
+
* Useful for resetting to defaults
|
|
470
|
+
*/
|
|
471
|
+
clear() {
|
|
472
|
+
try {
|
|
473
|
+
if (!hasLocalStorage()) {
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
const themeKey = this.getStorageKey(THEME_STORAGE_THEME_KEY);
|
|
477
|
+
const schemeKey = this.getStorageKey(THEME_STORAGE_SCHEME_KEY);
|
|
478
|
+
localStorage.removeItem(themeKey);
|
|
479
|
+
localStorage.removeItem(schemeKey);
|
|
480
|
+
}
|
|
481
|
+
catch (error) {
|
|
482
|
+
this.logger.error('Failed to clear storage', error, {
|
|
483
|
+
component: 'ThemeStorageService',
|
|
484
|
+
action: 'clear',
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Constructs a namespaced storage key to avoid collisions
|
|
490
|
+
* @param key - The base storage key
|
|
491
|
+
* @returns Namespaced key (e.g., "theme:selectedTheme")
|
|
492
|
+
*/
|
|
493
|
+
getStorageKey(key) {
|
|
494
|
+
return `${THEME_STORAGE_NAMESPACE}${key}`;
|
|
495
|
+
}
|
|
496
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: ThemeStorageService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
497
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: ThemeStorageService, providedIn: 'root' });
|
|
498
|
+
}
|
|
499
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: ThemeStorageService, decorators: [{
|
|
500
|
+
type: Injectable,
|
|
501
|
+
args: [{ providedIn: 'root' }]
|
|
502
|
+
}] });
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* Theme Assets Service
|
|
506
|
+
* Manages dynamic asset loading and retrieval based on selected theme and color scheme
|
|
507
|
+
*
|
|
508
|
+
* Responsibilities:
|
|
509
|
+
* - Retrieve assets (images, logos, illustrations) for current theme
|
|
510
|
+
* - Provide scheme-aware asset variants (light/dark)
|
|
511
|
+
* - Cache asset references with config-based resilience strategy
|
|
512
|
+
* - Validate asset availability and provide graceful fallback through memory layers
|
|
513
|
+
*
|
|
514
|
+
* Multi-Layer Caching Strategy (Like Theme Config Persistence):
|
|
515
|
+
* - Layer 1: Current config assets (read from active RuntimeThemeConfig)
|
|
516
|
+
* - Layer 2: Last working asset config (in-memory, persists across config updates)
|
|
517
|
+
* - Falls back to last complete working config if current config breaks
|
|
518
|
+
*
|
|
519
|
+
* This matches the runtime-config and ThemeService pattern where:
|
|
520
|
+
* - User preferences/working configs are stored in memory layers
|
|
521
|
+
* - When new config fails, the last working config is used automatically
|
|
522
|
+
* - Handles asset removal, name changes, path changes, config resets
|
|
523
|
+
*/
|
|
524
|
+
class ThemeAssetsService {
|
|
525
|
+
/**
|
|
526
|
+
* Signal holding current runtime configuration reference
|
|
527
|
+
* Used to look up asset definitions for the active theme
|
|
528
|
+
*/
|
|
529
|
+
config = signal(null);
|
|
530
|
+
themeConfigs = new Map();
|
|
531
|
+
/**
|
|
532
|
+
* Layer 1: In-memory cache of resolved assets
|
|
533
|
+
* Maps "themeName:assetKey" to CachedAsset for fast retrieval
|
|
534
|
+
* Cleared when setConfig() is called to force re-resolution from new config
|
|
535
|
+
*/
|
|
536
|
+
assetCacheByTheme = new Map();
|
|
537
|
+
/**
|
|
538
|
+
* Layer 2: Last working config storage (memory-based)
|
|
539
|
+
* Stores the most recent RuntimeThemeConfig that successfully resolved assets
|
|
540
|
+
* Persists across config updates as a complete fallback mechanism
|
|
541
|
+
* Similar to ThemeService's multi-layer config persistence
|
|
542
|
+
*
|
|
543
|
+
* When current config fails to provide an asset:
|
|
544
|
+
* - Falls back to the last complete working config
|
|
545
|
+
* - Handles asset removal, name changes, path changes
|
|
546
|
+
* - Automatically restores working state on config resets
|
|
547
|
+
* - No individual URL tracking - entire config stored once per successful load
|
|
548
|
+
*/
|
|
549
|
+
lastWorkingConfigLayer = null;
|
|
550
|
+
logger = inject(LoggerService);
|
|
551
|
+
constructor() { }
|
|
552
|
+
/**
|
|
553
|
+
* Initialize service with runtime configuration
|
|
554
|
+
* Called by ThemeService after loading configuration
|
|
555
|
+
*
|
|
556
|
+
* If new config successfully resolves assets, it becomes the new fallback layer.
|
|
557
|
+
* Otherwise, previous working config persists.
|
|
558
|
+
*
|
|
559
|
+
* Only updates Layer 2 if:
|
|
560
|
+
* - Config has no PARTIAL/BROKEN assets (missing variants)
|
|
561
|
+
* - Themes can be removed entirely (that's intentional)
|
|
562
|
+
* - But existing assets must be COMPLETE (both light and dark)
|
|
563
|
+
*
|
|
564
|
+
* This ensures that accidental removals of variants trigger fallback
|
|
565
|
+
* while intentional complete removals are allowed.
|
|
566
|
+
*
|
|
567
|
+
* @param config - Runtime configuration containing asset definitions
|
|
568
|
+
*/
|
|
569
|
+
setConfig(config) {
|
|
570
|
+
this.config.set(config);
|
|
571
|
+
const hasPartialAssets = this.hasPartialAssets(config);
|
|
572
|
+
const hasValid = !hasPartialAssets;
|
|
573
|
+
this.logger.debug('setConfig called', {
|
|
574
|
+
component: 'ThemeAssetsService',
|
|
575
|
+
action: 'setConfig',
|
|
576
|
+
hasPartialAssets,
|
|
577
|
+
hasValidAssets: hasValid,
|
|
578
|
+
assets: config?.assets ? config.assets.map((asset) => asset.name) : [],
|
|
579
|
+
hasLastWorking: !!this.lastWorkingConfigLayer,
|
|
580
|
+
});
|
|
581
|
+
// Only store as last working config if it has NO partial/broken assets
|
|
582
|
+
if (hasValid) {
|
|
583
|
+
this.logger.debug('Storing config as last working config', {
|
|
584
|
+
component: 'ThemeAssetsService',
|
|
585
|
+
action: 'setConfig',
|
|
586
|
+
});
|
|
587
|
+
this.lastWorkingConfigLayer = config;
|
|
588
|
+
}
|
|
589
|
+
else {
|
|
590
|
+
this.logger.debug('Config has partial/broken assets - keeping previous last working config', {
|
|
591
|
+
component: 'ThemeAssetsService',
|
|
592
|
+
action: 'setConfig',
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
this.clearCache();
|
|
596
|
+
}
|
|
597
|
+
setThemeConfig(themeName, config) {
|
|
598
|
+
this.themeConfigs.set(themeName, config);
|
|
599
|
+
this.config.set(config);
|
|
600
|
+
this.lastWorkingConfigLayer = config;
|
|
601
|
+
this.clearCache(themeName);
|
|
602
|
+
}
|
|
603
|
+
/**
|
|
604
|
+
* Internal: Check if config has any PARTIAL/BROKEN assets
|
|
605
|
+
* Returns true if ANY asset is incomplete (missing light or dark variant)
|
|
606
|
+
*
|
|
607
|
+
* A partial asset is invalid:
|
|
608
|
+
* - { name: "logo", light: "..." } ← missing dark
|
|
609
|
+
* - { name: "logo", dark: "..." } ← missing light
|
|
610
|
+
* - { name: "logo" } ← missing both
|
|
611
|
+
*
|
|
612
|
+
* Complete removals are OK:
|
|
613
|
+
* - [] ← no assets at all (intentional)
|
|
614
|
+
* - theme: {} ← theme removed (intentional)
|
|
615
|
+
*
|
|
616
|
+
* @private
|
|
617
|
+
* @param config - Config to check
|
|
326
618
|
* @returns True if config has partial/broken assets, false if all complete or intentionally removed
|
|
327
619
|
*/
|
|
328
620
|
hasPartialAssets(config) {
|
|
329
621
|
if (!config?.assets)
|
|
330
622
|
return false;
|
|
331
|
-
|
|
332
|
-
// Problematic = partial (missing variant) OR empty (intentionally removed)
|
|
333
|
-
for (const themeName in config.assets) {
|
|
334
|
-
const themeAssets = config.assets[themeName];
|
|
335
|
-
if (this.themeHasProblematicAssets(themeAssets)) {
|
|
336
|
-
return true; // Config has issues, don't update Layer 2
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
return false; // Config is clean, can update Layer 2
|
|
623
|
+
return this.themeHasProblematicAssets(config.assets);
|
|
340
624
|
}
|
|
341
625
|
/**
|
|
342
|
-
* Internal: Check if a theme
|
|
626
|
+
* Internal: Check if a theme asset list has ANY problematic assets
|
|
343
627
|
* Problematic assets are:
|
|
344
|
-
* - Partial assets:
|
|
345
|
-
* - Empty
|
|
346
|
-
* - Broken nested assets at any level
|
|
628
|
+
* - Partial assets: missing light or dark variant
|
|
629
|
+
* - Empty assets: no variants at all
|
|
347
630
|
*
|
|
348
631
|
* NOT problematic:
|
|
349
|
-
* - Completely empty
|
|
350
|
-
* - Missing themes (not in config at all)
|
|
632
|
+
* - Completely empty list: [] (all assets intentionally removed - OK to accept)
|
|
351
633
|
*
|
|
352
634
|
* @private
|
|
353
635
|
* @param obj - Theme's asset object to check
|
|
354
636
|
* @returns True if object has problematic assets
|
|
355
637
|
*/
|
|
356
|
-
themeHasProblematicAssets(
|
|
357
|
-
if (!
|
|
638
|
+
themeHasProblematicAssets(assets) {
|
|
639
|
+
if (!assets.length) {
|
|
358
640
|
return false;
|
|
359
|
-
|
|
360
|
-
const
|
|
361
|
-
|
|
362
|
-
// No need to check further, this is a valid state
|
|
363
|
-
if (keys.length === 0) {
|
|
364
|
-
return false; // Empty theme is fine, accept config
|
|
365
|
-
}
|
|
366
|
-
// Theme has content - check all properties for problems
|
|
367
|
-
for (const key of keys) {
|
|
368
|
-
const value = record[key];
|
|
369
|
-
// Check if this value is a partial asset (has light OR dark but not both)
|
|
370
|
-
if (this.isPartialAsset(value)) {
|
|
371
|
-
return true; // Partial asset found - problematic
|
|
372
|
-
}
|
|
373
|
-
// Check if it's an empty object (asset key exists but has no content)
|
|
374
|
-
// Example: { "logo": {} } - the logo key exists but is empty
|
|
375
|
-
if (typeof value === 'object' && value !== null && Object.keys(value).length === 0) {
|
|
376
|
-
return true; // Empty asset found (key exists but broken) - problematic
|
|
377
|
-
}
|
|
378
|
-
// Recursively check for problematic nested assets
|
|
379
|
-
if (this.themeHasProblematicAssets(value)) {
|
|
641
|
+
}
|
|
642
|
+
for (const asset of assets) {
|
|
643
|
+
if (this.isPartialAsset(asset)) {
|
|
380
644
|
return true;
|
|
381
645
|
}
|
|
382
646
|
}
|
|
383
|
-
return false;
|
|
647
|
+
return false;
|
|
384
648
|
}
|
|
385
649
|
/**
|
|
386
650
|
* Internal: Check if object is a PARTIAL asset (incomplete)
|
|
@@ -390,15 +654,13 @@ class ThemeAssetsService {
|
|
|
390
654
|
* @param obj - Object to check
|
|
391
655
|
* @returns True if object is a partial/incomplete asset
|
|
392
656
|
*/
|
|
393
|
-
isPartialAsset(
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
const hasSchemeKeys = 'light' in record || 'dark' in record;
|
|
401
|
-
return hasSchemeKeys && (!hasLight || !hasDark);
|
|
657
|
+
isPartialAsset(asset) {
|
|
658
|
+
const hasLight = typeof asset.light === 'string';
|
|
659
|
+
const hasDark = typeof asset.dark === 'string';
|
|
660
|
+
if (!hasLight && !hasDark) {
|
|
661
|
+
return true;
|
|
662
|
+
}
|
|
663
|
+
return !hasLight || !hasDark;
|
|
402
664
|
}
|
|
403
665
|
/**
|
|
404
666
|
* Get asset URL for the specified scheme
|
|
@@ -435,17 +697,24 @@ class ThemeAssetsService {
|
|
|
435
697
|
* // Returns: null
|
|
436
698
|
*/
|
|
437
699
|
getAssetUrl(themeName, assetKey, scheme) {
|
|
700
|
+
const cacheKey = `${themeName}:${assetKey}`;
|
|
701
|
+
const themeCache = this.assetCacheByTheme.get(themeName);
|
|
702
|
+
const cached = themeCache?.get(cacheKey);
|
|
703
|
+
if (cached) {
|
|
704
|
+
return scheme === 'light' ? cached.light : cached.dark;
|
|
705
|
+
}
|
|
438
706
|
// Layer 1: Try to resolve from current config
|
|
439
|
-
const
|
|
707
|
+
const configToUse = this.themeConfigs.get(themeName) ?? this.config();
|
|
708
|
+
const url = this.resolveAssetUrl(themeName, assetKey, scheme, configToUse);
|
|
440
709
|
if (url) {
|
|
441
710
|
this.logger.debug('Asset resolved from current config', {
|
|
442
711
|
component: 'ThemeAssetsService',
|
|
443
712
|
action: 'getAssetUrl',
|
|
444
|
-
themeName,
|
|
445
713
|
assetKey,
|
|
446
714
|
scheme,
|
|
447
715
|
url,
|
|
448
716
|
});
|
|
717
|
+
this.cacheAsset(themeName, assetKey, configToUse);
|
|
449
718
|
return url;
|
|
450
719
|
}
|
|
451
720
|
// Layer 2: Try to resolve from last working config
|
|
@@ -456,11 +725,11 @@ class ThemeAssetsService {
|
|
|
456
725
|
component: 'ThemeAssetsService',
|
|
457
726
|
action: 'getAssetUrl',
|
|
458
727
|
fallback: true,
|
|
459
|
-
themeName,
|
|
460
728
|
assetKey,
|
|
461
729
|
scheme,
|
|
462
730
|
url: lastWorkingUrl,
|
|
463
731
|
});
|
|
732
|
+
this.cacheAsset(themeName, assetKey, this.lastWorkingConfigLayer);
|
|
464
733
|
return lastWorkingUrl;
|
|
465
734
|
}
|
|
466
735
|
}
|
|
@@ -468,7 +737,6 @@ class ThemeAssetsService {
|
|
|
468
737
|
this.logger.debug('Asset not found in any layer', {
|
|
469
738
|
component: 'ThemeAssetsService',
|
|
470
739
|
action: 'getAssetUrl',
|
|
471
|
-
themeName,
|
|
472
740
|
assetKey,
|
|
473
741
|
scheme,
|
|
474
742
|
hasLastWorking: !!this.lastWorkingConfigLayer,
|
|
@@ -492,22 +760,13 @@ class ThemeAssetsService {
|
|
|
492
760
|
* @returns URL if found and complete, null otherwise
|
|
493
761
|
*/
|
|
494
762
|
resolveAssetUrl(themeName, assetKey, scheme, configToUse) {
|
|
495
|
-
if (!configToUse?.assets
|
|
763
|
+
if (!configToUse?.assets)
|
|
496
764
|
return null;
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
for (const part of parts) {
|
|
502
|
-
if (!current || typeof current !== 'object')
|
|
503
|
-
return null;
|
|
504
|
-
current = current[part];
|
|
505
|
-
}
|
|
506
|
-
// Check if it's a valid asset with the requested scheme
|
|
507
|
-
if (!this.isThemeAsset(current))
|
|
765
|
+
if (configToUse.meta?.name && configToUse.meta.name !== themeName)
|
|
766
|
+
return null;
|
|
767
|
+
const asset = this.findAsset(configToUse.assets, assetKey);
|
|
768
|
+
if (!asset || !this.isThemeAsset(asset))
|
|
508
769
|
return null;
|
|
509
|
-
// Asset must be complete (have both variants) - return requested variant
|
|
510
|
-
const asset = current;
|
|
511
770
|
const url = scheme === 'light' ? asset.light : asset.dark;
|
|
512
771
|
// Return null if variant is missing (indicates incomplete asset)
|
|
513
772
|
return url || null;
|
|
@@ -526,8 +785,9 @@ class ThemeAssetsService {
|
|
|
526
785
|
*/
|
|
527
786
|
getAsset(themeName, assetKey) {
|
|
528
787
|
// Try current config first
|
|
529
|
-
|
|
530
|
-
let
|
|
788
|
+
const configToUse = this.themeConfigs.get(themeName) ?? this.config();
|
|
789
|
+
let light = this.resolveAssetUrl(themeName, assetKey, 'light', configToUse);
|
|
790
|
+
let dark = this.resolveAssetUrl(themeName, assetKey, 'dark', configToUse);
|
|
531
791
|
// If not available in current config, try last working config
|
|
532
792
|
if ((!light || !dark) && this.lastWorkingConfigLayer) {
|
|
533
793
|
if (!light)
|
|
@@ -537,6 +797,7 @@ class ThemeAssetsService {
|
|
|
537
797
|
}
|
|
538
798
|
// Return asset if at least one variant found
|
|
539
799
|
if (light || dark) {
|
|
800
|
+
this.cacheAsset(themeName, assetKey, configToUse ?? this.lastWorkingConfigLayer);
|
|
540
801
|
return { light: light || undefined, dark: dark || undefined };
|
|
541
802
|
}
|
|
542
803
|
return null;
|
|
@@ -555,7 +816,8 @@ class ThemeAssetsService {
|
|
|
555
816
|
*/
|
|
556
817
|
hasAsset(themeName, assetKey) {
|
|
557
818
|
// Check if asset exists in current config
|
|
558
|
-
|
|
819
|
+
const configToUse = this.themeConfigs.get(themeName) ?? this.config();
|
|
820
|
+
if (this.resolveAssetUrl(themeName, assetKey, 'light', configToUse) || this.resolveAssetUrl(themeName, assetKey, 'dark', configToUse)) {
|
|
559
821
|
return true;
|
|
560
822
|
}
|
|
561
823
|
// Check if asset exists in last working config
|
|
@@ -575,10 +837,12 @@ class ThemeAssetsService {
|
|
|
575
837
|
* @returns All assets for the theme, or null if theme has no assets
|
|
576
838
|
*/
|
|
577
839
|
getThemeAssets(themeName) {
|
|
578
|
-
const cfg = this.config();
|
|
579
|
-
if (!cfg?.assets
|
|
840
|
+
const cfg = this.themeConfigs.get(themeName) ?? this.config();
|
|
841
|
+
if (!cfg?.assets)
|
|
580
842
|
return null;
|
|
581
|
-
|
|
843
|
+
if (cfg.meta?.name && cfg.meta.name !== themeName)
|
|
844
|
+
return null;
|
|
845
|
+
return cfg.assets;
|
|
582
846
|
}
|
|
583
847
|
/**
|
|
584
848
|
* Manually clear the asset cache
|
|
@@ -598,8 +862,27 @@ class ThemeAssetsService {
|
|
|
598
862
|
* assetsService.clearCache();
|
|
599
863
|
* assetsService.setConfig(currentConfig);
|
|
600
864
|
*/
|
|
601
|
-
clearCache() {
|
|
602
|
-
|
|
865
|
+
clearCache(themeName) {
|
|
866
|
+
if (themeName) {
|
|
867
|
+
this.assetCacheByTheme.delete(themeName);
|
|
868
|
+
return;
|
|
869
|
+
}
|
|
870
|
+
this.assetCacheByTheme.clear();
|
|
871
|
+
}
|
|
872
|
+
async prefetchAssets(themeName) {
|
|
873
|
+
const cfg = this.themeConfigs.get(themeName) ?? this.config();
|
|
874
|
+
if (!cfg?.assets) {
|
|
875
|
+
return;
|
|
876
|
+
}
|
|
877
|
+
if (cfg.meta?.name && cfg.meta.name !== themeName) {
|
|
878
|
+
return;
|
|
879
|
+
}
|
|
880
|
+
const urls = new Set();
|
|
881
|
+
this.collectAssetUrls(cfg.assets, urls);
|
|
882
|
+
await Promise.allSettled([...urls].map((url) => fetch(url, {
|
|
883
|
+
method: 'GET',
|
|
884
|
+
cache: 'no-store',
|
|
885
|
+
}).catch(() => undefined)));
|
|
603
886
|
}
|
|
604
887
|
/**
|
|
605
888
|
* Internal: Type guard to validate ThemeAsset structure
|
|
@@ -625,6 +908,40 @@ class ThemeAssetsService {
|
|
|
625
908
|
// Valid only if BOTH variants are present
|
|
626
909
|
return hasLight && hasDark;
|
|
627
910
|
}
|
|
911
|
+
collectAssetUrls(assets, urls) {
|
|
912
|
+
for (const asset of assets) {
|
|
913
|
+
if (!this.isThemeAsset(asset)) {
|
|
914
|
+
continue;
|
|
915
|
+
}
|
|
916
|
+
if (asset.light)
|
|
917
|
+
urls.add(asset.light);
|
|
918
|
+
if (asset.dark)
|
|
919
|
+
urls.add(asset.dark);
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
findAsset(assets, assetKey) {
|
|
923
|
+
return assets.find((asset) => asset.name === assetKey) ?? null;
|
|
924
|
+
}
|
|
925
|
+
cacheAsset(themeName, assetKey, config) {
|
|
926
|
+
if (!config) {
|
|
927
|
+
return;
|
|
928
|
+
}
|
|
929
|
+
const light = this.resolveAssetUrl(themeName, assetKey, 'light', config);
|
|
930
|
+
const dark = this.resolveAssetUrl(themeName, assetKey, 'dark', config);
|
|
931
|
+
if (!light && !dark) {
|
|
932
|
+
return;
|
|
933
|
+
}
|
|
934
|
+
const cacheKey = `${themeName}:${assetKey}`;
|
|
935
|
+
if (!this.assetCacheByTheme.has(themeName)) {
|
|
936
|
+
this.assetCacheByTheme.set(themeName, new Map());
|
|
937
|
+
}
|
|
938
|
+
this.assetCacheByTheme.get(themeName)?.set(cacheKey, {
|
|
939
|
+
themeName,
|
|
940
|
+
assetKey,
|
|
941
|
+
light: light ?? null,
|
|
942
|
+
dark: dark ?? null,
|
|
943
|
+
});
|
|
944
|
+
}
|
|
628
945
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: ThemeAssetsService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
629
946
|
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: ThemeAssetsService, providedIn: 'root' });
|
|
630
947
|
}
|
|
@@ -644,12 +961,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.0", ngImpor
|
|
|
644
961
|
* Decouples DOM operations from business logic
|
|
645
962
|
*/
|
|
646
963
|
class ThemeDomService {
|
|
647
|
-
rendererFactory;
|
|
648
|
-
document;
|
|
649
964
|
renderer;
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
965
|
+
rendererFactory = inject(RendererFactory2);
|
|
966
|
+
document = inject(DOCUMENT);
|
|
967
|
+
constructor() {
|
|
653
968
|
this.renderer = this.rendererFactory.createRenderer(null, null);
|
|
654
969
|
}
|
|
655
970
|
/**
|
|
@@ -685,6 +1000,18 @@ class ThemeDomService {
|
|
|
685
1000
|
this.appendStyleToHead(styleContent);
|
|
686
1001
|
}
|
|
687
1002
|
}
|
|
1003
|
+
/**
|
|
1004
|
+
* Injects CSS variables for a single theme only
|
|
1005
|
+
* @param themeName - Theme key
|
|
1006
|
+
* @param variants - Theme variants to inject
|
|
1007
|
+
*/
|
|
1008
|
+
injectSingleThemeStyles(themeName, variants) {
|
|
1009
|
+
const styleBlocks = this.buildThemeVariantStyles(themeName, variants);
|
|
1010
|
+
const styleContent = styleBlocks.filter((content) => content.length > 0).join('\n\n');
|
|
1011
|
+
if (styleContent) {
|
|
1012
|
+
this.replaceThemeStyle(themeName, styleContent);
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
688
1015
|
/**
|
|
689
1016
|
* Sets the active theme on the document body
|
|
690
1017
|
* Uses data-theme attribute for CSS theme targeting
|
|
@@ -764,7 +1091,8 @@ class ThemeDomService {
|
|
|
764
1091
|
*/
|
|
765
1092
|
buildThemeVariantRule(themeName, scheme, variables) {
|
|
766
1093
|
const selector = `[${THEME_ATTRIBUTE_NAME}="${themeName}${THEME_SCHEME_SEPARATOR}${scheme}"]`;
|
|
767
|
-
const
|
|
1094
|
+
const flattened = this.flattenVariables(variables);
|
|
1095
|
+
const declarations = Object.entries(flattened)
|
|
768
1096
|
.map(([key, value]) => `\t${key}: ${value};`)
|
|
769
1097
|
.join('\n');
|
|
770
1098
|
return `${selector} {
|
|
@@ -781,161 +1109,33 @@ ${declarations}
|
|
|
781
1109
|
style.textContent = content;
|
|
782
1110
|
this.renderer.appendChild(this.document.head, style);
|
|
783
1111
|
}
|
|
784
|
-
|
|
1112
|
+
flattenVariables(variables) {
|
|
1113
|
+
return {
|
|
1114
|
+
...variables.colors,
|
|
1115
|
+
...variables.radius,
|
|
1116
|
+
...variables.sizes,
|
|
1117
|
+
...variables.effects,
|
|
1118
|
+
...variables.others,
|
|
1119
|
+
};
|
|
1120
|
+
}
|
|
1121
|
+
replaceThemeStyle(themeName, content) {
|
|
1122
|
+
const existing = this.document.head.querySelector(`style[data-theme-style="${themeName}"]`);
|
|
1123
|
+
if (existing) {
|
|
1124
|
+
existing.textContent = content;
|
|
1125
|
+
return;
|
|
1126
|
+
}
|
|
1127
|
+
const style = this.renderer.createElement('style');
|
|
1128
|
+
style.textContent = content;
|
|
1129
|
+
style.setAttribute('data-theme-style', themeName);
|
|
1130
|
+
this.renderer.appendChild(this.document.head, style);
|
|
1131
|
+
}
|
|
1132
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: ThemeDomService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
785
1133
|
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: ThemeDomService, providedIn: 'root' });
|
|
786
1134
|
}
|
|
787
1135
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: ThemeDomService, decorators: [{
|
|
788
1136
|
type: Injectable,
|
|
789
1137
|
args: [{ providedIn: 'root' }]
|
|
790
|
-
}], ctorParameters: () => [
|
|
791
|
-
type: Inject,
|
|
792
|
-
args: [DOCUMENT]
|
|
793
|
-
}] }] });
|
|
794
|
-
|
|
795
|
-
/**
|
|
796
|
-
* Theme Utility Functions
|
|
797
|
-
* Pure, side-effect-free utilities for theme logic
|
|
798
|
-
*/
|
|
799
|
-
/**
|
|
800
|
-
* Validates that a given value is a valid theme scheme
|
|
801
|
-
* @param value - The value to validate
|
|
802
|
-
* @returns True if the value is a valid scheme ('system', 'light', or 'dark')
|
|
803
|
-
*/
|
|
804
|
-
function isValidScheme(value) {
|
|
805
|
-
return typeof value === 'string' && VALID_SCHEMES.includes(value);
|
|
806
|
-
}
|
|
807
|
-
/**
|
|
808
|
-
* Builds the final theme identifier by combining theme name and scheme
|
|
809
|
-
* @param themeName - The name of the theme
|
|
810
|
-
* @param scheme - The scheme variant (light or dark)
|
|
811
|
-
* @returns Combined identifier (e.g., "sixbell_telco__light")
|
|
812
|
-
*/
|
|
813
|
-
function buildThemeIdentifier(themeName, scheme) {
|
|
814
|
-
return `${themeName}__${scheme}`;
|
|
815
|
-
}
|
|
816
|
-
/**
|
|
817
|
-
* Extracts theme name and scheme from a combined identifier
|
|
818
|
-
* @param identifier - The combined identifier (e.g., "sixbell_telco__light")
|
|
819
|
-
* @returns Object with extracted themeName and scheme
|
|
820
|
-
*/
|
|
821
|
-
function parseThemeIdentifier(identifier) {
|
|
822
|
-
const [themeName, scheme] = identifier.split('__');
|
|
823
|
-
return { themeName, scheme };
|
|
824
|
-
}
|
|
825
|
-
/**
|
|
826
|
-
* Builds the list of available themes from configuration
|
|
827
|
-
* Starts with default base theme, adds additional themes, and filters exclusions
|
|
828
|
-
* Removes duplicates and returns sorted list
|
|
829
|
-
* @param additionalThemes - Additional themes to include
|
|
830
|
-
* @param excludeThemes - Themes to exclude
|
|
831
|
-
* @returns Deduplicated list of available themes
|
|
832
|
-
*/
|
|
833
|
-
function buildAvailableThemes(additionalThemes, excludeThemes) {
|
|
834
|
-
// Start with base theme
|
|
835
|
-
let themes = [DEFAULT_BASE_THEME];
|
|
836
|
-
// Add additional themes
|
|
837
|
-
if (additionalThemes && additionalThemes.length > 0) {
|
|
838
|
-
themes = [DEFAULT_BASE_THEME, ...additionalThemes];
|
|
839
|
-
}
|
|
840
|
-
// Filter exclusions
|
|
841
|
-
if (excludeThemes && excludeThemes.length > 0) {
|
|
842
|
-
themes = themes.filter((theme) => !excludeThemes.includes(theme));
|
|
843
|
-
}
|
|
844
|
-
// Remove duplicates and maintain consistency
|
|
845
|
-
return [...new Set(themes)];
|
|
846
|
-
}
|
|
847
|
-
/**
|
|
848
|
-
* Determines the effective default theme from configuration
|
|
849
|
-
* Ensures the default theme is in the available themes list
|
|
850
|
-
* Falls back to first available theme if default is not available
|
|
851
|
-
* @param defaultTheme - Configured default theme
|
|
852
|
-
* @param availableThemes - List of available themes
|
|
853
|
-
* @returns The effective default theme to use
|
|
854
|
-
*/
|
|
855
|
-
function resolveDefaultTheme(defaultTheme, availableThemes) {
|
|
856
|
-
// Use provided default if valid
|
|
857
|
-
if (defaultTheme && availableThemes.includes(defaultTheme)) {
|
|
858
|
-
return defaultTheme;
|
|
859
|
-
}
|
|
860
|
-
// Check if base theme is available
|
|
861
|
-
if (availableThemes.includes(DEFAULT_BASE_THEME)) {
|
|
862
|
-
return DEFAULT_BASE_THEME;
|
|
863
|
-
}
|
|
864
|
-
// Fallback to first available
|
|
865
|
-
return availableThemes[0] || DEFAULT_BASE_THEME;
|
|
866
|
-
}
|
|
867
|
-
/**
|
|
868
|
-
* Validates that a given theme exists in the available themes
|
|
869
|
-
* @param theme - Theme name to validate
|
|
870
|
-
* @param availableThemes - List of available themes
|
|
871
|
-
* @returns True if theme is available
|
|
872
|
-
*/
|
|
873
|
-
function isThemeAvailable(theme, availableThemes) {
|
|
874
|
-
return availableThemes.includes(theme);
|
|
875
|
-
}
|
|
876
|
-
/**
|
|
877
|
-
* Validates the configuration and logs warnings for invalid states
|
|
878
|
-
* Returns true if configuration is valid for use
|
|
879
|
-
* @param config - Configuration to validate
|
|
880
|
-
* @param configName - Name of config for logging purposes
|
|
881
|
-
* @returns True if configuration is valid
|
|
882
|
-
*/
|
|
883
|
-
function validateThemeConfig(config, configName = 'ThemeConfig') {
|
|
884
|
-
const errors = [];
|
|
885
|
-
if (!config.availableThemes || config.availableThemes.length === 0) {
|
|
886
|
-
errors.push('availableThemes must be a non-empty array');
|
|
887
|
-
}
|
|
888
|
-
if (!config.defaultTheme) {
|
|
889
|
-
errors.push('defaultTheme must be defined');
|
|
890
|
-
}
|
|
891
|
-
if (config.defaultTheme && !config.availableThemes.includes(config.defaultTheme)) {
|
|
892
|
-
errors.push(`defaultTheme '${config.defaultTheme}' not in availableThemes`);
|
|
893
|
-
}
|
|
894
|
-
if (errors.length > 0) {
|
|
895
|
-
console.error(`${configName} validation failed:`, errors.join(', '));
|
|
896
|
-
return false;
|
|
897
|
-
}
|
|
898
|
-
return true;
|
|
899
|
-
}
|
|
900
|
-
/**
|
|
901
|
-
* Formats a theme name for display to users
|
|
902
|
-
* Converts snake_case to Title Case
|
|
903
|
-
* @param theme - Theme name to format
|
|
904
|
-
* @returns Formatted theme name
|
|
905
|
-
*/
|
|
906
|
-
function formatThemeName(theme) {
|
|
907
|
-
return theme.replace(/_/g, ' ').replace(/\b\w/g, (l) => l.toUpperCase());
|
|
908
|
-
}
|
|
909
|
-
/**
|
|
910
|
-
* Formats a scheme name for display to users
|
|
911
|
-
* Capitalizes first letter
|
|
912
|
-
* @param scheme - Scheme name to format
|
|
913
|
-
* @returns Formatted scheme name
|
|
914
|
-
*/
|
|
915
|
-
function formatSchemeName(scheme) {
|
|
916
|
-
return scheme.charAt(0).toUpperCase() + scheme.slice(1);
|
|
917
|
-
}
|
|
918
|
-
/**
|
|
919
|
-
* Checks if the browser supports the matchMedia API
|
|
920
|
-
* Safe to call in non-browser environments
|
|
921
|
-
* @returns True if matchMedia is available
|
|
922
|
-
*/
|
|
923
|
-
function supportsMediaQuery() {
|
|
924
|
-
return typeof window !== 'undefined' && typeof window.matchMedia === 'function';
|
|
925
|
-
}
|
|
926
|
-
/**
|
|
927
|
-
* Checks if localStorage is available in the current environment
|
|
928
|
-
* Safe to call in non-browser environments
|
|
929
|
-
* @returns True if localStorage is accessible
|
|
930
|
-
*/
|
|
931
|
-
function hasLocalStorage() {
|
|
932
|
-
try {
|
|
933
|
-
return typeof window !== 'undefined' && typeof localStorage !== 'undefined' && localStorage !== null;
|
|
934
|
-
}
|
|
935
|
-
catch {
|
|
936
|
-
return false;
|
|
937
|
-
}
|
|
938
|
-
}
|
|
1138
|
+
}], ctorParameters: () => [] });
|
|
939
1139
|
|
|
940
1140
|
/**
|
|
941
1141
|
* Theme Scheme Resolver Service
|
|
@@ -947,230 +1147,99 @@ function hasLocalStorage() {
|
|
|
947
1147
|
* Separates scheme logic from the main service
|
|
948
1148
|
*/
|
|
949
1149
|
class ThemeSchemeService {
|
|
950
|
-
/**
|
|
951
|
-
* Media query list for detecting dark mode preference
|
|
952
|
-
* Cached to avoid repeated queries
|
|
953
|
-
*/
|
|
954
|
-
darkModeMediaQuery = null;
|
|
955
|
-
/**
|
|
956
|
-
* Resolves a theme scheme to its actual light/dark value
|
|
957
|
-
* If scheme is 'system', detects the OS preference
|
|
958
|
-
* If scheme is already 'light' or 'dark', returns it as-is
|
|
959
|
-
* @param scheme - The scheme to resolve
|
|
960
|
-
* @returns Resolved scheme ('light' or 'dark')
|
|
961
|
-
*/
|
|
962
|
-
resolveScheme(scheme) {
|
|
963
|
-
if (scheme === 'system') {
|
|
964
|
-
return this.detectSystemScheme();
|
|
965
|
-
}
|
|
966
|
-
return scheme;
|
|
967
|
-
}
|
|
968
|
-
/**
|
|
969
|
-
* Detects the system's preferred color scheme
|
|
970
|
-
* Uses CSS media query (prefers-color-scheme: dark)
|
|
971
|
-
* Safely handles environments where matchMedia is not available
|
|
972
|
-
* @returns 'dark' if system prefers dark, 'light' otherwise
|
|
973
|
-
*/
|
|
974
|
-
detectSystemScheme() {
|
|
975
|
-
if (!supportsMediaQuery()) {
|
|
976
|
-
// Fallback to light in non-browser environments
|
|
977
|
-
return 'light';
|
|
978
|
-
}
|
|
979
|
-
// Use cached media query list if available
|
|
980
|
-
if (!this.darkModeMediaQuery) {
|
|
981
|
-
this.darkModeMediaQuery = this.createMediaQuery();
|
|
982
|
-
}
|
|
983
|
-
return this.darkModeMediaQuery.matches ? 'dark' : 'light';
|
|
984
|
-
}
|
|
985
|
-
/**
|
|
986
|
-
* Listens for changes in system color scheme preference
|
|
987
|
-
* Allows components to react to OS theme changes
|
|
988
|
-
* @param listener - Callback function when scheme changes
|
|
989
|
-
* @returns Unsubscribe function to remove listener
|
|
990
|
-
*/
|
|
991
|
-
listenToSystemSchemeChanges(listener) {
|
|
992
|
-
if (!supportsMediaQuery()) {
|
|
993
|
-
// Return no-op unsubscribe function if matchMedia not available
|
|
994
|
-
return () => { };
|
|
995
|
-
}
|
|
996
|
-
const mediaQuery = this.createMediaQuery();
|
|
997
|
-
const handleChange = (e) => {
|
|
998
|
-
listener(e.matches ? 'dark' : 'light');
|
|
999
|
-
};
|
|
1000
|
-
// Use addEventListener for modern browsers
|
|
1001
|
-
if (mediaQuery.addEventListener) {
|
|
1002
|
-
mediaQuery.addEventListener('change', handleChange);
|
|
1003
|
-
return () => mediaQuery.removeEventListener('change', handleChange);
|
|
1004
|
-
}
|
|
1005
|
-
// Fallback for older browsers using addListener (deprecated but supported)
|
|
1006
|
-
const legacyMediaQuery = mediaQuery;
|
|
1007
|
-
legacyMediaQuery.addListener?.(handleChange);
|
|
1008
|
-
return () => legacyMediaQuery.removeListener?.(handleChange);
|
|
1009
|
-
}
|
|
1010
|
-
/**
|
|
1011
|
-
* Creates a media query for detecting dark mode
|
|
1012
|
-
* Extracted method to make testing easier
|
|
1013
|
-
* @returns MediaQueryList for dark mode preference
|
|
1014
|
-
*/
|
|
1015
|
-
createMediaQuery() {
|
|
1016
|
-
return window.matchMedia(DARK_MODE_MEDIA_QUERY);
|
|
1017
|
-
}
|
|
1018
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: ThemeSchemeService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1019
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: ThemeSchemeService, providedIn: 'root' });
|
|
1020
|
-
}
|
|
1021
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: ThemeSchemeService, decorators: [{
|
|
1022
|
-
type: Injectable,
|
|
1023
|
-
args: [{ providedIn: 'root' }]
|
|
1024
|
-
}] });
|
|
1025
|
-
|
|
1026
|
-
/**
|
|
1027
|
-
* Theme Storage Service
|
|
1028
|
-
* Handles persistent theme preferences using localStorage
|
|
1029
|
-
*/
|
|
1030
|
-
/**
|
|
1031
|
-
* Service for managing theme preferences in local storage
|
|
1032
|
-
* Provides safe access to localStorage with error handling
|
|
1033
|
-
* Works gracefully in non-browser environments (SSR)
|
|
1034
|
-
*/
|
|
1035
|
-
class ThemeStorageService {
|
|
1036
|
-
logger = inject(LoggerService);
|
|
1037
|
-
/**
|
|
1038
|
-
* Retrieves the saved theme preference from localStorage
|
|
1039
|
-
* Returns null if no saved preference or storage unavailable
|
|
1040
|
-
* @returns Saved theme name or null
|
|
1041
|
-
*/
|
|
1042
|
-
getSavedTheme() {
|
|
1043
|
-
try {
|
|
1044
|
-
if (!hasLocalStorage()) {
|
|
1045
|
-
return null;
|
|
1046
|
-
}
|
|
1047
|
-
const key = this.getStorageKey(THEME_STORAGE_THEME_KEY);
|
|
1048
|
-
return localStorage.getItem(key);
|
|
1049
|
-
}
|
|
1050
|
-
catch (error) {
|
|
1051
|
-
this.logger.error('Failed to retrieve saved theme', error, {
|
|
1052
|
-
component: 'ThemeStorageService',
|
|
1053
|
-
action: 'getSavedTheme',
|
|
1054
|
-
});
|
|
1055
|
-
return null;
|
|
1056
|
-
}
|
|
1057
|
-
}
|
|
1058
|
-
/**
|
|
1059
|
-
* Saves the current theme preference to localStorage
|
|
1060
|
-
* Fails silently if storage is unavailable
|
|
1061
|
-
* @param theme - Theme name to save
|
|
1062
|
-
*/
|
|
1063
|
-
saveTheme(theme) {
|
|
1064
|
-
try {
|
|
1065
|
-
if (!hasLocalStorage()) {
|
|
1066
|
-
return;
|
|
1067
|
-
}
|
|
1068
|
-
const key = this.getStorageKey(THEME_STORAGE_THEME_KEY);
|
|
1069
|
-
localStorage.setItem(key, theme);
|
|
1070
|
-
}
|
|
1071
|
-
catch (error) {
|
|
1072
|
-
this.logger.error('Failed to save theme', error, {
|
|
1073
|
-
component: 'ThemeStorageService',
|
|
1074
|
-
action: 'saveTheme',
|
|
1075
|
-
theme,
|
|
1076
|
-
});
|
|
1077
|
-
}
|
|
1078
|
-
}
|
|
1079
|
-
/**
|
|
1080
|
-
* Retrieves the saved scheme preference from localStorage
|
|
1081
|
-
* Returns null if no saved preference or storage unavailable
|
|
1082
|
-
* @returns Saved scheme ('system', 'light', 'dark') or null
|
|
1083
|
-
*/
|
|
1084
|
-
getSavedScheme() {
|
|
1085
|
-
try {
|
|
1086
|
-
if (!hasLocalStorage()) {
|
|
1087
|
-
return null;
|
|
1088
|
-
}
|
|
1089
|
-
const key = this.getStorageKey(THEME_STORAGE_SCHEME_KEY);
|
|
1090
|
-
return localStorage.getItem(key);
|
|
1091
|
-
}
|
|
1092
|
-
catch (error) {
|
|
1093
|
-
this.logger.error('Failed to retrieve saved scheme', error, {
|
|
1094
|
-
component: 'ThemeStorageService',
|
|
1095
|
-
action: 'getSavedScheme',
|
|
1096
|
-
});
|
|
1097
|
-
return null;
|
|
1150
|
+
/**
|
|
1151
|
+
* Media query list for detecting dark mode preference
|
|
1152
|
+
* Cached to avoid repeated queries
|
|
1153
|
+
*/
|
|
1154
|
+
darkModeMediaQuery = null;
|
|
1155
|
+
/**
|
|
1156
|
+
* Resolves a theme scheme to its actual light/dark value
|
|
1157
|
+
* If scheme is 'system', detects the OS preference
|
|
1158
|
+
* If scheme is already 'light' or 'dark', returns it as-is
|
|
1159
|
+
* @param scheme - The scheme to resolve
|
|
1160
|
+
* @returns Resolved scheme ('light' or 'dark')
|
|
1161
|
+
*/
|
|
1162
|
+
resolveScheme(scheme) {
|
|
1163
|
+
if (scheme === 'system') {
|
|
1164
|
+
return this.detectSystemScheme();
|
|
1098
1165
|
}
|
|
1166
|
+
return scheme;
|
|
1099
1167
|
}
|
|
1100
1168
|
/**
|
|
1101
|
-
*
|
|
1102
|
-
*
|
|
1103
|
-
*
|
|
1169
|
+
* Detects the system's preferred color scheme
|
|
1170
|
+
* Uses CSS media query (prefers-color-scheme: dark)
|
|
1171
|
+
* Safely handles environments where matchMedia is not available
|
|
1172
|
+
* @returns 'dark' if system prefers dark, 'light' otherwise
|
|
1104
1173
|
*/
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
}
|
|
1110
|
-
const key = this.getStorageKey(THEME_STORAGE_SCHEME_KEY);
|
|
1111
|
-
localStorage.setItem(key, scheme);
|
|
1174
|
+
detectSystemScheme() {
|
|
1175
|
+
if (!supportsMediaQuery()) {
|
|
1176
|
+
// Fallback to light in non-browser environments
|
|
1177
|
+
return 'light';
|
|
1112
1178
|
}
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
action: 'saveScheme',
|
|
1117
|
-
scheme,
|
|
1118
|
-
});
|
|
1179
|
+
// Use cached media query list if available
|
|
1180
|
+
if (!this.darkModeMediaQuery) {
|
|
1181
|
+
this.darkModeMediaQuery = this.createMediaQuery();
|
|
1119
1182
|
}
|
|
1183
|
+
return this.darkModeMediaQuery.matches ? 'dark' : 'light';
|
|
1120
1184
|
}
|
|
1121
1185
|
/**
|
|
1122
|
-
*
|
|
1123
|
-
*
|
|
1186
|
+
* Listens for changes in system color scheme preference
|
|
1187
|
+
* Allows components to react to OS theme changes
|
|
1188
|
+
* @param listener - Callback function when scheme changes
|
|
1189
|
+
* @returns Unsubscribe function to remove listener
|
|
1124
1190
|
*/
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
if
|
|
1128
|
-
|
|
1129
|
-
}
|
|
1130
|
-
const themeKey = this.getStorageKey(THEME_STORAGE_THEME_KEY);
|
|
1131
|
-
const schemeKey = this.getStorageKey(THEME_STORAGE_SCHEME_KEY);
|
|
1132
|
-
localStorage.removeItem(themeKey);
|
|
1133
|
-
localStorage.removeItem(schemeKey);
|
|
1191
|
+
listenToSystemSchemeChanges(listener) {
|
|
1192
|
+
if (!supportsMediaQuery()) {
|
|
1193
|
+
// Return no-op unsubscribe function if matchMedia not available
|
|
1194
|
+
return () => { };
|
|
1134
1195
|
}
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1196
|
+
const mediaQuery = this.createMediaQuery();
|
|
1197
|
+
const handleChange = (e) => {
|
|
1198
|
+
listener(e.matches ? 'dark' : 'light');
|
|
1199
|
+
};
|
|
1200
|
+
// Use addEventListener for modern browsers
|
|
1201
|
+
if (mediaQuery.addEventListener) {
|
|
1202
|
+
mediaQuery.addEventListener('change', handleChange);
|
|
1203
|
+
return () => mediaQuery.removeEventListener('change', handleChange);
|
|
1140
1204
|
}
|
|
1205
|
+
// Fallback for older browsers using addListener (deprecated but supported)
|
|
1206
|
+
const legacyMediaQuery = mediaQuery;
|
|
1207
|
+
legacyMediaQuery.addListener?.(handleChange);
|
|
1208
|
+
return () => legacyMediaQuery.removeListener?.(handleChange);
|
|
1141
1209
|
}
|
|
1142
1210
|
/**
|
|
1143
|
-
*
|
|
1144
|
-
*
|
|
1145
|
-
* @returns
|
|
1211
|
+
* Creates a media query for detecting dark mode
|
|
1212
|
+
* Extracted method to make testing easier
|
|
1213
|
+
* @returns MediaQueryList for dark mode preference
|
|
1146
1214
|
*/
|
|
1147
|
-
|
|
1148
|
-
return
|
|
1215
|
+
createMediaQuery() {
|
|
1216
|
+
return window.matchMedia(DARK_MODE_MEDIA_QUERY);
|
|
1149
1217
|
}
|
|
1150
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type:
|
|
1151
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type:
|
|
1218
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: ThemeSchemeService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1219
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: ThemeSchemeService, providedIn: 'root' });
|
|
1152
1220
|
}
|
|
1153
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type:
|
|
1221
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: ThemeSchemeService, decorators: [{
|
|
1154
1222
|
type: Injectable,
|
|
1155
1223
|
args: [{ providedIn: 'root' }]
|
|
1156
1224
|
}] });
|
|
1157
1225
|
|
|
1158
1226
|
class ThemeService {
|
|
1159
|
-
themeConfig;
|
|
1160
|
-
runtimeThemeConfig;
|
|
1161
1227
|
translationService = inject(TranslationService);
|
|
1162
1228
|
domService = inject(ThemeDomService);
|
|
1163
1229
|
storageService = inject(ThemeStorageService);
|
|
1164
1230
|
schemeResolver = inject(ThemeSchemeService);
|
|
1165
1231
|
assetsService = inject(ThemeAssetsService);
|
|
1166
|
-
router = inject(Router);
|
|
1167
1232
|
logger = inject(LoggerService);
|
|
1168
|
-
runtimeConfigPath;
|
|
1169
|
-
runtimeLoader;
|
|
1170
|
-
runtimeLoaderOptions;
|
|
1171
|
-
navigationSubscription;
|
|
1172
|
-
skipFirstNavigation = true;
|
|
1173
1233
|
isUsingFallbackConfig = false;
|
|
1234
|
+
runtimeHash = null;
|
|
1235
|
+
runtimeLoader;
|
|
1236
|
+
runtimeThemes = new Map();
|
|
1237
|
+
runtimeEventHashes = new Map();
|
|
1238
|
+
pendingUpdatedThemes = new Set();
|
|
1239
|
+
appliedThemeNames = new Set();
|
|
1240
|
+
refreshHandler;
|
|
1241
|
+
updateAvailable = signal(false);
|
|
1242
|
+
lastRefreshFailed = signal(false);
|
|
1174
1243
|
config = {
|
|
1175
1244
|
availableThemes: [DEFAULT_BASE_THEME],
|
|
1176
1245
|
defaultTheme: DEFAULT_BASE_THEME,
|
|
@@ -1188,97 +1257,41 @@ class ThemeService {
|
|
|
1188
1257
|
const scheme = this.resolvedScheme();
|
|
1189
1258
|
return buildThemeIdentifier(theme, scheme);
|
|
1190
1259
|
});
|
|
1191
|
-
constructor(
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
if (themeConfig) {
|
|
1195
|
-
this.configure(themeConfig);
|
|
1196
|
-
}
|
|
1197
|
-
else {
|
|
1198
|
-
// Don't call initializeFromStorage here - the runtime config might not be loaded yet
|
|
1199
|
-
// If we restore from storage now and the theme isn't available, we'll save the wrong value back
|
|
1200
|
-
// The runtime provider will call configureRuntime() which will properly restore from storage
|
|
1201
|
-
}
|
|
1202
|
-
}
|
|
1203
|
-
configure(config = {}) {
|
|
1204
|
-
const availableThemes = buildAvailableThemes(config.additionalThemes, config.excludeThemes);
|
|
1205
|
-
const defaultTheme = resolveDefaultTheme(config.defaultTheme, availableThemes);
|
|
1206
|
-
this.config = {
|
|
1207
|
-
availableThemes,
|
|
1208
|
-
defaultTheme,
|
|
1209
|
-
defaultScheme: config.defaultScheme || DEFAULT_SCHEME,
|
|
1210
|
-
};
|
|
1211
|
-
validateThemeConfig(this.config, 'ThemeService.configure');
|
|
1212
|
-
this.selectedTheme.set(this.config.defaultTheme);
|
|
1213
|
-
this.selectedScheme.set(this.config.defaultScheme);
|
|
1214
|
-
this.initializeFromStorage();
|
|
1215
|
-
this.applyTheme();
|
|
1216
|
-
}
|
|
1217
|
-
configureRuntime(config) {
|
|
1218
|
-
// Note: isUsingFallbackConfig is set via configureRuntimeWithSource() or left from previous call
|
|
1219
|
-
// This keeps configureRuntime compatible with existing code while allowing precise tracking
|
|
1220
|
-
if (config.fonts && config.fonts.length > 0) {
|
|
1221
|
-
this.domService.injectFonts(config.fonts);
|
|
1222
|
-
}
|
|
1223
|
-
if (config.globalVariables) {
|
|
1224
|
-
this.domService.injectGlobalVariables(config.globalVariables);
|
|
1225
|
-
}
|
|
1226
|
-
if (config.themes) {
|
|
1227
|
-
this.domService.injectThemeStyles(config.themes);
|
|
1228
|
-
}
|
|
1229
|
-
// Initialize assets service with configuration
|
|
1230
|
-
this.assetsService.setConfig(config);
|
|
1231
|
-
if (!config.themes || !Object.keys(config.themes).length) {
|
|
1260
|
+
constructor() { }
|
|
1261
|
+
async configureRuntime(config, themeName, options) {
|
|
1262
|
+
if (!config.themes) {
|
|
1232
1263
|
this.logger.error('Invalid runtime config - no themes defined', undefined, {
|
|
1233
1264
|
component: 'ThemeService',
|
|
1234
1265
|
action: 'configureRuntime',
|
|
1235
1266
|
});
|
|
1236
1267
|
return;
|
|
1237
1268
|
}
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
component: 'ThemeService',
|
|
1244
|
-
action: 'configureRuntime',
|
|
1245
|
-
});
|
|
1246
|
-
return;
|
|
1269
|
+
if (config.fonts && config.fonts.length > 0) {
|
|
1270
|
+
this.domService.injectFonts(config.fonts);
|
|
1271
|
+
if (options?.blocking) {
|
|
1272
|
+
await this.waitForFonts();
|
|
1273
|
+
}
|
|
1247
1274
|
}
|
|
1248
|
-
|
|
1249
|
-
const
|
|
1250
|
-
this.
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1275
|
+
this.assetsService.setThemeConfig(themeName, config);
|
|
1276
|
+
const themeVariants = config.themes;
|
|
1277
|
+
this.runtimeThemes.set(themeName, themeVariants);
|
|
1278
|
+
this.domService.injectSingleThemeStyles(themeName, themeVariants);
|
|
1279
|
+
this.appliedThemeNames.add(themeName);
|
|
1280
|
+
if (options?.blocking) {
|
|
1281
|
+
await this.assetsService.prefetchAssets(themeName);
|
|
1282
|
+
}
|
|
1283
|
+
else {
|
|
1284
|
+
void this.assetsService.prefetchAssets(themeName);
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
applyRuntimeConfig(config, source) {
|
|
1288
|
+
this.isUsingFallbackConfig = source === 'fallback';
|
|
1289
|
+
this.config = config;
|
|
1290
|
+
validateThemeConfig(this.config, 'ThemeService.applyRuntimeConfig');
|
|
1257
1291
|
this.selectedTheme.set(this.config.defaultTheme);
|
|
1258
1292
|
this.selectedScheme.set(this.config.defaultScheme);
|
|
1259
|
-
// Always restore user's saved settings (overrides defaults if they exist)
|
|
1260
1293
|
this.initializeFromStorage();
|
|
1261
1294
|
this.applyTheme();
|
|
1262
|
-
// Now that initialization is complete, set up the router subscription for fresh on navigation
|
|
1263
|
-
// This ensures the initial navigation event doesn't trigger a reload
|
|
1264
|
-
const freshOnNavigation = this.runtimeLoaderOptions?.freshOnNavigation ?? false;
|
|
1265
|
-
if (freshOnNavigation && !this.navigationSubscription) {
|
|
1266
|
-
this.navigationSubscription = this.router.events.pipe(filter((event) => event instanceof NavigationEnd)).subscribe(() => {
|
|
1267
|
-
// Skip the first navigation event (happens during app bootstrap)
|
|
1268
|
-
if (this.skipFirstNavigation) {
|
|
1269
|
-
this.skipFirstNavigation = false;
|
|
1270
|
-
return;
|
|
1271
|
-
}
|
|
1272
|
-
this.reloadRuntimeConfig().catch((error) => {
|
|
1273
|
-
if (this.runtimeLoaderOptions?.logErrors !== false) {
|
|
1274
|
-
this.logger.error('Error reloading runtime config on navigation', error, {
|
|
1275
|
-
component: 'ThemeService',
|
|
1276
|
-
action: 'configureRuntime.navigationSubscription',
|
|
1277
|
-
});
|
|
1278
|
-
}
|
|
1279
|
-
});
|
|
1280
|
-
});
|
|
1281
|
-
}
|
|
1282
1295
|
}
|
|
1283
1296
|
setTheme(theme) {
|
|
1284
1297
|
if (isThemeAvailable(theme, this.config.availableThemes)) {
|
|
@@ -1329,7 +1342,7 @@ class ThemeService {
|
|
|
1329
1342
|
return formatSchemeName(scheme);
|
|
1330
1343
|
}
|
|
1331
1344
|
getLocalizedThemeName(theme) {
|
|
1332
|
-
const translationKey = `sdk.theme.
|
|
1345
|
+
const translationKey = `sdk.theme.catalog.${theme}`;
|
|
1333
1346
|
const translatedName = this.translationService.instant(translationKey);
|
|
1334
1347
|
if (translatedName && translatedName !== translationKey) {
|
|
1335
1348
|
return translatedName;
|
|
@@ -1338,6 +1351,7 @@ class ThemeService {
|
|
|
1338
1351
|
}
|
|
1339
1352
|
initializeFromStorage() {
|
|
1340
1353
|
const savedTheme = this.storageService.getSavedTheme();
|
|
1354
|
+
let skipSchemeRestore = false;
|
|
1341
1355
|
this.logger.debug('initializeFromStorage - savedTheme', {
|
|
1342
1356
|
component: 'ThemeService',
|
|
1343
1357
|
action: 'initializeFromStorage',
|
|
@@ -1377,7 +1391,10 @@ class ThemeService {
|
|
|
1377
1391
|
savedTheme,
|
|
1378
1392
|
defaultTheme: this.config.defaultTheme,
|
|
1379
1393
|
});
|
|
1394
|
+
this.storageService.clear();
|
|
1395
|
+
skipSchemeRestore = true;
|
|
1380
1396
|
this.selectedTheme.set(this.config.defaultTheme);
|
|
1397
|
+
this.selectedScheme.set(DEFAULT_SCHEME);
|
|
1381
1398
|
}
|
|
1382
1399
|
}
|
|
1383
1400
|
const savedScheme = this.storageService.getSavedScheme();
|
|
@@ -1386,7 +1403,7 @@ class ThemeService {
|
|
|
1386
1403
|
action: 'initializeFromStorage',
|
|
1387
1404
|
savedScheme,
|
|
1388
1405
|
});
|
|
1389
|
-
if (savedScheme && isValidScheme(savedScheme)) {
|
|
1406
|
+
if (savedScheme && isValidScheme(savedScheme) && !skipSchemeRestore) {
|
|
1390
1407
|
this.logger.debug('Restoring saved scheme', {
|
|
1391
1408
|
component: 'ThemeService',
|
|
1392
1409
|
action: 'initializeFromStorage',
|
|
@@ -1394,147 +1411,462 @@ class ThemeService {
|
|
|
1394
1411
|
});
|
|
1395
1412
|
this.selectedScheme.set(savedScheme);
|
|
1396
1413
|
}
|
|
1414
|
+
else if (savedScheme && !this.isUsingFallbackConfig) {
|
|
1415
|
+
this.storageService.clear();
|
|
1416
|
+
}
|
|
1397
1417
|
}
|
|
1398
1418
|
applyTheme() {
|
|
1399
1419
|
const themeIdentifier = this.finalTheme();
|
|
1400
1420
|
this.domService.setActiveTheme(themeIdentifier);
|
|
1401
1421
|
this.storageService.saveTheme(this.selectedTheme());
|
|
1402
1422
|
this.storageService.saveScheme(this.selectedScheme());
|
|
1423
|
+
const selectedTheme = this.selectedTheme();
|
|
1424
|
+
if (!this.appliedThemeNames.has(selectedTheme)) {
|
|
1425
|
+
const variants = this.runtimeThemes.get(selectedTheme);
|
|
1426
|
+
if (variants) {
|
|
1427
|
+
this.domService.injectSingleThemeStyles(selectedTheme, variants);
|
|
1428
|
+
this.appliedThemeNames.add(selectedTheme);
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1403
1431
|
}
|
|
1404
1432
|
/**
|
|
1405
1433
|
* Internal method to set runtime loader and enable navigation-based reloading.
|
|
1406
1434
|
* Called by provideRuntimeTheme.
|
|
1407
1435
|
* @internal
|
|
1408
1436
|
*/
|
|
1409
|
-
setRuntimeLoader(
|
|
1410
|
-
this.runtimeConfigPath = configPath;
|
|
1437
|
+
setRuntimeLoader(loader, hash) {
|
|
1411
1438
|
this.runtimeLoader = loader;
|
|
1412
|
-
this.
|
|
1439
|
+
this.runtimeHash = hash ?? null;
|
|
1440
|
+
this.updateAvailable.set(false);
|
|
1441
|
+
this.lastRefreshFailed.set(false);
|
|
1413
1442
|
}
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1443
|
+
async checkForThemeUpdates(loader, event) {
|
|
1444
|
+
this.runtimeLoader = loader;
|
|
1445
|
+
if (event?.resource && event.resource !== 'theme' && event.resource !== 'both') {
|
|
1446
|
+
return;
|
|
1447
|
+
}
|
|
1448
|
+
const eventHash = event?.hash;
|
|
1449
|
+
const eventUrl = event?.url?.toString?.() ?? event?.url;
|
|
1450
|
+
const eventTheme = event?.resource === 'theme' || event?.resource === 'both' ? event.theme : undefined;
|
|
1451
|
+
if (eventHash) {
|
|
1452
|
+
if (eventUrl) {
|
|
1453
|
+
const knownEventHash = this.runtimeEventHashes.get(eventUrl);
|
|
1454
|
+
if (knownEventHash && knownEventHash === eventHash) {
|
|
1455
|
+
return;
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
if (eventHash === this.runtimeHash) {
|
|
1459
|
+
return;
|
|
1460
|
+
}
|
|
1461
|
+
if (!this.updateAvailable()) {
|
|
1462
|
+
this.updateAvailable.set(true);
|
|
1463
|
+
}
|
|
1464
|
+
if (eventUrl) {
|
|
1465
|
+
this.runtimeEventHashes.set(eventUrl, eventHash);
|
|
1466
|
+
}
|
|
1467
|
+
if (eventTheme) {
|
|
1468
|
+
this.pendingUpdatedThemes.add(eventTheme);
|
|
1469
|
+
}
|
|
1470
|
+
return;
|
|
1471
|
+
}
|
|
1472
|
+
const currentHash = this.runtimeHash;
|
|
1473
|
+
if (currentHash) {
|
|
1474
|
+
const check = await loader.checkForUpdates(currentHash);
|
|
1475
|
+
if (!check.updated || this.updateAvailable()) {
|
|
1476
|
+
return;
|
|
1477
|
+
}
|
|
1478
|
+
this.updateAvailable.set(true);
|
|
1479
|
+
return;
|
|
1480
|
+
}
|
|
1481
|
+
if (!this.updateAvailable()) {
|
|
1482
|
+
this.updateAvailable.set(true);
|
|
1483
|
+
}
|
|
1421
1484
|
}
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1485
|
+
async refreshTheme(loader) {
|
|
1486
|
+
const runtimeLoader = loader ?? this.runtimeLoader;
|
|
1487
|
+
if (!runtimeLoader) {
|
|
1488
|
+
this.logger.warn('Theme refresh requested without runtime loader', {
|
|
1489
|
+
component: 'ThemeService',
|
|
1490
|
+
action: 'refreshTheme',
|
|
1491
|
+
});
|
|
1492
|
+
return;
|
|
1493
|
+
}
|
|
1494
|
+
if (!this.refreshHandler) {
|
|
1495
|
+
this.logger.warn('Theme refresh requested without handler', {
|
|
1496
|
+
component: 'ThemeService',
|
|
1497
|
+
action: 'refreshTheme',
|
|
1498
|
+
});
|
|
1428
1499
|
return;
|
|
1429
1500
|
}
|
|
1430
1501
|
try {
|
|
1431
|
-
const
|
|
1432
|
-
this.
|
|
1502
|
+
const updatedThemes = Array.from(this.pendingUpdatedThemes);
|
|
1503
|
+
this.pendingUpdatedThemes.clear();
|
|
1504
|
+
await this.refreshHandler(updatedThemes);
|
|
1505
|
+
this.updateAvailable.set(false);
|
|
1506
|
+
this.lastRefreshFailed.set(false);
|
|
1433
1507
|
}
|
|
1434
1508
|
catch (error) {
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
});
|
|
1441
|
-
}
|
|
1442
|
-
// Don't update config on reload error - keep existing config
|
|
1509
|
+
this.lastRefreshFailed.set(true);
|
|
1510
|
+
this.logger.error('Theme refresh failed', error, {
|
|
1511
|
+
component: 'ThemeService',
|
|
1512
|
+
action: 'refreshTheme',
|
|
1513
|
+
});
|
|
1443
1514
|
}
|
|
1444
1515
|
}
|
|
1445
1516
|
init() {
|
|
1446
1517
|
this.getAvailableThemes();
|
|
1447
1518
|
}
|
|
1448
|
-
|
|
1519
|
+
setRefreshHandler(handler) {
|
|
1520
|
+
this.refreshHandler = handler;
|
|
1521
|
+
}
|
|
1522
|
+
async waitForFonts() {
|
|
1523
|
+
if (typeof document === 'undefined' || !document.fonts?.ready) {
|
|
1524
|
+
return;
|
|
1525
|
+
}
|
|
1526
|
+
try {
|
|
1527
|
+
await document.fonts.ready;
|
|
1528
|
+
}
|
|
1529
|
+
catch (error) {
|
|
1530
|
+
this.logger.warn('Font readiness check failed', {
|
|
1531
|
+
component: 'ThemeService',
|
|
1532
|
+
action: 'waitForFonts',
|
|
1533
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1534
|
+
});
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: ThemeService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1449
1538
|
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: ThemeService, providedIn: 'root' });
|
|
1450
1539
|
}
|
|
1451
1540
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: ThemeService, decorators: [{
|
|
1452
1541
|
type: Injectable,
|
|
1453
1542
|
args: [{ providedIn: 'root' }]
|
|
1454
|
-
}], ctorParameters: () => [
|
|
1455
|
-
type: Inject,
|
|
1456
|
-
args: [THEME_CONFIG_TOKEN]
|
|
1457
|
-
}, {
|
|
1458
|
-
type: Optional
|
|
1459
|
-
}] }, { type: undefined, decorators: [{
|
|
1460
|
-
type: Inject,
|
|
1461
|
-
args: [RUNTIME_THEME_CONFIG_TOKEN]
|
|
1462
|
-
}, {
|
|
1463
|
-
type: Optional
|
|
1464
|
-
}] }] });
|
|
1465
|
-
|
|
1466
|
-
/**
|
|
1467
|
-
* Theme-specific IndexedDB database name for resource caching
|
|
1468
|
-
*/
|
|
1469
|
-
const THEME_INDEXED_DB_NAME = 'sixbell-theme';
|
|
1470
|
-
const RUNTIME_THEME_LOADER_DEFAULTS = {
|
|
1471
|
-
cacheName: 'theme-runtime-config',
|
|
1472
|
-
indexedDBName: THEME_INDEXED_DB_NAME,
|
|
1473
|
-
storageOrder: ['indexedDB'],
|
|
1474
|
-
cacheTTL: 1000 * 60 * 60 * 24,
|
|
1475
|
-
freshOnNavigation: true, // Hot-reload on every navigation by default
|
|
1476
|
-
staleWhileRevalidate: true,
|
|
1477
|
-
useStaleOnError: true,
|
|
1478
|
-
revalidateOnFresh: true,
|
|
1479
|
-
retries: 3,
|
|
1480
|
-
retryDelayMs: 500,
|
|
1481
|
-
timeoutMs: 8000,
|
|
1482
|
-
seedCacheWithFallback: true,
|
|
1483
|
-
logErrors: true,
|
|
1484
|
-
};
|
|
1543
|
+
}], ctorParameters: () => [] });
|
|
1485
1544
|
|
|
1486
|
-
function buildRuntimeThemeLoaderOptions(configPath, overrides) {
|
|
1487
|
-
const merged = { ...RUNTIME_THEME_LOADER_DEFAULTS, ...overrides };
|
|
1488
|
-
return {
|
|
1489
|
-
...merged,
|
|
1490
|
-
cacheKey: overrides?.cacheKey ?? configPath,
|
|
1491
|
-
fallbackData: overrides?.fallbackData ?? FALLBACK_RUNTIME_THEME_CONFIG,
|
|
1492
|
-
parser: overrides?.parser ?? (async (response) => (await response.json())),
|
|
1493
|
-
};
|
|
1494
|
-
}
|
|
1495
|
-
/**
|
|
1496
|
-
* @deprecated Use provideRuntimeTheme instead.
|
|
1497
|
-
*/
|
|
1498
|
-
function provideTheme(config) {
|
|
1499
|
-
return makeEnvironmentProviders([
|
|
1500
|
-
{
|
|
1501
|
-
provide: THEME_CONFIG_TOKEN,
|
|
1502
|
-
useValue: (config || {}),
|
|
1503
|
-
},
|
|
1504
|
-
provideAppInitializer(() => inject(ThemeService).init()),
|
|
1505
|
-
]);
|
|
1506
|
-
}
|
|
1507
1545
|
function provideRuntimeTheme(configPath, options) {
|
|
1508
|
-
const initialConfig = options?.loaderOptions?.fallbackData ?? FALLBACK_RUNTIME_THEME_CONFIG;
|
|
1509
1546
|
return makeEnvironmentProviders([
|
|
1510
|
-
{
|
|
1511
|
-
provide: RUNTIME_THEME_CONFIG_TOKEN,
|
|
1512
|
-
useValue: initialConfig,
|
|
1513
|
-
},
|
|
1514
1547
|
provideAppInitializer(() => {
|
|
1515
1548
|
const themeService = inject(ThemeService);
|
|
1549
|
+
const storageService = inject(ThemeStorageService);
|
|
1516
1550
|
const logger = inject(LoggerService);
|
|
1517
|
-
|
|
1518
|
-
const
|
|
1551
|
+
const configStore = new RuntimeConfigStore('theme-runtime-config', options?.appId);
|
|
1552
|
+
const themeStore = new RuntimeConfigStore('theme-runtime-config', options?.appId);
|
|
1553
|
+
const configLoader = new RuntimeConfigLoader(configPath, {
|
|
1554
|
+
fallbackData: {
|
|
1555
|
+
meta: {
|
|
1556
|
+
name: DEFAULT_BASE_THEME,
|
|
1557
|
+
updatedAt: new Date().toISOString(),
|
|
1558
|
+
hash: 'fallback-hash',
|
|
1559
|
+
schemaVersion: THEME_SCHEMA_VERSION,
|
|
1560
|
+
},
|
|
1561
|
+
themes: [configPath],
|
|
1562
|
+
defaultTheme: DEFAULT_BASE_THEME,
|
|
1563
|
+
defaultScheme: DEFAULT_SCHEME,
|
|
1564
|
+
},
|
|
1565
|
+
schemaVersion: THEME_SCHEMA_VERSION,
|
|
1566
|
+
resource: 'theme',
|
|
1567
|
+
store: configStore,
|
|
1568
|
+
logger,
|
|
1569
|
+
parser: async (response) => (await response.json()),
|
|
1570
|
+
appId: options?.appId,
|
|
1571
|
+
});
|
|
1572
|
+
const updateAdapter = new RuntimeUpdateAdapter(async (event) => {
|
|
1573
|
+
if (event.resource && event.resource !== 'theme' && event.resource !== 'both') {
|
|
1574
|
+
return;
|
|
1575
|
+
}
|
|
1576
|
+
await themeService.checkForThemeUpdates(configLoader, event);
|
|
1577
|
+
});
|
|
1578
|
+
if (options?.sse) {
|
|
1579
|
+
updateAdapter.connectSse(options.sse.url, {
|
|
1580
|
+
resource: 'theme',
|
|
1581
|
+
withCredentials: options.sse.withCredentials,
|
|
1582
|
+
eventType: options.sse.eventType,
|
|
1583
|
+
transform: options.sse.transform,
|
|
1584
|
+
logger,
|
|
1585
|
+
});
|
|
1586
|
+
}
|
|
1587
|
+
if (options?.updateStream) {
|
|
1588
|
+
updateAdapter.connectStream(options.updateStream);
|
|
1589
|
+
}
|
|
1590
|
+
const loadThemeConfig = async (themePath, loadOptions) => {
|
|
1591
|
+
const themeLoader = new RuntimeConfigLoader(themePath, {
|
|
1592
|
+
fallbackData: FALLBACK_RUNTIME_THEME_CONFIG,
|
|
1593
|
+
schemaVersion: THEME_SCHEMA_VERSION,
|
|
1594
|
+
resource: 'theme',
|
|
1595
|
+
store: themeStore,
|
|
1596
|
+
logger,
|
|
1597
|
+
parser: async (response) => (await response.json()),
|
|
1598
|
+
appId: options?.appId,
|
|
1599
|
+
});
|
|
1600
|
+
let result = loadOptions?.forceRefresh ? await themeLoader.refresh() : await themeLoader.loadLatest();
|
|
1601
|
+
if (!loadOptions?.forceRefresh && result.source === 'cache') {
|
|
1602
|
+
try {
|
|
1603
|
+
const check = await themeLoader.checkForUpdates(result.hash);
|
|
1604
|
+
if (check.updated) {
|
|
1605
|
+
result = await themeLoader.refresh();
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
catch (error) {
|
|
1609
|
+
logger.warn('Theme entry bootstrap validation failed', {
|
|
1610
|
+
component: 'ThemeProvider',
|
|
1611
|
+
action: 'validateEntry',
|
|
1612
|
+
theme: themePath,
|
|
1613
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1614
|
+
});
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
if (!result.meta.schemaVersion) {
|
|
1618
|
+
throw new Error(`Theme schemaVersion missing for ${themePath}`);
|
|
1619
|
+
}
|
|
1620
|
+
if (result.meta.schemaVersion !== THEME_SCHEMA_VERSION) {
|
|
1621
|
+
throw new Error(`Theme schemaVersion mismatch for ${themePath}`);
|
|
1622
|
+
}
|
|
1623
|
+
if (!result.data.meta?.name) {
|
|
1624
|
+
throw new Error(`Theme meta.name missing for ${themePath}`);
|
|
1625
|
+
}
|
|
1626
|
+
if (!result.data.meta?.hash) {
|
|
1627
|
+
throw new Error(`Theme meta.hash missing for ${themePath}`);
|
|
1628
|
+
}
|
|
1629
|
+
if (!result.data.meta?.updatedAt) {
|
|
1630
|
+
throw new Error(`Theme meta.updatedAt missing for ${themePath}`);
|
|
1631
|
+
}
|
|
1632
|
+
return result.data;
|
|
1633
|
+
};
|
|
1634
|
+
const applyThemeConfig = async (config, blocking) => {
|
|
1635
|
+
const themeName = config.meta?.name;
|
|
1636
|
+
if (!themeName) {
|
|
1637
|
+
throw new Error('Theme meta.name missing for config apply');
|
|
1638
|
+
}
|
|
1639
|
+
const normalizedConfig = {
|
|
1640
|
+
...config,
|
|
1641
|
+
themes: {
|
|
1642
|
+
light: {
|
|
1643
|
+
...config.themes.light,
|
|
1644
|
+
prefersDark: false,
|
|
1645
|
+
},
|
|
1646
|
+
dark: {
|
|
1647
|
+
...config.themes.dark,
|
|
1648
|
+
prefersDark: true,
|
|
1649
|
+
},
|
|
1650
|
+
},
|
|
1651
|
+
};
|
|
1652
|
+
await themeService.configureRuntime(normalizedConfig, themeName, { blocking });
|
|
1653
|
+
};
|
|
1519
1654
|
return (async () => {
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
themeService.setRuntimeLoader(configPath, loader, loaderOptions);
|
|
1655
|
+
themeService.init();
|
|
1656
|
+
let configResult;
|
|
1523
1657
|
try {
|
|
1524
|
-
|
|
1525
|
-
// Pass the source so service knows if using cache, network, or fallback
|
|
1526
|
-
themeService.configureRuntimeWithSource(result.data, result.source);
|
|
1658
|
+
configResult = await configLoader.loadLatest();
|
|
1527
1659
|
}
|
|
1528
1660
|
catch (error) {
|
|
1529
|
-
|
|
1530
|
-
|
|
1661
|
+
logger.error('Theme config load failed', error, {
|
|
1662
|
+
component: 'ThemeProvider',
|
|
1663
|
+
action: 'loadLatest',
|
|
1664
|
+
});
|
|
1665
|
+
return;
|
|
1666
|
+
}
|
|
1667
|
+
if (configResult.source === 'cache') {
|
|
1668
|
+
try {
|
|
1669
|
+
const check = await configLoader.checkForUpdates(configResult.hash);
|
|
1670
|
+
if (check.updated) {
|
|
1671
|
+
configResult = await configLoader.refresh();
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
catch (error) {
|
|
1675
|
+
logger.warn('Theme config bootstrap validation failed', {
|
|
1676
|
+
component: 'ThemeProvider',
|
|
1677
|
+
action: 'bootstrapValidation',
|
|
1678
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1679
|
+
});
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
const themeConfig = configResult.data;
|
|
1683
|
+
if (!themeConfig.meta.schemaVersion) {
|
|
1684
|
+
logger.error('Theme config schemaVersion missing', undefined, {
|
|
1685
|
+
component: 'ThemeProvider',
|
|
1686
|
+
action: 'validateSchema',
|
|
1687
|
+
});
|
|
1688
|
+
return;
|
|
1689
|
+
}
|
|
1690
|
+
if (themeConfig.meta.schemaVersion !== THEME_SCHEMA_VERSION) {
|
|
1691
|
+
logger.error('Theme config schemaVersion mismatch', undefined, {
|
|
1692
|
+
component: 'ThemeProvider',
|
|
1693
|
+
action: 'validateSchema',
|
|
1694
|
+
expected: THEME_SCHEMA_VERSION,
|
|
1695
|
+
actual: themeConfig.meta.schemaVersion,
|
|
1696
|
+
});
|
|
1697
|
+
return;
|
|
1698
|
+
}
|
|
1699
|
+
if (!themeConfig.meta.hash) {
|
|
1700
|
+
logger.error('Theme config hash missing', undefined, {
|
|
1701
|
+
component: 'ThemeProvider',
|
|
1702
|
+
action: 'validateSchema',
|
|
1703
|
+
});
|
|
1704
|
+
return;
|
|
1705
|
+
}
|
|
1706
|
+
if (!themeConfig.meta.updatedAt) {
|
|
1707
|
+
logger.error('Theme config updatedAt missing', undefined, {
|
|
1708
|
+
component: 'ThemeProvider',
|
|
1709
|
+
action: 'validateSchema',
|
|
1710
|
+
});
|
|
1711
|
+
return;
|
|
1712
|
+
}
|
|
1713
|
+
const themePaths = themeConfig.themes ?? [];
|
|
1714
|
+
const themeEntries = new Map();
|
|
1715
|
+
const availableThemes = [];
|
|
1716
|
+
for (const themePath of themePaths) {
|
|
1717
|
+
try {
|
|
1718
|
+
const loadedConfig = await loadThemeConfig(themePath);
|
|
1719
|
+
const themeName = loadedConfig.meta?.name;
|
|
1720
|
+
if (!themeName) {
|
|
1721
|
+
logger.warn('Theme meta.name missing', {
|
|
1722
|
+
component: 'ThemeProvider',
|
|
1723
|
+
action: 'resolveThemeName',
|
|
1724
|
+
path: themePath,
|
|
1725
|
+
});
|
|
1726
|
+
continue;
|
|
1727
|
+
}
|
|
1728
|
+
if (themeConfig.excludeThemes?.includes(themeName)) {
|
|
1729
|
+
continue;
|
|
1730
|
+
}
|
|
1731
|
+
themeEntries.set(themeName, themePath);
|
|
1732
|
+
availableThemes.push(themeName);
|
|
1733
|
+
}
|
|
1734
|
+
catch (error) {
|
|
1735
|
+
logger.warn('Failed to load theme entry', {
|
|
1736
|
+
component: 'ThemeProvider',
|
|
1737
|
+
action: 'loadThemeEntry',
|
|
1738
|
+
path: themePath,
|
|
1739
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1740
|
+
});
|
|
1741
|
+
}
|
|
1742
|
+
}
|
|
1743
|
+
const defaultTheme = resolveDefaultTheme(themeConfig.defaultTheme, availableThemes);
|
|
1744
|
+
const config = {
|
|
1745
|
+
availableThemes,
|
|
1746
|
+
defaultTheme,
|
|
1747
|
+
defaultScheme: themeConfig.defaultScheme ?? DEFAULT_SCHEME,
|
|
1748
|
+
};
|
|
1749
|
+
themeService.applyRuntimeConfig(config, configResult.source);
|
|
1750
|
+
themeService.setRuntimeLoader(configLoader, configResult.hash);
|
|
1751
|
+
themeService.setRefreshHandler(async (updatedThemes) => {
|
|
1752
|
+
let refreshedConfig;
|
|
1753
|
+
try {
|
|
1754
|
+
refreshedConfig = await configLoader.refresh();
|
|
1755
|
+
}
|
|
1756
|
+
catch (error) {
|
|
1757
|
+
logger.error('Theme config refresh failed', error, {
|
|
1758
|
+
component: 'ThemeProvider',
|
|
1759
|
+
action: 'refresh',
|
|
1760
|
+
});
|
|
1761
|
+
return;
|
|
1762
|
+
}
|
|
1763
|
+
if (!refreshedConfig.data.meta.schemaVersion) {
|
|
1764
|
+
logger.error('Theme config schemaVersion missing', undefined, {
|
|
1531
1765
|
component: 'ThemeProvider',
|
|
1532
|
-
action: '
|
|
1533
|
-
configPath,
|
|
1766
|
+
action: 'validateSchema',
|
|
1534
1767
|
});
|
|
1768
|
+
return;
|
|
1535
1769
|
}
|
|
1536
|
-
|
|
1537
|
-
|
|
1770
|
+
if (refreshedConfig.data.meta.schemaVersion !== THEME_SCHEMA_VERSION) {
|
|
1771
|
+
logger.error('Theme config schemaVersion mismatch', undefined, {
|
|
1772
|
+
component: 'ThemeProvider',
|
|
1773
|
+
action: 'validateSchema',
|
|
1774
|
+
expected: THEME_SCHEMA_VERSION,
|
|
1775
|
+
actual: refreshedConfig.data.meta.schemaVersion,
|
|
1776
|
+
});
|
|
1777
|
+
return;
|
|
1778
|
+
}
|
|
1779
|
+
if (!refreshedConfig.data.meta.hash) {
|
|
1780
|
+
logger.error('Theme config hash missing', undefined, {
|
|
1781
|
+
component: 'ThemeProvider',
|
|
1782
|
+
action: 'validateSchema',
|
|
1783
|
+
});
|
|
1784
|
+
return;
|
|
1785
|
+
}
|
|
1786
|
+
if (!refreshedConfig.data.meta.updatedAt) {
|
|
1787
|
+
logger.error('Theme config updatedAt missing', undefined, {
|
|
1788
|
+
component: 'ThemeProvider',
|
|
1789
|
+
action: 'validateSchema',
|
|
1790
|
+
});
|
|
1791
|
+
return;
|
|
1792
|
+
}
|
|
1793
|
+
const refreshedPaths = refreshedConfig.data.themes ?? [];
|
|
1794
|
+
const refreshedEntries = new Map();
|
|
1795
|
+
const refreshedAvailableThemes = [];
|
|
1796
|
+
for (const themePath of refreshedPaths) {
|
|
1797
|
+
try {
|
|
1798
|
+
const loadedConfig = await loadThemeConfig(themePath);
|
|
1799
|
+
const themeName = loadedConfig.meta?.name;
|
|
1800
|
+
if (!themeName) {
|
|
1801
|
+
logger.warn('Theme meta.name missing', {
|
|
1802
|
+
component: 'ThemeProvider',
|
|
1803
|
+
action: 'resolveThemeName',
|
|
1804
|
+
path: themePath,
|
|
1805
|
+
});
|
|
1806
|
+
continue;
|
|
1807
|
+
}
|
|
1808
|
+
if (refreshedConfig.data.excludeThemes?.includes(themeName)) {
|
|
1809
|
+
continue;
|
|
1810
|
+
}
|
|
1811
|
+
refreshedEntries.set(themeName, themePath);
|
|
1812
|
+
refreshedAvailableThemes.push(themeName);
|
|
1813
|
+
}
|
|
1814
|
+
catch (error) {
|
|
1815
|
+
logger.warn('Failed to load theme entry', {
|
|
1816
|
+
component: 'ThemeProvider',
|
|
1817
|
+
action: 'loadThemeEntry',
|
|
1818
|
+
path: themePath,
|
|
1819
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1820
|
+
});
|
|
1821
|
+
}
|
|
1822
|
+
}
|
|
1823
|
+
const refreshedDefaultTheme = resolveDefaultTheme(refreshedConfig.data.defaultTheme, refreshedAvailableThemes);
|
|
1824
|
+
const refreshedSelected = themeService.selectedTheme();
|
|
1825
|
+
const configHashChanged = refreshedConfig.hash !== configResult.hash;
|
|
1826
|
+
const changedEntries = configHashChanged
|
|
1827
|
+
? refreshedEntries
|
|
1828
|
+
: new Map([...refreshedEntries].filter(([name]) => updatedThemes.includes(name)));
|
|
1829
|
+
if (configHashChanged) {
|
|
1830
|
+
themeService.applyRuntimeConfig({
|
|
1831
|
+
availableThemes: refreshedAvailableThemes,
|
|
1832
|
+
defaultTheme: refreshedDefaultTheme,
|
|
1833
|
+
defaultScheme: refreshedConfig.data.defaultScheme ?? DEFAULT_SCHEME,
|
|
1834
|
+
}, refreshedConfig.source);
|
|
1835
|
+
themeService.setRuntimeLoader(configLoader, refreshedConfig.hash);
|
|
1836
|
+
configResult = refreshedConfig;
|
|
1837
|
+
const refreshedPath = refreshedEntries.get(refreshedSelected) ?? [...refreshedEntries.values()][0];
|
|
1838
|
+
if (refreshedPath) {
|
|
1839
|
+
const refreshedThemeConfig = await loadThemeConfig(refreshedPath, { forceRefresh: true });
|
|
1840
|
+
await applyThemeConfig(refreshedThemeConfig, true);
|
|
1841
|
+
}
|
|
1842
|
+
return;
|
|
1843
|
+
}
|
|
1844
|
+
if (!changedEntries.size) {
|
|
1845
|
+
return;
|
|
1846
|
+
}
|
|
1847
|
+
for (const [name, path] of changedEntries) {
|
|
1848
|
+
const refreshedThemeConfig = await loadThemeConfig(path, { forceRefresh: true });
|
|
1849
|
+
const isSelected = name === refreshedSelected;
|
|
1850
|
+
await applyThemeConfig(refreshedThemeConfig, isSelected);
|
|
1851
|
+
}
|
|
1852
|
+
});
|
|
1853
|
+
const savedTheme = storageService.getSavedTheme();
|
|
1854
|
+
const selectedTheme = savedTheme && availableThemes.includes(savedTheme) ? savedTheme : config.defaultTheme;
|
|
1855
|
+
const selectedPath = themeEntries.get(selectedTheme) ?? [...themeEntries.values()][0];
|
|
1856
|
+
if (!selectedPath) {
|
|
1857
|
+
logger.warn('No theme entries available in config', {
|
|
1858
|
+
component: 'ThemeProvider',
|
|
1859
|
+
action: 'provideRuntimeTheme',
|
|
1860
|
+
});
|
|
1861
|
+
return;
|
|
1862
|
+
}
|
|
1863
|
+
const selectedConfig = await loadThemeConfig(selectedPath);
|
|
1864
|
+
await applyThemeConfig(selectedConfig, true);
|
|
1865
|
+
const remainingEntries = [...themeEntries.entries()].filter(([name]) => name !== selectedTheme);
|
|
1866
|
+
for (const [, path] of remainingEntries) {
|
|
1867
|
+
loadThemeConfig(path)
|
|
1868
|
+
.then((configToApply) => applyThemeConfig(configToApply, false))
|
|
1869
|
+
.catch(() => undefined);
|
|
1538
1870
|
}
|
|
1539
1871
|
})();
|
|
1540
1872
|
}),
|
|
@@ -1545,5 +1877,5 @@ function provideRuntimeTheme(configPath, options) {
|
|
|
1545
1877
|
* Generated bundle index. Do not edit.
|
|
1546
1878
|
*/
|
|
1547
1879
|
|
|
1548
|
-
export {
|
|
1880
|
+
export { DEFAULT_BASE_THEME, DEFAULT_SCHEME, FALLBACK_RUNTIME_THEME_CONFIG, THEME_SCHEMA_VERSION, ThemeAssetsService, ThemeDomService, ThemeSchemeService, ThemeService, ThemeStorageService, VALID_SCHEMES, buildThemeIdentifier, formatSchemeName, formatThemeName, hasLocalStorage, isThemeAvailable, isValidScheme, parseThemeIdentifier, provideRuntimeTheme, resolveDefaultTheme, supportsMediaQuery, validateThemeConfig };
|
|
1549
1881
|
//# sourceMappingURL=sixbell-telco-sdk-utils-theme.mjs.map
|