@nemigo/tailwind 0.0.1

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.
@@ -0,0 +1,4 @@
1
+ import plugin from "tailwindcss/plugin";
2
+ type Plugin = ReturnType<typeof plugin>;
3
+ declare const main: Plugin;
4
+ export default main;
package/dist/fluid.js ADDED
@@ -0,0 +1,100 @@
1
+ import plugin from "tailwindcss/plugin";
2
+ const getConfigScreens = (cfg) => {
3
+ const theme = cfg["theme"];
4
+ if (!theme)
5
+ return null;
6
+ const screens = theme["screens"];
7
+ if (!screens)
8
+ return null;
9
+ const medias = Object.values(screens).filter((v) => typeof v === "string");
10
+ if (medias.length <= 1)
11
+ return null;
12
+ const digitRegExp = /\D/g;
13
+ const converter = (v) => Number(v.replace(digitRegExp, ""));
14
+ const sorted = medias.map(converter).toSorted((a, b) => a - b);
15
+ const min = sorted[0];
16
+ const max = sorted[sorted.length - 1];
17
+ const diff = max - min;
18
+ return { min, max, diff };
19
+ };
20
+ const manual = (v) => isNaN(Number(v));
21
+ const unit = (v, unit) => (manual(v) ? v : v + unit);
22
+ const main = plugin((api) => {
23
+ const screens = getConfigScreens(api.config());
24
+ if (!screens)
25
+ return;
26
+ api.addBase({ ":root": { "--V": `calc((100vw - ${screens.min}em) / ${screens.diff})` } });
27
+ const clamp = (v, property, util) => {
28
+ const rule = {};
29
+ if (v.includes("~")) {
30
+ const [_min, _max] = v.split("~");
31
+ if (_min.startsWith("0.") || _max.startsWith("0.")) {
32
+ if (!_max.startsWith("0."))
33
+ console.warn("Tailwind:", `Use ${util}-[${_min.slice(1)}~${_max}] instead ${util}-[${v}]`);
34
+ else if (!_min.startsWith("0."))
35
+ console.warn("Tailwind:", `Use ${util}-[${_min}~${_max.slice(1)}] instead ${util}-[${v}]`);
36
+ else
37
+ console.warn("Tailwind:", `Use ${util}-[${_min.slice(1)}~${_max.slice(1)}] instead ${util}-[${v}]`);
38
+ }
39
+ const max = Number(_max) || 0;
40
+ const min = Number(_min) || 0;
41
+ const rounded = Number((max - min).toFixed(3));
42
+ const adaptive = `calc(var(--V) * ${rounded} + ${min}em)`;
43
+ rule[property] = `clamp(${min}em,${adaptive},${max}em)`;
44
+ }
45
+ else {
46
+ rule[property] = unit(v, "em");
47
+ }
48
+ return rule;
49
+ };
50
+ const createUtilities = (arr) => {
51
+ const acc = {};
52
+ for (const [util, property] of arr) {
53
+ acc[util] = (v) => clamp(v, property, util);
54
+ }
55
+ return acc;
56
+ };
57
+ api.matchUtilities(createUtilities([
58
+ ["v-fs", "fontSize"],
59
+ ["v-gap", "gap"],
60
+ //...
61
+ ["v-inset", "inset"],
62
+ ["v-top", "top"],
63
+ ["v-bottom", "bottom"],
64
+ ["v-left", "left"],
65
+ ["v-right", "right"],
66
+ //...
67
+ ["v-w", "width"],
68
+ ["v-h", "height"],
69
+ ["v-min-w", "minWidth"],
70
+ ["v-max-w", "maxWidth"],
71
+ ["v-min-h", "minHeight"],
72
+ ["v-max-h", "maxHeight"],
73
+ //...
74
+ ["v-p", "padding"],
75
+ ["v-py", "padding-block"],
76
+ ["v-pt", "padding-top"],
77
+ ["v-pb", "padding-bottom"],
78
+ ["v-px", "padding-inline"],
79
+ ["v-pl", "padding-left"],
80
+ ["v-pr", "padding-right"],
81
+ //...
82
+ ["v-m", "margin"],
83
+ ["v-my", "margin-block"],
84
+ ["v-mt", "margin-top"],
85
+ ["v-mb", "margin-bottom"],
86
+ ["v-mx", "margin-inline"],
87
+ ["v-ml", "margin-left"],
88
+ ["v-mr", "margin-right"],
89
+ //...
90
+ ["v-br", "borderRadius"],
91
+ ["v-br-t", "borderTopRadius"],
92
+ ["v-br-b", "borderBottomRadius"],
93
+ ["v-br-l", "borderLeftRadius"],
94
+ ["v-br-r", "borderRightRadius"],
95
+ //...
96
+ ["v-tt-x", "translateX"],
97
+ ["v-tt-y", "translateY"],
98
+ ]));
99
+ });
100
+ export default main;
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@nemigo/tailwind",
3
+ "version": "0.0.1",
4
+ "private": false,
5
+ "author": {
6
+ "name": "Vlad Logvin",
7
+ "email": "vlad.logvin84@gmail.com"
8
+ },
9
+ "type": "module",
10
+ "scripts": {
11
+ "build": "svelte-package && rimraf .svelte-kit",
12
+ "check": "tsc --noemit",
13
+ "lint": "eslint ./",
14
+ "format": "prettier --write ./"
15
+ },
16
+ "exports": {
17
+ "./fluid": {
18
+ "types": "./dist/fluid.d.ts",
19
+ "default": "./dist/fluid.js"
20
+ }
21
+ },
22
+ "peerDependencies": {
23
+ "tailwindcss": ">=4.0.0"
24
+ },
25
+ "devDependencies": {
26
+ "@nemigo/configs": "workspace:*",
27
+ "tailwindcss": "4.1.13"
28
+ }
29
+ }