@cute-widgets/base 20.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -0
- package/LICENSE.md +191 -0
- package/README.md +190 -0
- package/abstract/index.d.ts +327 -0
- package/alert/index.d.ts +68 -0
- package/autocomplete/index.d.ts +442 -0
- package/badge/index.d.ts +26 -0
- package/bottom-sheet/index.d.ts +231 -0
- package/button/index.d.ts +182 -0
- package/button-toggle/index.d.ts +225 -0
- package/card/index.d.ts +163 -0
- package/checkbox/index.d.ts +174 -0
- package/chips/index.d.ts +963 -0
- package/collapse/index.d.ts +97 -0
- package/core/animation/index.d.ts +43 -0
- package/core/datetime/index.d.ts +404 -0
- package/core/directives/index.d.ts +168 -0
- package/core/error/index.d.ts +74 -0
- package/core/index.d.ts +1039 -0
- package/core/interfaces/index.d.ts +114 -0
- package/core/layout/index.d.ts +53 -0
- package/core/line/index.d.ts +37 -0
- package/core/nav/index.d.ts +321 -0
- package/core/observers/index.d.ts +124 -0
- package/core/option/index.d.ts +185 -0
- package/core/pipes/index.d.ts +53 -0
- package/core/ripple/index.d.ts +66 -0
- package/core/testing/index.d.ts +154 -0
- package/core/theming/index.d.ts +118 -0
- package/core/types/index.d.ts +53 -0
- package/core/utils/index.d.ts +129 -0
- package/cute-widgets-base-20.0.1.tgz +0 -0
- package/datepicker/index.d.ts +1817 -0
- package/dialog/index.d.ts +484 -0
- package/divider/index.d.ts +24 -0
- package/expansion/README.md +8 -0
- package/expansion/index.d.ts +308 -0
- package/fesm2022/cute-widgets-base-abstract.mjs +547 -0
- package/fesm2022/cute-widgets-base-abstract.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-alert.mjs +198 -0
- package/fesm2022/cute-widgets-base-alert.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-autocomplete.mjs +1217 -0
- package/fesm2022/cute-widgets-base-autocomplete.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-badge.mjs +75 -0
- package/fesm2022/cute-widgets-base-badge.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-bottom-sheet.mjs +416 -0
- package/fesm2022/cute-widgets-base-bottom-sheet.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-button-toggle.mjs +640 -0
- package/fesm2022/cute-widgets-base-button-toggle.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-button.mjs +546 -0
- package/fesm2022/cute-widgets-base-button.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-card.mjs +471 -0
- package/fesm2022/cute-widgets-base-card.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-checkbox.mjs +390 -0
- package/fesm2022/cute-widgets-base-checkbox.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-chips.mjs +2360 -0
- package/fesm2022/cute-widgets-base-chips.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-collapse.mjs +259 -0
- package/fesm2022/cute-widgets-base-collapse.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-animation.mjs +53 -0
- package/fesm2022/cute-widgets-base-core-animation.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-datetime.mjs +568 -0
- package/fesm2022/cute-widgets-base-core-datetime.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-directives.mjs +404 -0
- package/fesm2022/cute-widgets-base-core-directives.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-error.mjs +105 -0
- package/fesm2022/cute-widgets-base-core-error.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-interfaces.mjs +22 -0
- package/fesm2022/cute-widgets-base-core-interfaces.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-layout.mjs +74 -0
- package/fesm2022/cute-widgets-base-core-layout.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-line.mjs +87 -0
- package/fesm2022/cute-widgets-base-core-line.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-nav.mjs +863 -0
- package/fesm2022/cute-widgets-base-core-nav.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-observers.mjs +304 -0
- package/fesm2022/cute-widgets-base-core-observers.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-option.mjs +373 -0
- package/fesm2022/cute-widgets-base-core-option.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-pipes.mjs +97 -0
- package/fesm2022/cute-widgets-base-core-pipes.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-ripple.mjs +172 -0
- package/fesm2022/cute-widgets-base-core-ripple.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-testing.mjs +210 -0
- package/fesm2022/cute-widgets-base-core-testing.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-theming.mjs +314 -0
- package/fesm2022/cute-widgets-base-core-theming.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-types.mjs +22 -0
- package/fesm2022/cute-widgets-base-core-types.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-utils.mjs +257 -0
- package/fesm2022/cute-widgets-base-core-utils.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core.mjs +1600 -0
- package/fesm2022/cute-widgets-base-core.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-datepicker.mjs +4827 -0
- package/fesm2022/cute-widgets-base-datepicker.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-dialog.mjs +1046 -0
- package/fesm2022/cute-widgets-base-dialog.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-divider.mjs +86 -0
- package/fesm2022/cute-widgets-base-divider.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-expansion.mjs +623 -0
- package/fesm2022/cute-widgets-base-expansion.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-form-field.mjs +969 -0
- package/fesm2022/cute-widgets-base-form-field.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-grid-list.mjs +715 -0
- package/fesm2022/cute-widgets-base-grid-list.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-icon.mjs +1105 -0
- package/fesm2022/cute-widgets-base-icon.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-input.mjs +726 -0
- package/fesm2022/cute-widgets-base-input.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-layout-container.mjs +95 -0
- package/fesm2022/cute-widgets-base-layout-container.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-layout-stack.mjs +166 -0
- package/fesm2022/cute-widgets-base-layout-stack.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-layout.mjs +250 -0
- package/fesm2022/cute-widgets-base-layout.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-list.mjs +1557 -0
- package/fesm2022/cute-widgets-base-list.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-menu.mjs +1283 -0
- package/fesm2022/cute-widgets-base-menu.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-navbar.mjs +359 -0
- package/fesm2022/cute-widgets-base-navbar.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-paginator.mjs +485 -0
- package/fesm2022/cute-widgets-base-paginator.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-progress.mjs +321 -0
- package/fesm2022/cute-widgets-base-progress.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-radio.mjs +637 -0
- package/fesm2022/cute-widgets-base-radio.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-select.mjs +1208 -0
- package/fesm2022/cute-widgets-base-select.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-sidenav.mjs +1095 -0
- package/fesm2022/cute-widgets-base-sidenav.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-slider.mjs +99 -0
- package/fesm2022/cute-widgets-base-slider.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-snack-bar.mjs +897 -0
- package/fesm2022/cute-widgets-base-snack-bar.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-sort.mjs +639 -0
- package/fesm2022/cute-widgets-base-sort.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-spinner.mjs +154 -0
- package/fesm2022/cute-widgets-base-spinner.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-stepper.mjs +673 -0
- package/fesm2022/cute-widgets-base-stepper.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-table.mjs +1023 -0
- package/fesm2022/cute-widgets-base-table.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-tabs.mjs +729 -0
- package/fesm2022/cute-widgets-base-tabs.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-timepicker.mjs +965 -0
- package/fesm2022/cute-widgets-base-timepicker.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-toolbar.mjs +120 -0
- package/fesm2022/cute-widgets-base-toolbar.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-tooltip.mjs +947 -0
- package/fesm2022/cute-widgets-base-tooltip.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-tree.mjs +598 -0
- package/fesm2022/cute-widgets-base-tree.mjs.map +1 -0
- package/fesm2022/cute-widgets-base.mjs +68 -0
- package/fesm2022/cute-widgets-base.mjs.map +1 -0
- package/form-field/index.d.ts +401 -0
- package/grid-list/index.d.ts +361 -0
- package/icon/index.d.ts +477 -0
- package/index.d.ts +3 -0
- package/input/index.d.ts +256 -0
- package/layout/container/index.d.ts +31 -0
- package/layout/index.d.ts +78 -0
- package/layout/stack/index.d.ts +52 -0
- package/list/index.d.ts +659 -0
- package/menu/index.d.ts +497 -0
- package/navbar/index.d.ts +91 -0
- package/package.json +279 -0
- package/paginator/index.d.ts +216 -0
- package/progress/index.d.ts +130 -0
- package/radio/index.d.ts +259 -0
- package/select/index.d.ts +426 -0
- package/sidenav/index.d.ts +369 -0
- package/slider/index.d.ts +48 -0
- package/snack-bar/index.d.ts +374 -0
- package/sort/index.d.ts +334 -0
- package/spinner/index.d.ts +70 -0
- package/stepper/index.d.ts +295 -0
- package/table/index.d.ts +395 -0
- package/tabs/index.d.ts +307 -0
- package/timepicker/index.d.ts +350 -0
- package/toolbar/index.d.ts +36 -0
- package/tooltip/index.d.ts +299 -0
- package/tree/index.d.ts +314 -0
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { InjectionToken, Input, Directive, inject, DOCUMENT, Injectable } from '@angular/core';
|
|
3
|
+
import { Subject, fromEvent } from 'rxjs';
|
|
4
|
+
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
|
5
|
+
import { MediaMatcher } from '@angular/cdk/layout';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @license Apache-2.0
|
|
9
|
+
*
|
|
10
|
+
* Copyright (c) 2025 CuteWidgets Team. All Rights Reserved.
|
|
11
|
+
*
|
|
12
|
+
* You may not use this file except in compliance with the License
|
|
13
|
+
* that can be found at http://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* `CuteWidgets` supports standard Bootstrap 5 theme colors - `ThemeColor` type. But to account
|
|
17
|
+
* miscellaneous use cases of usage this colors in components CuteWidgets add extended definition of
|
|
18
|
+
* latter - `RichThemeColor`. Rich color is the standard color name plus "-emphasis" or "-contrast" suffix at the end.
|
|
19
|
+
* Depending on the context of applying color, the result CSS-class can be `.text-*`, `.text-bg-*` or ended with
|
|
20
|
+
* `-emphasis` or `-subtle` suffixes.
|
|
21
|
+
*/
|
|
22
|
+
/** Bootstrap theme colors */
|
|
23
|
+
const Palette = ["primary", "secondary", "success", "danger", "warning", "info", "light", "dark", "link", "tertiary"];
|
|
24
|
+
/**
|
|
25
|
+
* Whether a string is a valid theme color name
|
|
26
|
+
* @param str Text case-sensitive value
|
|
27
|
+
* @returns _true_ if `str` is a valid color name, otherwise _false_
|
|
28
|
+
*/
|
|
29
|
+
function isThemeColor(str) {
|
|
30
|
+
if (str) {
|
|
31
|
+
return Palette.indexOf(str) !== -1;
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Whether a string is a valid rich or base theme color name.
|
|
37
|
+
* @param str Case-sensitive text value of the color name.
|
|
38
|
+
* @returns _true_ if `str` is a valid rich color name, otherwise _false_.
|
|
39
|
+
*/
|
|
40
|
+
function isRichThemeColor(str) {
|
|
41
|
+
if (str) {
|
|
42
|
+
if (isExtendedColor(str)) {
|
|
43
|
+
str = getBaseColor(str);
|
|
44
|
+
}
|
|
45
|
+
return isThemeColor(str);
|
|
46
|
+
}
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Transforms a string to `ThemeColor` type.
|
|
51
|
+
* @param color Color value to transform
|
|
52
|
+
* @returns _ThemeColor_'s value or _undefined_, if the `color` has an invalid value.
|
|
53
|
+
*/
|
|
54
|
+
function toThemeColor(color) {
|
|
55
|
+
if (typeof color === "string") {
|
|
56
|
+
color = color.trim().toLowerCase();
|
|
57
|
+
if (isExtendedColor(color)) {
|
|
58
|
+
color = getBaseColor(color);
|
|
59
|
+
}
|
|
60
|
+
if (isThemeColor(color)) {
|
|
61
|
+
return color;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* To `_RichThemeColor_` transformer function.
|
|
68
|
+
* @param color Color value to transform into rich color type.
|
|
69
|
+
* @returns _RichThemeColor_ value or _undefined_ if `color` is invalid.
|
|
70
|
+
*/
|
|
71
|
+
function toRichThemeColor(color) {
|
|
72
|
+
if (typeof color === "string") {
|
|
73
|
+
color = color.trim().toLowerCase();
|
|
74
|
+
if (isRichThemeColor(color)) {
|
|
75
|
+
return color;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Returns a valid Bootstrap's `.text-*` CSS class.
|
|
82
|
+
* @param color Color palette to transform into CSS-class.
|
|
83
|
+
*/
|
|
84
|
+
function toTextCssClass(color) {
|
|
85
|
+
const richThemeColor = toRichThemeColor(color);
|
|
86
|
+
if (richThemeColor) {
|
|
87
|
+
if (richThemeColor.startsWith("tertiary")) {
|
|
88
|
+
// Bootstrap 5 has no ".text-tertiary-*" classes, so we return following
|
|
89
|
+
return "text-body-tertiary";
|
|
90
|
+
}
|
|
91
|
+
let themeColor;
|
|
92
|
+
if (isExtendedColor(richThemeColor)) {
|
|
93
|
+
themeColor = getBaseColor(richThemeColor);
|
|
94
|
+
if (richThemeColor.endsWith("-emphasis")) {
|
|
95
|
+
return `text-${themeColor}-emphasis`;
|
|
96
|
+
}
|
|
97
|
+
// contrast
|
|
98
|
+
return `text-bg-${themeColor}`;
|
|
99
|
+
}
|
|
100
|
+
themeColor = richThemeColor;
|
|
101
|
+
return `text-${themeColor}`;
|
|
102
|
+
}
|
|
103
|
+
return "";
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Returns a valid Bootstrap's `.bg-*` or `.text-bg-*` CSS class name.
|
|
107
|
+
* @param color Value to transform into CSS-class.
|
|
108
|
+
*/
|
|
109
|
+
function toBgCssClass(color) {
|
|
110
|
+
const richThemeColor = toRichThemeColor(color);
|
|
111
|
+
if (richThemeColor) {
|
|
112
|
+
if (richThemeColor.startsWith("tertiary")) {
|
|
113
|
+
// Bootstrap 5 has no 'tertiary-subtle'/'bg-tertiary' classes, so we return following
|
|
114
|
+
return "bg-body-tertiary";
|
|
115
|
+
}
|
|
116
|
+
let themeColor;
|
|
117
|
+
if (isExtendedColor(richThemeColor)) {
|
|
118
|
+
themeColor = getBaseColor(richThemeColor);
|
|
119
|
+
if (richThemeColor.endsWith("-emphasis")) {
|
|
120
|
+
return `bg-${themeColor}-subtle`;
|
|
121
|
+
}
|
|
122
|
+
// contrast
|
|
123
|
+
return `text-bg-${themeColor}`;
|
|
124
|
+
}
|
|
125
|
+
themeColor = richThemeColor;
|
|
126
|
+
// Simple background
|
|
127
|
+
return `bg-${themeColor}`;
|
|
128
|
+
}
|
|
129
|
+
return "";
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Set a background color with contrasting foreground color.
|
|
133
|
+
* @param color Color palette to transform into CSS-class.
|
|
134
|
+
* @returns A valid Bootstrap's `.text-bg-*` CSS-class
|
|
135
|
+
*/
|
|
136
|
+
function toTextBgCssClass(color) {
|
|
137
|
+
const richThemeColor = toRichThemeColor(color);
|
|
138
|
+
if (richThemeColor) {
|
|
139
|
+
if (richThemeColor.startsWith("tertiary")) {
|
|
140
|
+
return "text-body-tertiary";
|
|
141
|
+
}
|
|
142
|
+
let themeColor;
|
|
143
|
+
if (isExtendedColor(richThemeColor)) {
|
|
144
|
+
themeColor = getBaseColor(richThemeColor);
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
themeColor = richThemeColor;
|
|
148
|
+
}
|
|
149
|
+
return "text-bg-" + themeColor;
|
|
150
|
+
}
|
|
151
|
+
return "";
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Returns a valid Bootstrap's `.text-*` or `.text-bg-*` CSS class.
|
|
155
|
+
* @param color Color value to transform into CSS-class.
|
|
156
|
+
*/
|
|
157
|
+
function toColorCssClass(color) {
|
|
158
|
+
if (color) {
|
|
159
|
+
if (color.endsWith("-contrast")) {
|
|
160
|
+
return toTextBgCssClass(color);
|
|
161
|
+
}
|
|
162
|
+
return toTextCssClass(color);
|
|
163
|
+
}
|
|
164
|
+
return "";
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Extracts `ThemeColor` from the `RichThemeColor`.
|
|
168
|
+
* @param color Rich color
|
|
169
|
+
* @returns Base theme color.
|
|
170
|
+
* @internal
|
|
171
|
+
*/
|
|
172
|
+
function getBaseColor(color) {
|
|
173
|
+
let dashPos = color.indexOf("-");
|
|
174
|
+
if (dashPos >= 0) {
|
|
175
|
+
return color.slice(0, dashPos);
|
|
176
|
+
}
|
|
177
|
+
return color;
|
|
178
|
+
}
|
|
179
|
+
/** Whether the specified color is extended counterpart of the standard palette color. */
|
|
180
|
+
function isExtendedColor(color) {
|
|
181
|
+
return color.endsWith("-emphasis") || color.endsWith("-contrast");
|
|
182
|
+
}
|
|
183
|
+
const CUTE_THEME_COLOR = new InjectionToken("CUTE_THEME_COLOR");
|
|
184
|
+
class CuteThemeColor /* extends ... */ {
|
|
185
|
+
colorClass() {
|
|
186
|
+
return toColorCssClass(this.color);
|
|
187
|
+
}
|
|
188
|
+
bgClass() {
|
|
189
|
+
return toBgCssClass(this.color);
|
|
190
|
+
}
|
|
191
|
+
textBgClass() {
|
|
192
|
+
return toTextBgCssClass(this.color);
|
|
193
|
+
}
|
|
194
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: CuteThemeColor /* extends ... */, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
195
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "20.3.15", type: CuteThemeColor /* extends ... */, isStandalone: true, selector: "[cuteThemeColor]", inputs: { color: ["cuteThemeColor", "color"] }, providers: [{ provide: CUTE_THEME_COLOR, useExisting: CuteThemeColor }], exportAs: ["cuteThemeColor"], ngImport: i0 }); }
|
|
196
|
+
}
|
|
197
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: CuteThemeColor /* extends ... */, decorators: [{
|
|
198
|
+
type: Directive,
|
|
199
|
+
args: [{
|
|
200
|
+
selector: '[cuteThemeColor]',
|
|
201
|
+
exportAs: 'cuteThemeColor',
|
|
202
|
+
host: {},
|
|
203
|
+
providers: [{ provide: CUTE_THEME_COLOR, useExisting: CuteThemeColor }],
|
|
204
|
+
}]
|
|
205
|
+
}], propDecorators: { color: [{
|
|
206
|
+
type: Input,
|
|
207
|
+
args: ["cuteThemeColor"]
|
|
208
|
+
}] } });
|
|
209
|
+
|
|
210
|
+
const PREFERS_COLOR_SCHEME = '(prefers-color-scheme: dark)';
|
|
211
|
+
const THEME_ATTR_NAME = "data-bs-theme";
|
|
212
|
+
class CuteThemeService {
|
|
213
|
+
constructor() {
|
|
214
|
+
this._document = inject(DOCUMENT);
|
|
215
|
+
this._mediaChange = new Subject();
|
|
216
|
+
/** Observable that can be used to receive `MediaMatcher`'s _change_ event. */
|
|
217
|
+
this.change = this._mediaChange.asObservable();
|
|
218
|
+
const mediaMatcher = inject(MediaMatcher);
|
|
219
|
+
this._mediaQueryList = mediaMatcher.matchMedia(PREFERS_COLOR_SCHEME);
|
|
220
|
+
fromEvent(this._mediaQueryList, "change")
|
|
221
|
+
.pipe(takeUntilDestroyed())
|
|
222
|
+
.subscribe(event => {
|
|
223
|
+
const storedTheme = this.getStoredTheme();
|
|
224
|
+
if (storedTheme !== 'light' && storedTheme !== 'dark') {
|
|
225
|
+
this.setTheme(this.getPreferredTheme(), false);
|
|
226
|
+
}
|
|
227
|
+
this._mediaChange.next(event);
|
|
228
|
+
});
|
|
229
|
+
fromEvent(window, "DOMContentLoaded")
|
|
230
|
+
.pipe(takeUntilDestroyed())
|
|
231
|
+
.subscribe(() => {
|
|
232
|
+
this.setTheme(this.getPreferredTheme());
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
getStoredTheme() {
|
|
236
|
+
const theme = localStorage.getItem('theme');
|
|
237
|
+
if (theme && ["light", "dark", "auto"].includes(theme)) {
|
|
238
|
+
return theme;
|
|
239
|
+
}
|
|
240
|
+
return null;
|
|
241
|
+
}
|
|
242
|
+
setStoredTheme(theme) {
|
|
243
|
+
return localStorage.setItem('theme', theme);
|
|
244
|
+
}
|
|
245
|
+
/** Returns the user's preferred color mode. */
|
|
246
|
+
getPreferredTheme() {
|
|
247
|
+
const storedTheme = this.getStoredTheme();
|
|
248
|
+
if (storedTheme) {
|
|
249
|
+
return storedTheme;
|
|
250
|
+
}
|
|
251
|
+
return this.getCurrentTheme();
|
|
252
|
+
}
|
|
253
|
+
/** Returns the browser's color theme. */
|
|
254
|
+
getCurrentTheme() {
|
|
255
|
+
return this._mediaQueryList.matches ? 'dark' : 'light';
|
|
256
|
+
}
|
|
257
|
+
/** Whether is the dark theme currently selected. */
|
|
258
|
+
isDarkTheme() {
|
|
259
|
+
return this.getTheme() == "dark";
|
|
260
|
+
}
|
|
261
|
+
/** Whether is the light theme currently selected. */
|
|
262
|
+
isLightTheme() {
|
|
263
|
+
return !this.isDarkTheme();
|
|
264
|
+
}
|
|
265
|
+
/** Returns the Bootstrap's color theme. */
|
|
266
|
+
getTheme() {
|
|
267
|
+
const docElem = this._document.documentElement;
|
|
268
|
+
let attrValue = docElem.getAttribute(THEME_ATTR_NAME);
|
|
269
|
+
if (attrValue == null) {
|
|
270
|
+
attrValue = this.getCurrentTheme();
|
|
271
|
+
}
|
|
272
|
+
return attrValue;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Changes the default color mode (theme) of all pages in the website with the opportunity of auto-detection.
|
|
276
|
+
* @param theme Desired color theme.
|
|
277
|
+
* @param emitEvent Emulate event emitting. Default is _true_.
|
|
278
|
+
*/
|
|
279
|
+
setTheme(theme, emitEvent = true) {
|
|
280
|
+
const docElem = this._document.documentElement;
|
|
281
|
+
let matches;
|
|
282
|
+
if (theme === 'auto') {
|
|
283
|
+
matches = this._mediaQueryList.matches;
|
|
284
|
+
docElem.setAttribute(THEME_ATTR_NAME, (matches ? 'dark' : 'light'));
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
matches = (theme === "dark");
|
|
288
|
+
docElem.setAttribute(THEME_ATTR_NAME, theme);
|
|
289
|
+
}
|
|
290
|
+
this.setStoredTheme(theme);
|
|
291
|
+
if (emitEvent) {
|
|
292
|
+
// dispatch artificial (not trusted) change event
|
|
293
|
+
this._mediaQueryList.dispatchEvent(new MediaQueryListEvent("change", { matches, media: this._mediaQueryList.media }));
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
ngOnDestroy() {
|
|
297
|
+
this._mediaChange.complete();
|
|
298
|
+
}
|
|
299
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: CuteThemeService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
300
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: CuteThemeService, providedIn: "root" }); }
|
|
301
|
+
}
|
|
302
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: CuteThemeService, decorators: [{
|
|
303
|
+
type: Injectable,
|
|
304
|
+
args: [{
|
|
305
|
+
providedIn: "root"
|
|
306
|
+
}]
|
|
307
|
+
}], ctorParameters: () => [] });
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Generated bundle index. Do not edit.
|
|
311
|
+
*/
|
|
312
|
+
|
|
313
|
+
export { CUTE_THEME_COLOR, CuteThemeColor, CuteThemeService, isRichThemeColor, isThemeColor, toBgCssClass, toColorCssClass, toRichThemeColor, toTextBgCssClass, toTextCssClass, toThemeColor };
|
|
314
|
+
//# sourceMappingURL=cute-widgets-base-core-theming.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cute-widgets-base-core-theming.mjs","sources":["../../../../projects/cute-widgets/base/core/theming/src/ThemeColor.ts","../../../../projects/cute-widgets/base/core/theming/src/theme.service.ts","../../../../projects/cute-widgets/base/core/theming/cute-widgets-base-core-theming.ts"],"sourcesContent":["/**\r\n * @license Apache-2.0\r\n *\r\n * Copyright (c) 2025 CuteWidgets Team. All Rights Reserved.\r\n *\r\n * You may not use this file except in compliance with the License\r\n * that can be found at http://www.apache.org/licenses/LICENSE-2.0\r\n */\r\n\r\n/**\r\n * `CuteWidgets` supports standard Bootstrap 5 theme colors - `ThemeColor` type. But to account\r\n * miscellaneous use cases of usage this colors in components CuteWidgets add extended definition of\r\n * latter - `RichThemeColor`. Rich color is the standard color name plus \"-emphasis\" or \"-contrast\" suffix at the end.\r\n * Depending on the context of applying color, the result CSS-class can be `.text-*`, `.text-bg-*` or ended with\r\n * `-emphasis` or `-subtle` suffixes.\r\n */\r\nimport {Directive, InjectionToken, Input, input} from \"@angular/core\";\r\n\r\n/** Bootstrap theme colors */\r\nconst Palette = [\"primary\",\"secondary\",\"success\",\"danger\",\"warning\",\"info\",\"light\",\"dark\",\"link\",\"tertiary\"] as const;\r\n\r\n/** Bootstrap’s base color palette. */\r\nexport type ThemeColor = typeof Palette[number];\r\n/** Rich color palette is based on the standard Bootstrap palette but has additional shades. */\r\nexport type RichThemeColor = ThemeColor | `${ThemeColor}-emphasis` | `${ThemeColor}-contrast`;\r\n\r\n/** Alias for `ThemeColor` type. */\r\nexport type ThemePalette = ThemeColor;\r\n/** Alias for `ThemeColor` type. */\r\nexport type RichThemePalette = RichThemeColor;\r\n\r\n/**\r\n * Whether a string is a valid theme color name\r\n * @param str Text case-sensitive value\r\n * @returns _true_ if `str` is a valid color name, otherwise _false_\r\n */\r\nexport function isThemeColor(str: string|undefined|null): str is ThemeColor {\r\n if (str) {\r\n return Palette.indexOf(str as any) !== -1;\r\n }\r\n return false;\r\n}\r\n\r\n/**\r\n * Whether a string is a valid rich or base theme color name.\r\n * @param str Case-sensitive text value of the color name.\r\n * @returns _true_ if `str` is a valid rich color name, otherwise _false_.\r\n */\r\nexport function isRichThemeColor(str: string|undefined|null): str is RichThemeColor {\r\n if (str) {\r\n if (isExtendedColor(str)) {\r\n str = getBaseColor(str as RichThemeColor);\r\n }\r\n return isThemeColor(str);\r\n }\r\n return false;\r\n}\r\n\r\n/**\r\n * Transforms a string to `ThemeColor` type.\r\n * @param color Color value to transform\r\n * @returns _ThemeColor_'s value or _undefined_, if the `color` has an invalid value.\r\n */\r\nexport function toThemeColor(color: string|undefined|null): ThemeColor|undefined {\r\n if (typeof color===\"string\") {\r\n color = color.trim().toLowerCase();\r\n if (isExtendedColor(color)) {\r\n color = getBaseColor(color as RichThemeColor);\r\n }\r\n if (isThemeColor(color)) {\r\n return color;\r\n }\r\n }\r\n return undefined;\r\n}\r\n\r\n/**\r\n * To `_RichThemeColor_` transformer function.\r\n * @param color Color value to transform into rich color type.\r\n * @returns _RichThemeColor_ value or _undefined_ if `color` is invalid.\r\n */\r\nexport function toRichThemeColor(color: string|undefined|null): RichThemeColor|undefined {\r\n if (typeof color===\"string\") {\r\n color = color.trim().toLowerCase();\r\n if (isRichThemeColor(color)) {\r\n return color;\r\n }\r\n }\r\n return undefined;\r\n}\r\n\r\n/**\r\n * Returns a valid Bootstrap's `.text-*` CSS class.\r\n * @param color Color palette to transform into CSS-class.\r\n */\r\nexport function toTextCssClass(color: string|undefined|null): string {\r\n const richThemeColor: RichThemeColor|undefined = toRichThemeColor(color);\r\n if (richThemeColor) {\r\n if (richThemeColor.startsWith(\"tertiary\")) {\r\n // Bootstrap 5 has no \".text-tertiary-*\" classes, so we return following\r\n return \"text-body-tertiary\";\r\n }\r\n\r\n let themeColor: ThemeColor;\r\n if (isExtendedColor(richThemeColor)) {\r\n themeColor = getBaseColor(richThemeColor);\r\n if (richThemeColor.endsWith(\"-emphasis\")) {\r\n return `text-${themeColor}-emphasis`;\r\n }\r\n // contrast\r\n return `text-bg-${themeColor}`;\r\n }\r\n themeColor = richThemeColor as ThemeColor;\r\n return `text-${themeColor}`;\r\n }\r\n return \"\";\r\n}\r\n\r\n/**\r\n * Returns a valid Bootstrap's `.bg-*` or `.text-bg-*` CSS class name.\r\n * @param color Value to transform into CSS-class.\r\n */\r\nexport function toBgCssClass(color: string|undefined|null): string {\r\n const richThemeColor: RichThemeColor|undefined = toRichThemeColor(color);\r\n if (richThemeColor) {\r\n if (richThemeColor.startsWith(\"tertiary\")) {\r\n // Bootstrap 5 has no 'tertiary-subtle'/'bg-tertiary' classes, so we return following\r\n return \"bg-body-tertiary\";\r\n }\r\n\r\n let themeColor: ThemeColor;\r\n if (isExtendedColor(richThemeColor)) {\r\n themeColor = getBaseColor(richThemeColor);\r\n if (richThemeColor.endsWith(\"-emphasis\")) {\r\n return `bg-${themeColor}-subtle`;\r\n }\r\n // contrast\r\n return `text-bg-${themeColor}`;\r\n }\r\n\r\n themeColor = richThemeColor as ThemeColor;\r\n // Simple background\r\n return `bg-${themeColor}`;\r\n }\r\n return \"\";\r\n}\r\n\r\n/**\r\n * Set a background color with contrasting foreground color.\r\n * @param color Color palette to transform into CSS-class.\r\n * @returns A valid Bootstrap's `.text-bg-*` CSS-class\r\n */\r\nexport function toTextBgCssClass(color: string|undefined|null): string {\r\n const richThemeColor: RichThemeColor|undefined = toRichThemeColor(color);\r\n if (richThemeColor) {\r\n if (richThemeColor.startsWith(\"tertiary\")) {\r\n return \"text-body-tertiary\";\r\n }\r\n let themeColor: ThemeColor;\r\n if (isExtendedColor(richThemeColor)) {\r\n themeColor = getBaseColor(richThemeColor);\r\n } else {\r\n themeColor = richThemeColor as ThemeColor;\r\n }\r\n return \"text-bg-\"+themeColor;\r\n }\r\n return \"\";\r\n}\r\n\r\n/**\r\n * Returns a valid Bootstrap's `.text-*` or `.text-bg-*` CSS class.\r\n * @param color Color value to transform into CSS-class.\r\n */\r\nexport function toColorCssClass(color: string|undefined|null): string {\r\n if (color) {\r\n if (color.endsWith(\"-contrast\")) {\r\n return toTextBgCssClass(color);\r\n }\r\n return toTextCssClass(color);\r\n }\r\n return \"\";\r\n}\r\n\r\n/**\r\n * Extracts `ThemeColor` from the `RichThemeColor`.\r\n * @param color Rich color\r\n * @returns Base theme color.\r\n * @internal\r\n */\r\nfunction getBaseColor(color: RichThemeColor): ThemeColor {\r\n let dashPos = color.indexOf(\"-\");\r\n if (dashPos >= 0) {\r\n return color.slice(0, dashPos) as ThemeColor;\r\n }\r\n return color as ThemeColor;\r\n}\r\n\r\n/** Whether the specified color is extended counterpart of the standard palette color. */\r\nfunction isExtendedColor(color: string): boolean {\r\n return color.endsWith(\"-emphasis\") || color.endsWith(\"-contrast\");\r\n}\r\n\r\n\r\nexport const CUTE_THEME_COLOR = new InjectionToken<CuteThemeColor>(\"CUTE_THEME_COLOR\");\r\n\r\n@Directive({\r\n selector: '[cuteThemeColor]',\r\n exportAs: 'cuteThemeColor',\r\n host: {},\r\n providers: [{provide: CUTE_THEME_COLOR, useExisting: CuteThemeColor}],\r\n})\r\nexport class CuteThemeColor /* extends ... */ {\r\n\r\n @Input(\"cuteThemeColor\")\r\n color: RichThemeColor | undefined;\r\n\r\n colorClass(): string {\r\n return toColorCssClass(this.color);\r\n }\r\n\r\n bgClass(): string {\r\n return toBgCssClass(this.color);\r\n }\r\n\r\n textBgClass(): string {\r\n return toTextBgCssClass(this.color);\r\n }\r\n\r\n}\r\n","import {DOCUMENT, inject, Injectable, OnDestroy} from '@angular/core';\r\nimport {fromEvent, Subject} from 'rxjs';\r\nimport {takeUntilDestroyed} from '@angular/core/rxjs-interop';\r\nimport {MediaMatcher} from '@angular/cdk/layout';\r\n\r\nconst PREFERS_COLOR_SCHEME = '(prefers-color-scheme: dark)';\r\nconst THEME_ATTR_NAME = \"data-bs-theme\";\r\n\r\nexport type CuteTheme = \"light\" | \"dark\" | \"auto\";\r\n\r\n@Injectable({\r\n providedIn: \"root\"\r\n})\r\nexport class CuteThemeService implements OnDestroy {\r\n private _document = inject(DOCUMENT);\r\n private _mediaQueryList: MediaQueryList;\r\n private _mediaChange = new Subject<MediaQueryListEvent>();\r\n\r\n /** Observable that can be used to receive `MediaMatcher`'s _change_ event. */\r\n readonly change = this._mediaChange.asObservable();\r\n\r\n constructor() {\r\n const mediaMatcher = inject(MediaMatcher);\r\n this._mediaQueryList = mediaMatcher.matchMedia(PREFERS_COLOR_SCHEME);\r\n\r\n fromEvent<MediaQueryListEvent>(this._mediaQueryList, \"change\")\r\n .pipe(takeUntilDestroyed())\r\n .subscribe(event => {\r\n const storedTheme = this.getStoredTheme();\r\n if (storedTheme !== 'light' && storedTheme !== 'dark') {\r\n this.setTheme( this.getPreferredTheme(), false );\r\n }\r\n this._mediaChange.next(event);\r\n });\r\n\r\n fromEvent(window, \"DOMContentLoaded\")\r\n .pipe(takeUntilDestroyed())\r\n .subscribe(() => {\r\n this.setTheme( this.getPreferredTheme() );\r\n });\r\n }\r\n\r\n private getStoredTheme(): CuteTheme|null {\r\n const theme = localStorage.getItem('theme');\r\n if (theme && [\"light\",\"dark\",\"auto\"].includes(theme)) {\r\n return theme as CuteTheme;\r\n }\r\n return null;\r\n }\r\n\r\n private setStoredTheme(theme: CuteTheme): void{\r\n return localStorage.setItem('theme', theme);\r\n }\r\n\r\n /** Returns the user's preferred color mode. */\r\n getPreferredTheme(): CuteTheme {\r\n const storedTheme = this.getStoredTheme();\r\n if (storedTheme) {\r\n return storedTheme;\r\n }\r\n\r\n return this.getCurrentTheme();\r\n }\r\n\r\n /** Returns the browser's color theme. */\r\n getCurrentTheme(): CuteTheme {\r\n return this._mediaQueryList.matches ? 'dark' : 'light';\r\n }\r\n\r\n /** Whether is the dark theme currently selected. */\r\n isDarkTheme(): boolean {\r\n return this.getTheme() == \"dark\";\r\n }\r\n\r\n /** Whether is the light theme currently selected. */\r\n isLightTheme(): boolean {\r\n return !this.isDarkTheme();\r\n }\r\n\r\n /** Returns the Bootstrap's color theme. */\r\n getTheme(): Omit<CuteTheme, \"auto\"> {\r\n const docElem = this._document.documentElement;\r\n let attrValue = docElem.getAttribute(THEME_ATTR_NAME);\r\n if (attrValue == null) {\r\n attrValue = this.getCurrentTheme();\r\n }\r\n return attrValue;\r\n }\r\n\r\n /**\r\n * Changes the default color mode (theme) of all pages in the website with the opportunity of auto-detection.\r\n * @param theme Desired color theme.\r\n * @param emitEvent Emulate event emitting. Default is _true_.\r\n */\r\n setTheme(theme: CuteTheme, emitEvent: boolean = true): void {\r\n const docElem = this._document.documentElement;\r\n let matches: boolean;\r\n if (theme === 'auto') {\r\n matches = this._mediaQueryList.matches;\r\n docElem.setAttribute(THEME_ATTR_NAME, (matches ? 'dark' : 'light'));\r\n } else {\r\n matches = (theme === \"dark\");\r\n docElem.setAttribute(THEME_ATTR_NAME, theme);\r\n }\r\n this.setStoredTheme(theme);\r\n if (emitEvent) {\r\n // dispatch artificial (not trusted) change event\r\n this._mediaQueryList.dispatchEvent( new MediaQueryListEvent(\"change\", {matches, media: this._mediaQueryList.media}) );\r\n }\r\n }\r\n\r\n ngOnDestroy() {\r\n this._mediaChange.complete();\r\n }\r\n\r\n}\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;AAAA;;;;;;;AAOG;AAEH;;;;;;AAMG;AAGH;AACA,MAAM,OAAO,GAAG,CAAC,SAAS,EAAC,WAAW,EAAC,SAAS,EAAC,QAAQ,EAAC,SAAS,EAAC,MAAM,EAAC,OAAO,EAAC,MAAM,EAAC,MAAM,EAAC,UAAU,CAAU;AAYrH;;;;AAIG;AACG,SAAU,YAAY,CAAC,GAA0B,EAAA;IACrD,IAAI,GAAG,EAAE;QACP,OAAO,OAAO,CAAC,OAAO,CAAC,GAAU,CAAC,KAAK,CAAC,CAAC;IAC3C;AACA,IAAA,OAAO,KAAK;AACd;AAEA;;;;AAIG;AACG,SAAU,gBAAgB,CAAC,GAA0B,EAAA;IACzD,IAAI,GAAG,EAAE;AACP,QAAA,IAAI,eAAe,CAAC,GAAG,CAAC,EAAE;AACxB,YAAA,GAAG,GAAG,YAAY,CAAC,GAAqB,CAAC;QAC3C;AACA,QAAA,OAAO,YAAY,CAAC,GAAG,CAAC;IAC1B;AACA,IAAA,OAAO,KAAK;AACd;AAEA;;;;AAIG;AACG,SAAU,YAAY,CAAC,KAA4B,EAAA;AACvD,IAAA,IAAI,OAAO,KAAK,KAAG,QAAQ,EAAE;QAC3B,KAAK,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE;AAClC,QAAA,IAAI,eAAe,CAAC,KAAK,CAAC,EAAE;AAC1B,YAAA,KAAK,GAAG,YAAY,CAAC,KAAuB,CAAC;QAC/C;AACA,QAAA,IAAI,YAAY,CAAC,KAAK,CAAC,EAAE;AACvB,YAAA,OAAO,KAAK;QACd;IACF;AACA,IAAA,OAAO,SAAS;AAClB;AAEA;;;;AAIG;AACG,SAAU,gBAAgB,CAAC,KAA4B,EAAA;AAC3D,IAAA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|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2025 CuteWidgets Team. All Rights Reserved.
|
|
5
|
+
*
|
|
6
|
+
* You may not use this file except in compliance with the License
|
|
7
|
+
* that can be found at http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @license Apache-2.0
|
|
12
|
+
*
|
|
13
|
+
* Copyright (c) 2025 CuteWidgets Team. All Rights Reserved.
|
|
14
|
+
*
|
|
15
|
+
* You may not use this file except in compliance with the License
|
|
16
|
+
* that can be found at http://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Generated bundle index. Do not edit.
|
|
21
|
+
*/
|
|
22
|
+
//# sourceMappingURL=cute-widgets-base-core-types.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cute-widgets-base-core-types.mjs","sources":["../../../../projects/cute-widgets/base/core/types/src/MouseCursor.ts","../../../../projects/cute-widgets/base/core/types/src/RelativeSize.ts","../../../../projects/cute-widgets/base/core/types/cute-widgets-base-core-types.ts"],"sourcesContent":["/**\r\n * @license Apache-2.0\r\n *\r\n * Copyright (c) 2025 CuteWidgets Team. All Rights Reserved.\r\n *\r\n * You may not use this file except in compliance with the License\r\n * that can be found at http://www.apache.org/licenses/LICENSE-2.0\r\n */\r\n\r\nexport type MouseGeneralCursor =\r\n | \"auto\"\r\n | \"default\"\r\n | \"none\";\r\n\r\nexport type MouseLinkAndStatusCursor =\r\n | \"context-menu\"\r\n | \"help\"\r\n | \"pointer\"\r\n | \"progress\"\r\n | \"wait\";\r\n\r\nexport type MouseSelectionCursor =\r\n | \"cell\"\r\n | \"crosshair\"\r\n | \"text\"\r\n | \"vertical-text\";\r\n\r\nexport type MouseDragAndDropCursor =\r\n | \"alias\"\r\n | \"copy\"\r\n | \"move\"\r\n | \"no-drop\"\r\n | \"not-allowed\"\r\n | \"grab\"\r\n | \"grabbing\";\r\n\r\nexport type MouseResizeAndScrollCursor =\r\n | \"all-scroll\"\r\n | \"col-resize\"\r\n | \"row-resize\"\r\n | \"n-resize\"\r\n | \"e-resize\"\r\n | \"s-resize\"\r\n | \"w-resize\"\r\n | \"ne-resize\"\r\n | \"nw-resize\"\r\n | \"se-resize\"\r\n | \"sw-resize\"\r\n | \"ew-resize\"\r\n | \"ns-resize\"\r\n | \"nesw-resize\"\r\n | \"nwse-resize\";\r\n\r\nexport type MouseZoomingCursor =\r\n | \"zoom-in\"\r\n | \"zoom-out\";\r\n\r\nexport type MouseCursor =\r\n | MouseGeneralCursor\r\n | MouseLinkAndStatusCursor\r\n | MouseSelectionCursor\r\n | MouseDragAndDropCursor\r\n | MouseResizeAndScrollCursor\r\n | MouseZoomingCursor;\r\n","/**\r\n * @license Apache-2.0\r\n *\r\n * Copyright (c) 2025 CuteWidgets Team. All Rights Reserved.\r\n *\r\n * You may not use this file except in compliance with the License\r\n * that can be found at http://www.apache.org/licenses/LICENSE-2.0\r\n */\r\n\r\nexport type RelativeSize3 = \"middle\"|\"large\"|\"small\";\r\nexport type RelativeSize5 = RelativeSize3 | (\"larger\"|\"smaller\");\r\nexport type RelativeSize7 = RelativeSize5 | (\"largest\"|\"smallest\");\r\nexport type RelativeSize = RelativeSize3;\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":"AAAA;;;;;;;AAOG;;ACPH;;;;;;;AAOG;;ACPH;;AAEG"}
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { InjectionToken, inject, APP_ID, Injectable } from '@angular/core';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @license Apache-2.0
|
|
6
|
+
*
|
|
7
|
+
* Copyright (c) 2025 CuteWidgets Team. All Rights Reserved.
|
|
8
|
+
*
|
|
9
|
+
* You may not use this file except in compliance with the License
|
|
10
|
+
* that can be found at http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Gets transition duration total value
|
|
14
|
+
* @param element Source HTML element
|
|
15
|
+
* @returns Duration with delay time in milliseconds
|
|
16
|
+
*/
|
|
17
|
+
function getOverallTransitionDuration(element) {
|
|
18
|
+
return getTransitionDelay(element) + getTransitionDuration(element);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Gets transition duration value
|
|
22
|
+
* @param element Source HTML element
|
|
23
|
+
* @returns Duration time in milliseconds
|
|
24
|
+
*/
|
|
25
|
+
function getTransitionDuration(element) {
|
|
26
|
+
const { transitionDuration } = window.getComputedStyle(element);
|
|
27
|
+
const durationInMilliseconds = transitionDuration.toLowerCase().endsWith("ms");
|
|
28
|
+
const transitionDurationMs = parseFloat(transitionDuration) * (durationInMilliseconds ? 1 : 1000);
|
|
29
|
+
return (transitionDurationMs);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Gets duration to wait before starting transition
|
|
33
|
+
* @param element Source HTML element
|
|
34
|
+
* @returns Delay time in milliseconds
|
|
35
|
+
*/
|
|
36
|
+
function getTransitionDelay(element) {
|
|
37
|
+
const { transitionDelay } = window.getComputedStyle(element);
|
|
38
|
+
const delayInMilliseconds = transitionDelay.toLowerCase().endsWith("ms");
|
|
39
|
+
const transitionDelayMs = parseFloat(transitionDelay) * (delayInMilliseconds ? 1 : 1000);
|
|
40
|
+
return (transitionDelayMs);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @license Apache-2.0
|
|
45
|
+
*
|
|
46
|
+
* Copyright (c) 2025 CuteWidgets Team. All Rights Reserved.
|
|
47
|
+
*
|
|
48
|
+
* You may not use this file except in compliance with the License
|
|
49
|
+
* that can be found at http://www.apache.org/licenses/LICENSE-2.0
|
|
50
|
+
*/
|
|
51
|
+
function createValueToken(value) {
|
|
52
|
+
return createFactoryToken(() => value);
|
|
53
|
+
}
|
|
54
|
+
function createFactoryToken(factory) {
|
|
55
|
+
return new InjectionToken(`createFactoryToken`, { factory });
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Forcibly starts the process of downloading and saving the file.
|
|
60
|
+
* @param blobData Data to save
|
|
61
|
+
* @param filename File name to save. Default is `download`.
|
|
62
|
+
*/
|
|
63
|
+
function saveAs(blobData, filename) {
|
|
64
|
+
const link = document.createElement("a");
|
|
65
|
+
link.href = URL.createObjectURL(blobData);
|
|
66
|
+
link.download = filename || "download";
|
|
67
|
+
link.click();
|
|
68
|
+
URL.revokeObjectURL(link.href);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Exports data from HTML table to MS Excel format text
|
|
72
|
+
* @param tableIdOrElem HTML table's `id` value or `ElementRef` object
|
|
73
|
+
* @param options Export options
|
|
74
|
+
*/
|
|
75
|
+
function exportToExcel(tableIdOrElem, options = { filename: 'records.xls' }) {
|
|
76
|
+
let tableElem;
|
|
77
|
+
if (typeof tableIdOrElem === "string") {
|
|
78
|
+
tableElem = document.getElementById(tableIdOrElem);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
tableElem = tableIdOrElem.nativeElement;
|
|
82
|
+
}
|
|
83
|
+
if (tableElem && tableElem instanceof HTMLTableElement) {
|
|
84
|
+
//const tableHTML = encodeURIComponent(tableElem.outerHTML.replace(/ or .*?>/g, '>'));
|
|
85
|
+
const tableHTML = tableElem.outerHTML.replace(/ or .*?>/g, '>');
|
|
86
|
+
const blobData = new Blob([tableHTML], { type: '{type: application/vnd.ms-excel' });
|
|
87
|
+
saveAs(blobData, options?.filename);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Exports data from HTML table to CSV format text
|
|
92
|
+
* @param tableIdOrElem HTML table's `id` value or `ElementRef` object
|
|
93
|
+
* @param options Export options
|
|
94
|
+
*/
|
|
95
|
+
function exportToCSV(tableIdOrElem, options = { filename: 'records.csv' }) {
|
|
96
|
+
let tableElem;
|
|
97
|
+
if (typeof tableIdOrElem === "string") {
|
|
98
|
+
tableElem = document.getElementById(tableIdOrElem);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
tableElem = tableIdOrElem.nativeElement;
|
|
102
|
+
}
|
|
103
|
+
if (tableElem && tableElem instanceof HTMLTableElement) {
|
|
104
|
+
const rows = tableElem.querySelectorAll("tr");
|
|
105
|
+
let csv = [];
|
|
106
|
+
let keys = [];
|
|
107
|
+
if (rows.length > 0 && options && options.columns?.length) {
|
|
108
|
+
const headers = rows[0].querySelectorAll("th");
|
|
109
|
+
headers.forEach((header, key) => {
|
|
110
|
+
if (options.columns.findIndex((name) => {
|
|
111
|
+
const loweredName = name.toLowerCase();
|
|
112
|
+
return header.innerText.toLowerCase() == loweredName || header.classList.contains("cdk-column-" + loweredName);
|
|
113
|
+
}) >= 0) {
|
|
114
|
+
keys.push(key);
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
const appendCells = (cells) => {
|
|
119
|
+
const rowText = Array.from(cells).map(cell => cell.innerText);
|
|
120
|
+
csv.push(rowText.join(options?.delimiter ?? ","));
|
|
121
|
+
};
|
|
122
|
+
if (keys.length > 0) {
|
|
123
|
+
rows.forEach((row) => {
|
|
124
|
+
const allCells = row.querySelectorAll("th,td");
|
|
125
|
+
let cells = [];
|
|
126
|
+
allCells.forEach((cell, key) => {
|
|
127
|
+
if (keys.indexOf(key) >= 0) {
|
|
128
|
+
cells.push(cell);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
appendCells(cells);
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
rows.forEach((row) => {
|
|
136
|
+
appendCells(row.querySelectorAll("th,td"));
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
const blobData = new Blob([csv.join("\n")], { type: "text/csv;charset=utf-8;" });
|
|
140
|
+
saveAs(blobData, options?.filename);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* @license Apache-2.0
|
|
146
|
+
*
|
|
147
|
+
* Copyright (c) 2025 CuteWidgets Team. All Rights Reserved.
|
|
148
|
+
*
|
|
149
|
+
* You may not use this file except in compliance with the License
|
|
150
|
+
* that can be found at http://www.apache.org/licenses/LICENSE-2.0
|
|
151
|
+
*
|
|
152
|
+
* This code is a modification of the `@angular/material` original
|
|
153
|
+
* code licensed under MIT-style License (https://angular.dev/license).
|
|
154
|
+
*/
|
|
155
|
+
/**
|
|
156
|
+
* Keeps track of the ID count per prefix. This helps us make the IDs a bit more deterministic
|
|
157
|
+
* like they were before the service was introduced. Note that ideally we wouldn't have to do
|
|
158
|
+
* this, but there are some internal tests that rely on the IDs.
|
|
159
|
+
*/
|
|
160
|
+
const counters = {};
|
|
161
|
+
/** Service that generates unique IDs for DOM nodes. */
|
|
162
|
+
class IdGenerator {
|
|
163
|
+
constructor() {
|
|
164
|
+
this._appId = inject(APP_ID);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Generates a unique ID with a specific prefix.
|
|
168
|
+
* @param prefix Prefix to add to the ID.
|
|
169
|
+
*/
|
|
170
|
+
getId(prefix) {
|
|
171
|
+
// Omit the app ID if it's the default `ng`. Since the vast majority of pages have one
|
|
172
|
+
// Angular app on them, we can reduce the number of breakages by not adding it.
|
|
173
|
+
if (this._appId !== 'ng') {
|
|
174
|
+
prefix += this._appId;
|
|
175
|
+
}
|
|
176
|
+
if (!counters.hasOwnProperty(prefix)) {
|
|
177
|
+
counters[prefix] = 0;
|
|
178
|
+
}
|
|
179
|
+
return `${prefix}${counters[prefix]++}`;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Generates UUID (ver.4) string using simple algorithm based on random value only
|
|
183
|
+
*/
|
|
184
|
+
getUUID() {
|
|
185
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
|
|
186
|
+
.replace(/[xy]/g, (c) => {
|
|
187
|
+
const r = (Math.random() * 16) | 0, v = c == 'x' ? r : (r & 0x3) | 0x8;
|
|
188
|
+
return v.toString(16);
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: IdGenerator, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
192
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: IdGenerator, providedIn: 'root' }); }
|
|
193
|
+
}
|
|
194
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: IdGenerator, decorators: [{
|
|
195
|
+
type: Injectable,
|
|
196
|
+
args: [{ providedIn: 'root' }]
|
|
197
|
+
}] });
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* @license Apache-2.0
|
|
201
|
+
*
|
|
202
|
+
* Copyright (c) 2025 CuteWidgets Team. All Rights Reserved.
|
|
203
|
+
*
|
|
204
|
+
* You may not use this file except in compliance with the License
|
|
205
|
+
* that can be found at http://www.apache.org/licenses/LICENSE-2.0
|
|
206
|
+
*/
|
|
207
|
+
/**
|
|
208
|
+
* A class with static methods specifically designed for scheduling tasks in the browser.
|
|
209
|
+
*/
|
|
210
|
+
class Scheduler {
|
|
211
|
+
/** Yielding to the main thread in the browser. */
|
|
212
|
+
static async yield() {
|
|
213
|
+
const globalScheduler = globalThis.scheduler;
|
|
214
|
+
if (globalScheduler?.yield) {
|
|
215
|
+
return globalScheduler.yield();
|
|
216
|
+
}
|
|
217
|
+
// Fall back to yielding with setTimeout.
|
|
218
|
+
return new Promise(resolve => {
|
|
219
|
+
setTimeout(resolve, 0);
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Resolves a promise after the delay time in milliseconds
|
|
224
|
+
* @param ms Number of milliseconds to wait
|
|
225
|
+
*
|
|
226
|
+
* @see {@link delay}
|
|
227
|
+
*/
|
|
228
|
+
static async wait(ms) {
|
|
229
|
+
const startNow = performance.now();
|
|
230
|
+
while ((performance.now() - startNow) < ms) {
|
|
231
|
+
await Scheduler.yield();
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Adding a task to be scheduled according to their priority.
|
|
236
|
+
* @param callback Function to run
|
|
237
|
+
* @param options Scheduler options
|
|
238
|
+
*
|
|
239
|
+
* @see {@link async.post}
|
|
240
|
+
*/
|
|
241
|
+
static async postTask(callback, options) {
|
|
242
|
+
const globalScheduler = globalThis.scheduler;
|
|
243
|
+
if (globalScheduler?.postTask) {
|
|
244
|
+
return globalScheduler.postTask(callback, options);
|
|
245
|
+
}
|
|
246
|
+
return new Promise((resolve) => {
|
|
247
|
+
setTimeout(() => resolve(callback()), options?.delay ?? 0);
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Generated bundle index. Do not edit.
|
|
254
|
+
*/
|
|
255
|
+
|
|
256
|
+
export { IdGenerator, Scheduler, createFactoryToken, createValueToken, exportToCSV, exportToExcel, getOverallTransitionDuration, getTransitionDelay, getTransitionDuration, saveAs };
|
|
257
|
+
//# sourceMappingURL=cute-widgets-base-core-utils.mjs.map
|