shirkasoft-ui-components 1.14.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/README.md +12 -9
  2. package/fesm2022/shirkasoft-ui-components-breadcrumb.mjs +189 -100
  3. package/fesm2022/shirkasoft-ui-components-breadcrumb.mjs.map +1 -1
  4. package/fesm2022/shirkasoft-ui-components-button.mjs +363 -69
  5. package/fesm2022/shirkasoft-ui-components-button.mjs.map +1 -1
  6. package/fesm2022/shirkasoft-ui-components-chart.mjs +206 -142
  7. package/fesm2022/shirkasoft-ui-components-chart.mjs.map +1 -1
  8. package/fesm2022/shirkasoft-ui-components-config.mjs +905 -843
  9. package/fesm2022/shirkasoft-ui-components-config.mjs.map +1 -1
  10. package/fesm2022/shirkasoft-ui-components-confirm-dialog.mjs +307 -142
  11. package/fesm2022/shirkasoft-ui-components-confirm-dialog.mjs.map +1 -1
  12. package/fesm2022/shirkasoft-ui-components-date-picker.mjs +1697 -1440
  13. package/fesm2022/shirkasoft-ui-components-date-picker.mjs.map +1 -1
  14. package/fesm2022/shirkasoft-ui-components-fieldset.mjs +347 -92
  15. package/fesm2022/shirkasoft-ui-components-fieldset.mjs.map +1 -1
  16. package/fesm2022/shirkasoft-ui-components-file-upload.mjs +555 -300
  17. package/fesm2022/shirkasoft-ui-components-file-upload.mjs.map +1 -1
  18. package/fesm2022/shirkasoft-ui-components-icons.mjs +1028 -533
  19. package/fesm2022/shirkasoft-ui-components-icons.mjs.map +1 -1
  20. package/fesm2022/shirkasoft-ui-components-knob.mjs +389 -201
  21. package/fesm2022/shirkasoft-ui-components-knob.mjs.map +1 -1
  22. package/fesm2022/shirkasoft-ui-components-loading.mjs +505 -128
  23. package/fesm2022/shirkasoft-ui-components-loading.mjs.map +1 -1
  24. package/fesm2022/shirkasoft-ui-components-modal.mjs +311 -314
  25. package/fesm2022/shirkasoft-ui-components-modal.mjs.map +1 -1
  26. package/fesm2022/shirkasoft-ui-components-notification.mjs +188 -142
  27. package/fesm2022/shirkasoft-ui-components-notification.mjs.map +1 -1
  28. package/fesm2022/shirkasoft-ui-components-price-input.mjs +585 -327
  29. package/fesm2022/shirkasoft-ui-components-price-input.mjs.map +1 -1
  30. package/fesm2022/shirkasoft-ui-components-rail-sidebar.mjs +669 -289
  31. package/fesm2022/shirkasoft-ui-components-rail-sidebar.mjs.map +1 -1
  32. package/fesm2022/shirkasoft-ui-components-select.mjs +1076 -819
  33. package/fesm2022/shirkasoft-ui-components-select.mjs.map +1 -1
  34. package/fesm2022/shirkasoft-ui-components-sidebar.mjs +508 -184
  35. package/fesm2022/shirkasoft-ui-components-sidebar.mjs.map +1 -1
  36. package/fesm2022/shirkasoft-ui-components-skeleton.mjs +197 -57
  37. package/fesm2022/shirkasoft-ui-components-skeleton.mjs.map +1 -1
  38. package/fesm2022/shirkasoft-ui-components-table.mjs +1916 -1698
  39. package/fesm2022/shirkasoft-ui-components-table.mjs.map +1 -1
  40. package/fesm2022/shirkasoft-ui-components-tabs.mjs +419 -175
  41. package/fesm2022/shirkasoft-ui-components-tabs.mjs.map +1 -1
  42. package/fesm2022/shirkasoft-ui-components-tag.mjs +175 -49
  43. package/fesm2022/shirkasoft-ui-components-tag.mjs.map +1 -1
  44. package/fesm2022/shirkasoft-ui-components-text-field.mjs +749 -402
  45. package/fesm2022/shirkasoft-ui-components-text-field.mjs.map +1 -1
  46. package/fesm2022/shirkasoft-ui-components-theme-picker.mjs +310 -124
  47. package/fesm2022/shirkasoft-ui-components-theme-picker.mjs.map +1 -1
  48. package/fesm2022/shirkasoft-ui-components-theme.mjs +141 -174
  49. package/fesm2022/shirkasoft-ui-components-theme.mjs.map +1 -1
  50. package/fesm2022/shirkasoft-ui-components-timeline.mjs +791 -203
  51. package/fesm2022/shirkasoft-ui-components-timeline.mjs.map +1 -1
  52. package/fesm2022/shirkasoft-ui-components-toggle.mjs +179 -109
  53. package/fesm2022/shirkasoft-ui-components-toggle.mjs.map +1 -1
  54. package/fesm2022/shirkasoft-ui-components-tooltip.mjs +244 -180
  55. package/fesm2022/shirkasoft-ui-components-tooltip.mjs.map +1 -1
  56. package/fesm2022/shirkasoft-ui-components-utils.mjs +129 -133
  57. package/fesm2022/shirkasoft-ui-components-utils.mjs.map +1 -1
  58. package/fesm2022/shirkasoft-ui-components-wizard.mjs +673 -165
  59. package/fesm2022/shirkasoft-ui-components-wizard.mjs.map +1 -1
  60. package/fesm2022/shirkasoft-ui-components.mjs +0 -9
  61. package/package.json +5 -5
  62. package/types/shirkasoft-ui-components-breadcrumb.d.ts +59 -44
  63. package/types/shirkasoft-ui-components-button.d.ts +142 -49
  64. package/types/shirkasoft-ui-components-chart.d.ts +59 -44
  65. package/types/shirkasoft-ui-components-config.d.ts +193 -204
  66. package/types/shirkasoft-ui-components-confirm-dialog.d.ts +107 -66
  67. package/types/shirkasoft-ui-components-date-picker.d.ts +561 -398
  68. package/types/shirkasoft-ui-components-fieldset.d.ts +135 -60
  69. package/types/shirkasoft-ui-components-file-upload.d.ts +210 -112
  70. package/types/shirkasoft-ui-components-icons.d.ts +1302 -1294
  71. package/types/shirkasoft-ui-components-knob.d.ts +144 -78
  72. package/types/shirkasoft-ui-components-loading.d.ts +155 -64
  73. package/types/shirkasoft-ui-components-modal.d.ts +134 -136
  74. package/types/shirkasoft-ui-components-notification.d.ts +63 -59
  75. package/types/shirkasoft-ui-components-price-input.d.ts +232 -113
  76. package/types/shirkasoft-ui-components-rail-sidebar.d.ts +262 -142
  77. package/types/shirkasoft-ui-components-select.d.ts +335 -196
  78. package/types/shirkasoft-ui-components-sidebar.d.ts +198 -93
  79. package/types/shirkasoft-ui-components-skeleton.d.ts +68 -27
  80. package/types/shirkasoft-ui-components-table.d.ts +849 -660
  81. package/types/shirkasoft-ui-components-tabs.d.ts +102 -61
  82. package/types/shirkasoft-ui-components-tag.d.ts +54 -23
  83. package/types/shirkasoft-ui-components-text-field.d.ts +263 -127
  84. package/types/shirkasoft-ui-components-theme-picker.d.ts +92 -58
  85. package/types/shirkasoft-ui-components-theme.d.ts +56 -64
  86. package/types/shirkasoft-ui-components-timeline.d.ts +325 -150
  87. package/types/shirkasoft-ui-components-toggle.d.ts +73 -49
  88. package/types/shirkasoft-ui-components-tooltip.d.ts +64 -43
  89. package/types/shirkasoft-ui-components-utils.d.ts +47 -15
  90. package/types/shirkasoft-ui-components-wizard.d.ts +236 -87
  91. package/types/shirkasoft-ui-components.d.ts +1 -2
  92. package/fesm2022/shirkasoft-ui-components.mjs.map +0 -1
