shirkasoft-ui-components 1.13.18 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +415 -42
- package/fesm2022/shirkasoft-ui-components-breadcrumb.mjs +189 -100
- package/fesm2022/shirkasoft-ui-components-breadcrumb.mjs.map +1 -1
- package/fesm2022/shirkasoft-ui-components-button.mjs +367 -73
- package/fesm2022/shirkasoft-ui-components-button.mjs.map +1 -1
- package/fesm2022/shirkasoft-ui-components-chart.mjs +206 -142
- package/fesm2022/shirkasoft-ui-components-chart.mjs.map +1 -1
- package/fesm2022/shirkasoft-ui-components-config.mjs +976 -0
- package/fesm2022/shirkasoft-ui-components-config.mjs.map +1 -0
- package/fesm2022/shirkasoft-ui-components-confirm-dialog.mjs +307 -142
- package/fesm2022/shirkasoft-ui-components-confirm-dialog.mjs.map +1 -1
- package/fesm2022/shirkasoft-ui-components-date-picker.mjs +1624 -1400
- package/fesm2022/shirkasoft-ui-components-date-picker.mjs.map +1 -1
- package/fesm2022/shirkasoft-ui-components-fieldset.mjs +347 -92
- package/fesm2022/shirkasoft-ui-components-fieldset.mjs.map +1 -1
- package/fesm2022/shirkasoft-ui-components-file-upload.mjs +484 -293
- package/fesm2022/shirkasoft-ui-components-file-upload.mjs.map +1 -1
- package/fesm2022/shirkasoft-ui-components-icons.mjs +1141 -0
- package/fesm2022/shirkasoft-ui-components-icons.mjs.map +1 -0
- package/fesm2022/shirkasoft-ui-components-knob.mjs +395 -180
- package/fesm2022/shirkasoft-ui-components-knob.mjs.map +1 -1
- package/fesm2022/shirkasoft-ui-components-loading.mjs +505 -128
- package/fesm2022/shirkasoft-ui-components-loading.mjs.map +1 -1
- package/fesm2022/shirkasoft-ui-components-modal.mjs +311 -303
- package/fesm2022/shirkasoft-ui-components-modal.mjs.map +1 -1
- package/fesm2022/shirkasoft-ui-components-notification.mjs +188 -142
- package/fesm2022/shirkasoft-ui-components-notification.mjs.map +1 -1
- package/fesm2022/shirkasoft-ui-components-price-input.mjs +517 -277
- package/fesm2022/shirkasoft-ui-components-price-input.mjs.map +1 -1
- package/fesm2022/shirkasoft-ui-components-rail-sidebar.mjs +669 -289
- package/fesm2022/shirkasoft-ui-components-rail-sidebar.mjs.map +1 -1
- package/fesm2022/shirkasoft-ui-components-select.mjs +1014 -814
- package/fesm2022/shirkasoft-ui-components-select.mjs.map +1 -1
- package/fesm2022/shirkasoft-ui-components-sidebar.mjs +508 -184
- package/fesm2022/shirkasoft-ui-components-sidebar.mjs.map +1 -1
- package/fesm2022/shirkasoft-ui-components-skeleton.mjs +197 -57
- package/fesm2022/shirkasoft-ui-components-skeleton.mjs.map +1 -1
- package/fesm2022/shirkasoft-ui-components-table.mjs +1918 -1676
- package/fesm2022/shirkasoft-ui-components-table.mjs.map +1 -1
- package/fesm2022/shirkasoft-ui-components-tabs.mjs +419 -177
- package/fesm2022/shirkasoft-ui-components-tabs.mjs.map +1 -1
- package/fesm2022/shirkasoft-ui-components-tag.mjs +177 -51
- package/fesm2022/shirkasoft-ui-components-tag.mjs.map +1 -1
- package/fesm2022/shirkasoft-ui-components-text-field.mjs +687 -369
- package/fesm2022/shirkasoft-ui-components-text-field.mjs.map +1 -1
- package/fesm2022/shirkasoft-ui-components-theme-picker.mjs +466 -0
- package/fesm2022/shirkasoft-ui-components-theme-picker.mjs.map +1 -0
- package/fesm2022/shirkasoft-ui-components-theme.mjs +147 -0
- package/fesm2022/shirkasoft-ui-components-theme.mjs.map +1 -0
- package/fesm2022/shirkasoft-ui-components-timeline.mjs +791 -215
- package/fesm2022/shirkasoft-ui-components-timeline.mjs.map +1 -1
- package/fesm2022/shirkasoft-ui-components-toggle.mjs +205 -128
- package/fesm2022/shirkasoft-ui-components-toggle.mjs.map +1 -1
- package/fesm2022/shirkasoft-ui-components-tooltip.mjs +244 -180
- package/fesm2022/shirkasoft-ui-components-tooltip.mjs.map +1 -1
- package/fesm2022/shirkasoft-ui-components-utils.mjs +97 -125
- package/fesm2022/shirkasoft-ui-components-utils.mjs.map +1 -1
- package/fesm2022/shirkasoft-ui-components-wizard.mjs +673 -166
- package/fesm2022/shirkasoft-ui-components-wizard.mjs.map +1 -1
- package/fesm2022/shirkasoft-ui-components.mjs +0 -9
- package/package.json +37 -7
- package/src/baseline.css +2472 -0
- package/src/theme.css +15 -543
- package/src/themes/ocean.css +56 -0
- package/src/themes/sunset.css +55 -0
- package/src/themes/violet.css +25 -0
- package/src/tokens.css +612 -0
- package/types/shirkasoft-ui-components-breadcrumb.d.ts +59 -44
- package/types/shirkasoft-ui-components-button.d.ts +142 -49
- package/types/shirkasoft-ui-components-chart.d.ts +59 -44
- package/types/shirkasoft-ui-components-config.d.ts +357 -0
- package/types/shirkasoft-ui-components-confirm-dialog.d.ts +107 -65
- package/types/shirkasoft-ui-components-date-picker.d.ts +527 -373
- package/types/shirkasoft-ui-components-fieldset.d.ts +135 -59
- package/types/shirkasoft-ui-components-file-upload.d.ts +176 -106
- package/types/shirkasoft-ui-components-icons.d.ts +1430 -0
- package/types/shirkasoft-ui-components-knob.d.ts +151 -64
- package/types/shirkasoft-ui-components-loading.d.ts +155 -64
- package/types/shirkasoft-ui-components-modal.d.ts +134 -132
- package/types/shirkasoft-ui-components-notification.d.ts +63 -58
- package/types/shirkasoft-ui-components-price-input.d.ts +198 -85
- package/types/shirkasoft-ui-components-rail-sidebar.d.ts +262 -142
- package/types/shirkasoft-ui-components-select.d.ts +301 -192
- package/types/shirkasoft-ui-components-sidebar.d.ts +198 -92
- package/types/shirkasoft-ui-components-skeleton.d.ts +68 -27
- package/types/shirkasoft-ui-components-table.d.ts +849 -649
- package/types/shirkasoft-ui-components-tabs.d.ts +102 -61
- package/types/shirkasoft-ui-components-tag.d.ts +54 -23
- package/types/shirkasoft-ui-components-text-field.d.ts +231 -111
- package/types/shirkasoft-ui-components-theme-picker.d.ts +117 -0
- package/types/shirkasoft-ui-components-theme.d.ts +80 -0
- package/types/shirkasoft-ui-components-timeline.d.ts +326 -150
- package/types/shirkasoft-ui-components-toggle.d.ts +76 -45
- package/types/shirkasoft-ui-components-tooltip.d.ts +64 -43
- package/types/shirkasoft-ui-components-utils.d.ts +26 -17
- package/types/shirkasoft-ui-components-wizard.d.ts +236 -86
- package/types/shirkasoft-ui-components.d.ts +1 -2
- package/fesm2022/shirkasoft-ui-components.mjs.map +0 -1
|
@@ -0,0 +1,976 @@
|
|
|
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";
|
|
5
|
+
const DATE_OPTIONS = [
|
|
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
|
+
}
|
|
149
|
+
];
|
|
150
|
+
const NUMBER_OPTIONS = [
|
|
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
|
+
}
|
|
255
|
+
];
|
|
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
|
+
});
|
|
456
|
+
function sameValue(a, b) {
|
|
457
|
+
return a === b || Number.isNaN(a) && Number.isNaN(b);
|
|
458
|
+
}
|
|
459
|
+
const HEX = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i;
|
|
460
|
+
const THEME_NAME = /^[a-z][a-z0-9-]*$/i;
|
|
461
|
+
const CSS_VAR_NAME = /^--shk-[a-z0-9-]+$/i;
|
|
462
|
+
const SHADES = [
|
|
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
|
+
]
|
|
518
|
+
];
|
|
519
|
+
const PRIMARY_VARS = [
|
|
520
|
+
...SHADES.map(([shade]) => `--shk-primary-${shade}`),
|
|
521
|
+
"--shk-emerald-400",
|
|
522
|
+
"--shk-emerald-600",
|
|
523
|
+
"--shk-emerald-700"
|
|
524
|
+
];
|
|
525
|
+
function assertHexColor(color, where) {
|
|
526
|
+
if (!HEX.test(color)) throw new Error(`[shk-config] ${where}: "${color}" is not a hex color such as #2563eb.`);
|
|
527
|
+
}
|
|
528
|
+
function primaryScale(color) {
|
|
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;
|
|
535
|
+
}
|
|
536
|
+
function normalizeCustomTheme(name, theme) {
|
|
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;
|
|
542
|
+
}
|
|
543
|
+
function customThemeCss(name, theme, attribute) {
|
|
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}`;
|
|
549
|
+
}
|
|
550
|
+
const SURFACE_PALETTES = {
|
|
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
|
+
}
|
|
626
|
+
};
|
|
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");
|
|
646
|
+
}
|
|
647
|
+
const BUILT_IN_PRESETS = [
|
|
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
|
+
}
|
|
672
|
+
];
|
|
673
|
+
const SHK_THEME_PRESETS = new InjectionToken("SHK_THEME_PRESETS", {
|
|
674
|
+
providedIn: "root",
|
|
675
|
+
factory: () => BUILT_IN_PRESETS
|
|
676
|
+
});
|
|
677
|
+
const SURFACE_ATTRIBUTE = "data-shk-surface";
|
|
678
|
+
function feature(value, extra = []) {
|
|
679
|
+
return { ɵproviders: [{
|
|
680
|
+
provide: SHK_CONFIG_FEATURES,
|
|
681
|
+
multi: true,
|
|
682
|
+
useValue: value
|
|
683
|
+
}, ...extra] };
|
|
684
|
+
}
|
|
685
|
+
function defaultsOf(module, values) {
|
|
686
|
+
const out = {};
|
|
687
|
+
for (const [name, value] of Object.entries(values)) if (value !== void 0) out[`${module}.${name}`] = value;
|
|
688
|
+
return out;
|
|
689
|
+
}
|
|
690
|
+
function provideShk(...features) {
|
|
691
|
+
return makeEnvironmentProviders(features.flatMap((f) => f.ɵproviders));
|
|
692
|
+
}
|
|
693
|
+
function withDates(config) {
|
|
694
|
+
return feature({ defaults: defaultsOf("dates", config) });
|
|
695
|
+
}
|
|
696
|
+
function withNumbers(config) {
|
|
697
|
+
return feature({ defaults: defaultsOf("numbers", config) });
|
|
698
|
+
}
|
|
699
|
+
function withTheme(config = {}) {
|
|
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
|
+
]);
|
|
816
|
+
}
|
|
817
|
+
function withOptions(options) {
|
|
818
|
+
return feature({ options });
|
|
819
|
+
}
|
|
820
|
+
function withPersistence(config = {}) {
|
|
821
|
+
return { ɵproviders: [{
|
|
822
|
+
provide: SHK_CONFIG_PERSISTENCE,
|
|
823
|
+
useValue: { storageKey: config.storageKey ?? "shk-config" }
|
|
824
|
+
}] };
|
|
825
|
+
}
|
|
826
|
+
const formatterCache = /* @__PURE__ */ new Map();
|
|
827
|
+
function dateFormatter(locale, options) {
|
|
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;
|
|
835
|
+
}
|
|
836
|
+
function numberFormatter(locale, options) {
|
|
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;
|
|
844
|
+
}
|
|
845
|
+
function safeLocale(locale) {
|
|
846
|
+
try {
|
|
847
|
+
return Intl.getCanonicalLocales(locale)[0];
|
|
848
|
+
} catch {
|
|
849
|
+
return;
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
function resolveDateFormat(format, locale) {
|
|
853
|
+
if (format) return format;
|
|
854
|
+
return locale.toLowerCase().startsWith("en") ? "MM/dd/yyyy" : "dd/MM/yyyy";
|
|
855
|
+
}
|
|
856
|
+
function toDate(value) {
|
|
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;
|
|
865
|
+
}
|
|
866
|
+
const pad = (n, width = 2) => String(n).padStart(width, "0");
|
|
867
|
+
const DATE_TOKENS = /'[^']*'|yyyy|yy|y|MMMM|MMM|MM|M|dd|d|EEEE|EEE|HH|H|hh|h|mm|ss|a/g;
|
|
868
|
+
function formatDate(value, pattern, locale) {
|
|
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
|
+
});
|
|
896
|
+
}
|
|
897
|
+
function formatDateStyle(value, style, locale, timeStyle) {
|
|
898
|
+
const date = toDate(value);
|
|
899
|
+
if (!date) return "";
|
|
900
|
+
return dateFormatter(locale, timeStyle ? {
|
|
901
|
+
dateStyle: style,
|
|
902
|
+
timeStyle
|
|
903
|
+
} : { dateStyle: style }).format(date);
|
|
904
|
+
}
|
|
905
|
+
function typedDateLayout(pattern) {
|
|
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
|
+
};
|
|
920
|
+
}
|
|
921
|
+
function currencySymbol(currency, locale) {
|
|
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
|
+
}
|
|
931
|
+
}
|
|
932
|
+
function formatCurrency(value, currency, locale, decimals = null) {
|
|
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
|
+
}
|
|
949
|
+
}
|
|
950
|
+
function currencyDecimals(currency) {
|
|
951
|
+
try {
|
|
952
|
+
return numberFormatter("en-US", {
|
|
953
|
+
style: "currency",
|
|
954
|
+
currency
|
|
955
|
+
}).resolvedOptions().maximumFractionDigits ?? 2;
|
|
956
|
+
} catch {
|
|
957
|
+
return 2;
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
function formatNumber(value, locale, maxDecimals = 2, minDecimals = 0) {
|
|
961
|
+
if (!isFinite(value)) return "";
|
|
962
|
+
return numberFormatter(locale, {
|
|
963
|
+
minimumFractionDigits: minDecimals,
|
|
964
|
+
maximumFractionDigits: maxDecimals
|
|
965
|
+
}).format(value);
|
|
966
|
+
}
|
|
967
|
+
function numberSeparators(locale) {
|
|
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
|
+
};
|
|
973
|
+
}
|
|
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 };
|
|
975
|
+
|
|
976
|
+
//# sourceMappingURL=shirkasoft-ui-components-config.mjs.map
|