tailwind-clamp-merge 4.2.2
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/LICENSE +21 -0
- package/README.md +54 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +125 -0
- package/dist/index.js.map +1 -0
- package/dist/index.umd.cjs +2 -0
- package/dist/index.umd.cjs.map +1 -0
- package/package.json +52 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Nicolas Cusan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# tailwind-clamp-merge
|
|
2
|
+
|
|
3
|
+
A [tailwind-merge](https://github.com/dcastil/tailwind-merge) plugin for [tailwind-clamp](https://github.com/nicolas-cusan/tailwind-clamp) utilities. Without it, `twMerge("p-4 clamp-[p,1,3]")` keeps both classes instead of resolving the conflict. This plugin teaches tailwind-merge that clamp utilities belong to the same class groups as their static counterparts.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm i tailwind-clamp-merge
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
`tailwind-merge` v3+ is required as a peer dependency.
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
Pass `withTailwindClamp` to `extendTailwindMerge`:
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
import { extendTailwindMerge } from 'tailwind-merge';
|
|
19
|
+
import { withTailwindClamp } from 'tailwind-clamp-merge';
|
|
20
|
+
|
|
21
|
+
const twMerge = extendTailwindMerge(withTailwindClamp);
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Conflicts are now resolved correctly:
|
|
25
|
+
|
|
26
|
+
```js
|
|
27
|
+
twMerge('p-4 clamp-[p,1,3]')
|
|
28
|
+
// => 'clamp-[p,1,3]'
|
|
29
|
+
|
|
30
|
+
twMerge('clamp-[p,1,3] p-4')
|
|
31
|
+
// => 'p-4'
|
|
32
|
+
|
|
33
|
+
twMerge('text-lg clamp-[text,lg,3xl]')
|
|
34
|
+
// => 'clamp-[text,lg,3xl]'
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Hierarchical conflicts (shorthand vs specific) are handled automatically:
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
twMerge('px-4 py-2 clamp-[p,1,3]')
|
|
41
|
+
// => 'clamp-[p,1,3]'
|
|
42
|
+
|
|
43
|
+
twMerge('w-4 h-8 clamp-[size,10,20]')
|
|
44
|
+
// => 'clamp-[size,10,20]'
|
|
45
|
+
|
|
46
|
+
twMerge('rounded-tl-lg clamp-[rounded,0.5rem,1rem]')
|
|
47
|
+
// => 'clamp-[rounded,0.5rem,1rem]'
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
All properties supported by tailwind-clamp are covered, including `p`, `m`, `gap`, `w`, `h`, `size`, `text`, `rounded`, `border`, `inset`, `translate`, `scroll-m`, `scroll-p`, and more.
|
|
51
|
+
|
|
52
|
+
## License
|
|
53
|
+
|
|
54
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Config } from 'tailwind-merge';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Plugin for `extendTailwindMerge` that teaches tailwind-merge about
|
|
5
|
+
* clamp-[property,...] utilities from tailwind-clamp.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { extendTailwindMerge } from 'tailwind-merge';
|
|
10
|
+
* import { withTailwindClamp } from 'tailwind-clamp-merge';
|
|
11
|
+
*
|
|
12
|
+
* const twMerge = extendTailwindMerge(withTailwindClamp);
|
|
13
|
+
*
|
|
14
|
+
* twMerge('p-4 clamp-[p,1rem,2rem]');
|
|
15
|
+
* // => 'clamp-[p,1rem,2rem]'
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function withTailwindClamp(config: Config): Config;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { mergeConfigs as s } from "tailwind-merge";
|
|
2
|
+
const d = {
|
|
3
|
+
// Padding
|
|
4
|
+
p: "p",
|
|
5
|
+
pt: "pt",
|
|
6
|
+
pb: "pb",
|
|
7
|
+
pl: "pl",
|
|
8
|
+
ps: "ps",
|
|
9
|
+
pr: "pr",
|
|
10
|
+
pe: "pe",
|
|
11
|
+
px: "px",
|
|
12
|
+
py: "py",
|
|
13
|
+
// Margin
|
|
14
|
+
m: "m",
|
|
15
|
+
mt: "mt",
|
|
16
|
+
mb: "mb",
|
|
17
|
+
ml: "ml",
|
|
18
|
+
ms: "ms",
|
|
19
|
+
mr: "mr",
|
|
20
|
+
me: "me",
|
|
21
|
+
mx: "mx",
|
|
22
|
+
my: "my",
|
|
23
|
+
// Inset
|
|
24
|
+
inset: "inset",
|
|
25
|
+
"inset-x": "inset-x",
|
|
26
|
+
"inset-y": "inset-y",
|
|
27
|
+
start: "start",
|
|
28
|
+
end: "end",
|
|
29
|
+
top: "top",
|
|
30
|
+
left: "left",
|
|
31
|
+
right: "right",
|
|
32
|
+
bottom: "bottom",
|
|
33
|
+
// Gap
|
|
34
|
+
gap: "gap",
|
|
35
|
+
"gap-x": "gap-x",
|
|
36
|
+
"gap-y": "gap-y",
|
|
37
|
+
// Width / Height
|
|
38
|
+
w: "w",
|
|
39
|
+
h: "h",
|
|
40
|
+
size: "size",
|
|
41
|
+
// Min / Max
|
|
42
|
+
"min-w": "min-w",
|
|
43
|
+
"min-h": "min-h",
|
|
44
|
+
"max-w": "max-w",
|
|
45
|
+
"max-h": "max-h",
|
|
46
|
+
// Scroll Margin
|
|
47
|
+
"scroll-m": "scroll-m",
|
|
48
|
+
"scroll-mx": "scroll-mx",
|
|
49
|
+
"scroll-my": "scroll-my",
|
|
50
|
+
"scroll-ms": "scroll-ms",
|
|
51
|
+
"scroll-me": "scroll-me",
|
|
52
|
+
"scroll-mt": "scroll-mt",
|
|
53
|
+
"scroll-mb": "scroll-mb",
|
|
54
|
+
"scroll-ml": "scroll-ml",
|
|
55
|
+
"scroll-mr": "scroll-mr",
|
|
56
|
+
// Scroll Padding
|
|
57
|
+
"scroll-p": "scroll-p",
|
|
58
|
+
"scroll-px": "scroll-px",
|
|
59
|
+
"scroll-py": "scroll-py",
|
|
60
|
+
"scroll-ps": "scroll-ps",
|
|
61
|
+
"scroll-pe": "scroll-pe",
|
|
62
|
+
"scroll-pt": "scroll-pt",
|
|
63
|
+
"scroll-pb": "scroll-pb",
|
|
64
|
+
"scroll-pl": "scroll-pl",
|
|
65
|
+
"scroll-pr": "scroll-pr",
|
|
66
|
+
// Translate
|
|
67
|
+
translate: "translate",
|
|
68
|
+
"translate-x": "translate-x",
|
|
69
|
+
"translate-y": "translate-y",
|
|
70
|
+
// Typography
|
|
71
|
+
text: "font-size",
|
|
72
|
+
leading: "leading",
|
|
73
|
+
tracking: "tracking",
|
|
74
|
+
"underline-offset": "underline-offset",
|
|
75
|
+
decoration: "text-decoration-thickness",
|
|
76
|
+
// Border Width (tw-merge uses `border-w` prefix, not `border`)
|
|
77
|
+
border: "border-w",
|
|
78
|
+
"border-t": "border-w-t",
|
|
79
|
+
"border-b": "border-w-b",
|
|
80
|
+
"border-l": "border-w-l",
|
|
81
|
+
"border-s": "border-w-s",
|
|
82
|
+
"border-r": "border-w-r",
|
|
83
|
+
"border-e": "border-w-e",
|
|
84
|
+
"border-x": "border-w-x",
|
|
85
|
+
"border-y": "border-w-y",
|
|
86
|
+
// Border Radius
|
|
87
|
+
rounded: "rounded",
|
|
88
|
+
"rounded-s": "rounded-s",
|
|
89
|
+
"rounded-ss": "rounded-ss",
|
|
90
|
+
"rounded-se": "rounded-se",
|
|
91
|
+
"rounded-e": "rounded-e",
|
|
92
|
+
"rounded-ee": "rounded-ee",
|
|
93
|
+
"rounded-es": "rounded-es",
|
|
94
|
+
"rounded-t": "rounded-t",
|
|
95
|
+
"rounded-r": "rounded-r",
|
|
96
|
+
"rounded-b": "rounded-b",
|
|
97
|
+
"rounded-l": "rounded-l",
|
|
98
|
+
"rounded-tl": "rounded-tl",
|
|
99
|
+
"rounded-tr": "rounded-tr",
|
|
100
|
+
"rounded-bl": "rounded-bl",
|
|
101
|
+
"rounded-br": "rounded-br",
|
|
102
|
+
// Stroke Width (tw-merge uses `stroke-w`, not `stroke`)
|
|
103
|
+
stroke: "stroke-w"
|
|
104
|
+
};
|
|
105
|
+
function t(r) {
|
|
106
|
+
const o = r.replace(/-/g, "\\-"), e = new RegExp(`^\\[${o},.+,.+`);
|
|
107
|
+
return (l) => e.test(l);
|
|
108
|
+
}
|
|
109
|
+
function n() {
|
|
110
|
+
const r = {};
|
|
111
|
+
for (const [o, e] of Object.entries(d))
|
|
112
|
+
r[e] || (r[e] = []), r[e].push({ clamp: [t(o)] });
|
|
113
|
+
return r;
|
|
114
|
+
}
|
|
115
|
+
function c(r) {
|
|
116
|
+
return s(r, {
|
|
117
|
+
extend: {
|
|
118
|
+
classGroups: n()
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
export {
|
|
123
|
+
c as withTailwindClamp
|
|
124
|
+
};
|
|
125
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../lib/mapping.js","../lib/index.js"],"sourcesContent":["/**\n * Maps clamp property shorthands to tailwind-merge class group IDs.\n *\n * Most properties map 1:1 (e.g. `p` → `p`). Key divergences:\n * - `border*` → `border-w*` (tw-merge separates width from color)\n * - `text` → `font-size` (tw-merge's group for text sizing)\n * - `stroke` → `stroke-w` (tw-merge separates width from color)\n * - `decoration` → `text-decoration-thickness`\n */\nexport const PROP_TO_GROUP = {\n // Padding\n p: 'p',\n pt: 'pt',\n pb: 'pb',\n pl: 'pl',\n ps: 'ps',\n pr: 'pr',\n pe: 'pe',\n px: 'px',\n py: 'py',\n\n // Margin\n m: 'm',\n mt: 'mt',\n mb: 'mb',\n ml: 'ml',\n ms: 'ms',\n mr: 'mr',\n me: 'me',\n mx: 'mx',\n my: 'my',\n\n // Inset\n inset: 'inset',\n 'inset-x': 'inset-x',\n 'inset-y': 'inset-y',\n start: 'start',\n end: 'end',\n top: 'top',\n left: 'left',\n right: 'right',\n bottom: 'bottom',\n\n // Gap\n gap: 'gap',\n 'gap-x': 'gap-x',\n 'gap-y': 'gap-y',\n\n // Width / Height\n w: 'w',\n h: 'h',\n size: 'size',\n\n // Min / Max\n 'min-w': 'min-w',\n 'min-h': 'min-h',\n 'max-w': 'max-w',\n 'max-h': 'max-h',\n\n // Scroll Margin\n 'scroll-m': 'scroll-m',\n 'scroll-mx': 'scroll-mx',\n 'scroll-my': 'scroll-my',\n 'scroll-ms': 'scroll-ms',\n 'scroll-me': 'scroll-me',\n 'scroll-mt': 'scroll-mt',\n 'scroll-mb': 'scroll-mb',\n 'scroll-ml': 'scroll-ml',\n 'scroll-mr': 'scroll-mr',\n\n // Scroll Padding\n 'scroll-p': 'scroll-p',\n 'scroll-px': 'scroll-px',\n 'scroll-py': 'scroll-py',\n 'scroll-ps': 'scroll-ps',\n 'scroll-pe': 'scroll-pe',\n 'scroll-pt': 'scroll-pt',\n 'scroll-pb': 'scroll-pb',\n 'scroll-pl': 'scroll-pl',\n 'scroll-pr': 'scroll-pr',\n\n // Translate\n translate: 'translate',\n 'translate-x': 'translate-x',\n 'translate-y': 'translate-y',\n\n // Typography\n text: 'font-size',\n leading: 'leading',\n tracking: 'tracking',\n 'underline-offset': 'underline-offset',\n decoration: 'text-decoration-thickness',\n\n // Border Width (tw-merge uses `border-w` prefix, not `border`)\n border: 'border-w',\n 'border-t': 'border-w-t',\n 'border-b': 'border-w-b',\n 'border-l': 'border-w-l',\n 'border-s': 'border-w-s',\n 'border-r': 'border-w-r',\n 'border-e': 'border-w-e',\n 'border-x': 'border-w-x',\n 'border-y': 'border-w-y',\n\n // Border Radius\n rounded: 'rounded',\n 'rounded-s': 'rounded-s',\n 'rounded-ss': 'rounded-ss',\n 'rounded-se': 'rounded-se',\n 'rounded-e': 'rounded-e',\n 'rounded-ee': 'rounded-ee',\n 'rounded-es': 'rounded-es',\n 'rounded-t': 'rounded-t',\n 'rounded-r': 'rounded-r',\n 'rounded-b': 'rounded-b',\n 'rounded-l': 'rounded-l',\n 'rounded-tl': 'rounded-tl',\n 'rounded-tr': 'rounded-tr',\n 'rounded-bl': 'rounded-bl',\n 'rounded-br': 'rounded-br',\n\n // Stroke Width (tw-merge uses `stroke-w`, not `stroke`)\n stroke: 'stroke-w',\n};\n","import { mergeConfigs } from 'tailwind-merge';\nimport { PROP_TO_GROUP } from './mapping.js';\n\n/**\n * Creates a validator function that matches clamp-[prop,...] values\n * for a specific property name.\n *\n * @param {string} prop - The clamp property name (e.g. \"p\", \"gap-x\")\n * @returns {(value: string) => boolean}\n */\nfunction createClampValidator(prop) {\n // Escape hyphens for regex, require comma after prop to prevent\n // `p` from matching `pt` or `px`\n const escaped = prop.replace(/-/g, '\\\\-');\n const re = new RegExp(`^\\\\[${escaped},.+,.+`);\n return (value) => re.test(value);\n}\n\n/**\n * Builds the classGroups extension object from the property-to-group mapping.\n * Each entry adds a `clamp` validator to the corresponding tw-merge group.\n */\nfunction buildClassGroups() {\n const groups = {};\n\n for (const [prop, group] of Object.entries(PROP_TO_GROUP)) {\n if (!groups[group]) {\n groups[group] = [];\n }\n groups[group].push({ clamp: [createClampValidator(prop)] });\n }\n\n return groups;\n}\n\n/**\n * Plugin for `extendTailwindMerge` that teaches tailwind-merge about\n * clamp-[property,...] utilities from tailwind-clamp.\n *\n * @example\n * ```js\n * import { extendTailwindMerge } from 'tailwind-merge';\n * import { withTailwindClamp } from 'tailwind-clamp-merge';\n *\n * const twMerge = extendTailwindMerge(withTailwindClamp);\n *\n * twMerge('p-4 clamp-[p,1rem,2rem]');\n * // => 'clamp-[p,1rem,2rem]'\n * ```\n *\n * @param {import('tailwind-merge').Config} config\n * @returns {import('tailwind-merge').Config}\n */\nexport function withTailwindClamp(config) {\n return mergeConfigs(config, {\n extend: {\n classGroups: buildClassGroups(),\n },\n });\n}\n"],"names":["PROP_TO_GROUP","createClampValidator","prop","escaped","re","value","buildClassGroups","groups","group","withTailwindClamp","config","mergeConfigs"],"mappings":";AASO,MAAMA,IAAgB;AAAA;AAAA,EAE3B,GAAG;AAAA,EACH,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA;AAAA,EAGJ,GAAG;AAAA,EACH,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA;AAAA,EAGJ,OAAO;AAAA,EACP,WAAW;AAAA,EACX,WAAW;AAAA,EACX,OAAO;AAAA,EACP,KAAK;AAAA,EACL,KAAK;AAAA,EACL,MAAM;AAAA,EACN,OAAO;AAAA,EACP,QAAQ;AAAA;AAAA,EAGR,KAAK;AAAA,EACL,SAAS;AAAA,EACT,SAAS;AAAA;AAAA,EAGT,GAAG;AAAA,EACH,GAAG;AAAA,EACH,MAAM;AAAA;AAAA,EAGN,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA;AAAA,EAGT,YAAY;AAAA,EACZ,aAAa;AAAA,EACb,aAAa;AAAA,EACb,aAAa;AAAA,EACb,aAAa;AAAA,EACb,aAAa;AAAA,EACb,aAAa;AAAA,EACb,aAAa;AAAA,EACb,aAAa;AAAA;AAAA,EAGb,YAAY;AAAA,EACZ,aAAa;AAAA,EACb,aAAa;AAAA,EACb,aAAa;AAAA,EACb,aAAa;AAAA,EACb,aAAa;AAAA,EACb,aAAa;AAAA,EACb,aAAa;AAAA,EACb,aAAa;AAAA;AAAA,EAGb,WAAW;AAAA,EACX,eAAe;AAAA,EACf,eAAe;AAAA;AAAA,EAGf,MAAM;AAAA,EACN,SAAS;AAAA,EACT,UAAU;AAAA,EACV,oBAAoB;AAAA,EACpB,YAAY;AAAA;AAAA,EAGZ,QAAQ;AAAA,EACR,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,YAAY;AAAA;AAAA,EAGZ,SAAS;AAAA,EACT,aAAa;AAAA,EACb,cAAc;AAAA,EACd,cAAc;AAAA,EACd,aAAa;AAAA,EACb,cAAc;AAAA,EACd,cAAc;AAAA,EACd,aAAa;AAAA,EACb,aAAa;AAAA,EACb,aAAa;AAAA,EACb,aAAa;AAAA,EACb,cAAc;AAAA,EACd,cAAc;AAAA,EACd,cAAc;AAAA,EACd,cAAc;AAAA;AAAA,EAGd,QAAQ;AACV;ACjHA,SAASC,EAAqBC,GAAM;AAGlC,QAAMC,IAAUD,EAAK,QAAQ,MAAM,KAAK,GAClCE,IAAK,IAAI,OAAO,OAAOD,CAAO,QAAQ;AAC5C,SAAO,CAACE,MAAUD,EAAG,KAAKC,CAAK;AACjC;AAMA,SAASC,IAAmB;AAC1B,QAAMC,IAAS,CAAE;AAEjB,aAAW,CAACL,GAAMM,CAAK,KAAK,OAAO,QAAQR,CAAa;AACtD,IAAKO,EAAOC,CAAK,MACfD,EAAOC,CAAK,IAAI,CAAE,IAEpBD,EAAOC,CAAK,EAAE,KAAK,EAAE,OAAO,CAACP,EAAqBC,CAAI,CAAC,GAAG;AAG5D,SAAOK;AACT;AAoBO,SAASE,EAAkBC,GAAQ;AACxC,SAAOC,EAAaD,GAAQ;AAAA,IAC1B,QAAQ;AAAA,MACN,aAAaJ,EAAkB;AAAA,IAChC;AAAA,EACL,CAAG;AACH;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
(function(e,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("tailwind-merge")):typeof define=="function"&&define.amd?define(["exports","tailwind-merge"],o):(e=typeof globalThis<"u"?globalThis:e||self,o(e["tailwind-clamp-merge"]={},e.tailwindMerge))})(this,function(e,o){"use strict";const s={p:"p",pt:"pt",pb:"pb",pl:"pl",ps:"ps",pr:"pr",pe:"pe",px:"px",py:"py",m:"m",mt:"mt",mb:"mb",ml:"ml",ms:"ms",mr:"mr",me:"me",mx:"mx",my:"my",inset:"inset","inset-x":"inset-x","inset-y":"inset-y",start:"start",end:"end",top:"top",left:"left",right:"right",bottom:"bottom",gap:"gap","gap-x":"gap-x","gap-y":"gap-y",w:"w",h:"h",size:"size","min-w":"min-w","min-h":"min-h","max-w":"max-w","max-h":"max-h","scroll-m":"scroll-m","scroll-mx":"scroll-mx","scroll-my":"scroll-my","scroll-ms":"scroll-ms","scroll-me":"scroll-me","scroll-mt":"scroll-mt","scroll-mb":"scroll-mb","scroll-ml":"scroll-ml","scroll-mr":"scroll-mr","scroll-p":"scroll-p","scroll-px":"scroll-px","scroll-py":"scroll-py","scroll-ps":"scroll-ps","scroll-pe":"scroll-pe","scroll-pt":"scroll-pt","scroll-pb":"scroll-pb","scroll-pl":"scroll-pl","scroll-pr":"scroll-pr",translate:"translate","translate-x":"translate-x","translate-y":"translate-y",text:"font-size",leading:"leading",tracking:"tracking","underline-offset":"underline-offset",decoration:"text-decoration-thickness",border:"border-w","border-t":"border-w-t","border-b":"border-w-b","border-l":"border-w-l","border-s":"border-w-s","border-r":"border-w-r","border-e":"border-w-e","border-x":"border-w-x","border-y":"border-w-y",rounded:"rounded","rounded-s":"rounded-s","rounded-ss":"rounded-ss","rounded-se":"rounded-se","rounded-e":"rounded-e","rounded-ee":"rounded-ee","rounded-es":"rounded-es","rounded-t":"rounded-t","rounded-r":"rounded-r","rounded-b":"rounded-b","rounded-l":"rounded-l","rounded-tl":"rounded-tl","rounded-tr":"rounded-tr","rounded-bl":"rounded-bl","rounded-br":"rounded-br",stroke:"stroke-w"};function t(r){const d=r.replace(/-/g,"\\-"),l=new RegExp(`^\\[${d},.+,.+`);return i=>l.test(i)}function n(){const r={};for(const[d,l]of Object.entries(s))r[l]||(r[l]=[]),r[l].push({clamp:[t(d)]});return r}function p(r){return o.mergeConfigs(r,{extend:{classGroups:n()}})}e.withTailwindClamp=p,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
|
|
2
|
+
//# sourceMappingURL=index.umd.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.umd.cjs","sources":["../lib/mapping.js","../lib/index.js"],"sourcesContent":["/**\n * Maps clamp property shorthands to tailwind-merge class group IDs.\n *\n * Most properties map 1:1 (e.g. `p` → `p`). Key divergences:\n * - `border*` → `border-w*` (tw-merge separates width from color)\n * - `text` → `font-size` (tw-merge's group for text sizing)\n * - `stroke` → `stroke-w` (tw-merge separates width from color)\n * - `decoration` → `text-decoration-thickness`\n */\nexport const PROP_TO_GROUP = {\n // Padding\n p: 'p',\n pt: 'pt',\n pb: 'pb',\n pl: 'pl',\n ps: 'ps',\n pr: 'pr',\n pe: 'pe',\n px: 'px',\n py: 'py',\n\n // Margin\n m: 'm',\n mt: 'mt',\n mb: 'mb',\n ml: 'ml',\n ms: 'ms',\n mr: 'mr',\n me: 'me',\n mx: 'mx',\n my: 'my',\n\n // Inset\n inset: 'inset',\n 'inset-x': 'inset-x',\n 'inset-y': 'inset-y',\n start: 'start',\n end: 'end',\n top: 'top',\n left: 'left',\n right: 'right',\n bottom: 'bottom',\n\n // Gap\n gap: 'gap',\n 'gap-x': 'gap-x',\n 'gap-y': 'gap-y',\n\n // Width / Height\n w: 'w',\n h: 'h',\n size: 'size',\n\n // Min / Max\n 'min-w': 'min-w',\n 'min-h': 'min-h',\n 'max-w': 'max-w',\n 'max-h': 'max-h',\n\n // Scroll Margin\n 'scroll-m': 'scroll-m',\n 'scroll-mx': 'scroll-mx',\n 'scroll-my': 'scroll-my',\n 'scroll-ms': 'scroll-ms',\n 'scroll-me': 'scroll-me',\n 'scroll-mt': 'scroll-mt',\n 'scroll-mb': 'scroll-mb',\n 'scroll-ml': 'scroll-ml',\n 'scroll-mr': 'scroll-mr',\n\n // Scroll Padding\n 'scroll-p': 'scroll-p',\n 'scroll-px': 'scroll-px',\n 'scroll-py': 'scroll-py',\n 'scroll-ps': 'scroll-ps',\n 'scroll-pe': 'scroll-pe',\n 'scroll-pt': 'scroll-pt',\n 'scroll-pb': 'scroll-pb',\n 'scroll-pl': 'scroll-pl',\n 'scroll-pr': 'scroll-pr',\n\n // Translate\n translate: 'translate',\n 'translate-x': 'translate-x',\n 'translate-y': 'translate-y',\n\n // Typography\n text: 'font-size',\n leading: 'leading',\n tracking: 'tracking',\n 'underline-offset': 'underline-offset',\n decoration: 'text-decoration-thickness',\n\n // Border Width (tw-merge uses `border-w` prefix, not `border`)\n border: 'border-w',\n 'border-t': 'border-w-t',\n 'border-b': 'border-w-b',\n 'border-l': 'border-w-l',\n 'border-s': 'border-w-s',\n 'border-r': 'border-w-r',\n 'border-e': 'border-w-e',\n 'border-x': 'border-w-x',\n 'border-y': 'border-w-y',\n\n // Border Radius\n rounded: 'rounded',\n 'rounded-s': 'rounded-s',\n 'rounded-ss': 'rounded-ss',\n 'rounded-se': 'rounded-se',\n 'rounded-e': 'rounded-e',\n 'rounded-ee': 'rounded-ee',\n 'rounded-es': 'rounded-es',\n 'rounded-t': 'rounded-t',\n 'rounded-r': 'rounded-r',\n 'rounded-b': 'rounded-b',\n 'rounded-l': 'rounded-l',\n 'rounded-tl': 'rounded-tl',\n 'rounded-tr': 'rounded-tr',\n 'rounded-bl': 'rounded-bl',\n 'rounded-br': 'rounded-br',\n\n // Stroke Width (tw-merge uses `stroke-w`, not `stroke`)\n stroke: 'stroke-w',\n};\n","import { mergeConfigs } from 'tailwind-merge';\nimport { PROP_TO_GROUP } from './mapping.js';\n\n/**\n * Creates a validator function that matches clamp-[prop,...] values\n * for a specific property name.\n *\n * @param {string} prop - The clamp property name (e.g. \"p\", \"gap-x\")\n * @returns {(value: string) => boolean}\n */\nfunction createClampValidator(prop) {\n // Escape hyphens for regex, require comma after prop to prevent\n // `p` from matching `pt` or `px`\n const escaped = prop.replace(/-/g, '\\\\-');\n const re = new RegExp(`^\\\\[${escaped},.+,.+`);\n return (value) => re.test(value);\n}\n\n/**\n * Builds the classGroups extension object from the property-to-group mapping.\n * Each entry adds a `clamp` validator to the corresponding tw-merge group.\n */\nfunction buildClassGroups() {\n const groups = {};\n\n for (const [prop, group] of Object.entries(PROP_TO_GROUP)) {\n if (!groups[group]) {\n groups[group] = [];\n }\n groups[group].push({ clamp: [createClampValidator(prop)] });\n }\n\n return groups;\n}\n\n/**\n * Plugin for `extendTailwindMerge` that teaches tailwind-merge about\n * clamp-[property,...] utilities from tailwind-clamp.\n *\n * @example\n * ```js\n * import { extendTailwindMerge } from 'tailwind-merge';\n * import { withTailwindClamp } from 'tailwind-clamp-merge';\n *\n * const twMerge = extendTailwindMerge(withTailwindClamp);\n *\n * twMerge('p-4 clamp-[p,1rem,2rem]');\n * // => 'clamp-[p,1rem,2rem]'\n * ```\n *\n * @param {import('tailwind-merge').Config} config\n * @returns {import('tailwind-merge').Config}\n */\nexport function withTailwindClamp(config) {\n return mergeConfigs(config, {\n extend: {\n classGroups: buildClassGroups(),\n },\n });\n}\n"],"names":["PROP_TO_GROUP","createClampValidator","prop","escaped","re","value","buildClassGroups","groups","group","withTailwindClamp","config","mergeConfigs"],"mappings":"4SASO,MAAMA,EAAgB,CAE3B,EAAG,IACH,GAAI,KACJ,GAAI,KACJ,GAAI,KACJ,GAAI,KACJ,GAAI,KACJ,GAAI,KACJ,GAAI,KACJ,GAAI,KAGJ,EAAG,IACH,GAAI,KACJ,GAAI,KACJ,GAAI,KACJ,GAAI,KACJ,GAAI,KACJ,GAAI,KACJ,GAAI,KACJ,GAAI,KAGJ,MAAO,QACP,UAAW,UACX,UAAW,UACX,MAAO,QACP,IAAK,MACL,IAAK,MACL,KAAM,OACN,MAAO,QACP,OAAQ,SAGR,IAAK,MACL,QAAS,QACT,QAAS,QAGT,EAAG,IACH,EAAG,IACH,KAAM,OAGN,QAAS,QACT,QAAS,QACT,QAAS,QACT,QAAS,QAGT,WAAY,WACZ,YAAa,YACb,YAAa,YACb,YAAa,YACb,YAAa,YACb,YAAa,YACb,YAAa,YACb,YAAa,YACb,YAAa,YAGb,WAAY,WACZ,YAAa,YACb,YAAa,YACb,YAAa,YACb,YAAa,YACb,YAAa,YACb,YAAa,YACb,YAAa,YACb,YAAa,YAGb,UAAW,YACX,cAAe,cACf,cAAe,cAGf,KAAM,YACN,QAAS,UACT,SAAU,WACV,mBAAoB,mBACpB,WAAY,4BAGZ,OAAQ,WACR,WAAY,aACZ,WAAY,aACZ,WAAY,aACZ,WAAY,aACZ,WAAY,aACZ,WAAY,aACZ,WAAY,aACZ,WAAY,aAGZ,QAAS,UACT,YAAa,YACb,aAAc,aACd,aAAc,aACd,YAAa,YACb,aAAc,aACd,aAAc,aACd,YAAa,YACb,YAAa,YACb,YAAa,YACb,YAAa,YACb,aAAc,aACd,aAAc,aACd,aAAc,aACd,aAAc,aAGd,OAAQ,UACV,ECjHA,SAASC,EAAqBC,EAAM,CAGlC,MAAMC,EAAUD,EAAK,QAAQ,KAAM,KAAK,EAClCE,EAAK,IAAI,OAAO,OAAOD,CAAO,QAAQ,EAC5C,OAAQE,GAAUD,EAAG,KAAKC,CAAK,CACjC,CAMA,SAASC,GAAmB,CAC1B,MAAMC,EAAS,CAAE,EAEjB,SAAW,CAACL,EAAMM,CAAK,IAAK,OAAO,QAAQR,CAAa,EACjDO,EAAOC,CAAK,IACfD,EAAOC,CAAK,EAAI,CAAE,GAEpBD,EAAOC,CAAK,EAAE,KAAK,CAAE,MAAO,CAACP,EAAqBC,CAAI,CAAC,EAAG,EAG5D,OAAOK,CACT,CAoBO,SAASE,EAAkBC,EAAQ,CACxC,OAAOC,EAAAA,aAAaD,EAAQ,CAC1B,OAAQ,CACN,YAAaJ,EAAkB,CAChC,CACL,CAAG,CACH"}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tailwind-clamp-merge",
|
|
3
|
+
"version": "4.2.2",
|
|
4
|
+
"description": "tailwind-merge plugin for tailwind-clamp utilities",
|
|
5
|
+
"main": "dist/index.umd.cjs",
|
|
6
|
+
"module": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"require": "./dist/index.umd.cjs"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"/dist"
|
|
17
|
+
],
|
|
18
|
+
"type": "module",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/nicolas-cusan/tailwind-clamp.git",
|
|
22
|
+
"directory": "packages/tailwind-clamp-merge"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"tailwind",
|
|
26
|
+
"css",
|
|
27
|
+
"clamp",
|
|
28
|
+
"tailwind-merge"
|
|
29
|
+
],
|
|
30
|
+
"author": "Nicolas Cusan",
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/nicolas-cusan/tailwind-clamp/issues"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://github.com/nicolas-cusan/tailwind-clamp#readme",
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"tailwind-merge": "^3.0.0"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@tailwindcss/vite": "^4.1.7",
|
|
41
|
+
"tailwind-merge": "^3.0.0",
|
|
42
|
+
"tailwindcss": "^4.1.7",
|
|
43
|
+
"vite": "^6.3.5",
|
|
44
|
+
"vitest": "^4.0.18"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"dev": "vite",
|
|
48
|
+
"build": "vite build && cp lib/index.d.ts dist/index.d.ts",
|
|
49
|
+
"test": "vitest run",
|
|
50
|
+
"preview": "vite preview"
|
|
51
|
+
}
|
|
52
|
+
}
|