@@ -1,914 +1,976 @@
1
- import { DOCUMENT } from '@angular/common';
2
- import * as i0 from '@angular/core';
3
- import { InjectionToken, inject, signal, computed, effect, untracked, Injectable, makeEnvironmentProviders, provideAppInitializer, CSP_NONCE } from '@angular/core';
4
- import { DEFAULT_SHK_THEME_CONFIG, SHK_THEME_CONFIG, ShkThemeService } from 'shirkasoft-ui-components/theme';
5
-
6
- /** Locales offered by the built-in `select` options (any BCP 47 tag is still accepted via `set`). */
7
- const LOCALE_CHOICES = [
8
- { value: 'es', label: 'Español' },
9
- { value: 'es-ES', label: 'Español (España)' },
10
- { value: 'es-MX', label: 'Español (México)' },
11
- { value: 'en-US', label: 'English (US)' },
12
- { value: 'en-GB', label: 'English (UK)' },
13
- { value: 'pt-BR', label: 'Português (Brasil)' },
14
- { value: 'fr-FR', label: 'Français' },
15
- ];
16
- /** Date options (`dates.*`), always registered. */
1
+ import { DOCUMENT } from "@angular/common";
2
+ import * as i0 from "@angular/core";
3
+ import { CSP_NONCE, Injectable, InjectionToken, computed, effect, inject, makeEnvironmentProviders, provideAppInitializer, signal, untracked } from "@angular/core";
4
+ import { DEFAULT_SHK_THEME_CONFIG, SHK_THEME_CONFIG, ShkThemeService } from "shirkasoft-ui-components/theme";
17
5
  const DATE_OPTIONS = [
18
- {
19
- key: 'dates.locale',
20
- module: 'dates',
21
- type: 'select',
22
- default: 'es',
23
- label: 'Idioma de las fechas',
24
- description: 'Nombres de meses y días del calendario.',
25
- choices: LOCALE_CHOICES,
26
- allowCustom: true,
27
- },
28
- {
29
- key: 'dates.format',
30
- module: 'dates',
31
- type: 'select',
32
- default: '',
33
- label: 'Formato de fecha',
34
- description: 'Cómo se escriben y muestran las fechas en campos y tablas.',
35
- allowCustom: true,
36
- choices: [
37
- { value: '', label: 'Automático según el idioma' },
38
- { value: 'dd/MM/yyyy', label: '31/12/2026' },
39
- { value: 'MM/dd/yyyy', label: '12/31/2026' },
40
- { value: 'yyyy-MM-dd', label: '2026-12-31' },
41
- { value: 'dd-MM-yyyy', label: '31-12-2026' },
42
- { value: 'dd.MM.yyyy', label: '31.12.2026' },
43
- { value: 'd MMM yyyy', label: '31 dic 2026' },
44
- ],
45
- },
46
- {
47
- key: 'dates.displayStyle',
48
- module: 'dates',
49
- type: 'select',
50
- default: 'long',
51
- label: 'Fecha seleccionada',
52
- description: 'Cómo muestra el selector de fecha el valor elegido.',
53
- choices: [
54
- { value: 'long', label: 'Larga (31 de diciembre de 2026)' },
55
- { value: 'medium', label: 'Media (31 dic 2026)' },
56
- { value: 'short', label: 'Corta (31/12/26)' },
57
- { value: 'format', label: 'Con el formato de fecha' },
58
- ],
59
- },
60
- {
61
- key: 'dates.hourFormat',
62
- module: 'dates',
63
- type: 'select',
64
- default: '24',
65
- label: 'Formato de hora',
66
- choices: [
67
- { value: '24', label: '24 horas (14:30)' },
68
- { value: '12', label: '12 horas (02:30 PM)' },
69
- ],
70
- },
71
- {
72
- key: 'dates.weekStart',
73
- module: 'dates',
74
- type: 'select',
75
- default: null,
76
- label: 'Primer día de la semana',
77
- choices: [
78
- { value: null, label: 'Según el idioma' },
79
- { value: 1, label: 'Lunes' },
80
- { value: 0, label: 'Domingo' },
81
- { value: 6, label: 'Sábado' },
82
- ],
83
- },
6
+ {
7
+ key: "dates.locale",
8
+ module: "dates",
9
+ type: "select",
10
+ default: "es",
11
+ label: "Idioma de las fechas",
12
+ description: "Nombres de meses y días del calendario.",
13
+ choices: [
14
+ {
15
+ value: "es",
16
+ label: "Español"
17
+ },
18
+ {
19
+ value: "es-ES",
20
+ label: "Español (España)"
21
+ },
22
+ {
23
+ value: "es-MX",
24
+ label: "Español (México)"
25
+ },
26
+ {
27
+ value: "en-US",
28
+ label: "English (US)"
29
+ },
30
+ {
31
+ value: "en-GB",
32
+ label: "English (UK)"
33
+ },
34
+ {
35
+ value: "pt-BR",
36
+ label: "Português (Brasil)"
37
+ },
38
+ {
39
+ value: "fr-FR",
40
+ label: "Français"
41
+ }
42
+ ],
43
+ allowCustom: true
44
+ },
45
+ {
46
+ key: "dates.format",
47
+ module: "dates",
48
+ type: "select",
49
+ default: "",
50
+ label: "Formato de fecha",
51
+ description: "Cómo se escriben y muestran las fechas en campos y tablas.",
52
+ allowCustom: true,
53
+ choices: [
54
+ {
55
+ value: "",
56
+ label: "Automático según el idioma"
57
+ },
58
+ {
59
+ value: "dd/MM/yyyy",
60
+ label: "31/12/2026"
61
+ },
62
+ {
63
+ value: "MM/dd/yyyy",
64
+ label: "12/31/2026"
65
+ },
66
+ {
67
+ value: "yyyy-MM-dd",
68
+ label: "2026-12-31"
69
+ },
70
+ {
71
+ value: "dd-MM-yyyy",
72
+ label: "31-12-2026"
73
+ },
74
+ {
75
+ value: "dd.MM.yyyy",
76
+ label: "31.12.2026"
77
+ },
78
+ {
79
+ value: "d MMM yyyy",
80
+ label: "31 dic 2026"
81
+ }
82
+ ]
83
+ },
84
+ {
85
+ key: "dates.displayStyle",
86
+ module: "dates",
87
+ type: "select",
88
+ default: "long",
89
+ label: "Fecha seleccionada",
90
+ description: "Cómo muestra el selector de fecha el valor elegido.",
91
+ choices: [
92
+ {
93
+ value: "long",
94
+ label: "Larga (31 de diciembre de 2026)"
95
+ },
96
+ {
97
+ value: "medium",
98
+ label: "Media (31 dic 2026)"
99
+ },
100
+ {
101
+ value: "short",
102
+ label: "Corta (31/12/26)"
103
+ },
104
+ {
105
+ value: "format",
106
+ label: "Con el formato de fecha"
107
+ }
108
+ ]
109
+ },
110
+ {
111
+ key: "dates.hourFormat",
112
+ module: "dates",
113
+ type: "select",
114
+ default: "24",
115
+ label: "Formato de hora",
116
+ choices: [{
117
+ value: "24",
118
+ label: "24 horas (14:30)"
119
+ }, {
120
+ value: "12",
121
+ label: "12 horas (02:30 PM)"
122
+ }]
123
+ },
124
+ {
125
+ key: "dates.weekStart",
126
+ module: "dates",
127
+ type: "select",
128
+ default: null,
129
+ label: "Primer día de la semana",
130
+ choices: [
131
+ {
132
+ value: null,
133
+ label: "Según el idioma"
134
+ },
135
+ {
136
+ value: 1,
137
+ label: "Lunes"
138
+ },
139
+ {
140
+ value: 0,
141
+ label: "Domingo"
142
+ },
143
+ {
144
+ value: 6,
145
+ label: "Sábado"
146
+ }
147
+ ]
148
+ }
84
149
  ];
85
- /** Number and currency options (`numbers.*`), always registered. */
86
150
  const NUMBER_OPTIONS = [
87
- {
88
- key: 'numbers.locale',
89
- module: 'numbers',
90
- type: 'select',
91
- default: 'en-US',
92
- label: 'Formato de números',
93
- description: 'Separadores de miles y decimales (1,234.56 o 1.234,56).',
94
- allowCustom: true,
95
- choices: [
96
- { value: 'en-US', label: '1,234.56' },
97
- { value: 'es-ES', label: '1.234,56' },
98
- { value: 'fr-FR', label: '1 234,56' },
99
- { value: 'de-CH', label: "1'234.56" },
100
- ],
101
- },
102
- {
103
- key: 'numbers.currency',
104
- module: 'numbers',
105
- type: 'select',
106
- default: 'USD',
107
- label: 'Moneda',
108
- description: 'Moneda por defecto de importes y columnas de moneda.',
109
- allowCustom: true,
110
- choices: [
111
- { value: 'USD', label: 'Dólar estadounidense (USD)' },
112
- { value: 'EUR', label: 'Euro (EUR)' },
113
- { value: 'CUP', label: 'Peso cubano (CUP)' },
114
- { value: 'MXN', label: 'Peso mexicano (MXN)' },
115
- { value: 'GBP', label: 'Libra esterlina (GBP)' },
116
- { value: 'BRL', label: 'Real brasileño (BRL)' },
117
- ],
118
- },
119
- {
120
- key: 'numbers.currencySymbol',
121
- module: 'numbers',
122
- type: 'string',
123
- default: '',
124
- label: 'Símbolo de moneda',
125
- description: 'Vacío = el de la moneda ($, €…).',
126
- },
127
- {
128
- key: 'numbers.decimals',
129
- module: 'numbers',
130
- type: 'select',
131
- default: null,
132
- label: 'Decimales',
133
- description: 'Decimales de los importes.',
134
- choices: [
135
- { value: null, label: 'Según la moneda (USD 2, JPY 0)' },
136
- { value: 0, label: '0' },
137
- { value: 1, label: '1' },
138
- { value: 2, label: '2' },
139
- { value: 3, label: '3' },
140
- { value: 4, label: '4' },
141
- ],
142
- },
151
+ {
152
+ key: "numbers.locale",
153
+ module: "numbers",
154
+ type: "select",
155
+ default: "en-US",
156
+ label: "Formato de números",
157
+ description: "Separadores de miles y decimales (1,234.56 o 1.234,56).",
158
+ allowCustom: true,
159
+ choices: [
160
+ {
161
+ value: "en-US",
162
+ label: "1,234.56"
163
+ },
164
+ {
165
+ value: "es-ES",
166
+ label: "1.234,56"
167
+ },
168
+ {
169
+ value: "fr-FR",
170
+ label: "1 234,56"
171
+ },
172
+ {
173
+ value: "de-CH",
174
+ label: "1'234.56"
175
+ }
176
+ ]
177
+ },
178
+ {
179
+ key: "numbers.currency",
180
+ module: "numbers",
181
+ type: "select",
182
+ default: "USD",
183
+ label: "Moneda",
184
+ description: "Moneda por defecto de importes y columnas de moneda.",
185
+ allowCustom: true,
186
+ choices: [
187
+ {
188
+ value: "USD",
189
+ label: "Dólar estadounidense (USD)"
190
+ },
191
+ {
192
+ value: "EUR",
193
+ label: "Euro (EUR)"
194
+ },
195
+ {
196
+ value: "CUP",
197
+ label: "Peso cubano (CUP)"
198
+ },
199
+ {
200
+ value: "MXN",
201
+ label: "Peso mexicano (MXN)"
202
+ },
203
+ {
204
+ value: "GBP",
205
+ label: "Libra esterlina (GBP)"
206
+ },
207
+ {
208
+ value: "BRL",
209
+ label: "Real brasileño (BRL)"
210
+ }
211
+ ]
212
+ },
213
+ {
214
+ key: "numbers.currencySymbol",
215
+ module: "numbers",
216
+ type: "string",
217
+ default: "",
218
+ label: "Símbolo de moneda",
219
+ description: "Vacío = el de la moneda ($, €…)."
220
+ },
221
+ {
222
+ key: "numbers.decimals",
223
+ module: "numbers",
224
+ type: "select",
225
+ default: null,
226
+ label: "Decimales",
227
+ description: "Decimales de los importes.",
228
+ choices: [
229
+ {
230
+ value: null,
231
+ label: "Según la moneda (USD 2, JPY 0)"
232
+ },
233
+ {
234
+ value: 0,
235
+ label: "0"
236
+ },
237
+ {
238
+ value: 1,
239
+ label: "1"
240
+ },
241
+ {
242
+ value: 2,
243
+ label: "2"
244
+ },
245
+ {
246
+ value: 3,
247
+ label: "3"
248
+ },
249
+ {
250
+ value: 4,
251
+ label: "4"
252
+ }
253
+ ]
254
+ }
143
255
  ];
