@apexshift/tailwindcss-fluid-typography 0.0.1 → 0.0.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/index.mjs +41 -9
- 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,
|
|
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,50 @@ 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
|
+
// In development, log when plugin is actually executed
|
|
27
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
28
|
+
console.log('[tailwindcss-fluid-typography] Plugin is running');
|
|
29
|
+
console.log('[tailwindcss-fluid-typography] Received options:', options);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Merge config – support both nested sizes (config file) and flat keys (CSS @plugin)
|
|
26
33
|
const config = {
|
|
27
34
|
...defaultConfig,
|
|
28
35
|
...options,
|
|
29
|
-
sizes: { ...defaultConfig.sizes
|
|
36
|
+
sizes: { ...defaultConfig.sizes },
|
|
30
37
|
};
|
|
31
38
|
|
|
39
|
+
// 1. If user provided nested sizes object (tailwind.config.js/mjs)
|
|
40
|
+
if (options.sizes && typeof options.sizes === 'object') {
|
|
41
|
+
config.sizes = { ...config.sizes, ...options.sizes };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// 2. Support flat keys from @plugin { size-base-min: 17; size-base-max: 23; ... }
|
|
45
|
+
Object.keys(options).forEach((key) => {
|
|
46
|
+
if (key.startsWith('size-')) {
|
|
47
|
+
const parts = key.split('-');
|
|
48
|
+
if (parts.length === 3) {
|
|
49
|
+
const [, sizeKey, prop] = parts; // size-base-min → base, min
|
|
50
|
+
if (prop === 'min' || prop === 'max') {
|
|
51
|
+
if (!config.sizes[sizeKey]) config.sizes[sizeKey] = {};
|
|
52
|
+
config.sizes[sizeKey][prop] = Number(options[key]);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
32
58
|
const utilities = {};
|
|
33
59
|
|
|
34
|
-
Object.entries(config.sizes).forEach(([key,
|
|
35
|
-
|
|
60
|
+
Object.entries(config.sizes).forEach(([key, value]) => {
|
|
61
|
+
const { min: minPx, max: maxPx } = value;
|
|
62
|
+
|
|
63
|
+
// Skip invalid entries
|
|
64
|
+
if (typeof minPx !== 'number' || typeof maxPx !== 'number' || minPx >= maxPx) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
36
67
|
|
|
37
68
|
const minRem = minPx / config.rootFontSize;
|
|
38
69
|
const maxRem = maxPx / config.rootFontSize;
|
|
@@ -49,11 +80,12 @@ export default plugin.withOptions(
|
|
|
49
80
|
};
|
|
50
81
|
});
|
|
51
82
|
|
|
83
|
+
// Add the generated utilities (with responsive variants)
|
|
52
84
|
addUtilities(utilities, ['responsive']);
|
|
53
85
|
};
|
|
54
86
|
},
|
|
55
87
|
|
|
56
|
-
// Theme extension
|
|
88
|
+
// 2. Theme extension – still useful for config-file users
|
|
57
89
|
function (options = {}) {
|
|
58
90
|
return {
|
|
59
91
|
theme: {
|