shirkasoft-ui-components 2.0.1 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +201 -52
- package/fesm2022/shirkasoft-ui-components-config.mjs +610 -72
- package/fesm2022/shirkasoft-ui-components-config.mjs.map +1 -1
- package/fesm2022/shirkasoft-ui-components-icons.mjs +6 -6
- package/fesm2022/shirkasoft-ui-components-icons.mjs.map +1 -1
- package/fesm2022/shirkasoft-ui-components-table.mjs +11 -0
- package/fesm2022/shirkasoft-ui-components-table.mjs.map +1 -1
- package/fesm2022/shirkasoft-ui-components-theme-picker.mjs +262 -165
- package/fesm2022/shirkasoft-ui-components-theme-picker.mjs.map +1 -1
- package/fesm2022/shirkasoft-ui-components-theme.mjs +2 -24
- package/fesm2022/shirkasoft-ui-components-theme.mjs.map +1 -1
- package/package.json +1 -1
- package/types/shirkasoft-ui-components-config.d.ts +246 -20
- package/types/shirkasoft-ui-components-icons.d.ts +6 -6
- package/types/shirkasoft-ui-components-theme-picker.d.ts +40 -12
- package/types/shirkasoft-ui-components-theme.d.ts +17 -9
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { DOCUMENT } from "@angular/common";
|
|
2
2
|
import * as i0 from "@angular/core";
|
|
3
3
|
import { CSP_NONCE, Injectable, InjectionToken, computed, effect, inject, makeEnvironmentProviders, provideAppInitializer, signal, untracked } from "@angular/core";
|
|
4
|
+
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
|
|
5
|
+
import { TranslocoService } from "@jsverse/transloco";
|
|
4
6
|
import { DEFAULT_SHK_THEME_CONFIG, SHK_THEME_CONFIG, ShkThemeService } from "shirkasoft-ui-components/theme";
|
|
5
7
|
const DATE_OPTIONS = [
|
|
6
8
|
{
|
|
@@ -253,23 +255,104 @@ const NUMBER_OPTIONS = [
|
|
|
253
255
|
]
|
|
254
256
|
}
|
|
255
257
|
];
|
|
258
|
+
var ShkLabels = class ShkLabels {
|
|
259
|
+
constructor() {
|
|
260
|
+
this.overrides = inject(SHK_LABEL_OVERRIDES);
|
|
261
|
+
this.transloco = this.injectTransloco();
|
|
262
|
+
this.revision = signal(0, ...ngDevMode ? [{ debugName: "revision" }] : /* istanbul ignore next */ []);
|
|
263
|
+
if (!this.transloco) return;
|
|
264
|
+
this.transloco.langChanges$.pipe(takeUntilDestroyed()).subscribe(() => {
|
|
265
|
+
this.revision.update((value) => value + 1);
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
get(key, fallback) {
|
|
269
|
+
this.revision();
|
|
270
|
+
if (!key) return fallback;
|
|
271
|
+
const override = this.overrides[key];
|
|
272
|
+
if (override) return override;
|
|
273
|
+
const transloco = this.transloco;
|
|
274
|
+
if (!transloco) return fallback;
|
|
275
|
+
try {
|
|
276
|
+
const value = transloco.translate(key);
|
|
277
|
+
return value && value !== key ? value : fallback;
|
|
278
|
+
} catch {
|
|
279
|
+
return fallback;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
injectTransloco() {
|
|
283
|
+
try {
|
|
284
|
+
return inject(TranslocoService, { optional: true }) ?? null;
|
|
285
|
+
} catch {
|
|
286
|
+
return null;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
static {
|
|
290
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
291
|
+
minVersion: "12.0.0",
|
|
292
|
+
version: "22.3.2",
|
|
293
|
+
ngImport: i0,
|
|
294
|
+
type: ShkLabels,
|
|
295
|
+
deps: [],
|
|
296
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
static {
|
|
300
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
301
|
+
minVersion: "12.0.0",
|
|
302
|
+
version: "22.3.2",
|
|
303
|
+
ngImport: i0,
|
|
304
|
+
type: ShkLabels,
|
|
305
|
+
providedIn: "root"
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
310
|
+
minVersion: "12.0.0",
|
|
311
|
+
version: "22.3.2",
|
|
312
|
+
ngImport: i0,
|
|
313
|
+
type: ShkLabels,
|
|
314
|
+
decorators: [{
|
|
315
|
+
type: Injectable,
|
|
316
|
+
args: [{ providedIn: "root" }]
|
|
317
|
+
}],
|
|
318
|
+
ctorParameters: () => []
|
|
319
|
+
});
|
|
320
|
+
const SHK_LABEL_OVERRIDES = new InjectionToken("SHK_LABEL_OVERRIDES", {
|
|
321
|
+
providedIn: "root",
|
|
322
|
+
factory: () => ({})
|
|
323
|
+
});
|
|
256
324
|
const SHK_CONFIG_FEATURES = new InjectionToken("SHK_CONFIG_FEATURES");
|
|
257
325
|
const SHK_CONFIG_PERSISTENCE = new InjectionToken("SHK_CONFIG_PERSISTENCE");
|
|
258
326
|
var ShkConfigService = class ShkConfigService {
|
|
259
327
|
constructor() {
|
|
260
328
|
this.win = inject(DOCUMENT).defaultView;
|
|
261
329
|
this.persistence = inject(SHK_CONFIG_PERSISTENCE, { optional: true });
|
|
330
|
+
this.labels = inject(ShkLabels);
|
|
262
331
|
this.defs = signal(/* @__PURE__ */ new Map(), ...ngDevMode ? [{ debugName: "defs" }] : /* istanbul ignore next */ []);
|
|
263
|
-
this.
|
|
332
|
+
this.deviceValues = signal({}, ...ngDevMode ? [{ debugName: "deviceValues" }] : /* istanbul ignore next */ []);
|
|
333
|
+
this.sharedValues = signal({}, ...ngDevMode ? [{ debugName: "sharedValues" }] : /* istanbul ignore next */ []);
|
|
334
|
+
this.draftValues = signal(null, ...ngDevMode ? [{ debugName: "draftValues" }] : /* istanbul ignore next */ []);
|
|
264
335
|
this.sources = signal(/* @__PURE__ */ new Map(), ...ngDevMode ? [{ debugName: "sources" }] : /* istanbul ignore next */ []);
|
|
336
|
+
this.appliers = signal(/* @__PURE__ */ new Map(), ...ngDevMode ? [{ debugName: "appliers" }] : /* istanbul ignore next */ []);
|
|
265
337
|
this.pending = {};
|
|
266
338
|
this.cache = /* @__PURE__ */ new Map();
|
|
339
|
+
this.device = this.deviceValues.asReadonly();
|
|
340
|
+
this.shared = this.sharedValues.asReadonly();
|
|
341
|
+
this.draft = this.draftValues.asReadonly();
|
|
342
|
+
this.isPreviewing = computed(() => this.draftValues() !== null, ...ngDevMode ? [{ debugName: "isPreviewing" }] : /* istanbul ignore next */ []);
|
|
267
343
|
this.options = computed(() => [...this.defs().values()].map((def) => {
|
|
268
344
|
const value = this.read(def.key);
|
|
269
345
|
return {
|
|
270
346
|
...def,
|
|
347
|
+
label: this.labels.get(def.labelKey, def.label ?? def.key),
|
|
348
|
+
description: this.labels.get(def.descriptionKey, def.description ?? ""),
|
|
349
|
+
choices: def.choices?.map((choice) => ({
|
|
350
|
+
...choice,
|
|
351
|
+
label: this.labels.get(choice.labelKey, choice.label)
|
|
352
|
+
})),
|
|
271
353
|
value,
|
|
272
|
-
isDefault: sameValue(value, def.default)
|
|
354
|
+
isDefault: sameValue(value, def.default),
|
|
355
|
+
source: this.sourceOf(def)
|
|
273
356
|
};
|
|
274
357
|
}), ...ngDevMode ? [{ debugName: "options" }] : /* istanbul ignore next */ []);
|
|
275
358
|
this.modules = computed(() => [...new Set([...this.defs().values()].map((def) => def.module))], ...ngDevMode ? [{ debugName: "modules" }] : /* istanbul ignore next */ []);
|
|
@@ -279,7 +362,13 @@ var ShkConfigService = class ShkConfigService {
|
|
|
279
362
|
if (feature.options) this.register(feature.options);
|
|
280
363
|
if (feature.defaults) this.setDefaults(feature.defaults);
|
|
281
364
|
}
|
|
282
|
-
if (this.persistence) effect(() => this.save(this.
|
|
365
|
+
if (this.persistence) effect(() => this.save(this.deviceValues()));
|
|
366
|
+
effect(() => {
|
|
367
|
+
for (const [key, callback] of this.appliers()) {
|
|
368
|
+
const value = this.read(key);
|
|
369
|
+
untracked(() => callback(value));
|
|
370
|
+
}
|
|
371
|
+
});
|
|
283
372
|
}
|
|
284
373
|
get(key) {
|
|
285
374
|
this.requireDef(key);
|
|
@@ -296,7 +385,7 @@ var ShkConfigService = class ShkConfigService {
|
|
|
296
385
|
value(key) {
|
|
297
386
|
return untracked(this.get(key));
|
|
298
387
|
}
|
|
299
|
-
set(key, value) {
|
|
388
|
+
set(key, value, layer) {
|
|
300
389
|
const def = this.requireDef(key);
|
|
301
390
|
const valid = this.validate(def, value);
|
|
302
391
|
const source = untracked(this.sources).get(key);
|
|
@@ -304,7 +393,18 @@ var ShkConfigService = class ShkConfigService {
|
|
|
304
393
|
source.set(valid);
|
|
305
394
|
return;
|
|
306
395
|
}
|
|
307
|
-
this.
|
|
396
|
+
if (untracked(this.draftValues) !== null) {
|
|
397
|
+
this.draftValues.update((draft) => ({
|
|
398
|
+
...draft,
|
|
399
|
+
[key]: valid
|
|
400
|
+
}));
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
if ((layer ?? def.scope ?? "device") === "shared") this.sharedValues.update((current) => ({
|
|
404
|
+
...current,
|
|
405
|
+
[key]: valid
|
|
406
|
+
}));
|
|
407
|
+
else this.deviceValues.update((current) => ({
|
|
308
408
|
...current,
|
|
309
409
|
[key]: valid
|
|
310
410
|
}));
|
|
@@ -316,11 +416,23 @@ var ShkConfigService = class ShkConfigService {
|
|
|
316
416
|
const source = untracked(this.sources).get(k);
|
|
317
417
|
if (source) source.set(def.default);
|
|
318
418
|
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
419
|
+
if (key) {
|
|
420
|
+
const draft = untracked(this.draftValues);
|
|
421
|
+
if (draft && key in draft) {
|
|
422
|
+
this.draftValues.update((current) => {
|
|
423
|
+
const { [key]: _removed, ...rest } = current ?? {};
|
|
424
|
+
return rest;
|
|
425
|
+
});
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
this.deviceValues.update((current) => {
|
|
429
|
+
const { [key]: _removed, ...rest } = current;
|
|
430
|
+
return rest;
|
|
431
|
+
});
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
this.draftValues.set(untracked(this.draftValues) === null ? null : {});
|
|
435
|
+
this.deviceValues.set({});
|
|
324
436
|
}
|
|
325
437
|
register(defs) {
|
|
326
438
|
this.defs.update((current) => {
|
|
@@ -335,7 +447,7 @@ var ShkConfigService = class ShkConfigService {
|
|
|
335
447
|
if (def.persist === false) continue;
|
|
336
448
|
try {
|
|
337
449
|
const valid = this.validate(def, stored);
|
|
338
|
-
this.
|
|
450
|
+
this.deviceValues.update((current) => ({
|
|
339
451
|
...current,
|
|
340
452
|
[def.key]: valid
|
|
341
453
|
}));
|
|
@@ -346,6 +458,36 @@ var ShkConfigService = class ShkConfigService {
|
|
|
346
458
|
this.requireDef(key);
|
|
347
459
|
this.sources.update((current) => new Map(current).set(key, source));
|
|
348
460
|
}
|
|
461
|
+
apply(key, callback) {
|
|
462
|
+
this.requireDef(key);
|
|
463
|
+
callback(untracked(() => this.read(key)));
|
|
464
|
+
this.appliers.update((current) => new Map(current).set(key, callback));
|
|
465
|
+
}
|
|
466
|
+
setShared(values) {
|
|
467
|
+
const accepted = {};
|
|
468
|
+
for (const [key, value] of Object.entries(values)) {
|
|
469
|
+
const def = untracked(this.defs).get(key);
|
|
470
|
+
if (!def || def.persist === false) continue;
|
|
471
|
+
try {
|
|
472
|
+
accepted[key] = this.validate(def, value);
|
|
473
|
+
} catch {}
|
|
474
|
+
}
|
|
475
|
+
this.sharedValues.set(accepted);
|
|
476
|
+
}
|
|
477
|
+
beginDraft() {
|
|
478
|
+
this.draftValues.set({});
|
|
479
|
+
}
|
|
480
|
+
commitDraft() {
|
|
481
|
+
const draft = untracked(this.draftValues) ?? {};
|
|
482
|
+
this.sharedValues.update((current) => ({
|
|
483
|
+
...current,
|
|
484
|
+
...draft
|
|
485
|
+
}));
|
|
486
|
+
this.draftValues.set(null);
|
|
487
|
+
}
|
|
488
|
+
discardDraft() {
|
|
489
|
+
this.draftValues.set(null);
|
|
490
|
+
}
|
|
349
491
|
setDefaults(defaults) {
|
|
350
492
|
const updated = [];
|
|
351
493
|
for (const [key, value] of Object.entries(defaults)) {
|
|
@@ -365,8 +507,22 @@ var ShkConfigService = class ShkConfigService {
|
|
|
365
507
|
read(key) {
|
|
366
508
|
const source = this.sources().get(key);
|
|
367
509
|
if (source) return source.value();
|
|
368
|
-
const
|
|
369
|
-
|
|
510
|
+
const def = this.defs().get(key);
|
|
511
|
+
const draft = this.draftValues();
|
|
512
|
+
if (draft && key in draft) return draft[key];
|
|
513
|
+
const device = this.deviceValues();
|
|
514
|
+
if (key in device) return device[key];
|
|
515
|
+
const shared = this.sharedValues();
|
|
516
|
+
if (key in shared) return shared[key];
|
|
517
|
+
return def?.default;
|
|
518
|
+
}
|
|
519
|
+
sourceOf(def) {
|
|
520
|
+
if (this.sources().get(def.key)) return "device";
|
|
521
|
+
const draft = this.draftValues();
|
|
522
|
+
if (draft && def.key in draft) return "draft";
|
|
523
|
+
if (def.key in this.deviceValues()) return "device";
|
|
524
|
+
if (def.key in this.sharedValues()) return "shared";
|
|
525
|
+
return "default";
|
|
370
526
|
}
|
|
371
527
|
requireDef(key) {
|
|
372
528
|
const def = untracked(this.defs).get(key);
|
|
@@ -413,11 +569,11 @@ var ShkConfigService = class ShkConfigService {
|
|
|
413
569
|
return {};
|
|
414
570
|
}
|
|
415
571
|
}
|
|
416
|
-
save(
|
|
572
|
+
save(device) {
|
|
417
573
|
if (!this.persistence) return;
|
|
418
574
|
const defs = untracked(this.defs);
|
|
419
575
|
const stored = { ...this.pending };
|
|
420
|
-
for (const [key, value] of Object.entries(
|
|
576
|
+
for (const [key, value] of Object.entries(device)) if (defs.get(key)?.persist !== false) stored[key] = value;
|
|
421
577
|
try {
|
|
422
578
|
this.win?.localStorage?.setItem(this.persistence.storageKey, JSON.stringify(stored));
|
|
423
579
|
} catch {}
|
|
@@ -456,6 +612,125 @@ i0.ɵɵngDeclareClassMetadata({
|
|
|
456
612
|
function sameValue(a, b) {
|
|
457
613
|
return a === b || Number.isNaN(a) && Number.isNaN(b);
|
|
458
614
|
}
|
|
615
|
+
const SHK_CONFIG_STORE = new InjectionToken("SHK_CONFIG_STORE");
|
|
616
|
+
var ShkConfigConflictError = class extends Error {
|
|
617
|
+
constructor(expected, actual) {
|
|
618
|
+
super(`[shk-config] The shared configuration changed on the server (expected revision ${expected}, got ${actual}). Load it again before saving.`);
|
|
619
|
+
this.expected = expected;
|
|
620
|
+
this.actual = actual;
|
|
621
|
+
this.name = "ShkConfigConflictError";
|
|
622
|
+
}
|
|
623
|
+
};
|
|
624
|
+
var ShkConfigSync = class ShkConfigSync {
|
|
625
|
+
constructor() {
|
|
626
|
+
this.config = inject(ShkConfigService);
|
|
627
|
+
this.store = inject(SHK_CONFIG_STORE, { optional: true });
|
|
628
|
+
this.available = !!this.store;
|
|
629
|
+
this.status = signal("idle", ...ngDevMode ? [{ debugName: "status" }] : /* istanbul ignore next */ []);
|
|
630
|
+
this.revision = signal(null, ...ngDevMode ? [{ debugName: "revision" }] : /* istanbul ignore next */ []);
|
|
631
|
+
this.error = signal(null, ...ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []);
|
|
632
|
+
this.isDirty = computed(() => {
|
|
633
|
+
const draft = this.config.draft();
|
|
634
|
+
if (!draft) return false;
|
|
635
|
+
const shared = this.config.shared();
|
|
636
|
+
return Object.entries(draft).some(([key, value]) => !(key in shared) || shared[key] !== value);
|
|
637
|
+
}, ...ngDevMode ? [{ debugName: "isDirty" }] : /* istanbul ignore next */ []);
|
|
638
|
+
}
|
|
639
|
+
async load() {
|
|
640
|
+
if (!this.store) return;
|
|
641
|
+
this.status.set("loading");
|
|
642
|
+
this.error.set(null);
|
|
643
|
+
try {
|
|
644
|
+
const snapshot = await this.store.load();
|
|
645
|
+
this.config.setShared(snapshot.values);
|
|
646
|
+
this.revision.set(snapshot.revision);
|
|
647
|
+
this.status.set("idle");
|
|
648
|
+
} catch (error) {
|
|
649
|
+
this.error.set(error);
|
|
650
|
+
this.status.set("error");
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
preview() {
|
|
654
|
+
this.config.beginDraft();
|
|
655
|
+
}
|
|
656
|
+
async save() {
|
|
657
|
+
if (!this.store) return;
|
|
658
|
+
this.status.set("saving");
|
|
659
|
+
this.error.set(null);
|
|
660
|
+
const values = {
|
|
661
|
+
...this.config.shared(),
|
|
662
|
+
...this.config.draft() ?? {}
|
|
663
|
+
};
|
|
664
|
+
try {
|
|
665
|
+
const snapshot = await this.store.save(values, this.revision());
|
|
666
|
+
this.config.setShared(snapshot.values);
|
|
667
|
+
this.revision.set(snapshot.revision);
|
|
668
|
+
this.config.discardDraft();
|
|
669
|
+
this.status.set("idle");
|
|
670
|
+
} catch (error) {
|
|
671
|
+
this.error.set(error);
|
|
672
|
+
this.status.set("error");
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
discard() {
|
|
676
|
+
this.config.discardDraft();
|
|
677
|
+
this.error.set(null);
|
|
678
|
+
this.status.set("idle");
|
|
679
|
+
}
|
|
680
|
+
static {
|
|
681
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
682
|
+
minVersion: "12.0.0",
|
|
683
|
+
version: "22.3.2",
|
|
684
|
+
ngImport: i0,
|
|
685
|
+
type: ShkConfigSync,
|
|
686
|
+
deps: [],
|
|
687
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
688
|
+
});
|
|
689
|
+
}
|
|
690
|
+
static {
|
|
691
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
692
|
+
minVersion: "12.0.0",
|
|
693
|
+
version: "22.3.2",
|
|
694
|
+
ngImport: i0,
|
|
695
|
+
type: ShkConfigSync,
|
|
696
|
+
providedIn: "root"
|
|
697
|
+
});
|
|
698
|
+
}
|
|
699
|
+
};
|
|
700
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
701
|
+
minVersion: "12.0.0",
|
|
702
|
+
version: "22.3.2",
|
|
703
|
+
ngImport: i0,
|
|
704
|
+
type: ShkConfigSync,
|
|
705
|
+
decorators: [{
|
|
706
|
+
type: Injectable,
|
|
707
|
+
args: [{ providedIn: "root" }]
|
|
708
|
+
}]
|
|
709
|
+
});
|
|
710
|
+
async function configRevision(values) {
|
|
711
|
+
const json = JSON.stringify(canonicalize(values));
|
|
712
|
+
const subtle = globalThis.crypto?.subtle;
|
|
713
|
+
if (!subtle) return fnv1a(json);
|
|
714
|
+
const digest = await subtle.digest("SHA-256", new TextEncoder().encode(json));
|
|
715
|
+
return [...new Uint8Array(digest)].map((byte) => byte.toString(16).padStart(2, "0")).join("").slice(0, 16);
|
|
716
|
+
}
|
|
717
|
+
function canonicalize(value) {
|
|
718
|
+
if (Array.isArray(value)) return value.map(canonicalize);
|
|
719
|
+
if (value && typeof value === "object") {
|
|
720
|
+
const out = {};
|
|
721
|
+
for (const key of Object.keys(value).sort()) out[key] = canonicalize(value[key]);
|
|
722
|
+
return out;
|
|
723
|
+
}
|
|
724
|
+
return value;
|
|
725
|
+
}
|
|
726
|
+
function fnv1a(text) {
|
|
727
|
+
let hash = 2166136261;
|
|
728
|
+
for (let i = 0; i < text.length; i++) {
|
|
729
|
+
hash ^= text.charCodeAt(i);
|
|
730
|
+
hash = Math.imul(hash, 16777619) >>> 0;
|
|
731
|
+
}
|
|
732
|
+
return hash.toString(16).padStart(8, "0");
|
|
733
|
+
}
|
|
459
734
|
const HEX = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i;
|
|
460
735
|
const THEME_NAME = /^[a-z][a-z0-9-]*$/i;
|
|
461
736
|
const CSS_VAR_NAME = /^--shk-[a-z0-9-]+$/i;
|
|
@@ -516,12 +791,70 @@ const SHADES = [
|
|
|
516
791
|
"black"
|
|
517
792
|
]
|
|
518
793
|
];
|
|
794
|
+
const DARK_SHADES = [
|
|
795
|
+
[
|
|
796
|
+
50,
|
|
797
|
+
14,
|
|
798
|
+
"black"
|
|
799
|
+
],
|
|
800
|
+
[
|
|
801
|
+
100,
|
|
802
|
+
20,
|
|
803
|
+
"black"
|
|
804
|
+
],
|
|
805
|
+
[
|
|
806
|
+
200,
|
|
807
|
+
30,
|
|
808
|
+
"black"
|
|
809
|
+
],
|
|
810
|
+
[
|
|
811
|
+
300,
|
|
812
|
+
52,
|
|
813
|
+
"white"
|
|
814
|
+
],
|
|
815
|
+
[
|
|
816
|
+
400,
|
|
817
|
+
70,
|
|
818
|
+
"white"
|
|
819
|
+
],
|
|
820
|
+
[
|
|
821
|
+
500,
|
|
822
|
+
86,
|
|
823
|
+
"white"
|
|
824
|
+
],
|
|
825
|
+
[
|
|
826
|
+
600,
|
|
827
|
+
100,
|
|
828
|
+
null
|
|
829
|
+
],
|
|
830
|
+
[
|
|
831
|
+
700,
|
|
832
|
+
86,
|
|
833
|
+
"white"
|
|
834
|
+
],
|
|
835
|
+
[
|
|
836
|
+
800,
|
|
837
|
+
66,
|
|
838
|
+
"black"
|
|
839
|
+
],
|
|
840
|
+
[
|
|
841
|
+
900,
|
|
842
|
+
52,
|
|
843
|
+
"black"
|
|
844
|
+
],
|
|
845
|
+
[
|
|
846
|
+
950,
|
|
847
|
+
28,
|
|
848
|
+
"black"
|
|
849
|
+
]
|
|
850
|
+
];
|
|
519
851
|
const PRIMARY_VARS = [
|
|
520
852
|
...SHADES.map(([shade]) => `--shk-primary-${shade}`),
|
|
521
853
|
"--shk-emerald-400",
|
|
522
854
|
"--shk-emerald-600",
|
|
523
855
|
"--shk-emerald-700"
|
|
524
856
|
];
|
|
857
|
+
const DEFAULT_PRIMARY = "#059669";
|
|
525
858
|
function assertHexColor(color, where) {
|
|
526
859
|
if (!HEX.test(color)) throw new Error(`[shk-config] ${where}: "${color}" is not a hex color such as #2563eb.`);
|
|
527
860
|
}
|
|
@@ -533,20 +866,24 @@ function primaryScale(color) {
|
|
|
533
866
|
vars["--shk-emerald-700"] = vars["--shk-primary-700"];
|
|
534
867
|
return vars;
|
|
535
868
|
}
|
|
869
|
+
function primaryScaleDark(color) {
|
|
870
|
+
const vars = {};
|
|
871
|
+
for (const [shade, base, mixWith] of DARK_SHADES) vars[`--shk-primary-${shade}`] = mixWith ? `color-mix(in oklab, ${color} ${base}%, ${mixWith})` : color;
|
|
872
|
+
vars["--shk-emerald-400"] = vars["--shk-primary-400"];
|
|
873
|
+
vars["--shk-emerald-600"] = vars["--shk-primary-600"];
|
|
874
|
+
vars["--shk-emerald-700"] = vars["--shk-primary-700"];
|
|
875
|
+
return vars;
|
|
876
|
+
}
|
|
536
877
|
function normalizeCustomTheme(name, theme) {
|
|
537
878
|
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
879
|
const normalized = typeof theme === "string" ? { primary: theme } : theme;
|
|
539
880
|
assertHexColor(normalized.primary, `theme "${name}"`);
|
|
540
|
-
for (const [prop, value] of Object.entries(
|
|
881
|
+
for (const [prop, value] of Object.entries({
|
|
882
|
+
...normalized.vars,
|
|
883
|
+
...normalized.darkVars
|
|
884
|
+
})) 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
885
|
return normalized;
|
|
542
886
|
}
|
|
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
887
|
const SURFACE_PALETTES = {
|
|
551
888
|
slate: {
|
|
552
889
|
label: "Slate",
|
|
@@ -636,38 +973,172 @@ const SURFACE_STEPS = [
|
|
|
636
973
|
800,
|
|
637
974
|
900
|
|
638
975
|
];
|
|
976
|
+
function surfaceVars(palette, dark = false) {
|
|
977
|
+
const entry = SURFACE_PALETTES[palette];
|
|
978
|
+
if (!entry) return {};
|
|
979
|
+
const vars = {};
|
|
980
|
+
for (let i = 0; i < SURFACE_STEPS.length; i++) vars[`--shk-surface-${SURFACE_STEPS[i]}`] = entry.scale[dark ? 9 - i : i];
|
|
981
|
+
vars["--shk-scrollbar-thumb"] = entry.scale[dark ? 6 : 3];
|
|
982
|
+
vars["--shk-scrollbar-thumb-hover"] = entry.scale[dark ? 5 : 4];
|
|
983
|
+
return vars;
|
|
984
|
+
}
|
|
639
985
|
function surfaceCss(attribute = "data-shk-surface") {
|
|
640
|
-
return Object.entries(SURFACE_PALETTES).map(([name
|
|
641
|
-
const
|
|
642
|
-
const
|
|
643
|
-
|
|
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]}; }`;
|
|
986
|
+
return Object.entries(SURFACE_PALETTES).map(([name]) => {
|
|
987
|
+
const light = surfaceVars(name);
|
|
988
|
+
const dark = surfaceVars(name, true);
|
|
989
|
+
return `${`html[${attribute}='${name}'][${attribute}]`} { ${cssBody(light)} }\nhtml.dark[${attribute}='${name}'][${attribute}] { ${cssBody(dark)} }`;
|
|
645
990
|
}).join("\n");
|
|
646
991
|
}
|
|
992
|
+
function cssBody(vars) {
|
|
993
|
+
return Object.entries(vars).map(([prop, value]) => `${prop}: ${value};`).join(" ");
|
|
994
|
+
}
|
|
995
|
+
function customThemeCss(name, theme, attribute) {
|
|
996
|
+
const light = {
|
|
997
|
+
...primaryScale(theme.primary),
|
|
998
|
+
...theme.surface ? surfaceVars(theme.surface) : {},
|
|
999
|
+
...theme.vars ?? {}
|
|
1000
|
+
};
|
|
1001
|
+
const dark = {
|
|
1002
|
+
...primaryScaleDark(theme.primary),
|
|
1003
|
+
...theme.surface ? surfaceVars(theme.surface, true) : {},
|
|
1004
|
+
...theme.darkVars ?? {}
|
|
1005
|
+
};
|
|
1006
|
+
return `[${attribute}='${name}'] {\n${Object.entries(light).map(([prop, value]) => ` ${prop}: ${value};`).join("\n")}\n}\nhtml.dark[${attribute}='${name}'] {\n${Object.entries(dark).map(([prop, value]) => ` ${prop}: ${value};`).join("\n")}\n}`;
|
|
1007
|
+
}
|
|
1008
|
+
function defaultDarkPrimaryCss() {
|
|
1009
|
+
return `html.dark {\n${Object.entries(primaryScaleDark(DEFAULT_PRIMARY)).map(([prop, value]) => ` ${prop}: ${value};`).join("\n")}\n}`;
|
|
1010
|
+
}
|
|
1011
|
+
function primaryOverrideCss(color, attribute = "data-shk-primary") {
|
|
1012
|
+
return `html[${attribute}][${attribute}] { ${cssBody(primaryScale(color))} }\nhtml.dark[${attribute}][${attribute}] { ${cssBody(primaryScaleDark(color))} }`;
|
|
1013
|
+
}
|
|
647
1014
|
const BUILT_IN_PRESETS = [
|
|
648
1015
|
{
|
|
649
1016
|
name: "default",
|
|
650
|
-
label: "
|
|
1017
|
+
label: "Emerald",
|
|
1018
|
+
labelKey: "theme.presets.default",
|
|
651
1019
|
primary: "#059669",
|
|
652
1020
|
surface: "zinc"
|
|
653
1021
|
},
|
|
654
1022
|
{
|
|
655
1023
|
name: "ocean",
|
|
656
|
-
label: "
|
|
1024
|
+
label: "Ocean",
|
|
1025
|
+
labelKey: "theme.presets.ocean",
|
|
657
1026
|
primary: "#0284c7",
|
|
658
|
-
surface: "slate"
|
|
1027
|
+
surface: "slate",
|
|
1028
|
+
vars: {
|
|
1029
|
+
"--shk-primary-50": "#f0f9ff",
|
|
1030
|
+
"--shk-primary-100": "#e0f2fe",
|
|
1031
|
+
"--shk-primary-200": "#bae6fd",
|
|
1032
|
+
"--shk-primary-300": "#7dd3fc",
|
|
1033
|
+
"--shk-primary-400": "#38bdf8",
|
|
1034
|
+
"--shk-primary-500": "#0ea5e9",
|
|
1035
|
+
"--shk-primary-600": "#0284c7",
|
|
1036
|
+
"--shk-primary-700": "#0369a1",
|
|
1037
|
+
"--shk-primary-800": "#075985",
|
|
1038
|
+
"--shk-primary-900": "#0c4a6e",
|
|
1039
|
+
"--shk-primary-950": "#082f49",
|
|
1040
|
+
"--shk-surface-50": "#f8fafc",
|
|
1041
|
+
"--shk-surface-100": "#f1f5f9",
|
|
1042
|
+
"--shk-surface-200": "#e2e8f0",
|
|
1043
|
+
"--shk-surface-300": "#cbd5e1",
|
|
1044
|
+
"--shk-surface-400": "#94a3b8",
|
|
1045
|
+
"--shk-surface-500": "#64748b",
|
|
1046
|
+
"--shk-surface-600": "#475569",
|
|
1047
|
+
"--shk-surface-700": "#334155",
|
|
1048
|
+
"--shk-surface-800": "#1e293b",
|
|
1049
|
+
"--shk-surface-900": "#0f172a",
|
|
1050
|
+
"--shk-emerald-400": "#38bdf8",
|
|
1051
|
+
"--shk-emerald-600": "#0284c7",
|
|
1052
|
+
"--shk-emerald-700": "#0369a1",
|
|
1053
|
+
"--shk-scrollbar-thumb": "#cbd5e1",
|
|
1054
|
+
"--shk-scrollbar-thumb-hover": "#94a3b8"
|
|
1055
|
+
},
|
|
1056
|
+
darkVars: {
|
|
1057
|
+
"--shk-surface-50": "#0f172a",
|
|
1058
|
+
"--shk-surface-100": "#1e293b",
|
|
1059
|
+
"--shk-surface-200": "#334155",
|
|
1060
|
+
"--shk-surface-300": "#475569",
|
|
1061
|
+
"--shk-surface-400": "#64748b",
|
|
1062
|
+
"--shk-surface-500": "#94a3b8",
|
|
1063
|
+
"--shk-surface-600": "#cbd5e1",
|
|
1064
|
+
"--shk-surface-700": "#e2e8f0",
|
|
1065
|
+
"--shk-surface-800": "#f1f5f9",
|
|
1066
|
+
"--shk-surface-900": "#f8fafc",
|
|
1067
|
+
"--shk-scrollbar-thumb": "#475569",
|
|
1068
|
+
"--shk-scrollbar-thumb-hover": "#64748b"
|
|
1069
|
+
}
|
|
659
1070
|
},
|
|
660
1071
|
{
|
|
661
1072
|
name: "violet",
|
|
662
|
-
label: "
|
|
1073
|
+
label: "Violet",
|
|
1074
|
+
labelKey: "theme.presets.violet",
|
|
663
1075
|
primary: "#7c3aed",
|
|
664
|
-
surface: "zinc"
|
|
1076
|
+
surface: "zinc",
|
|
1077
|
+
vars: {
|
|
1078
|
+
"--shk-primary-50": "#f5f3ff",
|
|
1079
|
+
"--shk-primary-100": "#ede9fe",
|
|
1080
|
+
"--shk-primary-200": "#ddd6fe",
|
|
1081
|
+
"--shk-primary-300": "#c4b5fd",
|
|
1082
|
+
"--shk-primary-400": "#a78bfa",
|
|
1083
|
+
"--shk-primary-500": "#8b5cf6",
|
|
1084
|
+
"--shk-primary-600": "#7c3aed",
|
|
1085
|
+
"--shk-primary-700": "#6d28d9",
|
|
1086
|
+
"--shk-primary-800": "#5b21b6",
|
|
1087
|
+
"--shk-primary-900": "#4c1d95",
|
|
1088
|
+
"--shk-primary-950": "#2e1065",
|
|
1089
|
+
"--shk-emerald-400": "#a78bfa",
|
|
1090
|
+
"--shk-emerald-600": "#7c3aed",
|
|
1091
|
+
"--shk-emerald-700": "#6d28d9"
|
|
1092
|
+
}
|
|
665
1093
|
},
|
|
666
1094
|
{
|
|
667
1095
|
name: "sunset",
|
|
668
|
-
label: "
|
|
1096
|
+
label: "Sunset",
|
|
1097
|
+
labelKey: "theme.presets.sunset",
|
|
669
1098
|
primary: "#ea580c",
|
|
670
|
-
surface: "stone"
|
|
1099
|
+
surface: "stone",
|
|
1100
|
+
vars: {
|
|
1101
|
+
"--shk-primary-50": "#fff7ed",
|
|
1102
|
+
"--shk-primary-100": "#ffedd5",
|
|
1103
|
+
"--shk-primary-200": "#fed7aa",
|
|
1104
|
+
"--shk-primary-300": "#fdba74",
|
|
1105
|
+
"--shk-primary-400": "#fb923c",
|
|
1106
|
+
"--shk-primary-500": "#f97316",
|
|
1107
|
+
"--shk-primary-600": "#ea580c",
|
|
1108
|
+
"--shk-primary-700": "#c2410c",
|
|
1109
|
+
"--shk-primary-800": "#9a3412",
|
|
1110
|
+
"--shk-primary-900": "#7c2d12",
|
|
1111
|
+
"--shk-primary-950": "#431407",
|
|
1112
|
+
"--shk-surface-50": "#fafaf9",
|
|
1113
|
+
"--shk-surface-100": "#f5f5f4",
|
|
1114
|
+
"--shk-surface-200": "#e7e5e4",
|
|
1115
|
+
"--shk-surface-300": "#d6d3d1",
|
|
1116
|
+
"--shk-surface-400": "#a8a29e",
|
|
1117
|
+
"--shk-surface-500": "#78716c",
|
|
1118
|
+
"--shk-surface-600": "#57534e",
|
|
1119
|
+
"--shk-surface-700": "#44403c",
|
|
1120
|
+
"--shk-surface-800": "#292524",
|
|
1121
|
+
"--shk-surface-900": "#1c1917",
|
|
1122
|
+
"--shk-emerald-400": "#fb923c",
|
|
1123
|
+
"--shk-emerald-600": "#ea580c",
|
|
1124
|
+
"--shk-emerald-700": "#c2410c",
|
|
1125
|
+
"--shk-scrollbar-thumb": "#d6d3d1",
|
|
1126
|
+
"--shk-scrollbar-thumb-hover": "#a8a29e"
|
|
1127
|
+
},
|
|
1128
|
+
darkVars: {
|
|
1129
|
+
"--shk-surface-50": "#1c1917",
|
|
1130
|
+
"--shk-surface-100": "#292524",
|
|
1131
|
+
"--shk-surface-200": "#44403c",
|
|
1132
|
+
"--shk-surface-300": "#57534e",
|
|
1133
|
+
"--shk-surface-400": "#78716c",
|
|
1134
|
+
"--shk-surface-500": "#a8a29e",
|
|
1135
|
+
"--shk-surface-600": "#d6d3d1",
|
|
1136
|
+
"--shk-surface-700": "#e7e5e4",
|
|
1137
|
+
"--shk-surface-800": "#f5f5f4",
|
|
1138
|
+
"--shk-surface-900": "#fafaf9",
|
|
1139
|
+
"--shk-scrollbar-thumb": "#57534e",
|
|
1140
|
+
"--shk-scrollbar-thumb-hover": "#78716c"
|
|
1141
|
+
}
|
|
671
1142
|
}
|
|
672
1143
|
];
|
|
673
1144
|
const SHK_THEME_PRESETS = new InjectionToken("SHK_THEME_PRESETS", {
|
|
@@ -675,6 +1146,8 @@ const SHK_THEME_PRESETS = new InjectionToken("SHK_THEME_PRESETS", {
|
|
|
675
1146
|
factory: () => BUILT_IN_PRESETS
|
|
676
1147
|
});
|
|
677
1148
|
const SURFACE_ATTRIBUTE = "data-shk-surface";
|
|
1149
|
+
const PRIMARY_ATTRIBUTE = "data-shk-primary";
|
|
1150
|
+
const RETIRED_THEMES = ["rose"];
|
|
678
1151
|
function feature(value, extra = []) {
|
|
679
1152
|
return { ɵproviders: [{
|
|
680
1153
|
provide: SHK_CONFIG_FEATURES,
|
|
@@ -688,7 +1161,12 @@ function defaultsOf(module, values) {
|
|
|
688
1161
|
return out;
|
|
689
1162
|
}
|
|
690
1163
|
function provideShk(...features) {
|
|
691
|
-
|
|
1164
|
+
const provided = features.flatMap((f) => f.ɵproviders);
|
|
1165
|
+
const defaults = provided.some((provider) => provider.provide === SHK_CONFIG_PERSISTENCE) ? [] : [{
|
|
1166
|
+
provide: SHK_CONFIG_PERSISTENCE,
|
|
1167
|
+
useValue: { storageKey: "shk-config" }
|
|
1168
|
+
}];
|
|
1169
|
+
return makeEnvironmentProviders([...defaults, ...provided]);
|
|
692
1170
|
}
|
|
693
1171
|
function withDates(config) {
|
|
694
1172
|
return feature({ defaults: defaultsOf("dates", config) });
|
|
@@ -697,77 +1175,96 @@ function withNumbers(config) {
|
|
|
697
1175
|
return feature({ defaults: defaultsOf("numbers", config) });
|
|
698
1176
|
}
|
|
699
1177
|
function withTheme(config = {}) {
|
|
700
|
-
const { themes = {}, primary = "", surface = "", ...themeConfig } = config;
|
|
1178
|
+
const { themes = {}, primary = "", surface = "", scope = "device", ...themeConfig } = config;
|
|
701
1179
|
const resolved = {
|
|
702
1180
|
...DEFAULT_SHK_THEME_CONFIG,
|
|
703
1181
|
...themeConfig
|
|
704
1182
|
};
|
|
705
1183
|
const custom = Object.entries(themes).map(([name, theme]) => [name, normalizeCustomTheme(name, theme)]);
|
|
706
1184
|
if (primary) assertHexColor(primary, "withTheme({ primary })");
|
|
707
|
-
const
|
|
1185
|
+
const customPresets = custom.map(([name, theme]) => ({
|
|
1186
|
+
...theme,
|
|
708
1187
|
name,
|
|
709
1188
|
label: theme.label ?? name,
|
|
1189
|
+
labelKey: theme.labelKey ?? `theme.presets.${name}`,
|
|
710
1190
|
primary: theme.primary,
|
|
711
|
-
surface: ""
|
|
712
|
-
}))
|
|
1191
|
+
surface: theme.surface ?? ""
|
|
1192
|
+
}));
|
|
1193
|
+
const presets = [...BUILT_IN_PRESETS, ...customPresets];
|
|
1194
|
+
const generated = [...BUILT_IN_PRESETS, ...customPresets].filter((preset) => preset.name !== "default");
|
|
713
1195
|
return feature({ options: [
|
|
714
1196
|
{
|
|
715
1197
|
key: "theme.name",
|
|
716
1198
|
module: "theme",
|
|
717
1199
|
type: "select",
|
|
718
1200
|
default: resolved.defaultTheme,
|
|
719
|
-
label: "
|
|
720
|
-
|
|
1201
|
+
label: "Theme",
|
|
1202
|
+
labelKey: "theme.options.name",
|
|
1203
|
+
description: "Color palette of the interface.",
|
|
1204
|
+
descriptionKey: "theme.options.nameDescription",
|
|
721
1205
|
choices: presets.map((preset) => ({
|
|
722
1206
|
value: preset.name,
|
|
723
|
-
label: preset.label
|
|
1207
|
+
label: preset.label,
|
|
1208
|
+
labelKey: preset.labelKey
|
|
724
1209
|
})),
|
|
725
|
-
|
|
1210
|
+
scope
|
|
726
1211
|
},
|
|
727
1212
|
{
|
|
728
1213
|
key: "theme.scheme",
|
|
729
1214
|
module: "theme",
|
|
730
1215
|
type: "select",
|
|
731
1216
|
default: resolved.defaultScheme,
|
|
732
|
-
label: "
|
|
1217
|
+
label: "Mode",
|
|
1218
|
+
labelKey: "theme.options.scheme",
|
|
733
1219
|
choices: [
|
|
734
1220
|
{
|
|
735
1221
|
value: "system",
|
|
736
|
-
label: "
|
|
1222
|
+
label: "System",
|
|
1223
|
+
labelKey: "theme.schemes.system"
|
|
737
1224
|
},
|
|
738
1225
|
{
|
|
739
1226
|
value: "light",
|
|
740
|
-
label: "
|
|
1227
|
+
label: "Light",
|
|
1228
|
+
labelKey: "theme.schemes.light"
|
|
741
1229
|
},
|
|
742
1230
|
{
|
|
743
1231
|
value: "dark",
|
|
744
|
-
label: "
|
|
1232
|
+
label: "Dark",
|
|
1233
|
+
labelKey: "theme.schemes.dark"
|
|
745
1234
|
}
|
|
746
1235
|
],
|
|
747
|
-
|
|
1236
|
+
scope: "device"
|
|
748
1237
|
},
|
|
749
1238
|
{
|
|
750
1239
|
key: "theme.primary",
|
|
751
1240
|
module: "theme",
|
|
752
1241
|
type: "color",
|
|
753
1242
|
default: primary,
|
|
754
|
-
label: "
|
|
755
|
-
|
|
1243
|
+
label: "Primary color",
|
|
1244
|
+
labelKey: "theme.options.primary",
|
|
1245
|
+
description: "Overrides the theme's primary color. Empty = the theme's own.",
|
|
1246
|
+
descriptionKey: "theme.options.primaryDescription",
|
|
1247
|
+
scope
|
|
756
1248
|
},
|
|
757
1249
|
{
|
|
758
1250
|
key: "theme.surface",
|
|
759
1251
|
module: "theme",
|
|
760
1252
|
type: "select",
|
|
761
1253
|
default: surface,
|
|
762
|
-
label: "
|
|
763
|
-
|
|
1254
|
+
label: "Surface",
|
|
1255
|
+
labelKey: "theme.options.surface",
|
|
1256
|
+
description: "Greys for backgrounds, borders and text. Empty = the theme's own.",
|
|
1257
|
+
descriptionKey: "theme.options.surfaceDescription",
|
|
764
1258
|
choices: [{
|
|
765
1259
|
value: "",
|
|
766
|
-
label: "
|
|
1260
|
+
label: "The theme's own",
|
|
1261
|
+
labelKey: "theme.surfaces.theme"
|
|
767
1262
|
}, ...Object.entries(SURFACE_PALETTES).map(([value, { label }]) => ({
|
|
768
1263
|
value,
|
|
769
|
-
label
|
|
770
|
-
|
|
1264
|
+
label,
|
|
1265
|
+
labelKey: `theme.surfaces.${value}`
|
|
1266
|
+
}))],
|
|
1267
|
+
scope
|
|
771
1268
|
}
|
|
772
1269
|
] }, [
|
|
773
1270
|
{
|
|
@@ -783,7 +1280,11 @@ function withTheme(config = {}) {
|
|
|
783
1280
|
const themeService = inject(ShkThemeService);
|
|
784
1281
|
const configService = inject(ShkConfigService);
|
|
785
1282
|
const nonce = inject(CSP_NONCE, { optional: true });
|
|
786
|
-
const css = [
|
|
1283
|
+
const css = [
|
|
1284
|
+
defaultDarkPrimaryCss(),
|
|
1285
|
+
surfaceCss(SURFACE_ATTRIBUTE),
|
|
1286
|
+
...generated.map((preset) => customThemeCss(preset.name, preset, resolved.attribute))
|
|
1287
|
+
].join("\n");
|
|
787
1288
|
let style = doc.head?.querySelector("style[data-shk-themes]");
|
|
788
1289
|
if (!style && doc.head) {
|
|
789
1290
|
style = doc.createElement("style");
|
|
@@ -792,28 +1293,53 @@ function withTheme(config = {}) {
|
|
|
792
1293
|
doc.head.appendChild(style);
|
|
793
1294
|
}
|
|
794
1295
|
if (style) style.textContent = css;
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
1296
|
+
let primaryStyle = doc.head?.querySelector("style[data-shk-primary-css]");
|
|
1297
|
+
if (!primaryStyle && doc.head) {
|
|
1298
|
+
primaryStyle = doc.createElement("style");
|
|
1299
|
+
primaryStyle.setAttribute("data-shk-primary-css", "");
|
|
1300
|
+
if (nonce) primaryStyle.setAttribute("nonce", nonce);
|
|
1301
|
+
doc.head.appendChild(primaryStyle);
|
|
1302
|
+
}
|
|
1303
|
+
migrateLegacyTheme(doc, configService, resolved);
|
|
1304
|
+
configService.apply("theme.name", (name) => themeService.setTheme(name));
|
|
1305
|
+
configService.apply("theme.scheme", (scheme) => themeService.setScheme(scheme));
|
|
803
1306
|
const root = doc.documentElement;
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
if (color)
|
|
807
|
-
else
|
|
1307
|
+
configService.apply("theme.primary", (color) => {
|
|
1308
|
+
if (primaryStyle) primaryStyle.textContent = color ? primaryOverrideCss(color, PRIMARY_ATTRIBUTE) : "";
|
|
1309
|
+
if (color) root.setAttribute(PRIMARY_ATTRIBUTE, "");
|
|
1310
|
+
else root.removeAttribute(PRIMARY_ATTRIBUTE);
|
|
808
1311
|
});
|
|
809
|
-
|
|
810
|
-
const palette = configService.get("theme.surface")();
|
|
1312
|
+
configService.apply("theme.surface", (palette) => {
|
|
811
1313
|
if (palette) root.setAttribute(SURFACE_ATTRIBUTE, palette);
|
|
812
1314
|
else root.removeAttribute(SURFACE_ATTRIBUTE);
|
|
813
1315
|
});
|
|
814
1316
|
})
|
|
815
1317
|
]);
|
|
816
1318
|
}
|
|
1319
|
+
function migrateLegacyTheme(doc, configService, resolved) {
|
|
1320
|
+
const storage = doc.defaultView?.localStorage;
|
|
1321
|
+
if (!storage) return;
|
|
1322
|
+
const legacyTheme = readItem(storage, resolved.storageKey);
|
|
1323
|
+
const legacyScheme = readItem(storage, resolved.schemeStorageKey);
|
|
1324
|
+
if (legacyTheme && !RETIRED_THEMES.includes(legacyTheme) && configService.value("theme.name") === resolved.defaultTheme) try {
|
|
1325
|
+
configService.set("theme.name", legacyTheme);
|
|
1326
|
+
} catch {}
|
|
1327
|
+
if ((legacyScheme === "light" || legacyScheme === "dark" || legacyScheme === "system") && configService.value("theme.scheme") === resolved.defaultScheme) configService.set("theme.scheme", legacyScheme);
|
|
1328
|
+
removeItem(storage, resolved.storageKey);
|
|
1329
|
+
removeItem(storage, resolved.schemeStorageKey);
|
|
1330
|
+
}
|
|
1331
|
+
function readItem(storage, key) {
|
|
1332
|
+
try {
|
|
1333
|
+
return storage.getItem(key);
|
|
1334
|
+
} catch {
|
|
1335
|
+
return null;
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
function removeItem(storage, key) {
|
|
1339
|
+
try {
|
|
1340
|
+
storage.removeItem(key);
|
|
1341
|
+
} catch {}
|
|
1342
|
+
}
|
|
817
1343
|
function withOptions(options) {
|
|
818
1344
|
return feature({ options });
|
|
819
1345
|
}
|
|
@@ -823,6 +1349,18 @@ function withPersistence(config = {}) {
|
|
|
823
1349
|
useValue: { storageKey: config.storageKey ?? "shk-config" }
|
|
824
1350
|
}] };
|
|
825
1351
|
}
|
|
1352
|
+
function withSharedConfig(store) {
|
|
1353
|
+
return { ɵproviders: [typeof store === "object" && store !== null && "provide" in store ? store : {
|
|
1354
|
+
provide: SHK_CONFIG_STORE,
|
|
1355
|
+
useValue: store
|
|
1356
|
+
}] };
|
|
1357
|
+
}
|
|
1358
|
+
function withLabels(labels) {
|
|
1359
|
+
return { ɵproviders: [{
|
|
1360
|
+
provide: SHK_LABEL_OVERRIDES,
|
|
1361
|
+
useValue: labels
|
|
1362
|
+
}] };
|
|
1363
|
+
}
|
|
826
1364
|
const formatterCache = /* @__PURE__ */ new Map();
|
|
827
1365
|
function dateFormatter(locale, options) {
|
|
828
1366
|
const key = `d|${locale}|${JSON.stringify(options)}`;
|
|
@@ -971,6 +1509,6 @@ function numberSeparators(locale) {
|
|
|
971
1509
|
group: parts.find((p) => p.type === "group")?.value ?? ","
|
|
972
1510
|
};
|
|
973
1511
|
}
|
|
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 };
|
|
1512
|
+
export { BUILT_IN_PRESETS, DATE_OPTIONS, DEFAULT_PRIMARY, NUMBER_OPTIONS, PRIMARY_VARS, SHK_CONFIG_FEATURES, SHK_CONFIG_PERSISTENCE, SHK_CONFIG_STORE, SHK_LABEL_OVERRIDES, SHK_THEME_PRESETS, SURFACE_PALETTES, ShkConfigConflictError, ShkConfigService, ShkConfigSync, ShkLabels, configRevision, currencyDecimals, currencySymbol, formatCurrency, formatDate, formatDateStyle, formatNumber, numberSeparators, primaryScale, primaryScaleDark, provideShk, resolveDateFormat, toDate, typedDateLayout, withDates, withLabels, withNumbers, withOptions, withPersistence, withSharedConfig, withTheme };
|
|
975
1513
|
|
|
976
1514
|
//# sourceMappingURL=shirkasoft-ui-components-config.mjs.map
|