144
-
145
- /**
146
- * Shirkasoft UI Components.
147
- * Authors: Roberto Valladares Martin (Ansem13), Julio César García García (Sanjuli14).
148
- * Belongs to Shirkasoft.
149
- */
150
- /** Features collected from `provideShk(...)`. */
151
- const SHK_CONFIG_FEATURES = new InjectionToken('SHK_CONFIG_FEATURES');
152
- const SHK_CONFIG_PERSISTENCE = new InjectionToken('SHK_CONFIG_PERSISTENCE');
153
- /**
154
- * Registry of the library's configurable options ("nomenclador" de opciones).
155
- *
156
- * Every option has a key (`dates.format`), a module, a type and a default.
157
- * Components read options as signals, so changing one at runtime updates every
158
- * component that uses it. A settings screen can list them with `options()`.
159
- *
160
- * ```ts
161
- * const config = inject(ShkConfigService);
162
- * config.get('dates.format')(); // 'dd/MM/yyyy'
163
- * config.set('numbers.currency', 'EUR'); // every price input/table updates
164
- * config.options(); // definitions + current values
165
- * ```
166
- */
167
- class ShkConfigService {
168
- constructor() {
169
- this.win = inject(DOCUMENT).defaultView;
170
- this.persistence = inject(SHK_CONFIG_PERSISTENCE, { optional: true });
171
- /** Registered definitions, by key. */
172
- this.defs = signal(new Map(), ...(ngDevMode ? [{ debugName: "defs" }] : /* istanbul ignore next */ []));
173
- /** Values set explicitly (anything else falls back to the definition's default). */
174
- this.values = signal({}, ...(ngDevMode ? [{ debugName: "values" }] : /* istanbul ignore next */ []));
175
- /** Options whose value lives elsewhere. */
176
- this.sources = signal(new Map(), ...(ngDevMode ? [{ debugName: "sources" }] : /* istanbul ignore next */ []));
177
- /** Stored values whose option is not registered yet; applied on `register`. */
178
- this.pending = {};
179
- /** Cached per-key signals returned by `get`. */
180
- this.cache = new Map();
181
- /** Every registered option with its current value, in registration order. */
182
- this.options = computed(() => [...this.defs().values()].map((def) => {
183
- const value = this.read(def.key);
184
- return { ...def, value, isDefault: sameValue(value, def.default) };
185
- }), ...(ngDevMode ? [{ debugName: "options" }] : /* istanbul ignore next */ []));
186
- /** Module names in registration order (`dates`, `numbers`, `theme`, …). */
187
- this.modules = computed(() => [
188
- ...new Set([...this.defs().values()].map((def) => def.module)),
189
- ], ...(ngDevMode ? [{ debugName: "modules" }] : /* istanbul ignore next */ []));
190
- this.pending = this.loadStored();
191
- this.register([...DATE_OPTIONS, ...NUMBER_OPTIONS]);
192
- for (const feature of inject(SHK_CONFIG_FEATURES, { optional: true }) ?? []) {
193
- if (feature.options)
194
- this.register(feature.options);
195
- if (feature.defaults)
196
- this.setDefaults(feature.defaults);
197
- }
198
- if (this.persistence) {
199
- effect(() => this.save(this.values()));
200
- }
201
- }
202
- get(key) {
203
- this.requireDef(key);
204
- let sig = this.cache.get(key);
205
- if (!sig) {
206
- sig = computed(() => this.read(key));
207
- this.cache.set(key, sig);
208
- }
209
- return sig;
210
- }
211
- /** Whether an option is registered (e.g. `theme.*` only exists with `withTheme()`). */
212
- has(key) {
213
- return untracked(this.defs).has(key);
214
- }
215
- value(key) {
216
- return untracked(this.get(key));
217
- }
218
- set(key, value) {
219
- const def = this.requireDef(key);
220
- const valid = this.validate(def, value);
221
- const source = untracked(this.sources).get(key);
222
- if (source) {
223
- source.set(valid);
224
- return;
225
- }
226
- this.values.update((current) => ({ ...current, [key]: valid }));
227
- }
228
- /** Restores one option (or all of them) to its default. */
229
- reset(key) {
230
- const keys = key ? [key] : [...untracked(this.defs).keys()];
231
- for (const k of keys) {
232
- const def = this.requireDef(k);
233
- const source = untracked(this.sources).get(k);
234
- if (source)
235
- source.set(def.default);
236
- }
237
- this.values.update((current) => {
238
- if (!key)
239
- return {};
240
- const { [key]: _removed, ...rest } = current;
241
- return rest;
242
- });
243
- }
244
- /**
245
- * Adds option definitions (or replaces existing ones with the same key).
246
- * Stored values for them are applied if they are still valid.
247
- */
248
- register(defs) {
249
- this.defs.update((current) => {
250
- const next = new Map(current);
251
- for (const def of defs)
252
- next.set(def.key, def);
253
- return next;
254
- });
255
- for (const def of defs) {
256
- if (!(def.key in this.pending))
257
- continue;
258
- const stored = this.pending[def.key];
259
- delete this.pending[def.key];
260
- if (def.persist === false)
261
- continue;
262
- try {
263
- const valid = this.validate(def, stored);
264
- this.values.update((current) => ({ ...current, [def.key]: valid }));
265
- }
266
- catch {
267
- // Stale or hand-edited storage: ignore the value, keep the default.
268
- }
269
- }
270
- }
271
- /**
272
- * Binds an option to a value held elsewhere (used by `withTheme()` to share
273
- * `theme.name`/`theme.scheme` with `ShkThemeService`).
274
- */
275
- bind(key, source) {
276
- this.requireDef(key);
277
- this.sources.update((current) => new Map(current).set(key, source));
278
- }
279
- /** Changes the defaults of registered options (`reset` returns to these). */
280
- setDefaults(defaults) {
281
- const updated = [];
282
- for (const [key, value] of Object.entries(defaults)) {
283
- if (value === undefined)
284
- continue;
285
- const def = this.requireDef(key);
286
- updated.push({ ...def, default: this.validate(def, value) });
287
- }
288
- this.defs.update((current) => {
289
- const next = new Map(current);
290
- for (const def of updated)
291
- next.set(def.key, def);
292
- return next;
293
- });
294
- }
295
- read(key) {
296
- const source = this.sources().get(key);
297
- if (source)
298
- return source.value();
299
- const values = this.values();
300
- return key in values ? values[key] : this.defs().get(key)?.default;
301
- }
302
- requireDef(key) {
303
- const def = untracked(this.defs).get(key);
304
- if (!def) {
305
- throw new Error(`[shk-config] Unknown option "${key}". Register it with withOptions() or ShkConfigService.register().`);
306
- }
307
- return def;
308
- }
309
- /** Returns the value coerced to the option's type, or throws if it is not acceptable. */
310
- validate(def, value) {
311
- const fail = (why) => {
312
- throw new Error(`[shk-config] Invalid value for "${def.key}": ${why}.`);
313
- };
314
- switch (def.type) {
315
- case 'boolean':
316
- if (typeof value !== 'boolean')
317
- fail('expected a boolean');
318
- return value;
319
- case 'number': {
320
- const n = typeof value === 'string' && value.trim() !== '' ? Number(value) : value;
321
- if (typeof n !== 'number' || !isFinite(n))
322
- fail('expected a number');
323
- if (def.min !== undefined && n < def.min)
324
- fail(`minimum is ${def.min}`);
325
- if (def.max !== undefined && n > def.max)
326
- fail(`maximum is ${def.max}`);
327
- return n;
328
- }
329
- case 'color':
330
- if (typeof value !== 'string')
331
- fail('expected a color string');
332
- if (value !== '' && !/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.test(value)) {
333
- fail('expected a hex color such as #2563eb (or empty)');
334
- }
335
- return value;
336
- case 'select': {
337
- const match = def.choices?.find((choice) => sameValue(choice.value, value));
338
- if (match)
339
- return match.value;
340
- if (def.allowCustom && typeof value === 'string' && value.trim() !== '') {
341
- return value.trim();
342
- }
343
- return fail('not one of the allowed choices');
344
- }
345
- default:
346
- if (typeof value !== 'string')
347
- fail('expected a string');
348
- return value;
349
- }
350
- }
351
- loadStored() {
352
- if (!this.persistence)
353
- return {};
354
- try {
355
- const raw = this.win?.localStorage?.getItem(this.persistence.storageKey);
356
- const parsed = raw ? JSON.parse(raw) : null;
357
- return parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : {};
358
- }
359
- catch {
360
- return {};
361
- }
362
- }
363
- save(values) {
364
- if (!this.persistence)
365
- return;
366
- const defs = untracked(this.defs);
367
- // Keep stored values of options that are not registered yet (registered later).
368
- const stored = { ...this.pending };
369
- for (const [key, value] of Object.entries(values)) {
370
- if (defs.get(key)?.persist !== false)
371
- stored[key] = value;
372
- }
373
- try {
374
- this.win?.localStorage?.setItem(this.persistence.storageKey, JSON.stringify(stored));
375
- }
376
- catch {
377
- // Storage can be blocked (private mode, quota); the option still applies.
378
- }
379
- }
380
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.27", ngImport: i0, type: ShkConfigService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
381
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.27", ngImport: i0, type: ShkConfigService, providedIn: 'root' }); }
382
- }
383
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.27", ngImport: i0, type: ShkConfigService, decorators: [{
384
- type: Injectable,
385
- args: [{ providedIn: 'root' }]
386
- }], ctorParameters: () => [] });
387
- /** Value equality for option values (primitives and `null`). */
256
+ const SHK_CONFIG_FEATURES = new InjectionToken("SHK_CONFIG_FEATURES");
257
+ const SHK_CONFIG_PERSISTENCE = new InjectionToken("SHK_CONFIG_PERSISTENCE");
258
+ var ShkConfigService = class ShkConfigService {
259
+ constructor() {
260
+ this.win = inject(DOCUMENT).defaultView;
261
+ this.persistence = inject(SHK_CONFIG_PERSISTENCE, { optional: true });
262
+ this.defs = signal(/* @__PURE__ */ new Map(), ...ngDevMode ? [{ debugName: "defs" }] : /* istanbul ignore next */ []);
263
+ this.values = signal({}, ...ngDevMode ? [{ debugName: "values" }] : /* istanbul ignore next */ []);
264
+ this.sources = signal(/* @__PURE__ */ new Map(), ...ngDevMode ? [{ debugName: "sources" }] : /* istanbul ignore next */ []);
265
+ this.pending = {};
266
+ this.cache = /* @__PURE__ */ new Map();
267
+ this.options = computed(() => [...this.defs().values()].map((def) => {
268
+ const value = this.read(def.key);
269
+ return {
270
+ ...def,
271
+ value,
272
+ isDefault: sameValue(value, def.default)
273
+ };
274
+ }), ...ngDevMode ? [{ debugName: "options" }] : /* istanbul ignore next */ []);
275
+ this.modules = computed(() => [...new Set([...this.defs().values()].map((def) => def.module))], ...ngDevMode ? [{ debugName: "modules" }] : /* istanbul ignore next */ []);
276
+ this.pending = this.loadStored();
277
+ this.register([...DATE_OPTIONS, ...NUMBER_OPTIONS]);
278
+ for (const feature of inject(SHK_CONFIG_FEATURES, { optional: true }) ?? []) {
279
+ if (feature.options) this.register(feature.options);
280
+ if (feature.defaults) this.setDefaults(feature.defaults);
281
+ }
282
+ if (this.persistence) effect(() => this.save(this.values()));
283
+ }
284
+ get(key) {
285
+ this.requireDef(key);
286
+ let sig = this.cache.get(key);
287
+ if (!sig) {
288
+ sig = computed(() => this.read(key));
289
+ this.cache.set(key, sig);
290
+ }
291
+ return sig;
292
+ }
293
+ has(key) {
294
+ return untracked(this.defs).has(key);
295
+ }
296
+ value(key) {
297
+ return untracked(this.get(key));
298
+ }
299
+ set(key, value) {
300
+ const def = this.requireDef(key);
301
+ const valid = this.validate(def, value);
302
+ const source = untracked(this.sources).get(key);
303
+ if (source) {
304
+ source.set(valid);
305
+ return;
306
+ }
307
+ this.values.update((current) => ({
308
+ ...current,
309
+ [key]: valid
310
+ }));
311
+ }
312
+ reset(key) {
313
+ const keys = key ? [key] : [...untracked(this.defs).keys()];
314
+ for (const k of keys) {
315
+ const def = this.requireDef(k);
316
+ const source = untracked(this.sources).get(k);
317
+ if (source) source.set(def.default);
318
+ }
319
+ this.values.update((current) => {
320
+ if (!key) return {};
321
+ const { [key]: _removed, ...rest } = current;
322
+ return rest;
323
+ });
324
+ }
325
+ register(defs) {
326
+ this.defs.update((current) => {
327
+ const next = new Map(current);
328
+ for (const def of defs) next.set(def.key, def);
329
+ return next;
330
+ });
331
+ for (const def of defs) {
332
+ if (!(def.key in this.pending)) continue;
333
+ const stored = this.pending[def.key];
334
+ delete this.pending[def.key];
335
+ if (def.persist === false) continue;
336
+ try {
337
+ const valid = this.validate(def, stored);
338
+ this.values.update((current) => ({
339
+ ...current,
340
+ [def.key]: valid
341
+ }));
342
+ } catch {}
343
+ }
344
+ }
345
+ bind(key, source) {
346
+ this.requireDef(key);
347
+ this.sources.update((current) => new Map(current).set(key, source));
348
+ }
349
+ setDefaults(defaults) {
350
+ const updated = [];
351
+ for (const [key, value] of Object.entries(defaults)) {
352
+ if (value === void 0) continue;
353
+ const def = this.requireDef(key);
354
+ updated.push({
355
+ ...def,
356
+ default: this.validate(def, value)
357
+ });
358
+ }
359
+ this.defs.update((current) => {
360
+ const next = new Map(current);
361
+ for (const def of updated) next.set(def.key, def);
362
+ return next;
363
+ });
364
+ }
365
+ read(key) {
366
+ const source = this.sources().get(key);
367
+ if (source) return source.value();
368
+ const values = this.values();
369
+ return key in values ? values[key] : this.defs().get(key)?.default;
370
+ }
371
+ requireDef(key) {
372
+ const def = untracked(this.defs).get(key);
373
+ if (!def) throw new Error(`[shk-config] Unknown option "${key}". Register it with withOptions() or ShkConfigService.register().`);
374
+ return def;
375
+ }
376
+ validate(def, value) {
377
+ const fail = (why) => {
378
+ throw new Error(`[shk-config] Invalid value for "${def.key}": ${why}.`);
379
+ };
380
+ switch (def.type) {
381
+ case "boolean":
382
+ if (typeof value !== "boolean") fail("expected a boolean");
383
+ return value;
384
+ case "number": {
385
+ const n = typeof value === "string" && value.trim() !== "" ? Number(value) : value;
386
+ if (typeof n !== "number" || !isFinite(n)) fail("expected a number");
387
+ if (def.min !== void 0 && n < def.min) fail(`minimum is ${def.min}`);
388
+ if (def.max !== void 0 && n > def.max) fail(`maximum is ${def.max}`);
389
+ return n;
390
+ }
391
+ case "color":
392
+ if (typeof value !== "string") fail("expected a color string");
393
+ if (value !== "" && !/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.test(value)) fail("expected a hex color such as #2563eb (or empty)");
394
+ return value;
395
+ case "select": {
396
+ const match = def.choices?.find((choice) => sameValue(choice.value, value));
397
+ if (match) return match.value;
398
+ if (def.allowCustom && typeof value === "string" && value.trim() !== "") return value.trim();
399
+ return fail("not one of the allowed choices");
400
+ }
401
+ default:
402
+ if (typeof value !== "string") fail("expected a string");
403
+ return value;
404
+ }
405
+ }
406
+ loadStored() {
407
+ if (!this.persistence) return {};
408
+ try {
409
+ const raw = this.win?.localStorage?.getItem(this.persistence.storageKey);
410
+ const parsed = raw ? JSON.parse(raw) : null;
411
+ return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
412
+ } catch {
413
+ return {};
414
+ }
415
+ }
416
+ save(values) {
417
+ if (!this.persistence) return;
418
+ const defs = untracked(this.defs);
419
+ const stored = { ...this.pending };
420
+ for (const [key, value] of Object.entries(values)) if (defs.get(key)?.persist !== false) stored[key] = value;
421
+ try {
422
+ this.win?.localStorage?.setItem(this.persistence.storageKey, JSON.stringify(stored));
423
+ } catch {}
424
+ }
425
+ static {
426
+ this.ɵfac = i0.ɵɵngDeclareFactory({
427
+ minVersion: "12.0.0",
428
+ version: "22.3.2",
429
+ ngImport: i0,
430
+ type: ShkConfigService,
431
+ deps: [],
432
+ target: i0.ɵɵFactoryTarget.Injectable
433
+ });
434
+ }
435
+ static {
436
+ this.ɵprov = i0.ɵɵngDeclareInjectable({
437
+ minVersion: "12.0.0",
438
+ version: "22.3.2",
439
+ ngImport: i0,
440
+ type: ShkConfigService,
441
+ providedIn: "root"
442
+ });
443
+ }
444
+ };
445
+ i0.ɵɵngDeclareClassMetadata({
446
+ minVersion: "12.0.0",
447
+ version: "22.3.2",
448
+ ngImport: i0,
449
+ type: ShkConfigService,
450
+ decorators: [{
451
+ type: Injectable,
452
+ args: [{ providedIn: "root" }]
453
+ }],
454
+ ctorParameters: () => []
455
+ });
388
456
  function sameValue(a, b) {
389
- return a === b || (Number.isNaN(a) && Number.isNaN(b));
457
+ return a === b || Number.isNaN(a) && Number.isNaN(b);
390
458
  }
