unocss-merge 0.2.1 → 0.3.0
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/README.md +33 -4
- package/dist/index.js +1 -1
- package/dist/react.js +1 -1
- package/dist/{src-BrrP8tFs.js → src-KQw-83RL.js} +1 -1
- package/package.json +13 -13
package/README.md
CHANGED
|
@@ -16,6 +16,8 @@ $ pnpm add unocss-merge
|
|
|
16
16
|
|
|
17
17
|
## API
|
|
18
18
|
|
|
19
|
+
### `unoMerge`
|
|
20
|
+
|
|
19
21
|
```ts
|
|
20
22
|
import { unoMerge } from 'unocss-merge'
|
|
21
23
|
|
|
@@ -30,6 +32,23 @@ expect(unoMerge('mr-1', 'mr--4px')).toBe('mr--4px')
|
|
|
30
32
|
expect(unoMerge('cursor-pointer', 'cursor-not-allowed')).toBe('cursor-not-allowed')
|
|
31
33
|
```
|
|
32
34
|
|
|
35
|
+
> [!TIP]
|
|
36
|
+
> This function does not provide any cache mechanism, wrap with your own cache if needed. [memoize](https://github.com/sindresorhus/memoize#install) or others.
|
|
37
|
+
|
|
38
|
+
### `useUnoMerge`
|
|
39
|
+
|
|
40
|
+
```tsx
|
|
41
|
+
import { useUnoMerge } from 'unocss-merge/react'
|
|
42
|
+
|
|
43
|
+
function Component(props) {
|
|
44
|
+
const className = useUnoMerge('cursor-pointer', props.className)
|
|
45
|
+
return <div className={className} />
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
> [!TIP]
|
|
50
|
+
> `useMemo` `deps array`.length should not change in runtime
|
|
51
|
+
|
|
33
52
|
## Why
|
|
34
53
|
|
|
35
54
|
- `twMerge` don't support [arbitrary value without brackets](https://github.com/dcastil/tailwind-merge/blob/v3.2.0/src/lib/validators.ts#L1)
|
|
@@ -49,12 +68,22 @@ console.log(twMerge('size-16px', 'size-18px')) // `size-16px size-18px` ❌
|
|
|
49
68
|
console.log(twMerge('ml-4px', 'ml-10px')) // `ml-4px ml-10px` ❌
|
|
50
69
|
```
|
|
51
70
|
|
|
52
|
-
## Status
|
|
71
|
+
## Status
|
|
72
|
+
|
|
73
|
+
### ✅ What is **KNOWN** Supported
|
|
74
|
+
|
|
75
|
+
- ✅ simple class name `mr-4px` `mr-4`
|
|
76
|
+
- ✅ arbitrary value `mr-[4px]` `mr-[4]`
|
|
77
|
+
- ✅ negative value `mr--4px`
|
|
78
|
+
- ✅ simple colon separated variants `hover:mr-4px` `dark:ml-4px` `hover:dark:ml-4px`
|
|
79
|
+
|
|
80
|
+
### ❌ What is **NOT** Supported
|
|
53
81
|
|
|
54
82
|
- complex features are not supported !!!
|
|
55
|
-
- ❌ [
|
|
56
|
-
- ❌ [Variant
|
|
57
|
-
-
|
|
83
|
+
- ❌ [Complex Variants](https://github.com/unocss/unocss/tree/main/packages-presets/preset-mini/src/_variants) are not recongized
|
|
84
|
+
- ❌ [Variant Group](https://unocss.dev/transformers/variant-group)
|
|
85
|
+
- ❌ [Shortcuts](https://unocss.dev/config/shortcuts) are not recongized
|
|
86
|
+
- ❌ shorthand: for example merge `mx` with `ml / mr` are not supported
|
|
58
87
|
|
|
59
88
|
## Changelog
|
|
60
89
|
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getClassList as e,unoMerge as t}from"./src-
|
|
1
|
+
import{getClassList as e,unoMerge as t}from"./src-KQw-83RL.js";export{e as getClassList,t as unoMerge};
|
package/dist/react.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{unoMerge as e}from"./src-
|
|
1
|
+
import{unoMerge as e}from"./src-KQw-83RL.js";import{useMemo as t}from"react";function n(...n){return t(()=>e(...n),[...n])}export{n as useUnoMerge};
|
|
@@ -3,4 +3,4 @@ function e(e){return Array.from(new Set(e))}function t(e,t){if(!e)throw typeof t
|
|
|
3
3
|
table,inline-table,table-caption,table-cell,table-column,table-row,
|
|
4
4
|
table-column-group,table-footer-group,table-header-group,table-row-group
|
|
5
5
|
`),`display`],[[`isolate`,`isolation-auto`],`isolation`],[[`static`,`fixed`,`absolute`,`relative`,`sticky`],`position`],[[`visible`,`invisible`,`collapse`],`visibility`],[h(`flex-`,[`row`,`row-reverse`,`col`,`col-reverse`]),`flex-direction`],[h(`flex-`,[`wrap`,`wrap-reverse`,`nowrap`]),`flex-wrap`],[h(`object-`,[`contain`,`cover`,`fill`,`none`,`scale-down`]),`object-fit`],[h(`object-`,[`bottom`,`center`,`left`,`left-bottom`,`left-top`,`right`,`right-bottom`,`right-top`,`top`]),`object-position`],[[`antialiased`,`subpixel-antialiased`],`font-smoothing`],[[`italic`,`not-italic`],`font-style`],[h(`font-`,[`thin`,`extralight`,`light`,`normal`,`medium`,`semibold`,`bold`,`extrabold`,`black`]),`font-weight`],[[`normal-nums`,`ordinal`,`slashed-zero`,`lining-nums`,`oldstyle-nums`,`proportional-nums`,`tabular-nums`,`diagonal-fractions`,`stacked-fractions`],`font-variant-numeric`],[r`^(text|text-size|font-size)-(\d+|${i}$)`,`font-size`],[h(`list-`,[`inside`,`outside`]),`list-style-position`],[h(`list-`,[`none`,`disc`,`decimal`]),`list-style-type`],[h(`text-`,[`left`,`center`,`right`,`justify`,`start`,`end`]),`text-align`],[[`underline`,`overline`,`line-through`,`no-underline`],`text-decoration-line`],[h(`decoration-`,[`solid`,`double`,`dotted`,`dashed`,`wavy`]),`text-decoration-style`],[/^decoration-(\d+|(auto|from-font)$)/,`text-decoration-thickness`],[[`truncate`,`text-ellipsis`,`text-clip`],`text-overflow`],[h(`text-`,[`wrap`,`nowrap`,`balance`,`pretty`]),`text-wrap`],[h(`bg-`,[`bottom`,`center`,`left`,`left-bottom`,`left-top`,`right`,`right-bottom`,`right-top`,`top`]),`background-position`],[/^bg(-no)?-repeat($|-)/,`background-repeat`],[h(`bg-`,[`auto`,`cover`,`contain`]),`background-size`],[[`bg-none`,/^bg-gradient-to-/],`background-image`],[/^(?:border-|b-)?(?:rounded|rd)(?:-(.+))?$/,`rounded`],[r`^b(?:order)?-${a}$`,`border-style`],[/^b(?:order)?($|-\d+)/,`border-width`],[/^b(?:order)?-([tblrxyse])($|-\d+)/,(e,t)=>`border-${t==null?void 0:t[1]}-width`],[/^outline-\d+/,`outline-width`],[[`outline`,r`^outline-${a}$`],`outline-style`],[r`^divide-${a}$`,`divide-style`],[/^divide-(x|y)($|-\d+)/,(e,t)=>`divide-${t==null?void 0:t[1]}-width`],[[`ring`,/^ring-\d+/],`ring-width`],[[/^ring-offset-\d+/],`ring-offset-width`],[[`shadow`,...h(`shadow-`,[`inner`,`none`]),r`^shadow-${i}$`],`box-shadow`],[h(`border-`,[`collapse`,`separate`]),`border-collapse`],[h(`table-`,[`auto`,`fixed`]),`table-layout`],[h(`caption-`,[`top`,`bottom`]),`caption-side`],[h(`scroll-`,[`auto`,`smooth`]),`scroll-behavior`],[h(`snap-`,[`start`,`end`,`center`,`align-none`]),`scroll-snap-align`],[h(`snap-`,[`normal`,`always`]),`scroll-snap-stop`],[h(`snap-`,[`none`,`x`,`y`,`both`,`mandatory`,`proximity`]),`scroll-snap-type`],[/^stroke-\d+/,`stroke-width`],[[`sr-only`,`not-sr-only`],`Screen-Readers`],[/^(flex-)?grow($|-\d+$)/,`flex-grow`],[/^(flex-)?shrink($|-\d+$)/,`flex-shrink`],...[`ring-inset`,`divide-x-reverse`,`divide-y-reverse`].map(e=>[e,e]),...[`resize`,`blur`,`drop-shadow`,`grayscale`,`invert`,`sepia`,`backdrop-blur`,`backdrop-grayscale`,`backdrop-invert`,`backdrop-sepia`].map(e=>[e,e])],s=new Map,c=new Map;for(let[e,t]of o){let n=[e].flat(),r=n.filter(e=>typeof e==`string`),i=n.filter(e=>typeof e==`object`&&e instanceof RegExp);r.forEach(e=>{let n=typeof t==`string`?t:t(e);s.set(e,n)}),i.forEach(e=>{c.set(e,t)})}function l(e){if(s.has(e))return s.get(e);for(let[t,n]of c.entries())if(t.test(e)){let r=t.exec(e),i=typeof n==`string`?n:n(e,r);return i}}function u(e){return d.map(e=>typeof e==`string`?[e,e]:e).find(([t,n])=>e.startsWith(`${t}-`))}const d=[`break-after`,`break-before`,`break-inside`,`grid-flow`,`align`,`whitespace`,`mix-blend`,`bg-blend`,`ease`,`origin`,`cursor`,`touch`,[`text`,`color`],`color`,[`bg`,`background-color`],[`b`,`border-color`],[`border`,`border-color`],[`decoration`,`text-decoration-color`],[`from`,`gradient-color-stops`],[`divide`,`divide-color`],[`outline`,`outline-color`],[`ring`,`ring-color`],[`ring-offset`,`ring-offset-color`],[`shadow`,`box-shadow-color`],[`accent`,`accent-color`],[`caret`,`caret-color`],`fill`,`stroke`];function f(e){return p.has(e)?p.get(e):e}const p=new Map(Object.entries({leading:`line-height`,col:`grid-column`,"col-span":`grid-column`,"col-start":`grid-column-start`,"col-end":`grid-column-end`,row:`grid-row`,"row-span":`grid-row`,"row-start":`grid-row-start`,"row-end":`grid-row-end`}));function m(e){return e.split(`
|
|
6
|
-
`).map(e=>e.trim()).filter(Boolean).map(e=>e.split(`,`).map(e=>e.trim()).filter(Boolean)).flat()}function h(e,n){return t(e.endsWith(`-`),"prefix must end with `-`"),n.map(t=>e+t)}function g(t){return e((t||``).split(` `).map(e=>e.trim()).filter(Boolean))}function _(...e){let t=e.map(g).flat().filter(Boolean),
|
|
6
|
+
`).map(e=>e.trim()).filter(Boolean).map(e=>e.split(`,`).map(e=>e.trim()).filter(Boolean)).flat()}function h(e,n){return t(e.endsWith(`-`),"prefix must end with `-`"),n.map(t=>e+t)}function g(t){return e((t||``).split(` `).map(e=>e.trim()).filter(Boolean))}function _(...e){let t=new Map,n=e.map(g).flat().filter(Boolean);return n.forEach(r),Array.from(t.values()).join(` `);function r(e){let n=e,r;function i(e){t.set(r?r+e:e,n)}{let t=/^(?:[\w-]+:)+/g,n=t.exec(e);n&&(r=n[0],e=e.slice(r.length))}{let t=l(e);if(t)return i(t)}let a=u(e);if(a){let[e,t]=a,n=f(t);return i(n)}let o=e,s=/(\[[\w,-]+\])$/;s.test(e)&&(o=e.replace(s,function(e,t){return`*`.repeat(t.length)})),o.includes(`--`)&&(o=o.replaceAll(`--`,`-*`));let c=o.lastIndexOf(`-`);if(c===-1)return i(f(e));let d=f(e.slice(0,c));i(d)}}export{g as getClassList,_ as unoMerge};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unocss-merge",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"packageManager": "pnpm@10.12.
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"packageManager": "pnpm@10.12.4+sha512.5ea8b0deed94ed68691c9bad4c955492705c5eeb8a87ef86bc62c74a26b037b08ff9570f108b2e4dbd1dd1a9186fea925e527f141c648e85af45631074680184",
|
|
5
5
|
"description": "simple utility to merge unocss class names",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"keywords": [
|
|
@@ -50,23 +50,23 @@
|
|
|
50
50
|
"react": ">=18"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@magicdawn/eslint-config": "^1.5.
|
|
53
|
+
"@magicdawn/eslint-config": "^1.5.6",
|
|
54
54
|
"@magicdawn/prettier-config": "^0.1.0",
|
|
55
|
-
"@swc/core": "^1.12.
|
|
56
|
-
"@types/node": "^24.0.
|
|
55
|
+
"@swc/core": "^1.12.9",
|
|
56
|
+
"@types/node": "^24.0.10",
|
|
57
57
|
"@types/react": "^19.1.8",
|
|
58
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
59
|
-
"@typescript-eslint/parser": "^8.
|
|
60
|
-
"@vitest/coverage-v8": "^3.2.
|
|
61
|
-
"es-toolkit": "^1.39.
|
|
62
|
-
"eslint": "^9.
|
|
58
|
+
"@typescript-eslint/eslint-plugin": "^8.35.1",
|
|
59
|
+
"@typescript-eslint/parser": "^8.35.1",
|
|
60
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
61
|
+
"es-toolkit": "^1.39.5",
|
|
62
|
+
"eslint": "^9.30.1",
|
|
63
63
|
"eslint-config-prettier": "^10.1.5",
|
|
64
64
|
"husky": "^9.1.7",
|
|
65
65
|
"lint-staged": "^16.1.2",
|
|
66
|
-
"prettier": "^3.
|
|
67
|
-
"tsdown": "^0.12.
|
|
66
|
+
"prettier": "^3.6.2",
|
|
67
|
+
"tsdown": "^0.12.9",
|
|
68
68
|
"typescript": "^5.8.3",
|
|
69
|
-
"vitest": "^3.2.
|
|
69
|
+
"vitest": "^3.2.4"
|
|
70
70
|
},
|
|
71
71
|
"lint-staged": {
|
|
72
72
|
"*.{?(c|m)(j|t)s?(x),json,y?(a)ml}": [
|