clampography 2.0.0-beta.2 → 2.0.0-beta.3

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clampography",
3
- "version": "2.0.0-beta.2",
3
+ "version": "2.0.0-beta.3",
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",
@@ -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; // lowercase because CSS might force it
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. 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
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
- // Check if it's one of our mapped short keys
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
- } // Or if it is already a custom property key (starts with --)
51
- else if (key.startsWith("--")) {
54
+ } else if (key.startsWith("--")) {
52
55
  themeColors[key] = options[key];
53
56
  }
54
57
  });
55
58
 
56
- // 3. Generate Styles
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 (always available)
65
+ // A. Define the theme as a named data-theme
60
66
  styles[`[data-theme="${themeName}"]`] = themeColors;
61
67
 
62
- // B. If marked as default, apply to :root
68
+ // B. If default, apply to root
63
69
  if (isDefault) {
64
70
  styles[rootSelector] = themeColors;
65
71
  }
66
72
 
67
- // C. If marked as prefers-dark, apply to media query
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",