clampography 2.0.0-beta.2 → 2.0.0-beta.4
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/package.json +1 -1
- package/src/index.js +8 -16
- package/src/theme-plugin.js +30 -24
- package/src/themes.js +4 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clampography",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.4",
|
|
4
4
|
"description": "Fluid typography system based on CSS clamp() with optional themes and extra styles. A feature-rich alternative to Tailwind CSS Typography plugin.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
package/src/index.js
CHANGED
|
@@ -20,54 +20,45 @@ export default plugin.withOptions((options = {}) => {
|
|
|
20
20
|
|
|
21
21
|
// Default values
|
|
22
22
|
let themesToInclude = [];
|
|
23
|
-
let defaultThemeName =
|
|
23
|
+
let defaultThemeName = null;
|
|
24
24
|
let prefersDarkTheme = false;
|
|
25
25
|
let rootSelector = options.root ?? ":root";
|
|
26
26
|
|
|
27
27
|
// Normalize input to an array of strings
|
|
28
|
-
// CSS might pass this as a single long string separated by commas
|
|
29
28
|
let rawThemeList = [];
|
|
30
29
|
|
|
31
30
|
if (typeof configThemes === "string") {
|
|
32
31
|
if (configThemes.trim() === "all") {
|
|
33
|
-
// Special case: themes: all
|
|
32
|
+
// Special case: themes: all -> load everything
|
|
34
33
|
rawThemeList = Object.keys(builtInThemes);
|
|
35
34
|
} else if (configThemes.trim() === "false") {
|
|
36
35
|
rawThemeList = [];
|
|
37
36
|
} else {
|
|
38
|
-
// Split by comma: "light --default, dark --prefersdark"
|
|
39
37
|
rawThemeList = configThemes.split(",");
|
|
40
38
|
}
|
|
41
39
|
} else if (Array.isArray(configThemes)) {
|
|
42
40
|
rawThemeList = configThemes;
|
|
43
41
|
} else {
|
|
44
|
-
//
|
|
45
|
-
|
|
42
|
+
// Fallback default is EMPTY array.
|
|
43
|
+
// User must explicitly ask for themes via options.
|
|
44
|
+
rawThemeList = [];
|
|
46
45
|
}
|
|
47
46
|
|
|
48
|
-
// 3. Process the list and look for flags
|
|
49
|
-
// If "all" was used, we don't look for flags (we use default light/dark logic) unless implemented otherwise.
|
|
50
|
-
// Here we focus on the explicit list.
|
|
51
|
-
|
|
47
|
+
// 3. Process the list and look for flags
|
|
52
48
|
rawThemeList.forEach((rawItem) => {
|
|
53
49
|
let themeName = rawItem.trim();
|
|
54
|
-
|
|
55
|
-
// Ignore empty entries
|
|
56
50
|
if (!themeName) return;
|
|
57
51
|
|
|
58
|
-
// Check for --default flag
|
|
59
52
|
if (themeName.includes("--default")) {
|
|
60
53
|
themeName = themeName.replace("--default", "").trim();
|
|
61
54
|
defaultThemeName = themeName;
|
|
62
55
|
}
|
|
63
56
|
|
|
64
|
-
// Check for --prefersdark flag (case insensitive just in case)
|
|
65
57
|
if (themeName.toLowerCase().includes("--prefersdark")) {
|
|
66
58
|
themeName = themeName.replace(/--prefersdark/i, "").trim();
|
|
67
59
|
prefersDarkTheme = themeName;
|
|
68
60
|
}
|
|
69
61
|
|
|
70
|
-
// Check if theme exists in the database
|
|
71
62
|
if (builtInThemes[themeName]) {
|
|
72
63
|
themesToInclude.push(themeName);
|
|
73
64
|
}
|
|
@@ -80,7 +71,8 @@ export default plugin.withOptions((options = {}) => {
|
|
|
80
71
|
const themeStyles = {};
|
|
81
72
|
|
|
82
73
|
// A. Default theme (:root)
|
|
83
|
-
if (
|
|
74
|
+
// Only applied if explicitly flagged with --default OR via manual logic (not applied here automatically anymore)
|
|
75
|
+
if (defaultThemeName && builtInThemes[defaultThemeName]) {
|
|
84
76
|
themeStyles[rootSelector] = builtInThemes[defaultThemeName];
|
|
85
77
|
}
|
|
86
78
|
|
package/src/theme-plugin.js
CHANGED
|
@@ -1,36 +1,30 @@
|
|
|
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
|
+
// Nowa opcja: color-scheme (defaults to 'light' 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
|
"surface": "--clampography-surface",
|
|
@@ -43,28 +37,40 @@ export default plugin.withOptions((options = {}) => {
|
|
|
43
37
|
"secondary": "--clampography-secondary",
|
|
44
38
|
};
|
|
45
39
|
|
|
40
|
+
// First, populate with fallback colors
|
|
41
|
+
Object.keys(fallbackTheme).forEach((key) => {
|
|
42
|
+
themeColors[key] = fallbackTheme[key];
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// Then override with user provided values
|
|
46
46
|
Object.keys(options).forEach((key) => {
|
|
47
|
-
//
|
|
47
|
+
// Ignore metadata keys
|
|
48
|
+
if (
|
|
49
|
+
["name", "default", "prefersdark", "root", "color-scheme"].includes(key)
|
|
50
|
+
) return;
|
|
51
|
+
|
|
48
52
|
if (keyMap[key]) {
|
|
49
53
|
themeColors[keyMap[key]] = options[key];
|
|
50
|
-
}
|
|
51
|
-
else if (key.startsWith("--")) {
|
|
54
|
+
} else if (key.startsWith("--")) {
|
|
52
55
|
themeColors[key] = options[key];
|
|
53
56
|
}
|
|
54
57
|
});
|
|
55
58
|
|
|
56
|
-
//
|
|
59
|
+
// Add the CSS property 'color-scheme' for browser UI adaptation (scrollbars, etc.)
|
|
60
|
+
themeColors["color-scheme"] = colorScheme;
|
|
61
|
+
|
|
62
|
+
// 4. Generate Styles
|
|
57
63
|
const styles = {};
|
|
58
64
|
|
|
59
|
-
// A. Define the theme as a named data-theme
|
|
65
|
+
// A. Define the theme as a named data-theme
|
|
60
66
|
styles[`[data-theme="${themeName}"]`] = themeColors;
|
|
61
67
|
|
|
62
|
-
// B. If
|
|
68
|
+
// B. If default, apply to root
|
|
63
69
|
if (isDefault) {
|
|
64
70
|
styles[rootSelector] = themeColors;
|
|
65
71
|
}
|
|
66
72
|
|
|
67
|
-
// C. If
|
|
73
|
+
// C. If prefers-dark, apply to media query
|
|
68
74
|
if (isPrefersDark) {
|
|
69
75
|
styles["@media (prefers-color-scheme: dark)"] = {
|
|
70
76
|
[rootSelector]: themeColors,
|
package/src/themes.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export const themes = {
|
|
2
2
|
light: {
|
|
3
|
+
"color-scheme": "light",
|
|
3
4
|
"--clampography-background": "#ffffff",
|
|
4
5
|
"--clampography-surface": "#f3f4f6",
|
|
5
6
|
"--clampography-border": "#e5e7eb",
|
|
@@ -11,6 +12,7 @@ export const themes = {
|
|
|
11
12
|
"--clampography-secondary": "#9333ea",
|
|
12
13
|
},
|
|
13
14
|
dark: {
|
|
15
|
+
"color-scheme": "dark",
|
|
14
16
|
"--clampography-background": "#0f172a",
|
|
15
17
|
"--clampography-surface": "#1e293b",
|
|
16
18
|
"--clampography-border": "#334155",
|
|
@@ -22,6 +24,7 @@ export const themes = {
|
|
|
22
24
|
"--clampography-secondary": "#a855f7",
|
|
23
25
|
},
|
|
24
26
|
retro: {
|
|
27
|
+
"color-scheme": "light",
|
|
25
28
|
"--clampography-background": "#ece3ca",
|
|
26
29
|
"--clampography-surface": "#e0d6b6",
|
|
27
30
|
"--clampography-border": "#cbbd99",
|
|
@@ -33,6 +36,7 @@ export const themes = {
|
|
|
33
36
|
"--clampography-secondary": "#f6c342",
|
|
34
37
|
},
|
|
35
38
|
cyberpunk: {
|
|
39
|
+
"color-scheme": "dark",
|
|
36
40
|
"--clampography-background": "#000b1e",
|
|
37
41
|
"--clampography-surface": "#051630",
|
|
38
42
|
"--clampography-border": "#0f3661",
|