clampography 2.0.0-beta.4 → 2.0.0-beta.5
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 +33 -12
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.5",
|
|
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
|
@@ -3,22 +3,36 @@ import { themes as builtInThemes } from "./themes.js";
|
|
|
3
3
|
import baseStyles from "./base.js";
|
|
4
4
|
import extraStyles from "./extra.js";
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Helper to resolve boolean options from CSS configuration.
|
|
8
|
+
* CSS values often come as strings ("true"/"false"), which are both truthy in JS.
|
|
9
|
+
*/
|
|
10
|
+
const resolveBool = (value, defaultValue) => {
|
|
11
|
+
if (value === "false" || value === false) return false;
|
|
12
|
+
if (value === "true" || value === true) return true;
|
|
13
|
+
return defaultValue;
|
|
14
|
+
};
|
|
15
|
+
|
|
6
16
|
/**
|
|
7
17
|
* Main plugin function.
|
|
8
18
|
*/
|
|
9
19
|
export default plugin.withOptions((options = {}) => {
|
|
10
20
|
return ({ addBase }) => {
|
|
11
21
|
// 1. Load Base and Extra styles
|
|
12
|
-
|
|
13
|
-
const
|
|
22
|
+
// We use the helper to correctly parse "false" string from CSS
|
|
23
|
+
const includeBase = resolveBool(options.base, true); // Default: true
|
|
24
|
+
const includeExtra = resolveBool(options.extra, false); // Default: false
|
|
25
|
+
|
|
26
|
+
if (includeBase) {
|
|
27
|
+
addBase(baseStyles);
|
|
28
|
+
}
|
|
14
29
|
|
|
15
|
-
if (
|
|
16
|
-
|
|
30
|
+
if (includeExtra) {
|
|
31
|
+
addBase(extraStyles);
|
|
32
|
+
}
|
|
17
33
|
|
|
18
34
|
// 2. Parse themes configuration
|
|
19
35
|
let configThemes = options.themes;
|
|
20
|
-
|
|
21
|
-
// Default values
|
|
22
36
|
let themesToInclude = [];
|
|
23
37
|
let defaultThemeName = null;
|
|
24
38
|
let prefersDarkTheme = false;
|
|
@@ -29,9 +43,10 @@ export default plugin.withOptions((options = {}) => {
|
|
|
29
43
|
|
|
30
44
|
if (typeof configThemes === "string") {
|
|
31
45
|
if (configThemes.trim() === "all") {
|
|
32
|
-
// Special case: themes: all
|
|
46
|
+
// Special case: themes: all
|
|
33
47
|
rawThemeList = Object.keys(builtInThemes);
|
|
34
48
|
} else if (configThemes.trim() === "false") {
|
|
49
|
+
// Explicitly disabled themes
|
|
35
50
|
rawThemeList = [];
|
|
36
51
|
} else {
|
|
37
52
|
rawThemeList = configThemes.split(",");
|
|
@@ -39,39 +54,45 @@ export default plugin.withOptions((options = {}) => {
|
|
|
39
54
|
} else if (Array.isArray(configThemes)) {
|
|
40
55
|
rawThemeList = configThemes;
|
|
41
56
|
} else {
|
|
42
|
-
//
|
|
43
|
-
// User must
|
|
57
|
+
// Default behavior: NO themes loaded automatically.
|
|
58
|
+
// User must specify themes to load them.
|
|
44
59
|
rawThemeList = [];
|
|
45
60
|
}
|
|
46
61
|
|
|
47
|
-
// 3. Process the list and look for flags
|
|
62
|
+
// 3. Process the list and look for flags (--default, --prefersdark)
|
|
48
63
|
rawThemeList.forEach((rawItem) => {
|
|
49
64
|
let themeName = rawItem.trim();
|
|
65
|
+
|
|
66
|
+
// Ignore empty entries
|
|
50
67
|
if (!themeName) return;
|
|
51
68
|
|
|
69
|
+
// Check for --default flag
|
|
52
70
|
if (themeName.includes("--default")) {
|
|
53
71
|
themeName = themeName.replace("--default", "").trim();
|
|
54
72
|
defaultThemeName = themeName;
|
|
55
73
|
}
|
|
56
74
|
|
|
75
|
+
// Check for --prefersdark flag
|
|
57
76
|
if (themeName.toLowerCase().includes("--prefersdark")) {
|
|
58
77
|
themeName = themeName.replace(/--prefersdark/i, "").trim();
|
|
59
78
|
prefersDarkTheme = themeName;
|
|
60
79
|
}
|
|
61
80
|
|
|
81
|
+
// Check if theme exists in the database
|
|
62
82
|
if (builtInThemes[themeName]) {
|
|
63
83
|
themesToInclude.push(themeName);
|
|
64
84
|
}
|
|
65
85
|
});
|
|
66
86
|
|
|
67
87
|
// If list is empty after filtering, stop here
|
|
68
|
-
if (
|
|
88
|
+
if (
|
|
89
|
+
themesToInclude.length === 0 && !defaultThemeName && !prefersDarkTheme
|
|
90
|
+
) return;
|
|
69
91
|
|
|
70
92
|
// 4. Generate CSS
|
|
71
93
|
const themeStyles = {};
|
|
72
94
|
|
|
73
95
|
// A. Default theme (:root)
|
|
74
|
-
// Only applied if explicitly flagged with --default OR via manual logic (not applied here automatically anymore)
|
|
75
96
|
if (defaultThemeName && builtInThemes[defaultThemeName]) {
|
|
76
97
|
themeStyles[rootSelector] = builtInThemes[defaultThemeName];
|
|
77
98
|
}
|