unocss-merge 0.1.0 → 0.2.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 CHANGED
@@ -16,13 +16,23 @@ $ pnpm add unocss-merge
16
16
 
17
17
  ## API
18
18
 
19
- ```js
20
- const unocssMerge = require('unocss-merge');
19
+ ```ts
20
+ import { unoMerge } from 'unocss-merge'
21
+
22
+ expect(unoMerge('hidden', 'block')).toBe('block')
23
+ expect(unoMerge('hidden', 'block', 'flex')).toBe('flex')
24
+
25
+ expect(unoMerge('mr-1', 'mr-2')).toBe('mr-2')
26
+ expect(unoMerge('mr-1', 'mr-4px')).toBe('mr-4px')
27
+ expect(unoMerge('mr-1', 'mr-[-4px]')).toBe('mr-[-4px]')
28
+ expect(unoMerge('mr-1', 'mr--4px')).toBe('mr--4px')
29
+
30
+ expect(unoMerge('cursor-pointer', 'cursor-not-allowed')).toBe('cursor-not-allowed')
21
31
  ```
22
32
 
23
33
  ## Changelog
24
34
 
25
- [CHANGELOG.md](CHANGELOG.md)
35
+ See https://github.com/magicdawn/unocss-merge/releases
26
36
 
27
37
  ## License
28
38
 
package/dist/index.d.ts CHANGED
@@ -1,4 +1,12 @@
1
- declare function getClassList(className?: string): string[];
2
- declare function unoMerge(...classNames: Array<string | undefined>): string;
1
+ //#region src/index.d.ts
2
+ declare function getClassList(className: string | null | undefined): string[];
3
+ /**
4
+ * Match steps
5
+ * 1. `getMergeMapKeyValue`: exact-string + regex match
6
+ * 2. `findInKnownPrefixHasDashValue`: prefix match; may replace alias via `PREFIX_ALIAS`
7
+ * 3. `lastIndexOf('-')` based split; may replace alias via `PREFIX_ALIAS`
8
+ */
9
+ declare function unoMerge(...classNames: Array<string | undefined | null>): string;
3
10
 
4
- export { getClassList, unoMerge };
11
+ //#endregion
12
+ export { getClassList, unoMerge };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{a,b}from"./chunk-MBFPIAXN.js";export{a as getClassList,b as unoMerge};
1
+ import{getClassList as e,unoMerge as t}from"./src-DkzuEjkD.js";export{e as getClassList,t as unoMerge};
package/dist/react.d.ts CHANGED
@@ -1,6 +1,8 @@
1
+ //#region src/react.d.ts
1
2
  /**
2
- * @note `useMemo` `deps array`.length should not change in runtime
3
- */
3
+ * @note `useMemo` `deps array`.length should not change in runtime
4
+ */
4
5
  declare function useUnoMerge(...classNames: Array<string | undefined>): string;
5
6
 
6
- export { useUnoMerge };
7
+ //#endregion
8
+ export { useUnoMerge };
package/dist/react.js CHANGED
@@ -1 +1 @@
1
- import{b as e}from"./chunk-MBFPIAXN.js";import{useMemo as n}from"react";function i(...r){return n(()=>e(...r),[...r])}export{i as useUnoMerge};
1
+ import{unoMerge as e}from"./src-DkzuEjkD.js";import{useMemo as t}from"react";function n(...n){return t(()=>e(...n),[...n])}export{n as useUnoMerge};
@@ -0,0 +1,6 @@
1
+ function e(e){return Array.from(new Set(e))}function t(e,t){if(!e)throw Error(t)}const n=[[u(`
2
+ block,inline-block,inline,flex,inline-flex,flow-root,grid,inline-grid,contents,list-item,hidden
3
+ table,inline-table,table-caption,table-cell,table-column,table-row,
4
+ table-column-group,table-footer-group,table-header-group,table-row-group
5
+ `),`display`],[[`isolate`,`isolation-auto`],`isolation`],[[`static`,`fixed`,`absolute`,`relative`,`sticky`],`position`],[[`visible`,`invisible`,`collapse`],`visibility`],[[`flex-row`,`flex-row-reverse`,`flex-col`,`flex-col-reverse`],`flex-direction`],[[`flex-wrap`,`flex-wrap-reverse`,`flex-nowrap`],`flex-wrap`],[d(`object-`,[`contain`,`cover`,`fill`,`none`,`scale-down`]),`object-fit`],[d(`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`],[d(`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`],[[`text-xs`,`text-sm`,`text-base`,`text-lg`,`text-xl`,/^text-(size-)?\d+xl/,/^text-(size-)?\d+/,/^font-size-\d+/],`font-size`],[[`list-inside`,`list-outside`],`list-style-position`],[[`list-none`,`list-disc`,`list-decimal`],`list-style-type`],[d(`text-`,[`left`,`center`,`right`,`justify`,`start`,`end`]),`text-align`],[[`underline`,`overline`,`line-through`,`no-underline`],`text-decoration-line`],[d(`decoration-`,[`solid`,`double`,`dotted`,`dashed`,`wavy`]),`text-decoration-style`],[[`decoration-auto`,`decoration-from-font`,/^decoration-\d+/],`text-decoration-thickness`],[[`truncate`,`text-ellipsis`,`text-clip`],`text-overflow`],[[`text-wrap`,`text-nowrap`,`text-balance`,`text-pretty`],`text-wrap`],[d(`bg-`,[`bottom`,`center`,`left`,`left-bottom`,`left-top`,`right`,`right-bottom`,`right-top`,`top`]),`background-position`],[[`bg-repeat`,`bg-no-repeat`,/^bg-repeat-/],`background-repeat`],[[`bg-auto`,`bg-cover`,`bg-contain`],`background-size`],[[`bg-none`,/^bg-gradient-to-/],`background-image`],[[/^(?:border-|b-)?(?:rounded|rd)()(?:-(.+))?$/],`rounded`],[/^b(?:order)?-(solid|dashed|dotted|double|hidden|none)$/,`border-style`],[/^b(?:order)?($|-\d+)/,`border-width`],[/^b(?:order)?-(t|b|l|r|x|y|s|e)($|-\d+)/,(e,t)=>`border-${t?.[1]}-width`],[/^outline-\d+/,`outline-width`],[[`outline`,/^outline-(solid|dashed|dotted|double|none)$/],`outline-style`],[/^divide-(solid|dashed|dotted|double|none)$/,`divide-style`],[/^divide-(x|y)($|-\d+)/,(e,t)=>`divide-${t?.[1]}-width`],[[`ring`,/^ring-\d+/],`ring-width`],[[/^ring-offset-\d+/],`ring-offset-width`],[[`shadow`,...d(`shadow-`,[`sm`,`md`,`lg`,`xl`,`2xl`,`inner`,`none`])],`box-shadow`],[[`border-collapse`,`border-separate`],`border-collapse`],[[`table-auto`,`table-fixed`],`table-layout`],[[`caption-top`,`caption-bottom`],`caption-side`],[[`scroll-auto`,`scroll-smooth`],`scroll-behavior`],[[`snap-start`,`snap-end`,`snap-center`,`snap-align-none`],`scroll-snap-align`],[[`snap-normal`,`snap-always`],`scroll-snap-stop`],[[`snap-none`,`snap-x`,`snap-y`,`snap-both`,`snap-mandatory`,`snap-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])],r=new Map,i=new Map;for(let[e,t]of n){let n=[e].flat(),a=n.filter(e=>typeof e==`string`),o=n.filter(e=>typeof e==`object`&&e instanceof RegExp);a.forEach(e=>{let n=typeof t==`string`?t:t(e);r.set(e,n)}),o.forEach(e=>{i.set(e,t)})}function a(e){if(r.has(e))return r.get(e);for(let[t,n]of i.entries())if(t.test(e)){let r=t.exec(e),i=typeof n==`string`?n:n(e,r);return i}}function o(e){return s.map(e=>typeof e==`string`?[e,e]:e).find(([t,n])=>e.startsWith(t+`-`))}const s=[`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 c(e){return l.has(e)?l.get(e):e}const l=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 u(e){return e.split(`
6
+ `).map(e=>e.trim()).filter(Boolean).map(e=>e.split(`,`).map(e=>e.trim()).filter(Boolean)).flat()}function d(e,n){return t(e.endsWith(`-`),"prefix must end with `-`"),n.map(t=>e+t)}function f(t){return e((t||``).split(` `).map(e=>e.trim()).filter(Boolean))}function p(...e){let t=e.map(f).flat().filter(Boolean),n=new Map;for(let e of t){{let t=a(e);if(t){n.set(t,e);continue}}let t=o(e);if(t){let[r,i]=t,a=c(i);n.set(a,e);continue}let r=e,i=/(\[[\w_,-]+\])$/;i.test(e)&&(r=e.replace(i,function(e,t){return`*`.repeat(t.length)})),r.includes(`--`)&&(r=r.replace(/--/g,`-*`));let s=r.lastIndexOf(`-`);if(s===-1){n.set(c(e),e);continue}let l=c(e.slice(0,s));n.set(l,e)}return Array.from(n.values()).join(` `)}export{f as getClassList,p as unoMerge};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unocss-merge",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "simple utility to merge unocss class names",
5
5
  "type": "module",
6
6
  "exports": {
@@ -19,30 +19,29 @@
19
19
  ],
20
20
  "scripts": {
21
21
  "prepare": "husky",
22
- "dev": "tsup --watch",
23
- "build": "tsup",
22
+ "dev": "tsdown --watch",
23
+ "build": "tsdown",
24
24
  "typecheck": "tsc --noEmit",
25
25
  "test": "vitest run",
26
26
  "test:dev": "vitest",
27
27
  "test-cover": "vitest run --coverage",
28
28
  "prepublishOnly": "pnpm typecheck && pnpm test-cover && pnpm build"
29
29
  },
30
- "dependencies": {
31
- "es-toolkit": "^1.36.0"
32
- },
33
30
  "devDependencies": {
34
31
  "@magicdawn/prettier-config": "^0.0.4",
35
32
  "@swc/core": "^1.11.22",
36
- "@types/node": "^22.15.0",
33
+ "@types/node": "^22.15.2",
34
+ "@types/react": "^19.1.2",
37
35
  "@typescript-eslint/eslint-plugin": "^8.31.0",
38
36
  "@typescript-eslint/parser": "^8.31.0",
39
37
  "@vitest/coverage-v8": "^3.1.2",
38
+ "es-toolkit": "^1.36.0",
40
39
  "eslint": "^9.25.1",
41
40
  "eslint-config-prettier": "^10.1.2",
42
41
  "husky": "^9.1.7",
43
42
  "lint-staged": "^15.5.1",
44
43
  "prettier": "^3.5.3",
45
- "tsup": "^8.4.0",
44
+ "tsdown": "^0.9.8",
46
45
  "typescript": "^5.8.3",
47
46
  "vitest": "^3.1.2"
48
47
  },
@@ -1,6 +0,0 @@
1
- import{uniq as y}from"es-toolkit";var h=[[w(`
2
- block,inline-block,inline,flex,inline-flex,flow-root,grid,inline-grid,contents,list-item,hidden
3
- table,inline-table,table-caption,table-cell,table-column,table-row,
4
- table-column-group,table-footer-group,table-header-group,table-row-group
5
- `),"display"],[["isolate","isolation-auto"],"isolation"],[["static","fixed","absolute","relative","stick"],"position"],[["visible","invisible","collapse"],"visibility"],[["flex-row","flex-row-reverse","flex-col","flex-col-reverse"],"flex-direction"],[["flex-wrap","flex-wrap-reverse","flex-nowrap"],"flex-wrap"],[l("object-",["contain","cover","fill","none","scale-down"]),"object-fit"],[l("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"],[l("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"],[["text-xs","text-sm","text-base","text-lg","text-xl",/^text-(size-)?\d+xl/,/^text-(size-)?\d+/,/^font-size-\d+/],"font-size"],[["list-inside","list-outside"],"list-style-position"],[["list-none","list-disc","list-decimal"],"list-style-type"],[l("text-",["left","center","right","justify","start","end"]),"text-align"],[["underline","overline","line-through","no-underline"],"text-decoration-line"],[l("decoration-",["solid","double","dotted","dashed","wavy"]),"text-decoration-style"],[["decoration-auto","decoration-from-font",/^decoration-\d+/],"text-decoration-thickness"],[["truncate","text-ellipsis","text-clip"],"text-overflow"],[["text-wrap","text-nowrap","text-balance","text-pretty"],"text-wrap"],[l("bg-",["bottom","center","left","left-bottom","left-top","right","right-bottom","right-top","top"]),"background-position"],[["bg-repeat","bg-no-repeat",/^bg-repeat-/],"background-repeat"],[["bg-auto","bg-cover","bg-contain"],"background-size"],[["bg-none",/^bg-gradient-to-/],"background-image"],[[/^(?:border-|b-)?(?:rounded|rd)()(?:-(.+))?$/],"rounded"],[/^b(?:order)?-(solid|dashed|dotted|double|hidden|none)$/,"border-style"],[/^b(?:order)?($|-\d+)/,"border-width"],[/^b(?:order)?-(t|b|l|r|x|y|s|e)($|-\d+)/,(t,e)=>`border-${e==null?void 0:e[1]}-width`],[/^outline-\d+/,"outline-width"],[["outline",/^outline-(solid|dashed|dotted|double|none)$/],"outline-style"],[/^divide-(solid|dashed|dotted|double|none)$/,"divide-style"],[/^divide-(x|y)($|-\d+)$/,(t,e)=>`divide-${e==null?void 0:e[1]}-width`],[["ring",/^ring-\d+/],"ring-width"],[[/^ring-offset-\d+/],"ring-offset-width"],[["shadow",...l("shadow",["sm","md","lg","xl","2xl","inner","none"])],"box-shadow"],[["border-collapse","border-separate"],"border-collapse"],[["table-auto","table-fixed"],"table-layout"],[["caption-top","caption-bottom"],"caption-side"],[["scroll-auto","scroll-smooth"],"scroll-behavior"],[["snap-start","snap-end","snap-center","snap-align-none"],"scroll-snap-align"],[["snap-normal","snap-always"],"scroll-snap-stop"],[["snap-none","snap-x","snap-y","snap-both","snap-mandatory","snap-proximity"],"scroll-snap-type"],[/^stroke-\d+/,"stroke-width"],[["sr-only","not-sr-only"],"Screen Readers"],[["grow","flex-grow"],"flex-grow"],[["shrink","flex-shrink"],"flex-shrink"],...["resize","ring-inset","divide-x-reverse","divide-y-reverse","blur","drop-shadow","grayscale","invert","sepia","backdrop-blur","backdrop-grayscale","backdrop-invert","backdrop-sepia"].map(t=>[t,t])],p=new Map,u=new Map;for(let[t,e]of h){let o=[t].flat(),r=o.filter(n=>typeof n=="string"),s=o.filter(n=>typeof n=="object"&&n instanceof RegExp);r.forEach(n=>{let a=typeof e=="string"?e:e(n);p.set(n,a)}),s.forEach(n=>{u.set(n,e)})}function x(t){if(p.has(t))return p.get(t);for(let[e,o]of u.entries())if(e.test(t)){let r=e.exec(t);return typeof o=="string"?o:o(t,r)}}var m=["break-after","break-before","break-inside","grid-flow","align","whitespace","mix-blend","bg-blend","ease","origin","cursor","touch","text","color","bg","b","border","decoration","from","divide","outline","ring","ring-offset","shadow","accent","caret","fill","stroke"],d=new Map(Object.entries({grow:"flex-grow",shrink:"flex-shrink",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",leading:"line-height"}));function w(t){return t.split(`
6
- `).map(e=>e.trim()).filter(Boolean).map(e=>e.split(",").map(o=>o.trim()).filter(Boolean)).flat()}function l(t,e){return e.map(o=>t+o)}function k(t){return y((t||"").split(" ").map(e=>e.trim()).filter(Boolean))}function E(...t){let e=t.map(k).flat().filter(Boolean),o=new Map;for(let r of e){let s=x(r);if(s){if(typeof s=="string")o.set(s,r);else{let[i,g]=s;o.set(i,g)}continue}let n=m.find(i=>r.startsWith(i+"-"));if(n){let i=n;d.has(i)&&(i=d.get(i)),o.set(i,r);continue}let a=r,f=/(\[[\w_,-]+\])$/;f.test(r)&&(a=r.replace(f,function(i,g){return"*".repeat(g.length)})),a.includes("--")&&(a=a.replace(/--/g,"-*"));let b=a.lastIndexOf("-");if(b===-1){o.set(r,r);continue}let c=r.slice(0,b);d.has(c)&&(c=d.get(c)),o.set(c,r)}return Array.from(o.values()).join(" ")}export{k as a,E as b};