391
-
392
- /**
393
- * Shirkasoft UI Components.
394
- * Authors: Roberto Valladares Martin (Ansem13), Julio César García García (Sanjuli14).
395
- * Belongs to Shirkasoft.
396
- *
397
- * Builds the `--shk-primary-*` scale from a single color with CSS `color-mix()`,
398
- * so the browser derives every shade and no color math ships in JavaScript.
399
- */
400
459
  const HEX = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i;
401
460
  const THEME_NAME = /^[a-z][a-z0-9-]*$/i;
402
461
  const CSS_VAR_NAME = /^--shk-[a-z0-9-]+$/i;
403
- /** How much of the base color each shade keeps, mixed with white (light) or black (dark). */
404
462
  const SHADES = [
405
- [50, 6, 'white'],
406
- [100, 12, 'white'],
407
- [200, 24, 'white'],
408
- [300, 42, 'white'],
409
- [400, 66, 'white'],
410
- [500, 85, 'white'],
411
- [600, 100, null],
412
- [700, 84, 'black'],
413
- [800, 68, 'black'],
414
- [900, 54, 'black'],
415
- [950, 36, 'black'],
463
+ [
464
+ 50,
465
+ 6,
466
+ "white"
467
+ ],
468
+ [
469
+ 100,
470
+ 12,
471
+ "white"
472
+ ],
473
+ [
474
+ 200,
475
+ 24,
476
+ "white"
477
+ ],
478
+ [
479
+ 300,
480
+ 42,
481
+ "white"
482
+ ],
483
+ [
484
+ 400,
485
+ 66,
486
+ "white"
487
+ ],
488
+ [
489
+ 500,
490
+ 85,
491
+ "white"
492
+ ],
493
+ [
494
+ 600,
495
+ 100,
496
+ null
497
+ ],
498
+ [
499
+ 700,
500
+ 84,
501
+ "black"
502
+ ],
503
+ [
504
+ 800,
505
+ 68,
506
+ "black"
507
+ ],
508
+ [
509
+ 900,
510
+ 54,
511
+ "black"
512
+ ],
513
+ [
514
+ 950,
515
+ 36,
516
+ "black"
517
+ ]
416
518
  ];
