@apexshift/tailwindcss-fluid-typography 0.0.2 → 0.0.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.
Files changed (2) hide show
  1. package/index.mjs +48 -9
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -2,10 +2,10 @@
2
2
  import plugin from 'tailwindcss/plugin.js';
3
3
 
4
4
  const defaultConfig = {
5
- minViewport: 375,
6
- maxViewport: 1440,
7
- rootFontSize: 10, // your 62.5% root → 1rem = 10px
8
- prefix: 'fluid-',
5
+ minViewport: 375, // px – typical mobile
6
+ maxViewport: 1440, // px – typical desktop/large
7
+ rootFontSize: 10, // px – matches html { font-size: 62.5%; } → 1rem = 10px
8
+ prefix: 'fluid-', // class prefix: text-fluid-base, etc.
9
9
  sizes: {
10
10
  xs: { min: 12, max: 14 },
11
11
  sm: { min: 14, max: 16 },
@@ -20,19 +20,57 @@ const defaultConfig = {
20
20
  };
21
21
 
22
22
  export default plugin.withOptions(
23
- // Plugin implementation
23
+ // 1. Plugin implementation (runs when Tailwind processes CSS)
24
24
  function (options = {}) {
25
25
  return function ({ addUtilities, theme }) {
26
+ console.log('[FLUID] Raw options received:', JSON.stringify(options, null, 2));
27
+ console.log('[FLUID] Detected flat size keys:', Object.keys(options).filter(k => k.startsWith('size-')));
28
+ console.log('[FLUID] Final config.rootFontSize:', config.rootFontSize);
29
+ console.log('[FLUID] Final config.minViewport:', config.minViewport);
30
+ console.log('[FLUID] Final config.maxViewport:', config.maxViewport);
31
+ console.log('[FLUID] Final config.sizes.base:', config.sizes.base);
32
+
33
+ // In development, log when plugin is actually executed
34
+ if (process.env.NODE_ENV !== 'production') {
35
+ console.log('[tailwindcss-fluid-typography] Plugin is running');
36
+ console.log('[tailwindcss-fluid-typography] Received options:', options);
37
+ }
38
+
39
+ // Merge config – support both nested sizes (config file) and flat keys (CSS @plugin)
26
40
  const config = {
27
41
  ...defaultConfig,
28
42
  ...options,
29
- sizes: { ...defaultConfig.sizes, ...options?.sizes },
43
+ sizes: { ...defaultConfig.sizes },
30
44
  };
31
45
 
46
+ // 1. If user provided nested sizes object (tailwind.config.js/mjs)
47
+ if (options.sizes && typeof options.sizes === 'object') {
48
+ config.sizes = { ...config.sizes, ...options.sizes };
49
+ }
50
+
51
+ // 2. Support flat keys from @plugin { size-base-min: 17; size-base-max: 23; ... }
52
+ Object.keys(options).forEach((key) => {
53
+ if (key.startsWith('size-')) {
54
+ const parts = key.split('-');
55
+ if (parts.length === 3) {
56
+ const [, sizeKey, prop] = parts; // size-base-min → base, min
57
+ if (prop === 'min' || prop === 'max') {
58
+ if (!config.sizes[sizeKey]) config.sizes[sizeKey] = {};
59
+ config.sizes[sizeKey][prop] = Number(options[key]);
60
+ }
61
+ }
62
+ }
63
+ });
64
+
32
65
  const utilities = {};
33
66
 
34
- Object.entries(config.sizes).forEach(([key, { min: minPx, max: maxPx }]) => {
35
- if (typeof minPx !== 'number' || typeof maxPx !== 'number') return;
67
+ Object.entries(config.sizes).forEach(([key, value]) => {
68
+ const { min: minPx, max: maxPx } = value;
69
+
70
+ // Skip invalid entries
71
+ if (typeof minPx !== 'number' || typeof maxPx !== 'number' || minPx >= maxPx) {
72
+ return;
73
+ }
36
74
 
37
75
  const minRem = minPx / config.rootFontSize;
38
76
  const maxRem = maxPx / config.rootFontSize;
@@ -49,11 +87,12 @@ export default plugin.withOptions(
49
87
  };
50
88
  });
51
89
 
90
+ // Add the generated utilities (with responsive variants)
52
91
  addUtilities(utilities, ['responsive']);
53
92
  };
54
93
  },
55
94
 
56
- // Theme extension (so users can override via tailwind.config.mjs)
95
+ // 2. Theme extension still useful for config-file users
57
96
  function (options = {}) {
58
97
  return {
59
98
  theme: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apexshift/tailwindcss-fluid-typography",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "Tailwind CSS plugin for automatic fluid typography using clamp()",
5
5
  "type": "module",
6
6
  "main": "./index.mjs",