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.
@@ -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; // lowercase because CSS might force it
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. Extract colors from options
26
- // We iterate over the options object and pick anything that looks like our CSS variable
27
- // or simply take all known keys.
28
- const themeColors = {};
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
- // You can also support short aliases here if you want (e.g., 'primary' -> '--clampography-primary')
31
- // For now, let's assume user passes full variable names or mapped keys.
24
+ // 3. Extract & Merge Colors
25
+ const themeColors = {};
32
26
 
33
- // Helper to map simplified keys to full CSS vars (optional convenience)
27
+ // Mapping of simplified keys to full CSS variable names
34
28
  const keyMap = {
35
29
  "background": "--clampography-background",
36
- "text": "--clampography-text",
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
- // Check if it's one of our mapped short keys
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
- } // Or if it is already a custom property key (starts with --)
47
- else if (key.startsWith("--")) {
58
+ } else if (key.startsWith("--")) {
48
59
  themeColors[key] = options[key];
49
60
  }
50
61
  });
51
62
 
52
- // 3. Generate Styles
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 (always available)
69
+ // A. Define the theme as a named data-theme
56
70
  styles[`[data-theme="${themeName}"]`] = themeColors;
57
71
 
58
- // B. If marked as default, apply to :root
72
+ // B. If default, apply to root
59
73
  if (isDefault) {
60
74
  styles[rootSelector] = themeColors;
61
75
  }
62
76
 
63
- // C. If marked as prefers-dark, apply to media query
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
- "--clampography-background": "#ffffff",
4
- "--clampography-text": "#1f2937",
5
- "--clampography-link": "#2563eb",
6
- "--clampography-primary": "#3b82f6",
7
- "--clampography-secondary": "#9333ea",
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
- "--clampography-background": "#0f172a",
11
- "--clampography-text": "#f3f4f6",
12
- "--clampography-link": "#60a5fa",
13
- "--clampography-primary": "#3b82f6",
14
- "--clampography-secondary": "#a855f7",
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
- "--clampography-background": "#ece3ca",
18
- "--clampography-text": "#2c2420",
19
- "--clampography-link": "#d97757",
20
- "--clampography-primary": "#e45f2b",
21
- "--clampography-secondary": "#f6c342",
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
- "--clampography-background": "#000b1e",
25
- "--clampography-text": "#00f0ff",
26
- "--clampography-link": "#ff0099",
27
- "--clampography-primary": "#fcee0a",
28
- "--clampography-secondary": "#05ffa1",
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