@axiomui/utils 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/dist/index.cjs +77 -0
- package/dist/index.d.cts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +68 -0
- package/package.json +7 -11
package/dist/index.cjs
CHANGED
|
@@ -3,6 +3,10 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
6
10
|
var __copyProps = (to, from, except, desc) => {
|
|
7
11
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
12
|
for (let key of __getOwnPropNames(from))
|
|
@@ -15,4 +19,77 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
15
19
|
|
|
16
20
|
// src/index.ts
|
|
17
21
|
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
cn: () => cn
|
|
24
|
+
});
|
|
18
25
|
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
|
|
27
|
+
// src/cn.ts
|
|
28
|
+
function toClassName(value) {
|
|
29
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
30
|
+
return String(value);
|
|
31
|
+
}
|
|
32
|
+
if (!value || typeof value === "boolean") {
|
|
33
|
+
return "";
|
|
34
|
+
}
|
|
35
|
+
if (Array.isArray(value)) {
|
|
36
|
+
return value.map(toClassName).filter(Boolean).join(" ");
|
|
37
|
+
}
|
|
38
|
+
return Object.entries(value).filter(([, condition]) => Boolean(condition)).map(([className]) => className).join(" ");
|
|
39
|
+
}
|
|
40
|
+
function getUtilityGroup(utility) {
|
|
41
|
+
const groups = [
|
|
42
|
+
[/^p[trblxy]?-/u, "padding"],
|
|
43
|
+
[/^m[trblxy]?-/u, "margin"],
|
|
44
|
+
[/^(w|min-w|max-w)-/u, "width"],
|
|
45
|
+
[/^(h|min-h|max-h)-/u, "height"],
|
|
46
|
+
[/^size-/u, "size"],
|
|
47
|
+
[/^bg-/u, "background"],
|
|
48
|
+
[/^text-/u, "text"],
|
|
49
|
+
[/^(font|tracking|leading)-/u, "typography"],
|
|
50
|
+
[/^rounded(?:-[trbl]{1,2})?-/u, "radius"],
|
|
51
|
+
[/^border(?:-[trblxy])?-/u, "border"],
|
|
52
|
+
[/^ring(?:-[trblxy])?-/u, "ring"],
|
|
53
|
+
[/^shadow/u, "shadow"],
|
|
54
|
+
[/^opacity-/u, "opacity"],
|
|
55
|
+
[/^gap[xy]?-/u, "gap"],
|
|
56
|
+
[/^justify-/u, "justify"],
|
|
57
|
+
[/^items-/u, "items"],
|
|
58
|
+
[/^inline-flex$|^flex$|^block$|^inline-block$|^hidden$/u, "display"],
|
|
59
|
+
[/^transition/u, "transition"],
|
|
60
|
+
[/^duration-/u, "duration"],
|
|
61
|
+
[/^ease-/u, "ease"],
|
|
62
|
+
[/^transform$/u, "transform"],
|
|
63
|
+
[/^(scale|translate|rotate|skew)-/u, "transform-effect"]
|
|
64
|
+
];
|
|
65
|
+
const matched = groups.find(([pattern]) => pattern.test(utility));
|
|
66
|
+
return matched ? matched[1] : utility;
|
|
67
|
+
}
|
|
68
|
+
function mergeTailwindLikeClasses(className) {
|
|
69
|
+
const tokens = className.trim().split(/\s+/u).filter(Boolean);
|
|
70
|
+
const merged = /* @__PURE__ */ new Map();
|
|
71
|
+
for (const token of tokens) {
|
|
72
|
+
const important = token.startsWith("!") ? "!" : "";
|
|
73
|
+
const cleanToken = important ? token.slice(1) : token;
|
|
74
|
+
const segments = cleanToken.split(":");
|
|
75
|
+
const utility = segments.pop() ?? cleanToken;
|
|
76
|
+
const variants = segments.join(":");
|
|
77
|
+
const key = `${important}${variants}|${getUtilityGroup(utility)}`;
|
|
78
|
+
if (merged.has(key)) {
|
|
79
|
+
merged.delete(key);
|
|
80
|
+
}
|
|
81
|
+
merged.set(key, token);
|
|
82
|
+
}
|
|
83
|
+
return Array.from(merged.values()).join(" ");
|
|
84
|
+
}
|
|
85
|
+
function cn(...inputs) {
|
|
86
|
+
const joined = inputs.map(toClassName).filter(Boolean).join(" ").trim();
|
|
87
|
+
if (!joined) {
|
|
88
|
+
return "";
|
|
89
|
+
}
|
|
90
|
+
return mergeTailwindLikeClasses(joined);
|
|
91
|
+
}
|
|
92
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
93
|
+
0 && (module.exports = {
|
|
94
|
+
cn
|
|
95
|
+
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
|
+
type ClassPrimitive = string | number | boolean | null | undefined;
|
|
2
|
+
type ClassDictionary = Record<string, boolean | null | undefined>;
|
|
3
|
+
type ClassArray = ClassValue[];
|
|
4
|
+
type ClassValue = ClassPrimitive | ClassDictionary | ClassArray;
|
|
5
|
+
declare function cn(...inputs: ClassValue[]): string;
|
|
1
6
|
|
|
2
|
-
export {
|
|
7
|
+
export { type ClassValue, cn };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
|
+
type ClassPrimitive = string | number | boolean | null | undefined;
|
|
2
|
+
type ClassDictionary = Record<string, boolean | null | undefined>;
|
|
3
|
+
type ClassArray = ClassValue[];
|
|
4
|
+
type ClassValue = ClassPrimitive | ClassDictionary | ClassArray;
|
|
5
|
+
declare function cn(...inputs: ClassValue[]): string;
|
|
1
6
|
|
|
2
|
-
export {
|
|
7
|
+
export { type ClassValue, cn };
|
package/dist/index.js
CHANGED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// src/cn.ts
|
|
2
|
+
function toClassName(value) {
|
|
3
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
4
|
+
return String(value);
|
|
5
|
+
}
|
|
6
|
+
if (!value || typeof value === "boolean") {
|
|
7
|
+
return "";
|
|
8
|
+
}
|
|
9
|
+
if (Array.isArray(value)) {
|
|
10
|
+
return value.map(toClassName).filter(Boolean).join(" ");
|
|
11
|
+
}
|
|
12
|
+
return Object.entries(value).filter(([, condition]) => Boolean(condition)).map(([className]) => className).join(" ");
|
|
13
|
+
}
|
|
14
|
+
function getUtilityGroup(utility) {
|
|
15
|
+
const groups = [
|
|
16
|
+
[/^p[trblxy]?-/u, "padding"],
|
|
17
|
+
[/^m[trblxy]?-/u, "margin"],
|
|
18
|
+
[/^(w|min-w|max-w)-/u, "width"],
|
|
19
|
+
[/^(h|min-h|max-h)-/u, "height"],
|
|
20
|
+
[/^size-/u, "size"],
|
|
21
|
+
[/^bg-/u, "background"],
|
|
22
|
+
[/^text-/u, "text"],
|
|
23
|
+
[/^(font|tracking|leading)-/u, "typography"],
|
|
24
|
+
[/^rounded(?:-[trbl]{1,2})?-/u, "radius"],
|
|
25
|
+
[/^border(?:-[trblxy])?-/u, "border"],
|
|
26
|
+
[/^ring(?:-[trblxy])?-/u, "ring"],
|
|
27
|
+
[/^shadow/u, "shadow"],
|
|
28
|
+
[/^opacity-/u, "opacity"],
|
|
29
|
+
[/^gap[xy]?-/u, "gap"],
|
|
30
|
+
[/^justify-/u, "justify"],
|
|
31
|
+
[/^items-/u, "items"],
|
|
32
|
+
[/^inline-flex$|^flex$|^block$|^inline-block$|^hidden$/u, "display"],
|
|
33
|
+
[/^transition/u, "transition"],
|
|
34
|
+
[/^duration-/u, "duration"],
|
|
35
|
+
[/^ease-/u, "ease"],
|
|
36
|
+
[/^transform$/u, "transform"],
|
|
37
|
+
[/^(scale|translate|rotate|skew)-/u, "transform-effect"]
|
|
38
|
+
];
|
|
39
|
+
const matched = groups.find(([pattern]) => pattern.test(utility));
|
|
40
|
+
return matched ? matched[1] : utility;
|
|
41
|
+
}
|
|
42
|
+
function mergeTailwindLikeClasses(className) {
|
|
43
|
+
const tokens = className.trim().split(/\s+/u).filter(Boolean);
|
|
44
|
+
const merged = /* @__PURE__ */ new Map();
|
|
45
|
+
for (const token of tokens) {
|
|
46
|
+
const important = token.startsWith("!") ? "!" : "";
|
|
47
|
+
const cleanToken = important ? token.slice(1) : token;
|
|
48
|
+
const segments = cleanToken.split(":");
|
|
49
|
+
const utility = segments.pop() ?? cleanToken;
|
|
50
|
+
const variants = segments.join(":");
|
|
51
|
+
const key = `${important}${variants}|${getUtilityGroup(utility)}`;
|
|
52
|
+
if (merged.has(key)) {
|
|
53
|
+
merged.delete(key);
|
|
54
|
+
}
|
|
55
|
+
merged.set(key, token);
|
|
56
|
+
}
|
|
57
|
+
return Array.from(merged.values()).join(" ");
|
|
58
|
+
}
|
|
59
|
+
function cn(...inputs) {
|
|
60
|
+
const joined = inputs.map(toClassName).filter(Boolean).join(" ").trim();
|
|
61
|
+
if (!joined) {
|
|
62
|
+
return "";
|
|
63
|
+
}
|
|
64
|
+
return mergeTailwindLikeClasses(joined);
|
|
65
|
+
}
|
|
66
|
+
export {
|
|
67
|
+
cn
|
|
68
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axiomui/utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -17,20 +17,16 @@
|
|
|
17
17
|
"files": [
|
|
18
18
|
"dist"
|
|
19
19
|
],
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@axiomui/primitives": "^0.2.0"
|
|
23
|
+
},
|
|
20
24
|
"scripts": {
|
|
21
25
|
"build": "tsup src/index.ts --format esm,cjs --dts --clean",
|
|
22
26
|
"dev": "tsup src/index.ts --format esm,cjs --dts --watch",
|
|
23
27
|
"lint": "tsc -p tsconfig.json --noEmit",
|
|
24
28
|
"test": "vitest run --passWithNoTests",
|
|
25
29
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
26
|
-
"clean": "rm -rf dist"
|
|
27
|
-
"prepublishOnly": "pnpm run build"
|
|
28
|
-
},
|
|
29
|
-
"publishConfig": {
|
|
30
|
-
"access": "public"
|
|
31
|
-
},
|
|
32
|
-
"sideEffects": false,
|
|
33
|
-
"dependencies": {
|
|
34
|
-
"@axiomui/primitives": "workspace:*"
|
|
30
|
+
"clean": "rm -rf dist"
|
|
35
31
|
}
|
|
36
|
-
}
|
|
32
|
+
}
|