shirkasoft-ui-components 1.14.0 → 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 +4 -8
- 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 +363 -69
- 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 +905 -843
- package/fesm2022/shirkasoft-ui-components-config.mjs.map +1 -1
- 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 -1440
- 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 -300
- package/fesm2022/shirkasoft-ui-components-file-upload.mjs.map +1 -1
- package/fesm2022/shirkasoft-ui-components-icons.mjs +1028 -533
- package/fesm2022/shirkasoft-ui-components-icons.mjs.map +1 -1
- package/fesm2022/shirkasoft-ui-components-knob.mjs +389 -201
- 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 -314
- 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 -327
- 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 -819
- 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 +1916 -1698
- package/fesm2022/shirkasoft-ui-components-table.mjs.map +1 -1
- package/fesm2022/shirkasoft-ui-components-tabs.mjs +419 -175
- package/fesm2022/shirkasoft-ui-components-tabs.mjs.map +1 -1
- package/fesm2022/shirkasoft-ui-components-tag.mjs +175 -49
- package/fesm2022/shirkasoft-ui-components-tag.mjs.map +1 -1
- package/fesm2022/shirkasoft-ui-components-text-field.mjs +687 -402
- package/fesm2022/shirkasoft-ui-components-text-field.mjs.map +1 -1
- package/fesm2022/shirkasoft-ui-components-theme-picker.mjs +310 -124
- package/fesm2022/shirkasoft-ui-components-theme-picker.mjs.map +1 -1
- package/fesm2022/shirkasoft-ui-components-theme.mjs +141 -174
- package/fesm2022/shirkasoft-ui-components-theme.mjs.map +1 -1
- package/fesm2022/shirkasoft-ui-components-timeline.mjs +791 -203
- package/fesm2022/shirkasoft-ui-components-timeline.mjs.map +1 -1
- package/fesm2022/shirkasoft-ui-components-toggle.mjs +179 -109
- 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 +95 -134
- package/fesm2022/shirkasoft-ui-components-utils.mjs.map +1 -1
- package/fesm2022/shirkasoft-ui-components-wizard.mjs +673 -165
- package/fesm2022/shirkasoft-ui-components-wizard.mjs.map +1 -1
- package/fesm2022/shirkasoft-ui-components.mjs +0 -9
- package/package.json +5 -5
- 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 +193 -204
- package/types/shirkasoft-ui-components-confirm-dialog.d.ts +107 -66
- package/types/shirkasoft-ui-components-date-picker.d.ts +527 -398
- package/types/shirkasoft-ui-components-fieldset.d.ts +135 -60
- package/types/shirkasoft-ui-components-file-upload.d.ts +176 -112
- package/types/shirkasoft-ui-components-icons.d.ts +1302 -1294
- package/types/shirkasoft-ui-components-knob.d.ts +144 -78
- package/types/shirkasoft-ui-components-loading.d.ts +155 -64
- package/types/shirkasoft-ui-components-modal.d.ts +134 -136
- package/types/shirkasoft-ui-components-notification.d.ts +63 -59
- package/types/shirkasoft-ui-components-price-input.d.ts +198 -113
- package/types/shirkasoft-ui-components-rail-sidebar.d.ts +262 -142
- package/types/shirkasoft-ui-components-select.d.ts +301 -196
- package/types/shirkasoft-ui-components-sidebar.d.ts +198 -93
- package/types/shirkasoft-ui-components-skeleton.d.ts +68 -27
- package/types/shirkasoft-ui-components-table.d.ts +849 -660
- 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 -127
- package/types/shirkasoft-ui-components-theme-picker.d.ts +92 -58
- package/types/shirkasoft-ui-components-theme.d.ts +56 -64
- package/types/shirkasoft-ui-components-timeline.d.ts +325 -150
- package/types/shirkasoft-ui-components-toggle.d.ts +73 -49
- package/types/shirkasoft-ui-components-tooltip.d.ts +64 -43
- package/types/shirkasoft-ui-components-utils.d.ts +15 -16
- package/types/shirkasoft-ui-components-wizard.d.ts +236 -87
- package/types/shirkasoft-ui-components.d.ts +1 -2
- package/fesm2022/shirkasoft-ui-components.mjs.map +0 -1
|
@@ -1,180 +1,147 @@
|
|
|
1
|
-
import * as i0 from
|
|
2
|
-
import {
|
|
3
|
-
import { DOCUMENT } from
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { Injectable, InjectionToken, computed, inject, makeEnvironmentProviders, provideAppInitializer, signal } from "@angular/core";
|
|
3
|
+
import { DOCUMENT } from "@angular/common";
|
|
4
|
+
const SHK_THEMES = [
|
|
5
|
+
"default",
|
|
6
|
+
"ocean",
|
|
7
|
+
"violet",
|
|
8
|
+
"sunset"
|
|
9
|
+
];
|
|
6
10
|
const DEFAULT_SHK_THEME_CONFIG = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
defaultTheme: "default",
|
|
12
|
+
defaultScheme: "system",
|
|
13
|
+
persist: true,
|
|
14
|
+
storageKey: "shk-theme",
|
|
15
|
+
schemeStorageKey: "shk-scheme",
|
|
16
|
+
attribute: "data-shk-theme",
|
|
17
|
+
darkClass: "dark"
|
|
14
18
|
};
|
|
15
|
-
const SHK_THEME_CONFIG = new InjectionToken(
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
const SHK_THEME_CONFIG = new InjectionToken("SHK_THEME_CONFIG", {
|
|
20
|
+
providedIn: "root",
|
|
21
|
+
factory: () => DEFAULT_SHK_THEME_CONFIG
|
|
22
|
+
});
|
|
23
|
+
const DARK_QUERY = "(prefers-color-scheme: dark)";
|
|
24
|
+
const RETIRED_THEMES = ["rose"];
|
|
25
|
+
var ShkThemeService = class ShkThemeService {
|
|
26
|
+
constructor() {
|
|
27
|
+
this.doc = inject(DOCUMENT);
|
|
28
|
+
this.config = inject(SHK_THEME_CONFIG);
|
|
29
|
+
this.win = this.doc.defaultView;
|
|
30
|
+
this.availableThemes = SHK_THEMES;
|
|
31
|
+
this.theme = signal(this.config.defaultTheme, ...ngDevMode ? [{ debugName: "theme" }] : /* istanbul ignore next */ []);
|
|
32
|
+
this.scheme = signal(this.config.defaultScheme, ...ngDevMode ? [{ debugName: "scheme" }] : /* istanbul ignore next */ []);
|
|
33
|
+
this.isDark = signal(false, ...ngDevMode ? [{ debugName: "isDark" }] : /* istanbul ignore next */ []);
|
|
34
|
+
this.isSystem = computed(() => this.scheme() === "system", ...ngDevMode ? [{ debugName: "isSystem" }] : /* istanbul ignore next */ []);
|
|
35
|
+
this.restore();
|
|
36
|
+
this.applyTheme(this.theme());
|
|
37
|
+
this.applyScheme(this.scheme());
|
|
38
|
+
this.watchSystem();
|
|
39
|
+
}
|
|
40
|
+
setTheme(theme) {
|
|
41
|
+
this.theme.set(theme);
|
|
42
|
+
this.applyTheme(theme);
|
|
43
|
+
this.persist(this.config.storageKey, theme);
|
|
44
|
+
}
|
|
45
|
+
setScheme(scheme) {
|
|
46
|
+
this.scheme.set(scheme);
|
|
47
|
+
this.applyScheme(scheme);
|
|
48
|
+
this.persist(this.config.schemeStorageKey, scheme);
|
|
49
|
+
}
|
|
50
|
+
toggleDark() {
|
|
51
|
+
this.setScheme(this.isDark() ? "light" : "dark");
|
|
52
|
+
}
|
|
53
|
+
previewTheme(theme) {
|
|
54
|
+
this.applyTheme(theme);
|
|
55
|
+
}
|
|
56
|
+
restore() {
|
|
57
|
+
if (!this.config.persist) return;
|
|
58
|
+
const storedTheme = this.read(this.config.storageKey);
|
|
59
|
+
if (storedTheme && !RETIRED_THEMES.includes(storedTheme)) this.theme.set(storedTheme);
|
|
60
|
+
const storedScheme = this.read(this.config.schemeStorageKey);
|
|
61
|
+
if (storedScheme === "light" || storedScheme === "dark" || storedScheme === "system") this.scheme.set(storedScheme);
|
|
62
|
+
}
|
|
63
|
+
applyTheme(theme) {
|
|
64
|
+
const root = this.doc?.documentElement;
|
|
65
|
+
if (!root) return;
|
|
66
|
+
if (theme === "default") root.removeAttribute(this.config.attribute);
|
|
67
|
+
else root.setAttribute(this.config.attribute, theme);
|
|
68
|
+
}
|
|
69
|
+
applyScheme(scheme) {
|
|
70
|
+
const root = this.doc?.documentElement;
|
|
71
|
+
if (!root) return;
|
|
72
|
+
const dark = scheme === "dark" || scheme === "system" && this.prefersDark();
|
|
73
|
+
root.classList.toggle(this.config.darkClass, dark);
|
|
74
|
+
root.style.colorScheme = dark ? "dark" : "light";
|
|
75
|
+
this.isDark.set(dark);
|
|
76
|
+
}
|
|
77
|
+
watchSystem() {
|
|
78
|
+
if (!this.win?.matchMedia) return;
|
|
79
|
+
this.mediaQuery ??= this.win.matchMedia(DARK_QUERY);
|
|
80
|
+
const onChange = (event) => {
|
|
81
|
+
if (this.scheme() !== "system") return;
|
|
82
|
+
this.applyScheme(event.matches ? "dark" : "light");
|
|
83
|
+
};
|
|
84
|
+
if (this.mediaQuery.addEventListener) this.mediaQuery.addEventListener("change", onChange);
|
|
85
|
+
else this.mediaQuery.addListener(onChange);
|
|
86
|
+
}
|
|
87
|
+
prefersDark() {
|
|
88
|
+
return this.win?.matchMedia?.(DARK_QUERY).matches ?? false;
|
|
89
|
+
}
|
|
90
|
+
read(key) {
|
|
91
|
+
try {
|
|
92
|
+
return this.win?.localStorage?.getItem(key) ?? null;
|
|
93
|
+
} catch {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
persist(key, value) {
|
|
98
|
+
if (!this.config.persist) return;
|
|
99
|
+
try {
|
|
100
|
+
this.win?.localStorage?.setItem(key, value);
|
|
101
|
+
} catch {}
|
|
102
|
+
}
|
|
103
|
+
static {
|
|
104
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
105
|
+
minVersion: "12.0.0",
|
|
106
|
+
version: "22.3.2",
|
|
107
|
+
ngImport: i0,
|
|
108
|
+
type: ShkThemeService,
|
|
109
|
+
deps: [],
|
|
110
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
static {
|
|
114
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
115
|
+
minVersion: "12.0.0",
|
|
116
|
+
version: "22.3.2",
|
|
117
|
+
ngImport: i0,
|
|
118
|
+
type: ShkThemeService,
|
|
119
|
+
providedIn: "root"
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
124
|
+
minVersion: "12.0.0",
|
|
125
|
+
version: "22.3.2",
|
|
126
|
+
ngImport: i0,
|
|
127
|
+
type: ShkThemeService,
|
|
128
|
+
decorators: [{
|
|
129
|
+
type: Injectable,
|
|
130
|
+
args: [{ providedIn: "root" }]
|
|
131
|
+
}],
|
|
132
|
+
ctorParameters: () => []
|
|
18
133
|
});
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Shirkasoft UI Components.
|
|
22
|
-
* Authors: Roberto Valladares Martin (Ansem13), Julio César García García (Sanjuli14).
|
|
23
|
-
* Belongs to Shirkasoft.
|
|
24
|
-
*/
|
|
25
|
-
const DARK_QUERY = '(prefers-color-scheme: dark)';
|
|
26
|
-
/** Theme packs removed in previous releases; a stored value falls back to the default. */
|
|
27
|
-
const RETIRED_THEMES = ['rose'];
|
|
28
|
-
/**
|
|
29
|
-
* Applies and persists the color theme.
|
|
30
|
-
*
|
|
31
|
-
* Themes are plain CSS custom properties, so switching a theme is just an
|
|
32
|
-
* attribute change on `<html>` — no component re-render involved.
|
|
33
|
-
*/
|
|
34
|
-
class ShkThemeService {
|
|
35
|
-
constructor() {
|
|
36
|
-
this.doc = inject(DOCUMENT);
|
|
37
|
-
this.config = inject(SHK_THEME_CONFIG);
|
|
38
|
-
this.win = this.doc.defaultView;
|
|
39
|
-
/** Every theme name the service knows about. */
|
|
40
|
-
this.availableThemes = SHK_THEMES;
|
|
41
|
-
/** Currently active theme. */
|
|
42
|
-
this.theme = signal(this.config.defaultTheme, ...(ngDevMode ? [{ debugName: "theme" }] : /* istanbul ignore next */ []));
|
|
43
|
-
/** Currently selected scheme (`light`, `dark` or `system`). */
|
|
44
|
-
this.scheme = signal(this.config.defaultScheme, ...(ngDevMode ? [{ debugName: "scheme" }] : /* istanbul ignore next */ []));
|
|
45
|
-
/** `true` when dark colors are being applied. */
|
|
46
|
-
this.isDark = signal(false, ...(ngDevMode ? [{ debugName: "isDark" }] : /* istanbul ignore next */ []));
|
|
47
|
-
/** Convenience flag for templates. */
|
|
48
|
-
this.isSystem = computed(() => this.scheme() === 'system', ...(ngDevMode ? [{ debugName: "isSystem" }] : /* istanbul ignore next */ []));
|
|
49
|
-
this.restore();
|
|
50
|
-
this.applyTheme(this.theme());
|
|
51
|
-
this.applyScheme(this.scheme());
|
|
52
|
-
this.watchSystem();
|
|
53
|
-
}
|
|
54
|
-
/** Switches the active theme pack. */
|
|
55
|
-
setTheme(theme) {
|
|
56
|
-
this.theme.set(theme);
|
|
57
|
-
this.applyTheme(theme);
|
|
58
|
-
this.persist(this.config.storageKey, theme);
|
|
59
|
-
}
|
|
60
|
-
/** Selects light, dark or system scheme. */
|
|
61
|
-
setScheme(scheme) {
|
|
62
|
-
this.scheme.set(scheme);
|
|
63
|
-
this.applyScheme(scheme);
|
|
64
|
-
this.persist(this.config.schemeStorageKey, scheme);
|
|
65
|
-
}
|
|
66
|
-
/** Flips between light and dark (leaves `system` on the opposite value). */
|
|
67
|
-
toggleDark() {
|
|
68
|
-
this.setScheme(this.isDark() ? 'light' : 'dark');
|
|
69
|
-
}
|
|
70
|
-
/** Applies a theme without persisting it (useful for previews). */
|
|
71
|
-
previewTheme(theme) {
|
|
72
|
-
this.applyTheme(theme);
|
|
73
|
-
}
|
|
74
|
-
restore() {
|
|
75
|
-
if (!this.config.persist)
|
|
76
|
-
return;
|
|
77
|
-
const storedTheme = this.read(this.config.storageKey);
|
|
78
|
-
if (storedTheme && !RETIRED_THEMES.includes(storedTheme))
|
|
79
|
-
this.theme.set(storedTheme);
|
|
80
|
-
const storedScheme = this.read(this.config.schemeStorageKey);
|
|
81
|
-
if (storedScheme === 'light' || storedScheme === 'dark' || storedScheme === 'system') {
|
|
82
|
-
this.scheme.set(storedScheme);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
applyTheme(theme) {
|
|
86
|
-
const root = this.doc?.documentElement;
|
|
87
|
-
if (!root)
|
|
88
|
-
return;
|
|
89
|
-
if (theme === 'default') {
|
|
90
|
-
root.removeAttribute(this.config.attribute);
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
root.setAttribute(this.config.attribute, theme);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
applyScheme(scheme) {
|
|
97
|
-
const root = this.doc?.documentElement;
|
|
98
|
-
if (!root)
|
|
99
|
-
return;
|
|
100
|
-
const dark = scheme === 'dark' || (scheme === 'system' && this.prefersDark());
|
|
101
|
-
root.classList.toggle(this.config.darkClass, dark);
|
|
102
|
-
root.style.colorScheme = dark ? 'dark' : 'light';
|
|
103
|
-
this.isDark.set(dark);
|
|
104
|
-
}
|
|
105
|
-
watchSystem() {
|
|
106
|
-
if (!this.win?.matchMedia)
|
|
107
|
-
return;
|
|
108
|
-
this.mediaQuery ??= this.win.matchMedia(DARK_QUERY);
|
|
109
|
-
const onChange = (event) => {
|
|
110
|
-
if (this.scheme() !== 'system')
|
|
111
|
-
return;
|
|
112
|
-
this.applyScheme(event.matches ? 'dark' : 'light');
|
|
113
|
-
};
|
|
114
|
-
// Safari < 14 only supports addListener.
|
|
115
|
-
if (this.mediaQuery.addEventListener) {
|
|
116
|
-
this.mediaQuery.addEventListener('change', onChange);
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
this.mediaQuery.addListener(onChange);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
prefersDark() {
|
|
123
|
-
return this.win?.matchMedia?.(DARK_QUERY).matches ?? false;
|
|
124
|
-
}
|
|
125
|
-
read(key) {
|
|
126
|
-
try {
|
|
127
|
-
return this.win?.localStorage?.getItem(key) ?? null;
|
|
128
|
-
}
|
|
129
|
-
catch {
|
|
130
|
-
return null;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
persist(key, value) {
|
|
134
|
-
if (!this.config.persist)
|
|
135
|
-
return;
|
|
136
|
-
try {
|
|
137
|
-
this.win?.localStorage?.setItem(key, value);
|
|
138
|
-
}
|
|
139
|
-
catch {
|
|
140
|
-
// Storage can be blocked (private mode, iframe, quota). Theme still applies.
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.27", ngImport: i0, type: ShkThemeService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
144
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.27", ngImport: i0, type: ShkThemeService, providedIn: 'root' }); }
|
|
145
|
-
}
|
|
146
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.27", ngImport: i0, type: ShkThemeService, decorators: [{
|
|
147
|
-
type: Injectable,
|
|
148
|
-
args: [{ providedIn: 'root' }]
|
|
149
|
-
}], ctorParameters: () => [] });
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Shirkasoft UI Components.
|
|
153
|
-
* Authors: Roberto Valladares Martin (Ansem13), Julio César García García (Sanjuli14).
|
|
154
|
-
* Belongs to Shirkasoft.
|
|
155
|
-
*/
|
|
156
|
-
/**
|
|
157
|
-
* Configures the theme system and applies the stored/default theme while the
|
|
158
|
-
* app boots, so it is active even if nothing injects `ShkThemeService`.
|
|
159
|
-
*
|
|
160
|
-
* ```ts
|
|
161
|
-
* bootstrapApplication(App, {
|
|
162
|
-
* providers: [provideShkTheme({ defaultTheme: 'ocean', defaultScheme: 'dark' })],
|
|
163
|
-
* });
|
|
164
|
-
* ```
|
|
165
|
-
*/
|
|
166
134
|
function provideShkTheme(config = {}) {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
135
|
+
return makeEnvironmentProviders([{
|
|
136
|
+
provide: SHK_THEME_CONFIG,
|
|
137
|
+
useValue: {
|
|
138
|
+
...DEFAULT_SHK_THEME_CONFIG,
|
|
139
|
+
...config
|
|
140
|
+
}
|
|
141
|
+
}, provideAppInitializer(() => {
|
|
142
|
+
inject(ShkThemeService);
|
|
143
|
+
})]);
|
|
173
144
|
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Generated bundle index. Do not edit.
|
|
177
|
-
*/
|
|
178
|
-
|
|
179
145
|
export { DEFAULT_SHK_THEME_CONFIG, SHK_THEMES, SHK_THEME_CONFIG, ShkThemeService, provideShkTheme };
|
|
180
|
-
|
|
146
|
+
|
|
147
|
+
//# sourceMappingURL=shirkasoft-ui-components-theme.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shirkasoft-ui-components-theme.mjs","sources":["../../../projects/ui-components/theme/theme.config.ts","../../../projects/ui-components/theme/theme.service.ts","../../../projects/ui-components/theme/theme.providers.ts","../../../projects/ui-components/theme/shirkasoft-ui-components-theme.ts"],"sourcesContent":["import { InjectionToken } from '@angular/core';\n\n/** Built-in theme packs shipped with the library. */\nexport type ShkThemeName = 'default' | 'ocean' | 'violet' | 'sunset' | (string & {});\n\n/** Color scheme selection. `system` follows `prefers-color-scheme`. */\nexport type ShkColorScheme = 'light' | 'dark' | 'system';\n\nexport interface ShkThemeConfig {\n /** Theme applied when nothing is stored yet. Defaults to `default`. */\n defaultTheme?: ShkThemeName;\n /** Scheme applied when nothing is stored yet. Defaults to `system`. */\n defaultScheme?: ShkColorScheme;\n /** Persist the selection in localStorage. Defaults to `true`. */\n persist?: boolean;\n /** localStorage keys. */\n storageKey?: string;\n schemeStorageKey?: string;\n /** Attribute written on <html>. Defaults to `data-shk-theme`. */\n attribute?: string;\n /** Class toggled on <html> for dark mode. Defaults to `dark`. */\n darkClass?: string;\n}\n\nexport type ResolvedShkThemeConfig = Required<ShkThemeConfig>;\n\nexport const SHK_THEMES: readonly ShkThemeName[] = ['default', 'ocean', 'violet', 'sunset'];\n\nexport const DEFAULT_SHK_THEME_CONFIG: ResolvedShkThemeConfig = {\n defaultTheme: 'default',\n defaultScheme: 'system',\n persist: true,\n storageKey: 'shk-theme',\n schemeStorageKey: 'shk-scheme',\n attribute: 'data-shk-theme',\n darkClass: 'dark',\n};\n\nexport const SHK_THEME_CONFIG = new InjectionToken<ResolvedShkThemeConfig>('SHK_THEME_CONFIG', {\n providedIn: 'root',\n factory: () => DEFAULT_SHK_THEME_CONFIG,\n});\n","/**\n * Shirkasoft UI Components.\n * Authors: Roberto Valladares Martin (Ansem13), Julio César García García (Sanjuli14).\n * Belongs to Shirkasoft.\n */\nimport { DOCUMENT } from '@angular/common';\nimport { Injectable, computed, inject, signal } from '@angular/core';\n\nimport {\n SHK_THEMES,\n SHK_THEME_CONFIG,\n ShkColorScheme,\n ShkThemeName,\n} from './theme.config';\n\nconst DARK_QUERY = '(prefers-color-scheme: dark)';\n\n/** Theme packs removed in previous releases; a stored value falls back to the default. */\nconst RETIRED_THEMES: readonly string[] = ['rose'];\n\n/**\n * Applies and persists the color theme.\n *\n * Themes are plain CSS custom properties, so switching a theme is just an\n * attribute change on `<html>` — no component re-render involved.\n */\n@Injectable({ providedIn: 'root' })\nexport class ShkThemeService {\n private readonly doc = inject(DOCUMENT);\n private readonly config = inject(SHK_THEME_CONFIG);\n private readonly win = this.doc.defaultView;\n\n /** Every theme name the service knows about. */\n readonly availableThemes = SHK_THEMES;\n\n /** Currently active theme. */\n readonly theme = signal<ShkThemeName>(this.config.defaultTheme);\n\n /** Currently selected scheme (`light`, `dark` or `system`). */\n readonly scheme = signal<ShkColorScheme>(this.config.defaultScheme);\n\n /** `true` when dark colors are being applied. */\n readonly isDark = signal(false);\n\n /** Convenience flag for templates. */\n readonly isSystem = computed(() => this.scheme() === 'system');\n\n private mediaQuery?: MediaQueryList;\n\n constructor() {\n this.restore();\n this.applyTheme(this.theme());\n this.applyScheme(this.scheme());\n this.watchSystem();\n }\n\n /** Switches the active theme pack. */\n setTheme(theme: ShkThemeName): void {\n this.theme.set(theme);\n this.applyTheme(theme);\n this.persist(this.config.storageKey, theme);\n }\n\n /** Selects light, dark or system scheme. */\n setScheme(scheme: ShkColorScheme): void {\n this.scheme.set(scheme);\n this.applyScheme(scheme);\n this.persist(this.config.schemeStorageKey, scheme);\n }\n\n /** Flips between light and dark (leaves `system` on the opposite value). */\n toggleDark(): void {\n this.setScheme(this.isDark() ? 'light' : 'dark');\n }\n\n /** Applies a theme without persisting it (useful for previews). */\n previewTheme(theme: ShkThemeName): void {\n this.applyTheme(theme);\n }\n\n private restore(): void {\n if (!this.config.persist) return;\n\n const storedTheme = this.read(this.config.storageKey);\n if (storedTheme && !RETIRED_THEMES.includes(storedTheme)) this.theme.set(storedTheme);\n\n const storedScheme = this.read(this.config.schemeStorageKey) as ShkColorScheme | null;\n if (storedScheme === 'light' || storedScheme === 'dark' || storedScheme === 'system') {\n this.scheme.set(storedScheme);\n }\n }\n\n private applyTheme(theme: ShkThemeName): void {\n const root = this.doc?.documentElement;\n if (!root) return;\n\n if (theme === 'default') {\n root.removeAttribute(this.config.attribute);\n } else {\n root.setAttribute(this.config.attribute, theme);\n }\n }\n\n private applyScheme(scheme: ShkColorScheme): void {\n const root = this.doc?.documentElement;\n if (!root) return;\n\n const dark = scheme === 'dark' || (scheme === 'system' && this.prefersDark());\n root.classList.toggle(this.config.darkClass, dark);\n root.style.colorScheme = dark ? 'dark' : 'light';\n this.isDark.set(dark);\n }\n\n private watchSystem(): void {\n if (!this.win?.matchMedia) return;\n\n this.mediaQuery ??= this.win.matchMedia(DARK_QUERY);\n const onChange = (event: MediaQueryListEvent) => {\n if (this.scheme() !== 'system') return;\n this.applyScheme(event.matches ? 'dark' : 'light');\n };\n\n // Safari < 14 only supports addListener.\n if (this.mediaQuery.addEventListener) {\n this.mediaQuery.addEventListener('change', onChange);\n } else {\n this.mediaQuery.addListener(onChange);\n }\n }\n\n private prefersDark(): boolean {\n return this.win?.matchMedia?.(DARK_QUERY).matches ?? false;\n }\n\n private read(key: string): string | null {\n try {\n return this.win?.localStorage?.getItem(key) ?? null;\n } catch {\n return null;\n }\n }\n\n private persist(key: string, value: string): void {\n if (!this.config.persist) return;\n\n try {\n this.win?.localStorage?.setItem(key, value);\n } catch {\n // Storage can be blocked (private mode, iframe, quota). Theme still applies.\n }\n }\n}\n","/**\n * Shirkasoft UI Components.\n * Authors: Roberto Valladares Martin (Ansem13), Julio César García García (Sanjuli14).\n * Belongs to Shirkasoft.\n */\nimport {\n EnvironmentProviders,\n inject,\n makeEnvironmentProviders,\n provideAppInitializer,\n} from '@angular/core';\n\nimport { DEFAULT_SHK_THEME_CONFIG, SHK_THEME_CONFIG, ShkThemeConfig } from './theme.config';\nimport { ShkThemeService } from './theme.service';\n\n/**\n * Configures the theme system and applies the stored/default theme while the\n * app boots, so it is active even if nothing injects `ShkThemeService`.\n *\n * ```ts\n * bootstrapApplication(App, {\n * providers: [provideShkTheme({ defaultTheme: 'ocean', defaultScheme: 'dark' })],\n * });\n * ```\n */\nexport function provideShkTheme(config: ShkThemeConfig = {}): EnvironmentProviders {\n return makeEnvironmentProviders([\n { provide: SHK_THEME_CONFIG, useValue: { ...DEFAULT_SHK_THEME_CONFIG, ...config } },\n provideAppInitializer(() => {\n inject(ShkThemeService);\n }),\n ]);\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;AA0BO,MAAM,UAAU,GAA4B,CAAC,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ;AAEnF,MAAM,wBAAwB,GAA2B;AAC9D,IAAA,YAAY,EAAE,SAAS;AACvB,IAAA,aAAa,EAAE,QAAQ;AACvB,IAAA,OAAO,EAAE,IAAI;AACb,IAAA,UAAU,EAAE,WAAW;AACvB,IA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;;;;AASG;AACG,SAAU,eAAe,CAAC,MAAA,GAAyB,EAAE,EAAA;AACzD,IAAA,OAAO,wBAAwB,CAAC;AAC9B,QAAA,EAAE,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,EAAE,GAAG,wBAAwB,EAAE,GAAG,MAAM,EAAE,EAAE;QACnF,qBAAqB,CAAC,MAAK;YACzB,MAAM,CAAC,eAAe,CAAC;AACzB,QAAA,CAAC,CAAC;AACH,KAAA,CAAC;AACJ;;AChCA;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"shirkasoft-ui-components-theme.mjs","names":[],"sources":["../../../projects/ui-components/theme/theme.config.ts","../../../projects/ui-components/theme/theme.service.ts","../../../projects/ui-components/theme/theme.providers.ts"],"sourcesContent":["import { InjectionToken } from '@angular/core';\n\n/** Built-in theme packs shipped with the library. */\nexport type ShkThemeName = 'default' | 'ocean' | 'violet' | 'sunset' | (string & {});\n\n/** Color scheme selection. `system` follows `prefers-color-scheme`. */\nexport type ShkColorScheme = 'light' | 'dark' | 'system';\n\nexport interface ShkThemeConfig {\n /** Theme applied when nothing is stored yet. Defaults to `default`. */\n defaultTheme?: ShkThemeName;\n /** Scheme applied when nothing is stored yet. Defaults to `system`. */\n defaultScheme?: ShkColorScheme;\n /** Persist the selection in localStorage. Defaults to `true`. */\n persist?: boolean;\n /** localStorage keys. */\n storageKey?: string;\n schemeStorageKey?: string;\n /** Attribute written on <html>. Defaults to `data-shk-theme`. */\n attribute?: string;\n /** Class toggled on <html> for dark mode. Defaults to `dark`. */\n darkClass?: string;\n}\n\nexport type ResolvedShkThemeConfig = Required<ShkThemeConfig>;\n\nexport const SHK_THEMES: readonly ShkThemeName[] = ['default', 'ocean', 'violet', 'sunset'];\n\nexport const DEFAULT_SHK_THEME_CONFIG: ResolvedShkThemeConfig = {\n defaultTheme: 'default',\n defaultScheme: 'system',\n persist: true,\n storageKey: 'shk-theme',\n schemeStorageKey: 'shk-scheme',\n attribute: 'data-shk-theme',\n darkClass: 'dark',\n};\n\nexport const SHK_THEME_CONFIG = new InjectionToken<ResolvedShkThemeConfig>('SHK_THEME_CONFIG', {\n providedIn: 'root',\n factory: () => DEFAULT_SHK_THEME_CONFIG,\n});\n","/**\n * Shirkasoft UI Components.\n * Authors: Roberto Valladares Martin (Ansem13), Julio César García García (Sanjuli14).\n * Belongs to Shirkasoft.\n */\nimport { DOCUMENT } from '@angular/common';\nimport { Injectable, computed, inject, signal } from '@angular/core';\n\nimport {\n SHK_THEMES,\n SHK_THEME_CONFIG,\n ShkColorScheme,\n ShkThemeName,\n} from './theme.config';\n\nconst DARK_QUERY = '(prefers-color-scheme: dark)';\n\n/** Theme packs removed in previous releases; a stored value falls back to the default. */\nconst RETIRED_THEMES: readonly string[] = ['rose'];\n\n/**\n * Applies and persists the color theme.\n *\n * Themes are plain CSS custom properties, so switching a theme is just an\n * attribute change on `<html>` — no component re-render involved.\n */\n@Injectable({ providedIn: 'root' })\nexport class ShkThemeService {\n private readonly doc = inject(DOCUMENT);\n private readonly config = inject(SHK_THEME_CONFIG);\n private readonly win = this.doc.defaultView;\n\n /** Every theme name the service knows about. */\n readonly availableThemes = SHK_THEMES;\n\n /** Currently active theme. */\n readonly theme = signal<ShkThemeName>(this.config.defaultTheme);\n\n /** Currently selected scheme (`light`, `dark` or `system`). */\n readonly scheme = signal<ShkColorScheme>(this.config.defaultScheme);\n\n /** `true` when dark colors are being applied. */\n readonly isDark = signal(false);\n\n /** Convenience flag for templates. */\n readonly isSystem = computed(() => this.scheme() === 'system');\n\n private mediaQuery?: MediaQueryList;\n\n constructor() {\n this.restore();\n this.applyTheme(this.theme());\n this.applyScheme(this.scheme());\n this.watchSystem();\n }\n\n /** Switches the active theme pack. */\n setTheme(theme: ShkThemeName): void {\n this.theme.set(theme);\n this.applyTheme(theme);\n this.persist(this.config.storageKey, theme);\n }\n\n /** Selects light, dark or system scheme. */\n setScheme(scheme: ShkColorScheme): void {\n this.scheme.set(scheme);\n this.applyScheme(scheme);\n this.persist(this.config.schemeStorageKey, scheme);\n }\n\n /** Flips between light and dark (leaves `system` on the opposite value). */\n toggleDark(): void {\n this.setScheme(this.isDark() ? 'light' : 'dark');\n }\n\n /** Applies a theme without persisting it (useful for previews). */\n previewTheme(theme: ShkThemeName): void {\n this.applyTheme(theme);\n }\n\n private restore(): void {\n if (!this.config.persist) return;\n\n const storedTheme = this.read(this.config.storageKey);\n if (storedTheme && !RETIRED_THEMES.includes(storedTheme)) this.theme.set(storedTheme);\n\n const storedScheme = this.read(this.config.schemeStorageKey) as ShkColorScheme | null;\n if (storedScheme === 'light' || storedScheme === 'dark' || storedScheme === 'system') {\n this.scheme.set(storedScheme);\n }\n }\n\n private applyTheme(theme: ShkThemeName): void {\n const root = this.doc?.documentElement;\n if (!root) return;\n\n if (theme === 'default') {\n root.removeAttribute(this.config.attribute);\n } else {\n root.setAttribute(this.config.attribute, theme);\n }\n }\n\n private applyScheme(scheme: ShkColorScheme): void {\n const root = this.doc?.documentElement;\n if (!root) return;\n\n const dark = scheme === 'dark' || (scheme === 'system' && this.prefersDark());\n root.classList.toggle(this.config.darkClass, dark);\n root.style.colorScheme = dark ? 'dark' : 'light';\n this.isDark.set(dark);\n }\n\n private watchSystem(): void {\n if (!this.win?.matchMedia) return;\n\n this.mediaQuery ??= this.win.matchMedia(DARK_QUERY);\n const onChange = (event: MediaQueryListEvent) => {\n if (this.scheme() !== 'system') return;\n this.applyScheme(event.matches ? 'dark' : 'light');\n };\n\n // Safari < 14 only supports addListener.\n if (this.mediaQuery.addEventListener) {\n this.mediaQuery.addEventListener('change', onChange);\n } else {\n this.mediaQuery.addListener(onChange);\n }\n }\n\n private prefersDark(): boolean {\n return this.win?.matchMedia?.(DARK_QUERY).matches ?? false;\n }\n\n private read(key: string): string | null {\n try {\n return this.win?.localStorage?.getItem(key) ?? null;\n } catch {\n return null;\n }\n }\n\n private persist(key: string, value: string): void {\n if (!this.config.persist) return;\n\n try {\n this.win?.localStorage?.setItem(key, value);\n } catch {\n // Storage can be blocked (private mode, iframe, quota). Theme still applies.\n }\n }\n}\n","/**\n * Shirkasoft UI Components.\n * Authors: Roberto Valladares Martin (Ansem13), Julio César García García (Sanjuli14).\n * Belongs to Shirkasoft.\n */\nimport {\n EnvironmentProviders,\n inject,\n makeEnvironmentProviders,\n provideAppInitializer,\n} from '@angular/core';\n\nimport { DEFAULT_SHK_THEME_CONFIG, SHK_THEME_CONFIG, ShkThemeConfig } from './theme.config';\nimport { ShkThemeService } from './theme.service';\n\n/**\n * Configures the theme system and applies the stored/default theme while the\n * app boots, so it is active even if nothing injects `ShkThemeService`.\n *\n * ```ts\n * bootstrapApplication(App, {\n * providers: [provideShkTheme({ defaultTheme: 'ocean', defaultScheme: 'dark' })],\n * });\n * ```\n */\nexport function provideShkTheme(config: ShkThemeConfig = {}): EnvironmentProviders {\n return makeEnvironmentProviders([\n { provide: SHK_THEME_CONFIG, useValue: { ...DEFAULT_SHK_THEME_CONFIG, ...config } },\n provideAppInitializer(() => {\n inject(ShkThemeService);\n }),\n ]);\n}\n"],"mappings":";;;AA0BA,MAAa,aAAsC;CAAC;CAAW;CAAS;CAAU;AAAQ;AAE1F,MAAa,2BAAmD;CAC9D,cAAc;CACd,eAAe;CACf,SAAS;CACT,YAAY;CACZ,kBAAkB;CAClB,WAAW;CACX,WAAW;AACZ;AAED,MAAa,mBAAmB,IAAI,eAAuC,oBAAoB;CAC7F,YAAY;CACZ,eAAe;AAChB,CAAA;AC1BD,MAAM,aAAa;AAGnB,MAAM,iBAAoC,CAAC,MAAM;AASjD,IAAa,kBAAb,MAAa,gBAAe;CAsB1B,cAAA;EArBiB,KAAA,MAAM,OAAO,QAAQ;EACrB,KAAA,SAAS,OAAO,gBAAgB;EAChC,KAAA,MAAM,KAAK,IAAI;EAGvB,KAAA,kBAAkB;EAGlB,KAAA,QAAQ,OAAqB,KAAK,OAAO,cAAa,GAAA,YAAA,CAAA,EAAA,WAAA,QAAA,CAAA,+BAAA,CAAA,CAAA;EAGtD,KAAA,S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