417
- /** Custom properties a primary color controls (the scale + the decorative accent). */
418
519
  const PRIMARY_VARS = [
419
- ...SHADES.map(([shade]) => `--shk-primary-${shade}`),
420
- '--shk-emerald-400',
421
- '--shk-emerald-600',
422
- '--shk-emerald-700',
520
+ ...SHADES.map(([shade]) => `--shk-primary-${shade}`),
521
+ "--shk-emerald-400",
522
+ "--shk-emerald-600",
523
+ "--shk-emerald-700"
423
524
  ];
424
- /** Throws when `color` is not a hex color. */
425
525
  function assertHexColor(color, where) {
426
- if (!HEX.test(color)) {
427
- throw new Error(`[shk-config] ${where}: "${color}" is not a hex color such as #2563eb.`);
428
- }
526
+ if (!HEX.test(color)) throw new Error(`[shk-config] ${where}: "${color}" is not a hex color such as #2563eb.`);
429
527
  }
430
- /** `--shk-primary-50` … `--shk-primary-950` (and the accent vars) derived from one color. */
431
528
  function primaryScale(color) {
432
- const vars = {};
433
- for (const [shade, base, mixWith] of SHADES) {
434
- vars[`--shk-primary-${shade}`] = mixWith
435
- ? `color-mix(in oklab, ${color} ${base}%, ${mixWith})`
436
- : color;
437
- }
438
- // Themes keep the decorative gradient in the accent color.
439
- vars['--shk-emerald-400'] = vars['--shk-primary-400'];
440
- vars['--shk-emerald-600'] = vars['--shk-primary-600'];
441
- vars['--shk-emerald-700'] = vars['--shk-primary-700'];
442
- return vars;
529
+ const vars = {};
530
+ for (const [shade, base, mixWith] of SHADES) vars[`--shk-primary-${shade}`] = mixWith ? `color-mix(in oklab, ${color} ${base}%, ${mixWith})` : color;
531
+ vars["--shk-emerald-400"] = vars["--shk-primary-400"];
532
+ vars["--shk-emerald-600"] = vars["--shk-primary-600"];
533
+ vars["--shk-emerald-700"] = vars["--shk-primary-700"];
534
+ return vars;
443
535
  }
444
- /** Normalizes `'#2563eb' | { primary }` and validates name and colors. */
445
536
  function normalizeCustomTheme(name, theme) {
446
- if (!THEME_NAME.test(name)) {
447
- throw new Error(`[shk-config] Theme name "${name}" must start with a letter and contain only letters, digits and dashes.`);
448
- }
449
- const normalized = typeof theme === 'string' ? { primary: theme } : theme;
450
- assertHexColor(normalized.primary, `theme "${name}"`);
451
- for (const [prop, value] of Object.entries(normalized.vars ?? {})) {
452
- // The values are written into a CSS rule: reject anything that could end it.
453
- if (!CSS_VAR_NAME.test(prop) || typeof value !== 'string' || /[;{}<>]/.test(value)) {
454
- throw new Error(`[shk-config] theme "${name}": invalid variable ${prop}: ${String(value)} (names are --shk-…; values cannot contain ; { } < >).`);
455
- }
456
- }
457
- return normalized;
537
+ if (!THEME_NAME.test(name)) throw new Error(`[shk-config] Theme name "${name}" must start with a letter and contain only letters, digits and dashes.`);
538
+ const normalized = typeof theme === "string" ? { primary: theme } : theme;
539
+ assertHexColor(normalized.primary, `theme "${name}"`);
540
+ for (const [prop, value] of Object.entries(normalized.vars ?? {})) if (!CSS_VAR_NAME.test(prop) || typeof value !== "string" || /[;{}<>]/.test(value)) throw new Error(`[shk-config] theme "${name}": invalid variable ${prop}: ${String(value)} (names are --shk-…; values cannot contain ; { } < >).`);
541
+ return normalized;
458
542
  }
459
- /** CSS rule that activates a custom theme through `<html data-shk-theme="name">`. */
460
543
  function customThemeCss(name, theme, attribute) {
461
- const vars = { ...primaryScale(theme.primary), ...(theme.vars ?? {}) };
462
- const body = Object.entries(vars)
463
- .map(([prop, value]) => ` ${prop}: ${value};`)
464
- .join('\n');
465
- return `[${attribute}='${name}'] {\n${body}\n}`;
544
+ const vars = {
545
+ ...primaryScale(theme.primary),
546
+ ...theme.vars ?? {}
547
+ };
548
+ return `[${attribute}='${name}'] {\n${Object.entries(vars).map(([prop, value]) => ` ${prop}: ${value};`).join("\n")}\n}`;
466
549
  }
467
- /** Neutral palettes for `theme.surface` (Tailwind scales, 50 … 900). */
468
550
  const SURFACE_PALETTES = {
469
- slate: {
470
- label: 'Slate',
471
- scale: ['#f8fafc', '#f1f5f9', '#e2e8f0', '#cbd5e1', '#94a3b8', '#64748b', '#475569', '#334155', '#1e293b', '#0f172a'],
472
- },
473
- gray: {
474
- label: 'Gray',
475
- scale: ['#f9fafb', '#f3f4f6', '#e5e7eb', '#d1d5db', '#9ca3af', '#6b7280', '#4b5563', '#374151', '#1f2937', '#111827'],
476
- },
477
- zinc: {
478
- label: 'Zinc',
479
- scale: ['#fafafa', '#f4f4f5', '#e4e4e7', '#d4d4d8', '#a1a1aa', '#71717a', '#52525b', '#3f3f46', '#27272a', '#18181b'],
480
- },
481
- neutral: {
482
- label: 'Neutral',
483
- scale: ['#fafafa', '#f5f5f5', '#e5e5e5', '#d4d4d4', '#a3a3a3', '#737373', '#525252', '#404040', '#262626', '#171717'],
484
- },
485
- stone: {
486
- label: 'Stone',
487
- scale: ['#fafaf9', '#f5f5f4', '#e7e5e4', '#d6d3d1', '#a8a29e', '#78716c', '#57534e', '#44403c', '#292524', '#1c1917'],
488
- },
551
+ slate: {
552
+ label: "Slate",
553
+ scale: [
554
+ "#f8fafc",
555
+ "#f1f5f9",
556
+ "#e2e8f0",
557
+ "#cbd5e1",
558
+ "#94a3b8",
559
+ "#64748b",
560
+ "#475569",
561
+ "#334155",
562
+ "#1e293b",
563
+ "#0f172a"
564
+ ]
565
+ },
566
+ gray: {
567
+ label: "Gray",
568
+ scale: [
569
+ "#f9fafb",
570
+ "#f3f4f6",
571
+ "#e5e7eb",
572
+ "#d1d5db",
573
+ "#9ca3af",
574
+ "#6b7280",
575
+ "#4b5563",
576
+ "#374151",
577
+ "#1f2937",
578
+ "#111827"
579
+ ]
580
+ },
581
+ zinc: {
582
+ label: "Zinc",
583
+ scale: [
584
+ "#fafafa",
585
+ "#f4f4f5",
586
+ "#e4e4e7",
587
+ "#d4d4d8",
588
+ "#a1a1aa",
589
+ "#71717a",
590
+ "#52525b",
591
+ "#3f3f46",
592
+ "#27272a",
593
+ "#18181b"
594
+ ]
595
+ },
596
+ neutral: {
597
+ label: "Neutral",
598
+ scale: [
599
+ "#fafafa",
600
+ "#f5f5f5",
601
+ "#e5e5e5",
602
+ "#d4d4d4",
603
+ "#a3a3a3",
604
+ "#737373",
605
+ "#525252",
606
+ "#404040",
607
+ "#262626",
608
+ "#171717"
609
+ ]
610
+ },
611
+ stone: {
612
+ label: "Stone",
613
+ scale: [
614
+ "#fafaf9",
615
+ "#f5f5f4",
616
+ "#e7e5e4",
617
+ "#d6d3d1",
618
+ "#a8a29e",
619
+ "#78716c",
620
+ "#57534e",
621
+ "#44403c",
622
+ "#292524",
623
+ "#1c1917"
624
+ ]
625
+ }
489
626
  };
