unocss-merge 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.
- package/LICENSE +21 -0
- package/README.md +29 -0
- package/dist/chunk-XPETEQCQ.js +180 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +8 -0
- package/dist/react.d.ts +6 -0
- package/dist/react.js +12 -0
- package/package.json +79 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Magicdawn(magicdawn@qq.com)
|
|
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,29 @@
|
|
|
1
|
+
# unocss-merge
|
|
2
|
+
|
|
3
|
+
> simple utility to merge unocss class names
|
|
4
|
+
|
|
5
|
+
[](https://github.com/magicdawn/unocss-merge/actions/workflows/ci.yml)
|
|
6
|
+
[](https://codecov.io/gh/magicdawn/unocss-merge)
|
|
7
|
+
[](https://www.npmjs.com/package/unocss-merge)
|
|
8
|
+
[](https://www.npmjs.com/package/unocss-merge)
|
|
9
|
+
[](http://magicdawn.mit-license.org)
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
$ pnpm add unocss-merge
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## API
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
const unocssMerge = require('unocss-merge');
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Changelog
|
|
24
|
+
|
|
25
|
+
[CHANGELOG.md](CHANGELOG.md)
|
|
26
|
+
|
|
27
|
+
## License
|
|
28
|
+
|
|
29
|
+
the MIT License http://magicdawn.mit-license.org
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { uniq } from "es-toolkit";
|
|
3
|
+
|
|
4
|
+
// src/config.ts
|
|
5
|
+
var singleValues = {
|
|
6
|
+
"display": toValues(`
|
|
7
|
+
block,inline-block,inline,flex,inline-flex,
|
|
8
|
+
table,inline-table,table-caption,table-cell,table-column,table-row,
|
|
9
|
+
table-column-group,table-footer-group,table-header-group,table-row-group,
|
|
10
|
+
flow-root,grid,inline-grid,contents,list-item,hidden
|
|
11
|
+
`),
|
|
12
|
+
"isolation": ["isolate", "isolation-auto"],
|
|
13
|
+
"position": ["static", "fixed", "absolute", "relative", "stick"],
|
|
14
|
+
"visibility": ["visible", "invisible", "collapse"],
|
|
15
|
+
"flex-direction": ["flex-row", "flex-row-reverse", "flex-col", "flex-col-reverse"],
|
|
16
|
+
"flex-wrap": ["flex-wrap", "flex-wrap-reverse", "flex-nowrap"],
|
|
17
|
+
"object-fit": [
|
|
18
|
+
"object-contain",
|
|
19
|
+
"object-cover",
|
|
20
|
+
"object-fill",
|
|
21
|
+
"object-none",
|
|
22
|
+
"object-scale-down"
|
|
23
|
+
],
|
|
24
|
+
"object-position": [
|
|
25
|
+
"object-bottom",
|
|
26
|
+
"object-center",
|
|
27
|
+
"object-left",
|
|
28
|
+
"object-left-bottom",
|
|
29
|
+
"object-left-top",
|
|
30
|
+
"object-right",
|
|
31
|
+
"object-right-bottom",
|
|
32
|
+
"object-right-top",
|
|
33
|
+
"object-top"
|
|
34
|
+
],
|
|
35
|
+
"font-smoothing": ["antialiased", "subpixel-antialiased"],
|
|
36
|
+
"font-style": ["italic", "not-italic"],
|
|
37
|
+
"font-weight": [
|
|
38
|
+
"font-thin",
|
|
39
|
+
"font-extralight",
|
|
40
|
+
"font-light",
|
|
41
|
+
"font-normal",
|
|
42
|
+
"font-medium",
|
|
43
|
+
"font-semibold",
|
|
44
|
+
"font-bold",
|
|
45
|
+
"font-extrabold",
|
|
46
|
+
"font-black"
|
|
47
|
+
],
|
|
48
|
+
"font-variant-numeric": [
|
|
49
|
+
"normal-nums",
|
|
50
|
+
"ordinal",
|
|
51
|
+
"slashed-zero",
|
|
52
|
+
"lining-nums",
|
|
53
|
+
"oldstyle-nums",
|
|
54
|
+
"proportional-nums",
|
|
55
|
+
"tabular-nums",
|
|
56
|
+
"diagonal-fractions",
|
|
57
|
+
"stacked-fractions"
|
|
58
|
+
],
|
|
59
|
+
// TODO:
|
|
60
|
+
"font-size": [
|
|
61
|
+
"text-xs",
|
|
62
|
+
"text-sm",
|
|
63
|
+
"text-base",
|
|
64
|
+
"text-lg",
|
|
65
|
+
"text-xl",
|
|
66
|
+
"text-2xl",
|
|
67
|
+
"text-3xl",
|
|
68
|
+
"text-4xl",
|
|
69
|
+
"text-5xl",
|
|
70
|
+
"text-6xl",
|
|
71
|
+
"text-7xl",
|
|
72
|
+
"text-8xl",
|
|
73
|
+
"text-9xl"
|
|
74
|
+
],
|
|
75
|
+
"list-style-position": ["list-inside", "list-outside"],
|
|
76
|
+
"list-style-type": ["list-none", "list-disc", "list-decimal"],
|
|
77
|
+
"text-align": [
|
|
78
|
+
"text-left",
|
|
79
|
+
"text-center",
|
|
80
|
+
"text-right",
|
|
81
|
+
"text-justify",
|
|
82
|
+
"text-start",
|
|
83
|
+
"text-end"
|
|
84
|
+
]
|
|
85
|
+
};
|
|
86
|
+
var specialValues = {
|
|
87
|
+
"grow": { key: "flex-grow", value: "1" },
|
|
88
|
+
"shrink": { key: "flex-shrink", value: "1" },
|
|
89
|
+
"flex-grow": { key: "flex-grow", value: "1" },
|
|
90
|
+
"flex-shrink": { key: "flex-shrink", value: "1" }
|
|
91
|
+
};
|
|
92
|
+
var classNameMap = /* @__PURE__ */ new Map();
|
|
93
|
+
for (const [prop, values] of Object.entries(singleValues)) {
|
|
94
|
+
for (const cls of values) {
|
|
95
|
+
classNameMap.set(cls, { key: prop, value: cls });
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
for (const [cls, config] of Object.entries(specialValues)) {
|
|
99
|
+
classNameMap.set(cls, config);
|
|
100
|
+
}
|
|
101
|
+
var knownPrefixHasDashValue = [
|
|
102
|
+
"break-after",
|
|
103
|
+
// break-after-avoid-page
|
|
104
|
+
"break-before",
|
|
105
|
+
"break-inside",
|
|
106
|
+
// grid
|
|
107
|
+
"grid-flow"
|
|
108
|
+
// grid-flow-row-dense
|
|
109
|
+
];
|
|
110
|
+
var ShortcutMap = new Map(
|
|
111
|
+
Object.entries({
|
|
112
|
+
"grow": "flex-grow",
|
|
113
|
+
"shrink": "flex-shrink",
|
|
114
|
+
"col": "grid-column",
|
|
115
|
+
// `col-auto` => `grid-column: auto;`
|
|
116
|
+
"col-span": "grid-column",
|
|
117
|
+
"col-start": "grid-column-start",
|
|
118
|
+
"col-end": "grid-column-end",
|
|
119
|
+
"row": "grid-row",
|
|
120
|
+
// `row-auto` => `grid-row: auto;`
|
|
121
|
+
"row-span": "grid-row",
|
|
122
|
+
"row-start": "grid-row-start",
|
|
123
|
+
"row-end": "grid-row-end",
|
|
124
|
+
"leading": "line-height"
|
|
125
|
+
})
|
|
126
|
+
);
|
|
127
|
+
function toValues(str) {
|
|
128
|
+
return str.split("\n").map((line) => line.trim()).filter(Boolean).map(
|
|
129
|
+
(line) => line.split(",").map((x) => x.trim()).filter(Boolean)
|
|
130
|
+
).flat();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// src/index.ts
|
|
134
|
+
function getClassList(className) {
|
|
135
|
+
return uniq(
|
|
136
|
+
(className || "").split(" ").map((x) => x.trim()).filter(Boolean)
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
function unoMerge(...classNames) {
|
|
140
|
+
const classList = classNames.map(getClassList).flat().filter(Boolean);
|
|
141
|
+
const map = /* @__PURE__ */ new Map();
|
|
142
|
+
for (const cls of classList) {
|
|
143
|
+
if (classNameMap.has(cls)) {
|
|
144
|
+
const { key: key2, value } = classNameMap.get(cls);
|
|
145
|
+
map.set(key2, value);
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
const prefix = knownPrefixHasDashValue.find((prefix2) => cls.startsWith(prefix2 + "-"));
|
|
149
|
+
if (prefix) {
|
|
150
|
+
map.set(prefix, cls);
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
let clsForSearing = cls;
|
|
154
|
+
const reg = /(\[[\w_,-]+\])$/;
|
|
155
|
+
if (reg.test(cls)) {
|
|
156
|
+
clsForSearing = cls.replace(reg, function(match, p1) {
|
|
157
|
+
return "*".repeat(p1.length);
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
if (clsForSearing.includes("--")) {
|
|
161
|
+
clsForSearing = clsForSearing.replace(/--/g, "-*");
|
|
162
|
+
}
|
|
163
|
+
const lastHyphenIndex = clsForSearing.lastIndexOf("-");
|
|
164
|
+
if (lastHyphenIndex === -1) {
|
|
165
|
+
map.set(cls, cls);
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
let key = cls.slice(0, lastHyphenIndex);
|
|
169
|
+
if (ShortcutMap.has(key)) {
|
|
170
|
+
key = ShortcutMap.get(key);
|
|
171
|
+
}
|
|
172
|
+
map.set(key, cls);
|
|
173
|
+
}
|
|
174
|
+
return Array.from(map.values()).join(" ");
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export {
|
|
178
|
+
getClassList,
|
|
179
|
+
unoMerge
|
|
180
|
+
};
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/dist/react.d.ts
ADDED
package/dist/react.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "unocss-merge",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "simple utility to merge unocss class names",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
"./package.json": "./package.json",
|
|
8
|
+
"./react": {
|
|
9
|
+
"types": "./dist/react.d.ts",
|
|
10
|
+
"default": "./dist/react.js"
|
|
11
|
+
},
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist/"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"prepare": "husky",
|
|
22
|
+
"dev": "tsup --watch",
|
|
23
|
+
"build": "tsup",
|
|
24
|
+
"typecheck": "tsc --noEmit",
|
|
25
|
+
"test": "vitest run",
|
|
26
|
+
"test:dev": "vitest",
|
|
27
|
+
"test-cover": "vitest run --coverage",
|
|
28
|
+
"prepublishOnly": "pnpm typecheck && pnpm test-cover && pnpm build"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"es-toolkit": "^1.36.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@magicdawn/prettier-config": "^0.0.4",
|
|
35
|
+
"@swc/core": "^1.11.22",
|
|
36
|
+
"@types/node": "^22.15.0",
|
|
37
|
+
"@typescript-eslint/eslint-plugin": "^8.31.0",
|
|
38
|
+
"@typescript-eslint/parser": "^8.31.0",
|
|
39
|
+
"@vitest/coverage-v8": "^3.1.2",
|
|
40
|
+
"eslint": "^9.25.1",
|
|
41
|
+
"eslint-config-prettier": "^10.1.2",
|
|
42
|
+
"husky": "^9.1.7",
|
|
43
|
+
"lint-staged": "^15.5.1",
|
|
44
|
+
"prettier": "^3.5.3",
|
|
45
|
+
"tsup": "^8.4.0",
|
|
46
|
+
"typescript": "^5.8.3",
|
|
47
|
+
"vitest": "^3.1.2"
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"react": ">=18"
|
|
51
|
+
},
|
|
52
|
+
"repository": {
|
|
53
|
+
"type": "git",
|
|
54
|
+
"url": "git+ssh://git@github.com/magicdawn/unocss-merge.git"
|
|
55
|
+
},
|
|
56
|
+
"keywords": [
|
|
57
|
+
"unocss",
|
|
58
|
+
"merge",
|
|
59
|
+
"tw-merge"
|
|
60
|
+
],
|
|
61
|
+
"author": "magicdawn",
|
|
62
|
+
"license": "MIT",
|
|
63
|
+
"bugs": {
|
|
64
|
+
"url": "https://github.com/magicdawn/unocss-merge/issues"
|
|
65
|
+
},
|
|
66
|
+
"homepage": "https://github.com/magicdawn/unocss-merge#readme",
|
|
67
|
+
"publishConfig": {
|
|
68
|
+
"registry": "https://registry.npmjs.org/"
|
|
69
|
+
},
|
|
70
|
+
"lint-staged": {
|
|
71
|
+
"**/*": [
|
|
72
|
+
"prettier --write --ignore-unknown"
|
|
73
|
+
],
|
|
74
|
+
"*.{js,jsx,ts,tsx,less,md}": [
|
|
75
|
+
"prettier --write"
|
|
76
|
+
]
|
|
77
|
+
},
|
|
78
|
+
"packageManager": "pnpm@10.9.0+sha512.0486e394640d3c1fb3c9d43d49cf92879ff74f8516959c235308f5a8f62e2e19528a65cdc2a3058f587cde71eba3d5b56327c8c33a97e4c4051ca48a10ca2d5f"
|
|
79
|
+
}
|