@celar-ui/svelte 0.3.1 → 0.3.2
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/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/utils.d.ts +4 -0
- package/dist/utils.js +41 -0
- package/package.json +1 -1
- package/src/styles/colors.scss +8 -10
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// Reexport your entry components here
|
|
2
|
+
export * from './utils.js';
|
|
2
3
|
export { default as TextButton } from './buttons/TextButton.svelte';
|
|
3
4
|
export { default as ElevatedButton } from './buttons/ElevatedButton.svelte';
|
|
4
5
|
export { default as FilledButton } from './buttons/FilledButton.svelte';
|
package/dist/utils.d.ts
ADDED
package/dist/utils.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Apply the chosen color scheme by traversing stylesheet rules and adjusting prefers-color-scheme media queries.
|
|
3
|
+
*/
|
|
4
|
+
export function applyPreferredColorScheme(scheme) {
|
|
5
|
+
for (const styleSheet of Array.from(document.styleSheets)) {
|
|
6
|
+
// Some stylesheets may be subject to CORS
|
|
7
|
+
let rules;
|
|
8
|
+
try {
|
|
9
|
+
rules = styleSheet.cssRules;
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
for (const rule of Array.from(rules)) {
|
|
15
|
+
if (rule instanceof CSSMediaRule && rule.media.mediaText.includes('prefers-color-scheme')) {
|
|
16
|
+
switch (scheme) {
|
|
17
|
+
case 'light':
|
|
18
|
+
rule.media.appendMedium('original-prefers-color-scheme');
|
|
19
|
+
if (rule.media.mediaText.includes('light'))
|
|
20
|
+
rule.media.deleteMedium('(prefers-color-scheme: light)');
|
|
21
|
+
if (rule.media.mediaText.includes('dark'))
|
|
22
|
+
rule.media.deleteMedium('(prefers-color-scheme: dark)');
|
|
23
|
+
break;
|
|
24
|
+
case 'dark':
|
|
25
|
+
rule.media.appendMedium('(prefers-color-scheme: light)');
|
|
26
|
+
rule.media.appendMedium('(prefers-color-scheme: dark)');
|
|
27
|
+
if (rule.media.mediaText.includes('original'))
|
|
28
|
+
rule.media.deleteMedium('original-prefers-color-scheme');
|
|
29
|
+
break;
|
|
30
|
+
default: // auto
|
|
31
|
+
rule.media.appendMedium('(prefers-color-scheme: dark)');
|
|
32
|
+
if (rule.media.mediaText.includes('light'))
|
|
33
|
+
rule.media.deleteMedium('(prefers-color-scheme: light)');
|
|
34
|
+
if (rule.media.mediaText.includes('original'))
|
|
35
|
+
rule.media.deleteMedium('original-prefers-color-scheme');
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
package/package.json
CHANGED
package/src/styles/colors.scss
CHANGED
|
@@ -51,7 +51,7 @@ $colors-theme-dark: (
|
|
|
51
51
|
color-text-warning: #bfa060,
|
|
52
52
|
color-text-danger: #b36a6a,
|
|
53
53
|
|
|
54
|
-
color-bg: #
|
|
54
|
+
color-bg: #1a1a1a,
|
|
55
55
|
color-bg-info: #101a3b,
|
|
56
56
|
color-bg-success: #184d3a,
|
|
57
57
|
color-bg-warning: #4a3700,
|
|
@@ -59,10 +59,10 @@ $colors-theme-dark: (
|
|
|
59
59
|
) !default;
|
|
60
60
|
|
|
61
61
|
$colors-misc: (
|
|
62
|
-
color-shadow--soft: rgba(
|
|
63
|
-
color-shadow--md: rgba(
|
|
64
|
-
color-shadow: rgba(
|
|
65
|
-
color-shadow--strong: rgba(
|
|
62
|
+
color-shadow--soft: rgba(var(--color-text--rgb), 0.05),
|
|
63
|
+
color-shadow--md: rgba(var(--color-text--rgb), 0.075),
|
|
64
|
+
color-shadow: rgba(var(--color-text--rgb), 0.1),
|
|
65
|
+
color-shadow--strong: rgba(var(--color-text--rgb), 0.16),
|
|
66
66
|
color-border: rgba(var(--color-text--rgb), 0.07),
|
|
67
67
|
color-border--strong: rgba(var(--color-text--rgb), 0.1),
|
|
68
68
|
color-wrapper: rgba(var(--color-text--rgb), 0.024)
|
|
@@ -73,12 +73,10 @@ $colors-misc: (
|
|
|
73
73
|
@include utils.add_prefix(config.$prefix, $colors-misc);
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
:
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
76
|
+
// Based on this to dynamically switch the interface:
|
|
77
|
+
// https://stackoverflow.com/a/75124760
|
|
80
78
|
@media (prefers-color-scheme: dark) {
|
|
81
|
-
:root
|
|
79
|
+
:root {
|
|
82
80
|
@include utils.generate_colors(config.$prefix, $colors-theme-dark);
|
|
83
81
|
}
|
|
84
82
|
}
|