490
- const SURFACE_STEPS = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900];
491
- /**
492
- * CSS for every surface palette, activated with `<html data-shk-surface="slate">`.
493
- * Dark mode uses the reversed scale (50 ↔ 900), like the built-in themes. The
494
- * doubled attribute selector out-ranks the theme packs (`html.dark[data-shk-theme]`).
495
- */
496
- function surfaceCss(attribute = 'data-shk-surface') {
497
- return Object.entries(SURFACE_PALETTES)
498
- .map(([name, { scale }]) => {
499
- const sel = `html[${attribute}='${name}'][${attribute}]`;
500
- const light = SURFACE_STEPS.map((step, i) => `--shk-surface-${step}: ${scale[i]};`).join(' ');
501
- const dark = SURFACE_STEPS.map((step, i) => `--shk-surface-${step}: ${scale[9 - i]};`).join(' ');
502
- return (`${sel} { ${light} --shk-scrollbar-thumb: ${scale[3]}; --shk-scrollbar-thumb-hover: ${scale[4]}; }\n` +
503
- `html.dark[${attribute}='${name}'][${attribute}] { ${dark} --shk-scrollbar-thumb: ${scale[6]}; --shk-scrollbar-thumb-hover: ${scale[5]}; }`);
504
- })
505
- .join('\n');
627
+ const SURFACE_STEPS = [
628
+ 50,
629
+ 100,
630
+ 200,
631
+ 300,
632
+ 400,
633
+ 500,
634
+ 600,
635
+ 700,
636
+ 800,
637
+ 900
638
+ ];
639
+ function surfaceCss(attribute = "data-shk-surface") {
640
+ return Object.entries(SURFACE_PALETTES).map(([name, { scale }]) => {
641
+ const sel = `html[${attribute}='${name}'][${attribute}]`;
642
+ const light = SURFACE_STEPS.map((step, i) => `--shk-surface-${step}: ${scale[i]};`).join(" ");
643
+ const dark = SURFACE_STEPS.map((step, i) => `--shk-surface-${step}: ${scale[9 - i]};`).join(" ");
644
+ return `${sel} { ${light} --shk-scrollbar-thumb: ${scale[3]}; --shk-scrollbar-thumb-hover: ${scale[4]}; }\nhtml.dark[${attribute}='${name}'][${attribute}] { ${dark} --shk-scrollbar-thumb: ${scale[6]}; --shk-scrollbar-thumb-hover: ${scale[5]}; }`;
645
+ }).join("\n");
506
646
  }
507
- /** The built-in theme packs as presets. */
508
647
  const BUILT_IN_PRESETS = [
509
- { name: 'default', label: 'Esmeralda', primary: '#059669', surface: 'zinc' },
510
- { name: 'ocean', label: 'Océano', primary: '#0284c7', surface: 'slate' },
511
- { name: 'violet', label: 'Violeta', primary: '#7c3aed', surface: 'zinc' },
512
- { name: 'sunset', label: 'Atardecer', primary: '#ea580c', surface: 'stone' },
648
+ {
649
+ name: "default",
650
+ label: "Esmeralda",
651
+ primary: "#059669",
652
+ surface: "zinc"
653
+ },
654
+ {
655
+ name: "ocean",
656
+ label: "Océano",
657
+ primary: "#0284c7",
658
+ surface: "slate"
659
+ },
660
+ {
661
+ name: "violet",
662
+ label: "Violeta",
663
+ primary: "#7c3aed",
664
+ surface: "zinc"
665
+ },
666
+ {
667
+ name: "sunset",
668
+ label: "Atardecer",
669
+ primary: "#ea580c",
670
+ surface: "stone"
671
+ }
513
672
  ];
514
-
515
- /**
516
- * Shirkasoft UI Components.
517
- * Authors: Roberto Valladares Martin (Ansem13), Julio César García García (Sanjuli14).
518
- * Belongs to Shirkasoft.
519
- */
520
- /**
521
- * Theme packs offered as presets (built-in + `withTheme({ themes })`), with the
522
- * primary color and surface each one uses. Read by `shk-theme-picker`.
523
- */
524
- const SHK_THEME_PRESETS = new InjectionToken('SHK_THEME_PRESETS', {
525
- providedIn: 'root',
526
- factory: () => BUILT_IN_PRESETS,
673
+ const SHK_THEME_PRESETS = new InjectionToken("SHK_THEME_PRESETS", {
674
+ providedIn: "root",
675
+ factory: () => BUILT_IN_PRESETS
527
676
  });
528
- /** Attribute on `<html>` that activates a `theme.surface` palette. */
529
- const SURFACE_ATTRIBUTE = 'data-shk-surface';
677
+ const SURFACE_ATTRIBUTE = "data-shk-surface";
530
678
  function feature(value, extra = []) {
531
- return {
532
- ɵproviders: [{ provide: SHK_CONFIG_FEATURES, multi: true, useValue: value }, ...extra],
533
- };
679
+ return { ɵproviders: [{
680
+ provide: SHK_CONFIG_FEATURES,
681
+ multi: true,
682
+ useValue: value
683
+ }, ...extra] };
534
684
  }
535
- /** Drops `undefined` entries and prefixes the keys with the module name. */
536
685
  function defaultsOf(module, values) {
537
- const out = {};
538
- for (const [name, value] of Object.entries(values)) {
539
- if (value !== undefined)
540
- out[`${module}.${name}`] = value;
541
- }
542
- return out;
686
+ const out = {};
687
+ for (const [name, value] of Object.entries(values)) if (value !== void 0) out[`${module}.${name}`] = value;
688
+ return out;
543
689
  }
544
- /**
545
- * Configures the library. Every module is optional; component inputs still
546
- * override the configured values.
547
- *
548
- * ```ts
549
- * bootstrapApplication(App, {
550
- * providers: [
551
- * provideShk(
552
- * withDates({ locale: 'es', format: 'dd/MM/yyyy' }),
553
- * withNumbers({ currency: 'EUR', locale: 'es-ES' }),
554
- * withTheme({ defaultTheme: 'marca', themes: { marca: '#2563eb' } }),
555
- * withPersistence(),
556
- * ),
557
- * ],
558
- * });
559
- * ```
560
- */
561
690
  function provideShk(...features) {
562
- return makeEnvironmentProviders(features.flatMap((f) => f.ɵproviders));
691
+ return makeEnvironmentProviders(features.flatMap((f) => f.ɵproviders));
563
692
  }
564
- /** Date module: locale, pattern, display style, 12/24 h and first day of the week. */
565
693
  function withDates(config) {
566
- return feature({ defaults: defaultsOf('dates', config) });
694
+ return feature({ defaults: defaultsOf("dates", config) });
567
695
  }
568
- /** Number module: separators locale, currency, currency symbol and decimals. */
569
696
  function withNumbers(config) {
570
- return feature({ defaults: defaultsOf('numbers', config) });
697
+ return feature({ defaults: defaultsOf("numbers", config) });
571
698
  }
572
- /**
573
- * Theme module: built-in and custom themes, light/dark/system scheme and a
574
- * runtime primary color. Replaces `provideShkTheme()` (do not use both).
575
- *
576
- * `theme.name` and `theme.scheme` are shared with `ShkThemeService` (which
577
- * persists them); `theme.primary` is stored by `withPersistence()`.
578
- */
579
699
  function withTheme(config = {}) {
580
- const { themes = {}, primary = '', surface = '', ...themeConfig } = config;
581
- const resolved = { ...DEFAULT_SHK_THEME_CONFIG, ...themeConfig };
582
- const custom = Object.entries(themes).map(([name, theme]) => [name, normalizeCustomTheme(name, theme)]);
583
- if (primary)
584
- assertHexColor(primary, 'withTheme({ primary })');
585
- const presets = [
586
- ...BUILT_IN_PRESETS,
587
- ...custom.map(([name, theme]) => ({
588
- name,
589
- label: theme.label ?? name,
590
- primary: theme.primary,
591
- surface: '',
592
- })),
593
- ];
594
- const options = [
595
- {
596
- key: 'theme.name',
597
- module: 'theme',
598
- type: 'select',
599
- default: resolved.defaultTheme,
600
- label: 'Tema',
601
- description: 'Paleta de colores de la interfaz.',
602
- choices: presets.map((preset) => ({ value: preset.name, label: preset.label })),
603
- persist: false,
604
- },
605
- {
606
- key: 'theme.scheme',
607
- module: 'theme',
608
- type: 'select',
609
- default: resolved.defaultScheme,
610
- label: 'Modo',
611
- choices: [
612
- { value: 'system', label: 'Según el sistema' },
613
- { value: 'light', label: 'Claro' },
614
- { value: 'dark', label: 'Oscuro' },
615
- ],
616
- persist: false,
617
- },
618
- {
619
- key: 'theme.primary',
620
- module: 'theme',
621
- type: 'color',
622
- default: primary,
623
- label: 'Color principal',
624
- description: 'Sustituye el color principal del tema. Vacío = el del tema.',
625
- },
626
- {
627
- key: 'theme.surface',
628
- module: 'theme',
629
- type: 'select',
630
- default: surface,
631
- label: 'Superficie',
632
- description: 'Gama de grises de fondos, bordes y textos. Vacío = la del tema.',
633
- choices: [
634
- { value: '', label: 'La del tema' },
635
- ...Object.entries(SURFACE_PALETTES).map(([value, { label }]) => ({ value, label })),
636
- ],
637
- },
638
- ];
639
- return feature({ options }, [
640
- { provide: SHK_THEME_CONFIG, useValue: resolved },
641
- { provide: SHK_THEME_PRESETS, useValue: presets },
642
- provideAppInitializer(() => {
643
- const doc = inject(DOCUMENT);
644
- const themeService = inject(ShkThemeService);
645
- const configService = inject(ShkConfigService);
646
- const nonce = inject(CSP_NONCE, { optional: true });
647
- // Custom themes + surface palettes, as one stylesheet.
648
- const css = [
649
- surfaceCss(SURFACE_ATTRIBUTE),
650
- ...custom.map(([name, theme]) => customThemeCss(name, theme, resolved.attribute)),
651
- ].join('\n');
652
- let style = doc.head?.querySelector('style[data-shk-themes]');
653
- if (!style && doc.head) {
654
- style = doc.createElement('style');
655
- style.setAttribute('data-shk-themes', '');
656
- // Lets the rules through a strict Content-Security-Policy (style-src 'nonce-…').
657
- if (nonce)
658
- style.setAttribute('nonce', nonce);
659
- doc.head.appendChild(style);
660
- }
661
- if (style)
662
- style.textContent = css;
663
- configService.bind('theme.name', {
664
- value: themeService.theme,
665
- set: (name) => themeService.setTheme(name),
666
- });
667
- configService.bind('theme.scheme', {
668
- value: themeService.scheme,
669
- set: (scheme) => themeService.setScheme(scheme),
670
- });
671
- // Runtime primary color: inline custom properties on <html> win over any theme.
672
- const root = doc.documentElement;
673
- effect(() => {
674
- const color = configService.get('theme.primary')();
675
- if (color) {
676
- for (const [prop, value] of Object.entries(primaryScale(color))) {
677
- root.style.setProperty(prop, value);
678
- }
679
- }
680
- else {
681
- for (const prop of PRIMARY_VARS)
682
- root.style.removeProperty(prop);
683
- }
684
- });
685
- // Runtime surface palette: an attribute selector, so light and dark both apply.
686
- effect(() => {
687
- const palette = configService.get('theme.surface')();
688
- if (palette)
689
- root.setAttribute(SURFACE_ATTRIBUTE, palette);
690
- else
691
- root.removeAttribute(SURFACE_ATTRIBUTE);
692
- });
693
- }),
694
- ]);
700
+ const { themes = {}, primary = "", surface = "", ...themeConfig } = config;
701
+ const resolved = {
702
+ ...DEFAULT_SHK_THEME_CONFIG,
703
+ ...themeConfig
704
+ };
705
+ const custom = Object.entries(themes).map(([name, theme]) => [name, normalizeCustomTheme(name, theme)]);
706
+ if (primary) assertHexColor(primary, "withTheme({ primary })");
707
+ const presets = [...BUILT_IN_PRESETS, ...custom.map(([name, theme]) => ({
708
+ name,
709
+ label: theme.label ?? name,
710
+ primary: theme.primary,
711
+ surface: ""
712
+ }))];
713
+ return feature({ options: [
714
+ {
715
+ key: "theme.name",
716
+ module: "theme",
717
+ type: "select",
718
+ default: resolved.defaultTheme,
719
+ label: "Tema",
720
+ description: "Paleta de colores de la interfaz.",
721
+ choices: presets.map((preset) => ({
722
+ value: preset.name,
723
+ label: preset.label
724
+ })),
725
+ persist: false
726
+ },
727
+ {
728
+ key: "theme.scheme",
729
+ module: "theme",
730
+ type: "select",
731
+ default: resolved.defaultScheme,
732
+ label: "Modo",
733
+ choices: [
734
+ {
735
+ value: "system",
736
+ label: "Según el sistema"
737
+ },
738
+ {
739
+ value: "light",
740
+ label: "Claro"
741
+ },
742
+ {
743
+ value: "dark",
744
+ label: "Oscuro"
745
+ }
746
+ ],
747
+ persist: false
748
+ },
749
+ {
750
+ key: "theme.primary",
751
+ module: "theme",
752
+ type: "color",
753
+ default: primary,
754
+ label: "Color principal",
755
+ description: "Sustituye el color principal del tema. Vacío = el del tema."
756
+ },
757
+ {
758
+ key: "theme.surface",
759
+ module: "theme",
760
+ type: "select",
761
+ default: surface,
762
+ label: "Superficie",
763
+ description: "Gama de grises de fondos, bordes y textos. Vacío = la del tema.",
764
+ choices: [{
765
+ value: "",
766
+ label: "La del tema"
767
+ }, ...Object.entries(SURFACE_PALETTES).map(([value, { label }]) => ({
768
+ value,
769
+ label
770
+ }))]
771
+ }
772
+ ] }, [
773
+ {
774
+ provide: SHK_THEME_CONFIG,
775
+ useValue: resolved
776
+ },
777
+ {
778
+ provide: SHK_THEME_PRESETS,
779
+ useValue: presets
780
+ },
781
+ provideAppInitializer(() => {
782
+ const doc = inject(DOCUMENT);
783
+ const themeService = inject(ShkThemeService);
784
+ const configService = inject(ShkConfigService);
785
+ const nonce = inject(CSP_NONCE, { optional: true });
786
+ const css = [surfaceCss(SURFACE_ATTRIBUTE), ...custom.map(([name, theme]) => customThemeCss(name, theme, resolved.attribute))].join("\n");
787
+ let style = doc.head?.querySelector("style[data-shk-themes]");
788
+ if (!style && doc.head) {
789
+ style = doc.createElement("style");
790
+ style.setAttribute("data-shk-themes", "");
791
+ if (nonce) style.setAttribute("nonce", nonce);
792
+ doc.head.appendChild(style);
793
+ }
794
+ if (style) style.textContent = css;
795
+ configService.bind("theme.name", {
796
+ value: themeService.theme,
797
+ set: (name) => themeService.setTheme(name)
798
+ });
799
+ configService.bind("theme.scheme", {
800
+ value: themeService.scheme,
801
+ set: (scheme) => themeService.setScheme(scheme)
802
+ });
803
+ const root = doc.documentElement;
804
+ effect(() => {
805
+ const color = configService.get("theme.primary")();
806
+ if (color) for (const [prop, value] of Object.entries(primaryScale(color))) root.style.setProperty(prop, value);
807
+ else for (const prop of PRIMARY_VARS) root.style.removeProperty(prop);
808
+ });
809
+ effect(() => {
810
+ const palette = configService.get("theme.surface")();
811
+ if (palette) root.setAttribute(SURFACE_ATTRIBUTE, palette);
812
+ else root.removeAttribute(SURFACE_ATTRIBUTE);
813
+ });
814
+ })
815
+ ]);
695
816
  }
696
- /** Registers app-defined options in the same registry (`app.pageSize`, …). */
697
817
  function withOptions(options) {
698
- return feature({ options });
818
+ return feature({ options });
699
819
  }
700
- /**
701
- * Persists changed options in localStorage so they survive reloads.
702
- * Options with `persist: false` are skipped (the theme service stores its own).
703
- */
704
820
  function withPersistence(config = {}) {
705
- return {
706
- ɵproviders: [
707
- {
708
- provide: SHK_CONFIG_PERSISTENCE,
709
- useValue: { storageKey: config.storageKey ?? 'shk-config' },
710
- },
711
- ],
712
- };
821
+ return { ɵproviders: [{
822
+ provide: SHK_CONFIG_PERSISTENCE,
823
+ useValue: { storageKey: config.storageKey ?? "shk-config" }
824
+ }] };
713
825
  }
714
-
715
- /**
716
- * Shirkasoft UI Components.
717
- * Authors: Roberto Valladares Martin (Ansem13), Julio César García García (Sanjuli14).
718
- * Belongs to Shirkasoft.
719
- *
720
- * Locale-aware formatting helpers used by the components and available to apps.
721
- * Pure functions on top of `Intl`: no Angular locale data needs registering.
722
- */
723
- /** `Intl` formatters are expensive to build; reuse them per locale/options. */
724
- const formatterCache = new Map();
826
+ const formatterCache = /* @__PURE__ */ new Map();
725
827
  function dateFormatter(locale, options) {
726
- const key = `d|${locale}|${JSON.stringify(options)}`;
727
- let fmt = formatterCache.get(key);
728
- if (!fmt) {
729
- fmt = new Intl.DateTimeFormat(safeLocale(locale), options);
730
- formatterCache.set(key, fmt);
731
- }
732
- return fmt;
828
+ const key = `d|${locale}|${JSON.stringify(options)}`;
829
+ let fmt = formatterCache.get(key);
830
+ if (!fmt) {
831
+ fmt = new Intl.DateTimeFormat(safeLocale(locale), options);
832
+ formatterCache.set(key, fmt);
833
+ }
834
+ return fmt;
733
835
  }
734
836
  function numberFormatter(locale, options) {
735
- const key = `n|${locale}|${JSON.stringify(options)}`;
736
- let fmt = formatterCache.get(key);
737
- if (!fmt) {
738
- fmt = new Intl.NumberFormat(safeLocale(locale), options);
739
- formatterCache.set(key, fmt);
740
- }
741
- return fmt;
837
+ const key = `n|${locale}|${JSON.stringify(options)}`;
838
+ let fmt = formatterCache.get(key);
839
+ if (!fmt) {
840
+ fmt = new Intl.NumberFormat(safeLocale(locale), options);
841
+ formatterCache.set(key, fmt);
842
+ }
843
+ return fmt;
742
844
  }
743
- /** Falls back to the runtime default when the tag is not a valid BCP 47 locale. */
744
845
  function safeLocale(locale) {
745
- try {
746
- return Intl.getCanonicalLocales(locale)[0];
747
- }
748
- catch {
749
- return undefined;
750
- }
846
+ try {
847
+ return Intl.getCanonicalLocales(locale)[0];
848
+ } catch {
849
+ return;
850
+ }
751
851
  }
752
- /** Default numeric pattern for a locale: `MM/dd/yyyy` for English, `dd/MM/yyyy` otherwise. */
753
852
  function resolveDateFormat(format, locale) {
754
- if (format)
755
- return format;
756
- return locale.toLowerCase().startsWith('en') ? 'MM/dd/yyyy' : 'dd/MM/yyyy';
853
+ if (format) return format;
854
+ return locale.toLowerCase().startsWith("en") ? "MM/dd/yyyy" : "dd/MM/yyyy";
757
855
  }
758
- /** Converts a value to a `Date`. ISO date-only strings (`2026-12-31`) are read as local dates. */
759
856
  function toDate(value) {
760
- if (value === null || value === undefined || value === '')
761
- return null;
762
- if (value instanceof Date)
763
- return isNaN(value.getTime()) ? null : value;
764
- if (typeof value === 'string') {
765
- const dateOnly = /^(\d{4})-(\d{1,2})-(\d{1,2})$/.exec(value.trim());
766
- if (dateOnly) {
767
- return new Date(Number(dateOnly[1]), Number(dateOnly[2]) - 1, Number(dateOnly[3]));
768
- }
769
- }
770
- const date = new Date(value);
771
- return isNaN(date.getTime()) ? null : date;
857
+ if (value === null || value === void 0 || value === "") return null;
858
+ if (value instanceof Date) return isNaN(value.getTime()) ? null : value;
859
+ if (typeof value === "string") {
860
+ const dateOnly = /^(\d{4})-(\d{1,2})-(\d{1,2})$/.exec(value.trim());
861
+ if (dateOnly) return new Date(Number(dateOnly[1]), Number(dateOnly[2]) - 1, Number(dateOnly[3]));
862
+ }
863
+ const date = new Date(value);
864
+ return isNaN(date.getTime()) ? null : date;
772
865
  }
773
- const pad = (n, width = 2) => String(n).padStart(width, '0');
774
- /**
775
- * Pattern tokens, longest first. Text between single quotes is copied verbatim.
776
- * Compatible with the common Angular `DatePipe` tokens (`y` = full year).
777
- */
866
+ const pad = (n, width = 2) => String(n).padStart(width, "0");
778
867
  const DATE_TOKENS = /'[^']*'|yyyy|yy|y|MMMM|MMM|MM|M|dd|d|EEEE|EEE|HH|H|hh|h|mm|ss|a/g;
779
- /**
780
- * Formats a date with a pattern (`dd/MM/yyyy`, `d MMM yyyy`, `yyyy-MM-dd HH:mm`…).
781
- *
782
- * Tokens: `yyyy y yy` year · `MMMM MMM MM M` month · `dd d` day · `EEEE EEE` weekday ·
783
- * `HH H` 0-23 · `hh h` 1-12 · `mm` minutes · `ss` seconds · `a` AM/PM ·
784
- * `'text'` literal. Month and weekday names follow `locale`, with its own casing
785
- * ("31 dic 2026" in Spanish, "Dec 31, 2026" in English).
786
- * Returns an empty string for empty or invalid values.
787
- */
788
868
  function formatDate(value, pattern, locale) {
789
- const date = toDate(value);
790
- if (!date)
791
- return '';
792
- const name = (options) => dateFormatter(locale, options).format(date).replace('.', '');
793
- const h = date.getHours();
794
- return pattern.replace(DATE_TOKENS, (token) => {
795
- switch (token) {
796
- case 'yyyy':
797
- case 'y': return String(date.getFullYear());
798
- case 'yy': return pad(date.getFullYear() % 100);
799
- case 'MMMM': return name({ month: 'long' });
800
- case 'MMM': return name({ month: 'short' });
801
- case 'MM': return pad(date.getMonth() + 1);
802
- case 'M': return String(date.getMonth() + 1);
803
- case 'dd': return pad(date.getDate());
804
- case 'd': return String(date.getDate());
805
- case 'EEEE': return name({ weekday: 'long' });
806
- case 'EEE': return name({ weekday: 'short' });
807
- case 'HH': return pad(h);
808
- case 'H': return String(h);
809
- case 'hh': return pad(h % 12 || 12);
810
- case 'h': return String(h % 12 || 12);
811
- case 'mm': return pad(date.getMinutes());
812
- case 'ss': return pad(date.getSeconds());
813
- case 'a': return h < 12 ? 'AM' : 'PM';
814
- default: return token.slice(1, -1); // 'literal'
815
- }
816
- });
869
+ const date = toDate(value);
870
+ if (!date) return "";
871
+ const name = (options) => dateFormatter(locale, options).format(date).replace(".", "");
872
+ const h = date.getHours();
873
+ return pattern.replace(DATE_TOKENS, (token) => {
874
+ switch (token) {
875
+ case "yyyy":
876
+ case "y": return String(date.getFullYear());
877
+ case "yy": return pad(date.getFullYear() % 100);
878
+ case "MMMM": return name({ month: "long" });
879
+ case "MMM": return name({ month: "short" });
880
+ case "MM": return pad(date.getMonth() + 1);
881
+ case "M": return String(date.getMonth() + 1);
882
+ case "dd": return pad(date.getDate());
883
+ case "d": return String(date.getDate());
884
+ case "EEEE": return name({ weekday: "long" });
885
+ case "EEE": return name({ weekday: "short" });
886
+ case "HH": return pad(h);
887
+ case "H": return String(h);
888
+ case "hh": return pad(h % 12 || 12);
889
+ case "h": return String(h % 12 || 12);
890
+ case "mm": return pad(date.getMinutes());
891
+ case "ss": return pad(date.getSeconds());
892
+ case "a": return h < 12 ? "AM" : "PM";
893
+ default: return token.slice(1, -1);
894
+ }
895
+ });
817
896
  }
818
- /**
819
- * Date formatted with an `Intl` style (`long`: "31 de diciembre de 2026"),
820
- * optionally followed by the time in `timeStyle`.
821
- */
822
897
  function formatDateStyle(value, style, locale, timeStyle) {
823
- const date = toDate(value);
824
- if (!date)
825
- return '';
826
- const options = timeStyle
827
- ? { dateStyle: style, timeStyle }
828
- : { dateStyle: style };
829
- return dateFormatter(locale, options).format(date);
898
+ const date = toDate(value);
899
+ if (!date) return "";
900
+ return dateFormatter(locale, timeStyle ? {
901
+ dateStyle: style,
902
+ timeStyle
903
+ } : { dateStyle: style }).format(date);
830
904
  }
831
- /**
832
- * Field order and separator of a pattern, for typing dates in an input.
833
- * Named months and weekdays are typed as numbers (`d MMM yyyy` → `dd/MM/yyyy`).
834
- */
835
905
  function typedDateLayout(pattern) {
836
- const order = [];
837
- for (const token of pattern.replace(/'[^']*'/g, '').match(/y+|M+|d+/g) ?? []) {
838
- const field = token[0] === 'y' ? 'y' : token[0] === 'M' ? 'm' : 'd';
839
- if (!order.includes(field))
840
- order.push(field);
841
- }
842
- for (const field of ['d', 'm', 'y']) {
843
- if (!order.includes(field))
844
- order.push(field);
845
- }
846
- const separator = /[\/\-.]/.exec(pattern)?.[0] ?? '/';
847
- return { order, separator };
906
+ const order = [];
907
+ for (const token of pattern.replace(/'[^']*'/g, "").match(/y+|M+|d+/g) ?? []) {
908
+ const field = token[0] === "y" ? "y" : token[0] === "M" ? "m" : "d";
909
+ if (!order.includes(field)) order.push(field);
910
+ }
911
+ for (const field of [
912
+ "d",
913
+ "m",
914
+ "y"
915
+ ]) if (!order.includes(field)) order.push(field);
916
+ return {
917
+ order,
918
+ separator: /[\/\-.]/.exec(pattern)?.[0] ?? "/"
919
+ };
848
920
  }
849
- /** Narrow currency symbol (`USD` → `$`, `EUR` → `€`). Unknown codes are returned as-is. */
850
921
  function currencySymbol(currency, locale) {
851
- try {
852
- const parts = numberFormatter(locale, {
853
- style: 'currency',
854
- currency,
855
- currencyDisplay: 'narrowSymbol',
856
- }).formatToParts(0);
857
- return parts.find((p) => p.type === 'currency')?.value ?? currency;
858
- }
859
- catch {
860
- return currency;
861
- }
922
+ try {
923
+ return numberFormatter(locale, {
924
+ style: "currency",
925
+ currency,
926
+ currencyDisplay: "narrowSymbol"
927
+ }).formatToParts(0).find((p) => p.type === "currency")?.value ?? currency;
928
+ } catch {
929
+ return currency;
930
+ }
862
931
  }
863
- /**
864
- * Formats an amount as money (`$1,234.50`, `1.234,50 €`, `¥1,000`).
865
- * `decimals` `null`/omitted = the currency's own digits (2 for USD, 0 for JPY).
866
- */
867
932
  function formatCurrency(value, currency, locale, decimals = null) {
868
- const n = typeof value === 'string' ? Number(value) : value;
869
- if (n === null || n === undefined || !isFinite(n))
870
- return '';
871
- const digits = decimals === null ? {} : { minimumFractionDigits: decimals, maximumFractionDigits: decimals };
872
- try {
873
- return numberFormatter(locale, { style: 'currency', currency, ...digits }).format(n);
874
- }
875
- catch {
876
- // Unknown currency code: plain number followed by the code.
877
- const d = decimals ?? 2;
878
- return `${formatNumber(n, locale, d, d)} ${currency}`;
879
- }
933
+ const n = typeof value === "string" ? Number(value) : value;
934
+ if (n === null || n === void 0 || !isFinite(n)) return "";
935
+ const digits = decimals === null ? {} : {
936
+ minimumFractionDigits: decimals,
937
+ maximumFractionDigits: decimals
938
+ };
939
+ try {
940
+ return numberFormatter(locale, {
941
+ style: "currency",
942
+ currency,
943
+ ...digits
944
+ }).format(n);
945
+ } catch {
946
+ const d = decimals ?? 2;
947
+ return `${formatNumber(n, locale, d, d)} ${currency}`;
948
+ }
880
949
  }
881
- /** Decimal digits a currency uses by default (USD → 2, JPY → 0, BHD → 3). Unknown codes → 2. */
882
950
  function currencyDecimals(currency) {
883
- try {
884
- return numberFormatter('en-US', { style: 'currency', currency }).resolvedOptions()
885
- .maximumFractionDigits ?? 2;
886
- }
887
- catch {
888
- return 2;
889
- }
951
+ try {
952
+ return numberFormatter("en-US", {
953
+ style: "currency",
954
+ currency
955
+ }).resolvedOptions().maximumFractionDigits ?? 2;
956
+ } catch {
957
+ return 2;
958
+ }
890
959
  }
891
- /** Formats a number with the locale's grouping and decimal separators. */
892
960
  function formatNumber(value, locale, maxDecimals = 2, minDecimals = 0) {
893
- if (!isFinite(value))
894
- return '';
895
- return numberFormatter(locale, {
896
- minimumFractionDigits: minDecimals,
897
- maximumFractionDigits: maxDecimals,
898
- }).format(value);
961
+ if (!isFinite(value)) return "";
962
+ return numberFormatter(locale, {
963
+ minimumFractionDigits: minDecimals,
964
+ maximumFractionDigits: maxDecimals
965
+ }).format(value);
899
966
  }
900
- /** Decimal and grouping separators of a locale (`es-ES` → `,` and `.`). */
901
967
  function numberSeparators(locale) {
902
- const parts = numberFormatter(locale, {}).formatToParts(12345.6);
903
- return {
904
- decimal: parts.find((p) => p.type === 'decimal')?.value ?? '.',
905
- group: parts.find((p) => p.type === 'group')?.value ?? ',',
906
- };
968
+ const parts = numberFormatter(locale, {}).formatToParts(12345.6);
969
+ return {
970
+ decimal: parts.find((p) => p.type === "decimal")?.value ?? ".",
971
+ group: parts.find((p) => p.type === "group")?.value ?? ","
972
+ };
907
973
  }
908
-
909
- /**
910
- * Generated bundle index. Do not edit.
911
- */
912
-
913
974
  export { BUILT_IN_PRESETS, DATE_OPTIONS, NUMBER_OPTIONS, SHK_CONFIG_FEATURES, SHK_CONFIG_PERSISTENCE, SHK_THEME_PRESETS, SURFACE_PALETTES, ShkConfigService, currencyDecimals, currencySymbol, formatCurrency, formatDate, formatDateStyle, formatNumber, numberSeparators, primaryScale, provideShk, resolveDateFormat, toDate, typedDateLayout, withDates, withNumbers, withOptions, withPersistence, withTheme };
914
- //# sourceMappingURL=shirkasoft-ui-components-config.mjs.map
975
+
976
+ //# sourceMappingURL=shirkasoft-ui-components-config.mjs.map