clampography 2.0.0-beta.3 → 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 +30 -17
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,29 +3,42 @@ 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
|
-
let defaultThemeName =
|
|
37
|
+
let defaultThemeName = null;
|
|
24
38
|
let prefersDarkTheme = false;
|
|
25
39
|
let rootSelector = options.root ?? ":root";
|
|
26
40
|
|
|
27
41
|
// Normalize input to an array of strings
|
|
28
|
-
// CSS might pass this as a single long string separated by commas
|
|
29
42
|
let rawThemeList = [];
|
|
30
43
|
|
|
31
44
|
if (typeof configThemes === "string") {
|
|
@@ -33,22 +46,20 @@ export default plugin.withOptions((options = {}) => {
|
|
|
33
46
|
// Special case: themes: all
|
|
34
47
|
rawThemeList = Object.keys(builtInThemes);
|
|
35
48
|
} else if (configThemes.trim() === "false") {
|
|
49
|
+
// Explicitly disabled themes
|
|
36
50
|
rawThemeList = [];
|
|
37
51
|
} else {
|
|
38
|
-
// Split by comma: "light --default, dark --prefersdark"
|
|
39
52
|
rawThemeList = configThemes.split(",");
|
|
40
53
|
}
|
|
41
54
|
} else if (Array.isArray(configThemes)) {
|
|
42
55
|
rawThemeList = configThemes;
|
|
43
56
|
} else {
|
|
44
|
-
// Default
|
|
45
|
-
|
|
57
|
+
// Default behavior: NO themes loaded automatically.
|
|
58
|
+
// User must specify themes to load them.
|
|
59
|
+
rawThemeList = [];
|
|
46
60
|
}
|
|
47
61
|
|
|
48
62
|
// 3. Process the list and look for flags (--default, --prefersdark)
|
|
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
|
-
|
|
52
63
|
rawThemeList.forEach((rawItem) => {
|
|
53
64
|
let themeName = rawItem.trim();
|
|
54
65
|
|
|
@@ -61,7 +72,7 @@ export default plugin.withOptions((options = {}) => {
|
|
|
61
72
|
defaultThemeName = themeName;
|
|
62
73
|
}
|
|
63
74
|
|
|
64
|
-
// Check for --prefersdark flag
|
|
75
|
+
// Check for --prefersdark flag
|
|
65
76
|
if (themeName.toLowerCase().includes("--prefersdark")) {
|
|
66
77
|
themeName = themeName.replace(/--prefersdark/i, "").trim();
|
|
67
78
|
prefersDarkTheme = themeName;
|
|
@@ -74,13 +85,15 @@ export default plugin.withOptions((options = {}) => {
|
|
|
74
85
|
});
|
|
75
86
|
|
|
76
87
|
// If list is empty after filtering, stop here
|
|
77
|
-
if (
|
|
88
|
+
if (
|
|
89
|
+
themesToInclude.length === 0 && !defaultThemeName && !prefersDarkTheme
|
|
90
|
+
) return;
|
|
78
91
|
|
|
79
92
|
// 4. Generate CSS
|
|
80
93
|
const themeStyles = {};
|
|
81
94
|
|
|
82
95
|
// A. Default theme (:root)
|
|
83
|
-
if (builtInThemes[defaultThemeName]) {
|
|
96
|
+
if (defaultThemeName && builtInThemes[defaultThemeName]) {
|
|
84
97
|
themeStyles[rootSelector] = builtInThemes[defaultThemeName];
|
|
85
98
|
}
|
|
86
99
|
|