clampography 2.0.0-beta.1 → 2.0.0-beta.11
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 +2 -0
- package/package.json +1 -1
- package/src/base.css +583 -0
- package/src/base.js +181 -136
- package/src/convert.js +185 -0
- package/src/extra.js +152 -16
- package/src/index.js +121 -87
- package/src/theme-plugin.js +39 -25
- package/src/themes.js +56 -20
package/src/theme-plugin.js
CHANGED
|
@@ -1,66 +1,80 @@
|
|
|
1
1
|
import plugin from "tailwindcss/plugin";
|
|
2
|
-
|
|
3
|
-
// List of required color keys for validation (optional but good practice)
|
|
4
|
-
const REQUIRED_KEYS = [
|
|
5
|
-
"--clampography-background",
|
|
6
|
-
"--clampography-text",
|
|
7
|
-
"--clampography-link",
|
|
8
|
-
"--clampography-primary",
|
|
9
|
-
"--clampography-secondary",
|
|
10
|
-
];
|
|
2
|
+
import { themes as builtInThemes } from "./themes.js";
|
|
11
3
|
|
|
12
4
|
export default plugin.withOptions((options = {}) => {
|
|
13
5
|
return ({ addBase }) => {
|
|
14
6
|
// 1. Extract metadata
|
|
15
7
|
const themeName = options.name;
|
|
16
8
|
const isDefault = options.default ?? false;
|
|
17
|
-
const isPrefersDark = options.prefersdark ?? false;
|
|
9
|
+
const isPrefersDark = options.prefersdark ?? false;
|
|
18
10
|
const rootSelector = options.root ?? ":root";
|
|
11
|
+
// Defaults to light scheme if not specified
|
|
12
|
+
const colorScheme = options["color-scheme"] ?? "light";
|
|
19
13
|
|
|
20
14
|
if (!themeName) {
|
|
21
15
|
console.warn("Clampography: Theme definition missing 'name' property.");
|
|
22
16
|
return;
|
|
23
17
|
}
|
|
24
18
|
|
|
25
|
-
// 2.
|
|
26
|
-
// We
|
|
27
|
-
//
|
|
28
|
-
const
|
|
19
|
+
// 2. Prepare Base Colors (Fallback)
|
|
20
|
+
// We fetch the full palette of the requested color scheme (light/dark)
|
|
21
|
+
// to fill in any missing gaps in the user's definition.
|
|
22
|
+
const fallbackTheme = builtInThemes[colorScheme] || builtInThemes["light"];
|
|
29
23
|
|
|
30
|
-
//
|
|
31
|
-
|
|
24
|
+
// 3. Extract & Merge Colors
|
|
25
|
+
const themeColors = {};
|
|
32
26
|
|
|
33
|
-
//
|
|
27
|
+
// Mapping of simplified keys to full CSS variable names
|
|
34
28
|
const keyMap = {
|
|
35
29
|
"background": "--clampography-background",
|
|
36
|
-
"
|
|
30
|
+
"border": "--clampography-border",
|
|
31
|
+
"error": "--clampography-error",
|
|
32
|
+
"heading": "--clampography-heading",
|
|
33
|
+
"info": "--clampography-info",
|
|
37
34
|
"link": "--clampography-link",
|
|
35
|
+
"muted": "--clampography-muted",
|
|
38
36
|
"primary": "--clampography-primary",
|
|
39
37
|
"secondary": "--clampography-secondary",
|
|
38
|
+
"success": "--clampography-success",
|
|
39
|
+
"surface": "--clampography-surface",
|
|
40
|
+
"text": "--clampography-text",
|
|
41
|
+
"warning": "--clampography-warning",
|
|
40
42
|
};
|
|
41
43
|
|
|
44
|
+
// First, populate with fallback colors
|
|
45
|
+
Object.keys(fallbackTheme).forEach((key) => {
|
|
46
|
+
themeColors[key] = fallbackTheme[key];
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// Then override with user provided values
|
|
42
50
|
Object.keys(options).forEach((key) => {
|
|
43
|
-
//
|
|
51
|
+
// Ignore metadata keys
|
|
52
|
+
if (
|
|
53
|
+
["name", "default", "prefersdark", "root", "color-scheme"].includes(key)
|
|
54
|
+
) return;
|
|
55
|
+
|
|
44
56
|
if (keyMap[key]) {
|
|
45
57
|
themeColors[keyMap[key]] = options[key];
|
|
46
|
-
}
|
|
47
|
-
else if (key.startsWith("--")) {
|
|
58
|
+
} else if (key.startsWith("--")) {
|
|
48
59
|
themeColors[key] = options[key];
|
|
49
60
|
}
|
|
50
61
|
});
|
|
51
62
|
|
|
52
|
-
//
|
|
63
|
+
// Add the CSS property 'color-scheme' for browser UI adaptation (scrollbars, etc.)
|
|
64
|
+
themeColors["color-scheme"] = colorScheme;
|
|
65
|
+
|
|
66
|
+
// 4. Generate Styles
|
|
53
67
|
const styles = {};
|
|
54
68
|
|
|
55
|
-
// A. Define the theme as a named data-theme
|
|
69
|
+
// A. Define the theme as a named data-theme
|
|
56
70
|
styles[`[data-theme="${themeName}"]`] = themeColors;
|
|
57
71
|
|
|
58
|
-
// B. If
|
|
72
|
+
// B. If default, apply to root
|
|
59
73
|
if (isDefault) {
|
|
60
74
|
styles[rootSelector] = themeColors;
|
|
61
75
|
}
|
|
62
76
|
|
|
63
|
-
// C. If
|
|
77
|
+
// C. If prefers-dark, apply to media query
|
|
64
78
|
if (isPrefersDark) {
|
|
65
79
|
styles["@media (prefers-color-scheme: dark)"] = {
|
|
66
80
|
[rootSelector]: themeColors,
|
package/src/themes.js
CHANGED
|
@@ -1,31 +1,67 @@
|
|
|
1
1
|
export const themes = {
|
|
2
2
|
light: {
|
|
3
|
-
"
|
|
4
|
-
"--clampography-
|
|
5
|
-
"--clampography-
|
|
6
|
-
"--clampography-
|
|
7
|
-
"--clampography-
|
|
3
|
+
"color-scheme": "light",
|
|
4
|
+
"--clampography-background": "100% 0 0",
|
|
5
|
+
"--clampography-border": "92% 0.003 264",
|
|
6
|
+
"--clampography-error": "63% 0.22 27",
|
|
7
|
+
"--clampography-heading": "15% 0.02 264",
|
|
8
|
+
"--clampography-info": "63% 0.258 262",
|
|
9
|
+
"--clampography-link": "43% 0.19 264",
|
|
10
|
+
"--clampography-muted": "52% 0.014 258",
|
|
11
|
+
"--clampography-primary": "63% 0.258 262",
|
|
12
|
+
"--clampography-secondary": "55% 0.28 300",
|
|
13
|
+
"--clampography-success": "65% 0.17 165",
|
|
14
|
+
"--clampography-surface": "96% 0.003 264",
|
|
15
|
+
"--clampography-text": "31% 0.02 257",
|
|
16
|
+
"--clampography-warning": "72% 0.17 65",
|
|
8
17
|
},
|
|
9
18
|
dark: {
|
|
10
|
-
"
|
|
11
|
-
"--clampography-
|
|
12
|
-
"--clampography-
|
|
13
|
-
"--clampography-
|
|
14
|
-
"--clampography-
|
|
19
|
+
"color-scheme": "dark",
|
|
20
|
+
"--clampography-background": "10% 0 0",
|
|
21
|
+
"--clampography-border": "31% 0.03 254",
|
|
22
|
+
"--clampography-error": "63% 0.22 27",
|
|
23
|
+
"--clampography-heading": "98% 0.003 264",
|
|
24
|
+
"--clampography-info": "72% 0.17 254",
|
|
25
|
+
"--clampography-link": "72% 0.17 254",
|
|
26
|
+
"--clampography-muted": "68% 0.024 254",
|
|
27
|
+
"--clampography-primary": "63% 0.258 262",
|
|
28
|
+
"--clampography-secondary": "63% 0.25 300",
|
|
29
|
+
"--clampography-success": "65% 0.17 165",
|
|
30
|
+
"--clampography-surface": "12% 0 0",
|
|
31
|
+
"--clampography-text": "95% 0 0",
|
|
32
|
+
"--clampography-warning": "72% 0.17 65",
|
|
15
33
|
},
|
|
16
34
|
retro: {
|
|
17
|
-
"
|
|
18
|
-
"--clampography-
|
|
19
|
-
"--clampography-
|
|
20
|
-
"--clampography-
|
|
21
|
-
"--clampography-
|
|
35
|
+
"color-scheme": "light",
|
|
36
|
+
"--clampography-background": "91% 0.03 85",
|
|
37
|
+
"--clampography-border": "78% 0.05 85",
|
|
38
|
+
"--clampography-error": "52% 0.15 35",
|
|
39
|
+
"--clampography-heading": "18% 0.02 35",
|
|
40
|
+
"--clampography-info": "60% 0.06 230",
|
|
41
|
+
"--clampography-link": "63% 0.13 40",
|
|
42
|
+
"--clampography-muted": "44% 0.03 45",
|
|
43
|
+
"--clampography-primary": "60% 0.19 35",
|
|
44
|
+
"--clampography-secondary": "80% 0.14 85",
|
|
45
|
+
"--clampography-success": "62% 0.10 130",
|
|
46
|
+
"--clampography-surface": "87% 0.04 85",
|
|
47
|
+
"--clampography-text": "28% 0.03 40",
|
|
48
|
+
"--clampography-warning": "80% 0.14 85",
|
|
22
49
|
},
|
|
23
50
|
cyberpunk: {
|
|
24
|
-
"
|
|
25
|
-
"--clampography-
|
|
26
|
-
"--clampography-
|
|
27
|
-
"--clampography-
|
|
28
|
-
"--clampography-
|
|
51
|
+
"color-scheme": "dark",
|
|
52
|
+
"--clampography-background": "8% 0.04 264",
|
|
53
|
+
"--clampography-border": "27% 0.09 254",
|
|
54
|
+
"--clampography-error": "60% 0.29 340",
|
|
55
|
+
"--clampography-heading": "100% 0 0",
|
|
56
|
+
"--clampography-info": "88% 0.16 195",
|
|
57
|
+
"--clampography-link": "60% 0.29 340",
|
|
58
|
+
"--clampography-muted": "55% 0.07 200",
|
|
59
|
+
"--clampography-primary": "93% 0.22 105",
|
|
60
|
+
"--clampography-secondary": "87% 0.20 165",
|
|
61
|
+
"--clampography-success": "87% 0.20 165",
|
|
62
|
+
"--clampography-surface": "12% 0.05 264",
|
|
63
|
+
"--clampography-text": "88% 0.16 195",
|
|
64
|
+
"--clampography-warning": "93% 0.22 105",
|
|
29
65
|
},
|
|
30
66
|
};
|
|
31
67
|
|