shirkasoft-ui-components 2.0.1 → 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.
@@ -1 +1 @@
1
- {"version":3,"file":"shirkasoft-ui-components-theme-picker.mjs","names":[],"sources":["../../../projects/ui-components/theme-picker/theme-picker.component.ts"],"sourcesContent":["import {\n ChangeDetectionStrategy,\n Component,\n ElementRef,\n computed,\n inject,\n input,\n signal,\n viewChild,\n} from '@angular/core';\nimport {\n SHK_THEME_PRESETS,\n SURFACE_PALETTES,\n ShkConfigService,\n} from 'shirkasoft-ui-components/config';\nimport { ShkIconDirective } from 'shirkasoft-ui-components/icons';\nimport { getIcon } from 'shirkasoft-ui-components/utils';\n\n/**\n * Shirkasoft UI Components.\n * Authors: Roberto Valladares Martin (Ansem13), Julio César García García (Sanjuli14).\n * Belongs to Shirkasoft.\n */\n\n/** A primary color offered by the picker. */\nexport interface ShkPickerColor {\n /** Hex color; it becomes `--shk-primary-600` (`theme.primary`). */\n color: string;\n /** Accessible name / tooltip. */\n label: string;\n}\n\n/**\n * Default primary colors (Tailwind 600 shades). Red and rose are left out on\n * purpose: red is reserved for danger states.\n */\nexport const DEFAULT_PRIMARY_COLORS: readonly ShkPickerColor[] = [\n { color: '#334155', label: 'Noir' },\n { color: '#059669', label: 'Emerald' },\n { color: '#16a34a', label: 'Green' },\n { color: '#65a30d', label: 'Lime' },\n { color: '#ea580c', label: 'Orange' },\n { color: '#d97706', label: 'Amber' },\n { color: '#ca8a04', label: 'Yellow' },\n { color: '#0d9488', label: 'Teal' },\n { color: '#0891b2', label: 'Cyan' },\n { color: '#0284c7', label: 'Sky' },\n { color: '#2563eb', label: 'Blue' },\n { color: '#4f46e5', label: 'Indigo' },\n { color: '#7c3aed', label: 'Violet' },\n { color: '#9333ea', label: 'Purple' },\n { color: '#c026d3', label: 'Fuchsia' },\n { color: '#db2777', label: 'Pink' },\n];\n\nlet pickerCounter = 0;\n\n/**\n * Theme customizer: a palette button that opens a panel to pick the primary\n * color, the surface (neutral) palette and a theme preset at runtime.\n *\n * It edits the `theme.primary`, `theme.surface` and `theme.name` options, so it\n * needs `provideShk(withTheme(...))`; add `withPersistence()` to remember the\n * choice. Without `withTheme()` it renders nothing.\n *\n * ```html\n * <shk-theme-picker />\n * ```\n */\n@Component({\n selector: 'shk-theme-picker',\n changeDetection: ChangeDetectionStrategy.OnPush,\n imports: [ShkIconDirective],\n host: {\n class: 'shk-theme-picker',\n '(document:pointerdown)': 'onDocumentPointerDown($event)',\n '(document:keydown.escape)': 'onEscape()',\n },\n template: `\n @if (available) {\n <button\n #trigger\n type=\"button\"\n class=\"shk-tp-trigger\"\n aria-haspopup=\"dialog\"\n [attr.aria-expanded]=\"open()\"\n [attr.aria-controls]=\"panelId\"\n [attr.aria-label]=\"triggerLabel()\"\n [attr.title]=\"triggerLabel()\"\n (click)=\"toggle()\"\n >\n <svg [shkIcon]=\"paletteIcon\" class=\"shk-tp-trigger-icon\"></svg>\n </button>\n\n @if (open()) {\n <div class=\"shk-tp-panel _shk-bg-panel-raised\" role=\"dialog\" [id]=\"panelId\" [attr.aria-label]=\"triggerLabel()\">\n <div class=\"shk-tp-section\">\n <span class=\"shk-tp-title\" [id]=\"panelId + '-primary'\">{{ primaryLabel() }}</span>\n <div class=\"shk-tp-swatches\" role=\"group\" [attr.aria-labelledby]=\"panelId + '-primary'\">\n @for (item of primaryColors(); track item.color) {\n <button\n type=\"button\"\n class=\"shk-tp-swatch\"\n [style.background-color]=\"item.color\"\n [class.is-selected]=\"item.color.toLowerCase() === activePrimary()\"\n [attr.aria-pressed]=\"item.color.toLowerCase() === activePrimary()\"\n [attr.aria-label]=\"item.label\"\n [attr.title]=\"item.label\"\n (click)=\"setPrimary(item.color)\"\n ></button>\n }\n </div>\n </div>\n\n @if (showSurface()) {\n <div class=\"shk-tp-section\">\n <span class=\"shk-tp-title\" [id]=\"panelId + '-surface'\">{{ surfaceLabel() }}</span>\n <div class=\"shk-tp-swatches\" role=\"group\" [attr.aria-labelledby]=\"panelId + '-surface'\">\n @for (item of surfaces; track item.name) {\n <button\n type=\"button\"\n class=\"shk-tp-swatch\"\n [style.background-color]=\"item.color\"\n [class.is-selected]=\"item.name === activeSurface()\"\n [attr.aria-pressed]=\"item.name === activeSurface()\"\n [attr.aria-label]=\"item.label\"\n [attr.title]=\"item.label\"\n (click)=\"setSurface(item.name)\"\n ></button>\n }\n </div>\n </div>\n }\n\n @if (showPresets() && presets.length > 1) {\n <div class=\"shk-tp-section\">\n <span class=\"shk-tp-title\" [id]=\"panelId + '-presets'\">{{ presetsLabel() }}</span>\n <div class=\"shk-tp-segmented\" role=\"group\" [attr.aria-labelledby]=\"panelId + '-presets'\">\n @for (preset of presets; track preset.name) {\n <button\n type=\"button\"\n class=\"shk-tp-segment\"\n [class.is-active]=\"preset.name === themeName() && isPresetPure()\"\n [attr.aria-pressed]=\"preset.name === themeName() && isPresetPure()\"\n (click)=\"setPreset(preset.name)\"\n >\n {{ preset.label }}\n </button>\n }\n </div>\n </div>\n }\n </div>\n }\n }\n `,\n styles: [\n `\n :host { position: relative; display: inline-flex; }\n .shk-tp-trigger {\n display: grid; place-items: center; width: 2.25rem; height: 2.25rem;\n border: 0; border-radius: 9999px; cursor: pointer; color: #fff;\n background-color: var(--shk-primary-600); transition: filter 0.15s ease;\n }\n .shk-tp-trigger:hover { filter: brightness(1.1); }\n .shk-tp-trigger:focus-visible { outline: 2px solid var(--shk-primary-600); outline-offset: 2px; }\n .shk-tp-trigger-icon { width: 1.15rem; height: 1.15rem; }\n .shk-tp-panel {\n position: absolute; top: calc(100% + 0.5rem); right: 0; z-index: 70;\n width: max-content; max-width: min(19rem, calc(100vw - 1.5rem));\n padding: 0.875rem 1rem 1rem; border-radius: 0.75rem;\n border: 1px solid var(--shk-surface-200);\n box-shadow: 0 10px 30px rgb(0 0 0 / 0.14);\n display: grid; gap: 0.875rem; text-align: left;\n }\n .shk-tp-title { display: block; margin-bottom: 0.5rem; font-size: 0.8125rem; font-weight: 600; color: var(--shk-surface-600); }\n .shk-tp-swatches { display: grid; grid-template-columns: repeat(8, 1.375rem); gap: 0.5rem; }\n .shk-tp-swatch {\n width: 1.375rem; height: 1.375rem; padding: 0; border: 0; border-radius: 9999px; cursor: pointer;\n transition: transform 0.12s ease;\n }\n .shk-tp-swatch:hover { transform: scale(1.12); }\n .shk-tp-swatch:focus-visible, .shk-tp-swatch.is-selected {\n outline: 2px solid var(--shk-surface-800); outline-offset: 2px;\n }\n .shk-tp-segmented {\n display: flex; flex-wrap: wrap; gap: 0.25rem; padding: 0.25rem;\n border-radius: 0.5rem; background-color: var(--shk-surface-100);\n }\n .shk-tp-segment {\n padding: 0.3rem 0.65rem; border: 0; border-radius: 0.375rem; background: transparent;\n font-size: 0.8125rem; color: var(--shk-surface-600); cursor: pointer;\n }\n .shk-tp-segment:hover { color: var(--shk-surface-800); }\n .shk-tp-segment:focus-visible { outline: 2px solid var(--shk-primary-600); outline-offset: 1px; }\n .shk-tp-segment.is-active {\n background-color: var(--shk-surface-50); color: var(--shk-surface-900);\n font-weight: 600; box-shadow: 0 1px 2px rgb(0 0 0 / 0.12);\n }\n `,\n ],\n})\nexport class ThemePickerComponent {\n private readonly config = inject(ShkConfigService);\n private readonly host = inject<ElementRef<HTMLElement>>(ElementRef);\n private readonly trigger = viewChild<ElementRef<HTMLButtonElement>>('trigger');\n\n /** Primary colors offered. */\n readonly primaryColors = input<readonly ShkPickerColor[]>(DEFAULT_PRIMARY_COLORS);\n /** Shows the surface (neutral palette) section. */\n readonly showSurface = input<boolean>(true);\n /** Shows the theme presets section (needs more than one preset). */\n readonly showPresets = input<boolean>(true);\n /** Accessible name and tooltip of the button. */\n readonly triggerLabel = input<string>('Personalizar tema');\n readonly primaryLabel = input<string>('Primario');\n readonly surfaceLabel = input<string>('Superficie');\n readonly presetsLabel = input<string>('Temas');\n\n /** `theme.*` options exist only when the app uses `withTheme()`. */\n protected readonly available = this.config.has('theme.primary') && this.config.has('theme.surface');\n protected readonly open = signal(false);\n protected readonly panelId = `shk-theme-picker-${++pickerCounter}`;\n protected readonly paletteIcon = getIcon('palette');\n protected readonly presets = inject(SHK_THEME_PRESETS);\n\n /** Surface palettes, each shown with its 500 shade. */\n protected readonly surfaces = Object.entries(SURFACE_PALETTES).map(([name, palette]) => ({\n name,\n label: palette.label,\n color: palette.scale[5],\n }));\n\n protected readonly themeName = computed(() =>\n this.available ? this.config.get<string>('theme.name')() : '',\n );\n private readonly currentPreset = computed(() =>\n this.presets.find((preset) => preset.name === this.themeName()),\n );\n private readonly primaryOverride = computed(() =>\n this.available ? this.config.get<string>('theme.primary')() : '',\n );\n private readonly surfaceOverride = computed(() =>\n this.available ? this.config.get<string>('theme.surface')() : '',\n );\n\n /** Primary color in use: the override, else the preset's own (lowercase hex). */\n protected readonly activePrimary = computed(() =>\n (this.primaryOverride() || this.currentPreset()?.primary || '').toLowerCase(),\n );\n /** Surface palette in use: the override, else the preset's own. */\n protected readonly activeSurface = computed(\n () => this.surfaceOverride() || this.currentPreset()?.surface || '',\n );\n /** True while no primary/surface override is applied on top of the preset. */\n protected readonly isPresetPure = computed(() => !this.primaryOverride() && !this.surfaceOverride());\n\n protected toggle(): void {\n this.open.update((open) => !open);\n }\n\n protected setPrimary(color: string): void {\n // Picking the preset's own color clears the override instead of pinning it.\n const own = this.currentPreset()?.primary.toLowerCase();\n this.config.set('theme.primary', color.toLowerCase() === own ? '' : color);\n }\n\n protected setSurface(name: string): void {\n this.config.set('theme.surface', name === this.currentPreset()?.surface ? '' : name);\n }\n\n /** Applies a theme pack and clears the primary/surface overrides. */\n protected setPreset(name: string): void {\n this.config.set('theme.name', name);\n this.config.set('theme.primary', '');\n this.config.set('theme.surface', '');\n }\n\n protected onDocumentPointerDown(event: PointerEvent): void {\n if (this.open() && !this.host.nativeElement.contains(event.target as Node)) {\n this.open.set(false);\n }\n }\n\n protected onEscape(): void {\n if (!this.open()) return;\n this.open.set(false);\n this.trigger()?.nativeElement.focus();\n }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,OAAA;IAAA,UAAA;GAAA,CAAA;EAAA,CAAA;EAAA,cAAA,CAAA;GAAA,MAAA,GAAA;GAAA,MAAA,CAAA;IAAA,UAAA;IAAA,OAAA;IAAA,UAAA;GAAA,CAAA;EAAA,CAAA;CAAA;AAAA,CAAA"}
1
+ {"version":3,"file":"shirkasoft-ui-components-theme-picker.mjs","names":[],"sources":["../../../projects/ui-components/theme-picker/theme-picker.component.ts"],"sourcesContent":["import {\n ChangeDetectionStrategy,\n Component,\n ElementRef,\n computed,\n inject,\n input,\n signal,\n viewChild,\n} from '@angular/core';\nimport { NgTemplateOutlet } from '@angular/common';\nimport {\n SHK_THEME_PRESETS,\n SURFACE_PALETTES,\n ShkConfigService,\n ShkLabels,\n ShkThemePreset,\n} from 'shirkasoft-ui-components/config';\nimport { ShkIconDirective } from 'shirkasoft-ui-components/icons';\nimport { getIcon } from 'shirkasoft-ui-components/utils';\n\n/**\n * Shirkasoft UI Components.\n * Authors: Roberto Valladares Martin (Ansem13), Julio César García García (Sanjuli14).\n * Belongs to Shirkasoft.\n */\n\n/** A primary color offered by the picker. */\nexport interface ShkPickerColor {\n /** Hex color; it becomes `--shk-primary-600` (`theme.primary`). */\n color: string;\n /** Accessible name / tooltip (English fallback). */\n label: string;\n /** Translation key of the label. */\n labelKey?: string;\n}\n\n/**\n * Default primary colors (Tailwind 600 shades). Red and rose are left out on\n * purpose: red is reserved for danger states.\n */\nexport const DEFAULT_PRIMARY_COLORS: readonly ShkPickerColor[] = [\n { color: '#334155', label: 'Noir', labelKey: 'theme.colors.noir' },\n { color: '#059669', label: 'Emerald', labelKey: 'theme.colors.emerald' },\n { color: '#16a34a', label: 'Green', labelKey: 'theme.colors.green' },\n { color: '#65a30d', label: 'Lime', labelKey: 'theme.colors.lime' },\n { color: '#ea580c', label: 'Orange', labelKey: 'theme.colors.orange' },\n { color: '#d97706', label: 'Amber', labelKey: 'theme.colors.amber' },\n { color: '#ca8a04', label: 'Yellow', labelKey: 'theme.colors.yellow' },\n { color: '#0d9488', label: 'Teal', labelKey: 'theme.colors.teal' },\n { color: '#0891b2', label: 'Cyan', labelKey: 'theme.colors.cyan' },\n { color: '#0284c7', label: 'Sky', labelKey: 'theme.colors.sky' },\n { color: '#2563eb', label: 'Blue', labelKey: 'theme.colors.blue' },\n { color: '#4f46e5', label: 'Indigo', labelKey: 'theme.colors.indigo' },\n { color: '#7c3aed', label: 'Violet', labelKey: 'theme.colors.violet' },\n { color: '#9333ea', label: 'Purple', labelKey: 'theme.colors.purple' },\n { color: '#c026d3', label: 'Fuchsia', labelKey: 'theme.colors.fuchsia' },\n { color: '#db2777', label: 'Pink', labelKey: 'theme.colors.pink' },\n];\n\nlet pickerCounter = 0;\n\n/**\n * Theme customizer: a palette button that opens a panel to pick a theme preset,\n * the primary color and the surface (neutral) palette at runtime.\n *\n * It edits the `theme.name`, `theme.primary` and `theme.surface` options, so it\n * needs `provideShk(withTheme(...))`. Without `withTheme()` it renders nothing.\n *\n * ```html\n * <!-- User preference (device layer) -->\n * <shk-theme-picker />\n *\n * <!-- Embedded in a settings screen (admin preview writes the draft) -->\n * <shk-theme-picker [inline]=\"true\" />\n * ```\n *\n * While `ShkConfigSync.preview()` is active every write goes to the draft, so\n * the same component serves the user and the admin without knowing about\n * layers.\n */\n@Component({\n selector: 'shk-theme-picker',\n changeDetection: ChangeDetectionStrategy.OnPush,\n imports: [ShkIconDirective, NgTemplateOutlet],\n host: {\n class: 'shk-theme-picker',\n '[class.is-inline]': 'inline()',\n '(document:pointerdown)': 'onDocumentPointerDown($event)',\n '(document:keydown.escape)': 'onEscape()',\n },\n template: `\n @if (available) {\n @if (inline()) {\n <div\n class=\"shk-tp-panel is-inline\"\n role=\"group\"\n [attr.aria-label]=\"triggerText()\"\n >\n <ng-container *ngTemplateOutlet=\"sections\" />\n </div>\n } @else {\n <button\n #trigger\n type=\"button\"\n class=\"shk-tp-trigger\"\n aria-haspopup=\"dialog\"\n [attr.aria-expanded]=\"open()\"\n [attr.aria-controls]=\"panelId\"\n [attr.aria-label]=\"triggerText()\"\n [attr.title]=\"triggerText()\"\n (click)=\"toggle()\"\n >\n <svg [shkIcon]=\"paletteIcon\" class=\"shk-tp-trigger-icon\"></svg>\n </button>\n\n @if (open()) {\n <div\n class=\"shk-tp-panel _shk-bg-panel-raised\"\n role=\"dialog\"\n [id]=\"panelId\"\n [attr.aria-label]=\"triggerText()\"\n >\n <ng-container *ngTemplateOutlet=\"sections\" />\n </div>\n }\n }\n }\n\n <ng-template #sections>\n @if (showPresets() && presets.length > 1) {\n <div class=\"shk-tp-section\">\n <span class=\"shk-tp-title\" [id]=\"panelId + '-presets'\">{{ presetsText() }}</span>\n <div class=\"shk-tp-segmented\" role=\"group\" [attr.aria-labelledby]=\"panelId + '-presets'\">\n @for (preset of presets; track preset.name) {\n <button\n type=\"button\"\n class=\"shk-tp-segment\"\n [class.is-active]=\"preset.name === themeName() && isPresetPure()\"\n [attr.aria-pressed]=\"preset.name === themeName() && isPresetPure()\"\n (click)=\"setPreset(preset.name)\"\n >\n {{ presetLabel(preset) }}\n </button>\n }\n </div>\n </div>\n }\n\n <div class=\"shk-tp-section\">\n <span class=\"shk-tp-title\" [id]=\"panelId + '-primary'\">{{ primaryText() }}</span>\n <div class=\"shk-tp-swatches\" role=\"group\" [attr.aria-labelledby]=\"panelId + '-primary'\">\n @for (item of primaryColors(); track item.color) {\n <button\n type=\"button\"\n class=\"shk-tp-swatch\"\n [style.background-color]=\"item.color\"\n [class.is-selected]=\"item.color.toLowerCase() === activePrimary()\"\n [attr.aria-pressed]=\"item.color.toLowerCase() === activePrimary()\"\n [attr.aria-label]=\"colorLabel(item)\"\n [attr.title]=\"colorLabel(item)\"\n (click)=\"setPrimary(item.color)\"\n ></button>\n }\n </div>\n </div>\n\n @if (showSurface()) {\n <div class=\"shk-tp-section\">\n <span class=\"shk-tp-title\" [id]=\"panelId + '-surface'\">{{ surfaceText() }}</span>\n <div class=\"shk-tp-swatches\" role=\"group\" [attr.aria-labelledby]=\"panelId + '-surface'\">\n @for (item of surfaces; track item.name) {\n <button\n type=\"button\"\n class=\"shk-tp-swatch\"\n [style.background-color]=\"item.color\"\n [class.is-selected]=\"item.name === activeSurface()\"\n [attr.aria-pressed]=\"item.name === activeSurface()\"\n [attr.aria-label]=\"surfaceName(item.name)\"\n [attr.title]=\"surfaceName(item.name)\"\n (click)=\"setSurface(item.name)\"\n ></button>\n }\n </div>\n </div>\n }\n </ng-template>\n `,\n styles: [\n `\n :host { position: relative; display: inline-flex; }\n :host(.is-inline) { display: block; width: 100%; }\n .shk-tp-trigger {\n display: grid; place-items: center; width: 2.25rem; height: 2.25rem;\n border: 0; border-radius: 9999px; cursor: pointer; color: #fff;\n background-color: var(--shk-primary-600); transition: filter 0.15s ease;\n }\n .shk-tp-trigger:hover { filter: brightness(1.1); }\n .shk-tp-trigger:focus-visible { outline: 2px solid var(--shk-primary-600); outline-offset: 2px; }\n .shk-tp-trigger-icon { width: 1.15rem; height: 1.15rem; }\n .shk-tp-panel {\n position: absolute; top: calc(100% + 0.5rem); right: 0; z-index: 70;\n width: max-content; max-width: min(19rem, calc(100vw - 1.5rem));\n padding: 0.875rem 1rem 1rem; border-radius: 0.75rem;\n border: 1px solid var(--shk-surface-200);\n box-shadow: 0 10px 30px rgb(0 0 0 / 0.14);\n display: grid; gap: 0.875rem; text-align: left;\n }\n /* Embedded: the host card already provides the surface. */\n .shk-tp-panel.is-inline {\n position: static; width: 100%; max-width: none; padding: 0;\n border: 0; border-radius: 0; box-shadow: none; background: transparent;\n }\n .shk-tp-title { display: block; margin-bottom: 0.5rem; font-size: 0.8125rem; font-weight: 600; color: var(--shk-surface-600); }\n .shk-tp-swatches { display: grid; grid-template-columns: repeat(8, 1.375rem); gap: 0.5rem; }\n .shk-tp-swatch {\n width: 1.375rem; height: 1.375rem; padding: 0; border: 0; border-radius: 9999px; cursor: pointer;\n transition: transform 0.12s ease;\n }\n .shk-tp-swatch:hover { transform: scale(1.12); }\n .shk-tp-swatch:focus-visible, .shk-tp-swatch.is-selected {\n outline: 2px solid var(--shk-surface-800); outline-offset: 2px;\n }\n .shk-tp-segmented {\n display: flex; flex-wrap: wrap; gap: 0.25rem; padding: 0.25rem;\n border-radius: 0.5rem; background-color: var(--shk-surface-100);\n }\n .shk-tp-segment {\n padding: 0.3rem 0.65rem; border: 0; border-radius: 0.375rem; background: transparent;\n font-size: 0.8125rem; color: var(--shk-surface-600); cursor: pointer;\n }\n .shk-tp-segment:hover { color: var(--shk-surface-800); }\n .shk-tp-segment:focus-visible { outline: 2px solid var(--shk-primary-600); outline-offset: 1px; }\n .shk-tp-segment.is-active {\n background-color: var(--shk-surface-50); color: var(--shk-surface-900);\n font-weight: 600; box-shadow: 0 1px 2px rgb(0 0 0 / 0.12);\n }\n `,\n ],\n})\nexport class ThemePickerComponent {\n private readonly config = inject(ShkConfigService);\n private readonly labels = inject(ShkLabels);\n private readonly host = inject<ElementRef<HTMLElement>>(ElementRef);\n private readonly trigger = viewChild<ElementRef<HTMLButtonElement>>('trigger');\n\n /** Primary colors offered. */\n readonly primaryColors = input<readonly ShkPickerColor[]>(DEFAULT_PRIMARY_COLORS);\n /** Shows the surface (neutral palette) section. */\n readonly showSurface = input<boolean>(true);\n /** Shows the theme presets section (needs more than one preset). */\n readonly showPresets = input<boolean>(true);\n /** Renders the panel inline (no button, no popover) to embed it in a page. */\n readonly inline = input<boolean>(false);\n\n /** Accessible name and tooltip of the button. Defaults to the translated label. */\n readonly triggerLabel = input<string | undefined>(undefined);\n readonly primaryLabel = input<string | undefined>(undefined);\n readonly surfaceLabel = input<string | undefined>(undefined);\n readonly presetsLabel = input<string | undefined>(undefined);\n\n /** `theme.*` options exist only when the app uses `withTheme()`. */\n protected readonly available = this.config.has('theme.primary') && this.config.has('theme.surface');\n protected readonly open = signal(false);\n protected readonly panelId = `shk-theme-picker-${++pickerCounter}`;\n protected readonly paletteIcon = getIcon('palette');\n protected readonly presets = inject(SHK_THEME_PRESETS);\n\n /** Surface palettes, each shown with its 500 shade. */\n protected readonly surfaces = Object.entries(SURFACE_PALETTES).map(([name, palette]) => ({\n name,\n label: palette.label,\n color: palette.scale[5],\n }));\n\n protected readonly triggerText = computed(\n () => this.triggerLabel() ?? this.labels.get('theme.picker.trigger', 'Customize theme'),\n );\n protected readonly primaryText = computed(\n () => this.primaryLabel() ?? this.labels.get('theme.picker.primary', 'Primary'),\n );\n protected readonly surfaceText = computed(\n () => this.surfaceLabel() ?? this.labels.get('theme.picker.surface', 'Surface'),\n );\n protected readonly presetsText = computed(\n () => this.presetsLabel() ?? this.labels.get('theme.picker.presets', 'Themes'),\n );\n\n protected readonly themeName = computed(() =>\n this.available ? this.config.get<string>('theme.name')() : '',\n );\n private readonly currentPreset = computed(() =>\n this.presets.find((preset) => preset.name === this.themeName()),\n );\n private readonly primaryOverride = computed(() =>\n this.available ? this.config.get<string>('theme.primary')() : '',\n );\n private readonly surfaceOverride = computed(() =>\n this.available ? this.config.get<string>('theme.surface')() : '',\n );\n\n /** Primary color in use: the override, else the preset's own (lowercase hex). */\n protected readonly activePrimary = computed(() =>\n (this.primaryOverride() || this.currentPreset()?.primary || '').toLowerCase(),\n );\n /** Surface palette in use: the override, else the preset's own. */\n protected readonly activeSurface = computed(\n () => this.surfaceOverride() || this.currentPreset()?.surface || '',\n );\n /** True while no primary/surface override is applied on top of the preset. */\n protected readonly isPresetPure = computed(() => !this.primaryOverride() && !this.surfaceOverride());\n\n /** Translated name of a preset. */\n protected presetLabel(preset: ShkThemePreset): string {\n return this.labels.get(preset.labelKey, preset.label);\n }\n\n /** Translated name of a primary color. */\n protected colorLabel(item: ShkPickerColor): string {\n return this.labels.get(item.labelKey, item.label);\n }\n\n /** Translated name of a surface palette. */\n protected surfaceName(name: string): string {\n const palette = SURFACE_PALETTES[name];\n return this.labels.get(`theme.surfaces.${name}`, palette?.label ?? name);\n }\n\n protected toggle(): void {\n this.open.update((open) => !open);\n }\n\n protected setPrimary(color: string): void {\n // Picking the preset's own color clears the override instead of pinning it.\n const own = this.currentPreset()?.primary.toLowerCase();\n this.config.set('theme.primary', color.toLowerCase() === own ? '' : color, 'device');\n }\n\n protected setSurface(name: string): void {\n this.config.set('theme.surface', name === this.currentPreset()?.surface ? '' : name, 'device');\n }\n\n /** Applies a theme pack and clears the primary/surface overrides. */\n protected setPreset(name: string): void {\n this.config.set('theme.name', name, 'device');\n this.config.set('theme.primary', '', 'device');\n this.config.set('theme.surface', '', 'device');\n }\n\n protected onDocumentPointerDown(event: PointerEvent): void {\n if (this.open() && !this.host.nativeElement.contains(event.target as Node)) {\n this.open.set(false);\n }\n }\n\n protected onEscape(): void {\n if (!this.open()) return;\n this.open.set(false);\n this.trigger()?.nativeElement.focus();\n }\n}\n"],"mappings":";;;;;;AAyCA,MAAa,yBAAoD;CAC/D;EAAE,OAAO;EAAW,OAAO;EAAQ,UAAU;CAAmB;CAChE;EAAE,OAAO;EAAW,OAAO;EAAW,UAAU;CAAsB;CACtE;EAAE,OAAO;EAAW,OAAO;EAAS,UAAU;CAAoB;CAClE;EAAE,OAAO;EAAW,OAAO;EAAQ,UAAU;CAAmB;CAChE;EAAE,OAAO;EAAW,OAAO;EAAU,UAAU;CAAqB;CACpE;EAAE,OAAO;EAAW,OAAO;EAAS,UAAU;CAAoB;CAClE;EAAE,OAAO;EAAW,OAAO;EAAU,UAAU;CAAqB;CACpE;EAAE,OAAO;EAAW,OAAO;EAAQ,UAAU;CAAmB;CAChE;EAAE,OAAO;EAAW,OAAO;EAAQ,UAAU;CAAmB;CAChE;EAAE,OAAO;EAAW,OAAO;EAAO,UAAU;CAAkB;CAC9D;EAAE,OAAO;EAAW,OAAO;EAAQ,UAAU;CAAmB;CAChE;EAAE,OAAO;EAAW,OAAO;EAAU,UAAU;CAAqB;CACpE;EAAE,OAAO;EAAW,OAAO;EAAU,UAAU;CAAqB;CACpE;EAAE,OAAO;EAAW,OAAO;EAAU,UAAU;CAAqB;CACpE;EAAE,OAAO;EAAW,OAAO;EAAW,UAAU;CAAsB;CACtE;EAAE,O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CAAA,WAAS,EAAA,UAAA,KAAA,CAAA;EAAA,CAAA;EAAA,eAAA,CAAA;GAAA,MAAA,GAAA;GAAA,MAAA,CAAA;IAAA,UAAA;IAAA,OAAA;IAAA,UAAA;GAAA,CAAA;EAAA,CAAA;EAAA,aAAA,CAAA;GAAA,MAAA,GAAA;GAAA,MAAA,CAAA;IAAA,UAAA;IAAA,OAAA;IAAA,UAAA;GAAA,CAAA;EAAA,CAAA;EAAA,aAAA,CAAA;GAAA,MAAA,GAAA;GAAA,MAAA,CAAA;IAAA,UAAA;IAAA,OAAA;IAAA,UAAA;GAAA,CAAA;EAAA,CAAA;EAAA,QAAA,CAAA;GAAA,MAAA,GAAA;GAAA,MAAA,CAAA;IAAA,UAAA;IAAA,OAAA;IAAA,UAAA;GAAA,CAAA;EAAA,CAAA;EAAA,cAAA,CAAA;GAAA,MAAA,GAAA;GAAA,MAAA,CAAA;IAAA,UAAA;IAAA,OAAA;IAAA,UAAA;GAAA,CAAA;EAAA,CAAA;EAAA,cAAA,CAAA;GAAA,MAAA,GAAA;GAAA,MAAA,CAAA;IAAA,UAAA;IAAA,OAAA;IAAA,UAAA;GAAA,CAAA;EAAA,CAAA;EAAA,cAAA,CAAA;GAAA,MAAA,GAAA;GAAA,MAAA,CAAA;IAAA,UAAA;IAAA,OAAA;IAAA,UAAA;GAAA,CAAA;EAAA,CAAA;EAAA,cAAA,CAAA;GAAA,MAAA,GAAA;GAAA,MAAA,CAAA;IAAA,UAAA;IAAA,OAAA;IAAA,UAAA;GAAA,CAAA;EAAA,CAAA;CAAA;AAAA,CAAA"}
@@ -21,7 +21,6 @@ const SHK_THEME_CONFIG = new InjectionToken("SHK_THEME_CONFIG", {
21
21
  factory: () => DEFAULT_SHK_THEME_CONFIG
22
22
  });
23
23
  const DARK_QUERY = "(prefers-color-scheme: dark)";
24
- const RETIRED_THEMES = ["rose"];
25
24
  var ShkThemeService = class ShkThemeService {
26
25
  constructor() {
27
26
  this.doc = inject(DOCUMENT);
@@ -32,20 +31,19 @@ var ShkThemeService = class ShkThemeService {
32
31
  this.scheme = signal(this.config.defaultScheme, ...ngDevMode ? [{ debugName: "scheme" }] : /* istanbul ignore next */ []);
33
32
  this.isDark = signal(false, ...ngDevMode ? [{ debugName: "isDark" }] : /* istanbul ignore next */ []);
34
33
  this.isSystem = computed(() => this.scheme() === "system", ...ngDevMode ? [{ debugName: "isSystem" }] : /* istanbul ignore next */ []);
35
- this.restore();
36
34
  this.applyTheme(this.theme());
37
35
  this.applyScheme(this.scheme());
38
36
  this.watchSystem();
39
37
  }
40
38
  setTheme(theme) {
39
+ if (this.theme() === theme) return;
41
40
  this.theme.set(theme);
42
41
  this.applyTheme(theme);
43
- this.persist(this.config.storageKey, theme);
44
42
  }
45
43
  setScheme(scheme) {
44
+ if (this.scheme() === scheme) return;
46
45
  this.scheme.set(scheme);
47
46
  this.applyScheme(scheme);
48
- this.persist(this.config.schemeStorageKey, scheme);
49
47
  }
50
48
  toggleDark() {
51
49
  this.setScheme(this.isDark() ? "light" : "dark");
@@ -53,13 +51,6 @@ var ShkThemeService = class ShkThemeService {
53
51
  previewTheme(theme) {
54
52
  this.applyTheme(theme);
55
53
  }
56
- restore() {
57
- if (!this.config.persist) return;
58
- const storedTheme = this.read(this.config.storageKey);
59
- if (storedTheme && !RETIRED_THEMES.includes(storedTheme)) this.theme.set(storedTheme);
60
- const storedScheme = this.read(this.config.schemeStorageKey);
61
- if (storedScheme === "light" || storedScheme === "dark" || storedScheme === "system") this.scheme.set(storedScheme);
62
- }
63
54
  applyTheme(theme) {
64
55
  const root = this.doc?.documentElement;
65
56
  if (!root) return;
@@ -87,19 +78,6 @@ var ShkThemeService = class ShkThemeService {
87
78
  prefersDark() {
88
79
  return this.win?.matchMedia?.(DARK_QUERY).matches ?? false;
89
80
  }
90
- read(key) {
91
- try {
92
- return this.win?.localStorage?.getItem(key) ?? null;
93
- } catch {
94
- return null;
95
- }
96
- }
97
- persist(key, value) {
98
- if (!this.config.persist) return;
99
- try {
100
- this.win?.localStorage?.setItem(key, value);
101
- } catch {}
102
- }
103
81
  static {
104
82
  this.ɵfac = i0.ɵɵngDeclareFactory({
105
83
  minVersion: "12.0.0",
@@ -1 +1 @@
1
- {"version":3,"file":"shirkasoft-ui-components-theme.mjs","names":[],"sources":["../../../projects/ui-components/theme/theme.config.ts","../../../projects/ui-components/theme/theme.service.ts","../../../projects/ui-components/theme/theme.providers.ts"],"sourcesContent":["import { InjectionToken } from '@angular/core';\n\n/** Built-in theme packs shipped with the library. */\nexport type ShkThemeName = 'default' | 'ocean' | 'violet' | 'sunset' | (string & {});\n\n/** Color scheme selection. `system` follows `prefers-color-scheme`. */\nexport type ShkColorScheme = 'light' | 'dark' | 'system';\n\nexport interface ShkThemeConfig {\n /** Theme applied when nothing is stored yet. Defaults to `default`. */\n defaultTheme?: ShkThemeName;\n /** Scheme applied when nothing is stored yet. Defaults to `system`. */\n defaultScheme?: ShkColorScheme;\n /** Persist the selection in localStorage. Defaults to `true`. */\n persist?: boolean;\n /** localStorage keys. */\n storageKey?: string;\n schemeStorageKey?: string;\n /** Attribute written on <html>. Defaults to `data-shk-theme`. */\n attribute?: string;\n /** Class toggled on <html> for dark mode. Defaults to `dark`. */\n darkClass?: string;\n}\n\nexport type ResolvedShkThemeConfig = Required<ShkThemeConfig>;\n\nexport const SHK_THEMES: readonly ShkThemeName[] = ['default', 'ocean', 'violet', 'sunset'];\n\nexport const DEFAULT_SHK_THEME_CONFIG: ResolvedShkThemeConfig = {\n defaultTheme: 'default',\n defaultScheme: 'system',\n persist: true,\n storageKey: 'shk-theme',\n schemeStorageKey: 'shk-scheme',\n attribute: 'data-shk-theme',\n darkClass: 'dark',\n};\n\nexport const SHK_THEME_CONFIG = new InjectionToken<ResolvedShkThemeConfig>('SHK_THEME_CONFIG', {\n providedIn: 'root',\n factory: () => DEFAULT_SHK_THEME_CONFIG,\n});\n","/**\n * Shirkasoft UI Components.\n * Authors: Roberto Valladares Martin (Ansem13), Julio César García García (Sanjuli14).\n * Belongs to Shirkasoft.\n */\nimport { DOCUMENT } from '@angular/common';\nimport { Injectable, computed, inject, signal } from '@angular/core';\n\nimport {\n SHK_THEMES,\n SHK_THEME_CONFIG,\n ShkColorScheme,\n ShkThemeName,\n} from './theme.config';\n\nconst DARK_QUERY = '(prefers-color-scheme: dark)';\n\n/** Theme packs removed in previous releases; a stored value falls back to the default. */\nconst RETIRED_THEMES: readonly string[] = ['rose'];\n\n/**\n * Applies and persists the color theme.\n *\n * Themes are plain CSS custom properties, so switching a theme is just an\n * attribute change on `<html>` — no component re-render involved.\n */\n@Injectable({ providedIn: 'root' })\nexport class ShkThemeService {\n private readonly doc = inject(DOCUMENT);\n private readonly config = inject(SHK_THEME_CONFIG);\n private readonly win = this.doc.defaultView;\n\n /** Every theme name the service knows about. */\n readonly availableThemes = SHK_THEMES;\n\n /** Currently active theme. */\n readonly theme = signal<ShkThemeName>(this.config.defaultTheme);\n\n /** Currently selected scheme (`light`, `dark` or `system`). */\n readonly scheme = signal<ShkColorScheme>(this.config.defaultScheme);\n\n /** `true` when dark colors are being applied. */\n readonly isDark = signal(false);\n\n /** Convenience flag for templates. */\n readonly isSystem = computed(() => this.scheme() === 'system');\n\n private mediaQuery?: MediaQueryList;\n\n constructor() {\n this.restore();\n this.applyTheme(this.theme());\n this.applyScheme(this.scheme());\n this.watchSystem();\n }\n\n /** Switches the active theme pack. */\n setTheme(theme: ShkThemeName): void {\n this.theme.set(theme);\n this.applyTheme(theme);\n this.persist(this.config.storageKey, theme);\n }\n\n /** Selects light, dark or system scheme. */\n setScheme(scheme: ShkColorScheme): void {\n this.scheme.set(scheme);\n this.applyScheme(scheme);\n this.persist(this.config.schemeStorageKey, scheme);\n }\n\n /** Flips between light and dark (leaves `system` on the opposite value). */\n toggleDark(): void {\n this.setScheme(this.isDark() ? 'light' : 'dark');\n }\n\n /** Applies a theme without persisting it (useful for previews). */\n previewTheme(theme: ShkThemeName): void {\n this.applyTheme(theme);\n }\n\n private restore(): void {\n if (!this.config.persist) return;\n\n const storedTheme = this.read(this.config.storageKey);\n if (storedTheme && !RETIRED_THEMES.includes(storedTheme)) this.theme.set(storedTheme);\n\n const storedScheme = this.read(this.config.schemeStorageKey) as ShkColorScheme | null;\n if (storedScheme === 'light' || storedScheme === 'dark' || storedScheme === 'system') {\n this.scheme.set(storedScheme);\n }\n }\n\n private applyTheme(theme: ShkThemeName): void {\n const root = this.doc?.documentElement;\n if (!root) return;\n\n if (theme === 'default') {\n root.removeAttribute(this.config.attribute);\n } else {\n root.setAttribute(this.config.attribute, theme);\n }\n }\n\n private applyScheme(scheme: ShkColorScheme): void {\n const root = this.doc?.documentElement;\n if (!root) return;\n\n const dark = scheme === 'dark' || (scheme === 'system' && this.prefersDark());\n root.classList.toggle(this.config.darkClass, dark);\n root.style.colorScheme = dark ? 'dark' : 'light';\n this.isDark.set(dark);\n }\n\n private watchSystem(): void {\n if (!this.win?.matchMedia) return;\n\n this.mediaQuery ??= this.win.matchMedia(DARK_QUERY);\n const onChange = (event: MediaQueryListEvent) => {\n if (this.scheme() !== 'system') return;\n this.applyScheme(event.matches ? 'dark' : 'light');\n };\n\n // Safari < 14 only supports addListener.\n if (this.mediaQuery.addEventListener) {\n this.mediaQuery.addEventListener('change', onChange);\n } else {\n this.mediaQuery.addListener(onChange);\n }\n }\n\n private prefersDark(): boolean {\n return this.win?.matchMedia?.(DARK_QUERY).matches ?? false;\n }\n\n private read(key: string): string | null {\n try {\n return this.win?.localStorage?.getItem(key) ?? null;\n } catch {\n return null;\n }\n }\n\n private persist(key: string, value: string): void {\n if (!this.config.persist) return;\n\n try {\n this.win?.localStorage?.setItem(key, value);\n } catch {\n // Storage can be blocked (private mode, iframe, quota). Theme still applies.\n }\n }\n}\n","/**\n * Shirkasoft UI Components.\n * Authors: Roberto Valladares Martin (Ansem13), Julio César García García (Sanjuli14).\n * Belongs to Shirkasoft.\n */\nimport {\n EnvironmentProviders,\n inject,\n makeEnvironmentProviders,\n provideAppInitializer,\n} from '@angular/core';\n\nimport { DEFAULT_SHK_THEME_CONFIG, SHK_THEME_CONFIG, ShkThemeConfig } from './theme.config';\nimport { ShkThemeService } from './theme.service';\n\n/**\n * Configures the theme system and applies the stored/default theme while the\n * app boots, so it is active even if nothing injects `ShkThemeService`.\n *\n * ```ts\n * bootstrapApplication(App, {\n * providers: [provideShkTheme({ defaultTheme: 'ocean', defaultScheme: 'dark' })],\n * });\n * ```\n */\nexport function provideShkTheme(config: ShkThemeConfig = {}): EnvironmentProviders {\n return makeEnvironmentProviders([\n { provide: SHK_THEME_CONFIG, useValue: { ...DEFAULT_SHK_THEME_CONFIG, ...config } },\n provideAppInitializer(() => {\n inject(ShkThemeService);\n }),\n ]);\n}\n"],"mappings":";;;AA0BA,MAAa,aAAsC;CAAC;CAAW;CAAS;CAAU;AAAQ;AAE1F,MAAa,2BAAmD;CAC9D,cAAc;CACd,eAAe;CACf,SAAS;CACT,YAAY;CACZ,kBAAkB;CAClB,WAAW;CACX,WAAW;AACZ;AAED,MAAa,mBAAmB,IAAI,eAAuC,oBAAoB;CAC7F,YAAY;CACZ,eAAe;AAChB,CAAA;AC1BD,MAAM,aAAa;AAGnB,MAAM,iBAAoC,CAAC,MAAM;AASjD,IAAa,kBAAb,MAAa,gBAAe;CAsB1B,cAAA;EArBiB,KAAA,MAAM,OAAO,QAAQ;EACrB,KAAA,SAAS,OAAO,gBAAgB;EAChC,KAAA,MAAM,KAAK,IAAI;EAGvB,KAAA,kBAAkB;EAGlB,KAAA,QAAQ,OAAqB,KAAK,OAAO,cAAa,GAAA,YAAA,CAAA,EAAA,WAAA,QAAA,CAAA,+BAAA,CAAA,CAAA;EAGtD,KAAA,SAAS,OAAuB,KAAK,OAAO,eAAc,GAAA,YAAA,CAAA,EAAA,WAAA,SAAA,CAAA,+BAAA,CAAA,CAAA;EAG1D,KAAA,SAAS,OAAO,OAAM,GAAA,YAAA,CAAA,EAAA,WAAA,SAAA,CAAA,+BAAA,CAAA,CAAA;EAGtB,KAAA,WAAW,e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G;GAA0B,GAAG;EAAM;CAAE,GACjF,4BAA2B;EACzB,OAAO,eAAe;CACxB,CAAC,CACF,CAAA;AACH"}
1
+ {"version":3,"file":"shirkasoft-ui-components-theme.mjs","names":[],"sources":["../../../projects/ui-components/theme/theme.config.ts","../../../projects/ui-components/theme/theme.service.ts","../../../projects/ui-components/theme/theme.providers.ts"],"sourcesContent":["import { InjectionToken } from '@angular/core';\n\n/** Built-in theme packs shipped with the library. */\nexport type ShkThemeName = 'default' | 'ocean' | 'violet' | 'sunset' | (string & {});\n\n/** Color scheme selection. `system` follows `prefers-color-scheme`. */\nexport type ShkColorScheme = 'light' | 'dark' | 'system';\n\nexport interface ShkThemeConfig {\n /** Theme applied when nothing is stored yet. Defaults to `default`. */\n defaultTheme?: ShkThemeName;\n /** Scheme applied when nothing is stored yet. Defaults to `system`. */\n defaultScheme?: ShkColorScheme;\n /**\n * @deprecated The selection is stored by `ShkConfigService`\n * (`provideShk(withTheme())`). Kept so `provideShkTheme()` keeps compiling.\n */\n persist?: boolean;\n /**\n * @deprecated Only read once to migrate a pre-2.1 selection into the\n * registry (`shk-config`).\n */\n storageKey?: string;\n /** @deprecated Only read once, like {@link storageKey}. */\n schemeStorageKey?: string;\n /** Attribute written on <html>. Defaults to `data-shk-theme`. */\n attribute?: string;\n /** Class toggled on <html> for dark mode. Defaults to `dark`. */\n darkClass?: string;\n}\n\nexport type ResolvedShkThemeConfig = Required<ShkThemeConfig>;\n\nexport const SHK_THEMES: readonly ShkThemeName[] = ['default', 'ocean', 'violet', 'sunset'];\n\nexport const DEFAULT_SHK_THEME_CONFIG: ResolvedShkThemeConfig = {\n defaultTheme: 'default',\n defaultScheme: 'system',\n persist: true,\n storageKey: 'shk-theme',\n schemeStorageKey: 'shk-scheme',\n attribute: 'data-shk-theme',\n darkClass: 'dark',\n};\n\nexport const SHK_THEME_CONFIG = new InjectionToken<ResolvedShkThemeConfig>('SHK_THEME_CONFIG', {\n providedIn: 'root',\n factory: () => DEFAULT_SHK_THEME_CONFIG,\n});\n","/**\n * Shirkasoft UI Components.\n * Authors: Roberto Valladares Martin (Ansem13), Julio César García García (Sanjuli14).\n * Belongs to Shirkasoft.\n */\nimport { DOCUMENT } from '@angular/common';\nimport { Injectable, computed, inject, signal } from '@angular/core';\n\nimport {\n SHK_THEMES,\n SHK_THEME_CONFIG,\n ShkColorScheme,\n ShkThemeName,\n} from './theme.config';\n\nconst DARK_QUERY = '(prefers-color-scheme: dark)';\n\n/**\n * Applies the color theme.\n *\n * Themes are plain CSS custom properties, so switching a theme is just an\n * attribute change on `<html>` — no component re-render involved.\n *\n * The service only *applies*: `theme.name` and `theme.scheme` are options of\n * `ShkConfigService`, which owns the value and its persistence (device layer,\n * shared layer or an admin preview). `withTheme()` connects both.\n */\n@Injectable({ providedIn: 'root' })\nexport class ShkThemeService {\n private readonly doc = inject(DOCUMENT);\n private readonly config = inject(SHK_THEME_CONFIG);\n private readonly win = this.doc.defaultView;\n\n /** Every theme name the service knows about. */\n readonly availableThemes = SHK_THEMES;\n\n /** Currently applied theme. */\n readonly theme = signal<ShkThemeName>(this.config.defaultTheme);\n\n /** Currently applied scheme (`light`, `dark` or `system`). */\n readonly scheme = signal<ShkColorScheme>(this.config.defaultScheme);\n\n /** `true` when dark colors are being applied. */\n readonly isDark = signal(false);\n\n /** Convenience flag for templates. */\n readonly isSystem = computed(() => this.scheme() === 'system');\n\n private mediaQuery?: MediaQueryList;\n\n constructor() {\n this.applyTheme(this.theme());\n this.applyScheme(this.scheme());\n this.watchSystem();\n }\n\n /** Switches the active theme pack. */\n setTheme(theme: ShkThemeName): void {\n if (this.theme() === theme) return;\n this.theme.set(theme);\n this.applyTheme(theme);\n }\n\n /** Selects light, dark or system scheme. */\n setScheme(scheme: ShkColorScheme): void {\n if (this.scheme() === scheme) return;\n this.scheme.set(scheme);\n this.applyScheme(scheme);\n }\n\n /** Flips between light and dark (leaves `system` on the opposite value). */\n toggleDark(): void {\n this.setScheme(this.isDark() ? 'light' : 'dark');\n }\n\n /** Applies a theme without changing the stored value (useful for previews). */\n previewTheme(theme: ShkThemeName): void {\n this.applyTheme(theme);\n }\n\n private applyTheme(theme: ShkThemeName): void {\n const root = this.doc?.documentElement;\n if (!root) return;\n\n if (theme === 'default') {\n root.removeAttribute(this.config.attribute);\n } else {\n root.setAttribute(this.config.attribute, theme);\n }\n }\n\n private applyScheme(scheme: ShkColorScheme): void {\n const root = this.doc?.documentElement;\n if (!root) return;\n\n const dark = scheme === 'dark' || (scheme === 'system' && this.prefersDark());\n root.classList.toggle(this.config.darkClass, dark);\n root.style.colorScheme = dark ? 'dark' : 'light';\n this.isDark.set(dark);\n }\n\n private watchSystem(): void {\n if (!this.win?.matchMedia) return;\n\n this.mediaQuery ??= this.win.matchMedia(DARK_QUERY);\n const onChange = (event: MediaQueryListEvent) => {\n if (this.scheme() !== 'system') return;\n this.applyScheme(event.matches ? 'dark' : 'light');\n };\n\n // Safari < 14 only supports addListener.\n if (this.mediaQuery.addEventListener) {\n this.mediaQuery.addEventListener('change', onChange);\n } else {\n this.mediaQuery.addListener(onChange);\n }\n }\n\n private prefersDark(): boolean {\n return this.win?.matchMedia?.(DARK_QUERY).matches ?? false;\n }\n}\n","/**\n * Shirkasoft UI Components.\n * Authors: Roberto Valladares Martin (Ansem13), Julio César García García (Sanjuli14).\n * Belongs to Shirkasoft.\n */\nimport {\n EnvironmentProviders,\n inject,\n makeEnvironmentProviders,\n provideAppInitializer,\n} from '@angular/core';\n\nimport { DEFAULT_SHK_THEME_CONFIG, SHK_THEME_CONFIG, ShkThemeConfig } from './theme.config';\nimport { ShkThemeService } from './theme.service';\n\n/**\n * Configures the theme system and applies the stored/default theme while the\n * app boots, so it is active even if nothing injects `ShkThemeService`.\n *\n * ```ts\n * bootstrapApplication(App, {\n * providers: [provideShkTheme({ defaultTheme: 'ocean', defaultScheme: 'dark' })],\n * });\n * ```\n */\nexport function provideShkTheme(config: ShkThemeConfig = {}): EnvironmentProviders {\n return makeEnvironmentProviders([\n { provide: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;EAAM,CAAA;CAAA;;AACnB,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAe,YAAA,CAAA;EAD3B,MAAA;EAAW,MAAA,CAAA,EAAE,YAAY,OAAM,CAAE;;;;ACFlC,SAAgB,gBAAgB,SAAyB,CAAA,GAAE;CACzD,OAAO,yBAAyB,CAC9B;EAAE,SAAS;EAAkB,UAAU;GAAE,GAAG;GAA0B,GAAG;EAAM;CAAE,GACjF,4BAA2B;EACzB,OAAO,eAAe;CACxB,CAAC,CACF,CAAA;AACH"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shirkasoft-ui-components",
3
- "version": "2.0.1",
3
+ "version": "2.1.0",
4
4
  "description": "Angular UI Components Library — themeable via CSS custom properties",
5
5
  "keywords": [
6
6
  "angular",
@@ -11,10 +11,22 @@ import { ShkThemeConfig } from "shirkasoft-ui-components/theme";
11
11
  */
12
12
  /** Kind of value an option holds; drives validation and the editor a settings UI shows. */
13
13
  type ShkOptionType = 'string' | 'number' | 'boolean' | 'select' | 'color';
14
+ /**
15
+ * Layer an option is written to by `ShkConfigService.set()`.
16
+ *
17
+ * - `device`: the user's own preference (localStorage, `withPersistence()`).
18
+ * - `shared`: the system-wide value (a `ShkConfigStore`, usually the backend).
19
+ */
20
+ type ShkConfigLayer = 'device' | 'shared';
21
+ /** Layer the current value of an option comes from. */
22
+ type ShkConfigSource = ShkConfigLayer | 'draft' | 'default';
14
23
  /** One allowed value of a `select` option. */
15
24
  interface ShkOptionChoice<T = unknown> {
16
25
  value: T;
26
+ /** English label (fallback when there is no translation). */
17
27
  label: string;
28
+ /** Translation key of the label. */
29
+ labelKey?: string;
18
30
  }
19
31
  /**
20
32
  * Definition of a configurable option (an entry of the options registry).
@@ -30,10 +42,14 @@ interface ShkOptionDef<T = unknown> {
30
42
  type: ShkOptionType;
31
43
  /** Value used until the option is set (or after `reset`). */
32
44
  default: T;
33
- /** Human-readable name for a settings screen. */
45
+ /** Human-readable name for a settings screen (English fallback). */
34
46
  label?: string;
35
- /** Longer help text for a settings screen. */
47
+ /** Translation key of `label`. */
48
+ labelKey?: string;
49
+ /** Longer help text for a settings screen (English fallback). */
36
50
  description?: string;
51
+ /** Translation key of `description`. */
52
+ descriptionKey?: string;
37
53
  /** Allowed values for `select` options. */
38
54
  choices?: readonly ShkOptionChoice<T>[];
39
55
  /**
@@ -45,9 +61,13 @@ interface ShkOptionDef<T = unknown> {
45
61
  min?: number;
46
62
  /** Upper bound for `number` options. */
47
63
  max?: number;
64
+ /**
65
+ * Layer `set()` writes to. Defaults to `device`. While a preview is active
66
+ * (`ShkConfigSync.preview()`) every write goes to the draft instead.
67
+ */
68
+ scope?: ShkConfigLayer;
48
69
  /**
49
70
  * Whether `withPersistence()` stores this option. Defaults to `true`.
50
- * Options persisted elsewhere (e.g. the theme service) set it to `false`.
51
71
  */
52
72
  persist?: boolean;
53
73
  }
@@ -56,6 +76,8 @@ interface ShkOptionEntry<T = unknown> extends ShkOptionDef<T> {
56
76
  value: T;
57
77
  /** True when the current value equals the default. */
58
78
  isDefault: boolean;
79
+ /** Layer the current value comes from. */
80
+ source: ShkConfigSource;
59
81
  }
60
82
  /** How the date picker shows the selected date when the field is not being edited. */
61
83
  type ShkDateDisplayStyle = 'long' | 'medium' | 'short' | 'format';
@@ -105,8 +127,11 @@ interface ShkConfigPersistence {
105
127
  }
106
128
  export declare const SHK_CONFIG_PERSISTENCE: InjectionToken<ShkConfigPersistence>;
107
129
  /**
108
- * Value held outside the registry (e.g. by `ShkThemeService`). The registry
109
- * reads and writes through it, so both stay in sync.
130
+ * Value held outside the registry. Kept for backwards compatibility: prefer
131
+ * `ShkConfigService.apply()` so the registry keeps owning the value.
132
+ *
133
+ * @deprecated The registry stores option values now. Bind a callback with
134
+ * `apply()` to react to changes instead of holding the value elsewhere.
110
135
  */
111
136
  interface ShkOptionSource<T = unknown> {
112
137
  value: Signal<T>;
@@ -119,6 +144,16 @@ interface ShkOptionSource<T = unknown> {
119
144
  * Components read options as signals, so changing one at runtime updates every
120
145
  * component that uses it. A settings screen can list them with `options()`.
121
146
  *
147
+ * Values live in layers, read in this order:
148
+ *
149
+ * 1. `draft` — the preview an admin screen is editing (`ShkConfigSync.preview()`).
150
+ * 2. `device` — the user's own choice (localStorage, `withPersistence()`).
151
+ * 3. `shared` — the system-wide value (`withSharedConfig()`, usually the backend).
152
+ * 4. the option's `default`.
153
+ *
154
+ * `set()` writes to the draft while a preview is active, otherwise to the
155
+ * option's `scope` (`device` by default).
156
+ *
122
157
  * ```ts
123
158
  * const config = inject(ShkConfigService);
124
159
  * config.get('dates.format')(); // 'dd/MM/yyyy'
@@ -129,16 +164,31 @@ interface ShkOptionSource<T = unknown> {
129
164
  export declare class ShkConfigService {
130
165
  private readonly win;
131
166
  private readonly persistence;
167
+ private readonly labels;
132
168
  /** Registered definitions, by key. */
133
169
  private readonly defs;
134
- /** Values set explicitly (anything else falls back to the definition's default). */
135
- private readonly values;
136
- /** Options whose value lives elsewhere. */
170
+ /** Values set explicitly on this device (persisted by `withPersistence()`). */
171
+ private readonly deviceValues;
172
+ /** Values coming from the shared layer (`withSharedConfig()`). */
173
+ private readonly sharedValues;
174
+ /** Values of the preview being edited (`null` when no preview is active). */
175
+ private readonly draftValues;
176
+ /** Options whose value lives elsewhere (legacy `bind`). */
137
177
  private readonly sources;
178
+ /** Callbacks registered with `apply()`, run on every value change. */
179
+ private readonly appliers;
138
180
  /** Stored values whose option is not registered yet; applied on `register`. */
139
181
  private pending;
140
182
  /** Cached per-key signals returned by `get`. */
141
183
  private readonly cache;
184
+ /** Values set on this device, by key. */
185
+ readonly device: Signal<Readonly<Record<string, unknown>>>;
186
+ /** Values of the shared layer, by key. */
187
+ readonly shared: Signal<Readonly<Record<string, unknown>>>;
188
+ /** Values of the preview being edited, or `null`. */
189
+ readonly draft: Signal<Readonly<Record<string, unknown>> | null>;
190
+ /** `true` while an admin screen is previewing changes. */
191
+ readonly isPreviewing: Signal<boolean>;
142
192
  /** Every registered option with its current value, in registration order. */
143
193
  readonly options: Signal<ShkOptionEntry[]>;
144
194
  /** Module names in registration order (`dates`, `numbers`, `theme`, …). */
@@ -155,9 +205,12 @@ export declare class ShkConfigService {
155
205
  /**
156
206
  * Sets an option. The value is validated against the definition (type,
157
207
  * choices, bounds); an invalid value throws and changes nothing.
208
+ *
209
+ * While a preview is active it is written to the draft; otherwise to
210
+ * `layer`, or to the option's `scope` (`device` by default).
158
211
  */
159
- set<K extends ShkConfigKey>(key: K, value: ShkConfigValues[K]): void;
160
- set(key: string, value: unknown): void;
212
+ set<K extends ShkConfigKey>(key: K, value: ShkConfigValues[K], layer?: ShkConfigLayer): void;
213
+ set(key: string, value: unknown, layer?: ShkConfigLayer): void;
161
214
  /** Restores one option (or all of them) to its default. */
162
215
  reset(key?: string): void;
163
216
  /**
@@ -166,13 +219,35 @@ export declare class ShkConfigService {
166
219
  */
167
220
  register(defs: readonly ShkOptionDef[]): void;
168
221
  /**
169
- * Binds an option to a value held elsewhere (used by `withTheme()` to share
170
- * `theme.name`/`theme.scheme` with `ShkThemeService`).
222
+ * Binds an option to a value held elsewhere.
223
+ *
224
+ * @deprecated The registry owns option values now. Use `apply()` to react to
225
+ * changes (`theme.*` uses it) and let the layers store the value.
171
226
  */
172
227
  bind<T>(key: string, source: ShkOptionSource<T>): void;
228
+ /**
229
+ * Runs `callback` with the option's current value and again on every change
230
+ * (any layer, including the preview). Used by `withTheme()` to apply
231
+ * `theme.name`/`theme.scheme`/`theme.primary`/`theme.surface` to the DOM.
232
+ */
233
+ apply(key: string, callback: (value: unknown) => void): void;
234
+ /**
235
+ * Replaces the shared layer with values loaded from a store. Invalid or
236
+ * unknown keys are ignored, so a store from a newer build cannot break the
237
+ * app.
238
+ */
239
+ setShared(values: Readonly<Record<string, unknown>>): void;
240
+ /** Starts (or restarts) a preview: an empty draft on top of the current values. */
241
+ beginDraft(): void;
242
+ /** Moves the preview values to the shared layer and closes the preview. */
243
+ commitDraft(): void;
244
+ /** Throws away the preview, keeping the previous values. */
245
+ discardDraft(): void;
173
246
  /** Changes the defaults of registered options (`reset` returns to these). */
174
247
  private setDefaults;
175
248
  private read;
249
+ /** Layer the current value comes from (for settings screens). */
250
+ private sourceOf;
176
251
  private requireDef;
177
252
  /** Returns the value coerced to the option's type, or throws if it is not acceptable. */
178
253
  private validate;
@@ -181,6 +256,81 @@ export declare class ShkConfigService {
181
256
  static ɵfac: i0.ɵɵFactoryDeclaration<ShkConfigService, never>;
182
257
  static ɵprov: i0.ɵɵInjectableDeclaration<any>;
183
258
  }
259
+ /** Values and revision returned by a {@link ShkConfigStore}. */
260
+ interface ShkConfigSnapshot {
261
+ /** Stored values, by option key. Keys equal to the default may be omitted. */
262
+ values: Readonly<Record<string, unknown>>;
263
+ /** Opaque revision of `values`; sent back on `save` to detect lost updates. */
264
+ revision: string;
265
+ }
266
+ /**
267
+ * Persistence of the shared layer (usually the backend).
268
+ *
269
+ * The library never talks to the network: the app implements this and passes
270
+ * it to `withSharedConfig()`. `save` must fail with
271
+ * {@link ShkConfigConflictError} when `revision` is not the current one.
272
+ */
273
+ interface ShkConfigStore {
274
+ load(): Promise<ShkConfigSnapshot>;
275
+ save(values: Readonly<Record<string, unknown>>, revision: string | null): Promise<ShkConfigSnapshot>;
276
+ }
277
+ /** The app's {@link ShkConfigStore}, enabled with `withSharedConfig()`. */
278
+ export declare const SHK_CONFIG_STORE: InjectionToken<ShkConfigStore>;
279
+ /** The shared values changed on the server since they were loaded. */
280
+ export declare class ShkConfigConflictError extends Error {
281
+ readonly expected: string | null;
282
+ readonly actual: string | null;
283
+ constructor(expected: string | null, actual: string | null);
284
+ }
285
+ /** State of a {@link ShkConfigSync} operation. */
286
+ type ShkConfigSyncStatus = 'idle' | 'loading' | 'saving' | 'error';
287
+ /**
288
+ * Loads, previews and saves the shared layer.
289
+ *
290
+ * ```ts
291
+ * const sync = inject(ShkConfigSync);
292
+ * await sync.load(); // shared values from the backend
293
+ * sync.preview(); // the admin screen now edits a draft
294
+ * sync.isDirty(); // true once something changed
295
+ * await sync.save(); // draft → shared (backend)
296
+ * sync.discard(); // throw the draft away
297
+ * ```
298
+ *
299
+ * While a preview is active, every `ShkConfigService.set()` goes to the draft,
300
+ * so the same settings screen (and the same `shk-theme-picker`) works for both
301
+ * the user and the admin without knowing about layers.
302
+ */
303
+ export declare class ShkConfigSync {
304
+ private readonly config;
305
+ private readonly store;
306
+ /** Whether a store is configured (`withSharedConfig()`). */
307
+ readonly available: boolean;
308
+ readonly status: import("@angular/core").WritableSignal<ShkConfigSyncStatus>;
309
+ /** Revision of the loaded values; `null` until the first load. */
310
+ readonly revision: import("@angular/core").WritableSignal<string | null>;
311
+ /** Last error (conflict, network…), or `null`. */
312
+ readonly error: import("@angular/core").WritableSignal<unknown>;
313
+ /** True when the draft differs from the shared values. */
314
+ readonly isDirty: import("@angular/core").Signal<boolean>;
315
+ /** Reads the shared layer from the store. */
316
+ load(): Promise<void>;
317
+ /** Starts editing a draft of the shared layer (live preview). */
318
+ preview(): void;
319
+ /** Saves the draft to the store and makes it the shared layer. */
320
+ save(): Promise<void>;
321
+ /** Throws the draft away and keeps the current shared values. */
322
+ discard(): void;
323
+ static ɵfac: i0.ɵɵFactoryDeclaration<ShkConfigSync, never>;
324
+ static ɵprov: i0.ɵɵInjectableDeclaration<any>;
325
+ }
326
+ /**
327
+ * Revision of a set of values: `sha256(canonical_json(values))`, first 16 hex
328
+ * characters. Key order does not matter, so equal values give equal revisions.
329
+ *
330
+ * Used by stores that keep the values locally; a backend can compute the same
331
+ * string to reject lost updates.
332
+ */
333
+ export declare function configRevision(values: Readonly<Record<string, unknown>>): Promise<string>;
184
334
  /**
185
335
  * Shirkasoft UI Components.
186
336
  * Authors: Roberto Valladares Martin (Ansem13), Julio César García García (Sanjuli14).
@@ -188,34 +338,58 @@ export declare class ShkConfigService {
188
338
  *
189
339
  * Builds the `--shk-primary-*` scale from a single color with CSS `color-mix()`,
190
340
  * so the browser derives every shade and no color math ships in JavaScript.
341
+ *
342
+ * A theme pack is plain data (`vars` + `darkVars`), not a CSS file: the
343
+ * stylesheet is generated at runtime, so `theme.name` works in any build
344
+ * without importing `themes/*.css`. The published CSS files are still shipped
345
+ * for apps that prefer a static import.
191
346
  */
192
- /** A theme registered with `withTheme({ themes })`. */
347
+ /** A theme pack: a primary color, an optional surface palette and overrides. */
193
348
  interface ShkCustomTheme {
194
349
  /** Main brand color (hex). It becomes `--shk-primary-600`, the shade buttons use. */
195
350
  primary: string;
196
351
  /** Name shown in settings screens. Defaults to the theme key. */
197
352
  label?: string;
198
- /** Extra CSS custom properties for the theme, e.g. `{ '--shk-surface-50': '#f8fafc' }`. */
353
+ /** Translation key for `label`; `label` is the English fallback. */
354
+ labelKey?: string;
355
+ /** Neutral palette (`slate`, `gray`, `zinc`, `neutral`, `stone`). */
356
+ surface?: string;
357
+ /** Light-mode custom properties, e.g. `{ '--shk-surface-50': '#f8fafc' }`. */
199
358
  vars?: Readonly<Record<`--shk-${string}`, string>>;
359
+ /** Dark-mode custom properties. Merged over the generated dark primary scale. */
360
+ darkVars?: Readonly<Record<`--shk-${string}`, string>>;
200
361
  }
362
+ /** Custom properties a primary color controls (the scale + the decorative accent). */
363
+ export declare const PRIMARY_VARS: readonly string[];
364
+ /** Primary color of the default theme (matches `tokens.css`). */
365
+ export declare const DEFAULT_PRIMARY = "#059669";
201
366
  /** `--shk-primary-50` … `--shk-primary-950` (and the accent vars) derived from one color. */
202
367
  export declare function primaryScale(color: string): Record<string, string>;
368
+ /**
369
+ * Dark-mode counterpart of {@link primaryScale}. Same variable names, shades
370
+ * chosen for dark backgrounds: 50–200 are dark tints, 300–500 light accents,
371
+ * 600 keeps the brand color and 700 is the light hover/text tone.
372
+ */
373
+ export declare function primaryScaleDark(color: string): Record<string, string>;
203
374
  /** Neutral palettes for `theme.surface` (Tailwind scales, 50 … 900). */
204
375
  export declare const SURFACE_PALETTES: Readonly<Record<string, {
205
376
  label: string;
206
377
  scale: readonly string[];
207
378
  }>>;
208
379
  /** A selectable combination shown as a preset: a theme pack and its colors. */
209
- interface ShkThemePreset {
380
+ interface ShkThemePreset extends ShkCustomTheme {
210
381
  /** Theme name (`theme.name`). */
211
382
  name: string;
383
+ /** English label (fallback when there is no translation). */
212
384
  label: string;
385
+ /** Translation key of the label. */
386
+ labelKey: string;
213
387
  /** Its primary color (`--shk-primary-600`). */
214
388
  primary: string;
215
389
  /** Its surface palette (a `SURFACE_PALETTES` key), or '' when it has its own. */
216
390
  surface: string;
217
391
  }
218
- /** The built-in theme packs as presets. */
392
+ /** Built-in theme packs, as data. `default` is the `tokens.css` palette. */
219
393
  export declare const BUILT_IN_PRESETS: readonly ShkThemePreset[];
220
394
  /**
221
395
  * Theme packs offered as presets (built-in + `withTheme({ themes })`), with the
@@ -243,6 +417,9 @@ interface ShkFeature {
243
417
  * ],
244
418
  * });
245
419
  * ```
420
+ *
421
+ * Options persist in localStorage by default; add `withPersistence()` to use a
422
+ * different key.
246
423
  */
247
424
  export declare function provideShk(...features: ShkFeature[]): EnvironmentProviders;
248
425
  /** App defaults for the date options (`dates.*`). */
@@ -275,24 +452,73 @@ interface ShkThemeModuleConfig extends ShkThemeConfig {
275
452
  primary?: string;
276
453
  /** Neutral palette applied on top of any theme (`theme.surface`). Empty = none. */
277
454
  surface?: string;
455
+ /**
456
+ * Layer `theme.*` writes to outside a preview. Defaults to `device`: the
457
+ * picker is the user's own preference and the admin screen edits a draft.
458
+ */
459
+ scope?: ShkConfigLayer;
278
460
  }
279
461
  /**
280
462
  * Theme module: built-in and custom themes, light/dark/system scheme and a
281
463
  * runtime primary color. Replaces `provideShkTheme()` (do not use both).
282
464
  *
283
- * `theme.name` and `theme.scheme` are shared with `ShkThemeService` (which
284
- * persists them); `theme.primary` is stored by `withPersistence()`.
465
+ * Theme packs are data (`vars` + `darkVars`), so `theme.name` works without
466
+ * importing `themes/*.css` and every pack has a dark variant.
285
467
  */
286
468
  export declare function withTheme(config?: ShkThemeModuleConfig): ShkFeature;
287
469
  /** Registers app-defined options in the same registry (`app.pageSize`, …). */
288
470
  export declare function withOptions(options: readonly ShkOptionDef[]): ShkFeature;
289
471
  /**
290
472
  * Persists changed options in localStorage so they survive reloads.
291
- * Options with `persist: false` are skipped (the theme service stores its own).
473
+ * Options with `persist: false` are skipped.
292
474
  */
293
475
  export declare function withPersistence(config?: {
294
476
  storageKey?: string;
295
477
  }): ShkFeature;
478
+ /**
479
+ * Enables the shared layer: the system-wide values an admin screen edits.
480
+ *
481
+ * ```ts
482
+ * provideShk(withSharedConfig({ provide: SHK_CONFIG_STORE, useClass: ApiConfigStore }))
483
+ * ```
484
+ */
485
+ export declare function withSharedConfig(store: ShkConfigStore | Provider): ShkFeature;
486
+ /**
487
+ * Explicit label translations for the library's own texts (theme names, option
488
+ * labels…). Transloco is used automatically when it is configured; this is for
489
+ * apps that use another i18n system. Untranslated labels fall back to English.
490
+ *
491
+ * ```ts
492
+ * withLabels({ 'theme.presets.ocean': 'Océano', 'theme.options.name': 'Tema' })
493
+ * ```
494
+ */
495
+ export declare function withLabels(labels: Readonly<Record<string, string>>): ShkFeature;
496
+ /**
497
+ * Labels the library shows for its own options and theme packs.
498
+ *
499
+ * Every definition carries an English fallback, so a translated label is
500
+ * optional: when there is no translation the English one is used.
501
+ */
502
+ export declare class ShkLabels {
503
+ /** Explicit translations registered with `withLabels()`. */
504
+ private readonly overrides;
505
+ /** Transloco is optional: without it only the overrides and fallbacks apply. */
506
+ private readonly transloco;
507
+ /** Bumped on every language change so signals reading `get()` recompute. */
508
+ private readonly revision;
509
+ constructor();
510
+ /**
511
+ * Translation of `key`, or `fallback` when there is none. Reads the language
512
+ * signal, so it can be used inside `computed`.
513
+ */
514
+ get(key: string | undefined, fallback: string): string;
515
+ /** Transloco is an optional peer: a missing provider must not break the app. */
516
+ private injectTransloco;
517
+ static ɵfac: i0.ɵɵFactoryDeclaration<ShkLabels, never>;
518
+ static ɵprov: i0.ɵɵInjectableDeclaration<any>;
519
+ }
520
+ /** Explicit label translations (`withLabels()`), keyed by translation key. */
521
+ export declare const SHK_LABEL_OVERRIDES: InjectionToken<Readonly<Record<string, string>>>;
296
522
  /** Date options (`dates.*`), always registered. */
297
523
  export declare const DATE_OPTIONS: readonly ShkOptionDef[];
298
524
  /** Number and currency options (`numbers.*`), always registered. */
@@ -354,4 +580,4 @@ export declare function numberSeparators(locale: string): {
354
580
  decimal: string;
355
581
  group: string;
356
582
  };
357
- export type { ShkConfigFeature, ShkConfigKey, ShkConfigPersistence, ShkConfigValues, ShkCustomTheme, ShkDateDisplayStyle, ShkDatesConfig, ShkFeature, ShkIntlStyle, ShkNumbersConfig, ShkOptionChoice, ShkOptionDef, ShkOptionEntry, ShkOptionSource, ShkOptionType, ShkThemeModuleConfig, ShkThemePreset, TypedDateLayout };
583
+ export type { ShkConfigFeature, ShkConfigKey, ShkConfigLayer, ShkConfigPersistence, ShkConfigSnapshot, ShkConfigSource, ShkConfigStore, ShkConfigSyncStatus, ShkConfigValues, ShkCustomTheme, ShkDateDisplayStyle, ShkDatesConfig, ShkFeature, ShkIntlStyle, ShkNumbersConfig, ShkOptionChoice, ShkOptionDef, ShkOptionEntry, ShkOptionSource, ShkOptionType, ShkThemeModuleConfig, ShkThemePreset, TypedDateLayout };